From b10fa6f894c1314dd06cd0720e95b4e4a8d3117f Mon Sep 17 00:00:00 2001 From: Nathan Froyd Date: Mon, 18 May 2020 15:32:14 -0400 Subject: [PATCH 001/942] add command-line option for disabling untagged unions One more thing that we can configure from the command line. --- src/options.rs | 9 ++ .../tests/disable-untagged-union.rs | 82 +++++++++++++++++++ tests/headers/disable-untagged-union.hpp | 6 ++ 3 files changed, 97 insertions(+) create mode 100644 tests/expectations/tests/disable-untagged-union.rs create mode 100644 tests/headers/disable-untagged-union.hpp diff --git a/src/options.rs b/src/options.rs index b630bb4bed..c2de1e5a15 100644 --- a/src/options.rs +++ b/src/options.rs @@ -267,6 +267,11 @@ where names like \"bar\" instead of \"foo_bar\" for a nested \ definition \"struct foo { struct bar { } b; };\"." ), + Arg::with_name("disable-untagged-union") + .long("disable-untagged-union") + .help( + "Disable support for native Rust unions.", + ), Arg::with_name("ignore-functions") .long("ignore-functions") .help( @@ -667,6 +672,10 @@ where builder = builder.disable_nested_struct_naming(); } + if matches.is_present("disable-untagged-union") { + builder = builder.disable_untagged_union(); + } + if matches.is_present("ignore-functions") { builder = builder.ignore_functions(); } diff --git a/tests/expectations/tests/disable-untagged-union.rs b/tests/expectations/tests/disable-untagged-union.rs new file mode 100644 index 0000000000..9661ef7969 --- /dev/null +++ b/tests/expectations/tests/disable-untagged-union.rs @@ -0,0 +1,82 @@ +/* automatically generated by rust-bindgen */ + +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +pub struct __BindgenUnionField(::std::marker::PhantomData); +impl __BindgenUnionField { + #[inline] + pub const fn new() -> Self { + __BindgenUnionField(::std::marker::PhantomData) + } + #[inline] + pub unsafe fn as_ref(&self) -> &T { + ::std::mem::transmute(self) + } + #[inline] + pub unsafe fn as_mut(&mut self) -> &mut T { + ::std::mem::transmute(self) + } +} +impl ::std::default::Default for __BindgenUnionField { + #[inline] + fn default() -> Self { + Self::new() + } +} +impl ::std::clone::Clone for __BindgenUnionField { + #[inline] + fn clone(&self) -> Self { + Self::new() + } +} +impl ::std::marker::Copy for __BindgenUnionField {} +impl ::std::fmt::Debug for __BindgenUnionField { + fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + fmt.write_str("__BindgenUnionField") + } +} +impl ::std::hash::Hash for __BindgenUnionField { + fn hash(&self, _state: &mut H) {} +} +impl ::std::cmp::PartialEq for __BindgenUnionField { + fn eq(&self, _other: &__BindgenUnionField) -> bool { + true + } +} +impl ::std::cmp::Eq for __BindgenUnionField {} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Foo { + pub bar: __BindgenUnionField<::std::os::raw::c_int>, + pub baz: __BindgenUnionField<::std::os::raw::c_uint>, + pub bindgen_union_field: u32, +} +#[test] +fn bindgen_test_layout_Foo() { + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Foo)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).baz as *const _ as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(baz)) + ); +} diff --git a/tests/headers/disable-untagged-union.hpp b/tests/headers/disable-untagged-union.hpp new file mode 100644 index 0000000000..4462318171 --- /dev/null +++ b/tests/headers/disable-untagged-union.hpp @@ -0,0 +1,6 @@ +// bindgen-flags: --disable-untagged-union + +union Foo { + int bar; + unsigned int baz; +}; From d405baf05acec7caf6d3d403cccdaeb5e67423e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 21 May 2020 21:41:37 +0200 Subject: [PATCH 002/942] Release 0.54.0. --- CHANGELOG.md | 107 +++++++++++++++++++++++++++++++-------------------- Cargo.lock | 2 +- Cargo.toml | 2 +- 3 files changed, 68 insertions(+), 43 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index af357683c3..b751fb9a49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,90 +9,94 @@ - [Removed](#removed) - [Fixed](#fixed) - [Security](#security) -- [0.53.2](#0532) +- [0.54.0](#0540) + - [Added](#added-1) - [Changed](#changed-1) + - [Fixed](#fixed-1) +- [0.53.2](#0532) + - [Changed](#changed-2) - [0.53.1](#0531) - - [Added](#added-1) -- [0.53.0](#0530) - [Added](#added-2) - - [Changed](#changed-2) - - [Fixed](#fixed-1) -- [0.52.0](#0520) +- [0.53.0](#0530) - [Added](#added-3) - [Changed](#changed-3) - [Fixed](#fixed-2) -- [0.51.1](#0511) - - [Fixed](#fixed-3) +- [0.52.0](#0520) + - [Added](#added-4) - [Changed](#changed-4) -- [0.51.0](#0510) + - [Fixed](#fixed-3) +- [0.51.1](#0511) - [Fixed](#fixed-4) - [Changed](#changed-5) - - [Added](#added-4) -- [0.50.0](#0500) +- [0.51.0](#0510) + - [Fixed](#fixed-5) + - [Changed](#changed-6) - [Added](#added-5) -- [0.49.3](#0493) +- [0.50.0](#0500) - [Added](#added-6) +- [0.49.3](#0493) + - [Added](#added-7) - [0.49.2](#0492) - - [Changed](#changed-6) -- [0.49.1](#0491) - - [Fixed](#fixed-5) - [Changed](#changed-7) -- [0.49.0](#0490) - - [Added](#added-7) +- [0.49.1](#0491) - [Fixed](#fixed-6) - [Changed](#changed-8) -- [0.48.1](#0481) +- [0.49.0](#0490) + - [Added](#added-8) - [Fixed](#fixed-7) -- [0.48.0](#0480) - [Changed](#changed-9) +- [0.48.1](#0481) - [Fixed](#fixed-8) -- [0.47.3](#0473) +- [0.48.0](#0480) - [Changed](#changed-10) -- [0.47.2](#0472) - [Fixed](#fixed-9) -- [0.47.1](#0471) +- [0.47.3](#0473) - [Changed](#changed-11) +- [0.47.2](#0472) - [Fixed](#fixed-10) -- [0.47.0](#0470) +- [0.47.1](#0471) - [Changed](#changed-12) - [Fixed](#fixed-11) -- [0.33.1 .. 0.46.0](#0331--0460) - - [Added](#added-8) - - [Removed](#removed-1) +- [0.47.0](#0470) - [Changed](#changed-13) - [Fixed](#fixed-12) -- [0.33.1](#0331) - - [Fixed](#fixed-13) -- [0.33.0](#0330) +- [0.33.1 .. 0.46.0](#0331--0460) - [Added](#added-9) + - [Removed](#removed-1) - [Changed](#changed-14) + - [Fixed](#fixed-13) +- [0.33.1](#0331) + - [Fixed](#fixed-14) +- [0.33.0](#0330) + - [Added](#added-10) + - [Changed](#changed-15) - [Deprecated](#deprecated-1) - [Removed](#removed-2) - - [Fixed](#fixed-14) + - [Fixed](#fixed-15) - [Security](#security-1) - [0.32.2](#0322) - - [Fixed](#fixed-15) -- [0.32.1](#0321) - [Fixed](#fixed-16) -- [0.32.0](#0320) - - [Added](#added-10) - - [Changed](#changed-15) +- [0.32.1](#0321) - [Fixed](#fixed-17) -- [0.31.0](#0310) +- [0.32.0](#0320) - [Added](#added-11) - [Changed](#changed-16) - - [Deprecated](#deprecated-2) - - [Removed](#removed-3) - [Fixed](#fixed-18) -- [0.30.0](#0300) +- [0.31.0](#0310) - [Added](#added-12) - [Changed](#changed-17) - - [Deprecated](#deprecated-3) + - [Deprecated](#deprecated-2) + - [Removed](#removed-3) - [Fixed](#fixed-19) -- [0.29.0](#0290) +- [0.30.0](#0300) - [Added](#added-13) - [Changed](#changed-18) + - [Deprecated](#deprecated-3) - [Fixed](#fixed-20) +- [0.29.0](#0290) + - [Added](#added-14) + - [Changed](#changed-19) + - [Fixed](#fixed-21) @@ -128,6 +132,27 @@ Released YYYY/MM/DD -------------------------------------------------------------------------------- +# 0.54.0 + +Released 2020/05/21. + +## Added + + * New command line flag to allow disabling untagged unions (#1789). + +## Changed + + * Various documentation improvements (#1764, #1751, #1757). + * Better Objective-C support (#1722, #1750). + +## Fixed + + * Rust method wrappers are not emitted for blacklisted functions (#1775). + * Fixed function signatures in some edge cases involving Objective-C or + `__stdcall` (#1781). + +-------------------------------------------------------------------------------- + # 0.53.2 Released 2020/03/10. diff --git a/Cargo.lock b/Cargo.lock index 2abe0ecd73..466c7b9e7e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -27,7 +27,7 @@ dependencies = [ [[package]] name = "bindgen" -version = "0.53.2" +version = "0.54.0" dependencies = [ "bitflags 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "cexpr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index ef1d01e320..da63ee5c94 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ readme = "README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.53.2" +version = "0.54.0" edition = "2018" build = "build.rs" From b9ed1a1bba10d80647c9850d2d86d0dd1fca7993 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 21 May 2020 21:51:54 +0200 Subject: [PATCH 003/942] Document the 0.53.3 release. --- CHANGELOG.md | 88 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 55 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b751fb9a49..1a371f054f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,90 +13,93 @@ - [Added](#added-1) - [Changed](#changed-1) - [Fixed](#fixed-1) +- [0.53.3](#0533) + - [Added](#added-2) + - [Fixed](#fixed-2) - [0.53.2](#0532) - [Changed](#changed-2) - [0.53.1](#0531) - - [Added](#added-2) -- [0.53.0](#0530) - [Added](#added-3) +- [0.53.0](#0530) + - [Added](#added-4) - [Changed](#changed-3) - - [Fixed](#fixed-2) + - [Fixed](#fixed-3) - [0.52.0](#0520) - - [Added](#added-4) + - [Added](#added-5) - [Changed](#changed-4) - - [Fixed](#fixed-3) -- [0.51.1](#0511) - [Fixed](#fixed-4) +- [0.51.1](#0511) + - [Fixed](#fixed-5) - [Changed](#changed-5) - [0.51.0](#0510) - - [Fixed](#fixed-5) + - [Fixed](#fixed-6) - [Changed](#changed-6) - - [Added](#added-5) -- [0.50.0](#0500) - [Added](#added-6) -- [0.49.3](#0493) +- [0.50.0](#0500) - [Added](#added-7) +- [0.49.3](#0493) + - [Added](#added-8) - [0.49.2](#0492) - [Changed](#changed-7) - [0.49.1](#0491) - - [Fixed](#fixed-6) + - [Fixed](#fixed-7) - [Changed](#changed-8) - [0.49.0](#0490) - - [Added](#added-8) - - [Fixed](#fixed-7) + - [Added](#added-9) + - [Fixed](#fixed-8) - [Changed](#changed-9) - [0.48.1](#0481) - - [Fixed](#fixed-8) + - [Fixed](#fixed-9) - [0.48.0](#0480) - [Changed](#changed-10) - - [Fixed](#fixed-9) + - [Fixed](#fixed-10) - [0.47.3](#0473) - [Changed](#changed-11) - [0.47.2](#0472) - - [Fixed](#fixed-10) + - [Fixed](#fixed-11) - [0.47.1](#0471) - [Changed](#changed-12) - - [Fixed](#fixed-11) + - [Fixed](#fixed-12) - [0.47.0](#0470) - [Changed](#changed-13) - - [Fixed](#fixed-12) + - [Fixed](#fixed-13) - [0.33.1 .. 0.46.0](#0331--0460) - - [Added](#added-9) + - [Added](#added-10) - [Removed](#removed-1) - [Changed](#changed-14) - - [Fixed](#fixed-13) -- [0.33.1](#0331) - [Fixed](#fixed-14) +- [0.33.1](#0331) + - [Fixed](#fixed-15) - [0.33.0](#0330) - - [Added](#added-10) + - [Added](#added-11) - [Changed](#changed-15) - [Deprecated](#deprecated-1) - [Removed](#removed-2) - - [Fixed](#fixed-15) + - [Fixed](#fixed-16) - [Security](#security-1) - [0.32.2](#0322) - - [Fixed](#fixed-16) -- [0.32.1](#0321) - [Fixed](#fixed-17) +- [0.32.1](#0321) + - [Fixed](#fixed-18) - [0.32.0](#0320) - - [Added](#added-11) + - [Added](#added-12) - [Changed](#changed-16) - - [Fixed](#fixed-18) + - [Fixed](#fixed-19) - [0.31.0](#0310) - - [Added](#added-12) + - [Added](#added-13) - [Changed](#changed-17) - [Deprecated](#deprecated-2) - [Removed](#removed-3) - - [Fixed](#fixed-19) + - [Fixed](#fixed-20) - [0.30.0](#0300) - - [Added](#added-13) + - [Added](#added-14) - [Changed](#changed-18) - [Deprecated](#deprecated-3) - - [Fixed](#fixed-20) + - [Fixed](#fixed-21) - [0.29.0](#0290) - - [Added](#added-14) + - [Added](#added-15) - [Changed](#changed-19) - - [Fixed](#fixed-21) + - [Fixed](#fixed-22) @@ -153,6 +156,25 @@ Released 2020/05/21. -------------------------------------------------------------------------------- +# 0.53.3 + +Released 2020/05/21. + +*Note: This release contains the same fixes and additions as 0.54.0, but without +the Objective-C breaking changes* + +## Added + + * New command line flag to allow disabling untagged unions (#1789). + +## Fixed + + * Rust method wrappers are not emitted for blacklisted functions (#1775). + * Fixed function signatures in some edge cases involving Objective-C or + `__stdcall` (#1781). + +-------------------------------------------------------------------------------- + # 0.53.2 Released 2020/03/10. From 117e2a1d5b12f63e0ade4b4acdad52fd7a1b5f7d Mon Sep 17 00:00:00 2001 From: Travis Finkenauer Date: Thu, 4 Jun 2020 23:50:01 -0400 Subject: [PATCH 004/942] Document BINDGEN_EXTRA_CLANG_ARGS env variable Feature was originally introduced in pull-request #1537 --- src/lib.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 6847dc7737..8a8b4e4af3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -191,6 +191,21 @@ impl Default for CodegenConfig { /// 4. Rustified enum /// /// If none of the above patterns match, then bindgen will generate a set of Rust constants. +/// +/// # Clang arguments +/// +/// Extra arguments can be passed to with clang: +/// 1. [`clang_arg()`](#method.clang_arg): takes a single argument +/// 2. [`clang_args()`](#method.clang_args): takes an iterator of arguments +/// 3. `BINDGEN_EXTRA_CLANG_ARGS` environment variable: whitespace separate +/// environment variable of arguments +/// +/// Clang arguments specific to your crate should be added via the +/// `clang_arg()`/`clang_args()` methods. +/// +/// End-users of the crate may need to set the `BINDGEN_EXTRA_CLANG_ARGS` environment variable to +/// add additional arguments. For example, to build against a different sysroot a user could set +/// `BINDGEN_EXTRA_CLANG_ARGS` to `--sysroot=/path/to/sysroot`. #[derive(Debug, Default)] pub struct Builder { options: BindgenOptions, From de23676c4b7feca98c8418bf701ce5ce80f7e4e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 7 Jun 2020 06:52:19 +0200 Subject: [PATCH 005/942] Fix warning introduced in recent objective-c work. --- src/codegen/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index af1622daff..1cefb9e294 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -3717,7 +3717,7 @@ impl CodeGenerator for ObjCInterface { } let instance_method_names: Vec<_> = - self.methods().iter().map({ |m| m.rust_name() }).collect(); + self.methods().iter().map(|m| m.rust_name()).collect(); for class_method in self.class_methods() { let ambiquity = From 93adc70ed8ebb10f9356abd8df97bed68cf908ad Mon Sep 17 00:00:00 2001 From: Travis Finkenauer Date: Sun, 7 Jun 2020 15:11:23 -0400 Subject: [PATCH 006/942] Document environment variables in README Mention BINDGEN_EXTRA_CLANG_ARGS and clang-sys variables. --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index a972ab9f6c..9e9b4d36ca 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,28 @@ No MSRV bump policy has been established yet, so MSRV may increase in any releas [API reference documentation is on docs.rs](https://docs.rs/bindgen) +## Environment Variables + +In addition to the [library API](https://docs.rs/bindgen) and [executable command-line API][bindgen-cmdline], +`bindgen` can be controlled through environment variables. + +End-users should set these environment variables to modify `bindgen`'s behavior without modifying the source code of direct consumers of `bindgen`. + +- `BINDGEN_EXTRA_CLANG_ARGS`: extra arguments to pass to `clang` + - Arguments are whitespace-separated + - Use shell-style quoting to pass through whitespace + - Examples: + - Specify alternate sysroot: `--sysroot=/path/to/sysroot` + - Add include search path with spaces: `-I"/path/with spaces"` + +Additionally, `bindgen` uses `libclang` to parse C and C++ header files. +To modify how `bindgen` searches for `libclang`, see the [`clang-sys` documentation][clang-sys-env]. +For more details on how `bindgen` uses `libclang`, see the [`bindgen` users guide][bindgen-book-clang]. + ## Contributing [See `CONTRIBUTING.md` for hacking on `bindgen`!](./CONTRIBUTING.md) + +[bindgen-cmdline]: https://rust-lang.github.io/rust-bindgen/command-line-usage.html +[clang-sys-env]: https://github.com/KyleMayes/clang-sys#environment-variables +[bindgen-book-clang]: https://rust-lang.github.io/rust-bindgen/requirements.html#clang \ No newline at end of file From b91353c97802a2901bb5d74640ada50a20a692d3 Mon Sep 17 00:00:00 2001 From: kellda <59569234+kellda@users.noreply.github.com> Date: Mon, 8 Jun 2020 07:05:09 +0000 Subject: [PATCH 007/942] Mangle items with the same name as Rust primitive types --- src/ir/context.rs | 4 +- .../tests/issue-1382-rust-primitive-types.rs | 138 ++++++++++++++++++ .../expectations/tests/jsval_layout_opaque.rs | 12 +- .../tests/jsval_layout_opaque_1_0.rs | 12 +- tests/expectations/tests/keywords.rs | 44 ++++-- .../headers/issue-1382-rust-primitive-types.h | 34 +++++ tests/headers/keywords.h | 3 + 7 files changed, 222 insertions(+), 25 deletions(-) create mode 100644 tests/expectations/tests/issue-1382-rust-primitive-types.rs create mode 100644 tests/headers/issue-1382-rust-primitive-types.h diff --git a/src/ir/context.rs b/src/ir/context.rs index 8ff102c023..901daa3a30 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -864,7 +864,9 @@ If you encounter an error missing from this list, please file an issue or a PR!" "return" | "Self" | "self" | "sizeof" | "static" | "struct" | "super" | "trait" | "true" | "type" | "typeof" | "unsafe" | "unsized" | "use" | "virtual" | "where" | - "while" | "yield" | "bool" | "_" => true, + "while" | "yield" | "str" | "bool" | "f32" | "f64" | + "usize" | "isize" | "u128" | "i128" | "u64" | "i64" | + "u32" | "i32" | "u16" | "i16" | "u8" | "i8" | "_" => true, _ => false, } { diff --git a/tests/expectations/tests/issue-1382-rust-primitive-types.rs b/tests/expectations/tests/issue-1382-rust-primitive-types.rs new file mode 100644 index 0000000000..053fee91e6 --- /dev/null +++ b/tests/expectations/tests/issue-1382-rust-primitive-types.rs @@ -0,0 +1,138 @@ +/* automatically generated by rust-bindgen */ + +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +pub type i8_ = i8; +pub type u8_ = u8; +pub type i16_ = i16; +pub type u16_ = u16; +pub type i32_ = i32; +pub type u32_ = u32; +pub type i64_ = i64; +pub type u64_ = u64; +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Foo { + pub i8_: ::std::os::raw::c_int, + pub u8_: ::std::os::raw::c_int, + pub i16_: ::std::os::raw::c_int, + pub u16_: ::std::os::raw::c_int, + pub i32_: ::std::os::raw::c_int, + pub u32_: ::std::os::raw::c_int, + pub i64_: ::std::os::raw::c_int, + pub u64_: ::std::os::raw::c_int, + pub i128_: ::std::os::raw::c_int, + pub u128_: ::std::os::raw::c_int, + pub isize_: ::std::os::raw::c_int, + pub usize_: ::std::os::raw::c_int, + pub f32_: ::std::os::raw::c_int, + pub f64_: ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout_Foo() { + assert_eq!( + ::std::mem::size_of::(), + 56usize, + concat!("Size of: ", stringify!(Foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Foo)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).i8_ as *const _ as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i8_)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).u8_ as *const _ as usize }, + 4usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u8_)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).i16_ as *const _ as usize }, + 8usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i16_)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).u16_ as *const _ as usize }, + 12usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u16_)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).i32_ as *const _ as usize }, + 16usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i32_)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).u32_ as *const _ as usize }, + 20usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u32_)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).i64_ as *const _ as usize }, + 24usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i64_)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).u64_ as *const _ as usize }, + 28usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u64_)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).i128_ as *const _ as usize }, + 32usize, + concat!( + "Offset of field: ", + stringify!(Foo), + "::", + stringify!(i128_) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).u128_ as *const _ as usize }, + 36usize, + concat!( + "Offset of field: ", + stringify!(Foo), + "::", + stringify!(u128_) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).isize_ as *const _ as usize }, + 40usize, + concat!( + "Offset of field: ", + stringify!(Foo), + "::", + stringify!(isize_) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).usize_ as *const _ as usize }, + 44usize, + concat!( + "Offset of field: ", + stringify!(Foo), + "::", + stringify!(usize_) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).f32_ as *const _ as usize }, + 48usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(f32_)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).f64_ as *const _ as usize }, + 52usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(f64_)) + ); +} diff --git a/tests/expectations/tests/jsval_layout_opaque.rs b/tests/expectations/tests/jsval_layout_opaque.rs index 0edcdc208b..bab7c1bda8 100644 --- a/tests/expectations/tests/jsval_layout_opaque.rs +++ b/tests/expectations/tests/jsval_layout_opaque.rs @@ -272,8 +272,8 @@ pub struct jsval_layout__bindgen_ty_2 { #[repr(C)] #[derive(Copy, Clone)] pub union jsval_layout__bindgen_ty_2__bindgen_ty_1 { - pub i32: i32, - pub u32: u32, + pub i32_: i32, + pub u32_: u32, pub why: JSWhyMagic, _bindgen_union_align: u32, } @@ -298,27 +298,27 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2__bindgen_ty_1() { assert_eq!( unsafe { &(*(::std::ptr::null::())) - .i32 as *const _ as usize + .i32_ as *const _ as usize }, 0usize, concat!( "Offset of field: ", stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), "::", - stringify!(i32) + stringify!(i32_) ) ); assert_eq!( unsafe { &(*(::std::ptr::null::())) - .u32 as *const _ as usize + .u32_ as *const _ as usize }, 0usize, concat!( "Offset of field: ", stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), "::", - stringify!(u32) + stringify!(u32_) ) ); assert_eq!( diff --git a/tests/expectations/tests/jsval_layout_opaque_1_0.rs b/tests/expectations/tests/jsval_layout_opaque_1_0.rs index 46f5b1c912..44acfbc4fe 100644 --- a/tests/expectations/tests/jsval_layout_opaque_1_0.rs +++ b/tests/expectations/tests/jsval_layout_opaque_1_0.rs @@ -320,8 +320,8 @@ pub struct jsval_layout__bindgen_ty_2 { #[repr(C)] #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct jsval_layout__bindgen_ty_2__bindgen_ty_1 { - pub i32: __BindgenUnionField, - pub u32: __BindgenUnionField, + pub i32_: __BindgenUnionField, + pub u32_: __BindgenUnionField, pub why: __BindgenUnionField, pub bindgen_union_field: u32, } @@ -346,27 +346,27 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2__bindgen_ty_1() { assert_eq!( unsafe { &(*(::std::ptr::null::())) - .i32 as *const _ as usize + .i32_ as *const _ as usize }, 0usize, concat!( "Offset of field: ", stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), "::", - stringify!(i32) + stringify!(i32_) ) ); assert_eq!( unsafe { &(*(::std::ptr::null::())) - .u32 as *const _ as usize + .u32_ as *const _ as usize }, 0usize, concat!( "Offset of field: ", stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), "::", - stringify!(u32) + stringify!(u32_) ) ); assert_eq!( diff --git a/tests/expectations/tests/keywords.rs b/tests/expectations/tests/keywords.rs index db57bb08f7..105b6cdce1 100644 --- a/tests/expectations/tests/keywords.rs +++ b/tests/expectations/tests/keywords.rs @@ -8,40 +8,60 @@ )] extern "C" { - pub static mut u8: ::std::os::raw::c_int; + #[link_name = "\u{1}u8"] + pub static mut u8_: ::std::os::raw::c_int; } extern "C" { - pub static mut u16: ::std::os::raw::c_int; + #[link_name = "\u{1}u16"] + pub static mut u16_: ::std::os::raw::c_int; } extern "C" { - pub static mut u32: ::std::os::raw::c_int; + #[link_name = "\u{1}u32"] + pub static mut u32_: ::std::os::raw::c_int; } extern "C" { - pub static mut u64: ::std::os::raw::c_int; + #[link_name = "\u{1}u64"] + pub static mut u64_: ::std::os::raw::c_int; } extern "C" { - pub static mut i8: ::std::os::raw::c_int; + #[link_name = "\u{1}i8"] + pub static mut i8_: ::std::os::raw::c_int; } extern "C" { - pub static mut i16: ::std::os::raw::c_int; + #[link_name = "\u{1}i16"] + pub static mut i16_: ::std::os::raw::c_int; } extern "C" { - pub static mut i32: ::std::os::raw::c_int; + #[link_name = "\u{1}i32"] + pub static mut i32_: ::std::os::raw::c_int; } extern "C" { - pub static mut i64: ::std::os::raw::c_int; + #[link_name = "\u{1}i64"] + pub static mut i64_: ::std::os::raw::c_int; } extern "C" { - pub static mut f32: ::std::os::raw::c_int; + #[link_name = "\u{1}f32"] + pub static mut f32_: ::std::os::raw::c_int; } extern "C" { - pub static mut f64: ::std::os::raw::c_int; + #[link_name = "\u{1}f64"] + pub static mut f64_: ::std::os::raw::c_int; } extern "C" { - pub static mut usize: ::std::os::raw::c_int; + #[link_name = "\u{1}usize"] + pub static mut usize_: ::std::os::raw::c_int; } extern "C" { - pub static mut isize: ::std::os::raw::c_int; + #[link_name = "\u{1}isize"] + pub static mut isize_: ::std::os::raw::c_int; +} +extern "C" { + #[link_name = "\u{1}bool"] + pub static mut bool_: ::std::os::raw::c_int; +} +extern "C" { + #[link_name = "\u{1}str"] + pub static mut str_: ::std::os::raw::c_int; } extern "C" { #[link_name = "\u{1}as"] diff --git a/tests/headers/issue-1382-rust-primitive-types.h b/tests/headers/issue-1382-rust-primitive-types.h new file mode 100644 index 0000000000..4cf346e6c9 --- /dev/null +++ b/tests/headers/issue-1382-rust-primitive-types.h @@ -0,0 +1,34 @@ +typedef int int8_t; +typedef int uint8_t; +typedef int int16_t; +typedef int uint16_t; +typedef int int32_t; +typedef int uint32_t; +typedef int int64_t; +typedef int uint64_t; + +typedef int8_t i8; +typedef uint8_t u8; +typedef int16_t i16; +typedef uint16_t u16; +typedef int32_t i32; +typedef uint32_t u32; +typedef int64_t i64; +typedef uint64_t u64; + +struct Foo { + int i8; + int u8; + int i16; + int u16; + int i32; + int u32; + int i64; + int u64; + int i128; + int u128; + int isize; + int usize; + int f32; + int f64; +}; diff --git a/tests/headers/keywords.h b/tests/headers/keywords.h index 8699ce5f22..0e492316bb 100644 --- a/tests/headers/keywords.h +++ b/tests/headers/keywords.h @@ -10,6 +10,9 @@ int f32; int f64; int usize; int isize; +int bool; +int str; + int as; int box; int crate; From 16189e443c86f06351ef4b8e1c729b67df9d8bc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 8 Jun 2020 12:00:34 +0200 Subject: [PATCH 008/942] Remove unused Token definition. --- src/clang.rs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/clang.rs b/src/clang.rs index 003ed2a68f..12ac46cebd 100644 --- a/src/clang.rs +++ b/src/clang.rs @@ -1540,15 +1540,6 @@ impl Drop for Index { } } -/// A token emitted by clang's lexer. -#[derive(Debug)] -pub struct Token { - /// The kind of token this is. - pub kind: CXTokenKind, - /// A display name for this token. - pub spelling: String, -} - /// A translation unit (or "compilation unit"). pub struct TranslationUnit { x: CXTranslationUnit, From 8078ad6f46e79930317719a514c9b87561f76a56 Mon Sep 17 00:00:00 2001 From: Yisu Rem Wang Date: Thu, 11 Jun 2020 23:13:56 -0700 Subject: [PATCH 009/942] Fix regex to be marked opaque While `std::*` makes informal sense, the user may be mislead into calling `opaque_type("std::*")` instead of the correct `opaque_type("std::.*")` (as I was). --- book/src/cpp.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/book/src/cpp.md b/book/src/cpp.md index 8a790407a7..6fef63912d 100644 --- a/book/src/cpp.md +++ b/book/src/cpp.md @@ -12,10 +12,10 @@ force C++ mode. You probably also want to use `-std=c++14` or similar clang args as well. You pretty much **must** use [whitelisting](./whitelisting.md) when working -with C++ to avoid pulling in all of the `std::*` types, many of which `bindgen` +with C++ to avoid pulling in all of the `std::.*` types, many of which `bindgen` cannot handle. Additionally, you may want to mark other types as [opaque](./opaque.md) that `bindgen` stumbles on. It is recommended to mark -all of `std::*` opaque, and to whitelist only precisely the functions and types +all of `std::.*` opaque, and to whitelist only precisely the functions and types you intend to use. You should read up on the [FAQs](./faq.md) as well. From 0de049e153f2c984ebbddfbe47381c9bc0818b5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 18 May 2020 22:50:36 +0200 Subject: [PATCH 010/942] ci: always try to find a nightly toolchain with rustfmt. --- ci/assert-rustfmt.sh | 7 ++++--- ci/script.sh | 8 ++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/ci/assert-rustfmt.sh b/ci/assert-rustfmt.sh index de8ede82ca..785530cb85 100755 --- a/ci/assert-rustfmt.sh +++ b/ci/assert-rustfmt.sh @@ -3,10 +3,11 @@ set -xeu cd "$(dirname "$0")/.." -rustup update nightly -rustup component add rustfmt --toolchain nightly +TOOLCHAIN="nightly-$(curl https://rust-lang.github.io/rustup-components-history/$(rustup target list --installed | tail -1)/rustfmt)" +rustup update "$TOOLCHAIN" +rustup component add rustfmt --toolchain "$TOOLCHAIN" # Run `rustfmt` on the crate! If `rustfmt` can't make a long line shorter, it # prints an error and exits non-zero, so tell it to kindly shut its yapper and # make sure it doesn't cause us to exit this whole script non-zero. -rustup run nightly cargo fmt -- --check +rustup run "$TOOLCHAIN" cargo fmt -- --check diff --git a/ci/script.sh b/ci/script.sh index e5f64f9653..967defc1e6 100755 --- a/ci/script.sh +++ b/ci/script.sh @@ -17,10 +17,10 @@ fi case "$BINDGEN_JOB" in "test") # Need rustfmt to compare the test expectations. - rustup update nightly - rustup component add rustfmt - rustup component add --toolchain nightly rustfmt - RUSTFMT="$(rustup which rustfmt)" + TOOLCHAIN="nightly-$(curl https://rust-lang.github.io/rustup-components-history/$(rustup target list --installed | tail -1)/rustfmt)" + rustup update "$TOOLCHAIN" + rustup component add rustfmt --toolchain "$TOOLCHAIN" + RUSTFMT="$(rustup which --toolchain "$TOOLCHAIN" rustfmt)" export RUSTFMT cargo test "$BINDGEN_PROFILE" $NO_DEFAULT_FEATURES --features "$BINDGEN_FEATURES" ./ci/assert-no-diff.sh From fc461b8ef72a93997d56e2df44d1b190b6594fad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 19 May 2020 04:37:23 +0200 Subject: [PATCH 011/942] tests: Fix rustfmt check to allow for RUSTFMT env vars. --- tests/tests.rs | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/tests/tests.rs b/tests/tests.rs index 2b435e457e..f4a768c082 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -26,8 +26,17 @@ fn rustfmt(source: String) -> (String, String) { static CHECK_RUSTFMT: Once = Once::new(); CHECK_RUSTFMT.call_once(|| { - let have_working_rustfmt = process::Command::new("rustup") - .args(&["run", "nightly", "rustfmt", "--version"]) + if env::var_os("RUSTFMT").is_some() { + return; + } + + let mut rustfmt = { + let mut p = process::Command::new("rustup"); + p.args(&["run", "nightly", "rustfmt", "--version"]); + p + }; + + let have_working_rustfmt = rustfmt .stdout(process::Stdio::null()) .stderr(process::Stdio::null()) .status() @@ -47,11 +56,17 @@ The latest `rustfmt` is required to run the `bindgen` test suite. Install } }); - let mut child = process::Command::new("rustup") + let mut child = match env::var_os("RUSTFMT") { + Some(r) => process::Command::new(r), + None => { + let mut p = process::Command::new("rustup"); + p.args(&["run", "nightly", "rustfmt"]); + p + } + }; + + let mut child = child .args(&[ - "run", - "nightly", - "rustfmt", "--config-path", concat!(env!("CARGO_MANIFEST_DIR"), "/tests/rustfmt.toml"), ]) From 806887f05f2a28a1c1f6f16c249f094da8f3707d Mon Sep 17 00:00:00 2001 From: eggyal Date: Mon, 15 Jun 2020 16:40:11 +0100 Subject: [PATCH 012/942] Derive traits for newtype aliases (#1802) --- src/codegen/mod.rs | 149 +++++++++++++----- .../tests/issue-1488-enum-new-type.rs | 4 + .../expectations/tests/issue-1488-options.rs | 2 + .../issue-1488-template-alias-new-type.rs | 1 + 4 files changed, 113 insertions(+), 43 deletions(-) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 1cefb9e294..cc9b8b41dd 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -95,6 +95,93 @@ fn root_import( } } +bitflags! { + struct DerivableTraits: u16 { + const DEBUG = 1 << 0; + const DEFAULT = 1 << 1; + const COPY = 1 << 2; + const CLONE = 1 << 3; + const HASH = 1 << 4; + const PARTIAL_ORD = 1 << 5; + const ORD = 1 << 6; + const PARTIAL_EQ = 1 << 7; + const EQ = 1 << 8; + } +} + +fn derives_of_item(item: &Item, ctx: &BindgenContext) -> DerivableTraits { + let mut derivable_traits = DerivableTraits::empty(); + + if item.can_derive_debug(ctx) { + derivable_traits |= DerivableTraits::DEBUG; + } + + if item.can_derive_default(ctx) { + derivable_traits |= DerivableTraits::DEFAULT; + } + + let all_template_params = item.all_template_params(ctx); + + if item.can_derive_copy(ctx) && !item.annotations().disallow_copy() { + derivable_traits |= DerivableTraits::COPY; + + if ctx.options().rust_features().builtin_clone_impls || + !all_template_params.is_empty() + { + // FIXME: This requires extra logic if you have a big array in a + // templated struct. The reason for this is that the magic: + // fn clone(&self) -> Self { *self } + // doesn't work for templates. + // + // It's not hard to fix though. + derivable_traits |= DerivableTraits::CLONE; + } + } + + if item.can_derive_hash(ctx) { + derivable_traits |= DerivableTraits::HASH; + } + + if item.can_derive_partialord(ctx) { + derivable_traits |= DerivableTraits::PARTIAL_ORD; + } + + if item.can_derive_ord(ctx) { + derivable_traits |= DerivableTraits::ORD; + } + + if item.can_derive_partialeq(ctx) { + derivable_traits |= DerivableTraits::PARTIAL_EQ; + } + + if item.can_derive_eq(ctx) { + derivable_traits |= DerivableTraits::EQ; + } + + derivable_traits +} + +impl From for Vec<&'static str> { + fn from(derivable_traits: DerivableTraits) -> Vec<&'static str> { + [ + (DerivableTraits::DEBUG, "Debug"), + (DerivableTraits::DEFAULT, "Default"), + (DerivableTraits::COPY, "Copy"), + (DerivableTraits::CLONE, "Clone"), + (DerivableTraits::HASH, "Hash"), + (DerivableTraits::PARTIAL_ORD, "PartialOrd"), + (DerivableTraits::ORD, "Ord"), + (DerivableTraits::PARTIAL_EQ, "PartialEq"), + (DerivableTraits::EQ, "Eq"), + ] + .iter() + .filter_map(|&(flag, derive)| { + Some(derive).filter(|_| derivable_traits.contains(flag)) + }) + .collect() + } +} + struct CodegenResult<'a> { items: Vec, @@ -793,8 +880,17 @@ impl CodeGenerator for Type { "repr_transparent feature is required to use {:?}", alias_style ); + + let mut attributes = + vec![attributes::repr("transparent")]; + let derivable_traits = derives_of_item(item, ctx); + if !derivable_traits.is_empty() { + let derives: Vec<_> = derivable_traits.into(); + attributes.push(attributes::derives(&derives)) + } + quote! { - #[repr(transparent)] + #( #attributes )* pub struct #rust_name } } @@ -1787,66 +1883,33 @@ impl CodeGenerator for CompInfo { } } - let mut derives = vec![]; - if item.can_derive_debug(ctx) { - derives.push("Debug"); - } else { + let derivable_traits = derives_of_item(item, ctx); + if !derivable_traits.contains(DerivableTraits::DEBUG) { needs_debug_impl = ctx.options().derive_debug && ctx.options().impl_debug } - if item.can_derive_default(ctx) { - derives.push("Default"); - } else { + if !derivable_traits.contains(DerivableTraits::DEFAULT) { needs_default_impl = ctx.options().derive_default && !self.is_forward_declaration(); } let all_template_params = item.all_template_params(ctx); - if item.can_derive_copy(ctx) && !item.annotations().disallow_copy() { - derives.push("Copy"); - - if ctx.options().rust_features().builtin_clone_impls || - !all_template_params.is_empty() - { - // FIXME: This requires extra logic if you have a big array in a - // templated struct. The reason for this is that the magic: - // fn clone(&self) -> Self { *self } - // doesn't work for templates. - // - // It's not hard to fix though. - derives.push("Clone"); - } else { - needs_clone_impl = true; - } - } - - if item.can_derive_hash(ctx) { - derives.push("Hash"); - } - - if item.can_derive_partialord(ctx) { - derives.push("PartialOrd"); - } - - if item.can_derive_ord(ctx) { - derives.push("Ord"); + if derivable_traits.contains(DerivableTraits::COPY) && + !derivable_traits.contains(DerivableTraits::CLONE) + { + needs_clone_impl = true; } - if item.can_derive_partialeq(ctx) { - derives.push("PartialEq"); - } else { + if !derivable_traits.contains(DerivableTraits::PARTIAL_EQ) { needs_partialeq_impl = ctx.options().derive_partialeq && ctx.options().impl_partialeq && ctx.lookup_can_derive_partialeq_or_partialord(item.id()) == CanDerive::Manually; } - if item.can_derive_eq(ctx) { - derives.push("Eq"); - } - + let mut derives: Vec<_> = derivable_traits.into(); derives.extend(item.annotations().derives().iter().map(String::as_str)); if !derives.is_empty() { diff --git a/tests/expectations/tests/issue-1488-enum-new-type.rs b/tests/expectations/tests/issue-1488-enum-new-type.rs index 2e0334a87b..bc8a23d2fa 100644 --- a/tests/expectations/tests/issue-1488-enum-new-type.rs +++ b/tests/expectations/tests/issue-1488-enum-new-type.rs @@ -11,6 +11,7 @@ pub const Foo_A: Foo = 0; pub const Foo_B: Foo = 1; pub type Foo = u32; #[repr(transparent)] +#[derive(Debug, Copy, Clone)] pub struct FooAlias(pub Foo); pub mod Bar { pub type Type = u32; @@ -18,6 +19,7 @@ pub mod Bar { pub const D: Type = 1; } #[repr(transparent)] +#[derive(Debug, Copy, Clone)] pub struct BarAlias(pub Bar::Type); #[repr(u32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] @@ -26,11 +28,13 @@ pub enum Qux { F = 1, } #[repr(transparent)] +#[derive(Debug, Copy, Clone)] pub struct QuxAlias(pub Qux); pub const Baz_G: Baz = 0; pub const Baz_H: Baz = 1; pub type Baz = u32; #[repr(transparent)] +#[derive(Debug, Copy, Clone)] pub struct BazAlias(pub Baz); impl ::std::ops::Deref for BazAlias { type Target = Baz; diff --git a/tests/expectations/tests/issue-1488-options.rs b/tests/expectations/tests/issue-1488-options.rs index ce85c329c1..e429ef3f87 100644 --- a/tests/expectations/tests/issue-1488-options.rs +++ b/tests/expectations/tests/issue-1488-options.rs @@ -9,8 +9,10 @@ pub type OSStatus = ::std::os::raw::c_int; #[repr(transparent)] +#[derive(Debug, Copy, Clone)] pub struct SomePtr(pub *mut ::std::os::raw::c_void); #[repr(transparent)] +#[derive(Debug, Copy, Clone)] pub struct AnotherPtr(pub *mut ::std::os::raw::c_void); impl ::std::ops::Deref for AnotherPtr { type Target = *mut ::std::os::raw::c_void; diff --git a/tests/expectations/tests/issue-1488-template-alias-new-type.rs b/tests/expectations/tests/issue-1488-template-alias-new-type.rs index 94cd5c34e2..fcd712bf4e 100644 --- a/tests/expectations/tests/issue-1488-template-alias-new-type.rs +++ b/tests/expectations/tests/issue-1488-template-alias-new-type.rs @@ -8,4 +8,5 @@ )] #[repr(transparent)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Wrapped(pub T); From b54182b055857b203fccb83a4cb6026ac84207f5 Mon Sep 17 00:00:00 2001 From: Alan Egerton Date: Wed, 10 Jun 2020 10:49:41 +0100 Subject: [PATCH 013/942] Permit IntKind::Custom to represent Paths instead of just Idents --- src/codegen/mod.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index cc9b8b41dd..026c2ff948 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -3328,10 +3328,7 @@ impl TryToRustTy for Type { IntKind::I64 => Ok(quote! { i64 }), IntKind::U64 => Ok(quote! { u64 }), IntKind::Custom { name, .. } => { - let ident = ctx.rust_ident_raw(name); - Ok(quote! { - #ident - }) + Ok(proc_macro2::TokenStream::from_str(name).unwrap()) } IntKind::U128 => { Ok(if ctx.options().rust_features.i128_and_u128 { From 8ea945145b6eb45052f51b776ae33e06ddb6e517 Mon Sep 17 00:00:00 2001 From: Alan Egerton Date: Mon, 15 Jun 2020 08:32:52 +0100 Subject: [PATCH 014/942] Added tests --- bindgen-integration/build.rs | 9 ++++++++- bindgen-integration/src/lib.rs | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs index 38c5849776..d106f7cd65 100644 --- a/bindgen-integration/build.rs +++ b/bindgen-integration/build.rs @@ -1,7 +1,7 @@ extern crate bindgen; extern crate cc; -use bindgen::callbacks::{MacroParsingBehavior, ParseCallbacks}; +use bindgen::callbacks::{MacroParsingBehavior, ParseCallbacks, IntKind}; use bindgen::Builder; use std::collections::HashSet; use std::env; @@ -59,6 +59,13 @@ impl ParseCallbacks for MacroCallback { _ => {} } } + + fn int_macro(&self, _name: &str, _value: i64) -> Option { + Some(IntKind::Custom { + name: "crate::MacroInteger", + is_signed: true, + }) + } } impl Drop for MacroCallback { diff --git a/bindgen-integration/src/lib.rs b/bindgen-integration/src/lib.rs index 8374e2084a..f8791174b7 100755 --- a/bindgen-integration/src/lib.rs +++ b/bindgen-integration/src/lib.rs @@ -11,6 +11,8 @@ use std::os::raw::c_int; #[allow(unused)] use bindings::testing::Bar; // This type is generated from module_raw_line. +type MacroInteger = isize; + #[test] fn test_static_array() { let mut test = unsafe { bindings::Test_COUNTDOWN.as_ptr() }; From ac17fc0f98d865d31f6b6a0417d5ce36cb14a6d3 Mon Sep 17 00:00:00 2001 From: Alan Egerton Date: Mon, 15 Jun 2020 21:53:48 +0100 Subject: [PATCH 015/942] Refined test to verify type of resulting integer --- bindgen-integration/build.rs | 14 +++++++++----- bindgen-integration/cpp/Test.h | 1 + bindgen-integration/src/lib.rs | 6 ++++++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs index d106f7cd65..f042fe9380 100644 --- a/bindgen-integration/build.rs +++ b/bindgen-integration/build.rs @@ -60,11 +60,15 @@ impl ParseCallbacks for MacroCallback { } } - fn int_macro(&self, _name: &str, _value: i64) -> Option { - Some(IntKind::Custom { - name: "crate::MacroInteger", - is_signed: true, - }) + fn int_macro(&self, name: &str, _value: i64) -> Option { + match name { + "TESTMACRO_CUSTOMINTKIND_PATH" => Some(IntKind::Custom { + name: "crate::MacroInteger", + is_signed: true, + }), + + _ => None, + } } } diff --git a/bindgen-integration/cpp/Test.h b/bindgen-integration/cpp/Test.h index 1299337bdc..a20cf4b7ad 100644 --- a/bindgen-integration/cpp/Test.h +++ b/bindgen-integration/cpp/Test.h @@ -5,6 +5,7 @@ #define TESTMACRO_INTEGER 42 #define TESTMACRO_STRING "Hello Preprocessor!" #define TESTMACRO_STRING_EXPANDED TESTMACRO_STRING +#define TESTMACRO_CUSTOMINTKIND_PATH 123 #include diff --git a/bindgen-integration/src/lib.rs b/bindgen-integration/src/lib.rs index f8791174b7..45cf9bca5d 100755 --- a/bindgen-integration/src/lib.rs +++ b/bindgen-integration/src/lib.rs @@ -244,3 +244,9 @@ fn test_item_rename() { member: bindings::bar { foo: 2 }, }; } + +#[test] +fn test_macro_customintkind_path() { + let v: &std::any::Any = &bindings::TESTMACRO_CUSTOMINTKIND_PATH; + assert!(v.is::()) +} From 9f7a203e8fd22eef3824ee7d25c3fa06a280ea98 Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Thu, 18 Jun 2020 23:50:12 -0700 Subject: [PATCH 016/942] Correct copy-paste error duplicating 5.0 config libclang versions before 5.0 need our `runtime` feature enabled, so that we do not suffer a link-time failure when not finding symbols that appeared only in newer libclang versions. --- .travis.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 655d2eaca8..4b7dfd8978 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,22 +14,22 @@ env: - LLVM_VERSION="3.8" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" - LLVM_VERSION="3.8" BINDGEN_JOB="integration" BINDGEN_PROFILE= - LLVM_VERSION="3.8" BINDGEN_JOB="integration" BINDGEN_PROFILE="--release" - - LLVM_VERSION="5.0" BINDGEN_JOB="test" BINDGEN_PROFILE= BINDGEN_NO_DEFAULT_FEATURES="1" - - LLVM_VERSION="5.0" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" BINDGEN_NO_DEFAULT_FEATURES="1" + - LLVM_VERSION="3.8" BINDGEN_JOB="test" BINDGEN_PROFILE= BINDGEN_NO_DEFAULT_FEATURES="1" BINDGEN_FEATURES="runtime" + - LLVM_VERSION="3.8" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" BINDGEN_NO_DEFAULT_FEATURES="1" BINDGEN_FEATURES="runtime" - LLVM_VERSION="3.9" BINDGEN_JOB="test" BINDGEN_PROFILE= - LLVM_VERSION="3.9" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" - LLVM_VERSION="3.9" BINDGEN_JOB="integration" BINDGEN_PROFILE= - LLVM_VERSION="3.9" BINDGEN_JOB="integration" BINDGEN_PROFILE="--release" - - LLVM_VERSION="5.0" BINDGEN_JOB="test" BINDGEN_PROFILE= BINDGEN_NO_DEFAULT_FEATURES="1" - - LLVM_VERSION="5.0" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" BINDGEN_NO_DEFAULT_FEATURES="1" + - LLVM_VERSION="3.9" BINDGEN_JOB="test" BINDGEN_PROFILE= BINDGEN_NO_DEFAULT_FEATURES="1" BINDGEN_FEATURES="runtime" + - LLVM_VERSION="3.9" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" BINDGEN_NO_DEFAULT_FEATURES="1" BINDGEN_FEATURES="runtime" - LLVM_VERSION="4.0" BINDGEN_JOB="test" BINDGEN_PROFILE= - LLVM_VERSION="4.0" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" - LLVM_VERSION="4.0" BINDGEN_JOB="integration" BINDGEN_PROFILE= - LLVM_VERSION="4.0" BINDGEN_JOB="integration" BINDGEN_PROFILE="--release" - - LLVM_VERSION="5.0" BINDGEN_JOB="test" BINDGEN_PROFILE= BINDGEN_NO_DEFAULT_FEATURES="1" - - LLVM_VERSION="5.0" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" BINDGEN_NO_DEFAULT_FEATURES="1" + - LLVM_VERSION="4.0" BINDGEN_JOB="test" BINDGEN_PROFILE= BINDGEN_NO_DEFAULT_FEATURES="1" BINDGEN_FEATURES="runtime" + - LLVM_VERSION="4.0" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" BINDGEN_NO_DEFAULT_FEATURES="1" BINDGEN_FEATURES="runtime" - LLVM_VERSION="5.0" BINDGEN_JOB="test" BINDGEN_PROFILE= - LLVM_VERSION="5.0" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" From 4ee3484e015081d1c98ca504737f4eb764efac40 Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Thu, 18 Jun 2020 23:53:20 -0700 Subject: [PATCH 017/942] Remove reference to nonexistent job --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4b7dfd8978..d22f4a060d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -69,8 +69,6 @@ env: matrix: fast_finish: true - allow_failures: - - env: LLVM_VERSION=9.0 BINDGEN_JOB=rustfmt cache: directories: From 43d4c4ed49e5dbbf35a76d089d2342ea4cbfd260 Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Thu, 18 Jun 2020 23:54:35 -0700 Subject: [PATCH 018/942] Remove webhook that 404's --- .travis.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index d22f4a060d..0628af333e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -85,6 +85,3 @@ after_success: test "$TRAVIS_BRANCH" == "master" && test "$BINDGEN_JOB" == "misc" && ./ci/deploy-book.sh - -notifications: - webhooks: http://build.servo.org:54856/travis From ed8d21558009e631323c7d39d86d22b41f007c86 Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Thu, 18 Jun 2020 23:56:09 -0700 Subject: [PATCH 019/942] Reorder jobs to reduce total runtime --- .travis.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0628af333e..3944e7c0b2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,13 @@ env: global: - CARGO_TARGET_DIR=/tmp/bindgen matrix: + # Miscellaneous tests. + # Start "misc" job first since it runs longer than any other job. + - LLVM_VERSION="9.0" BINDGEN_JOB="misc" + - LLVM_VERSION="9.0" BINDGEN_JOB="quickchecking" + - LLVM_VERSION="9.0" BINDGEN_JOB="msrv" + + # General matrix. - LLVM_VERSION="3.8" BINDGEN_JOB="test" BINDGEN_PROFILE= - LLVM_VERSION="3.8" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" - LLVM_VERSION="3.8" BINDGEN_JOB="integration" BINDGEN_PROFILE= @@ -62,11 +69,6 @@ env: - LLVM_VERSION="9.0" BINDGEN_JOB="expectations" BINDGEN_PROFILE= - LLVM_VERSION="9.0" BINDGEN_JOB="expectations" BINDGEN_PROFILE="--release" - # Miscellaneous tests. - - LLVM_VERSION="9.0" BINDGEN_JOB="misc" - - LLVM_VERSION="9.0" BINDGEN_JOB="quickchecking" - - LLVM_VERSION="9.0" BINDGEN_JOB="msrv" - matrix: fast_finish: true From c462892ad1f2de2599aa6b2cbb6d3ca3e47d6db1 Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Fri, 22 May 2020 16:22:01 -0700 Subject: [PATCH 020/942] Introduce extent to ClangToken --- src/clang.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/clang.rs b/src/clang.rs index 12ac46cebd..f5f4fa1a95 100644 --- a/src/clang.rs +++ b/src/clang.rs @@ -793,13 +793,16 @@ impl<'a> Drop for RawTokens<'a> { } } -/// A raw clang token, that exposes only the kind and spelling. This is a +/// A raw clang token, that exposes only kind, spelling, and extent. This is a /// slightly more convenient version of `CXToken` which owns the spelling -/// string. +/// string and extent. #[derive(Debug)] pub struct ClangToken { spelling: CXString, - /// The kind of token, this is the same as the relevant member from + /// The extent of the token. This is the same as the relevant member from + /// `CXToken`. + pub extent: CXSourceRange, + /// The kind of the token. This is the same as the relevant member from /// `CXToken`. pub kind: CXTokenKind, } @@ -834,7 +837,12 @@ impl<'a> Iterator for ClangTokenIterator<'a> { unsafe { let kind = clang_getTokenKind(*raw); let spelling = clang_getTokenSpelling(self.tu, *raw); - Some(ClangToken { kind, spelling }) + let extent = clang_getTokenExtent(self.tu, *raw); + Some(ClangToken { + kind, + extent, + spelling, + }) } } } From ec6cb2c7c4fc707f9b8ca2a700b6b4f252a3c6e6 Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Sat, 20 Jun 2020 09:47:30 -0700 Subject: [PATCH 021/942] Introduce is_macro_function_like --- src/clang.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/clang.rs b/src/clang.rs index f5f4fa1a95..c3def94db1 100644 --- a/src/clang.rs +++ b/src/clang.rs @@ -239,6 +239,17 @@ impl Cursor { } } + /// Is this Cursor pointing to a function-like macro definition? + /// Returns None if this cannot be determined with the available libclang + /// (it requires 3.9 or greater). + pub fn is_macro_function_like(&self) -> Option { + if clang_Cursor_isMacroFunctionLike::is_loaded() { + Some(unsafe { clang_Cursor_isMacroFunctionLike(self.x) != 0 }) + } else { + None + } + } + /// Get the kind of referent this cursor is pointing to. pub fn kind(&self) -> CXCursorKind { self.x.kind From db672a3eb24ab13750e2265fe559dce4eea5fc68 Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Fri, 22 May 2020 16:50:38 -0700 Subject: [PATCH 022/942] Introduce func_macro to ParseCallbacks trait --- src/callbacks.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/callbacks.rs b/src/callbacks.rs index 1b5445e642..051c1160a3 100644 --- a/src/callbacks.rs +++ b/src/callbacks.rs @@ -35,10 +35,21 @@ pub trait ParseCallbacks: fmt::Debug + UnwindSafe { None } - /// This will be run on every string macro. The callback can not influence the further + /// This will be run on every string macro. The callback cannot influence the further /// treatment of the macro, but may use the value to generate additional code or configuration. fn str_macro(&self, _name: &str, _value: &[u8]) {} + /// This will be run on every function-like macro. The callback cannot + /// influence the further treatment of the macro, but may use the value to + /// generate additional code or configuration. + /// + /// The first parameter represents the name and argument list (including the + /// parentheses) of the function-like macro. The second parameter represents + /// the expansion of the macro. It is not guaranteed that the whitespace of + /// the original is preserved, but it is guaranteed that tokenization will + /// not be changed. + fn func_macro(&self, _name: &str, _value: &str) {} + /// This function should return whether, given an enum variant /// name, and value, this enum variant will forcibly be a constant. fn enum_variant_behavior( From 63b05cb96e552e541835d1793329bbe31147d375 Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Fri, 22 May 2020 16:43:54 -0700 Subject: [PATCH 023/942] Generate func_macro callbacks --- src/callbacks.rs | 6 ++-- src/clang.rs | 47 ++++++++++++++------------- src/ir/var.rs | 83 ++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 107 insertions(+), 29 deletions(-) diff --git a/src/callbacks.rs b/src/callbacks.rs index 051c1160a3..1cd7f37b07 100644 --- a/src/callbacks.rs +++ b/src/callbacks.rs @@ -45,10 +45,8 @@ pub trait ParseCallbacks: fmt::Debug + UnwindSafe { /// /// The first parameter represents the name and argument list (including the /// parentheses) of the function-like macro. The second parameter represents - /// the expansion of the macro. It is not guaranteed that the whitespace of - /// the original is preserved, but it is guaranteed that tokenization will - /// not be changed. - fn func_macro(&self, _name: &str, _value: &str) {} + /// the expansion of the macro as a sequence of tokens. + fn func_macro(&self, _name: &str, _value: &[&[u8]]) {} /// This function should return whether, given an enum variant /// name, and value, this enum variant will forcibly be a constant. diff --git a/src/clang.rs b/src/clang.rs index c3def94db1..3ddf99dc8b 100644 --- a/src/clang.rs +++ b/src/clang.rs @@ -709,30 +709,9 @@ impl Cursor { /// Gets the tokens that correspond to that cursor as `cexpr` tokens. pub fn cexpr_tokens(self) -> Vec { - use cexpr::token; - self.tokens() .iter() - .filter_map(|token| { - let kind = match token.kind { - CXToken_Punctuation => token::Kind::Punctuation, - CXToken_Literal => token::Kind::Literal, - CXToken_Identifier => token::Kind::Identifier, - CXToken_Keyword => token::Kind::Keyword, - // NB: cexpr is not too happy about comments inside - // expressions, so we strip them down here. - CXToken_Comment => return None, - _ => { - error!("Found unexpected token kind: {:?}", token); - return None; - } - }; - - Some(token::Token { - kind, - raw: token.spelling().to_vec().into_boxed_slice(), - }) - }) + .filter_map(|token| token.as_cexpr_token()) .collect() } @@ -826,6 +805,30 @@ impl ClangToken { }; c_str.to_bytes() } + + /// Converts a ClangToken to a `cexpr` token if possible. + pub fn as_cexpr_token(&self) -> Option { + use cexpr::token; + + let kind = match self.kind { + CXToken_Punctuation => token::Kind::Punctuation, + CXToken_Literal => token::Kind::Literal, + CXToken_Identifier => token::Kind::Identifier, + CXToken_Keyword => token::Kind::Keyword, + // NB: cexpr is not too happy about comments inside + // expressions, so we strip them down here. + CXToken_Comment => return None, + _ => { + error!("Found unexpected token kind: {:?}", self); + return None; + } + }; + + Some(token::Token { + kind, + raw: self.spelling().to_vec().into_boxed_slice(), + }) + } } impl Drop for ClangToken { diff --git a/src/ir/var.rs b/src/ir/var.rs index 0f05a3eecf..67b2e348ce 100644 --- a/src/ir/var.rs +++ b/src/ir/var.rs @@ -8,6 +8,7 @@ use super::item::Item; use super::ty::{FloatKind, TypeKind}; use crate::callbacks::MacroParsingBehavior; use crate::clang; +use crate::clang::ClangToken; use crate::parse::{ ClangItemParser, ClangSubItemParser, ParseError, ParseResult, }; @@ -130,6 +131,75 @@ fn default_macro_constant_type(value: i64) -> IntKind { } } +/// Determines whether a set of tokens from a CXCursor_MacroDefinition +/// represent a function-like macro. If so, calls the func_macro callback +/// and returns `Err(ParseError::Continue)` to signal to skip further +/// processing. If conversion to UTF-8 fails (it is performed only where it +/// should be infallible), then `Err(ParseError::Continue)` is returned as well. +fn handle_function_macro( + cursor: &clang::Cursor, + tokens: &[ClangToken], + callbacks: &dyn crate::callbacks::ParseCallbacks, +) -> Result<(), ParseError> { + fn is_abutting(a: &ClangToken, b: &ClangToken) -> bool { + unsafe { + clang_sys::clang_equalLocations( + clang_sys::clang_getRangeEnd(a.extent), + clang_sys::clang_getRangeStart(b.extent), + ) != 0 + } + } + + let is_functional_macro = + // If we have libclang >= 3.9, we can use `is_macro_function_like()` and + // avoid checking for abutting tokens ourselves. + cursor.is_macro_function_like().unwrap_or_else(|| { + // If we cannot get a definitive answer from clang, we instead check + // for a parenthesis token immediately adjacent to (that is, + // abutting) the first token in the macro definition. + // TODO: Once we don't need the fallback check here, we can hoist + // the `is_macro_function_like` check into this function's caller, + // and thus avoid allocating the `tokens` vector for non-functional + // macros. + match tokens.get(0..2) { + Some([a, b]) => is_abutting(&a, &b) && b.spelling() == b"(", + _ => false, + } + }); + + if !is_functional_macro { + return Ok(()); + } + + let is_closing_paren = |t: &ClangToken| { + // Test cheap token kind before comparing exact spellings. + t.kind == clang_sys::CXToken_Punctuation && t.spelling() == b")" + }; + let boundary = tokens.iter().position(is_closing_paren); + + let mut spelled = tokens.iter().map(ClangToken::spelling); + // Add 1, to convert index to length. + let left = spelled + .by_ref() + .take(boundary.ok_or(ParseError::Continue)? + 1); + let left = left.collect::>().concat(); + let left = String::from_utf8(left).map_err(|_| ParseError::Continue)?; + let right = spelled; + // Drop last token with LLVM < 4.0, due to an LLVM bug. + // + // See: + // https://bugs.llvm.org//show_bug.cgi?id=9069 + let len = match (right.len(), crate::clang_version().parsed) { + (len, Some((v, _))) if len > 0 && v < 4 => len - 1, + (len, _) => len, + }; + let right: Vec<_> = right.take(len).collect(); + callbacks.func_macro(&left, &right); + + // We handled the macro, skip future macro processing. + Err(ParseError::Continue) +} + impl ClangSubItemParser for Var { fn parse( cursor: clang::Cursor, @@ -140,6 +210,8 @@ impl ClangSubItemParser for Var { use clang_sys::*; match cursor.kind() { CXCursor_MacroDefinition => { + let tokens: Vec<_> = cursor.tokens().iter().collect(); + if let Some(callbacks) = ctx.parse_callbacks() { match callbacks.will_parse_macro(&cursor.spelling()) { MacroParsingBehavior::Ignore => { @@ -147,9 +219,11 @@ impl ClangSubItemParser for Var { } MacroParsingBehavior::Default => {} } + + handle_function_macro(&cursor, &tokens, callbacks)?; } - let value = parse_macro(ctx, &cursor); + let value = parse_macro(ctx, &tokens); let (id, value) = match value { Some(v) => v, @@ -316,11 +390,14 @@ impl ClangSubItemParser for Var { /// Try and parse a macro using all the macros parsed until now. fn parse_macro( ctx: &BindgenContext, - cursor: &clang::Cursor, + tokens: &[ClangToken], ) -> Option<(Vec, cexpr::expr::EvalResult)> { use cexpr::expr; - let mut cexpr_tokens = cursor.cexpr_tokens(); + let mut cexpr_tokens: Vec<_> = tokens + .iter() + .filter_map(ClangToken::as_cexpr_token) + .collect(); let parser = expr::IdentifierParser::new(ctx.parsed_macros()); From d2e0407563156ed6c2449474c6f8a35389e7171e Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Sat, 23 May 2020 07:14:09 -0700 Subject: [PATCH 024/942] Introduce tests for functional macros --- bindgen-integration/build.rs | 59 ++++++++++++++++++++++++++++++++-- bindgen-integration/cpp/Test.h | 13 ++++++++ 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs index f042fe9380..0a28e8f56b 100644 --- a/bindgen-integration/build.rs +++ b/bindgen-integration/build.rs @@ -12,6 +12,7 @@ use std::sync::{Arc, Mutex, RwLock}; struct MacroCallback { macros: Arc>>, seen_hellos: Mutex, + seen_funcs: Mutex, } impl ParseCallbacks for MacroCallback { @@ -45,6 +46,10 @@ impl ParseCallbacks for MacroCallback { fn str_macro(&self, name: &str, value: &[u8]) { match name { + "TESTMACRO_STRING_EXPR" => { + assert_eq!(value, b"string"); + *self.seen_hellos.lock().unwrap() += 1; + } "TESTMACRO_STRING_EXPANDED" | "TESTMACRO_STRING" | "TESTMACRO_INTEGER" => { @@ -70,15 +75,64 @@ impl ParseCallbacks for MacroCallback { _ => None, } } + + fn func_macro(&self, name: &str, value: &[&[u8]]) { + match name { + "TESTMACRO_NONFUNCTIONAL" => { + panic!("func_macro was called for a non-functional macro"); + } + "TESTMACRO_FUNCTIONAL_NONEMPTY(TESTMACRO_INTEGER)" => { + // Spaces are inserted into the right-hand side of a functional + // macro during reconstruction from the tokenization. This might + // change in the future, but it is safe by the definition of a + // token in C, whereas leaving the spaces out could change + // tokenization. + assert_eq!(value, &[b"-" as &[u8], b"TESTMACRO_INTEGER"]); + *self.seen_funcs.lock().unwrap() += 1; + } + "TESTMACRO_FUNCTIONAL_EMPTY(TESTMACRO_INTEGER)" => { + assert_eq!(value, &[] as &[&[u8]]); + *self.seen_funcs.lock().unwrap() += 1; + } + "TESTMACRO_FUNCTIONAL_TOKENIZED(a,b,c,d,e)" => { + assert_eq!( + value, + &[b"a" as &[u8], b"/", b"b", b"c", b"d", b"##", b"e"] + ); + *self.seen_funcs.lock().unwrap() += 1; + } + "TESTMACRO_FUNCTIONAL_SPLIT(a,b)" => { + assert_eq!(value, &[b"b", b",", b"a"]); + *self.seen_funcs.lock().unwrap() += 1; + } + "TESTMACRO_STRING_FUNC_NON_UTF8(x)" => { + assert_eq!( + value, + &[b"(" as &[u8], b"x", b"\"\xff\xff\"", b")"] + ); + *self.seen_funcs.lock().unwrap() += 1; + } + _ => { + // The system might provide lots of functional macros. + // Ensure we did not miss handling one that we meant to handle. + assert!(!name.starts_with("TESTMACRO_"), "name = {}", name); + } + } + } } impl Drop for MacroCallback { fn drop(&mut self) { assert_eq!( *self.seen_hellos.lock().unwrap(), - 2, + 3, "str_macro handle was not called once for all relevant macros" - ) + ); + assert_eq!( + *self.seen_funcs.lock().unwrap(), + 5, + "func_macro handle was not called once for all relevant macros" + ); } } @@ -102,6 +156,7 @@ fn main() { .parse_callbacks(Box::new(MacroCallback { macros: macros.clone(), seen_hellos: Mutex::new(0), + seen_funcs: Mutex::new(0), })) .blacklist_function("my_prefixed_function_to_remove") .generate() diff --git a/bindgen-integration/cpp/Test.h b/bindgen-integration/cpp/Test.h index a20cf4b7ad..f8b2263f6d 100644 --- a/bindgen-integration/cpp/Test.h +++ b/bindgen-integration/cpp/Test.h @@ -7,6 +7,19 @@ #define TESTMACRO_STRING_EXPANDED TESTMACRO_STRING #define TESTMACRO_CUSTOMINTKIND_PATH 123 +// The following two macros are parsed the same by cexpr, but are semantically +// different. +#define TESTMACRO_NONFUNCTIONAL (TESTMACRO_INTEGER) +#define TESTMACRO_FUNCTIONAL_EMPTY(TESTMACRO_INTEGER) +#define TESTMACRO_FUNCTIONAL_NONEMPTY(TESTMACRO_INTEGER)-TESTMACRO_INTEGER +#define TESTMACRO_FUNCTIONAL_TOKENIZED( a, b ,c,d,e ) a/b c d ## e +#define TESTMACRO_FUNCTIONAL_SPLIT( a, \ + b) b,\ + a +//#define TESTMACRO_INVALID("string") // A conforming preprocessor rejects this +#define TESTMACRO_STRING_EXPR ("string") +#define TESTMACRO_STRING_FUNC_NON_UTF8(x) (x "ᅵᅵ") /* invalid UTF-8 on purpose */ + #include enum { From 871d4725206600e787f7bbc92dcc7b51cc651433 Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Sat, 20 Jun 2020 21:12:50 -0700 Subject: [PATCH 025/942] Rebuild when clang_sys environment changes --- build.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/build.rs b/build.rs index acae6d6722..5d2b9df69b 100644 --- a/build.rs +++ b/build.rs @@ -42,6 +42,13 @@ mod testgen { println!("cargo:rerun-if-changed=tests/headers"); + // On behalf of clang_sys, rebuild ourselves if important configuration + // variables change, to ensure that bindings get rebuilt if the + // underlying libclang changes. + println!("cargo:rerun-if-env-changed=LLVM_CONFIG_PATH"); + println!("cargo:rerun-if-env-changed=LIBCLANG_PATH"); + println!("cargo:rerun-if-env-changed=LIBCLANG_STATIC_PATH"); + for entry in entries { match entry.path().extension().and_then(OsStr::to_str) { Some("h") | Some("hpp") => { From b2ddb9d3dd03c2b096159a1ecab3205151dcee44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 22 Jun 2020 02:02:33 +0200 Subject: [PATCH 026/942] build: move the rebuild dependencies to somewhere where they don't seem test specific. --- build.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/build.rs b/build.rs index 5d2b9df69b..466eadf358 100644 --- a/build.rs +++ b/build.rs @@ -42,13 +42,6 @@ mod testgen { println!("cargo:rerun-if-changed=tests/headers"); - // On behalf of clang_sys, rebuild ourselves if important configuration - // variables change, to ensure that bindings get rebuilt if the - // underlying libclang changes. - println!("cargo:rerun-if-env-changed=LLVM_CONFIG_PATH"); - println!("cargo:rerun-if-env-changed=LIBCLANG_PATH"); - println!("cargo:rerun-if-env-changed=LIBCLANG_STATIC_PATH"); - for entry in entries { match entry.path().extension().and_then(OsStr::to_str) { Some("h") | Some("hpp") => { @@ -78,4 +71,11 @@ mod testgen { fn main() { target::main(); testgen::main(); + + // On behalf of clang_sys, rebuild ourselves if important configuration + // variables change, to ensure that bindings get rebuilt if the + // underlying libclang changes. + println!("cargo:rerun-if-env-changed=LLVM_CONFIG_PATH"); + println!("cargo:rerun-if-env-changed=LIBCLANG_PATH"); + println!("cargo:rerun-if-env-changed=LIBCLANG_STATIC_PATH"); } From 939959a7dffe5e4d91fc7525bc49c1e1ab805c51 Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Sun, 21 Jun 2020 18:29:31 -0700 Subject: [PATCH 027/942] Respect changes to BINDGEN_EXTRA_CLANG_ARGS --- build.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/build.rs b/build.rs index 466eadf358..cb40cb0c1f 100644 --- a/build.rs +++ b/build.rs @@ -78,4 +78,5 @@ fn main() { println!("cargo:rerun-if-env-changed=LLVM_CONFIG_PATH"); println!("cargo:rerun-if-env-changed=LIBCLANG_PATH"); println!("cargo:rerun-if-env-changed=LIBCLANG_STATIC_PATH"); + println!("cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS"); } From 01b1418800de854e6c73be69851fd9d2129dc642 Mon Sep 17 00:00:00 2001 From: Travis Finkenauer Date: Sat, 27 Jun 2020 01:41:35 -0400 Subject: [PATCH 028/942] Output clang args after '--' For command_line_flags(), some arguments (like '--no-record-matches') were added after '--'. The bindgen program would interpret these as clang args. --- src/lib.rs | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 8a8b4e4af3..05d7ea3e2a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -593,20 +593,6 @@ impl Builder { }) .count(); - output_vector.push("--".into()); - - if !self.options.clang_args.is_empty() { - output_vector.extend(self.options.clang_args.iter().cloned()); - } - - if self.input_headers.len() > 1 { - output_vector.extend( - self.input_headers[..self.input_headers.len() - 1] - .iter() - .cloned(), - ); - } - if !self.options.record_matches { output_vector.push("--no-record-matches".into()); } @@ -659,6 +645,22 @@ impl Builder { }) .count(); + // Add clang arguments + + output_vector.push("--".into()); + + if !self.options.clang_args.is_empty() { + output_vector.extend(self.options.clang_args.iter().cloned()); + } + + if self.input_headers.len() > 1 { + output_vector.extend( + self.input_headers[..self.input_headers.len() - 1] + .iter() + .cloned(), + ); + } + output_vector } From 0bc76716e58b3505c432ab695153b6d5b9a85cf4 Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Tue, 23 Jun 2020 05:35:09 -0700 Subject: [PATCH 029/942] Run `cargo +nightly fmt` on expectations Impending overwrites to expectations should be as simple and regular as possible, so get the formatting done here. --- tests/expectations/tests/libclang-3.8/auto.rs | 9 ++-- .../tests/libclang-3.8/call-conv-field.rs | 14 +++++-- .../tests/libclang-3.8/const_bool.rs | 9 ++-- .../tests/libclang-3.8/constant-evaluate.rs | 14 +++++-- .../issue-769-bad-instantiation-test.rs | 38 +++++++++++++---- .../tests/libclang-3.8/mangling-win32.rs | 9 ++-- .../tests/libclang-3.8/objc_template.rs | 8 +++- .../partial-specialization-and-inheritance.rs | 9 ++-- .../type_alias_template_specialized.rs | 9 ++-- tests/expectations/tests/libclang-3.9/auto.rs | 9 ++-- .../tests/libclang-3.9/call-conv-field.rs | 24 +++++++---- .../tests/libclang-3.9/const_bool.rs | 9 ++-- .../tests/libclang-3.9/constant-evaluate.rs | 9 ++-- .../issue-769-bad-instantiation-test.rs | 38 +++++++++++++---- .../tests/libclang-3.9/mangling-win32.rs | 9 ++-- .../tests/libclang-3.9/objc_template.rs | 8 +++- .../partial-specialization-and-inheritance.rs | 9 ++-- .../type_alias_template_specialized.rs | 9 ++-- tests/expectations/tests/libclang-4/auto.rs | 9 ++-- .../tests/libclang-4/call-conv-field.rs | 24 +++++++---- .../tests/libclang-4/const_bool.rs | 9 ++-- .../issue-769-bad-instantiation-test.rs | 41 +++++++++++++++---- .../tests/libclang-4/mangling-win32.rs | 9 ++-- .../tests/libclang-4/objc_template.rs | 13 +++--- .../partial-specialization-and-inheritance.rs | 9 ++-- .../type_alias_template_specialized.rs | 9 ++-- tests/expectations/tests/libclang-5/auto.rs | 9 ++-- .../tests/libclang-5/call-conv-field.rs | 14 +++++-- .../tests/libclang-5/const_bool.rs | 9 ++-- .../issue-769-bad-instantiation-test.rs | 41 +++++++++++++++---- .../tests/libclang-5/mangling-win32.rs | 9 ++-- .../partial-specialization-and-inheritance.rs | 9 ++-- tests/expectations/tests/libclang-9/auto.rs | 9 ++-- .../tests/libclang-9/const_bool.rs | 9 ++-- .../issue-769-bad-instantiation-test.rs | 41 +++++++++++++++---- .../tests/libclang-9/mangling-win32.rs | 9 ++-- .../partial-specialization-and-inheritance.rs | 9 ++-- .../expectations/tests/wasm-import-module.rs | 2 +- 38 files changed, 392 insertions(+), 144 deletions(-) diff --git a/tests/expectations/tests/libclang-3.8/auto.rs b/tests/expectations/tests/libclang-3.8/auto.rs index 920023f349..b5958a04a3 100644 --- a/tests/expectations/tests/libclang-3.8/auto.rs +++ b/tests/expectations/tests/libclang-3.8/auto.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] diff --git a/tests/expectations/tests/libclang-3.8/call-conv-field.rs b/tests/expectations/tests/libclang-3.8/call-conv-field.rs index 1800b6350b..4324f9b7ae 100644 --- a/tests/expectations/tests/libclang-3.8/call-conv-field.rs +++ b/tests/expectations/tests/libclang-3.8/call-conv-field.rs @@ -12,7 +12,9 @@ #[derive(Default, Copy, Clone)] pub struct JNINativeInterface_ { pub GetVersion: ::std::option::Option< - unsafe extern "stdcall" fn(env: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int, + unsafe extern "stdcall" fn( + env: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int, >, pub __hack: ::std::os::raw::c_ulonglong, } @@ -29,7 +31,10 @@ fn bindgen_test_layout_JNINativeInterface_() { concat!("Alignment of ", stringify!(JNINativeInterface_)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).GetVersion as *const _ as usize }, + unsafe { + &(*(::std::ptr::null::())).GetVersion + as *const _ as usize + }, 0usize, concat!( "Offset of field: ", @@ -39,7 +44,10 @@ fn bindgen_test_layout_JNINativeInterface_() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).__hack as *const _ as usize }, + unsafe { + &(*(::std::ptr::null::())).__hack as *const _ + as usize + }, 8usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/libclang-3.8/const_bool.rs b/tests/expectations/tests/libclang-3.8/const_bool.rs index af5adcaf8e..c20c554661 100644 --- a/tests/expectations/tests/libclang-3.8/const_bool.rs +++ b/tests/expectations/tests/libclang-3.8/const_bool.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] extern "C" { #[link_name = "\u{1}_ZL1k"] diff --git a/tests/expectations/tests/libclang-3.8/constant-evaluate.rs b/tests/expectations/tests/libclang-3.8/constant-evaluate.rs index 73455f3a6a..e988b40f44 100644 --- a/tests/expectations/tests/libclang-3.8/constant-evaluate.rs +++ b/tests/expectations/tests/libclang-3.8/constant-evaluate.rs @@ -1,14 +1,20 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] pub const foo: _bindgen_ty_1 = _bindgen_ty_1::foo; pub const bar: _bindgen_ty_1 = _bindgen_ty_1::bar; #[repr(u32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub enum _bindgen_ty_1 { foo = 4, bar = 8, } +pub enum _bindgen_ty_1 { + foo = 4, + bar = 8, +} pub type EasyToOverflow = ::std::os::raw::c_ulonglong; pub const k: EasyToOverflow = 2147483648; extern "C" { diff --git a/tests/expectations/tests/libclang-3.8/issue-769-bad-instantiation-test.rs b/tests/expectations/tests/libclang-3.8/issue-769-bad-instantiation-test.rs index 0603873df2..48a0785024 100644 --- a/tests/expectations/tests/libclang-3.8/issue-769-bad-instantiation-test.rs +++ b/tests/expectations/tests/libclang-3.8/issue-769-bad-instantiation-test.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![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 { @@ -26,14 +29,35 @@ pub mod root { 4usize, concat!( "Size of template specialization: ", - stringify ! ( root :: Rooted < :: std :: os :: raw :: c_int > ) + stringify!(root::Rooted<::std::os::raw::c_int>) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 4usize, + concat!( + "Alignment of template specialization: ", + stringify!(root::Rooted<::std::os::raw::c_int>) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < root :: Rooted < :: std :: os :: raw :: c_int > > ( ) , 4usize , concat ! ( "Alignment of template specialization: " , stringify ! ( root :: Rooted < :: std :: os :: raw :: c_int > ) ) ); } #[test] fn __bindgen_test_layout_Rooted_open0_int_close0_instantiation_1() { - assert_eq ! ( :: std :: mem :: size_of :: < root :: Rooted < :: std :: os :: raw :: c_int > > ( ) , 4usize , concat ! ( "Size of template specialization: " , stringify ! ( root :: Rooted < :: std :: os :: raw :: c_int > ) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < root :: Rooted < :: std :: os :: raw :: c_int > > ( ) , 4usize , concat ! ( "Alignment of template specialization: " , stringify ! ( root :: Rooted < :: std :: os :: raw :: c_int > ) ) ); + assert_eq!( + ::std::mem::size_of::>(), + 4usize, + concat!( + "Size of template specialization: ", + stringify!(root::Rooted<::std::os::raw::c_int>) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 4usize, + concat!( + "Alignment of template specialization: ", + stringify!(root::Rooted<::std::os::raw::c_int>) + ) + ); } } diff --git a/tests/expectations/tests/libclang-3.8/mangling-win32.rs b/tests/expectations/tests/libclang-3.8/mangling-win32.rs index e920634ed3..f219089f12 100644 --- a/tests/expectations/tests/libclang-3.8/mangling-win32.rs +++ b/tests/expectations/tests/libclang-3.8/mangling-win32.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] extern "C" { pub fn foo(); diff --git a/tests/expectations/tests/libclang-3.8/objc_template.rs b/tests/expectations/tests/libclang-3.8/objc_template.rs index 23a6de909d..22a6e17e11 100644 --- a/tests/expectations/tests/libclang-3.8/objc_template.rs +++ b/tests/expectations/tests/libclang-3.8/objc_template.rs @@ -1,7 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #![cfg(target_os = "macos")] #[macro_use] diff --git a/tests/expectations/tests/libclang-3.8/partial-specialization-and-inheritance.rs b/tests/expectations/tests/libclang-3.8/partial-specialization-and-inheritance.rs index 3e3eb9c58b..20b2f0242d 100644 --- a/tests/expectations/tests/libclang-3.8/partial-specialization-and-inheritance.rs +++ b/tests/expectations/tests/libclang-3.8/partial-specialization-and-inheritance.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] diff --git a/tests/expectations/tests/libclang-3.8/type_alias_template_specialized.rs b/tests/expectations/tests/libclang-3.8/type_alias_template_specialized.rs index a0d9ade6d0..6c171aeccf 100644 --- a/tests/expectations/tests/libclang-3.8/type_alias_template_specialized.rs +++ b/tests/expectations/tests/libclang-3.8/type_alias_template_specialized.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] diff --git a/tests/expectations/tests/libclang-3.9/auto.rs b/tests/expectations/tests/libclang-3.9/auto.rs index 2d7dfa3a85..ab0c7dc029 100644 --- a/tests/expectations/tests/libclang-3.9/auto.rs +++ b/tests/expectations/tests/libclang-3.9/auto.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] diff --git a/tests/expectations/tests/libclang-3.9/call-conv-field.rs b/tests/expectations/tests/libclang-3.9/call-conv-field.rs index 7007d2217a..ea7c0e40f5 100644 --- a/tests/expectations/tests/libclang-3.9/call-conv-field.rs +++ b/tests/expectations/tests/libclang-3.9/call-conv-field.rs @@ -1,16 +1,20 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #![cfg(not(test))] - #[repr(C)] #[derive(Default, Copy, Clone)] pub struct JNINativeInterface_ { pub GetVersion: ::std::option::Option< - unsafe extern "stdcall" fn(env: *mut ::std::os::raw::c_void) - -> ::std::os::raw::c_int, + unsafe extern "stdcall" fn( + env: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int, >, pub __hack: ::std::os::raw::c_ulonglong, } @@ -27,7 +31,10 @@ fn bindgen_test_layout_JNINativeInterface_() { concat!("Alignment of ", stringify!(JNINativeInterface_)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).GetVersion as *const _ as usize }, + unsafe { + &(*(::std::ptr::null::())).GetVersion + as *const _ as usize + }, 0usize, concat!( "Offset of field: ", @@ -37,7 +44,10 @@ fn bindgen_test_layout_JNINativeInterface_() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).__hack as *const _ as usize }, + unsafe { + &(*(::std::ptr::null::())).__hack as *const _ + as usize + }, 8usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/libclang-3.9/const_bool.rs b/tests/expectations/tests/libclang-3.9/const_bool.rs index 14f5139400..5be7850369 100644 --- a/tests/expectations/tests/libclang-3.9/const_bool.rs +++ b/tests/expectations/tests/libclang-3.9/const_bool.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] pub const k: bool = true; #[repr(C)] diff --git a/tests/expectations/tests/libclang-3.9/constant-evaluate.rs b/tests/expectations/tests/libclang-3.9/constant-evaluate.rs index 7e6fcd60de..87dafd63a4 100644 --- a/tests/expectations/tests/libclang-3.9/constant-evaluate.rs +++ b/tests/expectations/tests/libclang-3.9/constant-evaluate.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] pub const foo: _bindgen_ty_1 = _bindgen_ty_1::foo; pub const bar: _bindgen_ty_1 = _bindgen_ty_1::bar; diff --git a/tests/expectations/tests/libclang-3.9/issue-769-bad-instantiation-test.rs b/tests/expectations/tests/libclang-3.9/issue-769-bad-instantiation-test.rs index 0603873df2..48a0785024 100644 --- a/tests/expectations/tests/libclang-3.9/issue-769-bad-instantiation-test.rs +++ b/tests/expectations/tests/libclang-3.9/issue-769-bad-instantiation-test.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![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 { @@ -26,14 +29,35 @@ pub mod root { 4usize, concat!( "Size of template specialization: ", - stringify ! ( root :: Rooted < :: std :: os :: raw :: c_int > ) + stringify!(root::Rooted<::std::os::raw::c_int>) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 4usize, + concat!( + "Alignment of template specialization: ", + stringify!(root::Rooted<::std::os::raw::c_int>) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < root :: Rooted < :: std :: os :: raw :: c_int > > ( ) , 4usize , concat ! ( "Alignment of template specialization: " , stringify ! ( root :: Rooted < :: std :: os :: raw :: c_int > ) ) ); } #[test] fn __bindgen_test_layout_Rooted_open0_int_close0_instantiation_1() { - assert_eq ! ( :: std :: mem :: size_of :: < root :: Rooted < :: std :: os :: raw :: c_int > > ( ) , 4usize , concat ! ( "Size of template specialization: " , stringify ! ( root :: Rooted < :: std :: os :: raw :: c_int > ) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < root :: Rooted < :: std :: os :: raw :: c_int > > ( ) , 4usize , concat ! ( "Alignment of template specialization: " , stringify ! ( root :: Rooted < :: std :: os :: raw :: c_int > ) ) ); + assert_eq!( + ::std::mem::size_of::>(), + 4usize, + concat!( + "Size of template specialization: ", + stringify!(root::Rooted<::std::os::raw::c_int>) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 4usize, + concat!( + "Alignment of template specialization: ", + stringify!(root::Rooted<::std::os::raw::c_int>) + ) + ); } } diff --git a/tests/expectations/tests/libclang-3.9/mangling-win32.rs b/tests/expectations/tests/libclang-3.9/mangling-win32.rs index ad4ac42a15..24cd4eb0df 100644 --- a/tests/expectations/tests/libclang-3.9/mangling-win32.rs +++ b/tests/expectations/tests/libclang-3.9/mangling-win32.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] extern "C" { pub fn foo(); diff --git a/tests/expectations/tests/libclang-3.9/objc_template.rs b/tests/expectations/tests/libclang-3.9/objc_template.rs index 23a6de909d..22a6e17e11 100644 --- a/tests/expectations/tests/libclang-3.9/objc_template.rs +++ b/tests/expectations/tests/libclang-3.9/objc_template.rs @@ -1,7 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #![cfg(target_os = "macos")] #[macro_use] diff --git a/tests/expectations/tests/libclang-3.9/partial-specialization-and-inheritance.rs b/tests/expectations/tests/libclang-3.9/partial-specialization-and-inheritance.rs index 97d2eabe41..06ff60599c 100644 --- a/tests/expectations/tests/libclang-3.9/partial-specialization-and-inheritance.rs +++ b/tests/expectations/tests/libclang-3.9/partial-specialization-and-inheritance.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] diff --git a/tests/expectations/tests/libclang-3.9/type_alias_template_specialized.rs b/tests/expectations/tests/libclang-3.9/type_alias_template_specialized.rs index a0d9ade6d0..6c171aeccf 100644 --- a/tests/expectations/tests/libclang-3.9/type_alias_template_specialized.rs +++ b/tests/expectations/tests/libclang-3.9/type_alias_template_specialized.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] diff --git a/tests/expectations/tests/libclang-4/auto.rs b/tests/expectations/tests/libclang-4/auto.rs index 2d7dfa3a85..ab0c7dc029 100644 --- a/tests/expectations/tests/libclang-4/auto.rs +++ b/tests/expectations/tests/libclang-4/auto.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] diff --git a/tests/expectations/tests/libclang-4/call-conv-field.rs b/tests/expectations/tests/libclang-4/call-conv-field.rs index 7007d2217a..ea7c0e40f5 100644 --- a/tests/expectations/tests/libclang-4/call-conv-field.rs +++ b/tests/expectations/tests/libclang-4/call-conv-field.rs @@ -1,16 +1,20 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #![cfg(not(test))] - #[repr(C)] #[derive(Default, Copy, Clone)] pub struct JNINativeInterface_ { pub GetVersion: ::std::option::Option< - unsafe extern "stdcall" fn(env: *mut ::std::os::raw::c_void) - -> ::std::os::raw::c_int, + unsafe extern "stdcall" fn( + env: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int, >, pub __hack: ::std::os::raw::c_ulonglong, } @@ -27,7 +31,10 @@ fn bindgen_test_layout_JNINativeInterface_() { concat!("Alignment of ", stringify!(JNINativeInterface_)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).GetVersion as *const _ as usize }, + unsafe { + &(*(::std::ptr::null::())).GetVersion + as *const _ as usize + }, 0usize, concat!( "Offset of field: ", @@ -37,7 +44,10 @@ fn bindgen_test_layout_JNINativeInterface_() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).__hack as *const _ as usize }, + unsafe { + &(*(::std::ptr::null::())).__hack as *const _ + as usize + }, 8usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/libclang-4/const_bool.rs b/tests/expectations/tests/libclang-4/const_bool.rs index 14f5139400..5be7850369 100644 --- a/tests/expectations/tests/libclang-4/const_bool.rs +++ b/tests/expectations/tests/libclang-4/const_bool.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] pub const k: bool = true; #[repr(C)] diff --git a/tests/expectations/tests/libclang-4/issue-769-bad-instantiation-test.rs b/tests/expectations/tests/libclang-4/issue-769-bad-instantiation-test.rs index 86fad78d46..daceec2e22 100644 --- a/tests/expectations/tests/libclang-4/issue-769-bad-instantiation-test.rs +++ b/tests/expectations/tests/libclang-4/issue-769-bad-instantiation-test.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![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 { @@ -27,14 +30,36 @@ pub mod root { 4usize, concat!( "Size of template specialization: ", - stringify ! ( root :: Rooted < :: std :: os :: raw :: c_int > ) + stringify!(root::Rooted<::std::os::raw::c_int>) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 4usize, + concat!( + "Alignment of template specialization: ", + stringify!(root::Rooted<::std::os::raw::c_int>) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < root :: Rooted < :: std :: os :: raw :: c_int > > ( ) , 4usize , concat ! ( "Alignment of template specialization: " , stringify ! ( root :: Rooted < :: std :: os :: raw :: c_int > ) ) ); } #[test] - fn __bindgen_test_layout_Rooted_open0_AutoValueVector_Alias_close0_instantiation() { - assert_eq ! ( :: std :: mem :: size_of :: < root :: Rooted < root :: AutoValueVector_Alias > > ( ) , 4usize , concat ! ( "Size of template specialization: " , stringify ! ( root :: Rooted < root :: AutoValueVector_Alias > ) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < root :: Rooted < root :: AutoValueVector_Alias > > ( ) , 4usize , concat ! ( "Alignment of template specialization: " , stringify ! ( root :: Rooted < root :: AutoValueVector_Alias > ) ) ); + fn __bindgen_test_layout_Rooted_open0_AutoValueVector_Alias_close0_instantiation( + ) { + assert_eq!( + ::std::mem::size_of::>(), + 4usize, + concat!( + "Size of template specialization: ", + stringify!(root::Rooted) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 4usize, + concat!( + "Alignment of template specialization: ", + stringify!(root::Rooted) + ) + ); } } diff --git a/tests/expectations/tests/libclang-4/mangling-win32.rs b/tests/expectations/tests/libclang-4/mangling-win32.rs index ad4ac42a15..24cd4eb0df 100644 --- a/tests/expectations/tests/libclang-4/mangling-win32.rs +++ b/tests/expectations/tests/libclang-4/mangling-win32.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] extern "C" { pub fn foo(); diff --git a/tests/expectations/tests/libclang-4/objc_template.rs b/tests/expectations/tests/libclang-4/objc_template.rs index 25276c00fc..b4c117044c 100644 --- a/tests/expectations/tests/libclang-4/objc_template.rs +++ b/tests/expectations/tests/libclang-4/objc_template.rs @@ -1,9 +1,12 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - -#![cfg(target_os="macos")] +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] +#![cfg(target_os = "macos")] #[macro_use] extern crate objc; @@ -30,7 +33,7 @@ pub trait IFoo: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - msg_send!(self , get) + msg_send!(self, get) } } #[repr(transparent)] diff --git a/tests/expectations/tests/libclang-4/partial-specialization-and-inheritance.rs b/tests/expectations/tests/libclang-4/partial-specialization-and-inheritance.rs index 97d2eabe41..06ff60599c 100644 --- a/tests/expectations/tests/libclang-4/partial-specialization-and-inheritance.rs +++ b/tests/expectations/tests/libclang-4/partial-specialization-and-inheritance.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] diff --git a/tests/expectations/tests/libclang-4/type_alias_template_specialized.rs b/tests/expectations/tests/libclang-4/type_alias_template_specialized.rs index a09323a8f2..89e37fe81e 100644 --- a/tests/expectations/tests/libclang-4/type_alias_template_specialized.rs +++ b/tests/expectations/tests/libclang-4/type_alias_template_specialized.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #[repr(C)] #[derive(Debug, Copy, Clone)] diff --git a/tests/expectations/tests/libclang-5/auto.rs b/tests/expectations/tests/libclang-5/auto.rs index 2d7dfa3a85..ab0c7dc029 100644 --- a/tests/expectations/tests/libclang-5/auto.rs +++ b/tests/expectations/tests/libclang-5/auto.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] diff --git a/tests/expectations/tests/libclang-5/call-conv-field.rs b/tests/expectations/tests/libclang-5/call-conv-field.rs index 9cb9606f56..ea7c0e40f5 100644 --- a/tests/expectations/tests/libclang-5/call-conv-field.rs +++ b/tests/expectations/tests/libclang-5/call-conv-field.rs @@ -12,7 +12,9 @@ #[derive(Default, Copy, Clone)] pub struct JNINativeInterface_ { pub GetVersion: ::std::option::Option< - unsafe extern "stdcall" fn(env: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int, + unsafe extern "stdcall" fn( + env: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int, >, pub __hack: ::std::os::raw::c_ulonglong, } @@ -29,7 +31,10 @@ fn bindgen_test_layout_JNINativeInterface_() { concat!("Alignment of ", stringify!(JNINativeInterface_)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).GetVersion as *const _ as usize }, + unsafe { + &(*(::std::ptr::null::())).GetVersion + as *const _ as usize + }, 0usize, concat!( "Offset of field: ", @@ -39,7 +44,10 @@ fn bindgen_test_layout_JNINativeInterface_() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).__hack as *const _ as usize }, + unsafe { + &(*(::std::ptr::null::())).__hack as *const _ + as usize + }, 8usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/libclang-5/const_bool.rs b/tests/expectations/tests/libclang-5/const_bool.rs index 14f5139400..5be7850369 100644 --- a/tests/expectations/tests/libclang-5/const_bool.rs +++ b/tests/expectations/tests/libclang-5/const_bool.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] pub const k: bool = true; #[repr(C)] diff --git a/tests/expectations/tests/libclang-5/issue-769-bad-instantiation-test.rs b/tests/expectations/tests/libclang-5/issue-769-bad-instantiation-test.rs index 86fad78d46..daceec2e22 100644 --- a/tests/expectations/tests/libclang-5/issue-769-bad-instantiation-test.rs +++ b/tests/expectations/tests/libclang-5/issue-769-bad-instantiation-test.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![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 { @@ -27,14 +30,36 @@ pub mod root { 4usize, concat!( "Size of template specialization: ", - stringify ! ( root :: Rooted < :: std :: os :: raw :: c_int > ) + stringify!(root::Rooted<::std::os::raw::c_int>) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 4usize, + concat!( + "Alignment of template specialization: ", + stringify!(root::Rooted<::std::os::raw::c_int>) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < root :: Rooted < :: std :: os :: raw :: c_int > > ( ) , 4usize , concat ! ( "Alignment of template specialization: " , stringify ! ( root :: Rooted < :: std :: os :: raw :: c_int > ) ) ); } #[test] - fn __bindgen_test_layout_Rooted_open0_AutoValueVector_Alias_close0_instantiation() { - assert_eq ! ( :: std :: mem :: size_of :: < root :: Rooted < root :: AutoValueVector_Alias > > ( ) , 4usize , concat ! ( "Size of template specialization: " , stringify ! ( root :: Rooted < root :: AutoValueVector_Alias > ) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < root :: Rooted < root :: AutoValueVector_Alias > > ( ) , 4usize , concat ! ( "Alignment of template specialization: " , stringify ! ( root :: Rooted < root :: AutoValueVector_Alias > ) ) ); + fn __bindgen_test_layout_Rooted_open0_AutoValueVector_Alias_close0_instantiation( + ) { + assert_eq!( + ::std::mem::size_of::>(), + 4usize, + concat!( + "Size of template specialization: ", + stringify!(root::Rooted) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 4usize, + concat!( + "Alignment of template specialization: ", + stringify!(root::Rooted) + ) + ); } } diff --git a/tests/expectations/tests/libclang-5/mangling-win32.rs b/tests/expectations/tests/libclang-5/mangling-win32.rs index ad4ac42a15..24cd4eb0df 100644 --- a/tests/expectations/tests/libclang-5/mangling-win32.rs +++ b/tests/expectations/tests/libclang-5/mangling-win32.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] extern "C" { pub fn foo(); diff --git a/tests/expectations/tests/libclang-5/partial-specialization-and-inheritance.rs b/tests/expectations/tests/libclang-5/partial-specialization-and-inheritance.rs index 97d2eabe41..06ff60599c 100644 --- a/tests/expectations/tests/libclang-5/partial-specialization-and-inheritance.rs +++ b/tests/expectations/tests/libclang-5/partial-specialization-and-inheritance.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] diff --git a/tests/expectations/tests/libclang-9/auto.rs b/tests/expectations/tests/libclang-9/auto.rs index 2d7dfa3a85..ab0c7dc029 100644 --- a/tests/expectations/tests/libclang-9/auto.rs +++ b/tests/expectations/tests/libclang-9/auto.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] diff --git a/tests/expectations/tests/libclang-9/const_bool.rs b/tests/expectations/tests/libclang-9/const_bool.rs index 14f5139400..5be7850369 100644 --- a/tests/expectations/tests/libclang-9/const_bool.rs +++ b/tests/expectations/tests/libclang-9/const_bool.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] pub const k: bool = true; #[repr(C)] diff --git a/tests/expectations/tests/libclang-9/issue-769-bad-instantiation-test.rs b/tests/expectations/tests/libclang-9/issue-769-bad-instantiation-test.rs index 86fad78d46..daceec2e22 100644 --- a/tests/expectations/tests/libclang-9/issue-769-bad-instantiation-test.rs +++ b/tests/expectations/tests/libclang-9/issue-769-bad-instantiation-test.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![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 { @@ -27,14 +30,36 @@ pub mod root { 4usize, concat!( "Size of template specialization: ", - stringify ! ( root :: Rooted < :: std :: os :: raw :: c_int > ) + stringify!(root::Rooted<::std::os::raw::c_int>) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 4usize, + concat!( + "Alignment of template specialization: ", + stringify!(root::Rooted<::std::os::raw::c_int>) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < root :: Rooted < :: std :: os :: raw :: c_int > > ( ) , 4usize , concat ! ( "Alignment of template specialization: " , stringify ! ( root :: Rooted < :: std :: os :: raw :: c_int > ) ) ); } #[test] - fn __bindgen_test_layout_Rooted_open0_AutoValueVector_Alias_close0_instantiation() { - assert_eq ! ( :: std :: mem :: size_of :: < root :: Rooted < root :: AutoValueVector_Alias > > ( ) , 4usize , concat ! ( "Size of template specialization: " , stringify ! ( root :: Rooted < root :: AutoValueVector_Alias > ) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < root :: Rooted < root :: AutoValueVector_Alias > > ( ) , 4usize , concat ! ( "Alignment of template specialization: " , stringify ! ( root :: Rooted < root :: AutoValueVector_Alias > ) ) ); + fn __bindgen_test_layout_Rooted_open0_AutoValueVector_Alias_close0_instantiation( + ) { + assert_eq!( + ::std::mem::size_of::>(), + 4usize, + concat!( + "Size of template specialization: ", + stringify!(root::Rooted) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 4usize, + concat!( + "Alignment of template specialization: ", + stringify!(root::Rooted) + ) + ); } } diff --git a/tests/expectations/tests/libclang-9/mangling-win32.rs b/tests/expectations/tests/libclang-9/mangling-win32.rs index ad4ac42a15..24cd4eb0df 100644 --- a/tests/expectations/tests/libclang-9/mangling-win32.rs +++ b/tests/expectations/tests/libclang-9/mangling-win32.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] extern "C" { pub fn foo(); diff --git a/tests/expectations/tests/libclang-9/partial-specialization-and-inheritance.rs b/tests/expectations/tests/libclang-9/partial-specialization-and-inheritance.rs index 97d2eabe41..06ff60599c 100644 --- a/tests/expectations/tests/libclang-9/partial-specialization-and-inheritance.rs +++ b/tests/expectations/tests/libclang-9/partial-specialization-and-inheritance.rs @@ -1,8 +1,11 @@ /* automatically generated by rust-bindgen */ - -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] - +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] diff --git a/tests/expectations/tests/wasm-import-module.rs b/tests/expectations/tests/wasm-import-module.rs index afbc58462a..509fd56064 100644 --- a/tests/expectations/tests/wasm-import-module.rs +++ b/tests/expectations/tests/wasm-import-module.rs @@ -10,4 +10,4 @@ #[link(wasm_import_module = "test-module")] extern "C" { pub fn test_function(); -} \ No newline at end of file +} From 21ca3f128833c4e69cb8ba35e242f7d1c548056b Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Mon, 22 Jun 2020 18:03:48 -0700 Subject: [PATCH 030/942] Add option to disable generated header comment --- src/lib.rs | 15 +++++++++++++++ src/options.rs | 8 ++++++++ 2 files changed, 23 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 05d7ea3e2a..2099726783 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -484,6 +484,10 @@ impl Builder { output_vector.push("--disable-nested-struct-naming".into()); } + if self.options.disable_header_comment { + output_vector.push("--disable-header-comment".into()); + } + if !self.options.codegen_config.functions() { output_vector.push("--ignore-functions".into()); } @@ -714,6 +718,13 @@ impl Builder { self } + /// Disable insertion of bindgen's version identifier into generated + /// bindings. + pub fn disable_header_comment(mut self) -> Self { + self.options.disable_header_comment = true; + self + } + /// Set the output graphviz file. pub fn emit_ir_graphviz>(mut self, path: T) -> Builder { let path = path.into(); @@ -1664,6 +1675,9 @@ struct BindgenOptions { /// True if we should avoid generating nested struct names. disable_nested_struct_naming: bool, + /// True if we should avoid embedding version identifiers into source code. + disable_header_comment: bool, + /// True if we should generate layout tests for generated structures. layout_tests: bool, @@ -1925,6 +1939,7 @@ impl Default for BindgenOptions { enable_function_attribute_detection: false, disable_name_namespacing: false, disable_nested_struct_naming: false, + disable_header_comment: false, use_core: false, ctypes_prefix: None, namespaced_constants: true, diff --git a/src/options.rs b/src/options.rs index c2de1e5a15..0add7b4cbe 100644 --- a/src/options.rs +++ b/src/options.rs @@ -272,6 +272,10 @@ where .help( "Disable support for native Rust unions.", ), + Arg::with_name("disable-header-comment") + .long("disable-header-comment") + .help("Suppress insertion of bindgen's version identifier into generated bindings.") + .multiple(true), Arg::with_name("ignore-functions") .long("ignore-functions") .help( @@ -676,6 +680,10 @@ where builder = builder.disable_untagged_union(); } + if matches.is_present("disable-header-comment") { + builder = builder.disable_header_comment(); + } + if matches.is_present("ignore-functions") { builder = builder.ignore_functions(); } From 3dafdca17bd1c319f1ca45baee439cac97b0321f Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Mon, 22 Jun 2020 18:09:06 -0700 Subject: [PATCH 031/942] Disable generated comment in expectations test --- tests/stylo_sanity.rs | 1 + tests/tests.rs | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/stylo_sanity.rs b/tests/stylo_sanity.rs index 54fbb64e1e..3f59275c04 100755 --- a/tests/stylo_sanity.rs +++ b/tests/stylo_sanity.rs @@ -32,6 +32,7 @@ fn sanity_check_can_generate_stylo_bindings() { bindgen::builder() .time_phases(true) + .disable_header_comment() .header(concat!(env!("CARGO_MANIFEST_DIR"), "/tests/stylo.hpp")) .whitelist_function("Servo_.*") .whitelist_function("Gecko_.*") diff --git a/tests/tests.rs b/tests/tests.rs index f4a768c082..9bf11da947 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -244,7 +244,7 @@ fn builder() -> Builder { #[cfg(feature = "logging")] let _ = env_logger::try_init(); - bindgen::builder() + bindgen::builder().disable_header_comment() } fn create_bindgen_builder(header: &PathBuf) -> Result, Error> { @@ -304,6 +304,7 @@ fn create_bindgen_builder(header: &PathBuf) -> Result, Error> { // more control. "--no-rustfmt-bindings", "--with-derive-default", + "--disable-header-comment", header_str, "--raw-line", "", From d4f786ff4129cc8f0d218361bdd0fb2608c5823c Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Mon, 22 Jun 2020 18:07:08 -0700 Subject: [PATCH 032/942] Emit bindgen version in generated header Update expectations --- src/lib.rs | 11 ++++++++--- tests/expectations/tests/16-byte-alignment.rs | 2 -- tests/expectations/tests/16-byte-alignment_1_0.rs | 2 -- tests/expectations/tests/381-decltype-alias.rs | 2 -- tests/expectations/tests/accessors.rs | 2 -- tests/expectations/tests/annotation_hide.rs | 2 -- tests/expectations/tests/anon_enum.rs | 2 -- tests/expectations/tests/anon_enum_trait.rs | 2 -- tests/expectations/tests/anon_enum_whitelist.rs | 2 -- tests/expectations/tests/anon_struct_in_union.rs | 2 -- tests/expectations/tests/anon_struct_in_union_1_0.rs | 2 -- tests/expectations/tests/anon_union.rs | 2 -- tests/expectations/tests/anon_union_1_0.rs | 2 -- tests/expectations/tests/anonymous-template-types.rs | 2 -- tests/expectations/tests/arg_keyword.rs | 2 -- tests/expectations/tests/array-of-zero-sized-types.rs | 2 -- .../tests/attribute_warn_unused_result.rs | 2 -- ...ibute_warn_unused_result_no_attribute_detection.rs | 2 -- .../tests/attribute_warn_unused_result_pre_1_27.rs | 2 -- .../tests/bad-namespace-parenthood-inheritance.rs | 2 -- tests/expectations/tests/base-to-derived.rs | 2 -- .../tests/bindgen-union-inside-namespace.rs | 2 -- tests/expectations/tests/bitfield-32bit-overflow.rs | 2 -- tests/expectations/tests/bitfield-enum-basic.rs | 2 -- tests/expectations/tests/bitfield-enum-repr-c.rs | 2 -- .../tests/bitfield-enum-repr-transparent.rs | 2 -- tests/expectations/tests/bitfield-large.rs | 2 -- tests/expectations/tests/bitfield-linux-32.rs | 2 -- tests/expectations/tests/bitfield-method-same-name.rs | 2 -- tests/expectations/tests/bitfield_align.rs | 2 -- tests/expectations/tests/bitfield_align_2.rs | 2 -- tests/expectations/tests/bitfield_large_overflow.rs | 2 -- tests/expectations/tests/bitfield_method_mangling.rs | 2 -- tests/expectations/tests/blacklist-and-impl-debug.rs | 2 -- tests/expectations/tests/blacklist-function.rs | 2 -- tests/expectations/tests/blacklist-item.rs | 2 -- tests/expectations/tests/block_return_type.rs | 2 -- tests/expectations/tests/blocks-signature.rs | 2 -- tests/expectations/tests/blocks.rs | 2 -- tests/expectations/tests/bug-1529681.rs | 2 -- tests/expectations/tests/builtin-template.rs | 2 -- tests/expectations/tests/c-empty-layout.rs | 2 -- tests/expectations/tests/call-conv-typedef.rs | 2 -- .../tests/canonical_path_without_namespacing.rs | 2 -- tests/expectations/tests/char.rs | 2 -- tests/expectations/tests/class.rs | 2 -- tests/expectations/tests/class_1_0.rs | 2 -- tests/expectations/tests/class_nested.rs | 2 -- tests/expectations/tests/class_no_members.rs | 2 -- tests/expectations/tests/class_static.rs | 2 -- tests/expectations/tests/class_static_const.rs | 2 -- tests/expectations/tests/class_use_as.rs | 2 -- tests/expectations/tests/class_with_dtor.rs | 2 -- tests/expectations/tests/class_with_inner_struct.rs | 2 -- .../expectations/tests/class_with_inner_struct_1_0.rs | 2 -- tests/expectations/tests/class_with_typedef.rs | 2 -- tests/expectations/tests/comment-indent.rs | 2 -- tests/expectations/tests/complex.rs | 2 -- tests/expectations/tests/complex_global.rs | 2 -- tests/expectations/tests/const-const-mut-ptr.rs | 2 -- tests/expectations/tests/const_array.rs | 2 -- tests/expectations/tests/const_array_fn_arg.rs | 2 -- tests/expectations/tests/const_enum_unnamed.rs | 2 -- tests/expectations/tests/const_ptr.rs | 2 -- tests/expectations/tests/const_resolved_ty.rs | 2 -- tests/expectations/tests/const_tparam.rs | 2 -- .../expectations/tests/constant-non-specialized-tp.rs | 2 -- tests/expectations/tests/constify-all-enums.rs | 2 -- tests/expectations/tests/constify-enum.rs | 2 -- .../expectations/tests/constify-module-enums-basic.rs | 2 -- .../tests/constify-module-enums-namespace.rs | 2 -- .../tests/constify-module-enums-shadow-name.rs | 2 -- .../tests/constify-module-enums-simple-alias.rs | 2 -- .../tests/constify-module-enums-simple-nonamespace.rs | 2 -- .../expectations/tests/constify-module-enums-types.rs | 2 -- tests/expectations/tests/constructor-tp.rs | 2 -- tests/expectations/tests/constructors.rs | 2 -- tests/expectations/tests/constructors_1_33.rs | 2 -- .../tests/contains-vs-inherits-zero-sized.rs | 2 -- .../expectations/tests/convert-cpp-comment-to-rust.rs | 2 -- tests/expectations/tests/convert-floats.rs | 2 -- tests/expectations/tests/cpp-empty-layout.rs | 2 -- tests/expectations/tests/crtp.rs | 2 -- tests/expectations/tests/ctypes-prefix-path.rs | 2 -- tests/expectations/tests/dash_language.rs | 2 -- tests/expectations/tests/decl_extern_int_twice.rs | 2 -- tests/expectations/tests/decl_ptr_to_array.rs | 2 -- .../tests/default-enum-style-constified-module.rs | 2 -- .../expectations/tests/default-template-parameter.rs | 2 -- .../tests/derive-bitfield-method-same-name.rs | 2 -- tests/expectations/tests/derive-clone.rs | 2 -- tests/expectations/tests/derive-clone_1_0.rs | 2 -- tests/expectations/tests/derive-custom.rs | 2 -- .../expectations/tests/derive-debug-bitfield-core.rs | 2 -- tests/expectations/tests/derive-debug-bitfield.rs | 2 -- .../tests/derive-debug-function-pointer.rs | 2 -- tests/expectations/tests/derive-debug-generic.rs | 2 -- tests/expectations/tests/derive-debug-mangle-name.rs | 2 -- .../derive-debug-opaque-template-instantiation.rs | 2 -- tests/expectations/tests/derive-debug-opaque.rs | 2 -- .../tests/derive-default-and-blacklist.rs | 2 -- tests/expectations/tests/derive-fn-ptr.rs | 2 -- tests/expectations/tests/derive-hash-and-blacklist.rs | 2 -- tests/expectations/tests/derive-hash-blacklisting.rs | 2 -- .../derive-hash-struct-with-anon-struct-float.rs | 2 -- .../tests/derive-hash-struct-with-float-array.rs | 2 -- .../tests/derive-hash-struct-with-incomplete-array.rs | 2 -- .../tests/derive-hash-struct-with-pointer.rs | 2 -- .../tests/derive-hash-template-def-float.rs | 2 -- .../tests/derive-hash-template-inst-float.rs | 2 -- .../tests/derive-partialeq-and-blacklist.rs | 2 -- .../expectations/tests/derive-partialeq-anonfield.rs | 2 -- tests/expectations/tests/derive-partialeq-base.rs | 2 -- tests/expectations/tests/derive-partialeq-bitfield.rs | 2 -- tests/expectations/tests/derive-partialeq-core.rs | 2 -- tests/expectations/tests/derive-partialeq-pointer.rs | 2 -- tests/expectations/tests/derive-partialeq-union.rs | 2 -- .../expectations/tests/derive-partialeq-union_1_0.rs | 2 -- tests/expectations/tests/disable-namespacing.rs | 2 -- .../tests/disable-nested-struct-naming.rs | 2 -- tests/expectations/tests/disable-untagged-union.rs | 2 -- .../tests/divide-by-zero-in-struct-layout.rs | 2 -- tests/expectations/tests/do-not-derive-copy.rs | 2 -- tests/expectations/tests/doggo-or-null.rs | 2 -- .../tests/dupe-enum-variant-in-namespace.rs | 2 -- .../tests/duplicated-namespaces-definitions.rs | 2 -- tests/expectations/tests/duplicated-namespaces.rs | 2 -- .../expectations/tests/duplicated_constants_in_ns.rs | 2 -- tests/expectations/tests/elaborated.rs | 2 -- tests/expectations/tests/empty-enum.rs | 2 -- tests/expectations/tests/empty-union.rs | 2 -- tests/expectations/tests/empty_template_param_name.rs | 2 -- tests/expectations/tests/enum-default-bitfield.rs | 2 -- tests/expectations/tests/enum-default-consts.rs | 2 -- tests/expectations/tests/enum-default-module.rs | 2 -- tests/expectations/tests/enum-default-rust.rs | 2 -- tests/expectations/tests/enum-doc-bitfield.rs | 2 -- tests/expectations/tests/enum-doc-mod.rs | 2 -- tests/expectations/tests/enum-doc-rusty.rs | 2 -- tests/expectations/tests/enum-doc.rs | 2 -- tests/expectations/tests/enum-undefault.rs | 2 -- tests/expectations/tests/enum-variant-replaces.rs | 2 -- tests/expectations/tests/enum.rs | 2 -- tests/expectations/tests/enum_alias.rs | 2 -- tests/expectations/tests/enum_and_vtable_mangling.rs | 2 -- tests/expectations/tests/enum_dupe.rs | 2 -- tests/expectations/tests/enum_explicit_type.rs | 2 -- .../tests/enum_explicit_type_constants.rs | 2 -- tests/expectations/tests/enum_in_template.rs | 2 -- .../tests/enum_in_template_with_typedef.rs | 2 -- tests/expectations/tests/enum_negative.rs | 2 -- tests/expectations/tests/enum_packed.rs | 2 -- tests/expectations/tests/eval-value-dependent.rs | 2 -- .../tests/eval-variadic-template-parameter.rs | 2 -- tests/expectations/tests/extern-const-struct.rs | 2 -- tests/expectations/tests/extern.rs | 2 -- tests/expectations/tests/float128.rs | 2 -- .../expectations/tests/forward-declaration-autoptr.rs | 2 -- tests/expectations/tests/forward-enum-decl.rs | 2 -- .../tests/forward-inherit-struct-with-fields.rs | 2 -- tests/expectations/tests/forward-inherit-struct.rs | 2 -- .../tests/forward_declared_complex_types.rs | 2 -- .../tests/forward_declared_complex_types_1_0.rs | 2 -- tests/expectations/tests/forward_declared_opaque.rs | 2 -- tests/expectations/tests/forward_declared_struct.rs | 2 -- tests/expectations/tests/func_proto.rs | 2 -- tests/expectations/tests/func_ptr.rs | 2 -- tests/expectations/tests/func_ptr_in_struct.rs | 2 -- tests/expectations/tests/func_ptr_return_type.rs | 2 -- tests/expectations/tests/func_with_array_arg.rs | 2 -- tests/expectations/tests/func_with_func_ptr_arg.rs | 2 -- tests/expectations/tests/function-typedef-stdcall.rs | 2 -- tests/expectations/tests/gen-constructors-neg.rs | 2 -- tests/expectations/tests/gen-constructors.rs | 2 -- tests/expectations/tests/gen-destructors-neg.rs | 2 -- tests/expectations/tests/gen-destructors.rs | 2 -- tests/expectations/tests/generate-inline.rs | 2 -- tests/expectations/tests/i128.rs | 2 -- tests/expectations/tests/in_class_typedef.rs | 2 -- tests/expectations/tests/incomplete-array-padding.rs | 2 -- tests/expectations/tests/infinite-macro.rs | 2 -- ...inherit-from-template-instantiation-with-vtable.rs | 2 -- tests/expectations/tests/inherit-namespaced.rs | 2 -- tests/expectations/tests/inherit_named.rs | 2 -- tests/expectations/tests/inherit_typedef.rs | 2 -- tests/expectations/tests/inline-function.rs | 2 -- tests/expectations/tests/inline_namespace.rs | 2 -- .../tests/inline_namespace_conservative.rs | 2 -- .../tests/inline_namespace_no_ns_enabled.rs | 2 -- .../expectations/tests/inline_namespace_whitelist.rs | 2 -- tests/expectations/tests/inner_const.rs | 2 -- tests/expectations/tests/inner_template_self.rs | 2 -- tests/expectations/tests/int128_t.rs | 2 -- .../tests/issue-1025-unknown-enum-repr.rs | 2 -- tests/expectations/tests/issue-1034.rs | 2 -- tests/expectations/tests/issue-1040.rs | 2 -- .../tests/issue-1076-unnamed-bitfield-alignment.rs | 2 -- .../tests/issue-1113-template-references.rs | 2 -- .../tests/issue-1118-using-forward-decl.rs | 2 -- .../tests/issue-1197-pure-virtual-stuff.rs | 2 -- .../tests/issue-1198-alias-rust-bitfield-enum.rs | 2 -- .../issue-1198-alias-rust-const-mod-bitfield-enum.rs | 2 -- .../tests/issue-1198-alias-rust-const-mod-enum.rs | 2 -- .../expectations/tests/issue-1198-alias-rust-enum.rs | 2 -- .../expectations/tests/issue-1216-variadic-member.rs | 2 -- tests/expectations/tests/issue-1238-fwd-no-copy.rs | 2 -- tests/expectations/tests/issue-1281.rs | 2 -- tests/expectations/tests/issue-1285.rs | 2 -- tests/expectations/tests/issue-1291.rs | 2 -- .../tests/issue-1350-attribute-overloadable.rs | 2 -- .../tests/issue-1382-rust-primitive-types.rs | 2 -- tests/expectations/tests/issue-1435.rs | 2 -- tests/expectations/tests/issue-1443.rs | 2 -- tests/expectations/tests/issue-1464.rs | 2 -- tests/expectations/tests/issue-1488-enum-new-type.rs | 2 -- tests/expectations/tests/issue-1488-options.rs | 2 -- .../tests/issue-1488-template-alias-new-type.rs | 2 -- tests/expectations/tests/issue-1498.rs | 2 -- tests/expectations/tests/issue-1514.rs | 2 -- tests/expectations/tests/issue-1554.rs | 2 -- .../tests/issue-1599-opaque-typedef-to-enum.rs | 2 -- .../tests/issue-1676-macro-namespace-prefix.rs | 2 -- tests/expectations/tests/issue-358.rs | 2 -- tests/expectations/tests/issue-372.rs | 2 -- tests/expectations/tests/issue-410.rs | 2 -- tests/expectations/tests/issue-446.rs | 2 -- tests/expectations/tests/issue-447.rs | 2 -- tests/expectations/tests/issue-493.rs | 2 -- tests/expectations/tests/issue-493_1_0.rs | 2 -- tests/expectations/tests/issue-511.rs | 2 -- tests/expectations/tests/issue-537-repr-packed-n.rs | 2 -- tests/expectations/tests/issue-537.rs | 2 -- tests/expectations/tests/issue-544-stylo-creduce-2.rs | 2 -- tests/expectations/tests/issue-544-stylo-creduce.rs | 2 -- ...pe-template-params-causing-layout-test-failures.rs | 2 -- .../tests/issue-573-layout-test-failures.rs | 2 -- .../tests/issue-574-assertion-failure-in-codegen.rs | 2 -- .../tests/issue-584-stylo-template-analysis-panic.rs | 2 -- .../issue-638-stylo-cannot-find-T-in-this-scope.rs | 2 -- .../tests/issue-639-typedef-anon-field.rs | 2 -- tests/expectations/tests/issue-643-inner-struct.rs | 2 -- .../issue-645-cannot-find-type-T-in-this-scope.rs | 2 -- .../tests/issue-648-derive-debug-with-padding.rs | 2 -- .../tests/issue-654-struct-fn-collision.rs | 2 -- .../tests/issue-662-cannot-find-T-in-this-scope.rs | 2 -- tests/expectations/tests/issue-662-part-2.rs | 2 -- tests/expectations/tests/issue-674-1.rs | 2 -- tests/expectations/tests/issue-674-2.rs | 2 -- tests/expectations/tests/issue-674-3.rs | 2 -- .../tests/issue-677-nested-ns-specifier.rs | 2 -- .../tests/issue-691-template-parameter-virtual.rs | 2 -- .../tests/issue-739-pointer-wide-bitfield.rs | 2 -- .../expectations/tests/issue-801-opaque-sloppiness.rs | 2 -- .../issue-807-opaque-types-methods-being-generated.rs | 2 -- tests/expectations/tests/issue-816.rs | 2 -- .../tests/issue-820-unused-template-param-in-alias.rs | 2 -- .../issue-826-generating-methods-when-asked-not-to.rs | 2 -- tests/expectations/tests/issue-833-1.rs | 2 -- tests/expectations/tests/issue-833-2.rs | 2 -- tests/expectations/tests/issue-833.rs | 2 -- tests/expectations/tests/issue-834.rs | 2 -- .../tests/issue-848-replacement-system-include.rs | 2 -- .../tests/issue-888-enum-var-decl-jump.rs | 2 -- .../tests/issue-944-derive-copy-and-blacklisting.rs | 2 -- tests/expectations/tests/issue-946.rs | 2 -- tests/expectations/tests/issue_311.rs | 2 -- tests/expectations/tests/issue_315.rs | 2 -- tests/expectations/tests/jsval_layout_opaque.rs | 2 -- tests/expectations/tests/jsval_layout_opaque_1_0.rs | 2 -- tests/expectations/tests/keywords.rs | 2 -- tests/expectations/tests/layout.rs | 2 -- tests/expectations/tests/layout_align.rs | 2 -- tests/expectations/tests/layout_arp.rs | 2 -- tests/expectations/tests/layout_array.rs | 2 -- tests/expectations/tests/layout_array_too_long.rs | 2 -- tests/expectations/tests/layout_cmdline_token.rs | 2 -- tests/expectations/tests/layout_eth_conf.rs | 2 -- tests/expectations/tests/layout_eth_conf_1_0.rs | 2 -- tests/expectations/tests/layout_kni_mbuf.rs | 2 -- tests/expectations/tests/layout_large_align_field.rs | 2 -- tests/expectations/tests/layout_mbuf.rs | 2 -- tests/expectations/tests/layout_mbuf_1_0.rs | 2 -- .../tests/libclang-3.8/abi_variadic_function.rs | 2 -- tests/expectations/tests/libclang-3.8/auto.rs | 2 -- .../tests/libclang-3.8/call-conv-field.rs | 2 -- tests/expectations/tests/libclang-3.8/const_bool.rs | 2 -- .../tests/libclang-3.8/constant-evaluate.rs | 2 -- .../error-E0600-cannot-apply-unary-negation-to-u32.rs | 2 -- .../libclang-3.8/issue-769-bad-instantiation-test.rs | 2 -- .../expectations/tests/libclang-3.8/mangling-win32.rs | 2 -- .../tests/libclang-3.8/objc_inheritance.rs | 2 -- .../expectations/tests/libclang-3.8/objc_template.rs | 2 -- .../partial-specialization-and-inheritance.rs | 2 -- .../libclang-3.8/type_alias_template_specialized.rs | 2 -- .../tests/libclang-3.9/abi_variadic_function.rs | 2 -- tests/expectations/tests/libclang-3.9/auto.rs | 2 -- .../tests/libclang-3.9/call-conv-field.rs | 2 -- tests/expectations/tests/libclang-3.9/const_bool.rs | 2 -- .../tests/libclang-3.9/constant-evaluate.rs | 2 -- .../error-E0600-cannot-apply-unary-negation-to-u32.rs | 2 -- .../libclang-3.9/issue-769-bad-instantiation-test.rs | 2 -- .../expectations/tests/libclang-3.9/mangling-win32.rs | 2 -- .../tests/libclang-3.9/objc_inheritance.rs | 2 -- .../expectations/tests/libclang-3.9/objc_template.rs | 2 -- .../partial-specialization-and-inheritance.rs | 2 -- .../libclang-3.9/type_alias_template_specialized.rs | 2 -- .../tests/libclang-4/abi_variadic_function.rs | 2 -- tests/expectations/tests/libclang-4/auto.rs | 2 -- .../expectations/tests/libclang-4/call-conv-field.rs | 2 -- tests/expectations/tests/libclang-4/const_bool.rs | 2 -- .../tests/libclang-4/constant-evaluate.rs | 2 -- .../error-E0600-cannot-apply-unary-negation-to-u32.rs | 2 -- .../libclang-4/issue-769-bad-instantiation-test.rs | 2 -- tests/expectations/tests/libclang-4/mangling-win32.rs | 2 -- .../expectations/tests/libclang-4/objc_inheritance.rs | 2 -- tests/expectations/tests/libclang-4/objc_template.rs | 2 -- .../partial-specialization-and-inheritance.rs | 2 -- .../libclang-4/type_alias_template_specialized.rs | 2 -- .../tests/libclang-5/abi_variadic_function.rs | 2 -- tests/expectations/tests/libclang-5/auto.rs | 2 -- .../expectations/tests/libclang-5/call-conv-field.rs | 2 -- tests/expectations/tests/libclang-5/const_bool.rs | 2 -- .../tests/libclang-5/constant-evaluate.rs | 2 -- .../error-E0600-cannot-apply-unary-negation-to-u32.rs | 2 -- .../libclang-5/issue-769-bad-instantiation-test.rs | 2 -- tests/expectations/tests/libclang-5/mangling-win32.rs | 2 -- .../expectations/tests/libclang-5/objc_inheritance.rs | 2 -- tests/expectations/tests/libclang-5/objc_template.rs | 2 -- .../partial-specialization-and-inheritance.rs | 2 -- .../libclang-5/type_alias_template_specialized.rs | 2 -- .../tests/libclang-9/abi_variadic_function.rs | 2 -- tests/expectations/tests/libclang-9/auto.rs | 2 -- .../expectations/tests/libclang-9/call-conv-field.rs | 2 -- tests/expectations/tests/libclang-9/class.rs | 2 -- tests/expectations/tests/libclang-9/class_1_0.rs | 2 -- tests/expectations/tests/libclang-9/const_bool.rs | 2 -- .../tests/libclang-9/constant-evaluate.rs | 2 -- .../derive-hash-struct-with-incomplete-array.rs | 2 -- .../error-E0600-cannot-apply-unary-negation-to-u32.rs | 2 -- .../tests/libclang-9/incomplete-array-padding.rs | 2 -- .../tests/libclang-9/issue-643-inner-struct.rs | 2 -- .../libclang-9/issue-769-bad-instantiation-test.rs | 2 -- tests/expectations/tests/libclang-9/layout_align.rs | 2 -- tests/expectations/tests/libclang-9/mangling-win32.rs | 2 -- .../expectations/tests/libclang-9/objc_inheritance.rs | 2 -- tests/expectations/tests/libclang-9/objc_template.rs | 2 -- .../partial-specialization-and-inheritance.rs | 2 -- .../libclang-9/type_alias_template_specialized.rs | 2 -- .../expectations/tests/libclang-9/zero-sized-array.rs | 2 -- tests/expectations/tests/long_double.rs | 2 -- tests/expectations/tests/macro-expr-basic.rs | 2 -- tests/expectations/tests/macro-expr-uncommon-token.rs | 2 -- tests/expectations/tests/macro-redef.rs | 2 -- tests/expectations/tests/macro_const.rs | 2 -- tests/expectations/tests/maddness-is-avoidable.rs | 2 -- tests/expectations/tests/mangling-ios.rs | 2 -- tests/expectations/tests/mangling-linux32.rs | 2 -- tests/expectations/tests/mangling-linux64.rs | 2 -- tests/expectations/tests/mangling-macos.rs | 2 -- tests/expectations/tests/mangling-win64.rs | 2 -- tests/expectations/tests/method-mangling.rs | 2 -- tests/expectations/tests/module-whitelisted.rs | 2 -- tests/expectations/tests/msvc-no-usr.rs | 2 -- .../tests/multiple-inherit-empty-correct-layout.rs | 2 -- tests/expectations/tests/mutable.rs | 2 -- tests/expectations/tests/namespace.rs | 2 -- tests/expectations/tests/nested.rs | 2 -- tests/expectations/tests/nested_vtable.rs | 2 -- tests/expectations/tests/nested_within_namespace.rs | 2 -- tests/expectations/tests/newtype-enum.rs | 2 -- tests/expectations/tests/no-comments.rs | 2 -- tests/expectations/tests/no-derive-debug.rs | 2 -- tests/expectations/tests/no-derive-default.rs | 2 -- tests/expectations/tests/no-hash-opaque.rs | 2 -- tests/expectations/tests/no-hash-whitelisted.rs | 2 -- tests/expectations/tests/no-partialeq-opaque.rs | 2 -- tests/expectations/tests/no-partialeq-whitelisted.rs | 2 -- tests/expectations/tests/no-recursive-whitelisting.rs | 2 -- tests/expectations/tests/no-std.rs | 2 -- tests/expectations/tests/no_copy.rs | 2 -- tests/expectations/tests/no_copy_opaque.rs | 2 -- tests/expectations/tests/no_copy_whitelisted.rs | 2 -- tests/expectations/tests/non-type-params.rs | 2 -- tests/expectations/tests/nsBaseHashtable.rs | 2 -- tests/expectations/tests/nsStyleAutoArray.rs | 2 -- tests/expectations/tests/objc_category.rs | 2 -- tests/expectations/tests/objc_class.rs | 2 -- tests/expectations/tests/objc_class_method.rs | 2 -- tests/expectations/tests/objc_interface.rs | 2 -- tests/expectations/tests/objc_interface_type.rs | 2 -- tests/expectations/tests/objc_method.rs | 2 -- tests/expectations/tests/objc_method_clash.rs | 2 -- tests/expectations/tests/objc_property_fnptr.rs | 2 -- tests/expectations/tests/objc_protocol.rs | 2 -- tests/expectations/tests/objc_sel_and_id.rs | 2 -- tests/expectations/tests/objc_whitelist.rs | 2 -- tests/expectations/tests/only_bitfields.rs | 2 -- .../tests/opaque-template-inst-member-2.rs | 2 -- .../expectations/tests/opaque-template-inst-member.rs | 2 -- .../tests/opaque-template-instantiation-namespaced.rs | 2 -- .../tests/opaque-template-instantiation.rs | 2 -- tests/expectations/tests/opaque-tracing.rs | 2 -- tests/expectations/tests/opaque_in_struct.rs | 2 -- tests/expectations/tests/opaque_pointer.rs | 2 -- tests/expectations/tests/opaque_typedef.rs | 2 -- tests/expectations/tests/ord-enum.rs | 2 -- tests/expectations/tests/overflowed_enum.rs | 2 -- tests/expectations/tests/overloading.rs | 2 -- tests/expectations/tests/packed-bitfield.rs | 2 -- tests/expectations/tests/packed-vtable.rs | 2 -- .../tests/prepend-enum-constified-variant.rs | 2 -- tests/expectations/tests/prepend_enum_name.rs | 2 -- tests/expectations/tests/private.rs | 2 -- tests/expectations/tests/public-dtor.rs | 2 -- tests/expectations/tests/redeclaration.rs | 2 -- tests/expectations/tests/ref_argument_array.rs | 2 -- tests/expectations/tests/reparented_replacement.rs | 2 -- tests/expectations/tests/replace_template_alias.rs | 2 -- tests/expectations/tests/replace_use.rs | 2 -- tests/expectations/tests/replaces_double.rs | 2 -- tests/expectations/tests/repr-align.rs | 2 -- .../expectations/tests/resolved_type_def_function.rs | 2 -- .../tests/same_struct_name_in_different_namespaces.rs | 2 -- .../tests/sentry-defined-multiple-times.rs | 2 -- tests/expectations/tests/short-enums.rs | 2 -- tests/expectations/tests/size_t_is_usize.rs | 2 -- tests/expectations/tests/size_t_template.rs | 2 -- .../struct_containing_forward_declared_struct.rs | 2 -- tests/expectations/tests/struct_typedef.rs | 2 -- tests/expectations/tests/struct_typedef_ns.rs | 2 -- tests/expectations/tests/struct_with_anon_struct.rs | 2 -- .../tests/struct_with_anon_struct_array.rs | 2 -- .../tests/struct_with_anon_struct_pointer.rs | 2 -- tests/expectations/tests/struct_with_anon_union.rs | 2 -- .../expectations/tests/struct_with_anon_union_1_0.rs | 2 -- .../tests/struct_with_anon_unnamed_struct.rs | 2 -- .../tests/struct_with_anon_unnamed_union.rs | 2 -- .../tests/struct_with_anon_unnamed_union_1_0.rs | 2 -- tests/expectations/tests/struct_with_bitfields.rs | 2 -- tests/expectations/tests/struct_with_derive_debug.rs | 2 -- tests/expectations/tests/struct_with_large_array.rs | 2 -- tests/expectations/tests/struct_with_nesting.rs | 2 -- tests/expectations/tests/struct_with_nesting_1_0.rs | 2 -- tests/expectations/tests/struct_with_packing.rs | 2 -- tests/expectations/tests/struct_with_struct.rs | 2 -- .../tests/struct_with_typedef_template_arg.rs | 2 -- tests/expectations/tests/template-fun-ty.rs | 2 -- tests/expectations/tests/template-param-usage-0.rs | 2 -- tests/expectations/tests/template-param-usage-1.rs | 2 -- tests/expectations/tests/template-param-usage-10.rs | 2 -- tests/expectations/tests/template-param-usage-11.rs | 2 -- tests/expectations/tests/template-param-usage-12.rs | 2 -- tests/expectations/tests/template-param-usage-13.rs | 2 -- tests/expectations/tests/template-param-usage-14.rs | 2 -- tests/expectations/tests/template-param-usage-15.rs | 2 -- tests/expectations/tests/template-param-usage-2.rs | 2 -- tests/expectations/tests/template-param-usage-3.rs | 2 -- tests/expectations/tests/template-param-usage-4.rs | 2 -- tests/expectations/tests/template-param-usage-5.rs | 2 -- tests/expectations/tests/template-param-usage-6.rs | 2 -- tests/expectations/tests/template-param-usage-7.rs | 2 -- tests/expectations/tests/template-param-usage-8.rs | 2 -- tests/expectations/tests/template-param-usage-9.rs | 2 -- tests/expectations/tests/template-with-var.rs | 2 -- tests/expectations/tests/template.rs | 2 -- tests/expectations/tests/template_alias.rs | 2 -- tests/expectations/tests/template_alias_basic.rs | 2 -- tests/expectations/tests/template_alias_namespace.rs | 2 -- tests/expectations/tests/template_fun.rs | 2 -- .../tests/template_partial_specification.rs | 2 -- .../tests/template_typedef_transitive_param.rs | 2 -- tests/expectations/tests/template_typedefs.rs | 2 -- tests/expectations/tests/templateref_opaque.rs | 2 -- tests/expectations/tests/templatized-bitfield.rs | 2 -- .../tests/test_multiple_header_calls_in_builder.rs | 2 -- tests/expectations/tests/timex.rs | 2 -- tests/expectations/tests/transform-op.rs | 2 -- .../tests/type-referenced-by-whitelisted-function.rs | 2 -- tests/expectations/tests/type_alias_empty.rs | 2 -- .../type_alias_partial_template_especialization.rs | 2 -- .../tests/typedefd-array-as-function-arg.rs | 2 -- tests/expectations/tests/typeref.rs | 2 -- tests/expectations/tests/typeref_1_0.rs | 2 -- tests/expectations/tests/underscore.rs | 2 -- tests/expectations/tests/union-align.rs | 2 -- tests/expectations/tests/union-in-ns.rs | 2 -- tests/expectations/tests/union-in-ns_1_0.rs | 2 -- tests/expectations/tests/union_bitfield.rs | 2 -- tests/expectations/tests/union_bitfield_1_0.rs | 2 -- tests/expectations/tests/union_dtor.rs | 2 -- tests/expectations/tests/union_dtor_1_0.rs | 2 -- tests/expectations/tests/union_fields.rs | 2 -- tests/expectations/tests/union_fields_1_0.rs | 2 -- tests/expectations/tests/union_template.rs | 2 -- tests/expectations/tests/union_template_1_0.rs | 2 -- tests/expectations/tests/union_with_anon_struct.rs | 2 -- .../expectations/tests/union_with_anon_struct_1_0.rs | 2 -- .../tests/union_with_anon_struct_bitfield.rs | 2 -- .../tests/union_with_anon_struct_bitfield_1_0.rs | 2 -- tests/expectations/tests/union_with_anon_union.rs | 2 -- tests/expectations/tests/union_with_anon_union_1_0.rs | 2 -- .../tests/union_with_anon_unnamed_struct.rs | 2 -- .../tests/union_with_anon_unnamed_struct_1_0.rs | 2 -- .../tests/union_with_anon_unnamed_union.rs | 2 -- .../tests/union_with_anon_unnamed_union_1_0.rs | 2 -- tests/expectations/tests/union_with_big_member.rs | 2 -- tests/expectations/tests/union_with_big_member_1_0.rs | 2 -- tests/expectations/tests/union_with_nesting.rs | 2 -- tests/expectations/tests/union_with_nesting_1_0.rs | 2 -- tests/expectations/tests/unknown_attr.rs | 2 -- tests/expectations/tests/use-core.rs | 2 -- tests/expectations/tests/use-core_1_0.rs | 2 -- tests/expectations/tests/using.rs | 2 -- tests/expectations/tests/var-tracing.rs | 2 -- tests/expectations/tests/variadic-method.rs | 2 -- .../expectations/tests/variadic_template_function.rs | 2 -- tests/expectations/tests/vector.rs | 2 -- tests/expectations/tests/virtual_dtor.rs | 2 -- tests/expectations/tests/virtual_inheritance.rs | 2 -- tests/expectations/tests/virtual_overloaded.rs | 2 -- tests/expectations/tests/vtable_recursive_sig.rs | 2 -- tests/expectations/tests/wasm-import-module.rs | 2 -- tests/expectations/tests/weird_bitfields.rs | 2 -- tests/expectations/tests/what_is_going_on.rs | 2 -- .../expectations/tests/whitelist-namespaces-basic.rs | 2 -- tests/expectations/tests/whitelist-namespaces.rs | 2 -- tests/expectations/tests/whitelist_basic.rs | 2 -- tests/expectations/tests/whitelist_fix.rs | 2 -- tests/expectations/tests/whitelist_vars.rs | 2 -- .../tests/whitelisted-item-references-no-hash.rs | 2 -- .../tests/whitelisted-item-references-no-partialeq.rs | 2 -- .../tests/whitelisted_item_references_no_copy.rs | 2 -- tests/expectations/tests/win32-thiscall_1_0.rs | 2 -- tests/expectations/tests/win32-thiscall_nightly.rs | 2 -- .../tests/with_array_pointers_arguments.rs | 2 -- .../tests/without_array_pointers_arguments.rs | 2 -- tests/expectations/tests/zero-size-array-align.rs | 2 -- tests/expectations/tests/zero-sized-array.rs | 2 -- tests/tests.rs | 10 ++++------ 539 files changed, 12 insertions(+), 1083 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2099726783..22b5594a93 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2177,9 +2177,14 @@ impl Bindings { /// Write these bindings as source text to the given `Write`able. pub fn write<'a>(&self, mut writer: Box) -> io::Result<()> { - writer.write( - "/* automatically generated by rust-bindgen */\n\n".as_bytes(), - )?; + if !self.options.disable_header_comment { + let version = option_env!("CARGO_PKG_VERSION"); + let header = format!( + "/* automatically generated by rust-bindgen {} */\n\n", + version.unwrap_or("(unknown version)") + ); + writer.write(header.as_bytes())?; + } for line in self.options.raw_lines.iter() { writer.write(line.as_bytes())?; diff --git a/tests/expectations/tests/16-byte-alignment.rs b/tests/expectations/tests/16-byte-alignment.rs index 19151c7d52..00d311a59e 100644 --- a/tests/expectations/tests/16-byte-alignment.rs +++ b/tests/expectations/tests/16-byte-alignment.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/16-byte-alignment_1_0.rs b/tests/expectations/tests/16-byte-alignment_1_0.rs index b4b1d84624..8b1055731d 100644 --- a/tests/expectations/tests/16-byte-alignment_1_0.rs +++ b/tests/expectations/tests/16-byte-alignment_1_0.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/381-decltype-alias.rs b/tests/expectations/tests/381-decltype-alias.rs index f8cf202918..f4312a115a 100644 --- a/tests/expectations/tests/381-decltype-alias.rs +++ b/tests/expectations/tests/381-decltype-alias.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/accessors.rs b/tests/expectations/tests/accessors.rs index 514541e326..9977baa282 100644 --- a/tests/expectations/tests/accessors.rs +++ b/tests/expectations/tests/accessors.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/annotation_hide.rs b/tests/expectations/tests/annotation_hide.rs index b6a47cc093..38435d0a4c 100644 --- a/tests/expectations/tests/annotation_hide.rs +++ b/tests/expectations/tests/annotation_hide.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/anon_enum.rs b/tests/expectations/tests/anon_enum.rs index f2d9ec252f..0493d8cab7 100644 --- a/tests/expectations/tests/anon_enum.rs +++ b/tests/expectations/tests/anon_enum.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/anon_enum_trait.rs b/tests/expectations/tests/anon_enum_trait.rs index 6418549171..e6a901469c 100644 --- a/tests/expectations/tests/anon_enum_trait.rs +++ b/tests/expectations/tests/anon_enum_trait.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/anon_enum_whitelist.rs b/tests/expectations/tests/anon_enum_whitelist.rs index c109b317f7..b94229c0ab 100644 --- a/tests/expectations/tests/anon_enum_whitelist.rs +++ b/tests/expectations/tests/anon_enum_whitelist.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/anon_struct_in_union.rs b/tests/expectations/tests/anon_struct_in_union.rs index 66c64c0fbb..8d0035d693 100644 --- a/tests/expectations/tests/anon_struct_in_union.rs +++ b/tests/expectations/tests/anon_struct_in_union.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/anon_struct_in_union_1_0.rs b/tests/expectations/tests/anon_struct_in_union_1_0.rs index 725c4e22fb..021f41451b 100644 --- a/tests/expectations/tests/anon_struct_in_union_1_0.rs +++ b/tests/expectations/tests/anon_struct_in_union_1_0.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/anon_union.rs b/tests/expectations/tests/anon_union.rs index ff91944d8f..0490ad730c 100644 --- a/tests/expectations/tests/anon_union.rs +++ b/tests/expectations/tests/anon_union.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/anon_union_1_0.rs b/tests/expectations/tests/anon_union_1_0.rs index 3397c5515e..95713ea9e6 100644 --- a/tests/expectations/tests/anon_union_1_0.rs +++ b/tests/expectations/tests/anon_union_1_0.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/anonymous-template-types.rs b/tests/expectations/tests/anonymous-template-types.rs index c2cff3b8c3..3d072864a5 100644 --- a/tests/expectations/tests/anonymous-template-types.rs +++ b/tests/expectations/tests/anonymous-template-types.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/arg_keyword.rs b/tests/expectations/tests/arg_keyword.rs index 1aab5ce1e0..43ff58313d 100644 --- a/tests/expectations/tests/arg_keyword.rs +++ b/tests/expectations/tests/arg_keyword.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/array-of-zero-sized-types.rs b/tests/expectations/tests/array-of-zero-sized-types.rs index fa4d7a8a3d..0c00cea9ce 100644 --- a/tests/expectations/tests/array-of-zero-sized-types.rs +++ b/tests/expectations/tests/array-of-zero-sized-types.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/attribute_warn_unused_result.rs b/tests/expectations/tests/attribute_warn_unused_result.rs index 0230bc6289..12d5eab04b 100644 --- a/tests/expectations/tests/attribute_warn_unused_result.rs +++ b/tests/expectations/tests/attribute_warn_unused_result.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/attribute_warn_unused_result_no_attribute_detection.rs b/tests/expectations/tests/attribute_warn_unused_result_no_attribute_detection.rs index b1c6eb9258..d860acd1b4 100644 --- a/tests/expectations/tests/attribute_warn_unused_result_no_attribute_detection.rs +++ b/tests/expectations/tests/attribute_warn_unused_result_no_attribute_detection.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/attribute_warn_unused_result_pre_1_27.rs b/tests/expectations/tests/attribute_warn_unused_result_pre_1_27.rs index b1c6eb9258..d860acd1b4 100644 --- a/tests/expectations/tests/attribute_warn_unused_result_pre_1_27.rs +++ b/tests/expectations/tests/attribute_warn_unused_result_pre_1_27.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/bad-namespace-parenthood-inheritance.rs b/tests/expectations/tests/bad-namespace-parenthood-inheritance.rs index 7a4ac42ed0..228dafd5ab 100644 --- a/tests/expectations/tests/bad-namespace-parenthood-inheritance.rs +++ b/tests/expectations/tests/bad-namespace-parenthood-inheritance.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/base-to-derived.rs b/tests/expectations/tests/base-to-derived.rs index 528f1e17ed..97830cd4fb 100644 --- a/tests/expectations/tests/base-to-derived.rs +++ b/tests/expectations/tests/base-to-derived.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/bindgen-union-inside-namespace.rs b/tests/expectations/tests/bindgen-union-inside-namespace.rs index 1b5ff81f9f..6083313bfb 100644 --- a/tests/expectations/tests/bindgen-union-inside-namespace.rs +++ b/tests/expectations/tests/bindgen-union-inside-namespace.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/bitfield-32bit-overflow.rs b/tests/expectations/tests/bitfield-32bit-overflow.rs index cfd00ac3ca..cd2fd177c6 100644 --- a/tests/expectations/tests/bitfield-32bit-overflow.rs +++ b/tests/expectations/tests/bitfield-32bit-overflow.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/bitfield-enum-basic.rs b/tests/expectations/tests/bitfield-enum-basic.rs index 7a3dd3562b..390d8974b3 100644 --- a/tests/expectations/tests/bitfield-enum-basic.rs +++ b/tests/expectations/tests/bitfield-enum-basic.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/bitfield-enum-repr-c.rs b/tests/expectations/tests/bitfield-enum-repr-c.rs index 33103c17c2..72aaff00f9 100644 --- a/tests/expectations/tests/bitfield-enum-repr-c.rs +++ b/tests/expectations/tests/bitfield-enum-repr-c.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/bitfield-enum-repr-transparent.rs b/tests/expectations/tests/bitfield-enum-repr-transparent.rs index 6d0c541593..9b46c681e2 100644 --- a/tests/expectations/tests/bitfield-enum-repr-transparent.rs +++ b/tests/expectations/tests/bitfield-enum-repr-transparent.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/bitfield-large.rs b/tests/expectations/tests/bitfield-large.rs index b3f4e5cfb2..a29bd4c820 100644 --- a/tests/expectations/tests/bitfield-large.rs +++ b/tests/expectations/tests/bitfield-large.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/bitfield-linux-32.rs b/tests/expectations/tests/bitfield-linux-32.rs index 3b63a57760..bd2b391706 100644 --- a/tests/expectations/tests/bitfield-linux-32.rs +++ b/tests/expectations/tests/bitfield-linux-32.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/bitfield-method-same-name.rs b/tests/expectations/tests/bitfield-method-same-name.rs index bea1734d5d..fc2681e8a7 100644 --- a/tests/expectations/tests/bitfield-method-same-name.rs +++ b/tests/expectations/tests/bitfield-method-same-name.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/bitfield_align.rs b/tests/expectations/tests/bitfield_align.rs index 3c6da12246..57f726efde 100644 --- a/tests/expectations/tests/bitfield_align.rs +++ b/tests/expectations/tests/bitfield_align.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/bitfield_align_2.rs b/tests/expectations/tests/bitfield_align_2.rs index 277d828309..ef0cdffe47 100644 --- a/tests/expectations/tests/bitfield_align_2.rs +++ b/tests/expectations/tests/bitfield_align_2.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/bitfield_large_overflow.rs b/tests/expectations/tests/bitfield_large_overflow.rs index ea9b97abef..4ee1f59844 100644 --- a/tests/expectations/tests/bitfield_large_overflow.rs +++ b/tests/expectations/tests/bitfield_large_overflow.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/bitfield_method_mangling.rs b/tests/expectations/tests/bitfield_method_mangling.rs index a08292d399..584b7cc15f 100644 --- a/tests/expectations/tests/bitfield_method_mangling.rs +++ b/tests/expectations/tests/bitfield_method_mangling.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/blacklist-and-impl-debug.rs b/tests/expectations/tests/blacklist-and-impl-debug.rs index 21c8d9769d..2609b2e864 100644 --- a/tests/expectations/tests/blacklist-and-impl-debug.rs +++ b/tests/expectations/tests/blacklist-and-impl-debug.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/blacklist-function.rs b/tests/expectations/tests/blacklist-function.rs index 5c4e849719..5299b1517e 100644 --- a/tests/expectations/tests/blacklist-function.rs +++ b/tests/expectations/tests/blacklist-function.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/blacklist-item.rs b/tests/expectations/tests/blacklist-item.rs index b1d5564339..0edee9ec32 100644 --- a/tests/expectations/tests/blacklist-item.rs +++ b/tests/expectations/tests/blacklist-item.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/block_return_type.rs b/tests/expectations/tests/block_return_type.rs index 6809f609a2..bc4347335e 100644 --- a/tests/expectations/tests/block_return_type.rs +++ b/tests/expectations/tests/block_return_type.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/blocks-signature.rs b/tests/expectations/tests/blocks-signature.rs index 691862b925..bd9d815038 100644 --- a/tests/expectations/tests/blocks-signature.rs +++ b/tests/expectations/tests/blocks-signature.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/blocks.rs b/tests/expectations/tests/blocks.rs index a8fa62c9ec..4c731f895e 100644 --- a/tests/expectations/tests/blocks.rs +++ b/tests/expectations/tests/blocks.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/bug-1529681.rs b/tests/expectations/tests/bug-1529681.rs index 81a3209306..6a0f5e134a 100644 --- a/tests/expectations/tests/bug-1529681.rs +++ b/tests/expectations/tests/bug-1529681.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/builtin-template.rs b/tests/expectations/tests/builtin-template.rs index 0a6ded4946..112b767008 100644 --- a/tests/expectations/tests/builtin-template.rs +++ b/tests/expectations/tests/builtin-template.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/c-empty-layout.rs b/tests/expectations/tests/c-empty-layout.rs index 1ed41db89d..ebef2b6d82 100644 --- a/tests/expectations/tests/c-empty-layout.rs +++ b/tests/expectations/tests/c-empty-layout.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/call-conv-typedef.rs b/tests/expectations/tests/call-conv-typedef.rs index db37da0ec3..6eabb1f6ad 100644 --- a/tests/expectations/tests/call-conv-typedef.rs +++ b/tests/expectations/tests/call-conv-typedef.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/canonical_path_without_namespacing.rs b/tests/expectations/tests/canonical_path_without_namespacing.rs index cdc5b512d9..12f10a8873 100644 --- a/tests/expectations/tests/canonical_path_without_namespacing.rs +++ b/tests/expectations/tests/canonical_path_without_namespacing.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/char.rs b/tests/expectations/tests/char.rs index 55303e5d66..1e1a19879d 100644 --- a/tests/expectations/tests/char.rs +++ b/tests/expectations/tests/char.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/class.rs b/tests/expectations/tests/class.rs index 9275884859..c03f12745d 100644 --- a/tests/expectations/tests/class.rs +++ b/tests/expectations/tests/class.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/class_1_0.rs b/tests/expectations/tests/class_1_0.rs index 82a568b149..b341bdbe87 100644 --- a/tests/expectations/tests/class_1_0.rs +++ b/tests/expectations/tests/class_1_0.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/class_nested.rs b/tests/expectations/tests/class_nested.rs index 80cb621fab..5f7a1dfc65 100644 --- a/tests/expectations/tests/class_nested.rs +++ b/tests/expectations/tests/class_nested.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/class_no_members.rs b/tests/expectations/tests/class_no_members.rs index 729e517a5f..6c1e4880a6 100644 --- a/tests/expectations/tests/class_no_members.rs +++ b/tests/expectations/tests/class_no_members.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/class_static.rs b/tests/expectations/tests/class_static.rs index 979c51cbd7..2388f3b3a4 100644 --- a/tests/expectations/tests/class_static.rs +++ b/tests/expectations/tests/class_static.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/class_static_const.rs b/tests/expectations/tests/class_static_const.rs index 9e4841d35f..812d78e1ab 100644 --- a/tests/expectations/tests/class_static_const.rs +++ b/tests/expectations/tests/class_static_const.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/class_use_as.rs b/tests/expectations/tests/class_use_as.rs index c88f25c5c9..d6a71ac358 100644 --- a/tests/expectations/tests/class_use_as.rs +++ b/tests/expectations/tests/class_use_as.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/class_with_dtor.rs b/tests/expectations/tests/class_with_dtor.rs index 9baa1b4d2b..7cefe99df9 100644 --- a/tests/expectations/tests/class_with_dtor.rs +++ b/tests/expectations/tests/class_with_dtor.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/class_with_inner_struct.rs b/tests/expectations/tests/class_with_inner_struct.rs index 939143d632..2f87355c0b 100644 --- a/tests/expectations/tests/class_with_inner_struct.rs +++ b/tests/expectations/tests/class_with_inner_struct.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/class_with_inner_struct_1_0.rs b/tests/expectations/tests/class_with_inner_struct_1_0.rs index 3fd71bd00b..d7dd0b55c7 100644 --- a/tests/expectations/tests/class_with_inner_struct_1_0.rs +++ b/tests/expectations/tests/class_with_inner_struct_1_0.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/class_with_typedef.rs b/tests/expectations/tests/class_with_typedef.rs index 597b5cdb08..52f89b4dca 100644 --- a/tests/expectations/tests/class_with_typedef.rs +++ b/tests/expectations/tests/class_with_typedef.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/comment-indent.rs b/tests/expectations/tests/comment-indent.rs index e208b3bdf5..c381b7342b 100644 --- a/tests/expectations/tests/comment-indent.rs +++ b/tests/expectations/tests/comment-indent.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/complex.rs b/tests/expectations/tests/complex.rs index f40e53a0a0..b13ac90a9c 100644 --- a/tests/expectations/tests/complex.rs +++ b/tests/expectations/tests/complex.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/complex_global.rs b/tests/expectations/tests/complex_global.rs index 0ce2f7f3b3..f21735da53 100644 --- a/tests/expectations/tests/complex_global.rs +++ b/tests/expectations/tests/complex_global.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/const-const-mut-ptr.rs b/tests/expectations/tests/const-const-mut-ptr.rs index b214011699..789fccd63a 100644 --- a/tests/expectations/tests/const-const-mut-ptr.rs +++ b/tests/expectations/tests/const-const-mut-ptr.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/const_array.rs b/tests/expectations/tests/const_array.rs index 77dec91845..191bac9c3f 100644 --- a/tests/expectations/tests/const_array.rs +++ b/tests/expectations/tests/const_array.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/const_array_fn_arg.rs b/tests/expectations/tests/const_array_fn_arg.rs index 289be3686a..3286dce1be 100644 --- a/tests/expectations/tests/const_array_fn_arg.rs +++ b/tests/expectations/tests/const_array_fn_arg.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/const_enum_unnamed.rs b/tests/expectations/tests/const_enum_unnamed.rs index ea5a8f05b8..dae005abd8 100644 --- a/tests/expectations/tests/const_enum_unnamed.rs +++ b/tests/expectations/tests/const_enum_unnamed.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/const_ptr.rs b/tests/expectations/tests/const_ptr.rs index 4f2e60bc2e..0087aa99ee 100644 --- a/tests/expectations/tests/const_ptr.rs +++ b/tests/expectations/tests/const_ptr.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/const_resolved_ty.rs b/tests/expectations/tests/const_resolved_ty.rs index 536fee961d..66939ef932 100644 --- a/tests/expectations/tests/const_resolved_ty.rs +++ b/tests/expectations/tests/const_resolved_ty.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/const_tparam.rs b/tests/expectations/tests/const_tparam.rs index 2512d17df7..f56561f0dd 100644 --- a/tests/expectations/tests/const_tparam.rs +++ b/tests/expectations/tests/const_tparam.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/constant-non-specialized-tp.rs b/tests/expectations/tests/constant-non-specialized-tp.rs index ece462ab7d..6c1e3d382a 100644 --- a/tests/expectations/tests/constant-non-specialized-tp.rs +++ b/tests/expectations/tests/constant-non-specialized-tp.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/constify-all-enums.rs b/tests/expectations/tests/constify-all-enums.rs index 6a8dc3e39d..93388c6484 100644 --- a/tests/expectations/tests/constify-all-enums.rs +++ b/tests/expectations/tests/constify-all-enums.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/constify-enum.rs b/tests/expectations/tests/constify-enum.rs index 24d6ce20c3..e3fd235414 100644 --- a/tests/expectations/tests/constify-enum.rs +++ b/tests/expectations/tests/constify-enum.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/constify-module-enums-basic.rs b/tests/expectations/tests/constify-module-enums-basic.rs index db20058778..2d08d588e5 100644 --- a/tests/expectations/tests/constify-module-enums-basic.rs +++ b/tests/expectations/tests/constify-module-enums-basic.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/constify-module-enums-namespace.rs b/tests/expectations/tests/constify-module-enums-namespace.rs index a15157eb94..b09acf7025 100644 --- a/tests/expectations/tests/constify-module-enums-namespace.rs +++ b/tests/expectations/tests/constify-module-enums-namespace.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/constify-module-enums-shadow-name.rs b/tests/expectations/tests/constify-module-enums-shadow-name.rs index 636aa6fc61..ff0bc45d6c 100644 --- a/tests/expectations/tests/constify-module-enums-shadow-name.rs +++ b/tests/expectations/tests/constify-module-enums-shadow-name.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/constify-module-enums-simple-alias.rs b/tests/expectations/tests/constify-module-enums-simple-alias.rs index 3a7e1116a9..56de348bce 100644 --- a/tests/expectations/tests/constify-module-enums-simple-alias.rs +++ b/tests/expectations/tests/constify-module-enums-simple-alias.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs b/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs index fe58fc8ed1..fc6475df65 100644 --- a/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs +++ b/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/constify-module-enums-types.rs b/tests/expectations/tests/constify-module-enums-types.rs index bbb6308a6b..453796fa8b 100644 --- a/tests/expectations/tests/constify-module-enums-types.rs +++ b/tests/expectations/tests/constify-module-enums-types.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/constructor-tp.rs b/tests/expectations/tests/constructor-tp.rs index 75ff2a1740..4b339dc3c4 100644 --- a/tests/expectations/tests/constructor-tp.rs +++ b/tests/expectations/tests/constructor-tp.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/constructors.rs b/tests/expectations/tests/constructors.rs index f334b91d40..2f13effbef 100644 --- a/tests/expectations/tests/constructors.rs +++ b/tests/expectations/tests/constructors.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/constructors_1_33.rs b/tests/expectations/tests/constructors_1_33.rs index 7de6c27bd2..b5d333325b 100644 --- a/tests/expectations/tests/constructors_1_33.rs +++ b/tests/expectations/tests/constructors_1_33.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/contains-vs-inherits-zero-sized.rs b/tests/expectations/tests/contains-vs-inherits-zero-sized.rs index 61730fb66c..2882fa845d 100644 --- a/tests/expectations/tests/contains-vs-inherits-zero-sized.rs +++ b/tests/expectations/tests/contains-vs-inherits-zero-sized.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/convert-cpp-comment-to-rust.rs b/tests/expectations/tests/convert-cpp-comment-to-rust.rs index ba8359e16e..451cfa31ad 100644 --- a/tests/expectations/tests/convert-cpp-comment-to-rust.rs +++ b/tests/expectations/tests/convert-cpp-comment-to-rust.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/convert-floats.rs b/tests/expectations/tests/convert-floats.rs index 2083b4d2a6..a183f433f7 100644 --- a/tests/expectations/tests/convert-floats.rs +++ b/tests/expectations/tests/convert-floats.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/cpp-empty-layout.rs b/tests/expectations/tests/cpp-empty-layout.rs index f14057bfe6..f5ba025a25 100644 --- a/tests/expectations/tests/cpp-empty-layout.rs +++ b/tests/expectations/tests/cpp-empty-layout.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/crtp.rs b/tests/expectations/tests/crtp.rs index 4e6d7da7fb..2372e21153 100644 --- a/tests/expectations/tests/crtp.rs +++ b/tests/expectations/tests/crtp.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/ctypes-prefix-path.rs b/tests/expectations/tests/ctypes-prefix-path.rs index f7016ec1c8..af6087855e 100644 --- a/tests/expectations/tests/ctypes-prefix-path.rs +++ b/tests/expectations/tests/ctypes-prefix-path.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/dash_language.rs b/tests/expectations/tests/dash_language.rs index ed60dcf813..eb2bbc7689 100644 --- a/tests/expectations/tests/dash_language.rs +++ b/tests/expectations/tests/dash_language.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/decl_extern_int_twice.rs b/tests/expectations/tests/decl_extern_int_twice.rs index 6cf37251a4..d812b03238 100644 --- a/tests/expectations/tests/decl_extern_int_twice.rs +++ b/tests/expectations/tests/decl_extern_int_twice.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/decl_ptr_to_array.rs b/tests/expectations/tests/decl_ptr_to_array.rs index fc6184d54a..b520f1e033 100644 --- a/tests/expectations/tests/decl_ptr_to_array.rs +++ b/tests/expectations/tests/decl_ptr_to_array.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/default-enum-style-constified-module.rs b/tests/expectations/tests/default-enum-style-constified-module.rs index 4b71efdd1d..1ad803523a 100644 --- a/tests/expectations/tests/default-enum-style-constified-module.rs +++ b/tests/expectations/tests/default-enum-style-constified-module.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/default-template-parameter.rs b/tests/expectations/tests/default-template-parameter.rs index b4388fe2d0..666b3e6dd4 100644 --- a/tests/expectations/tests/default-template-parameter.rs +++ b/tests/expectations/tests/default-template-parameter.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/derive-bitfield-method-same-name.rs b/tests/expectations/tests/derive-bitfield-method-same-name.rs index b86b807abd..c804b54193 100644 --- a/tests/expectations/tests/derive-bitfield-method-same-name.rs +++ b/tests/expectations/tests/derive-bitfield-method-same-name.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/derive-clone.rs b/tests/expectations/tests/derive-clone.rs index 3d19fda129..e2dc7bdb92 100644 --- a/tests/expectations/tests/derive-clone.rs +++ b/tests/expectations/tests/derive-clone.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/derive-clone_1_0.rs b/tests/expectations/tests/derive-clone_1_0.rs index 7fd60b1a71..e5dc92dc34 100644 --- a/tests/expectations/tests/derive-clone_1_0.rs +++ b/tests/expectations/tests/derive-clone_1_0.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/derive-custom.rs b/tests/expectations/tests/derive-custom.rs index 1184e43568..1cae9af0ae 100644 --- a/tests/expectations/tests/derive-custom.rs +++ b/tests/expectations/tests/derive-custom.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/derive-debug-bitfield-core.rs b/tests/expectations/tests/derive-debug-bitfield-core.rs index b0a006e65d..690078b20b 100644 --- a/tests/expectations/tests/derive-debug-bitfield-core.rs +++ b/tests/expectations/tests/derive-debug-bitfield-core.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/derive-debug-bitfield.rs b/tests/expectations/tests/derive-debug-bitfield.rs index 945824485d..2474ec9ff7 100644 --- a/tests/expectations/tests/derive-debug-bitfield.rs +++ b/tests/expectations/tests/derive-debug-bitfield.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/derive-debug-function-pointer.rs b/tests/expectations/tests/derive-debug-function-pointer.rs index 7915fb66fc..7052ff0014 100644 --- a/tests/expectations/tests/derive-debug-function-pointer.rs +++ b/tests/expectations/tests/derive-debug-function-pointer.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/derive-debug-generic.rs b/tests/expectations/tests/derive-debug-generic.rs index 40cc99a58d..88fd972833 100644 --- a/tests/expectations/tests/derive-debug-generic.rs +++ b/tests/expectations/tests/derive-debug-generic.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/derive-debug-mangle-name.rs b/tests/expectations/tests/derive-debug-mangle-name.rs index e9ea16e440..4b4ae27baf 100644 --- a/tests/expectations/tests/derive-debug-mangle-name.rs +++ b/tests/expectations/tests/derive-debug-mangle-name.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/derive-debug-opaque-template-instantiation.rs b/tests/expectations/tests/derive-debug-opaque-template-instantiation.rs index d00b65ef49..4e87368b30 100644 --- a/tests/expectations/tests/derive-debug-opaque-template-instantiation.rs +++ b/tests/expectations/tests/derive-debug-opaque-template-instantiation.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/derive-debug-opaque.rs b/tests/expectations/tests/derive-debug-opaque.rs index a1747fcc8c..dfb264c7a0 100644 --- a/tests/expectations/tests/derive-debug-opaque.rs +++ b/tests/expectations/tests/derive-debug-opaque.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/derive-default-and-blacklist.rs b/tests/expectations/tests/derive-default-and-blacklist.rs index 0087dd508a..ce0f252890 100644 --- a/tests/expectations/tests/derive-default-and-blacklist.rs +++ b/tests/expectations/tests/derive-default-and-blacklist.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/derive-fn-ptr.rs b/tests/expectations/tests/derive-fn-ptr.rs index 6ea28a0219..7c9f426115 100644 --- a/tests/expectations/tests/derive-fn-ptr.rs +++ b/tests/expectations/tests/derive-fn-ptr.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/derive-hash-and-blacklist.rs b/tests/expectations/tests/derive-hash-and-blacklist.rs index 51a792f106..458081a457 100644 --- a/tests/expectations/tests/derive-hash-and-blacklist.rs +++ b/tests/expectations/tests/derive-hash-and-blacklist.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/derive-hash-blacklisting.rs b/tests/expectations/tests/derive-hash-blacklisting.rs index 8b696e9269..0424077b83 100644 --- a/tests/expectations/tests/derive-hash-blacklisting.rs +++ b/tests/expectations/tests/derive-hash-blacklisting.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs b/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs index 3e0693b8dc..92846f3c96 100644 --- a/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs +++ b/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/derive-hash-struct-with-float-array.rs b/tests/expectations/tests/derive-hash-struct-with-float-array.rs index 9ff64fdeb7..e2e1bcef22 100644 --- a/tests/expectations/tests/derive-hash-struct-with-float-array.rs +++ b/tests/expectations/tests/derive-hash-struct-with-float-array.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs b/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs index 45869e9470..851080749d 100644 --- a/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs +++ b/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/derive-hash-struct-with-pointer.rs b/tests/expectations/tests/derive-hash-struct-with-pointer.rs index 28d3105e58..152bffc2e8 100644 --- a/tests/expectations/tests/derive-hash-struct-with-pointer.rs +++ b/tests/expectations/tests/derive-hash-struct-with-pointer.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/derive-hash-template-def-float.rs b/tests/expectations/tests/derive-hash-template-def-float.rs index b404080240..554eb8bf7a 100644 --- a/tests/expectations/tests/derive-hash-template-def-float.rs +++ b/tests/expectations/tests/derive-hash-template-def-float.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/derive-hash-template-inst-float.rs b/tests/expectations/tests/derive-hash-template-inst-float.rs index ee9b3f4c32..c0a7272554 100644 --- a/tests/expectations/tests/derive-hash-template-inst-float.rs +++ b/tests/expectations/tests/derive-hash-template-inst-float.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/derive-partialeq-and-blacklist.rs b/tests/expectations/tests/derive-partialeq-and-blacklist.rs index 2026e5ad31..88bccdff21 100644 --- a/tests/expectations/tests/derive-partialeq-and-blacklist.rs +++ b/tests/expectations/tests/derive-partialeq-and-blacklist.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/derive-partialeq-anonfield.rs b/tests/expectations/tests/derive-partialeq-anonfield.rs index b5cb15937d..3486641deb 100644 --- a/tests/expectations/tests/derive-partialeq-anonfield.rs +++ b/tests/expectations/tests/derive-partialeq-anonfield.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/derive-partialeq-base.rs b/tests/expectations/tests/derive-partialeq-base.rs index b6c38c0fa1..9946616b34 100644 --- a/tests/expectations/tests/derive-partialeq-base.rs +++ b/tests/expectations/tests/derive-partialeq-base.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/derive-partialeq-bitfield.rs b/tests/expectations/tests/derive-partialeq-bitfield.rs index 808afc05c8..9896011f9a 100644 --- a/tests/expectations/tests/derive-partialeq-bitfield.rs +++ b/tests/expectations/tests/derive-partialeq-bitfield.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/derive-partialeq-core.rs b/tests/expectations/tests/derive-partialeq-core.rs index 8cf4b4a13c..cbe1f57749 100644 --- a/tests/expectations/tests/derive-partialeq-core.rs +++ b/tests/expectations/tests/derive-partialeq-core.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/derive-partialeq-pointer.rs b/tests/expectations/tests/derive-partialeq-pointer.rs index 2ac23c8120..55bd782fa7 100644 --- a/tests/expectations/tests/derive-partialeq-pointer.rs +++ b/tests/expectations/tests/derive-partialeq-pointer.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/derive-partialeq-union.rs b/tests/expectations/tests/derive-partialeq-union.rs index f91ce1242b..e873d134a7 100644 --- a/tests/expectations/tests/derive-partialeq-union.rs +++ b/tests/expectations/tests/derive-partialeq-union.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/derive-partialeq-union_1_0.rs b/tests/expectations/tests/derive-partialeq-union_1_0.rs index 7739088cb0..4b675fc71c 100644 --- a/tests/expectations/tests/derive-partialeq-union_1_0.rs +++ b/tests/expectations/tests/derive-partialeq-union_1_0.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/disable-namespacing.rs b/tests/expectations/tests/disable-namespacing.rs index 0ef47c0ea4..626bb060c5 100644 --- a/tests/expectations/tests/disable-namespacing.rs +++ b/tests/expectations/tests/disable-namespacing.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/disable-nested-struct-naming.rs b/tests/expectations/tests/disable-nested-struct-naming.rs index db34158ee3..a9ad26a50a 100644 --- a/tests/expectations/tests/disable-nested-struct-naming.rs +++ b/tests/expectations/tests/disable-nested-struct-naming.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/disable-untagged-union.rs b/tests/expectations/tests/disable-untagged-union.rs index 9661ef7969..5300273384 100644 --- a/tests/expectations/tests/disable-untagged-union.rs +++ b/tests/expectations/tests/disable-untagged-union.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/divide-by-zero-in-struct-layout.rs b/tests/expectations/tests/divide-by-zero-in-struct-layout.rs index 34a82ca024..1366548ea7 100644 --- a/tests/expectations/tests/divide-by-zero-in-struct-layout.rs +++ b/tests/expectations/tests/divide-by-zero-in-struct-layout.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/do-not-derive-copy.rs b/tests/expectations/tests/do-not-derive-copy.rs index c7a384d081..4112d88a5c 100644 --- a/tests/expectations/tests/do-not-derive-copy.rs +++ b/tests/expectations/tests/do-not-derive-copy.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/doggo-or-null.rs b/tests/expectations/tests/doggo-or-null.rs index 216889146e..1d3bf5c16a 100644 --- a/tests/expectations/tests/doggo-or-null.rs +++ b/tests/expectations/tests/doggo-or-null.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/dupe-enum-variant-in-namespace.rs b/tests/expectations/tests/dupe-enum-variant-in-namespace.rs index b93100b2fa..2d3c4b3384 100644 --- a/tests/expectations/tests/dupe-enum-variant-in-namespace.rs +++ b/tests/expectations/tests/dupe-enum-variant-in-namespace.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/duplicated-namespaces-definitions.rs b/tests/expectations/tests/duplicated-namespaces-definitions.rs index 8a377151fd..b79ccaea3a 100644 --- a/tests/expectations/tests/duplicated-namespaces-definitions.rs +++ b/tests/expectations/tests/duplicated-namespaces-definitions.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/duplicated-namespaces.rs b/tests/expectations/tests/duplicated-namespaces.rs index d44dac5d75..0bbceac8e2 100644 --- a/tests/expectations/tests/duplicated-namespaces.rs +++ b/tests/expectations/tests/duplicated-namespaces.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/duplicated_constants_in_ns.rs b/tests/expectations/tests/duplicated_constants_in_ns.rs index f616eaad1a..3b3405db5c 100644 --- a/tests/expectations/tests/duplicated_constants_in_ns.rs +++ b/tests/expectations/tests/duplicated_constants_in_ns.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/elaborated.rs b/tests/expectations/tests/elaborated.rs index def5e7c468..4741601640 100644 --- a/tests/expectations/tests/elaborated.rs +++ b/tests/expectations/tests/elaborated.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/empty-enum.rs b/tests/expectations/tests/empty-enum.rs index 06f24422b3..5cf787cb15 100644 --- a/tests/expectations/tests/empty-enum.rs +++ b/tests/expectations/tests/empty-enum.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/empty-union.rs b/tests/expectations/tests/empty-union.rs index 6cae993895..1f7d33d36d 100644 --- a/tests/expectations/tests/empty-union.rs +++ b/tests/expectations/tests/empty-union.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/empty_template_param_name.rs b/tests/expectations/tests/empty_template_param_name.rs index b80a983ba1..aa751f77e6 100644 --- a/tests/expectations/tests/empty_template_param_name.rs +++ b/tests/expectations/tests/empty_template_param_name.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/enum-default-bitfield.rs b/tests/expectations/tests/enum-default-bitfield.rs index a5ba04efba..fa6f77636b 100644 --- a/tests/expectations/tests/enum-default-bitfield.rs +++ b/tests/expectations/tests/enum-default-bitfield.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/enum-default-consts.rs b/tests/expectations/tests/enum-default-consts.rs index c2ef65026b..4973d7c86c 100644 --- a/tests/expectations/tests/enum-default-consts.rs +++ b/tests/expectations/tests/enum-default-consts.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/enum-default-module.rs b/tests/expectations/tests/enum-default-module.rs index 1ed4338fcf..a3db9afacb 100644 --- a/tests/expectations/tests/enum-default-module.rs +++ b/tests/expectations/tests/enum-default-module.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/enum-default-rust.rs b/tests/expectations/tests/enum-default-rust.rs index 6c65832476..f1d9c7a1ea 100644 --- a/tests/expectations/tests/enum-default-rust.rs +++ b/tests/expectations/tests/enum-default-rust.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/enum-doc-bitfield.rs b/tests/expectations/tests/enum-doc-bitfield.rs index 5fe668be07..817ef3a34b 100644 --- a/tests/expectations/tests/enum-doc-bitfield.rs +++ b/tests/expectations/tests/enum-doc-bitfield.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/enum-doc-mod.rs b/tests/expectations/tests/enum-doc-mod.rs index 1da02f4127..6dc60c570e 100644 --- a/tests/expectations/tests/enum-doc-mod.rs +++ b/tests/expectations/tests/enum-doc-mod.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/enum-doc-rusty.rs b/tests/expectations/tests/enum-doc-rusty.rs index e4209e3e2e..7c44143291 100644 --- a/tests/expectations/tests/enum-doc-rusty.rs +++ b/tests/expectations/tests/enum-doc-rusty.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/enum-doc.rs b/tests/expectations/tests/enum-doc.rs index 0df3a5a5ca..b58fb283e2 100644 --- a/tests/expectations/tests/enum-doc.rs +++ b/tests/expectations/tests/enum-doc.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/enum-undefault.rs b/tests/expectations/tests/enum-undefault.rs index 11d4162287..b865c82001 100644 --- a/tests/expectations/tests/enum-undefault.rs +++ b/tests/expectations/tests/enum-undefault.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/enum-variant-replaces.rs b/tests/expectations/tests/enum-variant-replaces.rs index d710e100db..b5f629db83 100644 --- a/tests/expectations/tests/enum-variant-replaces.rs +++ b/tests/expectations/tests/enum-variant-replaces.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/enum.rs b/tests/expectations/tests/enum.rs index 104d6b8b16..27a1f41bad 100644 --- a/tests/expectations/tests/enum.rs +++ b/tests/expectations/tests/enum.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/enum_alias.rs b/tests/expectations/tests/enum_alias.rs index 2996177981..7d6a49a968 100644 --- a/tests/expectations/tests/enum_alias.rs +++ b/tests/expectations/tests/enum_alias.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/enum_and_vtable_mangling.rs b/tests/expectations/tests/enum_and_vtable_mangling.rs index 8d2cf204e8..72efb618ed 100644 --- a/tests/expectations/tests/enum_and_vtable_mangling.rs +++ b/tests/expectations/tests/enum_and_vtable_mangling.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/enum_dupe.rs b/tests/expectations/tests/enum_dupe.rs index 8462f6d235..185a870de3 100644 --- a/tests/expectations/tests/enum_dupe.rs +++ b/tests/expectations/tests/enum_dupe.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/enum_explicit_type.rs b/tests/expectations/tests/enum_explicit_type.rs index fee19153a0..2f44c0b248 100644 --- a/tests/expectations/tests/enum_explicit_type.rs +++ b/tests/expectations/tests/enum_explicit_type.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/enum_explicit_type_constants.rs b/tests/expectations/tests/enum_explicit_type_constants.rs index c15849f37f..2454b39ca3 100644 --- a/tests/expectations/tests/enum_explicit_type_constants.rs +++ b/tests/expectations/tests/enum_explicit_type_constants.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/enum_in_template.rs b/tests/expectations/tests/enum_in_template.rs index 24be7a7173..c4c06a3733 100644 --- a/tests/expectations/tests/enum_in_template.rs +++ b/tests/expectations/tests/enum_in_template.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/enum_in_template_with_typedef.rs b/tests/expectations/tests/enum_in_template_with_typedef.rs index 91c22fcd51..60bd783499 100644 --- a/tests/expectations/tests/enum_in_template_with_typedef.rs +++ b/tests/expectations/tests/enum_in_template_with_typedef.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/enum_negative.rs b/tests/expectations/tests/enum_negative.rs index 4824c5d579..e37d42d573 100644 --- a/tests/expectations/tests/enum_negative.rs +++ b/tests/expectations/tests/enum_negative.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/enum_packed.rs b/tests/expectations/tests/enum_packed.rs index a1514ab254..62f69fc9ee 100644 --- a/tests/expectations/tests/enum_packed.rs +++ b/tests/expectations/tests/enum_packed.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/eval-value-dependent.rs b/tests/expectations/tests/eval-value-dependent.rs index b290a2e6a1..3376bfc6b3 100644 --- a/tests/expectations/tests/eval-value-dependent.rs +++ b/tests/expectations/tests/eval-value-dependent.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/eval-variadic-template-parameter.rs b/tests/expectations/tests/eval-variadic-template-parameter.rs index 8f6f8981df..576bb721c5 100644 --- a/tests/expectations/tests/eval-variadic-template-parameter.rs +++ b/tests/expectations/tests/eval-variadic-template-parameter.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/extern-const-struct.rs b/tests/expectations/tests/extern-const-struct.rs index 51e9f97096..0f515ed58b 100644 --- a/tests/expectations/tests/extern-const-struct.rs +++ b/tests/expectations/tests/extern-const-struct.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/extern.rs b/tests/expectations/tests/extern.rs index af01e955c2..7ded13f179 100644 --- a/tests/expectations/tests/extern.rs +++ b/tests/expectations/tests/extern.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/float128.rs b/tests/expectations/tests/float128.rs index d6776794e9..131dbdf39f 100644 --- a/tests/expectations/tests/float128.rs +++ b/tests/expectations/tests/float128.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/forward-declaration-autoptr.rs b/tests/expectations/tests/forward-declaration-autoptr.rs index 8501ce97ac..33a92bb476 100644 --- a/tests/expectations/tests/forward-declaration-autoptr.rs +++ b/tests/expectations/tests/forward-declaration-autoptr.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/forward-enum-decl.rs b/tests/expectations/tests/forward-enum-decl.rs index 90666f4b1c..eddb53782f 100644 --- a/tests/expectations/tests/forward-enum-decl.rs +++ b/tests/expectations/tests/forward-enum-decl.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/forward-inherit-struct-with-fields.rs b/tests/expectations/tests/forward-inherit-struct-with-fields.rs index 0135896482..cae75bf4da 100644 --- a/tests/expectations/tests/forward-inherit-struct-with-fields.rs +++ b/tests/expectations/tests/forward-inherit-struct-with-fields.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/forward-inherit-struct.rs b/tests/expectations/tests/forward-inherit-struct.rs index e39c8669a6..ae565be5b3 100644 --- a/tests/expectations/tests/forward-inherit-struct.rs +++ b/tests/expectations/tests/forward-inherit-struct.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/forward_declared_complex_types.rs b/tests/expectations/tests/forward_declared_complex_types.rs index 3175b8a901..c35d914c2d 100644 --- a/tests/expectations/tests/forward_declared_complex_types.rs +++ b/tests/expectations/tests/forward_declared_complex_types.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/forward_declared_complex_types_1_0.rs b/tests/expectations/tests/forward_declared_complex_types_1_0.rs index 011ab35e9a..9fea597c0a 100644 --- a/tests/expectations/tests/forward_declared_complex_types_1_0.rs +++ b/tests/expectations/tests/forward_declared_complex_types_1_0.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/forward_declared_opaque.rs b/tests/expectations/tests/forward_declared_opaque.rs index 44aff91f49..58c02b4406 100644 --- a/tests/expectations/tests/forward_declared_opaque.rs +++ b/tests/expectations/tests/forward_declared_opaque.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/forward_declared_struct.rs b/tests/expectations/tests/forward_declared_struct.rs index a595422628..2ecfc60ed6 100644 --- a/tests/expectations/tests/forward_declared_struct.rs +++ b/tests/expectations/tests/forward_declared_struct.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/func_proto.rs b/tests/expectations/tests/func_proto.rs index af01e955c2..7ded13f179 100644 --- a/tests/expectations/tests/func_proto.rs +++ b/tests/expectations/tests/func_proto.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/func_ptr.rs b/tests/expectations/tests/func_ptr.rs index ce89a2e6f8..9c718f03ec 100644 --- a/tests/expectations/tests/func_ptr.rs +++ b/tests/expectations/tests/func_ptr.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/func_ptr_in_struct.rs b/tests/expectations/tests/func_ptr_in_struct.rs index 60b8029d4a..bd1ec8c457 100644 --- a/tests/expectations/tests/func_ptr_in_struct.rs +++ b/tests/expectations/tests/func_ptr_in_struct.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/func_ptr_return_type.rs b/tests/expectations/tests/func_ptr_return_type.rs index 0ce7809c25..8f2da8efda 100644 --- a/tests/expectations/tests/func_ptr_return_type.rs +++ b/tests/expectations/tests/func_ptr_return_type.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/func_with_array_arg.rs b/tests/expectations/tests/func_with_array_arg.rs index e03cb82e4d..f98192f8db 100644 --- a/tests/expectations/tests/func_with_array_arg.rs +++ b/tests/expectations/tests/func_with_array_arg.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/func_with_func_ptr_arg.rs b/tests/expectations/tests/func_with_func_ptr_arg.rs index 8d94b715bb..fb06b88e68 100644 --- a/tests/expectations/tests/func_with_func_ptr_arg.rs +++ b/tests/expectations/tests/func_with_func_ptr_arg.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/function-typedef-stdcall.rs b/tests/expectations/tests/function-typedef-stdcall.rs index 2c77c1b5a7..11c9ef2072 100644 --- a/tests/expectations/tests/function-typedef-stdcall.rs +++ b/tests/expectations/tests/function-typedef-stdcall.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/gen-constructors-neg.rs b/tests/expectations/tests/gen-constructors-neg.rs index f14057bfe6..f5ba025a25 100644 --- a/tests/expectations/tests/gen-constructors-neg.rs +++ b/tests/expectations/tests/gen-constructors-neg.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/gen-constructors.rs b/tests/expectations/tests/gen-constructors.rs index 878a664d06..89b8637954 100644 --- a/tests/expectations/tests/gen-constructors.rs +++ b/tests/expectations/tests/gen-constructors.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/gen-destructors-neg.rs b/tests/expectations/tests/gen-destructors-neg.rs index 552ad41e8d..67b6d70143 100644 --- a/tests/expectations/tests/gen-destructors-neg.rs +++ b/tests/expectations/tests/gen-destructors-neg.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/gen-destructors.rs b/tests/expectations/tests/gen-destructors.rs index 1715a9d113..7d96870df8 100644 --- a/tests/expectations/tests/gen-destructors.rs +++ b/tests/expectations/tests/gen-destructors.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/generate-inline.rs b/tests/expectations/tests/generate-inline.rs index 4276a3efc5..3cb865a4d7 100644 --- a/tests/expectations/tests/generate-inline.rs +++ b/tests/expectations/tests/generate-inline.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/i128.rs b/tests/expectations/tests/i128.rs index 0d926260bc..1a239694c4 100644 --- a/tests/expectations/tests/i128.rs +++ b/tests/expectations/tests/i128.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/in_class_typedef.rs b/tests/expectations/tests/in_class_typedef.rs index 5fb517f3a2..7bb7d39182 100644 --- a/tests/expectations/tests/in_class_typedef.rs +++ b/tests/expectations/tests/in_class_typedef.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/incomplete-array-padding.rs b/tests/expectations/tests/incomplete-array-padding.rs index 3f2110b0c6..36e523b5e1 100644 --- a/tests/expectations/tests/incomplete-array-padding.rs +++ b/tests/expectations/tests/incomplete-array-padding.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/infinite-macro.rs b/tests/expectations/tests/infinite-macro.rs index b1a6646397..081a0c296b 100644 --- a/tests/expectations/tests/infinite-macro.rs +++ b/tests/expectations/tests/infinite-macro.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs b/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs index 6e118d685f..c488713fc7 100644 --- a/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs +++ b/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/inherit-namespaced.rs b/tests/expectations/tests/inherit-namespaced.rs index e39c8669a6..ae565be5b3 100644 --- a/tests/expectations/tests/inherit-namespaced.rs +++ b/tests/expectations/tests/inherit-namespaced.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/inherit_named.rs b/tests/expectations/tests/inherit_named.rs index 7c7f729ff6..77de3ec3f4 100644 --- a/tests/expectations/tests/inherit_named.rs +++ b/tests/expectations/tests/inherit_named.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/inherit_typedef.rs b/tests/expectations/tests/inherit_typedef.rs index 13eac16b20..285dd44f1c 100644 --- a/tests/expectations/tests/inherit_typedef.rs +++ b/tests/expectations/tests/inherit_typedef.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/inline-function.rs b/tests/expectations/tests/inline-function.rs index d6776794e9..131dbdf39f 100644 --- a/tests/expectations/tests/inline-function.rs +++ b/tests/expectations/tests/inline-function.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/inline_namespace.rs b/tests/expectations/tests/inline_namespace.rs index b6905c4dd9..036d2da618 100644 --- a/tests/expectations/tests/inline_namespace.rs +++ b/tests/expectations/tests/inline_namespace.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/inline_namespace_conservative.rs b/tests/expectations/tests/inline_namespace_conservative.rs index bfd48385bc..3d2ce0c419 100644 --- a/tests/expectations/tests/inline_namespace_conservative.rs +++ b/tests/expectations/tests/inline_namespace_conservative.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/inline_namespace_no_ns_enabled.rs b/tests/expectations/tests/inline_namespace_no_ns_enabled.rs index ac2fa72a5c..20bac9a137 100644 --- a/tests/expectations/tests/inline_namespace_no_ns_enabled.rs +++ b/tests/expectations/tests/inline_namespace_no_ns_enabled.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/inline_namespace_whitelist.rs b/tests/expectations/tests/inline_namespace_whitelist.rs index e4a471cfe8..1f4bc686c1 100644 --- a/tests/expectations/tests/inline_namespace_whitelist.rs +++ b/tests/expectations/tests/inline_namespace_whitelist.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/inner_const.rs b/tests/expectations/tests/inner_const.rs index c2e7902333..912ae02422 100644 --- a/tests/expectations/tests/inner_const.rs +++ b/tests/expectations/tests/inner_const.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/inner_template_self.rs b/tests/expectations/tests/inner_template_self.rs index 91666c8afa..f3e153f495 100644 --- a/tests/expectations/tests/inner_template_self.rs +++ b/tests/expectations/tests/inner_template_self.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/int128_t.rs b/tests/expectations/tests/int128_t.rs index d6776794e9..131dbdf39f 100644 --- a/tests/expectations/tests/int128_t.rs +++ b/tests/expectations/tests/int128_t.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-1025-unknown-enum-repr.rs b/tests/expectations/tests/issue-1025-unknown-enum-repr.rs index b871172724..c42e167fba 100644 --- a/tests/expectations/tests/issue-1025-unknown-enum-repr.rs +++ b/tests/expectations/tests/issue-1025-unknown-enum-repr.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-1034.rs b/tests/expectations/tests/issue-1034.rs index 1433fab1cb..ef122ec0bc 100644 --- a/tests/expectations/tests/issue-1034.rs +++ b/tests/expectations/tests/issue-1034.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-1040.rs b/tests/expectations/tests/issue-1040.rs index cde27973b9..8503e8d226 100644 --- a/tests/expectations/tests/issue-1040.rs +++ b/tests/expectations/tests/issue-1040.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs b/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs index 5665b24e20..9ac4f2fe8b 100644 --- a/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs +++ b/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-1113-template-references.rs b/tests/expectations/tests/issue-1113-template-references.rs index 54c80b3df5..79a06dac9f 100644 --- a/tests/expectations/tests/issue-1113-template-references.rs +++ b/tests/expectations/tests/issue-1113-template-references.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-1118-using-forward-decl.rs b/tests/expectations/tests/issue-1118-using-forward-decl.rs index 580329a5f3..df764a583e 100644 --- a/tests/expectations/tests/issue-1118-using-forward-decl.rs +++ b/tests/expectations/tests/issue-1118-using-forward-decl.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs b/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs index 1c1baa5919..9232767e34 100644 --- a/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs +++ b/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-1198-alias-rust-bitfield-enum.rs b/tests/expectations/tests/issue-1198-alias-rust-bitfield-enum.rs index 8c58b232c7..95f6cd5a14 100644 --- a/tests/expectations/tests/issue-1198-alias-rust-bitfield-enum.rs +++ b/tests/expectations/tests/issue-1198-alias-rust-bitfield-enum.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-1198-alias-rust-const-mod-bitfield-enum.rs b/tests/expectations/tests/issue-1198-alias-rust-const-mod-bitfield-enum.rs index 888636a11d..f4997aa2c2 100644 --- a/tests/expectations/tests/issue-1198-alias-rust-const-mod-bitfield-enum.rs +++ b/tests/expectations/tests/issue-1198-alias-rust-const-mod-bitfield-enum.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-1198-alias-rust-const-mod-enum.rs b/tests/expectations/tests/issue-1198-alias-rust-const-mod-enum.rs index 888636a11d..f4997aa2c2 100644 --- a/tests/expectations/tests/issue-1198-alias-rust-const-mod-enum.rs +++ b/tests/expectations/tests/issue-1198-alias-rust-const-mod-enum.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-1198-alias-rust-enum.rs b/tests/expectations/tests/issue-1198-alias-rust-enum.rs index 1659e29e7a..491430389f 100644 --- a/tests/expectations/tests/issue-1198-alias-rust-enum.rs +++ b/tests/expectations/tests/issue-1198-alias-rust-enum.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-1216-variadic-member.rs b/tests/expectations/tests/issue-1216-variadic-member.rs index e509956090..5bca80966c 100644 --- a/tests/expectations/tests/issue-1216-variadic-member.rs +++ b/tests/expectations/tests/issue-1216-variadic-member.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-1238-fwd-no-copy.rs b/tests/expectations/tests/issue-1238-fwd-no-copy.rs index 061e39ea54..006900cb6e 100644 --- a/tests/expectations/tests/issue-1238-fwd-no-copy.rs +++ b/tests/expectations/tests/issue-1238-fwd-no-copy.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-1281.rs b/tests/expectations/tests/issue-1281.rs index d56d6361cf..fe18fb1a0a 100644 --- a/tests/expectations/tests/issue-1281.rs +++ b/tests/expectations/tests/issue-1281.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-1285.rs b/tests/expectations/tests/issue-1285.rs index b630c54c30..3e0da41bcb 100644 --- a/tests/expectations/tests/issue-1285.rs +++ b/tests/expectations/tests/issue-1285.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-1291.rs b/tests/expectations/tests/issue-1291.rs index 81b29f7d1e..5680c348cf 100644 --- a/tests/expectations/tests/issue-1291.rs +++ b/tests/expectations/tests/issue-1291.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-1350-attribute-overloadable.rs b/tests/expectations/tests/issue-1350-attribute-overloadable.rs index 39b03406eb..4deed06055 100644 --- a/tests/expectations/tests/issue-1350-attribute-overloadable.rs +++ b/tests/expectations/tests/issue-1350-attribute-overloadable.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-1382-rust-primitive-types.rs b/tests/expectations/tests/issue-1382-rust-primitive-types.rs index 053fee91e6..6f5aec4b6f 100644 --- a/tests/expectations/tests/issue-1382-rust-primitive-types.rs +++ b/tests/expectations/tests/issue-1382-rust-primitive-types.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-1435.rs b/tests/expectations/tests/issue-1435.rs index 4c8b52e6c4..af602ebbe9 100644 --- a/tests/expectations/tests/issue-1435.rs +++ b/tests/expectations/tests/issue-1435.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-1443.rs b/tests/expectations/tests/issue-1443.rs index 54045ef32c..b02a2c4d8f 100644 --- a/tests/expectations/tests/issue-1443.rs +++ b/tests/expectations/tests/issue-1443.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-1464.rs b/tests/expectations/tests/issue-1464.rs index d6776794e9..131dbdf39f 100644 --- a/tests/expectations/tests/issue-1464.rs +++ b/tests/expectations/tests/issue-1464.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-1488-enum-new-type.rs b/tests/expectations/tests/issue-1488-enum-new-type.rs index bc8a23d2fa..018cea67df 100644 --- a/tests/expectations/tests/issue-1488-enum-new-type.rs +++ b/tests/expectations/tests/issue-1488-enum-new-type.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-1488-options.rs b/tests/expectations/tests/issue-1488-options.rs index e429ef3f87..cf13b56284 100644 --- a/tests/expectations/tests/issue-1488-options.rs +++ b/tests/expectations/tests/issue-1488-options.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-1488-template-alias-new-type.rs b/tests/expectations/tests/issue-1488-template-alias-new-type.rs index fcd712bf4e..1af0c5751d 100644 --- a/tests/expectations/tests/issue-1488-template-alias-new-type.rs +++ b/tests/expectations/tests/issue-1488-template-alias-new-type.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-1498.rs b/tests/expectations/tests/issue-1498.rs index 2c8eb4fe41..72bf7f7c48 100644 --- a/tests/expectations/tests/issue-1498.rs +++ b/tests/expectations/tests/issue-1498.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-1514.rs b/tests/expectations/tests/issue-1514.rs index 3f59f7430c..b2c11ea984 100644 --- a/tests/expectations/tests/issue-1514.rs +++ b/tests/expectations/tests/issue-1514.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-1554.rs b/tests/expectations/tests/issue-1554.rs index d302997913..e50023eea3 100644 --- a/tests/expectations/tests/issue-1554.rs +++ b/tests/expectations/tests/issue-1554.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-1599-opaque-typedef-to-enum.rs b/tests/expectations/tests/issue-1599-opaque-typedef-to-enum.rs index f98c6211b9..27a28bfead 100644 --- a/tests/expectations/tests/issue-1599-opaque-typedef-to-enum.rs +++ b/tests/expectations/tests/issue-1599-opaque-typedef-to-enum.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-1676-macro-namespace-prefix.rs b/tests/expectations/tests/issue-1676-macro-namespace-prefix.rs index d6776794e9..131dbdf39f 100644 --- a/tests/expectations/tests/issue-1676-macro-namespace-prefix.rs +++ b/tests/expectations/tests/issue-1676-macro-namespace-prefix.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-358.rs b/tests/expectations/tests/issue-358.rs index 19624c5176..320c7e1d89 100644 --- a/tests/expectations/tests/issue-358.rs +++ b/tests/expectations/tests/issue-358.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-372.rs b/tests/expectations/tests/issue-372.rs index ff9a7d046e..d232aabd70 100644 --- a/tests/expectations/tests/issue-372.rs +++ b/tests/expectations/tests/issue-372.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-410.rs b/tests/expectations/tests/issue-410.rs index 26ebcc3c78..71d27a2247 100644 --- a/tests/expectations/tests/issue-410.rs +++ b/tests/expectations/tests/issue-410.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-446.rs b/tests/expectations/tests/issue-446.rs index e4f1b2a793..6c9cae462f 100644 --- a/tests/expectations/tests/issue-446.rs +++ b/tests/expectations/tests/issue-446.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-447.rs b/tests/expectations/tests/issue-447.rs index 8103a69f86..949db73b79 100644 --- a/tests/expectations/tests/issue-447.rs +++ b/tests/expectations/tests/issue-447.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-493.rs b/tests/expectations/tests/issue-493.rs index dd4f6aa188..74e68ecbc2 100644 --- a/tests/expectations/tests/issue-493.rs +++ b/tests/expectations/tests/issue-493.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-493_1_0.rs b/tests/expectations/tests/issue-493_1_0.rs index 3438d2b475..f15ff8a768 100644 --- a/tests/expectations/tests/issue-493_1_0.rs +++ b/tests/expectations/tests/issue-493_1_0.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-511.rs b/tests/expectations/tests/issue-511.rs index 5d7982e054..b7705ef2b1 100644 --- a/tests/expectations/tests/issue-511.rs +++ b/tests/expectations/tests/issue-511.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-537-repr-packed-n.rs b/tests/expectations/tests/issue-537-repr-packed-n.rs index 6ec9a2d96a..13e1482d30 100644 --- a/tests/expectations/tests/issue-537-repr-packed-n.rs +++ b/tests/expectations/tests/issue-537-repr-packed-n.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-537.rs b/tests/expectations/tests/issue-537.rs index 1081f7abb4..e67c0e9c2e 100644 --- a/tests/expectations/tests/issue-537.rs +++ b/tests/expectations/tests/issue-537.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-544-stylo-creduce-2.rs b/tests/expectations/tests/issue-544-stylo-creduce-2.rs index 8d708ad672..5a6242ea8e 100644 --- a/tests/expectations/tests/issue-544-stylo-creduce-2.rs +++ b/tests/expectations/tests/issue-544-stylo-creduce-2.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-544-stylo-creduce.rs b/tests/expectations/tests/issue-544-stylo-creduce.rs index 7c4cd7e19a..1516c0a95e 100644 --- a/tests/expectations/tests/issue-544-stylo-creduce.rs +++ b/tests/expectations/tests/issue-544-stylo-creduce.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs b/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs index 18ecc73ed8..98f3ea040f 100644 --- a/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs +++ b/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-573-layout-test-failures.rs b/tests/expectations/tests/issue-573-layout-test-failures.rs index 0dfac5189f..871849aa47 100644 --- a/tests/expectations/tests/issue-573-layout-test-failures.rs +++ b/tests/expectations/tests/issue-573-layout-test-failures.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs b/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs index e1087f63dd..e04ff24cba 100644 --- a/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs +++ b/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs b/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs index 42cb8659b9..61489990a6 100644 --- a/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs +++ b/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-638-stylo-cannot-find-T-in-this-scope.rs b/tests/expectations/tests/issue-638-stylo-cannot-find-T-in-this-scope.rs index 0d846f4d2c..8c3ad474fd 100644 --- a/tests/expectations/tests/issue-638-stylo-cannot-find-T-in-this-scope.rs +++ b/tests/expectations/tests/issue-638-stylo-cannot-find-T-in-this-scope.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-639-typedef-anon-field.rs b/tests/expectations/tests/issue-639-typedef-anon-field.rs index 3494e1f129..4147c1d228 100644 --- a/tests/expectations/tests/issue-639-typedef-anon-field.rs +++ b/tests/expectations/tests/issue-639-typedef-anon-field.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-643-inner-struct.rs b/tests/expectations/tests/issue-643-inner-struct.rs index 3b8d97b722..35a5e52ca3 100644 --- a/tests/expectations/tests/issue-643-inner-struct.rs +++ b/tests/expectations/tests/issue-643-inner-struct.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-645-cannot-find-type-T-in-this-scope.rs b/tests/expectations/tests/issue-645-cannot-find-type-T-in-this-scope.rs index e34d0425d9..176fae6438 100644 --- a/tests/expectations/tests/issue-645-cannot-find-type-T-in-this-scope.rs +++ b/tests/expectations/tests/issue-645-cannot-find-type-T-in-this-scope.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-648-derive-debug-with-padding.rs b/tests/expectations/tests/issue-648-derive-debug-with-padding.rs index cb40465029..e6d529f0c0 100644 --- a/tests/expectations/tests/issue-648-derive-debug-with-padding.rs +++ b/tests/expectations/tests/issue-648-derive-debug-with-padding.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-654-struct-fn-collision.rs b/tests/expectations/tests/issue-654-struct-fn-collision.rs index 1f34e8ae8d..65d3a51636 100644 --- a/tests/expectations/tests/issue-654-struct-fn-collision.rs +++ b/tests/expectations/tests/issue-654-struct-fn-collision.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-662-cannot-find-T-in-this-scope.rs b/tests/expectations/tests/issue-662-cannot-find-T-in-this-scope.rs index 19e4ce3cd7..d12c871525 100644 --- a/tests/expectations/tests/issue-662-cannot-find-T-in-this-scope.rs +++ b/tests/expectations/tests/issue-662-cannot-find-T-in-this-scope.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-662-part-2.rs b/tests/expectations/tests/issue-662-part-2.rs index 7b79057838..d08e6fb810 100644 --- a/tests/expectations/tests/issue-662-part-2.rs +++ b/tests/expectations/tests/issue-662-part-2.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-674-1.rs b/tests/expectations/tests/issue-674-1.rs index cb76b7764c..5ad6694730 100644 --- a/tests/expectations/tests/issue-674-1.rs +++ b/tests/expectations/tests/issue-674-1.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-674-2.rs b/tests/expectations/tests/issue-674-2.rs index a6a37d9bfe..4ccc4504c3 100644 --- a/tests/expectations/tests/issue-674-2.rs +++ b/tests/expectations/tests/issue-674-2.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-674-3.rs b/tests/expectations/tests/issue-674-3.rs index c4b25649b4..99c96b969b 100644 --- a/tests/expectations/tests/issue-674-3.rs +++ b/tests/expectations/tests/issue-674-3.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-677-nested-ns-specifier.rs b/tests/expectations/tests/issue-677-nested-ns-specifier.rs index 2f1b904f0e..800f0dc84b 100644 --- a/tests/expectations/tests/issue-677-nested-ns-specifier.rs +++ b/tests/expectations/tests/issue-677-nested-ns-specifier.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-691-template-parameter-virtual.rs b/tests/expectations/tests/issue-691-template-parameter-virtual.rs index afe5b75d29..3d20728211 100644 --- a/tests/expectations/tests/issue-691-template-parameter-virtual.rs +++ b/tests/expectations/tests/issue-691-template-parameter-virtual.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs b/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs index 48298a6f5d..783ea26752 100644 --- a/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs +++ b/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-801-opaque-sloppiness.rs b/tests/expectations/tests/issue-801-opaque-sloppiness.rs index f6356c497d..6fe3cc681f 100644 --- a/tests/expectations/tests/issue-801-opaque-sloppiness.rs +++ b/tests/expectations/tests/issue-801-opaque-sloppiness.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs b/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs index 824fccba00..bad51ff43b 100644 --- a/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs +++ b/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-816.rs b/tests/expectations/tests/issue-816.rs index 82b1d676c8..64b58abb68 100644 --- a/tests/expectations/tests/issue-816.rs +++ b/tests/expectations/tests/issue-816.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-820-unused-template-param-in-alias.rs b/tests/expectations/tests/issue-820-unused-template-param-in-alias.rs index 3abfb89dba..cfe0078455 100644 --- a/tests/expectations/tests/issue-820-unused-template-param-in-alias.rs +++ b/tests/expectations/tests/issue-820-unused-template-param-in-alias.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-826-generating-methods-when-asked-not-to.rs b/tests/expectations/tests/issue-826-generating-methods-when-asked-not-to.rs index f14057bfe6..f5ba025a25 100644 --- a/tests/expectations/tests/issue-826-generating-methods-when-asked-not-to.rs +++ b/tests/expectations/tests/issue-826-generating-methods-when-asked-not-to.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-833-1.rs b/tests/expectations/tests/issue-833-1.rs index da5ae240d6..f91266f634 100644 --- a/tests/expectations/tests/issue-833-1.rs +++ b/tests/expectations/tests/issue-833-1.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-833-2.rs b/tests/expectations/tests/issue-833-2.rs index 42630af227..1dfe1abda6 100644 --- a/tests/expectations/tests/issue-833-2.rs +++ b/tests/expectations/tests/issue-833-2.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-833.rs b/tests/expectations/tests/issue-833.rs index e2ee6ad35b..a092fb7156 100644 --- a/tests/expectations/tests/issue-833.rs +++ b/tests/expectations/tests/issue-833.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-834.rs b/tests/expectations/tests/issue-834.rs index 03e0d44ecc..465341fb71 100644 --- a/tests/expectations/tests/issue-834.rs +++ b/tests/expectations/tests/issue-834.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-848-replacement-system-include.rs b/tests/expectations/tests/issue-848-replacement-system-include.rs index 6e20983f74..af91e1ec71 100644 --- a/tests/expectations/tests/issue-848-replacement-system-include.rs +++ b/tests/expectations/tests/issue-848-replacement-system-include.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-888-enum-var-decl-jump.rs b/tests/expectations/tests/issue-888-enum-var-decl-jump.rs index 35085a8da5..0e8bb8e0f1 100644 --- a/tests/expectations/tests/issue-888-enum-var-decl-jump.rs +++ b/tests/expectations/tests/issue-888-enum-var-decl-jump.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-944-derive-copy-and-blacklisting.rs b/tests/expectations/tests/issue-944-derive-copy-and-blacklisting.rs index 985ad446b9..bcb5550fe8 100644 --- a/tests/expectations/tests/issue-944-derive-copy-and-blacklisting.rs +++ b/tests/expectations/tests/issue-944-derive-copy-and-blacklisting.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue-946.rs b/tests/expectations/tests/issue-946.rs index 48d5e2d0be..897700b325 100644 --- a/tests/expectations/tests/issue-946.rs +++ b/tests/expectations/tests/issue-946.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue_311.rs b/tests/expectations/tests/issue_311.rs index 67ab8e5249..49e30d8407 100644 --- a/tests/expectations/tests/issue_311.rs +++ b/tests/expectations/tests/issue_311.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/issue_315.rs b/tests/expectations/tests/issue_315.rs index 1eb301197f..71ae1f2746 100644 --- a/tests/expectations/tests/issue_315.rs +++ b/tests/expectations/tests/issue_315.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/jsval_layout_opaque.rs b/tests/expectations/tests/jsval_layout_opaque.rs index bab7c1bda8..233aff7b41 100644 --- a/tests/expectations/tests/jsval_layout_opaque.rs +++ b/tests/expectations/tests/jsval_layout_opaque.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/jsval_layout_opaque_1_0.rs b/tests/expectations/tests/jsval_layout_opaque_1_0.rs index 44acfbc4fe..f2433a4619 100644 --- a/tests/expectations/tests/jsval_layout_opaque_1_0.rs +++ b/tests/expectations/tests/jsval_layout_opaque_1_0.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/keywords.rs b/tests/expectations/tests/keywords.rs index 105b6cdce1..129351912e 100644 --- a/tests/expectations/tests/keywords.rs +++ b/tests/expectations/tests/keywords.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/layout.rs b/tests/expectations/tests/layout.rs index 3053122d12..cf42d30277 100644 --- a/tests/expectations/tests/layout.rs +++ b/tests/expectations/tests/layout.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/layout_align.rs b/tests/expectations/tests/layout_align.rs index 2ff900d519..316eb7fb73 100644 --- a/tests/expectations/tests/layout_align.rs +++ b/tests/expectations/tests/layout_align.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/layout_arp.rs b/tests/expectations/tests/layout_arp.rs index b8987d9851..d6642d7e2b 100644 --- a/tests/expectations/tests/layout_arp.rs +++ b/tests/expectations/tests/layout_arp.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/layout_array.rs b/tests/expectations/tests/layout_array.rs index 3e0142d0ff..3ca20b01d5 100644 --- a/tests/expectations/tests/layout_array.rs +++ b/tests/expectations/tests/layout_array.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/layout_array_too_long.rs b/tests/expectations/tests/layout_array_too_long.rs index 5d84f05394..dbfd80d959 100644 --- a/tests/expectations/tests/layout_array_too_long.rs +++ b/tests/expectations/tests/layout_array_too_long.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/layout_cmdline_token.rs b/tests/expectations/tests/layout_cmdline_token.rs index 610a3914ac..38a4622b2b 100644 --- a/tests/expectations/tests/layout_cmdline_token.rs +++ b/tests/expectations/tests/layout_cmdline_token.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/layout_eth_conf.rs b/tests/expectations/tests/layout_eth_conf.rs index d10e7740c0..78e91c591a 100644 --- a/tests/expectations/tests/layout_eth_conf.rs +++ b/tests/expectations/tests/layout_eth_conf.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/layout_eth_conf_1_0.rs b/tests/expectations/tests/layout_eth_conf_1_0.rs index 9e6d18b28d..50653c1e09 100644 --- a/tests/expectations/tests/layout_eth_conf_1_0.rs +++ b/tests/expectations/tests/layout_eth_conf_1_0.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/layout_kni_mbuf.rs b/tests/expectations/tests/layout_kni_mbuf.rs index 19e82571a0..fce9dbac10 100644 --- a/tests/expectations/tests/layout_kni_mbuf.rs +++ b/tests/expectations/tests/layout_kni_mbuf.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/layout_large_align_field.rs b/tests/expectations/tests/layout_large_align_field.rs index 55a05fe5df..cbfb286c2b 100644 --- a/tests/expectations/tests/layout_large_align_field.rs +++ b/tests/expectations/tests/layout_large_align_field.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/layout_mbuf.rs b/tests/expectations/tests/layout_mbuf.rs index d0149b1097..2048f33544 100644 --- a/tests/expectations/tests/layout_mbuf.rs +++ b/tests/expectations/tests/layout_mbuf.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/layout_mbuf_1_0.rs b/tests/expectations/tests/layout_mbuf_1_0.rs index cf05efd315..1475cc2141 100644 --- a/tests/expectations/tests/layout_mbuf_1_0.rs +++ b/tests/expectations/tests/layout_mbuf_1_0.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-3.8/abi_variadic_function.rs b/tests/expectations/tests/libclang-3.8/abi_variadic_function.rs index ef1769ddb7..415c8cfda8 100644 --- a/tests/expectations/tests/libclang-3.8/abi_variadic_function.rs +++ b/tests/expectations/tests/libclang-3.8/abi_variadic_function.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-3.8/auto.rs b/tests/expectations/tests/libclang-3.8/auto.rs index b5958a04a3..fad1722cec 100644 --- a/tests/expectations/tests/libclang-3.8/auto.rs +++ b/tests/expectations/tests/libclang-3.8/auto.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-3.8/call-conv-field.rs b/tests/expectations/tests/libclang-3.8/call-conv-field.rs index 4324f9b7ae..2a905a9528 100644 --- a/tests/expectations/tests/libclang-3.8/call-conv-field.rs +++ b/tests/expectations/tests/libclang-3.8/call-conv-field.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-3.8/const_bool.rs b/tests/expectations/tests/libclang-3.8/const_bool.rs index c20c554661..838d9a91b0 100644 --- a/tests/expectations/tests/libclang-3.8/const_bool.rs +++ b/tests/expectations/tests/libclang-3.8/const_bool.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-3.8/constant-evaluate.rs b/tests/expectations/tests/libclang-3.8/constant-evaluate.rs index e988b40f44..a59066c844 100644 --- a/tests/expectations/tests/libclang-3.8/constant-evaluate.rs +++ b/tests/expectations/tests/libclang-3.8/constant-evaluate.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-3.8/error-E0600-cannot-apply-unary-negation-to-u32.rs b/tests/expectations/tests/libclang-3.8/error-E0600-cannot-apply-unary-negation-to-u32.rs index 04833a6581..3fa853eebe 100644 --- a/tests/expectations/tests/libclang-3.8/error-E0600-cannot-apply-unary-negation-to-u32.rs +++ b/tests/expectations/tests/libclang-3.8/error-E0600-cannot-apply-unary-negation-to-u32.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-3.8/issue-769-bad-instantiation-test.rs b/tests/expectations/tests/libclang-3.8/issue-769-bad-instantiation-test.rs index 48a0785024..c084de95d2 100644 --- a/tests/expectations/tests/libclang-3.8/issue-769-bad-instantiation-test.rs +++ b/tests/expectations/tests/libclang-3.8/issue-769-bad-instantiation-test.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-3.8/mangling-win32.rs b/tests/expectations/tests/libclang-3.8/mangling-win32.rs index f219089f12..4c11ba9eef 100644 --- a/tests/expectations/tests/libclang-3.8/mangling-win32.rs +++ b/tests/expectations/tests/libclang-3.8/mangling-win32.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-3.8/objc_inheritance.rs b/tests/expectations/tests/libclang-3.8/objc_inheritance.rs index 5443dd430f..cd2b085dc3 100644 --- a/tests/expectations/tests/libclang-3.8/objc_inheritance.rs +++ b/tests/expectations/tests/libclang-3.8/objc_inheritance.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-3.8/objc_template.rs b/tests/expectations/tests/libclang-3.8/objc_template.rs index 22a6e17e11..9c5a5b75a2 100644 --- a/tests/expectations/tests/libclang-3.8/objc_template.rs +++ b/tests/expectations/tests/libclang-3.8/objc_template.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-3.8/partial-specialization-and-inheritance.rs b/tests/expectations/tests/libclang-3.8/partial-specialization-and-inheritance.rs index 20b2f0242d..b68610e1d9 100644 --- a/tests/expectations/tests/libclang-3.8/partial-specialization-and-inheritance.rs +++ b/tests/expectations/tests/libclang-3.8/partial-specialization-and-inheritance.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-3.8/type_alias_template_specialized.rs b/tests/expectations/tests/libclang-3.8/type_alias_template_specialized.rs index 6c171aeccf..67e1c5aeb3 100644 --- a/tests/expectations/tests/libclang-3.8/type_alias_template_specialized.rs +++ b/tests/expectations/tests/libclang-3.8/type_alias_template_specialized.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-3.9/abi_variadic_function.rs b/tests/expectations/tests/libclang-3.9/abi_variadic_function.rs index 89cf9a64e9..6aeb16f2a7 100644 --- a/tests/expectations/tests/libclang-3.9/abi_variadic_function.rs +++ b/tests/expectations/tests/libclang-3.9/abi_variadic_function.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-3.9/auto.rs b/tests/expectations/tests/libclang-3.9/auto.rs index ab0c7dc029..0b20b39eb6 100644 --- a/tests/expectations/tests/libclang-3.9/auto.rs +++ b/tests/expectations/tests/libclang-3.9/auto.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-3.9/call-conv-field.rs b/tests/expectations/tests/libclang-3.9/call-conv-field.rs index ea7c0e40f5..f134bd8a46 100644 --- a/tests/expectations/tests/libclang-3.9/call-conv-field.rs +++ b/tests/expectations/tests/libclang-3.9/call-conv-field.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-3.9/const_bool.rs b/tests/expectations/tests/libclang-3.9/const_bool.rs index 5be7850369..97e1d8dda4 100644 --- a/tests/expectations/tests/libclang-3.9/const_bool.rs +++ b/tests/expectations/tests/libclang-3.9/const_bool.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-3.9/constant-evaluate.rs b/tests/expectations/tests/libclang-3.9/constant-evaluate.rs index 87dafd63a4..5f61f88ab6 100644 --- a/tests/expectations/tests/libclang-3.9/constant-evaluate.rs +++ b/tests/expectations/tests/libclang-3.9/constant-evaluate.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-3.9/error-E0600-cannot-apply-unary-negation-to-u32.rs b/tests/expectations/tests/libclang-3.9/error-E0600-cannot-apply-unary-negation-to-u32.rs index 04833a6581..3fa853eebe 100644 --- a/tests/expectations/tests/libclang-3.9/error-E0600-cannot-apply-unary-negation-to-u32.rs +++ b/tests/expectations/tests/libclang-3.9/error-E0600-cannot-apply-unary-negation-to-u32.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-3.9/issue-769-bad-instantiation-test.rs b/tests/expectations/tests/libclang-3.9/issue-769-bad-instantiation-test.rs index 48a0785024..c084de95d2 100644 --- a/tests/expectations/tests/libclang-3.9/issue-769-bad-instantiation-test.rs +++ b/tests/expectations/tests/libclang-3.9/issue-769-bad-instantiation-test.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-3.9/mangling-win32.rs b/tests/expectations/tests/libclang-3.9/mangling-win32.rs index 24cd4eb0df..0aee327414 100644 --- a/tests/expectations/tests/libclang-3.9/mangling-win32.rs +++ b/tests/expectations/tests/libclang-3.9/mangling-win32.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-3.9/objc_inheritance.rs b/tests/expectations/tests/libclang-3.9/objc_inheritance.rs index 5443dd430f..cd2b085dc3 100644 --- a/tests/expectations/tests/libclang-3.9/objc_inheritance.rs +++ b/tests/expectations/tests/libclang-3.9/objc_inheritance.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-3.9/objc_template.rs b/tests/expectations/tests/libclang-3.9/objc_template.rs index 22a6e17e11..9c5a5b75a2 100644 --- a/tests/expectations/tests/libclang-3.9/objc_template.rs +++ b/tests/expectations/tests/libclang-3.9/objc_template.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-3.9/partial-specialization-and-inheritance.rs b/tests/expectations/tests/libclang-3.9/partial-specialization-and-inheritance.rs index 06ff60599c..e62ea68172 100644 --- a/tests/expectations/tests/libclang-3.9/partial-specialization-and-inheritance.rs +++ b/tests/expectations/tests/libclang-3.9/partial-specialization-and-inheritance.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-3.9/type_alias_template_specialized.rs b/tests/expectations/tests/libclang-3.9/type_alias_template_specialized.rs index 6c171aeccf..67e1c5aeb3 100644 --- a/tests/expectations/tests/libclang-3.9/type_alias_template_specialized.rs +++ b/tests/expectations/tests/libclang-3.9/type_alias_template_specialized.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-4/abi_variadic_function.rs b/tests/expectations/tests/libclang-4/abi_variadic_function.rs index 89cf9a64e9..6aeb16f2a7 100644 --- a/tests/expectations/tests/libclang-4/abi_variadic_function.rs +++ b/tests/expectations/tests/libclang-4/abi_variadic_function.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-4/auto.rs b/tests/expectations/tests/libclang-4/auto.rs index ab0c7dc029..0b20b39eb6 100644 --- a/tests/expectations/tests/libclang-4/auto.rs +++ b/tests/expectations/tests/libclang-4/auto.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-4/call-conv-field.rs b/tests/expectations/tests/libclang-4/call-conv-field.rs index ea7c0e40f5..f134bd8a46 100644 --- a/tests/expectations/tests/libclang-4/call-conv-field.rs +++ b/tests/expectations/tests/libclang-4/call-conv-field.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-4/const_bool.rs b/tests/expectations/tests/libclang-4/const_bool.rs index 5be7850369..97e1d8dda4 100644 --- a/tests/expectations/tests/libclang-4/const_bool.rs +++ b/tests/expectations/tests/libclang-4/const_bool.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-4/constant-evaluate.rs b/tests/expectations/tests/libclang-4/constant-evaluate.rs index 07df8114df..9925e8d9d4 100644 --- a/tests/expectations/tests/libclang-4/constant-evaluate.rs +++ b/tests/expectations/tests/libclang-4/constant-evaluate.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-4/error-E0600-cannot-apply-unary-negation-to-u32.rs b/tests/expectations/tests/libclang-4/error-E0600-cannot-apply-unary-negation-to-u32.rs index ce5d0362d6..57878592d9 100644 --- a/tests/expectations/tests/libclang-4/error-E0600-cannot-apply-unary-negation-to-u32.rs +++ b/tests/expectations/tests/libclang-4/error-E0600-cannot-apply-unary-negation-to-u32.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-4/issue-769-bad-instantiation-test.rs b/tests/expectations/tests/libclang-4/issue-769-bad-instantiation-test.rs index daceec2e22..45bcb6f561 100644 --- a/tests/expectations/tests/libclang-4/issue-769-bad-instantiation-test.rs +++ b/tests/expectations/tests/libclang-4/issue-769-bad-instantiation-test.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-4/mangling-win32.rs b/tests/expectations/tests/libclang-4/mangling-win32.rs index 24cd4eb0df..0aee327414 100644 --- a/tests/expectations/tests/libclang-4/mangling-win32.rs +++ b/tests/expectations/tests/libclang-4/mangling-win32.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-4/objc_inheritance.rs b/tests/expectations/tests/libclang-4/objc_inheritance.rs index 5443dd430f..cd2b085dc3 100644 --- a/tests/expectations/tests/libclang-4/objc_inheritance.rs +++ b/tests/expectations/tests/libclang-4/objc_inheritance.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-4/objc_template.rs b/tests/expectations/tests/libclang-4/objc_template.rs index b4c117044c..eab2e36a5a 100644 --- a/tests/expectations/tests/libclang-4/objc_template.rs +++ b/tests/expectations/tests/libclang-4/objc_template.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-4/partial-specialization-and-inheritance.rs b/tests/expectations/tests/libclang-4/partial-specialization-and-inheritance.rs index 06ff60599c..e62ea68172 100644 --- a/tests/expectations/tests/libclang-4/partial-specialization-and-inheritance.rs +++ b/tests/expectations/tests/libclang-4/partial-specialization-and-inheritance.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-4/type_alias_template_specialized.rs b/tests/expectations/tests/libclang-4/type_alias_template_specialized.rs index 89e37fe81e..38f3bfb1c0 100644 --- a/tests/expectations/tests/libclang-4/type_alias_template_specialized.rs +++ b/tests/expectations/tests/libclang-4/type_alias_template_specialized.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-5/abi_variadic_function.rs b/tests/expectations/tests/libclang-5/abi_variadic_function.rs index 89cf9a64e9..6aeb16f2a7 100644 --- a/tests/expectations/tests/libclang-5/abi_variadic_function.rs +++ b/tests/expectations/tests/libclang-5/abi_variadic_function.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-5/auto.rs b/tests/expectations/tests/libclang-5/auto.rs index ab0c7dc029..0b20b39eb6 100644 --- a/tests/expectations/tests/libclang-5/auto.rs +++ b/tests/expectations/tests/libclang-5/auto.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-5/call-conv-field.rs b/tests/expectations/tests/libclang-5/call-conv-field.rs index ea7c0e40f5..f134bd8a46 100644 --- a/tests/expectations/tests/libclang-5/call-conv-field.rs +++ b/tests/expectations/tests/libclang-5/call-conv-field.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-5/const_bool.rs b/tests/expectations/tests/libclang-5/const_bool.rs index 5be7850369..97e1d8dda4 100644 --- a/tests/expectations/tests/libclang-5/const_bool.rs +++ b/tests/expectations/tests/libclang-5/const_bool.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-5/constant-evaluate.rs b/tests/expectations/tests/libclang-5/constant-evaluate.rs index 07df8114df..9925e8d9d4 100644 --- a/tests/expectations/tests/libclang-5/constant-evaluate.rs +++ b/tests/expectations/tests/libclang-5/constant-evaluate.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-5/error-E0600-cannot-apply-unary-negation-to-u32.rs b/tests/expectations/tests/libclang-5/error-E0600-cannot-apply-unary-negation-to-u32.rs index ce5d0362d6..57878592d9 100644 --- a/tests/expectations/tests/libclang-5/error-E0600-cannot-apply-unary-negation-to-u32.rs +++ b/tests/expectations/tests/libclang-5/error-E0600-cannot-apply-unary-negation-to-u32.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-5/issue-769-bad-instantiation-test.rs b/tests/expectations/tests/libclang-5/issue-769-bad-instantiation-test.rs index daceec2e22..45bcb6f561 100644 --- a/tests/expectations/tests/libclang-5/issue-769-bad-instantiation-test.rs +++ b/tests/expectations/tests/libclang-5/issue-769-bad-instantiation-test.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-5/mangling-win32.rs b/tests/expectations/tests/libclang-5/mangling-win32.rs index 24cd4eb0df..0aee327414 100644 --- a/tests/expectations/tests/libclang-5/mangling-win32.rs +++ b/tests/expectations/tests/libclang-5/mangling-win32.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-5/objc_inheritance.rs b/tests/expectations/tests/libclang-5/objc_inheritance.rs index 5443dd430f..cd2b085dc3 100644 --- a/tests/expectations/tests/libclang-5/objc_inheritance.rs +++ b/tests/expectations/tests/libclang-5/objc_inheritance.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-5/objc_template.rs b/tests/expectations/tests/libclang-5/objc_template.rs index b4c117044c..eab2e36a5a 100644 --- a/tests/expectations/tests/libclang-5/objc_template.rs +++ b/tests/expectations/tests/libclang-5/objc_template.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-5/partial-specialization-and-inheritance.rs b/tests/expectations/tests/libclang-5/partial-specialization-and-inheritance.rs index 06ff60599c..e62ea68172 100644 --- a/tests/expectations/tests/libclang-5/partial-specialization-and-inheritance.rs +++ b/tests/expectations/tests/libclang-5/partial-specialization-and-inheritance.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-5/type_alias_template_specialized.rs b/tests/expectations/tests/libclang-5/type_alias_template_specialized.rs index 89e37fe81e..38f3bfb1c0 100644 --- a/tests/expectations/tests/libclang-5/type_alias_template_specialized.rs +++ b/tests/expectations/tests/libclang-5/type_alias_template_specialized.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-9/abi_variadic_function.rs b/tests/expectations/tests/libclang-9/abi_variadic_function.rs index 89cf9a64e9..6aeb16f2a7 100644 --- a/tests/expectations/tests/libclang-9/abi_variadic_function.rs +++ b/tests/expectations/tests/libclang-9/abi_variadic_function.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-9/auto.rs b/tests/expectations/tests/libclang-9/auto.rs index ab0c7dc029..0b20b39eb6 100644 --- a/tests/expectations/tests/libclang-9/auto.rs +++ b/tests/expectations/tests/libclang-9/auto.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-9/call-conv-field.rs b/tests/expectations/tests/libclang-9/call-conv-field.rs index ea7c0e40f5..f134bd8a46 100644 --- a/tests/expectations/tests/libclang-9/call-conv-field.rs +++ b/tests/expectations/tests/libclang-9/call-conv-field.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-9/class.rs b/tests/expectations/tests/libclang-9/class.rs index 49e080d0aa..baa851b964 100644 --- a/tests/expectations/tests/libclang-9/class.rs +++ b/tests/expectations/tests/libclang-9/class.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-9/class_1_0.rs b/tests/expectations/tests/libclang-9/class_1_0.rs index b86534a7db..d527dfd75f 100644 --- a/tests/expectations/tests/libclang-9/class_1_0.rs +++ b/tests/expectations/tests/libclang-9/class_1_0.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-9/const_bool.rs b/tests/expectations/tests/libclang-9/const_bool.rs index 5be7850369..97e1d8dda4 100644 --- a/tests/expectations/tests/libclang-9/const_bool.rs +++ b/tests/expectations/tests/libclang-9/const_bool.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-9/constant-evaluate.rs b/tests/expectations/tests/libclang-9/constant-evaluate.rs index 07df8114df..9925e8d9d4 100644 --- a/tests/expectations/tests/libclang-9/constant-evaluate.rs +++ b/tests/expectations/tests/libclang-9/constant-evaluate.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs b/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs index 336cda1c03..32607b375f 100644 --- a/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs +++ b/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-9/error-E0600-cannot-apply-unary-negation-to-u32.rs b/tests/expectations/tests/libclang-9/error-E0600-cannot-apply-unary-negation-to-u32.rs index ce5d0362d6..57878592d9 100644 --- a/tests/expectations/tests/libclang-9/error-E0600-cannot-apply-unary-negation-to-u32.rs +++ b/tests/expectations/tests/libclang-9/error-E0600-cannot-apply-unary-negation-to-u32.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-9/incomplete-array-padding.rs b/tests/expectations/tests/libclang-9/incomplete-array-padding.rs index f5661ed576..57f15a2263 100644 --- a/tests/expectations/tests/libclang-9/incomplete-array-padding.rs +++ b/tests/expectations/tests/libclang-9/incomplete-array-padding.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs b/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs index 7a3d37f6cd..d8f2ac6ee8 100644 --- a/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs +++ b/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-9/issue-769-bad-instantiation-test.rs b/tests/expectations/tests/libclang-9/issue-769-bad-instantiation-test.rs index daceec2e22..45bcb6f561 100644 --- a/tests/expectations/tests/libclang-9/issue-769-bad-instantiation-test.rs +++ b/tests/expectations/tests/libclang-9/issue-769-bad-instantiation-test.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-9/layout_align.rs b/tests/expectations/tests/libclang-9/layout_align.rs index 93c4ecac1f..228177e10f 100644 --- a/tests/expectations/tests/libclang-9/layout_align.rs +++ b/tests/expectations/tests/libclang-9/layout_align.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-9/mangling-win32.rs b/tests/expectations/tests/libclang-9/mangling-win32.rs index 24cd4eb0df..0aee327414 100644 --- a/tests/expectations/tests/libclang-9/mangling-win32.rs +++ b/tests/expectations/tests/libclang-9/mangling-win32.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-9/objc_inheritance.rs b/tests/expectations/tests/libclang-9/objc_inheritance.rs index 5443dd430f..cd2b085dc3 100644 --- a/tests/expectations/tests/libclang-9/objc_inheritance.rs +++ b/tests/expectations/tests/libclang-9/objc_inheritance.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-9/objc_template.rs b/tests/expectations/tests/libclang-9/objc_template.rs index 4bf234d74a..09cc739c1c 100644 --- a/tests/expectations/tests/libclang-9/objc_template.rs +++ b/tests/expectations/tests/libclang-9/objc_template.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-9/partial-specialization-and-inheritance.rs b/tests/expectations/tests/libclang-9/partial-specialization-and-inheritance.rs index 06ff60599c..e62ea68172 100644 --- a/tests/expectations/tests/libclang-9/partial-specialization-and-inheritance.rs +++ b/tests/expectations/tests/libclang-9/partial-specialization-and-inheritance.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-9/type_alias_template_specialized.rs b/tests/expectations/tests/libclang-9/type_alias_template_specialized.rs index 89e37fe81e..38f3bfb1c0 100644 --- a/tests/expectations/tests/libclang-9/type_alias_template_specialized.rs +++ b/tests/expectations/tests/libclang-9/type_alias_template_specialized.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/libclang-9/zero-sized-array.rs b/tests/expectations/tests/libclang-9/zero-sized-array.rs index adb3210760..6514b930c7 100644 --- a/tests/expectations/tests/libclang-9/zero-sized-array.rs +++ b/tests/expectations/tests/libclang-9/zero-sized-array.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/long_double.rs b/tests/expectations/tests/long_double.rs index 632eeb5a69..dbd4248ee5 100644 --- a/tests/expectations/tests/long_double.rs +++ b/tests/expectations/tests/long_double.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/macro-expr-basic.rs b/tests/expectations/tests/macro-expr-basic.rs index 3f7b809935..4eeb310c8f 100644 --- a/tests/expectations/tests/macro-expr-basic.rs +++ b/tests/expectations/tests/macro-expr-basic.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/macro-expr-uncommon-token.rs b/tests/expectations/tests/macro-expr-uncommon-token.rs index 8c16a0d852..b2f2ebd2e2 100644 --- a/tests/expectations/tests/macro-expr-uncommon-token.rs +++ b/tests/expectations/tests/macro-expr-uncommon-token.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/macro-redef.rs b/tests/expectations/tests/macro-redef.rs index 3133bc0e0c..ff5654f47b 100644 --- a/tests/expectations/tests/macro-redef.rs +++ b/tests/expectations/tests/macro-redef.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/macro_const.rs b/tests/expectations/tests/macro_const.rs index 851dd54e62..e135661121 100644 --- a/tests/expectations/tests/macro_const.rs +++ b/tests/expectations/tests/macro_const.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/maddness-is-avoidable.rs b/tests/expectations/tests/maddness-is-avoidable.rs index 0e0ae290f1..12157f4b9d 100644 --- a/tests/expectations/tests/maddness-is-avoidable.rs +++ b/tests/expectations/tests/maddness-is-avoidable.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/mangling-ios.rs b/tests/expectations/tests/mangling-ios.rs index 90dc8d46f2..8a4ff6578e 100644 --- a/tests/expectations/tests/mangling-ios.rs +++ b/tests/expectations/tests/mangling-ios.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/mangling-linux32.rs b/tests/expectations/tests/mangling-linux32.rs index faa9a2f8d5..bddd761794 100644 --- a/tests/expectations/tests/mangling-linux32.rs +++ b/tests/expectations/tests/mangling-linux32.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/mangling-linux64.rs b/tests/expectations/tests/mangling-linux64.rs index faa9a2f8d5..bddd761794 100644 --- a/tests/expectations/tests/mangling-linux64.rs +++ b/tests/expectations/tests/mangling-linux64.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/mangling-macos.rs b/tests/expectations/tests/mangling-macos.rs index cc1ba069da..9af36259fd 100644 --- a/tests/expectations/tests/mangling-macos.rs +++ b/tests/expectations/tests/mangling-macos.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/mangling-win64.rs b/tests/expectations/tests/mangling-win64.rs index d8c55e1c4f..cb5f7103ad 100644 --- a/tests/expectations/tests/mangling-win64.rs +++ b/tests/expectations/tests/mangling-win64.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/method-mangling.rs b/tests/expectations/tests/method-mangling.rs index 7f72225adc..e4627ac8a7 100644 --- a/tests/expectations/tests/method-mangling.rs +++ b/tests/expectations/tests/method-mangling.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/module-whitelisted.rs b/tests/expectations/tests/module-whitelisted.rs index 3771472d21..30cdb3580b 100644 --- a/tests/expectations/tests/module-whitelisted.rs +++ b/tests/expectations/tests/module-whitelisted.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/msvc-no-usr.rs b/tests/expectations/tests/msvc-no-usr.rs index ad0f52c69f..ea5a90b871 100644 --- a/tests/expectations/tests/msvc-no-usr.rs +++ b/tests/expectations/tests/msvc-no-usr.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/multiple-inherit-empty-correct-layout.rs b/tests/expectations/tests/multiple-inherit-empty-correct-layout.rs index d9c12e7b8f..55b3d1e31b 100644 --- a/tests/expectations/tests/multiple-inherit-empty-correct-layout.rs +++ b/tests/expectations/tests/multiple-inherit-empty-correct-layout.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/mutable.rs b/tests/expectations/tests/mutable.rs index bfd939d3b9..9f5865fccc 100644 --- a/tests/expectations/tests/mutable.rs +++ b/tests/expectations/tests/mutable.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/namespace.rs b/tests/expectations/tests/namespace.rs index 7bb148f731..d5d10e2945 100644 --- a/tests/expectations/tests/namespace.rs +++ b/tests/expectations/tests/namespace.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/nested.rs b/tests/expectations/tests/nested.rs index fdca4524a2..92cd6605b4 100644 --- a/tests/expectations/tests/nested.rs +++ b/tests/expectations/tests/nested.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/nested_vtable.rs b/tests/expectations/tests/nested_vtable.rs index e11496e2db..8ea99846d8 100644 --- a/tests/expectations/tests/nested_vtable.rs +++ b/tests/expectations/tests/nested_vtable.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/nested_within_namespace.rs b/tests/expectations/tests/nested_within_namespace.rs index e329930532..86b9b8c68b 100644 --- a/tests/expectations/tests/nested_within_namespace.rs +++ b/tests/expectations/tests/nested_within_namespace.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/newtype-enum.rs b/tests/expectations/tests/newtype-enum.rs index 6653aea7c5..a7b811081d 100644 --- a/tests/expectations/tests/newtype-enum.rs +++ b/tests/expectations/tests/newtype-enum.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/no-comments.rs b/tests/expectations/tests/no-comments.rs index f78bae9921..7a9d0d82b5 100644 --- a/tests/expectations/tests/no-comments.rs +++ b/tests/expectations/tests/no-comments.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/no-derive-debug.rs b/tests/expectations/tests/no-derive-debug.rs index f5e724d088..0ddc5e2355 100644 --- a/tests/expectations/tests/no-derive-debug.rs +++ b/tests/expectations/tests/no-derive-debug.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/no-derive-default.rs b/tests/expectations/tests/no-derive-default.rs index cbf46c7438..995b1320e3 100644 --- a/tests/expectations/tests/no-derive-default.rs +++ b/tests/expectations/tests/no-derive-default.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/no-hash-opaque.rs b/tests/expectations/tests/no-hash-opaque.rs index 427a3d3424..49ff4daad7 100644 --- a/tests/expectations/tests/no-hash-opaque.rs +++ b/tests/expectations/tests/no-hash-opaque.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/no-hash-whitelisted.rs b/tests/expectations/tests/no-hash-whitelisted.rs index bcb38b5c51..1cd7f672b6 100644 --- a/tests/expectations/tests/no-hash-whitelisted.rs +++ b/tests/expectations/tests/no-hash-whitelisted.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/no-partialeq-opaque.rs b/tests/expectations/tests/no-partialeq-opaque.rs index 5bf2d12180..423799a6b9 100644 --- a/tests/expectations/tests/no-partialeq-opaque.rs +++ b/tests/expectations/tests/no-partialeq-opaque.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/no-partialeq-whitelisted.rs b/tests/expectations/tests/no-partialeq-whitelisted.rs index 17fec747fb..cd3ed3b935 100644 --- a/tests/expectations/tests/no-partialeq-whitelisted.rs +++ b/tests/expectations/tests/no-partialeq-whitelisted.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/no-recursive-whitelisting.rs b/tests/expectations/tests/no-recursive-whitelisting.rs index e7e71efcc7..047b22ef9d 100644 --- a/tests/expectations/tests/no-recursive-whitelisting.rs +++ b/tests/expectations/tests/no-recursive-whitelisting.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/no-std.rs b/tests/expectations/tests/no-std.rs index e884cfb07b..ea16dc4454 100644 --- a/tests/expectations/tests/no-std.rs +++ b/tests/expectations/tests/no-std.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/no_copy.rs b/tests/expectations/tests/no_copy.rs index a61b457ed5..daccf757ec 100644 --- a/tests/expectations/tests/no_copy.rs +++ b/tests/expectations/tests/no_copy.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/no_copy_opaque.rs b/tests/expectations/tests/no_copy_opaque.rs index 6659a95a99..7fc3529f6e 100644 --- a/tests/expectations/tests/no_copy_opaque.rs +++ b/tests/expectations/tests/no_copy_opaque.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/no_copy_whitelisted.rs b/tests/expectations/tests/no_copy_whitelisted.rs index 74fda3b2b3..fa53bb66fe 100644 --- a/tests/expectations/tests/no_copy_whitelisted.rs +++ b/tests/expectations/tests/no_copy_whitelisted.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/non-type-params.rs b/tests/expectations/tests/non-type-params.rs index 50b3a273fa..acd7a09f3a 100644 --- a/tests/expectations/tests/non-type-params.rs +++ b/tests/expectations/tests/non-type-params.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/nsBaseHashtable.rs b/tests/expectations/tests/nsBaseHashtable.rs index e229305d80..e26190b0d8 100644 --- a/tests/expectations/tests/nsBaseHashtable.rs +++ b/tests/expectations/tests/nsBaseHashtable.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/nsStyleAutoArray.rs b/tests/expectations/tests/nsStyleAutoArray.rs index fc1b4f3287..0f3463cbdf 100644 --- a/tests/expectations/tests/nsStyleAutoArray.rs +++ b/tests/expectations/tests/nsStyleAutoArray.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/objc_category.rs b/tests/expectations/tests/objc_category.rs index 544903f588..2c39be96be 100644 --- a/tests/expectations/tests/objc_category.rs +++ b/tests/expectations/tests/objc_category.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/objc_class.rs b/tests/expectations/tests/objc_class.rs index 515d1c1601..237b86b4ec 100644 --- a/tests/expectations/tests/objc_class.rs +++ b/tests/expectations/tests/objc_class.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/objc_class_method.rs b/tests/expectations/tests/objc_class_method.rs index d6a3343c52..e0a3803c26 100644 --- a/tests/expectations/tests/objc_class_method.rs +++ b/tests/expectations/tests/objc_class_method.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/objc_interface.rs b/tests/expectations/tests/objc_interface.rs index c2671317b4..7cabf762af 100644 --- a/tests/expectations/tests/objc_interface.rs +++ b/tests/expectations/tests/objc_interface.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/objc_interface_type.rs b/tests/expectations/tests/objc_interface_type.rs index b6d166daeb..edbf412ca6 100644 --- a/tests/expectations/tests/objc_interface_type.rs +++ b/tests/expectations/tests/objc_interface_type.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/objc_method.rs b/tests/expectations/tests/objc_method.rs index 381646c4b7..13e4d9f86d 100644 --- a/tests/expectations/tests/objc_method.rs +++ b/tests/expectations/tests/objc_method.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/objc_method_clash.rs b/tests/expectations/tests/objc_method_clash.rs index 92b7930b4b..ba741f8d3a 100644 --- a/tests/expectations/tests/objc_method_clash.rs +++ b/tests/expectations/tests/objc_method_clash.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/objc_property_fnptr.rs b/tests/expectations/tests/objc_property_fnptr.rs index 1ff55e5af5..b9bcf306d8 100644 --- a/tests/expectations/tests/objc_property_fnptr.rs +++ b/tests/expectations/tests/objc_property_fnptr.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/objc_protocol.rs b/tests/expectations/tests/objc_protocol.rs index 25870f2aca..5a659b2cbb 100644 --- a/tests/expectations/tests/objc_protocol.rs +++ b/tests/expectations/tests/objc_protocol.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/objc_sel_and_id.rs b/tests/expectations/tests/objc_sel_and_id.rs index b48575633d..2a389093df 100644 --- a/tests/expectations/tests/objc_sel_and_id.rs +++ b/tests/expectations/tests/objc_sel_and_id.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/objc_whitelist.rs b/tests/expectations/tests/objc_whitelist.rs index f4c0e231e7..213f1024ba 100644 --- a/tests/expectations/tests/objc_whitelist.rs +++ b/tests/expectations/tests/objc_whitelist.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/only_bitfields.rs b/tests/expectations/tests/only_bitfields.rs index 24721b6082..fa076d87a2 100644 --- a/tests/expectations/tests/only_bitfields.rs +++ b/tests/expectations/tests/only_bitfields.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/opaque-template-inst-member-2.rs b/tests/expectations/tests/opaque-template-inst-member-2.rs index 2054397c9b..7d3e83a86a 100644 --- a/tests/expectations/tests/opaque-template-inst-member-2.rs +++ b/tests/expectations/tests/opaque-template-inst-member-2.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/opaque-template-inst-member.rs b/tests/expectations/tests/opaque-template-inst-member.rs index 66a2f049ee..ea821fcd75 100644 --- a/tests/expectations/tests/opaque-template-inst-member.rs +++ b/tests/expectations/tests/opaque-template-inst-member.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/opaque-template-instantiation-namespaced.rs b/tests/expectations/tests/opaque-template-instantiation-namespaced.rs index ff9d89444d..7f1aac8e46 100644 --- a/tests/expectations/tests/opaque-template-instantiation-namespaced.rs +++ b/tests/expectations/tests/opaque-template-instantiation-namespaced.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/opaque-template-instantiation.rs b/tests/expectations/tests/opaque-template-instantiation.rs index 67828313e2..771a5191a4 100644 --- a/tests/expectations/tests/opaque-template-instantiation.rs +++ b/tests/expectations/tests/opaque-template-instantiation.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/opaque-tracing.rs b/tests/expectations/tests/opaque-tracing.rs index 6bba62456e..98c5417138 100644 --- a/tests/expectations/tests/opaque-tracing.rs +++ b/tests/expectations/tests/opaque-tracing.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/opaque_in_struct.rs b/tests/expectations/tests/opaque_in_struct.rs index 0209e5b05f..980df3d612 100644 --- a/tests/expectations/tests/opaque_in_struct.rs +++ b/tests/expectations/tests/opaque_in_struct.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/opaque_pointer.rs b/tests/expectations/tests/opaque_pointer.rs index 1d79906d39..f5fecd46aa 100644 --- a/tests/expectations/tests/opaque_pointer.rs +++ b/tests/expectations/tests/opaque_pointer.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/opaque_typedef.rs b/tests/expectations/tests/opaque_typedef.rs index 75b79f20c6..c61a294cf6 100644 --- a/tests/expectations/tests/opaque_typedef.rs +++ b/tests/expectations/tests/opaque_typedef.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/ord-enum.rs b/tests/expectations/tests/ord-enum.rs index 579817bc2b..7988f29061 100644 --- a/tests/expectations/tests/ord-enum.rs +++ b/tests/expectations/tests/ord-enum.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/overflowed_enum.rs b/tests/expectations/tests/overflowed_enum.rs index 31b88621af..76b6f730cb 100644 --- a/tests/expectations/tests/overflowed_enum.rs +++ b/tests/expectations/tests/overflowed_enum.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/overloading.rs b/tests/expectations/tests/overloading.rs index ae16f14c0f..b43432eb0d 100644 --- a/tests/expectations/tests/overloading.rs +++ b/tests/expectations/tests/overloading.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/packed-bitfield.rs b/tests/expectations/tests/packed-bitfield.rs index 62608af85d..d64bc85b93 100644 --- a/tests/expectations/tests/packed-bitfield.rs +++ b/tests/expectations/tests/packed-bitfield.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/packed-vtable.rs b/tests/expectations/tests/packed-vtable.rs index 4bb206c68a..7f12a3618c 100644 --- a/tests/expectations/tests/packed-vtable.rs +++ b/tests/expectations/tests/packed-vtable.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/prepend-enum-constified-variant.rs b/tests/expectations/tests/prepend-enum-constified-variant.rs index d0323e12ff..5b8c878398 100644 --- a/tests/expectations/tests/prepend-enum-constified-variant.rs +++ b/tests/expectations/tests/prepend-enum-constified-variant.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/prepend_enum_name.rs b/tests/expectations/tests/prepend_enum_name.rs index 1c88438b9b..ac0a755afd 100644 --- a/tests/expectations/tests/prepend_enum_name.rs +++ b/tests/expectations/tests/prepend_enum_name.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/private.rs b/tests/expectations/tests/private.rs index 618e68c052..328f97f08f 100644 --- a/tests/expectations/tests/private.rs +++ b/tests/expectations/tests/private.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/public-dtor.rs b/tests/expectations/tests/public-dtor.rs index 55b289df6f..64a503899e 100644 --- a/tests/expectations/tests/public-dtor.rs +++ b/tests/expectations/tests/public-dtor.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/redeclaration.rs b/tests/expectations/tests/redeclaration.rs index 90dc8d46f2..8a4ff6578e 100644 --- a/tests/expectations/tests/redeclaration.rs +++ b/tests/expectations/tests/redeclaration.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/ref_argument_array.rs b/tests/expectations/tests/ref_argument_array.rs index d31c774332..0643d47b6a 100644 --- a/tests/expectations/tests/ref_argument_array.rs +++ b/tests/expectations/tests/ref_argument_array.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/reparented_replacement.rs b/tests/expectations/tests/reparented_replacement.rs index bfc65febfa..1f4fa6e1b8 100644 --- a/tests/expectations/tests/reparented_replacement.rs +++ b/tests/expectations/tests/reparented_replacement.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/replace_template_alias.rs b/tests/expectations/tests/replace_template_alias.rs index 853ec09242..0c5500eae0 100644 --- a/tests/expectations/tests/replace_template_alias.rs +++ b/tests/expectations/tests/replace_template_alias.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/replace_use.rs b/tests/expectations/tests/replace_use.rs index d8223031df..7bec94b8d2 100644 --- a/tests/expectations/tests/replace_use.rs +++ b/tests/expectations/tests/replace_use.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/replaces_double.rs b/tests/expectations/tests/replaces_double.rs index dae55a1375..7b7ec00e2b 100644 --- a/tests/expectations/tests/replaces_double.rs +++ b/tests/expectations/tests/replaces_double.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/repr-align.rs b/tests/expectations/tests/repr-align.rs index 8a0c9023ef..df2353686a 100644 --- a/tests/expectations/tests/repr-align.rs +++ b/tests/expectations/tests/repr-align.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/resolved_type_def_function.rs b/tests/expectations/tests/resolved_type_def_function.rs index bf7489207e..797976798f 100644 --- a/tests/expectations/tests/resolved_type_def_function.rs +++ b/tests/expectations/tests/resolved_type_def_function.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/same_struct_name_in_different_namespaces.rs b/tests/expectations/tests/same_struct_name_in_different_namespaces.rs index 166abffbe9..056b671b33 100644 --- a/tests/expectations/tests/same_struct_name_in_different_namespaces.rs +++ b/tests/expectations/tests/same_struct_name_in_different_namespaces.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/sentry-defined-multiple-times.rs b/tests/expectations/tests/sentry-defined-multiple-times.rs index 47773a48d3..989b4d164a 100644 --- a/tests/expectations/tests/sentry-defined-multiple-times.rs +++ b/tests/expectations/tests/sentry-defined-multiple-times.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/short-enums.rs b/tests/expectations/tests/short-enums.rs index 835a7ac83a..bb30b67e6c 100644 --- a/tests/expectations/tests/short-enums.rs +++ b/tests/expectations/tests/short-enums.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/size_t_is_usize.rs b/tests/expectations/tests/size_t_is_usize.rs index c8cd9e054f..43dda32bcf 100644 --- a/tests/expectations/tests/size_t_is_usize.rs +++ b/tests/expectations/tests/size_t_is_usize.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/size_t_template.rs b/tests/expectations/tests/size_t_template.rs index fde0174a83..6796bc9f3a 100644 --- a/tests/expectations/tests/size_t_template.rs +++ b/tests/expectations/tests/size_t_template.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/struct_containing_forward_declared_struct.rs b/tests/expectations/tests/struct_containing_forward_declared_struct.rs index bf79ee0e5f..4844186fd4 100644 --- a/tests/expectations/tests/struct_containing_forward_declared_struct.rs +++ b/tests/expectations/tests/struct_containing_forward_declared_struct.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/struct_typedef.rs b/tests/expectations/tests/struct_typedef.rs index 47505e5017..e57efc8a03 100644 --- a/tests/expectations/tests/struct_typedef.rs +++ b/tests/expectations/tests/struct_typedef.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/struct_typedef_ns.rs b/tests/expectations/tests/struct_typedef_ns.rs index 1a9757778a..43c5d38fcc 100644 --- a/tests/expectations/tests/struct_typedef_ns.rs +++ b/tests/expectations/tests/struct_typedef_ns.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/struct_with_anon_struct.rs b/tests/expectations/tests/struct_with_anon_struct.rs index 5a63100827..0f5d3dac91 100644 --- a/tests/expectations/tests/struct_with_anon_struct.rs +++ b/tests/expectations/tests/struct_with_anon_struct.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/struct_with_anon_struct_array.rs b/tests/expectations/tests/struct_with_anon_struct_array.rs index 7261647116..d5a5044832 100644 --- a/tests/expectations/tests/struct_with_anon_struct_array.rs +++ b/tests/expectations/tests/struct_with_anon_struct_array.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/struct_with_anon_struct_pointer.rs b/tests/expectations/tests/struct_with_anon_struct_pointer.rs index e5bd27fd36..04e11af6af 100644 --- a/tests/expectations/tests/struct_with_anon_struct_pointer.rs +++ b/tests/expectations/tests/struct_with_anon_struct_pointer.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/struct_with_anon_union.rs b/tests/expectations/tests/struct_with_anon_union.rs index b630c54c30..3e0da41bcb 100644 --- a/tests/expectations/tests/struct_with_anon_union.rs +++ b/tests/expectations/tests/struct_with_anon_union.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/struct_with_anon_union_1_0.rs b/tests/expectations/tests/struct_with_anon_union_1_0.rs index ed6450afc1..b02c44482a 100644 --- a/tests/expectations/tests/struct_with_anon_union_1_0.rs +++ b/tests/expectations/tests/struct_with_anon_union_1_0.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/struct_with_anon_unnamed_struct.rs b/tests/expectations/tests/struct_with_anon_unnamed_struct.rs index a304dbb9f6..30751e7d83 100644 --- a/tests/expectations/tests/struct_with_anon_unnamed_struct.rs +++ b/tests/expectations/tests/struct_with_anon_unnamed_struct.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/struct_with_anon_unnamed_union.rs b/tests/expectations/tests/struct_with_anon_unnamed_union.rs index 6e34fa2977..5aeb51c334 100644 --- a/tests/expectations/tests/struct_with_anon_unnamed_union.rs +++ b/tests/expectations/tests/struct_with_anon_unnamed_union.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs b/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs index b2b6923d80..f72abd2b03 100644 --- a/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs +++ b/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/struct_with_bitfields.rs b/tests/expectations/tests/struct_with_bitfields.rs index 0a8564696c..7d6da17cce 100644 --- a/tests/expectations/tests/struct_with_bitfields.rs +++ b/tests/expectations/tests/struct_with_bitfields.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/struct_with_derive_debug.rs b/tests/expectations/tests/struct_with_derive_debug.rs index 73c7e4ffff..0a704fe5d5 100644 --- a/tests/expectations/tests/struct_with_derive_debug.rs +++ b/tests/expectations/tests/struct_with_derive_debug.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/struct_with_large_array.rs b/tests/expectations/tests/struct_with_large_array.rs index 5321aa10a4..850ded569a 100644 --- a/tests/expectations/tests/struct_with_large_array.rs +++ b/tests/expectations/tests/struct_with_large_array.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/struct_with_nesting.rs b/tests/expectations/tests/struct_with_nesting.rs index 872c1476d0..075832359e 100644 --- a/tests/expectations/tests/struct_with_nesting.rs +++ b/tests/expectations/tests/struct_with_nesting.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/struct_with_nesting_1_0.rs b/tests/expectations/tests/struct_with_nesting_1_0.rs index 221215b23e..9f27161a0c 100644 --- a/tests/expectations/tests/struct_with_nesting_1_0.rs +++ b/tests/expectations/tests/struct_with_nesting_1_0.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/struct_with_packing.rs b/tests/expectations/tests/struct_with_packing.rs index 2012349831..14ee36fbaa 100644 --- a/tests/expectations/tests/struct_with_packing.rs +++ b/tests/expectations/tests/struct_with_packing.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/struct_with_struct.rs b/tests/expectations/tests/struct_with_struct.rs index 9ed9454f86..c605c6e2e3 100644 --- a/tests/expectations/tests/struct_with_struct.rs +++ b/tests/expectations/tests/struct_with_struct.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/struct_with_typedef_template_arg.rs b/tests/expectations/tests/struct_with_typedef_template_arg.rs index 8b617ca475..49afe55906 100644 --- a/tests/expectations/tests/struct_with_typedef_template_arg.rs +++ b/tests/expectations/tests/struct_with_typedef_template_arg.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/template-fun-ty.rs b/tests/expectations/tests/template-fun-ty.rs index 225099fa88..a7132cf04c 100644 --- a/tests/expectations/tests/template-fun-ty.rs +++ b/tests/expectations/tests/template-fun-ty.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/template-param-usage-0.rs b/tests/expectations/tests/template-param-usage-0.rs index adc8219d81..f473b74d78 100644 --- a/tests/expectations/tests/template-param-usage-0.rs +++ b/tests/expectations/tests/template-param-usage-0.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/template-param-usage-1.rs b/tests/expectations/tests/template-param-usage-1.rs index ec8ad32c30..4fc227c914 100644 --- a/tests/expectations/tests/template-param-usage-1.rs +++ b/tests/expectations/tests/template-param-usage-1.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/template-param-usage-10.rs b/tests/expectations/tests/template-param-usage-10.rs index ced48333f2..0afc595255 100644 --- a/tests/expectations/tests/template-param-usage-10.rs +++ b/tests/expectations/tests/template-param-usage-10.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/template-param-usage-11.rs b/tests/expectations/tests/template-param-usage-11.rs index d226373811..63a31e234a 100644 --- a/tests/expectations/tests/template-param-usage-11.rs +++ b/tests/expectations/tests/template-param-usage-11.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/template-param-usage-12.rs b/tests/expectations/tests/template-param-usage-12.rs index c0391fafa8..9f964b2950 100644 --- a/tests/expectations/tests/template-param-usage-12.rs +++ b/tests/expectations/tests/template-param-usage-12.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/template-param-usage-13.rs b/tests/expectations/tests/template-param-usage-13.rs index 50b40a8b0a..64e08da479 100644 --- a/tests/expectations/tests/template-param-usage-13.rs +++ b/tests/expectations/tests/template-param-usage-13.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/template-param-usage-14.rs b/tests/expectations/tests/template-param-usage-14.rs index d093fd7395..8826105f9a 100644 --- a/tests/expectations/tests/template-param-usage-14.rs +++ b/tests/expectations/tests/template-param-usage-14.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/template-param-usage-15.rs b/tests/expectations/tests/template-param-usage-15.rs index 25792de08e..45f3422930 100644 --- a/tests/expectations/tests/template-param-usage-15.rs +++ b/tests/expectations/tests/template-param-usage-15.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/template-param-usage-2.rs b/tests/expectations/tests/template-param-usage-2.rs index 1f40e41ec3..3270e1608e 100644 --- a/tests/expectations/tests/template-param-usage-2.rs +++ b/tests/expectations/tests/template-param-usage-2.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/template-param-usage-3.rs b/tests/expectations/tests/template-param-usage-3.rs index 5564af8983..9d9d8f973e 100644 --- a/tests/expectations/tests/template-param-usage-3.rs +++ b/tests/expectations/tests/template-param-usage-3.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/template-param-usage-4.rs b/tests/expectations/tests/template-param-usage-4.rs index 35af5befa8..38479aca48 100644 --- a/tests/expectations/tests/template-param-usage-4.rs +++ b/tests/expectations/tests/template-param-usage-4.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/template-param-usage-5.rs b/tests/expectations/tests/template-param-usage-5.rs index 218264fec9..6976841805 100644 --- a/tests/expectations/tests/template-param-usage-5.rs +++ b/tests/expectations/tests/template-param-usage-5.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/template-param-usage-6.rs b/tests/expectations/tests/template-param-usage-6.rs index d6f5a14a4c..3c0e515264 100644 --- a/tests/expectations/tests/template-param-usage-6.rs +++ b/tests/expectations/tests/template-param-usage-6.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/template-param-usage-7.rs b/tests/expectations/tests/template-param-usage-7.rs index 71a5de1f0c..6f7544ff0b 100644 --- a/tests/expectations/tests/template-param-usage-7.rs +++ b/tests/expectations/tests/template-param-usage-7.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/template-param-usage-8.rs b/tests/expectations/tests/template-param-usage-8.rs index 9ea1ae68bb..3a0100ffce 100644 --- a/tests/expectations/tests/template-param-usage-8.rs +++ b/tests/expectations/tests/template-param-usage-8.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/template-param-usage-9.rs b/tests/expectations/tests/template-param-usage-9.rs index 2e109f19f1..a93e4b7c0a 100644 --- a/tests/expectations/tests/template-param-usage-9.rs +++ b/tests/expectations/tests/template-param-usage-9.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/template-with-var.rs b/tests/expectations/tests/template-with-var.rs index 36d5404997..0476a256bf 100644 --- a/tests/expectations/tests/template-with-var.rs +++ b/tests/expectations/tests/template-with-var.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/template.rs b/tests/expectations/tests/template.rs index 294ee98048..67a0f8568e 100644 --- a/tests/expectations/tests/template.rs +++ b/tests/expectations/tests/template.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/template_alias.rs b/tests/expectations/tests/template_alias.rs index 38a45fd85a..3b79a3d8b5 100644 --- a/tests/expectations/tests/template_alias.rs +++ b/tests/expectations/tests/template_alias.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/template_alias_basic.rs b/tests/expectations/tests/template_alias_basic.rs index f68b9059a8..e06ffadab3 100644 --- a/tests/expectations/tests/template_alias_basic.rs +++ b/tests/expectations/tests/template_alias_basic.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/template_alias_namespace.rs b/tests/expectations/tests/template_alias_namespace.rs index 56463f2c8f..fd20bab029 100644 --- a/tests/expectations/tests/template_alias_namespace.rs +++ b/tests/expectations/tests/template_alias_namespace.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/template_fun.rs b/tests/expectations/tests/template_fun.rs index d6776794e9..131dbdf39f 100644 --- a/tests/expectations/tests/template_fun.rs +++ b/tests/expectations/tests/template_fun.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/template_partial_specification.rs b/tests/expectations/tests/template_partial_specification.rs index d6776794e9..131dbdf39f 100644 --- a/tests/expectations/tests/template_partial_specification.rs +++ b/tests/expectations/tests/template_partial_specification.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/template_typedef_transitive_param.rs b/tests/expectations/tests/template_typedef_transitive_param.rs index d40e9be324..8c9dd4d0eb 100644 --- a/tests/expectations/tests/template_typedef_transitive_param.rs +++ b/tests/expectations/tests/template_typedef_transitive_param.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/template_typedefs.rs b/tests/expectations/tests/template_typedefs.rs index 774410b32e..3883879d28 100644 --- a/tests/expectations/tests/template_typedefs.rs +++ b/tests/expectations/tests/template_typedefs.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/templateref_opaque.rs b/tests/expectations/tests/templateref_opaque.rs index b7900240cf..70cef86717 100644 --- a/tests/expectations/tests/templateref_opaque.rs +++ b/tests/expectations/tests/templateref_opaque.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/templatized-bitfield.rs b/tests/expectations/tests/templatized-bitfield.rs index 1578511627..5657a65540 100644 --- a/tests/expectations/tests/templatized-bitfield.rs +++ b/tests/expectations/tests/templatized-bitfield.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/test_multiple_header_calls_in_builder.rs b/tests/expectations/tests/test_multiple_header_calls_in_builder.rs index 79f9e4b500..c77c18342a 100644 --- a/tests/expectations/tests/test_multiple_header_calls_in_builder.rs +++ b/tests/expectations/tests/test_multiple_header_calls_in_builder.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - extern "C" { pub static mut foo: ::std::option::Option< unsafe extern "C" fn( diff --git a/tests/expectations/tests/timex.rs b/tests/expectations/tests/timex.rs index 19543173f9..dc33f7482f 100644 --- a/tests/expectations/tests/timex.rs +++ b/tests/expectations/tests/timex.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/transform-op.rs b/tests/expectations/tests/transform-op.rs index 4093b65f25..169768fc41 100644 --- a/tests/expectations/tests/transform-op.rs +++ b/tests/expectations/tests/transform-op.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/type-referenced-by-whitelisted-function.rs b/tests/expectations/tests/type-referenced-by-whitelisted-function.rs index 0ef64b8840..568f94336b 100644 --- a/tests/expectations/tests/type-referenced-by-whitelisted-function.rs +++ b/tests/expectations/tests/type-referenced-by-whitelisted-function.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/type_alias_empty.rs b/tests/expectations/tests/type_alias_empty.rs index d9a65f9a0a..cb871a33a2 100644 --- a/tests/expectations/tests/type_alias_empty.rs +++ b/tests/expectations/tests/type_alias_empty.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/type_alias_partial_template_especialization.rs b/tests/expectations/tests/type_alias_partial_template_especialization.rs index 53006d28c8..a80f46b63e 100644 --- a/tests/expectations/tests/type_alias_partial_template_especialization.rs +++ b/tests/expectations/tests/type_alias_partial_template_especialization.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/typedefd-array-as-function-arg.rs b/tests/expectations/tests/typedefd-array-as-function-arg.rs index 64b69ba7d8..330499b8ab 100644 --- a/tests/expectations/tests/typedefd-array-as-function-arg.rs +++ b/tests/expectations/tests/typedefd-array-as-function-arg.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/typeref.rs b/tests/expectations/tests/typeref.rs index 5f651dc164..6155ff33d5 100644 --- a/tests/expectations/tests/typeref.rs +++ b/tests/expectations/tests/typeref.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/typeref_1_0.rs b/tests/expectations/tests/typeref_1_0.rs index ae676b5f67..75b41960e8 100644 --- a/tests/expectations/tests/typeref_1_0.rs +++ b/tests/expectations/tests/typeref_1_0.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/underscore.rs b/tests/expectations/tests/underscore.rs index 3404a3f98b..6ef2d8a124 100644 --- a/tests/expectations/tests/underscore.rs +++ b/tests/expectations/tests/underscore.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/union-align.rs b/tests/expectations/tests/union-align.rs index 01eb78b7f9..e9c3de5206 100644 --- a/tests/expectations/tests/union-align.rs +++ b/tests/expectations/tests/union-align.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/union-in-ns.rs b/tests/expectations/tests/union-in-ns.rs index d4bbb740fa..2ff76bb8be 100644 --- a/tests/expectations/tests/union-in-ns.rs +++ b/tests/expectations/tests/union-in-ns.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/union-in-ns_1_0.rs b/tests/expectations/tests/union-in-ns_1_0.rs index 34d9fbf4b7..c210c38c74 100644 --- a/tests/expectations/tests/union-in-ns_1_0.rs +++ b/tests/expectations/tests/union-in-ns_1_0.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/union_bitfield.rs b/tests/expectations/tests/union_bitfield.rs index 9e476099cc..c4b91899d0 100644 --- a/tests/expectations/tests/union_bitfield.rs +++ b/tests/expectations/tests/union_bitfield.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/union_bitfield_1_0.rs b/tests/expectations/tests/union_bitfield_1_0.rs index efc7dfebc6..2a620b23c4 100644 --- a/tests/expectations/tests/union_bitfield_1_0.rs +++ b/tests/expectations/tests/union_bitfield_1_0.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/union_dtor.rs b/tests/expectations/tests/union_dtor.rs index 3a24fc4a06..dd3635e145 100644 --- a/tests/expectations/tests/union_dtor.rs +++ b/tests/expectations/tests/union_dtor.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/union_dtor_1_0.rs b/tests/expectations/tests/union_dtor_1_0.rs index 0463bc964a..a59f99fc6c 100644 --- a/tests/expectations/tests/union_dtor_1_0.rs +++ b/tests/expectations/tests/union_dtor_1_0.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/union_fields.rs b/tests/expectations/tests/union_fields.rs index 148c19ab1f..d0bc26c2d6 100644 --- a/tests/expectations/tests/union_fields.rs +++ b/tests/expectations/tests/union_fields.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/union_fields_1_0.rs b/tests/expectations/tests/union_fields_1_0.rs index 0068f97abd..36972b6b8f 100644 --- a/tests/expectations/tests/union_fields_1_0.rs +++ b/tests/expectations/tests/union_fields_1_0.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/union_template.rs b/tests/expectations/tests/union_template.rs index a8af8b9c15..fcef30c9e0 100644 --- a/tests/expectations/tests/union_template.rs +++ b/tests/expectations/tests/union_template.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/union_template_1_0.rs b/tests/expectations/tests/union_template_1_0.rs index 370d27174b..487579f7e5 100644 --- a/tests/expectations/tests/union_template_1_0.rs +++ b/tests/expectations/tests/union_template_1_0.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/union_with_anon_struct.rs b/tests/expectations/tests/union_with_anon_struct.rs index b42063becd..8113ae09ec 100644 --- a/tests/expectations/tests/union_with_anon_struct.rs +++ b/tests/expectations/tests/union_with_anon_struct.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/union_with_anon_struct_1_0.rs b/tests/expectations/tests/union_with_anon_struct_1_0.rs index 0f53d17ed3..09dcfa1b08 100644 --- a/tests/expectations/tests/union_with_anon_struct_1_0.rs +++ b/tests/expectations/tests/union_with_anon_struct_1_0.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/union_with_anon_struct_bitfield.rs b/tests/expectations/tests/union_with_anon_struct_bitfield.rs index 46a4bb520d..ca8251745b 100644 --- a/tests/expectations/tests/union_with_anon_struct_bitfield.rs +++ b/tests/expectations/tests/union_with_anon_struct_bitfield.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs b/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs index 89047eca59..352b32b1ee 100644 --- a/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs +++ b/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/union_with_anon_union.rs b/tests/expectations/tests/union_with_anon_union.rs index bf4775b1a0..89756d44f0 100644 --- a/tests/expectations/tests/union_with_anon_union.rs +++ b/tests/expectations/tests/union_with_anon_union.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/union_with_anon_union_1_0.rs b/tests/expectations/tests/union_with_anon_union_1_0.rs index 722ee4d6f7..f892c45f8b 100644 --- a/tests/expectations/tests/union_with_anon_union_1_0.rs +++ b/tests/expectations/tests/union_with_anon_union_1_0.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/union_with_anon_unnamed_struct.rs b/tests/expectations/tests/union_with_anon_unnamed_struct.rs index 00887d1110..7f1d794f42 100644 --- a/tests/expectations/tests/union_with_anon_unnamed_struct.rs +++ b/tests/expectations/tests/union_with_anon_unnamed_struct.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs b/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs index dc9ff2cb9f..cbdac700fb 100644 --- a/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs +++ b/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/union_with_anon_unnamed_union.rs b/tests/expectations/tests/union_with_anon_unnamed_union.rs index ab729ea251..1720b82ff5 100644 --- a/tests/expectations/tests/union_with_anon_unnamed_union.rs +++ b/tests/expectations/tests/union_with_anon_unnamed_union.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs b/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs index beb151d655..910f5885c0 100644 --- a/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs +++ b/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/union_with_big_member.rs b/tests/expectations/tests/union_with_big_member.rs index 5b459d3c5a..ebfe765696 100644 --- a/tests/expectations/tests/union_with_big_member.rs +++ b/tests/expectations/tests/union_with_big_member.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/union_with_big_member_1_0.rs b/tests/expectations/tests/union_with_big_member_1_0.rs index 31fc746592..3aba485bc7 100644 --- a/tests/expectations/tests/union_with_big_member_1_0.rs +++ b/tests/expectations/tests/union_with_big_member_1_0.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/union_with_nesting.rs b/tests/expectations/tests/union_with_nesting.rs index eeefa6afa5..c1403d2cfa 100644 --- a/tests/expectations/tests/union_with_nesting.rs +++ b/tests/expectations/tests/union_with_nesting.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/union_with_nesting_1_0.rs b/tests/expectations/tests/union_with_nesting_1_0.rs index 1ae7d31fdc..3f105c39e8 100644 --- a/tests/expectations/tests/union_with_nesting_1_0.rs +++ b/tests/expectations/tests/union_with_nesting_1_0.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/unknown_attr.rs b/tests/expectations/tests/unknown_attr.rs index 0c0eeff1b7..8dbda00d71 100644 --- a/tests/expectations/tests/unknown_attr.rs +++ b/tests/expectations/tests/unknown_attr.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/use-core.rs b/tests/expectations/tests/use-core.rs index 04a0f0a7b8..89c631ebfc 100644 --- a/tests/expectations/tests/use-core.rs +++ b/tests/expectations/tests/use-core.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/use-core_1_0.rs b/tests/expectations/tests/use-core_1_0.rs index 5551800608..2d3b39df08 100644 --- a/tests/expectations/tests/use-core_1_0.rs +++ b/tests/expectations/tests/use-core_1_0.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/using.rs b/tests/expectations/tests/using.rs index bc30c5d472..28b4308b3d 100644 --- a/tests/expectations/tests/using.rs +++ b/tests/expectations/tests/using.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/var-tracing.rs b/tests/expectations/tests/var-tracing.rs index 9a7d70e0d8..2931f9121c 100644 --- a/tests/expectations/tests/var-tracing.rs +++ b/tests/expectations/tests/var-tracing.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/variadic-method.rs b/tests/expectations/tests/variadic-method.rs index ff62aa226c..be93dda70b 100644 --- a/tests/expectations/tests/variadic-method.rs +++ b/tests/expectations/tests/variadic-method.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/variadic_template_function.rs b/tests/expectations/tests/variadic_template_function.rs index 2b3ae2b46a..8f67136ac8 100644 --- a/tests/expectations/tests/variadic_template_function.rs +++ b/tests/expectations/tests/variadic_template_function.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/vector.rs b/tests/expectations/tests/vector.rs index 86a9d737fd..04f4de714b 100644 --- a/tests/expectations/tests/vector.rs +++ b/tests/expectations/tests/vector.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/virtual_dtor.rs b/tests/expectations/tests/virtual_dtor.rs index 486de8c691..f50130cd47 100644 --- a/tests/expectations/tests/virtual_dtor.rs +++ b/tests/expectations/tests/virtual_dtor.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/virtual_inheritance.rs b/tests/expectations/tests/virtual_inheritance.rs index 4da4170413..8283b6d544 100644 --- a/tests/expectations/tests/virtual_inheritance.rs +++ b/tests/expectations/tests/virtual_inheritance.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/virtual_overloaded.rs b/tests/expectations/tests/virtual_overloaded.rs index f55b5153b9..9a9d642441 100644 --- a/tests/expectations/tests/virtual_overloaded.rs +++ b/tests/expectations/tests/virtual_overloaded.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/vtable_recursive_sig.rs b/tests/expectations/tests/vtable_recursive_sig.rs index 90d8b0e394..0285154c1a 100644 --- a/tests/expectations/tests/vtable_recursive_sig.rs +++ b/tests/expectations/tests/vtable_recursive_sig.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/wasm-import-module.rs b/tests/expectations/tests/wasm-import-module.rs index 509fd56064..e334a7b734 100644 --- a/tests/expectations/tests/wasm-import-module.rs +++ b/tests/expectations/tests/wasm-import-module.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/weird_bitfields.rs b/tests/expectations/tests/weird_bitfields.rs index b786198ce1..4998a944a2 100644 --- a/tests/expectations/tests/weird_bitfields.rs +++ b/tests/expectations/tests/weird_bitfields.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/what_is_going_on.rs b/tests/expectations/tests/what_is_going_on.rs index 8c954c4c53..8f70466b99 100644 --- a/tests/expectations/tests/what_is_going_on.rs +++ b/tests/expectations/tests/what_is_going_on.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/whitelist-namespaces-basic.rs b/tests/expectations/tests/whitelist-namespaces-basic.rs index 39ad1ed6ee..36d03fefb5 100644 --- a/tests/expectations/tests/whitelist-namespaces-basic.rs +++ b/tests/expectations/tests/whitelist-namespaces-basic.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/whitelist-namespaces.rs b/tests/expectations/tests/whitelist-namespaces.rs index 6f36034b54..4236f63ed9 100644 --- a/tests/expectations/tests/whitelist-namespaces.rs +++ b/tests/expectations/tests/whitelist-namespaces.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/whitelist_basic.rs b/tests/expectations/tests/whitelist_basic.rs index 0fa97eab92..7806923c71 100644 --- a/tests/expectations/tests/whitelist_basic.rs +++ b/tests/expectations/tests/whitelist_basic.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/whitelist_fix.rs b/tests/expectations/tests/whitelist_fix.rs index a14b0e56da..9cff795bd6 100644 --- a/tests/expectations/tests/whitelist_fix.rs +++ b/tests/expectations/tests/whitelist_fix.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/whitelist_vars.rs b/tests/expectations/tests/whitelist_vars.rs index 29cb73897b..590cbafcfa 100644 --- a/tests/expectations/tests/whitelist_vars.rs +++ b/tests/expectations/tests/whitelist_vars.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/whitelisted-item-references-no-hash.rs b/tests/expectations/tests/whitelisted-item-references-no-hash.rs index 3a5655bf96..e1217bc505 100644 --- a/tests/expectations/tests/whitelisted-item-references-no-hash.rs +++ b/tests/expectations/tests/whitelisted-item-references-no-hash.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/whitelisted-item-references-no-partialeq.rs b/tests/expectations/tests/whitelisted-item-references-no-partialeq.rs index 4e1ee2de4c..2aabc1018b 100644 --- a/tests/expectations/tests/whitelisted-item-references-no-partialeq.rs +++ b/tests/expectations/tests/whitelisted-item-references-no-partialeq.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/whitelisted_item_references_no_copy.rs b/tests/expectations/tests/whitelisted_item_references_no_copy.rs index 2a4bfa600b..d13ede59e6 100644 --- a/tests/expectations/tests/whitelisted_item_references_no_copy.rs +++ b/tests/expectations/tests/whitelisted_item_references_no_copy.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/win32-thiscall_1_0.rs b/tests/expectations/tests/win32-thiscall_1_0.rs index e9c5d9769d..502e12fe44 100644 --- a/tests/expectations/tests/win32-thiscall_1_0.rs +++ b/tests/expectations/tests/win32-thiscall_1_0.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/win32-thiscall_nightly.rs b/tests/expectations/tests/win32-thiscall_nightly.rs index a135b63f44..92bb13cc61 100644 --- a/tests/expectations/tests/win32-thiscall_nightly.rs +++ b/tests/expectations/tests/win32-thiscall_nightly.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/with_array_pointers_arguments.rs b/tests/expectations/tests/with_array_pointers_arguments.rs index 9c7b225b6e..2a7d18025d 100644 --- a/tests/expectations/tests/with_array_pointers_arguments.rs +++ b/tests/expectations/tests/with_array_pointers_arguments.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/without_array_pointers_arguments.rs b/tests/expectations/tests/without_array_pointers_arguments.rs index 4221fc0c4c..c4acdb3e91 100644 --- a/tests/expectations/tests/without_array_pointers_arguments.rs +++ b/tests/expectations/tests/without_array_pointers_arguments.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/zero-size-array-align.rs b/tests/expectations/tests/zero-size-array-align.rs index 87beae3837..92b6798fb2 100644 --- a/tests/expectations/tests/zero-size-array-align.rs +++ b/tests/expectations/tests/zero-size-array-align.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/expectations/tests/zero-sized-array.rs b/tests/expectations/tests/zero-sized-array.rs index 75cf7572fb..347c22649d 100644 --- a/tests/expectations/tests/zero-sized-array.rs +++ b/tests/expectations/tests/zero-sized-array.rs @@ -1,5 +1,3 @@ -/* automatically generated by rust-bindgen */ - #![allow( dead_code, non_snake_case, diff --git a/tests/tests.rs b/tests/tests.rs index 9bf11da947..2f8cdea94b 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -352,6 +352,7 @@ fn test_clang_env_args() { "-D_ENV_ONE=1 -D_ENV_TWO=\"2 -DNOT_THREE=1\"", ); let actual = builder() + .disable_header_comment() .header_contents( "test.hpp", "#ifdef _ENV_ONE\nextern const int x[] = { 42 };\n#endif\n\ @@ -366,9 +367,7 @@ fn test_clang_env_args() { println!("{}", stderr); let (expected, _) = rustfmt( - "/* automatically generated by rust-bindgen */ - -extern \"C\" { + "extern \"C\" { pub static x: [::std::os::raw::c_int; 1usize]; } extern \"C\" { @@ -384,6 +383,7 @@ extern \"C\" { #[test] fn test_header_contents() { let actual = builder() + .disable_header_comment() .header_contents("test.h", "int foo(const char* a);") .clang_arg("--target=x86_64-unknown-linux") .generate() @@ -394,9 +394,7 @@ fn test_header_contents() { println!("{}", stderr); let (expected, _) = rustfmt( - "/* automatically generated by rust-bindgen */ - -extern \"C\" { + "extern \"C\" { pub fn foo(a: *const ::std::os::raw::c_char) -> ::std::os::raw::c_int; } " From a492a9ea9dbad164bdb7af6b43162e222c251923 Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Tue, 23 Jun 2020 05:48:42 -0700 Subject: [PATCH 033/942] Update some docs that are not changelogs --- README.md | 4 ++-- book/src/introduction.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9e9b4d36ca..1268d06e1d 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ void eleven_out_of_ten_majestic_af(Doggo* pupper); functions and use its types: ```rust -/* automatically generated by rust-bindgen */ +/* automatically generated by rust-bindgen 0.99.9 */ #[repr(C)] pub struct Doggo { @@ -71,4 +71,4 @@ For more details on how `bindgen` uses `libclang`, see the [`bindgen` users guid [bindgen-cmdline]: https://rust-lang.github.io/rust-bindgen/command-line-usage.html [clang-sys-env]: https://github.com/KyleMayes/clang-sys#environment-variables -[bindgen-book-clang]: https://rust-lang.github.io/rust-bindgen/requirements.html#clang \ No newline at end of file +[bindgen-book-clang]: https://rust-lang.github.io/rust-bindgen/requirements.html#clang diff --git a/book/src/introduction.md b/book/src/introduction.md index 971d257d4e..e77ea0c69e 100644 --- a/book/src/introduction.md +++ b/book/src/introduction.md @@ -18,7 +18,7 @@ void cool_function(int i, char c, CoolStruct* cs); functions and use its types: ```rust -/* automatically generated by rust-bindgen */ +/* automatically generated by rust-bindgen 0.99.9 */ #[repr(C)] pub struct CoolStruct { From 30ac96231ad4d8af8a92a5f83043bd61682691d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 29 Jun 2020 03:19:18 +0200 Subject: [PATCH 034/942] lib: Stop using count() to do for loops. This itched me when reviewing #1816. Seems easier to switch those to loop over `get_items()`, but this patch also deduplicates the code a bit, because all that copy-pasta was also itching me. These flags don't have ordering dependencies, so the result builder should be equivalent. --- src/lib.rs | 231 +++++++++-------------------------------------------- 1 file changed, 36 insertions(+), 195 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 22b5594a93..3fc439a5b0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -255,131 +255,46 @@ impl Builder { ) } - self.options - .bitfield_enums - .get_items() - .iter() - .map(|item| { - output_vector.push("--bitfield-enum".into()); - output_vector.push(item.to_owned()); - }) - .count(); - - self.options - .newtype_enums - .get_items() - .iter() - .map(|item| { - output_vector.push("--newtype-enum".into()); - output_vector.push(item.to_owned()); - }) - .count(); - - self.options - .rustified_enums - .get_items() - .iter() - .map(|item| { - output_vector.push("--rustified-enum".into()); - output_vector.push(item.to_owned()); - }) - .count(); - - self.options - .rustified_non_exhaustive_enums - .get_items() - .iter() - .map(|item| { - output_vector.push("--rustified-enum-non-exhaustive".into()); - output_vector.push(item.to_owned()); - }) - .count(); - - self.options - .constified_enum_modules - .get_items() - .iter() - .map(|item| { - output_vector.push("--constified-enum-module".into()); - output_vector.push(item.to_owned()); - }) - .count(); - - self.options - .constified_enums - .get_items() - .iter() - .map(|item| { - output_vector.push("--constified-enum".into()); - output_vector.push(item.to_owned()); - }) - .count(); - if self.options.default_alias_style != Default::default() { output_vector.push("--default-alias-style=".into()); output_vector .push(self.options.default_alias_style.as_str().into()); } - self.options - .type_alias - .get_items() - .iter() - .map(|item| { - output_vector.push("--type-alias".into()); - output_vector.push(item.to_owned()); - }) - .count(); - - self.options - .new_type_alias - .get_items() - .iter() - .map(|item| { - output_vector.push("--new-type-alias".into()); - output_vector.push(item.to_owned()); - }) - .count(); - - self.options - .new_type_alias_deref - .get_items() - .iter() - .map(|item| { - output_vector.push("--new-type-alias-deref".into()); - output_vector.push(item.to_owned()); - }) - .count(); - - self.options - .blacklisted_types - .get_items() - .iter() - .map(|item| { - output_vector.push("--blacklist-type".into()); - output_vector.push(item.to_owned()); - }) - .count(); - - self.options - .blacklisted_functions - .get_items() - .iter() - .map(|item| { - output_vector.push("--blacklist-function".into()); - output_vector.push(item.to_owned()); - }) - .count(); + let regex_sets = &[ + (&self.options.bitfield_enums, "--bitfield-enum"), + (&self.options.newtype_enums, "--newtype-enum"), + (&self.options.rustified_enums, "--rustified-enum"), + ( + &self.options.rustified_non_exhaustive_enums, + "--rustified-enum-non-exhaustive", + ), + ( + &self.options.constified_enum_modules, + "--constified-enum-module", + ), + (&self.options.constified_enums, "--constified-enum"), + (&self.options.type_alias, "--type-alias"), + (&self.options.new_type_alias, "--new-type-alias"), + (&self.options.new_type_alias_deref, "--new-type-alias-deref"), + (&self.options.blacklisted_types, "--blacklist-type"), + (&self.options.blacklisted_functions, "--blacklist-function"), + (&self.options.blacklisted_items, "--blacklist-item"), + (&self.options.opaque_types, "--opaque-type"), + (&self.options.whitelisted_functions, "--whitelist-function"), + (&self.options.whitelisted_types, "--whitelist-type"), + (&self.options.whitelisted_vars, "--whitelist-var"), + (&self.options.no_partialeq_types, "--no-partialeq"), + (&self.options.no_copy_types, "--no-copy"), + (&self.options.no_hash_types, "--no-hash"), + ]; - self.options - .blacklisted_items - .get_items() - .iter() - .map(|item| { - output_vector.push("--blacklist-item".into()); + for (set, flag) in regex_sets { + for item in set.get_items() { + output_vector.push((*flag).to_owned()); output_vector.push(item.to_owned()); - }) - .count(); + } + } if !self.options.layout_tests { output_vector.push("--no-layout-tests".into()); @@ -540,24 +455,10 @@ impl Builder { output_vector.push(wasm_import_module_name.clone()); } - self.options - .opaque_types - .get_items() - .iter() - .map(|item| { - output_vector.push("--opaque-type".into()); - output_vector.push(item.to_owned()); - }) - .count(); - - self.options - .raw_lines - .iter() - .map(|item| { - output_vector.push("--raw-line".into()); - output_vector.push(item.to_owned()); - }) - .count(); + for line in &self.options.raw_lines { + output_vector.push("--raw-line".into()); + output_vector.push(line.into()); + } if self.options.use_core { output_vector.push("--use-core".into()); @@ -567,36 +468,6 @@ impl Builder { output_vector.push("--conservative-inline-namespaces".into()); } - self.options - .whitelisted_functions - .get_items() - .iter() - .map(|item| { - output_vector.push("--whitelist-function".into()); - output_vector.push(item.to_owned()); - }) - .count(); - - self.options - .whitelisted_types - .get_items() - .iter() - .map(|item| { - output_vector.push("--whitelist-type".into()); - output_vector.push(item.to_owned()); - }) - .count(); - - self.options - .whitelisted_vars - .get_items() - .iter() - .map(|item| { - output_vector.push("--whitelist-var".into()); - output_vector.push(item.to_owned()); - }) - .count(); - if !self.options.record_matches { output_vector.push("--no-record-matches".into()); } @@ -619,36 +490,6 @@ impl Builder { output_vector.push(path.into()); } - self.options - .no_partialeq_types - .get_items() - .iter() - .map(|item| { - output_vector.push("--no-partialeq".into()); - output_vector.push(item.to_owned()); - }) - .count(); - - self.options - .no_copy_types - .get_items() - .iter() - .map(|item| { - output_vector.push("--no-copy".into()); - output_vector.push(item.to_owned()); - }) - .count(); - - self.options - .no_hash_types - .get_items() - .iter() - .map(|item| { - output_vector.push("--no-hash".into()); - output_vector.push(item.to_owned()); - }) - .count(); - // Add clang arguments output_vector.push("--".into()); From 3151087a3a3940aef33c4a3d23671a05683c6e85 Mon Sep 17 00:00:00 2001 From: Travis Finkenauer Date: Sun, 28 Jun 2020 21:14:48 -0400 Subject: [PATCH 035/942] Handle multiple headers for command_line_flags() Output from Builder::command_line_flags() would fail if more than one header were provided. This adds extra headers via the '-include' clang option. --- src/lib.rs | 12 +++++++----- src/main.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 3fc439a5b0..10e143533b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -499,11 +499,13 @@ impl Builder { } if self.input_headers.len() > 1 { - output_vector.extend( - self.input_headers[..self.input_headers.len() - 1] - .iter() - .cloned(), - ); + // To pass more than one header, we need to pass all but the last + // header via the `-include` clang arg + output_vector.reserve(2 * self.input_headers.len() - 2); + for header in &self.input_headers[..self.input_headers.len() - 1] { + output_vector.push("-include".to_string()); + output_vector.push(header.clone()); + } } output_vector diff --git a/src/main.rs b/src/main.rs index c554ac50e3..168d6cc03e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -86,3 +86,45 @@ fn print_verbose_err() { https://github.com/rust-lang/rust-bindgen/issues/new" ); } + +#[cfg(test)] +mod test { + use std::path::PathBuf; + + fn build_flags_output_helper(builder: &bindgen::Builder) { + let mut command_line_flags = builder.command_line_flags(); + command_line_flags.insert(0, "bindgen".to_string()); + + let flags_quoted: Vec = command_line_flags + .iter() + .map(|x| format!("'{}'", x)) + .collect(); + let flags_str = flags_quoted.join(" "); + println!("{}", flags_str); + + crate::options::builder_from_flags(command_line_flags.into_iter()) + .unwrap(); + } + + #[test] + fn commandline_flag_roundtrip() { + // test1: various options + let bindings = bindgen::Builder::default() + .header("tests/headers/char.h") + .record_matches(false) + .size_t_is_usize(true) + .rustfmt_bindings(false) + .rustfmt_configuration_file(Some(PathBuf::from("/dev/null"))) + .no_partialeq(".") + .no_copy(".") + .no_hash("."); + build_flags_output_helper(&bindings); + + // test2: multiple headers + let bindings = bindgen::Builder::default() + .header("tests/headers/char.h") + .header("tests/headers/func_ptr.h") + .header("tests/headers/16-byte-alignment.h"); + build_flags_output_helper(&bindings); + } +} From 394648a5f128b7dd2ca2f0e4b06ae4e362c583c9 Mon Sep 17 00:00:00 2001 From: Travis Finkenauer Date: Mon, 29 Jun 2020 01:42:09 -0400 Subject: [PATCH 036/942] Simplify multiple headers test Ensure that we try to generate() the test Builder. Remove unnecessary reserve() optimization. --- src/lib.rs | 1 - src/main.rs | 21 +++++---------------- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 10e143533b..0ba6da3ea6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -501,7 +501,6 @@ impl Builder { if self.input_headers.len() > 1 { // To pass more than one header, we need to pass all but the last // header via the `-include` clang arg - output_vector.reserve(2 * self.input_headers.len() - 2); for header in &self.input_headers[..self.input_headers.len() - 1] { output_vector.push("-include".to_string()); output_vector.push(header.clone()); diff --git a/src/main.rs b/src/main.rs index 168d6cc03e..5a9c3318f0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -102,25 +102,14 @@ mod test { let flags_str = flags_quoted.join(" "); println!("{}", flags_str); - crate::options::builder_from_flags(command_line_flags.into_iter()) - .unwrap(); + let (builder, _output, _verbose) = + crate::options::builder_from_flags(command_line_flags.into_iter()) + .unwrap(); + builder.generate().expect("failed to generate bindings"); } #[test] - fn commandline_flag_roundtrip() { - // test1: various options - let bindings = bindgen::Builder::default() - .header("tests/headers/char.h") - .record_matches(false) - .size_t_is_usize(true) - .rustfmt_bindings(false) - .rustfmt_configuration_file(Some(PathBuf::from("/dev/null"))) - .no_partialeq(".") - .no_copy(".") - .no_hash("."); - build_flags_output_helper(&bindings); - - // test2: multiple headers + fn commandline_multiple_headers() { let bindings = bindgen::Builder::default() .header("tests/headers/char.h") .header("tests/headers/func_ptr.h") From d8968fb2755de7cbf39fc31bf601e1b19d371d52 Mon Sep 17 00:00:00 2001 From: Travis Finkenauer Date: Mon, 29 Jun 2020 02:01:29 -0400 Subject: [PATCH 037/942] Properly shell quote flags in test output --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 5a9c3318f0..6dd436db38 100644 --- a/src/main.rs +++ b/src/main.rs @@ -97,7 +97,7 @@ mod test { let flags_quoted: Vec = command_line_flags .iter() - .map(|x| format!("'{}'", x)) + .map(|x| format!("{}", shlex::quote(x))) .collect(); let flags_str = flags_quoted.join(" "); println!("{}", flags_str); From a2fa62422fc2c94b5732dc2ed4326c6f3fbbc622 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 29 Jun 2020 15:36:48 +0200 Subject: [PATCH 038/942] lib: Fix msrv build. error[E0277]: the trait bound `std::string::String: std::convert::From<&std::string::String>` is not satisfied --> src/lib.rs:460:37 | 460 | output_vector.push(line.into()); | ^^^^ the trait `std::convert::From<&std::string::String>` is not implemented for `std::string::String` --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 0ba6da3ea6..9aef00731d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -457,7 +457,7 @@ impl Builder { for line in &self.options.raw_lines { output_vector.push("--raw-line".into()); - output_vector.push(line.into()); + output_vector.push(line.clone()); } if self.options.use_core { From d4c3d4c5ffab9a9a65545bc1bb8ab06c771d5c81 Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Mon, 29 Jun 2020 05:45:53 -0700 Subject: [PATCH 039/942] Refine test for C++ operators --- src/ir/function.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/ir/function.rs b/src/ir/function.rs index e811a721b1..93a8d89fcd 100644 --- a/src/ir/function.rs +++ b/src/ir/function.rs @@ -377,9 +377,14 @@ impl FunctionSig { return Err(ParseError::Continue); } - // Don't parse operatorxx functions in C++ let spelling = cursor.spelling(); - if spelling.starts_with("operator") { + + // Don't parse operatorxx functions in C++ + let is_operator = |spelling: &str| { + spelling.starts_with("operator") && + !clang::is_valid_identifier(spelling) + }; + if is_operator(&spelling) { return Err(ParseError::Continue); } From eab1137ea98c531cc079174a3a8bec1106ceaacf Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Mon, 29 Jun 2020 19:50:12 -0700 Subject: [PATCH 040/942] Introduce expectation test for operator names --- tests/expectations/tests/operator.rs | 16 ++++++++++++++++ tests/headers/operator.hpp | 5 +++++ 2 files changed, 21 insertions(+) create mode 100644 tests/expectations/tests/operator.rs create mode 100644 tests/headers/operator.hpp diff --git a/tests/expectations/tests/operator.rs b/tests/expectations/tests/operator.rs new file mode 100644 index 0000000000..5128226dd8 --- /dev/null +++ b/tests/expectations/tests/operator.rs @@ -0,0 +1,16 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +extern "C" { + #[link_name = "\u{1}_Z20operator_informationv"] + pub fn operator_information() -> ::std::os::raw::c_int; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct Foo { + _unused: [u8; 0], +} diff --git a/tests/headers/operator.hpp b/tests/headers/operator.hpp new file mode 100644 index 0000000000..186f1fe683 --- /dev/null +++ b/tests/headers/operator.hpp @@ -0,0 +1,5 @@ +int operator_information(void); + +class Foo; +int operator<<(const Foo&, int); + From 51ff49ae6366163b78d197db6b8f454c03d5733f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 29 Jun 2020 03:33:06 +0200 Subject: [PATCH 041/942] tests: Minor simplification of test harness. We were never returning Ok(None), so not sure why this was ever there. --- tests/tests.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/tests/tests.rs b/tests/tests.rs index 2f8cdea94b..a85803c3b9 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -247,7 +247,7 @@ fn builder() -> Builder { bindgen::builder().disable_header_comment() } -fn create_bindgen_builder(header: &PathBuf) -> Result, Error> { +fn create_bindgen_builder(header: &PathBuf) -> Result { #[cfg(feature = "logging")] let _ = env_logger::try_init(); @@ -319,7 +319,7 @@ fn create_bindgen_builder(header: &PathBuf) -> Result, Error> { .map(ToString::to_string) .chain(flags.into_iter()); - builder_from_flags(args).map(|(builder, _, _)| Some(builder)) + builder_from_flags(args).map(|(builder, _, _)| builder) } macro_rules! test_header { @@ -328,11 +328,7 @@ macro_rules! test_header { fn $function() { let header = PathBuf::from($header); let result = create_bindgen_builder(&header).and_then(|builder| { - if let Some(builder) = builder { - compare_generated_header(&header, builder) - } else { - Ok(()) - } + compare_generated_header(&header, builder) }); if let Err(err) = result { From 243359c36c78553f9348993e9f1b8dd20686439a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 29 Jun 2020 04:07:30 +0200 Subject: [PATCH 042/942] lib: Trivially fix various command line arguments that are not properly round-tripping. --- src/lib.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 9aef00731d..5a86364e6d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -232,8 +232,17 @@ impl Builder { output_vector.push("--rust-target".into()); output_vector.push(self.options.rust_target.into()); + // FIXME(emilio): This is a bit hacky, maybe we should stop re-using the + // RustFeatures to store the "disable_untagged_union" call, and make it + // a different flag that we check elsewhere / in generate(). + if !self.options.rust_features.untagged_union && + RustFeatures::from(self.options.rust_target).untagged_union + { + output_vector.push("--disable-untagged-union".into()); + } + if self.options.default_enum_style != Default::default() { - output_vector.push("--default-enum-style=".into()); + output_vector.push("--default-enum-style".into()); output_vector.push( match self.options.default_enum_style { codegen::EnumVariation::Rust { @@ -256,7 +265,7 @@ impl Builder { } if self.options.default_alias_style != Default::default() { - output_vector.push("--default-alias-style=".into()); + output_vector.push("--default-alias-style".into()); output_vector .push(self.options.default_alias_style.as_str().into()); } @@ -468,6 +477,10 @@ impl Builder { output_vector.push("--conservative-inline-namespaces".into()); } + if self.options.generate_inline_functions { + output_vector.push("--generate-inline-functions".into()); + } + if !self.options.record_matches { output_vector.push("--no-record-matches".into()); } From d794a0823c83d9b8e36666cdcb932b7a4c5aac21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 29 Jun 2020 03:57:07 +0200 Subject: [PATCH 043/942] tests: Check that command_line_args round-trips. Fixes #1818. --- CONTRIBUTING.md | 6 ++++- tests/tests.rs | 63 ++++++++++++++++++++++++++++++++----------------- 2 files changed, 46 insertions(+), 23 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 592556b843..ae72afb603 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -122,9 +122,13 @@ You may set the `BINDGEN_OVERWRITE_EXPECTED` environment variable to overwrite the expected bindings with `bindgen`'s current output: ``` -$BINDGEN_OVERWRITE_EXPECTED=1 cargo test +$ BINDGEN_OVERWRITE_EXPECTED=1 cargo test ``` +If you're not changing command line arguments, you may want to set +`BINDGEN_DISABLE_ROUNDTRIP_TEST` to avoid a lot of tests for round-tripping of +those. + ### Testing Generated Bindings If your local changes are introducing expected modifications in the diff --git a/tests/tests.rs b/tests/tests.rs index a85803c3b9..4cf39460e3 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -17,9 +17,6 @@ use std::sync::Once; mod options; use crate::options::builder_from_flags; -/// The environment variable that determines if test expectations are overwritten. -static OVERWRITE_ENV_VAR: &str = "BINDGEN_OVERWRITE_EXPECTED"; - // Run `rustfmt` on the given source string and return a tuple of the formatted // bindings, and rustfmt's stderr. fn rustfmt(source: String) -> (String, String) { @@ -119,6 +116,7 @@ The latest `rustfmt` is required to run the `bindgen` test suite. Install fn compare_generated_header( header: &PathBuf, builder: Builder, + check_roundtrip: bool, ) -> Result<(), Error> { let file_name = header.file_name().ok_or(Error::new( ErrorKind::Other, @@ -194,6 +192,14 @@ fn compare_generated_header( ), }; + let flags = if check_roundtrip { + let mut flags = builder.command_line_flags(); + flags.insert(0, "bindgen".into()); + flags + } else { + vec![] + }; + // We skip the generate() error here so we get a full diff below let (actual, rustfmt_stderr) = match builder.generate() { Ok(bindings) => { @@ -207,37 +213,48 @@ fn compare_generated_header( let (expected, rustfmt_stderr) = rustfmt(expected); println!("{}", rustfmt_stderr); - if actual == expected { - if !actual.is_empty() { - return Ok(()); - } + if actual.is_empty() { return Err(Error::new( ErrorKind::Other, "Something's gone really wrong!", )); } - println!("{}", rustfmt_stderr); + if actual != expected { + println!("{}", rustfmt_stderr); - println!("diff expected generated"); - println!("--- expected: {:?}", looked_at.last().unwrap()); - println!("+++ generated from: {:?}", header); + println!("diff expected generated"); + println!("--- expected: {:?}", looked_at.last().unwrap()); + println!("+++ generated from: {:?}", header); - for diff in diff::lines(&expected, &actual) { - match diff { - diff::Result::Left(l) => println!("-{}", l), - diff::Result::Both(l, _) => println!(" {}", l), - diff::Result::Right(r) => println!("+{}", r), + for diff in diff::lines(&expected, &actual) { + match diff { + diff::Result::Left(l) => println!("-{}", l), + diff::Result::Both(l, _) => println!(" {}", l), + diff::Result::Right(r) => println!("+{}", r), + } } + + // Overwrite the expectation with actual output. + if env::var_os("BINDGEN_OVERWRITE_EXPECTED").is_some() { + let mut expectation_file = + fs::File::create(looked_at.last().unwrap())?; + expectation_file.write_all(actual.as_bytes())?; + } + + return Err(Error::new(ErrorKind::Other, "Header and binding differ! Run with BINDGEN_OVERWRITE_EXPECTED=1 in the environment to automatically overwrite the expectation.")); } - // Overwrite the expectation with actual output. - if env::var_os(OVERWRITE_ENV_VAR).is_some() { - let mut expectation_file = fs::File::create(looked_at.last().unwrap())?; - expectation_file.write_all(actual.as_bytes())?; + if check_roundtrip { + let roundtrip_builder = builder_from_flags(flags.into_iter())?.0; + if let Err(e) = + compare_generated_header(&header, roundtrip_builder, false) + { + return Err(Error::new(ErrorKind::Other, format!("Checking CLI flags roundtrip errored! You probably need to fix Builder::command_line_args. {}", e))); + } } - Err(Error::new(ErrorKind::Other, "Header and binding differ! Run with BINDGEN_OVERWRITE_EXPECTED=1 in the environment to automatically overwrite the expectation.")) + Ok(()) } fn builder() -> Builder { @@ -328,7 +345,9 @@ macro_rules! test_header { fn $function() { let header = PathBuf::from($header); let result = create_bindgen_builder(&header).and_then(|builder| { - compare_generated_header(&header, builder) + let check_roundtrip = + env::var_os("BINDGEN_DISABLE_ROUNDTRIP_TEST").is_none(); + compare_generated_header(&header, builder, check_roundtrip) }); if let Err(err) = result { From 17b6ae835e94b2537ac0513a848705fe8f5614af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 6 Jul 2020 19:14:08 +0200 Subject: [PATCH 044/942] main: Remove unused use statement. --- src/main.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 6dd436db38..d84b01af8c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -89,8 +89,6 @@ fn print_verbose_err() { #[cfg(test)] mod test { - use std::path::PathBuf; - fn build_flags_output_helper(builder: &bindgen::Builder) { let mut command_line_flags = builder.command_line_flags(); command_line_flags.insert(0, "bindgen".to_string()); From f94036fd18eefee801b3e99c564b2b0bc1a81218 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 6 Jul 2020 19:13:11 +0200 Subject: [PATCH 045/942] Release v0.54.1 --- CHANGELOG.md | 34 ++++++++++++++++++++++++++++++++++ Cargo.lock | 2 +- Cargo.toml | 2 +- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a371f054f..279ba09ca5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -135,6 +135,40 @@ Released YYYY/MM/DD -------------------------------------------------------------------------------- +# 0.54.1 + +Released 2020/07/06. + +## Added + + * Added ParseCallbacks::func_macro to be able to process function-like macros. + (#1792). + + * Allowed IntKind::Custom to represent paths instead of idents (#1800). + +## Changed + + * Generated comment now includes the bindgen version, and can be disabled + (#1814). + + * Various documentation improvements. + +## Fixed + + * Typedefs for types with the same names as rust primitive types compiles + (#1798). + + * Bindgen dependencies will now get rebuilt when various environment variables + that affect bindgen change (#1809, #1813). + + * Various fixes to command_line_flags (#1816, #1819, #1821). + + * Functions that start with `operator` now get properly generated (#1817). + + +Thanks to all the awesome contributors that sent patches included in this +release! + # 0.54.0 Released 2020/05/21. diff --git a/Cargo.lock b/Cargo.lock index 466c7b9e7e..554235ee01 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -27,7 +27,7 @@ dependencies = [ [[package]] name = "bindgen" -version = "0.54.0" +version = "0.54.1" dependencies = [ "bitflags 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "cexpr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index da63ee5c94..9d433534fb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ readme = "README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.54.0" +version = "0.54.1" edition = "2018" build = "build.rs" From 1bfb3ad051fee3e19a4d2f8d5bb9144fded543cb Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Fri, 17 Jul 2020 10:11:11 -0700 Subject: [PATCH 046/942] Avoid needless `std::mem::replace` In Rust 1.45.0, `std::mem::replace` gained the `#[must_use]` attribute, causing a new diagnostic for some `bindgen` code : error: unused return value of `std::mem::replace` that must be used --> src/ir/comp.rs:751:17 | 751 | / mem::replace( 752 | | self, 753 | | CompFields::AfterComputingBitfieldUnits { 754 | | fields, 755 | | has_bitfield_units, 756 | | }, 757 | | ); | |__________________^ | = note: `-D unused-must-use` implied by `-D warnings` = note: if you don't need the old value, you can just assign the new value directly error: unused return value of `std::mem::replace` that must be used --> src/ir/comp.rs:760:17 | 760 | mem::replace(self, CompFields::ErrorComputingBitfieldUnits); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: if you don't need the old value, you can just assign the new value directly error: aborting due to 2 previous errors --- src/ir/comp.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/ir/comp.rs b/src/ir/comp.rs index 4eeb4745d5..9bb429d285 100644 --- a/src/ir/comp.rs +++ b/src/ir/comp.rs @@ -748,16 +748,13 @@ impl CompFields { match result { Ok((fields, has_bitfield_units)) => { - mem::replace( - self, - CompFields::AfterComputingBitfieldUnits { - fields, - has_bitfield_units, - }, - ); + *self = CompFields::AfterComputingBitfieldUnits { + fields, + has_bitfield_units, + }; } Err(()) => { - mem::replace(self, CompFields::ErrorComputingBitfieldUnits); + *self = CompFields::ErrorComputingBitfieldUnits; } } } From 7427017a5311cd683faca4402ba68d704310ad73 Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Fri, 19 Jun 2020 20:12:00 -0700 Subject: [PATCH 047/942] Stop accommodating libclang < 3.8 --- src/clang.rs | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/clang.rs b/src/clang.rs index 3ddf99dc8b..440f115eea 100644 --- a/src/clang.rs +++ b/src/clang.rs @@ -77,13 +77,10 @@ impl Cursor { } } - /// Gets the C++ manglings for this cursor, or an error if the function is - /// not loaded or the manglings are not available. + /// Gets the C++ manglings for this cursor, or an error if the manglings + /// are not available. pub fn cxx_manglings(&self) -> Result, ()> { use clang_sys::*; - if !clang_Cursor_getCXXManglings::is_loaded() { - return Err(()); - } unsafe { let manglings = clang_Cursor_getCXXManglings(self.x); if manglings.is_null() { @@ -592,11 +589,7 @@ impl Cursor { /// Get the visibility of this cursor's referent. pub fn visibility(&self) -> CXVisibilityKind { - if clang_getCursorVisibility::is_loaded() { - unsafe { clang_getCursorVisibility(self.x) } - } else { - CXVisibility_Default - } + unsafe { clang_getCursorVisibility(self.x) } } /// Given that this cursor's referent is a function, return cursors to its @@ -641,8 +634,7 @@ impl Cursor { /// Is this cursor's referent a field declaration that is marked as /// `mutable`? pub fn is_mutable_field(&self) -> bool { - clang_CXXField_isMutable::is_loaded() && - unsafe { clang_CXXField_isMutable(self.x) != 0 } + unsafe { clang_CXXField_isMutable(self.x) != 0 } } /// Get the offset of the field represented by the Cursor. From 682a32959fca2a1442065fac31a8f187c330848a Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Fri, 19 Jun 2020 20:12:01 -0700 Subject: [PATCH 048/942] Stop testing libclang 3.8 --- .travis.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3944e7c0b2..40b028462d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,13 +17,6 @@ env: - LLVM_VERSION="9.0" BINDGEN_JOB="msrv" # General matrix. - - LLVM_VERSION="3.8" BINDGEN_JOB="test" BINDGEN_PROFILE= - - LLVM_VERSION="3.8" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" - - LLVM_VERSION="3.8" BINDGEN_JOB="integration" BINDGEN_PROFILE= - - LLVM_VERSION="3.8" BINDGEN_JOB="integration" BINDGEN_PROFILE="--release" - - LLVM_VERSION="3.8" BINDGEN_JOB="test" BINDGEN_PROFILE= BINDGEN_NO_DEFAULT_FEATURES="1" BINDGEN_FEATURES="runtime" - - LLVM_VERSION="3.8" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" BINDGEN_NO_DEFAULT_FEATURES="1" BINDGEN_FEATURES="runtime" - - LLVM_VERSION="3.9" BINDGEN_JOB="test" BINDGEN_PROFILE= - LLVM_VERSION="3.9" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" - LLVM_VERSION="3.9" BINDGEN_JOB="integration" BINDGEN_PROFILE= From f4f773b6110b6b845f38414febbf37a056cc40ed Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Fri, 19 Jun 2020 20:12:02 -0700 Subject: [PATCH 049/942] Stop accommodating libclang 3.8 --- src/clang.rs | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/clang.rs b/src/clang.rs index 440f115eea..9c09f71c9a 100644 --- a/src/clang.rs +++ b/src/clang.rs @@ -477,8 +477,7 @@ impl Cursor { /// Is the referent an inlined function? pub fn is_inlined_function(&self) -> bool { - clang_Cursor_isFunctionInlined::is_loaded() && - unsafe { clang_Cursor_isFunctionInlined(self.x) != 0 } + unsafe { clang_Cursor_isFunctionInlined(self.x) != 0 } } /// Get the width of this cursor's referent bit field, or `None` if the @@ -1245,11 +1244,7 @@ impl Type { pub fn named(&self) -> Type { unsafe { Type { - x: if clang_Type_getNamedType::is_loaded() { - clang_Type_getNamedType(self.x) - } else { - self.x - }, + x: clang_Type_getNamedType(self.x), } } } @@ -1960,10 +1955,6 @@ pub struct EvalResult { impl EvalResult { /// Evaluate `cursor` and return the result. pub fn new(cursor: Cursor) -> Option { - if !clang_Cursor_Evaluate::is_loaded() { - return None; - } - // Work around https://bugs.llvm.org/show_bug.cgi?id=42532, see: // * https://github.com/rust-lang/rust-bindgen/issues/283 // * https://github.com/rust-lang/rust-bindgen/issues/1590 From 4ea1e21bccfd33d79a9244a849d1de0f8ac42b3b Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Sun, 21 Jun 2020 17:38:46 -0700 Subject: [PATCH 050/942] Simplify handle_function_macro for clang 3.9+ --- src/clang.rs | 10 ++-------- src/ir/var.rs | 29 ++++------------------------- 2 files changed, 6 insertions(+), 33 deletions(-) diff --git a/src/clang.rs b/src/clang.rs index 9c09f71c9a..357a6dd5f0 100644 --- a/src/clang.rs +++ b/src/clang.rs @@ -237,14 +237,8 @@ impl Cursor { } /// Is this Cursor pointing to a function-like macro definition? - /// Returns None if this cannot be determined with the available libclang - /// (it requires 3.9 or greater). - pub fn is_macro_function_like(&self) -> Option { - if clang_Cursor_isMacroFunctionLike::is_loaded() { - Some(unsafe { clang_Cursor_isMacroFunctionLike(self.x) != 0 }) - } else { - None - } + pub fn is_macro_function_like(&self) -> bool { + unsafe { clang_Cursor_isMacroFunctionLike(self.x) != 0 } } /// Get the kind of referent this cursor is pointing to. diff --git a/src/ir/var.rs b/src/ir/var.rs index 67b2e348ce..ef9635030b 100644 --- a/src/ir/var.rs +++ b/src/ir/var.rs @@ -141,31 +141,10 @@ fn handle_function_macro( tokens: &[ClangToken], callbacks: &dyn crate::callbacks::ParseCallbacks, ) -> Result<(), ParseError> { - fn is_abutting(a: &ClangToken, b: &ClangToken) -> bool { - unsafe { - clang_sys::clang_equalLocations( - clang_sys::clang_getRangeEnd(a.extent), - clang_sys::clang_getRangeStart(b.extent), - ) != 0 - } - } - - let is_functional_macro = - // If we have libclang >= 3.9, we can use `is_macro_function_like()` and - // avoid checking for abutting tokens ourselves. - cursor.is_macro_function_like().unwrap_or_else(|| { - // If we cannot get a definitive answer from clang, we instead check - // for a parenthesis token immediately adjacent to (that is, - // abutting) the first token in the macro definition. - // TODO: Once we don't need the fallback check here, we can hoist - // the `is_macro_function_like` check into this function's caller, - // and thus avoid allocating the `tokens` vector for non-functional - // macros. - match tokens.get(0..2) { - Some([a, b]) => is_abutting(&a, &b) && b.spelling() == b"(", - _ => false, - } - }); + // TODO: Hoist the `is_macro_function_like` check into this function's + // caller, and thus avoid allocating the `tokens` vector for non-functional + // macros. + let is_functional_macro = cursor.is_macro_function_like(); if !is_functional_macro { return Ok(()); From 03dbd1a3f8d80be52d6105e76e7603d9a3b939e0 Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Tue, 23 Jun 2020 15:48:31 -0700 Subject: [PATCH 051/942] Remove testing_only_libclang_3_8 and expectations --- Cargo.toml | 1 - bindgen-integration/Cargo.toml | 1 - src/main.rs | 2 - tests/expectations/build.rs | 1 - .../libclang-3.8/abi_variadic_function.rs | 15 ----- tests/expectations/tests/libclang-3.8/auto.rs | 38 ----------- .../tests/libclang-3.8/call-conv-field.rs | 61 ----------------- .../tests/libclang-3.8/const_bool.rs | 38 ----------- .../tests/libclang-3.8/constant-evaluate.rs | 41 ------------ ...0600-cannot-apply-unary-negation-to-u32.rs | 9 --- .../issue-769-bad-instantiation-test.rs | 61 ----------------- .../tests/libclang-3.8/mangling-win32.rs | 56 ---------------- .../tests/libclang-3.8/objc_inheritance.rs | 66 ------------------- .../tests/libclang-3.8/objc_template.rs | 65 ------------------ .../partial-specialization-and-inheritance.rs | 51 -------------- .../type_alias_template_specialized.rs | 37 ----------- tests/stylo_sanity.rs | 6 +- tests/tests.rs | 2 - 18 files changed, 1 insertion(+), 550 deletions(-) delete mode 100644 tests/expectations/tests/libclang-3.8/abi_variadic_function.rs delete mode 100644 tests/expectations/tests/libclang-3.8/auto.rs delete mode 100644 tests/expectations/tests/libclang-3.8/call-conv-field.rs delete mode 100644 tests/expectations/tests/libclang-3.8/const_bool.rs delete mode 100644 tests/expectations/tests/libclang-3.8/constant-evaluate.rs delete mode 100644 tests/expectations/tests/libclang-3.8/error-E0600-cannot-apply-unary-negation-to-u32.rs delete mode 100644 tests/expectations/tests/libclang-3.8/issue-769-bad-instantiation-test.rs delete mode 100644 tests/expectations/tests/libclang-3.8/mangling-win32.rs delete mode 100644 tests/expectations/tests/libclang-3.8/objc_inheritance.rs delete mode 100644 tests/expectations/tests/libclang-3.8/objc_template.rs delete mode 100644 tests/expectations/tests/libclang-3.8/partial-specialization-and-inheritance.rs delete mode 100644 tests/expectations/tests/libclang-3.8/type_alias_template_specialized.rs diff --git a/Cargo.toml b/Cargo.toml index 9d433534fb..8f93ede1bc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -87,4 +87,3 @@ testing_only_libclang_9 = [] testing_only_libclang_5 = [] testing_only_libclang_4 = [] testing_only_libclang_3_9 = [] -testing_only_libclang_3_8 = [] diff --git a/bindgen-integration/Cargo.toml b/bindgen-integration/Cargo.toml index 8f0cb1f94f..e82fbd9905 100644 --- a/bindgen-integration/Cargo.toml +++ b/bindgen-integration/Cargo.toml @@ -15,4 +15,3 @@ testing_only_libclang_9 = ["bindgen/testing_only_libclang_9"] testing_only_libclang_5 = ["bindgen/testing_only_libclang_5"] testing_only_libclang_4 = ["bindgen/testing_only_libclang_4"] testing_only_libclang_3_9 = ["bindgen/testing_only_libclang_3_9"] -testing_only_libclang_3_8 = ["bindgen/testing_only_libclang_3_8"] diff --git a/src/main.rs b/src/main.rs index d84b01af8c..1768ed8d5b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,8 +27,6 @@ fn clang_version_check() { Some((4, 0)) } else if cfg!(feature = "testing_only_libclang_3_9") { Some((3, 9)) - } else if cfg!(feature = "testing_only_libclang_3_8") { - Some((3, 8)) } else { None }; diff --git a/tests/expectations/build.rs b/tests/expectations/build.rs index 4652645823..2b426a449d 100644 --- a/tests/expectations/build.rs +++ b/tests/expectations/build.rs @@ -9,7 +9,6 @@ use std::io::Write; use std::path::Path; const LIBCLANG_VERSION_DIRS: &'static [&'static str] = &[ - "libclang-3.8", "libclang-3.9", "libclang-4", "libclang-5", diff --git a/tests/expectations/tests/libclang-3.8/abi_variadic_function.rs b/tests/expectations/tests/libclang-3.8/abi_variadic_function.rs deleted file mode 100644 index 415c8cfda8..0000000000 --- a/tests/expectations/tests/libclang-3.8/abi_variadic_function.rs +++ /dev/null @@ -1,15 +0,0 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -extern "C" { - #[link_name = "\u{1}_Z1acz"] - pub fn a(arg1: ::std::os::raw::c_char, ...) -> ::std::os::raw::c_char; -} -extern "C" { - #[link_name = "\u{1}_Z1bcz"] - pub fn b(arg1: ::std::os::raw::c_char, ...) -> ::std::os::raw::c_char; -} diff --git a/tests/expectations/tests/libclang-3.8/auto.rs b/tests/expectations/tests/libclang-3.8/auto.rs deleted file mode 100644 index fad1722cec..0000000000 --- a/tests/expectations/tests/libclang-3.8/auto.rs +++ /dev/null @@ -1,38 +0,0 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct Foo { - pub _address: u8, -} -extern "C" { - #[link_name = "\u{1}_ZN3Foo4kFooE"] - pub static Foo_kFoo: bool; -} -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) - ); -} -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct Bar { - pub _address: u8, -} -extern "C" { - #[link_name = "\u{1}_Z5Test2v"] - pub fn Test2() -> ::std::os::raw::c_uint; -} diff --git a/tests/expectations/tests/libclang-3.8/call-conv-field.rs b/tests/expectations/tests/libclang-3.8/call-conv-field.rs deleted file mode 100644 index 2a905a9528..0000000000 --- a/tests/expectations/tests/libclang-3.8/call-conv-field.rs +++ /dev/null @@ -1,61 +0,0 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] -#![cfg(not(test))] - -#[repr(C)] -#[derive(Default, Copy, Clone)] -pub struct JNINativeInterface_ { - pub GetVersion: ::std::option::Option< - unsafe extern "stdcall" fn( - env: *mut ::std::os::raw::c_void, - ) -> ::std::os::raw::c_int, - >, - pub __hack: ::std::os::raw::c_ulonglong, -} -#[test] -fn bindgen_test_layout_JNINativeInterface_() { - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(JNINativeInterface_)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(JNINativeInterface_)) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).GetVersion - as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(JNINativeInterface_), - "::", - stringify!(GetVersion) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).__hack as *const _ - as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(JNINativeInterface_), - "::", - stringify!(__hack) - ) - ); -} -extern "C" { - #[link_name = "\u{1}_bar@0"] - pub fn bar(); -} diff --git a/tests/expectations/tests/libclang-3.8/const_bool.rs b/tests/expectations/tests/libclang-3.8/const_bool.rs deleted file mode 100644 index 838d9a91b0..0000000000 --- a/tests/expectations/tests/libclang-3.8/const_bool.rs +++ /dev/null @@ -1,38 +0,0 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -extern "C" { - #[link_name = "\u{1}_ZL1k"] - pub static k: bool; -} -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct A { - pub _address: u8, -} -extern "C" { - #[link_name = "\u{1}_ZN1A1kE"] - pub static A_k: bool; -} -#[test] -fn bindgen_test_layout_A() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(A)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(A)) - ); -} -pub type foo = bool; -extern "C" { - #[link_name = "\u{1}_ZL2k2"] - pub static k2: foo; -} diff --git a/tests/expectations/tests/libclang-3.8/constant-evaluate.rs b/tests/expectations/tests/libclang-3.8/constant-evaluate.rs deleted file mode 100644 index a59066c844..0000000000 --- a/tests/expectations/tests/libclang-3.8/constant-evaluate.rs +++ /dev/null @@ -1,41 +0,0 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -pub const foo: _bindgen_ty_1 = _bindgen_ty_1::foo; -pub const bar: _bindgen_ty_1 = _bindgen_ty_1::bar; -#[repr(u32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub enum _bindgen_ty_1 { - foo = 4, - bar = 8, -} -pub type EasyToOverflow = ::std::os::raw::c_ulonglong; -pub const k: EasyToOverflow = 2147483648; -extern "C" { - pub static k_expr: EasyToOverflow; -} -extern "C" { - pub static wow: EasyToOverflow; -} -extern "C" { - pub static BAZ: ::std::os::raw::c_longlong; -} -extern "C" { - pub static fuzz: f64; -} -extern "C" { - pub static BAZZ: ::std::os::raw::c_char; -} -extern "C" { - pub static WAT: ::std::os::raw::c_char; -} -extern "C" { - pub static mut bytestring: *const ::std::os::raw::c_char; -} -extern "C" { - pub static mut NOT_UTF8: *const ::std::os::raw::c_char; -} diff --git a/tests/expectations/tests/libclang-3.8/error-E0600-cannot-apply-unary-negation-to-u32.rs b/tests/expectations/tests/libclang-3.8/error-E0600-cannot-apply-unary-negation-to-u32.rs deleted file mode 100644 index 3fa853eebe..0000000000 --- a/tests/expectations/tests/libclang-3.8/error-E0600-cannot-apply-unary-negation-to-u32.rs +++ /dev/null @@ -1,9 +0,0 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] -#![allow(overflowing_literals)] - -pub const a: u32 = 18446744073709551611; diff --git a/tests/expectations/tests/libclang-3.8/issue-769-bad-instantiation-test.rs b/tests/expectations/tests/libclang-3.8/issue-769-bad-instantiation-test.rs deleted file mode 100644 index c084de95d2..0000000000 --- a/tests/expectations/tests/libclang-3.8/issue-769-bad-instantiation-test.rs +++ /dev/null @@ -1,61 +0,0 @@ -#![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 { - #[allow(unused_imports)] - use self::super::root; - #[repr(C)] - #[derive(Debug, Copy, Clone)] - pub struct Rooted { - pub member: T, - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, - } - impl Default for Rooted { - fn default() -> Self { - unsafe { ::std::mem::zeroed() } - } - } - #[test] - fn __bindgen_test_layout_Rooted_open0_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!( - "Size of template specialization: ", - stringify!(root::Rooted<::std::os::raw::c_int>) - ) - ); - assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(root::Rooted<::std::os::raw::c_int>) - ) - ); - } - #[test] - fn __bindgen_test_layout_Rooted_open0_int_close0_instantiation_1() { - assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!( - "Size of template specialization: ", - stringify!(root::Rooted<::std::os::raw::c_int>) - ) - ); - assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(root::Rooted<::std::os::raw::c_int>) - ) - ); - } -} diff --git a/tests/expectations/tests/libclang-3.8/mangling-win32.rs b/tests/expectations/tests/libclang-3.8/mangling-win32.rs deleted file mode 100644 index 4c11ba9eef..0000000000 --- a/tests/expectations/tests/libclang-3.8/mangling-win32.rs +++ /dev/null @@ -1,56 +0,0 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -extern "C" { - pub fn foo(); -} -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct Foo { - pub _address: u8, -} -extern "C" { - #[link_name = "\u{1}?sBar@Foo@@2_NA"] - pub static mut Foo_sBar: bool; -} -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) - ); -} -extern "C" { - #[link_name = "\u{1}@fast_call_func_no_args@0"] - pub fn fast_call_func_no_args() -> ::std::os::raw::c_int; -} -extern "C" { - #[link_name = "\u{1}@fast_call_func_many_args@12"] - pub fn fast_call_func_many_args( - arg1: ::std::os::raw::c_int, - arg2: ::std::os::raw::c_int, - arg3: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int; -} -extern "C" { - #[link_name = "\u{1}_std_call_func_no_args@0"] - pub fn std_call_func_no_args() -> ::std::os::raw::c_int; -} -extern "C" { - #[link_name = "\u{1}_std_call_func_many_args@12"] - pub fn std_call_func_many_args( - arg1: ::std::os::raw::c_int, - arg2: ::std::os::raw::c_int, - arg3: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int; -} diff --git a/tests/expectations/tests/libclang-3.8/objc_inheritance.rs b/tests/expectations/tests/libclang-3.8/objc_inheritance.rs deleted file mode 100644 index cd2b085dc3..0000000000 --- a/tests/expectations/tests/libclang-3.8/objc_inheritance.rs +++ /dev/null @@ -1,66 +0,0 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] -#![cfg(target_os = "macos")] - -#[macro_use] -extern crate objc; -#[allow(non_camel_case_types)] -pub type id = *mut objc::runtime::Object; -#[repr(transparent)] -#[derive(Clone, Copy)] -pub struct Foo(pub id); -impl std::ops::Deref for Foo { - type Target = objc::runtime::Object; - fn deref(&self) -> &Self::Target { - unsafe { &*self.0 } - } -} -unsafe impl objc::Message for Foo {} -impl Foo { - pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Foo), alloc) }) - } -} -impl IFoo for Foo {} -pub trait IFoo: Sized + std::ops::Deref {} -#[repr(transparent)] -#[derive(Clone, Copy)] -pub struct Bar(pub id); -impl std::ops::Deref for Bar { - type Target = objc::runtime::Object; - fn deref(&self) -> &Self::Target { - unsafe { &*self.0 } - } -} -unsafe impl objc::Message for Bar {} -impl Bar { - pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Bar), alloc) }) - } -} -impl IFoo for Bar {} -impl IBar for Bar {} -pub trait IBar: Sized + std::ops::Deref {} -#[repr(transparent)] -#[derive(Clone, Copy)] -pub struct Baz(pub id); -impl std::ops::Deref for Baz { - type Target = objc::runtime::Object; - fn deref(&self) -> &Self::Target { - unsafe { &*self.0 } - } -} -unsafe impl objc::Message for Baz {} -impl Baz { - pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Baz), alloc) }) - } -} -impl IBar for Baz {} -impl IFoo for Baz {} -impl IBaz for Baz {} -pub trait IBaz: Sized + std::ops::Deref {} diff --git a/tests/expectations/tests/libclang-3.8/objc_template.rs b/tests/expectations/tests/libclang-3.8/objc_template.rs deleted file mode 100644 index 9c5a5b75a2..0000000000 --- a/tests/expectations/tests/libclang-3.8/objc_template.rs +++ /dev/null @@ -1,65 +0,0 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] -#![cfg(target_os = "macos")] - -#[macro_use] -extern crate objc; -#[allow(non_camel_case_types)] -pub type id = *mut objc::runtime::Object; -#[repr(transparent)] -#[derive(Clone, Copy)] -pub struct Foo(pub id); -impl std::ops::Deref for Foo { - type Target = objc::runtime::Object; - fn deref(&self) -> &Self::Target { - unsafe { &*self.0 } - } -} -unsafe impl objc::Message for Foo {} -impl Foo { - pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Foo), alloc) }) - } -} -impl IFoo for Foo {} -pub trait IFoo: Sized + std::ops::Deref { - unsafe fn get(self) -> id - where - ::Target: objc::Message + Sized, - { - msg_send!(self, get) - } -} -#[repr(transparent)] -#[derive(Clone, Copy)] -pub struct FooMultiGeneric(pub id); -impl std::ops::Deref for FooMultiGeneric { - type Target = objc::runtime::Object; - fn deref(&self) -> &Self::Target { - unsafe { &*self.0 } - } -} -unsafe impl objc::Message for FooMultiGeneric {} -impl FooMultiGeneric { - pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(FooMultiGeneric), alloc) }) - } -} -impl - IFooMultiGeneric for FooMultiGeneric -{ -} -pub trait IFooMultiGeneric: - Sized + std::ops::Deref -{ - unsafe fn objectForKey_(self, key: id) -> id - where - ::Target: objc::Message + Sized, - { - msg_send!(self, objectForKey: key) - } -} diff --git a/tests/expectations/tests/libclang-3.8/partial-specialization-and-inheritance.rs b/tests/expectations/tests/libclang-3.8/partial-specialization-and-inheritance.rs deleted file mode 100644 index b68610e1d9..0000000000 --- a/tests/expectations/tests/libclang-3.8/partial-specialization-and-inheritance.rs +++ /dev/null @@ -1,51 +0,0 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct Base { - pub _address: u8, -} -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct Derived { - pub b: bool, -} -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct Usage { - pub _address: u8, -} -extern "C" { - #[link_name = "\u{1}_ZN5Usage13static_memberE"] - pub static mut Usage_static_member: [u32; 2usize]; -} -#[test] -fn bindgen_test_layout_Usage() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Usage)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Usage)) - ); -} -extern "C" { - #[link_name = "\u{1}_ZN5UsageC1Ev"] - pub fn Usage_Usage(this: *mut Usage); -} -impl Usage { - #[inline] - pub unsafe fn new() -> Self { - let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); - Usage_Usage(__bindgen_tmp.as_mut_ptr()); - __bindgen_tmp.assume_init() - } -} diff --git a/tests/expectations/tests/libclang-3.8/type_alias_template_specialized.rs b/tests/expectations/tests/libclang-3.8/type_alias_template_specialized.rs deleted file mode 100644 index 67e1c5aeb3..0000000000 --- a/tests/expectations/tests/libclang-3.8/type_alias_template_specialized.rs +++ /dev/null @@ -1,37 +0,0 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct Rooted { - pub ptr: ::std::os::raw::c_int, -} -#[test] -fn bindgen_test_layout_Rooted() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Rooted)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Rooted)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).ptr as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Rooted), - "::", - stringify!(ptr) - ) - ); -} -///
-pub type MaybeWrapped
= a; diff --git a/tests/stylo_sanity.rs b/tests/stylo_sanity.rs index 3f59275c04..88d87adbf2 100755 --- a/tests/stylo_sanity.rs +++ b/tests/stylo_sanity.rs @@ -14,11 +14,7 @@ extern crate bindgen; /// how long bindings generation takes for Stylo. Stylo bindings generation /// takes too long to be a proper `#[bench]`. #[test] -#[cfg(not(any( - debug_assertions, - feature = "testing_only_extra_assertions", - feature = "testing_only_libclang_3_8" -)))] +#[cfg(not(any(debug_assertions, feature = "testing_only_extra_assertions",)))] #[cfg(any( feature = "testing_only_libclang_3_9", feature = "testing_only_libclang_4", diff --git a/tests/tests.rs b/tests/tests.rs index 4cf39460e3..f8419b53f2 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -144,8 +144,6 @@ fn compare_generated_header( expectation.push("libclang-4"); } else if cfg!(feature = "testing_only_libclang_3_9") { expectation.push("libclang-3.9"); - } else if cfg!(feature = "testing_only_libclang_3_8") { - expectation.push("libclang-3.8"); } else { match clang_version().parsed { None => {} From 3e2566d6a76a25da6ac25a99ca30f8c8b45350c8 Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Sun, 21 Jun 2020 17:30:32 -0700 Subject: [PATCH 052/942] Remove obsoleted `is_loaded` checks It is not clear what version of libclang these supported. Refer to #1321, #1304, #916, #915. --- src/clang.rs | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/src/clang.rs b/src/clang.rs index 357a6dd5f0..28fce4c3e3 100644 --- a/src/clang.rs +++ b/src/clang.rs @@ -70,11 +70,7 @@ impl Cursor { /// Get the mangled name of this cursor's referent. pub fn mangling(&self) -> String { - if clang_Cursor_getMangling::is_loaded() { - unsafe { cxstring_into_string(clang_Cursor_getMangling(self.x)) } - } else { - self.spelling() - } + unsafe { cxstring_into_string(clang_Cursor_getMangling(self.x)) } } /// Gets the C++ manglings for this cursor, or an error if the manglings @@ -632,10 +628,6 @@ impl Cursor { /// Get the offset of the field represented by the Cursor. pub fn offset_of_field(&self) -> Result { - if !clang_Cursor_getOffsetOfField::is_loaded() { - return Err(LayoutError::from(-1)); - } - let offset = unsafe { clang_Cursor_getOffsetOfField(self.x) }; if offset < 0 { @@ -1102,13 +1094,6 @@ impl Type { /// Get the number of template arguments this type has, or `None` if it is /// not some kind of template. pub fn num_template_args(&self) -> Option { - // If an old libclang is loaded, we have no hope of answering this - // question correctly. However, that's no reason to panic when - // generating bindings for simple C headers with an old libclang. - if !clang_Type_getNumTemplateArguments::is_loaded() { - return None; - } - let n = unsafe { clang_Type_getNumTemplateArguments(self.x) }; if n >= 0 { Some(n as u32) @@ -1848,11 +1833,7 @@ pub fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult { format!(" {}spelling = \"{}\"", prefix, ty.spelling()), ); let num_template_args = - if clang_Type_getNumTemplateArguments::is_loaded() { - unsafe { clang_Type_getNumTemplateArguments(ty.x) } - } else { - -1 - }; + unsafe { clang_Type_getNumTemplateArguments(ty.x) }; if num_template_args >= 0 { print_indent( depth, From 94bce1610a649d80016b6a3443e38eb7d45c387e Mon Sep 17 00:00:00 2001 From: leo60228 Date: Tue, 21 Jul 2020 09:30:01 -0400 Subject: [PATCH 053/942] Change non-fatal errors to warnings --- src/clang.rs | 2 +- src/codegen/mod.rs | 4 ++-- src/codegen/struct_layout.rs | 2 +- src/ir/context.rs | 6 +++--- src/ir/item.rs | 2 +- src/ir/ty.rs | 4 ++-- src/regex_set.rs | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/clang.rs b/src/clang.rs index 28fce4c3e3..1e6728ccc3 100644 --- a/src/clang.rs +++ b/src/clang.rs @@ -796,7 +796,7 @@ impl ClangToken { // expressions, so we strip them down here. CXToken_Comment => return None, _ => { - error!("Found unexpected token kind: {:?}", self); + warn!("Found unexpected token kind: {:?}", self); return None; } }; diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 026c2ff948..c68eb6da95 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -449,7 +449,7 @@ impl CodeGenerator for Item { // TODO(emilio, #453): Figure out what to do when this happens // legitimately, we could track the opaque stuff and disable the // assertion there I guess. - error!("Found non-whitelisted item in code generation: {:?}", self); + warn!("Found non-whitelisted item in code generation: {:?}", self); } result.set_seen(self.id()); @@ -3938,7 +3938,7 @@ pub(crate) fn codegen( "Your dot file was generated successfully into: {}", path ), - Err(e) => error!("{}", e), + Err(e) => warn!("{}", e), } } diff --git a/src/codegen/struct_layout.rs b/src/codegen/struct_layout.rs index 900f258617..54dfd86efa 100644 --- a/src/codegen/struct_layout.rs +++ b/src/codegen/struct_layout.rs @@ -248,7 +248,7 @@ impl<'a> StructLayoutTracker<'a> { ); if layout.size < self.latest_offset { - error!( + warn!( "Calculated wrong layout for {}, too more {} bytes", self.name, self.latest_offset - layout.size diff --git a/src/ir/context.rs b/src/ir/context.rs index 901daa3a30..38d73b7e64 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -2400,15 +2400,15 @@ If you encounter an error missing from this list, please file an issue or a PR!" self.codegen_items = Some(codegen_items); for item in self.options().whitelisted_functions.unmatched_items() { - error!("unused option: --whitelist-function {}", item); + warn!("unused option: --whitelist-function {}", item); } for item in self.options().whitelisted_vars.unmatched_items() { - error!("unused option: --whitelist-var {}", item); + warn!("unused option: --whitelist-var {}", item); } for item in self.options().whitelisted_types.unmatched_items() { - error!("unused option: --whitelist-type {}", item); + warn!("unused option: --whitelist-type {}", item); } } diff --git a/src/ir/item.rs b/src/ir/item.rs index 8e77ad71bd..0f94f02091 100644 --- a/src/ir/item.rs +++ b/src/ir/item.rs @@ -1428,7 +1428,7 @@ impl ClangItemParser for Item { // ignore toplevel operator overloads let spelling = cursor.spelling(); if !spelling.starts_with("operator") { - error!( + warn!( "Unhandled cursor kind {:?}: {:?}", cursor.kind(), cursor diff --git a/src/ir/ty.rs b/src/ir/ty.rs index b77b5e75e9..c1560ac3f6 100644 --- a/src/ir/ty.rs +++ b/src/ir/ty.rs @@ -973,7 +973,7 @@ impl Type { let inner_type = match inner { Ok(inner) => inner, Err(..) => { - error!( + warn!( "Failed to parse template alias \ {:?}", location @@ -1196,7 +1196,7 @@ impl Type { return Err(ParseError::Continue); } _ => { - error!( + warn!( "unsupported type: kind = {:?}; ty = {:?}; at {:?}", ty.kind(), ty, diff --git a/src/regex_set.rs b/src/regex_set.rs index 4e82282457..127c001829 100644 --- a/src/regex_set.rs +++ b/src/regex_set.rs @@ -58,7 +58,7 @@ impl RegexSet { self.set = match RxSet::new(items) { Ok(x) => Some(x), Err(e) => { - error!("Invalid regex in {:?}: {:?}", self.items, e); + warn!("Invalid regex in {:?}: {:?}", self.items, e); None } } From 5e7f2e9b116cd270eb3eaad9e2f6320495e97b12 Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Sat, 20 Jun 2020 22:20:20 -0700 Subject: [PATCH 054/942] Refactor before_install script Remove needless pushd that was causing trouble with `set -e` Remove old osx workaround for rvm Add shebang line Fix target descriptor Support LLVM versions 9.0.1+ --- ci/before_install.sh | 100 ++++++++++++++++++++++++++----------------- 1 file changed, 61 insertions(+), 39 deletions(-) diff --git a/ci/before_install.sh b/ci/before_install.sh index 41b397716b..9df6743d0d 100644 --- a/ci/before_install.sh +++ b/ci/before_install.sh @@ -1,63 +1,85 @@ -set -ex -pushd ~ - -# Workaround for Travis CI macOS bug (https://github.com/travis-ci/travis-ci/issues/6307) -if [ "${TRAVIS_OS_NAME}" == "osx" ]; then - rvm get head || true -fi +#!/usr/bin/env bash +# Bail on first error +set -e +# Bail if an unset variable is encountered +set -u +# Enable debugging output +set -x +# Give a pipeline a non-zero exit code if one of its constituents fails +set -o pipefail function llvm_linux_target_triple() { - if [ "$1" == "5.0" ]; then - echo "linux-x86_64-ubuntu14.04" - else - echo "x86_64-linux-gnu-ubuntu-14.04" - fi + case "$1" in + 5.*) echo "linux-x86_64-ubuntu14.04" ;; + *) echo "x86_64-linux-gnu-ubuntu-14.04" ;; + esac +} + +function llvm_macos_target_triple() { + case "$1" in + [0-8].* | 9.0.0) echo "x86_64-darwin-apple" ;; + # Starting with 9.0.1, triple swapped ordering + *) echo "x86_64-apple-darwin" ;; + esac } function llvm_version_triple() { - if [ "$1" == "3.5" ]; then - echo "3.5.2" - elif [ "$1" == "3.6" ]; then - echo "3.6.2" - elif [ "$1" == "3.7" ]; then - echo "3.7.1" - elif [ "$1" == "3.8" ]; then - echo "3.8.1" - elif [ "$1" == "3.9" ]; then - echo "3.9.0" - elif [ "$1" == "4.0" ]; then - echo "4.0.0" - elif [ "$1" == "5.0" ]; then - echo "5.0.0" - elif [ "$1" == "9.0" ]; then - echo "9.0.0" - fi + case "$1" in + 3.5) echo "3.5.2" ;; + 3.6) echo "3.6.2" ;; + 3.7) echo "3.7.1" ;; + 3.8) echo "3.8.1" ;; + # By default, take the .0 patch release + *) echo "$1.0" ;; + esac +} + +function llvm_base_url() { + local llvm_version_triple=$1 + + case "$llvm_version_triple" in + [0-8].* | 9.0.0) + echo "http://releases.llvm.org/$llvm_version_triple" + ;; + # Starting with 9.0.1, releases are hosted on github + *) + echo "https://github.com/llvm/llvm-project/releases/download/llvmorg-$llvm_version_triple" + ;; + esac } function llvm_download() { - export LLVM_VERSION_TRIPLE=`llvm_version_triple ${LLVM_VERSION}` - export LLVM=clang+llvm-${LLVM_VERSION_TRIPLE}-$1 + local base_url=$1 + local arch=$2 + + export LLVM=clang+llvm-${LLVM_VERSION_TRIPLE}-$arch export LLVM_DIRECTORY="$HOME/.llvm/${LLVM}" + local base_url + if [ -d "${LLVM_DIRECTORY}" ]; then echo "Using cached LLVM download for ${LLVM}..." else - wget http://releases.llvm.org/${LLVM_VERSION_TRIPLE}/${LLVM}.tar.xz + wget $base_url/${LLVM}.tar.xz mkdir -p "${LLVM_DIRECTORY}" tar xf ${LLVM}.tar.xz -C "${LLVM_DIRECTORY}" --strip-components=1 fi + export LIBCLANG_PATH="${LLVM_DIRECTORY}/lib" export LLVM_CONFIG_PATH="${LLVM_DIRECTORY}/bin/llvm-config" } +export LLVM_VERSION_TRIPLE=`llvm_version_triple ${LLVM_VERSION}` + +base_url=`llvm_base_url ${LLVM_VERSION_TRIPLE}` + if [ "${TRAVIS_OS_NAME}" == "linux" ]; then - llvm_download `llvm_linux_target_triple ${LLVM_VERSION}` - export LD_LIBRARY_PATH="${LLVM_DIRECTORY}/lib":$LD_LIBRARY_PATH + llvm_download $base_url `llvm_linux_target_triple ${LLVM_VERSION_TRIPLE}` + export LD_LIBRARY_PATH="${LLVM_DIRECTORY}/lib":${LD_LIBRARY_PATH:-} else - llvm_download x86_64-apple-darwin - cp "${LLVM_DIRECTORY}/lib/libclang.dylib" /usr/local/lib/libclang.dylib - export DYLD_LIBRARY_PATH="${LLVM_DIRECTORY}/lib":$DYLD_LIBRARY_PATH + llvm_download $base_url `llvm_macos_target_triple ${LLVM_VERSION_TRIPLE}` + export DYLD_LIBRARY_PATH="${LLVM_DIRECTORY}/lib":${DYLD_LIBRARY_PATH:-} fi -popd -set +e +# Subsequent scripts can see the state of `set -eu`, so unset it again. +set +eu From b424c17608206166b98db0e1b7da752a1e560f54 Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Sat, 20 Jun 2020 21:58:27 -0700 Subject: [PATCH 055/942] Explicitly run four macOS jobs --- .travis.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.travis.yml b/.travis.yml index 40b028462d..e7edd1cd10 100644 --- a/.travis.yml +++ b/.travis.yml @@ -65,6 +65,18 @@ env: matrix: fast_finish: true + # Include a few jobs for spot-checking different configurations without + # invoking combinatoric explosion of Travis jobs. + include: + - os: osx + env: LLVM_VERSION="9.0" BINDGEN_JOB="test" BINDGEN_PROFILE= + - os: osx + env: LLVM_VERSION="9.0" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" + - os: osx + env: LLVM_VERSION="9.0" BINDGEN_JOB="integration" BINDGEN_PROFILE= + - os: osx + env: LLVM_VERSION="9.0" BINDGEN_JOB="integration" BINDGEN_PROFILE="--release" + cache: directories: - $HOME/.cargo From 5678a142bce46de782d392f348bdc3541216e606 Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Sun, 26 Jul 2020 20:15:04 -0700 Subject: [PATCH 056/942] ci: Use llvm-5.0.1 to simplify target triple --- ci/before_install.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ci/before_install.sh b/ci/before_install.sh index 9df6743d0d..4e2da4612d 100644 --- a/ci/before_install.sh +++ b/ci/before_install.sh @@ -9,10 +9,7 @@ set -x set -o pipefail function llvm_linux_target_triple() { - case "$1" in - 5.*) echo "linux-x86_64-ubuntu14.04" ;; - *) echo "x86_64-linux-gnu-ubuntu-14.04" ;; - esac + echo "x86_64-linux-gnu-ubuntu-14.04" } function llvm_macos_target_triple() { @@ -29,6 +26,7 @@ function llvm_version_triple() { 3.6) echo "3.6.2" ;; 3.7) echo "3.7.1" ;; 3.8) echo "3.8.1" ;; + 5.0) echo "5.0.1" ;; # By default, take the .0 patch release *) echo "$1.0" ;; esac From ed3ae0fcf60554ad3840ff5ec6970127622a2ca4 Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Fri, 31 Jul 2020 17:04:46 -0700 Subject: [PATCH 057/942] ci: Remove overrides for unsupported LLVM versions --- ci/before_install.sh | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ci/before_install.sh b/ci/before_install.sh index 4e2da4612d..57927cf65b 100644 --- a/ci/before_install.sh +++ b/ci/before_install.sh @@ -22,10 +22,6 @@ function llvm_macos_target_triple() { function llvm_version_triple() { case "$1" in - 3.5) echo "3.5.2" ;; - 3.6) echo "3.6.2" ;; - 3.7) echo "3.7.1" ;; - 3.8) echo "3.8.1" ;; 5.0) echo "5.0.1" ;; # By default, take the .0 patch release *) echo "$1.0" ;; From 5a638c0a11500e1e38fc9ab6dd4f5dab6681b4d4 Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Fri, 31 Jul 2020 17:06:42 -0700 Subject: [PATCH 058/942] ci: Explicitly select Ubuntu 16.04 (xenial) Xenial was being used anyway, but it is wise to be explicit. This lets us download a newer precompiled LLVM, too. --- .travis.yml | 2 ++ ci/before_install.sh | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e7edd1cd10..c44aaa05cd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,7 @@ language: rust +dist: xenial + os: - linux diff --git a/ci/before_install.sh b/ci/before_install.sh index 57927cf65b..d5edde9444 100644 --- a/ci/before_install.sh +++ b/ci/before_install.sh @@ -9,7 +9,7 @@ set -x set -o pipefail function llvm_linux_target_triple() { - echo "x86_64-linux-gnu-ubuntu-14.04" + echo "x86_64-linux-gnu-ubuntu-16.04" } function llvm_macos_target_triple() { From 1f1766de4354bd8e4c7ff810e3abd6ceddb28b6b Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Sun, 2 Aug 2020 14:09:33 -0700 Subject: [PATCH 059/942] ci: Remove extraneous variable declaration --- ci/before_install.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/ci/before_install.sh b/ci/before_install.sh index d5edde9444..2e66ae4e74 100644 --- a/ci/before_install.sh +++ b/ci/before_install.sh @@ -49,8 +49,6 @@ function llvm_download() { export LLVM=clang+llvm-${LLVM_VERSION_TRIPLE}-$arch export LLVM_DIRECTORY="$HOME/.llvm/${LLVM}" - local base_url - if [ -d "${LLVM_DIRECTORY}" ]; then echo "Using cached LLVM download for ${LLVM}..." else From f56fbcef788098155a10ef455284e218fe15bc7a Mon Sep 17 00:00:00 2001 From: Cameron Mulhern Date: Tue, 28 Jul 2020 17:17:10 -0400 Subject: [PATCH 060/942] Improves bindings for typed and anonymous enums --- src/clang.rs | 14 ++++- src/codegen/mod.rs | 54 ++++++++++++++----- src/ir/enum_ty.rs | 27 ++++++---- .../expectations/tests/bitfield-enum-basic.rs | 8 +-- .../tests/bitfield-enum-repr-c.rs | 2 +- .../tests/bitfield-enum-repr-transparent.rs | 2 +- .../expectations/tests/constify-all-enums.rs | 2 +- .../tests/constify-module-enums-basic.rs | 2 +- .../tests/constify-module-enums-namespace.rs | 2 +- .../constify-module-enums-shadow-name.rs | 2 +- .../constify-module-enums-simple-alias.rs | 2 +- ...onstify-module-enums-simple-nonamespace.rs | 2 +- .../tests/constify-module-enums-types.rs | 10 ++-- .../default-enum-style-constified-module.rs | 2 +- tests/expectations/tests/empty-enum.rs | 12 ++--- .../tests/enum-default-bitfield.rs | 4 +- .../expectations/tests/enum-default-consts.rs | 4 +- .../expectations/tests/enum-default-module.rs | 4 +- tests/expectations/tests/enum-default-rust.rs | 2 +- tests/expectations/tests/enum-doc-bitfield.rs | 2 +- tests/expectations/tests/enum-doc-mod.rs | 2 +- tests/expectations/tests/enum-doc.rs | 2 +- tests/expectations/tests/enum-undefault.rs | 2 +- .../tests/enum-variant-replaces.rs | 2 +- .../expectations/tests/enum_explicit_type.rs | 10 ++++ .../tests/enum_explicit_type_constants.rs | 18 ++++--- .../tests/issue-1025-unknown-enum-repr.rs | 1 - .../issue-1198-alias-rust-bitfield-enum.rs | 4 +- ...1198-alias-rust-const-mod-bitfield-enum.rs | 4 +- .../issue-1198-alias-rust-const-mod-enum.rs | 4 +- tests/expectations/tests/issue-1435.rs | 2 +- .../tests/issue-1488-enum-new-type.rs | 6 +-- .../issue-1599-opaque-typedef-to-enum.rs | 2 +- tests/expectations/tests/newtype-enum.rs | 2 +- tests/expectations/tests/prepend_enum_name.rs | 2 +- tests/expectations/tests/transform-op.rs | 2 +- tests/headers/enum_explicit_type.hpp | 5 ++ 37 files changed, 147 insertions(+), 82 deletions(-) diff --git a/src/clang.rs b/src/clang.rs index 1e6728ccc3..488660c434 100644 --- a/src/clang.rs +++ b/src/clang.rs @@ -3,7 +3,6 @@ #![allow(non_upper_case_globals, dead_code)] - use crate::ir::context::BindgenContext; use cexpr; use clang_sys::*; @@ -498,6 +497,19 @@ impl Cursor { } } + /// Get the boolean constant value for this cursor's enum variant referent. + /// + /// Returns None if the cursor's referent is not an enum variant. + pub fn enum_val_boolean(&self) -> Option { + unsafe { + if self.kind() == CXCursor_EnumConstantDecl { + Some(clang_getEnumConstantDeclValue(self.x) != 0) + } else { + None + } + } + } + /// Get the signed constant value for this cursor's enum variant referent. /// /// Returns None if the cursor's referent is not an enum variant. diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index c68eb6da95..20bf54c48d 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -2438,6 +2438,7 @@ enum EnumBuilder<'a> { is_bitfield: bool, }, Consts { + repr: proc_macro2::TokenStream, variants: Vec, codegen_depth: usize, }, @@ -2459,6 +2460,14 @@ impl<'a> EnumBuilder<'a> { } } + /// Returns true if the builder is for a rustified enum. + fn is_rust_enum(&self) -> bool { + match *self { + EnumBuilder::Rust { .. } => true, + _ => false, + } + } + /// Create a new enum given an item builder, a canonical name, a name for /// the representation, and which variation it should be generated as. fn new( @@ -2467,6 +2476,7 @@ impl<'a> EnumBuilder<'a> { repr: proc_macro2::TokenStream, enum_variation: EnumVariation, enum_codegen_depth: usize, + is_ty_named: bool, ) -> Self { let ident = Ident::new(name, Span::call_site()); @@ -2492,13 +2502,22 @@ impl<'a> EnumBuilder<'a> { } } - EnumVariation::Consts => EnumBuilder::Consts { - variants: vec![quote! { - #( #attrs )* - pub type #ident = #repr; - }], - codegen_depth: enum_codegen_depth, - }, + EnumVariation::Consts => { + let mut variants = Vec::new(); + + if is_ty_named { + variants.push(quote! { + #( #attrs )* + pub type #ident = #repr; + }); + } + + EnumBuilder::Consts { + repr: repr, + variants: variants, + codegen_depth: enum_codegen_depth, + } + } EnumVariation::ModuleConsts => { let ident = Ident::new( @@ -2530,7 +2549,12 @@ impl<'a> EnumBuilder<'a> { is_ty_named: bool, ) -> Self { let variant_name = ctx.rust_mangle(variant.name()); + let is_rust_enum = self.is_rust_enum(); let expr = match variant.val() { + EnumVariantValue::Boolean(v) if is_rust_enum => { + helpers::ast_ty::uint_expr(v as u64) + } + EnumVariantValue::Boolean(v) => quote!(#v), EnumVariantValue::Signed(v) => helpers::ast_ty::int_expr(v), EnumVariantValue::Unsigned(v) => helpers::ast_ty::uint_expr(v), }; @@ -2593,7 +2617,7 @@ impl<'a> EnumBuilder<'a> { self } - EnumBuilder::Consts { .. } => { + EnumBuilder::Consts { ref repr, .. } => { let constant_name = match mangling_prefix { Some(prefix) => { Cow::Owned(format!("{}_{}", prefix, variant_name)) @@ -2601,10 +2625,12 @@ impl<'a> EnumBuilder<'a> { None => variant_name, }; + let ty = if is_ty_named { &rust_ty } else { repr }; + let ident = ctx.rust_ident(constant_name); result.push(quote! { #doc - pub const #ident : #rust_ty = #expr ; + pub const #ident : #ty = #expr ; }); self @@ -2859,9 +2885,12 @@ impl CodeGenerator for Enum { }); } - let repr = { - let repr_name = ctx.rust_ident_raw(repr_name); - quote! { #repr_name } + let repr = match self.repr() { + Some(ty) => ty.to_rust_ty_or_opaque(ctx, &()), + None => { + let repr_name = ctx.rust_ident_raw(repr_name); + quote! { #repr_name } + } }; let mut builder = EnumBuilder::new( @@ -2870,6 +2899,7 @@ impl CodeGenerator for Enum { repr, variation, item.codegen_depth(ctx), + enum_ty.name().is_some(), ); // A map where we keep a value -> variant relation. diff --git a/src/ir/enum_ty.rs b/src/ir/enum_ty.rs index 89b37ae739..17996af65b 100644 --- a/src/ir/enum_ty.rs +++ b/src/ir/enum_ty.rs @@ -3,7 +3,7 @@ use super::super::codegen::EnumVariation; use super::context::{BindgenContext, TypeId}; use super::item::Item; -use super::ty::TypeKind; +use super::ty::{Type, TypeKind}; use crate::clang; use crate::ir::annotations::Annotations; use crate::ir::item::ItemCanonicalPath; @@ -69,15 +69,17 @@ impl Enum { .and_then(|et| Item::from_ty(&et, declaration, None, ctx).ok()); let mut variants = vec![]; + let variant_ty = + repr.and_then(|r| ctx.resolve_type(r).safe_canonical_type(ctx)); + let is_bool = variant_ty.map_or(false, Type::is_bool); + // Assume signedness since the default type by the C standard is an int. - let is_signed = repr - .and_then(|r| ctx.resolve_type(r).safe_canonical_type(ctx)) - .map_or(true, |ty| match *ty.kind() { - TypeKind::Int(ref int_kind) => int_kind.is_signed(), - ref other => { - panic!("Since when enums can be non-integers? {:?}", other) - } - }); + let is_signed = variant_ty.map_or(true, |ty| match *ty.kind() { + TypeKind::Int(ref int_kind) => int_kind.is_signed(), + ref other => { + panic!("Since when enums can be non-integers? {:?}", other) + } + }); let type_name = ty.spelling(); let type_name = if type_name.is_empty() { @@ -90,7 +92,9 @@ impl Enum { let definition = declaration.definition().unwrap_or(declaration); definition.visit(|cursor| { if cursor.kind() == CXCursor_EnumConstantDecl { - let value = if is_signed { + let value = if is_bool { + cursor.enum_val_boolean().map(EnumVariantValue::Boolean) + } else if is_signed { cursor.enum_val_signed().map(EnumVariantValue::Signed) } else { cursor.enum_val_unsigned().map(EnumVariantValue::Unsigned) @@ -234,6 +238,9 @@ pub struct EnumVariant { /// A constant value assigned to an enumeration variant. #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum EnumVariantValue { + /// A boolean constant. + Boolean(bool), + /// A signed constant. Signed(i64), diff --git a/tests/expectations/tests/bitfield-enum-basic.rs b/tests/expectations/tests/bitfield-enum-basic.rs index 390d8974b3..645a3f5e10 100644 --- a/tests/expectations/tests/bitfield-enum-basic.rs +++ b/tests/expectations/tests/bitfield-enum-basic.rs @@ -45,7 +45,7 @@ impl ::std::ops::BitAndAssign for Foo { } #[repr(transparent)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub struct Foo(pub i32); +pub struct Foo(pub ::std::os::raw::c_int); impl Buz { pub const Bar: Buz = Buz(2); } @@ -86,7 +86,7 @@ impl ::std::ops::BitAndAssign for Buz { } #[repr(transparent)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub struct Buz(pub i8); +pub struct Buz(pub ::std::os::raw::c_schar); pub const NS_FOO: _bindgen_ty_1 = _bindgen_ty_1(1); pub const NS_BAR: _bindgen_ty_1 = _bindgen_ty_1(2); impl ::std::ops::BitOr<_bindgen_ty_1> for _bindgen_ty_1 { @@ -117,7 +117,7 @@ impl ::std::ops::BitAndAssign for _bindgen_ty_1 { } #[repr(transparent)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub struct _bindgen_ty_1(pub u32); +pub struct _bindgen_ty_1(pub ::std::os::raw::c_uint); #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Dummy { @@ -153,7 +153,7 @@ impl ::std::ops::BitAndAssign for Dummy__bindgen_ty_1 { } #[repr(transparent)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub struct Dummy__bindgen_ty_1(pub u32); +pub struct Dummy__bindgen_ty_1(pub ::std::os::raw::c_uint); #[test] fn bindgen_test_layout_Dummy() { assert_eq!( diff --git a/tests/expectations/tests/bitfield-enum-repr-c.rs b/tests/expectations/tests/bitfield-enum-repr-c.rs index 72aaff00f9..bd9a35dcb8 100644 --- a/tests/expectations/tests/bitfield-enum-repr-c.rs +++ b/tests/expectations/tests/bitfield-enum-repr-c.rs @@ -45,4 +45,4 @@ impl ::std::ops::BitAndAssign for Foo { } #[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub struct Foo(pub i32); +pub struct Foo(pub ::std::os::raw::c_int); diff --git a/tests/expectations/tests/bitfield-enum-repr-transparent.rs b/tests/expectations/tests/bitfield-enum-repr-transparent.rs index 9b46c681e2..690f3b4770 100644 --- a/tests/expectations/tests/bitfield-enum-repr-transparent.rs +++ b/tests/expectations/tests/bitfield-enum-repr-transparent.rs @@ -45,4 +45,4 @@ impl ::std::ops::BitAndAssign for Foo { } #[repr(transparent)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub struct Foo(pub i32); +pub struct Foo(pub ::std::os::raw::c_int); diff --git a/tests/expectations/tests/constify-all-enums.rs b/tests/expectations/tests/constify-all-enums.rs index 93388c6484..3c450e623e 100644 --- a/tests/expectations/tests/constify-all-enums.rs +++ b/tests/expectations/tests/constify-all-enums.rs @@ -8,7 +8,7 @@ pub const foo_THIS: foo = 0; pub const foo_SHOULD_BE: foo = 1; pub const foo_A_CONSTANT: foo = 2; -pub type foo = u32; +pub type foo = ::std::os::raw::c_uint; #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct bar { diff --git a/tests/expectations/tests/constify-module-enums-basic.rs b/tests/expectations/tests/constify-module-enums-basic.rs index 2d08d588e5..2cbb09bdcb 100644 --- a/tests/expectations/tests/constify-module-enums-basic.rs +++ b/tests/expectations/tests/constify-module-enums-basic.rs @@ -6,7 +6,7 @@ )] pub mod foo { - pub type Type = u32; + pub type Type = ::std::os::raw::c_uint; pub const THIS: Type = 0; pub const SHOULD_BE: Type = 1; pub const A_CONSTANT: Type = 2; diff --git a/tests/expectations/tests/constify-module-enums-namespace.rs b/tests/expectations/tests/constify-module-enums-namespace.rs index b09acf7025..c18b7175ad 100644 --- a/tests/expectations/tests/constify-module-enums-namespace.rs +++ b/tests/expectations/tests/constify-module-enums-namespace.rs @@ -16,7 +16,7 @@ pub mod root { #[allow(unused_imports)] use self::super::super::super::root; pub mod foo { - pub type Type = u32; + pub type Type = ::std::os::raw::c_uint; pub const THIS: Type = 0; pub const SHOULD_BE: Type = 1; pub const A_CONSTANT: Type = 2; diff --git a/tests/expectations/tests/constify-module-enums-shadow-name.rs b/tests/expectations/tests/constify-module-enums-shadow-name.rs index ff0bc45d6c..16f13fdbe3 100644 --- a/tests/expectations/tests/constify-module-enums-shadow-name.rs +++ b/tests/expectations/tests/constify-module-enums-shadow-name.rs @@ -6,7 +6,7 @@ )] pub mod foo { - pub type Type = u32; + pub type Type = ::std::os::raw::c_uint; pub const Type: Type = 0; pub const Type_: Type = 1; pub const Type1: Type = 2; diff --git a/tests/expectations/tests/constify-module-enums-simple-alias.rs b/tests/expectations/tests/constify-module-enums-simple-alias.rs index 56de348bce..64e77c68bd 100644 --- a/tests/expectations/tests/constify-module-enums-simple-alias.rs +++ b/tests/expectations/tests/constify-module-enums-simple-alias.rs @@ -6,7 +6,7 @@ )] pub mod Foo { - pub type Type = i32; + pub type Type = ::std::os::raw::c_int; pub const Variant1: Type = 0; pub const Variant2: Type = 1; pub const Variant3: Type = 2; diff --git a/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs b/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs index fc6475df65..3a95b3c912 100644 --- a/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs +++ b/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs @@ -6,7 +6,7 @@ )] pub mod one_Foo { - pub type Type = i32; + pub type Type = ::std::os::raw::c_int; pub const Variant1: Type = 0; pub const Variant2: Type = 1; } diff --git a/tests/expectations/tests/constify-module-enums-types.rs b/tests/expectations/tests/constify-module-enums-types.rs index 453796fa8b..4ba85b37d5 100644 --- a/tests/expectations/tests/constify-module-enums-types.rs +++ b/tests/expectations/tests/constify-module-enums-types.rs @@ -6,7 +6,7 @@ )] pub mod foo { - pub type Type = u32; + pub type Type = ::std::os::raw::c_uint; pub const THIS: Type = 0; pub const SHOULD_BE: Type = 1; pub const A_CONSTANT: Type = 2; @@ -14,20 +14,20 @@ pub mod foo { pub const AND_ALSO_THIS: Type = 42; } pub mod anon_enum { - pub type Type = u32; + pub type Type = ::std::os::raw::c_uint; pub const Variant1: Type = 0; pub const Variant2: Type = 1; pub const Variant3: Type = 2; } pub mod ns1_foo { - pub type Type = u32; + pub type Type = ::std::os::raw::c_uint; pub const THIS: Type = 0; pub const SHOULD_BE: Type = 1; pub const A_CONSTANT: Type = 2; pub const ALSO_THIS: Type = 42; } pub mod ns2_Foo { - pub type Type = i32; + pub type Type = ::std::os::raw::c_int; pub const Variant1: Type = 0; pub const Variant2: Type = 1; } @@ -205,7 +205,7 @@ impl Default for Baz { } } pub mod one_Foo { - pub type Type = i32; + pub type Type = ::std::os::raw::c_int; pub const Variant1: Type = 0; pub const Variant2: Type = 1; } diff --git a/tests/expectations/tests/default-enum-style-constified-module.rs b/tests/expectations/tests/default-enum-style-constified-module.rs index 1ad803523a..5e225e3db6 100644 --- a/tests/expectations/tests/default-enum-style-constified-module.rs +++ b/tests/expectations/tests/default-enum-style-constified-module.rs @@ -6,7 +6,7 @@ )] pub mod Foo { - pub type Type = u32; + pub type Type = ::std::os::raw::c_uint; pub const bar: Type = 0; pub const baz: Type = 1; pub const blap: Type = 2; diff --git a/tests/expectations/tests/empty-enum.rs b/tests/expectations/tests/empty-enum.rs index 5cf787cb15..bdf6b9e6d1 100644 --- a/tests/expectations/tests/empty-enum.rs +++ b/tests/expectations/tests/empty-enum.rs @@ -5,30 +5,30 @@ non_upper_case_globals )] -pub type EmptyConstified = u32; +pub type EmptyConstified = ::std::os::raw::c_uint; #[repr(u32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum EmptyRustified { __bindgen_cannot_repr_c_on_empty_enum = 0, } pub mod EmptyModule { - pub type Type = u32; + pub type Type = ::std::os::raw::c_uint; } #[repr(i8)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum EmptyClassRustified { __bindgen_cannot_repr_c_on_empty_enum = 0, } -pub type EmptyClassConstified = i8; +pub type EmptyClassConstified = ::std::os::raw::c_char; pub mod EmptyClassModule { - pub type Type = i8; + pub type Type = ::std::os::raw::c_char; } #[repr(i8)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum ForwardClassRustified { __bindgen_cannot_repr_c_on_empty_enum = 0, } -pub type ForwardClassConstified = i8; +pub type ForwardClassConstified = ::std::os::raw::c_char; pub mod ForwardClassModule { - pub type Type = i8; + pub type Type = ::std::os::raw::c_char; } diff --git a/tests/expectations/tests/enum-default-bitfield.rs b/tests/expectations/tests/enum-default-bitfield.rs index fa6f77636b..ebf5caa462 100644 --- a/tests/expectations/tests/enum-default-bitfield.rs +++ b/tests/expectations/tests/enum-default-bitfield.rs @@ -39,9 +39,9 @@ impl ::std::ops::BitAndAssign for Foo { } #[repr(transparent)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub struct Foo(pub u32); +pub struct Foo(pub ::std::os::raw::c_uint); pub mod Neg { - pub type Type = i32; + pub type Type = ::std::os::raw::c_int; pub const MinusOne: Type = -1; pub const One: Type = 1; } diff --git a/tests/expectations/tests/enum-default-consts.rs b/tests/expectations/tests/enum-default-consts.rs index 4973d7c86c..ab49663063 100644 --- a/tests/expectations/tests/enum-default-consts.rs +++ b/tests/expectations/tests/enum-default-consts.rs @@ -7,9 +7,9 @@ pub const Foo_Bar: Foo = 0; pub const Foo_Qux: Foo = 1; -pub type Foo = u32; +pub type Foo = ::std::os::raw::c_uint; pub mod Neg { - pub type Type = i32; + pub type Type = ::std::os::raw::c_int; pub const MinusOne: Type = -1; pub const One: Type = 1; } diff --git a/tests/expectations/tests/enum-default-module.rs b/tests/expectations/tests/enum-default-module.rs index a3db9afacb..a81e6ad023 100644 --- a/tests/expectations/tests/enum-default-module.rs +++ b/tests/expectations/tests/enum-default-module.rs @@ -6,12 +6,12 @@ )] pub mod Foo { - pub type Type = u32; + pub type Type = ::std::os::raw::c_uint; pub const Bar: Type = 0; pub const Qux: Type = 1; } pub mod Neg { - pub type Type = i32; + pub type Type = ::std::os::raw::c_int; pub const MinusOne: Type = -1; pub const One: Type = 1; } diff --git a/tests/expectations/tests/enum-default-rust.rs b/tests/expectations/tests/enum-default-rust.rs index f1d9c7a1ea..b497a5a3f2 100644 --- a/tests/expectations/tests/enum-default-rust.rs +++ b/tests/expectations/tests/enum-default-rust.rs @@ -12,7 +12,7 @@ pub enum Foo { Qux = 1, } pub mod Neg { - pub type Type = i32; + pub type Type = ::std::os::raw::c_int; pub const MinusOne: Type = -1; pub const One: Type = 1; } diff --git a/tests/expectations/tests/enum-doc-bitfield.rs b/tests/expectations/tests/enum-doc-bitfield.rs index 817ef3a34b..02a3adaab9 100644 --- a/tests/expectations/tests/enum-doc-bitfield.rs +++ b/tests/expectations/tests/enum-doc-bitfield.rs @@ -61,4 +61,4 @@ impl ::std::ops::BitAndAssign for B { #[repr(transparent)] /// Document enum #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub struct B(pub u32); +pub struct B(pub ::std::os::raw::c_uint); diff --git a/tests/expectations/tests/enum-doc-mod.rs b/tests/expectations/tests/enum-doc-mod.rs index 6dc60c570e..60d6b9f4d9 100644 --- a/tests/expectations/tests/enum-doc-mod.rs +++ b/tests/expectations/tests/enum-doc-mod.rs @@ -7,7 +7,7 @@ pub mod B { /// Document enum - pub type Type = u32; + pub type Type = ::std::os::raw::c_uint; /// Document field with three slashes pub const VAR_A: Type = 0; /// Document field with preceeding star diff --git a/tests/expectations/tests/enum-doc.rs b/tests/expectations/tests/enum-doc.rs index b58fb283e2..b5d14b3cf0 100644 --- a/tests/expectations/tests/enum-doc.rs +++ b/tests/expectations/tests/enum-doc.rs @@ -21,4 +21,4 @@ pub const B_VAR_E: B = 4; /// Very interesting documentation, definitely. pub const B_VAR_F: B = 5; /// Document enum -pub type B = u32; +pub type B = ::std::os::raw::c_uint; diff --git a/tests/expectations/tests/enum-undefault.rs b/tests/expectations/tests/enum-undefault.rs index b865c82001..7bb3169375 100644 --- a/tests/expectations/tests/enum-undefault.rs +++ b/tests/expectations/tests/enum-undefault.rs @@ -13,4 +13,4 @@ pub enum Foo { } pub const Neg_MinusOne: Neg = -1; pub const Neg_One: Neg = 1; -pub type Neg = i32; +pub type Neg = ::std::os::raw::c_int; diff --git a/tests/expectations/tests/enum-variant-replaces.rs b/tests/expectations/tests/enum-variant-replaces.rs index b5f629db83..d927657492 100644 --- a/tests/expectations/tests/enum-variant-replaces.rs +++ b/tests/expectations/tests/enum-variant-replaces.rs @@ -14,4 +14,4 @@ pub const OGRErr_PASS: OGRErr = 0; /// Should see OGRERR_NONE instead of CUSTOM_OGRERR_NONE below. pub const OGRErr_OGRERR_NONE: OGRErr = 1; ///
-pub type OGRErr = u32; +pub type OGRErr = ::std::os::raw::c_uint; diff --git a/tests/expectations/tests/enum_explicit_type.rs b/tests/expectations/tests/enum_explicit_type.rs index 2f44c0b248..3da645d23f 100644 --- a/tests/expectations/tests/enum_explicit_type.rs +++ b/tests/expectations/tests/enum_explicit_type.rs @@ -43,3 +43,13 @@ pub enum MuchULongLong { pub enum BoolEnumsAreFun { Value = 1, } +pub const AnonymousVariantOne: _bindgen_ty_1 = + _bindgen_ty_1::AnonymousVariantOne; +pub const AnonymousVariantTwo: _bindgen_ty_1 = + _bindgen_ty_1::AnonymousVariantTwo; +#[repr(u8)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +pub enum _bindgen_ty_1 { + AnonymousVariantOne = 0, + AnonymousVariantTwo = 1, +} diff --git a/tests/expectations/tests/enum_explicit_type_constants.rs b/tests/expectations/tests/enum_explicit_type_constants.rs index 2454b39ca3..9e198575f8 100644 --- a/tests/expectations/tests/enum_explicit_type_constants.rs +++ b/tests/expectations/tests/enum_explicit_type_constants.rs @@ -7,18 +7,20 @@ pub const Foo_Bar: Foo = 0; pub const Foo_Qux: Foo = 1; -pub type Foo = u8; +pub type Foo = ::std::os::raw::c_uchar; pub const Neg_MinusOne: Neg = -1; pub const Neg_One: Neg = 1; -pub type Neg = i8; +pub type Neg = ::std::os::raw::c_schar; pub const Bigger_Much: Bigger = 255; pub const Bigger_Larger: Bigger = 256; -pub type Bigger = u16; +pub type Bigger = ::std::os::raw::c_ushort; pub const MuchLong_MuchLow: MuchLong = -4294967296; -pub type MuchLong = i64; +pub type MuchLong = ::std::os::raw::c_long; pub const MuchLongLong_I64_MIN: MuchLongLong = -9223372036854775808; -pub type MuchLongLong = i64; +pub type MuchLongLong = ::std::os::raw::c_longlong; pub const MuchULongLong_MuchHigh: MuchULongLong = 4294967296; -pub type MuchULongLong = u64; -pub const BoolEnumsAreFun_Value: BoolEnumsAreFun = 1; -pub type BoolEnumsAreFun = u8; +pub type MuchULongLong = ::std::os::raw::c_ulonglong; +pub const BoolEnumsAreFun_Value: BoolEnumsAreFun = true; +pub type BoolEnumsAreFun = bool; +pub const AnonymousVariantOne: ::std::os::raw::c_uchar = 0; +pub const AnonymousVariantTwo: ::std::os::raw::c_uchar = 1; diff --git a/tests/expectations/tests/issue-1025-unknown-enum-repr.rs b/tests/expectations/tests/issue-1025-unknown-enum-repr.rs index c42e167fba..1516c0a95e 100644 --- a/tests/expectations/tests/issue-1025-unknown-enum-repr.rs +++ b/tests/expectations/tests/issue-1025-unknown-enum-repr.rs @@ -10,4 +10,3 @@ pub struct a { pub _address: u8, } -pub type a__bindgen_ty_1 = i32; diff --git a/tests/expectations/tests/issue-1198-alias-rust-bitfield-enum.rs b/tests/expectations/tests/issue-1198-alias-rust-bitfield-enum.rs index 95f6cd5a14..8ef4c498fb 100644 --- a/tests/expectations/tests/issue-1198-alias-rust-bitfield-enum.rs +++ b/tests/expectations/tests/issue-1198-alias-rust-bitfield-enum.rs @@ -42,7 +42,7 @@ impl ::std::ops::BitAndAssign for MyDupeEnum { } #[repr(transparent)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub struct MyDupeEnum(pub u32); +pub struct MyDupeEnum(pub ::std::os::raw::c_uint); impl MyOtherDupeEnum { pub const C: MyOtherDupeEnum = MyOtherDupeEnum(0); } @@ -80,4 +80,4 @@ impl ::std::ops::BitAndAssign for MyOtherDupeEnum { } #[repr(transparent)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub struct MyOtherDupeEnum(pub u32); +pub struct MyOtherDupeEnum(pub ::std::os::raw::c_uint); diff --git a/tests/expectations/tests/issue-1198-alias-rust-const-mod-bitfield-enum.rs b/tests/expectations/tests/issue-1198-alias-rust-const-mod-bitfield-enum.rs index f4997aa2c2..81c74abbf0 100644 --- a/tests/expectations/tests/issue-1198-alias-rust-const-mod-bitfield-enum.rs +++ b/tests/expectations/tests/issue-1198-alias-rust-const-mod-bitfield-enum.rs @@ -6,13 +6,13 @@ )] pub mod MyDupeEnum { - pub type Type = u32; + pub type Type = ::std::os::raw::c_uint; pub const A: Type = 0; pub const A_alias: Type = 0; pub const B: Type = 1; } pub mod MyOtherDupeEnum { - pub type Type = u32; + pub type Type = ::std::os::raw::c_uint; pub const C: Type = 0; pub const C_alias: Type = 0; pub const D: Type = 1; diff --git a/tests/expectations/tests/issue-1198-alias-rust-const-mod-enum.rs b/tests/expectations/tests/issue-1198-alias-rust-const-mod-enum.rs index f4997aa2c2..81c74abbf0 100644 --- a/tests/expectations/tests/issue-1198-alias-rust-const-mod-enum.rs +++ b/tests/expectations/tests/issue-1198-alias-rust-const-mod-enum.rs @@ -6,13 +6,13 @@ )] pub mod MyDupeEnum { - pub type Type = u32; + pub type Type = ::std::os::raw::c_uint; pub const A: Type = 0; pub const A_alias: Type = 0; pub const B: Type = 1; } pub mod MyOtherDupeEnum { - pub type Type = u32; + pub type Type = ::std::os::raw::c_uint; pub const C: Type = 0; pub const C_alias: Type = 0; pub const D: Type = 1; diff --git a/tests/expectations/tests/issue-1435.rs b/tests/expectations/tests/issue-1435.rs index af602ebbe9..79ed7b294b 100644 --- a/tests/expectations/tests/issue-1435.rs +++ b/tests/expectations/tests/issue-1435.rs @@ -14,7 +14,7 @@ pub mod root { use self::super::super::root; pub const AB_A: root::ns::AB = 0; pub const AB_B: root::ns::AB = 1; - pub type AB = i32; + pub type AB = ::std::os::raw::c_int; } pub use self::super::root::ns::AB; extern "C" { diff --git a/tests/expectations/tests/issue-1488-enum-new-type.rs b/tests/expectations/tests/issue-1488-enum-new-type.rs index 018cea67df..c61b93ba5c 100644 --- a/tests/expectations/tests/issue-1488-enum-new-type.rs +++ b/tests/expectations/tests/issue-1488-enum-new-type.rs @@ -7,12 +7,12 @@ pub const Foo_A: Foo = 0; pub const Foo_B: Foo = 1; -pub type Foo = u32; +pub type Foo = ::std::os::raw::c_uint; #[repr(transparent)] #[derive(Debug, Copy, Clone)] pub struct FooAlias(pub Foo); pub mod Bar { - pub type Type = u32; + pub type Type = ::std::os::raw::c_uint; pub const C: Type = 0; pub const D: Type = 1; } @@ -30,7 +30,7 @@ pub enum Qux { pub struct QuxAlias(pub Qux); pub const Baz_G: Baz = 0; pub const Baz_H: Baz = 1; -pub type Baz = u32; +pub type Baz = ::std::os::raw::c_uint; #[repr(transparent)] #[derive(Debug, Copy, Clone)] pub struct BazAlias(pub Baz); diff --git a/tests/expectations/tests/issue-1599-opaque-typedef-to-enum.rs b/tests/expectations/tests/issue-1599-opaque-typedef-to-enum.rs index 27a28bfead..eacb34111c 100644 --- a/tests/expectations/tests/issue-1599-opaque-typedef-to-enum.rs +++ b/tests/expectations/tests/issue-1599-opaque-typedef-to-enum.rs @@ -7,5 +7,5 @@ pub const a_b: a = 0; pub const a_c: a = 1; -pub type a = u32; +pub type a = ::std::os::raw::c_uint; pub type d = u32; diff --git a/tests/expectations/tests/newtype-enum.rs b/tests/expectations/tests/newtype-enum.rs index a7b811081d..4d9cc7e159 100644 --- a/tests/expectations/tests/newtype-enum.rs +++ b/tests/expectations/tests/newtype-enum.rs @@ -19,4 +19,4 @@ impl Foo { } #[repr(transparent)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub struct Foo(pub i32); +pub struct Foo(pub ::std::os::raw::c_int); diff --git a/tests/expectations/tests/prepend_enum_name.rs b/tests/expectations/tests/prepend_enum_name.rs index ac0a755afd..31db41444c 100644 --- a/tests/expectations/tests/prepend_enum_name.rs +++ b/tests/expectations/tests/prepend_enum_name.rs @@ -7,4 +7,4 @@ pub const FOO_BAR: foo = 0; pub const FOO_BAZ: foo = 1; -pub type foo = u32; +pub type foo = ::std::os::raw::c_uint; diff --git a/tests/expectations/tests/transform-op.rs b/tests/expectations/tests/transform-op.rs index 169768fc41..64c588d84c 100644 --- a/tests/expectations/tests/transform-op.rs +++ b/tests/expectations/tests/transform-op.rs @@ -134,7 +134,7 @@ pub const StyleBar_Tag_Bar1: StyleBar_Tag = 0; pub const StyleBar_Tag_Bar2: StyleBar_Tag = 0; pub const StyleBar_Tag_Bar3: StyleBar_Tag = 0; pub const StyleBar_Tag_Bar4: StyleBar_Tag = 0; -pub type StyleBar_Tag = i32; +pub type StyleBar_Tag = ::std::os::raw::c_int; #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct StyleBar_StyleBar1_Body { diff --git a/tests/headers/enum_explicit_type.hpp b/tests/headers/enum_explicit_type.hpp index d97134716d..b0f51c71fd 100644 --- a/tests/headers/enum_explicit_type.hpp +++ b/tests/headers/enum_explicit_type.hpp @@ -30,3 +30,8 @@ enum MuchULongLong: unsigned long long { enum BoolEnumsAreFun: bool { Value = true, }; + +enum : unsigned char { + AnonymousVariantOne, + AnonymousVariantTwo, +}; From ff3698189cb44f900e81d2b92131b1c191acf4de Mon Sep 17 00:00:00 2001 From: Varphone Wong Date: Sun, 2 Aug 2020 09:48:40 +0800 Subject: [PATCH 061/942] Add --no-debug flag --- book/src/SUMMARY.md | 1 + book/src/nodebug.md | 40 +++++++++++++++++++ src/codegen/mod.rs | 8 ++-- src/ir/analysis/derive.rs | 1 + src/ir/annotations.rs | 9 +++++ src/ir/context.rs | 6 +++ src/lib.rs | 13 ++++++ src/options.rs | 13 ++++++ tests/expectations/tests/no_debug.rs | 13 ++++++ .../tests/no_debug_bypass_impl_debug.rs | 32 +++++++++++++++ tests/expectations/tests/no_debug_opaque.rs | 26 ++++++++++++ .../tests/no_debug_whitelisted.rs | 30 ++++++++++++++ tests/headers/no_debug.hpp | 6 +++ tests/headers/no_debug_bypass_impl_debug.hpp | 11 +++++ tests/headers/no_debug_opaque.hpp | 5 +++ tests/headers/no_debug_whitelisted.hpp | 5 +++ 16 files changed, 216 insertions(+), 3 deletions(-) create mode 100644 book/src/nodebug.md create mode 100644 tests/expectations/tests/no_debug.rs create mode 100644 tests/expectations/tests/no_debug_bypass_impl_debug.rs create mode 100644 tests/expectations/tests/no_debug_opaque.rs create mode 100644 tests/expectations/tests/no_debug_whitelisted.rs create mode 100644 tests/headers/no_debug.hpp create mode 100644 tests/headers/no_debug_bypass_impl_debug.hpp create mode 100644 tests/headers/no_debug_opaque.hpp create mode 100644 tests/headers/no_debug_whitelisted.hpp diff --git a/book/src/SUMMARY.md b/book/src/SUMMARY.md index 1bd75cdd06..e2347fb43c 100644 --- a/book/src/SUMMARY.md +++ b/book/src/SUMMARY.md @@ -17,6 +17,7 @@ - [Treating a Type as an Opaque Blob of Bytes](./opaque.md) - [Replacing One Type with Another](./replacing-types.md) - [Preventing the Derivation of `Copy` and `Clone`](./nocopy.md) + - [Preventing the Derivation of `Debug`](./nodebug.md) - [Generating Bindings to C++](./cpp.md) - [Generating Bindings to Objective-c](./objc.md) - [Using Unions](./using-unions.md) diff --git a/book/src/nodebug.md b/book/src/nodebug.md new file mode 100644 index 0000000000..251b792b14 --- /dev/null +++ b/book/src/nodebug.md @@ -0,0 +1,40 @@ +# Preventing the Derivation of `Debug` + +`bindgen` will attempt to derive the `Debug` traits on a best-effort +basis. Sometimes, it might not understand that although adding `#[derive(Debug)]` to a translated type definition will compile, it still shouldn't do +that for reasons it can't know. In these cases, the `nodebug` annotation can be +used to prevent bindgen to autoderive the `Debug` traits for a type. + +### Library + +* [`bindgen::Builder::no_debug`](https://docs.rs/bindgen/0.54.2/bindgen/struct.Builder.html#method.no_debug) + +### Command Line + +* `--no-debug ` + +### Annotations + +```c +/** + * Although bindgen can't know, this enum is not safe to format the output. + * the value may be combined with multiple bits in many C/C++ cases, + * for example: + * + *
+ */ +enum AVRounding { + AV_ROUND_ZERO = 0, + AV_ROUND_INF = 1, + AV_ROUND_DOWN = 2, + AV_ROUND_UP = 3, + AV_ROUND_NEAR_INF = 5, + AV_ROUND_PASS_MINMAX = 8192, +}; + +// Prototype +int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding) av_const; + +// Call +int64_t pts = av_rescale_rnd(40000, 3600, 90000, AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX); +``` diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 20bf54c48d..00aa68f3f7 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -112,7 +112,7 @@ bitflags! { fn derives_of_item(item: &Item, ctx: &BindgenContext) -> DerivableTraits { let mut derivable_traits = DerivableTraits::empty(); - if item.can_derive_debug(ctx) { + if item.can_derive_debug(ctx) && !item.annotations().disallow_debug() { derivable_traits |= DerivableTraits::DEBUG; } @@ -1885,8 +1885,10 @@ impl CodeGenerator for CompInfo { let derivable_traits = derives_of_item(item, ctx); if !derivable_traits.contains(DerivableTraits::DEBUG) { - needs_debug_impl = - ctx.options().derive_debug && ctx.options().impl_debug + needs_debug_impl = ctx.options().derive_debug && + ctx.options().impl_debug && + !ctx.no_debug_by_name(item) && + !item.annotations().disallow_debug(); } if !derivable_traits.contains(DerivableTraits::DEFAULT) { diff --git a/src/ir/analysis/derive.rs b/src/ir/analysis/derive.rs index 6858d7f145..48c544f6aa 100644 --- a/src/ir/analysis/derive.rs +++ b/src/ir/analysis/derive.rs @@ -445,6 +445,7 @@ impl DeriveTrait { fn not_by_name(&self, ctx: &BindgenContext, item: &Item) -> bool { match self { DeriveTrait::Copy => ctx.no_copy_by_name(item), + DeriveTrait::Debug => ctx.no_debug_by_name(item), DeriveTrait::Hash => ctx.no_hash_by_name(item), DeriveTrait::PartialEqOrPartialOrd => { ctx.no_partialeq_by_name(item) diff --git a/src/ir/annotations.rs b/src/ir/annotations.rs index 98a0c0428f..da4ef4f75e 100644 --- a/src/ir/annotations.rs +++ b/src/ir/annotations.rs @@ -38,6 +38,8 @@ pub struct Annotations { /// Manually disable deriving copy/clone on this type. Only applies to /// struct or union types. disallow_copy: bool, + /// Manually disable deriving debug on this type. + disallow_debug: bool, /// Whether fields should be marked as private or not. You can set this on /// structs (it will apply to all the fields), or individual fields. private_fields: Option, @@ -78,6 +80,7 @@ impl Default for Annotations { hide: false, use_instead_of: None, disallow_copy: false, + disallow_debug: false, private_fields: None, accessor_kind: None, constify_enum_variant: false, @@ -147,6 +150,11 @@ impl Annotations { self.disallow_copy } + /// Should we avoid implementing the `Debug` trait? + pub fn disallow_debug(&self) -> bool { + self.disallow_debug + } + /// Should the fields be private? pub fn private_fields(&self) -> Option { self.private_fields @@ -172,6 +180,7 @@ impl Annotations { "opaque" => self.opaque = true, "hide" => self.hide = true, "nocopy" => self.disallow_copy = true, + "nodebug" => self.disallow_debug = true, "replaces" => { self.use_instead_of = Some( attr.value.split("::").map(Into::into).collect(), diff --git a/src/ir/context.rs b/src/ir/context.rs index 38d73b7e64..9513a41ce0 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -2635,6 +2635,12 @@ If you encounter an error missing from this list, please file an issue or a PR!" self.options().no_copy_types.matches(&name) } + /// Check if `--no-debug` flag is enabled for this item. + pub fn no_debug_by_name(&self, item: &Item) -> bool { + let name = item.path_for_whitelisting(self)[1..].join("::"); + self.options().no_debug_types.matches(&name) + } + /// Check if `--no-hash` flag is enabled for this item. pub fn no_hash_by_name(&self, item: &Item) -> bool { let name = item.path_for_whitelisting(self)[1..].join("::"); diff --git a/src/lib.rs b/src/lib.rs index 5a86364e6d..7fb2cdb824 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -295,6 +295,7 @@ impl Builder { (&self.options.whitelisted_vars, "--whitelist-var"), (&self.options.no_partialeq_types, "--no-partialeq"), (&self.options.no_copy_types, "--no-copy"), + (&self.options.no_debug_types, "--no-debug"), (&self.options.no_hash_types, "--no-hash"), ]; @@ -1410,6 +1411,13 @@ impl Builder { self } + /// Don't derive `Debug` for a given type. Regular + /// expressions are supported. + pub fn no_debug>(mut self, arg: T) -> Self { + self.options.no_debug_types.insert(arg.into()); + self + } + /// Don't derive `Hash` for a given type. Regular /// expressions are supported. pub fn no_hash>(mut self, arg: T) -> Builder { @@ -1691,6 +1699,9 @@ struct BindgenOptions { /// The set of types that we should not derive `Copy` for. no_copy_types: RegexSet, + /// The set of types that we should not derive `Debug` for. + no_debug_types: RegexSet, + /// The set of types that we should not derive `Hash` for. no_hash_types: RegexSet, @@ -1727,6 +1738,7 @@ impl BindgenOptions { &mut self.new_type_alias_deref, &mut self.no_partialeq_types, &mut self.no_copy_types, + &mut self.no_debug_types, &mut self.no_hash_types, ]; let record_matches = self.record_matches; @@ -1824,6 +1836,7 @@ impl Default for BindgenOptions { rustfmt_configuration_file: None, no_partialeq_types: Default::default(), no_copy_types: Default::default(), + no_debug_types: Default::default(), no_hash_types: Default::default(), array_pointers_in_arguments: false, wasm_import_module_name: None, diff --git a/src/options.rs b/src/options.rs index 0add7b4cbe..13fbf7a48a 100644 --- a/src/options.rs +++ b/src/options.rs @@ -430,6 +430,13 @@ where .takes_value(true) .multiple(true) .number_of_values(1), + Arg::with_name("no-debug") + .long("no-debug") + .help("Avoid deriving Debug for types matching .") + .value_name("regex") + .takes_value(true) + .multiple(true) + .number_of_values(1), Arg::with_name("no-hash") .long("no-hash") .help("Avoid deriving Hash for types matching .") @@ -831,6 +838,12 @@ where } } + if let Some(no_debug) = matches.values_of("no-debug") { + for regex in no_debug { + builder = builder.no_debug(regex); + } + } + if let Some(no_hash) = matches.values_of("no-hash") { for regex in no_hash { builder = builder.no_hash(regex); diff --git a/tests/expectations/tests/no_debug.rs b/tests/expectations/tests/no_debug.rs new file mode 100644 index 0000000000..21850ecb15 --- /dev/null +++ b/tests/expectations/tests/no_debug.rs @@ -0,0 +1,13 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +///
+#[repr(C)] +#[derive(Default, Copy, Clone)] +pub struct DebugButWait { + pub whatever: ::std::os::raw::c_int, +} diff --git a/tests/expectations/tests/no_debug_bypass_impl_debug.rs b/tests/expectations/tests/no_debug_bypass_impl_debug.rs new file mode 100644 index 0000000000..adb80eaa7e --- /dev/null +++ b/tests/expectations/tests/no_debug_bypass_impl_debug.rs @@ -0,0 +1,32 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +pub struct Generic { + pub t: [T; 40usize], + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, +} +impl Default for Generic { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +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 t: [T; 40usize], + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, +} +impl Default for NoDebug { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} diff --git a/tests/expectations/tests/no_debug_opaque.rs b/tests/expectations/tests/no_debug_opaque.rs new file mode 100644 index 0000000000..4b657481cd --- /dev/null +++ b/tests/expectations/tests/no_debug_opaque.rs @@ -0,0 +1,26 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +#[repr(align(4))] +#[derive(Default, Copy, Clone)] +pub struct NoDebug { + pub _bindgen_opaque_blob: u32, +} +#[test] +fn bindgen_test_layout_NoDebug() { + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(NoDebug)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(NoDebug)) + ); +} diff --git a/tests/expectations/tests/no_debug_whitelisted.rs b/tests/expectations/tests/no_debug_whitelisted.rs new file mode 100644 index 0000000000..ac43e4ea5a --- /dev/null +++ b/tests/expectations/tests/no_debug_whitelisted.rs @@ -0,0 +1,30 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +#[derive(Default, Copy, Clone)] +pub struct NoDebug { + pub i: ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout_NoDebug() { + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(NoDebug)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(NoDebug)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).i as *const _ as usize }, + 0usize, + concat!("Offset of field: ", stringify!(NoDebug), "::", stringify!(i)) + ); +} diff --git a/tests/headers/no_debug.hpp b/tests/headers/no_debug.hpp new file mode 100644 index 0000000000..2017f75da4 --- /dev/null +++ b/tests/headers/no_debug.hpp @@ -0,0 +1,6 @@ + +/**
*/ +template +class DebugButWait { + int whatever; +}; diff --git a/tests/headers/no_debug_bypass_impl_debug.hpp b/tests/headers/no_debug_bypass_impl_debug.hpp new file mode 100644 index 0000000000..a586441088 --- /dev/null +++ b/tests/headers/no_debug_bypass_impl_debug.hpp @@ -0,0 +1,11 @@ +// bindgen-flags: --no-debug "NoDebug" --impl-debug + +template +class Generic { + T t[40]; +}; + +template +class NoDebug { + T t[40]; +}; diff --git a/tests/headers/no_debug_opaque.hpp b/tests/headers/no_debug_opaque.hpp new file mode 100644 index 0000000000..d5dc18f773 --- /dev/null +++ b/tests/headers/no_debug_opaque.hpp @@ -0,0 +1,5 @@ +// bindgen-flags: --opaque-type "NoDebug" --no-debug "NoDebug" + +class NoDebug { + int i; +}; diff --git a/tests/headers/no_debug_whitelisted.hpp b/tests/headers/no_debug_whitelisted.hpp new file mode 100644 index 0000000000..7a855e8115 --- /dev/null +++ b/tests/headers/no_debug_whitelisted.hpp @@ -0,0 +1,5 @@ +// bindgen-flags: --whitelist-type "NoDebug" --no-debug "NoDebug" + +class NoDebug { + int i; +}; From 48808ed9d391fb90e5fdb5bf2223826eb5819e54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 3 Aug 2020 18:12:10 +0200 Subject: [PATCH 062/942] tests: Add a test for bool enum with an alias. --- tests/expectations/tests/enum_explicit_type.rs | 6 ++++++ tests/expectations/tests/enum_explicit_type_constants.rs | 3 +++ tests/headers/enum_explicit_type.hpp | 5 +++++ 3 files changed, 14 insertions(+) diff --git a/tests/expectations/tests/enum_explicit_type.rs b/tests/expectations/tests/enum_explicit_type.rs index 3da645d23f..92b4ace2c1 100644 --- a/tests/expectations/tests/enum_explicit_type.rs +++ b/tests/expectations/tests/enum_explicit_type.rs @@ -43,6 +43,12 @@ pub enum MuchULongLong { pub enum BoolEnumsAreFun { Value = 1, } +pub type MyType = bool; +#[repr(u8)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +pub enum BoolEnumsAreFun2 { + Value2 = 1, +} pub const AnonymousVariantOne: _bindgen_ty_1 = _bindgen_ty_1::AnonymousVariantOne; pub const AnonymousVariantTwo: _bindgen_ty_1 = diff --git a/tests/expectations/tests/enum_explicit_type_constants.rs b/tests/expectations/tests/enum_explicit_type_constants.rs index 9e198575f8..9406c7f2d6 100644 --- a/tests/expectations/tests/enum_explicit_type_constants.rs +++ b/tests/expectations/tests/enum_explicit_type_constants.rs @@ -22,5 +22,8 @@ pub const MuchULongLong_MuchHigh: MuchULongLong = 4294967296; pub type MuchULongLong = ::std::os::raw::c_ulonglong; pub const BoolEnumsAreFun_Value: BoolEnumsAreFun = true; pub type BoolEnumsAreFun = bool; +pub type MyType = bool; +pub const BoolEnumsAreFun2_Value2: BoolEnumsAreFun2 = true; +pub type BoolEnumsAreFun2 = MyType; pub const AnonymousVariantOne: ::std::os::raw::c_uchar = 0; pub const AnonymousVariantTwo: ::std::os::raw::c_uchar = 1; diff --git a/tests/headers/enum_explicit_type.hpp b/tests/headers/enum_explicit_type.hpp index b0f51c71fd..38e636e6c2 100644 --- a/tests/headers/enum_explicit_type.hpp +++ b/tests/headers/enum_explicit_type.hpp @@ -31,6 +31,11 @@ enum BoolEnumsAreFun: bool { Value = true, }; +using MyType = bool; +enum BoolEnumsAreFun2: MyType { + Value2 = true, +}; + enum : unsigned char { AnonymousVariantOne, AnonymousVariantTwo, From 7f7809f779542ddb26643a5732ee945bf99e2537 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 3 Aug 2020 18:13:22 +0200 Subject: [PATCH 063/942] codegen: Use shorthand initialization in EnumBuilder. This was introduced in #1850. --- src/codegen/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 00aa68f3f7..203da256b8 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -2515,8 +2515,8 @@ impl<'a> EnumBuilder<'a> { } EnumBuilder::Consts { - repr: repr, - variants: variants, + repr, + variants, codegen_depth: enum_codegen_depth, } } From 87b2bc033f35234d292d41ee2ba165516345dd18 Mon Sep 17 00:00:00 2001 From: Joseph Angelo Date: Mon, 3 Aug 2020 17:08:46 -0700 Subject: [PATCH 064/942] Fixed const-ness of multidimensional arrays --- src/ir/ty.rs | 5 ++++- .../expectations/tests/const_multidim_array_fn_arg.rs | 10 ++++++++++ tests/headers/const_multidim_array_fn_arg.h | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 tests/expectations/tests/const_multidim_array_fn_arg.rs create mode 100644 tests/headers/const_multidim_array_fn_arg.h diff --git a/src/ir/ty.rs b/src/ir/ty.rs index c1560ac3f6..e6eecc3c50 100644 --- a/src/ir/ty.rs +++ b/src/ir/ty.rs @@ -1209,7 +1209,10 @@ impl Type { let name = if name.is_empty() { None } else { Some(name) }; - let is_const = ty.is_const(); + let is_const = ty.is_const() || + (ty.kind() == CXType_ConstantArray && + ty.elem_type() + .map_or(false, |element| element.is_const())); let ty = Type::new(name, layout, kind, is_const); // TODO: maybe declaration.canonical()? diff --git a/tests/expectations/tests/const_multidim_array_fn_arg.rs b/tests/expectations/tests/const_multidim_array_fn_arg.rs new file mode 100644 index 0000000000..11ae184d85 --- /dev/null +++ b/tests/expectations/tests/const_multidim_array_fn_arg.rs @@ -0,0 +1,10 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +extern "C" { + pub fn f(a: *const [::std::os::raw::c_int; 1usize]); +} diff --git a/tests/headers/const_multidim_array_fn_arg.h b/tests/headers/const_multidim_array_fn_arg.h new file mode 100644 index 0000000000..784a51fe80 --- /dev/null +++ b/tests/headers/const_multidim_array_fn_arg.h @@ -0,0 +1 @@ +void f(const int a[1][1]); From dfeff8992e7726965c437697305379c7128a3812 Mon Sep 17 00:00:00 2001 From: Varphone Wong Date: Thu, 31 Oct 2019 23:32:45 +0800 Subject: [PATCH 065/942] Add --anon-fields-prefix option Allow to use the given prefix for the anon fields instead of `__bindgen_anon_`. --- src/ir/comp.rs | 12 +- src/lib.rs | 15 ++ src/options.rs | 12 ++ .../expectations/tests/anon-fields-prefix.rs | 156 ++++++++++++++++++ tests/headers/anon-fields-prefix.h | 15 ++ 5 files changed, 207 insertions(+), 3 deletions(-) create mode 100644 tests/expectations/tests/anon-fields-prefix.rs create mode 100644 tests/headers/anon-fields-prefix.h diff --git a/src/ir/comp.rs b/src/ir/comp.rs index 9bb429d285..c44e20f5f1 100644 --- a/src/ir/comp.rs +++ b/src/ir/comp.rs @@ -825,9 +825,15 @@ impl CompFields { } anon_field_counter += 1; - let generated_name = - format!("__bindgen_anon_{}", anon_field_counter); - *name = Some(generated_name); + if let Some(ref prefix) = ctx.options().anon_fields_prefix { + *name = + Some(format!("{}{}", prefix, anon_field_counter)); + } else { + *name = Some(format!( + "__bindgen_anon_{}", + anon_field_counter + )); + } } Field::Bitfields(ref mut bu) => { for bitfield in &mut bu.bitfields { diff --git a/src/lib.rs b/src/lib.rs index 7fb2cdb824..40b3b44ff3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -385,6 +385,11 @@ impl Builder { output_vector.push(prefix.clone()); } + if let Some(ref prefix) = self.options.anon_fields_prefix { + output_vector.push("--anon-fields-prefix".into()); + output_vector.push(prefix.clone()); + } + if self.options.emit_ast { output_vector.push("--emit-clang-ast".into()); } @@ -1212,6 +1217,12 @@ impl Builder { self } + /// Use the given prefix for the anon fields instead of `__bindgen_anon_`. + pub fn anon_fields_prefix>(mut self, prefix: T) -> Builder { + self.options.anon_fields_prefix = Some(prefix.into()); + self + } + /// Allows configuring types in different situations, see the /// [`ParseCallbacks`](./callbacks/trait.ParseCallbacks.html) documentation. pub fn parse_callbacks( @@ -1590,6 +1601,9 @@ struct BindgenOptions { /// An optional prefix for the "raw" types, like `c_int`, `c_void`... ctypes_prefix: Option, + /// An optional prefix for the anon fields instead of `__bindgen_anon_`. + anon_fields_prefix: Option, + /// Whether to time the bindgen phases. time_phases: bool, @@ -1809,6 +1823,7 @@ impl Default for BindgenOptions { disable_header_comment: false, use_core: false, ctypes_prefix: None, + anon_fields_prefix: None, namespaced_constants: true, msvc_mangling: false, convert_floats: true, diff --git a/src/options.rs b/src/options.rs index 13fbf7a48a..8dc80e1ea4 100644 --- a/src/options.rs +++ b/src/options.rs @@ -234,6 +234,14 @@ where ) .value_name("prefix") .takes_value(true), + Arg::with_name("anon-fields-prefix") + .long("anon-fields-prefix") + .help( + "Use the given prefix for the anon fields instead of \ + __bindgen_anon_.", + ) + .value_name("prefix") + .takes_value(true), Arg::with_name("time-phases") .long("time-phases") .help("Time the different bindgen phases and print to stderr"), @@ -634,6 +642,10 @@ where builder = builder.ctypes_prefix(prefix); } + if let Some(prefix) = matches.value_of("anon-fields-prefix") { + builder = builder.anon_fields_prefix(prefix); + } + if let Some(what_to_generate) = matches.value_of("generate") { let mut config = CodegenConfig::empty(); for what in what_to_generate.split(",") { diff --git a/tests/expectations/tests/anon-fields-prefix.rs b/tests/expectations/tests/anon-fields-prefix.rs new file mode 100644 index 0000000000..38baa2fdfc --- /dev/null +++ b/tests/expectations/tests/anon-fields-prefix.rs @@ -0,0 +1,156 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +#[derive(Copy, Clone)] +pub union color { + pub u1: color__bindgen_ty_1, + pub u2: color__bindgen_ty_2, + pub v3: [::std::os::raw::c_uchar; 3usize], + _bindgen_union_align: [u8; 3usize], +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct color__bindgen_ty_1 { + pub r: ::std::os::raw::c_uchar, + pub g: ::std::os::raw::c_uchar, + pub b: ::std::os::raw::c_uchar, +} +#[test] +fn bindgen_test_layout_color__bindgen_ty_1() { + assert_eq!( + ::std::mem::size_of::(), + 3usize, + concat!("Size of: ", stringify!(color__bindgen_ty_1)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(color__bindgen_ty_1)) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).r as *const _ + as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(color__bindgen_ty_1), + "::", + stringify!(r) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).g as *const _ + as usize + }, + 1usize, + concat!( + "Offset of field: ", + stringify!(color__bindgen_ty_1), + "::", + stringify!(g) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).b as *const _ + as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(color__bindgen_ty_1), + "::", + stringify!(b) + ) + ); +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct color__bindgen_ty_2 { + pub y: ::std::os::raw::c_uchar, + pub u: ::std::os::raw::c_uchar, + pub v: ::std::os::raw::c_uchar, +} +#[test] +fn bindgen_test_layout_color__bindgen_ty_2() { + assert_eq!( + ::std::mem::size_of::(), + 3usize, + concat!("Size of: ", stringify!(color__bindgen_ty_2)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(color__bindgen_ty_2)) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).y as *const _ + as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(color__bindgen_ty_2), + "::", + stringify!(y) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).u as *const _ + as usize + }, + 1usize, + concat!( + "Offset of field: ", + stringify!(color__bindgen_ty_2), + "::", + stringify!(u) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).v as *const _ + as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(color__bindgen_ty_2), + "::", + stringify!(v) + ) + ); +} +#[test] +fn bindgen_test_layout_color() { + assert_eq!( + ::std::mem::size_of::(), + 3usize, + concat!("Size of: ", stringify!(color)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(color)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).v3 as *const _ as usize }, + 0usize, + concat!("Offset of field: ", stringify!(color), "::", stringify!(v3)) + ); +} +impl Default for color { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} diff --git a/tests/headers/anon-fields-prefix.h b/tests/headers/anon-fields-prefix.h new file mode 100644 index 0000000000..8dcae0c61a --- /dev/null +++ b/tests/headers/anon-fields-prefix.h @@ -0,0 +1,15 @@ +// bindgen-flags: --anon-fields-prefix "u" + +union color { + struct { + unsigned char r; + unsigned char g; + unsigned char b; + }; + struct { + unsigned char y; + unsigned char u; + unsigned char v; + }; + unsigned char v3[3]; +}; From 4a75b21c13e0d21f5f4e8ffa7dcfaea2dd1d3717 Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Sun, 2 Aug 2020 14:49:48 -0700 Subject: [PATCH 066/942] Make anon-fields-prefix non-optional --- src/ir/comp.rs | 14 +++++--------- src/lib.rs | 12 ++++++------ src/options.rs | 6 ++---- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/ir/comp.rs b/src/ir/comp.rs index c44e20f5f1..22c124fa36 100644 --- a/src/ir/comp.rs +++ b/src/ir/comp.rs @@ -825,15 +825,11 @@ impl CompFields { } anon_field_counter += 1; - if let Some(ref prefix) = ctx.options().anon_fields_prefix { - *name = - Some(format!("{}{}", prefix, anon_field_counter)); - } else { - *name = Some(format!( - "__bindgen_anon_{}", - anon_field_counter - )); - } + *name = Some(format!( + "{}{}", + ctx.options().anon_fields_prefix, + anon_field_counter + )); } Field::Bitfields(ref mut bu) => { for bitfield in &mut bu.bitfields { diff --git a/src/lib.rs b/src/lib.rs index 40b3b44ff3..857a0665aa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -385,7 +385,7 @@ impl Builder { output_vector.push(prefix.clone()); } - if let Some(ref prefix) = self.options.anon_fields_prefix { + if let prefix = &self.options.anon_fields_prefix { output_vector.push("--anon-fields-prefix".into()); output_vector.push(prefix.clone()); } @@ -1217,9 +1217,9 @@ impl Builder { self } - /// Use the given prefix for the anon fields instead of `__bindgen_anon_`. + /// Use the given prefix for the anon fields. pub fn anon_fields_prefix>(mut self, prefix: T) -> Builder { - self.options.anon_fields_prefix = Some(prefix.into()); + self.options.anon_fields_prefix = prefix.into(); self } @@ -1601,8 +1601,8 @@ struct BindgenOptions { /// An optional prefix for the "raw" types, like `c_int`, `c_void`... ctypes_prefix: Option, - /// An optional prefix for the anon fields instead of `__bindgen_anon_`. - anon_fields_prefix: Option, + /// The prefix for the anon fields. + anon_fields_prefix: String, /// Whether to time the bindgen phases. time_phases: bool, @@ -1823,7 +1823,7 @@ impl Default for BindgenOptions { disable_header_comment: false, use_core: false, ctypes_prefix: None, - anon_fields_prefix: None, + anon_fields_prefix: "__bindgen_anon_".into(), namespaced_constants: true, msvc_mangling: false, convert_floats: true, diff --git a/src/options.rs b/src/options.rs index 8dc80e1ea4..4844b91aa4 100644 --- a/src/options.rs +++ b/src/options.rs @@ -236,11 +236,9 @@ where .takes_value(true), Arg::with_name("anon-fields-prefix") .long("anon-fields-prefix") - .help( - "Use the given prefix for the anon fields instead of \ - __bindgen_anon_.", - ) + .help("Use the given prefix for the anon fields.") .value_name("prefix") + .default_value("__bindgen_anon_") .takes_value(true), Arg::with_name("time-phases") .long("time-phases") From 8e6a6999e9392d80c45979dd3f0d6ceca58db94e Mon Sep 17 00:00:00 2001 From: Varphone Wong Date: Mon, 3 Aug 2020 10:03:40 +0800 Subject: [PATCH 067/942] =?UTF-8?q?Fix=20=E2=80=9Cwarning:=20irrefutable?= =?UTF-8?q?=20if-let=20pattern=E2=80=9D=20on=20add=20to=20output=5Fvector?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 857a0665aa..e492efc408 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -385,10 +385,8 @@ impl Builder { output_vector.push(prefix.clone()); } - if let prefix = &self.options.anon_fields_prefix { - output_vector.push("--anon-fields-prefix".into()); - output_vector.push(prefix.clone()); - } + output_vector.push("--anon-fields-prefix".into()); + output_vector.push(self.options.anon_fields_prefix.clone()); if self.options.emit_ast { output_vector.push("--emit-clang-ast".into()); From 1127561bb232fe0aa3ef48cc8404b26ed3b7116c Mon Sep 17 00:00:00 2001 From: Varphone Wong Date: Tue, 4 Aug 2020 14:04:35 +0800 Subject: [PATCH 068/942] Move `__bindgen_anon_` to constant `DEFAULT_ANON_FIELDS_PREFIX` --- src/lib.rs | 11 ++++++++--- src/options.rs | 4 ++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index e492efc408..9bbefaad3a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -94,6 +94,9 @@ type HashMap = ::rustc_hash::FxHashMap; type HashSet = ::rustc_hash::FxHashSet; pub(crate) use std::collections::hash_map::Entry; +/// Default prefix for the anon fields. +pub const DEFAULT_ANON_FIELDS_PREFIX: &'static str = "__bindgen_anon_"; + fn args_are_cpp(clang_args: &[String]) -> bool { return clang_args .windows(2) @@ -385,8 +388,10 @@ impl Builder { output_vector.push(prefix.clone()); } - output_vector.push("--anon-fields-prefix".into()); - output_vector.push(self.options.anon_fields_prefix.clone()); + if self.options.anon_fields_prefix != DEFAULT_ANON_FIELDS_PREFIX { + output_vector.push("--anon-fields-prefix".into()); + output_vector.push(self.options.anon_fields_prefix.clone()); + } if self.options.emit_ast { output_vector.push("--emit-clang-ast".into()); @@ -1821,7 +1826,7 @@ impl Default for BindgenOptions { disable_header_comment: false, use_core: false, ctypes_prefix: None, - anon_fields_prefix: "__bindgen_anon_".into(), + anon_fields_prefix: DEFAULT_ANON_FIELDS_PREFIX.into(), namespaced_constants: true, msvc_mangling: false, convert_floats: true, diff --git a/src/options.rs b/src/options.rs index 4844b91aa4..1ba349a91e 100644 --- a/src/options.rs +++ b/src/options.rs @@ -1,6 +1,6 @@ use bindgen::{ builder, AliasVariation, Builder, CodegenConfig, EnumVariation, RustTarget, - RUST_TARGET_STRINGS, + DEFAULT_ANON_FIELDS_PREFIX, RUST_TARGET_STRINGS, }; use clap::{App, Arg}; use std::fs::File; @@ -238,7 +238,7 @@ where .long("anon-fields-prefix") .help("Use the given prefix for the anon fields.") .value_name("prefix") - .default_value("__bindgen_anon_") + .default_value(DEFAULT_ANON_FIELDS_PREFIX) .takes_value(true), Arg::with_name("time-phases") .long("time-phases") From 53290e8f3535f118bcc06c048d34740233ef7821 Mon Sep 17 00:00:00 2001 From: Chih-Hung Hsieh Date: Sat, 8 Aug 2020 16:20:47 -0700 Subject: [PATCH 069/942] Add --default-macro-constant-type * --default-macro-constant-type could be 'signed' or 'unsigned' * Its default value is 'unsigned' to use u32/u64 for C macro constants that fit into the u32/u64 ranges. * For old C libraries that use macros as int/long parameter and/or return value types, their macros are better declared as i32/i64 if the values fit the i32/i64 ranges, to be compatible with c_int/c_long types. They can use "--default-macro-constant-type signed" --- src/codegen/mod.rs | 44 +++++++++++++++++++ src/ir/var.rs | 12 +++-- src/lib.rs | 21 ++++++++- src/options.rs | 17 ++++++- .../default-macro-constant-type-signed.rs | 42 ++++++++++++++++++ .../default-macro-constant-type-unsigned.rs | 42 ++++++++++++++++++ .../tests/default-macro-constant-type.rs | 42 ++++++++++++++++++ .../default-macro-constant-type-signed.h | 3 ++ .../default-macro-constant-type-unsigned.h | 3 ++ tests/headers/default-macro-constant-type.h | 34 ++++++++++++++ 10 files changed, 253 insertions(+), 7 deletions(-) create mode 100644 tests/expectations/tests/default-macro-constant-type-signed.rs create mode 100644 tests/expectations/tests/default-macro-constant-type-unsigned.rs create mode 100644 tests/expectations/tests/default-macro-constant-type.rs create mode 100644 tests/headers/default-macro-constant-type-signed.h create mode 100644 tests/headers/default-macro-constant-type-unsigned.h create mode 100644 tests/headers/default-macro-constant-type.h diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 203da256b8..de46bb2269 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -3048,6 +3048,50 @@ impl CodeGenerator for Enum { } } +/// Enum for the default type of macro constants. +#[derive(Copy, Clone, PartialEq, Debug)] +pub enum MacroTypeVariation { + /// Use i32 or i64 + Signed, + /// Use u32 or u64 + Unsigned, +} + +impl MacroTypeVariation { + /// Convert a `MacroTypeVariation` to its str representation. + pub fn as_str(&self) -> &str { + match self { + MacroTypeVariation::Signed => "signed", + MacroTypeVariation::Unsigned => "unsigned", + } + } +} + +impl Default for MacroTypeVariation { + fn default() -> MacroTypeVariation { + MacroTypeVariation::Unsigned + } +} + +impl std::str::FromStr for MacroTypeVariation { + type Err = std::io::Error; + + /// Create a `MacroTypeVariation` from a string. + fn from_str(s: &str) -> Result { + match s { + "signed" => Ok(MacroTypeVariation::Signed), + "unsigned" => Ok(MacroTypeVariation::Unsigned), + _ => Err(std::io::Error::new( + std::io::ErrorKind::InvalidInput, + concat!( + "Got an invalid MacroTypeVariation. Accepted values ", + "are 'signed' and 'unsigned'" + ), + )), + } + } +} + /// Enum for how aliases should be translated. #[derive(Copy, Clone, PartialEq, Debug)] pub enum AliasVariation { diff --git a/src/ir/var.rs b/src/ir/var.rs index ef9635030b..c6f121d74e 100644 --- a/src/ir/var.rs +++ b/src/ir/var.rs @@ -1,5 +1,6 @@ //! Intermediate representation of variables. +use super::super::codegen::MacroTypeVariation; use super::context::{BindgenContext, TypeId}; use super::dot::DotAttributes; use super::function::cursor_mangling; @@ -117,9 +118,12 @@ impl DotAttributes for Var { } // TODO(emilio): we could make this more (or less) granular, I guess. -fn default_macro_constant_type(value: i64) -> IntKind { - if value < 0 { - if value < i32::min_value() as i64 { +fn default_macro_constant_type(ctx: &BindgenContext, value: i64) -> IntKind { + if value < 0 || + ctx.options().default_macro_constant_type == + MacroTypeVariation::Signed + { + if value < i32::min_value() as i64 || value > i32::max_value() as i64 { IntKind::I64 } else { IntKind::I32 @@ -264,7 +268,7 @@ impl ClangSubItemParser for Var { .parse_callbacks() .and_then(|c| c.int_macro(&name, value)) .unwrap_or_else(|| { - default_macro_constant_type(value) + default_macro_constant_type(&ctx, value) }); (TypeKind::Int(kind), VarType::Int(value)) diff --git a/src/lib.rs b/src/lib.rs index 9bbefaad3a..0bcdf789db 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -72,7 +72,7 @@ doc_mod!(ir, ir_docs); doc_mod!(parse, parse_docs); doc_mod!(regex_set, regex_set_docs); -pub use crate::codegen::{AliasVariation, EnumVariation}; +pub use crate::codegen::{AliasVariation, EnumVariation, MacroTypeVariation}; use crate::features::RustFeatures; pub use crate::features::{ RustTarget, LATEST_STABLE_RUST, RUST_TARGET_STRINGS, @@ -267,6 +267,12 @@ impl Builder { ) } + if self.options.default_macro_constant_type != Default::default() { + output_vector.push("--default-macro-constant-type".into()); + output_vector + .push(self.options.default_macro_constant_type.as_str().into()); + } + if self.options.default_alias_style != Default::default() { output_vector.push("--default-alias-style".into()); output_vector @@ -872,6 +878,15 @@ impl Builder { self } + /// Set the default type for macro constants + pub fn default_macro_constant_type( + mut self, + arg: codegen::MacroTypeVariation, + ) -> Builder { + self.options.default_macro_constant_type = arg; + self + } + /// Set the default style of code to generate for typedefs pub fn default_alias_style( mut self, @@ -1513,6 +1528,9 @@ struct BindgenOptions { /// The enum patterns to mark an enum as a set of constants. constified_enums: RegexSet, + /// The default type for C macro constants. + default_macro_constant_type: codegen::MacroTypeVariation, + /// The default style of code to generate for typedefs. default_alias_style: codegen::AliasVariation, @@ -1800,6 +1818,7 @@ impl Default for BindgenOptions { rustified_non_exhaustive_enums: Default::default(), constified_enums: Default::default(), constified_enum_modules: Default::default(), + default_macro_constant_type: Default::default(), default_alias_style: Default::default(), type_alias: Default::default(), new_type_alias: Default::default(), diff --git a/src/options.rs b/src/options.rs index 1ba349a91e..a850dbbbfe 100644 --- a/src/options.rs +++ b/src/options.rs @@ -1,6 +1,7 @@ use bindgen::{ - builder, AliasVariation, Builder, CodegenConfig, EnumVariation, RustTarget, - DEFAULT_ANON_FIELDS_PREFIX, RUST_TARGET_STRINGS, + builder, AliasVariation, Builder, CodegenConfig, EnumVariation, + MacroTypeVariation, RustTarget, DEFAULT_ANON_FIELDS_PREFIX, + RUST_TARGET_STRINGS, }; use clap::{App, Arg}; use std::fs::File; @@ -87,6 +88,13 @@ where .takes_value(true) .multiple(true) .number_of_values(1), + Arg::with_name("default-macro-constant-type") + .long("default-macro-constant-type") + .help("The default signed/unsigned type for C macro constants.") + .value_name("variant") + .default_value("unsigned") + .possible_values(&["signed", "unsigned"]) + .multiple(false), Arg::with_name("default-alias-style") .long("default-alias-style") .help("The default style of code used to generate typedefs.") @@ -522,6 +530,11 @@ where } } + if let Some(variant) = matches.value_of("default-macro-constant-type") { + builder = builder + .default_macro_constant_type(MacroTypeVariation::from_str(variant)?) + } + if let Some(variant) = matches.value_of("default-alias-style") { builder = builder.default_alias_style(AliasVariation::from_str(variant)?); diff --git a/tests/expectations/tests/default-macro-constant-type-signed.rs b/tests/expectations/tests/default-macro-constant-type-signed.rs new file mode 100644 index 0000000000..eda3117d3e --- /dev/null +++ b/tests/expectations/tests/default-macro-constant-type-signed.rs @@ -0,0 +1,42 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +pub const N0: i32 = 0; +pub const N1: i32 = 1; +pub const N2: i32 = 2; +pub const N_1: i32 = -1; +pub const N_2: i32 = -2; +pub const MAX_U32: i64 = 4294967295; +pub const MAX_I32: i32 = 2147483647; +pub const MAX_I32_Plus1: i64 = 2147483648; +pub const MAX_U32_Plus1: i64 = 4294967296; +pub const MAX_I32_Minus1: i32 = 2147483646; +pub const MAX_U32_Minus1: i64 = 4294967294; +pub const MIN_U32: i32 = 0; +pub const MIN_I32: i32 = -2147483648; +pub const MIN_U32_Plus1: i32 = 1; +pub const MIN_I32_Plus1: i32 = -2147483647; +pub const MIN_U32_Minus1: i32 = -1; +pub const MIN_I32_Minus1: i64 = -2147483649; +pub const LONG12: i64 = 123456789012; +pub const LONG_12: i64 = -123456789012; +extern "C" { + pub fn foo( + arg1: ::std::os::raw::c_int, + arg2: ::std::os::raw::c_int, + arg3: ::std::os::raw::c_uint, + arg4: ::std::os::raw::c_char, + arg5: ::std::os::raw::c_uchar, + arg6: ::std::os::raw::c_schar, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn bar( + arg1: ::std::os::raw::c_long, + arg2: ::std::os::raw::c_longlong, + ) -> ::std::os::raw::c_long; +} diff --git a/tests/expectations/tests/default-macro-constant-type-unsigned.rs b/tests/expectations/tests/default-macro-constant-type-unsigned.rs new file mode 100644 index 0000000000..241443aa41 --- /dev/null +++ b/tests/expectations/tests/default-macro-constant-type-unsigned.rs @@ -0,0 +1,42 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +pub const N0: u32 = 0; +pub const N1: u32 = 1; +pub const N2: u32 = 2; +pub const N_1: i32 = -1; +pub const N_2: i32 = -2; +pub const MAX_U32: u32 = 4294967295; +pub const MAX_I32: u32 = 2147483647; +pub const MAX_I32_Plus1: u32 = 2147483648; +pub const MAX_U32_Plus1: u64 = 4294967296; +pub const MAX_I32_Minus1: u32 = 2147483646; +pub const MAX_U32_Minus1: u32 = 4294967294; +pub const MIN_U32: u32 = 0; +pub const MIN_I32: i32 = -2147483648; +pub const MIN_U32_Plus1: u32 = 1; +pub const MIN_I32_Plus1: i32 = -2147483647; +pub const MIN_U32_Minus1: i32 = -1; +pub const MIN_I32_Minus1: i64 = -2147483649; +pub const LONG12: u64 = 123456789012; +pub const LONG_12: i64 = -123456789012; +extern "C" { + pub fn foo( + arg1: ::std::os::raw::c_int, + arg2: ::std::os::raw::c_int, + arg3: ::std::os::raw::c_uint, + arg4: ::std::os::raw::c_char, + arg5: ::std::os::raw::c_uchar, + arg6: ::std::os::raw::c_schar, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn bar( + arg1: ::std::os::raw::c_long, + arg2: ::std::os::raw::c_longlong, + ) -> ::std::os::raw::c_long; +} diff --git a/tests/expectations/tests/default-macro-constant-type.rs b/tests/expectations/tests/default-macro-constant-type.rs new file mode 100644 index 0000000000..241443aa41 --- /dev/null +++ b/tests/expectations/tests/default-macro-constant-type.rs @@ -0,0 +1,42 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +pub const N0: u32 = 0; +pub const N1: u32 = 1; +pub const N2: u32 = 2; +pub const N_1: i32 = -1; +pub const N_2: i32 = -2; +pub const MAX_U32: u32 = 4294967295; +pub const MAX_I32: u32 = 2147483647; +pub const MAX_I32_Plus1: u32 = 2147483648; +pub const MAX_U32_Plus1: u64 = 4294967296; +pub const MAX_I32_Minus1: u32 = 2147483646; +pub const MAX_U32_Minus1: u32 = 4294967294; +pub const MIN_U32: u32 = 0; +pub const MIN_I32: i32 = -2147483648; +pub const MIN_U32_Plus1: u32 = 1; +pub const MIN_I32_Plus1: i32 = -2147483647; +pub const MIN_U32_Minus1: i32 = -1; +pub const MIN_I32_Minus1: i64 = -2147483649; +pub const LONG12: u64 = 123456789012; +pub const LONG_12: i64 = -123456789012; +extern "C" { + pub fn foo( + arg1: ::std::os::raw::c_int, + arg2: ::std::os::raw::c_int, + arg3: ::std::os::raw::c_uint, + arg4: ::std::os::raw::c_char, + arg5: ::std::os::raw::c_uchar, + arg6: ::std::os::raw::c_schar, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn bar( + arg1: ::std::os::raw::c_long, + arg2: ::std::os::raw::c_longlong, + ) -> ::std::os::raw::c_long; +} diff --git a/tests/headers/default-macro-constant-type-signed.h b/tests/headers/default-macro-constant-type-signed.h new file mode 100644 index 0000000000..da3f134467 --- /dev/null +++ b/tests/headers/default-macro-constant-type-signed.h @@ -0,0 +1,3 @@ +// bindgen-flags: --default-macro-constant-type signed +// All values are i32 if they fit; otherwise i64. +#include "default-macro-constant-type.h" diff --git a/tests/headers/default-macro-constant-type-unsigned.h b/tests/headers/default-macro-constant-type-unsigned.h new file mode 100644 index 0000000000..1078e852ee --- /dev/null +++ b/tests/headers/default-macro-constant-type-unsigned.h @@ -0,0 +1,3 @@ +// bindgen-flags: --default-macro-constant-type unsigned +// Negative values are i32 or i64; others are u32 or u64. +#include "default-macro-constant-type.h" diff --git a/tests/headers/default-macro-constant-type.h b/tests/headers/default-macro-constant-type.h new file mode 100644 index 0000000000..d11941b440 --- /dev/null +++ b/tests/headers/default-macro-constant-type.h @@ -0,0 +1,34 @@ +// Test default of --default-macro-constant-type +// Negative values are i32 or i64; others are u32 or u64. + +#define N0 0 +#define N1 1ULL +#define N2 2ULL + +#define N_1 (-1LL) +#define N_2 (-2LL) + +#define MAX_U32 0xFFFFFFFFULL +#define MAX_I32 (0x80000000ULL - 1) + +#define MAX_I32_Plus1 (MAX_I32 + 1) +#define MAX_U32_Plus1 (MAX_U32 + 1) + +#define MAX_I32_Minus1 (MAX_I32 - 1) +#define MAX_U32_Minus1 (MAX_U32 - 1) + +#define MIN_U32 0 +#define MIN_I32 (- (1ULL<<31)) + +#define MIN_U32_Plus1 (MIN_U32 + 1) +#define MIN_I32_Plus1 (MIN_I32 + 1) + +#define MIN_U32_Minus1 (MIN_U32 - 1) +#define MIN_I32_Minus1 (MIN_I32 - 1) + +#define LONG12 123456789012ULL +#define LONG_12 (- 123456789012ULL) + +// Function parameter and return types are not affected. +int foo(int, signed, unsigned, char, unsigned char, signed char); +long bar(long, long long); From f91c9b6604bef0abe3bbb0d4e659d445a463a06d Mon Sep 17 00:00:00 2001 From: Varphone Wong Date: Sat, 8 Aug 2020 21:57:41 +0800 Subject: [PATCH 070/942] Cleanup some `clippy::unused_io_amount` errors --- src/lib.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 0bcdf789db..390bde3a3f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1391,7 +1391,7 @@ impl Builder { { let mut wrapper_file = File::create(&wrapper_path)?; - wrapper_file.write(wrapper_contents.as_bytes())?; + wrapper_file.write_all(wrapper_contents.as_bytes())?; } let mut cmd = Command::new(&clang.path); @@ -2088,30 +2088,30 @@ impl Bindings { "/* automatically generated by rust-bindgen {} */\n\n", version.unwrap_or("(unknown version)") ); - writer.write(header.as_bytes())?; + writer.write_all(header.as_bytes())?; } for line in self.options.raw_lines.iter() { - writer.write(line.as_bytes())?; - writer.write("\n".as_bytes())?; + writer.write_all(line.as_bytes())?; + writer.write_all("\n".as_bytes())?; } if !self.options.raw_lines.is_empty() { - writer.write("\n".as_bytes())?; + writer.write_all("\n".as_bytes())?; } let bindings = self.module.to_string(); match self.rustfmt_generated_string(&bindings) { Ok(rustfmt_bindings) => { - writer.write(rustfmt_bindings.as_bytes())?; + writer.write_all(rustfmt_bindings.as_bytes())?; } Err(err) => { eprintln!( "Failed to run rustfmt: {} (non-fatal, continuing)", err ); - writer.write(bindings.as_bytes())?; + writer.write_all(bindings.as_bytes())?; } } Ok(()) From d55b063e8010a3acf5c2a549a1d2d7c238286314 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 13 Aug 2020 13:14:21 +0200 Subject: [PATCH 071/942] context: Don't pass --target=rust-target to clang when building for the host. This will prevent common issues in platforms where the Rust target is not the clang target, like aarch64-apple-darwin (Rust) vs. arm64-apple-darwin. We may want to special-case those too when cross-compiling. --- src/ir/context.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/ir/context.rs b/src/ir/context.rs index 9513a41ce0..30eff616a6 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -555,7 +555,14 @@ impl BindgenContext { let translation_unit = { let _t = Timer::new("translation_unit").with_output(options.time_phases); - let clang_args = if explicit_target { + // NOTE: The effective_target == HOST_TARGET check wouldn't be sound + // normally in some cases if we were to call a binary (if you have a + // 32-bit clang and are building on a 64-bit system for example). + // But since we rely on opening libclang.so, it has to be the same + // architecture and thus the check is fine. + let clang_args = if explicit_target || + effective_target == HOST_TARGET + { Cow::Borrowed(&options.clang_args) } else { let mut args = Vec::with_capacity(options.clang_args.len() + 1); From 802561e1779b188594527d400d44b37a79faadbe Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Fri, 14 Aug 2020 11:29:08 +0900 Subject: [PATCH 072/942] Add --target to the clang args earlier Because the --target was passed after the include path detection, in cases of cross-compilation, the include path detection would add paths relevant to the host (e.g. /usr/include/x86_64_linux-gnu on x86_64 linux while targeting something else), possibly breaking things along the way. --- src/ir/context.rs | 67 +---------------------------------------------- src/lib.rs | 56 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 66 deletions(-) diff --git a/src/ir/context.rs b/src/ir/context.rs index 30eff616a6..79c682e049 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -507,46 +507,12 @@ impl<'ctx> WhitelistedItemsTraversal<'ctx> { } } -const HOST_TARGET: &'static str = - include_str!(concat!(env!("OUT_DIR"), "/host-target.txt")); - -/// Returns the effective target, and whether it was explicitly specified on the -/// clang flags. -fn find_effective_target(clang_args: &[String]) -> (String, bool) { - use std::env; - - let mut args = clang_args.iter(); - while let Some(opt) = args.next() { - if opt.starts_with("--target=") { - let mut split = opt.split('='); - split.next(); - return (split.next().unwrap().to_owned(), true); - } - - if opt == "-target" { - if let Some(target) = args.next() { - return (target.clone(), true); - } - } - } - - // If we're running from a build script, try to find the cargo target. - if let Ok(t) = env::var("TARGET") { - return (t, false); - } - - (HOST_TARGET.to_owned(), false) -} - impl BindgenContext { /// Construct the context for the given `options`. pub(crate) fn new(options: BindgenOptions) -> Self { // TODO(emilio): Use the CXTargetInfo here when available. // // see: https://reviews.llvm.org/D32389 - let (effective_target, explicit_target) = - find_effective_target(&options.clang_args); - let index = clang::Index::new(false, true); let parse_options = @@ -555,26 +521,11 @@ impl BindgenContext { let translation_unit = { let _t = Timer::new("translation_unit").with_output(options.time_phases); - // NOTE: The effective_target == HOST_TARGET check wouldn't be sound - // normally in some cases if we were to call a binary (if you have a - // 32-bit clang and are building on a 64-bit system for example). - // But since we rely on opening libclang.so, it has to be the same - // architecture and thus the check is fine. - let clang_args = if explicit_target || - effective_target == HOST_TARGET - { - Cow::Borrowed(&options.clang_args) - } else { - let mut args = Vec::with_capacity(options.clang_args.len() + 1); - args.push(format!("--target={}", effective_target)); - args.extend_from_slice(&options.clang_args); - Cow::Owned(args) - }; clang::TranslationUnit::parse( &index, "", - &clang_args, + &options.clang_args, &options.input_unsaved_files, parse_options, ).expect("libclang error; possible causes include: @@ -587,22 +538,6 @@ If you encounter an error missing from this list, please file an issue or a PR!" }; let target_info = clang::TargetInfo::new(&translation_unit); - - #[cfg(debug_assertions)] - { - if let Some(ref ti) = target_info { - if effective_target == HOST_TARGET { - assert_eq!( - ti.pointer_width / 8, - mem::size_of::<*mut ()>(), - "{:?} {:?}", - effective_target, - HOST_TARGET - ); - } - } - } - let root_module = Self::build_root_module(ItemId(0)); let root_module_id = root_module.id().as_module_id_unchecked(); diff --git a/src/lib.rs b/src/lib.rs index 390bde3a3f..4317561bb9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1914,6 +1914,35 @@ pub struct Bindings { module: proc_macro2::TokenStream, } +pub(crate) const HOST_TARGET: &'static str = + include_str!(concat!(env!("OUT_DIR"), "/host-target.txt")); + +/// Returns the effective target, and whether it was explicitly specified on the +/// clang flags. +fn find_effective_target(clang_args: &[String]) -> (String, bool) { + let mut args = clang_args.iter(); + while let Some(opt) = args.next() { + if opt.starts_with("--target=") { + let mut split = opt.split('='); + split.next(); + return (split.next().unwrap().to_owned(), true); + } + + if opt == "-target" { + if let Some(target) = args.next() { + return (target.clone(), true); + } + } + } + + // If we're running from a build script, try to find the cargo target. + if let Ok(t) = env::var("TARGET") { + return (t, false); + } + + (HOST_TARGET.to_owned(), false) +} + impl Bindings { /// Generate bindings for the given options. pub(crate) fn generate( @@ -1931,6 +1960,20 @@ impl Bindings { options.build(); + let (effective_target, explicit_target) = + find_effective_target(&options.clang_args); + + // NOTE: The effective_target == HOST_TARGET check wouldn't be sound + // normally in some cases if we were to call a binary (if you have a + // 32-bit clang and are building on a 64-bit system for example). + // But since we rely on opening libclang.so, it has to be the same + // architecture and thus the check is fine. + if !(explicit_target || effective_target == HOST_TARGET) { + options + .clang_args + .insert(0, format!("--target={}", effective_target)); + }; + fn detect_include_paths(options: &mut BindgenOptions) { if !options.detect_include_paths { return; @@ -2045,6 +2088,19 @@ impl Bindings { let time_phases = options.time_phases; let mut context = BindgenContext::new(options); + #[cfg(debug_assertions)] + { + if effective_target == HOST_TARGET { + assert_eq!( + context.target_pointer_size(), + std::mem::size_of::<*mut ()>(), + "{:?} {:?}", + effective_target, + HOST_TARGET + ); + } + } + { let _t = time::Timer::new("parse").with_output(time_phases); parse(&mut context)?; From 4299255c8a327ad3619ed9921823e85cbf880a95 Mon Sep 17 00:00:00 2001 From: Sebastian Imlay Date: Mon, 27 Jul 2020 13:00:51 -0700 Subject: [PATCH 073/942] Added Bindgen names to objective-c pointer return types * Took advantage of the repr transparent to use Bindgen return type names. * Updated unit tests and book --- book/src/objc.md | 9 +++ src/codegen/mod.rs | 25 ++++++-- tests/expectations/tests/objc_class.rs | 2 +- tests/expectations/tests/objc_class_method.rs | 4 +- .../expectations/tests/objc_interface_type.rs | 6 +- tests/expectations/tests/objc_method.rs | 4 +- .../tests/objc_pointer_return_types.rs | 59 +++++++++++++++++++ tests/headers/objc_pointer_return_types.h | 10 ++++ 8 files changed, 105 insertions(+), 14 deletions(-) create mode 100644 tests/expectations/tests/objc_pointer_return_types.rs create mode 100644 tests/headers/objc_pointer_return_types.h diff --git a/book/src/objc.md b/book/src/objc.md index 7c2892aaa9..c7c97811fd 100644 --- a/book/src/objc.md +++ b/book/src/objc.md @@ -17,6 +17,15 @@ The objective-c classes will be represented as a `struct Foo(id)` and a trait objc::runtime::Object` (the pointer to the objective-c instance). The trait `IFoo` is needed to allow for the generated inheritance. +Functions that use or return objective-c pointers of instance `Foo` will return +`Foo`. The reason this works is beacuse `Foo` represented as `transparent`. +This will be helpful for a lot of objective-c frameworks however there are some +cases where functions return `instancetype` which is a type alias for `id` so +an occasional `foo.0` may be required. An example of this would in the UIKit +framework should you want to add a `UILabel` to a +[UIStackView](https://developer.apple.com/documentation/uikit/uistackview/1616227-addarrangedsubview?language=objc) +you will need to convert the `UILabel` to a `UIView` via `UIView(label.0)`. + Each class (struct) has an `alloc` and a `dealloc` to match that of some of the alloc methods found in `NSObject`. diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index de46bb2269..ccfa622c6c 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -3512,6 +3512,14 @@ impl TryToRustTy for Type { inner.into_resolver().through_type_refs().resolve(ctx); let inner_ty = inner.expect_type(); + let is_objc_pointer = + inner.kind().as_type().map_or(false, |ty| { + match ty.kind() { + TypeKind::ObjCInterface(..) => true, + _ => false, + } + }); + // Regardless if we can properly represent the inner type, we // should always generate a proper pointer here, so use // infallible conversion of the inner type. @@ -3520,7 +3528,8 @@ impl TryToRustTy for Type { // Avoid the first function pointer level, since it's already // represented in Rust. - if inner_ty.canonical_type(ctx).is_function() { + if inner_ty.canonical_type(ctx).is_function() || is_objc_pointer + { Ok(ty) } else { Ok(ty.to_ptr(is_const)) @@ -3539,9 +3548,12 @@ impl TryToRustTy for Type { TypeKind::ObjCId => Ok(quote! { id }), - TypeKind::ObjCInterface(..) => Ok(quote! { - objc::runtime::Object - }), + TypeKind::ObjCInterface(ref interface) => { + let name = ctx.rust_ident(interface.name()); + Ok(quote! { + #name + }) + } ref u @ TypeKind::UnresolvedTypeRef(..) => { unreachable!("Should have been resolved after parsing {:?}!", u) } @@ -4395,11 +4407,12 @@ mod utils { TypeKind::Pointer(inner) => { let inner = ctx.resolve_item(inner); let inner_ty = inner.expect_type(); - if let TypeKind::ObjCInterface(_) = + if let TypeKind::ObjCInterface(ref interface) = *inner_ty.canonical_type(ctx).kind() { + let name = ctx.rust_ident(interface.name()); quote! { - id + #name } } else { arg_item.to_rust_ty_or_opaque(ctx, &()) diff --git a/tests/expectations/tests/objc_class.rs b/tests/expectations/tests/objc_class.rs index 237b86b4ec..a1de91fb99 100644 --- a/tests/expectations/tests/objc_class.rs +++ b/tests/expectations/tests/objc_class.rs @@ -11,7 +11,7 @@ extern crate objc; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; extern "C" { - pub static mut fooVar: *mut objc::runtime::Object; + pub static mut fooVar: Foo; } #[repr(transparent)] #[derive(Clone, Copy)] diff --git a/tests/expectations/tests/objc_class_method.rs b/tests/expectations/tests/objc_class_method.rs index e0a3803c26..d28a233da2 100644 --- a/tests/expectations/tests/objc_class_method.rs +++ b/tests/expectations/tests/objc_class_method.rs @@ -39,7 +39,7 @@ pub trait IFoo: Sized + std::ops::Deref { { msg_send!(class!(Foo), methodWithInt: foo) } - unsafe fn methodWithFoo_(foo: id) + unsafe fn methodWithFoo_(foo: Foo) where ::Target: objc::Message + Sized, { @@ -51,7 +51,7 @@ pub trait IFoo: Sized + std::ops::Deref { { msg_send!(class!(Foo), methodReturningInt) } - unsafe fn methodReturningFoo() -> *mut objc::runtime::Object + unsafe fn methodReturningFoo() -> Foo where ::Target: objc::Message + Sized, { diff --git a/tests/expectations/tests/objc_interface_type.rs b/tests/expectations/tests/objc_interface_type.rs index edbf412ca6..e8a1596378 100644 --- a/tests/expectations/tests/objc_interface_type.rs +++ b/tests/expectations/tests/objc_interface_type.rs @@ -30,7 +30,7 @@ pub trait IFoo: Sized + std::ops::Deref {} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct FooStruct { - pub foo: *mut objc::runtime::Object, + pub foo: Foo, } #[test] fn bindgen_test_layout_FooStruct() { @@ -63,8 +63,8 @@ impl Default for FooStruct { } } extern "C" { - pub fn fooFunc(foo: id); + pub fn fooFunc(foo: Foo); } extern "C" { - pub static mut kFoo: *const objc::runtime::Object; + pub static mut kFoo: Foo; } diff --git a/tests/expectations/tests/objc_method.rs b/tests/expectations/tests/objc_method.rs index 13e4d9f86d..e24768d28e 100644 --- a/tests/expectations/tests/objc_method.rs +++ b/tests/expectations/tests/objc_method.rs @@ -39,7 +39,7 @@ pub trait IFoo: Sized + std::ops::Deref { { msg_send!(self, methodWithInt: foo) } - unsafe fn methodWithFoo_(self, foo: id) + unsafe fn methodWithFoo_(self, foo: Foo) where ::Target: objc::Message + Sized, { @@ -51,7 +51,7 @@ pub trait IFoo: Sized + std::ops::Deref { { msg_send!(self, methodReturningInt) } - unsafe fn methodReturningFoo(self) -> *mut objc::runtime::Object + unsafe fn methodReturningFoo(self) -> Foo where ::Target: objc::Message + Sized, { diff --git a/tests/expectations/tests/objc_pointer_return_types.rs b/tests/expectations/tests/objc_pointer_return_types.rs new file mode 100644 index 0000000000..0f222c8b48 --- /dev/null +++ b/tests/expectations/tests/objc_pointer_return_types.rs @@ -0,0 +1,59 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] +#![cfg(target_os = "macos")] + +#[macro_use] +extern crate objc; +#[allow(non_camel_case_types)] +pub type id = *mut objc::runtime::Object; +#[repr(transparent)] +#[derive(Clone, Copy)] +pub struct Bar(pub id); +impl std::ops::Deref for Bar { + type Target = objc::runtime::Object; + fn deref(&self) -> &Self::Target { + unsafe { &*self.0 } + } +} +unsafe impl objc::Message for Bar {} +impl Bar { + pub fn alloc() -> Self { + Self(unsafe { msg_send!(objc::class!(Bar), alloc) }) + } +} +impl IBar for Bar {} +pub trait IBar: Sized + std::ops::Deref {} +#[repr(transparent)] +#[derive(Clone, Copy)] +pub struct Foo(pub id); +impl std::ops::Deref for Foo { + type Target = objc::runtime::Object; + fn deref(&self) -> &Self::Target { + unsafe { &*self.0 } + } +} +unsafe impl objc::Message for Foo {} +impl Foo { + pub fn alloc() -> Self { + Self(unsafe { msg_send!(objc::class!(Foo), alloc) }) + } +} +impl IFoo for Foo {} +pub trait IFoo: Sized + std::ops::Deref { + unsafe fn methodUsingBar_(self, my_bar: Bar) + where + ::Target: objc::Message + Sized, + { + msg_send!(self, methodUsingBar: my_bar) + } + unsafe fn methodReturningBar() -> Bar + where + ::Target: objc::Message + Sized, + { + msg_send!(class!(Foo), methodReturningBar) + } +} diff --git a/tests/headers/objc_pointer_return_types.h b/tests/headers/objc_pointer_return_types.h new file mode 100644 index 0000000000..e289a8a53d --- /dev/null +++ b/tests/headers/objc_pointer_return_types.h @@ -0,0 +1,10 @@ +// bindgen-flags: --objc-extern-crate -- -x objective-c +// bindgen-osx-only + +@interface Bar +@end + +@interface Foo ++ (Bar*)methodReturningBar; +- (void)methodUsingBar:(Bar *)my_bar; +@end From 18ed6f418ec40d57d7e9f658416f47d3e7b5c6af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sat, 15 Aug 2020 13:57:59 +0200 Subject: [PATCH 074/942] codegen: Simplify a bit the code in #1847 --- src/codegen/mod.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index ccfa622c6c..60e0e5929f 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -3512,13 +3512,10 @@ impl TryToRustTy for Type { inner.into_resolver().through_type_refs().resolve(ctx); let inner_ty = inner.expect_type(); - let is_objc_pointer = - inner.kind().as_type().map_or(false, |ty| { - match ty.kind() { - TypeKind::ObjCInterface(..) => true, - _ => false, - } - }); + let is_objc_pointer = match inner_ty.kind() { + TypeKind::ObjCInterface(..) => true, + _ => false, + }; // Regardless if we can properly represent the inner type, we // should always generate a proper pointer here, so use From c15355306c04a08daad1bc3337fa557b62b9c797 Mon Sep 17 00:00:00 2001 From: Kyle Mayes Date: Sat, 8 Aug 2020 14:40:13 -0400 Subject: [PATCH 075/942] Bump MSRV to 1.40.0 The libloading crate is used for runtime linking and since 0.6.0 it has a MSRV of 1.40.0 --- README.md | 2 +- ci/script.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1268d06e1d..bd687858bf 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ extern "C" { ## MSRV -The minimum supported Rust version is **1.34**. +The minimum supported Rust version is **1.40**. No MSRV bump policy has been established yet, so MSRV may increase in any release. diff --git a/ci/script.sh b/ci/script.sh index 967defc1e6..16eddbf81d 100755 --- a/ci/script.sh +++ b/ci/script.sh @@ -31,8 +31,8 @@ case "$BINDGEN_JOB" in # This test should not use Cargo.lock as it's ignored for library builds rm Cargo.lock # The MSRV below is also documented in README.md, please keep in sync - rustup install 1.34.0 - cargo +1.34.0 build --lib $NO_DEFAULT_FEATURES --features "$BINDGEN_FEATURES" + rustup install 1.40.0 + cargo +1.40.0 build --lib $NO_DEFAULT_FEATURES --features "$BINDGEN_FEATURES" ;; "integration") From 704b9eece3b98ca40af109d22ecd8afa55af2c62 Mon Sep 17 00:00:00 2001 From: Kyle Mayes Date: Tue, 14 Jul 2020 01:17:29 -0400 Subject: [PATCH 076/942] Update to clang-sys 1.0.0 --- Cargo.lock | 19 ++++++------------- Cargo.toml | 2 +- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 554235ee01..31096b5f45 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -32,7 +32,7 @@ dependencies = [ "bitflags 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "cexpr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "clang-sys 0.29.0 (registry+https://github.com/rust-lang/crates.io-index)", + "clang-sys 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", "diff 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -58,11 +58,6 @@ name = "byteorder" version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "cc" -version = "1.0.45" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "cexpr" version = "0.4.0" @@ -78,12 +73,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "clang-sys" -version = "0.29.0" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", - "libloading 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libloading 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -147,10 +142,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libloading" -version = "0.5.2" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -330,10 +324,9 @@ dependencies = [ "checksum atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "1803c647a3ec87095e7ae7acfca019e98de5ec9a7d01343f611cf3152ed71a90" "checksum bitflags 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8a606a02debe2813760609f57a64a2ffd27d9fdf5b2f133eaca0b248dd92cdd2" "checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5" -"checksum cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)" = "4fc9a35e1f4290eb9e5fc54ba6cf40671ed2a2514c3eeb2b2a908dda2ea5a1be" "checksum cexpr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f4aedb84272dbe89af497cf81375129abda4fc0a9e7c5d317498c15cc30c0d27" "checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" -"checksum clang-sys 0.29.0 (registry+https://github.com/rust-lang/crates.io-index)" = "03542fa2ed0accba4a5c84ec031f09a20b725e7ba1b1c9b79f1feb4aa17d0c07" +"checksum clang-sys 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9da1484c6a890e374ca5086062d4847e0a2c1e5eba9afa5d48c09e8eb39b2519" "checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" "checksum diff 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "3c2b69f912779fbb121ceb775d74d51e915af17aaebc38d28a592843a2dd0a3a" "checksum env_logger 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "39ecdb7dd54465526f0a56d666e3b2dd5f3a218665a030b6e4ad9e70fa95d8fa" @@ -342,7 +335,7 @@ dependencies = [ "checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" "checksum lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" "checksum libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)" = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558" -"checksum libloading 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f2b111a074963af1d37a139918ac6d49ad1d0d5e47f72fd55388619691a7d753" +"checksum libloading 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2cadb8e769f070c45df05c78c7520eb4cd17061d4ab262e43cfc68b4d00ac71c" "checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" "checksum memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "88579771288728879b57485cc7d6b07d648c9f0141eb955f8ab7f9d45394468e" "checksum nom 5.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b471253da97532da4b61552249c521e01e736071f71c1a4f7ebbfbf0a06aad6" diff --git a/Cargo.toml b/Cargo.toml index 8f93ede1bc..ddf9b5aa23 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,7 +50,7 @@ cexpr = "0.4" cfg-if = "0.1.0" # This kinda sucks: https://github.com/rust-lang/cargo/issues/1982 clap = { version = "2", optional = true } -clang-sys = { version = "0.29", features = ["clang_6_0"] } +clang-sys = { version = "1", features = ["clang_6_0"] } lazycell = "1" lazy_static = "1" peeking_take_while = "0.1.2" From 7ed01270a54b811c73b16bc20b8ec8e52ddbfcf3 Mon Sep 17 00:00:00 2001 From: Audrius Date: Fri, 21 Aug 2020 17:40:29 +0300 Subject: [PATCH 077/942] Added constructor return type for wasm32 target --- src/ir/context.rs | 8 ++++++++ src/ir/function.rs | 10 +++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/ir/context.rs b/src/ir/context.rs index 79c682e049..bb0c3f9dc9 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -577,6 +577,14 @@ If you encounter an error missing from this list, please file an issue or a PR!" } } + /// Returns `true` if the target architecture is wasm32 + pub fn is_target_wasm32(&self) -> bool { + match self.target_info { + Some(ref ti) => ti.triple.starts_with("wasm32-"), + None => false, + } + } + /// Creates a timer for the current bindgen phase. If time_phases is `true`, /// the timer will print to stderr when it is dropped, otherwise it will do /// nothing. diff --git a/src/ir/function.rs b/src/ir/function.rs index 93a8d89fcd..0eecf9606f 100644 --- a/src/ir/function.rs +++ b/src/ir/function.rs @@ -495,7 +495,15 @@ impl FunctionSig { } else { ty.ret_type().ok_or(ParseError::Continue)? }; - let ret = Item::from_ty_or_ref(ty_ret_type, cursor, None, ctx); + + let ret = if ctx.is_target_wasm32() && is_constructor { + // Constructors in Clang wasm32 target return a pointer to the object + // being constructed. + let void = Item::builtin_type(TypeKind::Void, false, ctx); + Item::builtin_type(TypeKind::Pointer(void), false, ctx) + } else { + Item::from_ty_or_ref(ty_ret_type, cursor, None, ctx) + }; // Clang plays with us at "find the calling convention", see #549 and // co. This seems to be a better fix than that commit. From 6653d0c0ae5a5c2e134adf3362bd2df93fbcf722 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 23 Aug 2020 20:08:55 +0200 Subject: [PATCH 078/942] Document that 0.54.1 has been yanked. --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 279ba09ca5..f5889be0fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -139,6 +139,8 @@ Released YYYY/MM/DD Released 2020/07/06. +**Yanked**: The change in #1798 is technically breaking, see PR for details. + ## Added * Added ParseCallbacks::func_macro to be able to process function-like macros. From f4d0b7c6529a23506e1de185cfbfc90a7e5b17d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 23 Aug 2020 20:37:53 +0200 Subject: [PATCH 079/942] lib: Fix inferred target when clang target differs from rust target. Fixes #1211. --- src/lib.rs | 56 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 4317561bb9..08b9381785 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1917,6 +1917,17 @@ pub struct Bindings { pub(crate) const HOST_TARGET: &'static str = include_str!(concat!(env!("OUT_DIR"), "/host-target.txt")); +// Some architecture triplets are different between rust and libclang, see #1211 +// and duplicates. +fn rust_to_clang_target(rust_target: &str) -> String { + if rust_target.starts_with("aarch64-apple-") { + let mut clang_target = "arm64-apple-".to_owned(); + clang_target.push_str(&rust_target["aarch64-apple-".len()..]); + return clang_target; + } + rust_target.to_owned() +} + /// Returns the effective target, and whether it was explicitly specified on the /// clang flags. fn find_effective_target(clang_args: &[String]) -> (String, bool) { @@ -1937,10 +1948,10 @@ fn find_effective_target(clang_args: &[String]) -> (String, bool) { // If we're running from a build script, try to find the cargo target. if let Ok(t) = env::var("TARGET") { - return (t, false); + return (rust_to_clang_target(&t), false); } - (HOST_TARGET.to_owned(), false) + (rust_to_clang_target(HOST_TARGET), false) } impl Bindings { @@ -1963,12 +1974,15 @@ impl Bindings { let (effective_target, explicit_target) = find_effective_target(&options.clang_args); - // NOTE: The effective_target == HOST_TARGET check wouldn't be sound - // normally in some cases if we were to call a binary (if you have a - // 32-bit clang and are building on a 64-bit system for example). - // But since we rely on opening libclang.so, it has to be the same - // architecture and thus the check is fine. - if !(explicit_target || effective_target == HOST_TARGET) { + let is_host_build = + rust_to_clang_target(HOST_TARGET) == effective_target; + + // NOTE: The is_host_build check wouldn't be sound normally in some + // cases if we were to call a binary (if you have a 32-bit clang and are + // building on a 64-bit system for example). But since we rely on + // opening libclang.so, it has to be the same architecture and thus the + // check is fine. + if !explicit_target && !is_host_build { options .clang_args .insert(0, format!("--target={}", effective_target)); @@ -2088,17 +2102,14 @@ impl Bindings { let time_phases = options.time_phases; let mut context = BindgenContext::new(options); - #[cfg(debug_assertions)] - { - if effective_target == HOST_TARGET { - assert_eq!( - context.target_pointer_size(), - std::mem::size_of::<*mut ()>(), - "{:?} {:?}", - effective_target, - HOST_TARGET - ); - } + if is_host_build { + debug_assert_eq!( + context.target_pointer_size(), + std::mem::size_of::<*mut ()>(), + "{:?} {:?}", + effective_target, + HOST_TARGET + ); } { @@ -2109,7 +2120,7 @@ impl Bindings { let (items, options) = codegen::codegen(context); Ok(Bindings { - options: options, + options, module: quote! { #( #items )* }, @@ -2444,3 +2455,8 @@ fn commandline_flag_unit_test_function() { .iter() .all(|ref x| command_line_flags.contains(x),)); } + +#[test] +fn test_rust_to_clang_target() { + assert_eq!(rust_to_clang_target("aarch64-apple-ios"), "arm64-apple-ios"); +} From 0996486f0977e12f1a64f7730b3eca81659aa839 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 23 Aug 2020 20:27:03 +0200 Subject: [PATCH 080/942] Release v0.55.0 --- CHANGELOG.md | 154 ++++++++++++++++++++++++++++++++++----------------- Cargo.lock | 2 +- Cargo.toml | 2 +- 3 files changed, 105 insertions(+), 53 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f5889be0fe..1c5fca5ad5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,97 +9,106 @@ - [Removed](#removed) - [Fixed](#fixed) - [Security](#security) -- [0.54.0](#0540) +- [0.55.0](#0550) + - [Removed](#removed-1) - [Added](#added-1) - [Changed](#changed-1) - [Fixed](#fixed-1) -- [0.53.3](#0533) +- [0.54.1](#0541) - [Added](#added-2) - - [Fixed](#fixed-2) -- [0.53.2](#0532) - [Changed](#changed-2) -- [0.53.1](#0531) + - [Fixed](#fixed-2) +- [0.54.0](#0540) - [Added](#added-3) -- [0.53.0](#0530) - - [Added](#added-4) - [Changed](#changed-3) - [Fixed](#fixed-3) -- [0.52.0](#0520) - - [Added](#added-5) - - [Changed](#changed-4) +- [0.53.3](#0533) + - [Added](#added-4) - [Fixed](#fixed-4) -- [0.51.1](#0511) - - [Fixed](#fixed-5) - - [Changed](#changed-5) -- [0.51.0](#0510) - - [Fixed](#fixed-6) - - [Changed](#changed-6) +- [0.53.2](#0532) + - [Changed](#changed-4) +- [0.53.1](#0531) + - [Added](#added-5) +- [0.53.0](#0530) - [Added](#added-6) -- [0.50.0](#0500) + - [Changed](#changed-5) + - [Fixed](#fixed-5) +- [0.52.0](#0520) - [Added](#added-7) -- [0.49.3](#0493) - - [Added](#added-8) -- [0.49.2](#0492) - - [Changed](#changed-7) -- [0.49.1](#0491) + - [Changed](#changed-6) + - [Fixed](#fixed-6) +- [0.51.1](#0511) - [Fixed](#fixed-7) + - [Changed](#changed-7) +- [0.51.0](#0510) + - [Fixed](#fixed-8) - [Changed](#changed-8) -- [0.49.0](#0490) + - [Added](#added-8) +- [0.50.0](#0500) - [Added](#added-9) - - [Fixed](#fixed-8) +- [0.49.3](#0493) + - [Added](#added-10) +- [0.49.2](#0492) - [Changed](#changed-9) -- [0.48.1](#0481) +- [0.49.1](#0491) - [Fixed](#fixed-9) -- [0.48.0](#0480) - [Changed](#changed-10) +- [0.49.0](#0490) + - [Added](#added-11) - [Fixed](#fixed-10) -- [0.47.3](#0473) - [Changed](#changed-11) -- [0.47.2](#0472) +- [0.48.1](#0481) - [Fixed](#fixed-11) -- [0.47.1](#0471) +- [0.48.0](#0480) - [Changed](#changed-12) - [Fixed](#fixed-12) -- [0.47.0](#0470) +- [0.47.3](#0473) - [Changed](#changed-13) +- [0.47.2](#0472) - [Fixed](#fixed-13) -- [0.33.1 .. 0.46.0](#0331--0460) - - [Added](#added-10) - - [Removed](#removed-1) +- [0.47.1](#0471) - [Changed](#changed-14) - [Fixed](#fixed-14) -- [0.33.1](#0331) - - [Fixed](#fixed-15) -- [0.33.0](#0330) - - [Added](#added-11) +- [0.47.0](#0470) - [Changed](#changed-15) - - [Deprecated](#deprecated-1) + - [Fixed](#fixed-15) +- [0.33.1 .. 0.46.0](#0331--0460) + - [Added](#added-12) - [Removed](#removed-2) + - [Changed](#changed-16) - [Fixed](#fixed-16) - - [Security](#security-1) -- [0.32.2](#0322) +- [0.33.1](#0331) - [Fixed](#fixed-17) -- [0.32.1](#0321) - - [Fixed](#fixed-18) -- [0.32.0](#0320) - - [Added](#added-12) - - [Changed](#changed-16) - - [Fixed](#fixed-19) -- [0.31.0](#0310) +- [0.33.0](#0330) - [Added](#added-13) - [Changed](#changed-17) - - [Deprecated](#deprecated-2) + - [Deprecated](#deprecated-1) - [Removed](#removed-3) + - [Fixed](#fixed-18) + - [Security](#security-1) +- [0.32.2](#0322) + - [Fixed](#fixed-19) +- [0.32.1](#0321) - [Fixed](#fixed-20) -- [0.30.0](#0300) +- [0.32.0](#0320) - [Added](#added-14) - [Changed](#changed-18) - - [Deprecated](#deprecated-3) - [Fixed](#fixed-21) -- [0.29.0](#0290) +- [0.31.0](#0310) - [Added](#added-15) - [Changed](#changed-19) + - [Deprecated](#deprecated-2) + - [Removed](#removed-4) - [Fixed](#fixed-22) +- [0.30.0](#0300) + - [Added](#added-16) + - [Changed](#changed-20) + - [Deprecated](#deprecated-3) + - [Fixed](#fixed-23) +- [0.29.0](#0290) + - [Added](#added-17) + - [Changed](#changed-21) + - [Fixed](#fixed-24) @@ -135,6 +144,47 @@ Released YYYY/MM/DD -------------------------------------------------------------------------------- +# 0.55.0 + +Released 2020/08/23. + +## Removed + + * Support for libclang 3.8 has been removed (#1830). + +## Added + + * Added options to avoid deriving the Debug trait (#1858). + + * Added options to allow to override the default anonymous field prefix (#1859). + + * Added options to allow to override the default macro integer type from the + command line (#1863). + +## Changed + + * Typed anonymous enums now generate better code (#1850). + + * Objective-C bindings are more idiomatic now (#1847). + + * Updated to clang-sys 1.0. Minimum supported rust version is 1.40 as + a consequence of that change. + +## Fixed + + * Fixed constness of multi-dimensional arrays in some cases (#1861). + + * Fixed wrong target given to clang when compiling with a target which doesn't + match the target clang expects (#1870, #1878). + + * Fixed wrong flags being computed for cross-compilation cases where the target + wasn't explicitly provided via clang flags (#1872). + +Thanks again to all the awesome contributors that sent patches included in this +release! + +-------------------------------------------------------------------------------- + # 0.54.1 Released 2020/07/06. @@ -171,6 +221,8 @@ Released 2020/07/06. Thanks to all the awesome contributors that sent patches included in this release! +-------------------------------------------------------------------------------- + # 0.54.0 Released 2020/05/21. diff --git a/Cargo.lock b/Cargo.lock index 31096b5f45..25e878c0a0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -27,7 +27,7 @@ dependencies = [ [[package]] name = "bindgen" -version = "0.54.1" +version = "0.55.0" dependencies = [ "bitflags 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "cexpr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index ddf9b5aa23..41616e78be 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ readme = "README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.54.1" +version = "0.55.0" edition = "2018" build = "build.rs" From b1cefe2395fcf2e8f0d581ad0e0ccae49a45dcb5 Mon Sep 17 00:00:00 2001 From: Audrius Date: Mon, 24 Aug 2020 16:29:43 +0300 Subject: [PATCH 081/942] Optimized condition order, added regression test --- src/ir/function.rs | 2 +- .../tests/wasm-constructor-returns.rs | 40 +++++++++++++++++++ tests/headers/wasm-constructor-returns.hpp | 7 ++++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 tests/expectations/tests/wasm-constructor-returns.rs create mode 100644 tests/headers/wasm-constructor-returns.hpp diff --git a/src/ir/function.rs b/src/ir/function.rs index 0eecf9606f..a6f63a640e 100644 --- a/src/ir/function.rs +++ b/src/ir/function.rs @@ -496,7 +496,7 @@ impl FunctionSig { ty.ret_type().ok_or(ParseError::Continue)? }; - let ret = if ctx.is_target_wasm32() && is_constructor { + let ret = if is_constructor && ctx.is_target_wasm32() { // Constructors in Clang wasm32 target return a pointer to the object // being constructed. let void = Item::builtin_type(TypeKind::Void, false, ctx); diff --git a/tests/expectations/tests/wasm-constructor-returns.rs b/tests/expectations/tests/wasm-constructor-returns.rs new file mode 100644 index 0000000000..6d15c51f9d --- /dev/null +++ b/tests/expectations/tests/wasm-constructor-returns.rs @@ -0,0 +1,40 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[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, + concat!("Size of: ", stringify!(Foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)) + ); +} +extern "C" { + #[link_name = "\u{1}_ZN3FooC1Ei"] + pub fn Foo_Foo( + this: *mut Foo, + var: ::std::os::raw::c_int, + ) -> *mut ::std::os::raw::c_void; +} +impl Foo { + #[inline] + pub unsafe fn new(var: ::std::os::raw::c_int) -> Self { + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + Foo_Foo(__bindgen_tmp.as_mut_ptr(), var); + __bindgen_tmp.assume_init() + } +} diff --git a/tests/headers/wasm-constructor-returns.hpp b/tests/headers/wasm-constructor-returns.hpp new file mode 100644 index 0000000000..9e47032708 --- /dev/null +++ b/tests/headers/wasm-constructor-returns.hpp @@ -0,0 +1,7 @@ +// bindgen-flags: --generate constructors,types -- -fvisibility=default --target=wasm32-unknown-emscripten + +class Foo { +public: + Foo(int var); +}; + From d446a4f6f14e14eea61e14e45f4559701f1e2fd5 Mon Sep 17 00:00:00 2001 From: Audrius Date: Mon, 24 Aug 2020 21:50:18 +0300 Subject: [PATCH 082/942] Added expectation test files for clang 3.9 and 4 --- .../libclang-3.9/wasm-constructor-returns.rs | 37 +++++++++++++++++++ .../libclang-4/wasm-constructor-returns.rs | 37 +++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 tests/expectations/tests/libclang-3.9/wasm-constructor-returns.rs create mode 100644 tests/expectations/tests/libclang-4/wasm-constructor-returns.rs diff --git a/tests/expectations/tests/libclang-3.9/wasm-constructor-returns.rs b/tests/expectations/tests/libclang-3.9/wasm-constructor-returns.rs new file mode 100644 index 0000000000..f207d0d8e1 --- /dev/null +++ b/tests/expectations/tests/libclang-3.9/wasm-constructor-returns.rs @@ -0,0 +1,37 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[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, + concat!("Size of: ", stringify!(Foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)) + ); +} +extern "C" { + #[link_name = "\u{1}_ZN3FooC1Ei"] + pub fn Foo_Foo(this: *mut Foo, var: ::std::os::raw::c_int); +} +impl Foo { + #[inline] + pub unsafe fn new(var: ::std::os::raw::c_int) -> Self { + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + Foo_Foo(__bindgen_tmp.as_mut_ptr(), var); + __bindgen_tmp.assume_init() + } +} diff --git a/tests/expectations/tests/libclang-4/wasm-constructor-returns.rs b/tests/expectations/tests/libclang-4/wasm-constructor-returns.rs new file mode 100644 index 0000000000..f207d0d8e1 --- /dev/null +++ b/tests/expectations/tests/libclang-4/wasm-constructor-returns.rs @@ -0,0 +1,37 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[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, + concat!("Size of: ", stringify!(Foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)) + ); +} +extern "C" { + #[link_name = "\u{1}_ZN3FooC1Ei"] + pub fn Foo_Foo(this: *mut Foo, var: ::std::os::raw::c_int); +} +impl Foo { + #[inline] + pub unsafe fn new(var: ::std::os::raw::c_int) -> Self { + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + Foo_Foo(__bindgen_tmp.as_mut_ptr(), var); + __bindgen_tmp.assume_init() + } +} From bef180d353ca5b3cbc11e70588874af6a5e59b1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 24 Aug 2020 19:48:26 +0200 Subject: [PATCH 083/942] codegen: Do generate unnamed enums, as they can be referred to by members. Fixes #1880 --- src/codegen/mod.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 60e0e5929f..1ad413ffe2 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -2478,7 +2478,6 @@ impl<'a> EnumBuilder<'a> { repr: proc_macro2::TokenStream, enum_variation: EnumVariation, enum_codegen_depth: usize, - is_ty_named: bool, ) -> Self { let ident = Ident::new(name, Span::call_site()); @@ -2507,12 +2506,10 @@ impl<'a> EnumBuilder<'a> { EnumVariation::Consts => { let mut variants = Vec::new(); - if is_ty_named { - variants.push(quote! { - #( #attrs )* - pub type #ident = #repr; - }); - } + variants.push(quote! { + #( #attrs )* + pub type #ident = #repr; + }); EnumBuilder::Consts { repr, @@ -2901,7 +2898,6 @@ impl CodeGenerator for Enum { repr, variation, item.codegen_depth(ctx), - enum_ty.name().is_some(), ); // A map where we keep a value -> variant relation. From 428189cb41707713837982c21b694a68d276c92e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 24 Aug 2020 19:55:48 +0200 Subject: [PATCH 084/942] tests: Improve enum tests to avoid duplication, and add a test for #1880 --- .../tests/enum-default-bitfield.rs | 64 +++++++++++++++++++ .../expectations/tests/enum-default-consts.rs | 36 +++++++++++ .../expectations/tests/enum-default-module.rs | 38 +++++++++++ tests/expectations/tests/enum-default-rust.rs | 41 ++++++++++++ tests/expectations/tests/enum.rs | 50 ++++++++++++--- .../tests/enum_explicit_type_constants.rs | 1 + .../tests/issue-1025-unknown-enum-repr.rs | 1 + tests/headers/enum-default-bitfield.h | 10 +-- tests/headers/enum-default-consts.h | 10 +-- tests/headers/enum-default-module.h | 10 +-- tests/headers/enum-default-rust.h | 10 +-- tests/headers/enum.h | 10 ++- 12 files changed, 234 insertions(+), 47 deletions(-) diff --git a/tests/expectations/tests/enum-default-bitfield.rs b/tests/expectations/tests/enum-default-bitfield.rs index ebf5caa462..86a0449983 100644 --- a/tests/expectations/tests/enum-default-bitfield.rs +++ b/tests/expectations/tests/enum-default-bitfield.rs @@ -5,6 +5,70 @@ non_upper_case_globals )] +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct foo { + pub member: foo__bindgen_ty_1, +} +pub const foo_FOO_A: foo__bindgen_ty_1 = foo__bindgen_ty_1(0); +pub const foo_FOO_B: foo__bindgen_ty_1 = foo__bindgen_ty_1(1); +impl ::std::ops::BitOr for foo__bindgen_ty_1 { + type Output = Self; + #[inline] + fn bitor(self, other: Self) -> Self { + foo__bindgen_ty_1(self.0 | other.0) + } +} +impl ::std::ops::BitOrAssign for foo__bindgen_ty_1 { + #[inline] + fn bitor_assign(&mut self, rhs: foo__bindgen_ty_1) { + self.0 |= rhs.0; + } +} +impl ::std::ops::BitAnd for foo__bindgen_ty_1 { + type Output = Self; + #[inline] + fn bitand(self, other: Self) -> Self { + foo__bindgen_ty_1(self.0 & other.0) + } +} +impl ::std::ops::BitAndAssign for foo__bindgen_ty_1 { + #[inline] + fn bitand_assign(&mut self, rhs: foo__bindgen_ty_1) { + self.0 &= rhs.0; + } +} +#[repr(transparent)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +pub struct foo__bindgen_ty_1(pub ::std::os::raw::c_uint); +#[test] +fn bindgen_test_layout_foo() { + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).member as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(member) + ) + ); +} +impl Default for foo { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} impl Foo { pub const Bar: Foo = Foo(0); } diff --git a/tests/expectations/tests/enum-default-consts.rs b/tests/expectations/tests/enum-default-consts.rs index ab49663063..1f086791b9 100644 --- a/tests/expectations/tests/enum-default-consts.rs +++ b/tests/expectations/tests/enum-default-consts.rs @@ -5,6 +5,42 @@ non_upper_case_globals )] +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct foo { + pub member: foo__bindgen_ty_1, +} +pub const foo_FOO_A: ::std::os::raw::c_uint = 0; +pub const foo_FOO_B: ::std::os::raw::c_uint = 1; +pub type foo__bindgen_ty_1 = ::std::os::raw::c_uint; +#[test] +fn bindgen_test_layout_foo() { + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).member as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(member) + ) + ); +} +impl Default for foo { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} pub const Foo_Bar: Foo = 0; pub const Foo_Qux: Foo = 1; pub type Foo = ::std::os::raw::c_uint; diff --git a/tests/expectations/tests/enum-default-module.rs b/tests/expectations/tests/enum-default-module.rs index a81e6ad023..7eb63a95db 100644 --- a/tests/expectations/tests/enum-default-module.rs +++ b/tests/expectations/tests/enum-default-module.rs @@ -5,6 +5,44 @@ non_upper_case_globals )] +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct foo { + pub member: foo__bindgen_ty_1::Type, +} +pub mod foo__bindgen_ty_1 { + pub type Type = ::std::os::raw::c_uint; + pub const FOO_A: Type = 0; + pub const FOO_B: Type = 1; +} +#[test] +fn bindgen_test_layout_foo() { + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).member as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(member) + ) + ); +} +impl Default for foo { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} pub mod Foo { pub type Type = ::std::os::raw::c_uint; pub const Bar: Type = 0; diff --git a/tests/expectations/tests/enum-default-rust.rs b/tests/expectations/tests/enum-default-rust.rs index b497a5a3f2..788de139d8 100644 --- a/tests/expectations/tests/enum-default-rust.rs +++ b/tests/expectations/tests/enum-default-rust.rs @@ -5,6 +5,47 @@ non_upper_case_globals )] +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct foo { + pub member: foo__bindgen_ty_1, +} +pub const foo_FOO_A: foo__bindgen_ty_1 = foo__bindgen_ty_1::FOO_A; +pub const foo_FOO_B: foo__bindgen_ty_1 = foo__bindgen_ty_1::FOO_B; +#[repr(u32)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +pub enum foo__bindgen_ty_1 { + FOO_A = 0, + FOO_B = 1, +} +#[test] +fn bindgen_test_layout_foo() { + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).member as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(member) + ) + ); +} +impl Default for foo { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} #[repr(u32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum Foo { diff --git a/tests/expectations/tests/enum.rs b/tests/expectations/tests/enum.rs index 27a1f41bad..3a1bffcb40 100644 --- a/tests/expectations/tests/enum.rs +++ b/tests/expectations/tests/enum.rs @@ -5,15 +5,45 @@ non_upper_case_globals )] -#[repr(u32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub enum Foo { - Bar = 0, - Qux = 1, +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct foo { + pub member: foo__bindgen_ty_1, } -#[repr(i32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub enum Neg { - MinusOne = -1, - One = 1, +pub const foo_FOO_A: ::std::os::raw::c_uint = 0; +pub const foo_FOO_B: ::std::os::raw::c_uint = 1; +pub type foo__bindgen_ty_1 = ::std::os::raw::c_uint; +#[test] +fn bindgen_test_layout_foo() { + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).member as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(member) + ) + ); } +impl Default for foo { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +pub const Foo_Bar: Foo = 0; +pub const Foo_Qux: Foo = 1; +pub type Foo = ::std::os::raw::c_uint; +pub const Neg_MinusOne: Neg = -1; +pub const Neg_One: Neg = 1; +pub type Neg = ::std::os::raw::c_int; diff --git a/tests/expectations/tests/enum_explicit_type_constants.rs b/tests/expectations/tests/enum_explicit_type_constants.rs index 9406c7f2d6..030d64bedc 100644 --- a/tests/expectations/tests/enum_explicit_type_constants.rs +++ b/tests/expectations/tests/enum_explicit_type_constants.rs @@ -27,3 +27,4 @@ pub const BoolEnumsAreFun2_Value2: BoolEnumsAreFun2 = true; pub type BoolEnumsAreFun2 = MyType; pub const AnonymousVariantOne: ::std::os::raw::c_uchar = 0; pub const AnonymousVariantTwo: ::std::os::raw::c_uchar = 1; +pub type _bindgen_ty_1 = ::std::os::raw::c_uchar; diff --git a/tests/expectations/tests/issue-1025-unknown-enum-repr.rs b/tests/expectations/tests/issue-1025-unknown-enum-repr.rs index 1516c0a95e..c42e167fba 100644 --- a/tests/expectations/tests/issue-1025-unknown-enum-repr.rs +++ b/tests/expectations/tests/issue-1025-unknown-enum-repr.rs @@ -10,3 +10,4 @@ pub struct a { pub _address: u8, } +pub type a__bindgen_ty_1 = i32; diff --git a/tests/headers/enum-default-bitfield.h b/tests/headers/enum-default-bitfield.h index be2841329b..5f3cb95468 100644 --- a/tests/headers/enum-default-bitfield.h +++ b/tests/headers/enum-default-bitfield.h @@ -1,11 +1,3 @@ // bindgen-flags: --default-enum-style=bitfield --constified-enum-module=Neg -enum Foo { - Bar = 0, - Qux -}; - -enum Neg { - MinusOne = -1, - One = 1, -}; +#include "enum.h" diff --git a/tests/headers/enum-default-consts.h b/tests/headers/enum-default-consts.h index 448c3030a8..233d2718a4 100644 --- a/tests/headers/enum-default-consts.h +++ b/tests/headers/enum-default-consts.h @@ -1,11 +1,3 @@ // bindgen-flags: --default-enum-style=consts --constified-enum-module=Neg -enum Foo { - Bar = 0, - Qux -}; - -enum Neg { - MinusOne = -1, - One = 1, -}; +#include "enum.h" diff --git a/tests/headers/enum-default-module.h b/tests/headers/enum-default-module.h index a2f3d7adfd..8c2ec1bca4 100644 --- a/tests/headers/enum-default-module.h +++ b/tests/headers/enum-default-module.h @@ -1,11 +1,3 @@ // bindgen-flags: --default-enum-style=moduleconsts --constified-enum-module=Neg -enum Foo { - Bar = 0, - Qux -}; - -enum Neg { - MinusOne = -1, - One = 1, -}; +#include "enum.h" diff --git a/tests/headers/enum-default-rust.h b/tests/headers/enum-default-rust.h index 282c62f3ff..7fd2999fe0 100644 --- a/tests/headers/enum-default-rust.h +++ b/tests/headers/enum-default-rust.h @@ -1,11 +1,3 @@ // bindgen-flags: --default-enum-style=rust --constified-enum-module=Neg -enum Foo { - Bar = 0, - Qux -}; - -enum Neg { - MinusOne = -1, - One = 1, -}; +#include "enum.h" diff --git a/tests/headers/enum.h b/tests/headers/enum.h index f04c213e4f..901b805814 100644 --- a/tests/headers/enum.h +++ b/tests/headers/enum.h @@ -1,4 +1,12 @@ -// bindgen-flags: --rustified-enum ".*" +// A few tests for enum-related issues that should be tested with all the enum +// representations. + +struct foo { + enum { + FOO_A, + FOO_B, + } member; +}; enum Foo { Bar = 0, From d492ac4ae11ba7403acd533813982b052c5020a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 24 Aug 2020 20:00:18 +0200 Subject: [PATCH 085/942] v0.55.1 --- CHANGELOG.md | 11 +++++++++++ Cargo.lock | 2 +- Cargo.toml | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c5fca5ad5..4ab8200986 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -144,6 +144,17 @@ Released YYYY/MM/DD -------------------------------------------------------------------------------- +# 0.55.1 + +Released 2020/08/24. + +## Fixed + + * Fixed a regression where anonymous enums referenced by members or such won't + generate valid Rust code. (#1882). + +-------------------------------------------------------------------------------- + # 0.55.0 Released 2020/08/23. diff --git a/Cargo.lock b/Cargo.lock index 25e878c0a0..b4a5544398 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -27,7 +27,7 @@ dependencies = [ [[package]] name = "bindgen" -version = "0.55.0" +version = "0.55.1" dependencies = [ "bitflags 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "cexpr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 41616e78be..7ab43a21dc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ readme = "README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.55.0" +version = "0.55.1" edition = "2018" build = "build.rs" From 91d9600c33260202f3b438f14ad077be3bdc81e7 Mon Sep 17 00:00:00 2001 From: Adrian Taylor Date: Fri, 28 Aug 2020 15:25:21 -0700 Subject: [PATCH 086/942] Allow grepping bindings for multiple patterns. --- csmith-fuzzing/predicate.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/csmith-fuzzing/predicate.py b/csmith-fuzzing/predicate.py index 043a993534..8925755c62 100755 --- a/csmith-fuzzing/predicate.py +++ b/csmith-fuzzing/predicate.py @@ -80,6 +80,7 @@ reducing.add_argument( "--bindings-grep", type=str, + nargs='*', help="Exit non-zero if the given regexp pattern is not found in the emitted bindings.") reducing.add_argument( @@ -218,11 +219,11 @@ def run_bindgen(args, bindings): if not args.expect_bindgen_fail and child.returncode != 0: exit_1("Error: running `bindgen` failed", child) - if args.bindings_grep: - pattern = regexp(args.bindings_grep) + for arg in args.bindings_grep: + pattern = regexp(arg) with open(bindings, mode="r") as f: if not contains(pattern, f): - print("Error: expected the emitted bindings to contain '{}', but they didn't".format(args.bindings_grep)) + print("Error: expected the emitted bindings to contain '{}', but they didn't".format(arg)) print("---------- {} ----------------------------------------------".format(bindings)) f.seek(0) print(f.read()) From 57db7232b784f0bd69b9a019923b0a5b30a3eeae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sat, 29 Aug 2020 17:56:56 +0200 Subject: [PATCH 087/942] codegen: Use shorthand initialization in VTable::new. --- src/codegen/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 1ad413ffe2..4b51d21603 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -987,9 +987,9 @@ impl<'a> Vtable<'a> { base_classes: &'a [Base], ) -> Self { Vtable { - item_id: item_id, - methods: methods, - base_classes: base_classes, + item_id, + methods, + base_classes, } } } From f2214790c8e6a5ce2e599564b8f5340d7abca92f Mon Sep 17 00:00:00 2001 From: Youmu Date: Mon, 14 Sep 2020 01:22:24 -0400 Subject: [PATCH 088/942] Use path_for_whitelisting instead of canonical_path when matching for enum type specification and template opaque type specification --- src/ir/enum_ty.rs | 3 +-- src/ir/template.rs | 7 ++++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ir/enum_ty.rs b/src/ir/enum_ty.rs index 17996af65b..dde4bb1835 100644 --- a/src/ir/enum_ty.rs +++ b/src/ir/enum_ty.rs @@ -6,7 +6,6 @@ use super::item::Item; use super::ty::{Type, TypeKind}; use crate::clang; use crate::ir::annotations::Annotations; -use crate::ir::item::ItemCanonicalPath; use crate::parse::{ClangItemParser, ParseError}; use crate::regex_set::RegexSet; @@ -153,7 +152,7 @@ impl Enum { enums: &RegexSet, item: &Item, ) -> bool { - let path = item.canonical_path(ctx); + let path = item.path_for_whitelisting(ctx); let enum_ty = item.expect_type(); if enums.matches(&path[1..].join("::")) { diff --git a/src/ir/template.rs b/src/ir/template.rs index e2900e9579..8c625d1d92 100644 --- a/src/ir/template.rs +++ b/src/ir/template.rs @@ -28,7 +28,7 @@ //! ``` use super::context::{BindgenContext, ItemId, TypeId}; -use super::item::{IsOpaque, Item, ItemAncestors, ItemCanonicalPath}; +use super::item::{IsOpaque, Item, ItemAncestors}; use super::traversal::{EdgeKind, Trace, Tracer}; use crate::clang; use crate::parse::ClangItemParser; @@ -306,12 +306,13 @@ impl IsOpaque for TemplateInstantiation { // correct fix is to make `canonical_{name,path}` include template // arguments properly. - let mut path = item.canonical_path(ctx); + let mut path = item.path_for_whitelisting(ctx).clone(); let args: Vec<_> = self .template_arguments() .iter() .map(|arg| { - let arg_path = arg.canonical_path(ctx); + let arg_path = + ctx.resolve_item(*arg).path_for_whitelisting(ctx); arg_path[1..].join("::") }) .collect(); From f4d10c360453e91973cd08189af6185bb7c964c9 Mon Sep 17 00:00:00 2001 From: Youmu Date: Mon, 14 Sep 2020 16:04:34 -0400 Subject: [PATCH 089/942] Add integration test for name matching --- bindgen-integration/build.rs | 10 +++++++--- bindgen-integration/cpp/Test.cc | 2 +- bindgen-integration/cpp/Test.h | 17 +++++++++++++++++ bindgen-integration/src/lib.rs | 6 ++++++ 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs index 0a28e8f56b..1b9a79155a 100644 --- a/bindgen-integration/build.rs +++ b/bindgen-integration/build.rs @@ -1,8 +1,8 @@ extern crate bindgen; extern crate cc; -use bindgen::callbacks::{MacroParsingBehavior, ParseCallbacks, IntKind}; -use bindgen::Builder; +use bindgen::callbacks::{IntKind, MacroParsingBehavior, ParseCallbacks}; +use bindgen::{Builder, EnumVariation}; use std::collections::HashSet; use std::env; use std::path::PathBuf; @@ -147,7 +147,9 @@ fn main() { let bindings = Builder::default() .rustfmt_bindings(false) .enable_cxx_namespaces() - .rustified_enum(".*") + .default_enum_style(EnumVariation::Rust { + non_exhaustive: false, + }) .raw_line("pub use self::root::*;") .raw_line("extern { fn my_prefixed_function_to_remove(i: i32); }") .module_raw_line("root::testing", "pub type Bar = i32;") @@ -159,6 +161,8 @@ fn main() { seen_funcs: Mutex::new(0), })) .blacklist_function("my_prefixed_function_to_remove") + .constified_enum("my_prefixed_enum_to_be_constified") + .opaque_type("my_prefixed_templated_foo") .generate() .expect("Unable to generate bindings"); diff --git a/bindgen-integration/cpp/Test.cc b/bindgen-integration/cpp/Test.cc index c3d73411a3..240109bbe3 100644 --- a/bindgen-integration/cpp/Test.cc +++ b/bindgen-integration/cpp/Test.cc @@ -134,4 +134,4 @@ Seventh::assert(bool first, int my_prefixed_function_name() { return 4; -} \ No newline at end of file +} diff --git a/bindgen-integration/cpp/Test.h b/bindgen-integration/cpp/Test.h index f8b2263f6d..a9c5258c44 100644 --- a/bindgen-integration/cpp/Test.h +++ b/bindgen-integration/cpp/Test.h @@ -210,4 +210,21 @@ struct my_prefixed_foo { my_prefixed_bar member; }; +enum my_prefixed_enum_to_be_constified { + ONE = 1, + TWO, + THREE, +}; + +struct my_prefixed_baz { + char foo[30]; +}; + +template +struct my_prefixed_templated_foo { + T member; +}; + +my_prefixed_templated_foo TEMPLATED_CONST_VALUE; + void my_prefixed_function_to_remove(); diff --git a/bindgen-integration/src/lib.rs b/bindgen-integration/src/lib.rs index 45cf9bca5d..0468f23773 100755 --- a/bindgen-integration/src/lib.rs +++ b/bindgen-integration/src/lib.rs @@ -245,6 +245,12 @@ fn test_item_rename() { }; } +#[test] +fn test_matching_with_rename() { + assert_eq!(bindings::enum_to_be_constified_THREE, 3); + assert_eq!(unsafe { bindings::TEMPLATED_CONST_VALUE.len() }, 30); +} + #[test] fn test_macro_customintkind_path() { let v: &std::any::Any = &bindings::TESTMACRO_CUSTOMINTKIND_PATH; From 840b738ecfeefbd31d8676c60e2eca7ad6d0f424 Mon Sep 17 00:00:00 2001 From: Sebastian Imlay Date: Mon, 24 Aug 2020 14:21:03 -0700 Subject: [PATCH 090/942] Initial stuff for changing ownership and adding inheritance --- src/codegen/mod.rs | 17 +++++++++-- .../tests/libclang-9/objc_inheritance.rs | 21 +++++++++++-- .../tests/libclang-9/objc_template.rs | 12 ++++---- tests/expectations/tests/objc_category.rs | 10 +++---- tests/expectations/tests/objc_class.rs | 6 ++-- tests/expectations/tests/objc_class_method.rs | 2 +- tests/expectations/tests/objc_interface.rs | 2 +- .../expectations/tests/objc_interface_type.rs | 2 +- tests/expectations/tests/objc_method.rs | 30 +++++++++---------- tests/expectations/tests/objc_method_clash.rs | 6 ++-- .../tests/objc_pointer_return_types.rs | 8 ++--- .../expectations/tests/objc_property_fnptr.rs | 10 +++---- tests/expectations/tests/objc_protocol.rs | 2 +- 13 files changed, 77 insertions(+), 51 deletions(-) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 4b51d21603..7ae202bf96 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -3806,7 +3806,7 @@ fn objc_method_codegen( } } else { let fn_args = fn_args.clone(); - let args = iter::once(quote! { self }).chain(fn_args.into_iter()); + let args = iter::once(quote! { &self }).chain(fn_args.into_iter()); quote! { ( #( #args ),* ) #fn_ret } @@ -3825,7 +3825,7 @@ fn objc_method_codegen( } } else { quote! { - msg_send!(self, #methods_and_args) + msg_send!(*self, #methods_and_args) } }; @@ -3901,7 +3901,7 @@ impl CodeGenerator for ObjCInterface { if !self.is_category() && !self.is_protocol() { let struct_block = quote! { #[repr(transparent)] - #[derive(Clone, Copy)] + #[derive(Clone)] pub struct #class_name(pub id); impl std::ops::Deref for #class_name { type Target = objc::runtime::Object; @@ -3962,6 +3962,17 @@ impl CodeGenerator for ObjCInterface { } }; result.push(impl_trait); + if !parent.is_template() { + let parent_struct_name = ctx.rust_ident(parent.name()); + let from_block = quote! { + impl From<#class_name> for #parent_struct_name { + fn from(child: #class_name) -> #parent_struct_name { + #parent_struct_name(child.0) + } + } + }; + result.push(from_block); + } parent.parent_class } else { None diff --git a/tests/expectations/tests/libclang-9/objc_inheritance.rs b/tests/expectations/tests/libclang-9/objc_inheritance.rs index cd2b085dc3..ef16325e15 100644 --- a/tests/expectations/tests/libclang-9/objc_inheritance.rs +++ b/tests/expectations/tests/libclang-9/objc_inheritance.rs @@ -11,7 +11,7 @@ extern crate objc; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] -#[derive(Clone, Copy)] +#[derive(Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -28,7 +28,7 @@ impl Foo { impl IFoo for Foo {} pub trait IFoo: Sized + std::ops::Deref {} #[repr(transparent)] -#[derive(Clone, Copy)] +#[derive(Clone)] pub struct Bar(pub id); impl std::ops::Deref for Bar { type Target = objc::runtime::Object; @@ -43,10 +43,15 @@ impl Bar { } } impl IFoo for Bar {} +impl From for Foo { + fn from(child: Bar) -> Foo { + Foo(child.0) + } +} impl IBar for Bar {} pub trait IBar: Sized + std::ops::Deref {} #[repr(transparent)] -#[derive(Clone, Copy)] +#[derive(Clone)] pub struct Baz(pub id); impl std::ops::Deref for Baz { type Target = objc::runtime::Object; @@ -61,6 +66,16 @@ impl Baz { } } impl IBar for Baz {} +impl From for Bar { + fn from(child: Baz) -> Bar { + Bar(child.0) + } +} impl IFoo for Baz {} +impl From for Foo { + fn from(child: Baz) -> Foo { + Foo(child.0) + } +} impl IBaz for Baz {} pub trait IBaz: Sized + std::ops::Deref {} diff --git a/tests/expectations/tests/libclang-9/objc_template.rs b/tests/expectations/tests/libclang-9/objc_template.rs index 09cc739c1c..88cf209bdf 100644 --- a/tests/expectations/tests/libclang-9/objc_template.rs +++ b/tests/expectations/tests/libclang-9/objc_template.rs @@ -11,7 +11,7 @@ extern crate objc; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] -#[derive(Clone, Copy)] +#[derive(Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -27,15 +27,15 @@ impl Foo { } impl IFoo for Foo {} pub trait IFoo: Sized + std::ops::Deref { - unsafe fn get(self) -> u64 + unsafe fn get(&self) -> u64 where ::Target: objc::Message + Sized, { - msg_send!(self, get) + msg_send!(*self, get) } } #[repr(transparent)] -#[derive(Clone, Copy)] +#[derive(Clone)] pub struct FooMultiGeneric(pub id); impl std::ops::Deref for FooMultiGeneric { type Target = objc::runtime::Object; @@ -56,10 +56,10 @@ impl pub trait IFooMultiGeneric: Sized + std::ops::Deref { - unsafe fn objectForKey_(self, key: u64) -> u64 + unsafe fn objectForKey_(&self, key: u64) -> u64 where ::Target: objc::Message + Sized, { - msg_send!(self, objectForKey: key) + msg_send!(*self, objectForKey: key) } } diff --git a/tests/expectations/tests/objc_category.rs b/tests/expectations/tests/objc_category.rs index 2c39be96be..e0328c708f 100644 --- a/tests/expectations/tests/objc_category.rs +++ b/tests/expectations/tests/objc_category.rs @@ -11,7 +11,7 @@ extern crate objc; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] -#[derive(Clone, Copy)] +#[derive(Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -27,19 +27,19 @@ impl Foo { } impl IFoo for Foo {} pub trait IFoo: Sized + std::ops::Deref { - unsafe fn method(self) + unsafe fn method(&self) where ::Target: objc::Message + Sized, { - msg_send!(self, method) + msg_send!(*self, method) } } impl Foo_BarCategory for Foo {} pub trait Foo_BarCategory: Sized + std::ops::Deref { - unsafe fn categoryMethod(self) + unsafe fn categoryMethod(&self) where ::Target: objc::Message + Sized, { - msg_send!(self, categoryMethod) + msg_send!(*self, categoryMethod) } } diff --git a/tests/expectations/tests/objc_class.rs b/tests/expectations/tests/objc_class.rs index a1de91fb99..5a8a71d164 100644 --- a/tests/expectations/tests/objc_class.rs +++ b/tests/expectations/tests/objc_class.rs @@ -14,7 +14,7 @@ extern "C" { pub static mut fooVar: Foo; } #[repr(transparent)] -#[derive(Clone, Copy)] +#[derive(Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -30,10 +30,10 @@ impl Foo { } impl IFoo for Foo {} pub trait IFoo: Sized + std::ops::Deref { - unsafe fn method(self) + unsafe fn method(&self) where ::Target: objc::Message + Sized, { - msg_send!(self, method) + msg_send!(*self, method) } } diff --git a/tests/expectations/tests/objc_class_method.rs b/tests/expectations/tests/objc_class_method.rs index d28a233da2..d1f39b0c7d 100644 --- a/tests/expectations/tests/objc_class_method.rs +++ b/tests/expectations/tests/objc_class_method.rs @@ -11,7 +11,7 @@ extern crate objc; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] -#[derive(Clone, Copy)] +#[derive(Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; diff --git a/tests/expectations/tests/objc_interface.rs b/tests/expectations/tests/objc_interface.rs index 7cabf762af..c5ba2758b9 100644 --- a/tests/expectations/tests/objc_interface.rs +++ b/tests/expectations/tests/objc_interface.rs @@ -11,7 +11,7 @@ extern crate objc; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] -#[derive(Clone, Copy)] +#[derive(Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; diff --git a/tests/expectations/tests/objc_interface_type.rs b/tests/expectations/tests/objc_interface_type.rs index e8a1596378..2585df6ec1 100644 --- a/tests/expectations/tests/objc_interface_type.rs +++ b/tests/expectations/tests/objc_interface_type.rs @@ -11,7 +11,7 @@ extern crate objc; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] -#[derive(Clone, Copy)] +#[derive(Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; diff --git a/tests/expectations/tests/objc_method.rs b/tests/expectations/tests/objc_method.rs index e24768d28e..7c4fbd4309 100644 --- a/tests/expectations/tests/objc_method.rs +++ b/tests/expectations/tests/objc_method.rs @@ -11,7 +11,7 @@ extern crate objc; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] -#[derive(Clone, Copy)] +#[derive(Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -27,48 +27,48 @@ impl Foo { } impl IFoo for Foo {} pub trait IFoo: Sized + std::ops::Deref { - unsafe fn method(self) + unsafe fn method(&self) where ::Target: objc::Message + Sized, { - msg_send!(self, method) + msg_send!(*self, method) } - unsafe fn methodWithInt_(self, foo: ::std::os::raw::c_int) + unsafe fn methodWithInt_(&self, foo: ::std::os::raw::c_int) where ::Target: objc::Message + Sized, { - msg_send!(self, methodWithInt: foo) + msg_send!(*self, methodWithInt: foo) } - unsafe fn methodWithFoo_(self, foo: Foo) + unsafe fn methodWithFoo_(&self, foo: Foo) where ::Target: objc::Message + Sized, { - msg_send!(self, methodWithFoo: foo) + msg_send!(*self, methodWithFoo: foo) } - unsafe fn methodReturningInt(self) -> ::std::os::raw::c_int + unsafe fn methodReturningInt(&self) -> ::std::os::raw::c_int where ::Target: objc::Message + Sized, { - msg_send!(self, methodReturningInt) + msg_send!(*self, methodReturningInt) } - unsafe fn methodReturningFoo(self) -> Foo + unsafe fn methodReturningFoo(&self) -> Foo where ::Target: objc::Message + Sized, { - msg_send!(self, methodReturningFoo) + msg_send!(*self, methodReturningFoo) } unsafe fn methodWithArg1_andArg2_andArg3_( - self, + &self, intvalue: ::std::os::raw::c_int, ptr: *mut ::std::os::raw::c_char, floatvalue: f32, ) where ::Target: objc::Message + Sized, { - msg_send ! ( self , methodWithArg1 : intvalue andArg2 : ptr andArg3 : floatvalue ) + msg_send ! ( * self , methodWithArg1 : intvalue andArg2 : ptr andArg3 : floatvalue ) } unsafe fn methodWithAndWithoutKeywords_arg2Name__arg4Name_( - self, + &self, arg1: ::std::os::raw::c_int, arg2: f32, arg3: f32, @@ -77,7 +77,7 @@ pub trait IFoo: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - msg_send ! ( self , methodWithAndWithoutKeywords : arg1 arg2Name : arg2 arg3 : arg3 arg4Name : arg4 ) + msg_send ! ( * self , methodWithAndWithoutKeywords : arg1 arg2Name : arg2 arg3 : arg3 arg4Name : arg4 ) } } pub type instancetype = id; diff --git a/tests/expectations/tests/objc_method_clash.rs b/tests/expectations/tests/objc_method_clash.rs index ba741f8d3a..8370f33fc2 100644 --- a/tests/expectations/tests/objc_method_clash.rs +++ b/tests/expectations/tests/objc_method_clash.rs @@ -11,7 +11,7 @@ extern crate objc; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] -#[derive(Clone, Copy)] +#[derive(Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -27,11 +27,11 @@ impl Foo { } impl IFoo for Foo {} pub trait IFoo: Sized + std::ops::Deref { - unsafe fn foo(self) + unsafe fn foo(&self) where ::Target: objc::Message + Sized, { - msg_send!(self, foo) + msg_send!(*self, foo) } unsafe fn class_foo() where diff --git a/tests/expectations/tests/objc_pointer_return_types.rs b/tests/expectations/tests/objc_pointer_return_types.rs index 0f222c8b48..c9b6b52a6b 100644 --- a/tests/expectations/tests/objc_pointer_return_types.rs +++ b/tests/expectations/tests/objc_pointer_return_types.rs @@ -11,7 +11,7 @@ extern crate objc; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] -#[derive(Clone, Copy)] +#[derive(Clone)] pub struct Bar(pub id); impl std::ops::Deref for Bar { type Target = objc::runtime::Object; @@ -28,7 +28,7 @@ impl Bar { impl IBar for Bar {} pub trait IBar: Sized + std::ops::Deref {} #[repr(transparent)] -#[derive(Clone, Copy)] +#[derive(Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -44,11 +44,11 @@ impl Foo { } impl IFoo for Foo {} pub trait IFoo: Sized + std::ops::Deref { - unsafe fn methodUsingBar_(self, my_bar: Bar) + unsafe fn methodUsingBar_(&self, my_bar: Bar) where ::Target: objc::Message + Sized, { - msg_send!(self, methodUsingBar: my_bar) + msg_send!(*self, methodUsingBar: my_bar) } unsafe fn methodReturningBar() -> Bar where diff --git a/tests/expectations/tests/objc_property_fnptr.rs b/tests/expectations/tests/objc_property_fnptr.rs index b9bcf306d8..85f18e9c18 100644 --- a/tests/expectations/tests/objc_property_fnptr.rs +++ b/tests/expectations/tests/objc_property_fnptr.rs @@ -11,7 +11,7 @@ extern crate objc; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] -#[derive(Clone, Copy)] +#[derive(Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -28,7 +28,7 @@ impl Foo { impl IFoo for Foo {} pub trait IFoo: Sized + std::ops::Deref { unsafe fn func( - self, + &self, ) -> ::std::option::Option< unsafe extern "C" fn( arg1: ::std::os::raw::c_char, @@ -39,10 +39,10 @@ pub trait IFoo: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - msg_send!(self, func) + msg_send!(*self, func) } unsafe fn setFunc_( - self, + &self, func: ::std::option::Option< unsafe extern "C" fn( arg1: ::std::os::raw::c_char, @@ -53,6 +53,6 @@ pub trait IFoo: Sized + std::ops::Deref { ) where ::Target: objc::Message + Sized, { - msg_send!(self, setFunc: func) + msg_send!(*self, setFunc: func) } } diff --git a/tests/expectations/tests/objc_protocol.rs b/tests/expectations/tests/objc_protocol.rs index 5a659b2cbb..e68ddcc1d2 100644 --- a/tests/expectations/tests/objc_protocol.rs +++ b/tests/expectations/tests/objc_protocol.rs @@ -12,7 +12,7 @@ extern crate objc; pub type id = *mut objc::runtime::Object; pub trait PFoo: Sized + std::ops::Deref {} #[repr(transparent)] -#[derive(Clone, Copy)] +#[derive(Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; From 81d323d8b1f81f298e59cd72eff5e57e381f55ac Mon Sep 17 00:00:00 2001 From: Sebastian Imlay Date: Fri, 28 Aug 2020 16:30:47 -0700 Subject: [PATCH 091/942] Updates base on comments * Added TryInto trait implementation from parent to child interfaces. * Added HashSet for protocols so that the protocol inheritance works as well. --- src/codegen/mod.rs | 47 +++++++++++-- .../tests/libclang-9/objc_inheritance.rs | 45 ++++++++++++ .../tests/objc_protocol_inheritance.rs | 70 +++++++++++++++++++ tests/headers/objc_protocol_inheritance.h | 11 +++ 4 files changed, 167 insertions(+), 6 deletions(-) create mode 100644 tests/expectations/tests/objc_protocol_inheritance.rs create mode 100644 tests/headers/objc_protocol_inheritance.h diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 7ae202bf96..de4721f6e9 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -49,6 +49,7 @@ use crate::{Entry, HashMap, HashSet}; use std; use std::borrow::Cow; use std::cell::Cell; +use std::collections::HashSet as CollectionHashSet; use std::collections::VecDeque; use std::fmt::Write; use std::iter; @@ -3921,11 +3922,13 @@ impl CodeGenerator for ObjCInterface { } }; result.push(struct_block); + let mut protocol_set : CollectionHashSet = CollectionHashSet::new(); for protocol_id in self.conforms_to.iter() { + protocol_set.insert(*protocol_id); let protocol_name = ctx.rust_ident( ctx.resolve_type(protocol_id.expect_type_id(ctx)) - .name() - .unwrap(), + .name() + .unwrap(), ); let impl_trait = quote! { impl #protocol_name for #class_name { } @@ -3962,16 +3965,48 @@ impl CodeGenerator for ObjCInterface { } }; result.push(impl_trait); + for protocol_id in parent.conforms_to.iter() { + if !protocol_set.contains(protocol_id) { + + protocol_set.insert(*protocol_id); + let protocol_name = ctx.rust_ident( + ctx.resolve_type(protocol_id.expect_type_id(ctx)) + .name() + .unwrap(), + ); + let impl_trait = quote! { + impl #protocol_name for #class_name { } + }; + result.push(impl_trait); + } + } if !parent.is_template() { - let parent_struct_name = ctx.rust_ident(parent.name()); + let parent_struct_name = parent.name(); + let child_struct_name = self.name(); + let parent_struct = ctx.rust_ident(parent_struct_name); let from_block = quote! { - impl From<#class_name> for #parent_struct_name { - fn from(child: #class_name) -> #parent_struct_name { - #parent_struct_name(child.0) + impl From<#class_name> for #parent_struct { + fn from(child: #class_name) -> #parent_struct { + #parent_struct(child.0) } } }; result.push(from_block); + + let try_into_block = quote! { + impl std::convert::TryFrom<#parent_struct> for #class_name { + type Error = String; + fn try_from(parent: #parent_struct) -> Result<#class_name, Self::Error> { + let is_kind_of : bool = unsafe { msg_send!(parent, isKindOfClass:class!(#class_name))}; + if is_kind_of { + Ok(#class_name(parent.0)) + } else { + Err(format!("This {} is not an cannot be downcasted to {}", #parent_struct_name, #child_struct_name)) + } + } + } + }; + result.push(try_into_block); } parent.parent_class } else { diff --git a/tests/expectations/tests/libclang-9/objc_inheritance.rs b/tests/expectations/tests/libclang-9/objc_inheritance.rs index ef16325e15..a84f6f371b 100644 --- a/tests/expectations/tests/libclang-9/objc_inheritance.rs +++ b/tests/expectations/tests/libclang-9/objc_inheritance.rs @@ -48,6 +48,21 @@ impl From for Foo { Foo(child.0) } } +impl std::convert::TryFrom for Bar { + type Error = String; + fn try_from(parent: Foo) -> Result { + let is_kind_of: bool = + unsafe { msg_send!(parent, isKindOfClass: class!(Bar)) }; + if is_kind_of { + Ok(Bar(parent.0)) + } else { + Err(format!( + "This {} is not an cannot be downcasted to {}", + "Foo", "Bar" + )) + } + } +} impl IBar for Bar {} pub trait IBar: Sized + std::ops::Deref {} #[repr(transparent)] @@ -71,11 +86,41 @@ impl From for Bar { Bar(child.0) } } +impl std::convert::TryFrom for Baz { + type Error = String; + fn try_from(parent: Bar) -> Result { + let is_kind_of: bool = + unsafe { msg_send!(parent, isKindOfClass: class!(Baz)) }; + if is_kind_of { + Ok(Baz(parent.0)) + } else { + Err(format!( + "This {} is not an cannot be downcasted to {}", + "Bar", "Baz" + )) + } + } +} impl IFoo for Baz {} impl From for Foo { fn from(child: Baz) -> Foo { Foo(child.0) } } +impl std::convert::TryFrom for Baz { + type Error = String; + fn try_from(parent: Foo) -> Result { + let is_kind_of: bool = + unsafe { msg_send!(parent, isKindOfClass: class!(Baz)) }; + if is_kind_of { + Ok(Baz(parent.0)) + } else { + Err(format!( + "This {} is not an cannot be downcasted to {}", + "Foo", "Baz" + )) + } + } +} impl IBaz for Baz {} pub trait IBaz: Sized + std::ops::Deref {} diff --git a/tests/expectations/tests/objc_protocol_inheritance.rs b/tests/expectations/tests/objc_protocol_inheritance.rs new file mode 100644 index 0000000000..14570e1ee3 --- /dev/null +++ b/tests/expectations/tests/objc_protocol_inheritance.rs @@ -0,0 +1,70 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] +#![cfg(target_os = "macos")] + +#[macro_use] +extern crate objc; +#[allow(non_camel_case_types)] +pub type id = *mut objc::runtime::Object; +pub trait PFoo: Sized + std::ops::Deref {} +#[repr(transparent)] +#[derive(Clone)] +pub struct Foo(pub id); +impl std::ops::Deref for Foo { + type Target = objc::runtime::Object; + fn deref(&self) -> &Self::Target { + unsafe { &*self.0 } + } +} +unsafe impl objc::Message for Foo {} +impl Foo { + pub fn alloc() -> Self { + Self(unsafe { msg_send!(objc::class!(Foo), alloc) }) + } +} +impl PFoo for Foo {} +impl IFoo for Foo {} +pub trait IFoo: Sized + std::ops::Deref {} +#[repr(transparent)] +#[derive(Clone)] +pub struct Bar(pub id); +impl std::ops::Deref for Bar { + type Target = objc::runtime::Object; + fn deref(&self) -> &Self::Target { + unsafe { &*self.0 } + } +} +unsafe impl objc::Message for Bar {} +impl Bar { + pub fn alloc() -> Self { + Self(unsafe { msg_send!(objc::class!(Bar), alloc) }) + } +} +impl IFoo for Bar {} +impl PFoo for Bar {} +impl From for Foo { + fn from(child: Bar) -> Foo { + Foo(child.0) + } +} +impl std::convert::TryFrom for Bar { + type Error = String; + fn try_from(parent: Foo) -> Result { + let is_kind_of: bool = + unsafe { msg_send!(parent, isKindOfClass: class!(Bar)) }; + if is_kind_of { + Ok(Bar(parent.0)) + } else { + Err(format!( + "This {} is not an cannot be downcasted to {}", + "Foo", "Bar" + )) + } + } +} +impl IBar for Bar {} +pub trait IBar: Sized + std::ops::Deref {} diff --git a/tests/headers/objc_protocol_inheritance.h b/tests/headers/objc_protocol_inheritance.h new file mode 100644 index 0000000000..d5f3a490e5 --- /dev/null +++ b/tests/headers/objc_protocol_inheritance.h @@ -0,0 +1,11 @@ +// bindgen-flags: --objc-extern-crate -- -x objective-c +// bindgen-osx-only + +@protocol Foo +@end + +@interface Foo +@end + +@interface Bar : Foo +@end From 969aa7a5ee6c766f2eb870d233179b5b75676fb1 Mon Sep 17 00:00:00 2001 From: Sebastian Imlay Date: Fri, 28 Aug 2020 16:34:05 -0700 Subject: [PATCH 092/942] ran cargo fmt --- src/codegen/mod.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index de4721f6e9..0039a8594b 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -3922,13 +3922,14 @@ impl CodeGenerator for ObjCInterface { } }; result.push(struct_block); - let mut protocol_set : CollectionHashSet = CollectionHashSet::new(); + let mut protocol_set: CollectionHashSet = + CollectionHashSet::new(); for protocol_id in self.conforms_to.iter() { protocol_set.insert(*protocol_id); let protocol_name = ctx.rust_ident( ctx.resolve_type(protocol_id.expect_type_id(ctx)) - .name() - .unwrap(), + .name() + .unwrap(), ); let impl_trait = quote! { impl #protocol_name for #class_name { } @@ -3967,10 +3968,11 @@ impl CodeGenerator for ObjCInterface { result.push(impl_trait); for protocol_id in parent.conforms_to.iter() { if !protocol_set.contains(protocol_id) { - protocol_set.insert(*protocol_id); let protocol_name = ctx.rust_ident( - ctx.resolve_type(protocol_id.expect_type_id(ctx)) + ctx.resolve_type( + protocol_id.expect_type_id(ctx), + ) .name() .unwrap(), ); From c24626993d42c737631d702043b53da0faeb1fd5 Mon Sep 17 00:00:00 2001 From: Sebastian Imlay Date: Sat, 29 Aug 2020 16:57:13 -0700 Subject: [PATCH 093/942] First attempt to fix CI --- .../tests/libclang-3.9/objc_inheritance.rs | 76 +++++++++++++++++-- .../tests/libclang-4/objc_inheritance.rs | 66 +++++++++++++++- .../tests/libclang-5/objc_inheritance.rs | 66 +++++++++++++++- 3 files changed, 197 insertions(+), 11 deletions(-) diff --git a/tests/expectations/tests/libclang-3.9/objc_inheritance.rs b/tests/expectations/tests/libclang-3.9/objc_inheritance.rs index cd2b085dc3..982fc14cb4 100644 --- a/tests/expectations/tests/libclang-3.9/objc_inheritance.rs +++ b/tests/expectations/tests/libclang-3.9/objc_inheritance.rs @@ -11,7 +11,7 @@ extern crate objc; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] -#[derive(Clone, Copy)] +#[derive(Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -28,7 +28,7 @@ impl Foo { impl IFoo for Foo {} pub trait IFoo: Sized + std::ops::Deref {} #[repr(transparent)] -#[derive(Clone, Copy)] +#[derive(Clone)] pub struct Bar(pub id); impl std::ops::Deref for Bar { type Target = objc::runtime::Object; @@ -43,10 +43,78 @@ impl Bar { } } impl IFoo for Bar {} + +mpl From for Foo { + ++ fn from(child: Bar) -> Foo { + ++ Foo(child.0) + ++ } + ++} + +impl std::convert::TryFrom for Bar { + type Error = String; + fn try_from(parent: Foo) -> Result { + let is_kind_of: bool = + unsafe { msg_send!(parent, isKindOfClass: class!(Bar)) }; + if is_kind_of { + Ok(Bar(parent.0)) + } else { + Err(format!( + "This {} is not an cannot be downcasted to {}", + "Foo", "Bar" + )) + } + } +} impl IBar for Bar {} +impl From for Bar { + fn from(child: Baz) -> Bar { + Bar(child.0) + } +} + +impl std::convert::TryFrom for Baz { + type Error = String; + fn try_from(parent: Bar) -> Result { + let is_kind_of: bool = + unsafe { msg_send!(parent, isKindOfClass: class!(Baz)) }; + if is_kind_of { + Ok(Baz(parent.0)) + } else { + Err(format!( + "This {} is not an cannot be downcasted to {}", + "Bar", "Baz" + )) + } + } +} +impl IFoo for Baz {} +impl From for Foo { + fn from(child: Baz) -> Foo { + Foo(child.0) + } +} +impl std::convert::TryFrom for Baz { + type Error = String; + fn try_from(parent: Foo) -> Result { + let is_kind_of: bool = + unsafe { msg_send!(parent, isKindOfClass: class!(Baz)) }; + if is_kind_of { + Ok(Baz(parent.0)) + } else { + Err(format!( + "This {} is not an cannot be downcasted to {}", + "Foo", "Baz" + )) + } + } +} pub trait IBar: Sized + std::ops::Deref {} #[repr(transparent)] -#[derive(Clone, Copy)] +#[derive(Clone)] pub struct Baz(pub id); impl std::ops::Deref for Baz { type Target = objc::runtime::Object; @@ -60,7 +128,5 @@ impl Baz { Self(unsafe { msg_send!(objc::class!(Baz), alloc) }) } } -impl IBar for Baz {} -impl IFoo for Baz {} impl IBaz for Baz {} pub trait IBaz: Sized + std::ops::Deref {} diff --git a/tests/expectations/tests/libclang-4/objc_inheritance.rs b/tests/expectations/tests/libclang-4/objc_inheritance.rs index cd2b085dc3..a84f6f371b 100644 --- a/tests/expectations/tests/libclang-4/objc_inheritance.rs +++ b/tests/expectations/tests/libclang-4/objc_inheritance.rs @@ -11,7 +11,7 @@ extern crate objc; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] -#[derive(Clone, Copy)] +#[derive(Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -28,7 +28,7 @@ impl Foo { impl IFoo for Foo {} pub trait IFoo: Sized + std::ops::Deref {} #[repr(transparent)] -#[derive(Clone, Copy)] +#[derive(Clone)] pub struct Bar(pub id); impl std::ops::Deref for Bar { type Target = objc::runtime::Object; @@ -43,10 +43,30 @@ impl Bar { } } impl IFoo for Bar {} +impl From for Foo { + fn from(child: Bar) -> Foo { + Foo(child.0) + } +} +impl std::convert::TryFrom for Bar { + type Error = String; + fn try_from(parent: Foo) -> Result { + let is_kind_of: bool = + unsafe { msg_send!(parent, isKindOfClass: class!(Bar)) }; + if is_kind_of { + Ok(Bar(parent.0)) + } else { + Err(format!( + "This {} is not an cannot be downcasted to {}", + "Foo", "Bar" + )) + } + } +} impl IBar for Bar {} pub trait IBar: Sized + std::ops::Deref {} #[repr(transparent)] -#[derive(Clone, Copy)] +#[derive(Clone)] pub struct Baz(pub id); impl std::ops::Deref for Baz { type Target = objc::runtime::Object; @@ -61,6 +81,46 @@ impl Baz { } } impl IBar for Baz {} +impl From for Bar { + fn from(child: Baz) -> Bar { + Bar(child.0) + } +} +impl std::convert::TryFrom for Baz { + type Error = String; + fn try_from(parent: Bar) -> Result { + let is_kind_of: bool = + unsafe { msg_send!(parent, isKindOfClass: class!(Baz)) }; + if is_kind_of { + Ok(Baz(parent.0)) + } else { + Err(format!( + "This {} is not an cannot be downcasted to {}", + "Bar", "Baz" + )) + } + } +} impl IFoo for Baz {} +impl From for Foo { + fn from(child: Baz) -> Foo { + Foo(child.0) + } +} +impl std::convert::TryFrom for Baz { + type Error = String; + fn try_from(parent: Foo) -> Result { + let is_kind_of: bool = + unsafe { msg_send!(parent, isKindOfClass: class!(Baz)) }; + if is_kind_of { + Ok(Baz(parent.0)) + } else { + Err(format!( + "This {} is not an cannot be downcasted to {}", + "Foo", "Baz" + )) + } + } +} impl IBaz for Baz {} pub trait IBaz: Sized + std::ops::Deref {} diff --git a/tests/expectations/tests/libclang-5/objc_inheritance.rs b/tests/expectations/tests/libclang-5/objc_inheritance.rs index cd2b085dc3..a84f6f371b 100644 --- a/tests/expectations/tests/libclang-5/objc_inheritance.rs +++ b/tests/expectations/tests/libclang-5/objc_inheritance.rs @@ -11,7 +11,7 @@ extern crate objc; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] -#[derive(Clone, Copy)] +#[derive(Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -28,7 +28,7 @@ impl Foo { impl IFoo for Foo {} pub trait IFoo: Sized + std::ops::Deref {} #[repr(transparent)] -#[derive(Clone, Copy)] +#[derive(Clone)] pub struct Bar(pub id); impl std::ops::Deref for Bar { type Target = objc::runtime::Object; @@ -43,10 +43,30 @@ impl Bar { } } impl IFoo for Bar {} +impl From for Foo { + fn from(child: Bar) -> Foo { + Foo(child.0) + } +} +impl std::convert::TryFrom for Bar { + type Error = String; + fn try_from(parent: Foo) -> Result { + let is_kind_of: bool = + unsafe { msg_send!(parent, isKindOfClass: class!(Bar)) }; + if is_kind_of { + Ok(Bar(parent.0)) + } else { + Err(format!( + "This {} is not an cannot be downcasted to {}", + "Foo", "Bar" + )) + } + } +} impl IBar for Bar {} pub trait IBar: Sized + std::ops::Deref {} #[repr(transparent)] -#[derive(Clone, Copy)] +#[derive(Clone)] pub struct Baz(pub id); impl std::ops::Deref for Baz { type Target = objc::runtime::Object; @@ -61,6 +81,46 @@ impl Baz { } } impl IBar for Baz {} +impl From for Bar { + fn from(child: Baz) -> Bar { + Bar(child.0) + } +} +impl std::convert::TryFrom for Baz { + type Error = String; + fn try_from(parent: Bar) -> Result { + let is_kind_of: bool = + unsafe { msg_send!(parent, isKindOfClass: class!(Baz)) }; + if is_kind_of { + Ok(Baz(parent.0)) + } else { + Err(format!( + "This {} is not an cannot be downcasted to {}", + "Bar", "Baz" + )) + } + } +} impl IFoo for Baz {} +impl From for Foo { + fn from(child: Baz) -> Foo { + Foo(child.0) + } +} +impl std::convert::TryFrom for Baz { + type Error = String; + fn try_from(parent: Foo) -> Result { + let is_kind_of: bool = + unsafe { msg_send!(parent, isKindOfClass: class!(Baz)) }; + if is_kind_of { + Ok(Baz(parent.0)) + } else { + Err(format!( + "This {} is not an cannot be downcasted to {}", + "Foo", "Baz" + )) + } + } +} impl IBaz for Baz {} pub trait IBaz: Sized + std::ops::Deref {} From 0dff6d65d5a9ac086c951bd3d55058d3dbb7e193 Mon Sep 17 00:00:00 2001 From: Sebastian Imlay Date: Mon, 31 Aug 2020 02:13:39 -0700 Subject: [PATCH 094/942] Fix spacing issue --- .../tests/libclang-3.9/objc_inheritance.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/tests/expectations/tests/libclang-3.9/objc_inheritance.rs b/tests/expectations/tests/libclang-3.9/objc_inheritance.rs index 982fc14cb4..76b758ec50 100644 --- a/tests/expectations/tests/libclang-3.9/objc_inheritance.rs +++ b/tests/expectations/tests/libclang-3.9/objc_inheritance.rs @@ -44,16 +44,11 @@ impl Bar { } impl IFoo for Bar {} -mpl From for Foo { - -+ fn from(child: Bar) -> Foo { - -+ Foo(child.0) - -+ } - -+} - +impl From for Foo { + fn from(child: Bar) -> Foo { + Foo(child.0) + } +} impl std::convert::TryFrom for Bar { type Error = String; fn try_from(parent: Foo) -> Result { From d4e84650c8ed30fbc82a30da927f106d815b8123 Mon Sep 17 00:00:00 2001 From: Sebastian Imlay Date: Mon, 31 Aug 2020 13:51:42 -0700 Subject: [PATCH 095/942] Updates from PR comments --- src/codegen/mod.rs | 12 +++++----- .../tests/libclang-3.9/objc_inheritance.rs | 22 +++++-------------- .../tests/libclang-4/objc_inheritance.rs | 21 +++++------------- .../tests/libclang-5/objc_inheritance.rs | 19 +++++----------- .../tests/libclang-9/objc_inheritance.rs | 21 +++++------------- .../tests/objc_protocol_inheritance.rs | 7 ++---- 6 files changed, 30 insertions(+), 72 deletions(-) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 0039a8594b..d07e27a798 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -49,7 +49,6 @@ use crate::{Entry, HashMap, HashSet}; use std; use std::borrow::Cow; use std::cell::Cell; -use std::collections::HashSet as CollectionHashSet; use std::collections::VecDeque; use std::fmt::Write; use std::iter; @@ -3922,8 +3921,7 @@ impl CodeGenerator for ObjCInterface { } }; result.push(struct_block); - let mut protocol_set: CollectionHashSet = - CollectionHashSet::new(); + let mut protocol_set: HashSet = Default::default(); for protocol_id in self.conforms_to.iter() { protocol_set.insert(*protocol_id); let protocol_name = ctx.rust_ident( @@ -3967,8 +3965,7 @@ impl CodeGenerator for ObjCInterface { }; result.push(impl_trait); for protocol_id in parent.conforms_to.iter() { - if !protocol_set.contains(protocol_id) { - protocol_set.insert(*protocol_id); + if protocol_set.insert(*protocol_id) { let protocol_name = ctx.rust_ident( ctx.resolve_type( protocol_id.expect_type_id(ctx), @@ -3995,15 +3992,16 @@ impl CodeGenerator for ObjCInterface { }; result.push(from_block); + let error_msg = format!("This {} cannot be downcasted to {}", parent_struct_name, child_struct_name); let try_into_block = quote! { impl std::convert::TryFrom<#parent_struct> for #class_name { - type Error = String; + type Error = &'static str; fn try_from(parent: #parent_struct) -> Result<#class_name, Self::Error> { let is_kind_of : bool = unsafe { msg_send!(parent, isKindOfClass:class!(#class_name))}; if is_kind_of { Ok(#class_name(parent.0)) } else { - Err(format!("This {} is not an cannot be downcasted to {}", #parent_struct_name, #child_struct_name)) + Err(#error_msg) } } } diff --git a/tests/expectations/tests/libclang-3.9/objc_inheritance.rs b/tests/expectations/tests/libclang-3.9/objc_inheritance.rs index 76b758ec50..f2049a88b9 100644 --- a/tests/expectations/tests/libclang-3.9/objc_inheritance.rs +++ b/tests/expectations/tests/libclang-3.9/objc_inheritance.rs @@ -50,17 +50,14 @@ impl From for Foo { } } impl std::convert::TryFrom for Bar { - type Error = String; + type Error = &'static str; fn try_from(parent: Foo) -> Result { let is_kind_of: bool = unsafe { msg_send!(parent, isKindOfClass: class!(Bar)) }; if is_kind_of { Ok(Bar(parent.0)) } else { - Err(format!( - "This {} is not an cannot be downcasted to {}", - "Foo", "Bar" - )) + Err("This Foo cannot be downcasted to Bar") } } } @@ -70,19 +67,15 @@ impl From for Bar { Bar(child.0) } } - impl std::convert::TryFrom for Baz { - type Error = String; + type Error = &'static str; fn try_from(parent: Bar) -> Result { let is_kind_of: bool = unsafe { msg_send!(parent, isKindOfClass: class!(Baz)) }; if is_kind_of { Ok(Baz(parent.0)) } else { - Err(format!( - "This {} is not an cannot be downcasted to {}", - "Bar", "Baz" - )) + Err("This Bar cannot be downcasted to Baz") } } } @@ -93,17 +86,14 @@ impl From for Foo { } } impl std::convert::TryFrom for Baz { - type Error = String; + type Error = &'static str; fn try_from(parent: Foo) -> Result { let is_kind_of: bool = unsafe { msg_send!(parent, isKindOfClass: class!(Baz)) }; if is_kind_of { Ok(Baz(parent.0)) } else { - Err(format!( - "This {} is not an cannot be downcasted to {}", - "Foo", "Baz" - )) + Err("This Foo cannot be downcasted to Baz") } } } diff --git a/tests/expectations/tests/libclang-4/objc_inheritance.rs b/tests/expectations/tests/libclang-4/objc_inheritance.rs index a84f6f371b..5f07dbaab1 100644 --- a/tests/expectations/tests/libclang-4/objc_inheritance.rs +++ b/tests/expectations/tests/libclang-4/objc_inheritance.rs @@ -49,17 +49,14 @@ impl From for Foo { } } impl std::convert::TryFrom for Bar { - type Error = String; + type Error = &'static str; fn try_from(parent: Foo) -> Result { let is_kind_of: bool = unsafe { msg_send!(parent, isKindOfClass: class!(Bar)) }; if is_kind_of { Ok(Bar(parent.0)) } else { - Err(format!( - "This {} is not an cannot be downcasted to {}", - "Foo", "Bar" - )) + Err("This Foo cannot be downcasted to Bar") } } } @@ -87,17 +84,14 @@ impl From for Bar { } } impl std::convert::TryFrom for Baz { - type Error = String; + type Error = &'static str; fn try_from(parent: Bar) -> Result { let is_kind_of: bool = unsafe { msg_send!(parent, isKindOfClass: class!(Baz)) }; if is_kind_of { Ok(Baz(parent.0)) } else { - Err(format!( - "This {} is not an cannot be downcasted to {}", - "Bar", "Baz" - )) + Err("This Bar cannot be downcasted to Baz") } } } @@ -108,17 +102,14 @@ impl From for Foo { } } impl std::convert::TryFrom for Baz { - type Error = String; + type Error = &'static str; fn try_from(parent: Foo) -> Result { let is_kind_of: bool = unsafe { msg_send!(parent, isKindOfClass: class!(Baz)) }; if is_kind_of { Ok(Baz(parent.0)) } else { - Err(format!( - "This {} is not an cannot be downcasted to {}", - "Foo", "Baz" - )) + Err("This Foo cannot be downcasted to Baz") } } } diff --git a/tests/expectations/tests/libclang-5/objc_inheritance.rs b/tests/expectations/tests/libclang-5/objc_inheritance.rs index a84f6f371b..42c961e7cd 100644 --- a/tests/expectations/tests/libclang-5/objc_inheritance.rs +++ b/tests/expectations/tests/libclang-5/objc_inheritance.rs @@ -56,10 +56,7 @@ impl std::convert::TryFrom for Bar { if is_kind_of { Ok(Bar(parent.0)) } else { - Err(format!( - "This {} is not an cannot be downcasted to {}", - "Foo", "Bar" - )) + Err("This Foo cannot be downcasted to Bar") } } } @@ -87,17 +84,14 @@ impl From for Bar { } } impl std::convert::TryFrom for Baz { - type Error = String; + type Error = &'static str; fn try_from(parent: Bar) -> Result { let is_kind_of: bool = unsafe { msg_send!(parent, isKindOfClass: class!(Baz)) }; if is_kind_of { Ok(Baz(parent.0)) } else { - Err(format!( - "This {} is not an cannot be downcasted to {}", - "Bar", "Baz" - )) + Err("This Bar cannot be downcasted to Baz") } } } @@ -108,17 +102,14 @@ impl From for Foo { } } impl std::convert::TryFrom for Baz { - type Error = String; + type Error = &'static str; fn try_from(parent: Foo) -> Result { let is_kind_of: bool = unsafe { msg_send!(parent, isKindOfClass: class!(Baz)) }; if is_kind_of { Ok(Baz(parent.0)) } else { - Err(format!( - "This {} is not an cannot be downcasted to {}", - "Foo", "Baz" - )) + Err("This Foo cannot be downcasted to Baz") } } } diff --git a/tests/expectations/tests/libclang-9/objc_inheritance.rs b/tests/expectations/tests/libclang-9/objc_inheritance.rs index a84f6f371b..5f07dbaab1 100644 --- a/tests/expectations/tests/libclang-9/objc_inheritance.rs +++ b/tests/expectations/tests/libclang-9/objc_inheritance.rs @@ -49,17 +49,14 @@ impl From for Foo { } } impl std::convert::TryFrom for Bar { - type Error = String; + type Error = &'static str; fn try_from(parent: Foo) -> Result { let is_kind_of: bool = unsafe { msg_send!(parent, isKindOfClass: class!(Bar)) }; if is_kind_of { Ok(Bar(parent.0)) } else { - Err(format!( - "This {} is not an cannot be downcasted to {}", - "Foo", "Bar" - )) + Err("This Foo cannot be downcasted to Bar") } } } @@ -87,17 +84,14 @@ impl From for Bar { } } impl std::convert::TryFrom for Baz { - type Error = String; + type Error = &'static str; fn try_from(parent: Bar) -> Result { let is_kind_of: bool = unsafe { msg_send!(parent, isKindOfClass: class!(Baz)) }; if is_kind_of { Ok(Baz(parent.0)) } else { - Err(format!( - "This {} is not an cannot be downcasted to {}", - "Bar", "Baz" - )) + Err("This Bar cannot be downcasted to Baz") } } } @@ -108,17 +102,14 @@ impl From for Foo { } } impl std::convert::TryFrom for Baz { - type Error = String; + type Error = &'static str; fn try_from(parent: Foo) -> Result { let is_kind_of: bool = unsafe { msg_send!(parent, isKindOfClass: class!(Baz)) }; if is_kind_of { Ok(Baz(parent.0)) } else { - Err(format!( - "This {} is not an cannot be downcasted to {}", - "Foo", "Baz" - )) + Err("This Foo cannot be downcasted to Baz") } } } diff --git a/tests/expectations/tests/objc_protocol_inheritance.rs b/tests/expectations/tests/objc_protocol_inheritance.rs index 14570e1ee3..598273ba35 100644 --- a/tests/expectations/tests/objc_protocol_inheritance.rs +++ b/tests/expectations/tests/objc_protocol_inheritance.rs @@ -52,17 +52,14 @@ impl From for Foo { } } impl std::convert::TryFrom for Bar { - type Error = String; + type Error = &'static str; fn try_from(parent: Foo) -> Result { let is_kind_of: bool = unsafe { msg_send!(parent, isKindOfClass: class!(Bar)) }; if is_kind_of { Ok(Bar(parent.0)) } else { - Err(format!( - "This {} is not an cannot be downcasted to {}", - "Foo", "Bar" - )) + Err("This Foo cannot be downcasted to Bar") } } } From 27b02615693bab603c97799710d3c062fdab988f Mon Sep 17 00:00:00 2001 From: Sebastian Imlay Date: Mon, 31 Aug 2020 14:04:26 -0700 Subject: [PATCH 096/942] Updated CHANGELOG.md --- CHANGELOG.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ab8200986..487405ee8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -120,11 +120,11 @@ Released YYYY/MM/DD ## Added -* TODO (or remove section if none) +* Objective-c bindings generate `From for ParentClass` as well as `TryFrom for ChildClass` ([#1883][]). ## Changed -* TODO (or remove section if none) +* Objective-c bindings borrow self rather than take ownership ([#1883][]). ## Deprecated @@ -136,12 +136,15 @@ Released YYYY/MM/DD ## Fixed -* TODO (or remove section if none) +* Fixed objective-c protocol impl blocks for parent classes's protocols ([#1883][]). ## Security * TODO (or remove section if none) + +[#1883]: https://github.com/rust-lang/rust-bindgen/issues/1883 + -------------------------------------------------------------------------------- # 0.55.1 From 59a4c18b17dbf6b71ed2b70f6d3b5e39e59beda3 Mon Sep 17 00:00:00 2001 From: Sebastian Imlay Date: Mon, 31 Aug 2020 15:31:54 -0700 Subject: [PATCH 097/942] Updates for CI --- src/codegen/mod.rs | 5 ++++- .../expectations/tests/libclang-3.9/objc_template.rs | 12 ++++++------ tests/expectations/tests/libclang-4/objc_template.rs | 12 ++++++------ .../tests/libclang-5/objc_inheritance.rs | 2 +- tests/expectations/tests/libclang-5/objc_template.rs | 12 ++++++------ 5 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index d07e27a798..1a9416c983 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -3992,7 +3992,10 @@ impl CodeGenerator for ObjCInterface { }; result.push(from_block); - let error_msg = format!("This {} cannot be downcasted to {}", parent_struct_name, child_struct_name); + let error_msg = format!( + "This {} cannot be downcasted to {}", + parent_struct_name, child_struct_name + ); let try_into_block = quote! { impl std::convert::TryFrom<#parent_struct> for #class_name { type Error = &'static str; diff --git a/tests/expectations/tests/libclang-3.9/objc_template.rs b/tests/expectations/tests/libclang-3.9/objc_template.rs index 9c5a5b75a2..4ccf72b71b 100644 --- a/tests/expectations/tests/libclang-3.9/objc_template.rs +++ b/tests/expectations/tests/libclang-3.9/objc_template.rs @@ -11,7 +11,7 @@ extern crate objc; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] -#[derive(Clone, Copy)] +#[derive(Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -27,15 +27,15 @@ impl Foo { } impl IFoo for Foo {} pub trait IFoo: Sized + std::ops::Deref { - unsafe fn get(self) -> id + unsafe fn get(&self) -> id where ::Target: objc::Message + Sized, { - msg_send!(self, get) + msg_send!(*self, get) } } #[repr(transparent)] -#[derive(Clone, Copy)] +#[derive(Clone)] pub struct FooMultiGeneric(pub id); impl std::ops::Deref for FooMultiGeneric { type Target = objc::runtime::Object; @@ -56,10 +56,10 @@ impl pub trait IFooMultiGeneric: Sized + std::ops::Deref { - unsafe fn objectForKey_(self, key: id) -> id + unsafe fn objectForKey_(&self, key: id) -> id where ::Target: objc::Message + Sized, { - msg_send!(self, objectForKey: key) + msg_send!(*self, objectForKey: key) } } diff --git a/tests/expectations/tests/libclang-4/objc_template.rs b/tests/expectations/tests/libclang-4/objc_template.rs index eab2e36a5a..36b7d22baa 100644 --- a/tests/expectations/tests/libclang-4/objc_template.rs +++ b/tests/expectations/tests/libclang-4/objc_template.rs @@ -11,7 +11,7 @@ extern crate objc; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] -#[derive(Clone, Copy)] +#[derive(Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -27,15 +27,15 @@ impl Foo { } impl IFoo for Foo {} pub trait IFoo: Sized + std::ops::Deref { - unsafe fn get(self) -> *mut ObjectType + unsafe fn get(&self) -> *mut ObjectType where ::Target: objc::Message + Sized, { - msg_send!(self, get) + msg_send!(*self, get) } } #[repr(transparent)] -#[derive(Clone, Copy)] +#[derive(Clone)] pub struct FooMultiGeneric(pub id); impl std::ops::Deref for FooMultiGeneric { type Target = objc::runtime::Object; @@ -56,10 +56,10 @@ impl pub trait IFooMultiGeneric: Sized + std::ops::Deref { - unsafe fn objectForKey_(self, key: *mut KeyType) -> *mut ObjectType + unsafe fn objectForKey_(&self, key: *mut KeyType) -> *mut ObjectType where ::Target: objc::Message + Sized, { - msg_send!(self, objectForKey: key) + msg_send!(*self, objectForKey: key) } } diff --git a/tests/expectations/tests/libclang-5/objc_inheritance.rs b/tests/expectations/tests/libclang-5/objc_inheritance.rs index 42c961e7cd..5f07dbaab1 100644 --- a/tests/expectations/tests/libclang-5/objc_inheritance.rs +++ b/tests/expectations/tests/libclang-5/objc_inheritance.rs @@ -49,7 +49,7 @@ impl From for Foo { } } impl std::convert::TryFrom for Bar { - type Error = String; + type Error = &'static str; fn try_from(parent: Foo) -> Result { let is_kind_of: bool = unsafe { msg_send!(parent, isKindOfClass: class!(Bar)) }; diff --git a/tests/expectations/tests/libclang-5/objc_template.rs b/tests/expectations/tests/libclang-5/objc_template.rs index eab2e36a5a..36b7d22baa 100644 --- a/tests/expectations/tests/libclang-5/objc_template.rs +++ b/tests/expectations/tests/libclang-5/objc_template.rs @@ -11,7 +11,7 @@ extern crate objc; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] -#[derive(Clone, Copy)] +#[derive(Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -27,15 +27,15 @@ impl Foo { } impl IFoo for Foo {} pub trait IFoo: Sized + std::ops::Deref { - unsafe fn get(self) -> *mut ObjectType + unsafe fn get(&self) -> *mut ObjectType where ::Target: objc::Message + Sized, { - msg_send!(self, get) + msg_send!(*self, get) } } #[repr(transparent)] -#[derive(Clone, Copy)] +#[derive(Clone)] pub struct FooMultiGeneric(pub id); impl std::ops::Deref for FooMultiGeneric { type Target = objc::runtime::Object; @@ -56,10 +56,10 @@ impl pub trait IFooMultiGeneric: Sized + std::ops::Deref { - unsafe fn objectForKey_(self, key: *mut KeyType) -> *mut ObjectType + unsafe fn objectForKey_(&self, key: *mut KeyType) -> *mut ObjectType where ::Target: objc::Message + Sized, { - msg_send!(self, objectForKey: key) + msg_send!(*self, objectForKey: key) } } From 4a51c4552ce7e0fbca478e4acd11ecb40341e61f Mon Sep 17 00:00:00 2001 From: Sebastian Imlay Date: Mon, 31 Aug 2020 18:23:24 -0700 Subject: [PATCH 098/942] Update to fix CI --- .../tests/libclang-3.9/objc_inheritance.rs | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/tests/expectations/tests/libclang-3.9/objc_inheritance.rs b/tests/expectations/tests/libclang-3.9/objc_inheritance.rs index f2049a88b9..59cfacc34c 100644 --- a/tests/expectations/tests/libclang-3.9/objc_inheritance.rs +++ b/tests/expectations/tests/libclang-3.9/objc_inheritance.rs @@ -43,7 +43,6 @@ impl Bar { } } impl IFoo for Bar {} - impl From for Foo { fn from(child: Bar) -> Foo { Foo(child.0) @@ -62,6 +61,22 @@ impl std::convert::TryFrom for Bar { } } impl IBar for Bar {} +pub trait IBar: Sized + std::ops::Deref {} +#[repr(transparent)] +#[derive(Clone)] +pub struct Baz(pub id); +impl std::ops::Deref for Baz { + type Target = objc::runtime::Object; + fn deref(&self) -> &Self::Target { + unsafe { &*self.0 } + } +} +unsafe impl objc::Message for Baz {} +impl Baz { + pub fn alloc() -> Self { + Self(unsafe { msg_send!(objc::class!(Baz), alloc) }) + } +} impl From for Bar { fn from(child: Baz) -> Bar { Bar(child.0) @@ -97,21 +112,5 @@ impl std::convert::TryFrom for Baz { } } } -pub trait IBar: Sized + std::ops::Deref {} -#[repr(transparent)] -#[derive(Clone)] -pub struct Baz(pub id); -impl std::ops::Deref for Baz { - type Target = objc::runtime::Object; - fn deref(&self) -> &Self::Target { - unsafe { &*self.0 } - } -} -unsafe impl objc::Message for Baz {} -impl Baz { - pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Baz), alloc) }) - } -} impl IBaz for Baz {} pub trait IBaz: Sized + std::ops::Deref {} From 4f714ab79eb0ddff7b84ac0ec5487a6b347b3b90 Mon Sep 17 00:00:00 2001 From: Sebastian Imlay Date: Mon, 31 Aug 2020 20:20:53 -0700 Subject: [PATCH 099/942] Fix test for CI --- tests/expectations/tests/libclang-3.9/objc_inheritance.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/expectations/tests/libclang-3.9/objc_inheritance.rs b/tests/expectations/tests/libclang-3.9/objc_inheritance.rs index 59cfacc34c..5f07dbaab1 100644 --- a/tests/expectations/tests/libclang-3.9/objc_inheritance.rs +++ b/tests/expectations/tests/libclang-3.9/objc_inheritance.rs @@ -77,6 +77,7 @@ impl Baz { Self(unsafe { msg_send!(objc::class!(Baz), alloc) }) } } +impl IBar for Baz {} impl From for Bar { fn from(child: Baz) -> Bar { Bar(child.0) From 2306356183bbef78b52d7ee68930640e5c6fcf7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 16 Sep 2020 12:31:07 +0200 Subject: [PATCH 100/942] codegen: Deindent a bit some recently-introduced objective-c code. --- src/codegen/mod.rs | 123 ++++++++++++++++++++++----------------------- 1 file changed, 60 insertions(+), 63 deletions(-) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 1a9416c983..642aed42a5 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -3944,77 +3944,74 @@ impl CodeGenerator for ObjCInterface { .expect_type() .kind(); - parent_class = if let TypeKind::ObjCInterface(ref parent) = - parent - { - let parent_name = ctx.rust_ident(parent.rust_name()); - let impl_trait = if parent.is_template() { - let template_names: Vec = parent - .template_names - .iter() - .map(|g| ctx.rust_ident(g)) - .collect(); - quote! { - impl <#(#template_names :'static),*> #parent_name <#(#template_names),*> for #class_name { - } - } - } else { - quote! { - impl #parent_name for #class_name { } + let parent = match parent { + TypeKind::ObjCInterface(ref parent) => parent, + _ => break, + }; + parent_class = parent.parent_class; + + let parent_name = ctx.rust_ident(parent.rust_name()); + let impl_trait = if parent.is_template() { + let template_names: Vec = parent + .template_names + .iter() + .map(|g| ctx.rust_ident(g)) + .collect(); + quote! { + impl <#(#template_names :'static),*> #parent_name <#(#template_names),*> for #class_name { } - }; - result.push(impl_trait); - for protocol_id in parent.conforms_to.iter() { - if protocol_set.insert(*protocol_id) { - let protocol_name = ctx.rust_ident( - ctx.resolve_type( - protocol_id.expect_type_id(ctx), - ) + } + } else { + quote! { + impl #parent_name for #class_name { } + } + }; + result.push(impl_trait); + for protocol_id in parent.conforms_to.iter() { + if protocol_set.insert(*protocol_id) { + let protocol_name = ctx.rust_ident( + ctx.resolve_type(protocol_id.expect_type_id(ctx)) .name() .unwrap(), - ); - let impl_trait = quote! { - impl #protocol_name for #class_name { } - }; - result.push(impl_trait); - } + ); + let impl_trait = quote! { + impl #protocol_name for #class_name { } + }; + result.push(impl_trait); } - if !parent.is_template() { - let parent_struct_name = parent.name(); - let child_struct_name = self.name(); - let parent_struct = ctx.rust_ident(parent_struct_name); - let from_block = quote! { - impl From<#class_name> for #parent_struct { - fn from(child: #class_name) -> #parent_struct { - #parent_struct(child.0) - } + } + if !parent.is_template() { + let parent_struct_name = parent.name(); + let child_struct_name = self.name(); + let parent_struct = ctx.rust_ident(parent_struct_name); + let from_block = quote! { + impl From<#class_name> for #parent_struct { + fn from(child: #class_name) -> #parent_struct { + #parent_struct(child.0) } - }; - result.push(from_block); + } + }; + result.push(from_block); - let error_msg = format!( - "This {} cannot be downcasted to {}", - parent_struct_name, child_struct_name - ); - let try_into_block = quote! { - impl std::convert::TryFrom<#parent_struct> for #class_name { - type Error = &'static str; - fn try_from(parent: #parent_struct) -> Result<#class_name, Self::Error> { - let is_kind_of : bool = unsafe { msg_send!(parent, isKindOfClass:class!(#class_name))}; - if is_kind_of { - Ok(#class_name(parent.0)) - } else { - Err(#error_msg) - } + let error_msg = format!( + "This {} cannot be downcasted to {}", + parent_struct_name, child_struct_name + ); + let try_into_block = quote! { + impl std::convert::TryFrom<#parent_struct> for #class_name { + type Error = &'static str; + fn try_from(parent: #parent_struct) -> Result<#class_name, Self::Error> { + let is_kind_of : bool = unsafe { msg_send!(parent, isKindOfClass:class!(#class_name))}; + if is_kind_of { + Ok(#class_name(parent.0)) + } else { + Err(#error_msg) } } - }; - result.push(try_into_block); - } - parent.parent_class - } else { - None - }; + } + }; + result.push(try_into_block); + } } } From 1565fd45a9be8b27b884ed8eaf30c09cfb2cca61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 16 Sep 2020 12:31:41 +0200 Subject: [PATCH 101/942] codegen: Use shorthand struct initialization when possible. --- src/codegen/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 642aed42a5..44ad5cb2fc 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -239,7 +239,7 @@ impl<'a> CodegenResult<'a> { saw_objc: false, saw_block: false, saw_bitfield_unit: false, - codegen_id: codegen_id, + codegen_id, items_seen: Default::default(), functions_seen: Default::default(), vars_seen: Default::default(), From e0961491034b243cc23c40619da732cd5680f4c6 Mon Sep 17 00:00:00 2001 From: Kyle Mayes Date: Thu, 1 Oct 2020 16:07:38 -0400 Subject: [PATCH 102/942] Bump clang-sys to 1.0.1 --- Cargo.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b4a5544398..5612ccb327 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -32,7 +32,7 @@ dependencies = [ "bitflags 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "cexpr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "clang-sys 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "clang-sys 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", "diff 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -73,7 +73,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "clang-sys" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -326,7 +326,7 @@ dependencies = [ "checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5" "checksum cexpr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f4aedb84272dbe89af497cf81375129abda4fc0a9e7c5d317498c15cc30c0d27" "checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" -"checksum clang-sys 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9da1484c6a890e374ca5086062d4847e0a2c1e5eba9afa5d48c09e8eb39b2519" +"checksum clang-sys 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fa785e9017cb8e8c8045e3f096b7d1ebc4d7337cceccdca8d678a27f788ac133" "checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" "checksum diff 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "3c2b69f912779fbb121ceb775d74d51e915af17aaebc38d28a592843a2dd0a3a" "checksum env_logger 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "39ecdb7dd54465526f0a56d666e3b2dd5f3a218665a030b6e4ad9e70fa95d8fa" From a467d3efc6f9fbe2e811468adbaa3687a9938b0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 13 Oct 2020 11:06:24 +0200 Subject: [PATCH 103/942] codegen: Allow to not derive Debug on enums. Fixes #1899. This code predated all the derive machinery, and always hardcoded its derives. We could avoid hard-coding the other traits, but those seem usually-useful, so leave them there for backwards compat for now. --- src/codegen/mod.rs | 22 +++++----- tests/expectations/tests/anon_enum.rs | 4 +- tests/expectations/tests/anon_enum_trait.rs | 4 +- .../expectations/tests/anon_enum_whitelist.rs | 2 +- tests/expectations/tests/anon_union.rs | 2 +- tests/expectations/tests/anon_union_1_0.rs | 2 +- .../expectations/tests/bitfield-enum-basic.rs | 8 ++-- .../tests/bitfield-enum-repr-c.rs | 2 +- .../tests/bitfield-enum-repr-transparent.rs | 2 +- tests/expectations/tests/bitfield_align_2.rs | 2 +- .../tests/class_with_inner_struct.rs | 2 +- .../tests/class_with_inner_struct_1_0.rs | 2 +- .../expectations/tests/const_enum_unnamed.rs | 4 +- tests/expectations/tests/constify-enum.rs | 2 +- .../tests/dupe-enum-variant-in-namespace.rs | 2 +- tests/expectations/tests/empty-enum.rs | 6 +-- .../tests/enum-default-bitfield.rs | 40 ++++++++++++++++++- .../expectations/tests/enum-default-consts.rs | 4 ++ .../expectations/tests/enum-default-module.rs | 6 +++ tests/expectations/tests/enum-default-rust.rs | 11 ++++- tests/expectations/tests/enum-doc-bitfield.rs | 2 +- tests/expectations/tests/enum-doc-rusty.rs | 2 +- tests/expectations/tests/enum-undefault.rs | 2 +- tests/expectations/tests/enum.rs | 4 ++ tests/expectations/tests/enum_alias.rs | 2 +- .../tests/enum_and_vtable_mangling.rs | 2 +- tests/expectations/tests/enum_dupe.rs | 2 +- .../expectations/tests/enum_explicit_type.rs | 18 ++++----- .../tests/enum_in_template_with_typedef.rs | 2 +- tests/expectations/tests/enum_negative.rs | 2 +- tests/expectations/tests/enum_packed.rs | 6 +-- tests/expectations/tests/forward-enum-decl.rs | 2 +- .../expectations/tests/func_ptr_in_struct.rs | 2 +- .../issue-1198-alias-rust-bitfield-enum.rs | 4 +- .../tests/issue-1198-alias-rust-enum.rs | 4 +- .../tests/issue-1488-enum-new-type.rs | 2 +- tests/expectations/tests/issue-1554.rs | 2 +- tests/expectations/tests/issue-372.rs | 2 +- tests/expectations/tests/issue-410.rs | 2 +- tests/expectations/tests/issue-493.rs | 4 +- tests/expectations/tests/issue-493_1_0.rs | 4 +- ...ate-params-causing-layout-test-failures.rs | 2 +- .../tests/issue-888-enum-var-decl-jump.rs | 2 +- .../expectations/tests/jsval_layout_opaque.rs | 8 ++-- .../tests/jsval_layout_opaque_1_0.rs | 8 ++-- .../tests/layout_array_too_long.rs | 2 +- .../tests/layout_cmdline_token.rs | 2 +- tests/expectations/tests/layout_eth_conf.rs | 16 ++++---- .../expectations/tests/layout_eth_conf_1_0.rs | 16 ++++---- .../tests/layout_large_align_field.rs | 2 +- .../tests/libclang-3.9/constant-evaluate.rs | 2 +- .../tests/libclang-4/constant-evaluate.rs | 2 +- .../tests/libclang-5/constant-evaluate.rs | 2 +- .../tests/libclang-9/constant-evaluate.rs | 2 +- tests/expectations/tests/newtype-enum.rs | 2 +- tests/expectations/tests/nsStyleAutoArray.rs | 2 +- tests/expectations/tests/ord-enum.rs | 4 +- tests/expectations/tests/overflowed_enum.rs | 4 +- .../tests/prepend-enum-constified-variant.rs | 2 +- tests/expectations/tests/short-enums.rs | 6 +-- tests/expectations/tests/struct_typedef.rs | 4 +- tests/expectations/tests/struct_typedef_ns.rs | 4 +- tests/expectations/tests/weird_bitfields.rs | 2 +- tests/headers/enum.h | 6 +++ 64 files changed, 183 insertions(+), 120 deletions(-) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 44ad5cb2fc..91acf5b03a 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -2840,17 +2840,17 @@ impl CodeGenerator for Enum { } if !variation.is_const() { - let mut derives = - vec!["Debug", "Copy", "Clone", "PartialEq", "Eq", "Hash"]; - - if item.can_derive_partialord(ctx) { - derives.push("PartialOrd"); - } - - if item.can_derive_ord(ctx) { - derives.push("Ord"); - } - + let mut derives = derives_of_item(item, ctx); + // For backwards compat, enums always derive Clone/Eq/PartialEq/Hash, even + // if we don't generate those by default. + derives.insert( + DerivableTraits::CLONE | + DerivableTraits::COPY | + DerivableTraits::HASH | + DerivableTraits::PARTIAL_EQ | + DerivableTraits::EQ, + ); + let derives: Vec<_> = derives.into(); attrs.push(attributes::derives(&derives)); } diff --git a/tests/expectations/tests/anon_enum.rs b/tests/expectations/tests/anon_enum.rs index 0493d8cab7..8cae632999 100644 --- a/tests/expectations/tests/anon_enum.rs +++ b/tests/expectations/tests/anon_enum.rs @@ -13,7 +13,7 @@ pub struct Test { } pub const Test_T_NONE: Test__bindgen_ty_1 = Test__bindgen_ty_1::T_NONE; #[repr(u32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Test__bindgen_ty_1 { T_NONE = 0, } @@ -41,7 +41,7 @@ fn bindgen_test_layout_Test() { ); } #[repr(u32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Baz { Foo = 0, Bar = 1, diff --git a/tests/expectations/tests/anon_enum_trait.rs b/tests/expectations/tests/anon_enum_trait.rs index e6a901469c..9d6b8f574a 100644 --- a/tests/expectations/tests/anon_enum_trait.rs +++ b/tests/expectations/tests/anon_enum_trait.rs @@ -25,7 +25,7 @@ pub const DataType_fmt: DataType__bindgen_ty_1 = pub const DataType_type_: DataType__bindgen_ty_1 = DataType__bindgen_ty_1::generic_type; #[repr(i32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum DataType__bindgen_ty_1 { generic_type = 0, } @@ -37,7 +37,7 @@ pub struct Foo { pub const Foo_Bar: Foo__bindgen_ty_1 = Foo__bindgen_ty_1::Bar; pub const Foo_Baz: Foo__bindgen_ty_1 = Foo__bindgen_ty_1::Bar; #[repr(u32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Foo__bindgen_ty_1 { Bar = 0, } diff --git a/tests/expectations/tests/anon_enum_whitelist.rs b/tests/expectations/tests/anon_enum_whitelist.rs index b94229c0ab..f0c06c5634 100644 --- a/tests/expectations/tests/anon_enum_whitelist.rs +++ b/tests/expectations/tests/anon_enum_whitelist.rs @@ -8,7 +8,7 @@ pub const NODE_FLAG_FOO: _bindgen_ty_1 = _bindgen_ty_1::NODE_FLAG_FOO; pub const NODE_FLAG_BAR: _bindgen_ty_1 = _bindgen_ty_1::NODE_FLAG_BAR; #[repr(u32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum _bindgen_ty_1 { NODE_FLAG_FOO = 0, NODE_FLAG_BAR = 1, diff --git a/tests/expectations/tests/anon_union.rs b/tests/expectations/tests/anon_union.rs index 0490ad730c..0234406358 100644 --- a/tests/expectations/tests/anon_union.rs +++ b/tests/expectations/tests/anon_union.rs @@ -17,7 +17,7 @@ impl TErrorResult_UnionState { TErrorResult_UnionState::HasMessage; } #[repr(i32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum TErrorResult_UnionState { HasMessage = 0, } diff --git a/tests/expectations/tests/anon_union_1_0.rs b/tests/expectations/tests/anon_union_1_0.rs index 95713ea9e6..fbd6b36974 100644 --- a/tests/expectations/tests/anon_union_1_0.rs +++ b/tests/expectations/tests/anon_union_1_0.rs @@ -59,7 +59,7 @@ pub struct TErrorResult { pub const TErrorResult_UnionState_HasException: TErrorResult_UnionState = TErrorResult_UnionState::HasMessage; #[repr(i32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum TErrorResult_UnionState { HasMessage = 0, } diff --git a/tests/expectations/tests/bitfield-enum-basic.rs b/tests/expectations/tests/bitfield-enum-basic.rs index 645a3f5e10..b6c25870b0 100644 --- a/tests/expectations/tests/bitfield-enum-basic.rs +++ b/tests/expectations/tests/bitfield-enum-basic.rs @@ -44,7 +44,7 @@ impl ::std::ops::BitAndAssign for Foo { } } #[repr(transparent)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Foo(pub ::std::os::raw::c_int); impl Buz { pub const Bar: Buz = Buz(2); @@ -85,7 +85,7 @@ impl ::std::ops::BitAndAssign for Buz { } } #[repr(transparent)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Buz(pub ::std::os::raw::c_schar); pub const NS_FOO: _bindgen_ty_1 = _bindgen_ty_1(1); pub const NS_BAR: _bindgen_ty_1 = _bindgen_ty_1(2); @@ -116,7 +116,7 @@ impl ::std::ops::BitAndAssign for _bindgen_ty_1 { } } #[repr(transparent)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct _bindgen_ty_1(pub ::std::os::raw::c_uint); #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -152,7 +152,7 @@ impl ::std::ops::BitAndAssign for Dummy__bindgen_ty_1 { } } #[repr(transparent)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Dummy__bindgen_ty_1(pub ::std::os::raw::c_uint); #[test] fn bindgen_test_layout_Dummy() { diff --git a/tests/expectations/tests/bitfield-enum-repr-c.rs b/tests/expectations/tests/bitfield-enum-repr-c.rs index bd9a35dcb8..1f0228e8e6 100644 --- a/tests/expectations/tests/bitfield-enum-repr-c.rs +++ b/tests/expectations/tests/bitfield-enum-repr-c.rs @@ -44,5 +44,5 @@ impl ::std::ops::BitAndAssign for Foo { } } #[repr(C)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Foo(pub ::std::os::raw::c_int); diff --git a/tests/expectations/tests/bitfield-enum-repr-transparent.rs b/tests/expectations/tests/bitfield-enum-repr-transparent.rs index 690f3b4770..53e113ed5e 100644 --- a/tests/expectations/tests/bitfield-enum-repr-transparent.rs +++ b/tests/expectations/tests/bitfield-enum-repr-transparent.rs @@ -44,5 +44,5 @@ impl ::std::ops::BitAndAssign for Foo { } } #[repr(transparent)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Foo(pub ::std::os::raw::c_int); diff --git a/tests/expectations/tests/bitfield_align_2.rs b/tests/expectations/tests/bitfield_align_2.rs index ef0cdffe47..5602555b09 100644 --- a/tests/expectations/tests/bitfield_align_2.rs +++ b/tests/expectations/tests/bitfield_align_2.rs @@ -93,7 +93,7 @@ where } } #[repr(u32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum MyEnum { ONE = 0, TWO = 1, diff --git a/tests/expectations/tests/class_with_inner_struct.rs b/tests/expectations/tests/class_with_inner_struct.rs index 2f87355c0b..8d21b674e8 100644 --- a/tests/expectations/tests/class_with_inner_struct.rs +++ b/tests/expectations/tests/class_with_inner_struct.rs @@ -229,7 +229,7 @@ fn bindgen_test_layout_B() { ); } #[repr(i32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum StepSyntax { Keyword = 0, FunctionalWithoutKeyword = 1, diff --git a/tests/expectations/tests/class_with_inner_struct_1_0.rs b/tests/expectations/tests/class_with_inner_struct_1_0.rs index d7dd0b55c7..4bb71602b4 100644 --- a/tests/expectations/tests/class_with_inner_struct_1_0.rs +++ b/tests/expectations/tests/class_with_inner_struct_1_0.rs @@ -287,7 +287,7 @@ impl Clone for B { } } #[repr(i32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum StepSyntax { Keyword = 0, FunctionalWithoutKeyword = 1, diff --git a/tests/expectations/tests/const_enum_unnamed.rs b/tests/expectations/tests/const_enum_unnamed.rs index dae005abd8..da0ec2b82d 100644 --- a/tests/expectations/tests/const_enum_unnamed.rs +++ b/tests/expectations/tests/const_enum_unnamed.rs @@ -8,7 +8,7 @@ pub const FOO_BAR: _bindgen_ty_1 = _bindgen_ty_1::FOO_BAR; pub const FOO_BAZ: _bindgen_ty_1 = _bindgen_ty_1::FOO_BAZ; #[repr(u32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum _bindgen_ty_1 { FOO_BAR = 0, FOO_BAZ = 1, @@ -20,7 +20,7 @@ pub struct Foo { } pub const Foo_FOO_BAR: Foo__bindgen_ty_1 = Foo__bindgen_ty_1::FOO_BAR; #[repr(u32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Foo__bindgen_ty_1 { FOO_BAR = 10, } diff --git a/tests/expectations/tests/constify-enum.rs b/tests/expectations/tests/constify-enum.rs index e3fd235414..091743e945 100644 --- a/tests/expectations/tests/constify-enum.rs +++ b/tests/expectations/tests/constify-enum.rs @@ -13,7 +13,7 @@ impl nsCSSPropertyID { nsCSSPropertyID::eCSSPropertyAlias_aa; } #[repr(u32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum nsCSSPropertyID { eCSSProperty_a = 0, eCSSProperty_b = 1, diff --git a/tests/expectations/tests/dupe-enum-variant-in-namespace.rs b/tests/expectations/tests/dupe-enum-variant-in-namespace.rs index 2d3c4b3384..85e4539253 100644 --- a/tests/expectations/tests/dupe-enum-variant-in-namespace.rs +++ b/tests/expectations/tests/dupe-enum-variant-in-namespace.rs @@ -19,7 +19,7 @@ pub mod root { pub const Foo3: root::foo::Bar = Bar::Foo2; } #[repr(u32)] - #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] + #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Bar { Foo = 0, Foo2 = 1, diff --git a/tests/expectations/tests/empty-enum.rs b/tests/expectations/tests/empty-enum.rs index bdf6b9e6d1..fe188b3e3e 100644 --- a/tests/expectations/tests/empty-enum.rs +++ b/tests/expectations/tests/empty-enum.rs @@ -7,7 +7,7 @@ pub type EmptyConstified = ::std::os::raw::c_uint; #[repr(u32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum EmptyRustified { __bindgen_cannot_repr_c_on_empty_enum = 0, } @@ -15,7 +15,7 @@ pub mod EmptyModule { pub type Type = ::std::os::raw::c_uint; } #[repr(i8)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum EmptyClassRustified { __bindgen_cannot_repr_c_on_empty_enum = 0, } @@ -24,7 +24,7 @@ pub mod EmptyClassModule { pub type Type = ::std::os::raw::c_char; } #[repr(i8)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum ForwardClassRustified { __bindgen_cannot_repr_c_on_empty_enum = 0, } diff --git a/tests/expectations/tests/enum-default-bitfield.rs b/tests/expectations/tests/enum-default-bitfield.rs index 86a0449983..3e8272ad91 100644 --- a/tests/expectations/tests/enum-default-bitfield.rs +++ b/tests/expectations/tests/enum-default-bitfield.rs @@ -39,7 +39,7 @@ impl ::std::ops::BitAndAssign for foo__bindgen_ty_1 { } } #[repr(transparent)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct foo__bindgen_ty_1(pub ::std::os::raw::c_uint); #[test] fn bindgen_test_layout_foo() { @@ -102,10 +102,46 @@ impl ::std::ops::BitAndAssign for Foo { } } #[repr(transparent)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Foo(pub ::std::os::raw::c_uint); pub mod Neg { pub type Type = ::std::os::raw::c_int; pub const MinusOne: Type = -1; pub const One: Type = 1; } +impl NoDebug { + pub const NoDebug1: NoDebug = NoDebug(0); +} +impl NoDebug { + pub const NoDebug2: NoDebug = NoDebug(1); +} +impl ::std::ops::BitOr for NoDebug { + type Output = Self; + #[inline] + fn bitor(self, other: Self) -> Self { + NoDebug(self.0 | other.0) + } +} +impl ::std::ops::BitOrAssign for NoDebug { + #[inline] + fn bitor_assign(&mut self, rhs: NoDebug) { + self.0 |= rhs.0; + } +} +impl ::std::ops::BitAnd for NoDebug { + type Output = Self; + #[inline] + fn bitand(self, other: Self) -> Self { + NoDebug(self.0 & other.0) + } +} +impl ::std::ops::BitAndAssign for NoDebug { + #[inline] + fn bitand_assign(&mut self, rhs: NoDebug) { + self.0 &= rhs.0; + } +} +#[repr(transparent)] +///
+#[derive(Copy, Clone, Hash, PartialEq, Eq)] +pub struct NoDebug(pub ::std::os::raw::c_uint); diff --git a/tests/expectations/tests/enum-default-consts.rs b/tests/expectations/tests/enum-default-consts.rs index 1f086791b9..e913bcbf11 100644 --- a/tests/expectations/tests/enum-default-consts.rs +++ b/tests/expectations/tests/enum-default-consts.rs @@ -49,3 +49,7 @@ pub mod Neg { pub const MinusOne: Type = -1; pub const One: Type = 1; } +pub const NoDebug_NoDebug1: NoDebug = 0; +pub const NoDebug_NoDebug2: NoDebug = 1; +///
+pub type NoDebug = ::std::os::raw::c_uint; diff --git a/tests/expectations/tests/enum-default-module.rs b/tests/expectations/tests/enum-default-module.rs index 7eb63a95db..b8355e3d3a 100644 --- a/tests/expectations/tests/enum-default-module.rs +++ b/tests/expectations/tests/enum-default-module.rs @@ -53,3 +53,9 @@ pub mod Neg { pub const MinusOne: Type = -1; pub const One: Type = 1; } +pub mod NoDebug { + ///
+ pub type Type = ::std::os::raw::c_uint; + pub const NoDebug1: Type = 0; + pub const NoDebug2: Type = 1; +} diff --git a/tests/expectations/tests/enum-default-rust.rs b/tests/expectations/tests/enum-default-rust.rs index 788de139d8..8c697dcc45 100644 --- a/tests/expectations/tests/enum-default-rust.rs +++ b/tests/expectations/tests/enum-default-rust.rs @@ -13,7 +13,7 @@ pub struct foo { pub const foo_FOO_A: foo__bindgen_ty_1 = foo__bindgen_ty_1::FOO_A; pub const foo_FOO_B: foo__bindgen_ty_1 = foo__bindgen_ty_1::FOO_B; #[repr(u32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum foo__bindgen_ty_1 { FOO_A = 0, FOO_B = 1, @@ -47,7 +47,7 @@ impl Default for foo { } } #[repr(u32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Foo { Bar = 0, Qux = 1, @@ -57,3 +57,10 @@ pub mod Neg { pub const MinusOne: Type = -1; pub const One: Type = 1; } +#[repr(u32)] +///
+#[derive(Copy, Clone, Hash, PartialEq, Eq)] +pub enum NoDebug { + NoDebug1 = 0, + NoDebug2 = 1, +} diff --git a/tests/expectations/tests/enum-doc-bitfield.rs b/tests/expectations/tests/enum-doc-bitfield.rs index 02a3adaab9..3be0438e5b 100644 --- a/tests/expectations/tests/enum-doc-bitfield.rs +++ b/tests/expectations/tests/enum-doc-bitfield.rs @@ -60,5 +60,5 @@ impl ::std::ops::BitAndAssign for B { } #[repr(transparent)] /// Document enum -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct B(pub ::std::os::raw::c_uint); diff --git a/tests/expectations/tests/enum-doc-rusty.rs b/tests/expectations/tests/enum-doc-rusty.rs index 7c44143291..e7208a9db6 100644 --- a/tests/expectations/tests/enum-doc-rusty.rs +++ b/tests/expectations/tests/enum-doc-rusty.rs @@ -7,7 +7,7 @@ #[repr(u32)] /// Document enum -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum B { /// Document field with three slashes VAR_A = 0, diff --git a/tests/expectations/tests/enum-undefault.rs b/tests/expectations/tests/enum-undefault.rs index 7bb3169375..e5618b9148 100644 --- a/tests/expectations/tests/enum-undefault.rs +++ b/tests/expectations/tests/enum-undefault.rs @@ -6,7 +6,7 @@ )] #[repr(u32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Foo { Bar = 0, Qux = 1, diff --git a/tests/expectations/tests/enum.rs b/tests/expectations/tests/enum.rs index 3a1bffcb40..e4a7227637 100644 --- a/tests/expectations/tests/enum.rs +++ b/tests/expectations/tests/enum.rs @@ -47,3 +47,7 @@ pub type Foo = ::std::os::raw::c_uint; pub const Neg_MinusOne: Neg = -1; pub const Neg_One: Neg = 1; pub type Neg = ::std::os::raw::c_int; +pub const NoDebug_NoDebug1: NoDebug = 0; +pub const NoDebug_NoDebug2: NoDebug = 1; +///
+pub type NoDebug = ::std::os::raw::c_uint; diff --git a/tests/expectations/tests/enum_alias.rs b/tests/expectations/tests/enum_alias.rs index 7d6a49a968..ad62d16fa2 100644 --- a/tests/expectations/tests/enum_alias.rs +++ b/tests/expectations/tests/enum_alias.rs @@ -6,7 +6,7 @@ )] #[repr(u8)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Bar { VAL = 0, } diff --git a/tests/expectations/tests/enum_and_vtable_mangling.rs b/tests/expectations/tests/enum_and_vtable_mangling.rs index 72efb618ed..5eaaec95e0 100644 --- a/tests/expectations/tests/enum_and_vtable_mangling.rs +++ b/tests/expectations/tests/enum_and_vtable_mangling.rs @@ -8,7 +8,7 @@ pub const match_: _bindgen_ty_1 = _bindgen_ty_1::match_; pub const whatever_else: _bindgen_ty_1 = _bindgen_ty_1::whatever_else; #[repr(u32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum _bindgen_ty_1 { match_ = 0, whatever_else = 1, diff --git a/tests/expectations/tests/enum_dupe.rs b/tests/expectations/tests/enum_dupe.rs index 185a870de3..869375bbfd 100644 --- a/tests/expectations/tests/enum_dupe.rs +++ b/tests/expectations/tests/enum_dupe.rs @@ -9,7 +9,7 @@ impl Foo { pub const Dupe: Foo = Foo::Bar; } #[repr(u32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Foo { Bar = 1, } diff --git a/tests/expectations/tests/enum_explicit_type.rs b/tests/expectations/tests/enum_explicit_type.rs index 92b4ace2c1..29bc5d8cfc 100644 --- a/tests/expectations/tests/enum_explicit_type.rs +++ b/tests/expectations/tests/enum_explicit_type.rs @@ -6,46 +6,46 @@ )] #[repr(u8)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Foo { Bar = 0, Qux = 1, } #[repr(i8)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Neg { MinusOne = -1, One = 1, } #[repr(u16)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Bigger { Much = 255, Larger = 256, } #[repr(i64)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum MuchLong { MuchLow = -4294967296, } #[repr(i64)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum MuchLongLong { I64_MIN = -9223372036854775808, } #[repr(u64)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum MuchULongLong { MuchHigh = 4294967296, } #[repr(u8)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum BoolEnumsAreFun { Value = 1, } pub type MyType = bool; #[repr(u8)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum BoolEnumsAreFun2 { Value2 = 1, } @@ -54,7 +54,7 @@ pub const AnonymousVariantOne: _bindgen_ty_1 = pub const AnonymousVariantTwo: _bindgen_ty_1 = _bindgen_ty_1::AnonymousVariantTwo; #[repr(u8)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum _bindgen_ty_1 { AnonymousVariantOne = 0, AnonymousVariantTwo = 1, diff --git a/tests/expectations/tests/enum_in_template_with_typedef.rs b/tests/expectations/tests/enum_in_template_with_typedef.rs index 60bd783499..75dce30c0e 100644 --- a/tests/expectations/tests/enum_in_template_with_typedef.rs +++ b/tests/expectations/tests/enum_in_template_with_typedef.rs @@ -15,7 +15,7 @@ impl std_fbstring_core_Category { pub const Bar: std_fbstring_core_Category = std_fbstring_core_Category::Foo; } #[repr(u8)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum std_fbstring_core_Category { Foo = 0, } diff --git a/tests/expectations/tests/enum_negative.rs b/tests/expectations/tests/enum_negative.rs index e37d42d573..02b4baed59 100644 --- a/tests/expectations/tests/enum_negative.rs +++ b/tests/expectations/tests/enum_negative.rs @@ -6,7 +6,7 @@ )] #[repr(i32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Foo { Bar = -2, Qux = 1, diff --git a/tests/expectations/tests/enum_packed.rs b/tests/expectations/tests/enum_packed.rs index 62f69fc9ee..89b0da461d 100644 --- a/tests/expectations/tests/enum_packed.rs +++ b/tests/expectations/tests/enum_packed.rs @@ -6,19 +6,19 @@ )] #[repr(u8)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Foo { Bar = 0, Qux = 1, } #[repr(i8)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Neg { MinusOne = -1, One = 1, } #[repr(u16)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Bigger { Much = 255, Larger = 256, diff --git a/tests/expectations/tests/forward-enum-decl.rs b/tests/expectations/tests/forward-enum-decl.rs index eddb53782f..0ac550bcba 100644 --- a/tests/expectations/tests/forward-enum-decl.rs +++ b/tests/expectations/tests/forward-enum-decl.rs @@ -6,7 +6,7 @@ )] #[repr(i32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum CSSPseudoClassType { empty = 0, link = 1, diff --git a/tests/expectations/tests/func_ptr_in_struct.rs b/tests/expectations/tests/func_ptr_in_struct.rs index bd1ec8c457..8f98763fbc 100644 --- a/tests/expectations/tests/func_ptr_in_struct.rs +++ b/tests/expectations/tests/func_ptr_in_struct.rs @@ -6,7 +6,7 @@ )] #[repr(i32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum baz { __bindgen_cannot_repr_c_on_empty_enum = 0, } diff --git a/tests/expectations/tests/issue-1198-alias-rust-bitfield-enum.rs b/tests/expectations/tests/issue-1198-alias-rust-bitfield-enum.rs index 8ef4c498fb..ed9f7c9ba8 100644 --- a/tests/expectations/tests/issue-1198-alias-rust-bitfield-enum.rs +++ b/tests/expectations/tests/issue-1198-alias-rust-bitfield-enum.rs @@ -41,7 +41,7 @@ impl ::std::ops::BitAndAssign for MyDupeEnum { } } #[repr(transparent)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct MyDupeEnum(pub ::std::os::raw::c_uint); impl MyOtherDupeEnum { pub const C: MyOtherDupeEnum = MyOtherDupeEnum(0); @@ -79,5 +79,5 @@ impl ::std::ops::BitAndAssign for MyOtherDupeEnum { } } #[repr(transparent)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct MyOtherDupeEnum(pub ::std::os::raw::c_uint); diff --git a/tests/expectations/tests/issue-1198-alias-rust-enum.rs b/tests/expectations/tests/issue-1198-alias-rust-enum.rs index 491430389f..fda73a021f 100644 --- a/tests/expectations/tests/issue-1198-alias-rust-enum.rs +++ b/tests/expectations/tests/issue-1198-alias-rust-enum.rs @@ -9,7 +9,7 @@ impl MyDupeEnum { pub const A_alias: MyDupeEnum = MyDupeEnum::A; } #[repr(u32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum MyDupeEnum { A = 0, B = 1, @@ -18,7 +18,7 @@ impl MyOtherDupeEnum { pub const C_alias: MyOtherDupeEnum = MyOtherDupeEnum::C; } #[repr(u32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum MyOtherDupeEnum { C = 0, D = 1, diff --git a/tests/expectations/tests/issue-1488-enum-new-type.rs b/tests/expectations/tests/issue-1488-enum-new-type.rs index c61b93ba5c..b762659a50 100644 --- a/tests/expectations/tests/issue-1488-enum-new-type.rs +++ b/tests/expectations/tests/issue-1488-enum-new-type.rs @@ -20,7 +20,7 @@ pub mod Bar { #[derive(Debug, Copy, Clone)] pub struct BarAlias(pub Bar::Type); #[repr(u32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Qux { E = 0, F = 1, diff --git a/tests/expectations/tests/issue-1554.rs b/tests/expectations/tests/issue-1554.rs index e50023eea3..7e7cddd610 100644 --- a/tests/expectations/tests/issue-1554.rs +++ b/tests/expectations/tests/issue-1554.rs @@ -9,7 +9,7 @@ #[repr(u32)] #[non_exhaustive] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Planet { earth = 0, mars = 1, diff --git a/tests/expectations/tests/issue-372.rs b/tests/expectations/tests/issue-372.rs index d232aabd70..ce6e36c5b2 100644 --- a/tests/expectations/tests/issue-372.rs +++ b/tests/expectations/tests/issue-372.rs @@ -78,7 +78,7 @@ pub mod root { } } #[repr(u32)] - #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] + #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum n { o = 0, p = 1, diff --git a/tests/expectations/tests/issue-410.rs b/tests/expectations/tests/issue-410.rs index 71d27a2247..ad7463c266 100644 --- a/tests/expectations/tests/issue-410.rs +++ b/tests/expectations/tests/issue-410.rs @@ -42,7 +42,7 @@ pub mod root { } } #[repr(u32)] - #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] + #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum JSWhyMagic { __bindgen_cannot_repr_c_on_empty_enum = 0, } diff --git a/tests/expectations/tests/issue-493.rs b/tests/expectations/tests/issue-493.rs index 74e68ecbc2..867e3d174f 100644 --- a/tests/expectations/tests/issue-493.rs +++ b/tests/expectations/tests/issue-493.rs @@ -71,7 +71,7 @@ impl Default for basic_string___long { pub const basic_string___min_cap: basic_string__bindgen_ty_1 = basic_string__bindgen_ty_1::__min_cap; #[repr(i32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum basic_string__bindgen_ty_1 { __min_cap = 0, } @@ -110,7 +110,7 @@ impl Default for basic_string___ulx { pub const basic_string___n_words: basic_string__bindgen_ty_2 = basic_string__bindgen_ty_2::__n_words; #[repr(i32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum basic_string__bindgen_ty_2 { __n_words = 0, } diff --git a/tests/expectations/tests/issue-493_1_0.rs b/tests/expectations/tests/issue-493_1_0.rs index f15ff8a768..c42d06b5b1 100644 --- a/tests/expectations/tests/issue-493_1_0.rs +++ b/tests/expectations/tests/issue-493_1_0.rs @@ -71,7 +71,7 @@ impl Default for basic_string___long { pub const basic_string___min_cap: basic_string__bindgen_ty_1 = basic_string__bindgen_ty_1::__min_cap; #[repr(i32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum basic_string__bindgen_ty_1 { __min_cap = 0, } @@ -103,7 +103,7 @@ pub struct basic_string___ulx { pub const basic_string___n_words: basic_string__bindgen_ty_2 = basic_string__bindgen_ty_2::__n_words; #[repr(i32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum basic_string__bindgen_ty_2 { __n_words = 0, } diff --git a/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs b/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs index 98f3ea040f..4b2fa7a2af 100644 --- a/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs +++ b/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs @@ -8,7 +8,7 @@ pub const ENUM_VARIANT_1: _bindgen_ty_1 = _bindgen_ty_1::ENUM_VARIANT_1; pub const ENUM_VARIANT_2: _bindgen_ty_1 = _bindgen_ty_1::ENUM_VARIANT_2; #[repr(u32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum _bindgen_ty_1 { ENUM_VARIANT_1 = 0, ENUM_VARIANT_2 = 1, diff --git a/tests/expectations/tests/issue-888-enum-var-decl-jump.rs b/tests/expectations/tests/issue-888-enum-var-decl-jump.rs index 0e8bb8e0f1..6ac308a74f 100644 --- a/tests/expectations/tests/issue-888-enum-var-decl-jump.rs +++ b/tests/expectations/tests/issue-888-enum-var-decl-jump.rs @@ -36,7 +36,7 @@ pub mod root { } } #[repr(u32)] - #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] + #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum a { __bindgen_cannot_repr_c_on_empty_enum = 0, } diff --git a/tests/expectations/tests/jsval_layout_opaque.rs b/tests/expectations/tests/jsval_layout_opaque.rs index 233aff7b41..c9ce5ca0d5 100644 --- a/tests/expectations/tests/jsval_layout_opaque.rs +++ b/tests/expectations/tests/jsval_layout_opaque.rs @@ -97,7 +97,7 @@ pub const JSVAL_PAYLOAD_MASK: u64 = 140737488355327; pub const JSVAL_TAG_MASK: i64 = -140737488355328; pub type size_t = ::std::os::raw::c_ulonglong; #[repr(u8)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum JSValueType { JSVAL_TYPE_DOUBLE = 0, JSVAL_TYPE_INT32 = 1, @@ -112,7 +112,7 @@ pub enum JSValueType { JSVAL_TYPE_MISSING = 33, } #[repr(u32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum JSValueTag { JSVAL_TAG_MAX_DOUBLE = 131056, JSVAL_TAG_INT32 = 131057, @@ -125,7 +125,7 @@ pub enum JSValueTag { JSVAL_TAG_OBJECT = 131064, } #[repr(u64)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum JSValueShiftedTag { JSVAL_SHIFTED_TAG_MAX_DOUBLE = 18444492278190833663, JSVAL_SHIFTED_TAG_INT32 = 18444633011384221696, @@ -138,7 +138,7 @@ pub enum JSValueShiftedTag { JSVAL_SHIFTED_TAG_OBJECT = 18445618173802708992, } #[repr(u32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum JSWhyMagic { /// a hole in a native object's elements JS_ELEMENTS_HOLE = 0, diff --git a/tests/expectations/tests/jsval_layout_opaque_1_0.rs b/tests/expectations/tests/jsval_layout_opaque_1_0.rs index f2433a4619..a5d35c19e8 100644 --- a/tests/expectations/tests/jsval_layout_opaque_1_0.rs +++ b/tests/expectations/tests/jsval_layout_opaque_1_0.rs @@ -140,7 +140,7 @@ pub const JSVAL_PAYLOAD_MASK: u64 = 140737488355327; pub const JSVAL_TAG_MASK: i64 = -140737488355328; pub type size_t = ::std::os::raw::c_ulonglong; #[repr(u8)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum JSValueType { JSVAL_TYPE_DOUBLE = 0, JSVAL_TYPE_INT32 = 1, @@ -155,7 +155,7 @@ pub enum JSValueType { JSVAL_TYPE_MISSING = 33, } #[repr(u32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum JSValueTag { JSVAL_TAG_MAX_DOUBLE = 131056, JSVAL_TAG_INT32 = 131057, @@ -168,7 +168,7 @@ pub enum JSValueTag { JSVAL_TAG_OBJECT = 131064, } #[repr(u64)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum JSValueShiftedTag { JSVAL_SHIFTED_TAG_MAX_DOUBLE = 18444492278190833663, JSVAL_SHIFTED_TAG_INT32 = 18444633011384221696, @@ -181,7 +181,7 @@ pub enum JSValueShiftedTag { JSVAL_SHIFTED_TAG_OBJECT = 18445618173802708992, } #[repr(u32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum JSWhyMagic { /// a hole in a native object's elements JS_ELEMENTS_HOLE = 0, diff --git a/tests/expectations/tests/layout_array_too_long.rs b/tests/expectations/tests/layout_array_too_long.rs index dbfd80d959..9fe993a468 100644 --- a/tests/expectations/tests/layout_array_too_long.rs +++ b/tests/expectations/tests/layout_array_too_long.rs @@ -12,7 +12,7 @@ pub const IP_FIRST_FRAG_IDX: _bindgen_ty_1 = _bindgen_ty_1::IP_FIRST_FRAG_IDX; pub const IP_MIN_FRAG_NUM: _bindgen_ty_1 = _bindgen_ty_1::IP_MIN_FRAG_NUM; pub const IP_MAX_FRAG_NUM: _bindgen_ty_1 = _bindgen_ty_1::IP_MAX_FRAG_NUM; #[repr(u32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum _bindgen_ty_1 { ///< index of last fragment IP_LAST_FRAG_IDX = 0, diff --git a/tests/expectations/tests/layout_cmdline_token.rs b/tests/expectations/tests/layout_cmdline_token.rs index 38a4622b2b..601e88b562 100644 --- a/tests/expectations/tests/layout_cmdline_token.rs +++ b/tests/expectations/tests/layout_cmdline_token.rs @@ -177,7 +177,7 @@ fn bindgen_test_layout_cmdline_token_ops() { ); } #[repr(u32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum cmdline_numtype { UINT8 = 0, UINT16 = 1, diff --git a/tests/expectations/tests/layout_eth_conf.rs b/tests/expectations/tests/layout_eth_conf.rs index 78e91c591a..b75a16551e 100644 --- a/tests/expectations/tests/layout_eth_conf.rs +++ b/tests/expectations/tests/layout_eth_conf.rs @@ -127,7 +127,7 @@ pub const RTE_ETH_FLOW_MAX: u32 = 22; #[repr(u32)] /// A set of values to identify what method is to be used to route /// packets to multiple queues. -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum rte_eth_rx_mq_mode { /// None of DCB,RSS or VMDQ mode ETH_MQ_RX_NONE = 0, @@ -399,7 +399,7 @@ impl rte_eth_rxmode { #[repr(u32)] /// A set of values to identify what method is to be used to transmit /// packets using multi-TCs. -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum rte_eth_tx_mq_mode { ///< It is in neither DCB nor VT mode. ETH_MQ_TX_NONE = 0, @@ -616,7 +616,7 @@ impl Default for rte_eth_rss_conf { #[repr(u32)] /// This enum indicates the possible number of traffic classes /// in DCB configratioins -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum rte_eth_nb_tcs { ///< 4 TCs with DCB. ETH_4_TCS = 4, @@ -626,7 +626,7 @@ pub enum rte_eth_nb_tcs { #[repr(u32)] /// This enum indicates the possible number of queue pools /// in VMDQ configurations. -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum rte_eth_nb_pools { ///< 8 VMDq pools. ETH_8_POOLS = 8, @@ -1179,7 +1179,7 @@ impl Default for rte_eth_vmdq_rx_conf { } #[repr(u32)] /// Flow Director setting modes: none, signature or perfect. -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum rte_fdir_mode { ///< Disable FDIR support. RTE_FDIR_MODE_NONE = 0, @@ -1195,7 +1195,7 @@ pub enum rte_fdir_mode { #[repr(u32)] /// Memory space that can be configured to store Flow Director filters /// in the board memory. -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum rte_fdir_pballoc_type { ///< 64k. RTE_FDIR_PBALLOC_64K = 0, @@ -1206,7 +1206,7 @@ pub enum rte_fdir_pballoc_type { } #[repr(u32)] /// Select report mode of FDIR hash information in RX descriptors. -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum rte_fdir_status_mode { ///< Never report FDIR hash. RTE_FDIR_NO_REPORT_STATUS = 0, @@ -1544,7 +1544,7 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { } #[repr(u32)] /// Payload type -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum rte_eth_payload_type { RTE_ETH_PAYLOAD_UNKNOWN = 0, RTE_ETH_RAW_PAYLOAD = 1, diff --git a/tests/expectations/tests/layout_eth_conf_1_0.rs b/tests/expectations/tests/layout_eth_conf_1_0.rs index 50653c1e09..8800cf59ab 100644 --- a/tests/expectations/tests/layout_eth_conf_1_0.rs +++ b/tests/expectations/tests/layout_eth_conf_1_0.rs @@ -170,7 +170,7 @@ pub const RTE_ETH_FLOW_MAX: u32 = 22; #[repr(u32)] /// A set of values to identify what method is to be used to route /// packets to multiple queues. -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum rte_eth_rx_mq_mode { /// None of DCB,RSS or VMDQ mode ETH_MQ_RX_NONE = 0, @@ -447,7 +447,7 @@ impl rte_eth_rxmode { #[repr(u32)] /// A set of values to identify what method is to be used to transmit /// packets using multi-TCs. -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum rte_eth_tx_mq_mode { ///< It is in neither DCB nor VT mode. ETH_MQ_TX_NONE = 0, @@ -674,7 +674,7 @@ impl Default for rte_eth_rss_conf { #[repr(u32)] /// This enum indicates the possible number of traffic classes /// in DCB configratioins -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum rte_eth_nb_tcs { ///< 4 TCs with DCB. ETH_4_TCS = 4, @@ -684,7 +684,7 @@ pub enum rte_eth_nb_tcs { #[repr(u32)] /// This enum indicates the possible number of queue pools /// in VMDQ configurations. -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum rte_eth_nb_pools { ///< 8 VMDq pools. ETH_8_POOLS = 8, @@ -1277,7 +1277,7 @@ impl Default for rte_eth_vmdq_rx_conf { } #[repr(u32)] /// Flow Director setting modes: none, signature or perfect. -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum rte_fdir_mode { ///< Disable FDIR support. RTE_FDIR_MODE_NONE = 0, @@ -1293,7 +1293,7 @@ pub enum rte_fdir_mode { #[repr(u32)] /// Memory space that can be configured to store Flow Director filters /// in the board memory. -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum rte_fdir_pballoc_type { ///< 64k. RTE_FDIR_PBALLOC_64K = 0, @@ -1304,7 +1304,7 @@ pub enum rte_fdir_pballoc_type { } #[repr(u32)] /// Select report mode of FDIR hash information in RX descriptors. -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum rte_fdir_status_mode { ///< Never report FDIR hash. RTE_FDIR_NO_REPORT_STATUS = 0, @@ -1657,7 +1657,7 @@ impl Clone for rte_eth_fdir_masks { } #[repr(u32)] /// Payload type -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum rte_eth_payload_type { RTE_ETH_PAYLOAD_UNKNOWN = 0, RTE_ETH_RAW_PAYLOAD = 1, diff --git a/tests/expectations/tests/layout_large_align_field.rs b/tests/expectations/tests/layout_large_align_field.rs index cbfb286c2b..3cf3174548 100644 --- a/tests/expectations/tests/layout_large_align_field.rs +++ b/tests/expectations/tests/layout_large_align_field.rs @@ -42,7 +42,7 @@ pub const IP_FIRST_FRAG_IDX: _bindgen_ty_1 = _bindgen_ty_1::IP_FIRST_FRAG_IDX; pub const IP_MIN_FRAG_NUM: _bindgen_ty_1 = _bindgen_ty_1::IP_MIN_FRAG_NUM; pub const IP_MAX_FRAG_NUM: _bindgen_ty_1 = _bindgen_ty_1::IP_MAX_FRAG_NUM; #[repr(u32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum _bindgen_ty_1 { ///< index of last fragment IP_LAST_FRAG_IDX = 0, diff --git a/tests/expectations/tests/libclang-3.9/constant-evaluate.rs b/tests/expectations/tests/libclang-3.9/constant-evaluate.rs index 5f61f88ab6..77e281289e 100644 --- a/tests/expectations/tests/libclang-3.9/constant-evaluate.rs +++ b/tests/expectations/tests/libclang-3.9/constant-evaluate.rs @@ -8,7 +8,7 @@ pub const foo: _bindgen_ty_1 = _bindgen_ty_1::foo; pub const bar: _bindgen_ty_1 = _bindgen_ty_1::bar; #[repr(u32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum _bindgen_ty_1 { foo = 4, bar = 8, diff --git a/tests/expectations/tests/libclang-4/constant-evaluate.rs b/tests/expectations/tests/libclang-4/constant-evaluate.rs index 9925e8d9d4..df2638f447 100644 --- a/tests/expectations/tests/libclang-4/constant-evaluate.rs +++ b/tests/expectations/tests/libclang-4/constant-evaluate.rs @@ -8,7 +8,7 @@ pub const foo: _bindgen_ty_1 = _bindgen_ty_1::foo; pub const bar: _bindgen_ty_1 = _bindgen_ty_1::bar; #[repr(u32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum _bindgen_ty_1 { foo = 4, bar = 8, diff --git a/tests/expectations/tests/libclang-5/constant-evaluate.rs b/tests/expectations/tests/libclang-5/constant-evaluate.rs index 9925e8d9d4..df2638f447 100644 --- a/tests/expectations/tests/libclang-5/constant-evaluate.rs +++ b/tests/expectations/tests/libclang-5/constant-evaluate.rs @@ -8,7 +8,7 @@ pub const foo: _bindgen_ty_1 = _bindgen_ty_1::foo; pub const bar: _bindgen_ty_1 = _bindgen_ty_1::bar; #[repr(u32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum _bindgen_ty_1 { foo = 4, bar = 8, diff --git a/tests/expectations/tests/libclang-9/constant-evaluate.rs b/tests/expectations/tests/libclang-9/constant-evaluate.rs index 9925e8d9d4..df2638f447 100644 --- a/tests/expectations/tests/libclang-9/constant-evaluate.rs +++ b/tests/expectations/tests/libclang-9/constant-evaluate.rs @@ -8,7 +8,7 @@ pub const foo: _bindgen_ty_1 = _bindgen_ty_1::foo; pub const bar: _bindgen_ty_1 = _bindgen_ty_1::bar; #[repr(u32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum _bindgen_ty_1 { foo = 4, bar = 8, diff --git a/tests/expectations/tests/newtype-enum.rs b/tests/expectations/tests/newtype-enum.rs index 4d9cc7e159..26a4eb1fdf 100644 --- a/tests/expectations/tests/newtype-enum.rs +++ b/tests/expectations/tests/newtype-enum.rs @@ -18,5 +18,5 @@ impl Foo { pub const Negative: Foo = Foo(-3); } #[repr(transparent)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Foo(pub ::std::os::raw::c_int); diff --git a/tests/expectations/tests/nsStyleAutoArray.rs b/tests/expectations/tests/nsStyleAutoArray.rs index 0f3463cbdf..091be3ddf2 100644 --- a/tests/expectations/tests/nsStyleAutoArray.rs +++ b/tests/expectations/tests/nsStyleAutoArray.rs @@ -24,7 +24,7 @@ pub struct nsStyleAutoArray { pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } #[repr(i32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum nsStyleAutoArray_WithSingleInitialElement { WITH_SINGLE_INITIAL_ELEMENT = 0, } diff --git a/tests/expectations/tests/ord-enum.rs b/tests/expectations/tests/ord-enum.rs index 7988f29061..a72fef8df6 100644 --- a/tests/expectations/tests/ord-enum.rs +++ b/tests/expectations/tests/ord-enum.rs @@ -6,7 +6,7 @@ )] #[repr(i32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] +#[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] pub enum A { A0 = 0, A1 = 1, @@ -14,7 +14,7 @@ pub enum A { A3 = -1, } #[repr(i32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] +#[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] pub enum B { B0 = 1, B1 = 4, diff --git a/tests/expectations/tests/overflowed_enum.rs b/tests/expectations/tests/overflowed_enum.rs index 76b6f730cb..94e166addb 100644 --- a/tests/expectations/tests/overflowed_enum.rs +++ b/tests/expectations/tests/overflowed_enum.rs @@ -6,14 +6,14 @@ )] #[repr(u32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Foo { BAP_ARM = 9698489, BAP_X86 = 11960045, BAP_X86_64 = 3128633167, } #[repr(u16)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Bar { One = 1, Big = 2, diff --git a/tests/expectations/tests/prepend-enum-constified-variant.rs b/tests/expectations/tests/prepend-enum-constified-variant.rs index 5b8c878398..b2b094443b 100644 --- a/tests/expectations/tests/prepend-enum-constified-variant.rs +++ b/tests/expectations/tests/prepend-enum-constified-variant.rs @@ -9,7 +9,7 @@ impl AVCodecID { pub const AV_CODEC_ID_TTF: AVCodecID = AVCodecID::AV_CODEC_ID_FIRST_UNKNOWN; } #[repr(u32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum AVCodecID { AV_CODEC_ID_FIRST_UNKNOWN = 98304, } diff --git a/tests/expectations/tests/short-enums.rs b/tests/expectations/tests/short-enums.rs index bb30b67e6c..a8a494eaa6 100644 --- a/tests/expectations/tests/short-enums.rs +++ b/tests/expectations/tests/short-enums.rs @@ -6,17 +6,17 @@ )] #[repr(u8)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum one_byte_t { SOME_VALUE = 1, } #[repr(u16)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum two_byte_t { SOME_OTHER_VALUE = 256, } #[repr(u32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum four_byte_t { SOME_BIGGER_VALUE = 16777216, } diff --git a/tests/expectations/tests/struct_typedef.rs b/tests/expectations/tests/struct_typedef.rs index e57efc8a03..5756ab8188 100644 --- a/tests/expectations/tests/struct_typedef.rs +++ b/tests/expectations/tests/struct_typedef.rs @@ -75,13 +75,13 @@ impl Default for _bindgen_ty_1 { pub type struct_ptr_t = *mut _bindgen_ty_1; pub type struct_ptr_ptr_t = *mut *mut _bindgen_ty_1; #[repr(u32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum typedef_named_enum { ENUM_HAS_NAME = 1, } pub const ENUM_IS_ANON: _bindgen_ty_2 = _bindgen_ty_2::ENUM_IS_ANON; #[repr(u32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum _bindgen_ty_2 { ENUM_IS_ANON = 0, } diff --git a/tests/expectations/tests/struct_typedef_ns.rs b/tests/expectations/tests/struct_typedef_ns.rs index 43c5d38fcc..ef91fe49a9 100644 --- a/tests/expectations/tests/struct_typedef_ns.rs +++ b/tests/expectations/tests/struct_typedef_ns.rs @@ -44,7 +44,7 @@ pub mod root { ); } #[repr(u32)] - #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] + #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum typedef_enum { BAR = 1, } @@ -87,7 +87,7 @@ pub mod root { pub const _bindgen_mod_id_12_BAR: root::_bindgen_mod_id_12::_bindgen_ty_2 = _bindgen_ty_2::BAR; #[repr(u32)] - #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] + #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum _bindgen_ty_2 { BAR = 1, } diff --git a/tests/expectations/tests/weird_bitfields.rs b/tests/expectations/tests/weird_bitfields.rs index 4998a944a2..2c1a7d2588 100644 --- a/tests/expectations/tests/weird_bitfields.rs +++ b/tests/expectations/tests/weird_bitfields.rs @@ -93,7 +93,7 @@ where } } #[repr(u32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum nsStyleSVGOpacitySource { eStyleSVGOpacitySource_Normal = 0, eStyleSVGOpacitySource_ContextFillOpacity = 1, diff --git a/tests/headers/enum.h b/tests/headers/enum.h index 901b805814..8b41f855d9 100644 --- a/tests/headers/enum.h +++ b/tests/headers/enum.h @@ -17,3 +17,9 @@ enum Neg { MinusOne = -1, One = 1, }; + +/**
*/ +enum NoDebug { + NoDebug1, + NoDebug2, +}; From faeaba6ac8974dbf20df74322d2834d74fb14820 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Fri, 13 Nov 2020 19:45:45 +0100 Subject: [PATCH 104/942] Document 0.47 dot-release. --- CHANGELOG.md | 74 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 487405ee8b..18266bd739 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,22 +9,24 @@ - [Removed](#removed) - [Fixed](#fixed) - [Security](#security) +- [0.55.1](#0551) + - [Fixed](#fixed-1) - [0.55.0](#0550) - [Removed](#removed-1) - [Added](#added-1) - [Changed](#changed-1) - - [Fixed](#fixed-1) + - [Fixed](#fixed-2) - [0.54.1](#0541) - [Added](#added-2) - [Changed](#changed-2) - - [Fixed](#fixed-2) + - [Fixed](#fixed-3) - [0.54.0](#0540) - [Added](#added-3) - [Changed](#changed-3) - - [Fixed](#fixed-3) + - [Fixed](#fixed-4) - [0.53.3](#0533) - [Added](#added-4) - - [Fixed](#fixed-4) + - [Fixed](#fixed-5) - [0.53.2](#0532) - [Changed](#changed-4) - [0.53.1](#0531) @@ -32,16 +34,16 @@ - [0.53.0](#0530) - [Added](#added-6) - [Changed](#changed-5) - - [Fixed](#fixed-5) + - [Fixed](#fixed-6) - [0.52.0](#0520) - [Added](#added-7) - [Changed](#changed-6) - - [Fixed](#fixed-6) -- [0.51.1](#0511) - [Fixed](#fixed-7) +- [0.51.1](#0511) + - [Fixed](#fixed-8) - [Changed](#changed-7) - [0.51.0](#0510) - - [Fixed](#fixed-8) + - [Fixed](#fixed-9) - [Changed](#changed-8) - [Added](#added-8) - [0.50.0](#0500) @@ -51,64 +53,66 @@ - [0.49.2](#0492) - [Changed](#changed-9) - [0.49.1](#0491) - - [Fixed](#fixed-9) + - [Fixed](#fixed-10) - [Changed](#changed-10) - [0.49.0](#0490) - [Added](#added-11) - - [Fixed](#fixed-10) + - [Fixed](#fixed-11) - [Changed](#changed-11) - [0.48.1](#0481) - - [Fixed](#fixed-11) + - [Fixed](#fixed-12) - [0.48.0](#0480) - [Changed](#changed-12) - - [Fixed](#fixed-12) + - [Fixed](#fixed-13) +- [0.47.4](#0474) + - [Added](#added-12) - [0.47.3](#0473) - [Changed](#changed-13) - [0.47.2](#0472) - - [Fixed](#fixed-13) + - [Fixed](#fixed-14) - [0.47.1](#0471) - [Changed](#changed-14) - - [Fixed](#fixed-14) + - [Fixed](#fixed-15) - [0.47.0](#0470) - [Changed](#changed-15) - - [Fixed](#fixed-15) + - [Fixed](#fixed-16) - [0.33.1 .. 0.46.0](#0331--0460) - - [Added](#added-12) + - [Added](#added-13) - [Removed](#removed-2) - [Changed](#changed-16) - - [Fixed](#fixed-16) -- [0.33.1](#0331) - [Fixed](#fixed-17) +- [0.33.1](#0331) + - [Fixed](#fixed-18) - [0.33.0](#0330) - - [Added](#added-13) + - [Added](#added-14) - [Changed](#changed-17) - [Deprecated](#deprecated-1) - [Removed](#removed-3) - - [Fixed](#fixed-18) + - [Fixed](#fixed-19) - [Security](#security-1) - [0.32.2](#0322) - - [Fixed](#fixed-19) -- [0.32.1](#0321) - [Fixed](#fixed-20) +- [0.32.1](#0321) + - [Fixed](#fixed-21) - [0.32.0](#0320) - - [Added](#added-14) + - [Added](#added-15) - [Changed](#changed-18) - - [Fixed](#fixed-21) + - [Fixed](#fixed-22) - [0.31.0](#0310) - - [Added](#added-15) + - [Added](#added-16) - [Changed](#changed-19) - [Deprecated](#deprecated-2) - [Removed](#removed-4) - - [Fixed](#fixed-22) + - [Fixed](#fixed-23) - [0.30.0](#0300) - - [Added](#added-16) + - [Added](#added-17) - [Changed](#changed-20) - [Deprecated](#deprecated-3) - - [Fixed](#fixed-23) + - [Fixed](#fixed-24) - [0.29.0](#0290) - - [Added](#added-17) + - [Added](#added-18) - [Changed](#changed-21) - - [Fixed](#fixed-24) + - [Fixed](#fixed-25) @@ -539,6 +543,16 @@ Released 2019/03/04 -------------------------------------------------------------------------------- +# 0.47.4 + +Released 2020/11/13 + +## Added + +* Backported BINDGEN_EXTRA_CLANG_ARGS support per request (#1910). + +-------------------------------------------------------------------------------- + # 0.47.3 Released 2019/02/25 From 84b5455f882e10e9ddaa001dc8207023d82cdd5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Fri, 13 Nov 2020 19:58:40 +0100 Subject: [PATCH 105/942] Keep dependencies up-to-date. A few tests change some formatting, but that's fine. --- Cargo.lock | 285 +++++++++--------- Cargo.toml | 4 +- .../tests/default-template-parameter.rs | 4 +- tests/expectations/tests/layout_mbuf.rs | 8 +- tests/expectations/tests/layout_mbuf_1_0.rs | 8 +- tests/expectations/tests/objc_class_method.rs | 2 +- tests/expectations/tests/objc_method.rs | 4 +- .../tests/sentry-defined-multiple-times.rs | 6 +- 8 files changed, 154 insertions(+), 167 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5612ccb327..0d1c23f20c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,362 +2,349 @@ # It is not intended for manual editing. [[package]] name = "aho-corasick" -version = "0.7.6" +version = "0.7.15" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7404febffaa47dac81aa44dba71523c9d069b1bdc50a77db41195149e17f68e5" dependencies = [ - "memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr", ] [[package]] name = "ansi_term" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" dependencies = [ - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi", ] [[package]] name = "atty" -version = "0.2.13" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ - "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "hermit-abi", + "libc", + "winapi", ] [[package]] name = "bindgen" version = "0.55.1" dependencies = [ - "bitflags 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cexpr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "clang-sys 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", - "diff 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", - "env_logger 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "peeking_take_while 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "shlex 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "which 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags", + "cexpr", + "cfg-if 1.0.0", + "clang-sys", + "clap", + "diff", + "env_logger", + "lazy_static", + "lazycell", + "log", + "peeking_take_while", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "which", ] [[package]] name = "bitflags" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "byteorder" -version = "1.3.2" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" [[package]] name = "cexpr" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4aedb84272dbe89af497cf81375129abda4fc0a9e7c5d317498c15cc30c0d27" dependencies = [ - "nom 5.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "nom", ] [[package]] name = "cfg-if" version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clang-sys" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa785e9017cb8e8c8045e3f096b7d1ebc4d7337cceccdca8d678a27f788ac133" dependencies = [ - "glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", - "libloading 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "glob", + "libc", + "libloading", ] [[package]] name = "clap" -version = "2.33.0" +version = "2.33.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" dependencies = [ - "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", - "bitflags 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-width 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", + "ansi_term", + "atty", + "bitflags", + "strsim", + "textwrap", + "unicode-width", + "vec_map", ] [[package]] name = "diff" -version = "0.1.11" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e25ea47919b1560c4e3b7fe0aaab9becf5b84a10325ddf7db0f0ba5e1026499" [[package]] name = "env_logger" -version = "0.7.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54532e3223c5af90a6a757c90b5c5521564b07e5e7a958681bcd2afad421cdcd" dependencies = [ - "atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", - "humantime 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "termcolor 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "atty", + "humantime", + "log", + "regex", + "termcolor", ] [[package]] name = "glob" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" [[package]] -name = "humantime" -version = "1.3.0" +name = "hermit-abi" +version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aca5565f760fb5b220e499d72710ed156fdb74e631659e99377d9ebfbd13ae8" dependencies = [ - "quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc", ] +[[package]] +name = "humantime" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c1ad908cc71012b7bea4d0c53ba96a8cba9962f048fa68d143376143d863b7a" + [[package]] name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "lazycell" -version = "1.2.1" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.66" +version = "0.2.80" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d58d1b70b004888f764dfbf6a26a3b0342a1632d33968e4a179d8011c760614" [[package]] name = "libloading" -version = "0.6.2" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1090080fe06ec2648d0da3881d9453d97e71a45f00eb179af7fdd7e3f686fdb0" dependencies = [ - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 1.0.0", + "winapi", ] [[package]] name = "log" -version = "0.4.8" +version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10", ] [[package]] name = "memchr" -version = "2.2.1" +version = "2.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" [[package]] name = "nom" -version = "5.1.1" +version = "5.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffb4262d26ed83a1c0a33a38fe2bb15797329c85770da05e6b828ddb782627af" dependencies = [ - "memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "version_check 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr", + "version_check", ] [[package]] name = "peeking_take_while" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" [[package]] name = "proc-macro2" -version = "1.0.4" +version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71" dependencies = [ - "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid", ] -[[package]] -name = "quick-error" -version = "1.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "quote" -version = "1.0.2" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" dependencies = [ - "proc-macro2 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2", ] [[package]] name = "regex" -version = "1.3.1" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38cf2c13ed4745de91a5eb834e11c00bcc3709e773173b2ce4c56c9fbde04b9c" dependencies = [ - "aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)", - "memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "regex-syntax 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "aho-corasick", + "memchr", + "regex-syntax", + "thread_local", ] [[package]] name = "regex-syntax" -version = "0.6.12" +version = "0.6.21" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b181ba2dcf07aaccad5448e8ead58db5b742cf85dfe035e2227f137a539a189" [[package]] name = "rustc-hash" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", -] +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" [[package]] name = "shlex" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2" [[package]] name = "strsim" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" [[package]] name = "termcolor" -version = "1.0.5" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f" dependencies = [ - "wincolor 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-util", ] [[package]] name = "textwrap" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" dependencies = [ - "unicode-width 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-width", ] [[package]] name = "thread_local" -version = "0.3.6" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14" dependencies = [ - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static", ] [[package]] name = "unicode-width" -version = "0.1.6" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" [[package]] name = "unicode-xid" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" [[package]] name = "vec_map" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" [[package]] name = "version_check" -version = "0.9.1" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" [[package]] name = "which" -version = "3.0.0" +version = "3.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d011071ae14a2f6671d0b74080ae0cd8ebf3a6f8c9589a2cd45f23126fe29724" dependencies = [ - "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", + "libc", ] [[package]] name = "winapi" -version = "0.3.8" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" dependencies = [ - "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", ] [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.2" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" dependencies = [ - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi", ] [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "wincolor" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[metadata] -"checksum aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "58fb5e95d83b38284460a5fda7d6470aa0b8844d283a0b614b8535e880800d2d" -"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" -"checksum atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "1803c647a3ec87095e7ae7acfca019e98de5ec9a7d01343f611cf3152ed71a90" -"checksum bitflags 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8a606a02debe2813760609f57a64a2ffd27d9fdf5b2f133eaca0b248dd92cdd2" -"checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5" -"checksum cexpr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f4aedb84272dbe89af497cf81375129abda4fc0a9e7c5d317498c15cc30c0d27" -"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" -"checksum clang-sys 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fa785e9017cb8e8c8045e3f096b7d1ebc4d7337cceccdca8d678a27f788ac133" -"checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" -"checksum diff 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "3c2b69f912779fbb121ceb775d74d51e915af17aaebc38d28a592843a2dd0a3a" -"checksum env_logger 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "39ecdb7dd54465526f0a56d666e3b2dd5f3a218665a030b6e4ad9e70fa95d8fa" -"checksum glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" -"checksum humantime 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" -"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -"checksum lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" -"checksum libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)" = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558" -"checksum libloading 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2cadb8e769f070c45df05c78c7520eb4cd17061d4ab262e43cfc68b4d00ac71c" -"checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" -"checksum memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "88579771288728879b57485cc7d6b07d648c9f0141eb955f8ab7f9d45394468e" -"checksum nom 5.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b471253da97532da4b61552249c521e01e736071f71c1a4f7ebbfbf0a06aad6" -"checksum peeking_take_while 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" -"checksum proc-macro2 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "afdc77cc74ec70ed262262942ebb7dac3d479e9e5cfa2da1841c0806f6cdabcc" -"checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0" -"checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" -"checksum regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dc220bd33bdce8f093101afe22a037b8eb0e5af33592e6a9caafff0d4cb81cbd" -"checksum regex-syntax 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "11a7e20d1cce64ef2fed88b66d347f88bd9babb82845b2b858f3edbf59a4f716" -"checksum rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7540fc8b0c49f096ee9c961cda096467dce8084bec6bdca2fc83895fd9b28cb8" -"checksum shlex 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2" -"checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" -"checksum termcolor 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "96d6098003bde162e4277c70665bd87c326f5a0c3f3fbfb285787fa482d54e6e" -"checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" -"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" -"checksum unicode-width 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7007dbd421b92cc6e28410fe7362e2e0a2503394908f417b68ec8d1c364c4e20" -"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" -"checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" -"checksum version_check 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "078775d0255232fb988e6fccf26ddc9d1ac274299aaedcedce21c6f72cc533ce" -"checksum which 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "240a31163872f7e8e49f35b42b58485e35355b07eb009d9f3686733541339a69" -"checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" -"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" -"checksum winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7168bab6e1daee33b4557efd0e95d5ca70a03706d39fa5f3fe7a236f584b03c9" -"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -"checksum wincolor 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "96f5016b18804d24db43cebf3c77269e7569b8954a8464501c216cc5e070eaa9" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml index 7ab43a21dc..3b24d3db3e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,7 +47,7 @@ shlex = "0.1" [dependencies] bitflags = "1.0.3" cexpr = "0.4" -cfg-if = "0.1.0" +cfg-if = "1" # This kinda sucks: https://github.com/rust-lang/cargo/issues/1982 clap = { version = "2", optional = true } clang-sys = { version = "1", features = ["clang_6_0"] } @@ -65,7 +65,7 @@ proc-macro2 = { version = "1", default-features = false } [dependencies.env_logger] optional = true -version = "0.7" +version = "0.8" [dependencies.log] optional = true diff --git a/tests/expectations/tests/default-template-parameter.rs b/tests/expectations/tests/default-template-parameter.rs index 666b3e6dd4..f42e23bf62 100644 --- a/tests/expectations/tests/default-template-parameter.rs +++ b/tests/expectations/tests/default-template-parameter.rs @@ -25,7 +25,7 @@ fn __bindgen_test_layout_Foo_open0_bool__int_close0_instantiation() { 8usize, concat!( "Size of template specialization: ", - stringify ! ( Foo < bool , :: std :: os :: raw :: c_int > ) + stringify ! (Foo < bool , :: std :: os :: raw :: c_int >) ) ); assert_eq!( @@ -33,7 +33,7 @@ fn __bindgen_test_layout_Foo_open0_bool__int_close0_instantiation() { 4usize, concat!( "Alignment of template specialization: ", - stringify ! ( Foo < bool , :: std :: os :: raw :: c_int > ) + stringify ! (Foo < bool , :: std :: os :: raw :: c_int >) ) ); } diff --git a/tests/expectations/tests/layout_mbuf.rs b/tests/expectations/tests/layout_mbuf.rs index 2048f33544..e5929ac5c2 100644 --- a/tests/expectations/tests/layout_mbuf.rs +++ b/tests/expectations/tests/layout_mbuf.rs @@ -476,10 +476,10 @@ pub struct rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 { #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1( ) { - assert_eq ! ( :: std :: mem :: size_of :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > ( ) , 4usize , concat ! ( "Size of: " , stringify ! ( rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 ) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > ( ) , 2usize , concat ! ( "Alignment of " , stringify ! ( rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 ) ) ); - assert_eq ! ( unsafe { & ( * ( :: std :: ptr :: null :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > ( ) ) ) . hash as * const _ as usize } , 0usize , concat ! ( "Offset of field: " , stringify ! ( rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 ) , "::" , stringify ! ( hash ) ) ); - assert_eq ! ( unsafe { & ( * ( :: std :: ptr :: null :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > ( ) ) ) . id as * const _ as usize } , 2usize , concat ! ( "Offset of field: " , stringify ! ( rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 ) , "::" , stringify ! ( id ) ) ); + assert_eq ! (:: std :: mem :: size_of :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > () , 4usize , concat ! ("Size of: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1))); + assert_eq ! (:: std :: mem :: align_of :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > () , 2usize , concat ! ("Alignment of " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1))); + assert_eq ! (unsafe { & (* (:: std :: ptr :: null :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > ())) . hash as * const _ as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (hash))); + assert_eq ! (unsafe { & (* (:: std :: ptr :: null :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > ())) . id as * const _ as usize } , 2usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (id))); } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1() { diff --git a/tests/expectations/tests/layout_mbuf_1_0.rs b/tests/expectations/tests/layout_mbuf_1_0.rs index 1475cc2141..96b38cbb30 100644 --- a/tests/expectations/tests/layout_mbuf_1_0.rs +++ b/tests/expectations/tests/layout_mbuf_1_0.rs @@ -531,10 +531,10 @@ pub struct rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 { #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1( ) { - assert_eq ! ( :: std :: mem :: size_of :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > ( ) , 4usize , concat ! ( "Size of: " , stringify ! ( rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 ) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > ( ) , 2usize , concat ! ( "Alignment of " , stringify ! ( rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 ) ) ); - assert_eq ! ( unsafe { & ( * ( :: std :: ptr :: null :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > ( ) ) ) . hash as * const _ as usize } , 0usize , concat ! ( "Offset of field: " , stringify ! ( rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 ) , "::" , stringify ! ( hash ) ) ); - assert_eq ! ( unsafe { & ( * ( :: std :: ptr :: null :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > ( ) ) ) . id as * const _ as usize } , 2usize , concat ! ( "Offset of field: " , stringify ! ( rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 ) , "::" , stringify ! ( id ) ) ); + assert_eq ! (:: std :: mem :: size_of :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > () , 4usize , concat ! ("Size of: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1))); + assert_eq ! (:: std :: mem :: align_of :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > () , 2usize , concat ! ("Alignment of " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1))); + assert_eq ! (unsafe { & (* (:: std :: ptr :: null :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > ())) . hash as * const _ as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (hash))); + assert_eq ! (unsafe { & (* (:: std :: ptr :: null :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > ())) . id as * const _ as usize } , 2usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (id))); } impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 diff --git a/tests/expectations/tests/objc_class_method.rs b/tests/expectations/tests/objc_class_method.rs index d1f39b0c7d..26f2110f43 100644 --- a/tests/expectations/tests/objc_class_method.rs +++ b/tests/expectations/tests/objc_class_method.rs @@ -64,6 +64,6 @@ pub trait IFoo: Sized + std::ops::Deref { ) where ::Target: objc::Message + Sized, { - msg_send ! ( class ! ( Foo ) , methodWithArg1 : intvalue andArg2 : ptr andArg3 : floatvalue ) + msg_send ! (class ! (Foo) , methodWithArg1 : intvalue andArg2 : ptr andArg3 : floatvalue) } } diff --git a/tests/expectations/tests/objc_method.rs b/tests/expectations/tests/objc_method.rs index 7c4fbd4309..af5c6093db 100644 --- a/tests/expectations/tests/objc_method.rs +++ b/tests/expectations/tests/objc_method.rs @@ -65,7 +65,7 @@ pub trait IFoo: Sized + std::ops::Deref { ) where ::Target: objc::Message + Sized, { - msg_send ! ( * self , methodWithArg1 : intvalue andArg2 : ptr andArg3 : floatvalue ) + msg_send ! (* self , methodWithArg1 : intvalue andArg2 : ptr andArg3 : floatvalue) } unsafe fn methodWithAndWithoutKeywords_arg2Name__arg4Name_( &self, @@ -77,7 +77,7 @@ pub trait IFoo: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - msg_send ! ( * self , methodWithAndWithoutKeywords : arg1 arg2Name : arg2 arg3 : arg3 arg4Name : arg4 ) + msg_send ! (* self , methodWithAndWithoutKeywords : arg1 arg2Name : arg2 arg3 : arg3 arg4Name : arg4) } } pub type instancetype = id; diff --git a/tests/expectations/tests/sentry-defined-multiple-times.rs b/tests/expectations/tests/sentry-defined-multiple-times.rs index 989b4d164a..5f2ec54d5a 100644 --- a/tests/expectations/tests/sentry-defined-multiple-times.rs +++ b/tests/expectations/tests/sentry-defined-multiple-times.rs @@ -273,9 +273,9 @@ pub mod root { #[test] fn bindgen_test_layout_OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry( ) { - assert_eq ! ( :: std :: mem :: size_of :: < OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry > ( ) , 4usize , concat ! ( "Size of: " , stringify ! ( OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry ) ) ); - assert_eq ! ( :: std :: mem :: align_of :: < OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry > ( ) , 4usize , concat ! ( "Alignment of " , stringify ! ( OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry ) ) ); - assert_eq ! ( unsafe { & ( * ( :: std :: ptr :: null :: < OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry > ( ) ) ) . i_am_double_wrapper_inline_sentry as * const _ as usize } , 0usize , concat ! ( "Offset of field: " , stringify ! ( OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry ) , "::" , stringify ! ( i_am_double_wrapper_inline_sentry ) ) ); + assert_eq ! (:: std :: mem :: size_of :: < OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry > () , 4usize , concat ! ("Size of: " , stringify ! (OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry))); + assert_eq ! (:: std :: mem :: align_of :: < OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry > () , 4usize , concat ! ("Alignment of " , stringify ! (OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry))); + assert_eq ! (unsafe { & (* (:: std :: ptr :: null :: < OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry > ())) . i_am_double_wrapper_inline_sentry as * const _ as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry) , "::" , stringify ! (i_am_double_wrapper_inline_sentry))); } #[test] fn bindgen_test_layout_OuterDoubleInlineWrapper_InnerDoubleInlineWrapper( From 727dc6308b71562f3bf67024b30c2ec4d06e4c9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Fri, 13 Nov 2020 20:20:06 +0100 Subject: [PATCH 106/942] Document various changes that will get into the next release. --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 18266bd739..ea86698669 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -118,7 +118,7 @@ -------------------------------------------------------------------------------- -# Unreleased +# 0.56.0 Released YYYY/MM/DD @@ -129,6 +129,8 @@ Released YYYY/MM/DD ## Changed * Objective-c bindings borrow self rather than take ownership ([#1883][]). +* Templates and enums now correctly use the same naming scheme as other types + (#1891). ## Deprecated @@ -140,6 +142,7 @@ Released YYYY/MM/DD ## Fixed +* Constructors in wasm32 now return a value. (#1877). * Fixed objective-c protocol impl blocks for parent classes's protocols ([#1883][]). ## Security From ba4312f7457ec196a8291b4fdc70f2d174ccfe17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Fri, 13 Nov 2020 20:22:27 +0100 Subject: [PATCH 107/942] Document that people can request releases (and I'd be more than happy to make them happen :)) --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index bd687858bf..e1ad557e97 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,11 @@ Additionally, `bindgen` uses `libclang` to parse C and C++ header files. To modify how `bindgen` searches for `libclang`, see the [`clang-sys` documentation][clang-sys-env]. For more details on how `bindgen` uses `libclang`, see the [`bindgen` users guide][bindgen-book-clang]. +## Releases + +We don't follow a specific release calendar, but if you need a release please +file an issue requesting that (ping `@emilio` for increased effectiveness). + ## Contributing [See `CONTRIBUTING.md` for hacking on `bindgen`!](./CONTRIBUTING.md) From 90b801fb4fae01f37bd040c7bc5459b06c1b7b67 Mon Sep 17 00:00:00 2001 From: Samson Ootoovak Date: Wed, 18 Nov 2020 13:43:26 +1300 Subject: [PATCH 108/942] Update clang-sys dependency Version 1.0.2 of clang-sys fixes an issue that was causing upstream builds on macOS 11.0 to fail when it couldn't find LLVM configs properly. https://github.com/KyleMayes/clang-sys/blob/master/CHANGELOG.md#102---2020-11-17 https://github.com/KyleMayes/clang-sys/pull/118 --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0d1c23f20c..ed6e1c8846 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -81,9 +81,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clang-sys" -version = "1.0.1" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa785e9017cb8e8c8045e3f096b7d1ebc4d7337cceccdca8d678a27f788ac133" +checksum = "0659001ab56b791be01d4b729c44376edc6718cf389a502e579b77b758f3296c" dependencies = [ "glob", "libc", From 2c72903884a3b9ffc824f76fab250d36de7be74e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 25 Nov 2020 14:27:32 +0100 Subject: [PATCH 109/942] Rustfmt to green up CI. --- src/ir/item.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/ir/item.rs b/src/ir/item.rs index 0f94f02091..f9da64fd9d 100644 --- a/src/ir/item.rs +++ b/src/ir/item.rs @@ -1332,9 +1332,7 @@ impl ClangItemParser for Item { Ok(ParseResult::AlreadyResolved(id)) => { return Ok(id); } - Err(ParseError::Recurse) => { - return Err(ParseError::Recurse) - } + Err(ParseError::Recurse) => return Err(ParseError::Recurse), Err(ParseError::Continue) => {} } }; From db3d170d3bb5339336e0cfc96a1653ad25793507 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Volker=20Wei=C3=9Fmann?= Date: Tue, 17 Nov 2020 20:47:44 +0100 Subject: [PATCH 110/942] tests: Added option to hand check test differences. --- CONTRIBUTING.md | 6 ++++++ tests/tests.rs | 33 ++++++++++++++++++++++++++------- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ae72afb603..716217e041 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -125,6 +125,12 @@ the expected bindings with `bindgen`'s current output: $ BINDGEN_OVERWRITE_EXPECTED=1 cargo test ``` +If you set the BINDGEN_TESTS_DIFFTOOL environment variable, `cargo test` will +execute $BINDGEN_TESTS_DIFFTOOL /path/of/expected/output /path/of/actual/output +when the expected output differs from the actual output. You can use this to +hand check differences by setting it to e.g. "meld" (assuming you have meld +installed). + If you're not changing command line arguments, you may want to set `BINDGEN_DISABLE_ROUNDTRIP_TEST` to avoid a lot of tests for round-tripping of those. diff --git a/tests/tests.rs b/tests/tests.rs index f8419b53f2..8b5a91f71c 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -174,7 +174,7 @@ fn compare_generated_header( expectation.push(file_name); expectation.set_extension("rs"); expectation_file = fs::File::open(&expectation).ok(); - looked_at.push(expectation); + looked_at.push(expectation.clone()); } let mut expected = String::new(); @@ -233,14 +233,33 @@ fn compare_generated_header( } } - // Overwrite the expectation with actual output. - if env::var_os("BINDGEN_OVERWRITE_EXPECTED").is_some() { - let mut expectation_file = - fs::File::create(looked_at.last().unwrap())?; - expectation_file.write_all(actual.as_bytes())?; + if let Some(var) = env::var_os("BINDGEN_OVERWRITE_EXPECTED") { + if var == "1" { + // Overwrite the expectation with actual output. + let mut expectation_file = + fs::File::create(looked_at.last().unwrap())?; + expectation_file.write_all(actual.as_bytes())?; + } else if var != "0" && var != "" { + panic!("Invalid value of BINDGEN_OVERWRITE_EXPECTED"); + } + } + + if let Some(var) = env::var_os("BINDGEN_TESTS_DIFFTOOL") { + //usecase: var = "meld" -> You can hand check differences + let filename = match header.components().last() { + Some(std::path::Component::Normal(name)) => name, + _ => panic!("Why is the header variable so weird?"), + }; + let actual_result_path = + PathBuf::from(env::var("OUT_DIR").unwrap()).join(filename); + let mut actual_result_file = fs::File::create(&actual_result_path)?; + actual_result_file.write_all(actual.as_bytes())?; + std::process::Command::new(var) + .args(&[looked_at.last().unwrap(), &actual_result_path]) + .output()?; } - return Err(Error::new(ErrorKind::Other, "Header and binding differ! Run with BINDGEN_OVERWRITE_EXPECTED=1 in the environment to automatically overwrite the expectation.")); + return Err(Error::new(ErrorKind::Other, "Header and binding differ! Run with BINDGEN_OVERWRITE_EXPECTED=1 in the environment to automatically overwrite the expectation or with BINDGEN_TESTS_DIFFTOOL=meld to do this manually.")); } if check_roundtrip { From fc5fa9a8f2847b3d53ab88b80dd86165ea4da29b Mon Sep 17 00:00:00 2001 From: Joe Ellis Date: Mon, 27 Jul 2020 10:26:38 +0100 Subject: [PATCH 111/942] Add dynamic loading support Closes #1541. Closes #1846. Co-authored-by: Michael-F-Bryan --- src/codegen/dyngen.rs | 181 ++++++++++++++++++++++++++++++++++++++++++ src/codegen/mod.rs | 80 ++++++++++++++++++- src/lib.rs | 20 +++++ src/options.rs | 10 ++- 4 files changed, 288 insertions(+), 3 deletions(-) create mode 100644 src/codegen/dyngen.rs diff --git a/src/codegen/dyngen.rs b/src/codegen/dyngen.rs new file mode 100644 index 0000000000..aab6cac9ea --- /dev/null +++ b/src/codegen/dyngen.rs @@ -0,0 +1,181 @@ +use crate::ir::function::Abi; +use proc_macro2::Ident; + +/// Used to build the output tokens for dynamic bindings. +pub struct DynamicItems { + /// Tracks the tokens that will appears inside the library struct -- e.g.: + /// ```ignore + /// struct Lib { + /// __library: ::libloading::Library, + /// x: Result, // <- tracks these + /// ... + /// } + /// ``` + struct_members: Vec, + + /// Tracks the tokens that will appear inside the library struct's implementation, e.g.: + /// + /// ```ignore + /// impl Lib { + /// ... + /// pub unsafe fn foo(&self, ...) { // <- tracks these + /// ... + /// } + /// } + /// ``` + struct_implementation: Vec, + + /// Tracks the tokens that will appear inside the struct used for checking if a symbol is + /// usable, e.g.: + /// ```ignore + /// pub fn f(&self) -> Result<(), &'a ::libloading::Error> { // <- tracks these + /// self.__library.f.as_ref().map(|_| ()) + /// } + /// ``` + runtime_checks: Vec, + + /// Tracks the initialization of the fields inside the `::new` constructor of the library + /// struct, e.g.: + /// ```ignore + /// impl Lib { + /// + /// pub unsafe fn new

(path: P) -> Result + /// where + /// P: AsRef<::std::ffi::OsStr>, + /// { + /// ... + /// let foo = __library.get(...) ...; // <- tracks these + /// ... + /// } + /// + /// ... + /// } + /// ``` + constructor_inits: Vec, + + /// Tracks the information that is passed to the library struct at the end of the `::new` + /// constructor, e.g.: + /// ```ignore + /// impl LibFoo { + /// pub unsafe fn new

(path: P) -> Result + /// where + /// P: AsRef<::std::ffi::OsStr>, + /// { + /// ... + /// Ok(LibFoo { + /// __library: __library, + /// foo, + /// bar, // <- tracks these + /// ... + /// }) + /// } + /// } + /// ``` + init_fields: Vec, +} + +impl Default for DynamicItems { + fn default() -> Self { + DynamicItems { + struct_members: vec![], + struct_implementation: vec![], + runtime_checks: vec![], + constructor_inits: vec![], + init_fields: vec![], + } + } +} + +impl DynamicItems { + pub fn new() -> Self { + Self::default() + } + + pub fn get_tokens( + &self, + lib_ident: Ident, + check_struct_ident: Ident, + ) -> proc_macro2::TokenStream { + let struct_members = &self.struct_members; + let constructor_inits = &self.constructor_inits; + let init_fields = &self.init_fields; + let struct_implementation = &self.struct_implementation; + let runtime_checks = &self.runtime_checks; + quote! { + extern crate libloading; + + pub struct #lib_ident { + __library: ::libloading::Library, + #(#struct_members)* + } + + impl #lib_ident { + pub unsafe fn new

( + path: P + ) -> Result + where P: AsRef<::std::ffi::OsStr> { + let __library = ::libloading::Library::new(path)?; + #( #constructor_inits )* + Ok( + #lib_ident { + __library: __library, + #( #init_fields ),* + } + ) + } + + pub fn can_call(&self) -> #check_struct_ident { + #check_struct_ident { __library: self } + } + + #( #struct_implementation )* + } + + pub struct #check_struct_ident<'a> { + __library: &'a #lib_ident, + } + + impl<'a> #check_struct_ident<'a> { + #( #runtime_checks )* + } + } + } + + pub fn add_function( + &mut self, + ident: Ident, + abi: Abi, + args: Vec, + args_identifiers: Vec, + ret: proc_macro2::TokenStream, + ret_ty: proc_macro2::TokenStream, + ) { + assert_eq!(args.len(), args_identifiers.len()); + + self.struct_members.push(quote!{ + #ident: Result, + }); + + self.struct_implementation.push(quote! { + pub unsafe fn #ident ( &self, #( #args ),* ) -> #ret_ty { + let sym = self.#ident.as_ref().expect("Expected function, got error."); + (sym)(#( #args_identifiers ),*) + } + }); + + self.runtime_checks.push(quote! { + pub fn #ident (&self) -> Result<(), &'a::libloading::Error> { + self.__library.#ident.as_ref().map(|_| ()) + } + }); + + let ident_str = ident.to_string(); + self.constructor_inits.push(quote! { + let #ident = __library.get(#ident_str.as_bytes()).map(|sym| *sym); + }); + + self.init_fields.push(quote! { + #ident + }); + } +} diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 91acf5b03a..a62979b0bf 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -1,3 +1,4 @@ +mod dyngen; mod error; mod helpers; mod impl_debug; @@ -10,6 +11,7 @@ pub(crate) mod bitfield_unit; #[cfg(all(test, target_endian = "little"))] mod bitfield_unit_tests; +use self::dyngen::DynamicItems; use self::helpers::attributes; use self::struct_layout::StructLayoutTracker; @@ -184,6 +186,7 @@ impl From for Vec<&'static str> { struct CodegenResult<'a> { items: Vec, + dynamic_items: DynamicItems, /// A monotonic counter used to add stable unique id's to stuff that doesn't /// need to be referenced by anything. @@ -234,6 +237,7 @@ impl<'a> CodegenResult<'a> { fn new(codegen_id: &'a Cell) -> Self { CodegenResult { items: vec![], + dynamic_items: DynamicItems::new(), saw_bindgen_union: false, saw_incomplete_array: false, saw_objc: false, @@ -247,6 +251,10 @@ impl<'a> CodegenResult<'a> { } } + fn dynamic_items(&mut self) -> &mut DynamicItems { + &mut self.dynamic_items + } + fn saw_bindgen_union(&mut self) { self.saw_bindgen_union = true; } @@ -3785,7 +3793,29 @@ impl CodeGenerator for Function { pub fn #ident ( #( #args ),* ) #ret; } }; - result.push(tokens); + + // If we're doing dynamic binding generation, add to the dynamic items. + if ctx.options().dynamic_library_name.is_some() && + self.kind() == FunctionKind::Function + { + let args_identifiers = + utils::fnsig_argument_identifiers(ctx, signature); + let return_item = ctx.resolve_item(signature.return_type()); + let ret_ty = match *return_item.kind().expect_type().kind() { + TypeKind::Void => quote! {()}, + _ => return_item.to_rust_ty_or_opaque(ctx, &()), + }; + result.dynamic_items().add_function( + ident, + abi, + args, + args_identifiers, + ret, + ret_ty, + ); + } else { + result.push(tokens); + } } } @@ -4075,11 +4105,28 @@ pub(crate) fn codegen( &(), ); + if context.options().dynamic_library_name.is_some() { + let lib_ident = context.rust_ident( + context.options().dynamic_library_name.as_ref().unwrap(), + ); + let check_struct_ident = context.rust_ident( + [ + "Check", + context.options().dynamic_library_name.as_ref().unwrap(), + ] + .join(""), + ); + let dynamic_items_tokens = result + .dynamic_items() + .get_tokens(lib_ident, check_struct_ident); + result.push(dynamic_items_tokens); + } + result.items }) } -mod utils { +pub mod utils { use super::{error, ToRustTyOrOpaque}; use crate::ir::context::BindgenContext; use crate::ir::function::{Abi, FunctionSig}; @@ -4484,6 +4531,35 @@ mod utils { args } + pub fn fnsig_argument_identifiers( + ctx: &BindgenContext, + sig: &FunctionSig, + ) -> Vec { + let mut unnamed_arguments = 0; + let args = sig + .argument_types() + .iter() + .map(|&(ref name, _ty)| { + let arg_name = match *name { + Some(ref name) => ctx.rust_mangle(name).into_owned(), + None => { + unnamed_arguments += 1; + format!("arg{}", unnamed_arguments) + } + }; + + assert!(!arg_name.is_empty()); + let arg_name = ctx.rust_ident(arg_name); + + quote! { + #arg_name + } + }) + .collect::>(); + + args + } + pub fn fnsig_block( ctx: &BindgenContext, sig: &FunctionSig, diff --git a/src/lib.rs b/src/lib.rs index 08b9381785..7aa87831f2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -518,6 +518,12 @@ impl Builder { output_vector.push(path.into()); } + if self.options.dynamic_library_name.is_some() { + let libname = self.options.dynamic_library_name.as_ref().unwrap(); + output_vector.push("--dynamic-loading".into()); + output_vector.push(libname.clone()); + } + // Add clang arguments output_vector.push("--".into()); @@ -1468,6 +1474,15 @@ impl Builder { self.options.wasm_import_module_name = Some(import_name.into()); self } + + /// Specify the dynamic library name if we are generating bindings for a shared library. + pub fn dynamic_library_name>( + mut self, + dynamic_library_name: T, + ) -> Self { + self.options.dynamic_library_name = Some(dynamic_library_name.into()); + self + } } /// Configuration options for generated bindings. @@ -1745,6 +1760,10 @@ struct BindgenOptions { /// Wasm import module name. wasm_import_module_name: Option, + + /// The name of the dynamic library (if we are generating bindings for a shared library). If + /// this is None, no dynamic bindings are created. + dynamic_library_name: Option, } /// TODO(emilio): This is sort of a lie (see the error message that results from @@ -1877,6 +1896,7 @@ impl Default for BindgenOptions { no_hash_types: Default::default(), array_pointers_in_arguments: false, wasm_import_module_name: None, + dynamic_library_name: None, } } } diff --git a/src/options.rs b/src/options.rs index a850dbbbfe..8c85abae49 100644 --- a/src/options.rs +++ b/src/options.rs @@ -471,7 +471,11 @@ where .long("wasm-import-module-name") .value_name("name") .takes_value(true) - .help("The name to be used in a #[link(wasm_import_module = ...)] statement") + .help("The name to be used in a #[link(wasm_import_module = ...)] statement"), + Arg::with_name("dynamic-loading") + .long("dynamic-loading") + .takes_value(true) + .help("Use dynamic loading mode with the given library name."), ]) // .args() .get_matches_from(args); @@ -873,6 +877,10 @@ where } } + if let Some(dynamic_library_name) = matches.value_of("dynamic-loading") { + builder = builder.dynamic_library_name(dynamic_library_name); + } + let verbose = matches.is_present("verbose"); Ok((builder, output, verbose)) From c2b5c46ef4ab2de1281c1d8099daa49621e29794 Mon Sep 17 00:00:00 2001 From: Joe Ellis Date: Tue, 27 Oct 2020 18:17:45 +0000 Subject: [PATCH 112/942] Add tests for dynamic binding generation --- tests/expectations/Cargo.toml | 3 +- .../tests/dynamic_loading_simple.rs | 81 ++++++++++++ .../tests/dynamic_loading_template.rs | 56 +++++++++ .../tests/dynamic_loading_with_blacklist.rs | 117 ++++++++++++++++++ .../tests/dynamic_loading_with_class.rs | 109 ++++++++++++++++ .../tests/dynamic_loading_with_whitelist.rs | 66 ++++++++++ tests/headers/dynamic_loading_simple.h | 5 + tests/headers/dynamic_loading_template.hpp | 10 ++ .../dynamic_loading_with_blacklist.hpp | 15 +++ tests/headers/dynamic_loading_with_class.hpp | 15 +++ .../dynamic_loading_with_whitelist.hpp | 15 +++ 11 files changed, 491 insertions(+), 1 deletion(-) create mode 100644 tests/expectations/tests/dynamic_loading_simple.rs create mode 100644 tests/expectations/tests/dynamic_loading_template.rs create mode 100644 tests/expectations/tests/dynamic_loading_with_blacklist.rs create mode 100644 tests/expectations/tests/dynamic_loading_with_class.rs create mode 100644 tests/expectations/tests/dynamic_loading_with_whitelist.rs create mode 100644 tests/headers/dynamic_loading_simple.h create mode 100644 tests/headers/dynamic_loading_template.hpp create mode 100644 tests/headers/dynamic_loading_with_blacklist.hpp create mode 100644 tests/headers/dynamic_loading_with_class.hpp create mode 100644 tests/headers/dynamic_loading_with_whitelist.hpp diff --git a/tests/expectations/Cargo.toml b/tests/expectations/Cargo.toml index 6acb1d406d..c78cc09a0b 100644 --- a/tests/expectations/Cargo.toml +++ b/tests/expectations/Cargo.toml @@ -10,4 +10,5 @@ authors = [ [dependencies] objc = "0.2" -block = "0.1" \ No newline at end of file +block = "0.1" +libloading = "0.6.2" diff --git a/tests/expectations/tests/dynamic_loading_simple.rs b/tests/expectations/tests/dynamic_loading_simple.rs new file mode 100644 index 0000000000..b195a05d84 --- /dev/null +++ b/tests/expectations/tests/dynamic_loading_simple.rs @@ -0,0 +1,81 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +extern crate libloading; +pub struct TestLib { + __library: ::libloading::Library, + foo: Result< + unsafe extern "C" fn( + x: ::std::os::raw::c_int, + y: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + ::libloading::Error, + >, + bar: Result< + unsafe extern "C" fn( + x: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int, + ::libloading::Error, + >, + baz: Result< + unsafe extern "C" fn() -> ::std::os::raw::c_int, + ::libloading::Error, + >, +} +impl TestLib { + pub unsafe fn new

(path: P) -> Result + where + P: AsRef<::std::ffi::OsStr>, + { + let __library = ::libloading::Library::new(path)?; + let foo = __library.get("foo".as_bytes()).map(|sym| *sym); + let bar = __library.get("bar".as_bytes()).map(|sym| *sym); + let baz = __library.get("baz".as_bytes()).map(|sym| *sym); + Ok(TestLib { + __library: __library, + foo, + bar, + baz, + }) + } + pub fn can_call(&self) -> CheckTestLib { + CheckTestLib { __library: self } + } + pub unsafe fn foo( + &self, + x: ::std::os::raw::c_int, + y: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int { + let sym = self.foo.as_ref().expect("Expected function, got error."); + (sym)(x, y) + } + pub unsafe fn bar( + &self, + x: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int { + let sym = self.bar.as_ref().expect("Expected function, got error."); + (sym)(x) + } + pub unsafe fn baz(&self) -> ::std::os::raw::c_int { + let sym = self.baz.as_ref().expect("Expected function, got error."); + (sym)() + } +} +pub struct CheckTestLib<'a> { + __library: &'a TestLib, +} +impl<'a> CheckTestLib<'a> { + pub fn foo(&self) -> Result<(), &'a ::libloading::Error> { + self.__library.foo.as_ref().map(|_| ()) + } + pub fn bar(&self) -> Result<(), &'a ::libloading::Error> { + self.__library.bar.as_ref().map(|_| ()) + } + pub fn baz(&self) -> Result<(), &'a ::libloading::Error> { + self.__library.baz.as_ref().map(|_| ()) + } +} diff --git a/tests/expectations/tests/dynamic_loading_template.rs b/tests/expectations/tests/dynamic_loading_template.rs new file mode 100644 index 0000000000..b9fa1698db --- /dev/null +++ b/tests/expectations/tests/dynamic_loading_template.rs @@ -0,0 +1,56 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +extern crate libloading; +pub struct TestLib { + __library: ::libloading::Library, + foo: Result< + unsafe extern "C" fn(x: ::std::os::raw::c_int) -> ::std::os::raw::c_int, + ::libloading::Error, + >, + foo1: Result f32, ::libloading::Error>, +} +impl TestLib { + pub unsafe fn new

(path: P) -> Result + where + P: AsRef<::std::ffi::OsStr>, + { + let __library = ::libloading::Library::new(path)?; + let foo = __library.get("foo".as_bytes()).map(|sym| *sym); + let foo1 = __library.get("foo1".as_bytes()).map(|sym| *sym); + Ok(TestLib { + __library: __library, + foo, + foo1, + }) + } + pub fn can_call(&self) -> CheckTestLib { + CheckTestLib { __library: self } + } + pub unsafe fn foo( + &self, + x: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int { + let sym = self.foo.as_ref().expect("Expected function, got error."); + (sym)(x) + } + pub unsafe fn foo1(&self, x: f32) -> f32 { + let sym = self.foo1.as_ref().expect("Expected function, got error."); + (sym)(x) + } +} +pub struct CheckTestLib<'a> { + __library: &'a TestLib, +} +impl<'a> CheckTestLib<'a> { + pub fn foo(&self) -> Result<(), &'a ::libloading::Error> { + self.__library.foo.as_ref().map(|_| ()) + } + pub fn foo1(&self) -> Result<(), &'a ::libloading::Error> { + self.__library.foo1.as_ref().map(|_| ()) + } +} diff --git a/tests/expectations/tests/dynamic_loading_with_blacklist.rs b/tests/expectations/tests/dynamic_loading_with_blacklist.rs new file mode 100644 index 0000000000..259054b266 --- /dev/null +++ b/tests/expectations/tests/dynamic_loading_with_blacklist.rs @@ -0,0 +1,117 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct X { + pub _x: ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout_X() { + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(X)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(X)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::()))._x as *const _ as usize }, + 0usize, + concat!("Offset of field: ", stringify!(X), "::", stringify!(_x)) + ); +} +extern "C" { + #[link_name = "\u{1}_ZN1X13some_functionEv"] + pub fn X_some_function(this: *mut X); +} +extern "C" { + #[link_name = "\u{1}_ZN1X19some_other_functionEv"] + pub fn X_some_other_function(this: *mut X); +} +extern "C" { + #[link_name = "\u{1}_ZN1XC1Ei"] + pub fn X_X(this: *mut X, x: ::std::os::raw::c_int); +} +impl X { + #[inline] + pub unsafe fn some_function(&mut self) { + X_some_function(self) + } + #[inline] + pub unsafe fn some_other_function(&mut self) { + X_some_other_function(self) + } + #[inline] + pub unsafe fn new(x: ::std::os::raw::c_int) -> Self { + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + X_X(__bindgen_tmp.as_mut_ptr(), x); + __bindgen_tmp.assume_init() + } +} +extern crate libloading; +pub struct TestLib { + __library: ::libloading::Library, + foo: Result< + unsafe extern "C" fn( + x: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int, + ::libloading::Error, + >, + bar: Result< + unsafe extern "C" fn( + x: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int, + ::libloading::Error, + >, +} +impl TestLib { + pub unsafe fn new

(path: P) -> Result + where + P: AsRef<::std::ffi::OsStr>, + { + let __library = ::libloading::Library::new(path)?; + let foo = __library.get("foo".as_bytes()).map(|sym| *sym); + let bar = __library.get("bar".as_bytes()).map(|sym| *sym); + Ok(TestLib { + __library: __library, + foo, + bar, + }) + } + pub fn can_call(&self) -> CheckTestLib { + CheckTestLib { __library: self } + } + pub unsafe fn foo( + &self, + x: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int { + let sym = self.foo.as_ref().expect("Expected function, got error."); + (sym)(x) + } + pub unsafe fn bar( + &self, + x: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int { + let sym = self.bar.as_ref().expect("Expected function, got error."); + (sym)(x) + } +} +pub struct CheckTestLib<'a> { + __library: &'a TestLib, +} +impl<'a> CheckTestLib<'a> { + pub fn foo(&self) -> Result<(), &'a ::libloading::Error> { + self.__library.foo.as_ref().map(|_| ()) + } + pub fn bar(&self) -> Result<(), &'a ::libloading::Error> { + self.__library.bar.as_ref().map(|_| ()) + } +} diff --git a/tests/expectations/tests/dynamic_loading_with_class.rs b/tests/expectations/tests/dynamic_loading_with_class.rs new file mode 100644 index 0000000000..636f01bb2a --- /dev/null +++ b/tests/expectations/tests/dynamic_loading_with_class.rs @@ -0,0 +1,109 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct A { + pub _x: ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout_A() { + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(A)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(A)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::()))._x as *const _ as usize }, + 0usize, + concat!("Offset of field: ", stringify!(A), "::", stringify!(_x)) + ); +} +extern "C" { + #[link_name = "\u{1}_ZN1A13some_functionEv"] + pub fn A_some_function(this: *mut A); +} +extern "C" { + #[link_name = "\u{1}_ZN1A19some_other_functionEv"] + pub fn A_some_other_function(this: *mut A); +} +extern "C" { + #[link_name = "\u{1}_ZN1AC1Ei"] + pub fn A_A(this: *mut A, x: ::std::os::raw::c_int); +} +impl A { + #[inline] + pub unsafe fn some_function(&mut self) { + A_some_function(self) + } + #[inline] + pub unsafe fn some_other_function(&mut self) { + A_some_other_function(self) + } + #[inline] + pub unsafe fn new(x: ::std::os::raw::c_int) -> Self { + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + A_A(__bindgen_tmp.as_mut_ptr(), x); + __bindgen_tmp.assume_init() + } +} +extern crate libloading; +pub struct TestLib { + __library: ::libloading::Library, + foo: Result< + unsafe extern "C" fn( + x: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int, + ::libloading::Error, + >, + bar: Result, +} +impl TestLib { + pub unsafe fn new

(path: P) -> Result + where + P: AsRef<::std::ffi::OsStr>, + { + let __library = ::libloading::Library::new(path)?; + let foo = __library.get("foo".as_bytes()).map(|sym| *sym); + let bar = __library.get("bar".as_bytes()).map(|sym| *sym); + Ok(TestLib { + __library: __library, + foo, + bar, + }) + } + pub fn can_call(&self) -> CheckTestLib { + CheckTestLib { __library: self } + } + pub unsafe fn foo( + &self, + x: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int { + let sym = self.foo.as_ref().expect("Expected function, got error."); + (sym)(x) + } + pub unsafe fn bar(&self) -> () { + let sym = self.bar.as_ref().expect("Expected function, got error."); + (sym)() + } +} +pub struct CheckTestLib<'a> { + __library: &'a TestLib, +} +impl<'a> CheckTestLib<'a> { + pub fn foo(&self) -> Result<(), &'a ::libloading::Error> { + self.__library.foo.as_ref().map(|_| ()) + } + pub fn bar(&self) -> Result<(), &'a ::libloading::Error> { + self.__library.bar.as_ref().map(|_| ()) + } +} diff --git a/tests/expectations/tests/dynamic_loading_with_whitelist.rs b/tests/expectations/tests/dynamic_loading_with_whitelist.rs new file mode 100644 index 0000000000..a1f8a2a497 --- /dev/null +++ b/tests/expectations/tests/dynamic_loading_with_whitelist.rs @@ -0,0 +1,66 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +extern crate libloading; +pub struct TestLib { + __library: ::libloading::Library, + foo: Result< + unsafe extern "C" fn( + x: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int, + ::libloading::Error, + >, + baz: Result< + unsafe extern "C" fn( + x: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int, + ::libloading::Error, + >, +} +impl TestLib { + pub unsafe fn new

(path: P) -> Result + where + P: AsRef<::std::ffi::OsStr>, + { + let __library = ::libloading::Library::new(path)?; + let foo = __library.get("foo".as_bytes()).map(|sym| *sym); + let baz = __library.get("baz".as_bytes()).map(|sym| *sym); + Ok(TestLib { + __library: __library, + foo, + baz, + }) + } + pub fn can_call(&self) -> CheckTestLib { + CheckTestLib { __library: self } + } + pub unsafe fn foo( + &self, + x: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int { + let sym = self.foo.as_ref().expect("Expected function, got error."); + (sym)(x) + } + pub unsafe fn baz( + &self, + x: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int { + let sym = self.baz.as_ref().expect("Expected function, got error."); + (sym)(x) + } +} +pub struct CheckTestLib<'a> { + __library: &'a TestLib, +} +impl<'a> CheckTestLib<'a> { + pub fn foo(&self) -> Result<(), &'a ::libloading::Error> { + self.__library.foo.as_ref().map(|_| ()) + } + pub fn baz(&self) -> Result<(), &'a ::libloading::Error> { + self.__library.baz.as_ref().map(|_| ()) + } +} diff --git a/tests/headers/dynamic_loading_simple.h b/tests/headers/dynamic_loading_simple.h new file mode 100644 index 0000000000..f418851beb --- /dev/null +++ b/tests/headers/dynamic_loading_simple.h @@ -0,0 +1,5 @@ +// bindgen-flags: --dynamic-loading TestLib + +int foo(int x, int y); +int bar(void *x); +int baz(); diff --git a/tests/headers/dynamic_loading_template.hpp b/tests/headers/dynamic_loading_template.hpp new file mode 100644 index 0000000000..27f04c8e29 --- /dev/null +++ b/tests/headers/dynamic_loading_template.hpp @@ -0,0 +1,10 @@ +// bindgen-flags: --dynamic-loading TestLib + +template +T foo(T x); + +template<> +int foo(int x); + +template<> +float foo(float x); diff --git a/tests/headers/dynamic_loading_with_blacklist.hpp b/tests/headers/dynamic_loading_with_blacklist.hpp new file mode 100644 index 0000000000..2988ba691e --- /dev/null +++ b/tests/headers/dynamic_loading_with_blacklist.hpp @@ -0,0 +1,15 @@ +// bindgen-flags: --dynamic-loading TestLib --blacklist-function baz + +class X { + int _x; + + public: + X(int x); + + void some_function(); + void some_other_function(); +}; + +int foo(void *x); +int bar(void *x); +int baz(void *x); diff --git a/tests/headers/dynamic_loading_with_class.hpp b/tests/headers/dynamic_loading_with_class.hpp new file mode 100644 index 0000000000..632db4d065 --- /dev/null +++ b/tests/headers/dynamic_loading_with_class.hpp @@ -0,0 +1,15 @@ +// bindgen-flags: --dynamic-loading TestLib + +int foo(void *x); + +class A { + int _x; + + public: + A(int x); + + void some_function(); + void some_other_function(); +}; + +void bar(); diff --git a/tests/headers/dynamic_loading_with_whitelist.hpp b/tests/headers/dynamic_loading_with_whitelist.hpp new file mode 100644 index 0000000000..922b546124 --- /dev/null +++ b/tests/headers/dynamic_loading_with_whitelist.hpp @@ -0,0 +1,15 @@ +// bindgen-flags: --dynamic-loading TestLib --whitelist-function baz --whitelist-function foo + +class X { + int _x; + + public: + X(int x); + + void some_function(); + void some_other_function(); +}; + +int foo(void *x); +int bar(void *x); +int baz(void *x); From 7792d633c78d4ad39979e09a6215b656f7ec31f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 25 Nov 2020 14:38:00 +0100 Subject: [PATCH 113/942] codegen: Minor nits for dynamic function generation. --- src/codegen/dyngen.rs | 15 ++------------- src/codegen/mod.rs | 17 +++++------------ 2 files changed, 7 insertions(+), 25 deletions(-) diff --git a/src/codegen/dyngen.rs b/src/codegen/dyngen.rs index aab6cac9ea..4cd01c0173 100644 --- a/src/codegen/dyngen.rs +++ b/src/codegen/dyngen.rs @@ -2,6 +2,7 @@ use crate::ir::function::Abi; use proc_macro2::Ident; /// Used to build the output tokens for dynamic bindings. +#[derive(Default)] pub struct DynamicItems { /// Tracks the tokens that will appears inside the library struct -- e.g.: /// ```ignore @@ -74,18 +75,6 @@ pub struct DynamicItems { init_fields: Vec, } -impl Default for DynamicItems { - fn default() -> Self { - DynamicItems { - struct_members: vec![], - struct_implementation: vec![], - runtime_checks: vec![], - constructor_inits: vec![], - init_fields: vec![], - } - } -} - impl DynamicItems { pub fn new() -> Self { Self::default() @@ -141,7 +130,7 @@ impl DynamicItems { } } - pub fn add_function( + pub fn push( &mut self, ident: Ident, abi: Abi, diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index a62979b0bf..64f95f4ca8 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -3805,7 +3805,7 @@ impl CodeGenerator for Function { TypeKind::Void => quote! {()}, _ => return_item.to_rust_ty_or_opaque(ctx, &()), }; - result.dynamic_items().add_function( + result.dynamic_items().push( ident, abi, args, @@ -4105,17 +4105,10 @@ pub(crate) fn codegen( &(), ); - if context.options().dynamic_library_name.is_some() { - let lib_ident = context.rust_ident( - context.options().dynamic_library_name.as_ref().unwrap(), - ); - let check_struct_ident = context.rust_ident( - [ - "Check", - context.options().dynamic_library_name.as_ref().unwrap(), - ] - .join(""), - ); + if let Some(ref lib_name) = context.options().dynamic_library_name { + let lib_ident = context.rust_ident(lib_name); + let check_struct_ident = + context.rust_ident(format!("Check{}", lib_name)); let dynamic_items_tokens = result .dynamic_items() .get_tokens(lib_ident, check_struct_ident); From 01cbe4468358d843ef86e3e9a1e8ce2bb4fef95e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 25 Nov 2020 14:55:58 +0100 Subject: [PATCH 114/942] dyngen: Handle variadic functions. Right now trying to generate a dynamic library with variadic functions panics because we don't account for the extra `...` in the arguments. Keeping the current interface for variadic functions is tricky, as we cannot "wrap" a variadic function (VaList[1] is nightly-only). However, we don't need to. We're already exposing the libloading error, so exposing the function pointer field as public is just fine and allows consumers to call the variadic function. At that point the can_call() / CheckFoo libraries become pointless (you can just do library.function.is_ok() or such), so we can simplify the code as well removing those. [1]: https://doc.rust-lang.org/std/ffi/struct.VaList.html --- src/codegen/dyngen.rs | 63 ++++++------------- src/codegen/mod.rs | 8 +-- .../tests/dynamic_loading_simple.rs | 25 ++------ .../tests/dynamic_loading_template.rs | 20 +----- .../tests/dynamic_loading_with_blacklist.rs | 20 +----- .../tests/dynamic_loading_with_class.rs | 20 +----- .../tests/dynamic_loading_with_whitelist.rs | 29 ++++----- .../dynamic_loading_with_whitelist.hpp | 3 +- 8 files changed, 49 insertions(+), 139 deletions(-) diff --git a/src/codegen/dyngen.rs b/src/codegen/dyngen.rs index 4cd01c0173..65872ea276 100644 --- a/src/codegen/dyngen.rs +++ b/src/codegen/dyngen.rs @@ -8,7 +8,7 @@ pub struct DynamicItems { /// ```ignore /// struct Lib { /// __library: ::libloading::Library, - /// x: Result, // <- tracks these + /// pub x: Result, // <- tracks these /// ... /// } /// ``` @@ -26,15 +26,6 @@ pub struct DynamicItems { /// ``` struct_implementation: Vec, - /// Tracks the tokens that will appear inside the struct used for checking if a symbol is - /// usable, e.g.: - /// ```ignore - /// pub fn f(&self) -> Result<(), &'a ::libloading::Error> { // <- tracks these - /// self.__library.f.as_ref().map(|_| ()) - /// } - /// ``` - runtime_checks: Vec, - /// Tracks the initialization of the fields inside the `::new` constructor of the library /// struct, e.g.: /// ```ignore @@ -80,16 +71,11 @@ impl DynamicItems { Self::default() } - pub fn get_tokens( - &self, - lib_ident: Ident, - check_struct_ident: Ident, - ) -> proc_macro2::TokenStream { + pub fn get_tokens(&self, lib_ident: Ident) -> proc_macro2::TokenStream { let struct_members = &self.struct_members; let constructor_inits = &self.constructor_inits; let init_fields = &self.init_fields; let struct_implementation = &self.struct_implementation; - let runtime_checks = &self.runtime_checks; quote! { extern crate libloading; @@ -107,26 +93,14 @@ impl DynamicItems { #( #constructor_inits )* Ok( #lib_ident { - __library: __library, + __library, #( #init_fields ),* } ) } - pub fn can_call(&self) -> #check_struct_ident { - #check_struct_ident { __library: self } - } - #( #struct_implementation )* } - - pub struct #check_struct_ident<'a> { - __library: &'a #lib_ident, - } - - impl<'a> #check_struct_ident<'a> { - #( #runtime_checks )* - } } } @@ -134,29 +108,30 @@ impl DynamicItems { &mut self, ident: Ident, abi: Abi, + is_variadic: bool, args: Vec, args_identifiers: Vec, ret: proc_macro2::TokenStream, ret_ty: proc_macro2::TokenStream, ) { - assert_eq!(args.len(), args_identifiers.len()); - - self.struct_members.push(quote!{ - #ident: Result, - }); + if !is_variadic { + assert_eq!(args.len(), args_identifiers.len()); + } - self.struct_implementation.push(quote! { - pub unsafe fn #ident ( &self, #( #args ),* ) -> #ret_ty { - let sym = self.#ident.as_ref().expect("Expected function, got error."); - (sym)(#( #args_identifiers ),*) - } + self.struct_members.push(quote! { + pub #ident: Result, }); - self.runtime_checks.push(quote! { - pub fn #ident (&self) -> Result<(), &'a::libloading::Error> { - self.__library.#ident.as_ref().map(|_| ()) - } - }); + // We can't implement variadic functions from C easily, so we allow to + // access the function pointer so that the user can call it just fine. + if !is_variadic { + self.struct_implementation.push(quote! { + pub unsafe fn #ident ( &self, #( #args ),* ) -> #ret_ty { + let sym = self.#ident.as_ref().expect("Expected function, got error."); + (sym)(#( #args_identifiers ),*) + } + }); + } let ident_str = ident.to_string(); self.constructor_inits.push(quote! { diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 64f95f4ca8..754c2c8b42 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -3808,6 +3808,7 @@ impl CodeGenerator for Function { result.dynamic_items().push( ident, abi, + signature.is_variadic(), args, args_identifiers, ret, @@ -4107,11 +4108,8 @@ pub(crate) fn codegen( if let Some(ref lib_name) = context.options().dynamic_library_name { let lib_ident = context.rust_ident(lib_name); - let check_struct_ident = - context.rust_ident(format!("Check{}", lib_name)); - let dynamic_items_tokens = result - .dynamic_items() - .get_tokens(lib_ident, check_struct_ident); + let dynamic_items_tokens = + result.dynamic_items().get_tokens(lib_ident); result.push(dynamic_items_tokens); } diff --git a/tests/expectations/tests/dynamic_loading_simple.rs b/tests/expectations/tests/dynamic_loading_simple.rs index b195a05d84..b40711d8be 100644 --- a/tests/expectations/tests/dynamic_loading_simple.rs +++ b/tests/expectations/tests/dynamic_loading_simple.rs @@ -8,20 +8,20 @@ extern crate libloading; pub struct TestLib { __library: ::libloading::Library, - foo: Result< + pub foo: Result< unsafe extern "C" fn( x: ::std::os::raw::c_int, y: ::std::os::raw::c_int, ) -> ::std::os::raw::c_int, ::libloading::Error, >, - bar: Result< + pub bar: Result< unsafe extern "C" fn( x: *mut ::std::os::raw::c_void, ) -> ::std::os::raw::c_int, ::libloading::Error, >, - baz: Result< + pub baz: Result< unsafe extern "C" fn() -> ::std::os::raw::c_int, ::libloading::Error, >, @@ -36,15 +36,12 @@ impl TestLib { let bar = __library.get("bar".as_bytes()).map(|sym| *sym); let baz = __library.get("baz".as_bytes()).map(|sym| *sym); Ok(TestLib { - __library: __library, + __library, foo, bar, baz, }) } - pub fn can_call(&self) -> CheckTestLib { - CheckTestLib { __library: self } - } pub unsafe fn foo( &self, x: ::std::os::raw::c_int, @@ -65,17 +62,3 @@ impl TestLib { (sym)() } } -pub struct CheckTestLib<'a> { - __library: &'a TestLib, -} -impl<'a> CheckTestLib<'a> { - pub fn foo(&self) -> Result<(), &'a ::libloading::Error> { - self.__library.foo.as_ref().map(|_| ()) - } - pub fn bar(&self) -> Result<(), &'a ::libloading::Error> { - self.__library.bar.as_ref().map(|_| ()) - } - pub fn baz(&self) -> Result<(), &'a ::libloading::Error> { - self.__library.baz.as_ref().map(|_| ()) - } -} diff --git a/tests/expectations/tests/dynamic_loading_template.rs b/tests/expectations/tests/dynamic_loading_template.rs index b9fa1698db..e24599de15 100644 --- a/tests/expectations/tests/dynamic_loading_template.rs +++ b/tests/expectations/tests/dynamic_loading_template.rs @@ -8,11 +8,11 @@ extern crate libloading; pub struct TestLib { __library: ::libloading::Library, - foo: Result< + pub foo: Result< unsafe extern "C" fn(x: ::std::os::raw::c_int) -> ::std::os::raw::c_int, ::libloading::Error, >, - foo1: Result f32, ::libloading::Error>, + pub foo1: Result f32, ::libloading::Error>, } impl TestLib { pub unsafe fn new

(path: P) -> Result @@ -23,14 +23,11 @@ impl TestLib { let foo = __library.get("foo".as_bytes()).map(|sym| *sym); let foo1 = __library.get("foo1".as_bytes()).map(|sym| *sym); Ok(TestLib { - __library: __library, + __library, foo, foo1, }) } - pub fn can_call(&self) -> CheckTestLib { - CheckTestLib { __library: self } - } pub unsafe fn foo( &self, x: ::std::os::raw::c_int, @@ -43,14 +40,3 @@ impl TestLib { (sym)(x) } } -pub struct CheckTestLib<'a> { - __library: &'a TestLib, -} -impl<'a> CheckTestLib<'a> { - pub fn foo(&self) -> Result<(), &'a ::libloading::Error> { - self.__library.foo.as_ref().map(|_| ()) - } - pub fn foo1(&self) -> Result<(), &'a ::libloading::Error> { - self.__library.foo1.as_ref().map(|_| ()) - } -} diff --git a/tests/expectations/tests/dynamic_loading_with_blacklist.rs b/tests/expectations/tests/dynamic_loading_with_blacklist.rs index 259054b266..b3f6eb95bf 100644 --- a/tests/expectations/tests/dynamic_loading_with_blacklist.rs +++ b/tests/expectations/tests/dynamic_loading_with_blacklist.rs @@ -59,13 +59,13 @@ impl X { extern crate libloading; pub struct TestLib { __library: ::libloading::Library, - foo: Result< + pub foo: Result< unsafe extern "C" fn( x: *mut ::std::os::raw::c_void, ) -> ::std::os::raw::c_int, ::libloading::Error, >, - bar: Result< + pub bar: Result< unsafe extern "C" fn( x: *mut ::std::os::raw::c_void, ) -> ::std::os::raw::c_int, @@ -81,14 +81,11 @@ impl TestLib { let foo = __library.get("foo".as_bytes()).map(|sym| *sym); let bar = __library.get("bar".as_bytes()).map(|sym| *sym); Ok(TestLib { - __library: __library, + __library, foo, bar, }) } - pub fn can_call(&self) -> CheckTestLib { - CheckTestLib { __library: self } - } pub unsafe fn foo( &self, x: *mut ::std::os::raw::c_void, @@ -104,14 +101,3 @@ impl TestLib { (sym)(x) } } -pub struct CheckTestLib<'a> { - __library: &'a TestLib, -} -impl<'a> CheckTestLib<'a> { - pub fn foo(&self) -> Result<(), &'a ::libloading::Error> { - self.__library.foo.as_ref().map(|_| ()) - } - pub fn bar(&self) -> Result<(), &'a ::libloading::Error> { - self.__library.bar.as_ref().map(|_| ()) - } -} diff --git a/tests/expectations/tests/dynamic_loading_with_class.rs b/tests/expectations/tests/dynamic_loading_with_class.rs index 636f01bb2a..6c98caef14 100644 --- a/tests/expectations/tests/dynamic_loading_with_class.rs +++ b/tests/expectations/tests/dynamic_loading_with_class.rs @@ -59,13 +59,13 @@ impl A { extern crate libloading; pub struct TestLib { __library: ::libloading::Library, - foo: Result< + pub foo: Result< unsafe extern "C" fn( x: *mut ::std::os::raw::c_void, ) -> ::std::os::raw::c_int, ::libloading::Error, >, - bar: Result, + pub bar: Result, } impl TestLib { pub unsafe fn new

(path: P) -> Result @@ -76,14 +76,11 @@ impl TestLib { let foo = __library.get("foo".as_bytes()).map(|sym| *sym); let bar = __library.get("bar".as_bytes()).map(|sym| *sym); Ok(TestLib { - __library: __library, + __library, foo, bar, }) } - pub fn can_call(&self) -> CheckTestLib { - CheckTestLib { __library: self } - } pub unsafe fn foo( &self, x: *mut ::std::os::raw::c_void, @@ -96,14 +93,3 @@ impl TestLib { (sym)() } } -pub struct CheckTestLib<'a> { - __library: &'a TestLib, -} -impl<'a> CheckTestLib<'a> { - pub fn foo(&self) -> Result<(), &'a ::libloading::Error> { - self.__library.foo.as_ref().map(|_| ()) - } - pub fn bar(&self) -> Result<(), &'a ::libloading::Error> { - self.__library.bar.as_ref().map(|_| ()) - } -} diff --git a/tests/expectations/tests/dynamic_loading_with_whitelist.rs b/tests/expectations/tests/dynamic_loading_with_whitelist.rs index a1f8a2a497..0fcdf1daf3 100644 --- a/tests/expectations/tests/dynamic_loading_with_whitelist.rs +++ b/tests/expectations/tests/dynamic_loading_with_whitelist.rs @@ -8,18 +8,25 @@ extern crate libloading; pub struct TestLib { __library: ::libloading::Library, - foo: Result< + pub foo: Result< unsafe extern "C" fn( x: *mut ::std::os::raw::c_void, ) -> ::std::os::raw::c_int, ::libloading::Error, >, - baz: Result< + pub baz: Result< unsafe extern "C" fn( x: *mut ::std::os::raw::c_void, ) -> ::std::os::raw::c_int, ::libloading::Error, >, + pub bazz: Result< + unsafe extern "C" fn( + arg1: ::std::os::raw::c_int, + ... + ) -> ::std::os::raw::c_int, + ::libloading::Error, + >, } impl TestLib { pub unsafe fn new

(path: P) -> Result @@ -29,15 +36,14 @@ impl TestLib { let __library = ::libloading::Library::new(path)?; let foo = __library.get("foo".as_bytes()).map(|sym| *sym); let baz = __library.get("baz".as_bytes()).map(|sym| *sym); + let bazz = __library.get("bazz".as_bytes()).map(|sym| *sym); Ok(TestLib { - __library: __library, + __library, foo, baz, + bazz, }) } - pub fn can_call(&self) -> CheckTestLib { - CheckTestLib { __library: self } - } pub unsafe fn foo( &self, x: *mut ::std::os::raw::c_void, @@ -53,14 +59,3 @@ impl TestLib { (sym)(x) } } -pub struct CheckTestLib<'a> { - __library: &'a TestLib, -} -impl<'a> CheckTestLib<'a> { - pub fn foo(&self) -> Result<(), &'a ::libloading::Error> { - self.__library.foo.as_ref().map(|_| ()) - } - pub fn baz(&self) -> Result<(), &'a ::libloading::Error> { - self.__library.baz.as_ref().map(|_| ()) - } -} diff --git a/tests/headers/dynamic_loading_with_whitelist.hpp b/tests/headers/dynamic_loading_with_whitelist.hpp index 922b546124..33bfe805e2 100644 --- a/tests/headers/dynamic_loading_with_whitelist.hpp +++ b/tests/headers/dynamic_loading_with_whitelist.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --dynamic-loading TestLib --whitelist-function baz --whitelist-function foo +// bindgen-flags: --dynamic-loading TestLib --whitelist-function baz --whitelist-function foo --whitelist-function bazz class X { int _x; @@ -13,3 +13,4 @@ class X { int foo(void *x); int bar(void *x); int baz(void *x); +int bazz(int, ...); From 30fb4eccb3cf3068e4132e68ba832ec148c2b786 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 25 Nov 2020 15:05:30 +0100 Subject: [PATCH 115/942] Remove cfg-if dependency. We use it so little that it's not worth it. --- Cargo.lock | 1 - Cargo.toml | 1 - src/ir/item.rs | 31 +++++++++++++++---------------- src/lib.rs | 15 ++++----------- 4 files changed, 19 insertions(+), 29 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ed6e1c8846..4c453a8ca3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -35,7 +35,6 @@ version = "0.55.1" dependencies = [ "bitflags", "cexpr", - "cfg-if 1.0.0", "clang-sys", "clap", "diff", diff --git a/Cargo.toml b/Cargo.toml index 3b24d3db3e..d06359d9d9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,7 +47,6 @@ shlex = "0.1" [dependencies] bitflags = "1.0.3" cexpr = "0.4" -cfg-if = "1" # This kinda sucks: https://github.com/rust-lang/cargo/issues/1982 clap = { version = "2", optional = true } clang-sys = { version = "1", features = ["clang_6_0"] } diff --git a/src/ir/item.rs b/src/ir/item.rs index f9da64fd9d..e9abed7032 100644 --- a/src/ir/item.rs +++ b/src/ir/item.rs @@ -101,24 +101,23 @@ pub trait ItemAncestors { fn ancestors<'a>(&self, ctx: &'a BindgenContext) -> ItemAncestorsIter<'a>; } -cfg_if! { - if #[cfg(testing_only_extra_assertions)] { - type DebugOnlyItemSet = ItemSet; - } else { - struct DebugOnlyItemSet; - - impl DebugOnlyItemSet { - fn new() -> Self { - DebugOnlyItemSet - } +#[cfg(testing_only_extra_assertions)] +type DebugOnlyItemSet = ItemSet; - fn contains(&self, _id: &ItemId) -> bool { - false - } +#[cfg(not(testing_only_extra_assertions))] +struct DebugOnlyItemSet; - fn insert(&mut self, _id: ItemId) {} - } +#[cfg(not(testing_only_extra_assertions))] +impl DebugOnlyItemSet { + fn new() -> Self { + DebugOnlyItemSet } + + fn contains(&self, _id: &ItemId) -> bool { + false + } + + fn insert(&mut self, _id: ItemId) {} } /// An iterator over an item and its ancestors. @@ -132,7 +131,7 @@ impl<'a> ItemAncestorsIter<'a> { fn new>(ctx: &'a BindgenContext, id: Id) -> Self { ItemAncestorsIter { item: id.into(), - ctx: ctx, + ctx, seen: DebugOnlyItemSet::new(), } } diff --git a/src/lib.rs b/src/lib.rs index 7aa87831f2..37c301dfcc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,9 +18,6 @@ #[macro_use] extern crate bitflags; #[macro_use] -#[allow(unused_extern_crates)] -extern crate cfg_if; -#[macro_use] extern crate lazy_static; #[macro_use] extern crate quote; @@ -44,14 +41,10 @@ mod extra_assertions; // we don't expose internals to library consumers. macro_rules! doc_mod { ($m:ident, $doc_mod_name:ident) => { - cfg_if! { - if #[cfg(feature = "testing_only_docs")] { - pub mod $doc_mod_name { - //! Autogenerated documentation module. - pub use super::$m::*; - } - } else { - } + #[cfg(feature = "testing_only_docs")] + pub mod $doc_mod_name { + //! Autogenerated documentation module. + pub use super::$m::*; } }; } From d8082613e2c33efbd7b5347d4c1809578d49bd7b Mon Sep 17 00:00:00 2001 From: Varphone Wong Date: Wed, 25 Nov 2020 17:24:46 +0800 Subject: [PATCH 116/942] Add --no-default flag Sometimes, we need customize the implement of `Default` for certain types, In these cases, the `nodefault` annotation can be used to prevent bindgen to autoderive the `Default` traits for a type. --- book/src/SUMMARY.md | 1 + book/src/nodefault.md | 48 +++++++++++++++++++ src/codegen/mod.rs | 8 ++-- src/ir/analysis/derive.rs | 2 +- src/ir/annotations.rs | 9 ++++ src/ir/context.rs | 6 +++ src/lib.rs | 13 +++++ src/options.rs | 13 +++++ tests/expectations/tests/no_default.rs | 23 +++++++++ .../tests/no_default_bypass_derive_default.rs | 22 +++++++++ tests/expectations/tests/no_default_opaque.rs | 26 ++++++++++ .../tests/no_default_whitelisted.rs | 35 ++++++++++++++ tests/headers/no_default.hpp | 11 +++++ .../no_default_bypass_derive_default.hpp | 11 +++++ tests/headers/no_default_opaque.hpp | 5 ++ tests/headers/no_default_whitelisted.hpp | 5 ++ 16 files changed, 234 insertions(+), 4 deletions(-) create mode 100644 book/src/nodefault.md create mode 100644 tests/expectations/tests/no_default.rs create mode 100644 tests/expectations/tests/no_default_bypass_derive_default.rs create mode 100644 tests/expectations/tests/no_default_opaque.rs create mode 100644 tests/expectations/tests/no_default_whitelisted.rs create mode 100644 tests/headers/no_default.hpp create mode 100644 tests/headers/no_default_bypass_derive_default.hpp create mode 100644 tests/headers/no_default_opaque.hpp create mode 100644 tests/headers/no_default_whitelisted.hpp diff --git a/book/src/SUMMARY.md b/book/src/SUMMARY.md index e2347fb43c..16291c3631 100644 --- a/book/src/SUMMARY.md +++ b/book/src/SUMMARY.md @@ -18,6 +18,7 @@ - [Replacing One Type with Another](./replacing-types.md) - [Preventing the Derivation of `Copy` and `Clone`](./nocopy.md) - [Preventing the Derivation of `Debug`](./nodebug.md) + - [Preventing the Derivation of `Default`](./nodefault.md) - [Generating Bindings to C++](./cpp.md) - [Generating Bindings to Objective-c](./objc.md) - [Using Unions](./using-unions.md) diff --git a/book/src/nodefault.md b/book/src/nodefault.md new file mode 100644 index 0000000000..37896f6c5c --- /dev/null +++ b/book/src/nodefault.md @@ -0,0 +1,48 @@ +# Preventing the Derivation of `Default` + +`bindgen` will attempt to derive/impl the `Default` traits on a best-effort basis. +Sometimes, we need customize the implement of `Default` for certain types, +In these cases, the `nodefault` annotation can be used to prevent bindgen +to autoderive the `Default` traits for a type. + +### Library + +* [`bindgen::Builder::no_default`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.no_default) + +### Command Line + +* `--no-default ` + +### Annotations + +```c +/** + * We need to specify some preset values as the Default of Header. + * + * for example: + * + *

+ */ +struct Header { + unsigned int magic; + unsigned char data[252]; +}; + +... +``` + +### Customize Implements + +```rust,ignore +// Include the generated bindings. +include!(concat!(env!("OUT_DIR"), "/bindings.rs")); + +impl Default for Header { + fn default() -> Self { + Self { + magic: 0x10203040u32, + data: [0; 252usize], + } + } +} +``` diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 754c2c8b42..15aea22a0a 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -118,7 +118,7 @@ fn derives_of_item(item: &Item, ctx: &BindgenContext) -> DerivableTraits { derivable_traits |= DerivableTraits::DEBUG; } - if item.can_derive_default(ctx) { + if item.can_derive_default(ctx) && !item.annotations().disallow_default() { derivable_traits |= DerivableTraits::DEFAULT; } @@ -1900,8 +1900,10 @@ impl CodeGenerator for CompInfo { } if !derivable_traits.contains(DerivableTraits::DEFAULT) { - needs_default_impl = - ctx.options().derive_default && !self.is_forward_declaration(); + needs_default_impl = ctx.options().derive_default && + !self.is_forward_declaration() && + !ctx.no_default_by_name(item) && + !item.annotations().disallow_default(); } let all_template_params = item.all_template_params(ctx); diff --git a/src/ir/analysis/derive.rs b/src/ir/analysis/derive.rs index 48c544f6aa..6c50fa6cbf 100644 --- a/src/ir/analysis/derive.rs +++ b/src/ir/analysis/derive.rs @@ -446,11 +446,11 @@ impl DeriveTrait { match self { DeriveTrait::Copy => ctx.no_copy_by_name(item), DeriveTrait::Debug => ctx.no_debug_by_name(item), + DeriveTrait::Default => ctx.no_default_by_name(item), DeriveTrait::Hash => ctx.no_hash_by_name(item), DeriveTrait::PartialEqOrPartialOrd => { ctx.no_partialeq_by_name(item) } - _ => false, } } diff --git a/src/ir/annotations.rs b/src/ir/annotations.rs index da4ef4f75e..12664f6022 100644 --- a/src/ir/annotations.rs +++ b/src/ir/annotations.rs @@ -40,6 +40,8 @@ pub struct Annotations { disallow_copy: bool, /// Manually disable deriving debug on this type. disallow_debug: bool, + /// Manually disable deriving/implement default on this type. + disallow_default: bool, /// Whether fields should be marked as private or not. You can set this on /// structs (it will apply to all the fields), or individual fields. private_fields: Option, @@ -81,6 +83,7 @@ impl Default for Annotations { use_instead_of: None, disallow_copy: false, disallow_debug: false, + disallow_default: false, private_fields: None, accessor_kind: None, constify_enum_variant: false, @@ -155,6 +158,11 @@ impl Annotations { self.disallow_debug } + /// Should we avoid implementing the `Default` trait? + pub fn disallow_default(&self) -> bool { + self.disallow_default + } + /// Should the fields be private? pub fn private_fields(&self) -> Option { self.private_fields @@ -181,6 +189,7 @@ impl Annotations { "hide" => self.hide = true, "nocopy" => self.disallow_copy = true, "nodebug" => self.disallow_debug = true, + "nodefault" => self.disallow_default = true, "replaces" => { self.use_instead_of = Some( attr.value.split("::").map(Into::into).collect(), diff --git a/src/ir/context.rs b/src/ir/context.rs index bb0c3f9dc9..1a54375779 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -2591,6 +2591,12 @@ If you encounter an error missing from this list, please file an issue or a PR!" self.options().no_debug_types.matches(&name) } + /// Check if `--no-default` flag is enabled for this item. + pub fn no_default_by_name(&self, item: &Item) -> bool { + let name = item.path_for_whitelisting(self)[1..].join("::"); + self.options().no_default_types.matches(&name) + } + /// Check if `--no-hash` flag is enabled for this item. pub fn no_hash_by_name(&self, item: &Item) -> bool { let name = item.path_for_whitelisting(self)[1..].join("::"); diff --git a/src/lib.rs b/src/lib.rs index 37c301dfcc..09410b5ed3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -298,6 +298,7 @@ impl Builder { (&self.options.no_partialeq_types, "--no-partialeq"), (&self.options.no_copy_types, "--no-copy"), (&self.options.no_debug_types, "--no-debug"), + (&self.options.no_default_types, "--no-default"), (&self.options.no_hash_types, "--no-hash"), ]; @@ -1446,6 +1447,13 @@ impl Builder { self } + /// Don't derive/impl `Default` for a given type. Regular + /// expressions are supported. + pub fn no_default>(mut self, arg: T) -> Self { + self.options.no_default_types.insert(arg.into()); + self + } + /// Don't derive `Hash` for a given type. Regular /// expressions are supported. pub fn no_hash>(mut self, arg: T) -> Builder { @@ -1745,6 +1753,9 @@ struct BindgenOptions { /// The set of types that we should not derive `Debug` for. no_debug_types: RegexSet, + /// The set of types that we should not derive/impl `Default` for. + no_default_types: RegexSet, + /// The set of types that we should not derive `Hash` for. no_hash_types: RegexSet, @@ -1786,6 +1797,7 @@ impl BindgenOptions { &mut self.no_partialeq_types, &mut self.no_copy_types, &mut self.no_debug_types, + &mut self.no_default_types, &mut self.no_hash_types, ]; let record_matches = self.record_matches; @@ -1886,6 +1898,7 @@ impl Default for BindgenOptions { no_partialeq_types: Default::default(), no_copy_types: Default::default(), no_debug_types: Default::default(), + no_default_types: Default::default(), no_hash_types: Default::default(), array_pointers_in_arguments: false, wasm_import_module_name: None, diff --git a/src/options.rs b/src/options.rs index 8c85abae49..657c3c9abc 100644 --- a/src/options.rs +++ b/src/options.rs @@ -451,6 +451,13 @@ where .takes_value(true) .multiple(true) .number_of_values(1), + Arg::with_name("no-default") + .long("no-default") + .help("Avoid deriving/implement Default for types matching .") + .value_name("regex") + .takes_value(true) + .multiple(true) + .number_of_values(1), Arg::with_name("no-hash") .long("no-hash") .help("Avoid deriving Hash for types matching .") @@ -871,6 +878,12 @@ where } } + if let Some(no_default) = matches.values_of("no-default") { + for regex in no_default { + builder = builder.no_default(regex); + } + } + if let Some(no_hash) = matches.values_of("no-hash") { for regex in no_hash { builder = builder.no_hash(regex); diff --git a/tests/expectations/tests/no_default.rs b/tests/expectations/tests/no_default.rs new file mode 100644 index 0000000000..27ea3035c4 --- /dev/null +++ b/tests/expectations/tests/no_default.rs @@ -0,0 +1,23 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +///
+#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct DefaultButWait { + pub whatever: ::std::os::raw::c_int, +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct DefaultButWaitDerived { + pub whatever: DefaultButWait, +} +impl Default for DefaultButWaitDerived { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} diff --git a/tests/expectations/tests/no_default_bypass_derive_default.rs b/tests/expectations/tests/no_default_bypass_derive_default.rs new file mode 100644 index 0000000000..4b97e3f489 --- /dev/null +++ b/tests/expectations/tests/no_default_bypass_derive_default.rs @@ -0,0 +1,22 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +pub struct Generic { + pub t: [T; 40usize], + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, +} +impl Default for Generic { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +#[repr(C)] +pub struct NoDefault { + pub t: [T; 40usize], + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, +} diff --git a/tests/expectations/tests/no_default_opaque.rs b/tests/expectations/tests/no_default_opaque.rs new file mode 100644 index 0000000000..3c928551e6 --- /dev/null +++ b/tests/expectations/tests/no_default_opaque.rs @@ -0,0 +1,26 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +#[repr(align(4))] +#[derive(Debug, Copy, Clone)] +pub struct NoDefault { + pub _bindgen_opaque_blob: u32, +} +#[test] +fn bindgen_test_layout_NoDefault() { + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(NoDefault)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(NoDefault)) + ); +} diff --git a/tests/expectations/tests/no_default_whitelisted.rs b/tests/expectations/tests/no_default_whitelisted.rs new file mode 100644 index 0000000000..980f1575f0 --- /dev/null +++ b/tests/expectations/tests/no_default_whitelisted.rs @@ -0,0 +1,35 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct NoDefault { + pub i: ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout_NoDefault() { + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(NoDefault)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(NoDefault)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).i as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(NoDefault), + "::", + stringify!(i) + ) + ); +} diff --git a/tests/headers/no_default.hpp b/tests/headers/no_default.hpp new file mode 100644 index 0000000000..79d25fbdc2 --- /dev/null +++ b/tests/headers/no_default.hpp @@ -0,0 +1,11 @@ + +/**
*/ +template +class DefaultButWait { + int whatever; +}; + +template +class DefaultButWaitDerived { + DefaultButWait whatever; +}; diff --git a/tests/headers/no_default_bypass_derive_default.hpp b/tests/headers/no_default_bypass_derive_default.hpp new file mode 100644 index 0000000000..0f8339062f --- /dev/null +++ b/tests/headers/no_default_bypass_derive_default.hpp @@ -0,0 +1,11 @@ +// bindgen-flags: --no-default "NoDefault" + +template +class Generic { + T t[40]; +}; + +template +class NoDefault { + T t[40]; +}; diff --git a/tests/headers/no_default_opaque.hpp b/tests/headers/no_default_opaque.hpp new file mode 100644 index 0000000000..3245d8f93c --- /dev/null +++ b/tests/headers/no_default_opaque.hpp @@ -0,0 +1,5 @@ +// bindgen-flags: --opaque-type "NoDefault" --no-default "NoDefault" + +class NoDefault { + int i; +}; diff --git a/tests/headers/no_default_whitelisted.hpp b/tests/headers/no_default_whitelisted.hpp new file mode 100644 index 0000000000..12676be6d2 --- /dev/null +++ b/tests/headers/no_default_whitelisted.hpp @@ -0,0 +1,5 @@ +// bindgen-flags: --whitelist-type "NoDefault" --no-default "NoDefault" + +class NoDefault { + int i; +}; From 11ae35089e4748b7e2a6f50f6bef7709af72e724 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 26 Nov 2020 11:33:57 +0100 Subject: [PATCH 117/942] v0.56.0 --- CHANGELOG.md | 145 ++++++++++++++++++++++----------------------------- Cargo.lock | 2 +- Cargo.toml | 2 +- 3 files changed, 63 insertions(+), 86 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea86698669..8eed4d13d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,87 +9,85 @@ - [Removed](#removed) - [Fixed](#fixed) - [Security](#security) -- [0.55.1](#0551) - - [Fixed](#fixed-1) -- [0.55.0](#0550) - - [Removed](#removed-1) +- [0.56.0](#0560) - [Added](#added-1) - [Changed](#changed-1) + - [Fixed](#fixed-1) +- [0.55.1](#0551) - [Fixed](#fixed-2) -- [0.54.1](#0541) +- [0.55.0](#0550) + - [Removed](#removed-1) - [Added](#added-2) - [Changed](#changed-2) - [Fixed](#fixed-3) -- [0.54.0](#0540) +- [0.54.1](#0541) - [Added](#added-3) - [Changed](#changed-3) - [Fixed](#fixed-4) -- [0.53.3](#0533) +- [0.54.0](#0540) - [Added](#added-4) + - [Changed](#changed-4) - [Fixed](#fixed-5) +- [0.53.3](#0533) + - [Added](#added-5) + - [Fixed](#fixed-6) - [0.53.2](#0532) - - [Changed](#changed-4) + - [Changed](#changed-5) - [0.53.1](#0531) - - [Added](#added-5) -- [0.53.0](#0530) - [Added](#added-6) - - [Changed](#changed-5) - - [Fixed](#fixed-6) -- [0.52.0](#0520) +- [0.53.0](#0530) - [Added](#added-7) - [Changed](#changed-6) - [Fixed](#fixed-7) -- [0.51.1](#0511) - - [Fixed](#fixed-8) +- [0.52.0](#0520) + - [Added](#added-8) - [Changed](#changed-7) -- [0.51.0](#0510) + - [Fixed](#fixed-8) +- [0.51.1](#0511) - [Fixed](#fixed-9) - [Changed](#changed-8) - - [Added](#added-8) -- [0.50.0](#0500) +- [0.51.0](#0510) + - [Fixed](#fixed-10) + - [Changed](#changed-9) - [Added](#added-9) -- [0.49.3](#0493) +- [0.50.0](#0500) - [Added](#added-10) +- [0.49.3](#0493) + - [Added](#added-11) - [0.49.2](#0492) - - [Changed](#changed-9) -- [0.49.1](#0491) - - [Fixed](#fixed-10) - [Changed](#changed-10) -- [0.49.0](#0490) - - [Added](#added-11) +- [0.49.1](#0491) - [Fixed](#fixed-11) - [Changed](#changed-11) -- [0.48.1](#0481) +- [0.49.0](#0490) + - [Added](#added-12) - [Fixed](#fixed-12) -- [0.48.0](#0480) - [Changed](#changed-12) +- [0.48.1](#0481) - [Fixed](#fixed-13) -- [0.47.4](#0474) - - [Added](#added-12) -- [0.47.3](#0473) +- [0.48.0](#0480) - [Changed](#changed-13) -- [0.47.2](#0472) - [Fixed](#fixed-14) -- [0.47.1](#0471) +- [0.47.4](#0474) + - [Added](#added-13) +- [0.47.3](#0473) - [Changed](#changed-14) +- [0.47.2](#0472) - [Fixed](#fixed-15) -- [0.47.0](#0470) +- [0.47.1](#0471) - [Changed](#changed-15) - [Fixed](#fixed-16) -- [0.33.1 .. 0.46.0](#0331--0460) - - [Added](#added-13) - - [Removed](#removed-2) +- [0.47.0](#0470) - [Changed](#changed-16) - [Fixed](#fixed-17) -- [0.33.1](#0331) - - [Fixed](#fixed-18) -- [0.33.0](#0330) +- [0.33.1 .. 0.46.0](#0331--0460) - [Added](#added-14) + - [Removed](#removed-2) - [Changed](#changed-17) - - [Deprecated](#deprecated-1) - - [Removed](#removed-3) + - [Fixed](#fixed-18) +- [0.33.1](#0331) - [Fixed](#fixed-19) - - [Security](#security-1) +- [0.33.0](#0330) - [0.32.2](#0322) - [Fixed](#fixed-20) - [0.32.1](#0321) @@ -101,13 +99,13 @@ - [0.31.0](#0310) - [Added](#added-16) - [Changed](#changed-19) - - [Deprecated](#deprecated-2) - - [Removed](#removed-4) + - [Deprecated](#deprecated-1) + - [Removed](#removed-3) - [Fixed](#fixed-23) - [0.30.0](#0300) - [Added](#added-17) - [Changed](#changed-20) - - [Deprecated](#deprecated-3) + - [Deprecated](#deprecated-2) - [Fixed](#fixed-24) - [0.29.0](#0290) - [Added](#added-18) @@ -118,13 +116,31 @@ -------------------------------------------------------------------------------- +# Unreleased + +## Added + +## Changed + +## Deprecated + +## Removed + +## Fixed + +## Security + +--- + # 0.56.0 -Released YYYY/MM/DD +Released 2020/11/26 ## Added * Objective-c bindings generate `From for ParentClass` as well as `TryFrom for ChildClass` ([#1883][]). +* Experimental dynamic library support via `dynamic_library_name` (#1846). +* Option to disable deriving `Default` on a per-struct basis (#1930). ## Changed @@ -132,24 +148,11 @@ Released YYYY/MM/DD * Templates and enums now correctly use the same naming scheme as other types (#1891). -## Deprecated - -* TODO (or remove section if none) - -## Removed - -* TODO (or remove section if none) - ## Fixed * Constructors in wasm32 now return a value. (#1877). * Fixed objective-c protocol impl blocks for parent classes's protocols ([#1883][]). -## Security - -* TODO (or remove section if none) - - [#1883]: https://github.com/rust-lang/rust-bindgen/issues/1883 -------------------------------------------------------------------------------- @@ -705,32 +708,6 @@ Released 2018/02/14 # 0.33.0 -Released YYYY/MM/DD - -## Added - -* TODO (or remove section if none) - -## Changed - -* TODO (or remove section if none) - -## Deprecated - -* TODO (or remove section if none) - -## Removed - -* TODO (or remove section if none) - -## Fixed - -* TODO (or remove section if none) - -## Security - -* TODO (or remove section if none) - -------------------------------------------------------------------------------- # 0.32.2 diff --git a/Cargo.lock b/Cargo.lock index 4c453a8ca3..589076f2f9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -31,7 +31,7 @@ dependencies = [ [[package]] name = "bindgen" -version = "0.55.1" +version = "0.56.0" dependencies = [ "bitflags", "cexpr", diff --git a/Cargo.toml b/Cargo.toml index d06359d9d9..3516fc2584 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ readme = "README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.55.1" +version = "0.56.0" edition = "2018" build = "build.rs" From 337703b38f35ca9a87390720b339132a01e4c011 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 26 Nov 2020 12:09:15 +0100 Subject: [PATCH 118/942] lib: Improve c++ auto-detection. Fixes #1919, as otherwise we peek the wrong include paths unless you pass "-x c++" or such. --- src/lib.rs | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 09410b5ed3..a29c2cbb59 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -90,10 +90,26 @@ pub(crate) use std::collections::hash_map::Entry; /// Default prefix for the anon fields. pub const DEFAULT_ANON_FIELDS_PREFIX: &'static str = "__bindgen_anon_"; +fn file_is_cpp(name_file: &str) -> bool { + name_file.ends_with(".hpp") || + name_file.ends_with(".hxx") || + name_file.ends_with(".hh") || + name_file.ends_with(".h++") +} + fn args_are_cpp(clang_args: &[String]) -> bool { - return clang_args - .windows(2) - .any(|w| w[0] == "-xc++" || w[1] == "-xc++" || w == &["-x", "c++"]); + for w in clang_args.windows(2) { + if w[0] == "-xc++" || w[1] == "-xc++" { + return true; + } + if w[0] == "-x" && w[1] == "c++" { + return true; + } + if w[0] == "-include" && file_is_cpp(&w[1]) { + return true; + } + } + false } bitflags! { @@ -1341,13 +1357,6 @@ impl Builder { /// issues. The resulting file will be named something like `__bindgen.i` or /// `__bindgen.ii` pub fn dump_preprocessed_input(&self) -> io::Result<()> { - fn check_is_cpp(name_file: &str) -> bool { - name_file.ends_with(".hpp") || - name_file.ends_with(".hxx") || - name_file.ends_with(".hh") || - name_file.ends_with(".h++") - } - let clang = clang_sys::support::Clang::find(None, &[]).ok_or_else(|| { io::Error::new( @@ -1365,7 +1374,7 @@ impl Builder { // For each input header, add `#include "$header"`. for header in &self.input_headers { - is_cpp |= check_is_cpp(header); + is_cpp |= file_is_cpp(header); wrapper_contents.push_str("#include \""); wrapper_contents.push_str(header); @@ -1375,7 +1384,7 @@ impl Builder { // For each input header content, add a prefix line of `#line 0 "$name"` // followed by the contents. for &(ref name, ref contents) in &self.input_header_contents { - is_cpp |= check_is_cpp(name); + is_cpp |= file_is_cpp(name); wrapper_contents.push_str("#line 0 \""); wrapper_contents.push_str(name); @@ -2069,7 +2078,12 @@ impl Bindings { debug!("Found clang: {:?}", clang); // Whether we are working with C or C++ inputs. - let is_cpp = args_are_cpp(&options.clang_args); + let is_cpp = args_are_cpp(&options.clang_args) || + options + .input_header + .as_ref() + .map_or(false, |i| file_is_cpp(&i)); + let search_paths = if is_cpp { clang.cpp_search_paths } else { From 6a5726eac514b49ec8a9f8360ed5d0d73da9feb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 26 Nov 2020 13:39:06 +0100 Subject: [PATCH 119/942] lib: Use if let on recently-introduced code. --- src/lib.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index a29c2cbb59..dff7c5885a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -528,10 +528,9 @@ impl Builder { output_vector.push(path.into()); } - if self.options.dynamic_library_name.is_some() { - let libname = self.options.dynamic_library_name.as_ref().unwrap(); + if let Some(ref name) = self.options.dynamic_library_name { output_vector.push("--dynamic-loading".into()); - output_vector.push(libname.clone()); + output_vector.push(name.clone()); } // Add clang arguments From 19142ac6b3d8ee4fc5686d6f30b77e660026e528 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sat, 28 Nov 2020 01:33:32 +0100 Subject: [PATCH 120/942] struct_layout: Fix field offset computation for packed(n) structs. This can cause unnecessary padding to be computed otherwise at the end of the struct. With repr(packed(n)), a field can have padding to adjacent fields as long as its alignment is less than n. So reuse the code we have to align to a field layout, aligning to the struct layout instead. Fixes #1934 --- src/codegen/mod.rs | 2 +- src/codegen/struct_layout.rs | 35 +++++++++----- src/ir/comp.rs | 6 +-- .../tests/divide-by-zero-in-struct-layout.rs | 1 - .../tests/packed-n-with-padding.rs | 48 +++++++++++++++++++ tests/headers/packed-n-with-padding.h | 8 ++++ 6 files changed, 84 insertions(+), 16 deletions(-) create mode 100644 tests/expectations/tests/packed-n-with-padding.rs create mode 100644 tests/headers/packed-n-with-padding.h diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 15aea22a0a..0d93c49193 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -1650,7 +1650,7 @@ impl CodeGenerator for CompInfo { let ty = item.expect_type(); let layout = ty.layout(ctx); - let mut packed = self.is_packed(ctx, &layout); + let mut packed = self.is_packed(ctx, layout.as_ref()); let canonical_name = item.canonical_name(ctx); let canonical_ident = ctx.rust_ident(&canonical_name); diff --git a/src/codegen/struct_layout.rs b/src/codegen/struct_layout.rs index 54dfd86efa..4536e889af 100644 --- a/src/codegen/struct_layout.rs +++ b/src/codegen/struct_layout.rs @@ -18,6 +18,7 @@ pub struct StructLayoutTracker<'a> { ctx: &'a BindgenContext, comp: &'a CompInfo, is_packed: bool, + known_type_layout: Option, latest_offset: usize, padding_count: usize, latest_field_layout: Option, @@ -86,11 +87,14 @@ impl<'a> StructLayoutTracker<'a> { ty: &'a Type, name: &'a str, ) -> Self { + let known_type_layout = ty.layout(ctx); + let is_packed = comp.is_packed(ctx, known_type_layout.as_ref()); StructLayoutTracker { name, ctx, comp, - is_packed: comp.is_packed(ctx, &ty.layout(ctx)), + is_packed, + known_type_layout, latest_offset: 0, padding_count: 0, latest_field_layout: None, @@ -180,23 +184,32 @@ impl<'a> StructLayoutTracker<'a> { let will_merge_with_bitfield = self.align_to_latest_field(field_layout); + let padding_bytes = match field_offset { + Some(offset) if offset / 8 > self.latest_offset => { + offset / 8 - self.latest_offset + } + _ => { + if will_merge_with_bitfield || field_layout.align == 0 { + 0 + } else if !self.is_packed { + self.padding_bytes(field_layout) + } else if let Some(l) = self.known_type_layout { + self.padding_bytes(l) + } else { + 0 + } + } + }; + + self.latest_offset += padding_bytes; + let padding_layout = if self.is_packed { None } else { - let padding_bytes = match field_offset { - Some(offset) if offset / 8 > self.latest_offset => { - offset / 8 - self.latest_offset - } - _ if will_merge_with_bitfield || field_layout.align == 0 => 0, - _ => self.padding_bytes(field_layout), - }; - // Otherwise the padding is useless. let need_padding = padding_bytes >= field_layout.align || field_layout.align > MAX_GUARANTEED_ALIGN; - self.latest_offset += padding_bytes; - debug!( "Offset: : {} -> {}", self.latest_offset - padding_bytes, diff --git a/src/ir/comp.rs b/src/ir/comp.rs index 22c124fa36..1d257d20b2 100644 --- a/src/ir/comp.rs +++ b/src/ir/comp.rs @@ -1576,7 +1576,7 @@ impl CompInfo { pub fn is_packed( &self, ctx: &BindgenContext, - layout: &Option, + layout: Option<&Layout>, ) -> bool { if self.packed_attr { return true; @@ -1584,7 +1584,7 @@ impl CompInfo { // Even though `libclang` doesn't expose `#pragma packed(...)`, we can // detect it through its effects. - if let Some(ref parent_layout) = *layout { + if let Some(parent_layout) = layout { if self.fields().iter().any(|f| match *f { Field::Bitfields(ref unit) => { unit.layout().align > parent_layout.align @@ -1739,7 +1739,7 @@ impl IsOpaque for CompInfo { // // 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) && + if self.is_packed(ctx, layout.as_ref()) && layout.map_or(false, |l| l.align > 1) { warn!("Found a type that is both packed and aligned to greater than \ diff --git a/tests/expectations/tests/divide-by-zero-in-struct-layout.rs b/tests/expectations/tests/divide-by-zero-in-struct-layout.rs index 1366548ea7..1484719b9c 100644 --- a/tests/expectations/tests/divide-by-zero-in-struct-layout.rs +++ b/tests/expectations/tests/divide-by-zero-in-struct-layout.rs @@ -130,7 +130,6 @@ impl WithBitfieldAndAttrPacked { pub struct WithBitfieldAndPacked { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 0usize], u8>, pub a: ::std::os::raw::c_uint, - pub __bindgen_padding_0: u8, } impl WithBitfieldAndPacked { #[inline] diff --git a/tests/expectations/tests/packed-n-with-padding.rs b/tests/expectations/tests/packed-n-with-padding.rs new file mode 100644 index 0000000000..13cb030620 --- /dev/null +++ b/tests/expectations/tests/packed-n-with-padding.rs @@ -0,0 +1,48 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C, packed(2))] +#[derive(Debug, Default, Copy, Clone)] +pub struct Packed { + pub a: ::std::os::raw::c_char, + pub b: ::std::os::raw::c_short, + pub c: ::std::os::raw::c_char, + pub d: ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout_Packed() { + assert_eq!( + ::std::mem::size_of::(), + 10usize, + concat!("Size of: ", stringify!(Packed)) + ); + assert_eq!( + ::std::mem::align_of::(), + 2usize, + concat!("Alignment of ", stringify!(Packed)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Packed), "::", stringify!(a)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).b as *const _ as usize }, + 2usize, + concat!("Offset of field: ", stringify!(Packed), "::", stringify!(b)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).c as *const _ as usize }, + 4usize, + concat!("Offset of field: ", stringify!(Packed), "::", stringify!(c)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).d as *const _ as usize }, + 6usize, + concat!("Offset of field: ", stringify!(Packed), "::", stringify!(d)) + ); +} diff --git a/tests/headers/packed-n-with-padding.h b/tests/headers/packed-n-with-padding.h new file mode 100644 index 0000000000..8a6233b52b --- /dev/null +++ b/tests/headers/packed-n-with-padding.h @@ -0,0 +1,8 @@ +#pragma pack(push, 2) +struct Packed { + char a; + short b; + char c; + int d; +}; +#pragma pack(pop) From 460ae847d25000f5e08d16fe9217adc356d3ab6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 1 Dec 2020 20:59:36 +0100 Subject: [PATCH 121/942] cli: Expose module_raw_lines to the CLI. This makes command_line_args properly return them, instead of dropping them on the floor. --- src/lib.rs | 8 ++++++++ src/options.rs | 14 ++++++++++++++ tests/expectations/tests/namespace.rs | 1 + tests/headers/namespace.hpp | 2 +- 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index dff7c5885a..ce0d5d4d24 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -494,6 +494,14 @@ impl Builder { output_vector.push(line.clone()); } + for (module, lines) in &self.options.module_lines { + for line in lines.iter() { + output_vector.push("--module-raw-line".into()); + output_vector.push(module.clone()); + output_vector.push(line.clone()); + } + } + if self.options.use_core { output_vector.push("--use-core".into()); } diff --git a/src/options.rs b/src/options.rs index 657c3c9abc..8beac4696e 100644 --- a/src/options.rs +++ b/src/options.rs @@ -338,6 +338,13 @@ where .takes_value(true) .multiple(true) .number_of_values(1), + Arg::with_name("module-raw-line") + .long("module-raw-line") + .help("Add a raw line of Rust code to a given module.") + .takes_value(true) + .multiple(true) + .number_of_values(2) + .value_names(&["module-name", "raw-line"]), Arg::with_name("rust-target") .long("rust-target") .help(&rust_target_help) @@ -769,6 +776,13 @@ where } } + if let Some(mut values) = matches.values_of("module-raw-line") { + while let Some(module) = values.next() { + let line = values.next().unwrap(); + builder = builder.module_raw_line(module, line); + } + } + if matches.is_present("use-core") { builder = builder.use_core(); } diff --git a/tests/expectations/tests/namespace.rs b/tests/expectations/tests/namespace.rs index d5d10e2945..944ec5bb07 100644 --- a/tests/expectations/tests/namespace.rs +++ b/tests/expectations/tests/namespace.rs @@ -16,6 +16,7 @@ pub mod root { pub mod whatever { #[allow(unused_imports)] use self::super::super::root; + pub type whatever_other_thing_t = whatever_int_t; pub type whatever_int_t = ::std::os::raw::c_int; extern "C" { #[link_name = "\u{1}_ZN8whatever11in_whateverEv"] diff --git a/tests/headers/namespace.hpp b/tests/headers/namespace.hpp index a8e6f8eca3..7e4197da5f 100644 --- a/tests/headers/namespace.hpp +++ b/tests/headers/namespace.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --enable-cxx-namespaces +// bindgen-flags: --enable-cxx-namespaces --module-raw-line root::whatever 'pub type whatever_other_thing_t = whatever_int_t;' void top_level(); From caec44a0b4360548eea1523dd5503526631594bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 2 Dec 2020 10:52:25 +0100 Subject: [PATCH 122/942] dyngen: Pass null-terminated byte strings to libloading. Fixes #1938. --- src/codegen/dyngen.rs | 5 +++-- tests/expectations/tests/dynamic_loading_simple.rs | 6 +++--- tests/expectations/tests/dynamic_loading_template.rs | 4 ++-- tests/expectations/tests/dynamic_loading_with_blacklist.rs | 4 ++-- tests/expectations/tests/dynamic_loading_with_class.rs | 4 ++-- tests/expectations/tests/dynamic_loading_with_whitelist.rs | 6 +++--- 6 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/codegen/dyngen.rs b/src/codegen/dyngen.rs index 65872ea276..94dd574b91 100644 --- a/src/codegen/dyngen.rs +++ b/src/codegen/dyngen.rs @@ -1,3 +1,4 @@ +use crate::codegen; use crate::ir::function::Abi; use proc_macro2::Ident; @@ -133,9 +134,9 @@ impl DynamicItems { }); } - let ident_str = ident.to_string(); + let ident_str = codegen::helpers::ast_ty::cstr_expr(ident.to_string()); self.constructor_inits.push(quote! { - let #ident = __library.get(#ident_str.as_bytes()).map(|sym| *sym); + let #ident = __library.get(#ident_str).map(|sym| *sym); }); self.init_fields.push(quote! { diff --git a/tests/expectations/tests/dynamic_loading_simple.rs b/tests/expectations/tests/dynamic_loading_simple.rs index b40711d8be..dae273a6ba 100644 --- a/tests/expectations/tests/dynamic_loading_simple.rs +++ b/tests/expectations/tests/dynamic_loading_simple.rs @@ -32,9 +32,9 @@ impl TestLib { P: AsRef<::std::ffi::OsStr>, { let __library = ::libloading::Library::new(path)?; - let foo = __library.get("foo".as_bytes()).map(|sym| *sym); - let bar = __library.get("bar".as_bytes()).map(|sym| *sym); - let baz = __library.get("baz".as_bytes()).map(|sym| *sym); + let foo = __library.get(b"foo\0").map(|sym| *sym); + let bar = __library.get(b"bar\0").map(|sym| *sym); + let baz = __library.get(b"baz\0").map(|sym| *sym); Ok(TestLib { __library, foo, diff --git a/tests/expectations/tests/dynamic_loading_template.rs b/tests/expectations/tests/dynamic_loading_template.rs index e24599de15..4d90c62f38 100644 --- a/tests/expectations/tests/dynamic_loading_template.rs +++ b/tests/expectations/tests/dynamic_loading_template.rs @@ -20,8 +20,8 @@ impl TestLib { P: AsRef<::std::ffi::OsStr>, { let __library = ::libloading::Library::new(path)?; - let foo = __library.get("foo".as_bytes()).map(|sym| *sym); - let foo1 = __library.get("foo1".as_bytes()).map(|sym| *sym); + let foo = __library.get(b"foo\0").map(|sym| *sym); + let foo1 = __library.get(b"foo1\0").map(|sym| *sym); Ok(TestLib { __library, foo, diff --git a/tests/expectations/tests/dynamic_loading_with_blacklist.rs b/tests/expectations/tests/dynamic_loading_with_blacklist.rs index b3f6eb95bf..15092f06d2 100644 --- a/tests/expectations/tests/dynamic_loading_with_blacklist.rs +++ b/tests/expectations/tests/dynamic_loading_with_blacklist.rs @@ -78,8 +78,8 @@ impl TestLib { P: AsRef<::std::ffi::OsStr>, { let __library = ::libloading::Library::new(path)?; - let foo = __library.get("foo".as_bytes()).map(|sym| *sym); - let bar = __library.get("bar".as_bytes()).map(|sym| *sym); + let foo = __library.get(b"foo\0").map(|sym| *sym); + let bar = __library.get(b"bar\0").map(|sym| *sym); Ok(TestLib { __library, foo, diff --git a/tests/expectations/tests/dynamic_loading_with_class.rs b/tests/expectations/tests/dynamic_loading_with_class.rs index 6c98caef14..a402e28874 100644 --- a/tests/expectations/tests/dynamic_loading_with_class.rs +++ b/tests/expectations/tests/dynamic_loading_with_class.rs @@ -73,8 +73,8 @@ impl TestLib { P: AsRef<::std::ffi::OsStr>, { let __library = ::libloading::Library::new(path)?; - let foo = __library.get("foo".as_bytes()).map(|sym| *sym); - let bar = __library.get("bar".as_bytes()).map(|sym| *sym); + let foo = __library.get(b"foo\0").map(|sym| *sym); + let bar = __library.get(b"bar\0").map(|sym| *sym); Ok(TestLib { __library, foo, diff --git a/tests/expectations/tests/dynamic_loading_with_whitelist.rs b/tests/expectations/tests/dynamic_loading_with_whitelist.rs index 0fcdf1daf3..0c1d9df20c 100644 --- a/tests/expectations/tests/dynamic_loading_with_whitelist.rs +++ b/tests/expectations/tests/dynamic_loading_with_whitelist.rs @@ -34,9 +34,9 @@ impl TestLib { P: AsRef<::std::ffi::OsStr>, { let __library = ::libloading::Library::new(path)?; - let foo = __library.get("foo".as_bytes()).map(|sym| *sym); - let baz = __library.get("baz".as_bytes()).map(|sym| *sym); - let bazz = __library.get("bazz".as_bytes()).map(|sym| *sym); + let foo = __library.get(b"foo\0").map(|sym| *sym); + let baz = __library.get(b"baz\0").map(|sym| *sym); + let bazz = __library.get(b"bazz\0").map(|sym| *sym); Ok(TestLib { __library, foo, From 112c69129163ea3139de019328cd8e4b837e530f Mon Sep 17 00:00:00 2001 From: Weston Carvalho Date: Mon, 14 Dec 2020 13:39:57 -0800 Subject: [PATCH 123/942] Remove unsued mutable field logic. --- src/ir/comp.rs | 32 ++++---------------------------- 1 file changed, 4 insertions(+), 28 deletions(-) diff --git a/src/ir/comp.rs b/src/ir/comp.rs index 1d257d20b2..645f6251da 100644 --- a/src/ir/comp.rs +++ b/src/ir/comp.rs @@ -148,9 +148,6 @@ pub trait FieldMethods { /// If this is a bitfield, how many bits does it need? fn bitfield_width(&self) -> Option; - /// Is this field marked as `mutable`? - fn is_mutable(&self) -> bool; - /// Get the annotations for this field. fn annotations(&self) -> &Annotations; @@ -415,10 +412,6 @@ impl FieldMethods for Bitfield { self.data.bitfield_width() } - fn is_mutable(&self) -> bool { - self.data.is_mutable() - } - fn annotations(&self) -> &Annotations { self.data.annotations() } @@ -443,7 +436,6 @@ impl RawField { comment: Option, annotations: Option, bitfield_width: Option, - mutable: bool, offset: Option, ) -> RawField { RawField(FieldData { @@ -452,7 +444,6 @@ impl RawField { comment, annotations: annotations.unwrap_or_default(), bitfield_width, - mutable, offset, }) } @@ -475,10 +466,6 @@ impl FieldMethods for RawField { self.0.bitfield_width() } - fn is_mutable(&self) -> bool { - self.0.is_mutable() - } - fn annotations(&self) -> &Annotations { self.0.annotations() } @@ -891,9 +878,6 @@ pub struct FieldData { /// If this field is a bitfield, and how many bits does it contain if it is. bitfield_width: Option, - /// If the C++ field is marked as `mutable` - mutable: bool, - /// The offset of the field (in bits) offset: Option, } @@ -915,10 +899,6 @@ impl FieldMethods for FieldData { self.bitfield_width } - fn is_mutable(&self) -> bool { - self.mutable - } - fn annotations(&self) -> &Annotations { &self.annotations } @@ -1262,9 +1242,8 @@ impl CompInfo { // anonymous field. Detect that case here, and do // nothing. } else { - let field = RawField::new( - None, ty, None, None, None, false, offset, - ); + let field = + RawField::new(None, ty, None, None, None, offset); ci.fields.append_raw_field(field); } } @@ -1284,7 +1263,7 @@ impl CompInfo { }); if !used { let field = RawField::new( - None, ty, None, None, None, false, offset, + None, ty, None, None, None, offset, ); ci.fields.append_raw_field(field); } @@ -1301,7 +1280,6 @@ impl CompInfo { let comment = cur.raw_comment(); let annotations = Annotations::new(&cur); let name = cur.spelling(); - let is_mutable = cursor.is_mutable_field(); let offset = cur.offset_of_field().ok(); // Name can be empty if there are bitfields, for example, @@ -1319,7 +1297,6 @@ impl CompInfo { comment, annotations, bit_width, - is_mutable, offset, ); ci.fields.append_raw_field(field); @@ -1527,8 +1504,7 @@ impl CompInfo { }); if let Some((ty, _, offset)) = maybe_anonymous_struct_field { - let field = - RawField::new(None, ty, None, None, None, false, offset); + let field = RawField::new(None, ty, None, None, None, offset); ci.fields.append_raw_field(field); } From ea4164c85c6a305379e4cc70465aae15afedf3d7 Mon Sep 17 00:00:00 2001 From: Antoni Simka Date: Tue, 15 Dec 2020 17:18:16 +0100 Subject: [PATCH 124/942] Add option to fit macro consts into smaller types Add a `--fit-macro-constant-types` option to make bindgen try to fit macro integer constants into types smaller than u32/i32. Useful especially when dealing with 8/16-bit architectures. Closes #1945 --- src/ir/var.rs | 54 +++++++++++++++---- src/lib.rs | 14 +++++ src/options.rs | 7 +++ .../default-macro-constant-type-signed.rs | 12 +++++ .../default-macro-constant-type-unsigned.rs | 12 +++++ .../tests/default-macro-constant-type.rs | 12 +++++ .../tests/fit-macro-constant-types.rs | 54 +++++++++++++++++++ tests/headers/default-macro-constant-type.h | 18 +++++++ tests/headers/fit-macro-constant-types.h | 4 ++ 9 files changed, 176 insertions(+), 11 deletions(-) create mode 100644 tests/expectations/tests/fit-macro-constant-types.rs create mode 100644 tests/headers/fit-macro-constant-types.h diff --git a/src/ir/var.rs b/src/ir/var.rs index c6f121d74e..64f15703c1 100644 --- a/src/ir/var.rs +++ b/src/ir/var.rs @@ -117,21 +117,53 @@ impl DotAttributes for Var { } } -// TODO(emilio): we could make this more (or less) granular, I guess. fn default_macro_constant_type(ctx: &BindgenContext, value: i64) -> IntKind { - if value < 0 || - ctx.options().default_macro_constant_type == - MacroTypeVariation::Signed - { - if value < i32::min_value() as i64 || value > i32::max_value() as i64 { - IntKind::I64 + if ctx.options().fit_macro_constants { + if value < 0 || + ctx.options().default_macro_constant_type == + MacroTypeVariation::Signed + { + if value < i32::min_value() as i64 || + value > i32::max_value() as i64 + { + IntKind::I64 + } else if value < i16::min_value() as i64 || + value > i16::max_value() as i64 + { + IntKind::I32 + } else if value < i8::min_value() as i64 || + value > i8::max_value() as i64 + { + IntKind::I16 + } else { + IntKind::I8 + } + } else if value > u32::max_value() as i64 { + IntKind::U64 + } else if value > u16::max_value() as i64 { + IntKind::U32 + } else if value > u8::max_value() as i64 { + IntKind::U16 } else { - IntKind::I32 + IntKind::U8 } - } else if value > u32::max_value() as i64 { - IntKind::U64 } else { - IntKind::U32 + if value < 0 || + ctx.options().default_macro_constant_type == + MacroTypeVariation::Signed + { + if value < i32::min_value() as i64 || + value > i32::max_value() as i64 + { + IntKind::I64 + } else { + IntKind::I32 + } + } else if value > u32::max_value() as i64 { + IntKind::U64 + } else { + IntKind::U32 + } } } diff --git a/src/lib.rs b/src/lib.rs index ce0d5d4d24..b9e1bcc56f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -478,6 +478,10 @@ impl Builder { output_vector.push("--no-prepend-enum-name".into()); } + if self.options.fit_macro_constants { + output_vector.push("--fit-macro-constant-types".into()); + } + if self.options.array_pointers_in_arguments { output_vector.push("--use-array-pointers-in-arguments".into()); } @@ -1287,6 +1291,12 @@ impl Builder { self } + /// Whether to try to fit macro constants to types smaller than u32/i32 + pub fn fit_macro_constants(mut self, doit: bool) -> Self { + self.options.fit_macro_constants = doit; + self + } + /// Prepend the enum name to constant or newtype variants. pub fn prepend_enum_name(mut self, doit: bool) -> Self { self.options.prepend_enum_name = doit; @@ -1735,6 +1745,9 @@ struct BindgenOptions { /// Whether to detect include paths using clang_sys. detect_include_paths: bool, + /// Whether to try to fit macro constants into types smaller than u32/i32 + fit_macro_constants: bool, + /// Whether to prepend the enum name to constant or newtype variants. prepend_enum_name: bool, @@ -1905,6 +1918,7 @@ impl Default for BindgenOptions { block_extern_crate: false, enable_mangling: true, detect_include_paths: true, + fit_macro_constants: false, prepend_enum_name: true, time_phases: false, record_matches: true, diff --git a/src/options.rs b/src/options.rs index 8beac4696e..7d3e077ee8 100644 --- a/src/options.rs +++ b/src/options.rs @@ -316,6 +316,9 @@ where Arg::with_name("no-include-path-detection") .long("no-include-path-detection") .help("Do not try to detect default include paths"), + Arg::with_name("fit-macro-constant-types") + .long("fit-macro-constant-types") + .help("Try to fit macro constants into types smaller than u32/i32"), Arg::with_name("unstable-rust") .long("unstable-rust") .help("Generate unstable Rust code (deprecated; use --rust-target instead).") @@ -654,6 +657,10 @@ where builder = builder.detect_include_paths(false); } + if matches.is_present("fit-macro-constant-types") { + builder = builder.fit_macro_constants(true); + } + if matches.is_present("time-phases") { builder = builder.time_phases(true); } diff --git a/tests/expectations/tests/default-macro-constant-type-signed.rs b/tests/expectations/tests/default-macro-constant-type-signed.rs index eda3117d3e..38ebc531b3 100644 --- a/tests/expectations/tests/default-macro-constant-type-signed.rs +++ b/tests/expectations/tests/default-macro-constant-type-signed.rs @@ -10,6 +10,18 @@ pub const N1: i32 = 1; pub const N2: i32 = 2; pub const N_1: i32 = -1; pub const N_2: i32 = -2; +pub const MAX_U16: i32 = 65535; +pub const MAX_I16: i32 = 32767; +pub const MAX_I16_Plus1: i32 = 32768; +pub const MAX_U16_Plus1: i32 = 65536; +pub const MAX_I16_Minus1: i32 = 32766; +pub const MAX_U16_Minus1: i32 = 65534; +pub const MIN_U16: i32 = 0; +pub const MIN_I16: i32 = -32768; +pub const MIN_U16_Plus1: i32 = 1; +pub const MIN_I16_Plus1: i32 = -32767; +pub const MIN_U16_Minus1: i32 = -1; +pub const MIN_I16_Minus1: i32 = -32769; pub const MAX_U32: i64 = 4294967295; pub const MAX_I32: i32 = 2147483647; pub const MAX_I32_Plus1: i64 = 2147483648; diff --git a/tests/expectations/tests/default-macro-constant-type-unsigned.rs b/tests/expectations/tests/default-macro-constant-type-unsigned.rs index 241443aa41..5571563bcd 100644 --- a/tests/expectations/tests/default-macro-constant-type-unsigned.rs +++ b/tests/expectations/tests/default-macro-constant-type-unsigned.rs @@ -10,6 +10,18 @@ pub const N1: u32 = 1; pub const N2: u32 = 2; pub const N_1: i32 = -1; pub const N_2: i32 = -2; +pub const MAX_U16: u32 = 65535; +pub const MAX_I16: u32 = 32767; +pub const MAX_I16_Plus1: u32 = 32768; +pub const MAX_U16_Plus1: u32 = 65536; +pub const MAX_I16_Minus1: u32 = 32766; +pub const MAX_U16_Minus1: u32 = 65534; +pub const MIN_U16: u32 = 0; +pub const MIN_I16: i32 = -32768; +pub const MIN_U16_Plus1: u32 = 1; +pub const MIN_I16_Plus1: i32 = -32767; +pub const MIN_U16_Minus1: i32 = -1; +pub const MIN_I16_Minus1: i32 = -32769; pub const MAX_U32: u32 = 4294967295; pub const MAX_I32: u32 = 2147483647; pub const MAX_I32_Plus1: u32 = 2147483648; diff --git a/tests/expectations/tests/default-macro-constant-type.rs b/tests/expectations/tests/default-macro-constant-type.rs index 241443aa41..5571563bcd 100644 --- a/tests/expectations/tests/default-macro-constant-type.rs +++ b/tests/expectations/tests/default-macro-constant-type.rs @@ -10,6 +10,18 @@ pub const N1: u32 = 1; pub const N2: u32 = 2; pub const N_1: i32 = -1; pub const N_2: i32 = -2; +pub const MAX_U16: u32 = 65535; +pub const MAX_I16: u32 = 32767; +pub const MAX_I16_Plus1: u32 = 32768; +pub const MAX_U16_Plus1: u32 = 65536; +pub const MAX_I16_Minus1: u32 = 32766; +pub const MAX_U16_Minus1: u32 = 65534; +pub const MIN_U16: u32 = 0; +pub const MIN_I16: i32 = -32768; +pub const MIN_U16_Plus1: u32 = 1; +pub const MIN_I16_Plus1: i32 = -32767; +pub const MIN_U16_Minus1: i32 = -1; +pub const MIN_I16_Minus1: i32 = -32769; pub const MAX_U32: u32 = 4294967295; pub const MAX_I32: u32 = 2147483647; pub const MAX_I32_Plus1: u32 = 2147483648; diff --git a/tests/expectations/tests/fit-macro-constant-types.rs b/tests/expectations/tests/fit-macro-constant-types.rs new file mode 100644 index 0000000000..d8d3f207c1 --- /dev/null +++ b/tests/expectations/tests/fit-macro-constant-types.rs @@ -0,0 +1,54 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +pub const N0: u8 = 0; +pub const N1: u8 = 1; +pub const N2: u8 = 2; +pub const N_1: i8 = -1; +pub const N_2: i8 = -2; +pub const MAX_U16: u16 = 65535; +pub const MAX_I16: u16 = 32767; +pub const MAX_I16_Plus1: u16 = 32768; +pub const MAX_U16_Plus1: u32 = 65536; +pub const MAX_I16_Minus1: u16 = 32766; +pub const MAX_U16_Minus1: u16 = 65534; +pub const MIN_U16: u8 = 0; +pub const MIN_I16: i16 = -32768; +pub const MIN_U16_Plus1: u8 = 1; +pub const MIN_I16_Plus1: i16 = -32767; +pub const MIN_U16_Minus1: i8 = -1; +pub const MIN_I16_Minus1: i32 = -32769; +pub const MAX_U32: u32 = 4294967295; +pub const MAX_I32: u32 = 2147483647; +pub const MAX_I32_Plus1: u32 = 2147483648; +pub const MAX_U32_Plus1: u64 = 4294967296; +pub const MAX_I32_Minus1: u32 = 2147483646; +pub const MAX_U32_Minus1: u32 = 4294967294; +pub const MIN_U32: u8 = 0; +pub const MIN_I32: i32 = -2147483648; +pub const MIN_U32_Plus1: u8 = 1; +pub const MIN_I32_Plus1: i32 = -2147483647; +pub const MIN_U32_Minus1: i8 = -1; +pub const MIN_I32_Minus1: i64 = -2147483649; +pub const LONG12: u64 = 123456789012; +pub const LONG_12: i64 = -123456789012; +extern "C" { + pub fn foo( + arg1: ::std::os::raw::c_int, + arg2: ::std::os::raw::c_int, + arg3: ::std::os::raw::c_uint, + arg4: ::std::os::raw::c_char, + arg5: ::std::os::raw::c_uchar, + arg6: ::std::os::raw::c_schar, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn bar( + arg1: ::std::os::raw::c_long, + arg2: ::std::os::raw::c_longlong, + ) -> ::std::os::raw::c_long; +} diff --git a/tests/headers/default-macro-constant-type.h b/tests/headers/default-macro-constant-type.h index d11941b440..a863362c98 100644 --- a/tests/headers/default-macro-constant-type.h +++ b/tests/headers/default-macro-constant-type.h @@ -8,6 +8,24 @@ #define N_1 (-1LL) #define N_2 (-2LL) +#define MAX_U16 0xFFFFULL +#define MAX_I16 (0x8000ULL - 1) + +#define MAX_I16_Plus1 (MAX_I16 + 1) +#define MAX_U16_Plus1 (MAX_U16 + 1) + +#define MAX_I16_Minus1 (MAX_I16 - 1) +#define MAX_U16_Minus1 (MAX_U16 - 1) + +#define MIN_U16 0 +#define MIN_I16 (- (1ULL<<15)) + +#define MIN_U16_Plus1 (MIN_U16 + 1) +#define MIN_I16_Plus1 (MIN_I16 + 1) + +#define MIN_U16_Minus1 (MIN_U16 - 1) +#define MIN_I16_Minus1 (MIN_I16 - 1) + #define MAX_U32 0xFFFFFFFFULL #define MAX_I32 (0x80000000ULL - 1) diff --git a/tests/headers/fit-macro-constant-types.h b/tests/headers/fit-macro-constant-types.h new file mode 100644 index 0000000000..b995bfc0d4 --- /dev/null +++ b/tests/headers/fit-macro-constant-types.h @@ -0,0 +1,4 @@ +// bindgen-flags: --fit-macro-constant-types +// Test fitting macro constants into smaller integer types +// Negative values are i8, i16, i32 or i64; others are u8, u16, u32 or u64. +#include "default-macro-constant-type.h" \ No newline at end of file From 5c821867f237f0248b981da90a7607dfe9e328ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sat, 19 Dec 2020 19:20:27 +0100 Subject: [PATCH 125/942] var: Avoid a bit of duplication with fit_macro_constants. --- src/ir/var.rs | 66 +++++++++++++++++++-------------------------------- 1 file changed, 24 insertions(+), 42 deletions(-) diff --git a/src/ir/var.rs b/src/ir/var.rs index 64f15703c1..49c4f304fb 100644 --- a/src/ir/var.rs +++ b/src/ir/var.rs @@ -118,52 +118,34 @@ impl DotAttributes for Var { } fn default_macro_constant_type(ctx: &BindgenContext, value: i64) -> IntKind { - if ctx.options().fit_macro_constants { - if value < 0 || - ctx.options().default_macro_constant_type == - MacroTypeVariation::Signed + if value < 0 || + ctx.options().default_macro_constant_type == + MacroTypeVariation::Signed + { + if value < i32::min_value() as i64 || value > i32::max_value() as i64 { + IntKind::I64 + } else if !ctx.options().fit_macro_constants || + value < i16::min_value() as i64 || + value > i16::max_value() as i64 { - if value < i32::min_value() as i64 || - value > i32::max_value() as i64 - { - IntKind::I64 - } else if value < i16::min_value() as i64 || - value > i16::max_value() as i64 - { - IntKind::I32 - } else if value < i8::min_value() as i64 || - value > i8::max_value() as i64 - { - IntKind::I16 - } else { - IntKind::I8 - } - } else if value > u32::max_value() as i64 { - IntKind::U64 - } else if value > u16::max_value() as i64 { - IntKind::U32 - } else if value > u8::max_value() as i64 { - IntKind::U16 - } else { - IntKind::U8 - } - } else { - if value < 0 || - ctx.options().default_macro_constant_type == - MacroTypeVariation::Signed + IntKind::I32 + } else if value < i8::min_value() as i64 || + value > i8::max_value() as i64 { - if value < i32::min_value() as i64 || - value > i32::max_value() as i64 - { - IntKind::I64 - } else { - IntKind::I32 - } - } else if value > u32::max_value() as i64 { - IntKind::U64 + IntKind::I16 } else { - IntKind::U32 + IntKind::I8 } + } else if value > u32::max_value() as i64 { + IntKind::U64 + } else if !ctx.options().fit_macro_constants || + value > u16::max_value() as i64 + { + IntKind::U32 + } else if value > u8::max_value() as i64 { + IntKind::U16 + } else { + IntKind::U8 } } From 4ce4b934fdabb8066659a765c13b66eba3fba327 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sat, 19 Dec 2020 19:27:00 +0100 Subject: [PATCH 126/942] tests: Add another fit-macro-constant-types test. --- .../tests/fit-macro-constant-types-signed.rs | 54 +++++++++++++++++++ .../headers/fit-macro-constant-types-signed.h | 2 + 2 files changed, 56 insertions(+) create mode 100644 tests/expectations/tests/fit-macro-constant-types-signed.rs create mode 100644 tests/headers/fit-macro-constant-types-signed.h diff --git a/tests/expectations/tests/fit-macro-constant-types-signed.rs b/tests/expectations/tests/fit-macro-constant-types-signed.rs new file mode 100644 index 0000000000..ccb76b8507 --- /dev/null +++ b/tests/expectations/tests/fit-macro-constant-types-signed.rs @@ -0,0 +1,54 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +pub const N0: i8 = 0; +pub const N1: i8 = 1; +pub const N2: i8 = 2; +pub const N_1: i8 = -1; +pub const N_2: i8 = -2; +pub const MAX_U16: i32 = 65535; +pub const MAX_I16: i16 = 32767; +pub const MAX_I16_Plus1: i32 = 32768; +pub const MAX_U16_Plus1: i32 = 65536; +pub const MAX_I16_Minus1: i16 = 32766; +pub const MAX_U16_Minus1: i32 = 65534; +pub const MIN_U16: i8 = 0; +pub const MIN_I16: i16 = -32768; +pub const MIN_U16_Plus1: i8 = 1; +pub const MIN_I16_Plus1: i16 = -32767; +pub const MIN_U16_Minus1: i8 = -1; +pub const MIN_I16_Minus1: i32 = -32769; +pub const MAX_U32: i64 = 4294967295; +pub const MAX_I32: i32 = 2147483647; +pub const MAX_I32_Plus1: i64 = 2147483648; +pub const MAX_U32_Plus1: i64 = 4294967296; +pub const MAX_I32_Minus1: i32 = 2147483646; +pub const MAX_U32_Minus1: i64 = 4294967294; +pub const MIN_U32: i8 = 0; +pub const MIN_I32: i32 = -2147483648; +pub const MIN_U32_Plus1: i8 = 1; +pub const MIN_I32_Plus1: i32 = -2147483647; +pub const MIN_U32_Minus1: i8 = -1; +pub const MIN_I32_Minus1: i64 = -2147483649; +pub const LONG12: i64 = 123456789012; +pub const LONG_12: i64 = -123456789012; +extern "C" { + pub fn foo( + arg1: ::std::os::raw::c_int, + arg2: ::std::os::raw::c_int, + arg3: ::std::os::raw::c_uint, + arg4: ::std::os::raw::c_char, + arg5: ::std::os::raw::c_uchar, + arg6: ::std::os::raw::c_schar, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn bar( + arg1: ::std::os::raw::c_long, + arg2: ::std::os::raw::c_longlong, + ) -> ::std::os::raw::c_long; +} diff --git a/tests/headers/fit-macro-constant-types-signed.h b/tests/headers/fit-macro-constant-types-signed.h new file mode 100644 index 0000000000..dba20937df --- /dev/null +++ b/tests/headers/fit-macro-constant-types-signed.h @@ -0,0 +1,2 @@ +// bindgen-flags: --default-macro-constant-type=signed --fit-macro-constant-types +#include "default-macro-constant-type.h" From 98841b32ed51e4474377712aa636251d9a4f7215 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 20 Dec 2020 17:31:23 +0100 Subject: [PATCH 127/942] context: Escape the dyn keyword properly. Fixes #1946 --- src/ir/context.rs | 6 +++--- tests/expectations/tests/keywords.rs | 4 ++++ tests/headers/keywords.h | 1 + 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/ir/context.rs b/src/ir/context.rs index 1a54375779..0207547a54 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -807,9 +807,9 @@ If you encounter an error missing from this list, please file an issue or a PR!" match name { "abstract" | "alignof" | "as" | "async" | "become" | "box" | "break" | "const" | "continue" | "crate" | "do" | - "else" | "enum" | "extern" | "false" | "final" | "fn" | - "for" | "if" | "impl" | "in" | "let" | "loop" | "macro" | - "match" | "mod" | "move" | "mut" | "offsetof" | + "dyn" | "else" | "enum" | "extern" | "false" | "final" | + "fn" | "for" | "if" | "impl" | "in" | "let" | "loop" | + "macro" | "match" | "mod" | "move" | "mut" | "offsetof" | "override" | "priv" | "proc" | "pub" | "pure" | "ref" | "return" | "Self" | "self" | "sizeof" | "static" | "struct" | "super" | "trait" | "true" | "type" | "typeof" | diff --git a/tests/expectations/tests/keywords.rs b/tests/expectations/tests/keywords.rs index 129351912e..f77bda0bc2 100644 --- a/tests/expectations/tests/keywords.rs +++ b/tests/expectations/tests/keywords.rs @@ -61,6 +61,10 @@ extern "C" { #[link_name = "\u{1}str"] pub static mut str_: ::std::os::raw::c_int; } +extern "C" { + #[link_name = "\u{1}dyn"] + pub static mut dyn_: ::std::os::raw::c_int; +} extern "C" { #[link_name = "\u{1}as"] pub static mut as_: ::std::os::raw::c_int; diff --git a/tests/headers/keywords.h b/tests/headers/keywords.h index 0e492316bb..78ad278473 100644 --- a/tests/headers/keywords.h +++ b/tests/headers/keywords.h @@ -12,6 +12,7 @@ int usize; int isize; int bool; int str; +int dyn; int as; int box; From 669dc1b628b16da33cc382142c53f6377120a3b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 20 Dec 2020 17:07:40 +0100 Subject: [PATCH 128/942] comp: Fix bitfields to allow underaligned fields after them to take padding space. Fixes #1947. There are two separate issues here: First, the change in comp.rs ensures that we don't round up the amount of storage to the alignment of the bitfield. That generates the "expected" output in #1947 (`__BindgenBitfieldUnit<[u8; 3], u16>`). But that's still not enough to fix that test-case because __BindgenBitfieldUnit would be aligned and have padding, and Rust won't put the extra field in the padding. In order to ensure the bitfield starts at the right alignment, but that Rust can put stuff in the extra field, we need to make a breaking change and split the generated fields in two: One preceding that guarantees alignment, and the actual storage, bit-aligned. This keeps the existing behavior while fixing that test-case. --- bindgen-integration/src/lib.rs | 3 + src/codegen/bitfield_unit.rs | 9 +- src/codegen/bitfield_unit_tests.rs | 49 +-- src/codegen/helpers.rs | 9 +- src/codegen/mod.rs | 15 + src/ir/comp.rs | 2 +- .../tests/bitfield-32bit-overflow.rs | 20 +- tests/expectations/tests/bitfield-large.rs | 33 +- tests/expectations/tests/bitfield-linux-32.rs | 20 +- .../tests/bitfield-method-same-name.rs | 20 +- tests/expectations/tests/bitfield_align.rs | 75 ++-- tests/expectations/tests/bitfield_align_2.rs | 20 +- .../tests/bitfield_method_mangling.rs | 20 +- .../tests/derive-bitfield-method-same-name.rs | 20 +- .../tests/derive-debug-bitfield-core.rs | 20 +- .../tests/derive-debug-bitfield.rs | 20 +- .../tests/derive-partialeq-bitfield.rs | 20 +- .../tests/divide-by-zero-in-struct-layout.rs | 43 +-- .../tests/incomplete-array-padding.rs | 20 +- tests/expectations/tests/issue-1034.rs | 23 +- .../issue-1076-unnamed-bitfield-alignment.rs | 23 +- tests/expectations/tests/issue-1947.rs | 352 ++++++++++++++++++ .../tests/issue-739-pointer-wide-bitfield.rs | 20 +- tests/expectations/tests/issue-816.rs | 20 +- .../expectations/tests/jsval_layout_opaque.rs | 20 +- .../tests/jsval_layout_opaque_1_0.rs | 20 +- tests/expectations/tests/layout_align.rs | 20 +- tests/expectations/tests/layout_eth_conf.rs | 31 +- .../expectations/tests/layout_eth_conf_1_0.rs | 31 +- tests/expectations/tests/layout_mbuf.rs | 31 +- tests/expectations/tests/layout_mbuf_1_0.rs | 31 +- .../libclang-9/incomplete-array-padding.rs | 20 +- .../tests/libclang-9/layout_align.rs | 20 +- tests/expectations/tests/only_bitfields.rs | 20 +- tests/expectations/tests/packed-bitfield.rs | 20 +- .../tests/struct_with_bitfields.rs | 31 +- tests/expectations/tests/timex.rs | 15 +- tests/expectations/tests/union_bitfield.rs | 31 +- .../expectations/tests/union_bitfield_1_0.rs | 37 +- .../tests/union_with_anon_struct_bitfield.rs | 20 +- .../union_with_anon_struct_bitfield_1_0.rs | 20 +- tests/expectations/tests/weird_bitfields.rs | 31 +- tests/headers/issue-1947.h | 9 + 43 files changed, 788 insertions(+), 546 deletions(-) create mode 100644 tests/expectations/tests/issue-1947.rs create mode 100644 tests/headers/issue-1947.h diff --git a/bindgen-integration/src/lib.rs b/bindgen-integration/src/lib.rs index 0468f23773..088e808337 100755 --- a/bindgen-integration/src/lib.rs +++ b/bindgen-integration/src/lib.rs @@ -175,16 +175,19 @@ fn test_bitfields_seventh() { fn test_bitfield_constructors() { use std::mem; let mut first = bindings::bitfields::First { + _bitfield_align_1: [], _bitfield_1: bindings::bitfields::First::new_bitfield_1(1, 2, 3), }; assert!(unsafe { first.assert(1, 2, 3) }); let mut second = bindings::bitfields::Second { + _bitfield_align_1: [], _bitfield_1: bindings::bitfields::Second::new_bitfield_1(1337, true), }; assert!(unsafe { second.assert(1337, true) }); let mut third = bindings::bitfields::Third { + _bitfield_align_1: [], _bitfield_1: bindings::bitfields::Third::new_bitfield_1( 42, false, diff --git a/src/codegen/bitfield_unit.rs b/src/codegen/bitfield_unit.rs index a5a8ac77d4..73ec2bd629 100755 --- a/src/codegen/bitfield_unit.rs +++ b/src/codegen/bitfield_unit.rs @@ -1,18 +1,17 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit { +pub struct __BindgenBitfieldUnit { storage: Storage, - align: [Align; 0], } -impl __BindgenBitfieldUnit { +impl __BindgenBitfieldUnit { #[inline] pub const fn new(storage: Storage) -> Self { - Self { storage, align: [] } + Self { storage } } } -impl __BindgenBitfieldUnit +impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, { diff --git a/src/codegen/bitfield_unit_tests.rs b/src/codegen/bitfield_unit_tests.rs index 3a9239c2c8..e143e4ea78 100644 --- a/src/codegen/bitfield_unit_tests.rs +++ b/src/codegen/bitfield_unit_tests.rs @@ -22,12 +22,10 @@ //! ``` use super::bitfield_unit::__BindgenBitfieldUnit; -use std::mem; #[test] fn bitfield_unit_get_bit() { - let unit = - __BindgenBitfieldUnit::<[u8; 2], u64>::new([0b10011101, 0b00011101]); + let unit = __BindgenBitfieldUnit::<[u8; 2]>::new([0b10011101, 0b00011101]); let mut bits = vec![]; for i in 0..16 { @@ -50,7 +48,7 @@ fn bitfield_unit_get_bit() { #[test] fn bitfield_unit_set_bit() { let mut unit = - __BindgenBitfieldUnit::<[u8; 2], u64>::new([0b00000000, 0b00000000]); + __BindgenBitfieldUnit::<[u8; 2]>::new([0b00000000, 0b00000000]); for i in 0..16 { if i % 3 == 0 { @@ -63,7 +61,7 @@ fn bitfield_unit_set_bit() { } let mut unit = - __BindgenBitfieldUnit::<[u8; 2], u64>::new([0b11111111, 0b11111111]); + __BindgenBitfieldUnit::<[u8; 2]>::new([0b11111111, 0b11111111]); for i in 0..16 { if i % 3 == 0 { @@ -76,43 +74,6 @@ fn bitfield_unit_set_bit() { } } -#[test] -fn bitfield_unit_align() { - assert_eq!( - mem::align_of::<__BindgenBitfieldUnit<[u8; 1], u8>>(), - mem::align_of::() - ); - assert_eq!( - mem::align_of::<__BindgenBitfieldUnit<[u8; 1], u16>>(), - mem::align_of::() - ); - assert_eq!( - mem::align_of::<__BindgenBitfieldUnit<[u8; 1], u32>>(), - mem::align_of::() - ); - assert_eq!( - mem::align_of::<__BindgenBitfieldUnit<[u8; 1], u64>>(), - mem::align_of::() - ); - - assert_eq!( - mem::align_of::<__BindgenBitfieldUnit<[u8; 8], u8>>(), - mem::align_of::() - ); - assert_eq!( - mem::align_of::<__BindgenBitfieldUnit<[u8; 8], u16>>(), - mem::align_of::() - ); - assert_eq!( - mem::align_of::<__BindgenBitfieldUnit<[u8; 8], u32>>(), - mem::align_of::() - ); - assert_eq!( - mem::align_of::<__BindgenBitfieldUnit<[u8; 8], u64>>(), - mem::align_of::() - ); -} - macro_rules! bitfield_unit_get { ( $( @@ -123,7 +84,7 @@ macro_rules! bitfield_unit_get { fn bitfield_unit_get() { $({ let expected = $expected; - let unit = __BindgenBitfieldUnit::<_, u64>::new($storage); + let unit = __BindgenBitfieldUnit::<_>::new($storage); let actual = unit.get($start, $len); println!(); @@ -223,7 +184,7 @@ macro_rules! bitfield_unit_set { #[test] fn bitfield_unit_set() { $( - let mut unit = __BindgenBitfieldUnit::<[u8; 4], u64>::new([0, 0, 0, 0]); + let mut unit = __BindgenBitfieldUnit::<[u8; 4]>::new([0, 0, 0, 0]); unit.set($start, $len, $val); let actual = unit.get(0, 32); diff --git a/src/codegen/helpers.rs b/src/codegen/helpers.rs index b6825f5ed0..205995bc8e 100644 --- a/src/codegen/helpers.rs +++ b/src/codegen/helpers.rs @@ -120,16 +120,9 @@ pub fn bitfield_unit(ctx: &BindgenContext, layout: Layout) -> TokenStream { tokens.append_all(quote! { root:: }); } - let align = match layout.align { - n if n >= 8 => quote! { u64 }, - 4 => quote! { u32 }, - 2 => quote! { u16 }, - _ => quote! { u8 }, - }; - let size = layout.size; tokens.append_all(quote! { - __BindgenBitfieldUnit<[u8; #size], #align> + __BindgenBitfieldUnit<[u8; #size]> }); tokens diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 0d93c49193..194a461c63 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -1437,6 +1437,21 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit { } }; + { + let align_field_name = format!("_bitfield_align_{}", self.nth()); + let align_field_ident = ctx.rust_ident(&align_field_name); + let align_ty = match self.layout().align { + n if n >= 8 => quote! { u64 }, + 4 => quote! { u32 }, + 2 => quote! { u16 }, + _ => quote! { u8 }, + }; + let align_field = quote! { + pub #align_field_ident: [#align_ty; 0], + }; + fields.extend(Some(align_field)); + } + let unit_field_name = format!("_bitfield_{}", self.nth()); let unit_field_ident = ctx.rust_ident(&unit_field_name); diff --git a/src/ir/comp.rs b/src/ir/comp.rs index 645f6251da..a0ca925c20 100644 --- a/src/ir/comp.rs +++ b/src/ir/comp.rs @@ -575,7 +575,7 @@ where } else { bytes_from_bits_pow2(unit_align_in_bits) }; - let size = align_to(unit_size_in_bits, align * 8) / 8; + let size = align_to(unit_size_in_bits, 8) / 8; let layout = Layout::new(size, align); fields.extend(Some(Field::Bitfields(BitfieldUnit { nth: *bitfield_unit_count, diff --git a/tests/expectations/tests/bitfield-32bit-overflow.rs b/tests/expectations/tests/bitfield-32bit-overflow.rs index cd2fd177c6..680b25d8fd 100644 --- a/tests/expectations/tests/bitfield-32bit-overflow.rs +++ b/tests/expectations/tests/bitfield-32bit-overflow.rs @@ -7,17 +7,16 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit { +pub struct __BindgenBitfieldUnit { storage: Storage, - align: [Align; 0], } -impl __BindgenBitfieldUnit { +impl __BindgenBitfieldUnit { #[inline] pub const fn new(storage: Storage) -> Self { - Self { storage, align: [] } + Self { storage } } } -impl __BindgenBitfieldUnit +impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, { @@ -95,7 +94,8 @@ where #[repr(C, packed)] #[derive(Debug, Default, Copy, Clone)] pub struct MuchBitfield { - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 5usize], u8>, + pub _bitfield_align_1: [u8; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 5usize]>, } #[test] fn bindgen_test_layout_MuchBitfield() { @@ -575,11 +575,9 @@ impl MuchBitfield { m30: ::std::os::raw::c_char, m31: ::std::os::raw::c_char, m32: ::std::os::raw::c_char, - ) -> __BindgenBitfieldUnit<[u8; 5usize], u8> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 5usize], - u8, - > = Default::default(); + ) -> __BindgenBitfieldUnit<[u8; 5usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 5usize]> = + Default::default(); __bindgen_bitfield_unit.set(0usize, 1u8, { let m0: u8 = unsafe { ::std::mem::transmute(m0) }; m0 as u64 diff --git a/tests/expectations/tests/bitfield-large.rs b/tests/expectations/tests/bitfield-large.rs index a29bd4c820..b2c353a221 100644 --- a/tests/expectations/tests/bitfield-large.rs +++ b/tests/expectations/tests/bitfield-large.rs @@ -7,17 +7,16 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit { +pub struct __BindgenBitfieldUnit { storage: Storage, - align: [Align; 0], } -impl __BindgenBitfieldUnit { +impl __BindgenBitfieldUnit { #[inline] pub const fn new(storage: Storage) -> Self { - Self { storage, align: [] } + Self { storage } } } -impl __BindgenBitfieldUnit +impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, { @@ -96,7 +95,8 @@ where #[repr(align(16))] #[derive(Debug, Default, Copy, Clone)] pub struct HasBigBitfield { - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 16usize], u64>, + pub _bitfield_align_1: [u64; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 16usize]>, } #[test] fn bindgen_test_layout_HasBigBitfield() { @@ -126,13 +126,9 @@ impl HasBigBitfield { } } #[inline] - pub fn new_bitfield_1( - x: i128, - ) -> __BindgenBitfieldUnit<[u8; 16usize], u64> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 16usize], - u64, - > = Default::default(); + pub fn new_bitfield_1(x: i128) -> __BindgenBitfieldUnit<[u8; 16usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 16usize]> = + Default::default(); __bindgen_bitfield_unit.set(0usize, 128u8, { let x: u128 = unsafe { ::std::mem::transmute(x) }; x as u64 @@ -144,7 +140,8 @@ impl HasBigBitfield { #[repr(align(16))] #[derive(Debug, Default, Copy, Clone)] pub struct HasTwoBigBitfields { - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 16usize], u64>, + pub _bitfield_align_1: [u64; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 16usize]>, } #[test] fn bindgen_test_layout_HasTwoBigBitfields() { @@ -190,11 +187,9 @@ impl HasTwoBigBitfields { pub fn new_bitfield_1( x: i128, y: i128, - ) -> __BindgenBitfieldUnit<[u8; 16usize], u64> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 16usize], - u64, - > = Default::default(); + ) -> __BindgenBitfieldUnit<[u8; 16usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 16usize]> = + Default::default(); __bindgen_bitfield_unit.set(0usize, 80u8, { let x: u128 = unsafe { ::std::mem::transmute(x) }; x as u64 diff --git a/tests/expectations/tests/bitfield-linux-32.rs b/tests/expectations/tests/bitfield-linux-32.rs index bd2b391706..15c35cee8d 100644 --- a/tests/expectations/tests/bitfield-linux-32.rs +++ b/tests/expectations/tests/bitfield-linux-32.rs @@ -7,17 +7,16 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit { +pub struct __BindgenBitfieldUnit { storage: Storage, - align: [Align; 0], } -impl __BindgenBitfieldUnit { +impl __BindgenBitfieldUnit { #[inline] pub const fn new(storage: Storage) -> Self { - Self { storage, align: [] } + Self { storage } } } -impl __BindgenBitfieldUnit +impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, { @@ -96,7 +95,8 @@ where #[derive(Debug, Default, Copy, Clone)] pub struct Test { pub foo: u64, - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 8usize], u64>, + pub _bitfield_align_1: [u64; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 8usize]>, } #[test] fn bindgen_test_layout_Test() { @@ -147,11 +147,9 @@ impl Test { pub fn new_bitfield_1( x: u64, y: u64, - ) -> __BindgenBitfieldUnit<[u8; 8usize], u64> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 8usize], - u64, - > = Default::default(); + ) -> __BindgenBitfieldUnit<[u8; 8usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 8usize]> = + Default::default(); __bindgen_bitfield_unit.set(0usize, 56u8, { let x: u64 = unsafe { ::std::mem::transmute(x) }; x as u64 diff --git a/tests/expectations/tests/bitfield-method-same-name.rs b/tests/expectations/tests/bitfield-method-same-name.rs index fc2681e8a7..e9c1a76d1c 100644 --- a/tests/expectations/tests/bitfield-method-same-name.rs +++ b/tests/expectations/tests/bitfield-method-same-name.rs @@ -7,17 +7,16 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit { +pub struct __BindgenBitfieldUnit { storage: Storage, - align: [Align; 0], } -impl __BindgenBitfieldUnit { +impl __BindgenBitfieldUnit { #[inline] pub const fn new(storage: Storage) -> Self { - Self { storage, align: [] } + Self { storage } } } -impl __BindgenBitfieldUnit +impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, { @@ -95,7 +94,8 @@ where #[repr(C, packed)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize], u8>, + pub _bitfield_align_1: [u8; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, } #[test] fn bindgen_test_layout_Foo() { @@ -139,11 +139,9 @@ impl Foo { #[inline] pub fn new_bitfield_1( type__bindgen_bitfield: ::std::os::raw::c_char, - ) -> __BindgenBitfieldUnit<[u8; 1usize], u8> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 1usize], - u8, - > = Default::default(); + ) -> __BindgenBitfieldUnit<[u8; 1usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = + Default::default(); __bindgen_bitfield_unit.set(0usize, 3u8, { let type__bindgen_bitfield: u8 = unsafe { ::std::mem::transmute(type__bindgen_bitfield) }; diff --git a/tests/expectations/tests/bitfield_align.rs b/tests/expectations/tests/bitfield_align.rs index 57f726efde..509981a887 100644 --- a/tests/expectations/tests/bitfield_align.rs +++ b/tests/expectations/tests/bitfield_align.rs @@ -7,17 +7,16 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit { +pub struct __BindgenBitfieldUnit { storage: Storage, - align: [Align; 0], } -impl __BindgenBitfieldUnit { +impl __BindgenBitfieldUnit { #[inline] pub const fn new(storage: Storage) -> Self { - Self { storage, align: [] } + Self { storage } } } -impl __BindgenBitfieldUnit +impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, { @@ -97,7 +96,8 @@ where #[derive(Debug, Default, Copy, Clone)] pub struct A { pub x: ::std::os::raw::c_uchar, - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 2usize], u8>, + pub _bitfield_align_1: [u8; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 2usize]>, pub y: ::std::os::raw::c_uchar, } #[test] @@ -266,11 +266,9 @@ impl A { b8: ::std::os::raw::c_uint, b9: ::std::os::raw::c_uint, b10: ::std::os::raw::c_uint, - ) -> __BindgenBitfieldUnit<[u8; 2usize], u8> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 2usize], - u8, - > = Default::default(); + ) -> __BindgenBitfieldUnit<[u8; 2usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 2usize]> = + Default::default(); __bindgen_bitfield_unit.set(0usize, 1u8, { let b1: u32 = unsafe { ::std::mem::transmute(b1) }; b1 as u64 @@ -318,7 +316,8 @@ impl A { #[repr(align(4))] #[derive(Debug, Default, Copy, Clone)] pub struct B { - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize], u32>, + pub _bitfield_align_1: [u32; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, } #[test] fn bindgen_test_layout_B() { @@ -364,11 +363,9 @@ impl B { pub fn new_bitfield_1( foo: ::std::os::raw::c_uint, bar: ::std::os::raw::c_uchar, - ) -> __BindgenBitfieldUnit<[u8; 4usize], u32> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 4usize], - u32, - > = Default::default(); + ) -> __BindgenBitfieldUnit<[u8; 4usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = + Default::default(); __bindgen_bitfield_unit.set(0usize, 31u8, { let foo: u32 = unsafe { ::std::mem::transmute(foo) }; foo as u64 @@ -384,7 +381,8 @@ impl B { #[derive(Debug, Default, Copy, Clone)] pub struct C { pub x: ::std::os::raw::c_uchar, - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize], u8>, + pub _bitfield_align_1: [u8; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub baz: ::std::os::raw::c_uint, } #[test] @@ -441,11 +439,9 @@ impl C { pub fn new_bitfield_1( b1: ::std::os::raw::c_uint, b2: ::std::os::raw::c_uint, - ) -> __BindgenBitfieldUnit<[u8; 1usize], u8> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 1usize], - u8, - > = Default::default(); + ) -> __BindgenBitfieldUnit<[u8; 1usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = + Default::default(); __bindgen_bitfield_unit.set(0usize, 1u8, { let b1: u32 = unsafe { ::std::mem::transmute(b1) }; b1 as u64 @@ -461,7 +457,8 @@ impl C { #[repr(align(2))] #[derive(Debug, Default, Copy, Clone)] pub struct Date1 { - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 3usize], u8>, + pub _bitfield_align_1: [u8; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 3usize]>, pub __bindgen_padding_0: u8, } #[test] @@ -536,11 +533,9 @@ impl Date1 { nMonthDay: ::std::os::raw::c_ushort, nMonth: ::std::os::raw::c_ushort, nYear: ::std::os::raw::c_ushort, - ) -> __BindgenBitfieldUnit<[u8; 3usize], u8> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 3usize], - u8, - > = Default::default(); + ) -> __BindgenBitfieldUnit<[u8; 3usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 3usize]> = + Default::default(); __bindgen_bitfield_unit.set(0usize, 3u8, { let nWeekDay: u16 = unsafe { ::std::mem::transmute(nWeekDay) }; nWeekDay as u64 @@ -564,7 +559,8 @@ impl Date1 { #[repr(align(2))] #[derive(Debug, Default, Copy, Clone)] pub struct Date2 { - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize], u8>, + pub _bitfield_align_1: [u8; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, } #[test] fn bindgen_test_layout_Date2() { @@ -652,11 +648,9 @@ impl Date2 { nMonth: ::std::os::raw::c_ushort, nYear: ::std::os::raw::c_ushort, byte: ::std::os::raw::c_uchar, - ) -> __BindgenBitfieldUnit<[u8; 4usize], u8> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 4usize], - u8, - > = Default::default(); + ) -> __BindgenBitfieldUnit<[u8; 4usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = + Default::default(); __bindgen_bitfield_unit.set(0usize, 3u8, { let nWeekDay: u16 = unsafe { ::std::mem::transmute(nWeekDay) }; nWeekDay as u64 @@ -684,7 +678,8 @@ impl Date2 { #[repr(align(2))] #[derive(Debug, Default, Copy, Clone)] pub struct Date3 { - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 3usize], u8>, + pub _bitfield_align_1: [u8; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 3usize]>, pub byte: ::std::os::raw::c_uchar, } #[test] @@ -769,11 +764,9 @@ impl Date3 { nMonthDay: ::std::os::raw::c_ushort, nMonth: ::std::os::raw::c_ushort, nYear: ::std::os::raw::c_ushort, - ) -> __BindgenBitfieldUnit<[u8; 3usize], u8> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 3usize], - u8, - > = Default::default(); + ) -> __BindgenBitfieldUnit<[u8; 3usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 3usize]> = + Default::default(); __bindgen_bitfield_unit.set(0usize, 3u8, { let nWeekDay: u16 = unsafe { ::std::mem::transmute(nWeekDay) }; nWeekDay as u64 diff --git a/tests/expectations/tests/bitfield_align_2.rs b/tests/expectations/tests/bitfield_align_2.rs index 5602555b09..f4f0c98a70 100644 --- a/tests/expectations/tests/bitfield_align_2.rs +++ b/tests/expectations/tests/bitfield_align_2.rs @@ -7,17 +7,16 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit { +pub struct __BindgenBitfieldUnit { storage: Storage, - align: [Align; 0], } -impl __BindgenBitfieldUnit { +impl __BindgenBitfieldUnit { #[inline] pub const fn new(storage: Storage) -> Self { - Self { storage, align: [] } + Self { storage } } } -impl __BindgenBitfieldUnit +impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, { @@ -104,7 +103,8 @@ pub enum MyEnum { #[repr(align(8))] #[derive(Debug, Copy, Clone)] pub struct TaggedPtr { - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 8usize], u64>, + pub _bitfield_align_1: [u64; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 8usize]>, } #[test] fn bindgen_test_layout_TaggedPtr() { @@ -155,11 +155,9 @@ impl TaggedPtr { pub fn new_bitfield_1( tag: MyEnum, ptr: ::std::os::raw::c_long, - ) -> __BindgenBitfieldUnit<[u8; 8usize], u64> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 8usize], - u64, - > = Default::default(); + ) -> __BindgenBitfieldUnit<[u8; 8usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 8usize]> = + Default::default(); __bindgen_bitfield_unit.set(0usize, 2u8, { let tag: u32 = unsafe { ::std::mem::transmute(tag) }; tag as u64 diff --git a/tests/expectations/tests/bitfield_method_mangling.rs b/tests/expectations/tests/bitfield_method_mangling.rs index 584b7cc15f..42fa3c4cb4 100644 --- a/tests/expectations/tests/bitfield_method_mangling.rs +++ b/tests/expectations/tests/bitfield_method_mangling.rs @@ -7,17 +7,16 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit { +pub struct __BindgenBitfieldUnit { storage: Storage, - align: [Align; 0], } -impl __BindgenBitfieldUnit { +impl __BindgenBitfieldUnit { #[inline] pub const fn new(storage: Storage) -> Self { - Self { storage, align: [] } + Self { storage } } } -impl __BindgenBitfieldUnit +impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, { @@ -96,7 +95,8 @@ where #[repr(align(4))] #[derive(Debug, Default, Copy, Clone)] pub struct mach_msg_type_descriptor_t { - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize], u32>, + pub _bitfield_align_1: [u32; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, } #[test] fn bindgen_test_layout_mach_msg_type_descriptor_t() { @@ -142,11 +142,9 @@ impl mach_msg_type_descriptor_t { pub fn new_bitfield_1( pad3: ::std::os::raw::c_uint, type_: ::std::os::raw::c_uint, - ) -> __BindgenBitfieldUnit<[u8; 4usize], u32> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 4usize], - u32, - > = Default::default(); + ) -> __BindgenBitfieldUnit<[u8; 4usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = + Default::default(); __bindgen_bitfield_unit.set(0usize, 24u8, { let pad3: u32 = unsafe { ::std::mem::transmute(pad3) }; pad3 as u64 diff --git a/tests/expectations/tests/derive-bitfield-method-same-name.rs b/tests/expectations/tests/derive-bitfield-method-same-name.rs index c804b54193..d1c1aefa79 100644 --- a/tests/expectations/tests/derive-bitfield-method-same-name.rs +++ b/tests/expectations/tests/derive-bitfield-method-same-name.rs @@ -7,17 +7,16 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit { +pub struct __BindgenBitfieldUnit { storage: Storage, - align: [Align; 0], } -impl __BindgenBitfieldUnit { +impl __BindgenBitfieldUnit { #[inline] pub const fn new(storage: Storage) -> Self { - Self { storage, align: [] } + Self { storage } } } -impl __BindgenBitfieldUnit +impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, { @@ -99,7 +98,8 @@ where #[derive(Copy, Clone)] pub struct Foo { pub large: [::std::os::raw::c_int; 33usize], - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 2usize], u8>, + pub _bitfield_align_1: [u8; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 2usize]>, pub __bindgen_padding_0: u16, } #[test] @@ -183,11 +183,9 @@ impl Foo { #[inline] pub fn new_bitfield_1( type__bindgen_bitfield: ::std::os::raw::c_char, - ) -> __BindgenBitfieldUnit<[u8; 2usize], u8> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 2usize], - u8, - > = Default::default(); + ) -> __BindgenBitfieldUnit<[u8; 2usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 2usize]> = + Default::default(); __bindgen_bitfield_unit.set(0usize, 3u8, { let type__bindgen_bitfield: u8 = unsafe { ::std::mem::transmute(type__bindgen_bitfield) }; diff --git a/tests/expectations/tests/derive-debug-bitfield-core.rs b/tests/expectations/tests/derive-debug-bitfield-core.rs index 690078b20b..76fa20bab8 100644 --- a/tests/expectations/tests/derive-debug-bitfield-core.rs +++ b/tests/expectations/tests/derive-debug-bitfield-core.rs @@ -9,17 +9,16 @@ extern crate core; #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit { +pub struct __BindgenBitfieldUnit { storage: Storage, - align: [Align; 0], } -impl __BindgenBitfieldUnit { +impl __BindgenBitfieldUnit { #[inline] pub const fn new(storage: Storage) -> Self { - Self { storage, align: [] } + Self { storage } } } -impl __BindgenBitfieldUnit +impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, { @@ -97,7 +96,8 @@ where #[repr(C)] #[derive(Copy, Clone)] pub struct C { - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize], u8>, + pub _bitfield_align_1: [u8; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub large_array: [::std::os::raw::c_int; 50usize], } #[test] @@ -171,11 +171,9 @@ impl C { pub fn new_bitfield_1( a: bool, b: bool, - ) -> __BindgenBitfieldUnit<[u8; 1usize], u8> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 1usize], - u8, - > = Default::default(); + ) -> __BindgenBitfieldUnit<[u8; 1usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = + Default::default(); __bindgen_bitfield_unit.set(0usize, 1u8, { let a: u8 = unsafe { ::core::mem::transmute(a) }; a as u64 diff --git a/tests/expectations/tests/derive-debug-bitfield.rs b/tests/expectations/tests/derive-debug-bitfield.rs index 2474ec9ff7..d07642a83a 100644 --- a/tests/expectations/tests/derive-debug-bitfield.rs +++ b/tests/expectations/tests/derive-debug-bitfield.rs @@ -7,17 +7,16 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit { +pub struct __BindgenBitfieldUnit { storage: Storage, - align: [Align; 0], } -impl __BindgenBitfieldUnit { +impl __BindgenBitfieldUnit { #[inline] pub const fn new(storage: Storage) -> Self { - Self { storage, align: [] } + Self { storage } } } -impl __BindgenBitfieldUnit +impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, { @@ -95,7 +94,8 @@ where #[repr(C)] #[derive(Copy, Clone)] pub struct C { - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize], u8>, + pub _bitfield_align_1: [u8; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub large_array: [::std::os::raw::c_int; 50usize], } #[test] @@ -178,11 +178,9 @@ impl C { pub fn new_bitfield_1( a: bool, b: bool, - ) -> __BindgenBitfieldUnit<[u8; 1usize], u8> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 1usize], - u8, - > = Default::default(); + ) -> __BindgenBitfieldUnit<[u8; 1usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = + Default::default(); __bindgen_bitfield_unit.set(0usize, 1u8, { let a: u8 = unsafe { ::std::mem::transmute(a) }; a as u64 diff --git a/tests/expectations/tests/derive-partialeq-bitfield.rs b/tests/expectations/tests/derive-partialeq-bitfield.rs index 9896011f9a..c7f1231ef8 100644 --- a/tests/expectations/tests/derive-partialeq-bitfield.rs +++ b/tests/expectations/tests/derive-partialeq-bitfield.rs @@ -7,17 +7,16 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit { +pub struct __BindgenBitfieldUnit { storage: Storage, - align: [Align; 0], } -impl __BindgenBitfieldUnit { +impl __BindgenBitfieldUnit { #[inline] pub const fn new(storage: Storage) -> Self { - Self { storage, align: [] } + Self { storage } } } -impl __BindgenBitfieldUnit +impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, { @@ -95,7 +94,8 @@ where #[repr(C)] #[derive(Copy, Clone)] pub struct C { - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize], u8>, + pub _bitfield_align_1: [u8; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub large_array: [::std::os::raw::c_int; 50usize], } #[test] @@ -166,11 +166,9 @@ impl C { pub fn new_bitfield_1( a: bool, b: bool, - ) -> __BindgenBitfieldUnit<[u8; 1usize], u8> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 1usize], - u8, - > = Default::default(); + ) -> __BindgenBitfieldUnit<[u8; 1usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = + Default::default(); __bindgen_bitfield_unit.set(0usize, 1u8, { let a: u8 = unsafe { ::std::mem::transmute(a) }; a as u64 diff --git a/tests/expectations/tests/divide-by-zero-in-struct-layout.rs b/tests/expectations/tests/divide-by-zero-in-struct-layout.rs index 1484719b9c..721d71e259 100644 --- a/tests/expectations/tests/divide-by-zero-in-struct-layout.rs +++ b/tests/expectations/tests/divide-by-zero-in-struct-layout.rs @@ -7,17 +7,16 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit { +pub struct __BindgenBitfieldUnit { storage: Storage, - align: [Align; 0], } -impl __BindgenBitfieldUnit { +impl __BindgenBitfieldUnit { #[inline] pub const fn new(storage: Storage) -> Self { - Self { storage, align: [] } + Self { storage } } } -impl __BindgenBitfieldUnit +impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, { @@ -95,49 +94,45 @@ where #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct WithBitfield { - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 0usize], u8>, - pub __bindgen_padding_0: u32, + pub _bitfield_align_1: [u8; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub a: ::std::os::raw::c_uint, } impl WithBitfield { #[inline] - pub fn new_bitfield_1() -> __BindgenBitfieldUnit<[u8; 0usize], u8> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 0usize], - u8, - > = Default::default(); + pub fn new_bitfield_1() -> __BindgenBitfieldUnit<[u8; 1usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = + Default::default(); __bindgen_bitfield_unit } } #[repr(C, packed)] #[derive(Debug, Default, Copy, Clone)] pub struct WithBitfieldAndAttrPacked { - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize], u8>, + pub _bitfield_align_1: [u8; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub a: ::std::os::raw::c_uint, } impl WithBitfieldAndAttrPacked { #[inline] - pub fn new_bitfield_1() -> __BindgenBitfieldUnit<[u8; 1usize], u8> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 1usize], - u8, - > = Default::default(); + pub fn new_bitfield_1() -> __BindgenBitfieldUnit<[u8; 1usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = + Default::default(); __bindgen_bitfield_unit } } #[repr(C, packed)] #[derive(Debug, Default, Copy, Clone)] pub struct WithBitfieldAndPacked { - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 0usize], u8>, + pub _bitfield_align_1: [u8; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub a: ::std::os::raw::c_uint, } impl WithBitfieldAndPacked { #[inline] - pub fn new_bitfield_1() -> __BindgenBitfieldUnit<[u8; 0usize], u8> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 0usize], - u8, - > = Default::default(); + pub fn new_bitfield_1() -> __BindgenBitfieldUnit<[u8; 1usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = + Default::default(); __bindgen_bitfield_unit } } diff --git a/tests/expectations/tests/incomplete-array-padding.rs b/tests/expectations/tests/incomplete-array-padding.rs index 36e523b5e1..a0fa750c6a 100644 --- a/tests/expectations/tests/incomplete-array-padding.rs +++ b/tests/expectations/tests/incomplete-array-padding.rs @@ -7,17 +7,16 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit { +pub struct __BindgenBitfieldUnit { storage: Storage, - align: [Align; 0], } -impl __BindgenBitfieldUnit { +impl __BindgenBitfieldUnit { #[inline] pub const fn new(storage: Storage) -> Self { - Self { storage, align: [] } + Self { storage } } } -impl __BindgenBitfieldUnit +impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, { @@ -125,7 +124,8 @@ impl ::std::fmt::Debug for __IncompleteArrayField { #[repr(C)] #[derive(Debug)] pub struct foo { - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize], u8>, + pub _bitfield_align_1: [u8; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub b: __IncompleteArrayField<*mut ::std::os::raw::c_void>, } #[test] @@ -163,11 +163,9 @@ impl foo { #[inline] pub fn new_bitfield_1( a: ::std::os::raw::c_char, - ) -> __BindgenBitfieldUnit<[u8; 1usize], u8> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 1usize], - u8, - > = Default::default(); + ) -> __BindgenBitfieldUnit<[u8; 1usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = + Default::default(); __bindgen_bitfield_unit.set(0usize, 1u8, { let a: u8 = unsafe { ::std::mem::transmute(a) }; a as u64 diff --git a/tests/expectations/tests/issue-1034.rs b/tests/expectations/tests/issue-1034.rs index ef122ec0bc..32f4310e49 100644 --- a/tests/expectations/tests/issue-1034.rs +++ b/tests/expectations/tests/issue-1034.rs @@ -7,17 +7,16 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit { +pub struct __BindgenBitfieldUnit { storage: Storage, - align: [Align; 0], } -impl __BindgenBitfieldUnit { +impl __BindgenBitfieldUnit { #[inline] pub const fn new(storage: Storage) -> Self { - Self { storage, align: [] } + Self { storage } } } -impl __BindgenBitfieldUnit +impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, { @@ -92,11 +91,11 @@ where } } } -#[repr(C)] +#[repr(C, packed)] #[derive(Debug, Default, Copy, Clone)] pub struct S2 { - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize], u8>, - pub __bindgen_padding_0: u8, + pub _bitfield_align_1: [u8; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 2usize]>, } #[test] fn bindgen_test_layout_S2() { @@ -113,11 +112,9 @@ fn bindgen_test_layout_S2() { } impl S2 { #[inline] - pub fn new_bitfield_1() -> __BindgenBitfieldUnit<[u8; 1usize], u8> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 1usize], - u8, - > = Default::default(); + pub fn new_bitfield_1() -> __BindgenBitfieldUnit<[u8; 2usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 2usize]> = + Default::default(); __bindgen_bitfield_unit } } diff --git a/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs b/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs index 9ac4f2fe8b..d91dd8fa5c 100644 --- a/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs +++ b/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs @@ -7,17 +7,16 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit { +pub struct __BindgenBitfieldUnit { storage: Storage, - align: [Align; 0], } -impl __BindgenBitfieldUnit { +impl __BindgenBitfieldUnit { #[inline] pub const fn new(storage: Storage) -> Self { - Self { storage, align: [] } + Self { storage } } } -impl __BindgenBitfieldUnit +impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, { @@ -92,11 +91,11 @@ where } } } -#[repr(C)] +#[repr(C, packed)] #[derive(Debug, Default, Copy, Clone)] pub struct S1 { - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 2usize], u8>, - pub __bindgen_padding_0: u8, + pub _bitfield_align_1: [u8; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 3usize]>, } #[test] fn bindgen_test_layout_S1() { @@ -113,11 +112,9 @@ fn bindgen_test_layout_S1() { } impl S1 { #[inline] - pub fn new_bitfield_1() -> __BindgenBitfieldUnit<[u8; 2usize], u8> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 2usize], - u8, - > = Default::default(); + pub fn new_bitfield_1() -> __BindgenBitfieldUnit<[u8; 3usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 3usize]> = + Default::default(); __bindgen_bitfield_unit } } diff --git a/tests/expectations/tests/issue-1947.rs b/tests/expectations/tests/issue-1947.rs new file mode 100644 index 0000000000..1753ef8d02 --- /dev/null +++ b/tests/expectations/tests/issue-1947.rs @@ -0,0 +1,352 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[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] + 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]; + 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 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]; + 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 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 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); + } + } +} +pub type U8 = ::std::os::raw::c_uchar; +pub type U16 = ::std::os::raw::c_ushort; +#[repr(C)] +#[repr(align(2))] +#[derive(Debug, Default, Copy, Clone)] +pub struct V56AMDY { + pub _bitfield_align_1: [u16; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 2usize]>, + pub MADK: U8, + pub MABR: U8, + pub _bitfield_align_2: [u16; 0], + pub _bitfield_2: __BindgenBitfieldUnit<[u8; 3usize]>, + pub _rB_: U8, +} +#[test] +fn bindgen_test_layout_V56AMDY() { + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(V56AMDY)) + ); + assert_eq!( + ::std::mem::align_of::(), + 2usize, + concat!("Alignment of ", stringify!(V56AMDY)) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).MADK as *const _ as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(V56AMDY), + "::", + stringify!(MADK) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).MABR as *const _ as usize + }, + 3usize, + concat!( + "Offset of field: ", + stringify!(V56AMDY), + "::", + stringify!(MABR) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::()))._rB_ as *const _ as usize + }, + 7usize, + concat!( + "Offset of field: ", + stringify!(V56AMDY), + "::", + stringify!(_rB_) + ) + ); +} +impl V56AMDY { + #[inline] + pub fn MADZ(&self) -> U16 { + unsafe { + ::std::mem::transmute(self._bitfield_1.get(0usize, 10u8) as u16) + } + } + #[inline] + pub fn set_MADZ(&mut self, val: U16) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + self._bitfield_1.set(0usize, 10u8, val as u64) + } + } + #[inline] + pub fn MAI0(&self) -> U16 { + unsafe { + ::std::mem::transmute(self._bitfield_1.get(10usize, 2u8) as u16) + } + } + #[inline] + pub fn set_MAI0(&mut self, val: U16) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + self._bitfield_1.set(10usize, 2u8, val as u64) + } + } + #[inline] + pub fn MAI1(&self) -> U16 { + unsafe { + ::std::mem::transmute(self._bitfield_1.get(12usize, 2u8) as u16) + } + } + #[inline] + pub fn set_MAI1(&mut self, val: U16) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + self._bitfield_1.set(12usize, 2u8, val as u64) + } + } + #[inline] + pub fn MAI2(&self) -> U16 { + unsafe { + ::std::mem::transmute(self._bitfield_1.get(14usize, 2u8) as u16) + } + } + #[inline] + pub fn set_MAI2(&mut self, val: U16) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + self._bitfield_1.set(14usize, 2u8, val as u64) + } + } + #[inline] + pub fn new_bitfield_1( + MADZ: U16, + MAI0: U16, + MAI1: U16, + MAI2: U16, + ) -> __BindgenBitfieldUnit<[u8; 2usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 2usize]> = + Default::default(); + __bindgen_bitfield_unit.set(0usize, 10u8, { + let MADZ: u16 = unsafe { ::std::mem::transmute(MADZ) }; + MADZ as u64 + }); + __bindgen_bitfield_unit.set(10usize, 2u8, { + let MAI0: u16 = unsafe { ::std::mem::transmute(MAI0) }; + MAI0 as u64 + }); + __bindgen_bitfield_unit.set(12usize, 2u8, { + let MAI1: u16 = unsafe { ::std::mem::transmute(MAI1) }; + MAI1 as u64 + }); + __bindgen_bitfield_unit.set(14usize, 2u8, { + let MAI2: u16 = unsafe { ::std::mem::transmute(MAI2) }; + MAI2 as u64 + }); + __bindgen_bitfield_unit + } + #[inline] + pub fn MATH(&self) -> U16 { + unsafe { + ::std::mem::transmute(self._bitfield_2.get(0usize, 10u8) as u16) + } + } + #[inline] + pub fn set_MATH(&mut self, val: U16) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + self._bitfield_2.set(0usize, 10u8, val as u64) + } + } + #[inline] + pub fn MATE(&self) -> U16 { + unsafe { + ::std::mem::transmute(self._bitfield_2.get(10usize, 4u8) as u16) + } + } + #[inline] + pub fn set_MATE(&mut self, val: U16) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + self._bitfield_2.set(10usize, 4u8, val as u64) + } + } + #[inline] + pub fn MATW(&self) -> U16 { + unsafe { + ::std::mem::transmute(self._bitfield_2.get(14usize, 2u8) as u16) + } + } + #[inline] + pub fn set_MATW(&mut self, val: U16) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + self._bitfield_2.set(14usize, 2u8, val as u64) + } + } + #[inline] + pub fn MASW(&self) -> U8 { + unsafe { + ::std::mem::transmute(self._bitfield_2.get(16usize, 4u8) as u8) + } + } + #[inline] + pub fn set_MASW(&mut self, val: U8) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + self._bitfield_2.set(16usize, 4u8, val as u64) + } + } + #[inline] + pub fn MABW(&self) -> U8 { + unsafe { + ::std::mem::transmute(self._bitfield_2.get(20usize, 3u8) as u8) + } + } + #[inline] + pub fn set_MABW(&mut self, val: U8) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + self._bitfield_2.set(20usize, 3u8, val as u64) + } + } + #[inline] + pub fn MAXN(&self) -> U8 { + unsafe { + ::std::mem::transmute(self._bitfield_2.get(23usize, 1u8) as u8) + } + } + #[inline] + pub fn set_MAXN(&mut self, val: U8) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + self._bitfield_2.set(23usize, 1u8, val as u64) + } + } + #[inline] + pub fn new_bitfield_2( + MATH: U16, + MATE: U16, + MATW: U16, + MASW: U8, + MABW: U8, + MAXN: U8, + ) -> __BindgenBitfieldUnit<[u8; 3usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 3usize]> = + Default::default(); + __bindgen_bitfield_unit.set(0usize, 10u8, { + let MATH: u16 = unsafe { ::std::mem::transmute(MATH) }; + MATH as u64 + }); + __bindgen_bitfield_unit.set(10usize, 4u8, { + let MATE: u16 = unsafe { ::std::mem::transmute(MATE) }; + MATE as u64 + }); + __bindgen_bitfield_unit.set(14usize, 2u8, { + let MATW: u16 = unsafe { ::std::mem::transmute(MATW) }; + MATW as u64 + }); + __bindgen_bitfield_unit.set(16usize, 4u8, { + let MASW: u8 = unsafe { ::std::mem::transmute(MASW) }; + MASW as u64 + }); + __bindgen_bitfield_unit.set(20usize, 3u8, { + let MABW: u8 = unsafe { ::std::mem::transmute(MABW) }; + MABW as u64 + }); + __bindgen_bitfield_unit.set(23usize, 1u8, { + let MAXN: u8 = unsafe { ::std::mem::transmute(MAXN) }; + MAXN as u64 + }); + __bindgen_bitfield_unit + } +} diff --git a/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs b/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs index 783ea26752..7d7b792152 100644 --- a/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs +++ b/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs @@ -7,17 +7,16 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit { +pub struct __BindgenBitfieldUnit { storage: Storage, - align: [Align; 0], } -impl __BindgenBitfieldUnit { +impl __BindgenBitfieldUnit { #[inline] pub const fn new(storage: Storage) -> Self { - Self { storage, align: [] } + Self { storage } } } -impl __BindgenBitfieldUnit +impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, { @@ -96,7 +95,8 @@ where #[repr(align(8))] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 32usize], u64>, + pub _bitfield_align_1: [u64; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 32usize]>, } #[test] fn bindgen_test_layout_Foo() { @@ -170,11 +170,9 @@ impl Foo { m_bar: ::std::os::raw::c_ulong, foo: ::std::os::raw::c_ulong, bar: ::std::os::raw::c_ulong, - ) -> __BindgenBitfieldUnit<[u8; 32usize], u64> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 32usize], - u64, - > = Default::default(); + ) -> __BindgenBitfieldUnit<[u8; 32usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 32usize]> = + Default::default(); __bindgen_bitfield_unit.set(0usize, 64u8, { let m_bitfield: u64 = unsafe { ::std::mem::transmute(m_bitfield) }; m_bitfield as u64 diff --git a/tests/expectations/tests/issue-816.rs b/tests/expectations/tests/issue-816.rs index 64b58abb68..c7f94106f4 100644 --- a/tests/expectations/tests/issue-816.rs +++ b/tests/expectations/tests/issue-816.rs @@ -7,17 +7,16 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit { +pub struct __BindgenBitfieldUnit { storage: Storage, - align: [Align; 0], } -impl __BindgenBitfieldUnit { +impl __BindgenBitfieldUnit { #[inline] pub const fn new(storage: Storage) -> Self { - Self { storage, align: [] } + Self { storage } } } -impl __BindgenBitfieldUnit +impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, { @@ -96,7 +95,8 @@ where #[repr(align(4))] #[derive(Debug, Default, Copy, Clone)] pub struct capabilities { - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 16usize], u8>, + pub _bitfield_align_1: [u8; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 16usize]>, } #[test] fn bindgen_test_layout_capabilities() { @@ -688,11 +688,9 @@ impl capabilities { bit_39: ::std::os::raw::c_uint, bit_40: ::std::os::raw::c_uint, bit_41: ::std::os::raw::c_uint, - ) -> __BindgenBitfieldUnit<[u8; 16usize], u8> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 16usize], - u8, - > = Default::default(); + ) -> __BindgenBitfieldUnit<[u8; 16usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 16usize]> = + Default::default(); __bindgen_bitfield_unit.set(0usize, 1u8, { let bit_1: u32 = unsafe { ::std::mem::transmute(bit_1) }; bit_1 as u64 diff --git a/tests/expectations/tests/jsval_layout_opaque.rs b/tests/expectations/tests/jsval_layout_opaque.rs index c9ce5ca0d5..92ae978dd1 100644 --- a/tests/expectations/tests/jsval_layout_opaque.rs +++ b/tests/expectations/tests/jsval_layout_opaque.rs @@ -7,17 +7,16 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit { +pub struct __BindgenBitfieldUnit { storage: Storage, - align: [Align; 0], } -impl __BindgenBitfieldUnit { +impl __BindgenBitfieldUnit { #[inline] pub const fn new(storage: Storage) -> Self { - Self { storage, align: [] } + Self { storage } } } -impl __BindgenBitfieldUnit +impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, { @@ -195,7 +194,8 @@ pub union jsval_layout { #[repr(align(8))] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct jsval_layout__bindgen_ty_1 { - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 8usize], u64>, + pub _bitfield_align_1: [u64; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 8usize]>, } #[test] fn bindgen_test_layout_jsval_layout__bindgen_ty_1() { @@ -246,11 +246,9 @@ impl jsval_layout__bindgen_ty_1 { pub fn new_bitfield_1( payload47: u64, tag: JSValueTag, - ) -> __BindgenBitfieldUnit<[u8; 8usize], u64> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 8usize], - u64, - > = Default::default(); + ) -> __BindgenBitfieldUnit<[u8; 8usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 8usize]> = + Default::default(); __bindgen_bitfield_unit.set(0usize, 47u8, { let payload47: u64 = unsafe { ::std::mem::transmute(payload47) }; payload47 as u64 diff --git a/tests/expectations/tests/jsval_layout_opaque_1_0.rs b/tests/expectations/tests/jsval_layout_opaque_1_0.rs index a5d35c19e8..e593a2c75b 100644 --- a/tests/expectations/tests/jsval_layout_opaque_1_0.rs +++ b/tests/expectations/tests/jsval_layout_opaque_1_0.rs @@ -7,17 +7,16 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit { +pub struct __BindgenBitfieldUnit { storage: Storage, - align: [Align; 0], } -impl __BindgenBitfieldUnit { +impl __BindgenBitfieldUnit { #[inline] pub fn new(storage: Storage) -> Self { - Self { storage, align: [] } + Self { storage } } } -impl __BindgenBitfieldUnit +impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, { @@ -237,7 +236,8 @@ pub struct jsval_layout { #[repr(C)] #[derive(Debug, Copy, Hash, PartialEq, Eq)] pub struct jsval_layout__bindgen_ty_1 { - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 8usize], u64>, + pub _bitfield_align_1: [u64; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 8usize]>, pub __bindgen_align: [u64; 0usize], } #[test] @@ -294,11 +294,9 @@ impl jsval_layout__bindgen_ty_1 { pub fn new_bitfield_1( payload47: u64, tag: JSValueTag, - ) -> __BindgenBitfieldUnit<[u8; 8usize], u64> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 8usize], - u64, - > = Default::default(); + ) -> __BindgenBitfieldUnit<[u8; 8usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 8usize]> = + Default::default(); __bindgen_bitfield_unit.set(0usize, 47u8, { let payload47: u64 = unsafe { ::std::mem::transmute(payload47) }; payload47 as u64 diff --git a/tests/expectations/tests/layout_align.rs b/tests/expectations/tests/layout_align.rs index 316eb7fb73..44998a8947 100644 --- a/tests/expectations/tests/layout_align.rs +++ b/tests/expectations/tests/layout_align.rs @@ -7,17 +7,16 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit { +pub struct __BindgenBitfieldUnit { storage: Storage, - align: [Align; 0], } -impl __BindgenBitfieldUnit { +impl __BindgenBitfieldUnit { #[inline] pub const fn new(storage: Storage) -> Self { - Self { storage, align: [] } + Self { storage } } } -impl __BindgenBitfieldUnit +impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, { @@ -160,7 +159,8 @@ impl Default for rte_kni_fifo { pub struct rte_eth_link { ///< ETH_SPEED_NUM_ pub link_speed: u32, - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize], u8>, + pub _bitfield_align_1: [u8; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub __bindgen_padding_0: [u8; 3usize], } #[test] @@ -234,11 +234,9 @@ impl rte_eth_link { link_duplex: u16, link_autoneg: u16, link_status: u16, - ) -> __BindgenBitfieldUnit<[u8; 1usize], u8> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 1usize], - u8, - > = Default::default(); + ) -> __BindgenBitfieldUnit<[u8; 1usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = + Default::default(); __bindgen_bitfield_unit.set(0usize, 1u8, { let link_duplex: u16 = unsafe { ::std::mem::transmute(link_duplex) }; diff --git a/tests/expectations/tests/layout_eth_conf.rs b/tests/expectations/tests/layout_eth_conf.rs index b75a16551e..34db2c4a73 100644 --- a/tests/expectations/tests/layout_eth_conf.rs +++ b/tests/expectations/tests/layout_eth_conf.rs @@ -7,17 +7,16 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit { +pub struct __BindgenBitfieldUnit { storage: Storage, - align: [Align; 0], } -impl __BindgenBitfieldUnit { +impl __BindgenBitfieldUnit { #[inline] pub const fn new(storage: Storage) -> Self { - Self { storage, align: [] } + Self { storage } } } -impl __BindgenBitfieldUnit +impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, { @@ -156,7 +155,8 @@ pub struct rte_eth_rxmode { pub max_rx_pkt_len: u32, ///< hdr buf size (header_split enabled). pub split_hdr_size: u16, - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 2usize], u8>, + pub _bitfield_align_1: [u8; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 2usize]>, } #[test] fn bindgen_test_layout_rte_eth_rxmode() { @@ -344,11 +344,9 @@ impl rte_eth_rxmode { hw_strip_crc: u16, enable_scatter: u16, enable_lro: u16, - ) -> __BindgenBitfieldUnit<[u8; 2usize], u8> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 2usize], - u8, - > = Default::default(); + ) -> __BindgenBitfieldUnit<[u8; 2usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 2usize]> = + Default::default(); __bindgen_bitfield_unit.set(0usize, 1u8, { let header_split: u16 = unsafe { ::std::mem::transmute(header_split) }; @@ -417,7 +415,8 @@ pub struct rte_eth_txmode { ///< TX multi-queues mode. pub mq_mode: rte_eth_tx_mq_mode, pub pvid: u16, - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize], u8>, + pub _bitfield_align_1: [u8; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub __bindgen_padding_0: u8, } #[test] @@ -508,11 +507,9 @@ impl rte_eth_txmode { hw_vlan_reject_tagged: u8, hw_vlan_reject_untagged: u8, hw_vlan_insert_pvid: u8, - ) -> __BindgenBitfieldUnit<[u8; 1usize], u8> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 1usize], - u8, - > = Default::default(); + ) -> __BindgenBitfieldUnit<[u8; 1usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = + Default::default(); __bindgen_bitfield_unit.set(0usize, 1u8, { let hw_vlan_reject_tagged: u8 = unsafe { ::std::mem::transmute(hw_vlan_reject_tagged) }; diff --git a/tests/expectations/tests/layout_eth_conf_1_0.rs b/tests/expectations/tests/layout_eth_conf_1_0.rs index 8800cf59ab..26d2db0295 100644 --- a/tests/expectations/tests/layout_eth_conf_1_0.rs +++ b/tests/expectations/tests/layout_eth_conf_1_0.rs @@ -7,17 +7,16 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit { +pub struct __BindgenBitfieldUnit { storage: Storage, - align: [Align; 0], } -impl __BindgenBitfieldUnit { +impl __BindgenBitfieldUnit { #[inline] pub fn new(storage: Storage) -> Self { - Self { storage, align: [] } + Self { storage } } } -impl __BindgenBitfieldUnit +impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, { @@ -199,7 +198,8 @@ pub struct rte_eth_rxmode { pub max_rx_pkt_len: u32, ///< hdr buf size (header_split enabled). pub split_hdr_size: u16, - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 2usize], u8>, + pub _bitfield_align_1: [u8; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 2usize]>, } #[test] fn bindgen_test_layout_rte_eth_rxmode() { @@ -392,11 +392,9 @@ impl rte_eth_rxmode { hw_strip_crc: u16, enable_scatter: u16, enable_lro: u16, - ) -> __BindgenBitfieldUnit<[u8; 2usize], u8> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 2usize], - u8, - > = Default::default(); + ) -> __BindgenBitfieldUnit<[u8; 2usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 2usize]> = + Default::default(); __bindgen_bitfield_unit.set(0usize, 1u8, { let header_split: u16 = unsafe { ::std::mem::transmute(header_split) }; @@ -465,7 +463,8 @@ pub struct rte_eth_txmode { ///< TX multi-queues mode. pub mq_mode: rte_eth_tx_mq_mode, pub pvid: u16, - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize], u8>, + pub _bitfield_align_1: [u8; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub __bindgen_padding_0: u8, } #[test] @@ -561,11 +560,9 @@ impl rte_eth_txmode { hw_vlan_reject_tagged: u8, hw_vlan_reject_untagged: u8, hw_vlan_insert_pvid: u8, - ) -> __BindgenBitfieldUnit<[u8; 1usize], u8> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 1usize], - u8, - > = Default::default(); + ) -> __BindgenBitfieldUnit<[u8; 1usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = + Default::default(); __bindgen_bitfield_unit.set(0usize, 1u8, { let hw_vlan_reject_tagged: u8 = unsafe { ::std::mem::transmute(hw_vlan_reject_tagged) }; diff --git a/tests/expectations/tests/layout_mbuf.rs b/tests/expectations/tests/layout_mbuf.rs index e5929ac5c2..a7f71a302a 100644 --- a/tests/expectations/tests/layout_mbuf.rs +++ b/tests/expectations/tests/layout_mbuf.rs @@ -7,17 +7,16 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit { +pub struct __BindgenBitfieldUnit { storage: Storage, - align: [Align; 0], } -impl __BindgenBitfieldUnit { +impl __BindgenBitfieldUnit { #[inline] pub const fn new(storage: Storage) -> Self { - Self { storage, align: [] } + Self { storage } } } -impl __BindgenBitfieldUnit +impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, { @@ -248,7 +247,8 @@ pub union rte_mbuf__bindgen_ty_2 { #[repr(align(4))] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_mbuf__bindgen_ty_2__bindgen_ty_1 { - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize], u8>, + pub _bitfield_align_1: [u8; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_2__bindgen_ty_1() { @@ -370,11 +370,9 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { inner_l2_type: u32, inner_l3_type: u32, inner_l4_type: u32, - ) -> __BindgenBitfieldUnit<[u8; 4usize], u8> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 4usize], - u8, - > = Default::default(); + ) -> __BindgenBitfieldUnit<[u8; 4usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = + Default::default(); __bindgen_bitfield_unit.set(0usize, 4u8, { let l2_type: u32 = unsafe { ::std::mem::transmute(l2_type) }; l2_type as u64 @@ -746,7 +744,8 @@ pub union rte_mbuf__bindgen_ty_5 { #[repr(align(8))] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_mbuf__bindgen_ty_5__bindgen_ty_1 { - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 8usize], u16>, + pub _bitfield_align_1: [u16; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 7usize]>, } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_5__bindgen_ty_1() { @@ -854,11 +853,9 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { tso_segsz: u64, outer_l3_len: u64, outer_l2_len: u64, - ) -> __BindgenBitfieldUnit<[u8; 8usize], u16> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 8usize], - u16, - > = Default::default(); + ) -> __BindgenBitfieldUnit<[u8; 7usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 7usize]> = + Default::default(); __bindgen_bitfield_unit.set(0usize, 7u8, { let l2_len: u64 = unsafe { ::std::mem::transmute(l2_len) }; l2_len as u64 diff --git a/tests/expectations/tests/layout_mbuf_1_0.rs b/tests/expectations/tests/layout_mbuf_1_0.rs index 96b38cbb30..70d96d958b 100644 --- a/tests/expectations/tests/layout_mbuf_1_0.rs +++ b/tests/expectations/tests/layout_mbuf_1_0.rs @@ -7,17 +7,16 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit { +pub struct __BindgenBitfieldUnit { storage: Storage, - align: [Align; 0], } -impl __BindgenBitfieldUnit { +impl __BindgenBitfieldUnit { #[inline] pub fn new(storage: Storage) -> Self { - Self { storage, align: [] } + Self { storage } } } -impl __BindgenBitfieldUnit +impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, { @@ -296,7 +295,8 @@ pub struct rte_mbuf__bindgen_ty_2 { #[repr(C)] #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct rte_mbuf__bindgen_ty_2__bindgen_ty_1 { - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize], u8>, + pub _bitfield_align_1: [u8; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, pub __bindgen_align: [u32; 0usize], } #[test] @@ -424,11 +424,9 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { inner_l2_type: u32, inner_l3_type: u32, inner_l4_type: u32, - ) -> __BindgenBitfieldUnit<[u8; 4usize], u8> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 4usize], - u8, - > = Default::default(); + ) -> __BindgenBitfieldUnit<[u8; 4usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = + Default::default(); __bindgen_bitfield_unit.set(0usize, 4u8, { let l2_type: u32 = unsafe { ::std::mem::transmute(l2_type) }; l2_type as u64 @@ -813,7 +811,8 @@ pub struct rte_mbuf__bindgen_ty_5 { #[repr(C)] #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct rte_mbuf__bindgen_ty_5__bindgen_ty_1 { - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 8usize], u16>, + pub _bitfield_align_1: [u16; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 7usize]>, pub __bindgen_align: [u64; 0usize], } #[test] @@ -927,11 +926,9 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { tso_segsz: u64, outer_l3_len: u64, outer_l2_len: u64, - ) -> __BindgenBitfieldUnit<[u8; 8usize], u16> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 8usize], - u16, - > = Default::default(); + ) -> __BindgenBitfieldUnit<[u8; 7usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 7usize]> = + Default::default(); __bindgen_bitfield_unit.set(0usize, 7u8, { let l2_len: u64 = unsafe { ::std::mem::transmute(l2_len) }; l2_len as u64 diff --git a/tests/expectations/tests/libclang-9/incomplete-array-padding.rs b/tests/expectations/tests/libclang-9/incomplete-array-padding.rs index 57f15a2263..c380a0cc8d 100644 --- a/tests/expectations/tests/libclang-9/incomplete-array-padding.rs +++ b/tests/expectations/tests/libclang-9/incomplete-array-padding.rs @@ -7,17 +7,16 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit { +pub struct __BindgenBitfieldUnit { storage: Storage, - align: [Align; 0], } -impl __BindgenBitfieldUnit { +impl __BindgenBitfieldUnit { #[inline] pub const fn new(storage: Storage) -> Self { - Self { storage, align: [] } + Self { storage } } } -impl __BindgenBitfieldUnit +impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, { @@ -125,7 +124,8 @@ impl ::std::fmt::Debug for __IncompleteArrayField { #[repr(C)] #[derive(Debug)] pub struct foo { - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize], u8>, + pub _bitfield_align_1: [u8; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub b: __IncompleteArrayField<*mut ::std::os::raw::c_void>, } #[test] @@ -168,11 +168,9 @@ impl foo { #[inline] pub fn new_bitfield_1( a: ::std::os::raw::c_char, - ) -> __BindgenBitfieldUnit<[u8; 1usize], u8> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 1usize], - u8, - > = Default::default(); + ) -> __BindgenBitfieldUnit<[u8; 1usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = + Default::default(); __bindgen_bitfield_unit.set(0usize, 1u8, { let a: u8 = unsafe { ::std::mem::transmute(a) }; a as u64 diff --git a/tests/expectations/tests/libclang-9/layout_align.rs b/tests/expectations/tests/libclang-9/layout_align.rs index 228177e10f..d153fa5ec4 100644 --- a/tests/expectations/tests/libclang-9/layout_align.rs +++ b/tests/expectations/tests/libclang-9/layout_align.rs @@ -7,17 +7,16 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit { +pub struct __BindgenBitfieldUnit { storage: Storage, - align: [Align; 0], } -impl __BindgenBitfieldUnit { +impl __BindgenBitfieldUnit { #[inline] pub const fn new(storage: Storage) -> Self { - Self { storage, align: [] } + Self { storage } } } -impl __BindgenBitfieldUnit +impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, { @@ -221,7 +220,8 @@ impl Default for rte_kni_fifo { pub struct rte_eth_link { ///< ETH_SPEED_NUM_ pub link_speed: u32, - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize], u8>, + pub _bitfield_align_1: [u8; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub __bindgen_padding_0: [u8; 3usize], } #[test] @@ -295,11 +295,9 @@ impl rte_eth_link { link_duplex: u16, link_autoneg: u16, link_status: u16, - ) -> __BindgenBitfieldUnit<[u8; 1usize], u8> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 1usize], - u8, - > = Default::default(); + ) -> __BindgenBitfieldUnit<[u8; 1usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = + Default::default(); __bindgen_bitfield_unit.set(0usize, 1u8, { let link_duplex: u16 = unsafe { ::std::mem::transmute(link_duplex) }; diff --git a/tests/expectations/tests/only_bitfields.rs b/tests/expectations/tests/only_bitfields.rs index fa076d87a2..2f063b5b38 100644 --- a/tests/expectations/tests/only_bitfields.rs +++ b/tests/expectations/tests/only_bitfields.rs @@ -7,17 +7,16 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit { +pub struct __BindgenBitfieldUnit { storage: Storage, - align: [Align; 0], } -impl __BindgenBitfieldUnit { +impl __BindgenBitfieldUnit { #[inline] pub const fn new(storage: Storage) -> Self { - Self { storage, align: [] } + Self { storage } } } -impl __BindgenBitfieldUnit +impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, { @@ -95,7 +94,8 @@ where #[repr(C, packed)] #[derive(Debug, Default, Copy, Clone)] pub struct C { - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize], u8>, + pub _bitfield_align_1: [u8; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, } #[test] fn bindgen_test_layout_C() { @@ -141,11 +141,9 @@ impl C { pub fn new_bitfield_1( a: bool, b: bool, - ) -> __BindgenBitfieldUnit<[u8; 1usize], u8> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 1usize], - u8, - > = Default::default(); + ) -> __BindgenBitfieldUnit<[u8; 1usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = + Default::default(); __bindgen_bitfield_unit.set(0usize, 1u8, { let a: u8 = unsafe { ::std::mem::transmute(a) }; a as u64 diff --git a/tests/expectations/tests/packed-bitfield.rs b/tests/expectations/tests/packed-bitfield.rs index d64bc85b93..f90edb930b 100644 --- a/tests/expectations/tests/packed-bitfield.rs +++ b/tests/expectations/tests/packed-bitfield.rs @@ -7,17 +7,16 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit { +pub struct __BindgenBitfieldUnit { storage: Storage, - align: [Align; 0], } -impl __BindgenBitfieldUnit { +impl __BindgenBitfieldUnit { #[inline] pub const fn new(storage: Storage) -> Self { - Self { storage, align: [] } + Self { storage } } } -impl __BindgenBitfieldUnit +impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, { @@ -95,7 +94,8 @@ where #[repr(C, packed)] #[derive(Debug, Default, Copy, Clone)] pub struct Date { - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 3usize], u8>, + pub _bitfield_align_1: [u8; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 3usize]>, } #[test] fn bindgen_test_layout_Date() { @@ -155,11 +155,9 @@ impl Date { day: ::std::os::raw::c_uchar, month: ::std::os::raw::c_uchar, year: ::std::os::raw::c_short, - ) -> __BindgenBitfieldUnit<[u8; 3usize], u8> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 3usize], - u8, - > = Default::default(); + ) -> __BindgenBitfieldUnit<[u8; 3usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 3usize]> = + Default::default(); __bindgen_bitfield_unit.set(0usize, 5u8, { let day: u8 = unsafe { ::std::mem::transmute(day) }; day as u64 diff --git a/tests/expectations/tests/struct_with_bitfields.rs b/tests/expectations/tests/struct_with_bitfields.rs index 7d6da17cce..2e95726f4c 100644 --- a/tests/expectations/tests/struct_with_bitfields.rs +++ b/tests/expectations/tests/struct_with_bitfields.rs @@ -7,17 +7,16 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit { +pub struct __BindgenBitfieldUnit { storage: Storage, - align: [Align; 0], } -impl __BindgenBitfieldUnit { +impl __BindgenBitfieldUnit { #[inline] pub const fn new(storage: Storage) -> Self { - Self { storage, align: [] } + Self { storage } } } -impl __BindgenBitfieldUnit +impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, { @@ -95,9 +94,11 @@ where #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct bitfield { - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize], u8>, + pub _bitfield_align_1: [u8; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub e: ::std::os::raw::c_int, - pub _bitfield_2: __BindgenBitfieldUnit<[u8; 8usize], u32>, + pub _bitfield_align_2: [u32; 0], + pub _bitfield_2: __BindgenBitfieldUnit<[u8; 8usize]>, } #[test] fn bindgen_test_layout_bitfield() { @@ -181,11 +182,9 @@ impl bitfield { b: ::std::os::raw::c_ushort, c: ::std::os::raw::c_ushort, d: ::std::os::raw::c_ushort, - ) -> __BindgenBitfieldUnit<[u8; 1usize], u8> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 1usize], - u8, - > = Default::default(); + ) -> __BindgenBitfieldUnit<[u8; 1usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = + Default::default(); __bindgen_bitfield_unit.set(0usize, 1u8, { let a: u16 = unsafe { ::std::mem::transmute(a) }; a as u64 @@ -234,11 +233,9 @@ impl bitfield { pub fn new_bitfield_2( f: ::std::os::raw::c_uint, g: ::std::os::raw::c_uint, - ) -> __BindgenBitfieldUnit<[u8; 8usize], u32> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 8usize], - u32, - > = Default::default(); + ) -> __BindgenBitfieldUnit<[u8; 8usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 8usize]> = + Default::default(); __bindgen_bitfield_unit.set(0usize, 2u8, { let f: u32 = unsafe { ::std::mem::transmute(f) }; f as u64 diff --git a/tests/expectations/tests/timex.rs b/tests/expectations/tests/timex.rs index dc33f7482f..63917d6ab9 100644 --- a/tests/expectations/tests/timex.rs +++ b/tests/expectations/tests/timex.rs @@ -7,17 +7,16 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit { +pub struct __BindgenBitfieldUnit { storage: Storage, - align: [Align; 0], } -impl __BindgenBitfieldUnit { +impl __BindgenBitfieldUnit { #[inline] pub const fn new(storage: Storage) -> Self { - Self { storage, align: [] } + Self { storage } } } -impl __BindgenBitfieldUnit +impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, { @@ -96,7 +95,8 @@ where #[derive(Copy, Clone)] pub struct timex { pub tai: ::std::os::raw::c_int, - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 44usize], u8>, + pub _bitfield_align_1: [u8; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 44usize]>, } #[test] fn bindgen_test_layout_timex() { @@ -130,7 +130,8 @@ impl Default for timex { #[derive(Copy, Clone)] pub struct timex_named { pub tai: ::std::os::raw::c_int, - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 44usize], u32>, + pub _bitfield_align_1: [u32; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 44usize]>, } #[test] fn bindgen_test_layout_timex_named() { diff --git a/tests/expectations/tests/union_bitfield.rs b/tests/expectations/tests/union_bitfield.rs index c4b91899d0..22c0de8578 100644 --- a/tests/expectations/tests/union_bitfield.rs +++ b/tests/expectations/tests/union_bitfield.rs @@ -7,17 +7,16 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit { +pub struct __BindgenBitfieldUnit { storage: Storage, - align: [Align; 0], } -impl __BindgenBitfieldUnit { +impl __BindgenBitfieldUnit { #[inline] pub const fn new(storage: Storage) -> Self { - Self { storage, align: [] } + Self { storage } } } -impl __BindgenBitfieldUnit +impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, { @@ -95,7 +94,8 @@ where #[repr(C)] #[derive(Copy, Clone)] pub union U4 { - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize], u8>, + pub _bitfield_align_1: [u8; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, _bindgen_union_align: u32, } #[test] @@ -133,11 +133,9 @@ impl U4 { #[inline] pub fn new_bitfield_1( derp: ::std::os::raw::c_uint, - ) -> __BindgenBitfieldUnit<[u8; 1usize], u8> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 1usize], - u8, - > = Default::default(); + ) -> __BindgenBitfieldUnit<[u8; 1usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = + Default::default(); __bindgen_bitfield_unit.set(0usize, 1u8, { let derp: u32 = unsafe { ::std::mem::transmute(derp) }; derp as u64 @@ -148,7 +146,8 @@ impl U4 { #[repr(C)] #[derive(Copy, Clone)] pub union B { - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize], u32>, + pub _bitfield_align_1: [u32; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, _bindgen_union_align: u32, } #[test] @@ -200,11 +199,9 @@ impl B { pub fn new_bitfield_1( foo: ::std::os::raw::c_uint, bar: ::std::os::raw::c_uchar, - ) -> __BindgenBitfieldUnit<[u8; 4usize], u32> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 4usize], - u32, - > = Default::default(); + ) -> __BindgenBitfieldUnit<[u8; 4usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = + Default::default(); __bindgen_bitfield_unit.set(0usize, 31u8, { let foo: u32 = unsafe { ::std::mem::transmute(foo) }; foo as u64 diff --git a/tests/expectations/tests/union_bitfield_1_0.rs b/tests/expectations/tests/union_bitfield_1_0.rs index 2a620b23c4..7c846da8b1 100644 --- a/tests/expectations/tests/union_bitfield_1_0.rs +++ b/tests/expectations/tests/union_bitfield_1_0.rs @@ -7,17 +7,16 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit { +pub struct __BindgenBitfieldUnit { storage: Storage, - align: [Align; 0], } -impl __BindgenBitfieldUnit { +impl __BindgenBitfieldUnit { #[inline] pub fn new(storage: Storage) -> Self { - Self { storage, align: [] } + Self { storage } } } -impl __BindgenBitfieldUnit +impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, { @@ -138,8 +137,8 @@ impl ::std::cmp::Eq for __BindgenUnionField {} #[repr(C)] #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct U4 { - pub _bitfield_1: - __BindgenUnionField<__BindgenBitfieldUnit<[u8; 1usize], u8>>, + pub _bitfield_align_1: [u8; 0], + pub _bitfield_1: __BindgenUnionField<__BindgenBitfieldUnit<[u8; 1usize]>>, pub bindgen_union_field: u32, } #[test] @@ -179,11 +178,9 @@ impl U4 { #[inline] pub fn new_bitfield_1( derp: ::std::os::raw::c_uint, - ) -> __BindgenBitfieldUnit<[u8; 1usize], u8> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 1usize], - u8, - > = Default::default(); + ) -> __BindgenBitfieldUnit<[u8; 1usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = + Default::default(); __bindgen_bitfield_unit.set(0usize, 1u8, { let derp: u32 = unsafe { ::std::mem::transmute(derp) }; derp as u64 @@ -194,8 +191,8 @@ impl U4 { #[repr(C)] #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct B { - pub _bitfield_1: - __BindgenUnionField<__BindgenBitfieldUnit<[u8; 4usize], u32>>, + pub _bitfield_align_1: [u32; 0], + pub _bitfield_1: __BindgenUnionField<__BindgenBitfieldUnit<[u8; 4usize]>>, pub bindgen_union_field: u32, } #[test] @@ -251,11 +248,9 @@ impl B { pub fn new_bitfield_1( foo: ::std::os::raw::c_uint, bar: ::std::os::raw::c_uchar, - ) -> __BindgenBitfieldUnit<[u8; 4usize], u32> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 4usize], - u32, - > = Default::default(); + ) -> __BindgenBitfieldUnit<[u8; 4usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = + Default::default(); __bindgen_bitfield_unit.set(0usize, 31u8, { let foo: u32 = unsafe { ::std::mem::transmute(foo) }; foo as u64 @@ -270,8 +265,8 @@ impl B { #[repr(C)] #[derive(Copy)] pub struct HasBigBitfield { - pub _bitfield_1: - __BindgenUnionField<__BindgenBitfieldUnit<[u8; 16usize], u64>>, + pub _bitfield_align_1: [u64; 0], + pub _bitfield_1: __BindgenUnionField<__BindgenBitfieldUnit<[u8; 16usize]>>, pub bindgen_union_field: [u8; 16usize], } #[test] diff --git a/tests/expectations/tests/union_with_anon_struct_bitfield.rs b/tests/expectations/tests/union_with_anon_struct_bitfield.rs index ca8251745b..445a97efa1 100644 --- a/tests/expectations/tests/union_with_anon_struct_bitfield.rs +++ b/tests/expectations/tests/union_with_anon_struct_bitfield.rs @@ -7,17 +7,16 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit { +pub struct __BindgenBitfieldUnit { storage: Storage, - align: [Align; 0], } -impl __BindgenBitfieldUnit { +impl __BindgenBitfieldUnit { #[inline] pub const fn new(storage: Storage) -> Self { - Self { storage, align: [] } + Self { storage } } } -impl __BindgenBitfieldUnit +impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, { @@ -103,7 +102,8 @@ pub union foo { #[repr(align(4))] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct foo__bindgen_ty_1 { - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize], u32>, + pub _bitfield_align_1: [u32; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { @@ -149,11 +149,9 @@ impl foo__bindgen_ty_1 { pub fn new_bitfield_1( b: ::std::os::raw::c_int, c: ::std::os::raw::c_int, - ) -> __BindgenBitfieldUnit<[u8; 4usize], u32> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 4usize], - u32, - > = Default::default(); + ) -> __BindgenBitfieldUnit<[u8; 4usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = + Default::default(); __bindgen_bitfield_unit.set(0usize, 7u8, { let b: u32 = unsafe { ::std::mem::transmute(b) }; b as u64 diff --git a/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs b/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs index 352b32b1ee..43736b0311 100644 --- a/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs +++ b/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs @@ -7,17 +7,16 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit { +pub struct __BindgenBitfieldUnit { storage: Storage, - align: [Align; 0], } -impl __BindgenBitfieldUnit { +impl __BindgenBitfieldUnit { #[inline] pub fn new(storage: Storage) -> Self { - Self { storage, align: [] } + Self { storage } } } -impl __BindgenBitfieldUnit +impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, { @@ -145,7 +144,8 @@ pub struct foo { #[repr(C)] #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct foo__bindgen_ty_1 { - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize], u32>, + pub _bitfield_align_1: [u32; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, pub __bindgen_align: [u32; 0usize], } #[test] @@ -197,11 +197,9 @@ impl foo__bindgen_ty_1 { pub fn new_bitfield_1( b: ::std::os::raw::c_int, c: ::std::os::raw::c_int, - ) -> __BindgenBitfieldUnit<[u8; 4usize], u32> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 4usize], - u32, - > = Default::default(); + ) -> __BindgenBitfieldUnit<[u8; 4usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = + Default::default(); __bindgen_bitfield_unit.set(0usize, 7u8, { let b: u32 = unsafe { ::std::mem::transmute(b) }; b as u64 diff --git a/tests/expectations/tests/weird_bitfields.rs b/tests/expectations/tests/weird_bitfields.rs index 2c1a7d2588..d25c802e38 100644 --- a/tests/expectations/tests/weird_bitfields.rs +++ b/tests/expectations/tests/weird_bitfields.rs @@ -7,17 +7,16 @@ #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit { +pub struct __BindgenBitfieldUnit { storage: Storage, - align: [Align; 0], } -impl __BindgenBitfieldUnit { +impl __BindgenBitfieldUnit { #[inline] pub const fn new(storage: Storage) -> Self { - Self { storage, align: [] } + Self { storage } } } -impl __BindgenBitfieldUnit +impl __BindgenBitfieldUnit where Storage: AsRef<[u8]> + AsMut<[u8]>, { @@ -103,7 +102,8 @@ pub enum nsStyleSVGOpacitySource { #[derive(Debug, Copy, Clone)] pub struct Weird { pub mStrokeDasharrayLength: ::std::os::raw::c_uint, - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize], u16>, + pub _bitfield_align_1: [u16; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, pub mClipRule: ::std::os::raw::c_uchar, pub mColorInterpolation: ::std::os::raw::c_uchar, pub mColorInterpolationFilters: ::std::os::raw::c_uchar, @@ -115,7 +115,8 @@ pub struct Weird { pub mStrokeLinejoin: ::std::os::raw::c_uchar, pub mTextAnchor: ::std::os::raw::c_uchar, pub mTextRendering: ::std::os::raw::c_uchar, - pub _bitfield_2: __BindgenBitfieldUnit<[u8; 2usize], u8>, + pub _bitfield_align_2: [u8; 0], + pub _bitfield_2: __BindgenBitfieldUnit<[u8; 2usize]>, pub __bindgen_padding_0: [u8; 3usize], } #[test] @@ -319,11 +320,9 @@ impl Weird { pub fn new_bitfield_1( bitTest: ::std::os::raw::c_uint, bitTest2: ::std::os::raw::c_uint, - ) -> __BindgenBitfieldUnit<[u8; 4usize], u16> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 4usize], - u16, - > = Default::default(); + ) -> __BindgenBitfieldUnit<[u8; 4usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = + Default::default(); __bindgen_bitfield_unit.set(0usize, 16u8, { let bitTest: u32 = unsafe { ::std::mem::transmute(bitTest) }; bitTest as u64 @@ -406,11 +405,9 @@ impl Weird { mStrokeDasharrayFromObject: bool, mStrokeDashoffsetFromObject: bool, mStrokeWidthFromObject: bool, - ) -> __BindgenBitfieldUnit<[u8; 2usize], u8> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit< - [u8; 2usize], - u8, - > = Default::default(); + ) -> __BindgenBitfieldUnit<[u8; 2usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 2usize]> = + Default::default(); __bindgen_bitfield_unit.set(0usize, 3u8, { let mFillOpacitySource: u32 = unsafe { ::std::mem::transmute(mFillOpacitySource) }; diff --git a/tests/headers/issue-1947.h b/tests/headers/issue-1947.h new file mode 100644 index 0000000000..e2e9b3e19a --- /dev/null +++ b/tests/headers/issue-1947.h @@ -0,0 +1,9 @@ +typedef unsigned char U8; +typedef unsigned short U16; + +typedef struct { + U16 MADZ : 10, MAI0 : 2, MAI1 : 2, MAI2 : 2; + U8 MADK, MABR; + U16 MATH : 10, MATE : 4, MATW : 2; + U8 MASW : 4, MABW : 3, MAXN : 1, _rB_; +} V56AMDY; From c5f1c73be37c758804b79c9165cb1b3cebfb11f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 23 Dec 2020 01:34:46 +0100 Subject: [PATCH 129/942] Allow log stubs to be unused. --- src/log_stubs.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/log_stubs.rs b/src/log_stubs.rs index 4a72d9a5ea..4af496ce14 100644 --- a/src/log_stubs.rs +++ b/src/log_stubs.rs @@ -1,3 +1,5 @@ +#![allow(unused)] + macro_rules! log { (target: $target:expr, $lvl:expr, $($arg:tt)+) => { let _ = $target; From a0cd0414150dcbd495e23af1a7cf05be670e25fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 23 Dec 2020 01:47:41 +0100 Subject: [PATCH 130/942] integration: Forward some features to bindgen. --- bindgen-integration/Cargo.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bindgen-integration/Cargo.toml b/bindgen-integration/Cargo.toml index e82fbd9905..2664b60ad7 100644 --- a/bindgen-integration/Cargo.toml +++ b/bindgen-integration/Cargo.toml @@ -11,6 +11,10 @@ bindgen = { path = ".." } cc = "1.0" [features] +static = ["bindgen/static"] +runtime = ["bindgen/runtime"] + +testing_only_extra_assertions = ["bindgen/testing_only_extra_assertions"] testing_only_libclang_9 = ["bindgen/testing_only_libclang_9"] testing_only_libclang_5 = ["bindgen/testing_only_libclang_5"] testing_only_libclang_4 = ["bindgen/testing_only_libclang_4"] From afa50fa1add6aca654da3fe009258e57f4fcd4f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 23 Dec 2020 04:47:58 +0100 Subject: [PATCH 131/942] tests: Remove unnecessary system header include that makes macos unhappy --- bindgen-integration/cpp/Test.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/bindgen-integration/cpp/Test.h b/bindgen-integration/cpp/Test.h index a9c5258c44..7605d9f0f3 100644 --- a/bindgen-integration/cpp/Test.h +++ b/bindgen-integration/cpp/Test.h @@ -20,8 +20,6 @@ #define TESTMACRO_STRING_EXPR ("string") #define TESTMACRO_STRING_FUNC_NON_UTF8(x) (x "ᅵᅵ") /* invalid UTF-8 on purpose */ -#include - enum { MY_ANNOYING_MACRO = #define MY_ANNOYING_MACRO 1 From fde75f68e701b2f4b52a3655afba612187e20687 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 23 Dec 2020 01:10:12 +0100 Subject: [PATCH 132/942] ci: Switch most CI to GitHub actions. --- .github/workflows/bindgen.yml | 150 +++++++++++++++++++++++++++++++++ .travis.yml | 83 +----------------- bindgen-integration/Cargo.toml | 1 + ci/assert-docs.sh | 6 -- ci/assert-no-diff.sh | 8 -- ci/assert-rustfmt.sh | 13 --- ci/assert-warnings.sh | 6 -- ci/before_install.sh | 77 ----------------- ci/script.sh | 65 -------------- ci/test.sh | 130 ++++++++++++++++++++++++++++ tests/quickchecking/.gitignore | 1 + 11 files changed, 283 insertions(+), 257 deletions(-) create mode 100644 .github/workflows/bindgen.yml delete mode 100755 ci/assert-docs.sh delete mode 100755 ci/assert-no-diff.sh delete mode 100755 ci/assert-rustfmt.sh delete mode 100755 ci/assert-warnings.sh delete mode 100644 ci/before_install.sh delete mode 100755 ci/script.sh create mode 100755 ci/test.sh create mode 100644 tests/quickchecking/.gitignore diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml new file mode 100644 index 0000000000..29309e8270 --- /dev/null +++ b/.github/workflows/bindgen.yml @@ -0,0 +1,150 @@ +name: bindgen + +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + rustfmt: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Install stable + uses: actions-rs/toolchain@v1 + with: + profile: minimal + # TODO: Should ideally be stable, but we use some nightly-only + # features. + toolchain: nightly + override: true + components: rustfmt + + - name: Run rustfmt + uses: actions-rs/cargo@v1 + with: + command: fmt + args: -- --check + + msrv: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Install msrv + uses: actions-rs/toolchain@v1 + with: + profile: minimal + # MSRV below is documented in README.md, please update that if you + # change this. + toolchain: 1.40.0 + override: true + + - name: Build with msrv + run: rm Cargo.lock && cargo +1.40.0 build --lib + + quickchecking: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Install stable + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + # TODO: Actually run quickchecks once `bindgen` is reliable enough. + - name: Build quickcheck tests + run: cd tests/quickchecking && cargo test + + test-expectations: + runs-on: ${{matrix.os}} + strategy: + matrix: + # TODO(#1954): These should be run on mac too, but turns out they're + # broken. + os: [ubuntu-latest] + steps: + - uses: actions/checkout@v2 + + - name: Install stable + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + - name: Test expectations + run: cd tests/expectations && cargo test + + test: + runs-on: ${{matrix.os}} + strategy: + matrix: + os: [ubuntu-latest] + llvm_version: ["3.9", "4.0", "5.0", "9.0"] + release_build: [0, 1] + no_default_features: [0, 1] + # FIXME: There are no pre-built static libclang libraries, so the + # `static` feature is not testable atm. + feature_runtime: [0, 1] + feature_extra_asserts: [0] + feature_testing_only_docs: [0] + + exclude: + # 3.9 and 4.0 are too old to support regular dynamic linking, so this + # is not expected to work. + - os: ubuntu-latest + llvm_version: "3.9" + no_default_features: 1 + feature_runtime: 0 + + - os: ubuntu-latest + llvm_version: "4.0" + no_default_features: 1 + feature_runtime: 0 + + include: + # Test with extra asserts + docs just with latest llvm versions to + # prevent explosion + - os: ubuntu-latest + llvm_version: "9.0" + release_build: 0 + no_default_features: 0 + feature_extra_asserts: 1 + feature_testing_only_docs: 1 + + # Ensure stuff works on macos too + - os: macos-latest + llvm_version: "9.0" + release_build: 0 + no_default_features: 0 + feature_extra_asserts: 0 + feature_testing_only_docs: 0 + steps: + - uses: actions/checkout@v2 + + - name: Install stable + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + - name: Run all the tests + env: + GITHUB_ACTIONS_OS: ${{matrix.os}} + LLVM_VERSION: ${{matrix.llvm_version}} + BINDGEN_RELEASE_BUILD: ${{matrix.release_build}} + BINDGEN_FEATURE_RUNTIME: ${{matrix.feature_runtime}} + BINDGEN_FEATURE_EXTRA_ASSERTS: ${{matrix.feature_extra_asserts}} + BINDGEN_FEATURE_TESTING_ONLY_DOCS: ${{matrix.feature_testing_only_docs}} + BINDGEN_NO_DEFAULT_FEATURES: ${{matrix.no_default_features}} + run: ./ci/test.sh diff --git a/.travis.yml b/.travis.yml index c44aaa05cd..1e6d4f0aec 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,96 +1,15 @@ language: rust - dist: xenial - os: - linux - rust: - stable - env: global: - CARGO_TARGET_DIR=/tmp/bindgen - matrix: - # Miscellaneous tests. - # Start "misc" job first since it runs longer than any other job. - - LLVM_VERSION="9.0" BINDGEN_JOB="misc" - - LLVM_VERSION="9.0" BINDGEN_JOB="quickchecking" - - LLVM_VERSION="9.0" BINDGEN_JOB="msrv" - - # General matrix. - - LLVM_VERSION="3.9" BINDGEN_JOB="test" BINDGEN_PROFILE= - - LLVM_VERSION="3.9" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" - - LLVM_VERSION="3.9" BINDGEN_JOB="integration" BINDGEN_PROFILE= - - LLVM_VERSION="3.9" BINDGEN_JOB="integration" BINDGEN_PROFILE="--release" - - LLVM_VERSION="3.9" BINDGEN_JOB="test" BINDGEN_PROFILE= BINDGEN_NO_DEFAULT_FEATURES="1" BINDGEN_FEATURES="runtime" - - LLVM_VERSION="3.9" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" BINDGEN_NO_DEFAULT_FEATURES="1" BINDGEN_FEATURES="runtime" - - - LLVM_VERSION="4.0" BINDGEN_JOB="test" BINDGEN_PROFILE= - - LLVM_VERSION="4.0" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" - - LLVM_VERSION="4.0" BINDGEN_JOB="integration" BINDGEN_PROFILE= - - LLVM_VERSION="4.0" BINDGEN_JOB="integration" BINDGEN_PROFILE="--release" - - LLVM_VERSION="4.0" BINDGEN_JOB="test" BINDGEN_PROFILE= BINDGEN_NO_DEFAULT_FEATURES="1" BINDGEN_FEATURES="runtime" - - LLVM_VERSION="4.0" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" BINDGEN_NO_DEFAULT_FEATURES="1" BINDGEN_FEATURES="runtime" - - - LLVM_VERSION="5.0" BINDGEN_JOB="test" BINDGEN_PROFILE= - - LLVM_VERSION="5.0" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" - - LLVM_VERSION="5.0" BINDGEN_JOB="integration" BINDGEN_PROFILE= - - LLVM_VERSION="5.0" BINDGEN_JOB="integration" BINDGEN_PROFILE="--release" - - LLVM_VERSION="5.0" BINDGEN_JOB="test" BINDGEN_PROFILE= BINDGEN_NO_DEFAULT_FEATURES="1" - - LLVM_VERSION="5.0" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" BINDGEN_NO_DEFAULT_FEATURES="1" - - # FIXME: There are no pre-built static libclang libraries, so this is not testable at the moment. - # - LLVM_VERSION="5.0" BINDGEN_JOB="test" BINDGEN_PROFILE= BINDGEN_FEATURES="static" BINDGEN_NO_DEFAULT_FEATURES="1" - # - LLVM_VERSION="5.0" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" BINDGEN_FEATURES="static" BINDGEN_NO_DEFAULT_FEATURES="1" - - - LLVM_VERSION="9.0" BINDGEN_JOB="test" BINDGEN_PROFILE= - - LLVM_VERSION="9.0" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" - - LLVM_VERSION="9.0" BINDGEN_JOB="integration" BINDGEN_PROFILE= - - LLVM_VERSION="9.0" BINDGEN_JOB="integration" BINDGEN_PROFILE="--release" - - LLVM_VERSION="9.0" BINDGEN_JOB="test" BINDGEN_PROFILE= BINDGEN_NO_DEFAULT_FEATURES="1" - - LLVM_VERSION="9.0" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" BINDGEN_NO_DEFAULT_FEATURES="1" - - # FIXME: There are no pre-built static libclang libraries, so this is not testable at the moment. - # - LLVM_VERSION="9.0" BINDGEN_JOB="test" BINDGEN_PROFILE= BINDGEN_FEATURES="static" BINDGEN_NO_DEFAULT_FEATURES="1" - # - LLVM_VERSION="9.0" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" BINDGEN_FEATURES="static" BINDGEN_NO_DEFAULT_FEATURES="1" - - # Testing with extra asserts enabled - - LLVM_VERSION="9.0" BINDGEN_JOB="test" BINDGEN_PROFILE= BINDGEN_FEATURES="testing_only_extra_assertions" - - LLVM_VERSION="9.0" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" BINDGEN_FEATURES="testing_only_extra_assertions" - - - # Test the expectations build and pass tests. - - LLVM_VERSION="9.0" BINDGEN_JOB="expectations" BINDGEN_PROFILE= - - LLVM_VERSION="9.0" BINDGEN_JOB="expectations" BINDGEN_PROFILE="--release" - -matrix: - fast_finish: true - - # Include a few jobs for spot-checking different configurations without - # invoking combinatoric explosion of Travis jobs. - include: - - os: osx - env: LLVM_VERSION="9.0" BINDGEN_JOB="test" BINDGEN_PROFILE= - - os: osx - env: LLVM_VERSION="9.0" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" - - os: osx - env: LLVM_VERSION="9.0" BINDGEN_JOB="integration" BINDGEN_PROFILE= - - os: osx - env: LLVM_VERSION="9.0" BINDGEN_JOB="integration" BINDGEN_PROFILE="--release" - -cache: - directories: - - $HOME/.cargo - - $HOME/.llvm-builds - -before_install: . ./ci/before_install.sh - script: - - BINDGEN_JOB="$BINDGEN_JOB" BINDGEN_PROFILE="$BINDGEN_PROFILE" BINDGEN_FEATURES="$BINDGEN_FEATURES" BINDGEN_NO_DEFAULT_FEATURES="$BINDGEN_NO_DEFAULT_FEATURES" ./ci/script.sh - + - ./ci/test-book.sh after_success: - test "$TRAVIS_PULL_REQUEST" == "false" && test "$TRAVIS_BRANCH" == "master" && - test "$BINDGEN_JOB" == "misc" && ./ci/deploy-book.sh diff --git a/bindgen-integration/Cargo.toml b/bindgen-integration/Cargo.toml index 2664b60ad7..650dedafe2 100644 --- a/bindgen-integration/Cargo.toml +++ b/bindgen-integration/Cargo.toml @@ -14,6 +14,7 @@ cc = "1.0" static = ["bindgen/static"] runtime = ["bindgen/runtime"] +testing_only_docs = ["bindgen/testing_only_docs"] testing_only_extra_assertions = ["bindgen/testing_only_extra_assertions"] testing_only_libclang_9 = ["bindgen/testing_only_libclang_9"] testing_only_libclang_5 = ["bindgen/testing_only_libclang_5"] diff --git a/ci/assert-docs.sh b/ci/assert-docs.sh deleted file mode 100755 index 2bbc35af38..0000000000 --- a/ci/assert-docs.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash - -set -xeu -cd "$(dirname "$0")/.." - -cargo check --features "$BINDGEN_FEATURES testing_only_docs" diff --git a/ci/assert-no-diff.sh b/ci/assert-no-diff.sh deleted file mode 100755 index 14f2aa2161..0000000000 --- a/ci/assert-no-diff.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash - -set -xeu -cd "$(dirname "$0")/.." - -git add -u -git diff @ -git diff-index --quiet HEAD diff --git a/ci/assert-rustfmt.sh b/ci/assert-rustfmt.sh deleted file mode 100755 index 785530cb85..0000000000 --- a/ci/assert-rustfmt.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash - -set -xeu -cd "$(dirname "$0")/.." - -TOOLCHAIN="nightly-$(curl https://rust-lang.github.io/rustup-components-history/$(rustup target list --installed | tail -1)/rustfmt)" -rustup update "$TOOLCHAIN" -rustup component add rustfmt --toolchain "$TOOLCHAIN" - -# Run `rustfmt` on the crate! If `rustfmt` can't make a long line shorter, it -# prints an error and exits non-zero, so tell it to kindly shut its yapper and -# make sure it doesn't cause us to exit this whole script non-zero. -rustup run "$TOOLCHAIN" cargo fmt -- --check diff --git a/ci/assert-warnings.sh b/ci/assert-warnings.sh deleted file mode 100755 index 62c12c42d0..0000000000 --- a/ci/assert-warnings.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash - -set -xeu -cd "$(dirname "$0")/.." - -cargo rustc --lib --features "$BINDGEN_FEATURES" -- -Dwarnings diff --git a/ci/before_install.sh b/ci/before_install.sh deleted file mode 100644 index 2e66ae4e74..0000000000 --- a/ci/before_install.sh +++ /dev/null @@ -1,77 +0,0 @@ -#!/usr/bin/env bash -# Bail on first error -set -e -# Bail if an unset variable is encountered -set -u -# Enable debugging output -set -x -# Give a pipeline a non-zero exit code if one of its constituents fails -set -o pipefail - -function llvm_linux_target_triple() { - echo "x86_64-linux-gnu-ubuntu-16.04" -} - -function llvm_macos_target_triple() { - case "$1" in - [0-8].* | 9.0.0) echo "x86_64-darwin-apple" ;; - # Starting with 9.0.1, triple swapped ordering - *) echo "x86_64-apple-darwin" ;; - esac -} - -function llvm_version_triple() { - case "$1" in - 5.0) echo "5.0.1" ;; - # By default, take the .0 patch release - *) echo "$1.0" ;; - esac -} - -function llvm_base_url() { - local llvm_version_triple=$1 - - case "$llvm_version_triple" in - [0-8].* | 9.0.0) - echo "http://releases.llvm.org/$llvm_version_triple" - ;; - # Starting with 9.0.1, releases are hosted on github - *) - echo "https://github.com/llvm/llvm-project/releases/download/llvmorg-$llvm_version_triple" - ;; - esac -} - -function llvm_download() { - local base_url=$1 - local arch=$2 - - export LLVM=clang+llvm-${LLVM_VERSION_TRIPLE}-$arch - export LLVM_DIRECTORY="$HOME/.llvm/${LLVM}" - - if [ -d "${LLVM_DIRECTORY}" ]; then - echo "Using cached LLVM download for ${LLVM}..." - else - wget $base_url/${LLVM}.tar.xz - mkdir -p "${LLVM_DIRECTORY}" - tar xf ${LLVM}.tar.xz -C "${LLVM_DIRECTORY}" --strip-components=1 - fi - - export LIBCLANG_PATH="${LLVM_DIRECTORY}/lib" - export LLVM_CONFIG_PATH="${LLVM_DIRECTORY}/bin/llvm-config" -} - -export LLVM_VERSION_TRIPLE=`llvm_version_triple ${LLVM_VERSION}` - -base_url=`llvm_base_url ${LLVM_VERSION_TRIPLE}` - -if [ "${TRAVIS_OS_NAME}" == "linux" ]; then - llvm_download $base_url `llvm_linux_target_triple ${LLVM_VERSION_TRIPLE}` - export LD_LIBRARY_PATH="${LLVM_DIRECTORY}/lib":${LD_LIBRARY_PATH:-} -else - llvm_download $base_url `llvm_macos_target_triple ${LLVM_VERSION_TRIPLE}` - export DYLD_LIBRARY_PATH="${LLVM_DIRECTORY}/lib":${DYLD_LIBRARY_PATH:-} -fi - -# Subsequent scripts can see the state of `set -eu`, so unset it again. -set +eu diff --git a/ci/script.sh b/ci/script.sh deleted file mode 100755 index 16eddbf81d..0000000000 --- a/ci/script.sh +++ /dev/null @@ -1,65 +0,0 @@ -#!/usr/bin/env bash - -set -xeu -cd "$(dirname "$0")/.." - -# Note that `$BINDGEN_PROFILE` is never in quotes so that it expands to nothing -# (not even an empty string argument) when the variable is empty. This is -# necessary so we don't pass an unexpected flag to cargo. - -export RUST_BACKTRACE=1 - -NO_DEFAULT_FEATURES="" -if [ ! -z $BINDGEN_NO_DEFAULT_FEATURES ]; then - NO_DEFAULT_FEATURES=--no-default-features -fi - -case "$BINDGEN_JOB" in - "test") - # Need rustfmt to compare the test expectations. - TOOLCHAIN="nightly-$(curl https://rust-lang.github.io/rustup-components-history/$(rustup target list --installed | tail -1)/rustfmt)" - rustup update "$TOOLCHAIN" - rustup component add rustfmt --toolchain "$TOOLCHAIN" - RUSTFMT="$(rustup which --toolchain "$TOOLCHAIN" rustfmt)" - export RUSTFMT - cargo test "$BINDGEN_PROFILE" $NO_DEFAULT_FEATURES --features "$BINDGEN_FEATURES" - ./ci/assert-no-diff.sh - ;; - - "msrv") - # Test that the bindgen library can be built with the minimum supported Rust version - # This test should not use Cargo.lock as it's ignored for library builds - rm Cargo.lock - # The MSRV below is also documented in README.md, please keep in sync - rustup install 1.40.0 - cargo +1.40.0 build --lib $NO_DEFAULT_FEATURES --features "$BINDGEN_FEATURES" - ;; - - "integration") - cd ./bindgen-integration - cargo test "$BINDGEN_PROFILE" $NO_DEFAULT_FEATURES --features "$BINDGEN_FEATURES" - ;; - - "expectations") - cd ./tests/expectations - cargo test "$BINDGEN_PROFILE" - ;; - - "misc") - ./ci/assert-docs.sh - ./ci/assert-warnings.sh - ./ci/test-book.sh - ./ci/no-includes.sh - ./ci/assert-rustfmt.sh - ;; - - "quickchecking") - cd ./tests/quickchecking - # TODO: Actually run quickchecks once `bindgen` is reliable enough. - cargo test - ;; - - *) - echo "Error! Unknown \$BINDGEN_JOB: '$BINDGEN_JOB'" - exit 1 -esac diff --git a/ci/test.sh b/ci/test.sh new file mode 100755 index 0000000000..d5bb0bf40d --- /dev/null +++ b/ci/test.sh @@ -0,0 +1,130 @@ +#!/usr/bin/env bash +# Bail on first error +set -e +# Bail if an unset variable is encountered +set -u +# Enable debugging output +set -x +# Give a pipeline a non-zero exit code if one of its constituents fails +set -o pipefail + +function llvm_linux_target_triple() { + echo "x86_64-linux-gnu-ubuntu-16.04" +} + +function llvm_macos_target_triple() { + case "$1" in + [0-8].* | 9.0.0) echo "x86_64-darwin-apple" ;; + # Starting with 9.0.1, triple swapped ordering + *) echo "x86_64-apple-darwin" ;; + esac +} + +function llvm_version_triple() { + case "$1" in + 5.0) echo "5.0.1" ;; + # By default, take the .0 patch release + *) echo "$1.0" ;; + esac +} + +function llvm_base_url() { + local llvm_version_triple=$1 + + case "$llvm_version_triple" in + [0-8].* | 9.0.0) + echo "http://releases.llvm.org/$llvm_version_triple" + ;; + # Starting with 9.0.1, releases are hosted on github + *) + echo "https://github.com/llvm/llvm-project/releases/download/llvmorg-$llvm_version_triple" + ;; + esac +} + +function llvm_download() { + local base_url=$1 + local arch=$2 + + export LLVM=clang+llvm-${LLVM_VERSION_TRIPLE}-$arch + export LLVM_DIRECTORY="$HOME/.llvm/${LLVM}" + + if [ -d "${LLVM_DIRECTORY}" ]; then + echo "Using cached LLVM download for ${LLVM}..." + else + wget --no-verbose $base_url/${LLVM}.tar.xz + mkdir -p "${LLVM_DIRECTORY}" + tar xf ${LLVM}.tar.xz -C "${LLVM_DIRECTORY}" --strip-components=1 + fi + + export LIBCLANG_PATH="${LLVM_DIRECTORY}/lib" + export LLVM_CONFIG_PATH="${LLVM_DIRECTORY}/bin/llvm-config" +} + +# Download and set up a sane LLVM version +set_llvm_env() { + export LLVM_VERSION_TRIPLE=`llvm_version_triple ${LLVM_VERSION}` + local base_url=`llvm_base_url ${LLVM_VERSION_TRIPLE}` + + if [ "$GITHUB_ACTIONS_OS" == "ubuntu-latest" ]; then + llvm_download $base_url `llvm_linux_target_triple ${LLVM_VERSION_TRIPLE}` + export LD_LIBRARY_PATH="${LLVM_DIRECTORY}/lib":${LD_LIBRARY_PATH:-} + else + llvm_download $base_url `llvm_macos_target_triple ${LLVM_VERSION_TRIPLE}` + export DYLD_LIBRARY_PATH="${LLVM_DIRECTORY}/lib":${DYLD_LIBRARY_PATH:-} + fi +} + +# Need rustfmt to compare the test expectations. +set_rustfmt_env() { + local toolchain="nightly-$(curl https://rust-lang.github.io/rustup-components-history/$(rustup target list --installed | tail -1)/rustfmt)" + rustup update "$toolchain" + rustup component add rustfmt --toolchain "$toolchain" + export RUSTFMT="$(rustup which --toolchain "$toolchain" rustfmt)" +} + +assert_no_diff() { + git add -u + git diff @ + git diff-index --quiet HEAD +} + +set_llvm_env +set_rustfmt_env + +get_cargo_args() { + local args="" + if [ "$BINDGEN_RELEASE_BUILD" == "1" ]; then + args+=" --release" + fi + if [ "$BINDGEN_NO_DEFAULT_FEATURES" == "1" ]; then + args+=" --no-default-features" + fi + local features="" + if [ "$BINDGEN_FEATURE_RUNTIME" == "1" ]; then + features+="runtime" + fi + if [ "$BINDGEN_FEATURE_EXTRA_ASSERTS" == "1" ]; then + features+=" testing_only_extra_assertions" + fi + if [ "$BINDGEN_FEATURE_TESTING_ONLY_DOCS" == "1" ]; then + features+=" testing_only_docs" + fi + if [ ! -z "$features" ]; then + args+=" --features $(echo $features | tr ' ' ',')" + fi + echo $args +} + +CARGO_ARGS=`get_cargo_args` + +# Ensure we build without warnings +cargo rustc --lib $CARGO_ARGS -- -Dwarnings + +# Run the tests +cargo test $CARGO_ARGS + +assert_no_diff + +# Run the integration tests +(cd bindgen-integration && cargo test $CARGO_ARGS) diff --git a/tests/quickchecking/.gitignore b/tests/quickchecking/.gitignore new file mode 100644 index 0000000000..03314f77b5 --- /dev/null +++ b/tests/quickchecking/.gitignore @@ -0,0 +1 @@ +Cargo.lock From faf8b3edbaeb591315fc6f370c1228b8caf9860f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sat, 26 Dec 2020 19:58:03 +0100 Subject: [PATCH 133/942] ci: Move the remaining CI tasks (updating the book) to GitHub actions. --- .github/workflows/bindgen.yml | 19 +++++++++++++++++ .github/workflows/deploy-book.yml | 34 +++++++++++++++++++++++++++++++ .travis.yml | 15 -------------- ci/deploy-book.sh | 33 ------------------------------ ci/test-book.sh | 10 --------- 5 files changed, 53 insertions(+), 58 deletions(-) create mode 100644 .github/workflows/deploy-book.yml delete mode 100644 .travis.yml delete mode 100755 ci/deploy-book.sh delete mode 100755 ci/test-book.sh diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 29309e8270..933ac08d67 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -148,3 +148,22 @@ jobs: BINDGEN_FEATURE_TESTING_ONLY_DOCS: ${{matrix.feature_testing_only_docs}} BINDGEN_NO_DEFAULT_FEATURES: ${{matrix.no_default_features}} run: ./ci/test.sh + + test-book: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Install stable + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + # NOTE(emilio): Change deploy-book as well if you change this. + - name: Test book + run: | + cargo install mdbook --root mdbook-install --vers "^0.2.1" --force + ./mdbook-install/bin/mdbook build book + ./mdbook-install/bin/mdbook test book diff --git a/.github/workflows/deploy-book.yml b/.github/workflows/deploy-book.yml new file mode 100644 index 0000000000..4244391add --- /dev/null +++ b/.github/workflows/deploy-book.yml @@ -0,0 +1,34 @@ +name: Deploy book + +on: + push: + branches: + - master + +jobs: + deploy-book: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + persist-credentials: false + + - name: Install stable + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + - name: Test book + run: | + cargo install mdbook --root mdbook-install --vers "^0.2.1" --force + ./mdbook-install/bin/mdbook build book + ./mdbook-install/bin/mdbook test book + + - name: Deploy book + uses: JamesIves/github-pages-deploy-action@3.7.1 + with: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + BRANCH: gh-pages + FOLDER: book/book diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 1e6d4f0aec..0000000000 --- a/.travis.yml +++ /dev/null @@ -1,15 +0,0 @@ -language: rust -dist: xenial -os: - - linux -rust: - - stable -env: - global: - - CARGO_TARGET_DIR=/tmp/bindgen -script: - - ./ci/test-book.sh -after_success: - - test "$TRAVIS_PULL_REQUEST" == "false" && - test "$TRAVIS_BRANCH" == "master" && - ./ci/deploy-book.sh diff --git a/ci/deploy-book.sh b/ci/deploy-book.sh deleted file mode 100755 index 740e095acb..0000000000 --- a/ci/deploy-book.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env bash - -set -xeu -cd "$(dirname "$0")/../book" - -# Ensure mdbook is installed. -cargo install mdbook --vers "^0.2.1" --force || true -export PATH="$PATH:~/.cargo/bin" - -# Get the git revision we are on. -rev=$(git rev-parse --short HEAD) - -# Build the users guide book and go into the built book's directory. -rm -rf ./book -mdbook build -cd ./book - -# Make the built book directory a new git repo, fetch upstream, make a new -# commit on gh-pages, and push it upstream. - -git init -git config user.name "Travis CI" -git config user.email "builds@travis-ci.org" - -git remote add upstream "https://$GH_TOKEN@github.com/rust-lang/rust-bindgen.git" -git fetch upstream -git reset upstream/gh-pages - -touch . - -git add -A . -git commit -m "Rebuild users guide at ${rev}" -git push upstream HEAD:gh-pages diff --git a/ci/test-book.sh b/ci/test-book.sh deleted file mode 100755 index bc2ea333f5..0000000000 --- a/ci/test-book.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash - -set -xeu -cd "$(dirname "$0")/../book" - -cargo install mdbook --vers "^0.2.1" --force || true -export PATH="$PATH:~/.cargo/bin" - -mdbook build -mdbook test From 8945fa637e6e603f8d66fe60f7b5ae54d4134703 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sat, 26 Dec 2020 23:03:37 +0100 Subject: [PATCH 134/942] book: Touch the book to ensure that GH actions deploy works. --- book/src/objc.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/book/src/objc.md b/book/src/objc.md index c7c97811fd..aad7ee60f7 100644 --- a/book/src/objc.md +++ b/book/src/objc.md @@ -34,6 +34,7 @@ foo = Foo(Foo::alloc().initWithStuff())`. ## Supported Features + * Inheritance matched to rust traits with prefixes of `I` which stands for interface. * Protocols which match to rust traits with prefixes of `P` which @@ -43,6 +44,7 @@ name and `id` is a pointer to the objective-c Object. * Blocks ## Useful Notes + * If you're targeting `aarch64-apple-ios`, you'll need to have the clang arg `--target=arm64-apple-ios` as mentioned [here](https://github.com/rust-lang/rust-bindgen/issues/1211#issuecomment-569804287). @@ -63,8 +65,10 @@ all of Core Foundation and any other frameworks. This will result in a very long compile time. ## Not (yet) Supported + * Nullablibility attributes which return `Option`s. * Probably many other things. Feel free to [open an issue](https://github.com/rust-lang/rust-bindgen/issues). # Example crate(s) + * [uikit-sys](https://github.com/simlay/uikit-sys) From 922655f33646b7a126f4c39fb7df60a122d7eb1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sat, 26 Dec 2020 23:16:38 +0100 Subject: [PATCH 135/942] ci: update mdbook. --- .github/workflows/bindgen.yml | 6 +++--- .github/workflows/deploy-book.yml | 6 +++--- book/book.toml | 1 + 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 933ac08d67..493abe2696 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -164,6 +164,6 @@ jobs: # NOTE(emilio): Change deploy-book as well if you change this. - name: Test book run: | - cargo install mdbook --root mdbook-install --vers "^0.2.1" --force - ./mdbook-install/bin/mdbook build book - ./mdbook-install/bin/mdbook test book + curl -L https://github.com/rust-lang/mdBook/releases/download/v0.4.4/mdbook-v0.4.4-x86_64-unknown-linux-gnu.tar.gz | tar xz + ./mdbook build book + ./mdbook test book diff --git a/.github/workflows/deploy-book.yml b/.github/workflows/deploy-book.yml index 4244391add..e5a8806afd 100644 --- a/.github/workflows/deploy-book.yml +++ b/.github/workflows/deploy-book.yml @@ -22,9 +22,9 @@ jobs: - name: Test book run: | - cargo install mdbook --root mdbook-install --vers "^0.2.1" --force - ./mdbook-install/bin/mdbook build book - ./mdbook-install/bin/mdbook test book + curl -L https://github.com/rust-lang/mdBook/releases/download/v0.4.4/mdbook-v0.4.4-x86_64-unknown-linux-gnu.tar.gz | tar xz + ./mdbook build book + ./mdbook test book - name: Deploy book uses: JamesIves/github-pages-deploy-action@3.7.1 diff --git a/book/book.toml b/book/book.toml index e94e304621..340134a32e 100644 --- a/book/book.toml +++ b/book/book.toml @@ -1,3 +1,4 @@ +[book] title = "The `bindgen` User Guide" author = "The Servo project developers" description = "`bindgen` automatically generates Rust FFI bindings to C and C++ libraries." From 9de0d64fc041633c6d0a386a577ddf8ba25dafc3 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 4 Jan 2021 07:48:34 -0800 Subject: [PATCH 136/942] Update mdbook --- .github/workflows/bindgen.yml | 2 +- .github/workflows/deploy-book.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 493abe2696..9aa090754b 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -164,6 +164,6 @@ jobs: # NOTE(emilio): Change deploy-book as well if you change this. - name: Test book run: | - curl -L https://github.com/rust-lang/mdBook/releases/download/v0.4.4/mdbook-v0.4.4-x86_64-unknown-linux-gnu.tar.gz | tar xz + curl -L https://github.com/rust-lang/mdBook/releases/download/v0.4.5/mdbook-v0.4.5-x86_64-unknown-linux-gnu.tar.gz | tar xz ./mdbook build book ./mdbook test book diff --git a/.github/workflows/deploy-book.yml b/.github/workflows/deploy-book.yml index e5a8806afd..bf03d34b63 100644 --- a/.github/workflows/deploy-book.yml +++ b/.github/workflows/deploy-book.yml @@ -22,7 +22,7 @@ jobs: - name: Test book run: | - curl -L https://github.com/rust-lang/mdBook/releases/download/v0.4.4/mdbook-v0.4.4-x86_64-unknown-linux-gnu.tar.gz | tar xz + curl -L https://github.com/rust-lang/mdBook/releases/download/v0.4.5/mdbook-v0.4.5-x86_64-unknown-linux-gnu.tar.gz | tar xz ./mdbook build book ./mdbook test book From 51778893c4cb18eb11cbfe83a72046f7cb0f3eac Mon Sep 17 00:00:00 2001 From: Andrey Pushkar Date: Sat, 1 Aug 2020 19:26:16 +0300 Subject: [PATCH 137/942] Use absolute paths for unsaved files passed to clang and prepend -include directives to them. Fixes #1771 Closes #1857 --- src/lib.rs | 15 ++- .../test_mixed_header_and_header_contents.rs | 111 ++++++++++++++++++ tests/tests.rs | 54 +++++++++ 3 files changed, 178 insertions(+), 2 deletions(-) create mode 100644 tests/expectations/tests/test_mixed_header_and_header_contents.rs diff --git a/src/lib.rs b/src/lib.rs index b9e1bcc56f..2329dee981 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -596,8 +596,16 @@ impl Builder { /// /// The file `name` will be added to the clang arguments. pub fn header_contents(mut self, name: &str, contents: &str) -> Builder { + // Apparently clang relies on having virtual FS correspondent to + // the real one, so we need absolute paths here + let absolute_path = env::current_dir() + .expect("Cannot retrieve current directory") + .join(name) + .to_str() + .expect("Cannot convert current directory name to string") + .to_owned(); self.input_header_contents - .push((name.into(), contents.into())); + .push((absolute_path, contents.into())); self } @@ -2154,7 +2162,10 @@ impl Bindings { } } - for f in options.input_unsaved_files.iter() { + for (idx, f) in options.input_unsaved_files.iter().enumerate() { + if idx != 0 || options.input_header.is_some() { + options.clang_args.push("-include".to_owned()); + } options.clang_args.push(f.name.to_str().unwrap().to_owned()) } diff --git a/tests/expectations/tests/test_mixed_header_and_header_contents.rs b/tests/expectations/tests/test_mixed_header_and_header_contents.rs new file mode 100644 index 0000000000..c97be9b006 --- /dev/null +++ b/tests/expectations/tests/test_mixed_header_and_header_contents.rs @@ -0,0 +1,111 @@ +extern "C" { + pub static mut foo: ::std::option::Option< + unsafe extern "C" fn( + x: ::std::os::raw::c_int, + y: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >; +} +extern "C" { + pub fn bar(a: *const ::std::os::raw::c_char) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn bar2(b: *const ::std::os::raw::c_char) -> f32; +} +pub type Char = ::std::os::raw::c_char; +pub type SChar = ::std::os::raw::c_schar; +pub type UChar = ::std::os::raw::c_uchar; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct Test { + pub ch: ::std::os::raw::c_char, + pub u: ::std::os::raw::c_uchar, + pub d: ::std::os::raw::c_schar, + pub cch: ::std::os::raw::c_char, + pub cu: ::std::os::raw::c_uchar, + pub cd: ::std::os::raw::c_schar, + pub Cch: Char, + pub Cu: UChar, + pub Cd: SChar, + pub Ccch: Char, + pub Ccu: UChar, + pub Ccd: SChar, +} +#[test] +fn bindgen_test_layout_Test() { + assert_eq!( + ::std::mem::size_of::(), + 12usize, + concat!("Size of: ", stringify!(Test)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Test)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).ch as *const _ as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(ch)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).u as *const _ as usize }, + 1usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(u)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).d as *const _ as usize }, + 2usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(d)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).cch as *const _ as usize }, + 3usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(cch)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).cu as *const _ as usize }, + 4usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(cu)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).cd as *const _ as usize }, + 5usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(cd)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).Cch as *const _ as usize }, + 6usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cch)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).Cu as *const _ as usize }, + 7usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cu)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).Cd as *const _ as usize }, + 8usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cd)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).Ccch as *const _ as usize }, + 9usize, + concat!( + "Offset of field: ", + stringify!(Test), + "::", + stringify!(Ccch) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).Ccu as *const _ as usize }, + 10usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccu)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).Ccd as *const _ as usize }, + 11usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccd)) + ); +} diff --git a/tests/tests.rs b/tests/tests.rs index 8b5a91f71c..cd621177d6 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -473,6 +473,60 @@ fn test_multiple_header_calls_in_builder() { } } +#[test] +fn test_multiple_header_contents() { + let actual = builder() + .header_contents("test.h", "int foo(const char* a);") + .header_contents("test2.h", "float foo2(const char* b);") + .clang_arg("--target=x86_64-unknown-linux") + .generate() + .unwrap() + .to_string(); + + let (actual, stderr) = rustfmt(actual); + println!("{}", stderr); + + let (expected, _) = rustfmt( + "extern \"C\" { + pub fn foo2(b: *const ::std::os::raw::c_char) -> f32; +} +extern \"C\" { + pub fn foo(a: *const ::std::os::raw::c_char) -> ::std::os::raw::c_int; +} +" + .to_string(), + ); + + assert_eq!(expected, actual); +} + +#[test] +fn test_mixed_header_and_header_contents() { + let actual = builder() + .header(concat!( + env!("CARGO_MANIFEST_DIR"), + "/tests/headers/func_ptr.h" + )) + .header(concat!(env!("CARGO_MANIFEST_DIR"), "/tests/headers/char.h")) + .header_contents("test.h", "int bar(const char* a);") + .header_contents("test2.h", "float bar2(const char* b);") + .clang_arg("--target=x86_64-unknown-linux") + .generate() + .unwrap() + .to_string(); + + let (actual, stderr) = rustfmt(actual); + println!("{}", stderr); + + let expected = include_str!(concat!( + env!("CARGO_MANIFEST_DIR"), + "/tests/expectations/tests/test_mixed_header_and_header_contents.rs" + )); + let (expected, _) = rustfmt(expected.to_string()); + + assert_eq!(expected, actual); +} + #[test] // Doesn't support executing sh file on Windows. // We may want to implement it in Rust so that we support all systems. From e0f06c7fb2c59ab1154a4aba92cb885b1342a2fc Mon Sep 17 00:00:00 2001 From: Weston Carvalho Date: Wed, 13 Jan 2021 10:04:50 -0800 Subject: [PATCH 138/942] Generate fields as non-pub if they would be access restricted in C++. --- src/clang.rs | 9 + src/codegen/mod.rs | 54 +- src/ir/comp.rs | 52 +- src/lib.rs | 15 + src/options.rs | 7 + .../tests/no_debug_whitelisted.rs | 7 +- tests/expectations/tests/private_fields.rs | 522 ++++++++++++++++++ tests/headers/private_fields.hpp | 44 ++ 8 files changed, 684 insertions(+), 26 deletions(-) create mode 100644 tests/expectations/tests/private_fields.rs create mode 100644 tests/headers/private_fields.hpp diff --git a/src/clang.rs b/src/clang.rs index 488660c434..661250894e 100644 --- a/src/clang.rs +++ b/src/clang.rs @@ -632,6 +632,15 @@ impl Cursor { unsafe { clang_getCXXAccessSpecifier(self.x) } } + /// Is the cursor's referrent publically accessible in C++? + /// + /// Returns true if self.access_specifier() is `CX_CXXPublic` or + /// `CX_CXXInvalidAccessSpecifier`. + pub fn public_accessible(&self) -> bool { + let access = self.access_specifier(); + access == CX_CXXPublic || access == CX_CXXInvalidAccessSpecifier + } + /// Is this cursor's referent a field declaration that is marked as /// `mutable`? pub fn is_mutable_field(&self) -> bool { diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 194a461c63..cad2f47e50 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -1271,10 +1271,11 @@ impl<'a> FieldCodegen<'a> for FieldData { } } - let is_private = self - .annotations() - .private_fields() - .unwrap_or(fields_should_be_private); + let is_private = (!self.is_public() && + ctx.options().respect_cxx_access_specs) || + self.annotations() + .private_fields() + .unwrap_or(fields_should_be_private); let accessor_kind = self.annotations().accessor_kind().unwrap_or(accessor_kind); @@ -1395,6 +1396,17 @@ impl Bitfield { } } +fn access_specifier( + ctx: &BindgenContext, + is_pub: bool, +) -> proc_macro2::TokenStream { + if is_pub || !ctx.options().respect_cxx_access_specs { + quote! { pub } + } else { + quote! {} + } +} + impl<'a> FieldCodegen<'a> for BitfieldUnit { type Extra = (); @@ -1455,11 +1467,6 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit { let unit_field_name = format!("_bitfield_{}", self.nth()); let unit_field_ident = ctx.rust_ident(&unit_field_name); - let field = quote! { - pub #unit_field_ident : #field_ty , - }; - fields.extend(Some(field)); - let ctor_name = self.ctor_name(); let mut ctor_params = vec![]; let mut ctor_impl = quote! {}; @@ -1468,6 +1475,7 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit { // implement AsRef<[u8]> / AsMut<[u8]> / etc. let mut generate_ctor = layout.size <= RUST_DERIVE_IN_ARRAY_LIMIT; + let mut access_spec = !fields_should_be_private; for bf in self.bitfields() { // Codegen not allowed for anonymous bitfields if bf.name().is_none() { @@ -1478,6 +1486,7 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit { continue; } + access_spec &= bf.is_public(); let mut bitfield_representable_as_int = true; bf.codegen( @@ -1511,10 +1520,17 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit { ctor_impl = bf.extend_ctor_impl(ctx, param_name, ctor_impl); } + let access_spec = access_specifier(ctx, access_spec); + + let field = quote! { + #access_spec #unit_field_ident : #field_ty , + }; + fields.extend(Some(field)); + if generate_ctor { methods.extend(Some(quote! { #[inline] - pub fn #ctor_name ( #( #ctor_params ),* ) -> #unit_field_ty { + #access_spec fn #ctor_name ( #( #ctor_params ),* ) -> #unit_field_ty { let mut __bindgen_bitfield_unit: #unit_field_ty = Default::default(); #ctor_impl __bindgen_bitfield_unit @@ -1550,7 +1566,7 @@ impl<'a> FieldCodegen<'a> for Bitfield { fn codegen( &self, ctx: &BindgenContext, - _fields_should_be_private: bool, + fields_should_be_private: bool, _codegen_depth: usize, _accessor_kind: FieldAccessorKind, parent: &CompInfo, @@ -1590,13 +1606,16 @@ impl<'a> FieldCodegen<'a> for Bitfield { bitfield_ty.to_rust_ty_or_opaque(ctx, bitfield_ty_item); let offset = self.offset_into_unit(); - let width = self.width() as u8; + let access_spec = access_specifier( + ctx, + self.is_public() && !fields_should_be_private, + ); if parent.is_union() && !parent.can_be_rust_union(ctx) { methods.extend(Some(quote! { #[inline] - pub fn #getter_name(&self) -> #bitfield_ty { + #access_spec fn #getter_name(&self) -> #bitfield_ty { unsafe { ::#prefix::mem::transmute( self.#unit_field_ident.as_ref().get(#offset, #width) @@ -1606,7 +1625,7 @@ impl<'a> FieldCodegen<'a> for Bitfield { } #[inline] - pub fn #setter_name(&mut self, val: #bitfield_ty) { + #access_spec fn #setter_name(&mut self, val: #bitfield_ty) { unsafe { let val: #bitfield_int_ty = ::#prefix::mem::transmute(val); self.#unit_field_ident.as_mut().set( @@ -1620,7 +1639,7 @@ impl<'a> FieldCodegen<'a> for Bitfield { } else { methods.extend(Some(quote! { #[inline] - pub fn #getter_name(&self) -> #bitfield_ty { + #access_spec fn #getter_name(&self) -> #bitfield_ty { unsafe { ::#prefix::mem::transmute( self.#unit_field_ident.get(#offset, #width) @@ -1630,7 +1649,7 @@ impl<'a> FieldCodegen<'a> for Bitfield { } #[inline] - pub fn #setter_name(&mut self, val: #bitfield_ty) { + #access_spec fn #setter_name(&mut self, val: #bitfield_ty) { unsafe { let val: #bitfield_int_ty = ::#prefix::mem::transmute(val); self.#unit_field_ident.set( @@ -1717,8 +1736,9 @@ impl CodeGenerator for CompInfo { struct_layout.saw_base(inner_item.expect_type()); + let access_spec = access_specifier(ctx, base.is_public()); fields.push(quote! { - pub #field_name: #inner, + #access_spec #field_name: #inner, }); } } diff --git a/src/ir/comp.rs b/src/ir/comp.rs index a0ca925c20..60b1e2f0ff 100644 --- a/src/ir/comp.rs +++ b/src/ir/comp.rs @@ -148,6 +148,9 @@ pub trait FieldMethods { /// If this is a bitfield, how many bits does it need? fn bitfield_width(&self) -> Option; + /// Is this feild declared public? + fn is_public(&self) -> bool; + /// Get the annotations for this field. fn annotations(&self) -> &Annotations; @@ -412,6 +415,10 @@ impl FieldMethods for Bitfield { self.data.bitfield_width() } + fn is_public(&self) -> bool { + self.data.is_public() + } + fn annotations(&self) -> &Annotations { self.data.annotations() } @@ -436,6 +443,7 @@ impl RawField { comment: Option, annotations: Option, bitfield_width: Option, + public: bool, offset: Option, ) -> RawField { RawField(FieldData { @@ -444,6 +452,7 @@ impl RawField { comment, annotations: annotations.unwrap_or_default(), bitfield_width, + public, offset, }) } @@ -466,6 +475,10 @@ impl FieldMethods for RawField { self.0.bitfield_width() } + fn is_public(&self) -> bool { + self.0.is_public() + } + fn annotations(&self) -> &Annotations { self.0.annotations() } @@ -878,6 +891,9 @@ pub struct FieldData { /// If this field is a bitfield, and how many bits does it contain if it is. bitfield_width: Option, + /// If the C++ field is declared `public` + public: bool, + /// The offset of the field (in bits) offset: Option, } @@ -899,6 +915,10 @@ impl FieldMethods for FieldData { self.bitfield_width } + fn is_public(&self) -> bool { + self.public + } + fn annotations(&self) -> &Annotations { &self.annotations } @@ -934,6 +954,8 @@ pub struct Base { pub kind: BaseKind, /// Name of the field in which this base should be stored. pub field_name: String, + /// Whether this base is inherited from publically. + pub is_pub: bool, } impl Base { @@ -961,6 +983,11 @@ impl Base { true } + + /// Whether this base is inherited from publically. + pub fn is_public(&self) -> bool { + self.is_pub + } } /// A compound type. @@ -1230,7 +1257,7 @@ impl CompInfo { let mut maybe_anonymous_struct_field = None; cursor.visit(|cur| { if cur.kind() != CXCursor_FieldDecl { - if let Some((ty, clang_ty, offset)) = + if let Some((ty, clang_ty, public, offset)) = maybe_anonymous_struct_field.take() { if cur.kind() == CXCursor_TypedefDecl && @@ -1242,8 +1269,9 @@ impl CompInfo { // anonymous field. Detect that case here, and do // nothing. } else { - let field = - RawField::new(None, ty, None, None, None, offset); + let field = RawField::new( + None, ty, None, None, None, public, offset, + ); ci.fields.append_raw_field(field); } } @@ -1251,7 +1279,7 @@ impl CompInfo { match cur.kind() { CXCursor_FieldDecl => { - if let Some((ty, clang_ty, offset)) = + if let Some((ty, clang_ty, public, offset)) = maybe_anonymous_struct_field.take() { let mut used = false; @@ -1261,9 +1289,10 @@ impl CompInfo { } CXChildVisit_Continue }); + if !used { let field = RawField::new( - None, ty, None, None, None, offset, + None, ty, None, None, None, public, offset, ); ci.fields.append_raw_field(field); } @@ -1280,6 +1309,7 @@ impl CompInfo { let comment = cur.raw_comment(); let annotations = Annotations::new(&cur); let name = cur.spelling(); + let is_public = cur.public_accessible(); let offset = cur.offset_of_field().ok(); // Name can be empty if there are bitfields, for example, @@ -1297,6 +1327,7 @@ impl CompInfo { comment, annotations, bit_width, + is_public, offset, ); ci.fields.append_raw_field(field); @@ -1353,9 +1384,11 @@ impl CompInfo { cur.kind() != CXCursor_EnumDecl { let ty = cur.cur_type(); + let public = cur.public_accessible(); let offset = cur.offset_of_field().ok(); + maybe_anonymous_struct_field = - Some((inner, ty, offset)); + Some((inner, ty, public, offset)); } } CXCursor_PackedAttr => { @@ -1388,6 +1421,8 @@ impl CompInfo { ty: type_id, kind, field_name, + is_pub: cur.access_specifier() == + clang_sys::CX_CXXPublic, }); } CXCursor_Constructor | CXCursor_Destructor | @@ -1503,8 +1538,9 @@ impl CompInfo { CXChildVisit_Continue }); - if let Some((ty, _, offset)) = maybe_anonymous_struct_field { - let field = RawField::new(None, ty, None, None, None, offset); + if let Some((ty, _, public, offset)) = maybe_anonymous_struct_field { + let field = + RawField::new(None, ty, None, None, None, public, offset); ci.fields.append_raw_field(field); } diff --git a/src/lib.rs b/src/lib.rs index 2329dee981..8dcba3fb97 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -545,6 +545,10 @@ impl Builder { output_vector.push(name.clone()); } + if self.options.respect_cxx_access_specs { + output_vector.push("--respect-cxx-access-specs".into()); + } + // Add clang arguments output_vector.push("--".into()); @@ -1518,6 +1522,12 @@ impl Builder { self.options.dynamic_library_name = Some(dynamic_library_name.into()); self } + + /// Generate bindings as `pub` only if the bound item is publically accessible by C++. + pub fn respect_cxx_access_specs(mut self, doit: bool) -> Self { + self.options.respect_cxx_access_specs = doit; + self + } } /// Configuration options for generated bindings. @@ -1805,6 +1815,10 @@ struct BindgenOptions { /// The name of the dynamic library (if we are generating bindings for a shared library). If /// this is None, no dynamic bindings are created. dynamic_library_name: Option, + + /// Only make generated bindings `pub` if the items would be publically accessible + /// by C++. + respect_cxx_access_specs: bool, } /// TODO(emilio): This is sort of a lie (see the error message that results from @@ -1941,6 +1955,7 @@ impl Default for BindgenOptions { array_pointers_in_arguments: false, wasm_import_module_name: None, dynamic_library_name: None, + respect_cxx_access_specs: false, } } } diff --git a/src/options.rs b/src/options.rs index 7d3e077ee8..63e48dc830 100644 --- a/src/options.rs +++ b/src/options.rs @@ -493,6 +493,9 @@ where .long("dynamic-loading") .takes_value(true) .help("Use dynamic loading mode with the given library name."), + Arg::with_name("respect-cxx-access-specs") + .long("respect-cxx-access-specs") + .help("Makes generated bindings `pub` only for items if the items are publically accessible in C++."), ]) // .args() .get_matches_from(args); @@ -915,6 +918,10 @@ where builder = builder.dynamic_library_name(dynamic_library_name); } + if matches.is_present("respect-cxx-access-specs") { + builder = builder.respect_cxx_access_specs(true); + } + let verbose = matches.is_present("verbose"); Ok((builder, output, verbose)) diff --git a/tests/expectations/tests/no_debug_whitelisted.rs b/tests/expectations/tests/no_debug_whitelisted.rs index ac43e4ea5a..e240d645fb 100644 --- a/tests/expectations/tests/no_debug_whitelisted.rs +++ b/tests/expectations/tests/no_debug_whitelisted.rs @@ -25,6 +25,11 @@ fn bindgen_test_layout_NoDebug() { assert_eq!( unsafe { &(*(::std::ptr::null::())).i as *const _ as usize }, 0usize, - concat!("Offset of field: ", stringify!(NoDebug), "::", stringify!(i)) + concat!( + "Offset of field: ", + stringify!(NoDebug), + "::", + stringify!(i) + ) ); } diff --git a/tests/expectations/tests/private_fields.rs b/tests/expectations/tests/private_fields.rs new file mode 100644 index 0000000000..f5edccae41 --- /dev/null +++ b/tests/expectations/tests/private_fields.rs @@ -0,0 +1,522 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[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] + 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]; + 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 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]; + 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 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 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); + } + } +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct PubPriv { + pub x: ::std::os::raw::c_int, + y: ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout_PubPriv() { + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(PubPriv)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(PubPriv)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).x as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(PubPriv), + "::", + stringify!(x) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).y as *const _ as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(PubPriv), + "::", + stringify!(y) + ) + ); +} +#[repr(C)] +#[repr(align(4))] +#[derive(Debug, Default, Copy, Clone)] +pub struct PrivateBitFields { + pub _bitfield_align_1: [u8; 0], + _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, + pub __bindgen_padding_0: [u8; 3usize], +} +#[test] +fn bindgen_test_layout_PrivateBitFields() { + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(PrivateBitFields)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(PrivateBitFields)) + ); +} +impl PrivateBitFields { + #[inline] + fn a(&self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute(self._bitfield_1.get(0usize, 4u8) as u32) + } + } + #[inline] + fn set_a(&mut self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + self._bitfield_1.set(0usize, 4u8, val as u64) + } + } + #[inline] + fn b(&self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute(self._bitfield_1.get(4usize, 4u8) as u32) + } + } + #[inline] + fn set_b(&mut self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + self._bitfield_1.set(4usize, 4u8, val as u64) + } + } + #[inline] + fn new_bitfield_1( + a: ::std::os::raw::c_uint, + b: ::std::os::raw::c_uint, + ) -> __BindgenBitfieldUnit<[u8; 1usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = + Default::default(); + __bindgen_bitfield_unit.set(0usize, 4u8, { + let a: u32 = unsafe { ::std::mem::transmute(a) }; + a as u64 + }); + __bindgen_bitfield_unit.set(4usize, 4u8, { + let b: u32 = unsafe { ::std::mem::transmute(b) }; + b as u64 + }); + __bindgen_bitfield_unit + } +} +#[repr(C)] +#[repr(align(4))] +#[derive(Debug, Default, Copy, Clone)] +pub struct PublicBitFields { + pub _bitfield_align_1: [u8; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, + pub __bindgen_padding_0: [u8; 3usize], +} +#[test] +fn bindgen_test_layout_PublicBitFields() { + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(PublicBitFields)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(PublicBitFields)) + ); +} +impl PublicBitFields { + #[inline] + pub fn a(&self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute(self._bitfield_1.get(0usize, 4u8) as u32) + } + } + #[inline] + pub fn set_a(&mut self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + self._bitfield_1.set(0usize, 4u8, val as u64) + } + } + #[inline] + pub fn b(&self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute(self._bitfield_1.get(4usize, 4u8) as u32) + } + } + #[inline] + pub fn set_b(&mut self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + self._bitfield_1.set(4usize, 4u8, val as u64) + } + } + #[inline] + pub fn new_bitfield_1( + a: ::std::os::raw::c_uint, + b: ::std::os::raw::c_uint, + ) -> __BindgenBitfieldUnit<[u8; 1usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = + Default::default(); + __bindgen_bitfield_unit.set(0usize, 4u8, { + let a: u32 = unsafe { ::std::mem::transmute(a) }; + a as u64 + }); + __bindgen_bitfield_unit.set(4usize, 4u8, { + let b: u32 = unsafe { ::std::mem::transmute(b) }; + b as u64 + }); + __bindgen_bitfield_unit + } +} +#[repr(C)] +#[repr(align(4))] +#[derive(Debug, Default, Copy, Clone)] +pub struct MixedBitFields { + pub _bitfield_align_1: [u8; 0], + _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, + pub __bindgen_padding_0: [u8; 3usize], +} +#[test] +fn bindgen_test_layout_MixedBitFields() { + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(MixedBitFields)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(MixedBitFields)) + ); +} +impl MixedBitFields { + #[inline] + fn a(&self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute(self._bitfield_1.get(0usize, 4u8) as u32) + } + } + #[inline] + fn set_a(&mut self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + self._bitfield_1.set(0usize, 4u8, val as u64) + } + } + #[inline] + pub fn d(&self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute(self._bitfield_1.get(4usize, 4u8) as u32) + } + } + #[inline] + pub fn set_d(&mut self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + self._bitfield_1.set(4usize, 4u8, val as u64) + } + } + #[inline] + fn new_bitfield_1( + a: ::std::os::raw::c_uint, + d: ::std::os::raw::c_uint, + ) -> __BindgenBitfieldUnit<[u8; 1usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = + Default::default(); + __bindgen_bitfield_unit.set(0usize, 4u8, { + let a: u32 = unsafe { ::std::mem::transmute(a) }; + a as u64 + }); + __bindgen_bitfield_unit.set(4usize, 4u8, { + let d: u32 = unsafe { ::std::mem::transmute(d) }; + d as u64 + }); + __bindgen_bitfield_unit + } +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Base { + pub member: ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout_Base() { + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Base)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Base)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).member as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Base), + "::", + stringify!(member) + ) + ); +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct InheritsPrivately { + _base: Base, +} +#[test] +fn bindgen_test_layout_InheritsPrivately() { + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(InheritsPrivately)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(InheritsPrivately)) + ); +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct InheritsPublically { + pub _base: Base, +} +#[test] +fn bindgen_test_layout_InheritsPublically() { + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(InheritsPublically)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(InheritsPublically)) + ); +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct WithAnonStruct { + __bindgen_anon_1: WithAnonStruct__bindgen_ty_1, + pub __bindgen_anon_2: WithAnonStruct__bindgen_ty_2, +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct WithAnonStruct__bindgen_ty_1 { + pub a: ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout_WithAnonStruct__bindgen_ty_1() { + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(WithAnonStruct__bindgen_ty_1)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(WithAnonStruct__bindgen_ty_1)) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).a + as *const _ as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithAnonStruct__bindgen_ty_1), + "::", + stringify!(a) + ) + ); +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct WithAnonStruct__bindgen_ty_2 { + pub b: ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout_WithAnonStruct__bindgen_ty_2() { + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(WithAnonStruct__bindgen_ty_2)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(WithAnonStruct__bindgen_ty_2)) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).b + as *const _ as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithAnonStruct__bindgen_ty_2), + "::", + stringify!(b) + ) + ); +} +#[test] +fn bindgen_test_layout_WithAnonStruct() { + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(WithAnonStruct)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(WithAnonStruct)) + ); +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct WithAnonUnion { + __bindgen_anon_1: WithAnonUnion__bindgen_ty_1, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub union WithAnonUnion__bindgen_ty_1 { + _bindgen_union_align: u8, + pub _address: u8, +} +#[test] +fn bindgen_test_layout_WithAnonUnion__bindgen_ty_1() { + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(WithAnonUnion__bindgen_ty_1)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(WithAnonUnion__bindgen_ty_1)) + ); +} +impl Default for WithAnonUnion__bindgen_ty_1 { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +#[test] +fn bindgen_test_layout_WithAnonUnion() { + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(WithAnonUnion)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(WithAnonUnion)) + ); +} +impl Default for WithAnonUnion { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} diff --git a/tests/headers/private_fields.hpp b/tests/headers/private_fields.hpp new file mode 100644 index 0000000000..9d55ebcac8 --- /dev/null +++ b/tests/headers/private_fields.hpp @@ -0,0 +1,44 @@ +// bindgen-flags: --respect-cxx-access-specs +class PubPriv { + public: + int x; + private: + int y; +}; + +class PrivateBitFields { + unsigned int a : 4; + unsigned int b : 4; +}; +class PublicBitFields { + public: + unsigned int a : 4; + unsigned int b : 4; +}; +class MixedBitFields { + unsigned int a : 4; + public: + unsigned int d : 4; +}; + +class Base { + public: + int member; +}; + +class InheritsPrivately : Base {}; +class InheritsPublically : public Base {}; + +class WithAnonStruct { + struct { + int a; + }; + public: + struct { + int b; + }; +}; + +class WithAnonUnion { + union {}; +}; \ No newline at end of file From c509ef12acd198ffdde2af02148002257b60912a Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sat, 30 Jan 2021 09:33:17 -0500 Subject: [PATCH 139/942] Add failing regression test for #1973. --- bindgen-integration/cpp/Test.cc | 9 +++++++++ bindgen-integration/cpp/Test.h | 6 ++++++ bindgen-integration/src/lib.rs | 9 +++++++++ 3 files changed, 24 insertions(+) diff --git a/bindgen-integration/cpp/Test.cc b/bindgen-integration/cpp/Test.cc index 240109bbe3..71a0a4b9c7 100644 --- a/bindgen-integration/cpp/Test.cc +++ b/bindgen-integration/cpp/Test.cc @@ -135,3 +135,12 @@ Seventh::assert(bool first, int my_prefixed_function_name() { return 4; } + +Coord coord(double x, double y, double z, double t) { + Coord res; + res.v[0] = x; + res.v[1] = y; + res.v[2] = z; + res.v[3] = t; + return res; +} diff --git a/bindgen-integration/cpp/Test.h b/bindgen-integration/cpp/Test.h index 7605d9f0f3..51a6e4b87f 100644 --- a/bindgen-integration/cpp/Test.h +++ b/bindgen-integration/cpp/Test.h @@ -226,3 +226,9 @@ struct my_prefixed_templated_foo { my_prefixed_templated_foo TEMPLATED_CONST_VALUE; void my_prefixed_function_to_remove(); + +typedef union { + double v[4]; +} Coord; + +Coord coord(double x, double y, double z, double t); diff --git a/bindgen-integration/src/lib.rs b/bindgen-integration/src/lib.rs index 088e808337..c145d895e0 100755 --- a/bindgen-integration/src/lib.rs +++ b/bindgen-integration/src/lib.rs @@ -259,3 +259,12 @@ fn test_macro_customintkind_path() { let v: &std::any::Any = &bindings::TESTMACRO_CUSTOMINTKIND_PATH; assert!(v.is::()) } + +// https://github.com/rust-lang/rust-bindgen/issues/1973 +#[test] +fn test_homogeneous_aggregate_float_union() { + unsafe { + let coord = &bindings::coord(1., 2., 3., 4.); + assert_eq!([1., 2., 3., 4.], coord.v) + } +} From 5ca2fc7a0221cacde41fd60b0ce485ee5ab8dac3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 1 Feb 2021 14:05:43 +0100 Subject: [PATCH 140/942] v0.57.0 --- CHANGELOG.md | 17 +++++++++++++++++ Cargo.lock | 2 +- Cargo.toml | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8eed4d13d0..7532e5e60c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -132,6 +132,23 @@ --- +# 0.57.0 + +Released 2020/02/01 + +# Added + +* Expose module-raw-lines to the CLI (#1936) +* Added an option to fit macro constants to smaller types (#1945) +* Add an option to respect C++ access specifiers on fields (#1968) + +## Fixed + +* Improved C++ auto-detection (#1933) +* Fixed layout of bitfields in some edge cases (#1950) +* Escape the dyn keyword properly (#1951) +* Use absolute paths for unsaved files passed to clang (#1857). + # 0.56.0 Released 2020/11/26 diff --git a/Cargo.lock b/Cargo.lock index 589076f2f9..7e09431db4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -31,7 +31,7 @@ dependencies = [ [[package]] name = "bindgen" -version = "0.56.0" +version = "0.57.0" dependencies = [ "bitflags", "cexpr", diff --git a/Cargo.toml b/Cargo.toml index 3516fc2584..4f8ac75da1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ readme = "README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.56.0" +version = "0.57.0" edition = "2018" build = "build.rs" From 43a05656ae1949a59d95fb62300df1d0ee76de39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 1 Feb 2021 14:08:28 +0100 Subject: [PATCH 141/942] Fix changelog (run doctoc, plus we're in 2021 already) --- CHANGELOG.md | 91 +++++++++++++++++++++++++++------------------------- 1 file changed, 47 insertions(+), 44 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7532e5e60c..cafadb0698 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,108 +9,111 @@ - [Removed](#removed) - [Fixed](#fixed) - [Security](#security) +- [0.57.0](#0570) +- [Added](#added-1) + - [Fixed](#fixed-1) - [0.56.0](#0560) - - [Added](#added-1) + - [Added](#added-2) - [Changed](#changed-1) - - [Fixed](#fixed-1) -- [0.55.1](#0551) - [Fixed](#fixed-2) +- [0.55.1](#0551) + - [Fixed](#fixed-3) - [0.55.0](#0550) - [Removed](#removed-1) - - [Added](#added-2) - - [Changed](#changed-2) - - [Fixed](#fixed-3) -- [0.54.1](#0541) - [Added](#added-3) - - [Changed](#changed-3) + - [Changed](#changed-2) - [Fixed](#fixed-4) -- [0.54.0](#0540) +- [0.54.1](#0541) - [Added](#added-4) - - [Changed](#changed-4) + - [Changed](#changed-3) - [Fixed](#fixed-5) -- [0.53.3](#0533) +- [0.54.0](#0540) - [Added](#added-5) + - [Changed](#changed-4) - [Fixed](#fixed-6) +- [0.53.3](#0533) + - [Added](#added-6) + - [Fixed](#fixed-7) - [0.53.2](#0532) - [Changed](#changed-5) - [0.53.1](#0531) - - [Added](#added-6) -- [0.53.0](#0530) - [Added](#added-7) +- [0.53.0](#0530) + - [Added](#added-8) - [Changed](#changed-6) - - [Fixed](#fixed-7) + - [Fixed](#fixed-8) - [0.52.0](#0520) - - [Added](#added-8) + - [Added](#added-9) - [Changed](#changed-7) - - [Fixed](#fixed-8) -- [0.51.1](#0511) - [Fixed](#fixed-9) +- [0.51.1](#0511) + - [Fixed](#fixed-10) - [Changed](#changed-8) - [0.51.0](#0510) - - [Fixed](#fixed-10) + - [Fixed](#fixed-11) - [Changed](#changed-9) - - [Added](#added-9) -- [0.50.0](#0500) - [Added](#added-10) -- [0.49.3](#0493) +- [0.50.0](#0500) - [Added](#added-11) +- [0.49.3](#0493) + - [Added](#added-12) - [0.49.2](#0492) - [Changed](#changed-10) - [0.49.1](#0491) - - [Fixed](#fixed-11) + - [Fixed](#fixed-12) - [Changed](#changed-11) - [0.49.0](#0490) - - [Added](#added-12) - - [Fixed](#fixed-12) + - [Added](#added-13) + - [Fixed](#fixed-13) - [Changed](#changed-12) - [0.48.1](#0481) - - [Fixed](#fixed-13) + - [Fixed](#fixed-14) - [0.48.0](#0480) - [Changed](#changed-13) - - [Fixed](#fixed-14) + - [Fixed](#fixed-15) - [0.47.4](#0474) - - [Added](#added-13) + - [Added](#added-14) - [0.47.3](#0473) - [Changed](#changed-14) - [0.47.2](#0472) - - [Fixed](#fixed-15) + - [Fixed](#fixed-16) - [0.47.1](#0471) - [Changed](#changed-15) - - [Fixed](#fixed-16) + - [Fixed](#fixed-17) - [0.47.0](#0470) - [Changed](#changed-16) - - [Fixed](#fixed-17) + - [Fixed](#fixed-18) - [0.33.1 .. 0.46.0](#0331--0460) - - [Added](#added-14) + - [Added](#added-15) - [Removed](#removed-2) - [Changed](#changed-17) - - [Fixed](#fixed-18) -- [0.33.1](#0331) - [Fixed](#fixed-19) +- [0.33.1](#0331) + - [Fixed](#fixed-20) - [0.33.0](#0330) - [0.32.2](#0322) - - [Fixed](#fixed-20) -- [0.32.1](#0321) - [Fixed](#fixed-21) +- [0.32.1](#0321) + - [Fixed](#fixed-22) - [0.32.0](#0320) - - [Added](#added-15) + - [Added](#added-16) - [Changed](#changed-18) - - [Fixed](#fixed-22) + - [Fixed](#fixed-23) - [0.31.0](#0310) - - [Added](#added-16) + - [Added](#added-17) - [Changed](#changed-19) - [Deprecated](#deprecated-1) - [Removed](#removed-3) - - [Fixed](#fixed-23) + - [Fixed](#fixed-24) - [0.30.0](#0300) - - [Added](#added-17) + - [Added](#added-18) - [Changed](#changed-20) - [Deprecated](#deprecated-2) - - [Fixed](#fixed-24) + - [Fixed](#fixed-25) - [0.29.0](#0290) - - [Added](#added-18) + - [Added](#added-19) - [Changed](#changed-21) - - [Fixed](#fixed-25) + - [Fixed](#fixed-26) @@ -134,7 +137,7 @@ # 0.57.0 -Released 2020/02/01 +Released 2021/02/01 # Added From 0f8ceb68fd16e2b2a6c95a0e919dff4989cd0dec Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sun, 31 Jan 2021 16:34:27 -0500 Subject: [PATCH 142/942] Run tests on AArch64 --- .github/workflows/bindgen.yml | 23 +++++++++++++++++++++++ bindgen-integration/src/lib.rs | 1 + ci/test.sh | 16 +++++++++++++--- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 9aa090754b..0a340badcc 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -149,6 +149,29 @@ jobs: BINDGEN_NO_DEFAULT_FEATURES: ${{matrix.no_default_features}} run: ./ci/test.sh + test_aarch64: + name: "Run tests on AArch64" + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + - uses: uraimo/run-on-arch-action@v2.0.8 + name: Run test commands + with: + arch: aarch64 + distro: ubuntu20.04 + githubToken: ${{ github.token }} + env: | + LLVM_VERSION: "10.0" + dockerRunArgs: | + --volume "${HOME}/.cargo:/root/.cargo" + install: | + apt-get update -q -y + apt-get install -q -y curl gcc git g++ libtinfo5 xz-utils + run: | + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal + source $HOME/.cargo/env + ./ci/test.sh + test-book: runs-on: ubuntu-latest steps: diff --git a/bindgen-integration/src/lib.rs b/bindgen-integration/src/lib.rs index c145d895e0..0d6989616c 100755 --- a/bindgen-integration/src/lib.rs +++ b/bindgen-integration/src/lib.rs @@ -261,6 +261,7 @@ fn test_macro_customintkind_path() { } // https://github.com/rust-lang/rust-bindgen/issues/1973 +#[cfg_attr(target_arch = "aarch64", should_panic)] // This line should be removed after the bug linked above is fixed #[test] fn test_homogeneous_aggregate_float_union() { unsafe { diff --git a/ci/test.sh b/ci/test.sh index d5bb0bf40d..cc83475582 100755 --- a/ci/test.sh +++ b/ci/test.sh @@ -8,8 +8,18 @@ set -x # Give a pipeline a non-zero exit code if one of its constituents fails set -o pipefail +# Set default values on environment variables +BINDGEN_RELEASE_BUILD="${BINDGEN_RELEASE_BUILD:-0}" +BINDGEN_FEATURE_RUNTIME="${BINDGEN_FEATURE_RUNTIME:-0}" +BINDGEN_FEATURE_EXTRA_ASSERTS="${BINDGEN_FEATURE_EXTRA_ASSERTS:-0}" +BINDGEN_FEATURE_TESTING_ONLY_DOCS="${BINDGEN_FEATURE_TESTING_ONLY_DOCS:-0}" +BINDGEN_NO_DEFAULT_FEATURES="${BINDGEN_NO_DEFAULT_FEATURES:-0}" + function llvm_linux_target_triple() { - echo "x86_64-linux-gnu-ubuntu-16.04" + case "$(uname -m)" in + aarch64) echo "aarch64-linux-gnu" ;; + *) echo "x86_64-linux-gnu-ubuntu-16.04" ;; + esac } function llvm_macos_target_triple() { @@ -52,7 +62,7 @@ function llvm_download() { if [ -d "${LLVM_DIRECTORY}" ]; then echo "Using cached LLVM download for ${LLVM}..." else - wget --no-verbose $base_url/${LLVM}.tar.xz + curl -L -o ${LLVM}.tar.xz $base_url/${LLVM}.tar.xz mkdir -p "${LLVM_DIRECTORY}" tar xf ${LLVM}.tar.xz -C "${LLVM_DIRECTORY}" --strip-components=1 fi @@ -66,7 +76,7 @@ set_llvm_env() { export LLVM_VERSION_TRIPLE=`llvm_version_triple ${LLVM_VERSION}` local base_url=`llvm_base_url ${LLVM_VERSION_TRIPLE}` - if [ "$GITHUB_ACTIONS_OS" == "ubuntu-latest" ]; then + if [ "$(uname -s)" == "Linux" ]; then llvm_download $base_url `llvm_linux_target_triple ${LLVM_VERSION_TRIPLE}` export LD_LIBRARY_PATH="${LLVM_DIRECTORY}/lib":${LD_LIBRARY_PATH:-} else From 17476e9f4eee21cf7fe9aee5f5b68538bfcce169 Mon Sep 17 00:00:00 2001 From: Aaron Miller <829076+AaronM04@users.noreply.github.com> Date: Thu, 4 Feb 2021 21:27:15 -0800 Subject: [PATCH 143/942] OpenBSD requirements --- book/src/requirements.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/book/src/requirements.md b/book/src/requirements.md index 8a9597799f..921b6044f1 100644 --- a/book/src/requirements.md +++ b/book/src/requirements.md @@ -63,6 +63,14 @@ repos to get version 3.9. See http://apt.llvm.org/. # pacman -S clang ``` +#### OpenBSD + +```bash +# pkg_add llvm +``` + +Add `export LIBCLANG_PATH=/usr/local/lib` to your profile. + #### From source If your package manager doesn't yet offer Clang 3.9, you'll need to build from From 8ac787a9b4fab937533b964a3ee8d0bff840bf08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 7 Feb 2021 19:19:48 +0100 Subject: [PATCH 144/942] codegen: Track union layout more accurately. Instead of always generating the _bindgen_union_align method (which shouldn't be needed at all for Rust structs, since the struct layout tracker already deals with adding repr(align) as necessary) make sure to visit all fields appropriately to generate the correct alignment. --- bindgen-integration/src/lib.rs | 2 - src/codegen/mod.rs | 113 +++++++++--------- src/codegen/struct_layout.rs | 39 +++--- src/ir/comp.rs | 21 +++- tests/expectations/tests/16-byte-alignment.rs | 3 - .../expectations/tests/anon-fields-prefix.rs | 1 - .../tests/anon_struct_in_union.rs | 1 - tests/expectations/tests/anon_union.rs | 1 - tests/expectations/tests/class.rs | 1 - .../tests/class_with_inner_struct.rs | 3 - .../tests/derive-debug-mangle-name.rs | 1 - .../tests/derive-partialeq-anonfield.rs | 5 +- .../tests/derive-partialeq-pointer.rs | 1 - .../tests/derive-partialeq-union.rs | 1 - tests/expectations/tests/issue-1285.rs | 1 - tests/expectations/tests/issue-1498.rs | 1 - tests/expectations/tests/issue-493.rs | 3 +- .../expectations/tests/jsval_layout_opaque.rs | 2 - tests/expectations/tests/layout_eth_conf.rs | 1 - tests/expectations/tests/layout_mbuf.rs | 6 - tests/expectations/tests/libclang-9/class.rs | 1 - tests/expectations/tests/private_fields.rs | 1 - .../tests/struct_with_anon_union.rs | 1 - .../tests/struct_with_anon_unnamed_union.rs | 1 - .../expectations/tests/struct_with_nesting.rs | 1 - tests/expectations/tests/typeref.rs | 1 - tests/expectations/tests/union-align.rs | 30 ++++- tests/expectations/tests/union-in-ns.rs | 1 - tests/expectations/tests/union_bitfield.rs | 4 +- tests/expectations/tests/union_dtor.rs | 1 - tests/expectations/tests/union_fields.rs | 1 - tests/expectations/tests/union_template.rs | 3 - .../tests/union_with_anon_struct.rs | 1 - .../tests/union_with_anon_struct_bitfield.rs | 1 - .../tests/union_with_anon_union.rs | 2 - .../tests/union_with_anon_unnamed_struct.rs | 1 - .../tests/union_with_anon_unnamed_union.rs | 2 - .../tests/union_with_big_member.rs | 3 - .../expectations/tests/union_with_nesting.rs | 3 - tests/expectations/tests/use-core.rs | 1 - tests/headers/union-align.h | 5 + 41 files changed, 143 insertions(+), 129 deletions(-) diff --git a/bindgen-integration/src/lib.rs b/bindgen-integration/src/lib.rs index 0d6989616c..4b288afdc9 100755 --- a/bindgen-integration/src/lib.rs +++ b/bindgen-integration/src/lib.rs @@ -260,8 +260,6 @@ fn test_macro_customintkind_path() { assert!(v.is::()) } -// https://github.com/rust-lang/rust-bindgen/issues/1973 -#[cfg_attr(target_arch = "aarch64", should_panic)] // This line should be removed after the bug linked above is fixed #[test] fn test_homogeneous_aggregate_float_union() { unsafe { diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index cad2f47e50..6a7660f6c2 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -1219,7 +1219,7 @@ impl<'a> FieldCodegen<'a> for FieldData { ty.append_implicit_template_params(ctx, field_item); // NB: If supported, we use proper `union` types. - let ty = if parent.is_union() && !parent.can_be_rust_union(ctx) { + let ty = if parent.is_union() && !struct_layout.is_rust_union() { result.saw_bindgen_union(); if ctx.options().enable_cxx_namespaces { quote! { @@ -1263,12 +1263,10 @@ impl<'a> FieldCodegen<'a> for FieldData { .expect("Each field should have a name in codegen!"); let field_ident = ctx.rust_ident_raw(field_name.as_str()); - if !parent.is_union() { - if let Some(padding_field) = - struct_layout.pad_field(&field_name, field_ty, self.offset()) - { - fields.extend(Some(padding_field)); - } + if let Some(padding_field) = + struct_layout.saw_field(&field_name, field_ty, self.offset()) + { + fields.extend(Some(padding_field)); } let is_private = (!self.is_public() && @@ -1433,7 +1431,7 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit { let layout = self.layout(); let unit_field_ty = helpers::bitfield_unit(ctx, layout); let field_ty = { - if parent.is_union() && !parent.can_be_rust_union(ctx) { + if parent.is_union() && !struct_layout.is_rust_union() { result.saw_bindgen_union(); if ctx.options().enable_cxx_namespaces { quote! { @@ -1571,7 +1569,7 @@ impl<'a> FieldCodegen<'a> for Bitfield { _accessor_kind: FieldAccessorKind, parent: &CompInfo, _result: &mut CodegenResult, - _struct_layout: &mut StructLayoutTracker, + struct_layout: &mut StructLayoutTracker, _fields: &mut F, methods: &mut M, (unit_field_name, bitfield_representable_as_int): (&'a str, &mut bool), @@ -1612,7 +1610,7 @@ impl<'a> FieldCodegen<'a> for Bitfield { self.is_public() && !fields_should_be_private, ); - if parent.is_union() && !parent.can_be_rust_union(ctx) { + if parent.is_union() && !struct_layout.is_rust_union() { methods.extend(Some(quote! { #[inline] #access_spec fn #getter_name(&self) -> #bitfield_ty { @@ -1768,15 +1766,53 @@ impl CodeGenerator for CompInfo { } } - let is_union = self.kind() == CompKind::Union; - let layout = item.kind().expect_type().layout(ctx); - - let mut explicit_align = None; if is_opaque { // Opaque item should not have generated methods, fields. debug_assert!(fields.is_empty()); debug_assert!(methods.is_empty()); + } + let is_union = self.kind() == CompKind::Union; + let layout = item.kind().expect_type().layout(ctx); + let zero_sized = item.is_zero_sized(ctx); + let forward_decl = self.is_forward_declaration(); + + let mut explicit_align = None; + + // C++ requires every struct to be addressable, so what C++ compilers do + // is making the struct 1-byte sized. + // + // This is apparently not the case for C, see: + // https://github.com/rust-lang/rust-bindgen/issues/551 + // + // Just get the layout, and assume C++ if not. + // + // NOTE: This check is conveniently here to avoid the dummy fields we + // may add for unused template parameters. + if !forward_decl && zero_sized { + let has_address = if is_opaque { + // Generate the address field if it's an opaque type and + // couldn't determine the layout of the blob. + layout.is_none() + } else { + layout.map_or(true, |l| l.size != 0) + }; + + if has_address { + let layout = Layout::new(1, 1); + let ty = helpers::blob(ctx, Layout::new(1, 1)); + struct_layout.saw_field_with_layout( + "_address", + layout, + /* offset = */ Some(0), + ); + fields.push(quote! { + pub _address: #ty, + }); + } + } + + if is_opaque { match layout { Some(l) => { explicit_align = Some(l.align); @@ -1790,7 +1826,7 @@ impl CodeGenerator for CompInfo { warn!("Opaque type without layout! Expect dragons!"); } } - } else if !is_union && !item.is_zero_sized(ctx) { + } else if !is_union && !zero_sized { if let Some(padding_field) = layout.and_then(|layout| struct_layout.pad_struct(layout)) { @@ -1815,57 +1851,26 @@ impl CodeGenerator for CompInfo { } } } - } else if is_union && !self.is_forward_declaration() { + } else if is_union && !forward_decl { // TODO(emilio): It'd be nice to unify this with the struct path // above somehow. let layout = layout.expect("Unable to get layout information?"); - struct_layout.saw_union(layout); - if struct_layout.requires_explicit_align(layout) { explicit_align = Some(layout.align); } - let ty = helpers::blob(ctx, layout); - fields.push(if self.can_be_rust_union(ctx) { - quote! { - _bindgen_union_align: #ty , - } - } else { - quote! { + if !struct_layout.is_rust_union() { + let ty = helpers::blob(ctx, layout); + fields.push(quote! { pub bindgen_union_field: #ty , - } - }); + }) + } } - // C++ requires every struct to be addressable, so what C++ compilers do - // is making the struct 1-byte sized. - // - // This is apparently not the case for C, see: - // https://github.com/rust-lang/rust-bindgen/issues/551 - // - // Just get the layout, and assume C++ if not. - // - // NOTE: This check is conveniently here to avoid the dummy fields we - // may add for unused template parameters. - if self.is_forward_declaration() { + if forward_decl { fields.push(quote! { _unused: [u8; 0], }); - } else if item.is_zero_sized(ctx) { - let has_address = if is_opaque { - // Generate the address field if it's an opaque type and - // couldn't determine the layout of the blob. - layout.is_none() - } else { - layout.map_or(true, |l| l.size != 0) - }; - - if has_address { - let ty = helpers::blob(ctx, Layout::new(1, 1)); - fields.push(quote! { - pub _address: #ty, - }); - } } let mut generic_param_names = vec![]; @@ -1963,7 +1968,7 @@ impl CodeGenerator for CompInfo { attributes.push(attributes::derives(&derives)) } - let mut tokens = if is_union && self.can_be_rust_union(ctx) { + let mut tokens = if is_union && struct_layout.is_rust_union() { quote! { #( #attributes )* pub union #canonical_ident diff --git a/src/codegen/struct_layout.rs b/src/codegen/struct_layout.rs index 4536e889af..2e4b973591 100644 --- a/src/codegen/struct_layout.rs +++ b/src/codegen/struct_layout.rs @@ -19,6 +19,7 @@ pub struct StructLayoutTracker<'a> { comp: &'a CompInfo, is_packed: bool, known_type_layout: Option, + is_rust_union: bool, latest_offset: usize, padding_count: usize, latest_field_layout: Option, @@ -89,12 +90,15 @@ impl<'a> StructLayoutTracker<'a> { ) -> Self { let known_type_layout = ty.layout(ctx); let is_packed = comp.is_packed(ctx, known_type_layout.as_ref()); + let is_rust_union = comp.is_union() && + comp.can_be_rust_union(ctx, known_type_layout.as_ref()); StructLayoutTracker { name, ctx, comp, is_packed, known_type_layout, + is_rust_union, latest_offset: 0, padding_count: 0, latest_field_layout: None, @@ -103,6 +107,10 @@ impl<'a> StructLayoutTracker<'a> { } } + pub fn is_rust_union(&self) -> bool { + self.is_rust_union + } + pub fn saw_vtable(&mut self) { debug!("saw vtable for {}", self.name); @@ -143,18 +151,9 @@ impl<'a> StructLayoutTracker<'a> { // actually generate the dummy alignment. } - pub fn saw_union(&mut self, layout: Layout) { - debug!("saw union for {}: {:?}", self.name, layout); - self.align_to_latest_field(layout); - - self.latest_offset += self.padding_bytes(layout) + layout.size; - self.latest_field_layout = Some(layout); - self.max_field_align = cmp::max(self.max_field_align, layout.align); - } - - /// Add a padding field if necessary for a given new field _before_ adding - /// that field. - pub fn pad_field( + /// Returns a padding field if necessary for a given new field _before_ + /// adding that field. + pub fn saw_field( &mut self, field_name: &str, field_ty: &Type, @@ -181,15 +180,27 @@ impl<'a> StructLayoutTracker<'a> { } } } + self.saw_field_with_layout(field_name, field_layout, field_offset) + } + pub fn saw_field_with_layout( + &mut self, + field_name: &str, + field_layout: Layout, + field_offset: Option, + ) -> Option { let will_merge_with_bitfield = self.align_to_latest_field(field_layout); + let is_union = self.comp.is_union(); let padding_bytes = match field_offset { Some(offset) if offset / 8 > self.latest_offset => { offset / 8 - self.latest_offset } _ => { - if will_merge_with_bitfield || field_layout.align == 0 { + if will_merge_with_bitfield || + field_layout.align == 0 || + is_union + { 0 } else if !self.is_packed { self.padding_bytes(field_layout) @@ -203,7 +214,7 @@ impl<'a> StructLayoutTracker<'a> { self.latest_offset += padding_bytes; - let padding_layout = if self.is_packed { + let padding_layout = if self.is_packed || is_union { None } else { // Otherwise the padding is useless. diff --git a/src/ir/comp.rs b/src/ir/comp.rs index 60b1e2f0ff..52dcddd555 100644 --- a/src/ir/comp.rs +++ b/src/ir/comp.rs @@ -1642,7 +1642,12 @@ impl CompInfo { /// Requirements: /// 1. Current RustTarget allows for `untagged_union` /// 2. Each field can derive `Copy` - pub fn can_be_rust_union(&self, ctx: &BindgenContext) -> bool { + /// 3. It's not zero-sized. + pub fn can_be_rust_union( + &self, + ctx: &BindgenContext, + layout: Option<&Layout>, + ) -> bool { if !ctx.options().rust_features().untagged_union { return false; } @@ -1651,12 +1656,22 @@ impl CompInfo { return false; } - self.fields().iter().all(|f| match *f { + let all_can_copy = self.fields().iter().all(|f| match *f { Field::DataMember(ref field_data) => { field_data.ty().can_derive_copy(ctx) } Field::Bitfields(_) => true, - }) + }); + + if !all_can_copy { + return false; + } + + if layout.map_or(false, |l| l.size == 0) { + return false; + } + + true } } diff --git a/tests/expectations/tests/16-byte-alignment.rs b/tests/expectations/tests/16-byte-alignment.rs index 00d311a59e..0bb92fd17f 100644 --- a/tests/expectations/tests/16-byte-alignment.rs +++ b/tests/expectations/tests/16-byte-alignment.rs @@ -17,7 +17,6 @@ pub struct rte_ipv4_tuple { pub union rte_ipv4_tuple__bindgen_ty_1 { pub __bindgen_anon_1: rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1, pub sctp_tag: u32, - _bindgen_union_align: u32, } #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] @@ -159,7 +158,6 @@ pub struct rte_ipv6_tuple { pub union rte_ipv6_tuple__bindgen_ty_1 { pub __bindgen_anon_1: rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1, pub sctp_tag: u32, - _bindgen_union_align: u32, } #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] @@ -295,7 +293,6 @@ impl Default for rte_ipv6_tuple { pub union rte_thash_tuple { pub v4: rte_ipv4_tuple, pub v6: rte_ipv6_tuple, - _bindgen_union_align: [u128; 3usize], } #[test] fn bindgen_test_layout_rte_thash_tuple() { diff --git a/tests/expectations/tests/anon-fields-prefix.rs b/tests/expectations/tests/anon-fields-prefix.rs index 38baa2fdfc..f358dbd8f1 100644 --- a/tests/expectations/tests/anon-fields-prefix.rs +++ b/tests/expectations/tests/anon-fields-prefix.rs @@ -11,7 +11,6 @@ pub union color { pub u1: color__bindgen_ty_1, pub u2: color__bindgen_ty_2, pub v3: [::std::os::raw::c_uchar; 3usize], - _bindgen_union_align: [u8; 3usize], } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] diff --git a/tests/expectations/tests/anon_struct_in_union.rs b/tests/expectations/tests/anon_struct_in_union.rs index 8d0035d693..008ab611d9 100644 --- a/tests/expectations/tests/anon_struct_in_union.rs +++ b/tests/expectations/tests/anon_struct_in_union.rs @@ -14,7 +14,6 @@ pub struct s { #[derive(Copy, Clone)] pub union s__bindgen_ty_1 { pub field: s__bindgen_ty_1_inner, - _bindgen_union_align: u32, } #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] diff --git a/tests/expectations/tests/anon_union.rs b/tests/expectations/tests/anon_union.rs index 0234406358..386d8fadaa 100644 --- a/tests/expectations/tests/anon_union.rs +++ b/tests/expectations/tests/anon_union.rs @@ -35,7 +35,6 @@ pub struct TErrorResult_DOMExceptionInfo { pub union TErrorResult__bindgen_ty_1 { pub mMessage: *mut TErrorResult_Message, pub mDOMExceptionInfo: *mut TErrorResult_DOMExceptionInfo, - _bindgen_union_align: u64, } impl Default for TErrorResult__bindgen_ty_1 { fn default() -> Self { diff --git a/tests/expectations/tests/class.rs b/tests/expectations/tests/class.rs index c03f12745d..b13b3c81cd 100644 --- a/tests/expectations/tests/class.rs +++ b/tests/expectations/tests/class.rs @@ -340,7 +340,6 @@ impl Default for IncompleteArrayNonCopiable { pub union Union { pub d: f32, pub i: ::std::os::raw::c_int, - _bindgen_union_align: u32, } #[test] fn bindgen_test_layout_Union() { diff --git a/tests/expectations/tests/class_with_inner_struct.rs b/tests/expectations/tests/class_with_inner_struct.rs index 8d21b674e8..eab54118e1 100644 --- a/tests/expectations/tests/class_with_inner_struct.rs +++ b/tests/expectations/tests/class_with_inner_struct.rs @@ -59,7 +59,6 @@ fn bindgen_test_layout_A_Segment() { #[derive(Copy, Clone)] pub union A__bindgen_ty_1 { pub f: ::std::os::raw::c_int, - _bindgen_union_align: u32, } #[test] fn bindgen_test_layout_A__bindgen_ty_1() { @@ -95,7 +94,6 @@ impl Default for A__bindgen_ty_1 { #[derive(Copy, Clone)] pub union A__bindgen_ty_2 { pub d: ::std::os::raw::c_int, - _bindgen_union_align: u32, } #[test] fn bindgen_test_layout_A__bindgen_ty_2() { @@ -247,7 +245,6 @@ pub struct C { pub union C__bindgen_ty_1 { pub mFunc: C__bindgen_ty_1__bindgen_ty_1, pub __bindgen_anon_1: C__bindgen_ty_1__bindgen_ty_2, - _bindgen_union_align: [u32; 4usize], } #[repr(C)] #[derive(Debug, Default, Copy, Clone, PartialEq)] diff --git a/tests/expectations/tests/derive-debug-mangle-name.rs b/tests/expectations/tests/derive-debug-mangle-name.rs index 4b4ae27baf..d7f5c89208 100644 --- a/tests/expectations/tests/derive-debug-mangle-name.rs +++ b/tests/expectations/tests/derive-debug-mangle-name.rs @@ -17,7 +17,6 @@ pub struct perf_event_attr { pub union perf_event_attr__bindgen_ty_1 { pub b: ::std::os::raw::c_int, pub c: ::std::os::raw::c_int, - _bindgen_union_align: u32, } #[test] fn bindgen_test_layout_perf_event_attr__bindgen_ty_1() { diff --git a/tests/expectations/tests/derive-partialeq-anonfield.rs b/tests/expectations/tests/derive-partialeq-anonfield.rs index 3486641deb..8834ca3245 100644 --- a/tests/expectations/tests/derive-partialeq-anonfield.rs +++ b/tests/expectations/tests/derive-partialeq-anonfield.rs @@ -12,9 +12,10 @@ pub struct rte_mbuf { pub __bindgen_anon_1: rte_mbuf__bindgen_ty_1, } #[repr(C)] +#[repr(align(1))] #[derive(Copy, Clone)] -pub union rte_mbuf__bindgen_ty_1 { - _bindgen_union_align: [u8; 0usize], +pub struct rte_mbuf__bindgen_ty_1 { + pub bindgen_union_field: [u8; 0usize], } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_1() { diff --git a/tests/expectations/tests/derive-partialeq-pointer.rs b/tests/expectations/tests/derive-partialeq-pointer.rs index 55bd782fa7..1964e3731b 100644 --- a/tests/expectations/tests/derive-partialeq-pointer.rs +++ b/tests/expectations/tests/derive-partialeq-pointer.rs @@ -41,7 +41,6 @@ pub struct c { #[repr(C)] #[derive(Copy, Clone)] pub union c__bindgen_ty_1 { - _bindgen_union_align: u8, pub _address: u8, } #[test] diff --git a/tests/expectations/tests/derive-partialeq-union.rs b/tests/expectations/tests/derive-partialeq-union.rs index e873d134a7..b2ccb2e872 100644 --- a/tests/expectations/tests/derive-partialeq-union.rs +++ b/tests/expectations/tests/derive-partialeq-union.rs @@ -11,7 +11,6 @@ pub union ShouldNotDerivePartialEq { pub a: ::std::os::raw::c_char, pub b: ::std::os::raw::c_int, - _bindgen_union_align: u32, } #[test] fn bindgen_test_layout_ShouldNotDerivePartialEq() { diff --git a/tests/expectations/tests/issue-1285.rs b/tests/expectations/tests/issue-1285.rs index 3e0da41bcb..4ca8452739 100644 --- a/tests/expectations/tests/issue-1285.rs +++ b/tests/expectations/tests/issue-1285.rs @@ -15,7 +15,6 @@ pub struct foo { pub union foo__bindgen_ty_1 { pub a: ::std::os::raw::c_uint, pub b: ::std::os::raw::c_ushort, - _bindgen_union_align: u32, } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { diff --git a/tests/expectations/tests/issue-1498.rs b/tests/expectations/tests/issue-1498.rs index 72bf7f7c48..b14f06c869 100644 --- a/tests/expectations/tests/issue-1498.rs +++ b/tests/expectations/tests/issue-1498.rs @@ -30,7 +30,6 @@ pub union rte_memseg__bindgen_ty_1 { pub addr: *mut ::std::os::raw::c_void, ///< Makes sure addr is always 64 bits pub addr_64: u64, - _bindgen_union_align: u64, } #[test] fn bindgen_test_layout_rte_memseg__bindgen_ty_1() { diff --git a/tests/expectations/tests/issue-493.rs b/tests/expectations/tests/issue-493.rs index 867e3d174f..d17fbeccb0 100644 --- a/tests/expectations/tests/issue-493.rs +++ b/tests/expectations/tests/issue-493.rs @@ -84,7 +84,6 @@ pub struct basic_string___short { pub union basic_string___short__bindgen_ty_1 { pub __size_: ::std::os::raw::c_uchar, pub __lx: basic_string_value_type, - _bindgen_union_align: u8, } impl Default for basic_string___short__bindgen_ty_1 { fn default() -> Self { @@ -97,6 +96,7 @@ impl Default for basic_string___short { } } #[repr(C)] +#[repr(align(1))] pub struct basic_string___ulx { pub __lx: __BindgenUnionField, pub __lxx: __BindgenUnionField, @@ -129,6 +129,7 @@ pub struct basic_string___rep { pub __bindgen_anon_1: basic_string___rep__bindgen_ty_1, } #[repr(C)] +#[repr(align(1))] pub struct basic_string___rep__bindgen_ty_1 { pub __l: __BindgenUnionField, pub __s: __BindgenUnionField, diff --git a/tests/expectations/tests/jsval_layout_opaque.rs b/tests/expectations/tests/jsval_layout_opaque.rs index 92ae978dd1..8a3d7f3954 100644 --- a/tests/expectations/tests/jsval_layout_opaque.rs +++ b/tests/expectations/tests/jsval_layout_opaque.rs @@ -188,7 +188,6 @@ pub union jsval_layout { pub asPtr: *mut ::std::os::raw::c_void, pub asWord: size_t, pub asUIntPtr: usize, - _bindgen_union_align: u64, } #[repr(C)] #[repr(align(8))] @@ -271,7 +270,6 @@ pub union jsval_layout__bindgen_ty_2__bindgen_ty_1 { pub i32_: i32, pub u32_: u32, pub why: JSWhyMagic, - _bindgen_union_align: u32, } #[test] fn bindgen_test_layout_jsval_layout__bindgen_ty_2__bindgen_ty_1() { diff --git a/tests/expectations/tests/layout_eth_conf.rs b/tests/expectations/tests/layout_eth_conf.rs index 34db2c4a73..fe8b92fecd 100644 --- a/tests/expectations/tests/layout_eth_conf.rs +++ b/tests/expectations/tests/layout_eth_conf.rs @@ -2011,7 +2011,6 @@ pub union rte_eth_conf__bindgen_ty_2 { pub vmdq_dcb_tx_conf: rte_eth_vmdq_dcb_tx_conf, pub dcb_tx_conf: rte_eth_dcb_tx_conf, pub vmdq_tx_conf: rte_eth_vmdq_tx_conf, - _bindgen_union_align: [u32; 3usize], } #[test] fn bindgen_test_layout_rte_eth_conf__bindgen_ty_2() { diff --git a/tests/expectations/tests/layout_mbuf.rs b/tests/expectations/tests/layout_mbuf.rs index a7f71a302a..bc456a1800 100644 --- a/tests/expectations/tests/layout_mbuf.rs +++ b/tests/expectations/tests/layout_mbuf.rs @@ -189,7 +189,6 @@ pub union rte_mbuf__bindgen_ty_1 { pub refcnt_atomic: rte_atomic16_t, ///< Non-atomically accessed refcnt pub refcnt: u16, - _bindgen_union_align: u16, } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_1() { @@ -241,7 +240,6 @@ pub union rte_mbuf__bindgen_ty_2 { ///< L2/L3/L4 and tunnel information. pub packet_type: u32, pub __bindgen_anon_1: rte_mbuf__bindgen_ty_2__bindgen_ty_1, - _bindgen_union_align: u32, } #[repr(C)] #[repr(align(4))] @@ -449,7 +447,6 @@ pub union rte_mbuf__bindgen_ty_3 { pub sched: rte_mbuf__bindgen_ty_3__bindgen_ty_2, ///< User defined tags. See rte_distributor_process() pub usr: u32, - _bindgen_union_align: [u32; 2usize], } #[repr(C)] #[derive(Copy, Clone)] @@ -463,7 +460,6 @@ pub union rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 { pub __bindgen_anon_1: rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1, pub lo: u32, - _bindgen_union_align: u32, } #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] @@ -686,7 +682,6 @@ pub union rte_mbuf__bindgen_ty_4 { pub userdata: *mut ::std::os::raw::c_void, ///< Allow 8-byte userdata on 32-bit pub udata64: u64, - _bindgen_union_align: u64, } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_4() { @@ -738,7 +733,6 @@ pub union rte_mbuf__bindgen_ty_5 { ///< combined for easy fetch pub tx_offload: u64, pub __bindgen_anon_1: rte_mbuf__bindgen_ty_5__bindgen_ty_1, - _bindgen_union_align: u64, } #[repr(C)] #[repr(align(8))] diff --git a/tests/expectations/tests/libclang-9/class.rs b/tests/expectations/tests/libclang-9/class.rs index baa851b964..beea517eed 100644 --- a/tests/expectations/tests/libclang-9/class.rs +++ b/tests/expectations/tests/libclang-9/class.rs @@ -536,7 +536,6 @@ impl Default for IncompleteArrayNonCopiable { pub union Union { pub d: f32, pub i: ::std::os::raw::c_int, - _bindgen_union_align: u32, } #[test] fn bindgen_test_layout_Union() { diff --git a/tests/expectations/tests/private_fields.rs b/tests/expectations/tests/private_fields.rs index f5edccae41..d5371e1c43 100644 --- a/tests/expectations/tests/private_fields.rs +++ b/tests/expectations/tests/private_fields.rs @@ -481,7 +481,6 @@ pub struct WithAnonUnion { #[repr(C)] #[derive(Copy, Clone)] pub union WithAnonUnion__bindgen_ty_1 { - _bindgen_union_align: u8, pub _address: u8, } #[test] diff --git a/tests/expectations/tests/struct_with_anon_union.rs b/tests/expectations/tests/struct_with_anon_union.rs index 3e0da41bcb..4ca8452739 100644 --- a/tests/expectations/tests/struct_with_anon_union.rs +++ b/tests/expectations/tests/struct_with_anon_union.rs @@ -15,7 +15,6 @@ pub struct foo { pub union foo__bindgen_ty_1 { pub a: ::std::os::raw::c_uint, pub b: ::std::os::raw::c_ushort, - _bindgen_union_align: u32, } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { diff --git a/tests/expectations/tests/struct_with_anon_unnamed_union.rs b/tests/expectations/tests/struct_with_anon_unnamed_union.rs index 5aeb51c334..5d03b7fb01 100644 --- a/tests/expectations/tests/struct_with_anon_unnamed_union.rs +++ b/tests/expectations/tests/struct_with_anon_unnamed_union.rs @@ -15,7 +15,6 @@ pub struct foo { pub union foo__bindgen_ty_1 { pub a: ::std::os::raw::c_uint, pub b: ::std::os::raw::c_ushort, - _bindgen_union_align: u32, } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { diff --git a/tests/expectations/tests/struct_with_nesting.rs b/tests/expectations/tests/struct_with_nesting.rs index 075832359e..a98bd8cae8 100644 --- a/tests/expectations/tests/struct_with_nesting.rs +++ b/tests/expectations/tests/struct_with_nesting.rs @@ -17,7 +17,6 @@ pub union foo__bindgen_ty_1 { pub b: ::std::os::raw::c_uint, pub __bindgen_anon_1: foo__bindgen_ty_1__bindgen_ty_1, pub __bindgen_anon_2: foo__bindgen_ty_1__bindgen_ty_2, - _bindgen_union_align: u32, } #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] diff --git a/tests/expectations/tests/typeref.rs b/tests/expectations/tests/typeref.rs index 6155ff33d5..b62ce929c0 100644 --- a/tests/expectations/tests/typeref.rs +++ b/tests/expectations/tests/typeref.rs @@ -62,7 +62,6 @@ pub struct mozilla_StyleShapeSource { pub union mozilla_StyleShapeSource__bindgen_ty_1 { pub mPosition: *mut mozilla_Position, pub mFragmentOrURL: *mut mozilla_FragmentOrURL, - _bindgen_union_align: u64, } impl Default for mozilla_StyleShapeSource__bindgen_ty_1 { fn default() -> Self { diff --git a/tests/expectations/tests/union-align.rs b/tests/expectations/tests/union-align.rs index e9c3de5206..7151ba45cd 100644 --- a/tests/expectations/tests/union-align.rs +++ b/tests/expectations/tests/union-align.rs @@ -10,7 +10,6 @@ #[derive(Copy, Clone)] pub union Bar { pub foo: ::std::os::raw::c_uchar, - _bindgen_union_align: u128, } #[test] fn bindgen_test_layout_Bar() { @@ -35,3 +34,32 @@ impl Default for Bar { unsafe { ::std::mem::zeroed() } } } +#[repr(C)] +#[repr(align(16))] +#[derive(Copy, Clone)] +pub union Baz { + pub bar: Bar, +} +#[test] +fn bindgen_test_layout_Baz() { + assert_eq!( + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(Baz)) + ); + assert_eq!( + ::std::mem::align_of::(), + 16usize, + concat!("Alignment of ", stringify!(Baz)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Baz), "::", stringify!(bar)) + ); +} +impl Default for Baz { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} diff --git a/tests/expectations/tests/union-in-ns.rs b/tests/expectations/tests/union-in-ns.rs index 2ff76bb8be..abb330b86c 100644 --- a/tests/expectations/tests/union-in-ns.rs +++ b/tests/expectations/tests/union-in-ns.rs @@ -13,7 +13,6 @@ pub mod root { #[derive(Copy, Clone)] pub union bar { pub baz: ::std::os::raw::c_int, - _bindgen_union_align: u32, } #[test] fn bindgen_test_layout_bar() { diff --git a/tests/expectations/tests/union_bitfield.rs b/tests/expectations/tests/union_bitfield.rs index 22c0de8578..cf3595ec51 100644 --- a/tests/expectations/tests/union_bitfield.rs +++ b/tests/expectations/tests/union_bitfield.rs @@ -92,11 +92,11 @@ where } } #[repr(C)] +#[repr(align(4))] #[derive(Copy, Clone)] pub union U4 { pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, - _bindgen_union_align: u32, } #[test] fn bindgen_test_layout_U4() { @@ -144,11 +144,11 @@ impl U4 { } } #[repr(C)] +#[repr(align(4))] #[derive(Copy, Clone)] pub union B { pub _bitfield_align_1: [u32; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, - _bindgen_union_align: u32, } #[test] fn bindgen_test_layout_B() { diff --git a/tests/expectations/tests/union_dtor.rs b/tests/expectations/tests/union_dtor.rs index dd3635e145..a06e8ccffe 100644 --- a/tests/expectations/tests/union_dtor.rs +++ b/tests/expectations/tests/union_dtor.rs @@ -9,7 +9,6 @@ pub union UnionWithDtor { pub mFoo: ::std::os::raw::c_int, pub mBar: *mut ::std::os::raw::c_void, - _bindgen_union_align: u64, } #[test] fn bindgen_test_layout_UnionWithDtor() { diff --git a/tests/expectations/tests/union_fields.rs b/tests/expectations/tests/union_fields.rs index d0bc26c2d6..e605b0bce8 100644 --- a/tests/expectations/tests/union_fields.rs +++ b/tests/expectations/tests/union_fields.rs @@ -11,7 +11,6 @@ pub union nsStyleUnion { pub mInt: ::std::os::raw::c_int, pub mFloat: f32, pub mPointer: *mut ::std::os::raw::c_void, - _bindgen_union_align: u64, } #[test] fn bindgen_test_layout_nsStyleUnion() { diff --git a/tests/expectations/tests/union_template.rs b/tests/expectations/tests/union_template.rs index fcef30c9e0..6a366f9eae 100644 --- a/tests/expectations/tests/union_template.rs +++ b/tests/expectations/tests/union_template.rs @@ -15,7 +15,6 @@ pub struct NastyStruct { pub union NastyStruct__bindgen_ty_1 { pub mFoo: *mut ::std::os::raw::c_void, pub mDummy: ::std::os::raw::c_ulong, - _bindgen_union_align: u64, } impl Default for NastyStruct__bindgen_ty_1 { fn default() -> Self { @@ -26,7 +25,6 @@ impl Default for NastyStruct__bindgen_ty_1 { pub union NastyStruct__bindgen_ty_2 { pub wat: ::std::os::raw::c_short, pub wut: *mut ::std::os::raw::c_int, - _bindgen_union_align: u64, } impl Default for NastyStruct__bindgen_ty_2 { fn default() -> Self { @@ -42,7 +40,6 @@ impl Default for NastyStruct { pub union Whatever { pub mTPtr: *mut ::std::os::raw::c_void, pub mInt: ::std::os::raw::c_int, - _bindgen_union_align: u64, } impl Default for Whatever { fn default() -> Self { diff --git a/tests/expectations/tests/union_with_anon_struct.rs b/tests/expectations/tests/union_with_anon_struct.rs index 8113ae09ec..7d061cec68 100644 --- a/tests/expectations/tests/union_with_anon_struct.rs +++ b/tests/expectations/tests/union_with_anon_struct.rs @@ -9,7 +9,6 @@ #[derive(Copy, Clone)] pub union foo { pub bar: foo__bindgen_ty_1, - _bindgen_union_align: [u32; 2usize], } #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] diff --git a/tests/expectations/tests/union_with_anon_struct_bitfield.rs b/tests/expectations/tests/union_with_anon_struct_bitfield.rs index 445a97efa1..2e3e641579 100644 --- a/tests/expectations/tests/union_with_anon_struct_bitfield.rs +++ b/tests/expectations/tests/union_with_anon_struct_bitfield.rs @@ -96,7 +96,6 @@ where pub union foo { pub a: ::std::os::raw::c_int, pub __bindgen_anon_1: foo__bindgen_ty_1, - _bindgen_union_align: u32, } #[repr(C)] #[repr(align(4))] diff --git a/tests/expectations/tests/union_with_anon_union.rs b/tests/expectations/tests/union_with_anon_union.rs index 89756d44f0..83e4801a88 100644 --- a/tests/expectations/tests/union_with_anon_union.rs +++ b/tests/expectations/tests/union_with_anon_union.rs @@ -9,14 +9,12 @@ #[derive(Copy, Clone)] pub union foo { pub bar: foo__bindgen_ty_1, - _bindgen_union_align: u32, } #[repr(C)] #[derive(Copy, Clone)] pub union foo__bindgen_ty_1 { pub a: ::std::os::raw::c_uint, pub b: ::std::os::raw::c_ushort, - _bindgen_union_align: u32, } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { diff --git a/tests/expectations/tests/union_with_anon_unnamed_struct.rs b/tests/expectations/tests/union_with_anon_unnamed_struct.rs index 7f1d794f42..5802f563f7 100644 --- a/tests/expectations/tests/union_with_anon_unnamed_struct.rs +++ b/tests/expectations/tests/union_with_anon_unnamed_struct.rs @@ -10,7 +10,6 @@ pub union pixel { pub rgba: ::std::os::raw::c_uint, pub __bindgen_anon_1: pixel__bindgen_ty_1, - _bindgen_union_align: u32, } #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] diff --git a/tests/expectations/tests/union_with_anon_unnamed_union.rs b/tests/expectations/tests/union_with_anon_unnamed_union.rs index 1720b82ff5..fc465737d1 100644 --- a/tests/expectations/tests/union_with_anon_unnamed_union.rs +++ b/tests/expectations/tests/union_with_anon_unnamed_union.rs @@ -10,14 +10,12 @@ pub union foo { pub a: ::std::os::raw::c_uint, pub __bindgen_anon_1: foo__bindgen_ty_1, - _bindgen_union_align: u32, } #[repr(C)] #[derive(Copy, Clone)] pub union foo__bindgen_ty_1 { pub b: ::std::os::raw::c_ushort, pub c: ::std::os::raw::c_uchar, - _bindgen_union_align: u16, } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { diff --git a/tests/expectations/tests/union_with_big_member.rs b/tests/expectations/tests/union_with_big_member.rs index ebfe765696..6425c1141d 100644 --- a/tests/expectations/tests/union_with_big_member.rs +++ b/tests/expectations/tests/union_with_big_member.rs @@ -10,7 +10,6 @@ pub union WithBigArray { pub a: ::std::os::raw::c_int, pub b: [::std::os::raw::c_int; 33usize], - _bindgen_union_align: [u32; 33usize], } #[test] fn bindgen_test_layout_WithBigArray() { @@ -59,7 +58,6 @@ impl Default for WithBigArray { pub union WithBigArray2 { pub a: ::std::os::raw::c_int, pub b: [::std::os::raw::c_char; 33usize], - _bindgen_union_align: [u32; 9usize], } #[test] fn bindgen_test_layout_WithBigArray2() { @@ -108,7 +106,6 @@ impl Default for WithBigArray2 { pub union WithBigMember { pub a: ::std::os::raw::c_int, pub b: WithBigArray, - _bindgen_union_align: [u32; 33usize], } #[test] fn bindgen_test_layout_WithBigMember() { diff --git a/tests/expectations/tests/union_with_nesting.rs b/tests/expectations/tests/union_with_nesting.rs index c1403d2cfa..55045f2f1f 100644 --- a/tests/expectations/tests/union_with_nesting.rs +++ b/tests/expectations/tests/union_with_nesting.rs @@ -10,7 +10,6 @@ pub union foo { pub a: ::std::os::raw::c_uint, pub __bindgen_anon_1: foo__bindgen_ty_1, - _bindgen_union_align: u32, } #[repr(C)] #[derive(Copy, Clone)] @@ -23,7 +22,6 @@ pub struct foo__bindgen_ty_1 { pub union foo__bindgen_ty_1__bindgen_ty_1 { pub b1: ::std::os::raw::c_ushort, pub b2: ::std::os::raw::c_ushort, - _bindgen_union_align: u16, } #[test] fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { @@ -74,7 +72,6 @@ impl Default for foo__bindgen_ty_1__bindgen_ty_1 { pub union foo__bindgen_ty_1__bindgen_ty_2 { pub c1: ::std::os::raw::c_ushort, pub c2: ::std::os::raw::c_ushort, - _bindgen_union_align: u16, } #[test] fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { diff --git a/tests/expectations/tests/use-core.rs b/tests/expectations/tests/use-core.rs index 89c631ebfc..4cb2851fc2 100644 --- a/tests/expectations/tests/use-core.rs +++ b/tests/expectations/tests/use-core.rs @@ -52,7 +52,6 @@ impl Default for foo { pub union _bindgen_ty_1 { pub bar: ::std::os::raw::c_int, pub baz: ::std::os::raw::c_long, - _bindgen_union_align: u64, } #[test] fn bindgen_test_layout__bindgen_ty_1() { diff --git a/tests/headers/union-align.h b/tests/headers/union-align.h index 94e60ef165..9557b2798a 100644 --- a/tests/headers/union-align.h +++ b/tests/headers/union-align.h @@ -3,3 +3,8 @@ union Bar { unsigned char foo; } __attribute__ ((__aligned__ (16))); + + +union Baz { + union Bar bar; +}; From 04c653b665bb97a32237d478078bfbf2c0f5fba1 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sun, 7 Feb 2021 21:30:23 -0500 Subject: [PATCH 145/942] Fix heading level --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cafadb0698..3792ad80ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -139,7 +139,7 @@ Released 2021/02/01 -# Added +## Added * Expose module-raw-lines to the CLI (#1936) * Added an option to fit macro constants to smaller types (#1945) From 704c02b579822891ded0cb7b521ec6cd4a9e849e Mon Sep 17 00:00:00 2001 From: Saleem Rashid Date: Sun, 7 Feb 2021 22:13:44 +0000 Subject: [PATCH 146/942] Revert "Run tests on AArch64" This reverts commit 0f8ceb68fd16e2b2a6c95a0e919dff4989cd0dec. --- .github/workflows/bindgen.yml | 23 ----------------------- ci/test.sh | 16 +++------------- 2 files changed, 3 insertions(+), 36 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 0a340badcc..9aa090754b 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -149,29 +149,6 @@ jobs: BINDGEN_NO_DEFAULT_FEATURES: ${{matrix.no_default_features}} run: ./ci/test.sh - test_aarch64: - name: "Run tests on AArch64" - runs-on: ubuntu-20.04 - steps: - - uses: actions/checkout@v2 - - uses: uraimo/run-on-arch-action@v2.0.8 - name: Run test commands - with: - arch: aarch64 - distro: ubuntu20.04 - githubToken: ${{ github.token }} - env: | - LLVM_VERSION: "10.0" - dockerRunArgs: | - --volume "${HOME}/.cargo:/root/.cargo" - install: | - apt-get update -q -y - apt-get install -q -y curl gcc git g++ libtinfo5 xz-utils - run: | - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal - source $HOME/.cargo/env - ./ci/test.sh - test-book: runs-on: ubuntu-latest steps: diff --git a/ci/test.sh b/ci/test.sh index cc83475582..d5bb0bf40d 100755 --- a/ci/test.sh +++ b/ci/test.sh @@ -8,18 +8,8 @@ set -x # Give a pipeline a non-zero exit code if one of its constituents fails set -o pipefail -# Set default values on environment variables -BINDGEN_RELEASE_BUILD="${BINDGEN_RELEASE_BUILD:-0}" -BINDGEN_FEATURE_RUNTIME="${BINDGEN_FEATURE_RUNTIME:-0}" -BINDGEN_FEATURE_EXTRA_ASSERTS="${BINDGEN_FEATURE_EXTRA_ASSERTS:-0}" -BINDGEN_FEATURE_TESTING_ONLY_DOCS="${BINDGEN_FEATURE_TESTING_ONLY_DOCS:-0}" -BINDGEN_NO_DEFAULT_FEATURES="${BINDGEN_NO_DEFAULT_FEATURES:-0}" - function llvm_linux_target_triple() { - case "$(uname -m)" in - aarch64) echo "aarch64-linux-gnu" ;; - *) echo "x86_64-linux-gnu-ubuntu-16.04" ;; - esac + echo "x86_64-linux-gnu-ubuntu-16.04" } function llvm_macos_target_triple() { @@ -62,7 +52,7 @@ function llvm_download() { if [ -d "${LLVM_DIRECTORY}" ]; then echo "Using cached LLVM download for ${LLVM}..." else - curl -L -o ${LLVM}.tar.xz $base_url/${LLVM}.tar.xz + wget --no-verbose $base_url/${LLVM}.tar.xz mkdir -p "${LLVM_DIRECTORY}" tar xf ${LLVM}.tar.xz -C "${LLVM_DIRECTORY}" --strip-components=1 fi @@ -76,7 +66,7 @@ set_llvm_env() { export LLVM_VERSION_TRIPLE=`llvm_version_triple ${LLVM_VERSION}` local base_url=`llvm_base_url ${LLVM_VERSION_TRIPLE}` - if [ "$(uname -s)" == "Linux" ]; then + if [ "$GITHUB_ACTIONS_OS" == "ubuntu-latest" ]; then llvm_download $base_url `llvm_linux_target_triple ${LLVM_VERSION_TRIPLE}` export LD_LIBRARY_PATH="${LLVM_DIRECTORY}/lib":${LD_LIBRARY_PATH:-} else From b1c417882662c26398aae6c961b8a503ea8a27e7 Mon Sep 17 00:00:00 2001 From: Saleem Rashid Date: Sun, 7 Feb 2021 22:27:45 +0000 Subject: [PATCH 147/942] Run tests on AArch64 using Debian multiarch and QEMU --- .github/workflows/bindgen.yml | 35 +++++++++++++++++++++++++++++++++++ ci/test.sh | 13 +++++++++++-- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 9aa090754b..8f1dabd797 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -89,7 +89,12 @@ jobs: strategy: matrix: os: [ubuntu-latest] + target: + - debian: null + cross: null + rust: null llvm_version: ["3.9", "4.0", "5.0", "9.0"] + main_tests: [1] release_build: [0, 1] no_default_features: [0, 1] # FIXME: There are no pre-built static libclang libraries, so the @@ -121,6 +126,17 @@ jobs: feature_extra_asserts: 1 feature_testing_only_docs: 1 + - os: ubuntu-latest + target: + debian: arm64 + cross: aarch64-linux-gnu + rust: aarch64-unknown-linux-gnu + llvm_version: "9.0" + main_tests: 0 + release_build: 0 + feature_extra_asserts: 0 + feature_testing_only_docs: 0 + # Ensure stuff works on macos too - os: macos-latest llvm_version: "9.0" @@ -131,17 +147,36 @@ jobs: steps: - uses: actions/checkout@v2 + - name: Install multiarch packages + if: matrix.target.debian + run: | + sudo apt-get install binfmt-support qemu-user-static gcc-${{matrix.target.cross}} g++-${{matrix.target.cross}} + source /etc/lsb-release + sudo tee /etc/apt/sources.list </dev/null + deb [arch=${{matrix.target.debian}}] http://ports.ubuntu.com/ubuntu-ports/ $DISTRIB_CODENAME main + deb [arch=${{matrix.target.debian}}] http://ports.ubuntu.com/ubuntu-ports/ $DISTRIB_CODENAME-updates main + deb [arch=${{matrix.target.debian}}] http://ports.ubuntu.com/ubuntu-ports/ $DISTRIB_CODENAME-backports main + deb [arch=${{matrix.target.debian}}] http://ports.ubuntu.com/ubuntu-ports/ $DISTRIB_CODENAME-security main + EOF + sudo dpkg --add-architecture ${{matrix.target.debian}} + sudo apt-get update + sudo apt-get install libc6:${{matrix.target.debian}} libstdc++6:${{matrix.target.debian}} + - name: Install stable uses: actions-rs/toolchain@v1 with: profile: minimal toolchain: stable + target: ${{matrix.target.rust}} override: true - name: Run all the tests env: GITHUB_ACTIONS_OS: ${{matrix.os}} + RUST_CROSS_COMPILER: ${{matrix.target.cross}} + RUST_TARGET: ${{matrix.target.rust}} LLVM_VERSION: ${{matrix.llvm_version}} + BINDGEN_MAIN_TESTS: ${{matrix.main_tests}} BINDGEN_RELEASE_BUILD: ${{matrix.release_build}} BINDGEN_FEATURE_RUNTIME: ${{matrix.feature_runtime}} BINDGEN_FEATURE_EXTRA_ASSERTS: ${{matrix.feature_extra_asserts}} diff --git a/ci/test.sh b/ci/test.sh index d5bb0bf40d..b58ed0f14d 100755 --- a/ci/test.sh +++ b/ci/test.sh @@ -94,6 +94,9 @@ set_rustfmt_env get_cargo_args() { local args="" + if [ ! -z "$RUST_TARGET" ]; then + args+=" --target $RUST_TARGET" + fi if [ "$BINDGEN_RELEASE_BUILD" == "1" ]; then args+=" --release" fi @@ -116,13 +119,19 @@ get_cargo_args() { echo $args } +if [ ! -z "$RUST_CROSS_COMPILER" ]; then + export RUSTFLAGS="-C linker=${RUST_CROSS_COMPILER}-gcc" +fi + CARGO_ARGS=`get_cargo_args` # Ensure we build without warnings cargo rustc --lib $CARGO_ARGS -- -Dwarnings -# Run the tests -cargo test $CARGO_ARGS +if [ "$BINDGEN_MAIN_TESTS" == "1" ]; then + # Run the tests + cargo test $CARGO_ARGS +fi assert_no_diff From e92dcf2a3f9130a5053299384ce901269c6f161f Mon Sep 17 00:00:00 2001 From: Marcel Hlopko Date: Mon, 15 Feb 2021 13:39:30 +0100 Subject: [PATCH 148/942] Make clang version parsing logic more robust Previously the function assumed that the version number appeared in the third word. This PR adds a heuristic - take the first word that starts with a number. This way we can also parse: `debian clang version 11.0` that my clang reports. --- src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 8dcba3fb97..06ba8e6377 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2444,10 +2444,12 @@ pub struct ClangVersion { pub fn clang_version() -> ClangVersion { ensure_libclang_is_loaded(); + //Debian clang version 11.0.1-2 let raw_v: String = clang::extract_clang_version(); let split_v: Option> = raw_v .split_whitespace() - .nth(2) + .filter(|t| t.chars().next().map_or(false, |v| v.is_ascii_digit())) + .next() .map(|v| v.split('.').collect()); match split_v { Some(v) => { From e59aa9218b0e862cbaed319582bf0b692dfacde2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sat, 13 Feb 2021 04:41:15 +0100 Subject: [PATCH 149/942] tests: Guess modern libclang version when we fail to parse a version. Should fix the test failures described in #1991 and #1975 on modern Mac. --- tests/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tests.rs b/tests/tests.rs index cd621177d6..7bf2c65c4f 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -146,7 +146,7 @@ fn compare_generated_header( expectation.push("libclang-3.9"); } else { match clang_version().parsed { - None => {} + None => expectation.push("libclang-9"), Some(version) => { let (maj, min) = version; let version_str = if maj >= 9 { From 0e25962c4e69aef647e7275fa7bc7545dbb8cd0b Mon Sep 17 00:00:00 2001 From: Marcel Hlopko Date: Thu, 11 Feb 2021 08:58:46 +0100 Subject: [PATCH 150/942] Rename whitelist -> allowlist and blacklist -> blocklist For the commandline arguments I added undocumented aliases to old flags, to stay backwards compatible. --- CHANGELOG.md | 36 ++ bindgen-integration/build.rs | 2 +- book/src/SUMMARY.md | 4 +- book/src/allowlisting.md | 31 ++ book/src/{blacklisting.md => blocklisting.md} | 13 +- book/src/cpp.md | 4 +- book/src/faq.md | 6 +- book/src/objc.md | 4 +- book/src/replacing-types.md | 2 +- book/src/whitelisting.md | 31 -- src/codegen/impl_debug.rs | 4 +- src/codegen/mod.rs | 10 +- src/ir/analysis/derive.rs | 10 +- src/ir/analysis/has_destructor.rs | 2 +- src/ir/analysis/has_float.rs | 2 +- src/ir/analysis/has_type_param_in_array.rs | 2 +- src/ir/analysis/has_vtable.rs | 2 +- src/ir/analysis/mod.rs | 4 +- src/ir/analysis/sizedness.rs | 2 +- src/ir/analysis/template_params.rs | 60 +-- src/ir/context.rs | 136 +++--- src/ir/dot.rs | 6 +- src/ir/enum_ty.rs | 2 +- src/ir/item.rs | 44 +- src/ir/template.rs | 4 +- src/ir/traversal.rs | 4 +- src/lib.rs | 213 +++++---- src/options.rs | 83 ++-- ...basic.rs => allowlist-namespaces-basic.rs} | 0 ...-namespaces.rs => allowlist-namespaces.rs} | 0 ...{whitelist_basic.rs => allowlist_basic.rs} | 10 +- .../{whitelist_fix.rs => allowlist_fix.rs} | 0 .../{whitelist_vars.rs => allowlist_vars.rs} | 0 ...=> allowlisted-item-references-no-hash.rs} | 16 +- ...lowlisted-item-references-no-partialeq.rs} | 16 +- ...=> allowlisted_item_references_no_copy.rs} | 16 +- ...um_whitelist.rs => anon_enum_allowlist.rs} | 0 ...l-debug.rs => blocklist-and-impl-debug.rs} | 6 +- ...list-function.rs => blocklist-function.rs} | 0 .../{blacklist-item.rs => blocklist-item.rs} | 0 ...ist.rs => derive-default-and-blocklist.rs} | 6 +- ...cklist.rs => derive-hash-and-blocklist.rs} | 6 +- ...listing.rs => derive-hash-blocklisting.rs} | 46 +- ...t.rs => derive-partialeq-and-blocklist.rs} | 6 +- ...t.rs => dynamic_loading_with_allowlist.rs} | 0 ...t.rs => dynamic_loading_with_blocklist.rs} | 0 ...elist.rs => inline_namespace_allowlist.rs} | 0 ...07-opaque-types-methods-being-generated.rs | 16 +- ...issue-944-derive-copy-and-blocklisting.rs} | 6 +- ...e-whitelisted.rs => module-allowlisted.rs} | 0 tests/expectations/tests/no-derive-debug.rs | 2 +- tests/expectations/tests/no-derive-default.rs | 2 +- ...-whitelisted.rs => no-hash-allowlisted.rs} | 0 ...elisted.rs => no-partialeq-allowlisted.rs} | 0 ...isting.rs => no-recursive-allowlisting.rs} | 0 ..._whitelisted.rs => no_copy_allowlisted.rs} | 0 ...whitelisted.rs => no_debug_allowlisted.rs} | 0 ...itelisted.rs => no_default_allowlisted.rs} | 0 .../{objc_whitelist.rs => objc_allowlist.rs} | 4 +- ...ype-referenced-by-allowlisted-function.rs} | 0 ...sic.hpp => allowlist-namespaces-basic.hpp} | 2 +- ...amespaces.hpp => allowlist-namespaces.hpp} | 2 +- ...hitelist_basic.hpp => allowlist_basic.hpp} | 6 +- .../{whitelist_fix.hpp => allowlist_fix.hpp} | 2 +- .../{whitelist_vars.h => allowlist_vars.h} | 0 .../allowlisted-item-references-no-hash.hpp | 7 + ...lowlisted-item-references-no-partialeq.hpp | 7 + .../allowlisted_item_references_no_copy.hpp | 7 + tests/headers/anon_enum_allowlist.h | 6 + tests/headers/anon_enum_whitelist.h | 6 - tests/headers/blacklist-and-impl-debug.hpp | 10 - tests/headers/blocklist-and-impl-debug.hpp | 10 + ...st-function.hpp => blocklist-function.hpp} | 2 +- ...{blacklist-item.hpp => blocklist-item.hpp} | 2 +- ...t.hpp => derive-default-and-blocklist.hpp} | 8 +- tests/headers/derive-hash-and-blacklist.hpp | 10 - tests/headers/derive-hash-and-blocklist.hpp | 10 + tests/headers/derive-hash-blacklisting.hpp | 17 - tests/headers/derive-hash-blocklisting.hpp | 17 + .../derive-partialeq-and-blacklist.hpp | 11 - .../derive-partialeq-and-blocklist.hpp | 11 + ...hpp => dynamic_loading_with_allowlist.hpp} | 2 +- ...hpp => dynamic_loading_with_blocklist.hpp} | 2 +- ...ist.hpp => inline_namespace_allowlist.hpp} | 2 +- tests/headers/issue-1285.h | 2 +- tests/headers/issue-410.hpp | 2 +- tests/headers/issue-447.hpp | 2 +- ...ssue-584-stylo-template-analysis-panic.hpp | 2 +- ...e-645-cannot-find-type-T-in-this-scope.hpp | 2 +- tests/headers/issue-662-part-2.hpp | 4 +- tests/headers/issue-674-1.hpp | 2 +- tests/headers/issue-674-2.hpp | 2 +- tests/headers/issue-674-3.hpp | 2 +- .../issue-769-bad-instantiation-test.hpp | 2 +- tests/headers/issue-801-opaque-sloppiness.hpp | 2 +- ...7-opaque-types-methods-being-generated.hpp | 8 +- tests/headers/issue-833-1.hpp | 2 +- tests/headers/issue-833.hpp | 2 +- tests/headers/issue-834.hpp | 2 +- ...issue-944-derive-copy-and-blacklisting.hpp | 10 - ...issue-944-derive-copy-and-blocklisting.hpp | 10 + tests/headers/maddness-is-avoidable.hpp | 2 +- ...whitelisted.hpp => module-allowlisted.hpp} | 0 tests/headers/no-derive-debug.h | 4 +- tests/headers/no-derive-default.h | 4 +- tests/headers/no-hash-allowlisted.hpp | 5 + tests/headers/no-hash-whitelisted.hpp | 5 - ...isted.hpp => no-partialeq-allowlisted.hpp} | 2 +- ...elisting.h => no-recursive-allowlisting.h} | 2 +- tests/headers/no_copy_allowlisted.hpp | 5 + tests/headers/no_copy_whitelisted.hpp | 5 - tests/headers/no_debug_allowlisted.hpp | 5 + tests/headers/no_debug_whitelisted.hpp | 5 - tests/headers/no_default_allowlisted.hpp | 5 + tests/headers/no_default_whitelisted.hpp | 5 - tests/headers/objc_allowlist.h | 24 ++ tests/headers/objc_whitelist.h | 24 -- tests/headers/opaque-tracing.hpp | 4 +- tests/headers/replaces_double.hpp | 2 +- ...type-referenced-by-allowlisted-function.h} | 2 +- tests/headers/type_alias_empty.hpp | 4 +- .../type_alias_template_specialized.hpp | 2 +- tests/headers/var-tracing.hpp | 2 +- .../whitelisted-item-references-no-hash.hpp | 7 - ...itelisted-item-references-no-partialeq.hpp | 7 - .../whitelisted_item_references_no_copy.hpp | 7 - tests/stylo.hpp | 2 +- tests/stylo_sanity.rs | 406 +++++++++--------- 128 files changed, 867 insertions(+), 778 deletions(-) create mode 100644 book/src/allowlisting.md rename book/src/{blacklisting.md => blocklisting.md} (61%) delete mode 100644 book/src/whitelisting.md rename tests/expectations/tests/{whitelist-namespaces-basic.rs => allowlist-namespaces-basic.rs} (100%) rename tests/expectations/tests/{whitelist-namespaces.rs => allowlist-namespaces.rs} (100%) rename tests/expectations/tests/{whitelist_basic.rs => allowlist_basic.rs} (75%) rename tests/expectations/tests/{whitelist_fix.rs => allowlist_fix.rs} (100%) rename tests/expectations/tests/{whitelist_vars.rs => allowlist_vars.rs} (100%) rename tests/expectations/tests/{whitelisted-item-references-no-hash.rs => allowlisted-item-references-no-hash.rs} (69%) rename tests/expectations/tests/{whitelisted-item-references-no-partialeq.rs => allowlisted-item-references-no-partialeq.rs} (70%) rename tests/expectations/tests/{whitelisted_item_references_no_copy.rs => allowlisted_item_references_no_copy.rs} (68%) rename tests/expectations/tests/{anon_enum_whitelist.rs => anon_enum_allowlist.rs} (100%) rename tests/expectations/tests/{blacklist-and-impl-debug.rs => blocklist-and-impl-debug.rs} (91%) rename tests/expectations/tests/{blacklist-function.rs => blocklist-function.rs} (100%) rename tests/expectations/tests/{blacklist-item.rs => blocklist-item.rs} (100%) rename tests/expectations/tests/{derive-default-and-blacklist.rs => derive-default-and-blocklist.rs} (90%) rename tests/expectations/tests/{derive-hash-and-blacklist.rs => derive-hash-and-blocklist.rs} (89%) rename tests/expectations/tests/{derive-hash-blacklisting.rs => derive-hash-blocklisting.rs} (52%) rename tests/expectations/tests/{derive-partialeq-and-blacklist.rs => derive-partialeq-and-blocklist.rs} (89%) rename tests/expectations/tests/{dynamic_loading_with_whitelist.rs => dynamic_loading_with_allowlist.rs} (100%) rename tests/expectations/tests/{dynamic_loading_with_blacklist.rs => dynamic_loading_with_blocklist.rs} (100%) rename tests/expectations/tests/{inline_namespace_whitelist.rs => inline_namespace_allowlist.rs} (100%) rename tests/expectations/tests/{issue-944-derive-copy-and-blacklisting.rs => issue-944-derive-copy-and-blocklisting.rs} (88%) rename tests/expectations/tests/{module-whitelisted.rs => module-allowlisted.rs} (100%) rename tests/expectations/tests/{no-hash-whitelisted.rs => no-hash-allowlisted.rs} (100%) rename tests/expectations/tests/{no-partialeq-whitelisted.rs => no-partialeq-allowlisted.rs} (100%) rename tests/expectations/tests/{no-recursive-whitelisting.rs => no-recursive-allowlisting.rs} (100%) rename tests/expectations/tests/{no_copy_whitelisted.rs => no_copy_allowlisted.rs} (100%) rename tests/expectations/tests/{no_debug_whitelisted.rs => no_debug_allowlisted.rs} (100%) rename tests/expectations/tests/{no_default_whitelisted.rs => no_default_allowlisted.rs} (100%) rename tests/expectations/tests/{objc_whitelist.rs => objc_allowlist.rs} (66%) rename tests/expectations/tests/{type-referenced-by-whitelisted-function.rs => type-referenced-by-allowlisted-function.rs} (100%) rename tests/headers/{whitelist-namespaces-basic.hpp => allowlist-namespaces-basic.hpp} (67%) rename tests/headers/{whitelist-namespaces.hpp => allowlist-namespaces.hpp} (64%) rename tests/headers/{whitelist_basic.hpp => allowlist_basic.hpp} (59%) rename tests/headers/{whitelist_fix.hpp => allowlist_fix.hpp} (58%) rename tests/headers/{whitelist_vars.h => allowlist_vars.h} (100%) create mode 100644 tests/headers/allowlisted-item-references-no-hash.hpp create mode 100644 tests/headers/allowlisted-item-references-no-partialeq.hpp create mode 100644 tests/headers/allowlisted_item_references_no_copy.hpp create mode 100644 tests/headers/anon_enum_allowlist.h delete mode 100644 tests/headers/anon_enum_whitelist.h delete mode 100644 tests/headers/blacklist-and-impl-debug.hpp create mode 100644 tests/headers/blocklist-and-impl-debug.hpp rename tests/headers/{blacklist-function.hpp => blocklist-function.hpp} (62%) rename tests/headers/{blacklist-item.hpp => blocklist-item.hpp} (63%) rename tests/headers/{derive-default-and-blacklist.hpp => derive-default-and-blocklist.hpp} (56%) delete mode 100644 tests/headers/derive-hash-and-blacklist.hpp create mode 100644 tests/headers/derive-hash-and-blocklist.hpp delete mode 100644 tests/headers/derive-hash-blacklisting.hpp create mode 100644 tests/headers/derive-hash-blocklisting.hpp delete mode 100644 tests/headers/derive-partialeq-and-blacklist.hpp create mode 100644 tests/headers/derive-partialeq-and-blocklist.hpp rename tests/headers/{dynamic_loading_with_whitelist.hpp => dynamic_loading_with_allowlist.hpp} (59%) rename tests/headers/{dynamic_loading_with_blacklist.hpp => dynamic_loading_with_blocklist.hpp} (71%) rename tests/headers/{inline_namespace_whitelist.hpp => inline_namespace_allowlist.hpp} (61%) delete mode 100644 tests/headers/issue-944-derive-copy-and-blacklisting.hpp create mode 100644 tests/headers/issue-944-derive-copy-and-blocklisting.hpp rename tests/headers/{module-whitelisted.hpp => module-allowlisted.hpp} (100%) create mode 100644 tests/headers/no-hash-allowlisted.hpp delete mode 100644 tests/headers/no-hash-whitelisted.hpp rename tests/headers/{no-partialeq-whitelisted.hpp => no-partialeq-allowlisted.hpp} (52%) rename tests/headers/{no-recursive-whitelisting.h => no-recursive-allowlisting.h} (61%) create mode 100644 tests/headers/no_copy_allowlisted.hpp delete mode 100644 tests/headers/no_copy_whitelisted.hpp create mode 100644 tests/headers/no_debug_allowlisted.hpp delete mode 100644 tests/headers/no_debug_whitelisted.hpp create mode 100644 tests/headers/no_default_allowlisted.hpp delete mode 100644 tests/headers/no_default_whitelisted.hpp create mode 100644 tests/headers/objc_allowlist.h delete mode 100644 tests/headers/objc_whitelist.h rename tests/headers/{type-referenced-by-whitelisted-function.h => type-referenced-by-allowlisted-function.h} (59%) delete mode 100644 tests/headers/whitelisted-item-references-no-hash.hpp delete mode 100644 tests/headers/whitelisted-item-references-no-partialeq.hpp delete mode 100644 tests/headers/whitelisted_item_references_no_copy.hpp diff --git a/CHANGELOG.md b/CHANGELOG.md index 3792ad80ee..46607f5186 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -127,6 +127,42 @@ ## Deprecated +* `bindgen::Builder::whitelist_type` is deprecated in favor of + `bindgen::Builder::allowlist_type`. [#1812][] + +* `bindgen::Builder::whitelist_function` is deprecated in favor of + `bindgen::Builder::allowlist_function`. [#1812][] + +* `bindgen::Builder::whitelist_var` is deprecated in favor of + `bindgen::Builder::allowlist_var`. [#1812][] + +* `--whitelist-type` is deprecated in favor of + `--allowlist-type`. [#1812][] + +* `--whitelist-function` is deprecated in favor of + `--allowlist-function`. [#1812][] + +* `--whitelist-var` is deprecated in favor of + `--allowlist-var`. [#1812][] + +* `bindgen::Builder::blacklist_type` is deprecated in favor of + `bindgen::Builder::blocklist_type`. [#1812][] + +* `bindgen::Builder::blacklist_function` is deprecated in favor of + `bindgen::Builder::blocklist_function`. [#1812][] + +* `bindgen::Builder::blacklist_item` is deprecated in favor of + `bindgen::Builder::blocklist_item`. [#1812][] + +* `--blacklist-type` is deprecated in favor of + `--blocklist-type`. [#1812][] + +* `--blacklist-function` is deprecated in favor of + `--blocklist-function`. [#1812][] + +* `--blacklist-item` is deprecated in favor of + `--blocklist-item`. [#1812][] + ## Removed ## Fixed diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs index 1b9a79155a..f055f31f0d 100644 --- a/bindgen-integration/build.rs +++ b/bindgen-integration/build.rs @@ -160,7 +160,7 @@ fn main() { seen_hellos: Mutex::new(0), seen_funcs: Mutex::new(0), })) - .blacklist_function("my_prefixed_function_to_remove") + .blocklist_function("my_prefixed_function_to_remove") .constified_enum("my_prefixed_enum_to_be_constified") .opaque_type("my_prefixed_templated_foo") .generate() diff --git a/book/src/SUMMARY.md b/book/src/SUMMARY.md index 16291c3631..65ed0870fb 100644 --- a/book/src/SUMMARY.md +++ b/book/src/SUMMARY.md @@ -12,8 +12,8 @@ - [Publish Your Crate!](./tutorial-6.md) - [Command Line Usage](./command-line-usage.md) - [Customizing the Generated Bindings](./customizing-generated-bindings.md) - - [Whitelisting](./whitelisting.md) - - [Blacklisting](./blacklisting.md) + - [Allowlisting](./allowlisting.md) + - [Blocklisting](./blocklisting.md) - [Treating a Type as an Opaque Blob of Bytes](./opaque.md) - [Replacing One Type with Another](./replacing-types.md) - [Preventing the Derivation of `Copy` and `Clone`](./nocopy.md) diff --git a/book/src/allowlisting.md b/book/src/allowlisting.md new file mode 100644 index 0000000000..8c57eaf328 --- /dev/null +++ b/book/src/allowlisting.md @@ -0,0 +1,31 @@ +# Allowlisting + +Allowlisting allows us to be precise about which type, function, and global +variable definitions `bindgen` generates bindings for. By default, if we don't +specify any allowlisting rules, everything is considered allowlisted. This may +not be desirable because of either + +* the generated bindings contain a lot of extra definitions we don't plan on using, or +* the header file contains C++ features for which Rust does not have a + corresponding form (such as partial template specialization), and we would + like to avoid these definitions + +If we specify allowlisting rules, then `bindgen` will only generate bindings to +types, functions, and global variables that match the allowlisting rules, or are +transitively used by a definition that matches them. + +### Library + +* [`bindgen::Builder::allowlist_type`](https://docs.rs/bindgen/0.23.1/bindgen/struct.Builder.html#method.allowlist_type) +* [`bindgen::Builder::allowlist_function`](https://docs.rs/bindgen/0.23.1/bindgen/struct.Builder.html#method.allowlist_function) +* [`bindgen::Builder::allowlist_var`](https://docs.rs/bindgen/0.23.1/bindgen/struct.Builder.html#method.allowlist_var) + +### Command Line + +* `--allowlist-type ` +* `--allowlist-function ` +* `--allowlist-var ` + +### Annotations + +None. diff --git a/book/src/blacklisting.md b/book/src/blocklisting.md similarity index 61% rename from book/src/blacklisting.md rename to book/src/blocklisting.md index b56aacd983..1d6086164e 100644 --- a/book/src/blacklisting.md +++ b/book/src/blocklisting.md @@ -1,24 +1,25 @@ -# Blacklisting +# Blocklisting If you need to provide your own custom translation of some type (for example, because you need to wrap one of its fields in an `UnsafeCell`), you can -explicitly blacklist generation of its definition. Uses of the blacklisted type +explicitly blocklist + generation of its definition. Uses of the blocklisted type will still appear in other types' definitions. (If you don't want the type to appear in the bindings at all, [make it opaque](./opaque.md) instead of -blacklisting it.) +blocklisting it.) -Blacklisted types are pessimistically assumed not to be able to `derive` any +Blocklisted types are pessimistically assumed not to be able to `derive` any traits, which can transitively affect other types' ability to `derive` traits or not. ### Library -* [`bindgen::Builder::blacklist_type`](https://docs.rs/bindgen/0.31.3/bindgen/struct.Builder.html#method.blacklist_type) +* [`bindgen::Builder::blocklist_type`](https://docs.rs/bindgen/0.31.3/bindgen/struct.Builder.html#method.blocklist_type) ### Command Line -* `--blacklist-type ` +* `--blocklist-type ` ### Annotations diff --git a/book/src/cpp.md b/book/src/cpp.md index 6fef63912d..1be7a8a731 100644 --- a/book/src/cpp.md +++ b/book/src/cpp.md @@ -11,11 +11,11 @@ it ends in `.hpp`. If it doesn't, adding `-x c++` clang args can be used to force C++ mode. You probably also want to use `-std=c++14` or similar clang args as well. -You pretty much **must** use [whitelisting](./whitelisting.md) when working +You pretty much **must** use [allowlisting](./allowlisting.md) when working with C++ to avoid pulling in all of the `std::.*` types, many of which `bindgen` cannot handle. Additionally, you may want to mark other types as [opaque](./opaque.md) that `bindgen` stumbles on. It is recommended to mark -all of `std::.*` opaque, and to whitelist only precisely the functions and types +all of `std::.*` opaque, and to allowlist only precisely the functions and types you intend to use. You should read up on the [FAQs](./faq.md) as well. diff --git a/book/src/faq.md b/book/src/faq.md index 50ca075675..61e40e3586 100644 --- a/book/src/faq.md +++ b/book/src/faq.md @@ -4,13 +4,13 @@ -- [Why isn't `bindgen` generating methods for this whitelisted class?](#why-isnt-bindgen-generating-methods-for-this-whitelisted-class) +- [Why isn't `bindgen` generating methods for this allowlisted class?](#why-isnt-bindgen-generating-methods-for-this-allowlisted-class) - [Why isn't `bindgen` generating bindings to inline functions?](#why-isnt-bindgen-generating-bindings-to-inline-functions) - [Does `bindgen` support the C++ Standard Template Library (STL)?](#does-bindgen-support-the-c-standard-template-library-stl) -### Why isn't `bindgen` generating methods for this whitelisted class? +### Why isn't `bindgen` generating methods for this allowlisted class? Are the methods `inline` methods, or defined inline in the class? For example: @@ -62,7 +62,7 @@ STL. That ties our hands when it comes to linking: ["Why isn't `bindgen` generat As far as generating opaque blobs of bytes with the correct size and alignment, `bindgen` can do pretty well. This is typically enough to let you use types that transitively contain STL things. We generally recommend marking `std::.*` as -opaque, and then whitelisting only the specific things you need from the library +opaque, and then allowlisting only the specific things you need from the library you're binding to that is pulling in STL headers. ### How to deal with bindgen generated padding fields? diff --git a/book/src/objc.md b/book/src/objc.md index aad7ee60f7..55ec5e0b80 100644 --- a/book/src/objc.md +++ b/book/src/objc.md @@ -1,7 +1,7 @@ # Generating Bindings to Objective-C `bindgen` does not (yet) have full objective-c support but it can generate bindings -for a lot of the apple frameworks without too much blacklisting. +for a lot of the apple frameworks without too much blocklisting. In order to generate bindings, you will need `-x objective-c` as the clang args. If you'd like to use [block](https://crates.io/crates/block) you will need @@ -49,7 +49,7 @@ name and `id` is a pointer to the objective-c Object. `--target=arm64-apple-ios` as mentioned [here](https://github.com/rust-lang/rust-bindgen/issues/1211#issuecomment-569804287). * The generated bindings will almost certainly have some conflicts so you will -have to blacklist a few things. There are a few cases of the parameters being +have to blocklist a few things. There are a few cases of the parameters being poorly named in the objective-c headers. But if you're using anything with Core Foundation, you'll find that `time.h` as has a variable called timezone that conflicts with some of the things in `NSCalendar.h`. diff --git a/book/src/replacing-types.md b/book/src/replacing-types.md index cf3dd17ace..f47d945deb 100644 --- a/book/src/replacing-types.md +++ b/book/src/replacing-types.md @@ -24,4 +24,4 @@ That way, after code generation, the bindings for the `nsTArray` type are the ones that would be generated for `nsTArray_Simple`. Replacing is only available as an annotation. To replace a C or C++ definition -with a Rust definition, use [blacklisting](./blacklisting.md). +with a Rust definition, use [blocklisting](./blocklisting.md). diff --git a/book/src/whitelisting.md b/book/src/whitelisting.md deleted file mode 100644 index 749b56b051..0000000000 --- a/book/src/whitelisting.md +++ /dev/null @@ -1,31 +0,0 @@ -# Whitelisting - -Whitelisting allows us to be precise about which type, function, and global -variable definitions `bindgen` generates bindings for. By default, if we don't -specify any whitelisting rules, everything is considered whitelisted. This may -not be desirable because of either - -* the generated bindings contain a lot of extra definitions we don't plan on using, or -* the header file contains C++ features for which Rust does not have a - corresponding form (such as partial template specialization), and we would - like to avoid these definitions - -If we specify whitelisting rules, then `bindgen` will only generate bindings to -types, functions, and global variables that match the whitelisting rules, or are -transitively used by a definition that matches them. - -### Library - -* [`bindgen::Builder::whitelist_type`](https://docs.rs/bindgen/0.23.1/bindgen/struct.Builder.html#method.whitelist_type) -* [`bindgen::Builder::whitelist_function`](https://docs.rs/bindgen/0.23.1/bindgen/struct.Builder.html#method.whitelist_function) -* [`bindgen::Builder::whitelist_var`](https://docs.rs/bindgen/0.23.1/bindgen/struct.Builder.html#method.whitelist_var) - -### Command Line - -* `--whitelist-type ` -* `--whitelist-function ` -* `--whitelist-var ` - -### Annotations - -None. diff --git a/src/codegen/impl_debug.rs b/src/codegen/impl_debug.rs index ed1a5e25ea..b8fdd0d444 100644 --- a/src/codegen/impl_debug.rs +++ b/src/codegen/impl_debug.rs @@ -120,9 +120,9 @@ impl<'a> ImplDebug<'a> for Item { ) -> Option<(String, Vec)> { let name_ident = ctx.rust_ident(name); - // We don't know if blacklisted items `impl Debug` or not, so we can't + // We don't know if blocklisted items `impl Debug` or not, so we can't // add them to the format string we're building up. - if !ctx.whitelisted_items().contains(&self.id()) { + if !ctx.allowlisted_items().contains(&self.id()) { return None; } diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 6a7660f6c2..62271acf30 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -443,7 +443,7 @@ impl CodeGenerator for Item { return; } - if self.is_blacklisted(ctx) || result.seen(self.id()) { + if self.is_blocklisted(ctx) || result.seen(self.id()) { debug!( "::codegen: Ignoring hidden or seen: \ self = {:?}", @@ -457,7 +457,7 @@ impl CodeGenerator for Item { // TODO(emilio, #453): Figure out what to do when this happens // legitimately, we could track the opaque stuff and disable the // assertion there I guess. - warn!("Found non-whitelisted item in code generation: {:?}", self); + warn!("Found non-allowlisted item in code generation: {:?}", self); } result.set_seen(self.id()); @@ -725,7 +725,7 @@ impl CodeGenerator for Type { // These items don't need code generation, they only need to be // converted to rust types in fields, arguments, and such. // NOTE(emilio): If you add to this list, make sure to also add - // it to BindgenContext::compute_whitelisted_and_codegen_items. + // it to BindgenContext::compute_allowlisted_and_codegen_items. return; } TypeKind::TemplateInstantiation(ref inst) => { @@ -2261,8 +2261,8 @@ impl MethodCodegen for Method { // First of all, output the actual function. let function_item = ctx.resolve_item(self.signature()); - if function_item.is_blacklisted(ctx) { - // We shouldn't emit a method declaration if the function is blacklisted + if function_item.is_blocklisted(ctx) { + // We shouldn't emit a method declaration if the function is blocklisted return; } function_item.codegen(ctx, result, &()); diff --git a/src/ir/analysis/derive.rs b/src/ir/analysis/derive.rs index 6c50fa6cbf..fa4ce795da 100644 --- a/src/ir/analysis/derive.rs +++ b/src/ir/analysis/derive.rs @@ -138,9 +138,9 @@ impl<'ctx> CannotDerive<'ctx> { } fn constrain_type(&mut self, item: &Item, ty: &Type) -> CanDerive { - if !self.ctx.whitelisted_items().contains(&item.id()) { + if !self.ctx.allowlisted_items().contains(&item.id()) { trace!( - " cannot derive {} for blacklisted type", + " cannot derive {} for blocklisted type", self.derive_trait ); return CanDerive::No; @@ -640,10 +640,10 @@ impl<'ctx> MonotoneFramework for CannotDerive<'ctx> { } fn initial_worklist(&self) -> Vec { - // The transitive closure of all whitelisted items, including explicitly - // blacklisted items. + // The transitive closure of all allowlisted items, including explicitly + // blocklisted items. self.ctx - .whitelisted_items() + .allowlisted_items() .iter() .cloned() .flat_map(|i| { diff --git a/src/ir/analysis/has_destructor.rs b/src/ir/analysis/has_destructor.rs index ca4f2532a1..5fa22e3f0b 100644 --- a/src/ir/analysis/has_destructor.rs +++ b/src/ir/analysis/has_destructor.rs @@ -83,7 +83,7 @@ impl<'ctx> MonotoneFramework for HasDestructorAnalysis<'ctx> { } fn initial_worklist(&self) -> Vec { - self.ctx.whitelisted_items().iter().cloned().collect() + self.ctx.allowlisted_items().iter().cloned().collect() } fn constrain(&mut self, id: ItemId) -> ConstrainResult { diff --git a/src/ir/analysis/has_float.rs b/src/ir/analysis/has_float.rs index d21e651dfa..bbf2126f70 100644 --- a/src/ir/analysis/has_float.rs +++ b/src/ir/analysis/has_float.rs @@ -94,7 +94,7 @@ impl<'ctx> MonotoneFramework for HasFloat<'ctx> { } fn initial_worklist(&self) -> Vec { - self.ctx.whitelisted_items().iter().cloned().collect() + self.ctx.allowlisted_items().iter().cloned().collect() } fn constrain(&mut self, id: ItemId) -> ConstrainResult { diff --git a/src/ir/analysis/has_type_param_in_array.rs b/src/ir/analysis/has_type_param_in_array.rs index ebdb7e3486..aa52304758 100644 --- a/src/ir/analysis/has_type_param_in_array.rs +++ b/src/ir/analysis/has_type_param_in_array.rs @@ -100,7 +100,7 @@ impl<'ctx> MonotoneFramework for HasTypeParameterInArray<'ctx> { } fn initial_worklist(&self) -> Vec { - self.ctx.whitelisted_items().iter().cloned().collect() + self.ctx.allowlisted_items().iter().cloned().collect() } fn constrain(&mut self, id: ItemId) -> ConstrainResult { diff --git a/src/ir/analysis/has_vtable.rs b/src/ir/analysis/has_vtable.rs index d2a57d5af0..7f5f9117bf 100644 --- a/src/ir/analysis/has_vtable.rs +++ b/src/ir/analysis/has_vtable.rs @@ -147,7 +147,7 @@ impl<'ctx> MonotoneFramework for HasVtableAnalysis<'ctx> { } fn initial_worklist(&self) -> Vec { - self.ctx.whitelisted_items().iter().cloned().collect() + self.ctx.allowlisted_items().iter().cloned().collect() } fn constrain(&mut self, id: ItemId) -> ConstrainResult { diff --git a/src/ir/analysis/mod.rs b/src/ir/analysis/mod.rs index 2cb021f0c7..ec4d20f948 100644 --- a/src/ir/analysis/mod.rs +++ b/src/ir/analysis/mod.rs @@ -183,7 +183,7 @@ where { let mut dependencies = HashMap::default(); - for &item in ctx.whitelisted_items() { + for &item in ctx.allowlisted_items() { dependencies.entry(item).or_insert(vec![]); { @@ -192,7 +192,7 @@ where item.trace( ctx, &mut |sub_item: ItemId, edge_kind| { - if ctx.whitelisted_items().contains(&sub_item) && + if ctx.allowlisted_items().contains(&sub_item) && consider_edge(edge_kind) { dependencies diff --git a/src/ir/analysis/sizedness.rs b/src/ir/analysis/sizedness.rs index d8bced7279..a3ef75319c 100644 --- a/src/ir/analysis/sizedness.rs +++ b/src/ir/analysis/sizedness.rs @@ -194,7 +194,7 @@ impl<'ctx> MonotoneFramework for SizednessAnalysis<'ctx> { fn initial_worklist(&self) -> Vec { self.ctx - .whitelisted_items() + .allowlisted_items() .iter() .cloned() .filter_map(|id| id.as_type_id(self.ctx)) diff --git a/src/ir/analysis/template_params.rs b/src/ir/analysis/template_params.rs index f0d9b5e87d..c2f18b1f8d 100644 --- a/src/ir/analysis/template_params.rs +++ b/src/ir/analysis/template_params.rs @@ -137,13 +137,13 @@ use crate::{HashMap, HashSet}; /// analysis. If we didn't, then we would mistakenly determine that ever /// template parameter is always used. /// -/// The final wrinkle is handling of blacklisted types. Normally, we say that -/// the set of whitelisted items is the transitive closure of items explicitly -/// called out for whitelisting, *without* any items explicitly called out as -/// blacklisted. However, for the purposes of this analysis's correctness, we +/// The final wrinkle is handling of blocklisted types. Normally, we say that +/// the set of allowlisted items is the transitive closure of items explicitly +/// called out for allowlisting, *without* any items explicitly called out as +/// blocklisted. However, for the purposes of this analysis's correctness, we /// simplify and consider run the analysis on the full transitive closure of -/// whitelisted items. We do, however, treat instantiations of blacklisted items -/// specially; see `constrain_instantiation_of_blacklisted_template` and its +/// allowlisted items. We do, however, treat instantiations of blocklisted items +/// specially; see `constrain_instantiation_of_blocklisted_template` and its /// documentation for details. #[derive(Debug, Clone)] pub struct UsedTemplateParameters<'ctx> { @@ -155,10 +155,10 @@ pub struct UsedTemplateParameters<'ctx> { dependencies: HashMap>, - // The set of whitelisted items, without any blacklisted items reachable - // from the whitelisted items which would otherwise be considered - // whitelisted as well. - whitelisted_items: HashSet, + // The set of allowlisted items, without any blocklisted items reachable + // from the allowlisted items which would otherwise be considered + // allowlisted as well. + allowlisted_items: HashSet, } impl<'ctx> UsedTemplateParameters<'ctx> { @@ -221,19 +221,19 @@ impl<'ctx> UsedTemplateParameters<'ctx> { ) } - /// We say that blacklisted items use all of their template parameters. The - /// blacklisted type is most likely implemented explicitly by the user, + /// We say that blocklisted items use all of their template parameters. The + /// blocklisted type is most likely implemented explicitly by the user, /// since it won't be in the generated bindings, and we don't know exactly /// what they'll to with template parameters, but we can push the issue down /// the line to them. - fn constrain_instantiation_of_blacklisted_template( + fn constrain_instantiation_of_blocklisted_template( &self, this_id: ItemId, used_by_this_id: &mut ItemSet, instantiation: &TemplateInstantiation, ) { trace!( - " instantiation of blacklisted template, uses all template \ + " instantiation of blocklisted template, uses all template \ arguments" ); @@ -379,10 +379,10 @@ impl<'ctx> MonotoneFramework for UsedTemplateParameters<'ctx> { fn new(ctx: &'ctx BindgenContext) -> UsedTemplateParameters<'ctx> { let mut used = HashMap::default(); let mut dependencies = HashMap::default(); - let whitelisted_items: HashSet<_> = - ctx.whitelisted_items().iter().cloned().collect(); + let allowlisted_items: HashSet<_> = + ctx.allowlisted_items().iter().cloned().collect(); - let whitelisted_and_blacklisted_items: ItemSet = whitelisted_items + let allowlisted_and_blocklisted_items: ItemSet = allowlisted_items .iter() .cloned() .flat_map(|i| { @@ -398,7 +398,7 @@ impl<'ctx> MonotoneFramework for UsedTemplateParameters<'ctx> { }) .collect(); - for item in whitelisted_and_blacklisted_items { + for item in allowlisted_and_blocklisted_items { dependencies.entry(item).or_insert(vec![]); used.entry(item).or_insert(Some(ItemSet::new())); @@ -457,17 +457,17 @@ impl<'ctx> MonotoneFramework for UsedTemplateParameters<'ctx> { } if cfg!(feature = "testing_only_extra_assertions") { - // Invariant: The `used` map has an entry for every whitelisted - // item, as well as all explicitly blacklisted items that are - // reachable from whitelisted items. + // Invariant: The `used` map has an entry for every allowlisted + // item, as well as all explicitly blocklisted items that are + // reachable from allowlisted items. // // Invariant: the `dependencies` map has an entry for every - // whitelisted item. + // allowlisted item. // // (This is so that every item we call `constrain` on is guaranteed // to have a set of template parameters, and we can allow - // blacklisted templates to use all of their parameters). - for item in whitelisted_items.iter() { + // blocklisted templates to use all of their parameters). + for item in allowlisted_items.iter() { extra_assert!(used.contains_key(item)); extra_assert!(dependencies.contains_key(item)); item.trace( @@ -485,15 +485,15 @@ impl<'ctx> MonotoneFramework for UsedTemplateParameters<'ctx> { ctx: ctx, used: used, dependencies: dependencies, - whitelisted_items: whitelisted_items, + allowlisted_items: allowlisted_items, } } fn initial_worklist(&self) -> Vec { - // The transitive closure of all whitelisted items, including explicitly - // blacklisted items. + // The transitive closure of all allowlisted items, including explicitly + // blocklisted items. self.ctx - .whitelisted_items() + .allowlisted_items() .iter() .cloned() .flat_map(|i| { @@ -538,7 +538,7 @@ impl<'ctx> MonotoneFramework for UsedTemplateParameters<'ctx> { // template definition uses the corresponding template parameter. Some(&TypeKind::TemplateInstantiation(ref inst)) => { if self - .whitelisted_items + .allowlisted_items .contains(&inst.template_definition().into()) { self.constrain_instantiation( @@ -547,7 +547,7 @@ impl<'ctx> MonotoneFramework for UsedTemplateParameters<'ctx> { inst, ); } else { - self.constrain_instantiation_of_blacklisted_template( + self.constrain_instantiation_of_blocklisted_template( id, &mut used_by_this_id, inst, diff --git a/src/ir/context.rs b/src/ir/context.rs index 0207547a54..6a0f07d924 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -376,14 +376,14 @@ pub struct BindgenContext { /// Whether a bindgen complex was generated generated_bindgen_complex: Cell, - /// The set of `ItemId`s that are whitelisted. This the very first thing + /// The set of `ItemId`s that are allowlisted. This the very first thing /// computed after parsing our IR, and before running any of our analyses. - whitelisted: Option, + allowlisted: Option, - /// The set of `ItemId`s that are whitelisted for code generation _and_ that + /// The set of `ItemId`s that are allowlisted for code generation _and_ that /// we should generate accounting for the codegen options. /// - /// It's computed right after computing the whitelisted items. + /// It's computed right after computing the allowlisted items. codegen_items: Option, /// Map from an item's id to the set of template parameter items that it @@ -463,8 +463,8 @@ pub struct BindgenContext { has_float: Option>, } -/// A traversal of whitelisted items. -struct WhitelistedItemsTraversal<'ctx> { +/// A traversal of allowlisted items. +struct AllowlistedItemsTraversal<'ctx> { ctx: &'ctx BindgenContext, traversal: ItemTraversal< 'ctx, @@ -474,14 +474,14 @@ struct WhitelistedItemsTraversal<'ctx> { >, } -impl<'ctx> Iterator for WhitelistedItemsTraversal<'ctx> { +impl<'ctx> Iterator for AllowlistedItemsTraversal<'ctx> { type Item = ItemId; fn next(&mut self) -> Option { loop { let id = self.traversal.next()?; - if self.ctx.resolve_item(id).is_blacklisted(self.ctx) { + if self.ctx.resolve_item(id).is_blocklisted(self.ctx) { continue; } @@ -490,8 +490,8 @@ impl<'ctx> Iterator for WhitelistedItemsTraversal<'ctx> { } } -impl<'ctx> WhitelistedItemsTraversal<'ctx> { - /// Construct a new whitelisted items traversal. +impl<'ctx> AllowlistedItemsTraversal<'ctx> { + /// Construct a new allowlisted items traversal. pub fn new( ctx: &'ctx BindgenContext, roots: R, @@ -500,7 +500,7 @@ impl<'ctx> WhitelistedItemsTraversal<'ctx> { where R: IntoIterator, { - WhitelistedItemsTraversal { + AllowlistedItemsTraversal { ctx, traversal: ItemTraversal::new(ctx, roots, predicate), } @@ -559,7 +559,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" target_info, options, generated_bindgen_complex: Cell::new(false), - whitelisted: None, + allowlisted: None, codegen_items: None, used_template_parameters: None, need_bitfield_allocation: Default::default(), @@ -718,8 +718,8 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Ensure that every item (other than the root module) is in a module's - /// children list. This is to make sure that every whitelisted item get's - /// codegen'd, even if its parent is not whitelisted. See issue #769 for + /// children list. This is to make sure that every allowlisted item get's + /// codegen'd, even if its parent is not allowlisted. See issue #769 for /// details. fn add_item_to_module(&mut self, item: &Item) { assert!(item.id() != self.root_module); @@ -1024,7 +1024,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" _ => continue, } - let path = item.path_for_whitelisting(self); + let path = item.path_for_allowlisting(self); let replacement = self.replacements.get(&path[1..]); if let Some(replacement) = replacement { @@ -1134,10 +1134,10 @@ If you encounter an error missing from this list, please file an issue or a PR!" self.assert_no_dangling_references(); - // Compute the whitelisted set after processing replacements and + // Compute the allowlisted set after processing replacements and // resolving type refs, as those are the final mutations of the IR // graph, and their completion means that the IR graph is now frozen. - self.compute_whitelisted_and_codegen_items(); + self.compute_allowlisted_and_codegen_items(); // Make sure to do this after processing replacements, since that messes // with the parentage and module children, and we want to assert that it @@ -1293,14 +1293,14 @@ If you encounter an error missing from this list, please file an issue or a PR!" fn find_used_template_parameters(&mut self) { let _t = self.timer("find_used_template_parameters"); - if self.options.whitelist_recursively { + if self.options.allowlist_recursively { let used_params = analyze::(self); self.used_template_parameters = Some(used_params); } else { - // If you aren't recursively whitelisting, then we can't really make + // If you aren't recursively allowlisting, then we can't really make // any sense of template parameter usage, and you're on your own. let mut used_params = HashMap::default(); - for &id in self.whitelisted_items() { + for &id in self.allowlisted_items() { used_params.entry(id).or_insert( id.self_template_params(self) .into_iter() @@ -1319,9 +1319,9 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// template usage information is only computed as we enter the codegen /// phase. /// - /// If the item is blacklisted, then we say that it always uses the template + /// If the item is blocklisted, then we say that it always uses the template /// parameter. This is a little subtle. The template parameter usage - /// analysis only considers whitelisted items, and if any blacklisted item + /// analysis only considers allowlisted items, and if any blocklisted item /// shows up in the generated bindings, it is the user's responsibility to /// manually provide a definition for them. To give them the most /// flexibility when doing that, we assume that they use every template @@ -1336,7 +1336,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" "We only compute template parameter usage as we enter codegen" ); - if self.resolve_item(item).is_blacklisted(self) { + if self.resolve_item(item).is_blocklisted(self) { return true; } @@ -2194,15 +2194,15 @@ If you encounter an error missing from this list, please file an issue or a PR!" self.current_module = previous_id; } - /// Iterate over all (explicitly or transitively) whitelisted items. + /// Iterate over all (explicitly or transitively) allowlisted items. /// - /// If no items are explicitly whitelisted, then all items are considered - /// whitelisted. - pub fn whitelisted_items(&self) -> &ItemSet { + /// If no items are explicitly allowlisted, then all items are considered + /// allowlisted. + pub fn allowlisted_items(&self) -> &ItemSet { assert!(self.in_codegen_phase()); assert!(self.current_module == self.root_module); - self.whitelisted.as_ref().unwrap() + self.allowlisted.as_ref().unwrap() } /// Get a reference to the set of items we should generate. @@ -2212,12 +2212,12 @@ If you encounter an error missing from this list, please file an issue or a PR!" self.codegen_items.as_ref().unwrap() } - /// Compute the whitelisted items set and populate `self.whitelisted`. - fn compute_whitelisted_and_codegen_items(&mut self) { + /// Compute the allowlisted items set and populate `self.allowlisted`. + fn compute_allowlisted_and_codegen_items(&mut self) { assert!(self.in_codegen_phase()); assert!(self.current_module == self.root_module); - assert!(self.whitelisted.is_none()); - let _t = self.timer("compute_whitelisted_and_codegen_items"); + assert!(self.allowlisted.is_none()); + let _t = self.timer("compute_allowlisted_and_codegen_items"); let roots = { let mut roots = self @@ -2225,11 +2225,11 @@ If you encounter an error missing from this list, please file an issue or a PR!" // Only consider roots that are enabled for codegen. .filter(|&(_, item)| item.is_enabled_for_codegen(self)) .filter(|&(_, item)| { - // If nothing is explicitly whitelisted, then everything is fair + // If nothing is explicitly allowlisted, then everything is fair // game. - if self.options().whitelisted_types.is_empty() && - self.options().whitelisted_functions.is_empty() && - self.options().whitelisted_vars.is_empty() + if self.options().allowlisted_types.is_empty() && + self.options().allowlisted_functions.is_empty() && + self.options().allowlisted_vars.is_empty() { return true; } @@ -2240,25 +2240,25 @@ If you encounter an error missing from this list, please file an issue or a PR!" return true; } - let name = item.path_for_whitelisting(self)[1..].join("::"); - debug!("whitelisted_items: testing {:?}", name); + let name = item.path_for_allowlisting(self)[1..].join("::"); + debug!("allowlisted_items: testing {:?}", name); match *item.kind() { ItemKind::Module(..) => true, ItemKind::Function(_) => { - self.options().whitelisted_functions.matches(&name) + self.options().allowlisted_functions.matches(&name) } ItemKind::Var(_) => { - self.options().whitelisted_vars.matches(&name) + self.options().allowlisted_vars.matches(&name) } ItemKind::Type(ref ty) => { - if self.options().whitelisted_types.matches(&name) { + if self.options().allowlisted_types.matches(&name) { return true; } - // Auto-whitelist types that don't need code - // generation if not whitelisting recursively, to + // Auto-allowlist types that don't need code + // generation if not allowlisting recursively, to // make the #[derive] analysis not be lame. - if !self.options().whitelist_recursively { + if !self.options().allowlist_recursively { match *ty.kind() { TypeKind::Void | TypeKind::NullPtr | @@ -2278,7 +2278,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" } // Unnamed top-level enums are special and we - // whitelist them via the `whitelisted_vars` filter, + // allowlist them via the `allowlisted_vars` filter, // since they're effectively top-level constants, // and there's no way for them to be referenced // consistently. @@ -2297,12 +2297,12 @@ If you encounter an error missing from this list, please file an issue or a PR!" } let mut prefix_path = - parent.path_for_whitelisting(self).clone(); + parent.path_for_allowlisting(self).clone(); enum_.variants().iter().any(|variant| { prefix_path.push(variant.name().into()); let name = prefix_path[1..].join("::"); prefix_path.pop().unwrap(); - self.options().whitelisted_vars.matches(&name) + self.options().allowlisted_vars.matches(&name) }) } } @@ -2317,48 +2317,48 @@ If you encounter an error missing from this list, please file an issue or a PR!" roots }; - let whitelisted_items_predicate = - if self.options().whitelist_recursively { + let allowlisted_items_predicate = + if self.options().allowlist_recursively { traversal::all_edges } else { - // Only follow InnerType edges from the whitelisted roots. + // Only follow InnerType edges from the allowlisted roots. // Such inner types (e.g. anonymous structs/unions) are - // always emitted by codegen, and they need to be whitelisted + // always emitted by codegen, and they need to be allowlisted // to make sure they are processed by e.g. the derive analysis. traversal::only_inner_type_edges }; - let whitelisted = WhitelistedItemsTraversal::new( + let allowlisted = AllowlistedItemsTraversal::new( self, roots.clone(), - whitelisted_items_predicate, + allowlisted_items_predicate, ) .collect::(); - let codegen_items = if self.options().whitelist_recursively { - WhitelistedItemsTraversal::new( + let codegen_items = if self.options().allowlist_recursively { + AllowlistedItemsTraversal::new( self, roots.clone(), traversal::codegen_edges, ) .collect::() } else { - whitelisted.clone() + allowlisted.clone() }; - self.whitelisted = Some(whitelisted); + self.allowlisted = Some(allowlisted); self.codegen_items = Some(codegen_items); - for item in self.options().whitelisted_functions.unmatched_items() { - warn!("unused option: --whitelist-function {}", item); + for item in self.options().allowlisted_functions.unmatched_items() { + warn!("unused option: --allowlist-function {}", item); } - for item in self.options().whitelisted_vars.unmatched_items() { - warn!("unused option: --whitelist-var {}", item); + for item in self.options().allowlisted_vars.unmatched_items() { + warn!("unused option: --allowlist-var {}", item); } - for item in self.options().whitelisted_types.unmatched_items() { - warn!("unused option: --whitelist-type {}", item); + for item in self.options().allowlisted_types.unmatched_items() { + warn!("unused option: --allowlist-type {}", item); } } @@ -2575,31 +2575,31 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// Check if `--no-partialeq` flag is enabled for this item. pub fn no_partialeq_by_name(&self, item: &Item) -> bool { - let name = item.path_for_whitelisting(self)[1..].join("::"); + let name = item.path_for_allowlisting(self)[1..].join("::"); self.options().no_partialeq_types.matches(&name) } /// Check if `--no-copy` flag is enabled for this item. pub fn no_copy_by_name(&self, item: &Item) -> bool { - let name = item.path_for_whitelisting(self)[1..].join("::"); + let name = item.path_for_allowlisting(self)[1..].join("::"); self.options().no_copy_types.matches(&name) } /// Check if `--no-debug` flag is enabled for this item. pub fn no_debug_by_name(&self, item: &Item) -> bool { - let name = item.path_for_whitelisting(self)[1..].join("::"); + let name = item.path_for_allowlisting(self)[1..].join("::"); self.options().no_debug_types.matches(&name) } /// Check if `--no-default` flag is enabled for this item. pub fn no_default_by_name(&self, item: &Item) -> bool { - let name = item.path_for_whitelisting(self)[1..].join("::"); + let name = item.path_for_allowlisting(self)[1..].join("::"); self.options().no_default_types.matches(&name) } /// Check if `--no-hash` flag is enabled for this item. pub fn no_hash_by_name(&self, item: &Item) -> bool { - let name = item.path_for_whitelisting(self)[1..].join("::"); + let name = item.path_for_allowlisting(self)[1..].join("::"); self.options().no_hash_types.matches(&name) } } diff --git a/src/ir/dot.rs b/src/ir/dot.rs index 6bf75bfa77..f7d07f19e2 100644 --- a/src/ir/dot.rs +++ b/src/ir/dot.rs @@ -32,13 +32,13 @@ where let mut err: Option> = None; for (id, item) in ctx.items() { - let is_whitelisted = ctx.whitelisted_items().contains(&id); + let is_allowlisted = ctx.allowlisted_items().contains(&id); writeln!( &mut dot_file, r#"{} [fontname="courier", color={}, label=< "#, id.as_usize(), - if is_whitelisted { "black" } else { "gray" } + if is_allowlisted { "black" } else { "gray" } )?; item.dot_attributes(ctx, &mut dot_file)?; writeln!(&mut dot_file, r#"
>];"#)?; @@ -56,7 +56,7 @@ where id.as_usize(), sub_id.as_usize(), edge_kind, - if is_whitelisted { "black" } else { "gray" } + if is_allowlisted { "black" } else { "gray" } ) { Ok(_) => {} Err(e) => err = Some(Err(e)), diff --git a/src/ir/enum_ty.rs b/src/ir/enum_ty.rs index dde4bb1835..c6cd89ce97 100644 --- a/src/ir/enum_ty.rs +++ b/src/ir/enum_ty.rs @@ -152,7 +152,7 @@ impl Enum { enums: &RegexSet, item: &Item, ) -> bool { - let path = item.path_for_whitelisting(ctx); + let path = item.path_for_allowlisting(ctx); let enum_ty = item.expect_type(); if enums.matches(&path[1..].join("::")) { diff --git a/src/ir/item.rs b/src/ir/item.rs index e9abed7032..45415045fe 100644 --- a/src/ir/item.rs +++ b/src/ir/item.rs @@ -273,10 +273,10 @@ impl Trace for Item { where T: Tracer, { - // Even if this item is blacklisted/hidden, we want to trace it. It is + // Even if this item is blocklisted/hidden, we want to trace it. It is // traversal iterators' consumers' responsibility to filter items as // needed. Generally, this filtering happens in the implementation of - // `Iterator` for `WhitelistedItems`. Fully tracing blacklisted items is + // `Iterator` for `allowlistedItems`. Fully tracing blocklisted items is // necessary for things like the template parameter usage analysis to // function correctly. @@ -301,12 +301,12 @@ impl Trace for Item { } ItemKind::Module(_) => { // Module -> children edges are "weak", and we do not want to - // trace them. If we did, then whitelisting wouldn't work as + // trace them. If we did, then allowlisting wouldn't work as // expected: everything in every module would end up - // whitelisted. + // allowlisted. // // TODO: make a new edge kind for module -> children edges and - // filter them during whitelisting traversals. + // filter them during allowlisting traversals. } } } @@ -400,9 +400,9 @@ pub struct Item { /// considerably faster in those cases. canonical_name: LazyCell, - /// The path to use for whitelisting and other name-based checks, as - /// returned by `path_for_whitelisting`, lazily constructed. - path_for_whitelisting: LazyCell>, + /// The path to use for allowlisting and other name-based checks, as + /// returned by `path_for_allowlisting`, lazily constructed. + path_for_allowlisting: LazyCell>, /// A doc comment over the item, if any. comment: Option, @@ -440,7 +440,7 @@ impl Item { local_id: LazyCell::new(), next_child_local_id: Cell::new(1), canonical_name: LazyCell::new(), - path_for_whitelisting: LazyCell::new(), + path_for_allowlisting: LazyCell::new(), parent_id: parent_id, comment: comment, annotations: annotations.unwrap_or_default(), @@ -623,10 +623,10 @@ impl Item { &self.annotations } - /// Whether this item should be blacklisted. + /// Whether this item should be blocklisted. /// /// This may be due to either annotations or to other kind of configuration. - pub fn is_blacklisted(&self, ctx: &BindgenContext) -> bool { + pub fn is_blocklisted(&self, ctx: &BindgenContext) -> bool { debug_assert!( ctx.in_codegen_phase(), "You're not supposed to call this yet" @@ -635,18 +635,18 @@ impl Item { return true; } - let path = self.path_for_whitelisting(ctx); + let path = self.path_for_allowlisting(ctx); let name = path[1..].join("::"); - ctx.options().blacklisted_items.matches(&name) || + ctx.options().blocklisted_items.matches(&name) || match self.kind { ItemKind::Type(..) => { - ctx.options().blacklisted_types.matches(&name) || + ctx.options().blocklisted_types.matches(&name) || ctx.is_replaced_type(&path, self.id) } ItemKind::Function(..) => { - ctx.options().blacklisted_functions.matches(&name) + ctx.options().blocklisted_functions.matches(&name) } - // TODO: Add constant / namespace blacklisting? + // TODO: Add constant / namespace blocklisting? ItemKind::Var(..) | ItemKind::Module(..) => false, } } @@ -1012,10 +1012,10 @@ impl Item { } } - /// Returns the path we should use for whitelisting / blacklisting, which + /// Returns the path we should use for allowlisting / blocklisting, which /// doesn't include user-mangling. - pub fn path_for_whitelisting(&self, ctx: &BindgenContext) -> &Vec { - self.path_for_whitelisting + pub fn path_for_allowlisting(&self, ctx: &BindgenContext) -> &Vec { + self.path_for_allowlisting .borrow_with(|| self.compute_path(ctx, UserMangled::No)) } @@ -1081,7 +1081,7 @@ impl IsOpaque for Item { ); self.annotations.opaque() || self.as_type().map_or(false, |ty| ty.is_opaque(ctx, self)) || - ctx.opaque_by_name(&self.path_for_whitelisting(ctx)) + ctx.opaque_by_name(&self.path_for_allowlisting(ctx)) } } @@ -1390,7 +1390,7 @@ impl ClangItemParser for Item { if cursor.kind() == CXCursor_UnexposedDecl { Err(ParseError::Recurse) } else { - // We whitelist cursors here known to be unhandled, to prevent being + // We allowlist cursors here known to be unhandled, to prevent being // too noisy about this. match cursor.kind() { CXCursor_MacroDefinition | @@ -1918,7 +1918,7 @@ impl ItemCanonicalPath for Item { /// not. /// /// Most of the callers probably want just yes, but the ones dealing with -/// whitelisting and blacklisting don't. +/// allowlisting and blocklisting don't. #[derive(Copy, Clone, Debug, PartialEq)] enum UserMangled { No, diff --git a/src/ir/template.rs b/src/ir/template.rs index 8c625d1d92..b519fff132 100644 --- a/src/ir/template.rs +++ b/src/ir/template.rs @@ -306,13 +306,13 @@ impl IsOpaque for TemplateInstantiation { // correct fix is to make `canonical_{name,path}` include template // arguments properly. - let mut path = item.path_for_whitelisting(ctx).clone(); + let mut path = item.path_for_allowlisting(ctx).clone(); let args: Vec<_> = self .template_arguments() .iter() .map(|arg| { let arg_path = - ctx.resolve_item(*arg).path_for_whitelisting(ctx); + ctx.resolve_item(*arg).path_for_allowlisting(ctx); arg_path[1..].join("::") }) .collect(); diff --git a/src/ir/traversal.rs b/src/ir/traversal.rs index e4a447032b..430dd02796 100644 --- a/src/ir/traversal.rs +++ b/src/ir/traversal.rs @@ -201,7 +201,7 @@ pub fn all_edges(_: &BindgenContext, _: Edge) -> bool { /// A `TraversalPredicate` implementation that only follows /// `EdgeKind::InnerType` edges, and therefore traversals using this predicate /// will only visit the traversal's roots and their inner types. This is used -/// in no-recursive-whitelist mode, where inner types such as anonymous +/// in no-recursive-allowlist mode, where inner types such as anonymous /// structs/unions still need to be processed. pub fn only_inner_type_edges(_: &BindgenContext, edge: Edge) -> bool { edge.kind == EdgeKind::InnerType @@ -377,7 +377,7 @@ pub trait Trace { /// An graph traversal of the transitive closure of references between items. /// -/// See `BindgenContext::whitelisted_items` for more information. +/// See `BindgenContext::allowlisted_items` for more information. pub struct ItemTraversal<'ctx, Storage, Queue, Predicate> where Storage: TraversalStorage<'ctx>, diff --git a/src/lib.rs b/src/lib.rs index 06ba8e6377..945d3065f1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -177,8 +177,8 @@ impl Default for CodegenConfig { /// /// // Configure and generate bindings. /// let bindings = builder().header("path/to/input/header") -/// .whitelist_type("SomeCoolClass") -/// .whitelist_function("do_some_cool_thing") +/// .allowlist_type("SomeCoolClass") +/// .allowlist_function("do_some_cool_thing") /// .generate()?; /// /// // Write the generated bindings to an output file. @@ -304,13 +304,13 @@ impl Builder { (&self.options.type_alias, "--type-alias"), (&self.options.new_type_alias, "--new-type-alias"), (&self.options.new_type_alias_deref, "--new-type-alias-deref"), - (&self.options.blacklisted_types, "--blacklist-type"), - (&self.options.blacklisted_functions, "--blacklist-function"), - (&self.options.blacklisted_items, "--blacklist-item"), + (&self.options.blocklisted_types, "--blocklist-type"), + (&self.options.blocklisted_functions, "--blocklist-function"), + (&self.options.blocklisted_items, "--blocklist-item"), (&self.options.opaque_types, "--opaque-type"), - (&self.options.whitelisted_functions, "--whitelist-function"), - (&self.options.whitelisted_types, "--whitelist-type"), - (&self.options.whitelisted_vars, "--whitelist-var"), + (&self.options.allowlisted_functions, "--allowlist-function"), + (&self.options.allowlisted_types, "--allowlist-type"), + (&self.options.allowlisted_vars, "--allowlist-var"), (&self.options.no_partialeq_types, "--no-partialeq"), (&self.options.no_copy_types, "--no-copy"), (&self.options.no_debug_types, "--no-debug"), @@ -379,8 +379,8 @@ impl Builder { output_vector.push("--no-doc-comments".into()); } - if !self.options.whitelist_recursively { - output_vector.push("--no-recursive-whitelist".into()); + if !self.options.allowlist_recursively { + output_vector.push("--no-recursive-allowlist".into()); } if self.options.objc_extern_crate { @@ -661,9 +661,9 @@ impl Builder { self } - /// Whether to whitelist recursively or not. Defaults to true. + /// Whether to allowlist recursively or not. Defaults to true. /// - /// Given that we have explicitly whitelisted the "initiate_dance_party" + /// Given that we have explicitly allowlisted the "initiate_dance_party" /// function in this C header: /// /// ```c @@ -676,20 +676,20 @@ impl Builder { /// /// We would normally generate bindings to both the `initiate_dance_party` /// function and the `MoonBoots` struct that it transitively references. By - /// configuring with `whitelist_recursively(false)`, `bindgen` will not emit - /// bindings for anything except the explicitly whitelisted items, and there + /// configuring with `allowlist_recursively(false)`, `bindgen` will not emit + /// bindings for anything except the explicitly allowlisted items, and there /// would be no emitted struct definition for `MoonBoots`. However, the /// `initiate_dance_party` function would still reference `MoonBoots`! /// /// **Disabling this feature will almost certainly cause `bindgen` to emit /// bindings that will not compile!** If you disable this feature, then it /// is *your* responsibility to provide definitions for every type that is - /// referenced from an explicitly whitelisted item. One way to provide the + /// referenced from an explicitly allowlisted item. One way to provide the /// definitions is by using the [`Builder::raw_line`](#method.raw_line) /// method, another would be to define them in Rust and then `include!(...)` /// the bindings immediately afterwards. - pub fn whitelist_recursively(mut self, doit: bool) -> Self { - self.options.whitelist_recursively = doit; + pub fn allowlist_recursively(mut self, doit: bool) -> Self { + self.options.allowlist_recursively = doit; self } @@ -727,30 +727,53 @@ impl Builder { /// Hide the given type from the generated bindings. Regular expressions are /// supported. - #[deprecated(note = "Use blacklist_type instead")] + #[deprecated(note = "Use blocklist_type instead")] pub fn hide_type>(self, arg: T) -> Builder { - self.blacklist_type(arg) + self.blocklist_type(arg) + } + + /// Hide the given type from the generated bindings. Regular expressions are + /// supported. + #[deprecated(note = "Use blocklist_type instead")] + pub fn blacklist_type>(self, arg: T) -> Builder { + self.blocklist_type(arg) } /// Hide the given type from the generated bindings. Regular expressions are /// supported. /// - /// To blacklist types prefixed with "mylib" use `"mylib_.*"`. + /// To blocklist types prefixed with "mylib" use `"mylib_.*"`. /// For more complicated expressions check /// [regex](https://docs.rs/regex/*/regex/) docs - pub fn blacklist_type>(mut self, arg: T) -> Builder { - self.options.blacklisted_types.insert(arg); + pub fn blocklist_type>(mut self, arg: T) -> Builder { + self.options.blocklisted_types.insert(arg); self } + /// Hide the given function from the generated bindings. Regular expressions + /// are supported. + #[deprecated(note = "Use blocklist_function instead")] + pub fn blacklist_function>(self, arg: T) -> Builder { + self.blocklist_function(arg) + } + /// Hide the given function from the generated bindings. Regular expressions /// are supported. /// - /// To blacklist functions prefixed with "mylib" use `"mylib_.*"`. + /// To blocklist functions prefixed with "mylib" use `"mylib_.*"`. /// For more complicated expressions check /// [regex](https://docs.rs/regex/*/regex/) docs - pub fn blacklist_function>(mut self, arg: T) -> Builder { - self.options.blacklisted_functions.insert(arg); + pub fn blocklist_function>(mut self, arg: T) -> Builder { + self.options.blocklisted_functions.insert(arg); + self + } + + /// Hide the given item from the generated bindings, regardless of + /// whether it's a type, function, module, etc. Regular + /// expressions are supported. + #[deprecated(note = "Use blocklist_item instead")] + pub fn blacklist_item>(mut self, arg: T) -> Builder { + self.options.blocklisted_items.insert(arg); self } @@ -758,11 +781,11 @@ impl Builder { /// whether it's a type, function, module, etc. Regular /// expressions are supported. /// - /// To blacklist items prefixed with "mylib" use `"mylib_.*"`. + /// To blocklist items prefixed with "mylib" use `"mylib_.*"`. /// For more complicated expressions check /// [regex](https://docs.rs/regex/*/regex/) docs - pub fn blacklist_item>(mut self, arg: T) -> Builder { - self.options.blacklisted_items.insert(arg); + pub fn blocklist_item>(mut self, arg: T) -> Builder { + self.options.blocklisted_items.insert(arg); self } @@ -777,64 +800,86 @@ impl Builder { self } - /// Whitelist the given type so that it (and all types that it transitively + /// Allowlist the given type so that it (and all types that it transitively /// refers to) appears in the generated bindings. Regular expressions are /// supported. - #[deprecated(note = "use whitelist_type instead")] + #[deprecated(note = "use allowlist_type instead")] pub fn whitelisted_type>(self, arg: T) -> Builder { - self.whitelist_type(arg) + self.allowlist_type(arg) + } + + /// Allowlist the given type so that it (and all types that it transitively + /// refers to) appears in the generated bindings. Regular expressions are + /// supported. + #[deprecated(note = "use allowlist_type instead")] + pub fn whitelist_type>(self, arg: T) -> Builder { + self.allowlist_type(arg) } - /// Whitelist the given type so that it (and all types that it transitively + /// Allowlist the given type so that it (and all types that it transitively /// refers to) appears in the generated bindings. Regular expressions are /// supported. /// - /// To whitelist types prefixed with "mylib" use `"mylib_.*"`. + /// To allowlist types prefixed with "mylib" use `"mylib_.*"`. /// For more complicated expressions check /// [regex](https://docs.rs/regex/*/regex/) docs - pub fn whitelist_type>(mut self, arg: T) -> Builder { - self.options.whitelisted_types.insert(arg); + pub fn allowlist_type>(mut self, arg: T) -> Builder { + self.options.allowlisted_types.insert(arg); self } - /// Whitelist the given function so that it (and all types that it + /// Allowlist the given function so that it (and all types that it /// transitively refers to) appears in the generated bindings. Regular /// expressions are supported. /// - /// To whitelist functions prefixed with "mylib" use `"mylib_.*"`. + /// To allowlist functions prefixed with "mylib" use `"mylib_.*"`. /// For more complicated expressions check /// [regex](https://docs.rs/regex/*/regex/) docs - pub fn whitelist_function>(mut self, arg: T) -> Builder { - self.options.whitelisted_functions.insert(arg); + pub fn allowlist_function>(mut self, arg: T) -> Builder { + self.options.allowlisted_functions.insert(arg); self } - /// Whitelist the given function. + /// Allowlist the given function. + /// + /// Deprecated: use allowlist_function instead. + #[deprecated(note = "use allowlist_function instead")] + pub fn whitelist_function>(self, arg: T) -> Builder { + self.allowlist_function(arg) + } + + /// Allowlist the given function. /// - /// Deprecated: use whitelist_function instead. - #[deprecated(note = "use whitelist_function instead")] + /// Deprecated: use allowlist_function instead. + #[deprecated(note = "use allowlist_function instead")] pub fn whitelisted_function>(self, arg: T) -> Builder { - self.whitelist_function(arg) + self.allowlist_function(arg) } - /// Whitelist the given variable so that it (and all types that it + /// Allowlist the given variable so that it (and all types that it /// transitively refers to) appears in the generated bindings. Regular /// expressions are supported. /// - /// To whitelist variables prefixed with "mylib" use `"mylib_.*"`. + /// To allowlist variables prefixed with "mylib" use `"mylib_.*"`. /// For more complicated expressions check /// [regex](https://docs.rs/regex/*/regex/) docs - pub fn whitelist_var>(mut self, arg: T) -> Builder { - self.options.whitelisted_vars.insert(arg); + pub fn allowlist_var>(mut self, arg: T) -> Builder { + self.options.allowlisted_vars.insert(arg); self } - /// Whitelist the given variable. + /// Deprecated: use allowlist_var instead. + #[deprecated(note = "use allowlist_var instead")] + pub fn whitelist_var>(self, arg: T) -> Builder { + self.allowlist_var(arg) + } + + /// Allowlist the given variable. /// - /// Deprecated: use whitelist_var instead. - #[deprecated(note = "use whitelist_var instead")] + /// Deprecated: use allowlist_var instead. + #[deprecated(note = "use allowlist_var instead")] pub fn whitelisted_var>(self, arg: T) -> Builder { - self.whitelist_var(arg) + self.allowlist_var(arg) } /// Set the default style of code to generate for enums @@ -1163,7 +1208,7 @@ impl Builder { /// This method disables that behavior. /// /// Note that this intentionally does not change the names used for - /// whitelisting and blacklisting, which should still be mangled with the + /// allowlisting and blocklisting, which should still be mangled with the /// namespaces. /// /// Note, also, that this option may cause bindgen to generate duplicate @@ -1533,17 +1578,17 @@ impl Builder { /// Configuration options for generated bindings. #[derive(Debug)] struct BindgenOptions { - /// The set of types that have been blacklisted and should not appear + /// The set of types that have been blocklisted and should not appear /// anywhere in the generated code. - blacklisted_types: RegexSet, + blocklisted_types: RegexSet, - /// The set of functions that have been blacklisted and should not appear + /// The set of functions that have been blocklisted and should not appear /// in the generated code. - blacklisted_functions: RegexSet, + blocklisted_functions: RegexSet, /// The set of items, regardless of item-type, that have been - /// blacklisted and should not appear in the generated code. - blacklisted_items: RegexSet, + /// blocklisted and should not appear in the generated code. + blocklisted_items: RegexSet, /// The set of types that should be treated as opaque structures in the /// generated code. @@ -1556,15 +1601,15 @@ struct BindgenOptions { /// code. /// /// This includes all types transitively reachable from any type in this - /// set. One might think of whitelisted types/vars/functions as GC roots, + /// set. One might think of allowlisted types/vars/functions as GC roots, /// and the generated Rust code as including everything that gets marked. - whitelisted_types: RegexSet, + allowlisted_types: RegexSet, - /// Whitelisted functions. See docs for `whitelisted_types` for more. - whitelisted_functions: RegexSet, + /// Allowlisted functions. See docs for `allowlisted_types` for more. + allowlisted_functions: RegexSet, - /// Whitelisted variables. See docs for `whitelisted_types` for more. - whitelisted_vars: RegexSet, + /// Allowlisted variables. See docs for `allowlisted_types` for more. + allowlisted_vars: RegexSet, /// The default style of code to generate for enums default_enum_style: codegen::EnumVariation, @@ -1736,8 +1781,8 @@ struct BindgenOptions { /// Whether to generate inline functions. Defaults to false. generate_inline_functions: bool, - /// Whether to whitelist types recursively. Defaults to true. - whitelist_recursively: bool, + /// Whether to allowlist types recursively. Defaults to true. + allowlist_recursively: bool, /// Instead of emitting 'use objc;' to files generated from objective c files, /// generate '#[macro_use] extern crate objc;' @@ -1777,7 +1822,7 @@ struct BindgenOptions { /// Whether we should record which items in the regex sets ever matched. /// - /// This may be a bit slower, but will enable reporting of unused whitelist + /// This may be a bit slower, but will enable reporting of unused allowlist /// items via the `error!` log. record_matches: bool, @@ -1829,12 +1874,12 @@ impl ::std::panic::UnwindSafe for BindgenOptions {} impl BindgenOptions { fn build(&mut self) { let mut regex_sets = [ - &mut self.whitelisted_vars, - &mut self.whitelisted_types, - &mut self.whitelisted_functions, - &mut self.blacklisted_types, - &mut self.blacklisted_functions, - &mut self.blacklisted_items, + &mut self.allowlisted_vars, + &mut self.allowlisted_types, + &mut self.allowlisted_functions, + &mut self.blocklisted_types, + &mut self.blocklisted_functions, + &mut self.blocklisted_items, &mut self.opaque_types, &mut self.bitfield_enums, &mut self.constified_enums, @@ -1878,14 +1923,14 @@ impl Default for BindgenOptions { BindgenOptions { rust_target, rust_features: rust_target.into(), - blacklisted_types: Default::default(), - blacklisted_functions: Default::default(), - blacklisted_items: Default::default(), + blocklisted_types: Default::default(), + blocklisted_functions: Default::default(), + blocklisted_items: Default::default(), opaque_types: Default::default(), rustfmt_path: Default::default(), - whitelisted_types: Default::default(), - whitelisted_functions: Default::default(), - whitelisted_vars: Default::default(), + allowlisted_types: Default::default(), + allowlisted_functions: Default::default(), + allowlisted_vars: Default::default(), default_enum_style: Default::default(), bitfield_enums: Default::default(), newtype_enums: Default::default(), @@ -1934,7 +1979,7 @@ impl Default for BindgenOptions { conservative_inline_namespaces: false, generate_comments: true, generate_inline_functions: false, - whitelist_recursively: true, + allowlist_recursively: true, generate_block: false, objc_extern_crate: false, block_extern_crate: false, @@ -2520,8 +2565,8 @@ fn commandline_flag_unit_test_function() { //Test 2 let bindings = crate::builder() .header("input_header") - .whitelist_type("Distinct_Type") - .whitelist_function("safe_function"); + .allowlist_type("Distinct_Type") + .allowlist_function("safe_function"); let command_line_flags = bindings.command_line_flags(); let test_cases = vec![ @@ -2530,9 +2575,9 @@ fn commandline_flag_unit_test_function() { "--no-derive-default", "--generate", "functions,types,vars,methods,constructors,destructors", - "--whitelist-type", + "--allowlist-type", "Distinct_Type", - "--whitelist-function", + "--allowlist-function", "safe_function", ] .iter() diff --git a/src/options.rs b/src/options.rs index 63e48dc830..2289ad09bd 100644 --- a/src/options.rs +++ b/src/options.rs @@ -136,22 +136,25 @@ where .takes_value(true) .multiple(true) .number_of_values(1), - Arg::with_name("blacklist-type") - .long("blacklist-type") + Arg::with_name("blocklist-type") + .alias("blacklist-type") + .long("blocklist-type") .help("Mark as hidden.") .value_name("type") .takes_value(true) .multiple(true) .number_of_values(1), - Arg::with_name("blacklist-function") - .long("blacklist-function") + Arg::with_name("blocklist-function") + .alias("blacklist-function") + .long("blocklist-function") .help("Mark as hidden.") .value_name("function") .takes_value(true) .multiple(true) .number_of_values(1), - Arg::with_name("blacklist-item") - .long("blacklist-item") + Arg::with_name("blocklist-item") + .alias("blacklist-item") + .long("blocklist-item") .help("Mark as hidden.") .value_name("item") .takes_value(true) @@ -210,12 +213,13 @@ where "Avoid including doc comments in the output, see: \ https://github.com/rust-lang/rust-bindgen/issues/426", ), - Arg::with_name("no-recursive-whitelist") - .long("no-recursive-whitelist") + Arg::with_name("no-recursive-allowlist") + .long("no-recursive-allowlist") + .alias("no-recursive-whitelist") .help( - "Disable whitelisting types recursively. This will cause \ + "Disable allowlisting types recursively. This will cause \ bindgen to emit Rust code that won't compile! See the \ - `bindgen::Builder::whitelist_recursively` method's \ + `bindgen::Builder::allowlist_recursively` method's \ documentation for details.", ), Arg::with_name("objc-extern-crate") @@ -364,11 +368,12 @@ where Arg::with_name("use-msvc-mangling") .long("use-msvc-mangling") .help("MSVC C++ ABI mangling. DEPRECATED: Has no effect."), - Arg::with_name("whitelist-function") - .long("whitelist-function") + Arg::with_name("allowlist-function") + .long("allowlist-function") + .alias("whitelist-function") .help( - "Whitelist all the free-standing functions matching \ - . Other non-whitelisted functions will not be \ + "Allowlist all the free-standing functions matching \ + . Other non-allowlisted functions will not be \ generated.", ) .value_name("regex") @@ -378,21 +383,23 @@ where Arg::with_name("generate-inline-functions") .long("generate-inline-functions") .help("Generate inline functions."), - Arg::with_name("whitelist-type") - .long("whitelist-type") + Arg::with_name("allowlist-type") + .long("allowlist-type") + .alias("whitelist-type") .help( - "Only generate types matching . Other non-whitelisted types will \ + "Only generate types matching . Other non-allowlisted types will \ not be generated.", ) .value_name("regex") .takes_value(true) .multiple(true) .number_of_values(1), - Arg::with_name("whitelist-var") - .long("whitelist-var") + Arg::with_name("allowlist-var") + .long("allowlist-var") + .alias("whitelist-var") .help( - "Whitelist all the free-standing variables matching \ - . Other non-whitelisted variables will not be \ + "Allowlist all the free-standing variables matching \ + . Other non-allowlisted variables will not be \ generated.", ) .value_name("regex") @@ -582,21 +589,21 @@ where } } - if let Some(hidden_types) = matches.values_of("blacklist-type") { + if let Some(hidden_types) = matches.values_of("blocklist-type") { for ty in hidden_types { - builder = builder.blacklist_type(ty); + builder = builder.blocklist_type(ty); } } - if let Some(hidden_functions) = matches.values_of("blacklist-function") { + if let Some(hidden_functions) = matches.values_of("blocklist-function") { for fun in hidden_functions { - builder = builder.blacklist_function(fun); + builder = builder.blocklist_function(fun); } } - if let Some(hidden_identifiers) = matches.values_of("blacklist-item") { + if let Some(hidden_identifiers) = matches.values_of("blocklist-item") { for id in hidden_identifiers { - builder = builder.blacklist_item(id); + builder = builder.blocklist_item(id); } } @@ -758,8 +765,8 @@ where builder = builder.generate_comments(false); } - if matches.is_present("no-recursive-whitelist") { - builder = builder.whitelist_recursively(false); + if matches.is_present("no-recursive-allowlist") { + builder = builder.allowlist_recursively(false); } if matches.is_present("objc-extern-crate") { @@ -809,21 +816,21 @@ where builder = builder.generate_inline_functions(true); } - if let Some(whitelist) = matches.values_of("whitelist-function") { - for regex in whitelist { - builder = builder.whitelist_function(regex); + if let Some(allowlist) = matches.values_of("allowlist-function") { + for regex in allowlist { + builder = builder.allowlist_function(regex); } } - if let Some(whitelist) = matches.values_of("whitelist-type") { - for regex in whitelist { - builder = builder.whitelist_type(regex); + if let Some(allowlist) = matches.values_of("allowlist-type") { + for regex in allowlist { + builder = builder.allowlist_type(regex); } } - if let Some(whitelist) = matches.values_of("whitelist-var") { - for regex in whitelist { - builder = builder.whitelist_var(regex); + if let Some(allowlist) = matches.values_of("allowlist-var") { + for regex in allowlist { + builder = builder.allowlist_var(regex); } } diff --git a/tests/expectations/tests/whitelist-namespaces-basic.rs b/tests/expectations/tests/allowlist-namespaces-basic.rs similarity index 100% rename from tests/expectations/tests/whitelist-namespaces-basic.rs rename to tests/expectations/tests/allowlist-namespaces-basic.rs diff --git a/tests/expectations/tests/whitelist-namespaces.rs b/tests/expectations/tests/allowlist-namespaces.rs similarity index 100% rename from tests/expectations/tests/whitelist-namespaces.rs rename to tests/expectations/tests/allowlist-namespaces.rs diff --git a/tests/expectations/tests/whitelist_basic.rs b/tests/expectations/tests/allowlist_basic.rs similarity index 75% rename from tests/expectations/tests/whitelist_basic.rs rename to tests/expectations/tests/allowlist_basic.rs index 7806923c71..4e72e8b6dd 100644 --- a/tests/expectations/tests/whitelist_basic.rs +++ b/tests/expectations/tests/allowlist_basic.rs @@ -7,23 +7,23 @@ #[repr(C)] #[derive(Debug, Copy, Clone)] -pub struct WhitelistMe { +pub struct AllowlistMe { pub foo: ::std::os::raw::c_int, - pub bar: WhitelistMe_Inner, + pub bar: AllowlistMe_Inner, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } #[repr(C)] #[derive(Debug, Copy, Clone)] -pub struct WhitelistMe_Inner { +pub struct AllowlistMe_Inner { pub bar: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } -impl Default for WhitelistMe_Inner { +impl Default for AllowlistMe_Inner { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } -impl Default for WhitelistMe { +impl Default for AllowlistMe { fn default() -> Self { unsafe { ::std::mem::zeroed() } } diff --git a/tests/expectations/tests/whitelist_fix.rs b/tests/expectations/tests/allowlist_fix.rs similarity index 100% rename from tests/expectations/tests/whitelist_fix.rs rename to tests/expectations/tests/allowlist_fix.rs diff --git a/tests/expectations/tests/whitelist_vars.rs b/tests/expectations/tests/allowlist_vars.rs similarity index 100% rename from tests/expectations/tests/whitelist_vars.rs rename to tests/expectations/tests/allowlist_vars.rs diff --git a/tests/expectations/tests/whitelisted-item-references-no-hash.rs b/tests/expectations/tests/allowlisted-item-references-no-hash.rs similarity index 69% rename from tests/expectations/tests/whitelisted-item-references-no-hash.rs rename to tests/expectations/tests/allowlisted-item-references-no-hash.rs index e1217bc505..bc3fde1ded 100644 --- a/tests/expectations/tests/whitelisted-item-references-no-hash.rs +++ b/tests/expectations/tests/allowlisted-item-references-no-hash.rs @@ -25,29 +25,29 @@ fn bindgen_test_layout_NoHash() { } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] -pub struct WhitelistMe { +pub struct AllowlistMe { pub a: NoHash, } #[test] -fn bindgen_test_layout_WhitelistMe() { +fn bindgen_test_layout_AllowlistMe() { assert_eq!( - ::std::mem::size_of::(), + ::std::mem::size_of::(), 1usize, - concat!("Size of: ", stringify!(WhitelistMe)) + concat!("Size of: ", stringify!(AllowlistMe)) ); assert_eq!( - ::std::mem::align_of::(), + ::std::mem::align_of::(), 1usize, - concat!("Alignment of ", stringify!(WhitelistMe)) + concat!("Alignment of ", stringify!(AllowlistMe)) ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + &(*(::std::ptr::null::())).a as *const _ as usize }, 0usize, concat!( "Offset of field: ", - stringify!(WhitelistMe), + stringify!(AllowlistMe), "::", stringify!(a) ) diff --git a/tests/expectations/tests/whitelisted-item-references-no-partialeq.rs b/tests/expectations/tests/allowlisted-item-references-no-partialeq.rs similarity index 70% rename from tests/expectations/tests/whitelisted-item-references-no-partialeq.rs rename to tests/expectations/tests/allowlisted-item-references-no-partialeq.rs index 2aabc1018b..f26f692391 100644 --- a/tests/expectations/tests/whitelisted-item-references-no-partialeq.rs +++ b/tests/expectations/tests/allowlisted-item-references-no-partialeq.rs @@ -25,29 +25,29 @@ fn bindgen_test_layout_NoPartialEq() { } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] -pub struct WhitelistMe { +pub struct AllowlistMe { pub a: NoPartialEq, } #[test] -fn bindgen_test_layout_WhitelistMe() { +fn bindgen_test_layout_AllowlistMe() { assert_eq!( - ::std::mem::size_of::(), + ::std::mem::size_of::(), 1usize, - concat!("Size of: ", stringify!(WhitelistMe)) + concat!("Size of: ", stringify!(AllowlistMe)) ); assert_eq!( - ::std::mem::align_of::(), + ::std::mem::align_of::(), 1usize, - concat!("Alignment of ", stringify!(WhitelistMe)) + concat!("Alignment of ", stringify!(AllowlistMe)) ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + &(*(::std::ptr::null::())).a as *const _ as usize }, 0usize, concat!( "Offset of field: ", - stringify!(WhitelistMe), + stringify!(AllowlistMe), "::", stringify!(a) ) diff --git a/tests/expectations/tests/whitelisted_item_references_no_copy.rs b/tests/expectations/tests/allowlisted_item_references_no_copy.rs similarity index 68% rename from tests/expectations/tests/whitelisted_item_references_no_copy.rs rename to tests/expectations/tests/allowlisted_item_references_no_copy.rs index d13ede59e6..a5cb17b238 100644 --- a/tests/expectations/tests/whitelisted_item_references_no_copy.rs +++ b/tests/expectations/tests/allowlisted_item_references_no_copy.rs @@ -25,29 +25,29 @@ fn bindgen_test_layout_NoCopy() { } #[repr(C)] #[derive(Debug, Default)] -pub struct WhitelistMe { +pub struct AllowlistMe { pub a: NoCopy, } #[test] -fn bindgen_test_layout_WhitelistMe() { +fn bindgen_test_layout_AllowlistMe() { assert_eq!( - ::std::mem::size_of::(), + ::std::mem::size_of::(), 1usize, - concat!("Size of: ", stringify!(WhitelistMe)) + concat!("Size of: ", stringify!(AllowlistMe)) ); assert_eq!( - ::std::mem::align_of::(), + ::std::mem::align_of::(), 1usize, - concat!("Alignment of ", stringify!(WhitelistMe)) + concat!("Alignment of ", stringify!(AllowlistMe)) ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + &(*(::std::ptr::null::())).a as *const _ as usize }, 0usize, concat!( "Offset of field: ", - stringify!(WhitelistMe), + stringify!(AllowlistMe), "::", stringify!(a) ) diff --git a/tests/expectations/tests/anon_enum_whitelist.rs b/tests/expectations/tests/anon_enum_allowlist.rs similarity index 100% rename from tests/expectations/tests/anon_enum_whitelist.rs rename to tests/expectations/tests/anon_enum_allowlist.rs diff --git a/tests/expectations/tests/blacklist-and-impl-debug.rs b/tests/expectations/tests/blocklist-and-impl-debug.rs similarity index 91% rename from tests/expectations/tests/blacklist-and-impl-debug.rs rename to tests/expectations/tests/blocklist-and-impl-debug.rs index 2609b2e864..f272f9beac 100644 --- a/tests/expectations/tests/blacklist-and-impl-debug.rs +++ b/tests/expectations/tests/blocklist-and-impl-debug.rs @@ -5,12 +5,12 @@ non_upper_case_globals )] -pub struct BlacklistMe(u8); +pub struct BlocklistMe(u8); -/// Because this type contains a blacklisted type, it should not derive Debug. +/// Because this type contains a blocklisted type, it should not derive Debug. #[repr(C)] pub struct ShouldManuallyImplDebug { - pub a: BlacklistMe, + pub a: BlocklistMe, } #[test] fn bindgen_test_layout_ShouldManuallyImplDebug() { diff --git a/tests/expectations/tests/blacklist-function.rs b/tests/expectations/tests/blocklist-function.rs similarity index 100% rename from tests/expectations/tests/blacklist-function.rs rename to tests/expectations/tests/blocklist-function.rs diff --git a/tests/expectations/tests/blacklist-item.rs b/tests/expectations/tests/blocklist-item.rs similarity index 100% rename from tests/expectations/tests/blacklist-item.rs rename to tests/expectations/tests/blocklist-item.rs diff --git a/tests/expectations/tests/derive-default-and-blacklist.rs b/tests/expectations/tests/derive-default-and-blocklist.rs similarity index 90% rename from tests/expectations/tests/derive-default-and-blacklist.rs rename to tests/expectations/tests/derive-default-and-blocklist.rs index ce0f252890..fca9c7f3cb 100644 --- a/tests/expectations/tests/derive-default-and-blacklist.rs +++ b/tests/expectations/tests/derive-default-and-blocklist.rs @@ -5,13 +5,13 @@ non_upper_case_globals )] -pub struct BlacklistMe(u8); +pub struct BlocklistMe(u8); -/// Because this type contains a blacklisted type, it should not derive +/// Because this type contains a blocklisted type, it should not derive /// Default. Instead, we should emit a `mem::zeroed` implementation. #[repr(C)] pub struct ShouldNotDeriveDefault { - pub a: BlacklistMe, + pub a: BlocklistMe, } #[test] fn bindgen_test_layout_ShouldNotDeriveDefault() { diff --git a/tests/expectations/tests/derive-hash-and-blacklist.rs b/tests/expectations/tests/derive-hash-and-blocklist.rs similarity index 89% rename from tests/expectations/tests/derive-hash-and-blacklist.rs rename to tests/expectations/tests/derive-hash-and-blocklist.rs index 458081a457..ba606a25fe 100644 --- a/tests/expectations/tests/derive-hash-and-blacklist.rs +++ b/tests/expectations/tests/derive-hash-and-blocklist.rs @@ -5,12 +5,12 @@ non_upper_case_globals )] -pub struct BlacklistMe(u8); +pub struct BlocklistMe(u8); -/// Because this type contains a blacklisted type, it should not derive Hash. +/// Because this type contains a blocklisted type, it should not derive Hash. #[repr(C)] pub struct ShouldNotDeriveHash { - pub a: BlacklistMe, + pub a: BlocklistMe, } #[test] fn bindgen_test_layout_ShouldNotDeriveHash() { diff --git a/tests/expectations/tests/derive-hash-blacklisting.rs b/tests/expectations/tests/derive-hash-blocklisting.rs similarity index 52% rename from tests/expectations/tests/derive-hash-blacklisting.rs rename to tests/expectations/tests/derive-hash-blocklisting.rs index 0424077b83..f9dbc824cf 100644 --- a/tests/expectations/tests/derive-hash-blacklisting.rs +++ b/tests/expectations/tests/derive-hash-blocklisting.rs @@ -7,78 +7,78 @@ #[repr(C)] #[derive(Debug, Hash, Copy, Clone, PartialEq, Eq)] -pub struct Blacklisted { +pub struct Blocklisted { t: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } -/// This would derive(Hash, Eq, PartialEq) if it didn't contain a blacklisted type, +/// This would derive(Hash, Eq, PartialEq) if it didn't contain a blocklisted type, /// causing us to conservatively avoid deriving hash/Eq/PartialEq for it. #[repr(C)] -pub struct WhitelistedOne { - pub a: Blacklisted<::std::os::raw::c_int>, +pub struct AllowlistedOne { + pub a: Blocklisted<::std::os::raw::c_int>, } #[test] -fn bindgen_test_layout_WhitelistedOne() { +fn bindgen_test_layout_AllowlistedOne() { assert_eq!( - ::std::mem::size_of::(), + ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(WhitelistedOne)) + concat!("Size of: ", stringify!(AllowlistedOne)) ); assert_eq!( - ::std::mem::align_of::(), + ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(WhitelistedOne)) + concat!("Alignment of ", stringify!(AllowlistedOne)) ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + &(*(::std::ptr::null::())).a as *const _ as usize }, 0usize, concat!( "Offset of field: ", - stringify!(WhitelistedOne), + stringify!(AllowlistedOne), "::", stringify!(a) ) ); } -impl Default for WhitelistedOne { +impl Default for AllowlistedOne { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } -/// This can't derive(Hash/Eq) even if it didn't contain a blacklisted type. +/// This can't derive(Hash/Eq) even if it didn't contain a blocklisted type. #[repr(C)] -pub struct WhitelistedTwo { - pub b: Blacklisted, +pub struct AllowlistedTwo { + pub b: Blocklisted, } #[test] -fn bindgen_test_layout_WhitelistedTwo() { +fn bindgen_test_layout_AllowlistedTwo() { assert_eq!( - ::std::mem::size_of::(), + ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(WhitelistedTwo)) + concat!("Size of: ", stringify!(AllowlistedTwo)) ); assert_eq!( - ::std::mem::align_of::(), + ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(WhitelistedTwo)) + concat!("Alignment of ", stringify!(AllowlistedTwo)) ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize + &(*(::std::ptr::null::())).b as *const _ as usize }, 0usize, concat!( "Offset of field: ", - stringify!(WhitelistedTwo), + stringify!(AllowlistedTwo), "::", stringify!(b) ) ); } -impl Default for WhitelistedTwo { +impl Default for AllowlistedTwo { fn default() -> Self { unsafe { ::std::mem::zeroed() } } diff --git a/tests/expectations/tests/derive-partialeq-and-blacklist.rs b/tests/expectations/tests/derive-partialeq-and-blocklist.rs similarity index 89% rename from tests/expectations/tests/derive-partialeq-and-blacklist.rs rename to tests/expectations/tests/derive-partialeq-and-blocklist.rs index 88bccdff21..b211933d7c 100644 --- a/tests/expectations/tests/derive-partialeq-and-blacklist.rs +++ b/tests/expectations/tests/derive-partialeq-and-blocklist.rs @@ -5,13 +5,13 @@ non_upper_case_globals )] -pub struct BlacklistMe(u8); +pub struct BlocklistMe(u8); -/// Because this type contains a blacklisted type, it should not derive +/// Because this type contains a blocklisted type, it should not derive /// PartialEq. #[repr(C)] pub struct ShouldNotDerivePartialEq { - pub a: BlacklistMe, + pub a: BlocklistMe, } #[test] fn bindgen_test_layout_ShouldNotDerivePartialEq() { diff --git a/tests/expectations/tests/dynamic_loading_with_whitelist.rs b/tests/expectations/tests/dynamic_loading_with_allowlist.rs similarity index 100% rename from tests/expectations/tests/dynamic_loading_with_whitelist.rs rename to tests/expectations/tests/dynamic_loading_with_allowlist.rs diff --git a/tests/expectations/tests/dynamic_loading_with_blacklist.rs b/tests/expectations/tests/dynamic_loading_with_blocklist.rs similarity index 100% rename from tests/expectations/tests/dynamic_loading_with_blacklist.rs rename to tests/expectations/tests/dynamic_loading_with_blocklist.rs diff --git a/tests/expectations/tests/inline_namespace_whitelist.rs b/tests/expectations/tests/inline_namespace_allowlist.rs similarity index 100% rename from tests/expectations/tests/inline_namespace_whitelist.rs rename to tests/expectations/tests/inline_namespace_allowlist.rs diff --git a/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs b/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs index bad51ff43b..7fd9caa309 100644 --- a/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs +++ b/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs @@ -104,30 +104,30 @@ extern "C" { } #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] -pub struct Whitelisted { +pub struct Allowlisted { pub some_member: Opaque, } #[test] -fn bindgen_test_layout_Whitelisted() { +fn bindgen_test_layout_Allowlisted() { assert_eq!( - ::std::mem::size_of::(), + ::std::mem::size_of::(), 1usize, - concat!("Size of: ", stringify!(Whitelisted)) + concat!("Size of: ", stringify!(Allowlisted)) ); assert_eq!( - ::std::mem::align_of::(), + ::std::mem::align_of::(), 1usize, - concat!("Alignment of ", stringify!(Whitelisted)) + concat!("Alignment of ", stringify!(Allowlisted)) ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).some_member as *const _ + &(*(::std::ptr::null::())).some_member as *const _ as usize }, 0usize, concat!( "Offset of field: ", - stringify!(Whitelisted), + stringify!(Allowlisted), "::", stringify!(some_member) ) diff --git a/tests/expectations/tests/issue-944-derive-copy-and-blacklisting.rs b/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs similarity index 88% rename from tests/expectations/tests/issue-944-derive-copy-and-blacklisting.rs rename to tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs index bcb5550fe8..51e97964d3 100644 --- a/tests/expectations/tests/issue-944-derive-copy-and-blacklisting.rs +++ b/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs @@ -5,12 +5,12 @@ non_upper_case_globals )] -pub struct BlacklistMe(u8); +pub struct BlocklistMe(u8); -/// Because this type contains a blacklisted type, it should not derive Copy. +/// Because this type contains a blocklisted type, it should not derive Copy. #[repr(C)] pub struct ShouldNotBeCopy { - pub a: BlacklistMe, + pub a: BlocklistMe, } #[test] fn bindgen_test_layout_ShouldNotBeCopy() { diff --git a/tests/expectations/tests/module-whitelisted.rs b/tests/expectations/tests/module-allowlisted.rs similarity index 100% rename from tests/expectations/tests/module-whitelisted.rs rename to tests/expectations/tests/module-allowlisted.rs diff --git a/tests/expectations/tests/no-derive-debug.rs b/tests/expectations/tests/no-derive-debug.rs index 0ddc5e2355..d58093ec02 100644 --- a/tests/expectations/tests/no-derive-debug.rs +++ b/tests/expectations/tests/no-derive-debug.rs @@ -11,7 +11,7 @@ pub struct foo { bar: ::std::os::raw::c_int, } -/// bar should compile. It will normally derive debug, but our blacklist of foo +/// bar should compile. It will normally derive debug, but our blocklist of foo /// and replacement for another type that doesn't implement it would prevent it /// from building if --no-derive-debug didn't work. #[repr(C)] diff --git a/tests/expectations/tests/no-derive-default.rs b/tests/expectations/tests/no-derive-default.rs index 995b1320e3..eda13aad68 100644 --- a/tests/expectations/tests/no-derive-default.rs +++ b/tests/expectations/tests/no-derive-default.rs @@ -11,7 +11,7 @@ pub struct foo { bar: ::std::os::raw::c_int, } -/// bar should compile. It will normally derive default, but our blacklist of foo +/// bar should compile. It will normally derive default, but our blocklist of foo /// and replacement for another type that doesn't implement it would prevent it /// from building if --no-derive-default didn't work. #[repr(C)] diff --git a/tests/expectations/tests/no-hash-whitelisted.rs b/tests/expectations/tests/no-hash-allowlisted.rs similarity index 100% rename from tests/expectations/tests/no-hash-whitelisted.rs rename to tests/expectations/tests/no-hash-allowlisted.rs diff --git a/tests/expectations/tests/no-partialeq-whitelisted.rs b/tests/expectations/tests/no-partialeq-allowlisted.rs similarity index 100% rename from tests/expectations/tests/no-partialeq-whitelisted.rs rename to tests/expectations/tests/no-partialeq-allowlisted.rs diff --git a/tests/expectations/tests/no-recursive-whitelisting.rs b/tests/expectations/tests/no-recursive-allowlisting.rs similarity index 100% rename from tests/expectations/tests/no-recursive-whitelisting.rs rename to tests/expectations/tests/no-recursive-allowlisting.rs diff --git a/tests/expectations/tests/no_copy_whitelisted.rs b/tests/expectations/tests/no_copy_allowlisted.rs similarity index 100% rename from tests/expectations/tests/no_copy_whitelisted.rs rename to tests/expectations/tests/no_copy_allowlisted.rs diff --git a/tests/expectations/tests/no_debug_whitelisted.rs b/tests/expectations/tests/no_debug_allowlisted.rs similarity index 100% rename from tests/expectations/tests/no_debug_whitelisted.rs rename to tests/expectations/tests/no_debug_allowlisted.rs diff --git a/tests/expectations/tests/no_default_whitelisted.rs b/tests/expectations/tests/no_default_allowlisted.rs similarity index 100% rename from tests/expectations/tests/no_default_whitelisted.rs rename to tests/expectations/tests/no_default_allowlisted.rs diff --git a/tests/expectations/tests/objc_whitelist.rs b/tests/expectations/tests/objc_allowlist.rs similarity index 66% rename from tests/expectations/tests/objc_whitelist.rs rename to tests/expectations/tests/objc_allowlist.rs index 213f1024ba..dcec0fd12e 100644 --- a/tests/expectations/tests/objc_whitelist.rs +++ b/tests/expectations/tests/objc_allowlist.rs @@ -10,5 +10,5 @@ extern crate objc; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; -impl WhitelistMe_InterestingCategory for WhitelistMe {} -pub trait WhitelistMe_InterestingCategory: Sized + std::ops::Deref {} +impl AllowlistMe_InterestingCategory for AllowlistMe {} +pub trait AllowlistMe_InterestingCategory: Sized + std::ops::Deref {} diff --git a/tests/expectations/tests/type-referenced-by-whitelisted-function.rs b/tests/expectations/tests/type-referenced-by-allowlisted-function.rs similarity index 100% rename from tests/expectations/tests/type-referenced-by-whitelisted-function.rs rename to tests/expectations/tests/type-referenced-by-allowlisted-function.rs diff --git a/tests/headers/whitelist-namespaces-basic.hpp b/tests/headers/allowlist-namespaces-basic.hpp similarity index 67% rename from tests/headers/whitelist-namespaces-basic.hpp rename to tests/headers/allowlist-namespaces-basic.hpp index 2eaa87403e..fb4dd1be37 100644 --- a/tests/headers/whitelist-namespaces-basic.hpp +++ b/tests/headers/allowlist-namespaces-basic.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --enable-cxx-namespaces --whitelist-type outer::inner::Helper +// bindgen-flags: --enable-cxx-namespaces --allowlist-type outer::inner::Helper namespace outer { namespace inner { diff --git a/tests/headers/whitelist-namespaces.hpp b/tests/headers/allowlist-namespaces.hpp similarity index 64% rename from tests/headers/whitelist-namespaces.hpp rename to tests/headers/allowlist-namespaces.hpp index d34cbe9430..2cffe9d3dd 100644 --- a/tests/headers/whitelist-namespaces.hpp +++ b/tests/headers/allowlist-namespaces.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --enable-cxx-namespaces --whitelist-type '.*' +// bindgen-flags: --enable-cxx-namespaces --allowlist-type '.*' namespace outer { namespace inner { diff --git a/tests/headers/whitelist_basic.hpp b/tests/headers/allowlist_basic.hpp similarity index 59% rename from tests/headers/whitelist_basic.hpp rename to tests/headers/allowlist_basic.hpp index 8424f75a8e..ef858c95da 100644 --- a/tests/headers/whitelist_basic.hpp +++ b/tests/headers/allowlist_basic.hpp @@ -1,7 +1,7 @@ -// bindgen-flags: --whitelist-type WhitelistMe +// bindgen-flags: --allowlist-type AllowlistMe template -class WhitelistMe { +class AllowlistMe { class Inner { T bar; }; @@ -10,7 +10,7 @@ class WhitelistMe { Inner bar; }; -struct DontWhitelistMe { +struct DontAllowlistMe { void* foo; double _Complex noComplexGenerated; }; diff --git a/tests/headers/whitelist_fix.hpp b/tests/headers/allowlist_fix.hpp similarity index 58% rename from tests/headers/whitelist_fix.hpp rename to tests/headers/allowlist_fix.hpp index d0abda540d..ff810fc6e0 100644 --- a/tests/headers/whitelist_fix.hpp +++ b/tests/headers/allowlist_fix.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --whitelist-function 'Servo_.*' --blacklist-type Test --raw-line "pub enum Test {}" +// bindgen-flags: --allowlist-function 'Servo_.*' --blocklist-type Test --raw-line "pub enum Test {}" struct Test {}; extern "C" void Servo_Test(Test* a); diff --git a/tests/headers/whitelist_vars.h b/tests/headers/allowlist_vars.h similarity index 100% rename from tests/headers/whitelist_vars.h rename to tests/headers/allowlist_vars.h diff --git a/tests/headers/allowlisted-item-references-no-hash.hpp b/tests/headers/allowlisted-item-references-no-hash.hpp new file mode 100644 index 0000000000..56c2a39fba --- /dev/null +++ b/tests/headers/allowlisted-item-references-no-hash.hpp @@ -0,0 +1,7 @@ +// bindgen-flags: --with-derive-hash --allowlist-type "AllowlistMe" --no-hash "NoHash" + +struct NoHash {}; + +class AllowlistMe { + NoHash a; +}; diff --git a/tests/headers/allowlisted-item-references-no-partialeq.hpp b/tests/headers/allowlisted-item-references-no-partialeq.hpp new file mode 100644 index 0000000000..d85fb6b754 --- /dev/null +++ b/tests/headers/allowlisted-item-references-no-partialeq.hpp @@ -0,0 +1,7 @@ +// bindgen-flags: --with-derive-partialeq --allowlist-type "AllowlistMe" --no-partialeq "NoPartialEq" + +struct NoPartialEq {}; + +class AllowlistMe { + NoPartialEq a; +}; diff --git a/tests/headers/allowlisted_item_references_no_copy.hpp b/tests/headers/allowlisted_item_references_no_copy.hpp new file mode 100644 index 0000000000..9feb30549a --- /dev/null +++ b/tests/headers/allowlisted_item_references_no_copy.hpp @@ -0,0 +1,7 @@ +// bindgen-flags: --allowlist-type "AllowlistMe" --no-copy "NoCopy" + +struct NoCopy {}; + +class AllowlistMe { + NoCopy a; +}; diff --git a/tests/headers/anon_enum_allowlist.h b/tests/headers/anon_enum_allowlist.h new file mode 100644 index 0000000000..94119a8773 --- /dev/null +++ b/tests/headers/anon_enum_allowlist.h @@ -0,0 +1,6 @@ +// bindgen-flags: --allowlist-var "NODE_.*" --rustified-enum ".*" + +enum { + NODE_FLAG_FOO, + NODE_FLAG_BAR, +}; diff --git a/tests/headers/anon_enum_whitelist.h b/tests/headers/anon_enum_whitelist.h deleted file mode 100644 index a35e4886c3..0000000000 --- a/tests/headers/anon_enum_whitelist.h +++ /dev/null @@ -1,6 +0,0 @@ -// bindgen-flags: --whitelist-var "NODE_.*" --rustified-enum ".*" - -enum { - NODE_FLAG_FOO, - NODE_FLAG_BAR, -}; diff --git a/tests/headers/blacklist-and-impl-debug.hpp b/tests/headers/blacklist-and-impl-debug.hpp deleted file mode 100644 index b4b39fe40d..0000000000 --- a/tests/headers/blacklist-and-impl-debug.hpp +++ /dev/null @@ -1,10 +0,0 @@ -// bindgen-flags: --impl-debug --blacklist-type BlacklistMe --raw-line 'pub struct BlacklistMe(u8);' - -struct BlacklistMe {}; - -/** - * Because this type contains a blacklisted type, it should not derive Debug. - */ -struct ShouldManuallyImplDebug { - BlacklistMe a; -}; diff --git a/tests/headers/blocklist-and-impl-debug.hpp b/tests/headers/blocklist-and-impl-debug.hpp new file mode 100644 index 0000000000..14e17537e1 --- /dev/null +++ b/tests/headers/blocklist-and-impl-debug.hpp @@ -0,0 +1,10 @@ +// bindgen-flags: --impl-debug --blocklist-type BlocklistMe --raw-line 'pub struct BlocklistMe(u8);' + +struct BlocklistMe {}; + +/** + * Because this type contains a blocklisted type, it should not derive Debug. + */ +struct ShouldManuallyImplDebug { + BlocklistMe a; +}; diff --git a/tests/headers/blacklist-function.hpp b/tests/headers/blocklist-function.hpp similarity index 62% rename from tests/headers/blacklist-function.hpp rename to tests/headers/blocklist-function.hpp index 8087295cc1..d7c8bb35d7 100644 --- a/tests/headers/blacklist-function.hpp +++ b/tests/headers/blocklist-function.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --blacklist-function "ExternFunction" --blacklist-function "foo::NamespacedFunction" --blacklist-function "C_ClassMethod" --enable-cxx-namespaces +// bindgen-flags: --blocklist-function "ExternFunction" --blocklist-function "foo::NamespacedFunction" --blocklist-function "C_ClassMethod" --enable-cxx-namespaces extern "C" void ExternFunction(); diff --git a/tests/headers/blacklist-item.hpp b/tests/headers/blocklist-item.hpp similarity index 63% rename from tests/headers/blacklist-item.hpp rename to tests/headers/blocklist-item.hpp index 8d569dde98..2d795d5a5a 100644 --- a/tests/headers/blacklist-item.hpp +++ b/tests/headers/blocklist-item.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --blacklist-item "SomeFunction" --blacklist-item "SOME_DEFUN" --blacklist-item "someVar" --blacklist-item "ExternFunction" --blacklist-item "foo::NamespacedFunction" --blacklist-item "someClass.*" --enable-cxx-namespaces +// bindgen-flags: --blocklist-item "SomeFunction" --blocklist-item "SOME_DEFUN" --blocklist-item "someVar" --blocklist-item "ExternFunction" --blocklist-item "foo::NamespacedFunction" --blocklist-item "someClass.*" --enable-cxx-namespaces void SomeFunction(); extern int someVar; diff --git a/tests/headers/derive-default-and-blacklist.hpp b/tests/headers/derive-default-and-blocklist.hpp similarity index 56% rename from tests/headers/derive-default-and-blacklist.hpp rename to tests/headers/derive-default-and-blocklist.hpp index 7a2b7505d5..20d938ccf2 100644 --- a/tests/headers/derive-default-and-blacklist.hpp +++ b/tests/headers/derive-default-and-blocklist.hpp @@ -1,14 +1,14 @@ -// bindgen-flags: --blacklist-type BlacklistMe --raw-line 'pub struct BlacklistMe(u8);' +// bindgen-flags: --blocklist-type BlocklistMe --raw-line 'pub struct BlocklistMe(u8);' // Note that we do not explicitly provide the `--with-derive-default` flag // above, since it is added by the test runner implicitly. -struct BlacklistMe {}; +struct BlocklistMe {}; /** - * Because this type contains a blacklisted type, it should not derive + * Because this type contains a blocklisted type, it should not derive * Default. Instead, we should emit a `mem::zeroed` implementation. */ struct ShouldNotDeriveDefault { - BlacklistMe a; + BlocklistMe a; }; diff --git a/tests/headers/derive-hash-and-blacklist.hpp b/tests/headers/derive-hash-and-blacklist.hpp deleted file mode 100644 index 4b3a4a535b..0000000000 --- a/tests/headers/derive-hash-and-blacklist.hpp +++ /dev/null @@ -1,10 +0,0 @@ -// bindgen-flags: --with-derive-hash --blacklist-type BlacklistMe --raw-line 'pub struct BlacklistMe(u8);' - -struct BlacklistMe {}; - -/** - * Because this type contains a blacklisted type, it should not derive Hash. - */ -struct ShouldNotDeriveHash { - BlacklistMe a; -}; diff --git a/tests/headers/derive-hash-and-blocklist.hpp b/tests/headers/derive-hash-and-blocklist.hpp new file mode 100644 index 0000000000..51a3372fcf --- /dev/null +++ b/tests/headers/derive-hash-and-blocklist.hpp @@ -0,0 +1,10 @@ +// bindgen-flags: --with-derive-hash --blocklist-type BlocklistMe --raw-line 'pub struct BlocklistMe(u8);' + +struct BlocklistMe {}; + +/** + * Because this type contains a blocklisted type, it should not derive Hash. + */ +struct ShouldNotDeriveHash { + BlocklistMe a; +}; diff --git a/tests/headers/derive-hash-blacklisting.hpp b/tests/headers/derive-hash-blacklisting.hpp deleted file mode 100644 index e3256a0118..0000000000 --- a/tests/headers/derive-hash-blacklisting.hpp +++ /dev/null @@ -1,17 +0,0 @@ -// bindgen-flags: --with-derive-hash --with-derive-partialord --with-derive-ord --with-derive-partialeq --with-derive-eq --whitelist-type 'Whitelisted.*' --blacklist-type Blacklisted --raw-line "#[repr(C)] #[derive(Debug, Hash, Copy, Clone, PartialEq, Eq)] pub struct Blacklisted {t: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell> }" -// -template -struct Blacklisted { - T t; -}; - -/// This would derive(Hash, Eq, PartialEq) if it didn't contain a blacklisted type, -/// causing us to conservatively avoid deriving hash/Eq/PartialEq for it. -struct WhitelistedOne { - Blacklisted a; -}; - -/// This can't derive(Hash/Eq) even if it didn't contain a blacklisted type. -struct WhitelistedTwo { - Blacklisted b; -}; diff --git a/tests/headers/derive-hash-blocklisting.hpp b/tests/headers/derive-hash-blocklisting.hpp new file mode 100644 index 0000000000..4e20e3925a --- /dev/null +++ b/tests/headers/derive-hash-blocklisting.hpp @@ -0,0 +1,17 @@ +// bindgen-flags: --with-derive-hash --with-derive-partialord --with-derive-ord --with-derive-partialeq --with-derive-eq --allowlist-type 'Allowlisted.*' --blocklist-type Blocklisted --raw-line "#[repr(C)] #[derive(Debug, Hash, Copy, Clone, PartialEq, Eq)] pub struct Blocklisted {t: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell> }" +// +template +struct Blocklisted { + T t; +}; + +/// This would derive(Hash, Eq, PartialEq) if it didn't contain a blocklisted type, +/// causing us to conservatively avoid deriving hash/Eq/PartialEq for it. +struct AllowlistedOne { + Blocklisted a; +}; + +/// This can't derive(Hash/Eq) even if it didn't contain a blocklisted type. +struct AllowlistedTwo { + Blocklisted b; +}; diff --git a/tests/headers/derive-partialeq-and-blacklist.hpp b/tests/headers/derive-partialeq-and-blacklist.hpp deleted file mode 100644 index a996eee873..0000000000 --- a/tests/headers/derive-partialeq-and-blacklist.hpp +++ /dev/null @@ -1,11 +0,0 @@ -// bindgen-flags: --with-derive-partialeq --blacklist-type BlacklistMe --raw-line 'pub struct BlacklistMe(u8);' - -struct BlacklistMe {}; - -/** - * Because this type contains a blacklisted type, it should not derive - * PartialEq. - */ -struct ShouldNotDerivePartialEq { - BlacklistMe a; -}; diff --git a/tests/headers/derive-partialeq-and-blocklist.hpp b/tests/headers/derive-partialeq-and-blocklist.hpp new file mode 100644 index 0000000000..953d067714 --- /dev/null +++ b/tests/headers/derive-partialeq-and-blocklist.hpp @@ -0,0 +1,11 @@ +// bindgen-flags: --with-derive-partialeq --blocklist-type BlocklistMe --raw-line 'pub struct BlocklistMe(u8);' + +struct BlocklistMe {}; + +/** + * Because this type contains a blocklisted type, it should not derive + * PartialEq. + */ +struct ShouldNotDerivePartialEq { + BlocklistMe a; +}; diff --git a/tests/headers/dynamic_loading_with_whitelist.hpp b/tests/headers/dynamic_loading_with_allowlist.hpp similarity index 59% rename from tests/headers/dynamic_loading_with_whitelist.hpp rename to tests/headers/dynamic_loading_with_allowlist.hpp index 33bfe805e2..995fbdd531 100644 --- a/tests/headers/dynamic_loading_with_whitelist.hpp +++ b/tests/headers/dynamic_loading_with_allowlist.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --dynamic-loading TestLib --whitelist-function baz --whitelist-function foo --whitelist-function bazz +// bindgen-flags: --dynamic-loading TestLib --allowlist-function baz --allowlist-function foo --allowlist-function bazz class X { int _x; diff --git a/tests/headers/dynamic_loading_with_blacklist.hpp b/tests/headers/dynamic_loading_with_blocklist.hpp similarity index 71% rename from tests/headers/dynamic_loading_with_blacklist.hpp rename to tests/headers/dynamic_loading_with_blocklist.hpp index 2988ba691e..81266d1f40 100644 --- a/tests/headers/dynamic_loading_with_blacklist.hpp +++ b/tests/headers/dynamic_loading_with_blocklist.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --dynamic-loading TestLib --blacklist-function baz +// bindgen-flags: --dynamic-loading TestLib --blocklist-function baz class X { int _x; diff --git a/tests/headers/inline_namespace_whitelist.hpp b/tests/headers/inline_namespace_allowlist.hpp similarity index 61% rename from tests/headers/inline_namespace_whitelist.hpp rename to tests/headers/inline_namespace_allowlist.hpp index 30047bbec1..90e46dfb84 100644 --- a/tests/headers/inline_namespace_whitelist.hpp +++ b/tests/headers/inline_namespace_allowlist.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --enable-cxx-namespaces --whitelist-type=std::string -- -std=c++11 +// bindgen-flags: --enable-cxx-namespaces --allowlist-type=std::string -- -std=c++11 namespace std { inline namespace bar { diff --git a/tests/headers/issue-1285.h b/tests/headers/issue-1285.h index 7fb742ecf7..a2817d84b4 100644 --- a/tests/headers/issue-1285.h +++ b/tests/headers/issue-1285.h @@ -1,4 +1,4 @@ -// bindgen-flags: --with-derive-hash --no-recursive-whitelist --whitelist-type "foo" +// bindgen-flags: --with-derive-hash --no-recursive-allowlist --allowlist-type "foo" struct foo { union { diff --git a/tests/headers/issue-410.hpp b/tests/headers/issue-410.hpp index b5d502f33e..d4f3de3d1c 100644 --- a/tests/headers/issue-410.hpp +++ b/tests/headers/issue-410.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --enable-cxx-namespaces --whitelist-type JS::Value --rustified-enum ".*" +// bindgen-flags: --enable-cxx-namespaces --allowlist-type JS::Value --rustified-enum ".*" namespace JS { class Value; diff --git a/tests/headers/issue-447.hpp b/tests/headers/issue-447.hpp index 017838c42f..43765fa9ee 100644 --- a/tests/headers/issue-447.hpp +++ b/tests/headers/issue-447.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --enable-cxx-namespaces --whitelist-type JSAutoCompartment -- -std=c++11 +// bindgen-flags: --enable-cxx-namespaces --allowlist-type JSAutoCompartment -- -std=c++11 namespace mozilla { template class a {}; diff --git a/tests/headers/issue-584-stylo-template-analysis-panic.hpp b/tests/headers/issue-584-stylo-template-analysis-panic.hpp index 3bf00e5da9..5f11ea3c9c 100644 --- a/tests/headers/issue-584-stylo-template-analysis-panic.hpp +++ b/tests/headers/issue-584-stylo-template-analysis-panic.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --blacklist-type RefPtr --whitelist-function 'Servo_.*' --raw-line 'pub type RefPtr = T;' -- -std=c++14 +// bindgen-flags: --blocklist-type RefPtr --allowlist-function 'Servo_.*' --raw-line 'pub type RefPtr = T;' -- -std=c++14 template class RefPtr; class b; class A { diff --git a/tests/headers/issue-645-cannot-find-type-T-in-this-scope.hpp b/tests/headers/issue-645-cannot-find-type-T-in-this-scope.hpp index f817f34dce..8e07a8a0fd 100644 --- a/tests/headers/issue-645-cannot-find-type-T-in-this-scope.hpp +++ b/tests/headers/issue-645-cannot-find-type-T-in-this-scope.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --blacklist-type RefPtr --raw-line "#[derive(Clone, Copy, Debug)] pub struct RefPtr(T);" --whitelist-type "HasRefPtr" -- -std=c++14 +// bindgen-flags: --blocklist-type RefPtr --raw-line "#[derive(Clone, Copy, Debug)] pub struct RefPtr(T);" --allowlist-type "HasRefPtr" -- -std=c++14 template class RefPtr {}; diff --git a/tests/headers/issue-662-part-2.hpp b/tests/headers/issue-662-part-2.hpp index 84edb39778..1330c34280 100644 --- a/tests/headers/issue-662-part-2.hpp +++ b/tests/headers/issue-662-part-2.hpp @@ -1,7 +1,7 @@ -// bindgen-flags: --blacklist-type RefPtr --raw-line '#[derive(Clone, Copy, Debug)] pub struct RefPtr(T);' -- --std=c++14 +// bindgen-flags: --blocklist-type RefPtr --raw-line '#[derive(Clone, Copy, Debug)] pub struct RefPtr(T);' -- --std=c++14 // This is pretty much the same as the other issue 662 test case, but this time -// we blacklist RefPtr to exercise the instantiation-of-a-blacklisted-template +// we blocklist RefPtr to exercise the instantiation-of-a-blocklisted-template // path in the template analysis. template class RefPtr {}; diff --git a/tests/headers/issue-674-1.hpp b/tests/headers/issue-674-1.hpp index aa3c6118db..7fc781c1da 100644 --- a/tests/headers/issue-674-1.hpp +++ b/tests/headers/issue-674-1.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --enable-cxx-namespaces --whitelist-type CapturingContentInfo --opaque-type 'mozilla::Maybe' -- -std=c++14 +// bindgen-flags: --enable-cxx-namespaces --allowlist-type CapturingContentInfo --opaque-type 'mozilla::Maybe' -- -std=c++14 namespace mozilla { template class Maybe { using ValueType = T; }; diff --git a/tests/headers/issue-674-2.hpp b/tests/headers/issue-674-2.hpp index 58abcae24e..86d2b6488d 100644 --- a/tests/headers/issue-674-2.hpp +++ b/tests/headers/issue-674-2.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --enable-cxx-namespaces --whitelist-type StaticRefPtr --opaque-type 'JS::Rooted' -- -std=c++14 +// bindgen-flags: --enable-cxx-namespaces --allowlist-type StaticRefPtr --opaque-type 'JS::Rooted' -- -std=c++14 namespace JS { template class Rooted { using ElementType = T; }; diff --git a/tests/headers/issue-674-3.hpp b/tests/headers/issue-674-3.hpp index 2794c19299..20aa463c9e 100644 --- a/tests/headers/issue-674-3.hpp +++ b/tests/headers/issue-674-3.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --enable-cxx-namespaces --whitelist-type nsCSSValue --opaque-type 'nsRefPtrHashtable' -- -std=c++14 +// bindgen-flags: --enable-cxx-namespaces --allowlist-type nsCSSValue --opaque-type 'nsRefPtrHashtable' -- -std=c++14 template class nsRefPtrHashtable { typedef PtrType *UserDataType; diff --git a/tests/headers/issue-769-bad-instantiation-test.hpp b/tests/headers/issue-769-bad-instantiation-test.hpp index 1be89a6628..13c6dd1ce6 100644 --- a/tests/headers/issue-769-bad-instantiation-test.hpp +++ b/tests/headers/issue-769-bad-instantiation-test.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --enable-cxx-namespaces --whitelist-type Rooted +// bindgen-flags: --enable-cxx-namespaces --allowlist-type Rooted template class Rooted { diff --git a/tests/headers/issue-801-opaque-sloppiness.hpp b/tests/headers/issue-801-opaque-sloppiness.hpp index 678586342e..6b707f4ede 100644 --- a/tests/headers/issue-801-opaque-sloppiness.hpp +++ b/tests/headers/issue-801-opaque-sloppiness.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --opaque-type "B" --whitelist-type "C" --with-derive-hash --with-derive-partialeq --with-derive-eq +// bindgen-flags: --opaque-type "B" --allowlist-type "C" --with-derive-hash --with-derive-partialeq --with-derive-eq class A; diff --git a/tests/headers/issue-807-opaque-types-methods-being-generated.hpp b/tests/headers/issue-807-opaque-types-methods-being-generated.hpp index 91f221ce23..de98b32a15 100644 --- a/tests/headers/issue-807-opaque-types-methods-being-generated.hpp +++ b/tests/headers/issue-807-opaque-types-methods-being-generated.hpp @@ -1,12 +1,12 @@ -// bindgen-flags: --whitelist-type Whitelisted --opaque-type Opaque --with-derive-hash --with-derive-partialeq --with-derive-eq -- -std=c++11 +// bindgen-flags: --allowlist-type Allowlisted --opaque-type Opaque --with-derive-hash --with-derive-partialeq --with-derive-eq -- -std=c++11 -// These types are not explicitly whitelisted, but are reachable through the +// These types are not explicitly allowlisted, but are reachable through the // opaque type. class Pupper {}; class Doggo {}; class SuchWow {}; -// These types are not whitelisted, and would be reachable through `Opaque` if +// These types are not allowlisted, and would be reachable through `Opaque` if // it were not marked opaque, but since it is, there should be no bindings // generated for them. class NoBindingsShouldBeGeneratedForMe1 {}; @@ -31,6 +31,6 @@ class Opaque SuchWow eleven_out_of_ten(); }; -class Whitelisted { +class Allowlisted { Opaque some_member; }; diff --git a/tests/headers/issue-833-1.hpp b/tests/headers/issue-833-1.hpp index 30bf85f2d0..d66ee01fa7 100644 --- a/tests/headers/issue-833-1.hpp +++ b/tests/headers/issue-833-1.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --generate functions --whitelist-function func --raw-line "#[repr(C)] pub struct nsTArray { pub hdr: *const () }" +// bindgen-flags: --generate functions --allowlist-function func --raw-line "#[repr(C)] pub struct nsTArray { pub hdr: *const () }" template class nsTArray { diff --git a/tests/headers/issue-833.hpp b/tests/headers/issue-833.hpp index ea0d2add71..f8b708bf16 100644 --- a/tests/headers/issue-833.hpp +++ b/tests/headers/issue-833.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --generate functions --whitelist-function func --raw-line "#[repr(C)] pub struct nsTArray { pub hdr: *const T }" +// bindgen-flags: --generate functions --allowlist-function func --raw-line "#[repr(C)] pub struct nsTArray { pub hdr: *const T }" template class nsTArray { diff --git a/tests/headers/issue-834.hpp b/tests/headers/issue-834.hpp index c06e89fdb4..6479701262 100644 --- a/tests/headers/issue-834.hpp +++ b/tests/headers/issue-834.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --whitelist-type U --generate types +// bindgen-flags: --allowlist-type U --generate types struct T {}; struct U { diff --git a/tests/headers/issue-944-derive-copy-and-blacklisting.hpp b/tests/headers/issue-944-derive-copy-and-blacklisting.hpp deleted file mode 100644 index 657e0d849f..0000000000 --- a/tests/headers/issue-944-derive-copy-and-blacklisting.hpp +++ /dev/null @@ -1,10 +0,0 @@ -// bindgen-flags: --blacklist-type BlacklistMe --raw-line 'pub struct BlacklistMe(u8);' - -struct BlacklistMe {}; - -/** - * Because this type contains a blacklisted type, it should not derive Copy. - */ -struct ShouldNotBeCopy { - BlacklistMe a; -}; diff --git a/tests/headers/issue-944-derive-copy-and-blocklisting.hpp b/tests/headers/issue-944-derive-copy-and-blocklisting.hpp new file mode 100644 index 0000000000..5e94dfabd4 --- /dev/null +++ b/tests/headers/issue-944-derive-copy-and-blocklisting.hpp @@ -0,0 +1,10 @@ +// bindgen-flags: --blocklist-type BlocklistMe --raw-line 'pub struct BlocklistMe(u8);' + +struct BlocklistMe {}; + +/** + * Because this type contains a blocklisted type, it should not derive Copy. + */ +struct ShouldNotBeCopy { + BlocklistMe a; +}; diff --git a/tests/headers/maddness-is-avoidable.hpp b/tests/headers/maddness-is-avoidable.hpp index 46d7495ead..47a7ffbfac 100644 --- a/tests/headers/maddness-is-avoidable.hpp +++ b/tests/headers/maddness-is-avoidable.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --blacklist-type RefPtr_Proxy_member_function +// bindgen-flags: --blocklist-type RefPtr_Proxy_member_function template class RefPtr { diff --git a/tests/headers/module-whitelisted.hpp b/tests/headers/module-allowlisted.hpp similarity index 100% rename from tests/headers/module-whitelisted.hpp rename to tests/headers/module-allowlisted.hpp diff --git a/tests/headers/no-derive-debug.h b/tests/headers/no-derive-debug.h index c780d2d8f8..d11ca0ad92 100644 --- a/tests/headers/no-derive-debug.h +++ b/tests/headers/no-derive-debug.h @@ -1,11 +1,11 @@ -// bindgen-flags: --no-derive-debug --blacklist-type foo --raw-line "#[repr(C)] #[derive(Copy, Clone, Default)] pub struct foo { bar: ::std::os::raw::c_int, }" +// bindgen-flags: --no-derive-debug --blocklist-type foo --raw-line "#[repr(C)] #[derive(Copy, Clone, Default)] pub struct foo { bar: ::std::os::raw::c_int, }" struct foo { int bar; }; /** - * bar should compile. It will normally derive debug, but our blacklist of foo + * bar should compile. It will normally derive debug, but our blocklist of foo * and replacement for another type that doesn't implement it would prevent it * from building if --no-derive-debug didn't work. */ diff --git a/tests/headers/no-derive-default.h b/tests/headers/no-derive-default.h index 207b93b62f..d184ee3a98 100644 --- a/tests/headers/no-derive-default.h +++ b/tests/headers/no-derive-default.h @@ -1,11 +1,11 @@ -// bindgen-flags: --no-derive-default --blacklist-type foo --raw-line "#[repr(C)] #[derive(Copy, Clone, Debug)] pub struct foo { bar: ::std::os::raw::c_int, }" +// bindgen-flags: --no-derive-default --blocklist-type foo --raw-line "#[repr(C)] #[derive(Copy, Clone, Debug)] pub struct foo { bar: ::std::os::raw::c_int, }" struct foo { int bar; }; /** - * bar should compile. It will normally derive default, but our blacklist of foo + * bar should compile. It will normally derive default, but our blocklist of foo * and replacement for another type that doesn't implement it would prevent it * from building if --no-derive-default didn't work. */ diff --git a/tests/headers/no-hash-allowlisted.hpp b/tests/headers/no-hash-allowlisted.hpp new file mode 100644 index 0000000000..0f60817da6 --- /dev/null +++ b/tests/headers/no-hash-allowlisted.hpp @@ -0,0 +1,5 @@ +// bindgen-flags: --with-derive-hash --allowlist-type "NoHash" --no-hash "NoHash" + +class NoHash { + int i; +}; diff --git a/tests/headers/no-hash-whitelisted.hpp b/tests/headers/no-hash-whitelisted.hpp deleted file mode 100644 index 77c9086438..0000000000 --- a/tests/headers/no-hash-whitelisted.hpp +++ /dev/null @@ -1,5 +0,0 @@ -// bindgen-flags: --with-derive-hash --whitelist-type "NoHash" --no-hash "NoHash" - -class NoHash { - int i; -}; diff --git a/tests/headers/no-partialeq-whitelisted.hpp b/tests/headers/no-partialeq-allowlisted.hpp similarity index 52% rename from tests/headers/no-partialeq-whitelisted.hpp rename to tests/headers/no-partialeq-allowlisted.hpp index dba4e91f76..ced1b42a7b 100644 --- a/tests/headers/no-partialeq-whitelisted.hpp +++ b/tests/headers/no-partialeq-allowlisted.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --with-derive-partialeq --whitelist-type "NoPartialEq" --no-partialeq "NoPartialEq" +// bindgen-flags: --with-derive-partialeq --allowlist-type "NoPartialEq" --no-partialeq "NoPartialEq" class NoPartialEq { int i; diff --git a/tests/headers/no-recursive-whitelisting.h b/tests/headers/no-recursive-allowlisting.h similarity index 61% rename from tests/headers/no-recursive-whitelisting.h rename to tests/headers/no-recursive-allowlisting.h index c94cc491eb..1c6617110b 100644 --- a/tests/headers/no-recursive-whitelisting.h +++ b/tests/headers/no-recursive-allowlisting.h @@ -1,4 +1,4 @@ -// bindgen-flags: --no-recursive-whitelist --whitelist-type "Foo" --raw-line "pub enum Bar {}" --rustified-enum ".*" +// bindgen-flags: --no-recursive-allowlist --allowlist-type "Foo" --raw-line "pub enum Bar {}" --rustified-enum ".*" struct Bar; diff --git a/tests/headers/no_copy_allowlisted.hpp b/tests/headers/no_copy_allowlisted.hpp new file mode 100644 index 0000000000..f3b922cae1 --- /dev/null +++ b/tests/headers/no_copy_allowlisted.hpp @@ -0,0 +1,5 @@ +// bindgen-flags: --allowlist-type "NoCopy" --no-copy "NoCopy" + +class NoCopy { + int i; +}; diff --git a/tests/headers/no_copy_whitelisted.hpp b/tests/headers/no_copy_whitelisted.hpp deleted file mode 100644 index db44a8a7eb..0000000000 --- a/tests/headers/no_copy_whitelisted.hpp +++ /dev/null @@ -1,5 +0,0 @@ -// bindgen-flags: --whitelist-type "NoCopy" --no-copy "NoCopy" - -class NoCopy { - int i; -}; diff --git a/tests/headers/no_debug_allowlisted.hpp b/tests/headers/no_debug_allowlisted.hpp new file mode 100644 index 0000000000..3e3633e475 --- /dev/null +++ b/tests/headers/no_debug_allowlisted.hpp @@ -0,0 +1,5 @@ +// bindgen-flags: --allowlist-type "NoDebug" --no-debug "NoDebug" + +class NoDebug { + int i; +}; diff --git a/tests/headers/no_debug_whitelisted.hpp b/tests/headers/no_debug_whitelisted.hpp deleted file mode 100644 index 7a855e8115..0000000000 --- a/tests/headers/no_debug_whitelisted.hpp +++ /dev/null @@ -1,5 +0,0 @@ -// bindgen-flags: --whitelist-type "NoDebug" --no-debug "NoDebug" - -class NoDebug { - int i; -}; diff --git a/tests/headers/no_default_allowlisted.hpp b/tests/headers/no_default_allowlisted.hpp new file mode 100644 index 0000000000..8a604081f7 --- /dev/null +++ b/tests/headers/no_default_allowlisted.hpp @@ -0,0 +1,5 @@ +// bindgen-flags: --allowlist-type "NoDefault" --no-default "NoDefault" + +class NoDefault { + int i; +}; diff --git a/tests/headers/no_default_whitelisted.hpp b/tests/headers/no_default_whitelisted.hpp deleted file mode 100644 index 12676be6d2..0000000000 --- a/tests/headers/no_default_whitelisted.hpp +++ /dev/null @@ -1,5 +0,0 @@ -// bindgen-flags: --whitelist-type "NoDefault" --no-default "NoDefault" - -class NoDefault { - int i; -}; diff --git a/tests/headers/objc_allowlist.h b/tests/headers/objc_allowlist.h new file mode 100644 index 0000000000..8c939960b0 --- /dev/null +++ b/tests/headers/objc_allowlist.h @@ -0,0 +1,24 @@ +// bindgen-flags: --objc-extern-crate --allowlist-type AllowlistMe --allowlist-type AllowlistMe_InterestingCategory -- -x objective-c +// bindgen-osx-only + + +// Protocol should be included, since it is used by the AllowlistMe +@protocol SomeProtocol +-(void)protocolMethod; ++(void)protocolClassMethod; +@end + +// The allowlisted item +@interface AllowlistMe +-(void)method; ++(void)classMethod; +@end + +// This was also explicitly allowlisted +@interface AllowlistMe (InterestingCategory) +@end + +// This was not automatically allowlisted +@interface AllowlistMe (IgnoredCategory) +@end + diff --git a/tests/headers/objc_whitelist.h b/tests/headers/objc_whitelist.h deleted file mode 100644 index 8a3bb86917..0000000000 --- a/tests/headers/objc_whitelist.h +++ /dev/null @@ -1,24 +0,0 @@ -// bindgen-flags: --objc-extern-crate --whitelist-type WhitelistMe --whitelist-type WhitelistMe_InterestingCategory -- -x objective-c -// bindgen-osx-only - - -// Protocol should be included, since it is used by the WhitelistMe -@protocol SomeProtocol --(void)protocolMethod; -+(void)protocolClassMethod; -@end - -// The whitelisted item -@interface WhitelistMe --(void)method; -+(void)classMethod; -@end - -// This was also explicitly whitelisted -@interface WhitelistMe (InterestingCategory) -@end - -// This was not automatically whitelisted -@interface WhitelistMe (IgnoredCategory) -@end - diff --git a/tests/headers/opaque-tracing.hpp b/tests/headers/opaque-tracing.hpp index 9f7319cccd..cf65276a68 100644 --- a/tests/headers/opaque-tracing.hpp +++ b/tests/headers/opaque-tracing.hpp @@ -1,8 +1,8 @@ -// bindgen-flags: --opaque-type ".*" --whitelist-function=foo --with-derive-hash --with-derive-partialeq --with-derive-eq +// bindgen-flags: --opaque-type ".*" --allowlist-function=foo --with-derive-hash --with-derive-partialeq --with-derive-eq class Container; -// The whitelist tracing should reach the Container type, even though it's +// The allowlist tracing should reach the Container type, even though it's // marked as opaque. void foo(Container* c); diff --git a/tests/headers/replaces_double.hpp b/tests/headers/replaces_double.hpp index 1a78b0d92b..ce6a8dbb45 100644 --- a/tests/headers/replaces_double.hpp +++ b/tests/headers/replaces_double.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --blacklist-type Wrapper -- --std=c++11 +// bindgen-flags: --blocklist-type Wrapper -- --std=c++11 template struct Wrapper { diff --git a/tests/headers/type-referenced-by-whitelisted-function.h b/tests/headers/type-referenced-by-allowlisted-function.h similarity index 59% rename from tests/headers/type-referenced-by-whitelisted-function.h rename to tests/headers/type-referenced-by-allowlisted-function.h index 86b0030300..bf675bc9a7 100644 --- a/tests/headers/type-referenced-by-whitelisted-function.h +++ b/tests/headers/type-referenced-by-allowlisted-function.h @@ -1,4 +1,4 @@ -// bindgen-flags: --whitelist-function dl_iterate_phdr +// bindgen-flags: --allowlist-function dl_iterate_phdr struct dl_phdr_info { int x; diff --git a/tests/headers/type_alias_empty.hpp b/tests/headers/type_alias_empty.hpp index f0760c8ffd..bcccc3c85e 100644 --- a/tests/headers/type_alias_empty.hpp +++ b/tests/headers/type_alias_empty.hpp @@ -1,6 +1,6 @@ -// bindgen-flags: --whitelist-type bool_constant -- -std=c++11 +// bindgen-flags: --allowlist-type bool_constant -- -std=c++11 -// NB: The --whitelist-type is done to trigger the traversal of the types on +// NB: The --allowlist-type is done to trigger the traversal of the types on // codegen in order to trigger #67. template diff --git a/tests/headers/type_alias_template_specialized.hpp b/tests/headers/type_alias_template_specialized.hpp index a2d32b56a1..f7403a36d0 100644 --- a/tests/headers/type_alias_template_specialized.hpp +++ b/tests/headers/type_alias_template_specialized.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --whitelist-type Rooted -- -std=c++14 +// bindgen-flags: --allowlist-type Rooted -- -std=c++14 template using MaybeWrapped = a; class Rooted { diff --git a/tests/headers/var-tracing.hpp b/tests/headers/var-tracing.hpp index 0d0b0ccac2..ef002a00f5 100644 --- a/tests/headers/var-tracing.hpp +++ b/tests/headers/var-tracing.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --whitelist-type Baz +// bindgen-flags: --allowlist-type Baz struct Bar { const int m_baz; diff --git a/tests/headers/whitelisted-item-references-no-hash.hpp b/tests/headers/whitelisted-item-references-no-hash.hpp deleted file mode 100644 index e656d32d0e..0000000000 --- a/tests/headers/whitelisted-item-references-no-hash.hpp +++ /dev/null @@ -1,7 +0,0 @@ -// bindgen-flags: --with-derive-hash --whitelist-type "WhitelistMe" --no-hash "NoHash" - -struct NoHash {}; - -class WhitelistMe { - NoHash a; -}; diff --git a/tests/headers/whitelisted-item-references-no-partialeq.hpp b/tests/headers/whitelisted-item-references-no-partialeq.hpp deleted file mode 100644 index d9d3d4311f..0000000000 --- a/tests/headers/whitelisted-item-references-no-partialeq.hpp +++ /dev/null @@ -1,7 +0,0 @@ -// bindgen-flags: --with-derive-partialeq --whitelist-type "WhitelistMe" --no-partialeq "NoPartialEq" - -struct NoPartialEq {}; - -class WhitelistMe { - NoPartialEq a; -}; diff --git a/tests/headers/whitelisted_item_references_no_copy.hpp b/tests/headers/whitelisted_item_references_no_copy.hpp deleted file mode 100644 index 755bbbdd49..0000000000 --- a/tests/headers/whitelisted_item_references_no_copy.hpp +++ /dev/null @@ -1,7 +0,0 @@ -// bindgen-flags: --whitelist-type "WhitelistMe" --no-copy "NoCopy" - -struct NoCopy {}; - -class WhitelistMe { - NoCopy a; -}; diff --git a/tests/stylo.hpp b/tests/stylo.hpp index d6eabc3542..8810290365 100644 --- a/tests/stylo.hpp +++ b/tests/stylo.hpp @@ -103701,7 +103701,7 @@ class nsIExpandedPrincipal : public nsISupports { template struct COMTypeInfo; - virtual nsresult GetWhiteList(nsTArray > **aWhiteList) = 0; + virtual nsresult GetAllowList(nsTArray > **anAllowList) = 0; }; diff --git a/tests/stylo_sanity.rs b/tests/stylo_sanity.rs index 88d87adbf2..2ea77628a0 100755 --- a/tests/stylo_sanity.rs +++ b/tests/stylo_sanity.rs @@ -30,209 +30,209 @@ fn sanity_check_can_generate_stylo_bindings() { .time_phases(true) .disable_header_comment() .header(concat!(env!("CARGO_MANIFEST_DIR"), "/tests/stylo.hpp")) - .whitelist_function("Servo_.*") - .whitelist_function("Gecko_.*") - .blacklist_type("nsACString_internal") - .blacklist_type("nsAString_internal") - .blacklist_type("mozilla::css::URLValue") - .blacklist_type("RawGeckoAnimationPropertySegment") - .blacklist_type("RawGeckoComputedTiming") - .blacklist_type("RawGeckoDocument") - .blacklist_type("RawGeckoElement") - .blacklist_type("RawGeckoKeyframeList") - .blacklist_type("RawGeckoComputedKeyframeValuesList") - .blacklist_type("RawGeckoFontFaceRuleList") - .blacklist_type("RawGeckoNode") - .blacklist_type("RawGeckoAnimationValueList") - .blacklist_type("RawServoAnimationValue") - .blacklist_type("RawServoAnimationValueMap") - .blacklist_type("RawServoDeclarationBlock") - .blacklist_type("RawGeckoPresContext") - .blacklist_type("RawGeckoPresContextOwned") - .blacklist_type("RawGeckoStyleAnimationList") - .blacklist_type("RawGeckoURLExtraData") - .blacklist_type("RefPtr") - .blacklist_type("CSSPseudoClassType") - .blacklist_type("TraversalRootBehavior") - .blacklist_type("ComputedTimingFunction_BeforeFlag") - .blacklist_type("FontFamilyList") - .blacklist_type("FontFamilyType") - .blacklist_type("Keyframe") - .blacklist_type("ServoBundledURI") - .blacklist_type("ServoElementSnapshot") - .blacklist_type("SheetParsingMode") - .blacklist_type("StyleBasicShape") - .blacklist_type("StyleBasicShapeType") - .blacklist_type("StyleShapeSource") - .blacklist_type("nsCSSFontFaceRule") - .blacklist_type("nsCSSKeyword") - .blacklist_type("nsCSSPropertyID") - .blacklist_type("nsCSSShadowArray") - .blacklist_type("nsCSSUnit") - .blacklist_type("nsCSSValue") - .blacklist_type("nsCSSValueSharedList") - .blacklist_type("nsChangeHint") - .blacklist_type("nsCursorImage") - .blacklist_type("nsFont") - .blacklist_type("nsIAtom") - .blacklist_type("nsMediaFeature") - .blacklist_type("nsRestyleHint") - .blacklist_type("nsStyleBackground") - .blacklist_type("nsStyleBorder") - .blacklist_type("nsStyleColor") - .blacklist_type("nsStyleColumn") - .blacklist_type("nsStyleContent") - .blacklist_type("nsStyleContentData") - .blacklist_type("nsStyleContentType") - .blacklist_type("nsStyleContext") - .blacklist_type("nsStyleCoord") - .blacklist_type("nsStyleCoord_Calc") - .blacklist_type("nsStyleCoord_CalcValue") - .blacklist_type("nsStyleDisplay") - .blacklist_type("nsStyleEffects") - .blacklist_type("nsStyleFilter") - .blacklist_type("nsStyleFont") - .blacklist_type("nsStyleGradient") - .blacklist_type("nsStyleGradientStop") - .blacklist_type("nsStyleImage") - .blacklist_type("nsStyleImageLayers") - .blacklist_type("nsStyleImageLayers_Layer") - .blacklist_type("nsStyleImageLayers_LayerType") - .blacklist_type("nsStyleImageRequest") - .blacklist_type("nsStyleList") - .blacklist_type("nsStyleMargin") - .blacklist_type("nsStyleOutline") - .blacklist_type("nsStylePadding") - .blacklist_type("nsStylePosition") - .blacklist_type("nsStyleQuoteValues") - .blacklist_type("nsStyleSVG") - .blacklist_type("nsStyleSVGPaint") - .blacklist_type("nsStyleSVGReset") - .blacklist_type("nsStyleTable") - .blacklist_type("nsStyleTableBorder") - .blacklist_type("nsStyleText") - .blacklist_type("nsStyleTextReset") - .blacklist_type("nsStyleUIReset") - .blacklist_type("nsStyleUnion") - .blacklist_type("nsStyleUnit") - .blacklist_type("nsStyleUserInterface") - .blacklist_type("nsStyleVariables") - .blacklist_type("nsStyleVisibility") - .blacklist_type("nsStyleXUL") - .blacklist_type("nsTimingFunction") - .blacklist_type("nscolor") - .blacklist_type("nscoord") - .blacklist_type("nsresult") - .blacklist_type("Loader") - .blacklist_type("ServoStyleSheet") - .blacklist_type("EffectCompositor_CascadeLevel") - .blacklist_type("UpdateAnimationsTasks") - .blacklist_type("nsTArrayBorrowed_uintptr_t") - .blacklist_type("ServoCssRulesStrong") - .blacklist_type("ServoCssRulesBorrowed") - .blacklist_type("ServoCssRulesBorrowedOrNull") - .blacklist_type("ServoCssRules") - .blacklist_type("RawServoStyleSheetStrong") - .blacklist_type("RawServoStyleSheetBorrowed") - .blacklist_type("RawServoStyleSheetBorrowedOrNull") - .blacklist_type("RawServoStyleSheet") - .blacklist_type("ServoComputedValuesStrong") - .blacklist_type("ServoComputedValuesBorrowed") - .blacklist_type("ServoComputedValuesBorrowedOrNull") - .blacklist_type("ServoComputedValues") - .blacklist_type("RawServoDeclarationBlockStrong") - .blacklist_type("RawServoDeclarationBlockBorrowed") - .blacklist_type("RawServoDeclarationBlockBorrowedOrNull") - .blacklist_type("RawServoStyleRuleStrong") - .blacklist_type("RawServoStyleRuleBorrowed") - .blacklist_type("RawServoStyleRuleBorrowedOrNull") - .blacklist_type("RawServoStyleRule") - .blacklist_type("RawServoImportRuleStrong") - .blacklist_type("RawServoImportRuleBorrowed") - .blacklist_type("RawServoImportRuleBorrowedOrNull") - .blacklist_type("RawServoImportRule") - .blacklist_type("RawServoAnimationValueStrong") - .blacklist_type("RawServoAnimationValueBorrowed") - .blacklist_type("RawServoAnimationValueBorrowedOrNull") - .blacklist_type("RawServoAnimationValueMapStrong") - .blacklist_type("RawServoAnimationValueMapBorrowed") - .blacklist_type("RawServoAnimationValueMapBorrowedOrNull") - .blacklist_type("RawServoMediaListStrong") - .blacklist_type("RawServoMediaListBorrowed") - .blacklist_type("RawServoMediaListBorrowedOrNull") - .blacklist_type("RawServoMediaList") - .blacklist_type("RawServoMediaRuleStrong") - .blacklist_type("RawServoMediaRuleBorrowed") - .blacklist_type("RawServoMediaRuleBorrowedOrNull") - .blacklist_type("RawServoMediaRule") - .blacklist_type("RawServoNamespaceRuleStrong") - .blacklist_type("RawServoNamespaceRuleBorrowed") - .blacklist_type("RawServoNamespaceRuleBorrowedOrNull") - .blacklist_type("RawServoNamespaceRule") - .blacklist_type("RawServoStyleSetOwned") - .blacklist_type("RawServoStyleSetOwnedOrNull") - .blacklist_type("RawServoStyleSetBorrowed") - .blacklist_type("RawServoStyleSetBorrowedOrNull") - .blacklist_type("RawServoStyleSetBorrowedMut") - .blacklist_type("RawServoStyleSetBorrowedMutOrNull") - .blacklist_type("RawServoStyleSet") - .blacklist_type("StyleChildrenIteratorOwned") - .blacklist_type("StyleChildrenIteratorOwnedOrNull") - .blacklist_type("StyleChildrenIteratorBorrowed") - .blacklist_type("StyleChildrenIteratorBorrowedOrNull") - .blacklist_type("StyleChildrenIteratorBorrowedMut") - .blacklist_type("StyleChildrenIteratorBorrowedMutOrNull") - .blacklist_type("StyleChildrenIterator") - .blacklist_type("ServoElementSnapshotOwned") - .blacklist_type("ServoElementSnapshotOwnedOrNull") - .blacklist_type("ServoElementSnapshotBorrowed") - .blacklist_type("ServoElementSnapshotBorrowedOrNull") - .blacklist_type("ServoElementSnapshotBorrowedMut") - .blacklist_type("ServoElementSnapshotBorrowedMutOrNull") - .blacklist_type("RawGeckoNodeBorrowed") - .blacklist_type("RawGeckoNodeBorrowedOrNull") - .blacklist_type("RawGeckoElementBorrowed") - .blacklist_type("RawGeckoElementBorrowedOrNull") - .blacklist_type("RawGeckoDocumentBorrowed") - .blacklist_type("RawGeckoDocumentBorrowedOrNull") - .blacklist_type("RawServoDeclarationBlockStrongBorrowed") - .blacklist_type("RawServoDeclarationBlockStrongBorrowedOrNull") - .blacklist_type("RawGeckoPresContextBorrowed") - .blacklist_type("RawGeckoPresContextBorrowedOrNull") - .blacklist_type("RawGeckoStyleAnimationListBorrowed") - .blacklist_type("RawGeckoStyleAnimationListBorrowedOrNull") - .blacklist_type("nsCSSValueBorrowed") - .blacklist_type("nsCSSValueBorrowedOrNull") - .blacklist_type("nsCSSValueBorrowedMut") - .blacklist_type("nsCSSValueBorrowedMutOrNull") - .blacklist_type("nsTimingFunctionBorrowed") - .blacklist_type("nsTimingFunctionBorrowedOrNull") - .blacklist_type("nsTimingFunctionBorrowedMut") - .blacklist_type("nsTimingFunctionBorrowedMutOrNull") - .blacklist_type("RawGeckoAnimationPropertySegmentBorrowed") - .blacklist_type("RawGeckoAnimationPropertySegmentBorrowedOrNull") - .blacklist_type("RawGeckoAnimationPropertySegmentBorrowedMut") - .blacklist_type("RawGeckoAnimationPropertySegmentBorrowedMutOrNull") - .blacklist_type("RawGeckoAnimationValueListBorrowed") - .blacklist_type("RawGeckoAnimationValueListBorrowedOrNull") - .blacklist_type("RawGeckoAnimationValueListBorrowedMut") - .blacklist_type("RawGeckoAnimationValueListBorrowedMutOrNull") - .blacklist_type("RawGeckoComputedTimingBorrowed") - .blacklist_type("RawGeckoComputedTimingBorrowedOrNull") - .blacklist_type("RawGeckoComputedTimingBorrowedMut") - .blacklist_type("RawGeckoComputedTimingBorrowedMutOrNull") - .blacklist_type("RawGeckoKeyframeListBorrowed") - .blacklist_type("RawGeckoKeyframeListBorrowedOrNull") - .blacklist_type("RawGeckoKeyframeListBorrowedMut") - .blacklist_type("RawGeckoKeyframeListBorrowedMutOrNull") - .blacklist_type("RawGeckoComputedKeyframeValuesListBorrowed") - .blacklist_type("RawGeckoComputedKeyframeValuesListBorrowedOrNull") - .blacklist_type("RawGeckoComputedKeyframeValuesListBorrowedMut") - .blacklist_type("RawGeckoComputedKeyframeValuesListBorrowedMutOrNull") - .blacklist_type("RawGeckoFontFaceRuleListBorrowed") - .blacklist_type("RawGeckoFontFaceRuleListBorrowedOrNull") - .blacklist_type("RawGeckoFontFaceRuleListBorrowedMut") - .blacklist_type("RawGeckoFontFaceRuleListBorrowedMutOrNull") + .allowlist_function("Servo_.*") + .allowlist_function("Gecko_.*") + .blocklist_type("nsACString_internal") + .blocklist_type("nsAString_internal") + .blocklist_type("mozilla::css::URLValue") + .blocklist_type("RawGeckoAnimationPropertySegment") + .blocklist_type("RawGeckoComputedTiming") + .blocklist_type("RawGeckoDocument") + .blocklist_type("RawGeckoElement") + .blocklist_type("RawGeckoKeyframeList") + .blocklist_type("RawGeckoComputedKeyframeValuesList") + .blocklist_type("RawGeckoFontFaceRuleList") + .blocklist_type("RawGeckoNode") + .blocklist_type("RawGeckoAnimationValueList") + .blocklist_type("RawServoAnimationValue") + .blocklist_type("RawServoAnimationValueMap") + .blocklist_type("RawServoDeclarationBlock") + .blocklist_type("RawGeckoPresContext") + .blocklist_type("RawGeckoPresContextOwned") + .blocklist_type("RawGeckoStyleAnimationList") + .blocklist_type("RawGeckoURLExtraData") + .blocklist_type("RefPtr") + .blocklist_type("CSSPseudoClassType") + .blocklist_type("TraversalRootBehavior") + .blocklist_type("ComputedTimingFunction_BeforeFlag") + .blocklist_type("FontFamilyList") + .blocklist_type("FontFamilyType") + .blocklist_type("Keyframe") + .blocklist_type("ServoBundledURI") + .blocklist_type("ServoElementSnapshot") + .blocklist_type("SheetParsingMode") + .blocklist_type("StyleBasicShape") + .blocklist_type("StyleBasicShapeType") + .blocklist_type("StyleShapeSource") + .blocklist_type("nsCSSFontFaceRule") + .blocklist_type("nsCSSKeyword") + .blocklist_type("nsCSSPropertyID") + .blocklist_type("nsCSSShadowArray") + .blocklist_type("nsCSSUnit") + .blocklist_type("nsCSSValue") + .blocklist_type("nsCSSValueSharedList") + .blocklist_type("nsChangeHint") + .blocklist_type("nsCursorImage") + .blocklist_type("nsFont") + .blocklist_type("nsIAtom") + .blocklist_type("nsMediaFeature") + .blocklist_type("nsRestyleHint") + .blocklist_type("nsStyleBackground") + .blocklist_type("nsStyleBorder") + .blocklist_type("nsStyleColor") + .blocklist_type("nsStyleColumn") + .blocklist_type("nsStyleContent") + .blocklist_type("nsStyleContentData") + .blocklist_type("nsStyleContentType") + .blocklist_type("nsStyleContext") + .blocklist_type("nsStyleCoord") + .blocklist_type("nsStyleCoord_Calc") + .blocklist_type("nsStyleCoord_CalcValue") + .blocklist_type("nsStyleDisplay") + .blocklist_type("nsStyleEffects") + .blocklist_type("nsStyleFilter") + .blocklist_type("nsStyleFont") + .blocklist_type("nsStyleGradient") + .blocklist_type("nsStyleGradientStop") + .blocklist_type("nsStyleImage") + .blocklist_type("nsStyleImageLayers") + .blocklist_type("nsStyleImageLayers_Layer") + .blocklist_type("nsStyleImageLayers_LayerType") + .blocklist_type("nsStyleImageRequest") + .blocklist_type("nsStyleList") + .blocklist_type("nsStyleMargin") + .blocklist_type("nsStyleOutline") + .blocklist_type("nsStylePadding") + .blocklist_type("nsStylePosition") + .blocklist_type("nsStyleQuoteValues") + .blocklist_type("nsStyleSVG") + .blocklist_type("nsStyleSVGPaint") + .blocklist_type("nsStyleSVGReset") + .blocklist_type("nsStyleTable") + .blocklist_type("nsStyleTableBorder") + .blocklist_type("nsStyleText") + .blocklist_type("nsStyleTextReset") + .blocklist_type("nsStyleUIReset") + .blocklist_type("nsStyleUnion") + .blocklist_type("nsStyleUnit") + .blocklist_type("nsStyleUserInterface") + .blocklist_type("nsStyleVariables") + .blocklist_type("nsStyleVisibility") + .blocklist_type("nsStyleXUL") + .blocklist_type("nsTimingFunction") + .blocklist_type("nscolor") + .blocklist_type("nscoord") + .blocklist_type("nsresult") + .blocklist_type("Loader") + .blocklist_type("ServoStyleSheet") + .blocklist_type("EffectCompositor_CascadeLevel") + .blocklist_type("UpdateAnimationsTasks") + .blocklist_type("nsTArrayBorrowed_uintptr_t") + .blocklist_type("ServoCssRulesStrong") + .blocklist_type("ServoCssRulesBorrowed") + .blocklist_type("ServoCssRulesBorrowedOrNull") + .blocklist_type("ServoCssRules") + .blocklist_type("RawServoStyleSheetStrong") + .blocklist_type("RawServoStyleSheetBorrowed") + .blocklist_type("RawServoStyleSheetBorrowedOrNull") + .blocklist_type("RawServoStyleSheet") + .blocklist_type("ServoComputedValuesStrong") + .blocklist_type("ServoComputedValuesBorrowed") + .blocklist_type("ServoComputedValuesBorrowedOrNull") + .blocklist_type("ServoComputedValues") + .blocklist_type("RawServoDeclarationBlockStrong") + .blocklist_type("RawServoDeclarationBlockBorrowed") + .blocklist_type("RawServoDeclarationBlockBorrowedOrNull") + .blocklist_type("RawServoStyleRuleStrong") + .blocklist_type("RawServoStyleRuleBorrowed") + .blocklist_type("RawServoStyleRuleBorrowedOrNull") + .blocklist_type("RawServoStyleRule") + .blocklist_type("RawServoImportRuleStrong") + .blocklist_type("RawServoImportRuleBorrowed") + .blocklist_type("RawServoImportRuleBorrowedOrNull") + .blocklist_type("RawServoImportRule") + .blocklist_type("RawServoAnimationValueStrong") + .blocklist_type("RawServoAnimationValueBorrowed") + .blocklist_type("RawServoAnimationValueBorrowedOrNull") + .blocklist_type("RawServoAnimationValueMapStrong") + .blocklist_type("RawServoAnimationValueMapBorrowed") + .blocklist_type("RawServoAnimationValueMapBorrowedOrNull") + .blocklist_type("RawServoMediaListStrong") + .blocklist_type("RawServoMediaListBorrowed") + .blocklist_type("RawServoMediaListBorrowedOrNull") + .blocklist_type("RawServoMediaList") + .blocklist_type("RawServoMediaRuleStrong") + .blocklist_type("RawServoMediaRuleBorrowed") + .blocklist_type("RawServoMediaRuleBorrowedOrNull") + .blocklist_type("RawServoMediaRule") + .blocklist_type("RawServoNamespaceRuleStrong") + .blocklist_type("RawServoNamespaceRuleBorrowed") + .blocklist_type("RawServoNamespaceRuleBorrowedOrNull") + .blocklist_type("RawServoNamespaceRule") + .blocklist_type("RawServoStyleSetOwned") + .blocklist_type("RawServoStyleSetOwnedOrNull") + .blocklist_type("RawServoStyleSetBorrowed") + .blocklist_type("RawServoStyleSetBorrowedOrNull") + .blocklist_type("RawServoStyleSetBorrowedMut") + .blocklist_type("RawServoStyleSetBorrowedMutOrNull") + .blocklist_type("RawServoStyleSet") + .blocklist_type("StyleChildrenIteratorOwned") + .blocklist_type("StyleChildrenIteratorOwnedOrNull") + .blocklist_type("StyleChildrenIteratorBorrowed") + .blocklist_type("StyleChildrenIteratorBorrowedOrNull") + .blocklist_type("StyleChildrenIteratorBorrowedMut") + .blocklist_type("StyleChildrenIteratorBorrowedMutOrNull") + .blocklist_type("StyleChildrenIterator") + .blocklist_type("ServoElementSnapshotOwned") + .blocklist_type("ServoElementSnapshotOwnedOrNull") + .blocklist_type("ServoElementSnapshotBorrowed") + .blocklist_type("ServoElementSnapshotBorrowedOrNull") + .blocklist_type("ServoElementSnapshotBorrowedMut") + .blocklist_type("ServoElementSnapshotBorrowedMutOrNull") + .blocklist_type("RawGeckoNodeBorrowed") + .blocklist_type("RawGeckoNodeBorrowedOrNull") + .blocklist_type("RawGeckoElementBorrowed") + .blocklist_type("RawGeckoElementBorrowedOrNull") + .blocklist_type("RawGeckoDocumentBorrowed") + .blocklist_type("RawGeckoDocumentBorrowedOrNull") + .blocklist_type("RawServoDeclarationBlockStrongBorrowed") + .blocklist_type("RawServoDeclarationBlockStrongBorrowedOrNull") + .blocklist_type("RawGeckoPresContextBorrowed") + .blocklist_type("RawGeckoPresContextBorrowedOrNull") + .blocklist_type("RawGeckoStyleAnimationListBorrowed") + .blocklist_type("RawGeckoStyleAnimationListBorrowedOrNull") + .blocklist_type("nsCSSValueBorrowed") + .blocklist_type("nsCSSValueBorrowedOrNull") + .blocklist_type("nsCSSValueBorrowedMut") + .blocklist_type("nsCSSValueBorrowedMutOrNull") + .blocklist_type("nsTimingFunctionBorrowed") + .blocklist_type("nsTimingFunctionBorrowedOrNull") + .blocklist_type("nsTimingFunctionBorrowedMut") + .blocklist_type("nsTimingFunctionBorrowedMutOrNull") + .blocklist_type("RawGeckoAnimationPropertySegmentBorrowed") + .blocklist_type("RawGeckoAnimationPropertySegmentBorrowedOrNull") + .blocklist_type("RawGeckoAnimationPropertySegmentBorrowedMut") + .blocklist_type("RawGeckoAnimationPropertySegmentBorrowedMutOrNull") + .blocklist_type("RawGeckoAnimationValueListBorrowed") + .blocklist_type("RawGeckoAnimationValueListBorrowedOrNull") + .blocklist_type("RawGeckoAnimationValueListBorrowedMut") + .blocklist_type("RawGeckoAnimationValueListBorrowedMutOrNull") + .blocklist_type("RawGeckoComputedTimingBorrowed") + .blocklist_type("RawGeckoComputedTimingBorrowedOrNull") + .blocklist_type("RawGeckoComputedTimingBorrowedMut") + .blocklist_type("RawGeckoComputedTimingBorrowedMutOrNull") + .blocklist_type("RawGeckoKeyframeListBorrowed") + .blocklist_type("RawGeckoKeyframeListBorrowedOrNull") + .blocklist_type("RawGeckoKeyframeListBorrowedMut") + .blocklist_type("RawGeckoKeyframeListBorrowedMutOrNull") + .blocklist_type("RawGeckoComputedKeyframeValuesListBorrowed") + .blocklist_type("RawGeckoComputedKeyframeValuesListBorrowedOrNull") + .blocklist_type("RawGeckoComputedKeyframeValuesListBorrowedMut") + .blocklist_type("RawGeckoComputedKeyframeValuesListBorrowedMutOrNull") + .blocklist_type("RawGeckoFontFaceRuleListBorrowed") + .blocklist_type("RawGeckoFontFaceRuleListBorrowedOrNull") + .blocklist_type("RawGeckoFontFaceRuleListBorrowedMut") + .blocklist_type("RawGeckoFontFaceRuleListBorrowedMutOrNull") .raw_line(r#"pub use nsstring::{nsACString, nsAString, nsString};"#) .raw_line(r#"type nsACString_internal = nsACString;"#) .raw_line(r#"type nsAString_internal = nsAString;"#) From 650732cd22ce32b0f4662ad0d81612d13528c895 Mon Sep 17 00:00:00 2001 From: Fenhl Date: Sun, 21 Feb 2021 02:32:58 +0000 Subject: [PATCH 151/942] Upgrade to shlex 1 --- Cargo.lock | 4 ++-- Cargo.toml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7e09431db4..d846452ecd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -247,9 +247,9 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" [[package]] name = "shlex" -version = "0.1.1" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2" +checksum = "42a568c8f2cd051a4d283bd6eb0343ac214c1b0f1ac19f93e1175b2dee38c73d" [[package]] name = "strsim" diff --git a/Cargo.toml b/Cargo.toml index 4f8ac75da1..59cc2ad602 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,7 +42,7 @@ required-features = ["clap"] [dev-dependencies] diff = "0.1" clap = "2" -shlex = "0.1" +shlex = "1" [dependencies] bitflags = "1.0.3" @@ -56,7 +56,7 @@ peeking_take_while = "0.1.2" quote = { version = "1", default-features = false } regex = { version = "1.0", default-features = false , features = [ "std", "unicode"]} which = { version = "3.0", optional = true, default-features = false } -shlex = "0.1" +shlex = "1" rustc-hash = "1.0.1" # New validation in 0.3.6 breaks bindgen-integration: # https://github.com/alexcrichton/proc-macro2/commit/489c642. From 84c702036ed17058a4a47818161023acc70eb755 Mon Sep 17 00:00:00 2001 From: ldm0 Date: Tue, 9 Mar 2021 11:58:32 +0000 Subject: [PATCH 152/942] Remove outdated comments --- src/lib.rs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 945d3065f1..0716b42f47 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -642,12 +642,7 @@ impl Builder { } /// Whether the generated bindings should contain documentation comments - /// (docstrings) or not. - /// - /// This ideally will always be true, but it may need to be false until we - /// implement some processing on comments to work around issues as described - /// in [rust-bindgen issue - /// #426](https://github.com/rust-lang/rust-bindgen/issues/426). + /// (docstrings) or not. This is set to true by default. /// /// Note that clang by default excludes comments from system headers, pass /// `-fretain-comments-from-system-headers` as @@ -1775,7 +1770,7 @@ struct BindgenOptions { conservative_inline_namespaces: bool, /// Whether to keep documentation comments in the generated output. See the - /// documentation for more details. + /// documentation for more details. Defaults to true. generate_comments: bool, /// Whether to generate inline functions. Defaults to false. From af87a859ac67ac90123a52fcaf7c0b407a656ee2 Mon Sep 17 00:00:00 2001 From: Jethro Beekman Date: Tue, 9 Mar 2021 23:02:59 +0100 Subject: [PATCH 153/942] Fix typo in roundtrip test error message --- tests/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tests.rs b/tests/tests.rs index 7bf2c65c4f..4e38c11472 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -267,7 +267,7 @@ fn compare_generated_header( if let Err(e) = compare_generated_header(&header, roundtrip_builder, false) { - return Err(Error::new(ErrorKind::Other, format!("Checking CLI flags roundtrip errored! You probably need to fix Builder::command_line_args. {}", e))); + return Err(Error::new(ErrorKind::Other, format!("Checking CLI flags roundtrip errored! You probably need to fix Builder::command_line_flags. {}", e))); } } From 7286c815f80b14c0ee77773387434da40f511b42 Mon Sep 17 00:00:00 2001 From: Jethro Beekman Date: Tue, 9 Mar 2021 23:03:29 +0100 Subject: [PATCH 154/942] Add flag to ignore type blocklist when computing derive information Fixes #1454 --- src/ir/analysis/derive.rs | 5 +- src/lib.rs | 14 +++++ src/options.rs | 7 +++ tests/expectations/tests/issue-1454.rs | 81 ++++++++++++++++++++++++++ tests/headers/issue-1454.h | 12 ++++ 5 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 tests/expectations/tests/issue-1454.rs create mode 100644 tests/headers/issue-1454.h diff --git a/src/ir/analysis/derive.rs b/src/ir/analysis/derive.rs index fa4ce795da..dac9558691 100644 --- a/src/ir/analysis/derive.rs +++ b/src/ir/analysis/derive.rs @@ -138,8 +138,9 @@ impl<'ctx> CannotDerive<'ctx> { } fn constrain_type(&mut self, item: &Item, ty: &Type) -> CanDerive { - if !self.ctx.allowlisted_items().contains(&item.id()) { - trace!( + if !self.ctx.options().derive_ignore_blocklist && + !self.ctx.allowlisted_items().contains(&item.id()) + { trace!( " cannot derive {} for blocklisted type", self.derive_trait ); diff --git a/src/lib.rs b/src/lib.rs index 0716b42f47..804b965dae 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -549,6 +549,10 @@ impl Builder { output_vector.push("--respect-cxx-access-specs".into()); } + if self.options.derive_ignore_blocklist { + output_vector.push("--derive-ignore-blocklist".into()); + } + // Add clang arguments output_vector.push("--".into()); @@ -1568,6 +1572,12 @@ impl Builder { self.options.respect_cxx_access_specs = doit; self } + + /// Ignore the type blocklist when computing type derive information + pub fn derive_ignore_blocklist(mut self, doit: bool) -> Self { + self.options.derive_ignore_blocklist = doit; + self + } } /// Configuration options for generated bindings. @@ -1859,6 +1869,9 @@ struct BindgenOptions { /// Only make generated bindings `pub` if the items would be publically accessible /// by C++. respect_cxx_access_specs: bool, + + /// Ignore the type blocklist when computing type derive information + derive_ignore_blocklist: bool, } /// TODO(emilio): This is sort of a lie (see the error message that results from @@ -1996,6 +2009,7 @@ impl Default for BindgenOptions { wasm_import_module_name: None, dynamic_library_name: None, respect_cxx_access_specs: false, + derive_ignore_blocklist: false, } } } diff --git a/src/options.rs b/src/options.rs index 2289ad09bd..f1c26fd8ed 100644 --- a/src/options.rs +++ b/src/options.rs @@ -503,6 +503,9 @@ where Arg::with_name("respect-cxx-access-specs") .long("respect-cxx-access-specs") .help("Makes generated bindings `pub` only for items if the items are publically accessible in C++."), + Arg::with_name("derive-ignore-blocklist") + .long("derive-ignore-blocklist") + .help("Ignore the type blocklist when computing type derive information"), ]) // .args() .get_matches_from(args); @@ -929,6 +932,10 @@ where builder = builder.respect_cxx_access_specs(true); } + if matches.is_present("derive-ignore-blocklist") { + builder = builder.derive_ignore_blocklist(true); + } + let verbose = matches.is_present("verbose"); Ok((builder, output, verbose)) diff --git a/tests/expectations/tests/issue-1454.rs b/tests/expectations/tests/issue-1454.rs new file mode 100644 index 0000000000..e8df8da92d --- /dev/null +++ b/tests/expectations/tests/issue-1454.rs @@ -0,0 +1,81 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct rlimit; + +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct my_rlimit_conf { + pub core: rlimit, + pub cpu: rlimit, + pub data: rlimit, + pub fsize: rlimit, +} +#[test] +fn bindgen_test_layout_my_rlimit_conf() { + assert_eq!( + ::std::mem::size_of::(), + 0usize, + concat!("Size of: ", stringify!(my_rlimit_conf)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(my_rlimit_conf)) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).core as *const _ as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(my_rlimit_conf), + "::", + stringify!(core) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).cpu as *const _ as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(my_rlimit_conf), + "::", + stringify!(cpu) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).data as *const _ as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(my_rlimit_conf), + "::", + stringify!(data) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).fsize as *const _ + as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(my_rlimit_conf), + "::", + stringify!(fsize) + ) + ); +} diff --git a/tests/headers/issue-1454.h b/tests/headers/issue-1454.h new file mode 100644 index 0000000000..ce137b9238 --- /dev/null +++ b/tests/headers/issue-1454.h @@ -0,0 +1,12 @@ +// bindgen-flags: --no-recursive-allowlist --allowlist-type "my_rlimit_conf" --derive-ignore-blocklist --raw-line "#[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct rlimit;" + +struct rlimit {}; + +typedef struct +{ + struct rlimit core; + struct rlimit cpu; + struct rlimit data; + struct rlimit fsize; +} +my_rlimit_conf; From fb931bd6c1a91908fa34dab7bc76059f33131663 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 11 Mar 2021 12:52:18 +0100 Subject: [PATCH 155/942] Revert "Add flag to ignore type blocklist when computing derive information" This reverts commit 7286c815f80b14c0ee77773387434da40f511b42, because it was not intended to be merged after all, see https://github.com/rust-lang/rust-bindgen/pull/2003#issuecomment-796160427. --- src/ir/analysis/derive.rs | 5 +- src/lib.rs | 14 ----- src/options.rs | 7 --- tests/expectations/tests/issue-1454.rs | 81 -------------------------- tests/headers/issue-1454.h | 12 ---- 5 files changed, 2 insertions(+), 117 deletions(-) delete mode 100644 tests/expectations/tests/issue-1454.rs delete mode 100644 tests/headers/issue-1454.h diff --git a/src/ir/analysis/derive.rs b/src/ir/analysis/derive.rs index dac9558691..fa4ce795da 100644 --- a/src/ir/analysis/derive.rs +++ b/src/ir/analysis/derive.rs @@ -138,9 +138,8 @@ impl<'ctx> CannotDerive<'ctx> { } fn constrain_type(&mut self, item: &Item, ty: &Type) -> CanDerive { - if !self.ctx.options().derive_ignore_blocklist && - !self.ctx.allowlisted_items().contains(&item.id()) - { trace!( + if !self.ctx.allowlisted_items().contains(&item.id()) { + trace!( " cannot derive {} for blocklisted type", self.derive_trait ); diff --git a/src/lib.rs b/src/lib.rs index 804b965dae..0716b42f47 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -549,10 +549,6 @@ impl Builder { output_vector.push("--respect-cxx-access-specs".into()); } - if self.options.derive_ignore_blocklist { - output_vector.push("--derive-ignore-blocklist".into()); - } - // Add clang arguments output_vector.push("--".into()); @@ -1572,12 +1568,6 @@ impl Builder { self.options.respect_cxx_access_specs = doit; self } - - /// Ignore the type blocklist when computing type derive information - pub fn derive_ignore_blocklist(mut self, doit: bool) -> Self { - self.options.derive_ignore_blocklist = doit; - self - } } /// Configuration options for generated bindings. @@ -1869,9 +1859,6 @@ struct BindgenOptions { /// Only make generated bindings `pub` if the items would be publically accessible /// by C++. respect_cxx_access_specs: bool, - - /// Ignore the type blocklist when computing type derive information - derive_ignore_blocklist: bool, } /// TODO(emilio): This is sort of a lie (see the error message that results from @@ -2009,7 +1996,6 @@ impl Default for BindgenOptions { wasm_import_module_name: None, dynamic_library_name: None, respect_cxx_access_specs: false, - derive_ignore_blocklist: false, } } } diff --git a/src/options.rs b/src/options.rs index f1c26fd8ed..2289ad09bd 100644 --- a/src/options.rs +++ b/src/options.rs @@ -503,9 +503,6 @@ where Arg::with_name("respect-cxx-access-specs") .long("respect-cxx-access-specs") .help("Makes generated bindings `pub` only for items if the items are publically accessible in C++."), - Arg::with_name("derive-ignore-blocklist") - .long("derive-ignore-blocklist") - .help("Ignore the type blocklist when computing type derive information"), ]) // .args() .get_matches_from(args); @@ -932,10 +929,6 @@ where builder = builder.respect_cxx_access_specs(true); } - if matches.is_present("derive-ignore-blocklist") { - builder = builder.derive_ignore_blocklist(true); - } - let verbose = matches.is_present("verbose"); Ok((builder, output, verbose)) diff --git a/tests/expectations/tests/issue-1454.rs b/tests/expectations/tests/issue-1454.rs deleted file mode 100644 index e8df8da92d..0000000000 --- a/tests/expectations/tests/issue-1454.rs +++ /dev/null @@ -1,81 +0,0 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct rlimit; - -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct my_rlimit_conf { - pub core: rlimit, - pub cpu: rlimit, - pub data: rlimit, - pub fsize: rlimit, -} -#[test] -fn bindgen_test_layout_my_rlimit_conf() { - assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(my_rlimit_conf)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(my_rlimit_conf)) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).core as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(my_rlimit_conf), - "::", - stringify!(core) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).cpu as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(my_rlimit_conf), - "::", - stringify!(cpu) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).data as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(my_rlimit_conf), - "::", - stringify!(data) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).fsize as *const _ - as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(my_rlimit_conf), - "::", - stringify!(fsize) - ) - ); -} diff --git a/tests/headers/issue-1454.h b/tests/headers/issue-1454.h deleted file mode 100644 index ce137b9238..0000000000 --- a/tests/headers/issue-1454.h +++ /dev/null @@ -1,12 +0,0 @@ -// bindgen-flags: --no-recursive-allowlist --allowlist-type "my_rlimit_conf" --derive-ignore-blocklist --raw-line "#[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct rlimit;" - -struct rlimit {}; - -typedef struct -{ - struct rlimit core; - struct rlimit cpu; - struct rlimit data; - struct rlimit fsize; -} -my_rlimit_conf; From dedbea5bc0317be4e7fd47a49392a6b080f47ac8 Mon Sep 17 00:00:00 2001 From: Jethro Beekman Date: Wed, 10 Mar 2021 13:25:53 +0100 Subject: [PATCH 156/942] Add option to translate enum integer types to native Rust integer types Fixes #430 --- src/codegen/mod.rs | 102 ++++++++++-------- src/lib.rs | 18 ++++ src/options.rs | 7 ++ .../expectations/tests/enum-translate-type.rs | 15 +++ tests/headers/enum-translate-type.hpp | 14 +++ 5 files changed, 114 insertions(+), 42 deletions(-) create mode 100644 tests/expectations/tests/enum-translate-type.rs create mode 100644 tests/headers/enum-translate-type.hpp diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 62271acf30..1fba83167e 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -2524,7 +2524,7 @@ impl<'a> EnumBuilder<'a> { /// the representation, and which variation it should be generated as. fn new( name: &'a str, - attrs: Vec, + mut attrs: Vec, repr: proc_macro2::TokenStream, enum_variation: EnumVariation, enum_codegen_depth: usize, @@ -2543,6 +2543,8 @@ impl<'a> EnumBuilder<'a> { }, EnumVariation::Rust { .. } => { + // `repr` is guaranteed to be Rustified in Enum::codegen + attrs.insert(0, quote! { #[repr( #repr )] }); let tokens = quote!(); EnumBuilder::Rust { codegen_depth: enum_codegen_depth + 1, @@ -2820,51 +2822,73 @@ impl CodeGenerator for Enum { let ident = ctx.rust_ident(&name); let enum_ty = item.expect_type(); let layout = enum_ty.layout(ctx); + let variation = self.computed_enum_variation(ctx, item); - let repr = self.repr().map(|repr| ctx.resolve_type(repr)); - let repr = match repr { - Some(repr) => match *repr.canonical_type(ctx).kind() { - TypeKind::Int(int_kind) => int_kind, - _ => panic!("Unexpected type as enum repr"), - }, - None => { - warn!( - "Guessing type of enum! Forward declarations of enums \ - shouldn't be legal!" - ); - IntKind::Int + let repr_translated; + let repr = match self.repr().map(|repr| ctx.resolve_type(repr)) { + Some(repr) + if !ctx.options().translate_enum_integer_types && + !variation.is_rust() => + { + repr } - }; + repr => { + // An enum's integer type is translated to a native Rust + // integer type in 3 cases: + // * the enum is Rustified and we need a translated type for + // the repr attribute + // * the representation couldn't be determined from the C source + // * it was explicitly requested as a bindgen option + + let kind = match repr { + Some(repr) => match *repr.canonical_type(ctx).kind() { + TypeKind::Int(int_kind) => int_kind, + _ => panic!("Unexpected type as enum repr"), + }, + None => { + warn!( + "Guessing type of enum! Forward declarations of enums \ + shouldn't be legal!" + ); + IntKind::Int + } + }; + + let signed = kind.is_signed(); + let size = layout + .map(|l| l.size) + .or_else(|| kind.known_size()) + .unwrap_or(0); + + let translated = match (signed, size) { + (true, 1) => IntKind::I8, + (false, 1) => IntKind::U8, + (true, 2) => IntKind::I16, + (false, 2) => IntKind::U16, + (true, 4) => IntKind::I32, + (false, 4) => IntKind::U32, + (true, 8) => IntKind::I64, + (false, 8) => IntKind::U64, + _ => { + warn!( + "invalid enum decl: signed: {}, size: {}", + signed, size + ); + IntKind::I32 + } + }; - let signed = repr.is_signed(); - let size = layout - .map(|l| l.size) - .or_else(|| repr.known_size()) - .unwrap_or(0); - - let repr_name = match (signed, size) { - (true, 1) => "i8", - (false, 1) => "u8", - (true, 2) => "i16", - (false, 2) => "u16", - (true, 4) => "i32", - (false, 4) => "u32", - (true, 8) => "i64", - (false, 8) => "u64", - _ => { - warn!("invalid enum decl: signed: {}, size: {}", signed, size); - "i32" + repr_translated = + Type::new(None, None, TypeKind::Int(translated), false); + &repr_translated } }; let mut attrs = vec![]; - let variation = self.computed_enum_variation(ctx, item); - // TODO(emilio): Delegate this to the builders? match variation { EnumVariation::Rust { non_exhaustive } => { - attrs.push(attributes::repr(repr_name)); if non_exhaustive && ctx.options().rust_features().non_exhaustive { @@ -2934,13 +2958,7 @@ impl CodeGenerator for Enum { }); } - let repr = match self.repr() { - Some(ty) => ty.to_rust_ty_or_opaque(ctx, &()), - None => { - let repr_name = ctx.rust_ident_raw(repr_name); - quote! { #repr_name } - } - }; + let repr = repr.to_rust_ty_or_opaque(ctx, item); let mut builder = EnumBuilder::new( &name, diff --git a/src/lib.rs b/src/lib.rs index 0716b42f47..3eeb0735b4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -549,6 +549,10 @@ impl Builder { output_vector.push("--respect-cxx-access-specs".into()); } + if self.options.translate_enum_integer_types { + output_vector.push("--translate-enum-integer-types".into()); + } + // Add clang arguments output_vector.push("--".into()); @@ -1568,6 +1572,16 @@ impl Builder { self.options.respect_cxx_access_specs = doit; self } + + /// Always translate enum integer types to native Rust integer types. + /// + /// This will result in enums having types such as `u32` and `i16` instead + /// of `c_uint` and `c_short`. Types for Rustified enums are always + /// translated. + pub fn translate_enum_integer_types(mut self, doit: bool) -> Self { + self.options.translate_enum_integer_types = doit; + self + } } /// Configuration options for generated bindings. @@ -1859,6 +1873,9 @@ struct BindgenOptions { /// Only make generated bindings `pub` if the items would be publically accessible /// by C++. respect_cxx_access_specs: bool, + + /// Always translate enum integer types to native Rust integer types. + translate_enum_integer_types: bool, } /// TODO(emilio): This is sort of a lie (see the error message that results from @@ -1996,6 +2013,7 @@ impl Default for BindgenOptions { wasm_import_module_name: None, dynamic_library_name: None, respect_cxx_access_specs: false, + translate_enum_integer_types: false, } } } diff --git a/src/options.rs b/src/options.rs index 2289ad09bd..4f75424adf 100644 --- a/src/options.rs +++ b/src/options.rs @@ -503,6 +503,9 @@ where Arg::with_name("respect-cxx-access-specs") .long("respect-cxx-access-specs") .help("Makes generated bindings `pub` only for items if the items are publically accessible in C++."), + Arg::with_name("translate-enum-integer-types") + .long("translate-enum-integer-types") + .help("Always translate enum integer types to native Rust integer types."), ]) // .args() .get_matches_from(args); @@ -929,6 +932,10 @@ where builder = builder.respect_cxx_access_specs(true); } + if matches.is_present("translate-enum-integer-types") { + builder = builder.translate_enum_integer_types(true); + } + let verbose = matches.is_present("verbose"); Ok((builder, output, verbose)) diff --git a/tests/expectations/tests/enum-translate-type.rs b/tests/expectations/tests/enum-translate-type.rs new file mode 100644 index 0000000000..89e6003e44 --- /dev/null +++ b/tests/expectations/tests/enum-translate-type.rs @@ -0,0 +1,15 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +pub const my_enum1_A: my_enum1 = 0; +pub type my_enum1 = u32; +pub const my_enum2_B: my_enum2 = -1; +pub type my_enum2 = i32; +pub const my_enum3_C: my_enum3 = 0; +pub type my_enum3 = i16; +pub const my_enum4_D: my_enum4 = 255; +pub type my_enum4 = u8; diff --git a/tests/headers/enum-translate-type.hpp b/tests/headers/enum-translate-type.hpp new file mode 100644 index 0000000000..8d85626105 --- /dev/null +++ b/tests/headers/enum-translate-type.hpp @@ -0,0 +1,14 @@ +// bindgen-flags: --translate-enum-integer-types -- -std=c++11 -Wno-narrowing + +enum my_enum1 { + A = 0, +}; +enum my_enum2 { + B = -1, +}; +enum my_enum3: short { + C = 0, +}; +enum my_enum4: unsigned char { + D = -1, +}; From af98fd47c7770cc6f71a9cb67e9165e47e47a078 Mon Sep 17 00:00:00 2001 From: Jethro Beekman Date: Wed, 10 Mar 2021 22:23:39 +0100 Subject: [PATCH 157/942] Add test infrastructure for ParseCallbacks --- tests/parse_callbacks/mod.rs | 7 +++++ tests/tests.rs | 60 ++++++++++++++++++++++++++++-------- 2 files changed, 55 insertions(+), 12 deletions(-) create mode 100644 tests/parse_callbacks/mod.rs diff --git a/tests/parse_callbacks/mod.rs b/tests/parse_callbacks/mod.rs new file mode 100644 index 0000000000..c60aaa1991 --- /dev/null +++ b/tests/parse_callbacks/mod.rs @@ -0,0 +1,7 @@ +use bindgen::callbacks::ParseCallbacks; + +pub fn lookup(cb: &str) -> Box { + match cb { + _ => panic!("Couldn't find name ParseCallbacks: {}", cb), + } +} diff --git a/tests/tests.rs b/tests/tests.rs index 4e38c11472..80ccc8c9eb 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -17,6 +17,8 @@ use std::sync::Once; mod options; use crate::options::builder_from_flags; +mod parse_callbacks; + // Run `rustfmt` on the given source string and return a tuple of the formatted // bindings, and rustfmt's stderr. fn rustfmt(source: String) -> (String, String) { @@ -115,7 +117,7 @@ The latest `rustfmt` is required to run the `bindgen` test suite. Install fn compare_generated_header( header: &PathBuf, - builder: Builder, + builder: BuilderState, check_roundtrip: bool, ) -> Result<(), Error> { let file_name = header.file_name().ok_or(Error::new( @@ -190,13 +192,7 @@ fn compare_generated_header( ), }; - let flags = if check_roundtrip { - let mut flags = builder.command_line_flags(); - flags.insert(0, "bindgen".into()); - flags - } else { - vec![] - }; + let (builder, roundtrip_builder) = builder.into_builder(check_roundtrip)?; // We skip the generate() error here so we get a full diff below let (actual, rustfmt_stderr) = match builder.generate() { @@ -262,8 +258,7 @@ fn compare_generated_header( return Err(Error::new(ErrorKind::Other, "Header and binding differ! Run with BINDGEN_OVERWRITE_EXPECTED=1 in the environment to automatically overwrite the expectation or with BINDGEN_TESTS_DIFFTOOL=meld to do this manually.")); } - if check_roundtrip { - let roundtrip_builder = builder_from_flags(flags.into_iter())?.0; + if let Some(roundtrip_builder) = roundtrip_builder { if let Err(e) = compare_generated_header(&header, roundtrip_builder, false) { @@ -281,7 +276,36 @@ fn builder() -> Builder { bindgen::builder().disable_header_comment() } -fn create_bindgen_builder(header: &PathBuf) -> Result { +struct BuilderState { + builder: Builder, + parse_callbacks: Option, +} + +impl BuilderState { + fn into_builder( + self, + with_roundtrip_builder: bool, + ) -> Result<(Builder, Option), Error> { + let roundtrip_builder = if with_roundtrip_builder { + let mut flags = self.builder.command_line_flags(); + flags.insert(0, "bindgen".into()); + let mut builder = builder_from_flags(flags.into_iter())?.0; + if let Some(ref parse_cb) = self.parse_callbacks { + builder = + builder.parse_callbacks(parse_callbacks::lookup(&parse_cb)); + } + Some(BuilderState { + builder, + parse_callbacks: self.parse_callbacks, + }) + } else { + None + }; + Ok((self.builder, roundtrip_builder)) + } +} + +fn create_bindgen_builder(header: &PathBuf) -> Result { #[cfg(feature = "logging")] let _ = env_logger::try_init(); @@ -290,6 +314,7 @@ fn create_bindgen_builder(header: &PathBuf) -> Result { // Scoop up bindgen-flags from test header let mut flags = Vec::with_capacity(2); + let mut parse_callbacks = None; for line in reader.lines() { let line = line?; @@ -311,6 +336,10 @@ fn create_bindgen_builder(header: &PathBuf) -> Result { .map(ToString::to_string) .chain(flags) .collect(); + } else if line.contains("bindgen-parse-callbacks: ") { + let parse_cb = + line.split("bindgen-parse-callbacks: ").last().unwrap(); + parse_callbacks = Some(parse_cb.to_owned()); } } @@ -353,7 +382,14 @@ fn create_bindgen_builder(header: &PathBuf) -> Result { .map(ToString::to_string) .chain(flags.into_iter()); - builder_from_flags(args).map(|(builder, _, _)| builder) + let mut builder = builder_from_flags(args)?.0; + if let Some(ref parse_cb) = parse_callbacks { + builder = builder.parse_callbacks(parse_callbacks::lookup(&parse_cb)); + } + Ok(BuilderState { + builder, + parse_callbacks, + }) } macro_rules! test_header { From 2a46e2924256b229653a558435259ca4968d5bd9 Mon Sep 17 00:00:00 2001 From: Jethro Beekman Date: Wed, 10 Mar 2021 22:24:57 +0100 Subject: [PATCH 158/942] Use original name when checking allowlist for anonymous enum variants --- src/ir/context.rs | 4 +++- src/ir/enum_ty.rs | 15 +++++++++++++-- .../parsecb-anonymous-enum-variant-rename.rs | 9 +++++++++ .../parsecb-anonymous-enum-variant-rename.h | 6 ++++++ tests/parse_callbacks/mod.rs | 15 +++++++++++++++ 5 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 tests/expectations/tests/parsecb-anonymous-enum-variant-rename.rs create mode 100644 tests/headers/parsecb-anonymous-enum-variant-rename.h diff --git a/src/ir/context.rs b/src/ir/context.rs index 6a0f07d924..a0d4de1e22 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -2299,7 +2299,9 @@ If you encounter an error missing from this list, please file an issue or a PR!" let mut prefix_path = parent.path_for_allowlisting(self).clone(); enum_.variants().iter().any(|variant| { - prefix_path.push(variant.name().into()); + prefix_path.push( + variant.name_for_allowlisting().into(), + ); let name = prefix_path[1..].join("::"); prefix_path.pop().unwrap(); self.options().allowlisted_vars.matches(&name) diff --git a/src/ir/enum_ty.rs b/src/ir/enum_ty.rs index c6cd89ce97..15d4136802 100644 --- a/src/ir/enum_ty.rs +++ b/src/ir/enum_ty.rs @@ -118,7 +118,7 @@ impl Enum { } }); - let name = ctx + let new_name = ctx .parse_callbacks() .and_then(|callbacks| { callbacks.enum_variant_name(type_name, &name, val) @@ -130,10 +130,11 @@ impl Enum { .last() .cloned() }) - .unwrap_or(name); + .unwrap_or_else(|| name.clone()); let comment = cursor.raw_comment(); variants.push(EnumVariant::new( + new_name, name, comment, val, @@ -224,6 +225,9 @@ pub struct EnumVariant { /// The name of the variant. name: String, + /// The original name of the variant (without user mangling) + name_for_allowlisting: String, + /// An optional doc comment. comment: Option, @@ -251,12 +255,14 @@ impl EnumVariant { /// Construct a new enumeration variant from the given parts. pub fn new( name: String, + name_for_allowlisting: String, comment: Option, val: EnumVariantValue, custom_behavior: Option, ) -> Self { EnumVariant { name, + name_for_allowlisting, comment, val, custom_behavior, @@ -268,6 +274,11 @@ impl EnumVariant { &self.name } + /// Get this variant's name. + pub fn name_for_allowlisting(&self) -> &str { + &self.name_for_allowlisting + } + /// Get this variant's value. pub fn val(&self) -> EnumVariantValue { self.val diff --git a/tests/expectations/tests/parsecb-anonymous-enum-variant-rename.rs b/tests/expectations/tests/parsecb-anonymous-enum-variant-rename.rs new file mode 100644 index 0000000000..e615486ed8 --- /dev/null +++ b/tests/expectations/tests/parsecb-anonymous-enum-variant-rename.rs @@ -0,0 +1,9 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +pub const RENAMED_MyVal: ::std::os::raw::c_uint = 0; +pub type _bindgen_ty_1 = ::std::os::raw::c_uint; diff --git a/tests/headers/parsecb-anonymous-enum-variant-rename.h b/tests/headers/parsecb-anonymous-enum-variant-rename.h new file mode 100644 index 0000000000..9336cf8993 --- /dev/null +++ b/tests/headers/parsecb-anonymous-enum-variant-rename.h @@ -0,0 +1,6 @@ +// bindgen-flags: --allowlist-var ^MyVal$ +// bindgen-parse-callbacks: enum-variant-rename + +enum { + MyVal = 0, +}; diff --git a/tests/parse_callbacks/mod.rs b/tests/parse_callbacks/mod.rs index c60aaa1991..01993cfc77 100644 --- a/tests/parse_callbacks/mod.rs +++ b/tests/parse_callbacks/mod.rs @@ -1,7 +1,22 @@ use bindgen::callbacks::ParseCallbacks; +#[derive(Debug)] +struct EnumVariantRename; + +impl ParseCallbacks for EnumVariantRename { + fn enum_variant_name( + &self, + _enum_name: Option<&str>, + original_variant_name: &str, + _variant_value: bindgen::callbacks::EnumVariantValue, + ) -> Option { + Some(format!("RENAMED_{}", original_variant_name)) + } +} + pub fn lookup(cb: &str) -> Box { match cb { + "enum-variant-rename" => Box::new(EnumVariantRename), _ => panic!("Couldn't find name ParseCallbacks: {}", cb), } } From 0780f804a89309417b6c99ccfc5d5941bdd38bab Mon Sep 17 00:00:00 2001 From: Jethro Beekman Date: Wed, 10 Mar 2021 19:16:47 +0100 Subject: [PATCH 159/942] Add callback to check derives for blocklisted types Fixes #1454 #2003 --- src/callbacks.rs | 19 ++++++++++++ src/ir/analysis/derive.rs | 25 ++++++++++++---- src/ir/context.rs | 38 +++++++++++++++++++++++- tests/expectations/tests/issue-1454.rs | 41 ++++++++++++++++++++++++++ tests/headers/issue-1454.h | 10 +++++++ tests/parse_callbacks/mod.rs | 24 +++++++++++++-- 6 files changed, 148 insertions(+), 9 deletions(-) create mode 100644 tests/expectations/tests/issue-1454.rs create mode 100644 tests/headers/issue-1454.h diff --git a/src/callbacks.rs b/src/callbacks.rs index 1cd7f37b07..e288af4341 100644 --- a/src/callbacks.rs +++ b/src/callbacks.rs @@ -1,5 +1,7 @@ //! A public API for more fine-grained customization of bindgen behavior. +pub use crate::ir::analysis::DeriveTrait; +pub use crate::ir::derive::CanDerive as ImplementsTrait; pub use crate::ir::enum_ty::{EnumVariantCustomBehavior, EnumVariantValue}; pub use crate::ir::int::IntKind; use std::fmt; @@ -76,4 +78,21 @@ pub trait ParseCallbacks: fmt::Debug + UnwindSafe { /// This will be called on every file inclusion, with the full path of the included file. fn include_file(&self, _filename: &str) {} + + /// This will be called to determine whether a particular blocklisted type + /// implements a trait or not. This will be used to implement traits on + /// other types containing the blocklisted type. + /// + /// * `None`: use the default behavior + /// * `Some(ImplementsTrait::Yes)`: `_name` implements `_derive_trait` + /// * `Some(ImplementsTrait::Manually)`: any type including `_name` can't + /// derive `_derive_trait` but can implemented it manually + /// * `Some(ImplementsTrait::No)`: `_name` doesn't implement `_derive_trait` + fn blocklisted_type_implements_trait( + &self, + _name: &str, + _derive_trait: DeriveTrait, + ) -> Option { + None + } } diff --git a/src/ir/analysis/derive.rs b/src/ir/analysis/derive.rs index fa4ce795da..be6266610b 100644 --- a/src/ir/analysis/derive.rs +++ b/src/ir/analysis/derive.rs @@ -16,7 +16,7 @@ use crate::ir::ty::{Type, TypeKind}; use crate::{Entry, HashMap, HashSet}; /// Which trait to consider when doing the `CannotDerive` analysis. -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum DeriveTrait { /// The `Copy` trait. Copy, @@ -139,11 +139,24 @@ impl<'ctx> CannotDerive<'ctx> { fn constrain_type(&mut self, item: &Item, ty: &Type) -> CanDerive { if !self.ctx.allowlisted_items().contains(&item.id()) { - trace!( - " cannot derive {} for blocklisted type", - self.derive_trait - ); - return CanDerive::No; + let can_derive = self + .ctx + .blocklisted_type_implements_trait(item, self.derive_trait); + match can_derive { + CanDerive::Yes => trace!( + " blocklisted type explicitly implements {}", + self.derive_trait + ), + CanDerive::Manually => trace!( + " blocklisted type requires manual implementation of {}", + self.derive_trait + ), + CanDerive::No => trace!( + " cannot derive {} for blocklisted type", + self.derive_trait + ), + } + return can_derive; } if self.derive_trait.not_by_name(self.ctx, &item) { diff --git a/src/ir/context.rs b/src/ir/context.rs index a0d4de1e22..ccb05e7565 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -28,7 +28,7 @@ use cexpr; use clang_sys; use proc_macro2::{Ident, Span}; use std::borrow::Cow; -use std::cell::Cell; +use std::cell::{Cell, RefCell}; use std::collections::HashMap as StdHashMap; use std::iter::IntoIterator; use std::mem; @@ -380,6 +380,10 @@ pub struct BindgenContext { /// computed after parsing our IR, and before running any of our analyses. allowlisted: Option, + /// Cache for calls to `ParseCallbacks::blocklisted_type_implements_trait` + blocklisted_types_implement_traits: + RefCell>>, + /// The set of `ItemId`s that are allowlisted for code generation _and_ that /// we should generate accounting for the codegen options. /// @@ -560,6 +564,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" options, generated_bindgen_complex: Cell::new(false), allowlisted: None, + blocklisted_types_implement_traits: Default::default(), codegen_items: None, used_template_parameters: None, need_bitfield_allocation: Default::default(), @@ -2205,6 +2210,37 @@ If you encounter an error missing from this list, please file an issue or a PR!" self.allowlisted.as_ref().unwrap() } + /// Check whether a particular blocklisted type implements a trait or not. + /// Results may be cached. + pub fn blocklisted_type_implements_trait( + &self, + item: &Item, + derive_trait: DeriveTrait, + ) -> CanDerive { + assert!(self.in_codegen_phase()); + assert!(self.current_module == self.root_module); + + let cb = match self.options.parse_callbacks { + Some(ref cb) => cb, + None => return CanDerive::No, + }; + + *self + .blocklisted_types_implement_traits + .borrow_mut() + .entry(derive_trait) + .or_default() + .entry(item.id()) + .or_insert_with(|| { + item.expect_type() + .name() + .and_then(|name| { + cb.blocklisted_type_implements_trait(name, derive_trait) + }) + .unwrap_or(CanDerive::No) + }) + } + /// Get a reference to the set of items we should generate. pub fn codegen_items(&self) -> &ItemSet { assert!(self.in_codegen_phase()); diff --git a/tests/expectations/tests/issue-1454.rs b/tests/expectations/tests/issue-1454.rs new file mode 100644 index 0000000000..e88e46978b --- /dev/null +++ b/tests/expectations/tests/issue-1454.rs @@ -0,0 +1,41 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +#[derive(Debug)] +pub struct extern_type; + +#[repr(C)] +#[derive(Debug)] +pub struct local_type { + pub inner: extern_type, +} +#[test] +fn bindgen_test_layout_local_type() { + assert_eq!( + ::std::mem::size_of::(), + 0usize, + concat!("Size of: ", stringify!(local_type)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(local_type)) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).inner as *const _ as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(local_type), + "::", + stringify!(inner) + ) + ); +} diff --git a/tests/headers/issue-1454.h b/tests/headers/issue-1454.h new file mode 100644 index 0000000000..96645dac9d --- /dev/null +++ b/tests/headers/issue-1454.h @@ -0,0 +1,10 @@ +// bindgen-flags: --no-recursive-allowlist --allowlist-type "local_type" --with-derive-hash --no-derive-copy --no-derive-default --raw-line "#[repr(C)] #[derive(Debug)] pub struct extern_type;" +// bindgen-parse-callbacks: blocklisted-type-implements-trait + +struct extern_type {}; + +typedef struct +{ + struct extern_type inner; +} +local_type; diff --git a/tests/parse_callbacks/mod.rs b/tests/parse_callbacks/mod.rs index 01993cfc77..b94b54de0b 100644 --- a/tests/parse_callbacks/mod.rs +++ b/tests/parse_callbacks/mod.rs @@ -1,4 +1,4 @@ -use bindgen::callbacks::ParseCallbacks; +use bindgen::callbacks::*; #[derive(Debug)] struct EnumVariantRename; @@ -8,15 +8,35 @@ impl ParseCallbacks for EnumVariantRename { &self, _enum_name: Option<&str>, original_variant_name: &str, - _variant_value: bindgen::callbacks::EnumVariantValue, + _variant_value: EnumVariantValue, ) -> Option { Some(format!("RENAMED_{}", original_variant_name)) } } +#[derive(Debug)] +struct BlocklistedTypeImplementsTrait; + +impl ParseCallbacks for BlocklistedTypeImplementsTrait { + fn blocklisted_type_implements_trait( + &self, + _name: &str, + derive_trait: DeriveTrait, + ) -> Option { + if derive_trait == DeriveTrait::Hash { + Some(ImplementsTrait::No) + } else { + Some(ImplementsTrait::Yes) + } + } +} + pub fn lookup(cb: &str) -> Box { match cb { "enum-variant-rename" => Box::new(EnumVariantRename), + "blocklisted-type-implements-trait" => { + Box::new(BlocklistedTypeImplementsTrait) + } _ => panic!("Couldn't find name ParseCallbacks: {}", cb), } } From 5a055fde1d4b8937396914c4089a3f9883380786 Mon Sep 17 00:00:00 2001 From: "Wang, Chi" Date: Tue, 23 Mar 2021 03:04:59 +0800 Subject: [PATCH 160/942] Add from_library for generated dynamic library structs (#2011) --- src/codegen/dyngen.rs | 20 ++++++++++++------- .../tests/dynamic_loading_simple.rs | 13 +++++++++--- .../tests/dynamic_loading_template.rs | 13 +++++++++--- .../tests/dynamic_loading_with_allowlist.rs | 13 +++++++++--- .../tests/dynamic_loading_with_blocklist.rs | 13 +++++++++--- .../tests/dynamic_loading_with_class.rs | 13 +++++++++--- 6 files changed, 63 insertions(+), 22 deletions(-) diff --git a/src/codegen/dyngen.rs b/src/codegen/dyngen.rs index 94dd574b91..768fb02e32 100644 --- a/src/codegen/dyngen.rs +++ b/src/codegen/dyngen.rs @@ -90,14 +90,20 @@ impl DynamicItems { path: P ) -> Result where P: AsRef<::std::ffi::OsStr> { - let __library = ::libloading::Library::new(path)?; + let library = ::libloading::Library::new(path)?; + Ok(Self::from_library(library)) + } + + pub unsafe fn from_library( + library: L + ) -> Self + where L: Into<::libloading::Library> { + let __library = library.into(); #( #constructor_inits )* - Ok( - #lib_ident { - __library, - #( #init_fields ),* - } - ) + #lib_ident { + __library, + #( #init_fields ),* + } } #( #struct_implementation )* diff --git a/tests/expectations/tests/dynamic_loading_simple.rs b/tests/expectations/tests/dynamic_loading_simple.rs index dae273a6ba..c9c4ba15f4 100644 --- a/tests/expectations/tests/dynamic_loading_simple.rs +++ b/tests/expectations/tests/dynamic_loading_simple.rs @@ -31,16 +31,23 @@ impl TestLib { where P: AsRef<::std::ffi::OsStr>, { - let __library = ::libloading::Library::new(path)?; + let library = ::libloading::Library::new(path)?; + Ok(Self::from_library(library)) + } + pub unsafe fn from_library(library: L) -> Self + where + L: Into<::libloading::Library>, + { + let __library = library.into(); let foo = __library.get(b"foo\0").map(|sym| *sym); let bar = __library.get(b"bar\0").map(|sym| *sym); let baz = __library.get(b"baz\0").map(|sym| *sym); - Ok(TestLib { + TestLib { __library, foo, bar, baz, - }) + } } pub unsafe fn foo( &self, diff --git a/tests/expectations/tests/dynamic_loading_template.rs b/tests/expectations/tests/dynamic_loading_template.rs index 4d90c62f38..a46253c667 100644 --- a/tests/expectations/tests/dynamic_loading_template.rs +++ b/tests/expectations/tests/dynamic_loading_template.rs @@ -19,14 +19,21 @@ impl TestLib { where P: AsRef<::std::ffi::OsStr>, { - let __library = ::libloading::Library::new(path)?; + let library = ::libloading::Library::new(path)?; + Ok(Self::from_library(library)) + } + pub unsafe fn from_library(library: L) -> Self + where + L: Into<::libloading::Library>, + { + let __library = library.into(); let foo = __library.get(b"foo\0").map(|sym| *sym); let foo1 = __library.get(b"foo1\0").map(|sym| *sym); - Ok(TestLib { + TestLib { __library, foo, foo1, - }) + } } pub unsafe fn foo( &self, diff --git a/tests/expectations/tests/dynamic_loading_with_allowlist.rs b/tests/expectations/tests/dynamic_loading_with_allowlist.rs index 0c1d9df20c..678cd34013 100644 --- a/tests/expectations/tests/dynamic_loading_with_allowlist.rs +++ b/tests/expectations/tests/dynamic_loading_with_allowlist.rs @@ -33,16 +33,23 @@ impl TestLib { where P: AsRef<::std::ffi::OsStr>, { - let __library = ::libloading::Library::new(path)?; + let library = ::libloading::Library::new(path)?; + Ok(Self::from_library(library)) + } + pub unsafe fn from_library(library: L) -> Self + where + L: Into<::libloading::Library>, + { + let __library = library.into(); let foo = __library.get(b"foo\0").map(|sym| *sym); let baz = __library.get(b"baz\0").map(|sym| *sym); let bazz = __library.get(b"bazz\0").map(|sym| *sym); - Ok(TestLib { + TestLib { __library, foo, baz, bazz, - }) + } } pub unsafe fn foo( &self, diff --git a/tests/expectations/tests/dynamic_loading_with_blocklist.rs b/tests/expectations/tests/dynamic_loading_with_blocklist.rs index 15092f06d2..930876a406 100644 --- a/tests/expectations/tests/dynamic_loading_with_blocklist.rs +++ b/tests/expectations/tests/dynamic_loading_with_blocklist.rs @@ -77,14 +77,21 @@ impl TestLib { where P: AsRef<::std::ffi::OsStr>, { - let __library = ::libloading::Library::new(path)?; + let library = ::libloading::Library::new(path)?; + Ok(Self::from_library(library)) + } + pub unsafe fn from_library(library: L) -> Self + where + L: Into<::libloading::Library>, + { + let __library = library.into(); let foo = __library.get(b"foo\0").map(|sym| *sym); let bar = __library.get(b"bar\0").map(|sym| *sym); - Ok(TestLib { + TestLib { __library, foo, bar, - }) + } } pub unsafe fn foo( &self, diff --git a/tests/expectations/tests/dynamic_loading_with_class.rs b/tests/expectations/tests/dynamic_loading_with_class.rs index a402e28874..81a045b520 100644 --- a/tests/expectations/tests/dynamic_loading_with_class.rs +++ b/tests/expectations/tests/dynamic_loading_with_class.rs @@ -72,14 +72,21 @@ impl TestLib { where P: AsRef<::std::ffi::OsStr>, { - let __library = ::libloading::Library::new(path)?; + let library = ::libloading::Library::new(path)?; + Ok(Self::from_library(library)) + } + pub unsafe fn from_library(library: L) -> Self + where + L: Into<::libloading::Library>, + { + let __library = library.into(); let foo = __library.get(b"foo\0").map(|sym| *sym); let bar = __library.get(b"bar\0").map(|sym| *sym); - Ok(TestLib { + TestLib { __library, foo, bar, - }) + } } pub unsafe fn foo( &self, From 4fef50331a3bcc396d4f7d2a5202a242b03273ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 29 Mar 2021 13:59:09 +0200 Subject: [PATCH 161/942] docs: Remove IRC reference. For now point to #rust:mozilla.org. If that gets too much bindgen-related traffic we can create an specific room for it. Closes #2012 --- CONTRIBUTING.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 716217e041..d533b06451 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,7 +2,8 @@ Hi! We'd love to have your contributions! If you want help or mentorship, reach out to us in a GitHub issue, or stop by -[#servo on irc.mozilla.org](irc://irc.mozilla.org#servo) and introduce yourself. +[#rust on chat.mozilla.org](https://chat.mozilla.org/#/room/#rust:mozilla.org) +and introduce yourself. From e0157a648f87c4f86fe1a1e6d5bd0502b5eb265a Mon Sep 17 00:00:00 2001 From: Mehmet Oguz Derin Date: Mon, 29 Mar 2021 16:06:41 +0300 Subject: [PATCH 162/942] From Nullablibility to Nullability A basic fix --- book/src/objc.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/src/objc.md b/book/src/objc.md index 55ec5e0b80..60e5638dba 100644 --- a/book/src/objc.md +++ b/book/src/objc.md @@ -66,7 +66,7 @@ long compile time. ## Not (yet) Supported -* Nullablibility attributes which return `Option`s. +* Nullability attributes which return `Option`s. * Probably many other things. Feel free to [open an issue](https://github.com/rust-lang/rust-bindgen/issues). # Example crate(s) From 2c5a1ea6b1bd56085d726dac347a31c49c95be76 Mon Sep 17 00:00:00 2001 From: "Dr. Chat" Date: Fri, 26 Mar 2021 17:12:23 -0500 Subject: [PATCH 163/942] Add a flag to ensure all symbols are resolved when a library is loaded --- src/codegen/dyngen.rs | 65 +++++++++++++++---- src/codegen/mod.rs | 1 + src/lib.rs | 18 +++++ src/options.rs | 7 ++ .../tests/dynamic_loading_required.rs | 59 +++++++++++++++++ .../tests/dynamic_loading_simple.rs | 8 +-- .../tests/dynamic_loading_template.rs | 8 +-- .../tests/dynamic_loading_with_allowlist.rs | 8 +-- .../tests/dynamic_loading_with_blocklist.rs | 8 +-- .../tests/dynamic_loading_with_class.rs | 8 +-- tests/headers/dynamic_loading_required.h | 5 ++ 11 files changed, 161 insertions(+), 34 deletions(-) create mode 100644 tests/expectations/tests/dynamic_loading_required.rs create mode 100644 tests/headers/dynamic_loading_required.h diff --git a/src/codegen/dyngen.rs b/src/codegen/dyngen.rs index 768fb02e32..de9e0f988b 100644 --- a/src/codegen/dyngen.rs +++ b/src/codegen/dyngen.rs @@ -5,6 +5,11 @@ use proc_macro2::Ident; /// Used to build the output tokens for dynamic bindings. #[derive(Default)] pub struct DynamicItems { + /// Tracks whether or not we contain any required symbols. + /// If so, the signature of the generated `from_library` function + /// will be altered to return a `Result` + has_required: bool, + /// Tracks the tokens that will appears inside the library struct -- e.g.: /// ```ignore /// struct Lib { @@ -77,6 +82,11 @@ impl DynamicItems { let constructor_inits = &self.constructor_inits; let init_fields = &self.init_fields; let struct_implementation = &self.struct_implementation; + + // FIXME: Is there a better way to lay this out? Conditional in the quote + // macro? + // If we have any required symbols, we must alter the signature of `from_library` + // so that it can return a failure code. quote! { extern crate libloading; @@ -91,19 +101,19 @@ impl DynamicItems { ) -> Result where P: AsRef<::std::ffi::OsStr> { let library = ::libloading::Library::new(path)?; - Ok(Self::from_library(library)) + Self::from_library(library) } pub unsafe fn from_library( library: L - ) -> Self + ) -> Result where L: Into<::libloading::Library> { let __library = library.into(); #( #constructor_inits )* - #lib_ident { + Ok(#lib_ident { __library, #( #init_fields ),* - } + }) } #( #struct_implementation )* @@ -116,6 +126,7 @@ impl DynamicItems { ident: Ident, abi: Abi, is_variadic: bool, + is_required: bool, args: Vec, args_identifiers: Vec, ret: proc_macro2::TokenStream, @@ -125,24 +136,50 @@ impl DynamicItems { assert_eq!(args.len(), args_identifiers.len()); } - self.struct_members.push(quote! { - pub #ident: Result, - }); + self.has_required |= is_required; + + self.struct_members.push( + if is_required { + quote! { + pub #ident: unsafe extern #abi fn ( #( #args),* ) #ret, + } + } else { + quote! { + pub #ident: Result, + } + } + ); // We can't implement variadic functions from C easily, so we allow to // access the function pointer so that the user can call it just fine. if !is_variadic { - self.struct_implementation.push(quote! { - pub unsafe fn #ident ( &self, #( #args ),* ) -> #ret_ty { - let sym = self.#ident.as_ref().expect("Expected function, got error."); - (sym)(#( #args_identifiers ),*) + self.struct_implementation.push( + if is_required { + quote! { + pub unsafe fn #ident ( &self, #( #args ),* ) -> #ret_ty { + self.#ident(#( #args_identifiers ),*) + } + } + } else { + quote! { + pub unsafe fn #ident ( &self, #( #args ),* ) -> #ret_ty { + let sym = self.#ident.as_ref().expect("Expected function, got error."); + (sym)(#( #args_identifiers ),*) + } + } } - }); + ); } let ident_str = codegen::helpers::ast_ty::cstr_expr(ident.to_string()); - self.constructor_inits.push(quote! { - let #ident = __library.get(#ident_str).map(|sym| *sym); + self.constructor_inits.push(if is_required { + quote! { + let #ident = __library.get(#ident_str).map(|sym| *sym)?; + } + } else { + quote! { + let #ident = __library.get(#ident_str).map(|sym| *sym); + } }); self.init_fields.push(quote! { diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 1fba83167e..9516220477 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -3869,6 +3869,7 @@ impl CodeGenerator for Function { ident, abi, signature.is_variadic(), + ctx.options().dynamic_link_require_all, args, args_identifiers, ret, diff --git a/src/lib.rs b/src/lib.rs index 3eeb0735b4..0c207a2f0d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -545,6 +545,10 @@ impl Builder { output_vector.push(name.clone()); } + if self.options.dynamic_link_require_all { + output_vector.push("--dynamic-link-require-all".into()); + } + if self.options.respect_cxx_access_specs { output_vector.push("--respect-cxx-access-specs".into()); } @@ -1567,6 +1571,14 @@ impl Builder { self } + /// Require successful linkage for all routines in a shared library. + /// This allows us to optimize function calls by being able to safely assume function pointers + /// are valid. + pub fn dynamic_link_require_all(mut self, req: bool) -> Self { + self.options.dynamic_link_require_all = req; + self + } + /// Generate bindings as `pub` only if the bound item is publically accessible by C++. pub fn respect_cxx_access_specs(mut self, doit: bool) -> Self { self.options.respect_cxx_access_specs = doit; @@ -1870,6 +1882,11 @@ struct BindgenOptions { /// this is None, no dynamic bindings are created. dynamic_library_name: Option, + /// Require successful linkage for all routines in a shared library. + /// This allows us to optimize function calls by being able to safely assume function pointers + /// are valid. No effect if `dynamic_library_name` is None. + dynamic_link_require_all: bool, + /// Only make generated bindings `pub` if the items would be publically accessible /// by C++. respect_cxx_access_specs: bool, @@ -2012,6 +2029,7 @@ impl Default for BindgenOptions { array_pointers_in_arguments: false, wasm_import_module_name: None, dynamic_library_name: None, + dynamic_link_require_all: false, respect_cxx_access_specs: false, translate_enum_integer_types: false, } diff --git a/src/options.rs b/src/options.rs index 4f75424adf..3626732108 100644 --- a/src/options.rs +++ b/src/options.rs @@ -500,6 +500,9 @@ where .long("dynamic-loading") .takes_value(true) .help("Use dynamic loading mode with the given library name."), + Arg::with_name("dynamic-link-require-all") + .long("dynamic-link-require-all") + .help("Require successful linkage to all functions in the library."), Arg::with_name("respect-cxx-access-specs") .long("respect-cxx-access-specs") .help("Makes generated bindings `pub` only for items if the items are publically accessible in C++."), @@ -928,6 +931,10 @@ where builder = builder.dynamic_library_name(dynamic_library_name); } + if matches.is_present("dynamic-link-require-all") { + builder = builder.dynamic_link_require_all(true); + } + if matches.is_present("respect-cxx-access-specs") { builder = builder.respect_cxx_access_specs(true); } diff --git a/tests/expectations/tests/dynamic_loading_required.rs b/tests/expectations/tests/dynamic_loading_required.rs new file mode 100644 index 0000000000..3600eacef8 --- /dev/null +++ b/tests/expectations/tests/dynamic_loading_required.rs @@ -0,0 +1,59 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +extern crate libloading; +pub struct TestLib { + __library: ::libloading::Library, + pub foo: unsafe extern "C" fn( + x: ::std::os::raw::c_int, + y: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + pub bar: unsafe extern "C" fn( + x: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int, + pub baz: unsafe extern "C" fn() -> ::std::os::raw::c_int, +} +impl TestLib { + pub unsafe fn new

(path: P) -> Result + where + P: AsRef<::std::ffi::OsStr>, + { + let library = ::libloading::Library::new(path)?; + Self::from_library(library) + } + pub unsafe fn from_library(library: L) -> Result + where + L: Into<::libloading::Library>, + { + let __library = library.into(); + let foo = __library.get(b"foo\0").map(|sym| *sym)?; + let bar = __library.get(b"bar\0").map(|sym| *sym)?; + let baz = __library.get(b"baz\0").map(|sym| *sym)?; + Ok(TestLib { + __library, + foo, + bar, + baz, + }) + } + pub unsafe fn foo( + &self, + x: ::std::os::raw::c_int, + y: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int { + self.foo(x, y) + } + pub unsafe fn bar( + &self, + x: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int { + self.bar(x) + } + pub unsafe fn baz(&self) -> ::std::os::raw::c_int { + self.baz() + } +} diff --git a/tests/expectations/tests/dynamic_loading_simple.rs b/tests/expectations/tests/dynamic_loading_simple.rs index c9c4ba15f4..3d2e3d2cbc 100644 --- a/tests/expectations/tests/dynamic_loading_simple.rs +++ b/tests/expectations/tests/dynamic_loading_simple.rs @@ -32,9 +32,9 @@ impl TestLib { P: AsRef<::std::ffi::OsStr>, { let library = ::libloading::Library::new(path)?; - Ok(Self::from_library(library)) + Self::from_library(library) } - pub unsafe fn from_library(library: L) -> Self + pub unsafe fn from_library(library: L) -> Result where L: Into<::libloading::Library>, { @@ -42,12 +42,12 @@ impl TestLib { let foo = __library.get(b"foo\0").map(|sym| *sym); let bar = __library.get(b"bar\0").map(|sym| *sym); let baz = __library.get(b"baz\0").map(|sym| *sym); - TestLib { + Ok(TestLib { __library, foo, bar, baz, - } + }) } pub unsafe fn foo( &self, diff --git a/tests/expectations/tests/dynamic_loading_template.rs b/tests/expectations/tests/dynamic_loading_template.rs index a46253c667..de23143441 100644 --- a/tests/expectations/tests/dynamic_loading_template.rs +++ b/tests/expectations/tests/dynamic_loading_template.rs @@ -20,20 +20,20 @@ impl TestLib { P: AsRef<::std::ffi::OsStr>, { let library = ::libloading::Library::new(path)?; - Ok(Self::from_library(library)) + Self::from_library(library) } - pub unsafe fn from_library(library: L) -> Self + pub unsafe fn from_library(library: L) -> Result where L: Into<::libloading::Library>, { let __library = library.into(); let foo = __library.get(b"foo\0").map(|sym| *sym); let foo1 = __library.get(b"foo1\0").map(|sym| *sym); - TestLib { + Ok(TestLib { __library, foo, foo1, - } + }) } pub unsafe fn foo( &self, diff --git a/tests/expectations/tests/dynamic_loading_with_allowlist.rs b/tests/expectations/tests/dynamic_loading_with_allowlist.rs index 678cd34013..83e4a5410c 100644 --- a/tests/expectations/tests/dynamic_loading_with_allowlist.rs +++ b/tests/expectations/tests/dynamic_loading_with_allowlist.rs @@ -34,9 +34,9 @@ impl TestLib { P: AsRef<::std::ffi::OsStr>, { let library = ::libloading::Library::new(path)?; - Ok(Self::from_library(library)) + Self::from_library(library) } - pub unsafe fn from_library(library: L) -> Self + pub unsafe fn from_library(library: L) -> Result where L: Into<::libloading::Library>, { @@ -44,12 +44,12 @@ impl TestLib { let foo = __library.get(b"foo\0").map(|sym| *sym); let baz = __library.get(b"baz\0").map(|sym| *sym); let bazz = __library.get(b"bazz\0").map(|sym| *sym); - TestLib { + Ok(TestLib { __library, foo, baz, bazz, - } + }) } pub unsafe fn foo( &self, diff --git a/tests/expectations/tests/dynamic_loading_with_blocklist.rs b/tests/expectations/tests/dynamic_loading_with_blocklist.rs index 930876a406..598780b295 100644 --- a/tests/expectations/tests/dynamic_loading_with_blocklist.rs +++ b/tests/expectations/tests/dynamic_loading_with_blocklist.rs @@ -78,20 +78,20 @@ impl TestLib { P: AsRef<::std::ffi::OsStr>, { let library = ::libloading::Library::new(path)?; - Ok(Self::from_library(library)) + Self::from_library(library) } - pub unsafe fn from_library(library: L) -> Self + pub unsafe fn from_library(library: L) -> Result where L: Into<::libloading::Library>, { let __library = library.into(); let foo = __library.get(b"foo\0").map(|sym| *sym); let bar = __library.get(b"bar\0").map(|sym| *sym); - TestLib { + Ok(TestLib { __library, foo, bar, - } + }) } pub unsafe fn foo( &self, diff --git a/tests/expectations/tests/dynamic_loading_with_class.rs b/tests/expectations/tests/dynamic_loading_with_class.rs index 81a045b520..ba0defaa51 100644 --- a/tests/expectations/tests/dynamic_loading_with_class.rs +++ b/tests/expectations/tests/dynamic_loading_with_class.rs @@ -73,20 +73,20 @@ impl TestLib { P: AsRef<::std::ffi::OsStr>, { let library = ::libloading::Library::new(path)?; - Ok(Self::from_library(library)) + Self::from_library(library) } - pub unsafe fn from_library(library: L) -> Self + pub unsafe fn from_library(library: L) -> Result where L: Into<::libloading::Library>, { let __library = library.into(); let foo = __library.get(b"foo\0").map(|sym| *sym); let bar = __library.get(b"bar\0").map(|sym| *sym); - TestLib { + Ok(TestLib { __library, foo, bar, - } + }) } pub unsafe fn foo( &self, diff --git a/tests/headers/dynamic_loading_required.h b/tests/headers/dynamic_loading_required.h new file mode 100644 index 0000000000..f9861e84eb --- /dev/null +++ b/tests/headers/dynamic_loading_required.h @@ -0,0 +1,5 @@ +// bindgen-flags: --dynamic-loading TestLib --dynamic-link-require-all + +int foo(int x, int y); +int bar(void *x); +int baz(); From 75eaaa6b61f896fe9fc788c4c21d27197c9ed2f6 Mon Sep 17 00:00:00 2001 From: "Dr. Chat" Date: Mon, 29 Mar 2021 11:17:38 -0500 Subject: [PATCH 164/942] Remove `DynamicItems::has_required` --- src/codegen/dyngen.rs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/codegen/dyngen.rs b/src/codegen/dyngen.rs index de9e0f988b..59b8b3ca03 100644 --- a/src/codegen/dyngen.rs +++ b/src/codegen/dyngen.rs @@ -5,11 +5,6 @@ use proc_macro2::Ident; /// Used to build the output tokens for dynamic bindings. #[derive(Default)] pub struct DynamicItems { - /// Tracks whether or not we contain any required symbols. - /// If so, the signature of the generated `from_library` function - /// will be altered to return a `Result` - has_required: bool, - /// Tracks the tokens that will appears inside the library struct -- e.g.: /// ```ignore /// struct Lib { @@ -136,8 +131,6 @@ impl DynamicItems { assert_eq!(args.len(), args_identifiers.len()); } - self.has_required |= is_required; - self.struct_members.push( if is_required { quote! { From c8c20a6c8bb759a162138673c809245821bcadf5 Mon Sep 17 00:00:00 2001 From: "Dr. Chat" Date: Mon, 29 Mar 2021 11:23:35 -0500 Subject: [PATCH 165/942] Deduplicate dyngen code --- src/codegen/dyngen.rs | 52 ++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/src/codegen/dyngen.rs b/src/codegen/dyngen.rs index 59b8b3ca03..f015234993 100644 --- a/src/codegen/dyngen.rs +++ b/src/codegen/dyngen.rs @@ -131,39 +131,41 @@ impl DynamicItems { assert_eq!(args.len(), args_identifiers.len()); } - self.struct_members.push( - if is_required { - quote! { - pub #ident: unsafe extern #abi fn ( #( #args),* ) #ret, - } - } else { - quote! { - pub #ident: Result, - } + let signature = quote! { unsafe extern #abi fn ( #( #args),* ) #ret }; + let member = if is_required { + signature + } else { + quote! { Result<#signature, ::libloading::Error> } + }; + + self.struct_members.push(quote! { + pub #ident: #member, + }); + + // N.B: If the signature was required, it won't be wrapped in a Result<...> + // and we can simply call it directly. + let call_body = if is_required { + quote! { + self.#ident(#( #args_identifiers ),*) + } + } else { + quote! { + let sym = self.#ident.as_ref().expect("Expected function, got error."); + (sym)(#( #args_identifiers ),*) } - ); + }; // We can't implement variadic functions from C easily, so we allow to // access the function pointer so that the user can call it just fine. if !is_variadic { - self.struct_implementation.push( - if is_required { - quote! { - pub unsafe fn #ident ( &self, #( #args ),* ) -> #ret_ty { - self.#ident(#( #args_identifiers ),*) - } - } - } else { - quote! { - pub unsafe fn #ident ( &self, #( #args ),* ) -> #ret_ty { - let sym = self.#ident.as_ref().expect("Expected function, got error."); - (sym)(#( #args_identifiers ),*) - } - } + self.struct_implementation.push(quote! { + pub unsafe fn #ident ( &self, #( #args ),* ) -> #ret_ty { + #call_body } - ); + }); } + // N.B: Unwrap the signature upon construction if it is required to be resolved. let ident_str = codegen::helpers::ast_ty::cstr_expr(ident.to_string()); self.constructor_inits.push(if is_required { quote! { From 2605da86c8cd7930f0c0d5f1025e33855a582bc0 Mon Sep 17 00:00:00 2001 From: "Dr. Chat" Date: Mon, 29 Mar 2021 11:26:11 -0500 Subject: [PATCH 166/942] remove old comment --- src/codegen/dyngen.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/codegen/dyngen.rs b/src/codegen/dyngen.rs index f015234993..5bb8747ceb 100644 --- a/src/codegen/dyngen.rs +++ b/src/codegen/dyngen.rs @@ -78,10 +78,6 @@ impl DynamicItems { let init_fields = &self.init_fields; let struct_implementation = &self.struct_implementation; - // FIXME: Is there a better way to lay this out? Conditional in the quote - // macro? - // If we have any required symbols, we must alter the signature of `from_library` - // so that it can return a failure code. quote! { extern crate libloading; From b21086cc3ba5aaeea53082e0618733a1b354daab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sat, 3 Apr 2021 12:30:43 +0200 Subject: [PATCH 167/942] codegen: Don't use a `sym` temporary in dynamic library code. Fixes #2014. --- src/codegen/dyngen.rs | 14 ++++++-------- .../expectations/tests/dynamic_loading_required.rs | 10 ++++++---- tests/expectations/tests/dynamic_loading_simple.rs | 13 ++++++------- .../expectations/tests/dynamic_loading_template.rs | 10 +++++----- .../tests/dynamic_loading_with_allowlist.rs | 10 +++++----- .../tests/dynamic_loading_with_blocklist.rs | 10 +++++----- .../tests/dynamic_loading_with_class.rs | 10 +++++----- 7 files changed, 38 insertions(+), 39 deletions(-) diff --git a/src/codegen/dyngen.rs b/src/codegen/dyngen.rs index 5bb8747ceb..71c4dab1dc 100644 --- a/src/codegen/dyngen.rs +++ b/src/codegen/dyngen.rs @@ -140,15 +140,13 @@ impl DynamicItems { // N.B: If the signature was required, it won't be wrapped in a Result<...> // and we can simply call it directly. - let call_body = if is_required { - quote! { - self.#ident(#( #args_identifiers ),*) - } + let fn_ = if is_required { + quote! { self.#ident } } else { - quote! { - let sym = self.#ident.as_ref().expect("Expected function, got error."); - (sym)(#( #args_identifiers ),*) - } + quote! { self.#ident.as_ref().expect("Expected function, got error.") } + }; + let call_body = quote! { + (#fn_)(#( #args_identifiers ),*) }; // We can't implement variadic functions from C easily, so we allow to diff --git a/tests/expectations/tests/dynamic_loading_required.rs b/tests/expectations/tests/dynamic_loading_required.rs index 3600eacef8..e46ffd49e0 100644 --- a/tests/expectations/tests/dynamic_loading_required.rs +++ b/tests/expectations/tests/dynamic_loading_required.rs @@ -25,7 +25,9 @@ impl TestLib { let library = ::libloading::Library::new(path)?; Self::from_library(library) } - pub unsafe fn from_library(library: L) -> Result + pub unsafe fn from_library( + library: L, + ) -> Result where L: Into<::libloading::Library>, { @@ -45,15 +47,15 @@ impl TestLib { x: ::std::os::raw::c_int, y: ::std::os::raw::c_int, ) -> ::std::os::raw::c_int { - self.foo(x, y) + (self.foo)(x, y) } pub unsafe fn bar( &self, x: *mut ::std::os::raw::c_void, ) -> ::std::os::raw::c_int { - self.bar(x) + (self.bar)(x) } pub unsafe fn baz(&self) -> ::std::os::raw::c_int { - self.baz() + (self.baz)() } } diff --git a/tests/expectations/tests/dynamic_loading_simple.rs b/tests/expectations/tests/dynamic_loading_simple.rs index 3d2e3d2cbc..cae5bd6937 100644 --- a/tests/expectations/tests/dynamic_loading_simple.rs +++ b/tests/expectations/tests/dynamic_loading_simple.rs @@ -34,7 +34,9 @@ impl TestLib { let library = ::libloading::Library::new(path)?; Self::from_library(library) } - pub unsafe fn from_library(library: L) -> Result + pub unsafe fn from_library( + library: L, + ) -> Result where L: Into<::libloading::Library>, { @@ -54,18 +56,15 @@ impl TestLib { x: ::std::os::raw::c_int, y: ::std::os::raw::c_int, ) -> ::std::os::raw::c_int { - let sym = self.foo.as_ref().expect("Expected function, got error."); - (sym)(x, y) + (self.foo.as_ref().expect("Expected function, got error."))(x, y) } pub unsafe fn bar( &self, x: *mut ::std::os::raw::c_void, ) -> ::std::os::raw::c_int { - let sym = self.bar.as_ref().expect("Expected function, got error."); - (sym)(x) + (self.bar.as_ref().expect("Expected function, got error."))(x) } pub unsafe fn baz(&self) -> ::std::os::raw::c_int { - let sym = self.baz.as_ref().expect("Expected function, got error."); - (sym)() + (self.baz.as_ref().expect("Expected function, got error."))() } } diff --git a/tests/expectations/tests/dynamic_loading_template.rs b/tests/expectations/tests/dynamic_loading_template.rs index de23143441..06e67ed791 100644 --- a/tests/expectations/tests/dynamic_loading_template.rs +++ b/tests/expectations/tests/dynamic_loading_template.rs @@ -22,7 +22,9 @@ impl TestLib { let library = ::libloading::Library::new(path)?; Self::from_library(library) } - pub unsafe fn from_library(library: L) -> Result + pub unsafe fn from_library( + library: L, + ) -> Result where L: Into<::libloading::Library>, { @@ -39,11 +41,9 @@ impl TestLib { &self, x: ::std::os::raw::c_int, ) -> ::std::os::raw::c_int { - let sym = self.foo.as_ref().expect("Expected function, got error."); - (sym)(x) + (self.foo.as_ref().expect("Expected function, got error."))(x) } pub unsafe fn foo1(&self, x: f32) -> f32 { - let sym = self.foo1.as_ref().expect("Expected function, got error."); - (sym)(x) + (self.foo1.as_ref().expect("Expected function, got error."))(x) } } diff --git a/tests/expectations/tests/dynamic_loading_with_allowlist.rs b/tests/expectations/tests/dynamic_loading_with_allowlist.rs index 83e4a5410c..97bb67abdc 100644 --- a/tests/expectations/tests/dynamic_loading_with_allowlist.rs +++ b/tests/expectations/tests/dynamic_loading_with_allowlist.rs @@ -36,7 +36,9 @@ impl TestLib { let library = ::libloading::Library::new(path)?; Self::from_library(library) } - pub unsafe fn from_library(library: L) -> Result + pub unsafe fn from_library( + library: L, + ) -> Result where L: Into<::libloading::Library>, { @@ -55,14 +57,12 @@ impl TestLib { &self, x: *mut ::std::os::raw::c_void, ) -> ::std::os::raw::c_int { - let sym = self.foo.as_ref().expect("Expected function, got error."); - (sym)(x) + (self.foo.as_ref().expect("Expected function, got error."))(x) } pub unsafe fn baz( &self, x: *mut ::std::os::raw::c_void, ) -> ::std::os::raw::c_int { - let sym = self.baz.as_ref().expect("Expected function, got error."); - (sym)(x) + (self.baz.as_ref().expect("Expected function, got error."))(x) } } diff --git a/tests/expectations/tests/dynamic_loading_with_blocklist.rs b/tests/expectations/tests/dynamic_loading_with_blocklist.rs index 598780b295..b06a6cf809 100644 --- a/tests/expectations/tests/dynamic_loading_with_blocklist.rs +++ b/tests/expectations/tests/dynamic_loading_with_blocklist.rs @@ -80,7 +80,9 @@ impl TestLib { let library = ::libloading::Library::new(path)?; Self::from_library(library) } - pub unsafe fn from_library(library: L) -> Result + pub unsafe fn from_library( + library: L, + ) -> Result where L: Into<::libloading::Library>, { @@ -97,14 +99,12 @@ impl TestLib { &self, x: *mut ::std::os::raw::c_void, ) -> ::std::os::raw::c_int { - let sym = self.foo.as_ref().expect("Expected function, got error."); - (sym)(x) + (self.foo.as_ref().expect("Expected function, got error."))(x) } pub unsafe fn bar( &self, x: *mut ::std::os::raw::c_void, ) -> ::std::os::raw::c_int { - let sym = self.bar.as_ref().expect("Expected function, got error."); - (sym)(x) + (self.bar.as_ref().expect("Expected function, got error."))(x) } } diff --git a/tests/expectations/tests/dynamic_loading_with_class.rs b/tests/expectations/tests/dynamic_loading_with_class.rs index ba0defaa51..8a66dc3f9a 100644 --- a/tests/expectations/tests/dynamic_loading_with_class.rs +++ b/tests/expectations/tests/dynamic_loading_with_class.rs @@ -75,7 +75,9 @@ impl TestLib { let library = ::libloading::Library::new(path)?; Self::from_library(library) } - pub unsafe fn from_library(library: L) -> Result + pub unsafe fn from_library( + library: L, + ) -> Result where L: Into<::libloading::Library>, { @@ -92,11 +94,9 @@ impl TestLib { &self, x: *mut ::std::os::raw::c_void, ) -> ::std::os::raw::c_int { - let sym = self.foo.as_ref().expect("Expected function, got error."); - (sym)(x) + (self.foo.as_ref().expect("Expected function, got error."))(x) } pub unsafe fn bar(&self) -> () { - let sym = self.bar.as_ref().expect("Expected function, got error."); - (sym)() + (self.bar.as_ref().expect("Expected function, got error."))() } } From 4faaf9a5f3962f1548824cb42fb8559dc6baac7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sat, 3 Apr 2021 12:57:19 +0200 Subject: [PATCH 168/942] codegen: Deal with overloads in method code generation. Fixes #2019 --- src/codegen/mod.rs | 99 ++++++++++++++++++-------- tests/expectations/tests/issue-2019.rs | 73 +++++++++++++++++++ tests/headers/issue-2019.hpp | 10 +++ 3 files changed, 151 insertions(+), 31 deletions(-) create mode 100644 tests/expectations/tests/issue-2019.rs create mode 100644 tests/headers/issue-2019.hpp diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 9516220477..e62b1a8701 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -422,37 +422,36 @@ trait CodeGenerator { /// Extra information from the caller. type Extra; + /// Extra information returned to the caller. + type Return; + fn codegen<'a>( &self, ctx: &BindgenContext, result: &mut CodegenResult<'a>, extra: &Self::Extra, - ); + ) -> Self::Return; } -impl CodeGenerator for Item { - type Extra = (); - - fn codegen<'a>( +impl Item { + fn process_before_codegen( &self, ctx: &BindgenContext, - result: &mut CodegenResult<'a>, - _extra: &(), - ) { + result: &mut CodegenResult, + ) -> bool { if !self.is_enabled_for_codegen(ctx) { - return; + return false; } if self.is_blocklisted(ctx) || result.seen(self.id()) { debug!( - "::codegen: Ignoring hidden or seen: \ + "::process_before_codegen: Ignoring hidden or seen: \ self = {:?}", self ); - return; + return false; } - debug!("::codegen: self = {:?}", self); if !ctx.codegen_items().contains(&self.id()) { // TODO(emilio, #453): Figure out what to do when this happens // legitimately, we could track the opaque stuff and disable the @@ -461,6 +460,24 @@ impl CodeGenerator for Item { } result.set_seen(self.id()); + true + } +} + +impl CodeGenerator for Item { + type Extra = (); + type Return = (); + + fn codegen<'a>( + &self, + ctx: &BindgenContext, + result: &mut CodegenResult<'a>, + _extra: &(), + ) { + debug!("::codegen: self = {:?}", self); + if !self.process_before_codegen(ctx, result) { + return; + } match *self.kind() { ItemKind::Module(ref module) => { @@ -481,6 +498,7 @@ impl CodeGenerator for Item { impl CodeGenerator for Module { type Extra = Item; + type Return = (); fn codegen<'a>( &self, @@ -572,6 +590,8 @@ impl CodeGenerator for Module { impl CodeGenerator for Var { type Extra = Item; + type Return = (); + fn codegen<'a>( &self, ctx: &BindgenContext, @@ -698,6 +718,7 @@ impl CodeGenerator for Var { impl CodeGenerator for Type { type Extra = Item; + type Return = (); fn codegen<'a>( &self, @@ -1004,6 +1025,7 @@ impl<'a> Vtable<'a> { impl<'a> CodeGenerator for Vtable<'a> { type Extra = Item; + type Return = (); fn codegen<'b>( &self, @@ -1048,6 +1070,7 @@ impl<'a> TryToRustTy for Vtable<'a> { impl CodeGenerator for TemplateInstantiation { type Extra = Item; + type Return = (); fn codegen<'a>( &self, @@ -1664,6 +1687,7 @@ impl<'a> FieldCodegen<'a> for Bitfield { impl CodeGenerator for CompInfo { type Extra = Item; + type Return = (); fn codegen<'a>( &self, @@ -2261,13 +2285,15 @@ impl MethodCodegen for Method { // First of all, output the actual function. let function_item = ctx.resolve_item(self.signature()); - if function_item.is_blocklisted(ctx) { - // We shouldn't emit a method declaration if the function is blocklisted + if !function_item.process_before_codegen(ctx, result) { return; } - function_item.codegen(ctx, result, &()); - let function = function_item.expect_function(); + let times_seen = function.codegen(ctx, result, &function_item); + let times_seen = match times_seen { + Some(seen) => seen, + None => return, + }; let signature_item = ctx.resolve_item(function.signature()); let mut name = match self.kind() { MethodKind::Constructor => "new".into(), @@ -2302,7 +2328,11 @@ impl MethodCodegen for Method { name.push_str(&count.to_string()); } - let function_name = ctx.rust_ident(function_item.canonical_name(ctx)); + let mut function_name = function_item.canonical_name(ctx); + if times_seen > 0 { + write!(&mut function_name, "{}", times_seen).unwrap(); + } + let function_name = ctx.rust_ident(function_name); let mut args = utils::fnsig_arguments(ctx, signature); let mut ret = utils::fnsig_return_ty(ctx, signature); @@ -2808,6 +2838,7 @@ impl<'a> EnumBuilder<'a> { impl CodeGenerator for Enum { type Extra = Item; + type Return = (); fn codegen<'a>( &self, @@ -3731,19 +3762,23 @@ impl TryToRustTy for FunctionSig { impl CodeGenerator for Function { type Extra = Item; + /// If we've actually generated the symbol, the number of times we've seen + /// it. + type Return = Option; + fn codegen<'a>( &self, ctx: &BindgenContext, result: &mut CodegenResult<'a>, item: &Item, - ) { + ) -> Self::Return { debug!("::codegen: item = {:?}", item); debug_assert!(item.is_enabled_for_codegen(ctx)); // We can't currently do anything with Internal functions so just // avoid generating anything for them. match self.linkage() { - Linkage::Internal => return, + Linkage::Internal => return None, Linkage::External => {} } @@ -3753,7 +3788,7 @@ impl CodeGenerator for Function { FunctionKind::Method(ref method_kind) if method_kind.is_pure_virtual() => { - return; + return None; } _ => {} } @@ -3763,7 +3798,7 @@ impl CodeGenerator for Function { // instantiations is open ended and we have no way of knowing which // monomorphizations actually exist. if !item.all_template_params(ctx).is_empty() { - return; + return None; } let name = self.name(); @@ -3776,7 +3811,7 @@ impl CodeGenerator for Function { // TODO: Maybe warn here if there's a type/argument mismatch, or // something? if result.seen_function(seen_symbol_name) { - return; + return None; } result.saw_function(seen_symbol_name); } @@ -3803,21 +3838,14 @@ impl CodeGenerator for Function { attributes.push(attributes::doc(comment)); } - // Handle overloaded functions by giving each overload its own unique - // suffix. - let times_seen = result.overload_number(&canonical_name); - if times_seen > 0 { - write!(&mut canonical_name, "{}", times_seen).unwrap(); - } - let abi = match signature.abi() { Abi::ThisCall if !ctx.options().rust_features().thiscall_abi => { warn!("Skipping function with thiscall ABI that isn't supported by the configured Rust target"); - return; + return None; } Abi::Win64 if signature.is_variadic() => { warn!("Skipping variadic function with Win64 ABI that isn't supported"); - return; + return None; } Abi::Unknown(unknown_abi) => { panic!( @@ -3828,6 +3856,13 @@ impl CodeGenerator for Function { abi => abi, }; + // Handle overloaded functions by giving each overload its own unique + // suffix. + let times_seen = result.overload_number(&canonical_name); + if times_seen > 0 { + write!(&mut canonical_name, "{}", times_seen).unwrap(); + } + let link_name = mangled_name.unwrap_or(name); if !utils::names_will_be_identical_after_mangling( &canonical_name, @@ -3878,6 +3913,7 @@ impl CodeGenerator for Function { } else { result.push(tokens); } + Some(times_seen) } } @@ -3933,6 +3969,7 @@ fn objc_method_codegen( impl CodeGenerator for ObjCInterface { type Extra = Item; + type Return = (); fn codegen<'a>( &self, diff --git a/tests/expectations/tests/issue-2019.rs b/tests/expectations/tests/issue-2019.rs new file mode 100644 index 0000000000..383bd57e15 --- /dev/null +++ b/tests/expectations/tests/issue-2019.rs @@ -0,0 +1,73 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct A { + pub a: ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout_A() { + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(A)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(A)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + 0usize, + concat!("Offset of field: ", stringify!(A), "::", stringify!(a)) + ); +} +extern "C" { + #[link_name = "\u{1}_ZN1A4makeEv"] + pub fn make() -> A; +} +impl A { + #[inline] + pub unsafe fn make() -> A { + make() + } +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct B { + pub b: ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout_B() { + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(B)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(B)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).b as *const _ as usize }, + 0usize, + concat!("Offset of field: ", stringify!(B), "::", stringify!(b)) + ); +} +extern "C" { + #[link_name = "\u{1}_ZN1B4makeEv"] + pub fn make1() -> B; +} +impl B { + #[inline] + pub unsafe fn make() -> B { + make1() + } +} diff --git a/tests/headers/issue-2019.hpp b/tests/headers/issue-2019.hpp new file mode 100644 index 0000000000..2e9a3ffd72 --- /dev/null +++ b/tests/headers/issue-2019.hpp @@ -0,0 +1,10 @@ +// bindgen-flags: --disable-nested-struct-naming + +struct A { + static A make(); + int a; +}; +struct B { + static B make(); + int b; +}; From d7ba7d1dcb081c3c853e3385fd4ef15cb6c1c22c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sat, 3 Apr 2021 13:14:56 +0200 Subject: [PATCH 169/942] v0.58.0 --- CHANGELOG.md | 169 +++++++++++++++++++++++++++++++-------------------- Cargo.lock | 4 +- Cargo.toml | 2 +- 3 files changed, 108 insertions(+), 67 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46607f5186..9418fcbf58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,116 +4,125 @@ - [Unreleased](#unreleased) - [Added](#added) + - [Fixed](#fixed) - [Changed](#changed) - [Deprecated](#deprecated) - [Removed](#removed) - - [Fixed](#fixed) - - [Security](#security) -- [0.57.0](#0570) -- [Added](#added-1) - [Fixed](#fixed-1) -- [0.56.0](#0560) - - [Added](#added-2) - - [Changed](#changed-1) + - [Security](#security) +- [0.58.0](#0580) + - [Added](#added-1) - [Fixed](#fixed-2) -- [0.55.1](#0551) - - [Fixed](#fixed-3) -- [0.55.0](#0550) + - [Changed](#changed-1) + - [Deprecated](#deprecated-1) - [Removed](#removed-1) + - [Fixed](#fixed-3) + - [Security](#security-1) +- [0.57.0](#0570) + - [Added](#added-2) + - [Fixed](#fixed-4) +- [0.56.0](#0560) - [Added](#added-3) - [Changed](#changed-2) - - [Fixed](#fixed-4) -- [0.54.1](#0541) + - [Fixed](#fixed-5) +- [0.55.1](#0551) + - [Fixed](#fixed-6) +- [0.55.0](#0550) + - [Removed](#removed-2) - [Added](#added-4) - [Changed](#changed-3) - - [Fixed](#fixed-5) -- [0.54.0](#0540) + - [Fixed](#fixed-7) +- [0.54.1](#0541) - [Added](#added-5) - [Changed](#changed-4) - - [Fixed](#fixed-6) -- [0.53.3](#0533) + - [Fixed](#fixed-8) +- [0.54.0](#0540) - [Added](#added-6) - - [Fixed](#fixed-7) -- [0.53.2](#0532) - [Changed](#changed-5) -- [0.53.1](#0531) + - [Fixed](#fixed-9) +- [0.53.3](#0533) - [Added](#added-7) -- [0.53.0](#0530) - - [Added](#added-8) + - [Fixed](#fixed-10) +- [0.53.2](#0532) - [Changed](#changed-6) - - [Fixed](#fixed-8) -- [0.52.0](#0520) +- [0.53.1](#0531) + - [Added](#added-8) +- [0.53.0](#0530) - [Added](#added-9) - [Changed](#changed-7) - - [Fixed](#fixed-9) -- [0.51.1](#0511) - - [Fixed](#fixed-10) - - [Changed](#changed-8) -- [0.51.0](#0510) - [Fixed](#fixed-11) - - [Changed](#changed-9) +- [0.52.0](#0520) - [Added](#added-10) -- [0.50.0](#0500) + - [Changed](#changed-8) + - [Fixed](#fixed-12) +- [0.51.1](#0511) + - [Fixed](#fixed-13) + - [Changed](#changed-9) +- [0.51.0](#0510) + - [Fixed](#fixed-14) + - [Changed](#changed-10) - [Added](#added-11) -- [0.49.3](#0493) +- [0.50.0](#0500) - [Added](#added-12) +- [0.49.3](#0493) + - [Added](#added-13) - [0.49.2](#0492) - - [Changed](#changed-10) -- [0.49.1](#0491) - - [Fixed](#fixed-12) - [Changed](#changed-11) -- [0.49.0](#0490) - - [Added](#added-13) - - [Fixed](#fixed-13) +- [0.49.1](#0491) + - [Fixed](#fixed-15) - [Changed](#changed-12) +- [0.49.0](#0490) + - [Added](#added-14) + - [Fixed](#fixed-16) + - [Changed](#changed-13) - [0.48.1](#0481) - - [Fixed](#fixed-14) + - [Fixed](#fixed-17) - [0.48.0](#0480) - - [Changed](#changed-13) - - [Fixed](#fixed-15) + - [Changed](#changed-14) + - [Fixed](#fixed-18) - [0.47.4](#0474) - - [Added](#added-14) + - [Added](#added-15) - [0.47.3](#0473) - - [Changed](#changed-14) + - [Changed](#changed-15) - [0.47.2](#0472) - - [Fixed](#fixed-16) + - [Fixed](#fixed-19) - [0.47.1](#0471) - - [Changed](#changed-15) - - [Fixed](#fixed-17) -- [0.47.0](#0470) - [Changed](#changed-16) - - [Fixed](#fixed-18) -- [0.33.1 .. 0.46.0](#0331--0460) - - [Added](#added-15) - - [Removed](#removed-2) + - [Fixed](#fixed-20) +- [0.47.0](#0470) - [Changed](#changed-17) - - [Fixed](#fixed-19) + - [Fixed](#fixed-21) +- [0.33.1 .. 0.46.0](#0331--0460) + - [Added](#added-16) + - [Removed](#removed-3) + - [Changed](#changed-18) + - [Fixed](#fixed-22) - [0.33.1](#0331) - - [Fixed](#fixed-20) + - [Fixed](#fixed-23) - [0.33.0](#0330) - [0.32.2](#0322) - - [Fixed](#fixed-21) + - [Fixed](#fixed-24) - [0.32.1](#0321) - - [Fixed](#fixed-22) + - [Fixed](#fixed-25) - [0.32.0](#0320) - - [Added](#added-16) - - [Changed](#changed-18) - - [Fixed](#fixed-23) -- [0.31.0](#0310) - [Added](#added-17) - [Changed](#changed-19) - - [Deprecated](#deprecated-1) - - [Removed](#removed-3) - - [Fixed](#fixed-24) -- [0.30.0](#0300) + - [Fixed](#fixed-26) +- [0.31.0](#0310) - [Added](#added-18) - [Changed](#changed-20) - [Deprecated](#deprecated-2) - - [Fixed](#fixed-25) -- [0.29.0](#0290) + - [Removed](#removed-4) + - [Fixed](#fixed-27) +- [0.30.0](#0300) - [Added](#added-19) - [Changed](#changed-21) - - [Fixed](#fixed-26) + - [Deprecated](#deprecated-3) + - [Fixed](#fixed-28) +- [0.29.0](#0290) + - [Added](#added-20) + - [Changed](#changed-22) + - [Fixed](#fixed-29) @@ -123,6 +132,36 @@ ## Added +## Fixed + +## Changed + +## Deprecated + +## Removed + +## Fixed + +## Security + +# 0.58.0 + +Released 2021/03/04 + +## Added + + * Add option to translate enum integer types to native Rust integer types. + [#2004][] + * Add callback to check derives for blocklisted types. [#2007][] + * Add a flag to ensure all symbols are resolved when a library is loaded. + [#2013][] + * Add from_library for generated dynamic library structs [#2011][]. + +## Fixed + + * Track union layout more accurately. [#1984][] + * Use original name when checking allowlist for anonymous enum variants. [#2006][] + ## Changed ## Deprecated diff --git a/Cargo.lock b/Cargo.lock index d846452ecd..e7c273ebbf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,7 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "aho-corasick" version = "0.7.15" @@ -31,7 +33,7 @@ dependencies = [ [[package]] name = "bindgen" -version = "0.57.0" +version = "0.58.0" dependencies = [ "bitflags", "cexpr", diff --git a/Cargo.toml b/Cargo.toml index 59cc2ad602..4215c9598d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ readme = "README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.57.0" +version = "0.58.0" edition = "2018" build = "build.rs" From b5e6eb1cb2ce8566ae297a226581d6f1ec12f001 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sat, 3 Apr 2021 13:18:27 +0200 Subject: [PATCH 170/942] Reference aarch64 issue in the changelog. --- CHANGELOG.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9418fcbf58..59cc440f93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -159,7 +159,8 @@ Released 2021/03/04 ## Fixed - * Track union layout more accurately. [#1984][] + * Track union layout more accurately. Fixes [an AArch64 bug] and [makes the + bindings more portable] where unions could return garbage data ([#1984]) * Use original name when checking allowlist for anonymous enum variants. [#2006][] ## Changed @@ -202,6 +203,10 @@ Released 2021/03/04 * `--blacklist-item` is deprecated in favor of `--blocklist-item`. [#1812][] +[#1984]: https://github.com/rust-lang/rust-bindgen/pull/1984 +[an AArch64 bug]: https://github.com/rust-lang/rust-bindgen/issues/1973 +[makes the bindings more portable]: https://github.com/rust-lang/rust-bindgen/issues/1983 + ## Removed ## Fixed From 89baa2cf04bf7b4d87f88090a6947729ffae6698 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sun, 4 Apr 2021 09:38:33 -0400 Subject: [PATCH 171/942] Fix 0.58.0 release date --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 59cc440f93..a0f3b18de8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -146,7 +146,7 @@ # 0.58.0 -Released 2021/03/04 +Released 2021/04/03 ## Added From bf61569d30b368e50cb43e12b8efbff573a8c01e Mon Sep 17 00:00:00 2001 From: Ryan Zoeller Date: Mon, 5 Apr 2021 22:03:31 -0500 Subject: [PATCH 172/942] Document clang installation method on Fedora --- book/src/requirements.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/book/src/requirements.md b/book/src/requirements.md index 921b6044f1..9ccaea94ac 100644 --- a/book/src/requirements.md +++ b/book/src/requirements.md @@ -63,6 +63,12 @@ repos to get version 3.9. See http://apt.llvm.org/. # pacman -S clang ``` +#### Fedora + +```bash +# dnf install clang-devel +``` + #### OpenBSD ```bash From af2c8b8430f3fd3608c68d573e5c6d53bc1a399f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 6 Apr 2021 11:15:08 +0200 Subject: [PATCH 173/942] Re-introduce whitelist_recursively (with deprecation notice) Seems like an oversight from #1990. Fixes #2022. --- src/lib.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 0c207a2f0d..85d555992e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -696,6 +696,12 @@ impl Builder { self } + /// Deprecated alias for allowlist_recursively. + #[deprecated(note = "Use allowlist_recursively instead")] + pub fn whitelist_recursively(self, doit: bool) -> Self { + self.allowlist_recursively(doit) + } + /// Generate `#[macro_use] extern crate objc;` instead of `use objc;` /// in the prologue of the files generated from objective-c files pub fn objc_extern_crate(mut self, doit: bool) -> Self { From 696455d1c15e682b2b89f81f409315ea4964aef3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 6 Apr 2021 11:18:15 +0200 Subject: [PATCH 174/942] v0.58.1 --- CHANGELOG.md | 10 ++++++++++ Cargo.lock | 2 +- Cargo.toml | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a0f3b18de8..892a864fb2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -144,6 +144,16 @@ ## Security +# 0.58.1 + +Released 2021/04/06 + +## Added + + * Re-introduced unintentionally removed + `bindgen::Builder::whitelist_recursively` (deprecated in favor of + `bindgen::Builder::allowlist_recursively`). [#2022][] + # 0.58.0 Released 2021/04/03 diff --git a/Cargo.lock b/Cargo.lock index e7c273ebbf..7fc4535463 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -33,7 +33,7 @@ dependencies = [ [[package]] name = "bindgen" -version = "0.58.0" +version = "0.58.1" dependencies = [ "bitflags", "cexpr", diff --git a/Cargo.toml b/Cargo.toml index 4215c9598d..dd30f09ceb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ readme = "README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.58.0" +version = "0.58.1" edition = "2018" build = "build.rs" From d0d0726615e1891a66282e77d2b1daba072570cf Mon Sep 17 00:00:00 2001 From: Nico Chatzi Date: Sat, 10 Apr 2021 17:26:07 +0100 Subject: [PATCH 175/942] Fix docstring comment for constants --- src/codegen/mod.rs | 13 +++++++-- tests/expectations/tests/issue-1995.rs | 37 ++++++++++++++++++++++++++ tests/headers/issue-1995.h | 12 +++++++++ 3 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 tests/expectations/tests/issue-1995.rs create mode 100644 tests/headers/issue-1995.h diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index e62b1a8701..e498d2b26b 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -618,12 +618,18 @@ impl CodeGenerator for Var { return; } + let mut attrs = vec![]; + if let Some(comment) = item.comment(ctx) { + attrs.push(attributes::doc(comment)); + } + let ty = self.ty().to_rust_ty_or_opaque(ctx, &()); if let Some(val) = self.val() { match *val { VarType::Bool(val) => { result.push(quote! { + #(#attrs)* pub const #canonical_ident : #ty = #val ; }); } @@ -643,6 +649,7 @@ impl CodeGenerator for Var { helpers::ast_ty::uint_expr(val as _) }; result.push(quote! { + #(#attrs)* pub const #canonical_ident : #ty = #val ; }); } @@ -660,12 +667,14 @@ impl CodeGenerator for Var { Ok(string) => { let cstr = helpers::ast_ty::cstr_expr(string); result.push(quote! { + #(#attrs)* pub const #canonical_ident : &'static #ty = #cstr ; }); } Err(..) => { let bytes = helpers::ast_ty::byte_array_expr(bytes); result.push(quote! { + #(#attrs)* pub const #canonical_ident : #ty = #bytes ; }); } @@ -674,6 +683,7 @@ impl CodeGenerator for Var { VarType::Float(f) => { match helpers::ast_ty::float_expr(ctx, f) { Ok(expr) => result.push(quote! { + #(#attrs)* pub const #canonical_ident : #ty = #expr ; }), Err(..) => return, @@ -681,13 +691,12 @@ impl CodeGenerator for Var { } VarType::Char(c) => { result.push(quote! { + #(#attrs)* pub const #canonical_ident : #ty = #c ; }); } } } else { - let mut attrs = vec![]; - // If necessary, apply a `#[link_name]` attribute let link_name = self.mangled_name().unwrap_or(self.name()); if !utils::names_will_be_identical_after_mangling( diff --git a/tests/expectations/tests/issue-1995.rs b/tests/expectations/tests/issue-1995.rs new file mode 100644 index 0000000000..58e11eb297 --- /dev/null +++ b/tests/expectations/tests/issue-1995.rs @@ -0,0 +1,37 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +/// This is a constant that has a docstring +/// +/// And expected to be found in generated bindings code too. +pub const FOO: ::std::os::raw::c_int = 1; +/// This is a constant that has a docstring +/// +/// And expected to be found in generated bindings code too. +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Bar { + pub baz: ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout_Bar() { + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Bar)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Bar)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).baz as *const _ as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz)) + ); +} diff --git a/tests/headers/issue-1995.h b/tests/headers/issue-1995.h new file mode 100644 index 0000000000..619f673540 --- /dev/null +++ b/tests/headers/issue-1995.h @@ -0,0 +1,12 @@ +/// This is a constant that has a docstring +/// +/// And expected to be found in generated bindings code too. +const int FOO = 1; + +/// This is a constant that has a docstring +/// +/// And expected to be found in generated bindings code too. +struct Bar +{ + int baz; +}; \ No newline at end of file From c39c47c2e5a3839ab57dec0d585b7e6af60416f6 Mon Sep 17 00:00:00 2001 From: Thomas Vermeilh Date: Wed, 14 Apr 2021 15:17:02 +0200 Subject: [PATCH 176/942] Add env var EXTRA_CLANG_ARGS_ Closes #2009 --- README.md | 4 ++++ build.rs | 8 ++++++++ src/lib.rs | 17 ++++++++++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e1ad557e97..60e064ffb0 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,10 @@ End-users should set these environment variables to modify `bindgen`'s behavior - Examples: - Specify alternate sysroot: `--sysroot=/path/to/sysroot` - Add include search path with spaces: `-I"/path/with spaces"` +- `BINDGEN_EXTRA_CLANG_ARGS_`: similar to `BINDGEN_EXTRA_CLANG_ARGS`, + but used to set per-target arguments to pass to clang. Useful to set system include + directories in a target-specific way in cross-compilation environments with multiple targets. + Has precedence over `BINDGEN_EXTRA_CLANG_ARGS`. Additionally, `bindgen` uses `libclang` to parse C and C++ header files. To modify how `bindgen` searches for `libclang`, see the [`clang-sys` documentation][clang-sys-env]. diff --git a/build.rs b/build.rs index cb40cb0c1f..fcc0bb2217 100644 --- a/build.rs +++ b/build.rs @@ -79,4 +79,12 @@ fn main() { println!("cargo:rerun-if-env-changed=LIBCLANG_PATH"); println!("cargo:rerun-if-env-changed=LIBCLANG_STATIC_PATH"); println!("cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS"); + println!( + "cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_{}", + std::env::var("TARGET").unwrap() + ); + println!( + "cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_{}", + std::env::var("TARGET").unwrap().replace("-", "_") + ); } diff --git a/src/lib.rs b/src/lib.rs index 85d555992e..418811e3da 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1405,7 +1405,7 @@ impl Builder { pub fn generate(mut self) -> Result { // Add any extra arguments from the environment to the clang command line. if let Some(extra_clang_args) = - env::var("BINDGEN_EXTRA_CLANG_ARGS").ok() + get_target_dependent_env_var("BINDGEN_EXTRA_CLANG_ARGS") { // Try to parse it with shell quoting. If we fail, make it one single big argument. if let Some(strings) = shlex::split(&extra_clang_args) { @@ -2557,6 +2557,21 @@ pub fn clang_version() -> ClangVersion { } } +/// Looks for the env var `var_${TARGET}`, and falls back to just `var` when it is not found. +fn get_target_dependent_env_var(var: &str) -> Option { + if let Ok(target) = env::var("TARGET") { + if let Ok(v) = env::var(&format!("{}_{}", var, target)) { + return Some(v); + } + if let Ok(v) = + env::var(&format!("{}_{}", var, target.replace("-", "_"))) + { + return Some(v); + } + } + env::var(var).ok() +} + /// A ParseCallbacks implementation that will act on file includes by echoing a rerun-if-changed /// line /// From 1bb548b7a7c482e9851af9864a9736faee48a10b Mon Sep 17 00:00:00 2001 From: Adam Perry Date: Thu, 8 Apr 2021 17:26:55 +0000 Subject: [PATCH 177/942] Support emitting Makefile-syntax depfiles like gcc/clang/rustc. Needed to auto-bindgen with a ninja build without the build graph going stale. --- Cargo.lock | 96 ++++++++++++++++++++ Cargo.toml | 1 + src/codegen/mod.rs | 10 ++ src/deps.rs | 20 ++++ src/ir/context.rs | 26 +++++- src/ir/item.rs | 4 +- src/lib.rs | 34 ++++++- src/options.rs | 10 ++ tests/expectations/tests/enum-default-rust.d | 1 + tests/tests.rs | 26 ++++++ 10 files changed, 219 insertions(+), 9 deletions(-) create mode 100644 src/deps.rs create mode 100644 tests/expectations/tests/enum-default-rust.d diff --git a/Cargo.lock b/Cargo.lock index 7fc4535463..443201eedc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -50,6 +50,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", + "tempfile", "which", ] @@ -125,6 +126,17 @@ dependencies = [ "termcolor", ] +[[package]] +name = "getrandom" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "wasi", +] + [[package]] name = "glob" version = "0.3.0" @@ -205,6 +217,12 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" +[[package]] +name = "ppv-lite86" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" + [[package]] name = "proc-macro2" version = "1.0.24" @@ -223,6 +241,55 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rand" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", + "rand_hc", +] + +[[package]] +name = "rand_chacha" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rand_hc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73" +dependencies = [ + "rand_core", +] + +[[package]] +name = "redox_syscall" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94341e4e44e24f6b591b59e47a8a027df12e008d73fd5672dbea9cc22f4507d9" +dependencies = [ + "bitflags", +] + [[package]] name = "regex" version = "1.4.2" @@ -241,6 +308,15 @@ version = "0.6.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b181ba2dcf07aaccad5448e8ead58db5b742cf85dfe035e2227f137a539a189" +[[package]] +name = "remove_dir_all" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" +dependencies = [ + "winapi", +] + [[package]] name = "rustc-hash" version = "1.1.0" @@ -259,6 +335,20 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" +[[package]] +name = "tempfile" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "rand", + "redox_syscall", + "remove_dir_all", + "winapi", +] + [[package]] name = "termcolor" version = "1.1.0" @@ -310,6 +400,12 @@ version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" +[[package]] +name = "wasi" +version = "0.10.2+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" + [[package]] name = "which" version = "3.1.1" diff --git a/Cargo.toml b/Cargo.toml index dd30f09ceb..6140407840 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,6 +43,7 @@ required-features = ["clap"] diff = "0.1" clap = "2" shlex = "1" +tempfile = "3" [dependencies] bitflags = "1.0.3" diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index e498d2b26b..1a702b00f7 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -4207,6 +4207,16 @@ pub(crate) fn codegen( } } + if let Some(spec) = context.options().depfile.as_ref() { + match spec.write(context.deps()) { + Ok(()) => info!( + "Your depfile was generated successfully into: {}", + spec.depfile_path.display() + ), + Err(e) => warn!("{}", e), + } + } + context.resolve_item(context.root_module()).codegen( context, &mut result, diff --git a/src/deps.rs b/src/deps.rs new file mode 100644 index 0000000000..479c396cbb --- /dev/null +++ b/src/deps.rs @@ -0,0 +1,20 @@ +/// Generating build depfiles from parsed bindings. +use std::{collections::BTreeSet, path::PathBuf}; + +#[derive(Debug)] +pub(crate) struct DepfileSpec { + pub output_module: String, + pub depfile_path: PathBuf, +} + +impl DepfileSpec { + pub fn write(&self, deps: &BTreeSet) -> std::io::Result<()> { + let mut buf = format!("{}:", self.output_module); + + for file in deps { + buf = format!("{} {}", buf, file); + } + + std::fs::write(&self.depfile_path, &buf) + } +} diff --git a/src/ir/context.rs b/src/ir/context.rs index ccb05e7565..2b8acc36f0 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -29,7 +29,7 @@ use clang_sys; use proc_macro2::{Ident, Span}; use std::borrow::Cow; use std::cell::{Cell, RefCell}; -use std::collections::HashMap as StdHashMap; +use std::collections::{BTreeSet, HashMap as StdHashMap}; use std::iter::IntoIterator; use std::mem; @@ -354,6 +354,9 @@ pub struct BindgenContext { /// This needs to be an std::HashMap because the cexpr API requires it. parsed_macros: StdHashMap, cexpr::expr::EvalResult>, + /// A set of all the included filenames. + deps: BTreeSet, + /// The active replacements collected from replaces="xxx" annotations. replacements: HashMap, ItemId>, @@ -545,8 +548,16 @@ If you encounter an error missing from this list, please file an issue or a PR!" let root_module = Self::build_root_module(ItemId(0)); let root_module_id = root_module.id().as_module_id_unchecked(); + // depfiles need to include the explicitly listed headers too + let mut deps = BTreeSet::default(); + if let Some(filename) = &options.input_header { + deps.insert(filename.clone()); + } + deps.extend(options.extra_input_headers.iter().cloned()); + BindgenContext { items: vec![Some(root_module)], + deps, types: Default::default(), type_params: Default::default(), modules: Default::default(), @@ -632,6 +643,19 @@ If you encounter an error missing from this list, please file an issue or a PR!" self.options().parse_callbacks.as_ref().map(|t| &**t) } + /// Add another path to the set of included files. + pub fn include_file(&mut self, filename: String) { + if let Some(cbs) = self.parse_callbacks() { + cbs.include_file(&filename); + } + self.deps.insert(filename); + } + + /// Get any included files. + pub fn deps(&self) -> &BTreeSet { + &self.deps + } + /// Define a new item. /// /// This inserts it into the internal items set, and its type into the diff --git a/src/ir/item.rs b/src/ir/item.rs index 45415045fe..d7c92ab444 100644 --- a/src/ir/item.rs +++ b/src/ir/item.rs @@ -1415,9 +1415,7 @@ impl ClangItemParser for Item { ); } Some(filename) => { - if let Some(cb) = ctx.parse_callbacks() { - cb.include_file(&filename) - } + ctx.include_file(filename); } } } diff --git a/src/lib.rs b/src/lib.rs index 418811e3da..58c99c8dec 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -51,6 +51,7 @@ macro_rules! doc_mod { mod clang; mod codegen; +mod deps; mod features; mod ir; mod parse; @@ -604,6 +605,19 @@ impl Builder { self } + /// Add a depfile output which will be written alongside the generated bindings. + pub fn depfile, D: Into>( + mut self, + output_module: H, + depfile: D, + ) -> Builder { + self.options.depfile = Some(deps::DepfileSpec { + output_module: output_module.into(), + depfile_path: depfile.into(), + }); + self + } + /// Add `contents` as an input C/C++ header named `name`. /// /// The file `name` will be added to the clang arguments. @@ -1417,11 +1431,13 @@ impl Builder { // Transform input headers to arguments on the clang command line. self.options.input_header = self.input_headers.pop(); - self.options - .clang_args - .extend(self.input_headers.drain(..).flat_map(|header| { - iter::once("-include".into()).chain(iter::once(header)) - })); + self.options.extra_input_headers = self.input_headers; + self.options.clang_args.extend( + self.options.extra_input_headers.iter().flat_map(|header| { + iter::once("-include".into()) + .chain(iter::once(header.to_string())) + }), + ); self.options.input_unsaved_files.extend( self.input_header_contents @@ -1624,6 +1640,9 @@ struct BindgenOptions { /// The explicit rustfmt path. rustfmt_path: Option, + /// The path to which we should write a Makefile-syntax depfile (if any). + depfile: Option, + /// The set of types that we should have bindings for in the generated /// code. /// @@ -1785,6 +1804,9 @@ struct BindgenOptions { /// The input header file. input_header: Option, + /// Any additional input header files. + extra_input_headers: Vec, + /// Unsaved files for input. input_unsaved_files: Vec, @@ -1963,6 +1985,7 @@ impl Default for BindgenOptions { blocklisted_items: Default::default(), opaque_types: Default::default(), rustfmt_path: Default::default(), + depfile: Default::default(), allowlisted_types: Default::default(), allowlisted_functions: Default::default(), allowlisted_vars: Default::default(), @@ -2008,6 +2031,7 @@ impl Default for BindgenOptions { module_lines: HashMap::default(), clang_args: vec![], input_header: None, + extra_input_headers: vec![], input_unsaved_files: vec![], parse_callbacks: None, codegen_config: CodegenConfig::all(), diff --git a/src/options.rs b/src/options.rs index 3626732108..ff2d42827e 100644 --- a/src/options.rs +++ b/src/options.rs @@ -30,6 +30,10 @@ where Arg::with_name("header") .help("C or C++ header file") .required(true), + Arg::with_name("depfile") + .long("depfile") + .takes_value(true) + .help("Path to write depfile to"), Arg::with_name("default-enum-style") .long("default-enum-style") .help("The default style of code used to generate enums.") @@ -848,8 +852,14 @@ where let output = if let Some(path) = matches.value_of("output") { let file = File::create(path)?; + if let Some(depfile) = matches.value_of("depfile") { + builder = builder.depfile(path, depfile); + } Box::new(io::BufWriter::new(file)) as Box } else { + if let Some(depfile) = matches.value_of("depfile") { + builder = builder.depfile("-", depfile); + } Box::new(io::BufWriter::new(io::stdout())) as Box }; diff --git a/tests/expectations/tests/enum-default-rust.d b/tests/expectations/tests/enum-default-rust.d new file mode 100644 index 0000000000..a6540005c9 --- /dev/null +++ b/tests/expectations/tests/enum-default-rust.d @@ -0,0 +1 @@ +tests/expectations/tests/enum-default-rust.rs: tests/headers/enum-default-rust.h tests/headers/enum.h diff --git a/tests/tests.rs b/tests/tests.rs index 80ccc8c9eb..ced4854027 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -578,6 +578,32 @@ fn no_system_header_includes() { .success()); } +#[test] +fn emit_depfile() { + let header = PathBuf::from("tests/headers/enum-default-rust.h"); + let expected_depfile = PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join("tests") + .join("expectations") + .join("tests") + .join("enum-default-rust.d"); + let observed_depfile = tempfile::NamedTempFile::new().unwrap(); + let mut builder = create_bindgen_builder(&header).unwrap(); + builder.builder = builder.builder.depfile( + "tests/expectations/tests/enum-default-rust.rs", + observed_depfile.path(), + ); + + let check_roundtrip = + env::var_os("BINDGEN_DISABLE_ROUNDTRIP_TEST").is_none(); + let (builder, _roundtrip_builder) = + builder.into_builder(check_roundtrip).unwrap(); + let _bindings = builder.generate().unwrap(); + + let observed = std::fs::read_to_string(observed_depfile).unwrap(); + let expected = std::fs::read_to_string(expected_depfile).unwrap(); + assert_eq!(observed.trim(), expected.trim()); +} + #[test] fn dump_preprocessed_input() { let arg_keyword = From 2cfc64e023bb11f05829c094df887ed29f42332e Mon Sep 17 00:00:00 2001 From: Adam Perry Date: Fri, 23 Apr 2021 20:47:10 +0000 Subject: [PATCH 178/942] Integration test include directory paths for depfiles. --- bindgen-integration/build.rs | 23 +++++++++++++++++------ bindgen-integration/cpp/Test.h | 2 ++ bindgen-integration/include/stub.h | 0 3 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 bindgen-integration/include/stub.h diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs index f055f31f0d..b28dcee577 100644 --- a/bindgen-integration/build.rs +++ b/bindgen-integration/build.rs @@ -140,10 +140,16 @@ fn main() { cc::Build::new() .cpp(true) .file("cpp/Test.cc") + .include("include") .compile("libtest.a"); let macros = Arc::new(RwLock::new(HashSet::new())); + let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); + let out_rust_file = out_path.join("test.rs"); + let out_rust_file_relative = out_rust_file.strip_prefix(std::env::current_dir().unwrap()).unwrap(); + let out_dep_file = out_path.join("test.d"); + let bindings = Builder::default() .rustfmt_bindings(false) .enable_cxx_namespaces() @@ -154,7 +160,7 @@ fn main() { .raw_line("extern { fn my_prefixed_function_to_remove(i: i32); }") .module_raw_line("root::testing", "pub type Bar = i32;") .header("cpp/Test.h") - .clang_args(&["-x", "c++", "-std=c++11"]) + .clang_args(&["-x", "c++", "-std=c++11", "-I", "include"]) .parse_callbacks(Box::new(MacroCallback { macros: macros.clone(), seen_hellos: Mutex::new(0), @@ -163,13 +169,18 @@ fn main() { .blocklist_function("my_prefixed_function_to_remove") .constified_enum("my_prefixed_enum_to_be_constified") .opaque_type("my_prefixed_templated_foo") + .depfile(out_rust_file_relative.display().to_string(), &out_dep_file) .generate() .expect("Unable to generate bindings"); assert!(macros.read().unwrap().contains("TESTMACRO")); - - let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); - bindings - .write_to_file(out_path.join("test.rs")) - .expect("Couldn't write bindings!"); + bindings.write_to_file(&out_rust_file).expect("Couldn't write bindings!"); + + let observed_deps = std::fs::read_to_string(out_dep_file).expect("Couldn't read depfile!"); + let expected_deps = format!("{}: cpp/Test.h include/stub.h", out_rust_file_relative.display()); + assert_eq!( + observed_deps, + expected_deps, + "including stub via include dir must produce correct dep path", + ); } diff --git a/bindgen-integration/cpp/Test.h b/bindgen-integration/cpp/Test.h index 51a6e4b87f..ad71b0f672 100644 --- a/bindgen-integration/cpp/Test.h +++ b/bindgen-integration/cpp/Test.h @@ -1,3 +1,5 @@ +#include "stub.h" // this bad path is made valid by a `-I include` clang arg + #pragma once #define TESTMACRO diff --git a/bindgen-integration/include/stub.h b/bindgen-integration/include/stub.h new file mode 100644 index 0000000000..e69de29bb2 From 731c393be75cb472672fa55158bf97b9a9f18d89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 26 Apr 2021 22:26:02 +0200 Subject: [PATCH 179/942] Print with_id in debug log from builtin_or_resolved_ty. This makes debugging #2039 a bit easier. --- src/ir/context.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ir/context.rs b/src/ir/context.rs index 2b8acc36f0..4faf6cd123 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -1832,8 +1832,8 @@ If you encounter an error missing from this list, please file an issue or a PR!" ) -> Option { use clang_sys::{CXCursor_TypeAliasTemplateDecl, CXCursor_TypeRef}; debug!( - "builtin_or_resolved_ty: {:?}, {:?}, {:?}", - ty, location, parent_id + "builtin_or_resolved_ty: {:?}, {:?}, {:?}, {:?}", + ty, location, with_id, parent_id ); if let Some(decl) = ty.canonical_declaration(location.as_ref()) { From 91ec529f54398e3fc457b6f1a1ba4c1cf928cf9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 26 Apr 2021 22:31:30 +0200 Subject: [PATCH 180/942] Unblock CI for now. --- .github/workflows/bindgen.yml | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 8f1dabd797..91efe985c6 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -126,16 +126,20 @@ jobs: feature_extra_asserts: 1 feature_testing_only_docs: 1 - - os: ubuntu-latest - target: - debian: arm64 - cross: aarch64-linux-gnu - rust: aarch64-unknown-linux-gnu - llvm_version: "9.0" - main_tests: 0 - release_build: 0 - feature_extra_asserts: 0 - feature_testing_only_docs: 0 + # FIXME: Seems installing multiarch packages fails: + # + # https://github.com/rust-lang/rust-bindgen/pull/2037/checks?check_run_id=2441799333 + # + # - os: ubuntu-latest + # target: + # debian: arm64 + # cross: aarch64-linux-gnu + # rust: aarch64-unknown-linux-gnu + # llvm_version: "9.0" + # main_tests: 0 + # release_build: 0 + # feature_extra_asserts: 0 + # feature_testing_only_docs: 0 # Ensure stuff works on macos too - os: macos-latest From f597e2777355e358a8f2c5a96d98326f3bf624d9 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 23 Apr 2021 14:40:26 -0700 Subject: [PATCH 181/942] Translate types that were declared inside functions as opaque types. This fixes a panic with the following header: template struct Foo {}; template Foo foo{}; void f() { struct Bar { Bar() {} }; foo; } Because we don't parse the insides of function bodies, code like this could cause us to parse a type (here, `Bar`) that we didn't see in our initial pass, which can cause subtle problems. Closes #2036. --- src/ir/function.rs | 4 +- src/ir/item.rs | 12 +++ ...mplate_instantiation_with_fn_local_type.rs | 60 ++++++++++++ ...mplate_instantiation_with_fn_local_type.rs | 96 +++++++++++++++++++ ...plate_instantiation_with_fn_local_type.hpp | 27 ++++++ 5 files changed, 198 insertions(+), 1 deletion(-) create mode 100644 tests/expectations/tests/libclang-3.9/template_instantiation_with_fn_local_type.rs create mode 100644 tests/expectations/tests/template_instantiation_with_fn_local_type.rs create mode 100644 tests/headers/template_instantiation_with_fn_local_type.hpp diff --git a/src/ir/function.rs b/src/ir/function.rs index a6f63a640e..c0938b653d 100644 --- a/src/ir/function.rs +++ b/src/ir/function.rs @@ -28,7 +28,9 @@ pub enum FunctionKind { } impl FunctionKind { - fn from_cursor(cursor: &clang::Cursor) -> Option { + /// Given a clang cursor, return the kind of function it represents, or + /// `None` otherwise. + pub fn from_cursor(cursor: &clang::Cursor) -> Option { // FIXME(emilio): Deduplicate logic with `ir::comp`. Some(match cursor.kind() { clang_sys::CXCursor_FunctionDecl => FunctionKind::Function, diff --git a/src/ir/item.rs b/src/ir/item.rs index d7c92ab444..ffb52664ac 100644 --- a/src/ir/item.rs +++ b/src/ir/item.rs @@ -1558,6 +1558,18 @@ impl ClangItemParser for Item { } } + // Treat all types that are declared inside functions as opaque. The Rust binding + // won't be able to do anything with them anyway. + // + // (If we don't do this check here, we can have subtle logic bugs because we generally + // ignore function bodies. See issue #2036.) + if let Some(ref parent) = ty.declaration().fallible_semantic_parent() { + if FunctionKind::from_cursor(parent).is_some() { + debug!("Skipping type declared inside function: {:?}", ty); + return Ok(Item::new_opaque_type(id, ty, ctx)); + } + } + let decl = { let decl = ty.declaration(); decl.definition().unwrap_or(decl) diff --git a/tests/expectations/tests/libclang-3.9/template_instantiation_with_fn_local_type.rs b/tests/expectations/tests/libclang-3.9/template_instantiation_with_fn_local_type.rs new file mode 100644 index 0000000000..ba0c6e7b49 --- /dev/null +++ b/tests/expectations/tests/libclang-3.9/template_instantiation_with_fn_local_type.rs @@ -0,0 +1,60 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Foo { + pub _address: u8, +} +extern "C" { + #[link_name = "\u{1}_Z1fv"] + pub fn f(); +} +#[test] +fn __bindgen_test_layout_Foo_open0__bindgen_ty_id_20_close0_instantiation() { + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of template specialization: ", stringify!(Foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of template specialization: ", stringify!(Foo)) + ); +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Baz { + pub _address: u8, +} +#[test] +fn bindgen_test_layout_Baz() { + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Baz)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Baz)) + ); +} + #[test] +fn __bindgen_test_layout_Foo_open0__bindgen_ty_id_21_close0_instantiation() { + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of template specialization: ", stringify!(Foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of template specialization: ", stringify!(Foo)) + ); +} diff --git a/tests/expectations/tests/template_instantiation_with_fn_local_type.rs b/tests/expectations/tests/template_instantiation_with_fn_local_type.rs new file mode 100644 index 0000000000..d968e71bae --- /dev/null +++ b/tests/expectations/tests/template_instantiation_with_fn_local_type.rs @@ -0,0 +1,96 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Foo { + pub _address: u8, +} +extern "C" { + #[link_name = "\u{1}_Z1fv"] + pub fn f(); +} +#[test] +fn __bindgen_test_layout_Foo_open0_Bar_close0_instantiation() { + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of template specialization: ", stringify!(Foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of template specialization: ", stringify!(Foo)) + ); +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Baz { + pub _address: u8, +} +#[test] +fn bindgen_test_layout_Baz() { + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Baz)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Baz)) + ); +} +#[test] +fn __bindgen_test_layout_Foo_open0_Boo_close0_instantiation() { + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of template specialization: ", stringify!(Foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of template specialization: ", stringify!(Foo)) + ); +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Bar { + pub _address: u8, +} +#[test] +fn bindgen_test_layout_Bar() { + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Bar)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Bar)) + ); +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Boo { + pub _address: u8, +} +#[test] +fn bindgen_test_layout_Boo() { + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Boo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Boo)) + ); +} diff --git a/tests/headers/template_instantiation_with_fn_local_type.hpp b/tests/headers/template_instantiation_with_fn_local_type.hpp new file mode 100644 index 0000000000..b7ff28b099 --- /dev/null +++ b/tests/headers/template_instantiation_with_fn_local_type.hpp @@ -0,0 +1,27 @@ +// bindgen-flags: -- -std=c++14 +// +// https://github.com/rust-lang/rust-bindgen/issues/2036 + +template +struct Foo {}; +template +Foo foo{}; + +// Struct inside function +void f() { + struct Bar { + Bar() {} + }; + foo; +} + +// Struct inside method +class Baz { + void f() { + struct Boo { + Boo() {} + }; + foo; + } +}; + From 05fe83beb28077f8063a285095c48081d4391093 Mon Sep 17 00:00:00 2001 From: Hengqi Chen Date: Tue, 27 Apr 2021 21:45:02 +0800 Subject: [PATCH 182/942] Update TOC for FAQ page Signed-off-by: Hengqi Chen --- book/src/faq.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/src/faq.md b/book/src/faq.md index 61e40e3586..7a13afb4cd 100644 --- a/book/src/faq.md +++ b/book/src/faq.md @@ -3,10 +3,10 @@ - - [Why isn't `bindgen` generating methods for this allowlisted class?](#why-isnt-bindgen-generating-methods-for-this-allowlisted-class) - [Why isn't `bindgen` generating bindings to inline functions?](#why-isnt-bindgen-generating-bindings-to-inline-functions) - [Does `bindgen` support the C++ Standard Template Library (STL)?](#does-bindgen-support-the-c-standard-template-library-stl) +- [How to deal with bindgen generated padding fields?](#how-to-deal-with-bindgen-generated-padding-fields) From 425a14617a9b807e51f37610385a24a0485d89fc Mon Sep 17 00:00:00 2001 From: Hengqi Chen Date: Tue, 27 Apr 2021 21:45:46 +0800 Subject: [PATCH 183/942] Fix typo Signed-off-by: Hengqi Chen --- book/src/using-bitfields.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/src/using-bitfields.md b/book/src/using-bitfields.md index c6d2c7e80e..41e07ad703 100644 --- a/book/src/using-bitfields.md +++ b/book/src/using-bitfields.md @@ -85,5 +85,5 @@ Note: This requires the Builder's derive_default to be set to true, otherwise th This will print out ```text -StructWithBitfields: a:1, b:0, c:2 +StructWithBitfields: a:0, b:0, c:0 ``` From 49430588d720dbb99f6694f7742c1462d36ca01a Mon Sep 17 00:00:00 2001 From: Boris-Chengbiao Zhou Date: Fri, 30 Apr 2021 02:16:49 +0200 Subject: [PATCH 184/942] Add a C naming option (#2045) Closes #2045. Fixes #1252. --- src/ir/item.rs | 24 +++++++- src/lib.rs | 17 +++++ src/options.rs | 7 +++ tests/expectations/tests/c_naming.rs | 92 ++++++++++++++++++++++++++++ tests/headers/c_naming.h | 19 ++++++ 5 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 tests/expectations/tests/c_naming.rs create mode 100644 tests/headers/c_naming.h diff --git a/src/ir/item.rs b/src/ir/item.rs index ffb52664ac..9375c79871 100644 --- a/src/ir/item.rs +++ b/src/ir/item.rs @@ -4,7 +4,7 @@ use super::super::codegen::{EnumVariation, CONSTIFIED_ENUM_MODULE_REPR_NAME}; use super::analysis::{HasVtable, HasVtableResult, Sizedness, SizednessResult}; use super::annotations::Annotations; use super::comment; -use super::comp::MethodKind; +use super::comp::{CompKind, MethodKind}; use super::context::{BindgenContext, ItemId, PartialType, TypeId}; use super::derive::{ CanDeriveCopy, CanDeriveDebug, CanDeriveDefault, CanDeriveEq, @@ -904,6 +904,12 @@ impl Item { names.push(base_name); } + if ctx.options().c_naming { + if let Some(prefix) = self.c_naming_prefix() { + names.insert(0, prefix.to_string()); + } + } + let name = names.join("_"); let name = if opt.user_mangled == UserMangled::Yes { @@ -1054,6 +1060,22 @@ impl Item { path.reverse(); path } + + /// Returns a prefix for the canonical name when C naming is enabled. + fn c_naming_prefix(&self) -> Option<&str> { + if let ItemKind::Type(typ) = &self.kind { + match typ.kind() { + TypeKind::Comp(comp_info) => match comp_info.kind() { + CompKind::Struct => Some("struct"), + CompKind::Union => Some("union"), + }, + TypeKind::Enum(_) => Some("enum"), + _ => None, + } + } else { + None + } + } } impl IsOpaque for T diff --git a/src/lib.rs b/src/lib.rs index 58c99c8dec..1ac053b7f8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -558,6 +558,10 @@ impl Builder { output_vector.push("--translate-enum-integer-types".into()); } + if self.options.c_naming { + output_vector.push("--c-naming".into()); + } + // Add clang arguments output_vector.push("--".into()); @@ -1616,6 +1620,15 @@ impl Builder { self.options.translate_enum_integer_types = doit; self } + + /// Generate types with C style naming. + /// + /// This will add prefixes to the generated type names. For example instead of a struct `A` we + /// will generate struct `struct_A`. Currently applies to structs, unions, and enums. + pub fn c_naming(mut self, doit: bool) -> Self { + self.options.c_naming = doit; + self + } } /// Configuration options for generated bindings. @@ -1921,6 +1934,9 @@ struct BindgenOptions { /// Always translate enum integer types to native Rust integer types. translate_enum_integer_types: bool, + + /// Generate types with C style naming. + c_naming: bool, } /// TODO(emilio): This is sort of a lie (see the error message that results from @@ -2062,6 +2078,7 @@ impl Default for BindgenOptions { dynamic_link_require_all: false, respect_cxx_access_specs: false, translate_enum_integer_types: false, + c_naming: false, } } } diff --git a/src/options.rs b/src/options.rs index ff2d42827e..cbdc945ebb 100644 --- a/src/options.rs +++ b/src/options.rs @@ -513,6 +513,9 @@ where Arg::with_name("translate-enum-integer-types") .long("translate-enum-integer-types") .help("Always translate enum integer types to native Rust integer types."), + Arg::with_name("c-naming") + .long("c-naming") + .help("Generate types with C style naming."), ]) // .args() .get_matches_from(args); @@ -953,6 +956,10 @@ where builder = builder.translate_enum_integer_types(true); } + if matches.is_present("c-naming") { + builder = builder.c_naming(true); + } + let verbose = matches.is_present("verbose"); Ok((builder, output, verbose)) diff --git a/tests/expectations/tests/c_naming.rs b/tests/expectations/tests/c_naming.rs new file mode 100644 index 0000000000..041e75ea70 --- /dev/null +++ b/tests/expectations/tests/c_naming.rs @@ -0,0 +1,92 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct struct_a { + pub a: ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout_struct_a() { + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(struct_a)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(struct_a)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(struct_a), + "::", + stringify!(a) + ) + ); +} +pub type a = *const struct_a; +#[repr(C)] +#[derive(Copy, Clone)] +pub union union_b { + pub a: ::std::os::raw::c_int, + pub b: ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout_union_b() { + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(union_b)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(union_b)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(union_b), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).b as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(union_b), + "::", + stringify!(b) + ) + ); +} +impl Default for union_b { + fn default() -> Self { + unsafe { ::std::mem::zeroed() } + } +} +pub type b = union_b; +pub const enum_c_A: enum_c = 0; +pub type enum_c = ::std::os::raw::c_uint; +extern "C" { + pub fn takes_a(arg: a); +} +extern "C" { + pub fn takes_b(arg: b); +} +extern "C" { + pub fn takes_c(arg: enum_c); +} diff --git a/tests/headers/c_naming.h b/tests/headers/c_naming.h new file mode 100644 index 0000000000..fd84c271fa --- /dev/null +++ b/tests/headers/c_naming.h @@ -0,0 +1,19 @@ +// bindgen-flags: --c-naming + +typedef const struct a { + int a; +} *a; + +union b { + int a; + int b; +}; +typedef union b b; + +enum c { + A, +}; + +void takes_a(a arg) {} +void takes_b(b arg) {} +void takes_c(enum c arg) {} From f26d57d8f7febe2f7d62f39f7d9f2cbda8067bd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Fri, 30 Apr 2021 10:59:15 +0200 Subject: [PATCH 185/942] ir: Use early return in c_naming_prefix. --- src/ir/item.rs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/ir/item.rs b/src/ir/item.rs index 9375c79871..4e0ba80b42 100644 --- a/src/ir/item.rs +++ b/src/ir/item.rs @@ -1063,18 +1063,19 @@ impl Item { /// Returns a prefix for the canonical name when C naming is enabled. fn c_naming_prefix(&self) -> Option<&str> { - if let ItemKind::Type(typ) = &self.kind { - match typ.kind() { - TypeKind::Comp(comp_info) => match comp_info.kind() { - CompKind::Struct => Some("struct"), - CompKind::Union => Some("union"), - }, - TypeKind::Enum(_) => Some("enum"), - _ => None, - } - } else { - None - } + let ty = match self.kind { + ItemKind::Type(ref ty) => ty, + _ => return None, + }; + + Some(match ty.kind() { + TypeKind::Comp(ref ci) => match ci.kind() { + CompKind::Struct => "struct", + CompKind::Union => "union", + }, + TypeKind::Enum(..) => "enum", + _ => return None, + }) } } From 910d2be897bacd41a683c4055bc0fbae1b088dbc Mon Sep 17 00:00:00 2001 From: Martin Boehme Date: Thu, 29 Apr 2021 09:10:31 +0200 Subject: [PATCH 186/942] Don't generate bindings for deleted member functions. (#2044) Closes #2044 Fixes #2043 See https://github.com/rust-lang/rust-bindgen/issues/2043 for details. --- src/clang.rs | 21 +++++ src/ir/function.rs | 11 ++- tests/expectations/tests/deleted-function.rs | 91 ++++++++++++++++++++ tests/headers/deleted-function.hpp | 35 ++++++++ 4 files changed, 154 insertions(+), 4 deletions(-) create mode 100644 tests/expectations/tests/deleted-function.rs create mode 100644 tests/headers/deleted-function.hpp diff --git a/src/clang.rs b/src/clang.rs index 661250894e..96f772540b 100644 --- a/src/clang.rs +++ b/src/clang.rs @@ -469,6 +469,27 @@ impl Cursor { unsafe { clang_Cursor_isFunctionInlined(self.x) != 0 } } + /// Is the referent a defaulted function? + pub fn is_defaulted_function(&self) -> bool { + unsafe { clang_CXXMethod_isDefaulted(self.x) != 0 } + } + + /// Is the referent a deleted function? + pub fn is_deleted_function(&self) -> bool { + // Unfortunately, libclang doesn't yet have an API for checking if a + // member function is deleted, but the following should be a good + // enough approximation. + // Deleted functions are implicitly inline according to paragraph 4 of + // [dcl.fct.def.delete] in the C++ standard. Normal inline functions + // have a definition in the same translation unit, so if this is an + // inline function without a definition, and it's not a defaulted + // function, we can reasonably safely conclude that it's a deleted + // function. + self.is_inlined_function() && + self.definition().is_none() && + !self.is_defaulted_function() + } + /// Get the width of this cursor's referent bit field, or `None` if the /// referent is not a bit field. pub fn bit_width(&self) -> Option { diff --git a/src/ir/function.rs b/src/ir/function.rs index c0938b653d..661ee59333 100644 --- a/src/ir/function.rs +++ b/src/ir/function.rs @@ -597,10 +597,13 @@ impl ClangSubItemParser for Function { return Err(ParseError::Continue); } - if !context.options().generate_inline_functions && - cursor.is_inlined_function() - { - return Err(ParseError::Continue); + if cursor.is_inlined_function() { + if !context.options().generate_inline_functions { + return Err(ParseError::Continue); + } + if cursor.is_deleted_function() { + return Err(ParseError::Continue); + } } let linkage = cursor.linkage(); diff --git a/tests/expectations/tests/deleted-function.rs b/tests/expectations/tests/deleted-function.rs new file mode 100644 index 0000000000..96967bb461 --- /dev/null +++ b/tests/expectations/tests/deleted-function.rs @@ -0,0 +1,91 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct A { + pub _address: u8, +} +#[test] +fn bindgen_test_layout_A() { + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(A)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(A)) + ); +} +extern "C" { + #[link_name = "\u{1}_ZN1A17inline_definitionEv"] + pub fn A_inline_definition(this: *mut A); +} +extern "C" { + #[link_name = "\u{1}_ZN1A22out_of_line_definitionEv"] + pub fn A_out_of_line_definition(this: *mut A); +} +impl A { + #[inline] + pub unsafe fn inline_definition(&mut self) { + A_inline_definition(self) + } + #[inline] + pub unsafe fn out_of_line_definition(&mut self) { + A_out_of_line_definition(self) + } +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct B { + pub _address: u8, +} +#[test] +fn bindgen_test_layout_B() { + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(B)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(B)) + ); +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct C { + pub _address: u8, +} +#[test] +fn bindgen_test_layout_C() { + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(C)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(C)) + ); +} +extern "C" { + #[link_name = "\u{1}_ZN1CC1ERS_"] + pub fn C_C(this: *mut C, arg1: *mut C); +} +impl C { + #[inline] + pub unsafe fn new(arg1: *mut C) -> Self { + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + C_C(__bindgen_tmp.as_mut_ptr(), arg1); + __bindgen_tmp.assume_init() + } +} diff --git a/tests/headers/deleted-function.hpp b/tests/headers/deleted-function.hpp new file mode 100644 index 0000000000..61848a0ae9 --- /dev/null +++ b/tests/headers/deleted-function.hpp @@ -0,0 +1,35 @@ +// bindgen-flags: --generate-inline-functions -- -std=c++11 + +class A { +public: + // Deleted function should not get a binding. + void deleted() = delete; + + // Inline functions should get bindings, whether they are defined inline + // (in the class) or out of line. + inline void inline_definition() {} + inline void out_of_line_definition(); + + // TODO: This is an edge case that we get wrong: An inline function + // without a definition in the same translation unit should still get a + // binding. We currently can't distinguish this case from a deleted member + // function because libclang doesn't provide a direct way to query for + // deleted member functions. This seems acceptable, however, as an inline + // function without a definition in the same translation unit is unlikely + // to be useful in practice. + inline void inline_without_definition(); +}; + +void A::out_of_line_definition() {} + +class B { +public: + // Deleted copy constructor should not get a binding. + B(B&) = delete; +}; + +class C { +public: + // Defaulted copy constructor should get a binding. + C(C&) = default; +}; \ No newline at end of file From 4116b701f5c86f4197824703d935283ca644c21b Mon Sep 17 00:00:00 2001 From: Fernando Jimenez Moreno Date: Sat, 1 May 2021 18:23:19 +0200 Subject: [PATCH 187/942] Point book docs.rs links to latest version of the crate --- book/src/allowlisting.md | 6 +++--- book/src/blocklisting.md | 2 +- book/src/nocopy.md | 2 +- book/src/nodebug.md | 2 +- book/src/opaque.md | 2 +- book/src/using-unions.md | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/book/src/allowlisting.md b/book/src/allowlisting.md index 8c57eaf328..2e28d80ff6 100644 --- a/book/src/allowlisting.md +++ b/book/src/allowlisting.md @@ -16,9 +16,9 @@ transitively used by a definition that matches them. ### Library -* [`bindgen::Builder::allowlist_type`](https://docs.rs/bindgen/0.23.1/bindgen/struct.Builder.html#method.allowlist_type) -* [`bindgen::Builder::allowlist_function`](https://docs.rs/bindgen/0.23.1/bindgen/struct.Builder.html#method.allowlist_function) -* [`bindgen::Builder::allowlist_var`](https://docs.rs/bindgen/0.23.1/bindgen/struct.Builder.html#method.allowlist_var) +* [`bindgen::Builder::allowlist_type`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.allowlist_type) +* [`bindgen::Builder::allowlist_function`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.allowlist_function) +* [`bindgen::Builder::allowlist_var`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.allowlist_var) ### Command Line diff --git a/book/src/blocklisting.md b/book/src/blocklisting.md index 1d6086164e..5c082ddaba 100644 --- a/book/src/blocklisting.md +++ b/book/src/blocklisting.md @@ -15,7 +15,7 @@ not. ### Library -* [`bindgen::Builder::blocklist_type`](https://docs.rs/bindgen/0.31.3/bindgen/struct.Builder.html#method.blocklist_type) +* [`bindgen::Builder::blocklist_type`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.blocklist_type) ### Command Line diff --git a/book/src/nocopy.md b/book/src/nocopy.md index ec21f3ae7e..8a637a59c3 100644 --- a/book/src/nocopy.md +++ b/book/src/nocopy.md @@ -8,7 +8,7 @@ used to prevent bindgen to autoderive the `Copy` and `Clone` traits for a type. ### Library -* [`bindgen::Builder::no_copy`](https://docs.rs/bindgen/0.23.1/bindgen/struct.Builder.html#method.no_copy) +* [`bindgen::Builder::no_copy`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.no_copy) ### Command Line diff --git a/book/src/nodebug.md b/book/src/nodebug.md index 251b792b14..c412a7dfca 100644 --- a/book/src/nodebug.md +++ b/book/src/nodebug.md @@ -7,7 +7,7 @@ used to prevent bindgen to autoderive the `Debug` traits for a type. ### Library -* [`bindgen::Builder::no_debug`](https://docs.rs/bindgen/0.54.2/bindgen/struct.Builder.html#method.no_debug) +* [`bindgen::Builder::no_debug`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.no_debug) ### Command Line diff --git a/book/src/opaque.md b/book/src/opaque.md index e1bf600cec..ad15056743 100644 --- a/book/src/opaque.md +++ b/book/src/opaque.md @@ -10,7 +10,7 @@ automatically, but other times it needs some explicit help from you. ### Library -* [`bindgen::Builder::opaque_type`](https://docs.rs/bindgen/0.23.1/bindgen/struct.Builder.html#method.opaque_type) +* [`bindgen::Builder::opaque_type`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.opaque_type) ### Command Line diff --git a/book/src/using-unions.md b/book/src/using-unions.md index 9a0cc3ee9a..9e8e9b99d7 100644 --- a/book/src/using-unions.md +++ b/book/src/using-unions.md @@ -35,8 +35,8 @@ typedef union { ### Library -* [`bindgen::Builder::rust_target()`](https://docs.rs/bindgen/0.29.0/bindgen/struct.Builder.html#method.rust_target) -* [`bindgen::Builder::derive_default()`](https://docs.rs/bindgen/0.29.0/bindgen/struct.Builder.html#method.derive_default) +* [`bindgen::Builder::rust_target()`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.rust_target) +* [`bindgen::Builder::derive_default()`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.derive_default) ### Command Line From e6684dc5c56d0283b9c14b34f68d445e9d5a580f Mon Sep 17 00:00:00 2001 From: Daniel Xu Date: Tue, 11 May 2021 10:46:27 -0500 Subject: [PATCH 188/942] Zero out padding in custom Default trait implementations (#2051) * Zero out padding in custom Default trait implementations Previously, we were using `std::mem::zeroed()` which unfortunately does not necessarily zero out padding. It'd be better if the padding is zeroed out because some libraries are sensitive to non-zero'd out bytes, especially when forward/backward compatability is involved. This commit ensures all bytes are zeroed out in custom Default trait implementations. --- src/codegen/mod.rs | 25 ++++- tests/expectations/tests/16-byte-alignment.rs | 30 +++++- .../tests/16-byte-alignment_1_0.rs | 6 +- tests/expectations/tests/allowlist_basic.rs | 12 ++- .../expectations/tests/anon-fields-prefix.rs | 6 +- .../tests/anon_struct_in_union.rs | 12 ++- tests/expectations/tests/anon_union.rs | 18 +++- tests/expectations/tests/anon_union_1_0.rs | 12 ++- .../tests/anonymous-template-types.rs | 12 ++- .../bad-namespace-parenthood-inheritance.rs | 6 +- tests/expectations/tests/bitfield_align_2.rs | 6 +- .../tests/blocklist-and-impl-debug.rs | 6 +- tests/expectations/tests/blocks-signature.rs | 6 +- tests/expectations/tests/blocks.rs | 6 +- tests/expectations/tests/c_naming.rs | 6 +- tests/expectations/tests/class.rs | 42 ++++++-- tests/expectations/tests/class_1_0.rs | 30 +++++- tests/expectations/tests/class_nested.rs | 18 +++- tests/expectations/tests/class_with_dtor.rs | 12 ++- .../tests/class_with_inner_struct.rs | 36 +++++-- .../tests/class_with_inner_struct_1_0.rs | 6 +- .../expectations/tests/class_with_typedef.rs | 12 ++- tests/expectations/tests/complex.rs | 12 ++- .../expectations/tests/const-const-mut-ptr.rs | 6 +- tests/expectations/tests/const_tparam.rs | 6 +- .../expectations/tests/constify-all-enums.rs | 6 +- .../tests/constify-module-enums-basic.rs | 6 +- .../tests/constify-module-enums-namespace.rs | 6 +- .../constify-module-enums-shadow-name.rs | 6 +- .../constify-module-enums-simple-alias.rs | 6 +- ...onstify-module-enums-simple-nonamespace.rs | 6 +- .../tests/constify-module-enums-types.rs | 24 ++++- .../tests/convert-cpp-comment-to-rust.rs | 6 +- tests/expectations/tests/convert-floats.rs | 6 +- .../expectations/tests/ctypes-prefix-path.rs | 6 +- .../tests/default-template-parameter.rs | 6 +- .../tests/derive-bitfield-method-same-name.rs | 6 +- tests/expectations/tests/derive-clone.rs | 6 +- tests/expectations/tests/derive-clone_1_0.rs | 6 +- .../tests/derive-debug-bitfield-core.rs | 6 +- .../tests/derive-debug-bitfield.rs | 6 +- .../tests/derive-debug-function-pointer.rs | 6 +- .../tests/derive-debug-generic.rs | 6 +- .../tests/derive-debug-mangle-name.rs | 12 ++- ...ive-debug-opaque-template-instantiation.rs | 6 +- .../expectations/tests/derive-debug-opaque.rs | 12 ++- .../tests/derive-default-and-blocklist.rs | 6 +- .../tests/derive-hash-and-blocklist.rs | 6 +- .../tests/derive-hash-blocklisting.rs | 12 ++- .../tests/derive-hash-struct-with-pointer.rs | 24 ++++- .../tests/derive-hash-template-def-float.rs | 6 +- .../tests/derive-hash-template-inst-float.rs | 18 +++- .../tests/derive-partialeq-and-blocklist.rs | 6 +- .../tests/derive-partialeq-anonfield.rs | 12 ++- .../tests/derive-partialeq-base.rs | 12 ++- .../tests/derive-partialeq-bitfield.rs | 6 +- .../tests/derive-partialeq-core.rs | 6 +- .../tests/derive-partialeq-pointer.rs | 24 ++++- .../tests/derive-partialeq-union.rs | 6 +- .../tests/derive-partialeq-union_1_0.rs | 6 +- tests/expectations/tests/doggo-or-null.rs | 6 +- .../duplicated-namespaces-definitions.rs | 6 +- tests/expectations/tests/empty-union.rs | 6 +- .../tests/enum-default-bitfield.rs | 6 +- .../expectations/tests/enum-default-consts.rs | 6 +- .../expectations/tests/enum-default-module.rs | 6 +- tests/expectations/tests/enum-default-rust.rs | 6 +- tests/expectations/tests/enum.rs | 6 +- .../tests/enum_and_vtable_mangling.rs | 6 +- .../expectations/tests/extern-const-struct.rs | 6 +- .../tests/forward-declaration-autoptr.rs | 12 ++- .../forward-inherit-struct-with-fields.rs | 12 ++- .../tests/forward-inherit-struct.rs | 6 +- .../tests/forward_declared_complex_types.rs | 6 +- .../forward_declared_complex_types_1_0.rs | 6 +- .../tests/incomplete-array-padding.rs | 6 +- ...from-template-instantiation-with-vtable.rs | 36 +++++-- .../expectations/tests/inherit-namespaced.rs | 6 +- tests/expectations/tests/inherit_named.rs | 6 +- .../tests/inline_namespace_no_ns_enabled.rs | 18 +++- .../expectations/tests/inner_template_self.rs | 12 ++- .../tests/issue-1113-template-references.rs | 12 ++- .../tests/issue-1118-using-forward-decl.rs | 18 +++- .../tests/issue-1197-pure-virtual-stuff.rs | 6 +- tests/expectations/tests/issue-1285.rs | 12 ++- tests/expectations/tests/issue-1443.rs | 24 ++++- tests/expectations/tests/issue-1498.rs | 12 ++- tests/expectations/tests/issue-1514.rs | 12 ++- tests/expectations/tests/issue-358.rs | 12 ++- tests/expectations/tests/issue-372.rs | 18 +++- tests/expectations/tests/issue-446.rs | 12 ++- tests/expectations/tests/issue-493.rs | 42 ++++++-- tests/expectations/tests/issue-493_1_0.rs | 18 +++- .../tests/issue-544-stylo-creduce-2.rs | 6 +- ...ate-params-causing-layout-test-failures.rs | 12 ++- ...issue-584-stylo-template-analysis-panic.rs | 18 +++- ...e-638-stylo-cannot-find-T-in-this-scope.rs | 12 ++- .../tests/issue-643-inner-struct.rs | 6 +- ...ue-645-cannot-find-type-T-in-this-scope.rs | 6 +- .../issue-648-derive-debug-with-padding.rs | 12 ++- .../issue-662-cannot-find-T-in-this-scope.rs | 18 +++- tests/expectations/tests/issue-662-part-2.rs | 12 ++- .../issue-691-template-parameter-virtual.rs | 12 ++- .../issue-848-replacement-system-include.rs | 6 +- .../issue-944-derive-copy-and-blocklisting.rs | 6 +- .../expectations/tests/jsval_layout_opaque.rs | 30 +++++- .../tests/jsval_layout_opaque_1_0.rs | 6 +- tests/expectations/tests/layout.rs | 6 +- tests/expectations/tests/layout_align.rs | 6 +- tests/expectations/tests/layout_array.rs | 24 ++++- .../tests/layout_array_too_long.rs | 18 +++- .../tests/layout_cmdline_token.rs | 18 +++- tests/expectations/tests/layout_eth_conf.rs | 90 +++++++++++++--- .../expectations/tests/layout_eth_conf_1_0.rs | 84 ++++++++++++--- tests/expectations/tests/layout_kni_mbuf.rs | 6 +- .../tests/layout_large_align_field.rs | 36 +++++-- tests/expectations/tests/layout_mbuf.rs | 48 +++++++-- tests/expectations/tests/layout_mbuf_1_0.rs | 6 +- .../issue-769-bad-instantiation-test.rs | 6 +- .../issue-769-bad-instantiation-test.rs | 6 +- .../type_alias_template_specialized.rs | 6 +- .../issue-769-bad-instantiation-test.rs | 6 +- .../type_alias_template_specialized.rs | 6 +- tests/expectations/tests/libclang-9/class.rs | 42 ++++++-- .../tests/libclang-9/class_1_0.rs | 30 +++++- .../libclang-9/incomplete-array-padding.rs | 6 +- .../libclang-9/issue-643-inner-struct.rs | 6 +- .../issue-769-bad-instantiation-test.rs | 6 +- .../tests/libclang-9/layout_align.rs | 6 +- .../type_alias_template_specialized.rs | 6 +- tests/expectations/tests/namespace.rs | 12 ++- tests/expectations/tests/nested_vtable.rs | 18 +++- tests/expectations/tests/no-derive-debug.rs | 6 +- .../tests/no-recursive-allowlisting.rs | 6 +- tests/expectations/tests/no-std.rs | 6 +- .../tests/no_debug_bypass_impl_debug.rs | 12 ++- tests/expectations/tests/no_default.rs | 6 +- .../tests/no_default_bypass_derive_default.rs | 6 +- tests/expectations/tests/nsBaseHashtable.rs | 18 +++- tests/expectations/tests/nsStyleAutoArray.rs | 12 ++- .../expectations/tests/objc_interface_type.rs | 6 +- .../tests/opaque-template-inst-member-2.rs | 6 +- .../tests/opaque-template-inst-member.rs | 12 ++- ...paque-template-instantiation-namespaced.rs | 12 ++- .../tests/opaque-template-instantiation.rs | 12 ++- tests/expectations/tests/opaque_pointer.rs | 6 +- tests/expectations/tests/packed-vtable.rs | 6 +- tests/expectations/tests/private_fields.rs | 12 ++- .../expectations/tests/ref_argument_array.rs | 6 +- .../tests/replace_template_alias.rs | 6 +- tests/expectations/tests/replaces_double.rs | 12 ++- tests/expectations/tests/size_t_is_usize.rs | 6 +- ...ruct_containing_forward_declared_struct.rs | 6 +- tests/expectations/tests/struct_typedef.rs | 6 +- .../tests/struct_with_anon_struct_pointer.rs | 6 +- .../tests/struct_with_anon_union.rs | 12 ++- .../tests/struct_with_anon_unnamed_union.rs | 12 ++- .../tests/struct_with_derive_debug.rs | 12 ++- .../tests/struct_with_large_array.rs | 12 ++- .../expectations/tests/struct_with_nesting.rs | 12 ++- .../tests/template-param-usage-0.rs | 6 +- .../tests/template-param-usage-10.rs | 12 ++- .../tests/template-param-usage-12.rs | 12 ++- .../tests/template-param-usage-13.rs | 6 +- .../tests/template-param-usage-14.rs | 6 +- .../tests/template-param-usage-15.rs | 12 ++- .../tests/template-param-usage-2.rs | 12 ++- .../tests/template-param-usage-3.rs | 12 ++- .../tests/template-param-usage-4.rs | 6 +- .../tests/template-param-usage-5.rs | 6 +- .../tests/template-param-usage-7.rs | 6 +- .../tests/template-param-usage-8.rs | 6 +- .../tests/template-param-usage-9.rs | 6 +- tests/expectations/tests/template.rs | 102 +++++++++++++++--- tests/expectations/tests/template_alias.rs | 6 +- .../tests/template_alias_namespace.rs | 6 +- .../template_typedef_transitive_param.rs | 6 +- tests/expectations/tests/timex.rs | 12 ++- tests/expectations/tests/transform-op.rs | 54 ++++++++-- ..._alias_partial_template_especialization.rs | 6 +- tests/expectations/tests/typeref.rs | 24 ++++- tests/expectations/tests/typeref_1_0.rs | 6 +- tests/expectations/tests/union-align.rs | 12 ++- tests/expectations/tests/union-in-ns.rs | 6 +- tests/expectations/tests/union_bitfield.rs | 12 ++- .../expectations/tests/union_bitfield_1_0.rs | 6 +- tests/expectations/tests/union_dtor.rs | 6 +- tests/expectations/tests/union_fields.rs | 6 +- tests/expectations/tests/union_template.rs | 24 ++++- .../tests/union_with_anon_struct.rs | 6 +- .../tests/union_with_anon_struct_bitfield.rs | 6 +- .../tests/union_with_anon_union.rs | 12 ++- .../tests/union_with_anon_unnamed_struct.rs | 6 +- .../tests/union_with_anon_unnamed_union.rs | 12 ++- .../tests/union_with_big_member.rs | 18 +++- .../tests/union_with_big_member_1_0.rs | 12 ++- .../expectations/tests/union_with_nesting.rs | 24 ++++- tests/expectations/tests/use-core.rs | 12 ++- tests/expectations/tests/use-core_1_0.rs | 6 +- tests/expectations/tests/using.rs | 6 +- tests/expectations/tests/virtual_dtor.rs | 6 +- .../expectations/tests/virtual_inheritance.rs | 18 +++- .../expectations/tests/virtual_overloaded.rs | 6 +- .../tests/vtable_recursive_sig.rs | 12 ++- tests/expectations/tests/weird_bitfields.rs | 6 +- tests/expectations/tests/what_is_going_on.rs | 6 +- 206 files changed, 2114 insertions(+), 419 deletions(-) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 1a702b00f7..6f8a451a2a 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -2196,9 +2196,32 @@ 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 + } + } + }; + // Note we use `ptr::write_bytes()` instead of `mem::zeroed()` because the latter does + // not necessarily ensure padding bytes are zeroed. Some C libraries are sensitive to + // non-zero padding bytes, especially when forwards/backwards compatability is + // involved. result.push(quote! { impl #generics Default for #ty_for_impl { - fn default() -> Self { unsafe { ::#prefix::mem::zeroed() } } + fn default() -> Self { + #body + } } }); } diff --git a/tests/expectations/tests/16-byte-alignment.rs b/tests/expectations/tests/16-byte-alignment.rs index 0bb92fd17f..058568f24c 100644 --- a/tests/expectations/tests/16-byte-alignment.rs +++ b/tests/expectations/tests/16-byte-alignment.rs @@ -99,7 +99,11 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1() { } impl Default for rte_ipv4_tuple__bindgen_ty_1 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[test] @@ -143,7 +147,11 @@ fn bindgen_test_layout_rte_ipv4_tuple() { } impl Default for rte_ipv4_tuple { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -240,7 +248,11 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1() { } impl Default for rte_ipv6_tuple__bindgen_ty_1 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[test] @@ -284,7 +296,11 @@ fn bindgen_test_layout_rte_ipv6_tuple() { } impl Default for rte_ipv6_tuple { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -333,6 +349,10 @@ fn bindgen_test_layout_rte_thash_tuple() { } impl Default for rte_thash_tuple { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/16-byte-alignment_1_0.rs b/tests/expectations/tests/16-byte-alignment_1_0.rs index 8b1055731d..1df6778b56 100644 --- a/tests/expectations/tests/16-byte-alignment_1_0.rs +++ b/tests/expectations/tests/16-byte-alignment_1_0.rs @@ -390,6 +390,10 @@ impl Clone for rte_thash_tuple { } impl Default for rte_thash_tuple { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } diff --git a/tests/expectations/tests/allowlist_basic.rs b/tests/expectations/tests/allowlist_basic.rs index 4e72e8b6dd..5bfe42e870 100644 --- a/tests/expectations/tests/allowlist_basic.rs +++ b/tests/expectations/tests/allowlist_basic.rs @@ -20,11 +20,19 @@ pub struct AllowlistMe_Inner { } impl Default for AllowlistMe_Inner { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl Default for AllowlistMe { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/anon-fields-prefix.rs b/tests/expectations/tests/anon-fields-prefix.rs index f358dbd8f1..edd551d193 100644 --- a/tests/expectations/tests/anon-fields-prefix.rs +++ b/tests/expectations/tests/anon-fields-prefix.rs @@ -150,6 +150,10 @@ fn bindgen_test_layout_color() { } impl Default for color { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/anon_struct_in_union.rs b/tests/expectations/tests/anon_struct_in_union.rs index 008ab611d9..1a4040151e 100644 --- a/tests/expectations/tests/anon_struct_in_union.rs +++ b/tests/expectations/tests/anon_struct_in_union.rs @@ -74,7 +74,11 @@ fn bindgen_test_layout_s__bindgen_ty_1() { } impl Default for s__bindgen_ty_1 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[test] @@ -97,6 +101,10 @@ fn bindgen_test_layout_s() { } impl Default for s { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/anon_union.rs b/tests/expectations/tests/anon_union.rs index 386d8fadaa..8caf7d110d 100644 --- a/tests/expectations/tests/anon_union.rs +++ b/tests/expectations/tests/anon_union.rs @@ -38,12 +38,20 @@ pub union TErrorResult__bindgen_ty_1 { } impl Default for TErrorResult__bindgen_ty_1 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl Default for TErrorResult { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -65,7 +73,11 @@ fn bindgen_test_layout_ErrorResult() { } impl Default for ErrorResult { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[test] diff --git a/tests/expectations/tests/anon_union_1_0.rs b/tests/expectations/tests/anon_union_1_0.rs index fbd6b36974..63273e608f 100644 --- a/tests/expectations/tests/anon_union_1_0.rs +++ b/tests/expectations/tests/anon_union_1_0.rs @@ -83,7 +83,11 @@ pub struct TErrorResult__bindgen_ty_1 { } impl Default for TErrorResult { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } #[repr(C)] @@ -111,7 +115,11 @@ impl Clone for ErrorResult { } impl Default for ErrorResult { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } #[test] diff --git a/tests/expectations/tests/anonymous-template-types.rs b/tests/expectations/tests/anonymous-template-types.rs index 3d072864a5..14afd6b316 100644 --- a/tests/expectations/tests/anonymous-template-types.rs +++ b/tests/expectations/tests/anonymous-template-types.rs @@ -13,7 +13,11 @@ pub struct Foo { } impl Default for Foo { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -29,7 +33,11 @@ pub struct Quux { } impl Default for Quux { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] diff --git a/tests/expectations/tests/bad-namespace-parenthood-inheritance.rs b/tests/expectations/tests/bad-namespace-parenthood-inheritance.rs index 228dafd5ab..4d0d6bcd18 100644 --- a/tests/expectations/tests/bad-namespace-parenthood-inheritance.rs +++ b/tests/expectations/tests/bad-namespace-parenthood-inheritance.rs @@ -12,7 +12,11 @@ pub struct std_char_traits { } impl Default for std_char_traits { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] diff --git a/tests/expectations/tests/bitfield_align_2.rs b/tests/expectations/tests/bitfield_align_2.rs index f4f0c98a70..1a1f7dd822 100644 --- a/tests/expectations/tests/bitfield_align_2.rs +++ b/tests/expectations/tests/bitfield_align_2.rs @@ -121,7 +121,11 @@ fn bindgen_test_layout_TaggedPtr() { } impl Default for TaggedPtr { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl TaggedPtr { diff --git a/tests/expectations/tests/blocklist-and-impl-debug.rs b/tests/expectations/tests/blocklist-and-impl-debug.rs index f272f9beac..ba39fb14d5 100644 --- a/tests/expectations/tests/blocklist-and-impl-debug.rs +++ b/tests/expectations/tests/blocklist-and-impl-debug.rs @@ -40,7 +40,11 @@ fn bindgen_test_layout_ShouldManuallyImplDebug() { } impl Default for ShouldManuallyImplDebug { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl ::std::fmt::Debug for ShouldManuallyImplDebug { diff --git a/tests/expectations/tests/blocks-signature.rs b/tests/expectations/tests/blocks-signature.rs index bd9d815038..22136ddfb7 100644 --- a/tests/expectations/tests/blocks-signature.rs +++ b/tests/expectations/tests/blocks-signature.rs @@ -76,7 +76,11 @@ fn bindgen_test_layout_contains_block_pointers() { } impl Default for contains_block_pointers { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } pub type _bindgen_ty_id_33 = *const ::block::Block<(), ()>; diff --git a/tests/expectations/tests/blocks.rs b/tests/expectations/tests/blocks.rs index 4c731f895e..b2ae0b2901 100644 --- a/tests/expectations/tests/blocks.rs +++ b/tests/expectations/tests/blocks.rs @@ -75,6 +75,10 @@ fn bindgen_test_layout_contains_block_pointers() { } impl Default for contains_block_pointers { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/c_naming.rs b/tests/expectations/tests/c_naming.rs index 041e75ea70..abcccf1fd2 100644 --- a/tests/expectations/tests/c_naming.rs +++ b/tests/expectations/tests/c_naming.rs @@ -75,7 +75,11 @@ fn bindgen_test_layout_union_b() { } impl Default for union_b { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } pub type b = union_b; diff --git a/tests/expectations/tests/class.rs b/tests/expectations/tests/class.rs index b13b3c81cd..3d3afb1926 100644 --- a/tests/expectations/tests/class.rs +++ b/tests/expectations/tests/class.rs @@ -71,7 +71,11 @@ fn bindgen_test_layout_C() { } impl Default for C { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -134,7 +138,11 @@ fn bindgen_test_layout_C_with_zero_length_array() { } impl Default for C_with_zero_length_array { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -203,7 +211,11 @@ fn bindgen_test_layout_C_with_incomplete_array() { } impl Default for C_with_incomplete_array { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -253,7 +265,11 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { } impl Default for C_with_zero_length_array_and_incomplete_array { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -332,7 +348,11 @@ fn bindgen_test_layout_IncompleteArrayNonCopiable() { } impl Default for IncompleteArrayNonCopiable { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -366,7 +386,11 @@ fn bindgen_test_layout_Union() { } impl Default for Union { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -401,7 +425,11 @@ fn bindgen_test_layout_WithUnion() { } impl Default for WithUnion { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] diff --git a/tests/expectations/tests/class_1_0.rs b/tests/expectations/tests/class_1_0.rs index b341bdbe87..3f948bb138 100644 --- a/tests/expectations/tests/class_1_0.rs +++ b/tests/expectations/tests/class_1_0.rs @@ -119,7 +119,11 @@ impl Clone for C { } impl Default for C { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } impl ::std::cmp::PartialEq for C { @@ -187,7 +191,11 @@ fn bindgen_test_layout_C_with_zero_length_array() { } impl Default for C_with_zero_length_array { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } #[repr(C)] @@ -256,7 +264,11 @@ fn bindgen_test_layout_C_with_incomplete_array() { } impl Default for C_with_incomplete_array { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } #[repr(C)] @@ -306,7 +318,11 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { } impl Default for C_with_zero_length_array_and_incomplete_array { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } #[repr(C)] @@ -385,7 +401,11 @@ fn bindgen_test_layout_IncompleteArrayNonCopiable() { } impl Default for IncompleteArrayNonCopiable { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } #[repr(C)] diff --git a/tests/expectations/tests/class_nested.rs b/tests/expectations/tests/class_nested.rs index 5f7a1dfc65..ecc5c20a7e 100644 --- a/tests/expectations/tests/class_nested.rs +++ b/tests/expectations/tests/class_nested.rs @@ -48,7 +48,11 @@ pub struct A_D { } impl Default for A_D { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[test] @@ -159,11 +163,19 @@ pub struct Templated_Templated_inner { } impl Default for Templated_Templated_inner { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl Default for Templated { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/class_with_dtor.rs b/tests/expectations/tests/class_with_dtor.rs index 7cefe99df9..0cf2d8d236 100644 --- a/tests/expectations/tests/class_with_dtor.rs +++ b/tests/expectations/tests/class_with_dtor.rs @@ -13,7 +13,11 @@ pub struct HandleWithDtor { } impl Default for HandleWithDtor { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } pub type HandleValue = HandleWithDtor<::std::os::raw::c_int>; @@ -50,7 +54,11 @@ fn bindgen_test_layout_WithoutDtor() { } impl Default for WithoutDtor { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[test] diff --git a/tests/expectations/tests/class_with_inner_struct.rs b/tests/expectations/tests/class_with_inner_struct.rs index eab54118e1..35ed765914 100644 --- a/tests/expectations/tests/class_with_inner_struct.rs +++ b/tests/expectations/tests/class_with_inner_struct.rs @@ -87,7 +87,11 @@ fn bindgen_test_layout_A__bindgen_ty_1() { } impl Default for A__bindgen_ty_1 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -122,7 +126,11 @@ fn bindgen_test_layout_A__bindgen_ty_2() { } impl Default for A__bindgen_ty_2 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[test] @@ -157,7 +165,11 @@ fn bindgen_test_layout_A() { } impl Default for A { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -366,7 +378,11 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_2() { } impl Default for C__bindgen_ty_1__bindgen_ty_2 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[test] @@ -397,7 +413,11 @@ fn bindgen_test_layout_C__bindgen_ty_1() { } impl Default for C__bindgen_ty_1 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -463,6 +483,10 @@ fn bindgen_test_layout_C() { } impl Default for C { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/class_with_inner_struct_1_0.rs b/tests/expectations/tests/class_with_inner_struct_1_0.rs index 4bb71602b4..52cd590d67 100644 --- a/tests/expectations/tests/class_with_inner_struct_1_0.rs +++ b/tests/expectations/tests/class_with_inner_struct_1_0.rs @@ -437,7 +437,11 @@ impl Clone for C__bindgen_ty_1__bindgen_ty_2 { } impl Default for C__bindgen_ty_1__bindgen_ty_2 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } #[test] diff --git a/tests/expectations/tests/class_with_typedef.rs b/tests/expectations/tests/class_with_typedef.rs index 52f89b4dca..31faa49ddb 100644 --- a/tests/expectations/tests/class_with_typedef.rs +++ b/tests/expectations/tests/class_with_typedef.rs @@ -78,7 +78,11 @@ extern "C" { } impl Default for C { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl C { @@ -125,6 +129,10 @@ fn bindgen_test_layout_D() { } impl Default for D { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/complex.rs b/tests/expectations/tests/complex.rs index b13ac90a9c..4dae071727 100644 --- a/tests/expectations/tests/complex.rs +++ b/tests/expectations/tests/complex.rs @@ -74,7 +74,11 @@ fn bindgen_test_layout_TestDoublePtr() { } impl Default for TestDoublePtr { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -140,6 +144,10 @@ fn bindgen_test_layout_TestFloatPtr() { } impl Default for TestFloatPtr { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/const-const-mut-ptr.rs b/tests/expectations/tests/const-const-mut-ptr.rs index 789fccd63a..bc1e76277a 100644 --- a/tests/expectations/tests/const-const-mut-ptr.rs +++ b/tests/expectations/tests/const-const-mut-ptr.rs @@ -30,6 +30,10 @@ fn bindgen_test_layout_foo() { } impl Default for foo { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/const_tparam.rs b/tests/expectations/tests/const_tparam.rs index f56561f0dd..ec256872df 100644 --- a/tests/expectations/tests/const_tparam.rs +++ b/tests/expectations/tests/const_tparam.rs @@ -14,6 +14,10 @@ pub struct C { } impl Default for C { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/constify-all-enums.rs b/tests/expectations/tests/constify-all-enums.rs index 3c450e623e..78bb99faf5 100644 --- a/tests/expectations/tests/constify-all-enums.rs +++ b/tests/expectations/tests/constify-all-enums.rs @@ -42,6 +42,10 @@ fn bindgen_test_layout_bar() { } impl Default for bar { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/constify-module-enums-basic.rs b/tests/expectations/tests/constify-module-enums-basic.rs index 2cbb09bdcb..59e9ba12ba 100644 --- a/tests/expectations/tests/constify-module-enums-basic.rs +++ b/tests/expectations/tests/constify-module-enums-basic.rs @@ -46,7 +46,11 @@ fn bindgen_test_layout_bar() { } impl Default for bar { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } extern "C" { diff --git a/tests/expectations/tests/constify-module-enums-namespace.rs b/tests/expectations/tests/constify-module-enums-namespace.rs index c18b7175ad..e434291a15 100644 --- a/tests/expectations/tests/constify-module-enums-namespace.rs +++ b/tests/expectations/tests/constify-module-enums-namespace.rs @@ -58,7 +58,11 @@ pub mod root { } impl Default for bar { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } } diff --git a/tests/expectations/tests/constify-module-enums-shadow-name.rs b/tests/expectations/tests/constify-module-enums-shadow-name.rs index 16f13fdbe3..60401dc093 100644 --- a/tests/expectations/tests/constify-module-enums-shadow-name.rs +++ b/tests/expectations/tests/constify-module-enums-shadow-name.rs @@ -42,6 +42,10 @@ fn bindgen_test_layout_bar() { } impl Default for bar { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/constify-module-enums-simple-alias.rs b/tests/expectations/tests/constify-module-enums-simple-alias.rs index 64e77c68bd..317697dd3b 100644 --- a/tests/expectations/tests/constify-module-enums-simple-alias.rs +++ b/tests/expectations/tests/constify-module-enums-simple-alias.rs @@ -109,6 +109,10 @@ fn bindgen_test_layout_Bar() { } impl Default for Bar { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs b/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs index 3a95b3c912..b6644797d7 100644 --- a/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs +++ b/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs @@ -41,6 +41,10 @@ fn bindgen_test_layout_Bar() { } impl Default for Bar { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/constify-module-enums-types.rs b/tests/expectations/tests/constify-module-enums-types.rs index 4ba85b37d5..ec7e6c0eee 100644 --- a/tests/expectations/tests/constify-module-enums-types.rs +++ b/tests/expectations/tests/constify-module-enums-types.rs @@ -168,7 +168,11 @@ fn bindgen_test_layout_bar() { } impl Default for bar { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -201,7 +205,11 @@ fn bindgen_test_layout_Baz() { } impl Default for Baz { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } pub mod one_Foo { @@ -234,7 +242,11 @@ fn bindgen_test_layout_Bar() { } impl Default for Bar { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } extern "C" { @@ -261,7 +273,11 @@ pub struct Thing { } impl Default for Thing { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } extern "C" { diff --git a/tests/expectations/tests/convert-cpp-comment-to-rust.rs b/tests/expectations/tests/convert-cpp-comment-to-rust.rs index 451cfa31ad..86279caf47 100644 --- a/tests/expectations/tests/convert-cpp-comment-to-rust.rs +++ b/tests/expectations/tests/convert-cpp-comment-to-rust.rs @@ -68,6 +68,10 @@ fn bindgen_test_layout_mbedtls_mpi() { } impl Default for mbedtls_mpi { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/convert-floats.rs b/tests/expectations/tests/convert-floats.rs index a183f433f7..6623159211 100644 --- a/tests/expectations/tests/convert-floats.rs +++ b/tests/expectations/tests/convert-floats.rs @@ -85,6 +85,10 @@ fn bindgen_test_layout_foo() { } impl Default for foo { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/ctypes-prefix-path.rs b/tests/expectations/tests/ctypes-prefix-path.rs index af6087855e..12cedac955 100644 --- a/tests/expectations/tests/ctypes-prefix-path.rs +++ b/tests/expectations/tests/ctypes-prefix-path.rs @@ -49,6 +49,10 @@ fn bindgen_test_layout_foo() { } impl Default for foo { fn default() -> Self { - unsafe { ::core::mem::zeroed() } + let mut s = ::core::mem::MaybeUninit::::uninit(); + unsafe { + ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/default-template-parameter.rs b/tests/expectations/tests/default-template-parameter.rs index f42e23bf62..2cbe463cd9 100644 --- a/tests/expectations/tests/default-template-parameter.rs +++ b/tests/expectations/tests/default-template-parameter.rs @@ -15,7 +15,11 @@ pub struct Foo { } impl Default for Foo { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[test] diff --git a/tests/expectations/tests/derive-bitfield-method-same-name.rs b/tests/expectations/tests/derive-bitfield-method-same-name.rs index d1c1aefa79..1dc1d6e350 100644 --- a/tests/expectations/tests/derive-bitfield-method-same-name.rs +++ b/tests/expectations/tests/derive-bitfield-method-same-name.rs @@ -139,7 +139,11 @@ extern "C" { } impl Default for Foo { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl ::std::fmt::Debug for Foo { diff --git a/tests/expectations/tests/derive-clone.rs b/tests/expectations/tests/derive-clone.rs index e2dc7bdb92..e589a29ea3 100644 --- a/tests/expectations/tests/derive-clone.rs +++ b/tests/expectations/tests/derive-clone.rs @@ -39,6 +39,10 @@ fn bindgen_test_layout_ShouldDeriveClone() { } impl Default for ShouldDeriveClone { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/derive-clone_1_0.rs b/tests/expectations/tests/derive-clone_1_0.rs index e5dc92dc34..a437d5c314 100644 --- a/tests/expectations/tests/derive-clone_1_0.rs +++ b/tests/expectations/tests/derive-clone_1_0.rs @@ -45,6 +45,10 @@ impl Clone for ShouldImplClone { } impl Default for ShouldImplClone { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } diff --git a/tests/expectations/tests/derive-debug-bitfield-core.rs b/tests/expectations/tests/derive-debug-bitfield-core.rs index 76fa20bab8..33f0f2ffbc 100644 --- a/tests/expectations/tests/derive-debug-bitfield-core.rs +++ b/tests/expectations/tests/derive-debug-bitfield-core.rs @@ -127,7 +127,11 @@ fn bindgen_test_layout_C() { } impl Default for C { fn default() -> Self { - unsafe { ::core::mem::zeroed() } + let mut s = ::core::mem::MaybeUninit::::uninit(); + unsafe { + ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl ::core::fmt::Debug for C { diff --git a/tests/expectations/tests/derive-debug-bitfield.rs b/tests/expectations/tests/derive-debug-bitfield.rs index d07642a83a..00976b59df 100644 --- a/tests/expectations/tests/derive-debug-bitfield.rs +++ b/tests/expectations/tests/derive-debug-bitfield.rs @@ -125,7 +125,11 @@ fn bindgen_test_layout_C() { } impl Default for C { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl ::std::fmt::Debug for C { diff --git a/tests/expectations/tests/derive-debug-function-pointer.rs b/tests/expectations/tests/derive-debug-function-pointer.rs index 7052ff0014..c031897b6a 100644 --- a/tests/expectations/tests/derive-debug-function-pointer.rs +++ b/tests/expectations/tests/derive-debug-function-pointer.rs @@ -52,7 +52,11 @@ fn bindgen_test_layout_Nice() { } impl Default for Nice { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl ::std::fmt::Debug for Nice { diff --git a/tests/expectations/tests/derive-debug-generic.rs b/tests/expectations/tests/derive-debug-generic.rs index 88fd972833..49d4e9b89e 100644 --- a/tests/expectations/tests/derive-debug-generic.rs +++ b/tests/expectations/tests/derive-debug-generic.rs @@ -12,7 +12,11 @@ pub struct Generic { } impl Default for Generic { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl ::std::fmt::Debug for Generic { diff --git a/tests/expectations/tests/derive-debug-mangle-name.rs b/tests/expectations/tests/derive-debug-mangle-name.rs index d7f5c89208..ed5416486c 100644 --- a/tests/expectations/tests/derive-debug-mangle-name.rs +++ b/tests/expectations/tests/derive-debug-mangle-name.rs @@ -59,7 +59,11 @@ fn bindgen_test_layout_perf_event_attr__bindgen_ty_1() { } impl Default for perf_event_attr__bindgen_ty_1 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl ::std::fmt::Debug for perf_event_attr__bindgen_ty_1 { @@ -107,7 +111,11 @@ fn bindgen_test_layout_perf_event_attr() { } impl Default for perf_event_attr { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl ::std::fmt::Debug for perf_event_attr { diff --git a/tests/expectations/tests/derive-debug-opaque-template-instantiation.rs b/tests/expectations/tests/derive-debug-opaque-template-instantiation.rs index 4e87368b30..ceb70ffe4e 100644 --- a/tests/expectations/tests/derive-debug-opaque-template-instantiation.rs +++ b/tests/expectations/tests/derive-debug-opaque-template-instantiation.rs @@ -36,7 +36,11 @@ fn bindgen_test_layout_Instance() { } impl Default for Instance { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl ::std::fmt::Debug for Instance { diff --git a/tests/expectations/tests/derive-debug-opaque.rs b/tests/expectations/tests/derive-debug-opaque.rs index dfb264c7a0..411c7a7036 100644 --- a/tests/expectations/tests/derive-debug-opaque.rs +++ b/tests/expectations/tests/derive-debug-opaque.rs @@ -25,7 +25,11 @@ fn bindgen_test_layout_Opaque() { } impl Default for Opaque { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl ::std::fmt::Debug for Opaque { @@ -64,7 +68,11 @@ fn bindgen_test_layout_OpaqueUser() { } impl Default for OpaqueUser { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl ::std::fmt::Debug for OpaqueUser { diff --git a/tests/expectations/tests/derive-default-and-blocklist.rs b/tests/expectations/tests/derive-default-and-blocklist.rs index fca9c7f3cb..5d53ede28c 100644 --- a/tests/expectations/tests/derive-default-and-blocklist.rs +++ b/tests/expectations/tests/derive-default-and-blocklist.rs @@ -41,6 +41,10 @@ fn bindgen_test_layout_ShouldNotDeriveDefault() { } impl Default for ShouldNotDeriveDefault { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/derive-hash-and-blocklist.rs b/tests/expectations/tests/derive-hash-and-blocklist.rs index ba606a25fe..8e1190ea72 100644 --- a/tests/expectations/tests/derive-hash-and-blocklist.rs +++ b/tests/expectations/tests/derive-hash-and-blocklist.rs @@ -40,6 +40,10 @@ fn bindgen_test_layout_ShouldNotDeriveHash() { } impl Default for ShouldNotDeriveHash { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/derive-hash-blocklisting.rs b/tests/expectations/tests/derive-hash-blocklisting.rs index f9dbc824cf..7cd29c21d2 100644 --- a/tests/expectations/tests/derive-hash-blocklisting.rs +++ b/tests/expectations/tests/derive-hash-blocklisting.rs @@ -45,7 +45,11 @@ fn bindgen_test_layout_AllowlistedOne() { } impl Default for AllowlistedOne { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } /// This can't derive(Hash/Eq) even if it didn't contain a blocklisted type. @@ -80,6 +84,10 @@ fn bindgen_test_layout_AllowlistedTwo() { } impl Default for AllowlistedTwo { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/derive-hash-struct-with-pointer.rs b/tests/expectations/tests/derive-hash-struct-with-pointer.rs index 152bffc2e8..e98bbf0f32 100644 --- a/tests/expectations/tests/derive-hash-struct-with-pointer.rs +++ b/tests/expectations/tests/derive-hash-struct-with-pointer.rs @@ -38,7 +38,11 @@ fn bindgen_test_layout_ConstPtrMutObj() { } impl Default for ConstPtrMutObj { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -73,7 +77,11 @@ fn bindgen_test_layout_MutPtrMutObj() { } impl Default for MutPtrMutObj { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -108,7 +116,11 @@ fn bindgen_test_layout_MutPtrConstObj() { } impl Default for MutPtrConstObj { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -144,6 +156,10 @@ fn bindgen_test_layout_ConstPtrConstObj() { } impl Default for ConstPtrConstObj { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/derive-hash-template-def-float.rs b/tests/expectations/tests/derive-hash-template-def-float.rs index 554eb8bf7a..5e07a61115 100644 --- a/tests/expectations/tests/derive-hash-template-def-float.rs +++ b/tests/expectations/tests/derive-hash-template-def-float.rs @@ -15,6 +15,10 @@ pub struct foo { } impl Default for foo { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/derive-hash-template-inst-float.rs b/tests/expectations/tests/derive-hash-template-inst-float.rs index c0a7272554..f861815234 100644 --- a/tests/expectations/tests/derive-hash-template-inst-float.rs +++ b/tests/expectations/tests/derive-hash-template-inst-float.rs @@ -14,7 +14,11 @@ pub struct foo { } impl Default for foo { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } /// Can derive Hash/PartialOrd/Ord/PartialEq/Eq when instantiated with int @@ -43,7 +47,11 @@ fn bindgen_test_layout_IntStr() { } impl Default for IntStr { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } /// Cannot derive Hash/Eq/Ord when instantiated with float but can derive PartialEq/PartialOrd @@ -77,7 +85,11 @@ fn bindgen_test_layout_FloatStr() { } impl Default for FloatStr { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[test] diff --git a/tests/expectations/tests/derive-partialeq-and-blocklist.rs b/tests/expectations/tests/derive-partialeq-and-blocklist.rs index b211933d7c..d9dfb44618 100644 --- a/tests/expectations/tests/derive-partialeq-and-blocklist.rs +++ b/tests/expectations/tests/derive-partialeq-and-blocklist.rs @@ -41,6 +41,10 @@ fn bindgen_test_layout_ShouldNotDerivePartialEq() { } impl Default for ShouldNotDerivePartialEq { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/derive-partialeq-anonfield.rs b/tests/expectations/tests/derive-partialeq-anonfield.rs index 8834ca3245..16d4381f86 100644 --- a/tests/expectations/tests/derive-partialeq-anonfield.rs +++ b/tests/expectations/tests/derive-partialeq-anonfield.rs @@ -32,7 +32,11 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_1() { } impl Default for rte_mbuf__bindgen_ty_1 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[test] @@ -50,6 +54,10 @@ fn bindgen_test_layout_rte_mbuf() { } impl Default for rte_mbuf { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/derive-partialeq-base.rs b/tests/expectations/tests/derive-partialeq-base.rs index 9946616b34..cdf8dff8b4 100644 --- a/tests/expectations/tests/derive-partialeq-base.rs +++ b/tests/expectations/tests/derive-partialeq-base.rs @@ -35,7 +35,11 @@ fn bindgen_test_layout_Base() { } impl Default for Base { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl ::std::cmp::PartialEq for Base { @@ -63,7 +67,11 @@ fn bindgen_test_layout_ShouldDerivePartialEq() { } impl Default for ShouldDerivePartialEq { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl ::std::cmp::PartialEq for ShouldDerivePartialEq { diff --git a/tests/expectations/tests/derive-partialeq-bitfield.rs b/tests/expectations/tests/derive-partialeq-bitfield.rs index c7f1231ef8..cffffca57c 100644 --- a/tests/expectations/tests/derive-partialeq-bitfield.rs +++ b/tests/expectations/tests/derive-partialeq-bitfield.rs @@ -125,7 +125,11 @@ fn bindgen_test_layout_C() { } impl Default for C { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl ::std::cmp::PartialEq for C { diff --git a/tests/expectations/tests/derive-partialeq-core.rs b/tests/expectations/tests/derive-partialeq-core.rs index cbe1f57749..8cdfb92c6a 100644 --- a/tests/expectations/tests/derive-partialeq-core.rs +++ b/tests/expectations/tests/derive-partialeq-core.rs @@ -39,7 +39,11 @@ fn bindgen_test_layout_C() { } impl Default for C { fn default() -> Self { - unsafe { ::core::mem::zeroed() } + let mut s = ::core::mem::MaybeUninit::::uninit(); + unsafe { + ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl ::core::cmp::PartialEq for C { diff --git a/tests/expectations/tests/derive-partialeq-pointer.rs b/tests/expectations/tests/derive-partialeq-pointer.rs index 1964e3731b..17a5edcbbf 100644 --- a/tests/expectations/tests/derive-partialeq-pointer.rs +++ b/tests/expectations/tests/derive-partialeq-pointer.rs @@ -30,7 +30,11 @@ fn bindgen_test_layout_Bar() { } impl Default for Bar { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -58,7 +62,11 @@ fn bindgen_test_layout_c__bindgen_ty_1() { } impl Default for c__bindgen_ty_1 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[test] @@ -76,7 +84,11 @@ fn bindgen_test_layout_c() { } impl Default for c { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -104,6 +116,10 @@ fn bindgen_test_layout_a() { } impl Default for a { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/derive-partialeq-union.rs b/tests/expectations/tests/derive-partialeq-union.rs index b2ccb2e872..b97c053198 100644 --- a/tests/expectations/tests/derive-partialeq-union.rs +++ b/tests/expectations/tests/derive-partialeq-union.rs @@ -53,6 +53,10 @@ fn bindgen_test_layout_ShouldNotDerivePartialEq() { } impl Default for ShouldNotDerivePartialEq { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/derive-partialeq-union_1_0.rs b/tests/expectations/tests/derive-partialeq-union_1_0.rs index 4b675fc71c..2098849f99 100644 --- a/tests/expectations/tests/derive-partialeq-union_1_0.rs +++ b/tests/expectations/tests/derive-partialeq-union_1_0.rs @@ -102,7 +102,11 @@ impl Clone for ShouldDerivePartialEq { } impl Default for ShouldDerivePartialEq { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } impl ::std::cmp::PartialEq for ShouldDerivePartialEq { diff --git a/tests/expectations/tests/doggo-or-null.rs b/tests/expectations/tests/doggo-or-null.rs index 1d3bf5c16a..fa7a5e89dc 100644 --- a/tests/expectations/tests/doggo-or-null.rs +++ b/tests/expectations/tests/doggo-or-null.rs @@ -73,6 +73,10 @@ fn bindgen_test_layout_DoggoOrNull() { } impl Default for DoggoOrNull { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/duplicated-namespaces-definitions.rs b/tests/expectations/tests/duplicated-namespaces-definitions.rs index b79ccaea3a..324fe2a0a7 100644 --- a/tests/expectations/tests/duplicated-namespaces-definitions.rs +++ b/tests/expectations/tests/duplicated-namespaces-definitions.rs @@ -91,7 +91,11 @@ pub mod root { } impl Default for Foo { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } } diff --git a/tests/expectations/tests/empty-union.rs b/tests/expectations/tests/empty-union.rs index 1f7d33d36d..c21ae2f01f 100644 --- a/tests/expectations/tests/empty-union.rs +++ b/tests/expectations/tests/empty-union.rs @@ -12,6 +12,10 @@ pub union a__bindgen_ty_1 { } impl Default for a__bindgen_ty_1 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/enum-default-bitfield.rs b/tests/expectations/tests/enum-default-bitfield.rs index 3e8272ad91..1520bea70d 100644 --- a/tests/expectations/tests/enum-default-bitfield.rs +++ b/tests/expectations/tests/enum-default-bitfield.rs @@ -66,7 +66,11 @@ fn bindgen_test_layout_foo() { } impl Default for foo { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl Foo { diff --git a/tests/expectations/tests/enum-default-consts.rs b/tests/expectations/tests/enum-default-consts.rs index e913bcbf11..1a9513d928 100644 --- a/tests/expectations/tests/enum-default-consts.rs +++ b/tests/expectations/tests/enum-default-consts.rs @@ -38,7 +38,11 @@ fn bindgen_test_layout_foo() { } impl Default for foo { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } pub const Foo_Bar: Foo = 0; diff --git a/tests/expectations/tests/enum-default-module.rs b/tests/expectations/tests/enum-default-module.rs index b8355e3d3a..73a0462eac 100644 --- a/tests/expectations/tests/enum-default-module.rs +++ b/tests/expectations/tests/enum-default-module.rs @@ -40,7 +40,11 @@ fn bindgen_test_layout_foo() { } impl Default for foo { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } pub mod Foo { diff --git a/tests/expectations/tests/enum-default-rust.rs b/tests/expectations/tests/enum-default-rust.rs index 8c697dcc45..c47521a29c 100644 --- a/tests/expectations/tests/enum-default-rust.rs +++ b/tests/expectations/tests/enum-default-rust.rs @@ -43,7 +43,11 @@ fn bindgen_test_layout_foo() { } impl Default for foo { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(u32)] diff --git a/tests/expectations/tests/enum.rs b/tests/expectations/tests/enum.rs index e4a7227637..67d263e94c 100644 --- a/tests/expectations/tests/enum.rs +++ b/tests/expectations/tests/enum.rs @@ -38,7 +38,11 @@ fn bindgen_test_layout_foo() { } impl Default for foo { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } pub const Foo_Bar: Foo = 0; diff --git a/tests/expectations/tests/enum_and_vtable_mangling.rs b/tests/expectations/tests/enum_and_vtable_mangling.rs index 5eaaec95e0..9e9c6bcb2f 100644 --- a/tests/expectations/tests/enum_and_vtable_mangling.rs +++ b/tests/expectations/tests/enum_and_vtable_mangling.rs @@ -41,7 +41,11 @@ fn bindgen_test_layout_C() { } impl Default for C { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } extern "C" { diff --git a/tests/expectations/tests/extern-const-struct.rs b/tests/expectations/tests/extern-const-struct.rs index 0f515ed58b..fa0018ba90 100644 --- a/tests/expectations/tests/extern-const-struct.rs +++ b/tests/expectations/tests/extern-const-struct.rs @@ -37,7 +37,11 @@ fn bindgen_test_layout_nsFoo() { } impl Default for nsFoo { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } extern "C" { diff --git a/tests/expectations/tests/forward-declaration-autoptr.rs b/tests/expectations/tests/forward-declaration-autoptr.rs index 33a92bb476..bf0b6926f1 100644 --- a/tests/expectations/tests/forward-declaration-autoptr.rs +++ b/tests/expectations/tests/forward-declaration-autoptr.rs @@ -18,7 +18,11 @@ pub struct RefPtr { } impl Default for RefPtr { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -53,7 +57,11 @@ fn bindgen_test_layout_Bar() { } impl Default for Bar { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[test] diff --git a/tests/expectations/tests/forward-inherit-struct-with-fields.rs b/tests/expectations/tests/forward-inherit-struct-with-fields.rs index cae75bf4da..330d766b31 100644 --- a/tests/expectations/tests/forward-inherit-struct-with-fields.rs +++ b/tests/expectations/tests/forward-inherit-struct-with-fields.rs @@ -14,7 +14,11 @@ pub struct js_RootedBase { } impl Default for js_RootedBase { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -25,6 +29,10 @@ pub struct Rooted { } impl Default for Rooted { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/forward-inherit-struct.rs b/tests/expectations/tests/forward-inherit-struct.rs index ae565be5b3..2c4546eb41 100644 --- a/tests/expectations/tests/forward-inherit-struct.rs +++ b/tests/expectations/tests/forward-inherit-struct.rs @@ -17,6 +17,10 @@ pub struct Rooted { } impl Default for Rooted { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/forward_declared_complex_types.rs b/tests/expectations/tests/forward_declared_complex_types.rs index c35d914c2d..e185e83064 100644 --- a/tests/expectations/tests/forward_declared_complex_types.rs +++ b/tests/expectations/tests/forward_declared_complex_types.rs @@ -53,7 +53,11 @@ fn bindgen_test_layout_Bar() { } impl Default for Bar { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } extern "C" { diff --git a/tests/expectations/tests/forward_declared_complex_types_1_0.rs b/tests/expectations/tests/forward_declared_complex_types_1_0.rs index 9fea597c0a..c6331c6941 100644 --- a/tests/expectations/tests/forward_declared_complex_types_1_0.rs +++ b/tests/expectations/tests/forward_declared_complex_types_1_0.rs @@ -68,7 +68,11 @@ impl Clone for Bar { } impl Default for Bar { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } extern "C" { diff --git a/tests/expectations/tests/incomplete-array-padding.rs b/tests/expectations/tests/incomplete-array-padding.rs index a0fa750c6a..18061ea12a 100644 --- a/tests/expectations/tests/incomplete-array-padding.rs +++ b/tests/expectations/tests/incomplete-array-padding.rs @@ -143,7 +143,11 @@ fn bindgen_test_layout_foo() { } impl Default for foo { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl foo { diff --git a/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs b/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs index c488713fc7..f292125d1c 100644 --- a/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs +++ b/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs @@ -17,7 +17,11 @@ pub struct BaseWithVtable { } impl Default for BaseWithVtable { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } /// This should not have an explicit vtable. @@ -41,7 +45,11 @@ fn bindgen_test_layout_DerivedWithNoVirtualMethods() { } impl Default for DerivedWithNoVirtualMethods { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } /// This should not have an explicit vtable. @@ -65,7 +73,11 @@ fn bindgen_test_layout_DerivedWithVirtualMethods() { } impl Default for DerivedWithVirtualMethods { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } /// This should not have any vtable. @@ -77,7 +89,11 @@ pub struct BaseWithoutVtable { } impl Default for BaseWithoutVtable { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -104,7 +120,11 @@ fn bindgen_test_layout_DerivedWithVtable() { } impl Default for DerivedWithVtable { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } /// This should not have any vtable. @@ -128,7 +148,11 @@ fn bindgen_test_layout_DerivedWithoutVtable() { } impl Default for DerivedWithoutVtable { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[test] diff --git a/tests/expectations/tests/inherit-namespaced.rs b/tests/expectations/tests/inherit-namespaced.rs index ae565be5b3..2c4546eb41 100644 --- a/tests/expectations/tests/inherit-namespaced.rs +++ b/tests/expectations/tests/inherit-namespaced.rs @@ -17,6 +17,10 @@ pub struct Rooted { } impl Default for Rooted { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/inherit_named.rs b/tests/expectations/tests/inherit_named.rs index 77de3ec3f4..a8eee20767 100644 --- a/tests/expectations/tests/inherit_named.rs +++ b/tests/expectations/tests/inherit_named.rs @@ -18,6 +18,10 @@ pub struct Weeee { } impl Default for Weeee { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/inline_namespace_no_ns_enabled.rs b/tests/expectations/tests/inline_namespace_no_ns_enabled.rs index 20bac9a137..7a0c993555 100644 --- a/tests/expectations/tests/inline_namespace_no_ns_enabled.rs +++ b/tests/expectations/tests/inline_namespace_no_ns_enabled.rs @@ -20,7 +20,11 @@ pub struct std_basic_string_Alloc_hider { } impl Default for std_basic_string_Alloc_hider { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -31,11 +35,19 @@ pub struct std_basic_string__bindgen_ty_1 { } impl Default for std_basic_string__bindgen_ty_1 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl Default for std_basic_string { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/inner_template_self.rs b/tests/expectations/tests/inner_template_self.rs index f3e153f495..3361a1f9dd 100644 --- a/tests/expectations/tests/inner_template_self.rs +++ b/tests/expectations/tests/inner_template_self.rs @@ -13,7 +13,11 @@ pub struct LinkedList { } impl Default for LinkedList { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -49,7 +53,11 @@ fn bindgen_test_layout_InstantiateIt() { } impl Default for InstantiateIt { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[test] diff --git a/tests/expectations/tests/issue-1113-template-references.rs b/tests/expectations/tests/issue-1113-template-references.rs index 79a06dac9f..c146583521 100644 --- a/tests/expectations/tests/issue-1113-template-references.rs +++ b/tests/expectations/tests/issue-1113-template-references.rs @@ -15,7 +15,11 @@ pub struct Entry { } impl Default for Entry { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -34,6 +38,10 @@ pub struct nsBaseHashtable_EntryPtr { } impl Default for nsBaseHashtable_EntryPtr { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/issue-1118-using-forward-decl.rs b/tests/expectations/tests/issue-1118-using-forward-decl.rs index df764a583e..99f0341c9d 100644 --- a/tests/expectations/tests/issue-1118-using-forward-decl.rs +++ b/tests/expectations/tests/issue-1118-using-forward-decl.rs @@ -38,7 +38,11 @@ fn bindgen_test_layout_nsTArray_base() { } impl Default for nsTArray_base { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -48,7 +52,11 @@ pub struct nsTArray { } impl Default for nsTArray { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -83,7 +91,11 @@ fn bindgen_test_layout_nsIContent() { } impl Default for nsIContent { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } extern "C" { diff --git a/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs b/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs index 9232767e34..fd023363d7 100644 --- a/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs +++ b/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs @@ -27,6 +27,10 @@ fn bindgen_test_layout_Foo() { } impl Default for Foo { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/issue-1285.rs b/tests/expectations/tests/issue-1285.rs index 4ca8452739..15b8c9e449 100644 --- a/tests/expectations/tests/issue-1285.rs +++ b/tests/expectations/tests/issue-1285.rs @@ -55,7 +55,11 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { } impl Default for foo__bindgen_ty_1 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[test] @@ -78,6 +82,10 @@ fn bindgen_test_layout_foo() { } impl Default for foo { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/issue-1443.rs b/tests/expectations/tests/issue-1443.rs index b02a2c4d8f..f422f4c353 100644 --- a/tests/expectations/tests/issue-1443.rs +++ b/tests/expectations/tests/issue-1443.rs @@ -41,7 +41,11 @@ fn bindgen_test_layout_Bar() { } impl Default for Bar { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -75,7 +79,11 @@ fn bindgen_test_layout_Baz() { } impl Default for Baz { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -109,7 +117,11 @@ fn bindgen_test_layout_Tar() { } impl Default for Tar { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -143,6 +155,10 @@ fn bindgen_test_layout_Taz() { } impl Default for Taz { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/issue-1498.rs b/tests/expectations/tests/issue-1498.rs index b14f06c869..4f8a89305b 100644 --- a/tests/expectations/tests/issue-1498.rs +++ b/tests/expectations/tests/issue-1498.rs @@ -72,7 +72,11 @@ fn bindgen_test_layout_rte_memseg__bindgen_ty_1() { } impl Default for rte_memseg__bindgen_ty_1 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[test] @@ -165,6 +169,10 @@ fn bindgen_test_layout_rte_memseg() { } impl Default for rte_memseg { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/issue-1514.rs b/tests/expectations/tests/issue-1514.rs index b2c11ea984..31939ca588 100644 --- a/tests/expectations/tests/issue-1514.rs +++ b/tests/expectations/tests/issue-1514.rs @@ -18,7 +18,11 @@ pub struct Thing_Inner { } impl Default for Thing_Inner { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -29,6 +33,10 @@ pub struct Thing_AnotherInner { } impl Default for Thing_AnotherInner { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/issue-358.rs b/tests/expectations/tests/issue-358.rs index 320c7e1d89..e9ee0f502f 100644 --- a/tests/expectations/tests/issue-358.rs +++ b/tests/expectations/tests/issue-358.rs @@ -12,7 +12,11 @@ pub struct JS_PersistentRooted { } impl Default for JS_PersistentRooted { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -22,6 +26,10 @@ pub struct a { } impl Default for a { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/issue-372.rs b/tests/expectations/tests/issue-372.rs index ce6e36c5b2..0cd9f7adb3 100644 --- a/tests/expectations/tests/issue-372.rs +++ b/tests/expectations/tests/issue-372.rs @@ -46,7 +46,11 @@ pub mod root { } impl Default for i { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -74,7 +78,11 @@ pub mod root { } impl Default for d { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(u32)] @@ -117,7 +125,11 @@ pub mod root { } impl Default for F { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } } diff --git a/tests/expectations/tests/issue-446.rs b/tests/expectations/tests/issue-446.rs index 6c9cae462f..db69f159c7 100644 --- a/tests/expectations/tests/issue-446.rs +++ b/tests/expectations/tests/issue-446.rs @@ -12,7 +12,11 @@ pub struct List { } impl Default for List { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -22,6 +26,10 @@ pub struct PersistentRooted { } impl Default for PersistentRooted { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/issue-493.rs b/tests/expectations/tests/issue-493.rs index d17fbeccb0..61c7f7929e 100644 --- a/tests/expectations/tests/issue-493.rs +++ b/tests/expectations/tests/issue-493.rs @@ -65,7 +65,11 @@ pub struct basic_string___long { } impl Default for basic_string___long { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } pub const basic_string___min_cap: basic_string__bindgen_ty_1 = @@ -87,12 +91,20 @@ pub union basic_string___short__bindgen_ty_1 { } impl Default for basic_string___short__bindgen_ty_1 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl Default for basic_string___short { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -104,7 +116,11 @@ pub struct basic_string___ulx { } impl Default for basic_string___ulx { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } pub const basic_string___n_words: basic_string__bindgen_ty_2 = @@ -121,7 +137,11 @@ pub struct basic_string___raw { } impl Default for basic_string___raw { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -138,11 +158,19 @@ pub struct basic_string___rep__bindgen_ty_1 { } impl Default for basic_string___rep__bindgen_ty_1 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl Default for basic_string___rep { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/issue-493_1_0.rs b/tests/expectations/tests/issue-493_1_0.rs index c42d06b5b1..1a0131c327 100644 --- a/tests/expectations/tests/issue-493_1_0.rs +++ b/tests/expectations/tests/issue-493_1_0.rs @@ -65,7 +65,11 @@ pub struct basic_string___long { } impl Default for basic_string___long { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } pub const basic_string___min_cap: basic_string__bindgen_ty_1 = @@ -90,7 +94,11 @@ pub struct basic_string___short__bindgen_ty_1 { } impl Default for basic_string___short { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } #[repr(C)] @@ -114,7 +122,11 @@ pub struct basic_string___raw { } impl Default for basic_string___raw { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } #[repr(C)] diff --git a/tests/expectations/tests/issue-544-stylo-creduce-2.rs b/tests/expectations/tests/issue-544-stylo-creduce-2.rs index 5a6242ea8e..6165419d65 100644 --- a/tests/expectations/tests/issue-544-stylo-creduce-2.rs +++ b/tests/expectations/tests/issue-544-stylo-creduce-2.rs @@ -13,6 +13,10 @@ pub type Foo_FirstAlias = [u8; 0usize]; pub type Foo_SecondAlias = [u8; 0usize]; impl Default for Foo { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs b/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs index 4b2fa7a2af..997a73112d 100644 --- a/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs +++ b/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs @@ -21,7 +21,11 @@ pub struct JS_Base { } impl Default for JS_Base { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -44,7 +48,11 @@ fn bindgen_test_layout_JS_AutoIdVector() { } impl Default for JS_AutoIdVector { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[test] diff --git a/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs b/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs index 61489990a6..01abdcc412 100644 --- a/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs +++ b/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs @@ -33,7 +33,11 @@ pub struct e { } impl Default for e { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -65,7 +69,11 @@ fn bindgen_test_layout_g() { } impl Default for g { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -87,7 +95,11 @@ fn bindgen_test_layout_b() { } impl Default for b { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } extern "C" { diff --git a/tests/expectations/tests/issue-638-stylo-cannot-find-T-in-this-scope.rs b/tests/expectations/tests/issue-638-stylo-cannot-find-T-in-this-scope.rs index 8c3ad474fd..ba886f361e 100644 --- a/tests/expectations/tests/issue-638-stylo-cannot-find-T-in-this-scope.rs +++ b/tests/expectations/tests/issue-638-stylo-cannot-find-T-in-this-scope.rs @@ -13,7 +13,11 @@ pub struct RefPtr { } impl Default for RefPtr { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -25,6 +29,10 @@ pub struct UsesRefPtrWithAliasedTypeParam { pub type UsesRefPtrWithAliasedTypeParam_V = U; impl Default for UsesRefPtrWithAliasedTypeParam { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/issue-643-inner-struct.rs b/tests/expectations/tests/issue-643-inner-struct.rs index 35a5e52ca3..0728500754 100644 --- a/tests/expectations/tests/issue-643-inner-struct.rs +++ b/tests/expectations/tests/issue-643-inner-struct.rs @@ -120,7 +120,11 @@ fn bindgen_test_layout_rte_ring() { } impl Default for rte_ring { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] diff --git a/tests/expectations/tests/issue-645-cannot-find-type-T-in-this-scope.rs b/tests/expectations/tests/issue-645-cannot-find-type-T-in-this-scope.rs index 176fae6438..75d6581e2d 100644 --- a/tests/expectations/tests/issue-645-cannot-find-type-T-in-this-scope.rs +++ b/tests/expectations/tests/issue-645-cannot-find-type-T-in-this-scope.rs @@ -16,6 +16,10 @@ pub struct HasRefPtr { pub type HasRefPtr_TypedefOfT = T; impl Default for HasRefPtr { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/issue-648-derive-debug-with-padding.rs b/tests/expectations/tests/issue-648-derive-debug-with-padding.rs index e6d529f0c0..15822b5bdf 100644 --- a/tests/expectations/tests/issue-648-derive-debug-with-padding.rs +++ b/tests/expectations/tests/issue-648-derive-debug-with-padding.rs @@ -40,7 +40,11 @@ fn bindgen_test_layout_NoDebug() { } impl Default for NoDebug { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl ::std::cmp::PartialEq for NoDebug { @@ -100,7 +104,11 @@ fn bindgen_test_layout_ShouldDeriveDebugButDoesNot() { } impl Default for ShouldDeriveDebugButDoesNot { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl ::std::cmp::PartialEq for ShouldDeriveDebugButDoesNot { diff --git a/tests/expectations/tests/issue-662-cannot-find-T-in-this-scope.rs b/tests/expectations/tests/issue-662-cannot-find-T-in-this-scope.rs index d12c871525..5636a977b4 100644 --- a/tests/expectations/tests/issue-662-cannot-find-T-in-this-scope.rs +++ b/tests/expectations/tests/issue-662-cannot-find-T-in-this-scope.rs @@ -13,7 +13,11 @@ pub struct RefPtr { } impl Default for RefPtr { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -24,7 +28,11 @@ pub struct nsMainThreadPtrHolder { } impl Default for nsMainThreadPtrHolder { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -35,6 +43,10 @@ pub struct nsMainThreadPtrHandle { } impl Default for nsMainThreadPtrHandle { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/issue-662-part-2.rs b/tests/expectations/tests/issue-662-part-2.rs index d08e6fb810..e8d14bfe89 100644 --- a/tests/expectations/tests/issue-662-part-2.rs +++ b/tests/expectations/tests/issue-662-part-2.rs @@ -16,7 +16,11 @@ pub struct nsMainThreadPtrHolder { } impl Default for nsMainThreadPtrHolder { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -26,6 +30,10 @@ pub struct nsMainThreadPtrHandle { } impl Default for nsMainThreadPtrHandle { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/issue-691-template-parameter-virtual.rs b/tests/expectations/tests/issue-691-template-parameter-virtual.rs index 3d20728211..4747b955a3 100644 --- a/tests/expectations/tests/issue-691-template-parameter-virtual.rs +++ b/tests/expectations/tests/issue-691-template-parameter-virtual.rs @@ -27,7 +27,11 @@ fn bindgen_test_layout_VirtualMethods() { } impl Default for VirtualMethods { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -55,7 +59,11 @@ fn bindgen_test_layout_ServoElementSnapshotTable() { } impl Default for ServoElementSnapshotTable { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[test] diff --git a/tests/expectations/tests/issue-848-replacement-system-include.rs b/tests/expectations/tests/issue-848-replacement-system-include.rs index af91e1ec71..294df575da 100644 --- a/tests/expectations/tests/issue-848-replacement-system-include.rs +++ b/tests/expectations/tests/issue-848-replacement-system-include.rs @@ -19,7 +19,11 @@ pub struct nsTArray { } impl Default for nsTArray { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } extern "C" { diff --git a/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs b/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs index 51e97964d3..dc50fe1bfa 100644 --- a/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs +++ b/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs @@ -39,6 +39,10 @@ fn bindgen_test_layout_ShouldNotBeCopy() { } impl Default for ShouldNotBeCopy { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/jsval_layout_opaque.rs b/tests/expectations/tests/jsval_layout_opaque.rs index 8a3d7f3954..5b8427913c 100644 --- a/tests/expectations/tests/jsval_layout_opaque.rs +++ b/tests/expectations/tests/jsval_layout_opaque.rs @@ -211,7 +211,11 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_1() { } impl Default for jsval_layout__bindgen_ty_1 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl jsval_layout__bindgen_ty_1 { @@ -331,7 +335,11 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2__bindgen_ty_1() { } impl Default for jsval_layout__bindgen_ty_2__bindgen_ty_1 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[test] @@ -362,7 +370,11 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2() { } impl Default for jsval_layout__bindgen_ty_2 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[test] @@ -467,7 +479,11 @@ fn bindgen_test_layout_jsval_layout() { } impl Default for jsval_layout { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -500,6 +516,10 @@ fn bindgen_test_layout_Value() { } impl Default for Value { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/jsval_layout_opaque_1_0.rs b/tests/expectations/tests/jsval_layout_opaque_1_0.rs index e593a2c75b..260282dbba 100644 --- a/tests/expectations/tests/jsval_layout_opaque_1_0.rs +++ b/tests/expectations/tests/jsval_layout_opaque_1_0.rs @@ -260,7 +260,11 @@ impl Clone for jsval_layout__bindgen_ty_1 { } impl Default for jsval_layout__bindgen_ty_1 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } impl jsval_layout__bindgen_ty_1 { diff --git a/tests/expectations/tests/layout.rs b/tests/expectations/tests/layout.rs index cf42d30277..ae417259cd 100644 --- a/tests/expectations/tests/layout.rs +++ b/tests/expectations/tests/layout.rs @@ -19,6 +19,10 @@ fn bindgen_test_layout_header() { } impl Default for header { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } diff --git a/tests/expectations/tests/layout_align.rs b/tests/expectations/tests/layout_align.rs index 44998a8947..cb34df3e76 100644 --- a/tests/expectations/tests/layout_align.rs +++ b/tests/expectations/tests/layout_align.rs @@ -150,7 +150,11 @@ fn bindgen_test_layout_rte_kni_fifo() { } impl Default for rte_kni_fifo { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] diff --git a/tests/expectations/tests/layout_array.rs b/tests/expectations/tests/layout_array.rs index 3ca20b01d5..3ba1b6d0ba 100644 --- a/tests/expectations/tests/layout_array.rs +++ b/tests/expectations/tests/layout_array.rs @@ -160,7 +160,11 @@ fn bindgen_test_layout_rte_mempool_ops() { } impl Default for rte_mempool_ops { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl ::std::cmp::PartialEq for rte_mempool_ops { @@ -279,7 +283,11 @@ fn bindgen_test_layout_rte_mempool_ops_table() { } impl Default for rte_mempool_ops_table { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } /// Structure to hold malloc heap @@ -325,7 +333,11 @@ fn bindgen_test_layout_malloc_heap__bindgen_ty_1() { } impl Default for malloc_heap__bindgen_ty_1 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[test] @@ -394,7 +406,11 @@ fn bindgen_test_layout_malloc_heap() { } impl Default for malloc_heap { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl ::std::cmp::PartialEq for malloc_heap { diff --git a/tests/expectations/tests/layout_array_too_long.rs b/tests/expectations/tests/layout_array_too_long.rs index 9fe993a468..c9880ea2a9 100644 --- a/tests/expectations/tests/layout_array_too_long.rs +++ b/tests/expectations/tests/layout_array_too_long.rs @@ -78,7 +78,11 @@ fn bindgen_test_layout_ip_frag() { } impl Default for ip_frag { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } /// @internal to uniquely indetify fragmented datagram. @@ -209,7 +213,11 @@ fn bindgen_test_layout_ip_frag_pkt__bindgen_ty_1() { } impl Default for ip_frag_pkt__bindgen_ty_1 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[test] @@ -314,7 +322,11 @@ fn bindgen_test_layout_ip_frag_pkt() { } impl Default for ip_frag_pkt { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl ::std::cmp::PartialEq for ip_frag_pkt { diff --git a/tests/expectations/tests/layout_cmdline_token.rs b/tests/expectations/tests/layout_cmdline_token.rs index 601e88b562..644b1b8aab 100644 --- a/tests/expectations/tests/layout_cmdline_token.rs +++ b/tests/expectations/tests/layout_cmdline_token.rs @@ -54,7 +54,11 @@ fn bindgen_test_layout_cmdline_token_hdr() { } impl Default for cmdline_token_hdr { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } pub type cmdline_parse_token_hdr_t = cmdline_token_hdr; @@ -221,7 +225,11 @@ fn bindgen_test_layout_cmdline_token_num_data() { } impl Default for cmdline_token_num_data { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -271,7 +279,11 @@ fn bindgen_test_layout_cmdline_token_num() { } impl Default for cmdline_token_num { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } pub type cmdline_parse_token_num_t = cmdline_token_num; diff --git a/tests/expectations/tests/layout_eth_conf.rs b/tests/expectations/tests/layout_eth_conf.rs index fe8b92fecd..e880608203 100644 --- a/tests/expectations/tests/layout_eth_conf.rs +++ b/tests/expectations/tests/layout_eth_conf.rs @@ -212,7 +212,11 @@ fn bindgen_test_layout_rte_eth_rxmode() { } impl Default for rte_eth_rxmode { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl rte_eth_rxmode { @@ -459,7 +463,11 @@ fn bindgen_test_layout_rte_eth_txmode() { } impl Default for rte_eth_txmode { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl rte_eth_txmode { @@ -607,7 +615,11 @@ fn bindgen_test_layout_rte_eth_rss_conf() { } impl Default for rte_eth_rss_conf { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(u32)] @@ -801,7 +813,11 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { } impl Default for rte_eth_vmdq_dcb_conf { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -853,7 +869,11 @@ fn bindgen_test_layout_rte_eth_dcb_rx_conf() { } impl Default for rte_eth_dcb_rx_conf { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -905,7 +925,11 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_tx_conf() { } impl Default for rte_eth_vmdq_dcb_tx_conf { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -957,7 +981,11 @@ fn bindgen_test_layout_rte_eth_dcb_tx_conf() { } impl Default for rte_eth_dcb_tx_conf { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -994,7 +1022,11 @@ fn bindgen_test_layout_rte_eth_vmdq_tx_conf() { } impl Default for rte_eth_vmdq_tx_conf { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -1171,7 +1203,11 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { } impl Default for rte_eth_vmdq_rx_conf { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(u32)] @@ -1600,7 +1636,11 @@ fn bindgen_test_layout_rte_eth_flex_payload_cfg() { } impl Default for rte_eth_flex_payload_cfg { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } /// A structure used to define FDIR masks for flexible payload @@ -1729,7 +1769,11 @@ fn bindgen_test_layout_rte_eth_fdir_flex_conf() { } impl Default for rte_eth_fdir_flex_conf { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } /// A structure used to configure the Flow Director (FDIR) feature @@ -1841,7 +1885,11 @@ fn bindgen_test_layout_rte_fdir_conf() { } impl Default for rte_fdir_conf { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } /// A structure used to enable/disable specific device interrupts. @@ -2002,7 +2050,11 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_1() { } impl Default for rte_eth_conf__bindgen_ty_1 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -2066,7 +2118,11 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_2() { } impl Default for rte_eth_conf__bindgen_ty_2 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[test] @@ -2199,6 +2255,10 @@ fn bindgen_test_layout_rte_eth_conf() { } impl Default for rte_eth_conf { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/layout_eth_conf_1_0.rs b/tests/expectations/tests/layout_eth_conf_1_0.rs index 26d2db0295..fde1c678cf 100644 --- a/tests/expectations/tests/layout_eth_conf_1_0.rs +++ b/tests/expectations/tests/layout_eth_conf_1_0.rs @@ -260,7 +260,11 @@ impl Clone for rte_eth_rxmode { } impl Default for rte_eth_rxmode { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } impl rte_eth_rxmode { @@ -512,7 +516,11 @@ impl Clone for rte_eth_txmode { } impl Default for rte_eth_txmode { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } impl rte_eth_txmode { @@ -665,7 +673,11 @@ impl Clone for rte_eth_rss_conf { } impl Default for rte_eth_rss_conf { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } #[repr(u32)] @@ -869,7 +881,11 @@ impl Clone for rte_eth_vmdq_dcb_conf { } impl Default for rte_eth_vmdq_dcb_conf { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } #[repr(C)] @@ -926,7 +942,11 @@ impl Clone for rte_eth_dcb_rx_conf { } impl Default for rte_eth_dcb_rx_conf { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } #[repr(C)] @@ -983,7 +1003,11 @@ impl Clone for rte_eth_vmdq_dcb_tx_conf { } impl Default for rte_eth_vmdq_dcb_tx_conf { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } #[repr(C)] @@ -1040,7 +1064,11 @@ impl Clone for rte_eth_dcb_tx_conf { } impl Default for rte_eth_dcb_tx_conf { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } #[repr(C)] @@ -1082,7 +1110,11 @@ impl Clone for rte_eth_vmdq_tx_conf { } impl Default for rte_eth_vmdq_tx_conf { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } #[repr(C)] @@ -1269,7 +1301,11 @@ impl Clone for rte_eth_vmdq_rx_conf { } impl Default for rte_eth_vmdq_rx_conf { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } #[repr(u32)] @@ -1718,7 +1754,11 @@ impl Clone for rte_eth_flex_payload_cfg { } impl Default for rte_eth_flex_payload_cfg { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } /// A structure used to define FDIR masks for flexible payload @@ -1857,7 +1897,11 @@ impl Clone for rte_eth_fdir_flex_conf { } impl Default for rte_eth_fdir_flex_conf { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } /// A structure used to configure the Flow Director (FDIR) feature @@ -1974,7 +2018,11 @@ impl Clone for rte_fdir_conf { } impl Default for rte_fdir_conf { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } /// A structure used to enable/disable specific device interrupts. @@ -2145,7 +2193,11 @@ impl Clone for rte_eth_conf__bindgen_ty_1 { } impl Default for rte_eth_conf__bindgen_ty_1 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } #[repr(C)] @@ -2348,6 +2400,10 @@ impl Clone for rte_eth_conf { } impl Default for rte_eth_conf { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } diff --git a/tests/expectations/tests/layout_kni_mbuf.rs b/tests/expectations/tests/layout_kni_mbuf.rs index fce9dbac10..e73344c7d0 100644 --- a/tests/expectations/tests/layout_kni_mbuf.rs +++ b/tests/expectations/tests/layout_kni_mbuf.rs @@ -222,6 +222,10 @@ fn bindgen_test_layout_rte_kni_mbuf() { } impl Default for rte_kni_mbuf { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/layout_large_align_field.rs b/tests/expectations/tests/layout_large_align_field.rs index 3cf3174548..4208e7259c 100644 --- a/tests/expectations/tests/layout_large_align_field.rs +++ b/tests/expectations/tests/layout_large_align_field.rs @@ -108,7 +108,11 @@ fn bindgen_test_layout_ip_frag() { } impl Default for ip_frag { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } /// @internal to uniquely indetify fragmented datagram. @@ -239,7 +243,11 @@ fn bindgen_test_layout_ip_frag_pkt__bindgen_ty_1() { } impl Default for ip_frag_pkt__bindgen_ty_1 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[test] @@ -344,7 +352,11 @@ fn bindgen_test_layout_ip_frag_pkt() { } impl Default for ip_frag_pkt { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -394,7 +406,11 @@ fn bindgen_test_layout_ip_pkt_list() { } impl Default for ip_pkt_list { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } /// fragmentation table statistics @@ -508,7 +524,11 @@ fn bindgen_test_layout_ip_frag_tbl_stat() { } impl Default for ip_frag_tbl_stat { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } /// fragmentation table @@ -695,7 +715,11 @@ fn bindgen_test_layout_rte_ip_frag_tbl() { } impl Default for rte_ip_frag_tbl { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } ///< fragment mbuf diff --git a/tests/expectations/tests/layout_mbuf.rs b/tests/expectations/tests/layout_mbuf.rs index bc456a1800..aefce3d6e3 100644 --- a/tests/expectations/tests/layout_mbuf.rs +++ b/tests/expectations/tests/layout_mbuf.rs @@ -231,7 +231,11 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_1() { } impl Default for rte_mbuf__bindgen_ty_1 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -433,7 +437,11 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_2() { } impl Default for rte_mbuf__bindgen_ty_2 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -514,7 +522,11 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1() { } impl Default for rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[test] @@ -551,7 +563,11 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1() { } impl Default for rte_mbuf__bindgen_ty_3__bindgen_ty_1 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -672,7 +688,11 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3() { } impl Default for rte_mbuf__bindgen_ty_3 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -724,7 +744,11 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_4() { } impl Default for rte_mbuf__bindgen_ty_4 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -907,7 +931,11 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_5() { } impl Default for rte_mbuf__bindgen_ty_5 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[test] @@ -1180,7 +1208,11 @@ fn bindgen_test_layout_rte_mbuf() { } impl Default for rte_mbuf { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } ///< Pool from which mbuf was allocated. diff --git a/tests/expectations/tests/layout_mbuf_1_0.rs b/tests/expectations/tests/layout_mbuf_1_0.rs index 70d96d958b..ce4c66c2f0 100644 --- a/tests/expectations/tests/layout_mbuf_1_0.rs +++ b/tests/expectations/tests/layout_mbuf_1_0.rs @@ -1254,7 +1254,11 @@ fn bindgen_test_layout_rte_mbuf() { } impl Default for rte_mbuf { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } ///< Pool from which mbuf was allocated. diff --git a/tests/expectations/tests/libclang-3.9/issue-769-bad-instantiation-test.rs b/tests/expectations/tests/libclang-3.9/issue-769-bad-instantiation-test.rs index c084de95d2..47e166c76b 100644 --- a/tests/expectations/tests/libclang-3.9/issue-769-bad-instantiation-test.rs +++ b/tests/expectations/tests/libclang-3.9/issue-769-bad-instantiation-test.rs @@ -17,7 +17,11 @@ pub mod root { } impl Default for Rooted { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[test] diff --git a/tests/expectations/tests/libclang-4/issue-769-bad-instantiation-test.rs b/tests/expectations/tests/libclang-4/issue-769-bad-instantiation-test.rs index 45bcb6f561..60857966ce 100644 --- a/tests/expectations/tests/libclang-4/issue-769-bad-instantiation-test.rs +++ b/tests/expectations/tests/libclang-4/issue-769-bad-instantiation-test.rs @@ -17,7 +17,11 @@ pub mod root { } impl Default for Rooted { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } pub type AutoValueVector_Alias = ::std::os::raw::c_int; diff --git a/tests/expectations/tests/libclang-4/type_alias_template_specialized.rs b/tests/expectations/tests/libclang-4/type_alias_template_specialized.rs index 38f3bfb1c0..f874e9d221 100644 --- a/tests/expectations/tests/libclang-4/type_alias_template_specialized.rs +++ b/tests/expectations/tests/libclang-4/type_alias_template_specialized.rs @@ -35,7 +35,11 @@ fn bindgen_test_layout_Rooted() { } impl Default for Rooted { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } ///

diff --git a/tests/expectations/tests/libclang-5/issue-769-bad-instantiation-test.rs b/tests/expectations/tests/libclang-5/issue-769-bad-instantiation-test.rs index 45bcb6f561..60857966ce 100644 --- a/tests/expectations/tests/libclang-5/issue-769-bad-instantiation-test.rs +++ b/tests/expectations/tests/libclang-5/issue-769-bad-instantiation-test.rs @@ -17,7 +17,11 @@ pub mod root { } impl Default for Rooted { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } pub type AutoValueVector_Alias = ::std::os::raw::c_int; diff --git a/tests/expectations/tests/libclang-5/type_alias_template_specialized.rs b/tests/expectations/tests/libclang-5/type_alias_template_specialized.rs index 38f3bfb1c0..f874e9d221 100644 --- a/tests/expectations/tests/libclang-5/type_alias_template_specialized.rs +++ b/tests/expectations/tests/libclang-5/type_alias_template_specialized.rs @@ -35,7 +35,11 @@ fn bindgen_test_layout_Rooted() { } impl Default for Rooted { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } ///
diff --git a/tests/expectations/tests/libclang-9/class.rs b/tests/expectations/tests/libclang-9/class.rs index beea517eed..e4527de0e2 100644 --- a/tests/expectations/tests/libclang-9/class.rs +++ b/tests/expectations/tests/libclang-9/class.rs @@ -71,7 +71,11 @@ fn bindgen_test_layout_C() { } impl Default for C { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -134,7 +138,11 @@ fn bindgen_test_layout_C_with_zero_length_array() { } impl Default for C_with_zero_length_array { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -242,7 +250,11 @@ fn bindgen_test_layout_C_with_incomplete_array() { } impl Default for C_with_incomplete_array { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -378,7 +390,11 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { } impl Default for C_with_zero_length_array_and_incomplete_array { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -528,7 +544,11 @@ fn bindgen_test_layout_IncompleteArrayNonCopiable() { } impl Default for IncompleteArrayNonCopiable { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -562,7 +582,11 @@ fn bindgen_test_layout_Union() { } impl Default for Union { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -597,7 +621,11 @@ fn bindgen_test_layout_WithUnion() { } impl Default for WithUnion { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] diff --git a/tests/expectations/tests/libclang-9/class_1_0.rs b/tests/expectations/tests/libclang-9/class_1_0.rs index d527dfd75f..4263bd144c 100644 --- a/tests/expectations/tests/libclang-9/class_1_0.rs +++ b/tests/expectations/tests/libclang-9/class_1_0.rs @@ -119,7 +119,11 @@ impl Clone for C { } impl Default for C { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } impl ::std::cmp::PartialEq for C { @@ -187,7 +191,11 @@ fn bindgen_test_layout_C_with_zero_length_array() { } impl Default for C_with_zero_length_array { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } #[repr(C)] @@ -295,7 +303,11 @@ fn bindgen_test_layout_C_with_incomplete_array() { } impl Default for C_with_incomplete_array { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } #[repr(C)] @@ -431,7 +443,11 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { } impl Default for C_with_zero_length_array_and_incomplete_array { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } #[repr(C)] @@ -581,7 +597,11 @@ fn bindgen_test_layout_IncompleteArrayNonCopiable() { } impl Default for IncompleteArrayNonCopiable { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } #[repr(C)] diff --git a/tests/expectations/tests/libclang-9/incomplete-array-padding.rs b/tests/expectations/tests/libclang-9/incomplete-array-padding.rs index c380a0cc8d..382195dbb9 100644 --- a/tests/expectations/tests/libclang-9/incomplete-array-padding.rs +++ b/tests/expectations/tests/libclang-9/incomplete-array-padding.rs @@ -148,7 +148,11 @@ fn bindgen_test_layout_foo() { } impl Default for foo { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl foo { diff --git a/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs b/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs index d8f2ac6ee8..49664cdd5e 100644 --- a/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs +++ b/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs @@ -168,7 +168,11 @@ fn bindgen_test_layout_rte_ring() { } impl Default for rte_ring { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] diff --git a/tests/expectations/tests/libclang-9/issue-769-bad-instantiation-test.rs b/tests/expectations/tests/libclang-9/issue-769-bad-instantiation-test.rs index 45bcb6f561..60857966ce 100644 --- a/tests/expectations/tests/libclang-9/issue-769-bad-instantiation-test.rs +++ b/tests/expectations/tests/libclang-9/issue-769-bad-instantiation-test.rs @@ -17,7 +17,11 @@ pub mod root { } impl Default for Rooted { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } pub type AutoValueVector_Alias = ::std::os::raw::c_int; diff --git a/tests/expectations/tests/libclang-9/layout_align.rs b/tests/expectations/tests/libclang-9/layout_align.rs index d153fa5ec4..4ad5417577 100644 --- a/tests/expectations/tests/libclang-9/layout_align.rs +++ b/tests/expectations/tests/libclang-9/layout_align.rs @@ -211,7 +211,11 @@ fn bindgen_test_layout_rte_kni_fifo() { } impl Default for rte_kni_fifo { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] diff --git a/tests/expectations/tests/libclang-9/type_alias_template_specialized.rs b/tests/expectations/tests/libclang-9/type_alias_template_specialized.rs index 38f3bfb1c0..f874e9d221 100644 --- a/tests/expectations/tests/libclang-9/type_alias_template_specialized.rs +++ b/tests/expectations/tests/libclang-9/type_alias_template_specialized.rs @@ -35,7 +35,11 @@ fn bindgen_test_layout_Rooted() { } impl Default for Rooted { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } ///
diff --git a/tests/expectations/tests/namespace.rs b/tests/expectations/tests/namespace.rs index 944ec5bb07..576fc9336f 100644 --- a/tests/expectations/tests/namespace.rs +++ b/tests/expectations/tests/namespace.rs @@ -66,7 +66,11 @@ pub mod root { } impl Default for C { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } pub mod w { @@ -82,7 +86,11 @@ pub mod root { } impl Default for D { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } extern "C" { diff --git a/tests/expectations/tests/nested_vtable.rs b/tests/expectations/tests/nested_vtable.rs index 8ea99846d8..021877763b 100644 --- a/tests/expectations/tests/nested_vtable.rs +++ b/tests/expectations/tests/nested_vtable.rs @@ -27,7 +27,11 @@ fn bindgen_test_layout_nsISupports() { } impl Default for nsISupports { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } extern "C" { @@ -56,7 +60,11 @@ fn bindgen_test_layout_nsIRunnable() { } impl Default for nsIRunnable { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -79,6 +87,10 @@ fn bindgen_test_layout_Runnable() { } impl Default for Runnable { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/no-derive-debug.rs b/tests/expectations/tests/no-derive-debug.rs index d58093ec02..a62eaa5df5 100644 --- a/tests/expectations/tests/no-derive-debug.rs +++ b/tests/expectations/tests/no-derive-debug.rs @@ -44,6 +44,10 @@ fn bindgen_test_layout_bar() { } impl Default for bar { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/no-recursive-allowlisting.rs b/tests/expectations/tests/no-recursive-allowlisting.rs index 047b22ef9d..0aa0b5e322 100644 --- a/tests/expectations/tests/no-recursive-allowlisting.rs +++ b/tests/expectations/tests/no-recursive-allowlisting.rs @@ -32,6 +32,10 @@ fn bindgen_test_layout_Foo() { } impl Default for Foo { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/no-std.rs b/tests/expectations/tests/no-std.rs index ea16dc4454..f63ac4512b 100644 --- a/tests/expectations/tests/no-std.rs +++ b/tests/expectations/tests/no-std.rs @@ -47,6 +47,10 @@ fn bindgen_test_layout_foo() { } impl Default for foo { fn default() -> Self { - unsafe { ::core::mem::zeroed() } + let mut s = ::core::mem::MaybeUninit::::uninit(); + unsafe { + ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/no_debug_bypass_impl_debug.rs b/tests/expectations/tests/no_debug_bypass_impl_debug.rs index adb80eaa7e..334f39ddb0 100644 --- a/tests/expectations/tests/no_debug_bypass_impl_debug.rs +++ b/tests/expectations/tests/no_debug_bypass_impl_debug.rs @@ -12,7 +12,11 @@ pub struct Generic { } impl Default for Generic { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl ::std::fmt::Debug for Generic { @@ -27,6 +31,10 @@ pub struct NoDebug { } impl Default for NoDebug { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/no_default.rs b/tests/expectations/tests/no_default.rs index 27ea3035c4..22fdbf36e4 100644 --- a/tests/expectations/tests/no_default.rs +++ b/tests/expectations/tests/no_default.rs @@ -18,6 +18,10 @@ pub struct DefaultButWaitDerived { } impl Default for DefaultButWaitDerived { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/no_default_bypass_derive_default.rs b/tests/expectations/tests/no_default_bypass_derive_default.rs index 4b97e3f489..6c44a9dd28 100644 --- a/tests/expectations/tests/no_default_bypass_derive_default.rs +++ b/tests/expectations/tests/no_default_bypass_derive_default.rs @@ -12,7 +12,11 @@ pub struct Generic { } impl Default for Generic { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] diff --git a/tests/expectations/tests/nsBaseHashtable.rs b/tests/expectations/tests/nsBaseHashtable.rs index e26190b0d8..d7607b91ab 100644 --- a/tests/expectations/tests/nsBaseHashtable.rs +++ b/tests/expectations/tests/nsBaseHashtable.rs @@ -31,7 +31,11 @@ pub struct nsBaseHashtable_LookupResult { } impl Default for nsBaseHashtable_LookupResult { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -42,11 +46,19 @@ pub struct nsBaseHashtable_EntryPtr { } impl Default for nsBaseHashtable_EntryPtr { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl Default for nsBaseHashtable { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/nsStyleAutoArray.rs b/tests/expectations/tests/nsStyleAutoArray.rs index 091be3ddf2..fab18c1cab 100644 --- a/tests/expectations/tests/nsStyleAutoArray.rs +++ b/tests/expectations/tests/nsStyleAutoArray.rs @@ -13,7 +13,11 @@ pub struct nsTArray { } impl Default for nsTArray { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -30,6 +34,10 @@ pub enum nsStyleAutoArray_WithSingleInitialElement { } impl Default for nsStyleAutoArray { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/objc_interface_type.rs b/tests/expectations/tests/objc_interface_type.rs index 2585df6ec1..cef29c8c96 100644 --- a/tests/expectations/tests/objc_interface_type.rs +++ b/tests/expectations/tests/objc_interface_type.rs @@ -59,7 +59,11 @@ fn bindgen_test_layout_FooStruct() { } impl Default for FooStruct { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } extern "C" { diff --git a/tests/expectations/tests/opaque-template-inst-member-2.rs b/tests/expectations/tests/opaque-template-inst-member-2.rs index 7d3e83a86a..f47aff0552 100644 --- a/tests/expectations/tests/opaque-template-inst-member-2.rs +++ b/tests/expectations/tests/opaque-template-inst-member-2.rs @@ -93,6 +93,10 @@ fn bindgen_test_layout_InheritsOpaqueTemplate() { } impl Default for InheritsOpaqueTemplate { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/opaque-template-inst-member.rs b/tests/expectations/tests/opaque-template-inst-member.rs index ea821fcd75..a3c67784de 100644 --- a/tests/expectations/tests/opaque-template-inst-member.rs +++ b/tests/expectations/tests/opaque-template-inst-member.rs @@ -58,7 +58,11 @@ fn bindgen_test_layout_ContainsOpaqueTemplate() { } impl Default for ContainsOpaqueTemplate { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl ::std::cmp::PartialEq for ContainsOpaqueTemplate { @@ -101,7 +105,11 @@ fn bindgen_test_layout_InheritsOpaqueTemplate() { } impl Default for InheritsOpaqueTemplate { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl ::std::cmp::PartialEq for InheritsOpaqueTemplate { diff --git a/tests/expectations/tests/opaque-template-instantiation-namespaced.rs b/tests/expectations/tests/opaque-template-instantiation-namespaced.rs index 7f1aac8e46..e972443ed3 100644 --- a/tests/expectations/tests/opaque-template-instantiation-namespaced.rs +++ b/tests/expectations/tests/opaque-template-instantiation-namespaced.rs @@ -21,7 +21,11 @@ pub mod root { } impl Default for Template { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -117,7 +121,11 @@ pub mod root { } impl Default for ContainsInstantiation { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] diff --git a/tests/expectations/tests/opaque-template-instantiation.rs b/tests/expectations/tests/opaque-template-instantiation.rs index 771a5191a4..6f0f31b376 100644 --- a/tests/expectations/tests/opaque-template-instantiation.rs +++ b/tests/expectations/tests/opaque-template-instantiation.rs @@ -13,7 +13,11 @@ pub struct Template { } impl Default for Template { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -49,7 +53,11 @@ fn bindgen_test_layout_ContainsInstantiation() { } impl Default for ContainsInstantiation { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] diff --git a/tests/expectations/tests/opaque_pointer.rs b/tests/expectations/tests/opaque_pointer.rs index f5fecd46aa..90b019b290 100644 --- a/tests/expectations/tests/opaque_pointer.rs +++ b/tests/expectations/tests/opaque_pointer.rs @@ -90,6 +90,10 @@ fn bindgen_test_layout_WithOpaquePtr() { } impl Default for WithOpaquePtr { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/packed-vtable.rs b/tests/expectations/tests/packed-vtable.rs index 7f12a3618c..0069eada96 100644 --- a/tests/expectations/tests/packed-vtable.rs +++ b/tests/expectations/tests/packed-vtable.rs @@ -28,7 +28,11 @@ fn bindgen_test_layout_PackedVtable() { } impl Default for PackedVtable { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } extern "C" { diff --git a/tests/expectations/tests/private_fields.rs b/tests/expectations/tests/private_fields.rs index d5371e1c43..92a4bf653b 100644 --- a/tests/expectations/tests/private_fields.rs +++ b/tests/expectations/tests/private_fields.rs @@ -498,7 +498,11 @@ fn bindgen_test_layout_WithAnonUnion__bindgen_ty_1() { } impl Default for WithAnonUnion__bindgen_ty_1 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[test] @@ -516,6 +520,10 @@ fn bindgen_test_layout_WithAnonUnion() { } impl Default for WithAnonUnion { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/ref_argument_array.rs b/tests/expectations/tests/ref_argument_array.rs index 0643d47b6a..799dd81587 100644 --- a/tests/expectations/tests/ref_argument_array.rs +++ b/tests/expectations/tests/ref_argument_array.rs @@ -28,7 +28,11 @@ fn bindgen_test_layout_nsID() { } impl Default for nsID { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } extern "C" { diff --git a/tests/expectations/tests/replace_template_alias.rs b/tests/expectations/tests/replace_template_alias.rs index 0c5500eae0..4f464129fe 100644 --- a/tests/expectations/tests/replace_template_alias.rs +++ b/tests/expectations/tests/replace_template_alias.rs @@ -17,6 +17,10 @@ pub struct JS_Rooted { } impl Default for JS_Rooted { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/replaces_double.rs b/tests/expectations/tests/replaces_double.rs index 7b7ec00e2b..99de132090 100644 --- a/tests/expectations/tests/replaces_double.rs +++ b/tests/expectations/tests/replaces_double.rs @@ -13,7 +13,11 @@ pub struct Wrapper_Wrapped { } impl Default for Wrapper_Wrapped { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } pub type Wrapper_Type = Wrapper_Wrapped; @@ -27,6 +31,10 @@ pub struct Rooted { pub type Rooted_MaybeWrapped = T; impl Default for Rooted { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/size_t_is_usize.rs b/tests/expectations/tests/size_t_is_usize.rs index 43dda32bcf..0d9ab2caba 100644 --- a/tests/expectations/tests/size_t_is_usize.rs +++ b/tests/expectations/tests/size_t_is_usize.rs @@ -42,6 +42,10 @@ fn bindgen_test_layout_A() { } impl Default for A { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/struct_containing_forward_declared_struct.rs b/tests/expectations/tests/struct_containing_forward_declared_struct.rs index 4844186fd4..7298095e21 100644 --- a/tests/expectations/tests/struct_containing_forward_declared_struct.rs +++ b/tests/expectations/tests/struct_containing_forward_declared_struct.rs @@ -30,7 +30,11 @@ fn bindgen_test_layout_a() { } impl Default for a { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] diff --git a/tests/expectations/tests/struct_typedef.rs b/tests/expectations/tests/struct_typedef.rs index 5756ab8188..34c9dbd21e 100644 --- a/tests/expectations/tests/struct_typedef.rs +++ b/tests/expectations/tests/struct_typedef.rs @@ -69,7 +69,11 @@ fn bindgen_test_layout__bindgen_ty_1() { } impl Default for _bindgen_ty_1 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } pub type struct_ptr_t = *mut _bindgen_ty_1; diff --git a/tests/expectations/tests/struct_with_anon_struct_pointer.rs b/tests/expectations/tests/struct_with_anon_struct_pointer.rs index 04e11af6af..0ed19f7634 100644 --- a/tests/expectations/tests/struct_with_anon_struct_pointer.rs +++ b/tests/expectations/tests/struct_with_anon_struct_pointer.rs @@ -73,6 +73,10 @@ fn bindgen_test_layout_foo() { } impl Default for foo { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/struct_with_anon_union.rs b/tests/expectations/tests/struct_with_anon_union.rs index 4ca8452739..15b8c9e449 100644 --- a/tests/expectations/tests/struct_with_anon_union.rs +++ b/tests/expectations/tests/struct_with_anon_union.rs @@ -55,7 +55,11 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { } impl Default for foo__bindgen_ty_1 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[test] @@ -78,6 +82,10 @@ fn bindgen_test_layout_foo() { } impl Default for foo { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/struct_with_anon_unnamed_union.rs b/tests/expectations/tests/struct_with_anon_unnamed_union.rs index 5d03b7fb01..17a83574e7 100644 --- a/tests/expectations/tests/struct_with_anon_unnamed_union.rs +++ b/tests/expectations/tests/struct_with_anon_unnamed_union.rs @@ -55,7 +55,11 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { } impl Default for foo__bindgen_ty_1 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[test] @@ -73,6 +77,10 @@ fn bindgen_test_layout_foo() { } impl Default for foo { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/struct_with_derive_debug.rs b/tests/expectations/tests/struct_with_derive_debug.rs index 0a704fe5d5..721ba96caf 100644 --- a/tests/expectations/tests/struct_with_derive_debug.rs +++ b/tests/expectations/tests/struct_with_derive_debug.rs @@ -65,7 +65,11 @@ fn bindgen_test_layout_BigArray() { } impl Default for BigArray { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -130,6 +134,10 @@ fn bindgen_test_layout_WithBigArray() { } impl Default for WithBigArray { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/struct_with_large_array.rs b/tests/expectations/tests/struct_with_large_array.rs index 850ded569a..56179c20f8 100644 --- a/tests/expectations/tests/struct_with_large_array.rs +++ b/tests/expectations/tests/struct_with_large_array.rs @@ -37,7 +37,11 @@ fn bindgen_test_layout_S() { } impl Default for S { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -47,6 +51,10 @@ pub struct ST { } impl Default for ST { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/struct_with_nesting.rs b/tests/expectations/tests/struct_with_nesting.rs index a98bd8cae8..7ced63e6ce 100644 --- a/tests/expectations/tests/struct_with_nesting.rs +++ b/tests/expectations/tests/struct_with_nesting.rs @@ -163,7 +163,11 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { } impl Default for foo__bindgen_ty_1 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[test] @@ -186,6 +190,10 @@ fn bindgen_test_layout_foo() { } impl Default for foo { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/template-param-usage-0.rs b/tests/expectations/tests/template-param-usage-0.rs index f473b74d78..2acfb06926 100644 --- a/tests/expectations/tests/template-param-usage-0.rs +++ b/tests/expectations/tests/template-param-usage-0.rs @@ -13,6 +13,10 @@ pub struct UsesTemplateParameter { } impl Default for UsesTemplateParameter { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/template-param-usage-10.rs b/tests/expectations/tests/template-param-usage-10.rs index 0afc595255..c6034fb8fe 100644 --- a/tests/expectations/tests/template-param-usage-10.rs +++ b/tests/expectations/tests/template-param-usage-10.rs @@ -24,11 +24,19 @@ pub struct DoublyIndirectUsage_IndirectUsage { } impl Default for DoublyIndirectUsage_IndirectUsage { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl Default for DoublyIndirectUsage { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/template-param-usage-12.rs b/tests/expectations/tests/template-param-usage-12.rs index 9f964b2950..626e451af4 100644 --- a/tests/expectations/tests/template-param-usage-12.rs +++ b/tests/expectations/tests/template-param-usage-12.rs @@ -13,7 +13,11 @@ pub struct BaseUsesT { } impl Default for BaseUsesT { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -25,6 +29,10 @@ pub struct CrtpUsesU { } impl Default for CrtpUsesU { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/template-param-usage-13.rs b/tests/expectations/tests/template-param-usage-13.rs index 64e08da479..70c1778bd5 100644 --- a/tests/expectations/tests/template-param-usage-13.rs +++ b/tests/expectations/tests/template-param-usage-13.rs @@ -19,6 +19,10 @@ pub struct CrtpUsesU { } impl Default for CrtpUsesU { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/template-param-usage-14.rs b/tests/expectations/tests/template-param-usage-14.rs index 8826105f9a..0e0fd0c9ef 100644 --- a/tests/expectations/tests/template-param-usage-14.rs +++ b/tests/expectations/tests/template-param-usage-14.rs @@ -18,6 +18,10 @@ pub struct CrtpIgnoresU { } impl Default for CrtpIgnoresU { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/template-param-usage-15.rs b/tests/expectations/tests/template-param-usage-15.rs index 45f3422930..941c607321 100644 --- a/tests/expectations/tests/template-param-usage-15.rs +++ b/tests/expectations/tests/template-param-usage-15.rs @@ -13,7 +13,11 @@ pub struct BaseUsesT { } impl Default for BaseUsesT { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -24,6 +28,10 @@ pub struct CrtpIgnoresU { } impl Default for CrtpIgnoresU { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/template-param-usage-2.rs b/tests/expectations/tests/template-param-usage-2.rs index 3270e1608e..0ad5d7bb69 100644 --- a/tests/expectations/tests/template-param-usage-2.rs +++ b/tests/expectations/tests/template-param-usage-2.rs @@ -19,11 +19,19 @@ pub struct UsesTemplateParameter_AlsoUsesTemplateParameter { } impl Default for UsesTemplateParameter_AlsoUsesTemplateParameter { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl Default for UsesTemplateParameter { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/template-param-usage-3.rs b/tests/expectations/tests/template-param-usage-3.rs index 9d9d8f973e..414818d920 100644 --- a/tests/expectations/tests/template-param-usage-3.rs +++ b/tests/expectations/tests/template-param-usage-3.rs @@ -23,11 +23,19 @@ impl Default for UsesTemplateParameter_AlsoUsesTemplateParameterAndMore { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl Default for UsesTemplateParameter { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/template-param-usage-4.rs b/tests/expectations/tests/template-param-usage-4.rs index 38479aca48..afcba978de 100644 --- a/tests/expectations/tests/template-param-usage-4.rs +++ b/tests/expectations/tests/template-param-usage-4.rs @@ -18,6 +18,10 @@ pub struct UsesTemplateParameter_DoesNotUseTemplateParameters { } impl Default for UsesTemplateParameter { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/template-param-usage-5.rs b/tests/expectations/tests/template-param-usage-5.rs index 6976841805..2cc8db6fe2 100644 --- a/tests/expectations/tests/template-param-usage-5.rs +++ b/tests/expectations/tests/template-param-usage-5.rs @@ -14,6 +14,10 @@ pub struct IndirectlyUsesTemplateParameter { pub type IndirectlyUsesTemplateParameter_Aliased = T; impl Default for IndirectlyUsesTemplateParameter { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/template-param-usage-7.rs b/tests/expectations/tests/template-param-usage-7.rs index 6f7544ff0b..3ed7a45dfc 100644 --- a/tests/expectations/tests/template-param-usage-7.rs +++ b/tests/expectations/tests/template-param-usage-7.rs @@ -15,7 +15,11 @@ pub struct DoesNotUseU { } impl Default for DoesNotUseU { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } pub type Alias = DoesNotUseU<::std::os::raw::c_int, ::std::os::raw::c_char>; diff --git a/tests/expectations/tests/template-param-usage-8.rs b/tests/expectations/tests/template-param-usage-8.rs index 3a0100ffce..f8ac671410 100644 --- a/tests/expectations/tests/template-param-usage-8.rs +++ b/tests/expectations/tests/template-param-usage-8.rs @@ -17,6 +17,10 @@ pub type IndirectUsage_Typedefed = T; pub type IndirectUsage_Aliased = U; impl Default for IndirectUsage { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/template-param-usage-9.rs b/tests/expectations/tests/template-param-usage-9.rs index a93e4b7c0a..a50079a2ed 100644 --- a/tests/expectations/tests/template-param-usage-9.rs +++ b/tests/expectations/tests/template-param-usage-9.rs @@ -22,6 +22,10 @@ pub struct DoesNotUse_IndirectUsage { } impl Default for DoesNotUse_IndirectUsage { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/template.rs b/tests/expectations/tests/template.rs index 67a0f8568e..9c48488693 100644 --- a/tests/expectations/tests/template.rs +++ b/tests/expectations/tests/template.rs @@ -15,7 +15,11 @@ pub struct Foo { } impl Default for Foo { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -26,7 +30,11 @@ pub struct B { } impl Default for B { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } extern "C" { @@ -231,7 +239,11 @@ fn bindgen_test_layout_C() { } impl Default for C { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -249,12 +261,20 @@ pub struct D_U { } impl Default for D_U { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl Default for D { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -267,7 +287,11 @@ pub struct Rooted { } impl Default for Rooted { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -303,7 +327,11 @@ fn bindgen_test_layout_RootedContainer() { } impl Default for RootedContainer { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } pub type WithDtorIntFwd = WithDtor<::std::os::raw::c_int>; @@ -315,7 +343,11 @@ pub struct WithDtor { } impl Default for WithDtor { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -351,7 +383,11 @@ fn bindgen_test_layout_PODButContainsDtor() { } impl Default for PODButContainsDtor { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } ///
@@ -399,7 +435,11 @@ pub struct NestedReplaced { } impl Default for NestedReplaced { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -410,7 +450,11 @@ pub struct NestedBase { } impl Default for NestedBase { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -423,7 +467,11 @@ pub struct NestedContainer { } impl Default for NestedContainer { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -434,7 +482,11 @@ pub struct Incomplete { } impl Default for Incomplete { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -472,7 +524,11 @@ pub struct ReplacedWithoutDestructor { } impl Default for ReplacedWithoutDestructor { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -483,7 +539,11 @@ pub struct ShouldNotBeCopiable { } impl Default for ShouldNotBeCopiable { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -494,7 +554,11 @@ pub struct ShouldNotBeCopiableAsWell { } impl Default for ShouldNotBeCopiableAsWell { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } /// If the replacement doesn't happen at the parse level the container would be @@ -509,7 +573,11 @@ pub struct ReplacedWithoutDestructorFwd { } impl Default for ReplacedWithoutDestructorFwd { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[test] diff --git a/tests/expectations/tests/template_alias.rs b/tests/expectations/tests/template_alias.rs index 3b79a3d8b5..7e0af20d78 100644 --- a/tests/expectations/tests/template_alias.rs +++ b/tests/expectations/tests/template_alias.rs @@ -14,6 +14,10 @@ pub struct JS_Rooted { } impl Default for JS_Rooted { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/template_alias_namespace.rs b/tests/expectations/tests/template_alias_namespace.rs index fd20bab029..7196b532f6 100644 --- a/tests/expectations/tests/template_alias_namespace.rs +++ b/tests/expectations/tests/template_alias_namespace.rs @@ -26,7 +26,11 @@ pub mod root { } impl Default for Rooted { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } } diff --git a/tests/expectations/tests/template_typedef_transitive_param.rs b/tests/expectations/tests/template_typedef_transitive_param.rs index 8c9dd4d0eb..68ca126ac9 100644 --- a/tests/expectations/tests/template_typedef_transitive_param.rs +++ b/tests/expectations/tests/template_typedef_transitive_param.rs @@ -18,7 +18,11 @@ pub struct Wrapper_Wrapped { } impl Default for Wrapper_Wrapped { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } pub type Wrapper_Type = Wrapper_Wrapped; diff --git a/tests/expectations/tests/timex.rs b/tests/expectations/tests/timex.rs index 63917d6ab9..72ada37ad3 100644 --- a/tests/expectations/tests/timex.rs +++ b/tests/expectations/tests/timex.rs @@ -123,7 +123,11 @@ fn bindgen_test_layout_timex() { } impl Default for timex { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -160,6 +164,10 @@ fn bindgen_test_layout_timex_named() { } impl Default for timex_named { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/transform-op.rs b/tests/expectations/tests/transform-op.rs index 64c588d84c..84a9460362 100644 --- a/tests/expectations/tests/transform-op.rs +++ b/tests/expectations/tests/transform-op.rs @@ -57,7 +57,11 @@ pub struct StylePoint { } impl Default for StylePoint { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } #[repr(C)] @@ -86,7 +90,11 @@ pub struct StyleFoo_Foo_Body { } impl Default for StyleFoo_Foo_Body { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } #[repr(C)] @@ -98,7 +106,11 @@ pub struct StyleFoo_Bar_Body { } impl Default for StyleFoo_Bar_Body { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } #[repr(C)] @@ -110,7 +122,11 @@ pub struct StyleFoo_Baz_Body { } impl Default for StyleFoo_Baz_Body { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } #[repr(C)] @@ -120,7 +136,11 @@ pub struct StyleFoo__bindgen_ty_1 { } impl Default for StyleFoo__bindgen_ty_1 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } #[repr(C)] @@ -145,7 +165,11 @@ pub struct StyleBar_StyleBar1_Body { } impl Default for StyleBar_StyleBar1_Body { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } #[repr(C)] @@ -156,7 +180,11 @@ pub struct StyleBar_StyleBar2_Body { } impl Default for StyleBar_StyleBar2_Body { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } #[repr(C)] @@ -167,7 +195,11 @@ pub struct StyleBar_StyleBar3_Body { } impl Default for StyleBar_StyleBar3_Body { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } #[repr(C)] @@ -181,7 +213,11 @@ pub struct StyleBar__bindgen_ty_1 { } impl Default for StyleBar { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } #[test] diff --git a/tests/expectations/tests/type_alias_partial_template_especialization.rs b/tests/expectations/tests/type_alias_partial_template_especialization.rs index a80f46b63e..44449f20d1 100644 --- a/tests/expectations/tests/type_alias_partial_template_especialization.rs +++ b/tests/expectations/tests/type_alias_partial_template_especialization.rs @@ -14,6 +14,10 @@ pub struct Rooted { } impl Default for Rooted { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/typeref.rs b/tests/expectations/tests/typeref.rs index b62ce929c0..1c34be7e9b 100644 --- a/tests/expectations/tests/typeref.rs +++ b/tests/expectations/tests/typeref.rs @@ -65,12 +65,20 @@ pub union mozilla_StyleShapeSource__bindgen_ty_1 { } impl Default for mozilla_StyleShapeSource__bindgen_ty_1 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl Default for mozilla_StyleShapeSource { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -98,7 +106,11 @@ fn bindgen_test_layout_Bar() { } impl Default for Bar { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -130,7 +142,11 @@ fn bindgen_test_layout_nsFoo() { } impl Default for nsFoo { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[test] diff --git a/tests/expectations/tests/typeref_1_0.rs b/tests/expectations/tests/typeref_1_0.rs index 75b41960e8..2820d9f96c 100644 --- a/tests/expectations/tests/typeref_1_0.rs +++ b/tests/expectations/tests/typeref_1_0.rs @@ -149,7 +149,11 @@ impl Clone for Bar { } impl Default for Bar { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } #[repr(C)] diff --git a/tests/expectations/tests/union-align.rs b/tests/expectations/tests/union-align.rs index 7151ba45cd..8612764186 100644 --- a/tests/expectations/tests/union-align.rs +++ b/tests/expectations/tests/union-align.rs @@ -31,7 +31,11 @@ fn bindgen_test_layout_Bar() { } impl Default for Bar { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } #[repr(C)] @@ -60,6 +64,10 @@ fn bindgen_test_layout_Baz() { } impl Default for Baz { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } diff --git a/tests/expectations/tests/union-in-ns.rs b/tests/expectations/tests/union-in-ns.rs index abb330b86c..b52c6c3600 100644 --- a/tests/expectations/tests/union-in-ns.rs +++ b/tests/expectations/tests/union-in-ns.rs @@ -39,7 +39,11 @@ pub mod root { } impl Default for bar { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } } diff --git a/tests/expectations/tests/union_bitfield.rs b/tests/expectations/tests/union_bitfield.rs index cf3595ec51..9e07a1dfcd 100644 --- a/tests/expectations/tests/union_bitfield.rs +++ b/tests/expectations/tests/union_bitfield.rs @@ -113,7 +113,11 @@ fn bindgen_test_layout_U4() { } impl Default for U4 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl U4 { @@ -165,7 +169,11 @@ fn bindgen_test_layout_B() { } impl Default for B { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl B { diff --git a/tests/expectations/tests/union_bitfield_1_0.rs b/tests/expectations/tests/union_bitfield_1_0.rs index 7c846da8b1..2227746849 100644 --- a/tests/expectations/tests/union_bitfield_1_0.rs +++ b/tests/expectations/tests/union_bitfield_1_0.rs @@ -284,7 +284,11 @@ impl Clone for HasBigBitfield { } impl Default for HasBigBitfield { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } impl ::std::cmp::PartialEq for HasBigBitfield { diff --git a/tests/expectations/tests/union_dtor.rs b/tests/expectations/tests/union_dtor.rs index a06e8ccffe..94ad3fd873 100644 --- a/tests/expectations/tests/union_dtor.rs +++ b/tests/expectations/tests/union_dtor.rs @@ -53,7 +53,11 @@ extern "C" { } impl Default for UnionWithDtor { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl UnionWithDtor { diff --git a/tests/expectations/tests/union_fields.rs b/tests/expectations/tests/union_fields.rs index e605b0bce8..6cd0d56cdb 100644 --- a/tests/expectations/tests/union_fields.rs +++ b/tests/expectations/tests/union_fields.rs @@ -64,6 +64,10 @@ fn bindgen_test_layout_nsStyleUnion() { } impl Default for nsStyleUnion { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/union_template.rs b/tests/expectations/tests/union_template.rs index 6a366f9eae..9c3d7a07eb 100644 --- a/tests/expectations/tests/union_template.rs +++ b/tests/expectations/tests/union_template.rs @@ -18,7 +18,11 @@ pub union NastyStruct__bindgen_ty_1 { } impl Default for NastyStruct__bindgen_ty_1 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -28,12 +32,20 @@ pub union NastyStruct__bindgen_ty_2 { } impl Default for NastyStruct__bindgen_ty_2 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl Default for NastyStruct { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -43,6 +55,10 @@ pub union Whatever { } impl Default for Whatever { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/union_with_anon_struct.rs b/tests/expectations/tests/union_with_anon_struct.rs index 7d061cec68..afb735043d 100644 --- a/tests/expectations/tests/union_with_anon_struct.rs +++ b/tests/expectations/tests/union_with_anon_struct.rs @@ -73,6 +73,10 @@ fn bindgen_test_layout_foo() { } impl Default for foo { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/union_with_anon_struct_bitfield.rs b/tests/expectations/tests/union_with_anon_struct_bitfield.rs index 2e3e641579..09ed515f99 100644 --- a/tests/expectations/tests/union_with_anon_struct_bitfield.rs +++ b/tests/expectations/tests/union_with_anon_struct_bitfield.rs @@ -182,6 +182,10 @@ fn bindgen_test_layout_foo() { } impl Default for foo { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/union_with_anon_union.rs b/tests/expectations/tests/union_with_anon_union.rs index 83e4801a88..a24962c4a6 100644 --- a/tests/expectations/tests/union_with_anon_union.rs +++ b/tests/expectations/tests/union_with_anon_union.rs @@ -55,7 +55,11 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { } impl Default for foo__bindgen_ty_1 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[test] @@ -78,6 +82,10 @@ fn bindgen_test_layout_foo() { } impl Default for foo { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/union_with_anon_unnamed_struct.rs b/tests/expectations/tests/union_with_anon_unnamed_struct.rs index 5802f563f7..94380d1a54 100644 --- a/tests/expectations/tests/union_with_anon_unnamed_struct.rs +++ b/tests/expectations/tests/union_with_anon_unnamed_struct.rs @@ -109,6 +109,10 @@ fn bindgen_test_layout_pixel() { } impl Default for pixel { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/union_with_anon_unnamed_union.rs b/tests/expectations/tests/union_with_anon_unnamed_union.rs index fc465737d1..2004ff4cef 100644 --- a/tests/expectations/tests/union_with_anon_unnamed_union.rs +++ b/tests/expectations/tests/union_with_anon_unnamed_union.rs @@ -56,7 +56,11 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { } impl Default for foo__bindgen_ty_1 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[test] @@ -79,6 +83,10 @@ fn bindgen_test_layout_foo() { } impl Default for foo { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/union_with_big_member.rs b/tests/expectations/tests/union_with_big_member.rs index 6425c1141d..3f9294dd05 100644 --- a/tests/expectations/tests/union_with_big_member.rs +++ b/tests/expectations/tests/union_with_big_member.rs @@ -50,7 +50,11 @@ fn bindgen_test_layout_WithBigArray() { } impl Default for WithBigArray { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -98,7 +102,11 @@ fn bindgen_test_layout_WithBigArray2() { } impl Default for WithBigArray2 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -146,6 +154,10 @@ fn bindgen_test_layout_WithBigMember() { } impl Default for WithBigMember { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/union_with_big_member_1_0.rs b/tests/expectations/tests/union_with_big_member_1_0.rs index 3aba485bc7..541c9d4c77 100644 --- a/tests/expectations/tests/union_with_big_member_1_0.rs +++ b/tests/expectations/tests/union_with_big_member_1_0.rs @@ -99,7 +99,11 @@ impl Clone for WithBigArray { } impl Default for WithBigArray { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } #[repr(C)] @@ -202,6 +206,10 @@ impl Clone for WithBigMember { } impl Default for WithBigMember { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } diff --git a/tests/expectations/tests/union_with_nesting.rs b/tests/expectations/tests/union_with_nesting.rs index 55045f2f1f..54a3179b41 100644 --- a/tests/expectations/tests/union_with_nesting.rs +++ b/tests/expectations/tests/union_with_nesting.rs @@ -64,7 +64,11 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { } impl Default for foo__bindgen_ty_1__bindgen_ty_1 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -114,7 +118,11 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { } impl Default for foo__bindgen_ty_1__bindgen_ty_2 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[test] @@ -132,7 +140,11 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { } impl Default for foo__bindgen_ty_1 { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[test] @@ -155,6 +167,10 @@ fn bindgen_test_layout_foo() { } impl Default for foo { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/use-core.rs b/tests/expectations/tests/use-core.rs index 4cb2851fc2..d919b6e745 100644 --- a/tests/expectations/tests/use-core.rs +++ b/tests/expectations/tests/use-core.rs @@ -44,7 +44,11 @@ fn bindgen_test_layout_foo() { } impl Default for foo { fn default() -> Self { - unsafe { ::core::mem::zeroed() } + let mut s = ::core::mem::MaybeUninit::::uninit(); + unsafe { + ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -92,7 +96,11 @@ fn bindgen_test_layout__bindgen_ty_1() { } impl Default for _bindgen_ty_1 { fn default() -> Self { - unsafe { ::core::mem::zeroed() } + let mut s = ::core::mem::MaybeUninit::::uninit(); + unsafe { + ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } extern "C" { diff --git a/tests/expectations/tests/use-core_1_0.rs b/tests/expectations/tests/use-core_1_0.rs index 2d3b39df08..61ddfc42cb 100644 --- a/tests/expectations/tests/use-core_1_0.rs +++ b/tests/expectations/tests/use-core_1_0.rs @@ -92,7 +92,11 @@ impl Clone for foo { } impl Default for foo { fn default() -> Self { - unsafe { ::core::mem::zeroed() } + unsafe { + let mut s: Self = ::core::mem::uninitialized(); + ::core::ptr::write_bytes(&mut s, 0, 1); + s + } } } #[repr(C)] diff --git a/tests/expectations/tests/using.rs b/tests/expectations/tests/using.rs index 28b4308b3d..4749ed5552 100644 --- a/tests/expectations/tests/using.rs +++ b/tests/expectations/tests/using.rs @@ -14,7 +14,11 @@ pub struct Point { } impl Default for Point { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } pub type IntPoint2D = Point<::std::os::raw::c_int>; diff --git a/tests/expectations/tests/virtual_dtor.rs b/tests/expectations/tests/virtual_dtor.rs index f50130cd47..c3c66e91d8 100644 --- a/tests/expectations/tests/virtual_dtor.rs +++ b/tests/expectations/tests/virtual_dtor.rs @@ -27,7 +27,11 @@ fn bindgen_test_layout_nsSlots() { } impl Default for nsSlots { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } extern "C" { diff --git a/tests/expectations/tests/virtual_inheritance.rs b/tests/expectations/tests/virtual_inheritance.rs index 8283b6d544..eac6aa665e 100644 --- a/tests/expectations/tests/virtual_inheritance.rs +++ b/tests/expectations/tests/virtual_inheritance.rs @@ -56,7 +56,11 @@ fn bindgen_test_layout_B() { } impl Default for B { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -87,7 +91,11 @@ fn bindgen_test_layout_C() { } impl Default for C { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -112,6 +120,10 @@ fn bindgen_test_layout_D() { } impl Default for D { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/virtual_overloaded.rs b/tests/expectations/tests/virtual_overloaded.rs index 9a9d642441..4556b1b6af 100644 --- a/tests/expectations/tests/virtual_overloaded.rs +++ b/tests/expectations/tests/virtual_overloaded.rs @@ -27,7 +27,11 @@ fn bindgen_test_layout_C() { } impl Default for C { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } extern "C" { diff --git a/tests/expectations/tests/vtable_recursive_sig.rs b/tests/expectations/tests/vtable_recursive_sig.rs index 0285154c1a..ca77bc8ca5 100644 --- a/tests/expectations/tests/vtable_recursive_sig.rs +++ b/tests/expectations/tests/vtable_recursive_sig.rs @@ -27,7 +27,11 @@ fn bindgen_test_layout_Base() { } impl Default for Base { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } extern "C" { @@ -54,6 +58,10 @@ fn bindgen_test_layout_Derived() { } impl Default for Derived { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } diff --git a/tests/expectations/tests/weird_bitfields.rs b/tests/expectations/tests/weird_bitfields.rs index d25c802e38..c4dfa55ad9 100644 --- a/tests/expectations/tests/weird_bitfields.rs +++ b/tests/expectations/tests/weird_bitfields.rs @@ -286,7 +286,11 @@ fn bindgen_test_layout_Weird() { } impl Default for Weird { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } impl Weird { diff --git a/tests/expectations/tests/what_is_going_on.rs b/tests/expectations/tests/what_is_going_on.rs index 8f70466b99..b4f42791db 100644 --- a/tests/expectations/tests/what_is_going_on.rs +++ b/tests/expectations/tests/what_is_going_on.rs @@ -33,7 +33,11 @@ pub struct PointTyped { } impl Default for PointTyped { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } pub type IntPoint = PointTyped; From b60339ece3994868a55889b7f1f6043ab29ba30e Mon Sep 17 00:00:00 2001 From: Adrian Taylor Date: Tue, 18 May 2021 06:51:52 -0700 Subject: [PATCH 189/942] Identify forward declarations in params. (#2052) --- src/clang.rs | 2 +- src/ir/comp.rs | 1 + tests/expectations/tests/parm-union.rs | 40 ++++++++++++++++++++++++++ tests/headers/parm-union.hpp | 4 +++ 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 tests/expectations/tests/parm-union.rs create mode 100644 tests/headers/parm-union.hpp diff --git a/src/clang.rs b/src/clang.rs index 96f772540b..db6467e398 100644 --- a/src/clang.rs +++ b/src/clang.rs @@ -241,7 +241,7 @@ impl Cursor { self.x.kind } - /// Returns true is the cursor is a definition + /// Returns true if the cursor is a definition pub fn is_definition(&self) -> bool { unsafe { clang_isCursorDefinition(self.x) != 0 } } diff --git a/src/ir/comp.rs b/src/ir/comp.rs index 52dcddd555..d57c272a30 100644 --- a/src/ir/comp.rs +++ b/src/ir/comp.rs @@ -1249,6 +1249,7 @@ impl CompInfo { let mut ci = CompInfo::new(kind); ci.is_forward_declaration = location.map_or(true, |cur| match cur.kind() { + CXCursor_ParmDecl => true, CXCursor_StructDecl | CXCursor_UnionDecl | CXCursor_ClassDecl => !cur.is_definition(), _ => false, diff --git a/tests/expectations/tests/parm-union.rs b/tests/expectations/tests/parm-union.rs new file mode 100644 index 0000000000..9f7dd20ad9 --- /dev/null +++ b/tests/expectations/tests/parm-union.rs @@ -0,0 +1,40 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Struct { + pub _address: u8, +} +#[test] +fn bindgen_test_layout_Struct() { + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Struct)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Struct)) + ); +} +extern "C" { + #[link_name = "\u{1}_ZN6Struct8FunctionER5Union"] + pub fn Struct_Function(this: *mut Struct, arg1: *mut Union); +} +impl Struct { + #[inline] + pub unsafe fn Function(&mut self, arg1: *mut Union) { + Struct_Function(self, arg1) + } +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct Union { + _unused: [u8; 0], +} diff --git a/tests/headers/parm-union.hpp b/tests/headers/parm-union.hpp new file mode 100644 index 0000000000..e36df69120 --- /dev/null +++ b/tests/headers/parm-union.hpp @@ -0,0 +1,4 @@ +struct Struct +{ + void Function(union Union&); +}; From 14a8d29baa1da364c6f33de42c4048ed573b06ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 21 Jun 2021 13:47:34 +0200 Subject: [PATCH 190/942] comp: Do a better effort of computing packedness before bitfield units. Fixes #2067 --- src/ir/comp.rs | 88 +++++--- src/ir/context.rs | 9 +- .../tests/bitfield_pragma_packed.rs | 211 ++++++++++++++++++ tests/headers/bitfield_pragma_packed.h | 9 + 4 files changed, 283 insertions(+), 34 deletions(-) create mode 100644 tests/expectations/tests/bitfield_pragma_packed.rs create mode 100644 tests/headers/bitfield_pragma_packed.h diff --git a/src/ir/comp.rs b/src/ir/comp.rs index d57c272a30..e554f9a89c 100644 --- a/src/ir/comp.rs +++ b/src/ir/comp.rs @@ -1113,21 +1113,17 @@ impl CompInfo { } // empty union case - if self.fields().is_empty() { + if !self.has_fields() { return None; } let mut max_size = 0; // Don't allow align(0) let mut max_align = 1; - for field in self.fields() { - let field_layout = field.layout(ctx); - - if let Some(layout) = field_layout { - max_size = cmp::max(max_size, layout.size); - max_align = cmp::max(max_align, layout.align); - } - } + self.each_known_field_layout(ctx, |layout| { + max_size = cmp::max(max_size, layout.size); + max_align = cmp::max(max_align, layout.align); + }); Some(Layout::new(max_size, max_align)) } @@ -1139,12 +1135,49 @@ impl CompInfo { CompFields::AfterComputingBitfieldUnits { ref fields, .. } => { fields } - CompFields::BeforeComputingBitfieldUnits(_) => { + CompFields::BeforeComputingBitfieldUnits(..) => { panic!("Should always have computed bitfield units first"); } } } + fn has_fields(&self) -> bool { + match self.fields { + CompFields::ErrorComputingBitfieldUnits => false, + CompFields::AfterComputingBitfieldUnits { ref fields, .. } => { + !fields.is_empty() + } + CompFields::BeforeComputingBitfieldUnits(ref raw_fields) => { + !raw_fields.is_empty() + } + } + } + + fn each_known_field_layout( + &self, + ctx: &BindgenContext, + mut callback: impl FnMut(Layout), + ) { + match self.fields { + CompFields::ErrorComputingBitfieldUnits => return, + CompFields::AfterComputingBitfieldUnits { ref fields, .. } => { + for field in fields.iter() { + if let Some(layout) = field.layout(ctx) { + callback(layout); + } + } + } + CompFields::BeforeComputingBitfieldUnits(ref raw_fields) => { + for field in raw_fields.iter() { + let field_ty = ctx.resolve_type(field.0.ty); + if let Some(layout) = field_ty.layout(ctx) { + callback(layout); + } + } + } + } + } + fn has_bitfields(&self) -> bool { match self.fields { CompFields::ErrorComputingBitfieldUnits => false, @@ -1598,23 +1631,17 @@ impl CompInfo { // Even though `libclang` doesn't expose `#pragma packed(...)`, we can // detect it through its effects. if let Some(parent_layout) = layout { - if self.fields().iter().any(|f| match *f { - Field::Bitfields(ref unit) => { - unit.layout().align > parent_layout.align - } - Field::DataMember(ref data) => { - let field_ty = ctx.resolve_type(data.ty()); - field_ty.layout(ctx).map_or(false, |field_ty_layout| { - field_ty_layout.align > parent_layout.align - }) - } - }) { + let mut packed = false; + self.each_known_field_layout(ctx, |layout| { + packed = packed || layout.align > parent_layout.align; + }); + if packed { info!("Found a struct that was defined within `#pragma packed(...)`"); return true; - } else if self.has_own_virtual_method { - if parent_layout.align == 1 { - return true; - } + } + + if self.has_own_virtual_method && parent_layout.align == 1 { + return true; } } @@ -1627,10 +1654,13 @@ impl CompInfo { } /// Compute this compound structure's bitfield allocation units. - pub fn compute_bitfield_units(&mut self, ctx: &BindgenContext) { - // TODO(emilio): If we could detect #pragma packed here we'd fix layout - // tests in divide-by-zero-in-struct-layout.rs - self.fields.compute_bitfield_units(ctx, self.packed_attr) + pub fn compute_bitfield_units( + &mut self, + ctx: &BindgenContext, + layout: Option<&Layout>, + ) { + let packed = self.is_packed(ctx, layout); + self.fields.compute_bitfield_units(ctx, packed) } /// Assign for each anonymous field a generated name. diff --git a/src/ir/context.rs b/src/ir/context.rs index 4faf6cd123..72ce06b10c 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -981,12 +981,11 @@ If you encounter an error missing from this list, please file an issue or a PR!" mem::replace(&mut self.need_bitfield_allocation, vec![]); for id in need_bitfield_allocation { self.with_loaned_item(id, |ctx, item| { - item.kind_mut() - .as_type_mut() - .unwrap() - .as_comp_mut() + let ty = item.kind_mut().as_type_mut().unwrap(); + let layout = ty.layout(ctx); + ty.as_comp_mut() .unwrap() - .compute_bitfield_units(ctx); + .compute_bitfield_units(ctx, layout.as_ref()); }); } } diff --git a/tests/expectations/tests/bitfield_pragma_packed.rs b/tests/expectations/tests/bitfield_pragma_packed.rs new file mode 100644 index 0000000000..27cd90f140 --- /dev/null +++ b/tests/expectations/tests/bitfield_pragma_packed.rs @@ -0,0 +1,211 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[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] + 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]; + 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 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]; + 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 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 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); + } + } +} +#[repr(C, packed)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Struct { + pub _bitfield_align_1: [u8; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, +} +#[test] +fn bindgen_test_layout_Struct() { + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Struct)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Struct)) + ); +} +impl Struct { + #[inline] + pub fn a(&self) -> ::std::os::raw::c_uchar { + unsafe { + ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) + } + } + #[inline] + pub fn set_a(&mut self, val: ::std::os::raw::c_uchar) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + self._bitfield_1.set(0usize, 1u8, val as u64) + } + } + #[inline] + pub fn b(&self) -> ::std::os::raw::c_uchar { + unsafe { + ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u8) + } + } + #[inline] + pub fn set_b(&mut self, val: ::std::os::raw::c_uchar) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + self._bitfield_1.set(1usize, 1u8, val as u64) + } + } + #[inline] + pub fn c(&self) -> ::std::os::raw::c_uchar { + unsafe { + ::std::mem::transmute(self._bitfield_1.get(2usize, 6u8) as u8) + } + } + #[inline] + pub fn set_c(&mut self, val: ::std::os::raw::c_uchar) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + self._bitfield_1.set(2usize, 6u8, val as u64) + } + } + #[inline] + pub fn d(&self) -> ::std::os::raw::c_ushort { + unsafe { + ::std::mem::transmute(self._bitfield_1.get(8usize, 16u8) as u16) + } + } + #[inline] + pub fn set_d(&mut self, val: ::std::os::raw::c_ushort) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + self._bitfield_1.set(8usize, 16u8, val as u64) + } + } + #[inline] + pub fn e(&self) -> ::std::os::raw::c_uchar { + unsafe { + ::std::mem::transmute(self._bitfield_1.get(24usize, 8u8) as u8) + } + } + #[inline] + pub fn set_e(&mut self, val: ::std::os::raw::c_uchar) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + self._bitfield_1.set(24usize, 8u8, val as u64) + } + } + #[inline] + pub fn new_bitfield_1( + a: ::std::os::raw::c_uchar, + b: ::std::os::raw::c_uchar, + c: ::std::os::raw::c_uchar, + d: ::std::os::raw::c_ushort, + e: ::std::os::raw::c_uchar, + ) -> __BindgenBitfieldUnit<[u8; 4usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = + Default::default(); + __bindgen_bitfield_unit.set(0usize, 1u8, { + let a: u8 = unsafe { ::std::mem::transmute(a) }; + a as u64 + }); + __bindgen_bitfield_unit.set(1usize, 1u8, { + let b: u8 = unsafe { ::std::mem::transmute(b) }; + b as u64 + }); + __bindgen_bitfield_unit.set(2usize, 6u8, { + let c: u8 = unsafe { ::std::mem::transmute(c) }; + c as u64 + }); + __bindgen_bitfield_unit.set(8usize, 16u8, { + let d: u16 = unsafe { ::std::mem::transmute(d) }; + d as u64 + }); + __bindgen_bitfield_unit.set(24usize, 8u8, { + let e: u8 = unsafe { ::std::mem::transmute(e) }; + e as u64 + }); + __bindgen_bitfield_unit + } +} diff --git a/tests/headers/bitfield_pragma_packed.h b/tests/headers/bitfield_pragma_packed.h new file mode 100644 index 0000000000..b4011ca844 --- /dev/null +++ b/tests/headers/bitfield_pragma_packed.h @@ -0,0 +1,9 @@ +#pragma pack(push, 1) +struct Struct { + unsigned char a : 1; + unsigned char b : 1; + unsigned char c : 6; + unsigned short int d : 16; + unsigned char e : 8; +}; +#pragma pack(pop) From 67538b64ea1b90a0d01e4f6ebd45713ec03c9222 Mon Sep 17 00:00:00 2001 From: Eric Seppanen Date: Fri, 16 Jul 2021 12:22:02 -0700 Subject: [PATCH 191/942] Allow explicit padding (#2060) If a struct needs to be serialized in its native format (padding bytes and all), for example writing it to a file or sending it on the network, then explicit padding fields are necessary, as anything reading the padding bytes of a struct may lead to Undefined Behavior. --- src/codegen/mod.rs | 8 +++ src/codegen/struct_layout.rs | 42 +++++++++++-- src/lib.rs | 19 ++++++ src/options.rs | 7 +++ tests/expectations/tests/explicit-padding.rs | 65 ++++++++++++++++++++ tests/headers/explicit-padding.h | 11 ++++ 6 files changed, 147 insertions(+), 5 deletions(-) create mode 100644 tests/expectations/tests/explicit-padding.rs create mode 100644 tests/headers/explicit-padding.h diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 6f8a451a2a..515ebf1733 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -1797,6 +1797,14 @@ impl CodeGenerator for CompInfo { (), ); } + // Check whether an explicit padding field is needed + // at the end. + if let Some(comp_layout) = layout { + fields.extend( + struct_layout + .add_tail_padding(&canonical_name, comp_layout), + ); + } } if is_opaque { diff --git a/src/codegen/struct_layout.rs b/src/codegen/struct_layout.rs index 2e4b973591..1c6b977b99 100644 --- a/src/codegen/struct_layout.rs +++ b/src/codegen/struct_layout.rs @@ -217,8 +217,11 @@ impl<'a> StructLayoutTracker<'a> { let padding_layout = if self.is_packed || is_union { None } else { + let force_padding = self.ctx.options().force_explicit_padding; + // Otherwise the padding is useless. - let need_padding = padding_bytes >= field_layout.align || + let need_padding = force_padding || + padding_bytes >= field_layout.align || field_layout.align > MAX_GUARANTEED_ALIGN; debug!( @@ -236,11 +239,14 @@ impl<'a> StructLayoutTracker<'a> { field_layout ); + let padding_align = if force_padding { + 1 + } else { + cmp::min(field_layout.align, MAX_GUARANTEED_ALIGN) + }; + if need_padding && padding_bytes != 0 { - Some(Layout::new( - padding_bytes, - cmp::min(field_layout.align, MAX_GUARANTEED_ALIGN), - )) + Some(Layout::new(padding_bytes, padding_align)) } else { None } @@ -262,6 +268,32 @@ impl<'a> StructLayoutTracker<'a> { padding_layout.map(|layout| self.padding_field(layout)) } + pub fn add_tail_padding( + &mut self, + comp_name: &str, + comp_layout: Layout, + ) -> Option { + // Only emit an padding field at the end of a struct if the + // user configures explicit padding. + if !self.ctx.options().force_explicit_padding { + return None; + } + + if self.latest_offset == comp_layout.size { + // This struct does not contain tail padding. + return None; + } + + trace!( + "need a tail padding field for {}: offset {} -> size {}", + comp_name, + self.latest_offset, + comp_layout.size + ); + let size = comp_layout.size - self.latest_offset; + Some(self.padding_field(Layout::new(size, 0))) + } + pub fn pad_struct( &mut self, layout: Layout, diff --git a/src/lib.rs b/src/lib.rs index 1ac053b7f8..1c51c8ae42 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -562,6 +562,10 @@ impl Builder { output_vector.push("--c-naming".into()); } + if self.options.force_explicit_padding { + output_vector.push("--explicit-padding".into()); + } + // Add clang arguments output_vector.push("--".into()); @@ -1419,6 +1423,17 @@ impl Builder { self } + /// If true, always emit explicit padding fields. + /// + /// If a struct needs to be serialized in its native format (padding bytes + /// and all), for example writing it to a file or sending it on the network, + /// then this should be enabled, as anything reading the padding bytes of + /// a struct may lead to Undefined Behavior. + pub fn explicit_padding(mut self, doit: bool) -> Self { + self.options.force_explicit_padding = doit; + self + } + /// Generate the Rust bindings using the options built up thus far. pub fn generate(mut self) -> Result { // Add any extra arguments from the environment to the clang command line. @@ -1937,6 +1952,9 @@ struct BindgenOptions { /// Generate types with C style naming. c_naming: bool, + + /// Always output explicit padding fields + force_explicit_padding: bool, } /// TODO(emilio): This is sort of a lie (see the error message that results from @@ -2079,6 +2097,7 @@ impl Default for BindgenOptions { respect_cxx_access_specs: false, translate_enum_integer_types: false, c_naming: false, + force_explicit_padding: false, } } } diff --git a/src/options.rs b/src/options.rs index cbdc945ebb..eeeb5aae8c 100644 --- a/src/options.rs +++ b/src/options.rs @@ -516,6 +516,9 @@ where Arg::with_name("c-naming") .long("c-naming") .help("Generate types with C style naming."), + Arg::with_name("explicit-padding") + .long("explicit-padding") + .help("Always output explicit padding fields."), ]) // .args() .get_matches_from(args); @@ -960,6 +963,10 @@ where builder = builder.c_naming(true); } + if matches.is_present("explicit-padding") { + builder = builder.explicit_padding(true); + } + let verbose = matches.is_present("verbose"); Ok((builder, output, verbose)) diff --git a/tests/expectations/tests/explicit-padding.rs b/tests/expectations/tests/explicit-padding.rs new file mode 100644 index 0000000000..e395e5d245 --- /dev/null +++ b/tests/expectations/tests/explicit-padding.rs @@ -0,0 +1,65 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct pad_me { + pub first: u8, + pub __bindgen_padding_0: [u8; 3usize], + pub second: u32, + pub third: u16, + pub __bindgen_padding_1: [u8; 2usize], +} +#[test] +fn bindgen_test_layout_pad_me() { + assert_eq!( + ::std::mem::size_of::(), + 12usize, + concat!("Size of: ", stringify!(pad_me)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(pad_me)) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).first as *const _ as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(pad_me), + "::", + stringify!(first) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).second as *const _ as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(pad_me), + "::", + stringify!(second) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).third as *const _ as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(pad_me), + "::", + stringify!(third) + ) + ); +} diff --git a/tests/headers/explicit-padding.h b/tests/headers/explicit-padding.h new file mode 100644 index 0000000000..d228961df2 --- /dev/null +++ b/tests/headers/explicit-padding.h @@ -0,0 +1,11 @@ +// bindgen-flags: --explicit-padding + +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; + +struct pad_me { + uint8_t first; + uint32_t second; + uint16_t third; +}; From b6109c00fcb13a27e06387ce2ef417a54c24cf3f Mon Sep 17 00:00:00 2001 From: Eric Seppanen Date: Wed, 2 Jun 2021 18:17:15 -0700 Subject: [PATCH 192/942] add custom derives callback This callback allows us to specify arbitrary derive attributes for each named struct. This is useful for adding things that can't easily be implemented separately, such as `serde::Deserialize` or `zerocopy::FromBytes`. --- src/callbacks.rs | 8 ++++++++ src/codegen/mod.rs | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/src/callbacks.rs b/src/callbacks.rs index e288af4341..9b34544947 100644 --- a/src/callbacks.rs +++ b/src/callbacks.rs @@ -95,4 +95,12 @@ pub trait ParseCallbacks: fmt::Debug + UnwindSafe { ) -> Option { None } + + /// Provide a list of custom derive attributes. + /// + /// If no additional attributes are wanted, this function should return an + /// empty `Vec`. + fn add_derives(&self, _name: &str) -> Vec { + vec![] + } } diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 515ebf1733..c70c106427 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -2005,6 +2005,15 @@ impl CodeGenerator for CompInfo { let mut derives: Vec<_> = derivable_traits.into(); derives.extend(item.annotations().derives().iter().map(String::as_str)); + // The custom derives callback may return a list of derive attributes; + // add them to the end of the list. + let custom_derives; + if let Some(cb) = &ctx.options().parse_callbacks { + custom_derives = cb.add_derives(&canonical_name); + // In most cases this will be a no-op, since custom_derives will be empty. + derives.extend(custom_derives.iter().map(|s| s.as_str())); + }; + if !derives.is_empty() { attributes.push(attributes::derives(&derives)) } From f65f2307f69a85cc7857b88409fe89c2bd2f79b7 Mon Sep 17 00:00:00 2001 From: Eric Seppanen Date: Sun, 6 Jun 2021 15:10:34 -0700 Subject: [PATCH 193/942] add test for add_derives This test derives PartialEq for the Test struct, and then attempts to use that by calling assert_ne! on two Test instances. If the derive callback doesn't work, no PartialEq will be present and the test will fail to compile. --- bindgen-integration/build.rs | 11 +++++++++++ bindgen-integration/src/lib.rs | 9 +++++++++ 2 files changed, 20 insertions(+) diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs index b28dcee577..fa0246c460 100644 --- a/bindgen-integration/build.rs +++ b/bindgen-integration/build.rs @@ -119,6 +119,17 @@ impl ParseCallbacks for MacroCallback { } } } + + // Test the "custom derives" capability by adding `PartialEq` to the `Test` struct. + fn add_derives(&self, name: &str) -> Vec { + if name == "Test" { + vec![ + "PartialEq".into(), + ] + } else { + vec![] + } + } } impl Drop for MacroCallback { diff --git a/bindgen-integration/src/lib.rs b/bindgen-integration/src/lib.rs index 4b288afdc9..f56e72597d 100755 --- a/bindgen-integration/src/lib.rs +++ b/bindgen-integration/src/lib.rs @@ -267,3 +267,12 @@ fn test_homogeneous_aggregate_float_union() { assert_eq!([1., 2., 3., 4.], coord.v) } } + +#[test] +fn test_custom_derive() { + // The `add_derives` callback should have added `#[derive(PartialEq)]` + // to the `Test` struct. If it didn't, this will fail to compile. + let test1 = unsafe { bindings::Test::new(5) }; + let test2 = unsafe { bindings::Test::new(6) }; + assert_ne!(test1, test2); +} From a380678490b821201f10b861144b15bbe08694a2 Mon Sep 17 00:00:00 2001 From: "Ian P. Cooke" Date: Wed, 7 Jul 2021 06:37:04 -0500 Subject: [PATCH 194/942] Let Rust derive everything but Default for large arrays in 1.47 and later Fixes #1977 as of rust-lang/rust#74060 is available since Rust 1.47 Fixes #2041. Closes #2070. --- src/codegen/impl_debug.rs | 4 +- src/codegen/impl_partialeq.rs | 4 +- src/codegen/mod.rs | 7 ++- src/features.rs | 8 ++- src/ir/analysis/derive.rs | 21 ++++--- src/ir/ty.rs | 1 - .../tests/issue-1977-larger-arrays.rs | 61 +++++++++++++++++++ .../issue-648-derive-debug-with-padding.rs | 6 +- tests/headers/class.hpp | 2 +- .../derive-bitfield-method-same-name.hpp | 2 +- tests/headers/derive-clone.h | 2 + tests/headers/derive-debug-bitfield-core.hpp | 2 +- tests/headers/derive-debug-bitfield.hpp | 2 +- .../headers/derive-debug-function-pointer.hpp | 2 +- tests/headers/derive-debug-generic.hpp | 2 +- ...ve-debug-opaque-template-instantiation.hpp | 2 +- tests/headers/derive-debug-opaque.hpp | 2 +- tests/headers/derive-partialeq-base.hpp | 2 +- tests/headers/derive-partialeq-bitfield.hpp | 2 +- tests/headers/derive-partialeq-core.h | 2 +- tests/headers/extern-const-struct.h | 2 + tests/headers/issue-1977-larger-arrays.hpp | 9 +++ tests/headers/issue-372.hpp | 2 +- .../issue-648-derive-debug-with-padding.h | 8 +-- tests/headers/layout_array.h | 2 +- tests/headers/layout_array_too_long.h | 2 +- tests/headers/layout_eth_conf.h | 2 +- tests/headers/layout_kni_mbuf.h | 1 + tests/headers/layout_large_align_field.h | 2 +- tests/headers/no_debug_bypass_impl_debug.hpp | 2 +- .../no_default_bypass_derive_default.hpp | 2 +- tests/headers/opaque-template-inst-member.hpp | 2 +- tests/headers/struct_with_derive_debug.h | 2 +- tests/headers/struct_with_large_array.hpp | 2 +- tests/headers/timex.h | 2 + 35 files changed, 135 insertions(+), 43 deletions(-) create mode 100644 tests/expectations/tests/issue-1977-larger-arrays.rs create mode 100644 tests/headers/issue-1977-larger-arrays.hpp diff --git a/src/codegen/impl_debug.rs b/src/codegen/impl_debug.rs index b8fdd0d444..661711e8a6 100644 --- a/src/codegen/impl_debug.rs +++ b/src/codegen/impl_debug.rs @@ -181,7 +181,9 @@ impl<'a> ImplDebug<'a> for Item { format!("{}: Array with length {}", name, len), vec![], )) - } else if len < RUST_DERIVE_IN_ARRAY_LIMIT { + } else if len < RUST_DERIVE_IN_ARRAY_LIMIT || + ctx.options().rust_features().larger_arrays + { // The simple case debug_print(name, quote! { #name_ident }) } else { diff --git a/src/codegen/impl_partialeq.rs b/src/codegen/impl_partialeq.rs index 5f2600e290..5a1ba3fed4 100644 --- a/src/codegen/impl_partialeq.rs +++ b/src/codegen/impl_partialeq.rs @@ -114,7 +114,9 @@ fn gen_field( } TypeKind::Array(_, len) => { - if len <= RUST_DERIVE_IN_ARRAY_LIMIT { + if len <= RUST_DERIVE_IN_ARRAY_LIMIT || + ctx.options().rust_features().larger_arrays + { quote_equals(name_ident) } else { quote! { diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index c70c106427..d49d3248b4 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -1503,7 +1503,8 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit { // We cannot generate any constructor if the underlying storage can't // implement AsRef<[u8]> / AsMut<[u8]> / etc. - let mut generate_ctor = layout.size <= RUST_DERIVE_IN_ARRAY_LIMIT; + let mut generate_ctor = layout.size <= RUST_DERIVE_IN_ARRAY_LIMIT || + ctx.options().rust_features().larger_arrays; let mut access_spec = !fields_should_be_private; for bf in self.bitfields() { @@ -1512,7 +1513,9 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit { continue; } - if layout.size > RUST_DERIVE_IN_ARRAY_LIMIT { + if layout.size > RUST_DERIVE_IN_ARRAY_LIMIT && + !ctx.options().rust_features().larger_arrays + { continue; } diff --git a/src/features.rs b/src/features.rs index 4ec9dee74d..99b789e089 100644 --- a/src/features.rs +++ b/src/features.rs @@ -123,6 +123,9 @@ macro_rules! rust_target_base { /// Rust stable 1.40 /// * `non_exhaustive` enums/structs ([Tracking issue](https://github.com/rust-lang/rust/issues/44109)) => Stable_1_40 => 1.40; + /// Rust stable 1.47 + /// * `larger_arrays` ([Tracking issue](https://github.com/rust-lang/rust/pull/74060)) + => Stable_1_47 => 1.47; /// Nightly rust /// * `thiscall` calling convention ([Tracking issue](https://github.com/rust-lang/rust/issues/42202)) => Nightly => nightly; @@ -134,7 +137,7 @@ rust_target_base!(rust_target_def); rust_target_base!(rust_target_values_def); /// Latest stable release of Rust -pub const LATEST_STABLE_RUST: RustTarget = RustTarget::Stable_1_40; +pub const LATEST_STABLE_RUST: RustTarget = RustTarget::Stable_1_47; /// Create RustFeatures struct definition, new(), and a getter for each field macro_rules! rust_feature_def { @@ -222,6 +225,9 @@ rust_feature_def!( Stable_1_40 { => non_exhaustive; } + Stable_1_47 { + => larger_arrays; + } Nightly { => thiscall_abi; } diff --git a/src/ir/analysis/derive.rs b/src/ir/analysis/derive.rs index be6266610b..44e6702a40 100644 --- a/src/ir/analysis/derive.rs +++ b/src/ir/analysis/derive.rs @@ -255,7 +255,7 @@ impl<'ctx> CannotDerive<'ctx> { return CanDerive::No; } - if self.derive_trait.can_derive_large_array() { + if self.derive_trait.can_derive_large_array(&self.ctx) { trace!(" array can derive {}", self.derive_trait); return CanDerive::Yes; } @@ -377,7 +377,7 @@ impl<'ctx> CannotDerive<'ctx> { // Bitfield units are always represented as arrays of u8, but // they're not traced as arrays, so we need to check here // instead. - if !self.derive_trait.can_derive_large_array() && + if !self.derive_trait.can_derive_large_array(&self.ctx) && info.has_too_large_bitfield_unit() && !item.is_opaque(self.ctx, &()) { @@ -496,10 +496,17 @@ impl DeriveTrait { } } - fn can_derive_large_array(&self) -> bool { - match self { - DeriveTrait::Copy => true, - _ => false, + fn can_derive_large_array(&self, ctx: &BindgenContext) -> bool { + if ctx.options().rust_features().larger_arrays { + match self { + DeriveTrait::Default => false, + _ => true, + } + } else { + match self { + DeriveTrait::Copy => true, + _ => false, + } } } @@ -686,7 +693,7 @@ impl<'ctx> MonotoneFramework for CannotDerive<'ctx> { Some(ty) => { let mut can_derive = self.constrain_type(item, ty); if let CanDerive::Yes = can_derive { - if !self.derive_trait.can_derive_large_array() && + if !self.derive_trait.can_derive_large_array(&self.ctx) && ty.layout(self.ctx).map_or(false, |l| { l.align > RUST_DERIVE_IN_ARRAY_LIMIT }) diff --git a/src/ir/ty.rs b/src/ir/ty.rs index e6eecc3c50..e049ed6520 100644 --- a/src/ir/ty.rs +++ b/src/ir/ty.rs @@ -39,7 +39,6 @@ pub struct Type { /// traits, and so if we have a type containing an array with more than this /// many items, we won't be able to derive common traits on that type. /// -/// We need type-level integers yesterday :'( pub const RUST_DERIVE_IN_ARRAY_LIMIT: usize = 32; impl Type { diff --git a/tests/expectations/tests/issue-1977-larger-arrays.rs b/tests/expectations/tests/issue-1977-larger-arrays.rs new file mode 100644 index 0000000000..54e5b431db --- /dev/null +++ b/tests/expectations/tests/issue-1977-larger-arrays.rs @@ -0,0 +1,61 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +#[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() { + assert_eq!( + ::std::mem::size_of::(), + 33usize, + concat!("Size of: ", stringify!(S)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(S)) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).large_array as *const _ as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(S), + "::", + stringify!(large_array) + ) + ); +} +impl Default for S { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] +#[derive(Debug, Hash, PartialEq, Eq)] +pub struct ST { + pub large_array: [T; 33usize], + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, +} +impl Default for ST { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} diff --git a/tests/expectations/tests/issue-648-derive-debug-with-padding.rs b/tests/expectations/tests/issue-648-derive-debug-with-padding.rs index 15822b5bdf..4355486947 100644 --- a/tests/expectations/tests/issue-648-derive-debug-with-padding.rs +++ b/tests/expectations/tests/issue-648-derive-debug-with-padding.rs @@ -6,9 +6,7 @@ )] /// We emit a `[u8; 63usize]` padding field for this struct, which cannot derive -/// Debug/Hash because 63 is over the hard coded limit. (Yes, this struct doesn't end -/// up with the reight alignment, we're waiting on `#[repr(align="N")]` to land -/// in rustc). +/// Debug/Hash because 63 is over the hard coded limit. #[repr(C)] #[repr(align(64))] #[derive(Copy, Clone)] @@ -55,7 +53,7 @@ impl ::std::cmp::PartialEq for NoDebug { /// 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. (Again, we expect to get the alignment wrong for similar reasons.) +/// codegen. #[repr(C)] #[repr(align(64))] #[derive(Copy, Clone)] diff --git a/tests/headers/class.hpp b/tests/headers/class.hpp index f77ac92a66..a90e373f77 100644 --- a/tests/headers/class.hpp +++ b/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 +// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --with-derive-partialord --with-derive-ord --rust-target 1.40 // class C { int a; diff --git a/tests/headers/derive-bitfield-method-same-name.hpp b/tests/headers/derive-bitfield-method-same-name.hpp index 4b7b21e93a..ea9d801f4e 100644 --- a/tests/headers/derive-bitfield-method-same-name.hpp +++ b/tests/headers/derive-bitfield-method-same-name.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --with-derive-partialeq --impl-partialeq --impl-debug +// bindgen-flags: --with-derive-partialeq --impl-partialeq --impl-debug --rust-target 1.40 /// Because this struct have array larger than 32 items /// and --with-derive-partialeq --impl-partialeq --impl-debug is provided, diff --git a/tests/headers/derive-clone.h b/tests/headers/derive-clone.h index a84d35cdd2..aacbcaf885 100644 --- a/tests/headers/derive-clone.h +++ b/tests/headers/derive-clone.h @@ -1,3 +1,5 @@ +// bindgen-flags: --rust-target 1.40 +// /// This struct should derive `Clone`. struct ShouldDeriveClone { diff --git a/tests/headers/derive-debug-bitfield-core.hpp b/tests/headers/derive-debug-bitfield-core.hpp index 5d78e74359..2073cc2a0d 100644 --- a/tests/headers/derive-debug-bitfield-core.hpp +++ b/tests/headers/derive-debug-bitfield-core.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --impl-debug --use-core --raw-line "extern crate core;" +// bindgen-flags: --impl-debug --use-core --raw-line "extern crate core;" --rust-target 1.40 class C { bool a: 1; diff --git a/tests/headers/derive-debug-bitfield.hpp b/tests/headers/derive-debug-bitfield.hpp index df43e6a7c2..b68919054a 100644 --- a/tests/headers/derive-debug-bitfield.hpp +++ b/tests/headers/derive-debug-bitfield.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --impl-debug +// bindgen-flags: --impl-debug --rust-target 1.40 class C { bool a: 1; diff --git a/tests/headers/derive-debug-function-pointer.hpp b/tests/headers/derive-debug-function-pointer.hpp index a370dee813..147097fbd8 100644 --- a/tests/headers/derive-debug-function-pointer.hpp +++ b/tests/headers/derive-debug-function-pointer.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --impl-debug +// bindgen-flags: --impl-debug --rust-target 1.40 class Nice { typedef void (*Function) (int data); diff --git a/tests/headers/derive-debug-generic.hpp b/tests/headers/derive-debug-generic.hpp index d5158510ea..50122fafa5 100644 --- a/tests/headers/derive-debug-generic.hpp +++ b/tests/headers/derive-debug-generic.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --impl-debug +// bindgen-flags: --impl-debug --rust-target 1.40 template class Generic { diff --git a/tests/headers/derive-debug-opaque-template-instantiation.hpp b/tests/headers/derive-debug-opaque-template-instantiation.hpp index 0dead782ff..0c70fcc53a 100644 --- a/tests/headers/derive-debug-opaque-template-instantiation.hpp +++ b/tests/headers/derive-debug-opaque-template-instantiation.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --impl-debug +// bindgen-flags: --impl-debug --rust-target 1.40 // This type is opaque because the second template parameter // is a non-type template parameter diff --git a/tests/headers/derive-debug-opaque.hpp b/tests/headers/derive-debug-opaque.hpp index 0ce1d63ab8..715d3c89f1 100644 --- a/tests/headers/derive-debug-opaque.hpp +++ b/tests/headers/derive-debug-opaque.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --opaque-type "Opaque" --impl-debug +// bindgen-flags: --opaque-type "Opaque" --impl-debug --rust-target 1.40 class Opaque { int i; diff --git a/tests/headers/derive-partialeq-base.hpp b/tests/headers/derive-partialeq-base.hpp index 989cbe693a..2a57dca47d 100644 --- a/tests/headers/derive-partialeq-base.hpp +++ b/tests/headers/derive-partialeq-base.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --with-derive-partialeq --impl-partialeq +// bindgen-flags: --with-derive-partialeq --impl-partialeq --rust-target 1.40 class Base { int large[33]; diff --git a/tests/headers/derive-partialeq-bitfield.hpp b/tests/headers/derive-partialeq-bitfield.hpp index ac2cac632a..f6dd82e572 100644 --- a/tests/headers/derive-partialeq-bitfield.hpp +++ b/tests/headers/derive-partialeq-bitfield.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --with-derive-partialeq --impl-partialeq +// bindgen-flags: --with-derive-partialeq --impl-partialeq --rust-target 1.40 class C { bool a: 1; diff --git a/tests/headers/derive-partialeq-core.h b/tests/headers/derive-partialeq-core.h index 6da5b786bc..18eed8b324 100644 --- a/tests/headers/derive-partialeq-core.h +++ b/tests/headers/derive-partialeq-core.h @@ -1,4 +1,4 @@ -// bindgen-flags: --with-derive-partialeq --impl-partialeq --use-core --raw-line "extern crate core;" +// bindgen-flags: --with-derive-partialeq --impl-partialeq --use-core --raw-line "extern crate core;" --rust-target 1.40 struct C { int large_array[420]; diff --git a/tests/headers/extern-const-struct.h b/tests/headers/extern-const-struct.h index 10006e8284..1027127428 100644 --- a/tests/headers/extern-const-struct.h +++ b/tests/headers/extern-const-struct.h @@ -1,3 +1,5 @@ +// bindgen-flags: --rust-target 1.40 + struct nsFoo { float details[400]; }; diff --git a/tests/headers/issue-1977-larger-arrays.hpp b/tests/headers/issue-1977-larger-arrays.hpp new file mode 100644 index 0000000000..58e8e4d19a --- /dev/null +++ b/tests/headers/issue-1977-larger-arrays.hpp @@ -0,0 +1,9 @@ +// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq +// +struct S { + char large_array[33]; +}; + +template struct ST { + T large_array[33]; +}; diff --git a/tests/headers/issue-372.hpp b/tests/headers/issue-372.hpp index 7127be2ccb..a2a5d45122 100644 --- a/tests/headers/issue-372.hpp +++ b/tests/headers/issue-372.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --enable-cxx-namespaces --rustified-enum ".*" +// bindgen-flags: --enable-cxx-namespaces --rustified-enum ".*" --rust-target 1.40 template class c { a e[b]; }; class d; template class C { c h; }; diff --git a/tests/headers/issue-648-derive-debug-with-padding.h b/tests/headers/issue-648-derive-debug-with-padding.h index f528c10011..0860ce9502 100644 --- a/tests/headers/issue-648-derive-debug-with-padding.h +++ b/tests/headers/issue-648-derive-debug-with-padding.h @@ -1,9 +1,7 @@ -// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --impl-partialeq +// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --impl-partialeq --rust-target 1.40 /** * We emit a `[u8; 63usize]` padding field for this struct, which cannot derive - * Debug/Hash because 63 is over the hard coded limit. (Yes, this struct doesn't end - * up with the reight alignment, we're waiting on `#[repr(align="N")]` to land - * in rustc). + * Debug/Hash because 63 is over the hard coded limit. */ struct NoDebug { char c; @@ -14,7 +12,7 @@ struct NoDebug { * 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. (Again, we expect to get the alignment wrong for similar reasons.) + * codegen. */ struct ShouldDeriveDebugButDoesNot { char c[32]; diff --git a/tests/headers/layout_array.h b/tests/headers/layout_array.h index 239e52b193..e6a57f7ca4 100644 --- a/tests/headers/layout_array.h +++ b/tests/headers/layout_array.h @@ -1,4 +1,4 @@ -// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --impl-partialeq +// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --impl-partialeq --rust-target 1.40 typedef unsigned char uint8_t; typedef unsigned short uint16_t; typedef unsigned int uint32_t; diff --git a/tests/headers/layout_array_too_long.h b/tests/headers/layout_array_too_long.h index d0d34ba038..53e4d8bed4 100644 --- a/tests/headers/layout_array_too_long.h +++ b/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 ".*" +// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --impl-partialeq --rustified-enum ".*" --rust-target 1.40 typedef unsigned char uint8_t; typedef unsigned short uint16_t; typedef unsigned int uint32_t; diff --git a/tests/headers/layout_eth_conf.h b/tests/headers/layout_eth_conf.h index 93ab8408ec..9446bffb4c 100644 --- a/tests/headers/layout_eth_conf.h +++ b/tests/headers/layout_eth_conf.h @@ -1,4 +1,4 @@ -// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --rustified-enum ".*" +// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --rustified-enum ".*" --rust-target 1.40 typedef unsigned char uint8_t; typedef unsigned short uint16_t; typedef unsigned int uint32_t; diff --git a/tests/headers/layout_kni_mbuf.h b/tests/headers/layout_kni_mbuf.h index ff161144a3..4d604aa6a8 100644 --- a/tests/headers/layout_kni_mbuf.h +++ b/tests/headers/layout_kni_mbuf.h @@ -1,3 +1,4 @@ +// bindgen-flags: --rust-target 1.40 #define RTE_CACHE_LINE_MIN_SIZE 64 /**< Minimum Cache line size. */ diff --git a/tests/headers/layout_large_align_field.h b/tests/headers/layout_large_align_field.h index f292bb70dc..63aea90bd9 100644 --- a/tests/headers/layout_large_align_field.h +++ b/tests/headers/layout_large_align_field.h @@ -1,4 +1,4 @@ -// bindgen-flags: --rustified-enum ".*" +// bindgen-flags: --rustified-enum ".*" --rust-target 1.40 typedef unsigned char uint8_t; typedef unsigned short uint16_t; diff --git a/tests/headers/no_debug_bypass_impl_debug.hpp b/tests/headers/no_debug_bypass_impl_debug.hpp index a586441088..d934d2c7cb 100644 --- a/tests/headers/no_debug_bypass_impl_debug.hpp +++ b/tests/headers/no_debug_bypass_impl_debug.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --no-debug "NoDebug" --impl-debug +// bindgen-flags: --no-debug "NoDebug" --impl-debug --rust-target 1.40 template class Generic { diff --git a/tests/headers/no_default_bypass_derive_default.hpp b/tests/headers/no_default_bypass_derive_default.hpp index 0f8339062f..ab0fdfae9f 100644 --- a/tests/headers/no_default_bypass_derive_default.hpp +++ b/tests/headers/no_default_bypass_derive_default.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --no-default "NoDefault" +// bindgen-flags: --no-default "NoDefault" --rust-target 1.40 template class Generic { diff --git a/tests/headers/opaque-template-inst-member.hpp b/tests/headers/opaque-template-inst-member.hpp index 6516aa564d..9b327919c1 100644 --- a/tests/headers/opaque-template-inst-member.hpp +++ b/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 +// bindgen-flags: --opaque-type 'OpaqueTemplate' --with-derive-hash --with-derive-partialeq --impl-partialeq --with-derive-eq --rust-target 1.40 template class OpaqueTemplate { diff --git a/tests/headers/struct_with_derive_debug.h b/tests/headers/struct_with_derive_debug.h index 201748d9c5..4dc816b787 100644 --- a/tests/headers/struct_with_derive_debug.h +++ b/tests/headers/struct_with_derive_debug.h @@ -1,4 +1,4 @@ -// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq +// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --rust-target 1.40 // struct LittleArray { int a[32]; diff --git a/tests/headers/struct_with_large_array.hpp b/tests/headers/struct_with_large_array.hpp index 58e8e4d19a..974ca526a3 100644 --- a/tests/headers/struct_with_large_array.hpp +++ b/tests/headers/struct_with_large_array.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq +// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --rust-target 1.40 // struct S { char large_array[33]; diff --git a/tests/headers/timex.h b/tests/headers/timex.h index 1add26cabe..099be61f24 100644 --- a/tests/headers/timex.h +++ b/tests/headers/timex.h @@ -1,3 +1,5 @@ +// bindgen-flags: --rust-target 1.40 + struct timex { int tai; From e05a451ba704fd9e9d310c49bfac4944176b99a3 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Tue, 13 Jul 2021 14:19:31 +0200 Subject: [PATCH 195/942] Bump cexpr to 0.5 --- .github/workflows/bindgen.yml | 4 +-- Cargo.lock | 46 ++++++++++++++++++++++++++++++++--- Cargo.toml | 4 +-- README.md | 2 +- 4 files changed, 46 insertions(+), 10 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 91efe985c6..7080352ce4 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -42,11 +42,11 @@ jobs: profile: minimal # MSRV below is documented in README.md, please update that if you # change this. - toolchain: 1.40.0 + toolchain: 1.44.0 override: true - name: Build with msrv - run: rm Cargo.lock && cargo +1.40.0 build --lib + run: rm Cargo.lock && cargo +1.44.0 build --lib quickchecking: runs-on: ubuntu-latest diff --git a/Cargo.lock b/Cargo.lock index 443201eedc..934dfe4089 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -60,11 +60,23 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +[[package]] +name = "bitvec" +version = "0.19.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8942c8d352ae1838c9dda0b0ca2ab657696ef2232a20147cf1b30ae1a9cb4321" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + [[package]] name = "cexpr" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4aedb84272dbe89af497cf81375129abda4fc0a9e7c5d317498c15cc30c0d27" +checksum = "db507a7679252d2276ed0dd8113c6875ec56d3089f9225b2b42c30cc1f8e5c89" dependencies = [ "nom", ] @@ -126,6 +138,12 @@ dependencies = [ "termcolor", ] +[[package]] +name = "funty" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fed34cd105917e91daa4da6b3728c47b068749d6a62c59811f06ed2ac71d9da7" + [[package]] name = "getrandom" version = "0.2.2" @@ -203,10 +221,12 @@ checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" [[package]] name = "nom" -version = "5.1.2" +version = "6.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffb4262d26ed83a1c0a33a38fe2bb15797329c85770da05e6b828ddb782627af" +checksum = "9c5c51b9083a3c620fa67a2a635d1ce7d95b897e957d6b28ff9a5da960a103a6" dependencies = [ + "bitvec", + "funty", "memchr", "version_check", ] @@ -241,6 +261,12 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "radium" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "941ba9d78d8e2f7ce474c015eea4d9c6d25b6a3327f9832ee29a4de27f91bbb8" + [[package]] name = "rand" version = "0.8.3" @@ -335,6 +361,12 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + [[package]] name = "tempfile" version = "3.2.0" @@ -445,3 +477,9 @@ name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "wyz" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85e60b0d1b5f99db2556934e21937020776a5d31520bf169e851ac44e6420214" diff --git a/Cargo.toml b/Cargo.toml index 6140407840..b276eabd78 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,7 +47,7 @@ tempfile = "3" [dependencies] bitflags = "1.0.3" -cexpr = "0.4" +cexpr = "0.5" # This kinda sucks: https://github.com/rust-lang/cargo/issues/1982 clap = { version = "2", optional = true } clang-sys = { version = "1", features = ["clang_6_0"] } @@ -59,8 +59,6 @@ regex = { version = "1.0", default-features = false , features = [ "std", "unico which = { version = "3.0", optional = true, default-features = false } shlex = "1" rustc-hash = "1.0.1" -# New validation in 0.3.6 breaks bindgen-integration: -# https://github.com/alexcrichton/proc-macro2/commit/489c642. proc-macro2 = { version = "1", default-features = false } [dependencies.env_logger] diff --git a/README.md b/README.md index 60e064ffb0..00f66ebbac 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ extern "C" { ## MSRV -The minimum supported Rust version is **1.40**. +The minimum supported Rust version is **1.44**. No MSRV bump policy has been established yet, so MSRV may increase in any release. From 67140077f65bb5af6eae1b257c91c9f379e56bc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 20 Jul 2021 12:11:31 +0200 Subject: [PATCH 196/942] v0.59.0 --- CHANGELOG.md | 152 ++++++++++++++++++++++++++++++--------------------- Cargo.lock | 2 +- Cargo.toml | 2 +- 3 files changed, 93 insertions(+), 63 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 892a864fb2..5a4cef0844 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,119 +10,125 @@ - [Removed](#removed) - [Fixed](#fixed-1) - [Security](#security) -- [0.58.0](#0580) +- [0.59.0](#0590) - [Added](#added-1) - [Fixed](#fixed-2) - [Changed](#changed-1) +- [0.58.1](#0581) + - [Added](#added-2) +- [0.58.0](#0580) + - [Added](#added-3) + - [Fixed](#fixed-3) + - [Changed](#changed-2) - [Deprecated](#deprecated-1) - [Removed](#removed-1) - - [Fixed](#fixed-3) + - [Fixed](#fixed-4) - [Security](#security-1) - [0.57.0](#0570) - - [Added](#added-2) - - [Fixed](#fixed-4) -- [0.56.0](#0560) - - [Added](#added-3) - - [Changed](#changed-2) + - [Added](#added-4) - [Fixed](#fixed-5) -- [0.55.1](#0551) +- [0.56.0](#0560) + - [Added](#added-5) + - [Changed](#changed-3) - [Fixed](#fixed-6) +- [0.55.1](#0551) + - [Fixed](#fixed-7) - [0.55.0](#0550) - [Removed](#removed-2) - - [Added](#added-4) - - [Changed](#changed-3) - - [Fixed](#fixed-7) -- [0.54.1](#0541) - - [Added](#added-5) + - [Added](#added-6) - [Changed](#changed-4) - [Fixed](#fixed-8) -- [0.54.0](#0540) - - [Added](#added-6) +- [0.54.1](#0541) + - [Added](#added-7) - [Changed](#changed-5) - [Fixed](#fixed-9) -- [0.53.3](#0533) - - [Added](#added-7) - - [Fixed](#fixed-10) -- [0.53.2](#0532) - - [Changed](#changed-6) -- [0.53.1](#0531) +- [0.54.0](#0540) - [Added](#added-8) -- [0.53.0](#0530) + - [Changed](#changed-6) + - [Fixed](#fixed-10) +- [0.53.3](#0533) - [Added](#added-9) - - [Changed](#changed-7) - [Fixed](#fixed-11) -- [0.52.0](#0520) +- [0.53.2](#0532) + - [Changed](#changed-7) +- [0.53.1](#0531) - [Added](#added-10) +- [0.53.0](#0530) + - [Added](#added-11) - [Changed](#changed-8) - [Fixed](#fixed-12) -- [0.51.1](#0511) - - [Fixed](#fixed-13) +- [0.52.0](#0520) + - [Added](#added-12) - [Changed](#changed-9) -- [0.51.0](#0510) + - [Fixed](#fixed-13) +- [0.51.1](#0511) - [Fixed](#fixed-14) - [Changed](#changed-10) - - [Added](#added-11) +- [0.51.0](#0510) + - [Fixed](#fixed-15) + - [Changed](#changed-11) + - [Added](#added-13) - [0.50.0](#0500) - - [Added](#added-12) + - [Added](#added-14) - [0.49.3](#0493) - - [Added](#added-13) + - [Added](#added-15) - [0.49.2](#0492) - - [Changed](#changed-11) -- [0.49.1](#0491) - - [Fixed](#fixed-15) - [Changed](#changed-12) -- [0.49.0](#0490) - - [Added](#added-14) +- [0.49.1](#0491) - [Fixed](#fixed-16) - [Changed](#changed-13) -- [0.48.1](#0481) +- [0.49.0](#0490) + - [Added](#added-16) - [Fixed](#fixed-17) -- [0.48.0](#0480) - [Changed](#changed-14) +- [0.48.1](#0481) - [Fixed](#fixed-18) -- [0.47.4](#0474) - - [Added](#added-15) -- [0.47.3](#0473) +- [0.48.0](#0480) - [Changed](#changed-15) -- [0.47.2](#0472) - [Fixed](#fixed-19) -- [0.47.1](#0471) +- [0.47.4](#0474) + - [Added](#added-17) +- [0.47.3](#0473) - [Changed](#changed-16) +- [0.47.2](#0472) - [Fixed](#fixed-20) -- [0.47.0](#0470) +- [0.47.1](#0471) - [Changed](#changed-17) - [Fixed](#fixed-21) -- [0.33.1 .. 0.46.0](#0331--0460) - - [Added](#added-16) - - [Removed](#removed-3) +- [0.47.0](#0470) - [Changed](#changed-18) - [Fixed](#fixed-22) -- [0.33.1](#0331) +- [0.33.1 .. 0.46.0](#0331--0460) + - [Added](#added-18) + - [Removed](#removed-3) + - [Changed](#changed-19) - [Fixed](#fixed-23) +- [0.33.1](#0331) + - [Fixed](#fixed-24) - [0.33.0](#0330) - [0.32.2](#0322) - - [Fixed](#fixed-24) -- [0.32.1](#0321) - [Fixed](#fixed-25) -- [0.32.0](#0320) - - [Added](#added-17) - - [Changed](#changed-19) +- [0.32.1](#0321) - [Fixed](#fixed-26) -- [0.31.0](#0310) - - [Added](#added-18) +- [0.32.0](#0320) + - [Added](#added-19) - [Changed](#changed-20) - - [Deprecated](#deprecated-2) - - [Removed](#removed-4) - [Fixed](#fixed-27) -- [0.30.0](#0300) - - [Added](#added-19) +- [0.31.0](#0310) + - [Added](#added-20) - [Changed](#changed-21) - - [Deprecated](#deprecated-3) + - [Deprecated](#deprecated-2) + - [Removed](#removed-4) - [Fixed](#fixed-28) -- [0.29.0](#0290) - - [Added](#added-20) +- [0.30.0](#0300) + - [Added](#added-21) - [Changed](#changed-22) + - [Deprecated](#deprecated-3) - [Fixed](#fixed-29) +- [0.29.0](#0290) + - [Added](#added-22) + - [Changed](#changed-23) + - [Fixed](#fixed-30) @@ -144,6 +150,30 @@ ## Security +# 0.59.0 + +Released 2021/07/20 + +## Added + + * Support emitting Makefile-syntax depfiles (#2026) + * Add a C naming option (#2045) + * Allow explicit padding (#2060) + * Add custom derives callback (#2059) + * Let Rust derive everything but Default for large arrays in 1.47 and later (#2070). + +## Fixed + + * Constants now have docstrings (#2027) + * Don't generate bindings for deleted member functions. (#2044) + * Zero out padding in custom Default trait implementations (#2051) + * Identify forward declarations in params. (#2052) + * Add env var EXTRA_CLANG_ARGS_. (#2031) + +## Changed + + * cexpr and nom have been updated, new msrv is 1.44 (#2073). + # 0.58.1 Released 2021/04/06 diff --git a/Cargo.lock b/Cargo.lock index 934dfe4089..8648f3a7c5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -33,7 +33,7 @@ dependencies = [ [[package]] name = "bindgen" -version = "0.58.1" +version = "0.59.0" dependencies = [ "bitflags", "cexpr", diff --git a/Cargo.toml b/Cargo.toml index b276eabd78..0d44577147 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ readme = "README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.58.1" +version = "0.59.0" edition = "2018" build = "build.rs" From 271eeb0782d34942267ceabcf5f1cf118f0f5842 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 26 Jul 2021 00:22:05 +0200 Subject: [PATCH 197/942] codegen: Don't check large_arrays to generate bitfield ctors because they use the Default trait. Fixes #2082 --- src/codegen/mod.rs | 8 +- tests/expectations/tests/timex.rs | 149 +++++++++++++++++++++++++++++- tests/headers/timex.h | 2 - 3 files changed, 152 insertions(+), 7 deletions(-) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index d49d3248b4..0f3337ac5d 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -1502,9 +1502,11 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit { let mut ctor_impl = quote! {}; // We cannot generate any constructor if the underlying storage can't - // implement AsRef<[u8]> / AsMut<[u8]> / etc. - let mut generate_ctor = layout.size <= RUST_DERIVE_IN_ARRAY_LIMIT || - ctx.options().rust_features().larger_arrays; + // implement AsRef<[u8]> / AsMut<[u8]> / etc, or can't derive Default. + // + // We don't check `larger_arrays` here because Default does still have + // the 32 items limitation. + let mut generate_ctor = layout.size <= RUST_DERIVE_IN_ARRAY_LIMIT; let mut access_spec = !fields_should_be_private; for bf in self.bitfields() { diff --git a/tests/expectations/tests/timex.rs b/tests/expectations/tests/timex.rs index 72ada37ad3..b2a84d8462 100644 --- a/tests/expectations/tests/timex.rs +++ b/tests/expectations/tests/timex.rs @@ -92,7 +92,7 @@ where } } #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct timex { pub tai: ::std::os::raw::c_int, pub _bitfield_align_1: [u8; 0], @@ -131,7 +131,7 @@ impl Default for timex { } } #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub struct timex_named { pub tai: ::std::os::raw::c_int, pub _bitfield_align_1: [u32; 0], @@ -171,3 +171,148 @@ impl Default for timex_named { } } } +impl timex_named { + #[inline] + pub fn a(&self) -> ::std::os::raw::c_int { + unsafe { + ::std::mem::transmute(self._bitfield_1.get(0usize, 32u8) as u32) + } + } + #[inline] + pub fn set_a(&mut self, val: ::std::os::raw::c_int) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + self._bitfield_1.set(0usize, 32u8, val as u64) + } + } + #[inline] + pub fn b(&self) -> ::std::os::raw::c_int { + unsafe { + ::std::mem::transmute(self._bitfield_1.get(32usize, 32u8) as u32) + } + } + #[inline] + pub fn set_b(&mut self, val: ::std::os::raw::c_int) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + self._bitfield_1.set(32usize, 32u8, val as u64) + } + } + #[inline] + pub fn c(&self) -> ::std::os::raw::c_int { + unsafe { + ::std::mem::transmute(self._bitfield_1.get(64usize, 32u8) as u32) + } + } + #[inline] + pub fn set_c(&mut self, val: ::std::os::raw::c_int) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + self._bitfield_1.set(64usize, 32u8, val as u64) + } + } + #[inline] + pub fn d(&self) -> ::std::os::raw::c_int { + unsafe { + ::std::mem::transmute(self._bitfield_1.get(96usize, 32u8) as u32) + } + } + #[inline] + pub fn set_d(&mut self, val: ::std::os::raw::c_int) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + self._bitfield_1.set(96usize, 32u8, val as u64) + } + } + #[inline] + pub fn e(&self) -> ::std::os::raw::c_int { + unsafe { + ::std::mem::transmute(self._bitfield_1.get(128usize, 32u8) as u32) + } + } + #[inline] + pub fn set_e(&mut self, val: ::std::os::raw::c_int) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + self._bitfield_1.set(128usize, 32u8, val as u64) + } + } + #[inline] + pub fn f(&self) -> ::std::os::raw::c_int { + unsafe { + ::std::mem::transmute(self._bitfield_1.get(160usize, 32u8) as u32) + } + } + #[inline] + pub fn set_f(&mut self, val: ::std::os::raw::c_int) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + self._bitfield_1.set(160usize, 32u8, val as u64) + } + } + #[inline] + pub fn g(&self) -> ::std::os::raw::c_int { + unsafe { + ::std::mem::transmute(self._bitfield_1.get(192usize, 32u8) as u32) + } + } + #[inline] + pub fn set_g(&mut self, val: ::std::os::raw::c_int) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + self._bitfield_1.set(192usize, 32u8, val as u64) + } + } + #[inline] + pub fn h(&self) -> ::std::os::raw::c_int { + unsafe { + ::std::mem::transmute(self._bitfield_1.get(224usize, 32u8) as u32) + } + } + #[inline] + pub fn set_h(&mut self, val: ::std::os::raw::c_int) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + self._bitfield_1.set(224usize, 32u8, val as u64) + } + } + #[inline] + pub fn i(&self) -> ::std::os::raw::c_int { + unsafe { + ::std::mem::transmute(self._bitfield_1.get(256usize, 32u8) as u32) + } + } + #[inline] + pub fn set_i(&mut self, val: ::std::os::raw::c_int) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + self._bitfield_1.set(256usize, 32u8, val as u64) + } + } + #[inline] + pub fn j(&self) -> ::std::os::raw::c_int { + unsafe { + ::std::mem::transmute(self._bitfield_1.get(288usize, 32u8) as u32) + } + } + #[inline] + pub fn set_j(&mut self, val: ::std::os::raw::c_int) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + self._bitfield_1.set(288usize, 32u8, val as u64) + } + } + #[inline] + pub fn k(&self) -> ::std::os::raw::c_int { + unsafe { + ::std::mem::transmute(self._bitfield_1.get(320usize, 32u8) as u32) + } + } + #[inline] + pub fn set_k(&mut self, val: ::std::os::raw::c_int) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + self._bitfield_1.set(320usize, 32u8, val as u64) + } + } +} diff --git a/tests/headers/timex.h b/tests/headers/timex.h index 099be61f24..1add26cabe 100644 --- a/tests/headers/timex.h +++ b/tests/headers/timex.h @@ -1,5 +1,3 @@ -// bindgen-flags: --rust-target 1.40 - struct timex { int tai; From 9a9438f3d6a3523c69d7bc890e8608b63dbe38a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 26 Jul 2021 00:24:37 +0200 Subject: [PATCH 198/942] v0.59.1 --- CHANGELOG.md | 68 ++++++++++++++++++++++++++++++---------------------- Cargo.lock | 2 +- Cargo.toml | 2 +- 3 files changed, 41 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a4cef0844..a5e8bea0a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,45 +10,47 @@ - [Removed](#removed) - [Fixed](#fixed-1) - [Security](#security) +- [0.59.1](#0591) + - [Fixed](#fixed-2) - [0.59.0](#0590) - [Added](#added-1) - - [Fixed](#fixed-2) + - [Fixed](#fixed-3) - [Changed](#changed-1) - [0.58.1](#0581) - [Added](#added-2) - [0.58.0](#0580) - [Added](#added-3) - - [Fixed](#fixed-3) + - [Fixed](#fixed-4) - [Changed](#changed-2) - [Deprecated](#deprecated-1) - [Removed](#removed-1) - - [Fixed](#fixed-4) + - [Fixed](#fixed-5) - [Security](#security-1) - [0.57.0](#0570) - [Added](#added-4) - - [Fixed](#fixed-5) + - [Fixed](#fixed-6) - [0.56.0](#0560) - [Added](#added-5) - [Changed](#changed-3) - - [Fixed](#fixed-6) -- [0.55.1](#0551) - [Fixed](#fixed-7) +- [0.55.1](#0551) + - [Fixed](#fixed-8) - [0.55.0](#0550) - [Removed](#removed-2) - [Added](#added-6) - [Changed](#changed-4) - - [Fixed](#fixed-8) + - [Fixed](#fixed-9) - [0.54.1](#0541) - [Added](#added-7) - [Changed](#changed-5) - - [Fixed](#fixed-9) + - [Fixed](#fixed-10) - [0.54.0](#0540) - [Added](#added-8) - [Changed](#changed-6) - - [Fixed](#fixed-10) + - [Fixed](#fixed-11) - [0.53.3](#0533) - [Added](#added-9) - - [Fixed](#fixed-11) + - [Fixed](#fixed-12) - [0.53.2](#0532) - [Changed](#changed-7) - [0.53.1](#0531) @@ -56,16 +58,16 @@ - [0.53.0](#0530) - [Added](#added-11) - [Changed](#changed-8) - - [Fixed](#fixed-12) + - [Fixed](#fixed-13) - [0.52.0](#0520) - [Added](#added-12) - [Changed](#changed-9) - - [Fixed](#fixed-13) -- [0.51.1](#0511) - [Fixed](#fixed-14) +- [0.51.1](#0511) + - [Fixed](#fixed-15) - [Changed](#changed-10) - [0.51.0](#0510) - - [Fixed](#fixed-15) + - [Fixed](#fixed-16) - [Changed](#changed-11) - [Added](#added-13) - [0.50.0](#0500) @@ -75,60 +77,60 @@ - [0.49.2](#0492) - [Changed](#changed-12) - [0.49.1](#0491) - - [Fixed](#fixed-16) + - [Fixed](#fixed-17) - [Changed](#changed-13) - [0.49.0](#0490) - [Added](#added-16) - - [Fixed](#fixed-17) + - [Fixed](#fixed-18) - [Changed](#changed-14) - [0.48.1](#0481) - - [Fixed](#fixed-18) + - [Fixed](#fixed-19) - [0.48.0](#0480) - [Changed](#changed-15) - - [Fixed](#fixed-19) + - [Fixed](#fixed-20) - [0.47.4](#0474) - [Added](#added-17) - [0.47.3](#0473) - [Changed](#changed-16) - [0.47.2](#0472) - - [Fixed](#fixed-20) + - [Fixed](#fixed-21) - [0.47.1](#0471) - [Changed](#changed-17) - - [Fixed](#fixed-21) + - [Fixed](#fixed-22) - [0.47.0](#0470) - [Changed](#changed-18) - - [Fixed](#fixed-22) + - [Fixed](#fixed-23) - [0.33.1 .. 0.46.0](#0331--0460) - [Added](#added-18) - [Removed](#removed-3) - [Changed](#changed-19) - - [Fixed](#fixed-23) -- [0.33.1](#0331) - [Fixed](#fixed-24) +- [0.33.1](#0331) + - [Fixed](#fixed-25) - [0.33.0](#0330) - [0.32.2](#0322) - - [Fixed](#fixed-25) -- [0.32.1](#0321) - [Fixed](#fixed-26) +- [0.32.1](#0321) + - [Fixed](#fixed-27) - [0.32.0](#0320) - [Added](#added-19) - [Changed](#changed-20) - - [Fixed](#fixed-27) + - [Fixed](#fixed-28) - [0.31.0](#0310) - [Added](#added-20) - [Changed](#changed-21) - [Deprecated](#deprecated-2) - [Removed](#removed-4) - - [Fixed](#fixed-28) + - [Fixed](#fixed-29) - [0.30.0](#0300) - [Added](#added-21) - [Changed](#changed-22) - [Deprecated](#deprecated-3) - - [Fixed](#fixed-29) + - [Fixed](#fixed-30) - [0.29.0](#0290) - [Added](#added-22) - [Changed](#changed-23) - - [Fixed](#fixed-30) + - [Fixed](#fixed-31) @@ -150,6 +152,14 @@ ## Security +# 0.59.1 + +Released 2021/07/26 + +## Fixed + + * Fixed incorrect bitfield constructors generated for very large bitfields (#2082). + # 0.59.0 Released 2021/07/20 diff --git a/Cargo.lock b/Cargo.lock index 8648f3a7c5..0e93f41aed 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -33,7 +33,7 @@ dependencies = [ [[package]] name = "bindgen" -version = "0.59.0" +version = "0.59.1" dependencies = [ "bitflags", "cexpr", diff --git a/Cargo.toml b/Cargo.toml index 0d44577147..7cf5953bfd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ readme = "README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.59.0" +version = "0.59.1" edition = "2018" build = "build.rs" From d79922d763fa048fbc903beacf7dbf25aaad1f75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 26 Jul 2021 00:27:07 +0200 Subject: [PATCH 199/942] docs: Fix rustfmt install steps. Fixes #2080 --- CONTRIBUTING.md | 2 +- tests/tests.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d533b06451..8a9f8688f6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -100,7 +100,7 @@ compared. Make sure you have `rustfmt` up to date: ``` $ rustup update nightly -$ rustup run nightly cargo install -f rustfmt-nightly +$ rustup component add rustfmt --toolchain nightly ``` Note: running `cargo test` from the root directory of `bindgen`'s repository does not diff --git a/tests/tests.rs b/tests/tests.rs index ced4854027..323cf16dd7 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -49,7 +49,7 @@ The latest `rustfmt` is required to run the `bindgen` test suite. Install `rustfmt` with: $ rustup update nightly - $ rustup run nightly cargo install -f rustfmt-nightly + $ rustup component add rustfmt --toolchain nightly " ); } From fe29f5334aa985e56955b03d5a0d1b8f61eb1a82 Mon Sep 17 00:00:00 2001 From: Bastien Orivel Date: Sat, 31 Jul 2021 05:36:56 +0200 Subject: [PATCH 200/942] Update env_logger to 0.9 The default output changed to be using target instead of the module path in it but this doesn't seem to be affecting bindgen since it's never overriding it and it defaults to the module path. --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0e93f41aed..0bec7b23c9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -127,9 +127,9 @@ checksum = "0e25ea47919b1560c4e3b7fe0aaab9becf5b84a10325ddf7db0f0ba5e1026499" [[package]] name = "env_logger" -version = "0.8.1" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54532e3223c5af90a6a757c90b5c5521564b07e5e7a958681bcd2afad421cdcd" +checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3" dependencies = [ "atty", "humantime", diff --git a/Cargo.toml b/Cargo.toml index 7cf5953bfd..6292dd87bf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -63,7 +63,7 @@ proc-macro2 = { version = "1", default-features = false } [dependencies.env_logger] optional = true -version = "0.8" +version = "0.9.0" [dependencies.log] optional = true From a3f9125ce8c7a6badf972a8e73a1977f6e975262 Mon Sep 17 00:00:00 2001 From: Bastien Orivel Date: Sat, 31 Jul 2021 05:42:22 +0200 Subject: [PATCH 201/942] Update which to 4 --- Cargo.lock | 12 ++++++++++-- Cargo.toml | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0bec7b23c9..9653d3d041 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -125,6 +125,12 @@ version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0e25ea47919b1560c4e3b7fe0aaab9becf5b84a10325ddf7db0f0ba5e1026499" +[[package]] +name = "either" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" + [[package]] name = "env_logger" version = "0.9.0" @@ -440,10 +446,12 @@ checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" [[package]] name = "which" -version = "3.1.1" +version = "4.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d011071ae14a2f6671d0b74080ae0cd8ebf3a6f8c9589a2cd45f23126fe29724" +checksum = "7cc009ab82a2afc94b9e467ab4214aee9cad1356cd9191264203d7d72006e00d" dependencies = [ + "either", + "lazy_static", "libc", ] diff --git a/Cargo.toml b/Cargo.toml index 6292dd87bf..0b04cda72c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -56,7 +56,7 @@ lazy_static = "1" peeking_take_while = "0.1.2" quote = { version = "1", default-features = false } regex = { version = "1.0", default-features = false , features = [ "std", "unicode"]} -which = { version = "3.0", optional = true, default-features = false } +which = { version = "4.2.1", optional = true, default-features = false } shlex = "1" rustc-hash = "1.0.1" proc-macro2 = { version = "1", default-features = false } From 6b7e3eac43a7fd85baef31caf70174c00356ef6a Mon Sep 17 00:00:00 2001 From: Bastien Orivel Date: Sat, 31 Jul 2021 05:44:03 +0200 Subject: [PATCH 202/942] Run a full cargo update for good measure --- Cargo.lock | 100 ++++++++++++++++++++++------------------------------- 1 file changed, 42 insertions(+), 58 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9653d3d041..06dae40e2d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -81,12 +81,6 @@ dependencies = [ "nom", ] -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - [[package]] name = "cfg-if" version = "1.0.0" @@ -95,9 +89,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clang-sys" -version = "1.0.3" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0659001ab56b791be01d4b729c44376edc6718cf389a502e579b77b758f3296c" +checksum = "853eda514c284c2287f4bf20ae614f8781f40a81d32ecda6e91449304dfe077c" dependencies = [ "glob", "libc", @@ -152,11 +146,11 @@ checksum = "fed34cd105917e91daa4da6b3728c47b068749d6a62c59811f06ed2ac71d9da7" [[package]] name = "getrandom" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8" +checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "libc", "wasi", ] @@ -169,18 +163,18 @@ checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" [[package]] name = "hermit-abi" -version = "0.1.17" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aca5565f760fb5b220e499d72710ed156fdb74e631659e99377d9ebfbd13ae8" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" dependencies = [ "libc", ] [[package]] name = "humantime" -version = "2.0.1" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c1ad908cc71012b7bea4d0c53ba96a8cba9962f048fa68d143376143d863b7a" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "lazy_static" @@ -196,27 +190,27 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.80" +version = "0.2.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d58d1b70b004888f764dfbf6a26a3b0342a1632d33968e4a179d8011c760614" +checksum = "320cfe77175da3a483efed4bc0adc1968ca050b098ce4f2f1c13a56626128790" [[package]] name = "libloading" -version = "0.6.5" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1090080fe06ec2648d0da3881d9453d97e71a45f00eb179af7fdd7e3f686fdb0" +checksum = "6f84d96438c15fcd6c3f244c8fce01d1e2b9c6b5623e9c711dc9286d8fc92d6a" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "winapi", ] [[package]] name = "log" -version = "0.4.11" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" +checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" dependencies = [ - "cfg-if 0.1.10", + "cfg-if", ] [[package]] @@ -251,18 +245,18 @@ checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" [[package]] name = "proc-macro2" -version = "1.0.24" +version = "1.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71" +checksum = "5c7ed8b8c7b886ea3ed7dde405212185f423ab44682667c8c6dd14aa1d9f6612" dependencies = [ "unicode-xid", ] [[package]] name = "quote" -version = "1.0.7" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" +checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" dependencies = [ "proc-macro2", ] @@ -275,9 +269,9 @@ checksum = "941ba9d78d8e2f7ce474c015eea4d9c6d25b6a3327f9832ee29a4de27f91bbb8" [[package]] name = "rand" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e" +checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8" dependencies = [ "libc", "rand_chacha", @@ -287,9 +281,9 @@ dependencies = [ [[package]] name = "rand_chacha" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", "rand_core", @@ -297,48 +291,47 @@ dependencies = [ [[package]] name = "rand_core" -version = "0.6.2" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7" +checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" dependencies = [ "getrandom", ] [[package]] name = "rand_hc" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73" +checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7" dependencies = [ "rand_core", ] [[package]] name = "redox_syscall" -version = "0.2.5" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94341e4e44e24f6b591b59e47a8a027df12e008d73fd5672dbea9cc22f4507d9" +checksum = "5ab49abadf3f9e1c4bc499e8845e152ad87d2ad2d30371841171169e9d75feee" dependencies = [ "bitflags", ] [[package]] name = "regex" -version = "1.4.2" +version = "1.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38cf2c13ed4745de91a5eb834e11c00bcc3709e773173b2ce4c56c9fbde04b9c" +checksum = "2a26af418b574bd56588335b3a3659a65725d4e636eb1016c2f9e3b38c7cc759" dependencies = [ "aho-corasick", "memchr", "regex-syntax", - "thread_local", ] [[package]] name = "regex-syntax" -version = "0.6.21" +version = "0.6.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b181ba2dcf07aaccad5448e8ead58db5b742cf85dfe035e2227f137a539a189" +checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" [[package]] name = "remove_dir_all" @@ -379,7 +372,7 @@ version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "libc", "rand", "redox_syscall", @@ -389,9 +382,9 @@ dependencies = [ [[package]] name = "termcolor" -version = "1.1.0" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f" +checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" dependencies = [ "winapi-util", ] @@ -405,15 +398,6 @@ dependencies = [ "unicode-width", ] -[[package]] -name = "thread_local" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14" -dependencies = [ - "lazy_static", -] - [[package]] name = "unicode-width" version = "0.1.8" @@ -422,9 +406,9 @@ checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" [[package]] name = "unicode-xid" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" +checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" [[package]] name = "vec_map" @@ -434,9 +418,9 @@ checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" [[package]] name = "version_check" -version = "0.9.2" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" +checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" [[package]] name = "wasi" From 546454625caa66eddc9400bc7a1048edf2a9fbc8 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Wed, 28 Jul 2021 21:14:12 -0700 Subject: [PATCH 203/942] Canonicalize types before looking for their definitions. In some esoteric cases involving nested templates, `ty.declaration().definition()` isn't enough to find the definition: we need `ty.canonical_type().declaration().definition()` instead. Closes #2078. --- src/ir/item.rs | 4 +- tests/expectations/tests/canonical-types.rs | 278 ++++++++++++++++++ .../tests/layout_cmdline_token.rs | 2 + tests/headers/canonical-types.hpp | 51 ++++ 4 files changed, 333 insertions(+), 2 deletions(-) create mode 100644 tests/expectations/tests/canonical-types.rs create mode 100644 tests/headers/canonical-types.hpp diff --git a/src/ir/item.rs b/src/ir/item.rs index 4e0ba80b42..a38c8e5fb8 100644 --- a/src/ir/item.rs +++ b/src/ir/item.rs @@ -1594,8 +1594,8 @@ impl ClangItemParser for Item { } let decl = { - let decl = ty.declaration(); - decl.definition().unwrap_or(decl) + let canonical_def = ty.canonical_type().declaration().definition(); + canonical_def.unwrap_or_else(|| ty.declaration()) }; let comment = decl.raw_comment().or_else(|| location.raw_comment()); diff --git a/tests/expectations/tests/canonical-types.rs b/tests/expectations/tests/canonical-types.rs new file mode 100644 index 0000000000..80d7fec374 --- /dev/null +++ b/tests/expectations/tests/canonical-types.rs @@ -0,0 +1,278 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct ClassA { + pub _address: u8, +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct ClassA_ClassAInner { + pub x: *mut T, + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, +} +impl Default for ClassA_ClassAInner { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct ClassB { + pub _address: u8, +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct ClassC { + pub _address: u8, +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct ClassC_ClassCInnerB { + pub cache: *mut ClassC_ClassCInnerA, +} +impl Default for ClassC_ClassCInnerB { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct ClassC_ClassCInnerA { + pub member: *mut ClassC_ClassCInnerB, +} +impl Default for ClassC_ClassCInnerA { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct ClassC_ClassCInnerCRTP { + pub _address: u8, +} +impl Default for ClassC_ClassCInnerCRTP { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct ClassD { + pub _address: u8, +} +#[test] +fn bindgen_test_layout_ClassD() { + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(ClassD)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(ClassD)) + ); +} +impl Default for ClassD { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[test] +fn __bindgen_test_layout_ClassB_open0_ClassD_ClassCInnerCRTP_close0_instantiation( +) { + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of template specialization: ", stringify!(ClassB)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of template specialization: ", stringify!(ClassB)) + ); +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct ClassCInnerCRTP { + pub _address: u8, +} +#[test] +fn bindgen_test_layout_ClassCInnerCRTP() { + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(ClassCInnerCRTP)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(ClassCInnerCRTP)) + ); +} +impl Default for ClassCInnerCRTP { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[test] +fn __bindgen_test_layout_ClassB_open0_ClassCInnerCRTP_ClassAInner_close0_instantiation( +) { + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of template specialization: ", stringify!(ClassB)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of template specialization: ", stringify!(ClassB)) + ); +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct ClassAInner { + pub x: *mut ClassCInnerA, +} +#[test] +fn bindgen_test_layout_ClassAInner() { + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(ClassAInner)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(ClassAInner)) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).x as *const _ as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ClassAInner), + "::", + stringify!(x) + ) + ); +} +impl Default for ClassAInner { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct ClassCInnerA { + pub member: *mut ClassCInnerB, +} +#[test] +fn bindgen_test_layout_ClassCInnerA() { + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(ClassCInnerA)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(ClassCInnerA)) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).member as *const _ as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ClassCInnerA), + "::", + stringify!(member) + ) + ); +} +impl Default for ClassCInnerA { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct ClassCInnerB { + pub cache: *mut ClassCInnerA, +} +#[test] +fn bindgen_test_layout_ClassCInnerB() { + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(ClassCInnerB)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(ClassCInnerB)) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).cache as *const _ as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ClassCInnerB), + "::", + stringify!(cache) + ) + ); +} +impl Default for ClassCInnerB { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} diff --git a/tests/expectations/tests/layout_cmdline_token.rs b/tests/expectations/tests/layout_cmdline_token.rs index 644b1b8aab..47170dd709 100644 --- a/tests/expectations/tests/layout_cmdline_token.rs +++ b/tests/expectations/tests/layout_cmdline_token.rs @@ -61,6 +61,8 @@ impl Default for cmdline_token_hdr { } } } +/// Stores a pointer to the ops struct, and the offset: the place to +/// write the parsed result in the destination structure. pub type cmdline_parse_token_hdr_t = cmdline_token_hdr; /// A token is defined by this structure. /// diff --git a/tests/headers/canonical-types.hpp b/tests/headers/canonical-types.hpp new file mode 100644 index 0000000000..c8eadd7e5e --- /dev/null +++ b/tests/headers/canonical-types.hpp @@ -0,0 +1,51 @@ +// bindgen-flags: -- -std=c++14 + +// Issue #2078. To pick up the definition of `ClassCInnerA`, +// `ty.canonical_type().declaration().definition()` is needed. + +template +class ClassA { +public: + class ClassAInner { + public: + T *x; + }; +}; + +template +class ClassB { +public: + void foo() { + ((D *)0)->quux(); + } +}; + +template +class ClassC { + struct ClassCInnerA; + + struct ClassCInnerB { + ClassCInnerA *cache; + }; + static_assert(sizeof(ClassCInnerB) > 0, ""); + + struct ClassCInnerA { + ClassCInnerB *member; + }; + +public: + class ClassCInnerCRTP : public ClassB::ClassAInner> { + public: + void quux() { + ((typename ClassA::ClassAInner *)0)->x->member; + } + }; +}; + +class ClassD : public ClassB::ClassCInnerCRTP> { +public: + void bar() { + ((ClassC::ClassCInnerCRTP *)0)->foo(); + } +}; + From d1d2eb62d36c462416a606c680e6b4ba4716daab Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 30 Jul 2021 19:41:10 -0700 Subject: [PATCH 204/942] Don't assume that an inner class declaration always immediately yields a complete type. It might not if we had to avoid recursion when processing types. Detect that case and bail out. This bug was being masked by the fact that we didn't always find definitions for the recursion check and so it didn't trigger, but now that this check is more reliable we have to be careful in more places. The test case was reduced from the GCC STL allocator definition. --- src/ir/comp.rs | 33 +++++++++++-------- .../tests/nested-template-typedef.rs | 17 ++++++++++ tests/headers/nested-template-typedef.hpp | 8 +++++ 3 files changed, 44 insertions(+), 14 deletions(-) create mode 100644 tests/expectations/tests/nested-template-typedef.rs create mode 100644 tests/headers/nested-template-typedef.hpp diff --git a/src/ir/comp.rs b/src/ir/comp.rs index e554f9a89c..97983308db 100644 --- a/src/ir/comp.rs +++ b/src/ir/comp.rs @@ -1408,21 +1408,26 @@ impl CompInfo { let inner = Item::parse(cur, Some(potential_id), ctx) .expect("Inner ClassDecl"); - let inner = inner.expect_type_id(ctx); - - ci.inner_types.push(inner); - - // A declaration of an union or a struct without name could - // also be an unnamed field, unfortunately. - if cur.spelling().is_empty() && - cur.kind() != CXCursor_EnumDecl - { - let ty = cur.cur_type(); - let public = cur.public_accessible(); - let offset = cur.offset_of_field().ok(); + // If we avoided recursion parsing this type (in + // `Item::from_ty_with_id()`), then this might not be a + // valid type ID, so check and gracefully handle this. + if ctx.resolve_item_fallible(inner).is_some() { + let inner = inner.expect_type_id(ctx); + + ci.inner_types.push(inner); + + // A declaration of an union or a struct without name + // could also be an unnamed field, unfortunately. + if cur.spelling().is_empty() && + cur.kind() != CXCursor_EnumDecl + { + let ty = cur.cur_type(); + let public = cur.public_accessible(); + let offset = cur.offset_of_field().ok(); - maybe_anonymous_struct_field = - Some((inner, ty, public, offset)); + maybe_anonymous_struct_field = + Some((inner, ty, public, offset)); + } } } CXCursor_PackedAttr => { diff --git a/tests/expectations/tests/nested-template-typedef.rs b/tests/expectations/tests/nested-template-typedef.rs new file mode 100644 index 0000000000..ab761d286f --- /dev/null +++ b/tests/expectations/tests/nested-template-typedef.rs @@ -0,0 +1,17 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Foo { + pub _address: u8, +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Foo_Bar { + pub _address: u8, +} diff --git a/tests/headers/nested-template-typedef.hpp b/tests/headers/nested-template-typedef.hpp new file mode 100644 index 0000000000..8c83de5bae --- /dev/null +++ b/tests/headers/nested-template-typedef.hpp @@ -0,0 +1,8 @@ +template +class Foo { +public: + template + struct Bar { + typedef Foo FooU; + }; +}; From 9833b6745d74896620ea760f3bf81f344a105f30 Mon Sep 17 00:00:00 2001 From: Karel Peeters Date: Fri, 23 Jul 2021 17:43:44 +0200 Subject: [PATCH 205/942] Implement must_use_type commandline flag and builder option. --- src/codegen/mod.rs | 4 ++++ src/ir/context.rs | 6 ++++++ src/lib.rs | 13 +++++++++++++ src/options.rs | 13 +++++++++++++ .../tests/issue-710-must-use-type.rs | 18 ++++++++++++++++++ tests/headers/issue-710-must-use-type.h | 5 +++++ 6 files changed, 59 insertions(+) create mode 100644 tests/expectations/tests/issue-710-must-use-type.rs create mode 100644 tests/headers/issue-710-must-use-type.h diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 0f3337ac5d..76c64e4ad7 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -2023,6 +2023,10 @@ impl CodeGenerator for CompInfo { attributes.push(attributes::derives(&derives)) } + if ctx.must_use_type_by_name(item) { + attributes.push(attributes::must_use()); + } + let mut tokens = if is_union && struct_layout.is_rust_union() { quote! { #( #attributes )* diff --git a/src/ir/context.rs b/src/ir/context.rs index 72ce06b10c..bd21058c4b 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -2663,6 +2663,12 @@ If you encounter an error missing from this list, please file an issue or a PR!" let name = item.path_for_allowlisting(self)[1..].join("::"); self.options().no_hash_types.matches(&name) } + + /// Check if `--must-use-type` flag is enabled for this item. + pub fn must_use_type_by_name(&self, item: &Item) -> bool { + let name = item.path_for_allowlisting(self)[1..].join("::"); + self.options().must_use_types.matches(&name) + } } /// A builder struct for configuring item resolution options. diff --git a/src/lib.rs b/src/lib.rs index 1c51c8ae42..67cfeb3dae 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -317,6 +317,7 @@ impl Builder { (&self.options.no_debug_types, "--no-debug"), (&self.options.no_default_types, "--no-default"), (&self.options.no_hash_types, "--no-hash"), + (&self.options.must_use_types, "--must-use-type"), ]; for (set, flag) in regex_sets { @@ -1588,6 +1589,13 @@ impl Builder { self } + /// Add `#[must_use]` for the given type. Regular + /// expressions are supported. + pub fn must_use_type>(mut self, arg: T) -> Builder { + self.options.must_use_types.insert(arg.into()); + self + } + /// Set whether `arr[size]` should be treated as `*mut T` or `*mut [T; size]` (same for mut) pub fn array_pointers_in_arguments(mut self, doit: bool) -> Self { self.options.array_pointers_in_arguments = doit; @@ -1928,6 +1936,9 @@ struct BindgenOptions { /// The set of types that we should not derive `Hash` for. no_hash_types: RegexSet, + /// The set of types that we should be annotated with `#[must_use]`. + must_use_types: RegexSet, + /// Decide if C arrays should be regular pointers in rust or array pointers array_pointers_in_arguments: bool, @@ -1986,6 +1997,7 @@ impl BindgenOptions { &mut self.no_debug_types, &mut self.no_default_types, &mut self.no_hash_types, + &mut self.must_use_types, ]; let record_matches = self.record_matches; for regex_set in &mut regex_sets { @@ -2090,6 +2102,7 @@ impl Default for BindgenOptions { no_debug_types: Default::default(), no_default_types: Default::default(), no_hash_types: Default::default(), + must_use_types: Default::default(), array_pointers_in_arguments: false, wasm_import_module_name: None, dynamic_library_name: None, diff --git a/src/options.rs b/src/options.rs index eeeb5aae8c..7f27e22116 100644 --- a/src/options.rs +++ b/src/options.rs @@ -486,6 +486,13 @@ where .takes_value(true) .multiple(true) .number_of_values(1), + Arg::with_name("must-use-type") + .long("must-use-type") + .help("Add #[must_use] annotation to types matching .") + .value_name("regex") + .takes_value(true) + .multiple(true) + .number_of_values(1), Arg::with_name("enable-function-attribute-detection") .long("enable-function-attribute-detection") .help( @@ -942,6 +949,12 @@ where builder = builder.no_hash(regex); } } + + if let Some(must_use_type) = matches.values_of("must-use-type") { + for regex in must_use_type { + builder = builder.must_use_type(regex); + } + } if let Some(dynamic_library_name) = matches.value_of("dynamic-loading") { builder = builder.dynamic_library_name(dynamic_library_name); diff --git a/tests/expectations/tests/issue-710-must-use-type.rs b/tests/expectations/tests/issue-710-must-use-type.rs new file mode 100644 index 0000000000..20a713e45e --- /dev/null +++ b/tests/expectations/tests/issue-710-must-use-type.rs @@ -0,0 +1,18 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +#[derive(Debug, Copy, Clone)] +#[must_use] +pub struct MyType { + _unused: [u8; 0], +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct OtherType { + _unused: [u8; 0], +} diff --git a/tests/headers/issue-710-must-use-type.h b/tests/headers/issue-710-must-use-type.h new file mode 100644 index 0000000000..0c047e611f --- /dev/null +++ b/tests/headers/issue-710-must-use-type.h @@ -0,0 +1,5 @@ +// bindgen-flags: --must-use-type MyType + +struct MyType; + +struct OtherType; From 01a7a4d7158c2d227dc55199fe1a4306dcbe68cf Mon Sep 17 00:00:00 2001 From: Karel Peeters Date: Fri, 23 Jul 2021 18:40:23 +0200 Subject: [PATCH 206/942] Also implement div-style must_use_type annotation. --- src/codegen/mod.rs | 2 +- src/ir/annotations.rs | 9 +++++++++ tests/expectations/tests/issue-710-must-use-type.rs | 11 +++++++++-- tests/headers/issue-710-must-use-type.h | 9 ++++++--- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 76c64e4ad7..2522922a9c 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -2023,7 +2023,7 @@ impl CodeGenerator for CompInfo { attributes.push(attributes::derives(&derives)) } - if ctx.must_use_type_by_name(item) { + if item.annotations().must_use_type() || ctx.must_use_type_by_name(item) { attributes.push(attributes::must_use()); } diff --git a/src/ir/annotations.rs b/src/ir/annotations.rs index 12664f6022..4b571eaa9f 100644 --- a/src/ir/annotations.rs +++ b/src/ir/annotations.rs @@ -42,6 +42,8 @@ pub struct Annotations { disallow_debug: bool, /// Manually disable deriving/implement default on this type. disallow_default: bool, + /// Whether to add a #[must_use] annotation to this type. + must_use_type: bool, /// Whether fields should be marked as private or not. You can set this on /// structs (it will apply to all the fields), or individual fields. private_fields: Option, @@ -84,6 +86,7 @@ impl Default for Annotations { disallow_copy: false, disallow_debug: false, disallow_default: false, + must_use_type: false, private_fields: None, accessor_kind: None, constify_enum_variant: false, @@ -163,6 +166,11 @@ impl Annotations { self.disallow_default } + /// Should this type get a `#[must_use]` annotation? + pub fn must_use_type(&self) -> bool { + self.must_use_type + } + /// Should the fields be private? pub fn private_fields(&self) -> Option { self.private_fields @@ -190,6 +198,7 @@ impl Annotations { "nocopy" => self.disallow_copy = true, "nodebug" => self.disallow_debug = true, "nodefault" => self.disallow_default = true, + "mustusetype" => self.must_use_type = true, "replaces" => { self.use_instead_of = Some( attr.value.split("::").map(Into::into).collect(), diff --git a/tests/expectations/tests/issue-710-must-use-type.rs b/tests/expectations/tests/issue-710-must-use-type.rs index 20a713e45e..1d59824146 100644 --- a/tests/expectations/tests/issue-710-must-use-type.rs +++ b/tests/expectations/tests/issue-710-must-use-type.rs @@ -8,11 +8,18 @@ #[repr(C)] #[derive(Debug, Copy, Clone)] #[must_use] -pub struct MyType { +pub struct A { _unused: [u8; 0], } +///
#[repr(C)] #[derive(Debug, Copy, Clone)] -pub struct OtherType { +#[must_use] +pub struct B { + _unused: [u8; 0], +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct C { _unused: [u8; 0], } diff --git a/tests/headers/issue-710-must-use-type.h b/tests/headers/issue-710-must-use-type.h index 0c047e611f..276f636d70 100644 --- a/tests/headers/issue-710-must-use-type.h +++ b/tests/headers/issue-710-must-use-type.h @@ -1,5 +1,8 @@ -// bindgen-flags: --must-use-type MyType +// bindgen-flags: --must-use-type A -struct MyType; +struct A; -struct OtherType; +/**
*/ +struct B; + +struct C; From 2c5840fb3d6400922e8f136f44fe787b6dd7ed7a Mon Sep 17 00:00:00 2001 From: Karel Peeters Date: Fri, 23 Jul 2021 18:46:31 +0200 Subject: [PATCH 207/942] Add must-use-type to the book. --- book/src/SUMMARY.md | 1 + book/src/must-use-types.md | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 book/src/must-use-types.md diff --git a/book/src/SUMMARY.md b/book/src/SUMMARY.md index 65ed0870fb..f9cc869f12 100644 --- a/book/src/SUMMARY.md +++ b/book/src/SUMMARY.md @@ -19,6 +19,7 @@ - [Preventing the Derivation of `Copy` and `Clone`](./nocopy.md) - [Preventing the Derivation of `Debug`](./nodebug.md) - [Preventing the Derivation of `Default`](./nodefault.md) + - [Annotating types with `#[must-use]`](./must-use-types.md) - [Generating Bindings to C++](./cpp.md) - [Generating Bindings to Objective-c](./objc.md) - [Using Unions](./using-unions.md) diff --git a/book/src/must-use-types.md b/book/src/must-use-types.md new file mode 100644 index 0000000000..490339c9d2 --- /dev/null +++ b/book/src/must-use-types.md @@ -0,0 +1,27 @@ +# Annotating types with `#[must-use]` + +`bindgen` can be instructed to annotate certain types with +[`#[must_use]`](https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-must_use-attribute). + +Some libraries have a common error type, returned by lots of their functions, +which needs to be checked after every call. In these cases it's useful to add `#[must_use]` to this type, so the Rust +compiler emits a warning when the check is missing. +### Library + +* [`bindgen::Builder::must_use_type`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.must_use_type) + +### Command Line + +* `--must-use-type ` + +### Annotations + +```c +/**
*/ +struct ErrorType { + // ... +}; + +... +``` + From 0f641061a78b8af93e977e072cfd8106461b3ca5 Mon Sep 17 00:00:00 2001 From: Karel Peeters Date: Fri, 23 Jul 2021 19:38:02 +0200 Subject: [PATCH 208/942] Also implement must-use-type for enums. --- src/codegen/mod.rs | 8 +++++++- src/options.rs | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 2522922a9c..b823fb340c 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -2023,7 +2023,8 @@ impl CodeGenerator for CompInfo { attributes.push(attributes::derives(&derives)) } - if item.annotations().must_use_type() || ctx.must_use_type_by_name(item) { + if item.annotations().must_use_type() || ctx.must_use_type_by_name(item) + { attributes.push(attributes::must_use()); } @@ -3002,6 +3003,11 @@ impl CodeGenerator for Enum { attrs.push(attributes::doc(comment)); } + if item.annotations().must_use_type() || ctx.must_use_type_by_name(item) + { + attrs.push(attributes::must_use()); + } + if !variation.is_const() { let mut derives = derives_of_item(item, ctx); // For backwards compat, enums always derive Clone/Eq/PartialEq/Hash, even diff --git a/src/options.rs b/src/options.rs index 7f27e22116..0524871aef 100644 --- a/src/options.rs +++ b/src/options.rs @@ -949,7 +949,7 @@ where builder = builder.no_hash(regex); } } - + if let Some(must_use_type) = matches.values_of("must-use-type") { for regex in must_use_type { builder = builder.must_use_type(regex); From 098b416283610b3adbb5a51325644a8a66a4bfd2 Mon Sep 17 00:00:00 2001 From: Christian Vetter Date: Tue, 3 Aug 2021 09:03:46 +0200 Subject: [PATCH 209/942] Use annotations on enumerations: This enables users to add additional derives, or prevent deriving traits Fixes #2076 --- src/codegen/mod.rs | 16 +++++++-- .../tests/enum-default-bitfield.rs | 36 +++++++++++++++++++ .../expectations/tests/enum-default-consts.rs | 4 +++ .../expectations/tests/enum-default-module.rs | 6 ++++ tests/expectations/tests/enum-default-rust.rs | 7 ++++ tests/expectations/tests/enum.rs | 4 +++ tests/headers/enum.h | 6 ++++ 7 files changed, 76 insertions(+), 3 deletions(-) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index b823fb340c..8858377fa6 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -3010,16 +3010,26 @@ impl CodeGenerator for Enum { if !variation.is_const() { let mut derives = derives_of_item(item, ctx); - // For backwards compat, enums always derive Clone/Eq/PartialEq/Hash, even + // For backwards compat, enums always derive Debug/Clone/Eq/PartialEq/Hash, even // if we don't generate those by default. + if !item.annotations().disallow_debug() { + derives.insert(DerivableTraits::DEBUG); + } + if !item.annotations().disallow_copy() { + derives.insert(DerivableTraits::COPY); + } derives.insert( DerivableTraits::CLONE | - DerivableTraits::COPY | DerivableTraits::HASH | DerivableTraits::PARTIAL_EQ | DerivableTraits::EQ, ); - let derives: Vec<_> = derives.into(); + let mut derives: Vec<_> = derives.into(); + for derive in item.annotations().derives().iter() { + if !derives.contains(&derive.as_str()) { + derives.push(&derive); + } + } attrs.push(attributes::derives(&derives)); } diff --git a/tests/expectations/tests/enum-default-bitfield.rs b/tests/expectations/tests/enum-default-bitfield.rs index 1520bea70d..1dc27fdc40 100644 --- a/tests/expectations/tests/enum-default-bitfield.rs +++ b/tests/expectations/tests/enum-default-bitfield.rs @@ -149,3 +149,39 @@ impl ::std::ops::BitAndAssign for NoDebug { ///
#[derive(Copy, Clone, Hash, PartialEq, Eq)] pub struct NoDebug(pub ::std::os::raw::c_uint); +impl Debug { + pub const Debug1: Debug = Debug(0); +} +impl Debug { + pub const Debug2: Debug = Debug(1); +} +impl ::std::ops::BitOr for Debug { + type Output = Self; + #[inline] + fn bitor(self, other: Self) -> Self { + Debug(self.0 | other.0) + } +} +impl ::std::ops::BitOrAssign for Debug { + #[inline] + fn bitor_assign(&mut self, rhs: Debug) { + self.0 |= rhs.0; + } +} +impl ::std::ops::BitAnd for Debug { + type Output = Self; + #[inline] + fn bitand(self, other: Self) -> Self { + Debug(self.0 & other.0) + } +} +impl ::std::ops::BitAndAssign for Debug { + #[inline] + fn bitand_assign(&mut self, rhs: Debug) { + self.0 &= rhs.0; + } +} +#[repr(transparent)] +///
+#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +pub struct Debug(pub ::std::os::raw::c_uint); \ No newline at end of file diff --git a/tests/expectations/tests/enum-default-consts.rs b/tests/expectations/tests/enum-default-consts.rs index 1a9513d928..5c023a3c64 100644 --- a/tests/expectations/tests/enum-default-consts.rs +++ b/tests/expectations/tests/enum-default-consts.rs @@ -57,3 +57,7 @@ pub const NoDebug_NoDebug1: NoDebug = 0; pub const NoDebug_NoDebug2: NoDebug = 1; ///
pub type NoDebug = ::std::os::raw::c_uint; +pub const Debug_Debug1: Debug = 0; +pub const Debug_Debug2: Debug = 1; +///
+pub type Debug = ::std::os::raw::c_uint; \ No newline at end of file diff --git a/tests/expectations/tests/enum-default-module.rs b/tests/expectations/tests/enum-default-module.rs index 73a0462eac..156bbcaad0 100644 --- a/tests/expectations/tests/enum-default-module.rs +++ b/tests/expectations/tests/enum-default-module.rs @@ -63,3 +63,9 @@ pub mod NoDebug { pub const NoDebug1: Type = 0; pub const NoDebug2: Type = 1; } +pub mod Debug { + ///
+ pub type Type = ::std::os::raw::c_uint; + pub const Debug1: Type = 0; + pub const Debug2: Type = 1; +} \ No newline at end of file diff --git a/tests/expectations/tests/enum-default-rust.rs b/tests/expectations/tests/enum-default-rust.rs index c47521a29c..045330a823 100644 --- a/tests/expectations/tests/enum-default-rust.rs +++ b/tests/expectations/tests/enum-default-rust.rs @@ -68,3 +68,10 @@ pub enum NoDebug { NoDebug1 = 0, NoDebug2 = 1, } +#[repr(u32)] +///
+#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +pub enum Debug { + Debug1 = 0, + Debug2 = 1, +} \ No newline at end of file diff --git a/tests/expectations/tests/enum.rs b/tests/expectations/tests/enum.rs index 67d263e94c..cc3f4932ca 100644 --- a/tests/expectations/tests/enum.rs +++ b/tests/expectations/tests/enum.rs @@ -55,3 +55,7 @@ pub const NoDebug_NoDebug1: NoDebug = 0; pub const NoDebug_NoDebug2: NoDebug = 1; ///
pub type NoDebug = ::std::os::raw::c_uint; +pub const Debug_Debug1: Debug = 0; +pub const Debug_Debug2: Debug = 1; +///
+pub type Debug = ::std::os::raw::c_uint; \ No newline at end of file diff --git a/tests/headers/enum.h b/tests/headers/enum.h index 8b41f855d9..0147433ee9 100644 --- a/tests/headers/enum.h +++ b/tests/headers/enum.h @@ -23,3 +23,9 @@ enum NoDebug { NoDebug1, NoDebug2, }; + +/**
*/ +enum Debug { + Debug1, + Debug2, +}; \ No newline at end of file From cf6edbd7b0dc59b82311b65dcb62d5993349f577 Mon Sep 17 00:00:00 2001 From: Christian Vetter Date: Tue, 3 Aug 2021 09:04:40 +0200 Subject: [PATCH 210/942] Add tests --- .../expectations/tests/enum-no-debug-rust.rs | 77 +++++++++++++++++++ tests/headers/enum-no-debug-rust.h | 3 + 2 files changed, 80 insertions(+) create mode 100644 tests/expectations/tests/enum-no-debug-rust.rs create mode 100644 tests/headers/enum-no-debug-rust.h diff --git a/tests/expectations/tests/enum-no-debug-rust.rs b/tests/expectations/tests/enum-no-debug-rust.rs new file mode 100644 index 0000000000..fa06fbc0c6 --- /dev/null +++ b/tests/expectations/tests/enum-no-debug-rust.rs @@ -0,0 +1,77 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct foo { + pub member: foo__bindgen_ty_1, +} +pub const foo_FOO_A: foo__bindgen_ty_1 = foo__bindgen_ty_1::FOO_A; +pub const foo_FOO_B: foo__bindgen_ty_1 = foo__bindgen_ty_1::FOO_B; +#[repr(u32)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +pub enum foo__bindgen_ty_1 { + FOO_A = 0, + FOO_B = 1, +} +#[test] +fn bindgen_test_layout_foo() { + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).member as *const _ as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(member) + ) + ); +} +impl Default for foo { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(u32)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +pub enum Foo { + Bar = 0, + Qux = 1, +} +pub mod Neg { + pub type Type = ::std::os::raw::c_int; + pub const MinusOne: Type = -1; + pub const One: Type = 1; +} +#[repr(u32)] +///
+#[derive(Copy, Clone, Hash, PartialEq, Eq)] +pub enum NoDebug { + NoDebug1 = 0, + NoDebug2 = 1, +} +#[repr(u32)] +///
+#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +pub enum Debug { + Debug1 = 0, + Debug2 = 1, +} \ No newline at end of file diff --git a/tests/headers/enum-no-debug-rust.h b/tests/headers/enum-no-debug-rust.h new file mode 100644 index 0000000000..7cb7398029 --- /dev/null +++ b/tests/headers/enum-no-debug-rust.h @@ -0,0 +1,3 @@ +// bindgen-flags: --no-derive-debug --default-enum-style=rust --constified-enum-module=Neg + +#include "enum.h" From b71e73bfb58a7c70d6e1561b258b4f648246a374 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 30 Jul 2021 17:25:08 -0700 Subject: [PATCH 211/942] Detect and avoid cycles when resolving items. These can happen in certain cases involving incomplete qualified dependent types. To avoid looping forever, we need to check for them. Closes #2085. --- src/ir/context.rs | 8 ++++++++ .../tests/qualified-dependent-types.rs | 17 +++++++++++++++++ tests/headers/qualified-dependent-types.hpp | 16 ++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 tests/expectations/tests/qualified-dependent-types.rs create mode 100644 tests/headers/qualified-dependent-types.hpp diff --git a/src/ir/context.rs b/src/ir/context.rs index bd21058c4b..44df063a9b 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -2723,8 +2723,16 @@ impl ItemResolver { assert!(ctx.collected_typerefs()); let mut id = self.id; + let mut seen_ids = HashSet::default(); loop { let item = ctx.resolve_item(id); + + // Detect cycles and bail out. These can happen in certain cases + // involving incomplete qualified dependent types (#2085). + if !seen_ids.insert(id) { + return item; + } + let ty_kind = item.as_type().map(|t| t.kind()); match ty_kind { Some(&TypeKind::ResolvedTypeRef(next_id)) diff --git a/tests/expectations/tests/qualified-dependent-types.rs b/tests/expectations/tests/qualified-dependent-types.rs new file mode 100644 index 0000000000..f1b2c8459c --- /dev/null +++ b/tests/expectations/tests/qualified-dependent-types.rs @@ -0,0 +1,17 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Foo { + pub _address: u8, +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Bar { + pub _address: u8, +} diff --git a/tests/headers/qualified-dependent-types.hpp b/tests/headers/qualified-dependent-types.hpp new file mode 100644 index 0000000000..fcdfc87c81 --- /dev/null +++ b/tests/headers/qualified-dependent-types.hpp @@ -0,0 +1,16 @@ +// Issue #2085. + +template +struct Foo; + +template +struct Bar {}; + +template +struct Bar { + using BarDependent = typename Foo::Dependent; + void method(const BarDependent &); +}; + +template +void Bar::method(const BarDependent &) {} From 82462a37a149108db8c428f6caa5d8853ba25c40 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Wed, 13 Oct 2021 11:30:08 +0200 Subject: [PATCH 212/942] Bump cexpr to 0.6 --- .github/workflows/bindgen.yml | 4 +-- CHANGELOG.md | 2 ++ Cargo.lock | 53 ++++++++--------------------------- Cargo.toml | 2 +- README.md | 2 +- 5 files changed, 17 insertions(+), 46 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 7080352ce4..11379aa7d6 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -42,11 +42,11 @@ jobs: profile: minimal # MSRV below is documented in README.md, please update that if you # change this. - toolchain: 1.44.0 + toolchain: 1.46.0 override: true - name: Build with msrv - run: rm Cargo.lock && cargo +1.44.0 build --lib + run: rm Cargo.lock && cargo +1.46.0 build --lib quickchecking: runs-on: ubuntu-latest diff --git a/CHANGELOG.md b/CHANGELOG.md index a5e8bea0a3..73c405c7da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -144,6 +144,8 @@ ## Changed + * cexpr and nom have been updated, new msrv is 1.46 (#2107). + ## Deprecated ## Removed diff --git a/Cargo.lock b/Cargo.lock index 06dae40e2d..400fb112dd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -60,23 +60,11 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" -[[package]] -name = "bitvec" -version = "0.19.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8942c8d352ae1838c9dda0b0ca2ab657696ef2232a20147cf1b30ae1a9cb4321" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "cexpr" -version = "0.5.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db507a7679252d2276ed0dd8113c6875ec56d3089f9225b2b42c30cc1f8e5c89" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" dependencies = [ "nom", ] @@ -138,12 +126,6 @@ dependencies = [ "termcolor", ] -[[package]] -name = "funty" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fed34cd105917e91daa4da6b3728c47b068749d6a62c59811f06ed2ac71d9da7" - [[package]] name = "getrandom" version = "0.2.3" @@ -219,15 +201,20 @@ version = "2.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" +[[package]] +name = "minimal-lexical" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c64630dcdd71f1a64c435f54885086a0de5d6a12d104d69b165fb7d5286d677" + [[package]] name = "nom" -version = "6.2.1" +version = "7.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c5c51b9083a3c620fa67a2a635d1ce7d95b897e957d6b28ff9a5da960a103a6" +checksum = "7ffd9d26838a953b4af82cbeb9f1592c6798916983959be223a7124e992742c1" dependencies = [ - "bitvec", - "funty", "memchr", + "minimal-lexical", "version_check", ] @@ -261,12 +248,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "941ba9d78d8e2f7ce474c015eea4d9c6d25b6a3327f9832ee29a4de27f91bbb8" - [[package]] name = "rand" version = "0.8.4" @@ -360,12 +341,6 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "tempfile" version = "3.2.0" @@ -469,9 +444,3 @@ name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "wyz" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85e60b0d1b5f99db2556934e21937020776a5d31520bf169e851ac44e6420214" diff --git a/Cargo.toml b/Cargo.toml index 0b04cda72c..26fd6cb9ea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,7 +47,7 @@ tempfile = "3" [dependencies] bitflags = "1.0.3" -cexpr = "0.5" +cexpr = "0.6" # This kinda sucks: https://github.com/rust-lang/cargo/issues/1982 clap = { version = "2", optional = true } clang-sys = { version = "1", features = ["clang_6_0"] } diff --git a/README.md b/README.md index 00f66ebbac..7b2dbbc233 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ extern "C" { ## MSRV -The minimum supported Rust version is **1.44**. +The minimum supported Rust version is **1.46**. No MSRV bump policy has been established yet, so MSRV may increase in any release. From 1e6db4c30689636e31a8bca2817c2edd53991ff8 Mon Sep 17 00:00:00 2001 From: MikuroXina Date: Mon, 25 Oct 2021 22:06:54 +0900 Subject: [PATCH 213/942] Fix warnings --- src/clang.rs | 64 +++++----- src/codegen/helpers.rs | 6 +- src/codegen/impl_debug.rs | 37 +++--- src/codegen/impl_partialeq.rs | 5 +- src/codegen/mod.rs | 89 ++++++------- src/codegen/struct_layout.rs | 2 +- src/ir/analysis/derive.rs | 75 ++++------- src/ir/analysis/has_destructor.rs | 16 ++- src/ir/analysis/has_vtable.rs | 14 +-- src/ir/analysis/mod.rs | 4 +- src/ir/analysis/sizedness.rs | 20 +-- src/ir/analysis/template_params.rs | 86 +++++++------ src/ir/annotations.rs | 22 +--- src/ir/comment.rs | 6 +- src/ir/comp.rs | 101 +++++++-------- src/ir/context.rs | 196 ++++++++++++++++++----------- src/ir/enum_ty.rs | 4 +- src/ir/function.rs | 22 ++-- src/ir/item.rs | 62 ++++----- src/ir/layout.rs | 2 +- src/ir/module.rs | 6 +- src/ir/objc.rs | 69 +++++----- src/ir/template.rs | 4 +- src/ir/traversal.rs | 14 +-- src/ir/ty.rs | 120 ++++++------------ src/ir/var.rs | 11 +- src/lib.rs | 64 +++++----- src/main.rs | 6 +- src/options.rs | 2 +- tests/stylo_sanity.rs | 8 +- 30 files changed, 523 insertions(+), 614 deletions(-) diff --git a/src/clang.rs b/src/clang.rs index db6467e398..d50d903090 100644 --- a/src/clang.rs +++ b/src/clang.rs @@ -4,9 +4,7 @@ #![allow(non_upper_case_globals, dead_code)] use crate::ir::context::BindgenContext; -use cexpr; use clang_sys::*; -use regex; use std::ffi::{CStr, CString}; use std::fmt; use std::hash::Hash; @@ -85,7 +83,7 @@ impl Cursor { let mut result = Vec::with_capacity(count); for i in 0..count { - let string_ptr = (*manglings).Strings.offset(i as isize); + let string_ptr = (*manglings).Strings.add(i); result.push(cxstring_to_string_leaky(*string_ptr)); } clang_disposeStringSet(manglings); @@ -223,12 +221,12 @@ impl Cursor { /// not tracking the type declaration but the location of the cursor, given /// clang doesn't expose a proper declaration for these types. pub fn is_template_like(&self) -> bool { - match self.kind() { + matches!( + self.kind(), CXCursor_ClassTemplate | - CXCursor_ClassTemplatePartialSpecialization | - CXCursor_TypeAliasTemplateDecl => true, - _ => false, - } + CXCursor_ClassTemplatePartialSpecialization | + CXCursor_TypeAliasTemplateDecl + ) } /// Is this Cursor pointing to a function-like macro definition? @@ -275,7 +273,7 @@ impl Cursor { return parent.is_in_non_fully_specialized_template(); } - return true; + true } /// Is this cursor pointing a valid referent? @@ -900,7 +898,7 @@ extern "C" fn visit_children( where Visitor: FnMut(Cursor) -> CXChildVisitResult, { - let func: &mut Visitor = unsafe { mem::transmute(data) }; + let func: &mut Visitor = unsafe { &mut *(data as *mut Visitor) }; let child = Cursor { x: cur }; (*func)(child) @@ -1027,7 +1025,7 @@ impl Type { let s = unsafe { cxstring_into_string(clang_getTypeSpelling(self.x)) }; // Clang 5.0 introduced changes in the spelling API so it returned the // full qualified name. Let's undo that here. - if s.split("::").all(|s| is_valid_identifier(s)) { + if s.split("::").all(is_valid_identifier) { if let Some(s) = s.split("::").last() { return s.to_owned(); } @@ -1055,7 +1053,7 @@ impl Type { ctx.target_pointer_size() as c_longlong } // Work-around https://bugs.llvm.org/show_bug.cgi?id=40813 - CXType_Auto if self.is_non_deductible_auto_type() => return -6, + CXType_Auto if self.is_non_deductible_auto_type() => -6, _ => unsafe { clang_Type_getSizeOf(self.x) }, } } @@ -1068,7 +1066,7 @@ impl Type { ctx.target_pointer_size() as c_longlong } // Work-around https://bugs.llvm.org/show_bug.cgi?id=40813 - CXType_Auto if self.is_non_deductible_auto_type() => return -6, + CXType_Auto if self.is_non_deductible_auto_type() => -6, _ => unsafe { clang_Type_getAlignOf(self.x) }, } } @@ -1286,12 +1284,12 @@ impl Type { // nasty... But can happen in . Unfortunately I couldn't // reduce it enough :( self.template_args().map_or(false, |args| args.len() > 0) && - match self.declaration().kind() { + !matches!( + self.declaration().kind(), CXCursor_ClassTemplatePartialSpecialization | - CXCursor_TypeAliasTemplateDecl | - CXCursor_TemplateTemplateParameter => false, - _ => true, - } + CXCursor_TypeAliasTemplateDecl | + CXCursor_TemplateTemplateParameter + ) } /// Is this type an associated template type? Eg `T::Associated` in @@ -1704,11 +1702,7 @@ impl UnsavedFile { Contents: contents.as_ptr(), Length: contents.as_bytes().len() as c_ulong, }; - UnsavedFile { - x: x, - name: name, - contents: contents, - } + UnsavedFile { x, name, contents } } } @@ -1819,7 +1813,7 @@ pub fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult { if let Some(refd) = c.referenced() { if refd != *c { - println!(""); + println!(); print_cursor( depth, String::from(prefix) + "referenced.", @@ -1830,7 +1824,7 @@ pub fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult { let canonical = c.canonical(); if canonical != *c { - println!(""); + println!(); print_cursor( depth, String::from(prefix) + "canonical.", @@ -1840,7 +1834,7 @@ pub fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult { if let Some(specialized) = c.specialized() { if specialized != *c { - println!(""); + println!(); print_cursor( depth, String::from(prefix) + "specialized.", @@ -1850,7 +1844,7 @@ pub fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult { } if let Some(parent) = c.fallible_semantic_parent() { - println!(""); + println!(); print_cursor( depth, String::from(prefix) + "semantic-parent.", @@ -1898,34 +1892,34 @@ pub fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult { let canonical = ty.canonical_type(); if canonical != *ty { - println!(""); + println!(); print_type(depth, String::from(prefix) + "canonical.", &canonical); } if let Some(pointee) = ty.pointee_type() { if pointee != *ty { - println!(""); + println!(); print_type(depth, String::from(prefix) + "pointee.", &pointee); } } if let Some(elem) = ty.elem_type() { if elem != *ty { - println!(""); + println!(); print_type(depth, String::from(prefix) + "elements.", &elem); } } if let Some(ret) = ty.ret_type() { if ret != *ty { - println!(""); + println!(); print_type(depth, String::from(prefix) + "return.", &ret); } } let named = ty.named(); if named != *ty && named.is_valid() { - println!(""); + println!(); print_type(depth, String::from(prefix) + "named.", &named); } } @@ -1933,13 +1927,13 @@ pub fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult { print_indent(depth, "("); print_cursor(depth, "", c); - println!(""); + println!(); let ty = c.cur_type(); print_type(depth, "type.", &ty); let declaration = ty.declaration(); if declaration != *c && declaration.kind() != CXCursor_NoDeclFound { - println!(""); + println!(); print_cursor(depth, "type.declaration.", &declaration); } @@ -1947,7 +1941,7 @@ pub fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult { let mut found_children = false; c.visit(|s| { if !found_children { - println!(""); + println!(); found_children = true; } ast_dump(&s, depth + 1) diff --git a/src/codegen/helpers.rs b/src/codegen/helpers.rs index 205995bc8e..2ce6894fb2 100644 --- a/src/codegen/helpers.rs +++ b/src/codegen/helpers.rs @@ -230,14 +230,14 @@ pub mod ast_ty { } pub fn byte_array_expr(bytes: &[u8]) -> TokenStream { - let mut bytes: Vec<_> = bytes.iter().cloned().collect(); + let mut bytes: Vec<_> = bytes.to_vec(); bytes.push(0); quote! { [ #(#bytes),* ] } } pub fn cstr_expr(mut string: String) -> TokenStream { string.push('\0'); - let b = proc_macro2::Literal::byte_string(&string.as_bytes()); + let b = proc_macro2::Literal::byte_string(string.as_bytes()); quote! { #b } @@ -271,7 +271,7 @@ pub mod ast_ty { } warn!("Unknown non-finite float number: {:?}", f); - return Err(()); + Err(()) } pub fn arguments_from_signature( diff --git a/src/codegen/impl_debug.rs b/src/codegen/impl_debug.rs index 661711e8a6..0e2cd33ad5 100644 --- a/src/codegen/impl_debug.rs +++ b/src/codegen/impl_debug.rs @@ -2,7 +2,6 @@ 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 proc_macro2; pub fn gen_debug_impl( ctx: &BindgenContext, @@ -23,8 +22,8 @@ pub fn gen_debug_impl( } CompKind::Struct => { let processed_fields = fields.iter().filter_map(|f| match f { - &Field::DataMember(ref fd) => fd.impl_debug(ctx, ()), - &Field::Bitfields(ref bu) => bu.impl_debug(ctx, ()), + Field::DataMember(ref fd) => fd.impl_debug(ctx, ()), + Field::Bitfields(ref bu) => bu.impl_debug(ctx, ()), }); for (i, (fstring, toks)) in processed_fields.enumerate() { @@ -186,24 +185,22 @@ impl<'a> ImplDebug<'a> for Item { { // The simple case debug_print(name, quote! { #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 { - 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! { - self.#name_ident - .iter() - .enumerate() - .map(|(i, v)| format!("{}{:?}", if i > 0 { ", " } else { "" }, v)) - .collect::() - }], - )) - } + // Let's implement our own print function + Some(( + format!("{}: [{{}}]", name), + vec![quote! { + self.#name_ident + .iter() + .enumerate() + .map(|(i, v)| format!("{}{:?}", if i > 0 { ", " } else { "" }, v)) + .collect::() + }], + )) } } TypeKind::Vector(_, len) => { diff --git a/src/codegen/impl_partialeq.rs b/src/codegen/impl_partialeq.rs index 5a1ba3fed4..960306ffc6 100644 --- a/src/codegen/impl_partialeq.rs +++ b/src/codegen/impl_partialeq.rs @@ -2,7 +2,6 @@ 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 proc_macro2; /// Generate a manual implementation of `PartialEq` trait for the /// specified compound type. @@ -51,7 +50,7 @@ pub fn gen_partialeq_impl( } Field::Bitfields(ref bu) => { for bitfield in bu.bitfields() { - if let Some(_) = bitfield.name() { + if bitfield.name().is_some() { let getter_name = bitfield.getter_name(); let name_ident = ctx.rust_ident_raw(getter_name); tokens.push(quote! { @@ -104,7 +103,7 @@ fn gen_field( TypeKind::Opaque => quote_equals(name_ident), TypeKind::TemplateInstantiation(ref inst) => { - if inst.is_opaque(ctx, &ty_item) { + if inst.is_opaque(ctx, ty_item) { quote! { &self. #name_ident [..] == &other. #name_ident [..] } diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 8858377fa6..69dde2c580 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -48,7 +48,6 @@ use proc_macro2::{self, Ident, Span}; use quote::TokenStreamExt; use crate::{Entry, HashMap, HashSet}; -use std; use std::borrow::Cow; use std::cell::Cell; use std::collections::VecDeque; @@ -58,7 +57,7 @@ use std::ops; use std::str::FromStr; // Name of type defined in constified enum module -pub static CONSTIFIED_ENUM_MODULE_REPR_NAME: &'static str = "Type"; +pub static CONSTIFIED_ENUM_MODULE_REPR_NAME: &str = "Type"; fn top_level_path( ctx: &BindgenContext, @@ -681,12 +680,11 @@ impl CodeGenerator for Var { } } VarType::Float(f) => { - match helpers::ast_ty::float_expr(ctx, f) { - Ok(expr) => result.push(quote! { + if let Ok(expr) = helpers::ast_ty::float_expr(ctx, f) { + result.push(quote! { #(#attrs)* pub const #canonical_ident : #ty = #expr ; - }), - Err(..) => return, + }); } } VarType::Char(c) => { @@ -698,7 +696,7 @@ impl CodeGenerator for Var { } } else { // If necessary, apply a `#[link_name]` attribute - let link_name = self.mangled_name().unwrap_or(self.name()); + let link_name = self.mangled_name().unwrap_or_else(|| self.name()); if !utils::names_will_be_identical_after_mangling( &canonical_name, link_name, @@ -756,7 +754,6 @@ impl CodeGenerator for Type { // converted to rust types in fields, arguments, and such. // NOTE(emilio): If you add to this list, make sure to also add // it to BindgenContext::compute_allowlisted_and_codegen_items. - return; } TypeKind::TemplateInstantiation(ref inst) => { inst.codegen(ctx, result, item) @@ -886,12 +883,9 @@ impl CodeGenerator for Type { // We prefer using `pub use` over `pub type` because of: // https://github.com/rust-lang/rust/issues/26264 - if inner_rust_type.to_string().chars().all(|c| match c { - // These are the only characters allowed in simple - // paths, eg `good::dogs::Bront`. - 'A'..='Z' | 'a'..='z' | '0'..='9' | ':' | '_' | ' ' => true, - _ => false, - }) && outer_params.is_empty() && + // These are the only characters allowed in simple + // paths, eg `good::dogs::Bront`. + if inner_rust_type.to_string().chars().all(|c| matches!(c, 'A'..='Z' | 'a'..='z' | '0'..='9' | ':' | '_' | ' ')) && outer_params.is_empty() && !is_opaque && alias_style == AliasVariation::TypeAlias && inner_item.expect_type().canonical_type(ctx).is_enum() @@ -1767,7 +1761,7 @@ impl CodeGenerator for CompInfo { let inner_item = ctx.resolve_item(base.ty); let mut inner = inner_item.to_rust_ty_or_opaque(ctx, &()); - inner.append_implicit_template_params(ctx, &inner_item); + inner.append_implicit_template_params(ctx, inner_item); let field_name = ctx.rust_ident(&base.field_name); struct_layout.saw_base(inner_item.expect_type()); @@ -2126,11 +2120,11 @@ impl CodeGenerator for CompInfo { }) .flat_map(|field| { let name = field.name().unwrap(); - field.offset().and_then(|offset| { + field.offset().map(|offset| { let field_offset = offset / 8; let field_name = ctx.rust_ident(name); - Some(quote! { + quote! { assert_eq!( unsafe { &(*(::#prefix::ptr::null::<#canonical_ident>())).#field_name as *const _ as usize @@ -2138,7 +2132,7 @@ impl CodeGenerator for CompInfo { #field_offset, concat!("Offset of field: ", stringify!(#canonical_ident), "::", stringify!(#field_name)) ); - }) + } }) }) .collect::>(); @@ -2348,7 +2342,7 @@ impl MethodCodegen for Method { return; } let function = function_item.expect_function(); - let times_seen = function.codegen(ctx, result, &function_item); + let times_seen = function.codegen(ctx, result, function_item); let times_seen = match times_seen { Some(seen) => seen, None => return, @@ -2414,7 +2408,7 @@ impl MethodCodegen for Method { } let mut exprs = - helpers::ast_ty::arguments_from_signature(&signature, ctx); + helpers::ast_ty::arguments_from_signature(signature, ctx); let mut stmts = vec![]; @@ -2471,8 +2465,7 @@ impl MethodCodegen for Method { #( #stmts );* }; - let mut attrs = vec![]; - attrs.push(attributes::inline()); + let mut attrs = vec![attributes::inline()]; if signature.must_use() && ctx.options().rust_features().must_use_function @@ -2513,19 +2506,13 @@ pub enum EnumVariation { impl EnumVariation { fn is_rust(&self) -> bool { - match *self { - EnumVariation::Rust { .. } => true, - _ => false, - } + matches!(*self, EnumVariation::Rust { .. }) } /// Both the `Const` and `ModuleConsts` variants will cause this to return /// true. fn is_const(&self) -> bool { - match *self { - EnumVariation::Consts | EnumVariation::ModuleConsts => true, - _ => false, - } + matches!(*self, EnumVariation::Consts | EnumVariation::ModuleConsts) } } @@ -2603,10 +2590,7 @@ impl<'a> EnumBuilder<'a> { /// Returns true if the builder is for a rustified enum. fn is_rust_enum(&self) -> bool { - match *self { - EnumBuilder::Rust { .. } => true, - _ => false, - } + matches!(*self, EnumBuilder::Rust { .. }) } /// Create a new enum given an item builder, a canonical name, a name for @@ -3027,7 +3011,7 @@ impl CodeGenerator for Enum { let mut derives: Vec<_> = derives.into(); for derive in item.annotations().derives().iter() { if !derives.contains(&derive.as_str()) { - derives.push(&derive); + derives.push(derive); } } attrs.push(attributes::derives(&derives)); @@ -3087,7 +3071,7 @@ impl CodeGenerator for Enum { let constant_mangling_prefix = if ctx.options().prepend_enum_name { if enum_ty.name().is_none() { - parent_canonical_name.as_ref().map(|n| &**n) + parent_canonical_name.as_deref() } else { Some(&*name) } @@ -3646,13 +3630,12 @@ impl TryToRustTy for Type { let void = c_void(ctx); return Ok(void.to_ptr(/* is_const = */ false)); } - let template_params = item - .used_template_params(ctx) - .into_iter() - .filter(|param| param.is_template_param(ctx, &())) - .collect::>(); - if item.is_opaque(ctx, &()) && !template_params.is_empty() { + if item.is_opaque(ctx, &()) && + item.used_template_params(ctx) + .into_iter() + .any(|param| param.is_template_param(ctx, &())) + { self.try_to_opaque(ctx, item) } else if let Some(ty) = self .name() @@ -3681,10 +3664,8 @@ impl TryToRustTy for Type { inner.into_resolver().through_type_refs().resolve(ctx); let inner_ty = inner.expect_type(); - let is_objc_pointer = match inner_ty.kind() { - TypeKind::ObjCInterface(..) => true, - _ => false, - }; + let is_objc_pointer = + matches!(inner_ty.kind(), TypeKind::ObjCInterface(..)); // Regardless if we can properly represent the inner type, we // should always generate a proper pointer here, so use @@ -3817,8 +3798,8 @@ impl TryToRustTy for FunctionSig { _: &(), ) -> error::Result { // TODO: we might want to consider ignoring the reference return value. - let ret = utils::fnsig_return_ty(ctx, &self); - let arguments = utils::fnsig_arguments(ctx, &self); + let ret = utils::fnsig_return_ty(ctx, self); + let arguments = utils::fnsig_arguments(ctx, self); let abi = self.abi(); match abi { @@ -4060,12 +4041,12 @@ impl CodeGenerator for ObjCInterface { impl_items.push(impl_item); } - let instance_method_names: Vec<_> = - self.methods().iter().map(|m| m.rust_name()).collect(); - for class_method in self.class_methods() { - let ambiquity = - instance_method_names.contains(&class_method.rust_name()); + let ambiquity = self + .methods() + .iter() + .map(|m| m.rust_name()) + .any(|x| x == class_method.rust_name()); let prefix = if ambiquity { "class_" } else { "" }; let impl_item = objc_method_codegen( ctx, @@ -4657,7 +4638,7 @@ pub mod utils { TypeKind::Array(t, _) => { let stream = if ctx.options().array_pointers_in_arguments { - arg_ty.to_rust_ty_or_opaque(ctx, &arg_item) + arg_ty.to_rust_ty_or_opaque(ctx, arg_item) } else { t.to_rust_ty_or_opaque(ctx, &()) }; diff --git a/src/codegen/struct_layout.rs b/src/codegen/struct_layout.rs index 1c6b977b99..b49fab41f3 100644 --- a/src/codegen/struct_layout.rs +++ b/src/codegen/struct_layout.rs @@ -428,6 +428,6 @@ impl<'a> StructLayoutTracker<'a> { // Else, just align the obvious way. self.latest_offset += self.padding_bytes(layout); - return false; + false } } diff --git a/src/ir/analysis/derive.rs b/src/ir/analysis/derive.rs index 44e6702a40..682f7852a2 100644 --- a/src/ir/analysis/derive.rs +++ b/src/ir/analysis/derive.rs @@ -159,7 +159,7 @@ impl<'ctx> CannotDerive<'ctx> { return can_derive; } - if self.derive_trait.not_by_name(self.ctx, &item) { + if self.derive_trait.not_by_name(self.ctx, item) { trace!( " cannot derive {} for explicitly excluded type", self.derive_trait @@ -223,13 +223,13 @@ impl<'ctx> CannotDerive<'ctx> { let inner_type = self.ctx.resolve_type(inner).canonical_type(self.ctx); if let TypeKind::Function(ref sig) = *inner_type.kind() { - return self.derive_trait.can_derive_fnptr(sig); + self.derive_trait.can_derive_fnptr(sig) } else { - return self.derive_trait.can_derive_pointer(); + self.derive_trait.can_derive_pointer() } } TypeKind::Function(ref sig) => { - return self.derive_trait.can_derive_fnptr(sig) + self.derive_trait.can_derive_fnptr(sig) } // Complex cases need more information @@ -255,7 +255,7 @@ impl<'ctx> CannotDerive<'ctx> { return CanDerive::No; } - if self.derive_trait.can_derive_large_array(&self.ctx) { + if self.derive_trait.can_derive_large_array(self.ctx) { trace!(" array can derive {}", self.derive_trait); return CanDerive::Yes; } @@ -270,7 +270,7 @@ impl<'ctx> CannotDerive<'ctx> { " array is small enough to derive {}", self.derive_trait ); - return CanDerive::Yes; + CanDerive::Yes } TypeKind::Vector(t, len) => { let inner_type = @@ -285,7 +285,7 @@ impl<'ctx> CannotDerive<'ctx> { return CanDerive::No; } assert_ne!(len, 0, "vectors cannot have zero length"); - return self.derive_trait.can_derive_vector(); + self.derive_trait.can_derive_vector() } TypeKind::Comp(ref info) => { @@ -377,7 +377,7 @@ impl<'ctx> CannotDerive<'ctx> { // Bitfield units are always represented as arrays of u8, but // they're not traced as arrays, so we need to check here // instead. - if !self.derive_trait.can_derive_large_array(&self.ctx) && + if !self.derive_trait.can_derive_large_array(self.ctx) && info.has_too_large_bitfield_unit() && !item.is_opaque(self.ctx, &()) { @@ -389,7 +389,7 @@ impl<'ctx> CannotDerive<'ctx> { } let pred = self.derive_trait.consider_edge_comp(); - return self.constrain_join(item, pred); + self.constrain_join(item, pred) } TypeKind::ResolvedTypeRef(..) | @@ -397,12 +397,12 @@ impl<'ctx> CannotDerive<'ctx> { TypeKind::Alias(..) | TypeKind::BlockPointer(..) => { let pred = self.derive_trait.consider_edge_typeref(); - return self.constrain_join(item, pred); + self.constrain_join(item, pred) } TypeKind::TemplateInstantiation(..) => { let pred = self.derive_trait.consider_edge_tmpl_inst(); - return self.constrain_join(item, pred); + self.constrain_join(item, pred) } TypeKind::Opaque => unreachable!( @@ -470,10 +470,7 @@ impl DeriveTrait { fn consider_edge_comp(&self) -> EdgePredicate { match self { DeriveTrait::PartialEqOrPartialOrd => consider_edge_default, - _ => |kind| match kind { - EdgeKind::BaseMember | EdgeKind::Field => true, - _ => false, - }, + _ => |kind| matches!(kind, EdgeKind::BaseMember | EdgeKind::Field), } } @@ -498,53 +495,35 @@ impl DeriveTrait { fn can_derive_large_array(&self, ctx: &BindgenContext) -> bool { if ctx.options().rust_features().larger_arrays { - match self { - DeriveTrait::Default => false, - _ => true, - } + !matches!(self, DeriveTrait::Default) } else { - match self { - DeriveTrait::Copy => true, - _ => false, - } + matches!(self, DeriveTrait::Copy) } } fn can_derive_union(&self) -> bool { - match self { - DeriveTrait::Copy => true, - _ => false, - } + matches!(self, DeriveTrait::Copy) } fn can_derive_compound_with_destructor(&self) -> bool { - match self { - DeriveTrait::Copy => false, - _ => true, - } + !matches!(self, DeriveTrait::Copy) } fn can_derive_compound_with_vtable(&self) -> bool { - match self { - DeriveTrait::Default => false, - _ => true, - } + !matches!(self, DeriveTrait::Default) } fn can_derive_compound_forward_decl(&self) -> bool { - match self { - DeriveTrait::Copy | DeriveTrait::Debug => true, - _ => false, - } + matches!(self, DeriveTrait::Copy | DeriveTrait::Debug) } fn can_derive_incomplete_array(&self) -> bool { - match self { + !matches!( + self, DeriveTrait::Copy | - DeriveTrait::Hash | - DeriveTrait::PartialEqOrPartialOrd => false, - _ => true, - } + DeriveTrait::Hash | + DeriveTrait::PartialEqOrPartialOrd + ) } fn can_derive_fnptr(&self, f: &FunctionSig) -> CanDerive { @@ -693,10 +672,10 @@ impl<'ctx> MonotoneFramework for CannotDerive<'ctx> { Some(ty) => { let mut can_derive = self.constrain_type(item, ty); if let CanDerive::Yes = can_derive { - if !self.derive_trait.can_derive_large_array(&self.ctx) && - ty.layout(self.ctx).map_or(false, |l| { - l.align > RUST_DERIVE_IN_ARRAY_LIMIT - }) + if !self.derive_trait.can_derive_large_array(self.ctx) && + ty.layout(self.ctx) + .map(|l| l.align > RUST_DERIVE_IN_ARRAY_LIMIT) + .unwrap_or_default() { // We have to be conservative: the struct *could* have enough // padding that we emit an array that is longer than diff --git a/src/ir/analysis/has_destructor.rs b/src/ir/analysis/has_destructor.rs index 5fa22e3f0b..fe95b516f8 100644 --- a/src/ir/analysis/has_destructor.rs +++ b/src/ir/analysis/has_destructor.rs @@ -41,16 +41,14 @@ pub struct HasDestructorAnalysis<'ctx> { impl<'ctx> HasDestructorAnalysis<'ctx> { fn consider_edge(kind: EdgeKind) -> bool { - match kind { - // These are the only edges that can affect whether a type has a - // destructor or not. + matches!( + kind, EdgeKind::TypeReference | - EdgeKind::BaseMember | - EdgeKind::Field | - EdgeKind::TemplateArgument | - EdgeKind::TemplateDeclaration => true, - _ => false, - } + EdgeKind::BaseMember | + EdgeKind::Field | + EdgeKind::TemplateArgument | + EdgeKind::TemplateDeclaration + ) } fn insert>(&mut self, id: Id) -> ConstrainResult { diff --git a/src/ir/analysis/has_vtable.rs b/src/ir/analysis/has_vtable.rs index 7f5f9117bf..8ac47a65da 100644 --- a/src/ir/analysis/has_vtable.rs +++ b/src/ir/analysis/has_vtable.rs @@ -79,14 +79,14 @@ pub struct HasVtableAnalysis<'ctx> { impl<'ctx> HasVtableAnalysis<'ctx> { fn consider_edge(kind: EdgeKind) -> bool { - match kind { - // These are the only edges that can affect whether a type has a - // vtable or not. + // These are the only edges that can affect whether a type has a + // vtable or not. + matches!( + kind, EdgeKind::TypeReference | - EdgeKind::BaseMember | - EdgeKind::TemplateDeclaration => true, - _ => false, - } + EdgeKind::BaseMember | + EdgeKind::TemplateDeclaration + ) } fn insert>( diff --git a/src/ir/analysis/mod.rs b/src/ir/analysis/mod.rs index ec4d20f948..eb9a1c0d64 100644 --- a/src/ir/analysis/mod.rs +++ b/src/ir/analysis/mod.rs @@ -184,7 +184,7 @@ where let mut dependencies = HashMap::default(); for &item in ctx.allowlisted_items() { - dependencies.entry(item).or_insert(vec![]); + dependencies.entry(item).or_insert_with(Vec::new); { // We reverse our natural IR graph edges to find dependencies @@ -197,7 +197,7 @@ where { dependencies .entry(sub_item) - .or_insert(vec![]) + .or_insert_with(Vec::new) .push(item); } }, diff --git a/src/ir/analysis/sizedness.rs b/src/ir/analysis/sizedness.rs index a3ef75319c..251c3747b2 100644 --- a/src/ir/analysis/sizedness.rs +++ b/src/ir/analysis/sizedness.rs @@ -112,17 +112,17 @@ pub struct SizednessAnalysis<'ctx> { impl<'ctx> SizednessAnalysis<'ctx> { fn consider_edge(kind: EdgeKind) -> bool { - match kind { - // These are the only edges that can affect whether a type is - // zero-sized or not. + // These are the only edges that can affect whether a type is + // zero-sized or not. + matches!( + kind, EdgeKind::TemplateArgument | - EdgeKind::TemplateParameterDefinition | - EdgeKind::TemplateDeclaration | - EdgeKind::TypeReference | - EdgeKind::BaseMember | - EdgeKind::Field => true, - _ => false, - } + EdgeKind::TemplateParameterDefinition | + EdgeKind::TemplateDeclaration | + EdgeKind::TypeReference | + EdgeKind::BaseMember | + EdgeKind::Field + ) } /// Insert an incremental result, and return whether this updated our diff --git a/src/ir/analysis/template_params.rs b/src/ir/analysis/template_params.rs index c2f18b1f8d..e88b774dee 100644 --- a/src/ir/analysis/template_params.rs +++ b/src/ir/analysis/template_params.rs @@ -239,7 +239,7 @@ impl<'ctx> UsedTemplateParameters<'ctx> { let args = instantiation .template_arguments() - .into_iter() + .iter() .map(|a| { a.into_resolver() .through_type_refs() @@ -399,8 +399,8 @@ impl<'ctx> MonotoneFramework for UsedTemplateParameters<'ctx> { .collect(); for item in allowlisted_and_blocklisted_items { - dependencies.entry(item).or_insert(vec![]); - used.entry(item).or_insert(Some(ItemSet::new())); + dependencies.entry(item).or_insert_with(Vec::new); + used.entry(item).or_insert_with(|| Some(ItemSet::new())); { // We reverse our natural IR graph edges to find dependencies @@ -408,10 +408,11 @@ impl<'ctx> MonotoneFramework for UsedTemplateParameters<'ctx> { item.trace( ctx, &mut |sub_item: ItemId, _| { - used.entry(sub_item).or_insert(Some(ItemSet::new())); + used.entry(sub_item) + .or_insert_with(|| Some(ItemSet::new())); dependencies .entry(sub_item) - .or_insert(vec![]) + .or_insert_with(Vec::new) .push(item); }, &(), @@ -421,39 +422,42 @@ impl<'ctx> MonotoneFramework for UsedTemplateParameters<'ctx> { // Additionally, whether a template instantiation's template // arguments are used depends on whether the template declaration's // generic template parameters are used. - ctx.resolve_item(item).as_type().map(|ty| match ty.kind() { - &TypeKind::TemplateInstantiation(ref inst) => { - let decl = ctx.resolve_type(inst.template_definition()); - let args = inst.template_arguments(); - - // Although template definitions should always have - // template parameters, there is a single exception: - // opaque templates. Hence the unwrap_or. - let params = decl.self_template_params(ctx); - - for (arg, param) in args.iter().zip(params.iter()) { - let arg = arg - .into_resolver() - .through_type_aliases() - .through_type_refs() - .resolve(ctx) - .id(); - - let param = param - .into_resolver() - .through_type_aliases() - .through_type_refs() - .resolve(ctx) - .id(); - - used.entry(arg).or_insert(Some(ItemSet::new())); - used.entry(param).or_insert(Some(ItemSet::new())); - - dependencies.entry(arg).or_insert(vec![]).push(param); - } + let item_kind = + ctx.resolve_item(item).as_type().map(|ty| ty.kind()); + if let Some(&TypeKind::TemplateInstantiation(ref inst)) = item_kind + { + let decl = ctx.resolve_type(inst.template_definition()); + let args = inst.template_arguments(); + + // Although template definitions should always have + // template parameters, there is a single exception: + // opaque templates. Hence the unwrap_or. + let params = decl.self_template_params(ctx); + + for (arg, param) in args.iter().zip(params.iter()) { + let arg = arg + .into_resolver() + .through_type_aliases() + .through_type_refs() + .resolve(ctx) + .id(); + + let param = param + .into_resolver() + .through_type_aliases() + .through_type_refs() + .resolve(ctx) + .id(); + + used.entry(arg).or_insert_with(|| Some(ItemSet::new())); + used.entry(param).or_insert_with(|| Some(ItemSet::new())); + + dependencies + .entry(arg) + .or_insert_with(Vec::new) + .push(param); } - _ => {} - }); + } } if cfg!(feature = "testing_only_extra_assertions") { @@ -482,10 +486,10 @@ impl<'ctx> MonotoneFramework for UsedTemplateParameters<'ctx> { } UsedTemplateParameters { - ctx: ctx, - used: used, - dependencies: dependencies, - allowlisted_items: allowlisted_items, + ctx, + used, + dependencies, + allowlisted_items, } } diff --git a/src/ir/annotations.rs b/src/ir/annotations.rs index 4b571eaa9f..9bcda508ee 100644 --- a/src/ir/annotations.rs +++ b/src/ir/annotations.rs @@ -25,7 +25,7 @@ pub enum FieldAccessorKind { /// documentation: /// /// http://www.stack.nl/~dimitri/doxygen/manual/docblocks.html -#[derive(Clone, PartialEq, Debug)] +#[derive(Default, Clone, PartialEq, Debug)] pub struct Annotations { /// Whether this item is marked as opaque. Only applies to types. opaque: bool, @@ -77,24 +77,6 @@ fn parse_accessor(s: &str) -> FieldAccessorKind { } } -impl Default for Annotations { - fn default() -> Self { - Annotations { - opaque: false, - hide: false, - use_instead_of: None, - disallow_copy: false, - disallow_debug: false, - disallow_default: false, - must_use_type: false, - private_fields: None, - accessor_kind: None, - constify_enum_variant: false, - derives: vec![], - } - } -} - impl Annotations { /// Construct new annotations for the given cursor and its bindgen comments /// (if any). @@ -143,7 +125,7 @@ impl Annotations { /// /// That is, code for `Foo` is used to generate `Bar`. pub fn use_instead_of(&self) -> Option<&[String]> { - self.use_instead_of.as_ref().map(|s| &**s) + self.use_instead_of.as_deref() } /// The list of derives that have been specified in this annotation. diff --git a/src/ir/comment.rs b/src/ir/comment.rs index 4ebe19a225..c96e3ebb9e 100644 --- a/src/ir/comment.rs +++ b/src/ir/comment.rs @@ -1,7 +1,5 @@ //! Utilities for manipulating C/C++ comments. -use std::iter; - /// The type of a comment. #[derive(Debug, PartialEq, Eq)] enum Kind { @@ -15,7 +13,7 @@ enum Kind { /// Preprocesses a C/C++ comment so that it is a valid Rust comment. pub fn preprocess(comment: &str, indent: usize) -> String { - match self::kind(&comment) { + match self::kind(comment) { Some(Kind::SingleLines) => preprocess_single_lines(comment, indent), Some(Kind::MultiLine) => preprocess_multi_line(comment, indent), None => comment.to_owned(), @@ -35,7 +33,7 @@ fn kind(comment: &str) -> Option { fn make_indent(indent: usize) -> String { const RUST_INDENTATION: usize = 4; - iter::repeat(' ').take(indent * RUST_INDENTATION).collect() + " ".repeat(indent * RUST_INDENTATION) } /// Preprocesses multiple single line comments. diff --git a/src/ir/comp.rs b/src/ir/comp.rs index 97983308db..a221e52074 100644 --- a/src/ir/comp.rs +++ b/src/ir/comp.rs @@ -111,11 +111,10 @@ impl Method { /// Is this a virtual method? pub fn is_virtual(&self) -> bool { - match self.kind { - MethodKind::Virtual { .. } | - MethodKind::VirtualDestructor { .. } => true, - _ => false, - } + matches!( + self.kind, + MethodKind::Virtual { .. } | MethodKind::VirtualDestructor { .. } + ) } /// Is this a static method? @@ -630,7 +629,7 @@ where bitfield_unit_count, unit_size_in_bits, unit_align, - mem::replace(&mut bitfields_in_unit, vec![]), + mem::take(&mut bitfields_in_unit), packed, ); @@ -639,15 +638,12 @@ where offset = 0; unit_align = 0; } - } else { - if offset != 0 && - (bitfield_width == 0 || - (offset & (bitfield_align * 8 - 1)) + - bitfield_width > - bitfield_size * 8) - { - offset = align_to(offset, bitfield_align * 8); - } + } else if offset != 0 && + (bitfield_width == 0 || + (offset & (bitfield_align * 8 - 1)) + bitfield_width > + bitfield_size * 8) + { + offset = align_to(offset, bitfield_align * 8); } } @@ -706,24 +702,24 @@ where /// after. #[derive(Debug)] enum CompFields { - BeforeComputingBitfieldUnits(Vec), - AfterComputingBitfieldUnits { + Before(Vec), + After { fields: Vec, has_bitfield_units: bool, }, - ErrorComputingBitfieldUnits, + Error, } impl Default for CompFields { fn default() -> CompFields { - CompFields::BeforeComputingBitfieldUnits(vec![]) + CompFields::Before(vec![]) } } impl CompFields { fn append_raw_field(&mut self, raw: RawField) { match *self { - CompFields::BeforeComputingBitfieldUnits(ref mut raws) => { + CompFields::Before(ref mut raws) => { raws.push(raw); } _ => { @@ -736,9 +732,7 @@ impl CompFields { fn compute_bitfield_units(&mut self, ctx: &BindgenContext, packed: bool) { let raws = match *self { - CompFields::BeforeComputingBitfieldUnits(ref mut raws) => { - mem::replace(raws, vec![]) - } + CompFields::Before(ref mut raws) => mem::take(raws), _ => { panic!("Already computed bitfield units"); } @@ -748,25 +742,23 @@ impl CompFields { match result { Ok((fields, has_bitfield_units)) => { - *self = CompFields::AfterComputingBitfieldUnits { + *self = CompFields::After { fields, has_bitfield_units, }; } Err(()) => { - *self = CompFields::ErrorComputingBitfieldUnits; + *self = CompFields::Error; } } } fn deanonymize_fields(&mut self, ctx: &BindgenContext, methods: &[Method]) { let fields = match *self { - CompFields::AfterComputingBitfieldUnits { - ref mut fields, .. - } => fields, + CompFields::After { ref mut fields, .. } => fields, // Nothing to do here. - CompFields::ErrorComputingBitfieldUnits => return, - CompFields::BeforeComputingBitfieldUnits(_) => { + CompFields::Error => return, + CompFields::Before(_) => { panic!("Not yet computed bitfield units."); } }; @@ -778,7 +770,7 @@ impl CompFields { ) -> bool { methods.iter().any(|method| { let method_name = ctx.resolve_func(method.signature()).name(); - method_name == name || ctx.rust_mangle(&method_name) == name + method_name == name || ctx.rust_mangle(method_name) == name }) } @@ -820,7 +812,7 @@ impl CompFields { for field in fields.iter_mut() { match *field { Field::DataMember(FieldData { ref mut name, .. }) => { - if let Some(_) = *name { + if name.is_some() { continue; } @@ -858,13 +850,13 @@ impl Trace for CompFields { T: Tracer, { match *self { - CompFields::ErrorComputingBitfieldUnits => {} - CompFields::BeforeComputingBitfieldUnits(ref fields) => { + CompFields::Error => {} + CompFields::Before(ref fields) => { for f in fields { tracer.visit_kind(f.ty().into(), EdgeKind::Field); } } - CompFields::AfterComputingBitfieldUnits { ref fields, .. } => { + CompFields::After { ref fields, .. } => { for f in fields { f.trace(context, tracer, &()); } @@ -900,7 +892,7 @@ pub struct FieldData { impl FieldMethods for FieldData { fn name(&self) -> Option<&str> { - self.name.as_ref().map(|n| &**n) + self.name.as_deref() } fn ty(&self) -> TypeId { @@ -908,7 +900,7 @@ impl FieldMethods for FieldData { } fn comment(&self) -> Option<&str> { - self.comment.as_ref().map(|c| &**c) + self.comment.as_deref() } fn bitfield_width(&self) -> Option { @@ -1131,11 +1123,9 @@ impl CompInfo { /// Get this type's set of fields. pub fn fields(&self) -> &[Field] { match self.fields { - CompFields::ErrorComputingBitfieldUnits => &[], - CompFields::AfterComputingBitfieldUnits { ref fields, .. } => { - fields - } - CompFields::BeforeComputingBitfieldUnits(..) => { + CompFields::Error => &[], + CompFields::After { ref fields, .. } => fields, + CompFields::Before(..) => { panic!("Should always have computed bitfield units first"); } } @@ -1143,13 +1133,9 @@ impl CompInfo { fn has_fields(&self) -> bool { match self.fields { - CompFields::ErrorComputingBitfieldUnits => false, - CompFields::AfterComputingBitfieldUnits { ref fields, .. } => { - !fields.is_empty() - } - CompFields::BeforeComputingBitfieldUnits(ref raw_fields) => { - !raw_fields.is_empty() - } + CompFields::Error => false, + CompFields::After { ref fields, .. } => !fields.is_empty(), + CompFields::Before(ref raw_fields) => !raw_fields.is_empty(), } } @@ -1159,15 +1145,15 @@ impl CompInfo { mut callback: impl FnMut(Layout), ) { match self.fields { - CompFields::ErrorComputingBitfieldUnits => return, - CompFields::AfterComputingBitfieldUnits { ref fields, .. } => { + CompFields::Error => {} + CompFields::After { ref fields, .. } => { for field in fields.iter() { if let Some(layout) = field.layout(ctx) { callback(layout); } } } - CompFields::BeforeComputingBitfieldUnits(ref raw_fields) => { + CompFields::Before(ref raw_fields) => { for field in raw_fields.iter() { let field_ty = ctx.resolve_type(field.0.ty); if let Some(layout) = field_ty.layout(ctx) { @@ -1180,12 +1166,11 @@ impl CompInfo { fn has_bitfields(&self) -> bool { match self.fields { - CompFields::ErrorComputingBitfieldUnits => false, - CompFields::AfterComputingBitfieldUnits { - has_bitfield_units, - .. + CompFields::Error => false, + CompFields::After { + has_bitfield_units, .. } => has_bitfield_units, - CompFields::BeforeComputingBitfieldUnits(_) => { + CompFields::Before(_) => { panic!("Should always have computed bitfield units first"); } } @@ -1776,7 +1761,7 @@ impl IsOpaque for CompInfo { // is a type parameter), then we can't compute bitfield units. We are // left with no choice but to make the whole struct opaque, or else we // might generate structs with incorrect sizes and alignments. - if let CompFields::ErrorComputingBitfieldUnits = self.fields { + if let CompFields::Error = self.fields { return true; } diff --git a/src/ir/context.rs b/src/ir/context.rs index 44df063a9b..5b23a43d40 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -299,7 +299,7 @@ where /// types. #[derive(Eq, PartialEq, Hash, Debug)] enum TypeKey { - USR(String), + Usr(String), Declaration(Cursor), } @@ -640,7 +640,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// Get the user-provided callbacks by reference, if any. pub fn parse_callbacks(&self) -> Option<&dyn ParseCallbacks> { - self.options().parse_callbacks.as_ref().map(|t| &**t) + self.options().parse_callbacks.as_deref() } /// Add another path to the set of included files. @@ -702,8 +702,10 @@ If you encounter an error missing from this list, please file an issue or a PR!" // Unnamed items can have an USR, but they can't be referenced from // other sites explicitly and the USR can match if the unnamed items are // nested, so don't bother tracking them. - if is_type && !is_template_instantiation && declaration.is_some() { - let mut declaration = declaration.unwrap(); + if !is_type || is_template_instantiation { + return; + } + if let Some(mut declaration) = declaration { if !declaration.is_valid() { if let Some(location) = location { if location.is_template_like() { @@ -732,7 +734,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" let key = if is_unnamed { TypeKey::Declaration(declaration) } else if let Some(usr) = declaration.usr() { - TypeKey::USR(usr) + TypeKey::Usr(usr) } else { warn!( "Valid declaration with no USR: {:?}, {:?}", @@ -830,30 +832,89 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// Mangles a name so it doesn't conflict with any keyword. pub fn rust_mangle<'a>(&self, name: &'a str) -> Cow<'a, str> { - if name.contains("@") || - name.contains("?") || - name.contains("$") || - match name { - "abstract" | "alignof" | "as" | "async" | "become" | - "box" | "break" | "const" | "continue" | "crate" | "do" | - "dyn" | "else" | "enum" | "extern" | "false" | "final" | - "fn" | "for" | "if" | "impl" | "in" | "let" | "loop" | - "macro" | "match" | "mod" | "move" | "mut" | "offsetof" | - "override" | "priv" | "proc" | "pub" | "pure" | "ref" | - "return" | "Self" | "self" | "sizeof" | "static" | - "struct" | "super" | "trait" | "true" | "type" | "typeof" | - "unsafe" | "unsized" | "use" | "virtual" | "where" | - "while" | "yield" | "str" | "bool" | "f32" | "f64" | - "usize" | "isize" | "u128" | "i128" | "u64" | "i64" | - "u32" | "i32" | "u16" | "i16" | "u8" | "i8" | "_" => true, - _ => false, - } + if name.contains('@') || + name.contains('?') || + name.contains('$') || + matches!( + name, + "abstract" | + "alignof" | + "as" | + "async" | + "become" | + "box" | + "break" | + "const" | + "continue" | + "crate" | + "do" | + "dyn" | + "else" | + "enum" | + "extern" | + "false" | + "final" | + "fn" | + "for" | + "if" | + "impl" | + "in" | + "let" | + "loop" | + "macro" | + "match" | + "mod" | + "move" | + "mut" | + "offsetof" | + "override" | + "priv" | + "proc" | + "pub" | + "pure" | + "ref" | + "return" | + "Self" | + "self" | + "sizeof" | + "static" | + "struct" | + "super" | + "trait" | + "true" | + "type" | + "typeof" | + "unsafe" | + "unsized" | + "use" | + "virtual" | + "where" | + "while" | + "yield" | + "str" | + "bool" | + "f32" | + "f64" | + "usize" | + "isize" | + "u128" | + "i128" | + "u64" | + "i64" | + "u32" | + "i32" | + "u16" | + "i16" | + "u8" | + "i8" | + "_" + ) { let mut s = name.to_owned(); s = s.replace("@", "_"); s = s.replace("?", "_"); s = s.replace("$", "_"); - s.push_str("_"); + s.push('_'); return Cow::Owned(s); } Cow::Borrowed(name) @@ -903,11 +964,10 @@ If you encounter an error missing from this list, please file an issue or a PR!" None => continue, }; - match *ty.kind() { - TypeKind::UnresolvedTypeRef(ref ty, loc, parent_id) => { - typerefs.push((id, ty.clone(), loc, parent_id)); - } - _ => {} + if let TypeKind::UnresolvedTypeRef(ref ty, loc, parent_id) = + *ty.kind() + { + typerefs.push((id, *ty, loc, parent_id)); }; } typerefs @@ -978,7 +1038,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" assert!(self.collected_typerefs()); let need_bitfield_allocation = - mem::replace(&mut self.need_bitfield_allocation, vec![]); + mem::take(&mut self.need_bitfield_allocation); for id in need_bitfield_allocation { self.with_loaned_item(id, |ctx, item| { let ty = item.kind_mut().as_type_mut().unwrap(); @@ -1121,7 +1181,8 @@ If you encounter an error missing from this list, please file an issue or a PR!" .ancestors(immut_self) .find(|id| immut_self.resolve_item(*id).is_module()) }; - let new_module = new_module.unwrap_or(self.root_module.into()); + let new_module = + new_module.unwrap_or_else(|| self.root_module.into()); if new_module == old_module { // Already in the correct module. @@ -1329,12 +1390,12 @@ If you encounter an error missing from this list, please file an issue or a PR!" // any sense of template parameter usage, and you're on your own. let mut used_params = HashMap::default(); for &id in self.allowlisted_items() { - used_params.entry(id).or_insert( + used_params.entry(id).or_insert_with(|| { id.self_template_params(self) .into_iter() .map(|p| p.into()) - .collect(), - ); + .collect() + }); } self.used_template_parameters = Some(used_params); } @@ -1815,7 +1876,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" .or_else(|| { decl.cursor() .usr() - .and_then(|usr| self.types.get(&TypeKey::USR(usr))) + .and_then(|usr| self.types.get(&TypeKey::Usr(usr))) }) .cloned() } @@ -1848,32 +1909,32 @@ If you encounter an error missing from this list, please file an issue or a PR!" // of it, or // * we have already parsed and resolved this type, and // there's nothing left to do. - if decl.cursor().is_template_like() && - *ty != decl.cursor().cur_type() && - location.is_some() - { - let location = location.unwrap(); - - // For specialized type aliases, there's no way to get the - // template parameters as of this writing (for a struct - // specialization we wouldn't be in this branch anyway). - // - // Explicitly return `None` if there aren't any - // unspecialized parameters (contains any `TypeRef`) so we - // resolve the canonical type if there is one and it's - // exposed. - // - // This is _tricky_, I know :( - if decl.cursor().kind() == CXCursor_TypeAliasTemplateDecl && - !location.contains_cursor(CXCursor_TypeRef) && - ty.canonical_type().is_valid_and_exposed() + if let Some(location) = location { + if decl.cursor().is_template_like() && + *ty != decl.cursor().cur_type() { - return None; - } + // For specialized type aliases, there's no way to get the + // template parameters as of this writing (for a struct + // specialization we wouldn't be in this branch anyway). + // + // Explicitly return `None` if there aren't any + // unspecialized parameters (contains any `TypeRef`) so we + // resolve the canonical type if there is one and it's + // exposed. + // + // This is _tricky_, I know :( + if decl.cursor().kind() == + CXCursor_TypeAliasTemplateDecl && + !location.contains_cursor(CXCursor_TypeRef) && + ty.canonical_type().is_valid_and_exposed() + { + return None; + } - return self - .instantiate_template(with_id, id, ty, location) - .or_else(|| Some(id)); + return self + .instantiate_template(with_id, id, ty, location) + .or(Some(id)); + } } return Some(self.build_ty_wrapper(with_id, id, parent_id, ty)); @@ -1933,7 +1994,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" with_id, None, None, - parent_id.unwrap_or(self.current_module.into()), + parent_id.unwrap_or_else(|| self.current_module.into()), ItemKind::Type(ty), ); self.add_builtin_item(item); @@ -2074,10 +2135,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" id: Id, ) -> bool { let id = id.into(); - match self.replacements.get(path) { - Some(replaced_by) if *replaced_by != id => true, - _ => false, - } + matches!(self.replacements.get(path), Some(replaced_by) if *replaced_by != id) } /// Is the type with the given `name` marked as opaque? @@ -2112,11 +2170,9 @@ If you encounter an error missing from this list, please file an issue or a PR!" module_name = Some(spelling) } - let tokens = cursor.tokens(); - let mut iter = tokens.iter(); let mut kind = ModuleKind::Normal; let mut found_namespace_keyword = false; - while let Some(token) = iter.next() { + for token in cursor.tokens().iter() { match token.spelling() { b"inline" => { assert!(!found_namespace_keyword); @@ -2399,7 +2455,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" let codegen_items = if self.options().allowlist_recursively { AllowlistedItemsTraversal::new( self, - roots.clone(), + roots, traversal::codegen_edges, ) .collect::() @@ -2700,7 +2756,7 @@ impl ItemResolver { pub fn new>(id: Id) -> ItemResolver { let id = id.into(); ItemResolver { - id: id, + id, through_type_refs: false, through_type_aliases: false, } @@ -2767,7 +2823,7 @@ impl PartialType { /// Construct a new `PartialType`. pub fn new(decl: Cursor, id: ItemId) -> PartialType { // assert!(decl == decl.canonical()); - PartialType { decl: decl, id: id } + PartialType { decl, id } } /// The cursor pointing to this partial type's declaration location. diff --git a/src/ir/enum_ty.rs b/src/ir/enum_ty.rs index 15d4136802..97455c9123 100644 --- a/src/ir/enum_ty.rs +++ b/src/ir/enum_ty.rs @@ -86,7 +86,7 @@ impl Enum { } else { Some(type_name) }; - let type_name = type_name.as_ref().map(String::as_str); + let type_name = type_name.as_deref(); let definition = declaration.definition().unwrap_or(declaration); definition.visit(|cursor| { @@ -286,7 +286,7 @@ impl EnumVariant { /// Get this variant's documentation. pub fn comment(&self) -> Option<&str> { - self.comment.as_ref().map(|s| &**s) + self.comment.as_deref() } /// Returns whether this variant should be enforced to be a constant by code diff --git a/src/ir/function.rs b/src/ir/function.rs index 661ee59333..a3a2bbfbfe 100644 --- a/src/ir/function.rs +++ b/src/ir/function.rs @@ -123,7 +123,7 @@ impl Function { /// Get this function's name. pub fn mangled_name(&self) -> Option<&str> { - self.mangled_name.as_ref().map(|n| &**n) + self.mangled_name.as_deref() } /// Get this function's signature type. @@ -187,10 +187,7 @@ pub enum Abi { impl Abi { /// Returns whether this Abi is known or not. fn is_unknown(&self) -> bool { - match *self { - Abi::Unknown(..) => true, - _ => false, - } + matches!(*self, Abi::Unknown(..)) } } @@ -340,7 +337,7 @@ fn args_from_ty_and_cursor( }); let cursor = arg_cur.unwrap_or(*cursor); - let ty = arg_ty.unwrap_or(cursor.cur_type()); + let ty = arg_ty.unwrap_or_else(|| cursor.cur_type()); (name, Item::from_ty_or_ref(ty, cursor, None, ctx)) }) .collect() @@ -360,7 +357,7 @@ impl FunctionSig { argument_types, is_variadic, must_use, - abi: abi, + abi, } } @@ -411,7 +408,7 @@ impl FunctionSig { CXCursor_CXXMethod | CXCursor_ObjCInstanceMethodDecl | CXCursor_ObjCClassMethodDecl => { - args_from_ty_and_cursor(&ty, &cursor, ctx) + args_from_ty_and_cursor(ty, &cursor, ctx) } _ => { // For non-CXCursor_FunctionDecl, visiting the cursor's children @@ -434,7 +431,7 @@ impl FunctionSig { // right AST for functions tagged as stdcall and such... // // https://bugs.llvm.org/show_bug.cgi?id=45919 - args_from_ty_and_cursor(&ty, &cursor, ctx) + args_from_ty_and_cursor(ty, &cursor, ctx) } else { args } @@ -522,7 +519,7 @@ impl FunctionSig { warn!("Unknown calling convention: {:?}", call_conv); } - Ok(Self::new(ret.into(), args, ty.is_variadic(), must_use, abi)) + Ok(Self::new(ret, args, ty.is_variadic(), must_use, abi)) } /// Get this function signature's return type. @@ -567,10 +564,7 @@ impl FunctionSig { return false; } - match self.abi { - Abi::C | Abi::Unknown(..) => true, - _ => false, - } + matches!(self.abi, Abi::C | Abi::Unknown(..)) } } diff --git a/src/ir/item.rs b/src/ir/item.rs index a38c8e5fb8..730271efea 100644 --- a/src/ir/item.rs +++ b/src/ir/item.rs @@ -436,15 +436,15 @@ impl Item { ) -> Self { debug_assert!(id != parent_id || kind.is_module()); Item { - id: id, + id, local_id: LazyCell::new(), next_child_local_id: Cell::new(1), canonical_name: LazyCell::new(), path_for_allowlisting: LazyCell::new(), - parent_id: parent_id, - comment: comment, + parent_id, + comment, annotations: annotations.unwrap_or_default(), - kind: kind, + kind, } } @@ -612,10 +612,7 @@ impl Item { /// Is this item a module? pub fn is_module(&self) -> bool { - match self.kind { - ItemKind::Module(..) => true, - _ => false, - } + matches!(self.kind, ItemKind::Module(..)) } /// Get this item's annotations. @@ -641,7 +638,7 @@ impl Item { match self.kind { ItemKind::Type(..) => { ctx.options().blocklisted_types.matches(&name) || - ctx.is_replaced_type(&path, self.id) + ctx.is_replaced_type(path, self.id) } ItemKind::Function(..) => { ctx.options().blocklisted_functions.matches(&name) @@ -658,10 +655,7 @@ impl Item { /// Is this item a var type? pub fn is_var(&self) -> bool { - match *self.kind() { - ItemKind::Var(..) => true, - _ => false, - } + matches!(*self.kind(), ItemKind::Var(..)) } /// Take out item NameOptions @@ -722,7 +716,7 @@ impl Item { .through_type_refs() .resolve(ctx) .push_disambiguated_name(ctx, to, level + 1); - to.push_str("_"); + to.push('_'); } to.push_str(&format!("close{}", level)); } @@ -835,7 +829,7 @@ impl Item { if ctx.options().enable_cxx_namespaces { return path.last().unwrap().clone(); } - return path.join("_").to_owned(); + return path.join("_"); } let base_name = target.base_name(ctx); @@ -873,7 +867,7 @@ impl Item { // If target is anonymous we need find its first named ancestor. if target.is_anon() { - while let Some(id) = ids_iter.next() { + for id in ids_iter.by_ref() { ids.push(id); if !ctx.resolve_item(id).is_anon() { @@ -1104,7 +1098,7 @@ impl IsOpaque for Item { ); self.annotations.opaque() || self.as_type().map_or(false, |ty| ty.is_opaque(ctx, self)) || - ctx.opaque_by_name(&self.path_for_allowlisting(ctx)) + ctx.opaque_by_name(self.path_for_allowlisting(ctx)) } } @@ -1114,20 +1108,16 @@ where { fn has_vtable(&self, ctx: &BindgenContext) -> bool { let id: ItemId = (*self).into(); - id.as_type_id(ctx) - .map_or(false, |id| match ctx.lookup_has_vtable(id) { - HasVtableResult::No => false, - _ => true, - }) + id.as_type_id(ctx).map_or(false, |id| { + !matches!(ctx.lookup_has_vtable(id), HasVtableResult::No) + }) } fn has_vtable_ptr(&self, ctx: &BindgenContext) -> bool { let id: ItemId = (*self).into(); - id.as_type_id(ctx) - .map_or(false, |id| match ctx.lookup_has_vtable(id) { - HasVtableResult::SelfHasVtable => true, - _ => false, - }) + id.as_type_id(ctx).map_or(false, |id| { + matches!(ctx.lookup_has_vtable(id), HasVtableResult::SelfHasVtable) + }) } } @@ -1392,7 +1382,7 @@ impl ClangItemParser for Item { } ctx.known_semantic_parent(definition) .or(parent_id) - .unwrap_or(ctx.current_module().into()) + .unwrap_or_else(|| ctx.current_module().into()) } None => relevant_parent_id, }; @@ -1524,7 +1514,7 @@ impl ClangItemParser for Item { potential_id, None, None, - parent_id.unwrap_or(current_module.into()), + parent_id.unwrap_or_else(|| current_module.into()), ItemKind::Type(Type::new(None, None, kind, is_const)), ), None, @@ -1603,7 +1593,7 @@ impl ClangItemParser for Item { Annotations::new(&decl).or_else(|| Annotations::new(&location)); if let Some(ref annotations) = annotations { - if let Some(ref replaced) = annotations.use_instead_of() { + if let Some(replaced) = annotations.use_instead_of() { ctx.replace(replaced, id); } } @@ -1851,11 +1841,7 @@ impl ClangItemParser for Item { clang_sys::CXChildVisit_Continue }); - if let Some(def) = definition { - def - } else { - return None; - } + definition? }; assert!(is_template_with_spelling(&definition, &ty_spelling)); @@ -1939,7 +1925,7 @@ impl ItemCanonicalPath for Item { path.push(CONSTIFIED_ENUM_MODULE_REPR_NAME.into()); } - return path; + path } fn canonical_path(&self, ctx: &BindgenContext) -> Vec { @@ -1972,8 +1958,8 @@ impl<'a> NameOptions<'a> { /// Construct a new `NameOptions` pub fn new(item: &'a Item, ctx: &'a BindgenContext) -> Self { NameOptions { - item: item, - ctx: ctx, + item, + ctx, within_namespaces: false, user_mangled: UserMangled::Yes, } diff --git a/src/ir/layout.rs b/src/ir/layout.rs index 28a6604d95..6cf91131bb 100644 --- a/src/ir/layout.rs +++ b/src/ir/layout.rs @@ -64,7 +64,7 @@ impl Layout { next_align *= 2; } Layout { - size: size, + size, align: next_align / 2, packed: false, } diff --git a/src/ir/module.rs b/src/ir/module.rs index 13b7c19fff..d5aca94a6e 100644 --- a/src/ir/module.rs +++ b/src/ir/module.rs @@ -32,15 +32,15 @@ impl Module { /// Construct a new `Module`. pub fn new(name: Option, kind: ModuleKind) -> Self { Module { - name: name, - kind: kind, + name, + kind, children: ItemSet::new(), } } /// Get this module's name. pub fn name(&self) -> Option<&str> { - self.name.as_ref().map(|n| &**n) + self.name.as_deref() } /// Get a mutable reference to this module's children. diff --git a/src/ir/objc.rs b/src/ir/objc.rs index 91855c6776..0845ad0fde 100644 --- a/src/ir/objc.rs +++ b/src/ir/objc.rs @@ -89,12 +89,10 @@ impl ObjCInterface { pub fn rust_name(&self) -> String { if let Some(ref cat) = self.category { format!("{}_{}", self.name(), cat) + } else if self.is_protocol { + format!("P{}", self.name()) } else { - if self.is_protocol { - format!("P{}", self.name()) - } else { - format!("I{}", self.name().to_owned()) - } + format!("I{}", self.name().to_owned()) } } @@ -149,28 +147,34 @@ impl ObjCInterface { // Gather protocols this interface conforms to let needle = format!("P{}", c.spelling()); let items_map = ctx.items(); - debug!("Interface {} conforms to {}, find the item", interface.name, needle); + debug!( + "Interface {} conforms to {}, find the item", + interface.name, needle + ); - for (id, item) in items_map - { + for (id, item) in items_map { if let Some(ty) = item.as_type() { - match *ty.kind() { - TypeKind::ObjCInterface(ref protocol) => { - if protocol.is_protocol - { - debug!("Checking protocol {}, ty.name {:?}", protocol.name, ty.name()); - if Some(needle.as_ref()) == ty.name() { - debug!("Found conforming protocol {:?}", item); - interface.conforms_to.push(id); - break; - } + if let TypeKind::ObjCInterface(ref protocol) = + *ty.kind() + { + if protocol.is_protocol { + debug!( + "Checking protocol {}, ty.name {:?}", + protocol.name, + ty.name() + ); + if Some(needle.as_ref()) == ty.name() { + debug!( + "Found conforming protocol {:?}", + item + ); + interface.conforms_to.push(id); + break; } } - _ => {} } } } - } CXCursor_ObjCInstanceMethodDecl | CXCursor_ObjCClassMethodDecl => { @@ -178,8 +182,10 @@ impl ObjCInterface { let signature = FunctionSig::from_ty(&c.cur_type(), &c, ctx) .expect("Invalid function sig"); - let is_class_method = c.kind() == CXCursor_ObjCClassMethodDecl; - let method = ObjCMethod::new(&name, signature, is_class_method); + let is_class_method = + c.kind() == CXCursor_ObjCClassMethodDecl; + let method = + ObjCMethod::new(&name, signature, is_class_method); interface.add_method(method); } CXCursor_TemplateTypeParameter => { @@ -189,7 +195,7 @@ impl ObjCInterface { CXCursor_ObjCSuperClassRef => { let item = Item::from_ty_or_ref(c.cur_type(), c, None, ctx); interface.parent_class = Some(item.into()); - }, + } _ => {} } CXChildVisit_Continue @@ -218,7 +224,7 @@ impl ObjCMethod { ObjCMethod { name: name.to_owned(), - rust_name: rust_name.to_owned(), + rust_name, signature, is_class_method, } @@ -261,7 +267,7 @@ impl ObjCMethod { .collect(); // No arguments - if args.len() == 0 && split_name.len() == 1 { + if args.is_empty() && split_name.len() == 1 { let name = &split_name[0]; return quote! { #name @@ -269,13 +275,12 @@ impl ObjCMethod { } // Check right amount of arguments - if args.len() != split_name.len() - 1 { - panic!( - "Incorrect method name or arguments for objc method, {:?} vs {:?}", - args, - split_name, - ); - } + assert!( + args.len() == split_name.len() - 1, + "Incorrect method name or arguments for objc method, {:?} vs {:?}", + args, + split_name + ); // Get arguments without type signatures to pass to `msg_send!` let mut args_without_types = vec![]; diff --git a/src/ir/template.rs b/src/ir/template.rs index b519fff132..8b06748e2c 100644 --- a/src/ir/template.rs +++ b/src/ir/template.rs @@ -134,10 +134,10 @@ pub trait TemplateParameters: Sized { where Self: ItemAncestors, { - let ancestors: Vec<_> = self.ancestors(ctx).collect(); + let mut ancestors: Vec<_> = self.ancestors(ctx).collect(); + ancestors.reverse(); ancestors .into_iter() - .rev() .flat_map(|id| id.self_template_params(ctx).into_iter()) .collect() } diff --git a/src/ir/traversal.rs b/src/ir/traversal.rs index 430dd02796..088e744a4b 100644 --- a/src/ir/traversal.rs +++ b/src/ir/traversal.rs @@ -24,9 +24,9 @@ impl Edge { } } -impl Into for Edge { - fn into(self) -> ItemId { - self.to +impl From for ItemId { + fn from(val: Edge) -> Self { + val.to } } @@ -424,10 +424,10 @@ where } ItemTraversal { - ctx: ctx, - seen: seen, - queue: queue, - predicate: predicate, + ctx, + seen, + queue, + predicate, currently_traversing: None, } } diff --git a/src/ir/ty.rs b/src/ir/ty.rs index e049ed6520..9cfbd7a922 100644 --- a/src/ir/ty.rs +++ b/src/ir/ty.rs @@ -87,23 +87,17 @@ impl Type { /// Get this type's name. pub fn name(&self) -> Option<&str> { - self.name.as_ref().map(|name| &**name) + self.name.as_deref() } /// Whether this is a block pointer type. pub fn is_block_pointer(&self) -> bool { - match self.kind { - TypeKind::BlockPointer(..) => true, - _ => false, - } + matches!(self.kind, TypeKind::BlockPointer(..)) } /// Is this a compound type? pub fn is_comp(&self) -> bool { - match self.kind { - TypeKind::Comp(..) => true, - _ => false, - } + matches!(self.kind, TypeKind::Comp(..)) } /// Is this a union? @@ -116,58 +110,43 @@ impl Type { /// Is this type of kind `TypeKind::TypeParam`? pub fn is_type_param(&self) -> bool { - match self.kind { - TypeKind::TypeParam => true, - _ => false, - } + matches!(self.kind, TypeKind::TypeParam) } /// Is this a template instantiation type? pub fn is_template_instantiation(&self) -> bool { - match self.kind { - TypeKind::TemplateInstantiation(..) => true, - _ => false, - } + matches!(self.kind, TypeKind::TemplateInstantiation(..)) } /// Is this a template alias type? pub fn is_template_alias(&self) -> bool { - match self.kind { - TypeKind::TemplateAlias(..) => true, - _ => false, - } + matches!(self.kind, TypeKind::TemplateAlias(..)) } /// Is this a function type? pub fn is_function(&self) -> bool { - match self.kind { - TypeKind::Function(..) => true, - _ => false, - } + matches!(self.kind, TypeKind::Function(..)) } /// Is this an enum type? pub fn is_enum(&self) -> bool { - match self.kind { - TypeKind::Enum(..) => true, - _ => false, - } + matches!(self.kind, TypeKind::Enum(..)) } /// Is this either a builtin or named type? pub fn is_builtin_or_type_param(&self) -> bool { - match self.kind { + matches!( + self.kind, TypeKind::Void | - TypeKind::NullPtr | - TypeKind::Function(..) | - TypeKind::Array(..) | - TypeKind::Reference(..) | - TypeKind::Pointer(..) | - TypeKind::Int(..) | - TypeKind::Float(..) | - TypeKind::TypeParam => true, - _ => false, - } + TypeKind::NullPtr | + TypeKind::Function(..) | + TypeKind::Array(..) | + TypeKind::Reference(..) | + TypeKind::Pointer(..) | + TypeKind::Int(..) | + TypeKind::Float(..) | + TypeKind::TypeParam + ) } /// Creates a new named type, with name `name`. @@ -178,26 +157,17 @@ impl Type { /// Is this a floating point type? pub fn is_float(&self) -> bool { - match self.kind { - TypeKind::Float(..) => true, - _ => false, - } + matches!(self.kind, TypeKind::Float(..)) } /// Is this a boolean type? pub fn is_bool(&self) -> bool { - match self.kind { - TypeKind::Int(IntKind::Bool) => true, - _ => false, - } + matches!(self.kind, TypeKind::Int(IntKind::Bool)) } /// Is this an integer type? pub fn is_integer(&self) -> bool { - match self.kind { - TypeKind::Int(..) => true, - _ => false, - } + matches!(self.kind, TypeKind::Int(..)) } /// Cast this type to an integer kind, or `None` if it is not an integer @@ -216,19 +186,15 @@ impl Type { /// Is this a reference to another type? pub fn is_type_ref(&self) -> bool { - match self.kind { - TypeKind::ResolvedTypeRef(_) | - TypeKind::UnresolvedTypeRef(_, _, _) => true, - _ => false, - } + matches!( + self.kind, + TypeKind::ResolvedTypeRef(_) | TypeKind::UnresolvedTypeRef(_, _, _) + ) } /// Is this an unresolved reference? pub fn is_unresolved_ref(&self) -> bool { - match self.kind { - TypeKind::UnresolvedTypeRef(_, _, _) => true, - _ => false, - } + matches!(self.kind, TypeKind::UnresolvedTypeRef(_, _, _)) } /// Is this a incomplete array type? @@ -278,14 +244,14 @@ impl Type { match self.kind { TypeKind::TypeParam => { let name = self.name().expect("Unnamed named type?"); - !clang::is_valid_identifier(&name) + !clang::is_valid_identifier(name) } _ => false, } } /// Takes `name`, and returns a suitable identifier representation for it. - fn sanitize_name<'a>(name: &'a str) -> Cow<'a, str> { + fn sanitize_name(name: &str) -> Cow { if clang::is_valid_identifier(name) { return Cow::Borrowed(name); } @@ -300,12 +266,8 @@ impl Type { ctx: &BindgenContext, ) -> Option> { let name_info = match *self.kind() { - TypeKind::Pointer(inner) => { - Some((inner.into(), Cow::Borrowed("ptr"))) - } - TypeKind::Reference(inner) => { - Some((inner.into(), Cow::Borrowed("ref"))) - } + TypeKind::Pointer(inner) => Some((inner, Cow::Borrowed("ptr"))), + TypeKind::Reference(inner) => Some((inner, Cow::Borrowed("ref"))), TypeKind::Array(inner, length) => { Some((inner, format!("array{}", length).into())) } @@ -375,16 +337,16 @@ impl Type { /// There are some types we don't want to stop at when finding an opaque /// item, so we can arrive to the proper item that needs to be generated. pub fn should_be_traced_unconditionally(&self) -> bool { - match self.kind { + matches!( + self.kind, TypeKind::Comp(..) | - TypeKind::Function(..) | - TypeKind::Pointer(..) | - TypeKind::Array(..) | - TypeKind::Reference(..) | - TypeKind::TemplateInstantiation(..) | - TypeKind::ResolvedTypeRef(..) => true, - _ => false, - } + TypeKind::Function(..) | + TypeKind::Pointer(..) | + TypeKind::Array(..) | + TypeKind::Reference(..) | + TypeKind::TemplateInstantiation(..) | + TypeKind::ResolvedTypeRef(..) + ) } } @@ -791,7 +753,7 @@ impl Type { (ty.template_args().is_some() && ty_kind != CXType_Typedef) { // This is a template instantiation. - match TemplateInstantiation::from_ty(&ty, ctx) { + match TemplateInstantiation::from_ty(ty, ctx) { Some(inst) => TypeKind::TemplateInstantiation(inst), None => TypeKind::Opaque, } diff --git a/src/ir/var.rs b/src/ir/var.rs index 49c4f304fb..cd17937013 100644 --- a/src/ir/var.rs +++ b/src/ir/var.rs @@ -88,7 +88,7 @@ impl Var { /// Get this variable's mangled name. pub fn mangled_name(&self) -> Option<&str> { - self.mangled_name.as_ref().map(|n| &**n) + self.mangled_name.as_deref() } } @@ -282,7 +282,7 @@ impl ClangSubItemParser for Var { .parse_callbacks() .and_then(|c| c.int_macro(&name, value)) .unwrap_or_else(|| { - default_macro_constant_type(&ctx, value) + default_macro_constant_type(ctx, value) }); (TypeKind::Int(kind), VarType::Int(value)) @@ -398,11 +398,8 @@ fn parse_macro( let parser = expr::IdentifierParser::new(ctx.parsed_macros()); - match parser.macro_definition(&cexpr_tokens) { - Ok((_, (id, val))) => { - return Some((id.into(), val)); - } - _ => {} + if let Ok((_, (id, val))) = parser.macro_definition(&cexpr_tokens) { + return Some((id.into(), val)); } // Try without the last token, to workaround a libclang bug in versions diff --git a/src/lib.rs b/src/lib.rs index 67cfeb3dae..1129efe767 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -89,7 +89,7 @@ type HashSet = ::rustc_hash::FxHashSet; pub(crate) use std::collections::hash_map::Entry; /// Default prefix for the anon fields. -pub const DEFAULT_ANON_FIELDS_PREFIX: &'static str = "__bindgen_anon_"; +pub const DEFAULT_ANON_FIELDS_PREFIX: &str = "__bindgen_anon_"; fn file_is_cpp(name_file: &str) -> bool { name_file.ends_with(".hpp") || @@ -2148,7 +2148,7 @@ pub struct Bindings { module: proc_macro2::TokenStream, } -pub(crate) const HOST_TARGET: &'static str = +pub(crate) const HOST_TARGET: &str = include_str!(concat!(env!("OUT_DIR"), "/host-target.txt")); // Some architecture triplets are different between rust and libclang, see #1211 @@ -2156,7 +2156,8 @@ pub(crate) const HOST_TARGET: &'static str = fn rust_to_clang_target(rust_target: &str) -> String { if rust_target.starts_with("aarch64-apple-") { let mut clang_target = "arm64-apple-".to_owned(); - clang_target.push_str(&rust_target["aarch64-apple-".len()..]); + clang_target + .push_str(rust_target.strip_prefix("aarch64-apple-").unwrap()); return clang_target; } rust_target.to_owned() @@ -2278,10 +2279,7 @@ impl Bindings { // Whether we are working with C or C++ inputs. let is_cpp = args_are_cpp(&options.clang_args) || - options - .input_header - .as_ref() - .map_or(false, |i| file_is_cpp(&i)); + options.input_header.as_deref().map_or(false, file_is_cpp); let search_paths = if is_cpp { clang.cpp_search_paths @@ -2369,15 +2367,6 @@ impl Bindings { }) } - /// Convert these bindings into source text (with raw lines prepended). - pub fn to_string(&self) -> String { - let mut bytes = vec![]; - self.write(Box::new(&mut bytes) as Box) - .expect("writing to a vec cannot fail"); - String::from_utf8(bytes) - .expect("we should only write bindings that are valid utf-8") - } - /// Write these bindings as source text to a file. pub fn write_to_file>(&self, path: P) -> io::Result<()> { let file = OpenOptions::new() @@ -2427,7 +2416,7 @@ impl Bindings { } /// Gets the rustfmt path to rustfmt the generated bindings. - fn rustfmt_path<'a>(&'a self) -> io::Result> { + fn rustfmt_path(&self) -> io::Result> { debug_assert!(self.options.rustfmt_bindings); if let Some(ref p) = self.options.rustfmt_path { return Ok(Cow::Borrowed(p)); @@ -2518,6 +2507,18 @@ impl Bindings { } } +impl std::fmt::Display for Bindings { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let mut bytes = vec![]; + self.write(Box::new(&mut bytes) as Box) + .expect("writing to a vec cannot fail"); + f.write_str( + std::str::from_utf8(&bytes) + .expect("we should only write bindings that are valid utf-8"), + ) + } +} + /// Determines whether the given cursor is in any of the files matched by the /// options. fn filter_builtins(ctx: &BindgenContext, cursor: &clang::Cursor) -> bool { @@ -2566,7 +2567,7 @@ fn parse(context: &mut BindgenContext) -> Result<(), ()> { if context.options().emit_ast { fn dump_if_not_builtin(cur: &clang::Cursor) -> CXChildVisitResult { if !cur.is_builtin() { - clang::ast_dump(&cur, 0) + clang::ast_dump(cur, 0) } else { CXChildVisit_Continue } @@ -2603,26 +2604,19 @@ pub fn clang_version() -> ClangVersion { let raw_v: String = clang::extract_clang_version(); let split_v: Option> = raw_v .split_whitespace() - .filter(|t| t.chars().next().map_or(false, |v| v.is_ascii_digit())) - .next() + .find(|t| t.chars().next().map_or(false, |v| v.is_ascii_digit())) .map(|v| v.split('.').collect()); - match split_v { - Some(v) => { - if v.len() >= 2 { - let maybe_major = v[0].parse::(); - let maybe_minor = v[1].parse::(); - match (maybe_major, maybe_minor) { - (Ok(major), Ok(minor)) => { - return ClangVersion { - parsed: Some((major, minor)), - full: raw_v.clone(), - } - } - _ => {} - } + if let Some(v) = split_v { + if v.len() >= 2 { + let maybe_major = v[0].parse::(); + let maybe_minor = v[1].parse::(); + if let (Ok(major), Ok(minor)) = (maybe_major, maybe_minor) { + return ClangVersion { + parsed: Some((major, minor)), + full: raw_v.clone(), + }; } } - None => {} }; ClangVersion { parsed: None, diff --git a/src/main.rs b/src/main.rs index 1768ed8d5b..f3398db890 100644 --- a/src/main.rs +++ b/src/main.rs @@ -37,7 +37,7 @@ fn clang_version_check() { ); if expected_version.is_some() { - assert_eq!(version.parsed, version.parsed); + // assert_eq!(version.parsed, version.parsed); } } @@ -45,9 +45,7 @@ pub fn main() { #[cfg(feature = "logging")] env_logger::init(); - let bind_args: Vec<_> = env::args().collect(); - - match builder_from_flags(bind_args.into_iter()) { + match builder_from_flags(env::args()) { Ok((builder, output, verbose)) => { clang_version_check(); let builder_result = panic::catch_unwind(|| { diff --git a/src/options.rs b/src/options.rs index 0524871aef..9aac5dae83 100644 --- a/src/options.rs +++ b/src/options.rs @@ -717,7 +717,7 @@ where if let Some(what_to_generate) = matches.value_of("generate") { let mut config = CodegenConfig::empty(); - for what in what_to_generate.split(",") { + for what in what_to_generate.split(',') { match what { "functions" => config.insert(CodegenConfig::FUNCTIONS), "types" => config.insert(CodegenConfig::TYPES), diff --git a/tests/stylo_sanity.rs b/tests/stylo_sanity.rs index 2ea77628a0..39777cd154 100755 --- a/tests/stylo_sanity.rs +++ b/tests/stylo_sanity.rs @@ -545,14 +545,14 @@ fn sanity_check_can_generate_stylo_bindings() { let now = Instant::now(); - println!(""); - println!(""); + println!(); + println!(); println!( "Generated Stylo bindings in: {:?}", now.duration_since(then) ); - println!(""); - println!(""); + println!(); + println!(); // panic!("Uncomment this line to get timing logs"); } From a311cacbdf8fd5b41b444f639ecf21219d479aca Mon Sep 17 00:00:00 2001 From: MikuroXina Date: Mon, 25 Oct 2021 22:21:12 +0900 Subject: [PATCH 214/942] Add clippy in rustfmt job --- .github/workflows/bindgen.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 11379aa7d6..bc525ed6f3 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -23,7 +23,7 @@ jobs: # features. toolchain: nightly override: true - components: rustfmt + components: rustfmt, clippy - name: Run rustfmt uses: actions-rs/cargo@v1 @@ -31,6 +31,11 @@ jobs: command: fmt args: -- --check + - name: Run clippy + uses: actions-rs/cargo@v1 + with: + command: clippy + msrv: runs-on: ubuntu-latest steps: From 74115f4f01b5a97830075244bcb7351e5c468ccd Mon Sep 17 00:00:00 2001 From: MikuroXina Date: Mon, 25 Oct 2021 22:46:02 +0900 Subject: [PATCH 215/942] Extract as is_reached_limit --- src/ir/analysis/derive.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ir/analysis/derive.rs b/src/ir/analysis/derive.rs index 682f7852a2..f63458e5e7 100644 --- a/src/ir/analysis/derive.rs +++ b/src/ir/analysis/derive.rs @@ -9,6 +9,7 @@ use crate::ir::context::{BindgenContext, ItemId}; use crate::ir::derive::CanDerive; use crate::ir::function::FunctionSig; use crate::ir::item::{IsOpaque, Item}; +use crate::ir::layout::Layout; use crate::ir::template::TemplateParameters; use crate::ir::traversal::{EdgeKind, Trace}; use crate::ir::ty::RUST_DERIVE_IN_ARRAY_LIMIT; @@ -672,10 +673,10 @@ impl<'ctx> MonotoneFramework for CannotDerive<'ctx> { Some(ty) => { let mut can_derive = self.constrain_type(item, ty); if let CanDerive::Yes = can_derive { + let is_reached_limit = + |l: Layout| l.align > RUST_DERIVE_IN_ARRAY_LIMIT; if !self.derive_trait.can_derive_large_array(self.ctx) && - ty.layout(self.ctx) - .map(|l| l.align > RUST_DERIVE_IN_ARRAY_LIMIT) - .unwrap_or_default() + ty.layout(self.ctx).map_or(false, is_reached_limit) { // We have to be conservative: the struct *could* have enough // padding that we emit an array that is longer than From f21f6f322f92b3c3739ff97ab2bcb98030addebf Mon Sep 17 00:00:00 2001 From: MikuroXina Date: Mon, 25 Oct 2021 22:50:27 +0900 Subject: [PATCH 216/942] Bring back comment --- src/ir/analysis/has_destructor.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ir/analysis/has_destructor.rs b/src/ir/analysis/has_destructor.rs index fe95b516f8..74fd73d14e 100644 --- a/src/ir/analysis/has_destructor.rs +++ b/src/ir/analysis/has_destructor.rs @@ -41,6 +41,8 @@ pub struct HasDestructorAnalysis<'ctx> { impl<'ctx> HasDestructorAnalysis<'ctx> { fn consider_edge(kind: EdgeKind) -> bool { + // These are the only edges that can affect whether a type has a + // destructor or not. matches!( kind, EdgeKind::TypeReference | From 70446e549c3c5096789161dd07f5b21e8ffe51dc Mon Sep 17 00:00:00 2001 From: MikuroXina Date: Mon, 25 Oct 2021 22:55:40 +0900 Subject: [PATCH 217/942] Shorten patterns --- src/ir/context.rs | 84 ++++++++--------------------------------------- 1 file changed, 13 insertions(+), 71 deletions(-) diff --git a/src/ir/context.rs b/src/ir/context.rs index 5b23a43d40..874fb5df2b 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -831,83 +831,25 @@ If you encounter an error missing from this list, please file an issue or a PR!" // TODO: Move all this syntax crap to other part of the code. /// Mangles a name so it doesn't conflict with any keyword. + #[rustfmt::skip] pub fn rust_mangle<'a>(&self, name: &'a str) -> Cow<'a, str> { if name.contains('@') || name.contains('?') || name.contains('$') || matches!( name, - "abstract" | - "alignof" | - "as" | - "async" | - "become" | - "box" | - "break" | - "const" | - "continue" | - "crate" | - "do" | - "dyn" | - "else" | - "enum" | - "extern" | - "false" | - "final" | - "fn" | - "for" | - "if" | - "impl" | - "in" | - "let" | - "loop" | - "macro" | - "match" | - "mod" | - "move" | - "mut" | - "offsetof" | - "override" | - "priv" | - "proc" | - "pub" | - "pure" | - "ref" | - "return" | - "Self" | - "self" | - "sizeof" | - "static" | - "struct" | - "super" | - "trait" | - "true" | - "type" | - "typeof" | - "unsafe" | - "unsized" | - "use" | - "virtual" | - "where" | - "while" | - "yield" | - "str" | - "bool" | - "f32" | - "f64" | - "usize" | - "isize" | - "u128" | - "i128" | - "u64" | - "i64" | - "u32" | - "i32" | - "u16" | - "i16" | - "u8" | - "i8" | - "_" + "abstract" | "alignof" | "as" | "async" | "become" | + "box" | "break" | "const" | "continue" | "crate" | "do" | + "dyn" | "else" | "enum" | "extern" | "false" | "final" | + "fn" | "for" | "if" | "impl" | "in" | "let" | "loop" | + "macro" | "match" | "mod" | "move" | "mut" | "offsetof" | + "override" | "priv" | "proc" | "pub" | "pure" | "ref" | + "return" | "Self" | "self" | "sizeof" | "static" | + "struct" | "super" | "trait" | "true" | "type" | "typeof" | + "unsafe" | "unsized" | "use" | "virtual" | "where" | + "while" | "yield" | "str" | "bool" | "f32" | "f64" | + "usize" | "isize" | "u128" | "i128" | "u64" | "i64" | + "u32" | "i32" | "u16" | "i16" | "u8" | "i8" | "_" ) { let mut s = name.to_owned(); From be3314302068147d1c21c8b18fcb4c8fbe4b6bef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikuro=E3=81=95=E3=81=84=E3=81=AA?= Date: Tue, 26 Oct 2021 10:04:15 +0900 Subject: [PATCH 218/942] Remove trailing semis --- src/log_stubs.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/log_stubs.rs b/src/log_stubs.rs index 4af496ce14..58b855a04d 100644 --- a/src/log_stubs.rs +++ b/src/log_stubs.rs @@ -4,29 +4,29 @@ macro_rules! log { (target: $target:expr, $lvl:expr, $($arg:tt)+) => { let _ = $target; let _ = log!($lvl, $($arg)+); - }; - ($lvl:expr, $($arg:tt)+) => {{ + } + ($lvl:expr, $($arg:tt)+) => { let _ = $lvl; let _ = format_args!($($arg)+); - }}; + } } macro_rules! error { - (target: $target:expr, $($arg:tt)*) => { log!($target, $($arg)*); }; - ($($arg:tt)*) => { log!("", $($arg)*); }; + (target: $target:expr, $($arg:tt)*) => { log!($target, $($arg)*); } + ($($arg:tt)*) => { log!("", $($arg)*); } } macro_rules! warn { - (target: $target:expr, $($arg:tt)*) => { log!($target, $($arg)*); }; - ($($arg:tt)*) => { log!("", $($arg)*); }; + (target: $target:expr, $($arg:tt)*) => { log!($target, $($arg)*); } + ($($arg:tt)*) => { log!("", $($arg)*); } } macro_rules! info { - (target: $target:expr, $($arg:tt)*) => { log!($target, $($arg)*); }; - ($($arg:tt)*) => { log!("", $($arg)*); }; + (target: $target:expr, $($arg:tt)*) => { log!($target, $($arg)*); } + ($($arg:tt)*) => { log!("", $($arg)*); } } macro_rules! debug { - (target: $target:expr, $($arg:tt)*) => { log!($target, $($arg)*); }; - ($($arg:tt)*) => { log!("", $($arg)*); }; + (target: $target:expr, $($arg:tt)*) => { log!($target, $($arg)*); } + ($($arg:tt)*) => { log!("", $($arg)*); } } macro_rules! trace { - (target: $target:expr, $($arg:tt)*) => { log!($target, $($arg)*); }; - ($($arg:tt)*) => { log!("", $($arg)*); }; + (target: $target:expr, $($arg:tt)*) => { log!($target, $($arg)*); } + ($($arg:tt)*) => { log!("", $($arg)*); } } From e73e19091331bce9099ec7e3a199309b6a3db35a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikuro=E3=81=95=E3=81=84=E3=81=AA?= Date: Tue, 26 Oct 2021 12:58:54 +0900 Subject: [PATCH 219/942] Fix log args --- src/log_stubs.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/log_stubs.rs b/src/log_stubs.rs index 58b855a04d..477e0f8053 100644 --- a/src/log_stubs.rs +++ b/src/log_stubs.rs @@ -11,22 +11,22 @@ macro_rules! log { } } macro_rules! error { - (target: $target:expr, $($arg:tt)*) => { log!($target, $($arg)*); } + (target: $target:expr, $($arg:tt)*) => { log!(target: $target, "", $($arg)*); } ($($arg:tt)*) => { log!("", $($arg)*); } } macro_rules! warn { - (target: $target:expr, $($arg:tt)*) => { log!($target, $($arg)*); } + (target: $target:expr, $($arg:tt)*) => { log!(target: $target, "", $($arg)*); } ($($arg:tt)*) => { log!("", $($arg)*); } } macro_rules! info { - (target: $target:expr, $($arg:tt)*) => { log!($target, $($arg)*); } + (target: $target:expr, $($arg:tt)*) => { log!(target: $target, "", $($arg)*); } ($($arg:tt)*) => { log!("", $($arg)*); } } macro_rules! debug { - (target: $target:expr, $($arg:tt)*) => { log!($target, $($arg)*); } + (target: $target:expr, $($arg:tt)*) => { log!(target: $target, "", $($arg)*); } ($($arg:tt)*) => { log!("", $($arg)*); } } macro_rules! trace { - (target: $target:expr, $($arg:tt)*) => { log!($target, $($arg)*); } + (target: $target:expr, $($arg:tt)*) => { log!(target: $target, "", $($arg)*); } ($($arg:tt)*) => { log!("", $($arg)*); } } From b4cd6e4d3e851eb51801f8e53a9021a902b64dfb Mon Sep 17 00:00:00 2001 From: MikuroXina Date: Tue, 26 Oct 2021 18:19:37 +0900 Subject: [PATCH 220/942] Fix repetetion --- src/log_stubs.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/log_stubs.rs b/src/log_stubs.rs index 477e0f8053..429a458a94 100644 --- a/src/log_stubs.rs +++ b/src/log_stubs.rs @@ -11,22 +11,22 @@ macro_rules! log { } } macro_rules! error { - (target: $target:expr, $($arg:tt)*) => { log!(target: $target, "", $($arg)*); } - ($($arg:tt)*) => { log!("", $($arg)*); } + (target: $target:expr, $($arg:tt)+) => { log!(target: $target, "", $($arg)+); } + ($($arg:tt)+) => { log!("", $($arg)+); } } macro_rules! warn { (target: $target:expr, $($arg:tt)*) => { log!(target: $target, "", $($arg)*); } ($($arg:tt)*) => { log!("", $($arg)*); } } macro_rules! info { - (target: $target:expr, $($arg:tt)*) => { log!(target: $target, "", $($arg)*); } - ($($arg:tt)*) => { log!("", $($arg)*); } + (target: $target:expr, $($arg:tt)+) => { log!(target: $target, "", $($arg)+); } + ($($arg:tt)+) => { log!("", $($arg)+); } } macro_rules! debug { - (target: $target:expr, $($arg:tt)*) => { log!(target: $target, "", $($arg)*); } - ($($arg:tt)*) => { log!("", $($arg)*); } + (target: $target:expr, $($arg:tt)+) => { log!(target: $target, "", $($arg)+); } + ($($arg:tt)+) => { log!("", $($arg)+); } } macro_rules! trace { - (target: $target:expr, $($arg:tt)*) => { log!(target: $target, "", $($arg)*); } - ($($arg:tt)*) => { log!("", $($arg)*); } + (target: $target:expr, $($arg:tt)+) => { log!(target: $target, "", $($arg)+); } + ($($arg:tt)+) => { log!("", $($arg)+); } } From f91e1a635e5104fc4a113fbb72ad3fe4ca0c1d21 Mon Sep 17 00:00:00 2001 From: MikuroXina Date: Tue, 26 Oct 2021 18:34:51 +0900 Subject: [PATCH 221/942] Fix separator and treating expression --- src/log_stubs.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/log_stubs.rs b/src/log_stubs.rs index 429a458a94..8315983128 100644 --- a/src/log_stubs.rs +++ b/src/log_stubs.rs @@ -1,32 +1,32 @@ #![allow(unused)] macro_rules! log { - (target: $target:expr, $lvl:expr, $($arg:tt)+) => { + (target: $target:expr, $lvl:expr, $($arg:tt)+) => {{ let _ = $target; let _ = log!($lvl, $($arg)+); - } - ($lvl:expr, $($arg:tt)+) => { + }}; + ($lvl:expr, $($arg:tt)+) => {{ let _ = $lvl; let _ = format_args!($($arg)+); - } + }}; } macro_rules! error { - (target: $target:expr, $($arg:tt)+) => { log!(target: $target, "", $($arg)+); } - ($($arg:tt)+) => { log!("", $($arg)+); } + (target: $target:expr, $($arg:tt)+) => { log!(target: $target, "", $($arg)+) }; + ($($arg:tt)+) => { log!("", $($arg)+) }; } macro_rules! warn { - (target: $target:expr, $($arg:tt)*) => { log!(target: $target, "", $($arg)*); } - ($($arg:tt)*) => { log!("", $($arg)*); } + (target: $target:expr, $($arg:tt)*) => { log!(target: $target, "", $($arg)*) }; + ($($arg:tt)*) => { log!("", $($arg)*) }; } macro_rules! info { - (target: $target:expr, $($arg:tt)+) => { log!(target: $target, "", $($arg)+); } - ($($arg:tt)+) => { log!("", $($arg)+); } + (target: $target:expr, $($arg:tt)+) => { log!(target: $target, "", $($arg)+) }; + ($($arg:tt)+) => { log!("", $($arg)+) }; } macro_rules! debug { - (target: $target:expr, $($arg:tt)+) => { log!(target: $target, "", $($arg)+); } - ($($arg:tt)+) => { log!("", $($arg)+); } + (target: $target:expr, $($arg:tt)+) => { log!(target: $target, "", $($arg)+) }; + ($($arg:tt)+) => { log!("", $($arg)+) }; } macro_rules! trace { - (target: $target:expr, $($arg:tt)+) => { log!(target: $target, "", $($arg)+); } - ($($arg:tt)+) => { log!("", $($arg)+); } + (target: $target:expr, $($arg:tt)+) => { log!(target: $target, "", $($arg)+) }; + ($($arg:tt)+) => { log!("", $($arg)+) }; } From 9738fb9d0bafbc986412d695ec6933eda94dbe4f Mon Sep 17 00:00:00 2001 From: MikuroXina Date: Wed, 27 Oct 2021 17:33:03 +0900 Subject: [PATCH 222/942] Avoid transmute --- src/clang.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/clang.rs b/src/clang.rs index d50d903090..36ccd266f8 100644 --- a/src/clang.rs +++ b/src/clang.rs @@ -400,12 +400,9 @@ impl Cursor { where Visitor: FnMut(Cursor) -> CXChildVisitResult, { + let data = &mut visitor as *mut Visitor; unsafe { - clang_visitChildren( - self.x, - visit_children::, - mem::transmute(&mut visitor), - ); + clang_visitChildren(self.x, visit_children::, data.cast()); } } From 57853405463dd985dd49a2f14fb78bbf3595b1df Mon Sep 17 00:00:00 2001 From: Theodore Dubois Date: Wed, 13 Oct 2021 15:00:47 -0700 Subject: [PATCH 223/942] Don't generate 2^64 byte padding fields on unions The --explicit-padding flag would make bindgen try to add tail padding to rust unions, by adding up the size of all the union fields and subtracting from the size of the union as given by clang. The total size of a union's fields is always larger than the union, so the subtraction underflowed and bindgen produced padding fields larger than addressable RAM. --- src/codegen/struct_layout.rs | 5 ++ tests/expectations/tests/explicit-padding.rs | 65 ++++++++++++++++++++ tests/headers/explicit-padding.h | 6 ++ 3 files changed, 76 insertions(+) diff --git a/src/codegen/struct_layout.rs b/src/codegen/struct_layout.rs index b49fab41f3..657be0b489 100644 --- a/src/codegen/struct_layout.rs +++ b/src/codegen/struct_layout.rs @@ -279,6 +279,11 @@ impl<'a> StructLayoutTracker<'a> { return None; } + // Padding doesn't make sense for rust unions. + if self.is_rust_union { + return None; + } + if self.latest_offset == comp_layout.size { // This struct does not contain tail padding. return None; diff --git a/tests/expectations/tests/explicit-padding.rs b/tests/expectations/tests/explicit-padding.rs index e395e5d245..3c429756c2 100644 --- a/tests/expectations/tests/explicit-padding.rs +++ b/tests/expectations/tests/explicit-padding.rs @@ -63,3 +63,68 @@ fn bindgen_test_layout_pad_me() { ) ); } +#[repr(C)] +#[derive(Copy, Clone)] +pub union dont_pad_me { + pub first: u8, + pub second: u32, + pub third: u16, +} +#[test] +fn bindgen_test_layout_dont_pad_me() { + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(dont_pad_me)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(dont_pad_me)) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).first as *const _ as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(dont_pad_me), + "::", + stringify!(first) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).second as *const _ as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(dont_pad_me), + "::", + stringify!(second) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).third as *const _ as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(dont_pad_me), + "::", + stringify!(third) + ) + ); +} +impl Default for dont_pad_me { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} diff --git a/tests/headers/explicit-padding.h b/tests/headers/explicit-padding.h index d228961df2..4abaafba9b 100644 --- a/tests/headers/explicit-padding.h +++ b/tests/headers/explicit-padding.h @@ -9,3 +9,9 @@ struct pad_me { uint32_t second; uint16_t third; }; + +union dont_pad_me { + uint8_t first; + uint32_t second; + uint16_t third; +}; From da3f3a3ab13fb335b525d74a38e6a8634a117fe5 Mon Sep 17 00:00:00 2001 From: Adrian Taylor Date: Sun, 3 Oct 2021 09:35:10 -0700 Subject: [PATCH 224/942] Avoid case of a self-referential type alias. This previously produced a type alias which referred to itself, which was clearly wrong and resulted in downstream code recursing infinitely. The problem case (per bug #2102) is: template class B{}; template class C { public: using U = B; }; class A : C
{ U u; }; As far as I can tell, we parse clang's definition of B; that leads us to parse A; to find it has a field U which turns out to be of type B. And so we hit the line in item.rs which says: debug!("Avoiding recursion parsing type: {:?}", ty); and bail out, returning the original item ID: hence, a self- referential typedef is created. The 'fix' in this PR creates an opaque type in this case instead, to avoid later infinite loops. It would be preferable to avoid this situation in the first place, but presumably that would require us to split the parsing phase into two: 1) types 2) fields within those types. Fixes #2102. --- src/ir/ty.rs | 11 +++- .../tests/constified-enum-module-overflow.rs | 54 +++++++++++++++++++ .../constified-enum-module-overflow.hpp | 8 +++ 3 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 tests/expectations/tests/constified-enum-module-overflow.rs create mode 100644 tests/headers/constified-enum-module-overflow.hpp diff --git a/src/ir/ty.rs b/src/ir/ty.rs index 9cfbd7a922..d573408c3b 100644 --- a/src/ir/ty.rs +++ b/src/ir/ty.rs @@ -1082,7 +1082,16 @@ impl Type { let inner = cursor.typedef_type().expect("Not valid Type?"); let inner = Item::from_ty_or_ref(inner, location, None, ctx); - TypeKind::Alias(inner) + if inner == potential_id { + warn!( + "Generating oqaque type instead of self-referential \ + typedef"); + // This can happen if we bail out of recursive situations + // within the clang parsing. + TypeKind::Opaque + } else { + TypeKind::Alias(inner) + } } CXType_Enum => { let enum_ = Enum::from_ty(ty, ctx).expect("Not an enum?"); diff --git a/tests/expectations/tests/constified-enum-module-overflow.rs b/tests/expectations/tests/constified-enum-module-overflow.rs new file mode 100644 index 0000000000..4a799ef8e5 --- /dev/null +++ b/tests/expectations/tests/constified-enum-module-overflow.rs @@ -0,0 +1,54 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct B { + pub _address: u8, +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct C { + pub _address: u8, +} +pub type C_U = B; +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct A { + pub u: u8, +} +#[test] +fn bindgen_test_layout_A() { + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(A)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(A)) + ); + assert_eq!( + unsafe { &(*(::std::ptr::null::())).u as *const _ as usize }, + 0usize, + concat!("Offset of field: ", stringify!(A), "::", stringify!(u)) + ); +} +#[test] +fn __bindgen_test_layout_C_open0_A_close0_instantiation() { + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of template specialization: ", stringify!(C)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of template specialization: ", stringify!(C)) + ); +} diff --git a/tests/headers/constified-enum-module-overflow.hpp b/tests/headers/constified-enum-module-overflow.hpp new file mode 100644 index 0000000000..d48f2be1b2 --- /dev/null +++ b/tests/headers/constified-enum-module-overflow.hpp @@ -0,0 +1,8 @@ +template class B{}; +template class C { +public: + using U = B; +}; +class A : C { + U u; +}; From 2aed6b0216805e27228ed39988ffe1a1ffd7e940 Mon Sep 17 00:00:00 2001 From: Fionera Date: Sat, 30 Oct 2021 01:37:26 +0200 Subject: [PATCH 225/942] context: Escape the try keyword properly --- src/ir/context.rs | 2 +- tests/expectations/tests/keywords.rs | 4 ++++ tests/headers/keywords.h | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ir/context.rs b/src/ir/context.rs index 874fb5df2b..ffb49d7400 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -845,7 +845,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" "macro" | "match" | "mod" | "move" | "mut" | "offsetof" | "override" | "priv" | "proc" | "pub" | "pure" | "ref" | "return" | "Self" | "self" | "sizeof" | "static" | - "struct" | "super" | "trait" | "true" | "type" | "typeof" | + "struct" | "super" | "trait" | "true" | "try" | "type" | "typeof" | "unsafe" | "unsized" | "use" | "virtual" | "where" | "while" | "yield" | "str" | "bool" | "f32" | "f64" | "usize" | "isize" | "u128" | "i128" | "u64" | "i64" | diff --git a/tests/expectations/tests/keywords.rs b/tests/expectations/tests/keywords.rs index f77bda0bc2..055b0f003e 100644 --- a/tests/expectations/tests/keywords.rs +++ b/tests/expectations/tests/keywords.rs @@ -145,6 +145,10 @@ extern "C" { #[link_name = "\u{1}true"] pub static mut true_: ::std::os::raw::c_int; } +extern "C" { + #[link_name = "\u{1}try"] + pub static mut try_: ::std::os::raw::c_int; +} extern "C" { #[link_name = "\u{1}type"] pub static mut type_: ::std::os::raw::c_int; diff --git a/tests/headers/keywords.h b/tests/headers/keywords.h index 78ad278473..d7fe2065b0 100644 --- a/tests/headers/keywords.h +++ b/tests/headers/keywords.h @@ -34,6 +34,7 @@ int Self; int super; int trait; int true; +int try; int type; int unsafe; int use; From 0a24ab3a304e7d8f0a08918413145667cabb9aaa Mon Sep 17 00:00:00 2001 From: Eric Seppanen Date: Sun, 7 Nov 2021 13:41:19 -0800 Subject: [PATCH 226/942] allow custom derives on enums Custom derives are just as useful on enums as they are on structs; not supporting this was an oversight. Adds a test that will fail to compile if the custom derive doesn't work on enums. This test fails without the codegen fix. --- bindgen-integration/build.rs | 4 ++++ bindgen-integration/cpp/Test.h | 7 +++++++ bindgen-integration/src/lib.rs | 10 ++++++++++ src/codegen/mod.rs | 10 ++++++++++ 4 files changed, 31 insertions(+) diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs index fa0246c460..77ea64b581 100644 --- a/bindgen-integration/build.rs +++ b/bindgen-integration/build.rs @@ -126,6 +126,10 @@ impl ParseCallbacks for MacroCallback { vec![ "PartialEq".into(), ] + } else if name == "MyOrderedEnum" { + vec![ + "PartialOrd".into(), + ] } else { vec![] } diff --git a/bindgen-integration/cpp/Test.h b/bindgen-integration/cpp/Test.h index ad71b0f672..eee1974cbc 100644 --- a/bindgen-integration/cpp/Test.h +++ b/bindgen-integration/cpp/Test.h @@ -234,3 +234,10 @@ typedef union { } Coord; Coord coord(double x, double y, double z, double t); + +// Used to test custom derives on enum. See `test_custom_derive`. +enum MyOrderedEnum { + MICRON, + METER, + LIGHTYEAR, +}; diff --git a/bindgen-integration/src/lib.rs b/bindgen-integration/src/lib.rs index f56e72597d..43f71580d2 100755 --- a/bindgen-integration/src/lib.rs +++ b/bindgen-integration/src/lib.rs @@ -275,4 +275,14 @@ fn test_custom_derive() { let test1 = unsafe { bindings::Test::new(5) }; let test2 = unsafe { bindings::Test::new(6) }; assert_ne!(test1, test2); + + // The `add_derives` callback should have added `#[derive(PartialOrd)]` + // to the `MyOrderedEnum` enum. If it didn't, this will fail to compile. + + let micron = unsafe { bindings::MyOrderedEnum::MICRON }; + let meter = unsafe { bindings::MyOrderedEnum::METER }; + let lightyear = unsafe { bindings::MyOrderedEnum::LIGHTYEAR }; + + assert!(meter < lightyear); + assert!(meter > micron); } diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 69dde2c580..b703a1064b 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -3014,6 +3014,16 @@ impl CodeGenerator for Enum { derives.push(derive); } } + + // The custom derives callback may return a list of derive attributes; + // add them to the end of the list. + let custom_derives; + if let Some(cb) = &ctx.options().parse_callbacks { + custom_derives = cb.add_derives(&name); + // In most cases this will be a no-op, since custom_derives will be empty. + derives.extend(custom_derives.iter().map(|s| s.as_str())); + }; + attrs.push(attributes::derives(&derives)); } From 302b4842a39ed3a50d3d4dc8b3d2ce066b40fd83 Mon Sep 17 00:00:00 2001 From: follower Date: Mon, 8 Nov 2021 09:07:47 +1300 Subject: [PATCH 227/942] Typo fix: "in side" -> "inside" --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 1129efe767..a47d26e167 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2642,7 +2642,7 @@ fn get_target_dependent_env_var(var: &str) -> Option { /// A ParseCallbacks implementation that will act on file includes by echoing a rerun-if-changed /// line /// -/// When running in side a `build.rs` script, this can be used to make cargo invalidate the +/// When running inside a `build.rs` script, this can be used to make cargo invalidate the /// generated bindings whenever any of the files included from the header change: /// ``` /// use bindgen::builder; From 04f5c0715832feee6c059128cd5cd70056e861f7 Mon Sep 17 00:00:00 2001 From: Alberto Planas Date: Fri, 17 Sep 2021 11:34:11 +0200 Subject: [PATCH 228/942] Drop 'static for pub const strings for rustc>1.17 Constant and static declaration have a 'static live time by default, that is already elided since 1.17. Clippy complains on this kind of strings that are present in the generated code. This patch remove the 'static live time for those strings when rustc > 1.17 via a new added RustFeature. Fix #1612 Signed-off-by: Alberto Planas --- src/codegen/mod.rs | 19 +++++++++++++++---- src/features.rs | 18 +++++++++++++----- .../tests/libclang-3.9/constant-evaluate.rs | 2 +- .../tests/libclang-4/constant-evaluate.rs | 2 +- .../tests/libclang-5/constant-evaluate.rs | 2 +- .../tests/libclang-9/constant-evaluate.rs | 2 +- tests/expectations/tests/macro_const.rs | 2 +- tests/expectations/tests/macro_const_1_0.rs | 14 ++++++++++++++ tests/headers/macro_const_1_0.h | 10 ++++++++++ 9 files changed, 57 insertions(+), 14 deletions(-) create mode 100644 tests/expectations/tests/macro_const_1_0.rs create mode 100644 tests/headers/macro_const_1_0.h diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index b703a1064b..19886e3d3c 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -665,10 +665,21 @@ impl CodeGenerator for Var { match String::from_utf8(bytes.clone()) { Ok(string) => { let cstr = helpers::ast_ty::cstr_expr(string); - result.push(quote! { - #(#attrs)* - pub const #canonical_ident : &'static #ty = #cstr ; - }); + if ctx + .options() + .rust_features + .static_lifetime_elision + { + result.push(quote! { + #(#attrs)* + pub const #canonical_ident : &#ty = #cstr ; + }); + } else { + result.push(quote! { + #(#attrs)* + pub const #canonical_ident : &'static #ty = #cstr ; + }); + } } Err(..) => { let bytes = helpers::ast_ty::byte_array_expr(bytes); diff --git a/src/features.rs b/src/features.rs index 99b789e089..a786f07f12 100644 --- a/src/features.rs +++ b/src/features.rs @@ -87,8 +87,9 @@ macro_rules! rust_target_base { $x_macro!( /// Rust stable 1.0 => Stable_1_0 => 1.0; - /// Rust stable 1.1 - => Stable_1_1 => 1.1; + /// Rust stable 1.17 + /// * Static lifetime elision ([RFC 1623](https://github.com/rust-lang/rfcs/blob/master/text/1623-static.md)) + => Stable_1_17 => 1.17; /// Rust stable 1.19 /// * Untagged unions ([RFC 1444](https://github.com/rust-lang/rfcs/blob/master/text/1444-union.md)) => Stable_1_19 => 1.19; @@ -191,6 +192,9 @@ macro_rules! rust_feature_def { // documentation for the relevant variant in the rust_target_base macro // definition. rust_feature_def!( + Stable_1_17 { + => static_lifetime_elision; + } Stable_1_19 { => untagged_union; } @@ -249,7 +253,8 @@ mod test { fn target_features() { let f_1_0 = RustFeatures::from(RustTarget::Stable_1_0); assert!( - !f_1_0.core_ffi_c_void && + !f_1_0.static_lifetime_elision && + !f_1_0.core_ffi_c_void && !f_1_0.untagged_union && !f_1_0.associated_const && !f_1_0.builtin_clone_impls && @@ -258,7 +263,8 @@ mod test { ); let f_1_21 = RustFeatures::from(RustTarget::Stable_1_21); assert!( - !f_1_21.core_ffi_c_void && + f_1_21.static_lifetime_elision && + !f_1_21.core_ffi_c_void && f_1_21.untagged_union && f_1_21.associated_const && f_1_21.builtin_clone_impls && @@ -267,7 +273,8 @@ mod test { ); let f_nightly = RustFeatures::from(RustTarget::Nightly); assert!( - f_nightly.core_ffi_c_void && + f_nightly.static_lifetime_elision && + f_nightly.core_ffi_c_void && f_nightly.untagged_union && f_nightly.associated_const && f_nightly.builtin_clone_impls && @@ -286,6 +293,7 @@ mod test { #[test] fn str_to_target() { test_target("1.0", RustTarget::Stable_1_0); + test_target("1.17", RustTarget::Stable_1_17); test_target("1.19", RustTarget::Stable_1_19); test_target("1.21", RustTarget::Stable_1_21); test_target("1.25", RustTarget::Stable_1_25); diff --git a/tests/expectations/tests/libclang-3.9/constant-evaluate.rs b/tests/expectations/tests/libclang-3.9/constant-evaluate.rs index 77e281289e..b7286a37aa 100644 --- a/tests/expectations/tests/libclang-3.9/constant-evaluate.rs +++ b/tests/expectations/tests/libclang-3.9/constant-evaluate.rs @@ -23,5 +23,5 @@ pub const BAZ: ::std::os::raw::c_longlong = 24; pub const fuzz: f64 = 51.0; pub const BAZZ: ::std::os::raw::c_char = 53; pub const WAT: ::std::os::raw::c_char = 0; -pub const bytestring: &'static [u8; 4usize] = b"Foo\0"; +pub const bytestring: &[u8; 4usize] = b"Foo\0"; pub const NOT_UTF8: [u8; 5usize] = [240u8, 40u8, 140u8, 40u8, 0u8]; diff --git a/tests/expectations/tests/libclang-4/constant-evaluate.rs b/tests/expectations/tests/libclang-4/constant-evaluate.rs index df2638f447..9debe39d3e 100644 --- a/tests/expectations/tests/libclang-4/constant-evaluate.rs +++ b/tests/expectations/tests/libclang-4/constant-evaluate.rs @@ -21,5 +21,5 @@ pub const BAZ: ::std::os::raw::c_longlong = 24; pub const fuzz: f64 = 51.0; pub const BAZZ: ::std::os::raw::c_char = 53; pub const WAT: ::std::os::raw::c_char = 0; -pub const bytestring: &'static [u8; 4usize] = b"Foo\0"; +pub const bytestring: &[u8; 4usize] = b"Foo\0"; pub const NOT_UTF8: [u8; 5usize] = [240u8, 40u8, 140u8, 40u8, 0u8]; diff --git a/tests/expectations/tests/libclang-5/constant-evaluate.rs b/tests/expectations/tests/libclang-5/constant-evaluate.rs index df2638f447..9debe39d3e 100644 --- a/tests/expectations/tests/libclang-5/constant-evaluate.rs +++ b/tests/expectations/tests/libclang-5/constant-evaluate.rs @@ -21,5 +21,5 @@ pub const BAZ: ::std::os::raw::c_longlong = 24; pub const fuzz: f64 = 51.0; pub const BAZZ: ::std::os::raw::c_char = 53; pub const WAT: ::std::os::raw::c_char = 0; -pub const bytestring: &'static [u8; 4usize] = b"Foo\0"; +pub const bytestring: &[u8; 4usize] = b"Foo\0"; pub const NOT_UTF8: [u8; 5usize] = [240u8, 40u8, 140u8, 40u8, 0u8]; diff --git a/tests/expectations/tests/libclang-9/constant-evaluate.rs b/tests/expectations/tests/libclang-9/constant-evaluate.rs index df2638f447..9debe39d3e 100644 --- a/tests/expectations/tests/libclang-9/constant-evaluate.rs +++ b/tests/expectations/tests/libclang-9/constant-evaluate.rs @@ -21,5 +21,5 @@ pub const BAZ: ::std::os::raw::c_longlong = 24; pub const fuzz: f64 = 51.0; pub const BAZZ: ::std::os::raw::c_char = 53; pub const WAT: ::std::os::raw::c_char = 0; -pub const bytestring: &'static [u8; 4usize] = b"Foo\0"; +pub const bytestring: &[u8; 4usize] = b"Foo\0"; pub const NOT_UTF8: [u8; 5usize] = [240u8, 40u8, 140u8, 40u8, 0u8]; diff --git a/tests/expectations/tests/macro_const.rs b/tests/expectations/tests/macro_const.rs index e135661121..de423a2af0 100644 --- a/tests/expectations/tests/macro_const.rs +++ b/tests/expectations/tests/macro_const.rs @@ -5,7 +5,7 @@ non_upper_case_globals )] -pub const foo: &'static [u8; 4usize] = b"bar\0"; +pub const foo: &[u8; 4usize] = b"bar\0"; pub const CHAR: u8 = 98u8; pub const CHARR: u8 = 0u8; pub const FLOAT: f64 = 5.09; diff --git a/tests/expectations/tests/macro_const_1_0.rs b/tests/expectations/tests/macro_const_1_0.rs new file mode 100644 index 0000000000..e135661121 --- /dev/null +++ b/tests/expectations/tests/macro_const_1_0.rs @@ -0,0 +1,14 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +pub const foo: &'static [u8; 4usize] = b"bar\0"; +pub const CHAR: u8 = 98u8; +pub const CHARR: u8 = 0u8; +pub const FLOAT: f64 = 5.09; +pub const FLOAT_EXPR: f64 = 0.005; +pub const LONG: u32 = 3; +pub const INVALID_UTF8: [u8; 5usize] = [240u8, 40u8, 140u8, 40u8, 0u8]; diff --git a/tests/headers/macro_const_1_0.h b/tests/headers/macro_const_1_0.h new file mode 100644 index 0000000000..3be86b4fd2 --- /dev/null +++ b/tests/headers/macro_const_1_0.h @@ -0,0 +1,10 @@ +// bindgen-flags: --rust-target 1.0 + +#define foo "bar" +#define CHAR 'b' +#define CHARR '\0' +#define FLOAT 5.09f +#define FLOAT_EXPR (5 / 1000.0f) +#define LONG 3L + +#define INVALID_UTF8 "\xf0\x28\x8c\x28" From 7bd23291e29e1874f57a628e94d7632b3b367ae6 Mon Sep 17 00:00:00 2001 From: David Drysdale Date: Fri, 26 Nov 2021 01:42:47 +0000 Subject: [PATCH 229/942] Add --blocklist-file option (#2097) Update Item to hold a `clang::SourceLocation` and use this to allow blocklisting based on filename. The existing code has a special case that always maps integer types to corresponding Rust integer types, even if the C types are blocklisted. To match this special case behaviour, also treat these C types as being eligible for derived Copy/Clone/Debug traits. Fixes #2096 --- CONTRIBUTING.md | 6 +- book/src/blocklisting.md | 14 +++- src/clang.rs | 6 ++ src/ir/context.rs | 37 +++++++-- src/ir/item.rs | 28 ++++++- src/lib.rs | 14 ++++ src/options.rs | 14 ++++ tests/expectations/tests/blocklist-file.rs | 94 ++++++++++++++++++++++ tests/headers/blocklist-file.hpp | 18 +++++ tests/headers/blocklisted/fake-stdint.h | 7 ++ tests/headers/blocklisted/file.hpp | 26 ++++++ 11 files changed, 250 insertions(+), 14 deletions(-) create mode 100644 tests/expectations/tests/blocklist-file.rs create mode 100644 tests/headers/blocklist-file.hpp create mode 100644 tests/headers/blocklisted/fake-stdint.h create mode 100644 tests/headers/blocklisted/file.hpp diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8a9f8688f6..e6b6a505d0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -247,8 +247,8 @@ See [./csmith-fuzzing/README.md](./csmith-fuzzing/README.md) for details. The `tests/quickchecking` crate generates property tests for `bindgen`. From the crate's directory you can run the tests with `cargo run`. For details -on additional configuration including how to preserve / inspect the generated -property tests, see +on additional configuration including how to preserve / inspect the generated +property tests, see [./tests/quickchecking/README.md](./tests/quickchecking/README.md). ## Code Overview @@ -298,6 +298,8 @@ looking at. Here is a summary of the IR types and their relationships: * Its type's `ItemId` * Optionally, a mangled name * Optionally, a value + * An optional `clang::SourceLocation` that holds the first source code + location where the `Item` was encountered. The IR forms a graph of interconnected and inter-referencing types and functions. The `ir::traversal` module provides IR graph traversal diff --git a/book/src/blocklisting.md b/book/src/blocklisting.md index 5c082ddaba..6eb5786328 100644 --- a/book/src/blocklisting.md +++ b/book/src/blocklisting.md @@ -2,8 +2,7 @@ If you need to provide your own custom translation of some type (for example, because you need to wrap one of its fields in an `UnsafeCell`), you can -explicitly blocklist - generation of its definition. Uses of the blocklisted type +explicitly blocklist generation of its definition. Uses of the blocklisted type will still appear in other types' definitions. (If you don't want the type to appear in the bindings at all, [make it opaque](./opaque.md) instead of @@ -13,14 +12,25 @@ Blocklisted types are pessimistically assumed not to be able to `derive` any traits, which can transitively affect other types' ability to `derive` traits or not. +The `blocklist-file` option also allows the blocklisting of all items from a +particular path regex, for example to block all types defined in system headers +that are transitively included. + ### Library +* [`bindgen::Builder::blocklist_file`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.blocklist_file) +* [`bindgen::Builder::blocklist_function`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.blocklist_function) +* [`bindgen::Builder::blocklist_item`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.blocklist_item) * [`bindgen::Builder::blocklist_type`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.blocklist_type) ### Command Line +* `--blocklist-file ` +* `--blocklist-function ` +* `--blocklist-item ` * `--blocklist-type ` + ### Annotations ```cpp diff --git a/src/clang.rs b/src/clang.rs index 36ccd266f8..074d459ba7 100644 --- a/src/clang.rs +++ b/src/clang.rs @@ -1401,6 +1401,12 @@ impl fmt::Display for SourceLocation { } } +impl fmt::Debug for SourceLocation { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", self) + } +} + /// A comment in the source text. /// /// Comments are sort of parsed by Clang, and have a tree structure. diff --git a/src/ir/context.rs b/src/ir/context.rs index ffb49d7400..a9e19fb2a1 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -1423,7 +1423,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" fn build_root_module(id: ItemId) -> Item { let module = Module::new(Some("root".into()), ModuleKind::Normal); - Item::new(id, None, None, id, ItemKind::Module(module)) + Item::new(id, None, None, id, ItemKind::Module(module), None) } /// Get the root module. @@ -1733,6 +1733,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" None, self.current_module.into(), ItemKind::Type(sub_ty), + Some(child.location()), ); // Bypass all the validations in add_item explicitly. @@ -1797,6 +1798,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" None, self.current_module.into(), ItemKind::Type(ty), + Some(location.location()), ); // Bypass all the validations in add_item explicitly. @@ -1930,6 +1932,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" ) -> TypeId { let spelling = ty.spelling(); let layout = ty.fallible_layout(self).ok(); + let location = ty.declaration().location(); let type_kind = TypeKind::ResolvedTypeRef(wrapped_id); let ty = Type::new(Some(spelling), layout, type_kind, is_const); let item = Item::new( @@ -1938,6 +1941,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" None, parent_id.unwrap_or_else(|| self.current_module.into()), ItemKind::Type(ty), + Some(location), ); self.add_builtin_item(item); with_id.as_type_id_unchecked() @@ -1998,6 +2002,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" let spelling = ty.spelling(); let is_const = ty.is_const(); let layout = ty.fallible_layout(self).ok(); + let location = ty.declaration().location(); let ty = Type::new(Some(spelling), layout, type_kind, is_const); let id = self.next_item_id(); let item = Item::new( @@ -2006,6 +2011,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" None, self.root_module.into(), ItemKind::Type(ty), + Some(location), ); self.add_builtin_item(item); Some(id.as_type_id_unchecked()) @@ -2194,6 +2200,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" None, self.current_module.into(), ItemKind::Module(module), + Some(cursor.location()), ); let module_id = module.id().as_module_id_unchecked(); @@ -2241,11 +2248,6 @@ If you encounter an error missing from this list, please file an issue or a PR!" assert!(self.in_codegen_phase()); assert!(self.current_module == self.root_module); - let cb = match self.options.parse_callbacks { - Some(ref cb) => cb, - None => return CanDerive::No, - }; - *self .blocklisted_types_implement_traits .borrow_mut() @@ -2255,8 +2257,27 @@ If you encounter an error missing from this list, please file an issue or a PR!" .or_insert_with(|| { item.expect_type() .name() - .and_then(|name| { - cb.blocklisted_type_implements_trait(name, derive_trait) + .and_then(|name| match self.options.parse_callbacks { + Some(ref cb) => cb.blocklisted_type_implements_trait( + name, + derive_trait, + ), + // Sized integer types from get mapped to Rust primitive + // types regardless of whether they are blocklisted, so ensure that + // standard traits are considered derivable for them too. + None => match name { + "int8_t" | "uint8_t" | "int16_t" | "uint16_t" | + "int32_t" | "uint32_t" | "int64_t" | + "uint64_t" | "uintptr_t" | "intptr_t" | + "ptrdiff_t" => Some(CanDerive::Yes), + "size_t" if self.options.size_t_is_usize => { + Some(CanDerive::Yes) + } + "ssize_t" if self.options.size_t_is_usize => { + Some(CanDerive::Yes) + } + _ => Some(CanDerive::No), + }, }) .unwrap_or(CanDerive::No) }) diff --git a/src/ir/item.rs b/src/ir/item.rs index 730271efea..8692575fe9 100644 --- a/src/ir/item.rs +++ b/src/ir/item.rs @@ -417,6 +417,8 @@ pub struct Item { parent_id: ItemId, /// The item kind. kind: ItemKind, + /// The source location of the item. + location: Option, } impl AsRef for Item { @@ -433,6 +435,7 @@ impl Item { annotations: Option, parent_id: ItemId, kind: ItemKind, + location: Option, ) -> Self { debug_assert!(id != parent_id || kind.is_module()); Item { @@ -445,6 +448,7 @@ impl Item { comment, annotations: annotations.unwrap_or_default(), kind, + location, } } @@ -454,10 +458,15 @@ impl Item { ty: &clang::Type, ctx: &mut BindgenContext, ) -> TypeId { + let location = ty.declaration().location(); let ty = Opaque::from_clang_ty(ty, ctx); let kind = ItemKind::Type(ty); let parent = ctx.root_module().into(); - ctx.add_item(Item::new(with_id, None, None, parent, kind), None, None); + ctx.add_item( + Item::new(with_id, None, None, parent, kind, Some(location)), + None, + None, + ); with_id.as_type_id_unchecked() } @@ -632,6 +641,17 @@ impl Item { return true; } + if !ctx.options().blocklisted_files.is_empty() { + if let Some(location) = &self.location { + let (file, _, _, _) = location.location(); + if let Some(filename) = file.name() { + if ctx.options().blocklisted_files.matches(&filename) { + return true; + } + } + } + } + let path = self.path_for_allowlisting(ctx); let name = path[1..].join("::"); ctx.options().blocklisted_items.matches(&name) || @@ -1297,7 +1317,7 @@ impl ClangItemParser for Item { let id = ctx.next_item_id(); let module = ctx.root_module().into(); ctx.add_item( - Item::new(id, None, None, module, ItemKind::Type(ty)), + Item::new(id, None, None, module, ItemKind::Type(ty), None), None, None, ); @@ -1335,6 +1355,7 @@ impl ClangItemParser for Item { annotations, relevant_parent_id, ItemKind::$what(item), + Some(cursor.location()), ), declaration, Some(cursor), @@ -1516,6 +1537,7 @@ impl ClangItemParser for Item { None, parent_id.unwrap_or_else(|| current_module.into()), ItemKind::Type(Type::new(None, None, kind, is_const)), + Some(location.location()), ), None, None, @@ -1647,6 +1669,7 @@ impl ClangItemParser for Item { annotations, relevant_parent_id, ItemKind::Type(item), + Some(location.location()), ), declaration, Some(location), @@ -1875,6 +1898,7 @@ impl ClangItemParser for Item { None, parent, ItemKind::Type(Type::named(name)), + Some(location.location()), ); ctx.add_type_param(item, definition); Some(id.as_type_id_unchecked()) diff --git a/src/lib.rs b/src/lib.rs index a47d26e167..abe1ed709b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -308,6 +308,7 @@ impl Builder { (&self.options.blocklisted_types, "--blocklist-type"), (&self.options.blocklisted_functions, "--blocklist-function"), (&self.options.blocklisted_items, "--blocklist-item"), + (&self.options.blocklisted_files, "--blocklist-file"), (&self.options.opaque_types, "--opaque-type"), (&self.options.allowlisted_functions, "--allowlist-function"), (&self.options.allowlisted_types, "--allowlist-type"), @@ -821,6 +822,13 @@ impl Builder { self } + /// Hide any contents of the given file from the generated bindings, + /// regardless of whether it's a type, function, module etc. + pub fn blocklist_file>(mut self, arg: T) -> Builder { + self.options.blocklisted_files.insert(arg); + self + } + /// Treat the given type as opaque in the generated bindings. Regular /// expressions are supported. /// @@ -1669,6 +1677,10 @@ struct BindgenOptions { /// blocklisted and should not appear in the generated code. blocklisted_items: RegexSet, + /// The set of files whose contents should be blocklisted and should not + /// appear in the generated code. + blocklisted_files: RegexSet, + /// The set of types that should be treated as opaque structures in the /// generated code. opaque_types: RegexSet, @@ -1982,6 +1994,7 @@ impl BindgenOptions { &mut self.blocklisted_types, &mut self.blocklisted_functions, &mut self.blocklisted_items, + &mut self.blocklisted_files, &mut self.opaque_types, &mut self.bitfield_enums, &mut self.constified_enums, @@ -2029,6 +2042,7 @@ impl Default for BindgenOptions { blocklisted_types: Default::default(), blocklisted_functions: Default::default(), blocklisted_items: Default::default(), + blocklisted_files: Default::default(), opaque_types: Default::default(), rustfmt_path: Default::default(), depfile: Default::default(), diff --git a/src/options.rs b/src/options.rs index 9aac5dae83..bc7431c52d 100644 --- a/src/options.rs +++ b/src/options.rs @@ -164,6 +164,14 @@ where .takes_value(true) .multiple(true) .number_of_values(1), + Arg::with_name("blocklist-file") + .alias("blacklist-file") + .long("blocklist-file") + .help("Mark all contents of as hidden.") + .value_name("path") + .takes_value(true) + .multiple(true) + .number_of_values(1), Arg::with_name("no-layout-tests") .long("no-layout-tests") .help("Avoid generating layout tests for any type."), @@ -630,6 +638,12 @@ where } } + if let Some(hidden_files) = matches.values_of("blocklist-file") { + for file in hidden_files { + builder = builder.blocklist_file(file); + } + } + if matches.is_present("builtins") { builder = builder.emit_builtins(); } diff --git a/tests/expectations/tests/blocklist-file.rs b/tests/expectations/tests/blocklist-file.rs new file mode 100644 index 0000000000..fe00b5ab4a --- /dev/null +++ b/tests/expectations/tests/blocklist-file.rs @@ -0,0 +1,94 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct SizedIntegers { + pub x: u8, + pub y: u16, + pub z: u32, +} +#[test] +fn bindgen_test_layout_SizedIntegers() { + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(SizedIntegers)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(SizedIntegers)) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).x as *const _ as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(SizedIntegers), + "::", + stringify!(x) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).y as *const _ as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(SizedIntegers), + "::", + stringify!(y) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).z as *const _ as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(SizedIntegers), + "::", + stringify!(z) + ) + ); +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct StructWithBlocklistedFwdDecl { + pub b: u8, +} +#[test] +fn bindgen_test_layout_StructWithBlocklistedFwdDecl() { + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(StructWithBlocklistedFwdDecl)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(StructWithBlocklistedFwdDecl)) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).b + as *const _ as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(StructWithBlocklistedFwdDecl), + "::", + stringify!(b) + ) + ); +} diff --git a/tests/headers/blocklist-file.hpp b/tests/headers/blocklist-file.hpp new file mode 100644 index 0000000000..ad8bcd665c --- /dev/null +++ b/tests/headers/blocklist-file.hpp @@ -0,0 +1,18 @@ +// bindgen-flags: --blocklist-file ".*/blocklisted/file.*" -- -Itests/headers + +// Forward declaration of struct that's defined in a blocklisted file. +struct StructWithBlocklistedDefinition; + +#include "blocklisted/file.hpp" +#include "blocklisted/fake-stdint.h" + +struct SizedIntegers { + uint8_t x; + uint16_t y; + uint32_t z; +}; + +// Actual definition of struct that has a forward declaration in a blocklisted file. +struct StructWithBlocklistedFwdDecl { + uint8_t b; +}; diff --git a/tests/headers/blocklisted/fake-stdint.h b/tests/headers/blocklisted/fake-stdint.h new file mode 100644 index 0000000000..a8cfe01056 --- /dev/null +++ b/tests/headers/blocklisted/fake-stdint.h @@ -0,0 +1,7 @@ +// -like types get special treatment even when blocklisted. +typedef signed char int8_t; +typedef unsigned char uint8_t; +typedef signed short int16_t; +typedef unsigned short uint16_t; +typedef signed int int32_t; +typedef unsigned int uint32_t; diff --git a/tests/headers/blocklisted/file.hpp b/tests/headers/blocklisted/file.hpp new file mode 100644 index 0000000000..4bcb589e1d --- /dev/null +++ b/tests/headers/blocklisted/file.hpp @@ -0,0 +1,26 @@ +void SomeFunction(); +extern int someVar; +#define SOME_DEFUN 123 + +class someClass { + void somePrivateMethod(); +public: + void somePublicMethod(int foo); +}; + +extern "C" void ExternFunction(); + +namespace foo { + void NamespacedFunction(); +} + +namespace bar { + void NamespacedFunction(); +} + + +struct StructWithBlocklistedFwdDecl; + +struct StructWithBlocklistedDefinition { + StructWithBlocklistedFwdDecl* other; +}; From 89032649044d875983a851fff6fbde2d4e2ceaeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Fri, 26 Nov 2021 02:50:32 +0100 Subject: [PATCH 230/942] Bump version. * cexpr+env_logger bump. * Various fixes for C++ crashes / hangs. * Enums now respect annotations and derives properly in more cases. * Some more APIs (blocklist-file, etc). * 'static lifetime is elided when appropriate. --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 400fb112dd..d79a408e7d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -33,7 +33,7 @@ dependencies = [ [[package]] name = "bindgen" -version = "0.59.1" +version = "0.59.2" dependencies = [ "bitflags", "cexpr", diff --git a/Cargo.toml b/Cargo.toml index 26fd6cb9ea..ba41a22dbb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ readme = "README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.59.1" +version = "0.59.2" edition = "2018" build = "build.rs" From b1af6a42f583badc425c10cbbefb9dc4c833301e Mon Sep 17 00:00:00 2001 From: MikuroXina Date: Tue, 7 Dec 2021 07:11:48 +0900 Subject: [PATCH 231/942] Remove fields never read --- src/ir/context.rs | 11 ----------- src/ir/function.rs | 5 +++++ src/lib.rs | 9 --------- 3 files changed, 5 insertions(+), 20 deletions(-) diff --git a/src/ir/context.rs b/src/ir/context.rs index a9e19fb2a1..b2e6f98542 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -364,9 +364,6 @@ pub struct BindgenContext { in_codegen: bool, - /// The clang index for parsing. - index: clang::Index, - /// The translation unit for parsing. translation_unit: clang::TranslationUnit, @@ -420,12 +417,6 @@ pub struct BindgenContext { /// and is always `None` before that and `Some` after. cannot_derive_copy: Option>, - /// The set of (`ItemId`s of) types that can't derive copy in array. - /// - /// This is populated when we enter codegen by `compute_cannot_derive_copy` - /// and is always `None` before that and `Some` after. - cannot_derive_copy_in_array: Option>, - /// The set of (`ItemId`s of) types that can't derive hash. /// /// This is populated when we enter codegen by `compute_can_derive_hash` @@ -569,7 +560,6 @@ If you encounter an error missing from this list, please file an issue or a PR!" replacements: Default::default(), collected_typerefs: false, in_codegen: false, - index, translation_unit, target_info, options, @@ -582,7 +572,6 @@ If you encounter an error missing from this list, please file an issue or a PR!" cannot_derive_debug: None, cannot_derive_default: None, cannot_derive_copy: None, - cannot_derive_copy_in_array: None, cannot_derive_hash: None, cannot_derive_partialeq_or_partialord: None, sizedness: None, diff --git a/src/ir/function.rs b/src/ir/function.rs index a3a2bbfbfe..0ba2d1ee51 100644 --- a/src/ir/function.rs +++ b/src/ir/function.rs @@ -131,6 +131,11 @@ impl Function { self.signature } + /// Get this function's comment. + pub fn comment(&self) -> Option<&str> { + self.comment.as_deref() + } + /// Get this function's kind. pub fn kind(&self) -> FunctionKind { self.kind diff --git a/src/lib.rs b/src/lib.rs index abe1ed709b..36128ded58 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1827,13 +1827,6 @@ struct BindgenOptions { /// Whether to time the bindgen phases. time_phases: bool, - /// True if we should generate constant names that are **directly** under - /// namespaces. - namespaced_constants: bool, - - /// True if we should use MSVC name mangling rules. - msvc_mangling: bool, - /// Whether we should convert float types to f32/f64 types. convert_floats: bool, @@ -2084,8 +2077,6 @@ impl Default for BindgenOptions { use_core: false, ctypes_prefix: None, anon_fields_prefix: DEFAULT_ANON_FIELDS_PREFIX.into(), - namespaced_constants: true, - msvc_mangling: false, convert_floats: true, raw_lines: vec![], module_lines: HashMap::default(), From 421e0eea167f7b4cc6607cd85fd7eee2a0bca554 Mon Sep 17 00:00:00 2001 From: Aapo Alasuutari Date: Sun, 5 Dec 2021 21:53:00 +0200 Subject: [PATCH 232/942] Add note about RVO in cpp.md `bindgen`'s inability to currently support RVO should be noted in C++ bindings generation document. --- book/src/cpp.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/book/src/cpp.md b/book/src/cpp.md index 1be7a8a731..75ef855494 100644 --- a/book/src/cpp.md +++ b/book/src/cpp.md @@ -71,3 +71,8 @@ cannot translate into Rust: generate undefined behaviour. See [the tracking issue for exceptions](https://github.com/rust-lang/rust-bindgen/issues/1208) for more details. + +* Return value optimization. C++ compilers will in certain circumstances optimize functions + returning a struct type value to instead take an extra hidden argument that refers + to the return value struct. `bindgen` cannot necessarily know about this optimization and + thus at present `bindgen`-interfaces for these kinds of functions are invalid. From 949e610f6bebaa48eb927983f5547fdbf54947a1 Mon Sep 17 00:00:00 2001 From: MikuroXina Date: Sat, 4 Dec 2021 17:25:06 +0900 Subject: [PATCH 233/942] Fix warnings on tests --- src/ir/analysis/mod.rs | 16 ++++++++++------ src/lib.rs | 8 ++------ tests/tests.rs | 29 ++++++++++++++--------------- 3 files changed, 26 insertions(+), 27 deletions(-) diff --git a/src/ir/analysis/mod.rs b/src/ir/analysis/mod.rs index eb9a1c0d64..40dfc6d644 100644 --- a/src/ir/analysis/mod.rs +++ b/src/ir/analysis/mod.rs @@ -281,9 +281,13 @@ mod tests { fn reverse(&self) -> Graph { let mut reversed = Graph::default(); for (node, edges) in self.0.iter() { - reversed.0.entry(*node).or_insert(vec![]); + reversed.0.entry(*node).or_insert_with(Vec::new); for referent in edges.iter() { - reversed.0.entry(*referent).or_insert(vec![]).push(*node); + reversed + .0 + .entry(*referent) + .or_insert_with(Vec::new) + .push(*node); } } reversed @@ -306,8 +310,8 @@ mod tests { let reversed = graph.reverse(); ReachableFrom { reachable: Default::default(), - graph: graph, - reversed: reversed, + graph, + reversed, } } @@ -328,7 +332,7 @@ mod tests { let original_size = self .reachable .entry(node) - .or_insert(HashSet::default()) + .or_insert_with(HashSet::default) .len(); for sub_node in self.graph.0[&node].iter() { @@ -337,7 +341,7 @@ mod tests { let sub_reachable = self .reachable .entry(*sub_node) - .or_insert(HashSet::default()) + .or_insert_with(HashSet::default) .clone(); for transitive in sub_reachable { diff --git a/src/lib.rs b/src/lib.rs index 36128ded58..560370b25a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2682,9 +2682,7 @@ fn commandline_flag_unit_test_function() { .map(|&x| x.into()) .collect::>(); - assert!(test_cases - .iter() - .all(|ref x| command_line_flags.contains(x),)); + assert!(test_cases.iter().all(|x| command_line_flags.contains(x))); //Test 2 let bindings = crate::builder() @@ -2709,9 +2707,7 @@ fn commandline_flag_unit_test_function() { .collect::>(); println!("{:?}", command_line_flags); - assert!(test_cases - .iter() - .all(|ref x| command_line_flags.contains(x),)); + assert!(test_cases.iter().all(|x| command_line_flags.contains(x))); } #[test] diff --git a/tests/tests.rs b/tests/tests.rs index 323cf16dd7..a62fe42fa4 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -9,7 +9,7 @@ use bindgen::{clang_version, Builder}; use std::env; use std::fs; use std::io::{self, BufRead, BufReader, Error, ErrorKind, Read, Write}; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use std::process; use std::sync::Once; @@ -116,14 +116,13 @@ The latest `rustfmt` is required to run the `bindgen` test suite. Install } fn compare_generated_header( - header: &PathBuf, + header: &Path, builder: BuilderState, check_roundtrip: bool, ) -> Result<(), Error> { - let file_name = header.file_name().ok_or(Error::new( - ErrorKind::Other, - "compare_generated_header expects a file", - ))?; + let file_name = header.file_name().ok_or_else(|| { + Error::new(ErrorKind::Other, "compare_generated_header expects a file") + })?; let mut expectation = PathBuf::from(header); expectation.pop(); @@ -260,7 +259,7 @@ fn compare_generated_header( if let Some(roundtrip_builder) = roundtrip_builder { if let Err(e) = - compare_generated_header(&header, roundtrip_builder, false) + compare_generated_header(header, roundtrip_builder, false) { return Err(Error::new(ErrorKind::Other, format!("Checking CLI flags roundtrip errored! You probably need to fix Builder::command_line_flags. {}", e))); } @@ -292,7 +291,7 @@ impl BuilderState { let mut builder = builder_from_flags(flags.into_iter())?.0; if let Some(ref parse_cb) = self.parse_callbacks { builder = - builder.parse_callbacks(parse_callbacks::lookup(&parse_cb)); + builder.parse_callbacks(parse_callbacks::lookup(parse_cb)); } Some(BuilderState { builder, @@ -305,7 +304,7 @@ impl BuilderState { } } -fn create_bindgen_builder(header: &PathBuf) -> Result { +fn create_bindgen_builder(header: &Path) -> Result { #[cfg(feature = "logging")] let _ = env_logger::try_init(); @@ -357,9 +356,9 @@ fn create_bindgen_builder(header: &PathBuf) -> Result { // - add header filename as 1st element // - prepend raw lines so they're in the right order for expected output // - append the test header's bindgen flags - let header_str = header - .to_str() - .ok_or(Error::new(ErrorKind::Other, "Invalid header file name"))?; + let header_str = header.to_str().ok_or_else(|| { + Error::new(ErrorKind::Other, "Invalid header file name") + })?; let prepend = [ "bindgen", @@ -384,7 +383,7 @@ fn create_bindgen_builder(header: &PathBuf) -> Result { let mut builder = builder_from_flags(args)?.0; if let Some(ref parse_cb) = parse_callbacks { - builder = builder.parse_callbacks(parse_callbacks::lookup(&parse_cb)); + builder = builder.parse_callbacks(parse_callbacks::lookup(parse_cb)); } Ok(BuilderState { builder, @@ -631,11 +630,11 @@ fn dump_preprocessed_input() { let empty_layout = slurp(empty_layout); assert!( - bindgen_ii.find(&arg_keyword).is_some(), + bindgen_ii.contains(&arg_keyword), "arg_keyword.hpp is in the preprocessed file" ); assert!( - bindgen_ii.find(&empty_layout).is_some(), + bindgen_ii.contains(&empty_layout), "cpp-empty-layout.hpp is in the preprocessed file" ); } From 1d250491fc05f3ada141ff34014bf1876b0d9d20 Mon Sep 17 00:00:00 2001 From: MikuroXina Date: Sat, 4 Dec 2021 17:34:47 +0900 Subject: [PATCH 234/942] Add args --- .github/workflows/bindgen.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index bc525ed6f3..e750bc406c 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -35,6 +35,7 @@ jobs: uses: actions-rs/cargo@v1 with: command: clippy + args: -- --cfg test msrv: runs-on: ubuntu-latest From bcbd72d7f89a1fdfae59fad8db47ca4892d9c940 Mon Sep 17 00:00:00 2001 From: Triss Healy Date: Sun, 12 Dec 2021 15:09:30 +1100 Subject: [PATCH 235/942] Handle difference between clang and rust targets on RISC-V. --- src/lib.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 560370b25a..f3912e8e5b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2164,6 +2164,10 @@ fn rust_to_clang_target(rust_target: &str) -> String { clang_target .push_str(rust_target.strip_prefix("aarch64-apple-").unwrap()); return clang_target; + } else if rust_target.starts_with("riscv64gc-") { + let mut clang_target = "riscv64-".to_owned(); + clang_target.push_str(rust_target.strip_prefix("riscv64gc-").unwrap()); + return clang_target; } rust_target.to_owned() } @@ -2714,3 +2718,11 @@ fn commandline_flag_unit_test_function() { fn test_rust_to_clang_target() { assert_eq!(rust_to_clang_target("aarch64-apple-ios"), "arm64-apple-ios"); } + +#[test] +fn test_rust_to_clang_target_riscv() { + assert_eq!( + rust_to_clang_target("riscv64gc-unknown-linux-gnu"), + "riscv64-unknown-linux-gnu" + ) +} From ada0ac52107451a50f377fee04002db24e0ce02c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 21 Dec 2021 13:04:59 +0100 Subject: [PATCH 236/942] codegen: Don't automatically derive Debug and Copy for non-rust enums. Fixes #2143 --- src/codegen/mod.rs | 11 +++-------- tests/expectations/tests/enum-no-debug-rust.rs | 8 ++++---- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 19886e3d3c..bee299edfc 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -3005,14 +3005,9 @@ impl CodeGenerator for Enum { if !variation.is_const() { let mut derives = derives_of_item(item, ctx); - // For backwards compat, enums always derive Debug/Clone/Eq/PartialEq/Hash, even - // if we don't generate those by default. - if !item.annotations().disallow_debug() { - derives.insert(DerivableTraits::DEBUG); - } - if !item.annotations().disallow_copy() { - derives.insert(DerivableTraits::COPY); - } + // For backwards compat, enums always derive + // Clone/Eq/PartialEq/Hash, even if we don't generate those by + // default. derives.insert( DerivableTraits::CLONE | DerivableTraits::HASH | diff --git a/tests/expectations/tests/enum-no-debug-rust.rs b/tests/expectations/tests/enum-no-debug-rust.rs index fa06fbc0c6..dbcbd052cc 100644 --- a/tests/expectations/tests/enum-no-debug-rust.rs +++ b/tests/expectations/tests/enum-no-debug-rust.rs @@ -13,7 +13,7 @@ pub struct foo { pub const foo_FOO_A: foo__bindgen_ty_1 = foo__bindgen_ty_1::FOO_A; pub const foo_FOO_B: foo__bindgen_ty_1 = foo__bindgen_ty_1::FOO_B; #[repr(u32)] -#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +#[derive(Copy, Clone, Hash, PartialEq, Eq)] pub enum foo__bindgen_ty_1 { FOO_A = 0, FOO_B = 1, @@ -51,7 +51,7 @@ impl Default for foo { } } #[repr(u32)] -#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +#[derive(Copy, Clone, Hash, PartialEq, Eq)] pub enum Foo { Bar = 0, Qux = 1, @@ -70,8 +70,8 @@ pub enum NoDebug { } #[repr(u32)] ///
-#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +#[derive(Copy, Clone, Hash, PartialEq, Eq, Debug)] pub enum Debug { Debug1 = 0, Debug2 = 1, -} \ No newline at end of file +} From c8f11665d40d4a2ea2efa383a422f7f4e303c125 Mon Sep 17 00:00:00 2001 From: MikuroXina Date: Sat, 4 Dec 2021 16:46:39 +0900 Subject: [PATCH 237/942] Add BindgenError --- src/lib.rs | 94 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 80 insertions(+), 14 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index f3912e8e5b..4ff72cc84f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1444,6 +1444,7 @@ impl Builder { } /// Generate the Rust bindings using the options built up thus far. + #[deprecated(since = "0.59.3", note = "please use `gen` instead")] pub fn generate(mut self) -> Result { // Add any extra arguments from the environment to the clang command line. if let Some(extra_clang_args) = @@ -1475,6 +1476,41 @@ impl Builder { }), ); + Bindings::generate(self.options).map_err(|_| ()) + } + + /// Generate the Rust bindings using the options built up thus far, or `Err` on failure. + pub fn gen(mut self) -> Result { + // Add any extra arguments from the environment to the clang command line. + if let Some(extra_clang_args) = + get_target_dependent_env_var("BINDGEN_EXTRA_CLANG_ARGS") + { + // Try to parse it with shell quoting. If we fail, make it one single big argument. + if let Some(strings) = shlex::split(&extra_clang_args) { + self.options.clang_args.extend(strings); + } else { + self.options.clang_args.push(extra_clang_args); + }; + } + + // Transform input headers to arguments on the clang command line. + self.options.input_header = self.input_headers.pop(); + self.options.extra_input_headers = self.input_headers; + self.options.clang_args.extend( + self.options.extra_input_headers.iter().flat_map(|header| { + iter::once("-include".into()) + .chain(iter::once(header.to_string())) + }), + ); + + self.options.input_unsaved_files.extend( + self.input_header_contents + .drain(..) + .map(|(name, contents)| { + clang::UnsavedFile::new(&name, &contents) + }), + ); + Bindings::generate(self.options) } @@ -2146,6 +2182,28 @@ fn ensure_libclang_is_loaded() { #[cfg(not(feature = "runtime"))] fn ensure_libclang_is_loaded() {} +/// Error type for rust-bindgen. +#[derive(Debug)] +pub enum BindgenError { + /// Any provided header was invalid. + InvalidHeader(String), + /// Clang diagnosed an error. + ClangDiagnostic(String), +} + +impl std::fmt::Display for BindgenError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + BindgenError::InvalidHeader(message) => { + write!(f, "invalid header: {}", message) + } + BindgenError::ClangDiagnostic(message) => { + write!(f, "clang diagnosed error: {}", message) + } + } + } +} + /// Generated Rust bindings. #[derive(Debug)] pub struct Bindings { @@ -2202,7 +2260,7 @@ impl Bindings { /// Generate bindings for the given options. pub(crate) fn generate( mut options: BindgenOptions, - ) -> Result { + ) -> Result { ensure_libclang_is_loaded(); #[cfg(feature = "runtime")] @@ -2322,20 +2380,23 @@ impl Bindings { if let Some(h) = options.input_header.as_ref() { if let Ok(md) = std::fs::metadata(h) { if md.is_dir() { - eprintln!("error: '{}' is a folder", h); - return Err(()); + return Err(BindgenError::InvalidHeader(format!( + "error: '{}' is a folder", + h + ))); } if !can_read(&md.permissions()) { - eprintln!( + return Err(BindgenError::InvalidHeader(format!( "error: insufficient permissions to read '{}'", h - ); - return Err(()); + ))); } options.clang_args.push(h.clone()) } else { - eprintln!("error: header '{}' does not exist.", h); - return Err(()); + return Err(BindgenError::InvalidHeader(format!( + "error: header '{}' does not exist.", + h + ))); } } @@ -2556,19 +2617,24 @@ fn parse_one( } /// Parse the Clang AST into our `Item` internal representation. -fn parse(context: &mut BindgenContext) -> Result<(), ()> { +fn parse(context: &mut BindgenContext) -> Result<(), BindgenError> { use clang_sys::*; - let mut any_error = false; + let mut error = None; for d in context.translation_unit().diags().iter() { let msg = d.format(); let is_err = d.severity() >= CXDiagnostic_Error; - eprintln!("{}, err: {}", msg, is_err); - any_error |= is_err; + if is_err { + let error = error.get_or_insert_with(String::new); + error.push_str(&msg); + error.push('\n'); + } else { + eprintln!("clang diag: {}", msg); + } } - if any_error { - return Err(()); + if let Some(message) = error { + return Err(BindgenError::ClangDiagnostic(message)); } let cursor = context.translation_unit().cursor(); From c97169673b2371ae1791fb41c9d30372796b59bf Mon Sep 17 00:00:00 2001 From: MikuroXina Date: Sat, 4 Dec 2021 16:53:35 +0900 Subject: [PATCH 238/942] Impl Error trait for BindgenError --- src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 4ff72cc84f..76841427dd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2204,6 +2204,8 @@ impl std::fmt::Display for BindgenError { } } +impl std::error::Error for BindgenError {} + /// Generated Rust bindings. #[derive(Debug)] pub struct Bindings { From 66cc4598e4ca760db17ddbdf5202b3e20f8e5ae9 Mon Sep 17 00:00:00 2001 From: MikuroXina Date: Sat, 4 Dec 2021 16:56:05 +0900 Subject: [PATCH 239/942] Replace generate with gen in test --- .github/ISSUE_TEMPLATE.md | 2 +- bindgen-integration/build.rs | 2 +- book/src/tutorial-3.md | 2 +- src/lib.rs | 10 +++++----- src/main.rs | 4 ++-- tests/stylo_sanity.rs | 2 +- tests/tests.rs | 18 +++++++++--------- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 442e078699..86785dbb69 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -24,7 +24,7 @@ ```Rust bindgen::Builder::default() .header("input.h") - .generate() + .gen() .unwrap() ``` diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs index 77ea64b581..76778379a2 100644 --- a/bindgen-integration/build.rs +++ b/bindgen-integration/build.rs @@ -185,7 +185,7 @@ fn main() { .constified_enum("my_prefixed_enum_to_be_constified") .opaque_type("my_prefixed_templated_foo") .depfile(out_rust_file_relative.display().to_string(), &out_dep_file) - .generate() + .gen() .expect("Unable to generate bindings"); assert!(macros.read().unwrap().contains("TESTMACRO")); diff --git a/book/src/tutorial-3.md b/book/src/tutorial-3.md index 139a24f9a3..d4152ca29d 100644 --- a/book/src/tutorial-3.md +++ b/book/src/tutorial-3.md @@ -32,7 +32,7 @@ fn main() { // included header files changed. .parse_callbacks(Box::new(bindgen::CargoCallbacks)) // Finish the builder and generate the bindings. - .generate() + .gen() // Unwrap the Result and panic on failure. .expect("Unable to generate bindings"); diff --git a/src/lib.rs b/src/lib.rs index 76841427dd..01fd027f30 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -180,7 +180,7 @@ impl Default for CodegenConfig { /// let bindings = builder().header("path/to/input/header") /// .allowlist_type("SomeCoolClass") /// .allowlist_function("do_some_cool_thing") -/// .generate()?; +/// .gen()?; /// /// // Write the generated bindings to an output file. /// bindings.write_to_file("path/to/output.rs")?; @@ -247,7 +247,7 @@ impl Builder { // FIXME(emilio): This is a bit hacky, maybe we should stop re-using the // RustFeatures to store the "disable_untagged_union" call, and make it - // a different flag that we check elsewhere / in generate(). + // a different flag that we check elsewhere / in gen(). if !self.options.rust_features.untagged_union && RustFeatures::from(self.options.rust_target).untagged_union { @@ -595,7 +595,7 @@ impl Builder { /// ```ignore /// let bindings = bindgen::Builder::default() /// .header("input.h") - /// .generate() + /// .gen() /// .unwrap(); /// ``` /// @@ -607,7 +607,7 @@ impl Builder { /// .header("first.h") /// .header("second.h") /// .header("third.h") - /// .generate() + /// .gen() /// .unwrap(); /// ``` pub fn header>(mut self, header: T) -> Builder { @@ -2726,7 +2726,7 @@ fn get_target_dependent_env_var(var: &str) -> Option { /// let bindings = builder() /// .header("path/to/input/header") /// .parse_callbacks(Box::new(bindgen::CargoCallbacks)) -/// .generate(); +/// .gen(); /// ``` #[derive(Debug)] pub struct CargoCallbacks; diff --git a/src/main.rs b/src/main.rs index f3398db890..d8472fdbef 100644 --- a/src/main.rs +++ b/src/main.rs @@ -49,7 +49,7 @@ pub fn main() { Ok((builder, output, verbose)) => { clang_version_check(); let builder_result = panic::catch_unwind(|| { - builder.generate().expect("Unable to generate bindings") + builder.gen().expect("Unable to generate bindings") }); if builder_result.is_err() { @@ -99,7 +99,7 @@ mod test { let (builder, _output, _verbose) = crate::options::builder_from_flags(command_line_flags.into_iter()) .unwrap(); - builder.generate().expect("failed to generate bindings"); + builder.gen().expect("failed to generate bindings"); } #[test] diff --git a/tests/stylo_sanity.rs b/tests/stylo_sanity.rs index 39777cd154..93b1147318 100755 --- a/tests/stylo_sanity.rs +++ b/tests/stylo_sanity.rs @@ -540,7 +540,7 @@ fn sanity_check_can_generate_stylo_bindings() { .clang_arg("-DMOZ_STYLO") .clang_arg("-DOS_POSIX=1") .clang_arg("-DOS_LINUX=1") - .generate() + .gen() .expect("Should generate stylo bindings"); let now = Instant::now(); diff --git a/tests/tests.rs b/tests/tests.rs index a62fe42fa4..08781d46f8 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -193,13 +193,13 @@ fn compare_generated_header( let (builder, roundtrip_builder) = builder.into_builder(check_roundtrip)?; - // We skip the generate() error here so we get a full diff below - let (actual, rustfmt_stderr) = match builder.generate() { + // We skip the gen() error here so we get a full diff below + let (actual, rustfmt_stderr) = match builder.gen() { Ok(bindings) => { let actual = bindings.to_string(); rustfmt(actual) } - Err(()) => ("".to_string(), "".to_string()), + Err(_) => ("".to_string(), "".to_string()), }; println!("{}", rustfmt_stderr); @@ -426,7 +426,7 @@ fn test_clang_env_args() { #ifdef _ENV_TWO\nextern const int y[] = { 42 };\n#endif\n\ #ifdef NOT_THREE\nextern const int z[] = { 42 };\n#endif\n", ) - .generate() + .gen() .unwrap() .to_string(); @@ -453,7 +453,7 @@ fn test_header_contents() { .disable_header_comment() .header_contents("test.h", "int foo(const char* a);") .clang_arg("--target=x86_64-unknown-linux") - .generate() + .gen() .unwrap() .to_string(); @@ -480,7 +480,7 @@ fn test_multiple_header_calls_in_builder() { )) .header(concat!(env!("CARGO_MANIFEST_DIR"), "/tests/headers/char.h")) .clang_arg("--target=x86_64-unknown-linux") - .generate() + .gen() .unwrap() .to_string(); @@ -514,7 +514,7 @@ fn test_multiple_header_contents() { .header_contents("test.h", "int foo(const char* a);") .header_contents("test2.h", "float foo2(const char* b);") .clang_arg("--target=x86_64-unknown-linux") - .generate() + .gen() .unwrap() .to_string(); @@ -546,7 +546,7 @@ fn test_mixed_header_and_header_contents() { .header_contents("test.h", "int bar(const char* a);") .header_contents("test2.h", "float bar2(const char* b);") .clang_arg("--target=x86_64-unknown-linux") - .generate() + .gen() .unwrap() .to_string(); @@ -596,7 +596,7 @@ fn emit_depfile() { env::var_os("BINDGEN_DISABLE_ROUNDTRIP_TEST").is_none(); let (builder, _roundtrip_builder) = builder.into_builder(check_roundtrip).unwrap(); - let _bindings = builder.generate().unwrap(); + let _bindings = builder.gen().unwrap(); let observed = std::fs::read_to_string(observed_depfile).unwrap(); let expected = std::fs::read_to_string(expected_depfile).unwrap(); From b5e39bce5d34ff25f8ce8a99d803ae2286fd2a49 Mon Sep 17 00:00:00 2001 From: MikuroXina Date: Sat, 4 Dec 2021 16:58:26 +0900 Subject: [PATCH 240/942] Merge into new one --- src/lib.rs | 34 ++-------------------------------- 1 file changed, 2 insertions(+), 32 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 01fd027f30..a95c433a4c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1445,38 +1445,8 @@ impl Builder { /// Generate the Rust bindings using the options built up thus far. #[deprecated(since = "0.59.3", note = "please use `gen` instead")] - pub fn generate(mut self) -> Result { - // Add any extra arguments from the environment to the clang command line. - if let Some(extra_clang_args) = - get_target_dependent_env_var("BINDGEN_EXTRA_CLANG_ARGS") - { - // Try to parse it with shell quoting. If we fail, make it one single big argument. - if let Some(strings) = shlex::split(&extra_clang_args) { - self.options.clang_args.extend(strings); - } else { - self.options.clang_args.push(extra_clang_args); - }; - } - - // Transform input headers to arguments on the clang command line. - self.options.input_header = self.input_headers.pop(); - self.options.extra_input_headers = self.input_headers; - self.options.clang_args.extend( - self.options.extra_input_headers.iter().flat_map(|header| { - iter::once("-include".into()) - .chain(iter::once(header.to_string())) - }), - ); - - self.options.input_unsaved_files.extend( - self.input_header_contents - .drain(..) - .map(|(name, contents)| { - clang::UnsavedFile::new(&name, &contents) - }), - ); - - Bindings::generate(self.options).map_err(|_| ()) + pub fn generate(self) -> Result { + self.gen().map_err(|_| ()) } /// Generate the Rust bindings using the options built up thus far, or `Err` on failure. From c9495faa483b1ddb741cde046407f33184f728cd Mon Sep 17 00:00:00 2001 From: MikuroXina Date: Sat, 4 Dec 2021 17:04:46 +0900 Subject: [PATCH 241/942] Remove 'error: ' part --- src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index a95c433a4c..d897248c9d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2353,20 +2353,20 @@ impl Bindings { if let Ok(md) = std::fs::metadata(h) { if md.is_dir() { return Err(BindgenError::InvalidHeader(format!( - "error: '{}' is a folder", + "'{}' is a folder", h ))); } if !can_read(&md.permissions()) { return Err(BindgenError::InvalidHeader(format!( - "error: insufficient permissions to read '{}'", + "insufficient permissions to read '{}'", h ))); } options.clang_args.push(h.clone()) } else { return Err(BindgenError::InvalidHeader(format!( - "error: header '{}' does not exist.", + "header '{}' does not exist.", h ))); } From 5685440dbb0040e784d752770d38012850c22a1a Mon Sep 17 00:00:00 2001 From: MikuroXina Date: Sun, 5 Dec 2021 09:51:30 +0900 Subject: [PATCH 242/942] Add non_exhaustive --- src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.rs b/src/lib.rs index d897248c9d..f7b7dd935e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2154,6 +2154,7 @@ fn ensure_libclang_is_loaded() {} /// Error type for rust-bindgen. #[derive(Debug)] +#[non_exhaustive] pub enum BindgenError { /// Any provided header was invalid. InvalidHeader(String), From 24cfccd9c5d1d4b4be9bfba3c28c758486fe15cd Mon Sep 17 00:00:00 2001 From: MikuroXina Date: Wed, 8 Dec 2021 09:10:05 +0900 Subject: [PATCH 243/942] Remove deprecation and Replace --- .github/ISSUE_TEMPLATE.md | 2 +- bindgen-integration/build.rs | 2 +- book/src/tutorial-3.md | 2 +- src/lib.rs | 18 ++++++------------ src/main.rs | 4 ++-- tests/stylo_sanity.rs | 2 +- tests/tests.rs | 16 ++++++++-------- 7 files changed, 20 insertions(+), 26 deletions(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 86785dbb69..442e078699 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -24,7 +24,7 @@ ```Rust bindgen::Builder::default() .header("input.h") - .gen() + .generate() .unwrap() ``` diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs index 76778379a2..77ea64b581 100644 --- a/bindgen-integration/build.rs +++ b/bindgen-integration/build.rs @@ -185,7 +185,7 @@ fn main() { .constified_enum("my_prefixed_enum_to_be_constified") .opaque_type("my_prefixed_templated_foo") .depfile(out_rust_file_relative.display().to_string(), &out_dep_file) - .gen() + .generate() .expect("Unable to generate bindings"); assert!(macros.read().unwrap().contains("TESTMACRO")); diff --git a/book/src/tutorial-3.md b/book/src/tutorial-3.md index d4152ca29d..139a24f9a3 100644 --- a/book/src/tutorial-3.md +++ b/book/src/tutorial-3.md @@ -32,7 +32,7 @@ fn main() { // included header files changed. .parse_callbacks(Box::new(bindgen::CargoCallbacks)) // Finish the builder and generate the bindings. - .gen() + .generate() // Unwrap the Result and panic on failure. .expect("Unable to generate bindings"); diff --git a/src/lib.rs b/src/lib.rs index f7b7dd935e..1c88cb88b3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -180,7 +180,7 @@ impl Default for CodegenConfig { /// let bindings = builder().header("path/to/input/header") /// .allowlist_type("SomeCoolClass") /// .allowlist_function("do_some_cool_thing") -/// .gen()?; +/// .generate()?; /// /// // Write the generated bindings to an output file. /// bindings.write_to_file("path/to/output.rs")?; @@ -247,7 +247,7 @@ impl Builder { // FIXME(emilio): This is a bit hacky, maybe we should stop re-using the // RustFeatures to store the "disable_untagged_union" call, and make it - // a different flag that we check elsewhere / in gen(). + // a different flag that we check elsewhere / in generate(). if !self.options.rust_features.untagged_union && RustFeatures::from(self.options.rust_target).untagged_union { @@ -595,7 +595,7 @@ impl Builder { /// ```ignore /// let bindings = bindgen::Builder::default() /// .header("input.h") - /// .gen() + /// .generate() /// .unwrap(); /// ``` /// @@ -607,7 +607,7 @@ impl Builder { /// .header("first.h") /// .header("second.h") /// .header("third.h") - /// .gen() + /// .generate() /// .unwrap(); /// ``` pub fn header>(mut self, header: T) -> Builder { @@ -1444,13 +1444,7 @@ impl Builder { } /// Generate the Rust bindings using the options built up thus far. - #[deprecated(since = "0.59.3", note = "please use `gen` instead")] - pub fn generate(self) -> Result { - self.gen().map_err(|_| ()) - } - - /// Generate the Rust bindings using the options built up thus far, or `Err` on failure. - pub fn gen(mut self) -> Result { + pub fn generate(mut self) -> Result { // Add any extra arguments from the environment to the clang command line. if let Some(extra_clang_args) = get_target_dependent_env_var("BINDGEN_EXTRA_CLANG_ARGS") @@ -2697,7 +2691,7 @@ fn get_target_dependent_env_var(var: &str) -> Option { /// let bindings = builder() /// .header("path/to/input/header") /// .parse_callbacks(Box::new(bindgen::CargoCallbacks)) -/// .gen(); +/// .generate(); /// ``` #[derive(Debug)] pub struct CargoCallbacks; diff --git a/src/main.rs b/src/main.rs index d8472fdbef..f3398db890 100644 --- a/src/main.rs +++ b/src/main.rs @@ -49,7 +49,7 @@ pub fn main() { Ok((builder, output, verbose)) => { clang_version_check(); let builder_result = panic::catch_unwind(|| { - builder.gen().expect("Unable to generate bindings") + builder.generate().expect("Unable to generate bindings") }); if builder_result.is_err() { @@ -99,7 +99,7 @@ mod test { let (builder, _output, _verbose) = crate::options::builder_from_flags(command_line_flags.into_iter()) .unwrap(); - builder.gen().expect("failed to generate bindings"); + builder.generate().expect("failed to generate bindings"); } #[test] diff --git a/tests/stylo_sanity.rs b/tests/stylo_sanity.rs index 93b1147318..39777cd154 100755 --- a/tests/stylo_sanity.rs +++ b/tests/stylo_sanity.rs @@ -540,7 +540,7 @@ fn sanity_check_can_generate_stylo_bindings() { .clang_arg("-DMOZ_STYLO") .clang_arg("-DOS_POSIX=1") .clang_arg("-DOS_LINUX=1") - .gen() + .generate() .expect("Should generate stylo bindings"); let now = Instant::now(); diff --git a/tests/tests.rs b/tests/tests.rs index 08781d46f8..ac0106ad17 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -193,8 +193,8 @@ fn compare_generated_header( let (builder, roundtrip_builder) = builder.into_builder(check_roundtrip)?; - // We skip the gen() error here so we get a full diff below - let (actual, rustfmt_stderr) = match builder.gen() { + // We skip the generate() error here so we get a full diff below + let (actual, rustfmt_stderr) = match builder.generate() { Ok(bindings) => { let actual = bindings.to_string(); rustfmt(actual) @@ -426,7 +426,7 @@ fn test_clang_env_args() { #ifdef _ENV_TWO\nextern const int y[] = { 42 };\n#endif\n\ #ifdef NOT_THREE\nextern const int z[] = { 42 };\n#endif\n", ) - .gen() + .generate() .unwrap() .to_string(); @@ -453,7 +453,7 @@ fn test_header_contents() { .disable_header_comment() .header_contents("test.h", "int foo(const char* a);") .clang_arg("--target=x86_64-unknown-linux") - .gen() + .generate() .unwrap() .to_string(); @@ -480,7 +480,7 @@ fn test_multiple_header_calls_in_builder() { )) .header(concat!(env!("CARGO_MANIFEST_DIR"), "/tests/headers/char.h")) .clang_arg("--target=x86_64-unknown-linux") - .gen() + .generate() .unwrap() .to_string(); @@ -514,7 +514,7 @@ fn test_multiple_header_contents() { .header_contents("test.h", "int foo(const char* a);") .header_contents("test2.h", "float foo2(const char* b);") .clang_arg("--target=x86_64-unknown-linux") - .gen() + .generate() .unwrap() .to_string(); @@ -546,7 +546,7 @@ fn test_mixed_header_and_header_contents() { .header_contents("test.h", "int bar(const char* a);") .header_contents("test2.h", "float bar2(const char* b);") .clang_arg("--target=x86_64-unknown-linux") - .gen() + .generate() .unwrap() .to_string(); @@ -596,7 +596,7 @@ fn emit_depfile() { env::var_os("BINDGEN_DISABLE_ROUNDTRIP_TEST").is_none(); let (builder, _roundtrip_builder) = builder.into_builder(check_roundtrip).unwrap(); - let _bindings = builder.gen().unwrap(); + let _bindings = builder.generate().unwrap(); let observed = std::fs::read_to_string(observed_depfile).unwrap(); let expected = std::fs::read_to_string(expected_depfile).unwrap(); From fc5ac7b4397b5a90ae0a045d672455ecce5dc485 Mon Sep 17 00:00:00 2001 From: MikuroXina Date: Wed, 8 Dec 2021 13:49:54 +0900 Subject: [PATCH 244/942] More detailed error --- src/lib.rs | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1c88cb88b3..e5ebd80468 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2150,8 +2150,12 @@ fn ensure_libclang_is_loaded() {} #[derive(Debug)] #[non_exhaustive] pub enum BindgenError { - /// Any provided header was invalid. - InvalidHeader(String), + /// The header was a folder. + FolderAsHeader(String), + /// Permissions to read the header is insufficient. + InsufficientPermissions(String), + /// The header does not exist. + NotExist(String), /// Clang diagnosed an error. ClangDiagnostic(String), } @@ -2159,8 +2163,12 @@ pub enum BindgenError { impl std::fmt::Display for BindgenError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - BindgenError::InvalidHeader(message) => { - write!(f, "invalid header: {}", message) + BindgenError::FolderAsHeader(h) => write!(f, "'{}' is a folder", h), + BindgenError::InsufficientPermissions(h) => { + write!(f, "insufficient permissions to read '{}'", h) + } + BindgenError::NotExist(h) => { + write!(f, "header '{}' does not exist.", h) } BindgenError::ClangDiagnostic(message) => { write!(f, "clang diagnosed error: {}", message) @@ -2347,23 +2355,16 @@ impl Bindings { if let Some(h) = options.input_header.as_ref() { if let Ok(md) = std::fs::metadata(h) { if md.is_dir() { - return Err(BindgenError::InvalidHeader(format!( - "'{}' is a folder", - h - ))); + return Err(BindgenError::FolderAsHeader(h.into())); } if !can_read(&md.permissions()) { - return Err(BindgenError::InvalidHeader(format!( - "insufficient permissions to read '{}'", - h - ))); + return Err(BindgenError::InsufficientPermissions( + h.into(), + )); } options.clang_args.push(h.clone()) } else { - return Err(BindgenError::InvalidHeader(format!( - "header '{}' does not exist.", - h - ))); + return Err(BindgenError::NotExist(h.into())); } } From 0d95ea126a49fbcb15a7b9261a34b20f81bf9970 Mon Sep 17 00:00:00 2001 From: MikuroXina Date: Wed, 8 Dec 2021 13:51:57 +0900 Subject: [PATCH 245/942] Derive some traits --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index e5ebd80468..b93c6ef095 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2147,7 +2147,7 @@ fn ensure_libclang_is_loaded() { fn ensure_libclang_is_loaded() {} /// Error type for rust-bindgen. -#[derive(Debug)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[non_exhaustive] pub enum BindgenError { /// The header was a folder. From e24afad6a16b0940baadebc937be9461fdccdc0f Mon Sep 17 00:00:00 2001 From: MikuroXina Date: Thu, 9 Dec 2021 09:50:21 +0900 Subject: [PATCH 246/942] Change into PathBuf --- src/lib.rs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b93c6ef095..39f55f04ff 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2151,11 +2151,11 @@ fn ensure_libclang_is_loaded() {} #[non_exhaustive] pub enum BindgenError { /// The header was a folder. - FolderAsHeader(String), + FolderAsHeader(PathBuf), /// Permissions to read the header is insufficient. - InsufficientPermissions(String), + InsufficientPermissions(PathBuf), /// The header does not exist. - NotExist(String), + NotExist(PathBuf), /// Clang diagnosed an error. ClangDiagnostic(String), } @@ -2163,12 +2163,14 @@ pub enum BindgenError { impl std::fmt::Display for BindgenError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - BindgenError::FolderAsHeader(h) => write!(f, "'{}' is a folder", h), + BindgenError::FolderAsHeader(h) => { + write!(f, "'{}' is a folder", h.display()) + } BindgenError::InsufficientPermissions(h) => { - write!(f, "insufficient permissions to read '{}'", h) + write!(f, "insufficient permissions to read '{}'", h.display()) } BindgenError::NotExist(h) => { - write!(f, "header '{}' does not exist.", h) + write!(f, "header '{}' does not exist.", h.display()) } BindgenError::ClangDiagnostic(message) => { write!(f, "clang diagnosed error: {}", message) @@ -2353,18 +2355,19 @@ impl Bindings { } if let Some(h) = options.input_header.as_ref() { - if let Ok(md) = std::fs::metadata(h) { + let path = Path::new(h); + if let Ok(md) = std::fs::metadata(path) { if md.is_dir() { - return Err(BindgenError::FolderAsHeader(h.into())); + return Err(BindgenError::FolderAsHeader(path.into())); } if !can_read(&md.permissions()) { return Err(BindgenError::InsufficientPermissions( - h.into(), + path.into(), )); } options.clang_args.push(h.clone()) } else { - return Err(BindgenError::NotExist(h.into())); + return Err(BindgenError::NotExist(path.into())); } } From e755ea4a6d9aee386223a027f2d251b836275515 Mon Sep 17 00:00:00 2001 From: "Dr. Chat" Date: Fri, 24 Dec 2021 14:12:13 -0600 Subject: [PATCH 247/942] Extremely basic Vtable generation --- src/codegen/mod.rs | 66 +++++++-- tests/expectations/tests/virtual_interface.rs | 125 ++++++++++++++++++ tests/headers/virtual_interface.hpp | 24 ++++ 3 files changed, 207 insertions(+), 8 deletions(-) create mode 100644 tests/expectations/tests/virtual_interface.rs create mode 100644 tests/headers/virtual_interface.hpp diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index bee299edfc..7b72722a26 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -1049,15 +1049,65 @@ impl<'a> CodeGenerator for Vtable<'a> { ) { assert_eq!(item.id(), self.item_id); debug_assert!(item.is_enabled_for_codegen(ctx)); - - // For now, generate an empty struct, later we should generate function - // pointers and whatnot. let name = ctx.rust_ident(&self.canonical_name(ctx)); - let void = helpers::ast_ty::c_void(ctx); - result.push(quote! { - #[repr(C)] - pub struct #name ( #void ); - }); + + // For now, we will only generate vtables for classes that do not inherit from others. + if self.base_classes.is_empty() { + let methods = self + .methods + .iter() + .filter_map(|m| { + if !m.is_virtual() { + return None; + } + + let function_item = ctx.resolve_item(m.signature()); + if !function_item.process_before_codegen(ctx, result) { + return None; + } + + let function = function_item.expect_function(); + let signature_item = ctx.resolve_item(function.signature()); + let signature = match signature_item.expect_type().kind() { + TypeKind::Function(ref sig) => sig, + _ => panic!("Function signature type mismatch"), + }; + + // FIXME: Is there a canonical name without the class prepended? + let function_name = function_item.canonical_name(ctx); + + // FIXME: Need to account for overloading with times_seen (separately from regular function path). + let function_name = ctx.rust_ident(function_name); + let mut args = utils::fnsig_arguments(ctx, signature); + let ret = utils::fnsig_return_ty(ctx, signature); + + args[0] = if m.is_const() { + quote! { &self } + } else { + quote! { &mut self } + }; + + Some(quote! { + #function_name : fn( #( #args ),* ) #ret + }) + }) + .collect::>(); + + result.push(quote! { + #[repr(C)] + pub struct #name { + #( #methods ),* + } + }) + } else { + // For the cases we don't support, simply generate an empty struct. + let void = helpers::ast_ty::c_void(ctx); + + result.push(quote! { + #[repr(C)] + pub struct #name ( #void ); + }); + } } } diff --git a/tests/expectations/tests/virtual_interface.rs b/tests/expectations/tests/virtual_interface.rs new file mode 100644 index 0000000000..5d4f1bbc04 --- /dev/null +++ b/tests/expectations/tests/virtual_interface.rs @@ -0,0 +1,125 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +pub struct PureVirtualIFace__bindgen_vtable { + PureVirtualIFace_Foo: fn(&mut self), + PureVirtualIFace_Bar: fn(&mut self, arg1: ::std::os::raw::c_uint), +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct PureVirtualIFace { + pub vtable_: *const PureVirtualIFace__bindgen_vtable, +} +#[test] +fn bindgen_test_layout_PureVirtualIFace() { + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(PureVirtualIFace)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(PureVirtualIFace)) + ); +} +impl Default for PureVirtualIFace { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] +pub struct AnotherInterface__bindgen_vtable { + AnotherInterface_Baz: fn(&mut self), +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct AnotherInterface { + pub vtable_: *const AnotherInterface__bindgen_vtable, +} +#[test] +fn bindgen_test_layout_AnotherInterface() { + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(AnotherInterface)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(AnotherInterface)) + ); +} +impl Default for AnotherInterface { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct Implementation { + pub _base: PureVirtualIFace, +} +#[test] +fn bindgen_test_layout_Implementation() { + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Implementation)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Implementation)) + ); +} +impl Default for Implementation { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct DoubleImpl { + pub _base: PureVirtualIFace, + pub _base_1: AnotherInterface, +} +#[test] +fn bindgen_test_layout_DoubleImpl() { + assert_eq!( + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(DoubleImpl)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(DoubleImpl)) + ); +} +impl Default for DoubleImpl { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} diff --git a/tests/headers/virtual_interface.hpp b/tests/headers/virtual_interface.hpp new file mode 100644 index 0000000000..00ab0737b7 --- /dev/null +++ b/tests/headers/virtual_interface.hpp @@ -0,0 +1,24 @@ +class PureVirtualIFace { +public: + virtual void Foo() = 0; + virtual void Bar(unsigned int) = 0; +}; + +class AnotherInterface { +public: + virtual void Baz() = 0; +}; + +class Implementation : public PureVirtualIFace { +public: + void Foo() override {} + void Bar(unsigned int) override {} +}; + +class DoubleImpl : public PureVirtualIFace, public AnotherInterface { +public: + void Foo() override {} + void Bar(unsigned int) override {} + + void Baz() override {} +}; From acfc9ac95b65542a5172af383bdbb658dcd07187 Mon Sep 17 00:00:00 2001 From: "Dr. Chat" Date: Wed, 29 Dec 2021 22:47:33 -0600 Subject: [PATCH 248/942] Pass the vtable's base class as the first parameter --- src/codegen/mod.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 7b72722a26..c78010308f 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -1050,6 +1050,7 @@ impl<'a> CodeGenerator for Vtable<'a> { assert_eq!(item.id(), self.item_id); debug_assert!(item.is_enabled_for_codegen(ctx)); let name = ctx.rust_ident(&self.canonical_name(ctx)); + let class_ident = ctx.rust_ident(self.item_id.canonical_name(ctx)); // For now, we will only generate vtables for classes that do not inherit from others. if self.base_classes.is_empty() { @@ -1062,10 +1063,6 @@ impl<'a> CodeGenerator for Vtable<'a> { } let function_item = ctx.resolve_item(m.signature()); - if !function_item.process_before_codegen(ctx, result) { - return None; - } - let function = function_item.expect_function(); let signature_item = ctx.resolve_item(function.signature()); let signature = match signature_item.expect_type().kind() { @@ -1082,9 +1079,9 @@ impl<'a> CodeGenerator for Vtable<'a> { let ret = utils::fnsig_return_ty(ctx, signature); args[0] = if m.is_const() { - quote! { &self } + quote! { this: & #class_ident } } else { - quote! { &mut self } + quote! { this: &mut #class_ident } }; Some(quote! { From 604792310e19899f2c6d34e382de3b55678a8550 Mon Sep 17 00:00:00 2001 From: "Dr. Chat" Date: Thu, 30 Dec 2021 00:29:15 -0600 Subject: [PATCH 249/942] Account for virtual destructors --- src/codegen/mod.rs | 36 +++++++++---------- .../tests/enum_and_vtable_mangling.rs | 4 ++- ...from-template-instantiation-with-vtable.rs | 2 +- .../tests/issue-1197-pure-virtual-stuff.rs | 5 ++- .../issue-691-template-parameter-virtual.rs | 2 +- tests/expectations/tests/nested_vtable.rs | 4 ++- tests/expectations/tests/packed-vtable.rs | 4 ++- .../expectations/tests/ref_argument_array.rs | 5 ++- tests/expectations/tests/virtual_dtor.rs | 4 ++- tests/expectations/tests/virtual_interface.rs | 7 ++-- .../expectations/tests/virtual_overloaded.rs | 5 ++- .../tests/vtable_recursive_sig.rs | 4 ++- 12 files changed, 49 insertions(+), 33 deletions(-) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index c78010308f..2b10b3debf 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -21,8 +21,8 @@ use crate::ir::analysis::{HasVtable, Sizedness}; use crate::ir::annotations::FieldAccessorKind; use crate::ir::comment; use crate::ir::comp::{ - Base, Bitfield, BitfieldUnit, CompInfo, CompKind, Field, FieldData, - FieldMethods, Method, MethodKind, + Bitfield, BitfieldUnit, CompInfo, CompKind, Field, FieldData, FieldMethods, + Method, MethodKind, }; use crate::ir::context::{BindgenContext, ItemId}; use crate::ir::derive::{ @@ -1017,23 +1017,14 @@ impl CodeGenerator for Type { struct Vtable<'a> { item_id: ItemId, + /// A reference to the originating compound object. #[allow(dead_code)] - methods: &'a [Method], - #[allow(dead_code)] - base_classes: &'a [Base], + comp_info: &'a CompInfo, } impl<'a> Vtable<'a> { - fn new( - item_id: ItemId, - methods: &'a [Method], - base_classes: &'a [Base], - ) -> Self { - Vtable { - item_id, - methods, - base_classes, - } + fn new(item_id: ItemId, comp_info: &'a CompInfo) -> Self { + Vtable { item_id, comp_info } } } @@ -1053,10 +1044,16 @@ impl<'a> CodeGenerator for Vtable<'a> { let class_ident = ctx.rust_ident(self.item_id.canonical_name(ctx)); // For now, we will only generate vtables for classes that do not inherit from others. - if self.base_classes.is_empty() { - let methods = self - .methods + if self.comp_info.base_members().is_empty() { + // Map the destructor into a Method, and chain it into the below iteration. + let dtor = self + .comp_info + .destructor() + .map(|(kind, id)| Method::new(kind, id, false)); + + let methods = dtor .iter() + .chain(self.comp_info.methods().iter()) .filter_map(|m| { if !m.is_virtual() { return None; @@ -1796,8 +1793,7 @@ impl CodeGenerator for CompInfo { if !is_opaque { if item.has_vtable_ptr(ctx) { - let vtable = - Vtable::new(item.id(), self.methods(), self.base_members()); + let vtable = Vtable::new(item.id(), &self); vtable.codegen(ctx, result, item); let vtable_type = vtable diff --git a/tests/expectations/tests/enum_and_vtable_mangling.rs b/tests/expectations/tests/enum_and_vtable_mangling.rs index 9e9c6bcb2f..c0414c376f 100644 --- a/tests/expectations/tests/enum_and_vtable_mangling.rs +++ b/tests/expectations/tests/enum_and_vtable_mangling.rs @@ -14,7 +14,9 @@ pub enum _bindgen_ty_1 { whatever_else = 1, } #[repr(C)] -pub struct C__bindgen_vtable(::std::os::raw::c_void); +pub struct C__bindgen_vtable { + C_match: fn(this: &mut C), +} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct C { diff --git a/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs b/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs index f292125d1c..0876878efc 100644 --- a/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs +++ b/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs @@ -6,7 +6,7 @@ )] #[repr(C)] -pub struct BaseWithVtable__bindgen_vtable(::std::os::raw::c_void); +pub struct BaseWithVtable__bindgen_vtable {} /// This should have an explicit vtable. #[repr(C)] #[derive(Debug, Copy, Clone)] diff --git a/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs b/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs index fd023363d7..80606c2aa0 100644 --- a/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs +++ b/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs @@ -6,7 +6,10 @@ )] #[repr(C)] -pub struct Foo__bindgen_vtable(::std::os::raw::c_void); +pub struct Foo__bindgen_vtable { + Foo_Foo_destructor: fn(this: &mut Foo), + Foo_Bar: fn(this: &mut Foo), +} #[repr(C)] #[derive(Debug)] pub struct Foo { diff --git a/tests/expectations/tests/issue-691-template-parameter-virtual.rs b/tests/expectations/tests/issue-691-template-parameter-virtual.rs index 4747b955a3..e71b2aae91 100644 --- a/tests/expectations/tests/issue-691-template-parameter-virtual.rs +++ b/tests/expectations/tests/issue-691-template-parameter-virtual.rs @@ -6,7 +6,7 @@ )] #[repr(C)] -pub struct VirtualMethods__bindgen_vtable(::std::os::raw::c_void); +pub struct VirtualMethods__bindgen_vtable {} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct VirtualMethods { diff --git a/tests/expectations/tests/nested_vtable.rs b/tests/expectations/tests/nested_vtable.rs index 021877763b..2b0f259919 100644 --- a/tests/expectations/tests/nested_vtable.rs +++ b/tests/expectations/tests/nested_vtable.rs @@ -6,7 +6,9 @@ )] #[repr(C)] -pub struct nsISupports__bindgen_vtable(::std::os::raw::c_void); +pub struct nsISupports__bindgen_vtable { + nsISupports_QueryInterface: fn(this: &mut nsISupports) -> *mut nsISupports, +} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct nsISupports { diff --git a/tests/expectations/tests/packed-vtable.rs b/tests/expectations/tests/packed-vtable.rs index 0069eada96..05fea61929 100644 --- a/tests/expectations/tests/packed-vtable.rs +++ b/tests/expectations/tests/packed-vtable.rs @@ -7,7 +7,9 @@ #![cfg(feature = "nightly")] #[repr(C)] -pub struct PackedVtable__bindgen_vtable(::std::os::raw::c_void); +pub struct PackedVtable__bindgen_vtable { + PackedVtable_PackedVtable_destructor: fn(this: &mut PackedVtable), +} #[repr(C, packed)] #[derive(Debug)] pub struct PackedVtable { diff --git a/tests/expectations/tests/ref_argument_array.rs b/tests/expectations/tests/ref_argument_array.rs index 799dd81587..04938d15ec 100644 --- a/tests/expectations/tests/ref_argument_array.rs +++ b/tests/expectations/tests/ref_argument_array.rs @@ -7,7 +7,10 @@ pub const NSID_LENGTH: u32 = 10; #[repr(C)] -pub struct nsID__bindgen_vtable(::std::os::raw::c_void); +pub struct nsID__bindgen_vtable { + nsID_ToProvidedString: + fn(this: &mut nsID, aDest: *mut [::std::os::raw::c_char; 10usize]), +} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct nsID { diff --git a/tests/expectations/tests/virtual_dtor.rs b/tests/expectations/tests/virtual_dtor.rs index c3c66e91d8..5af64bfe86 100644 --- a/tests/expectations/tests/virtual_dtor.rs +++ b/tests/expectations/tests/virtual_dtor.rs @@ -6,7 +6,9 @@ )] #[repr(C)] -pub struct nsSlots__bindgen_vtable(::std::os::raw::c_void); +pub struct nsSlots__bindgen_vtable { + nsSlots_nsSlots_destructor: fn(this: &mut nsSlots), +} #[repr(C)] #[derive(Debug)] pub struct nsSlots { diff --git a/tests/expectations/tests/virtual_interface.rs b/tests/expectations/tests/virtual_interface.rs index 5d4f1bbc04..ecd547fb45 100644 --- a/tests/expectations/tests/virtual_interface.rs +++ b/tests/expectations/tests/virtual_interface.rs @@ -7,8 +7,9 @@ #[repr(C)] pub struct PureVirtualIFace__bindgen_vtable { - PureVirtualIFace_Foo: fn(&mut self), - PureVirtualIFace_Bar: fn(&mut self, arg1: ::std::os::raw::c_uint), + PureVirtualIFace_Foo: fn(this: &mut PureVirtualIFace), + PureVirtualIFace_Bar: + fn(this: &mut PureVirtualIFace, arg1: ::std::os::raw::c_uint), } #[repr(C)] #[derive(Debug, Copy, Clone)] @@ -39,7 +40,7 @@ impl Default for PureVirtualIFace { } #[repr(C)] pub struct AnotherInterface__bindgen_vtable { - AnotherInterface_Baz: fn(&mut self), + AnotherInterface_Baz: fn(this: &mut AnotherInterface), } #[repr(C)] #[derive(Debug, Copy, Clone)] diff --git a/tests/expectations/tests/virtual_overloaded.rs b/tests/expectations/tests/virtual_overloaded.rs index 4556b1b6af..771e08c054 100644 --- a/tests/expectations/tests/virtual_overloaded.rs +++ b/tests/expectations/tests/virtual_overloaded.rs @@ -6,7 +6,10 @@ )] #[repr(C)] -pub struct C__bindgen_vtable(::std::os::raw::c_void); +pub struct C__bindgen_vtable { + C_do_thing: fn(this: &mut C, arg1: ::std::os::raw::c_char), + C_do_thing1: fn(this: &mut C, arg1: ::std::os::raw::c_int), +} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct C { diff --git a/tests/expectations/tests/vtable_recursive_sig.rs b/tests/expectations/tests/vtable_recursive_sig.rs index ca77bc8ca5..c10f2f0f1a 100644 --- a/tests/expectations/tests/vtable_recursive_sig.rs +++ b/tests/expectations/tests/vtable_recursive_sig.rs @@ -6,7 +6,9 @@ )] #[repr(C)] -pub struct Base__bindgen_vtable(::std::os::raw::c_void); +pub struct Base__bindgen_vtable { + Base_AsDerived: fn(this: &mut Base) -> *mut Derived, +} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Base { From f578b0b4505a46bbf7724eeaa48ea93f1a2aacea Mon Sep 17 00:00:00 2001 From: "Dr. Chat" Date: Thu, 30 Dec 2021 01:11:12 -0600 Subject: [PATCH 250/942] Mark all vtable functions as `pub` --- src/codegen/mod.rs | 2 +- tests/expectations/tests/enum_and_vtable_mangling.rs | 2 +- tests/expectations/tests/issue-1197-pure-virtual-stuff.rs | 4 ++-- tests/expectations/tests/nested_vtable.rs | 3 ++- tests/expectations/tests/packed-vtable.rs | 2 +- tests/expectations/tests/ref_argument_array.rs | 2 +- tests/expectations/tests/virtual_dtor.rs | 2 +- tests/expectations/tests/virtual_interface.rs | 6 +++--- tests/expectations/tests/virtual_overloaded.rs | 4 ++-- tests/expectations/tests/vtable_recursive_sig.rs | 2 +- 10 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 2b10b3debf..7a46f885cc 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -1082,7 +1082,7 @@ impl<'a> CodeGenerator for Vtable<'a> { }; Some(quote! { - #function_name : fn( #( #args ),* ) #ret + pub #function_name : fn( #( #args ),* ) #ret }) }) .collect::>(); diff --git a/tests/expectations/tests/enum_and_vtable_mangling.rs b/tests/expectations/tests/enum_and_vtable_mangling.rs index c0414c376f..126c40baec 100644 --- a/tests/expectations/tests/enum_and_vtable_mangling.rs +++ b/tests/expectations/tests/enum_and_vtable_mangling.rs @@ -15,7 +15,7 @@ pub enum _bindgen_ty_1 { } #[repr(C)] pub struct C__bindgen_vtable { - C_match: fn(this: &mut C), + pub C_match: fn(this: &mut C), } #[repr(C)] #[derive(Debug, Copy, Clone)] diff --git a/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs b/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs index 80606c2aa0..0b91eb2457 100644 --- a/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs +++ b/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs @@ -7,8 +7,8 @@ #[repr(C)] pub struct Foo__bindgen_vtable { - Foo_Foo_destructor: fn(this: &mut Foo), - Foo_Bar: fn(this: &mut Foo), + pub Foo_Foo_destructor: fn(this: &mut Foo), + pub Foo_Bar: fn(this: &mut Foo), } #[repr(C)] #[derive(Debug)] diff --git a/tests/expectations/tests/nested_vtable.rs b/tests/expectations/tests/nested_vtable.rs index 2b0f259919..92651d450e 100644 --- a/tests/expectations/tests/nested_vtable.rs +++ b/tests/expectations/tests/nested_vtable.rs @@ -7,7 +7,8 @@ #[repr(C)] pub struct nsISupports__bindgen_vtable { - nsISupports_QueryInterface: fn(this: &mut nsISupports) -> *mut nsISupports, + pub nsISupports_QueryInterface: + fn(this: &mut nsISupports) -> *mut nsISupports, } #[repr(C)] #[derive(Debug, Copy, Clone)] diff --git a/tests/expectations/tests/packed-vtable.rs b/tests/expectations/tests/packed-vtable.rs index 05fea61929..339891014d 100644 --- a/tests/expectations/tests/packed-vtable.rs +++ b/tests/expectations/tests/packed-vtable.rs @@ -8,7 +8,7 @@ #[repr(C)] pub struct PackedVtable__bindgen_vtable { - PackedVtable_PackedVtable_destructor: fn(this: &mut PackedVtable), + pub PackedVtable_PackedVtable_destructor: fn(this: &mut PackedVtable), } #[repr(C, packed)] #[derive(Debug)] diff --git a/tests/expectations/tests/ref_argument_array.rs b/tests/expectations/tests/ref_argument_array.rs index 04938d15ec..215fc5dad7 100644 --- a/tests/expectations/tests/ref_argument_array.rs +++ b/tests/expectations/tests/ref_argument_array.rs @@ -8,7 +8,7 @@ pub const NSID_LENGTH: u32 = 10; #[repr(C)] pub struct nsID__bindgen_vtable { - nsID_ToProvidedString: + pub nsID_ToProvidedString: fn(this: &mut nsID, aDest: *mut [::std::os::raw::c_char; 10usize]), } #[repr(C)] diff --git a/tests/expectations/tests/virtual_dtor.rs b/tests/expectations/tests/virtual_dtor.rs index 5af64bfe86..5d8834fa6b 100644 --- a/tests/expectations/tests/virtual_dtor.rs +++ b/tests/expectations/tests/virtual_dtor.rs @@ -7,7 +7,7 @@ #[repr(C)] pub struct nsSlots__bindgen_vtable { - nsSlots_nsSlots_destructor: fn(this: &mut nsSlots), + pub nsSlots_nsSlots_destructor: fn(this: &mut nsSlots), } #[repr(C)] #[derive(Debug)] diff --git a/tests/expectations/tests/virtual_interface.rs b/tests/expectations/tests/virtual_interface.rs index ecd547fb45..79656c28d9 100644 --- a/tests/expectations/tests/virtual_interface.rs +++ b/tests/expectations/tests/virtual_interface.rs @@ -7,8 +7,8 @@ #[repr(C)] pub struct PureVirtualIFace__bindgen_vtable { - PureVirtualIFace_Foo: fn(this: &mut PureVirtualIFace), - PureVirtualIFace_Bar: + pub PureVirtualIFace_Foo: fn(this: &mut PureVirtualIFace), + pub PureVirtualIFace_Bar: fn(this: &mut PureVirtualIFace, arg1: ::std::os::raw::c_uint), } #[repr(C)] @@ -40,7 +40,7 @@ impl Default for PureVirtualIFace { } #[repr(C)] pub struct AnotherInterface__bindgen_vtable { - AnotherInterface_Baz: fn(this: &mut AnotherInterface), + pub AnotherInterface_Baz: fn(this: &mut AnotherInterface), } #[repr(C)] #[derive(Debug, Copy, Clone)] diff --git a/tests/expectations/tests/virtual_overloaded.rs b/tests/expectations/tests/virtual_overloaded.rs index 771e08c054..f619f4ea46 100644 --- a/tests/expectations/tests/virtual_overloaded.rs +++ b/tests/expectations/tests/virtual_overloaded.rs @@ -7,8 +7,8 @@ #[repr(C)] pub struct C__bindgen_vtable { - C_do_thing: fn(this: &mut C, arg1: ::std::os::raw::c_char), - C_do_thing1: fn(this: &mut C, arg1: ::std::os::raw::c_int), + pub C_do_thing: fn(this: &mut C, arg1: ::std::os::raw::c_char), + pub C_do_thing1: fn(this: &mut C, arg1: ::std::os::raw::c_int), } #[repr(C)] #[derive(Debug, Copy, Clone)] diff --git a/tests/expectations/tests/vtable_recursive_sig.rs b/tests/expectations/tests/vtable_recursive_sig.rs index c10f2f0f1a..f136c0157c 100644 --- a/tests/expectations/tests/vtable_recursive_sig.rs +++ b/tests/expectations/tests/vtable_recursive_sig.rs @@ -7,7 +7,7 @@ #[repr(C)] pub struct Base__bindgen_vtable { - Base_AsDerived: fn(this: &mut Base) -> *mut Derived, + pub Base_AsDerived: fn(this: &mut Base) -> *mut Derived, } #[repr(C)] #[derive(Debug, Copy, Clone)] From 0587ff95a9a411c7392ff2aa1775f69ac36caff5 Mon Sep 17 00:00:00 2001 From: "Dr. Chat" Date: Thu, 30 Dec 2021 11:28:06 -0600 Subject: [PATCH 251/942] On second thought, don't generate virtual destructors --- src/codegen/mod.rs | 20 +++++++++---------- .../tests/issue-1197-pure-virtual-stuff.rs | 5 +---- tests/expectations/tests/packed-vtable.rs | 4 +--- tests/expectations/tests/virtual_dtor.rs | 4 +--- 4 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 7a46f885cc..b7cee7ec62 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -1041,19 +1041,19 @@ impl<'a> CodeGenerator for Vtable<'a> { assert_eq!(item.id(), self.item_id); debug_assert!(item.is_enabled_for_codegen(ctx)); let name = ctx.rust_ident(&self.canonical_name(ctx)); - let class_ident = ctx.rust_ident(self.item_id.canonical_name(ctx)); - // For now, we will only generate vtables for classes that do not inherit from others. - if self.comp_info.base_members().is_empty() { - // Map the destructor into a Method, and chain it into the below iteration. - let dtor = self - .comp_info - .destructor() - .map(|(kind, id)| Method::new(kind, id, false)); + // For now, we will only generate vtables for classes that: + // - do not inherit from others (compilers merge VTable from primary parent class). + // - do not contain a virtual destructor (requires ordering; platforms generate different vtables). + if self.comp_info.base_members().is_empty() && + self.comp_info.destructor().is_none() + { + let class_ident = ctx.rust_ident(self.item_id.canonical_name(ctx)); - let methods = dtor + let methods = self + .comp_info + .methods() .iter() - .chain(self.comp_info.methods().iter()) .filter_map(|m| { if !m.is_virtual() { return None; diff --git a/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs b/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs index 0b91eb2457..fd023363d7 100644 --- a/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs +++ b/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs @@ -6,10 +6,7 @@ )] #[repr(C)] -pub struct Foo__bindgen_vtable { - pub Foo_Foo_destructor: fn(this: &mut Foo), - pub Foo_Bar: fn(this: &mut Foo), -} +pub struct Foo__bindgen_vtable(::std::os::raw::c_void); #[repr(C)] #[derive(Debug)] pub struct Foo { diff --git a/tests/expectations/tests/packed-vtable.rs b/tests/expectations/tests/packed-vtable.rs index 339891014d..0069eada96 100644 --- a/tests/expectations/tests/packed-vtable.rs +++ b/tests/expectations/tests/packed-vtable.rs @@ -7,9 +7,7 @@ #![cfg(feature = "nightly")] #[repr(C)] -pub struct PackedVtable__bindgen_vtable { - pub PackedVtable_PackedVtable_destructor: fn(this: &mut PackedVtable), -} +pub struct PackedVtable__bindgen_vtable(::std::os::raw::c_void); #[repr(C, packed)] #[derive(Debug)] pub struct PackedVtable { diff --git a/tests/expectations/tests/virtual_dtor.rs b/tests/expectations/tests/virtual_dtor.rs index 5d8834fa6b..c3c66e91d8 100644 --- a/tests/expectations/tests/virtual_dtor.rs +++ b/tests/expectations/tests/virtual_dtor.rs @@ -6,9 +6,7 @@ )] #[repr(C)] -pub struct nsSlots__bindgen_vtable { - pub nsSlots_nsSlots_destructor: fn(this: &mut nsSlots), -} +pub struct nsSlots__bindgen_vtable(::std::os::raw::c_void); #[repr(C)] #[derive(Debug)] pub struct nsSlots { From be6d07ac2c00ada005e5512b19ff6c6a34cfe985 Mon Sep 17 00:00:00 2001 From: Justin Moore Date: Thu, 30 Dec 2021 19:41:57 -0600 Subject: [PATCH 252/942] Mark all vtable functions as `unsafe extern "C"` --- src/codegen/mod.rs | 2 +- tests/expectations/tests/enum_and_vtable_mangling.rs | 2 +- tests/expectations/tests/nested_vtable.rs | 2 +- tests/expectations/tests/ref_argument_array.rs | 6 ++++-- tests/expectations/tests/virtual_interface.rs | 10 ++++++---- tests/expectations/tests/virtual_overloaded.rs | 6 ++++-- tests/expectations/tests/vtable_recursive_sig.rs | 2 +- 7 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index b7cee7ec62..5ce42c3449 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -1082,7 +1082,7 @@ impl<'a> CodeGenerator for Vtable<'a> { }; Some(quote! { - pub #function_name : fn( #( #args ),* ) #ret + pub #function_name : unsafe extern "C" fn( #( #args ),* ) #ret }) }) .collect::>(); diff --git a/tests/expectations/tests/enum_and_vtable_mangling.rs b/tests/expectations/tests/enum_and_vtable_mangling.rs index 126c40baec..bd6f7ff603 100644 --- a/tests/expectations/tests/enum_and_vtable_mangling.rs +++ b/tests/expectations/tests/enum_and_vtable_mangling.rs @@ -15,7 +15,7 @@ pub enum _bindgen_ty_1 { } #[repr(C)] pub struct C__bindgen_vtable { - pub C_match: fn(this: &mut C), + pub C_match: unsafe extern "C" fn(this: &mut C), } #[repr(C)] #[derive(Debug, Copy, Clone)] diff --git a/tests/expectations/tests/nested_vtable.rs b/tests/expectations/tests/nested_vtable.rs index 92651d450e..8747a59f11 100644 --- a/tests/expectations/tests/nested_vtable.rs +++ b/tests/expectations/tests/nested_vtable.rs @@ -8,7 +8,7 @@ #[repr(C)] pub struct nsISupports__bindgen_vtable { pub nsISupports_QueryInterface: - fn(this: &mut nsISupports) -> *mut nsISupports, + unsafe extern "C" fn(this: &mut nsISupports) -> *mut nsISupports, } #[repr(C)] #[derive(Debug, Copy, Clone)] diff --git a/tests/expectations/tests/ref_argument_array.rs b/tests/expectations/tests/ref_argument_array.rs index 215fc5dad7..a99bf2c3bf 100644 --- a/tests/expectations/tests/ref_argument_array.rs +++ b/tests/expectations/tests/ref_argument_array.rs @@ -8,8 +8,10 @@ pub const NSID_LENGTH: u32 = 10; #[repr(C)] pub struct nsID__bindgen_vtable { - pub nsID_ToProvidedString: - fn(this: &mut nsID, aDest: *mut [::std::os::raw::c_char; 10usize]), + pub nsID_ToProvidedString: unsafe extern "C" fn( + this: &mut nsID, + aDest: *mut [::std::os::raw::c_char; 10usize], + ), } #[repr(C)] #[derive(Debug, Copy, Clone)] diff --git a/tests/expectations/tests/virtual_interface.rs b/tests/expectations/tests/virtual_interface.rs index 79656c28d9..7677c51fb6 100644 --- a/tests/expectations/tests/virtual_interface.rs +++ b/tests/expectations/tests/virtual_interface.rs @@ -7,9 +7,11 @@ #[repr(C)] pub struct PureVirtualIFace__bindgen_vtable { - pub PureVirtualIFace_Foo: fn(this: &mut PureVirtualIFace), - pub PureVirtualIFace_Bar: - fn(this: &mut PureVirtualIFace, arg1: ::std::os::raw::c_uint), + pub PureVirtualIFace_Foo: unsafe extern "C" fn(this: &mut PureVirtualIFace), + pub PureVirtualIFace_Bar: unsafe extern "C" fn( + this: &mut PureVirtualIFace, + arg1: ::std::os::raw::c_uint, + ), } #[repr(C)] #[derive(Debug, Copy, Clone)] @@ -40,7 +42,7 @@ impl Default for PureVirtualIFace { } #[repr(C)] pub struct AnotherInterface__bindgen_vtable { - pub AnotherInterface_Baz: fn(this: &mut AnotherInterface), + pub AnotherInterface_Baz: unsafe extern "C" fn(this: &mut AnotherInterface), } #[repr(C)] #[derive(Debug, Copy, Clone)] diff --git a/tests/expectations/tests/virtual_overloaded.rs b/tests/expectations/tests/virtual_overloaded.rs index f619f4ea46..3fcfe33e61 100644 --- a/tests/expectations/tests/virtual_overloaded.rs +++ b/tests/expectations/tests/virtual_overloaded.rs @@ -7,8 +7,10 @@ #[repr(C)] pub struct C__bindgen_vtable { - pub C_do_thing: fn(this: &mut C, arg1: ::std::os::raw::c_char), - pub C_do_thing1: fn(this: &mut C, arg1: ::std::os::raw::c_int), + pub C_do_thing: + unsafe extern "C" fn(this: &mut C, arg1: ::std::os::raw::c_char), + pub C_do_thing1: + unsafe extern "C" fn(this: &mut C, arg1: ::std::os::raw::c_int), } #[repr(C)] #[derive(Debug, Copy, Clone)] diff --git a/tests/expectations/tests/vtable_recursive_sig.rs b/tests/expectations/tests/vtable_recursive_sig.rs index f136c0157c..dd1b0f4d16 100644 --- a/tests/expectations/tests/vtable_recursive_sig.rs +++ b/tests/expectations/tests/vtable_recursive_sig.rs @@ -7,7 +7,7 @@ #[repr(C)] pub struct Base__bindgen_vtable { - pub Base_AsDerived: fn(this: &mut Base) -> *mut Derived, + pub Base_AsDerived: unsafe extern "C" fn(this: &mut Base) -> *mut Derived, } #[repr(C)] #[derive(Debug, Copy, Clone)] From 3bc4044c789fa52e141942dfafe500b1335b6487 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Tue, 4 Jan 2022 23:35:13 +0100 Subject: [PATCH 253/942] Upgrade Clap to version 3 --- Cargo.lock | 77 ++++++++------- Cargo.toml | 4 +- src/options.rs | 248 ++++++++++++++++++++++++------------------------- 3 files changed, 168 insertions(+), 161 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d79a408e7d..3de8f8f5d2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,15 +11,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "ansi_term" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" -dependencies = [ - "winapi", -] - [[package]] name = "atty" version = "0.2.14" @@ -31,6 +22,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "autocfg" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" + [[package]] name = "bindgen" version = "0.59.2" @@ -88,17 +85,17 @@ dependencies = [ [[package]] name = "clap" -version = "2.33.3" +version = "3.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" +checksum = "d01c9347757e131122b19cd19a05c85805b68c2352a97b623efdc3c295290299" dependencies = [ - "ansi_term", "atty", "bitflags", + "indexmap", + "os_str_bytes", "strsim", + "termcolor", "textwrap", - "unicode-width", - "vec_map", ] [[package]] @@ -143,6 +140,12 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" +[[package]] +name = "hashbrown" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" + [[package]] name = "hermit-abi" version = "0.1.19" @@ -158,6 +161,16 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" +[[package]] +name = "indexmap" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5" +dependencies = [ + "autocfg", + "hashbrown", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -197,9 +210,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.3.4" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" +checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" [[package]] name = "minimal-lexical" @@ -218,6 +231,15 @@ dependencies = [ "version_check", ] +[[package]] +name = "os_str_bytes" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64" +dependencies = [ + "memchr", +] + [[package]] name = "peeking_take_while" version = "0.1.2" @@ -337,9 +359,9 @@ checksum = "42a568c8f2cd051a4d283bd6eb0343ac214c1b0f1ac19f93e1175b2dee38c73d" [[package]] name = "strsim" -version = "0.8.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "tempfile" @@ -366,18 +388,9 @@ dependencies = [ [[package]] name = "textwrap" -version = "0.11.0" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" -dependencies = [ - "unicode-width", -] - -[[package]] -name = "unicode-width" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" +checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80" [[package]] name = "unicode-xid" @@ -385,12 +398,6 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" -[[package]] -name = "vec_map" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" - [[package]] name = "version_check" version = "0.9.3" diff --git a/Cargo.toml b/Cargo.toml index ba41a22dbb..cc60870636 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,7 +41,7 @@ required-features = ["clap"] [dev-dependencies] diff = "0.1" -clap = "2" +clap = "3" shlex = "1" tempfile = "3" @@ -49,7 +49,7 @@ tempfile = "3" bitflags = "1.0.3" cexpr = "0.6" # This kinda sucks: https://github.com/rust-lang/cargo/issues/1982 -clap = { version = "2", optional = true } +clap = { version = "3", optional = true } clang-sys = { version = "1", features = ["clang_6_0"] } lazycell = "1" lazy_static = "1" diff --git a/src/options.rs b/src/options.rs index bc7431c52d..67bcda74fc 100644 --- a/src/options.rs +++ b/src/options.rs @@ -25,16 +25,16 @@ where let matches = App::new("bindgen") .version(option_env!("CARGO_PKG_VERSION").unwrap_or("unknown")) .about("Generates Rust bindings from C/C++ headers.") - .usage("bindgen [FLAGS] [OPTIONS]
-- ...") + .override_usage("bindgen [FLAGS] [OPTIONS]
-- ...") .args(&[ - Arg::with_name("header") + Arg::new("header") .help("C or C++ header file") .required(true), - Arg::with_name("depfile") + Arg::new("depfile") .long("depfile") .takes_value(true) .help("Path to write depfile to"), - Arg::with_name("default-enum-style") + Arg::new("default-enum-style") .long("default-enum-style") .help("The default style of code used to generate enums.") .value_name("variant") @@ -47,8 +47,8 @@ where "rust", "rust_non_exhaustive", ]) - .multiple(false), - Arg::with_name("bitfield-enum") + .multiple_occurrences(false), + Arg::new("bitfield-enum") .long("bitfield-enum") .help( "Mark any enum whose name matches as a set of \ @@ -56,23 +56,23 @@ where ) .value_name("regex") .takes_value(true) - .multiple(true) + .multiple_occurrences(true) .number_of_values(1), - Arg::with_name("newtype-enum") + Arg::new("newtype-enum") .long("newtype-enum") .help("Mark any enum whose name matches as a newtype.") .value_name("regex") .takes_value(true) - .multiple(true) + .multiple_occurrences(true) .number_of_values(1), - Arg::with_name("rustified-enum") + Arg::new("rustified-enum") .long("rustified-enum") .help("Mark any enum whose name matches as a Rust enum.") .value_name("regex") .takes_value(true) - .multiple(true) + .multiple_occurrences(true) .number_of_values(1), - Arg::with_name("constified-enum") + Arg::new("constified-enum") .long("constified-enum") .help( "Mark any enum whose name matches as a series of \ @@ -80,9 +80,9 @@ where ) .value_name("regex") .takes_value(true) - .multiple(true) + .multiple_occurrences(true) .number_of_values(1), - Arg::with_name("constified-enum-module") + Arg::new("constified-enum-module") .long("constified-enum-module") .help( "Mark any enum whose name matches as a module of \ @@ -90,16 +90,16 @@ where ) .value_name("regex") .takes_value(true) - .multiple(true) + .multiple_occurrences(true) .number_of_values(1), - Arg::with_name("default-macro-constant-type") + Arg::new("default-macro-constant-type") .long("default-macro-constant-type") .help("The default signed/unsigned type for C macro constants.") .value_name("variant") .default_value("unsigned") .possible_values(&["signed", "unsigned"]) - .multiple(false), - Arg::with_name("default-alias-style") + .multiple_occurrences(false), + Arg::new("default-alias-style") .long("default-alias-style") .help("The default style of code used to generate typedefs.") .value_name("variant") @@ -109,8 +109,8 @@ where "new_type", "new_type_deref", ]) - .multiple(false), - Arg::with_name("normal-alias") + .multiple_occurrences(false), + Arg::new("normal-alias") .long("normal-alias") .help( "Mark any typedef alias whose name matches to use \ @@ -118,9 +118,9 @@ where ) .value_name("regex") .takes_value(true) - .multiple(true) + .multiple_occurrences(true) .number_of_values(1), - Arg::with_name("new-type-alias") + Arg::new("new-type-alias") .long("new-type-alias") .help( "Mark any typedef alias whose name matches to have \ @@ -128,9 +128,9 @@ where ) .value_name("regex") .takes_value(true) - .multiple(true) + .multiple_occurrences(true) .number_of_values(1), - Arg::with_name("new-type-alias-deref") + Arg::new("new-type-alias-deref") .long("new-type-alias-deref") .help( "Mark any typedef alias whose name matches to have \ @@ -138,94 +138,94 @@ where ) .value_name("regex") .takes_value(true) - .multiple(true) + .multiple_occurrences(true) .number_of_values(1), - Arg::with_name("blocklist-type") + Arg::new("blocklist-type") .alias("blacklist-type") .long("blocklist-type") .help("Mark as hidden.") .value_name("type") .takes_value(true) - .multiple(true) + .multiple_occurrences(true) .number_of_values(1), - Arg::with_name("blocklist-function") + Arg::new("blocklist-function") .alias("blacklist-function") .long("blocklist-function") .help("Mark as hidden.") .value_name("function") .takes_value(true) - .multiple(true) + .multiple_occurrences(true) .number_of_values(1), - Arg::with_name("blocklist-item") + Arg::new("blocklist-item") .alias("blacklist-item") .long("blocklist-item") .help("Mark as hidden.") .value_name("item") .takes_value(true) - .multiple(true) + .multiple_occurrences(true) .number_of_values(1), - Arg::with_name("blocklist-file") + Arg::new("blocklist-file") .alias("blacklist-file") .long("blocklist-file") .help("Mark all contents of as hidden.") .value_name("path") .takes_value(true) - .multiple(true) + .multiple_occurrences(true) .number_of_values(1), - Arg::with_name("no-layout-tests") + Arg::new("no-layout-tests") .long("no-layout-tests") .help("Avoid generating layout tests for any type."), - Arg::with_name("no-derive-copy") + Arg::new("no-derive-copy") .long("no-derive-copy") .help("Avoid deriving Copy on any type."), - Arg::with_name("no-derive-debug") + Arg::new("no-derive-debug") .long("no-derive-debug") .help("Avoid deriving Debug on any type."), - Arg::with_name("no-derive-default") + Arg::new("no-derive-default") .long("no-derive-default") - .hidden(true) + .hide(true) .help("Avoid deriving Default on any type."), - Arg::with_name("impl-debug").long("impl-debug").help( + Arg::new("impl-debug").long("impl-debug").help( "Create Debug implementation, if it can not be derived \ automatically.", ), - Arg::with_name("impl-partialeq") + Arg::new("impl-partialeq") .long("impl-partialeq") .help( "Create PartialEq implementation, if it can not be derived \ automatically.", ), - Arg::with_name("with-derive-default") + Arg::new("with-derive-default") .long("with-derive-default") .help("Derive Default on any type."), - Arg::with_name("with-derive-hash") + Arg::new("with-derive-hash") .long("with-derive-hash") .help("Derive hash on any type."), - Arg::with_name("with-derive-partialeq") + Arg::new("with-derive-partialeq") .long("with-derive-partialeq") .help("Derive partialeq on any type."), - Arg::with_name("with-derive-partialord") + Arg::new("with-derive-partialord") .long("with-derive-partialord") .help("Derive partialord on any type."), - Arg::with_name("with-derive-eq") + Arg::new("with-derive-eq") .long("with-derive-eq") .help( "Derive eq on any type. Enable this option also \ enables --with-derive-partialeq", ), - Arg::with_name("with-derive-ord") + Arg::new("with-derive-ord") .long("with-derive-ord") .help( "Derive ord on any type. Enable this option also \ enables --with-derive-partialord", ), - Arg::with_name("no-doc-comments") + Arg::new("no-doc-comments") .long("no-doc-comments") .help( "Avoid including doc comments in the output, see: \ https://github.com/rust-lang/rust-bindgen/issues/426", ), - Arg::with_name("no-recursive-allowlist") + Arg::new("no-recursive-allowlist") .long("no-recursive-allowlist") .alias("no-recursive-whitelist") .help( @@ -234,23 +234,23 @@ where `bindgen::Builder::allowlist_recursively` method's \ documentation for details.", ), - Arg::with_name("objc-extern-crate") + Arg::new("objc-extern-crate") .long("objc-extern-crate") .help("Use extern crate instead of use for objc."), - Arg::with_name("generate-block") + Arg::new("generate-block") .long("generate-block") .help("Generate block signatures instead of void pointers."), - Arg::with_name("block-extern-crate") + Arg::new("block-extern-crate") .long("block-extern-crate") .help("Use extern crate instead of use for block."), - Arg::with_name("distrust-clang-mangling") + Arg::new("distrust-clang-mangling") .long("distrust-clang-mangling") .help("Do not trust the libclang-provided mangling"), - Arg::with_name("builtins").long("builtins").help( + Arg::new("builtins").long("builtins").help( "Output bindings for builtin definitions, e.g. \ __builtin_va_list.", ), - Arg::with_name("ctypes-prefix") + Arg::new("ctypes-prefix") .long("ctypes-prefix") .help( "Use the given prefix before raw types instead of \ @@ -258,61 +258,61 @@ where ) .value_name("prefix") .takes_value(true), - Arg::with_name("anon-fields-prefix") + Arg::new("anon-fields-prefix") .long("anon-fields-prefix") .help("Use the given prefix for the anon fields.") .value_name("prefix") .default_value(DEFAULT_ANON_FIELDS_PREFIX) .takes_value(true), - Arg::with_name("time-phases") + Arg::new("time-phases") .long("time-phases") .help("Time the different bindgen phases and print to stderr"), // All positional arguments after the end of options marker, `--` - Arg::with_name("clang-args").last(true).multiple(true), - Arg::with_name("emit-clang-ast") + Arg::new("clang-args").last(true).multiple_occurrences(true), + Arg::new("emit-clang-ast") .long("emit-clang-ast") .help("Output the Clang AST for debugging purposes."), - Arg::with_name("emit-ir") + Arg::new("emit-ir") .long("emit-ir") .help("Output our internal IR for debugging purposes."), - Arg::with_name("emit-ir-graphviz") + Arg::new("emit-ir-graphviz") .long("emit-ir-graphviz") .help("Dump graphviz dot file.") .value_name("path") .takes_value(true), - Arg::with_name("enable-cxx-namespaces") + Arg::new("enable-cxx-namespaces") .long("enable-cxx-namespaces") .help("Enable support for C++ namespaces."), - Arg::with_name("disable-name-namespacing") + Arg::new("disable-name-namespacing") .long("disable-name-namespacing") .help( "Disable namespacing via mangling, causing bindgen to \ generate names like \"Baz\" instead of \"foo_bar_Baz\" \ for an input name \"foo::bar::Baz\".", ), - Arg::with_name("disable-nested-struct-naming") + Arg::new("disable-nested-struct-naming") .long("disable-nested-struct-naming") .help( "Disable nested struct naming, causing bindgen to generate \ names like \"bar\" instead of \"foo_bar\" for a nested \ definition \"struct foo { struct bar { } b; };\"." ), - Arg::with_name("disable-untagged-union") + Arg::new("disable-untagged-union") .long("disable-untagged-union") .help( "Disable support for native Rust unions.", ), - Arg::with_name("disable-header-comment") + Arg::new("disable-header-comment") .long("disable-header-comment") .help("Suppress insertion of bindgen's version identifier into generated bindings.") - .multiple(true), - Arg::with_name("ignore-functions") + .multiple_occurrences(true), + Arg::new("ignore-functions") .long("ignore-functions") .help( "Do not generate bindings for functions or methods. This \ is useful when you only care about struct layouts.", ), - Arg::with_name("generate") + Arg::new("generate") .long("generate") .help( "Generate only given items, split by commas. \ @@ -320,67 +320,67 @@ where \"methods\", \"constructors\" and \"destructors\".", ) .takes_value(true), - Arg::with_name("ignore-methods") + Arg::new("ignore-methods") .long("ignore-methods") .help("Do not generate bindings for methods."), - Arg::with_name("no-convert-floats") + Arg::new("no-convert-floats") .long("no-convert-floats") .help("Do not automatically convert floats to f32/f64."), - Arg::with_name("no-prepend-enum-name") + Arg::new("no-prepend-enum-name") .long("no-prepend-enum-name") .help("Do not prepend the enum name to constant or newtype variants."), - Arg::with_name("no-include-path-detection") + Arg::new("no-include-path-detection") .long("no-include-path-detection") .help("Do not try to detect default include paths"), - Arg::with_name("fit-macro-constant-types") + Arg::new("fit-macro-constant-types") .long("fit-macro-constant-types") .help("Try to fit macro constants into types smaller than u32/i32"), - Arg::with_name("unstable-rust") + Arg::new("unstable-rust") .long("unstable-rust") .help("Generate unstable Rust code (deprecated; use --rust-target instead).") - .multiple(true), // FIXME: Pass legacy test suite - Arg::with_name("opaque-type") + .multiple_occurrences(true), // FIXME: Pass legacy test suite + Arg::new("opaque-type") .long("opaque-type") .help("Mark as opaque.") .value_name("type") .takes_value(true) - .multiple(true) + .multiple_occurrences(true) .number_of_values(1), - Arg::with_name("output") - .short("o") + Arg::new("output") + .short('o') .long("output") .help("Write Rust bindings to .") .takes_value(true), - Arg::with_name("raw-line") + Arg::new("raw-line") .long("raw-line") .help("Add a raw line of Rust code at the beginning of output.") .takes_value(true) - .multiple(true) + .multiple_occurrences(true) .number_of_values(1), - Arg::with_name("module-raw-line") + Arg::new("module-raw-line") .long("module-raw-line") .help("Add a raw line of Rust code to a given module.") .takes_value(true) - .multiple(true) + .multiple_occurrences(true) .number_of_values(2) .value_names(&["module-name", "raw-line"]), - Arg::with_name("rust-target") + Arg::new("rust-target") .long("rust-target") - .help(&rust_target_help) + .help(rust_target_help.as_ref()) .takes_value(true), - Arg::with_name("use-core") + Arg::new("use-core") .long("use-core") .help("Use types from Rust core instead of std."), - Arg::with_name("conservative-inline-namespaces") + Arg::new("conservative-inline-namespaces") .long("conservative-inline-namespaces") .help( "Conservatively generate inline namespaces to avoid name \ conflicts.", ), - Arg::with_name("use-msvc-mangling") + Arg::new("use-msvc-mangling") .long("use-msvc-mangling") .help("MSVC C++ ABI mangling. DEPRECATED: Has no effect."), - Arg::with_name("allowlist-function") + Arg::new("allowlist-function") .long("allowlist-function") .alias("whitelist-function") .help( @@ -390,12 +390,12 @@ where ) .value_name("regex") .takes_value(true) - .multiple(true) + .multiple_occurrences(true) .number_of_values(1), - Arg::with_name("generate-inline-functions") + Arg::new("generate-inline-functions") .long("generate-inline-functions") .help("Generate inline functions."), - Arg::with_name("allowlist-type") + Arg::new("allowlist-type") .long("allowlist-type") .alias("whitelist-type") .help( @@ -404,9 +404,9 @@ where ) .value_name("regex") .takes_value(true) - .multiple(true) + .multiple_occurrences(true) .number_of_values(1), - Arg::with_name("allowlist-var") + Arg::new("allowlist-var") .long("allowlist-var") .alias("whitelist-var") .help( @@ -416,12 +416,12 @@ where ) .value_name("regex") .takes_value(true) - .multiple(true) + .multiple_occurrences(true) .number_of_values(1), - Arg::with_name("verbose") + Arg::new("verbose") .long("verbose") .help("Print verbose error messages."), - Arg::with_name("dump-preprocessed-input") + Arg::new("dump-preprocessed-input") .long("dump-preprocessed-input") .help( "Preprocess and dump the input header files to disk. \ @@ -429,26 +429,26 @@ where filing issues. The resulting file will be named \ something like `__bindgen.i` or `__bindgen.ii`.", ), - Arg::with_name("no-record-matches") + Arg::new("no-record-matches") .long("no-record-matches") .help( "Do not record matching items in the regex sets. \ This disables reporting of unused items.", ), - Arg::with_name("size_t-is-usize") + Arg::new("size_t-is-usize") .long("size_t-is-usize") .help("Translate size_t to usize."), - Arg::with_name("no-rustfmt-bindings") + Arg::new("no-rustfmt-bindings") .long("no-rustfmt-bindings") .help("Do not format the generated bindings with rustfmt."), - Arg::with_name("rustfmt-bindings") + Arg::new("rustfmt-bindings") .long("rustfmt-bindings") .help( "Format the generated bindings with rustfmt. DEPRECATED: \ --rustfmt-bindings is now enabled by default. Disable \ with --no-rustfmt-bindings.", ), - Arg::with_name("rustfmt-configuration-file") + Arg::new("rustfmt-configuration-file") .long("rustfmt-configuration-file") .help( "The absolute path to the rustfmt configuration file. \ @@ -457,81 +457,81 @@ where ) .value_name("path") .takes_value(true) - .multiple(false) + .multiple_occurrences(false) .number_of_values(1), - Arg::with_name("no-partialeq") + Arg::new("no-partialeq") .long("no-partialeq") .help("Avoid deriving PartialEq for types matching .") .value_name("regex") .takes_value(true) - .multiple(true) + .multiple_occurrences(true) .number_of_values(1), - Arg::with_name("no-copy") + Arg::new("no-copy") .long("no-copy") .help("Avoid deriving Copy for types matching .") .value_name("regex") .takes_value(true) - .multiple(true) + .multiple_occurrences(true) .number_of_values(1), - Arg::with_name("no-debug") + Arg::new("no-debug") .long("no-debug") .help("Avoid deriving Debug for types matching .") .value_name("regex") .takes_value(true) - .multiple(true) + .multiple_occurrences(true) .number_of_values(1), - Arg::with_name("no-default") + Arg::new("no-default") .long("no-default") .help("Avoid deriving/implement Default for types matching .") .value_name("regex") .takes_value(true) - .multiple(true) + .multiple_occurrences(true) .number_of_values(1), - Arg::with_name("no-hash") + Arg::new("no-hash") .long("no-hash") .help("Avoid deriving Hash for types matching .") .value_name("regex") .takes_value(true) - .multiple(true) + .multiple_occurrences(true) .number_of_values(1), - Arg::with_name("must-use-type") + Arg::new("must-use-type") .long("must-use-type") .help("Add #[must_use] annotation to types matching .") .value_name("regex") .takes_value(true) - .multiple(true) + .multiple_occurrences(true) .number_of_values(1), - Arg::with_name("enable-function-attribute-detection") + Arg::new("enable-function-attribute-detection") .long("enable-function-attribute-detection") .help( "Enables detecting unexposed attributes in functions (slow). Used to generate #[must_use] annotations.", ), - Arg::with_name("use-array-pointers-in-arguments") + Arg::new("use-array-pointers-in-arguments") .long("use-array-pointers-in-arguments") .help("Use `*const [T; size]` instead of `*const T` for C arrays"), - Arg::with_name("wasm-import-module-name") + Arg::new("wasm-import-module-name") .long("wasm-import-module-name") .value_name("name") .takes_value(true) .help("The name to be used in a #[link(wasm_import_module = ...)] statement"), - Arg::with_name("dynamic-loading") + Arg::new("dynamic-loading") .long("dynamic-loading") .takes_value(true) .help("Use dynamic loading mode with the given library name."), - Arg::with_name("dynamic-link-require-all") + Arg::new("dynamic-link-require-all") .long("dynamic-link-require-all") .help("Require successful linkage to all functions in the library."), - Arg::with_name("respect-cxx-access-specs") + Arg::new("respect-cxx-access-specs") .long("respect-cxx-access-specs") .help("Makes generated bindings `pub` only for items if the items are publically accessible in C++."), - Arg::with_name("translate-enum-integer-types") + Arg::new("translate-enum-integer-types") .long("translate-enum-integer-types") .help("Always translate enum integer types to native Rust integer types."), - Arg::with_name("c-naming") + Arg::new("c-naming") .long("c-naming") .help("Generate types with C style naming."), - Arg::with_name("explicit-padding") + Arg::new("explicit-padding") .long("explicit-padding") .help("Always output explicit padding fields."), ]) // .args() From ca78ae9c41998713db0c6fa70cd21089cdb2af2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Sat, 15 Jan 2022 16:18:53 +0100 Subject: [PATCH 254/942] Bump MSRV to 1.54 --- .github/workflows/bindgen.yml | 4 ++-- README.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index e750bc406c..bb2d565ece 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -48,11 +48,11 @@ jobs: profile: minimal # MSRV below is documented in README.md, please update that if you # change this. - toolchain: 1.46.0 + toolchain: 1.54.0 override: true - name: Build with msrv - run: rm Cargo.lock && cargo +1.46.0 build --lib + run: rm Cargo.lock && cargo +1.54.0 build --lib quickchecking: runs-on: ubuntu-latest diff --git a/README.md b/README.md index 7b2dbbc233..4b1194fa2e 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ extern "C" { ## MSRV -The minimum supported Rust version is **1.46**. +The minimum supported Rust version is **1.54**. No MSRV bump policy has been established yet, so MSRV may increase in any release. From 71fe5fdcb657470b7c2e1b841eaea4660d4ccc40 Mon Sep 17 00:00:00 2001 From: Adrian Taylor Date: Tue, 15 Feb 2022 16:49:59 -0800 Subject: [PATCH 255/942] Fix an erroneous +x bit on a source code file. --- src/codegen/bitfield_unit.rs | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 src/codegen/bitfield_unit.rs diff --git a/src/codegen/bitfield_unit.rs b/src/codegen/bitfield_unit.rs old mode 100755 new mode 100644 From b3e6a9882f56b5e9e65bf38c1a2c9ccac2995d37 Mon Sep 17 00:00:00 2001 From: Jake Merdich Date: Thu, 3 Feb 2022 11:02:30 -0500 Subject: [PATCH 256/942] Allow fully-qualified derives Adding a custom derive like "serde::Deserialize" results in a panic complaining that it is not a valid Ident. Derive params are not identifiers, so treat it as a token stream instead. --- bindgen-integration/build.rs | 2 +- src/codegen/helpers.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs index 77ea64b581..d0ec3bc0dd 100644 --- a/bindgen-integration/build.rs +++ b/bindgen-integration/build.rs @@ -128,7 +128,7 @@ impl ParseCallbacks for MacroCallback { ] } else if name == "MyOrderedEnum" { vec![ - "PartialOrd".into(), + "std::cmp::PartialOrd".into(), ] } else { vec![] diff --git a/src/codegen/helpers.rs b/src/codegen/helpers.rs index 2ce6894fb2..75c169c67d 100644 --- a/src/codegen/helpers.rs +++ b/src/codegen/helpers.rs @@ -30,7 +30,7 @@ pub mod attributes { let which_ones = which_ones .iter() .cloned() - .map(|one| Ident::new(one, Span::call_site())); + .map(|one| TokenStream::from_str(one).expect("derive to be valid")); quote! { #[derive( #( #which_ones ),* )] } From 5f5f6fa1933540c0a447973cd6e5239ed9159201 Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Fri, 19 Jun 2020 20:12:03 -0700 Subject: [PATCH 257/942] ci: Stop testing libclang 3.9 --- .github/workflows/bindgen.yml | 9 ++------- appveyor.yml | 6 ------ 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index bb2d565ece..87b2cdb1d8 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -99,7 +99,7 @@ jobs: - debian: null cross: null rust: null - llvm_version: ["3.9", "4.0", "5.0", "9.0"] + llvm_version: ["4.0", "5.0", "9.0"] main_tests: [1] release_build: [0, 1] no_default_features: [0, 1] @@ -110,13 +110,8 @@ jobs: feature_testing_only_docs: [0] exclude: - # 3.9 and 4.0 are too old to support regular dynamic linking, so this + # 4.0 is too old to support regular dynamic linking, so this # is not expected to work. - - os: ubuntu-latest - llvm_version: "3.9" - no_default_features: 1 - feature_runtime: 0 - - os: ubuntu-latest llvm_version: "4.0" no_default_features: 1 diff --git a/appveyor.yml b/appveyor.yml index 342f47cc2e..51129cdcbe 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,9 +2,6 @@ environment: RUST_BACKTRACE: 1 RUST_CHANNEL: "%Configuration%" matrix: - - TARGET: gnu - LLVM_VERSION: 3.9.0-2 - BINDGEN_FEATURES: testing_only_libclang_3_9 - TARGET: gnu LLVM_VERSION: 4.0.0-1 BINDGEN_FEATURES: testing_only_libclang_4 @@ -14,9 +11,6 @@ environment: - TARGET: gnu LLVM_VERSION: 9.0.0-1 BINDGEN_FEATURES: testing_only_libclang_9 - - TARGET: msvc - LLVM_VERSION: 3.9.0 - BINDGEN_FEATURES: testing_only_libclang_3_9 - TARGET: msvc LLVM_VERSION: 4.0.0 BINDGEN_FEATURES: testing_only_libclang_4 From fdb762a9d44229a74f5d428b167b39f02bd10432 Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Fri, 19 Jun 2020 20:12:04 -0700 Subject: [PATCH 258/942] clang: Stop accommodating libclang 3.9 --- src/clang.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/clang.rs b/src/clang.rs index 074d459ba7..528c8a9111 100644 --- a/src/clang.rs +++ b/src/clang.rs @@ -2014,12 +2014,6 @@ impl EvalResult { return None; } - if !clang_EvalResult_isUnsignedInt::is_loaded() { - // FIXME(emilio): There's no way to detect underflow here, and clang - // will just happily give us a value. - return Some(unsafe { clang_EvalResult_getAsInt(self.x) } as i64); - } - if unsafe { clang_EvalResult_isUnsignedInt(self.x) } != 0 { let value = unsafe { clang_EvalResult_getAsUnsigned(self.x) }; if value > i64::max_value() as c_ulonglong { From 69ee6fb243f56648a66c492f5b7395bc37d59f06 Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Sun, 21 Jun 2020 17:35:09 -0700 Subject: [PATCH 259/942] parser: Simplify parse_macro for clang 4.0+ Here we delete a workaround that is no longer needed. --- src/ir/var.rs | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/ir/var.rs b/src/ir/var.rs index cd17937013..396b3e047b 100644 --- a/src/ir/var.rs +++ b/src/ir/var.rs @@ -391,25 +391,13 @@ fn parse_macro( ) -> Option<(Vec, cexpr::expr::EvalResult)> { use cexpr::expr; - let mut cexpr_tokens: Vec<_> = tokens + let cexpr_tokens: Vec<_> = tokens .iter() .filter_map(ClangToken::as_cexpr_token) .collect(); let parser = expr::IdentifierParser::new(ctx.parsed_macros()); - if let Ok((_, (id, val))) = parser.macro_definition(&cexpr_tokens) { - return Some((id.into(), val)); - } - - // Try without the last token, to workaround a libclang bug in versions - // previous to 4.0. - // - // See: - // https://bugs.llvm.org//show_bug.cgi?id=9069 - // https://reviews.llvm.org/D26446 - cexpr_tokens.pop()?; - match parser.macro_definition(&cexpr_tokens) { Ok((_, (id, val))) => Some((id.into(), val)), _ => None, From c4532e0c1756e2df1c20dd67b781582f4289709b Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Sun, 21 Jun 2020 17:40:04 -0700 Subject: [PATCH 260/942] parser: Simplify handle_function_macro for clang 4.0+ --- src/ir/var.rs | 70 ++++++++++++++++----------------------------------- 1 file changed, 22 insertions(+), 48 deletions(-) diff --git a/src/ir/var.rs b/src/ir/var.rs index 396b3e047b..e44d57afe4 100644 --- a/src/ir/var.rs +++ b/src/ir/var.rs @@ -149,52 +149,27 @@ fn default_macro_constant_type(ctx: &BindgenContext, value: i64) -> IntKind { } } -/// Determines whether a set of tokens from a CXCursor_MacroDefinition -/// represent a function-like macro. If so, calls the func_macro callback -/// and returns `Err(ParseError::Continue)` to signal to skip further -/// processing. If conversion to UTF-8 fails (it is performed only where it -/// should be infallible), then `Err(ParseError::Continue)` is returned as well. +/// Parses tokens from a CXCursor_MacroDefinition pointing into a function-like +/// macro, and calls the func_macro callback. fn handle_function_macro( cursor: &clang::Cursor, - tokens: &[ClangToken], callbacks: &dyn crate::callbacks::ParseCallbacks, -) -> Result<(), ParseError> { - // TODO: Hoist the `is_macro_function_like` check into this function's - // caller, and thus avoid allocating the `tokens` vector for non-functional - // macros. - let is_functional_macro = cursor.is_macro_function_like(); - - if !is_functional_macro { - return Ok(()); - } - +) { let is_closing_paren = |t: &ClangToken| { // Test cheap token kind before comparing exact spellings. t.kind == clang_sys::CXToken_Punctuation && t.spelling() == b")" }; - let boundary = tokens.iter().position(is_closing_paren); - - let mut spelled = tokens.iter().map(ClangToken::spelling); - // Add 1, to convert index to length. - let left = spelled - .by_ref() - .take(boundary.ok_or(ParseError::Continue)? + 1); - let left = left.collect::>().concat(); - let left = String::from_utf8(left).map_err(|_| ParseError::Continue)?; - let right = spelled; - // Drop last token with LLVM < 4.0, due to an LLVM bug. - // - // See: - // https://bugs.llvm.org//show_bug.cgi?id=9069 - let len = match (right.len(), crate::clang_version().parsed) { - (len, Some((v, _))) if len > 0 && v < 4 => len - 1, - (len, _) => len, - }; - let right: Vec<_> = right.take(len).collect(); - callbacks.func_macro(&left, &right); - - // We handled the macro, skip future macro processing. - Err(ParseError::Continue) + let tokens: Vec<_> = cursor.tokens().iter().collect(); + if let Some(boundary) = tokens.iter().position(is_closing_paren) { + let mut spelled = tokens.iter().map(ClangToken::spelling); + // Add 1, to convert index to length. + let left = spelled.by_ref().take(boundary + 1); + let left = left.collect::>().concat(); + if let Ok(left) = String::from_utf8(left) { + let right: Vec<_> = spelled.collect(); + callbacks.func_macro(&left, &right); + } + } } impl ClangSubItemParser for Var { @@ -207,8 +182,6 @@ impl ClangSubItemParser for Var { use clang_sys::*; match cursor.kind() { CXCursor_MacroDefinition => { - let tokens: Vec<_> = cursor.tokens().iter().collect(); - if let Some(callbacks) = ctx.parse_callbacks() { match callbacks.will_parse_macro(&cursor.spelling()) { MacroParsingBehavior::Ignore => { @@ -217,10 +190,14 @@ impl ClangSubItemParser for Var { MacroParsingBehavior::Default => {} } - handle_function_macro(&cursor, &tokens, callbacks)?; + if cursor.is_macro_function_like() { + handle_function_macro(&cursor, callbacks); + // We handled the macro, skip macro processing below. + return Err(ParseError::Continue); + } } - let value = parse_macro(ctx, &tokens); + let value = parse_macro(ctx, &cursor); let (id, value) = match value { Some(v) => v, @@ -387,14 +364,11 @@ impl ClangSubItemParser for Var { /// Try and parse a macro using all the macros parsed until now. fn parse_macro( ctx: &BindgenContext, - tokens: &[ClangToken], + cursor: &clang::Cursor, ) -> Option<(Vec, cexpr::expr::EvalResult)> { use cexpr::expr; - let cexpr_tokens: Vec<_> = tokens - .iter() - .filter_map(ClangToken::as_cexpr_token) - .collect(); + let cexpr_tokens = cursor.cexpr_tokens(); let parser = expr::IdentifierParser::new(ctx.parsed_macros()); From 8be556a08ee967fea301a2298831ff829f2db061 Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Tue, 23 Jun 2020 15:50:42 -0700 Subject: [PATCH 261/942] tests: Remove clang-3.9 expectations --- Cargo.toml | 1 - bindgen-integration/Cargo.toml | 1 - src/main.rs | 2 - tests/expectations/build.rs | 1 - .../libclang-3.9/abi_variadic_function.rs | 11 -- tests/expectations/tests/libclang-3.9/auto.rs | 35 ------ .../tests/libclang-3.9/call-conv-field.rs | 60 --------- .../tests/libclang-3.9/const_bool.rs | 29 ----- .../tests/libclang-3.9/constant-evaluate.rs | 27 ---- ...0600-cannot-apply-unary-negation-to-u32.rs | 9 -- .../issue-769-bad-instantiation-test.rs | 65 ---------- .../tests/libclang-3.9/mangling-win32.rs | 52 -------- .../tests/libclang-3.9/objc_inheritance.rs | 117 ------------------ .../tests/libclang-3.9/objc_template.rs | 65 ---------- .../partial-specialization-and-inheritance.rs | 39 ------ ...mplate_instantiation_with_fn_local_type.rs | 60 --------- .../type_alias_template_specialized.rs | 37 ------ .../libclang-3.9/wasm-constructor-returns.rs | 37 ------ tests/stylo_sanity.rs | 1 - tests/tests.rs | 2 - 20 files changed, 651 deletions(-) delete mode 100644 tests/expectations/tests/libclang-3.9/abi_variadic_function.rs delete mode 100644 tests/expectations/tests/libclang-3.9/auto.rs delete mode 100644 tests/expectations/tests/libclang-3.9/call-conv-field.rs delete mode 100644 tests/expectations/tests/libclang-3.9/const_bool.rs delete mode 100644 tests/expectations/tests/libclang-3.9/constant-evaluate.rs delete mode 100644 tests/expectations/tests/libclang-3.9/error-E0600-cannot-apply-unary-negation-to-u32.rs delete mode 100644 tests/expectations/tests/libclang-3.9/issue-769-bad-instantiation-test.rs delete mode 100644 tests/expectations/tests/libclang-3.9/mangling-win32.rs delete mode 100644 tests/expectations/tests/libclang-3.9/objc_inheritance.rs delete mode 100644 tests/expectations/tests/libclang-3.9/objc_template.rs delete mode 100644 tests/expectations/tests/libclang-3.9/partial-specialization-and-inheritance.rs delete mode 100644 tests/expectations/tests/libclang-3.9/template_instantiation_with_fn_local_type.rs delete mode 100644 tests/expectations/tests/libclang-3.9/type_alias_template_specialized.rs delete mode 100644 tests/expectations/tests/libclang-3.9/wasm-constructor-returns.rs diff --git a/Cargo.toml b/Cargo.toml index cc60870636..cec8a57902 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -84,4 +84,3 @@ testing_only_extra_assertions = [] testing_only_libclang_9 = [] testing_only_libclang_5 = [] testing_only_libclang_4 = [] -testing_only_libclang_3_9 = [] diff --git a/bindgen-integration/Cargo.toml b/bindgen-integration/Cargo.toml index 650dedafe2..9dcf1d377b 100644 --- a/bindgen-integration/Cargo.toml +++ b/bindgen-integration/Cargo.toml @@ -19,4 +19,3 @@ testing_only_extra_assertions = ["bindgen/testing_only_extra_assertions"] testing_only_libclang_9 = ["bindgen/testing_only_libclang_9"] testing_only_libclang_5 = ["bindgen/testing_only_libclang_5"] testing_only_libclang_4 = ["bindgen/testing_only_libclang_4"] -testing_only_libclang_3_9 = ["bindgen/testing_only_libclang_3_9"] diff --git a/src/main.rs b/src/main.rs index f3398db890..a208957410 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,8 +25,6 @@ fn clang_version_check() { Some((5, 0)) } else if cfg!(feature = "testing_only_libclang_4") { Some((4, 0)) - } else if cfg!(feature = "testing_only_libclang_3_9") { - Some((3, 9)) } else { None }; diff --git a/tests/expectations/build.rs b/tests/expectations/build.rs index 2b426a449d..beed7116a4 100644 --- a/tests/expectations/build.rs +++ b/tests/expectations/build.rs @@ -9,7 +9,6 @@ use std::io::Write; use std::path::Path; const LIBCLANG_VERSION_DIRS: &'static [&'static str] = &[ - "libclang-3.9", "libclang-4", "libclang-5", "libclang-9", diff --git a/tests/expectations/tests/libclang-3.9/abi_variadic_function.rs b/tests/expectations/tests/libclang-3.9/abi_variadic_function.rs deleted file mode 100644 index 6aeb16f2a7..0000000000 --- a/tests/expectations/tests/libclang-3.9/abi_variadic_function.rs +++ /dev/null @@ -1,11 +0,0 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -extern "C" { - #[link_name = "\u{1}_Z1bcz"] - pub fn b(arg1: ::std::os::raw::c_char, ...) -> ::std::os::raw::c_char; -} diff --git a/tests/expectations/tests/libclang-3.9/auto.rs b/tests/expectations/tests/libclang-3.9/auto.rs deleted file mode 100644 index 0b20b39eb6..0000000000 --- a/tests/expectations/tests/libclang-3.9/auto.rs +++ /dev/null @@ -1,35 +0,0 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct Foo { - pub _address: u8, -} -pub const Foo_kFoo: bool = true; -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) - ); -} -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct Bar { - pub _address: u8, -} -extern "C" { - #[link_name = "\u{1}_Z5Test2v"] - pub fn Test2() -> ::std::os::raw::c_uint; -} diff --git a/tests/expectations/tests/libclang-3.9/call-conv-field.rs b/tests/expectations/tests/libclang-3.9/call-conv-field.rs deleted file mode 100644 index f134bd8a46..0000000000 --- a/tests/expectations/tests/libclang-3.9/call-conv-field.rs +++ /dev/null @@ -1,60 +0,0 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] -#![cfg(not(test))] - -#[repr(C)] -#[derive(Default, Copy, Clone)] -pub struct JNINativeInterface_ { - pub GetVersion: ::std::option::Option< - unsafe extern "stdcall" fn( - env: *mut ::std::os::raw::c_void, - ) -> ::std::os::raw::c_int, - >, - pub __hack: ::std::os::raw::c_ulonglong, -} -#[test] -fn bindgen_test_layout_JNINativeInterface_() { - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(JNINativeInterface_)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(JNINativeInterface_)) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).GetVersion - as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(JNINativeInterface_), - "::", - stringify!(GetVersion) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).__hack as *const _ - as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(JNINativeInterface_), - "::", - stringify!(__hack) - ) - ); -} -extern "stdcall" { - pub fn bar(); -} diff --git a/tests/expectations/tests/libclang-3.9/const_bool.rs b/tests/expectations/tests/libclang-3.9/const_bool.rs deleted file mode 100644 index 97e1d8dda4..0000000000 --- a/tests/expectations/tests/libclang-3.9/const_bool.rs +++ /dev/null @@ -1,29 +0,0 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -pub const k: bool = true; -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct A { - pub _address: u8, -} -pub const A_k: bool = false; -#[test] -fn bindgen_test_layout_A() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(A)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(A)) - ); -} -pub type foo = bool; -pub const k2: foo = true; diff --git a/tests/expectations/tests/libclang-3.9/constant-evaluate.rs b/tests/expectations/tests/libclang-3.9/constant-evaluate.rs deleted file mode 100644 index b7286a37aa..0000000000 --- a/tests/expectations/tests/libclang-3.9/constant-evaluate.rs +++ /dev/null @@ -1,27 +0,0 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -pub const foo: _bindgen_ty_1 = _bindgen_ty_1::foo; -pub const bar: _bindgen_ty_1 = _bindgen_ty_1::bar; -#[repr(u32)] -#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] -pub enum _bindgen_ty_1 { - foo = 4, - bar = 8, -} -pub type EasyToOverflow = ::std::os::raw::c_ulonglong; -pub const k: EasyToOverflow = 2147483648; -pub const k_expr: EasyToOverflow = 0; -extern "C" { - pub static wow: EasyToOverflow; -} -pub const BAZ: ::std::os::raw::c_longlong = 24; -pub const fuzz: f64 = 51.0; -pub const BAZZ: ::std::os::raw::c_char = 53; -pub const WAT: ::std::os::raw::c_char = 0; -pub const bytestring: &[u8; 4usize] = b"Foo\0"; -pub const NOT_UTF8: [u8; 5usize] = [240u8, 40u8, 140u8, 40u8, 0u8]; diff --git a/tests/expectations/tests/libclang-3.9/error-E0600-cannot-apply-unary-negation-to-u32.rs b/tests/expectations/tests/libclang-3.9/error-E0600-cannot-apply-unary-negation-to-u32.rs deleted file mode 100644 index 3fa853eebe..0000000000 --- a/tests/expectations/tests/libclang-3.9/error-E0600-cannot-apply-unary-negation-to-u32.rs +++ /dev/null @@ -1,9 +0,0 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] -#![allow(overflowing_literals)] - -pub const a: u32 = 18446744073709551611; diff --git a/tests/expectations/tests/libclang-3.9/issue-769-bad-instantiation-test.rs b/tests/expectations/tests/libclang-3.9/issue-769-bad-instantiation-test.rs deleted file mode 100644 index 47e166c76b..0000000000 --- a/tests/expectations/tests/libclang-3.9/issue-769-bad-instantiation-test.rs +++ /dev/null @@ -1,65 +0,0 @@ -#![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 { - #[allow(unused_imports)] - use self::super::root; - #[repr(C)] - #[derive(Debug, Copy, Clone)] - pub struct Rooted { - pub member: T, - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, - } - impl Default for Rooted { - fn default() -> Self { - let mut s = ::std::mem::MaybeUninit::::uninit(); - unsafe { - ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); - s.assume_init() - } - } - } - #[test] - fn __bindgen_test_layout_Rooted_open0_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!( - "Size of template specialization: ", - stringify!(root::Rooted<::std::os::raw::c_int>) - ) - ); - assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(root::Rooted<::std::os::raw::c_int>) - ) - ); - } - #[test] - fn __bindgen_test_layout_Rooted_open0_int_close0_instantiation_1() { - assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!( - "Size of template specialization: ", - stringify!(root::Rooted<::std::os::raw::c_int>) - ) - ); - assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(root::Rooted<::std::os::raw::c_int>) - ) - ); - } -} diff --git a/tests/expectations/tests/libclang-3.9/mangling-win32.rs b/tests/expectations/tests/libclang-3.9/mangling-win32.rs deleted file mode 100644 index 0aee327414..0000000000 --- a/tests/expectations/tests/libclang-3.9/mangling-win32.rs +++ /dev/null @@ -1,52 +0,0 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -extern "C" { - pub fn foo(); -} -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct Foo { - pub _address: u8, -} -extern "C" { - #[link_name = "\u{1}?sBar@Foo@@2_NA"] - pub static mut Foo_sBar: bool; -} -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) - ); -} -extern "fastcall" { - pub fn fast_call_func_no_args() -> ::std::os::raw::c_int; -} -extern "fastcall" { - pub fn fast_call_func_many_args( - arg1: ::std::os::raw::c_int, - arg2: ::std::os::raw::c_int, - arg3: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int; -} -extern "stdcall" { - pub fn std_call_func_no_args() -> ::std::os::raw::c_int; -} -extern "stdcall" { - pub fn std_call_func_many_args( - arg1: ::std::os::raw::c_int, - arg2: ::std::os::raw::c_int, - arg3: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int; -} diff --git a/tests/expectations/tests/libclang-3.9/objc_inheritance.rs b/tests/expectations/tests/libclang-3.9/objc_inheritance.rs deleted file mode 100644 index 5f07dbaab1..0000000000 --- a/tests/expectations/tests/libclang-3.9/objc_inheritance.rs +++ /dev/null @@ -1,117 +0,0 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] -#![cfg(target_os = "macos")] - -#[macro_use] -extern crate objc; -#[allow(non_camel_case_types)] -pub type id = *mut objc::runtime::Object; -#[repr(transparent)] -#[derive(Clone)] -pub struct Foo(pub id); -impl std::ops::Deref for Foo { - type Target = objc::runtime::Object; - fn deref(&self) -> &Self::Target { - unsafe { &*self.0 } - } -} -unsafe impl objc::Message for Foo {} -impl Foo { - pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Foo), alloc) }) - } -} -impl IFoo for Foo {} -pub trait IFoo: Sized + std::ops::Deref {} -#[repr(transparent)] -#[derive(Clone)] -pub struct Bar(pub id); -impl std::ops::Deref for Bar { - type Target = objc::runtime::Object; - fn deref(&self) -> &Self::Target { - unsafe { &*self.0 } - } -} -unsafe impl objc::Message for Bar {} -impl Bar { - pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Bar), alloc) }) - } -} -impl IFoo for Bar {} -impl From for Foo { - fn from(child: Bar) -> Foo { - Foo(child.0) - } -} -impl std::convert::TryFrom for Bar { - type Error = &'static str; - fn try_from(parent: Foo) -> Result { - let is_kind_of: bool = - unsafe { msg_send!(parent, isKindOfClass: class!(Bar)) }; - if is_kind_of { - Ok(Bar(parent.0)) - } else { - Err("This Foo cannot be downcasted to Bar") - } - } -} -impl IBar for Bar {} -pub trait IBar: Sized + std::ops::Deref {} -#[repr(transparent)] -#[derive(Clone)] -pub struct Baz(pub id); -impl std::ops::Deref for Baz { - type Target = objc::runtime::Object; - fn deref(&self) -> &Self::Target { - unsafe { &*self.0 } - } -} -unsafe impl objc::Message for Baz {} -impl Baz { - pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Baz), alloc) }) - } -} -impl IBar for Baz {} -impl From for Bar { - fn from(child: Baz) -> Bar { - Bar(child.0) - } -} -impl std::convert::TryFrom for Baz { - type Error = &'static str; - fn try_from(parent: Bar) -> Result { - let is_kind_of: bool = - unsafe { msg_send!(parent, isKindOfClass: class!(Baz)) }; - if is_kind_of { - Ok(Baz(parent.0)) - } else { - Err("This Bar cannot be downcasted to Baz") - } - } -} -impl IFoo for Baz {} -impl From for Foo { - fn from(child: Baz) -> Foo { - Foo(child.0) - } -} -impl std::convert::TryFrom for Baz { - type Error = &'static str; - fn try_from(parent: Foo) -> Result { - let is_kind_of: bool = - unsafe { msg_send!(parent, isKindOfClass: class!(Baz)) }; - if is_kind_of { - Ok(Baz(parent.0)) - } else { - Err("This Foo cannot be downcasted to Baz") - } - } -} -impl IBaz for Baz {} -pub trait IBaz: Sized + std::ops::Deref {} diff --git a/tests/expectations/tests/libclang-3.9/objc_template.rs b/tests/expectations/tests/libclang-3.9/objc_template.rs deleted file mode 100644 index 4ccf72b71b..0000000000 --- a/tests/expectations/tests/libclang-3.9/objc_template.rs +++ /dev/null @@ -1,65 +0,0 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] -#![cfg(target_os = "macos")] - -#[macro_use] -extern crate objc; -#[allow(non_camel_case_types)] -pub type id = *mut objc::runtime::Object; -#[repr(transparent)] -#[derive(Clone)] -pub struct Foo(pub id); -impl std::ops::Deref for Foo { - type Target = objc::runtime::Object; - fn deref(&self) -> &Self::Target { - unsafe { &*self.0 } - } -} -unsafe impl objc::Message for Foo {} -impl Foo { - pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Foo), alloc) }) - } -} -impl IFoo for Foo {} -pub trait IFoo: Sized + std::ops::Deref { - unsafe fn get(&self) -> id - where - ::Target: objc::Message + Sized, - { - msg_send!(*self, get) - } -} -#[repr(transparent)] -#[derive(Clone)] -pub struct FooMultiGeneric(pub id); -impl std::ops::Deref for FooMultiGeneric { - type Target = objc::runtime::Object; - fn deref(&self) -> &Self::Target { - unsafe { &*self.0 } - } -} -unsafe impl objc::Message for FooMultiGeneric {} -impl FooMultiGeneric { - pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(FooMultiGeneric), alloc) }) - } -} -impl - IFooMultiGeneric for FooMultiGeneric -{ -} -pub trait IFooMultiGeneric: - Sized + std::ops::Deref -{ - unsafe fn objectForKey_(&self, key: id) -> id - where - ::Target: objc::Message + Sized, - { - msg_send!(*self, objectForKey: key) - } -} diff --git a/tests/expectations/tests/libclang-3.9/partial-specialization-and-inheritance.rs b/tests/expectations/tests/libclang-3.9/partial-specialization-and-inheritance.rs deleted file mode 100644 index e62ea68172..0000000000 --- a/tests/expectations/tests/libclang-3.9/partial-specialization-and-inheritance.rs +++ /dev/null @@ -1,39 +0,0 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct Base { - pub _address: u8, -} -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct Derived { - pub b: bool, -} -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct Usage { - pub _address: u8, -} -extern "C" { - #[link_name = "\u{1}_ZN5Usage13static_memberE"] - pub static mut Usage_static_member: [u32; 2usize]; -} -#[test] -fn bindgen_test_layout_Usage() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Usage)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Usage)) - ); -} diff --git a/tests/expectations/tests/libclang-3.9/template_instantiation_with_fn_local_type.rs b/tests/expectations/tests/libclang-3.9/template_instantiation_with_fn_local_type.rs deleted file mode 100644 index ba0c6e7b49..0000000000 --- a/tests/expectations/tests/libclang-3.9/template_instantiation_with_fn_local_type.rs +++ /dev/null @@ -1,60 +0,0 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct Foo { - pub _address: u8, -} -extern "C" { - #[link_name = "\u{1}_Z1fv"] - pub fn f(); -} -#[test] -fn __bindgen_test_layout_Foo_open0__bindgen_ty_id_20_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of template specialization: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of template specialization: ", stringify!(Foo)) - ); -} -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct Baz { - pub _address: u8, -} -#[test] -fn bindgen_test_layout_Baz() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Baz)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Baz)) - ); -} - #[test] -fn __bindgen_test_layout_Foo_open0__bindgen_ty_id_21_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of template specialization: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of template specialization: ", stringify!(Foo)) - ); -} diff --git a/tests/expectations/tests/libclang-3.9/type_alias_template_specialized.rs b/tests/expectations/tests/libclang-3.9/type_alias_template_specialized.rs deleted file mode 100644 index 67e1c5aeb3..0000000000 --- a/tests/expectations/tests/libclang-3.9/type_alias_template_specialized.rs +++ /dev/null @@ -1,37 +0,0 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct Rooted { - pub ptr: ::std::os::raw::c_int, -} -#[test] -fn bindgen_test_layout_Rooted() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Rooted)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Rooted)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).ptr as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Rooted), - "::", - stringify!(ptr) - ) - ); -} -///
-pub type MaybeWrapped
= a; diff --git a/tests/expectations/tests/libclang-3.9/wasm-constructor-returns.rs b/tests/expectations/tests/libclang-3.9/wasm-constructor-returns.rs deleted file mode 100644 index f207d0d8e1..0000000000 --- a/tests/expectations/tests/libclang-3.9/wasm-constructor-returns.rs +++ /dev/null @@ -1,37 +0,0 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -#[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, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) - ); -} -extern "C" { - #[link_name = "\u{1}_ZN3FooC1Ei"] - pub fn Foo_Foo(this: *mut Foo, var: ::std::os::raw::c_int); -} -impl Foo { - #[inline] - pub unsafe fn new(var: ::std::os::raw::c_int) -> Self { - let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); - Foo_Foo(__bindgen_tmp.as_mut_ptr(), var); - __bindgen_tmp.assume_init() - } -} diff --git a/tests/stylo_sanity.rs b/tests/stylo_sanity.rs index 39777cd154..f44f12878d 100755 --- a/tests/stylo_sanity.rs +++ b/tests/stylo_sanity.rs @@ -16,7 +16,6 @@ extern crate bindgen; #[test] #[cfg(not(any(debug_assertions, feature = "testing_only_extra_assertions",)))] #[cfg(any( - feature = "testing_only_libclang_3_9", feature = "testing_only_libclang_4", feature = "testing_only_libclang_5", feature = "testing_only_libclang_9" diff --git a/tests/tests.rs b/tests/tests.rs index ac0106ad17..274c568301 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -143,8 +143,6 @@ fn compare_generated_header( expectation.push("libclang-5"); } else if cfg!(feature = "testing_only_libclang_4") { expectation.push("libclang-4"); - } else if cfg!(feature = "testing_only_libclang_3_9") { - expectation.push("libclang-3.9"); } else { match clang_version().parsed { None => expectation.push("libclang-9"), From f985aa5f2932f7453b53fe007a3b616d558fac3a Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Tue, 1 Feb 2022 23:02:12 -0800 Subject: [PATCH 262/942] book: Update Clang references from 3.9 -> 4.0 --- book/src/requirements.md | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/book/src/requirements.md b/book/src/requirements.md index 9ccaea94ac..8a7cbcb25c 100644 --- a/book/src/requirements.md +++ b/book/src/requirements.md @@ -7,16 +7,13 @@ This page lists the requirements for running `bindgen` and how to get them. `bindgen` leverages `libclang` to preprocess, parse, and type check C and C++ header files. -It is recommended to use Clang 3.9 or greater, however `bindgen` can run with +It is recommended to use Clang 4.0 or greater, however `bindgen` can run with older Clangs with some features disabled. -* **If you are generating bindings to C,** 3.7 and 3.8 will probably work OK for -you. - -* **If you are generating bindings to C++,** you almost definitely want 3.9 or +* **If you are generating bindings to C++,** you almost definitely want 4.0 or greater. -### Installing Clang 3.9 +### Installing Clang 4.0 #### Windows @@ -53,9 +50,9 @@ $ port install clang # apt install llvm-dev libclang-dev clang ``` -Ubuntu 16.10 provides the necessary packages directly. If you are using older +Ubuntu 18.04 provides the necessary packages directly. If you are using older version of Ubuntu or other Debian-based distros, you may need to add the LLVM -repos to get version 3.9. See http://apt.llvm.org/. +repos to get version 4.0. See http://apt.llvm.org/. #### Arch @@ -79,7 +76,7 @@ Add `export LIBCLANG_PATH=/usr/local/lib` to your profile. #### From source -If your package manager doesn't yet offer Clang 3.9, you'll need to build from +If your package manager doesn't yet offer Clang 4.0, you'll need to build from source. For that, follow the instructions [here](http://clang.llvm.org/get_started.html). From ddfa28f91f6db2580c2a09c90b06c02455a84229 Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Tue, 1 Feb 2022 23:19:43 -0800 Subject: [PATCH 263/942] docs: Update CONTRIBUTING.md for clang versions --- CONTRIBUTING.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e6b6a505d0..439a18da58 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -71,7 +71,7 @@ latest version of libclang. In that case, you may want to either uninstall other versions of llvm, or specify the path of the desired libclang explicitly: ``` -$ export LIBCLANG_PATH=path/to/clang-3.9/lib +$ export LIBCLANG_PATH=path/to/clang-9.0/lib ``` Additionally, you may want to build and test with the `testing_only_docs` @@ -195,9 +195,9 @@ can add multiple test expectations, one for each supported `libclang` version. Instead of having a single `tests/expectations/tests/my_test.rs` file, add each of: +* `tests/expectations/tests/libclang-9/my_test.rs` +* `tests/expectations/tests/libclang-5/my_test.rs` * `tests/expectations/tests/libclang-4/my_test.rs` -* `tests/expectations/tests/libclang-3.9/my_test.rs` -* `tests/expectations/tests/libclang-3.8/my_test.rs` If you need to update the test expectations for a test file that generates different bindings for different `libclang` versions, you *don't* need to have From e180d145a49b09c6d521cdc7989d1a1d4f173541 Mon Sep 17 00:00:00 2001 From: David Drysdale Date: Mon, 29 Nov 2021 13:03:26 +0000 Subject: [PATCH 264/942] Add --allowlist-file option --- book/src/allowlisting.md | 2 + src/ir/context.rs | 20 ++- src/ir/item.rs | 5 + src/lib.rs | 12 ++ src/options.rs | 14 ++ tests/expectations/tests/allowlist-file.rs | 154 +++++++++++++++++++++ tests/headers/allowlist-file.hpp | 21 +++ tests/headers/allowlisted/file.hpp | 22 +++ 8 files changed, 249 insertions(+), 1 deletion(-) create mode 100644 tests/expectations/tests/allowlist-file.rs create mode 100644 tests/headers/allowlist-file.hpp create mode 100644 tests/headers/allowlisted/file.hpp diff --git a/book/src/allowlisting.md b/book/src/allowlisting.md index 2e28d80ff6..edf93df0ef 100644 --- a/book/src/allowlisting.md +++ b/book/src/allowlisting.md @@ -19,12 +19,14 @@ transitively used by a definition that matches them. * [`bindgen::Builder::allowlist_type`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.allowlist_type) * [`bindgen::Builder::allowlist_function`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.allowlist_function) * [`bindgen::Builder::allowlist_var`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.allowlist_var) +* [`bindgen::Builder::allowlist_file`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.allowlist_file) ### Command Line * `--allowlist-type ` * `--allowlist-function ` * `--allowlist-var ` +* `--allowlist-file ` ### Annotations diff --git a/src/ir/context.rs b/src/ir/context.rs index b2e6f98542..9afd16d6a6 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -2296,7 +2296,8 @@ If you encounter an error missing from this list, please file an issue or a PR!" // game. if self.options().allowlisted_types.is_empty() && self.options().allowlisted_functions.is_empty() && - self.options().allowlisted_vars.is_empty() + self.options().allowlisted_vars.is_empty() && + self.options().allowlisted_files.is_empty() { return true; } @@ -2307,6 +2308,23 @@ If you encounter an error missing from this list, please file an issue or a PR!" return true; } + // Items with a source location in an explicitly allowlisted file + // are always included. + if !self.options().allowlisted_files.is_empty() { + if let Some(location) = item.location() { + let (file, _, _, _) = location.location(); + if let Some(filename) = file.name() { + if self + .options() + .allowlisted_files + .matches(&filename) + { + return true; + } + } + } + } + let name = item.path_for_allowlisting(self)[1..].join("::"); debug!("allowlisted_items: testing {:?}", name); match *item.kind() { diff --git a/src/ir/item.rs b/src/ir/item.rs index 8692575fe9..aed575ca11 100644 --- a/src/ir/item.rs +++ b/src/ir/item.rs @@ -530,6 +530,11 @@ impl Item { &mut self.kind } + /// Where in the source is this item located? + pub fn location(&self) -> Option<&clang::SourceLocation> { + self.location.as_ref() + } + /// Get an identifier that differentiates this item from its siblings. /// /// This should stay relatively stable in the face of code motion outside or diff --git a/src/lib.rs b/src/lib.rs index 39f55f04ff..ea5c61b405 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -313,6 +313,7 @@ impl Builder { (&self.options.allowlisted_functions, "--allowlist-function"), (&self.options.allowlisted_types, "--allowlist-type"), (&self.options.allowlisted_vars, "--allowlist-var"), + (&self.options.allowlisted_files, "--allowlist-file"), (&self.options.no_partialeq_types, "--no-partialeq"), (&self.options.no_copy_types, "--no-copy"), (&self.options.no_debug_types, "--no-debug"), @@ -908,6 +909,12 @@ impl Builder { self } + /// Allowlist the given file so that its contents appear in the generated bindings. + pub fn allowlist_file>(mut self, arg: T) -> Builder { + self.options.allowlisted_files.insert(arg); + self + } + /// Deprecated: use allowlist_var instead. #[deprecated(note = "use allowlist_var instead")] pub fn whitelist_var>(self, arg: T) -> Builder { @@ -1705,6 +1712,9 @@ struct BindgenOptions { /// Allowlisted variables. See docs for `allowlisted_types` for more. allowlisted_vars: RegexSet, + /// The set of files whose contents should be allowlisted. + allowlisted_files: RegexSet, + /// The default style of code to generate for enums default_enum_style: codegen::EnumVariation, @@ -1984,6 +1994,7 @@ impl BindgenOptions { &mut self.allowlisted_vars, &mut self.allowlisted_types, &mut self.allowlisted_functions, + &mut self.allowlisted_files, &mut self.blocklisted_types, &mut self.blocklisted_functions, &mut self.blocklisted_items, @@ -2042,6 +2053,7 @@ impl Default for BindgenOptions { allowlisted_types: Default::default(), allowlisted_functions: Default::default(), allowlisted_vars: Default::default(), + allowlisted_files: Default::default(), default_enum_style: Default::default(), bitfield_enums: Default::default(), newtype_enums: Default::default(), diff --git a/src/options.rs b/src/options.rs index 67bcda74fc..04d42ed5c3 100644 --- a/src/options.rs +++ b/src/options.rs @@ -418,6 +418,14 @@ where .takes_value(true) .multiple_occurrences(true) .number_of_values(1), + Arg::new("allowlist-file") + .alias("allowlist-file") + .long("allowlist-file") + .help("Allowlist all contents of .") + .value_name("path") + .takes_value(true) + .multiple_occurrences(true) + .number_of_values(1), Arg::new("verbose") .long("verbose") .help("Print verbose error messages."), @@ -871,6 +879,12 @@ where } } + if let Some(hidden_files) = matches.values_of("allowlist-file") { + for file in hidden_files { + builder = builder.allowlist_file(file); + } + } + if let Some(args) = matches.values_of("clang-args") { for arg in args { builder = builder.clang_arg(arg); diff --git a/tests/expectations/tests/allowlist-file.rs b/tests/expectations/tests/allowlist-file.rs new file mode 100644 index 0000000000..2c2660a606 --- /dev/null +++ b/tests/expectations/tests/allowlist-file.rs @@ -0,0 +1,154 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +pub const SOME_DEFUN: u32 = 123; +extern "C" { + #[link_name = "\u{1}_Z12SomeFunctionv"] + pub fn SomeFunction(); +} +extern "C" { + pub static mut someVar: ::std::os::raw::c_int; +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct someClass { + pub _address: u8, +} +#[test] +fn bindgen_test_layout_someClass() { + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(someClass)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(someClass)) + ); +} +extern "C" { + #[link_name = "\u{1}_ZN9someClass16somePublicMethodEi"] + pub fn someClass_somePublicMethod( + this: *mut someClass, + foo: ::std::os::raw::c_int, + ); +} +impl someClass { + #[inline] + pub unsafe fn somePublicMethod(&mut self, foo: ::std::os::raw::c_int) { + someClass_somePublicMethod(self, foo) + } +} +extern "C" { + pub fn ExternFunction(); +} +extern "C" { + #[link_name = "\u{1}_ZN3foo18NamespacedFunctionEv"] + pub fn foo_NamespacedFunction(); +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct StructWithAllowlistedDefinition { + pub other: *mut StructWithAllowlistedFwdDecl, +} +#[test] +fn bindgen_test_layout_StructWithAllowlistedDefinition() { + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(StructWithAllowlistedDefinition)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(StructWithAllowlistedDefinition)) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).other + as *const _ as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(StructWithAllowlistedDefinition), + "::", + stringify!(other) + ) + ); +} +impl Default for StructWithAllowlistedDefinition { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct StructWithAllowlistedFwdDecl { + pub b: ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout_StructWithAllowlistedFwdDecl() { + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(StructWithAllowlistedFwdDecl)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(StructWithAllowlistedFwdDecl)) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).b + as *const _ as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(StructWithAllowlistedFwdDecl), + "::", + stringify!(b) + ) + ); +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct AllowlistMe { + pub foo: ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout_AllowlistMe() { + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(AllowlistMe)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(AllowlistMe)) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).foo as *const _ as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(AllowlistMe), + "::", + stringify!(foo) + ) + ); +} diff --git a/tests/headers/allowlist-file.hpp b/tests/headers/allowlist-file.hpp new file mode 100644 index 0000000000..b0354a047f --- /dev/null +++ b/tests/headers/allowlist-file.hpp @@ -0,0 +1,21 @@ +// bindgen-flags: --allowlist-file ".*/allowlisted/file.*" --allowlist-type AllowlistMe -- -Itests/headers + + +// Forward declaration of struct that's defined in an allowlisted file. +struct StructWithAllowlistedDefinition; + +#include "allowlisted/file.hpp" + +// Actual definition of struct that has a forward declaration in an allowlisted file. +struct StructWithAllowlistedFwdDecl { + int b; +}; + +class Ignored { + char c; +}; + +// Also have an explicitly allowlisted type +class AllowlistMe { + int foo; +}; diff --git a/tests/headers/allowlisted/file.hpp b/tests/headers/allowlisted/file.hpp new file mode 100644 index 0000000000..5f360e5ea9 --- /dev/null +++ b/tests/headers/allowlisted/file.hpp @@ -0,0 +1,22 @@ +void SomeFunction(); +extern int someVar; +#define SOME_DEFUN 123 + +class someClass { + void somePrivateMethod(); +public: + void somePublicMethod(int foo); +}; + +extern "C" void ExternFunction(); + +namespace foo { + void NamespacedFunction(); +} + + +struct StructWithAllowlistedFwdDecl; + +struct StructWithAllowlistedDefinition { + StructWithAllowlistedFwdDecl* other; +}; From 68d2b0e0f8a4766ad5f73ae92c5e1e7be36df7f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Fri, 18 Feb 2022 19:45:20 +0100 Subject: [PATCH 265/942] Put vtable generation behind a flag for now. --- src/codegen/mod.rs | 5 +++-- src/lib.rs | 16 ++++++++++++++++ src/options.rs | 7 +++++++ tests/tests.rs | 1 + 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 5ce42c3449..3face26476 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -1045,7 +1045,8 @@ impl<'a> CodeGenerator for Vtable<'a> { // For now, we will only generate vtables for classes that: // - do not inherit from others (compilers merge VTable from primary parent class). // - do not contain a virtual destructor (requires ordering; platforms generate different vtables). - if self.comp_info.base_members().is_empty() && + if ctx.options().vtable_generation && + self.comp_info.base_members().is_empty() && self.comp_info.destructor().is_none() { let class_ident = ctx.rust_ident(self.item_id.canonical_name(ctx)); @@ -1793,7 +1794,7 @@ impl CodeGenerator for CompInfo { if !is_opaque { if item.has_vtable_ptr(ctx) { - let vtable = Vtable::new(item.id(), &self); + let vtable = Vtable::new(item.id(), self); vtable.codegen(ctx, result, item); let vtable_type = vtable diff --git a/src/lib.rs b/src/lib.rs index ea5c61b405..baea21b7e0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -569,6 +569,10 @@ impl Builder { output_vector.push("--explicit-padding".into()); } + if self.options.vtable_generation { + output_vector.push("--vtable-generation".into()); + } + // Add clang arguments output_vector.push("--".into()); @@ -1450,6 +1454,14 @@ impl Builder { self } + /// If true, enables experimental support to generate vtable functions. + /// + /// Should mostly work, though some edge cases are likely to be broken. + pub fn vtable_generation(mut self, doit: bool) -> Self { + self.options.vtable_generation = doit; + self + } + /// Generate the Rust bindings using the options built up thus far. pub fn generate(mut self) -> Result { // Add any extra arguments from the environment to the clang command line. @@ -1981,6 +1993,9 @@ struct BindgenOptions { /// Always output explicit padding fields force_explicit_padding: bool, + + /// Emit vtable functions. + vtable_generation: bool, } /// TODO(emilio): This is sort of a lie (see the error message that results from @@ -2128,6 +2143,7 @@ impl Default for BindgenOptions { translate_enum_integer_types: false, c_naming: false, force_explicit_padding: false, + vtable_generation: false, } } } diff --git a/src/options.rs b/src/options.rs index 04d42ed5c3..081aad61da 100644 --- a/src/options.rs +++ b/src/options.rs @@ -542,6 +542,9 @@ where Arg::new("explicit-padding") .long("explicit-padding") .help("Always output explicit padding fields."), + Arg::new("vtable-generation") + .long("vtable-generation") + .help("Enables generation of vtable functions."), ]) // .args() .get_matches_from(args); @@ -1008,6 +1011,10 @@ where builder = builder.explicit_padding(true); } + if matches.is_present("vtable-generation") { + builder = builder.vtable_generation(true); + } + let verbose = matches.is_present("verbose"); Ok((builder, output, verbose)) diff --git a/tests/tests.rs b/tests/tests.rs index 274c568301..1f116c93b3 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -365,6 +365,7 @@ fn create_bindgen_builder(header: &Path) -> Result { "--no-rustfmt-bindings", "--with-derive-default", "--disable-header-comment", + "--vtable-generation", header_str, "--raw-line", "", From cd78b6540789b22b79c1058fec4fdfe3449ea50e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Fri, 18 Feb 2022 19:47:12 +0100 Subject: [PATCH 266/942] codegen: Use raw pointers rather than references in vtable functions. Closes #2163 --- src/codegen/mod.rs | 4 ++-- tests/expectations/tests/enum_and_vtable_mangling.rs | 2 +- tests/expectations/tests/nested_vtable.rs | 2 +- tests/expectations/tests/ref_argument_array.rs | 2 +- tests/expectations/tests/virtual_interface.rs | 6 +++--- tests/expectations/tests/virtual_overloaded.rs | 4 ++-- tests/expectations/tests/vtable_recursive_sig.rs | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 3face26476..ffb21d13b3 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -1077,9 +1077,9 @@ impl<'a> CodeGenerator for Vtable<'a> { let ret = utils::fnsig_return_ty(ctx, signature); args[0] = if m.is_const() { - quote! { this: & #class_ident } + quote! { this: *const #class_ident } } else { - quote! { this: &mut #class_ident } + quote! { this: *mut #class_ident } }; Some(quote! { diff --git a/tests/expectations/tests/enum_and_vtable_mangling.rs b/tests/expectations/tests/enum_and_vtable_mangling.rs index bd6f7ff603..5ae76c4c29 100644 --- a/tests/expectations/tests/enum_and_vtable_mangling.rs +++ b/tests/expectations/tests/enum_and_vtable_mangling.rs @@ -15,7 +15,7 @@ pub enum _bindgen_ty_1 { } #[repr(C)] pub struct C__bindgen_vtable { - pub C_match: unsafe extern "C" fn(this: &mut C), + pub C_match: unsafe extern "C" fn(this: *mut C), } #[repr(C)] #[derive(Debug, Copy, Clone)] diff --git a/tests/expectations/tests/nested_vtable.rs b/tests/expectations/tests/nested_vtable.rs index 8747a59f11..7ee483044e 100644 --- a/tests/expectations/tests/nested_vtable.rs +++ b/tests/expectations/tests/nested_vtable.rs @@ -8,7 +8,7 @@ #[repr(C)] pub struct nsISupports__bindgen_vtable { pub nsISupports_QueryInterface: - unsafe extern "C" fn(this: &mut nsISupports) -> *mut nsISupports, + unsafe extern "C" fn(this: *mut nsISupports) -> *mut nsISupports, } #[repr(C)] #[derive(Debug, Copy, Clone)] diff --git a/tests/expectations/tests/ref_argument_array.rs b/tests/expectations/tests/ref_argument_array.rs index a99bf2c3bf..00a8e0ee35 100644 --- a/tests/expectations/tests/ref_argument_array.rs +++ b/tests/expectations/tests/ref_argument_array.rs @@ -9,7 +9,7 @@ pub const NSID_LENGTH: u32 = 10; #[repr(C)] pub struct nsID__bindgen_vtable { pub nsID_ToProvidedString: unsafe extern "C" fn( - this: &mut nsID, + this: *mut nsID, aDest: *mut [::std::os::raw::c_char; 10usize], ), } diff --git a/tests/expectations/tests/virtual_interface.rs b/tests/expectations/tests/virtual_interface.rs index 7677c51fb6..be94f23205 100644 --- a/tests/expectations/tests/virtual_interface.rs +++ b/tests/expectations/tests/virtual_interface.rs @@ -7,9 +7,9 @@ #[repr(C)] pub struct PureVirtualIFace__bindgen_vtable { - pub PureVirtualIFace_Foo: unsafe extern "C" fn(this: &mut PureVirtualIFace), + pub PureVirtualIFace_Foo: unsafe extern "C" fn(this: *mut PureVirtualIFace), pub PureVirtualIFace_Bar: unsafe extern "C" fn( - this: &mut PureVirtualIFace, + this: *mut PureVirtualIFace, arg1: ::std::os::raw::c_uint, ), } @@ -42,7 +42,7 @@ impl Default for PureVirtualIFace { } #[repr(C)] pub struct AnotherInterface__bindgen_vtable { - pub AnotherInterface_Baz: unsafe extern "C" fn(this: &mut AnotherInterface), + pub AnotherInterface_Baz: unsafe extern "C" fn(this: *mut AnotherInterface), } #[repr(C)] #[derive(Debug, Copy, Clone)] diff --git a/tests/expectations/tests/virtual_overloaded.rs b/tests/expectations/tests/virtual_overloaded.rs index 3fcfe33e61..c117d9ef6c 100644 --- a/tests/expectations/tests/virtual_overloaded.rs +++ b/tests/expectations/tests/virtual_overloaded.rs @@ -8,9 +8,9 @@ #[repr(C)] pub struct C__bindgen_vtable { pub C_do_thing: - unsafe extern "C" fn(this: &mut C, arg1: ::std::os::raw::c_char), + unsafe extern "C" fn(this: *mut C, arg1: ::std::os::raw::c_char), pub C_do_thing1: - unsafe extern "C" fn(this: &mut C, arg1: ::std::os::raw::c_int), + unsafe extern "C" fn(this: *mut C, arg1: ::std::os::raw::c_int), } #[repr(C)] #[derive(Debug, Copy, Clone)] diff --git a/tests/expectations/tests/vtable_recursive_sig.rs b/tests/expectations/tests/vtable_recursive_sig.rs index dd1b0f4d16..74e1dc7914 100644 --- a/tests/expectations/tests/vtable_recursive_sig.rs +++ b/tests/expectations/tests/vtable_recursive_sig.rs @@ -7,7 +7,7 @@ #[repr(C)] pub struct Base__bindgen_vtable { - pub Base_AsDerived: unsafe extern "C" fn(this: &mut Base) -> *mut Derived, + pub Base_AsDerived: unsafe extern "C" fn(this: *mut Base) -> *mut Derived, } #[repr(C)] #[derive(Debug, Copy, Clone)] From f34e4103f304500c96d332f5cecc9067c980d0f9 Mon Sep 17 00:00:00 2001 From: Nicklas Boman Date: Wed, 4 Aug 2021 23:32:20 +0200 Subject: [PATCH 267/942] BINDGEN_EXTRA_CLANG_ARGS for dump_preprocessed_input. Fixes #1723 --- src/lib.rs | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index baea21b7e0..0742217fe1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -232,6 +232,20 @@ pub fn builder() -> Builder { Default::default() } +fn get_extra_clang_args() -> Vec { + // Add any extra arguments from the environment to the clang command line. + let extra_clang_args = + match get_target_dependent_env_var("BINDGEN_EXTRA_CLANG_ARGS") { + None => return vec![], + Some(s) => s, + }; + // Try to parse it with shell quoting. If we fail, make it one single big argument. + if let Some(strings) = shlex::split(&extra_clang_args) { + return strings; + } + vec![extra_clang_args] +} + impl Builder { /// Generates the command line flags use for creating `Builder`. pub fn command_line_flags(&self) -> Vec { @@ -1465,16 +1479,7 @@ impl Builder { /// Generate the Rust bindings using the options built up thus far. pub fn generate(mut self) -> Result { // Add any extra arguments from the environment to the clang command line. - if let Some(extra_clang_args) = - get_target_dependent_env_var("BINDGEN_EXTRA_CLANG_ARGS") - { - // Try to parse it with shell quoting. If we fail, make it one single big argument. - if let Some(strings) = shlex::split(&extra_clang_args) { - self.options.clang_args.extend(strings); - } else { - self.options.clang_args.push(extra_clang_args); - }; - } + self.options.clang_args.extend(get_extra_clang_args()); // Transform input headers to arguments on the clang command line. self.options.input_header = self.input_headers.pop(); @@ -1561,6 +1566,10 @@ impl Builder { cmd.arg(a); } + for a in get_extra_clang_args() { + cmd.arg(a); + } + let mut child = cmd.spawn()?; let mut preprocessed = child.stdout.take().unwrap(); From 6a169f21344d541ab4790dee894d2cc9e51a0345 Mon Sep 17 00:00:00 2001 From: Sebastian Imlay Date: Mon, 7 Mar 2022 16:14:52 -0500 Subject: [PATCH 268/942] Fix macOS test expectations * Updated tests/expectations/Cargo.toml to use 2018 rust. * Added Debug and Copy to objective-c structs. * Fixed lifetimes in objective-c trait templates. * Fixed imports for objective-c expectations tests. --- .github/workflows/bindgen.yml | 2 +- CHANGELOG.md | 8 ++++ src/codegen/mod.rs | 8 ++-- tests/expectations/Cargo.toml | 1 + .../tests/libclang-4/objc_inheritance.rs | 15 +++--- .../tests/libclang-4/objc_template.rs | 15 +++--- .../tests/libclang-5/objc_inheritance.rs | 15 +++--- .../tests/libclang-5/objc_template.rs | 15 +++--- .../tests/libclang-9/objc_inheritance.rs | 15 +++--- .../tests/libclang-9/objc_template.rs | 15 +++--- tests/expectations/tests/objc_allowlist.rs | 48 ++++++++++++++++++- tests/expectations/tests/objc_category.rs | 7 ++- tests/expectations/tests/objc_class.rs | 7 ++- tests/expectations/tests/objc_class_method.rs | 7 ++- tests/expectations/tests/objc_interface.rs | 7 ++- .../expectations/tests/objc_interface_type.rs | 7 ++- tests/expectations/tests/objc_method.rs | 7 ++- tests/expectations/tests/objc_method_clash.rs | 7 ++- .../tests/objc_pointer_return_types.rs | 11 ++--- .../expectations/tests/objc_property_fnptr.rs | 7 ++- tests/expectations/tests/objc_protocol.rs | 7 ++- .../tests/objc_protocol_inheritance.rs | 11 ++--- tests/expectations/tests/objc_sel_and_id.rs | 3 +- tests/headers/objc_allowlist.h | 2 +- tests/headers/objc_category.h | 2 +- tests/headers/objc_class.h | 2 +- tests/headers/objc_class_method.h | 2 +- tests/headers/objc_inheritance.h | 2 +- tests/headers/objc_interface.h | 2 +- tests/headers/objc_interface_type.h | 2 +- tests/headers/objc_method.h | 2 +- tests/headers/objc_method_clash.h | 2 +- tests/headers/objc_pointer_return_types.h | 2 +- tests/headers/objc_property_fnptr.h | 2 +- tests/headers/objc_protocol.h | 2 +- tests/headers/objc_protocol_inheritance.h | 2 +- tests/headers/objc_sel_and_id.h | 2 +- tests/headers/objc_template.h | 2 +- 38 files changed, 155 insertions(+), 120 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 87b2cdb1d8..e8cd10bf29 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -76,7 +76,7 @@ jobs: matrix: # TODO(#1954): These should be run on mac too, but turns out they're # broken. - os: [ubuntu-latest] + os: [ubuntu-latest, macos-latest] steps: - uses: actions/checkout@v2 diff --git a/CHANGELOG.md b/CHANGELOG.md index 73c405c7da..7f206c9cc0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -140,8 +140,13 @@ ## Added + * Objective-C structs now derive `Debug` and `Copy` to support C and Objective-C structs. [(#2176)][] + ## Fixed + * Fixed lifetimes with Objective-C trait templates. [(#2176)][] + * Fixed objc imports for non-`#[macro_use]` use. [(#2176)][] + ## Changed * cexpr and nom have been updated, new msrv is 1.46 (#2107). @@ -154,6 +159,9 @@ ## Security + + [(#2176)]: https://github.com/rust-lang/rust-bindgen/pull/2176 + # 0.59.1 Released 2021/07/26 diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index ffb21d13b3..a0a0670cb2 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -4129,7 +4129,7 @@ impl CodeGenerator for ObjCInterface { .collect(); quote! { - pub trait #trait_name <#(#template_names),*> : #trait_constraints { + pub trait #trait_name <#(#template_names:'static),*> : #trait_constraints { #( #impl_items )* } } @@ -4145,7 +4145,7 @@ impl CodeGenerator for ObjCInterface { if !self.is_category() && !self.is_protocol() { let struct_block = quote! { #[repr(transparent)] - #[derive(Clone)] + #[derive(Debug, Copy, Clone)] pub struct #class_name(pub id); impl std::ops::Deref for #class_name { type Target = objc::runtime::Object; @@ -4159,7 +4159,7 @@ impl CodeGenerator for ObjCInterface { impl #class_name { pub fn alloc() -> Self { Self(unsafe { - msg_send!(objc::class!(#class_name), alloc) + msg_send!(class!(#class_name), alloc) }) } } @@ -4381,7 +4381,7 @@ pub mod utils { } } else { quote! { - use objc; + use objc::{self, msg_send, sel, sel_impl, class}; } }; diff --git a/tests/expectations/Cargo.toml b/tests/expectations/Cargo.toml index c78cc09a0b..f8006afeab 100644 --- a/tests/expectations/Cargo.toml +++ b/tests/expectations/Cargo.toml @@ -7,6 +7,7 @@ authors = [ "Emilio Cobos Álvarez ", "The Servo project developers", ] +edition = "2018" [dependencies] objc = "0.2" diff --git a/tests/expectations/tests/libclang-4/objc_inheritance.rs b/tests/expectations/tests/libclang-4/objc_inheritance.rs index 5f07dbaab1..f1c2a88cb0 100644 --- a/tests/expectations/tests/libclang-4/objc_inheritance.rs +++ b/tests/expectations/tests/libclang-4/objc_inheritance.rs @@ -6,12 +6,11 @@ )] #![cfg(target_os = "macos")] -#[macro_use] -extern crate objc; +use objc::{self, class, msg_send, sel, sel_impl}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -22,13 +21,13 @@ impl std::ops::Deref for Foo { unsafe impl objc::Message for Foo {} impl Foo { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Foo), alloc) }) + Self(unsafe { msg_send!(class!(Foo), alloc) }) } } impl IFoo for Foo {} pub trait IFoo: Sized + std::ops::Deref {} #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Bar(pub id); impl std::ops::Deref for Bar { type Target = objc::runtime::Object; @@ -39,7 +38,7 @@ impl std::ops::Deref for Bar { unsafe impl objc::Message for Bar {} impl Bar { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Bar), alloc) }) + Self(unsafe { msg_send!(class!(Bar), alloc) }) } } impl IFoo for Bar {} @@ -63,7 +62,7 @@ impl std::convert::TryFrom for Bar { impl IBar for Bar {} pub trait IBar: Sized + std::ops::Deref {} #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Baz(pub id); impl std::ops::Deref for Baz { type Target = objc::runtime::Object; @@ -74,7 +73,7 @@ impl std::ops::Deref for Baz { unsafe impl objc::Message for Baz {} impl Baz { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Baz), alloc) }) + Self(unsafe { msg_send!(class!(Baz), alloc) }) } } impl IBar for Baz {} diff --git a/tests/expectations/tests/libclang-4/objc_template.rs b/tests/expectations/tests/libclang-4/objc_template.rs index 36b7d22baa..53caa661c6 100644 --- a/tests/expectations/tests/libclang-4/objc_template.rs +++ b/tests/expectations/tests/libclang-4/objc_template.rs @@ -6,12 +6,11 @@ )] #![cfg(target_os = "macos")] -#[macro_use] -extern crate objc; +use objc::{self, class, msg_send, sel, sel_impl}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -22,11 +21,11 @@ impl std::ops::Deref for Foo { unsafe impl objc::Message for Foo {} impl Foo { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Foo), alloc) }) + Self(unsafe { msg_send!(class!(Foo), alloc) }) } } impl IFoo for Foo {} -pub trait IFoo: Sized + std::ops::Deref { +pub trait IFoo: Sized + std::ops::Deref { unsafe fn get(&self) -> *mut ObjectType where ::Target: objc::Message + Sized, @@ -35,7 +34,7 @@ pub trait IFoo: Sized + std::ops::Deref { } } #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct FooMultiGeneric(pub id); impl std::ops::Deref for FooMultiGeneric { type Target = objc::runtime::Object; @@ -46,14 +45,14 @@ impl std::ops::Deref for FooMultiGeneric { unsafe impl objc::Message for FooMultiGeneric {} impl FooMultiGeneric { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(FooMultiGeneric), alloc) }) + Self(unsafe { msg_send!(class!(FooMultiGeneric), alloc) }) } } impl IFooMultiGeneric for FooMultiGeneric { } -pub trait IFooMultiGeneric: +pub trait IFooMultiGeneric: Sized + std::ops::Deref { unsafe fn objectForKey_(&self, key: *mut KeyType) -> *mut ObjectType diff --git a/tests/expectations/tests/libclang-5/objc_inheritance.rs b/tests/expectations/tests/libclang-5/objc_inheritance.rs index 5f07dbaab1..f1c2a88cb0 100644 --- a/tests/expectations/tests/libclang-5/objc_inheritance.rs +++ b/tests/expectations/tests/libclang-5/objc_inheritance.rs @@ -6,12 +6,11 @@ )] #![cfg(target_os = "macos")] -#[macro_use] -extern crate objc; +use objc::{self, class, msg_send, sel, sel_impl}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -22,13 +21,13 @@ impl std::ops::Deref for Foo { unsafe impl objc::Message for Foo {} impl Foo { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Foo), alloc) }) + Self(unsafe { msg_send!(class!(Foo), alloc) }) } } impl IFoo for Foo {} pub trait IFoo: Sized + std::ops::Deref {} #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Bar(pub id); impl std::ops::Deref for Bar { type Target = objc::runtime::Object; @@ -39,7 +38,7 @@ impl std::ops::Deref for Bar { unsafe impl objc::Message for Bar {} impl Bar { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Bar), alloc) }) + Self(unsafe { msg_send!(class!(Bar), alloc) }) } } impl IFoo for Bar {} @@ -63,7 +62,7 @@ impl std::convert::TryFrom for Bar { impl IBar for Bar {} pub trait IBar: Sized + std::ops::Deref {} #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Baz(pub id); impl std::ops::Deref for Baz { type Target = objc::runtime::Object; @@ -74,7 +73,7 @@ impl std::ops::Deref for Baz { unsafe impl objc::Message for Baz {} impl Baz { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Baz), alloc) }) + Self(unsafe { msg_send!(class!(Baz), alloc) }) } } impl IBar for Baz {} diff --git a/tests/expectations/tests/libclang-5/objc_template.rs b/tests/expectations/tests/libclang-5/objc_template.rs index 36b7d22baa..53caa661c6 100644 --- a/tests/expectations/tests/libclang-5/objc_template.rs +++ b/tests/expectations/tests/libclang-5/objc_template.rs @@ -6,12 +6,11 @@ )] #![cfg(target_os = "macos")] -#[macro_use] -extern crate objc; +use objc::{self, class, msg_send, sel, sel_impl}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -22,11 +21,11 @@ impl std::ops::Deref for Foo { unsafe impl objc::Message for Foo {} impl Foo { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Foo), alloc) }) + Self(unsafe { msg_send!(class!(Foo), alloc) }) } } impl IFoo for Foo {} -pub trait IFoo: Sized + std::ops::Deref { +pub trait IFoo: Sized + std::ops::Deref { unsafe fn get(&self) -> *mut ObjectType where ::Target: objc::Message + Sized, @@ -35,7 +34,7 @@ pub trait IFoo: Sized + std::ops::Deref { } } #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct FooMultiGeneric(pub id); impl std::ops::Deref for FooMultiGeneric { type Target = objc::runtime::Object; @@ -46,14 +45,14 @@ impl std::ops::Deref for FooMultiGeneric { unsafe impl objc::Message for FooMultiGeneric {} impl FooMultiGeneric { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(FooMultiGeneric), alloc) }) + Self(unsafe { msg_send!(class!(FooMultiGeneric), alloc) }) } } impl IFooMultiGeneric for FooMultiGeneric { } -pub trait IFooMultiGeneric: +pub trait IFooMultiGeneric: Sized + std::ops::Deref { unsafe fn objectForKey_(&self, key: *mut KeyType) -> *mut ObjectType diff --git a/tests/expectations/tests/libclang-9/objc_inheritance.rs b/tests/expectations/tests/libclang-9/objc_inheritance.rs index 5f07dbaab1..f1c2a88cb0 100644 --- a/tests/expectations/tests/libclang-9/objc_inheritance.rs +++ b/tests/expectations/tests/libclang-9/objc_inheritance.rs @@ -6,12 +6,11 @@ )] #![cfg(target_os = "macos")] -#[macro_use] -extern crate objc; +use objc::{self, class, msg_send, sel, sel_impl}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -22,13 +21,13 @@ impl std::ops::Deref for Foo { unsafe impl objc::Message for Foo {} impl Foo { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Foo), alloc) }) + Self(unsafe { msg_send!(class!(Foo), alloc) }) } } impl IFoo for Foo {} pub trait IFoo: Sized + std::ops::Deref {} #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Bar(pub id); impl std::ops::Deref for Bar { type Target = objc::runtime::Object; @@ -39,7 +38,7 @@ impl std::ops::Deref for Bar { unsafe impl objc::Message for Bar {} impl Bar { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Bar), alloc) }) + Self(unsafe { msg_send!(class!(Bar), alloc) }) } } impl IFoo for Bar {} @@ -63,7 +62,7 @@ impl std::convert::TryFrom for Bar { impl IBar for Bar {} pub trait IBar: Sized + std::ops::Deref {} #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Baz(pub id); impl std::ops::Deref for Baz { type Target = objc::runtime::Object; @@ -74,7 +73,7 @@ impl std::ops::Deref for Baz { unsafe impl objc::Message for Baz {} impl Baz { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Baz), alloc) }) + Self(unsafe { msg_send!(class!(Baz), alloc) }) } } impl IBar for Baz {} diff --git a/tests/expectations/tests/libclang-9/objc_template.rs b/tests/expectations/tests/libclang-9/objc_template.rs index 88cf209bdf..3c615035ce 100644 --- a/tests/expectations/tests/libclang-9/objc_template.rs +++ b/tests/expectations/tests/libclang-9/objc_template.rs @@ -6,12 +6,11 @@ )] #![cfg(target_os = "macos")] -#[macro_use] -extern crate objc; +use objc::{self, class, msg_send, sel, sel_impl}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -22,11 +21,11 @@ impl std::ops::Deref for Foo { unsafe impl objc::Message for Foo {} impl Foo { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Foo), alloc) }) + Self(unsafe { msg_send!(class!(Foo), alloc) }) } } impl IFoo for Foo {} -pub trait IFoo: Sized + std::ops::Deref { +pub trait IFoo: Sized + std::ops::Deref { unsafe fn get(&self) -> u64 where ::Target: objc::Message + Sized, @@ -35,7 +34,7 @@ pub trait IFoo: Sized + std::ops::Deref { } } #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct FooMultiGeneric(pub id); impl std::ops::Deref for FooMultiGeneric { type Target = objc::runtime::Object; @@ -46,14 +45,14 @@ impl std::ops::Deref for FooMultiGeneric { unsafe impl objc::Message for FooMultiGeneric {} impl FooMultiGeneric { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(FooMultiGeneric), alloc) }) + Self(unsafe { msg_send!(class!(FooMultiGeneric), alloc) }) } } impl IFooMultiGeneric for FooMultiGeneric { } -pub trait IFooMultiGeneric: +pub trait IFooMultiGeneric: Sized + std::ops::Deref { unsafe fn objectForKey_(&self, key: u64) -> u64 diff --git a/tests/expectations/tests/objc_allowlist.rs b/tests/expectations/tests/objc_allowlist.rs index dcec0fd12e..370cab9332 100644 --- a/tests/expectations/tests/objc_allowlist.rs +++ b/tests/expectations/tests/objc_allowlist.rs @@ -6,9 +6,53 @@ )] #![cfg(target_os = "macos")] -#[macro_use] -extern crate objc; +use objc::{self, class, msg_send, sel, sel_impl}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; +pub trait PSomeProtocol: Sized + std::ops::Deref { + unsafe fn protocolMethod(&self) + where + ::Target: objc::Message + Sized, + { + msg_send!(*self, protocolMethod) + } + unsafe fn protocolClassMethod() + where + ::Target: objc::Message + Sized, + { + msg_send!(class!(SomeProtocol), protocolClassMethod) + } +} +#[repr(transparent)] +#[derive(Debug, Copy, Clone)] +pub struct AllowlistMe(pub id); +impl std::ops::Deref for AllowlistMe { + type Target = objc::runtime::Object; + fn deref(&self) -> &Self::Target { + unsafe { &*self.0 } + } +} +unsafe impl objc::Message for AllowlistMe {} +impl AllowlistMe { + pub fn alloc() -> Self { + Self(unsafe { msg_send!(class!(AllowlistMe), alloc) }) + } +} +impl PSomeProtocol for AllowlistMe {} +impl IAllowlistMe for AllowlistMe {} +pub trait IAllowlistMe: Sized + std::ops::Deref { + unsafe fn method(&self) + where + ::Target: objc::Message + Sized, + { + msg_send!(*self, method) + } + unsafe fn classMethod() + where + ::Target: objc::Message + Sized, + { + msg_send!(class!(AllowlistMe), classMethod) + } +} impl AllowlistMe_InterestingCategory for AllowlistMe {} pub trait AllowlistMe_InterestingCategory: Sized + std::ops::Deref {} diff --git a/tests/expectations/tests/objc_category.rs b/tests/expectations/tests/objc_category.rs index e0328c708f..9d60233bed 100644 --- a/tests/expectations/tests/objc_category.rs +++ b/tests/expectations/tests/objc_category.rs @@ -6,12 +6,11 @@ )] #![cfg(target_os = "macos")] -#[macro_use] -extern crate objc; +use objc::{self, class, msg_send, sel, sel_impl}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -22,7 +21,7 @@ impl std::ops::Deref for Foo { unsafe impl objc::Message for Foo {} impl Foo { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Foo), alloc) }) + Self(unsafe { msg_send!(class!(Foo), alloc) }) } } impl IFoo for Foo {} diff --git a/tests/expectations/tests/objc_class.rs b/tests/expectations/tests/objc_class.rs index 5a8a71d164..b322bddcb6 100644 --- a/tests/expectations/tests/objc_class.rs +++ b/tests/expectations/tests/objc_class.rs @@ -6,15 +6,14 @@ )] #![cfg(target_os = "macos")] -#[macro_use] -extern crate objc; +use objc::{self, class, msg_send, sel, sel_impl}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; extern "C" { pub static mut fooVar: Foo; } #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -25,7 +24,7 @@ impl std::ops::Deref for Foo { unsafe impl objc::Message for Foo {} impl Foo { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Foo), alloc) }) + Self(unsafe { msg_send!(class!(Foo), alloc) }) } } impl IFoo for Foo {} diff --git a/tests/expectations/tests/objc_class_method.rs b/tests/expectations/tests/objc_class_method.rs index 26f2110f43..29e70256ff 100644 --- a/tests/expectations/tests/objc_class_method.rs +++ b/tests/expectations/tests/objc_class_method.rs @@ -6,12 +6,11 @@ )] #![cfg(target_os = "macos")] -#[macro_use] -extern crate objc; +use objc::{self, class, msg_send, sel, sel_impl}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -22,7 +21,7 @@ impl std::ops::Deref for Foo { unsafe impl objc::Message for Foo {} impl Foo { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Foo), alloc) }) + Self(unsafe { msg_send!(class!(Foo), alloc) }) } } impl IFoo for Foo {} diff --git a/tests/expectations/tests/objc_interface.rs b/tests/expectations/tests/objc_interface.rs index c5ba2758b9..89e64d86b6 100644 --- a/tests/expectations/tests/objc_interface.rs +++ b/tests/expectations/tests/objc_interface.rs @@ -6,12 +6,11 @@ )] #![cfg(target_os = "macos")] -#[macro_use] -extern crate objc; +use objc::{self, class, msg_send, sel, sel_impl}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -22,7 +21,7 @@ impl std::ops::Deref for Foo { unsafe impl objc::Message for Foo {} impl Foo { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Foo), alloc) }) + Self(unsafe { msg_send!(class!(Foo), alloc) }) } } impl IFoo for Foo {} diff --git a/tests/expectations/tests/objc_interface_type.rs b/tests/expectations/tests/objc_interface_type.rs index cef29c8c96..4ffb15d303 100644 --- a/tests/expectations/tests/objc_interface_type.rs +++ b/tests/expectations/tests/objc_interface_type.rs @@ -6,12 +6,11 @@ )] #![cfg(target_os = "macos")] -#[macro_use] -extern crate objc; +use objc::{self, class, msg_send, sel, sel_impl}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -22,7 +21,7 @@ impl std::ops::Deref for Foo { unsafe impl objc::Message for Foo {} impl Foo { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Foo), alloc) }) + Self(unsafe { msg_send!(class!(Foo), alloc) }) } } impl IFoo for Foo {} diff --git a/tests/expectations/tests/objc_method.rs b/tests/expectations/tests/objc_method.rs index af5c6093db..593fd27738 100644 --- a/tests/expectations/tests/objc_method.rs +++ b/tests/expectations/tests/objc_method.rs @@ -6,12 +6,11 @@ )] #![cfg(target_os = "macos")] -#[macro_use] -extern crate objc; +use objc::{self, class, msg_send, sel, sel_impl}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -22,7 +21,7 @@ impl std::ops::Deref for Foo { unsafe impl objc::Message for Foo {} impl Foo { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Foo), alloc) }) + Self(unsafe { msg_send!(class!(Foo), alloc) }) } } impl IFoo for Foo {} diff --git a/tests/expectations/tests/objc_method_clash.rs b/tests/expectations/tests/objc_method_clash.rs index 8370f33fc2..ac77cc19e3 100644 --- a/tests/expectations/tests/objc_method_clash.rs +++ b/tests/expectations/tests/objc_method_clash.rs @@ -6,12 +6,11 @@ )] #![cfg(target_os = "macos")] -#[macro_use] -extern crate objc; +use objc::{self, class, msg_send, sel, sel_impl}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -22,7 +21,7 @@ impl std::ops::Deref for Foo { unsafe impl objc::Message for Foo {} impl Foo { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Foo), alloc) }) + Self(unsafe { msg_send!(class!(Foo), alloc) }) } } impl IFoo for Foo {} diff --git a/tests/expectations/tests/objc_pointer_return_types.rs b/tests/expectations/tests/objc_pointer_return_types.rs index c9b6b52a6b..1ec8494d25 100644 --- a/tests/expectations/tests/objc_pointer_return_types.rs +++ b/tests/expectations/tests/objc_pointer_return_types.rs @@ -6,12 +6,11 @@ )] #![cfg(target_os = "macos")] -#[macro_use] -extern crate objc; +use objc::{self, class, msg_send, sel, sel_impl}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Bar(pub id); impl std::ops::Deref for Bar { type Target = objc::runtime::Object; @@ -22,13 +21,13 @@ impl std::ops::Deref for Bar { unsafe impl objc::Message for Bar {} impl Bar { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Bar), alloc) }) + Self(unsafe { msg_send!(class!(Bar), alloc) }) } } impl IBar for Bar {} pub trait IBar: Sized + std::ops::Deref {} #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -39,7 +38,7 @@ impl std::ops::Deref for Foo { unsafe impl objc::Message for Foo {} impl Foo { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Foo), alloc) }) + Self(unsafe { msg_send!(class!(Foo), alloc) }) } } impl IFoo for Foo {} diff --git a/tests/expectations/tests/objc_property_fnptr.rs b/tests/expectations/tests/objc_property_fnptr.rs index 85f18e9c18..9f3fabd272 100644 --- a/tests/expectations/tests/objc_property_fnptr.rs +++ b/tests/expectations/tests/objc_property_fnptr.rs @@ -6,12 +6,11 @@ )] #![cfg(target_os = "macos")] -#[macro_use] -extern crate objc; +use objc::{self, class, msg_send, sel, sel_impl}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -22,7 +21,7 @@ impl std::ops::Deref for Foo { unsafe impl objc::Message for Foo {} impl Foo { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Foo), alloc) }) + Self(unsafe { msg_send!(class!(Foo), alloc) }) } } impl IFoo for Foo {} diff --git a/tests/expectations/tests/objc_protocol.rs b/tests/expectations/tests/objc_protocol.rs index e68ddcc1d2..5bd7d433f4 100644 --- a/tests/expectations/tests/objc_protocol.rs +++ b/tests/expectations/tests/objc_protocol.rs @@ -6,13 +6,12 @@ )] #![cfg(target_os = "macos")] -#[macro_use] -extern crate objc; +use objc::{self, class, msg_send, sel, sel_impl}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; pub trait PFoo: Sized + std::ops::Deref {} #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -23,7 +22,7 @@ impl std::ops::Deref for Foo { unsafe impl objc::Message for Foo {} impl Foo { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Foo), alloc) }) + Self(unsafe { msg_send!(class!(Foo), alloc) }) } } impl PFoo for Foo {} diff --git a/tests/expectations/tests/objc_protocol_inheritance.rs b/tests/expectations/tests/objc_protocol_inheritance.rs index 598273ba35..f5f80e2e30 100644 --- a/tests/expectations/tests/objc_protocol_inheritance.rs +++ b/tests/expectations/tests/objc_protocol_inheritance.rs @@ -6,13 +6,12 @@ )] #![cfg(target_os = "macos")] -#[macro_use] -extern crate objc; +use objc::{self, class, msg_send, sel, sel_impl}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; pub trait PFoo: Sized + std::ops::Deref {} #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -23,14 +22,14 @@ impl std::ops::Deref for Foo { unsafe impl objc::Message for Foo {} impl Foo { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Foo), alloc) }) + Self(unsafe { msg_send!(class!(Foo), alloc) }) } } impl PFoo for Foo {} impl IFoo for Foo {} pub trait IFoo: Sized + std::ops::Deref {} #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Bar(pub id); impl std::ops::Deref for Bar { type Target = objc::runtime::Object; @@ -41,7 +40,7 @@ impl std::ops::Deref for Bar { unsafe impl objc::Message for Bar {} impl Bar { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Bar), alloc) }) + Self(unsafe { msg_send!(class!(Bar), alloc) }) } } impl IFoo for Bar {} diff --git a/tests/expectations/tests/objc_sel_and_id.rs b/tests/expectations/tests/objc_sel_and_id.rs index 2a389093df..0017eab00d 100644 --- a/tests/expectations/tests/objc_sel_and_id.rs +++ b/tests/expectations/tests/objc_sel_and_id.rs @@ -6,8 +6,7 @@ )] #![cfg(target_os = "macos")] -#[macro_use] -extern crate objc; +use objc::{self, class, msg_send, sel, sel_impl}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; extern "C" { diff --git a/tests/headers/objc_allowlist.h b/tests/headers/objc_allowlist.h index 8c939960b0..b5406d0adf 100644 --- a/tests/headers/objc_allowlist.h +++ b/tests/headers/objc_allowlist.h @@ -1,4 +1,4 @@ -// bindgen-flags: --objc-extern-crate --allowlist-type AllowlistMe --allowlist-type AllowlistMe_InterestingCategory -- -x objective-c +// bindgen-flags: --allowlist-type IAllowlistMe --allowlist-type AllowlistMe_InterestingCategory -- -x objective-c // bindgen-osx-only diff --git a/tests/headers/objc_category.h b/tests/headers/objc_category.h index c464b72eb2..b8e60d5fa9 100644 --- a/tests/headers/objc_category.h +++ b/tests/headers/objc_category.h @@ -1,4 +1,4 @@ -// bindgen-flags: --objc-extern-crate -- -x objective-c +// bindgen-flags: -- -x objective-c // bindgen-osx-only @interface Foo diff --git a/tests/headers/objc_class.h b/tests/headers/objc_class.h index cea72e78aa..f5ec950750 100644 --- a/tests/headers/objc_class.h +++ b/tests/headers/objc_class.h @@ -1,4 +1,4 @@ -// bindgen-flags: --objc-extern-crate -- -x objective-c +// bindgen-flags: -- -x objective-c // bindgen-osx-only @class Foo; diff --git a/tests/headers/objc_class_method.h b/tests/headers/objc_class_method.h index ddda742e8a..1a68ed3e6e 100644 --- a/tests/headers/objc_class_method.h +++ b/tests/headers/objc_class_method.h @@ -1,4 +1,4 @@ -// bindgen-flags: --objc-extern-crate -- -x objective-c +// bindgen-flags: -- -x objective-c // bindgen-osx-only @interface Foo diff --git a/tests/headers/objc_inheritance.h b/tests/headers/objc_inheritance.h index 8f96e45ba8..985f1597e5 100644 --- a/tests/headers/objc_inheritance.h +++ b/tests/headers/objc_inheritance.h @@ -1,4 +1,4 @@ -// bindgen-flags: --objc-extern-crate -- -x objective-c +// bindgen-flags: -- -x objective-c // bindgen-osx-only @interface Foo diff --git a/tests/headers/objc_interface.h b/tests/headers/objc_interface.h index af84bf925a..df16e921ec 100644 --- a/tests/headers/objc_interface.h +++ b/tests/headers/objc_interface.h @@ -1,4 +1,4 @@ -// bindgen-flags: --objc-extern-crate -- -x objective-c +// bindgen-flags: -- -x objective-c // bindgen-osx-only @interface Foo diff --git a/tests/headers/objc_interface_type.h b/tests/headers/objc_interface_type.h index 31d33664c1..4667ce2a0c 100644 --- a/tests/headers/objc_interface_type.h +++ b/tests/headers/objc_interface_type.h @@ -1,4 +1,4 @@ -// bindgen-flags: --objc-extern-crate -- -x objective-c +// bindgen-flags: -- -x objective-c // bindgen-osx-only @interface Foo diff --git a/tests/headers/objc_method.h b/tests/headers/objc_method.h index c4d375bac0..b89d1621b1 100644 --- a/tests/headers/objc_method.h +++ b/tests/headers/objc_method.h @@ -1,4 +1,4 @@ -// bindgen-flags: --objc-extern-crate -- -x objective-c +// bindgen-flags: -- -x objective-c // bindgen-osx-only @interface Foo diff --git a/tests/headers/objc_method_clash.h b/tests/headers/objc_method_clash.h index a56e39dba8..d99d3691fe 100644 --- a/tests/headers/objc_method_clash.h +++ b/tests/headers/objc_method_clash.h @@ -1,4 +1,4 @@ -// bindgen-flags: --objc-extern-crate -- -x objective-c +// bindgen-flags: -- -x objective-c // bindgen-osx-only @interface Foo diff --git a/tests/headers/objc_pointer_return_types.h b/tests/headers/objc_pointer_return_types.h index e289a8a53d..4d1a6dea34 100644 --- a/tests/headers/objc_pointer_return_types.h +++ b/tests/headers/objc_pointer_return_types.h @@ -1,4 +1,4 @@ -// bindgen-flags: --objc-extern-crate -- -x objective-c +// bindgen-flags: -- -x objective-c // bindgen-osx-only @interface Bar diff --git a/tests/headers/objc_property_fnptr.h b/tests/headers/objc_property_fnptr.h index bac0c779a9..fe3e7fcc99 100644 --- a/tests/headers/objc_property_fnptr.h +++ b/tests/headers/objc_property_fnptr.h @@ -1,4 +1,4 @@ -// bindgen-flags: --objc-extern-crate -- -x objective-c +// bindgen-flags: -- -x objective-c // bindgen-osx-only @interface Foo diff --git a/tests/headers/objc_protocol.h b/tests/headers/objc_protocol.h index 0c760fa51f..46978a3b4e 100644 --- a/tests/headers/objc_protocol.h +++ b/tests/headers/objc_protocol.h @@ -1,4 +1,4 @@ -// bindgen-flags: --objc-extern-crate -- -x objective-c +// bindgen-flags: -- -x objective-c // bindgen-osx-only @protocol Foo diff --git a/tests/headers/objc_protocol_inheritance.h b/tests/headers/objc_protocol_inheritance.h index d5f3a490e5..13135fddbc 100644 --- a/tests/headers/objc_protocol_inheritance.h +++ b/tests/headers/objc_protocol_inheritance.h @@ -1,4 +1,4 @@ -// bindgen-flags: --objc-extern-crate -- -x objective-c +// bindgen-flags: -- -x objective-c // bindgen-osx-only @protocol Foo diff --git a/tests/headers/objc_sel_and_id.h b/tests/headers/objc_sel_and_id.h index 3c8c656166..6491a541c6 100644 --- a/tests/headers/objc_sel_and_id.h +++ b/tests/headers/objc_sel_and_id.h @@ -1,4 +1,4 @@ -// bindgen-flags: --objc-extern-crate -- -x objective-c +// bindgen-flags: -- -x objective-c // bindgen-osx-only id object; diff --git a/tests/headers/objc_template.h b/tests/headers/objc_template.h index a4d0055c16..b616da013f 100644 --- a/tests/headers/objc_template.h +++ b/tests/headers/objc_template.h @@ -1,4 +1,4 @@ -// bindgen-flags: --objc-extern-crate -- -x objective-c +// bindgen-flags: -- -x objective-c // bindgen-osx-only @interface Foo<__covariant ObjectType> From 1b66dcf87692e455dc5e1603ca05d3f41b3f771b Mon Sep 17 00:00:00 2001 From: David Cole Date: Sun, 13 Mar 2022 12:30:06 +1300 Subject: [PATCH 269/942] Added support for `vectorcall` ABI --- src/codegen/mod.rs | 33 ++++++++++++++++--- src/features.rs | 11 +++++-- src/ir/function.rs | 4 +++ .../tests/win32-vectorcall-1_0.rs | 6 ++++ .../tests/win32-vectorcall-nightly.rs | 16 +++++++++ tests/headers/win32-vectorcall-1_0.h | 3 ++ tests/headers/win32-vectorcall-nightly.h | 3 ++ 7 files changed, 69 insertions(+), 7 deletions(-) create mode 100644 tests/expectations/tests/win32-vectorcall-1_0.rs create mode 100644 tests/expectations/tests/win32-vectorcall-nightly.rs create mode 100644 tests/headers/win32-vectorcall-1_0.h create mode 100644 tests/headers/win32-vectorcall-nightly.h diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index a0a0670cb2..1b54597fff 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -17,6 +17,7 @@ use self::struct_layout::StructLayoutTracker; use super::BindgenOptions; +use crate::features::RustFeatures; use crate::ir::analysis::{HasVtable, Sizedness}; use crate::ir::annotations::FieldAccessorKind; use crate::ir::comment; @@ -2414,10 +2415,22 @@ impl MethodCodegen for Method { _ => panic!("How in the world?"), }; - if let (Abi::ThisCall, false) = - (signature.abi(), ctx.options().rust_features().thiscall_abi) - { - return; + match (signature.abi(), ctx.options().rust_features()) { + ( + Abi::ThisCall, + RustFeatures { + thiscall_abi: false, + .. + }, + ) | + ( + Abi::Vectorcall, + RustFeatures { + vectorcall_abi: false, + .. + }, + ) => return, + _ => {} } // Do not generate variadic methods, since rust does not allow @@ -3867,6 +3880,12 @@ impl TryToRustTy for FunctionSig { warn!("Skipping function with thiscall ABI that isn't supported by the configured Rust target"); Ok(proc_macro2::TokenStream::new()) } + Abi::Vectorcall + if !ctx.options().rust_features().vectorcall_abi => + { + warn!("Skipping function with vectorcall ABI that isn't supported by the configured Rust target"); + Ok(proc_macro2::TokenStream::new()) + } _ => Ok(quote! { unsafe extern #abi fn ( #( #arguments ),* ) #ret }), @@ -3958,6 +3977,12 @@ impl CodeGenerator for Function { warn!("Skipping function with thiscall ABI that isn't supported by the configured Rust target"); return None; } + Abi::Vectorcall + if !ctx.options().rust_features().vectorcall_abi => + { + warn!("Skipping function with vectorcall ABI that isn't supported by the configured Rust target"); + return None; + } Abi::Win64 if signature.is_variadic() => { warn!("Skipping variadic function with Win64 ABI that isn't supported"); return None; diff --git a/src/features.rs b/src/features.rs index a786f07f12..594677036d 100644 --- a/src/features.rs +++ b/src/features.rs @@ -129,6 +129,7 @@ macro_rules! rust_target_base { => Stable_1_47 => 1.47; /// Nightly rust /// * `thiscall` calling convention ([Tracking issue](https://github.com/rust-lang/rust/issues/42202)) + /// * `vectorcall` calling convention (no tracking issue) => Nightly => nightly; ); } @@ -234,6 +235,7 @@ rust_feature_def!( } Nightly { => thiscall_abi; + => vectorcall_abi; } ); @@ -259,7 +261,8 @@ mod test { !f_1_0.associated_const && !f_1_0.builtin_clone_impls && !f_1_0.repr_align && - !f_1_0.thiscall_abi + !f_1_0.thiscall_abi && + !f_1_0.vectorcall_abi ); let f_1_21 = RustFeatures::from(RustTarget::Stable_1_21); assert!( @@ -269,7 +272,8 @@ mod test { f_1_21.associated_const && f_1_21.builtin_clone_impls && !f_1_21.repr_align && - !f_1_21.thiscall_abi + !f_1_21.thiscall_abi && + !f_1_21.vectorcall_abi ); let f_nightly = RustFeatures::from(RustTarget::Nightly); assert!( @@ -280,7 +284,8 @@ mod test { f_nightly.builtin_clone_impls && f_nightly.maybe_uninit && f_nightly.repr_align && - f_nightly.thiscall_abi + f_nightly.thiscall_abi && + f_nightly.vectorcall_abi ); } diff --git a/src/ir/function.rs b/src/ir/function.rs index 0ba2d1ee51..e8e2c2dfed 100644 --- a/src/ir/function.rs +++ b/src/ir/function.rs @@ -181,6 +181,8 @@ pub enum Abi { Fastcall, /// The "thiscall" ABI. ThisCall, + /// The "vectorcall" ABI. + Vectorcall, /// The "aapcs" ABI. Aapcs, /// The "win64" ABI. @@ -203,6 +205,7 @@ impl quote::ToTokens for Abi { Abi::Stdcall => quote! { "stdcall" }, Abi::Fastcall => quote! { "fastcall" }, Abi::ThisCall => quote! { "thiscall" }, + Abi::Vectorcall => quote! { "vectorcall" }, Abi::Aapcs => quote! { "aapcs" }, Abi::Win64 => quote! { "win64" }, Abi::Unknown(cc) => panic!( @@ -241,6 +244,7 @@ fn get_abi(cc: CXCallingConv) -> Abi { CXCallingConv_X86StdCall => Abi::Stdcall, CXCallingConv_X86FastCall => Abi::Fastcall, CXCallingConv_X86ThisCall => Abi::ThisCall, + CXCallingConv_X86VectorCall => Abi::Vectorcall, CXCallingConv_AAPCS => Abi::Aapcs, CXCallingConv_X86_64Win64 => Abi::Win64, other => Abi::Unknown(other), diff --git a/tests/expectations/tests/win32-vectorcall-1_0.rs b/tests/expectations/tests/win32-vectorcall-1_0.rs new file mode 100644 index 0000000000..131dbdf39f --- /dev/null +++ b/tests/expectations/tests/win32-vectorcall-1_0.rs @@ -0,0 +1,6 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] diff --git a/tests/expectations/tests/win32-vectorcall-nightly.rs b/tests/expectations/tests/win32-vectorcall-nightly.rs new file mode 100644 index 0000000000..163741df62 --- /dev/null +++ b/tests/expectations/tests/win32-vectorcall-nightly.rs @@ -0,0 +1,16 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] +#![cfg(feature = "nightly")] +#![feature(abi_vectorcall)] + +extern "vectorcall" { + #[link_name = "\u{1}test_vectorcall@@16"] + pub fn test_vectorcall( + a: ::std::os::raw::c_int, + b: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} diff --git a/tests/headers/win32-vectorcall-1_0.h b/tests/headers/win32-vectorcall-1_0.h new file mode 100644 index 0000000000..a1f852b52f --- /dev/null +++ b/tests/headers/win32-vectorcall-1_0.h @@ -0,0 +1,3 @@ +// bindgen-flags: --rust-target 1.0 -- --target=x86_64-pc-windows-msvc + +int __vectorcall test_vectorcall(int a, int b); diff --git a/tests/headers/win32-vectorcall-nightly.h b/tests/headers/win32-vectorcall-nightly.h new file mode 100644 index 0000000000..c099bb59a5 --- /dev/null +++ b/tests/headers/win32-vectorcall-nightly.h @@ -0,0 +1,3 @@ +// bindgen-flags: --rust-target nightly --raw-line '#![cfg(feature = "nightly")]' --raw-line '#![feature(abi_vectorcall)]' -- --target=x86_64-pc-windows-msvc + +int __vectorcall test_vectorcall(int a, int b); From 91b5371df62447fb91549b758ad3025dc83f295b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 15 Mar 2022 03:47:53 +0100 Subject: [PATCH 270/942] codegen: Simplify abi support condition. --- src/codegen/mod.rs | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 1b54597fff..b988a5167f 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -17,7 +17,6 @@ use self::struct_layout::StructLayoutTracker; use super::BindgenOptions; -use crate::features::RustFeatures; use crate::ir::analysis::{HasVtable, Sizedness}; use crate::ir::annotations::FieldAccessorKind; use crate::ir::comment; @@ -2415,22 +2414,14 @@ impl MethodCodegen for Method { _ => panic!("How in the world?"), }; - match (signature.abi(), ctx.options().rust_features()) { - ( - Abi::ThisCall, - RustFeatures { - thiscall_abi: false, - .. - }, - ) | - ( - Abi::Vectorcall, - RustFeatures { - vectorcall_abi: false, - .. - }, - ) => return, - _ => {} + let supported_abi = match signature.abi() { + Abi::ThisCall => ctx.options().rust_features().thiscall_abi, + Abi::Vectorcall => ctx.options().rust_features().vectorcall_abi, + _ => true, + }; + + if !supported_abi { + return; } // Do not generate variadic methods, since rust does not allow From 638729fdbadfa4661553bb011b34f47058e26257 Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Sat, 19 Feb 2022 20:24:27 -0500 Subject: [PATCH 271/942] tests: Enable a test with a const template param This should have been added in #2155 but was missed then. --- tests/expectations/tests/template.rs | 34 +++++++++++++++++++++++++++- tests/headers/template.hpp | 4 +--- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/tests/expectations/tests/template.rs b/tests/expectations/tests/template.rs index 9c48488693..2e544ec30a 100644 --- a/tests/expectations/tests/template.rs +++ b/tests/expectations/tests/template.rs @@ -64,12 +64,13 @@ pub struct C { pub mBConstRef: B<*const ::std::os::raw::c_int>, pub mPtrRef: B<*mut *mut ::std::os::raw::c_int>, pub mArrayRef: B<*mut [::std::os::raw::c_int; 1usize]>, + pub mBConstArray: B<[::std::os::raw::c_int; 1usize]>, } #[test] fn bindgen_test_layout_C() { assert_eq!( ::std::mem::size_of::(), - 96usize, + 104usize, concat!("Size of: ", stringify!(C)) ); assert_eq!( @@ -236,6 +237,18 @@ fn bindgen_test_layout_C() { stringify!(mArrayRef) ) ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).mBConstArray as *const _ as usize + }, + 96usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(mBConstArray) + ) + ); } impl Default for C { fn default() -> Self { @@ -877,6 +890,25 @@ fn __bindgen_test_layout_B_open0_ref_array1_int_close0_instantiation() { ); } #[test] +fn __bindgen_test_layout_B_open0_array1_const_int_close0_instantiation() { + assert_eq!( + ::std::mem::size_of::>(), + 4usize, + concat!( + "Size of template specialization: ", + stringify!(B<[::std::os::raw::c_int; 1usize]>) + ) + ); + assert_eq!( + ::std::mem::align_of::>(), + 4usize, + concat!( + "Alignment of template specialization: ", + stringify!(B<[::std::os::raw::c_int; 1usize]>) + ) + ); +} +#[test] fn __bindgen_test_layout_Foo_open0_int_int_close0_instantiation_1() { assert_eq!( ::std::mem::size_of::>(), diff --git a/tests/headers/template.hpp b/tests/headers/template.hpp index eea2c4def5..bc32a357e8 100644 --- a/tests/headers/template.hpp +++ b/tests/headers/template.hpp @@ -32,9 +32,7 @@ struct C { B mBConstRef; B mPtrRef; B mArrayRef; - // clang 3.x ignores const in this case, so they generate different - // result than clang 4.0. - // B mBConstArray; + B mBConstArray; }; template From d6714c6be67cd463ebbbfdb19d6b4c1daee9cbfa Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Fri, 19 Jun 2020 20:12:05 -0700 Subject: [PATCH 272/942] tests: Stop testing libclang 4.0 --- .github/workflows/bindgen.yml | 10 +--------- appveyor.yml | 6 ------ 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index e8cd10bf29..32a5287d32 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -99,7 +99,7 @@ jobs: - debian: null cross: null rust: null - llvm_version: ["4.0", "5.0", "9.0"] + llvm_version: ["5.0", "9.0"] main_tests: [1] release_build: [0, 1] no_default_features: [0, 1] @@ -109,14 +109,6 @@ jobs: feature_extra_asserts: [0] feature_testing_only_docs: [0] - exclude: - # 4.0 is too old to support regular dynamic linking, so this - # is not expected to work. - - os: ubuntu-latest - llvm_version: "4.0" - no_default_features: 1 - feature_runtime: 0 - include: # Test with extra asserts + docs just with latest llvm versions to # prevent explosion diff --git a/appveyor.yml b/appveyor.yml index 51129cdcbe..62efeea2c4 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,18 +2,12 @@ environment: RUST_BACKTRACE: 1 RUST_CHANNEL: "%Configuration%" matrix: - - TARGET: gnu - LLVM_VERSION: 4.0.0-1 - BINDGEN_FEATURES: testing_only_libclang_4 - TARGET: gnu LLVM_VERSION: 5.0.0-1 BINDGEN_FEATURES: testing_only_libclang_5 - TARGET: gnu LLVM_VERSION: 9.0.0-1 BINDGEN_FEATURES: testing_only_libclang_9 - - TARGET: msvc - LLVM_VERSION: 4.0.0 - BINDGEN_FEATURES: testing_only_libclang_4 - TARGET: msvc LLVM_VERSION: 5.0.0 BINDGEN_FEATURES: testing_only_libclang_5 From 63237152212457f956bde9f540cb60836f93dd3f Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Fri, 19 Jun 2020 20:12:06 -0700 Subject: [PATCH 273/942] clang: Stop accommodating libclang 4.0 Closes #2166 --- src/clang.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/clang.rs b/src/clang.rs index 528c8a9111..eb5ff6e162 100644 --- a/src/clang.rs +++ b/src/clang.rs @@ -2066,9 +2066,6 @@ pub struct TargetInfo { impl TargetInfo { /// Tries to obtain target information from libclang. pub fn new(tu: &TranslationUnit) -> Option { - if !clang_getTranslationUnitTargetInfo::is_loaded() { - return None; - } let triple; let pointer_width; unsafe { From e3a6b8cd2b32a0cefbfc62c7bf14aee74f5d722a Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Sun, 21 Jun 2020 17:56:34 -0700 Subject: [PATCH 274/942] ir: Make TargetInfo::new infallible Now that we require Clang 5.0, there is no way for this function to return None. --- src/clang.rs | 6 +++--- src/ir/context.rs | 12 +++--------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/clang.rs b/src/clang.rs index eb5ff6e162..587cc0ba7d 100644 --- a/src/clang.rs +++ b/src/clang.rs @@ -2065,7 +2065,7 @@ pub struct TargetInfo { impl TargetInfo { /// Tries to obtain target information from libclang. - pub fn new(tu: &TranslationUnit) -> Option { + pub fn new(tu: &TranslationUnit) -> Self { let triple; let pointer_width; unsafe { @@ -2076,9 +2076,9 @@ impl TargetInfo { } assert!(pointer_width > 0); assert_eq!(pointer_width % 8, 0); - Some(TargetInfo { + TargetInfo { triple, pointer_width: pointer_width as usize, - }) + } } } diff --git a/src/ir/context.rs b/src/ir/context.rs index 9afd16d6a6..9cf43ec3c6 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -368,7 +368,7 @@ pub struct BindgenContext { translation_unit: clang::TranslationUnit, /// Target information that can be useful for some stuff. - target_info: Option, + target_info: clang::TargetInfo, /// The options given by the user via cli or other medium. options: BindgenOptions, @@ -584,10 +584,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// Returns `true` if the target architecture is wasm32 pub fn is_target_wasm32(&self) -> bool { - match self.target_info { - Some(ref ti) => ti.triple.starts_with("wasm32-"), - None => false, - } + self.target_info.triple.starts_with("wasm32-") } /// Creates a timer for the current bindgen phase. If time_phases is `true`, @@ -600,10 +597,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// Returns the pointer width to use for the target for the current /// translation. pub fn target_pointer_size(&self) -> usize { - if let Some(ref ti) = self.target_info { - return ti.pointer_width / 8; - } - mem::size_of::<*mut ()>() + return self.target_info.pointer_width / 8; } /// Get the stack of partially parsed types that we are in the middle of From 0223cab9d8a00f2bb3c90d693b89141930db573a Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Tue, 23 Jun 2020 15:51:39 -0700 Subject: [PATCH 275/942] tests: Remove testing_only_libclang_4 and expectations --- Cargo.toml | 1 - bindgen-integration/Cargo.toml | 1 - src/main.rs | 2 - tests/expectations/build.rs | 1 - .../tests/libclang-4/abi_variadic_function.rs | 11 -- tests/expectations/tests/libclang-4/auto.rs | 35 ------ .../tests/libclang-4/call-conv-field.rs | 60 --------- .../tests/libclang-4/const_bool.rs | 29 ----- .../tests/libclang-4/constant-evaluate.rs | 25 ---- ...0600-cannot-apply-unary-negation-to-u32.rs | 9 -- .../issue-769-bad-instantiation-test.rs | 67 ---------- .../tests/libclang-4/mangling-win32.rs | 52 -------- .../tests/libclang-4/objc_inheritance.rs | 116 ------------------ .../tests/libclang-4/objc_template.rs | 64 ---------- .../partial-specialization-and-inheritance.rs | 39 ------ .../type_alias_template_specialized.rs | 65 ---------- .../libclang-4/wasm-constructor-returns.rs | 37 ------ tests/stylo_sanity.rs | 1 - tests/tests.rs | 2 - 19 files changed, 617 deletions(-) delete mode 100644 tests/expectations/tests/libclang-4/abi_variadic_function.rs delete mode 100644 tests/expectations/tests/libclang-4/auto.rs delete mode 100644 tests/expectations/tests/libclang-4/call-conv-field.rs delete mode 100644 tests/expectations/tests/libclang-4/const_bool.rs delete mode 100644 tests/expectations/tests/libclang-4/constant-evaluate.rs delete mode 100644 tests/expectations/tests/libclang-4/error-E0600-cannot-apply-unary-negation-to-u32.rs delete mode 100644 tests/expectations/tests/libclang-4/issue-769-bad-instantiation-test.rs delete mode 100644 tests/expectations/tests/libclang-4/mangling-win32.rs delete mode 100644 tests/expectations/tests/libclang-4/objc_inheritance.rs delete mode 100644 tests/expectations/tests/libclang-4/objc_template.rs delete mode 100644 tests/expectations/tests/libclang-4/partial-specialization-and-inheritance.rs delete mode 100644 tests/expectations/tests/libclang-4/type_alias_template_specialized.rs delete mode 100644 tests/expectations/tests/libclang-4/wasm-constructor-returns.rs diff --git a/Cargo.toml b/Cargo.toml index cec8a57902..82f9dc17eb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -83,4 +83,3 @@ testing_only_docs = [] testing_only_extra_assertions = [] testing_only_libclang_9 = [] testing_only_libclang_5 = [] -testing_only_libclang_4 = [] diff --git a/bindgen-integration/Cargo.toml b/bindgen-integration/Cargo.toml index 9dcf1d377b..733fba58db 100644 --- a/bindgen-integration/Cargo.toml +++ b/bindgen-integration/Cargo.toml @@ -18,4 +18,3 @@ testing_only_docs = ["bindgen/testing_only_docs"] testing_only_extra_assertions = ["bindgen/testing_only_extra_assertions"] testing_only_libclang_9 = ["bindgen/testing_only_libclang_9"] testing_only_libclang_5 = ["bindgen/testing_only_libclang_5"] -testing_only_libclang_4 = ["bindgen/testing_only_libclang_4"] diff --git a/src/main.rs b/src/main.rs index a208957410..50f3e71440 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,8 +23,6 @@ fn clang_version_check() { Some((9, 0)) } else if cfg!(feature = "testing_only_libclang_5") { Some((5, 0)) - } else if cfg!(feature = "testing_only_libclang_4") { - Some((4, 0)) } else { None }; diff --git a/tests/expectations/build.rs b/tests/expectations/build.rs index beed7116a4..a5904d9622 100644 --- a/tests/expectations/build.rs +++ b/tests/expectations/build.rs @@ -9,7 +9,6 @@ use std::io::Write; use std::path::Path; const LIBCLANG_VERSION_DIRS: &'static [&'static str] = &[ - "libclang-4", "libclang-5", "libclang-9", ]; diff --git a/tests/expectations/tests/libclang-4/abi_variadic_function.rs b/tests/expectations/tests/libclang-4/abi_variadic_function.rs deleted file mode 100644 index 6aeb16f2a7..0000000000 --- a/tests/expectations/tests/libclang-4/abi_variadic_function.rs +++ /dev/null @@ -1,11 +0,0 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -extern "C" { - #[link_name = "\u{1}_Z1bcz"] - pub fn b(arg1: ::std::os::raw::c_char, ...) -> ::std::os::raw::c_char; -} diff --git a/tests/expectations/tests/libclang-4/auto.rs b/tests/expectations/tests/libclang-4/auto.rs deleted file mode 100644 index 0b20b39eb6..0000000000 --- a/tests/expectations/tests/libclang-4/auto.rs +++ /dev/null @@ -1,35 +0,0 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct Foo { - pub _address: u8, -} -pub const Foo_kFoo: bool = true; -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) - ); -} -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct Bar { - pub _address: u8, -} -extern "C" { - #[link_name = "\u{1}_Z5Test2v"] - pub fn Test2() -> ::std::os::raw::c_uint; -} diff --git a/tests/expectations/tests/libclang-4/call-conv-field.rs b/tests/expectations/tests/libclang-4/call-conv-field.rs deleted file mode 100644 index f134bd8a46..0000000000 --- a/tests/expectations/tests/libclang-4/call-conv-field.rs +++ /dev/null @@ -1,60 +0,0 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] -#![cfg(not(test))] - -#[repr(C)] -#[derive(Default, Copy, Clone)] -pub struct JNINativeInterface_ { - pub GetVersion: ::std::option::Option< - unsafe extern "stdcall" fn( - env: *mut ::std::os::raw::c_void, - ) -> ::std::os::raw::c_int, - >, - pub __hack: ::std::os::raw::c_ulonglong, -} -#[test] -fn bindgen_test_layout_JNINativeInterface_() { - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(JNINativeInterface_)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(JNINativeInterface_)) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).GetVersion - as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(JNINativeInterface_), - "::", - stringify!(GetVersion) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).__hack as *const _ - as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(JNINativeInterface_), - "::", - stringify!(__hack) - ) - ); -} -extern "stdcall" { - pub fn bar(); -} diff --git a/tests/expectations/tests/libclang-4/const_bool.rs b/tests/expectations/tests/libclang-4/const_bool.rs deleted file mode 100644 index 97e1d8dda4..0000000000 --- a/tests/expectations/tests/libclang-4/const_bool.rs +++ /dev/null @@ -1,29 +0,0 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -pub const k: bool = true; -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct A { - pub _address: u8, -} -pub const A_k: bool = false; -#[test] -fn bindgen_test_layout_A() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(A)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(A)) - ); -} -pub type foo = bool; -pub const k2: foo = true; diff --git a/tests/expectations/tests/libclang-4/constant-evaluate.rs b/tests/expectations/tests/libclang-4/constant-evaluate.rs deleted file mode 100644 index 9debe39d3e..0000000000 --- a/tests/expectations/tests/libclang-4/constant-evaluate.rs +++ /dev/null @@ -1,25 +0,0 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -pub const foo: _bindgen_ty_1 = _bindgen_ty_1::foo; -pub const bar: _bindgen_ty_1 = _bindgen_ty_1::bar; -#[repr(u32)] -#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] -pub enum _bindgen_ty_1 { - foo = 4, - bar = 8, -} -pub type EasyToOverflow = ::std::os::raw::c_ulonglong; -pub const k: EasyToOverflow = 2147483648; -pub const k_expr: EasyToOverflow = 1152921504606846976; -pub const wow: EasyToOverflow = 2147483648; -pub const BAZ: ::std::os::raw::c_longlong = 24; -pub const fuzz: f64 = 51.0; -pub const BAZZ: ::std::os::raw::c_char = 53; -pub const WAT: ::std::os::raw::c_char = 0; -pub const bytestring: &[u8; 4usize] = b"Foo\0"; -pub const NOT_UTF8: [u8; 5usize] = [240u8, 40u8, 140u8, 40u8, 0u8]; diff --git a/tests/expectations/tests/libclang-4/error-E0600-cannot-apply-unary-negation-to-u32.rs b/tests/expectations/tests/libclang-4/error-E0600-cannot-apply-unary-negation-to-u32.rs deleted file mode 100644 index 57878592d9..0000000000 --- a/tests/expectations/tests/libclang-4/error-E0600-cannot-apply-unary-negation-to-u32.rs +++ /dev/null @@ -1,9 +0,0 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] -#![allow(overflowing_literals)] - -pub const a: u32 = 4294967291; diff --git a/tests/expectations/tests/libclang-4/issue-769-bad-instantiation-test.rs b/tests/expectations/tests/libclang-4/issue-769-bad-instantiation-test.rs deleted file mode 100644 index 60857966ce..0000000000 --- a/tests/expectations/tests/libclang-4/issue-769-bad-instantiation-test.rs +++ /dev/null @@ -1,67 +0,0 @@ -#![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 { - #[allow(unused_imports)] - use self::super::root; - #[repr(C)] - #[derive(Debug, Copy, Clone)] - pub struct Rooted { - pub member: T, - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, - } - impl Default for Rooted { - fn default() -> Self { - let mut s = ::std::mem::MaybeUninit::::uninit(); - unsafe { - ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); - s.assume_init() - } - } - } - pub type AutoValueVector_Alias = ::std::os::raw::c_int; - #[test] - fn __bindgen_test_layout_Rooted_open0_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!( - "Size of template specialization: ", - stringify!(root::Rooted<::std::os::raw::c_int>) - ) - ); - assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(root::Rooted<::std::os::raw::c_int>) - ) - ); - } - #[test] - fn __bindgen_test_layout_Rooted_open0_AutoValueVector_Alias_close0_instantiation( - ) { - assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!( - "Size of template specialization: ", - stringify!(root::Rooted) - ) - ); - assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(root::Rooted) - ) - ); - } -} diff --git a/tests/expectations/tests/libclang-4/mangling-win32.rs b/tests/expectations/tests/libclang-4/mangling-win32.rs deleted file mode 100644 index 0aee327414..0000000000 --- a/tests/expectations/tests/libclang-4/mangling-win32.rs +++ /dev/null @@ -1,52 +0,0 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -extern "C" { - pub fn foo(); -} -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct Foo { - pub _address: u8, -} -extern "C" { - #[link_name = "\u{1}?sBar@Foo@@2_NA"] - pub static mut Foo_sBar: bool; -} -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) - ); -} -extern "fastcall" { - pub fn fast_call_func_no_args() -> ::std::os::raw::c_int; -} -extern "fastcall" { - pub fn fast_call_func_many_args( - arg1: ::std::os::raw::c_int, - arg2: ::std::os::raw::c_int, - arg3: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int; -} -extern "stdcall" { - pub fn std_call_func_no_args() -> ::std::os::raw::c_int; -} -extern "stdcall" { - pub fn std_call_func_many_args( - arg1: ::std::os::raw::c_int, - arg2: ::std::os::raw::c_int, - arg3: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int; -} diff --git a/tests/expectations/tests/libclang-4/objc_inheritance.rs b/tests/expectations/tests/libclang-4/objc_inheritance.rs deleted file mode 100644 index f1c2a88cb0..0000000000 --- a/tests/expectations/tests/libclang-4/objc_inheritance.rs +++ /dev/null @@ -1,116 +0,0 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] -#![cfg(target_os = "macos")] - -use objc::{self, class, msg_send, sel, sel_impl}; -#[allow(non_camel_case_types)] -pub type id = *mut objc::runtime::Object; -#[repr(transparent)] -#[derive(Debug, Copy, Clone)] -pub struct Foo(pub id); -impl std::ops::Deref for Foo { - type Target = objc::runtime::Object; - fn deref(&self) -> &Self::Target { - unsafe { &*self.0 } - } -} -unsafe impl objc::Message for Foo {} -impl Foo { - pub fn alloc() -> Self { - Self(unsafe { msg_send!(class!(Foo), alloc) }) - } -} -impl IFoo for Foo {} -pub trait IFoo: Sized + std::ops::Deref {} -#[repr(transparent)] -#[derive(Debug, Copy, Clone)] -pub struct Bar(pub id); -impl std::ops::Deref for Bar { - type Target = objc::runtime::Object; - fn deref(&self) -> &Self::Target { - unsafe { &*self.0 } - } -} -unsafe impl objc::Message for Bar {} -impl Bar { - pub fn alloc() -> Self { - Self(unsafe { msg_send!(class!(Bar), alloc) }) - } -} -impl IFoo for Bar {} -impl From for Foo { - fn from(child: Bar) -> Foo { - Foo(child.0) - } -} -impl std::convert::TryFrom for Bar { - type Error = &'static str; - fn try_from(parent: Foo) -> Result { - let is_kind_of: bool = - unsafe { msg_send!(parent, isKindOfClass: class!(Bar)) }; - if is_kind_of { - Ok(Bar(parent.0)) - } else { - Err("This Foo cannot be downcasted to Bar") - } - } -} -impl IBar for Bar {} -pub trait IBar: Sized + std::ops::Deref {} -#[repr(transparent)] -#[derive(Debug, Copy, Clone)] -pub struct Baz(pub id); -impl std::ops::Deref for Baz { - type Target = objc::runtime::Object; - fn deref(&self) -> &Self::Target { - unsafe { &*self.0 } - } -} -unsafe impl objc::Message for Baz {} -impl Baz { - pub fn alloc() -> Self { - Self(unsafe { msg_send!(class!(Baz), alloc) }) - } -} -impl IBar for Baz {} -impl From for Bar { - fn from(child: Baz) -> Bar { - Bar(child.0) - } -} -impl std::convert::TryFrom for Baz { - type Error = &'static str; - fn try_from(parent: Bar) -> Result { - let is_kind_of: bool = - unsafe { msg_send!(parent, isKindOfClass: class!(Baz)) }; - if is_kind_of { - Ok(Baz(parent.0)) - } else { - Err("This Bar cannot be downcasted to Baz") - } - } -} -impl IFoo for Baz {} -impl From for Foo { - fn from(child: Baz) -> Foo { - Foo(child.0) - } -} -impl std::convert::TryFrom for Baz { - type Error = &'static str; - fn try_from(parent: Foo) -> Result { - let is_kind_of: bool = - unsafe { msg_send!(parent, isKindOfClass: class!(Baz)) }; - if is_kind_of { - Ok(Baz(parent.0)) - } else { - Err("This Foo cannot be downcasted to Baz") - } - } -} -impl IBaz for Baz {} -pub trait IBaz: Sized + std::ops::Deref {} diff --git a/tests/expectations/tests/libclang-4/objc_template.rs b/tests/expectations/tests/libclang-4/objc_template.rs deleted file mode 100644 index 53caa661c6..0000000000 --- a/tests/expectations/tests/libclang-4/objc_template.rs +++ /dev/null @@ -1,64 +0,0 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] -#![cfg(target_os = "macos")] - -use objc::{self, class, msg_send, sel, sel_impl}; -#[allow(non_camel_case_types)] -pub type id = *mut objc::runtime::Object; -#[repr(transparent)] -#[derive(Debug, Copy, Clone)] -pub struct Foo(pub id); -impl std::ops::Deref for Foo { - type Target = objc::runtime::Object; - fn deref(&self) -> &Self::Target { - unsafe { &*self.0 } - } -} -unsafe impl objc::Message for Foo {} -impl Foo { - pub fn alloc() -> Self { - Self(unsafe { msg_send!(class!(Foo), alloc) }) - } -} -impl IFoo for Foo {} -pub trait IFoo: Sized + std::ops::Deref { - unsafe fn get(&self) -> *mut ObjectType - where - ::Target: objc::Message + Sized, - { - msg_send!(*self, get) - } -} -#[repr(transparent)] -#[derive(Debug, Copy, Clone)] -pub struct FooMultiGeneric(pub id); -impl std::ops::Deref for FooMultiGeneric { - type Target = objc::runtime::Object; - fn deref(&self) -> &Self::Target { - unsafe { &*self.0 } - } -} -unsafe impl objc::Message for FooMultiGeneric {} -impl FooMultiGeneric { - pub fn alloc() -> Self { - Self(unsafe { msg_send!(class!(FooMultiGeneric), alloc) }) - } -} -impl - IFooMultiGeneric for FooMultiGeneric -{ -} -pub trait IFooMultiGeneric: - Sized + std::ops::Deref -{ - unsafe fn objectForKey_(&self, key: *mut KeyType) -> *mut ObjectType - where - ::Target: objc::Message + Sized, - { - msg_send!(*self, objectForKey: key) - } -} diff --git a/tests/expectations/tests/libclang-4/partial-specialization-and-inheritance.rs b/tests/expectations/tests/libclang-4/partial-specialization-and-inheritance.rs deleted file mode 100644 index e62ea68172..0000000000 --- a/tests/expectations/tests/libclang-4/partial-specialization-and-inheritance.rs +++ /dev/null @@ -1,39 +0,0 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct Base { - pub _address: u8, -} -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct Derived { - pub b: bool, -} -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct Usage { - pub _address: u8, -} -extern "C" { - #[link_name = "\u{1}_ZN5Usage13static_memberE"] - pub static mut Usage_static_member: [u32; 2usize]; -} -#[test] -fn bindgen_test_layout_Usage() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Usage)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Usage)) - ); -} diff --git a/tests/expectations/tests/libclang-4/type_alias_template_specialized.rs b/tests/expectations/tests/libclang-4/type_alias_template_specialized.rs deleted file mode 100644 index f874e9d221..0000000000 --- a/tests/expectations/tests/libclang-4/type_alias_template_specialized.rs +++ /dev/null @@ -1,65 +0,0 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct Rooted { - pub ptr: MaybeWrapped<::std::os::raw::c_int>, -} -#[test] -fn bindgen_test_layout_Rooted() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Rooted)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Rooted)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).ptr as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Rooted), - "::", - stringify!(ptr) - ) - ); -} -impl Default for Rooted { - fn default() -> Self { - let mut s = ::std::mem::MaybeUninit::::uninit(); - unsafe { - ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); - s.assume_init() - } - } -} -///
-pub type MaybeWrapped
= a; -#[test] -fn __bindgen_test_layout_MaybeWrapped_open0_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!( - "Size of template specialization: ", - stringify!(MaybeWrapped<::std::os::raw::c_int>) - ) - ); - assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(MaybeWrapped<::std::os::raw::c_int>) - ) - ); -} diff --git a/tests/expectations/tests/libclang-4/wasm-constructor-returns.rs b/tests/expectations/tests/libclang-4/wasm-constructor-returns.rs deleted file mode 100644 index f207d0d8e1..0000000000 --- a/tests/expectations/tests/libclang-4/wasm-constructor-returns.rs +++ /dev/null @@ -1,37 +0,0 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -#[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, - concat!("Size of: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) - ); -} -extern "C" { - #[link_name = "\u{1}_ZN3FooC1Ei"] - pub fn Foo_Foo(this: *mut Foo, var: ::std::os::raw::c_int); -} -impl Foo { - #[inline] - pub unsafe fn new(var: ::std::os::raw::c_int) -> Self { - let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); - Foo_Foo(__bindgen_tmp.as_mut_ptr(), var); - __bindgen_tmp.assume_init() - } -} diff --git a/tests/stylo_sanity.rs b/tests/stylo_sanity.rs index f44f12878d..52b96355e0 100755 --- a/tests/stylo_sanity.rs +++ b/tests/stylo_sanity.rs @@ -16,7 +16,6 @@ extern crate bindgen; #[test] #[cfg(not(any(debug_assertions, feature = "testing_only_extra_assertions",)))] #[cfg(any( - feature = "testing_only_libclang_4", feature = "testing_only_libclang_5", feature = "testing_only_libclang_9" ))] diff --git a/tests/tests.rs b/tests/tests.rs index 1f116c93b3..a3e27f05fb 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -141,8 +141,6 @@ fn compare_generated_header( expectation.push("libclang-9"); } else if cfg!(feature = "testing_only_libclang_5") { expectation.push("libclang-5"); - } else if cfg!(feature = "testing_only_libclang_4") { - expectation.push("libclang-4"); } else { match clang_version().parsed { None => expectation.push("libclang-9"), From b387d2337dfd096ee1144fd88f8800581658a66a Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Sat, 19 Feb 2022 20:18:39 -0500 Subject: [PATCH 276/942] docs: Drop references to Clang 4 --- CONTRIBUTING.md | 1 - book/src/requirements.md | 14 ++++---------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 439a18da58..d4090f6606 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -197,7 +197,6 @@ add each of: * `tests/expectations/tests/libclang-9/my_test.rs` * `tests/expectations/tests/libclang-5/my_test.rs` -* `tests/expectations/tests/libclang-4/my_test.rs` If you need to update the test expectations for a test file that generates different bindings for different `libclang` versions, you *don't* need to have diff --git a/book/src/requirements.md b/book/src/requirements.md index 8a7cbcb25c..7cce87aed9 100644 --- a/book/src/requirements.md +++ b/book/src/requirements.md @@ -7,13 +7,9 @@ This page lists the requirements for running `bindgen` and how to get them. `bindgen` leverages `libclang` to preprocess, parse, and type check C and C++ header files. -It is recommended to use Clang 4.0 or greater, however `bindgen` can run with -older Clangs with some features disabled. +It is required to use Clang 5.0 or greater. -* **If you are generating bindings to C++,** you almost definitely want 4.0 or -greater. - -### Installing Clang 4.0 +### Installing Clang #### Windows @@ -50,9 +46,7 @@ $ port install clang # apt install llvm-dev libclang-dev clang ``` -Ubuntu 18.04 provides the necessary packages directly. If you are using older -version of Ubuntu or other Debian-based distros, you may need to add the LLVM -repos to get version 4.0. See http://apt.llvm.org/. +Ubuntu 18.04 provides the necessary packages directly. #### Arch @@ -76,7 +70,7 @@ Add `export LIBCLANG_PATH=/usr/local/lib` to your profile. #### From source -If your package manager doesn't yet offer Clang 4.0, you'll need to build from +If your package manager doesn't yet offer Clang 5.0, you'll need to build from source. For that, follow the instructions [here](http://clang.llvm.org/get_started.html). From d90a41ad24a813dc701ff6ee9bcd8a0b0fcb9fe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20Gardstr=C3=B6m?= Date: Fri, 25 Feb 2022 21:38:31 +0100 Subject: [PATCH 277/942] escape `\` in paths for tests modules --- tests/expectations/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/expectations/build.rs b/tests/expectations/build.rs index a5904d9622..e44bcc8596 100644 --- a/tests/expectations/build.rs +++ b/tests/expectations/build.rs @@ -52,7 +52,7 @@ fn main() { #[path = "{}"] mod {}; "###, - path.display(), + path.display().to_string().replace('\\', "\\\\"), module_name, )); } From 4a5ae0884da76d6d8538a6cc607e5dba144842db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20Gardstr=C3=B6m?= Date: Fri, 25 Feb 2022 21:39:34 +0100 Subject: [PATCH 278/942] disable layout tests for `derive-custom` and `convert-cpp-comment-to-rust` test --- .../tests/convert-cpp-comment-to-rust.rs | 49 ------------- tests/expectations/tests/derive-custom.rs | 69 ------------------- tests/headers/convert-cpp-comment-to-rust.hpp | 2 +- tests/headers/derive-custom.h | 2 +- 4 files changed, 2 insertions(+), 120 deletions(-) diff --git a/tests/expectations/tests/convert-cpp-comment-to-rust.rs b/tests/expectations/tests/convert-cpp-comment-to-rust.rs index 86279caf47..09a22c4f65 100644 --- a/tests/expectations/tests/convert-cpp-comment-to-rust.rs +++ b/tests/expectations/tests/convert-cpp-comment-to-rust.rs @@ -17,55 +17,6 @@ pub struct mbedtls_mpi { ///< pointer to limbs pub p: *mut mbedtls_mpi_uint, } -#[test] -fn bindgen_test_layout_mbedtls_mpi() { - assert_eq!( - ::std::mem::size_of::(), - 24usize, - concat!("Size of: ", stringify!(mbedtls_mpi)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(mbedtls_mpi)) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).s as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(mbedtls_mpi), - "::", - stringify!(s) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).n as *const _ as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(mbedtls_mpi), - "::", - stringify!(n) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).p as *const _ as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(mbedtls_mpi), - "::", - stringify!(p) - ) - ); -} impl Default for mbedtls_mpi { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/tests/expectations/tests/derive-custom.rs b/tests/expectations/tests/derive-custom.rs index 1cae9af0ae..542b6bb25f 100644 --- a/tests/expectations/tests/derive-custom.rs +++ b/tests/expectations/tests/derive-custom.rs @@ -11,29 +11,6 @@ pub struct my_type { pub a: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_my_type() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(my_type)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(my_type)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(my_type), - "::", - stringify!(a) - ) - ); -} ///
///
#[repr(C)] @@ -41,55 +18,9 @@ fn bindgen_test_layout_my_type() { pub struct my_type2 { pub a: ::std::os::raw::c_uint, } -#[test] -fn bindgen_test_layout_my_type2() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(my_type2)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(my_type2)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(my_type2), - "::", - stringify!(a) - ) - ); -} ///
#[repr(C)] #[derive(Default, Debug, Clone)] pub struct my_type3 { pub a: ::std::os::raw::c_ulong, } -#[test] -fn bindgen_test_layout_my_type3() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(my_type3)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(my_type3)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(my_type3), - "::", - stringify!(a) - ) - ); -} diff --git a/tests/headers/convert-cpp-comment-to-rust.hpp b/tests/headers/convert-cpp-comment-to-rust.hpp index 649c236538..f5bbbf58b2 100644 --- a/tests/headers/convert-cpp-comment-to-rust.hpp +++ b/tests/headers/convert-cpp-comment-to-rust.hpp @@ -1,4 +1,4 @@ - +// bindgen-flags: --no-layout-tests typedef unsigned mbedtls_mpi_uint; /** diff --git a/tests/headers/derive-custom.h b/tests/headers/derive-custom.h index 83f2ce08a9..8c57278cb3 100644 --- a/tests/headers/derive-custom.h +++ b/tests/headers/derive-custom.h @@ -1,4 +1,4 @@ -// bindgen-flags: --no-derive-debug --no-derive-copy --default-enum-style rust +// bindgen-flags: --no-derive-debug --no-derive-copy --default-enum-style rust --no-layout-tests /**
*/ struct my_type; From 26fed0967cd79d363a3b6f39de29a1f7d9eab0ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20Gardstr=C3=B6m?= Date: Fri, 25 Feb 2022 21:45:58 +0100 Subject: [PATCH 279/942] disable some tests on windows This is due to differences in representation of `signed long` and `unsigned long` on most Linux-based systems and Windows (`64` vs. `32` bits) --- tests/expectations/tests/bitfield_align_2.rs | 1 + tests/expectations/tests/enum_explicit_type_constants.rs | 1 + tests/expectations/tests/issue-739-pointer-wide-bitfield.rs | 1 + tests/expectations/tests/use-core.rs | 2 +- tests/headers/bitfield_align_2.h | 2 +- tests/headers/enum_explicit_type_constants.hpp | 2 +- tests/headers/issue-739-pointer-wide-bitfield.h | 1 + tests/headers/use-core.h | 2 +- 8 files changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/expectations/tests/bitfield_align_2.rs b/tests/expectations/tests/bitfield_align_2.rs index 1a1f7dd822..aa11f80c51 100644 --- a/tests/expectations/tests/bitfield_align_2.rs +++ b/tests/expectations/tests/bitfield_align_2.rs @@ -4,6 +4,7 @@ non_camel_case_types, non_upper_case_globals )] +#![cfg(not(target_os = "windows"))] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] diff --git a/tests/expectations/tests/enum_explicit_type_constants.rs b/tests/expectations/tests/enum_explicit_type_constants.rs index 030d64bedc..117f684723 100644 --- a/tests/expectations/tests/enum_explicit_type_constants.rs +++ b/tests/expectations/tests/enum_explicit_type_constants.rs @@ -4,6 +4,7 @@ non_camel_case_types, non_upper_case_globals )] +#![cfg(not(target_os = "windows"))] pub const Foo_Bar: Foo = 0; pub const Foo_Qux: Foo = 1; diff --git a/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs b/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs index 7d7b792152..1a633844f2 100644 --- a/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs +++ b/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs @@ -4,6 +4,7 @@ non_camel_case_types, non_upper_case_globals )] +#![cfg(not(target_os = "windows"))] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] diff --git a/tests/expectations/tests/use-core.rs b/tests/expectations/tests/use-core.rs index d919b6e745..66e3b36360 100644 --- a/tests/expectations/tests/use-core.rs +++ b/tests/expectations/tests/use-core.rs @@ -4,7 +4,7 @@ non_camel_case_types, non_upper_case_globals )] - +#![cfg(not(target_os = "windows"))] extern crate core; #[repr(C)] diff --git a/tests/headers/bitfield_align_2.h b/tests/headers/bitfield_align_2.h index b6a6cd284c..cb0f2e20d2 100644 --- a/tests/headers/bitfield_align_2.h +++ b/tests/headers/bitfield_align_2.h @@ -1,4 +1,4 @@ -// bindgen-flags: --rustified-enum ".*" +// bindgen-flags: --rustified-enum ".*" --raw-line '#![cfg(not(target_os="windows"))]' enum MyEnum { ONE, TWO, diff --git a/tests/headers/enum_explicit_type_constants.hpp b/tests/headers/enum_explicit_type_constants.hpp index 7deab3699a..e1ecf6fa8d 100644 --- a/tests/headers/enum_explicit_type_constants.hpp +++ b/tests/headers/enum_explicit_type_constants.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: -- -std=c++11 +// bindgen-flags: --raw-line '#![cfg(not(target_os="windows"))]' -- -std=c++11 // // This test is much like enum_explicit_type, but without --rustified-enum. diff --git a/tests/headers/issue-739-pointer-wide-bitfield.h b/tests/headers/issue-739-pointer-wide-bitfield.h index 611dab1da0..eeb7ae9c2d 100644 --- a/tests/headers/issue-739-pointer-wide-bitfield.h +++ b/tests/headers/issue-739-pointer-wide-bitfield.h @@ -1,3 +1,4 @@ +// bindgen-flags: --raw-line '#![cfg(not(target_os="windows"))]' #define POINTER_WIDTH (sizeof(void*) * 8) struct Foo { diff --git a/tests/headers/use-core.h b/tests/headers/use-core.h index b4135b44a7..5ee0ac6f39 100644 --- a/tests/headers/use-core.h +++ b/tests/headers/use-core.h @@ -1,4 +1,4 @@ -// bindgen-flags: --use-core --raw-line "extern crate core;" --with-derive-hash --with-derive-partialeq --with-derive-eq +// bindgen-flags: --use-core --raw-line '#![cfg(not(target_os="windows"))] extern crate core;' --with-derive-hash --with-derive-partialeq --with-derive-eq struct foo { int a, b; From 310f7f877042f0858cd01fb1c326a41d23bd821c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20Gardstr=C3=B6m?= Date: Fri, 25 Feb 2022 21:47:29 +0100 Subject: [PATCH 280/942] disable test_clang_env_args on windows --- tests/tests.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/tests.rs b/tests/tests.rs index a3e27f05fb..5611baaf62 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -410,6 +410,7 @@ macro_rules! test_header { include!(concat!(env!("OUT_DIR"), "/tests.rs")); #[test] +#[cfg_attr(target_os = "windows", ignore)] fn test_clang_env_args() { std::env::set_var( "BINDGEN_EXTRA_CLANG_ARGS", From 9689aecbfe45c9ba18d6d95de3cb903b1740b8cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20Gardstr=C3=B6m?= Date: Fri, 25 Feb 2022 20:13:47 +0100 Subject: [PATCH 281/942] add attributes to dynamic functions this includes comments and must_use annotations --- src/codegen/dyngen.rs | 3 + src/codegen/mod.rs | 29 ++++++---- .../tests/dynamic_loading_attributes.rs | 56 +++++++++++++++++++ tests/headers/dynamic_loading_attributes.h | 11 ++++ 4 files changed, 89 insertions(+), 10 deletions(-) create mode 100644 tests/expectations/tests/dynamic_loading_attributes.rs create mode 100644 tests/headers/dynamic_loading_attributes.h diff --git a/src/codegen/dyngen.rs b/src/codegen/dyngen.rs index 71c4dab1dc..26cfe5cc9e 100644 --- a/src/codegen/dyngen.rs +++ b/src/codegen/dyngen.rs @@ -112,6 +112,7 @@ impl DynamicItems { } } + #[allow(clippy::too_many_arguments)] pub fn push( &mut self, ident: Ident, @@ -122,6 +123,7 @@ impl DynamicItems { args_identifiers: Vec, ret: proc_macro2::TokenStream, ret_ty: proc_macro2::TokenStream, + attributes: Vec, ) { if !is_variadic { assert_eq!(args.len(), args_identifiers.len()); @@ -153,6 +155,7 @@ impl DynamicItems { // access the function pointer so that the user can call it just fine. if !is_variadic { self.struct_implementation.push(quote! { + #(#attributes)* pub unsafe fn #ident ( &self, #( #args ),* ) -> #ret_ty { #call_body } diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index b988a5167f..7c8e26463f 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -3907,6 +3907,8 @@ impl CodeGenerator for Function { Linkage::External => {} } + #[allow(clippy::needless_late_init)] + let is_dynamic_function; // Pure virtual methods have no actual symbol, so we can't generate // something meaningful for them. match self.kind() { @@ -3915,7 +3917,14 @@ impl CodeGenerator for Function { { return None; } - _ => {} + FunctionKind::Function => { + // If we're generating for dynamic loading, some attributes can not be emitted. + is_dynamic_function = + ctx.options().dynamic_library_name.is_some() + } + _ => { + is_dynamic_function = false; + } } // Similar to static member variables in a class template, we can't @@ -3958,7 +3967,6 @@ impl CodeGenerator for Function { { attributes.push(attributes::must_use()); } - if let Some(comment) = item.comment(ctx) { attributes.push(attributes::doc(comment)); } @@ -3995,11 +4003,13 @@ impl CodeGenerator for Function { } let link_name = mangled_name.unwrap_or(name); - if !utils::names_will_be_identical_after_mangling( - &canonical_name, - link_name, - Some(abi), - ) { + if !is_dynamic_function && + !utils::names_will_be_identical_after_mangling( + &canonical_name, + link_name, + Some(abi), + ) + { attributes.push(attributes::link_name(link_name)); } @@ -4021,9 +4031,7 @@ impl CodeGenerator for Function { }; // If we're doing dynamic binding generation, add to the dynamic items. - if ctx.options().dynamic_library_name.is_some() && - self.kind() == FunctionKind::Function - { + if is_dynamic_function { let args_identifiers = utils::fnsig_argument_identifiers(ctx, signature); let return_item = ctx.resolve_item(signature.return_type()); @@ -4040,6 +4048,7 @@ impl CodeGenerator for Function { args_identifiers, ret, ret_ty, + attributes, ); } else { result.push(tokens); diff --git a/tests/expectations/tests/dynamic_loading_attributes.rs b/tests/expectations/tests/dynamic_loading_attributes.rs new file mode 100644 index 0000000000..b50fbd08c4 --- /dev/null +++ b/tests/expectations/tests/dynamic_loading_attributes.rs @@ -0,0 +1,56 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +extern crate libloading; +pub struct TestLib { + __library: ::libloading::Library, + pub foo: unsafe extern "C" fn( + x: ::std::os::raw::c_int, + y: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + pub baz: unsafe extern "C" fn() -> ::std::os::raw::c_int, +} +impl TestLib { + pub unsafe fn new

(path: P) -> Result + where + P: AsRef<::std::ffi::OsStr>, + { + let library = ::libloading::Library::new(path)?; + Self::from_library(library) + } + pub unsafe fn from_library( + library: L, + ) -> Result + where + L: Into<::libloading::Library>, + { + let __library = library.into(); + let foo = __library.get(b"foo\0").map(|sym| *sym)?; + let baz = __library.get(b"baz\0").map(|sym| *sym)?; + Ok(TestLib { + __library, + foo, + baz, + }) + } + #[must_use] + #[doc = " @brief A function"] + #[doc = ""] + #[doc = " @param x"] + #[doc = " @param y"] + #[doc = " @return int"] + pub unsafe fn foo( + &self, + x: ::std::os::raw::c_int, + y: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int { + (self.foo)(x, y) + } + pub unsafe fn baz(&self) -> ::std::os::raw::c_int { + (self.baz)() + } +} diff --git a/tests/headers/dynamic_loading_attributes.h b/tests/headers/dynamic_loading_attributes.h new file mode 100644 index 0000000000..e2ca62b159 --- /dev/null +++ b/tests/headers/dynamic_loading_attributes.h @@ -0,0 +1,11 @@ +// bindgen-flags: --dynamic-loading TestLib --dynamic-link-require-all --enable-function-attribute-detection +/** + * @brief A function + * + * @param x + * @param y + * @return int + */ +__attribute__((warn_unused_result)) +int foo(int x, int y); +int baz() ; From c27578fac5372575e3caa933a83eac931ae3b53f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 15 Mar 2022 04:01:13 +0100 Subject: [PATCH 282/942] codegen: Fix minor clippy warning. --- src/codegen/mod.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 7c8e26463f..ffa6879baa 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -3907,25 +3907,19 @@ impl CodeGenerator for Function { Linkage::External => {} } - #[allow(clippy::needless_late_init)] - let is_dynamic_function; // Pure virtual methods have no actual symbol, so we can't generate // something meaningful for them. - match self.kind() { + let is_dynamic_function = match self.kind() { FunctionKind::Method(ref method_kind) if method_kind.is_pure_virtual() => { return None; } FunctionKind::Function => { - // If we're generating for dynamic loading, some attributes can not be emitted. - is_dynamic_function = - ctx.options().dynamic_library_name.is_some() + ctx.options().dynamic_library_name.is_some() } - _ => { - is_dynamic_function = false; - } - } + _ => false, + }; // Similar to static member variables in a class template, we can't // generate bindings to template functions, because the set of From 841fd4c8dc3790b068e2b63fbf892ccad5f17e00 Mon Sep 17 00:00:00 2001 From: Alan Wu Date: Wed, 13 Apr 2022 18:55:49 -0400 Subject: [PATCH 283/942] Use common type alias for anonymous enums in consts mode Previously, anonymous enums generated a type alias but did not use it. For example the following: ```C enum { ZERO, ONE = 4999, }; ``` Generated this: ```Rust /* automatically generated by rust-bindgen 0.59.2 */ pub const ZERO: ::std::os::raw::c_uint = 0; pub const ONE: ::std::os::raw::c_uint = 4999; pub type _bindgen_ty_1 = ::std::os::raw::c_uint; ``` For use cases where humans look at bindgen's Rust output this was a little strange since it's a deviation from how the Rust output for named enums is organized, where all constants share the same type using the type alias. The unused type alias also triggered the dead_code lint. Change to use the generated type alias. --- src/codegen/mod.rs | 8 ++------ tests/expectations/tests/enum-default-consts.rs | 6 +++--- tests/expectations/tests/enum.rs | 6 +++--- tests/expectations/tests/enum_explicit_type_constants.rs | 4 ++-- .../tests/parsecb-anonymous-enum-variant-rename.rs | 2 +- 5 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index ffa6879baa..99cdf3c86b 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -2625,7 +2625,6 @@ enum EnumBuilder<'a> { is_bitfield: bool, }, Consts { - repr: proc_macro2::TokenStream, variants: Vec, codegen_depth: usize, }, @@ -2696,7 +2695,6 @@ impl<'a> EnumBuilder<'a> { }); EnumBuilder::Consts { - repr, variants, codegen_depth: enum_codegen_depth, } @@ -2800,7 +2798,7 @@ impl<'a> EnumBuilder<'a> { self } - EnumBuilder::Consts { ref repr, .. } => { + EnumBuilder::Consts { .. } => { let constant_name = match mangling_prefix { Some(prefix) => { Cow::Owned(format!("{}_{}", prefix, variant_name)) @@ -2808,12 +2806,10 @@ impl<'a> EnumBuilder<'a> { None => variant_name, }; - let ty = if is_ty_named { &rust_ty } else { repr }; - let ident = ctx.rust_ident(constant_name); result.push(quote! { #doc - pub const #ident : #ty = #expr ; + pub const #ident : #rust_ty = #expr ; }); self diff --git a/tests/expectations/tests/enum-default-consts.rs b/tests/expectations/tests/enum-default-consts.rs index 5c023a3c64..d7f5d7c28a 100644 --- a/tests/expectations/tests/enum-default-consts.rs +++ b/tests/expectations/tests/enum-default-consts.rs @@ -10,8 +10,8 @@ pub struct foo { pub member: foo__bindgen_ty_1, } -pub const foo_FOO_A: ::std::os::raw::c_uint = 0; -pub const foo_FOO_B: ::std::os::raw::c_uint = 1; +pub const foo_FOO_A: foo__bindgen_ty_1 = 0; +pub const foo_FOO_B: foo__bindgen_ty_1 = 1; pub type foo__bindgen_ty_1 = ::std::os::raw::c_uint; #[test] fn bindgen_test_layout_foo() { @@ -60,4 +60,4 @@ pub type NoDebug = ::std::os::raw::c_uint; pub const Debug_Debug1: Debug = 0; pub const Debug_Debug2: Debug = 1; ///

-pub type Debug = ::std::os::raw::c_uint; \ No newline at end of file +pub type Debug = ::std::os::raw::c_uint; diff --git a/tests/expectations/tests/enum.rs b/tests/expectations/tests/enum.rs index cc3f4932ca..fd76151f9f 100644 --- a/tests/expectations/tests/enum.rs +++ b/tests/expectations/tests/enum.rs @@ -10,8 +10,8 @@ pub struct foo { pub member: foo__bindgen_ty_1, } -pub const foo_FOO_A: ::std::os::raw::c_uint = 0; -pub const foo_FOO_B: ::std::os::raw::c_uint = 1; +pub const foo_FOO_A: foo__bindgen_ty_1 = 0; +pub const foo_FOO_B: foo__bindgen_ty_1 = 1; pub type foo__bindgen_ty_1 = ::std::os::raw::c_uint; #[test] fn bindgen_test_layout_foo() { @@ -58,4 +58,4 @@ pub type NoDebug = ::std::os::raw::c_uint; pub const Debug_Debug1: Debug = 0; pub const Debug_Debug2: Debug = 1; ///
-pub type Debug = ::std::os::raw::c_uint; \ No newline at end of file +pub type Debug = ::std::os::raw::c_uint; diff --git a/tests/expectations/tests/enum_explicit_type_constants.rs b/tests/expectations/tests/enum_explicit_type_constants.rs index 117f684723..0c833b6640 100644 --- a/tests/expectations/tests/enum_explicit_type_constants.rs +++ b/tests/expectations/tests/enum_explicit_type_constants.rs @@ -26,6 +26,6 @@ pub type BoolEnumsAreFun = bool; pub type MyType = bool; pub const BoolEnumsAreFun2_Value2: BoolEnumsAreFun2 = true; pub type BoolEnumsAreFun2 = MyType; -pub const AnonymousVariantOne: ::std::os::raw::c_uchar = 0; -pub const AnonymousVariantTwo: ::std::os::raw::c_uchar = 1; +pub const AnonymousVariantOne: _bindgen_ty_1 = 0; +pub const AnonymousVariantTwo: _bindgen_ty_1 = 1; pub type _bindgen_ty_1 = ::std::os::raw::c_uchar; diff --git a/tests/expectations/tests/parsecb-anonymous-enum-variant-rename.rs b/tests/expectations/tests/parsecb-anonymous-enum-variant-rename.rs index e615486ed8..8ead5b8a60 100644 --- a/tests/expectations/tests/parsecb-anonymous-enum-variant-rename.rs +++ b/tests/expectations/tests/parsecb-anonymous-enum-variant-rename.rs @@ -5,5 +5,5 @@ non_upper_case_globals )] -pub const RENAMED_MyVal: ::std::os::raw::c_uint = 0; +pub const RENAMED_MyVal: _bindgen_ty_1 = 0; pub type _bindgen_ty_1 = ::std::os::raw::c_uint; From ee6ff69229ee20914fe262d32624f0b01e441e20 Mon Sep 17 00:00:00 2001 From: Henryk Paluch Date: Tue, 19 Apr 2022 17:51:14 +0200 Subject: [PATCH 284/942] Fix panic!() argument (quote it) --- book/src/tutorial-5.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/src/tutorial-5.md b/book/src/tutorial-5.md index 54b4dda524..de91d092a1 100644 --- a/book/src/tutorial-5.md +++ b/book/src/tutorial-5.md @@ -61,7 +61,7 @@ mod tests { // Finish the compression stream. let result = BZ2_bzCompressEnd(&mut stream as *mut _); match result { - r if r == (BZ_PARAM_ERROR as _) => panic!(BZ_PARAM_ERROR), + r if r == (BZ_PARAM_ERROR as _) => panic!("BZ_PARAM_ERROR"), r if r == (BZ_OK as _) => {}, r => panic!("Unknown return value = {}", r), } From 4b085b45f83f4722b13820d031dd8269812fe48c Mon Sep 17 00:00:00 2001 From: Michal Rostecki Date: Wed, 4 May 2022 14:11:30 +0200 Subject: [PATCH 285/942] Derive from any other trait only when deriving from Copy It's impossible to #[derive] from any other trait when not deriving from Copy when using the newest Rust nightly. Any attempt to do that results in the following error: error: `#[derive]` can't be used on a `#[repr(packed)]` struct that does not derive Copy (error E0133) Fixes: #2083 Signed-off-by: Michal Rostecki --- src/codegen/mod.rs | 35 +++++++++++++++-------- tests/expectations/tests/packed-vtable.rs | 1 - 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 99cdf3c86b..4fcbaefd97 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -110,17 +110,13 @@ bitflags! { } } -fn derives_of_item(item: &Item, ctx: &BindgenContext) -> DerivableTraits { +fn derives_of_item( + item: &Item, + ctx: &BindgenContext, + packed: bool, +) -> DerivableTraits { let mut derivable_traits = DerivableTraits::empty(); - if item.can_derive_debug(ctx) && !item.annotations().disallow_debug() { - derivable_traits |= DerivableTraits::DEBUG; - } - - if item.can_derive_default(ctx) && !item.annotations().disallow_default() { - derivable_traits |= DerivableTraits::DEFAULT; - } - let all_template_params = item.all_template_params(ctx); if item.can_derive_copy(ctx) && !item.annotations().disallow_copy() { @@ -137,6 +133,18 @@ fn derives_of_item(item: &Item, ctx: &BindgenContext) -> DerivableTraits { // It's not hard to fix though. derivable_traits |= DerivableTraits::CLONE; } + } else if packed { + // If the struct or union is packed, deriving from Copy is required for + // deriving from any other trait. + return derivable_traits; + } + + if item.can_derive_debug(ctx) && !item.annotations().disallow_debug() { + derivable_traits |= DerivableTraits::DEBUG; + } + + if item.can_derive_default(ctx) && !item.annotations().disallow_default() { + derivable_traits |= DerivableTraits::DEFAULT; } if item.can_derive_hash(ctx) { @@ -926,7 +934,9 @@ impl CodeGenerator for Type { let mut attributes = vec![attributes::repr("transparent")]; - let derivable_traits = derives_of_item(item, ctx); + let packed = false; // Types can't be packed in Rust. + let derivable_traits = + derives_of_item(item, ctx, packed); if !derivable_traits.is_empty() { let derives: Vec<_> = derivable_traits.into(); attributes.push(attributes::derives(&derives)) @@ -2026,7 +2036,7 @@ impl CodeGenerator for CompInfo { } } - let derivable_traits = derives_of_item(item, ctx); + let derivable_traits = derives_of_item(item, ctx, packed); if !derivable_traits.contains(DerivableTraits::DEBUG) { needs_debug_impl = ctx.options().derive_debug && ctx.options().impl_debug && @@ -3048,7 +3058,8 @@ impl CodeGenerator for Enum { } if !variation.is_const() { - let mut derives = derives_of_item(item, ctx); + let packed = false; // Enums can't be packed in Rust. + let mut derives = derives_of_item(item, ctx, packed); // For backwards compat, enums always derive // Clone/Eq/PartialEq/Hash, even if we don't generate those by // default. diff --git a/tests/expectations/tests/packed-vtable.rs b/tests/expectations/tests/packed-vtable.rs index 0069eada96..71688151f5 100644 --- a/tests/expectations/tests/packed-vtable.rs +++ b/tests/expectations/tests/packed-vtable.rs @@ -9,7 +9,6 @@ #[repr(C)] pub struct PackedVtable__bindgen_vtable(::std::os::raw::c_void); #[repr(C, packed)] -#[derive(Debug)] pub struct PackedVtable { pub vtable_: *const PackedVtable__bindgen_vtable, } From 7766ab7166dd5765850ac397a2c960e93de4a599 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 29 Apr 2022 19:46:10 -0700 Subject: [PATCH 286/942] Update GitHub Actions actions/checkout@v2 to v3 The v2 implementation uses Node 12, which is end-of-life on April 30, 2022. See https://nodejs.org/en/about/releases/. Update to v3, which is based on Node 16 whose support lasts until April 30, 2024. --- .github/workflows/bindgen.yml | 12 ++++++------ .github/workflows/deploy-book.yml | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 32a5287d32..71baf542f0 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Install stable uses: actions-rs/toolchain@v1 @@ -40,7 +40,7 @@ jobs: msrv: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Install msrv uses: actions-rs/toolchain@v1 @@ -57,7 +57,7 @@ jobs: quickchecking: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Install stable uses: actions-rs/toolchain@v1 @@ -78,7 +78,7 @@ jobs: # broken. os: [ubuntu-latest, macos-latest] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Install stable uses: actions-rs/toolchain@v1 @@ -142,7 +142,7 @@ jobs: feature_extra_asserts: 0 feature_testing_only_docs: 0 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Install multiarch packages if: matrix.target.debian @@ -184,7 +184,7 @@ jobs: test-book: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Install stable uses: actions-rs/toolchain@v1 diff --git a/.github/workflows/deploy-book.yml b/.github/workflows/deploy-book.yml index bf03d34b63..ce7083c8c8 100644 --- a/.github/workflows/deploy-book.yml +++ b/.github/workflows/deploy-book.yml @@ -9,7 +9,7 @@ jobs: deploy-book: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: persist-credentials: false From bbffd83f0328095357465fe9a6e9eb3e311f4822 Mon Sep 17 00:00:00 2001 From: jakobgerhardt Date: Tue, 26 Apr 2022 23:40:12 +0200 Subject: [PATCH 287/942] provide information how to link to shared objects --- book/src/tutorial-3.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/book/src/tutorial-3.md b/book/src/tutorial-3.md index 139a24f9a3..dcd67c5ca8 100644 --- a/book/src/tutorial-3.md +++ b/book/src/tutorial-3.md @@ -7,6 +7,8 @@ bindings to `bzip2` at compile time. The resulting bindings will be written to `$OUT_DIR/bindings.rs` where `$OUT_DIR` is chosen by `cargo` and is something like `./target/debug/build/bindgen-tutorial-bzip2-sys-afc7747d7eafd720/out/`. +Note that the associated shared object to `bz2` is `libbz2.so`. In general, a `lib.so` should be referenced in the build file by ``. + ```rust,ignore extern crate bindgen; @@ -14,6 +16,9 @@ use std::env; use std::path::PathBuf; fn main() { + // Tell cargo to look for shared libraries in the specified directory + println!("cargo:rustc-link-search=/path/to/lib"); + // Tell cargo to tell rustc to link the system bzip2 // shared library. println!("cargo:rustc-link-lib=bz2"); From 92487d4ed4c7ed0c006f461986b410b17f24cfa8 Mon Sep 17 00:00:00 2001 From: alexdevteam Date: Sun, 24 Apr 2022 14:23:11 +0200 Subject: [PATCH 288/942] Fix NoneType error --- csmith-fuzzing/predicate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/csmith-fuzzing/predicate.py b/csmith-fuzzing/predicate.py index 8925755c62..6ca5047659 100755 --- a/csmith-fuzzing/predicate.py +++ b/csmith-fuzzing/predicate.py @@ -219,7 +219,7 @@ def run_bindgen(args, bindings): if not args.expect_bindgen_fail and child.returncode != 0: exit_1("Error: running `bindgen` failed", child) - for arg in args.bindings_grep: + for arg in args.bindings_grep or []: pattern = regexp(arg) with open(bindings, mode="r") as f: if not contains(pattern, f): From 5a01c551993e56d20240ef64d0ec78cd4195855d Mon Sep 17 00:00:00 2001 From: Gavin Li Date: Thu, 12 May 2022 13:38:17 -0700 Subject: [PATCH 289/942] Fix "dereferencing a null pointer" in C layout tests Instead of dereferencing a null pointer, create a MaybeUninit from which we can extract well-defined addresses. --- src/codegen/mod.rs | 4 +- tests/expectations/tests/16-byte-alignment.rs | 74 ++- .../tests/16-byte-alignment_1_0.rs | 74 ++- tests/expectations/tests/accessors.rs | 80 ++- tests/expectations/tests/allowlist-file.rs | 18 +- .../tests/allowlist-namespaces.rs | 4 +- .../allowlisted-item-references-no-hash.rs | 4 +- ...llowlisted-item-references-no-partialeq.rs | 4 +- .../allowlisted_item_references_no_copy.rs | 4 +- tests/expectations/tests/annotation_hide.rs | 4 +- .../expectations/tests/anon-fields-prefix.rs | 42 +- tests/expectations/tests/anon_enum.rs | 12 +- .../tests/anon_struct_in_union.rs | 17 +- .../tests/anon_struct_in_union_1_0.rs | 17 +- .../tests/array-of-zero-sized-types.rs | 5 +- .../tests/bindgen-union-inside-namespace.rs | 8 +- tests/expectations/tests/bitfield-linux-32.rs | 6 +- tests/expectations/tests/bitfield_align.rs | 30 +- .../tests/blocklist-and-impl-debug.rs | 6 +- tests/expectations/tests/blocklist-file.rs | 19 +- tests/expectations/tests/blocks-signature.rs | 12 +- tests/expectations/tests/blocks.rs | 12 +- tests/expectations/tests/c_naming.rs | 18 +- tests/expectations/tests/canonical-types.rs | 12 +- tests/expectations/tests/char.rs | 72 ++- tests/expectations/tests/class.rs | 66 ++- tests/expectations/tests/class_1_0.rs | 66 ++- tests/expectations/tests/class_nested.rs | 22 +- tests/expectations/tests/class_no_members.rs | 6 +- tests/expectations/tests/class_use_as.rs | 11 +- tests/expectations/tests/class_with_dtor.rs | 6 +- .../tests/class_with_inner_struct.rs | 89 +++- .../tests/class_with_inner_struct_1_0.rs | 89 +++- .../expectations/tests/class_with_typedef.rs | 36 +- tests/expectations/tests/comment-indent.rs | 4 +- tests/expectations/tests/complex.rs | 18 +- .../expectations/tests/const-const-mut-ptr.rs | 6 +- .../tests/constified-enum-module-overflow.rs | 6 +- .../expectations/tests/constify-all-enums.rs | 6 +- .../tests/constify-module-enums-basic.rs | 6 +- .../tests/constify-module-enums-namespace.rs | 6 +- .../constify-module-enums-shadow-name.rs | 6 +- .../constify-module-enums-simple-alias.rs | 40 +- ...onstify-module-enums-simple-nonamespace.rs | 12 +- .../tests/constify-module-enums-types.rs | 70 ++- .../tests/contains-vs-inherits-zero-sized.rs | 16 +- tests/expectations/tests/convert-floats.rs | 32 +- .../expectations/tests/ctypes-prefix-path.rs | 18 +- .../tests/derive-bitfield-method-same-name.rs | 6 +- tests/expectations/tests/derive-clone.rs | 5 +- tests/expectations/tests/derive-clone_1_0.rs | 5 +- .../tests/derive-debug-bitfield-core.rs | 4 +- .../tests/derive-debug-bitfield.rs | 4 +- .../tests/derive-debug-function-pointer.rs | 8 +- .../tests/derive-debug-mangle-name.rs | 19 +- ...ive-debug-opaque-template-instantiation.rs | 4 +- .../expectations/tests/derive-debug-opaque.rs | 4 +- .../tests/derive-default-and-blocklist.rs | 6 +- tests/expectations/tests/derive-fn-ptr.rs | 8 +- .../tests/derive-hash-and-blocklist.rs | 6 +- .../tests/derive-hash-blocklisting.rs | 8 +- ...rive-hash-struct-with-anon-struct-float.rs | 14 +- .../derive-hash-struct-with-float-array.rs | 6 +- ...erive-hash-struct-with-incomplete-array.rs | 12 +- .../tests/derive-hash-struct-with-pointer.rs | 17 +- .../tests/derive-hash-template-inst-float.rs | 12 +- .../tests/derive-partialeq-and-blocklist.rs | 6 +- .../tests/derive-partialeq-base.rs | 6 +- .../tests/derive-partialeq-bitfield.rs | 4 +- .../tests/derive-partialeq-core.rs | 4 +- .../tests/derive-partialeq-pointer.rs | 12 +- .../tests/derive-partialeq-union.rs | 12 +- .../tests/derive-partialeq-union_1_0.rs | 12 +- .../tests/disable-nested-struct-naming.rs | 67 ++- .../tests/disable-untagged-union.rs | 12 +- .../expectations/tests/do-not-derive-copy.rs | 7 +- tests/expectations/tests/doggo-or-null.rs | 6 +- .../duplicated-namespaces-definitions.rs | 12 +- .../tests/dynamic_loading_with_blocklist.rs | 6 +- .../tests/dynamic_loading_with_class.rs | 6 +- .../tests/enum-default-bitfield.rs | 8 +- .../expectations/tests/enum-default-consts.rs | 6 +- .../expectations/tests/enum-default-module.rs | 8 +- tests/expectations/tests/enum-default-rust.rs | 8 +- .../expectations/tests/enum-no-debug-rust.rs | 6 +- tests/expectations/tests/enum.rs | 6 +- .../tests/enum_and_vtable_mangling.rs | 6 +- tests/expectations/tests/explicit-padding.rs | 24 +- .../expectations/tests/extern-const-struct.rs | 4 +- .../tests/forward-declaration-autoptr.rs | 4 +- .../tests/forward_declared_complex_types.rs | 6 +- .../forward_declared_complex_types_1_0.rs | 6 +- .../tests/forward_declared_struct.rs | 12 +- .../expectations/tests/func_ptr_in_struct.rs | 6 +- .../expectations/tests/gen-destructors-neg.rs | 6 +- tests/expectations/tests/gen-destructors.rs | 6 +- tests/expectations/tests/i128.rs | 8 +- tests/expectations/tests/inline_namespace.rs | 6 +- .../tests/inline_namespace_conservative.rs | 6 +- tests/expectations/tests/inner_const.rs | 6 +- .../expectations/tests/inner_template_self.rs | 5 +- .../tests/issue-1118-using-forward-decl.rs | 8 +- .../tests/issue-1216-variadic-member.rs | 6 +- tests/expectations/tests/issue-1281.rs | 18 +- tests/expectations/tests/issue-1285.rs | 14 +- tests/expectations/tests/issue-1291.rs | 76 ++- .../tests/issue-1382-rust-primitive-types.rs | 84 +++- tests/expectations/tests/issue-1443.rs | 48 +- tests/expectations/tests/issue-1454.rs | 4 +- tests/expectations/tests/issue-1498.rs | 39 +- tests/expectations/tests/issue-1947.rs | 12 +- .../tests/issue-1977-larger-arrays.rs | 4 +- tests/expectations/tests/issue-1995.rs | 6 +- tests/expectations/tests/issue-2019.rs | 12 +- tests/expectations/tests/issue-372.rs | 30 +- .../tests/issue-537-repr-packed-n.rs | 24 +- tests/expectations/tests/issue-537.rs | 24 +- .../tests/issue-573-layout-test-failures.rs | 4 +- .../issue-574-assertion-failure-in-codegen.rs | 4 +- ...issue-584-stylo-template-analysis-panic.rs | 6 +- .../tests/issue-639-typedef-anon-field.rs | 18 +- .../tests/issue-643-inner-struct.rs | 10 +- .../issue-648-derive-debug-with-padding.rs | 20 +- tests/expectations/tests/issue-674-1.rs | 6 +- tests/expectations/tests/issue-674-2.rs | 12 +- tests/expectations/tests/issue-674-3.rs | 10 +- .../tests/issue-801-opaque-sloppiness.rs | 6 +- ...07-opaque-types-methods-being-generated.rs | 5 +- .../issue-944-derive-copy-and-blocklisting.rs | 4 +- .../expectations/tests/jsval_layout_opaque.rs | 64 ++- .../tests/jsval_layout_opaque_1_0.rs | 64 ++- tests/expectations/tests/layout_align.rs | 5 +- tests/expectations/tests/layout_arp.rs | 45 +- tests/expectations/tests/layout_array.rs | 78 +-- .../tests/layout_array_too_long.rs | 73 ++- .../tests/layout_cmdline_token.rs | 47 +- tests/expectations/tests/layout_eth_conf.rs | 461 ++++++++++++------ .../expectations/tests/layout_eth_conf_1_0.rs | 461 ++++++++++++------ tests/expectations/tests/layout_kni_mbuf.rs | 63 ++- .../tests/layout_large_align_field.rs | 166 ++++--- tests/expectations/tests/layout_mbuf.rs | 184 ++++--- tests/expectations/tests/layout_mbuf_1_0.rs | 184 ++++--- .../tests/libclang-5/call-conv-field.rs | 12 +- .../type_alias_template_specialized.rs | 6 +- .../tests/libclang-9/call-conv-field.rs | 12 +- tests/expectations/tests/libclang-9/class.rs | 164 +++++-- .../tests/libclang-9/class_1_0.rs | 164 +++++-- ...erive-hash-struct-with-incomplete-array.rs | 42 +- .../libclang-9/incomplete-array-padding.rs | 6 +- .../libclang-9/issue-643-inner-struct.rs | 26 +- .../tests/libclang-9/layout_align.rs | 26 +- .../type_alias_template_specialized.rs | 6 +- .../tests/libclang-9/zero-sized-array.rs | 21 +- tests/expectations/tests/long_double.rs | 6 +- tests/expectations/tests/msvc-no-usr.rs | 6 +- tests/expectations/tests/mutable.rs | 24 +- tests/expectations/tests/namespace.rs | 6 +- tests/expectations/tests/nested.rs | 14 +- .../tests/nested_within_namespace.rs | 12 +- tests/expectations/tests/no-comments.rs | 6 +- tests/expectations/tests/no-derive-debug.rs | 12 +- tests/expectations/tests/no-derive-default.rs | 12 +- .../expectations/tests/no-hash-allowlisted.rs | 6 +- .../tests/no-partialeq-allowlisted.rs | 4 +- .../tests/no-recursive-allowlisting.rs | 6 +- tests/expectations/tests/no-std.rs | 18 +- .../expectations/tests/no_copy_allowlisted.rs | 6 +- .../tests/no_debug_allowlisted.rs | 6 +- .../tests/no_default_allowlisted.rs | 6 +- tests/expectations/tests/non-type-params.rs | 15 +- .../expectations/tests/objc_interface_type.rs | 4 +- .../tests/opaque-template-inst-member-2.rs | 18 +- .../tests/opaque-template-inst-member.rs | 18 +- ...paque-template-instantiation-namespaced.rs | 21 +- .../tests/opaque-template-instantiation.rs | 13 +- tests/expectations/tests/opaque_in_struct.rs | 4 +- tests/expectations/tests/opaque_pointer.rs | 13 +- .../tests/packed-n-with-padding.rs | 24 +- tests/expectations/tests/private.rs | 30 +- tests/expectations/tests/private_fields.rs | 32 +- .../tests/reparented_replacement.rs | 4 +- tests/expectations/tests/replace_use.rs | 6 +- tests/expectations/tests/repr-align.rs | 24 +- ...ame_struct_name_in_different_namespaces.rs | 8 +- .../tests/sentry-defined-multiple-times.rs | 47 +- tests/expectations/tests/size_t_is_usize.rs | 18 +- tests/expectations/tests/size_t_template.rs | 6 +- ...ruct_containing_forward_declared_struct.rs | 12 +- tests/expectations/tests/struct_typedef.rs | 11 +- tests/expectations/tests/struct_typedef_ns.rs | 12 +- .../tests/struct_with_anon_struct.rs | 14 +- .../tests/struct_with_anon_struct_array.rs | 28 +- .../tests/struct_with_anon_struct_pointer.rs | 14 +- .../tests/struct_with_anon_union.rs | 14 +- .../tests/struct_with_anon_union_1_0.rs | 14 +- .../tests/struct_with_anon_unnamed_struct.rs | 8 +- .../tests/struct_with_anon_unnamed_union.rs | 8 +- .../struct_with_anon_unnamed_union_1_0.rs | 8 +- .../tests/struct_with_bitfields.rs | 6 +- .../tests/struct_with_derive_debug.rs | 18 +- .../tests/struct_with_large_array.rs | 4 +- .../expectations/tests/struct_with_nesting.rs | 52 +- .../tests/struct_with_nesting_1_0.rs | 52 +- .../expectations/tests/struct_with_packing.rs | 12 +- .../expectations/tests/struct_with_struct.rs | 14 +- tests/expectations/tests/template.rs | 94 +++- .../test_mixed_header_and_header_contents.rs | 72 ++- .../test_multiple_header_calls_in_builder.rs | 72 ++- tests/expectations/tests/timex.rs | 10 +- ...type-referenced-by-allowlisted-function.rs | 4 +- tests/expectations/tests/typeref.rs | 18 +- tests/expectations/tests/typeref_1_0.rs | 18 +- tests/expectations/tests/underscore.rs | 6 +- tests/expectations/tests/union-align.rs | 12 +- tests/expectations/tests/union-in-ns.rs | 6 +- tests/expectations/tests/union-in-ns_1_0.rs | 6 +- tests/expectations/tests/union_dtor.rs | 8 +- tests/expectations/tests/union_dtor_1_0.rs | 8 +- tests/expectations/tests/union_fields.rs | 13 +- tests/expectations/tests/union_fields_1_0.rs | 13 +- .../tests/union_with_anon_struct.rs | 14 +- .../tests/union_with_anon_struct_1_0.rs | 14 +- .../tests/union_with_anon_struct_bitfield.rs | 6 +- .../union_with_anon_struct_bitfield_1_0.rs | 6 +- .../tests/union_with_anon_union.rs | 14 +- .../tests/union_with_anon_union_1_0.rs | 14 +- .../tests/union_with_anon_unnamed_struct.rs | 30 +- .../union_with_anon_unnamed_struct_1_0.rs | 30 +- .../tests/union_with_anon_unnamed_union.rs | 14 +- .../union_with_anon_unnamed_union_1_0.rs | 14 +- .../tests/union_with_big_member.rs | 24 +- .../tests/union_with_big_member_1_0.rs | 24 +- .../expectations/tests/union_with_nesting.rs | 34 +- .../tests/union_with_nesting_1_0.rs | 34 +- tests/expectations/tests/unknown_attr.rs | 12 +- tests/expectations/tests/use-core.rs | 26 +- tests/expectations/tests/use-core_1_0.rs | 26 +- tests/expectations/tests/var-tracing.rs | 6 +- tests/expectations/tests/vector.rs | 6 +- .../expectations/tests/virtual_inheritance.rs | 18 +- tests/expectations/tests/weird_bitfields.rs | 59 ++- .../tests/zero-size-array-align.rs | 12 +- tests/expectations/tests/zero-sized-array.rs | 10 +- 243 files changed, 4453 insertions(+), 1672 deletions(-) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 4fcbaefd97..e4ce95264f 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -2192,7 +2192,9 @@ impl CodeGenerator for CompInfo { quote! { assert_eq!( unsafe { - &(*(::#prefix::ptr::null::<#canonical_ident>())).#field_name as *const _ as usize + let uninit = ::#prefix::mem::MaybeUninit::<#canonical_ident>::uninit(); + let ptr = uninit.as_ptr(); + ::#prefix::ptr::addr_of!((*ptr).#field_name) as usize - ptr as usize }, #field_offset, concat!("Offset of field: ", stringify!(#canonical_ident), "::", stringify!(#field_name)) diff --git a/tests/expectations/tests/16-byte-alignment.rs b/tests/expectations/tests/16-byte-alignment.rs index 058568f24c..c690cc8e87 100644 --- a/tests/expectations/tests/16-byte-alignment.rs +++ b/tests/expectations/tests/16-byte-alignment.rs @@ -44,9 +44,11 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::( - ))) - .dport as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dport) as usize - ptr as usize }, 0usize, concat!( @@ -58,9 +60,11 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::( - ))) - .sport as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).sport) as usize - ptr as usize }, 2usize, concat!( @@ -85,8 +89,11 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).sctp_tag - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).sctp_tag) as usize - ptr as usize }, 0usize, concat!( @@ -120,8 +127,9 @@ fn bindgen_test_layout_rte_ipv4_tuple() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).src_addr as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).src_addr) as usize - ptr as usize }, 0usize, concat!( @@ -133,8 +141,9 @@ fn bindgen_test_layout_rte_ipv4_tuple() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).dst_addr as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dst_addr) as usize - ptr as usize }, 4usize, concat!( @@ -193,9 +202,11 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::( - ))) - .dport as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dport) as usize - ptr as usize }, 0usize, concat!( @@ -207,9 +218,11 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::( - ))) - .sport as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).sport) as usize - ptr as usize }, 2usize, concat!( @@ -234,8 +247,11 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).sctp_tag - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).sctp_tag) as usize - ptr as usize }, 0usize, concat!( @@ -269,8 +285,9 @@ fn bindgen_test_layout_rte_ipv6_tuple() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).src_addr as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).src_addr) as usize - ptr as usize }, 0usize, concat!( @@ -282,8 +299,9 @@ fn bindgen_test_layout_rte_ipv6_tuple() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).dst_addr as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dst_addr) as usize - ptr as usize }, 16usize, concat!( @@ -324,7 +342,9 @@ fn bindgen_test_layout_rte_thash_tuple() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).v4 as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).v4) as usize - ptr as usize }, 0usize, concat!( @@ -336,7 +356,9 @@ fn bindgen_test_layout_rte_thash_tuple() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).v6 as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).v6) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/16-byte-alignment_1_0.rs b/tests/expectations/tests/16-byte-alignment_1_0.rs index 1df6778b56..304b6bc150 100644 --- a/tests/expectations/tests/16-byte-alignment_1_0.rs +++ b/tests/expectations/tests/16-byte-alignment_1_0.rs @@ -89,9 +89,11 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::( - ))) - .dport as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dport) as usize - ptr as usize }, 0usize, concat!( @@ -103,9 +105,11 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::( - ))) - .sport as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).sport) as usize - ptr as usize }, 2usize, concat!( @@ -135,8 +139,11 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).sctp_tag - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).sctp_tag) as usize - ptr as usize }, 0usize, concat!( @@ -166,8 +173,9 @@ fn bindgen_test_layout_rte_ipv4_tuple() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).src_addr as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).src_addr) as usize - ptr as usize }, 0usize, concat!( @@ -179,8 +187,9 @@ fn bindgen_test_layout_rte_ipv4_tuple() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).dst_addr as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dst_addr) as usize - ptr as usize }, 4usize, concat!( @@ -237,9 +246,11 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::( - ))) - .dport as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dport) as usize - ptr as usize }, 0usize, concat!( @@ -251,9 +262,11 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::( - ))) - .sport as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).sport) as usize - ptr as usize }, 2usize, concat!( @@ -283,8 +296,11 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).sctp_tag - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).sctp_tag) as usize - ptr as usize }, 0usize, concat!( @@ -314,8 +330,9 @@ fn bindgen_test_layout_rte_ipv6_tuple() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).src_addr as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).src_addr) as usize - ptr as usize }, 0usize, concat!( @@ -327,8 +344,9 @@ fn bindgen_test_layout_rte_ipv6_tuple() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).dst_addr as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dst_addr) as usize - ptr as usize }, 16usize, concat!( @@ -360,7 +378,9 @@ fn bindgen_test_layout_rte_thash_tuple() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).v4 as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).v4) as usize - ptr as usize }, 0usize, concat!( @@ -372,7 +392,9 @@ fn bindgen_test_layout_rte_thash_tuple() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).v6 as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).v6) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/accessors.rs b/tests/expectations/tests/accessors.rs index 9977baa282..0771eceb59 100644 --- a/tests/expectations/tests/accessors.rs +++ b/tests/expectations/tests/accessors.rs @@ -30,8 +30,9 @@ fn bindgen_test_layout_SomeAccessors() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mNoAccessor as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mNoAccessor) as usize - ptr as usize }, 0usize, concat!( @@ -43,8 +44,9 @@ fn bindgen_test_layout_SomeAccessors() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mBothAccessors as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBothAccessors) as usize - ptr as usize }, 4usize, concat!( @@ -56,8 +58,10 @@ fn bindgen_test_layout_SomeAccessors() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mUnsafeAccessors - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mUnsafeAccessors) as usize - + ptr as usize }, 8usize, concat!( @@ -69,8 +73,10 @@ fn bindgen_test_layout_SomeAccessors() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mImmutableAccessor - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mImmutableAccessor) as usize - + ptr as usize }, 12usize, concat!( @@ -126,8 +132,9 @@ fn bindgen_test_layout_AllAccessors() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mBothAccessors as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBothAccessors) as usize - ptr as usize }, 0usize, concat!( @@ -139,8 +146,10 @@ fn bindgen_test_layout_AllAccessors() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mAlsoBothAccessors - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mAlsoBothAccessors) as usize - + ptr as usize }, 4usize, concat!( @@ -190,8 +199,10 @@ fn bindgen_test_layout_AllUnsafeAccessors() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mBothAccessors - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBothAccessors) as usize - ptr as usize }, 0usize, concat!( @@ -203,8 +214,11 @@ fn bindgen_test_layout_AllUnsafeAccessors() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mAlsoBothAccessors - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mAlsoBothAccessors) as usize - + ptr as usize }, 4usize, concat!( @@ -263,8 +277,10 @@ fn bindgen_test_layout_ContradictAccessors() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mBothAccessors - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBothAccessors) as usize - ptr as usize }, 0usize, concat!( @@ -276,8 +292,10 @@ fn bindgen_test_layout_ContradictAccessors() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mNoAccessors - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mNoAccessors) as usize - ptr as usize }, 4usize, concat!( @@ -289,8 +307,11 @@ fn bindgen_test_layout_ContradictAccessors() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mUnsafeAccessors - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mUnsafeAccessors) as usize - + ptr as usize }, 8usize, concat!( @@ -302,8 +323,11 @@ fn bindgen_test_layout_ContradictAccessors() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mImmutableAccessor - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mImmutableAccessor) as usize - + ptr as usize }, 12usize, concat!( @@ -358,7 +382,9 @@ fn bindgen_test_layout_Replaced() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mAccessor as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mAccessor) as usize - ptr as usize }, 0usize, concat!( @@ -399,7 +425,9 @@ fn bindgen_test_layout_Wrapper() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mReplaced as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mReplaced) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/allowlist-file.rs b/tests/expectations/tests/allowlist-file.rs index 2c2660a606..462f690bc3 100644 --- a/tests/expectations/tests/allowlist-file.rs +++ b/tests/expectations/tests/allowlist-file.rs @@ -70,8 +70,11 @@ fn bindgen_test_layout_StructWithAllowlistedDefinition() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).other - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + StructWithAllowlistedDefinition, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).other) as usize - ptr as usize }, 0usize, concat!( @@ -110,8 +113,11 @@ fn bindgen_test_layout_StructWithAllowlistedFwdDecl() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).b - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( @@ -141,7 +147,9 @@ fn bindgen_test_layout_AllowlistMe() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).foo as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/allowlist-namespaces.rs b/tests/expectations/tests/allowlist-namespaces.rs index 4236f63ed9..c789ec6353 100644 --- a/tests/expectations/tests/allowlist-namespaces.rs +++ b/tests/expectations/tests/allowlist-namespaces.rs @@ -53,7 +53,9 @@ pub mod root { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).helper as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).helper) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/allowlisted-item-references-no-hash.rs b/tests/expectations/tests/allowlisted-item-references-no-hash.rs index bc3fde1ded..d11fc5bea8 100644 --- a/tests/expectations/tests/allowlisted-item-references-no-hash.rs +++ b/tests/expectations/tests/allowlisted-item-references-no-hash.rs @@ -42,7 +42,9 @@ fn bindgen_test_layout_AllowlistMe() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/allowlisted-item-references-no-partialeq.rs b/tests/expectations/tests/allowlisted-item-references-no-partialeq.rs index f26f692391..8501c479d9 100644 --- a/tests/expectations/tests/allowlisted-item-references-no-partialeq.rs +++ b/tests/expectations/tests/allowlisted-item-references-no-partialeq.rs @@ -42,7 +42,9 @@ fn bindgen_test_layout_AllowlistMe() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/allowlisted_item_references_no_copy.rs b/tests/expectations/tests/allowlisted_item_references_no_copy.rs index a5cb17b238..3b8f4e71e3 100644 --- a/tests/expectations/tests/allowlisted_item_references_no_copy.rs +++ b/tests/expectations/tests/allowlisted_item_references_no_copy.rs @@ -42,7 +42,9 @@ fn bindgen_test_layout_AllowlistMe() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/annotation_hide.rs b/tests/expectations/tests/annotation_hide.rs index 38435d0a4c..f2bc7be5a8 100644 --- a/tests/expectations/tests/annotation_hide.rs +++ b/tests/expectations/tests/annotation_hide.rs @@ -44,7 +44,9 @@ fn bindgen_test_layout_NotAnnotated() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).f as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/anon-fields-prefix.rs b/tests/expectations/tests/anon-fields-prefix.rs index edd551d193..e54459528c 100644 --- a/tests/expectations/tests/anon-fields-prefix.rs +++ b/tests/expectations/tests/anon-fields-prefix.rs @@ -33,8 +33,10 @@ fn bindgen_test_layout_color__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).r as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).r) as usize - ptr as usize }, 0usize, concat!( @@ -46,8 +48,10 @@ fn bindgen_test_layout_color__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).g as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).g) as usize - ptr as usize }, 1usize, concat!( @@ -59,8 +63,10 @@ fn bindgen_test_layout_color__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).b as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 2usize, concat!( @@ -92,8 +98,10 @@ fn bindgen_test_layout_color__bindgen_ty_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).y as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, 0usize, concat!( @@ -105,8 +113,10 @@ fn bindgen_test_layout_color__bindgen_ty_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).u as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize }, 1usize, concat!( @@ -118,8 +128,10 @@ fn bindgen_test_layout_color__bindgen_ty_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).v as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).v) as usize - ptr as usize }, 2usize, concat!( @@ -143,7 +155,11 @@ fn bindgen_test_layout_color() { concat!("Alignment of ", stringify!(color)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).v3 as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).v3) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(color), "::", stringify!(v3)) ); diff --git a/tests/expectations/tests/anon_enum.rs b/tests/expectations/tests/anon_enum.rs index 8cae632999..a06beb857c 100644 --- a/tests/expectations/tests/anon_enum.rs +++ b/tests/expectations/tests/anon_enum.rs @@ -30,12 +30,20 @@ fn bindgen_test_layout_Test() { concat!("Alignment of ", stringify!(Test)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).foo as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, 4usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/anon_struct_in_union.rs b/tests/expectations/tests/anon_struct_in_union.rs index 1a4040151e..f80f817bb2 100644 --- a/tests/expectations/tests/anon_struct_in_union.rs +++ b/tests/expectations/tests/anon_struct_in_union.rs @@ -34,8 +34,10 @@ fn bindgen_test_layout_s__bindgen_ty_1_inner() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).b as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( @@ -60,8 +62,9 @@ fn bindgen_test_layout_s__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).field as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).field) as usize - ptr as usize }, 0usize, concat!( @@ -94,7 +97,11 @@ fn bindgen_test_layout_s() { concat!("Alignment of ", stringify!(s)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).u as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(s), "::", stringify!(u)) ); diff --git a/tests/expectations/tests/anon_struct_in_union_1_0.rs b/tests/expectations/tests/anon_struct_in_union_1_0.rs index 021f41451b..4631b1dc07 100644 --- a/tests/expectations/tests/anon_struct_in_union_1_0.rs +++ b/tests/expectations/tests/anon_struct_in_union_1_0.rs @@ -78,8 +78,10 @@ fn bindgen_test_layout_s__bindgen_ty_1_inner() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).b as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( @@ -109,8 +111,9 @@ fn bindgen_test_layout_s__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).field as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).field) as usize - ptr as usize }, 0usize, concat!( @@ -139,7 +142,11 @@ fn bindgen_test_layout_s() { concat!("Alignment of ", stringify!(s)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).u as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(s), "::", stringify!(u)) ); diff --git a/tests/expectations/tests/array-of-zero-sized-types.rs b/tests/expectations/tests/array-of-zero-sized-types.rs index 0c00cea9ce..f8d9e985be 100644 --- a/tests/expectations/tests/array-of-zero-sized-types.rs +++ b/tests/expectations/tests/array-of-zero-sized-types.rs @@ -45,8 +45,9 @@ fn bindgen_test_layout_HasArrayOfEmpty() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).empties as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).empties) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/bindgen-union-inside-namespace.rs b/tests/expectations/tests/bindgen-union-inside-namespace.rs index 6083313bfb..558a098239 100644 --- a/tests/expectations/tests/bindgen-union-inside-namespace.rs +++ b/tests/expectations/tests/bindgen-union-inside-namespace.rs @@ -79,7 +79,9 @@ pub mod root { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).foo as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, 0usize, concat!( @@ -91,7 +93,9 @@ pub mod root { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).bar as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/bitfield-linux-32.rs b/tests/expectations/tests/bitfield-linux-32.rs index 15c35cee8d..59a8001d3a 100644 --- a/tests/expectations/tests/bitfield-linux-32.rs +++ b/tests/expectations/tests/bitfield-linux-32.rs @@ -111,7 +111,11 @@ fn bindgen_test_layout_Test() { concat!("Alignment of ", stringify!(Test)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).foo as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(foo)) ); diff --git a/tests/expectations/tests/bitfield_align.rs b/tests/expectations/tests/bitfield_align.rs index 509981a887..708f364faf 100644 --- a/tests/expectations/tests/bitfield_align.rs +++ b/tests/expectations/tests/bitfield_align.rs @@ -113,12 +113,20 @@ fn bindgen_test_layout_A() { concat!("Alignment of ", stringify!(A)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::
())).x as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(x)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).y as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize + }, 3usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(y)) ); @@ -398,12 +406,20 @@ fn bindgen_test_layout_C() { concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).x as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(x)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).baz as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, 4usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(baz)) ); @@ -695,7 +711,11 @@ fn bindgen_test_layout_Date3() { concat!("Alignment of ", stringify!(Date3)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).byte as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).byte) as usize - ptr as usize + }, 3usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/blocklist-and-impl-debug.rs b/tests/expectations/tests/blocklist-and-impl-debug.rs index ba39fb14d5..2cb1fef398 100644 --- a/tests/expectations/tests/blocklist-and-impl-debug.rs +++ b/tests/expectations/tests/blocklist-and-impl-debug.rs @@ -26,8 +26,10 @@ fn bindgen_test_layout_ShouldManuallyImplDebug() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/blocklist-file.rs b/tests/expectations/tests/blocklist-file.rs index fe00b5ab4a..5e41376ca2 100644 --- a/tests/expectations/tests/blocklist-file.rs +++ b/tests/expectations/tests/blocklist-file.rs @@ -26,7 +26,9 @@ fn bindgen_test_layout_SizedIntegers() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).x as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, 0usize, concat!( @@ -38,7 +40,9 @@ fn bindgen_test_layout_SizedIntegers() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).y as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, 2usize, concat!( @@ -50,7 +54,9 @@ fn bindgen_test_layout_SizedIntegers() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).z as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).z) as usize - ptr as usize }, 4usize, concat!( @@ -80,8 +86,11 @@ fn bindgen_test_layout_StructWithBlocklistedFwdDecl() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).b - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/blocks-signature.rs b/tests/expectations/tests/blocks-signature.rs index 22136ddfb7..df28cf85c7 100644 --- a/tests/expectations/tests/blocks-signature.rs +++ b/tests/expectations/tests/blocks-signature.rs @@ -49,8 +49,10 @@ fn bindgen_test_layout_contains_block_pointers() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).val as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).val) as usize - ptr as usize }, 0usize, concat!( @@ -62,8 +64,10 @@ fn bindgen_test_layout_contains_block_pointers() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).ptr_val - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ptr_val) as usize - ptr as usize }, 8usize, concat!( diff --git a/tests/expectations/tests/blocks.rs b/tests/expectations/tests/blocks.rs index b2ae0b2901..f3734bf59a 100644 --- a/tests/expectations/tests/blocks.rs +++ b/tests/expectations/tests/blocks.rs @@ -48,8 +48,10 @@ fn bindgen_test_layout_contains_block_pointers() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).val as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).val) as usize - ptr as usize }, 0usize, concat!( @@ -61,8 +63,10 @@ fn bindgen_test_layout_contains_block_pointers() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).ptr_val - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ptr_val) as usize - ptr as usize }, 8usize, concat!( diff --git a/tests/expectations/tests/c_naming.rs b/tests/expectations/tests/c_naming.rs index abcccf1fd2..636929ce9c 100644 --- a/tests/expectations/tests/c_naming.rs +++ b/tests/expectations/tests/c_naming.rs @@ -23,7 +23,11 @@ fn bindgen_test_layout_struct_a() { concat!("Alignment of ", stringify!(struct_a)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", @@ -53,7 +57,11 @@ fn bindgen_test_layout_union_b() { concat!("Alignment of ", stringify!(union_b)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", @@ -63,7 +71,11 @@ fn bindgen_test_layout_union_b() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).b as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/canonical-types.rs b/tests/expectations/tests/canonical-types.rs index 80d7fec374..10808d2071 100644 --- a/tests/expectations/tests/canonical-types.rs +++ b/tests/expectations/tests/canonical-types.rs @@ -178,7 +178,9 @@ fn bindgen_test_layout_ClassAInner() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).x as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, 0usize, concat!( @@ -217,7 +219,9 @@ fn bindgen_test_layout_ClassCInnerA() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).member as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, 0usize, concat!( @@ -256,7 +260,9 @@ fn bindgen_test_layout_ClassCInnerB() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).cache as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).cache) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/char.rs b/tests/expectations/tests/char.rs index 1e1a19879d..35f353e05c 100644 --- a/tests/expectations/tests/char.rs +++ b/tests/expectations/tests/char.rs @@ -37,52 +37,92 @@ fn bindgen_test_layout_Test() { concat!("Alignment of ", stringify!(Test)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).ch as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ch) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(ch)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).u as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize + }, 1usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(u)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).d as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, 2usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(d)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).cch as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).cch) as usize - ptr as usize + }, 3usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(cch)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).cu as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).cu) as usize - ptr as usize + }, 4usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(cu)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).cd as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).cd) as usize - ptr as usize + }, 5usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(cd)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).Cch as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Cch) as usize - ptr as usize + }, 6usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cch)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).Cu as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Cu) as usize - ptr as usize + }, 7usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cu)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).Cd as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Cd) as usize - ptr as usize + }, 8usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cd)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).Ccch as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Ccch) as usize - ptr as usize + }, 9usize, concat!( "Offset of field: ", @@ -92,12 +132,20 @@ fn bindgen_test_layout_Test() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).Ccu as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Ccu) as usize - ptr as usize + }, 10usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccu)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).Ccd as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Ccd) as usize - ptr as usize + }, 11usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccd)) ); diff --git a/tests/expectations/tests/class.rs b/tests/expectations/tests/class.rs index 3d3afb1926..74d568599c 100644 --- a/tests/expectations/tests/class.rs +++ b/tests/expectations/tests/class.rs @@ -54,12 +54,20 @@ fn bindgen_test_layout_C() { concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(a)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).big_array as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize + }, 4usize, concat!( "Offset of field: ", @@ -98,8 +106,10 @@ fn bindgen_test_layout_C_with_zero_length_array() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( @@ -111,8 +121,10 @@ fn bindgen_test_layout_C_with_zero_length_array() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).big_array - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, 4usize, concat!( @@ -124,8 +136,11 @@ fn bindgen_test_layout_C_with_zero_length_array() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())) - .zero_length_array as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - + ptr as usize }, 37usize, concat!( @@ -165,8 +180,10 @@ fn bindgen_test_layout_C_with_zero_length_array_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( @@ -178,8 +195,11 @@ fn bindgen_test_layout_C_with_zero_length_array_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())) - .zero_length_array as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - + ptr as usize }, 4usize, concat!( @@ -318,7 +338,11 @@ fn bindgen_test_layout_WithDtor() { concat!("Alignment of ", stringify!(WithDtor)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).b as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", @@ -374,12 +398,20 @@ fn bindgen_test_layout_Union() { concat!("Alignment of ", stringify!(Union)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).d as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(Union), "::", stringify!(d)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).i as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(Union), "::", stringify!(i)) ); @@ -412,7 +444,9 @@ fn bindgen_test_layout_WithUnion() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).data as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/class_1_0.rs b/tests/expectations/tests/class_1_0.rs index 3f948bb138..7d1f67776a 100644 --- a/tests/expectations/tests/class_1_0.rs +++ b/tests/expectations/tests/class_1_0.rs @@ -97,12 +97,20 @@ fn bindgen_test_layout_C() { concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(a)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).big_array as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize + }, 4usize, concat!( "Offset of field: ", @@ -151,8 +159,10 @@ fn bindgen_test_layout_C_with_zero_length_array() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( @@ -164,8 +174,10 @@ fn bindgen_test_layout_C_with_zero_length_array() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).big_array - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, 4usize, concat!( @@ -177,8 +189,11 @@ fn bindgen_test_layout_C_with_zero_length_array() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())) - .zero_length_array as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - + ptr as usize }, 37usize, concat!( @@ -218,8 +233,10 @@ fn bindgen_test_layout_C_with_zero_length_array_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( @@ -231,8 +248,11 @@ fn bindgen_test_layout_C_with_zero_length_array_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())) - .zero_length_array as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - + ptr as usize }, 4usize, concat!( @@ -371,7 +391,11 @@ fn bindgen_test_layout_WithDtor() { concat!("Alignment of ", stringify!(WithDtor)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).b as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", @@ -428,12 +452,20 @@ fn bindgen_test_layout_Union() { concat!("Alignment of ", stringify!(Union)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).d as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(Union), "::", stringify!(d)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).i as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(Union), "::", stringify!(i)) ); @@ -462,7 +494,9 @@ fn bindgen_test_layout_WithUnion() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).data as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/class_nested.rs b/tests/expectations/tests/class_nested.rs index ecc5c20a7e..55ea6e1def 100644 --- a/tests/expectations/tests/class_nested.rs +++ b/tests/expectations/tests/class_nested.rs @@ -29,7 +29,9 @@ fn bindgen_test_layout_A_B() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).member_b as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member_b) as usize - ptr as usize }, 0usize, concat!( @@ -68,7 +70,11 @@ fn bindgen_test_layout_A() { concat!("Alignment of ", stringify!(A)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).member_a as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member_a) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", @@ -96,7 +102,11 @@ fn bindgen_test_layout_A_C() { concat!("Alignment of ", stringify!(A_C)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).baz as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(A_C), "::", stringify!(baz)) ); @@ -144,7 +154,11 @@ fn bindgen_test_layout_D() { concat!("Alignment of ", stringify!(D)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).member as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(D), "::", stringify!(member)) ); diff --git a/tests/expectations/tests/class_no_members.rs b/tests/expectations/tests/class_no_members.rs index 6c1e4880a6..5ac7ffdebb 100644 --- a/tests/expectations/tests/class_no_members.rs +++ b/tests/expectations/tests/class_no_members.rs @@ -60,8 +60,10 @@ fn bindgen_test_layout_whatever_child_with_member() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).m_member - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/class_use_as.rs b/tests/expectations/tests/class_use_as.rs index d6a71ac358..f1f08e4d07 100644 --- a/tests/expectations/tests/class_use_as.rs +++ b/tests/expectations/tests/class_use_as.rs @@ -25,8 +25,9 @@ fn bindgen_test_layout_whatever() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).replacement as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).replacement) as usize - ptr as usize }, 0usize, concat!( @@ -55,7 +56,11 @@ fn bindgen_test_layout_container() { concat!("Alignment of ", stringify!(container)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).c as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/class_with_dtor.rs b/tests/expectations/tests/class_with_dtor.rs index 0cf2d8d236..e94e8e5f1b 100644 --- a/tests/expectations/tests/class_with_dtor.rs +++ b/tests/expectations/tests/class_with_dtor.rs @@ -40,8 +40,10 @@ fn bindgen_test_layout_WithoutDtor() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).shouldBeWithDtor as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).shouldBeWithDtor) as usize - + ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/class_with_inner_struct.rs b/tests/expectations/tests/class_with_inner_struct.rs index 35ed765914..49ca304877 100644 --- a/tests/expectations/tests/class_with_inner_struct.rs +++ b/tests/expectations/tests/class_with_inner_struct.rs @@ -32,7 +32,9 @@ fn bindgen_test_layout_A_Segment() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).begin as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize }, 0usize, concat!( @@ -44,7 +46,9 @@ fn bindgen_test_layout_A_Segment() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).end as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize }, 4usize, concat!( @@ -74,7 +78,9 @@ fn bindgen_test_layout_A__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).f as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, 0usize, concat!( @@ -113,7 +119,9 @@ fn bindgen_test_layout_A__bindgen_ty_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).d as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, 0usize, concat!( @@ -146,13 +154,19 @@ fn bindgen_test_layout_A() { concat!("Alignment of ", stringify!(A)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).c as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(c)) ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).named_union as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).named_union) as usize - ptr as usize }, 4usize, concat!( @@ -197,7 +211,9 @@ fn bindgen_test_layout_B_Segment() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).begin as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize }, 0usize, concat!( @@ -209,7 +225,9 @@ fn bindgen_test_layout_B_Segment() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).end as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize }, 4usize, concat!( @@ -233,7 +251,11 @@ fn bindgen_test_layout_B() { concat!("Alignment of ", stringify!(B)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).d as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(B), "::", stringify!(d)) ); @@ -280,8 +302,9 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mX1 - as *const _ as usize + let uninit = :: std :: mem :: MaybeUninit :: < C__bindgen_ty_1__bindgen_ty_1 > :: uninit () ; + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mX1) as usize - ptr as usize }, 0usize, concat!( @@ -293,8 +316,9 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mY1 - as *const _ as usize + let uninit = :: std :: mem :: MaybeUninit :: < C__bindgen_ty_1__bindgen_ty_1 > :: uninit () ; + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mY1) as usize - ptr as usize }, 4usize, concat!( @@ -306,8 +330,9 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mX2 - as *const _ as usize + let uninit = :: std :: mem :: MaybeUninit :: < C__bindgen_ty_1__bindgen_ty_1 > :: uninit () ; + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mX2) as usize - ptr as usize }, 8usize, concat!( @@ -319,8 +344,9 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mY2 - as *const _ as usize + let uninit = :: std :: mem :: MaybeUninit :: < C__bindgen_ty_1__bindgen_ty_1 > :: uninit () ; + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mY2) as usize - ptr as usize }, 12usize, concat!( @@ -351,8 +377,9 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())) - .mStepSyntax as *const _ as usize + let uninit = :: std :: mem :: MaybeUninit :: < C__bindgen_ty_1__bindgen_ty_2 > :: uninit () ; + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mStepSyntax) as usize - ptr as usize }, 0usize, concat!( @@ -364,8 +391,9 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mSteps - as *const _ as usize + let uninit = :: std :: mem :: MaybeUninit :: < C__bindgen_ty_1__bindgen_ty_2 > :: uninit () ; + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mSteps) as usize - ptr as usize }, 4usize, concat!( @@ -399,8 +427,9 @@ fn bindgen_test_layout_C__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mFunc as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mFunc) as usize - ptr as usize }, 0usize, concat!( @@ -440,7 +469,9 @@ fn bindgen_test_layout_C_Segment() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).begin as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize }, 0usize, concat!( @@ -452,7 +483,9 @@ fn bindgen_test_layout_C_Segment() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).end as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize }, 4usize, concat!( @@ -476,7 +509,11 @@ fn bindgen_test_layout_C() { concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).d as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(d)) ); diff --git a/tests/expectations/tests/class_with_inner_struct_1_0.rs b/tests/expectations/tests/class_with_inner_struct_1_0.rs index 52cd590d67..3232a8d00d 100644 --- a/tests/expectations/tests/class_with_inner_struct_1_0.rs +++ b/tests/expectations/tests/class_with_inner_struct_1_0.rs @@ -75,7 +75,9 @@ fn bindgen_test_layout_A_Segment() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).begin as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize }, 0usize, concat!( @@ -87,7 +89,9 @@ fn bindgen_test_layout_A_Segment() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).end as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize }, 4usize, concat!( @@ -123,7 +127,9 @@ fn bindgen_test_layout_A__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).f as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, 0usize, concat!( @@ -159,7 +165,9 @@ fn bindgen_test_layout_A__bindgen_ty_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).d as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, 0usize, concat!( @@ -188,13 +196,19 @@ fn bindgen_test_layout_A() { concat!("Alignment of ", stringify!(A)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).c as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(c)) ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).named_union as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).named_union) as usize - ptr as usize }, 4usize, concat!( @@ -235,7 +249,9 @@ fn bindgen_test_layout_B_Segment() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).begin as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize }, 0usize, concat!( @@ -247,7 +263,9 @@ fn bindgen_test_layout_B_Segment() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).end as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize }, 4usize, concat!( @@ -276,7 +294,11 @@ fn bindgen_test_layout_B() { concat!("Alignment of ", stringify!(B)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).d as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(B), "::", stringify!(d)) ); @@ -329,8 +351,9 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mX1 - as *const _ as usize + let uninit = :: std :: mem :: MaybeUninit :: < C__bindgen_ty_1__bindgen_ty_1 > :: uninit () ; + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mX1) as usize - ptr as usize }, 0usize, concat!( @@ -342,8 +365,9 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mY1 - as *const _ as usize + let uninit = :: std :: mem :: MaybeUninit :: < C__bindgen_ty_1__bindgen_ty_1 > :: uninit () ; + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mY1) as usize - ptr as usize }, 4usize, concat!( @@ -355,8 +379,9 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mX2 - as *const _ as usize + let uninit = :: std :: mem :: MaybeUninit :: < C__bindgen_ty_1__bindgen_ty_1 > :: uninit () ; + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mX2) as usize - ptr as usize }, 8usize, concat!( @@ -368,8 +393,9 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mY2 - as *const _ as usize + let uninit = :: std :: mem :: MaybeUninit :: < C__bindgen_ty_1__bindgen_ty_1 > :: uninit () ; + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mY2) as usize - ptr as usize }, 12usize, concat!( @@ -405,8 +431,9 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())) - .mStepSyntax as *const _ as usize + let uninit = :: std :: mem :: MaybeUninit :: < C__bindgen_ty_1__bindgen_ty_2 > :: uninit () ; + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mStepSyntax) as usize - ptr as usize }, 0usize, concat!( @@ -418,8 +445,9 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mSteps - as *const _ as usize + let uninit = :: std :: mem :: MaybeUninit :: < C__bindgen_ty_1__bindgen_ty_2 > :: uninit () ; + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mSteps) as usize - ptr as usize }, 4usize, concat!( @@ -458,8 +486,9 @@ fn bindgen_test_layout_C__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mFunc as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mFunc) as usize - ptr as usize }, 0usize, concat!( @@ -495,7 +524,9 @@ fn bindgen_test_layout_C_Segment() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).begin as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize }, 0usize, concat!( @@ -507,7 +538,9 @@ fn bindgen_test_layout_C_Segment() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).end as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize }, 4usize, concat!( @@ -536,7 +569,11 @@ fn bindgen_test_layout_C() { concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).d as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(d)) ); diff --git a/tests/expectations/tests/class_with_typedef.rs b/tests/expectations/tests/class_with_typedef.rs index 31faa49ddb..7af009e743 100644 --- a/tests/expectations/tests/class_with_typedef.rs +++ b/tests/expectations/tests/class_with_typedef.rs @@ -30,27 +30,47 @@ fn bindgen_test_layout_C() { concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).c as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(c)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).ptr as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize + }, 8usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(ptr)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).arr as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize + }, 16usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(arr)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).d as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, 56usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(d)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).other_ptr as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).other_ptr) as usize - ptr as usize + }, 64usize, concat!( "Offset of field: ", @@ -122,7 +142,11 @@ fn bindgen_test_layout_D() { concat!("Alignment of ", stringify!(D)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).ptr as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize + }, 72usize, concat!("Offset of field: ", stringify!(D), "::", stringify!(ptr)) ); diff --git a/tests/expectations/tests/comment-indent.rs b/tests/expectations/tests/comment-indent.rs index c381b7342b..e4bdea3d6f 100644 --- a/tests/expectations/tests/comment-indent.rs +++ b/tests/expectations/tests/comment-indent.rs @@ -82,7 +82,9 @@ pub mod root { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).member as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/complex.rs b/tests/expectations/tests/complex.rs index 4dae071727..77ab28080a 100644 --- a/tests/expectations/tests/complex.rs +++ b/tests/expectations/tests/complex.rs @@ -30,7 +30,9 @@ fn bindgen_test_layout_TestDouble() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mMember as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize }, 0usize, concat!( @@ -60,8 +62,9 @@ fn bindgen_test_layout_TestDoublePtr() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mMember as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize }, 0usize, concat!( @@ -100,7 +103,9 @@ fn bindgen_test_layout_TestFloat() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mMember as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize }, 0usize, concat!( @@ -130,8 +135,9 @@ fn bindgen_test_layout_TestFloatPtr() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mMember as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/const-const-mut-ptr.rs b/tests/expectations/tests/const-const-mut-ptr.rs index bc1e76277a..9f656102a6 100644 --- a/tests/expectations/tests/const-const-mut-ptr.rs +++ b/tests/expectations/tests/const-const-mut-ptr.rs @@ -23,7 +23,11 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/constified-enum-module-overflow.rs b/tests/expectations/tests/constified-enum-module-overflow.rs index 4a799ef8e5..6c625321b1 100644 --- a/tests/expectations/tests/constified-enum-module-overflow.rs +++ b/tests/expectations/tests/constified-enum-module-overflow.rs @@ -34,7 +34,11 @@ fn bindgen_test_layout_A() { concat!("Alignment of ", stringify!(A)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).u as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(u)) ); diff --git a/tests/expectations/tests/constify-all-enums.rs b/tests/expectations/tests/constify-all-enums.rs index 78bb99faf5..3627faaea7 100644 --- a/tests/expectations/tests/constify-all-enums.rs +++ b/tests/expectations/tests/constify-all-enums.rs @@ -28,8 +28,10 @@ fn bindgen_test_layout_bar() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).this_should_work as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).this_should_work) as usize - + ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/constify-module-enums-basic.rs b/tests/expectations/tests/constify-module-enums-basic.rs index 59e9ba12ba..0ea84b9dda 100644 --- a/tests/expectations/tests/constify-module-enums-basic.rs +++ b/tests/expectations/tests/constify-module-enums-basic.rs @@ -32,8 +32,10 @@ fn bindgen_test_layout_bar() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).this_should_work as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).this_should_work) as usize - + ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/constify-module-enums-namespace.rs b/tests/expectations/tests/constify-module-enums-namespace.rs index e434291a15..637e6e4feb 100644 --- a/tests/expectations/tests/constify-module-enums-namespace.rs +++ b/tests/expectations/tests/constify-module-enums-namespace.rs @@ -44,8 +44,10 @@ pub mod root { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).this_should_work - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).this_should_work) as usize - + ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/constify-module-enums-shadow-name.rs b/tests/expectations/tests/constify-module-enums-shadow-name.rs index 60401dc093..21ad17a3f0 100644 --- a/tests/expectations/tests/constify-module-enums-shadow-name.rs +++ b/tests/expectations/tests/constify-module-enums-shadow-name.rs @@ -30,7 +30,11 @@ fn bindgen_test_layout_bar() { concat!("Alignment of ", stringify!(bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).member as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/constify-module-enums-simple-alias.rs b/tests/expectations/tests/constify-module-enums-simple-alias.rs index 317697dd3b..4d7ae60482 100644 --- a/tests/expectations/tests/constify-module-enums-simple-alias.rs +++ b/tests/expectations/tests/constify-module-enums-simple-alias.rs @@ -39,28 +39,46 @@ fn bindgen_test_layout_Bar() { concat!("Alignment of ", stringify!(Bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).baz1 as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz1) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz1)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).baz2 as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz2) as usize - ptr as usize + }, 4usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz2)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).baz3 as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz3) as usize - ptr as usize + }, 8usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz3)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).baz4 as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz4) as usize - ptr as usize + }, 12usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz4)) ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).baz_ptr1 as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz_ptr1) as usize - ptr as usize }, 16usize, concat!( @@ -72,7 +90,9 @@ fn bindgen_test_layout_Bar() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).baz_ptr2 as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz_ptr2) as usize - ptr as usize }, 24usize, concat!( @@ -84,7 +104,9 @@ fn bindgen_test_layout_Bar() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).baz_ptr3 as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz_ptr3) as usize - ptr as usize }, 32usize, concat!( @@ -96,7 +118,9 @@ fn bindgen_test_layout_Bar() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).baz_ptr4 as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz_ptr4) as usize - ptr as usize }, 40usize, concat!( diff --git a/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs b/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs index b6644797d7..f15ae7efb4 100644 --- a/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs +++ b/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs @@ -29,12 +29,20 @@ fn bindgen_test_layout_Bar() { concat!("Alignment of ", stringify!(Bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).baz1 as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz1) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz1)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).baz2 as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz2) as usize - ptr as usize + }, 8usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz2)) ); diff --git a/tests/expectations/tests/constify-module-enums-types.rs b/tests/expectations/tests/constify-module-enums-types.rs index ec7e6c0eee..9c7490b650 100644 --- a/tests/expectations/tests/constify-module-enums-types.rs +++ b/tests/expectations/tests/constify-module-enums-types.rs @@ -64,7 +64,11 @@ fn bindgen_test_layout_bar() { concat!("Alignment of ", stringify!(bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).member1 as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member1) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", @@ -74,7 +78,11 @@ fn bindgen_test_layout_bar() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).member2 as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member2) as usize - ptr as usize + }, 4usize, concat!( "Offset of field: ", @@ -84,7 +92,11 @@ fn bindgen_test_layout_bar() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).member3 as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member3) as usize - ptr as usize + }, 8usize, concat!( "Offset of field: ", @@ -94,7 +106,11 @@ fn bindgen_test_layout_bar() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).member4 as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member4) as usize - ptr as usize + }, 12usize, concat!( "Offset of field: ", @@ -104,7 +120,11 @@ fn bindgen_test_layout_bar() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).member5 as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member5) as usize - ptr as usize + }, 16usize, concat!( "Offset of field: ", @@ -114,7 +134,11 @@ fn bindgen_test_layout_bar() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).member6 as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member6) as usize - ptr as usize + }, 24usize, concat!( "Offset of field: ", @@ -124,7 +148,11 @@ fn bindgen_test_layout_bar() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).member7 as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member7) as usize - ptr as usize + }, 32usize, concat!( "Offset of field: ", @@ -134,7 +162,11 @@ fn bindgen_test_layout_bar() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).member8 as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member8) as usize - ptr as usize + }, 36usize, concat!( "Offset of field: ", @@ -144,7 +176,11 @@ fn bindgen_test_layout_bar() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).member9 as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member9) as usize - ptr as usize + }, 40usize, concat!( "Offset of field: ", @@ -155,7 +191,9 @@ fn bindgen_test_layout_bar() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).member10 as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member10) as usize - ptr as usize }, 44usize, concat!( @@ -193,7 +231,11 @@ fn bindgen_test_layout_Baz() { concat!("Alignment of ", stringify!(Baz)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).member1 as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member1) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", @@ -235,7 +277,11 @@ fn bindgen_test_layout_Bar() { concat!("Alignment of ", stringify!(Bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).baz as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz)) ); diff --git a/tests/expectations/tests/contains-vs-inherits-zero-sized.rs b/tests/expectations/tests/contains-vs-inherits-zero-sized.rs index 2882fa845d..45db909916 100644 --- a/tests/expectations/tests/contains-vs-inherits-zero-sized.rs +++ b/tests/expectations/tests/contains-vs-inherits-zero-sized.rs @@ -44,7 +44,11 @@ fn bindgen_test_layout_Inherits() { concat!("Alignment of ", stringify!(Inherits)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).b as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", @@ -76,7 +80,9 @@ fn bindgen_test_layout_Contains() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).empty as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).empty) as usize - ptr as usize }, 0usize, concat!( @@ -87,7 +93,11 @@ fn bindgen_test_layout_Contains() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).b as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, 1usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/convert-floats.rs b/tests/expectations/tests/convert-floats.rs index 6623159211..d6e4628511 100644 --- a/tests/expectations/tests/convert-floats.rs +++ b/tests/expectations/tests/convert-floats.rs @@ -34,22 +34,38 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).baz as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, 4usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(baz)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bazz as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bazz) as usize - ptr as usize + }, 8usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bazz)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bazzz as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bazzz) as usize - ptr as usize + }, 16usize, concat!( "Offset of field: ", @@ -60,7 +76,9 @@ fn bindgen_test_layout_foo() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).complexFloat as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).complexFloat) as usize - ptr as usize }, 24usize, concat!( @@ -72,7 +90,9 @@ fn bindgen_test_layout_foo() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).complexDouble as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).complexDouble) as usize - ptr as usize }, 32usize, concat!( diff --git a/tests/expectations/tests/ctypes-prefix-path.rs b/tests/expectations/tests/ctypes-prefix-path.rs index 12cedac955..b0c7a0f708 100644 --- a/tests/expectations/tests/ctypes-prefix-path.rs +++ b/tests/expectations/tests/ctypes-prefix-path.rs @@ -32,17 +32,29 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::core::ptr::null::())).a as *const _ as usize }, + unsafe { + let uninit = ::core::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::core::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) ); assert_eq!( - unsafe { &(*(::core::ptr::null::())).b as *const _ as usize }, + unsafe { + let uninit = ::core::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::core::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, 4usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) ); assert_eq!( - unsafe { &(*(::core::ptr::null::())).bar as *const _ as usize }, + unsafe { + let uninit = ::core::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, 8usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/derive-bitfield-method-same-name.rs b/tests/expectations/tests/derive-bitfield-method-same-name.rs index 1dc1d6e350..3cde87dfe7 100644 --- a/tests/expectations/tests/derive-bitfield-method-same-name.rs +++ b/tests/expectations/tests/derive-bitfield-method-same-name.rs @@ -115,7 +115,11 @@ fn bindgen_test_layout_Foo() { concat!("Alignment of ", stringify!(Foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).large as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).large) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/derive-clone.rs b/tests/expectations/tests/derive-clone.rs index e589a29ea3..25d30b215e 100644 --- a/tests/expectations/tests/derive-clone.rs +++ b/tests/expectations/tests/derive-clone.rs @@ -25,8 +25,9 @@ fn bindgen_test_layout_ShouldDeriveClone() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).large as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).large) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/derive-clone_1_0.rs b/tests/expectations/tests/derive-clone_1_0.rs index a437d5c314..f18041cef2 100644 --- a/tests/expectations/tests/derive-clone_1_0.rs +++ b/tests/expectations/tests/derive-clone_1_0.rs @@ -26,8 +26,9 @@ fn bindgen_test_layout_ShouldImplClone() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).large as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).large) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/derive-debug-bitfield-core.rs b/tests/expectations/tests/derive-debug-bitfield-core.rs index 33f0f2ffbc..1eb5297c8d 100644 --- a/tests/expectations/tests/derive-debug-bitfield-core.rs +++ b/tests/expectations/tests/derive-debug-bitfield-core.rs @@ -114,7 +114,9 @@ fn bindgen_test_layout_C() { ); assert_eq!( unsafe { - &(*(::core::ptr::null::())).large_array as *const _ as usize + let uninit = ::core::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::core::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize }, 4usize, concat!( diff --git a/tests/expectations/tests/derive-debug-bitfield.rs b/tests/expectations/tests/derive-debug-bitfield.rs index 00976b59df..57e246dc33 100644 --- a/tests/expectations/tests/derive-debug-bitfield.rs +++ b/tests/expectations/tests/derive-debug-bitfield.rs @@ -112,7 +112,9 @@ fn bindgen_test_layout_C() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).large_array as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize }, 4usize, concat!( diff --git a/tests/expectations/tests/derive-debug-function-pointer.rs b/tests/expectations/tests/derive-debug-function-pointer.rs index c031897b6a..da522aa4b9 100644 --- a/tests/expectations/tests/derive-debug-function-pointer.rs +++ b/tests/expectations/tests/derive-debug-function-pointer.rs @@ -27,7 +27,9 @@ fn bindgen_test_layout_Nice() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).pointer as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pointer) as usize - ptr as usize }, 0usize, concat!( @@ -39,7 +41,9 @@ fn bindgen_test_layout_Nice() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).large_array as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize }, 8usize, concat!( diff --git a/tests/expectations/tests/derive-debug-mangle-name.rs b/tests/expectations/tests/derive-debug-mangle-name.rs index ed5416486c..5fb9d3813e 100644 --- a/tests/expectations/tests/derive-debug-mangle-name.rs +++ b/tests/expectations/tests/derive-debug-mangle-name.rs @@ -32,8 +32,9 @@ fn bindgen_test_layout_perf_event_attr__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).b - as *const _ as usize + let uninit = :: std :: mem :: MaybeUninit :: < perf_event_attr__bindgen_ty_1 > :: uninit () ; + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( @@ -45,8 +46,9 @@ fn bindgen_test_layout_perf_event_attr__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).c - as *const _ as usize + let uninit = :: std :: mem :: MaybeUninit :: < perf_event_attr__bindgen_ty_1 > :: uninit () ; + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, 0usize, concat!( @@ -85,8 +87,9 @@ fn bindgen_test_layout_perf_event_attr() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).type_ as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize }, 0usize, concat!( @@ -98,7 +101,9 @@ fn bindgen_test_layout_perf_event_attr() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 4usize, concat!( diff --git a/tests/expectations/tests/derive-debug-opaque-template-instantiation.rs b/tests/expectations/tests/derive-debug-opaque-template-instantiation.rs index ceb70ffe4e..51071c3241 100644 --- a/tests/expectations/tests/derive-debug-opaque-template-instantiation.rs +++ b/tests/expectations/tests/derive-debug-opaque-template-instantiation.rs @@ -23,7 +23,9 @@ fn bindgen_test_layout_Instance() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).val as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).val) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/derive-debug-opaque.rs b/tests/expectations/tests/derive-debug-opaque.rs index 411c7a7036..6f8a0d9114 100644 --- a/tests/expectations/tests/derive-debug-opaque.rs +++ b/tests/expectations/tests/derive-debug-opaque.rs @@ -55,7 +55,9 @@ fn bindgen_test_layout_OpaqueUser() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).opaque as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).opaque) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/derive-default-and-blocklist.rs b/tests/expectations/tests/derive-default-and-blocklist.rs index 5d53ede28c..7e80e33683 100644 --- a/tests/expectations/tests/derive-default-and-blocklist.rs +++ b/tests/expectations/tests/derive-default-and-blocklist.rs @@ -27,8 +27,10 @@ fn bindgen_test_layout_ShouldNotDeriveDefault() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/derive-fn-ptr.rs b/tests/expectations/tests/derive-fn-ptr.rs index 7c9f426115..d28c53287d 100644 --- a/tests/expectations/tests/derive-fn-ptr.rs +++ b/tests/expectations/tests/derive-fn-ptr.rs @@ -44,7 +44,9 @@ fn bindgen_test_layout_Foo() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).callback as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).callback) as usize - ptr as usize }, 0usize, concat!( @@ -90,7 +92,9 @@ fn bindgen_test_layout_Bar() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).callback as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).callback) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/derive-hash-and-blocklist.rs b/tests/expectations/tests/derive-hash-and-blocklist.rs index 8e1190ea72..15d1a6d71d 100644 --- a/tests/expectations/tests/derive-hash-and-blocklist.rs +++ b/tests/expectations/tests/derive-hash-and-blocklist.rs @@ -26,8 +26,10 @@ fn bindgen_test_layout_ShouldNotDeriveHash() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/derive-hash-blocklisting.rs b/tests/expectations/tests/derive-hash-blocklisting.rs index 7cd29c21d2..28ce3ab8e0 100644 --- a/tests/expectations/tests/derive-hash-blocklisting.rs +++ b/tests/expectations/tests/derive-hash-blocklisting.rs @@ -32,7 +32,9 @@ fn bindgen_test_layout_AllowlistedOne() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( @@ -71,7 +73,9 @@ fn bindgen_test_layout_AllowlistedTwo() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs b/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs index 92846f3c96..74644f98ac 100644 --- a/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs +++ b/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs @@ -31,7 +31,9 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( @@ -43,7 +45,9 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 4usize, concat!( @@ -67,7 +71,11 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/derive-hash-struct-with-float-array.rs b/tests/expectations/tests/derive-hash-struct-with-float-array.rs index e2e1bcef22..b22cb25ef1 100644 --- a/tests/expectations/tests/derive-hash-struct-with-float-array.rs +++ b/tests/expectations/tests/derive-hash-struct-with-float-array.rs @@ -24,7 +24,11 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs b/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs index 851080749d..d1f7ae3f77 100644 --- a/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs +++ b/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs @@ -54,14 +54,20 @@ fn bindgen_test_layout_test() { concat!("Alignment of ", stringify!(test)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(test), "::", stringify!(a)) ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).zero_length_array as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - + ptr as usize }, 4usize, concat!( diff --git a/tests/expectations/tests/derive-hash-struct-with-pointer.rs b/tests/expectations/tests/derive-hash-struct-with-pointer.rs index e98bbf0f32..8931689b95 100644 --- a/tests/expectations/tests/derive-hash-struct-with-pointer.rs +++ b/tests/expectations/tests/derive-hash-struct-with-pointer.rs @@ -25,7 +25,9 @@ fn bindgen_test_layout_ConstPtrMutObj() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).bar as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, concat!( @@ -64,7 +66,9 @@ fn bindgen_test_layout_MutPtrMutObj() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).bar as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, concat!( @@ -103,7 +107,9 @@ fn bindgen_test_layout_MutPtrConstObj() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).bar as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, concat!( @@ -142,8 +148,9 @@ fn bindgen_test_layout_ConstPtrConstObj() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).bar as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/derive-hash-template-inst-float.rs b/tests/expectations/tests/derive-hash-template-inst-float.rs index f861815234..27f7f72c8c 100644 --- a/tests/expectations/tests/derive-hash-template-inst-float.rs +++ b/tests/expectations/tests/derive-hash-template-inst-float.rs @@ -40,7 +40,11 @@ fn bindgen_test_layout_IntStr() { concat!("Alignment of ", stringify!(IntStr)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(IntStr), "::", stringify!(a)) ); @@ -73,7 +77,11 @@ fn bindgen_test_layout_FloatStr() { concat!("Alignment of ", stringify!(FloatStr)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/derive-partialeq-and-blocklist.rs b/tests/expectations/tests/derive-partialeq-and-blocklist.rs index d9dfb44618..e3d812779c 100644 --- a/tests/expectations/tests/derive-partialeq-and-blocklist.rs +++ b/tests/expectations/tests/derive-partialeq-and-blocklist.rs @@ -27,8 +27,10 @@ fn bindgen_test_layout_ShouldNotDerivePartialEq() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/derive-partialeq-base.rs b/tests/expectations/tests/derive-partialeq-base.rs index cdf8dff8b4..ce24144734 100644 --- a/tests/expectations/tests/derive-partialeq-base.rs +++ b/tests/expectations/tests/derive-partialeq-base.rs @@ -23,7 +23,11 @@ fn bindgen_test_layout_Base() { concat!("Alignment of ", stringify!(Base)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).large as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).large) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/derive-partialeq-bitfield.rs b/tests/expectations/tests/derive-partialeq-bitfield.rs index cffffca57c..94b47eba74 100644 --- a/tests/expectations/tests/derive-partialeq-bitfield.rs +++ b/tests/expectations/tests/derive-partialeq-bitfield.rs @@ -112,7 +112,9 @@ fn bindgen_test_layout_C() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).large_array as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize }, 4usize, concat!( diff --git a/tests/expectations/tests/derive-partialeq-core.rs b/tests/expectations/tests/derive-partialeq-core.rs index 8cdfb92c6a..171c0a4513 100644 --- a/tests/expectations/tests/derive-partialeq-core.rs +++ b/tests/expectations/tests/derive-partialeq-core.rs @@ -26,7 +26,9 @@ fn bindgen_test_layout_C() { ); assert_eq!( unsafe { - &(*(::core::ptr::null::())).large_array as *const _ as usize + let uninit = ::core::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::core::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/derive-partialeq-pointer.rs b/tests/expectations/tests/derive-partialeq-pointer.rs index 17a5edcbbf..a2d6246c20 100644 --- a/tests/expectations/tests/derive-partialeq-pointer.rs +++ b/tests/expectations/tests/derive-partialeq-pointer.rs @@ -23,7 +23,11 @@ fn bindgen_test_layout_Bar() { concat!("Alignment of ", stringify!(Bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).b as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(b)) ); @@ -109,7 +113,11 @@ fn bindgen_test_layout_a() { concat!("Alignment of ", stringify!(a)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).d as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(a), "::", stringify!(d)) ); diff --git a/tests/expectations/tests/derive-partialeq-union.rs b/tests/expectations/tests/derive-partialeq-union.rs index b97c053198..c8ff8afa53 100644 --- a/tests/expectations/tests/derive-partialeq-union.rs +++ b/tests/expectations/tests/derive-partialeq-union.rs @@ -26,8 +26,10 @@ fn bindgen_test_layout_ShouldNotDerivePartialEq() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( @@ -39,8 +41,10 @@ fn bindgen_test_layout_ShouldNotDerivePartialEq() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).b as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/derive-partialeq-union_1_0.rs b/tests/expectations/tests/derive-partialeq-union_1_0.rs index 2098849f99..b45cc22168 100644 --- a/tests/expectations/tests/derive-partialeq-union_1_0.rs +++ b/tests/expectations/tests/derive-partialeq-union_1_0.rs @@ -70,8 +70,10 @@ fn bindgen_test_layout_ShouldDerivePartialEq() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( @@ -83,8 +85,10 @@ fn bindgen_test_layout_ShouldDerivePartialEq() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).b as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/disable-nested-struct-naming.rs b/tests/expectations/tests/disable-nested-struct-naming.rs index a9ad26a50a..6085eb7a75 100644 --- a/tests/expectations/tests/disable-nested-struct-naming.rs +++ b/tests/expectations/tests/disable-nested-struct-naming.rs @@ -46,7 +46,11 @@ fn bindgen_test_layout_bar4() { concat!("Alignment of ", stringify!(bar4)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).x4 as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).x4) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(bar4), "::", stringify!(x4)) ); @@ -68,8 +72,11 @@ fn bindgen_test_layout_bar1__bindgen_ty_1__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).x3 - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + bar1__bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).x3) as usize - ptr as usize }, 0usize, concat!( @@ -81,8 +88,11 @@ fn bindgen_test_layout_bar1__bindgen_ty_1__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).b4 - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + bar1__bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b4) as usize - ptr as usize }, 4usize, concat!( @@ -107,8 +117,10 @@ fn bindgen_test_layout_bar1__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).x2 as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).x2) as usize - ptr as usize }, 0usize, concat!( @@ -120,8 +132,10 @@ fn bindgen_test_layout_bar1__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).b3 as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b3) as usize - ptr as usize }, 4usize, concat!( @@ -145,12 +159,20 @@ fn bindgen_test_layout_bar1() { concat!("Alignment of ", stringify!(bar1)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).x1 as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).x1) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(bar1), "::", stringify!(x1)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).b2 as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b2) as usize - ptr as usize + }, 4usize, concat!("Offset of field: ", stringify!(bar1), "::", stringify!(b2)) ); @@ -168,7 +190,11 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).b1 as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b1) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(b1)) ); @@ -201,7 +227,11 @@ fn bindgen_test_layout_baz() { concat!("Alignment of ", stringify!(baz)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).x as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(baz), "::", stringify!(x)) ); @@ -220,8 +250,11 @@ fn bindgen_test_layout__bindgen_ty_1__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::<_bindgen_ty_1__bindgen_ty_1>())).b - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::<_bindgen_ty_1__bindgen_ty_1>::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( @@ -246,7 +279,9 @@ fn bindgen_test_layout__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::<_bindgen_ty_1>())).anon2 as *const _ as usize + let uninit = ::std::mem::MaybeUninit::<_bindgen_ty_1>::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).anon2) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/disable-untagged-union.rs b/tests/expectations/tests/disable-untagged-union.rs index 5300273384..8031a0c18a 100644 --- a/tests/expectations/tests/disable-untagged-union.rs +++ b/tests/expectations/tests/disable-untagged-union.rs @@ -68,12 +68,20 @@ fn bindgen_test_layout_Foo() { concat!("Alignment of ", stringify!(Foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).baz as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(baz)) ); diff --git a/tests/expectations/tests/do-not-derive-copy.rs b/tests/expectations/tests/do-not-derive-copy.rs index 4112d88a5c..ac1943230b 100644 --- a/tests/expectations/tests/do-not-derive-copy.rs +++ b/tests/expectations/tests/do-not-derive-copy.rs @@ -27,8 +27,11 @@ fn bindgen_test_layout_WouldBeCopyButWeAreNotDerivingCopy() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).x - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + WouldBeCopyButWeAreNotDerivingCopy, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/doggo-or-null.rs b/tests/expectations/tests/doggo-or-null.rs index fa7a5e89dc..88093fd1e0 100644 --- a/tests/expectations/tests/doggo-or-null.rs +++ b/tests/expectations/tests/doggo-or-null.rs @@ -23,7 +23,11 @@ fn bindgen_test_layout_Doggo() { concat!("Alignment of ", stringify!(Doggo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).x as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(Doggo), "::", stringify!(x)) ); diff --git a/tests/expectations/tests/duplicated-namespaces-definitions.rs b/tests/expectations/tests/duplicated-namespaces-definitions.rs index 324fe2a0a7..9be3d27c45 100644 --- a/tests/expectations/tests/duplicated-namespaces-definitions.rs +++ b/tests/expectations/tests/duplicated-namespaces-definitions.rs @@ -32,7 +32,9 @@ pub mod root { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).foo as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, 0usize, concat!( @@ -44,7 +46,9 @@ pub mod root { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).baz as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, 4usize, concat!( @@ -78,7 +82,9 @@ pub mod root { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).ptr as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/dynamic_loading_with_blocklist.rs b/tests/expectations/tests/dynamic_loading_with_blocklist.rs index b06a6cf809..aedc0ad427 100644 --- a/tests/expectations/tests/dynamic_loading_with_blocklist.rs +++ b/tests/expectations/tests/dynamic_loading_with_blocklist.rs @@ -23,7 +23,11 @@ fn bindgen_test_layout_X() { concat!("Alignment of ", stringify!(X)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::()))._x as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr)._x) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(X), "::", stringify!(_x)) ); diff --git a/tests/expectations/tests/dynamic_loading_with_class.rs b/tests/expectations/tests/dynamic_loading_with_class.rs index 8a66dc3f9a..d995d9bf8e 100644 --- a/tests/expectations/tests/dynamic_loading_with_class.rs +++ b/tests/expectations/tests/dynamic_loading_with_class.rs @@ -23,7 +23,11 @@ fn bindgen_test_layout_A() { concat!("Alignment of ", stringify!(A)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::()))._x as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr)._x) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(_x)) ); diff --git a/tests/expectations/tests/enum-default-bitfield.rs b/tests/expectations/tests/enum-default-bitfield.rs index 1dc27fdc40..406b29e050 100644 --- a/tests/expectations/tests/enum-default-bitfield.rs +++ b/tests/expectations/tests/enum-default-bitfield.rs @@ -54,7 +54,11 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).member as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", @@ -184,4 +188,4 @@ impl ::std::ops::BitAndAssign for Debug { #[repr(transparent)] ///
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] -pub struct Debug(pub ::std::os::raw::c_uint); \ No newline at end of file +pub struct Debug(pub ::std::os::raw::c_uint); diff --git a/tests/expectations/tests/enum-default-consts.rs b/tests/expectations/tests/enum-default-consts.rs index d7f5d7c28a..dc0889f1c7 100644 --- a/tests/expectations/tests/enum-default-consts.rs +++ b/tests/expectations/tests/enum-default-consts.rs @@ -26,7 +26,11 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).member as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/enum-default-module.rs b/tests/expectations/tests/enum-default-module.rs index 156bbcaad0..8f2b603c55 100644 --- a/tests/expectations/tests/enum-default-module.rs +++ b/tests/expectations/tests/enum-default-module.rs @@ -28,7 +28,11 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).member as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", @@ -68,4 +72,4 @@ pub mod Debug { pub type Type = ::std::os::raw::c_uint; pub const Debug1: Type = 0; pub const Debug2: Type = 1; -} \ No newline at end of file +} diff --git a/tests/expectations/tests/enum-default-rust.rs b/tests/expectations/tests/enum-default-rust.rs index 045330a823..e8d4a0bec9 100644 --- a/tests/expectations/tests/enum-default-rust.rs +++ b/tests/expectations/tests/enum-default-rust.rs @@ -31,7 +31,11 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).member as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", @@ -74,4 +78,4 @@ pub enum NoDebug { pub enum Debug { Debug1 = 0, Debug2 = 1, -} \ No newline at end of file +} diff --git a/tests/expectations/tests/enum-no-debug-rust.rs b/tests/expectations/tests/enum-no-debug-rust.rs index dbcbd052cc..7808527c74 100644 --- a/tests/expectations/tests/enum-no-debug-rust.rs +++ b/tests/expectations/tests/enum-no-debug-rust.rs @@ -31,7 +31,11 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).member as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/enum.rs b/tests/expectations/tests/enum.rs index fd76151f9f..5464038510 100644 --- a/tests/expectations/tests/enum.rs +++ b/tests/expectations/tests/enum.rs @@ -26,7 +26,11 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).member as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/enum_and_vtable_mangling.rs b/tests/expectations/tests/enum_and_vtable_mangling.rs index 5ae76c4c29..372921fdad 100644 --- a/tests/expectations/tests/enum_and_vtable_mangling.rs +++ b/tests/expectations/tests/enum_and_vtable_mangling.rs @@ -36,7 +36,11 @@ fn bindgen_test_layout_C() { concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).i as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize + }, 8usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(i)) ); diff --git a/tests/expectations/tests/explicit-padding.rs b/tests/expectations/tests/explicit-padding.rs index 3c429756c2..2614f83b11 100644 --- a/tests/expectations/tests/explicit-padding.rs +++ b/tests/expectations/tests/explicit-padding.rs @@ -28,7 +28,9 @@ fn bindgen_test_layout_pad_me() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).first as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).first) as usize - ptr as usize }, 0usize, concat!( @@ -40,7 +42,9 @@ fn bindgen_test_layout_pad_me() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).second as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).second) as usize - ptr as usize }, 4usize, concat!( @@ -52,7 +56,9 @@ fn bindgen_test_layout_pad_me() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).third as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).third) as usize - ptr as usize }, 8usize, concat!( @@ -84,7 +90,9 @@ fn bindgen_test_layout_dont_pad_me() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).first as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).first) as usize - ptr as usize }, 0usize, concat!( @@ -96,7 +104,9 @@ fn bindgen_test_layout_dont_pad_me() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).second as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).second) as usize - ptr as usize }, 0usize, concat!( @@ -108,7 +118,9 @@ fn bindgen_test_layout_dont_pad_me() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).third as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).third) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/extern-const-struct.rs b/tests/expectations/tests/extern-const-struct.rs index fa0018ba90..a1bd34f98e 100644 --- a/tests/expectations/tests/extern-const-struct.rs +++ b/tests/expectations/tests/extern-const-struct.rs @@ -24,7 +24,9 @@ fn bindgen_test_layout_nsFoo() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).details as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).details) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/forward-declaration-autoptr.rs b/tests/expectations/tests/forward-declaration-autoptr.rs index bf0b6926f1..022089d04e 100644 --- a/tests/expectations/tests/forward-declaration-autoptr.rs +++ b/tests/expectations/tests/forward-declaration-autoptr.rs @@ -44,7 +44,9 @@ fn bindgen_test_layout_Bar() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).m_member as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/forward_declared_complex_types.rs b/tests/expectations/tests/forward_declared_complex_types.rs index e185e83064..14531d3fff 100644 --- a/tests/expectations/tests/forward_declared_complex_types.rs +++ b/tests/expectations/tests/forward_declared_complex_types.rs @@ -46,7 +46,11 @@ fn bindgen_test_layout_Bar() { concat!("Alignment of ", stringify!(Bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).f as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(f)) ); diff --git a/tests/expectations/tests/forward_declared_complex_types_1_0.rs b/tests/expectations/tests/forward_declared_complex_types_1_0.rs index c6331c6941..bf9d27ca36 100644 --- a/tests/expectations/tests/forward_declared_complex_types_1_0.rs +++ b/tests/expectations/tests/forward_declared_complex_types_1_0.rs @@ -56,7 +56,11 @@ fn bindgen_test_layout_Bar() { concat!("Alignment of ", stringify!(Bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).f as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(f)) ); diff --git a/tests/expectations/tests/forward_declared_struct.rs b/tests/expectations/tests/forward_declared_struct.rs index 2ecfc60ed6..be038ee266 100644 --- a/tests/expectations/tests/forward_declared_struct.rs +++ b/tests/expectations/tests/forward_declared_struct.rs @@ -23,7 +23,11 @@ fn bindgen_test_layout_a() { concat!("Alignment of ", stringify!(a)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::
())).b as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(a), "::", stringify!(b)) ); @@ -46,7 +50,11 @@ fn bindgen_test_layout_c() { concat!("Alignment of ", stringify!(c)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).d as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(c), "::", stringify!(d)) ); diff --git a/tests/expectations/tests/func_ptr_in_struct.rs b/tests/expectations/tests/func_ptr_in_struct.rs index 8f98763fbc..3f2a4faa36 100644 --- a/tests/expectations/tests/func_ptr_in_struct.rs +++ b/tests/expectations/tests/func_ptr_in_struct.rs @@ -33,7 +33,11 @@ fn bindgen_test_layout_Foo() { concat!("Alignment of ", stringify!(Foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/gen-destructors-neg.rs b/tests/expectations/tests/gen-destructors-neg.rs index 67b6d70143..8f4eeaf681 100644 --- a/tests/expectations/tests/gen-destructors-neg.rs +++ b/tests/expectations/tests/gen-destructors-neg.rs @@ -23,7 +23,11 @@ fn bindgen_test_layout_Foo() { concat!("Alignment of ", stringify!(Foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/gen-destructors.rs b/tests/expectations/tests/gen-destructors.rs index 7d96870df8..582e482910 100644 --- a/tests/expectations/tests/gen-destructors.rs +++ b/tests/expectations/tests/gen-destructors.rs @@ -23,7 +23,11 @@ fn bindgen_test_layout_Foo() { concat!("Alignment of ", stringify!(Foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/i128.rs b/tests/expectations/tests/i128.rs index 1a239694c4..656a409bba 100644 --- a/tests/expectations/tests/i128.rs +++ b/tests/expectations/tests/i128.rs @@ -26,7 +26,9 @@ fn bindgen_test_layout_foo() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).my_signed as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).my_signed) as usize - ptr as usize }, 0usize, concat!( @@ -38,7 +40,9 @@ fn bindgen_test_layout_foo() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).my_unsigned as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).my_unsigned) as usize - ptr as usize }, 16usize, concat!( diff --git a/tests/expectations/tests/inline_namespace.rs b/tests/expectations/tests/inline_namespace.rs index 036d2da618..b552ae02ee 100644 --- a/tests/expectations/tests/inline_namespace.rs +++ b/tests/expectations/tests/inline_namespace.rs @@ -32,7 +32,11 @@ pub mod root { concat!("Alignment of ", stringify!(Bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).baz as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/inline_namespace_conservative.rs b/tests/expectations/tests/inline_namespace_conservative.rs index 3d2ce0c419..57c6e214f8 100644 --- a/tests/expectations/tests/inline_namespace_conservative.rs +++ b/tests/expectations/tests/inline_namespace_conservative.rs @@ -37,7 +37,11 @@ pub mod root { concat!("Alignment of ", stringify!(Bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).baz as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/inner_const.rs b/tests/expectations/tests/inner_const.rs index 912ae02422..d93bc8b523 100644 --- a/tests/expectations/tests/inner_const.rs +++ b/tests/expectations/tests/inner_const.rs @@ -31,7 +31,11 @@ fn bindgen_test_layout_Foo() { concat!("Alignment of ", stringify!(Foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/inner_template_self.rs b/tests/expectations/tests/inner_template_self.rs index 3361a1f9dd..e6062718f0 100644 --- a/tests/expectations/tests/inner_template_self.rs +++ b/tests/expectations/tests/inner_template_self.rs @@ -39,8 +39,9 @@ fn bindgen_test_layout_InstantiateIt() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).m_list as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).m_list) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/issue-1118-using-forward-decl.rs b/tests/expectations/tests/issue-1118-using-forward-decl.rs index 99f0341c9d..b29a572ed6 100644 --- a/tests/expectations/tests/issue-1118-using-forward-decl.rs +++ b/tests/expectations/tests/issue-1118-using-forward-decl.rs @@ -25,7 +25,9 @@ fn bindgen_test_layout_nsTArray_base() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).d as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, 0usize, concat!( @@ -78,7 +80,9 @@ fn bindgen_test_layout_nsIContent() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).foo as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/issue-1216-variadic-member.rs b/tests/expectations/tests/issue-1216-variadic-member.rs index 5bca80966c..5f0cd81806 100644 --- a/tests/expectations/tests/issue-1216-variadic-member.rs +++ b/tests/expectations/tests/issue-1216-variadic-member.rs @@ -33,7 +33,11 @@ fn bindgen_test_layout_Foo() { concat!("Alignment of ", stringify!(Foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).f as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(f)) ); diff --git a/tests/expectations/tests/issue-1281.rs b/tests/expectations/tests/issue-1281.rs index fe18fb1a0a..62b5748512 100644 --- a/tests/expectations/tests/issue-1281.rs +++ b/tests/expectations/tests/issue-1281.rs @@ -28,7 +28,11 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).foo as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(foo)) ); @@ -46,7 +50,11 @@ fn bindgen_test_layout_bar() { concat!("Alignment of ", stringify!(bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).u as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(bar), "::", stringify!(u)) ); @@ -70,7 +78,11 @@ fn bindgen_test_layout_baz() { concat!("Alignment of ", stringify!(baz)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).f as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(baz), "::", stringify!(f)) ); diff --git a/tests/expectations/tests/issue-1285.rs b/tests/expectations/tests/issue-1285.rs index 15b8c9e449..e15939bdb8 100644 --- a/tests/expectations/tests/issue-1285.rs +++ b/tests/expectations/tests/issue-1285.rs @@ -30,7 +30,9 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( @@ -42,7 +44,9 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( @@ -75,7 +79,11 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/issue-1291.rs b/tests/expectations/tests/issue-1291.rs index 5680c348cf..355c64f0f8 100644 --- a/tests/expectations/tests/issue-1291.rs +++ b/tests/expectations/tests/issue-1291.rs @@ -38,7 +38,11 @@ fn bindgen_test_layout_RTCRay() { concat!("Alignment of ", stringify!(RTCRay)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).org as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).org) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", @@ -49,7 +53,9 @@ fn bindgen_test_layout_RTCRay() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).align0 as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).align0) as usize - ptr as usize }, 12usize, concat!( @@ -60,7 +66,11 @@ fn bindgen_test_layout_RTCRay() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).dir as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dir) as usize - ptr as usize + }, 16usize, concat!( "Offset of field: ", @@ -71,7 +81,9 @@ fn bindgen_test_layout_RTCRay() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).align1 as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).align1) as usize - ptr as usize }, 28usize, concat!( @@ -83,7 +95,9 @@ fn bindgen_test_layout_RTCRay() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).tnear as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tnear) as usize - ptr as usize }, 32usize, concat!( @@ -94,7 +108,11 @@ fn bindgen_test_layout_RTCRay() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).tfar as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tfar) as usize - ptr as usize + }, 36usize, concat!( "Offset of field: ", @@ -104,7 +122,11 @@ fn bindgen_test_layout_RTCRay() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).time as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).time) as usize - ptr as usize + }, 40usize, concat!( "Offset of field: ", @@ -114,7 +136,11 @@ fn bindgen_test_layout_RTCRay() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).mask as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize + }, 44usize, concat!( "Offset of field: ", @@ -124,7 +150,11 @@ fn bindgen_test_layout_RTCRay() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).Ng as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Ng) as usize - ptr as usize + }, 48usize, concat!( "Offset of field: ", @@ -135,7 +165,9 @@ fn bindgen_test_layout_RTCRay() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).align2 as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).align2) as usize - ptr as usize }, 60usize, concat!( @@ -146,18 +178,28 @@ fn bindgen_test_layout_RTCRay() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).u as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize + }, 64usize, concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(u)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).v as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).v) as usize - ptr as usize + }, 68usize, concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(v)) ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).geomID as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).geomID) as usize - ptr as usize }, 72usize, concat!( @@ -169,7 +211,9 @@ fn bindgen_test_layout_RTCRay() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).primID as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).primID) as usize - ptr as usize }, 76usize, concat!( @@ -181,7 +225,9 @@ fn bindgen_test_layout_RTCRay() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).instID as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).instID) as usize - ptr as usize }, 80usize, concat!( diff --git a/tests/expectations/tests/issue-1382-rust-primitive-types.rs b/tests/expectations/tests/issue-1382-rust-primitive-types.rs index 6f5aec4b6f..3e3e82c9d9 100644 --- a/tests/expectations/tests/issue-1382-rust-primitive-types.rs +++ b/tests/expectations/tests/issue-1382-rust-primitive-types.rs @@ -44,47 +44,83 @@ fn bindgen_test_layout_Foo() { concat!("Alignment of ", stringify!(Foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).i8_ as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i8_) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i8_)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).u8_ as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).u8_) as usize - ptr as usize + }, 4usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u8_)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).i16_ as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i16_) as usize - ptr as usize + }, 8usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i16_)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).u16_ as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).u16_) as usize - ptr as usize + }, 12usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u16_)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).i32_ as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i32_) as usize - ptr as usize + }, 16usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i32_)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).u32_ as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).u32_) as usize - ptr as usize + }, 20usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u32_)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).i64_ as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i64_) as usize - ptr as usize + }, 24usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i64_)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).u64_ as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).u64_) as usize - ptr as usize + }, 28usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u64_)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).i128_ as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i128_) as usize - ptr as usize + }, 32usize, concat!( "Offset of field: ", @@ -94,7 +130,11 @@ fn bindgen_test_layout_Foo() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).u128_ as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).u128_) as usize - ptr as usize + }, 36usize, concat!( "Offset of field: ", @@ -104,7 +144,11 @@ fn bindgen_test_layout_Foo() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).isize_ as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).isize_) as usize - ptr as usize + }, 40usize, concat!( "Offset of field: ", @@ -114,7 +158,11 @@ fn bindgen_test_layout_Foo() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).usize_ as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).usize_) as usize - ptr as usize + }, 44usize, concat!( "Offset of field: ", @@ -124,12 +172,20 @@ fn bindgen_test_layout_Foo() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).f32_ as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).f32_) as usize - ptr as usize + }, 48usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(f32_)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).f64_ as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).f64_) as usize - ptr as usize + }, 52usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(f64_)) ); diff --git a/tests/expectations/tests/issue-1443.rs b/tests/expectations/tests/issue-1443.rs index f422f4c353..b15f5b4571 100644 --- a/tests/expectations/tests/issue-1443.rs +++ b/tests/expectations/tests/issue-1443.rs @@ -29,12 +29,20 @@ fn bindgen_test_layout_Bar() { concat!("Alignment of ", stringify!(Bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).f as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(f)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).m as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize + }, 8usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(m)) ); @@ -67,12 +75,20 @@ fn bindgen_test_layout_Baz() { concat!("Alignment of ", stringify!(Baz)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).f as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(Baz), "::", stringify!(f)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).m as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize + }, 8usize, concat!("Offset of field: ", stringify!(Baz), "::", stringify!(m)) ); @@ -105,12 +121,20 @@ fn bindgen_test_layout_Tar() { concat!("Alignment of ", stringify!(Tar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).f as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(Tar), "::", stringify!(f)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).m as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize + }, 8usize, concat!("Offset of field: ", stringify!(Tar), "::", stringify!(m)) ); @@ -143,12 +167,20 @@ fn bindgen_test_layout_Taz() { concat!("Alignment of ", stringify!(Taz)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).f as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(Taz), "::", stringify!(f)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).m as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize + }, 8usize, concat!("Offset of field: ", stringify!(Taz), "::", stringify!(m)) ); diff --git a/tests/expectations/tests/issue-1454.rs b/tests/expectations/tests/issue-1454.rs index e88e46978b..299e01ba2b 100644 --- a/tests/expectations/tests/issue-1454.rs +++ b/tests/expectations/tests/issue-1454.rs @@ -28,7 +28,9 @@ fn bindgen_test_layout_local_type() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).inner as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).inner) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/issue-1498.rs b/tests/expectations/tests/issue-1498.rs index 4f8a89305b..f526a22303 100644 --- a/tests/expectations/tests/issue-1498.rs +++ b/tests/expectations/tests/issue-1498.rs @@ -45,8 +45,10 @@ fn bindgen_test_layout_rte_memseg__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).addr - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).addr) as usize - ptr as usize }, 0usize, concat!( @@ -58,8 +60,10 @@ fn bindgen_test_layout_rte_memseg__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).addr_64 - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).addr_64) as usize - ptr as usize }, 0usize, concat!( @@ -93,8 +97,9 @@ fn bindgen_test_layout_rte_memseg() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).phys_addr as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).phys_addr) as usize - ptr as usize }, 0usize, concat!( @@ -106,7 +111,9 @@ fn bindgen_test_layout_rte_memseg() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).len as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize }, 16usize, concat!( @@ -118,8 +125,9 @@ fn bindgen_test_layout_rte_memseg() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).hugepage_sz as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).hugepage_sz) as usize - ptr as usize }, 24usize, concat!( @@ -131,8 +139,9 @@ fn bindgen_test_layout_rte_memseg() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).socket_id as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).socket_id) as usize - ptr as usize }, 32usize, concat!( @@ -144,7 +153,9 @@ fn bindgen_test_layout_rte_memseg() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).nchannel as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nchannel) as usize - ptr as usize }, 36usize, concat!( @@ -156,7 +167,9 @@ fn bindgen_test_layout_rte_memseg() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).nrank as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nrank) as usize - ptr as usize }, 40usize, concat!( diff --git a/tests/expectations/tests/issue-1947.rs b/tests/expectations/tests/issue-1947.rs index 1753ef8d02..7303b53ed3 100644 --- a/tests/expectations/tests/issue-1947.rs +++ b/tests/expectations/tests/issue-1947.rs @@ -119,7 +119,9 @@ fn bindgen_test_layout_V56AMDY() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).MADK as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).MADK) as usize - ptr as usize }, 2usize, concat!( @@ -131,7 +133,9 @@ fn bindgen_test_layout_V56AMDY() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).MABR as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).MABR) as usize - ptr as usize }, 3usize, concat!( @@ -143,7 +147,9 @@ fn bindgen_test_layout_V56AMDY() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::()))._rB_ as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr)._rB_) as usize - ptr as usize }, 7usize, concat!( diff --git a/tests/expectations/tests/issue-1977-larger-arrays.rs b/tests/expectations/tests/issue-1977-larger-arrays.rs index 54e5b431db..d0b478e9d6 100644 --- a/tests/expectations/tests/issue-1977-larger-arrays.rs +++ b/tests/expectations/tests/issue-1977-larger-arrays.rs @@ -24,7 +24,9 @@ fn bindgen_test_layout_S() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).large_array as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/issue-1995.rs b/tests/expectations/tests/issue-1995.rs index 58e11eb297..f5abbefcbb 100644 --- a/tests/expectations/tests/issue-1995.rs +++ b/tests/expectations/tests/issue-1995.rs @@ -30,7 +30,11 @@ fn bindgen_test_layout_Bar() { concat!("Alignment of ", stringify!(Bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).baz as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz)) ); diff --git a/tests/expectations/tests/issue-2019.rs b/tests/expectations/tests/issue-2019.rs index 383bd57e15..7d67f1c39a 100644 --- a/tests/expectations/tests/issue-2019.rs +++ b/tests/expectations/tests/issue-2019.rs @@ -23,7 +23,11 @@ fn bindgen_test_layout_A() { concat!("Alignment of ", stringify!(A)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(a)) ); @@ -56,7 +60,11 @@ fn bindgen_test_layout_B() { concat!("Alignment of ", stringify!(B)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).b as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(B), "::", stringify!(b)) ); diff --git a/tests/expectations/tests/issue-372.rs b/tests/expectations/tests/issue-372.rs index 0cd9f7adb3..ad9b41e604 100644 --- a/tests/expectations/tests/issue-372.rs +++ b/tests/expectations/tests/issue-372.rs @@ -29,17 +29,29 @@ pub mod root { concat!("Alignment of ", stringify!(i)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).j as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).j) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(i), "::", stringify!(j)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).k as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).k) as usize - ptr as usize + }, 8usize, concat!("Offset of field: ", stringify!(i), "::", stringify!(k)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).l as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).l) as usize - ptr as usize + }, 16usize, concat!("Offset of field: ", stringify!(i), "::", stringify!(l)) ); @@ -71,7 +83,11 @@ pub mod root { concat!("Alignment of ", stringify!(d)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).m as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(d), "::", stringify!(m)) ); @@ -118,7 +134,11 @@ pub mod root { concat!("Alignment of ", stringify!(F)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).w as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).w) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(F), "::", stringify!(w)) ); diff --git a/tests/expectations/tests/issue-537-repr-packed-n.rs b/tests/expectations/tests/issue-537-repr-packed-n.rs index 13e1482d30..a17664c79a 100644 --- a/tests/expectations/tests/issue-537-repr-packed-n.rs +++ b/tests/expectations/tests/issue-537-repr-packed-n.rs @@ -27,7 +27,9 @@ fn bindgen_test_layout_AlignedToOne() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).i as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, 0usize, concat!( @@ -58,7 +60,9 @@ fn bindgen_test_layout_AlignedToTwo() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).i as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, 0usize, concat!( @@ -92,7 +96,9 @@ fn bindgen_test_layout_PackedToOne() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).x as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, 0usize, concat!( @@ -104,7 +110,9 @@ fn bindgen_test_layout_PackedToOne() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).y as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, 4usize, concat!( @@ -136,7 +144,9 @@ fn bindgen_test_layout_PackedToTwo() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).x as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, 0usize, concat!( @@ -148,7 +158,9 @@ fn bindgen_test_layout_PackedToTwo() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).y as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, 4usize, concat!( diff --git a/tests/expectations/tests/issue-537.rs b/tests/expectations/tests/issue-537.rs index e67c0e9c2e..8675d2277f 100644 --- a/tests/expectations/tests/issue-537.rs +++ b/tests/expectations/tests/issue-537.rs @@ -26,7 +26,9 @@ fn bindgen_test_layout_AlignedToOne() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).i as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, 0usize, concat!( @@ -58,7 +60,9 @@ fn bindgen_test_layout_AlignedToTwo() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).i as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, 0usize, concat!( @@ -92,7 +96,9 @@ fn bindgen_test_layout_PackedToOne() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).x as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, 0usize, concat!( @@ -104,7 +110,9 @@ fn bindgen_test_layout_PackedToOne() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).y as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, 4usize, concat!( @@ -138,7 +146,9 @@ fn bindgen_test_layout_PackedToTwo() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).x as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, 0usize, concat!( @@ -150,7 +160,9 @@ fn bindgen_test_layout_PackedToTwo() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).y as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, 4usize, concat!( diff --git a/tests/expectations/tests/issue-573-layout-test-failures.rs b/tests/expectations/tests/issue-573-layout-test-failures.rs index 871849aa47..bcffcc504e 100644 --- a/tests/expectations/tests/issue-573-layout-test-failures.rs +++ b/tests/expectations/tests/issue-573-layout-test-failures.rs @@ -29,7 +29,9 @@ fn bindgen_test_layout_AutoIdVector() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).ar as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ar) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs b/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs index e04ff24cba..45fe605699 100644 --- a/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs +++ b/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs @@ -29,7 +29,9 @@ fn bindgen_test_layout__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::<_bindgen_ty_1>())).ar as *const _ as usize + let uninit = ::std::mem::MaybeUninit::<_bindgen_ty_1>::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ar) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs b/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs index 01abdcc412..5539ec8b6e 100644 --- a/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs +++ b/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs @@ -62,7 +62,11 @@ fn bindgen_test_layout_g() { concat!("Alignment of ", stringify!(g)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).h as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).h) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(g), "::", stringify!(h)) ); diff --git a/tests/expectations/tests/issue-639-typedef-anon-field.rs b/tests/expectations/tests/issue-639-typedef-anon-field.rs index 4147c1d228..2c634c8ed5 100644 --- a/tests/expectations/tests/issue-639-typedef-anon-field.rs +++ b/tests/expectations/tests/issue-639-typedef-anon-field.rs @@ -28,7 +28,11 @@ fn bindgen_test_layout_Foo_Bar() { concat!("Alignment of ", stringify!(Foo_Bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).abc as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).abc) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", @@ -51,7 +55,11 @@ fn bindgen_test_layout_Foo() { concat!("Alignment of ", stringify!(Foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) ); @@ -79,7 +87,11 @@ fn bindgen_test_layout_Baz_Bar() { concat!("Alignment of ", stringify!(Baz_Bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).abc as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).abc) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/issue-643-inner-struct.rs b/tests/expectations/tests/issue-643-inner-struct.rs index 0728500754..350ecc7be9 100644 --- a/tests/expectations/tests/issue-643-inner-struct.rs +++ b/tests/expectations/tests/issue-643-inner-struct.rs @@ -62,8 +62,9 @@ fn bindgen_test_layout_rte_ring_prod() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).watermark as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).watermark) as usize - ptr as usize }, 0usize, concat!( @@ -93,8 +94,9 @@ fn bindgen_test_layout_rte_ring_cons() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).sc_dequeue as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).sc_dequeue) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/issue-648-derive-debug-with-padding.rs b/tests/expectations/tests/issue-648-derive-debug-with-padding.rs index 4355486947..e686a0afdf 100644 --- a/tests/expectations/tests/issue-648-derive-debug-with-padding.rs +++ b/tests/expectations/tests/issue-648-derive-debug-with-padding.rs @@ -26,7 +26,11 @@ fn bindgen_test_layout_NoDebug() { concat!("Alignment of ", stringify!(NoDebug)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).c as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", @@ -75,8 +79,11 @@ fn bindgen_test_layout_ShouldDeriveDebugButDoesNot() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).c - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, 0usize, concat!( @@ -88,8 +95,11 @@ fn bindgen_test_layout_ShouldDeriveDebugButDoesNot() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).d - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, 32usize, concat!( diff --git a/tests/expectations/tests/issue-674-1.rs b/tests/expectations/tests/issue-674-1.rs index 5ad6694730..8420934aed 100644 --- a/tests/expectations/tests/issue-674-1.rs +++ b/tests/expectations/tests/issue-674-1.rs @@ -38,8 +38,10 @@ pub mod root { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/issue-674-2.rs b/tests/expectations/tests/issue-674-2.rs index 4ccc4504c3..293f94b43f 100644 --- a/tests/expectations/tests/issue-674-2.rs +++ b/tests/expectations/tests/issue-674-2.rs @@ -37,7 +37,11 @@ pub mod root { concat!("Alignment of ", stringify!(c)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).b as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(c), "::", stringify!(b)) ); @@ -60,7 +64,11 @@ pub mod root { concat!("Alignment of ", stringify!(B)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(B), "::", stringify!(a)) ); diff --git a/tests/expectations/tests/issue-674-3.rs b/tests/expectations/tests/issue-674-3.rs index 99c96b969b..91a7b7e2b6 100644 --- a/tests/expectations/tests/issue-674-3.rs +++ b/tests/expectations/tests/issue-674-3.rs @@ -33,7 +33,11 @@ pub mod root { concat!("Alignment of ", stringify!(a)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).b as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(a), "::", stringify!(b)) ); @@ -57,7 +61,9 @@ pub mod root { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).c as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/issue-801-opaque-sloppiness.rs b/tests/expectations/tests/issue-801-opaque-sloppiness.rs index 6fe3cc681f..04f46bafa3 100644 --- a/tests/expectations/tests/issue-801-opaque-sloppiness.rs +++ b/tests/expectations/tests/issue-801-opaque-sloppiness.rs @@ -51,7 +51,11 @@ fn bindgen_test_layout_C() { concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).b as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(b)) ); diff --git a/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs b/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs index 7fd9caa309..655096c8d8 100644 --- a/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs +++ b/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs @@ -121,8 +121,9 @@ fn bindgen_test_layout_Allowlisted() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).some_member as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).some_member) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs b/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs index dc50fe1bfa..4296f57cb4 100644 --- a/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs +++ b/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs @@ -26,7 +26,9 @@ fn bindgen_test_layout_ShouldNotBeCopy() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/jsval_layout_opaque.rs b/tests/expectations/tests/jsval_layout_opaque.rs index 5b8427913c..f8dd367378 100644 --- a/tests/expectations/tests/jsval_layout_opaque.rs +++ b/tests/expectations/tests/jsval_layout_opaque.rs @@ -295,8 +295,11 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())) - .i32_ as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + jsval_layout__bindgen_ty_2__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i32_) as usize - ptr as usize }, 0usize, concat!( @@ -308,8 +311,11 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())) - .u32_ as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + jsval_layout__bindgen_ty_2__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).u32_) as usize - ptr as usize }, 0usize, concat!( @@ -321,8 +327,11 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())) - .why as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + jsval_layout__bindgen_ty_2__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).why) as usize - ptr as usize }, 0usize, concat!( @@ -356,8 +365,10 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).payload - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).payload) as usize - ptr as usize }, 0usize, concat!( @@ -391,7 +402,9 @@ fn bindgen_test_layout_jsval_layout() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).asBits as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).asBits) as usize - ptr as usize }, 0usize, concat!( @@ -403,8 +416,9 @@ fn bindgen_test_layout_jsval_layout() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).debugView as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).debugView) as usize - ptr as usize }, 0usize, concat!( @@ -416,7 +430,9 @@ fn bindgen_test_layout_jsval_layout() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).s as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).s) as usize - ptr as usize }, 0usize, concat!( @@ -428,8 +444,9 @@ fn bindgen_test_layout_jsval_layout() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).asDouble as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).asDouble) as usize - ptr as usize }, 0usize, concat!( @@ -441,7 +458,9 @@ fn bindgen_test_layout_jsval_layout() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).asPtr as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).asPtr) as usize - ptr as usize }, 0usize, concat!( @@ -453,7 +472,9 @@ fn bindgen_test_layout_jsval_layout() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).asWord as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).asWord) as usize - ptr as usize }, 0usize, concat!( @@ -465,8 +486,9 @@ fn bindgen_test_layout_jsval_layout() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).asUIntPtr as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).asUIntPtr) as usize - ptr as usize }, 0usize, concat!( @@ -504,7 +526,11 @@ fn bindgen_test_layout_Value() { concat!("Alignment of ", stringify!(Value)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).data as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/jsval_layout_opaque_1_0.rs b/tests/expectations/tests/jsval_layout_opaque_1_0.rs index 260282dbba..309d54ac6e 100644 --- a/tests/expectations/tests/jsval_layout_opaque_1_0.rs +++ b/tests/expectations/tests/jsval_layout_opaque_1_0.rs @@ -345,8 +345,11 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())) - .i32_ as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + jsval_layout__bindgen_ty_2__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i32_) as usize - ptr as usize }, 0usize, concat!( @@ -358,8 +361,11 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())) - .u32_ as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + jsval_layout__bindgen_ty_2__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).u32_) as usize - ptr as usize }, 0usize, concat!( @@ -371,8 +377,11 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())) - .why as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + jsval_layout__bindgen_ty_2__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).why) as usize - ptr as usize }, 0usize, concat!( @@ -402,8 +411,10 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).payload - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).payload) as usize - ptr as usize }, 0usize, concat!( @@ -433,7 +444,9 @@ fn bindgen_test_layout_jsval_layout() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).asBits as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).asBits) as usize - ptr as usize }, 0usize, concat!( @@ -445,8 +458,9 @@ fn bindgen_test_layout_jsval_layout() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).debugView as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).debugView) as usize - ptr as usize }, 0usize, concat!( @@ -458,7 +472,9 @@ fn bindgen_test_layout_jsval_layout() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).s as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).s) as usize - ptr as usize }, 0usize, concat!( @@ -470,8 +486,9 @@ fn bindgen_test_layout_jsval_layout() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).asDouble as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).asDouble) as usize - ptr as usize }, 0usize, concat!( @@ -483,7 +500,9 @@ fn bindgen_test_layout_jsval_layout() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).asPtr as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).asPtr) as usize - ptr as usize }, 0usize, concat!( @@ -495,7 +514,9 @@ fn bindgen_test_layout_jsval_layout() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).asWord as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).asWord) as usize - ptr as usize }, 0usize, concat!( @@ -507,8 +528,9 @@ fn bindgen_test_layout_jsval_layout() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).asUIntPtr as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).asUIntPtr) as usize - ptr as usize }, 0usize, concat!( @@ -542,7 +564,11 @@ fn bindgen_test_layout_Value() { concat!("Alignment of ", stringify!(Value)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).data as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/layout_align.rs b/tests/expectations/tests/layout_align.rs index cb34df3e76..7d2c5a6ee9 100644 --- a/tests/expectations/tests/layout_align.rs +++ b/tests/expectations/tests/layout_align.rs @@ -181,8 +181,9 @@ fn bindgen_test_layout_rte_eth_link() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).link_speed as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).link_speed) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/layout_arp.rs b/tests/expectations/tests/layout_arp.rs index d6642d7e2b..390c87aa81 100644 --- a/tests/expectations/tests/layout_arp.rs +++ b/tests/expectations/tests/layout_arp.rs @@ -42,8 +42,9 @@ fn bindgen_test_layout_ether_addr() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).addr_bytes as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).addr_bytes) as usize - ptr as usize }, 0usize, concat!( @@ -81,7 +82,9 @@ fn bindgen_test_layout_arp_ipv4() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).arp_sha as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).arp_sha) as usize - ptr as usize }, 0usize, concat!( @@ -93,7 +96,9 @@ fn bindgen_test_layout_arp_ipv4() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).arp_sip as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).arp_sip) as usize - ptr as usize }, 6usize, concat!( @@ -105,7 +110,9 @@ fn bindgen_test_layout_arp_ipv4() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).arp_tha as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).arp_tha) as usize - ptr as usize }, 10usize, concat!( @@ -117,7 +124,9 @@ fn bindgen_test_layout_arp_ipv4() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).arp_tip as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).arp_tip) as usize - ptr as usize }, 16usize, concat!( @@ -153,7 +162,9 @@ fn bindgen_test_layout_arp_hdr() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).arp_hrd as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).arp_hrd) as usize - ptr as usize }, 0usize, concat!( @@ -165,7 +176,9 @@ fn bindgen_test_layout_arp_hdr() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).arp_pro as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).arp_pro) as usize - ptr as usize }, 2usize, concat!( @@ -177,7 +190,9 @@ fn bindgen_test_layout_arp_hdr() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).arp_hln as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).arp_hln) as usize - ptr as usize }, 4usize, concat!( @@ -189,7 +204,9 @@ fn bindgen_test_layout_arp_hdr() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).arp_pln as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).arp_pln) as usize - ptr as usize }, 5usize, concat!( @@ -201,7 +218,9 @@ fn bindgen_test_layout_arp_hdr() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).arp_op as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).arp_op) as usize - ptr as usize }, 6usize, concat!( @@ -213,7 +232,9 @@ fn bindgen_test_layout_arp_hdr() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).arp_data as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).arp_data) as usize - ptr as usize }, 8usize, concat!( diff --git a/tests/expectations/tests/layout_array.rs b/tests/expectations/tests/layout_array.rs index 3ba1b6d0ba..0e25258ae5 100644 --- a/tests/expectations/tests/layout_array.rs +++ b/tests/expectations/tests/layout_array.rs @@ -81,8 +81,9 @@ fn bindgen_test_layout_rte_mempool_ops() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).name as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).name) as usize - ptr as usize }, 0usize, concat!( @@ -94,8 +95,9 @@ fn bindgen_test_layout_rte_mempool_ops() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).alloc as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).alloc) as usize - ptr as usize }, 32usize, concat!( @@ -107,8 +109,9 @@ fn bindgen_test_layout_rte_mempool_ops() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).free as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).free) as usize - ptr as usize }, 40usize, concat!( @@ -120,8 +123,9 @@ fn bindgen_test_layout_rte_mempool_ops() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).enqueue as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).enqueue) as usize - ptr as usize }, 48usize, concat!( @@ -133,8 +137,9 @@ fn bindgen_test_layout_rte_mempool_ops() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).dequeue as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dequeue) as usize - ptr as usize }, 56usize, concat!( @@ -146,8 +151,9 @@ fn bindgen_test_layout_rte_mempool_ops() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).get_count as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).get_count) as usize - ptr as usize }, 64usize, concat!( @@ -198,8 +204,9 @@ fn bindgen_test_layout_rte_spinlock_t() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).locked as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).locked) as usize - ptr as usize }, 0usize, concat!( @@ -243,8 +250,10 @@ fn bindgen_test_layout_rte_mempool_ops_table() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).sl as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).sl) as usize - ptr as usize }, 0usize, concat!( @@ -256,8 +265,10 @@ fn bindgen_test_layout_rte_mempool_ops_table() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).num_ops - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).num_ops) as usize - ptr as usize }, 4usize, concat!( @@ -269,8 +280,10 @@ fn bindgen_test_layout_rte_mempool_ops_table() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).ops as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ops) as usize - ptr as usize }, 64usize, concat!( @@ -319,8 +332,10 @@ fn bindgen_test_layout_malloc_heap__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).lh_first - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).lh_first) as usize - ptr as usize }, 0usize, concat!( @@ -354,7 +369,9 @@ fn bindgen_test_layout_malloc_heap() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).lock as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).lock) as usize - ptr as usize }, 0usize, concat!( @@ -366,8 +383,9 @@ fn bindgen_test_layout_malloc_heap() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).free_head as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).free_head) as usize - ptr as usize }, 8usize, concat!( @@ -379,8 +397,9 @@ fn bindgen_test_layout_malloc_heap() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).alloc_count as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).alloc_count) as usize - ptr as usize }, 112usize, concat!( @@ -392,8 +411,9 @@ fn bindgen_test_layout_malloc_heap() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).total_size as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).total_size) as usize - ptr as usize }, 120usize, concat!( diff --git a/tests/expectations/tests/layout_array_too_long.rs b/tests/expectations/tests/layout_array_too_long.rs index c9880ea2a9..b38523ffd5 100644 --- a/tests/expectations/tests/layout_array_too_long.rs +++ b/tests/expectations/tests/layout_array_too_long.rs @@ -46,7 +46,11 @@ fn bindgen_test_layout_ip_frag() { concat!("Alignment of ", stringify!(ip_frag)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).ofs as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ofs) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", @@ -56,7 +60,11 @@ fn bindgen_test_layout_ip_frag() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).len as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize + }, 2usize, concat!( "Offset of field: ", @@ -66,7 +74,11 @@ fn bindgen_test_layout_ip_frag() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).mb as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mb) as usize - ptr as usize + }, 8usize, concat!( "Offset of field: ", @@ -110,7 +122,9 @@ fn bindgen_test_layout_ip_frag_key() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).src_dst as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).src_dst) as usize - ptr as usize }, 0usize, concat!( @@ -122,7 +136,9 @@ fn bindgen_test_layout_ip_frag_key() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).id as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).id) as usize - ptr as usize }, 32usize, concat!( @@ -134,7 +150,9 @@ fn bindgen_test_layout_ip_frag_key() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).key_len as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).key_len) as usize - ptr as usize }, 36usize, concat!( @@ -186,8 +204,10 @@ fn bindgen_test_layout_ip_frag_pkt__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).tqe_next - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tqe_next) as usize - ptr as usize }, 0usize, concat!( @@ -199,8 +219,10 @@ fn bindgen_test_layout_ip_frag_pkt__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).tqe_prev - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tqe_prev) as usize - ptr as usize }, 8usize, concat!( @@ -234,7 +256,9 @@ fn bindgen_test_layout_ip_frag_pkt() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).lru as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).lru) as usize - ptr as usize }, 0usize, concat!( @@ -246,7 +270,9 @@ fn bindgen_test_layout_ip_frag_pkt() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).key as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).key) as usize - ptr as usize }, 16usize, concat!( @@ -258,7 +284,9 @@ fn bindgen_test_layout_ip_frag_pkt() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).start as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).start) as usize - ptr as usize }, 56usize, concat!( @@ -270,8 +298,9 @@ fn bindgen_test_layout_ip_frag_pkt() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).total_size as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).total_size) as usize - ptr as usize }, 64usize, concat!( @@ -283,8 +312,9 @@ fn bindgen_test_layout_ip_frag_pkt() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).frag_size as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).frag_size) as usize - ptr as usize }, 68usize, concat!( @@ -296,8 +326,9 @@ fn bindgen_test_layout_ip_frag_pkt() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).last_idx as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).last_idx) as usize - ptr as usize }, 72usize, concat!( @@ -309,7 +340,9 @@ fn bindgen_test_layout_ip_frag_pkt() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).frags as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).frags) as usize - ptr as usize }, 80usize, concat!( diff --git a/tests/expectations/tests/layout_cmdline_token.rs b/tests/expectations/tests/layout_cmdline_token.rs index 47170dd709..37c8928cc8 100644 --- a/tests/expectations/tests/layout_cmdline_token.rs +++ b/tests/expectations/tests/layout_cmdline_token.rs @@ -27,8 +27,9 @@ fn bindgen_test_layout_cmdline_token_hdr() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).ops as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ops) as usize - ptr as usize }, 0usize, concat!( @@ -40,8 +41,9 @@ fn bindgen_test_layout_cmdline_token_hdr() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).offset as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).offset) as usize - ptr as usize }, 8usize, concat!( @@ -131,8 +133,9 @@ fn bindgen_test_layout_cmdline_token_ops() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).parse as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).parse) as usize - ptr as usize }, 0usize, concat!( @@ -144,8 +147,9 @@ fn bindgen_test_layout_cmdline_token_ops() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).complete_get_nb - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).complete_get_nb) as usize - ptr as usize }, 8usize, concat!( @@ -157,8 +161,10 @@ fn bindgen_test_layout_cmdline_token_ops() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).complete_get_elt - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).complete_get_elt) as usize - + ptr as usize }, 16usize, concat!( @@ -170,8 +176,9 @@ fn bindgen_test_layout_cmdline_token_ops() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).get_help as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).get_help) as usize - ptr as usize }, 24usize, concat!( @@ -213,8 +220,10 @@ fn bindgen_test_layout_cmdline_token_num_data() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).type_ as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize }, 0usize, concat!( @@ -254,8 +263,9 @@ fn bindgen_test_layout_cmdline_token_num() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).hdr as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).hdr) as usize - ptr as usize }, 0usize, concat!( @@ -267,8 +277,9 @@ fn bindgen_test_layout_cmdline_token_num() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).num_data as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).num_data) as usize - ptr as usize }, 16usize, concat!( diff --git a/tests/expectations/tests/layout_eth_conf.rs b/tests/expectations/tests/layout_eth_conf.rs index e880608203..9398357f6e 100644 --- a/tests/expectations/tests/layout_eth_conf.rs +++ b/tests/expectations/tests/layout_eth_conf.rs @@ -172,8 +172,9 @@ fn bindgen_test_layout_rte_eth_rxmode() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mq_mode as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mq_mode) as usize - ptr as usize }, 0usize, concat!( @@ -185,8 +186,9 @@ fn bindgen_test_layout_rte_eth_rxmode() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).max_rx_pkt_len - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).max_rx_pkt_len) as usize - ptr as usize }, 4usize, concat!( @@ -198,8 +200,9 @@ fn bindgen_test_layout_rte_eth_rxmode() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).split_hdr_size - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).split_hdr_size) as usize - ptr as usize }, 8usize, concat!( @@ -437,8 +440,9 @@ fn bindgen_test_layout_rte_eth_txmode() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mq_mode as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mq_mode) as usize - ptr as usize }, 0usize, concat!( @@ -450,7 +454,9 @@ fn bindgen_test_layout_rte_eth_txmode() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).pvid as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pvid) as usize - ptr as usize }, 4usize, concat!( @@ -575,8 +581,9 @@ fn bindgen_test_layout_rte_eth_rss_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).rss_key as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rss_key) as usize - ptr as usize }, 0usize, concat!( @@ -588,8 +595,9 @@ fn bindgen_test_layout_rte_eth_rss_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).rss_key_len as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rss_key_len) as usize - ptr as usize }, 8usize, concat!( @@ -601,8 +609,9 @@ fn bindgen_test_layout_rte_eth_rss_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).rss_hf as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rss_hf) as usize - ptr as usize }, 16usize, concat!( @@ -695,8 +704,11 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())) - .vlan_id as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + rte_eth_vmdq_dcb_conf__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).vlan_id) as usize - ptr as usize }, 0usize, concat!( @@ -708,8 +720,11 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())) - .pools as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + rte_eth_vmdq_dcb_conf__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pools) as usize - ptr as usize }, 8usize, concat!( @@ -734,8 +749,10 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).nb_queue_pools - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize }, 0usize, concat!( @@ -747,8 +764,11 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())) - .enable_default_pool as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).enable_default_pool) as usize - + ptr as usize }, 4usize, concat!( @@ -760,8 +780,10 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).default_pool - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).default_pool) as usize - ptr as usize }, 5usize, concat!( @@ -773,8 +795,10 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).nb_pool_maps - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_pool_maps) as usize - ptr as usize }, 6usize, concat!( @@ -786,8 +810,10 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).pool_map - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pool_map) as usize - ptr as usize }, 8usize, concat!( @@ -799,8 +825,10 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).dcb_tc as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize }, 1032usize, concat!( @@ -842,8 +870,10 @@ fn bindgen_test_layout_rte_eth_dcb_rx_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).nb_tcs as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize }, 0usize, concat!( @@ -855,8 +885,10 @@ fn bindgen_test_layout_rte_eth_dcb_rx_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).dcb_tc as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize }, 4usize, concat!( @@ -898,8 +930,10 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_tx_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).nb_queue_pools - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize }, 0usize, concat!( @@ -911,8 +945,10 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_tx_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).dcb_tc - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize }, 4usize, concat!( @@ -954,8 +990,10 @@ fn bindgen_test_layout_rte_eth_dcb_tx_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).nb_tcs as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize }, 0usize, concat!( @@ -967,8 +1005,10 @@ fn bindgen_test_layout_rte_eth_dcb_tx_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).dcb_tc as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize }, 4usize, concat!( @@ -1008,8 +1048,10 @@ fn bindgen_test_layout_rte_eth_vmdq_tx_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).nb_queue_pools - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize }, 0usize, concat!( @@ -1072,8 +1114,11 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())) - .vlan_id as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + rte_eth_vmdq_rx_conf__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).vlan_id) as usize - ptr as usize }, 0usize, concat!( @@ -1085,8 +1130,11 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).pools - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + rte_eth_vmdq_rx_conf__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pools) as usize - ptr as usize }, 8usize, concat!( @@ -1111,8 +1159,10 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).nb_queue_pools - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize }, 0usize, concat!( @@ -1124,8 +1174,11 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).enable_default_pool - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).enable_default_pool) as usize - + ptr as usize }, 4usize, concat!( @@ -1137,8 +1190,10 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).default_pool - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).default_pool) as usize - ptr as usize }, 5usize, concat!( @@ -1150,8 +1205,11 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).enable_loop_back - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).enable_loop_back) as usize - + ptr as usize }, 6usize, concat!( @@ -1163,8 +1221,10 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).nb_pool_maps - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_pool_maps) as usize - ptr as usize }, 7usize, concat!( @@ -1176,8 +1236,10 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).rx_mode as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rx_mode) as usize - ptr as usize }, 8usize, concat!( @@ -1189,8 +1251,10 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).pool_map - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pool_map) as usize - ptr as usize }, 16usize, concat!( @@ -1277,8 +1341,9 @@ fn bindgen_test_layout_rte_eth_ipv4_flow() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).src_ip as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize }, 0usize, concat!( @@ -1290,8 +1355,9 @@ fn bindgen_test_layout_rte_eth_ipv4_flow() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).dst_ip as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dst_ip) as usize - ptr as usize }, 4usize, concat!( @@ -1303,8 +1369,9 @@ fn bindgen_test_layout_rte_eth_ipv4_flow() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).tos as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tos) as usize - ptr as usize }, 8usize, concat!( @@ -1316,8 +1383,9 @@ fn bindgen_test_layout_rte_eth_ipv4_flow() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).ttl as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ttl) as usize - ptr as usize }, 9usize, concat!( @@ -1329,8 +1397,9 @@ fn bindgen_test_layout_rte_eth_ipv4_flow() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).proto as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize }, 10usize, concat!( @@ -1370,8 +1439,9 @@ fn bindgen_test_layout_rte_eth_ipv6_flow() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).src_ip as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize }, 0usize, concat!( @@ -1383,8 +1453,9 @@ fn bindgen_test_layout_rte_eth_ipv6_flow() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).dst_ip as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dst_ip) as usize - ptr as usize }, 16usize, concat!( @@ -1396,8 +1467,9 @@ fn bindgen_test_layout_rte_eth_ipv6_flow() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).tc as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tc) as usize - ptr as usize }, 32usize, concat!( @@ -1409,8 +1481,9 @@ fn bindgen_test_layout_rte_eth_ipv6_flow() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).proto as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize }, 33usize, concat!( @@ -1422,8 +1495,9 @@ fn bindgen_test_layout_rte_eth_ipv6_flow() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).hop_limits as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).hop_limits) as usize - ptr as usize }, 34usize, concat!( @@ -1472,8 +1546,10 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).vlan_tci_mask - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).vlan_tci_mask) as usize - ptr as usize }, 0usize, concat!( @@ -1485,8 +1561,10 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).ipv4_mask as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ipv4_mask) as usize - ptr as usize }, 4usize, concat!( @@ -1498,8 +1576,10 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).ipv6_mask as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ipv6_mask) as usize - ptr as usize }, 16usize, concat!( @@ -1511,8 +1591,10 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).src_port_mask - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).src_port_mask) as usize - ptr as usize }, 52usize, concat!( @@ -1524,8 +1606,10 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).dst_port_mask - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dst_port_mask) as usize - ptr as usize }, 54usize, concat!( @@ -1537,8 +1621,11 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mac_addr_byte_mask - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mac_addr_byte_mask) as usize - + ptr as usize }, 56usize, concat!( @@ -1550,8 +1637,10 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).tunnel_id_mask - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tunnel_id_mask) as usize - ptr as usize }, 60usize, concat!( @@ -1563,8 +1652,11 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).tunnel_type_mask - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tunnel_type_mask) as usize - + ptr as usize }, 64usize, concat!( @@ -1609,8 +1701,10 @@ fn bindgen_test_layout_rte_eth_flex_payload_cfg() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).type_ - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize }, 0usize, concat!( @@ -1622,8 +1716,10 @@ fn bindgen_test_layout_rte_eth_flex_payload_cfg() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).src_offset - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).src_offset) as usize - ptr as usize }, 4usize, concat!( @@ -1665,8 +1761,10 @@ fn bindgen_test_layout_rte_eth_fdir_flex_mask() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).flow_type - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).flow_type) as usize - ptr as usize }, 0usize, concat!( @@ -1678,8 +1776,10 @@ fn bindgen_test_layout_rte_eth_fdir_flex_mask() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mask as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize }, 2usize, concat!( @@ -1716,8 +1816,10 @@ fn bindgen_test_layout_rte_eth_fdir_flex_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).nb_payloads - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_payloads) as usize - ptr as usize }, 0usize, concat!( @@ -1729,8 +1831,10 @@ fn bindgen_test_layout_rte_eth_fdir_flex_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).nb_flexmasks - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_flexmasks) as usize - ptr as usize }, 2usize, concat!( @@ -1742,8 +1846,10 @@ fn bindgen_test_layout_rte_eth_fdir_flex_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).flex_set - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).flex_set) as usize - ptr as usize }, 4usize, concat!( @@ -1755,8 +1861,10 @@ fn bindgen_test_layout_rte_eth_fdir_flex_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).flex_mask - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).flex_mask) as usize - ptr as usize }, 292usize, concat!( @@ -1808,7 +1916,9 @@ fn bindgen_test_layout_rte_fdir_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mode as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mode) as usize - ptr as usize }, 0usize, concat!( @@ -1820,8 +1930,9 @@ fn bindgen_test_layout_rte_fdir_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).pballoc as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pballoc) as usize - ptr as usize }, 4usize, concat!( @@ -1833,8 +1944,9 @@ fn bindgen_test_layout_rte_fdir_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).status as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).status) as usize - ptr as usize }, 8usize, concat!( @@ -1846,8 +1958,9 @@ fn bindgen_test_layout_rte_fdir_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).drop_queue as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).drop_queue) as usize - ptr as usize }, 12usize, concat!( @@ -1859,7 +1972,9 @@ fn bindgen_test_layout_rte_fdir_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mask as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize }, 16usize, concat!( @@ -1871,8 +1986,9 @@ fn bindgen_test_layout_rte_fdir_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).flex_conf as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).flex_conf) as usize - ptr as usize }, 84usize, concat!( @@ -1915,7 +2031,9 @@ fn bindgen_test_layout_rte_intr_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).lsc as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).lsc) as usize - ptr as usize }, 0usize, concat!( @@ -1927,7 +2045,9 @@ fn bindgen_test_layout_rte_intr_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).rxq as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rxq) as usize - ptr as usize }, 2usize, concat!( @@ -1997,8 +2117,10 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).rss_conf - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rss_conf) as usize - ptr as usize }, 0usize, concat!( @@ -2010,8 +2132,10 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).vmdq_dcb_conf - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).vmdq_dcb_conf) as usize - ptr as usize }, 24usize, concat!( @@ -2023,8 +2147,10 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).dcb_rx_conf - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dcb_rx_conf) as usize - ptr as usize }, 1064usize, concat!( @@ -2036,8 +2162,10 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).vmdq_rx_conf - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).vmdq_rx_conf) as usize - ptr as usize }, 1080usize, concat!( @@ -2078,8 +2206,11 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())) - .vmdq_dcb_tx_conf as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).vmdq_dcb_tx_conf) as usize - + ptr as usize }, 0usize, concat!( @@ -2091,8 +2222,10 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).dcb_tx_conf - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dcb_tx_conf) as usize - ptr as usize }, 0usize, concat!( @@ -2104,8 +2237,10 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).vmdq_tx_conf - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).vmdq_tx_conf) as usize - ptr as usize }, 0usize, concat!( @@ -2139,8 +2274,9 @@ fn bindgen_test_layout_rte_eth_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).link_speeds as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).link_speeds) as usize - ptr as usize }, 0usize, concat!( @@ -2152,7 +2288,9 @@ fn bindgen_test_layout_rte_eth_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).rxmode as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rxmode) as usize - ptr as usize }, 4usize, concat!( @@ -2164,7 +2302,9 @@ fn bindgen_test_layout_rte_eth_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).txmode as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).txmode) as usize - ptr as usize }, 16usize, concat!( @@ -2176,8 +2316,9 @@ fn bindgen_test_layout_rte_eth_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).lpbk_mode as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).lpbk_mode) as usize - ptr as usize }, 24usize, concat!( @@ -2189,8 +2330,9 @@ fn bindgen_test_layout_rte_eth_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).rx_adv_conf as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rx_adv_conf) as usize - ptr as usize }, 32usize, concat!( @@ -2202,8 +2344,9 @@ fn bindgen_test_layout_rte_eth_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).tx_adv_conf as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tx_adv_conf) as usize - ptr as usize }, 2152usize, concat!( @@ -2215,8 +2358,10 @@ fn bindgen_test_layout_rte_eth_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).dcb_capability_en - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dcb_capability_en) as usize - + ptr as usize }, 2164usize, concat!( @@ -2228,8 +2373,9 @@ fn bindgen_test_layout_rte_eth_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).fdir_conf as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).fdir_conf) as usize - ptr as usize }, 2168usize, concat!( @@ -2241,8 +2387,9 @@ fn bindgen_test_layout_rte_eth_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).intr_conf as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).intr_conf) as usize - ptr as usize }, 2940usize, concat!( diff --git a/tests/expectations/tests/layout_eth_conf_1_0.rs b/tests/expectations/tests/layout_eth_conf_1_0.rs index fde1c678cf..d395acdfff 100644 --- a/tests/expectations/tests/layout_eth_conf_1_0.rs +++ b/tests/expectations/tests/layout_eth_conf_1_0.rs @@ -215,8 +215,9 @@ fn bindgen_test_layout_rte_eth_rxmode() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mq_mode as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mq_mode) as usize - ptr as usize }, 0usize, concat!( @@ -228,8 +229,9 @@ fn bindgen_test_layout_rte_eth_rxmode() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).max_rx_pkt_len - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).max_rx_pkt_len) as usize - ptr as usize }, 4usize, concat!( @@ -241,8 +243,9 @@ fn bindgen_test_layout_rte_eth_rxmode() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).split_hdr_size - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).split_hdr_size) as usize - ptr as usize }, 8usize, concat!( @@ -485,8 +488,9 @@ fn bindgen_test_layout_rte_eth_txmode() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mq_mode as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mq_mode) as usize - ptr as usize }, 0usize, concat!( @@ -498,7 +502,9 @@ fn bindgen_test_layout_rte_eth_txmode() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).pvid as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pvid) as usize - ptr as usize }, 4usize, concat!( @@ -628,8 +634,9 @@ fn bindgen_test_layout_rte_eth_rss_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).rss_key as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rss_key) as usize - ptr as usize }, 0usize, concat!( @@ -641,8 +648,9 @@ fn bindgen_test_layout_rte_eth_rss_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).rss_key_len as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rss_key_len) as usize - ptr as usize }, 8usize, concat!( @@ -654,8 +662,9 @@ fn bindgen_test_layout_rte_eth_rss_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).rss_hf as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rss_hf) as usize - ptr as usize }, 16usize, concat!( @@ -753,8 +762,11 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())) - .vlan_id as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + rte_eth_vmdq_dcb_conf__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).vlan_id) as usize - ptr as usize }, 0usize, concat!( @@ -766,8 +778,11 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())) - .pools as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + rte_eth_vmdq_dcb_conf__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pools) as usize - ptr as usize }, 8usize, concat!( @@ -797,8 +812,10 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).nb_queue_pools - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize }, 0usize, concat!( @@ -810,8 +827,11 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())) - .enable_default_pool as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).enable_default_pool) as usize - + ptr as usize }, 4usize, concat!( @@ -823,8 +843,10 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).default_pool - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).default_pool) as usize - ptr as usize }, 5usize, concat!( @@ -836,8 +858,10 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).nb_pool_maps - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_pool_maps) as usize - ptr as usize }, 6usize, concat!( @@ -849,8 +873,10 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).pool_map - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pool_map) as usize - ptr as usize }, 8usize, concat!( @@ -862,8 +888,10 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).dcb_tc as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize }, 1032usize, concat!( @@ -910,8 +938,10 @@ fn bindgen_test_layout_rte_eth_dcb_rx_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).nb_tcs as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize }, 0usize, concat!( @@ -923,8 +953,10 @@ fn bindgen_test_layout_rte_eth_dcb_rx_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).dcb_tc as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize }, 4usize, concat!( @@ -971,8 +1003,10 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_tx_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).nb_queue_pools - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize }, 0usize, concat!( @@ -984,8 +1018,10 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_tx_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).dcb_tc - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize }, 4usize, concat!( @@ -1032,8 +1068,10 @@ fn bindgen_test_layout_rte_eth_dcb_tx_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).nb_tcs as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize }, 0usize, concat!( @@ -1045,8 +1083,10 @@ fn bindgen_test_layout_rte_eth_dcb_tx_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).dcb_tc as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize }, 4usize, concat!( @@ -1091,8 +1131,10 @@ fn bindgen_test_layout_rte_eth_vmdq_tx_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).nb_queue_pools - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize }, 0usize, concat!( @@ -1160,8 +1202,11 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())) - .vlan_id as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + rte_eth_vmdq_rx_conf__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).vlan_id) as usize - ptr as usize }, 0usize, concat!( @@ -1173,8 +1218,11 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).pools - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + rte_eth_vmdq_rx_conf__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pools) as usize - ptr as usize }, 8usize, concat!( @@ -1204,8 +1252,10 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).nb_queue_pools - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize }, 0usize, concat!( @@ -1217,8 +1267,11 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).enable_default_pool - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).enable_default_pool) as usize - + ptr as usize }, 4usize, concat!( @@ -1230,8 +1283,10 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).default_pool - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).default_pool) as usize - ptr as usize }, 5usize, concat!( @@ -1243,8 +1298,11 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).enable_loop_back - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).enable_loop_back) as usize - + ptr as usize }, 6usize, concat!( @@ -1256,8 +1314,10 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).nb_pool_maps - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_pool_maps) as usize - ptr as usize }, 7usize, concat!( @@ -1269,8 +1329,10 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).rx_mode as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rx_mode) as usize - ptr as usize }, 8usize, concat!( @@ -1282,8 +1344,10 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).pool_map - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pool_map) as usize - ptr as usize }, 16usize, concat!( @@ -1375,8 +1439,9 @@ fn bindgen_test_layout_rte_eth_ipv4_flow() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).src_ip as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize }, 0usize, concat!( @@ -1388,8 +1453,9 @@ fn bindgen_test_layout_rte_eth_ipv4_flow() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).dst_ip as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dst_ip) as usize - ptr as usize }, 4usize, concat!( @@ -1401,8 +1467,9 @@ fn bindgen_test_layout_rte_eth_ipv4_flow() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).tos as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tos) as usize - ptr as usize }, 8usize, concat!( @@ -1414,8 +1481,9 @@ fn bindgen_test_layout_rte_eth_ipv4_flow() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).ttl as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ttl) as usize - ptr as usize }, 9usize, concat!( @@ -1427,8 +1495,9 @@ fn bindgen_test_layout_rte_eth_ipv4_flow() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).proto as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize }, 10usize, concat!( @@ -1473,8 +1542,9 @@ fn bindgen_test_layout_rte_eth_ipv6_flow() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).src_ip as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize }, 0usize, concat!( @@ -1486,8 +1556,9 @@ fn bindgen_test_layout_rte_eth_ipv6_flow() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).dst_ip as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dst_ip) as usize - ptr as usize }, 16usize, concat!( @@ -1499,8 +1570,9 @@ fn bindgen_test_layout_rte_eth_ipv6_flow() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).tc as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tc) as usize - ptr as usize }, 32usize, concat!( @@ -1512,8 +1584,9 @@ fn bindgen_test_layout_rte_eth_ipv6_flow() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).proto as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize }, 33usize, concat!( @@ -1525,8 +1598,9 @@ fn bindgen_test_layout_rte_eth_ipv6_flow() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).hop_limits as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).hop_limits) as usize - ptr as usize }, 34usize, concat!( @@ -1580,8 +1654,10 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).vlan_tci_mask - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).vlan_tci_mask) as usize - ptr as usize }, 0usize, concat!( @@ -1593,8 +1669,10 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).ipv4_mask as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ipv4_mask) as usize - ptr as usize }, 4usize, concat!( @@ -1606,8 +1684,10 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).ipv6_mask as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ipv6_mask) as usize - ptr as usize }, 16usize, concat!( @@ -1619,8 +1699,10 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).src_port_mask - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).src_port_mask) as usize - ptr as usize }, 52usize, concat!( @@ -1632,8 +1714,10 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).dst_port_mask - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dst_port_mask) as usize - ptr as usize }, 54usize, concat!( @@ -1645,8 +1729,11 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mac_addr_byte_mask - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mac_addr_byte_mask) as usize - + ptr as usize }, 56usize, concat!( @@ -1658,8 +1745,10 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).tunnel_id_mask - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tunnel_id_mask) as usize - ptr as usize }, 60usize, concat!( @@ -1671,8 +1760,11 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).tunnel_type_mask - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tunnel_type_mask) as usize - + ptr as usize }, 64usize, concat!( @@ -1722,8 +1814,10 @@ fn bindgen_test_layout_rte_eth_flex_payload_cfg() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).type_ - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize }, 0usize, concat!( @@ -1735,8 +1829,10 @@ fn bindgen_test_layout_rte_eth_flex_payload_cfg() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).src_offset - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).src_offset) as usize - ptr as usize }, 4usize, concat!( @@ -1783,8 +1879,10 @@ fn bindgen_test_layout_rte_eth_fdir_flex_mask() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).flow_type - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).flow_type) as usize - ptr as usize }, 0usize, concat!( @@ -1796,8 +1894,10 @@ fn bindgen_test_layout_rte_eth_fdir_flex_mask() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mask as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize }, 2usize, concat!( @@ -1839,8 +1939,10 @@ fn bindgen_test_layout_rte_eth_fdir_flex_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).nb_payloads - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_payloads) as usize - ptr as usize }, 0usize, concat!( @@ -1852,8 +1954,10 @@ fn bindgen_test_layout_rte_eth_fdir_flex_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).nb_flexmasks - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_flexmasks) as usize - ptr as usize }, 2usize, concat!( @@ -1865,8 +1969,10 @@ fn bindgen_test_layout_rte_eth_fdir_flex_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).flex_set - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).flex_set) as usize - ptr as usize }, 4usize, concat!( @@ -1878,8 +1984,10 @@ fn bindgen_test_layout_rte_eth_fdir_flex_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).flex_mask - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).flex_mask) as usize - ptr as usize }, 292usize, concat!( @@ -1936,7 +2044,9 @@ fn bindgen_test_layout_rte_fdir_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mode as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mode) as usize - ptr as usize }, 0usize, concat!( @@ -1948,8 +2058,9 @@ fn bindgen_test_layout_rte_fdir_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).pballoc as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pballoc) as usize - ptr as usize }, 4usize, concat!( @@ -1961,8 +2072,9 @@ fn bindgen_test_layout_rte_fdir_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).status as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).status) as usize - ptr as usize }, 8usize, concat!( @@ -1974,8 +2086,9 @@ fn bindgen_test_layout_rte_fdir_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).drop_queue as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).drop_queue) as usize - ptr as usize }, 12usize, concat!( @@ -1987,7 +2100,9 @@ fn bindgen_test_layout_rte_fdir_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mask as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize }, 16usize, concat!( @@ -1999,8 +2114,9 @@ fn bindgen_test_layout_rte_fdir_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).flex_conf as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).flex_conf) as usize - ptr as usize }, 84usize, concat!( @@ -2048,7 +2164,9 @@ fn bindgen_test_layout_rte_intr_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).lsc as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).lsc) as usize - ptr as usize }, 0usize, concat!( @@ -2060,7 +2178,9 @@ fn bindgen_test_layout_rte_intr_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).rxq as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rxq) as usize - ptr as usize }, 2usize, concat!( @@ -2135,8 +2255,10 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).rss_conf - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rss_conf) as usize - ptr as usize }, 0usize, concat!( @@ -2148,8 +2270,10 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).vmdq_dcb_conf - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).vmdq_dcb_conf) as usize - ptr as usize }, 24usize, concat!( @@ -2161,8 +2285,10 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).dcb_rx_conf - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dcb_rx_conf) as usize - ptr as usize }, 1064usize, concat!( @@ -2174,8 +2300,10 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).vmdq_rx_conf - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).vmdq_rx_conf) as usize - ptr as usize }, 1080usize, concat!( @@ -2222,8 +2350,11 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())) - .vmdq_dcb_tx_conf as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).vmdq_dcb_tx_conf) as usize - + ptr as usize }, 0usize, concat!( @@ -2235,8 +2366,10 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).dcb_tx_conf - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dcb_tx_conf) as usize - ptr as usize }, 0usize, concat!( @@ -2248,8 +2381,10 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).vmdq_tx_conf - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).vmdq_tx_conf) as usize - ptr as usize }, 0usize, concat!( @@ -2279,8 +2414,9 @@ fn bindgen_test_layout_rte_eth_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).link_speeds as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).link_speeds) as usize - ptr as usize }, 0usize, concat!( @@ -2292,7 +2428,9 @@ fn bindgen_test_layout_rte_eth_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).rxmode as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rxmode) as usize - ptr as usize }, 4usize, concat!( @@ -2304,7 +2442,9 @@ fn bindgen_test_layout_rte_eth_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).txmode as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).txmode) as usize - ptr as usize }, 16usize, concat!( @@ -2316,8 +2456,9 @@ fn bindgen_test_layout_rte_eth_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).lpbk_mode as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).lpbk_mode) as usize - ptr as usize }, 24usize, concat!( @@ -2329,8 +2470,9 @@ fn bindgen_test_layout_rte_eth_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).rx_adv_conf as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rx_adv_conf) as usize - ptr as usize }, 32usize, concat!( @@ -2342,8 +2484,9 @@ fn bindgen_test_layout_rte_eth_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).tx_adv_conf as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tx_adv_conf) as usize - ptr as usize }, 2152usize, concat!( @@ -2355,8 +2498,10 @@ fn bindgen_test_layout_rte_eth_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).dcb_capability_en - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dcb_capability_en) as usize - + ptr as usize }, 2164usize, concat!( @@ -2368,8 +2513,9 @@ fn bindgen_test_layout_rte_eth_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).fdir_conf as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).fdir_conf) as usize - ptr as usize }, 2168usize, concat!( @@ -2381,8 +2527,9 @@ fn bindgen_test_layout_rte_eth_conf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).intr_conf as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).intr_conf) as usize - ptr as usize }, 2940usize, concat!( diff --git a/tests/expectations/tests/layout_kni_mbuf.rs b/tests/expectations/tests/layout_kni_mbuf.rs index e73344c7d0..f277d86d97 100644 --- a/tests/expectations/tests/layout_kni_mbuf.rs +++ b/tests/expectations/tests/layout_kni_mbuf.rs @@ -46,8 +46,9 @@ fn bindgen_test_layout_rte_kni_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).buf_addr as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).buf_addr) as usize - ptr as usize }, 0usize, concat!( @@ -59,8 +60,9 @@ fn bindgen_test_layout_rte_kni_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).buf_physaddr as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).buf_physaddr) as usize - ptr as usize }, 8usize, concat!( @@ -72,7 +74,9 @@ fn bindgen_test_layout_rte_kni_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).pad0 as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pad0) as usize - ptr as usize }, 16usize, concat!( @@ -84,8 +88,9 @@ fn bindgen_test_layout_rte_kni_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).data_off as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).data_off) as usize - ptr as usize }, 18usize, concat!( @@ -97,7 +102,9 @@ fn bindgen_test_layout_rte_kni_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).pad1 as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pad1) as usize - ptr as usize }, 20usize, concat!( @@ -109,8 +116,9 @@ fn bindgen_test_layout_rte_kni_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).nb_segs as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_segs) as usize - ptr as usize }, 22usize, concat!( @@ -122,7 +130,9 @@ fn bindgen_test_layout_rte_kni_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).pad4 as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pad4) as usize - ptr as usize }, 23usize, concat!( @@ -134,8 +144,9 @@ fn bindgen_test_layout_rte_kni_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).ol_flags as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ol_flags) as usize - ptr as usize }, 24usize, concat!( @@ -147,7 +158,9 @@ fn bindgen_test_layout_rte_kni_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).pad2 as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pad2) as usize - ptr as usize }, 32usize, concat!( @@ -159,8 +172,9 @@ fn bindgen_test_layout_rte_kni_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).pkt_len as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pkt_len) as usize - ptr as usize }, 36usize, concat!( @@ -172,8 +186,9 @@ fn bindgen_test_layout_rte_kni_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).data_len as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).data_len) as usize - ptr as usize }, 40usize, concat!( @@ -185,7 +200,9 @@ fn bindgen_test_layout_rte_kni_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).pad3 as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pad3) as usize - ptr as usize }, 64usize, concat!( @@ -197,7 +214,9 @@ fn bindgen_test_layout_rte_kni_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).pool as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pool) as usize - ptr as usize }, 72usize, concat!( @@ -209,7 +228,9 @@ fn bindgen_test_layout_rte_kni_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).next as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize }, 80usize, concat!( diff --git a/tests/expectations/tests/layout_large_align_field.rs b/tests/expectations/tests/layout_large_align_field.rs index 4208e7259c..4461408972 100644 --- a/tests/expectations/tests/layout_large_align_field.rs +++ b/tests/expectations/tests/layout_large_align_field.rs @@ -76,7 +76,11 @@ fn bindgen_test_layout_ip_frag() { concat!("Alignment of ", stringify!(ip_frag)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).ofs as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ofs) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", @@ -86,7 +90,11 @@ fn bindgen_test_layout_ip_frag() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).len as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize + }, 2usize, concat!( "Offset of field: ", @@ -96,7 +104,11 @@ fn bindgen_test_layout_ip_frag() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).mb as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mb) as usize - ptr as usize + }, 8usize, concat!( "Offset of field: ", @@ -140,7 +152,9 @@ fn bindgen_test_layout_ip_frag_key() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).src_dst as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).src_dst) as usize - ptr as usize }, 0usize, concat!( @@ -152,7 +166,9 @@ fn bindgen_test_layout_ip_frag_key() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).id as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).id) as usize - ptr as usize }, 32usize, concat!( @@ -164,7 +180,9 @@ fn bindgen_test_layout_ip_frag_key() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).key_len as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).key_len) as usize - ptr as usize }, 36usize, concat!( @@ -216,8 +234,10 @@ fn bindgen_test_layout_ip_frag_pkt__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).tqe_next - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tqe_next) as usize - ptr as usize }, 0usize, concat!( @@ -229,8 +249,10 @@ fn bindgen_test_layout_ip_frag_pkt__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).tqe_prev - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tqe_prev) as usize - ptr as usize }, 8usize, concat!( @@ -264,7 +286,9 @@ fn bindgen_test_layout_ip_frag_pkt() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).lru as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).lru) as usize - ptr as usize }, 0usize, concat!( @@ -276,7 +300,9 @@ fn bindgen_test_layout_ip_frag_pkt() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).key as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).key) as usize - ptr as usize }, 16usize, concat!( @@ -288,7 +314,9 @@ fn bindgen_test_layout_ip_frag_pkt() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).start as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).start) as usize - ptr as usize }, 56usize, concat!( @@ -300,8 +328,9 @@ fn bindgen_test_layout_ip_frag_pkt() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).total_size as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).total_size) as usize - ptr as usize }, 64usize, concat!( @@ -313,8 +342,9 @@ fn bindgen_test_layout_ip_frag_pkt() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).frag_size as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).frag_size) as usize - ptr as usize }, 68usize, concat!( @@ -326,8 +356,9 @@ fn bindgen_test_layout_ip_frag_pkt() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).last_idx as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).last_idx) as usize - ptr as usize }, 72usize, concat!( @@ -339,7 +370,9 @@ fn bindgen_test_layout_ip_frag_pkt() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).frags as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).frags) as usize - ptr as usize }, 80usize, concat!( @@ -379,8 +412,9 @@ fn bindgen_test_layout_ip_pkt_list() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).tqh_first as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tqh_first) as usize - ptr as usize }, 0usize, concat!( @@ -392,8 +426,9 @@ fn bindgen_test_layout_ip_pkt_list() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).tqh_last as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tqh_last) as usize - ptr as usize }, 8usize, concat!( @@ -445,8 +480,9 @@ fn bindgen_test_layout_ip_frag_tbl_stat() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).find_num as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).find_num) as usize - ptr as usize }, 0usize, concat!( @@ -458,8 +494,9 @@ fn bindgen_test_layout_ip_frag_tbl_stat() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).add_num as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).add_num) as usize - ptr as usize }, 8usize, concat!( @@ -471,8 +508,9 @@ fn bindgen_test_layout_ip_frag_tbl_stat() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).del_num as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).del_num) as usize - ptr as usize }, 16usize, concat!( @@ -484,8 +522,9 @@ fn bindgen_test_layout_ip_frag_tbl_stat() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).reuse_num as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).reuse_num) as usize - ptr as usize }, 24usize, concat!( @@ -497,8 +536,9 @@ fn bindgen_test_layout_ip_frag_tbl_stat() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).fail_total as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).fail_total) as usize - ptr as usize }, 32usize, concat!( @@ -510,8 +550,9 @@ fn bindgen_test_layout_ip_frag_tbl_stat() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).fail_nospace - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).fail_nospace) as usize - ptr as usize }, 40usize, concat!( @@ -573,8 +614,9 @@ fn bindgen_test_layout_rte_ip_frag_tbl() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).max_cycles as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).max_cycles) as usize - ptr as usize }, 0usize, concat!( @@ -586,8 +628,9 @@ fn bindgen_test_layout_rte_ip_frag_tbl() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).entry_mask as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).entry_mask) as usize - ptr as usize }, 8usize, concat!( @@ -599,8 +642,9 @@ fn bindgen_test_layout_rte_ip_frag_tbl() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).max_entries as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).max_entries) as usize - ptr as usize }, 12usize, concat!( @@ -612,8 +656,9 @@ fn bindgen_test_layout_rte_ip_frag_tbl() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).use_entries as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).use_entries) as usize - ptr as usize }, 16usize, concat!( @@ -625,8 +670,9 @@ fn bindgen_test_layout_rte_ip_frag_tbl() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).bucket_entries - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bucket_entries) as usize - ptr as usize }, 20usize, concat!( @@ -638,8 +684,9 @@ fn bindgen_test_layout_rte_ip_frag_tbl() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).nb_entries as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_entries) as usize - ptr as usize }, 24usize, concat!( @@ -651,8 +698,9 @@ fn bindgen_test_layout_rte_ip_frag_tbl() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).nb_buckets as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_buckets) as usize - ptr as usize }, 28usize, concat!( @@ -664,8 +712,9 @@ fn bindgen_test_layout_rte_ip_frag_tbl() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).last as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).last) as usize - ptr as usize }, 32usize, concat!( @@ -677,7 +726,9 @@ fn bindgen_test_layout_rte_ip_frag_tbl() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).lru as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).lru) as usize - ptr as usize }, 40usize, concat!( @@ -689,8 +740,9 @@ fn bindgen_test_layout_rte_ip_frag_tbl() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).stat as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).stat) as usize - ptr as usize }, 64usize, concat!( @@ -702,7 +754,9 @@ fn bindgen_test_layout_rte_ip_frag_tbl() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).pkt as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pkt) as usize - ptr as usize }, 128usize, concat!( diff --git a/tests/expectations/tests/layout_mbuf.rs b/tests/expectations/tests/layout_mbuf.rs index aefce3d6e3..cf7a0e26d1 100644 --- a/tests/expectations/tests/layout_mbuf.rs +++ b/tests/expectations/tests/layout_mbuf.rs @@ -118,7 +118,9 @@ fn bindgen_test_layout_rte_atomic16_t() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).cnt as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).cnt) as usize - ptr as usize }, 0usize, concat!( @@ -204,8 +206,10 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).refcnt_atomic - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).refcnt_atomic) as usize - ptr as usize }, 0usize, concat!( @@ -217,8 +221,10 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).refcnt - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).refcnt) as usize - ptr as usize }, 0usize, concat!( @@ -423,8 +429,10 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).packet_type - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).packet_type) as usize - ptr as usize }, 0usize, concat!( @@ -480,8 +488,8 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindg ) { assert_eq ! (:: std :: mem :: size_of :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > () , 4usize , concat ! ("Size of: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1))); assert_eq ! (:: std :: mem :: align_of :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > () , 2usize , concat ! ("Alignment of " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1))); - assert_eq ! (unsafe { & (* (:: std :: ptr :: null :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > ())) . hash as * const _ as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (hash))); - assert_eq ! (unsafe { & (* (:: std :: ptr :: null :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > ())) . id as * const _ as usize } , 2usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (id))); + assert_eq ! (unsafe { let uninit = :: std :: mem :: MaybeUninit :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > :: uninit () ; let ptr = uninit . as_ptr () ; :: std :: ptr :: addr_of ! ((* ptr) . hash) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (hash))); + assert_eq ! (unsafe { let uninit = :: std :: mem :: MaybeUninit :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > :: uninit () ; let ptr = uninit . as_ptr () ; :: std :: ptr :: addr_of ! ((* ptr) . id) as usize - ptr as usize } , 2usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (id))); } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1() { @@ -506,10 +514,11 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::< + let uninit = ::std::mem::MaybeUninit::< rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1, - >())) - .lo as *const _ as usize + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).lo) as usize - ptr as usize }, 0usize, concat!( @@ -549,8 +558,11 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).hi - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + rte_mbuf__bindgen_ty_3__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).hi) as usize - ptr as usize }, 4usize, concat!( @@ -596,8 +608,11 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).lo - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + rte_mbuf__bindgen_ty_3__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).lo) as usize - ptr as usize }, 0usize, concat!( @@ -609,8 +624,11 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).hi - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + rte_mbuf__bindgen_ty_3__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).hi) as usize - ptr as usize }, 4usize, concat!( @@ -635,8 +653,10 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).rss as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rss) as usize - ptr as usize }, 0usize, concat!( @@ -648,8 +668,10 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).fdir as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).fdir) as usize - ptr as usize }, 0usize, concat!( @@ -661,8 +683,10 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).sched as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).sched) as usize - ptr as usize }, 0usize, concat!( @@ -674,8 +698,10 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).usr as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).usr) as usize - ptr as usize }, 0usize, concat!( @@ -717,8 +743,10 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_4() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).userdata - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).userdata) as usize - ptr as usize }, 0usize, concat!( @@ -730,8 +758,10 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_4() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).udata64 - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).udata64) as usize - ptr as usize }, 0usize, concat!( @@ -917,8 +947,10 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_5() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).tx_offload - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tx_offload) as usize - ptr as usize }, 0usize, concat!( @@ -952,7 +984,9 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).cacheline0 as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).cacheline0) as usize - ptr as usize }, 0usize, concat!( @@ -964,7 +998,9 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).buf_addr as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).buf_addr) as usize - ptr as usize }, 0usize, concat!( @@ -976,8 +1012,9 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).buf_physaddr as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).buf_physaddr) as usize - ptr as usize }, 8usize, concat!( @@ -989,7 +1026,9 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).buf_len as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).buf_len) as usize - ptr as usize }, 16usize, concat!( @@ -1001,7 +1040,9 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).rearm_data as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rearm_data) as usize - ptr as usize }, 18usize, concat!( @@ -1013,7 +1054,9 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).data_off as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).data_off) as usize - ptr as usize }, 18usize, concat!( @@ -1025,7 +1068,9 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).nb_segs as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_segs) as usize - ptr as usize }, 22usize, concat!( @@ -1037,7 +1082,9 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).port as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).port) as usize - ptr as usize }, 23usize, concat!( @@ -1049,7 +1096,9 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).ol_flags as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ol_flags) as usize - ptr as usize }, 24usize, concat!( @@ -1061,8 +1110,10 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).rx_descriptor_fields1 - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rx_descriptor_fields1) as usize - + ptr as usize }, 32usize, concat!( @@ -1074,7 +1125,9 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).pkt_len as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pkt_len) as usize - ptr as usize }, 36usize, concat!( @@ -1086,7 +1139,9 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).data_len as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).data_len) as usize - ptr as usize }, 40usize, concat!( @@ -1098,7 +1153,9 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).vlan_tci as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).vlan_tci) as usize - ptr as usize }, 42usize, concat!( @@ -1110,7 +1167,9 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).hash as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).hash) as usize - ptr as usize }, 44usize, concat!( @@ -1122,7 +1181,9 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).seqn as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).seqn) as usize - ptr as usize }, 52usize, concat!( @@ -1134,8 +1195,9 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).vlan_tci_outer as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).vlan_tci_outer) as usize - ptr as usize }, 56usize, concat!( @@ -1147,7 +1209,9 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).cacheline1 as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).cacheline1) as usize - ptr as usize }, 64usize, concat!( @@ -1159,7 +1223,9 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).pool as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pool) as usize - ptr as usize }, 72usize, concat!( @@ -1171,7 +1237,9 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).next as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize }, 80usize, concat!( @@ -1183,7 +1251,9 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).priv_size as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).priv_size) as usize - ptr as usize }, 96usize, concat!( @@ -1195,7 +1265,9 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).timesync as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).timesync) as usize - ptr as usize }, 98usize, concat!( diff --git a/tests/expectations/tests/layout_mbuf_1_0.rs b/tests/expectations/tests/layout_mbuf_1_0.rs index ce4c66c2f0..0dbcf8e942 100644 --- a/tests/expectations/tests/layout_mbuf_1_0.rs +++ b/tests/expectations/tests/layout_mbuf_1_0.rs @@ -161,7 +161,9 @@ fn bindgen_test_layout_rte_atomic16_t() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).cnt as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).cnt) as usize - ptr as usize }, 0usize, concat!( @@ -253,8 +255,10 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).refcnt_atomic - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).refcnt_atomic) as usize - ptr as usize }, 0usize, concat!( @@ -266,8 +270,10 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).refcnt - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).refcnt) as usize - ptr as usize }, 0usize, concat!( @@ -475,8 +481,10 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).packet_type - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).packet_type) as usize - ptr as usize }, 0usize, concat!( @@ -531,8 +539,8 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindg ) { assert_eq ! (:: std :: mem :: size_of :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > () , 4usize , concat ! ("Size of: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1))); assert_eq ! (:: std :: mem :: align_of :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > () , 2usize , concat ! ("Alignment of " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1))); - assert_eq ! (unsafe { & (* (:: std :: ptr :: null :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > ())) . hash as * const _ as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (hash))); - assert_eq ! (unsafe { & (* (:: std :: ptr :: null :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > ())) . id as * const _ as usize } , 2usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (id))); + assert_eq ! (unsafe { let uninit = :: std :: mem :: MaybeUninit :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > :: uninit () ; let ptr = uninit . as_ptr () ; :: std :: ptr :: addr_of ! ((* ptr) . hash) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (hash))); + assert_eq ! (unsafe { let uninit = :: std :: mem :: MaybeUninit :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > :: uninit () ; let ptr = uninit . as_ptr () ; :: std :: ptr :: addr_of ! ((* ptr) . id) as usize - ptr as usize } , 2usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (id))); } impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 @@ -564,10 +572,11 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::< + let uninit = ::std::mem::MaybeUninit::< rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1, - >())) - .lo as *const _ as usize + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).lo) as usize - ptr as usize }, 0usize, concat!( @@ -603,8 +612,11 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).hi - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + rte_mbuf__bindgen_ty_3__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).hi) as usize - ptr as usize }, 4usize, concat!( @@ -646,8 +658,11 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).lo - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + rte_mbuf__bindgen_ty_3__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).lo) as usize - ptr as usize }, 0usize, concat!( @@ -659,8 +674,11 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).hi - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + rte_mbuf__bindgen_ty_3__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).hi) as usize - ptr as usize }, 4usize, concat!( @@ -690,8 +708,10 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).rss as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rss) as usize - ptr as usize }, 0usize, concat!( @@ -703,8 +723,10 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).fdir as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).fdir) as usize - ptr as usize }, 0usize, concat!( @@ -716,8 +738,10 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).sched as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).sched) as usize - ptr as usize }, 0usize, concat!( @@ -729,8 +753,10 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).usr as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).usr) as usize - ptr as usize }, 0usize, concat!( @@ -769,8 +795,10 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_4() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).userdata - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).userdata) as usize - ptr as usize }, 0usize, concat!( @@ -782,8 +810,10 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_4() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).udata64 - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).udata64) as usize - ptr as usize }, 0usize, concat!( @@ -972,8 +1002,10 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_5() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).tx_offload - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tx_offload) as usize - ptr as usize }, 0usize, concat!( @@ -998,7 +1030,9 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).cacheline0 as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).cacheline0) as usize - ptr as usize }, 0usize, concat!( @@ -1010,7 +1044,9 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).buf_addr as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).buf_addr) as usize - ptr as usize }, 0usize, concat!( @@ -1022,8 +1058,9 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).buf_physaddr as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).buf_physaddr) as usize - ptr as usize }, 8usize, concat!( @@ -1035,7 +1072,9 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).buf_len as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).buf_len) as usize - ptr as usize }, 16usize, concat!( @@ -1047,7 +1086,9 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).rearm_data as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rearm_data) as usize - ptr as usize }, 18usize, concat!( @@ -1059,7 +1100,9 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).data_off as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).data_off) as usize - ptr as usize }, 18usize, concat!( @@ -1071,7 +1114,9 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).nb_segs as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_segs) as usize - ptr as usize }, 22usize, concat!( @@ -1083,7 +1128,9 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).port as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).port) as usize - ptr as usize }, 23usize, concat!( @@ -1095,7 +1142,9 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).ol_flags as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ol_flags) as usize - ptr as usize }, 24usize, concat!( @@ -1107,8 +1156,10 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).rx_descriptor_fields1 - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rx_descriptor_fields1) as usize - + ptr as usize }, 32usize, concat!( @@ -1120,7 +1171,9 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).pkt_len as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pkt_len) as usize - ptr as usize }, 36usize, concat!( @@ -1132,7 +1185,9 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).data_len as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).data_len) as usize - ptr as usize }, 40usize, concat!( @@ -1144,7 +1199,9 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).vlan_tci as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).vlan_tci) as usize - ptr as usize }, 42usize, concat!( @@ -1156,7 +1213,9 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).hash as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).hash) as usize - ptr as usize }, 44usize, concat!( @@ -1168,7 +1227,9 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).seqn as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).seqn) as usize - ptr as usize }, 52usize, concat!( @@ -1180,8 +1241,9 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).vlan_tci_outer as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).vlan_tci_outer) as usize - ptr as usize }, 56usize, concat!( @@ -1193,7 +1255,9 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).cacheline1 as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).cacheline1) as usize - ptr as usize }, 64usize, concat!( @@ -1205,7 +1269,9 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).pool as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pool) as usize - ptr as usize }, 72usize, concat!( @@ -1217,7 +1283,9 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).next as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize }, 80usize, concat!( @@ -1229,7 +1297,9 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).priv_size as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).priv_size) as usize - ptr as usize }, 96usize, concat!( @@ -1241,7 +1311,9 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).timesync as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).timesync) as usize - ptr as usize }, 98usize, concat!( diff --git a/tests/expectations/tests/libclang-5/call-conv-field.rs b/tests/expectations/tests/libclang-5/call-conv-field.rs index f134bd8a46..c8060c9d0b 100644 --- a/tests/expectations/tests/libclang-5/call-conv-field.rs +++ b/tests/expectations/tests/libclang-5/call-conv-field.rs @@ -30,8 +30,10 @@ fn bindgen_test_layout_JNINativeInterface_() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).GetVersion - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).GetVersion) as usize - ptr as usize }, 0usize, concat!( @@ -43,8 +45,10 @@ fn bindgen_test_layout_JNINativeInterface_() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).__hack as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).__hack) as usize - ptr as usize }, 8usize, concat!( diff --git a/tests/expectations/tests/libclang-5/type_alias_template_specialized.rs b/tests/expectations/tests/libclang-5/type_alias_template_specialized.rs index f874e9d221..16bd02e44c 100644 --- a/tests/expectations/tests/libclang-5/type_alias_template_specialized.rs +++ b/tests/expectations/tests/libclang-5/type_alias_template_specialized.rs @@ -23,7 +23,11 @@ fn bindgen_test_layout_Rooted() { concat!("Alignment of ", stringify!(Rooted)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).ptr as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/libclang-9/call-conv-field.rs b/tests/expectations/tests/libclang-9/call-conv-field.rs index f134bd8a46..c8060c9d0b 100644 --- a/tests/expectations/tests/libclang-9/call-conv-field.rs +++ b/tests/expectations/tests/libclang-9/call-conv-field.rs @@ -30,8 +30,10 @@ fn bindgen_test_layout_JNINativeInterface_() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).GetVersion - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).GetVersion) as usize - ptr as usize }, 0usize, concat!( @@ -43,8 +45,10 @@ fn bindgen_test_layout_JNINativeInterface_() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).__hack as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).__hack) as usize - ptr as usize }, 8usize, concat!( diff --git a/tests/expectations/tests/libclang-9/class.rs b/tests/expectations/tests/libclang-9/class.rs index e4527de0e2..117cc815b8 100644 --- a/tests/expectations/tests/libclang-9/class.rs +++ b/tests/expectations/tests/libclang-9/class.rs @@ -54,12 +54,20 @@ fn bindgen_test_layout_C() { concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(a)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).big_array as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize + }, 4usize, concat!( "Offset of field: ", @@ -98,8 +106,10 @@ fn bindgen_test_layout_C_with_zero_length_array() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( @@ -111,8 +121,10 @@ fn bindgen_test_layout_C_with_zero_length_array() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).big_array - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, 4usize, concat!( @@ -124,8 +136,11 @@ fn bindgen_test_layout_C_with_zero_length_array() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())) - .zero_length_array as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - + ptr as usize }, 37usize, concat!( @@ -165,8 +180,10 @@ fn bindgen_test_layout_C_with_zero_length_array_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( @@ -178,8 +195,11 @@ fn bindgen_test_layout_C_with_zero_length_array_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())) - .zero_length_array as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - + ptr as usize }, 4usize, concat!( @@ -210,8 +230,10 @@ fn bindgen_test_layout_C_with_incomplete_array() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( @@ -223,8 +245,10 @@ fn bindgen_test_layout_C_with_incomplete_array() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).big_array - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, 4usize, concat!( @@ -236,8 +260,11 @@ fn bindgen_test_layout_C_with_incomplete_array() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).incomplete_array - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - + ptr as usize }, 37usize, concat!( @@ -277,8 +304,10 @@ fn bindgen_test_layout_C_with_incomplete_array_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( @@ -290,8 +319,11 @@ fn bindgen_test_layout_C_with_incomplete_array_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())) - .incomplete_array as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - + ptr as usize }, 4usize, concat!( @@ -329,10 +361,11 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::< + let uninit = ::std::mem::MaybeUninit::< C_with_zero_length_array_and_incomplete_array, - >())) - .a as *const _ as usize + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( @@ -344,10 +377,11 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::< + let uninit = ::std::mem::MaybeUninit::< C_with_zero_length_array_and_incomplete_array, - >())) - .big_array as *const _ as usize + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, 4usize, concat!( @@ -359,10 +393,12 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::< + let uninit = ::std::mem::MaybeUninit::< C_with_zero_length_array_and_incomplete_array, - >())) - .zero_length_array as *const _ as usize + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - + ptr as usize }, 37usize, concat!( @@ -374,10 +410,12 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::< + let uninit = ::std::mem::MaybeUninit::< C_with_zero_length_array_and_incomplete_array, - >())) - .incomplete_array as *const _ as usize + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - + ptr as usize }, 37usize, concat!( @@ -426,10 +464,11 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::< + let uninit = ::std::mem::MaybeUninit::< C_with_zero_length_array_and_incomplete_array_2, - >())) - .a as *const _ as usize + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( @@ -441,10 +480,12 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::< + let uninit = ::std::mem::MaybeUninit::< C_with_zero_length_array_and_incomplete_array_2, - >())) - .zero_length_array as *const _ as usize + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - + ptr as usize }, 4usize, concat!( @@ -456,10 +497,12 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::< + let uninit = ::std::mem::MaybeUninit::< C_with_zero_length_array_and_incomplete_array_2, - >())) - .incomplete_array as *const _ as usize + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - + ptr as usize }, 4usize, concat!( @@ -488,7 +531,11 @@ fn bindgen_test_layout_WithDtor() { concat!("Alignment of ", stringify!(WithDtor)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).b as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", @@ -517,8 +564,10 @@ fn bindgen_test_layout_IncompleteArrayNonCopiable() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).whatever - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).whatever) as usize - ptr as usize }, 0usize, concat!( @@ -530,8 +579,11 @@ fn bindgen_test_layout_IncompleteArrayNonCopiable() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())) - .incomplete_array as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - + ptr as usize }, 8usize, concat!( @@ -570,12 +622,20 @@ fn bindgen_test_layout_Union() { concat!("Alignment of ", stringify!(Union)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).d as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(Union), "::", stringify!(d)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).i as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(Union), "::", stringify!(i)) ); @@ -608,7 +668,9 @@ fn bindgen_test_layout_WithUnion() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).data as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/libclang-9/class_1_0.rs b/tests/expectations/tests/libclang-9/class_1_0.rs index 4263bd144c..0a707d228f 100644 --- a/tests/expectations/tests/libclang-9/class_1_0.rs +++ b/tests/expectations/tests/libclang-9/class_1_0.rs @@ -97,12 +97,20 @@ fn bindgen_test_layout_C() { concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(a)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).big_array as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize + }, 4usize, concat!( "Offset of field: ", @@ -151,8 +159,10 @@ fn bindgen_test_layout_C_with_zero_length_array() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( @@ -164,8 +174,10 @@ fn bindgen_test_layout_C_with_zero_length_array() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).big_array - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, 4usize, concat!( @@ -177,8 +189,11 @@ fn bindgen_test_layout_C_with_zero_length_array() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())) - .zero_length_array as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - + ptr as usize }, 37usize, concat!( @@ -218,8 +233,10 @@ fn bindgen_test_layout_C_with_zero_length_array_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( @@ -231,8 +248,11 @@ fn bindgen_test_layout_C_with_zero_length_array_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())) - .zero_length_array as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - + ptr as usize }, 4usize, concat!( @@ -263,8 +283,10 @@ fn bindgen_test_layout_C_with_incomplete_array() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( @@ -276,8 +298,10 @@ fn bindgen_test_layout_C_with_incomplete_array() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).big_array - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, 4usize, concat!( @@ -289,8 +313,11 @@ fn bindgen_test_layout_C_with_incomplete_array() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).incomplete_array - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - + ptr as usize }, 37usize, concat!( @@ -330,8 +357,10 @@ fn bindgen_test_layout_C_with_incomplete_array_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( @@ -343,8 +372,11 @@ fn bindgen_test_layout_C_with_incomplete_array_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())) - .incomplete_array as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - + ptr as usize }, 4usize, concat!( @@ -382,10 +414,11 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::< + let uninit = ::std::mem::MaybeUninit::< C_with_zero_length_array_and_incomplete_array, - >())) - .a as *const _ as usize + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( @@ -397,10 +430,11 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::< + let uninit = ::std::mem::MaybeUninit::< C_with_zero_length_array_and_incomplete_array, - >())) - .big_array as *const _ as usize + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, 4usize, concat!( @@ -412,10 +446,12 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::< + let uninit = ::std::mem::MaybeUninit::< C_with_zero_length_array_and_incomplete_array, - >())) - .zero_length_array as *const _ as usize + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - + ptr as usize }, 37usize, concat!( @@ -427,10 +463,12 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::< + let uninit = ::std::mem::MaybeUninit::< C_with_zero_length_array_and_incomplete_array, - >())) - .incomplete_array as *const _ as usize + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - + ptr as usize }, 37usize, concat!( @@ -479,10 +517,11 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::< + let uninit = ::std::mem::MaybeUninit::< C_with_zero_length_array_and_incomplete_array_2, - >())) - .a as *const _ as usize + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( @@ -494,10 +533,12 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::< + let uninit = ::std::mem::MaybeUninit::< C_with_zero_length_array_and_incomplete_array_2, - >())) - .zero_length_array as *const _ as usize + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - + ptr as usize }, 4usize, concat!( @@ -509,10 +550,12 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::< + let uninit = ::std::mem::MaybeUninit::< C_with_zero_length_array_and_incomplete_array_2, - >())) - .incomplete_array as *const _ as usize + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - + ptr as usize }, 4usize, concat!( @@ -541,7 +584,11 @@ fn bindgen_test_layout_WithDtor() { concat!("Alignment of ", stringify!(WithDtor)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).b as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", @@ -570,8 +617,10 @@ fn bindgen_test_layout_IncompleteArrayNonCopiable() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).whatever - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).whatever) as usize - ptr as usize }, 0usize, concat!( @@ -583,8 +632,11 @@ fn bindgen_test_layout_IncompleteArrayNonCopiable() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())) - .incomplete_array as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - + ptr as usize }, 8usize, concat!( @@ -624,12 +676,20 @@ fn bindgen_test_layout_Union() { concat!("Alignment of ", stringify!(Union)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).d as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(Union), "::", stringify!(d)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).i as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(Union), "::", stringify!(i)) ); @@ -658,7 +718,9 @@ fn bindgen_test_layout_WithUnion() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).data as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs b/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs index 32607b375f..42de2d7748 100644 --- a/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs +++ b/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs @@ -54,14 +54,20 @@ fn bindgen_test_layout_test() { concat!("Alignment of ", stringify!(test)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(test), "::", stringify!(a)) ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).zero_length_array as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - + ptr as usize }, 4usize, concat!( @@ -91,14 +97,20 @@ fn bindgen_test_layout_test2() { concat!("Alignment of ", stringify!(test2)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(test2), "::", stringify!(a)) ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).incomplete_array as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - + ptr as usize }, 4usize, concat!( @@ -129,14 +141,20 @@ fn bindgen_test_layout_test3() { concat!("Alignment of ", stringify!(test3)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(test3), "::", stringify!(a)) ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).zero_length_array as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - + ptr as usize }, 4usize, concat!( @@ -148,8 +166,10 @@ fn bindgen_test_layout_test3() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).incomplete_array as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - + ptr as usize }, 4usize, concat!( diff --git a/tests/expectations/tests/libclang-9/incomplete-array-padding.rs b/tests/expectations/tests/libclang-9/incomplete-array-padding.rs index 382195dbb9..ba1f9ce05d 100644 --- a/tests/expectations/tests/libclang-9/incomplete-array-padding.rs +++ b/tests/expectations/tests/libclang-9/incomplete-array-padding.rs @@ -141,7 +141,11 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).b as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, 8usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) ); diff --git a/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs b/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs index 49664cdd5e..91c3771129 100644 --- a/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs +++ b/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs @@ -62,8 +62,9 @@ fn bindgen_test_layout_rte_ring_prod() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).watermark as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).watermark) as usize - ptr as usize }, 0usize, concat!( @@ -93,8 +94,9 @@ fn bindgen_test_layout_rte_ring_cons() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).sc_dequeue as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).sc_dequeue) as usize - ptr as usize }, 0usize, concat!( @@ -119,7 +121,9 @@ fn bindgen_test_layout_rte_ring() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).memzone as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).memzone) as usize - ptr as usize }, 0usize, concat!( @@ -131,7 +135,9 @@ fn bindgen_test_layout_rte_ring() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).prod as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).prod) as usize - ptr as usize }, 8usize, concat!( @@ -143,7 +149,9 @@ fn bindgen_test_layout_rte_ring() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).cons as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).cons) as usize - ptr as usize }, 12usize, concat!( @@ -155,7 +163,9 @@ fn bindgen_test_layout_rte_ring() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).ring as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ring) as usize - ptr as usize }, 16usize, concat!( diff --git a/tests/expectations/tests/libclang-9/layout_align.rs b/tests/expectations/tests/libclang-9/layout_align.rs index 4ad5417577..fa5179aeb3 100644 --- a/tests/expectations/tests/libclang-9/layout_align.rs +++ b/tests/expectations/tests/libclang-9/layout_align.rs @@ -149,7 +149,9 @@ fn bindgen_test_layout_rte_kni_fifo() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).write as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).write) as usize - ptr as usize }, 0usize, concat!( @@ -161,7 +163,9 @@ fn bindgen_test_layout_rte_kni_fifo() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).read as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).read) as usize - ptr as usize }, 4usize, concat!( @@ -173,7 +177,9 @@ fn bindgen_test_layout_rte_kni_fifo() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).len as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize }, 8usize, concat!( @@ -185,8 +191,9 @@ fn bindgen_test_layout_rte_kni_fifo() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).elem_size as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).elem_size) as usize - ptr as usize }, 12usize, concat!( @@ -198,7 +205,9 @@ fn bindgen_test_layout_rte_kni_fifo() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).buffer as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).buffer) as usize - ptr as usize }, 16usize, concat!( @@ -242,8 +251,9 @@ fn bindgen_test_layout_rte_eth_link() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).link_speed as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).link_speed) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/libclang-9/type_alias_template_specialized.rs b/tests/expectations/tests/libclang-9/type_alias_template_specialized.rs index f874e9d221..16bd02e44c 100644 --- a/tests/expectations/tests/libclang-9/type_alias_template_specialized.rs +++ b/tests/expectations/tests/libclang-9/type_alias_template_specialized.rs @@ -23,7 +23,11 @@ fn bindgen_test_layout_Rooted() { concat!("Alignment of ", stringify!(Rooted)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).ptr as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/libclang-9/zero-sized-array.rs b/tests/expectations/tests/libclang-9/zero-sized-array.rs index 6514b930c7..1c2f242ffd 100644 --- a/tests/expectations/tests/libclang-9/zero-sized-array.rs +++ b/tests/expectations/tests/libclang-9/zero-sized-array.rs @@ -55,7 +55,9 @@ fn bindgen_test_layout_ZeroSizedArray() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).arr as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize }, 0usize, concat!( @@ -86,8 +88,10 @@ fn bindgen_test_layout_ContainsZeroSizedArray() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).zsa as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).zsa) as usize - ptr as usize }, 0usize, concat!( @@ -138,8 +142,10 @@ fn bindgen_test_layout_DynamicallySizedArray() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).arr as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize }, 0usize, concat!( @@ -170,8 +176,9 @@ fn bindgen_test_layout_ContainsDynamicallySizedArray() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).dsa - as *const _ as usize + let uninit = :: std :: mem :: MaybeUninit :: < ContainsDynamicallySizedArray > :: uninit () ; + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dsa) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/long_double.rs b/tests/expectations/tests/long_double.rs index dbd4248ee5..f08438259d 100644 --- a/tests/expectations/tests/long_double.rs +++ b/tests/expectations/tests/long_double.rs @@ -24,7 +24,11 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/msvc-no-usr.rs b/tests/expectations/tests/msvc-no-usr.rs index ea5a90b871..b0ad37ca32 100644 --- a/tests/expectations/tests/msvc-no-usr.rs +++ b/tests/expectations/tests/msvc-no-usr.rs @@ -24,7 +24,11 @@ fn bindgen_test_layout_A() { concat!("Alignment of ", stringify!(A)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).foo as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(foo)) ); diff --git a/tests/expectations/tests/mutable.rs b/tests/expectations/tests/mutable.rs index 9f5865fccc..4f5d97ab9f 100644 --- a/tests/expectations/tests/mutable.rs +++ b/tests/expectations/tests/mutable.rs @@ -24,7 +24,11 @@ fn bindgen_test_layout_C() { concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).m_member as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", @@ -34,7 +38,11 @@ fn bindgen_test_layout_C() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).m_other as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).m_other) as usize - ptr as usize + }, 4usize, concat!( "Offset of field: ", @@ -63,8 +71,9 @@ fn bindgen_test_layout_NonCopiable() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).m_member as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize }, 0usize, concat!( @@ -100,8 +109,11 @@ fn bindgen_test_layout_NonCopiableWithNonCopiableMutableMember() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())) - .m_member as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + NonCopiableWithNonCopiableMutableMember, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/namespace.rs b/tests/expectations/tests/namespace.rs index 576fc9336f..33e2118fb4 100644 --- a/tests/expectations/tests/namespace.rs +++ b/tests/expectations/tests/namespace.rs @@ -44,7 +44,11 @@ pub mod root { concat!("Alignment of ", stringify!(A)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).b as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/nested.rs b/tests/expectations/tests/nested.rs index 92cd6605b4..558ccd6c13 100644 --- a/tests/expectations/tests/nested.rs +++ b/tests/expectations/tests/nested.rs @@ -23,7 +23,11 @@ fn bindgen_test_layout_Calc() { concat!("Alignment of ", stringify!(Calc)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).w as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).w) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(Calc), "::", stringify!(w)) ); @@ -71,7 +75,9 @@ fn bindgen_test_layout_Test_Size() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mWidth as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mWidth) as usize - ptr as usize }, 0usize, concat!( @@ -83,7 +89,9 @@ fn bindgen_test_layout_Test_Size() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mHeight as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mHeight) as usize - ptr as usize }, 4usize, concat!( diff --git a/tests/expectations/tests/nested_within_namespace.rs b/tests/expectations/tests/nested_within_namespace.rs index 86b9b8c68b..8bb8559f4e 100644 --- a/tests/expectations/tests/nested_within_namespace.rs +++ b/tests/expectations/tests/nested_within_namespace.rs @@ -36,7 +36,9 @@ pub mod root { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).foo as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, 0usize, concat!( @@ -61,7 +63,9 @@ pub mod root { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).foo as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, 0usize, concat!( @@ -91,7 +95,9 @@ pub mod root { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).baz as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/no-comments.rs b/tests/expectations/tests/no-comments.rs index 7a9d0d82b5..5c1cdc4387 100644 --- a/tests/expectations/tests/no-comments.rs +++ b/tests/expectations/tests/no-comments.rs @@ -23,7 +23,11 @@ fn bindgen_test_layout_Foo() { concat!("Alignment of ", stringify!(Foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).s as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).s) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(s)) ); diff --git a/tests/expectations/tests/no-derive-debug.rs b/tests/expectations/tests/no-derive-debug.rs index a62eaa5df5..ffa372c297 100644 --- a/tests/expectations/tests/no-derive-debug.rs +++ b/tests/expectations/tests/no-derive-debug.rs @@ -32,12 +32,20 @@ fn bindgen_test_layout_bar() { concat!("Alignment of ", stringify!(bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).foo as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(bar), "::", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).baz as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, 4usize, concat!("Offset of field: ", stringify!(bar), "::", stringify!(baz)) ); diff --git a/tests/expectations/tests/no-derive-default.rs b/tests/expectations/tests/no-derive-default.rs index eda13aad68..82d630f5c3 100644 --- a/tests/expectations/tests/no-derive-default.rs +++ b/tests/expectations/tests/no-derive-default.rs @@ -32,12 +32,20 @@ fn bindgen_test_layout_bar() { concat!("Alignment of ", stringify!(bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).foo as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(bar), "::", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).baz as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, 4usize, concat!("Offset of field: ", stringify!(bar), "::", stringify!(baz)) ); diff --git a/tests/expectations/tests/no-hash-allowlisted.rs b/tests/expectations/tests/no-hash-allowlisted.rs index 1cd7f672b6..f060b729f1 100644 --- a/tests/expectations/tests/no-hash-allowlisted.rs +++ b/tests/expectations/tests/no-hash-allowlisted.rs @@ -23,7 +23,11 @@ fn bindgen_test_layout_NoHash() { concat!("Alignment of ", stringify!(NoHash)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).i as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(NoHash), "::", stringify!(i)) ); diff --git a/tests/expectations/tests/no-partialeq-allowlisted.rs b/tests/expectations/tests/no-partialeq-allowlisted.rs index cd3ed3b935..758b4670be 100644 --- a/tests/expectations/tests/no-partialeq-allowlisted.rs +++ b/tests/expectations/tests/no-partialeq-allowlisted.rs @@ -24,7 +24,9 @@ fn bindgen_test_layout_NoPartialEq() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).i as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/no-recursive-allowlisting.rs b/tests/expectations/tests/no-recursive-allowlisting.rs index 0aa0b5e322..32907d6e8d 100644 --- a/tests/expectations/tests/no-recursive-allowlisting.rs +++ b/tests/expectations/tests/no-recursive-allowlisting.rs @@ -25,7 +25,11 @@ fn bindgen_test_layout_Foo() { concat!("Alignment of ", stringify!(Foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).baz as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(baz)) ); diff --git a/tests/expectations/tests/no-std.rs b/tests/expectations/tests/no-std.rs index f63ac4512b..8fa4a4e594 100644 --- a/tests/expectations/tests/no-std.rs +++ b/tests/expectations/tests/no-std.rs @@ -30,17 +30,29 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::core::ptr::null::())).a as *const _ as usize }, + unsafe { + let uninit = ::core::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::core::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) ); assert_eq!( - unsafe { &(*(::core::ptr::null::())).b as *const _ as usize }, + unsafe { + let uninit = ::core::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::core::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, 4usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) ); assert_eq!( - unsafe { &(*(::core::ptr::null::())).bar as *const _ as usize }, + unsafe { + let uninit = ::core::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, 8usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/no_copy_allowlisted.rs b/tests/expectations/tests/no_copy_allowlisted.rs index fa53bb66fe..db895e488e 100644 --- a/tests/expectations/tests/no_copy_allowlisted.rs +++ b/tests/expectations/tests/no_copy_allowlisted.rs @@ -23,7 +23,11 @@ fn bindgen_test_layout_NoCopy() { concat!("Alignment of ", stringify!(NoCopy)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).i as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(NoCopy), "::", stringify!(i)) ); diff --git a/tests/expectations/tests/no_debug_allowlisted.rs b/tests/expectations/tests/no_debug_allowlisted.rs index e240d645fb..6722fc995c 100644 --- a/tests/expectations/tests/no_debug_allowlisted.rs +++ b/tests/expectations/tests/no_debug_allowlisted.rs @@ -23,7 +23,11 @@ fn bindgen_test_layout_NoDebug() { concat!("Alignment of ", stringify!(NoDebug)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).i as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/no_default_allowlisted.rs b/tests/expectations/tests/no_default_allowlisted.rs index 980f1575f0..930c611454 100644 --- a/tests/expectations/tests/no_default_allowlisted.rs +++ b/tests/expectations/tests/no_default_allowlisted.rs @@ -23,7 +23,11 @@ fn bindgen_test_layout_NoDefault() { concat!("Alignment of ", stringify!(NoDefault)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).i as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/non-type-params.rs b/tests/expectations/tests/non-type-params.rs index acd7a09f3a..9572d69c8a 100644 --- a/tests/expectations/tests/non-type-params.rs +++ b/tests/expectations/tests/non-type-params.rs @@ -28,8 +28,9 @@ fn bindgen_test_layout_UsesArray() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).array_char_16 as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).array_char_16) as usize - ptr as usize }, 0usize, concat!( @@ -41,8 +42,9 @@ fn bindgen_test_layout_UsesArray() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).array_bool_8 as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).array_bool_8) as usize - ptr as usize }, 16usize, concat!( @@ -54,8 +56,9 @@ fn bindgen_test_layout_UsesArray() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).array_int_4 as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).array_int_4) as usize - ptr as usize }, 24usize, concat!( diff --git a/tests/expectations/tests/objc_interface_type.rs b/tests/expectations/tests/objc_interface_type.rs index 4ffb15d303..41607b7999 100644 --- a/tests/expectations/tests/objc_interface_type.rs +++ b/tests/expectations/tests/objc_interface_type.rs @@ -45,7 +45,9 @@ fn bindgen_test_layout_FooStruct() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).foo as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/opaque-template-inst-member-2.rs b/tests/expectations/tests/opaque-template-inst-member-2.rs index f47aff0552..e341c68989 100644 --- a/tests/expectations/tests/opaque-template-inst-member-2.rs +++ b/tests/expectations/tests/opaque-template-inst-member-2.rs @@ -33,8 +33,10 @@ fn bindgen_test_layout_ContainsOpaqueTemplate() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mBlah as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBlah) as usize - ptr as usize }, 0usize, concat!( @@ -46,8 +48,10 @@ fn bindgen_test_layout_ContainsOpaqueTemplate() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mBaz as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBaz) as usize - ptr as usize }, 4usize, concat!( @@ -79,8 +83,10 @@ fn bindgen_test_layout_InheritsOpaqueTemplate() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).wow as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).wow) as usize - ptr as usize }, 8usize, concat!( diff --git a/tests/expectations/tests/opaque-template-inst-member.rs b/tests/expectations/tests/opaque-template-inst-member.rs index a3c67784de..ef2b3edab7 100644 --- a/tests/expectations/tests/opaque-template-inst-member.rs +++ b/tests/expectations/tests/opaque-template-inst-member.rs @@ -31,8 +31,10 @@ fn bindgen_test_layout_ContainsOpaqueTemplate() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mBlah as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBlah) as usize - ptr as usize }, 0usize, concat!( @@ -44,8 +46,10 @@ fn bindgen_test_layout_ContainsOpaqueTemplate() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mBaz as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBaz) as usize - ptr as usize }, 404usize, concat!( @@ -91,8 +95,10 @@ fn bindgen_test_layout_InheritsOpaqueTemplate() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).wow as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).wow) as usize - ptr as usize }, 408usize, concat!( diff --git a/tests/expectations/tests/opaque-template-instantiation-namespaced.rs b/tests/expectations/tests/opaque-template-instantiation-namespaced.rs index e972443ed3..fa1ed3b839 100644 --- a/tests/expectations/tests/opaque-template-instantiation-namespaced.rs +++ b/tests/expectations/tests/opaque-template-instantiation-namespaced.rs @@ -47,7 +47,9 @@ pub mod root { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).c as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, 0usize, concat!( @@ -77,7 +79,9 @@ pub mod root { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).i as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, 0usize, concat!( @@ -107,8 +111,10 @@ pub mod root { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).not_opaque - as *const _ as usize + let uninit = :: std :: mem :: MaybeUninit :: < ContainsInstantiation > :: uninit () ; + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).not_opaque) as usize - + ptr as usize }, 0usize, concat!( @@ -150,8 +156,11 @@ pub mod root { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())) - .opaque as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + ContainsOpaqueInstantiation, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).opaque) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/opaque-template-instantiation.rs b/tests/expectations/tests/opaque-template-instantiation.rs index 6f0f31b376..994e59a231 100644 --- a/tests/expectations/tests/opaque-template-instantiation.rs +++ b/tests/expectations/tests/opaque-template-instantiation.rs @@ -39,8 +39,10 @@ fn bindgen_test_layout_ContainsInstantiation() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).not_opaque - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).not_opaque) as usize - ptr as usize }, 0usize, concat!( @@ -79,8 +81,11 @@ fn bindgen_test_layout_ContainsOpaqueInstantiation() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).opaque - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).opaque) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/opaque_in_struct.rs b/tests/expectations/tests/opaque_in_struct.rs index 980df3d612..f900e5fddc 100644 --- a/tests/expectations/tests/opaque_in_struct.rs +++ b/tests/expectations/tests/opaque_in_struct.rs @@ -44,7 +44,9 @@ fn bindgen_test_layout_container() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).contained as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).contained) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/opaque_pointer.rs b/tests/expectations/tests/opaque_pointer.rs index 90b019b290..9d3af55fe5 100644 --- a/tests/expectations/tests/opaque_pointer.rs +++ b/tests/expectations/tests/opaque_pointer.rs @@ -52,8 +52,9 @@ fn bindgen_test_layout_WithOpaquePtr() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).whatever as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).whatever) as usize - ptr as usize }, 0usize, concat!( @@ -65,7 +66,9 @@ fn bindgen_test_layout_WithOpaquePtr() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).other as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).other) as usize - ptr as usize }, 8usize, concat!( @@ -77,7 +80,9 @@ fn bindgen_test_layout_WithOpaquePtr() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).t as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).t) as usize - ptr as usize }, 12usize, concat!( diff --git a/tests/expectations/tests/packed-n-with-padding.rs b/tests/expectations/tests/packed-n-with-padding.rs index 13cb030620..4039605ac4 100644 --- a/tests/expectations/tests/packed-n-with-padding.rs +++ b/tests/expectations/tests/packed-n-with-padding.rs @@ -26,22 +26,38 @@ fn bindgen_test_layout_Packed() { concat!("Alignment of ", stringify!(Packed)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(Packed), "::", stringify!(a)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).b as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, 2usize, concat!("Offset of field: ", stringify!(Packed), "::", stringify!(b)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).c as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize + }, 4usize, concat!("Offset of field: ", stringify!(Packed), "::", stringify!(c)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).d as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, 6usize, concat!("Offset of field: ", stringify!(Packed), "::", stringify!(d)) ); diff --git a/tests/expectations/tests/private.rs b/tests/expectations/tests/private.rs index 328f97f08f..568701eb21 100644 --- a/tests/expectations/tests/private.rs +++ b/tests/expectations/tests/private.rs @@ -26,8 +26,9 @@ fn bindgen_test_layout_HasPrivate() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mNotPrivate as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mNotPrivate) as usize - ptr as usize }, 0usize, concat!( @@ -39,8 +40,9 @@ fn bindgen_test_layout_HasPrivate() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mIsPrivate as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mIsPrivate) as usize - ptr as usize }, 4usize, concat!( @@ -72,8 +74,9 @@ fn bindgen_test_layout_VeryPrivate() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mIsPrivate as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mIsPrivate) as usize - ptr as usize }, 0usize, concat!( @@ -85,8 +88,9 @@ fn bindgen_test_layout_VeryPrivate() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mIsAlsoPrivate as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mIsAlsoPrivate) as usize - ptr as usize }, 4usize, concat!( @@ -119,8 +123,9 @@ fn bindgen_test_layout_ContradictPrivate() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mNotPrivate - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mNotPrivate) as usize - ptr as usize }, 0usize, concat!( @@ -132,8 +137,9 @@ fn bindgen_test_layout_ContradictPrivate() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mIsPrivate as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mIsPrivate) as usize - ptr as usize }, 4usize, concat!( diff --git a/tests/expectations/tests/private_fields.rs b/tests/expectations/tests/private_fields.rs index 92a4bf653b..887a736014 100644 --- a/tests/expectations/tests/private_fields.rs +++ b/tests/expectations/tests/private_fields.rs @@ -110,7 +110,11 @@ fn bindgen_test_layout_PubPriv() { concat!("Alignment of ", stringify!(PubPriv)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).x as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", @@ -120,7 +124,11 @@ fn bindgen_test_layout_PubPriv() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).y as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize + }, 4usize, concat!( "Offset of field: ", @@ -346,7 +354,11 @@ fn bindgen_test_layout_Base() { concat!("Alignment of ", stringify!(Base)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).member as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", @@ -417,8 +429,11 @@ fn bindgen_test_layout_WithAnonStruct__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( @@ -448,8 +463,11 @@ fn bindgen_test_layout_WithAnonStruct__bindgen_ty_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).b - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/reparented_replacement.rs b/tests/expectations/tests/reparented_replacement.rs index 1f4fa6e1b8..d04eaa25b9 100644 --- a/tests/expectations/tests/reparented_replacement.rs +++ b/tests/expectations/tests/reparented_replacement.rs @@ -32,7 +32,9 @@ pub mod root { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).bazz as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bazz) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/replace_use.rs b/tests/expectations/tests/replace_use.rs index 7bec94b8d2..ea1da9871e 100644 --- a/tests/expectations/tests/replace_use.rs +++ b/tests/expectations/tests/replace_use.rs @@ -29,7 +29,11 @@ fn bindgen_test_layout_Test() { concat!("Alignment of ", stringify!(Test)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(a)) ); diff --git a/tests/expectations/tests/repr-align.rs b/tests/expectations/tests/repr-align.rs index df2353686a..38f55428bf 100644 --- a/tests/expectations/tests/repr-align.rs +++ b/tests/expectations/tests/repr-align.rs @@ -26,12 +26,20 @@ fn bindgen_test_layout_a() { concat!("Alignment of ", stringify!(a)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).b as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(a), "::", stringify!(b)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).c as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize + }, 4usize, concat!("Offset of field: ", stringify!(a), "::", stringify!(c)) ); @@ -56,12 +64,20 @@ fn bindgen_test_layout_b() { concat!("Alignment of ", stringify!(b)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).b as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(b), "::", stringify!(b)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).c as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize + }, 4usize, concat!("Offset of field: ", stringify!(b), "::", stringify!(c)) ); diff --git a/tests/expectations/tests/same_struct_name_in_different_namespaces.rs b/tests/expectations/tests/same_struct_name_in_different_namespaces.rs index 056b671b33..91c4750aed 100644 --- a/tests/expectations/tests/same_struct_name_in_different_namespaces.rs +++ b/tests/expectations/tests/same_struct_name_in_different_namespaces.rs @@ -30,7 +30,9 @@ fn bindgen_test_layout_JS_shadow_Zone() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).x as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, 0usize, concat!( @@ -42,7 +44,9 @@ fn bindgen_test_layout_JS_shadow_Zone() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).y as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, 4usize, concat!( diff --git a/tests/expectations/tests/sentry-defined-multiple-times.rs b/tests/expectations/tests/sentry-defined-multiple-times.rs index 5f2ec54d5a..a11a72b365 100644 --- a/tests/expectations/tests/sentry-defined-multiple-times.rs +++ b/tests/expectations/tests/sentry-defined-multiple-times.rs @@ -41,8 +41,10 @@ pub mod root { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).i_am_plain_sentry - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i_am_plain_sentry) as usize - + ptr as usize }, 0usize, concat!( @@ -90,9 +92,14 @@ pub mod root { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())) - .i_am_not_template_wrapper_sentry - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + NotTemplateWrapper_sentry, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!( + (*ptr).i_am_not_template_wrapper_sentry + ) as usize - + ptr as usize }, 0usize, concat!( @@ -133,9 +140,14 @@ pub mod root { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())) - .i_am_inline_not_template_wrapper_sentry - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + InlineNotTemplateWrapper_sentry, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!( + (*ptr).i_am_inline_not_template_wrapper_sentry + ) as usize - + ptr as usize }, 0usize, concat!( @@ -240,11 +252,13 @@ pub mod root { ); assert_eq!( unsafe { - &(*(::std::ptr::null::< + let uninit = ::std::mem::MaybeUninit::< OuterDoubleWrapper_InnerDoubleWrapper_sentry, - >())) - .i_am_double_wrapper_sentry as *const _ - as usize + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i_am_double_wrapper_sentry) + as usize - + ptr as usize }, 0usize, concat!( @@ -275,7 +289,7 @@ pub mod root { ) { assert_eq ! (:: std :: mem :: size_of :: < OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry > () , 4usize , concat ! ("Size of: " , stringify ! (OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry))); assert_eq ! (:: std :: mem :: align_of :: < OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry > () , 4usize , concat ! ("Alignment of " , stringify ! (OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry))); - assert_eq ! (unsafe { & (* (:: std :: ptr :: null :: < OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry > ())) . i_am_double_wrapper_inline_sentry as * const _ as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry) , "::" , stringify ! (i_am_double_wrapper_inline_sentry))); + assert_eq ! (unsafe { let uninit = :: std :: mem :: MaybeUninit :: < OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry > :: uninit () ; let ptr = uninit . as_ptr () ; :: std :: ptr :: addr_of ! ((* ptr) . i_am_double_wrapper_inline_sentry) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry) , "::" , stringify ! (i_am_double_wrapper_inline_sentry))); } #[test] fn bindgen_test_layout_OuterDoubleInlineWrapper_InnerDoubleInlineWrapper( @@ -348,8 +362,11 @@ pub mod root { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).i_am_outside_namespace_sentry - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i_am_outside_namespace_sentry) + as usize - + ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/size_t_is_usize.rs b/tests/expectations/tests/size_t_is_usize.rs index 0d9ab2caba..60e566f0d9 100644 --- a/tests/expectations/tests/size_t_is_usize.rs +++ b/tests/expectations/tests/size_t_is_usize.rs @@ -25,17 +25,29 @@ fn bindgen_test_layout_A() { concat!("Alignment of ", stringify!(A)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).len as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(len)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).offset as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).offset) as usize - ptr as usize + }, 8usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(offset)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).next as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize + }, 16usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(next)) ); diff --git a/tests/expectations/tests/size_t_template.rs b/tests/expectations/tests/size_t_template.rs index 6796bc9f3a..512e05528c 100644 --- a/tests/expectations/tests/size_t_template.rs +++ b/tests/expectations/tests/size_t_template.rs @@ -23,7 +23,11 @@ fn bindgen_test_layout_C() { concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).arr as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(arr)) ); diff --git a/tests/expectations/tests/struct_containing_forward_declared_struct.rs b/tests/expectations/tests/struct_containing_forward_declared_struct.rs index 7298095e21..d61e9dc3a2 100644 --- a/tests/expectations/tests/struct_containing_forward_declared_struct.rs +++ b/tests/expectations/tests/struct_containing_forward_declared_struct.rs @@ -23,7 +23,11 @@ fn bindgen_test_layout_a() { concat!("Alignment of ", stringify!(a)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).val_a as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).val_a) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(a), "::", stringify!(val_a)) ); @@ -55,7 +59,11 @@ fn bindgen_test_layout_b() { concat!("Alignment of ", stringify!(b)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).val_b as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).val_b) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(b), "::", stringify!(val_b)) ); diff --git a/tests/expectations/tests/struct_typedef.rs b/tests/expectations/tests/struct_typedef.rs index 34c9dbd21e..9a646afad6 100644 --- a/tests/expectations/tests/struct_typedef.rs +++ b/tests/expectations/tests/struct_typedef.rs @@ -24,8 +24,10 @@ fn bindgen_test_layout_typedef_named_struct() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).has_name - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).has_name) as usize - ptr as usize }, 0usize, concat!( @@ -55,8 +57,9 @@ fn bindgen_test_layout__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::<_bindgen_ty_1>())).no_name as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::<_bindgen_ty_1>::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).no_name) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/struct_typedef_ns.rs b/tests/expectations/tests/struct_typedef_ns.rs index ef91fe49a9..687b31ea91 100644 --- a/tests/expectations/tests/struct_typedef_ns.rs +++ b/tests/expectations/tests/struct_typedef_ns.rs @@ -31,8 +31,10 @@ pub mod root { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).foo as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, 0usize, concat!( @@ -71,8 +73,10 @@ pub mod root { ); assert_eq!( unsafe { - &(*(::std::ptr::null::<_bindgen_ty_1>())).foo as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::<_bindgen_ty_1>::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/struct_with_anon_struct.rs b/tests/expectations/tests/struct_with_anon_struct.rs index 0f5d3dac91..e34d9294a0 100644 --- a/tests/expectations/tests/struct_with_anon_struct.rs +++ b/tests/expectations/tests/struct_with_anon_struct.rs @@ -30,7 +30,9 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( @@ -42,7 +44,9 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 4usize, concat!( @@ -66,7 +70,11 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/struct_with_anon_struct_array.rs b/tests/expectations/tests/struct_with_anon_struct_array.rs index d5a5044832..c5b0fcc5ef 100644 --- a/tests/expectations/tests/struct_with_anon_struct_array.rs +++ b/tests/expectations/tests/struct_with_anon_struct_array.rs @@ -31,7 +31,9 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( @@ -43,7 +45,9 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 4usize, concat!( @@ -74,7 +78,9 @@ fn bindgen_test_layout_foo__bindgen_ty_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( @@ -86,7 +92,9 @@ fn bindgen_test_layout_foo__bindgen_ty_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 4usize, concat!( @@ -110,12 +118,20 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).baz as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, 16usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(baz)) ); diff --git a/tests/expectations/tests/struct_with_anon_struct_pointer.rs b/tests/expectations/tests/struct_with_anon_struct_pointer.rs index 0ed19f7634..968251249d 100644 --- a/tests/expectations/tests/struct_with_anon_struct_pointer.rs +++ b/tests/expectations/tests/struct_with_anon_struct_pointer.rs @@ -30,7 +30,9 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( @@ -42,7 +44,9 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 4usize, concat!( @@ -66,7 +70,11 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/struct_with_anon_union.rs b/tests/expectations/tests/struct_with_anon_union.rs index 15b8c9e449..e15939bdb8 100644 --- a/tests/expectations/tests/struct_with_anon_union.rs +++ b/tests/expectations/tests/struct_with_anon_union.rs @@ -30,7 +30,9 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( @@ -42,7 +44,9 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( @@ -75,7 +79,11 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/struct_with_anon_union_1_0.rs b/tests/expectations/tests/struct_with_anon_union_1_0.rs index b02c44482a..2b7d33b09d 100644 --- a/tests/expectations/tests/struct_with_anon_union_1_0.rs +++ b/tests/expectations/tests/struct_with_anon_union_1_0.rs @@ -74,7 +74,9 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( @@ -86,7 +88,9 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( @@ -115,7 +119,11 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/struct_with_anon_unnamed_struct.rs b/tests/expectations/tests/struct_with_anon_unnamed_struct.rs index 30751e7d83..a680604646 100644 --- a/tests/expectations/tests/struct_with_anon_unnamed_struct.rs +++ b/tests/expectations/tests/struct_with_anon_unnamed_struct.rs @@ -30,7 +30,9 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( @@ -42,7 +44,9 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 4usize, concat!( diff --git a/tests/expectations/tests/struct_with_anon_unnamed_union.rs b/tests/expectations/tests/struct_with_anon_unnamed_union.rs index 17a83574e7..0700253809 100644 --- a/tests/expectations/tests/struct_with_anon_unnamed_union.rs +++ b/tests/expectations/tests/struct_with_anon_unnamed_union.rs @@ -30,7 +30,9 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( @@ -42,7 +44,9 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs b/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs index f72abd2b03..622dbcbe20 100644 --- a/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs +++ b/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs @@ -74,7 +74,9 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( @@ -86,7 +88,9 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/struct_with_bitfields.rs b/tests/expectations/tests/struct_with_bitfields.rs index 2e95726f4c..8a7d070ec0 100644 --- a/tests/expectations/tests/struct_with_bitfields.rs +++ b/tests/expectations/tests/struct_with_bitfields.rs @@ -113,7 +113,11 @@ fn bindgen_test_layout_bitfield() { concat!("Alignment of ", stringify!(bitfield)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).e as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).e) as usize - ptr as usize + }, 4usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/struct_with_derive_debug.rs b/tests/expectations/tests/struct_with_derive_debug.rs index 721ba96caf..9ab32de0c7 100644 --- a/tests/expectations/tests/struct_with_derive_debug.rs +++ b/tests/expectations/tests/struct_with_derive_debug.rs @@ -24,7 +24,9 @@ fn bindgen_test_layout_LittleArray() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( @@ -53,7 +55,11 @@ fn bindgen_test_layout_BigArray() { concat!("Alignment of ", stringify!(BigArray)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", @@ -91,7 +97,9 @@ fn bindgen_test_layout_WithLittleArray() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( @@ -121,7 +129,9 @@ fn bindgen_test_layout_WithBigArray() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/struct_with_large_array.rs b/tests/expectations/tests/struct_with_large_array.rs index 56179c20f8..e323247f3f 100644 --- a/tests/expectations/tests/struct_with_large_array.rs +++ b/tests/expectations/tests/struct_with_large_array.rs @@ -24,7 +24,9 @@ fn bindgen_test_layout_S() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).large_array as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/struct_with_nesting.rs b/tests/expectations/tests/struct_with_nesting.rs index 7ced63e6ce..897b757df1 100644 --- a/tests/expectations/tests/struct_with_nesting.rs +++ b/tests/expectations/tests/struct_with_nesting.rs @@ -38,8 +38,11 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).c1 - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + foo__bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).c1) as usize - ptr as usize }, 0usize, concat!( @@ -51,8 +54,11 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).c2 - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + foo__bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).c2) as usize - ptr as usize }, 2usize, concat!( @@ -85,8 +91,11 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).d1 - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + foo__bindgen_ty_1__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d1) as usize - ptr as usize }, 0usize, concat!( @@ -98,8 +107,11 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).d2 - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + foo__bindgen_ty_1__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d2) as usize - ptr as usize }, 1usize, concat!( @@ -111,8 +123,11 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).d3 - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + foo__bindgen_ty_1__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d3) as usize - ptr as usize }, 2usize, concat!( @@ -124,8 +139,11 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).d4 - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + foo__bindgen_ty_1__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d4) as usize - ptr as usize }, 3usize, concat!( @@ -150,7 +168,9 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( @@ -183,7 +203,11 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) ); diff --git a/tests/expectations/tests/struct_with_nesting_1_0.rs b/tests/expectations/tests/struct_with_nesting_1_0.rs index 9f27161a0c..04d72bc0d6 100644 --- a/tests/expectations/tests/struct_with_nesting_1_0.rs +++ b/tests/expectations/tests/struct_with_nesting_1_0.rs @@ -82,8 +82,11 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).c1 - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + foo__bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).c1) as usize - ptr as usize }, 0usize, concat!( @@ -95,8 +98,11 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).c2 - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + foo__bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).c2) as usize - ptr as usize }, 2usize, concat!( @@ -134,8 +140,11 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).d1 - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + foo__bindgen_ty_1__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d1) as usize - ptr as usize }, 0usize, concat!( @@ -147,8 +156,11 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).d2 - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + foo__bindgen_ty_1__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d2) as usize - ptr as usize }, 1usize, concat!( @@ -160,8 +172,11 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).d3 - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + foo__bindgen_ty_1__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d3) as usize - ptr as usize }, 2usize, concat!( @@ -173,8 +188,11 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).d4 - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + foo__bindgen_ty_1__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d4) as usize - ptr as usize }, 3usize, concat!( @@ -204,7 +222,9 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( @@ -233,7 +253,11 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) ); diff --git a/tests/expectations/tests/struct_with_packing.rs b/tests/expectations/tests/struct_with_packing.rs index 14ee36fbaa..8a3b417454 100644 --- a/tests/expectations/tests/struct_with_packing.rs +++ b/tests/expectations/tests/struct_with_packing.rs @@ -24,12 +24,20 @@ fn bindgen_test_layout_a() { concat!("Alignment of ", stringify!(a)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).b as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(a), "::", stringify!(b)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).c as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize + }, 1usize, concat!("Offset of field: ", stringify!(a), "::", stringify!(c)) ); diff --git a/tests/expectations/tests/struct_with_struct.rs b/tests/expectations/tests/struct_with_struct.rs index c605c6e2e3..f62fd0570c 100644 --- a/tests/expectations/tests/struct_with_struct.rs +++ b/tests/expectations/tests/struct_with_struct.rs @@ -30,7 +30,9 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).x as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, 0usize, concat!( @@ -42,7 +44,9 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).y as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, 4usize, concat!( @@ -66,7 +70,11 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/template.rs b/tests/expectations/tests/template.rs index 2e544ec30a..7c36632855 100644 --- a/tests/expectations/tests/template.rs +++ b/tests/expectations/tests/template.rs @@ -79,13 +79,19 @@ fn bindgen_test_layout_C() { concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).mB as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mB) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(mB)) ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mBConstPtr as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBConstPtr) as usize - ptr as usize }, 8usize, concat!( @@ -97,7 +103,10 @@ fn bindgen_test_layout_C() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mBConstStructPtr as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBConstStructPtr) as usize - + ptr as usize }, 16usize, concat!( @@ -109,8 +118,10 @@ fn bindgen_test_layout_C() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mBConstStructPtrArray as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBConstStructPtrArray) as usize - + ptr as usize }, 24usize, concat!( @@ -121,7 +132,11 @@ fn bindgen_test_layout_C() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).mBConst as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBConst) as usize - ptr as usize + }, 32usize, concat!( "Offset of field: ", @@ -132,7 +147,9 @@ fn bindgen_test_layout_C() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mBVolatile as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBVolatile) as usize - ptr as usize }, 36usize, concat!( @@ -144,7 +161,9 @@ fn bindgen_test_layout_C() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mBConstBool as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBConstBool) as usize - ptr as usize }, 40usize, concat!( @@ -156,7 +175,9 @@ fn bindgen_test_layout_C() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mBConstChar as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBConstChar) as usize - ptr as usize }, 42usize, concat!( @@ -167,7 +188,11 @@ fn bindgen_test_layout_C() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).mBArray as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBArray) as usize - ptr as usize + }, 44usize, concat!( "Offset of field: ", @@ -178,7 +203,9 @@ fn bindgen_test_layout_C() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mBPtrArray as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBPtrArray) as usize - ptr as usize }, 48usize, concat!( @@ -190,7 +217,9 @@ fn bindgen_test_layout_C() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mBArrayPtr as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBArrayPtr) as usize - ptr as usize }, 56usize, concat!( @@ -201,13 +230,19 @@ fn bindgen_test_layout_C() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).mBRef as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBRef) as usize - ptr as usize + }, 64usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(mBRef)) ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mBConstRef as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBConstRef) as usize - ptr as usize }, 72usize, concat!( @@ -218,7 +253,11 @@ fn bindgen_test_layout_C() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).mPtrRef as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mPtrRef) as usize - ptr as usize + }, 80usize, concat!( "Offset of field: ", @@ -228,7 +267,11 @@ fn bindgen_test_layout_C() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).mArrayRef as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mArrayRef) as usize - ptr as usize + }, 88usize, concat!( "Offset of field: ", @@ -239,7 +282,9 @@ fn bindgen_test_layout_C() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mBConstArray as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBConstArray) as usize - ptr as usize }, 96usize, concat!( @@ -326,8 +371,9 @@ fn bindgen_test_layout_RootedContainer() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).root as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).root) as usize - ptr as usize }, 0usize, concat!( @@ -382,8 +428,10 @@ fn bindgen_test_layout_PODButContainsDtor() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).member as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, 0usize, concat!( @@ -428,7 +476,9 @@ fn bindgen_test_layout_POD() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).opaque_member as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).opaque_member) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/test_mixed_header_and_header_contents.rs b/tests/expectations/tests/test_mixed_header_and_header_contents.rs index c97be9b006..76f28dcbb7 100644 --- a/tests/expectations/tests/test_mixed_header_and_header_contents.rs +++ b/tests/expectations/tests/test_mixed_header_and_header_contents.rs @@ -44,52 +44,92 @@ fn bindgen_test_layout_Test() { concat!("Alignment of ", stringify!(Test)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).ch as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ch) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(ch)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).u as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize + }, 1usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(u)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).d as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, 2usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(d)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).cch as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).cch) as usize - ptr as usize + }, 3usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(cch)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).cu as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).cu) as usize - ptr as usize + }, 4usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(cu)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).cd as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).cd) as usize - ptr as usize + }, 5usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(cd)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).Cch as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Cch) as usize - ptr as usize + }, 6usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cch)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).Cu as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Cu) as usize - ptr as usize + }, 7usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cu)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).Cd as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Cd) as usize - ptr as usize + }, 8usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cd)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).Ccch as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Ccch) as usize - ptr as usize + }, 9usize, concat!( "Offset of field: ", @@ -99,12 +139,20 @@ fn bindgen_test_layout_Test() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).Ccu as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Ccu) as usize - ptr as usize + }, 10usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccu)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).Ccd as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Ccd) as usize - ptr as usize + }, 11usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccd)) ); diff --git a/tests/expectations/tests/test_multiple_header_calls_in_builder.rs b/tests/expectations/tests/test_multiple_header_calls_in_builder.rs index c77c18342a..b90ec73002 100644 --- a/tests/expectations/tests/test_multiple_header_calls_in_builder.rs +++ b/tests/expectations/tests/test_multiple_header_calls_in_builder.rs @@ -38,52 +38,92 @@ fn bindgen_test_layout_Test() { concat!("Alignment of ", stringify!(Test)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).ch as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ch) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(ch)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).u as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize + }, 1usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(u)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).d as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, 2usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(d)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).cch as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).cch) as usize - ptr as usize + }, 3usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(cch)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).cu as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).cu) as usize - ptr as usize + }, 4usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(cu)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).cd as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).cd) as usize - ptr as usize + }, 5usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(cd)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).Cch as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Cch) as usize - ptr as usize + }, 6usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cch)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).Cu as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Cu) as usize - ptr as usize + }, 7usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cu)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).Cd as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Cd) as usize - ptr as usize + }, 8usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cd)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).Ccch as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Ccch) as usize - ptr as usize + }, 9usize, concat!( "Offset of field: ", @@ -93,12 +133,20 @@ fn bindgen_test_layout_Test() { ) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).Ccu as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Ccu) as usize - ptr as usize + }, 10usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccu)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).Ccd as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Ccd) as usize - ptr as usize + }, 11usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccd)) ); diff --git a/tests/expectations/tests/timex.rs b/tests/expectations/tests/timex.rs index b2a84d8462..ec761f34be 100644 --- a/tests/expectations/tests/timex.rs +++ b/tests/expectations/tests/timex.rs @@ -111,7 +111,11 @@ fn bindgen_test_layout_timex() { concat!("Alignment of ", stringify!(timex)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).tai as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tai) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", @@ -151,7 +155,9 @@ fn bindgen_test_layout_timex_named() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).tai as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tai) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/type-referenced-by-allowlisted-function.rs b/tests/expectations/tests/type-referenced-by-allowlisted-function.rs index 568f94336b..cc491fcccc 100644 --- a/tests/expectations/tests/type-referenced-by-allowlisted-function.rs +++ b/tests/expectations/tests/type-referenced-by-allowlisted-function.rs @@ -24,7 +24,9 @@ fn bindgen_test_layout_dl_phdr_info() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).x as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/typeref.rs b/tests/expectations/tests/typeref.rs index 1c34be7e9b..00f8f52742 100644 --- a/tests/expectations/tests/typeref.rs +++ b/tests/expectations/tests/typeref.rs @@ -24,8 +24,10 @@ fn bindgen_test_layout_mozilla_FragmentOrURL() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mIsLocalRef - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mIsLocalRef) as usize - ptr as usize }, 0usize, concat!( @@ -99,7 +101,11 @@ fn bindgen_test_layout_Bar() { concat!("Alignment of ", stringify!(Bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).mFoo as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mFoo) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(mFoo)) ); @@ -130,7 +136,11 @@ fn bindgen_test_layout_nsFoo() { concat!("Alignment of ", stringify!(nsFoo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).mBar as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBar) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/typeref_1_0.rs b/tests/expectations/tests/typeref_1_0.rs index 2820d9f96c..b4d896cd4b 100644 --- a/tests/expectations/tests/typeref_1_0.rs +++ b/tests/expectations/tests/typeref_1_0.rs @@ -67,8 +67,10 @@ fn bindgen_test_layout_mozilla_FragmentOrURL() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mIsLocalRef - as *const _ as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mIsLocalRef) as usize - ptr as usize }, 0usize, concat!( @@ -137,7 +139,11 @@ fn bindgen_test_layout_Bar() { concat!("Alignment of ", stringify!(Bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).mFoo as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mFoo) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(mFoo)) ); @@ -174,7 +180,11 @@ fn bindgen_test_layout_nsFoo() { concat!("Alignment of ", stringify!(nsFoo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).mBar as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBar) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/underscore.rs b/tests/expectations/tests/underscore.rs index 6ef2d8a124..8e5e456682 100644 --- a/tests/expectations/tests/underscore.rs +++ b/tests/expectations/tests/underscore.rs @@ -24,7 +24,11 @@ fn bindgen_test_layout_ptr_t() { concat!("Alignment of ", stringify!(ptr_t)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).__ as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).__) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(ptr_t), "::", stringify!(__)) ); diff --git a/tests/expectations/tests/union-align.rs b/tests/expectations/tests/union-align.rs index 8612764186..cb938f4926 100644 --- a/tests/expectations/tests/union-align.rs +++ b/tests/expectations/tests/union-align.rs @@ -24,7 +24,11 @@ fn bindgen_test_layout_Bar() { concat!("Alignment of ", stringify!(Bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).foo as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(foo)) ); @@ -57,7 +61,11 @@ fn bindgen_test_layout_Baz() { concat!("Alignment of ", stringify!(Baz)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(Baz), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/union-in-ns.rs b/tests/expectations/tests/union-in-ns.rs index b52c6c3600..f7187c497b 100644 --- a/tests/expectations/tests/union-in-ns.rs +++ b/tests/expectations/tests/union-in-ns.rs @@ -27,7 +27,11 @@ pub mod root { concat!("Alignment of ", stringify!(bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).baz as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/union-in-ns_1_0.rs b/tests/expectations/tests/union-in-ns_1_0.rs index c210c38c74..6e58fee2fd 100644 --- a/tests/expectations/tests/union-in-ns_1_0.rs +++ b/tests/expectations/tests/union-in-ns_1_0.rs @@ -74,7 +74,11 @@ pub mod root { concat!("Alignment of ", stringify!(bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).baz as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/union_dtor.rs b/tests/expectations/tests/union_dtor.rs index 94ad3fd873..f7240fd577 100644 --- a/tests/expectations/tests/union_dtor.rs +++ b/tests/expectations/tests/union_dtor.rs @@ -24,7 +24,9 @@ fn bindgen_test_layout_UnionWithDtor() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mFoo as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mFoo) as usize - ptr as usize }, 0usize, concat!( @@ -36,7 +38,9 @@ fn bindgen_test_layout_UnionWithDtor() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mBar as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBar) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/union_dtor_1_0.rs b/tests/expectations/tests/union_dtor_1_0.rs index a59f99fc6c..928884de07 100644 --- a/tests/expectations/tests/union_dtor_1_0.rs +++ b/tests/expectations/tests/union_dtor_1_0.rs @@ -69,7 +69,9 @@ fn bindgen_test_layout_UnionWithDtor() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mFoo as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mFoo) as usize - ptr as usize }, 0usize, concat!( @@ -81,7 +83,9 @@ fn bindgen_test_layout_UnionWithDtor() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mBar as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBar) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/union_fields.rs b/tests/expectations/tests/union_fields.rs index 6cd0d56cdb..d0b316a843 100644 --- a/tests/expectations/tests/union_fields.rs +++ b/tests/expectations/tests/union_fields.rs @@ -26,7 +26,9 @@ fn bindgen_test_layout_nsStyleUnion() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mInt as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mInt) as usize - ptr as usize }, 0usize, concat!( @@ -38,7 +40,9 @@ fn bindgen_test_layout_nsStyleUnion() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mFloat as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mFloat) as usize - ptr as usize }, 0usize, concat!( @@ -50,8 +54,9 @@ fn bindgen_test_layout_nsStyleUnion() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mPointer as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mPointer) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/union_fields_1_0.rs b/tests/expectations/tests/union_fields_1_0.rs index 36972b6b8f..90c01f48bd 100644 --- a/tests/expectations/tests/union_fields_1_0.rs +++ b/tests/expectations/tests/union_fields_1_0.rs @@ -70,7 +70,9 @@ fn bindgen_test_layout_nsStyleUnion() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mInt as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mInt) as usize - ptr as usize }, 0usize, concat!( @@ -82,7 +84,9 @@ fn bindgen_test_layout_nsStyleUnion() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mFloat as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mFloat) as usize - ptr as usize }, 0usize, concat!( @@ -94,8 +98,9 @@ fn bindgen_test_layout_nsStyleUnion() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mPointer as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mPointer) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/union_with_anon_struct.rs b/tests/expectations/tests/union_with_anon_struct.rs index afb735043d..d70f7f3880 100644 --- a/tests/expectations/tests/union_with_anon_struct.rs +++ b/tests/expectations/tests/union_with_anon_struct.rs @@ -30,7 +30,9 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( @@ -42,7 +44,9 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 4usize, concat!( @@ -66,7 +70,11 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/union_with_anon_struct_1_0.rs b/tests/expectations/tests/union_with_anon_struct_1_0.rs index 09dcfa1b08..ba582c1063 100644 --- a/tests/expectations/tests/union_with_anon_struct_1_0.rs +++ b/tests/expectations/tests/union_with_anon_struct_1_0.rs @@ -74,7 +74,9 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( @@ -86,7 +88,9 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 4usize, concat!( @@ -115,7 +119,11 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/union_with_anon_struct_bitfield.rs b/tests/expectations/tests/union_with_anon_struct_bitfield.rs index 09ed515f99..85bf0dae18 100644 --- a/tests/expectations/tests/union_with_anon_struct_bitfield.rs +++ b/tests/expectations/tests/union_with_anon_struct_bitfield.rs @@ -175,7 +175,11 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) ); diff --git a/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs b/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs index 43736b0311..1989a8305e 100644 --- a/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs +++ b/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs @@ -224,7 +224,11 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) ); diff --git a/tests/expectations/tests/union_with_anon_union.rs b/tests/expectations/tests/union_with_anon_union.rs index a24962c4a6..6c049f9be3 100644 --- a/tests/expectations/tests/union_with_anon_union.rs +++ b/tests/expectations/tests/union_with_anon_union.rs @@ -30,7 +30,9 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( @@ -42,7 +44,9 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( @@ -75,7 +79,11 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/union_with_anon_union_1_0.rs b/tests/expectations/tests/union_with_anon_union_1_0.rs index f892c45f8b..56675f36bc 100644 --- a/tests/expectations/tests/union_with_anon_union_1_0.rs +++ b/tests/expectations/tests/union_with_anon_union_1_0.rs @@ -75,7 +75,9 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( @@ -87,7 +89,9 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( @@ -116,7 +120,11 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/union_with_anon_unnamed_struct.rs b/tests/expectations/tests/union_with_anon_unnamed_struct.rs index 94380d1a54..622bb4a64f 100644 --- a/tests/expectations/tests/union_with_anon_unnamed_struct.rs +++ b/tests/expectations/tests/union_with_anon_unnamed_struct.rs @@ -33,8 +33,10 @@ fn bindgen_test_layout_pixel__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).r as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).r) as usize - ptr as usize }, 0usize, concat!( @@ -46,8 +48,10 @@ fn bindgen_test_layout_pixel__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).g as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).g) as usize - ptr as usize }, 1usize, concat!( @@ -59,8 +63,10 @@ fn bindgen_test_layout_pixel__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).b as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 2usize, concat!( @@ -72,8 +78,10 @@ fn bindgen_test_layout_pixel__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 3usize, concat!( @@ -97,7 +105,11 @@ fn bindgen_test_layout_pixel() { concat!("Alignment of ", stringify!(pixel)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).rgba as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rgba) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs b/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs index cbdac700fb..cb4897a825 100644 --- a/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs +++ b/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs @@ -77,8 +77,10 @@ fn bindgen_test_layout_pixel__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).r as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).r) as usize - ptr as usize }, 0usize, concat!( @@ -90,8 +92,10 @@ fn bindgen_test_layout_pixel__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).g as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).g) as usize - ptr as usize }, 1usize, concat!( @@ -103,8 +107,10 @@ fn bindgen_test_layout_pixel__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).b as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 2usize, concat!( @@ -116,8 +122,10 @@ fn bindgen_test_layout_pixel__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 3usize, concat!( @@ -146,7 +154,11 @@ fn bindgen_test_layout_pixel() { concat!("Alignment of ", stringify!(pixel)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).rgba as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rgba) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/union_with_anon_unnamed_union.rs b/tests/expectations/tests/union_with_anon_unnamed_union.rs index 2004ff4cef..2156a325b4 100644 --- a/tests/expectations/tests/union_with_anon_unnamed_union.rs +++ b/tests/expectations/tests/union_with_anon_unnamed_union.rs @@ -31,7 +31,9 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( @@ -43,7 +45,9 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).c as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, 0usize, concat!( @@ -76,7 +80,11 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) ); diff --git a/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs b/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs index 910f5885c0..613d8e4889 100644 --- a/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs +++ b/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs @@ -76,7 +76,9 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( @@ -88,7 +90,9 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).c as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, 0usize, concat!( @@ -117,7 +121,11 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) ); diff --git a/tests/expectations/tests/union_with_big_member.rs b/tests/expectations/tests/union_with_big_member.rs index 3f9294dd05..66e0ad8a55 100644 --- a/tests/expectations/tests/union_with_big_member.rs +++ b/tests/expectations/tests/union_with_big_member.rs @@ -25,7 +25,9 @@ fn bindgen_test_layout_WithBigArray() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( @@ -37,7 +39,9 @@ fn bindgen_test_layout_WithBigArray() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( @@ -77,7 +81,9 @@ fn bindgen_test_layout_WithBigArray2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( @@ -89,7 +95,9 @@ fn bindgen_test_layout_WithBigArray2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( @@ -129,7 +137,9 @@ fn bindgen_test_layout_WithBigMember() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( @@ -141,7 +151,9 @@ fn bindgen_test_layout_WithBigMember() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/union_with_big_member_1_0.rs b/tests/expectations/tests/union_with_big_member_1_0.rs index 541c9d4c77..252d2fb830 100644 --- a/tests/expectations/tests/union_with_big_member_1_0.rs +++ b/tests/expectations/tests/union_with_big_member_1_0.rs @@ -69,7 +69,9 @@ fn bindgen_test_layout_WithBigArray() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( @@ -81,7 +83,9 @@ fn bindgen_test_layout_WithBigArray() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( @@ -127,7 +131,9 @@ fn bindgen_test_layout_WithBigArray2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( @@ -139,7 +145,9 @@ fn bindgen_test_layout_WithBigArray2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( @@ -176,7 +184,9 @@ fn bindgen_test_layout_WithBigMember() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).a as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( @@ -188,7 +198,9 @@ fn bindgen_test_layout_WithBigMember() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).b as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/union_with_nesting.rs b/tests/expectations/tests/union_with_nesting.rs index 54a3179b41..87556243ea 100644 --- a/tests/expectations/tests/union_with_nesting.rs +++ b/tests/expectations/tests/union_with_nesting.rs @@ -37,8 +37,11 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).b1 - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + foo__bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b1) as usize - ptr as usize }, 0usize, concat!( @@ -50,8 +53,11 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).b2 - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + foo__bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b2) as usize - ptr as usize }, 0usize, concat!( @@ -91,8 +97,11 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).c1 - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + foo__bindgen_ty_1__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).c1) as usize - ptr as usize }, 0usize, concat!( @@ -104,8 +113,11 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).c2 - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + foo__bindgen_ty_1__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).c2) as usize - ptr as usize }, 0usize, concat!( @@ -160,7 +172,11 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) ); diff --git a/tests/expectations/tests/union_with_nesting_1_0.rs b/tests/expectations/tests/union_with_nesting_1_0.rs index 3f105c39e8..cd6104b788 100644 --- a/tests/expectations/tests/union_with_nesting_1_0.rs +++ b/tests/expectations/tests/union_with_nesting_1_0.rs @@ -82,8 +82,11 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).b1 - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + foo__bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b1) as usize - ptr as usize }, 0usize, concat!( @@ -95,8 +98,11 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).b2 - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + foo__bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b2) as usize - ptr as usize }, 0usize, concat!( @@ -133,8 +139,11 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).c1 - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + foo__bindgen_ty_1__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).c1) as usize - ptr as usize }, 0usize, concat!( @@ -146,8 +155,11 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).c2 - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::< + foo__bindgen_ty_1__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).c2) as usize - ptr as usize }, 0usize, concat!( @@ -194,7 +206,11 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).a as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) ); diff --git a/tests/expectations/tests/unknown_attr.rs b/tests/expectations/tests/unknown_attr.rs index 8dbda00d71..bc2dd0a0e0 100644 --- a/tests/expectations/tests/unknown_attr.rs +++ b/tests/expectations/tests/unknown_attr.rs @@ -27,8 +27,10 @@ fn bindgen_test_layout_max_align_t() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).__clang_max_align_nonce1 - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).__clang_max_align_nonce1) as usize - + ptr as usize }, 0usize, concat!( @@ -40,8 +42,10 @@ fn bindgen_test_layout_max_align_t() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).__clang_max_align_nonce2 - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).__clang_max_align_nonce2) as usize - + ptr as usize }, 16usize, concat!( diff --git a/tests/expectations/tests/use-core.rs b/tests/expectations/tests/use-core.rs index 66e3b36360..49020c7868 100644 --- a/tests/expectations/tests/use-core.rs +++ b/tests/expectations/tests/use-core.rs @@ -27,17 +27,29 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::core::ptr::null::())).a as *const _ as usize }, + unsafe { + let uninit = ::core::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::core::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) ); assert_eq!( - unsafe { &(*(::core::ptr::null::())).b as *const _ as usize }, + unsafe { + let uninit = ::core::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::core::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, 4usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) ); assert_eq!( - unsafe { &(*(::core::ptr::null::())).bar as *const _ as usize }, + unsafe { + let uninit = ::core::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, 8usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); @@ -71,7 +83,9 @@ fn bindgen_test_layout__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::core::ptr::null::<_bindgen_ty_1>())).bar as *const _ as usize + let uninit = ::core::mem::MaybeUninit::<_bindgen_ty_1>::uninit(); + let ptr = uninit.as_ptr(); + ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, concat!( @@ -83,7 +97,9 @@ fn bindgen_test_layout__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::core::ptr::null::<_bindgen_ty_1>())).baz as *const _ as usize + let uninit = ::core::mem::MaybeUninit::<_bindgen_ty_1>::uninit(); + let ptr = uninit.as_ptr(); + ::core::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/use-core_1_0.rs b/tests/expectations/tests/use-core_1_0.rs index 61ddfc42cb..fbe27223fe 100644 --- a/tests/expectations/tests/use-core_1_0.rs +++ b/tests/expectations/tests/use-core_1_0.rs @@ -70,17 +70,29 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::core::ptr::null::())).a as *const _ as usize }, + unsafe { + let uninit = ::core::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::core::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) ); assert_eq!( - unsafe { &(*(::core::ptr::null::())).b as *const _ as usize }, + unsafe { + let uninit = ::core::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::core::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, 4usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) ); assert_eq!( - unsafe { &(*(::core::ptr::null::())).bar as *const _ as usize }, + unsafe { + let uninit = ::core::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, 8usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); @@ -120,7 +132,9 @@ fn bindgen_test_layout__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::core::ptr::null::<_bindgen_ty_1>())).bar as *const _ as usize + let uninit = ::core::mem::MaybeUninit::<_bindgen_ty_1>::uninit(); + let ptr = uninit.as_ptr(); + ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, concat!( @@ -132,7 +146,9 @@ fn bindgen_test_layout__bindgen_ty_1() { ); assert_eq!( unsafe { - &(*(::core::ptr::null::<_bindgen_ty_1>())).baz as *const _ as usize + let uninit = ::core::mem::MaybeUninit::<_bindgen_ty_1>::uninit(); + let ptr = uninit.as_ptr(); + ::core::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, 0usize, concat!( diff --git a/tests/expectations/tests/var-tracing.rs b/tests/expectations/tests/var-tracing.rs index 2931f9121c..a77453c5b1 100644 --- a/tests/expectations/tests/var-tracing.rs +++ b/tests/expectations/tests/var-tracing.rs @@ -23,7 +23,11 @@ fn bindgen_test_layout_Bar() { concat!("Alignment of ", stringify!(Bar)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).m_baz as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).m_baz) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/vector.rs b/tests/expectations/tests/vector.rs index 04f4de714b..434e786d8c 100644 --- a/tests/expectations/tests/vector.rs +++ b/tests/expectations/tests/vector.rs @@ -23,7 +23,11 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).mMember as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize + }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/virtual_inheritance.rs b/tests/expectations/tests/virtual_inheritance.rs index eac6aa665e..85575d2ff7 100644 --- a/tests/expectations/tests/virtual_inheritance.rs +++ b/tests/expectations/tests/virtual_inheritance.rs @@ -23,7 +23,11 @@ fn bindgen_test_layout_A() { concat!("Alignment of ", stringify!(A)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).foo as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(foo)) ); @@ -49,7 +53,11 @@ fn bindgen_test_layout_B() { concat!("Alignment of ", stringify!(B)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).bar as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, 8usize, concat!("Offset of field: ", stringify!(B), "::", stringify!(bar)) ); @@ -84,7 +92,11 @@ fn bindgen_test_layout_C() { concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { &(*(::std::ptr::null::())).baz as *const _ as usize }, + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, 8usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(baz)) ); diff --git a/tests/expectations/tests/weird_bitfields.rs b/tests/expectations/tests/weird_bitfields.rs index c4dfa55ad9..091732d084 100644 --- a/tests/expectations/tests/weird_bitfields.rs +++ b/tests/expectations/tests/weird_bitfields.rs @@ -133,8 +133,10 @@ fn bindgen_test_layout_Weird() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mStrokeDasharrayLength as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mStrokeDasharrayLength) as usize - + ptr as usize }, 0usize, concat!( @@ -146,7 +148,9 @@ fn bindgen_test_layout_Weird() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mClipRule as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mClipRule) as usize - ptr as usize }, 8usize, concat!( @@ -158,8 +162,10 @@ fn bindgen_test_layout_Weird() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mColorInterpolation as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mColorInterpolation) as usize - + ptr as usize }, 9usize, concat!( @@ -171,8 +177,10 @@ fn bindgen_test_layout_Weird() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mColorInterpolationFilters - as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mColorInterpolationFilters) as usize - + ptr as usize }, 10usize, concat!( @@ -184,7 +192,9 @@ fn bindgen_test_layout_Weird() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mFillRule as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mFillRule) as usize - ptr as usize }, 11usize, concat!( @@ -196,8 +206,9 @@ fn bindgen_test_layout_Weird() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mImageRendering as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mImageRendering) as usize - ptr as usize }, 12usize, concat!( @@ -209,7 +220,9 @@ fn bindgen_test_layout_Weird() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mPaintOrder as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mPaintOrder) as usize - ptr as usize }, 13usize, concat!( @@ -221,8 +234,9 @@ fn bindgen_test_layout_Weird() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mShapeRendering as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mShapeRendering) as usize - ptr as usize }, 14usize, concat!( @@ -234,8 +248,9 @@ fn bindgen_test_layout_Weird() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mStrokeLinecap as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mStrokeLinecap) as usize - ptr as usize }, 15usize, concat!( @@ -247,8 +262,9 @@ fn bindgen_test_layout_Weird() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mStrokeLinejoin as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mStrokeLinejoin) as usize - ptr as usize }, 16usize, concat!( @@ -260,7 +276,9 @@ fn bindgen_test_layout_Weird() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mTextAnchor as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mTextAnchor) as usize - ptr as usize }, 17usize, concat!( @@ -272,8 +290,9 @@ fn bindgen_test_layout_Weird() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).mTextRendering as *const _ - as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mTextRendering) as usize - ptr as usize }, 18usize, concat!( diff --git a/tests/expectations/tests/zero-size-array-align.rs b/tests/expectations/tests/zero-size-array-align.rs index 92b6798fb2..6b94324407 100644 --- a/tests/expectations/tests/zero-size-array-align.rs +++ b/tests/expectations/tests/zero-size-array-align.rs @@ -56,7 +56,9 @@ fn bindgen_test_layout_dm_deps() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).count as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).count) as usize - ptr as usize }, 0usize, concat!( @@ -68,7 +70,9 @@ fn bindgen_test_layout_dm_deps() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).filler as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).filler) as usize - ptr as usize }, 4usize, concat!( @@ -80,7 +84,9 @@ fn bindgen_test_layout_dm_deps() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).device as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).device) as usize - ptr as usize }, 8usize, concat!( diff --git a/tests/expectations/tests/zero-sized-array.rs b/tests/expectations/tests/zero-sized-array.rs index 347c22649d..c615ae0bd7 100644 --- a/tests/expectations/tests/zero-sized-array.rs +++ b/tests/expectations/tests/zero-sized-array.rs @@ -55,7 +55,9 @@ fn bindgen_test_layout_ZeroSizedArray() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).arr as *const _ as usize + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize }, 0usize, concat!( @@ -86,8 +88,10 @@ fn bindgen_test_layout_ContainsZeroSizedArray() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).zsa as *const _ - as usize + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).zsa) as usize - ptr as usize }, 0usize, concat!( From 4d18f7606a2bc8a18b181b3e9639c9464a9dc896 Mon Sep 17 00:00:00 2001 From: Nick Desaulniers Date: Tue, 31 May 2022 09:38:48 -0700 Subject: [PATCH 290/942] upgrade clang-sys from 1.2.0 to 1.3.3 Via: $ cargo update -p clang-sys Contains a fix that was preventing me from running bindgen in my env. Link: https://github.com/KyleMayes/clang-sys/issues/138 Link: https://github.com/KyleMayes/clang-sys/pull/142 Signed-off-by: Nick Desaulniers --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3de8f8f5d2..bcab40b49a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -74,9 +74,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clang-sys" -version = "1.2.0" +version = "1.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "853eda514c284c2287f4bf20ae614f8781f40a81d32ecda6e91449304dfe077c" +checksum = "5a050e2153c5be08febd6734e29298e844fdb0fa21aeddd63b4eb7baa106c69b" dependencies = [ "glob", "libc", From 2cf7ba9ee1a0b545ec52ffea697af42ee681ee22 Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Thu, 2 Jun 2022 06:18:45 -0400 Subject: [PATCH 291/942] deps: Update `which` crate to 4.2.2 Fixes #2181. --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bcab40b49a..47a73bc68a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -412,9 +412,9 @@ checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" [[package]] name = "which" -version = "4.2.1" +version = "4.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cc009ab82a2afc94b9e467ab4214aee9cad1356cd9191264203d7d72006e00d" +checksum = "ea187a8ef279bc014ec368c27a920da2024d2a711109bfbe3440585d5cf27ad9" dependencies = [ "either", "lazy_static", From 3a8a60cd4c88fd6e753a2f215796a5117b7bfaa8 Mon Sep 17 00:00:00 2001 From: Ian Chamberlain Date: Thu, 19 May 2022 21:54:46 -0400 Subject: [PATCH 292/942] Look for `must_use` on typdefs in function return Closes #2206 --- src/codegen/mod.rs | 32 +++++++- src/ir/context.rs | 3 +- .../tests/func_return_must_use.rs | 76 +++++++++++++++++++ tests/headers/func_return_must_use.h | 36 +++++++++ 4 files changed, 142 insertions(+), 5 deletions(-) create mode 100644 tests/expectations/tests/func_return_must_use.rs create mode 100644 tests/headers/func_return_must_use.h diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index e4ce95264f..fdc9b5ed16 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -3965,11 +3965,35 @@ impl CodeGenerator for Function { let mut attributes = vec![]; - if signature.must_use() && - ctx.options().rust_features().must_use_function - { - attributes.push(attributes::must_use()); + if ctx.options().rust_features().must_use_function { + let must_use = signature.must_use() || { + let ret_ty = signature.return_type(); + + let resolved_ret = ret_ty + .into_resolver() + .through_type_refs() + .through_type_aliases() + .resolve(ctx); + + let must_use_resolved_ty = + resolved_ret.annotations().must_use_type() || + ctx.must_use_type_by_name(resolved_ret); + + let ret = ctx.resolve_item(ret_ty); + let must_use_ty = ret.annotations().must_use_type() || + ctx.must_use_type_by_name(ret); + + // If the return type already has #[must_use], the function does not + // need the annotation. This preserves the codegen behavior before + // type aliases with #[must_use] were supported. + !must_use_resolved_ty && must_use_ty + }; + + if must_use { + attributes.push(attributes::must_use()); + } } + if let Some(comment) = item.comment(ctx) { attributes.push(attributes::doc(comment)); } diff --git a/src/ir/context.rs b/src/ir/context.rs index 9cf43ec3c6..2f71debd00 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -1921,7 +1921,8 @@ If you encounter an error missing from this list, please file an issue or a PR!" let item = Item::new( with_id, None, - None, + self.resolve_item_fallible(wrapped_id) + .map(|item| item.annotations().clone()), parent_id.unwrap_or_else(|| self.current_module.into()), ItemKind::Type(ty), Some(location), diff --git a/tests/expectations/tests/func_return_must_use.rs b/tests/expectations/tests/func_return_must_use.rs new file mode 100644 index 0000000000..9f40aaa61a --- /dev/null +++ b/tests/expectations/tests/func_return_must_use.rs @@ -0,0 +1,76 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +pub type MustUseInt = ::std::os::raw::c_int; +extern "C" { + #[must_use] + pub fn return_int() -> MustUseInt; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +#[must_use] +pub struct MustUseStruct { + _unused: [u8; 0], +} +extern "C" { + pub fn return_struct() -> MustUseStruct; +} +///
+pub type AnnotatedInt = ::std::os::raw::c_int; +extern "C" { + #[must_use] + pub fn return_annotated_int() -> AnnotatedInt; +} +extern "C" { + pub fn return_plain_int() -> ::std::os::raw::c_int; +} +///
+#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +#[must_use] +pub struct AnnotatedStruct {} +#[test] +fn bindgen_test_layout_AnnotatedStruct() { + assert_eq!( + ::std::mem::size_of::(), + 0usize, + concat!("Size of: ", stringify!(AnnotatedStruct)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(AnnotatedStruct)) + ); +} +extern "C" { + pub fn return_annotated_struct() -> AnnotatedStruct; +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct PlainStruct {} +#[test] +fn bindgen_test_layout_PlainStruct() { + assert_eq!( + ::std::mem::size_of::(), + 0usize, + concat!("Size of: ", stringify!(PlainStruct)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(PlainStruct)) + ); +} +///
+pub type TypedefPlainStruct = PlainStruct; +extern "C" { + pub fn return_plain_struct() -> PlainStruct; +} +extern "C" { + #[must_use] + pub fn return_typedef_struct() -> TypedefPlainStruct; +} diff --git a/tests/headers/func_return_must_use.h b/tests/headers/func_return_must_use.h new file mode 100644 index 0000000000..f05bd2de40 --- /dev/null +++ b/tests/headers/func_return_must_use.h @@ -0,0 +1,36 @@ +// bindgen-flags: --must-use-type 'MustUse.*' + +typedef int MustUseInt; + +MustUseInt return_int(); + +struct MustUseStruct; + +struct MustUseStruct return_struct(); + +/** + *
+ */ +typedef int AnnotatedInt; + +AnnotatedInt return_annotated_int(); + +int return_plain_int(); + +/** + *
+ */ +struct AnnotatedStruct {}; + +struct AnnotatedStruct return_annotated_struct(); + +struct PlainStruct {}; + +/** + *
+ */ +typedef struct PlainStruct TypedefPlainStruct; + +struct PlainStruct return_plain_struct(); + +TypedefPlainStruct return_typedef_struct(); From aa103a6d9059c013e5cea959041a48cbdd9d3131 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 5 Jun 2022 19:37:24 +0200 Subject: [PATCH 293/942] ir: Centralize must_use checks and simplify codegen. --- src/codegen/mod.rs | 26 ++++--------------- src/ir/context.rs | 3 +-- src/ir/item.rs | 5 ++++ .../tests/func_return_must_use.rs | 2 ++ 4 files changed, 13 insertions(+), 23 deletions(-) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index fdc9b5ed16..4dd520368b 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -2082,8 +2082,7 @@ impl CodeGenerator for CompInfo { attributes.push(attributes::derives(&derives)) } - if item.annotations().must_use_type() || ctx.must_use_type_by_name(item) - { + if item.must_use(ctx) { attributes.push(attributes::must_use()); } @@ -3054,8 +3053,7 @@ impl CodeGenerator for Enum { attrs.push(attributes::doc(comment)); } - if item.annotations().must_use_type() || ctx.must_use_type_by_name(item) - { + if item.must_use(ctx) { attrs.push(attributes::must_use()); } @@ -3967,26 +3965,12 @@ impl CodeGenerator for Function { if ctx.options().rust_features().must_use_function { let must_use = signature.must_use() || { - let ret_ty = signature.return_type(); - - let resolved_ret = ret_ty + let ret_ty = signature + .return_type() .into_resolver() .through_type_refs() - .through_type_aliases() .resolve(ctx); - - let must_use_resolved_ty = - resolved_ret.annotations().must_use_type() || - ctx.must_use_type_by_name(resolved_ret); - - let ret = ctx.resolve_item(ret_ty); - let must_use_ty = ret.annotations().must_use_type() || - ctx.must_use_type_by_name(ret); - - // If the return type already has #[must_use], the function does not - // need the annotation. This preserves the codegen behavior before - // type aliases with #[must_use] were supported. - !must_use_resolved_ty && must_use_ty + ret_ty.must_use(ctx) }; if must_use { diff --git a/src/ir/context.rs b/src/ir/context.rs index 2f71debd00..9cf43ec3c6 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -1921,8 +1921,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" let item = Item::new( with_id, None, - self.resolve_item_fallible(wrapped_id) - .map(|item| item.annotations().clone()), + None, parent_id.unwrap_or_else(|| self.current_module.into()), ItemKind::Type(ty), Some(location), diff --git a/src/ir/item.rs b/src/ir/item.rs index aed575ca11..6ce420171f 100644 --- a/src/ir/item.rs +++ b/src/ir/item.rs @@ -1096,6 +1096,11 @@ impl Item { _ => return None, }) } + + /// Whether this is a #[must_use] type. + pub fn must_use(&self, ctx: &BindgenContext) -> bool { + self.annotations().must_use_type() || ctx.must_use_type_by_name(self) + } } impl IsOpaque for T diff --git a/tests/expectations/tests/func_return_must_use.rs b/tests/expectations/tests/func_return_must_use.rs index 9f40aaa61a..6ea6c704f0 100644 --- a/tests/expectations/tests/func_return_must_use.rs +++ b/tests/expectations/tests/func_return_must_use.rs @@ -17,6 +17,7 @@ pub struct MustUseStruct { _unused: [u8; 0], } extern "C" { + #[must_use] pub fn return_struct() -> MustUseStruct; } ///
@@ -47,6 +48,7 @@ fn bindgen_test_layout_AnnotatedStruct() { ); } extern "C" { + #[must_use] pub fn return_annotated_struct() -> AnnotatedStruct; } #[repr(C)] From 24252f0876217d18b0ef291446fd7545d0b90bf1 Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Fri, 3 Jun 2022 20:40:07 -0400 Subject: [PATCH 294/942] Invoke clippy better for tests See https://github.com/rust-lang/rust-clippy/issues/1436#issuecomment-462059561 --- .github/workflows/bindgen.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 71baf542f0..0bc7d235d4 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -35,7 +35,7 @@ jobs: uses: actions-rs/cargo@v1 with: command: clippy - args: -- --cfg test + args: --tests msrv: runs-on: ubuntu-latest From 11f3b37faf5635bf005da3645b8f3bdcaab208dc Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Fri, 3 Jun 2022 20:05:33 -0400 Subject: [PATCH 295/942] Fix some clippy warnings cargo clippy --fix --tests cargo +nightly fmt --- build.rs | 2 +- src/codegen/mod.rs | 4 +--- src/ir/context.rs | 8 ++++---- src/ir/item.rs | 2 +- src/lib.rs | 2 +- 5 files changed, 8 insertions(+), 10 deletions(-) diff --git a/build.rs b/build.rs index fcc0bb2217..8c05d59b4c 100644 --- a/build.rs +++ b/build.rs @@ -85,6 +85,6 @@ fn main() { ); println!( "cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_{}", - std::env::var("TARGET").unwrap().replace("-", "_") + std::env::var("TARGET").unwrap().replace('-', "_") ); } diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 4dd520368b..eee9f0986b 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -4095,9 +4095,7 @@ fn objc_method_codegen( let body = if method.is_class_method() { let class_name = ctx.rust_ident( - class_name - .expect("Generating a class method without class name?") - .to_owned(), + class_name.expect("Generating a class method without class name?"), ); quote! { msg_send!(class!(#class_name), #methods_and_args) diff --git a/src/ir/context.rs b/src/ir/context.rs index 9cf43ec3c6..3bfe549b28 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -597,7 +597,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// Returns the pointer width to use for the target for the current /// translation. pub fn target_pointer_size(&self) -> usize { - return self.target_info.pointer_width / 8; + self.target_info.pointer_width / 8 } /// Get the stack of partially parsed types that we are in the middle of @@ -836,9 +836,9 @@ If you encounter an error missing from this list, please file an issue or a PR!" ) { let mut s = name.to_owned(); - s = s.replace("@", "_"); - s = s.replace("?", "_"); - s = s.replace("$", "_"); + s = s.replace('@', "_"); + s = s.replace('?', "_"); + s = s.replace('$', "_"); s.push('_'); return Cow::Owned(s); } diff --git a/src/ir/item.rs b/src/ir/item.rs index 6ce420171f..3b15cd6ed6 100644 --- a/src/ir/item.rs +++ b/src/ir/item.rs @@ -1899,7 +1899,7 @@ impl ClangItemParser for Item { // See tests/headers/const_tparam.hpp and // tests/headers/variadic_tname.hpp. - let name = ty_spelling.replace("const ", "").replace(".", ""); + let name = ty_spelling.replace("const ", "").replace('.', ""); let id = with_id.unwrap_or_else(|| ctx.next_item_id()); let item = Item::new( diff --git a/src/lib.rs b/src/lib.rs index 0742217fe1..3d09ab71f1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2714,7 +2714,7 @@ fn get_target_dependent_env_var(var: &str) -> Option { return Some(v); } if let Ok(v) = - env::var(&format!("{}_{}", var, target.replace("-", "_"))) + env::var(&format!("{}_{}", var, target.replace('-', "_"))) { return Some(v); } From 3b99dd541023059d575da45ac4d71925a65df57d Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Thu, 2 Jun 2022 06:51:35 -0400 Subject: [PATCH 296/942] Skip generated files in Linguist statistics [skip ci] --- tests/expectations/tests/.gitattributes | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 tests/expectations/tests/.gitattributes diff --git a/tests/expectations/tests/.gitattributes b/tests/expectations/tests/.gitattributes new file mode 100644 index 0000000000..9699dfa001 --- /dev/null +++ b/tests/expectations/tests/.gitattributes @@ -0,0 +1,2 @@ +# Prevent Github Linguist from counting generated files in statistics. +*.rs linguist-generated From aba2c29fd330b005b0e88b4e585bfe0ea86f3d5e Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Thu, 2 Jun 2022 06:51:43 -0400 Subject: [PATCH 297/942] Skip input headers in Linguist statistics [skip ci] --- bindgen-integration/.gitattributes | 4 ++++ tests/.gitattributes | 4 ++++ 2 files changed, 8 insertions(+) create mode 100644 bindgen-integration/.gitattributes create mode 100644 tests/.gitattributes diff --git a/bindgen-integration/.gitattributes b/bindgen-integration/.gitattributes new file mode 100644 index 0000000000..d42187e6fe --- /dev/null +++ b/bindgen-integration/.gitattributes @@ -0,0 +1,4 @@ +# Tell Github Linguist to avoid counting these C and C++ test inputs toward +# statistics. +*.h -linguist-detectable +*.cc -linguist-detectable diff --git a/tests/.gitattributes b/tests/.gitattributes new file mode 100644 index 0000000000..96122eb1da --- /dev/null +++ b/tests/.gitattributes @@ -0,0 +1,4 @@ +# Tell Github Linguist to avoid counting these C and C++ test inputs toward +# statistics. +*.h -linguist-detectable +*.hpp -linguist-detectable From 566d2266f68f5115329d1a1f6bb6f0a3217d80a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sat, 18 Dec 2021 00:48:19 +0100 Subject: [PATCH 298/942] options: Implement --version manually and print clang version on --version --verbose Fixes #2138 --- src/options.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/options.rs b/src/options.rs index 081aad61da..4e1fb93fbe 100644 --- a/src/options.rs +++ b/src/options.rs @@ -23,13 +23,13 @@ where ); let matches = App::new("bindgen") - .version(option_env!("CARGO_PKG_VERSION").unwrap_or("unknown")) .about("Generates Rust bindings from C/C++ headers.") + .setting(clap::AppSettings::NoAutoVersion) .override_usage("bindgen [FLAGS] [OPTIONS]
-- ...") .args(&[ Arg::new("header") .help("C or C++ header file") - .required(true), + .required_unless_present("V"), Arg::new("depfile") .long("depfile") .takes_value(true) @@ -545,9 +545,24 @@ where Arg::new("vtable-generation") .long("vtable-generation") .help("Enables generation of vtable functions."), + Arg::new("V") + .long("version") + .help("Prints the version, and exits"), ]) // .args() .get_matches_from(args); + let verbose = matches.is_present("verbose"); + if matches.is_present("V") { + println!( + "bindgen {}", + option_env!("CARGO_PKG_VERSION").unwrap_or("unknown") + ); + if verbose { + println!("Clang: {}", crate::clang_version().full); + } + std::process::exit(0); + } + let mut builder = builder(); if let Some(header) = matches.value_of("header") { @@ -1015,7 +1030,5 @@ where builder = builder.vtable_generation(true); } - let verbose = matches.is_present("verbose"); - Ok((builder, output, verbose)) } From 355181134094202e0caae60c1fbf145d8e6ca84b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 5 Jun 2022 20:23:04 +0200 Subject: [PATCH 299/942] v0.60.0 Closes #2209 --- CHANGELOG.md | 158 +++++++++++++++++++++++++++++++-------------------- Cargo.lock | 2 +- Cargo.toml | 2 +- 3 files changed, 98 insertions(+), 64 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f206c9cc0..ad78c1de75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,109 +1,112 @@ - - [Unreleased](#unreleased) - [Added](#added) - - [Fixed](#fixed) - [Changed](#changed) - - [Deprecated](#deprecated) - [Removed](#removed) - - [Fixed](#fixed-1) + - [Fixed](#fixed) - [Security](#security) +- [0.60.0](#0600) + - [Added](#added-1) + - [Fixed](#fixed-1) + - [Changed](#changed-1) + - [Removed](#removed-1) +- [0.59.2](#0592) - [0.59.1](#0591) - [Fixed](#fixed-2) - [0.59.0](#0590) - - [Added](#added-1) + - [Added](#added-2) - [Fixed](#fixed-3) - - [Changed](#changed-1) + - [Changed](#changed-2) - [0.58.1](#0581) - - [Added](#added-2) -- [0.58.0](#0580) - [Added](#added-3) +- [0.58.0](#0580) + - [Added](#added-4) - [Fixed](#fixed-4) - - [Changed](#changed-2) - - [Deprecated](#deprecated-1) - - [Removed](#removed-1) + - [Changed](#changed-3) + - [Deprecated](#deprecated) + - [Removed](#removed-2) - [Fixed](#fixed-5) - [Security](#security-1) - [0.57.0](#0570) - - [Added](#added-4) + - [Added](#added-5) - [Fixed](#fixed-6) - [0.56.0](#0560) - - [Added](#added-5) - - [Changed](#changed-3) + - [Added](#added-6) + - [Changed](#changed-4) - [Fixed](#fixed-7) - [0.55.1](#0551) - [Fixed](#fixed-8) - [0.55.0](#0550) - - [Removed](#removed-2) - - [Added](#added-6) - - [Changed](#changed-4) - - [Fixed](#fixed-9) -- [0.54.1](#0541) + - [Removed](#removed-3) - [Added](#added-7) - [Changed](#changed-5) - - [Fixed](#fixed-10) -- [0.54.0](#0540) + - [Fixed](#fixed-9) +- [0.54.1](#0541) - [Added](#added-8) - [Changed](#changed-6) + - [Fixed](#fixed-10) +- [0.54.0](#0540) + - [Added](#added-9) + - [Changed](#changed-7) - [Fixed](#fixed-11) - [0.53.3](#0533) - - [Added](#added-9) + - [Added](#added-10) - [Fixed](#fixed-12) - [0.53.2](#0532) - - [Changed](#changed-7) + - [Changed](#changed-8) - [0.53.1](#0531) - - [Added](#added-10) -- [0.53.0](#0530) - [Added](#added-11) - - [Changed](#changed-8) - - [Fixed](#fixed-13) -- [0.52.0](#0520) +- [0.53.0](#0530) - [Added](#added-12) - [Changed](#changed-9) + - [Fixed](#fixed-13) +- [0.52.0](#0520) + - [Added](#added-13) + - [Changed](#changed-10) - [Fixed](#fixed-14) - [0.51.1](#0511) - [Fixed](#fixed-15) - - [Changed](#changed-10) + - [Changed](#changed-11) - [0.51.0](#0510) - [Fixed](#fixed-16) - - [Changed](#changed-11) - - [Added](#added-13) -- [0.50.0](#0500) + - [Changed](#changed-12) - [Added](#added-14) -- [0.49.3](#0493) +- [0.50.0](#0500) - [Added](#added-15) +- [0.49.3](#0493) + - [Added](#added-16) - [0.49.2](#0492) - - [Changed](#changed-12) + - [Changed](#changed-13) - [0.49.1](#0491) - [Fixed](#fixed-17) - - [Changed](#changed-13) + - [Changed](#changed-14) - [0.49.0](#0490) - - [Added](#added-16) + - [Added](#added-17) - [Fixed](#fixed-18) - - [Changed](#changed-14) + - [Changed](#changed-15) - [0.48.1](#0481) - [Fixed](#fixed-19) - [0.48.0](#0480) - - [Changed](#changed-15) + - [Changed](#changed-16) - [Fixed](#fixed-20) - [0.47.4](#0474) - - [Added](#added-17) + - [Added](#added-18) - [0.47.3](#0473) - - [Changed](#changed-16) + - [Changed](#changed-17) - [0.47.2](#0472) - [Fixed](#fixed-21) - [0.47.1](#0471) - - [Changed](#changed-17) + - [Changed](#changed-18) - [Fixed](#fixed-22) - [0.47.0](#0470) - - [Changed](#changed-18) + - [Changed](#changed-19) - [Fixed](#fixed-23) - [0.33.1 .. 0.46.0](#0331--0460) - - [Added](#added-18) - - [Removed](#removed-3) - - [Changed](#changed-19) + - [Added](#added-19) + - [Removed](#removed-4) + - [Changed](#changed-20) - [Fixed](#fixed-24) - [0.33.1](#0331) - [Fixed](#fixed-25) @@ -113,23 +116,23 @@ - [0.32.1](#0321) - [Fixed](#fixed-27) - [0.32.0](#0320) - - [Added](#added-19) - - [Changed](#changed-20) - - [Fixed](#fixed-28) -- [0.31.0](#0310) - [Added](#added-20) - [Changed](#changed-21) - - [Deprecated](#deprecated-2) - - [Removed](#removed-4) - - [Fixed](#fixed-29) -- [0.30.0](#0300) + - [Fixed](#fixed-28) +- [0.31.0](#0310) - [Added](#added-21) - [Changed](#changed-22) - - [Deprecated](#deprecated-3) - - [Fixed](#fixed-30) -- [0.29.0](#0290) + - [Deprecated](#deprecated-1) + - [Removed](#removed-5) + - [Fixed](#fixed-29) +- [0.30.0](#0300) - [Added](#added-22) - [Changed](#changed-23) + - [Deprecated](#deprecated-2) + - [Fixed](#fixed-30) +- [0.29.0](#0290) + - [Added](#added-23) + - [Changed](#changed-24) - [Fixed](#fixed-31) @@ -138,29 +141,60 @@ # Unreleased +## Added + +## Changed + +## Removed + +## Fixed + +## Security + +# 0.60.0 + +Released 2022/06/05 + ## Added * Objective-C structs now derive `Debug` and `Copy` to support C and Objective-C structs. [(#2176)][] + * Allow fully-qualified derives. (#2156) + * Bindings generation now returns a more suitable error (#2125) + * `--version --verbose` now prints clang version (#2140). + * Experimental vtable generation (#2145). + * Added an `--allowlist-file` option (#2122). + * Support for vectorcall ABI (#2177). ## Fixed * Fixed lifetimes with Objective-C trait templates. [(#2176)][] * Fixed objc imports for non-`#[macro_use]` use. [(#2176)][] + * Handle differences between clang and rustc targets for RISCV (#2137). + * `BINDGEN_EXTRA_CLANG_ARGS` is respected on the CLI now (#1723). + * Use common type alias for anonymous enums in consts mode (#2191) + * Look for `#[must_use]` in typedefs (#2206). + * Fixed derive on packed structs (#2083). + * Fixed warnings on layout tests (#2203). ## Changed - * cexpr and nom have been updated, new msrv is 1.46 (#2107). - -## Deprecated + * cexpr, clap, and nom have been updated, new msrv is 1.54. ## Removed -## Fixed + * Support for ancient libclang versions has been removed. -## Security + [(#2176)]: https://github.com/rust-lang/rust-bindgen/pull/2176 +# 0.59.2 - [(#2176)]: https://github.com/rust-lang/rust-bindgen/pull/2176 +Released 2021/11/26 + + * cexpr+env_logger bump. + * Various fixes for C++ crashes / hangs. + * Enums now respect annotations and derives properly in more cases. + * Some more APIs (blocklist-file, etc). + * 'static lifetime is elided when appropriate. # 0.59.1 diff --git a/Cargo.lock b/Cargo.lock index 47a73bc68a..cf52a6f3a4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -30,7 +30,7 @@ checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" [[package]] name = "bindgen" -version = "0.59.2" +version = "0.60.0" dependencies = [ "bitflags", "cexpr", diff --git a/Cargo.toml b/Cargo.toml index 82f9dc17eb..302b73bb00 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ readme = "README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.59.2" +version = "0.60.0" edition = "2018" build = "build.rs" From ae1b386f865e048b1ba2dbea93c621c6a68dfdf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 6 Jun 2022 12:23:25 +0200 Subject: [PATCH 300/942] codegen: tests: Put each individual field test in a function. So that rustc doesn't take too much stack space without optimizations. Fixes #2218 --- src/codegen/mod.rs | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index eee9f0986b..ee4a6bfd42 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -2176,19 +2176,23 @@ impl CodeGenerator for CompInfo { { vec![] } else { - let asserts = self.fields() - .iter() - .filter_map(|field| match *field { - Field::DataMember(ref f) if f.name().is_some() => Some(f), - _ => None, - }) - .flat_map(|field| { - let name = field.name().unwrap(); - field.offset().map(|offset| { - let field_offset = offset / 8; - let field_name = ctx.rust_ident(name); - - quote! { + self.fields() + .iter() + .filter_map(|field| match *field { + Field::DataMember(ref f) if f.name().is_some() => Some(f), + _ => None, + }) + .flat_map(|field| { + let name = field.name().unwrap(); + field.offset().map(|offset| { + let field_offset = offset / 8; + let field_name = ctx.rust_ident(name); + // Put each check in its own function, so + // that rustc with opt-level=0 doesn't take + // too much stack space, see #2218. + let test_fn = Ident::new(&format!("test_field_{}", name), Span::call_site()); + quote! { + fn #test_fn() { assert_eq!( unsafe { let uninit = ::#prefix::mem::MaybeUninit::<#canonical_ident>::uninit(); @@ -2199,11 +2203,11 @@ impl CodeGenerator for CompInfo { concat!("Offset of field: ", stringify!(#canonical_ident), "::", stringify!(#field_name)) ); } - }) + #test_fn(); + } }) - .collect::>(); - - asserts + }) + .collect::>() }; let item = quote! { From 59babdd334a00ee71daa9ba44bc6db589a3a0450 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 6 Jun 2022 12:42:02 +0200 Subject: [PATCH 301/942] tests: Make some other tests auto-update with BINDGEN_OVERWRITE_EXPECTED=1 --- tests/tests.rs | 138 ++++++++++++++++++++++++++++++------------------- 1 file changed, 86 insertions(+), 52 deletions(-) diff --git a/tests/tests.rs b/tests/tests.rs index 5611baaf62..cc64cfdd29 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -115,6 +115,62 @@ The latest `rustfmt` is required to run the `bindgen` test suite. Install (bindings, stderr) } +fn should_overwrite_expected() -> bool { + if let Some(var) = env::var_os("BINDGEN_OVERWRITE_EXPECTED") { + if var == "1" { + return true; + } + if var != "0" && var != "" { + panic!("Invalid value of BINDGEN_OVERWRITE_EXPECTED"); + } + } + false +} + +fn error_diff_mismatch( + actual: &str, + expected: &str, + header: Option<&Path>, + filename: &Path, +) -> Result<(), Error> { + println!("diff expected generated"); + println!("--- expected: {:?}", filename); + if let Some(header) = header { + println!("+++ generated from: {:?}", header); + } + + for diff in diff::lines(&expected, &actual) { + match diff { + diff::Result::Left(l) => println!("-{}", l), + diff::Result::Both(l, _) => println!(" {}", l), + diff::Result::Right(r) => println!("+{}", r), + } + } + + if should_overwrite_expected() { + // Overwrite the expectation with actual output. + let mut expectation_file = fs::File::create(filename)?; + expectation_file.write_all(actual.as_bytes())?; + } + + if let Some(var) = env::var_os("BINDGEN_TESTS_DIFFTOOL") { + //usecase: var = "meld" -> You can hand check differences + let name = match filename.components().last() { + Some(std::path::Component::Normal(name)) => name, + _ => panic!("Why is the header variable so weird?"), + }; + let actual_result_path = + PathBuf::from(env::var("OUT_DIR").unwrap()).join(name); + let mut actual_result_file = fs::File::create(&actual_result_path)?; + actual_result_file.write_all(actual.as_bytes())?; + std::process::Command::new(var) + .args(&[filename, &actual_result_path]) + .output()?; + } + + return Err(Error::new(ErrorKind::Other, "Header and binding differ! Run with BINDGEN_OVERWRITE_EXPECTED=1 in the environment to automatically overwrite the expectation or with BINDGEN_TESTS_DIFFTOOL=meld to do this manually.")); +} + fn compare_generated_header( header: &Path, builder: BuilderState, @@ -211,46 +267,12 @@ fn compare_generated_header( if actual != expected { println!("{}", rustfmt_stderr); - - println!("diff expected generated"); - println!("--- expected: {:?}", looked_at.last().unwrap()); - println!("+++ generated from: {:?}", header); - - for diff in diff::lines(&expected, &actual) { - match diff { - diff::Result::Left(l) => println!("-{}", l), - diff::Result::Both(l, _) => println!(" {}", l), - diff::Result::Right(r) => println!("+{}", r), - } - } - - if let Some(var) = env::var_os("BINDGEN_OVERWRITE_EXPECTED") { - if var == "1" { - // Overwrite the expectation with actual output. - let mut expectation_file = - fs::File::create(looked_at.last().unwrap())?; - expectation_file.write_all(actual.as_bytes())?; - } else if var != "0" && var != "" { - panic!("Invalid value of BINDGEN_OVERWRITE_EXPECTED"); - } - } - - if let Some(var) = env::var_os("BINDGEN_TESTS_DIFFTOOL") { - //usecase: var = "meld" -> You can hand check differences - let filename = match header.components().last() { - Some(std::path::Component::Normal(name)) => name, - _ => panic!("Why is the header variable so weird?"), - }; - let actual_result_path = - PathBuf::from(env::var("OUT_DIR").unwrap()).join(filename); - let mut actual_result_file = fs::File::create(&actual_result_path)?; - actual_result_file.write_all(actual.as_bytes())?; - std::process::Command::new(var) - .args(&[looked_at.last().unwrap(), &actual_result_path]) - .output()?; - } - - return Err(Error::new(ErrorKind::Other, "Header and binding differ! Run with BINDGEN_OVERWRITE_EXPECTED=1 in the environment to automatically overwrite the expectation or with BINDGEN_TESTS_DIFFTOOL=meld to do this manually.")); + return error_diff_mismatch( + &actual, + &expected, + Some(header), + looked_at.last().unwrap(), + ); } if let Some(roundtrip_builder) = roundtrip_builder { @@ -485,6 +507,10 @@ fn test_multiple_header_calls_in_builder() { let (actual, stderr) = rustfmt(actual); println!("{}", stderr); + let expected_filename = concat!( + env!("CARGO_MANIFEST_DIR"), + "/tests/expectations/tests/test_multiple_header_calls_in_builder.rs" + ); let expected = include_str!(concat!( env!("CARGO_MANIFEST_DIR"), "/tests/expectations/tests/test_multiple_header_calls_in_builder.rs" @@ -493,16 +519,13 @@ fn test_multiple_header_calls_in_builder() { if actual != expected { println!("Generated bindings differ from expected!"); - - for diff in diff::lines(&actual, &expected) { - match diff { - diff::Result::Left(l) => println!("-{}", l), - diff::Result::Both(l, _) => println!(" {}", l), - diff::Result::Right(r) => println!("+{}", r), - } - } - - panic!(); + error_diff_mismatch( + &actual, + &expected, + None, + Path::new(expected_filename), + ) + .unwrap(); } } @@ -551,13 +574,24 @@ fn test_mixed_header_and_header_contents() { let (actual, stderr) = rustfmt(actual); println!("{}", stderr); + let expected_filename = concat!( + env!("CARGO_MANIFEST_DIR"), + "/tests/expectations/tests/test_mixed_header_and_header_contents.rs" + ); let expected = include_str!(concat!( env!("CARGO_MANIFEST_DIR"), "/tests/expectations/tests/test_mixed_header_and_header_contents.rs" )); let (expected, _) = rustfmt(expected.to_string()); - - assert_eq!(expected, actual); + if expected != actual { + error_diff_mismatch( + &actual, + &expected, + None, + Path::new(expected_filename), + ) + .unwrap(); + } } #[test] From 0e459610d730a2f8d86eaf952fda527d3e76e50b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 6 Jun 2022 12:42:31 +0200 Subject: [PATCH 302/942] Update test expectations. --- tests/expectations/tests/16-byte-alignment.rs | 402 +-- .../tests/16-byte-alignment_1_0.rs | 402 +-- tests/expectations/tests/accessors.rs | 463 +-- tests/expectations/tests/allowlist-file.rs | 101 +- .../tests/allowlist-namespaces.rs | 32 +- .../allowlisted-item-references-no-hash.rs | 31 +- ...llowlisted-item-references-no-partialeq.rs | 31 +- .../allowlisted_item_references_no_copy.rs | 31 +- tests/expectations/tests/annotation_hide.rs | 31 +- .../expectations/tests/anon-fields-prefix.rs | 224 +- tests/expectations/tests/anon_enum.rs | 52 +- .../tests/anon_struct_in_union.rs | 86 +- .../tests/anon_struct_in_union_1_0.rs | 86 +- .../tests/array-of-zero-sized-types.rs | 32 +- .../tests/bindgen-union-inside-namespace.rs | 62 +- tests/expectations/tests/bitfield-linux-32.rs | 26 +- tests/expectations/tests/bitfield_align.rs | 115 +- .../tests/blocklist-and-impl-debug.rs | 34 +- tests/expectations/tests/blocklist-file.rs | 128 +- tests/expectations/tests/blocks-signature.rs | 68 +- tests/expectations/tests/blocks.rs | 68 +- tests/expectations/tests/c_naming.rs | 93 +- tests/expectations/tests/canonical-types.rs | 93 +- tests/expectations/tests/char.rs | 307 +- tests/expectations/tests/class.rs | 340 ++- tests/expectations/tests/class_1_0.rs | 340 ++- tests/expectations/tests/class_nested.rs | 114 +- tests/expectations/tests/class_no_members.rs | 34 +- tests/expectations/tests/class_use_as.rs | 62 +- tests/expectations/tests/class_with_dtor.rs | 33 +- .../tests/class_with_inner_struct.rs | 574 ++-- .../tests/class_with_inner_struct_1_0.rs | 574 ++-- .../expectations/tests/class_with_typedef.rs | 136 +- tests/expectations/tests/comment-indent.rs | 32 +- tests/expectations/tests/complex.rs | 124 +- .../expectations/tests/const-const-mut-ptr.rs | 26 +- .../tests/constified-enum-module-overflow.rs | 21 +- .../expectations/tests/constify-all-enums.rs | 33 +- .../tests/constify-module-enums-basic.rs | 33 +- .../tests/constify-module-enums-namespace.rs | 35 +- .../constify-module-enums-shadow-name.rs | 31 +- .../constify-module-enums-simple-alias.rs | 228 +- ...onstify-module-enums-simple-nonamespace.rs | 52 +- .../tests/constify-module-enums-types.rs | 367 ++- .../tests/contains-vs-inherits-zero-sized.rs | 93 +- tests/expectations/tests/convert-floats.rs | 173 +- .../expectations/tests/ctypes-prefix-path.rs | 68 +- .../tests/derive-bitfield-method-same-name.rs | 31 +- tests/expectations/tests/derive-clone.rs | 32 +- tests/expectations/tests/derive-clone_1_0.rs | 32 +- .../tests/derive-debug-bitfield-core.rs | 32 +- .../tests/derive-debug-bitfield.rs | 31 +- .../tests/derive-debug-function-pointer.rs | 62 +- .../tests/derive-debug-mangle-name.rs | 130 +- ...ive-debug-opaque-template-instantiation.rs | 31 +- .../expectations/tests/derive-debug-opaque.rs | 31 +- .../tests/derive-default-and-blocklist.rs | 33 +- tests/expectations/tests/derive-fn-ptr.rs | 62 +- .../tests/derive-hash-and-blocklist.rs | 33 +- .../tests/derive-hash-blocklisting.rs | 64 +- ...rive-hash-struct-with-anon-struct-float.rs | 90 +- .../derive-hash-struct-with-float-array.rs | 26 +- ...erive-hash-struct-with-incomplete-array.rs | 54 +- .../tests/derive-hash-struct-with-pointer.rs | 127 +- .../tests/derive-hash-template-inst-float.rs | 57 +- .../tests/derive-partialeq-and-blocklist.rs | 34 +- .../tests/derive-partialeq-base.rs | 31 +- .../tests/derive-partialeq-bitfield.rs | 31 +- .../tests/derive-partialeq-core.rs | 32 +- .../tests/derive-partialeq-pointer.rs | 42 +- .../tests/derive-partialeq-union.rs | 68 +- .../tests/derive-partialeq-union_1_0.rs | 66 +- .../tests/disable-nested-struct-naming.rs | 322 +- .../tests/disable-untagged-union.rs | 52 +- .../expectations/tests/do-not-derive-copy.rs | 35 +- tests/expectations/tests/doggo-or-null.rs | 26 +- .../duplicated-namespaces-definitions.rs | 93 +- .../tests/dynamic_loading_with_blocklist.rs | 21 +- .../tests/dynamic_loading_with_class.rs | 21 +- .../tests/enum-default-bitfield.rs | 31 +- .../expectations/tests/enum-default-consts.rs | 31 +- .../expectations/tests/enum-default-module.rs | 31 +- tests/expectations/tests/enum-default-rust.rs | 31 +- .../expectations/tests/enum-no-debug-rust.rs | 31 +- tests/expectations/tests/enum.rs | 31 +- .../tests/enum_and_vtable_mangling.rs | 21 +- tests/expectations/tests/explicit-padding.rs | 186 +- .../expectations/tests/extern-const-struct.rs | 31 +- .../tests/forward-declaration-autoptr.rs | 31 +- .../tests/forward_declared_complex_types.rs | 21 +- .../forward_declared_complex_types_1_0.rs | 21 +- .../tests/forward_declared_struct.rs | 42 +- .../expectations/tests/func_ptr_in_struct.rs | 26 +- .../expectations/tests/gen-destructors-neg.rs | 26 +- tests/expectations/tests/gen-destructors.rs | 26 +- tests/expectations/tests/i128.rs | 62 +- tests/expectations/tests/inline_namespace.rs | 31 +- .../tests/inline_namespace_conservative.rs | 31 +- tests/expectations/tests/inner_const.rs | 26 +- .../expectations/tests/inner_template_self.rs | 31 +- .../tests/issue-1118-using-forward-decl.rs | 62 +- .../tests/issue-1216-variadic-member.rs | 21 +- tests/expectations/tests/issue-1281.rs | 68 +- tests/expectations/tests/issue-1285.rs | 90 +- tests/expectations/tests/issue-1291.rs | 455 +-- .../tests/issue-1382-rust-primitive-types.rs | 384 ++- tests/expectations/tests/issue-1443.rs | 168 +- tests/expectations/tests/issue-1454.rs | 31 +- tests/expectations/tests/issue-1498.rs | 254 +- tests/expectations/tests/issue-1947.rs | 93 +- .../tests/issue-1977-larger-arrays.rs | 31 +- tests/expectations/tests/issue-1995.rs | 26 +- tests/expectations/tests/issue-2019.rs | 42 +- tests/expectations/tests/issue-372.rs | 130 +- .../tests/issue-537-repr-packed-n.rs | 186 +- tests/expectations/tests/issue-537.rs | 186 +- .../tests/issue-573-layout-test-failures.rs | 31 +- .../issue-574-assertion-failure-in-codegen.rs | 31 +- ...issue-584-stylo-template-analysis-panic.rs | 21 +- .../tests/issue-639-typedef-anon-field.rs | 88 +- .../tests/issue-643-inner-struct.rs | 62 +- .../issue-648-derive-debug-with-padding.rs | 101 +- tests/expectations/tests/issue-674-1.rs | 34 +- tests/expectations/tests/issue-674-2.rs | 52 +- tests/expectations/tests/issue-674-3.rs | 58 +- .../tests/issue-801-opaque-sloppiness.rs | 21 +- ...07-opaque-types-methods-being-generated.rs | 31 +- .../issue-944-derive-copy-and-blocklisting.rs | 32 +- .../expectations/tests/jsval_layout_opaque.rs | 387 +-- .../tests/jsval_layout_opaque_1_0.rs | 387 +-- tests/expectations/tests/layout_align.rs | 31 +- tests/expectations/tests/layout_arp.rs | 341 ++- tests/expectations/tests/layout_array.rs | 479 +-- .../tests/layout_array_too_long.rs | 467 +-- .../tests/layout_cmdline_token.rs | 292 +- tests/expectations/tests/layout_eth_conf.rs | 2705 +++++++++-------- .../expectations/tests/layout_eth_conf_1_0.rs | 2705 +++++++++-------- tests/expectations/tests/layout_kni_mbuf.rs | 435 +-- .../tests/layout_large_align_field.rs | 1075 ++++--- tests/expectations/tests/layout_mbuf.rs | 1168 +++---- tests/expectations/tests/layout_mbuf_1_0.rs | 1168 +++---- .../tests/libclang-5/call-conv-field.rs | 66 +- .../type_alias_template_specialized.rs | 31 +- .../tests/libclang-9/call-conv-field.rs | 66 +- tests/expectations/tests/libclang-9/class.rs | 833 ++--- .../tests/libclang-9/class_1_0.rs | 833 ++--- ...erive-hash-struct-with-incomplete-array.rs | 205 +- .../libclang-9/incomplete-array-padding.rs | 21 +- .../libclang-9/issue-643-inner-struct.rs | 186 +- .../tests/libclang-9/layout_align.rs | 186 +- .../type_alias_template_specialized.rs | 31 +- .../tests/libclang-9/zero-sized-array.rs | 131 +- tests/expectations/tests/long_double.rs | 26 +- tests/expectations/tests/msvc-no-usr.rs | 21 +- tests/expectations/tests/mutable.rs | 128 +- tests/expectations/tests/namespace.rs | 31 +- tests/expectations/tests/nested.rs | 83 +- .../tests/nested_within_namespace.rs | 94 +- tests/expectations/tests/no-comments.rs | 21 +- tests/expectations/tests/no-derive-debug.rs | 52 +- tests/expectations/tests/no-derive-default.rs | 52 +- .../expectations/tests/no-hash-allowlisted.rs | 26 +- .../tests/no-partialeq-allowlisted.rs | 31 +- .../tests/no-recursive-allowlisting.rs | 26 +- tests/expectations/tests/no-std.rs | 68 +- .../expectations/tests/no_copy_allowlisted.rs | 26 +- .../tests/no_debug_allowlisted.rs | 31 +- .../tests/no_default_allowlisted.rs | 31 +- tests/expectations/tests/non-type-params.rs | 95 +- .../expectations/tests/objc_interface_type.rs | 31 +- .../tests/opaque-template-inst-member-2.rs | 99 +- .../tests/opaque-template-inst-member.rs | 99 +- ...paque-template-instantiation-namespaced.rs | 133 +- .../tests/opaque-template-instantiation.rs | 68 +- tests/expectations/tests/opaque_in_struct.rs | 31 +- tests/expectations/tests/opaque_pointer.rs | 93 +- .../tests/packed-n-with-padding.rs | 104 +- tests/expectations/tests/private.rs | 189 +- tests/expectations/tests/private_fields.rs | 163 +- .../tests/reparented_replacement.rs | 32 +- tests/expectations/tests/replace_use.rs | 21 +- tests/expectations/tests/repr-align.rs | 84 +- ...ame_struct_name_in_different_namespaces.rs | 64 +- .../tests/sentry-defined-multiple-times.rs | 197 +- tests/expectations/tests/size_t_is_usize.rs | 68 +- tests/expectations/tests/size_t_template.rs | 21 +- ...ruct_containing_forward_declared_struct.rs | 52 +- tests/expectations/tests/struct_typedef.rs | 64 +- tests/expectations/tests/struct_typedef_ns.rs | 66 +- .../tests/struct_with_anon_struct.rs | 90 +- .../tests/struct_with_anon_struct_array.rs | 180 +- .../tests/struct_with_anon_struct_pointer.rs | 90 +- .../tests/struct_with_anon_union.rs | 90 +- .../tests/struct_with_anon_union_1_0.rs | 90 +- .../tests/struct_with_anon_unnamed_struct.rs | 64 +- .../tests/struct_with_anon_unnamed_union.rs | 64 +- .../struct_with_anon_unnamed_union_1_0.rs | 64 +- .../tests/struct_with_bitfields.rs | 31 +- .../tests/struct_with_derive_debug.rs | 125 +- .../tests/struct_with_large_array.rs | 31 +- .../expectations/tests/struct_with_nesting.rs | 263 +- .../tests/struct_with_nesting_1_0.rs | 263 +- .../expectations/tests/struct_with_packing.rs | 42 +- .../expectations/tests/struct_with_struct.rs | 90 +- tests/expectations/tests/template.rs | 583 ++-- .../test_mixed_header_and_header_contents.rs | 307 +- .../test_multiple_header_calls_in_builder.rs | 307 +- tests/expectations/tests/timex.rs | 62 +- ...type-referenced-by-allowlisted-function.rs | 31 +- tests/expectations/tests/typeref.rs | 90 +- tests/expectations/tests/typeref_1_0.rs | 90 +- tests/expectations/tests/underscore.rs | 26 +- tests/expectations/tests/union-align.rs | 52 +- tests/expectations/tests/union-in-ns.rs | 31 +- tests/expectations/tests/union-in-ns_1_0.rs | 31 +- tests/expectations/tests/union_dtor.rs | 62 +- tests/expectations/tests/union_dtor_1_0.rs | 62 +- tests/expectations/tests/union_fields.rs | 93 +- tests/expectations/tests/union_fields_1_0.rs | 93 +- .../tests/union_with_anon_struct.rs | 90 +- .../tests/union_with_anon_struct_1_0.rs | 90 +- .../tests/union_with_anon_struct_bitfield.rs | 21 +- .../union_with_anon_struct_bitfield_1_0.rs | 21 +- .../tests/union_with_anon_union.rs | 90 +- .../tests/union_with_anon_union_1_0.rs | 90 +- .../tests/union_with_anon_unnamed_struct.rs | 163 +- .../union_with_anon_unnamed_struct_1_0.rs | 163 +- .../tests/union_with_anon_unnamed_union.rs | 85 +- .../union_with_anon_unnamed_union_1_0.rs | 85 +- .../tests/union_with_big_member.rs | 186 +- .../tests/union_with_big_member_1_0.rs | 186 +- .../expectations/tests/union_with_nesting.rs | 161 +- .../tests/union_with_nesting_1_0.rs | 161 +- tests/expectations/tests/unknown_attr.rs | 66 +- tests/expectations/tests/use-core.rs | 132 +- tests/expectations/tests/use-core_1_0.rs | 132 +- tests/expectations/tests/var-tracing.rs | 31 +- tests/expectations/tests/vector.rs | 31 +- .../expectations/tests/virtual_inheritance.rs | 63 +- tests/expectations/tests/weird_bitfields.rs | 383 +-- .../tests/zero-size-array-align.rs | 93 +- tests/expectations/tests/zero-sized-array.rs | 65 +- 242 files changed, 19567 insertions(+), 15208 deletions(-) diff --git a/tests/expectations/tests/16-byte-alignment.rs b/tests/expectations/tests/16-byte-alignment.rs index c690cc8e87..6aa491d606 100644 --- a/tests/expectations/tests/16-byte-alignment.rs +++ b/tests/expectations/tests/16-byte-alignment.rs @@ -42,38 +42,44 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1() { stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1) ) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dport) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(dport) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).sport) as usize - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(sport) - ) - ); + fn test_field_dport() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dport) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(dport) + ) + ); + } + test_field_dport(); + fn test_field_sport() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).sport) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(sport) + ) + ); + } + test_field_sport(); } #[test] fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1() { @@ -87,22 +93,25 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(rte_ipv4_tuple__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).sctp_tag) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple__bindgen_ty_1), - "::", - stringify!(sctp_tag) - ) - ); + fn test_field_sctp_tag() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + rte_ipv4_tuple__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).sctp_tag) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv4_tuple__bindgen_ty_1), + "::", + stringify!(sctp_tag) + ) + ); + } + test_field_sctp_tag(); } impl Default for rte_ipv4_tuple__bindgen_ty_1 { fn default() -> Self { @@ -125,34 +134,42 @@ fn bindgen_test_layout_rte_ipv4_tuple() { 4usize, concat!("Alignment of ", stringify!(rte_ipv4_tuple)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).src_addr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple), - "::", - stringify!(src_addr) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dst_addr) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple), - "::", - stringify!(dst_addr) - ) - ); + fn test_field_src_addr() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).src_addr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv4_tuple), + "::", + stringify!(src_addr) + ) + ); + } + test_field_src_addr(); + fn test_field_dst_addr() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dst_addr) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv4_tuple), + "::", + stringify!(dst_addr) + ) + ); + } + test_field_dst_addr(); } impl Default for rte_ipv4_tuple { fn default() -> Self { @@ -200,38 +217,44 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1() { stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1) ) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dport) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(dport) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).sport) as usize - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(sport) - ) - ); + fn test_field_dport() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dport) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(dport) + ) + ); + } + test_field_dport(); + fn test_field_sport() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).sport) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(sport) + ) + ); + } + test_field_sport(); } #[test] fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1() { @@ -245,22 +268,25 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(rte_ipv6_tuple__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).sctp_tag) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple__bindgen_ty_1), - "::", - stringify!(sctp_tag) - ) - ); + fn test_field_sctp_tag() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + rte_ipv6_tuple__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).sctp_tag) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv6_tuple__bindgen_ty_1), + "::", + stringify!(sctp_tag) + ) + ); + } + test_field_sctp_tag(); } impl Default for rte_ipv6_tuple__bindgen_ty_1 { fn default() -> Self { @@ -283,34 +309,42 @@ fn bindgen_test_layout_rte_ipv6_tuple() { 4usize, concat!("Alignment of ", stringify!(rte_ipv6_tuple)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).src_addr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple), - "::", - stringify!(src_addr) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dst_addr) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple), - "::", - stringify!(dst_addr) - ) - ); + fn test_field_src_addr() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).src_addr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv6_tuple), + "::", + stringify!(src_addr) + ) + ); + } + test_field_src_addr(); + fn test_field_dst_addr() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dst_addr) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv6_tuple), + "::", + stringify!(dst_addr) + ) + ); + } + test_field_dst_addr(); } impl Default for rte_ipv6_tuple { fn default() -> Self { @@ -340,34 +374,42 @@ fn bindgen_test_layout_rte_thash_tuple() { 16usize, concat!("Alignment of ", stringify!(rte_thash_tuple)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).v4) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_thash_tuple), - "::", - stringify!(v4) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).v6) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_thash_tuple), - "::", - stringify!(v6) - ) - ); + fn test_field_v4() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).v4) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_thash_tuple), + "::", + stringify!(v4) + ) + ); + } + test_field_v4(); + fn test_field_v6() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).v6) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_thash_tuple), + "::", + stringify!(v6) + ) + ); + } + test_field_v6(); } impl Default for rte_thash_tuple { fn default() -> Self { diff --git a/tests/expectations/tests/16-byte-alignment_1_0.rs b/tests/expectations/tests/16-byte-alignment_1_0.rs index 304b6bc150..b798697a68 100644 --- a/tests/expectations/tests/16-byte-alignment_1_0.rs +++ b/tests/expectations/tests/16-byte-alignment_1_0.rs @@ -87,38 +87,44 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1() { stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1) ) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dport) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(dport) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).sport) as usize - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(sport) - ) - ); + fn test_field_dport() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dport) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(dport) + ) + ); + } + test_field_dport(); + fn test_field_sport() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).sport) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(sport) + ) + ); + } + test_field_sport(); } impl Clone for rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 { fn clone(&self) -> Self { @@ -137,22 +143,25 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(rte_ipv4_tuple__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).sctp_tag) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple__bindgen_ty_1), - "::", - stringify!(sctp_tag) - ) - ); + fn test_field_sctp_tag() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + rte_ipv4_tuple__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).sctp_tag) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv4_tuple__bindgen_ty_1), + "::", + stringify!(sctp_tag) + ) + ); + } + test_field_sctp_tag(); } impl Clone for rte_ipv4_tuple__bindgen_ty_1 { fn clone(&self) -> Self { @@ -171,34 +180,42 @@ fn bindgen_test_layout_rte_ipv4_tuple() { 4usize, concat!("Alignment of ", stringify!(rte_ipv4_tuple)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).src_addr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple), - "::", - stringify!(src_addr) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dst_addr) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple), - "::", - stringify!(dst_addr) - ) - ); + fn test_field_src_addr() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).src_addr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv4_tuple), + "::", + stringify!(src_addr) + ) + ); + } + test_field_src_addr(); + fn test_field_dst_addr() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dst_addr) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv4_tuple), + "::", + stringify!(dst_addr) + ) + ); + } + test_field_dst_addr(); } impl Clone for rte_ipv4_tuple { fn clone(&self) -> Self { @@ -244,38 +261,44 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1() { stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1) ) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dport) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(dport) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).sport) as usize - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(sport) - ) - ); + fn test_field_dport() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dport) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(dport) + ) + ); + } + test_field_dport(); + fn test_field_sport() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).sport) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(sport) + ) + ); + } + test_field_sport(); } impl Clone for rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 { fn clone(&self) -> Self { @@ -294,22 +317,25 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(rte_ipv6_tuple__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).sctp_tag) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple__bindgen_ty_1), - "::", - stringify!(sctp_tag) - ) - ); + fn test_field_sctp_tag() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + rte_ipv6_tuple__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).sctp_tag) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv6_tuple__bindgen_ty_1), + "::", + stringify!(sctp_tag) + ) + ); + } + test_field_sctp_tag(); } impl Clone for rte_ipv6_tuple__bindgen_ty_1 { fn clone(&self) -> Self { @@ -328,34 +354,42 @@ fn bindgen_test_layout_rte_ipv6_tuple() { 4usize, concat!("Alignment of ", stringify!(rte_ipv6_tuple)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).src_addr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple), - "::", - stringify!(src_addr) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dst_addr) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple), - "::", - stringify!(dst_addr) - ) - ); + fn test_field_src_addr() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).src_addr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv6_tuple), + "::", + stringify!(src_addr) + ) + ); + } + test_field_src_addr(); + fn test_field_dst_addr() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dst_addr) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv6_tuple), + "::", + stringify!(dst_addr) + ) + ); + } + test_field_dst_addr(); } impl Clone for rte_ipv6_tuple { fn clone(&self) -> Self { @@ -376,34 +410,42 @@ fn bindgen_test_layout_rte_thash_tuple() { 48usize, concat!("Size of: ", stringify!(rte_thash_tuple)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).v4) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_thash_tuple), - "::", - stringify!(v4) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).v6) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_thash_tuple), - "::", - stringify!(v6) - ) - ); + fn test_field_v4() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).v4) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_thash_tuple), + "::", + stringify!(v4) + ) + ); + } + test_field_v4(); + fn test_field_v6() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).v6) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_thash_tuple), + "::", + stringify!(v6) + ) + ); + } + test_field_v6(); } impl Clone for rte_thash_tuple { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/accessors.rs b/tests/expectations/tests/accessors.rs index 0771eceb59..843b792e68 100644 --- a/tests/expectations/tests/accessors.rs +++ b/tests/expectations/tests/accessors.rs @@ -28,64 +28,77 @@ fn bindgen_test_layout_SomeAccessors() { 4usize, concat!("Alignment of ", stringify!(SomeAccessors)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mNoAccessor) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(SomeAccessors), - "::", - stringify!(mNoAccessor) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBothAccessors) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(SomeAccessors), - "::", - stringify!(mBothAccessors) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mUnsafeAccessors) as usize - - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(SomeAccessors), - "::", - stringify!(mUnsafeAccessors) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mImmutableAccessor) as usize - - ptr as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(SomeAccessors), - "::", - stringify!(mImmutableAccessor) - ) - ); + fn test_field_mNoAccessor() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mNoAccessor) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(SomeAccessors), + "::", + stringify!(mNoAccessor) + ) + ); + } + test_field_mNoAccessor(); + fn test_field_mBothAccessors() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBothAccessors) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(SomeAccessors), + "::", + stringify!(mBothAccessors) + ) + ); + } + test_field_mBothAccessors(); + fn test_field_mUnsafeAccessors() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mUnsafeAccessors) as usize - + ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(SomeAccessors), + "::", + stringify!(mUnsafeAccessors) + ) + ); + } + test_field_mUnsafeAccessors(); + fn test_field_mImmutableAccessor() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mImmutableAccessor) as usize - + ptr as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(SomeAccessors), + "::", + stringify!(mImmutableAccessor) + ) + ); + } + test_field_mImmutableAccessor(); } impl SomeAccessors { #[inline] @@ -130,35 +143,42 @@ fn bindgen_test_layout_AllAccessors() { 4usize, concat!("Alignment of ", stringify!(AllAccessors)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBothAccessors) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AllAccessors), - "::", - stringify!(mBothAccessors) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mAlsoBothAccessors) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(AllAccessors), - "::", - stringify!(mAlsoBothAccessors) - ) - ); + fn test_field_mBothAccessors() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBothAccessors) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(AllAccessors), + "::", + stringify!(mBothAccessors) + ) + ); + } + test_field_mBothAccessors(); + fn test_field_mAlsoBothAccessors() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mAlsoBothAccessors) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(AllAccessors), + "::", + stringify!(mAlsoBothAccessors) + ) + ); + } + test_field_mAlsoBothAccessors(); } impl AllAccessors { #[inline] @@ -197,37 +217,44 @@ fn bindgen_test_layout_AllUnsafeAccessors() { 4usize, concat!("Alignment of ", stringify!(AllUnsafeAccessors)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBothAccessors) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AllUnsafeAccessors), - "::", - stringify!(mBothAccessors) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mAlsoBothAccessors) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(AllUnsafeAccessors), - "::", - stringify!(mAlsoBothAccessors) - ) - ); + fn test_field_mBothAccessors() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBothAccessors) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(AllUnsafeAccessors), + "::", + stringify!(mBothAccessors) + ) + ); + } + test_field_mBothAccessors(); + fn test_field_mAlsoBothAccessors() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mAlsoBothAccessors) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(AllUnsafeAccessors), + "::", + stringify!(mAlsoBothAccessors) + ) + ); + } + test_field_mAlsoBothAccessors(); } impl AllUnsafeAccessors { #[inline] @@ -275,68 +302,82 @@ fn bindgen_test_layout_ContradictAccessors() { 4usize, concat!("Alignment of ", stringify!(ContradictAccessors)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBothAccessors) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContradictAccessors), - "::", - stringify!(mBothAccessors) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mNoAccessors) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(ContradictAccessors), - "::", - stringify!(mNoAccessors) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mUnsafeAccessors) as usize - - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(ContradictAccessors), - "::", - stringify!(mUnsafeAccessors) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mImmutableAccessor) as usize - - ptr as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(ContradictAccessors), - "::", - stringify!(mImmutableAccessor) - ) - ); + fn test_field_mBothAccessors() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBothAccessors) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ContradictAccessors), + "::", + stringify!(mBothAccessors) + ) + ); + } + test_field_mBothAccessors(); + fn test_field_mNoAccessors() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mNoAccessors) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(ContradictAccessors), + "::", + stringify!(mNoAccessors) + ) + ); + } + test_field_mNoAccessors(); + fn test_field_mUnsafeAccessors() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mUnsafeAccessors) as usize - + ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(ContradictAccessors), + "::", + stringify!(mUnsafeAccessors) + ) + ); + } + test_field_mUnsafeAccessors(); + fn test_field_mImmutableAccessor() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mImmutableAccessor) as usize - + ptr as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(ContradictAccessors), + "::", + stringify!(mImmutableAccessor) + ) + ); + } + test_field_mImmutableAccessor(); } impl ContradictAccessors { #[inline] @@ -380,20 +421,23 @@ fn bindgen_test_layout_Replaced() { 4usize, concat!("Alignment of ", stringify!(Replaced)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mAccessor) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Replaced), - "::", - stringify!(mAccessor) - ) - ); + fn test_field_mAccessor() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mAccessor) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Replaced), + "::", + stringify!(mAccessor) + ) + ); + } + test_field_mAccessor(); } impl Replaced { #[inline] @@ -423,20 +467,23 @@ fn bindgen_test_layout_Wrapper() { 4usize, concat!("Alignment of ", stringify!(Wrapper)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mReplaced) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Wrapper), - "::", - stringify!(mReplaced) - ) - ); + fn test_field_mReplaced() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mReplaced) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Wrapper), + "::", + stringify!(mReplaced) + ) + ); + } + test_field_mReplaced(); } impl Wrapper { #[inline] diff --git a/tests/expectations/tests/allowlist-file.rs b/tests/expectations/tests/allowlist-file.rs index 462f690bc3..e737fe8251 100644 --- a/tests/expectations/tests/allowlist-file.rs +++ b/tests/expectations/tests/allowlist-file.rs @@ -68,22 +68,25 @@ fn bindgen_test_layout_StructWithAllowlistedDefinition() { 8usize, concat!("Alignment of ", stringify!(StructWithAllowlistedDefinition)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - StructWithAllowlistedDefinition, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).other) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(StructWithAllowlistedDefinition), - "::", - stringify!(other) - ) - ); + fn test_field_other() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + StructWithAllowlistedDefinition, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).other) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(StructWithAllowlistedDefinition), + "::", + stringify!(other) + ) + ); + } + test_field_other(); } impl Default for StructWithAllowlistedDefinition { fn default() -> Self { @@ -111,22 +114,25 @@ fn bindgen_test_layout_StructWithAllowlistedFwdDecl() { 4usize, concat!("Alignment of ", stringify!(StructWithAllowlistedFwdDecl)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(StructWithAllowlistedFwdDecl), - "::", - stringify!(b) - ) - ); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + StructWithAllowlistedFwdDecl, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(StructWithAllowlistedFwdDecl), + "::", + stringify!(b) + ) + ); + } + test_field_b(); } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -145,18 +151,21 @@ fn bindgen_test_layout_AllowlistMe() { 4usize, concat!("Alignment of ", stringify!(AllowlistMe)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AllowlistMe), - "::", - stringify!(foo) - ) - ); + fn test_field_foo() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(AllowlistMe), + "::", + stringify!(foo) + ) + ); + } + test_field_foo(); } diff --git a/tests/expectations/tests/allowlist-namespaces.rs b/tests/expectations/tests/allowlist-namespaces.rs index c789ec6353..ac868c646b 100644 --- a/tests/expectations/tests/allowlist-namespaces.rs +++ b/tests/expectations/tests/allowlist-namespaces.rs @@ -51,20 +51,24 @@ pub mod root { 1usize, concat!("Alignment of ", stringify!(Test)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).helper) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Test), - "::", - stringify!(helper) - ) - ); + fn test_field_helper() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).helper) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Test), + "::", + stringify!(helper) + ) + ); + } + test_field_helper(); } } } diff --git a/tests/expectations/tests/allowlisted-item-references-no-hash.rs b/tests/expectations/tests/allowlisted-item-references-no-hash.rs index d11fc5bea8..827016340f 100644 --- a/tests/expectations/tests/allowlisted-item-references-no-hash.rs +++ b/tests/expectations/tests/allowlisted-item-references-no-hash.rs @@ -40,18 +40,21 @@ fn bindgen_test_layout_AllowlistMe() { 1usize, concat!("Alignment of ", stringify!(AllowlistMe)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AllowlistMe), - "::", - stringify!(a) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(AllowlistMe), + "::", + stringify!(a) + ) + ); + } + test_field_a(); } diff --git a/tests/expectations/tests/allowlisted-item-references-no-partialeq.rs b/tests/expectations/tests/allowlisted-item-references-no-partialeq.rs index 8501c479d9..ec4e0c9d0f 100644 --- a/tests/expectations/tests/allowlisted-item-references-no-partialeq.rs +++ b/tests/expectations/tests/allowlisted-item-references-no-partialeq.rs @@ -40,18 +40,21 @@ fn bindgen_test_layout_AllowlistMe() { 1usize, concat!("Alignment of ", stringify!(AllowlistMe)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AllowlistMe), - "::", - stringify!(a) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(AllowlistMe), + "::", + stringify!(a) + ) + ); + } + test_field_a(); } diff --git a/tests/expectations/tests/allowlisted_item_references_no_copy.rs b/tests/expectations/tests/allowlisted_item_references_no_copy.rs index 3b8f4e71e3..9f6685ec48 100644 --- a/tests/expectations/tests/allowlisted_item_references_no_copy.rs +++ b/tests/expectations/tests/allowlisted_item_references_no_copy.rs @@ -40,18 +40,21 @@ fn bindgen_test_layout_AllowlistMe() { 1usize, concat!("Alignment of ", stringify!(AllowlistMe)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AllowlistMe), - "::", - stringify!(a) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(AllowlistMe), + "::", + stringify!(a) + ) + ); + } + test_field_a(); } diff --git a/tests/expectations/tests/annotation_hide.rs b/tests/expectations/tests/annotation_hide.rs index f2bc7be5a8..a899195e1a 100644 --- a/tests/expectations/tests/annotation_hide.rs +++ b/tests/expectations/tests/annotation_hide.rs @@ -42,18 +42,21 @@ fn bindgen_test_layout_NotAnnotated() { 4usize, concat!("Alignment of ", stringify!(NotAnnotated)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NotAnnotated), - "::", - stringify!(f) - ) - ); + fn test_field_f() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(NotAnnotated), + "::", + stringify!(f) + ) + ); + } + test_field_f(); } diff --git a/tests/expectations/tests/anon-fields-prefix.rs b/tests/expectations/tests/anon-fields-prefix.rs index e54459528c..a77bc8a753 100644 --- a/tests/expectations/tests/anon-fields-prefix.rs +++ b/tests/expectations/tests/anon-fields-prefix.rs @@ -31,51 +31,60 @@ fn bindgen_test_layout_color__bindgen_ty_1() { 1usize, concat!("Alignment of ", stringify!(color__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).r) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(color__bindgen_ty_1), - "::", - stringify!(r) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).g) as usize - ptr as usize - }, - 1usize, - concat!( - "Offset of field: ", - stringify!(color__bindgen_ty_1), - "::", - stringify!(g) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(color__bindgen_ty_1), - "::", - stringify!(b) - ) - ); + fn test_field_r() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).r) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(color__bindgen_ty_1), + "::", + stringify!(r) + ) + ); + } + test_field_r(); + fn test_field_g() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).g) as usize - ptr as usize + }, + 1usize, + concat!( + "Offset of field: ", + stringify!(color__bindgen_ty_1), + "::", + stringify!(g) + ) + ); + } + test_field_g(); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(color__bindgen_ty_1), + "::", + stringify!(b) + ) + ); + } + test_field_b(); } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -96,51 +105,60 @@ fn bindgen_test_layout_color__bindgen_ty_2() { 1usize, concat!("Alignment of ", stringify!(color__bindgen_ty_2)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(color__bindgen_ty_2), - "::", - stringify!(y) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize - }, - 1usize, - concat!( - "Offset of field: ", - stringify!(color__bindgen_ty_2), - "::", - stringify!(u) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).v) as usize - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(color__bindgen_ty_2), - "::", - stringify!(v) - ) - ); + fn test_field_y() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(color__bindgen_ty_2), + "::", + stringify!(y) + ) + ); + } + test_field_y(); + fn test_field_u() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize + }, + 1usize, + concat!( + "Offset of field: ", + stringify!(color__bindgen_ty_2), + "::", + stringify!(u) + ) + ); + } + test_field_u(); + fn test_field_v() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).v) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(color__bindgen_ty_2), + "::", + stringify!(v) + ) + ); + } + test_field_v(); } #[test] fn bindgen_test_layout_color() { @@ -154,15 +172,23 @@ fn bindgen_test_layout_color() { 1usize, concat!("Alignment of ", stringify!(color)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).v3) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(color), "::", stringify!(v3)) - ); + fn test_field_v3() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).v3) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(color), + "::", + stringify!(v3) + ) + ); + } + test_field_v3(); } impl Default for color { fn default() -> Self { diff --git a/tests/expectations/tests/anon_enum.rs b/tests/expectations/tests/anon_enum.rs index a06beb857c..06e98e7157 100644 --- a/tests/expectations/tests/anon_enum.rs +++ b/tests/expectations/tests/anon_enum.rs @@ -29,24 +29,40 @@ fn bindgen_test_layout_Test() { 4usize, concat!("Alignment of ", stringify!(Test)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(foo)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 4usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(bar)) - ); + fn test_field_foo() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Test), + "::", + stringify!(foo) + ) + ); + } + test_field_foo(); + fn test_field_bar() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(Test), + "::", + stringify!(bar) + ) + ); + } + test_field_bar(); } #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] diff --git a/tests/expectations/tests/anon_struct_in_union.rs b/tests/expectations/tests/anon_struct_in_union.rs index f80f817bb2..49caa13baa 100644 --- a/tests/expectations/tests/anon_struct_in_union.rs +++ b/tests/expectations/tests/anon_struct_in_union.rs @@ -32,21 +32,24 @@ fn bindgen_test_layout_s__bindgen_ty_1_inner() { 4usize, concat!("Alignment of ", stringify!(s__bindgen_ty_1_inner)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(s__bindgen_ty_1_inner), - "::", - stringify!(b) - ) - ); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(s__bindgen_ty_1_inner), + "::", + stringify!(b) + ) + ); + } + test_field_b(); } #[test] fn bindgen_test_layout_s__bindgen_ty_1() { @@ -60,20 +63,24 @@ fn bindgen_test_layout_s__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(s__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).field) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(s__bindgen_ty_1), - "::", - stringify!(field) - ) - ); + fn test_field_field() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).field) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(s__bindgen_ty_1), + "::", + stringify!(field) + ) + ); + } + test_field_field(); } impl Default for s__bindgen_ty_1 { fn default() -> Self { @@ -96,15 +103,18 @@ fn bindgen_test_layout_s() { 4usize, concat!("Alignment of ", stringify!(s)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(s), "::", stringify!(u)) - ); + fn test_field_u() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(s), "::", stringify!(u)) + ); + } + test_field_u(); } impl Default for s { fn default() -> Self { diff --git a/tests/expectations/tests/anon_struct_in_union_1_0.rs b/tests/expectations/tests/anon_struct_in_union_1_0.rs index 4631b1dc07..492ed6ca5c 100644 --- a/tests/expectations/tests/anon_struct_in_union_1_0.rs +++ b/tests/expectations/tests/anon_struct_in_union_1_0.rs @@ -76,21 +76,24 @@ fn bindgen_test_layout_s__bindgen_ty_1_inner() { 4usize, concat!("Alignment of ", stringify!(s__bindgen_ty_1_inner)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(s__bindgen_ty_1_inner), - "::", - stringify!(b) - ) - ); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(s__bindgen_ty_1_inner), + "::", + stringify!(b) + ) + ); + } + test_field_b(); } impl Clone for s__bindgen_ty_1_inner { fn clone(&self) -> Self { @@ -109,20 +112,24 @@ fn bindgen_test_layout_s__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(s__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).field) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(s__bindgen_ty_1), - "::", - stringify!(field) - ) - ); + fn test_field_field() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).field) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(s__bindgen_ty_1), + "::", + stringify!(field) + ) + ); + } + test_field_field(); } impl Clone for s__bindgen_ty_1 { fn clone(&self) -> Self { @@ -141,15 +148,18 @@ fn bindgen_test_layout_s() { 4usize, concat!("Alignment of ", stringify!(s)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(s), "::", stringify!(u)) - ); + fn test_field_u() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(s), "::", stringify!(u)) + ); + } + test_field_u(); } impl Clone for s { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/array-of-zero-sized-types.rs b/tests/expectations/tests/array-of-zero-sized-types.rs index f8d9e985be..875aef106d 100644 --- a/tests/expectations/tests/array-of-zero-sized-types.rs +++ b/tests/expectations/tests/array-of-zero-sized-types.rs @@ -43,18 +43,22 @@ fn bindgen_test_layout_HasArrayOfEmpty() { 1usize, concat!("Alignment of ", stringify!(HasArrayOfEmpty)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).empties) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(HasArrayOfEmpty), - "::", - stringify!(empties) - ) - ); + fn test_field_empties() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).empties) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(HasArrayOfEmpty), + "::", + stringify!(empties) + ) + ); + } + test_field_empties(); } diff --git a/tests/expectations/tests/bindgen-union-inside-namespace.rs b/tests/expectations/tests/bindgen-union-inside-namespace.rs index 558a098239..04cdf0b472 100644 --- a/tests/expectations/tests/bindgen-union-inside-namespace.rs +++ b/tests/expectations/tests/bindgen-union-inside-namespace.rs @@ -77,34 +77,40 @@ pub mod root { 4usize, concat!("Alignment of ", stringify!(Bar)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(foo) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(bar) - ) - ); + fn test_field_foo() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Bar), + "::", + stringify!(foo) + ) + ); + } + test_field_foo(); + fn test_field_bar() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Bar), + "::", + stringify!(bar) + ) + ); + } + test_field_bar(); } impl Clone for Bar { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/bitfield-linux-32.rs b/tests/expectations/tests/bitfield-linux-32.rs index 59a8001d3a..dd41d92d43 100644 --- a/tests/expectations/tests/bitfield-linux-32.rs +++ b/tests/expectations/tests/bitfield-linux-32.rs @@ -110,15 +110,23 @@ fn bindgen_test_layout_Test() { 4usize, concat!("Alignment of ", stringify!(Test)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(foo)) - ); + fn test_field_foo() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Test), + "::", + stringify!(foo) + ) + ); + } + test_field_foo(); } impl Test { #[inline] diff --git a/tests/expectations/tests/bitfield_align.rs b/tests/expectations/tests/bitfield_align.rs index 708f364faf..1b951336cf 100644 --- a/tests/expectations/tests/bitfield_align.rs +++ b/tests/expectations/tests/bitfield_align.rs @@ -112,24 +112,30 @@ fn bindgen_test_layout_A() { 4usize, concat!("Alignment of ", stringify!(A)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(x)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize - }, - 3usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(y)) - ); + fn test_field_x() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(A), "::", stringify!(x)) + ); + } + test_field_x(); + fn test_field_y() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize + }, + 3usize, + concat!("Offset of field: ", stringify!(A), "::", stringify!(y)) + ); + } + test_field_y(); } impl A { #[inline] @@ -405,24 +411,30 @@ fn bindgen_test_layout_C() { 4usize, concat!("Alignment of ", stringify!(C)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(x)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, - 4usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(baz)) - ); + fn test_field_x() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(x)) + ); + } + test_field_x(); + fn test_field_baz() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, + 4usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(baz)) + ); + } + test_field_baz(); } impl C { #[inline] @@ -710,20 +722,23 @@ fn bindgen_test_layout_Date3() { 2usize, concat!("Alignment of ", stringify!(Date3)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).byte) as usize - ptr as usize - }, - 3usize, - concat!( - "Offset of field: ", - stringify!(Date3), - "::", - stringify!(byte) - ) - ); + fn test_field_byte() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).byte) as usize - ptr as usize + }, + 3usize, + concat!( + "Offset of field: ", + stringify!(Date3), + "::", + stringify!(byte) + ) + ); + } + test_field_byte(); } impl Date3 { #[inline] diff --git a/tests/expectations/tests/blocklist-and-impl-debug.rs b/tests/expectations/tests/blocklist-and-impl-debug.rs index 2cb1fef398..055cca8c12 100644 --- a/tests/expectations/tests/blocklist-and-impl-debug.rs +++ b/tests/expectations/tests/blocklist-and-impl-debug.rs @@ -24,21 +24,25 @@ fn bindgen_test_layout_ShouldManuallyImplDebug() { 1usize, concat!("Alignment of ", stringify!(ShouldManuallyImplDebug)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldManuallyImplDebug), - "::", - stringify!(a) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ShouldManuallyImplDebug), + "::", + stringify!(a) + ) + ); + } + test_field_a(); } impl Default for ShouldManuallyImplDebug { fn default() -> Self { diff --git a/tests/expectations/tests/blocklist-file.rs b/tests/expectations/tests/blocklist-file.rs index 5e41376ca2..7843028d64 100644 --- a/tests/expectations/tests/blocklist-file.rs +++ b/tests/expectations/tests/blocklist-file.rs @@ -24,48 +24,57 @@ fn bindgen_test_layout_SizedIntegers() { 4usize, concat!("Alignment of ", stringify!(SizedIntegers)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(SizedIntegers), - "::", - stringify!(x) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(SizedIntegers), - "::", - stringify!(y) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).z) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(SizedIntegers), - "::", - stringify!(z) - ) - ); + fn test_field_x() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(SizedIntegers), + "::", + stringify!(x) + ) + ); + } + test_field_x(); + fn test_field_y() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(SizedIntegers), + "::", + stringify!(y) + ) + ); + } + test_field_y(); + fn test_field_z() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).z) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(SizedIntegers), + "::", + stringify!(z) + ) + ); + } + test_field_z(); } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -84,20 +93,23 @@ fn bindgen_test_layout_StructWithBlocklistedFwdDecl() { 1usize, concat!("Alignment of ", stringify!(StructWithBlocklistedFwdDecl)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(StructWithBlocklistedFwdDecl), - "::", - stringify!(b) - ) - ); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + StructWithBlocklistedFwdDecl, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(StructWithBlocklistedFwdDecl), + "::", + stringify!(b) + ) + ); + } + test_field_b(); } diff --git a/tests/expectations/tests/blocks-signature.rs b/tests/expectations/tests/blocks-signature.rs index df28cf85c7..048a0d4ebf 100644 --- a/tests/expectations/tests/blocks-signature.rs +++ b/tests/expectations/tests/blocks-signature.rs @@ -47,36 +47,44 @@ fn bindgen_test_layout_contains_block_pointers() { 8usize, concat!("Alignment of ", stringify!(contains_block_pointers)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).val) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(contains_block_pointers), - "::", - stringify!(val) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ptr_val) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(contains_block_pointers), - "::", - stringify!(ptr_val) - ) - ); + fn test_field_val() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).val) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(contains_block_pointers), + "::", + stringify!(val) + ) + ); + } + test_field_val(); + fn test_field_ptr_val() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ptr_val) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(contains_block_pointers), + "::", + stringify!(ptr_val) + ) + ); + } + test_field_ptr_val(); } impl Default for contains_block_pointers { fn default() -> Self { diff --git a/tests/expectations/tests/blocks.rs b/tests/expectations/tests/blocks.rs index f3734bf59a..abeec80f83 100644 --- a/tests/expectations/tests/blocks.rs +++ b/tests/expectations/tests/blocks.rs @@ -46,36 +46,44 @@ fn bindgen_test_layout_contains_block_pointers() { 8usize, concat!("Alignment of ", stringify!(contains_block_pointers)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).val) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(contains_block_pointers), - "::", - stringify!(val) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ptr_val) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(contains_block_pointers), - "::", - stringify!(ptr_val) - ) - ); + fn test_field_val() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).val) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(contains_block_pointers), + "::", + stringify!(val) + ) + ); + } + test_field_val(); + fn test_field_ptr_val() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ptr_val) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(contains_block_pointers), + "::", + stringify!(ptr_val) + ) + ); + } + test_field_ptr_val(); } impl Default for contains_block_pointers { fn default() -> Self { diff --git a/tests/expectations/tests/c_naming.rs b/tests/expectations/tests/c_naming.rs index 636929ce9c..bc0955fe9d 100644 --- a/tests/expectations/tests/c_naming.rs +++ b/tests/expectations/tests/c_naming.rs @@ -22,20 +22,23 @@ fn bindgen_test_layout_struct_a() { 4usize, concat!("Alignment of ", stringify!(struct_a)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(struct_a), - "::", - stringify!(a) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(struct_a), + "::", + stringify!(a) + ) + ); + } + test_field_a(); } pub type a = *const struct_a; #[repr(C)] @@ -56,34 +59,40 @@ fn bindgen_test_layout_union_b() { 4usize, concat!("Alignment of ", stringify!(union_b)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(union_b), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(union_b), - "::", - stringify!(b) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(union_b), + "::", + stringify!(a) + ) + ); + } + test_field_a(); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(union_b), + "::", + stringify!(b) + ) + ); + } + test_field_b(); } impl Default for union_b { fn default() -> Self { diff --git a/tests/expectations/tests/canonical-types.rs b/tests/expectations/tests/canonical-types.rs index 10808d2071..effe7fed68 100644 --- a/tests/expectations/tests/canonical-types.rs +++ b/tests/expectations/tests/canonical-types.rs @@ -176,20 +176,23 @@ fn bindgen_test_layout_ClassAInner() { 8usize, concat!("Alignment of ", stringify!(ClassAInner)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ClassAInner), - "::", - stringify!(x) - ) - ); + fn test_field_x() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ClassAInner), + "::", + stringify!(x) + ) + ); + } + test_field_x(); } impl Default for ClassAInner { fn default() -> Self { @@ -217,20 +220,23 @@ fn bindgen_test_layout_ClassCInnerA() { 8usize, concat!("Alignment of ", stringify!(ClassCInnerA)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ClassCInnerA), - "::", - stringify!(member) - ) - ); + fn test_field_member() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ClassCInnerA), + "::", + stringify!(member) + ) + ); + } + test_field_member(); } impl Default for ClassCInnerA { fn default() -> Self { @@ -258,20 +264,23 @@ fn bindgen_test_layout_ClassCInnerB() { 8usize, concat!("Alignment of ", stringify!(ClassCInnerB)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).cache) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ClassCInnerB), - "::", - stringify!(cache) - ) - ); + fn test_field_cache() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).cache) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ClassCInnerB), + "::", + stringify!(cache) + ) + ); + } + test_field_cache(); } impl Default for ClassCInnerB { fn default() -> Self { diff --git a/tests/expectations/tests/char.rs b/tests/expectations/tests/char.rs index 35f353e05c..3b6e119529 100644 --- a/tests/expectations/tests/char.rs +++ b/tests/expectations/tests/char.rs @@ -36,117 +36,198 @@ fn bindgen_test_layout_Test() { 1usize, concat!("Alignment of ", stringify!(Test)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ch) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(ch)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize - }, - 1usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(u)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, - 2usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(d)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).cch) as usize - ptr as usize - }, - 3usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(cch)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).cu) as usize - ptr as usize - }, - 4usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(cu)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).cd) as usize - ptr as usize - }, - 5usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(cd)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).Cch) as usize - ptr as usize - }, - 6usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cch)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).Cu) as usize - ptr as usize - }, - 7usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cu)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).Cd) as usize - ptr as usize - }, - 8usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cd)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).Ccch) as usize - ptr as usize - }, - 9usize, - concat!( - "Offset of field: ", - stringify!(Test), - "::", - stringify!(Ccch) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).Ccu) as usize - ptr as usize - }, - 10usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccu)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).Ccd) as usize - ptr as usize - }, - 11usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccd)) - ); + fn test_field_ch() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ch) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Test), + "::", + stringify!(ch) + ) + ); + } + test_field_ch(); + fn test_field_u() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize + }, + 1usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(u)) + ); + } + test_field_u(); + fn test_field_d() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, + 2usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(d)) + ); + } + test_field_d(); + fn test_field_cch() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).cch) as usize - ptr as usize + }, + 3usize, + concat!( + "Offset of field: ", + stringify!(Test), + "::", + stringify!(cch) + ) + ); + } + test_field_cch(); + fn test_field_cu() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).cu) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(Test), + "::", + stringify!(cu) + ) + ); + } + test_field_cu(); + fn test_field_cd() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).cd) as usize - ptr as usize + }, + 5usize, + concat!( + "Offset of field: ", + stringify!(Test), + "::", + stringify!(cd) + ) + ); + } + test_field_cd(); + fn test_field_Cch() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Cch) as usize - ptr as usize + }, + 6usize, + concat!( + "Offset of field: ", + stringify!(Test), + "::", + stringify!(Cch) + ) + ); + } + test_field_Cch(); + fn test_field_Cu() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Cu) as usize - ptr as usize + }, + 7usize, + concat!( + "Offset of field: ", + stringify!(Test), + "::", + stringify!(Cu) + ) + ); + } + test_field_Cu(); + fn test_field_Cd() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Cd) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(Test), + "::", + stringify!(Cd) + ) + ); + } + test_field_Cd(); + fn test_field_Ccch() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Ccch) as usize - ptr as usize + }, + 9usize, + concat!( + "Offset of field: ", + stringify!(Test), + "::", + stringify!(Ccch) + ) + ); + } + test_field_Ccch(); + fn test_field_Ccu() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Ccu) as usize - ptr as usize + }, + 10usize, + concat!( + "Offset of field: ", + stringify!(Test), + "::", + stringify!(Ccu) + ) + ); + } + test_field_Ccu(); + fn test_field_Ccd() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Ccd) as usize - ptr as usize + }, + 11usize, + concat!( + "Offset of field: ", + stringify!(Test), + "::", + stringify!(Ccd) + ) + ); + } + test_field_Ccd(); } diff --git a/tests/expectations/tests/class.rs b/tests/expectations/tests/class.rs index 74d568599c..3bfba7e149 100644 --- a/tests/expectations/tests/class.rs +++ b/tests/expectations/tests/class.rs @@ -53,29 +53,35 @@ fn bindgen_test_layout_C() { 4usize, concat!("Alignment of ", stringify!(C)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(a)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(big_array) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(a)) + ); + } + test_field_a(); + fn test_field_big_array() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(big_array) + ) + ); + } + test_field_big_array(); } impl Default for C { fn default() -> Self { @@ -104,52 +110,64 @@ fn bindgen_test_layout_C_with_zero_length_array() { 4usize, concat!("Alignment of ", stringify!(C_with_zero_length_array)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(big_array) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize - }, - 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(zero_length_array) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array), + "::", + stringify!(a) + ) + ); + } + test_field_a(); + fn test_field_big_array() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array), + "::", + stringify!(big_array) + ) + ); + } + test_field_big_array(); + fn test_field_zero_length_array() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - + ptr as usize + }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array), + "::", + stringify!(zero_length_array) + ) + ); + } + test_field_zero_length_array(); } impl Default for C_with_zero_length_array { fn default() -> Self { @@ -178,37 +196,45 @@ fn bindgen_test_layout_C_with_zero_length_array_2() { 4usize, concat!("Alignment of ", stringify!(C_with_zero_length_array_2)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_2), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_2), - "::", - stringify!(zero_length_array) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + C_with_zero_length_array_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_2), + "::", + stringify!(a) + ) + ); + } + test_field_a(); + fn test_field_zero_length_array() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + C_with_zero_length_array_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_2), + "::", + stringify!(zero_length_array) + ) + ); + } + test_field_zero_length_array(); } #[repr(C)] pub struct C_with_incomplete_array { @@ -337,20 +363,23 @@ fn bindgen_test_layout_WithDtor() { 4usize, concat!("Alignment of ", stringify!(WithDtor)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithDtor), - "::", - stringify!(b) - ) - ); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithDtor), + "::", + stringify!(b) + ) + ); + } + test_field_b(); } #[repr(C)] pub struct IncompleteArrayNonCopiable { @@ -397,24 +426,40 @@ fn bindgen_test_layout_Union() { 4usize, concat!("Alignment of ", stringify!(Union)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Union), "::", stringify!(d)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Union), "::", stringify!(i)) - ); + fn test_field_d() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Union), + "::", + stringify!(d) + ) + ); + } + test_field_d(); + fn test_field_i() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Union), + "::", + stringify!(i) + ) + ); + } + test_field_i(); } impl Default for Union { fn default() -> Self { @@ -442,20 +487,23 @@ fn bindgen_test_layout_WithUnion() { 4usize, concat!("Alignment of ", stringify!(WithUnion)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithUnion), - "::", - stringify!(data) - ) - ); + fn test_field_data() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithUnion), + "::", + stringify!(data) + ) + ); + } + test_field_data(); } impl Default for WithUnion { fn default() -> Self { diff --git a/tests/expectations/tests/class_1_0.rs b/tests/expectations/tests/class_1_0.rs index 7d1f67776a..5415500aca 100644 --- a/tests/expectations/tests/class_1_0.rs +++ b/tests/expectations/tests/class_1_0.rs @@ -96,29 +96,35 @@ fn bindgen_test_layout_C() { 4usize, concat!("Alignment of ", stringify!(C)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(a)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(big_array) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(a)) + ); + } + test_field_a(); + fn test_field_big_array() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(big_array) + ) + ); + } + test_field_big_array(); } impl Clone for C { fn clone(&self) -> Self { @@ -157,52 +163,64 @@ fn bindgen_test_layout_C_with_zero_length_array() { 4usize, concat!("Alignment of ", stringify!(C_with_zero_length_array)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(big_array) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize - }, - 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(zero_length_array) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array), + "::", + stringify!(a) + ) + ); + } + test_field_a(); + fn test_field_big_array() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array), + "::", + stringify!(big_array) + ) + ); + } + test_field_big_array(); + fn test_field_zero_length_array() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - + ptr as usize + }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array), + "::", + stringify!(zero_length_array) + ) + ); + } + test_field_zero_length_array(); } impl Default for C_with_zero_length_array { fn default() -> Self { @@ -231,37 +249,45 @@ fn bindgen_test_layout_C_with_zero_length_array_2() { 4usize, concat!("Alignment of ", stringify!(C_with_zero_length_array_2)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_2), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_2), - "::", - stringify!(zero_length_array) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + C_with_zero_length_array_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_2), + "::", + stringify!(a) + ) + ); + } + test_field_a(); + fn test_field_zero_length_array() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + C_with_zero_length_array_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_2), + "::", + stringify!(zero_length_array) + ) + ); + } + test_field_zero_length_array(); } #[repr(C)] pub struct C_with_incomplete_array { @@ -390,20 +416,23 @@ fn bindgen_test_layout_WithDtor() { 4usize, concat!("Alignment of ", stringify!(WithDtor)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithDtor), - "::", - stringify!(b) - ) - ); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithDtor), + "::", + stringify!(b) + ) + ); + } + test_field_b(); } #[repr(C)] pub struct IncompleteArrayNonCopiable { @@ -451,24 +480,40 @@ fn bindgen_test_layout_Union() { 4usize, concat!("Alignment of ", stringify!(Union)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Union), "::", stringify!(d)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Union), "::", stringify!(i)) - ); + fn test_field_d() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Union), + "::", + stringify!(d) + ) + ); + } + test_field_d(); + fn test_field_i() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Union), + "::", + stringify!(i) + ) + ); + } + test_field_i(); } impl Clone for Union { fn clone(&self) -> Self { @@ -492,20 +537,23 @@ fn bindgen_test_layout_WithUnion() { 4usize, concat!("Alignment of ", stringify!(WithUnion)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithUnion), - "::", - stringify!(data) - ) - ); + fn test_field_data() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithUnion), + "::", + stringify!(data) + ) + ); + } + test_field_data(); } impl Clone for WithUnion { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/class_nested.rs b/tests/expectations/tests/class_nested.rs index 55ea6e1def..7ea2fe818d 100644 --- a/tests/expectations/tests/class_nested.rs +++ b/tests/expectations/tests/class_nested.rs @@ -27,20 +27,23 @@ fn bindgen_test_layout_A_B() { 4usize, concat!("Alignment of ", stringify!(A_B)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member_b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(A_B), - "::", - stringify!(member_b) - ) - ); + fn test_field_member_b() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member_b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(A_B), + "::", + stringify!(member_b) + ) + ); + } + test_field_member_b(); } #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] @@ -69,20 +72,23 @@ fn bindgen_test_layout_A() { 4usize, concat!("Alignment of ", stringify!(A)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member_a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(A), - "::", - stringify!(member_a) - ) - ); + fn test_field_member_a() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member_a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(A), + "::", + stringify!(member_a) + ) + ); + } + test_field_member_a(); } #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] @@ -101,15 +107,23 @@ fn bindgen_test_layout_A_C() { 4usize, concat!("Alignment of ", stringify!(A_C)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(A_C), "::", stringify!(baz)) - ); + fn test_field_baz() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(A_C), + "::", + stringify!(baz) + ) + ); + } + test_field_baz(); } extern "C" { pub static mut var: A_B; @@ -153,15 +167,23 @@ fn bindgen_test_layout_D() { 4usize, concat!("Alignment of ", stringify!(D)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(D), "::", stringify!(member)) - ); + fn test_field_member() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(D), + "::", + stringify!(member) + ) + ); + } + test_field_member(); } #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] diff --git a/tests/expectations/tests/class_no_members.rs b/tests/expectations/tests/class_no_members.rs index 5ac7ffdebb..75487a4071 100644 --- a/tests/expectations/tests/class_no_members.rs +++ b/tests/expectations/tests/class_no_members.rs @@ -58,19 +58,23 @@ fn bindgen_test_layout_whatever_child_with_member() { 4usize, concat!("Alignment of ", stringify!(whatever_child_with_member)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(whatever_child_with_member), - "::", - stringify!(m_member) - ) - ); + fn test_field_m_member() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + whatever_child_with_member, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(whatever_child_with_member), + "::", + stringify!(m_member) + ) + ); + } + test_field_m_member(); } diff --git a/tests/expectations/tests/class_use_as.rs b/tests/expectations/tests/class_use_as.rs index f1f08e4d07..12a51bd61c 100644 --- a/tests/expectations/tests/class_use_as.rs +++ b/tests/expectations/tests/class_use_as.rs @@ -23,20 +23,23 @@ fn bindgen_test_layout_whatever() { 4usize, concat!("Alignment of ", stringify!(whatever)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).replacement) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(whatever), - "::", - stringify!(replacement) - ) - ); + fn test_field_replacement() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).replacement) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(whatever), + "::", + stringify!(replacement) + ) + ); + } + test_field_replacement(); } #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] @@ -55,18 +58,21 @@ fn bindgen_test_layout_container() { 4usize, concat!("Alignment of ", stringify!(container)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(container), - "::", - stringify!(c) - ) - ); + fn test_field_c() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(container), + "::", + stringify!(c) + ) + ); + } + test_field_c(); } diff --git a/tests/expectations/tests/class_with_dtor.rs b/tests/expectations/tests/class_with_dtor.rs index e94e8e5f1b..a6e7586786 100644 --- a/tests/expectations/tests/class_with_dtor.rs +++ b/tests/expectations/tests/class_with_dtor.rs @@ -38,21 +38,24 @@ fn bindgen_test_layout_WithoutDtor() { 8usize, concat!("Alignment of ", stringify!(WithoutDtor)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).shouldBeWithDtor) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithoutDtor), - "::", - stringify!(shouldBeWithDtor) - ) - ); + fn test_field_shouldBeWithDtor() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).shouldBeWithDtor) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithoutDtor), + "::", + stringify!(shouldBeWithDtor) + ) + ); + } + test_field_shouldBeWithDtor(); } impl Default for WithoutDtor { fn default() -> Self { diff --git a/tests/expectations/tests/class_with_inner_struct.rs b/tests/expectations/tests/class_with_inner_struct.rs index 49ca304877..ba1373b25f 100644 --- a/tests/expectations/tests/class_with_inner_struct.rs +++ b/tests/expectations/tests/class_with_inner_struct.rs @@ -30,34 +30,40 @@ fn bindgen_test_layout_A_Segment() { 4usize, concat!("Alignment of ", stringify!(A_Segment)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(A_Segment), - "::", - stringify!(begin) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(A_Segment), - "::", - stringify!(end) - ) - ); + fn test_field_begin() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(A_Segment), + "::", + stringify!(begin) + ) + ); + } + test_field_begin(); + fn test_field_end() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(A_Segment), + "::", + stringify!(end) + ) + ); + } + test_field_end(); } #[repr(C)] #[derive(Copy, Clone)] @@ -76,20 +82,24 @@ fn bindgen_test_layout_A__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(A__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(A__bindgen_ty_1), - "::", - stringify!(f) - ) - ); + fn test_field_f() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(A__bindgen_ty_1), + "::", + stringify!(f) + ) + ); + } + test_field_f(); } impl Default for A__bindgen_ty_1 { fn default() -> Self { @@ -117,20 +127,24 @@ fn bindgen_test_layout_A__bindgen_ty_2() { 4usize, concat!("Alignment of ", stringify!(A__bindgen_ty_2)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(A__bindgen_ty_2), - "::", - stringify!(d) - ) - ); + fn test_field_d() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(A__bindgen_ty_2), + "::", + stringify!(d) + ) + ); + } + test_field_d(); } impl Default for A__bindgen_ty_2 { fn default() -> Self { @@ -153,29 +167,35 @@ fn bindgen_test_layout_A() { 4usize, concat!("Alignment of ", stringify!(A)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(c)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).named_union) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(A), - "::", - stringify!(named_union) - ) - ); + fn test_field_c() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(A), "::", stringify!(c)) + ); + } + test_field_c(); + fn test_field_named_union() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).named_union) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(A), + "::", + stringify!(named_union) + ) + ); + } + test_field_named_union(); } impl Default for A { fn default() -> Self { @@ -209,34 +229,40 @@ fn bindgen_test_layout_B_Segment() { 4usize, concat!("Alignment of ", stringify!(B_Segment)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(B_Segment), - "::", - stringify!(begin) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(B_Segment), - "::", - stringify!(end) - ) - ); + fn test_field_begin() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(B_Segment), + "::", + stringify!(begin) + ) + ); + } + test_field_begin(); + fn test_field_end() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(B_Segment), + "::", + stringify!(end) + ) + ); + } + test_field_end(); } #[test] fn bindgen_test_layout_B() { @@ -250,15 +276,18 @@ fn bindgen_test_layout_B() { 4usize, concat!("Alignment of ", stringify!(B)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(B), "::", stringify!(d)) - ); + fn test_field_d() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(B), "::", stringify!(d)) + ); + } + test_field_d(); } #[repr(i32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] @@ -300,62 +329,82 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(C__bindgen_ty_1__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = :: std :: mem :: MaybeUninit :: < C__bindgen_ty_1__bindgen_ty_1 > :: uninit () ; - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mX1) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(mX1) - ) - ); - assert_eq!( - unsafe { - let uninit = :: std :: mem :: MaybeUninit :: < C__bindgen_ty_1__bindgen_ty_1 > :: uninit () ; - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mY1) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(mY1) - ) - ); - assert_eq!( - unsafe { - let uninit = :: std :: mem :: MaybeUninit :: < C__bindgen_ty_1__bindgen_ty_1 > :: uninit () ; - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mX2) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(mX2) - ) - ); - assert_eq!( - unsafe { - let uninit = :: std :: mem :: MaybeUninit :: < C__bindgen_ty_1__bindgen_ty_1 > :: uninit () ; - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mY2) as usize - ptr as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(mY2) - ) - ); + fn test_field_mX1() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + C__bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mX1) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(mX1) + ) + ); + } + test_field_mX1(); + fn test_field_mY1() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + C__bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mY1) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(mY1) + ) + ); + } + test_field_mY1(); + fn test_field_mX2() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + C__bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mX2) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(C__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(mX2) + ) + ); + } + test_field_mX2(); + fn test_field_mY2() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + C__bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mY2) as usize - ptr as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(C__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(mY2) + ) + ); + } + test_field_mY2(); } #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] @@ -375,34 +424,44 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_2() { 4usize, concat!("Alignment of ", stringify!(C__bindgen_ty_1__bindgen_ty_2)) ); - assert_eq!( - unsafe { - let uninit = :: std :: mem :: MaybeUninit :: < C__bindgen_ty_1__bindgen_ty_2 > :: uninit () ; - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mStepSyntax) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(mStepSyntax) - ) - ); - assert_eq!( - unsafe { - let uninit = :: std :: mem :: MaybeUninit :: < C__bindgen_ty_1__bindgen_ty_2 > :: uninit () ; - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mSteps) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(mSteps) - ) - ); + fn test_field_mStepSyntax() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + C__bindgen_ty_1__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mStepSyntax) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(mStepSyntax) + ) + ); + } + test_field_mStepSyntax(); + fn test_field_mSteps() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + C__bindgen_ty_1__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mSteps) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(mSteps) + ) + ); + } + test_field_mSteps(); } impl Default for C__bindgen_ty_1__bindgen_ty_2 { fn default() -> Self { @@ -425,20 +484,24 @@ fn bindgen_test_layout_C__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(C__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mFunc) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1), - "::", - stringify!(mFunc) - ) - ); + fn test_field_mFunc() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mFunc) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C__bindgen_ty_1), + "::", + stringify!(mFunc) + ) + ); + } + test_field_mFunc(); } impl Default for C__bindgen_ty_1 { fn default() -> Self { @@ -467,34 +530,40 @@ fn bindgen_test_layout_C_Segment() { 4usize, concat!("Alignment of ", stringify!(C_Segment)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_Segment), - "::", - stringify!(begin) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_Segment), - "::", - stringify!(end) - ) - ); + fn test_field_begin() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_Segment), + "::", + stringify!(begin) + ) + ); + } + test_field_begin(); + fn test_field_end() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_Segment), + "::", + stringify!(end) + ) + ); + } + test_field_end(); } #[test] fn bindgen_test_layout_C() { @@ -508,15 +577,18 @@ fn bindgen_test_layout_C() { 4usize, concat!("Alignment of ", stringify!(C)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(d)) - ); + fn test_field_d() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(d)) + ); + } + test_field_d(); } impl Default for C { fn default() -> Self { diff --git a/tests/expectations/tests/class_with_inner_struct_1_0.rs b/tests/expectations/tests/class_with_inner_struct_1_0.rs index 3232a8d00d..3774c1442a 100644 --- a/tests/expectations/tests/class_with_inner_struct_1_0.rs +++ b/tests/expectations/tests/class_with_inner_struct_1_0.rs @@ -73,34 +73,40 @@ fn bindgen_test_layout_A_Segment() { 4usize, concat!("Alignment of ", stringify!(A_Segment)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(A_Segment), - "::", - stringify!(begin) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(A_Segment), - "::", - stringify!(end) - ) - ); + fn test_field_begin() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(A_Segment), + "::", + stringify!(begin) + ) + ); + } + test_field_begin(); + fn test_field_end() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(A_Segment), + "::", + stringify!(end) + ) + ); + } + test_field_end(); } impl Clone for A_Segment { fn clone(&self) -> Self { @@ -125,20 +131,24 @@ fn bindgen_test_layout_A__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(A__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(A__bindgen_ty_1), - "::", - stringify!(f) - ) - ); + fn test_field_f() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(A__bindgen_ty_1), + "::", + stringify!(f) + ) + ); + } + test_field_f(); } impl Clone for A__bindgen_ty_1 { fn clone(&self) -> Self { @@ -163,20 +173,24 @@ fn bindgen_test_layout_A__bindgen_ty_2() { 4usize, concat!("Alignment of ", stringify!(A__bindgen_ty_2)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(A__bindgen_ty_2), - "::", - stringify!(d) - ) - ); + fn test_field_d() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(A__bindgen_ty_2), + "::", + stringify!(d) + ) + ); + } + test_field_d(); } impl Clone for A__bindgen_ty_2 { fn clone(&self) -> Self { @@ -195,29 +209,35 @@ fn bindgen_test_layout_A() { 4usize, concat!("Alignment of ", stringify!(A)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(c)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).named_union) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(A), - "::", - stringify!(named_union) - ) - ); + fn test_field_c() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(A), "::", stringify!(c)) + ); + } + test_field_c(); + fn test_field_named_union() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).named_union) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(A), + "::", + stringify!(named_union) + ) + ); + } + test_field_named_union(); } impl Clone for A { fn clone(&self) -> Self { @@ -247,34 +267,40 @@ fn bindgen_test_layout_B_Segment() { 4usize, concat!("Alignment of ", stringify!(B_Segment)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(B_Segment), - "::", - stringify!(begin) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(B_Segment), - "::", - stringify!(end) - ) - ); + fn test_field_begin() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(B_Segment), + "::", + stringify!(begin) + ) + ); + } + test_field_begin(); + fn test_field_end() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(B_Segment), + "::", + stringify!(end) + ) + ); + } + test_field_end(); } impl Clone for B_Segment { fn clone(&self) -> Self { @@ -293,15 +319,18 @@ fn bindgen_test_layout_B() { 4usize, concat!("Alignment of ", stringify!(B)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(B), "::", stringify!(d)) - ); + fn test_field_d() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(B), "::", stringify!(d)) + ); + } + test_field_d(); } impl Clone for B { fn clone(&self) -> Self { @@ -349,62 +378,82 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(C__bindgen_ty_1__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = :: std :: mem :: MaybeUninit :: < C__bindgen_ty_1__bindgen_ty_1 > :: uninit () ; - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mX1) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(mX1) - ) - ); - assert_eq!( - unsafe { - let uninit = :: std :: mem :: MaybeUninit :: < C__bindgen_ty_1__bindgen_ty_1 > :: uninit () ; - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mY1) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(mY1) - ) - ); - assert_eq!( - unsafe { - let uninit = :: std :: mem :: MaybeUninit :: < C__bindgen_ty_1__bindgen_ty_1 > :: uninit () ; - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mX2) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(mX2) - ) - ); - assert_eq!( - unsafe { - let uninit = :: std :: mem :: MaybeUninit :: < C__bindgen_ty_1__bindgen_ty_1 > :: uninit () ; - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mY2) as usize - ptr as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(mY2) - ) - ); + fn test_field_mX1() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + C__bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mX1) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(mX1) + ) + ); + } + test_field_mX1(); + fn test_field_mY1() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + C__bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mY1) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(mY1) + ) + ); + } + test_field_mY1(); + fn test_field_mX2() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + C__bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mX2) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(C__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(mX2) + ) + ); + } + test_field_mX2(); + fn test_field_mY2() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + C__bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mY2) as usize - ptr as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(C__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(mY2) + ) + ); + } + test_field_mY2(); } impl Clone for C__bindgen_ty_1__bindgen_ty_1 { fn clone(&self) -> Self { @@ -429,34 +478,44 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_2() { 4usize, concat!("Alignment of ", stringify!(C__bindgen_ty_1__bindgen_ty_2)) ); - assert_eq!( - unsafe { - let uninit = :: std :: mem :: MaybeUninit :: < C__bindgen_ty_1__bindgen_ty_2 > :: uninit () ; - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mStepSyntax) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(mStepSyntax) - ) - ); - assert_eq!( - unsafe { - let uninit = :: std :: mem :: MaybeUninit :: < C__bindgen_ty_1__bindgen_ty_2 > :: uninit () ; - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mSteps) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(mSteps) - ) - ); + fn test_field_mStepSyntax() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + C__bindgen_ty_1__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mStepSyntax) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(mStepSyntax) + ) + ); + } + test_field_mStepSyntax(); + fn test_field_mSteps() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + C__bindgen_ty_1__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mSteps) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(mSteps) + ) + ); + } + test_field_mSteps(); } impl Clone for C__bindgen_ty_1__bindgen_ty_2 { fn clone(&self) -> Self { @@ -484,20 +543,24 @@ fn bindgen_test_layout_C__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(C__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mFunc) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1), - "::", - stringify!(mFunc) - ) - ); + fn test_field_mFunc() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mFunc) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C__bindgen_ty_1), + "::", + stringify!(mFunc) + ) + ); + } + test_field_mFunc(); } impl Clone for C__bindgen_ty_1 { fn clone(&self) -> Self { @@ -522,34 +585,40 @@ fn bindgen_test_layout_C_Segment() { 4usize, concat!("Alignment of ", stringify!(C_Segment)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_Segment), - "::", - stringify!(begin) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_Segment), - "::", - stringify!(end) - ) - ); + fn test_field_begin() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_Segment), + "::", + stringify!(begin) + ) + ); + } + test_field_begin(); + fn test_field_end() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_Segment), + "::", + stringify!(end) + ) + ); + } + test_field_end(); } impl Clone for C_Segment { fn clone(&self) -> Self { @@ -568,15 +637,18 @@ fn bindgen_test_layout_C() { 4usize, concat!("Alignment of ", stringify!(C)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(d)) - ); + fn test_field_d() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(d)) + ); + } + test_field_d(); } impl Clone for C { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/class_with_typedef.rs b/tests/expectations/tests/class_with_typedef.rs index 7af009e743..6df675b9c4 100644 --- a/tests/expectations/tests/class_with_typedef.rs +++ b/tests/expectations/tests/class_with_typedef.rs @@ -29,56 +29,71 @@ fn bindgen_test_layout_C() { 8usize, concat!("Alignment of ", stringify!(C)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(c)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize - }, - 8usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(ptr)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize - }, - 16usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(arr)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, - 56usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(d)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).other_ptr) as usize - ptr as usize - }, - 64usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(other_ptr) - ) - ); + fn test_field_c() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(c)) + ); + } + test_field_c(); + fn test_field_ptr() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize + }, + 8usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(ptr)) + ); + } + test_field_ptr(); + fn test_field_arr() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize + }, + 16usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(arr)) + ); + } + test_field_arr(); + fn test_field_d() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, + 56usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(d)) + ); + } + test_field_d(); + fn test_field_other_ptr() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).other_ptr) as usize - ptr as usize + }, + 64usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(other_ptr) + ) + ); + } + test_field_other_ptr(); } extern "C" { #[link_name = "\u{1}_ZN1C6methodEi"] @@ -141,15 +156,18 @@ fn bindgen_test_layout_D() { 8usize, concat!("Alignment of ", stringify!(D)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize - }, - 72usize, - concat!("Offset of field: ", stringify!(D), "::", stringify!(ptr)) - ); + fn test_field_ptr() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize + }, + 72usize, + concat!("Offset of field: ", stringify!(D), "::", stringify!(ptr)) + ); + } + test_field_ptr(); } impl Default for D { fn default() -> Self { diff --git a/tests/expectations/tests/comment-indent.rs b/tests/expectations/tests/comment-indent.rs index e4bdea3d6f..93412f2f25 100644 --- a/tests/expectations/tests/comment-indent.rs +++ b/tests/expectations/tests/comment-indent.rs @@ -80,20 +80,24 @@ pub mod root { 4usize, concat!("Alignment of ", stringify!(Baz)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Baz), - "::", - stringify!(member) - ) - ); + fn test_field_member() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Baz), + "::", + stringify!(member) + ) + ); + } + test_field_member(); } /// I'm in an inline namespace, and as such I shouldn't get generated inside /// a rust module, except when the relevant option is specified. Also, this diff --git a/tests/expectations/tests/complex.rs b/tests/expectations/tests/complex.rs index 77ab28080a..ba1d4ae832 100644 --- a/tests/expectations/tests/complex.rs +++ b/tests/expectations/tests/complex.rs @@ -28,20 +28,23 @@ fn bindgen_test_layout_TestDouble() { 8usize, concat!("Alignment of ", stringify!(TestDouble)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(TestDouble), - "::", - stringify!(mMember) - ) - ); + fn test_field_mMember() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(TestDouble), + "::", + stringify!(mMember) + ) + ); + } + test_field_mMember(); } #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] @@ -60,20 +63,23 @@ fn bindgen_test_layout_TestDoublePtr() { 8usize, concat!("Alignment of ", stringify!(TestDoublePtr)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(TestDoublePtr), - "::", - stringify!(mMember) - ) - ); + fn test_field_mMember() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(TestDoublePtr), + "::", + stringify!(mMember) + ) + ); + } + test_field_mMember(); } impl Default for TestDoublePtr { fn default() -> Self { @@ -101,20 +107,23 @@ fn bindgen_test_layout_TestFloat() { 4usize, concat!("Alignment of ", stringify!(TestFloat)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(TestFloat), - "::", - stringify!(mMember) - ) - ); + fn test_field_mMember() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(TestFloat), + "::", + stringify!(mMember) + ) + ); + } + test_field_mMember(); } #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] @@ -133,20 +142,23 @@ fn bindgen_test_layout_TestFloatPtr() { 8usize, concat!("Alignment of ", stringify!(TestFloatPtr)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(TestFloatPtr), - "::", - stringify!(mMember) - ) - ); + fn test_field_mMember() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(TestFloatPtr), + "::", + stringify!(mMember) + ) + ); + } + test_field_mMember(); } impl Default for TestFloatPtr { fn default() -> Self { diff --git a/tests/expectations/tests/const-const-mut-ptr.rs b/tests/expectations/tests/const-const-mut-ptr.rs index 9f656102a6..b6b3bdb9ae 100644 --- a/tests/expectations/tests/const-const-mut-ptr.rs +++ b/tests/expectations/tests/const-const-mut-ptr.rs @@ -22,15 +22,23 @@ fn bindgen_test_layout_foo() { 8usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) - ); + fn test_field_bar() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(bar) + ) + ); + } + test_field_bar(); } impl Default for foo { fn default() -> Self { diff --git a/tests/expectations/tests/constified-enum-module-overflow.rs b/tests/expectations/tests/constified-enum-module-overflow.rs index 6c625321b1..df112982b3 100644 --- a/tests/expectations/tests/constified-enum-module-overflow.rs +++ b/tests/expectations/tests/constified-enum-module-overflow.rs @@ -33,15 +33,18 @@ fn bindgen_test_layout_A() { 1usize, concat!("Alignment of ", stringify!(A)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(u)) - ); + fn test_field_u() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(A), "::", stringify!(u)) + ); + } + test_field_u(); } #[test] fn __bindgen_test_layout_C_open0_A_close0_instantiation() { diff --git a/tests/expectations/tests/constify-all-enums.rs b/tests/expectations/tests/constify-all-enums.rs index 3627faaea7..c926d85766 100644 --- a/tests/expectations/tests/constify-all-enums.rs +++ b/tests/expectations/tests/constify-all-enums.rs @@ -26,21 +26,24 @@ fn bindgen_test_layout_bar() { 4usize, concat!("Alignment of ", stringify!(bar)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).this_should_work) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(this_should_work) - ) - ); + fn test_field_this_should_work() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).this_should_work) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(bar), + "::", + stringify!(this_should_work) + ) + ); + } + test_field_this_should_work(); } impl Default for bar { fn default() -> Self { diff --git a/tests/expectations/tests/constify-module-enums-basic.rs b/tests/expectations/tests/constify-module-enums-basic.rs index 0ea84b9dda..6078ef20d1 100644 --- a/tests/expectations/tests/constify-module-enums-basic.rs +++ b/tests/expectations/tests/constify-module-enums-basic.rs @@ -30,21 +30,24 @@ fn bindgen_test_layout_bar() { 4usize, concat!("Alignment of ", stringify!(bar)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).this_should_work) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(this_should_work) - ) - ); + fn test_field_this_should_work() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).this_should_work) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(bar), + "::", + stringify!(this_should_work) + ) + ); + } + test_field_this_should_work(); } impl Default for bar { fn default() -> Self { diff --git a/tests/expectations/tests/constify-module-enums-namespace.rs b/tests/expectations/tests/constify-module-enums-namespace.rs index 637e6e4feb..326c219da3 100644 --- a/tests/expectations/tests/constify-module-enums-namespace.rs +++ b/tests/expectations/tests/constify-module-enums-namespace.rs @@ -42,21 +42,26 @@ pub mod root { 4usize, concat!("Alignment of ", stringify!(bar)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).this_should_work) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(this_should_work) - ) - ); + fn test_field_this_should_work() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).this_should_work) + as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(bar), + "::", + stringify!(this_should_work) + ) + ); + } + test_field_this_should_work(); } impl Default for bar { fn default() -> Self { diff --git a/tests/expectations/tests/constify-module-enums-shadow-name.rs b/tests/expectations/tests/constify-module-enums-shadow-name.rs index 21ad17a3f0..a5340e698f 100644 --- a/tests/expectations/tests/constify-module-enums-shadow-name.rs +++ b/tests/expectations/tests/constify-module-enums-shadow-name.rs @@ -29,20 +29,23 @@ fn bindgen_test_layout_bar() { 4usize, concat!("Alignment of ", stringify!(bar)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(member) - ) - ); + fn test_field_member() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(bar), + "::", + stringify!(member) + ) + ); + } + test_field_member(); } impl Default for bar { fn default() -> Self { diff --git a/tests/expectations/tests/constify-module-enums-simple-alias.rs b/tests/expectations/tests/constify-module-enums-simple-alias.rs index 4d7ae60482..52d4651697 100644 --- a/tests/expectations/tests/constify-module-enums-simple-alias.rs +++ b/tests/expectations/tests/constify-module-enums-simple-alias.rs @@ -38,98 +38,142 @@ fn bindgen_test_layout_Bar() { 8usize, concat!("Alignment of ", stringify!(Bar)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz1) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz1)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz2) as usize - ptr as usize - }, - 4usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz2)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz3) as usize - ptr as usize - }, - 8usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz3)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz4) as usize - ptr as usize - }, - 12usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz4)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz_ptr1) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(baz_ptr1) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz_ptr2) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(baz_ptr2) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz_ptr3) as usize - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(baz_ptr3) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz_ptr4) as usize - ptr as usize - }, - 40usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(baz_ptr4) - ) - ); + fn test_field_baz1() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz1) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Bar), + "::", + stringify!(baz1) + ) + ); + } + test_field_baz1(); + fn test_field_baz2() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz2) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(Bar), + "::", + stringify!(baz2) + ) + ); + } + test_field_baz2(); + fn test_field_baz3() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz3) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(Bar), + "::", + stringify!(baz3) + ) + ); + } + test_field_baz3(); + fn test_field_baz4() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz4) as usize - ptr as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(Bar), + "::", + stringify!(baz4) + ) + ); + } + test_field_baz4(); + fn test_field_baz_ptr1() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz_ptr1) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(Bar), + "::", + stringify!(baz_ptr1) + ) + ); + } + test_field_baz_ptr1(); + fn test_field_baz_ptr2() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz_ptr2) as usize - ptr as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(Bar), + "::", + stringify!(baz_ptr2) + ) + ); + } + test_field_baz_ptr2(); + fn test_field_baz_ptr3() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz_ptr3) as usize - ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(Bar), + "::", + stringify!(baz_ptr3) + ) + ); + } + test_field_baz_ptr3(); + fn test_field_baz_ptr4() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz_ptr4) as usize - ptr as usize + }, + 40usize, + concat!( + "Offset of field: ", + stringify!(Bar), + "::", + stringify!(baz_ptr4) + ) + ); + } + test_field_baz_ptr4(); } impl Default for Bar { fn default() -> Self { diff --git a/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs b/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs index f15ae7efb4..c2032b21a8 100644 --- a/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs +++ b/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs @@ -28,24 +28,40 @@ fn bindgen_test_layout_Bar() { 8usize, concat!("Alignment of ", stringify!(Bar)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz1) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz1)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz2) as usize - ptr as usize - }, - 8usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz2)) - ); + fn test_field_baz1() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz1) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Bar), + "::", + stringify!(baz1) + ) + ); + } + test_field_baz1(); + fn test_field_baz2() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz2) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(Bar), + "::", + stringify!(baz2) + ) + ); + } + test_field_baz2(); } impl Default for Bar { fn default() -> Self { diff --git a/tests/expectations/tests/constify-module-enums-types.rs b/tests/expectations/tests/constify-module-enums-types.rs index 9c7490b650..7319ec7253 100644 --- a/tests/expectations/tests/constify-module-enums-types.rs +++ b/tests/expectations/tests/constify-module-enums-types.rs @@ -63,146 +63,176 @@ fn bindgen_test_layout_bar() { 8usize, concat!("Alignment of ", stringify!(bar)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member1) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(member1) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member2) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(member2) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member3) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(member3) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member4) as usize - ptr as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(member4) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member5) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(member5) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member6) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(member6) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member7) as usize - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(member7) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member8) as usize - ptr as usize - }, - 36usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(member8) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member9) as usize - ptr as usize - }, - 40usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(member9) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member10) as usize - ptr as usize - }, - 44usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(member10) - ) - ); + fn test_field_member1() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member1) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(bar), + "::", + stringify!(member1) + ) + ); + } + test_field_member1(); + fn test_field_member2() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member2) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(bar), + "::", + stringify!(member2) + ) + ); + } + test_field_member2(); + fn test_field_member3() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member3) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(bar), + "::", + stringify!(member3) + ) + ); + } + test_field_member3(); + fn test_field_member4() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member4) as usize - ptr as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(bar), + "::", + stringify!(member4) + ) + ); + } + test_field_member4(); + fn test_field_member5() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member5) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(bar), + "::", + stringify!(member5) + ) + ); + } + test_field_member5(); + fn test_field_member6() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member6) as usize - ptr as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(bar), + "::", + stringify!(member6) + ) + ); + } + test_field_member6(); + fn test_field_member7() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member7) as usize - ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(bar), + "::", + stringify!(member7) + ) + ); + } + test_field_member7(); + fn test_field_member8() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member8) as usize - ptr as usize + }, + 36usize, + concat!( + "Offset of field: ", + stringify!(bar), + "::", + stringify!(member8) + ) + ); + } + test_field_member8(); + fn test_field_member9() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member9) as usize - ptr as usize + }, + 40usize, + concat!( + "Offset of field: ", + stringify!(bar), + "::", + stringify!(member9) + ) + ); + } + test_field_member9(); + fn test_field_member10() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member10) as usize - ptr as usize + }, + 44usize, + concat!( + "Offset of field: ", + stringify!(bar), + "::", + stringify!(member10) + ) + ); + } + test_field_member10(); } impl Default for bar { fn default() -> Self { @@ -230,20 +260,23 @@ fn bindgen_test_layout_Baz() { 4usize, concat!("Alignment of ", stringify!(Baz)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member1) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Baz), - "::", - stringify!(member1) - ) - ); + fn test_field_member1() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member1) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Baz), + "::", + stringify!(member1) + ) + ); + } + test_field_member1(); } impl Default for Baz { fn default() -> Self { @@ -276,15 +309,23 @@ fn bindgen_test_layout_Bar() { 8usize, concat!("Alignment of ", stringify!(Bar)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz)) - ); + fn test_field_baz() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Bar), + "::", + stringify!(baz) + ) + ); + } + test_field_baz(); } impl Default for Bar { fn default() -> Self { diff --git a/tests/expectations/tests/contains-vs-inherits-zero-sized.rs b/tests/expectations/tests/contains-vs-inherits-zero-sized.rs index 45db909916..b218a62f11 100644 --- a/tests/expectations/tests/contains-vs-inherits-zero-sized.rs +++ b/tests/expectations/tests/contains-vs-inherits-zero-sized.rs @@ -43,20 +43,23 @@ fn bindgen_test_layout_Inherits() { 1usize, concat!("Alignment of ", stringify!(Inherits)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Inherits), - "::", - stringify!(b) - ) - ); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Inherits), + "::", + stringify!(b) + ) + ); + } + test_field_b(); } /// This should not get an `_address` byte, but contains `Empty` which *does* get /// one, so `sizeof(Contains)` should be `1 + 1`. @@ -78,32 +81,38 @@ fn bindgen_test_layout_Contains() { 1usize, concat!("Alignment of ", stringify!(Contains)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).empty) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Contains), - "::", - stringify!(empty) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 1usize, - concat!( - "Offset of field: ", - stringify!(Contains), - "::", - stringify!(b) - ) - ); + fn test_field_empty() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).empty) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Contains), + "::", + stringify!(empty) + ) + ); + } + test_field_empty(); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 1usize, + concat!( + "Offset of field: ", + stringify!(Contains), + "::", + stringify!(b) + ) + ); + } + test_field_b(); } diff --git a/tests/expectations/tests/convert-floats.rs b/tests/expectations/tests/convert-floats.rs index d6e4628511..6e6d1c678b 100644 --- a/tests/expectations/tests/convert-floats.rs +++ b/tests/expectations/tests/convert-floats.rs @@ -33,75 +33,110 @@ fn bindgen_test_layout_foo() { 8usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, - 4usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(baz)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bazz) as usize - ptr as usize - }, - 8usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bazz)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bazzz) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(bazzz) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).complexFloat) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(complexFloat) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).complexDouble) as usize - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(complexDouble) - ) - ); + fn test_field_bar() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(bar) + ) + ); + } + test_field_bar(); + fn test_field_baz() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(baz) + ) + ); + } + test_field_baz(); + fn test_field_bazz() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bazz) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(bazz) + ) + ); + } + test_field_bazz(); + fn test_field_bazzz() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bazzz) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(bazzz) + ) + ); + } + test_field_bazzz(); + fn test_field_complexFloat() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).complexFloat) as usize - + ptr as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(complexFloat) + ) + ); + } + test_field_complexFloat(); + fn test_field_complexDouble() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).complexDouble) as usize - + ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(complexDouble) + ) + ); + } + test_field_complexDouble(); } impl Default for foo { fn default() -> Self { diff --git a/tests/expectations/tests/ctypes-prefix-path.rs b/tests/expectations/tests/ctypes-prefix-path.rs index b0c7a0f708..0dc4909566 100644 --- a/tests/expectations/tests/ctypes-prefix-path.rs +++ b/tests/expectations/tests/ctypes-prefix-path.rs @@ -31,33 +31,47 @@ fn bindgen_test_layout_foo() { 8usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { - let uninit = ::core::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::core::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) - ); - assert_eq!( - unsafe { - let uninit = ::core::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::core::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 4usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) - ); - assert_eq!( - unsafe { - let uninit = ::core::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 8usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::core::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::core::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) + ); + } + test_field_a(); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = ::core::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::core::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 4usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) + ); + } + test_field_b(); + fn test_field_bar() { + assert_eq!( + unsafe { + let uninit = ::core::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(bar) + ) + ); + } + test_field_bar(); } impl Default for foo { fn default() -> Self { diff --git a/tests/expectations/tests/derive-bitfield-method-same-name.rs b/tests/expectations/tests/derive-bitfield-method-same-name.rs index 3cde87dfe7..56bbdc5433 100644 --- a/tests/expectations/tests/derive-bitfield-method-same-name.rs +++ b/tests/expectations/tests/derive-bitfield-method-same-name.rs @@ -114,20 +114,23 @@ fn bindgen_test_layout_Foo() { 4usize, concat!("Alignment of ", stringify!(Foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).large) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(large) - ) - ); + fn test_field_large() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).large) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Foo), + "::", + stringify!(large) + ) + ); + } + test_field_large(); } extern "C" { #[link_name = "\u{1}_ZN3Foo4typeEv"] diff --git a/tests/expectations/tests/derive-clone.rs b/tests/expectations/tests/derive-clone.rs index 25d30b215e..4a80a856d8 100644 --- a/tests/expectations/tests/derive-clone.rs +++ b/tests/expectations/tests/derive-clone.rs @@ -23,20 +23,24 @@ fn bindgen_test_layout_ShouldDeriveClone() { 4usize, concat!("Alignment of ", stringify!(ShouldDeriveClone)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).large) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldDeriveClone), - "::", - stringify!(large) - ) - ); + fn test_field_large() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).large) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ShouldDeriveClone), + "::", + stringify!(large) + ) + ); + } + test_field_large(); } impl Default for ShouldDeriveClone { fn default() -> Self { diff --git a/tests/expectations/tests/derive-clone_1_0.rs b/tests/expectations/tests/derive-clone_1_0.rs index f18041cef2..90c8c72aa4 100644 --- a/tests/expectations/tests/derive-clone_1_0.rs +++ b/tests/expectations/tests/derive-clone_1_0.rs @@ -24,20 +24,24 @@ fn bindgen_test_layout_ShouldImplClone() { 4usize, concat!("Alignment of ", stringify!(ShouldImplClone)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).large) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldImplClone), - "::", - stringify!(large) - ) - ); + fn test_field_large() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).large) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ShouldImplClone), + "::", + stringify!(large) + ) + ); + } + test_field_large(); } impl Clone for ShouldImplClone { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/derive-debug-bitfield-core.rs b/tests/expectations/tests/derive-debug-bitfield-core.rs index 1eb5297c8d..249df3d5e0 100644 --- a/tests/expectations/tests/derive-debug-bitfield-core.rs +++ b/tests/expectations/tests/derive-debug-bitfield-core.rs @@ -112,20 +112,24 @@ fn bindgen_test_layout_C() { 4usize, concat!("Alignment of ", stringify!(C)) ); - assert_eq!( - unsafe { - let uninit = ::core::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::core::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(large_array) - ) - ); + fn test_field_large_array() { + assert_eq!( + unsafe { + let uninit = ::core::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::core::ptr::addr_of!((*ptr).large_array) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(large_array) + ) + ); + } + test_field_large_array(); } impl Default for C { fn default() -> Self { diff --git a/tests/expectations/tests/derive-debug-bitfield.rs b/tests/expectations/tests/derive-debug-bitfield.rs index 57e246dc33..4ca28af3b4 100644 --- a/tests/expectations/tests/derive-debug-bitfield.rs +++ b/tests/expectations/tests/derive-debug-bitfield.rs @@ -110,20 +110,23 @@ fn bindgen_test_layout_C() { 4usize, concat!("Alignment of ", stringify!(C)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(large_array) - ) - ); + fn test_field_large_array() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(large_array) + ) + ); + } + test_field_large_array(); } impl Default for C { fn default() -> Self { diff --git a/tests/expectations/tests/derive-debug-function-pointer.rs b/tests/expectations/tests/derive-debug-function-pointer.rs index da522aa4b9..9f4cecedce 100644 --- a/tests/expectations/tests/derive-debug-function-pointer.rs +++ b/tests/expectations/tests/derive-debug-function-pointer.rs @@ -25,34 +25,40 @@ fn bindgen_test_layout_Nice() { 8usize, concat!("Alignment of ", stringify!(Nice)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pointer) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Nice), - "::", - stringify!(pointer) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(Nice), - "::", - stringify!(large_array) - ) - ); + fn test_field_pointer() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pointer) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Nice), + "::", + stringify!(pointer) + ) + ); + } + test_field_pointer(); + fn test_field_large_array() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(Nice), + "::", + stringify!(large_array) + ) + ); + } + test_field_large_array(); } impl Default for Nice { fn default() -> Self { diff --git a/tests/expectations/tests/derive-debug-mangle-name.rs b/tests/expectations/tests/derive-debug-mangle-name.rs index 5fb9d3813e..8e66efc674 100644 --- a/tests/expectations/tests/derive-debug-mangle-name.rs +++ b/tests/expectations/tests/derive-debug-mangle-name.rs @@ -30,34 +30,44 @@ fn bindgen_test_layout_perf_event_attr__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(perf_event_attr__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = :: std :: mem :: MaybeUninit :: < perf_event_attr__bindgen_ty_1 > :: uninit () ; - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(perf_event_attr__bindgen_ty_1), - "::", - stringify!(b) - ) - ); - assert_eq!( - unsafe { - let uninit = :: std :: mem :: MaybeUninit :: < perf_event_attr__bindgen_ty_1 > :: uninit () ; - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(perf_event_attr__bindgen_ty_1), - "::", - stringify!(c) - ) - ); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + perf_event_attr__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(perf_event_attr__bindgen_ty_1), + "::", + stringify!(b) + ) + ); + } + test_field_b(); + fn test_field_c() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + perf_event_attr__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(perf_event_attr__bindgen_ty_1), + "::", + stringify!(c) + ) + ); + } + test_field_c(); } impl Default for perf_event_attr__bindgen_ty_1 { fn default() -> Self { @@ -85,34 +95,42 @@ fn bindgen_test_layout_perf_event_attr() { 4usize, concat!("Alignment of ", stringify!(perf_event_attr)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(perf_event_attr), - "::", - stringify!(type_) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(perf_event_attr), - "::", - stringify!(a) - ) - ); + fn test_field_type() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(perf_event_attr), + "::", + stringify!(type_) + ) + ); + } + test_field_type(); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(perf_event_attr), + "::", + stringify!(a) + ) + ); + } + test_field_a(); } impl Default for perf_event_attr { fn default() -> Self { diff --git a/tests/expectations/tests/derive-debug-opaque-template-instantiation.rs b/tests/expectations/tests/derive-debug-opaque-template-instantiation.rs index 51071c3241..78101ada8f 100644 --- a/tests/expectations/tests/derive-debug-opaque-template-instantiation.rs +++ b/tests/expectations/tests/derive-debug-opaque-template-instantiation.rs @@ -21,20 +21,23 @@ fn bindgen_test_layout_Instance() { 4usize, concat!("Alignment of ", stringify!(Instance)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).val) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Instance), - "::", - stringify!(val) - ) - ); + fn test_field_val() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).val) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Instance), + "::", + stringify!(val) + ) + ); + } + test_field_val(); } impl Default for Instance { fn default() -> Self { diff --git a/tests/expectations/tests/derive-debug-opaque.rs b/tests/expectations/tests/derive-debug-opaque.rs index 6f8a0d9114..06f33952e2 100644 --- a/tests/expectations/tests/derive-debug-opaque.rs +++ b/tests/expectations/tests/derive-debug-opaque.rs @@ -53,20 +53,23 @@ fn bindgen_test_layout_OpaqueUser() { 4usize, concat!("Alignment of ", stringify!(OpaqueUser)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).opaque) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(OpaqueUser), - "::", - stringify!(opaque) - ) - ); + fn test_field_opaque() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).opaque) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(OpaqueUser), + "::", + stringify!(opaque) + ) + ); + } + test_field_opaque(); } impl Default for OpaqueUser { fn default() -> Self { diff --git a/tests/expectations/tests/derive-default-and-blocklist.rs b/tests/expectations/tests/derive-default-and-blocklist.rs index 7e80e33683..4b8ecf9787 100644 --- a/tests/expectations/tests/derive-default-and-blocklist.rs +++ b/tests/expectations/tests/derive-default-and-blocklist.rs @@ -25,21 +25,24 @@ fn bindgen_test_layout_ShouldNotDeriveDefault() { 1usize, concat!("Alignment of ", stringify!(ShouldNotDeriveDefault)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldNotDeriveDefault), - "::", - stringify!(a) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ShouldNotDeriveDefault), + "::", + stringify!(a) + ) + ); + } + test_field_a(); } impl Default for ShouldNotDeriveDefault { fn default() -> Self { diff --git a/tests/expectations/tests/derive-fn-ptr.rs b/tests/expectations/tests/derive-fn-ptr.rs index d28c53287d..bab7f6b844 100644 --- a/tests/expectations/tests/derive-fn-ptr.rs +++ b/tests/expectations/tests/derive-fn-ptr.rs @@ -42,20 +42,23 @@ fn bindgen_test_layout_Foo() { 8usize, concat!("Alignment of ", stringify!(Foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).callback) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(callback) - ) - ); + fn test_field_callback() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).callback) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Foo), + "::", + stringify!(callback) + ) + ); + } + test_field_callback(); } pub type my_fun2_t = ::std::option::Option< unsafe extern "C" fn( @@ -90,18 +93,21 @@ fn bindgen_test_layout_Bar() { 8usize, concat!("Alignment of ", stringify!(Bar)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).callback) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(callback) - ) - ); + fn test_field_callback() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).callback) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Bar), + "::", + stringify!(callback) + ) + ); + } + test_field_callback(); } diff --git a/tests/expectations/tests/derive-hash-and-blocklist.rs b/tests/expectations/tests/derive-hash-and-blocklist.rs index 15d1a6d71d..ca436fa882 100644 --- a/tests/expectations/tests/derive-hash-and-blocklist.rs +++ b/tests/expectations/tests/derive-hash-and-blocklist.rs @@ -24,21 +24,24 @@ fn bindgen_test_layout_ShouldNotDeriveHash() { 1usize, concat!("Alignment of ", stringify!(ShouldNotDeriveHash)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldNotDeriveHash), - "::", - stringify!(a) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ShouldNotDeriveHash), + "::", + stringify!(a) + ) + ); + } + test_field_a(); } impl Default for ShouldNotDeriveHash { fn default() -> Self { diff --git a/tests/expectations/tests/derive-hash-blocklisting.rs b/tests/expectations/tests/derive-hash-blocklisting.rs index 28ce3ab8e0..e2aaf03f03 100644 --- a/tests/expectations/tests/derive-hash-blocklisting.rs +++ b/tests/expectations/tests/derive-hash-blocklisting.rs @@ -30,20 +30,24 @@ fn bindgen_test_layout_AllowlistedOne() { 4usize, concat!("Alignment of ", stringify!(AllowlistedOne)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AllowlistedOne), - "::", - stringify!(a) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(AllowlistedOne), + "::", + stringify!(a) + ) + ); + } + test_field_a(); } impl Default for AllowlistedOne { fn default() -> Self { @@ -71,20 +75,24 @@ fn bindgen_test_layout_AllowlistedTwo() { 4usize, concat!("Alignment of ", stringify!(AllowlistedTwo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AllowlistedTwo), - "::", - stringify!(b) - ) - ); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(AllowlistedTwo), + "::", + stringify!(b) + ) + ); + } + test_field_b(); } impl Default for AllowlistedTwo { fn default() -> Self { diff --git a/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs b/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs index 74644f98ac..c519885610 100644 --- a/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs +++ b/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs @@ -29,34 +29,42 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(a) + ) + ); + } + test_field_a(); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(b) + ) + ); + } + test_field_b(); } #[test] fn bindgen_test_layout_foo() { @@ -70,13 +78,21 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) - ); + fn test_field_bar() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(bar) + ) + ); + } + test_field_bar(); } diff --git a/tests/expectations/tests/derive-hash-struct-with-float-array.rs b/tests/expectations/tests/derive-hash-struct-with-float-array.rs index b22cb25ef1..b561cc3777 100644 --- a/tests/expectations/tests/derive-hash-struct-with-float-array.rs +++ b/tests/expectations/tests/derive-hash-struct-with-float-array.rs @@ -23,13 +23,21 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) - ); + fn test_field_bar() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(bar) + ) + ); + } + test_field_bar(); } diff --git a/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs b/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs index d1f7ae3f77..abba4b28a8 100644 --- a/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs +++ b/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs @@ -53,30 +53,36 @@ fn bindgen_test_layout_test() { 4usize, concat!("Alignment of ", stringify!(test)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(test), "::", stringify!(a)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(test), - "::", - stringify!(zero_length_array) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(test), "::", stringify!(a)) + ); + } + test_field_a(); + fn test_field_zero_length_array() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(test), + "::", + stringify!(zero_length_array) + ) + ); + } + test_field_zero_length_array(); } #[repr(C)] #[derive(Debug, Default)] diff --git a/tests/expectations/tests/derive-hash-struct-with-pointer.rs b/tests/expectations/tests/derive-hash-struct-with-pointer.rs index 8931689b95..658810080c 100644 --- a/tests/expectations/tests/derive-hash-struct-with-pointer.rs +++ b/tests/expectations/tests/derive-hash-struct-with-pointer.rs @@ -23,20 +23,24 @@ fn bindgen_test_layout_ConstPtrMutObj() { 8usize, concat!("Alignment of ", stringify!(ConstPtrMutObj)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ConstPtrMutObj), - "::", - stringify!(bar) - ) - ); + fn test_field_bar() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ConstPtrMutObj), + "::", + stringify!(bar) + ) + ); + } + test_field_bar(); } impl Default for ConstPtrMutObj { fn default() -> Self { @@ -64,20 +68,23 @@ fn bindgen_test_layout_MutPtrMutObj() { 8usize, concat!("Alignment of ", stringify!(MutPtrMutObj)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(MutPtrMutObj), - "::", - stringify!(bar) - ) - ); + fn test_field_bar() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(MutPtrMutObj), + "::", + stringify!(bar) + ) + ); + } + test_field_bar(); } impl Default for MutPtrMutObj { fn default() -> Self { @@ -105,20 +112,24 @@ fn bindgen_test_layout_MutPtrConstObj() { 8usize, concat!("Alignment of ", stringify!(MutPtrConstObj)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(MutPtrConstObj), - "::", - stringify!(bar) - ) - ); + fn test_field_bar() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(MutPtrConstObj), + "::", + stringify!(bar) + ) + ); + } + test_field_bar(); } impl Default for MutPtrConstObj { fn default() -> Self { @@ -146,20 +157,24 @@ fn bindgen_test_layout_ConstPtrConstObj() { 8usize, concat!("Alignment of ", stringify!(ConstPtrConstObj)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ConstPtrConstObj), - "::", - stringify!(bar) - ) - ); + fn test_field_bar() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ConstPtrConstObj), + "::", + stringify!(bar) + ) + ); + } + test_field_bar(); } impl Default for ConstPtrConstObj { fn default() -> Self { diff --git a/tests/expectations/tests/derive-hash-template-inst-float.rs b/tests/expectations/tests/derive-hash-template-inst-float.rs index 27f7f72c8c..18cccb3b56 100644 --- a/tests/expectations/tests/derive-hash-template-inst-float.rs +++ b/tests/expectations/tests/derive-hash-template-inst-float.rs @@ -39,15 +39,23 @@ fn bindgen_test_layout_IntStr() { 4usize, concat!("Alignment of ", stringify!(IntStr)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(IntStr), "::", stringify!(a)) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(IntStr), + "::", + stringify!(a) + ) + ); + } + test_field_a(); } impl Default for IntStr { fn default() -> Self { @@ -76,20 +84,23 @@ fn bindgen_test_layout_FloatStr() { 4usize, concat!("Alignment of ", stringify!(FloatStr)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(FloatStr), - "::", - stringify!(a) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(FloatStr), + "::", + stringify!(a) + ) + ); + } + test_field_a(); } impl Default for FloatStr { fn default() -> Self { diff --git a/tests/expectations/tests/derive-partialeq-and-blocklist.rs b/tests/expectations/tests/derive-partialeq-and-blocklist.rs index e3d812779c..23c493dc28 100644 --- a/tests/expectations/tests/derive-partialeq-and-blocklist.rs +++ b/tests/expectations/tests/derive-partialeq-and-blocklist.rs @@ -25,21 +25,25 @@ fn bindgen_test_layout_ShouldNotDerivePartialEq() { 1usize, concat!("Alignment of ", stringify!(ShouldNotDerivePartialEq)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldNotDerivePartialEq), - "::", - stringify!(a) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ShouldNotDerivePartialEq), + "::", + stringify!(a) + ) + ); + } + test_field_a(); } impl Default for ShouldNotDerivePartialEq { fn default() -> Self { diff --git a/tests/expectations/tests/derive-partialeq-base.rs b/tests/expectations/tests/derive-partialeq-base.rs index ce24144734..25f37549f6 100644 --- a/tests/expectations/tests/derive-partialeq-base.rs +++ b/tests/expectations/tests/derive-partialeq-base.rs @@ -22,20 +22,23 @@ fn bindgen_test_layout_Base() { 4usize, concat!("Alignment of ", stringify!(Base)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).large) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Base), - "::", - stringify!(large) - ) - ); + fn test_field_large() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).large) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Base), + "::", + stringify!(large) + ) + ); + } + test_field_large(); } impl Default for Base { fn default() -> Self { diff --git a/tests/expectations/tests/derive-partialeq-bitfield.rs b/tests/expectations/tests/derive-partialeq-bitfield.rs index 94b47eba74..b27f1cb5d9 100644 --- a/tests/expectations/tests/derive-partialeq-bitfield.rs +++ b/tests/expectations/tests/derive-partialeq-bitfield.rs @@ -110,20 +110,23 @@ fn bindgen_test_layout_C() { 4usize, concat!("Alignment of ", stringify!(C)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(large_array) - ) - ); + fn test_field_large_array() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(large_array) + ) + ); + } + test_field_large_array(); } impl Default for C { fn default() -> Self { diff --git a/tests/expectations/tests/derive-partialeq-core.rs b/tests/expectations/tests/derive-partialeq-core.rs index 171c0a4513..eec02324e4 100644 --- a/tests/expectations/tests/derive-partialeq-core.rs +++ b/tests/expectations/tests/derive-partialeq-core.rs @@ -24,20 +24,24 @@ fn bindgen_test_layout_C() { 4usize, concat!("Alignment of ", stringify!(C)) ); - assert_eq!( - unsafe { - let uninit = ::core::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::core::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(large_array) - ) - ); + fn test_field_large_array() { + assert_eq!( + unsafe { + let uninit = ::core::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::core::ptr::addr_of!((*ptr).large_array) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(large_array) + ) + ); + } + test_field_large_array(); } impl Default for C { fn default() -> Self { diff --git a/tests/expectations/tests/derive-partialeq-pointer.rs b/tests/expectations/tests/derive-partialeq-pointer.rs index a2d6246c20..4b29a5d4f2 100644 --- a/tests/expectations/tests/derive-partialeq-pointer.rs +++ b/tests/expectations/tests/derive-partialeq-pointer.rs @@ -22,15 +22,18 @@ fn bindgen_test_layout_Bar() { 8usize, concat!("Alignment of ", stringify!(Bar)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(b)) - ); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(b)) + ); + } + test_field_b(); } impl Default for Bar { fn default() -> Self { @@ -112,15 +115,18 @@ fn bindgen_test_layout_a() { 1usize, concat!("Alignment of ", stringify!(a)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(a), "::", stringify!(d)) - ); + fn test_field_d() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(a), "::", stringify!(d)) + ); + } + test_field_d(); } impl Default for a { fn default() -> Self { diff --git a/tests/expectations/tests/derive-partialeq-union.rs b/tests/expectations/tests/derive-partialeq-union.rs index c8ff8afa53..0007477518 100644 --- a/tests/expectations/tests/derive-partialeq-union.rs +++ b/tests/expectations/tests/derive-partialeq-union.rs @@ -24,36 +24,44 @@ fn bindgen_test_layout_ShouldNotDerivePartialEq() { 4usize, concat!("Alignment of ", stringify!(ShouldNotDerivePartialEq)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldNotDerivePartialEq), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldNotDerivePartialEq), - "::", - stringify!(b) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ShouldNotDerivePartialEq), + "::", + stringify!(a) + ) + ); + } + test_field_a(); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ShouldNotDerivePartialEq), + "::", + stringify!(b) + ) + ); + } + test_field_b(); } impl Default for ShouldNotDerivePartialEq { fn default() -> Self { diff --git a/tests/expectations/tests/derive-partialeq-union_1_0.rs b/tests/expectations/tests/derive-partialeq-union_1_0.rs index b45cc22168..dd6f756cbc 100644 --- a/tests/expectations/tests/derive-partialeq-union_1_0.rs +++ b/tests/expectations/tests/derive-partialeq-union_1_0.rs @@ -68,36 +68,42 @@ fn bindgen_test_layout_ShouldDerivePartialEq() { 4usize, concat!("Alignment of ", stringify!(ShouldDerivePartialEq)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldDerivePartialEq), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldDerivePartialEq), - "::", - stringify!(b) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ShouldDerivePartialEq), + "::", + stringify!(a) + ) + ); + } + test_field_a(); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ShouldDerivePartialEq), + "::", + stringify!(b) + ) + ); + } + test_field_b(); } impl Clone for ShouldDerivePartialEq { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/disable-nested-struct-naming.rs b/tests/expectations/tests/disable-nested-struct-naming.rs index 6085eb7a75..23391041d6 100644 --- a/tests/expectations/tests/disable-nested-struct-naming.rs +++ b/tests/expectations/tests/disable-nested-struct-naming.rs @@ -45,15 +45,23 @@ fn bindgen_test_layout_bar4() { 4usize, concat!("Alignment of ", stringify!(bar4)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).x4) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(bar4), "::", stringify!(x4)) - ); + fn test_field_x4() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).x4) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(bar4), + "::", + stringify!(x4) + ) + ); + } + test_field_x4(); } #[test] fn bindgen_test_layout_bar1__bindgen_ty_1__bindgen_ty_1() { @@ -70,38 +78,44 @@ fn bindgen_test_layout_bar1__bindgen_ty_1__bindgen_ty_1() { stringify!(bar1__bindgen_ty_1__bindgen_ty_1) ) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - bar1__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).x3) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(bar1__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(x3) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - bar1__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b4) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(bar1__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(b4) - ) - ); + fn test_field_x3() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + bar1__bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).x3) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(bar1__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(x3) + ) + ); + } + test_field_x3(); + fn test_field_b4() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + bar1__bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b4) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(bar1__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(b4) + ) + ); + } + test_field_b4(); } #[test] fn bindgen_test_layout_bar1__bindgen_ty_1() { @@ -115,36 +129,42 @@ fn bindgen_test_layout_bar1__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(bar1__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).x2) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(bar1__bindgen_ty_1), - "::", - stringify!(x2) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b3) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(bar1__bindgen_ty_1), - "::", - stringify!(b3) - ) - ); + fn test_field_x2() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).x2) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(bar1__bindgen_ty_1), + "::", + stringify!(x2) + ) + ); + } + test_field_x2(); + fn test_field_b3() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b3) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(bar1__bindgen_ty_1), + "::", + stringify!(b3) + ) + ); + } + test_field_b3(); } #[test] fn bindgen_test_layout_bar1() { @@ -158,24 +178,40 @@ fn bindgen_test_layout_bar1() { 4usize, concat!("Alignment of ", stringify!(bar1)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).x1) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(bar1), "::", stringify!(x1)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b2) as usize - ptr as usize - }, - 4usize, - concat!("Offset of field: ", stringify!(bar1), "::", stringify!(b2)) - ); + fn test_field_x1() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).x1) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(bar1), + "::", + stringify!(x1) + ) + ); + } + test_field_x1(); + fn test_field_b2() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b2) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(bar1), + "::", + stringify!(b2) + ) + ); + } + test_field_b2(); } #[test] fn bindgen_test_layout_foo() { @@ -189,15 +225,18 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b1) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(b1)) - ); + fn test_field_b1() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b1) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(b1)) + ); + } + test_field_b1(); } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -226,15 +265,18 @@ fn bindgen_test_layout_baz() { 4usize, concat!("Alignment of ", stringify!(baz)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(baz), "::", stringify!(x)) - ); + fn test_field_x() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(baz), "::", stringify!(x)) + ); + } + test_field_x(); } #[test] fn bindgen_test_layout__bindgen_ty_1__bindgen_ty_1() { @@ -248,22 +290,25 @@ fn bindgen_test_layout__bindgen_ty_1__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(_bindgen_ty_1__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::<_bindgen_ty_1__bindgen_ty_1>::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(b) - ) - ); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + _bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(b) + ) + ); + } + test_field_b(); } #[test] fn bindgen_test_layout__bindgen_ty_1() { @@ -277,20 +322,23 @@ fn bindgen_test_layout__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(_bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::<_bindgen_ty_1>::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).anon2) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_bindgen_ty_1), - "::", - stringify!(anon2) - ) - ); + fn test_field_anon2() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::<_bindgen_ty_1>::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).anon2) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_bindgen_ty_1), + "::", + stringify!(anon2) + ) + ); + } + test_field_anon2(); } extern "C" { pub static mut anon1: _bindgen_ty_1; diff --git a/tests/expectations/tests/disable-untagged-union.rs b/tests/expectations/tests/disable-untagged-union.rs index 8031a0c18a..912238b345 100644 --- a/tests/expectations/tests/disable-untagged-union.rs +++ b/tests/expectations/tests/disable-untagged-union.rs @@ -67,22 +67,38 @@ fn bindgen_test_layout_Foo() { 4usize, concat!("Alignment of ", stringify!(Foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(baz)) - ); + fn test_field_bar() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Foo), + "::", + stringify!(bar) + ) + ); + } + test_field_bar(); + fn test_field_baz() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Foo), + "::", + stringify!(baz) + ) + ); + } + test_field_baz(); } diff --git a/tests/expectations/tests/do-not-derive-copy.rs b/tests/expectations/tests/do-not-derive-copy.rs index ac1943230b..2e02cc5096 100644 --- a/tests/expectations/tests/do-not-derive-copy.rs +++ b/tests/expectations/tests/do-not-derive-copy.rs @@ -25,20 +25,23 @@ fn bindgen_test_layout_WouldBeCopyButWeAreNotDerivingCopy() { stringify!(WouldBeCopyButWeAreNotDerivingCopy) ) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - WouldBeCopyButWeAreNotDerivingCopy, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WouldBeCopyButWeAreNotDerivingCopy), - "::", - stringify!(x) - ) - ); + fn test_field_x() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + WouldBeCopyButWeAreNotDerivingCopy, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WouldBeCopyButWeAreNotDerivingCopy), + "::", + stringify!(x) + ) + ); + } + test_field_x(); } diff --git a/tests/expectations/tests/doggo-or-null.rs b/tests/expectations/tests/doggo-or-null.rs index 88093fd1e0..0b34b3d05b 100644 --- a/tests/expectations/tests/doggo-or-null.rs +++ b/tests/expectations/tests/doggo-or-null.rs @@ -22,15 +22,23 @@ fn bindgen_test_layout_Doggo() { 4usize, concat!("Alignment of ", stringify!(Doggo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Doggo), "::", stringify!(x)) - ); + fn test_field_x() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Doggo), + "::", + stringify!(x) + ) + ); + } + test_field_x(); } #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq)] diff --git a/tests/expectations/tests/duplicated-namespaces-definitions.rs b/tests/expectations/tests/duplicated-namespaces-definitions.rs index 9be3d27c45..2322aa87ce 100644 --- a/tests/expectations/tests/duplicated-namespaces-definitions.rs +++ b/tests/expectations/tests/duplicated-namespaces-definitions.rs @@ -30,34 +30,40 @@ pub mod root { 4usize, concat!("Alignment of ", stringify!(Bar)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(foo) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(baz) - ) - ); + fn test_field_foo() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Bar), + "::", + stringify!(foo) + ) + ); + } + test_field_foo(); + fn test_field_baz() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(Bar), + "::", + stringify!(baz) + ) + ); + } + test_field_baz(); } } pub mod bar { @@ -80,20 +86,23 @@ pub mod root { 8usize, concat!("Alignment of ", stringify!(Foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(ptr) - ) - ); + fn test_field_ptr() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Foo), + "::", + stringify!(ptr) + ) + ); + } + test_field_ptr(); } impl Default for Foo { fn default() -> Self { diff --git a/tests/expectations/tests/dynamic_loading_with_blocklist.rs b/tests/expectations/tests/dynamic_loading_with_blocklist.rs index aedc0ad427..f2ffe671cb 100644 --- a/tests/expectations/tests/dynamic_loading_with_blocklist.rs +++ b/tests/expectations/tests/dynamic_loading_with_blocklist.rs @@ -22,15 +22,18 @@ fn bindgen_test_layout_X() { 4usize, concat!("Alignment of ", stringify!(X)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr)._x) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(X), "::", stringify!(_x)) - ); + fn test_field__x() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr)._x) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(X), "::", stringify!(_x)) + ); + } + test_field__x(); } extern "C" { #[link_name = "\u{1}_ZN1X13some_functionEv"] diff --git a/tests/expectations/tests/dynamic_loading_with_class.rs b/tests/expectations/tests/dynamic_loading_with_class.rs index d995d9bf8e..03655c8efa 100644 --- a/tests/expectations/tests/dynamic_loading_with_class.rs +++ b/tests/expectations/tests/dynamic_loading_with_class.rs @@ -22,15 +22,18 @@ fn bindgen_test_layout_A() { 4usize, concat!("Alignment of ", stringify!(A)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr)._x) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(_x)) - ); + fn test_field__x() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr)._x) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(A), "::", stringify!(_x)) + ); + } + test_field__x(); } extern "C" { #[link_name = "\u{1}_ZN1A13some_functionEv"] diff --git a/tests/expectations/tests/enum-default-bitfield.rs b/tests/expectations/tests/enum-default-bitfield.rs index 406b29e050..6ea42d0b91 100644 --- a/tests/expectations/tests/enum-default-bitfield.rs +++ b/tests/expectations/tests/enum-default-bitfield.rs @@ -53,20 +53,23 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(member) - ) - ); + fn test_field_member() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(member) + ) + ); + } + test_field_member(); } impl Default for foo { fn default() -> Self { diff --git a/tests/expectations/tests/enum-default-consts.rs b/tests/expectations/tests/enum-default-consts.rs index dc0889f1c7..631617bd30 100644 --- a/tests/expectations/tests/enum-default-consts.rs +++ b/tests/expectations/tests/enum-default-consts.rs @@ -25,20 +25,23 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(member) - ) - ); + fn test_field_member() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(member) + ) + ); + } + test_field_member(); } impl Default for foo { fn default() -> Self { diff --git a/tests/expectations/tests/enum-default-module.rs b/tests/expectations/tests/enum-default-module.rs index 8f2b603c55..e74e9fc3e8 100644 --- a/tests/expectations/tests/enum-default-module.rs +++ b/tests/expectations/tests/enum-default-module.rs @@ -27,20 +27,23 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(member) - ) - ); + fn test_field_member() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(member) + ) + ); + } + test_field_member(); } impl Default for foo { fn default() -> Self { diff --git a/tests/expectations/tests/enum-default-rust.rs b/tests/expectations/tests/enum-default-rust.rs index e8d4a0bec9..8cc843a34d 100644 --- a/tests/expectations/tests/enum-default-rust.rs +++ b/tests/expectations/tests/enum-default-rust.rs @@ -30,20 +30,23 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(member) - ) - ); + fn test_field_member() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(member) + ) + ); + } + test_field_member(); } impl Default for foo { fn default() -> Self { diff --git a/tests/expectations/tests/enum-no-debug-rust.rs b/tests/expectations/tests/enum-no-debug-rust.rs index 7808527c74..6291137f19 100644 --- a/tests/expectations/tests/enum-no-debug-rust.rs +++ b/tests/expectations/tests/enum-no-debug-rust.rs @@ -30,20 +30,23 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(member) - ) - ); + fn test_field_member() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(member) + ) + ); + } + test_field_member(); } impl Default for foo { fn default() -> Self { diff --git a/tests/expectations/tests/enum.rs b/tests/expectations/tests/enum.rs index 5464038510..484adf5b1d 100644 --- a/tests/expectations/tests/enum.rs +++ b/tests/expectations/tests/enum.rs @@ -25,20 +25,23 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(member) - ) - ); + fn test_field_member() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(member) + ) + ); + } + test_field_member(); } impl Default for foo { fn default() -> Self { diff --git a/tests/expectations/tests/enum_and_vtable_mangling.rs b/tests/expectations/tests/enum_and_vtable_mangling.rs index 372921fdad..5f41a62b0d 100644 --- a/tests/expectations/tests/enum_and_vtable_mangling.rs +++ b/tests/expectations/tests/enum_and_vtable_mangling.rs @@ -35,15 +35,18 @@ fn bindgen_test_layout_C() { 8usize, concat!("Alignment of ", stringify!(C)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize - }, - 8usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(i)) - ); + fn test_field_i() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize + }, + 8usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(i)) + ); + } + test_field_i(); } impl Default for C { fn default() -> Self { diff --git a/tests/expectations/tests/explicit-padding.rs b/tests/expectations/tests/explicit-padding.rs index 2614f83b11..508c6b5b86 100644 --- a/tests/expectations/tests/explicit-padding.rs +++ b/tests/expectations/tests/explicit-padding.rs @@ -26,48 +26,57 @@ fn bindgen_test_layout_pad_me() { 4usize, concat!("Alignment of ", stringify!(pad_me)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).first) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(pad_me), - "::", - stringify!(first) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).second) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(pad_me), - "::", - stringify!(second) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).third) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(pad_me), - "::", - stringify!(third) - ) - ); + fn test_field_first() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).first) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(pad_me), + "::", + stringify!(first) + ) + ); + } + test_field_first(); + fn test_field_second() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).second) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(pad_me), + "::", + stringify!(second) + ) + ); + } + test_field_second(); + fn test_field_third() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).third) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(pad_me), + "::", + stringify!(third) + ) + ); + } + test_field_third(); } #[repr(C)] #[derive(Copy, Clone)] @@ -88,48 +97,57 @@ fn bindgen_test_layout_dont_pad_me() { 4usize, concat!("Alignment of ", stringify!(dont_pad_me)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).first) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(dont_pad_me), - "::", - stringify!(first) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).second) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(dont_pad_me), - "::", - stringify!(second) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).third) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(dont_pad_me), - "::", - stringify!(third) - ) - ); + fn test_field_first() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).first) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(dont_pad_me), + "::", + stringify!(first) + ) + ); + } + test_field_first(); + fn test_field_second() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).second) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(dont_pad_me), + "::", + stringify!(second) + ) + ); + } + test_field_second(); + fn test_field_third() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).third) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(dont_pad_me), + "::", + stringify!(third) + ) + ); + } + test_field_third(); } impl Default for dont_pad_me { fn default() -> Self { diff --git a/tests/expectations/tests/extern-const-struct.rs b/tests/expectations/tests/extern-const-struct.rs index a1bd34f98e..ab2b3a661b 100644 --- a/tests/expectations/tests/extern-const-struct.rs +++ b/tests/expectations/tests/extern-const-struct.rs @@ -22,20 +22,23 @@ fn bindgen_test_layout_nsFoo() { 4usize, concat!("Alignment of ", stringify!(nsFoo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).details) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsFoo), - "::", - stringify!(details) - ) - ); + fn test_field_details() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).details) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(nsFoo), + "::", + stringify!(details) + ) + ); + } + test_field_details(); } impl Default for nsFoo { fn default() -> Self { diff --git a/tests/expectations/tests/forward-declaration-autoptr.rs b/tests/expectations/tests/forward-declaration-autoptr.rs index 022089d04e..f46f73b630 100644 --- a/tests/expectations/tests/forward-declaration-autoptr.rs +++ b/tests/expectations/tests/forward-declaration-autoptr.rs @@ -42,20 +42,23 @@ fn bindgen_test_layout_Bar() { 8usize, concat!("Alignment of ", stringify!(Bar)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(m_member) - ) - ); + fn test_field_m_member() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Bar), + "::", + stringify!(m_member) + ) + ); + } + test_field_m_member(); } impl Default for Bar { fn default() -> Self { diff --git a/tests/expectations/tests/forward_declared_complex_types.rs b/tests/expectations/tests/forward_declared_complex_types.rs index 14531d3fff..9c3d7c6648 100644 --- a/tests/expectations/tests/forward_declared_complex_types.rs +++ b/tests/expectations/tests/forward_declared_complex_types.rs @@ -45,15 +45,18 @@ fn bindgen_test_layout_Bar() { 8usize, concat!("Alignment of ", stringify!(Bar)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(f)) - ); + fn test_field_f() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(f)) + ); + } + test_field_f(); } impl Default for Bar { fn default() -> Self { diff --git a/tests/expectations/tests/forward_declared_complex_types_1_0.rs b/tests/expectations/tests/forward_declared_complex_types_1_0.rs index bf9d27ca36..0e79263300 100644 --- a/tests/expectations/tests/forward_declared_complex_types_1_0.rs +++ b/tests/expectations/tests/forward_declared_complex_types_1_0.rs @@ -55,15 +55,18 @@ fn bindgen_test_layout_Bar() { 8usize, concat!("Alignment of ", stringify!(Bar)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(f)) - ); + fn test_field_f() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(f)) + ); + } + test_field_f(); } impl Clone for Bar { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/forward_declared_struct.rs b/tests/expectations/tests/forward_declared_struct.rs index be038ee266..eee7da7378 100644 --- a/tests/expectations/tests/forward_declared_struct.rs +++ b/tests/expectations/tests/forward_declared_struct.rs @@ -22,15 +22,18 @@ fn bindgen_test_layout_a() { 4usize, concat!("Alignment of ", stringify!(a)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(a), "::", stringify!(b)) - ); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(a), "::", stringify!(b)) + ); + } + test_field_b(); } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -49,13 +52,16 @@ fn bindgen_test_layout_c() { 4usize, concat!("Alignment of ", stringify!(c)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(c), "::", stringify!(d)) - ); + fn test_field_d() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(c), "::", stringify!(d)) + ); + } + test_field_d(); } diff --git a/tests/expectations/tests/func_ptr_in_struct.rs b/tests/expectations/tests/func_ptr_in_struct.rs index 3f2a4faa36..8709ee2b1c 100644 --- a/tests/expectations/tests/func_ptr_in_struct.rs +++ b/tests/expectations/tests/func_ptr_in_struct.rs @@ -32,13 +32,21 @@ fn bindgen_test_layout_Foo() { 8usize, concat!("Alignment of ", stringify!(Foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) - ); + fn test_field_bar() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Foo), + "::", + stringify!(bar) + ) + ); + } + test_field_bar(); } diff --git a/tests/expectations/tests/gen-destructors-neg.rs b/tests/expectations/tests/gen-destructors-neg.rs index 8f4eeaf681..09c1486240 100644 --- a/tests/expectations/tests/gen-destructors-neg.rs +++ b/tests/expectations/tests/gen-destructors-neg.rs @@ -22,13 +22,21 @@ fn bindgen_test_layout_Foo() { 4usize, concat!("Alignment of ", stringify!(Foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) - ); + fn test_field_bar() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Foo), + "::", + stringify!(bar) + ) + ); + } + test_field_bar(); } diff --git a/tests/expectations/tests/gen-destructors.rs b/tests/expectations/tests/gen-destructors.rs index 582e482910..79f4ed8089 100644 --- a/tests/expectations/tests/gen-destructors.rs +++ b/tests/expectations/tests/gen-destructors.rs @@ -22,15 +22,23 @@ fn bindgen_test_layout_Foo() { 4usize, concat!("Alignment of ", stringify!(Foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) - ); + fn test_field_bar() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Foo), + "::", + stringify!(bar) + ) + ); + } + test_field_bar(); } extern "C" { #[link_name = "\u{1}_ZN3FooD1Ev"] diff --git a/tests/expectations/tests/i128.rs b/tests/expectations/tests/i128.rs index 656a409bba..545198c64e 100644 --- a/tests/expectations/tests/i128.rs +++ b/tests/expectations/tests/i128.rs @@ -24,32 +24,38 @@ fn bindgen_test_layout_foo() { 16usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).my_signed) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(my_signed) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).my_unsigned) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(my_unsigned) - ) - ); + fn test_field_my_signed() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).my_signed) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(my_signed) + ) + ); + } + test_field_my_signed(); + fn test_field_my_unsigned() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).my_unsigned) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(my_unsigned) + ) + ); + } + test_field_my_unsigned(); } diff --git a/tests/expectations/tests/inline_namespace.rs b/tests/expectations/tests/inline_namespace.rs index b552ae02ee..daa0868563 100644 --- a/tests/expectations/tests/inline_namespace.rs +++ b/tests/expectations/tests/inline_namespace.rs @@ -31,19 +31,22 @@ pub mod root { 4usize, concat!("Alignment of ", stringify!(Bar)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(baz) - ) - ); + fn test_field_baz() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Bar), + "::", + stringify!(baz) + ) + ); + } + test_field_baz(); } } diff --git a/tests/expectations/tests/inline_namespace_conservative.rs b/tests/expectations/tests/inline_namespace_conservative.rs index 57c6e214f8..d855e0616b 100644 --- a/tests/expectations/tests/inline_namespace_conservative.rs +++ b/tests/expectations/tests/inline_namespace_conservative.rs @@ -36,19 +36,22 @@ pub mod root { 4usize, concat!("Alignment of ", stringify!(Bar)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(baz) - ) - ); + fn test_field_baz() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Bar), + "::", + stringify!(baz) + ) + ); + } + test_field_baz(); } } diff --git a/tests/expectations/tests/inner_const.rs b/tests/expectations/tests/inner_const.rs index d93bc8b523..41c990475d 100644 --- a/tests/expectations/tests/inner_const.rs +++ b/tests/expectations/tests/inner_const.rs @@ -30,13 +30,21 @@ fn bindgen_test_layout_Foo() { 4usize, concat!("Alignment of ", stringify!(Foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) - ); + fn test_field_bar() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Foo), + "::", + stringify!(bar) + ) + ); + } + test_field_bar(); } diff --git a/tests/expectations/tests/inner_template_self.rs b/tests/expectations/tests/inner_template_self.rs index e6062718f0..033dc57b16 100644 --- a/tests/expectations/tests/inner_template_self.rs +++ b/tests/expectations/tests/inner_template_self.rs @@ -37,20 +37,23 @@ fn bindgen_test_layout_InstantiateIt() { 8usize, concat!("Alignment of ", stringify!(InstantiateIt)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).m_list) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(InstantiateIt), - "::", - stringify!(m_list) - ) - ); + fn test_field_m_list() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).m_list) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(InstantiateIt), + "::", + stringify!(m_list) + ) + ); + } + test_field_m_list(); } impl Default for InstantiateIt { fn default() -> Self { diff --git a/tests/expectations/tests/issue-1118-using-forward-decl.rs b/tests/expectations/tests/issue-1118-using-forward-decl.rs index b29a572ed6..121c086622 100644 --- a/tests/expectations/tests/issue-1118-using-forward-decl.rs +++ b/tests/expectations/tests/issue-1118-using-forward-decl.rs @@ -23,20 +23,23 @@ fn bindgen_test_layout_nsTArray_base() { 8usize, concat!("Alignment of ", stringify!(nsTArray_base)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsTArray_base), - "::", - stringify!(d) - ) - ); + fn test_field_d() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(nsTArray_base), + "::", + stringify!(d) + ) + ); + } + test_field_d(); } impl Default for nsTArray_base { fn default() -> Self { @@ -78,20 +81,23 @@ fn bindgen_test_layout_nsIContent() { 8usize, concat!("Alignment of ", stringify!(nsIContent)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsIContent), - "::", - stringify!(foo) - ) - ); + fn test_field_foo() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(nsIContent), + "::", + stringify!(foo) + ) + ); + } + test_field_foo(); } impl Default for nsIContent { fn default() -> Self { diff --git a/tests/expectations/tests/issue-1216-variadic-member.rs b/tests/expectations/tests/issue-1216-variadic-member.rs index 5f0cd81806..792586b4dc 100644 --- a/tests/expectations/tests/issue-1216-variadic-member.rs +++ b/tests/expectations/tests/issue-1216-variadic-member.rs @@ -32,13 +32,16 @@ fn bindgen_test_layout_Foo() { 8usize, concat!("Alignment of ", stringify!(Foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(f)) - ); + fn test_field_f() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(f)) + ); + } + test_field_f(); } diff --git a/tests/expectations/tests/issue-1281.rs b/tests/expectations/tests/issue-1281.rs index 62b5748512..9da4c9546f 100644 --- a/tests/expectations/tests/issue-1281.rs +++ b/tests/expectations/tests/issue-1281.rs @@ -27,15 +27,23 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(foo)) - ); + fn test_field_foo() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(foo) + ) + ); + } + test_field_foo(); } #[test] fn bindgen_test_layout_bar() { @@ -49,15 +57,18 @@ fn bindgen_test_layout_bar() { 4usize, concat!("Alignment of ", stringify!(bar)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(bar), "::", stringify!(u)) - ); + fn test_field_u() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(bar), "::", stringify!(u)) + ); + } + test_field_u(); } pub type bar_t = bar; #[repr(C)] @@ -77,13 +88,16 @@ fn bindgen_test_layout_baz() { 4usize, concat!("Alignment of ", stringify!(baz)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(baz), "::", stringify!(f)) - ); + fn test_field_f() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(baz), "::", stringify!(f)) + ); + } + test_field_f(); } diff --git a/tests/expectations/tests/issue-1285.rs b/tests/expectations/tests/issue-1285.rs index e15939bdb8..37f07476fd 100644 --- a/tests/expectations/tests/issue-1285.rs +++ b/tests/expectations/tests/issue-1285.rs @@ -28,34 +28,42 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(a) + ) + ); + } + test_field_a(); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(b) + ) + ); + } + test_field_b(); } impl Default for foo__bindgen_ty_1 { fn default() -> Self { @@ -78,15 +86,23 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) - ); + fn test_field_bar() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(bar) + ) + ); + } + test_field_bar(); } impl Default for foo { fn default() -> Self { diff --git a/tests/expectations/tests/issue-1291.rs b/tests/expectations/tests/issue-1291.rs index 355c64f0f8..6776a19d0a 100644 --- a/tests/expectations/tests/issue-1291.rs +++ b/tests/expectations/tests/issue-1291.rs @@ -37,204 +37,259 @@ fn bindgen_test_layout_RTCRay() { 16usize, concat!("Alignment of ", stringify!(RTCRay)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).org) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(org) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).align0) as usize - ptr as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(align0) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dir) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(dir) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).align1) as usize - ptr as usize - }, - 28usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(align1) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).tnear) as usize - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(tnear) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).tfar) as usize - ptr as usize - }, - 36usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(tfar) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).time) as usize - ptr as usize - }, - 40usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(time) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize - }, - 44usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(mask) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).Ng) as usize - ptr as usize - }, - 48usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(Ng) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).align2) as usize - ptr as usize - }, - 60usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(align2) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize - }, - 64usize, - concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(u)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).v) as usize - ptr as usize - }, - 68usize, - concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(v)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).geomID) as usize - ptr as usize - }, - 72usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(geomID) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).primID) as usize - ptr as usize - }, - 76usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(primID) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).instID) as usize - ptr as usize - }, - 80usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(instID) - ) - ); + fn test_field_org() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).org) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(RTCRay), + "::", + stringify!(org) + ) + ); + } + test_field_org(); + fn test_field_align0() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).align0) as usize - ptr as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(RTCRay), + "::", + stringify!(align0) + ) + ); + } + test_field_align0(); + fn test_field_dir() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dir) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(RTCRay), + "::", + stringify!(dir) + ) + ); + } + test_field_dir(); + fn test_field_align1() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).align1) as usize - ptr as usize + }, + 28usize, + concat!( + "Offset of field: ", + stringify!(RTCRay), + "::", + stringify!(align1) + ) + ); + } + test_field_align1(); + fn test_field_tnear() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tnear) as usize - ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(RTCRay), + "::", + stringify!(tnear) + ) + ); + } + test_field_tnear(); + fn test_field_tfar() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tfar) as usize - ptr as usize + }, + 36usize, + concat!( + "Offset of field: ", + stringify!(RTCRay), + "::", + stringify!(tfar) + ) + ); + } + test_field_tfar(); + fn test_field_time() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).time) as usize - ptr as usize + }, + 40usize, + concat!( + "Offset of field: ", + stringify!(RTCRay), + "::", + stringify!(time) + ) + ); + } + test_field_time(); + fn test_field_mask() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize + }, + 44usize, + concat!( + "Offset of field: ", + stringify!(RTCRay), + "::", + stringify!(mask) + ) + ); + } + test_field_mask(); + fn test_field_Ng() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Ng) as usize - ptr as usize + }, + 48usize, + concat!( + "Offset of field: ", + stringify!(RTCRay), + "::", + stringify!(Ng) + ) + ); + } + test_field_Ng(); + fn test_field_align2() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).align2) as usize - ptr as usize + }, + 60usize, + concat!( + "Offset of field: ", + stringify!(RTCRay), + "::", + stringify!(align2) + ) + ); + } + test_field_align2(); + fn test_field_u() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize + }, + 64usize, + concat!( + "Offset of field: ", + stringify!(RTCRay), + "::", + stringify!(u) + ) + ); + } + test_field_u(); + fn test_field_v() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).v) as usize - ptr as usize + }, + 68usize, + concat!( + "Offset of field: ", + stringify!(RTCRay), + "::", + stringify!(v) + ) + ); + } + test_field_v(); + fn test_field_geomID() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).geomID) as usize - ptr as usize + }, + 72usize, + concat!( + "Offset of field: ", + stringify!(RTCRay), + "::", + stringify!(geomID) + ) + ); + } + test_field_geomID(); + fn test_field_primID() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).primID) as usize - ptr as usize + }, + 76usize, + concat!( + "Offset of field: ", + stringify!(RTCRay), + "::", + stringify!(primID) + ) + ); + } + test_field_primID(); + fn test_field_instID() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).instID) as usize - ptr as usize + }, + 80usize, + concat!( + "Offset of field: ", + stringify!(RTCRay), + "::", + stringify!(instID) + ) + ); + } + test_field_instID(); } diff --git a/tests/expectations/tests/issue-1382-rust-primitive-types.rs b/tests/expectations/tests/issue-1382-rust-primitive-types.rs index 3e3e82c9d9..4ef922c3eb 100644 --- a/tests/expectations/tests/issue-1382-rust-primitive-types.rs +++ b/tests/expectations/tests/issue-1382-rust-primitive-types.rs @@ -43,150 +43,242 @@ fn bindgen_test_layout_Foo() { 4usize, concat!("Alignment of ", stringify!(Foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i8_) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i8_)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).u8_) as usize - ptr as usize - }, - 4usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u8_)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i16_) as usize - ptr as usize - }, - 8usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i16_)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).u16_) as usize - ptr as usize - }, - 12usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u16_)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i32_) as usize - ptr as usize - }, - 16usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i32_)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).u32_) as usize - ptr as usize - }, - 20usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u32_)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i64_) as usize - ptr as usize - }, - 24usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i64_)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).u64_) as usize - ptr as usize - }, - 28usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u64_)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i128_) as usize - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(i128_) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).u128_) as usize - ptr as usize - }, - 36usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(u128_) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).isize_) as usize - ptr as usize - }, - 40usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(isize_) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).usize_) as usize - ptr as usize - }, - 44usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(usize_) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).f32_) as usize - ptr as usize - }, - 48usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(f32_)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).f64_) as usize - ptr as usize - }, - 52usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(f64_)) - ); + fn test_field_i8() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i8_) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Foo), + "::", + stringify!(i8_) + ) + ); + } + test_field_i8(); + fn test_field_u8() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).u8_) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(Foo), + "::", + stringify!(u8_) + ) + ); + } + test_field_u8(); + fn test_field_i16() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i16_) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(Foo), + "::", + stringify!(i16_) + ) + ); + } + test_field_i16(); + fn test_field_u16() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).u16_) as usize - ptr as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(Foo), + "::", + stringify!(u16_) + ) + ); + } + test_field_u16(); + fn test_field_i32() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i32_) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(Foo), + "::", + stringify!(i32_) + ) + ); + } + test_field_i32(); + fn test_field_u32() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).u32_) as usize - ptr as usize + }, + 20usize, + concat!( + "Offset of field: ", + stringify!(Foo), + "::", + stringify!(u32_) + ) + ); + } + test_field_u32(); + fn test_field_i64() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i64_) as usize - ptr as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(Foo), + "::", + stringify!(i64_) + ) + ); + } + test_field_i64(); + fn test_field_u64() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).u64_) as usize - ptr as usize + }, + 28usize, + concat!( + "Offset of field: ", + stringify!(Foo), + "::", + stringify!(u64_) + ) + ); + } + test_field_u64(); + fn test_field_i128() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i128_) as usize - ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(Foo), + "::", + stringify!(i128_) + ) + ); + } + test_field_i128(); + fn test_field_u128() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).u128_) as usize - ptr as usize + }, + 36usize, + concat!( + "Offset of field: ", + stringify!(Foo), + "::", + stringify!(u128_) + ) + ); + } + test_field_u128(); + fn test_field_isize() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).isize_) as usize - ptr as usize + }, + 40usize, + concat!( + "Offset of field: ", + stringify!(Foo), + "::", + stringify!(isize_) + ) + ); + } + test_field_isize(); + fn test_field_usize() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).usize_) as usize - ptr as usize + }, + 44usize, + concat!( + "Offset of field: ", + stringify!(Foo), + "::", + stringify!(usize_) + ) + ); + } + test_field_usize(); + fn test_field_f32() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).f32_) as usize - ptr as usize + }, + 48usize, + concat!( + "Offset of field: ", + stringify!(Foo), + "::", + stringify!(f32_) + ) + ); + } + test_field_f32(); + fn test_field_f64() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).f64_) as usize - ptr as usize + }, + 52usize, + concat!( + "Offset of field: ", + stringify!(Foo), + "::", + stringify!(f64_) + ) + ); + } + test_field_f64(); } diff --git a/tests/expectations/tests/issue-1443.rs b/tests/expectations/tests/issue-1443.rs index b15f5b4571..92a1c7d414 100644 --- a/tests/expectations/tests/issue-1443.rs +++ b/tests/expectations/tests/issue-1443.rs @@ -28,24 +28,30 @@ fn bindgen_test_layout_Bar() { 8usize, concat!("Alignment of ", stringify!(Bar)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(f)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize - }, - 8usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(m)) - ); + fn test_field_f() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(f)) + ); + } + test_field_f(); + fn test_field_m() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize + }, + 8usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(m)) + ); + } + test_field_m(); } impl Default for Bar { fn default() -> Self { @@ -74,24 +80,30 @@ fn bindgen_test_layout_Baz() { 8usize, concat!("Alignment of ", stringify!(Baz)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Baz), "::", stringify!(f)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize - }, - 8usize, - concat!("Offset of field: ", stringify!(Baz), "::", stringify!(m)) - ); + fn test_field_f() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Baz), "::", stringify!(f)) + ); + } + test_field_f(); + fn test_field_m() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize + }, + 8usize, + concat!("Offset of field: ", stringify!(Baz), "::", stringify!(m)) + ); + } + test_field_m(); } impl Default for Baz { fn default() -> Self { @@ -120,24 +132,30 @@ fn bindgen_test_layout_Tar() { 8usize, concat!("Alignment of ", stringify!(Tar)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Tar), "::", stringify!(f)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize - }, - 8usize, - concat!("Offset of field: ", stringify!(Tar), "::", stringify!(m)) - ); + fn test_field_f() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Tar), "::", stringify!(f)) + ); + } + test_field_f(); + fn test_field_m() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize + }, + 8usize, + concat!("Offset of field: ", stringify!(Tar), "::", stringify!(m)) + ); + } + test_field_m(); } impl Default for Tar { fn default() -> Self { @@ -166,24 +184,30 @@ fn bindgen_test_layout_Taz() { 8usize, concat!("Alignment of ", stringify!(Taz)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Taz), "::", stringify!(f)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize - }, - 8usize, - concat!("Offset of field: ", stringify!(Taz), "::", stringify!(m)) - ); + fn test_field_f() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Taz), "::", stringify!(f)) + ); + } + test_field_f(); + fn test_field_m() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize + }, + 8usize, + concat!("Offset of field: ", stringify!(Taz), "::", stringify!(m)) + ); + } + test_field_m(); } impl Default for Taz { fn default() -> Self { diff --git a/tests/expectations/tests/issue-1454.rs b/tests/expectations/tests/issue-1454.rs index 299e01ba2b..e0ad1d71a6 100644 --- a/tests/expectations/tests/issue-1454.rs +++ b/tests/expectations/tests/issue-1454.rs @@ -26,18 +26,21 @@ fn bindgen_test_layout_local_type() { 1usize, concat!("Alignment of ", stringify!(local_type)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).inner) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(local_type), - "::", - stringify!(inner) - ) - ); + fn test_field_inner() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).inner) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(local_type), + "::", + stringify!(inner) + ) + ); + } + test_field_inner(); } diff --git a/tests/expectations/tests/issue-1498.rs b/tests/expectations/tests/issue-1498.rs index f526a22303..b3064e648d 100644 --- a/tests/expectations/tests/issue-1498.rs +++ b/tests/expectations/tests/issue-1498.rs @@ -43,36 +43,44 @@ fn bindgen_test_layout_rte_memseg__bindgen_ty_1() { 8usize, concat!("Alignment of ", stringify!(rte_memseg__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).addr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_memseg__bindgen_ty_1), - "::", - stringify!(addr) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).addr_64) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_memseg__bindgen_ty_1), - "::", - stringify!(addr_64) - ) - ); + fn test_field_addr() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).addr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_memseg__bindgen_ty_1), + "::", + stringify!(addr) + ) + ); + } + test_field_addr(); + fn test_field_addr_64() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).addr_64) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_memseg__bindgen_ty_1), + "::", + stringify!(addr_64) + ) + ); + } + test_field_addr_64(); } impl Default for rte_memseg__bindgen_ty_1 { fn default() -> Self { @@ -95,90 +103,108 @@ fn bindgen_test_layout_rte_memseg() { 1usize, concat!("Alignment of ", stringify!(rte_memseg)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).phys_addr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_memseg), - "::", - stringify!(phys_addr) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_memseg), - "::", - stringify!(len) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).hugepage_sz) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(rte_memseg), - "::", - stringify!(hugepage_sz) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).socket_id) as usize - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(rte_memseg), - "::", - stringify!(socket_id) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nchannel) as usize - ptr as usize - }, - 36usize, - concat!( - "Offset of field: ", - stringify!(rte_memseg), - "::", - stringify!(nchannel) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nrank) as usize - ptr as usize - }, - 40usize, - concat!( - "Offset of field: ", - stringify!(rte_memseg), - "::", - stringify!(nrank) - ) - ); + fn test_field_phys_addr() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).phys_addr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_memseg), + "::", + stringify!(phys_addr) + ) + ); + } + test_field_phys_addr(); + fn test_field_len() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_memseg), + "::", + stringify!(len) + ) + ); + } + test_field_len(); + fn test_field_hugepage_sz() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).hugepage_sz) as usize - ptr as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(rte_memseg), + "::", + stringify!(hugepage_sz) + ) + ); + } + test_field_hugepage_sz(); + fn test_field_socket_id() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).socket_id) as usize - ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(rte_memseg), + "::", + stringify!(socket_id) + ) + ); + } + test_field_socket_id(); + fn test_field_nchannel() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nchannel) as usize - ptr as usize + }, + 36usize, + concat!( + "Offset of field: ", + stringify!(rte_memseg), + "::", + stringify!(nchannel) + ) + ); + } + test_field_nchannel(); + fn test_field_nrank() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nrank) as usize - ptr as usize + }, + 40usize, + concat!( + "Offset of field: ", + stringify!(rte_memseg), + "::", + stringify!(nrank) + ) + ); + } + test_field_nrank(); } impl Default for rte_memseg { fn default() -> Self { diff --git a/tests/expectations/tests/issue-1947.rs b/tests/expectations/tests/issue-1947.rs index 7303b53ed3..e32b7f5f93 100644 --- a/tests/expectations/tests/issue-1947.rs +++ b/tests/expectations/tests/issue-1947.rs @@ -117,48 +117,57 @@ fn bindgen_test_layout_V56AMDY() { 2usize, concat!("Alignment of ", stringify!(V56AMDY)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).MADK) as usize - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(V56AMDY), - "::", - stringify!(MADK) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).MABR) as usize - ptr as usize - }, - 3usize, - concat!( - "Offset of field: ", - stringify!(V56AMDY), - "::", - stringify!(MABR) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr)._rB_) as usize - ptr as usize - }, - 7usize, - concat!( - "Offset of field: ", - stringify!(V56AMDY), - "::", - stringify!(_rB_) - ) - ); + fn test_field_MADK() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).MADK) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(V56AMDY), + "::", + stringify!(MADK) + ) + ); + } + test_field_MADK(); + fn test_field_MABR() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).MABR) as usize - ptr as usize + }, + 3usize, + concat!( + "Offset of field: ", + stringify!(V56AMDY), + "::", + stringify!(MABR) + ) + ); + } + test_field_MABR(); + fn test_field__rB_() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr)._rB_) as usize - ptr as usize + }, + 7usize, + concat!( + "Offset of field: ", + stringify!(V56AMDY), + "::", + stringify!(_rB_) + ) + ); + } + test_field__rB_(); } impl V56AMDY { #[inline] diff --git a/tests/expectations/tests/issue-1977-larger-arrays.rs b/tests/expectations/tests/issue-1977-larger-arrays.rs index d0b478e9d6..be4723febb 100644 --- a/tests/expectations/tests/issue-1977-larger-arrays.rs +++ b/tests/expectations/tests/issue-1977-larger-arrays.rs @@ -22,20 +22,23 @@ fn bindgen_test_layout_S() { 1usize, concat!("Alignment of ", stringify!(S)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(S), - "::", - stringify!(large_array) - ) - ); + fn test_field_large_array() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(S), + "::", + stringify!(large_array) + ) + ); + } + test_field_large_array(); } impl Default for S { fn default() -> Self { diff --git a/tests/expectations/tests/issue-1995.rs b/tests/expectations/tests/issue-1995.rs index f5abbefcbb..a0f10c013a 100644 --- a/tests/expectations/tests/issue-1995.rs +++ b/tests/expectations/tests/issue-1995.rs @@ -29,13 +29,21 @@ fn bindgen_test_layout_Bar() { 4usize, concat!("Alignment of ", stringify!(Bar)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz)) - ); + fn test_field_baz() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Bar), + "::", + stringify!(baz) + ) + ); + } + test_field_baz(); } diff --git a/tests/expectations/tests/issue-2019.rs b/tests/expectations/tests/issue-2019.rs index 7d67f1c39a..6140dfdde4 100644 --- a/tests/expectations/tests/issue-2019.rs +++ b/tests/expectations/tests/issue-2019.rs @@ -22,15 +22,18 @@ fn bindgen_test_layout_A() { 4usize, concat!("Alignment of ", stringify!(A)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(a)) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(A), "::", stringify!(a)) + ); + } + test_field_a(); } extern "C" { #[link_name = "\u{1}_ZN1A4makeEv"] @@ -59,15 +62,18 @@ fn bindgen_test_layout_B() { 4usize, concat!("Alignment of ", stringify!(B)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(B), "::", stringify!(b)) - ); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(B), "::", stringify!(b)) + ); + } + test_field_b(); } extern "C" { #[link_name = "\u{1}_ZN1B4makeEv"] diff --git a/tests/expectations/tests/issue-372.rs b/tests/expectations/tests/issue-372.rs index ad9b41e604..f46d2c9fb6 100644 --- a/tests/expectations/tests/issue-372.rs +++ b/tests/expectations/tests/issue-372.rs @@ -28,33 +28,57 @@ pub mod root { 8usize, concat!("Alignment of ", stringify!(i)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).j) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(i), "::", stringify!(j)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).k) as usize - ptr as usize - }, - 8usize, - concat!("Offset of field: ", stringify!(i), "::", stringify!(k)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).l) as usize - ptr as usize - }, - 16usize, - concat!("Offset of field: ", stringify!(i), "::", stringify!(l)) - ); + fn test_field_j() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).j) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(i), + "::", + stringify!(j) + ) + ); + } + test_field_j(); + fn test_field_k() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).k) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(i), + "::", + stringify!(k) + ) + ); + } + test_field_k(); + fn test_field_l() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).l) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(i), + "::", + stringify!(l) + ) + ); + } + test_field_l(); } impl Default for i { fn default() -> Self { @@ -82,15 +106,23 @@ pub mod root { 8usize, concat!("Alignment of ", stringify!(d)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(d), "::", stringify!(m)) - ); + fn test_field_m() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(d), + "::", + stringify!(m) + ) + ); + } + test_field_m(); } impl Default for d { fn default() -> Self { @@ -133,15 +165,23 @@ pub mod root { 8usize, concat!("Alignment of ", stringify!(F)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).w) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(F), "::", stringify!(w)) - ); + fn test_field_w() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).w) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(F), + "::", + stringify!(w) + ) + ); + } + test_field_w(); } impl Default for F { fn default() -> Self { diff --git a/tests/expectations/tests/issue-537-repr-packed-n.rs b/tests/expectations/tests/issue-537-repr-packed-n.rs index a17664c79a..55ff25a46c 100644 --- a/tests/expectations/tests/issue-537-repr-packed-n.rs +++ b/tests/expectations/tests/issue-537-repr-packed-n.rs @@ -25,20 +25,23 @@ fn bindgen_test_layout_AlignedToOne() { 1usize, concat!("Alignment of ", stringify!(AlignedToOne)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AlignedToOne), - "::", - stringify!(i) - ) - ); + fn test_field_i() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(AlignedToOne), + "::", + stringify!(i) + ) + ); + } + test_field_i(); } /// This should be be packed because Rust 1.33 has `#[repr(packed(N))]`. #[repr(C, packed(2))] @@ -58,20 +61,23 @@ fn bindgen_test_layout_AlignedToTwo() { 2usize, concat!("Alignment of ", stringify!(AlignedToTwo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AlignedToTwo), - "::", - stringify!(i) - ) - ); + fn test_field_i() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(AlignedToTwo), + "::", + stringify!(i) + ) + ); + } + test_field_i(); } /// 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 @@ -94,34 +100,40 @@ fn bindgen_test_layout_PackedToOne() { 1usize, concat!("Alignment of ", stringify!(PackedToOne)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(PackedToOne), - "::", - stringify!(x) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(PackedToOne), - "::", - stringify!(y) - ) - ); + fn test_field_x() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(PackedToOne), + "::", + stringify!(x) + ) + ); + } + test_field_x(); + fn test_field_y() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(PackedToOne), + "::", + stringify!(y) + ) + ); + } + test_field_y(); } /// This should be be packed because Rust 1.33 has `#[repr(packed(N))]`. #[repr(C, packed(2))] @@ -142,32 +154,38 @@ fn bindgen_test_layout_PackedToTwo() { 2usize, concat!("Alignment of ", stringify!(PackedToTwo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(PackedToTwo), - "::", - stringify!(x) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(PackedToTwo), - "::", - stringify!(y) - ) - ); + fn test_field_x() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(PackedToTwo), + "::", + stringify!(x) + ) + ); + } + test_field_x(); + fn test_field_y() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(PackedToTwo), + "::", + stringify!(y) + ) + ); + } + test_field_y(); } diff --git a/tests/expectations/tests/issue-537.rs b/tests/expectations/tests/issue-537.rs index 8675d2277f..d3a0e8c576 100644 --- a/tests/expectations/tests/issue-537.rs +++ b/tests/expectations/tests/issue-537.rs @@ -24,20 +24,23 @@ fn bindgen_test_layout_AlignedToOne() { 1usize, concat!("Alignment of ", stringify!(AlignedToOne)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AlignedToOne), - "::", - stringify!(i) - ) - ); + fn test_field_i() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(AlignedToOne), + "::", + stringify!(i) + ) + ); + } + test_field_i(); } /// This should be opaque because although we can see the attributes, Rust before /// 1.33 doesn't have `#[repr(packed(N))]`. @@ -58,20 +61,23 @@ fn bindgen_test_layout_AlignedToTwo() { 2usize, concat!("Alignment of ", stringify!(AlignedToTwo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AlignedToTwo), - "::", - stringify!(i) - ) - ); + fn test_field_i() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(AlignedToTwo), + "::", + stringify!(i) + ) + ); + } + test_field_i(); } /// 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 @@ -94,34 +100,40 @@ fn bindgen_test_layout_PackedToOne() { 1usize, concat!("Alignment of ", stringify!(PackedToOne)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(PackedToOne), - "::", - stringify!(x) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(PackedToOne), - "::", - stringify!(y) - ) - ); + fn test_field_x() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(PackedToOne), + "::", + stringify!(x) + ) + ); + } + test_field_x(); + fn test_field_y() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(PackedToOne), + "::", + stringify!(y) + ) + ); + } + test_field_y(); } /// In this case, even if we can detect the weird alignment triggered by /// `#pragma pack(2)`, we can't do anything about it because Rust before 1.33 @@ -144,32 +156,38 @@ fn bindgen_test_layout_PackedToTwo() { 2usize, concat!("Alignment of ", stringify!(PackedToTwo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(PackedToTwo), - "::", - stringify!(x) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(PackedToTwo), - "::", - stringify!(y) - ) - ); + fn test_field_x() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(PackedToTwo), + "::", + stringify!(x) + ) + ); + } + test_field_x(); + fn test_field_y() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(PackedToTwo), + "::", + stringify!(y) + ) + ); + } + test_field_y(); } diff --git a/tests/expectations/tests/issue-573-layout-test-failures.rs b/tests/expectations/tests/issue-573-layout-test-failures.rs index bcffcc504e..1c94f94fbe 100644 --- a/tests/expectations/tests/issue-573-layout-test-failures.rs +++ b/tests/expectations/tests/issue-573-layout-test-failures.rs @@ -27,20 +27,23 @@ fn bindgen_test_layout_AutoIdVector() { 1usize, concat!("Alignment of ", stringify!(AutoIdVector)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AutoIdVector), - "::", - stringify!(ar) - ) - ); + fn test_field_ar() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(AutoIdVector), + "::", + stringify!(ar) + ) + ); + } + test_field_ar(); } #[test] fn __bindgen_test_layout_Outer_open0_int_close0_instantiation() { diff --git a/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs b/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs index 45fe605699..66407d818b 100644 --- a/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs +++ b/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs @@ -27,20 +27,23 @@ fn bindgen_test_layout__bindgen_ty_1() { 1usize, concat!("Alignment of ", stringify!(_bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::<_bindgen_ty_1>::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_bindgen_ty_1), - "::", - stringify!(ar) - ) - ); + fn test_field_ar() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::<_bindgen_ty_1>::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_bindgen_ty_1), + "::", + stringify!(ar) + ) + ); + } + test_field_ar(); } extern "C" { pub static mut AutoIdVector: _bindgen_ty_1; diff --git a/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs b/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs index 5539ec8b6e..2a1d045bcb 100644 --- a/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs +++ b/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs @@ -61,15 +61,18 @@ fn bindgen_test_layout_g() { 1usize, concat!("Alignment of ", stringify!(g)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).h) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(g), "::", stringify!(h)) - ); + fn test_field_h() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).h) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(g), "::", stringify!(h)) + ); + } + test_field_h(); } impl Default for g { fn default() -> Self { diff --git a/tests/expectations/tests/issue-639-typedef-anon-field.rs b/tests/expectations/tests/issue-639-typedef-anon-field.rs index 2c634c8ed5..8f4b2a5ae3 100644 --- a/tests/expectations/tests/issue-639-typedef-anon-field.rs +++ b/tests/expectations/tests/issue-639-typedef-anon-field.rs @@ -27,20 +27,23 @@ fn bindgen_test_layout_Foo_Bar() { 4usize, concat!("Alignment of ", stringify!(Foo_Bar)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).abc) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Foo_Bar), - "::", - stringify!(abc) - ) - ); + fn test_field_abc() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).abc) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Foo_Bar), + "::", + stringify!(abc) + ) + ); + } + test_field_abc(); } #[test] fn bindgen_test_layout_Foo() { @@ -54,15 +57,23 @@ fn bindgen_test_layout_Foo() { 4usize, concat!("Alignment of ", stringify!(Foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) - ); + fn test_field_bar() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Foo), + "::", + stringify!(bar) + ) + ); + } + test_field_bar(); } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -86,20 +97,23 @@ fn bindgen_test_layout_Baz_Bar() { 4usize, concat!("Alignment of ", stringify!(Baz_Bar)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).abc) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Baz_Bar), - "::", - stringify!(abc) - ) - ); + fn test_field_abc() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).abc) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Baz_Bar), + "::", + stringify!(abc) + ) + ); + } + test_field_abc(); } #[test] fn bindgen_test_layout_Baz() { diff --git a/tests/expectations/tests/issue-643-inner-struct.rs b/tests/expectations/tests/issue-643-inner-struct.rs index 350ecc7be9..0fb586c40f 100644 --- a/tests/expectations/tests/issue-643-inner-struct.rs +++ b/tests/expectations/tests/issue-643-inner-struct.rs @@ -60,20 +60,23 @@ fn bindgen_test_layout_rte_ring_prod() { 4usize, concat!("Alignment of ", stringify!(rte_ring_prod)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).watermark) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ring_prod), - "::", - stringify!(watermark) - ) - ); + fn test_field_watermark() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).watermark) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ring_prod), + "::", + stringify!(watermark) + ) + ); + } + test_field_watermark(); } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -92,20 +95,23 @@ fn bindgen_test_layout_rte_ring_cons() { 4usize, concat!("Alignment of ", stringify!(rte_ring_cons)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).sc_dequeue) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ring_cons), - "::", - stringify!(sc_dequeue) - ) - ); + fn test_field_sc_dequeue() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).sc_dequeue) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ring_cons), + "::", + stringify!(sc_dequeue) + ) + ); + } + test_field_sc_dequeue(); } #[test] fn bindgen_test_layout_rte_ring() { diff --git a/tests/expectations/tests/issue-648-derive-debug-with-padding.rs b/tests/expectations/tests/issue-648-derive-debug-with-padding.rs index e686a0afdf..f91bd4693b 100644 --- a/tests/expectations/tests/issue-648-derive-debug-with-padding.rs +++ b/tests/expectations/tests/issue-648-derive-debug-with-padding.rs @@ -25,20 +25,23 @@ fn bindgen_test_layout_NoDebug() { 64usize, concat!("Alignment of ", stringify!(NoDebug)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NoDebug), - "::", - stringify!(c) - ) - ); + fn test_field_c() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(NoDebug), + "::", + stringify!(c) + ) + ); + } + test_field_c(); } impl Default for NoDebug { fn default() -> Self { @@ -77,38 +80,44 @@ fn bindgen_test_layout_ShouldDeriveDebugButDoesNot() { 64usize, concat!("Alignment of ", stringify!(ShouldDeriveDebugButDoesNot)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldDeriveDebugButDoesNot), - "::", - stringify!(c) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(ShouldDeriveDebugButDoesNot), - "::", - stringify!(d) - ) - ); + fn test_field_c() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + ShouldDeriveDebugButDoesNot, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ShouldDeriveDebugButDoesNot), + "::", + stringify!(c) + ) + ); + } + test_field_c(); + fn test_field_d() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + ShouldDeriveDebugButDoesNot, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(ShouldDeriveDebugButDoesNot), + "::", + stringify!(d) + ) + ); + } + test_field_d(); } impl Default for ShouldDeriveDebugButDoesNot { fn default() -> Self { diff --git a/tests/expectations/tests/issue-674-1.rs b/tests/expectations/tests/issue-674-1.rs index 8420934aed..e3e7a54fde 100644 --- a/tests/expectations/tests/issue-674-1.rs +++ b/tests/expectations/tests/issue-674-1.rs @@ -36,20 +36,24 @@ pub mod root { 1usize, concat!("Alignment of ", stringify!(CapturingContentInfo)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(CapturingContentInfo), - "::", - stringify!(a) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(CapturingContentInfo), + "::", + stringify!(a) + ) + ); + } + test_field_a(); } } diff --git a/tests/expectations/tests/issue-674-2.rs b/tests/expectations/tests/issue-674-2.rs index 293f94b43f..61a456f605 100644 --- a/tests/expectations/tests/issue-674-2.rs +++ b/tests/expectations/tests/issue-674-2.rs @@ -36,15 +36,23 @@ pub mod root { 1usize, concat!("Alignment of ", stringify!(c)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(c), "::", stringify!(b)) - ); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(c), + "::", + stringify!(b) + ) + ); + } + test_field_b(); } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -63,15 +71,23 @@ pub mod root { 1usize, concat!("Alignment of ", stringify!(B)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(B), "::", stringify!(a)) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(B), + "::", + stringify!(a) + ) + ); + } + test_field_a(); } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] diff --git a/tests/expectations/tests/issue-674-3.rs b/tests/expectations/tests/issue-674-3.rs index 91a7b7e2b6..b45a953e99 100644 --- a/tests/expectations/tests/issue-674-3.rs +++ b/tests/expectations/tests/issue-674-3.rs @@ -32,15 +32,23 @@ pub mod root { 1usize, concat!("Alignment of ", stringify!(a)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(a), "::", stringify!(b)) - ); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(a), + "::", + stringify!(b) + ) + ); + } + test_field_b(); } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -59,19 +67,23 @@ pub mod root { 1usize, concat!("Alignment of ", stringify!(nsCSSValue)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsCSSValue), - "::", - stringify!(c) - ) - ); + fn test_field_c() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(nsCSSValue), + "::", + stringify!(c) + ) + ); + } + test_field_c(); } } diff --git a/tests/expectations/tests/issue-801-opaque-sloppiness.rs b/tests/expectations/tests/issue-801-opaque-sloppiness.rs index 04f46bafa3..cd89eec5e8 100644 --- a/tests/expectations/tests/issue-801-opaque-sloppiness.rs +++ b/tests/expectations/tests/issue-801-opaque-sloppiness.rs @@ -50,13 +50,16 @@ fn bindgen_test_layout_C() { 1usize, concat!("Alignment of ", stringify!(C)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(b)) - ); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(b)) + ); + } + test_field_b(); } diff --git a/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs b/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs index 655096c8d8..584bd00a35 100644 --- a/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs +++ b/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs @@ -119,18 +119,21 @@ fn bindgen_test_layout_Allowlisted() { 1usize, concat!("Alignment of ", stringify!(Allowlisted)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).some_member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Allowlisted), - "::", - stringify!(some_member) - ) - ); + fn test_field_some_member() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).some_member) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Allowlisted), + "::", + stringify!(some_member) + ) + ); + } + test_field_some_member(); } diff --git a/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs b/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs index 4296f57cb4..af00cb2df1 100644 --- a/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs +++ b/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs @@ -24,20 +24,24 @@ fn bindgen_test_layout_ShouldNotBeCopy() { 1usize, concat!("Alignment of ", stringify!(ShouldNotBeCopy)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldNotBeCopy), - "::", - stringify!(a) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ShouldNotBeCopy), + "::", + stringify!(a) + ) + ); + } + test_field_a(); } impl Default for ShouldNotBeCopy { fn default() -> Self { diff --git a/tests/expectations/tests/jsval_layout_opaque.rs b/tests/expectations/tests/jsval_layout_opaque.rs index f8dd367378..383410bd8b 100644 --- a/tests/expectations/tests/jsval_layout_opaque.rs +++ b/tests/expectations/tests/jsval_layout_opaque.rs @@ -293,54 +293,63 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2__bindgen_ty_1() { stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1) ) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - jsval_layout__bindgen_ty_2__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i32_) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), - "::", - stringify!(i32_) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - jsval_layout__bindgen_ty_2__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).u32_) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), - "::", - stringify!(u32_) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - jsval_layout__bindgen_ty_2__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).why) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), - "::", - stringify!(why) - ) - ); + fn test_field_i32() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + jsval_layout__bindgen_ty_2__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i32_) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), + "::", + stringify!(i32_) + ) + ); + } + test_field_i32(); + fn test_field_u32() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + jsval_layout__bindgen_ty_2__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).u32_) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), + "::", + stringify!(u32_) + ) + ); + } + test_field_u32(); + fn test_field_why() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + jsval_layout__bindgen_ty_2__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).why) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), + "::", + stringify!(why) + ) + ); + } + test_field_why(); } impl Default for jsval_layout__bindgen_ty_2__bindgen_ty_1 { fn default() -> Self { @@ -363,21 +372,25 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2() { 4usize, concat!("Alignment of ", stringify!(jsval_layout__bindgen_ty_2)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).payload) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2), - "::", - stringify!(payload) - ) - ); + fn test_field_payload() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + jsval_layout__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).payload) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout__bindgen_ty_2), + "::", + stringify!(payload) + ) + ); + } + test_field_payload(); } impl Default for jsval_layout__bindgen_ty_2 { fn default() -> Self { @@ -400,104 +413,125 @@ fn bindgen_test_layout_jsval_layout() { 8usize, concat!("Alignment of ", stringify!(jsval_layout)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).asBits) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asBits) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).debugView) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(debugView) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).s) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(s) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).asDouble) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asDouble) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).asPtr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asPtr) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).asWord) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asWord) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).asUIntPtr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asUIntPtr) - ) - ); + fn test_field_asBits() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).asBits) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout), + "::", + stringify!(asBits) + ) + ); + } + test_field_asBits(); + fn test_field_debugView() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).debugView) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout), + "::", + stringify!(debugView) + ) + ); + } + test_field_debugView(); + fn test_field_s() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).s) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout), + "::", + stringify!(s) + ) + ); + } + test_field_s(); + fn test_field_asDouble() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).asDouble) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout), + "::", + stringify!(asDouble) + ) + ); + } + test_field_asDouble(); + fn test_field_asPtr() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).asPtr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout), + "::", + stringify!(asPtr) + ) + ); + } + test_field_asPtr(); + fn test_field_asWord() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).asWord) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout), + "::", + stringify!(asWord) + ) + ); + } + test_field_asWord(); + fn test_field_asUIntPtr() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).asUIntPtr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout), + "::", + stringify!(asUIntPtr) + ) + ); + } + test_field_asUIntPtr(); } impl Default for jsval_layout { fn default() -> Self { @@ -525,20 +559,23 @@ fn bindgen_test_layout_Value() { 8usize, concat!("Alignment of ", stringify!(Value)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Value), - "::", - stringify!(data) - ) - ); + fn test_field_data() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Value), + "::", + stringify!(data) + ) + ); + } + test_field_data(); } impl Default for Value { fn default() -> Self { diff --git a/tests/expectations/tests/jsval_layout_opaque_1_0.rs b/tests/expectations/tests/jsval_layout_opaque_1_0.rs index 309d54ac6e..bdb411043a 100644 --- a/tests/expectations/tests/jsval_layout_opaque_1_0.rs +++ b/tests/expectations/tests/jsval_layout_opaque_1_0.rs @@ -343,54 +343,63 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2__bindgen_ty_1() { stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1) ) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - jsval_layout__bindgen_ty_2__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i32_) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), - "::", - stringify!(i32_) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - jsval_layout__bindgen_ty_2__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).u32_) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), - "::", - stringify!(u32_) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - jsval_layout__bindgen_ty_2__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).why) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), - "::", - stringify!(why) - ) - ); + fn test_field_i32() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + jsval_layout__bindgen_ty_2__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i32_) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), + "::", + stringify!(i32_) + ) + ); + } + test_field_i32(); + fn test_field_u32() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + jsval_layout__bindgen_ty_2__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).u32_) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), + "::", + stringify!(u32_) + ) + ); + } + test_field_u32(); + fn test_field_why() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + jsval_layout__bindgen_ty_2__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).why) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), + "::", + stringify!(why) + ) + ); + } + test_field_why(); } impl Clone for jsval_layout__bindgen_ty_2__bindgen_ty_1 { fn clone(&self) -> Self { @@ -409,21 +418,25 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2() { 4usize, concat!("Alignment of ", stringify!(jsval_layout__bindgen_ty_2)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).payload) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2), - "::", - stringify!(payload) - ) - ); + fn test_field_payload() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + jsval_layout__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).payload) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout__bindgen_ty_2), + "::", + stringify!(payload) + ) + ); + } + test_field_payload(); } impl Clone for jsval_layout__bindgen_ty_2 { fn clone(&self) -> Self { @@ -442,104 +455,125 @@ fn bindgen_test_layout_jsval_layout() { 8usize, concat!("Alignment of ", stringify!(jsval_layout)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).asBits) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asBits) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).debugView) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(debugView) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).s) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(s) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).asDouble) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asDouble) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).asPtr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asPtr) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).asWord) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asWord) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).asUIntPtr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asUIntPtr) - ) - ); + fn test_field_asBits() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).asBits) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout), + "::", + stringify!(asBits) + ) + ); + } + test_field_asBits(); + fn test_field_debugView() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).debugView) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout), + "::", + stringify!(debugView) + ) + ); + } + test_field_debugView(); + fn test_field_s() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).s) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout), + "::", + stringify!(s) + ) + ); + } + test_field_s(); + fn test_field_asDouble() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).asDouble) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout), + "::", + stringify!(asDouble) + ) + ); + } + test_field_asDouble(); + fn test_field_asPtr() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).asPtr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout), + "::", + stringify!(asPtr) + ) + ); + } + test_field_asPtr(); + fn test_field_asWord() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).asWord) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout), + "::", + stringify!(asWord) + ) + ); + } + test_field_asWord(); + fn test_field_asUIntPtr() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).asUIntPtr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout), + "::", + stringify!(asUIntPtr) + ) + ); + } + test_field_asUIntPtr(); } impl Clone for jsval_layout { fn clone(&self) -> Self { @@ -563,20 +597,23 @@ fn bindgen_test_layout_Value() { 8usize, concat!("Alignment of ", stringify!(Value)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Value), - "::", - stringify!(data) - ) - ); + fn test_field_data() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Value), + "::", + stringify!(data) + ) + ); + } + test_field_data(); } impl Clone for Value { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/layout_align.rs b/tests/expectations/tests/layout_align.rs index 7d2c5a6ee9..44df4c1cb7 100644 --- a/tests/expectations/tests/layout_align.rs +++ b/tests/expectations/tests/layout_align.rs @@ -179,20 +179,23 @@ fn bindgen_test_layout_rte_eth_link() { 8usize, concat!("Alignment of ", stringify!(rte_eth_link)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).link_speed) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_link), - "::", - stringify!(link_speed) - ) - ); + fn test_field_link_speed() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).link_speed) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_link), + "::", + stringify!(link_speed) + ) + ); + } + test_field_link_speed(); } impl rte_eth_link { #[inline] diff --git a/tests/expectations/tests/layout_arp.rs b/tests/expectations/tests/layout_arp.rs index 390c87aa81..fc3aa5d533 100644 --- a/tests/expectations/tests/layout_arp.rs +++ b/tests/expectations/tests/layout_arp.rs @@ -40,20 +40,23 @@ fn bindgen_test_layout_ether_addr() { 1usize, concat!("Alignment of ", stringify!(ether_addr)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).addr_bytes) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ether_addr), - "::", - stringify!(addr_bytes) - ) - ); + fn test_field_addr_bytes() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).addr_bytes) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ether_addr), + "::", + stringify!(addr_bytes) + ) + ); + } + test_field_addr_bytes(); } /// ARP header IPv4 payload. #[repr(C, packed)] @@ -80,62 +83,74 @@ fn bindgen_test_layout_arp_ipv4() { 1usize, concat!("Alignment of ", stringify!(arp_ipv4)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).arp_sha) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(arp_ipv4), - "::", - stringify!(arp_sha) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).arp_sip) as usize - ptr as usize - }, - 6usize, - concat!( - "Offset of field: ", - stringify!(arp_ipv4), - "::", - stringify!(arp_sip) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).arp_tha) as usize - ptr as usize - }, - 10usize, - concat!( - "Offset of field: ", - stringify!(arp_ipv4), - "::", - stringify!(arp_tha) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).arp_tip) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(arp_ipv4), - "::", - stringify!(arp_tip) - ) - ); + fn test_field_arp_sha() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).arp_sha) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(arp_ipv4), + "::", + stringify!(arp_sha) + ) + ); + } + test_field_arp_sha(); + fn test_field_arp_sip() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).arp_sip) as usize - ptr as usize + }, + 6usize, + concat!( + "Offset of field: ", + stringify!(arp_ipv4), + "::", + stringify!(arp_sip) + ) + ); + } + test_field_arp_sip(); + fn test_field_arp_tha() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).arp_tha) as usize - ptr as usize + }, + 10usize, + concat!( + "Offset of field: ", + stringify!(arp_ipv4), + "::", + stringify!(arp_tha) + ) + ); + } + test_field_arp_tha(); + fn test_field_arp_tip() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).arp_tip) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(arp_ipv4), + "::", + stringify!(arp_tip) + ) + ); + } + test_field_arp_tip(); } /// ARP header. #[repr(C, packed)] @@ -160,88 +175,106 @@ fn bindgen_test_layout_arp_hdr() { 1usize, concat!("Alignment of ", stringify!(arp_hdr)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).arp_hrd) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(arp_hdr), - "::", - stringify!(arp_hrd) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).arp_pro) as usize - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(arp_hdr), - "::", - stringify!(arp_pro) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).arp_hln) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(arp_hdr), - "::", - stringify!(arp_hln) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).arp_pln) as usize - ptr as usize - }, - 5usize, - concat!( - "Offset of field: ", - stringify!(arp_hdr), - "::", - stringify!(arp_pln) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).arp_op) as usize - ptr as usize - }, - 6usize, - concat!( - "Offset of field: ", - stringify!(arp_hdr), - "::", - stringify!(arp_op) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).arp_data) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(arp_hdr), - "::", - stringify!(arp_data) - ) - ); + fn test_field_arp_hrd() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).arp_hrd) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(arp_hdr), + "::", + stringify!(arp_hrd) + ) + ); + } + test_field_arp_hrd(); + fn test_field_arp_pro() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).arp_pro) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(arp_hdr), + "::", + stringify!(arp_pro) + ) + ); + } + test_field_arp_pro(); + fn test_field_arp_hln() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).arp_hln) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(arp_hdr), + "::", + stringify!(arp_hln) + ) + ); + } + test_field_arp_hln(); + fn test_field_arp_pln() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).arp_pln) as usize - ptr as usize + }, + 5usize, + concat!( + "Offset of field: ", + stringify!(arp_hdr), + "::", + stringify!(arp_pln) + ) + ); + } + test_field_arp_pln(); + fn test_field_arp_op() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).arp_op) as usize - ptr as usize + }, + 6usize, + concat!( + "Offset of field: ", + stringify!(arp_hdr), + "::", + stringify!(arp_op) + ) + ); + } + test_field_arp_op(); + fn test_field_arp_data() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).arp_data) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(arp_hdr), + "::", + stringify!(arp_data) + ) + ); + } + test_field_arp_data(); } diff --git a/tests/expectations/tests/layout_array.rs b/tests/expectations/tests/layout_array.rs index 0e25258ae5..c8ee421636 100644 --- a/tests/expectations/tests/layout_array.rs +++ b/tests/expectations/tests/layout_array.rs @@ -79,90 +79,114 @@ fn bindgen_test_layout_rte_mempool_ops() { 64usize, concat!("Alignment of ", stringify!(rte_mempool_ops)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).name) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mempool_ops), - "::", - stringify!(name) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).alloc) as usize - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(rte_mempool_ops), - "::", - stringify!(alloc) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).free) as usize - ptr as usize - }, - 40usize, - concat!( - "Offset of field: ", - stringify!(rte_mempool_ops), - "::", - stringify!(free) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).enqueue) as usize - ptr as usize - }, - 48usize, - concat!( - "Offset of field: ", - stringify!(rte_mempool_ops), - "::", - stringify!(enqueue) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dequeue) as usize - ptr as usize - }, - 56usize, - concat!( - "Offset of field: ", - stringify!(rte_mempool_ops), - "::", - stringify!(dequeue) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).get_count) as usize - ptr as usize - }, - 64usize, - concat!( - "Offset of field: ", - stringify!(rte_mempool_ops), - "::", - stringify!(get_count) - ) - ); + fn test_field_name() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).name) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mempool_ops), + "::", + stringify!(name) + ) + ); + } + test_field_name(); + fn test_field_alloc() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).alloc) as usize - ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(rte_mempool_ops), + "::", + stringify!(alloc) + ) + ); + } + test_field_alloc(); + fn test_field_free() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).free) as usize - ptr as usize + }, + 40usize, + concat!( + "Offset of field: ", + stringify!(rte_mempool_ops), + "::", + stringify!(free) + ) + ); + } + test_field_free(); + fn test_field_enqueue() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).enqueue) as usize - ptr as usize + }, + 48usize, + concat!( + "Offset of field: ", + stringify!(rte_mempool_ops), + "::", + stringify!(enqueue) + ) + ); + } + test_field_enqueue(); + fn test_field_dequeue() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dequeue) as usize - ptr as usize + }, + 56usize, + concat!( + "Offset of field: ", + stringify!(rte_mempool_ops), + "::", + stringify!(dequeue) + ) + ); + } + test_field_dequeue(); + fn test_field_get_count() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).get_count) as usize - ptr as usize + }, + 64usize, + concat!( + "Offset of field: ", + stringify!(rte_mempool_ops), + "::", + stringify!(get_count) + ) + ); + } + test_field_get_count(); } impl Default for rte_mempool_ops { fn default() -> Self { @@ -202,20 +226,24 @@ fn bindgen_test_layout_rte_spinlock_t() { 4usize, concat!("Alignment of ", stringify!(rte_spinlock_t)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).locked) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_spinlock_t), - "::", - stringify!(locked) - ) - ); + fn test_field_locked() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).locked) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_spinlock_t), + "::", + stringify!(locked) + ) + ); + } + test_field_locked(); } /// Structure storing the table of registered ops structs, each of which contain /// the function pointers for the mempool ops functions. @@ -248,51 +276,60 @@ fn bindgen_test_layout_rte_mempool_ops_table() { 64usize, concat!("Alignment of ", stringify!(rte_mempool_ops_table)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).sl) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mempool_ops_table), - "::", - stringify!(sl) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).num_ops) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_mempool_ops_table), - "::", - stringify!(num_ops) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ops) as usize - ptr as usize - }, - 64usize, - concat!( - "Offset of field: ", - stringify!(rte_mempool_ops_table), - "::", - stringify!(ops) - ) - ); + fn test_field_sl() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).sl) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mempool_ops_table), + "::", + stringify!(sl) + ) + ); + } + test_field_sl(); + fn test_field_num_ops() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).num_ops) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_mempool_ops_table), + "::", + stringify!(num_ops) + ) + ); + } + test_field_num_ops(); + fn test_field_ops() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ops) as usize - ptr as usize + }, + 64usize, + concat!( + "Offset of field: ", + stringify!(rte_mempool_ops_table), + "::", + stringify!(ops) + ) + ); + } + test_field_ops(); } impl Default for rte_mempool_ops_table { fn default() -> Self { @@ -330,21 +367,23 @@ fn bindgen_test_layout_malloc_heap__bindgen_ty_1() { 8usize, concat!("Alignment of ", stringify!(malloc_heap__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).lh_first) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(malloc_heap__bindgen_ty_1), - "::", - stringify!(lh_first) - ) - ); + fn test_field_lh_first() { + assert_eq!( + unsafe { + let uninit = :: std :: mem :: MaybeUninit :: < malloc_heap__bindgen_ty_1 > :: uninit () ; + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).lh_first) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(malloc_heap__bindgen_ty_1), + "::", + stringify!(lh_first) + ) + ); + } + test_field_lh_first(); } impl Default for malloc_heap__bindgen_ty_1 { fn default() -> Self { @@ -367,62 +406,74 @@ fn bindgen_test_layout_malloc_heap() { 64usize, concat!("Alignment of ", stringify!(malloc_heap)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).lock) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(malloc_heap), - "::", - stringify!(lock) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).free_head) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(malloc_heap), - "::", - stringify!(free_head) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).alloc_count) as usize - ptr as usize - }, - 112usize, - concat!( - "Offset of field: ", - stringify!(malloc_heap), - "::", - stringify!(alloc_count) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).total_size) as usize - ptr as usize - }, - 120usize, - concat!( - "Offset of field: ", - stringify!(malloc_heap), - "::", - stringify!(total_size) - ) - ); + fn test_field_lock() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).lock) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(malloc_heap), + "::", + stringify!(lock) + ) + ); + } + test_field_lock(); + fn test_field_free_head() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).free_head) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(malloc_heap), + "::", + stringify!(free_head) + ) + ); + } + test_field_free_head(); + fn test_field_alloc_count() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).alloc_count) as usize - ptr as usize + }, + 112usize, + concat!( + "Offset of field: ", + stringify!(malloc_heap), + "::", + stringify!(alloc_count) + ) + ); + } + test_field_alloc_count(); + fn test_field_total_size() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).total_size) as usize - ptr as usize + }, + 120usize, + concat!( + "Offset of field: ", + stringify!(malloc_heap), + "::", + stringify!(total_size) + ) + ); + } + test_field_total_size(); } impl Default for malloc_heap { fn default() -> Self { diff --git a/tests/expectations/tests/layout_array_too_long.rs b/tests/expectations/tests/layout_array_too_long.rs index b38523ffd5..586d35ecb5 100644 --- a/tests/expectations/tests/layout_array_too_long.rs +++ b/tests/expectations/tests/layout_array_too_long.rs @@ -45,48 +45,57 @@ fn bindgen_test_layout_ip_frag() { 8usize, concat!("Alignment of ", stringify!(ip_frag)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ofs) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ip_frag), - "::", - stringify!(ofs) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(ip_frag), - "::", - stringify!(len) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mb) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(ip_frag), - "::", - stringify!(mb) - ) - ); + fn test_field_ofs() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ofs) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ip_frag), + "::", + stringify!(ofs) + ) + ); + } + test_field_ofs(); + fn test_field_len() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(ip_frag), + "::", + stringify!(len) + ) + ); + } + test_field_len(); + fn test_field_mb() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mb) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(ip_frag), + "::", + stringify!(mb) + ) + ); + } + test_field_mb(); } impl Default for ip_frag { fn default() -> Self { @@ -120,48 +129,57 @@ fn bindgen_test_layout_ip_frag_key() { 8usize, concat!("Alignment of ", stringify!(ip_frag_key)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).src_dst) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_key), - "::", - stringify!(src_dst) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).id) as usize - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_key), - "::", - stringify!(id) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).key_len) as usize - ptr as usize - }, - 36usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_key), - "::", - stringify!(key_len) - ) - ); + fn test_field_src_dst() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).src_dst) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_key), + "::", + stringify!(src_dst) + ) + ); + } + test_field_src_dst(); + fn test_field_id() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).id) as usize - ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_key), + "::", + stringify!(id) + ) + ); + } + test_field_id(); + fn test_field_key_len() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).key_len) as usize - ptr as usize + }, + 36usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_key), + "::", + stringify!(key_len) + ) + ); + } + test_field_key_len(); } /// @internal Fragmented packet to reassemble. /// First two entries in the frags[] array are for the last and first fragments. @@ -202,36 +220,40 @@ fn bindgen_test_layout_ip_frag_pkt__bindgen_ty_1() { 8usize, concat!("Alignment of ", stringify!(ip_frag_pkt__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).tqe_next) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt__bindgen_ty_1), - "::", - stringify!(tqe_next) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).tqe_prev) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt__bindgen_ty_1), - "::", - stringify!(tqe_prev) - ) - ); + fn test_field_tqe_next() { + assert_eq!( + unsafe { + let uninit = :: std :: mem :: MaybeUninit :: < ip_frag_pkt__bindgen_ty_1 > :: uninit () ; + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tqe_next) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_pkt__bindgen_ty_1), + "::", + stringify!(tqe_next) + ) + ); + } + test_field_tqe_next(); + fn test_field_tqe_prev() { + assert_eq!( + unsafe { + let uninit = :: std :: mem :: MaybeUninit :: < ip_frag_pkt__bindgen_ty_1 > :: uninit () ; + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tqe_prev) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_pkt__bindgen_ty_1), + "::", + stringify!(tqe_prev) + ) + ); + } + test_field_tqe_prev(); } impl Default for ip_frag_pkt__bindgen_ty_1 { fn default() -> Self { @@ -254,104 +276,125 @@ fn bindgen_test_layout_ip_frag_pkt() { 64usize, concat!("Alignment of ", stringify!(ip_frag_pkt)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).lru) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(lru) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).key) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(key) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).start) as usize - ptr as usize - }, - 56usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(start) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).total_size) as usize - ptr as usize - }, - 64usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(total_size) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).frag_size) as usize - ptr as usize - }, - 68usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(frag_size) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).last_idx) as usize - ptr as usize - }, - 72usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(last_idx) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).frags) as usize - ptr as usize - }, - 80usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(frags) - ) - ); + fn test_field_lru() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).lru) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_pkt), + "::", + stringify!(lru) + ) + ); + } + test_field_lru(); + fn test_field_key() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).key) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_pkt), + "::", + stringify!(key) + ) + ); + } + test_field_key(); + fn test_field_start() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).start) as usize - ptr as usize + }, + 56usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_pkt), + "::", + stringify!(start) + ) + ); + } + test_field_start(); + fn test_field_total_size() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).total_size) as usize - ptr as usize + }, + 64usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_pkt), + "::", + stringify!(total_size) + ) + ); + } + test_field_total_size(); + fn test_field_frag_size() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).frag_size) as usize - ptr as usize + }, + 68usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_pkt), + "::", + stringify!(frag_size) + ) + ); + } + test_field_frag_size(); + fn test_field_last_idx() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).last_idx) as usize - ptr as usize + }, + 72usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_pkt), + "::", + stringify!(last_idx) + ) + ); + } + test_field_last_idx(); + fn test_field_frags() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).frags) as usize - ptr as usize + }, + 80usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_pkt), + "::", + stringify!(frags) + ) + ); + } + test_field_frags(); } impl Default for ip_frag_pkt { fn default() -> Self { diff --git a/tests/expectations/tests/layout_cmdline_token.rs b/tests/expectations/tests/layout_cmdline_token.rs index 37c8928cc8..a4360cd310 100644 --- a/tests/expectations/tests/layout_cmdline_token.rs +++ b/tests/expectations/tests/layout_cmdline_token.rs @@ -25,34 +25,42 @@ fn bindgen_test_layout_cmdline_token_hdr() { 8usize, concat!("Alignment of ", stringify!(cmdline_token_hdr)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ops) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(cmdline_token_hdr), - "::", - stringify!(ops) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).offset) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(cmdline_token_hdr), - "::", - stringify!(offset) - ) - ); + fn test_field_ops() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ops) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(cmdline_token_hdr), + "::", + stringify!(ops) + ) + ); + } + test_field_ops(); + fn test_field_offset() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).offset) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(cmdline_token_hdr), + "::", + stringify!(offset) + ) + ); + } + test_field_offset(); } impl Default for cmdline_token_hdr { fn default() -> Self { @@ -131,63 +139,80 @@ fn bindgen_test_layout_cmdline_token_ops() { 8usize, concat!("Alignment of ", stringify!(cmdline_token_ops)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).parse) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(cmdline_token_ops), - "::", - stringify!(parse) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).complete_get_nb) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(cmdline_token_ops), - "::", - stringify!(complete_get_nb) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).complete_get_elt) as usize - - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(cmdline_token_ops), - "::", - stringify!(complete_get_elt) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).get_help) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(cmdline_token_ops), - "::", - stringify!(get_help) - ) - ); + fn test_field_parse() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).parse) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(cmdline_token_ops), + "::", + stringify!(parse) + ) + ); + } + test_field_parse(); + fn test_field_complete_get_nb() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).complete_get_nb) as usize - + ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(cmdline_token_ops), + "::", + stringify!(complete_get_nb) + ) + ); + } + test_field_complete_get_nb(); + fn test_field_complete_get_elt() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).complete_get_elt) as usize - + ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(cmdline_token_ops), + "::", + stringify!(complete_get_elt) + ) + ); + } + test_field_complete_get_elt(); + fn test_field_get_help() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).get_help) as usize - ptr as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(cmdline_token_ops), + "::", + stringify!(get_help) + ) + ); + } + test_field_get_help(); } #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] @@ -218,21 +243,24 @@ fn bindgen_test_layout_cmdline_token_num_data() { 4usize, concat!("Alignment of ", stringify!(cmdline_token_num_data)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(cmdline_token_num_data), - "::", - stringify!(type_) - ) - ); + fn test_field_type() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(cmdline_token_num_data), + "::", + stringify!(type_) + ) + ); + } + test_field_type(); } impl Default for cmdline_token_num_data { fn default() -> Self { @@ -261,34 +289,42 @@ fn bindgen_test_layout_cmdline_token_num() { 8usize, concat!("Alignment of ", stringify!(cmdline_token_num)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).hdr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(cmdline_token_num), - "::", - stringify!(hdr) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).num_data) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(cmdline_token_num), - "::", - stringify!(num_data) - ) - ); + fn test_field_hdr() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).hdr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(cmdline_token_num), + "::", + stringify!(hdr) + ) + ); + } + test_field_hdr(); + fn test_field_num_data() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).num_data) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(cmdline_token_num), + "::", + stringify!(num_data) + ) + ); + } + test_field_num_data(); } impl Default for cmdline_token_num { fn default() -> Self { diff --git a/tests/expectations/tests/layout_eth_conf.rs b/tests/expectations/tests/layout_eth_conf.rs index 9398357f6e..3296a0f8cc 100644 --- a/tests/expectations/tests/layout_eth_conf.rs +++ b/tests/expectations/tests/layout_eth_conf.rs @@ -170,48 +170,62 @@ fn bindgen_test_layout_rte_eth_rxmode() { 4usize, concat!("Alignment of ", stringify!(rte_eth_rxmode)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mq_mode) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rxmode), - "::", - stringify!(mq_mode) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).max_rx_pkt_len) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rxmode), - "::", - stringify!(max_rx_pkt_len) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).split_hdr_size) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rxmode), - "::", - stringify!(split_hdr_size) - ) - ); + fn test_field_mq_mode() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mq_mode) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_rxmode), + "::", + stringify!(mq_mode) + ) + ); + } + test_field_mq_mode(); + fn test_field_max_rx_pkt_len() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).max_rx_pkt_len) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_rxmode), + "::", + stringify!(max_rx_pkt_len) + ) + ); + } + test_field_max_rx_pkt_len(); + fn test_field_split_hdr_size() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).split_hdr_size) as usize - + ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_rxmode), + "::", + stringify!(split_hdr_size) + ) + ); + } + test_field_split_hdr_size(); } impl Default for rte_eth_rxmode { fn default() -> Self { @@ -438,34 +452,42 @@ fn bindgen_test_layout_rte_eth_txmode() { 4usize, concat!("Alignment of ", stringify!(rte_eth_txmode)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mq_mode) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_txmode), - "::", - stringify!(mq_mode) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pvid) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_txmode), - "::", - stringify!(pvid) - ) - ); + fn test_field_mq_mode() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mq_mode) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_txmode), + "::", + stringify!(mq_mode) + ) + ); + } + test_field_mq_mode(); + fn test_field_pvid() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pvid) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_txmode), + "::", + stringify!(pvid) + ) + ); + } + test_field_pvid(); } impl Default for rte_eth_txmode { fn default() -> Self { @@ -579,48 +601,60 @@ fn bindgen_test_layout_rte_eth_rss_conf() { 8usize, concat!("Alignment of ", stringify!(rte_eth_rss_conf)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rss_key) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rss_conf), - "::", - stringify!(rss_key) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rss_key_len) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rss_conf), - "::", - stringify!(rss_key_len) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rss_hf) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rss_conf), - "::", - stringify!(rss_hf) - ) - ); + fn test_field_rss_key() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rss_key) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_rss_conf), + "::", + stringify!(rss_key) + ) + ); + } + test_field_rss_key(); + fn test_field_rss_key_len() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rss_key_len) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_rss_conf), + "::", + stringify!(rss_key_len) + ) + ); + } + test_field_rss_key_len(); + fn test_field_rss_hf() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rss_hf) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_rss_conf), + "::", + stringify!(rss_hf) + ) + ); + } + test_field_rss_hf(); } impl Default for rte_eth_rss_conf { fn default() -> Self { @@ -702,38 +736,44 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf__bindgen_ty_1() { stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1) ) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_eth_vmdq_dcb_conf__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).vlan_id) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1), - "::", - stringify!(vlan_id) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_eth_vmdq_dcb_conf__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pools) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1), - "::", - stringify!(pools) - ) - ); + fn test_field_vlan_id() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + rte_eth_vmdq_dcb_conf__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).vlan_id) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1), + "::", + stringify!(vlan_id) + ) + ); + } + test_field_vlan_id(); + fn test_field_pools() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + rte_eth_vmdq_dcb_conf__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pools) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1), + "::", + stringify!(pools) + ) + ); + } + test_field_pools(); } #[test] fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { @@ -747,97 +787,118 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { 8usize, concat!("Alignment of ", stringify!(rte_eth_vmdq_dcb_conf)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(nb_queue_pools) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).enable_default_pool) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(enable_default_pool) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).default_pool) as usize - ptr as usize - }, - 5usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(default_pool) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_pool_maps) as usize - ptr as usize - }, - 6usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(nb_pool_maps) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pool_map) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(pool_map) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize - }, - 1032usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(dcb_tc) - ) - ); + fn test_field_nb_queue_pools() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf), + "::", + stringify!(nb_queue_pools) + ) + ); + } + test_field_nb_queue_pools(); + fn test_field_enable_default_pool() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).enable_default_pool) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf), + "::", + stringify!(enable_default_pool) + ) + ); + } + test_field_enable_default_pool(); + fn test_field_default_pool() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).default_pool) as usize - + ptr as usize + }, + 5usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf), + "::", + stringify!(default_pool) + ) + ); + } + test_field_default_pool(); + fn test_field_nb_pool_maps() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_pool_maps) as usize - + ptr as usize + }, + 6usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf), + "::", + stringify!(nb_pool_maps) + ) + ); + } + test_field_nb_pool_maps(); + fn test_field_pool_map() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pool_map) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf), + "::", + stringify!(pool_map) + ) + ); + } + test_field_pool_map(); + fn test_field_dcb_tc() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize + }, + 1032usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf), + "::", + stringify!(dcb_tc) + ) + ); + } + test_field_dcb_tc(); } impl Default for rte_eth_vmdq_dcb_conf { fn default() -> Self { @@ -868,36 +929,42 @@ fn bindgen_test_layout_rte_eth_dcb_rx_conf() { 4usize, concat!("Alignment of ", stringify!(rte_eth_dcb_rx_conf)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_dcb_rx_conf), - "::", - stringify!(nb_tcs) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_dcb_rx_conf), - "::", - stringify!(dcb_tc) - ) - ); + fn test_field_nb_tcs() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_dcb_rx_conf), + "::", + stringify!(nb_tcs) + ) + ); + } + test_field_nb_tcs(); + fn test_field_dcb_tc() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_dcb_rx_conf), + "::", + stringify!(dcb_tc) + ) + ); + } + test_field_dcb_tc(); } impl Default for rte_eth_dcb_rx_conf { fn default() -> Self { @@ -928,36 +995,45 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_tx_conf() { 4usize, concat!("Alignment of ", stringify!(rte_eth_vmdq_dcb_tx_conf)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_tx_conf), - "::", - stringify!(nb_queue_pools) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_tx_conf), - "::", - stringify!(dcb_tc) - ) - ); + fn test_field_nb_queue_pools() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_tx_conf), + "::", + stringify!(nb_queue_pools) + ) + ); + } + test_field_nb_queue_pools(); + fn test_field_dcb_tc() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_tx_conf), + "::", + stringify!(dcb_tc) + ) + ); + } + test_field_dcb_tc(); } impl Default for rte_eth_vmdq_dcb_tx_conf { fn default() -> Self { @@ -988,36 +1064,42 @@ fn bindgen_test_layout_rte_eth_dcb_tx_conf() { 4usize, concat!("Alignment of ", stringify!(rte_eth_dcb_tx_conf)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_dcb_tx_conf), - "::", - stringify!(nb_tcs) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_dcb_tx_conf), - "::", - stringify!(dcb_tc) - ) - ); + fn test_field_nb_tcs() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_dcb_tx_conf), + "::", + stringify!(nb_tcs) + ) + ); + } + test_field_nb_tcs(); + fn test_field_dcb_tc() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_dcb_tx_conf), + "::", + stringify!(dcb_tc) + ) + ); + } + test_field_dcb_tc(); } impl Default for rte_eth_dcb_tx_conf { fn default() -> Self { @@ -1046,21 +1128,25 @@ fn bindgen_test_layout_rte_eth_vmdq_tx_conf() { 4usize, concat!("Alignment of ", stringify!(rte_eth_vmdq_tx_conf)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_tx_conf), - "::", - stringify!(nb_queue_pools) - ) - ); + fn test_field_nb_queue_pools() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_tx_conf), + "::", + stringify!(nb_queue_pools) + ) + ); + } + test_field_nb_queue_pools(); } impl Default for rte_eth_vmdq_tx_conf { fn default() -> Self { @@ -1112,38 +1198,44 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf__bindgen_ty_1() { stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1) ) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_eth_vmdq_rx_conf__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).vlan_id) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1), - "::", - stringify!(vlan_id) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_eth_vmdq_rx_conf__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pools) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1), - "::", - stringify!(pools) - ) - ); + fn test_field_vlan_id() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + rte_eth_vmdq_rx_conf__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).vlan_id) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1), + "::", + stringify!(vlan_id) + ) + ); + } + test_field_vlan_id(); + fn test_field_pools() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + rte_eth_vmdq_rx_conf__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pools) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1), + "::", + stringify!(pools) + ) + ); + } + test_field_pools(); } #[test] fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { @@ -1157,113 +1249,137 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { 8usize, concat!("Alignment of ", stringify!(rte_eth_vmdq_rx_conf)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(nb_queue_pools) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).enable_default_pool) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(enable_default_pool) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).default_pool) as usize - ptr as usize - }, - 5usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(default_pool) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).enable_loop_back) as usize - - ptr as usize - }, - 6usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(enable_loop_back) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_pool_maps) as usize - ptr as usize - }, - 7usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(nb_pool_maps) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rx_mode) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(rx_mode) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pool_map) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(pool_map) - ) - ); + fn test_field_nb_queue_pools() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf), + "::", + stringify!(nb_queue_pools) + ) + ); + } + test_field_nb_queue_pools(); + fn test_field_enable_default_pool() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).enable_default_pool) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf), + "::", + stringify!(enable_default_pool) + ) + ); + } + test_field_enable_default_pool(); + fn test_field_default_pool() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).default_pool) as usize - + ptr as usize + }, + 5usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf), + "::", + stringify!(default_pool) + ) + ); + } + test_field_default_pool(); + fn test_field_enable_loop_back() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).enable_loop_back) as usize - + ptr as usize + }, + 6usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf), + "::", + stringify!(enable_loop_back) + ) + ); + } + test_field_enable_loop_back(); + fn test_field_nb_pool_maps() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_pool_maps) as usize - + ptr as usize + }, + 7usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf), + "::", + stringify!(nb_pool_maps) + ) + ); + } + test_field_nb_pool_maps(); + fn test_field_rx_mode() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rx_mode) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf), + "::", + stringify!(rx_mode) + ) + ); + } + test_field_rx_mode(); + fn test_field_pool_map() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pool_map) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf), + "::", + stringify!(pool_map) + ) + ); + } + test_field_pool_map(); } impl Default for rte_eth_vmdq_rx_conf { fn default() -> Self { @@ -1339,76 +1455,96 @@ fn bindgen_test_layout_rte_eth_ipv4_flow() { 4usize, concat!("Alignment of ", stringify!(rte_eth_ipv4_flow)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(src_ip) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dst_ip) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(dst_ip) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).tos) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(tos) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ttl) as usize - ptr as usize - }, - 9usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(ttl) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize - }, - 10usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(proto) - ) - ); + fn test_field_src_ip() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv4_flow), + "::", + stringify!(src_ip) + ) + ); + } + test_field_src_ip(); + fn test_field_dst_ip() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dst_ip) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv4_flow), + "::", + stringify!(dst_ip) + ) + ); + } + test_field_dst_ip(); + fn test_field_tos() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tos) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv4_flow), + "::", + stringify!(tos) + ) + ); + } + test_field_tos(); + fn test_field_ttl() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ttl) as usize - ptr as usize + }, + 9usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv4_flow), + "::", + stringify!(ttl) + ) + ); + } + test_field_ttl(); + fn test_field_proto() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize + }, + 10usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv4_flow), + "::", + stringify!(proto) + ) + ); + } + test_field_proto(); } /// A structure used to define the input for IPV6 flow #[repr(C)] @@ -1437,76 +1573,96 @@ fn bindgen_test_layout_rte_eth_ipv6_flow() { 4usize, concat!("Alignment of ", stringify!(rte_eth_ipv6_flow)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(src_ip) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dst_ip) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(dst_ip) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).tc) as usize - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(tc) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize - }, - 33usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(proto) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).hop_limits) as usize - ptr as usize - }, - 34usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(hop_limits) - ) - ); + fn test_field_src_ip() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv6_flow), + "::", + stringify!(src_ip) + ) + ); + } + test_field_src_ip(); + fn test_field_dst_ip() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dst_ip) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv6_flow), + "::", + stringify!(dst_ip) + ) + ); + } + test_field_dst_ip(); + fn test_field_tc() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tc) as usize - ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv6_flow), + "::", + stringify!(tc) + ) + ); + } + test_field_tc(); + fn test_field_proto() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize + }, + 33usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv6_flow), + "::", + stringify!(proto) + ) + ); + } + test_field_proto(); + fn test_field_hop_limits() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).hop_limits) as usize - ptr as usize + }, + 34usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv6_flow), + "::", + stringify!(hop_limits) + ) + ); + } + test_field_hop_limits(); } /// A structure used to configure FDIR masks that are used by the device /// to match the various fields of RX packet headers. @@ -1544,128 +1700,156 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { 4usize, concat!("Alignment of ", stringify!(rte_eth_fdir_masks)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).vlan_tci_mask) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(vlan_tci_mask) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ipv4_mask) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(ipv4_mask) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ipv6_mask) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(ipv6_mask) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).src_port_mask) as usize - ptr as usize - }, - 52usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(src_port_mask) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dst_port_mask) as usize - ptr as usize - }, - 54usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(dst_port_mask) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mac_addr_byte_mask) as usize - - ptr as usize - }, - 56usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(mac_addr_byte_mask) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).tunnel_id_mask) as usize - ptr as usize - }, - 60usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(tunnel_id_mask) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).tunnel_type_mask) as usize - - ptr as usize - }, - 64usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(tunnel_type_mask) - ) - ); + fn test_field_vlan_tci_mask() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).vlan_tci_mask) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(vlan_tci_mask) + ) + ); + } + test_field_vlan_tci_mask(); + fn test_field_ipv4_mask() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ipv4_mask) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(ipv4_mask) + ) + ); + } + test_field_ipv4_mask(); + fn test_field_ipv6_mask() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ipv6_mask) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(ipv6_mask) + ) + ); + } + test_field_ipv6_mask(); + fn test_field_src_port_mask() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).src_port_mask) as usize - + ptr as usize + }, + 52usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(src_port_mask) + ) + ); + } + test_field_src_port_mask(); + fn test_field_dst_port_mask() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dst_port_mask) as usize - + ptr as usize + }, + 54usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(dst_port_mask) + ) + ); + } + test_field_dst_port_mask(); + fn test_field_mac_addr_byte_mask() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mac_addr_byte_mask) as usize - + ptr as usize + }, + 56usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(mac_addr_byte_mask) + ) + ); + } + test_field_mac_addr_byte_mask(); + fn test_field_tunnel_id_mask() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tunnel_id_mask) as usize - + ptr as usize + }, + 60usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(tunnel_id_mask) + ) + ); + } + test_field_tunnel_id_mask(); + fn test_field_tunnel_type_mask() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tunnel_type_mask) as usize - + ptr as usize + }, + 64usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(tunnel_type_mask) + ) + ); + } + test_field_tunnel_type_mask(); } #[repr(u32)] /// Payload type @@ -1699,36 +1883,44 @@ fn bindgen_test_layout_rte_eth_flex_payload_cfg() { 4usize, concat!("Alignment of ", stringify!(rte_eth_flex_payload_cfg)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_flex_payload_cfg), - "::", - stringify!(type_) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).src_offset) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_flex_payload_cfg), - "::", - stringify!(src_offset) - ) - ); + fn test_field_type() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_flex_payload_cfg), + "::", + stringify!(type_) + ) + ); + } + test_field_type(); + fn test_field_src_offset() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).src_offset) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_flex_payload_cfg), + "::", + stringify!(src_offset) + ) + ); + } + test_field_src_offset(); } impl Default for rte_eth_flex_payload_cfg { fn default() -> Self { @@ -1759,36 +1951,42 @@ fn bindgen_test_layout_rte_eth_fdir_flex_mask() { 2usize, concat!("Alignment of ", stringify!(rte_eth_fdir_flex_mask)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).flow_type) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_mask), - "::", - stringify!(flow_type) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_mask), - "::", - stringify!(mask) - ) - ); + fn test_field_flow_type() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).flow_type) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_flex_mask), + "::", + stringify!(flow_type) + ) + ); + } + test_field_flow_type(); + fn test_field_mask() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_flex_mask), + "::", + stringify!(mask) + ) + ); + } + test_field_mask(); } /// A structure used to define all flexible payload related setting /// include flex payload and flex mask @@ -1814,66 +2012,79 @@ fn bindgen_test_layout_rte_eth_fdir_flex_conf() { 4usize, concat!("Alignment of ", stringify!(rte_eth_fdir_flex_conf)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_payloads) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_conf), - "::", - stringify!(nb_payloads) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_flexmasks) as usize - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_conf), - "::", - stringify!(nb_flexmasks) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).flex_set) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_conf), - "::", - stringify!(flex_set) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).flex_mask) as usize - ptr as usize - }, - 292usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_conf), - "::", - stringify!(flex_mask) - ) - ); + fn test_field_nb_payloads() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_payloads) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_flex_conf), + "::", + stringify!(nb_payloads) + ) + ); + } + test_field_nb_payloads(); + fn test_field_nb_flexmasks() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_flexmasks) as usize - + ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_flex_conf), + "::", + stringify!(nb_flexmasks) + ) + ); + } + test_field_nb_flexmasks(); + fn test_field_flex_set() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).flex_set) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_flex_conf), + "::", + stringify!(flex_set) + ) + ); + } + test_field_flex_set(); + fn test_field_flex_mask() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).flex_mask) as usize - ptr as usize + }, + 292usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_flex_conf), + "::", + stringify!(flex_mask) + ) + ); + } + test_field_flex_mask(); } impl Default for rte_eth_fdir_flex_conf { fn default() -> Self { @@ -1914,90 +2125,108 @@ fn bindgen_test_layout_rte_fdir_conf() { 4usize, concat!("Alignment of ", stringify!(rte_fdir_conf)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mode) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(mode) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pballoc) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(pballoc) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).status) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(status) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).drop_queue) as usize - ptr as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(drop_queue) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(mask) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).flex_conf) as usize - ptr as usize - }, - 84usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(flex_conf) - ) - ); + fn test_field_mode() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mode) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_fdir_conf), + "::", + stringify!(mode) + ) + ); + } + test_field_mode(); + fn test_field_pballoc() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pballoc) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_fdir_conf), + "::", + stringify!(pballoc) + ) + ); + } + test_field_pballoc(); + fn test_field_status() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).status) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_fdir_conf), + "::", + stringify!(status) + ) + ); + } + test_field_status(); + fn test_field_drop_queue() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).drop_queue) as usize - ptr as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(rte_fdir_conf), + "::", + stringify!(drop_queue) + ) + ); + } + test_field_drop_queue(); + fn test_field_mask() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_fdir_conf), + "::", + stringify!(mask) + ) + ); + } + test_field_mask(); + fn test_field_flex_conf() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).flex_conf) as usize - ptr as usize + }, + 84usize, + concat!( + "Offset of field: ", + stringify!(rte_fdir_conf), + "::", + stringify!(flex_conf) + ) + ); + } + test_field_flex_conf(); } impl Default for rte_fdir_conf { fn default() -> Self { @@ -2029,34 +2258,40 @@ fn bindgen_test_layout_rte_intr_conf() { 2usize, concat!("Alignment of ", stringify!(rte_intr_conf)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).lsc) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_intr_conf), - "::", - stringify!(lsc) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rxq) as usize - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(rte_intr_conf), - "::", - stringify!(rxq) - ) - ); + fn test_field_lsc() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).lsc) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_intr_conf), + "::", + stringify!(lsc) + ) + ); + } + test_field_lsc(); + fn test_field_rxq() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rxq) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(rte_intr_conf), + "::", + stringify!(rxq) + ) + ); + } + test_field_rxq(); } /// A structure used to configure an Ethernet port. /// Depending upon the RX multi-queue mode, extra advanced @@ -2115,66 +2350,84 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_1() { 8usize, concat!("Alignment of ", stringify!(rte_eth_conf__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rss_conf) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_1), - "::", - stringify!(rss_conf) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).vmdq_dcb_conf) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_1), - "::", - stringify!(vmdq_dcb_conf) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dcb_rx_conf) as usize - ptr as usize - }, - 1064usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_1), - "::", - stringify!(dcb_rx_conf) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).vmdq_rx_conf) as usize - ptr as usize - }, - 1080usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_1), - "::", - stringify!(vmdq_rx_conf) - ) - ); + fn test_field_rss_conf() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + rte_eth_conf__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rss_conf) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf__bindgen_ty_1), + "::", + stringify!(rss_conf) + ) + ); + } + test_field_rss_conf(); + fn test_field_vmdq_dcb_conf() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + rte_eth_conf__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).vmdq_dcb_conf) as usize - + ptr as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf__bindgen_ty_1), + "::", + stringify!(vmdq_dcb_conf) + ) + ); + } + test_field_vmdq_dcb_conf(); + fn test_field_dcb_rx_conf() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + rte_eth_conf__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dcb_rx_conf) as usize - ptr as usize + }, + 1064usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf__bindgen_ty_1), + "::", + stringify!(dcb_rx_conf) + ) + ); + } + test_field_dcb_rx_conf(); + fn test_field_vmdq_rx_conf() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + rte_eth_conf__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).vmdq_rx_conf) as usize - + ptr as usize + }, + 1080usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf__bindgen_ty_1), + "::", + stringify!(vmdq_rx_conf) + ) + ); + } + test_field_vmdq_rx_conf(); } impl Default for rte_eth_conf__bindgen_ty_1 { fn default() -> Self { @@ -2204,52 +2457,65 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_2() { 4usize, concat!("Alignment of ", stringify!(rte_eth_conf__bindgen_ty_2)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).vmdq_dcb_tx_conf) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_2), - "::", - stringify!(vmdq_dcb_tx_conf) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dcb_tx_conf) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_2), - "::", - stringify!(dcb_tx_conf) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).vmdq_tx_conf) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_2), - "::", - stringify!(vmdq_tx_conf) - ) - ); + fn test_field_vmdq_dcb_tx_conf() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + rte_eth_conf__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).vmdq_dcb_tx_conf) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf__bindgen_ty_2), + "::", + stringify!(vmdq_dcb_tx_conf) + ) + ); + } + test_field_vmdq_dcb_tx_conf(); + fn test_field_dcb_tx_conf() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + rte_eth_conf__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dcb_tx_conf) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf__bindgen_ty_2), + "::", + stringify!(dcb_tx_conf) + ) + ); + } + test_field_dcb_tx_conf(); + fn test_field_vmdq_tx_conf() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + rte_eth_conf__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).vmdq_tx_conf) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf__bindgen_ty_2), + "::", + stringify!(vmdq_tx_conf) + ) + ); + } + test_field_vmdq_tx_conf(); } impl Default for rte_eth_conf__bindgen_ty_2 { fn default() -> Self { @@ -2272,133 +2538,160 @@ fn bindgen_test_layout_rte_eth_conf() { 8usize, concat!("Alignment of ", stringify!(rte_eth_conf)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).link_speeds) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(link_speeds) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rxmode) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(rxmode) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).txmode) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(txmode) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).lpbk_mode) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(lpbk_mode) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rx_adv_conf) as usize - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(rx_adv_conf) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).tx_adv_conf) as usize - ptr as usize - }, - 2152usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(tx_adv_conf) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dcb_capability_en) as usize - - ptr as usize - }, - 2164usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(dcb_capability_en) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).fdir_conf) as usize - ptr as usize - }, - 2168usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(fdir_conf) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).intr_conf) as usize - ptr as usize - }, - 2940usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(intr_conf) - ) - ); + fn test_field_link_speeds() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).link_speeds) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(link_speeds) + ) + ); + } + test_field_link_speeds(); + fn test_field_rxmode() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rxmode) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(rxmode) + ) + ); + } + test_field_rxmode(); + fn test_field_txmode() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).txmode) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(txmode) + ) + ); + } + test_field_txmode(); + fn test_field_lpbk_mode() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).lpbk_mode) as usize - ptr as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(lpbk_mode) + ) + ); + } + test_field_lpbk_mode(); + fn test_field_rx_adv_conf() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rx_adv_conf) as usize - ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(rx_adv_conf) + ) + ); + } + test_field_rx_adv_conf(); + fn test_field_tx_adv_conf() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tx_adv_conf) as usize - ptr as usize + }, + 2152usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(tx_adv_conf) + ) + ); + } + test_field_tx_adv_conf(); + fn test_field_dcb_capability_en() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dcb_capability_en) as usize - + ptr as usize + }, + 2164usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(dcb_capability_en) + ) + ); + } + test_field_dcb_capability_en(); + fn test_field_fdir_conf() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).fdir_conf) as usize - ptr as usize + }, + 2168usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(fdir_conf) + ) + ); + } + test_field_fdir_conf(); + fn test_field_intr_conf() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).intr_conf) as usize - ptr as usize + }, + 2940usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(intr_conf) + ) + ); + } + test_field_intr_conf(); } impl Default for rte_eth_conf { fn default() -> Self { diff --git a/tests/expectations/tests/layout_eth_conf_1_0.rs b/tests/expectations/tests/layout_eth_conf_1_0.rs index d395acdfff..0458a3ab7c 100644 --- a/tests/expectations/tests/layout_eth_conf_1_0.rs +++ b/tests/expectations/tests/layout_eth_conf_1_0.rs @@ -213,48 +213,62 @@ fn bindgen_test_layout_rte_eth_rxmode() { 4usize, concat!("Alignment of ", stringify!(rte_eth_rxmode)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mq_mode) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rxmode), - "::", - stringify!(mq_mode) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).max_rx_pkt_len) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rxmode), - "::", - stringify!(max_rx_pkt_len) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).split_hdr_size) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rxmode), - "::", - stringify!(split_hdr_size) - ) - ); + fn test_field_mq_mode() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mq_mode) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_rxmode), + "::", + stringify!(mq_mode) + ) + ); + } + test_field_mq_mode(); + fn test_field_max_rx_pkt_len() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).max_rx_pkt_len) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_rxmode), + "::", + stringify!(max_rx_pkt_len) + ) + ); + } + test_field_max_rx_pkt_len(); + fn test_field_split_hdr_size() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).split_hdr_size) as usize - + ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_rxmode), + "::", + stringify!(split_hdr_size) + ) + ); + } + test_field_split_hdr_size(); } impl Clone for rte_eth_rxmode { fn clone(&self) -> Self { @@ -486,34 +500,42 @@ fn bindgen_test_layout_rte_eth_txmode() { 4usize, concat!("Alignment of ", stringify!(rte_eth_txmode)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mq_mode) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_txmode), - "::", - stringify!(mq_mode) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pvid) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_txmode), - "::", - stringify!(pvid) - ) - ); + fn test_field_mq_mode() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mq_mode) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_txmode), + "::", + stringify!(mq_mode) + ) + ); + } + test_field_mq_mode(); + fn test_field_pvid() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pvid) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_txmode), + "::", + stringify!(pvid) + ) + ); + } + test_field_pvid(); } impl Clone for rte_eth_txmode { fn clone(&self) -> Self { @@ -632,48 +654,60 @@ fn bindgen_test_layout_rte_eth_rss_conf() { 8usize, concat!("Alignment of ", stringify!(rte_eth_rss_conf)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rss_key) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rss_conf), - "::", - stringify!(rss_key) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rss_key_len) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rss_conf), - "::", - stringify!(rss_key_len) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rss_hf) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rss_conf), - "::", - stringify!(rss_hf) - ) - ); + fn test_field_rss_key() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rss_key) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_rss_conf), + "::", + stringify!(rss_key) + ) + ); + } + test_field_rss_key(); + fn test_field_rss_key_len() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rss_key_len) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_rss_conf), + "::", + stringify!(rss_key_len) + ) + ); + } + test_field_rss_key_len(); + fn test_field_rss_hf() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rss_hf) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_rss_conf), + "::", + stringify!(rss_hf) + ) + ); + } + test_field_rss_hf(); } impl Clone for rte_eth_rss_conf { fn clone(&self) -> Self { @@ -760,38 +794,44 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf__bindgen_ty_1() { stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1) ) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_eth_vmdq_dcb_conf__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).vlan_id) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1), - "::", - stringify!(vlan_id) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_eth_vmdq_dcb_conf__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pools) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1), - "::", - stringify!(pools) - ) - ); + fn test_field_vlan_id() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + rte_eth_vmdq_dcb_conf__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).vlan_id) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1), + "::", + stringify!(vlan_id) + ) + ); + } + test_field_vlan_id(); + fn test_field_pools() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + rte_eth_vmdq_dcb_conf__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pools) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1), + "::", + stringify!(pools) + ) + ); + } + test_field_pools(); } impl Clone for rte_eth_vmdq_dcb_conf__bindgen_ty_1 { fn clone(&self) -> Self { @@ -810,97 +850,118 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { 8usize, concat!("Alignment of ", stringify!(rte_eth_vmdq_dcb_conf)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(nb_queue_pools) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).enable_default_pool) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(enable_default_pool) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).default_pool) as usize - ptr as usize - }, - 5usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(default_pool) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_pool_maps) as usize - ptr as usize - }, - 6usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(nb_pool_maps) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pool_map) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(pool_map) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize - }, - 1032usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(dcb_tc) - ) - ); + fn test_field_nb_queue_pools() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf), + "::", + stringify!(nb_queue_pools) + ) + ); + } + test_field_nb_queue_pools(); + fn test_field_enable_default_pool() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).enable_default_pool) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf), + "::", + stringify!(enable_default_pool) + ) + ); + } + test_field_enable_default_pool(); + fn test_field_default_pool() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).default_pool) as usize - + ptr as usize + }, + 5usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf), + "::", + stringify!(default_pool) + ) + ); + } + test_field_default_pool(); + fn test_field_nb_pool_maps() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_pool_maps) as usize - + ptr as usize + }, + 6usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf), + "::", + stringify!(nb_pool_maps) + ) + ); + } + test_field_nb_pool_maps(); + fn test_field_pool_map() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pool_map) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf), + "::", + stringify!(pool_map) + ) + ); + } + test_field_pool_map(); + fn test_field_dcb_tc() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize + }, + 1032usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf), + "::", + stringify!(dcb_tc) + ) + ); + } + test_field_dcb_tc(); } impl Clone for rte_eth_vmdq_dcb_conf { fn clone(&self) -> Self { @@ -936,36 +997,42 @@ fn bindgen_test_layout_rte_eth_dcb_rx_conf() { 4usize, concat!("Alignment of ", stringify!(rte_eth_dcb_rx_conf)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_dcb_rx_conf), - "::", - stringify!(nb_tcs) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_dcb_rx_conf), - "::", - stringify!(dcb_tc) - ) - ); + fn test_field_nb_tcs() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_dcb_rx_conf), + "::", + stringify!(nb_tcs) + ) + ); + } + test_field_nb_tcs(); + fn test_field_dcb_tc() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_dcb_rx_conf), + "::", + stringify!(dcb_tc) + ) + ); + } + test_field_dcb_tc(); } impl Clone for rte_eth_dcb_rx_conf { fn clone(&self) -> Self { @@ -1001,36 +1068,45 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_tx_conf() { 4usize, concat!("Alignment of ", stringify!(rte_eth_vmdq_dcb_tx_conf)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_tx_conf), - "::", - stringify!(nb_queue_pools) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_tx_conf), - "::", - stringify!(dcb_tc) - ) - ); + fn test_field_nb_queue_pools() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_tx_conf), + "::", + stringify!(nb_queue_pools) + ) + ); + } + test_field_nb_queue_pools(); + fn test_field_dcb_tc() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_tx_conf), + "::", + stringify!(dcb_tc) + ) + ); + } + test_field_dcb_tc(); } impl Clone for rte_eth_vmdq_dcb_tx_conf { fn clone(&self) -> Self { @@ -1066,36 +1142,42 @@ fn bindgen_test_layout_rte_eth_dcb_tx_conf() { 4usize, concat!("Alignment of ", stringify!(rte_eth_dcb_tx_conf)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_dcb_tx_conf), - "::", - stringify!(nb_tcs) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_dcb_tx_conf), - "::", - stringify!(dcb_tc) - ) - ); + fn test_field_nb_tcs() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_dcb_tx_conf), + "::", + stringify!(nb_tcs) + ) + ); + } + test_field_nb_tcs(); + fn test_field_dcb_tc() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_dcb_tx_conf), + "::", + stringify!(dcb_tc) + ) + ); + } + test_field_dcb_tc(); } impl Clone for rte_eth_dcb_tx_conf { fn clone(&self) -> Self { @@ -1129,21 +1211,25 @@ fn bindgen_test_layout_rte_eth_vmdq_tx_conf() { 4usize, concat!("Alignment of ", stringify!(rte_eth_vmdq_tx_conf)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_tx_conf), - "::", - stringify!(nb_queue_pools) - ) - ); + fn test_field_nb_queue_pools() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_tx_conf), + "::", + stringify!(nb_queue_pools) + ) + ); + } + test_field_nb_queue_pools(); } impl Clone for rte_eth_vmdq_tx_conf { fn clone(&self) -> Self { @@ -1200,38 +1286,44 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf__bindgen_ty_1() { stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1) ) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_eth_vmdq_rx_conf__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).vlan_id) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1), - "::", - stringify!(vlan_id) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_eth_vmdq_rx_conf__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pools) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1), - "::", - stringify!(pools) - ) - ); + fn test_field_vlan_id() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + rte_eth_vmdq_rx_conf__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).vlan_id) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1), + "::", + stringify!(vlan_id) + ) + ); + } + test_field_vlan_id(); + fn test_field_pools() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + rte_eth_vmdq_rx_conf__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pools) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1), + "::", + stringify!(pools) + ) + ); + } + test_field_pools(); } impl Clone for rte_eth_vmdq_rx_conf__bindgen_ty_1 { fn clone(&self) -> Self { @@ -1250,113 +1342,137 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { 8usize, concat!("Alignment of ", stringify!(rte_eth_vmdq_rx_conf)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(nb_queue_pools) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).enable_default_pool) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(enable_default_pool) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).default_pool) as usize - ptr as usize - }, - 5usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(default_pool) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).enable_loop_back) as usize - - ptr as usize - }, - 6usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(enable_loop_back) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_pool_maps) as usize - ptr as usize - }, - 7usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(nb_pool_maps) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rx_mode) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(rx_mode) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pool_map) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(pool_map) - ) - ); + fn test_field_nb_queue_pools() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf), + "::", + stringify!(nb_queue_pools) + ) + ); + } + test_field_nb_queue_pools(); + fn test_field_enable_default_pool() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).enable_default_pool) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf), + "::", + stringify!(enable_default_pool) + ) + ); + } + test_field_enable_default_pool(); + fn test_field_default_pool() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).default_pool) as usize - + ptr as usize + }, + 5usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf), + "::", + stringify!(default_pool) + ) + ); + } + test_field_default_pool(); + fn test_field_enable_loop_back() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).enable_loop_back) as usize - + ptr as usize + }, + 6usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf), + "::", + stringify!(enable_loop_back) + ) + ); + } + test_field_enable_loop_back(); + fn test_field_nb_pool_maps() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_pool_maps) as usize - + ptr as usize + }, + 7usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf), + "::", + stringify!(nb_pool_maps) + ) + ); + } + test_field_nb_pool_maps(); + fn test_field_rx_mode() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rx_mode) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf), + "::", + stringify!(rx_mode) + ) + ); + } + test_field_rx_mode(); + fn test_field_pool_map() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pool_map) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf), + "::", + stringify!(pool_map) + ) + ); + } + test_field_pool_map(); } impl Clone for rte_eth_vmdq_rx_conf { fn clone(&self) -> Self { @@ -1437,76 +1553,96 @@ fn bindgen_test_layout_rte_eth_ipv4_flow() { 4usize, concat!("Alignment of ", stringify!(rte_eth_ipv4_flow)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(src_ip) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dst_ip) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(dst_ip) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).tos) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(tos) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ttl) as usize - ptr as usize - }, - 9usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(ttl) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize - }, - 10usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(proto) - ) - ); + fn test_field_src_ip() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv4_flow), + "::", + stringify!(src_ip) + ) + ); + } + test_field_src_ip(); + fn test_field_dst_ip() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dst_ip) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv4_flow), + "::", + stringify!(dst_ip) + ) + ); + } + test_field_dst_ip(); + fn test_field_tos() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tos) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv4_flow), + "::", + stringify!(tos) + ) + ); + } + test_field_tos(); + fn test_field_ttl() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ttl) as usize - ptr as usize + }, + 9usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv4_flow), + "::", + stringify!(ttl) + ) + ); + } + test_field_ttl(); + fn test_field_proto() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize + }, + 10usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv4_flow), + "::", + stringify!(proto) + ) + ); + } + test_field_proto(); } impl Clone for rte_eth_ipv4_flow { fn clone(&self) -> Self { @@ -1540,76 +1676,96 @@ fn bindgen_test_layout_rte_eth_ipv6_flow() { 4usize, concat!("Alignment of ", stringify!(rte_eth_ipv6_flow)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(src_ip) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dst_ip) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(dst_ip) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).tc) as usize - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(tc) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize - }, - 33usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(proto) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).hop_limits) as usize - ptr as usize - }, - 34usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(hop_limits) - ) - ); + fn test_field_src_ip() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv6_flow), + "::", + stringify!(src_ip) + ) + ); + } + test_field_src_ip(); + fn test_field_dst_ip() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dst_ip) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv6_flow), + "::", + stringify!(dst_ip) + ) + ); + } + test_field_dst_ip(); + fn test_field_tc() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tc) as usize - ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv6_flow), + "::", + stringify!(tc) + ) + ); + } + test_field_tc(); + fn test_field_proto() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize + }, + 33usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv6_flow), + "::", + stringify!(proto) + ) + ); + } + test_field_proto(); + fn test_field_hop_limits() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).hop_limits) as usize - ptr as usize + }, + 34usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv6_flow), + "::", + stringify!(hop_limits) + ) + ); + } + test_field_hop_limits(); } impl Clone for rte_eth_ipv6_flow { fn clone(&self) -> Self { @@ -1652,128 +1808,156 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { 4usize, concat!("Alignment of ", stringify!(rte_eth_fdir_masks)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).vlan_tci_mask) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(vlan_tci_mask) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ipv4_mask) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(ipv4_mask) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ipv6_mask) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(ipv6_mask) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).src_port_mask) as usize - ptr as usize - }, - 52usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(src_port_mask) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dst_port_mask) as usize - ptr as usize - }, - 54usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(dst_port_mask) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mac_addr_byte_mask) as usize - - ptr as usize - }, - 56usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(mac_addr_byte_mask) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).tunnel_id_mask) as usize - ptr as usize - }, - 60usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(tunnel_id_mask) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).tunnel_type_mask) as usize - - ptr as usize - }, - 64usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(tunnel_type_mask) - ) - ); + fn test_field_vlan_tci_mask() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).vlan_tci_mask) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(vlan_tci_mask) + ) + ); + } + test_field_vlan_tci_mask(); + fn test_field_ipv4_mask() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ipv4_mask) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(ipv4_mask) + ) + ); + } + test_field_ipv4_mask(); + fn test_field_ipv6_mask() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ipv6_mask) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(ipv6_mask) + ) + ); + } + test_field_ipv6_mask(); + fn test_field_src_port_mask() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).src_port_mask) as usize - + ptr as usize + }, + 52usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(src_port_mask) + ) + ); + } + test_field_src_port_mask(); + fn test_field_dst_port_mask() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dst_port_mask) as usize - + ptr as usize + }, + 54usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(dst_port_mask) + ) + ); + } + test_field_dst_port_mask(); + fn test_field_mac_addr_byte_mask() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mac_addr_byte_mask) as usize - + ptr as usize + }, + 56usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(mac_addr_byte_mask) + ) + ); + } + test_field_mac_addr_byte_mask(); + fn test_field_tunnel_id_mask() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tunnel_id_mask) as usize - + ptr as usize + }, + 60usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(tunnel_id_mask) + ) + ); + } + test_field_tunnel_id_mask(); + fn test_field_tunnel_type_mask() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tunnel_type_mask) as usize - + ptr as usize + }, + 64usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(tunnel_type_mask) + ) + ); + } + test_field_tunnel_type_mask(); } impl Clone for rte_eth_fdir_masks { fn clone(&self) -> Self { @@ -1812,36 +1996,44 @@ fn bindgen_test_layout_rte_eth_flex_payload_cfg() { 4usize, concat!("Alignment of ", stringify!(rte_eth_flex_payload_cfg)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_flex_payload_cfg), - "::", - stringify!(type_) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).src_offset) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_flex_payload_cfg), - "::", - stringify!(src_offset) - ) - ); + fn test_field_type() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_flex_payload_cfg), + "::", + stringify!(type_) + ) + ); + } + test_field_type(); + fn test_field_src_offset() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).src_offset) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_flex_payload_cfg), + "::", + stringify!(src_offset) + ) + ); + } + test_field_src_offset(); } impl Clone for rte_eth_flex_payload_cfg { fn clone(&self) -> Self { @@ -1877,36 +2069,42 @@ fn bindgen_test_layout_rte_eth_fdir_flex_mask() { 2usize, concat!("Alignment of ", stringify!(rte_eth_fdir_flex_mask)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).flow_type) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_mask), - "::", - stringify!(flow_type) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_mask), - "::", - stringify!(mask) - ) - ); + fn test_field_flow_type() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).flow_type) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_flex_mask), + "::", + stringify!(flow_type) + ) + ); + } + test_field_flow_type(); + fn test_field_mask() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_flex_mask), + "::", + stringify!(mask) + ) + ); + } + test_field_mask(); } impl Clone for rte_eth_fdir_flex_mask { fn clone(&self) -> Self { @@ -1937,66 +2135,79 @@ fn bindgen_test_layout_rte_eth_fdir_flex_conf() { 4usize, concat!("Alignment of ", stringify!(rte_eth_fdir_flex_conf)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_payloads) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_conf), - "::", - stringify!(nb_payloads) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_flexmasks) as usize - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_conf), - "::", - stringify!(nb_flexmasks) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).flex_set) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_conf), - "::", - stringify!(flex_set) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).flex_mask) as usize - ptr as usize - }, - 292usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_conf), - "::", - stringify!(flex_mask) - ) - ); + fn test_field_nb_payloads() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_payloads) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_flex_conf), + "::", + stringify!(nb_payloads) + ) + ); + } + test_field_nb_payloads(); + fn test_field_nb_flexmasks() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_flexmasks) as usize - + ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_flex_conf), + "::", + stringify!(nb_flexmasks) + ) + ); + } + test_field_nb_flexmasks(); + fn test_field_flex_set() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).flex_set) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_flex_conf), + "::", + stringify!(flex_set) + ) + ); + } + test_field_flex_set(); + fn test_field_flex_mask() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).flex_mask) as usize - ptr as usize + }, + 292usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_flex_conf), + "::", + stringify!(flex_mask) + ) + ); + } + test_field_flex_mask(); } impl Clone for rte_eth_fdir_flex_conf { fn clone(&self) -> Self { @@ -2042,90 +2253,108 @@ fn bindgen_test_layout_rte_fdir_conf() { 4usize, concat!("Alignment of ", stringify!(rte_fdir_conf)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mode) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(mode) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pballoc) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(pballoc) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).status) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(status) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).drop_queue) as usize - ptr as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(drop_queue) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(mask) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).flex_conf) as usize - ptr as usize - }, - 84usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(flex_conf) - ) - ); + fn test_field_mode() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mode) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_fdir_conf), + "::", + stringify!(mode) + ) + ); + } + test_field_mode(); + fn test_field_pballoc() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pballoc) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_fdir_conf), + "::", + stringify!(pballoc) + ) + ); + } + test_field_pballoc(); + fn test_field_status() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).status) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_fdir_conf), + "::", + stringify!(status) + ) + ); + } + test_field_status(); + fn test_field_drop_queue() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).drop_queue) as usize - ptr as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(rte_fdir_conf), + "::", + stringify!(drop_queue) + ) + ); + } + test_field_drop_queue(); + fn test_field_mask() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_fdir_conf), + "::", + stringify!(mask) + ) + ); + } + test_field_mask(); + fn test_field_flex_conf() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).flex_conf) as usize - ptr as usize + }, + 84usize, + concat!( + "Offset of field: ", + stringify!(rte_fdir_conf), + "::", + stringify!(flex_conf) + ) + ); + } + test_field_flex_conf(); } impl Clone for rte_fdir_conf { fn clone(&self) -> Self { @@ -2162,34 +2391,40 @@ fn bindgen_test_layout_rte_intr_conf() { 2usize, concat!("Alignment of ", stringify!(rte_intr_conf)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).lsc) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_intr_conf), - "::", - stringify!(lsc) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rxq) as usize - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(rte_intr_conf), - "::", - stringify!(rxq) - ) - ); + fn test_field_lsc() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).lsc) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_intr_conf), + "::", + stringify!(lsc) + ) + ); + } + test_field_lsc(); + fn test_field_rxq() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rxq) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(rte_intr_conf), + "::", + stringify!(rxq) + ) + ); + } + test_field_rxq(); } impl Clone for rte_intr_conf { fn clone(&self) -> Self { @@ -2253,66 +2488,84 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_1() { 8usize, concat!("Alignment of ", stringify!(rte_eth_conf__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rss_conf) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_1), - "::", - stringify!(rss_conf) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).vmdq_dcb_conf) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_1), - "::", - stringify!(vmdq_dcb_conf) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dcb_rx_conf) as usize - ptr as usize - }, - 1064usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_1), - "::", - stringify!(dcb_rx_conf) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).vmdq_rx_conf) as usize - ptr as usize - }, - 1080usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_1), - "::", - stringify!(vmdq_rx_conf) - ) - ); + fn test_field_rss_conf() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + rte_eth_conf__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rss_conf) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf__bindgen_ty_1), + "::", + stringify!(rss_conf) + ) + ); + } + test_field_rss_conf(); + fn test_field_vmdq_dcb_conf() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + rte_eth_conf__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).vmdq_dcb_conf) as usize - + ptr as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf__bindgen_ty_1), + "::", + stringify!(vmdq_dcb_conf) + ) + ); + } + test_field_vmdq_dcb_conf(); + fn test_field_dcb_rx_conf() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + rte_eth_conf__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dcb_rx_conf) as usize - ptr as usize + }, + 1064usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf__bindgen_ty_1), + "::", + stringify!(dcb_rx_conf) + ) + ); + } + test_field_dcb_rx_conf(); + fn test_field_vmdq_rx_conf() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + rte_eth_conf__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).vmdq_rx_conf) as usize - + ptr as usize + }, + 1080usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf__bindgen_ty_1), + "::", + stringify!(vmdq_rx_conf) + ) + ); + } + test_field_vmdq_rx_conf(); } impl Clone for rte_eth_conf__bindgen_ty_1 { fn clone(&self) -> Self { @@ -2348,52 +2601,65 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_2() { 4usize, concat!("Alignment of ", stringify!(rte_eth_conf__bindgen_ty_2)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).vmdq_dcb_tx_conf) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_2), - "::", - stringify!(vmdq_dcb_tx_conf) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dcb_tx_conf) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_2), - "::", - stringify!(dcb_tx_conf) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).vmdq_tx_conf) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_2), - "::", - stringify!(vmdq_tx_conf) - ) - ); + fn test_field_vmdq_dcb_tx_conf() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + rte_eth_conf__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).vmdq_dcb_tx_conf) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf__bindgen_ty_2), + "::", + stringify!(vmdq_dcb_tx_conf) + ) + ); + } + test_field_vmdq_dcb_tx_conf(); + fn test_field_dcb_tx_conf() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + rte_eth_conf__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dcb_tx_conf) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf__bindgen_ty_2), + "::", + stringify!(dcb_tx_conf) + ) + ); + } + test_field_dcb_tx_conf(); + fn test_field_vmdq_tx_conf() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + rte_eth_conf__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).vmdq_tx_conf) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf__bindgen_ty_2), + "::", + stringify!(vmdq_tx_conf) + ) + ); + } + test_field_vmdq_tx_conf(); } impl Clone for rte_eth_conf__bindgen_ty_2 { fn clone(&self) -> Self { @@ -2412,133 +2678,160 @@ fn bindgen_test_layout_rte_eth_conf() { 8usize, concat!("Alignment of ", stringify!(rte_eth_conf)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).link_speeds) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(link_speeds) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rxmode) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(rxmode) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).txmode) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(txmode) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).lpbk_mode) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(lpbk_mode) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rx_adv_conf) as usize - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(rx_adv_conf) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).tx_adv_conf) as usize - ptr as usize - }, - 2152usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(tx_adv_conf) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dcb_capability_en) as usize - - ptr as usize - }, - 2164usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(dcb_capability_en) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).fdir_conf) as usize - ptr as usize - }, - 2168usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(fdir_conf) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).intr_conf) as usize - ptr as usize - }, - 2940usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(intr_conf) - ) - ); + fn test_field_link_speeds() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).link_speeds) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(link_speeds) + ) + ); + } + test_field_link_speeds(); + fn test_field_rxmode() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rxmode) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(rxmode) + ) + ); + } + test_field_rxmode(); + fn test_field_txmode() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).txmode) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(txmode) + ) + ); + } + test_field_txmode(); + fn test_field_lpbk_mode() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).lpbk_mode) as usize - ptr as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(lpbk_mode) + ) + ); + } + test_field_lpbk_mode(); + fn test_field_rx_adv_conf() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rx_adv_conf) as usize - ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(rx_adv_conf) + ) + ); + } + test_field_rx_adv_conf(); + fn test_field_tx_adv_conf() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tx_adv_conf) as usize - ptr as usize + }, + 2152usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(tx_adv_conf) + ) + ); + } + test_field_tx_adv_conf(); + fn test_field_dcb_capability_en() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dcb_capability_en) as usize - + ptr as usize + }, + 2164usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(dcb_capability_en) + ) + ); + } + test_field_dcb_capability_en(); + fn test_field_fdir_conf() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).fdir_conf) as usize - ptr as usize + }, + 2168usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(fdir_conf) + ) + ); + } + test_field_fdir_conf(); + fn test_field_intr_conf() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).intr_conf) as usize - ptr as usize + }, + 2940usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(intr_conf) + ) + ); + } + test_field_intr_conf(); } impl Clone for rte_eth_conf { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/layout_kni_mbuf.rs b/tests/expectations/tests/layout_kni_mbuf.rs index f277d86d97..4eaa707882 100644 --- a/tests/expectations/tests/layout_kni_mbuf.rs +++ b/tests/expectations/tests/layout_kni_mbuf.rs @@ -44,202 +44,245 @@ fn bindgen_test_layout_rte_kni_mbuf() { 64usize, concat!("Alignment of ", stringify!(rte_kni_mbuf)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).buf_addr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(buf_addr) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).buf_physaddr) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(buf_physaddr) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pad0) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(pad0) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).data_off) as usize - ptr as usize - }, - 18usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(data_off) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pad1) as usize - ptr as usize - }, - 20usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(pad1) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_segs) as usize - ptr as usize - }, - 22usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(nb_segs) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pad4) as usize - ptr as usize - }, - 23usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(pad4) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ol_flags) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(ol_flags) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pad2) as usize - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(pad2) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pkt_len) as usize - ptr as usize - }, - 36usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(pkt_len) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).data_len) as usize - ptr as usize - }, - 40usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(data_len) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pad3) as usize - ptr as usize - }, - 64usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(pad3) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pool) as usize - ptr as usize - }, - 72usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(pool) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize - }, - 80usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(next) - ) - ); + fn test_field_buf_addr() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).buf_addr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_mbuf), + "::", + stringify!(buf_addr) + ) + ); + } + test_field_buf_addr(); + fn test_field_buf_physaddr() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).buf_physaddr) as usize - + ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_mbuf), + "::", + stringify!(buf_physaddr) + ) + ); + } + test_field_buf_physaddr(); + fn test_field_pad0() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pad0) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_mbuf), + "::", + stringify!(pad0) + ) + ); + } + test_field_pad0(); + fn test_field_data_off() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).data_off) as usize - ptr as usize + }, + 18usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_mbuf), + "::", + stringify!(data_off) + ) + ); + } + test_field_data_off(); + fn test_field_pad1() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pad1) as usize - ptr as usize + }, + 20usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_mbuf), + "::", + stringify!(pad1) + ) + ); + } + test_field_pad1(); + fn test_field_nb_segs() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_segs) as usize - ptr as usize + }, + 22usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_mbuf), + "::", + stringify!(nb_segs) + ) + ); + } + test_field_nb_segs(); + fn test_field_pad4() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pad4) as usize - ptr as usize + }, + 23usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_mbuf), + "::", + stringify!(pad4) + ) + ); + } + test_field_pad4(); + fn test_field_ol_flags() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ol_flags) as usize - ptr as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_mbuf), + "::", + stringify!(ol_flags) + ) + ); + } + test_field_ol_flags(); + fn test_field_pad2() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pad2) as usize - ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_mbuf), + "::", + stringify!(pad2) + ) + ); + } + test_field_pad2(); + fn test_field_pkt_len() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pkt_len) as usize - ptr as usize + }, + 36usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_mbuf), + "::", + stringify!(pkt_len) + ) + ); + } + test_field_pkt_len(); + fn test_field_data_len() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).data_len) as usize - ptr as usize + }, + 40usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_mbuf), + "::", + stringify!(data_len) + ) + ); + } + test_field_data_len(); + fn test_field_pad3() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pad3) as usize - ptr as usize + }, + 64usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_mbuf), + "::", + stringify!(pad3) + ) + ); + } + test_field_pad3(); + fn test_field_pool() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pool) as usize - ptr as usize + }, + 72usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_mbuf), + "::", + stringify!(pool) + ) + ); + } + test_field_pool(); + fn test_field_next() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize + }, + 80usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_mbuf), + "::", + stringify!(next) + ) + ); + } + test_field_next(); } impl Default for rte_kni_mbuf { fn default() -> Self { diff --git a/tests/expectations/tests/layout_large_align_field.rs b/tests/expectations/tests/layout_large_align_field.rs index 4461408972..daf3d56272 100644 --- a/tests/expectations/tests/layout_large_align_field.rs +++ b/tests/expectations/tests/layout_large_align_field.rs @@ -75,48 +75,57 @@ fn bindgen_test_layout_ip_frag() { 8usize, concat!("Alignment of ", stringify!(ip_frag)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ofs) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ip_frag), - "::", - stringify!(ofs) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(ip_frag), - "::", - stringify!(len) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mb) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(ip_frag), - "::", - stringify!(mb) - ) - ); + fn test_field_ofs() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ofs) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ip_frag), + "::", + stringify!(ofs) + ) + ); + } + test_field_ofs(); + fn test_field_len() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(ip_frag), + "::", + stringify!(len) + ) + ); + } + test_field_len(); + fn test_field_mb() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mb) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(ip_frag), + "::", + stringify!(mb) + ) + ); + } + test_field_mb(); } impl Default for ip_frag { fn default() -> Self { @@ -150,48 +159,57 @@ fn bindgen_test_layout_ip_frag_key() { 8usize, concat!("Alignment of ", stringify!(ip_frag_key)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).src_dst) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_key), - "::", - stringify!(src_dst) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).id) as usize - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_key), - "::", - stringify!(id) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).key_len) as usize - ptr as usize - }, - 36usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_key), - "::", - stringify!(key_len) - ) - ); + fn test_field_src_dst() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).src_dst) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_key), + "::", + stringify!(src_dst) + ) + ); + } + test_field_src_dst(); + fn test_field_id() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).id) as usize - ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_key), + "::", + stringify!(id) + ) + ); + } + test_field_id(); + fn test_field_key_len() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).key_len) as usize - ptr as usize + }, + 36usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_key), + "::", + stringify!(key_len) + ) + ); + } + test_field_key_len(); } /// @internal Fragmented packet to reassemble. /// First two entries in the frags[] array are for the last and first fragments. @@ -232,36 +250,40 @@ fn bindgen_test_layout_ip_frag_pkt__bindgen_ty_1() { 8usize, concat!("Alignment of ", stringify!(ip_frag_pkt__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).tqe_next) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt__bindgen_ty_1), - "::", - stringify!(tqe_next) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).tqe_prev) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt__bindgen_ty_1), - "::", - stringify!(tqe_prev) - ) - ); + fn test_field_tqe_next() { + assert_eq!( + unsafe { + let uninit = :: std :: mem :: MaybeUninit :: < ip_frag_pkt__bindgen_ty_1 > :: uninit () ; + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tqe_next) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_pkt__bindgen_ty_1), + "::", + stringify!(tqe_next) + ) + ); + } + test_field_tqe_next(); + fn test_field_tqe_prev() { + assert_eq!( + unsafe { + let uninit = :: std :: mem :: MaybeUninit :: < ip_frag_pkt__bindgen_ty_1 > :: uninit () ; + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tqe_prev) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_pkt__bindgen_ty_1), + "::", + stringify!(tqe_prev) + ) + ); + } + test_field_tqe_prev(); } impl Default for ip_frag_pkt__bindgen_ty_1 { fn default() -> Self { @@ -284,104 +306,125 @@ fn bindgen_test_layout_ip_frag_pkt() { 64usize, concat!("Alignment of ", stringify!(ip_frag_pkt)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).lru) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(lru) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).key) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(key) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).start) as usize - ptr as usize - }, - 56usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(start) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).total_size) as usize - ptr as usize - }, - 64usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(total_size) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).frag_size) as usize - ptr as usize - }, - 68usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(frag_size) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).last_idx) as usize - ptr as usize - }, - 72usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(last_idx) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).frags) as usize - ptr as usize - }, - 80usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(frags) - ) - ); + fn test_field_lru() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).lru) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_pkt), + "::", + stringify!(lru) + ) + ); + } + test_field_lru(); + fn test_field_key() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).key) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_pkt), + "::", + stringify!(key) + ) + ); + } + test_field_key(); + fn test_field_start() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).start) as usize - ptr as usize + }, + 56usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_pkt), + "::", + stringify!(start) + ) + ); + } + test_field_start(); + fn test_field_total_size() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).total_size) as usize - ptr as usize + }, + 64usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_pkt), + "::", + stringify!(total_size) + ) + ); + } + test_field_total_size(); + fn test_field_frag_size() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).frag_size) as usize - ptr as usize + }, + 68usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_pkt), + "::", + stringify!(frag_size) + ) + ); + } + test_field_frag_size(); + fn test_field_last_idx() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).last_idx) as usize - ptr as usize + }, + 72usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_pkt), + "::", + stringify!(last_idx) + ) + ); + } + test_field_last_idx(); + fn test_field_frags() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).frags) as usize - ptr as usize + }, + 80usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_pkt), + "::", + stringify!(frags) + ) + ); + } + test_field_frags(); } impl Default for ip_frag_pkt { fn default() -> Self { @@ -410,34 +453,40 @@ fn bindgen_test_layout_ip_pkt_list() { 8usize, concat!("Alignment of ", stringify!(ip_pkt_list)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).tqh_first) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ip_pkt_list), - "::", - stringify!(tqh_first) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).tqh_last) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(ip_pkt_list), - "::", - stringify!(tqh_last) - ) - ); + fn test_field_tqh_first() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tqh_first) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ip_pkt_list), + "::", + stringify!(tqh_first) + ) + ); + } + test_field_tqh_first(); + fn test_field_tqh_last() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tqh_last) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(ip_pkt_list), + "::", + stringify!(tqh_last) + ) + ); + } + test_field_tqh_last(); } impl Default for ip_pkt_list { fn default() -> Self { @@ -478,90 +527,115 @@ fn bindgen_test_layout_ip_frag_tbl_stat() { 64usize, concat!("Alignment of ", stringify!(ip_frag_tbl_stat)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).find_num) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_tbl_stat), - "::", - stringify!(find_num) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).add_num) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_tbl_stat), - "::", - stringify!(add_num) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).del_num) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_tbl_stat), - "::", - stringify!(del_num) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).reuse_num) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_tbl_stat), - "::", - stringify!(reuse_num) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).fail_total) as usize - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_tbl_stat), - "::", - stringify!(fail_total) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).fail_nospace) as usize - ptr as usize - }, - 40usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_tbl_stat), - "::", - stringify!(fail_nospace) - ) - ); + fn test_field_find_num() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).find_num) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_tbl_stat), + "::", + stringify!(find_num) + ) + ); + } + test_field_find_num(); + fn test_field_add_num() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).add_num) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_tbl_stat), + "::", + stringify!(add_num) + ) + ); + } + test_field_add_num(); + fn test_field_del_num() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).del_num) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_tbl_stat), + "::", + stringify!(del_num) + ) + ); + } + test_field_del_num(); + fn test_field_reuse_num() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).reuse_num) as usize - ptr as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_tbl_stat), + "::", + stringify!(reuse_num) + ) + ); + } + test_field_reuse_num(); + fn test_field_fail_total() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).fail_total) as usize - ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_tbl_stat), + "::", + stringify!(fail_total) + ) + ); + } + test_field_fail_total(); + fn test_field_fail_nospace() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).fail_nospace) as usize - + ptr as usize + }, + 40usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_tbl_stat), + "::", + stringify!(fail_nospace) + ) + ); + } + test_field_fail_nospace(); } impl Default for ip_frag_tbl_stat { fn default() -> Self { @@ -612,160 +686,205 @@ fn bindgen_test_layout_rte_ip_frag_tbl() { 64usize, concat!("Alignment of ", stringify!(rte_ip_frag_tbl)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).max_cycles) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(max_cycles) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).entry_mask) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(entry_mask) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).max_entries) as usize - ptr as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(max_entries) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).use_entries) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(use_entries) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bucket_entries) as usize - ptr as usize - }, - 20usize, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(bucket_entries) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_entries) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(nb_entries) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_buckets) as usize - ptr as usize - }, - 28usize, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(nb_buckets) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).last) as usize - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(last) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).lru) as usize - ptr as usize - }, - 40usize, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(lru) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).stat) as usize - ptr as usize - }, - 64usize, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(stat) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pkt) as usize - ptr as usize - }, - 128usize, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(pkt) - ) - ); + fn test_field_max_cycles() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).max_cycles) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ip_frag_tbl), + "::", + stringify!(max_cycles) + ) + ); + } + test_field_max_cycles(); + fn test_field_entry_mask() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).entry_mask) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_ip_frag_tbl), + "::", + stringify!(entry_mask) + ) + ); + } + test_field_entry_mask(); + fn test_field_max_entries() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).max_entries) as usize - ptr as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(rte_ip_frag_tbl), + "::", + stringify!(max_entries) + ) + ); + } + test_field_max_entries(); + fn test_field_use_entries() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).use_entries) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_ip_frag_tbl), + "::", + stringify!(use_entries) + ) + ); + } + test_field_use_entries(); + fn test_field_bucket_entries() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bucket_entries) as usize - + ptr as usize + }, + 20usize, + concat!( + "Offset of field: ", + stringify!(rte_ip_frag_tbl), + "::", + stringify!(bucket_entries) + ) + ); + } + test_field_bucket_entries(); + fn test_field_nb_entries() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_entries) as usize - ptr as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(rte_ip_frag_tbl), + "::", + stringify!(nb_entries) + ) + ); + } + test_field_nb_entries(); + fn test_field_nb_buckets() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_buckets) as usize - ptr as usize + }, + 28usize, + concat!( + "Offset of field: ", + stringify!(rte_ip_frag_tbl), + "::", + stringify!(nb_buckets) + ) + ); + } + test_field_nb_buckets(); + fn test_field_last() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).last) as usize - ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(rte_ip_frag_tbl), + "::", + stringify!(last) + ) + ); + } + test_field_last(); + fn test_field_lru() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).lru) as usize - ptr as usize + }, + 40usize, + concat!( + "Offset of field: ", + stringify!(rte_ip_frag_tbl), + "::", + stringify!(lru) + ) + ); + } + test_field_lru(); + fn test_field_stat() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).stat) as usize - ptr as usize + }, + 64usize, + concat!( + "Offset of field: ", + stringify!(rte_ip_frag_tbl), + "::", + stringify!(stat) + ) + ); + } + test_field_stat(); + fn test_field_pkt() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pkt) as usize - ptr as usize + }, + 128usize, + concat!( + "Offset of field: ", + stringify!(rte_ip_frag_tbl), + "::", + stringify!(pkt) + ) + ); + } + test_field_pkt(); } impl Default for rte_ip_frag_tbl { fn default() -> Self { diff --git a/tests/expectations/tests/layout_mbuf.rs b/tests/expectations/tests/layout_mbuf.rs index cf7a0e26d1..549c5292a5 100644 --- a/tests/expectations/tests/layout_mbuf.rs +++ b/tests/expectations/tests/layout_mbuf.rs @@ -116,20 +116,24 @@ fn bindgen_test_layout_rte_atomic16_t() { 2usize, concat!("Alignment of ", stringify!(rte_atomic16_t)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).cnt) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_atomic16_t), - "::", - stringify!(cnt) - ) - ); + fn test_field_cnt() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).cnt) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_atomic16_t), + "::", + stringify!(cnt) + ) + ); + } + test_field_cnt(); } /// The generic rte_mbuf, containing a packet mbuf. #[repr(C)] @@ -204,36 +208,43 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_1() { 2usize, concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).refcnt_atomic) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_1), - "::", - stringify!(refcnt_atomic) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).refcnt) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_1), - "::", - stringify!(refcnt) - ) - ); + fn test_field_refcnt_atomic() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).refcnt_atomic) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_1), + "::", + stringify!(refcnt_atomic) + ) + ); + } + test_field_refcnt_atomic(); + fn test_field_refcnt() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).refcnt) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_1), + "::", + stringify!(refcnt) + ) + ); + } + test_field_refcnt(); } impl Default for rte_mbuf__bindgen_ty_1 { fn default() -> Self { @@ -427,21 +438,24 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_2() { 4usize, concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_2)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).packet_type) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_2), - "::", - stringify!(packet_type) - ) - ); + fn test_field_packet_type() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).packet_type) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_2), + "::", + stringify!(packet_type) + ) + ); + } + test_field_packet_type(); } impl Default for rte_mbuf__bindgen_ty_2 { fn default() -> Self { @@ -488,8 +502,14 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindg ) { assert_eq ! (:: std :: mem :: size_of :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > () , 4usize , concat ! ("Size of: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1))); assert_eq ! (:: std :: mem :: align_of :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > () , 2usize , concat ! ("Alignment of " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1))); - assert_eq ! (unsafe { let uninit = :: std :: mem :: MaybeUninit :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > :: uninit () ; let ptr = uninit . as_ptr () ; :: std :: ptr :: addr_of ! ((* ptr) . hash) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (hash))); - assert_eq ! (unsafe { let uninit = :: std :: mem :: MaybeUninit :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > :: uninit () ; let ptr = uninit . as_ptr () ; :: std :: ptr :: addr_of ! ((* ptr) . id) as usize - ptr as usize } , 2usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (id))); + fn test_field_hash() { + assert_eq ! (unsafe { let uninit = :: std :: mem :: MaybeUninit :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > :: uninit () ; let ptr = uninit . as_ptr () ; :: std :: ptr :: addr_of ! ((* ptr) . hash) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (hash))); + } + test_field_hash(); + fn test_field_id() { + assert_eq ! (unsafe { let uninit = :: std :: mem :: MaybeUninit :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > :: uninit () ; let ptr = uninit . as_ptr () ; :: std :: ptr :: addr_of ! ((* ptr) . id) as usize - ptr as usize } , 2usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (id))); + } + test_field_id(); } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1() { @@ -512,22 +532,25 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1() { stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1) ) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).lo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(lo) - ) - ); + fn test_field_lo() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).lo) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(lo) + ) + ); + } + test_field_lo(); } impl Default for rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 { fn default() -> Self { @@ -556,22 +579,25 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1() { stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1) ) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_mbuf__bindgen_ty_3__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).hi) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1), - "::", - stringify!(hi) - ) - ); + fn test_field_hi() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + rte_mbuf__bindgen_ty_3__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).hi) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1), + "::", + stringify!(hi) + ) + ); + } + test_field_hi(); } impl Default for rte_mbuf__bindgen_ty_3__bindgen_ty_1 { fn default() -> Self { @@ -606,38 +632,44 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_2() { stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2) ) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_mbuf__bindgen_ty_3__bindgen_ty_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).lo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2), - "::", - stringify!(lo) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_mbuf__bindgen_ty_3__bindgen_ty_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).hi) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2), - "::", - stringify!(hi) - ) - ); + fn test_field_lo() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + rte_mbuf__bindgen_ty_3__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).lo) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2), + "::", + stringify!(lo) + ) + ); + } + test_field_lo(); + fn test_field_hi() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + rte_mbuf__bindgen_ty_3__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).hi) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2), + "::", + stringify!(hi) + ) + ); + } + test_field_hi(); } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_3() { @@ -651,66 +683,78 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3() { 4usize, concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_3)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rss) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(rss) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).fdir) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(fdir) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).sched) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(sched) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).usr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(usr) - ) - ); + fn test_field_rss() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rss) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3), + "::", + stringify!(rss) + ) + ); + } + test_field_rss(); + fn test_field_fdir() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).fdir) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3), + "::", + stringify!(fdir) + ) + ); + } + test_field_fdir(); + fn test_field_sched() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).sched) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3), + "::", + stringify!(sched) + ) + ); + } + test_field_sched(); + fn test_field_usr() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).usr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3), + "::", + stringify!(usr) + ) + ); + } + test_field_usr(); } impl Default for rte_mbuf__bindgen_ty_3 { fn default() -> Self { @@ -741,36 +785,42 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_4() { 8usize, concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_4)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).userdata) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_4), - "::", - stringify!(userdata) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).udata64) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_4), - "::", - stringify!(udata64) - ) - ); + fn test_field_userdata() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).userdata) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_4), + "::", + stringify!(userdata) + ) + ); + } + test_field_userdata(); + fn test_field_udata64() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).udata64) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_4), + "::", + stringify!(udata64) + ) + ); + } + test_field_udata64(); } impl Default for rte_mbuf__bindgen_ty_4 { fn default() -> Self { @@ -945,21 +995,24 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_5() { 8usize, concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_5)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).tx_offload) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_5), - "::", - stringify!(tx_offload) - ) - ); + fn test_field_tx_offload() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tx_offload) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_5), + "::", + stringify!(tx_offload) + ) + ); + } + test_field_tx_offload(); } impl Default for rte_mbuf__bindgen_ty_5 { fn default() -> Self { @@ -982,301 +1035,366 @@ fn bindgen_test_layout_rte_mbuf() { 64usize, concat!("Alignment of ", stringify!(rte_mbuf)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).cacheline0) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(cacheline0) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).buf_addr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(buf_addr) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).buf_physaddr) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(buf_physaddr) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).buf_len) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(buf_len) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rearm_data) as usize - ptr as usize - }, - 18usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(rearm_data) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).data_off) as usize - ptr as usize - }, - 18usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(data_off) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_segs) as usize - ptr as usize - }, - 22usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(nb_segs) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).port) as usize - ptr as usize - }, - 23usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(port) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ol_flags) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(ol_flags) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rx_descriptor_fields1) as usize - - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(rx_descriptor_fields1) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pkt_len) as usize - ptr as usize - }, - 36usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(pkt_len) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).data_len) as usize - ptr as usize - }, - 40usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(data_len) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).vlan_tci) as usize - ptr as usize - }, - 42usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(vlan_tci) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).hash) as usize - ptr as usize - }, - 44usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(hash) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).seqn) as usize - ptr as usize - }, - 52usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(seqn) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).vlan_tci_outer) as usize - ptr as usize - }, - 56usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(vlan_tci_outer) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).cacheline1) as usize - ptr as usize - }, - 64usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(cacheline1) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pool) as usize - ptr as usize - }, - 72usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(pool) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize - }, - 80usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(next) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).priv_size) as usize - ptr as usize - }, - 96usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(priv_size) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).timesync) as usize - ptr as usize - }, - 98usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(timesync) - ) - ); + fn test_field_cacheline0() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).cacheline0) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(cacheline0) + ) + ); + } + test_field_cacheline0(); + fn test_field_buf_addr() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).buf_addr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(buf_addr) + ) + ); + } + test_field_buf_addr(); + fn test_field_buf_physaddr() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).buf_physaddr) as usize - + ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(buf_physaddr) + ) + ); + } + test_field_buf_physaddr(); + fn test_field_buf_len() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).buf_len) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(buf_len) + ) + ); + } + test_field_buf_len(); + fn test_field_rearm_data() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rearm_data) as usize - ptr as usize + }, + 18usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(rearm_data) + ) + ); + } + test_field_rearm_data(); + fn test_field_data_off() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).data_off) as usize - ptr as usize + }, + 18usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(data_off) + ) + ); + } + test_field_data_off(); + fn test_field_nb_segs() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_segs) as usize - ptr as usize + }, + 22usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(nb_segs) + ) + ); + } + test_field_nb_segs(); + fn test_field_port() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).port) as usize - ptr as usize + }, + 23usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(port) + ) + ); + } + test_field_port(); + fn test_field_ol_flags() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ol_flags) as usize - ptr as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(ol_flags) + ) + ); + } + test_field_ol_flags(); + fn test_field_rx_descriptor_fields1() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rx_descriptor_fields1) as usize - + ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(rx_descriptor_fields1) + ) + ); + } + test_field_rx_descriptor_fields1(); + fn test_field_pkt_len() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pkt_len) as usize - ptr as usize + }, + 36usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(pkt_len) + ) + ); + } + test_field_pkt_len(); + fn test_field_data_len() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).data_len) as usize - ptr as usize + }, + 40usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(data_len) + ) + ); + } + test_field_data_len(); + fn test_field_vlan_tci() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).vlan_tci) as usize - ptr as usize + }, + 42usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(vlan_tci) + ) + ); + } + test_field_vlan_tci(); + fn test_field_hash() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).hash) as usize - ptr as usize + }, + 44usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(hash) + ) + ); + } + test_field_hash(); + fn test_field_seqn() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).seqn) as usize - ptr as usize + }, + 52usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(seqn) + ) + ); + } + test_field_seqn(); + fn test_field_vlan_tci_outer() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).vlan_tci_outer) as usize - + ptr as usize + }, + 56usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(vlan_tci_outer) + ) + ); + } + test_field_vlan_tci_outer(); + fn test_field_cacheline1() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).cacheline1) as usize - ptr as usize + }, + 64usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(cacheline1) + ) + ); + } + test_field_cacheline1(); + fn test_field_pool() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pool) as usize - ptr as usize + }, + 72usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(pool) + ) + ); + } + test_field_pool(); + fn test_field_next() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize + }, + 80usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(next) + ) + ); + } + test_field_next(); + fn test_field_priv_size() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).priv_size) as usize - ptr as usize + }, + 96usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(priv_size) + ) + ); + } + test_field_priv_size(); + fn test_field_timesync() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).timesync) as usize - ptr as usize + }, + 98usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(timesync) + ) + ); + } + test_field_timesync(); } impl Default for rte_mbuf { fn default() -> Self { diff --git a/tests/expectations/tests/layout_mbuf_1_0.rs b/tests/expectations/tests/layout_mbuf_1_0.rs index 0dbcf8e942..b9fddeb3cb 100644 --- a/tests/expectations/tests/layout_mbuf_1_0.rs +++ b/tests/expectations/tests/layout_mbuf_1_0.rs @@ -159,20 +159,24 @@ fn bindgen_test_layout_rte_atomic16_t() { 2usize, concat!("Alignment of ", stringify!(rte_atomic16_t)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).cnt) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_atomic16_t), - "::", - stringify!(cnt) - ) - ); + fn test_field_cnt() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).cnt) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_atomic16_t), + "::", + stringify!(cnt) + ) + ); + } + test_field_cnt(); } impl Clone for rte_atomic16_t { fn clone(&self) -> Self { @@ -253,36 +257,43 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_1() { 2usize, concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).refcnt_atomic) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_1), - "::", - stringify!(refcnt_atomic) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).refcnt) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_1), - "::", - stringify!(refcnt) - ) - ); + fn test_field_refcnt_atomic() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).refcnt_atomic) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_1), + "::", + stringify!(refcnt_atomic) + ) + ); + } + test_field_refcnt_atomic(); + fn test_field_refcnt() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).refcnt) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_1), + "::", + stringify!(refcnt) + ) + ); + } + test_field_refcnt(); } impl Clone for rte_mbuf__bindgen_ty_1 { fn clone(&self) -> Self { @@ -479,21 +490,24 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_2() { 4usize, concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_2)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).packet_type) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_2), - "::", - stringify!(packet_type) - ) - ); + fn test_field_packet_type() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).packet_type) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_2), + "::", + stringify!(packet_type) + ) + ); + } + test_field_packet_type(); } impl Clone for rte_mbuf__bindgen_ty_2 { fn clone(&self) -> Self { @@ -539,8 +553,14 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindg ) { assert_eq ! (:: std :: mem :: size_of :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > () , 4usize , concat ! ("Size of: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1))); assert_eq ! (:: std :: mem :: align_of :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > () , 2usize , concat ! ("Alignment of " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1))); - assert_eq ! (unsafe { let uninit = :: std :: mem :: MaybeUninit :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > :: uninit () ; let ptr = uninit . as_ptr () ; :: std :: ptr :: addr_of ! ((* ptr) . hash) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (hash))); - assert_eq ! (unsafe { let uninit = :: std :: mem :: MaybeUninit :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > :: uninit () ; let ptr = uninit . as_ptr () ; :: std :: ptr :: addr_of ! ((* ptr) . id) as usize - ptr as usize } , 2usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (id))); + fn test_field_hash() { + assert_eq ! (unsafe { let uninit = :: std :: mem :: MaybeUninit :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > :: uninit () ; let ptr = uninit . as_ptr () ; :: std :: ptr :: addr_of ! ((* ptr) . hash) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (hash))); + } + test_field_hash(); + fn test_field_id() { + assert_eq ! (unsafe { let uninit = :: std :: mem :: MaybeUninit :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > :: uninit () ; let ptr = uninit . as_ptr () ; :: std :: ptr :: addr_of ! ((* ptr) . id) as usize - ptr as usize } , 2usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (id))); + } + test_field_id(); } impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 @@ -570,22 +590,25 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1() { stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1) ) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).lo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(lo) - ) - ); + fn test_field_lo() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).lo) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(lo) + ) + ); + } + test_field_lo(); } impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 { fn clone(&self) -> Self { @@ -610,22 +633,25 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1() { stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1) ) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_mbuf__bindgen_ty_3__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).hi) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1), - "::", - stringify!(hi) - ) - ); + fn test_field_hi() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + rte_mbuf__bindgen_ty_3__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).hi) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1), + "::", + stringify!(hi) + ) + ); + } + test_field_hi(); } impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_1 { fn clone(&self) -> Self { @@ -656,38 +682,44 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_2() { stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2) ) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_mbuf__bindgen_ty_3__bindgen_ty_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).lo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2), - "::", - stringify!(lo) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_mbuf__bindgen_ty_3__bindgen_ty_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).hi) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2), - "::", - stringify!(hi) - ) - ); + fn test_field_lo() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + rte_mbuf__bindgen_ty_3__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).lo) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2), + "::", + stringify!(lo) + ) + ); + } + test_field_lo(); + fn test_field_hi() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + rte_mbuf__bindgen_ty_3__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).hi) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2), + "::", + stringify!(hi) + ) + ); + } + test_field_hi(); } impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_2 { fn clone(&self) -> Self { @@ -706,66 +738,78 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3() { 4usize, concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_3)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rss) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(rss) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).fdir) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(fdir) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).sched) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(sched) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).usr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(usr) - ) - ); + fn test_field_rss() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rss) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3), + "::", + stringify!(rss) + ) + ); + } + test_field_rss(); + fn test_field_fdir() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).fdir) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3), + "::", + stringify!(fdir) + ) + ); + } + test_field_fdir(); + fn test_field_sched() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).sched) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3), + "::", + stringify!(sched) + ) + ); + } + test_field_sched(); + fn test_field_usr() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).usr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3), + "::", + stringify!(usr) + ) + ); + } + test_field_usr(); } impl Clone for rte_mbuf__bindgen_ty_3 { fn clone(&self) -> Self { @@ -793,36 +837,42 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_4() { 8usize, concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_4)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).userdata) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_4), - "::", - stringify!(userdata) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).udata64) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_4), - "::", - stringify!(udata64) - ) - ); + fn test_field_userdata() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).userdata) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_4), + "::", + stringify!(userdata) + ) + ); + } + test_field_userdata(); + fn test_field_udata64() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).udata64) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_4), + "::", + stringify!(udata64) + ) + ); + } + test_field_udata64(); } impl Clone for rte_mbuf__bindgen_ty_4 { fn clone(&self) -> Self { @@ -1000,21 +1050,24 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_5() { 8usize, concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_5)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).tx_offload) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_5), - "::", - stringify!(tx_offload) - ) - ); + fn test_field_tx_offload() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tx_offload) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_5), + "::", + stringify!(tx_offload) + ) + ); + } + test_field_tx_offload(); } impl Clone for rte_mbuf__bindgen_ty_5 { fn clone(&self) -> Self { @@ -1028,301 +1081,366 @@ fn bindgen_test_layout_rte_mbuf() { 128usize, concat!("Size of: ", stringify!(rte_mbuf)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).cacheline0) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(cacheline0) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).buf_addr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(buf_addr) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).buf_physaddr) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(buf_physaddr) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).buf_len) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(buf_len) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rearm_data) as usize - ptr as usize - }, - 18usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(rearm_data) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).data_off) as usize - ptr as usize - }, - 18usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(data_off) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_segs) as usize - ptr as usize - }, - 22usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(nb_segs) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).port) as usize - ptr as usize - }, - 23usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(port) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ol_flags) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(ol_flags) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rx_descriptor_fields1) as usize - - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(rx_descriptor_fields1) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pkt_len) as usize - ptr as usize - }, - 36usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(pkt_len) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).data_len) as usize - ptr as usize - }, - 40usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(data_len) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).vlan_tci) as usize - ptr as usize - }, - 42usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(vlan_tci) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).hash) as usize - ptr as usize - }, - 44usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(hash) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).seqn) as usize - ptr as usize - }, - 52usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(seqn) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).vlan_tci_outer) as usize - ptr as usize - }, - 56usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(vlan_tci_outer) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).cacheline1) as usize - ptr as usize - }, - 64usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(cacheline1) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pool) as usize - ptr as usize - }, - 72usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(pool) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize - }, - 80usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(next) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).priv_size) as usize - ptr as usize - }, - 96usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(priv_size) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).timesync) as usize - ptr as usize - }, - 98usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(timesync) - ) - ); + fn test_field_cacheline0() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).cacheline0) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(cacheline0) + ) + ); + } + test_field_cacheline0(); + fn test_field_buf_addr() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).buf_addr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(buf_addr) + ) + ); + } + test_field_buf_addr(); + fn test_field_buf_physaddr() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).buf_physaddr) as usize - + ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(buf_physaddr) + ) + ); + } + test_field_buf_physaddr(); + fn test_field_buf_len() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).buf_len) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(buf_len) + ) + ); + } + test_field_buf_len(); + fn test_field_rearm_data() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rearm_data) as usize - ptr as usize + }, + 18usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(rearm_data) + ) + ); + } + test_field_rearm_data(); + fn test_field_data_off() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).data_off) as usize - ptr as usize + }, + 18usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(data_off) + ) + ); + } + test_field_data_off(); + fn test_field_nb_segs() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_segs) as usize - ptr as usize + }, + 22usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(nb_segs) + ) + ); + } + test_field_nb_segs(); + fn test_field_port() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).port) as usize - ptr as usize + }, + 23usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(port) + ) + ); + } + test_field_port(); + fn test_field_ol_flags() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ol_flags) as usize - ptr as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(ol_flags) + ) + ); + } + test_field_ol_flags(); + fn test_field_rx_descriptor_fields1() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rx_descriptor_fields1) as usize - + ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(rx_descriptor_fields1) + ) + ); + } + test_field_rx_descriptor_fields1(); + fn test_field_pkt_len() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pkt_len) as usize - ptr as usize + }, + 36usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(pkt_len) + ) + ); + } + test_field_pkt_len(); + fn test_field_data_len() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).data_len) as usize - ptr as usize + }, + 40usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(data_len) + ) + ); + } + test_field_data_len(); + fn test_field_vlan_tci() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).vlan_tci) as usize - ptr as usize + }, + 42usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(vlan_tci) + ) + ); + } + test_field_vlan_tci(); + fn test_field_hash() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).hash) as usize - ptr as usize + }, + 44usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(hash) + ) + ); + } + test_field_hash(); + fn test_field_seqn() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).seqn) as usize - ptr as usize + }, + 52usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(seqn) + ) + ); + } + test_field_seqn(); + fn test_field_vlan_tci_outer() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).vlan_tci_outer) as usize - + ptr as usize + }, + 56usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(vlan_tci_outer) + ) + ); + } + test_field_vlan_tci_outer(); + fn test_field_cacheline1() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).cacheline1) as usize - ptr as usize + }, + 64usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(cacheline1) + ) + ); + } + test_field_cacheline1(); + fn test_field_pool() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).pool) as usize - ptr as usize + }, + 72usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(pool) + ) + ); + } + test_field_pool(); + fn test_field_next() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize + }, + 80usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(next) + ) + ); + } + test_field_next(); + fn test_field_priv_size() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).priv_size) as usize - ptr as usize + }, + 96usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(priv_size) + ) + ); + } + test_field_priv_size(); + fn test_field_timesync() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).timesync) as usize - ptr as usize + }, + 98usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(timesync) + ) + ); + } + test_field_timesync(); } impl Default for rte_mbuf { fn default() -> Self { diff --git a/tests/expectations/tests/libclang-5/call-conv-field.rs b/tests/expectations/tests/libclang-5/call-conv-field.rs index c8060c9d0b..f83181ea0b 100644 --- a/tests/expectations/tests/libclang-5/call-conv-field.rs +++ b/tests/expectations/tests/libclang-5/call-conv-field.rs @@ -28,36 +28,42 @@ fn bindgen_test_layout_JNINativeInterface_() { 8usize, concat!("Alignment of ", stringify!(JNINativeInterface_)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).GetVersion) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(JNINativeInterface_), - "::", - stringify!(GetVersion) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).__hack) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(JNINativeInterface_), - "::", - stringify!(__hack) - ) - ); + fn test_field_GetVersion() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).GetVersion) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(JNINativeInterface_), + "::", + stringify!(GetVersion) + ) + ); + } + test_field_GetVersion(); + fn test_field___hack() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).__hack) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(JNINativeInterface_), + "::", + stringify!(__hack) + ) + ); + } + test_field___hack(); } extern "stdcall" { pub fn bar(); diff --git a/tests/expectations/tests/libclang-5/type_alias_template_specialized.rs b/tests/expectations/tests/libclang-5/type_alias_template_specialized.rs index 16bd02e44c..213d4cd685 100644 --- a/tests/expectations/tests/libclang-5/type_alias_template_specialized.rs +++ b/tests/expectations/tests/libclang-5/type_alias_template_specialized.rs @@ -22,20 +22,23 @@ fn bindgen_test_layout_Rooted() { 4usize, concat!("Alignment of ", stringify!(Rooted)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Rooted), - "::", - stringify!(ptr) - ) - ); + fn test_field_ptr() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Rooted), + "::", + stringify!(ptr) + ) + ); + } + test_field_ptr(); } impl Default for Rooted { fn default() -> Self { diff --git a/tests/expectations/tests/libclang-9/call-conv-field.rs b/tests/expectations/tests/libclang-9/call-conv-field.rs index c8060c9d0b..f83181ea0b 100644 --- a/tests/expectations/tests/libclang-9/call-conv-field.rs +++ b/tests/expectations/tests/libclang-9/call-conv-field.rs @@ -28,36 +28,42 @@ fn bindgen_test_layout_JNINativeInterface_() { 8usize, concat!("Alignment of ", stringify!(JNINativeInterface_)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).GetVersion) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(JNINativeInterface_), - "::", - stringify!(GetVersion) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).__hack) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(JNINativeInterface_), - "::", - stringify!(__hack) - ) - ); + fn test_field_GetVersion() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).GetVersion) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(JNINativeInterface_), + "::", + stringify!(GetVersion) + ) + ); + } + test_field_GetVersion(); + fn test_field___hack() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).__hack) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(JNINativeInterface_), + "::", + stringify!(__hack) + ) + ); + } + test_field___hack(); } extern "stdcall" { pub fn bar(); diff --git a/tests/expectations/tests/libclang-9/class.rs b/tests/expectations/tests/libclang-9/class.rs index 117cc815b8..82ab6806f2 100644 --- a/tests/expectations/tests/libclang-9/class.rs +++ b/tests/expectations/tests/libclang-9/class.rs @@ -53,29 +53,35 @@ fn bindgen_test_layout_C() { 4usize, concat!("Alignment of ", stringify!(C)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(a)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(big_array) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(a)) + ); + } + test_field_a(); + fn test_field_big_array() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(big_array) + ) + ); + } + test_field_big_array(); } impl Default for C { fn default() -> Self { @@ -104,52 +110,64 @@ fn bindgen_test_layout_C_with_zero_length_array() { 4usize, concat!("Alignment of ", stringify!(C_with_zero_length_array)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(big_array) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize - }, - 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(zero_length_array) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array), + "::", + stringify!(a) + ) + ); + } + test_field_a(); + fn test_field_big_array() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array), + "::", + stringify!(big_array) + ) + ); + } + test_field_big_array(); + fn test_field_zero_length_array() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - + ptr as usize + }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array), + "::", + stringify!(zero_length_array) + ) + ); + } + test_field_zero_length_array(); } impl Default for C_with_zero_length_array { fn default() -> Self { @@ -178,37 +196,45 @@ fn bindgen_test_layout_C_with_zero_length_array_2() { 4usize, concat!("Alignment of ", stringify!(C_with_zero_length_array_2)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_2), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_2), - "::", - stringify!(zero_length_array) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + C_with_zero_length_array_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_2), + "::", + stringify!(a) + ) + ); + } + test_field_a(); + fn test_field_zero_length_array() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + C_with_zero_length_array_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_2), + "::", + stringify!(zero_length_array) + ) + ); + } + test_field_zero_length_array(); } #[repr(C)] pub struct C_with_incomplete_array { @@ -228,52 +254,64 @@ fn bindgen_test_layout_C_with_incomplete_array() { 4usize, concat!("Alignment of ", stringify!(C_with_incomplete_array)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array), - "::", - stringify!(big_array) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - - ptr as usize - }, - 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array), - "::", - stringify!(incomplete_array) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array), + "::", + stringify!(a) + ) + ); + } + test_field_a(); + fn test_field_big_array() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array), + "::", + stringify!(big_array) + ) + ); + } + test_field_big_array(); + fn test_field_incomplete_array() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - + ptr as usize + }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array), + "::", + stringify!(incomplete_array) + ) + ); + } + test_field_incomplete_array(); } impl Default for C_with_incomplete_array { fn default() -> Self { @@ -302,37 +340,41 @@ fn bindgen_test_layout_C_with_incomplete_array_2() { 4usize, concat!("Alignment of ", stringify!(C_with_incomplete_array_2)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array_2), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array_2), - "::", - stringify!(incomplete_array) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = :: std :: mem :: MaybeUninit :: < C_with_incomplete_array_2 > :: uninit () ; + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array_2), + "::", + stringify!(a) + ) + ); + } + test_field_a(); + fn test_field_incomplete_array() { + assert_eq!( + unsafe { + let uninit = :: std :: mem :: MaybeUninit :: < C_with_incomplete_array_2 > :: uninit () ; + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array_2), + "::", + stringify!(incomplete_array) + ) + ); + } + test_field_incomplete_array(); } #[repr(C)] pub struct C_with_zero_length_array_and_incomplete_array { @@ -359,72 +401,84 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { stringify!(C_with_zero_length_array_and_incomplete_array) ) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C_with_zero_length_array_and_incomplete_array, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C_with_zero_length_array_and_incomplete_array, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(big_array) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C_with_zero_length_array_and_incomplete_array, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize - }, - 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(zero_length_array) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C_with_zero_length_array_and_incomplete_array, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - - ptr as usize - }, - 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(incomplete_array) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + C_with_zero_length_array_and_incomplete_array, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(a) + ) + ); + } + test_field_a(); + fn test_field_big_array() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + C_with_zero_length_array_and_incomplete_array, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(big_array) + ) + ); + } + test_field_big_array(); + fn test_field_zero_length_array() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + C_with_zero_length_array_and_incomplete_array, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - + ptr as usize + }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(zero_length_array) + ) + ); + } + test_field_zero_length_array(); + fn test_field_incomplete_array() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + C_with_zero_length_array_and_incomplete_array, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - + ptr as usize + }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(incomplete_array) + ) + ); + } + test_field_incomplete_array(); } impl Default for C_with_zero_length_array_and_incomplete_array { fn default() -> Self { @@ -462,56 +516,65 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { stringify!(C_with_zero_length_array_and_incomplete_array_2) ) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C_with_zero_length_array_and_incomplete_array_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C_with_zero_length_array_and_incomplete_array_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), - "::", - stringify!(zero_length_array) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C_with_zero_length_array_and_incomplete_array_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), - "::", - stringify!(incomplete_array) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + C_with_zero_length_array_and_incomplete_array_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), + "::", + stringify!(a) + ) + ); + } + test_field_a(); + fn test_field_zero_length_array() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + C_with_zero_length_array_and_incomplete_array_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), + "::", + stringify!(zero_length_array) + ) + ); + } + test_field_zero_length_array(); + fn test_field_incomplete_array() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + C_with_zero_length_array_and_incomplete_array_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), + "::", + stringify!(incomplete_array) + ) + ); + } + test_field_incomplete_array(); } #[repr(C)] #[derive(Debug, Default, Hash, PartialOrd, Ord, PartialEq, Eq)] @@ -530,20 +593,23 @@ fn bindgen_test_layout_WithDtor() { 4usize, concat!("Alignment of ", stringify!(WithDtor)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithDtor), - "::", - stringify!(b) - ) - ); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithDtor), + "::", + stringify!(b) + ) + ); + } + test_field_b(); } #[repr(C)] pub struct IncompleteArrayNonCopiable { @@ -562,37 +628,45 @@ fn bindgen_test_layout_IncompleteArrayNonCopiable() { 8usize, concat!("Alignment of ", stringify!(IncompleteArrayNonCopiable)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).whatever) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(IncompleteArrayNonCopiable), - "::", - stringify!(whatever) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(IncompleteArrayNonCopiable), - "::", - stringify!(incomplete_array) - ) - ); + fn test_field_whatever() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + IncompleteArrayNonCopiable, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).whatever) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(IncompleteArrayNonCopiable), + "::", + stringify!(whatever) + ) + ); + } + test_field_whatever(); + fn test_field_incomplete_array() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + IncompleteArrayNonCopiable, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - + ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(IncompleteArrayNonCopiable), + "::", + stringify!(incomplete_array) + ) + ); + } + test_field_incomplete_array(); } impl Default for IncompleteArrayNonCopiable { fn default() -> Self { @@ -621,24 +695,40 @@ fn bindgen_test_layout_Union() { 4usize, concat!("Alignment of ", stringify!(Union)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Union), "::", stringify!(d)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Union), "::", stringify!(i)) - ); + fn test_field_d() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Union), + "::", + stringify!(d) + ) + ); + } + test_field_d(); + fn test_field_i() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Union), + "::", + stringify!(i) + ) + ); + } + test_field_i(); } impl Default for Union { fn default() -> Self { @@ -666,20 +756,23 @@ fn bindgen_test_layout_WithUnion() { 4usize, concat!("Alignment of ", stringify!(WithUnion)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithUnion), - "::", - stringify!(data) - ) - ); + fn test_field_data() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithUnion), + "::", + stringify!(data) + ) + ); + } + test_field_data(); } impl Default for WithUnion { fn default() -> Self { diff --git a/tests/expectations/tests/libclang-9/class_1_0.rs b/tests/expectations/tests/libclang-9/class_1_0.rs index 0a707d228f..604dde7b8e 100644 --- a/tests/expectations/tests/libclang-9/class_1_0.rs +++ b/tests/expectations/tests/libclang-9/class_1_0.rs @@ -96,29 +96,35 @@ fn bindgen_test_layout_C() { 4usize, concat!("Alignment of ", stringify!(C)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(a)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(big_array) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(a)) + ); + } + test_field_a(); + fn test_field_big_array() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(big_array) + ) + ); + } + test_field_big_array(); } impl Clone for C { fn clone(&self) -> Self { @@ -157,52 +163,64 @@ fn bindgen_test_layout_C_with_zero_length_array() { 4usize, concat!("Alignment of ", stringify!(C_with_zero_length_array)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(big_array) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize - }, - 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(zero_length_array) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array), + "::", + stringify!(a) + ) + ); + } + test_field_a(); + fn test_field_big_array() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array), + "::", + stringify!(big_array) + ) + ); + } + test_field_big_array(); + fn test_field_zero_length_array() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - + ptr as usize + }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array), + "::", + stringify!(zero_length_array) + ) + ); + } + test_field_zero_length_array(); } impl Default for C_with_zero_length_array { fn default() -> Self { @@ -231,37 +249,45 @@ fn bindgen_test_layout_C_with_zero_length_array_2() { 4usize, concat!("Alignment of ", stringify!(C_with_zero_length_array_2)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_2), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_2), - "::", - stringify!(zero_length_array) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + C_with_zero_length_array_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_2), + "::", + stringify!(a) + ) + ); + } + test_field_a(); + fn test_field_zero_length_array() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + C_with_zero_length_array_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_2), + "::", + stringify!(zero_length_array) + ) + ); + } + test_field_zero_length_array(); } #[repr(C)] pub struct C_with_incomplete_array { @@ -281,52 +307,64 @@ fn bindgen_test_layout_C_with_incomplete_array() { 4usize, concat!("Alignment of ", stringify!(C_with_incomplete_array)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array), - "::", - stringify!(big_array) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - - ptr as usize - }, - 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array), - "::", - stringify!(incomplete_array) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array), + "::", + stringify!(a) + ) + ); + } + test_field_a(); + fn test_field_big_array() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array), + "::", + stringify!(big_array) + ) + ); + } + test_field_big_array(); + fn test_field_incomplete_array() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit( + ); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - + ptr as usize + }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array), + "::", + stringify!(incomplete_array) + ) + ); + } + test_field_incomplete_array(); } impl Default for C_with_incomplete_array { fn default() -> Self { @@ -355,37 +393,41 @@ fn bindgen_test_layout_C_with_incomplete_array_2() { 4usize, concat!("Alignment of ", stringify!(C_with_incomplete_array_2)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array_2), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array_2), - "::", - stringify!(incomplete_array) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = :: std :: mem :: MaybeUninit :: < C_with_incomplete_array_2 > :: uninit () ; + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array_2), + "::", + stringify!(a) + ) + ); + } + test_field_a(); + fn test_field_incomplete_array() { + assert_eq!( + unsafe { + let uninit = :: std :: mem :: MaybeUninit :: < C_with_incomplete_array_2 > :: uninit () ; + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array_2), + "::", + stringify!(incomplete_array) + ) + ); + } + test_field_incomplete_array(); } #[repr(C)] pub struct C_with_zero_length_array_and_incomplete_array { @@ -412,72 +454,84 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { stringify!(C_with_zero_length_array_and_incomplete_array) ) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C_with_zero_length_array_and_incomplete_array, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C_with_zero_length_array_and_incomplete_array, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(big_array) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C_with_zero_length_array_and_incomplete_array, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize - }, - 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(zero_length_array) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C_with_zero_length_array_and_incomplete_array, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - - ptr as usize - }, - 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(incomplete_array) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + C_with_zero_length_array_and_incomplete_array, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(a) + ) + ); + } + test_field_a(); + fn test_field_big_array() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + C_with_zero_length_array_and_incomplete_array, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(big_array) + ) + ); + } + test_field_big_array(); + fn test_field_zero_length_array() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + C_with_zero_length_array_and_incomplete_array, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - + ptr as usize + }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(zero_length_array) + ) + ); + } + test_field_zero_length_array(); + fn test_field_incomplete_array() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + C_with_zero_length_array_and_incomplete_array, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - + ptr as usize + }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(incomplete_array) + ) + ); + } + test_field_incomplete_array(); } impl Default for C_with_zero_length_array_and_incomplete_array { fn default() -> Self { @@ -515,56 +569,65 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { stringify!(C_with_zero_length_array_and_incomplete_array_2) ) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C_with_zero_length_array_and_incomplete_array_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C_with_zero_length_array_and_incomplete_array_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), - "::", - stringify!(zero_length_array) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C_with_zero_length_array_and_incomplete_array_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), - "::", - stringify!(incomplete_array) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + C_with_zero_length_array_and_incomplete_array_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), + "::", + stringify!(a) + ) + ); + } + test_field_a(); + fn test_field_zero_length_array() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + C_with_zero_length_array_and_incomplete_array_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), + "::", + stringify!(zero_length_array) + ) + ); + } + test_field_zero_length_array(); + fn test_field_incomplete_array() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + C_with_zero_length_array_and_incomplete_array_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), + "::", + stringify!(incomplete_array) + ) + ); + } + test_field_incomplete_array(); } #[repr(C)] #[derive(Debug, Default, Hash, PartialEq, Eq)] @@ -583,20 +646,23 @@ fn bindgen_test_layout_WithDtor() { 4usize, concat!("Alignment of ", stringify!(WithDtor)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithDtor), - "::", - stringify!(b) - ) - ); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithDtor), + "::", + stringify!(b) + ) + ); + } + test_field_b(); } #[repr(C)] pub struct IncompleteArrayNonCopiable { @@ -615,37 +681,45 @@ fn bindgen_test_layout_IncompleteArrayNonCopiable() { 8usize, concat!("Alignment of ", stringify!(IncompleteArrayNonCopiable)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).whatever) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(IncompleteArrayNonCopiable), - "::", - stringify!(whatever) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(IncompleteArrayNonCopiable), - "::", - stringify!(incomplete_array) - ) - ); + fn test_field_whatever() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + IncompleteArrayNonCopiable, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).whatever) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(IncompleteArrayNonCopiable), + "::", + stringify!(whatever) + ) + ); + } + test_field_whatever(); + fn test_field_incomplete_array() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + IncompleteArrayNonCopiable, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - + ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(IncompleteArrayNonCopiable), + "::", + stringify!(incomplete_array) + ) + ); + } + test_field_incomplete_array(); } impl Default for IncompleteArrayNonCopiable { fn default() -> Self { @@ -675,24 +749,40 @@ fn bindgen_test_layout_Union() { 4usize, concat!("Alignment of ", stringify!(Union)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Union), "::", stringify!(d)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Union), "::", stringify!(i)) - ); + fn test_field_d() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Union), + "::", + stringify!(d) + ) + ); + } + test_field_d(); + fn test_field_i() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Union), + "::", + stringify!(i) + ) + ); + } + test_field_i(); } impl Clone for Union { fn clone(&self) -> Self { @@ -716,20 +806,23 @@ fn bindgen_test_layout_WithUnion() { 4usize, concat!("Alignment of ", stringify!(WithUnion)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithUnion), - "::", - stringify!(data) - ) - ); + fn test_field_data() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithUnion), + "::", + stringify!(data) + ) + ); + } + test_field_data(); } impl Clone for WithUnion { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs b/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs index 42de2d7748..2365d9a3c2 100644 --- a/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs +++ b/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs @@ -53,30 +53,36 @@ fn bindgen_test_layout_test() { 4usize, concat!("Alignment of ", stringify!(test)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(test), "::", stringify!(a)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(test), - "::", - stringify!(zero_length_array) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(test), "::", stringify!(a)) + ); + } + test_field_a(); + fn test_field_zero_length_array() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(test), + "::", + stringify!(zero_length_array) + ) + ); + } + test_field_zero_length_array(); } #[repr(C)] #[derive(Debug, Default)] @@ -96,30 +102,41 @@ fn bindgen_test_layout_test2() { 4usize, concat!("Alignment of ", stringify!(test2)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(test2), "::", stringify!(a)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(test2), - "::", - stringify!(incomplete_array) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(test2), + "::", + stringify!(a) + ) + ); + } + test_field_a(); + fn test_field_incomplete_array() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(test2), + "::", + stringify!(incomplete_array) + ) + ); + } + test_field_incomplete_array(); } #[repr(C)] #[derive(Debug, Default)] @@ -140,43 +157,57 @@ fn bindgen_test_layout_test3() { 4usize, concat!("Alignment of ", stringify!(test3)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(test3), "::", stringify!(a)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(test3), - "::", - stringify!(zero_length_array) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(test3), - "::", - stringify!(incomplete_array) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(test3), + "::", + stringify!(a) + ) + ); + } + test_field_a(); + fn test_field_zero_length_array() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(test3), + "::", + stringify!(zero_length_array) + ) + ); + } + test_field_zero_length_array(); + fn test_field_incomplete_array() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(test3), + "::", + stringify!(incomplete_array) + ) + ); + } + test_field_incomplete_array(); } diff --git a/tests/expectations/tests/libclang-9/incomplete-array-padding.rs b/tests/expectations/tests/libclang-9/incomplete-array-padding.rs index ba1f9ce05d..d796cc6031 100644 --- a/tests/expectations/tests/libclang-9/incomplete-array-padding.rs +++ b/tests/expectations/tests/libclang-9/incomplete-array-padding.rs @@ -140,15 +140,18 @@ fn bindgen_test_layout_foo() { 8usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 8usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) - ); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 8usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) + ); + } + test_field_b(); } impl Default for foo { fn default() -> Self { diff --git a/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs b/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs index 91c3771129..53f125486f 100644 --- a/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs +++ b/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs @@ -60,20 +60,23 @@ fn bindgen_test_layout_rte_ring_prod() { 4usize, concat!("Alignment of ", stringify!(rte_ring_prod)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).watermark) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ring_prod), - "::", - stringify!(watermark) - ) - ); + fn test_field_watermark() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).watermark) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ring_prod), + "::", + stringify!(watermark) + ) + ); + } + test_field_watermark(); } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -92,20 +95,23 @@ fn bindgen_test_layout_rte_ring_cons() { 4usize, concat!("Alignment of ", stringify!(rte_ring_cons)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).sc_dequeue) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ring_cons), - "::", - stringify!(sc_dequeue) - ) - ); + fn test_field_sc_dequeue() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).sc_dequeue) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ring_cons), + "::", + stringify!(sc_dequeue) + ) + ); + } + test_field_sc_dequeue(); } #[test] fn bindgen_test_layout_rte_ring() { @@ -119,62 +125,74 @@ fn bindgen_test_layout_rte_ring() { 8usize, concat!("Alignment of ", stringify!(rte_ring)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).memzone) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ring), - "::", - stringify!(memzone) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).prod) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_ring), - "::", - stringify!(prod) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).cons) as usize - ptr as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(rte_ring), - "::", - stringify!(cons) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ring) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_ring), - "::", - stringify!(ring) - ) - ); + fn test_field_memzone() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).memzone) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ring), + "::", + stringify!(memzone) + ) + ); + } + test_field_memzone(); + fn test_field_prod() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).prod) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_ring), + "::", + stringify!(prod) + ) + ); + } + test_field_prod(); + fn test_field_cons() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).cons) as usize - ptr as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(rte_ring), + "::", + stringify!(cons) + ) + ); + } + test_field_cons(); + fn test_field_ring() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ring) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_ring), + "::", + stringify!(ring) + ) + ); + } + test_field_ring(); } impl Default for rte_ring { fn default() -> Self { diff --git a/tests/expectations/tests/libclang-9/layout_align.rs b/tests/expectations/tests/libclang-9/layout_align.rs index fa5179aeb3..2ecbb6f9b0 100644 --- a/tests/expectations/tests/libclang-9/layout_align.rs +++ b/tests/expectations/tests/libclang-9/layout_align.rs @@ -147,76 +147,91 @@ fn bindgen_test_layout_rte_kni_fifo() { 8usize, concat!("Alignment of ", stringify!(rte_kni_fifo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).write) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_fifo), - "::", - stringify!(write) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).read) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_fifo), - "::", - stringify!(read) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_fifo), - "::", - stringify!(len) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).elem_size) as usize - ptr as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_fifo), - "::", - stringify!(elem_size) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).buffer) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_fifo), - "::", - stringify!(buffer) - ) - ); + fn test_field_write() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).write) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_fifo), + "::", + stringify!(write) + ) + ); + } + test_field_write(); + fn test_field_read() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).read) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_fifo), + "::", + stringify!(read) + ) + ); + } + test_field_read(); + fn test_field_len() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_fifo), + "::", + stringify!(len) + ) + ); + } + test_field_len(); + fn test_field_elem_size() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).elem_size) as usize - ptr as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_fifo), + "::", + stringify!(elem_size) + ) + ); + } + test_field_elem_size(); + fn test_field_buffer() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).buffer) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_fifo), + "::", + stringify!(buffer) + ) + ); + } + test_field_buffer(); } impl Default for rte_kni_fifo { fn default() -> Self { @@ -249,20 +264,23 @@ fn bindgen_test_layout_rte_eth_link() { 8usize, concat!("Alignment of ", stringify!(rte_eth_link)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).link_speed) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_link), - "::", - stringify!(link_speed) - ) - ); + fn test_field_link_speed() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).link_speed) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_link), + "::", + stringify!(link_speed) + ) + ); + } + test_field_link_speed(); } impl rte_eth_link { #[inline] diff --git a/tests/expectations/tests/libclang-9/type_alias_template_specialized.rs b/tests/expectations/tests/libclang-9/type_alias_template_specialized.rs index 16bd02e44c..213d4cd685 100644 --- a/tests/expectations/tests/libclang-9/type_alias_template_specialized.rs +++ b/tests/expectations/tests/libclang-9/type_alias_template_specialized.rs @@ -22,20 +22,23 @@ fn bindgen_test_layout_Rooted() { 4usize, concat!("Alignment of ", stringify!(Rooted)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Rooted), - "::", - stringify!(ptr) - ) - ); + fn test_field_ptr() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Rooted), + "::", + stringify!(ptr) + ) + ); + } + test_field_ptr(); } impl Default for Rooted { fn default() -> Self { diff --git a/tests/expectations/tests/libclang-9/zero-sized-array.rs b/tests/expectations/tests/libclang-9/zero-sized-array.rs index 1c2f242ffd..185b8e21ab 100644 --- a/tests/expectations/tests/libclang-9/zero-sized-array.rs +++ b/tests/expectations/tests/libclang-9/zero-sized-array.rs @@ -53,20 +53,24 @@ fn bindgen_test_layout_ZeroSizedArray() { 1usize, concat!("Alignment of ", stringify!(ZeroSizedArray)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ZeroSizedArray), - "::", - stringify!(arr) - ) - ); + fn test_field_arr() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ZeroSizedArray), + "::", + stringify!(arr) + ) + ); + } + test_field_arr(); } /// And nor should this get an `_address` field. #[repr(C)] @@ -86,21 +90,24 @@ fn bindgen_test_layout_ContainsZeroSizedArray() { 1usize, concat!("Alignment of ", stringify!(ContainsZeroSizedArray)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).zsa) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContainsZeroSizedArray), - "::", - stringify!(zsa) - ) - ); + fn test_field_zsa() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).zsa) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ContainsZeroSizedArray), + "::", + stringify!(zsa) + ) + ); + } + test_field_zsa(); } /// Inheriting from ZeroSizedArray shouldn't cause an `_address` to be inserted /// either. @@ -140,21 +147,24 @@ fn bindgen_test_layout_DynamicallySizedArray() { 1usize, concat!("Alignment of ", stringify!(DynamicallySizedArray)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(DynamicallySizedArray), - "::", - stringify!(arr) - ) - ); + fn test_field_arr() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(DynamicallySizedArray), + "::", + stringify!(arr) + ) + ); + } + test_field_arr(); } /// No `_address` field here either. #[repr(C)] @@ -174,18 +184,23 @@ fn bindgen_test_layout_ContainsDynamicallySizedArray() { 1usize, concat!("Alignment of ", stringify!(ContainsDynamicallySizedArray)) ); - assert_eq!( - unsafe { - let uninit = :: std :: mem :: MaybeUninit :: < ContainsDynamicallySizedArray > :: uninit () ; - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dsa) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContainsDynamicallySizedArray), - "::", - stringify!(dsa) - ) - ); + fn test_field_dsa() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + ContainsDynamicallySizedArray, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).dsa) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ContainsDynamicallySizedArray), + "::", + stringify!(dsa) + ) + ); + } + test_field_dsa(); } diff --git a/tests/expectations/tests/long_double.rs b/tests/expectations/tests/long_double.rs index f08438259d..7e2dfd2a31 100644 --- a/tests/expectations/tests/long_double.rs +++ b/tests/expectations/tests/long_double.rs @@ -23,13 +23,21 @@ fn bindgen_test_layout_foo() { 16usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) - ); + fn test_field_bar() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(bar) + ) + ); + } + test_field_bar(); } diff --git a/tests/expectations/tests/msvc-no-usr.rs b/tests/expectations/tests/msvc-no-usr.rs index b0ad37ca32..6e8a98c330 100644 --- a/tests/expectations/tests/msvc-no-usr.rs +++ b/tests/expectations/tests/msvc-no-usr.rs @@ -23,13 +23,16 @@ fn bindgen_test_layout_A() { 8usize, concat!("Alignment of ", stringify!(A)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(foo)) - ); + fn test_field_foo() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(A), "::", stringify!(foo)) + ); + } + test_field_foo(); } diff --git a/tests/expectations/tests/mutable.rs b/tests/expectations/tests/mutable.rs index 4f5d97ab9f..feae0609c1 100644 --- a/tests/expectations/tests/mutable.rs +++ b/tests/expectations/tests/mutable.rs @@ -23,34 +23,40 @@ fn bindgen_test_layout_C() { 4usize, concat!("Alignment of ", stringify!(C)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(m_member) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).m_other) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(m_other) - ) - ); + fn test_field_m_member() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(m_member) + ) + ); + } + test_field_m_member(); + fn test_field_m_other() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).m_other) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(m_other) + ) + ); + } + test_field_m_other(); } #[repr(C)] #[derive(Debug, Default)] @@ -69,20 +75,23 @@ fn bindgen_test_layout_NonCopiable() { 4usize, concat!("Alignment of ", stringify!(NonCopiable)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NonCopiable), - "::", - stringify!(m_member) - ) - ); + fn test_field_m_member() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(NonCopiable), + "::", + stringify!(m_member) + ) + ); + } + test_field_m_member(); } #[repr(C)] #[derive(Debug, Default)] @@ -107,20 +116,23 @@ fn bindgen_test_layout_NonCopiableWithNonCopiableMutableMember() { stringify!(NonCopiableWithNonCopiableMutableMember) ) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - NonCopiableWithNonCopiableMutableMember, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NonCopiableWithNonCopiableMutableMember), - "::", - stringify!(m_member) - ) - ); + fn test_field_m_member() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + NonCopiableWithNonCopiableMutableMember, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(NonCopiableWithNonCopiableMutableMember), + "::", + stringify!(m_member) + ) + ); + } + test_field_m_member(); } diff --git a/tests/expectations/tests/namespace.rs b/tests/expectations/tests/namespace.rs index 33e2118fb4..72c17ee64a 100644 --- a/tests/expectations/tests/namespace.rs +++ b/tests/expectations/tests/namespace.rs @@ -43,20 +43,23 @@ pub mod root { 4usize, concat!("Alignment of ", stringify!(A)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(A), - "::", - stringify!(b) - ) - ); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(A), + "::", + stringify!(b) + ) + ); + } + test_field_b(); } } #[repr(C)] diff --git a/tests/expectations/tests/nested.rs b/tests/expectations/tests/nested.rs index 558ccd6c13..48061e9be1 100644 --- a/tests/expectations/tests/nested.rs +++ b/tests/expectations/tests/nested.rs @@ -22,15 +22,18 @@ fn bindgen_test_layout_Calc() { 4usize, concat!("Alignment of ", stringify!(Calc)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).w) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Calc), "::", stringify!(w)) - ); + fn test_field_w() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).w) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Calc), "::", stringify!(w)) + ); + } + test_field_w(); } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -73,34 +76,40 @@ fn bindgen_test_layout_Test_Size() { 4usize, concat!("Alignment of ", stringify!(Test_Size)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mWidth) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Test_Size), - "::", - stringify!(mWidth) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mHeight) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(Test_Size), - "::", - stringify!(mHeight) - ) - ); + fn test_field_mWidth() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mWidth) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Test_Size), + "::", + stringify!(mWidth) + ) + ); + } + test_field_mWidth(); + fn test_field_mHeight() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mHeight) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(Test_Size), + "::", + stringify!(mHeight) + ) + ); + } + test_field_mHeight(); } #[test] fn bindgen_test_layout_Test() { diff --git a/tests/expectations/tests/nested_within_namespace.rs b/tests/expectations/tests/nested_within_namespace.rs index 8bb8559f4e..3e6e0466d2 100644 --- a/tests/expectations/tests/nested_within_namespace.rs +++ b/tests/expectations/tests/nested_within_namespace.rs @@ -34,20 +34,24 @@ pub mod root { 4usize, concat!("Alignment of ", stringify!(Bar_Baz)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar_Baz), - "::", - stringify!(foo) - ) - ); + fn test_field_foo() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Bar_Baz), + "::", + stringify!(foo) + ) + ); + } + test_field_foo(); } #[test] fn bindgen_test_layout_Bar() { @@ -61,20 +65,23 @@ pub mod root { 4usize, concat!("Alignment of ", stringify!(Bar)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(foo) - ) - ); + fn test_field_foo() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Bar), + "::", + stringify!(foo) + ) + ); + } + test_field_foo(); } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -93,20 +100,23 @@ pub mod root { 4usize, concat!("Alignment of ", stringify!(Baz)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Baz), - "::", - stringify!(baz) - ) - ); + fn test_field_baz() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Baz), + "::", + stringify!(baz) + ) + ); + } + test_field_baz(); } } } diff --git a/tests/expectations/tests/no-comments.rs b/tests/expectations/tests/no-comments.rs index 5c1cdc4387..f13b4f8b1d 100644 --- a/tests/expectations/tests/no-comments.rs +++ b/tests/expectations/tests/no-comments.rs @@ -22,13 +22,16 @@ fn bindgen_test_layout_Foo() { 4usize, concat!("Alignment of ", stringify!(Foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).s) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(s)) - ); + fn test_field_s() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).s) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(s)) + ); + } + test_field_s(); } diff --git a/tests/expectations/tests/no-derive-debug.rs b/tests/expectations/tests/no-derive-debug.rs index ffa372c297..2aa1c10280 100644 --- a/tests/expectations/tests/no-derive-debug.rs +++ b/tests/expectations/tests/no-derive-debug.rs @@ -31,24 +31,40 @@ fn bindgen_test_layout_bar() { 4usize, concat!("Alignment of ", stringify!(bar)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(bar), "::", stringify!(foo)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, - 4usize, - concat!("Offset of field: ", stringify!(bar), "::", stringify!(baz)) - ); + fn test_field_foo() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(bar), + "::", + stringify!(foo) + ) + ); + } + test_field_foo(); + fn test_field_baz() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(bar), + "::", + stringify!(baz) + ) + ); + } + test_field_baz(); } impl Default for bar { fn default() -> Self { diff --git a/tests/expectations/tests/no-derive-default.rs b/tests/expectations/tests/no-derive-default.rs index 82d630f5c3..6e5efbe60a 100644 --- a/tests/expectations/tests/no-derive-default.rs +++ b/tests/expectations/tests/no-derive-default.rs @@ -31,22 +31,38 @@ fn bindgen_test_layout_bar() { 4usize, concat!("Alignment of ", stringify!(bar)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(bar), "::", stringify!(foo)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, - 4usize, - concat!("Offset of field: ", stringify!(bar), "::", stringify!(baz)) - ); + fn test_field_foo() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(bar), + "::", + stringify!(foo) + ) + ); + } + test_field_foo(); + fn test_field_baz() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(bar), + "::", + stringify!(baz) + ) + ); + } + test_field_baz(); } diff --git a/tests/expectations/tests/no-hash-allowlisted.rs b/tests/expectations/tests/no-hash-allowlisted.rs index f060b729f1..43132cb052 100644 --- a/tests/expectations/tests/no-hash-allowlisted.rs +++ b/tests/expectations/tests/no-hash-allowlisted.rs @@ -22,13 +22,21 @@ fn bindgen_test_layout_NoHash() { 4usize, concat!("Alignment of ", stringify!(NoHash)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(NoHash), "::", stringify!(i)) - ); + fn test_field_i() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(NoHash), + "::", + stringify!(i) + ) + ); + } + test_field_i(); } diff --git a/tests/expectations/tests/no-partialeq-allowlisted.rs b/tests/expectations/tests/no-partialeq-allowlisted.rs index 758b4670be..e43e855727 100644 --- a/tests/expectations/tests/no-partialeq-allowlisted.rs +++ b/tests/expectations/tests/no-partialeq-allowlisted.rs @@ -22,18 +22,21 @@ fn bindgen_test_layout_NoPartialEq() { 4usize, concat!("Alignment of ", stringify!(NoPartialEq)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NoPartialEq), - "::", - stringify!(i) - ) - ); + fn test_field_i() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(NoPartialEq), + "::", + stringify!(i) + ) + ); + } + test_field_i(); } diff --git a/tests/expectations/tests/no-recursive-allowlisting.rs b/tests/expectations/tests/no-recursive-allowlisting.rs index 32907d6e8d..197b099dc1 100644 --- a/tests/expectations/tests/no-recursive-allowlisting.rs +++ b/tests/expectations/tests/no-recursive-allowlisting.rs @@ -24,15 +24,23 @@ fn bindgen_test_layout_Foo() { 8usize, concat!("Alignment of ", stringify!(Foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(baz)) - ); + fn test_field_baz() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Foo), + "::", + stringify!(baz) + ) + ); + } + test_field_baz(); } impl Default for Foo { fn default() -> Self { diff --git a/tests/expectations/tests/no-std.rs b/tests/expectations/tests/no-std.rs index 8fa4a4e594..f3157bbeea 100644 --- a/tests/expectations/tests/no-std.rs +++ b/tests/expectations/tests/no-std.rs @@ -29,33 +29,47 @@ fn bindgen_test_layout_foo() { 8usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { - let uninit = ::core::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::core::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) - ); - assert_eq!( - unsafe { - let uninit = ::core::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::core::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 4usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) - ); - assert_eq!( - unsafe { - let uninit = ::core::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 8usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::core::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::core::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) + ); + } + test_field_a(); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = ::core::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::core::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 4usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) + ); + } + test_field_b(); + fn test_field_bar() { + assert_eq!( + unsafe { + let uninit = ::core::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(bar) + ) + ); + } + test_field_bar(); } impl Default for foo { fn default() -> Self { diff --git a/tests/expectations/tests/no_copy_allowlisted.rs b/tests/expectations/tests/no_copy_allowlisted.rs index db895e488e..ae086d2133 100644 --- a/tests/expectations/tests/no_copy_allowlisted.rs +++ b/tests/expectations/tests/no_copy_allowlisted.rs @@ -22,13 +22,21 @@ fn bindgen_test_layout_NoCopy() { 4usize, concat!("Alignment of ", stringify!(NoCopy)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(NoCopy), "::", stringify!(i)) - ); + fn test_field_i() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(NoCopy), + "::", + stringify!(i) + ) + ); + } + test_field_i(); } diff --git a/tests/expectations/tests/no_debug_allowlisted.rs b/tests/expectations/tests/no_debug_allowlisted.rs index 6722fc995c..9f070d24af 100644 --- a/tests/expectations/tests/no_debug_allowlisted.rs +++ b/tests/expectations/tests/no_debug_allowlisted.rs @@ -22,18 +22,21 @@ fn bindgen_test_layout_NoDebug() { 4usize, concat!("Alignment of ", stringify!(NoDebug)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NoDebug), - "::", - stringify!(i) - ) - ); + fn test_field_i() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(NoDebug), + "::", + stringify!(i) + ) + ); + } + test_field_i(); } diff --git a/tests/expectations/tests/no_default_allowlisted.rs b/tests/expectations/tests/no_default_allowlisted.rs index 930c611454..07e01b72c8 100644 --- a/tests/expectations/tests/no_default_allowlisted.rs +++ b/tests/expectations/tests/no_default_allowlisted.rs @@ -22,18 +22,21 @@ fn bindgen_test_layout_NoDefault() { 4usize, concat!("Alignment of ", stringify!(NoDefault)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NoDefault), - "::", - stringify!(i) - ) - ); + fn test_field_i() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(NoDefault), + "::", + stringify!(i) + ) + ); + } + test_field_i(); } diff --git a/tests/expectations/tests/non-type-params.rs b/tests/expectations/tests/non-type-params.rs index 9572d69c8a..f6478528c3 100644 --- a/tests/expectations/tests/non-type-params.rs +++ b/tests/expectations/tests/non-type-params.rs @@ -26,46 +26,57 @@ fn bindgen_test_layout_UsesArray() { 4usize, concat!("Alignment of ", stringify!(UsesArray)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).array_char_16) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(UsesArray), - "::", - stringify!(array_char_16) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).array_bool_8) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(UsesArray), - "::", - stringify!(array_bool_8) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).array_int_4) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(UsesArray), - "::", - stringify!(array_int_4) - ) - ); + fn test_field_array_char_16() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).array_char_16) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(UsesArray), + "::", + stringify!(array_char_16) + ) + ); + } + test_field_array_char_16(); + fn test_field_array_bool_8() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).array_bool_8) as usize - + ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(UsesArray), + "::", + stringify!(array_bool_8) + ) + ); + } + test_field_array_bool_8(); + fn test_field_array_int_4() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).array_int_4) as usize - ptr as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(UsesArray), + "::", + stringify!(array_int_4) + ) + ); + } + test_field_array_int_4(); } diff --git a/tests/expectations/tests/objc_interface_type.rs b/tests/expectations/tests/objc_interface_type.rs index 41607b7999..5cafeede56 100644 --- a/tests/expectations/tests/objc_interface_type.rs +++ b/tests/expectations/tests/objc_interface_type.rs @@ -43,20 +43,23 @@ fn bindgen_test_layout_FooStruct() { 8usize, concat!("Alignment of ", stringify!(FooStruct)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(FooStruct), - "::", - stringify!(foo) - ) - ); + fn test_field_foo() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(FooStruct), + "::", + stringify!(foo) + ) + ); + } + test_field_foo(); } impl Default for FooStruct { fn default() -> Self { diff --git a/tests/expectations/tests/opaque-template-inst-member-2.rs b/tests/expectations/tests/opaque-template-inst-member-2.rs index e341c68989..391c46d1d0 100644 --- a/tests/expectations/tests/opaque-template-inst-member-2.rs +++ b/tests/expectations/tests/opaque-template-inst-member-2.rs @@ -31,36 +31,42 @@ fn bindgen_test_layout_ContainsOpaqueTemplate() { 4usize, concat!("Alignment of ", stringify!(ContainsOpaqueTemplate)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBlah) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContainsOpaqueTemplate), - "::", - stringify!(mBlah) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBaz) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(ContainsOpaqueTemplate), - "::", - stringify!(mBaz) - ) - ); + fn test_field_mBlah() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBlah) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ContainsOpaqueTemplate), + "::", + stringify!(mBlah) + ) + ); + } + test_field_mBlah(); + fn test_field_mBaz() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBaz) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(ContainsOpaqueTemplate), + "::", + stringify!(mBaz) + ) + ); + } + test_field_mBaz(); } /// Should also derive Debug/Hash/PartialEq. #[repr(C)] @@ -81,21 +87,24 @@ fn bindgen_test_layout_InheritsOpaqueTemplate() { 8usize, concat!("Alignment of ", stringify!(InheritsOpaqueTemplate)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).wow) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(InheritsOpaqueTemplate), - "::", - stringify!(wow) - ) - ); + fn test_field_wow() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).wow) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(InheritsOpaqueTemplate), + "::", + stringify!(wow) + ) + ); + } + test_field_wow(); } impl Default for InheritsOpaqueTemplate { fn default() -> Self { diff --git a/tests/expectations/tests/opaque-template-inst-member.rs b/tests/expectations/tests/opaque-template-inst-member.rs index ef2b3edab7..0942976816 100644 --- a/tests/expectations/tests/opaque-template-inst-member.rs +++ b/tests/expectations/tests/opaque-template-inst-member.rs @@ -29,36 +29,42 @@ fn bindgen_test_layout_ContainsOpaqueTemplate() { 4usize, concat!("Alignment of ", stringify!(ContainsOpaqueTemplate)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBlah) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContainsOpaqueTemplate), - "::", - stringify!(mBlah) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBaz) as usize - ptr as usize - }, - 404usize, - concat!( - "Offset of field: ", - stringify!(ContainsOpaqueTemplate), - "::", - stringify!(mBaz) - ) - ); + fn test_field_mBlah() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBlah) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ContainsOpaqueTemplate), + "::", + stringify!(mBlah) + ) + ); + } + test_field_mBlah(); + fn test_field_mBaz() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBaz) as usize - ptr as usize + }, + 404usize, + concat!( + "Offset of field: ", + stringify!(ContainsOpaqueTemplate), + "::", + stringify!(mBaz) + ) + ); + } + test_field_mBaz(); } impl Default for ContainsOpaqueTemplate { fn default() -> Self { @@ -93,21 +99,24 @@ fn bindgen_test_layout_InheritsOpaqueTemplate() { 8usize, concat!("Alignment of ", stringify!(InheritsOpaqueTemplate)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).wow) as usize - ptr as usize - }, - 408usize, - concat!( - "Offset of field: ", - stringify!(InheritsOpaqueTemplate), - "::", - stringify!(wow) - ) - ); + fn test_field_wow() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).wow) as usize - ptr as usize + }, + 408usize, + concat!( + "Offset of field: ", + stringify!(InheritsOpaqueTemplate), + "::", + stringify!(wow) + ) + ); + } + test_field_wow(); } impl Default for InheritsOpaqueTemplate { fn default() -> Self { diff --git a/tests/expectations/tests/opaque-template-instantiation-namespaced.rs b/tests/expectations/tests/opaque-template-instantiation-namespaced.rs index fa1ed3b839..293f2a1ba6 100644 --- a/tests/expectations/tests/opaque-template-instantiation-namespaced.rs +++ b/tests/expectations/tests/opaque-template-instantiation-namespaced.rs @@ -45,20 +45,23 @@ pub mod root { 1usize, concat!("Alignment of ", stringify!(Foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(c) - ) - ); + fn test_field_c() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Foo), + "::", + stringify!(c) + ) + ); + } + test_field_c(); } #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] @@ -77,20 +80,23 @@ pub mod root { 4usize, concat!("Alignment of ", stringify!(Bar)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(i) - ) - ); + fn test_field_i() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Bar), + "::", + stringify!(i) + ) + ); + } + test_field_i(); } #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] @@ -109,21 +115,26 @@ pub mod root { 1usize, concat!("Alignment of ", stringify!(ContainsInstantiation)) ); - assert_eq!( - unsafe { - let uninit = :: std :: mem :: MaybeUninit :: < ContainsInstantiation > :: uninit () ; - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).not_opaque) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContainsInstantiation), - "::", - stringify!(not_opaque) - ) - ); + fn test_field_not_opaque() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + ContainsInstantiation, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).not_opaque) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ContainsInstantiation), + "::", + stringify!(not_opaque) + ) + ); + } + test_field_not_opaque(); } impl Default for ContainsInstantiation { fn default() -> Self { @@ -154,22 +165,26 @@ pub mod root { stringify!(ContainsOpaqueInstantiation) ) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - ContainsOpaqueInstantiation, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).opaque) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContainsOpaqueInstantiation), - "::", - stringify!(opaque) - ) - ); + fn test_field_opaque() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + ContainsOpaqueInstantiation, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).opaque) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ContainsOpaqueInstantiation), + "::", + stringify!(opaque) + ) + ); + } + test_field_opaque(); } } #[test] diff --git a/tests/expectations/tests/opaque-template-instantiation.rs b/tests/expectations/tests/opaque-template-instantiation.rs index 994e59a231..9f02920eb6 100644 --- a/tests/expectations/tests/opaque-template-instantiation.rs +++ b/tests/expectations/tests/opaque-template-instantiation.rs @@ -37,21 +37,24 @@ fn bindgen_test_layout_ContainsInstantiation() { 1usize, concat!("Alignment of ", stringify!(ContainsInstantiation)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).not_opaque) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContainsInstantiation), - "::", - stringify!(not_opaque) - ) - ); + fn test_field_not_opaque() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).not_opaque) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ContainsInstantiation), + "::", + stringify!(not_opaque) + ) + ); + } + test_field_not_opaque(); } impl Default for ContainsInstantiation { fn default() -> Self { @@ -79,22 +82,25 @@ fn bindgen_test_layout_ContainsOpaqueInstantiation() { 4usize, concat!("Alignment of ", stringify!(ContainsOpaqueInstantiation)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).opaque) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContainsOpaqueInstantiation), - "::", - stringify!(opaque) - ) - ); + fn test_field_opaque() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + ContainsOpaqueInstantiation, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).opaque) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ContainsOpaqueInstantiation), + "::", + stringify!(opaque) + ) + ); + } + test_field_opaque(); } #[test] fn __bindgen_test_layout_Template_open0_char_close0_instantiation() { diff --git a/tests/expectations/tests/opaque_in_struct.rs b/tests/expectations/tests/opaque_in_struct.rs index f900e5fddc..4af91c4fac 100644 --- a/tests/expectations/tests/opaque_in_struct.rs +++ b/tests/expectations/tests/opaque_in_struct.rs @@ -42,18 +42,21 @@ fn bindgen_test_layout_container() { 4usize, concat!("Alignment of ", stringify!(container)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).contained) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(container), - "::", - stringify!(contained) - ) - ); + fn test_field_contained() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).contained) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(container), + "::", + stringify!(contained) + ) + ); + } + test_field_contained(); } diff --git a/tests/expectations/tests/opaque_pointer.rs b/tests/expectations/tests/opaque_pointer.rs index 9d3af55fe5..7230c3c066 100644 --- a/tests/expectations/tests/opaque_pointer.rs +++ b/tests/expectations/tests/opaque_pointer.rs @@ -50,48 +50,57 @@ fn bindgen_test_layout_WithOpaquePtr() { 8usize, concat!("Alignment of ", stringify!(WithOpaquePtr)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).whatever) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithOpaquePtr), - "::", - stringify!(whatever) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).other) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(WithOpaquePtr), - "::", - stringify!(other) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).t) as usize - ptr as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(WithOpaquePtr), - "::", - stringify!(t) - ) - ); + fn test_field_whatever() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).whatever) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithOpaquePtr), + "::", + stringify!(whatever) + ) + ); + } + test_field_whatever(); + fn test_field_other() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).other) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(WithOpaquePtr), + "::", + stringify!(other) + ) + ); + } + test_field_other(); + fn test_field_t() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).t) as usize - ptr as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(WithOpaquePtr), + "::", + stringify!(t) + ) + ); + } + test_field_t(); } impl Default for WithOpaquePtr { fn default() -> Self { diff --git a/tests/expectations/tests/packed-n-with-padding.rs b/tests/expectations/tests/packed-n-with-padding.rs index 4039605ac4..6e749b1b72 100644 --- a/tests/expectations/tests/packed-n-with-padding.rs +++ b/tests/expectations/tests/packed-n-with-padding.rs @@ -25,40 +25,72 @@ fn bindgen_test_layout_Packed() { 2usize, concat!("Alignment of ", stringify!(Packed)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Packed), "::", stringify!(a)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 2usize, - concat!("Offset of field: ", stringify!(Packed), "::", stringify!(b)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize - }, - 4usize, - concat!("Offset of field: ", stringify!(Packed), "::", stringify!(c)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, - 6usize, - concat!("Offset of field: ", stringify!(Packed), "::", stringify!(d)) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Packed), + "::", + stringify!(a) + ) + ); + } + test_field_a(); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(Packed), + "::", + stringify!(b) + ) + ); + } + test_field_b(); + fn test_field_c() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(Packed), + "::", + stringify!(c) + ) + ); + } + test_field_c(); + fn test_field_d() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, + 6usize, + concat!( + "Offset of field: ", + stringify!(Packed), + "::", + stringify!(d) + ) + ); + } + test_field_d(); } diff --git a/tests/expectations/tests/private.rs b/tests/expectations/tests/private.rs index 568701eb21..63b5676849 100644 --- a/tests/expectations/tests/private.rs +++ b/tests/expectations/tests/private.rs @@ -24,34 +24,40 @@ fn bindgen_test_layout_HasPrivate() { 4usize, concat!("Alignment of ", stringify!(HasPrivate)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mNotPrivate) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(HasPrivate), - "::", - stringify!(mNotPrivate) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mIsPrivate) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(HasPrivate), - "::", - stringify!(mIsPrivate) - ) - ); + fn test_field_mNotPrivate() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mNotPrivate) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(HasPrivate), + "::", + stringify!(mNotPrivate) + ) + ); + } + test_field_mNotPrivate(); + fn test_field_mIsPrivate() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mIsPrivate) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(HasPrivate), + "::", + stringify!(mIsPrivate) + ) + ); + } + test_field_mIsPrivate(); } ///
#[repr(C)] @@ -72,34 +78,41 @@ fn bindgen_test_layout_VeryPrivate() { 4usize, concat!("Alignment of ", stringify!(VeryPrivate)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mIsPrivate) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(VeryPrivate), - "::", - stringify!(mIsPrivate) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mIsAlsoPrivate) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(VeryPrivate), - "::", - stringify!(mIsAlsoPrivate) - ) - ); + fn test_field_mIsPrivate() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mIsPrivate) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(VeryPrivate), + "::", + stringify!(mIsPrivate) + ) + ); + } + test_field_mIsPrivate(); + fn test_field_mIsAlsoPrivate() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mIsAlsoPrivate) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(VeryPrivate), + "::", + stringify!(mIsAlsoPrivate) + ) + ); + } + test_field_mIsAlsoPrivate(); } ///
#[repr(C)] @@ -121,32 +134,40 @@ fn bindgen_test_layout_ContradictPrivate() { 4usize, concat!("Alignment of ", stringify!(ContradictPrivate)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mNotPrivate) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContradictPrivate), - "::", - stringify!(mNotPrivate) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mIsPrivate) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(ContradictPrivate), - "::", - stringify!(mIsPrivate) - ) - ); + fn test_field_mNotPrivate() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mNotPrivate) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ContradictPrivate), + "::", + stringify!(mNotPrivate) + ) + ); + } + test_field_mNotPrivate(); + fn test_field_mIsPrivate() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mIsPrivate) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(ContradictPrivate), + "::", + stringify!(mIsPrivate) + ) + ); + } + test_field_mIsPrivate(); } diff --git a/tests/expectations/tests/private_fields.rs b/tests/expectations/tests/private_fields.rs index 887a736014..bea0fa4c2c 100644 --- a/tests/expectations/tests/private_fields.rs +++ b/tests/expectations/tests/private_fields.rs @@ -109,34 +109,40 @@ fn bindgen_test_layout_PubPriv() { 4usize, concat!("Alignment of ", stringify!(PubPriv)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(PubPriv), - "::", - stringify!(x) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(PubPriv), - "::", - stringify!(y) - ) - ); + fn test_field_x() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(PubPriv), + "::", + stringify!(x) + ) + ); + } + test_field_x(); + fn test_field_y() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(PubPriv), + "::", + stringify!(y) + ) + ); + } + test_field_y(); } #[repr(C)] #[repr(align(4))] @@ -353,20 +359,23 @@ fn bindgen_test_layout_Base() { 4usize, concat!("Alignment of ", stringify!(Base)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Base), - "::", - stringify!(member) - ) - ); + fn test_field_member() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Base), + "::", + stringify!(member) + ) + ); + } + test_field_member(); } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -427,22 +436,25 @@ fn bindgen_test_layout_WithAnonStruct__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(WithAnonStruct__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithAnonStruct__bindgen_ty_1), - "::", - stringify!(a) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + WithAnonStruct__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithAnonStruct__bindgen_ty_1), + "::", + stringify!(a) + ) + ); + } + test_field_a(); } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -461,22 +473,25 @@ fn bindgen_test_layout_WithAnonStruct__bindgen_ty_2() { 4usize, concat!("Alignment of ", stringify!(WithAnonStruct__bindgen_ty_2)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithAnonStruct__bindgen_ty_2), - "::", - stringify!(b) - ) - ); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + WithAnonStruct__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithAnonStruct__bindgen_ty_2), + "::", + stringify!(b) + ) + ); + } + test_field_b(); } #[test] fn bindgen_test_layout_WithAnonStruct() { diff --git a/tests/expectations/tests/reparented_replacement.rs b/tests/expectations/tests/reparented_replacement.rs index d04eaa25b9..f8426c2840 100644 --- a/tests/expectations/tests/reparented_replacement.rs +++ b/tests/expectations/tests/reparented_replacement.rs @@ -30,20 +30,24 @@ pub mod root { 4usize, concat!("Alignment of ", stringify!(Bar)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bazz) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(bazz) - ) - ); + fn test_field_bazz() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bazz) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Bar), + "::", + stringify!(bazz) + ) + ); + } + test_field_bazz(); } } pub type ReferencesBar = root::foo::Bar; diff --git a/tests/expectations/tests/replace_use.rs b/tests/expectations/tests/replace_use.rs index ea1da9871e..9478801f4b 100644 --- a/tests/expectations/tests/replace_use.rs +++ b/tests/expectations/tests/replace_use.rs @@ -28,15 +28,18 @@ fn bindgen_test_layout_Test() { 4usize, concat!("Alignment of ", stringify!(Test)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(a)) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(a)) + ); + } + test_field_a(); } #[test] fn __bindgen_test_layout_nsTArray_open0_long_close0_instantiation() { diff --git a/tests/expectations/tests/repr-align.rs b/tests/expectations/tests/repr-align.rs index 38f55428bf..3f00fce35c 100644 --- a/tests/expectations/tests/repr-align.rs +++ b/tests/expectations/tests/repr-align.rs @@ -25,24 +25,30 @@ fn bindgen_test_layout_a() { 8usize, concat!("Alignment of ", stringify!(a)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::
::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(a), "::", stringify!(b)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize - }, - 4usize, - concat!("Offset of field: ", stringify!(a), "::", stringify!(c)) - ); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(a), "::", stringify!(b)) + ); + } + test_field_b(); + fn test_field_c() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize + }, + 4usize, + concat!("Offset of field: ", stringify!(a), "::", stringify!(c)) + ); + } + test_field_c(); } #[repr(C)] #[repr(align(8))] @@ -63,22 +69,28 @@ fn bindgen_test_layout_b() { 8usize, concat!("Alignment of ", stringify!(b)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(b), "::", stringify!(b)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize - }, - 4usize, - concat!("Offset of field: ", stringify!(b), "::", stringify!(c)) - ); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(b), "::", stringify!(b)) + ); + } + test_field_b(); + fn test_field_c() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize + }, + 4usize, + concat!("Offset of field: ", stringify!(b), "::", stringify!(c)) + ); + } + test_field_c(); } diff --git a/tests/expectations/tests/same_struct_name_in_different_namespaces.rs b/tests/expectations/tests/same_struct_name_in_different_namespaces.rs index 91c4750aed..294861d15b 100644 --- a/tests/expectations/tests/same_struct_name_in_different_namespaces.rs +++ b/tests/expectations/tests/same_struct_name_in_different_namespaces.rs @@ -28,32 +28,40 @@ fn bindgen_test_layout_JS_shadow_Zone() { 4usize, concat!("Alignment of ", stringify!(JS_shadow_Zone)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(JS_shadow_Zone), - "::", - stringify!(x) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(JS_shadow_Zone), - "::", - stringify!(y) - ) - ); + fn test_field_x() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(JS_shadow_Zone), + "::", + stringify!(x) + ) + ); + } + test_field_x(); + fn test_field_y() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(JS_shadow_Zone), + "::", + stringify!(y) + ) + ); + } + test_field_y(); } diff --git a/tests/expectations/tests/sentry-defined-multiple-times.rs b/tests/expectations/tests/sentry-defined-multiple-times.rs index a11a72b365..bf76d0e1e7 100644 --- a/tests/expectations/tests/sentry-defined-multiple-times.rs +++ b/tests/expectations/tests/sentry-defined-multiple-times.rs @@ -39,21 +39,25 @@ pub mod root { 1usize, concat!("Alignment of ", stringify!(sentry)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i_am_plain_sentry) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(sentry), - "::", - stringify!(i_am_plain_sentry) - ) - ); + fn test_field_i_am_plain_sentry() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i_am_plain_sentry) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(sentry), + "::", + stringify!(i_am_plain_sentry) + ) + ); + } + test_field_i_am_plain_sentry(); } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -90,25 +94,28 @@ pub mod root { 1usize, concat!("Alignment of ", stringify!(NotTemplateWrapper_sentry)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - NotTemplateWrapper_sentry, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!( - (*ptr).i_am_not_template_wrapper_sentry - ) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NotTemplateWrapper_sentry), - "::", - stringify!(i_am_not_template_wrapper_sentry) - ) - ); + fn test_field_i_am_not_template_wrapper_sentry() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + NotTemplateWrapper_sentry, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!( + (*ptr).i_am_not_template_wrapper_sentry + ) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(NotTemplateWrapper_sentry), + "::", + stringify!(i_am_not_template_wrapper_sentry) + ) + ); + } + test_field_i_am_not_template_wrapper_sentry(); } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -138,25 +145,28 @@ pub mod root { stringify!(InlineNotTemplateWrapper_sentry) ) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - InlineNotTemplateWrapper_sentry, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!( - (*ptr).i_am_inline_not_template_wrapper_sentry - ) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(InlineNotTemplateWrapper_sentry), - "::", - stringify!(i_am_inline_not_template_wrapper_sentry) - ) - ); + fn test_field_i_am_inline_not_template_wrapper_sentry() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + InlineNotTemplateWrapper_sentry, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!( + (*ptr).i_am_inline_not_template_wrapper_sentry + ) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(InlineNotTemplateWrapper_sentry), + "::", + stringify!(i_am_inline_not_template_wrapper_sentry) + ) + ); + } + test_field_i_am_inline_not_template_wrapper_sentry(); } #[test] fn bindgen_test_layout_InlineNotTemplateWrapper() { @@ -250,24 +260,29 @@ pub mod root { stringify!(OuterDoubleWrapper_InnerDoubleWrapper_sentry) ) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - OuterDoubleWrapper_InnerDoubleWrapper_sentry, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i_am_double_wrapper_sentry) - as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(OuterDoubleWrapper_InnerDoubleWrapper_sentry), - "::", - stringify!(i_am_double_wrapper_sentry) - ) - ); + fn test_field_i_am_double_wrapper_sentry() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + OuterDoubleWrapper_InnerDoubleWrapper_sentry, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i_am_double_wrapper_sentry) + as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!( + OuterDoubleWrapper_InnerDoubleWrapper_sentry + ), + "::", + stringify!(i_am_double_wrapper_sentry) + ) + ); + } + test_field_i_am_double_wrapper_sentry(); } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -289,7 +304,10 @@ pub mod root { ) { assert_eq ! (:: std :: mem :: size_of :: < OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry > () , 4usize , concat ! ("Size of: " , stringify ! (OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry))); assert_eq ! (:: std :: mem :: align_of :: < OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry > () , 4usize , concat ! ("Alignment of " , stringify ! (OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry))); - assert_eq ! (unsafe { let uninit = :: std :: mem :: MaybeUninit :: < OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry > :: uninit () ; let ptr = uninit . as_ptr () ; :: std :: ptr :: addr_of ! ((* ptr) . i_am_double_wrapper_inline_sentry) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry) , "::" , stringify ! (i_am_double_wrapper_inline_sentry))); + fn test_field_i_am_double_wrapper_inline_sentry() { + assert_eq ! (unsafe { let uninit = :: std :: mem :: MaybeUninit :: < OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry > :: uninit () ; let ptr = uninit . as_ptr () ; :: std :: ptr :: addr_of ! ((* ptr) . i_am_double_wrapper_inline_sentry) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry) , "::" , stringify ! (i_am_double_wrapper_inline_sentry))); + } + test_field_i_am_double_wrapper_inline_sentry(); } #[test] fn bindgen_test_layout_OuterDoubleInlineWrapper_InnerDoubleInlineWrapper( @@ -360,21 +378,24 @@ pub mod root { 4usize, concat!("Alignment of ", stringify!(sentry)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i_am_outside_namespace_sentry) - as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(sentry), - "::", - stringify!(i_am_outside_namespace_sentry) - ) - ); + fn test_field_i_am_outside_namespace_sentry() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).i_am_outside_namespace_sentry) + as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(sentry), + "::", + stringify!(i_am_outside_namespace_sentry) + ) + ); + } + test_field_i_am_outside_namespace_sentry(); } } diff --git a/tests/expectations/tests/size_t_is_usize.rs b/tests/expectations/tests/size_t_is_usize.rs index 60e566f0d9..f4e4b79ba7 100644 --- a/tests/expectations/tests/size_t_is_usize.rs +++ b/tests/expectations/tests/size_t_is_usize.rs @@ -24,33 +24,47 @@ fn bindgen_test_layout_A() { 8usize, concat!("Alignment of ", stringify!(A)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(len)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).offset) as usize - ptr as usize - }, - 8usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(offset)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize - }, - 16usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(next)) - ); + fn test_field_len() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(A), "::", stringify!(len)) + ); + } + test_field_len(); + fn test_field_offset() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).offset) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(A), + "::", + stringify!(offset) + ) + ); + } + test_field_offset(); + fn test_field_next() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize + }, + 16usize, + concat!("Offset of field: ", stringify!(A), "::", stringify!(next)) + ); + } + test_field_next(); } impl Default for A { fn default() -> Self { diff --git a/tests/expectations/tests/size_t_template.rs b/tests/expectations/tests/size_t_template.rs index 512e05528c..3c14d85727 100644 --- a/tests/expectations/tests/size_t_template.rs +++ b/tests/expectations/tests/size_t_template.rs @@ -22,13 +22,16 @@ fn bindgen_test_layout_C() { 4usize, concat!("Alignment of ", stringify!(C)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(arr)) - ); + fn test_field_arr() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(arr)) + ); + } + test_field_arr(); } diff --git a/tests/expectations/tests/struct_containing_forward_declared_struct.rs b/tests/expectations/tests/struct_containing_forward_declared_struct.rs index d61e9dc3a2..bd1419c6f1 100644 --- a/tests/expectations/tests/struct_containing_forward_declared_struct.rs +++ b/tests/expectations/tests/struct_containing_forward_declared_struct.rs @@ -22,15 +22,23 @@ fn bindgen_test_layout_a() { 8usize, concat!("Alignment of ", stringify!(a)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).val_a) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(a), "::", stringify!(val_a)) - ); + fn test_field_val_a() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).val_a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(a), + "::", + stringify!(val_a) + ) + ); + } + test_field_val_a(); } impl Default for a { fn default() -> Self { @@ -58,13 +66,21 @@ fn bindgen_test_layout_b() { 4usize, concat!("Alignment of ", stringify!(b)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).val_b) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(b), "::", stringify!(val_b)) - ); + fn test_field_val_b() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).val_b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(b), + "::", + stringify!(val_b) + ) + ); + } + test_field_val_b(); } diff --git a/tests/expectations/tests/struct_typedef.rs b/tests/expectations/tests/struct_typedef.rs index 9a646afad6..1eab593ebb 100644 --- a/tests/expectations/tests/struct_typedef.rs +++ b/tests/expectations/tests/struct_typedef.rs @@ -22,21 +22,24 @@ fn bindgen_test_layout_typedef_named_struct() { 1usize, concat!("Alignment of ", stringify!(typedef_named_struct)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).has_name) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(typedef_named_struct), - "::", - stringify!(has_name) - ) - ); + fn test_field_has_name() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).has_name) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(typedef_named_struct), + "::", + stringify!(has_name) + ) + ); + } + test_field_has_name(); } #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] @@ -55,20 +58,23 @@ fn bindgen_test_layout__bindgen_ty_1() { 8usize, concat!("Alignment of ", stringify!(_bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::<_bindgen_ty_1>::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).no_name) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_bindgen_ty_1), - "::", - stringify!(no_name) - ) - ); + fn test_field_no_name() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::<_bindgen_ty_1>::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).no_name) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_bindgen_ty_1), + "::", + stringify!(no_name) + ) + ); + } + test_field_no_name(); } impl Default for _bindgen_ty_1 { fn default() -> Self { diff --git a/tests/expectations/tests/struct_typedef_ns.rs b/tests/expectations/tests/struct_typedef_ns.rs index 687b31ea91..8b113567ba 100644 --- a/tests/expectations/tests/struct_typedef_ns.rs +++ b/tests/expectations/tests/struct_typedef_ns.rs @@ -29,21 +29,24 @@ pub mod root { 4usize, concat!("Alignment of ", stringify!(typedef_struct)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(typedef_struct), - "::", - stringify!(foo) - ) - ); + fn test_field_foo() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(typedef_struct), + "::", + stringify!(foo) + ) + ); + } + test_field_foo(); } #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] @@ -71,21 +74,24 @@ pub mod root { 4usize, concat!("Alignment of ", stringify!(_bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::<_bindgen_ty_1>::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_bindgen_ty_1), - "::", - stringify!(foo) - ) - ); + fn test_field_foo() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::<_bindgen_ty_1>::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_bindgen_ty_1), + "::", + stringify!(foo) + ) + ); + } + test_field_foo(); } pub type typedef_struct = root::_bindgen_mod_id_12::_bindgen_ty_1; pub const _bindgen_mod_id_12_BAR: diff --git a/tests/expectations/tests/struct_with_anon_struct.rs b/tests/expectations/tests/struct_with_anon_struct.rs index e34d9294a0..88e1d7b599 100644 --- a/tests/expectations/tests/struct_with_anon_struct.rs +++ b/tests/expectations/tests/struct_with_anon_struct.rs @@ -28,34 +28,42 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(a) + ) + ); + } + test_field_a(); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(b) + ) + ); + } + test_field_b(); } #[test] fn bindgen_test_layout_foo() { @@ -69,13 +77,21 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) - ); + fn test_field_bar() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(bar) + ) + ); + } + test_field_bar(); } diff --git a/tests/expectations/tests/struct_with_anon_struct_array.rs b/tests/expectations/tests/struct_with_anon_struct_array.rs index c5b0fcc5ef..b556699302 100644 --- a/tests/expectations/tests/struct_with_anon_struct_array.rs +++ b/tests/expectations/tests/struct_with_anon_struct_array.rs @@ -29,34 +29,42 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(a) + ) + ); + } + test_field_a(); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(b) + ) + ); + } + test_field_b(); } #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] @@ -76,34 +84,42 @@ fn bindgen_test_layout_foo__bindgen_ty_2() { 4usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_2)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_2), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_2), - "::", - stringify!(b) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_2), + "::", + stringify!(a) + ) + ); + } + test_field_a(); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_2), + "::", + stringify!(b) + ) + ); + } + test_field_b(); } #[test] fn bindgen_test_layout_foo() { @@ -117,22 +133,38 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, - 16usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(baz)) - ); + fn test_field_bar() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(bar) + ) + ); + } + test_field_bar(); + fn test_field_baz() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(baz) + ) + ); + } + test_field_baz(); } diff --git a/tests/expectations/tests/struct_with_anon_struct_pointer.rs b/tests/expectations/tests/struct_with_anon_struct_pointer.rs index 968251249d..5050ef4598 100644 --- a/tests/expectations/tests/struct_with_anon_struct_pointer.rs +++ b/tests/expectations/tests/struct_with_anon_struct_pointer.rs @@ -28,34 +28,42 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(a) + ) + ); + } + test_field_a(); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(b) + ) + ); + } + test_field_b(); } #[test] fn bindgen_test_layout_foo() { @@ -69,15 +77,23 @@ fn bindgen_test_layout_foo() { 8usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) - ); + fn test_field_bar() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(bar) + ) + ); + } + test_field_bar(); } impl Default for foo { fn default() -> Self { diff --git a/tests/expectations/tests/struct_with_anon_union.rs b/tests/expectations/tests/struct_with_anon_union.rs index e15939bdb8..37f07476fd 100644 --- a/tests/expectations/tests/struct_with_anon_union.rs +++ b/tests/expectations/tests/struct_with_anon_union.rs @@ -28,34 +28,42 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(a) + ) + ); + } + test_field_a(); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(b) + ) + ); + } + test_field_b(); } impl Default for foo__bindgen_ty_1 { fn default() -> Self { @@ -78,15 +86,23 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) - ); + fn test_field_bar() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(bar) + ) + ); + } + test_field_bar(); } impl Default for foo { fn default() -> Self { diff --git a/tests/expectations/tests/struct_with_anon_union_1_0.rs b/tests/expectations/tests/struct_with_anon_union_1_0.rs index 2b7d33b09d..03e0efc7d5 100644 --- a/tests/expectations/tests/struct_with_anon_union_1_0.rs +++ b/tests/expectations/tests/struct_with_anon_union_1_0.rs @@ -72,34 +72,42 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(a) + ) + ); + } + test_field_a(); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(b) + ) + ); + } + test_field_b(); } impl Clone for foo__bindgen_ty_1 { fn clone(&self) -> Self { @@ -118,15 +126,23 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) - ); + fn test_field_bar() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(bar) + ) + ); + } + test_field_bar(); } impl Clone for foo { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/struct_with_anon_unnamed_struct.rs b/tests/expectations/tests/struct_with_anon_unnamed_struct.rs index a680604646..8916bcd492 100644 --- a/tests/expectations/tests/struct_with_anon_unnamed_struct.rs +++ b/tests/expectations/tests/struct_with_anon_unnamed_struct.rs @@ -28,34 +28,42 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(a) + ) + ); + } + test_field_a(); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(b) + ) + ); + } + test_field_b(); } #[test] fn bindgen_test_layout_foo() { diff --git a/tests/expectations/tests/struct_with_anon_unnamed_union.rs b/tests/expectations/tests/struct_with_anon_unnamed_union.rs index 0700253809..eb177c9bd5 100644 --- a/tests/expectations/tests/struct_with_anon_unnamed_union.rs +++ b/tests/expectations/tests/struct_with_anon_unnamed_union.rs @@ -28,34 +28,42 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(a) + ) + ); + } + test_field_a(); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(b) + ) + ); + } + test_field_b(); } impl Default for foo__bindgen_ty_1 { fn default() -> Self { diff --git a/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs b/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs index 622dbcbe20..0098a4046f 100644 --- a/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs +++ b/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs @@ -72,34 +72,42 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(a) + ) + ); + } + test_field_a(); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(b) + ) + ); + } + test_field_b(); } impl Clone for foo__bindgen_ty_1 { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/struct_with_bitfields.rs b/tests/expectations/tests/struct_with_bitfields.rs index 8a7d070ec0..00123956d8 100644 --- a/tests/expectations/tests/struct_with_bitfields.rs +++ b/tests/expectations/tests/struct_with_bitfields.rs @@ -112,20 +112,23 @@ fn bindgen_test_layout_bitfield() { 4usize, concat!("Alignment of ", stringify!(bitfield)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).e) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(bitfield), - "::", - stringify!(e) - ) - ); + fn test_field_e() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).e) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(bitfield), + "::", + stringify!(e) + ) + ); + } + test_field_e(); } impl bitfield { #[inline] diff --git a/tests/expectations/tests/struct_with_derive_debug.rs b/tests/expectations/tests/struct_with_derive_debug.rs index 9ab32de0c7..a2729bbeb8 100644 --- a/tests/expectations/tests/struct_with_derive_debug.rs +++ b/tests/expectations/tests/struct_with_derive_debug.rs @@ -22,20 +22,23 @@ fn bindgen_test_layout_LittleArray() { 4usize, concat!("Alignment of ", stringify!(LittleArray)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(LittleArray), - "::", - stringify!(a) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(LittleArray), + "::", + stringify!(a) + ) + ); + } + test_field_a(); } #[repr(C)] #[derive(Copy, Clone)] @@ -54,20 +57,23 @@ fn bindgen_test_layout_BigArray() { 4usize, concat!("Alignment of ", stringify!(BigArray)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(BigArray), - "::", - stringify!(a) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(BigArray), + "::", + stringify!(a) + ) + ); + } + test_field_a(); } impl Default for BigArray { fn default() -> Self { @@ -95,20 +101,24 @@ fn bindgen_test_layout_WithLittleArray() { 4usize, concat!("Alignment of ", stringify!(WithLittleArray)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithLittleArray), - "::", - stringify!(a) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithLittleArray), + "::", + stringify!(a) + ) + ); + } + test_field_a(); } #[repr(C)] #[derive(Copy, Clone)] @@ -127,20 +137,23 @@ fn bindgen_test_layout_WithBigArray() { 4usize, concat!("Alignment of ", stringify!(WithBigArray)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigArray), - "::", - stringify!(a) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithBigArray), + "::", + stringify!(a) + ) + ); + } + test_field_a(); } impl Default for WithBigArray { fn default() -> Self { diff --git a/tests/expectations/tests/struct_with_large_array.rs b/tests/expectations/tests/struct_with_large_array.rs index e323247f3f..e792f71acc 100644 --- a/tests/expectations/tests/struct_with_large_array.rs +++ b/tests/expectations/tests/struct_with_large_array.rs @@ -22,20 +22,23 @@ fn bindgen_test_layout_S() { 1usize, concat!("Alignment of ", stringify!(S)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(S), - "::", - stringify!(large_array) - ) - ); + fn test_field_large_array() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(S), + "::", + stringify!(large_array) + ) + ); + } + test_field_large_array(); } impl Default for S { fn default() -> Self { diff --git a/tests/expectations/tests/struct_with_nesting.rs b/tests/expectations/tests/struct_with_nesting.rs index 897b757df1..5b98fc49c8 100644 --- a/tests/expectations/tests/struct_with_nesting.rs +++ b/tests/expectations/tests/struct_with_nesting.rs @@ -36,38 +36,44 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { 2usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - foo__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).c1) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(c1) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - foo__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).c2) as usize - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(c2) - ) - ); + fn test_field_c1() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + foo__bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).c1) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(c1) + ) + ); + } + test_field_c1(); + fn test_field_c2() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + foo__bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).c2) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(c2) + ) + ); + } + test_field_c2(); } #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] @@ -89,70 +95,82 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { 1usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - foo__bindgen_ty_1__bindgen_ty_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d1) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(d1) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - foo__bindgen_ty_1__bindgen_ty_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d2) as usize - ptr as usize - }, - 1usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(d2) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - foo__bindgen_ty_1__bindgen_ty_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d3) as usize - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(d3) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - foo__bindgen_ty_1__bindgen_ty_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d4) as usize - ptr as usize - }, - 3usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(d4) - ) - ); + fn test_field_d1() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + foo__bindgen_ty_1__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d1) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(d1) + ) + ); + } + test_field_d1(); + fn test_field_d2() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + foo__bindgen_ty_1__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d2) as usize - ptr as usize + }, + 1usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(d2) + ) + ); + } + test_field_d2(); + fn test_field_d3() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + foo__bindgen_ty_1__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d3) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(d3) + ) + ); + } + test_field_d3(); + fn test_field_d4() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + foo__bindgen_ty_1__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d4) as usize - ptr as usize + }, + 3usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(d4) + ) + ); + } + test_field_d4(); } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { @@ -166,20 +184,24 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(b) + ) + ); + } + test_field_b(); } impl Default for foo__bindgen_ty_1 { fn default() -> Self { @@ -202,15 +224,18 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) + ); + } + test_field_a(); } impl Default for foo { fn default() -> Self { diff --git a/tests/expectations/tests/struct_with_nesting_1_0.rs b/tests/expectations/tests/struct_with_nesting_1_0.rs index 04d72bc0d6..0a7e1ec992 100644 --- a/tests/expectations/tests/struct_with_nesting_1_0.rs +++ b/tests/expectations/tests/struct_with_nesting_1_0.rs @@ -80,38 +80,44 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { 2usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - foo__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).c1) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(c1) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - foo__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).c2) as usize - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(c2) - ) - ); + fn test_field_c1() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + foo__bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).c1) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(c1) + ) + ); + } + test_field_c1(); + fn test_field_c2() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + foo__bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).c2) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(c2) + ) + ); + } + test_field_c2(); } impl Clone for foo__bindgen_ty_1__bindgen_ty_1 { fn clone(&self) -> Self { @@ -138,70 +144,82 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { 1usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - foo__bindgen_ty_1__bindgen_ty_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d1) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(d1) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - foo__bindgen_ty_1__bindgen_ty_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d2) as usize - ptr as usize - }, - 1usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(d2) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - foo__bindgen_ty_1__bindgen_ty_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d3) as usize - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(d3) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - foo__bindgen_ty_1__bindgen_ty_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d4) as usize - ptr as usize - }, - 3usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(d4) - ) - ); + fn test_field_d1() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + foo__bindgen_ty_1__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d1) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(d1) + ) + ); + } + test_field_d1(); + fn test_field_d2() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + foo__bindgen_ty_1__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d2) as usize - ptr as usize + }, + 1usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(d2) + ) + ); + } + test_field_d2(); + fn test_field_d3() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + foo__bindgen_ty_1__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d3) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(d3) + ) + ); + } + test_field_d3(); + fn test_field_d4() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + foo__bindgen_ty_1__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d4) as usize - ptr as usize + }, + 3usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(d4) + ) + ); + } + test_field_d4(); } impl Clone for foo__bindgen_ty_1__bindgen_ty_2 { fn clone(&self) -> Self { @@ -220,20 +238,24 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(b) + ) + ); + } + test_field_b(); } impl Clone for foo__bindgen_ty_1 { fn clone(&self) -> Self { @@ -252,15 +274,18 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) + ); + } + test_field_a(); } impl Clone for foo { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/struct_with_packing.rs b/tests/expectations/tests/struct_with_packing.rs index 8a3b417454..c82edf28b5 100644 --- a/tests/expectations/tests/struct_with_packing.rs +++ b/tests/expectations/tests/struct_with_packing.rs @@ -23,22 +23,28 @@ fn bindgen_test_layout_a() { 1usize, concat!("Alignment of ", stringify!(a)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(a), "::", stringify!(b)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize - }, - 1usize, - concat!("Offset of field: ", stringify!(a), "::", stringify!(c)) - ); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(a), "::", stringify!(b)) + ); + } + test_field_b(); + fn test_field_c() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize + }, + 1usize, + concat!("Offset of field: ", stringify!(a), "::", stringify!(c)) + ); + } + test_field_c(); } diff --git a/tests/expectations/tests/struct_with_struct.rs b/tests/expectations/tests/struct_with_struct.rs index f62fd0570c..a8d0693786 100644 --- a/tests/expectations/tests/struct_with_struct.rs +++ b/tests/expectations/tests/struct_with_struct.rs @@ -28,34 +28,42 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(x) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(y) - ) - ); + fn test_field_x() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(x) + ) + ); + } + test_field_x(); + fn test_field_y() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(y) + ) + ); + } + test_field_y(); } #[test] fn bindgen_test_layout_foo() { @@ -69,13 +77,21 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) - ); + fn test_field_bar() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(bar) + ) + ); + } + test_field_bar(); } diff --git a/tests/expectations/tests/template.rs b/tests/expectations/tests/template.rs index 7c36632855..4de7b7aad6 100644 --- a/tests/expectations/tests/template.rs +++ b/tests/expectations/tests/template.rs @@ -78,222 +78,276 @@ fn bindgen_test_layout_C() { 8usize, concat!("Alignment of ", stringify!(C)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mB) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(mB)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBConstPtr) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBConstPtr) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBConstStructPtr) as usize - - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBConstStructPtr) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBConstStructPtrArray) as usize - - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBConstStructPtrArray) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBConst) as usize - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBConst) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBVolatile) as usize - ptr as usize - }, - 36usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBVolatile) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBConstBool) as usize - ptr as usize - }, - 40usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBConstBool) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBConstChar) as usize - ptr as usize - }, - 42usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBConstChar) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBArray) as usize - ptr as usize - }, - 44usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBArray) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBPtrArray) as usize - ptr as usize - }, - 48usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBPtrArray) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBArrayPtr) as usize - ptr as usize - }, - 56usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBArrayPtr) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBRef) as usize - ptr as usize - }, - 64usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(mBRef)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBConstRef) as usize - ptr as usize - }, - 72usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBConstRef) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mPtrRef) as usize - ptr as usize - }, - 80usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mPtrRef) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mArrayRef) as usize - ptr as usize - }, - 88usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mArrayRef) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBConstArray) as usize - ptr as usize - }, - 96usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBConstArray) - ) - ); + fn test_field_mB() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mB) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(mB)) + ); + } + test_field_mB(); + fn test_field_mBConstPtr() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBConstPtr) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(mBConstPtr) + ) + ); + } + test_field_mBConstPtr(); + fn test_field_mBConstStructPtr() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBConstStructPtr) as usize - + ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(mBConstStructPtr) + ) + ); + } + test_field_mBConstStructPtr(); + fn test_field_mBConstStructPtrArray() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBConstStructPtrArray) as usize - + ptr as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(mBConstStructPtrArray) + ) + ); + } + test_field_mBConstStructPtrArray(); + fn test_field_mBConst() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBConst) as usize - ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(mBConst) + ) + ); + } + test_field_mBConst(); + fn test_field_mBVolatile() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBVolatile) as usize - ptr as usize + }, + 36usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(mBVolatile) + ) + ); + } + test_field_mBVolatile(); + fn test_field_mBConstBool() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBConstBool) as usize - ptr as usize + }, + 40usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(mBConstBool) + ) + ); + } + test_field_mBConstBool(); + fn test_field_mBConstChar() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBConstChar) as usize - ptr as usize + }, + 42usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(mBConstChar) + ) + ); + } + test_field_mBConstChar(); + fn test_field_mBArray() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBArray) as usize - ptr as usize + }, + 44usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(mBArray) + ) + ); + } + test_field_mBArray(); + fn test_field_mBPtrArray() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBPtrArray) as usize - ptr as usize + }, + 48usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(mBPtrArray) + ) + ); + } + test_field_mBPtrArray(); + fn test_field_mBArrayPtr() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBArrayPtr) as usize - ptr as usize + }, + 56usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(mBArrayPtr) + ) + ); + } + test_field_mBArrayPtr(); + fn test_field_mBRef() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBRef) as usize - ptr as usize + }, + 64usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(mBRef) + ) + ); + } + test_field_mBRef(); + fn test_field_mBConstRef() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBConstRef) as usize - ptr as usize + }, + 72usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(mBConstRef) + ) + ); + } + test_field_mBConstRef(); + fn test_field_mPtrRef() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mPtrRef) as usize - ptr as usize + }, + 80usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(mPtrRef) + ) + ); + } + test_field_mPtrRef(); + fn test_field_mArrayRef() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mArrayRef) as usize - ptr as usize + }, + 88usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(mArrayRef) + ) + ); + } + test_field_mArrayRef(); + fn test_field_mBConstArray() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBConstArray) as usize - + ptr as usize + }, + 96usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(mBConstArray) + ) + ); + } + test_field_mBConstArray(); } impl Default for C { fn default() -> Self { @@ -369,20 +423,24 @@ fn bindgen_test_layout_RootedContainer() { 8usize, concat!("Alignment of ", stringify!(RootedContainer)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).root) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(RootedContainer), - "::", - stringify!(root) - ) - ); + fn test_field_root() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).root) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(RootedContainer), + "::", + stringify!(root) + ) + ); + } + test_field_root(); } impl Default for RootedContainer { fn default() -> Self { @@ -426,21 +484,24 @@ fn bindgen_test_layout_PODButContainsDtor() { 4usize, concat!("Alignment of ", stringify!(PODButContainsDtor)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(PODButContainsDtor), - "::", - stringify!(member) - ) - ); + fn test_field_member() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(PODButContainsDtor), + "::", + stringify!(member) + ) + ); + } + test_field_member(); } impl Default for PODButContainsDtor { fn default() -> Self { @@ -474,20 +535,24 @@ fn bindgen_test_layout_POD() { 4usize, concat!("Alignment of ", stringify!(POD)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).opaque_member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(POD), - "::", - stringify!(opaque_member) - ) - ); + fn test_field_opaque_member() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).opaque_member) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(POD), + "::", + stringify!(opaque_member) + ) + ); + } + test_field_opaque_member(); } ///
#[repr(C)] diff --git a/tests/expectations/tests/test_mixed_header_and_header_contents.rs b/tests/expectations/tests/test_mixed_header_and_header_contents.rs index 76f28dcbb7..369d10d3ac 100644 --- a/tests/expectations/tests/test_mixed_header_and_header_contents.rs +++ b/tests/expectations/tests/test_mixed_header_and_header_contents.rs @@ -43,117 +43,198 @@ fn bindgen_test_layout_Test() { 1usize, concat!("Alignment of ", stringify!(Test)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ch) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(ch)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize - }, - 1usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(u)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, - 2usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(d)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).cch) as usize - ptr as usize - }, - 3usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(cch)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).cu) as usize - ptr as usize - }, - 4usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(cu)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).cd) as usize - ptr as usize - }, - 5usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(cd)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).Cch) as usize - ptr as usize - }, - 6usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cch)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).Cu) as usize - ptr as usize - }, - 7usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cu)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).Cd) as usize - ptr as usize - }, - 8usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cd)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).Ccch) as usize - ptr as usize - }, - 9usize, - concat!( - "Offset of field: ", - stringify!(Test), - "::", - stringify!(Ccch) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).Ccu) as usize - ptr as usize - }, - 10usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccu)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).Ccd) as usize - ptr as usize - }, - 11usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccd)) - ); + fn test_field_ch() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ch) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Test), + "::", + stringify!(ch) + ) + ); + } + test_field_ch(); + fn test_field_u() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize + }, + 1usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(u)) + ); + } + test_field_u(); + fn test_field_d() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, + 2usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(d)) + ); + } + test_field_d(); + fn test_field_cch() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).cch) as usize - ptr as usize + }, + 3usize, + concat!( + "Offset of field: ", + stringify!(Test), + "::", + stringify!(cch) + ) + ); + } + test_field_cch(); + fn test_field_cu() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).cu) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(Test), + "::", + stringify!(cu) + ) + ); + } + test_field_cu(); + fn test_field_cd() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).cd) as usize - ptr as usize + }, + 5usize, + concat!( + "Offset of field: ", + stringify!(Test), + "::", + stringify!(cd) + ) + ); + } + test_field_cd(); + fn test_field_Cch() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Cch) as usize - ptr as usize + }, + 6usize, + concat!( + "Offset of field: ", + stringify!(Test), + "::", + stringify!(Cch) + ) + ); + } + test_field_Cch(); + fn test_field_Cu() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Cu) as usize - ptr as usize + }, + 7usize, + concat!( + "Offset of field: ", + stringify!(Test), + "::", + stringify!(Cu) + ) + ); + } + test_field_Cu(); + fn test_field_Cd() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Cd) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(Test), + "::", + stringify!(Cd) + ) + ); + } + test_field_Cd(); + fn test_field_Ccch() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Ccch) as usize - ptr as usize + }, + 9usize, + concat!( + "Offset of field: ", + stringify!(Test), + "::", + stringify!(Ccch) + ) + ); + } + test_field_Ccch(); + fn test_field_Ccu() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Ccu) as usize - ptr as usize + }, + 10usize, + concat!( + "Offset of field: ", + stringify!(Test), + "::", + stringify!(Ccu) + ) + ); + } + test_field_Ccu(); + fn test_field_Ccd() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Ccd) as usize - ptr as usize + }, + 11usize, + concat!( + "Offset of field: ", + stringify!(Test), + "::", + stringify!(Ccd) + ) + ); + } + test_field_Ccd(); } diff --git a/tests/expectations/tests/test_multiple_header_calls_in_builder.rs b/tests/expectations/tests/test_multiple_header_calls_in_builder.rs index b90ec73002..b05dd971ea 100644 --- a/tests/expectations/tests/test_multiple_header_calls_in_builder.rs +++ b/tests/expectations/tests/test_multiple_header_calls_in_builder.rs @@ -37,117 +37,198 @@ fn bindgen_test_layout_Test() { 1usize, concat!("Alignment of ", stringify!(Test)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ch) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(ch)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize - }, - 1usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(u)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, - 2usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(d)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).cch) as usize - ptr as usize - }, - 3usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(cch)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).cu) as usize - ptr as usize - }, - 4usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(cu)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).cd) as usize - ptr as usize - }, - 5usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(cd)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).Cch) as usize - ptr as usize - }, - 6usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cch)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).Cu) as usize - ptr as usize - }, - 7usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cu)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).Cd) as usize - ptr as usize - }, - 8usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cd)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).Ccch) as usize - ptr as usize - }, - 9usize, - concat!( - "Offset of field: ", - stringify!(Test), - "::", - stringify!(Ccch) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).Ccu) as usize - ptr as usize - }, - 10usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccu)) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).Ccd) as usize - ptr as usize - }, - 11usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccd)) - ); + fn test_field_ch() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ch) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Test), + "::", + stringify!(ch) + ) + ); + } + test_field_ch(); + fn test_field_u() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize + }, + 1usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(u)) + ); + } + test_field_u(); + fn test_field_d() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, + 2usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(d)) + ); + } + test_field_d(); + fn test_field_cch() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).cch) as usize - ptr as usize + }, + 3usize, + concat!( + "Offset of field: ", + stringify!(Test), + "::", + stringify!(cch) + ) + ); + } + test_field_cch(); + fn test_field_cu() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).cu) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(Test), + "::", + stringify!(cu) + ) + ); + } + test_field_cu(); + fn test_field_cd() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).cd) as usize - ptr as usize + }, + 5usize, + concat!( + "Offset of field: ", + stringify!(Test), + "::", + stringify!(cd) + ) + ); + } + test_field_cd(); + fn test_field_Cch() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Cch) as usize - ptr as usize + }, + 6usize, + concat!( + "Offset of field: ", + stringify!(Test), + "::", + stringify!(Cch) + ) + ); + } + test_field_Cch(); + fn test_field_Cu() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Cu) as usize - ptr as usize + }, + 7usize, + concat!( + "Offset of field: ", + stringify!(Test), + "::", + stringify!(Cu) + ) + ); + } + test_field_Cu(); + fn test_field_Cd() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Cd) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(Test), + "::", + stringify!(Cd) + ) + ); + } + test_field_Cd(); + fn test_field_Ccch() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Ccch) as usize - ptr as usize + }, + 9usize, + concat!( + "Offset of field: ", + stringify!(Test), + "::", + stringify!(Ccch) + ) + ); + } + test_field_Ccch(); + fn test_field_Ccu() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Ccu) as usize - ptr as usize + }, + 10usize, + concat!( + "Offset of field: ", + stringify!(Test), + "::", + stringify!(Ccu) + ) + ); + } + test_field_Ccu(); + fn test_field_Ccd() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).Ccd) as usize - ptr as usize + }, + 11usize, + concat!( + "Offset of field: ", + stringify!(Test), + "::", + stringify!(Ccd) + ) + ); + } + test_field_Ccd(); } diff --git a/tests/expectations/tests/timex.rs b/tests/expectations/tests/timex.rs index ec761f34be..8f0677b160 100644 --- a/tests/expectations/tests/timex.rs +++ b/tests/expectations/tests/timex.rs @@ -110,20 +110,23 @@ fn bindgen_test_layout_timex() { 4usize, concat!("Alignment of ", stringify!(timex)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).tai) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(timex), - "::", - stringify!(tai) - ) - ); + fn test_field_tai() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tai) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(timex), + "::", + stringify!(tai) + ) + ); + } + test_field_tai(); } impl Default for timex { fn default() -> Self { @@ -153,20 +156,23 @@ fn bindgen_test_layout_timex_named() { 4usize, concat!("Alignment of ", stringify!(timex_named)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).tai) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(timex_named), - "::", - stringify!(tai) - ) - ); + fn test_field_tai() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).tai) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(timex_named), + "::", + stringify!(tai) + ) + ); + } + test_field_tai(); } impl Default for timex_named { fn default() -> Self { diff --git a/tests/expectations/tests/type-referenced-by-allowlisted-function.rs b/tests/expectations/tests/type-referenced-by-allowlisted-function.rs index cc491fcccc..421abdc940 100644 --- a/tests/expectations/tests/type-referenced-by-allowlisted-function.rs +++ b/tests/expectations/tests/type-referenced-by-allowlisted-function.rs @@ -22,20 +22,23 @@ fn bindgen_test_layout_dl_phdr_info() { 4usize, concat!("Alignment of ", stringify!(dl_phdr_info)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(dl_phdr_info), - "::", - stringify!(x) - ) - ); + fn test_field_x() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(dl_phdr_info), + "::", + stringify!(x) + ) + ); + } + test_field_x(); } extern "C" { pub fn dl_iterate_phdr(arg1: *mut dl_phdr_info) -> ::std::os::raw::c_int; diff --git a/tests/expectations/tests/typeref.rs b/tests/expectations/tests/typeref.rs index 00f8f52742..f4b048c636 100644 --- a/tests/expectations/tests/typeref.rs +++ b/tests/expectations/tests/typeref.rs @@ -22,21 +22,24 @@ fn bindgen_test_layout_mozilla_FragmentOrURL() { 1usize, concat!("Alignment of ", stringify!(mozilla_FragmentOrURL)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mIsLocalRef) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(mozilla_FragmentOrURL), - "::", - stringify!(mIsLocalRef) - ) - ); + fn test_field_mIsLocalRef() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mIsLocalRef) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(mozilla_FragmentOrURL), + "::", + stringify!(mIsLocalRef) + ) + ); + } + test_field_mIsLocalRef(); } #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] @@ -100,15 +103,23 @@ fn bindgen_test_layout_Bar() { 8usize, concat!("Alignment of ", stringify!(Bar)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mFoo) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(mFoo)) - ); + fn test_field_mFoo() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mFoo) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Bar), + "::", + stringify!(mFoo) + ) + ); + } + test_field_mFoo(); } impl Default for Bar { fn default() -> Self { @@ -135,20 +146,23 @@ fn bindgen_test_layout_nsFoo() { 8usize, concat!("Alignment of ", stringify!(nsFoo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsFoo), - "::", - stringify!(mBar) - ) - ); + fn test_field_mBar() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(nsFoo), + "::", + stringify!(mBar) + ) + ); + } + test_field_mBar(); } impl Default for nsFoo { fn default() -> Self { diff --git a/tests/expectations/tests/typeref_1_0.rs b/tests/expectations/tests/typeref_1_0.rs index b4d896cd4b..273a7741fd 100644 --- a/tests/expectations/tests/typeref_1_0.rs +++ b/tests/expectations/tests/typeref_1_0.rs @@ -65,21 +65,24 @@ fn bindgen_test_layout_mozilla_FragmentOrURL() { 1usize, concat!("Alignment of ", stringify!(mozilla_FragmentOrURL)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mIsLocalRef) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(mozilla_FragmentOrURL), - "::", - stringify!(mIsLocalRef) - ) - ); + fn test_field_mIsLocalRef() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mIsLocalRef) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(mozilla_FragmentOrURL), + "::", + stringify!(mIsLocalRef) + ) + ); + } + test_field_mIsLocalRef(); } impl Clone for mozilla_FragmentOrURL { fn clone(&self) -> Self { @@ -138,15 +141,23 @@ fn bindgen_test_layout_Bar() { 8usize, concat!("Alignment of ", stringify!(Bar)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mFoo) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(mFoo)) - ); + fn test_field_mFoo() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mFoo) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Bar), + "::", + stringify!(mFoo) + ) + ); + } + test_field_mFoo(); } impl Clone for Bar { fn clone(&self) -> Self { @@ -179,20 +190,23 @@ fn bindgen_test_layout_nsFoo() { 8usize, concat!("Alignment of ", stringify!(nsFoo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsFoo), - "::", - stringify!(mBar) - ) - ); + fn test_field_mBar() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(nsFoo), + "::", + stringify!(mBar) + ) + ); + } + test_field_mBar(); } impl Clone for nsFoo { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/underscore.rs b/tests/expectations/tests/underscore.rs index 8e5e456682..a9c20d0e62 100644 --- a/tests/expectations/tests/underscore.rs +++ b/tests/expectations/tests/underscore.rs @@ -23,13 +23,21 @@ fn bindgen_test_layout_ptr_t() { 1usize, concat!("Alignment of ", stringify!(ptr_t)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).__) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(ptr_t), "::", stringify!(__)) - ); + fn test_field__() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).__) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ptr_t), + "::", + stringify!(__) + ) + ); + } + test_field__(); } diff --git a/tests/expectations/tests/union-align.rs b/tests/expectations/tests/union-align.rs index cb938f4926..53701694c7 100644 --- a/tests/expectations/tests/union-align.rs +++ b/tests/expectations/tests/union-align.rs @@ -23,15 +23,23 @@ fn bindgen_test_layout_Bar() { 16usize, concat!("Alignment of ", stringify!(Bar)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(foo)) - ); + fn test_field_foo() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Bar), + "::", + stringify!(foo) + ) + ); + } + test_field_foo(); } impl Default for Bar { fn default() -> Self { @@ -60,15 +68,23 @@ fn bindgen_test_layout_Baz() { 16usize, concat!("Alignment of ", stringify!(Baz)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Baz), "::", stringify!(bar)) - ); + fn test_field_bar() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Baz), + "::", + stringify!(bar) + ) + ); + } + test_field_bar(); } impl Default for Baz { fn default() -> Self { diff --git a/tests/expectations/tests/union-in-ns.rs b/tests/expectations/tests/union-in-ns.rs index f7187c497b..28e7fa2334 100644 --- a/tests/expectations/tests/union-in-ns.rs +++ b/tests/expectations/tests/union-in-ns.rs @@ -26,20 +26,23 @@ pub mod root { 4usize, concat!("Alignment of ", stringify!(bar)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(baz) - ) - ); + fn test_field_baz() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(bar), + "::", + stringify!(baz) + ) + ); + } + test_field_baz(); } impl Default for bar { fn default() -> Self { diff --git a/tests/expectations/tests/union-in-ns_1_0.rs b/tests/expectations/tests/union-in-ns_1_0.rs index 6e58fee2fd..2d0584a61a 100644 --- a/tests/expectations/tests/union-in-ns_1_0.rs +++ b/tests/expectations/tests/union-in-ns_1_0.rs @@ -73,20 +73,23 @@ pub mod root { 4usize, concat!("Alignment of ", stringify!(bar)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(baz) - ) - ); + fn test_field_baz() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(bar), + "::", + stringify!(baz) + ) + ); + } + test_field_baz(); } impl Clone for bar { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/union_dtor.rs b/tests/expectations/tests/union_dtor.rs index f7240fd577..359005cb4a 100644 --- a/tests/expectations/tests/union_dtor.rs +++ b/tests/expectations/tests/union_dtor.rs @@ -22,34 +22,40 @@ fn bindgen_test_layout_UnionWithDtor() { 8usize, concat!("Alignment of ", stringify!(UnionWithDtor)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mFoo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(UnionWithDtor), - "::", - stringify!(mFoo) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(UnionWithDtor), - "::", - stringify!(mBar) - ) - ); + fn test_field_mFoo() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mFoo) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(UnionWithDtor), + "::", + stringify!(mFoo) + ) + ); + } + test_field_mFoo(); + fn test_field_mBar() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(UnionWithDtor), + "::", + stringify!(mBar) + ) + ); + } + test_field_mBar(); } extern "C" { #[link_name = "\u{1}_ZN13UnionWithDtorD1Ev"] diff --git a/tests/expectations/tests/union_dtor_1_0.rs b/tests/expectations/tests/union_dtor_1_0.rs index 928884de07..68ebced57c 100644 --- a/tests/expectations/tests/union_dtor_1_0.rs +++ b/tests/expectations/tests/union_dtor_1_0.rs @@ -67,34 +67,40 @@ fn bindgen_test_layout_UnionWithDtor() { 8usize, concat!("Alignment of ", stringify!(UnionWithDtor)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mFoo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(UnionWithDtor), - "::", - stringify!(mFoo) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(UnionWithDtor), - "::", - stringify!(mBar) - ) - ); + fn test_field_mFoo() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mFoo) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(UnionWithDtor), + "::", + stringify!(mFoo) + ) + ); + } + test_field_mFoo(); + fn test_field_mBar() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(UnionWithDtor), + "::", + stringify!(mBar) + ) + ); + } + test_field_mBar(); } extern "C" { #[link_name = "\u{1}_ZN13UnionWithDtorD1Ev"] diff --git a/tests/expectations/tests/union_fields.rs b/tests/expectations/tests/union_fields.rs index d0b316a843..7864ac15b1 100644 --- a/tests/expectations/tests/union_fields.rs +++ b/tests/expectations/tests/union_fields.rs @@ -24,48 +24,57 @@ fn bindgen_test_layout_nsStyleUnion() { 8usize, concat!("Alignment of ", stringify!(nsStyleUnion)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mInt) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsStyleUnion), - "::", - stringify!(mInt) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mFloat) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsStyleUnion), - "::", - stringify!(mFloat) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mPointer) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsStyleUnion), - "::", - stringify!(mPointer) - ) - ); + fn test_field_mInt() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mInt) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(nsStyleUnion), + "::", + stringify!(mInt) + ) + ); + } + test_field_mInt(); + fn test_field_mFloat() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mFloat) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(nsStyleUnion), + "::", + stringify!(mFloat) + ) + ); + } + test_field_mFloat(); + fn test_field_mPointer() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mPointer) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(nsStyleUnion), + "::", + stringify!(mPointer) + ) + ); + } + test_field_mPointer(); } impl Default for nsStyleUnion { fn default() -> Self { diff --git a/tests/expectations/tests/union_fields_1_0.rs b/tests/expectations/tests/union_fields_1_0.rs index 90c01f48bd..5fccd4e1d4 100644 --- a/tests/expectations/tests/union_fields_1_0.rs +++ b/tests/expectations/tests/union_fields_1_0.rs @@ -68,48 +68,57 @@ fn bindgen_test_layout_nsStyleUnion() { 8usize, concat!("Alignment of ", stringify!(nsStyleUnion)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mInt) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsStyleUnion), - "::", - stringify!(mInt) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mFloat) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsStyleUnion), - "::", - stringify!(mFloat) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mPointer) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsStyleUnion), - "::", - stringify!(mPointer) - ) - ); + fn test_field_mInt() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mInt) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(nsStyleUnion), + "::", + stringify!(mInt) + ) + ); + } + test_field_mInt(); + fn test_field_mFloat() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mFloat) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(nsStyleUnion), + "::", + stringify!(mFloat) + ) + ); + } + test_field_mFloat(); + fn test_field_mPointer() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mPointer) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(nsStyleUnion), + "::", + stringify!(mPointer) + ) + ); + } + test_field_mPointer(); } impl Clone for nsStyleUnion { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/union_with_anon_struct.rs b/tests/expectations/tests/union_with_anon_struct.rs index d70f7f3880..7a67b2d618 100644 --- a/tests/expectations/tests/union_with_anon_struct.rs +++ b/tests/expectations/tests/union_with_anon_struct.rs @@ -28,34 +28,42 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(a) + ) + ); + } + test_field_a(); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(b) + ) + ); + } + test_field_b(); } #[test] fn bindgen_test_layout_foo() { @@ -69,15 +77,23 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) - ); + fn test_field_bar() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(bar) + ) + ); + } + test_field_bar(); } impl Default for foo { fn default() -> Self { diff --git a/tests/expectations/tests/union_with_anon_struct_1_0.rs b/tests/expectations/tests/union_with_anon_struct_1_0.rs index ba582c1063..aed67ec68b 100644 --- a/tests/expectations/tests/union_with_anon_struct_1_0.rs +++ b/tests/expectations/tests/union_with_anon_struct_1_0.rs @@ -72,34 +72,42 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(a) + ) + ); + } + test_field_a(); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(b) + ) + ); + } + test_field_b(); } impl Clone for foo__bindgen_ty_1 { fn clone(&self) -> Self { @@ -118,15 +126,23 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) - ); + fn test_field_bar() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(bar) + ) + ); + } + test_field_bar(); } impl Clone for foo { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/union_with_anon_struct_bitfield.rs b/tests/expectations/tests/union_with_anon_struct_bitfield.rs index 85bf0dae18..87186fe04f 100644 --- a/tests/expectations/tests/union_with_anon_struct_bitfield.rs +++ b/tests/expectations/tests/union_with_anon_struct_bitfield.rs @@ -174,15 +174,18 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) + ); + } + test_field_a(); } impl Default for foo { fn default() -> Self { diff --git a/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs b/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs index 1989a8305e..66f3367461 100644 --- a/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs +++ b/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs @@ -223,15 +223,18 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) + ); + } + test_field_a(); } impl Clone for foo { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/union_with_anon_union.rs b/tests/expectations/tests/union_with_anon_union.rs index 6c049f9be3..789fb495be 100644 --- a/tests/expectations/tests/union_with_anon_union.rs +++ b/tests/expectations/tests/union_with_anon_union.rs @@ -28,34 +28,42 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(a) + ) + ); + } + test_field_a(); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(b) + ) + ); + } + test_field_b(); } impl Default for foo__bindgen_ty_1 { fn default() -> Self { @@ -78,15 +86,23 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) - ); + fn test_field_bar() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(bar) + ) + ); + } + test_field_bar(); } impl Default for foo { fn default() -> Self { diff --git a/tests/expectations/tests/union_with_anon_union_1_0.rs b/tests/expectations/tests/union_with_anon_union_1_0.rs index 56675f36bc..4bb91cf370 100644 --- a/tests/expectations/tests/union_with_anon_union_1_0.rs +++ b/tests/expectations/tests/union_with_anon_union_1_0.rs @@ -73,34 +73,42 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(a) + ) + ); + } + test_field_a(); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(b) + ) + ); + } + test_field_b(); } impl Clone for foo__bindgen_ty_1 { fn clone(&self) -> Self { @@ -119,15 +127,23 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) - ); + fn test_field_bar() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(bar) + ) + ); + } + test_field_bar(); } impl Clone for foo { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/union_with_anon_unnamed_struct.rs b/tests/expectations/tests/union_with_anon_unnamed_struct.rs index 622bb4a64f..968e20fac5 100644 --- a/tests/expectations/tests/union_with_anon_unnamed_struct.rs +++ b/tests/expectations/tests/union_with_anon_unnamed_struct.rs @@ -31,66 +31,78 @@ fn bindgen_test_layout_pixel__bindgen_ty_1() { 1usize, concat!("Alignment of ", stringify!(pixel__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).r) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(pixel__bindgen_ty_1), - "::", - stringify!(r) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).g) as usize - ptr as usize - }, - 1usize, - concat!( - "Offset of field: ", - stringify!(pixel__bindgen_ty_1), - "::", - stringify!(g) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(pixel__bindgen_ty_1), - "::", - stringify!(b) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 3usize, - concat!( - "Offset of field: ", - stringify!(pixel__bindgen_ty_1), - "::", - stringify!(a) - ) - ); + fn test_field_r() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).r) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(pixel__bindgen_ty_1), + "::", + stringify!(r) + ) + ); + } + test_field_r(); + fn test_field_g() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).g) as usize - ptr as usize + }, + 1usize, + concat!( + "Offset of field: ", + stringify!(pixel__bindgen_ty_1), + "::", + stringify!(g) + ) + ); + } + test_field_g(); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(pixel__bindgen_ty_1), + "::", + stringify!(b) + ) + ); + } + test_field_b(); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 3usize, + concat!( + "Offset of field: ", + stringify!(pixel__bindgen_ty_1), + "::", + stringify!(a) + ) + ); + } + test_field_a(); } #[test] fn bindgen_test_layout_pixel() { @@ -104,20 +116,23 @@ fn bindgen_test_layout_pixel() { 4usize, concat!("Alignment of ", stringify!(pixel)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rgba) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(pixel), - "::", - stringify!(rgba) - ) - ); + fn test_field_rgba() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rgba) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(pixel), + "::", + stringify!(rgba) + ) + ); + } + test_field_rgba(); } impl Default for pixel { fn default() -> Self { diff --git a/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs b/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs index cb4897a825..b6f315bf1d 100644 --- a/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs +++ b/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs @@ -75,66 +75,78 @@ fn bindgen_test_layout_pixel__bindgen_ty_1() { 1usize, concat!("Alignment of ", stringify!(pixel__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).r) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(pixel__bindgen_ty_1), - "::", - stringify!(r) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).g) as usize - ptr as usize - }, - 1usize, - concat!( - "Offset of field: ", - stringify!(pixel__bindgen_ty_1), - "::", - stringify!(g) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(pixel__bindgen_ty_1), - "::", - stringify!(b) - ) - ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 3usize, - concat!( - "Offset of field: ", - stringify!(pixel__bindgen_ty_1), - "::", - stringify!(a) - ) - ); + fn test_field_r() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).r) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(pixel__bindgen_ty_1), + "::", + stringify!(r) + ) + ); + } + test_field_r(); + fn test_field_g() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).g) as usize - ptr as usize + }, + 1usize, + concat!( + "Offset of field: ", + stringify!(pixel__bindgen_ty_1), + "::", + stringify!(g) + ) + ); + } + test_field_g(); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(pixel__bindgen_ty_1), + "::", + stringify!(b) + ) + ); + } + test_field_b(); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 3usize, + concat!( + "Offset of field: ", + stringify!(pixel__bindgen_ty_1), + "::", + stringify!(a) + ) + ); + } + test_field_a(); } impl Clone for pixel__bindgen_ty_1 { fn clone(&self) -> Self { @@ -153,20 +165,23 @@ fn bindgen_test_layout_pixel() { 4usize, concat!("Alignment of ", stringify!(pixel)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rgba) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(pixel), - "::", - stringify!(rgba) - ) - ); + fn test_field_rgba() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).rgba) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(pixel), + "::", + stringify!(rgba) + ) + ); + } + test_field_rgba(); } impl Clone for pixel { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/union_with_anon_unnamed_union.rs b/tests/expectations/tests/union_with_anon_unnamed_union.rs index 2156a325b4..f7defd0654 100644 --- a/tests/expectations/tests/union_with_anon_unnamed_union.rs +++ b/tests/expectations/tests/union_with_anon_unnamed_union.rs @@ -29,34 +29,42 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 2usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(c) - ) - ); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(b) + ) + ); + } + test_field_b(); + fn test_field_c() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(c) + ) + ); + } + test_field_c(); } impl Default for foo__bindgen_ty_1 { fn default() -> Self { @@ -79,15 +87,18 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) + ); + } + test_field_a(); } impl Default for foo { fn default() -> Self { diff --git a/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs b/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs index 613d8e4889..72239a304e 100644 --- a/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs +++ b/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs @@ -74,34 +74,42 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 2usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(c) - ) - ); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(b) + ) + ); + } + test_field_b(); + fn test_field_c() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(c) + ) + ); + } + test_field_c(); } impl Clone for foo__bindgen_ty_1 { fn clone(&self) -> Self { @@ -120,15 +128,18 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) + ); + } + test_field_a(); } impl Clone for foo { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/union_with_big_member.rs b/tests/expectations/tests/union_with_big_member.rs index 66e0ad8a55..72210c8367 100644 --- a/tests/expectations/tests/union_with_big_member.rs +++ b/tests/expectations/tests/union_with_big_member.rs @@ -23,34 +23,40 @@ fn bindgen_test_layout_WithBigArray() { 4usize, concat!("Alignment of ", stringify!(WithBigArray)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigArray), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigArray), - "::", - stringify!(b) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithBigArray), + "::", + stringify!(a) + ) + ); + } + test_field_a(); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithBigArray), + "::", + stringify!(b) + ) + ); + } + test_field_b(); } impl Default for WithBigArray { fn default() -> Self { @@ -79,34 +85,40 @@ fn bindgen_test_layout_WithBigArray2() { 4usize, concat!("Alignment of ", stringify!(WithBigArray2)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigArray2), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigArray2), - "::", - stringify!(b) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithBigArray2), + "::", + stringify!(a) + ) + ); + } + test_field_a(); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithBigArray2), + "::", + stringify!(b) + ) + ); + } + test_field_b(); } impl Default for WithBigArray2 { fn default() -> Self { @@ -135,34 +147,40 @@ fn bindgen_test_layout_WithBigMember() { 4usize, concat!("Alignment of ", stringify!(WithBigMember)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigMember), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigMember), - "::", - stringify!(b) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithBigMember), + "::", + stringify!(a) + ) + ); + } + test_field_a(); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithBigMember), + "::", + stringify!(b) + ) + ); + } + test_field_b(); } impl Default for WithBigMember { fn default() -> Self { diff --git a/tests/expectations/tests/union_with_big_member_1_0.rs b/tests/expectations/tests/union_with_big_member_1_0.rs index 252d2fb830..8be46be7bf 100644 --- a/tests/expectations/tests/union_with_big_member_1_0.rs +++ b/tests/expectations/tests/union_with_big_member_1_0.rs @@ -67,34 +67,40 @@ fn bindgen_test_layout_WithBigArray() { 4usize, concat!("Alignment of ", stringify!(WithBigArray)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigArray), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigArray), - "::", - stringify!(b) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithBigArray), + "::", + stringify!(a) + ) + ); + } + test_field_a(); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithBigArray), + "::", + stringify!(b) + ) + ); + } + test_field_b(); } impl Clone for WithBigArray { fn clone(&self) -> Self { @@ -129,34 +135,40 @@ fn bindgen_test_layout_WithBigArray2() { 4usize, concat!("Alignment of ", stringify!(WithBigArray2)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigArray2), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigArray2), - "::", - stringify!(b) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithBigArray2), + "::", + stringify!(a) + ) + ); + } + test_field_a(); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithBigArray2), + "::", + stringify!(b) + ) + ); + } + test_field_b(); } impl Clone for WithBigArray2 { fn clone(&self) -> Self { @@ -182,34 +194,40 @@ fn bindgen_test_layout_WithBigMember() { 4usize, concat!("Alignment of ", stringify!(WithBigMember)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigMember), - "::", - stringify!(a) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigMember), - "::", - stringify!(b) - ) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithBigMember), + "::", + stringify!(a) + ) + ); + } + test_field_a(); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithBigMember), + "::", + stringify!(b) + ) + ); + } + test_field_b(); } impl Clone for WithBigMember { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/union_with_nesting.rs b/tests/expectations/tests/union_with_nesting.rs index 87556243ea..3ef99f7faa 100644 --- a/tests/expectations/tests/union_with_nesting.rs +++ b/tests/expectations/tests/union_with_nesting.rs @@ -35,38 +35,44 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { 2usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - foo__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b1) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(b1) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - foo__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b2) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(b2) - ) - ); + fn test_field_b1() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + foo__bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b1) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(b1) + ) + ); + } + test_field_b1(); + fn test_field_b2() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + foo__bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b2) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(b2) + ) + ); + } + test_field_b2(); } impl Default for foo__bindgen_ty_1__bindgen_ty_1 { fn default() -> Self { @@ -95,38 +101,44 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { 2usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - foo__bindgen_ty_1__bindgen_ty_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).c1) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(c1) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - foo__bindgen_ty_1__bindgen_ty_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).c2) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(c2) - ) - ); + fn test_field_c1() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + foo__bindgen_ty_1__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).c1) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(c1) + ) + ); + } + test_field_c1(); + fn test_field_c2() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + foo__bindgen_ty_1__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).c2) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(c2) + ) + ); + } + test_field_c2(); } impl Default for foo__bindgen_ty_1__bindgen_ty_2 { fn default() -> Self { @@ -171,15 +183,18 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) + ); + } + test_field_a(); } impl Default for foo { fn default() -> Self { diff --git a/tests/expectations/tests/union_with_nesting_1_0.rs b/tests/expectations/tests/union_with_nesting_1_0.rs index cd6104b788..9d4fc4d25a 100644 --- a/tests/expectations/tests/union_with_nesting_1_0.rs +++ b/tests/expectations/tests/union_with_nesting_1_0.rs @@ -80,38 +80,44 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { 2usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - foo__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b1) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(b1) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - foo__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b2) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(b2) - ) - ); + fn test_field_b1() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + foo__bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b1) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(b1) + ) + ); + } + test_field_b1(); + fn test_field_b2() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + foo__bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).b2) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(b2) + ) + ); + } + test_field_b2(); } impl Clone for foo__bindgen_ty_1__bindgen_ty_1 { fn clone(&self) -> Self { @@ -137,38 +143,44 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { 2usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - foo__bindgen_ty_1__bindgen_ty_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).c1) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(c1) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - foo__bindgen_ty_1__bindgen_ty_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).c2) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(c2) - ) - ); + fn test_field_c1() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + foo__bindgen_ty_1__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).c1) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(c1) + ) + ); + } + test_field_c1(); + fn test_field_c2() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + foo__bindgen_ty_1__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).c2) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(c2) + ) + ); + } + test_field_c2(); } impl Clone for foo__bindgen_ty_1__bindgen_ty_2 { fn clone(&self) -> Self { @@ -205,15 +217,18 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) + ); + } + test_field_a(); } impl Clone for foo { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/unknown_attr.rs b/tests/expectations/tests/unknown_attr.rs index bc2dd0a0e0..cc29d8b3a9 100644 --- a/tests/expectations/tests/unknown_attr.rs +++ b/tests/expectations/tests/unknown_attr.rs @@ -25,34 +25,40 @@ fn bindgen_test_layout_max_align_t() { 16usize, concat!("Alignment of ", stringify!(max_align_t)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).__clang_max_align_nonce1) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(max_align_t), - "::", - stringify!(__clang_max_align_nonce1) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).__clang_max_align_nonce2) as usize - - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(max_align_t), - "::", - stringify!(__clang_max_align_nonce2) - ) - ); + fn test_field___clang_max_align_nonce1() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).__clang_max_align_nonce1) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(max_align_t), + "::", + stringify!(__clang_max_align_nonce1) + ) + ); + } + test_field___clang_max_align_nonce1(); + fn test_field___clang_max_align_nonce2() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).__clang_max_align_nonce2) as usize - + ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(max_align_t), + "::", + stringify!(__clang_max_align_nonce2) + ) + ); + } + test_field___clang_max_align_nonce2(); } diff --git a/tests/expectations/tests/use-core.rs b/tests/expectations/tests/use-core.rs index 49020c7868..cc58821943 100644 --- a/tests/expectations/tests/use-core.rs +++ b/tests/expectations/tests/use-core.rs @@ -26,33 +26,47 @@ fn bindgen_test_layout_foo() { 8usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { - let uninit = ::core::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::core::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) - ); - assert_eq!( - unsafe { - let uninit = ::core::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::core::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 4usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) - ); - assert_eq!( - unsafe { - let uninit = ::core::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 8usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::core::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::core::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) + ); + } + test_field_a(); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = ::core::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::core::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 4usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) + ); + } + test_field_b(); + fn test_field_bar() { + assert_eq!( + unsafe { + let uninit = ::core::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(bar) + ) + ); + } + test_field_bar(); } impl Default for foo { fn default() -> Self { @@ -81,34 +95,42 @@ fn bindgen_test_layout__bindgen_ty_1() { 8usize, concat!("Alignment of ", stringify!(_bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = ::core::mem::MaybeUninit::<_bindgen_ty_1>::uninit(); - let ptr = uninit.as_ptr(); - ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_bindgen_ty_1), - "::", - stringify!(bar) - ) - ); - assert_eq!( - unsafe { - let uninit = ::core::mem::MaybeUninit::<_bindgen_ty_1>::uninit(); - let ptr = uninit.as_ptr(); - ::core::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_bindgen_ty_1), - "::", - stringify!(baz) - ) - ); + fn test_field_bar() { + assert_eq!( + unsafe { + let uninit = + ::core::mem::MaybeUninit::<_bindgen_ty_1>::uninit(); + let ptr = uninit.as_ptr(); + ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_bindgen_ty_1), + "::", + stringify!(bar) + ) + ); + } + test_field_bar(); + fn test_field_baz() { + assert_eq!( + unsafe { + let uninit = + ::core::mem::MaybeUninit::<_bindgen_ty_1>::uninit(); + let ptr = uninit.as_ptr(); + ::core::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_bindgen_ty_1), + "::", + stringify!(baz) + ) + ); + } + test_field_baz(); } impl Default for _bindgen_ty_1 { fn default() -> Self { diff --git a/tests/expectations/tests/use-core_1_0.rs b/tests/expectations/tests/use-core_1_0.rs index fbe27223fe..bb5ce95734 100644 --- a/tests/expectations/tests/use-core_1_0.rs +++ b/tests/expectations/tests/use-core_1_0.rs @@ -69,33 +69,47 @@ fn bindgen_test_layout_foo() { 8usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { - let uninit = ::core::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::core::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) - ); - assert_eq!( - unsafe { - let uninit = ::core::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::core::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 4usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) - ); - assert_eq!( - unsafe { - let uninit = ::core::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 8usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) - ); + fn test_field_a() { + assert_eq!( + unsafe { + let uninit = ::core::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::core::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) + ); + } + test_field_a(); + fn test_field_b() { + assert_eq!( + unsafe { + let uninit = ::core::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::core::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 4usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) + ); + } + test_field_b(); + fn test_field_bar() { + assert_eq!( + unsafe { + let uninit = ::core::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(bar) + ) + ); + } + test_field_bar(); } impl Clone for foo { fn clone(&self) -> Self { @@ -130,34 +144,42 @@ fn bindgen_test_layout__bindgen_ty_1() { 8usize, concat!("Alignment of ", stringify!(_bindgen_ty_1)) ); - assert_eq!( - unsafe { - let uninit = ::core::mem::MaybeUninit::<_bindgen_ty_1>::uninit(); - let ptr = uninit.as_ptr(); - ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_bindgen_ty_1), - "::", - stringify!(bar) - ) - ); - assert_eq!( - unsafe { - let uninit = ::core::mem::MaybeUninit::<_bindgen_ty_1>::uninit(); - let ptr = uninit.as_ptr(); - ::core::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_bindgen_ty_1), - "::", - stringify!(baz) - ) - ); + fn test_field_bar() { + assert_eq!( + unsafe { + let uninit = + ::core::mem::MaybeUninit::<_bindgen_ty_1>::uninit(); + let ptr = uninit.as_ptr(); + ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_bindgen_ty_1), + "::", + stringify!(bar) + ) + ); + } + test_field_bar(); + fn test_field_baz() { + assert_eq!( + unsafe { + let uninit = + ::core::mem::MaybeUninit::<_bindgen_ty_1>::uninit(); + let ptr = uninit.as_ptr(); + ::core::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_bindgen_ty_1), + "::", + stringify!(baz) + ) + ); + } + test_field_baz(); } impl Clone for _bindgen_ty_1 { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/var-tracing.rs b/tests/expectations/tests/var-tracing.rs index a77453c5b1..2ce6853991 100644 --- a/tests/expectations/tests/var-tracing.rs +++ b/tests/expectations/tests/var-tracing.rs @@ -22,20 +22,23 @@ fn bindgen_test_layout_Bar() { 4usize, concat!("Alignment of ", stringify!(Bar)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).m_baz) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(m_baz) - ) - ); + fn test_field_m_baz() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).m_baz) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Bar), + "::", + stringify!(m_baz) + ) + ); + } + test_field_m_baz(); } extern "C" { #[link_name = "\u{1}_ZN3BarC1Ei"] diff --git a/tests/expectations/tests/vector.rs b/tests/expectations/tests/vector.rs index 434e786d8c..936d29c619 100644 --- a/tests/expectations/tests/vector.rs +++ b/tests/expectations/tests/vector.rs @@ -22,20 +22,23 @@ fn bindgen_test_layout_foo() { 8usize, concat!("Alignment of ", stringify!(foo)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(mMember) - ) - ); + fn test_field_mMember() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(mMember) + ) + ); + } + test_field_mMember(); } pub type __m128 = [f32; 4usize]; pub type __m128d = [f64; 2usize]; diff --git a/tests/expectations/tests/virtual_inheritance.rs b/tests/expectations/tests/virtual_inheritance.rs index 85575d2ff7..9e56c8269b 100644 --- a/tests/expectations/tests/virtual_inheritance.rs +++ b/tests/expectations/tests/virtual_inheritance.rs @@ -22,15 +22,18 @@ fn bindgen_test_layout_A() { 4usize, concat!("Alignment of ", stringify!(A)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::
::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(foo)) - ); + fn test_field_foo() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(A), "::", stringify!(foo)) + ); + } + test_field_foo(); } #[repr(C)] pub struct B__bindgen_vtable(::std::os::raw::c_void); @@ -52,15 +55,18 @@ fn bindgen_test_layout_B() { 8usize, concat!("Alignment of ", stringify!(B)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 8usize, - concat!("Offset of field: ", stringify!(B), "::", stringify!(bar)) - ); + fn test_field_bar() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 8usize, + concat!("Offset of field: ", stringify!(B), "::", stringify!(bar)) + ); + } + test_field_bar(); } impl Default for B { fn default() -> Self { @@ -91,15 +97,18 @@ fn bindgen_test_layout_C() { 8usize, concat!("Alignment of ", stringify!(C)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, - 8usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(baz)) - ); + fn test_field_baz() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, + 8usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(baz)) + ); + } + test_field_baz(); } impl Default for C { fn default() -> Self { diff --git a/tests/expectations/tests/weird_bitfields.rs b/tests/expectations/tests/weird_bitfields.rs index 091732d084..c524b90d83 100644 --- a/tests/expectations/tests/weird_bitfields.rs +++ b/tests/expectations/tests/weird_bitfields.rs @@ -131,177 +131,218 @@ fn bindgen_test_layout_Weird() { 4usize, concat!("Alignment of ", stringify!(Weird)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mStrokeDasharrayLength) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mStrokeDasharrayLength) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mClipRule) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mClipRule) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mColorInterpolation) as usize - - ptr as usize - }, - 9usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mColorInterpolation) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mColorInterpolationFilters) as usize - - ptr as usize - }, - 10usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mColorInterpolationFilters) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mFillRule) as usize - ptr as usize - }, - 11usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mFillRule) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mImageRendering) as usize - ptr as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mImageRendering) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mPaintOrder) as usize - ptr as usize - }, - 13usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mPaintOrder) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mShapeRendering) as usize - ptr as usize - }, - 14usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mShapeRendering) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mStrokeLinecap) as usize - ptr as usize - }, - 15usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mStrokeLinecap) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mStrokeLinejoin) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mStrokeLinejoin) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mTextAnchor) as usize - ptr as usize - }, - 17usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mTextAnchor) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mTextRendering) as usize - ptr as usize - }, - 18usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mTextRendering) - ) - ); + fn test_field_mStrokeDasharrayLength() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mStrokeDasharrayLength) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Weird), + "::", + stringify!(mStrokeDasharrayLength) + ) + ); + } + test_field_mStrokeDasharrayLength(); + fn test_field_mClipRule() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mClipRule) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(Weird), + "::", + stringify!(mClipRule) + ) + ); + } + test_field_mClipRule(); + fn test_field_mColorInterpolation() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mColorInterpolation) as usize - + ptr as usize + }, + 9usize, + concat!( + "Offset of field: ", + stringify!(Weird), + "::", + stringify!(mColorInterpolation) + ) + ); + } + test_field_mColorInterpolation(); + fn test_field_mColorInterpolationFilters() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mColorInterpolationFilters) as usize - + ptr as usize + }, + 10usize, + concat!( + "Offset of field: ", + stringify!(Weird), + "::", + stringify!(mColorInterpolationFilters) + ) + ); + } + test_field_mColorInterpolationFilters(); + fn test_field_mFillRule() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mFillRule) as usize - ptr as usize + }, + 11usize, + concat!( + "Offset of field: ", + stringify!(Weird), + "::", + stringify!(mFillRule) + ) + ); + } + test_field_mFillRule(); + fn test_field_mImageRendering() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mImageRendering) as usize - + ptr as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(Weird), + "::", + stringify!(mImageRendering) + ) + ); + } + test_field_mImageRendering(); + fn test_field_mPaintOrder() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mPaintOrder) as usize - ptr as usize + }, + 13usize, + concat!( + "Offset of field: ", + stringify!(Weird), + "::", + stringify!(mPaintOrder) + ) + ); + } + test_field_mPaintOrder(); + fn test_field_mShapeRendering() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mShapeRendering) as usize - + ptr as usize + }, + 14usize, + concat!( + "Offset of field: ", + stringify!(Weird), + "::", + stringify!(mShapeRendering) + ) + ); + } + test_field_mShapeRendering(); + fn test_field_mStrokeLinecap() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mStrokeLinecap) as usize - + ptr as usize + }, + 15usize, + concat!( + "Offset of field: ", + stringify!(Weird), + "::", + stringify!(mStrokeLinecap) + ) + ); + } + test_field_mStrokeLinecap(); + fn test_field_mStrokeLinejoin() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mStrokeLinejoin) as usize - + ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(Weird), + "::", + stringify!(mStrokeLinejoin) + ) + ); + } + test_field_mStrokeLinejoin(); + fn test_field_mTextAnchor() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mTextAnchor) as usize - ptr as usize + }, + 17usize, + concat!( + "Offset of field: ", + stringify!(Weird), + "::", + stringify!(mTextAnchor) + ) + ); + } + test_field_mTextAnchor(); + fn test_field_mTextRendering() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mTextRendering) as usize - + ptr as usize + }, + 18usize, + concat!( + "Offset of field: ", + stringify!(Weird), + "::", + stringify!(mTextRendering) + ) + ); + } + test_field_mTextRendering(); } impl Default for Weird { fn default() -> Self { diff --git a/tests/expectations/tests/zero-size-array-align.rs b/tests/expectations/tests/zero-size-array-align.rs index 6b94324407..31eff3898c 100644 --- a/tests/expectations/tests/zero-size-array-align.rs +++ b/tests/expectations/tests/zero-size-array-align.rs @@ -54,46 +54,55 @@ fn bindgen_test_layout_dm_deps() { 8usize, concat!("Alignment of ", stringify!(dm_deps)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).count) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(dm_deps), - "::", - stringify!(count) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).filler) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(dm_deps), - "::", - stringify!(filler) - ) - ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).device) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(dm_deps), - "::", - stringify!(device) - ) - ); + fn test_field_count() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).count) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(dm_deps), + "::", + stringify!(count) + ) + ); + } + test_field_count(); + fn test_field_filler() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).filler) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(dm_deps), + "::", + stringify!(filler) + ) + ); + } + test_field_filler(); + fn test_field_device() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).device) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(dm_deps), + "::", + stringify!(device) + ) + ); + } + test_field_device(); } diff --git a/tests/expectations/tests/zero-sized-array.rs b/tests/expectations/tests/zero-sized-array.rs index c615ae0bd7..c12afa5995 100644 --- a/tests/expectations/tests/zero-sized-array.rs +++ b/tests/expectations/tests/zero-sized-array.rs @@ -53,20 +53,24 @@ fn bindgen_test_layout_ZeroSizedArray() { 1usize, concat!("Alignment of ", stringify!(ZeroSizedArray)) ); - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ZeroSizedArray), - "::", - stringify!(arr) - ) - ); + fn test_field_arr() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ZeroSizedArray), + "::", + stringify!(arr) + ) + ); + } + test_field_arr(); } /// And nor should this get an `_address` field. #[repr(C)] @@ -86,21 +90,24 @@ fn bindgen_test_layout_ContainsZeroSizedArray() { 1usize, concat!("Alignment of ", stringify!(ContainsZeroSizedArray)) ); - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).zsa) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContainsZeroSizedArray), - "::", - stringify!(zsa) - ) - ); + fn test_field_zsa() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).zsa) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ContainsZeroSizedArray), + "::", + stringify!(zsa) + ) + ); + } + test_field_zsa(); } /// Inheriting from ZeroSizedArray shouldn't cause an `_address` to be inserted /// either. From 9ca5f856a35deddde0575002d76d1db4430e6c42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 6 Jun 2022 12:42:39 +0200 Subject: [PATCH 303/942] Bump version. --- CHANGELOG.md | 8 ++++++++ Cargo.lock | 2 +- Cargo.toml | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad78c1de75..17b3223723 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -151,6 +151,14 @@ ## Security +# 0.60.1 + +Released 2022/06/06 + +## Fixed + + * Fixed stack overflow in generated tests for structs with many fields (#2219). + # 0.60.0 Released 2022/06/05 diff --git a/Cargo.lock b/Cargo.lock index cf52a6f3a4..82ad5f182a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -30,7 +30,7 @@ checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" [[package]] name = "bindgen" -version = "0.60.0" +version = "0.60.1" dependencies = [ "bitflags", "cexpr", diff --git a/Cargo.toml b/Cargo.toml index 302b73bb00..0cbfd05924 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ readme = "README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.60.0" +version = "0.60.1" edition = "2018" build = "build.rs" From 3988fce62fa3e3c96a5c86fc4079ff7cbcc99d04 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 6 Jun 2022 21:05:57 +0000 Subject: [PATCH 304/942] Bump regex from 1.4.6 to 1.5.5 Bumps [regex](https://github.com/rust-lang/regex) from 1.4.6 to 1.5.5. - [Release notes](https://github.com/rust-lang/regex/releases) - [Changelog](https://github.com/rust-lang/regex/blob/master/CHANGELOG.md) - [Commits](https://github.com/rust-lang/regex/compare/1.4.6...1.5.5) --- updated-dependencies: - dependency-name: regex dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- Cargo.lock | 8 ++++---- Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 82ad5f182a..e054462774 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "aho-corasick" -version = "0.7.15" +version = "0.7.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7404febffaa47dac81aa44dba71523c9d069b1bdc50a77db41195149e17f68e5" +checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" dependencies = [ "memchr", ] @@ -321,9 +321,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.4.6" +version = "1.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a26af418b574bd56588335b3a3659a65725d4e636eb1016c2f9e3b38c7cc759" +checksum = "1a11647b6b25ff05a515cb92c365cec08801e83423a235b51e231e1808747286" dependencies = [ "aho-corasick", "memchr", diff --git a/Cargo.toml b/Cargo.toml index 0cbfd05924..b3e4c5016b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,7 +55,7 @@ lazycell = "1" lazy_static = "1" peeking_take_while = "0.1.2" quote = { version = "1", default-features = false } -regex = { version = "1.0", default-features = false , features = [ "std", "unicode"]} +regex = { version = "1.5", default-features = false , features = [ "std", "unicode"]} which = { version = "4.2.1", optional = true, default-features = false } shlex = "1" rustc-hash = "1.0.1" From 798c0566269382868a6b3f54a21a301012935042 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danny=20M=C3=B6sch?= Date: Thu, 23 Jun 2022 11:15:28 +0200 Subject: [PATCH 305/942] Fix link for creduce building/installation --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d4090f6606..0ffd5b4fea 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -404,7 +404,7 @@ $ brew install creduce $ # Etc... ``` -[Otherwise, follow these instructions for building and/or installing `creduce`.](https://github.com/csmith-project/creduce/blob/master/INSTALL) +Otherwise, follow [these instructions](https://github.com/csmith-project/creduce/blob/master/INSTALL.md) for building and/or installing `creduce`. Running `creduce` requires two things: From a1a00434ffc0b5d93ef108d8cc93fafb8c649d83 Mon Sep 17 00:00:00 2001 From: Justin Smith Date: Thu, 16 Jun 2022 09:18:49 -0400 Subject: [PATCH 306/942] Bump msrv to 1.56.1 --- .github/workflows/bindgen.yml | 6 +++--- Cargo.toml | 2 ++ README.md | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 0bc7d235d4..3e2234133a 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -46,13 +46,13 @@ jobs: uses: actions-rs/toolchain@v1 with: profile: minimal - # MSRV below is documented in README.md, please update that if you + # MSRV below is documented in Cargo.toml and README.md, please update those if you # change this. - toolchain: 1.54.0 + toolchain: 1.56.1 override: true - name: Build with msrv - run: rm Cargo.lock && cargo +1.54.0 build --lib + run: rm Cargo.lock && cargo +1.56.1 build --lib quickchecking: runs-on: ubuntu-latest diff --git a/Cargo.toml b/Cargo.toml index b3e4c5016b..f3297d1936 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,8 @@ homepage = "https://rust-lang.github.io/rust-bindgen/" version = "0.60.1" edition = "2018" build = "build.rs" +# If you change this, also update README.md and msrv in .github/workflows/bindgen.yml +rust-version = "1.56.1" include = [ "LICENSE", diff --git a/README.md b/README.md index 4b1194fa2e..3ae5f96733 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ extern "C" { ## MSRV -The minimum supported Rust version is **1.54**. +The minimum supported Rust version is **1.56.1**. No MSRV bump policy has been established yet, so MSRV may increase in any release. From 3c8d6e9c2cdffda944d7f7e7b17fd1abc2cceca4 Mon Sep 17 00:00:00 2001 From: Justin Smith Date: Thu, 23 Jun 2022 12:50:42 -0400 Subject: [PATCH 307/942] Generated name override --- src/callbacks.rs | 6 +++ src/ir/function.rs | 6 +++ .../tests/issue-1375-prefixed-functions.rs | 11 ++++++ tests/headers/issue-1375-prefixed-functions.h | 4 ++ tests/parse_callbacks/mod.rs | 38 ++++++++++++++++++- 5 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 tests/expectations/tests/issue-1375-prefixed-functions.rs create mode 100644 tests/headers/issue-1375-prefixed-functions.h diff --git a/src/callbacks.rs b/src/callbacks.rs index 9b34544947..d0eb466734 100644 --- a/src/callbacks.rs +++ b/src/callbacks.rs @@ -31,6 +31,12 @@ pub trait ParseCallbacks: fmt::Debug + UnwindSafe { MacroParsingBehavior::Default } + /// This function will run for every function. The returned value determines the name visible + /// in the bindings. + fn generated_name_override(&self, _function_name: &str) -> Option { + None + } + /// The integer kind an integer macro should have, given a name and the /// value of that macro, or `None` if you want the default to be chosen. fn int_macro(&self, _name: &str, _value: i64) -> Option { diff --git a/src/ir/function.rs b/src/ir/function.rs index e8e2c2dfed..288c049bf0 100644 --- a/src/ir/function.rs +++ b/src/ir/function.rs @@ -635,6 +635,12 @@ impl ClangSubItemParser for Function { // but seems easy enough to handle it here. name.push_str("_destructor"); } + if let Some(callbacks) = context.parse_callbacks() { + if let Some(nm) = callbacks.generated_name_override(&name) { + name = nm; + } + } + assert!(!name.is_empty(), "Empty function name."); let mangled_name = cursor_mangling(context, &cursor); let comment = cursor.raw_comment(); diff --git a/tests/expectations/tests/issue-1375-prefixed-functions.rs b/tests/expectations/tests/issue-1375-prefixed-functions.rs new file mode 100644 index 0000000000..835b75790d --- /dev/null +++ b/tests/expectations/tests/issue-1375-prefixed-functions.rs @@ -0,0 +1,11 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +extern "C" { + #[link_name = "\u{1}my_custom_prefix_function_name"] + pub fn function_name(x: ::std::os::raw::c_int); +} diff --git a/tests/headers/issue-1375-prefixed-functions.h b/tests/headers/issue-1375-prefixed-functions.h new file mode 100644 index 0000000000..4264e52d65 --- /dev/null +++ b/tests/headers/issue-1375-prefixed-functions.h @@ -0,0 +1,4 @@ +// bindgen-parse-callbacks: remove-function-prefix-my_custom_prefix_ + +void my_custom_prefix_function_name(const int x); + diff --git a/tests/parse_callbacks/mod.rs b/tests/parse_callbacks/mod.rs index b94b54de0b..2dc35a6d2c 100644 --- a/tests/parse_callbacks/mod.rs +++ b/tests/parse_callbacks/mod.rs @@ -1,5 +1,29 @@ use bindgen::callbacks::*; +#[derive(Debug)] +pub struct RemoveFunctionPrefixParseCallback { + pub remove_function_prefix: Option, +} + +impl RemoveFunctionPrefixParseCallback { + pub fn new(prefix: &str) -> Self { + RemoveFunctionPrefixParseCallback { + remove_function_prefix: Some(prefix.to_string()), + } + } +} + +impl ParseCallbacks for RemoveFunctionPrefixParseCallback { + fn generated_name_override(&self, function_name: &str) -> Option { + if let Some(prefix) = &self.remove_function_prefix { + if function_name.starts_with(prefix) { + return Some(function_name[prefix.len()..].to_string()); + } + } + None + } +} + #[derive(Debug)] struct EnumVariantRename; @@ -37,6 +61,18 @@ pub fn lookup(cb: &str) -> Box { "blocklisted-type-implements-trait" => { Box::new(BlocklistedTypeImplementsTrait) } - _ => panic!("Couldn't find name ParseCallbacks: {}", cb), + call_back => { + if call_back.starts_with("remove-function-prefix-") { + let prefix = call_back + .split("remove-function-prefix-") + .last() + .to_owned(); + let lnopc = + RemoveFunctionPrefixParseCallback::new(prefix.unwrap()); + Box::new(lnopc) + } else { + panic!("Couldn't find name ParseCallbacks: {}", cb) + } + } } } From 83d0fd56a73a642956fc642a4bd5a4596ab44ac7 Mon Sep 17 00:00:00 2001 From: onalante-msft <89409054+onalante-msft@users.noreply.github.com> Date: Mon, 27 Jun 2022 11:38:41 -0700 Subject: [PATCH 308/942] Place field alignment test functions before statements Clears clippy::items_after_statements warning for tests. --- src/codegen/mod.rs | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index ee4a6bfd42..2b2857663f 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -2172,9 +2172,9 @@ impl CodeGenerator for CompInfo { let should_skip_field_offset_checks = is_opaque || too_many_base_vtables; - let check_field_offset = if should_skip_field_offset_checks + let (check_field_offset_decls, check_field_offset_invocs) = if should_skip_field_offset_checks { - vec![] + (vec![], vec![]) } else { self.fields() .iter() @@ -2191,34 +2191,37 @@ impl CodeGenerator for CompInfo { // that rustc with opt-level=0 doesn't take // too much stack space, see #2218. let test_fn = Ident::new(&format!("test_field_{}", name), Span::call_site()); - quote! { - fn #test_fn() { - assert_eq!( - unsafe { - let uninit = ::#prefix::mem::MaybeUninit::<#canonical_ident>::uninit(); - let ptr = uninit.as_ptr(); - ::#prefix::ptr::addr_of!((*ptr).#field_name) as usize - ptr as usize - }, - #field_offset, - concat!("Offset of field: ", stringify!(#canonical_ident), "::", stringify!(#field_name)) - ); - } - #test_fn(); - } + ( + quote! { + fn #test_fn() { + assert_eq!( + unsafe { + let uninit = ::#prefix::mem::MaybeUninit::<#canonical_ident>::uninit(); + let ptr = uninit.as_ptr(); + ::#prefix::ptr::addr_of!((*ptr).#field_name) as usize - ptr as usize + }, + #field_offset, + concat!("Offset of field: ", stringify!(#canonical_ident), "::", stringify!(#field_name)) + ); + } + }, + quote! { #test_fn(); } + ) }) }) - .collect::>() + .unzip() }; let item = quote! { #[test] fn #fn_name() { + #( #check_field_offset_decls )* assert_eq!(#size_of_expr, #size, concat!("Size of: ", stringify!(#canonical_ident))); #check_struct_align - #( #check_field_offset )* + #( #check_field_offset_invocs )* } }; result.push(item); From df57bd97910c1261842f3645c64113d6fa199c73 Mon Sep 17 00:00:00 2001 From: onalante-msft <89409054+onalante-msft@users.noreply.github.com> Date: Mon, 27 Jun 2022 12:10:07 -0700 Subject: [PATCH 309/942] Remove functions, use same uninit for all field tests --- src/codegen/mod.rs | 70 ++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 36 deletions(-) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 2b2857663f..607f57ac3e 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -2172,56 +2172,54 @@ impl CodeGenerator for CompInfo { let should_skip_field_offset_checks = is_opaque || too_many_base_vtables; - let (check_field_offset_decls, check_field_offset_invocs) = if should_skip_field_offset_checks + let (uninit_decl, check_field_offset) = if should_skip_field_offset_checks { - (vec![], vec![]) + (None, vec![]) } else { - self.fields() - .iter() - .filter_map(|field| match *field { - Field::DataMember(ref f) if f.name().is_some() => Some(f), - _ => None, - }) - .flat_map(|field| { - let name = field.name().unwrap(); - field.offset().map(|offset| { - let field_offset = offset / 8; - let field_name = ctx.rust_ident(name); - // Put each check in its own function, so - // that rustc with opt-level=0 doesn't take - // too much stack space, see #2218. - let test_fn = Ident::new(&format!("test_field_{}", name), Span::call_site()); - ( + ( + Some(quote! { + // Use a shared MaybeUninit so that rustc with + // opt-level=0 doesn't take too much stack + // space, see #2218. + const UNINIT: ::#prefix::mem::MaybeUninit<#canonical_ident> = ::#prefix::mem::MaybeUninit::uninit(); + }), + self.fields() + .iter() + .filter_map(|field| match *field { + Field::DataMember(ref f) if f.name().is_some() => Some(f), + _ => None, + }) + .flat_map(|field| { + let name = field.name().unwrap(); + field.offset().map(|offset| { + let field_offset = offset / 8; + let field_name = ctx.rust_ident(name); quote! { - fn #test_fn() { - assert_eq!( - unsafe { - let uninit = ::#prefix::mem::MaybeUninit::<#canonical_ident>::uninit(); - let ptr = uninit.as_ptr(); - ::#prefix::ptr::addr_of!((*ptr).#field_name) as usize - ptr as usize - }, - #field_offset, - concat!("Offset of field: ", stringify!(#canonical_ident), "::", stringify!(#field_name)) - ); - } - }, - quote! { #test_fn(); } - ) + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::#prefix::ptr::addr_of!((*ptr).#field_name) as usize - ptr as usize + }, + #field_offset, + concat!("Offset of field: ", stringify!(#canonical_ident), "::", stringify!(#field_name)) + ); + } + }) }) - }) - .unzip() + .collect() + ) }; let item = quote! { #[test] fn #fn_name() { - #( #check_field_offset_decls )* + #uninit_decl assert_eq!(#size_of_expr, #size, concat!("Size of: ", stringify!(#canonical_ident))); #check_struct_align - #( #check_field_offset_invocs )* + #( #check_field_offset )* } }; result.push(item); From 5a4e0d3c7b64aa1347fb1b269e3bc3388db5fe11 Mon Sep 17 00:00:00 2001 From: onalante-msft <89409054+onalante-msft@users.noreply.github.com> Date: Fri, 15 Jul 2022 19:11:04 -0700 Subject: [PATCH 310/942] rustfmt --- src/codegen/mod.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 607f57ac3e..b68b237c0e 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -2172,11 +2172,11 @@ impl CodeGenerator for CompInfo { let should_skip_field_offset_checks = is_opaque || too_many_base_vtables; - let (uninit_decl, check_field_offset) = if should_skip_field_offset_checks - { - (None, vec![]) - } else { - ( + let (uninit_decl, check_field_offset) = + if should_skip_field_offset_checks { + (None, vec![]) + } else { + ( Some(quote! { // Use a shared MaybeUninit so that rustc with // opt-level=0 doesn't take too much stack @@ -2207,8 +2207,8 @@ impl CodeGenerator for CompInfo { }) }) .collect() - ) - }; + ) + }; let item = quote! { #[test] From cb23b471c11aea8232f76c6858b06e0d3badc3c0 Mon Sep 17 00:00:00 2001 From: onalante-msft <89409054+onalante-msft@users.noreply.github.com> Date: Fri, 15 Jul 2022 19:33:39 -0700 Subject: [PATCH 311/942] Only insert uninit_decl if check_field_offset is non-empty --- Cargo.toml | 2 +- src/codegen/mod.rs | 76 ++++++++++++++++++++++++---------------------- 2 files changed, 40 insertions(+), 38 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f3297d1936..2e18545dd9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -57,7 +57,7 @@ lazycell = "1" lazy_static = "1" peeking_take_while = "0.1.2" quote = { version = "1", default-features = false } -regex = { version = "1.5", default-features = false , features = [ "std", "unicode"]} +regex = { version = "1.5", default-features = false , features = ["std", "unicode"] } which = { version = "4.2.1", optional = true, default-features = false } shlex = "1" rustc-hash = "1.0.1" diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index b68b237c0e..80b7233bc7 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -2172,43 +2172,46 @@ impl CodeGenerator for CompInfo { let should_skip_field_offset_checks = is_opaque || too_many_base_vtables; - let (uninit_decl, check_field_offset) = - if should_skip_field_offset_checks { - (None, vec![]) - } else { - ( - Some(quote! { - // Use a shared MaybeUninit so that rustc with - // opt-level=0 doesn't take too much stack - // space, see #2218. - const UNINIT: ::#prefix::mem::MaybeUninit<#canonical_ident> = ::#prefix::mem::MaybeUninit::uninit(); - }), - self.fields() - .iter() - .filter_map(|field| match *field { - Field::DataMember(ref f) if f.name().is_some() => Some(f), - _ => None, - }) - .flat_map(|field| { - let name = field.name().unwrap(); - field.offset().map(|offset| { - let field_offset = offset / 8; - let field_name = ctx.rust_ident(name); - quote! { - assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::#prefix::ptr::addr_of!((*ptr).#field_name) as usize - ptr as usize - }, - #field_offset, - concat!("Offset of field: ", stringify!(#canonical_ident), "::", stringify!(#field_name)) - ); - } - }) + let check_field_offset = if should_skip_field_offset_checks + { + vec![] + } else { + self.fields() + .iter() + .filter_map(|field| match *field { + Field::DataMember(ref f) if f.name().is_some() => Some(f), + _ => None, + }) + .flat_map(|field| { + let name = field.name().unwrap(); + field.offset().map(|offset| { + let field_offset = offset / 8; + let field_name = ctx.rust_ident(name); + quote! { + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::#prefix::ptr::addr_of!((*ptr).#field_name) as usize - ptr as usize + }, + #field_offset, + concat!("Offset of field: ", stringify!(#canonical_ident), "::", stringify!(#field_name)) + ); + } }) - .collect() - ) - }; + }) + .collect() + }; + + let uninit_decl = if !check_field_offset.is_empty() { + Some(quote! { + // Use a shared MaybeUninit so that rustc with + // opt-level=0 doesn't take too much stack space, + // see #2218. + const UNINIT: ::#prefix::mem::MaybeUninit<#canonical_ident> = ::#prefix::mem::MaybeUninit::uninit(); + }) + } else { + None + }; let item = quote! { #[test] @@ -2217,7 +2220,6 @@ impl CodeGenerator for CompInfo { assert_eq!(#size_of_expr, #size, concat!("Size of: ", stringify!(#canonical_ident))); - #check_struct_align #( #check_field_offset )* } From fba40c70e5967a67f7a00991c1544eb9b76abf0a Mon Sep 17 00:00:00 2001 From: onalante-msft <89409054+onalante-msft@users.noreply.github.com> Date: Fri, 15 Jul 2022 21:29:58 -0700 Subject: [PATCH 312/942] Regenerate tests targeting libclang 9 --- tests/expectations/tests/16-byte-alignment.rs | 394 ++- .../tests/16-byte-alignment_1_0.rs | 394 ++- tests/expectations/tests/accessors.rs | 455 ++- tests/expectations/tests/allowlist-file.rs | 100 +- .../tests/allowlist-namespaces.rs | 33 +- .../allowlisted-item-references-no-hash.rs | 32 +- ...llowlisted-item-references-no-partialeq.rs | 32 +- .../allowlisted_item_references_no_copy.rs | 32 +- tests/expectations/tests/annotation_hide.rs | 32 +- .../expectations/tests/anon-fields-prefix.rs | 217 +- tests/expectations/tests/anon_enum.rs | 52 +- .../tests/anon_struct_in_union.rs | 88 +- .../tests/anon_struct_in_union_1_0.rs | 88 +- .../tests/array-of-zero-sized-types.rs | 33 +- .../tests/bindgen-union-inside-namespace.rs | 62 +- tests/expectations/tests/bitfield-linux-32.rs | 27 +- tests/expectations/tests/bitfield_align.rs | 116 +- .../tests/blocklist-and-impl-debug.rs | 34 +- tests/expectations/tests/blocklist-file.rs | 126 +- tests/expectations/tests/blocks-signature.rs | 66 +- tests/expectations/tests/blocks.rs | 66 +- tests/expectations/tests/c_naming.rs | 94 +- tests/expectations/tests/canonical-types.rs | 96 +- tests/expectations/tests/char.rs | 297 +- tests/expectations/tests/class_nested.rs | 118 +- tests/expectations/tests/class_no_members.rs | 34 +- tests/expectations/tests/class_use_as.rs | 64 +- tests/expectations/tests/class_with_dtor.rs | 34 +- .../tests/class_with_inner_struct.rs | 577 ++-- .../tests/class_with_inner_struct_1_0.rs | 577 ++-- .../expectations/tests/class_with_typedef.rs | 134 +- tests/expectations/tests/comment-indent.rs | 33 +- tests/expectations/tests/complex.rs | 128 +- .../expectations/tests/const-const-mut-ptr.rs | 27 +- .../tests/constified-enum-module-overflow.rs | 22 +- .../expectations/tests/constify-all-enums.rs | 34 +- .../tests/constify-module-enums-basic.rs | 34 +- .../tests/constify-module-enums-namespace.rs | 36 +- .../constify-module-enums-shadow-name.rs | 32 +- .../constify-module-enums-simple-alias.rs | 222 +- ...onstify-module-enums-simple-nonamespace.rs | 52 +- .../tests/constify-module-enums-types.rs | 361 +-- .../tests/contains-vs-inherits-zero-sized.rs | 94 +- tests/expectations/tests/convert-floats.rs | 169 +- .../expectations/tests/ctypes-prefix-path.rs | 67 +- .../tests/derive-bitfield-method-same-name.rs | 32 +- tests/expectations/tests/derive-clone.rs | 33 +- tests/expectations/tests/derive-clone_1_0.rs | 33 +- .../tests/derive-debug-bitfield-core.rs | 33 +- .../tests/derive-debug-bitfield.rs | 32 +- .../tests/derive-debug-function-pointer.rs | 62 +- .../tests/derive-debug-mangle-name.rs | 130 +- ...ive-debug-opaque-template-instantiation.rs | 32 +- .../expectations/tests/derive-debug-opaque.rs | 32 +- .../tests/derive-default-and-blocklist.rs | 33 +- tests/expectations/tests/derive-fn-ptr.rs | 64 +- .../tests/derive-hash-and-blocklist.rs | 33 +- .../tests/derive-hash-blocklisting.rs | 66 +- ...rive-hash-struct-with-anon-struct-float.rs | 91 +- .../derive-hash-struct-with-float-array.rs | 27 +- .../tests/derive-hash-struct-with-pointer.rs | 131 +- .../tests/derive-hash-template-inst-float.rs | 59 +- .../tests/derive-partialeq-and-blocklist.rs | 34 +- .../tests/derive-partialeq-base.rs | 32 +- .../tests/derive-partialeq-bitfield.rs | 32 +- .../tests/derive-partialeq-core.rs | 33 +- .../tests/derive-partialeq-pointer.rs | 44 +- .../tests/derive-partialeq-union.rs | 66 +- .../tests/derive-partialeq-union_1_0.rs | 64 +- .../tests/disable-nested-struct-naming.rs | 319 +- .../tests/disable-untagged-union.rs | 52 +- .../expectations/tests/do-not-derive-copy.rs | 34 +- tests/expectations/tests/doggo-or-null.rs | 27 +- .../duplicated-namespaces-definitions.rs | 94 +- .../tests/dynamic_loading_with_blocklist.rs | 22 +- .../tests/dynamic_loading_with_class.rs | 22 +- .../tests/enum-default-bitfield.rs | 32 +- .../expectations/tests/enum-default-consts.rs | 32 +- .../expectations/tests/enum-default-module.rs | 32 +- tests/expectations/tests/enum-default-rust.rs | 32 +- .../expectations/tests/enum-no-debug-rust.rs | 32 +- tests/expectations/tests/enum.rs | 32 +- .../tests/enum_and_vtable_mangling.rs | 22 +- tests/expectations/tests/explicit-padding.rs | 184 +- .../expectations/tests/extern-const-struct.rs | 32 +- .../tests/forward-declaration-autoptr.rs | 32 +- .../tests/forward_declared_complex_types.rs | 22 +- .../forward_declared_complex_types_1_0.rs | 22 +- .../tests/forward_declared_struct.rs | 44 +- .../expectations/tests/func_ptr_in_struct.rs | 27 +- .../expectations/tests/gen-destructors-neg.rs | 27 +- tests/expectations/tests/gen-destructors.rs | 27 +- tests/expectations/tests/i128.rs | 62 +- tests/expectations/tests/inline_namespace.rs | 32 +- .../tests/inline_namespace_conservative.rs | 32 +- tests/expectations/tests/inner_const.rs | 27 +- .../expectations/tests/inner_template_self.rs | 32 +- .../tests/issue-1118-using-forward-decl.rs | 64 +- .../tests/issue-1216-variadic-member.rs | 22 +- tests/expectations/tests/issue-1281.rs | 71 +- tests/expectations/tests/issue-1285.rs | 91 +- tests/expectations/tests/issue-1291.rs | 442 ++- .../tests/issue-1382-rust-primitive-types.rs | 372 +-- tests/expectations/tests/issue-1443.rs | 168 +- tests/expectations/tests/issue-1454.rs | 32 +- tests/expectations/tests/issue-1498.rs | 248 +- tests/expectations/tests/issue-1947.rs | 92 +- .../tests/issue-1977-larger-arrays.rs | 32 +- tests/expectations/tests/issue-1995.rs | 27 +- tests/expectations/tests/issue-2019.rs | 44 +- tests/expectations/tests/issue-372.rs | 131 +- .../tests/issue-537-repr-packed-n.rs | 188 +- tests/expectations/tests/issue-537.rs | 188 +- .../tests/issue-573-layout-test-failures.rs | 32 +- .../issue-574-assertion-failure-in-codegen.rs | 32 +- ...issue-584-stylo-template-analysis-panic.rs | 22 +- .../tests/issue-639-typedef-anon-field.rs | 91 +- .../issue-648-derive-debug-with-padding.rs | 98 +- tests/expectations/tests/issue-674-1.rs | 34 +- tests/expectations/tests/issue-674-2.rs | 54 +- tests/expectations/tests/issue-674-3.rs | 60 +- .../tests/issue-801-opaque-sloppiness.rs | 22 +- ...07-opaque-types-methods-being-generated.rs | 32 +- .../issue-944-derive-copy-and-blocklisting.rs | 33 +- .../expectations/tests/jsval_layout_opaque.rs | 377 ++- .../tests/jsval_layout_opaque_1_0.rs | 377 ++- tests/expectations/tests/layout_arp.rs | 336 +-- tests/expectations/tests/layout_array.rs | 470 ++- .../tests/layout_array_too_long.rs | 458 ++- .../tests/layout_cmdline_token.rs | 290 +- tests/expectations/tests/layout_eth_conf.rs | 2630 +++++++---------- .../expectations/tests/layout_eth_conf_1_0.rs | 2630 +++++++---------- tests/expectations/tests/layout_kni_mbuf.rs | 423 ++- .../tests/layout_large_align_field.rs | 1053 +++---- tests/expectations/tests/layout_mbuf.rs | 1140 ++++--- tests/expectations/tests/layout_mbuf_1_0.rs | 1140 ++++--- .../tests/libclang-9/call-conv-field.rs | 64 +- tests/expectations/tests/libclang-9/class.rs | 806 +++-- .../tests/libclang-9/class_1_0.rs | 806 +++-- ...erive-hash-struct-with-incomplete-array.rs | 204 +- .../libclang-9/incomplete-array-padding.rs | 22 +- .../libclang-9/issue-643-inner-struct.rs | 186 +- .../tests/libclang-9/layout_align.rs | 184 +- .../type_alias_template_specialized.rs | 32 +- .../tests/libclang-9/zero-sized-array.rs | 133 +- tests/expectations/tests/long_double.rs | 27 +- tests/expectations/tests/msvc-no-usr.rs | 22 +- tests/expectations/tests/mutable.rs | 129 +- tests/expectations/tests/namespace.rs | 32 +- tests/expectations/tests/nested.rs | 84 +- .../tests/nested_within_namespace.rs | 97 +- tests/expectations/tests/no-comments.rs | 22 +- tests/expectations/tests/no-derive-debug.rs | 52 +- tests/expectations/tests/no-derive-default.rs | 52 +- .../expectations/tests/no-hash-allowlisted.rs | 27 +- .../tests/no-partialeq-allowlisted.rs | 32 +- .../tests/no-recursive-allowlisting.rs | 27 +- tests/expectations/tests/no-std.rs | 67 +- .../expectations/tests/no_copy_allowlisted.rs | 27 +- .../tests/no_debug_allowlisted.rs | 32 +- .../tests/no_default_allowlisted.rs | 32 +- tests/expectations/tests/non-type-params.rs | 94 +- .../expectations/tests/objc_interface_type.rs | 32 +- .../tests/opaque-template-inst-member-2.rs | 97 +- .../tests/opaque-template-inst-member.rs | 97 +- ...paque-template-instantiation-namespaced.rs | 135 +- .../tests/opaque-template-instantiation.rs | 67 +- tests/expectations/tests/opaque_in_struct.rs | 32 +- tests/expectations/tests/opaque_pointer.rs | 92 +- .../tests/packed-n-with-padding.rs | 102 +- tests/expectations/tests/private.rs | 189 +- tests/expectations/tests/private_fields.rs | 162 +- .../tests/reparented_replacement.rs | 33 +- tests/expectations/tests/replace_use.rs | 22 +- tests/expectations/tests/repr-align.rs | 84 +- ...ame_struct_name_in_different_namespaces.rs | 64 +- .../tests/sentry-defined-multiple-times.rs | 201 +- tests/expectations/tests/size_t_is_usize.rs | 67 +- tests/expectations/tests/size_t_template.rs | 22 +- ...ruct_containing_forward_declared_struct.rs | 54 +- tests/expectations/tests/struct_typedef.rs | 65 +- tests/expectations/tests/struct_typedef_ns.rs | 66 +- .../tests/struct_with_anon_struct.rs | 91 +- .../tests/struct_with_anon_struct_array.rs | 180 +- .../tests/struct_with_anon_struct_pointer.rs | 91 +- .../tests/struct_with_anon_union.rs | 91 +- .../tests/struct_with_anon_union_1_0.rs | 91 +- .../tests/struct_with_anon_unnamed_struct.rs | 64 +- .../tests/struct_with_anon_unnamed_union.rs | 64 +- .../struct_with_anon_unnamed_union_1_0.rs | 64 +- .../tests/struct_with_bitfields.rs | 32 +- .../tests/struct_with_derive_debug.rs | 129 +- .../tests/struct_with_large_array.rs | 32 +- .../expectations/tests/struct_with_nesting.rs | 251 +- .../tests/struct_with_nesting_1_0.rs | 251 +- .../expectations/tests/struct_with_packing.rs | 42 +- .../expectations/tests/struct_with_struct.rs | 91 +- tests/expectations/tests/template.rs | 571 ++-- .../test_mixed_header_and_header_contents.rs | 297 +- .../test_multiple_header_calls_in_builder.rs | 297 +- tests/expectations/tests/timex.rs | 64 +- ...type-referenced-by-allowlisted-function.rs | 32 +- tests/expectations/tests/typeref.rs | 92 +- tests/expectations/tests/typeref_1_0.rs | 92 +- tests/expectations/tests/underscore.rs | 27 +- tests/expectations/tests/union-align.rs | 54 +- tests/expectations/tests/union-in-ns.rs | 32 +- tests/expectations/tests/union-in-ns_1_0.rs | 32 +- tests/expectations/tests/union_dtor.rs | 62 +- tests/expectations/tests/union_dtor_1_0.rs | 62 +- tests/expectations/tests/union_fields.rs | 92 +- tests/expectations/tests/union_fields_1_0.rs | 92 +- .../tests/union_with_anon_struct.rs | 91 +- .../tests/union_with_anon_struct_1_0.rs | 91 +- .../tests/union_with_anon_struct_bitfield.rs | 22 +- .../union_with_anon_struct_bitfield_1_0.rs | 22 +- .../tests/union_with_anon_union.rs | 91 +- .../tests/union_with_anon_union_1_0.rs | 91 +- .../tests/union_with_anon_unnamed_struct.rs | 158 +- .../union_with_anon_unnamed_struct_1_0.rs | 158 +- .../tests/union_with_anon_unnamed_union.rs | 86 +- .../union_with_anon_unnamed_union_1_0.rs | 86 +- .../tests/union_with_big_member.rs | 186 +- .../tests/union_with_big_member_1_0.rs | 186 +- .../expectations/tests/union_with_nesting.rs | 154 +- .../tests/union_with_nesting_1_0.rs | 154 +- tests/expectations/tests/unknown_attr.rs | 66 +- tests/expectations/tests/use-core.rs | 131 +- tests/expectations/tests/use-core_1_0.rs | 131 +- tests/expectations/tests/var-tracing.rs | 32 +- tests/expectations/tests/vector.rs | 32 +- .../expectations/tests/virtual_inheritance.rs | 66 +- tests/expectations/tests/weird_bitfields.rs | 373 +-- .../tests/zero-size-array-align.rs | 92 +- 234 files changed, 14388 insertions(+), 19023 deletions(-) diff --git a/tests/expectations/tests/16-byte-alignment.rs b/tests/expectations/tests/16-byte-alignment.rs index 6aa491d606..e1b6e283f9 100644 --- a/tests/expectations/tests/16-byte-alignment.rs +++ b/tests/expectations/tests/16-byte-alignment.rs @@ -26,6 +26,9 @@ pub struct rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit< + rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1, + > = ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -42,47 +45,37 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1() { stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1) ) ); - fn test_field_dport() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dport) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(dport) - ) - ); - } - test_field_dport(); - fn test_field_sport() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).sport) as usize - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(sport) - ) - ); - } - test_field_sport(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).dport) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(dport) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).sport) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(sport) + ) + ); } #[test] fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -93,25 +86,19 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(rte_ipv4_tuple__bindgen_ty_1)) ); - fn test_field_sctp_tag() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_ipv4_tuple__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).sctp_tag) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple__bindgen_ty_1), - "::", - stringify!(sctp_tag) - ) - ); - } - test_field_sctp_tag(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).sctp_tag) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv4_tuple__bindgen_ty_1), + "::", + stringify!(sctp_tag) + ) + ); } impl Default for rte_ipv4_tuple__bindgen_ty_1 { fn default() -> Self { @@ -124,6 +111,8 @@ impl Default for rte_ipv4_tuple__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_ipv4_tuple() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 12usize, @@ -134,42 +123,32 @@ fn bindgen_test_layout_rte_ipv4_tuple() { 4usize, concat!("Alignment of ", stringify!(rte_ipv4_tuple)) ); - fn test_field_src_addr() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).src_addr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple), - "::", - stringify!(src_addr) - ) - ); - } - test_field_src_addr(); - fn test_field_dst_addr() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dst_addr) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple), - "::", - stringify!(dst_addr) - ) - ); - } - test_field_dst_addr(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).src_addr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv4_tuple), + "::", + stringify!(src_addr) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).dst_addr) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv4_tuple), + "::", + stringify!(dst_addr) + ) + ); } impl Default for rte_ipv4_tuple { fn default() -> Self { @@ -201,6 +180,9 @@ pub struct rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit< + rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1, + > = ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -217,47 +199,37 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1() { stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1) ) ); - fn test_field_dport() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dport) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(dport) - ) - ); - } - test_field_dport(); - fn test_field_sport() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).sport) as usize - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(sport) - ) - ); - } - test_field_sport(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).dport) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(dport) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).sport) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(sport) + ) + ); } #[test] fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -268,25 +240,19 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(rte_ipv6_tuple__bindgen_ty_1)) ); - fn test_field_sctp_tag() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_ipv6_tuple__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).sctp_tag) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple__bindgen_ty_1), - "::", - stringify!(sctp_tag) - ) - ); - } - test_field_sctp_tag(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).sctp_tag) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv6_tuple__bindgen_ty_1), + "::", + stringify!(sctp_tag) + ) + ); } impl Default for rte_ipv6_tuple__bindgen_ty_1 { fn default() -> Self { @@ -299,6 +265,8 @@ impl Default for rte_ipv6_tuple__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_ipv6_tuple() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 36usize, @@ -309,42 +277,32 @@ fn bindgen_test_layout_rte_ipv6_tuple() { 4usize, concat!("Alignment of ", stringify!(rte_ipv6_tuple)) ); - fn test_field_src_addr() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).src_addr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple), - "::", - stringify!(src_addr) - ) - ); - } - test_field_src_addr(); - fn test_field_dst_addr() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dst_addr) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple), - "::", - stringify!(dst_addr) - ) - ); - } - test_field_dst_addr(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).src_addr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv6_tuple), + "::", + stringify!(src_addr) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).dst_addr) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv6_tuple), + "::", + stringify!(dst_addr) + ) + ); } impl Default for rte_ipv6_tuple { fn default() -> Self { @@ -364,6 +322,8 @@ pub union rte_thash_tuple { } #[test] fn bindgen_test_layout_rte_thash_tuple() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 48usize, @@ -374,42 +334,32 @@ fn bindgen_test_layout_rte_thash_tuple() { 16usize, concat!("Alignment of ", stringify!(rte_thash_tuple)) ); - fn test_field_v4() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).v4) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_thash_tuple), - "::", - stringify!(v4) - ) - ); - } - test_field_v4(); - fn test_field_v6() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).v6) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_thash_tuple), - "::", - stringify!(v6) - ) - ); - } - test_field_v6(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).v4) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_thash_tuple), + "::", + stringify!(v4) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).v6) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_thash_tuple), + "::", + stringify!(v6) + ) + ); } impl Default for rte_thash_tuple { fn default() -> Self { diff --git a/tests/expectations/tests/16-byte-alignment_1_0.rs b/tests/expectations/tests/16-byte-alignment_1_0.rs index b798697a68..6b39efdadc 100644 --- a/tests/expectations/tests/16-byte-alignment_1_0.rs +++ b/tests/expectations/tests/16-byte-alignment_1_0.rs @@ -71,6 +71,9 @@ pub struct rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit< + rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1, + > = ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -87,44 +90,32 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1() { stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1) ) ); - fn test_field_dport() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dport) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(dport) - ) - ); - } - test_field_dport(); - fn test_field_sport() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).sport) as usize - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(sport) - ) - ); - } - test_field_sport(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).dport) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(dport) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).sport) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(sport) + ) + ); } impl Clone for rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 { fn clone(&self) -> Self { @@ -133,6 +124,8 @@ impl Clone for rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -143,25 +136,19 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(rte_ipv4_tuple__bindgen_ty_1)) ); - fn test_field_sctp_tag() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_ipv4_tuple__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).sctp_tag) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple__bindgen_ty_1), - "::", - stringify!(sctp_tag) - ) - ); - } - test_field_sctp_tag(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).sctp_tag) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv4_tuple__bindgen_ty_1), + "::", + stringify!(sctp_tag) + ) + ); } impl Clone for rte_ipv4_tuple__bindgen_ty_1 { fn clone(&self) -> Self { @@ -170,6 +157,8 @@ impl Clone for rte_ipv4_tuple__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_ipv4_tuple() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 12usize, @@ -180,42 +169,32 @@ fn bindgen_test_layout_rte_ipv4_tuple() { 4usize, concat!("Alignment of ", stringify!(rte_ipv4_tuple)) ); - fn test_field_src_addr() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).src_addr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple), - "::", - stringify!(src_addr) - ) - ); - } - test_field_src_addr(); - fn test_field_dst_addr() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dst_addr) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple), - "::", - stringify!(dst_addr) - ) - ); - } - test_field_dst_addr(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).src_addr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv4_tuple), + "::", + stringify!(src_addr) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).dst_addr) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv4_tuple), + "::", + stringify!(dst_addr) + ) + ); } impl Clone for rte_ipv4_tuple { fn clone(&self) -> Self { @@ -245,6 +224,9 @@ pub struct rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit< + rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1, + > = ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -261,44 +243,32 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1() { stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1) ) ); - fn test_field_dport() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dport) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(dport) - ) - ); - } - test_field_dport(); - fn test_field_sport() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).sport) as usize - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(sport) - ) - ); - } - test_field_sport(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).dport) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(dport) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).sport) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(sport) + ) + ); } impl Clone for rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 { fn clone(&self) -> Self { @@ -307,6 +277,8 @@ impl Clone for rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -317,25 +289,19 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(rte_ipv6_tuple__bindgen_ty_1)) ); - fn test_field_sctp_tag() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_ipv6_tuple__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).sctp_tag) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple__bindgen_ty_1), - "::", - stringify!(sctp_tag) - ) - ); - } - test_field_sctp_tag(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).sctp_tag) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv6_tuple__bindgen_ty_1), + "::", + stringify!(sctp_tag) + ) + ); } impl Clone for rte_ipv6_tuple__bindgen_ty_1 { fn clone(&self) -> Self { @@ -344,6 +310,8 @@ impl Clone for rte_ipv6_tuple__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_ipv6_tuple() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 36usize, @@ -354,42 +322,32 @@ fn bindgen_test_layout_rte_ipv6_tuple() { 4usize, concat!("Alignment of ", stringify!(rte_ipv6_tuple)) ); - fn test_field_src_addr() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).src_addr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple), - "::", - stringify!(src_addr) - ) - ); - } - test_field_src_addr(); - fn test_field_dst_addr() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dst_addr) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple), - "::", - stringify!(dst_addr) - ) - ); - } - test_field_dst_addr(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).src_addr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv6_tuple), + "::", + stringify!(src_addr) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).dst_addr) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv6_tuple), + "::", + stringify!(dst_addr) + ) + ); } impl Clone for rte_ipv6_tuple { fn clone(&self) -> Self { @@ -405,47 +363,39 @@ pub struct rte_thash_tuple { } #[test] fn bindgen_test_layout_rte_thash_tuple() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 48usize, concat!("Size of: ", stringify!(rte_thash_tuple)) ); - fn test_field_v4() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).v4) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_thash_tuple), - "::", - stringify!(v4) - ) - ); - } - test_field_v4(); - fn test_field_v6() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).v6) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_thash_tuple), - "::", - stringify!(v6) - ) - ); - } - test_field_v6(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).v4) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_thash_tuple), + "::", + stringify!(v4) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).v6) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_thash_tuple), + "::", + stringify!(v6) + ) + ); } impl Clone for rte_thash_tuple { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/accessors.rs b/tests/expectations/tests/accessors.rs index 843b792e68..c38c1d6313 100644 --- a/tests/expectations/tests/accessors.rs +++ b/tests/expectations/tests/accessors.rs @@ -18,6 +18,8 @@ pub struct SomeAccessors { } #[test] fn bindgen_test_layout_SomeAccessors() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -28,77 +30,60 @@ fn bindgen_test_layout_SomeAccessors() { 4usize, concat!("Alignment of ", stringify!(SomeAccessors)) ); - fn test_field_mNoAccessor() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mNoAccessor) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(SomeAccessors), - "::", - stringify!(mNoAccessor) - ) - ); - } - test_field_mNoAccessor(); - fn test_field_mBothAccessors() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBothAccessors) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(SomeAccessors), - "::", - stringify!(mBothAccessors) - ) - ); - } - test_field_mBothAccessors(); - fn test_field_mUnsafeAccessors() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mUnsafeAccessors) as usize - - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(SomeAccessors), - "::", - stringify!(mUnsafeAccessors) - ) - ); - } - test_field_mUnsafeAccessors(); - fn test_field_mImmutableAccessor() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mImmutableAccessor) as usize - - ptr as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(SomeAccessors), - "::", - stringify!(mImmutableAccessor) - ) - ); - } - test_field_mImmutableAccessor(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mNoAccessor) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(SomeAccessors), + "::", + stringify!(mNoAccessor) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBothAccessors) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(SomeAccessors), + "::", + stringify!(mBothAccessors) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mUnsafeAccessors) as usize - + ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(SomeAccessors), + "::", + stringify!(mUnsafeAccessors) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mImmutableAccessor) as usize - + ptr as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(SomeAccessors), + "::", + stringify!(mImmutableAccessor) + ) + ); } impl SomeAccessors { #[inline] @@ -133,6 +118,8 @@ pub struct AllAccessors { } #[test] fn bindgen_test_layout_AllAccessors() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -143,42 +130,33 @@ fn bindgen_test_layout_AllAccessors() { 4usize, concat!("Alignment of ", stringify!(AllAccessors)) ); - fn test_field_mBothAccessors() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBothAccessors) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AllAccessors), - "::", - stringify!(mBothAccessors) - ) - ); - } - test_field_mBothAccessors(); - fn test_field_mAlsoBothAccessors() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mAlsoBothAccessors) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(AllAccessors), - "::", - stringify!(mAlsoBothAccessors) - ) - ); - } - test_field_mAlsoBothAccessors(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBothAccessors) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(AllAccessors), + "::", + stringify!(mBothAccessors) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mAlsoBothAccessors) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(AllAccessors), + "::", + stringify!(mAlsoBothAccessors) + ) + ); } impl AllAccessors { #[inline] @@ -207,6 +185,8 @@ pub struct AllUnsafeAccessors { } #[test] fn bindgen_test_layout_AllUnsafeAccessors() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -217,44 +197,33 @@ fn bindgen_test_layout_AllUnsafeAccessors() { 4usize, concat!("Alignment of ", stringify!(AllUnsafeAccessors)) ); - fn test_field_mBothAccessors() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBothAccessors) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AllUnsafeAccessors), - "::", - stringify!(mBothAccessors) - ) - ); - } - test_field_mBothAccessors(); - fn test_field_mAlsoBothAccessors() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mAlsoBothAccessors) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(AllUnsafeAccessors), - "::", - stringify!(mAlsoBothAccessors) - ) - ); - } - test_field_mAlsoBothAccessors(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBothAccessors) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(AllUnsafeAccessors), + "::", + stringify!(mBothAccessors) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mAlsoBothAccessors) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(AllUnsafeAccessors), + "::", + stringify!(mAlsoBothAccessors) + ) + ); } impl AllUnsafeAccessors { #[inline] @@ -292,6 +261,8 @@ pub struct ContradictAccessors { } #[test] fn bindgen_test_layout_ContradictAccessors() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -302,82 +273,60 @@ fn bindgen_test_layout_ContradictAccessors() { 4usize, concat!("Alignment of ", stringify!(ContradictAccessors)) ); - fn test_field_mBothAccessors() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBothAccessors) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContradictAccessors), - "::", - stringify!(mBothAccessors) - ) - ); - } - test_field_mBothAccessors(); - fn test_field_mNoAccessors() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mNoAccessors) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(ContradictAccessors), - "::", - stringify!(mNoAccessors) - ) - ); - } - test_field_mNoAccessors(); - fn test_field_mUnsafeAccessors() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mUnsafeAccessors) as usize - - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(ContradictAccessors), - "::", - stringify!(mUnsafeAccessors) - ) - ); - } - test_field_mUnsafeAccessors(); - fn test_field_mImmutableAccessor() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mImmutableAccessor) as usize - - ptr as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(ContradictAccessors), - "::", - stringify!(mImmutableAccessor) - ) - ); - } - test_field_mImmutableAccessor(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBothAccessors) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ContradictAccessors), + "::", + stringify!(mBothAccessors) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mNoAccessors) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(ContradictAccessors), + "::", + stringify!(mNoAccessors) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mUnsafeAccessors) as usize - + ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(ContradictAccessors), + "::", + stringify!(mUnsafeAccessors) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mImmutableAccessor) as usize - + ptr as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(ContradictAccessors), + "::", + stringify!(mImmutableAccessor) + ) + ); } impl ContradictAccessors { #[inline] @@ -411,6 +360,8 @@ pub struct Replaced { } #[test] fn bindgen_test_layout_Replaced() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -421,23 +372,19 @@ fn bindgen_test_layout_Replaced() { 4usize, concat!("Alignment of ", stringify!(Replaced)) ); - fn test_field_mAccessor() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mAccessor) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Replaced), - "::", - stringify!(mAccessor) - ) - ); - } - test_field_mAccessor(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mAccessor) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Replaced), + "::", + stringify!(mAccessor) + ) + ); } impl Replaced { #[inline] @@ -457,6 +404,8 @@ pub struct Wrapper { } #[test] fn bindgen_test_layout_Wrapper() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -467,23 +416,19 @@ fn bindgen_test_layout_Wrapper() { 4usize, concat!("Alignment of ", stringify!(Wrapper)) ); - fn test_field_mReplaced() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mReplaced) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Wrapper), - "::", - stringify!(mReplaced) - ) - ); - } - test_field_mReplaced(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mReplaced) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Wrapper), + "::", + stringify!(mReplaced) + ) + ); } impl Wrapper { #[inline] diff --git a/tests/expectations/tests/allowlist-file.rs b/tests/expectations/tests/allowlist-file.rs index e737fe8251..2b6437c041 100644 --- a/tests/expectations/tests/allowlist-file.rs +++ b/tests/expectations/tests/allowlist-file.rs @@ -58,6 +58,8 @@ pub struct StructWithAllowlistedDefinition { } #[test] fn bindgen_test_layout_StructWithAllowlistedDefinition() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -68,25 +70,19 @@ fn bindgen_test_layout_StructWithAllowlistedDefinition() { 8usize, concat!("Alignment of ", stringify!(StructWithAllowlistedDefinition)) ); - fn test_field_other() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - StructWithAllowlistedDefinition, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).other) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(StructWithAllowlistedDefinition), - "::", - stringify!(other) - ) - ); - } - test_field_other(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).other) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(StructWithAllowlistedDefinition), + "::", + stringify!(other) + ) + ); } impl Default for StructWithAllowlistedDefinition { fn default() -> Self { @@ -104,6 +100,8 @@ pub struct StructWithAllowlistedFwdDecl { } #[test] fn bindgen_test_layout_StructWithAllowlistedFwdDecl() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -114,25 +112,19 @@ fn bindgen_test_layout_StructWithAllowlistedFwdDecl() { 4usize, concat!("Alignment of ", stringify!(StructWithAllowlistedFwdDecl)) ); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - StructWithAllowlistedFwdDecl, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(StructWithAllowlistedFwdDecl), - "::", - stringify!(b) - ) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(StructWithAllowlistedFwdDecl), + "::", + stringify!(b) + ) + ); } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -141,6 +133,8 @@ pub struct AllowlistMe { } #[test] fn bindgen_test_layout_AllowlistMe() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -151,21 +145,17 @@ fn bindgen_test_layout_AllowlistMe() { 4usize, concat!("Alignment of ", stringify!(AllowlistMe)) ); - fn test_field_foo() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AllowlistMe), - "::", - stringify!(foo) - ) - ); - } - test_field_foo(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(AllowlistMe), + "::", + stringify!(foo) + ) + ); } diff --git a/tests/expectations/tests/allowlist-namespaces.rs b/tests/expectations/tests/allowlist-namespaces.rs index ac868c646b..dd6ca222b3 100644 --- a/tests/expectations/tests/allowlist-namespaces.rs +++ b/tests/expectations/tests/allowlist-namespaces.rs @@ -41,6 +41,8 @@ pub mod root { } #[test] fn bindgen_test_layout_Test() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -51,24 +53,19 @@ pub mod root { 1usize, concat!("Alignment of ", stringify!(Test)) ); - fn test_field_helper() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).helper) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Test), - "::", - stringify!(helper) - ) - ); - } - test_field_helper(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).helper) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Test), + "::", + stringify!(helper) + ) + ); } } } diff --git a/tests/expectations/tests/allowlisted-item-references-no-hash.rs b/tests/expectations/tests/allowlisted-item-references-no-hash.rs index 827016340f..f78e3cb483 100644 --- a/tests/expectations/tests/allowlisted-item-references-no-hash.rs +++ b/tests/expectations/tests/allowlisted-item-references-no-hash.rs @@ -30,6 +30,8 @@ pub struct AllowlistMe { } #[test] fn bindgen_test_layout_AllowlistMe() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -40,21 +42,17 @@ fn bindgen_test_layout_AllowlistMe() { 1usize, concat!("Alignment of ", stringify!(AllowlistMe)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AllowlistMe), - "::", - stringify!(a) - ) - ); - } - test_field_a(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(AllowlistMe), + "::", + stringify!(a) + ) + ); } diff --git a/tests/expectations/tests/allowlisted-item-references-no-partialeq.rs b/tests/expectations/tests/allowlisted-item-references-no-partialeq.rs index ec4e0c9d0f..e0a2accf4c 100644 --- a/tests/expectations/tests/allowlisted-item-references-no-partialeq.rs +++ b/tests/expectations/tests/allowlisted-item-references-no-partialeq.rs @@ -30,6 +30,8 @@ pub struct AllowlistMe { } #[test] fn bindgen_test_layout_AllowlistMe() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -40,21 +42,17 @@ fn bindgen_test_layout_AllowlistMe() { 1usize, concat!("Alignment of ", stringify!(AllowlistMe)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AllowlistMe), - "::", - stringify!(a) - ) - ); - } - test_field_a(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(AllowlistMe), + "::", + stringify!(a) + ) + ); } diff --git a/tests/expectations/tests/allowlisted_item_references_no_copy.rs b/tests/expectations/tests/allowlisted_item_references_no_copy.rs index 9f6685ec48..4a598831e5 100644 --- a/tests/expectations/tests/allowlisted_item_references_no_copy.rs +++ b/tests/expectations/tests/allowlisted_item_references_no_copy.rs @@ -30,6 +30,8 @@ pub struct AllowlistMe { } #[test] fn bindgen_test_layout_AllowlistMe() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -40,21 +42,17 @@ fn bindgen_test_layout_AllowlistMe() { 1usize, concat!("Alignment of ", stringify!(AllowlistMe)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AllowlistMe), - "::", - stringify!(a) - ) - ); - } - test_field_a(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(AllowlistMe), + "::", + stringify!(a) + ) + ); } diff --git a/tests/expectations/tests/annotation_hide.rs b/tests/expectations/tests/annotation_hide.rs index a899195e1a..3c02bd4d61 100644 --- a/tests/expectations/tests/annotation_hide.rs +++ b/tests/expectations/tests/annotation_hide.rs @@ -32,6 +32,8 @@ pub struct NotAnnotated { } #[test] fn bindgen_test_layout_NotAnnotated() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -42,21 +44,17 @@ fn bindgen_test_layout_NotAnnotated() { 4usize, concat!("Alignment of ", stringify!(NotAnnotated)) ); - fn test_field_f() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NotAnnotated), - "::", - stringify!(f) - ) - ); - } - test_field_f(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(NotAnnotated), + "::", + stringify!(f) + ) + ); } diff --git a/tests/expectations/tests/anon-fields-prefix.rs b/tests/expectations/tests/anon-fields-prefix.rs index a77bc8a753..78e786df03 100644 --- a/tests/expectations/tests/anon-fields-prefix.rs +++ b/tests/expectations/tests/anon-fields-prefix.rs @@ -21,6 +21,8 @@ pub struct color__bindgen_ty_1 { } #[test] fn bindgen_test_layout_color__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 3usize, @@ -31,60 +33,45 @@ fn bindgen_test_layout_color__bindgen_ty_1() { 1usize, concat!("Alignment of ", stringify!(color__bindgen_ty_1)) ); - fn test_field_r() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).r) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(color__bindgen_ty_1), - "::", - stringify!(r) - ) - ); - } - test_field_r(); - fn test_field_g() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).g) as usize - ptr as usize - }, - 1usize, - concat!( - "Offset of field: ", - stringify!(color__bindgen_ty_1), - "::", - stringify!(g) - ) - ); - } - test_field_g(); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(color__bindgen_ty_1), - "::", - stringify!(b) - ) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).r) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(color__bindgen_ty_1), + "::", + stringify!(r) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).g) as usize - ptr as usize + }, + 1usize, + concat!( + "Offset of field: ", + stringify!(color__bindgen_ty_1), + "::", + stringify!(g) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(color__bindgen_ty_1), + "::", + stringify!(b) + ) + ); } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -95,6 +82,8 @@ pub struct color__bindgen_ty_2 { } #[test] fn bindgen_test_layout_color__bindgen_ty_2() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 3usize, @@ -105,63 +94,50 @@ fn bindgen_test_layout_color__bindgen_ty_2() { 1usize, concat!("Alignment of ", stringify!(color__bindgen_ty_2)) ); - fn test_field_y() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(color__bindgen_ty_2), - "::", - stringify!(y) - ) - ); - } - test_field_y(); - fn test_field_u() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize - }, - 1usize, - concat!( - "Offset of field: ", - stringify!(color__bindgen_ty_2), - "::", - stringify!(u) - ) - ); - } - test_field_u(); - fn test_field_v() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).v) as usize - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(color__bindgen_ty_2), - "::", - stringify!(v) - ) - ); - } - test_field_v(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(color__bindgen_ty_2), + "::", + stringify!(y) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize + }, + 1usize, + concat!( + "Offset of field: ", + stringify!(color__bindgen_ty_2), + "::", + stringify!(u) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).v) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(color__bindgen_ty_2), + "::", + stringify!(v) + ) + ); } #[test] fn bindgen_test_layout_color() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 3usize, @@ -172,23 +148,14 @@ fn bindgen_test_layout_color() { 1usize, concat!("Alignment of ", stringify!(color)) ); - fn test_field_v3() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).v3) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(color), - "::", - stringify!(v3) - ) - ); - } - test_field_v3(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).v3) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(color), "::", stringify!(v3)) + ); } impl Default for color { fn default() -> Self { diff --git a/tests/expectations/tests/anon_enum.rs b/tests/expectations/tests/anon_enum.rs index 06e98e7157..bf643e998c 100644 --- a/tests/expectations/tests/anon_enum.rs +++ b/tests/expectations/tests/anon_enum.rs @@ -19,6 +19,8 @@ pub enum Test__bindgen_ty_1 { } #[test] fn bindgen_test_layout_Test() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -29,40 +31,22 @@ fn bindgen_test_layout_Test() { 4usize, concat!("Alignment of ", stringify!(Test)) ); - fn test_field_foo() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Test), - "::", - stringify!(foo) - ) - ); - } - test_field_foo(); - fn test_field_bar() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(Test), - "::", - stringify!(bar) - ) - ); - } - test_field_bar(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(foo)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 4usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(bar)) + ); } #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] diff --git a/tests/expectations/tests/anon_struct_in_union.rs b/tests/expectations/tests/anon_struct_in_union.rs index 49caa13baa..15ec9221fe 100644 --- a/tests/expectations/tests/anon_struct_in_union.rs +++ b/tests/expectations/tests/anon_struct_in_union.rs @@ -22,6 +22,8 @@ pub struct s__bindgen_ty_1_inner { } #[test] fn bindgen_test_layout_s__bindgen_ty_1_inner() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -32,27 +34,24 @@ fn bindgen_test_layout_s__bindgen_ty_1_inner() { 4usize, concat!("Alignment of ", stringify!(s__bindgen_ty_1_inner)) ); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(s__bindgen_ty_1_inner), - "::", - stringify!(b) - ) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(s__bindgen_ty_1_inner), + "::", + stringify!(b) + ) + ); } #[test] fn bindgen_test_layout_s__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -63,24 +62,19 @@ fn bindgen_test_layout_s__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(s__bindgen_ty_1)) ); - fn test_field_field() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).field) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(s__bindgen_ty_1), - "::", - stringify!(field) - ) - ); - } - test_field_field(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).field) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(s__bindgen_ty_1), + "::", + stringify!(field) + ) + ); } impl Default for s__bindgen_ty_1 { fn default() -> Self { @@ -93,6 +87,8 @@ impl Default for s__bindgen_ty_1 { } #[test] fn bindgen_test_layout_s() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -103,18 +99,14 @@ fn bindgen_test_layout_s() { 4usize, concat!("Alignment of ", stringify!(s)) ); - fn test_field_u() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(s), "::", stringify!(u)) - ); - } - test_field_u(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(s), "::", stringify!(u)) + ); } impl Default for s { fn default() -> Self { diff --git a/tests/expectations/tests/anon_struct_in_union_1_0.rs b/tests/expectations/tests/anon_struct_in_union_1_0.rs index 492ed6ca5c..8b04ea03a1 100644 --- a/tests/expectations/tests/anon_struct_in_union_1_0.rs +++ b/tests/expectations/tests/anon_struct_in_union_1_0.rs @@ -66,6 +66,8 @@ pub struct s__bindgen_ty_1_inner { } #[test] fn bindgen_test_layout_s__bindgen_ty_1_inner() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -76,24 +78,19 @@ fn bindgen_test_layout_s__bindgen_ty_1_inner() { 4usize, concat!("Alignment of ", stringify!(s__bindgen_ty_1_inner)) ); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(s__bindgen_ty_1_inner), - "::", - stringify!(b) - ) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(s__bindgen_ty_1_inner), + "::", + stringify!(b) + ) + ); } impl Clone for s__bindgen_ty_1_inner { fn clone(&self) -> Self { @@ -102,6 +99,8 @@ impl Clone for s__bindgen_ty_1_inner { } #[test] fn bindgen_test_layout_s__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -112,24 +111,19 @@ fn bindgen_test_layout_s__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(s__bindgen_ty_1)) ); - fn test_field_field() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).field) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(s__bindgen_ty_1), - "::", - stringify!(field) - ) - ); - } - test_field_field(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).field) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(s__bindgen_ty_1), + "::", + stringify!(field) + ) + ); } impl Clone for s__bindgen_ty_1 { fn clone(&self) -> Self { @@ -138,6 +132,8 @@ impl Clone for s__bindgen_ty_1 { } #[test] fn bindgen_test_layout_s() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -148,18 +144,14 @@ fn bindgen_test_layout_s() { 4usize, concat!("Alignment of ", stringify!(s)) ); - fn test_field_u() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(s), "::", stringify!(u)) - ); - } - test_field_u(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(s), "::", stringify!(u)) + ); } impl Clone for s { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/array-of-zero-sized-types.rs b/tests/expectations/tests/array-of-zero-sized-types.rs index 875aef106d..aed6386a6a 100644 --- a/tests/expectations/tests/array-of-zero-sized-types.rs +++ b/tests/expectations/tests/array-of-zero-sized-types.rs @@ -33,6 +33,8 @@ pub struct HasArrayOfEmpty { } #[test] fn bindgen_test_layout_HasArrayOfEmpty() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 10usize, @@ -43,22 +45,17 @@ fn bindgen_test_layout_HasArrayOfEmpty() { 1usize, concat!("Alignment of ", stringify!(HasArrayOfEmpty)) ); - fn test_field_empties() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).empties) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(HasArrayOfEmpty), - "::", - stringify!(empties) - ) - ); - } - test_field_empties(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).empties) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(HasArrayOfEmpty), + "::", + stringify!(empties) + ) + ); } diff --git a/tests/expectations/tests/bindgen-union-inside-namespace.rs b/tests/expectations/tests/bindgen-union-inside-namespace.rs index 04cdf0b472..fa20e6f754 100644 --- a/tests/expectations/tests/bindgen-union-inside-namespace.rs +++ b/tests/expectations/tests/bindgen-union-inside-namespace.rs @@ -67,6 +67,8 @@ pub mod root { } #[test] fn bindgen_test_layout_Bar() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -77,40 +79,32 @@ pub mod root { 4usize, concat!("Alignment of ", stringify!(Bar)) ); - fn test_field_foo() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(foo) - ) - ); - } - test_field_foo(); - fn test_field_bar() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(bar) - ) - ); - } - test_field_bar(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Bar), + "::", + stringify!(foo) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Bar), + "::", + stringify!(bar) + ) + ); } impl Clone for Bar { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/bitfield-linux-32.rs b/tests/expectations/tests/bitfield-linux-32.rs index dd41d92d43..b80f25145d 100644 --- a/tests/expectations/tests/bitfield-linux-32.rs +++ b/tests/expectations/tests/bitfield-linux-32.rs @@ -100,6 +100,8 @@ pub struct Test { } #[test] fn bindgen_test_layout_Test() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -110,23 +112,14 @@ fn bindgen_test_layout_Test() { 4usize, concat!("Alignment of ", stringify!(Test)) ); - fn test_field_foo() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Test), - "::", - stringify!(foo) - ) - ); - } - test_field_foo(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(foo)) + ); } impl Test { #[inline] diff --git a/tests/expectations/tests/bitfield_align.rs b/tests/expectations/tests/bitfield_align.rs index 1b951336cf..0d67f44e9e 100644 --- a/tests/expectations/tests/bitfield_align.rs +++ b/tests/expectations/tests/bitfield_align.rs @@ -102,6 +102,8 @@ pub struct A { } #[test] fn bindgen_test_layout_A() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -112,30 +114,22 @@ fn bindgen_test_layout_A() { 4usize, concat!("Alignment of ", stringify!(A)) ); - fn test_field_x() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(x)) - ); - } - test_field_x(); - fn test_field_y() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize - }, - 3usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(y)) - ); - } - test_field_y(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(A), "::", stringify!(x)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize + }, + 3usize, + concat!("Offset of field: ", stringify!(A), "::", stringify!(y)) + ); } impl A { #[inline] @@ -401,6 +395,8 @@ pub struct C { } #[test] fn bindgen_test_layout_C() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -411,30 +407,22 @@ fn bindgen_test_layout_C() { 4usize, concat!("Alignment of ", stringify!(C)) ); - fn test_field_x() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(x)) - ); - } - test_field_x(); - fn test_field_baz() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, - 4usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(baz)) - ); - } - test_field_baz(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(x)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, + 4usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(baz)) + ); } impl C { #[inline] @@ -712,6 +700,8 @@ pub struct Date3 { } #[test] fn bindgen_test_layout_Date3() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -722,23 +712,19 @@ fn bindgen_test_layout_Date3() { 2usize, concat!("Alignment of ", stringify!(Date3)) ); - fn test_field_byte() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).byte) as usize - ptr as usize - }, - 3usize, - concat!( - "Offset of field: ", - stringify!(Date3), - "::", - stringify!(byte) - ) - ); - } - test_field_byte(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).byte) as usize - ptr as usize + }, + 3usize, + concat!( + "Offset of field: ", + stringify!(Date3), + "::", + stringify!(byte) + ) + ); } impl Date3 { #[inline] diff --git a/tests/expectations/tests/blocklist-and-impl-debug.rs b/tests/expectations/tests/blocklist-and-impl-debug.rs index 055cca8c12..f72c59bbde 100644 --- a/tests/expectations/tests/blocklist-and-impl-debug.rs +++ b/tests/expectations/tests/blocklist-and-impl-debug.rs @@ -14,6 +14,8 @@ pub struct ShouldManuallyImplDebug { } #[test] fn bindgen_test_layout_ShouldManuallyImplDebug() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -24,25 +26,19 @@ fn bindgen_test_layout_ShouldManuallyImplDebug() { 1usize, concat!("Alignment of ", stringify!(ShouldManuallyImplDebug)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldManuallyImplDebug), - "::", - stringify!(a) - ) - ); - } - test_field_a(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ShouldManuallyImplDebug), + "::", + stringify!(a) + ) + ); } impl Default for ShouldManuallyImplDebug { fn default() -> Self { diff --git a/tests/expectations/tests/blocklist-file.rs b/tests/expectations/tests/blocklist-file.rs index 7843028d64..d897e5930f 100644 --- a/tests/expectations/tests/blocklist-file.rs +++ b/tests/expectations/tests/blocklist-file.rs @@ -14,6 +14,8 @@ pub struct SizedIntegers { } #[test] fn bindgen_test_layout_SizedIntegers() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -24,57 +26,45 @@ fn bindgen_test_layout_SizedIntegers() { 4usize, concat!("Alignment of ", stringify!(SizedIntegers)) ); - fn test_field_x() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(SizedIntegers), - "::", - stringify!(x) - ) - ); - } - test_field_x(); - fn test_field_y() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(SizedIntegers), - "::", - stringify!(y) - ) - ); - } - test_field_y(); - fn test_field_z() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).z) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(SizedIntegers), - "::", - stringify!(z) - ) - ); - } - test_field_z(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(SizedIntegers), + "::", + stringify!(x) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(SizedIntegers), + "::", + stringify!(y) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).z) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(SizedIntegers), + "::", + stringify!(z) + ) + ); } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -83,6 +73,8 @@ pub struct StructWithBlocklistedFwdDecl { } #[test] fn bindgen_test_layout_StructWithBlocklistedFwdDecl() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -93,23 +85,17 @@ fn bindgen_test_layout_StructWithBlocklistedFwdDecl() { 1usize, concat!("Alignment of ", stringify!(StructWithBlocklistedFwdDecl)) ); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - StructWithBlocklistedFwdDecl, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(StructWithBlocklistedFwdDecl), - "::", - stringify!(b) - ) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(StructWithBlocklistedFwdDecl), + "::", + stringify!(b) + ) + ); } diff --git a/tests/expectations/tests/blocks-signature.rs b/tests/expectations/tests/blocks-signature.rs index 048a0d4ebf..faf9521cd6 100644 --- a/tests/expectations/tests/blocks-signature.rs +++ b/tests/expectations/tests/blocks-signature.rs @@ -37,6 +37,8 @@ pub struct contains_block_pointers { } #[test] fn bindgen_test_layout_contains_block_pointers() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -47,44 +49,32 @@ fn bindgen_test_layout_contains_block_pointers() { 8usize, concat!("Alignment of ", stringify!(contains_block_pointers)) ); - fn test_field_val() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).val) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(contains_block_pointers), - "::", - stringify!(val) - ) - ); - } - test_field_val(); - fn test_field_ptr_val() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ptr_val) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(contains_block_pointers), - "::", - stringify!(ptr_val) - ) - ); - } - test_field_ptr_val(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).val) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(contains_block_pointers), + "::", + stringify!(val) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).ptr_val) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(contains_block_pointers), + "::", + stringify!(ptr_val) + ) + ); } impl Default for contains_block_pointers { fn default() -> Self { diff --git a/tests/expectations/tests/blocks.rs b/tests/expectations/tests/blocks.rs index abeec80f83..da4d3e8577 100644 --- a/tests/expectations/tests/blocks.rs +++ b/tests/expectations/tests/blocks.rs @@ -36,6 +36,8 @@ pub struct contains_block_pointers { } #[test] fn bindgen_test_layout_contains_block_pointers() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -46,44 +48,32 @@ fn bindgen_test_layout_contains_block_pointers() { 8usize, concat!("Alignment of ", stringify!(contains_block_pointers)) ); - fn test_field_val() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).val) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(contains_block_pointers), - "::", - stringify!(val) - ) - ); - } - test_field_val(); - fn test_field_ptr_val() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ptr_val) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(contains_block_pointers), - "::", - stringify!(ptr_val) - ) - ); - } - test_field_ptr_val(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).val) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(contains_block_pointers), + "::", + stringify!(val) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).ptr_val) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(contains_block_pointers), + "::", + stringify!(ptr_val) + ) + ); } impl Default for contains_block_pointers { fn default() -> Self { diff --git a/tests/expectations/tests/c_naming.rs b/tests/expectations/tests/c_naming.rs index bc0955fe9d..6c221fcdfe 100644 --- a/tests/expectations/tests/c_naming.rs +++ b/tests/expectations/tests/c_naming.rs @@ -12,6 +12,8 @@ pub struct struct_a { } #[test] fn bindgen_test_layout_struct_a() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -22,23 +24,19 @@ fn bindgen_test_layout_struct_a() { 4usize, concat!("Alignment of ", stringify!(struct_a)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(struct_a), - "::", - stringify!(a) - ) - ); - } - test_field_a(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(struct_a), + "::", + stringify!(a) + ) + ); } pub type a = *const struct_a; #[repr(C)] @@ -49,6 +47,8 @@ pub union union_b { } #[test] fn bindgen_test_layout_union_b() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -59,40 +59,32 @@ fn bindgen_test_layout_union_b() { 4usize, concat!("Alignment of ", stringify!(union_b)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(union_b), - "::", - stringify!(a) - ) - ); - } - test_field_a(); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(union_b), - "::", - stringify!(b) - ) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(union_b), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(union_b), + "::", + stringify!(b) + ) + ); } impl Default for union_b { fn default() -> Self { diff --git a/tests/expectations/tests/canonical-types.rs b/tests/expectations/tests/canonical-types.rs index effe7fed68..b1b88f8ca6 100644 --- a/tests/expectations/tests/canonical-types.rs +++ b/tests/expectations/tests/canonical-types.rs @@ -166,6 +166,8 @@ pub struct ClassAInner { } #[test] fn bindgen_test_layout_ClassAInner() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -176,23 +178,19 @@ fn bindgen_test_layout_ClassAInner() { 8usize, concat!("Alignment of ", stringify!(ClassAInner)) ); - fn test_field_x() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ClassAInner), - "::", - stringify!(x) - ) - ); - } - test_field_x(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ClassAInner), + "::", + stringify!(x) + ) + ); } impl Default for ClassAInner { fn default() -> Self { @@ -210,6 +208,8 @@ pub struct ClassCInnerA { } #[test] fn bindgen_test_layout_ClassCInnerA() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -220,23 +220,19 @@ fn bindgen_test_layout_ClassCInnerA() { 8usize, concat!("Alignment of ", stringify!(ClassCInnerA)) ); - fn test_field_member() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ClassCInnerA), - "::", - stringify!(member) - ) - ); - } - test_field_member(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ClassCInnerA), + "::", + stringify!(member) + ) + ); } impl Default for ClassCInnerA { fn default() -> Self { @@ -254,6 +250,8 @@ pub struct ClassCInnerB { } #[test] fn bindgen_test_layout_ClassCInnerB() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -264,23 +262,19 @@ fn bindgen_test_layout_ClassCInnerB() { 8usize, concat!("Alignment of ", stringify!(ClassCInnerB)) ); - fn test_field_cache() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).cache) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ClassCInnerB), - "::", - stringify!(cache) - ) - ); - } - test_field_cache(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).cache) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ClassCInnerB), + "::", + stringify!(cache) + ) + ); } impl Default for ClassCInnerB { fn default() -> Self { diff --git a/tests/expectations/tests/char.rs b/tests/expectations/tests/char.rs index 3b6e119529..99dbbc8529 100644 --- a/tests/expectations/tests/char.rs +++ b/tests/expectations/tests/char.rs @@ -26,6 +26,8 @@ pub struct Test { } #[test] fn bindgen_test_layout_Test() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 12usize, @@ -36,198 +38,105 @@ fn bindgen_test_layout_Test() { 1usize, concat!("Alignment of ", stringify!(Test)) ); - fn test_field_ch() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ch) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Test), - "::", - stringify!(ch) - ) - ); - } - test_field_ch(); - fn test_field_u() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize - }, - 1usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(u)) - ); - } - test_field_u(); - fn test_field_d() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, - 2usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(d)) - ); - } - test_field_d(); - fn test_field_cch() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).cch) as usize - ptr as usize - }, - 3usize, - concat!( - "Offset of field: ", - stringify!(Test), - "::", - stringify!(cch) - ) - ); - } - test_field_cch(); - fn test_field_cu() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).cu) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(Test), - "::", - stringify!(cu) - ) - ); - } - test_field_cu(); - fn test_field_cd() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).cd) as usize - ptr as usize - }, - 5usize, - concat!( - "Offset of field: ", - stringify!(Test), - "::", - stringify!(cd) - ) - ); - } - test_field_cd(); - fn test_field_Cch() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).Cch) as usize - ptr as usize - }, - 6usize, - concat!( - "Offset of field: ", - stringify!(Test), - "::", - stringify!(Cch) - ) - ); - } - test_field_Cch(); - fn test_field_Cu() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).Cu) as usize - ptr as usize - }, - 7usize, - concat!( - "Offset of field: ", - stringify!(Test), - "::", - stringify!(Cu) - ) - ); - } - test_field_Cu(); - fn test_field_Cd() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).Cd) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(Test), - "::", - stringify!(Cd) - ) - ); - } - test_field_Cd(); - fn test_field_Ccch() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).Ccch) as usize - ptr as usize - }, - 9usize, - concat!( - "Offset of field: ", - stringify!(Test), - "::", - stringify!(Ccch) - ) - ); - } - test_field_Ccch(); - fn test_field_Ccu() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).Ccu) as usize - ptr as usize - }, - 10usize, - concat!( - "Offset of field: ", - stringify!(Test), - "::", - stringify!(Ccu) - ) - ); - } - test_field_Ccu(); - fn test_field_Ccd() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).Ccd) as usize - ptr as usize - }, - 11usize, - concat!( - "Offset of field: ", - stringify!(Test), - "::", - stringify!(Ccd) - ) - ); - } - test_field_Ccd(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).ch) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(ch)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize + }, + 1usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(u)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, + 2usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(d)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).cch) as usize - ptr as usize + }, + 3usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(cch)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).cu) as usize - ptr as usize + }, + 4usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(cu)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).cd) as usize - ptr as usize + }, + 5usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(cd)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).Cch) as usize - ptr as usize + }, + 6usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cch)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).Cu) as usize - ptr as usize + }, + 7usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cu)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).Cd) as usize - ptr as usize + }, + 8usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cd)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).Ccch) as usize - ptr as usize + }, + 9usize, + concat!( + "Offset of field: ", + stringify!(Test), + "::", + stringify!(Ccch) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).Ccu) as usize - ptr as usize + }, + 10usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccu)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).Ccd) as usize - ptr as usize + }, + 11usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccd)) + ); } diff --git a/tests/expectations/tests/class_nested.rs b/tests/expectations/tests/class_nested.rs index 7ea2fe818d..6e5b3f70ff 100644 --- a/tests/expectations/tests/class_nested.rs +++ b/tests/expectations/tests/class_nested.rs @@ -17,6 +17,8 @@ pub struct A_B { } #[test] fn bindgen_test_layout_A_B() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -27,23 +29,19 @@ fn bindgen_test_layout_A_B() { 4usize, concat!("Alignment of ", stringify!(A_B)) ); - fn test_field_member_b() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member_b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(A_B), - "::", - stringify!(member_b) - ) - ); - } - test_field_member_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).member_b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(A_B), + "::", + stringify!(member_b) + ) + ); } #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] @@ -62,6 +60,8 @@ impl Default for A_D { } #[test] fn bindgen_test_layout_A() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -72,23 +72,19 @@ fn bindgen_test_layout_A() { 4usize, concat!("Alignment of ", stringify!(A)) ); - fn test_field_member_a() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member_a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(A), - "::", - stringify!(member_a) - ) - ); - } - test_field_member_a(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).member_a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(A), + "::", + stringify!(member_a) + ) + ); } #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] @@ -97,6 +93,8 @@ pub struct A_C { } #[test] fn bindgen_test_layout_A_C() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -107,23 +105,14 @@ fn bindgen_test_layout_A_C() { 4usize, concat!("Alignment of ", stringify!(A_C)) ); - fn test_field_baz() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(A_C), - "::", - stringify!(baz) - ) - ); - } - test_field_baz(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(A_C), "::", stringify!(baz)) + ); } extern "C" { pub static mut var: A_B; @@ -157,6 +146,8 @@ pub struct D { } #[test] fn bindgen_test_layout_D() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -167,23 +158,14 @@ fn bindgen_test_layout_D() { 4usize, concat!("Alignment of ", stringify!(D)) ); - fn test_field_member() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(D), - "::", - stringify!(member) - ) - ); - } - test_field_member(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(D), "::", stringify!(member)) + ); } #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] diff --git a/tests/expectations/tests/class_no_members.rs b/tests/expectations/tests/class_no_members.rs index 75487a4071..951487452f 100644 --- a/tests/expectations/tests/class_no_members.rs +++ b/tests/expectations/tests/class_no_members.rs @@ -48,6 +48,8 @@ pub struct whatever_child_with_member { } #[test] fn bindgen_test_layout_whatever_child_with_member() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -58,23 +60,17 @@ fn bindgen_test_layout_whatever_child_with_member() { 4usize, concat!("Alignment of ", stringify!(whatever_child_with_member)) ); - fn test_field_m_member() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - whatever_child_with_member, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(whatever_child_with_member), - "::", - stringify!(m_member) - ) - ); - } - test_field_m_member(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(whatever_child_with_member), + "::", + stringify!(m_member) + ) + ); } diff --git a/tests/expectations/tests/class_use_as.rs b/tests/expectations/tests/class_use_as.rs index 12a51bd61c..d73a7f1cfa 100644 --- a/tests/expectations/tests/class_use_as.rs +++ b/tests/expectations/tests/class_use_as.rs @@ -13,6 +13,8 @@ pub struct whatever { } #[test] fn bindgen_test_layout_whatever() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -23,23 +25,19 @@ fn bindgen_test_layout_whatever() { 4usize, concat!("Alignment of ", stringify!(whatever)) ); - fn test_field_replacement() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).replacement) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(whatever), - "::", - stringify!(replacement) - ) - ); - } - test_field_replacement(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).replacement) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(whatever), + "::", + stringify!(replacement) + ) + ); } #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] @@ -48,6 +46,8 @@ pub struct container { } #[test] fn bindgen_test_layout_container() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -58,21 +58,17 @@ fn bindgen_test_layout_container() { 4usize, concat!("Alignment of ", stringify!(container)) ); - fn test_field_c() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(container), - "::", - stringify!(c) - ) - ); - } - test_field_c(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(container), + "::", + stringify!(c) + ) + ); } diff --git a/tests/expectations/tests/class_with_dtor.rs b/tests/expectations/tests/class_with_dtor.rs index a6e7586786..78dd37d4ec 100644 --- a/tests/expectations/tests/class_with_dtor.rs +++ b/tests/expectations/tests/class_with_dtor.rs @@ -28,6 +28,8 @@ pub struct WithoutDtor { } #[test] fn bindgen_test_layout_WithoutDtor() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -38,24 +40,20 @@ fn bindgen_test_layout_WithoutDtor() { 8usize, concat!("Alignment of ", stringify!(WithoutDtor)) ); - fn test_field_shouldBeWithDtor() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).shouldBeWithDtor) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithoutDtor), - "::", - stringify!(shouldBeWithDtor) - ) - ); - } - test_field_shouldBeWithDtor(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).shouldBeWithDtor) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithoutDtor), + "::", + stringify!(shouldBeWithDtor) + ) + ); } impl Default for WithoutDtor { fn default() -> Self { diff --git a/tests/expectations/tests/class_with_inner_struct.rs b/tests/expectations/tests/class_with_inner_struct.rs index ba1373b25f..c8b36e9d8a 100644 --- a/tests/expectations/tests/class_with_inner_struct.rs +++ b/tests/expectations/tests/class_with_inner_struct.rs @@ -20,6 +20,8 @@ pub struct A_Segment { } #[test] fn bindgen_test_layout_A_Segment() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -30,40 +32,32 @@ fn bindgen_test_layout_A_Segment() { 4usize, concat!("Alignment of ", stringify!(A_Segment)) ); - fn test_field_begin() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(A_Segment), - "::", - stringify!(begin) - ) - ); - } - test_field_begin(); - fn test_field_end() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(A_Segment), - "::", - stringify!(end) - ) - ); - } - test_field_end(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(A_Segment), + "::", + stringify!(begin) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(A_Segment), + "::", + stringify!(end) + ) + ); } #[repr(C)] #[derive(Copy, Clone)] @@ -72,6 +66,8 @@ pub union A__bindgen_ty_1 { } #[test] fn bindgen_test_layout_A__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -82,24 +78,19 @@ fn bindgen_test_layout_A__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(A__bindgen_ty_1)) ); - fn test_field_f() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(A__bindgen_ty_1), - "::", - stringify!(f) - ) - ); - } - test_field_f(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(A__bindgen_ty_1), + "::", + stringify!(f) + ) + ); } impl Default for A__bindgen_ty_1 { fn default() -> Self { @@ -117,6 +108,8 @@ pub union A__bindgen_ty_2 { } #[test] fn bindgen_test_layout_A__bindgen_ty_2() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -127,24 +120,19 @@ fn bindgen_test_layout_A__bindgen_ty_2() { 4usize, concat!("Alignment of ", stringify!(A__bindgen_ty_2)) ); - fn test_field_d() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(A__bindgen_ty_2), - "::", - stringify!(d) - ) - ); - } - test_field_d(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(A__bindgen_ty_2), + "::", + stringify!(d) + ) + ); } impl Default for A__bindgen_ty_2 { fn default() -> Self { @@ -157,6 +145,8 @@ impl Default for A__bindgen_ty_2 { } #[test] fn bindgen_test_layout_A() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 12usize, @@ -167,35 +157,27 @@ fn bindgen_test_layout_A() { 4usize, concat!("Alignment of ", stringify!(A)) ); - fn test_field_c() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(c)) - ); - } - test_field_c(); - fn test_field_named_union() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).named_union) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(A), - "::", - stringify!(named_union) - ) - ); - } - test_field_named_union(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(A), "::", stringify!(c)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).named_union) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(A), + "::", + stringify!(named_union) + ) + ); } impl Default for A { fn default() -> Self { @@ -219,6 +201,8 @@ pub struct B_Segment { } #[test] fn bindgen_test_layout_B_Segment() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -229,43 +213,37 @@ fn bindgen_test_layout_B_Segment() { 4usize, concat!("Alignment of ", stringify!(B_Segment)) ); - fn test_field_begin() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(B_Segment), - "::", - stringify!(begin) - ) - ); - } - test_field_begin(); - fn test_field_end() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(B_Segment), - "::", - stringify!(end) - ) - ); - } - test_field_end(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(B_Segment), + "::", + stringify!(begin) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(B_Segment), + "::", + stringify!(end) + ) + ); } #[test] fn bindgen_test_layout_B() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -276,18 +254,14 @@ fn bindgen_test_layout_B() { 4usize, concat!("Alignment of ", stringify!(B)) ); - fn test_field_d() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(B), "::", stringify!(d)) - ); - } - test_field_d(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(B), "::", stringify!(d)) + ); } #[repr(i32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] @@ -319,6 +293,8 @@ pub struct C__bindgen_ty_1__bindgen_ty_1 { } #[test] fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -329,82 +305,58 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(C__bindgen_ty_1__bindgen_ty_1)) ); - fn test_field_mX1() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mX1) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(mX1) - ) - ); - } - test_field_mX1(); - fn test_field_mY1() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mY1) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(mY1) - ) - ); - } - test_field_mY1(); - fn test_field_mX2() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mX2) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(mX2) - ) - ); - } - test_field_mX2(); - fn test_field_mY2() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mY2) as usize - ptr as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(mY2) - ) - ); - } - test_field_mY2(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mX1) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(mX1) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mY1) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(mY1) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mX2) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(C__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(mX2) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mY2) as usize - ptr as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(C__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(mY2) + ) + ); } #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] @@ -414,6 +366,8 @@ pub struct C__bindgen_ty_1__bindgen_ty_2 { } #[test] fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_2() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -424,44 +378,32 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_2() { 4usize, concat!("Alignment of ", stringify!(C__bindgen_ty_1__bindgen_ty_2)) ); - fn test_field_mStepSyntax() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C__bindgen_ty_1__bindgen_ty_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mStepSyntax) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(mStepSyntax) - ) - ); - } - test_field_mStepSyntax(); - fn test_field_mSteps() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C__bindgen_ty_1__bindgen_ty_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mSteps) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(mSteps) - ) - ); - } - test_field_mSteps(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mStepSyntax) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(mStepSyntax) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mSteps) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(mSteps) + ) + ); } impl Default for C__bindgen_ty_1__bindgen_ty_2 { fn default() -> Self { @@ -474,6 +416,8 @@ impl Default for C__bindgen_ty_1__bindgen_ty_2 { } #[test] fn bindgen_test_layout_C__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -484,24 +428,19 @@ fn bindgen_test_layout_C__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(C__bindgen_ty_1)) ); - fn test_field_mFunc() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mFunc) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1), - "::", - stringify!(mFunc) - ) - ); - } - test_field_mFunc(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mFunc) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C__bindgen_ty_1), + "::", + stringify!(mFunc) + ) + ); } impl Default for C__bindgen_ty_1 { fn default() -> Self { @@ -520,6 +459,8 @@ pub struct C_Segment { } #[test] fn bindgen_test_layout_C_Segment() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -530,43 +471,37 @@ fn bindgen_test_layout_C_Segment() { 4usize, concat!("Alignment of ", stringify!(C_Segment)) ); - fn test_field_begin() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_Segment), - "::", - stringify!(begin) - ) - ); - } - test_field_begin(); - fn test_field_end() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_Segment), - "::", - stringify!(end) - ) - ); - } - test_field_end(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_Segment), + "::", + stringify!(begin) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_Segment), + "::", + stringify!(end) + ) + ); } #[test] fn bindgen_test_layout_C() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 20usize, @@ -577,18 +512,14 @@ fn bindgen_test_layout_C() { 4usize, concat!("Alignment of ", stringify!(C)) ); - fn test_field_d() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(d)) - ); - } - test_field_d(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(d)) + ); } impl Default for C { fn default() -> Self { diff --git a/tests/expectations/tests/class_with_inner_struct_1_0.rs b/tests/expectations/tests/class_with_inner_struct_1_0.rs index 3774c1442a..5a3116fd1d 100644 --- a/tests/expectations/tests/class_with_inner_struct_1_0.rs +++ b/tests/expectations/tests/class_with_inner_struct_1_0.rs @@ -63,6 +63,8 @@ pub struct A_Segment { } #[test] fn bindgen_test_layout_A_Segment() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -73,40 +75,32 @@ fn bindgen_test_layout_A_Segment() { 4usize, concat!("Alignment of ", stringify!(A_Segment)) ); - fn test_field_begin() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(A_Segment), - "::", - stringify!(begin) - ) - ); - } - test_field_begin(); - fn test_field_end() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(A_Segment), - "::", - stringify!(end) - ) - ); - } - test_field_end(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(A_Segment), + "::", + stringify!(begin) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(A_Segment), + "::", + stringify!(end) + ) + ); } impl Clone for A_Segment { fn clone(&self) -> Self { @@ -121,6 +115,8 @@ pub struct A__bindgen_ty_1 { } #[test] fn bindgen_test_layout_A__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -131,24 +127,19 @@ fn bindgen_test_layout_A__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(A__bindgen_ty_1)) ); - fn test_field_f() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(A__bindgen_ty_1), - "::", - stringify!(f) - ) - ); - } - test_field_f(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(A__bindgen_ty_1), + "::", + stringify!(f) + ) + ); } impl Clone for A__bindgen_ty_1 { fn clone(&self) -> Self { @@ -163,6 +154,8 @@ pub struct A__bindgen_ty_2 { } #[test] fn bindgen_test_layout_A__bindgen_ty_2() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -173,24 +166,19 @@ fn bindgen_test_layout_A__bindgen_ty_2() { 4usize, concat!("Alignment of ", stringify!(A__bindgen_ty_2)) ); - fn test_field_d() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(A__bindgen_ty_2), - "::", - stringify!(d) - ) - ); - } - test_field_d(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(A__bindgen_ty_2), + "::", + stringify!(d) + ) + ); } impl Clone for A__bindgen_ty_2 { fn clone(&self) -> Self { @@ -199,6 +187,8 @@ impl Clone for A__bindgen_ty_2 { } #[test] fn bindgen_test_layout_A() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 12usize, @@ -209,35 +199,27 @@ fn bindgen_test_layout_A() { 4usize, concat!("Alignment of ", stringify!(A)) ); - fn test_field_c() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(c)) - ); - } - test_field_c(); - fn test_field_named_union() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).named_union) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(A), - "::", - stringify!(named_union) - ) - ); - } - test_field_named_union(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(A), "::", stringify!(c)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).named_union) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(A), + "::", + stringify!(named_union) + ) + ); } impl Clone for A { fn clone(&self) -> Self { @@ -257,6 +239,8 @@ pub struct B_Segment { } #[test] fn bindgen_test_layout_B_Segment() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -267,40 +251,32 @@ fn bindgen_test_layout_B_Segment() { 4usize, concat!("Alignment of ", stringify!(B_Segment)) ); - fn test_field_begin() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(B_Segment), - "::", - stringify!(begin) - ) - ); - } - test_field_begin(); - fn test_field_end() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(B_Segment), - "::", - stringify!(end) - ) - ); - } - test_field_end(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(B_Segment), + "::", + stringify!(begin) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(B_Segment), + "::", + stringify!(end) + ) + ); } impl Clone for B_Segment { fn clone(&self) -> Self { @@ -309,6 +285,8 @@ impl Clone for B_Segment { } #[test] fn bindgen_test_layout_B() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -319,18 +297,14 @@ fn bindgen_test_layout_B() { 4usize, concat!("Alignment of ", stringify!(B)) ); - fn test_field_d() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(B), "::", stringify!(d)) - ); - } - test_field_d(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(B), "::", stringify!(d)) + ); } impl Clone for B { fn clone(&self) -> Self { @@ -368,6 +342,8 @@ pub struct C__bindgen_ty_1__bindgen_ty_1 { } #[test] fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -378,82 +354,58 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(C__bindgen_ty_1__bindgen_ty_1)) ); - fn test_field_mX1() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mX1) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(mX1) - ) - ); - } - test_field_mX1(); - fn test_field_mY1() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mY1) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(mY1) - ) - ); - } - test_field_mY1(); - fn test_field_mX2() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mX2) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(mX2) - ) - ); - } - test_field_mX2(); - fn test_field_mY2() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mY2) as usize - ptr as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(mY2) - ) - ); - } - test_field_mY2(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mX1) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(mX1) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mY1) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(mY1) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mX2) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(C__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(mX2) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mY2) as usize - ptr as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(C__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(mY2) + ) + ); } impl Clone for C__bindgen_ty_1__bindgen_ty_1 { fn clone(&self) -> Self { @@ -468,6 +420,8 @@ pub struct C__bindgen_ty_1__bindgen_ty_2 { } #[test] fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_2() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -478,44 +432,32 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_2() { 4usize, concat!("Alignment of ", stringify!(C__bindgen_ty_1__bindgen_ty_2)) ); - fn test_field_mStepSyntax() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C__bindgen_ty_1__bindgen_ty_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mStepSyntax) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(mStepSyntax) - ) - ); - } - test_field_mStepSyntax(); - fn test_field_mSteps() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C__bindgen_ty_1__bindgen_ty_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mSteps) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(mSteps) - ) - ); - } - test_field_mSteps(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mStepSyntax) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(mStepSyntax) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mSteps) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(mSteps) + ) + ); } impl Clone for C__bindgen_ty_1__bindgen_ty_2 { fn clone(&self) -> Self { @@ -533,6 +475,8 @@ impl Default for C__bindgen_ty_1__bindgen_ty_2 { } #[test] fn bindgen_test_layout_C__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -543,24 +487,19 @@ fn bindgen_test_layout_C__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(C__bindgen_ty_1)) ); - fn test_field_mFunc() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mFunc) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1), - "::", - stringify!(mFunc) - ) - ); - } - test_field_mFunc(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mFunc) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C__bindgen_ty_1), + "::", + stringify!(mFunc) + ) + ); } impl Clone for C__bindgen_ty_1 { fn clone(&self) -> Self { @@ -575,6 +514,8 @@ pub struct C_Segment { } #[test] fn bindgen_test_layout_C_Segment() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -585,40 +526,32 @@ fn bindgen_test_layout_C_Segment() { 4usize, concat!("Alignment of ", stringify!(C_Segment)) ); - fn test_field_begin() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_Segment), - "::", - stringify!(begin) - ) - ); - } - test_field_begin(); - fn test_field_end() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_Segment), - "::", - stringify!(end) - ) - ); - } - test_field_end(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_Segment), + "::", + stringify!(begin) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_Segment), + "::", + stringify!(end) + ) + ); } impl Clone for C_Segment { fn clone(&self) -> Self { @@ -627,6 +560,8 @@ impl Clone for C_Segment { } #[test] fn bindgen_test_layout_C() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 20usize, @@ -637,18 +572,14 @@ fn bindgen_test_layout_C() { 4usize, concat!("Alignment of ", stringify!(C)) ); - fn test_field_d() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(d)) - ); - } - test_field_d(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(d)) + ); } impl Clone for C { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/class_with_typedef.rs b/tests/expectations/tests/class_with_typedef.rs index 6df675b9c4..74b938e6cf 100644 --- a/tests/expectations/tests/class_with_typedef.rs +++ b/tests/expectations/tests/class_with_typedef.rs @@ -19,6 +19,8 @@ pub type C_MyInt = ::std::os::raw::c_int; pub type C_Lookup = *const ::std::os::raw::c_char; #[test] fn bindgen_test_layout_C() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 72usize, @@ -29,71 +31,51 @@ fn bindgen_test_layout_C() { 8usize, concat!("Alignment of ", stringify!(C)) ); - fn test_field_c() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(c)) - ); - } - test_field_c(); - fn test_field_ptr() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize - }, - 8usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(ptr)) - ); - } - test_field_ptr(); - fn test_field_arr() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize - }, - 16usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(arr)) - ); - } - test_field_arr(); - fn test_field_d() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, - 56usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(d)) - ); - } - test_field_d(); - fn test_field_other_ptr() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).other_ptr) as usize - ptr as usize - }, - 64usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(other_ptr) - ) - ); - } - test_field_other_ptr(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(c)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize + }, + 8usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(ptr)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize + }, + 16usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(arr)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, + 56usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(d)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).other_ptr) as usize - ptr as usize + }, + 64usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(other_ptr) + ) + ); } extern "C" { #[link_name = "\u{1}_ZN1C6methodEi"] @@ -146,6 +128,8 @@ pub struct D { } #[test] fn bindgen_test_layout_D() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 80usize, @@ -156,18 +140,14 @@ fn bindgen_test_layout_D() { 8usize, concat!("Alignment of ", stringify!(D)) ); - fn test_field_ptr() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize - }, - 72usize, - concat!("Offset of field: ", stringify!(D), "::", stringify!(ptr)) - ); - } - test_field_ptr(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize + }, + 72usize, + concat!("Offset of field: ", stringify!(D), "::", stringify!(ptr)) + ); } impl Default for D { fn default() -> Self { diff --git a/tests/expectations/tests/comment-indent.rs b/tests/expectations/tests/comment-indent.rs index 93412f2f25..e02bfee0af 100644 --- a/tests/expectations/tests/comment-indent.rs +++ b/tests/expectations/tests/comment-indent.rs @@ -70,6 +70,8 @@ pub mod root { } #[test] fn bindgen_test_layout_Baz() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -80,24 +82,19 @@ pub mod root { 4usize, concat!("Alignment of ", stringify!(Baz)) ); - fn test_field_member() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Baz), - "::", - stringify!(member) - ) - ); - } - test_field_member(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Baz), + "::", + stringify!(member) + ) + ); } /// I'm in an inline namespace, and as such I shouldn't get generated inside /// a rust module, except when the relevant option is specified. Also, this diff --git a/tests/expectations/tests/complex.rs b/tests/expectations/tests/complex.rs index ba1d4ae832..c5633a6cec 100644 --- a/tests/expectations/tests/complex.rs +++ b/tests/expectations/tests/complex.rs @@ -18,6 +18,8 @@ pub struct TestDouble { } #[test] fn bindgen_test_layout_TestDouble() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -28,23 +30,19 @@ fn bindgen_test_layout_TestDouble() { 8usize, concat!("Alignment of ", stringify!(TestDouble)) ); - fn test_field_mMember() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(TestDouble), - "::", - stringify!(mMember) - ) - ); - } - test_field_mMember(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(TestDouble), + "::", + stringify!(mMember) + ) + ); } #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] @@ -53,6 +51,8 @@ pub struct TestDoublePtr { } #[test] fn bindgen_test_layout_TestDoublePtr() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -63,23 +63,19 @@ fn bindgen_test_layout_TestDoublePtr() { 8usize, concat!("Alignment of ", stringify!(TestDoublePtr)) ); - fn test_field_mMember() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(TestDoublePtr), - "::", - stringify!(mMember) - ) - ); - } - test_field_mMember(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(TestDoublePtr), + "::", + stringify!(mMember) + ) + ); } impl Default for TestDoublePtr { fn default() -> Self { @@ -97,6 +93,8 @@ pub struct TestFloat { } #[test] fn bindgen_test_layout_TestFloat() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -107,23 +105,19 @@ fn bindgen_test_layout_TestFloat() { 4usize, concat!("Alignment of ", stringify!(TestFloat)) ); - fn test_field_mMember() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(TestFloat), - "::", - stringify!(mMember) - ) - ); - } - test_field_mMember(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(TestFloat), + "::", + stringify!(mMember) + ) + ); } #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] @@ -132,6 +126,8 @@ pub struct TestFloatPtr { } #[test] fn bindgen_test_layout_TestFloatPtr() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -142,23 +138,19 @@ fn bindgen_test_layout_TestFloatPtr() { 8usize, concat!("Alignment of ", stringify!(TestFloatPtr)) ); - fn test_field_mMember() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(TestFloatPtr), - "::", - stringify!(mMember) - ) - ); - } - test_field_mMember(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(TestFloatPtr), + "::", + stringify!(mMember) + ) + ); } impl Default for TestFloatPtr { fn default() -> Self { diff --git a/tests/expectations/tests/const-const-mut-ptr.rs b/tests/expectations/tests/const-const-mut-ptr.rs index b6b3bdb9ae..5e0c7800f4 100644 --- a/tests/expectations/tests/const-const-mut-ptr.rs +++ b/tests/expectations/tests/const-const-mut-ptr.rs @@ -12,6 +12,8 @@ pub struct foo { } #[test] fn bindgen_test_layout_foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -22,23 +24,14 @@ fn bindgen_test_layout_foo() { 8usize, concat!("Alignment of ", stringify!(foo)) ); - fn test_field_bar() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(bar) - ) - ); - } - test_field_bar(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) + ); } impl Default for foo { fn default() -> Self { diff --git a/tests/expectations/tests/constified-enum-module-overflow.rs b/tests/expectations/tests/constified-enum-module-overflow.rs index df112982b3..ab81b17362 100644 --- a/tests/expectations/tests/constified-enum-module-overflow.rs +++ b/tests/expectations/tests/constified-enum-module-overflow.rs @@ -23,6 +23,8 @@ pub struct A { } #[test] fn bindgen_test_layout_A() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -33,18 +35,14 @@ fn bindgen_test_layout_A() { 1usize, concat!("Alignment of ", stringify!(A)) ); - fn test_field_u() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(u)) - ); - } - test_field_u(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(A), "::", stringify!(u)) + ); } #[test] fn __bindgen_test_layout_C_open0_A_close0_instantiation() { diff --git a/tests/expectations/tests/constify-all-enums.rs b/tests/expectations/tests/constify-all-enums.rs index c926d85766..bfa255d6f9 100644 --- a/tests/expectations/tests/constify-all-enums.rs +++ b/tests/expectations/tests/constify-all-enums.rs @@ -16,6 +16,8 @@ pub struct bar { } #[test] fn bindgen_test_layout_bar() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -26,24 +28,20 @@ fn bindgen_test_layout_bar() { 4usize, concat!("Alignment of ", stringify!(bar)) ); - fn test_field_this_should_work() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).this_should_work) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(this_should_work) - ) - ); - } - test_field_this_should_work(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).this_should_work) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(bar), + "::", + stringify!(this_should_work) + ) + ); } impl Default for bar { fn default() -> Self { diff --git a/tests/expectations/tests/constify-module-enums-basic.rs b/tests/expectations/tests/constify-module-enums-basic.rs index 6078ef20d1..e74eb4433c 100644 --- a/tests/expectations/tests/constify-module-enums-basic.rs +++ b/tests/expectations/tests/constify-module-enums-basic.rs @@ -20,6 +20,8 @@ pub struct bar { } #[test] fn bindgen_test_layout_bar() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -30,24 +32,20 @@ fn bindgen_test_layout_bar() { 4usize, concat!("Alignment of ", stringify!(bar)) ); - fn test_field_this_should_work() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).this_should_work) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(this_should_work) - ) - ); - } - test_field_this_should_work(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).this_should_work) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(bar), + "::", + stringify!(this_should_work) + ) + ); } impl Default for bar { fn default() -> Self { diff --git a/tests/expectations/tests/constify-module-enums-namespace.rs b/tests/expectations/tests/constify-module-enums-namespace.rs index 326c219da3..30955dfe9d 100644 --- a/tests/expectations/tests/constify-module-enums-namespace.rs +++ b/tests/expectations/tests/constify-module-enums-namespace.rs @@ -32,6 +32,8 @@ pub mod root { } #[test] fn bindgen_test_layout_bar() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -42,26 +44,20 @@ pub mod root { 4usize, concat!("Alignment of ", stringify!(bar)) ); - fn test_field_this_should_work() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).this_should_work) - as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(this_should_work) - ) - ); - } - test_field_this_should_work(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).this_should_work) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(bar), + "::", + stringify!(this_should_work) + ) + ); } impl Default for bar { fn default() -> Self { diff --git a/tests/expectations/tests/constify-module-enums-shadow-name.rs b/tests/expectations/tests/constify-module-enums-shadow-name.rs index a5340e698f..21283c1cba 100644 --- a/tests/expectations/tests/constify-module-enums-shadow-name.rs +++ b/tests/expectations/tests/constify-module-enums-shadow-name.rs @@ -19,6 +19,8 @@ pub struct bar { } #[test] fn bindgen_test_layout_bar() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -29,23 +31,19 @@ fn bindgen_test_layout_bar() { 4usize, concat!("Alignment of ", stringify!(bar)) ); - fn test_field_member() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(member) - ) - ); - } - test_field_member(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(bar), + "::", + stringify!(member) + ) + ); } impl Default for bar { fn default() -> Self { diff --git a/tests/expectations/tests/constify-module-enums-simple-alias.rs b/tests/expectations/tests/constify-module-enums-simple-alias.rs index 52d4651697..736a88801a 100644 --- a/tests/expectations/tests/constify-module-enums-simple-alias.rs +++ b/tests/expectations/tests/constify-module-enums-simple-alias.rs @@ -28,6 +28,8 @@ pub struct Bar { } #[test] fn bindgen_test_layout_Bar() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 48usize, @@ -38,142 +40,90 @@ fn bindgen_test_layout_Bar() { 8usize, concat!("Alignment of ", stringify!(Bar)) ); - fn test_field_baz1() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz1) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(baz1) - ) - ); - } - test_field_baz1(); - fn test_field_baz2() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz2) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(baz2) - ) - ); - } - test_field_baz2(); - fn test_field_baz3() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz3) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(baz3) - ) - ); - } - test_field_baz3(); - fn test_field_baz4() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz4) as usize - ptr as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(baz4) - ) - ); - } - test_field_baz4(); - fn test_field_baz_ptr1() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz_ptr1) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(baz_ptr1) - ) - ); - } - test_field_baz_ptr1(); - fn test_field_baz_ptr2() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz_ptr2) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(baz_ptr2) - ) - ); - } - test_field_baz_ptr2(); - fn test_field_baz_ptr3() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz_ptr3) as usize - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(baz_ptr3) - ) - ); - } - test_field_baz_ptr3(); - fn test_field_baz_ptr4() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz_ptr4) as usize - ptr as usize - }, - 40usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(baz_ptr4) - ) - ); - } - test_field_baz_ptr4(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz1) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz1)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz2) as usize - ptr as usize + }, + 4usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz2)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz3) as usize - ptr as usize + }, + 8usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz3)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz4) as usize - ptr as usize + }, + 12usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz4)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz_ptr1) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(Bar), + "::", + stringify!(baz_ptr1) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz_ptr2) as usize - ptr as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(Bar), + "::", + stringify!(baz_ptr2) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz_ptr3) as usize - ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(Bar), + "::", + stringify!(baz_ptr3) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz_ptr4) as usize - ptr as usize + }, + 40usize, + concat!( + "Offset of field: ", + stringify!(Bar), + "::", + stringify!(baz_ptr4) + ) + ); } impl Default for Bar { fn default() -> Self { diff --git a/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs b/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs index c2032b21a8..71dc1d7011 100644 --- a/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs +++ b/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs @@ -18,6 +18,8 @@ pub struct Bar { } #[test] fn bindgen_test_layout_Bar() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -28,40 +30,22 @@ fn bindgen_test_layout_Bar() { 8usize, concat!("Alignment of ", stringify!(Bar)) ); - fn test_field_baz1() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz1) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(baz1) - ) - ); - } - test_field_baz1(); - fn test_field_baz2() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz2) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(baz2) - ) - ); - } - test_field_baz2(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz1) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz1)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz2) as usize - ptr as usize + }, + 8usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz2)) + ); } impl Default for Bar { fn default() -> Self { diff --git a/tests/expectations/tests/constify-module-enums-types.rs b/tests/expectations/tests/constify-module-enums-types.rs index 7319ec7253..d22e206543 100644 --- a/tests/expectations/tests/constify-module-enums-types.rs +++ b/tests/expectations/tests/constify-module-enums-types.rs @@ -53,6 +53,8 @@ pub struct bar { } #[test] fn bindgen_test_layout_bar() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 48usize, @@ -63,176 +65,136 @@ fn bindgen_test_layout_bar() { 8usize, concat!("Alignment of ", stringify!(bar)) ); - fn test_field_member1() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member1) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(member1) - ) - ); - } - test_field_member1(); - fn test_field_member2() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member2) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(member2) - ) - ); - } - test_field_member2(); - fn test_field_member3() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member3) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(member3) - ) - ); - } - test_field_member3(); - fn test_field_member4() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member4) as usize - ptr as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(member4) - ) - ); - } - test_field_member4(); - fn test_field_member5() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member5) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(member5) - ) - ); - } - test_field_member5(); - fn test_field_member6() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member6) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(member6) - ) - ); - } - test_field_member6(); - fn test_field_member7() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member7) as usize - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(member7) - ) - ); - } - test_field_member7(); - fn test_field_member8() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member8) as usize - ptr as usize - }, - 36usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(member8) - ) - ); - } - test_field_member8(); - fn test_field_member9() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member9) as usize - ptr as usize - }, - 40usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(member9) - ) - ); - } - test_field_member9(); - fn test_field_member10() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member10) as usize - ptr as usize - }, - 44usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(member10) - ) - ); - } - test_field_member10(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).member1) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(bar), + "::", + stringify!(member1) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).member2) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(bar), + "::", + stringify!(member2) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).member3) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(bar), + "::", + stringify!(member3) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).member4) as usize - ptr as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(bar), + "::", + stringify!(member4) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).member5) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(bar), + "::", + stringify!(member5) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).member6) as usize - ptr as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(bar), + "::", + stringify!(member6) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).member7) as usize - ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(bar), + "::", + stringify!(member7) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).member8) as usize - ptr as usize + }, + 36usize, + concat!( + "Offset of field: ", + stringify!(bar), + "::", + stringify!(member8) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).member9) as usize - ptr as usize + }, + 40usize, + concat!( + "Offset of field: ", + stringify!(bar), + "::", + stringify!(member9) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).member10) as usize - ptr as usize + }, + 44usize, + concat!( + "Offset of field: ", + stringify!(bar), + "::", + stringify!(member10) + ) + ); } impl Default for bar { fn default() -> Self { @@ -250,6 +212,8 @@ pub struct Baz { } #[test] fn bindgen_test_layout_Baz() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -260,23 +224,19 @@ fn bindgen_test_layout_Baz() { 4usize, concat!("Alignment of ", stringify!(Baz)) ); - fn test_field_member1() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member1) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Baz), - "::", - stringify!(member1) - ) - ); - } - test_field_member1(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).member1) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Baz), + "::", + stringify!(member1) + ) + ); } impl Default for Baz { fn default() -> Self { @@ -299,6 +259,8 @@ pub struct Bar { } #[test] fn bindgen_test_layout_Bar() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -309,23 +271,14 @@ fn bindgen_test_layout_Bar() { 8usize, concat!("Alignment of ", stringify!(Bar)) ); - fn test_field_baz() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(baz) - ) - ); - } - test_field_baz(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz)) + ); } impl Default for Bar { fn default() -> Self { diff --git a/tests/expectations/tests/contains-vs-inherits-zero-sized.rs b/tests/expectations/tests/contains-vs-inherits-zero-sized.rs index b218a62f11..3a0f5586d4 100644 --- a/tests/expectations/tests/contains-vs-inherits-zero-sized.rs +++ b/tests/expectations/tests/contains-vs-inherits-zero-sized.rs @@ -33,6 +33,8 @@ pub struct Inherits { } #[test] fn bindgen_test_layout_Inherits() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -43,23 +45,19 @@ fn bindgen_test_layout_Inherits() { 1usize, concat!("Alignment of ", stringify!(Inherits)) ); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Inherits), - "::", - stringify!(b) - ) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Inherits), + "::", + stringify!(b) + ) + ); } /// This should not get an `_address` byte, but contains `Empty` which *does* get /// one, so `sizeof(Contains)` should be `1 + 1`. @@ -71,6 +69,8 @@ pub struct Contains { } #[test] fn bindgen_test_layout_Contains() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 2usize, @@ -81,38 +81,30 @@ fn bindgen_test_layout_Contains() { 1usize, concat!("Alignment of ", stringify!(Contains)) ); - fn test_field_empty() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).empty) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Contains), - "::", - stringify!(empty) - ) - ); - } - test_field_empty(); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 1usize, - concat!( - "Offset of field: ", - stringify!(Contains), - "::", - stringify!(b) - ) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).empty) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Contains), + "::", + stringify!(empty) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 1usize, + concat!( + "Offset of field: ", + stringify!(Contains), + "::", + stringify!(b) + ) + ); } diff --git a/tests/expectations/tests/convert-floats.rs b/tests/expectations/tests/convert-floats.rs index 6e6d1c678b..bd9ed3c800 100644 --- a/tests/expectations/tests/convert-floats.rs +++ b/tests/expectations/tests/convert-floats.rs @@ -23,6 +23,8 @@ pub struct foo { } #[test] fn bindgen_test_layout_foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 48usize, @@ -33,110 +35,69 @@ fn bindgen_test_layout_foo() { 8usize, concat!("Alignment of ", stringify!(foo)) ); - fn test_field_bar() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(bar) - ) - ); - } - test_field_bar(); - fn test_field_baz() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(baz) - ) - ); - } - test_field_baz(); - fn test_field_bazz() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bazz) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(bazz) - ) - ); - } - test_field_bazz(); - fn test_field_bazzz() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bazzz) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(bazzz) - ) - ); - } - test_field_bazzz(); - fn test_field_complexFloat() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).complexFloat) as usize - - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(complexFloat) - ) - ); - } - test_field_complexFloat(); - fn test_field_complexDouble() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).complexDouble) as usize - - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(complexDouble) - ) - ); - } - test_field_complexDouble(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, + 4usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(baz)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).bazz) as usize - ptr as usize + }, + 8usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(bazz)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).bazzz) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(bazzz) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).complexFloat) as usize - ptr as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(complexFloat) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).complexDouble) as usize - ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(complexDouble) + ) + ); } impl Default for foo { fn default() -> Self { diff --git a/tests/expectations/tests/ctypes-prefix-path.rs b/tests/expectations/tests/ctypes-prefix-path.rs index 0dc4909566..203f075948 100644 --- a/tests/expectations/tests/ctypes-prefix-path.rs +++ b/tests/expectations/tests/ctypes-prefix-path.rs @@ -21,6 +21,8 @@ pub struct foo { } #[test] fn bindgen_test_layout_foo() { + const UNINIT: ::core::mem::MaybeUninit = + ::core::mem::MaybeUninit::uninit(); assert_eq!( ::core::mem::size_of::(), 16usize, @@ -31,47 +33,30 @@ fn bindgen_test_layout_foo() { 8usize, concat!("Alignment of ", stringify!(foo)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::core::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::core::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) - ); - } - test_field_a(); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = ::core::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::core::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 4usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) - ); - } - test_field_b(); - fn test_field_bar() { - assert_eq!( - unsafe { - let uninit = ::core::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(bar) - ) - ); - } - test_field_bar(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::core::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::core::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 4usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 8usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) + ); } impl Default for foo { fn default() -> Self { diff --git a/tests/expectations/tests/derive-bitfield-method-same-name.rs b/tests/expectations/tests/derive-bitfield-method-same-name.rs index 56bbdc5433..6b84111b70 100644 --- a/tests/expectations/tests/derive-bitfield-method-same-name.rs +++ b/tests/expectations/tests/derive-bitfield-method-same-name.rs @@ -104,6 +104,8 @@ pub struct Foo { } #[test] fn bindgen_test_layout_Foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 136usize, @@ -114,23 +116,19 @@ fn bindgen_test_layout_Foo() { 4usize, concat!("Alignment of ", stringify!(Foo)) ); - fn test_field_large() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).large) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(large) - ) - ); - } - test_field_large(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).large) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Foo), + "::", + stringify!(large) + ) + ); } extern "C" { #[link_name = "\u{1}_ZN3Foo4typeEv"] diff --git a/tests/expectations/tests/derive-clone.rs b/tests/expectations/tests/derive-clone.rs index 4a80a856d8..6bdf35df00 100644 --- a/tests/expectations/tests/derive-clone.rs +++ b/tests/expectations/tests/derive-clone.rs @@ -13,6 +13,8 @@ pub struct ShouldDeriveClone { } #[test] fn bindgen_test_layout_ShouldDeriveClone() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 132usize, @@ -23,24 +25,19 @@ fn bindgen_test_layout_ShouldDeriveClone() { 4usize, concat!("Alignment of ", stringify!(ShouldDeriveClone)) ); - fn test_field_large() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).large) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldDeriveClone), - "::", - stringify!(large) - ) - ); - } - test_field_large(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).large) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ShouldDeriveClone), + "::", + stringify!(large) + ) + ); } impl Default for ShouldDeriveClone { fn default() -> Self { diff --git a/tests/expectations/tests/derive-clone_1_0.rs b/tests/expectations/tests/derive-clone_1_0.rs index 90c8c72aa4..590e663715 100644 --- a/tests/expectations/tests/derive-clone_1_0.rs +++ b/tests/expectations/tests/derive-clone_1_0.rs @@ -14,6 +14,8 @@ pub struct ShouldImplClone { } #[test] fn bindgen_test_layout_ShouldImplClone() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 132usize, @@ -24,24 +26,19 @@ fn bindgen_test_layout_ShouldImplClone() { 4usize, concat!("Alignment of ", stringify!(ShouldImplClone)) ); - fn test_field_large() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).large) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldImplClone), - "::", - stringify!(large) - ) - ); - } - test_field_large(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).large) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ShouldImplClone), + "::", + stringify!(large) + ) + ); } impl Clone for ShouldImplClone { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/derive-debug-bitfield-core.rs b/tests/expectations/tests/derive-debug-bitfield-core.rs index 249df3d5e0..b3cacd105e 100644 --- a/tests/expectations/tests/derive-debug-bitfield-core.rs +++ b/tests/expectations/tests/derive-debug-bitfield-core.rs @@ -102,6 +102,8 @@ pub struct C { } #[test] fn bindgen_test_layout_C() { + const UNINIT: ::core::mem::MaybeUninit = + ::core::mem::MaybeUninit::uninit(); assert_eq!( ::core::mem::size_of::(), 204usize, @@ -112,24 +114,19 @@ fn bindgen_test_layout_C() { 4usize, concat!("Alignment of ", stringify!(C)) ); - fn test_field_large_array() { - assert_eq!( - unsafe { - let uninit = ::core::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::core::ptr::addr_of!((*ptr).large_array) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(large_array) - ) - ); - } - test_field_large_array(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::core::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(large_array) + ) + ); } impl Default for C { fn default() -> Self { diff --git a/tests/expectations/tests/derive-debug-bitfield.rs b/tests/expectations/tests/derive-debug-bitfield.rs index 4ca28af3b4..1805335a35 100644 --- a/tests/expectations/tests/derive-debug-bitfield.rs +++ b/tests/expectations/tests/derive-debug-bitfield.rs @@ -100,6 +100,8 @@ pub struct C { } #[test] fn bindgen_test_layout_C() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 204usize, @@ -110,23 +112,19 @@ fn bindgen_test_layout_C() { 4usize, concat!("Alignment of ", stringify!(C)) ); - fn test_field_large_array() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(large_array) - ) - ); - } - test_field_large_array(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(large_array) + ) + ); } impl Default for C { fn default() -> Self { diff --git a/tests/expectations/tests/derive-debug-function-pointer.rs b/tests/expectations/tests/derive-debug-function-pointer.rs index 9f4cecedce..9b0df65065 100644 --- a/tests/expectations/tests/derive-debug-function-pointer.rs +++ b/tests/expectations/tests/derive-debug-function-pointer.rs @@ -15,6 +15,8 @@ pub type Nice_Function = ::std::option::Option; #[test] fn bindgen_test_layout_Nice() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 144usize, @@ -25,40 +27,32 @@ fn bindgen_test_layout_Nice() { 8usize, concat!("Alignment of ", stringify!(Nice)) ); - fn test_field_pointer() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pointer) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Nice), - "::", - stringify!(pointer) - ) - ); - } - test_field_pointer(); - fn test_field_large_array() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(Nice), - "::", - stringify!(large_array) - ) - ); - } - test_field_large_array(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).pointer) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Nice), + "::", + stringify!(pointer) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(Nice), + "::", + stringify!(large_array) + ) + ); } impl Default for Nice { fn default() -> Self { diff --git a/tests/expectations/tests/derive-debug-mangle-name.rs b/tests/expectations/tests/derive-debug-mangle-name.rs index 8e66efc674..30c7f816bc 100644 --- a/tests/expectations/tests/derive-debug-mangle-name.rs +++ b/tests/expectations/tests/derive-debug-mangle-name.rs @@ -20,6 +20,8 @@ pub union perf_event_attr__bindgen_ty_1 { } #[test] fn bindgen_test_layout_perf_event_attr__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -30,44 +32,32 @@ fn bindgen_test_layout_perf_event_attr__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(perf_event_attr__bindgen_ty_1)) ); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - perf_event_attr__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(perf_event_attr__bindgen_ty_1), - "::", - stringify!(b) - ) - ); - } - test_field_b(); - fn test_field_c() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - perf_event_attr__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(perf_event_attr__bindgen_ty_1), - "::", - stringify!(c) - ) - ); - } - test_field_c(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(perf_event_attr__bindgen_ty_1), + "::", + stringify!(b) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(perf_event_attr__bindgen_ty_1), + "::", + stringify!(c) + ) + ); } impl Default for perf_event_attr__bindgen_ty_1 { fn default() -> Self { @@ -85,6 +75,8 @@ impl ::std::fmt::Debug for perf_event_attr__bindgen_ty_1 { } #[test] fn bindgen_test_layout_perf_event_attr() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 12usize, @@ -95,42 +87,32 @@ fn bindgen_test_layout_perf_event_attr() { 4usize, concat!("Alignment of ", stringify!(perf_event_attr)) ); - fn test_field_type() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(perf_event_attr), - "::", - stringify!(type_) - ) - ); - } - test_field_type(); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(perf_event_attr), - "::", - stringify!(a) - ) - ); - } - test_field_a(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(perf_event_attr), + "::", + stringify!(type_) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(perf_event_attr), + "::", + stringify!(a) + ) + ); } impl Default for perf_event_attr { fn default() -> Self { diff --git a/tests/expectations/tests/derive-debug-opaque-template-instantiation.rs b/tests/expectations/tests/derive-debug-opaque-template-instantiation.rs index 78101ada8f..1242df834d 100644 --- a/tests/expectations/tests/derive-debug-opaque-template-instantiation.rs +++ b/tests/expectations/tests/derive-debug-opaque-template-instantiation.rs @@ -11,6 +11,8 @@ pub struct Instance { } #[test] fn bindgen_test_layout_Instance() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 200usize, @@ -21,23 +23,19 @@ fn bindgen_test_layout_Instance() { 4usize, concat!("Alignment of ", stringify!(Instance)) ); - fn test_field_val() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).val) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Instance), - "::", - stringify!(val) - ) - ); - } - test_field_val(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).val) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Instance), + "::", + stringify!(val) + ) + ); } impl Default for Instance { fn default() -> Self { diff --git a/tests/expectations/tests/derive-debug-opaque.rs b/tests/expectations/tests/derive-debug-opaque.rs index 06f33952e2..0fe6b73c17 100644 --- a/tests/expectations/tests/derive-debug-opaque.rs +++ b/tests/expectations/tests/derive-debug-opaque.rs @@ -43,6 +43,8 @@ pub struct OpaqueUser { } #[test] fn bindgen_test_layout_OpaqueUser() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 164usize, @@ -53,23 +55,19 @@ fn bindgen_test_layout_OpaqueUser() { 4usize, concat!("Alignment of ", stringify!(OpaqueUser)) ); - fn test_field_opaque() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).opaque) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(OpaqueUser), - "::", - stringify!(opaque) - ) - ); - } - test_field_opaque(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).opaque) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(OpaqueUser), + "::", + stringify!(opaque) + ) + ); } impl Default for OpaqueUser { fn default() -> Self { diff --git a/tests/expectations/tests/derive-default-and-blocklist.rs b/tests/expectations/tests/derive-default-and-blocklist.rs index 4b8ecf9787..c50e2df2a9 100644 --- a/tests/expectations/tests/derive-default-and-blocklist.rs +++ b/tests/expectations/tests/derive-default-and-blocklist.rs @@ -15,6 +15,8 @@ pub struct ShouldNotDeriveDefault { } #[test] fn bindgen_test_layout_ShouldNotDeriveDefault() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -25,24 +27,19 @@ fn bindgen_test_layout_ShouldNotDeriveDefault() { 1usize, concat!("Alignment of ", stringify!(ShouldNotDeriveDefault)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldNotDeriveDefault), - "::", - stringify!(a) - ) - ); - } - test_field_a(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ShouldNotDeriveDefault), + "::", + stringify!(a) + ) + ); } impl Default for ShouldNotDeriveDefault { fn default() -> Self { diff --git a/tests/expectations/tests/derive-fn-ptr.rs b/tests/expectations/tests/derive-fn-ptr.rs index bab7f6b844..4ce06e048d 100644 --- a/tests/expectations/tests/derive-fn-ptr.rs +++ b/tests/expectations/tests/derive-fn-ptr.rs @@ -32,6 +32,8 @@ pub struct Foo { } #[test] fn bindgen_test_layout_Foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -42,23 +44,19 @@ fn bindgen_test_layout_Foo() { 8usize, concat!("Alignment of ", stringify!(Foo)) ); - fn test_field_callback() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).callback) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(callback) - ) - ); - } - test_field_callback(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).callback) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Foo), + "::", + stringify!(callback) + ) + ); } pub type my_fun2_t = ::std::option::Option< unsafe extern "C" fn( @@ -83,6 +81,8 @@ pub struct Bar { } #[test] fn bindgen_test_layout_Bar() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -93,21 +93,17 @@ fn bindgen_test_layout_Bar() { 8usize, concat!("Alignment of ", stringify!(Bar)) ); - fn test_field_callback() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).callback) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(callback) - ) - ); - } - test_field_callback(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).callback) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Bar), + "::", + stringify!(callback) + ) + ); } diff --git a/tests/expectations/tests/derive-hash-and-blocklist.rs b/tests/expectations/tests/derive-hash-and-blocklist.rs index ca436fa882..27cb8312e9 100644 --- a/tests/expectations/tests/derive-hash-and-blocklist.rs +++ b/tests/expectations/tests/derive-hash-and-blocklist.rs @@ -14,6 +14,8 @@ pub struct ShouldNotDeriveHash { } #[test] fn bindgen_test_layout_ShouldNotDeriveHash() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -24,24 +26,19 @@ fn bindgen_test_layout_ShouldNotDeriveHash() { 1usize, concat!("Alignment of ", stringify!(ShouldNotDeriveHash)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldNotDeriveHash), - "::", - stringify!(a) - ) - ); - } - test_field_a(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ShouldNotDeriveHash), + "::", + stringify!(a) + ) + ); } impl Default for ShouldNotDeriveHash { fn default() -> Self { diff --git a/tests/expectations/tests/derive-hash-blocklisting.rs b/tests/expectations/tests/derive-hash-blocklisting.rs index e2aaf03f03..b00da661ef 100644 --- a/tests/expectations/tests/derive-hash-blocklisting.rs +++ b/tests/expectations/tests/derive-hash-blocklisting.rs @@ -20,6 +20,8 @@ pub struct AllowlistedOne { } #[test] fn bindgen_test_layout_AllowlistedOne() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -30,24 +32,19 @@ fn bindgen_test_layout_AllowlistedOne() { 4usize, concat!("Alignment of ", stringify!(AllowlistedOne)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AllowlistedOne), - "::", - stringify!(a) - ) - ); - } - test_field_a(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(AllowlistedOne), + "::", + stringify!(a) + ) + ); } impl Default for AllowlistedOne { fn default() -> Self { @@ -65,6 +62,8 @@ pub struct AllowlistedTwo { } #[test] fn bindgen_test_layout_AllowlistedTwo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -75,24 +74,19 @@ fn bindgen_test_layout_AllowlistedTwo() { 4usize, concat!("Alignment of ", stringify!(AllowlistedTwo)) ); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AllowlistedTwo), - "::", - stringify!(b) - ) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(AllowlistedTwo), + "::", + stringify!(b) + ) + ); } impl Default for AllowlistedTwo { fn default() -> Self { diff --git a/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs b/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs index c519885610..d0860e58bb 100644 --- a/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs +++ b/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs @@ -19,6 +19,8 @@ pub struct foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -29,45 +31,37 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - } - test_field_a(); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(b) + ) + ); } #[test] fn bindgen_test_layout_foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -78,21 +72,12 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - fn test_field_bar() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(bar) - ) - ); - } - test_field_bar(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) + ); } diff --git a/tests/expectations/tests/derive-hash-struct-with-float-array.rs b/tests/expectations/tests/derive-hash-struct-with-float-array.rs index b561cc3777..2a7168dde3 100644 --- a/tests/expectations/tests/derive-hash-struct-with-float-array.rs +++ b/tests/expectations/tests/derive-hash-struct-with-float-array.rs @@ -13,6 +13,8 @@ pub struct foo { } #[test] fn bindgen_test_layout_foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 12usize, @@ -23,21 +25,12 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - fn test_field_bar() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(bar) - ) - ); - } - test_field_bar(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) + ); } diff --git a/tests/expectations/tests/derive-hash-struct-with-pointer.rs b/tests/expectations/tests/derive-hash-struct-with-pointer.rs index 658810080c..7bda695bac 100644 --- a/tests/expectations/tests/derive-hash-struct-with-pointer.rs +++ b/tests/expectations/tests/derive-hash-struct-with-pointer.rs @@ -13,6 +13,8 @@ pub struct ConstPtrMutObj { } #[test] fn bindgen_test_layout_ConstPtrMutObj() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -23,24 +25,19 @@ fn bindgen_test_layout_ConstPtrMutObj() { 8usize, concat!("Alignment of ", stringify!(ConstPtrMutObj)) ); - fn test_field_bar() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ConstPtrMutObj), - "::", - stringify!(bar) - ) - ); - } - test_field_bar(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ConstPtrMutObj), + "::", + stringify!(bar) + ) + ); } impl Default for ConstPtrMutObj { fn default() -> Self { @@ -58,6 +55,8 @@ pub struct MutPtrMutObj { } #[test] fn bindgen_test_layout_MutPtrMutObj() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -68,23 +67,19 @@ fn bindgen_test_layout_MutPtrMutObj() { 8usize, concat!("Alignment of ", stringify!(MutPtrMutObj)) ); - fn test_field_bar() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(MutPtrMutObj), - "::", - stringify!(bar) - ) - ); - } - test_field_bar(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(MutPtrMutObj), + "::", + stringify!(bar) + ) + ); } impl Default for MutPtrMutObj { fn default() -> Self { @@ -102,6 +97,8 @@ pub struct MutPtrConstObj { } #[test] fn bindgen_test_layout_MutPtrConstObj() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -112,24 +109,19 @@ fn bindgen_test_layout_MutPtrConstObj() { 8usize, concat!("Alignment of ", stringify!(MutPtrConstObj)) ); - fn test_field_bar() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(MutPtrConstObj), - "::", - stringify!(bar) - ) - ); - } - test_field_bar(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(MutPtrConstObj), + "::", + stringify!(bar) + ) + ); } impl Default for MutPtrConstObj { fn default() -> Self { @@ -147,6 +139,8 @@ pub struct ConstPtrConstObj { } #[test] fn bindgen_test_layout_ConstPtrConstObj() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -157,24 +151,19 @@ fn bindgen_test_layout_ConstPtrConstObj() { 8usize, concat!("Alignment of ", stringify!(ConstPtrConstObj)) ); - fn test_field_bar() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ConstPtrConstObj), - "::", - stringify!(bar) - ) - ); - } - test_field_bar(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ConstPtrConstObj), + "::", + stringify!(bar) + ) + ); } impl Default for ConstPtrConstObj { fn default() -> Self { diff --git a/tests/expectations/tests/derive-hash-template-inst-float.rs b/tests/expectations/tests/derive-hash-template-inst-float.rs index 18cccb3b56..02b127e46d 100644 --- a/tests/expectations/tests/derive-hash-template-inst-float.rs +++ b/tests/expectations/tests/derive-hash-template-inst-float.rs @@ -29,6 +29,8 @@ pub struct IntStr { } #[test] fn bindgen_test_layout_IntStr() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -39,23 +41,14 @@ fn bindgen_test_layout_IntStr() { 4usize, concat!("Alignment of ", stringify!(IntStr)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(IntStr), - "::", - stringify!(a) - ) - ); - } - test_field_a(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(IntStr), "::", stringify!(a)) + ); } impl Default for IntStr { fn default() -> Self { @@ -74,6 +67,8 @@ pub struct FloatStr { } #[test] fn bindgen_test_layout_FloatStr() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -84,23 +79,19 @@ fn bindgen_test_layout_FloatStr() { 4usize, concat!("Alignment of ", stringify!(FloatStr)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(FloatStr), - "::", - stringify!(a) - ) - ); - } - test_field_a(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(FloatStr), + "::", + stringify!(a) + ) + ); } impl Default for FloatStr { fn default() -> Self { diff --git a/tests/expectations/tests/derive-partialeq-and-blocklist.rs b/tests/expectations/tests/derive-partialeq-and-blocklist.rs index 23c493dc28..ff1a33dc5f 100644 --- a/tests/expectations/tests/derive-partialeq-and-blocklist.rs +++ b/tests/expectations/tests/derive-partialeq-and-blocklist.rs @@ -15,6 +15,8 @@ pub struct ShouldNotDerivePartialEq { } #[test] fn bindgen_test_layout_ShouldNotDerivePartialEq() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -25,25 +27,19 @@ fn bindgen_test_layout_ShouldNotDerivePartialEq() { 1usize, concat!("Alignment of ", stringify!(ShouldNotDerivePartialEq)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldNotDerivePartialEq), - "::", - stringify!(a) - ) - ); - } - test_field_a(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ShouldNotDerivePartialEq), + "::", + stringify!(a) + ) + ); } impl Default for ShouldNotDerivePartialEq { fn default() -> Self { diff --git a/tests/expectations/tests/derive-partialeq-base.rs b/tests/expectations/tests/derive-partialeq-base.rs index 25f37549f6..74b9d68ba3 100644 --- a/tests/expectations/tests/derive-partialeq-base.rs +++ b/tests/expectations/tests/derive-partialeq-base.rs @@ -12,6 +12,8 @@ pub struct Base { } #[test] fn bindgen_test_layout_Base() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 132usize, @@ -22,23 +24,19 @@ fn bindgen_test_layout_Base() { 4usize, concat!("Alignment of ", stringify!(Base)) ); - fn test_field_large() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).large) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Base), - "::", - stringify!(large) - ) - ); - } - test_field_large(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).large) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Base), + "::", + stringify!(large) + ) + ); } impl Default for Base { fn default() -> Self { diff --git a/tests/expectations/tests/derive-partialeq-bitfield.rs b/tests/expectations/tests/derive-partialeq-bitfield.rs index b27f1cb5d9..a6484e63ec 100644 --- a/tests/expectations/tests/derive-partialeq-bitfield.rs +++ b/tests/expectations/tests/derive-partialeq-bitfield.rs @@ -100,6 +100,8 @@ pub struct C { } #[test] fn bindgen_test_layout_C() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 204usize, @@ -110,23 +112,19 @@ fn bindgen_test_layout_C() { 4usize, concat!("Alignment of ", stringify!(C)) ); - fn test_field_large_array() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(large_array) - ) - ); - } - test_field_large_array(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(large_array) + ) + ); } impl Default for C { fn default() -> Self { diff --git a/tests/expectations/tests/derive-partialeq-core.rs b/tests/expectations/tests/derive-partialeq-core.rs index eec02324e4..1a4ae223b8 100644 --- a/tests/expectations/tests/derive-partialeq-core.rs +++ b/tests/expectations/tests/derive-partialeq-core.rs @@ -14,6 +14,8 @@ pub struct C { } #[test] fn bindgen_test_layout_C() { + const UNINIT: ::core::mem::MaybeUninit = + ::core::mem::MaybeUninit::uninit(); assert_eq!( ::core::mem::size_of::(), 1680usize, @@ -24,24 +26,19 @@ fn bindgen_test_layout_C() { 4usize, concat!("Alignment of ", stringify!(C)) ); - fn test_field_large_array() { - assert_eq!( - unsafe { - let uninit = ::core::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::core::ptr::addr_of!((*ptr).large_array) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(large_array) - ) - ); - } - test_field_large_array(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::core::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(large_array) + ) + ); } impl Default for C { fn default() -> Self { diff --git a/tests/expectations/tests/derive-partialeq-pointer.rs b/tests/expectations/tests/derive-partialeq-pointer.rs index 4b29a5d4f2..89c9091ff2 100644 --- a/tests/expectations/tests/derive-partialeq-pointer.rs +++ b/tests/expectations/tests/derive-partialeq-pointer.rs @@ -12,6 +12,8 @@ pub struct Bar { } #[test] fn bindgen_test_layout_Bar() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -22,18 +24,14 @@ fn bindgen_test_layout_Bar() { 8usize, concat!("Alignment of ", stringify!(Bar)) ); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(b)) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(b)) + ); } impl Default for Bar { fn default() -> Self { @@ -105,6 +103,8 @@ pub struct a { } #[test] fn bindgen_test_layout_a() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -115,18 +115,14 @@ fn bindgen_test_layout_a() { 1usize, concat!("Alignment of ", stringify!(a)) ); - fn test_field_d() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(a), "::", stringify!(d)) - ); - } - test_field_d(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(a), "::", stringify!(d)) + ); } impl Default for a { fn default() -> Self { diff --git a/tests/expectations/tests/derive-partialeq-union.rs b/tests/expectations/tests/derive-partialeq-union.rs index 0007477518..a0c501ccbd 100644 --- a/tests/expectations/tests/derive-partialeq-union.rs +++ b/tests/expectations/tests/derive-partialeq-union.rs @@ -14,6 +14,8 @@ pub union ShouldNotDerivePartialEq { } #[test] fn bindgen_test_layout_ShouldNotDerivePartialEq() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -24,44 +26,32 @@ fn bindgen_test_layout_ShouldNotDerivePartialEq() { 4usize, concat!("Alignment of ", stringify!(ShouldNotDerivePartialEq)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldNotDerivePartialEq), - "::", - stringify!(a) - ) - ); - } - test_field_a(); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldNotDerivePartialEq), - "::", - stringify!(b) - ) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ShouldNotDerivePartialEq), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ShouldNotDerivePartialEq), + "::", + stringify!(b) + ) + ); } impl Default for ShouldNotDerivePartialEq { fn default() -> Self { diff --git a/tests/expectations/tests/derive-partialeq-union_1_0.rs b/tests/expectations/tests/derive-partialeq-union_1_0.rs index dd6f756cbc..bf5061bfb8 100644 --- a/tests/expectations/tests/derive-partialeq-union_1_0.rs +++ b/tests/expectations/tests/derive-partialeq-union_1_0.rs @@ -58,6 +58,8 @@ pub struct ShouldDerivePartialEq { } #[test] fn bindgen_test_layout_ShouldDerivePartialEq() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 152usize, @@ -68,42 +70,32 @@ fn bindgen_test_layout_ShouldDerivePartialEq() { 4usize, concat!("Alignment of ", stringify!(ShouldDerivePartialEq)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldDerivePartialEq), - "::", - stringify!(a) - ) - ); - } - test_field_a(); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldDerivePartialEq), - "::", - stringify!(b) - ) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ShouldDerivePartialEq), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ShouldDerivePartialEq), + "::", + stringify!(b) + ) + ); } impl Clone for ShouldDerivePartialEq { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/disable-nested-struct-naming.rs b/tests/expectations/tests/disable-nested-struct-naming.rs index 23391041d6..ccb6e1b015 100644 --- a/tests/expectations/tests/disable-nested-struct-naming.rs +++ b/tests/expectations/tests/disable-nested-struct-naming.rs @@ -35,6 +35,8 @@ pub struct bar4 { } #[test] fn bindgen_test_layout_bar4() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -45,26 +47,19 @@ fn bindgen_test_layout_bar4() { 4usize, concat!("Alignment of ", stringify!(bar4)) ); - fn test_field_x4() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).x4) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(bar4), - "::", - stringify!(x4) - ) - ); - } - test_field_x4(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).x4) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(bar4), "::", stringify!(x4)) + ); } #[test] fn bindgen_test_layout_bar1__bindgen_ty_1__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -78,47 +73,37 @@ fn bindgen_test_layout_bar1__bindgen_ty_1__bindgen_ty_1() { stringify!(bar1__bindgen_ty_1__bindgen_ty_1) ) ); - fn test_field_x3() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - bar1__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).x3) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(bar1__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(x3) - ) - ); - } - test_field_x3(); - fn test_field_b4() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - bar1__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b4) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(bar1__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(b4) - ) - ); - } - test_field_b4(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).x3) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(bar1__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(x3) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b4) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(bar1__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(b4) + ) + ); } #[test] fn bindgen_test_layout_bar1__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 12usize, @@ -129,45 +114,37 @@ fn bindgen_test_layout_bar1__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(bar1__bindgen_ty_1)) ); - fn test_field_x2() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).x2) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(bar1__bindgen_ty_1), - "::", - stringify!(x2) - ) - ); - } - test_field_x2(); - fn test_field_b3() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b3) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(bar1__bindgen_ty_1), - "::", - stringify!(b3) - ) - ); - } - test_field_b3(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).x2) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(bar1__bindgen_ty_1), + "::", + stringify!(x2) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b3) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(bar1__bindgen_ty_1), + "::", + stringify!(b3) + ) + ); } #[test] fn bindgen_test_layout_bar1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -178,43 +155,27 @@ fn bindgen_test_layout_bar1() { 4usize, concat!("Alignment of ", stringify!(bar1)) ); - fn test_field_x1() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).x1) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(bar1), - "::", - stringify!(x1) - ) - ); - } - test_field_x1(); - fn test_field_b2() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b2) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(bar1), - "::", - stringify!(b2) - ) - ); - } - test_field_b2(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).x1) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(bar1), "::", stringify!(x1)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b2) as usize - ptr as usize + }, + 4usize, + concat!("Offset of field: ", stringify!(bar1), "::", stringify!(b2)) + ); } #[test] fn bindgen_test_layout_foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -225,18 +186,14 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - fn test_field_b1() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b1) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(b1)) - ); - } - test_field_b1(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b1) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(b1)) + ); } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -255,6 +212,8 @@ pub struct baz { } #[test] fn bindgen_test_layout_baz() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -265,21 +224,19 @@ fn bindgen_test_layout_baz() { 4usize, concat!("Alignment of ", stringify!(baz)) ); - fn test_field_x() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(baz), "::", stringify!(x)) - ); - } - test_field_x(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(baz), "::", stringify!(x)) + ); } #[test] fn bindgen_test_layout__bindgen_ty_1__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit<_bindgen_ty_1__bindgen_ty_1> = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::<_bindgen_ty_1__bindgen_ty_1>(), 4usize, @@ -290,28 +247,24 @@ fn bindgen_test_layout__bindgen_ty_1__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(_bindgen_ty_1__bindgen_ty_1)) ); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - _bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(b) - ) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(b) + ) + ); } #[test] fn bindgen_test_layout__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit<_bindgen_ty_1> = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::<_bindgen_ty_1>(), 4usize, @@ -322,23 +275,19 @@ fn bindgen_test_layout__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(_bindgen_ty_1)) ); - fn test_field_anon2() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::<_bindgen_ty_1>::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).anon2) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_bindgen_ty_1), - "::", - stringify!(anon2) - ) - ); - } - test_field_anon2(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).anon2) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_bindgen_ty_1), + "::", + stringify!(anon2) + ) + ); } extern "C" { pub static mut anon1: _bindgen_ty_1; diff --git a/tests/expectations/tests/disable-untagged-union.rs b/tests/expectations/tests/disable-untagged-union.rs index 912238b345..0251c8dfdf 100644 --- a/tests/expectations/tests/disable-untagged-union.rs +++ b/tests/expectations/tests/disable-untagged-union.rs @@ -57,6 +57,8 @@ pub struct Foo { } #[test] fn bindgen_test_layout_Foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -67,38 +69,20 @@ fn bindgen_test_layout_Foo() { 4usize, concat!("Alignment of ", stringify!(Foo)) ); - fn test_field_bar() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(bar) - ) - ); - } - test_field_bar(); - fn test_field_baz() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(baz) - ) - ); - } - test_field_baz(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(baz)) + ); } diff --git a/tests/expectations/tests/do-not-derive-copy.rs b/tests/expectations/tests/do-not-derive-copy.rs index 2e02cc5096..4d55df55fc 100644 --- a/tests/expectations/tests/do-not-derive-copy.rs +++ b/tests/expectations/tests/do-not-derive-copy.rs @@ -12,6 +12,8 @@ pub struct WouldBeCopyButWeAreNotDerivingCopy { } #[test] fn bindgen_test_layout_WouldBeCopyButWeAreNotDerivingCopy() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -25,23 +27,17 @@ fn bindgen_test_layout_WouldBeCopyButWeAreNotDerivingCopy() { stringify!(WouldBeCopyButWeAreNotDerivingCopy) ) ); - fn test_field_x() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - WouldBeCopyButWeAreNotDerivingCopy, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WouldBeCopyButWeAreNotDerivingCopy), - "::", - stringify!(x) - ) - ); - } - test_field_x(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WouldBeCopyButWeAreNotDerivingCopy), + "::", + stringify!(x) + ) + ); } diff --git a/tests/expectations/tests/doggo-or-null.rs b/tests/expectations/tests/doggo-or-null.rs index 0b34b3d05b..ff1e536335 100644 --- a/tests/expectations/tests/doggo-or-null.rs +++ b/tests/expectations/tests/doggo-or-null.rs @@ -12,6 +12,8 @@ pub struct Doggo { } #[test] fn bindgen_test_layout_Doggo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -22,23 +24,14 @@ fn bindgen_test_layout_Doggo() { 4usize, concat!("Alignment of ", stringify!(Doggo)) ); - fn test_field_x() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Doggo), - "::", - stringify!(x) - ) - ); - } - test_field_x(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Doggo), "::", stringify!(x)) + ); } #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq)] diff --git a/tests/expectations/tests/duplicated-namespaces-definitions.rs b/tests/expectations/tests/duplicated-namespaces-definitions.rs index 2322aa87ce..407e6f1212 100644 --- a/tests/expectations/tests/duplicated-namespaces-definitions.rs +++ b/tests/expectations/tests/duplicated-namespaces-definitions.rs @@ -20,6 +20,8 @@ pub mod root { } #[test] fn bindgen_test_layout_Bar() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -30,40 +32,32 @@ pub mod root { 4usize, concat!("Alignment of ", stringify!(Bar)) ); - fn test_field_foo() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(foo) - ) - ); - } - test_field_foo(); - fn test_field_baz() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(baz) - ) - ); - } - test_field_baz(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Bar), + "::", + stringify!(foo) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(Bar), + "::", + stringify!(baz) + ) + ); } } pub mod bar { @@ -76,6 +70,8 @@ pub mod root { } #[test] fn bindgen_test_layout_Foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -86,23 +82,19 @@ pub mod root { 8usize, concat!("Alignment of ", stringify!(Foo)) ); - fn test_field_ptr() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(ptr) - ) - ); - } - test_field_ptr(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Foo), + "::", + stringify!(ptr) + ) + ); } impl Default for Foo { fn default() -> Self { diff --git a/tests/expectations/tests/dynamic_loading_with_blocklist.rs b/tests/expectations/tests/dynamic_loading_with_blocklist.rs index f2ffe671cb..703d1f7fb4 100644 --- a/tests/expectations/tests/dynamic_loading_with_blocklist.rs +++ b/tests/expectations/tests/dynamic_loading_with_blocklist.rs @@ -12,6 +12,8 @@ pub struct X { } #[test] fn bindgen_test_layout_X() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -22,18 +24,14 @@ fn bindgen_test_layout_X() { 4usize, concat!("Alignment of ", stringify!(X)) ); - fn test_field__x() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr)._x) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(X), "::", stringify!(_x)) - ); - } - test_field__x(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr)._x) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(X), "::", stringify!(_x)) + ); } extern "C" { #[link_name = "\u{1}_ZN1X13some_functionEv"] diff --git a/tests/expectations/tests/dynamic_loading_with_class.rs b/tests/expectations/tests/dynamic_loading_with_class.rs index 03655c8efa..6bcb1eef83 100644 --- a/tests/expectations/tests/dynamic_loading_with_class.rs +++ b/tests/expectations/tests/dynamic_loading_with_class.rs @@ -12,6 +12,8 @@ pub struct A { } #[test] fn bindgen_test_layout_A() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -22,18 +24,14 @@ fn bindgen_test_layout_A() { 4usize, concat!("Alignment of ", stringify!(A)) ); - fn test_field__x() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr)._x) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(_x)) - ); - } - test_field__x(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr)._x) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(A), "::", stringify!(_x)) + ); } extern "C" { #[link_name = "\u{1}_ZN1A13some_functionEv"] diff --git a/tests/expectations/tests/enum-default-bitfield.rs b/tests/expectations/tests/enum-default-bitfield.rs index 6ea42d0b91..90d442f55e 100644 --- a/tests/expectations/tests/enum-default-bitfield.rs +++ b/tests/expectations/tests/enum-default-bitfield.rs @@ -43,6 +43,8 @@ impl ::std::ops::BitAndAssign for foo__bindgen_ty_1 { pub struct foo__bindgen_ty_1(pub ::std::os::raw::c_uint); #[test] fn bindgen_test_layout_foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -53,23 +55,19 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - fn test_field_member() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(member) - ) - ); - } - test_field_member(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(member) + ) + ); } impl Default for foo { fn default() -> Self { diff --git a/tests/expectations/tests/enum-default-consts.rs b/tests/expectations/tests/enum-default-consts.rs index 631617bd30..c40b903416 100644 --- a/tests/expectations/tests/enum-default-consts.rs +++ b/tests/expectations/tests/enum-default-consts.rs @@ -15,6 +15,8 @@ pub const foo_FOO_B: foo__bindgen_ty_1 = 1; pub type foo__bindgen_ty_1 = ::std::os::raw::c_uint; #[test] fn bindgen_test_layout_foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -25,23 +27,19 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - fn test_field_member() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(member) - ) - ); - } - test_field_member(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(member) + ) + ); } impl Default for foo { fn default() -> Self { diff --git a/tests/expectations/tests/enum-default-module.rs b/tests/expectations/tests/enum-default-module.rs index e74e9fc3e8..2990d8fc15 100644 --- a/tests/expectations/tests/enum-default-module.rs +++ b/tests/expectations/tests/enum-default-module.rs @@ -17,6 +17,8 @@ pub mod foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -27,23 +29,19 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - fn test_field_member() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(member) - ) - ); - } - test_field_member(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(member) + ) + ); } impl Default for foo { fn default() -> Self { diff --git a/tests/expectations/tests/enum-default-rust.rs b/tests/expectations/tests/enum-default-rust.rs index 8cc843a34d..fd799aeeda 100644 --- a/tests/expectations/tests/enum-default-rust.rs +++ b/tests/expectations/tests/enum-default-rust.rs @@ -20,6 +20,8 @@ pub enum foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -30,23 +32,19 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - fn test_field_member() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(member) - ) - ); - } - test_field_member(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(member) + ) + ); } impl Default for foo { fn default() -> Self { diff --git a/tests/expectations/tests/enum-no-debug-rust.rs b/tests/expectations/tests/enum-no-debug-rust.rs index 6291137f19..d433d4ccac 100644 --- a/tests/expectations/tests/enum-no-debug-rust.rs +++ b/tests/expectations/tests/enum-no-debug-rust.rs @@ -20,6 +20,8 @@ pub enum foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -30,23 +32,19 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - fn test_field_member() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(member) - ) - ); - } - test_field_member(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(member) + ) + ); } impl Default for foo { fn default() -> Self { diff --git a/tests/expectations/tests/enum.rs b/tests/expectations/tests/enum.rs index 484adf5b1d..3c8e0814a2 100644 --- a/tests/expectations/tests/enum.rs +++ b/tests/expectations/tests/enum.rs @@ -15,6 +15,8 @@ pub const foo_FOO_B: foo__bindgen_ty_1 = 1; pub type foo__bindgen_ty_1 = ::std::os::raw::c_uint; #[test] fn bindgen_test_layout_foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -25,23 +27,19 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - fn test_field_member() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(member) - ) - ); - } - test_field_member(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(member) + ) + ); } impl Default for foo { fn default() -> Self { diff --git a/tests/expectations/tests/enum_and_vtable_mangling.rs b/tests/expectations/tests/enum_and_vtable_mangling.rs index 5f41a62b0d..ca982c330a 100644 --- a/tests/expectations/tests/enum_and_vtable_mangling.rs +++ b/tests/expectations/tests/enum_and_vtable_mangling.rs @@ -25,6 +25,8 @@ pub struct C { } #[test] fn bindgen_test_layout_C() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -35,18 +37,14 @@ fn bindgen_test_layout_C() { 8usize, concat!("Alignment of ", stringify!(C)) ); - fn test_field_i() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize - }, - 8usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(i)) - ); - } - test_field_i(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize + }, + 8usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(i)) + ); } impl Default for C { fn default() -> Self { diff --git a/tests/expectations/tests/explicit-padding.rs b/tests/expectations/tests/explicit-padding.rs index 508c6b5b86..73d2b69460 100644 --- a/tests/expectations/tests/explicit-padding.rs +++ b/tests/expectations/tests/explicit-padding.rs @@ -16,6 +16,8 @@ pub struct pad_me { } #[test] fn bindgen_test_layout_pad_me() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 12usize, @@ -26,57 +28,45 @@ fn bindgen_test_layout_pad_me() { 4usize, concat!("Alignment of ", stringify!(pad_me)) ); - fn test_field_first() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).first) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(pad_me), - "::", - stringify!(first) - ) - ); - } - test_field_first(); - fn test_field_second() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).second) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(pad_me), - "::", - stringify!(second) - ) - ); - } - test_field_second(); - fn test_field_third() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).third) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(pad_me), - "::", - stringify!(third) - ) - ); - } - test_field_third(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).first) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(pad_me), + "::", + stringify!(first) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).second) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(pad_me), + "::", + stringify!(second) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).third) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(pad_me), + "::", + stringify!(third) + ) + ); } #[repr(C)] #[derive(Copy, Clone)] @@ -87,6 +77,8 @@ pub union dont_pad_me { } #[test] fn bindgen_test_layout_dont_pad_me() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -97,57 +89,45 @@ fn bindgen_test_layout_dont_pad_me() { 4usize, concat!("Alignment of ", stringify!(dont_pad_me)) ); - fn test_field_first() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).first) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(dont_pad_me), - "::", - stringify!(first) - ) - ); - } - test_field_first(); - fn test_field_second() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).second) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(dont_pad_me), - "::", - stringify!(second) - ) - ); - } - test_field_second(); - fn test_field_third() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).third) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(dont_pad_me), - "::", - stringify!(third) - ) - ); - } - test_field_third(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).first) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(dont_pad_me), + "::", + stringify!(first) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).second) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(dont_pad_me), + "::", + stringify!(second) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).third) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(dont_pad_me), + "::", + stringify!(third) + ) + ); } impl Default for dont_pad_me { fn default() -> Self { diff --git a/tests/expectations/tests/extern-const-struct.rs b/tests/expectations/tests/extern-const-struct.rs index ab2b3a661b..e1af23c819 100644 --- a/tests/expectations/tests/extern-const-struct.rs +++ b/tests/expectations/tests/extern-const-struct.rs @@ -12,6 +12,8 @@ pub struct nsFoo { } #[test] fn bindgen_test_layout_nsFoo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 1600usize, @@ -22,23 +24,19 @@ fn bindgen_test_layout_nsFoo() { 4usize, concat!("Alignment of ", stringify!(nsFoo)) ); - fn test_field_details() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).details) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsFoo), - "::", - stringify!(details) - ) - ); - } - test_field_details(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).details) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(nsFoo), + "::", + stringify!(details) + ) + ); } impl Default for nsFoo { fn default() -> Self { diff --git a/tests/expectations/tests/forward-declaration-autoptr.rs b/tests/expectations/tests/forward-declaration-autoptr.rs index f46f73b630..fc4203f540 100644 --- a/tests/expectations/tests/forward-declaration-autoptr.rs +++ b/tests/expectations/tests/forward-declaration-autoptr.rs @@ -32,6 +32,8 @@ pub struct Bar { } #[test] fn bindgen_test_layout_Bar() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -42,23 +44,19 @@ fn bindgen_test_layout_Bar() { 8usize, concat!("Alignment of ", stringify!(Bar)) ); - fn test_field_m_member() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(m_member) - ) - ); - } - test_field_m_member(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Bar), + "::", + stringify!(m_member) + ) + ); } impl Default for Bar { fn default() -> Self { diff --git a/tests/expectations/tests/forward_declared_complex_types.rs b/tests/expectations/tests/forward_declared_complex_types.rs index 9c3d7c6648..f8f25bd672 100644 --- a/tests/expectations/tests/forward_declared_complex_types.rs +++ b/tests/expectations/tests/forward_declared_complex_types.rs @@ -35,6 +35,8 @@ pub struct Bar { } #[test] fn bindgen_test_layout_Bar() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -45,18 +47,14 @@ fn bindgen_test_layout_Bar() { 8usize, concat!("Alignment of ", stringify!(Bar)) ); - fn test_field_f() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(f)) - ); - } - test_field_f(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(f)) + ); } impl Default for Bar { fn default() -> Self { diff --git a/tests/expectations/tests/forward_declared_complex_types_1_0.rs b/tests/expectations/tests/forward_declared_complex_types_1_0.rs index 0e79263300..5c749f8297 100644 --- a/tests/expectations/tests/forward_declared_complex_types_1_0.rs +++ b/tests/expectations/tests/forward_declared_complex_types_1_0.rs @@ -45,6 +45,8 @@ pub struct Bar { } #[test] fn bindgen_test_layout_Bar() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -55,18 +57,14 @@ fn bindgen_test_layout_Bar() { 8usize, concat!("Alignment of ", stringify!(Bar)) ); - fn test_field_f() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(f)) - ); - } - test_field_f(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(f)) + ); } impl Clone for Bar { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/forward_declared_struct.rs b/tests/expectations/tests/forward_declared_struct.rs index eee7da7378..e65e0351bd 100644 --- a/tests/expectations/tests/forward_declared_struct.rs +++ b/tests/expectations/tests/forward_declared_struct.rs @@ -12,6 +12,8 @@ pub struct a { } #[test] fn bindgen_test_layout_a() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -22,18 +24,14 @@ fn bindgen_test_layout_a() { 4usize, concat!("Alignment of ", stringify!(a)) ); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(a), "::", stringify!(b)) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(a), "::", stringify!(b)) + ); } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -42,6 +40,8 @@ pub struct c { } #[test] fn bindgen_test_layout_c() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -52,16 +52,12 @@ fn bindgen_test_layout_c() { 4usize, concat!("Alignment of ", stringify!(c)) ); - fn test_field_d() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(c), "::", stringify!(d)) - ); - } - test_field_d(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(c), "::", stringify!(d)) + ); } diff --git a/tests/expectations/tests/func_ptr_in_struct.rs b/tests/expectations/tests/func_ptr_in_struct.rs index 8709ee2b1c..6e7357f7ef 100644 --- a/tests/expectations/tests/func_ptr_in_struct.rs +++ b/tests/expectations/tests/func_ptr_in_struct.rs @@ -22,6 +22,8 @@ pub struct Foo { } #[test] fn bindgen_test_layout_Foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -32,21 +34,12 @@ fn bindgen_test_layout_Foo() { 8usize, concat!("Alignment of ", stringify!(Foo)) ); - fn test_field_bar() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(bar) - ) - ); - } - test_field_bar(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) + ); } diff --git a/tests/expectations/tests/gen-destructors-neg.rs b/tests/expectations/tests/gen-destructors-neg.rs index 09c1486240..3b5193ae44 100644 --- a/tests/expectations/tests/gen-destructors-neg.rs +++ b/tests/expectations/tests/gen-destructors-neg.rs @@ -12,6 +12,8 @@ pub struct Foo { } #[test] fn bindgen_test_layout_Foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -22,21 +24,12 @@ fn bindgen_test_layout_Foo() { 4usize, concat!("Alignment of ", stringify!(Foo)) ); - fn test_field_bar() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(bar) - ) - ); - } - test_field_bar(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) + ); } diff --git a/tests/expectations/tests/gen-destructors.rs b/tests/expectations/tests/gen-destructors.rs index 79f4ed8089..dbd02151ed 100644 --- a/tests/expectations/tests/gen-destructors.rs +++ b/tests/expectations/tests/gen-destructors.rs @@ -12,6 +12,8 @@ pub struct Foo { } #[test] fn bindgen_test_layout_Foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -22,23 +24,14 @@ fn bindgen_test_layout_Foo() { 4usize, concat!("Alignment of ", stringify!(Foo)) ); - fn test_field_bar() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(bar) - ) - ); - } - test_field_bar(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) + ); } extern "C" { #[link_name = "\u{1}_ZN3FooD1Ev"] diff --git a/tests/expectations/tests/i128.rs b/tests/expectations/tests/i128.rs index 545198c64e..addc227d60 100644 --- a/tests/expectations/tests/i128.rs +++ b/tests/expectations/tests/i128.rs @@ -14,6 +14,8 @@ pub struct foo { } #[test] fn bindgen_test_layout_foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 32usize, @@ -24,38 +26,30 @@ fn bindgen_test_layout_foo() { 16usize, concat!("Alignment of ", stringify!(foo)) ); - fn test_field_my_signed() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).my_signed) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(my_signed) - ) - ); - } - test_field_my_signed(); - fn test_field_my_unsigned() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).my_unsigned) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(my_unsigned) - ) - ); - } - test_field_my_unsigned(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).my_signed) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(my_signed) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).my_unsigned) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(my_unsigned) + ) + ); } diff --git a/tests/expectations/tests/inline_namespace.rs b/tests/expectations/tests/inline_namespace.rs index daa0868563..81446a9687 100644 --- a/tests/expectations/tests/inline_namespace.rs +++ b/tests/expectations/tests/inline_namespace.rs @@ -21,6 +21,8 @@ pub mod root { } #[test] fn bindgen_test_layout_Bar() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -31,22 +33,18 @@ pub mod root { 4usize, concat!("Alignment of ", stringify!(Bar)) ); - fn test_field_baz() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(baz) - ) - ); - } - test_field_baz(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Bar), + "::", + stringify!(baz) + ) + ); } } diff --git a/tests/expectations/tests/inline_namespace_conservative.rs b/tests/expectations/tests/inline_namespace_conservative.rs index d855e0616b..bbee2dee19 100644 --- a/tests/expectations/tests/inline_namespace_conservative.rs +++ b/tests/expectations/tests/inline_namespace_conservative.rs @@ -26,6 +26,8 @@ pub mod root { } #[test] fn bindgen_test_layout_Bar() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -36,22 +38,18 @@ pub mod root { 4usize, concat!("Alignment of ", stringify!(Bar)) ); - fn test_field_baz() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(baz) - ) - ); - } - test_field_baz(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Bar), + "::", + stringify!(baz) + ) + ); } } diff --git a/tests/expectations/tests/inner_const.rs b/tests/expectations/tests/inner_const.rs index 41c990475d..84dfdc3786 100644 --- a/tests/expectations/tests/inner_const.rs +++ b/tests/expectations/tests/inner_const.rs @@ -20,6 +20,8 @@ extern "C" { } #[test] fn bindgen_test_layout_Foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -30,21 +32,12 @@ fn bindgen_test_layout_Foo() { 4usize, concat!("Alignment of ", stringify!(Foo)) ); - fn test_field_bar() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(bar) - ) - ); - } - test_field_bar(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) + ); } diff --git a/tests/expectations/tests/inner_template_self.rs b/tests/expectations/tests/inner_template_self.rs index 033dc57b16..eed9885ddf 100644 --- a/tests/expectations/tests/inner_template_self.rs +++ b/tests/expectations/tests/inner_template_self.rs @@ -27,6 +27,8 @@ pub struct InstantiateIt { } #[test] fn bindgen_test_layout_InstantiateIt() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -37,23 +39,19 @@ fn bindgen_test_layout_InstantiateIt() { 8usize, concat!("Alignment of ", stringify!(InstantiateIt)) ); - fn test_field_m_list() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).m_list) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(InstantiateIt), - "::", - stringify!(m_list) - ) - ); - } - test_field_m_list(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).m_list) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(InstantiateIt), + "::", + stringify!(m_list) + ) + ); } impl Default for InstantiateIt { fn default() -> Self { diff --git a/tests/expectations/tests/issue-1118-using-forward-decl.rs b/tests/expectations/tests/issue-1118-using-forward-decl.rs index 121c086622..2596a6ba0d 100644 --- a/tests/expectations/tests/issue-1118-using-forward-decl.rs +++ b/tests/expectations/tests/issue-1118-using-forward-decl.rs @@ -13,6 +13,8 @@ pub struct nsTArray_base { } #[test] fn bindgen_test_layout_nsTArray_base() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -23,23 +25,19 @@ fn bindgen_test_layout_nsTArray_base() { 8usize, concat!("Alignment of ", stringify!(nsTArray_base)) ); - fn test_field_d() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsTArray_base), - "::", - stringify!(d) - ) - ); - } - test_field_d(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(nsTArray_base), + "::", + stringify!(d) + ) + ); } impl Default for nsTArray_base { fn default() -> Self { @@ -71,6 +69,8 @@ pub struct nsIContent { } #[test] fn bindgen_test_layout_nsIContent() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -81,23 +81,19 @@ fn bindgen_test_layout_nsIContent() { 8usize, concat!("Alignment of ", stringify!(nsIContent)) ); - fn test_field_foo() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsIContent), - "::", - stringify!(foo) - ) - ); - } - test_field_foo(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(nsIContent), + "::", + stringify!(foo) + ) + ); } impl Default for nsIContent { fn default() -> Self { diff --git a/tests/expectations/tests/issue-1216-variadic-member.rs b/tests/expectations/tests/issue-1216-variadic-member.rs index 792586b4dc..c7ffa3b613 100644 --- a/tests/expectations/tests/issue-1216-variadic-member.rs +++ b/tests/expectations/tests/issue-1216-variadic-member.rs @@ -22,6 +22,8 @@ pub struct Foo { } #[test] fn bindgen_test_layout_Foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -32,16 +34,12 @@ fn bindgen_test_layout_Foo() { 8usize, concat!("Alignment of ", stringify!(Foo)) ); - fn test_field_f() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(f)) - ); - } - test_field_f(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(f)) + ); } diff --git a/tests/expectations/tests/issue-1281.rs b/tests/expectations/tests/issue-1281.rs index 9da4c9546f..ff3eb88a4c 100644 --- a/tests/expectations/tests/issue-1281.rs +++ b/tests/expectations/tests/issue-1281.rs @@ -17,6 +17,8 @@ pub struct foo { } #[test] fn bindgen_test_layout_foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -27,26 +29,19 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - fn test_field_foo() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(foo) - ) - ); - } - test_field_foo(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(foo)) + ); } #[test] fn bindgen_test_layout_bar() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -57,18 +52,14 @@ fn bindgen_test_layout_bar() { 4usize, concat!("Alignment of ", stringify!(bar)) ); - fn test_field_u() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(bar), "::", stringify!(u)) - ); - } - test_field_u(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(bar), "::", stringify!(u)) + ); } pub type bar_t = bar; #[repr(C)] @@ -78,6 +69,8 @@ pub struct baz { } #[test] fn bindgen_test_layout_baz() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -88,16 +81,12 @@ fn bindgen_test_layout_baz() { 4usize, concat!("Alignment of ", stringify!(baz)) ); - fn test_field_f() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(baz), "::", stringify!(f)) - ); - } - test_field_f(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(baz), "::", stringify!(f)) + ); } diff --git a/tests/expectations/tests/issue-1285.rs b/tests/expectations/tests/issue-1285.rs index 37f07476fd..f97c5236f1 100644 --- a/tests/expectations/tests/issue-1285.rs +++ b/tests/expectations/tests/issue-1285.rs @@ -18,6 +18,8 @@ pub union foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -28,42 +30,32 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - } - test_field_a(); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(b) + ) + ); } impl Default for foo__bindgen_ty_1 { fn default() -> Self { @@ -76,6 +68,8 @@ impl Default for foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -86,23 +80,14 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - fn test_field_bar() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(bar) - ) - ); - } - test_field_bar(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) + ); } impl Default for foo { fn default() -> Self { diff --git a/tests/expectations/tests/issue-1291.rs b/tests/expectations/tests/issue-1291.rs index 6776a19d0a..e7914e48d2 100644 --- a/tests/expectations/tests/issue-1291.rs +++ b/tests/expectations/tests/issue-1291.rs @@ -27,6 +27,8 @@ pub struct RTCRay { } #[test] fn bindgen_test_layout_RTCRay() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 96usize, @@ -37,259 +39,189 @@ fn bindgen_test_layout_RTCRay() { 16usize, concat!("Alignment of ", stringify!(RTCRay)) ); - fn test_field_org() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).org) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(org) - ) - ); - } - test_field_org(); - fn test_field_align0() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).align0) as usize - ptr as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(align0) - ) - ); - } - test_field_align0(); - fn test_field_dir() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dir) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(dir) - ) - ); - } - test_field_dir(); - fn test_field_align1() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).align1) as usize - ptr as usize - }, - 28usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(align1) - ) - ); - } - test_field_align1(); - fn test_field_tnear() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).tnear) as usize - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(tnear) - ) - ); - } - test_field_tnear(); - fn test_field_tfar() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).tfar) as usize - ptr as usize - }, - 36usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(tfar) - ) - ); - } - test_field_tfar(); - fn test_field_time() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).time) as usize - ptr as usize - }, - 40usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(time) - ) - ); - } - test_field_time(); - fn test_field_mask() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize - }, - 44usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(mask) - ) - ); - } - test_field_mask(); - fn test_field_Ng() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).Ng) as usize - ptr as usize - }, - 48usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(Ng) - ) - ); - } - test_field_Ng(); - fn test_field_align2() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).align2) as usize - ptr as usize - }, - 60usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(align2) - ) - ); - } - test_field_align2(); - fn test_field_u() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize - }, - 64usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(u) - ) - ); - } - test_field_u(); - fn test_field_v() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).v) as usize - ptr as usize - }, - 68usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(v) - ) - ); - } - test_field_v(); - fn test_field_geomID() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).geomID) as usize - ptr as usize - }, - 72usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(geomID) - ) - ); - } - test_field_geomID(); - fn test_field_primID() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).primID) as usize - ptr as usize - }, - 76usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(primID) - ) - ); - } - test_field_primID(); - fn test_field_instID() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).instID) as usize - ptr as usize - }, - 80usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(instID) - ) - ); - } - test_field_instID(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).org) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(RTCRay), + "::", + stringify!(org) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).align0) as usize - ptr as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(RTCRay), + "::", + stringify!(align0) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).dir) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(RTCRay), + "::", + stringify!(dir) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).align1) as usize - ptr as usize + }, + 28usize, + concat!( + "Offset of field: ", + stringify!(RTCRay), + "::", + stringify!(align1) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).tnear) as usize - ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(RTCRay), + "::", + stringify!(tnear) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).tfar) as usize - ptr as usize + }, + 36usize, + concat!( + "Offset of field: ", + stringify!(RTCRay), + "::", + stringify!(tfar) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).time) as usize - ptr as usize + }, + 40usize, + concat!( + "Offset of field: ", + stringify!(RTCRay), + "::", + stringify!(time) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize + }, + 44usize, + concat!( + "Offset of field: ", + stringify!(RTCRay), + "::", + stringify!(mask) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).Ng) as usize - ptr as usize + }, + 48usize, + concat!( + "Offset of field: ", + stringify!(RTCRay), + "::", + stringify!(Ng) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).align2) as usize - ptr as usize + }, + 60usize, + concat!( + "Offset of field: ", + stringify!(RTCRay), + "::", + stringify!(align2) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize + }, + 64usize, + concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(u)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).v) as usize - ptr as usize + }, + 68usize, + concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(v)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).geomID) as usize - ptr as usize + }, + 72usize, + concat!( + "Offset of field: ", + stringify!(RTCRay), + "::", + stringify!(geomID) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).primID) as usize - ptr as usize + }, + 76usize, + concat!( + "Offset of field: ", + stringify!(RTCRay), + "::", + stringify!(primID) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).instID) as usize - ptr as usize + }, + 80usize, + concat!( + "Offset of field: ", + stringify!(RTCRay), + "::", + stringify!(instID) + ) + ); } diff --git a/tests/expectations/tests/issue-1382-rust-primitive-types.rs b/tests/expectations/tests/issue-1382-rust-primitive-types.rs index 4ef922c3eb..0891493472 100644 --- a/tests/expectations/tests/issue-1382-rust-primitive-types.rs +++ b/tests/expectations/tests/issue-1382-rust-primitive-types.rs @@ -33,6 +33,8 @@ pub struct Foo { } #[test] fn bindgen_test_layout_Foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 56usize, @@ -43,242 +45,136 @@ fn bindgen_test_layout_Foo() { 4usize, concat!("Alignment of ", stringify!(Foo)) ); - fn test_field_i8() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i8_) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(i8_) - ) - ); - } - test_field_i8(); - fn test_field_u8() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).u8_) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(u8_) - ) - ); - } - test_field_u8(); - fn test_field_i16() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i16_) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(i16_) - ) - ); - } - test_field_i16(); - fn test_field_u16() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).u16_) as usize - ptr as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(u16_) - ) - ); - } - test_field_u16(); - fn test_field_i32() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i32_) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(i32_) - ) - ); - } - test_field_i32(); - fn test_field_u32() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).u32_) as usize - ptr as usize - }, - 20usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(u32_) - ) - ); - } - test_field_u32(); - fn test_field_i64() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i64_) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(i64_) - ) - ); - } - test_field_i64(); - fn test_field_u64() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).u64_) as usize - ptr as usize - }, - 28usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(u64_) - ) - ); - } - test_field_u64(); - fn test_field_i128() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i128_) as usize - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(i128_) - ) - ); - } - test_field_i128(); - fn test_field_u128() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).u128_) as usize - ptr as usize - }, - 36usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(u128_) - ) - ); - } - test_field_u128(); - fn test_field_isize() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).isize_) as usize - ptr as usize - }, - 40usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(isize_) - ) - ); - } - test_field_isize(); - fn test_field_usize() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).usize_) as usize - ptr as usize - }, - 44usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(usize_) - ) - ); - } - test_field_usize(); - fn test_field_f32() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).f32_) as usize - ptr as usize - }, - 48usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(f32_) - ) - ); - } - test_field_f32(); - fn test_field_f64() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).f64_) as usize - ptr as usize - }, - 52usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(f64_) - ) - ); - } - test_field_f64(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).i8_) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i8_)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).u8_) as usize - ptr as usize + }, + 4usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u8_)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).i16_) as usize - ptr as usize + }, + 8usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i16_)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).u16_) as usize - ptr as usize + }, + 12usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u16_)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).i32_) as usize - ptr as usize + }, + 16usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i32_)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).u32_) as usize - ptr as usize + }, + 20usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u32_)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).i64_) as usize - ptr as usize + }, + 24usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i64_)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).u64_) as usize - ptr as usize + }, + 28usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u64_)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).i128_) as usize - ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(Foo), + "::", + stringify!(i128_) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).u128_) as usize - ptr as usize + }, + 36usize, + concat!( + "Offset of field: ", + stringify!(Foo), + "::", + stringify!(u128_) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).isize_) as usize - ptr as usize + }, + 40usize, + concat!( + "Offset of field: ", + stringify!(Foo), + "::", + stringify!(isize_) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).usize_) as usize - ptr as usize + }, + 44usize, + concat!( + "Offset of field: ", + stringify!(Foo), + "::", + stringify!(usize_) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).f32_) as usize - ptr as usize + }, + 48usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(f32_)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).f64_) as usize - ptr as usize + }, + 52usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(f64_)) + ); } diff --git a/tests/expectations/tests/issue-1443.rs b/tests/expectations/tests/issue-1443.rs index 92a1c7d414..3267ab0176 100644 --- a/tests/expectations/tests/issue-1443.rs +++ b/tests/expectations/tests/issue-1443.rs @@ -18,6 +18,8 @@ pub struct Bar { } #[test] fn bindgen_test_layout_Bar() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -28,30 +30,22 @@ fn bindgen_test_layout_Bar() { 8usize, concat!("Alignment of ", stringify!(Bar)) ); - fn test_field_f() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(f)) - ); - } - test_field_f(); - fn test_field_m() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize - }, - 8usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(m)) - ); - } - test_field_m(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(f)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize + }, + 8usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(m)) + ); } impl Default for Bar { fn default() -> Self { @@ -70,6 +64,8 @@ pub struct Baz { } #[test] fn bindgen_test_layout_Baz() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -80,30 +76,22 @@ fn bindgen_test_layout_Baz() { 8usize, concat!("Alignment of ", stringify!(Baz)) ); - fn test_field_f() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Baz), "::", stringify!(f)) - ); - } - test_field_f(); - fn test_field_m() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize - }, - 8usize, - concat!("Offset of field: ", stringify!(Baz), "::", stringify!(m)) - ); - } - test_field_m(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Baz), "::", stringify!(f)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize + }, + 8usize, + concat!("Offset of field: ", stringify!(Baz), "::", stringify!(m)) + ); } impl Default for Baz { fn default() -> Self { @@ -122,6 +110,8 @@ pub struct Tar { } #[test] fn bindgen_test_layout_Tar() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -132,30 +122,22 @@ fn bindgen_test_layout_Tar() { 8usize, concat!("Alignment of ", stringify!(Tar)) ); - fn test_field_f() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Tar), "::", stringify!(f)) - ); - } - test_field_f(); - fn test_field_m() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize - }, - 8usize, - concat!("Offset of field: ", stringify!(Tar), "::", stringify!(m)) - ); - } - test_field_m(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Tar), "::", stringify!(f)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize + }, + 8usize, + concat!("Offset of field: ", stringify!(Tar), "::", stringify!(m)) + ); } impl Default for Tar { fn default() -> Self { @@ -174,6 +156,8 @@ pub struct Taz { } #[test] fn bindgen_test_layout_Taz() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -184,30 +168,22 @@ fn bindgen_test_layout_Taz() { 8usize, concat!("Alignment of ", stringify!(Taz)) ); - fn test_field_f() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Taz), "::", stringify!(f)) - ); - } - test_field_f(); - fn test_field_m() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize - }, - 8usize, - concat!("Offset of field: ", stringify!(Taz), "::", stringify!(m)) - ); - } - test_field_m(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Taz), "::", stringify!(f)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize + }, + 8usize, + concat!("Offset of field: ", stringify!(Taz), "::", stringify!(m)) + ); } impl Default for Taz { fn default() -> Self { diff --git a/tests/expectations/tests/issue-1454.rs b/tests/expectations/tests/issue-1454.rs index e0ad1d71a6..2ba6c493fe 100644 --- a/tests/expectations/tests/issue-1454.rs +++ b/tests/expectations/tests/issue-1454.rs @@ -16,6 +16,8 @@ pub struct local_type { } #[test] fn bindgen_test_layout_local_type() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 0usize, @@ -26,21 +28,17 @@ fn bindgen_test_layout_local_type() { 1usize, concat!("Alignment of ", stringify!(local_type)) ); - fn test_field_inner() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).inner) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(local_type), - "::", - stringify!(inner) - ) - ); - } - test_field_inner(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).inner) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(local_type), + "::", + stringify!(inner) + ) + ); } diff --git a/tests/expectations/tests/issue-1498.rs b/tests/expectations/tests/issue-1498.rs index b3064e648d..56fc922a20 100644 --- a/tests/expectations/tests/issue-1498.rs +++ b/tests/expectations/tests/issue-1498.rs @@ -33,6 +33,8 @@ pub union rte_memseg__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_memseg__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -43,44 +45,32 @@ fn bindgen_test_layout_rte_memseg__bindgen_ty_1() { 8usize, concat!("Alignment of ", stringify!(rte_memseg__bindgen_ty_1)) ); - fn test_field_addr() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).addr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_memseg__bindgen_ty_1), - "::", - stringify!(addr) - ) - ); - } - test_field_addr(); - fn test_field_addr_64() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).addr_64) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_memseg__bindgen_ty_1), - "::", - stringify!(addr_64) - ) - ); - } - test_field_addr_64(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).addr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_memseg__bindgen_ty_1), + "::", + stringify!(addr) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).addr_64) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_memseg__bindgen_ty_1), + "::", + stringify!(addr_64) + ) + ); } impl Default for rte_memseg__bindgen_ty_1 { fn default() -> Self { @@ -93,6 +83,8 @@ impl Default for rte_memseg__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_memseg() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 44usize, @@ -103,108 +95,84 @@ fn bindgen_test_layout_rte_memseg() { 1usize, concat!("Alignment of ", stringify!(rte_memseg)) ); - fn test_field_phys_addr() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).phys_addr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_memseg), - "::", - stringify!(phys_addr) - ) - ); - } - test_field_phys_addr(); - fn test_field_len() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_memseg), - "::", - stringify!(len) - ) - ); - } - test_field_len(); - fn test_field_hugepage_sz() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).hugepage_sz) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(rte_memseg), - "::", - stringify!(hugepage_sz) - ) - ); - } - test_field_hugepage_sz(); - fn test_field_socket_id() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).socket_id) as usize - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(rte_memseg), - "::", - stringify!(socket_id) - ) - ); - } - test_field_socket_id(); - fn test_field_nchannel() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nchannel) as usize - ptr as usize - }, - 36usize, - concat!( - "Offset of field: ", - stringify!(rte_memseg), - "::", - stringify!(nchannel) - ) - ); - } - test_field_nchannel(); - fn test_field_nrank() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nrank) as usize - ptr as usize - }, - 40usize, - concat!( - "Offset of field: ", - stringify!(rte_memseg), - "::", - stringify!(nrank) - ) - ); - } - test_field_nrank(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).phys_addr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_memseg), + "::", + stringify!(phys_addr) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_memseg), + "::", + stringify!(len) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).hugepage_sz) as usize - ptr as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(rte_memseg), + "::", + stringify!(hugepage_sz) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).socket_id) as usize - ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(rte_memseg), + "::", + stringify!(socket_id) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).nchannel) as usize - ptr as usize + }, + 36usize, + concat!( + "Offset of field: ", + stringify!(rte_memseg), + "::", + stringify!(nchannel) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).nrank) as usize - ptr as usize + }, + 40usize, + concat!( + "Offset of field: ", + stringify!(rte_memseg), + "::", + stringify!(nrank) + ) + ); } impl Default for rte_memseg { fn default() -> Self { diff --git a/tests/expectations/tests/issue-1947.rs b/tests/expectations/tests/issue-1947.rs index e32b7f5f93..f390a588a5 100644 --- a/tests/expectations/tests/issue-1947.rs +++ b/tests/expectations/tests/issue-1947.rs @@ -107,6 +107,8 @@ pub struct V56AMDY { } #[test] fn bindgen_test_layout_V56AMDY() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -117,57 +119,45 @@ fn bindgen_test_layout_V56AMDY() { 2usize, concat!("Alignment of ", stringify!(V56AMDY)) ); - fn test_field_MADK() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).MADK) as usize - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(V56AMDY), - "::", - stringify!(MADK) - ) - ); - } - test_field_MADK(); - fn test_field_MABR() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).MABR) as usize - ptr as usize - }, - 3usize, - concat!( - "Offset of field: ", - stringify!(V56AMDY), - "::", - stringify!(MABR) - ) - ); - } - test_field_MABR(); - fn test_field__rB_() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr)._rB_) as usize - ptr as usize - }, - 7usize, - concat!( - "Offset of field: ", - stringify!(V56AMDY), - "::", - stringify!(_rB_) - ) - ); - } - test_field__rB_(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).MADK) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(V56AMDY), + "::", + stringify!(MADK) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).MABR) as usize - ptr as usize + }, + 3usize, + concat!( + "Offset of field: ", + stringify!(V56AMDY), + "::", + stringify!(MABR) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr)._rB_) as usize - ptr as usize + }, + 7usize, + concat!( + "Offset of field: ", + stringify!(V56AMDY), + "::", + stringify!(_rB_) + ) + ); } impl V56AMDY { #[inline] diff --git a/tests/expectations/tests/issue-1977-larger-arrays.rs b/tests/expectations/tests/issue-1977-larger-arrays.rs index be4723febb..917cf52257 100644 --- a/tests/expectations/tests/issue-1977-larger-arrays.rs +++ b/tests/expectations/tests/issue-1977-larger-arrays.rs @@ -12,6 +12,8 @@ pub struct S { } #[test] fn bindgen_test_layout_S() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 33usize, @@ -22,23 +24,19 @@ fn bindgen_test_layout_S() { 1usize, concat!("Alignment of ", stringify!(S)) ); - fn test_field_large_array() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(S), - "::", - stringify!(large_array) - ) - ); - } - test_field_large_array(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(S), + "::", + stringify!(large_array) + ) + ); } impl Default for S { fn default() -> Self { diff --git a/tests/expectations/tests/issue-1995.rs b/tests/expectations/tests/issue-1995.rs index a0f10c013a..1cb803a7d8 100644 --- a/tests/expectations/tests/issue-1995.rs +++ b/tests/expectations/tests/issue-1995.rs @@ -19,6 +19,8 @@ pub struct Bar { } #[test] fn bindgen_test_layout_Bar() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -29,21 +31,12 @@ fn bindgen_test_layout_Bar() { 4usize, concat!("Alignment of ", stringify!(Bar)) ); - fn test_field_baz() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(baz) - ) - ); - } - test_field_baz(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz)) + ); } diff --git a/tests/expectations/tests/issue-2019.rs b/tests/expectations/tests/issue-2019.rs index 6140dfdde4..371345349c 100644 --- a/tests/expectations/tests/issue-2019.rs +++ b/tests/expectations/tests/issue-2019.rs @@ -12,6 +12,8 @@ pub struct A { } #[test] fn bindgen_test_layout_A() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -22,18 +24,14 @@ fn bindgen_test_layout_A() { 4usize, concat!("Alignment of ", stringify!(A)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(a)) - ); - } - test_field_a(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(A), "::", stringify!(a)) + ); } extern "C" { #[link_name = "\u{1}_ZN1A4makeEv"] @@ -52,6 +50,8 @@ pub struct B { } #[test] fn bindgen_test_layout_B() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -62,18 +62,14 @@ fn bindgen_test_layout_B() { 4usize, concat!("Alignment of ", stringify!(B)) ); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(B), "::", stringify!(b)) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(B), "::", stringify!(b)) + ); } extern "C" { #[link_name = "\u{1}_ZN1B4makeEv"] diff --git a/tests/expectations/tests/issue-372.rs b/tests/expectations/tests/issue-372.rs index f46d2c9fb6..b6fe4cf0c7 100644 --- a/tests/expectations/tests/issue-372.rs +++ b/tests/expectations/tests/issue-372.rs @@ -18,6 +18,8 @@ pub mod root { } #[test] fn bindgen_test_layout_i() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 24usize, @@ -28,57 +30,30 @@ pub mod root { 8usize, concat!("Alignment of ", stringify!(i)) ); - fn test_field_j() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).j) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(i), - "::", - stringify!(j) - ) - ); - } - test_field_j(); - fn test_field_k() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).k) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(i), - "::", - stringify!(k) - ) - ); - } - test_field_k(); - fn test_field_l() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).l) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(i), - "::", - stringify!(l) - ) - ); - } - test_field_l(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).j) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(i), "::", stringify!(j)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).k) as usize - ptr as usize + }, + 8usize, + concat!("Offset of field: ", stringify!(i), "::", stringify!(k)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).l) as usize - ptr as usize + }, + 16usize, + concat!("Offset of field: ", stringify!(i), "::", stringify!(l)) + ); } impl Default for i { fn default() -> Self { @@ -96,6 +71,8 @@ pub mod root { } #[test] fn bindgen_test_layout_d() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 24usize, @@ -106,23 +83,14 @@ pub mod root { 8usize, concat!("Alignment of ", stringify!(d)) ); - fn test_field_m() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(d), - "::", - stringify!(m) - ) - ); - } - test_field_m(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(d), "::", stringify!(m)) + ); } impl Default for d { fn default() -> Self { @@ -155,6 +123,8 @@ pub mod root { } #[test] fn bindgen_test_layout_F() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 264usize, @@ -165,23 +135,14 @@ pub mod root { 8usize, concat!("Alignment of ", stringify!(F)) ); - fn test_field_w() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).w) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(F), - "::", - stringify!(w) - ) - ); - } - test_field_w(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).w) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(F), "::", stringify!(w)) + ); } impl Default for F { fn default() -> Self { diff --git a/tests/expectations/tests/issue-537-repr-packed-n.rs b/tests/expectations/tests/issue-537-repr-packed-n.rs index 55ff25a46c..ab19685ba5 100644 --- a/tests/expectations/tests/issue-537-repr-packed-n.rs +++ b/tests/expectations/tests/issue-537-repr-packed-n.rs @@ -15,6 +15,8 @@ pub struct AlignedToOne { } #[test] fn bindgen_test_layout_AlignedToOne() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -25,23 +27,19 @@ fn bindgen_test_layout_AlignedToOne() { 1usize, concat!("Alignment of ", stringify!(AlignedToOne)) ); - fn test_field_i() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AlignedToOne), - "::", - stringify!(i) - ) - ); - } - test_field_i(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(AlignedToOne), + "::", + stringify!(i) + ) + ); } /// This should be be packed because Rust 1.33 has `#[repr(packed(N))]`. #[repr(C, packed(2))] @@ -51,6 +49,8 @@ pub struct AlignedToTwo { } #[test] fn bindgen_test_layout_AlignedToTwo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -61,23 +61,19 @@ fn bindgen_test_layout_AlignedToTwo() { 2usize, concat!("Alignment of ", stringify!(AlignedToTwo)) ); - fn test_field_i() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AlignedToTwo), - "::", - stringify!(i) - ) - ); - } - test_field_i(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(AlignedToTwo), + "::", + stringify!(i) + ) + ); } /// 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 @@ -90,6 +86,8 @@ pub struct PackedToOne { } #[test] fn bindgen_test_layout_PackedToOne() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -100,40 +98,32 @@ fn bindgen_test_layout_PackedToOne() { 1usize, concat!("Alignment of ", stringify!(PackedToOne)) ); - fn test_field_x() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(PackedToOne), - "::", - stringify!(x) - ) - ); - } - test_field_x(); - fn test_field_y() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(PackedToOne), - "::", - stringify!(y) - ) - ); - } - test_field_y(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(PackedToOne), + "::", + stringify!(x) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(PackedToOne), + "::", + stringify!(y) + ) + ); } /// This should be be packed because Rust 1.33 has `#[repr(packed(N))]`. #[repr(C, packed(2))] @@ -144,6 +134,8 @@ pub struct PackedToTwo { } #[test] fn bindgen_test_layout_PackedToTwo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -154,38 +146,30 @@ fn bindgen_test_layout_PackedToTwo() { 2usize, concat!("Alignment of ", stringify!(PackedToTwo)) ); - fn test_field_x() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(PackedToTwo), - "::", - stringify!(x) - ) - ); - } - test_field_x(); - fn test_field_y() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(PackedToTwo), - "::", - stringify!(y) - ) - ); - } - test_field_y(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(PackedToTwo), + "::", + stringify!(x) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(PackedToTwo), + "::", + stringify!(y) + ) + ); } diff --git a/tests/expectations/tests/issue-537.rs b/tests/expectations/tests/issue-537.rs index d3a0e8c576..e2e1bce0c9 100644 --- a/tests/expectations/tests/issue-537.rs +++ b/tests/expectations/tests/issue-537.rs @@ -14,6 +14,8 @@ pub struct AlignedToOne { } #[test] fn bindgen_test_layout_AlignedToOne() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -24,23 +26,19 @@ fn bindgen_test_layout_AlignedToOne() { 1usize, concat!("Alignment of ", stringify!(AlignedToOne)) ); - fn test_field_i() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AlignedToOne), - "::", - stringify!(i) - ) - ); - } - test_field_i(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(AlignedToOne), + "::", + stringify!(i) + ) + ); } /// This should be opaque because although we can see the attributes, Rust before /// 1.33 doesn't have `#[repr(packed(N))]`. @@ -51,6 +49,8 @@ pub struct AlignedToTwo { } #[test] fn bindgen_test_layout_AlignedToTwo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -61,23 +61,19 @@ fn bindgen_test_layout_AlignedToTwo() { 2usize, concat!("Alignment of ", stringify!(AlignedToTwo)) ); - fn test_field_i() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AlignedToTwo), - "::", - stringify!(i) - ) - ); - } - test_field_i(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(AlignedToTwo), + "::", + stringify!(i) + ) + ); } /// 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 @@ -90,6 +86,8 @@ pub struct PackedToOne { } #[test] fn bindgen_test_layout_PackedToOne() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -100,40 +98,32 @@ fn bindgen_test_layout_PackedToOne() { 1usize, concat!("Alignment of ", stringify!(PackedToOne)) ); - fn test_field_x() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(PackedToOne), - "::", - stringify!(x) - ) - ); - } - test_field_x(); - fn test_field_y() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(PackedToOne), - "::", - stringify!(y) - ) - ); - } - test_field_y(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(PackedToOne), + "::", + stringify!(x) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(PackedToOne), + "::", + stringify!(y) + ) + ); } /// In this case, even if we can detect the weird alignment triggered by /// `#pragma pack(2)`, we can't do anything about it because Rust before 1.33 @@ -146,6 +136,8 @@ pub struct PackedToTwo { } #[test] fn bindgen_test_layout_PackedToTwo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -156,38 +148,30 @@ fn bindgen_test_layout_PackedToTwo() { 2usize, concat!("Alignment of ", stringify!(PackedToTwo)) ); - fn test_field_x() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(PackedToTwo), - "::", - stringify!(x) - ) - ); - } - test_field_x(); - fn test_field_y() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(PackedToTwo), - "::", - stringify!(y) - ) - ); - } - test_field_y(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(PackedToTwo), + "::", + stringify!(x) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(PackedToTwo), + "::", + stringify!(y) + ) + ); } diff --git a/tests/expectations/tests/issue-573-layout-test-failures.rs b/tests/expectations/tests/issue-573-layout-test-failures.rs index 1c94f94fbe..3c16b87209 100644 --- a/tests/expectations/tests/issue-573-layout-test-failures.rs +++ b/tests/expectations/tests/issue-573-layout-test-failures.rs @@ -17,6 +17,8 @@ pub struct AutoIdVector { } #[test] fn bindgen_test_layout_AutoIdVector() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -27,23 +29,19 @@ fn bindgen_test_layout_AutoIdVector() { 1usize, concat!("Alignment of ", stringify!(AutoIdVector)) ); - fn test_field_ar() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AutoIdVector), - "::", - stringify!(ar) - ) - ); - } - test_field_ar(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).ar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(AutoIdVector), + "::", + stringify!(ar) + ) + ); } #[test] fn __bindgen_test_layout_Outer_open0_int_close0_instantiation() { diff --git a/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs b/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs index 66407d818b..36a7f4f5a2 100644 --- a/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs +++ b/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs @@ -17,6 +17,8 @@ pub struct _bindgen_ty_1 { } #[test] fn bindgen_test_layout__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit<_bindgen_ty_1> = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::<_bindgen_ty_1>(), 1usize, @@ -27,23 +29,19 @@ fn bindgen_test_layout__bindgen_ty_1() { 1usize, concat!("Alignment of ", stringify!(_bindgen_ty_1)) ); - fn test_field_ar() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::<_bindgen_ty_1>::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_bindgen_ty_1), - "::", - stringify!(ar) - ) - ); - } - test_field_ar(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).ar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_bindgen_ty_1), + "::", + stringify!(ar) + ) + ); } extern "C" { pub static mut AutoIdVector: _bindgen_ty_1; diff --git a/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs b/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs index 2a1d045bcb..0d9a14e665 100644 --- a/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs +++ b/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs @@ -51,6 +51,8 @@ pub struct g { } #[test] fn bindgen_test_layout_g() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -61,18 +63,14 @@ fn bindgen_test_layout_g() { 1usize, concat!("Alignment of ", stringify!(g)) ); - fn test_field_h() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).h) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(g), "::", stringify!(h)) - ); - } - test_field_h(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).h) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(g), "::", stringify!(h)) + ); } impl Default for g { fn default() -> Self { diff --git a/tests/expectations/tests/issue-639-typedef-anon-field.rs b/tests/expectations/tests/issue-639-typedef-anon-field.rs index 8f4b2a5ae3..40fb6829f4 100644 --- a/tests/expectations/tests/issue-639-typedef-anon-field.rs +++ b/tests/expectations/tests/issue-639-typedef-anon-field.rs @@ -17,6 +17,8 @@ pub struct Foo_Bar { } #[test] fn bindgen_test_layout_Foo_Bar() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -27,26 +29,24 @@ fn bindgen_test_layout_Foo_Bar() { 4usize, concat!("Alignment of ", stringify!(Foo_Bar)) ); - fn test_field_abc() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).abc) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Foo_Bar), - "::", - stringify!(abc) - ) - ); - } - test_field_abc(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).abc) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Foo_Bar), + "::", + stringify!(abc) + ) + ); } #[test] fn bindgen_test_layout_Foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -57,23 +57,14 @@ fn bindgen_test_layout_Foo() { 4usize, concat!("Alignment of ", stringify!(Foo)) ); - fn test_field_bar() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(bar) - ) - ); - } - test_field_bar(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) + ); } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -87,6 +78,8 @@ pub struct Baz_Bar { } #[test] fn bindgen_test_layout_Baz_Bar() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -97,23 +90,19 @@ fn bindgen_test_layout_Baz_Bar() { 4usize, concat!("Alignment of ", stringify!(Baz_Bar)) ); - fn test_field_abc() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).abc) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Baz_Bar), - "::", - stringify!(abc) - ) - ); - } - test_field_abc(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).abc) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Baz_Bar), + "::", + stringify!(abc) + ) + ); } #[test] fn bindgen_test_layout_Baz() { diff --git a/tests/expectations/tests/issue-648-derive-debug-with-padding.rs b/tests/expectations/tests/issue-648-derive-debug-with-padding.rs index f91bd4693b..1eed229d6b 100644 --- a/tests/expectations/tests/issue-648-derive-debug-with-padding.rs +++ b/tests/expectations/tests/issue-648-derive-debug-with-padding.rs @@ -15,6 +15,8 @@ pub struct NoDebug { } #[test] fn bindgen_test_layout_NoDebug() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 64usize, @@ -25,23 +27,19 @@ fn bindgen_test_layout_NoDebug() { 64usize, concat!("Alignment of ", stringify!(NoDebug)) ); - fn test_field_c() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NoDebug), - "::", - stringify!(c) - ) - ); - } - test_field_c(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(NoDebug), + "::", + stringify!(c) + ) + ); } impl Default for NoDebug { fn default() -> Self { @@ -70,6 +68,8 @@ pub struct ShouldDeriveDebugButDoesNot { } #[test] fn bindgen_test_layout_ShouldDeriveDebugButDoesNot() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 64usize, @@ -80,44 +80,32 @@ fn bindgen_test_layout_ShouldDeriveDebugButDoesNot() { 64usize, concat!("Alignment of ", stringify!(ShouldDeriveDebugButDoesNot)) ); - fn test_field_c() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - ShouldDeriveDebugButDoesNot, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldDeriveDebugButDoesNot), - "::", - stringify!(c) - ) - ); - } - test_field_c(); - fn test_field_d() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - ShouldDeriveDebugButDoesNot, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(ShouldDeriveDebugButDoesNot), - "::", - stringify!(d) - ) - ); - } - test_field_d(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ShouldDeriveDebugButDoesNot), + "::", + stringify!(c) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(ShouldDeriveDebugButDoesNot), + "::", + stringify!(d) + ) + ); } impl Default for ShouldDeriveDebugButDoesNot { fn default() -> Self { diff --git a/tests/expectations/tests/issue-674-1.rs b/tests/expectations/tests/issue-674-1.rs index e3e7a54fde..a28b78ec8d 100644 --- a/tests/expectations/tests/issue-674-1.rs +++ b/tests/expectations/tests/issue-674-1.rs @@ -26,6 +26,8 @@ pub mod root { } #[test] fn bindgen_test_layout_CapturingContentInfo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -36,24 +38,18 @@ pub mod root { 1usize, concat!("Alignment of ", stringify!(CapturingContentInfo)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(CapturingContentInfo), - "::", - stringify!(a) - ) - ); - } - test_field_a(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(CapturingContentInfo), + "::", + stringify!(a) + ) + ); } } diff --git a/tests/expectations/tests/issue-674-2.rs b/tests/expectations/tests/issue-674-2.rs index 61a456f605..07ca59e831 100644 --- a/tests/expectations/tests/issue-674-2.rs +++ b/tests/expectations/tests/issue-674-2.rs @@ -26,6 +26,8 @@ pub mod root { } #[test] fn bindgen_test_layout_c() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -36,23 +38,14 @@ pub mod root { 1usize, concat!("Alignment of ", stringify!(c)) ); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(c), - "::", - stringify!(b) - ) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(c), "::", stringify!(b)) + ); } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -61,6 +54,8 @@ pub mod root { } #[test] fn bindgen_test_layout_B() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -71,23 +66,14 @@ pub mod root { 1usize, concat!("Alignment of ", stringify!(B)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(B), - "::", - stringify!(a) - ) - ); - } - test_field_a(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(B), "::", stringify!(a)) + ); } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] diff --git a/tests/expectations/tests/issue-674-3.rs b/tests/expectations/tests/issue-674-3.rs index b45a953e99..cd8421be6f 100644 --- a/tests/expectations/tests/issue-674-3.rs +++ b/tests/expectations/tests/issue-674-3.rs @@ -22,6 +22,8 @@ pub mod root { } #[test] fn bindgen_test_layout_a() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -32,23 +34,14 @@ pub mod root { 1usize, concat!("Alignment of ", stringify!(a)) ); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(a), - "::", - stringify!(b) - ) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(a), "::", stringify!(b)) + ); } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -57,6 +50,8 @@ pub mod root { } #[test] fn bindgen_test_layout_nsCSSValue() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -67,23 +62,18 @@ pub mod root { 1usize, concat!("Alignment of ", stringify!(nsCSSValue)) ); - fn test_field_c() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsCSSValue), - "::", - stringify!(c) - ) - ); - } - test_field_c(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(nsCSSValue), + "::", + stringify!(c) + ) + ); } } diff --git a/tests/expectations/tests/issue-801-opaque-sloppiness.rs b/tests/expectations/tests/issue-801-opaque-sloppiness.rs index cd89eec5e8..9252bab92c 100644 --- a/tests/expectations/tests/issue-801-opaque-sloppiness.rs +++ b/tests/expectations/tests/issue-801-opaque-sloppiness.rs @@ -40,6 +40,8 @@ pub struct C { } #[test] fn bindgen_test_layout_C() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -50,16 +52,12 @@ fn bindgen_test_layout_C() { 1usize, concat!("Alignment of ", stringify!(C)) ); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(b)) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(b)) + ); } diff --git a/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs b/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs index 584bd00a35..6d66e61007 100644 --- a/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs +++ b/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs @@ -109,6 +109,8 @@ pub struct Allowlisted { } #[test] fn bindgen_test_layout_Allowlisted() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -119,21 +121,17 @@ fn bindgen_test_layout_Allowlisted() { 1usize, concat!("Alignment of ", stringify!(Allowlisted)) ); - fn test_field_some_member() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).some_member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Allowlisted), - "::", - stringify!(some_member) - ) - ); - } - test_field_some_member(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).some_member) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Allowlisted), + "::", + stringify!(some_member) + ) + ); } diff --git a/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs b/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs index af00cb2df1..5bc5977799 100644 --- a/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs +++ b/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs @@ -14,6 +14,8 @@ pub struct ShouldNotBeCopy { } #[test] fn bindgen_test_layout_ShouldNotBeCopy() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -24,24 +26,19 @@ fn bindgen_test_layout_ShouldNotBeCopy() { 1usize, concat!("Alignment of ", stringify!(ShouldNotBeCopy)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldNotBeCopy), - "::", - stringify!(a) - ) - ); - } - test_field_a(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ShouldNotBeCopy), + "::", + stringify!(a) + ) + ); } impl Default for ShouldNotBeCopy { fn default() -> Self { diff --git a/tests/expectations/tests/jsval_layout_opaque.rs b/tests/expectations/tests/jsval_layout_opaque.rs index 383410bd8b..3340c9b275 100644 --- a/tests/expectations/tests/jsval_layout_opaque.rs +++ b/tests/expectations/tests/jsval_layout_opaque.rs @@ -277,6 +277,9 @@ pub union jsval_layout__bindgen_ty_2__bindgen_ty_1 { } #[test] fn bindgen_test_layout_jsval_layout__bindgen_ty_2__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit< + jsval_layout__bindgen_ty_2__bindgen_ty_1, + > = ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -293,63 +296,45 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2__bindgen_ty_1() { stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1) ) ); - fn test_field_i32() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - jsval_layout__bindgen_ty_2__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i32_) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), - "::", - stringify!(i32_) - ) - ); - } - test_field_i32(); - fn test_field_u32() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - jsval_layout__bindgen_ty_2__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).u32_) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), - "::", - stringify!(u32_) - ) - ); - } - test_field_u32(); - fn test_field_why() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - jsval_layout__bindgen_ty_2__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).why) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), - "::", - stringify!(why) - ) - ); - } - test_field_why(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).i32_) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), + "::", + stringify!(i32_) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).u32_) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), + "::", + stringify!(u32_) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).why) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), + "::", + stringify!(why) + ) + ); } impl Default for jsval_layout__bindgen_ty_2__bindgen_ty_1 { fn default() -> Self { @@ -362,6 +347,8 @@ impl Default for jsval_layout__bindgen_ty_2__bindgen_ty_1 { } #[test] fn bindgen_test_layout_jsval_layout__bindgen_ty_2() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -372,25 +359,19 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2() { 4usize, concat!("Alignment of ", stringify!(jsval_layout__bindgen_ty_2)) ); - fn test_field_payload() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - jsval_layout__bindgen_ty_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).payload) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2), - "::", - stringify!(payload) - ) - ); - } - test_field_payload(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).payload) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout__bindgen_ty_2), + "::", + stringify!(payload) + ) + ); } impl Default for jsval_layout__bindgen_ty_2 { fn default() -> Self { @@ -403,6 +384,8 @@ impl Default for jsval_layout__bindgen_ty_2 { } #[test] fn bindgen_test_layout_jsval_layout() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -413,125 +396,97 @@ fn bindgen_test_layout_jsval_layout() { 8usize, concat!("Alignment of ", stringify!(jsval_layout)) ); - fn test_field_asBits() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).asBits) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asBits) - ) - ); - } - test_field_asBits(); - fn test_field_debugView() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).debugView) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(debugView) - ) - ); - } - test_field_debugView(); - fn test_field_s() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).s) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(s) - ) - ); - } - test_field_s(); - fn test_field_asDouble() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).asDouble) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asDouble) - ) - ); - } - test_field_asDouble(); - fn test_field_asPtr() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).asPtr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asPtr) - ) - ); - } - test_field_asPtr(); - fn test_field_asWord() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).asWord) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asWord) - ) - ); - } - test_field_asWord(); - fn test_field_asUIntPtr() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).asUIntPtr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asUIntPtr) - ) - ); - } - test_field_asUIntPtr(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).asBits) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout), + "::", + stringify!(asBits) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).debugView) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout), + "::", + stringify!(debugView) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).s) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout), + "::", + stringify!(s) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).asDouble) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout), + "::", + stringify!(asDouble) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).asPtr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout), + "::", + stringify!(asPtr) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).asWord) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout), + "::", + stringify!(asWord) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).asUIntPtr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout), + "::", + stringify!(asUIntPtr) + ) + ); } impl Default for jsval_layout { fn default() -> Self { @@ -549,6 +504,8 @@ pub struct Value { } #[test] fn bindgen_test_layout_Value() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -559,23 +516,19 @@ fn bindgen_test_layout_Value() { 8usize, concat!("Alignment of ", stringify!(Value)) ); - fn test_field_data() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Value), - "::", - stringify!(data) - ) - ); - } - test_field_data(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Value), + "::", + stringify!(data) + ) + ); } impl Default for Value { fn default() -> Self { diff --git a/tests/expectations/tests/jsval_layout_opaque_1_0.rs b/tests/expectations/tests/jsval_layout_opaque_1_0.rs index bdb411043a..055d273a88 100644 --- a/tests/expectations/tests/jsval_layout_opaque_1_0.rs +++ b/tests/expectations/tests/jsval_layout_opaque_1_0.rs @@ -327,6 +327,9 @@ pub struct jsval_layout__bindgen_ty_2__bindgen_ty_1 { } #[test] fn bindgen_test_layout_jsval_layout__bindgen_ty_2__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit< + jsval_layout__bindgen_ty_2__bindgen_ty_1, + > = ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -343,63 +346,45 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2__bindgen_ty_1() { stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1) ) ); - fn test_field_i32() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - jsval_layout__bindgen_ty_2__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i32_) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), - "::", - stringify!(i32_) - ) - ); - } - test_field_i32(); - fn test_field_u32() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - jsval_layout__bindgen_ty_2__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).u32_) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), - "::", - stringify!(u32_) - ) - ); - } - test_field_u32(); - fn test_field_why() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - jsval_layout__bindgen_ty_2__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).why) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), - "::", - stringify!(why) - ) - ); - } - test_field_why(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).i32_) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), + "::", + stringify!(i32_) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).u32_) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), + "::", + stringify!(u32_) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).why) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), + "::", + stringify!(why) + ) + ); } impl Clone for jsval_layout__bindgen_ty_2__bindgen_ty_1 { fn clone(&self) -> Self { @@ -408,6 +393,8 @@ impl Clone for jsval_layout__bindgen_ty_2__bindgen_ty_1 { } #[test] fn bindgen_test_layout_jsval_layout__bindgen_ty_2() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -418,25 +405,19 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2() { 4usize, concat!("Alignment of ", stringify!(jsval_layout__bindgen_ty_2)) ); - fn test_field_payload() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - jsval_layout__bindgen_ty_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).payload) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2), - "::", - stringify!(payload) - ) - ); - } - test_field_payload(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).payload) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout__bindgen_ty_2), + "::", + stringify!(payload) + ) + ); } impl Clone for jsval_layout__bindgen_ty_2 { fn clone(&self) -> Self { @@ -445,6 +426,8 @@ impl Clone for jsval_layout__bindgen_ty_2 { } #[test] fn bindgen_test_layout_jsval_layout() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -455,125 +438,97 @@ fn bindgen_test_layout_jsval_layout() { 8usize, concat!("Alignment of ", stringify!(jsval_layout)) ); - fn test_field_asBits() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).asBits) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asBits) - ) - ); - } - test_field_asBits(); - fn test_field_debugView() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).debugView) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(debugView) - ) - ); - } - test_field_debugView(); - fn test_field_s() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).s) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(s) - ) - ); - } - test_field_s(); - fn test_field_asDouble() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).asDouble) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asDouble) - ) - ); - } - test_field_asDouble(); - fn test_field_asPtr() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).asPtr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asPtr) - ) - ); - } - test_field_asPtr(); - fn test_field_asWord() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).asWord) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asWord) - ) - ); - } - test_field_asWord(); - fn test_field_asUIntPtr() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).asUIntPtr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asUIntPtr) - ) - ); - } - test_field_asUIntPtr(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).asBits) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout), + "::", + stringify!(asBits) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).debugView) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout), + "::", + stringify!(debugView) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).s) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout), + "::", + stringify!(s) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).asDouble) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout), + "::", + stringify!(asDouble) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).asPtr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout), + "::", + stringify!(asPtr) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).asWord) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout), + "::", + stringify!(asWord) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).asUIntPtr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout), + "::", + stringify!(asUIntPtr) + ) + ); } impl Clone for jsval_layout { fn clone(&self) -> Self { @@ -587,6 +542,8 @@ pub struct Value { } #[test] fn bindgen_test_layout_Value() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -597,23 +554,19 @@ fn bindgen_test_layout_Value() { 8usize, concat!("Alignment of ", stringify!(Value)) ); - fn test_field_data() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Value), - "::", - stringify!(data) - ) - ); - } - test_field_data(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Value), + "::", + stringify!(data) + ) + ); } impl Clone for Value { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/layout_arp.rs b/tests/expectations/tests/layout_arp.rs index fc3aa5d533..f0277dd836 100644 --- a/tests/expectations/tests/layout_arp.rs +++ b/tests/expectations/tests/layout_arp.rs @@ -30,6 +30,8 @@ pub struct ether_addr { } #[test] fn bindgen_test_layout_ether_addr() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 6usize, @@ -40,23 +42,19 @@ fn bindgen_test_layout_ether_addr() { 1usize, concat!("Alignment of ", stringify!(ether_addr)) ); - fn test_field_addr_bytes() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).addr_bytes) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ether_addr), - "::", - stringify!(addr_bytes) - ) - ); - } - test_field_addr_bytes(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).addr_bytes) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ether_addr), + "::", + stringify!(addr_bytes) + ) + ); } /// ARP header IPv4 payload. #[repr(C, packed)] @@ -73,6 +71,8 @@ pub struct arp_ipv4 { } #[test] fn bindgen_test_layout_arp_ipv4() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 20usize, @@ -83,74 +83,58 @@ fn bindgen_test_layout_arp_ipv4() { 1usize, concat!("Alignment of ", stringify!(arp_ipv4)) ); - fn test_field_arp_sha() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).arp_sha) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(arp_ipv4), - "::", - stringify!(arp_sha) - ) - ); - } - test_field_arp_sha(); - fn test_field_arp_sip() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).arp_sip) as usize - ptr as usize - }, - 6usize, - concat!( - "Offset of field: ", - stringify!(arp_ipv4), - "::", - stringify!(arp_sip) - ) - ); - } - test_field_arp_sip(); - fn test_field_arp_tha() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).arp_tha) as usize - ptr as usize - }, - 10usize, - concat!( - "Offset of field: ", - stringify!(arp_ipv4), - "::", - stringify!(arp_tha) - ) - ); - } - test_field_arp_tha(); - fn test_field_arp_tip() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).arp_tip) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(arp_ipv4), - "::", - stringify!(arp_tip) - ) - ); - } - test_field_arp_tip(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).arp_sha) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(arp_ipv4), + "::", + stringify!(arp_sha) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).arp_sip) as usize - ptr as usize + }, + 6usize, + concat!( + "Offset of field: ", + stringify!(arp_ipv4), + "::", + stringify!(arp_sip) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).arp_tha) as usize - ptr as usize + }, + 10usize, + concat!( + "Offset of field: ", + stringify!(arp_ipv4), + "::", + stringify!(arp_tha) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).arp_tip) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(arp_ipv4), + "::", + stringify!(arp_tip) + ) + ); } /// ARP header. #[repr(C, packed)] @@ -165,6 +149,8 @@ pub struct arp_hdr { } #[test] fn bindgen_test_layout_arp_hdr() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 28usize, @@ -175,106 +161,82 @@ fn bindgen_test_layout_arp_hdr() { 1usize, concat!("Alignment of ", stringify!(arp_hdr)) ); - fn test_field_arp_hrd() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).arp_hrd) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(arp_hdr), - "::", - stringify!(arp_hrd) - ) - ); - } - test_field_arp_hrd(); - fn test_field_arp_pro() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).arp_pro) as usize - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(arp_hdr), - "::", - stringify!(arp_pro) - ) - ); - } - test_field_arp_pro(); - fn test_field_arp_hln() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).arp_hln) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(arp_hdr), - "::", - stringify!(arp_hln) - ) - ); - } - test_field_arp_hln(); - fn test_field_arp_pln() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).arp_pln) as usize - ptr as usize - }, - 5usize, - concat!( - "Offset of field: ", - stringify!(arp_hdr), - "::", - stringify!(arp_pln) - ) - ); - } - test_field_arp_pln(); - fn test_field_arp_op() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).arp_op) as usize - ptr as usize - }, - 6usize, - concat!( - "Offset of field: ", - stringify!(arp_hdr), - "::", - stringify!(arp_op) - ) - ); - } - test_field_arp_op(); - fn test_field_arp_data() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).arp_data) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(arp_hdr), - "::", - stringify!(arp_data) - ) - ); - } - test_field_arp_data(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).arp_hrd) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(arp_hdr), + "::", + stringify!(arp_hrd) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).arp_pro) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(arp_hdr), + "::", + stringify!(arp_pro) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).arp_hln) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(arp_hdr), + "::", + stringify!(arp_hln) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).arp_pln) as usize - ptr as usize + }, + 5usize, + concat!( + "Offset of field: ", + stringify!(arp_hdr), + "::", + stringify!(arp_pln) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).arp_op) as usize - ptr as usize + }, + 6usize, + concat!( + "Offset of field: ", + stringify!(arp_hdr), + "::", + stringify!(arp_op) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).arp_data) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(arp_hdr), + "::", + stringify!(arp_data) + ) + ); } diff --git a/tests/expectations/tests/layout_array.rs b/tests/expectations/tests/layout_array.rs index c8ee421636..83fb15b826 100644 --- a/tests/expectations/tests/layout_array.rs +++ b/tests/expectations/tests/layout_array.rs @@ -69,6 +69,8 @@ pub struct rte_mempool_ops { } #[test] fn bindgen_test_layout_rte_mempool_ops() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 128usize, @@ -79,114 +81,84 @@ fn bindgen_test_layout_rte_mempool_ops() { 64usize, concat!("Alignment of ", stringify!(rte_mempool_ops)) ); - fn test_field_name() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).name) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mempool_ops), - "::", - stringify!(name) - ) - ); - } - test_field_name(); - fn test_field_alloc() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).alloc) as usize - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(rte_mempool_ops), - "::", - stringify!(alloc) - ) - ); - } - test_field_alloc(); - fn test_field_free() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).free) as usize - ptr as usize - }, - 40usize, - concat!( - "Offset of field: ", - stringify!(rte_mempool_ops), - "::", - stringify!(free) - ) - ); - } - test_field_free(); - fn test_field_enqueue() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).enqueue) as usize - ptr as usize - }, - 48usize, - concat!( - "Offset of field: ", - stringify!(rte_mempool_ops), - "::", - stringify!(enqueue) - ) - ); - } - test_field_enqueue(); - fn test_field_dequeue() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dequeue) as usize - ptr as usize - }, - 56usize, - concat!( - "Offset of field: ", - stringify!(rte_mempool_ops), - "::", - stringify!(dequeue) - ) - ); - } - test_field_dequeue(); - fn test_field_get_count() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).get_count) as usize - ptr as usize - }, - 64usize, - concat!( - "Offset of field: ", - stringify!(rte_mempool_ops), - "::", - stringify!(get_count) - ) - ); - } - test_field_get_count(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).name) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mempool_ops), + "::", + stringify!(name) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).alloc) as usize - ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(rte_mempool_ops), + "::", + stringify!(alloc) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).free) as usize - ptr as usize + }, + 40usize, + concat!( + "Offset of field: ", + stringify!(rte_mempool_ops), + "::", + stringify!(free) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).enqueue) as usize - ptr as usize + }, + 48usize, + concat!( + "Offset of field: ", + stringify!(rte_mempool_ops), + "::", + stringify!(enqueue) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).dequeue) as usize - ptr as usize + }, + 56usize, + concat!( + "Offset of field: ", + stringify!(rte_mempool_ops), + "::", + stringify!(dequeue) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).get_count) as usize - ptr as usize + }, + 64usize, + concat!( + "Offset of field: ", + stringify!(rte_mempool_ops), + "::", + stringify!(get_count) + ) + ); } impl Default for rte_mempool_ops { fn default() -> Self { @@ -216,6 +188,8 @@ pub struct rte_spinlock_t { } #[test] fn bindgen_test_layout_rte_spinlock_t() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -226,24 +200,19 @@ fn bindgen_test_layout_rte_spinlock_t() { 4usize, concat!("Alignment of ", stringify!(rte_spinlock_t)) ); - fn test_field_locked() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).locked) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_spinlock_t), - "::", - stringify!(locked) - ) - ); - } - test_field_locked(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).locked) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_spinlock_t), + "::", + stringify!(locked) + ) + ); } /// Structure storing the table of registered ops structs, each of which contain /// the function pointers for the mempool ops functions. @@ -266,6 +235,8 @@ pub struct rte_mempool_ops_table { } #[test] fn bindgen_test_layout_rte_mempool_ops_table() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 2112usize, @@ -276,60 +247,45 @@ fn bindgen_test_layout_rte_mempool_ops_table() { 64usize, concat!("Alignment of ", stringify!(rte_mempool_ops_table)) ); - fn test_field_sl() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).sl) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mempool_ops_table), - "::", - stringify!(sl) - ) - ); - } - test_field_sl(); - fn test_field_num_ops() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).num_ops) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_mempool_ops_table), - "::", - stringify!(num_ops) - ) - ); - } - test_field_num_ops(); - fn test_field_ops() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ops) as usize - ptr as usize - }, - 64usize, - concat!( - "Offset of field: ", - stringify!(rte_mempool_ops_table), - "::", - stringify!(ops) - ) - ); - } - test_field_ops(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).sl) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mempool_ops_table), + "::", + stringify!(sl) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).num_ops) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_mempool_ops_table), + "::", + stringify!(num_ops) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).ops) as usize - ptr as usize + }, + 64usize, + concat!( + "Offset of field: ", + stringify!(rte_mempool_ops_table), + "::", + stringify!(ops) + ) + ); } impl Default for rte_mempool_ops_table { fn default() -> Self { @@ -357,6 +313,8 @@ pub struct malloc_heap__bindgen_ty_1 { } #[test] fn bindgen_test_layout_malloc_heap__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -367,23 +325,19 @@ fn bindgen_test_layout_malloc_heap__bindgen_ty_1() { 8usize, concat!("Alignment of ", stringify!(malloc_heap__bindgen_ty_1)) ); - fn test_field_lh_first() { - assert_eq!( - unsafe { - let uninit = :: std :: mem :: MaybeUninit :: < malloc_heap__bindgen_ty_1 > :: uninit () ; - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).lh_first) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(malloc_heap__bindgen_ty_1), - "::", - stringify!(lh_first) - ) - ); - } - test_field_lh_first(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).lh_first) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(malloc_heap__bindgen_ty_1), + "::", + stringify!(lh_first) + ) + ); } impl Default for malloc_heap__bindgen_ty_1 { fn default() -> Self { @@ -396,6 +350,8 @@ impl Default for malloc_heap__bindgen_ty_1 { } #[test] fn bindgen_test_layout_malloc_heap() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 128usize, @@ -406,74 +362,58 @@ fn bindgen_test_layout_malloc_heap() { 64usize, concat!("Alignment of ", stringify!(malloc_heap)) ); - fn test_field_lock() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).lock) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(malloc_heap), - "::", - stringify!(lock) - ) - ); - } - test_field_lock(); - fn test_field_free_head() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).free_head) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(malloc_heap), - "::", - stringify!(free_head) - ) - ); - } - test_field_free_head(); - fn test_field_alloc_count() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).alloc_count) as usize - ptr as usize - }, - 112usize, - concat!( - "Offset of field: ", - stringify!(malloc_heap), - "::", - stringify!(alloc_count) - ) - ); - } - test_field_alloc_count(); - fn test_field_total_size() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).total_size) as usize - ptr as usize - }, - 120usize, - concat!( - "Offset of field: ", - stringify!(malloc_heap), - "::", - stringify!(total_size) - ) - ); - } - test_field_total_size(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).lock) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(malloc_heap), + "::", + stringify!(lock) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).free_head) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(malloc_heap), + "::", + stringify!(free_head) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).alloc_count) as usize - ptr as usize + }, + 112usize, + concat!( + "Offset of field: ", + stringify!(malloc_heap), + "::", + stringify!(alloc_count) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).total_size) as usize - ptr as usize + }, + 120usize, + concat!( + "Offset of field: ", + stringify!(malloc_heap), + "::", + stringify!(total_size) + ) + ); } impl Default for malloc_heap { fn default() -> Self { diff --git a/tests/expectations/tests/layout_array_too_long.rs b/tests/expectations/tests/layout_array_too_long.rs index 586d35ecb5..c1575a0274 100644 --- a/tests/expectations/tests/layout_array_too_long.rs +++ b/tests/expectations/tests/layout_array_too_long.rs @@ -35,6 +35,8 @@ pub struct ip_frag { } #[test] fn bindgen_test_layout_ip_frag() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -45,57 +47,45 @@ fn bindgen_test_layout_ip_frag() { 8usize, concat!("Alignment of ", stringify!(ip_frag)) ); - fn test_field_ofs() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ofs) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ip_frag), - "::", - stringify!(ofs) - ) - ); - } - test_field_ofs(); - fn test_field_len() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(ip_frag), - "::", - stringify!(len) - ) - ); - } - test_field_len(); - fn test_field_mb() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mb) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(ip_frag), - "::", - stringify!(mb) - ) - ); - } - test_field_mb(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).ofs) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ip_frag), + "::", + stringify!(ofs) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(ip_frag), + "::", + stringify!(len) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mb) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(ip_frag), + "::", + stringify!(mb) + ) + ); } impl Default for ip_frag { fn default() -> Self { @@ -119,6 +109,8 @@ pub struct ip_frag_key { } #[test] fn bindgen_test_layout_ip_frag_key() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 40usize, @@ -129,57 +121,45 @@ fn bindgen_test_layout_ip_frag_key() { 8usize, concat!("Alignment of ", stringify!(ip_frag_key)) ); - fn test_field_src_dst() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).src_dst) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_key), - "::", - stringify!(src_dst) - ) - ); - } - test_field_src_dst(); - fn test_field_id() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).id) as usize - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_key), - "::", - stringify!(id) - ) - ); - } - test_field_id(); - fn test_field_key_len() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).key_len) as usize - ptr as usize - }, - 36usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_key), - "::", - stringify!(key_len) - ) - ); - } - test_field_key_len(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).src_dst) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_key), + "::", + stringify!(src_dst) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).id) as usize - ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_key), + "::", + stringify!(id) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).key_len) as usize - ptr as usize + }, + 36usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_key), + "::", + stringify!(key_len) + ) + ); } /// @internal Fragmented packet to reassemble. /// First two entries in the frags[] array are for the last and first fragments. @@ -210,6 +190,8 @@ pub struct ip_frag_pkt__bindgen_ty_1 { } #[test] fn bindgen_test_layout_ip_frag_pkt__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -220,40 +202,32 @@ fn bindgen_test_layout_ip_frag_pkt__bindgen_ty_1() { 8usize, concat!("Alignment of ", stringify!(ip_frag_pkt__bindgen_ty_1)) ); - fn test_field_tqe_next() { - assert_eq!( - unsafe { - let uninit = :: std :: mem :: MaybeUninit :: < ip_frag_pkt__bindgen_ty_1 > :: uninit () ; - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).tqe_next) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt__bindgen_ty_1), - "::", - stringify!(tqe_next) - ) - ); - } - test_field_tqe_next(); - fn test_field_tqe_prev() { - assert_eq!( - unsafe { - let uninit = :: std :: mem :: MaybeUninit :: < ip_frag_pkt__bindgen_ty_1 > :: uninit () ; - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).tqe_prev) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt__bindgen_ty_1), - "::", - stringify!(tqe_prev) - ) - ); - } - test_field_tqe_prev(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).tqe_next) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_pkt__bindgen_ty_1), + "::", + stringify!(tqe_next) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).tqe_prev) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_pkt__bindgen_ty_1), + "::", + stringify!(tqe_prev) + ) + ); } impl Default for ip_frag_pkt__bindgen_ty_1 { fn default() -> Self { @@ -266,6 +240,8 @@ 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(); assert_eq!( ::std::mem::size_of::(), 192usize, @@ -276,125 +252,97 @@ fn bindgen_test_layout_ip_frag_pkt() { 64usize, concat!("Alignment of ", stringify!(ip_frag_pkt)) ); - fn test_field_lru() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).lru) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(lru) - ) - ); - } - test_field_lru(); - fn test_field_key() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).key) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(key) - ) - ); - } - test_field_key(); - fn test_field_start() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).start) as usize - ptr as usize - }, - 56usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(start) - ) - ); - } - test_field_start(); - fn test_field_total_size() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).total_size) as usize - ptr as usize - }, - 64usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(total_size) - ) - ); - } - test_field_total_size(); - fn test_field_frag_size() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).frag_size) as usize - ptr as usize - }, - 68usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(frag_size) - ) - ); - } - test_field_frag_size(); - fn test_field_last_idx() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).last_idx) as usize - ptr as usize - }, - 72usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(last_idx) - ) - ); - } - test_field_last_idx(); - fn test_field_frags() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).frags) as usize - ptr as usize - }, - 80usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(frags) - ) - ); - } - test_field_frags(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).lru) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_pkt), + "::", + stringify!(lru) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).key) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_pkt), + "::", + stringify!(key) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).start) as usize - ptr as usize + }, + 56usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_pkt), + "::", + stringify!(start) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).total_size) as usize - ptr as usize + }, + 64usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_pkt), + "::", + stringify!(total_size) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).frag_size) as usize - ptr as usize + }, + 68usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_pkt), + "::", + stringify!(frag_size) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).last_idx) as usize - ptr as usize + }, + 72usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_pkt), + "::", + stringify!(last_idx) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).frags) as usize - ptr as usize + }, + 80usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_pkt), + "::", + stringify!(frags) + ) + ); } impl Default for ip_frag_pkt { fn default() -> Self { diff --git a/tests/expectations/tests/layout_cmdline_token.rs b/tests/expectations/tests/layout_cmdline_token.rs index a4360cd310..0f6e0ca4ab 100644 --- a/tests/expectations/tests/layout_cmdline_token.rs +++ b/tests/expectations/tests/layout_cmdline_token.rs @@ -15,6 +15,8 @@ pub struct cmdline_token_hdr { } #[test] fn bindgen_test_layout_cmdline_token_hdr() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -25,42 +27,32 @@ fn bindgen_test_layout_cmdline_token_hdr() { 8usize, concat!("Alignment of ", stringify!(cmdline_token_hdr)) ); - fn test_field_ops() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ops) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(cmdline_token_hdr), - "::", - stringify!(ops) - ) - ); - } - test_field_ops(); - fn test_field_offset() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).offset) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(cmdline_token_hdr), - "::", - stringify!(offset) - ) - ); - } - test_field_offset(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).ops) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(cmdline_token_hdr), + "::", + stringify!(ops) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).offset) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(cmdline_token_hdr), + "::", + stringify!(offset) + ) + ); } impl Default for cmdline_token_hdr { fn default() -> Self { @@ -129,6 +121,8 @@ pub struct cmdline_token_ops { } #[test] fn bindgen_test_layout_cmdline_token_ops() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 32usize, @@ -139,80 +133,59 @@ fn bindgen_test_layout_cmdline_token_ops() { 8usize, concat!("Alignment of ", stringify!(cmdline_token_ops)) ); - fn test_field_parse() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).parse) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(cmdline_token_ops), - "::", - stringify!(parse) - ) - ); - } - test_field_parse(); - fn test_field_complete_get_nb() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).complete_get_nb) as usize - - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(cmdline_token_ops), - "::", - stringify!(complete_get_nb) - ) - ); - } - test_field_complete_get_nb(); - fn test_field_complete_get_elt() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).complete_get_elt) as usize - - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(cmdline_token_ops), - "::", - stringify!(complete_get_elt) - ) - ); - } - test_field_complete_get_elt(); - fn test_field_get_help() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).get_help) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(cmdline_token_ops), - "::", - stringify!(get_help) - ) - ); - } - test_field_get_help(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).parse) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(cmdline_token_ops), + "::", + stringify!(parse) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).complete_get_nb) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(cmdline_token_ops), + "::", + stringify!(complete_get_nb) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).complete_get_elt) as usize - + ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(cmdline_token_ops), + "::", + stringify!(complete_get_elt) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).get_help) as usize - ptr as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(cmdline_token_ops), + "::", + stringify!(get_help) + ) + ); } #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] @@ -233,6 +206,8 @@ pub struct cmdline_token_num_data { } #[test] fn bindgen_test_layout_cmdline_token_num_data() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -243,24 +218,19 @@ fn bindgen_test_layout_cmdline_token_num_data() { 4usize, concat!("Alignment of ", stringify!(cmdline_token_num_data)) ); - fn test_field_type() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(cmdline_token_num_data), - "::", - stringify!(type_) - ) - ); - } - test_field_type(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(cmdline_token_num_data), + "::", + stringify!(type_) + ) + ); } impl Default for cmdline_token_num_data { fn default() -> Self { @@ -279,6 +249,8 @@ pub struct cmdline_token_num { } #[test] fn bindgen_test_layout_cmdline_token_num() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 24usize, @@ -289,42 +261,32 @@ fn bindgen_test_layout_cmdline_token_num() { 8usize, concat!("Alignment of ", stringify!(cmdline_token_num)) ); - fn test_field_hdr() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).hdr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(cmdline_token_num), - "::", - stringify!(hdr) - ) - ); - } - test_field_hdr(); - fn test_field_num_data() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).num_data) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(cmdline_token_num), - "::", - stringify!(num_data) - ) - ); - } - test_field_num_data(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).hdr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(cmdline_token_num), + "::", + stringify!(hdr) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).num_data) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(cmdline_token_num), + "::", + stringify!(num_data) + ) + ); } impl Default for cmdline_token_num { fn default() -> Self { diff --git a/tests/expectations/tests/layout_eth_conf.rs b/tests/expectations/tests/layout_eth_conf.rs index 3296a0f8cc..839a4ac690 100644 --- a/tests/expectations/tests/layout_eth_conf.rs +++ b/tests/expectations/tests/layout_eth_conf.rs @@ -160,6 +160,8 @@ pub struct rte_eth_rxmode { } #[test] fn bindgen_test_layout_rte_eth_rxmode() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 12usize, @@ -170,62 +172,45 @@ fn bindgen_test_layout_rte_eth_rxmode() { 4usize, concat!("Alignment of ", stringify!(rte_eth_rxmode)) ); - fn test_field_mq_mode() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mq_mode) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rxmode), - "::", - stringify!(mq_mode) - ) - ); - } - test_field_mq_mode(); - fn test_field_max_rx_pkt_len() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).max_rx_pkt_len) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rxmode), - "::", - stringify!(max_rx_pkt_len) - ) - ); - } - test_field_max_rx_pkt_len(); - fn test_field_split_hdr_size() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).split_hdr_size) as usize - - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rxmode), - "::", - stringify!(split_hdr_size) - ) - ); - } - test_field_split_hdr_size(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mq_mode) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_rxmode), + "::", + stringify!(mq_mode) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).max_rx_pkt_len) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_rxmode), + "::", + stringify!(max_rx_pkt_len) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).split_hdr_size) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_rxmode), + "::", + stringify!(split_hdr_size) + ) + ); } impl Default for rte_eth_rxmode { fn default() -> Self { @@ -442,6 +427,8 @@ pub struct rte_eth_txmode { } #[test] fn bindgen_test_layout_rte_eth_txmode() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -452,42 +439,32 @@ fn bindgen_test_layout_rte_eth_txmode() { 4usize, concat!("Alignment of ", stringify!(rte_eth_txmode)) ); - fn test_field_mq_mode() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mq_mode) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_txmode), - "::", - stringify!(mq_mode) - ) - ); - } - test_field_mq_mode(); - fn test_field_pvid() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pvid) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_txmode), - "::", - stringify!(pvid) - ) - ); - } - test_field_pvid(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mq_mode) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_txmode), + "::", + stringify!(mq_mode) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).pvid) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_txmode), + "::", + stringify!(pvid) + ) + ); } impl Default for rte_eth_txmode { fn default() -> Self { @@ -591,6 +568,8 @@ pub struct rte_eth_rss_conf { } #[test] fn bindgen_test_layout_rte_eth_rss_conf() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 24usize, @@ -601,60 +580,45 @@ fn bindgen_test_layout_rte_eth_rss_conf() { 8usize, concat!("Alignment of ", stringify!(rte_eth_rss_conf)) ); - fn test_field_rss_key() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rss_key) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rss_conf), - "::", - stringify!(rss_key) - ) - ); - } - test_field_rss_key(); - fn test_field_rss_key_len() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rss_key_len) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rss_conf), - "::", - stringify!(rss_key_len) - ) - ); - } - test_field_rss_key_len(); - fn test_field_rss_hf() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rss_hf) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rss_conf), - "::", - stringify!(rss_hf) - ) - ); - } - test_field_rss_hf(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).rss_key) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_rss_conf), + "::", + stringify!(rss_key) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).rss_key_len) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_rss_conf), + "::", + stringify!(rss_key_len) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).rss_hf) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_rss_conf), + "::", + stringify!(rss_hf) + ) + ); } impl Default for rte_eth_rss_conf { fn default() -> Self { @@ -723,6 +687,8 @@ pub struct rte_eth_vmdq_dcb_conf__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_eth_vmdq_dcb_conf__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -736,47 +702,37 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf__bindgen_ty_1() { stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1) ) ); - fn test_field_vlan_id() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_eth_vmdq_dcb_conf__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).vlan_id) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1), - "::", - stringify!(vlan_id) - ) - ); - } - test_field_vlan_id(); - fn test_field_pools() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_eth_vmdq_dcb_conf__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pools) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1), - "::", - stringify!(pools) - ) - ); - } - test_field_pools(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).vlan_id) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1), + "::", + stringify!(vlan_id) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).pools) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1), + "::", + stringify!(pools) + ) + ); } #[test] fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 1040usize, @@ -787,118 +743,85 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { 8usize, concat!("Alignment of ", stringify!(rte_eth_vmdq_dcb_conf)) ); - fn test_field_nb_queue_pools() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(nb_queue_pools) - ) - ); - } - test_field_nb_queue_pools(); - fn test_field_enable_default_pool() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).enable_default_pool) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(enable_default_pool) - ) - ); - } - test_field_enable_default_pool(); - fn test_field_default_pool() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).default_pool) as usize - - ptr as usize - }, - 5usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(default_pool) - ) - ); - } - test_field_default_pool(); - fn test_field_nb_pool_maps() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_pool_maps) as usize - - ptr as usize - }, - 6usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(nb_pool_maps) - ) - ); - } - test_field_nb_pool_maps(); - fn test_field_pool_map() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pool_map) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(pool_map) - ) - ); - } - test_field_pool_map(); - fn test_field_dcb_tc() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize - }, - 1032usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(dcb_tc) - ) - ); - } - test_field_dcb_tc(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf), + "::", + stringify!(nb_queue_pools) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).enable_default_pool) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf), + "::", + stringify!(enable_default_pool) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).default_pool) as usize - ptr as usize + }, + 5usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf), + "::", + stringify!(default_pool) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_pool_maps) as usize - ptr as usize + }, + 6usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf), + "::", + stringify!(nb_pool_maps) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).pool_map) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf), + "::", + stringify!(pool_map) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize + }, + 1032usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf), + "::", + stringify!(dcb_tc) + ) + ); } impl Default for rte_eth_vmdq_dcb_conf { fn default() -> Self { @@ -919,6 +842,8 @@ pub struct rte_eth_dcb_rx_conf { } #[test] fn bindgen_test_layout_rte_eth_dcb_rx_conf() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 12usize, @@ -929,42 +854,32 @@ fn bindgen_test_layout_rte_eth_dcb_rx_conf() { 4usize, concat!("Alignment of ", stringify!(rte_eth_dcb_rx_conf)) ); - fn test_field_nb_tcs() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_dcb_rx_conf), - "::", - stringify!(nb_tcs) - ) - ); - } - test_field_nb_tcs(); - fn test_field_dcb_tc() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_dcb_rx_conf), - "::", - stringify!(dcb_tc) - ) - ); - } - test_field_dcb_tc(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_dcb_rx_conf), + "::", + stringify!(nb_tcs) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_dcb_rx_conf), + "::", + stringify!(dcb_tc) + ) + ); } impl Default for rte_eth_dcb_rx_conf { fn default() -> Self { @@ -985,6 +900,8 @@ pub struct rte_eth_vmdq_dcb_tx_conf { } #[test] fn bindgen_test_layout_rte_eth_vmdq_dcb_tx_conf() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 12usize, @@ -995,45 +912,32 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_tx_conf() { 4usize, concat!("Alignment of ", stringify!(rte_eth_vmdq_dcb_tx_conf)) ); - fn test_field_nb_queue_pools() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_tx_conf), - "::", - stringify!(nb_queue_pools) - ) - ); - } - test_field_nb_queue_pools(); - fn test_field_dcb_tc() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_tx_conf), - "::", - stringify!(dcb_tc) - ) - ); - } - test_field_dcb_tc(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_tx_conf), + "::", + stringify!(nb_queue_pools) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_tx_conf), + "::", + stringify!(dcb_tc) + ) + ); } impl Default for rte_eth_vmdq_dcb_tx_conf { fn default() -> Self { @@ -1054,6 +958,8 @@ pub struct rte_eth_dcb_tx_conf { } #[test] fn bindgen_test_layout_rte_eth_dcb_tx_conf() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 12usize, @@ -1064,42 +970,32 @@ fn bindgen_test_layout_rte_eth_dcb_tx_conf() { 4usize, concat!("Alignment of ", stringify!(rte_eth_dcb_tx_conf)) ); - fn test_field_nb_tcs() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_dcb_tx_conf), - "::", - stringify!(nb_tcs) - ) - ); - } - test_field_nb_tcs(); - fn test_field_dcb_tc() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_dcb_tx_conf), - "::", - stringify!(dcb_tc) - ) - ); - } - test_field_dcb_tc(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_dcb_tx_conf), + "::", + stringify!(nb_tcs) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_dcb_tx_conf), + "::", + stringify!(dcb_tc) + ) + ); } impl Default for rte_eth_dcb_tx_conf { fn default() -> Self { @@ -1118,6 +1014,8 @@ pub struct rte_eth_vmdq_tx_conf { } #[test] fn bindgen_test_layout_rte_eth_vmdq_tx_conf() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -1128,25 +1026,19 @@ fn bindgen_test_layout_rte_eth_vmdq_tx_conf() { 4usize, concat!("Alignment of ", stringify!(rte_eth_vmdq_tx_conf)) ); - fn test_field_nb_queue_pools() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_tx_conf), - "::", - stringify!(nb_queue_pools) - ) - ); - } - test_field_nb_queue_pools(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_tx_conf), + "::", + stringify!(nb_queue_pools) + ) + ); } impl Default for rte_eth_vmdq_tx_conf { fn default() -> Self { @@ -1185,6 +1077,8 @@ pub struct rte_eth_vmdq_rx_conf__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_eth_vmdq_rx_conf__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -1198,47 +1092,37 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf__bindgen_ty_1() { stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1) ) ); - fn test_field_vlan_id() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_eth_vmdq_rx_conf__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).vlan_id) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1), - "::", - stringify!(vlan_id) - ) - ); - } - test_field_vlan_id(); - fn test_field_pools() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_eth_vmdq_rx_conf__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pools) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1), - "::", - stringify!(pools) - ) - ); - } - test_field_pools(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).vlan_id) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1), + "::", + stringify!(vlan_id) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).pools) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1), + "::", + stringify!(pools) + ) + ); } #[test] fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 1040usize, @@ -1249,137 +1133,99 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { 8usize, concat!("Alignment of ", stringify!(rte_eth_vmdq_rx_conf)) ); - fn test_field_nb_queue_pools() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(nb_queue_pools) - ) - ); - } - test_field_nb_queue_pools(); - fn test_field_enable_default_pool() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).enable_default_pool) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(enable_default_pool) - ) - ); - } - test_field_enable_default_pool(); - fn test_field_default_pool() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).default_pool) as usize - - ptr as usize - }, - 5usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(default_pool) - ) - ); - } - test_field_default_pool(); - fn test_field_enable_loop_back() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).enable_loop_back) as usize - - ptr as usize - }, - 6usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(enable_loop_back) - ) - ); - } - test_field_enable_loop_back(); - fn test_field_nb_pool_maps() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_pool_maps) as usize - - ptr as usize - }, - 7usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(nb_pool_maps) - ) - ); - } - test_field_nb_pool_maps(); - fn test_field_rx_mode() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rx_mode) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(rx_mode) - ) - ); - } - test_field_rx_mode(); - fn test_field_pool_map() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pool_map) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(pool_map) - ) - ); - } - test_field_pool_map(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf), + "::", + stringify!(nb_queue_pools) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).enable_default_pool) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf), + "::", + stringify!(enable_default_pool) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).default_pool) as usize - ptr as usize + }, + 5usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf), + "::", + stringify!(default_pool) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).enable_loop_back) as usize - + ptr as usize + }, + 6usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf), + "::", + stringify!(enable_loop_back) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_pool_maps) as usize - ptr as usize + }, + 7usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf), + "::", + stringify!(nb_pool_maps) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).rx_mode) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf), + "::", + stringify!(rx_mode) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).pool_map) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf), + "::", + stringify!(pool_map) + ) + ); } impl Default for rte_eth_vmdq_rx_conf { fn default() -> Self { @@ -1445,6 +1291,8 @@ pub struct rte_eth_ipv4_flow { } #[test] fn bindgen_test_layout_rte_eth_ipv4_flow() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 12usize, @@ -1455,103 +1303,78 @@ fn bindgen_test_layout_rte_eth_ipv4_flow() { 4usize, concat!("Alignment of ", stringify!(rte_eth_ipv4_flow)) ); - fn test_field_src_ip() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(src_ip) - ) - ); - } - test_field_src_ip(); - fn test_field_dst_ip() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dst_ip) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(dst_ip) - ) - ); - } - test_field_dst_ip(); - fn test_field_tos() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).tos) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(tos) - ) - ); - } - test_field_tos(); - fn test_field_ttl() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ttl) as usize - ptr as usize - }, - 9usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(ttl) - ) - ); - } - test_field_ttl(); - fn test_field_proto() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize - }, - 10usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(proto) - ) - ); - } - test_field_proto(); -} -/// A structure used to define the input for IPV6 flow -#[repr(C)] -#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] -pub struct rte_eth_ipv6_flow { - ///< IPv6 source address in big endian. - pub src_ip: [u32; 4usize], + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv4_flow), + "::", + stringify!(src_ip) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).dst_ip) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv4_flow), + "::", + stringify!(dst_ip) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).tos) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv4_flow), + "::", + stringify!(tos) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).ttl) as usize - ptr as usize + }, + 9usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv4_flow), + "::", + stringify!(ttl) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize + }, + 10usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv4_flow), + "::", + stringify!(proto) + ) + ); +} +/// A structure used to define the input for IPV6 flow +#[repr(C)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] +pub struct rte_eth_ipv6_flow { + ///< IPv6 source address in big endian. + pub src_ip: [u32; 4usize], ///< IPv6 destination address in big endian. pub dst_ip: [u32; 4usize], ///< Traffic class to match. @@ -1563,6 +1386,8 @@ pub struct rte_eth_ipv6_flow { } #[test] fn bindgen_test_layout_rte_eth_ipv6_flow() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 36usize, @@ -1573,96 +1398,71 @@ fn bindgen_test_layout_rte_eth_ipv6_flow() { 4usize, concat!("Alignment of ", stringify!(rte_eth_ipv6_flow)) ); - fn test_field_src_ip() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(src_ip) - ) - ); - } - test_field_src_ip(); - fn test_field_dst_ip() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dst_ip) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(dst_ip) - ) - ); - } - test_field_dst_ip(); - fn test_field_tc() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).tc) as usize - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(tc) - ) - ); - } - test_field_tc(); - fn test_field_proto() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize - }, - 33usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(proto) - ) - ); - } - test_field_proto(); - fn test_field_hop_limits() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).hop_limits) as usize - ptr as usize - }, - 34usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(hop_limits) - ) - ); - } - test_field_hop_limits(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv6_flow), + "::", + stringify!(src_ip) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).dst_ip) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv6_flow), + "::", + stringify!(dst_ip) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).tc) as usize - ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv6_flow), + "::", + stringify!(tc) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize + }, + 33usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv6_flow), + "::", + stringify!(proto) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).hop_limits) as usize - ptr as usize + }, + 34usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv6_flow), + "::", + stringify!(hop_limits) + ) + ); } /// A structure used to configure FDIR masks that are used by the device /// to match the various fields of RX packet headers. @@ -1690,6 +1490,8 @@ pub struct rte_eth_fdir_masks { } #[test] fn bindgen_test_layout_rte_eth_fdir_masks() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 68usize, @@ -1700,156 +1502,112 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { 4usize, concat!("Alignment of ", stringify!(rte_eth_fdir_masks)) ); - fn test_field_vlan_tci_mask() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).vlan_tci_mask) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(vlan_tci_mask) - ) - ); - } - test_field_vlan_tci_mask(); - fn test_field_ipv4_mask() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ipv4_mask) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(ipv4_mask) - ) - ); - } - test_field_ipv4_mask(); - fn test_field_ipv6_mask() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ipv6_mask) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(ipv6_mask) - ) - ); - } - test_field_ipv6_mask(); - fn test_field_src_port_mask() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).src_port_mask) as usize - - ptr as usize - }, - 52usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(src_port_mask) - ) - ); - } - test_field_src_port_mask(); - fn test_field_dst_port_mask() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dst_port_mask) as usize - - ptr as usize - }, - 54usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(dst_port_mask) - ) - ); - } - test_field_dst_port_mask(); - fn test_field_mac_addr_byte_mask() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mac_addr_byte_mask) as usize - - ptr as usize - }, - 56usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(mac_addr_byte_mask) - ) - ); - } - test_field_mac_addr_byte_mask(); - fn test_field_tunnel_id_mask() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).tunnel_id_mask) as usize - - ptr as usize - }, - 60usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(tunnel_id_mask) - ) - ); - } - test_field_tunnel_id_mask(); - fn test_field_tunnel_type_mask() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).tunnel_type_mask) as usize - - ptr as usize - }, - 64usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(tunnel_type_mask) - ) - ); - } - test_field_tunnel_type_mask(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).vlan_tci_mask) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(vlan_tci_mask) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).ipv4_mask) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(ipv4_mask) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).ipv6_mask) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(ipv6_mask) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).src_port_mask) as usize - ptr as usize + }, + 52usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(src_port_mask) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).dst_port_mask) as usize - ptr as usize + }, + 54usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(dst_port_mask) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mac_addr_byte_mask) as usize - + ptr as usize + }, + 56usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(mac_addr_byte_mask) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).tunnel_id_mask) as usize - ptr as usize + }, + 60usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(tunnel_id_mask) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).tunnel_type_mask) as usize - + ptr as usize + }, + 64usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(tunnel_type_mask) + ) + ); } #[repr(u32)] /// Payload type @@ -1873,6 +1631,8 @@ pub struct rte_eth_flex_payload_cfg { } #[test] fn bindgen_test_layout_rte_eth_flex_payload_cfg() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 36usize, @@ -1883,44 +1643,32 @@ fn bindgen_test_layout_rte_eth_flex_payload_cfg() { 4usize, concat!("Alignment of ", stringify!(rte_eth_flex_payload_cfg)) ); - fn test_field_type() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_flex_payload_cfg), - "::", - stringify!(type_) - ) - ); - } - test_field_type(); - fn test_field_src_offset() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).src_offset) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_flex_payload_cfg), - "::", - stringify!(src_offset) - ) - ); - } - test_field_src_offset(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_flex_payload_cfg), + "::", + stringify!(type_) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).src_offset) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_flex_payload_cfg), + "::", + stringify!(src_offset) + ) + ); } impl Default for rte_eth_flex_payload_cfg { fn default() -> Self { @@ -1941,6 +1689,8 @@ pub struct rte_eth_fdir_flex_mask { } #[test] fn bindgen_test_layout_rte_eth_fdir_flex_mask() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 18usize, @@ -1951,42 +1701,32 @@ fn bindgen_test_layout_rte_eth_fdir_flex_mask() { 2usize, concat!("Alignment of ", stringify!(rte_eth_fdir_flex_mask)) ); - fn test_field_flow_type() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).flow_type) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_mask), - "::", - stringify!(flow_type) - ) - ); - } - test_field_flow_type(); - fn test_field_mask() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_mask), - "::", - stringify!(mask) - ) - ); - } - test_field_mask(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).flow_type) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_flex_mask), + "::", + stringify!(flow_type) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_flex_mask), + "::", + stringify!(mask) + ) + ); } /// A structure used to define all flexible payload related setting /// include flex payload and flex mask @@ -2002,6 +1742,8 @@ pub struct rte_eth_fdir_flex_conf { } #[test] fn bindgen_test_layout_rte_eth_fdir_flex_conf() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 688usize, @@ -2012,79 +1754,58 @@ fn bindgen_test_layout_rte_eth_fdir_flex_conf() { 4usize, concat!("Alignment of ", stringify!(rte_eth_fdir_flex_conf)) ); - fn test_field_nb_payloads() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_payloads) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_conf), - "::", - stringify!(nb_payloads) - ) - ); - } - test_field_nb_payloads(); - fn test_field_nb_flexmasks() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_flexmasks) as usize - - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_conf), - "::", - stringify!(nb_flexmasks) - ) - ); - } - test_field_nb_flexmasks(); - fn test_field_flex_set() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).flex_set) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_conf), - "::", - stringify!(flex_set) - ) - ); - } - test_field_flex_set(); - fn test_field_flex_mask() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).flex_mask) as usize - ptr as usize - }, - 292usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_conf), - "::", - stringify!(flex_mask) - ) - ); - } - test_field_flex_mask(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_payloads) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_flex_conf), + "::", + stringify!(nb_payloads) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_flexmasks) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_flex_conf), + "::", + stringify!(nb_flexmasks) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).flex_set) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_flex_conf), + "::", + stringify!(flex_set) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).flex_mask) as usize - ptr as usize + }, + 292usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_flex_conf), + "::", + stringify!(flex_mask) + ) + ); } impl Default for rte_eth_fdir_flex_conf { fn default() -> Self { @@ -2115,6 +1836,8 @@ pub struct rte_fdir_conf { } #[test] fn bindgen_test_layout_rte_fdir_conf() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 772usize, @@ -2125,108 +1848,84 @@ fn bindgen_test_layout_rte_fdir_conf() { 4usize, concat!("Alignment of ", stringify!(rte_fdir_conf)) ); - fn test_field_mode() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mode) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(mode) - ) - ); - } - test_field_mode(); - fn test_field_pballoc() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pballoc) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(pballoc) - ) - ); - } - test_field_pballoc(); - fn test_field_status() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).status) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(status) - ) - ); - } - test_field_status(); - fn test_field_drop_queue() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).drop_queue) as usize - ptr as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(drop_queue) - ) - ); - } - test_field_drop_queue(); - fn test_field_mask() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(mask) - ) - ); - } - test_field_mask(); - fn test_field_flex_conf() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).flex_conf) as usize - ptr as usize - }, - 84usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(flex_conf) - ) - ); - } - test_field_flex_conf(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mode) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_fdir_conf), + "::", + stringify!(mode) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).pballoc) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_fdir_conf), + "::", + stringify!(pballoc) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).status) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_fdir_conf), + "::", + stringify!(status) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).drop_queue) as usize - ptr as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(rte_fdir_conf), + "::", + stringify!(drop_queue) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_fdir_conf), + "::", + stringify!(mask) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).flex_conf) as usize - ptr as usize + }, + 84usize, + concat!( + "Offset of field: ", + stringify!(rte_fdir_conf), + "::", + stringify!(flex_conf) + ) + ); } impl Default for rte_fdir_conf { fn default() -> Self { @@ -2248,6 +1947,8 @@ pub struct rte_intr_conf { } #[test] fn bindgen_test_layout_rte_intr_conf() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -2258,40 +1959,32 @@ fn bindgen_test_layout_rte_intr_conf() { 2usize, concat!("Alignment of ", stringify!(rte_intr_conf)) ); - fn test_field_lsc() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).lsc) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_intr_conf), - "::", - stringify!(lsc) - ) - ); - } - test_field_lsc(); - fn test_field_rxq() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rxq) as usize - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(rte_intr_conf), - "::", - stringify!(rxq) - ) - ); - } - test_field_rxq(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).lsc) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_intr_conf), + "::", + stringify!(lsc) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).rxq) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(rte_intr_conf), + "::", + stringify!(rxq) + ) + ); } /// A structure used to configure an Ethernet port. /// Depending upon the RX multi-queue mode, extra advanced @@ -2340,6 +2033,8 @@ pub struct rte_eth_conf__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_eth_conf__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 2120usize, @@ -2350,84 +2045,58 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_1() { 8usize, concat!("Alignment of ", stringify!(rte_eth_conf__bindgen_ty_1)) ); - fn test_field_rss_conf() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_eth_conf__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rss_conf) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_1), - "::", - stringify!(rss_conf) - ) - ); - } - test_field_rss_conf(); - fn test_field_vmdq_dcb_conf() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_eth_conf__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).vmdq_dcb_conf) as usize - - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_1), - "::", - stringify!(vmdq_dcb_conf) - ) - ); - } - test_field_vmdq_dcb_conf(); - fn test_field_dcb_rx_conf() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_eth_conf__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dcb_rx_conf) as usize - ptr as usize - }, - 1064usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_1), - "::", - stringify!(dcb_rx_conf) - ) - ); - } - test_field_dcb_rx_conf(); - fn test_field_vmdq_rx_conf() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_eth_conf__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).vmdq_rx_conf) as usize - - ptr as usize - }, - 1080usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_1), - "::", - stringify!(vmdq_rx_conf) - ) - ); - } - test_field_vmdq_rx_conf(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).rss_conf) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf__bindgen_ty_1), + "::", + stringify!(rss_conf) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).vmdq_dcb_conf) as usize - ptr as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf__bindgen_ty_1), + "::", + stringify!(vmdq_dcb_conf) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).dcb_rx_conf) as usize - ptr as usize + }, + 1064usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf__bindgen_ty_1), + "::", + stringify!(dcb_rx_conf) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).vmdq_rx_conf) as usize - ptr as usize + }, + 1080usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf__bindgen_ty_1), + "::", + stringify!(vmdq_rx_conf) + ) + ); } impl Default for rte_eth_conf__bindgen_ty_1 { fn default() -> Self { @@ -2447,6 +2116,8 @@ pub union rte_eth_conf__bindgen_ty_2 { } #[test] fn bindgen_test_layout_rte_eth_conf__bindgen_ty_2() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 12usize, @@ -2457,65 +2128,46 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_2() { 4usize, concat!("Alignment of ", stringify!(rte_eth_conf__bindgen_ty_2)) ); - fn test_field_vmdq_dcb_tx_conf() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_eth_conf__bindgen_ty_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).vmdq_dcb_tx_conf) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_2), - "::", - stringify!(vmdq_dcb_tx_conf) - ) - ); - } - test_field_vmdq_dcb_tx_conf(); - fn test_field_dcb_tx_conf() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_eth_conf__bindgen_ty_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dcb_tx_conf) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_2), - "::", - stringify!(dcb_tx_conf) - ) - ); - } - test_field_dcb_tx_conf(); - fn test_field_vmdq_tx_conf() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_eth_conf__bindgen_ty_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).vmdq_tx_conf) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_2), - "::", - stringify!(vmdq_tx_conf) - ) - ); - } - test_field_vmdq_tx_conf(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).vmdq_dcb_tx_conf) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf__bindgen_ty_2), + "::", + stringify!(vmdq_dcb_tx_conf) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).dcb_tx_conf) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf__bindgen_ty_2), + "::", + stringify!(dcb_tx_conf) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).vmdq_tx_conf) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf__bindgen_ty_2), + "::", + stringify!(vmdq_tx_conf) + ) + ); } impl Default for rte_eth_conf__bindgen_ty_2 { fn default() -> Self { @@ -2528,6 +2180,8 @@ 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(); assert_eq!( ::std::mem::size_of::(), 2944usize, @@ -2538,160 +2192,124 @@ fn bindgen_test_layout_rte_eth_conf() { 8usize, concat!("Alignment of ", stringify!(rte_eth_conf)) ); - fn test_field_link_speeds() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).link_speeds) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(link_speeds) - ) - ); - } - test_field_link_speeds(); - fn test_field_rxmode() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rxmode) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(rxmode) - ) - ); - } - test_field_rxmode(); - fn test_field_txmode() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).txmode) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(txmode) - ) - ); - } - test_field_txmode(); - fn test_field_lpbk_mode() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).lpbk_mode) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(lpbk_mode) - ) - ); - } - test_field_lpbk_mode(); - fn test_field_rx_adv_conf() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rx_adv_conf) as usize - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(rx_adv_conf) - ) - ); - } - test_field_rx_adv_conf(); - fn test_field_tx_adv_conf() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).tx_adv_conf) as usize - ptr as usize - }, - 2152usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(tx_adv_conf) - ) - ); - } - test_field_tx_adv_conf(); - fn test_field_dcb_capability_en() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dcb_capability_en) as usize - - ptr as usize - }, - 2164usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(dcb_capability_en) - ) - ); - } - test_field_dcb_capability_en(); - fn test_field_fdir_conf() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).fdir_conf) as usize - ptr as usize - }, - 2168usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(fdir_conf) - ) - ); - } - test_field_fdir_conf(); - fn test_field_intr_conf() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).intr_conf) as usize - ptr as usize - }, - 2940usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(intr_conf) - ) - ); - } - test_field_intr_conf(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).link_speeds) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(link_speeds) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).rxmode) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(rxmode) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).txmode) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(txmode) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).lpbk_mode) as usize - ptr as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(lpbk_mode) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).rx_adv_conf) as usize - ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(rx_adv_conf) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).tx_adv_conf) as usize - ptr as usize + }, + 2152usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(tx_adv_conf) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).dcb_capability_en) as usize - + ptr as usize + }, + 2164usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(dcb_capability_en) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).fdir_conf) as usize - ptr as usize + }, + 2168usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(fdir_conf) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).intr_conf) as usize - ptr as usize + }, + 2940usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(intr_conf) + ) + ); } impl Default for rte_eth_conf { fn default() -> Self { diff --git a/tests/expectations/tests/layout_eth_conf_1_0.rs b/tests/expectations/tests/layout_eth_conf_1_0.rs index 0458a3ab7c..fcec665f31 100644 --- a/tests/expectations/tests/layout_eth_conf_1_0.rs +++ b/tests/expectations/tests/layout_eth_conf_1_0.rs @@ -203,6 +203,8 @@ pub struct rte_eth_rxmode { } #[test] fn bindgen_test_layout_rte_eth_rxmode() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 12usize, @@ -213,62 +215,45 @@ fn bindgen_test_layout_rte_eth_rxmode() { 4usize, concat!("Alignment of ", stringify!(rte_eth_rxmode)) ); - fn test_field_mq_mode() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mq_mode) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rxmode), - "::", - stringify!(mq_mode) - ) - ); - } - test_field_mq_mode(); - fn test_field_max_rx_pkt_len() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).max_rx_pkt_len) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rxmode), - "::", - stringify!(max_rx_pkt_len) - ) - ); - } - test_field_max_rx_pkt_len(); - fn test_field_split_hdr_size() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).split_hdr_size) as usize - - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rxmode), - "::", - stringify!(split_hdr_size) - ) - ); - } - test_field_split_hdr_size(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mq_mode) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_rxmode), + "::", + stringify!(mq_mode) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).max_rx_pkt_len) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_rxmode), + "::", + stringify!(max_rx_pkt_len) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).split_hdr_size) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_rxmode), + "::", + stringify!(split_hdr_size) + ) + ); } impl Clone for rte_eth_rxmode { fn clone(&self) -> Self { @@ -490,6 +475,8 @@ pub struct rte_eth_txmode { } #[test] fn bindgen_test_layout_rte_eth_txmode() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -500,42 +487,32 @@ fn bindgen_test_layout_rte_eth_txmode() { 4usize, concat!("Alignment of ", stringify!(rte_eth_txmode)) ); - fn test_field_mq_mode() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mq_mode) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_txmode), - "::", - stringify!(mq_mode) - ) - ); - } - test_field_mq_mode(); - fn test_field_pvid() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pvid) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_txmode), - "::", - stringify!(pvid) - ) - ); - } - test_field_pvid(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mq_mode) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_txmode), + "::", + stringify!(mq_mode) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).pvid) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_txmode), + "::", + stringify!(pvid) + ) + ); } impl Clone for rte_eth_txmode { fn clone(&self) -> Self { @@ -644,6 +621,8 @@ pub struct rte_eth_rss_conf { } #[test] fn bindgen_test_layout_rte_eth_rss_conf() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 24usize, @@ -654,60 +633,45 @@ fn bindgen_test_layout_rte_eth_rss_conf() { 8usize, concat!("Alignment of ", stringify!(rte_eth_rss_conf)) ); - fn test_field_rss_key() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rss_key) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rss_conf), - "::", - stringify!(rss_key) - ) - ); - } - test_field_rss_key(); - fn test_field_rss_key_len() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rss_key_len) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rss_conf), - "::", - stringify!(rss_key_len) - ) - ); - } - test_field_rss_key_len(); - fn test_field_rss_hf() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rss_hf) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rss_conf), - "::", - stringify!(rss_hf) - ) - ); - } - test_field_rss_hf(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).rss_key) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_rss_conf), + "::", + stringify!(rss_key) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).rss_key_len) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_rss_conf), + "::", + stringify!(rss_key_len) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).rss_hf) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_rss_conf), + "::", + stringify!(rss_hf) + ) + ); } impl Clone for rte_eth_rss_conf { fn clone(&self) -> Self { @@ -781,6 +745,8 @@ pub struct rte_eth_vmdq_dcb_conf__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_eth_vmdq_dcb_conf__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -794,44 +760,32 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf__bindgen_ty_1() { stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1) ) ); - fn test_field_vlan_id() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_eth_vmdq_dcb_conf__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).vlan_id) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1), - "::", - stringify!(vlan_id) - ) - ); - } - test_field_vlan_id(); - fn test_field_pools() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_eth_vmdq_dcb_conf__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pools) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1), - "::", - stringify!(pools) - ) - ); - } - test_field_pools(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).vlan_id) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1), + "::", + stringify!(vlan_id) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).pools) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1), + "::", + stringify!(pools) + ) + ); } impl Clone for rte_eth_vmdq_dcb_conf__bindgen_ty_1 { fn clone(&self) -> Self { @@ -840,6 +794,8 @@ impl Clone for rte_eth_vmdq_dcb_conf__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 1040usize, @@ -850,118 +806,85 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { 8usize, concat!("Alignment of ", stringify!(rte_eth_vmdq_dcb_conf)) ); - fn test_field_nb_queue_pools() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(nb_queue_pools) - ) - ); - } - test_field_nb_queue_pools(); - fn test_field_enable_default_pool() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).enable_default_pool) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(enable_default_pool) - ) - ); - } - test_field_enable_default_pool(); - fn test_field_default_pool() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).default_pool) as usize - - ptr as usize - }, - 5usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(default_pool) - ) - ); - } - test_field_default_pool(); - fn test_field_nb_pool_maps() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_pool_maps) as usize - - ptr as usize - }, - 6usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(nb_pool_maps) - ) - ); - } - test_field_nb_pool_maps(); - fn test_field_pool_map() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pool_map) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(pool_map) - ) - ); - } - test_field_pool_map(); - fn test_field_dcb_tc() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize - }, - 1032usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(dcb_tc) - ) - ); - } - test_field_dcb_tc(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf), + "::", + stringify!(nb_queue_pools) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).enable_default_pool) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf), + "::", + stringify!(enable_default_pool) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).default_pool) as usize - ptr as usize + }, + 5usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf), + "::", + stringify!(default_pool) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_pool_maps) as usize - ptr as usize + }, + 6usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf), + "::", + stringify!(nb_pool_maps) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).pool_map) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf), + "::", + stringify!(pool_map) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize + }, + 1032usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf), + "::", + stringify!(dcb_tc) + ) + ); } impl Clone for rte_eth_vmdq_dcb_conf { fn clone(&self) -> Self { @@ -987,6 +910,8 @@ pub struct rte_eth_dcb_rx_conf { } #[test] fn bindgen_test_layout_rte_eth_dcb_rx_conf() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 12usize, @@ -997,42 +922,32 @@ fn bindgen_test_layout_rte_eth_dcb_rx_conf() { 4usize, concat!("Alignment of ", stringify!(rte_eth_dcb_rx_conf)) ); - fn test_field_nb_tcs() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_dcb_rx_conf), - "::", - stringify!(nb_tcs) - ) - ); - } - test_field_nb_tcs(); - fn test_field_dcb_tc() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_dcb_rx_conf), - "::", - stringify!(dcb_tc) - ) - ); - } - test_field_dcb_tc(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_dcb_rx_conf), + "::", + stringify!(nb_tcs) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_dcb_rx_conf), + "::", + stringify!(dcb_tc) + ) + ); } impl Clone for rte_eth_dcb_rx_conf { fn clone(&self) -> Self { @@ -1058,6 +973,8 @@ pub struct rte_eth_vmdq_dcb_tx_conf { } #[test] fn bindgen_test_layout_rte_eth_vmdq_dcb_tx_conf() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 12usize, @@ -1068,45 +985,32 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_tx_conf() { 4usize, concat!("Alignment of ", stringify!(rte_eth_vmdq_dcb_tx_conf)) ); - fn test_field_nb_queue_pools() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_tx_conf), - "::", - stringify!(nb_queue_pools) - ) - ); - } - test_field_nb_queue_pools(); - fn test_field_dcb_tc() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_tx_conf), - "::", - stringify!(dcb_tc) - ) - ); - } - test_field_dcb_tc(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_tx_conf), + "::", + stringify!(nb_queue_pools) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_tx_conf), + "::", + stringify!(dcb_tc) + ) + ); } impl Clone for rte_eth_vmdq_dcb_tx_conf { fn clone(&self) -> Self { @@ -1132,6 +1036,8 @@ pub struct rte_eth_dcb_tx_conf { } #[test] fn bindgen_test_layout_rte_eth_dcb_tx_conf() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 12usize, @@ -1142,42 +1048,32 @@ fn bindgen_test_layout_rte_eth_dcb_tx_conf() { 4usize, concat!("Alignment of ", stringify!(rte_eth_dcb_tx_conf)) ); - fn test_field_nb_tcs() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_dcb_tx_conf), - "::", - stringify!(nb_tcs) - ) - ); - } - test_field_nb_tcs(); - fn test_field_dcb_tc() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_dcb_tx_conf), - "::", - stringify!(dcb_tc) - ) - ); - } - test_field_dcb_tc(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_dcb_tx_conf), + "::", + stringify!(nb_tcs) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_dcb_tx_conf), + "::", + stringify!(dcb_tc) + ) + ); } impl Clone for rte_eth_dcb_tx_conf { fn clone(&self) -> Self { @@ -1201,6 +1097,8 @@ pub struct rte_eth_vmdq_tx_conf { } #[test] fn bindgen_test_layout_rte_eth_vmdq_tx_conf() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -1211,25 +1109,19 @@ fn bindgen_test_layout_rte_eth_vmdq_tx_conf() { 4usize, concat!("Alignment of ", stringify!(rte_eth_vmdq_tx_conf)) ); - fn test_field_nb_queue_pools() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_tx_conf), - "::", - stringify!(nb_queue_pools) - ) - ); - } - test_field_nb_queue_pools(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_tx_conf), + "::", + stringify!(nb_queue_pools) + ) + ); } impl Clone for rte_eth_vmdq_tx_conf { fn clone(&self) -> Self { @@ -1273,6 +1165,8 @@ pub struct rte_eth_vmdq_rx_conf__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_eth_vmdq_rx_conf__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -1286,44 +1180,32 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf__bindgen_ty_1() { stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1) ) ); - fn test_field_vlan_id() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_eth_vmdq_rx_conf__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).vlan_id) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1), - "::", - stringify!(vlan_id) - ) - ); - } - test_field_vlan_id(); - fn test_field_pools() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_eth_vmdq_rx_conf__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pools) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1), - "::", - stringify!(pools) - ) - ); - } - test_field_pools(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).vlan_id) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1), + "::", + stringify!(vlan_id) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).pools) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1), + "::", + stringify!(pools) + ) + ); } impl Clone for rte_eth_vmdq_rx_conf__bindgen_ty_1 { fn clone(&self) -> Self { @@ -1332,6 +1214,8 @@ impl Clone for rte_eth_vmdq_rx_conf__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 1040usize, @@ -1342,137 +1226,99 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { 8usize, concat!("Alignment of ", stringify!(rte_eth_vmdq_rx_conf)) ); - fn test_field_nb_queue_pools() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(nb_queue_pools) - ) - ); - } - test_field_nb_queue_pools(); - fn test_field_enable_default_pool() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).enable_default_pool) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(enable_default_pool) - ) - ); - } - test_field_enable_default_pool(); - fn test_field_default_pool() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).default_pool) as usize - - ptr as usize - }, - 5usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(default_pool) - ) - ); - } - test_field_default_pool(); - fn test_field_enable_loop_back() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).enable_loop_back) as usize - - ptr as usize - }, - 6usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(enable_loop_back) - ) - ); - } - test_field_enable_loop_back(); - fn test_field_nb_pool_maps() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_pool_maps) as usize - - ptr as usize - }, - 7usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(nb_pool_maps) - ) - ); - } - test_field_nb_pool_maps(); - fn test_field_rx_mode() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rx_mode) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(rx_mode) - ) - ); - } - test_field_rx_mode(); - fn test_field_pool_map() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pool_map) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(pool_map) - ) - ); - } - test_field_pool_map(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf), + "::", + stringify!(nb_queue_pools) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).enable_default_pool) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf), + "::", + stringify!(enable_default_pool) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).default_pool) as usize - ptr as usize + }, + 5usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf), + "::", + stringify!(default_pool) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).enable_loop_back) as usize - + ptr as usize + }, + 6usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf), + "::", + stringify!(enable_loop_back) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_pool_maps) as usize - ptr as usize + }, + 7usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf), + "::", + stringify!(nb_pool_maps) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).rx_mode) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf), + "::", + stringify!(rx_mode) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).pool_map) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf), + "::", + stringify!(pool_map) + ) + ); } impl Clone for rte_eth_vmdq_rx_conf { fn clone(&self) -> Self { @@ -1543,6 +1389,8 @@ pub struct rte_eth_ipv4_flow { } #[test] fn bindgen_test_layout_rte_eth_ipv4_flow() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 12usize, @@ -1553,103 +1401,78 @@ fn bindgen_test_layout_rte_eth_ipv4_flow() { 4usize, concat!("Alignment of ", stringify!(rte_eth_ipv4_flow)) ); - fn test_field_src_ip() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(src_ip) - ) - ); - } - test_field_src_ip(); - fn test_field_dst_ip() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dst_ip) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(dst_ip) - ) - ); - } - test_field_dst_ip(); - fn test_field_tos() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).tos) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(tos) - ) - ); - } - test_field_tos(); - fn test_field_ttl() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ttl) as usize - ptr as usize - }, - 9usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(ttl) - ) - ); - } - test_field_ttl(); - fn test_field_proto() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize - }, - 10usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(proto) - ) - ); - } - test_field_proto(); -} -impl Clone for rte_eth_ipv4_flow { - fn clone(&self) -> Self { - *self - } -} -/// A structure used to define the input for IPV6 flow + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv4_flow), + "::", + stringify!(src_ip) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).dst_ip) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv4_flow), + "::", + stringify!(dst_ip) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).tos) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv4_flow), + "::", + stringify!(tos) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).ttl) as usize - ptr as usize + }, + 9usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv4_flow), + "::", + stringify!(ttl) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize + }, + 10usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv4_flow), + "::", + stringify!(proto) + ) + ); +} +impl Clone for rte_eth_ipv4_flow { + fn clone(&self) -> Self { + *self + } +} +/// A structure used to define the input for IPV6 flow #[repr(C)] #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct rte_eth_ipv6_flow { @@ -1666,6 +1489,8 @@ pub struct rte_eth_ipv6_flow { } #[test] fn bindgen_test_layout_rte_eth_ipv6_flow() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 36usize, @@ -1676,96 +1501,71 @@ fn bindgen_test_layout_rte_eth_ipv6_flow() { 4usize, concat!("Alignment of ", stringify!(rte_eth_ipv6_flow)) ); - fn test_field_src_ip() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(src_ip) - ) - ); - } - test_field_src_ip(); - fn test_field_dst_ip() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dst_ip) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(dst_ip) - ) - ); - } - test_field_dst_ip(); - fn test_field_tc() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).tc) as usize - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(tc) - ) - ); - } - test_field_tc(); - fn test_field_proto() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize - }, - 33usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(proto) - ) - ); - } - test_field_proto(); - fn test_field_hop_limits() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).hop_limits) as usize - ptr as usize - }, - 34usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(hop_limits) - ) - ); - } - test_field_hop_limits(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv6_flow), + "::", + stringify!(src_ip) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).dst_ip) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv6_flow), + "::", + stringify!(dst_ip) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).tc) as usize - ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv6_flow), + "::", + stringify!(tc) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize + }, + 33usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv6_flow), + "::", + stringify!(proto) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).hop_limits) as usize - ptr as usize + }, + 34usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv6_flow), + "::", + stringify!(hop_limits) + ) + ); } impl Clone for rte_eth_ipv6_flow { fn clone(&self) -> Self { @@ -1798,6 +1598,8 @@ pub struct rte_eth_fdir_masks { } #[test] fn bindgen_test_layout_rte_eth_fdir_masks() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 68usize, @@ -1808,156 +1610,112 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { 4usize, concat!("Alignment of ", stringify!(rte_eth_fdir_masks)) ); - fn test_field_vlan_tci_mask() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).vlan_tci_mask) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(vlan_tci_mask) - ) - ); - } - test_field_vlan_tci_mask(); - fn test_field_ipv4_mask() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ipv4_mask) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(ipv4_mask) - ) - ); - } - test_field_ipv4_mask(); - fn test_field_ipv6_mask() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ipv6_mask) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(ipv6_mask) - ) - ); - } - test_field_ipv6_mask(); - fn test_field_src_port_mask() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).src_port_mask) as usize - - ptr as usize - }, - 52usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(src_port_mask) - ) - ); - } - test_field_src_port_mask(); - fn test_field_dst_port_mask() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dst_port_mask) as usize - - ptr as usize - }, - 54usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(dst_port_mask) - ) - ); - } - test_field_dst_port_mask(); - fn test_field_mac_addr_byte_mask() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mac_addr_byte_mask) as usize - - ptr as usize - }, - 56usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(mac_addr_byte_mask) - ) - ); - } - test_field_mac_addr_byte_mask(); - fn test_field_tunnel_id_mask() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).tunnel_id_mask) as usize - - ptr as usize - }, - 60usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(tunnel_id_mask) - ) - ); - } - test_field_tunnel_id_mask(); - fn test_field_tunnel_type_mask() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).tunnel_type_mask) as usize - - ptr as usize - }, - 64usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(tunnel_type_mask) - ) - ); - } - test_field_tunnel_type_mask(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).vlan_tci_mask) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(vlan_tci_mask) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).ipv4_mask) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(ipv4_mask) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).ipv6_mask) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(ipv6_mask) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).src_port_mask) as usize - ptr as usize + }, + 52usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(src_port_mask) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).dst_port_mask) as usize - ptr as usize + }, + 54usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(dst_port_mask) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mac_addr_byte_mask) as usize - + ptr as usize + }, + 56usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(mac_addr_byte_mask) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).tunnel_id_mask) as usize - ptr as usize + }, + 60usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(tunnel_id_mask) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).tunnel_type_mask) as usize - + ptr as usize + }, + 64usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(tunnel_type_mask) + ) + ); } impl Clone for rte_eth_fdir_masks { fn clone(&self) -> Self { @@ -1986,6 +1744,8 @@ pub struct rte_eth_flex_payload_cfg { } #[test] fn bindgen_test_layout_rte_eth_flex_payload_cfg() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 36usize, @@ -1996,44 +1756,32 @@ fn bindgen_test_layout_rte_eth_flex_payload_cfg() { 4usize, concat!("Alignment of ", stringify!(rte_eth_flex_payload_cfg)) ); - fn test_field_type() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_flex_payload_cfg), - "::", - stringify!(type_) - ) - ); - } - test_field_type(); - fn test_field_src_offset() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).src_offset) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_flex_payload_cfg), - "::", - stringify!(src_offset) - ) - ); - } - test_field_src_offset(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_flex_payload_cfg), + "::", + stringify!(type_) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).src_offset) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_flex_payload_cfg), + "::", + stringify!(src_offset) + ) + ); } impl Clone for rte_eth_flex_payload_cfg { fn clone(&self) -> Self { @@ -2059,6 +1807,8 @@ pub struct rte_eth_fdir_flex_mask { } #[test] fn bindgen_test_layout_rte_eth_fdir_flex_mask() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 18usize, @@ -2069,42 +1819,32 @@ fn bindgen_test_layout_rte_eth_fdir_flex_mask() { 2usize, concat!("Alignment of ", stringify!(rte_eth_fdir_flex_mask)) ); - fn test_field_flow_type() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).flow_type) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_mask), - "::", - stringify!(flow_type) - ) - ); - } - test_field_flow_type(); - fn test_field_mask() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_mask), - "::", - stringify!(mask) - ) - ); - } - test_field_mask(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).flow_type) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_flex_mask), + "::", + stringify!(flow_type) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_flex_mask), + "::", + stringify!(mask) + ) + ); } impl Clone for rte_eth_fdir_flex_mask { fn clone(&self) -> Self { @@ -2125,6 +1865,8 @@ pub struct rte_eth_fdir_flex_conf { } #[test] fn bindgen_test_layout_rte_eth_fdir_flex_conf() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 688usize, @@ -2135,79 +1877,58 @@ fn bindgen_test_layout_rte_eth_fdir_flex_conf() { 4usize, concat!("Alignment of ", stringify!(rte_eth_fdir_flex_conf)) ); - fn test_field_nb_payloads() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_payloads) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_conf), - "::", - stringify!(nb_payloads) - ) - ); - } - test_field_nb_payloads(); - fn test_field_nb_flexmasks() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_flexmasks) as usize - - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_conf), - "::", - stringify!(nb_flexmasks) - ) - ); - } - test_field_nb_flexmasks(); - fn test_field_flex_set() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).flex_set) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_conf), - "::", - stringify!(flex_set) - ) - ); - } - test_field_flex_set(); - fn test_field_flex_mask() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).flex_mask) as usize - ptr as usize - }, - 292usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_conf), - "::", - stringify!(flex_mask) - ) - ); - } - test_field_flex_mask(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_payloads) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_flex_conf), + "::", + stringify!(nb_payloads) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_flexmasks) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_flex_conf), + "::", + stringify!(nb_flexmasks) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).flex_set) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_flex_conf), + "::", + stringify!(flex_set) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).flex_mask) as usize - ptr as usize + }, + 292usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_flex_conf), + "::", + stringify!(flex_mask) + ) + ); } impl Clone for rte_eth_fdir_flex_conf { fn clone(&self) -> Self { @@ -2243,6 +1964,8 @@ pub struct rte_fdir_conf { } #[test] fn bindgen_test_layout_rte_fdir_conf() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 772usize, @@ -2253,108 +1976,84 @@ fn bindgen_test_layout_rte_fdir_conf() { 4usize, concat!("Alignment of ", stringify!(rte_fdir_conf)) ); - fn test_field_mode() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mode) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(mode) - ) - ); - } - test_field_mode(); - fn test_field_pballoc() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pballoc) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(pballoc) - ) - ); - } - test_field_pballoc(); - fn test_field_status() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).status) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(status) - ) - ); - } - test_field_status(); - fn test_field_drop_queue() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).drop_queue) as usize - ptr as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(drop_queue) - ) - ); - } - test_field_drop_queue(); - fn test_field_mask() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(mask) - ) - ); - } - test_field_mask(); - fn test_field_flex_conf() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).flex_conf) as usize - ptr as usize - }, - 84usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(flex_conf) - ) - ); - } - test_field_flex_conf(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mode) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_fdir_conf), + "::", + stringify!(mode) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).pballoc) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_fdir_conf), + "::", + stringify!(pballoc) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).status) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_fdir_conf), + "::", + stringify!(status) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).drop_queue) as usize - ptr as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(rte_fdir_conf), + "::", + stringify!(drop_queue) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_fdir_conf), + "::", + stringify!(mask) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).flex_conf) as usize - ptr as usize + }, + 84usize, + concat!( + "Offset of field: ", + stringify!(rte_fdir_conf), + "::", + stringify!(flex_conf) + ) + ); } impl Clone for rte_fdir_conf { fn clone(&self) -> Self { @@ -2381,6 +2080,8 @@ pub struct rte_intr_conf { } #[test] fn bindgen_test_layout_rte_intr_conf() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -2391,40 +2092,32 @@ fn bindgen_test_layout_rte_intr_conf() { 2usize, concat!("Alignment of ", stringify!(rte_intr_conf)) ); - fn test_field_lsc() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).lsc) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_intr_conf), - "::", - stringify!(lsc) - ) - ); - } - test_field_lsc(); - fn test_field_rxq() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rxq) as usize - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(rte_intr_conf), - "::", - stringify!(rxq) - ) - ); - } - test_field_rxq(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).lsc) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_intr_conf), + "::", + stringify!(lsc) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).rxq) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(rte_intr_conf), + "::", + stringify!(rxq) + ) + ); } impl Clone for rte_intr_conf { fn clone(&self) -> Self { @@ -2478,6 +2171,8 @@ pub struct rte_eth_conf__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_eth_conf__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 2120usize, @@ -2488,84 +2183,58 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_1() { 8usize, concat!("Alignment of ", stringify!(rte_eth_conf__bindgen_ty_1)) ); - fn test_field_rss_conf() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_eth_conf__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rss_conf) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_1), - "::", - stringify!(rss_conf) - ) - ); - } - test_field_rss_conf(); - fn test_field_vmdq_dcb_conf() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_eth_conf__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).vmdq_dcb_conf) as usize - - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_1), - "::", - stringify!(vmdq_dcb_conf) - ) - ); - } - test_field_vmdq_dcb_conf(); - fn test_field_dcb_rx_conf() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_eth_conf__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dcb_rx_conf) as usize - ptr as usize - }, - 1064usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_1), - "::", - stringify!(dcb_rx_conf) - ) - ); - } - test_field_dcb_rx_conf(); - fn test_field_vmdq_rx_conf() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_eth_conf__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).vmdq_rx_conf) as usize - - ptr as usize - }, - 1080usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_1), - "::", - stringify!(vmdq_rx_conf) - ) - ); - } - test_field_vmdq_rx_conf(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).rss_conf) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf__bindgen_ty_1), + "::", + stringify!(rss_conf) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).vmdq_dcb_conf) as usize - ptr as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf__bindgen_ty_1), + "::", + stringify!(vmdq_dcb_conf) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).dcb_rx_conf) as usize - ptr as usize + }, + 1064usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf__bindgen_ty_1), + "::", + stringify!(dcb_rx_conf) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).vmdq_rx_conf) as usize - ptr as usize + }, + 1080usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf__bindgen_ty_1), + "::", + stringify!(vmdq_rx_conf) + ) + ); } impl Clone for rte_eth_conf__bindgen_ty_1 { fn clone(&self) -> Self { @@ -2591,6 +2260,8 @@ pub struct rte_eth_conf__bindgen_ty_2 { } #[test] fn bindgen_test_layout_rte_eth_conf__bindgen_ty_2() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 12usize, @@ -2601,65 +2272,46 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_2() { 4usize, concat!("Alignment of ", stringify!(rte_eth_conf__bindgen_ty_2)) ); - fn test_field_vmdq_dcb_tx_conf() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_eth_conf__bindgen_ty_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).vmdq_dcb_tx_conf) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_2), - "::", - stringify!(vmdq_dcb_tx_conf) - ) - ); - } - test_field_vmdq_dcb_tx_conf(); - fn test_field_dcb_tx_conf() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_eth_conf__bindgen_ty_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dcb_tx_conf) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_2), - "::", - stringify!(dcb_tx_conf) - ) - ); - } - test_field_dcb_tx_conf(); - fn test_field_vmdq_tx_conf() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_eth_conf__bindgen_ty_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).vmdq_tx_conf) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_2), - "::", - stringify!(vmdq_tx_conf) - ) - ); - } - test_field_vmdq_tx_conf(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).vmdq_dcb_tx_conf) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf__bindgen_ty_2), + "::", + stringify!(vmdq_dcb_tx_conf) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).dcb_tx_conf) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf__bindgen_ty_2), + "::", + stringify!(dcb_tx_conf) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).vmdq_tx_conf) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf__bindgen_ty_2), + "::", + stringify!(vmdq_tx_conf) + ) + ); } impl Clone for rte_eth_conf__bindgen_ty_2 { fn clone(&self) -> Self { @@ -2668,6 +2320,8 @@ impl Clone for rte_eth_conf__bindgen_ty_2 { } #[test] fn bindgen_test_layout_rte_eth_conf() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 2944usize, @@ -2678,160 +2332,124 @@ fn bindgen_test_layout_rte_eth_conf() { 8usize, concat!("Alignment of ", stringify!(rte_eth_conf)) ); - fn test_field_link_speeds() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).link_speeds) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(link_speeds) - ) - ); - } - test_field_link_speeds(); - fn test_field_rxmode() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rxmode) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(rxmode) - ) - ); - } - test_field_rxmode(); - fn test_field_txmode() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).txmode) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(txmode) - ) - ); - } - test_field_txmode(); - fn test_field_lpbk_mode() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).lpbk_mode) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(lpbk_mode) - ) - ); - } - test_field_lpbk_mode(); - fn test_field_rx_adv_conf() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rx_adv_conf) as usize - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(rx_adv_conf) - ) - ); - } - test_field_rx_adv_conf(); - fn test_field_tx_adv_conf() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).tx_adv_conf) as usize - ptr as usize - }, - 2152usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(tx_adv_conf) - ) - ); - } - test_field_tx_adv_conf(); - fn test_field_dcb_capability_en() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dcb_capability_en) as usize - - ptr as usize - }, - 2164usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(dcb_capability_en) - ) - ); - } - test_field_dcb_capability_en(); - fn test_field_fdir_conf() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).fdir_conf) as usize - ptr as usize - }, - 2168usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(fdir_conf) - ) - ); - } - test_field_fdir_conf(); - fn test_field_intr_conf() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).intr_conf) as usize - ptr as usize - }, - 2940usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(intr_conf) - ) - ); - } - test_field_intr_conf(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).link_speeds) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(link_speeds) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).rxmode) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(rxmode) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).txmode) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(txmode) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).lpbk_mode) as usize - ptr as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(lpbk_mode) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).rx_adv_conf) as usize - ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(rx_adv_conf) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).tx_adv_conf) as usize - ptr as usize + }, + 2152usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(tx_adv_conf) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).dcb_capability_en) as usize - + ptr as usize + }, + 2164usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(dcb_capability_en) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).fdir_conf) as usize - ptr as usize + }, + 2168usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(fdir_conf) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).intr_conf) as usize - ptr as usize + }, + 2940usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(intr_conf) + ) + ); } impl Clone for rte_eth_conf { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/layout_kni_mbuf.rs b/tests/expectations/tests/layout_kni_mbuf.rs index 4eaa707882..eb17fa63e2 100644 --- a/tests/expectations/tests/layout_kni_mbuf.rs +++ b/tests/expectations/tests/layout_kni_mbuf.rs @@ -34,6 +34,8 @@ pub struct rte_kni_mbuf { } #[test] fn bindgen_test_layout_rte_kni_mbuf() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 128usize, @@ -44,245 +46,188 @@ fn bindgen_test_layout_rte_kni_mbuf() { 64usize, concat!("Alignment of ", stringify!(rte_kni_mbuf)) ); - fn test_field_buf_addr() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).buf_addr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(buf_addr) - ) - ); - } - test_field_buf_addr(); - fn test_field_buf_physaddr() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).buf_physaddr) as usize - - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(buf_physaddr) - ) - ); - } - test_field_buf_physaddr(); - fn test_field_pad0() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pad0) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(pad0) - ) - ); - } - test_field_pad0(); - fn test_field_data_off() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).data_off) as usize - ptr as usize - }, - 18usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(data_off) - ) - ); - } - test_field_data_off(); - fn test_field_pad1() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pad1) as usize - ptr as usize - }, - 20usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(pad1) - ) - ); - } - test_field_pad1(); - fn test_field_nb_segs() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_segs) as usize - ptr as usize - }, - 22usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(nb_segs) - ) - ); - } - test_field_nb_segs(); - fn test_field_pad4() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pad4) as usize - ptr as usize - }, - 23usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(pad4) - ) - ); - } - test_field_pad4(); - fn test_field_ol_flags() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ol_flags) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(ol_flags) - ) - ); - } - test_field_ol_flags(); - fn test_field_pad2() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pad2) as usize - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(pad2) - ) - ); - } - test_field_pad2(); - fn test_field_pkt_len() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pkt_len) as usize - ptr as usize - }, - 36usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(pkt_len) - ) - ); - } - test_field_pkt_len(); - fn test_field_data_len() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).data_len) as usize - ptr as usize - }, - 40usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(data_len) - ) - ); - } - test_field_data_len(); - fn test_field_pad3() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pad3) as usize - ptr as usize - }, - 64usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(pad3) - ) - ); - } - test_field_pad3(); - fn test_field_pool() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pool) as usize - ptr as usize - }, - 72usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(pool) - ) - ); - } - test_field_pool(); - fn test_field_next() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize - }, - 80usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(next) - ) - ); - } - test_field_next(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).buf_addr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_mbuf), + "::", + stringify!(buf_addr) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).buf_physaddr) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_mbuf), + "::", + stringify!(buf_physaddr) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).pad0) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_mbuf), + "::", + stringify!(pad0) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).data_off) as usize - ptr as usize + }, + 18usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_mbuf), + "::", + stringify!(data_off) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).pad1) as usize - ptr as usize + }, + 20usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_mbuf), + "::", + stringify!(pad1) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_segs) as usize - ptr as usize + }, + 22usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_mbuf), + "::", + stringify!(nb_segs) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).pad4) as usize - ptr as usize + }, + 23usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_mbuf), + "::", + stringify!(pad4) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).ol_flags) as usize - ptr as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_mbuf), + "::", + stringify!(ol_flags) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).pad2) as usize - ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_mbuf), + "::", + stringify!(pad2) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).pkt_len) as usize - ptr as usize + }, + 36usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_mbuf), + "::", + stringify!(pkt_len) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).data_len) as usize - ptr as usize + }, + 40usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_mbuf), + "::", + stringify!(data_len) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).pad3) as usize - ptr as usize + }, + 64usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_mbuf), + "::", + stringify!(pad3) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).pool) as usize - ptr as usize + }, + 72usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_mbuf), + "::", + stringify!(pool) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize + }, + 80usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_mbuf), + "::", + stringify!(next) + ) + ); } impl Default for rte_kni_mbuf { fn default() -> Self { diff --git a/tests/expectations/tests/layout_large_align_field.rs b/tests/expectations/tests/layout_large_align_field.rs index daf3d56272..3f050269f6 100644 --- a/tests/expectations/tests/layout_large_align_field.rs +++ b/tests/expectations/tests/layout_large_align_field.rs @@ -65,6 +65,8 @@ pub struct ip_frag { } #[test] fn bindgen_test_layout_ip_frag() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -75,57 +77,45 @@ fn bindgen_test_layout_ip_frag() { 8usize, concat!("Alignment of ", stringify!(ip_frag)) ); - fn test_field_ofs() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ofs) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ip_frag), - "::", - stringify!(ofs) - ) - ); - } - test_field_ofs(); - fn test_field_len() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(ip_frag), - "::", - stringify!(len) - ) - ); - } - test_field_len(); - fn test_field_mb() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mb) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(ip_frag), - "::", - stringify!(mb) - ) - ); - } - test_field_mb(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).ofs) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ip_frag), + "::", + stringify!(ofs) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(ip_frag), + "::", + stringify!(len) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mb) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(ip_frag), + "::", + stringify!(mb) + ) + ); } impl Default for ip_frag { fn default() -> Self { @@ -149,6 +139,8 @@ pub struct ip_frag_key { } #[test] fn bindgen_test_layout_ip_frag_key() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 40usize, @@ -159,57 +151,45 @@ fn bindgen_test_layout_ip_frag_key() { 8usize, concat!("Alignment of ", stringify!(ip_frag_key)) ); - fn test_field_src_dst() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).src_dst) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_key), - "::", - stringify!(src_dst) - ) - ); - } - test_field_src_dst(); - fn test_field_id() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).id) as usize - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_key), - "::", - stringify!(id) - ) - ); - } - test_field_id(); - fn test_field_key_len() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).key_len) as usize - ptr as usize - }, - 36usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_key), - "::", - stringify!(key_len) - ) - ); - } - test_field_key_len(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).src_dst) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_key), + "::", + stringify!(src_dst) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).id) as usize - ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_key), + "::", + stringify!(id) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).key_len) as usize - ptr as usize + }, + 36usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_key), + "::", + stringify!(key_len) + ) + ); } /// @internal Fragmented packet to reassemble. /// First two entries in the frags[] array are for the last and first fragments. @@ -240,6 +220,8 @@ pub struct ip_frag_pkt__bindgen_ty_1 { } #[test] fn bindgen_test_layout_ip_frag_pkt__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -250,40 +232,32 @@ fn bindgen_test_layout_ip_frag_pkt__bindgen_ty_1() { 8usize, concat!("Alignment of ", stringify!(ip_frag_pkt__bindgen_ty_1)) ); - fn test_field_tqe_next() { - assert_eq!( - unsafe { - let uninit = :: std :: mem :: MaybeUninit :: < ip_frag_pkt__bindgen_ty_1 > :: uninit () ; - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).tqe_next) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt__bindgen_ty_1), - "::", - stringify!(tqe_next) - ) - ); - } - test_field_tqe_next(); - fn test_field_tqe_prev() { - assert_eq!( - unsafe { - let uninit = :: std :: mem :: MaybeUninit :: < ip_frag_pkt__bindgen_ty_1 > :: uninit () ; - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).tqe_prev) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt__bindgen_ty_1), - "::", - stringify!(tqe_prev) - ) - ); - } - test_field_tqe_prev(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).tqe_next) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_pkt__bindgen_ty_1), + "::", + stringify!(tqe_next) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).tqe_prev) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_pkt__bindgen_ty_1), + "::", + stringify!(tqe_prev) + ) + ); } impl Default for ip_frag_pkt__bindgen_ty_1 { fn default() -> Self { @@ -296,6 +270,8 @@ 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(); assert_eq!( ::std::mem::size_of::(), 192usize, @@ -306,125 +282,97 @@ fn bindgen_test_layout_ip_frag_pkt() { 64usize, concat!("Alignment of ", stringify!(ip_frag_pkt)) ); - fn test_field_lru() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).lru) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(lru) - ) - ); - } - test_field_lru(); - fn test_field_key() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).key) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(key) - ) - ); - } - test_field_key(); - fn test_field_start() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).start) as usize - ptr as usize - }, - 56usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(start) - ) - ); - } - test_field_start(); - fn test_field_total_size() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).total_size) as usize - ptr as usize - }, - 64usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(total_size) - ) - ); - } - test_field_total_size(); - fn test_field_frag_size() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).frag_size) as usize - ptr as usize - }, - 68usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(frag_size) - ) - ); - } - test_field_frag_size(); - fn test_field_last_idx() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).last_idx) as usize - ptr as usize - }, - 72usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(last_idx) - ) - ); - } - test_field_last_idx(); - fn test_field_frags() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).frags) as usize - ptr as usize - }, - 80usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(frags) - ) - ); - } - test_field_frags(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).lru) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_pkt), + "::", + stringify!(lru) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).key) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_pkt), + "::", + stringify!(key) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).start) as usize - ptr as usize + }, + 56usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_pkt), + "::", + stringify!(start) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).total_size) as usize - ptr as usize + }, + 64usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_pkt), + "::", + stringify!(total_size) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).frag_size) as usize - ptr as usize + }, + 68usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_pkt), + "::", + stringify!(frag_size) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).last_idx) as usize - ptr as usize + }, + 72usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_pkt), + "::", + stringify!(last_idx) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).frags) as usize - ptr as usize + }, + 80usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_pkt), + "::", + stringify!(frags) + ) + ); } impl Default for ip_frag_pkt { fn default() -> Self { @@ -443,6 +391,8 @@ pub struct ip_pkt_list { } #[test] fn bindgen_test_layout_ip_pkt_list() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -453,40 +403,32 @@ fn bindgen_test_layout_ip_pkt_list() { 8usize, concat!("Alignment of ", stringify!(ip_pkt_list)) ); - fn test_field_tqh_first() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).tqh_first) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ip_pkt_list), - "::", - stringify!(tqh_first) - ) - ); - } - test_field_tqh_first(); - fn test_field_tqh_last() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).tqh_last) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(ip_pkt_list), - "::", - stringify!(tqh_last) - ) - ); - } - test_field_tqh_last(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).tqh_first) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ip_pkt_list), + "::", + stringify!(tqh_first) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).tqh_last) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(ip_pkt_list), + "::", + stringify!(tqh_last) + ) + ); } impl Default for ip_pkt_list { fn default() -> Self { @@ -517,6 +459,8 @@ pub struct ip_frag_tbl_stat { } #[test] fn bindgen_test_layout_ip_frag_tbl_stat() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 64usize, @@ -527,115 +471,84 @@ fn bindgen_test_layout_ip_frag_tbl_stat() { 64usize, concat!("Alignment of ", stringify!(ip_frag_tbl_stat)) ); - fn test_field_find_num() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).find_num) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_tbl_stat), - "::", - stringify!(find_num) - ) - ); - } - test_field_find_num(); - fn test_field_add_num() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).add_num) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_tbl_stat), - "::", - stringify!(add_num) - ) - ); - } - test_field_add_num(); - fn test_field_del_num() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).del_num) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_tbl_stat), - "::", - stringify!(del_num) - ) - ); - } - test_field_del_num(); - fn test_field_reuse_num() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).reuse_num) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_tbl_stat), - "::", - stringify!(reuse_num) - ) - ); - } - test_field_reuse_num(); - fn test_field_fail_total() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).fail_total) as usize - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_tbl_stat), - "::", - stringify!(fail_total) - ) - ); - } - test_field_fail_total(); - fn test_field_fail_nospace() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).fail_nospace) as usize - - ptr as usize - }, - 40usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_tbl_stat), - "::", - stringify!(fail_nospace) - ) - ); - } - test_field_fail_nospace(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).find_num) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_tbl_stat), + "::", + stringify!(find_num) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).add_num) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_tbl_stat), + "::", + stringify!(add_num) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).del_num) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_tbl_stat), + "::", + stringify!(del_num) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).reuse_num) as usize - ptr as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_tbl_stat), + "::", + stringify!(reuse_num) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).fail_total) as usize - ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_tbl_stat), + "::", + stringify!(fail_total) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).fail_nospace) as usize - ptr as usize + }, + 40usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_tbl_stat), + "::", + stringify!(fail_nospace) + ) + ); } impl Default for ip_frag_tbl_stat { fn default() -> Self { @@ -676,6 +589,8 @@ pub struct rte_ip_frag_tbl { } #[test] fn bindgen_test_layout_rte_ip_frag_tbl() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 128usize, @@ -686,205 +601,149 @@ fn bindgen_test_layout_rte_ip_frag_tbl() { 64usize, concat!("Alignment of ", stringify!(rte_ip_frag_tbl)) ); - fn test_field_max_cycles() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).max_cycles) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(max_cycles) - ) - ); - } - test_field_max_cycles(); - fn test_field_entry_mask() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).entry_mask) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(entry_mask) - ) - ); - } - test_field_entry_mask(); - fn test_field_max_entries() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).max_entries) as usize - ptr as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(max_entries) - ) - ); - } - test_field_max_entries(); - fn test_field_use_entries() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).use_entries) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(use_entries) - ) - ); - } - test_field_use_entries(); - fn test_field_bucket_entries() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bucket_entries) as usize - - ptr as usize - }, - 20usize, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(bucket_entries) - ) - ); - } - test_field_bucket_entries(); - fn test_field_nb_entries() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_entries) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(nb_entries) - ) - ); - } - test_field_nb_entries(); - fn test_field_nb_buckets() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_buckets) as usize - ptr as usize - }, - 28usize, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(nb_buckets) - ) - ); - } - test_field_nb_buckets(); - fn test_field_last() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).last) as usize - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(last) - ) - ); - } - test_field_last(); - fn test_field_lru() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).lru) as usize - ptr as usize - }, - 40usize, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(lru) - ) - ); - } - test_field_lru(); - fn test_field_stat() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).stat) as usize - ptr as usize - }, - 64usize, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(stat) - ) - ); - } - test_field_stat(); - fn test_field_pkt() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pkt) as usize - ptr as usize - }, - 128usize, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(pkt) - ) - ); - } - test_field_pkt(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).max_cycles) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ip_frag_tbl), + "::", + stringify!(max_cycles) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).entry_mask) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_ip_frag_tbl), + "::", + stringify!(entry_mask) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).max_entries) as usize - ptr as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(rte_ip_frag_tbl), + "::", + stringify!(max_entries) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).use_entries) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_ip_frag_tbl), + "::", + stringify!(use_entries) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).bucket_entries) as usize - ptr as usize + }, + 20usize, + concat!( + "Offset of field: ", + stringify!(rte_ip_frag_tbl), + "::", + stringify!(bucket_entries) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_entries) as usize - ptr as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(rte_ip_frag_tbl), + "::", + stringify!(nb_entries) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_buckets) as usize - ptr as usize + }, + 28usize, + concat!( + "Offset of field: ", + stringify!(rte_ip_frag_tbl), + "::", + stringify!(nb_buckets) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).last) as usize - ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(rte_ip_frag_tbl), + "::", + stringify!(last) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).lru) as usize - ptr as usize + }, + 40usize, + concat!( + "Offset of field: ", + stringify!(rte_ip_frag_tbl), + "::", + stringify!(lru) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).stat) as usize - ptr as usize + }, + 64usize, + concat!( + "Offset of field: ", + stringify!(rte_ip_frag_tbl), + "::", + stringify!(stat) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).pkt) as usize - ptr as usize + }, + 128usize, + concat!( + "Offset of field: ", + stringify!(rte_ip_frag_tbl), + "::", + stringify!(pkt) + ) + ); } impl Default for rte_ip_frag_tbl { fn default() -> Self { diff --git a/tests/expectations/tests/layout_mbuf.rs b/tests/expectations/tests/layout_mbuf.rs index 549c5292a5..5a7d77b7ad 100644 --- a/tests/expectations/tests/layout_mbuf.rs +++ b/tests/expectations/tests/layout_mbuf.rs @@ -106,6 +106,8 @@ pub struct rte_atomic16_t { } #[test] fn bindgen_test_layout_rte_atomic16_t() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 2usize, @@ -116,24 +118,19 @@ fn bindgen_test_layout_rte_atomic16_t() { 2usize, concat!("Alignment of ", stringify!(rte_atomic16_t)) ); - fn test_field_cnt() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).cnt) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_atomic16_t), - "::", - stringify!(cnt) - ) - ); - } - test_field_cnt(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).cnt) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_atomic16_t), + "::", + stringify!(cnt) + ) + ); } /// The generic rte_mbuf, containing a packet mbuf. #[repr(C)] @@ -198,6 +195,8 @@ pub union rte_mbuf__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 2usize, @@ -208,43 +207,32 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_1() { 2usize, concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_1)) ); - fn test_field_refcnt_atomic() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).refcnt_atomic) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_1), - "::", - stringify!(refcnt_atomic) - ) - ); - } - test_field_refcnt_atomic(); - fn test_field_refcnt() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).refcnt) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_1), - "::", - stringify!(refcnt) - ) - ); - } - test_field_refcnt(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).refcnt_atomic) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_1), + "::", + stringify!(refcnt_atomic) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).refcnt) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_1), + "::", + stringify!(refcnt) + ) + ); } impl Default for rte_mbuf__bindgen_ty_1 { fn default() -> Self { @@ -428,6 +416,8 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_2() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -438,24 +428,19 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_2() { 4usize, concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_2)) ); - fn test_field_packet_type() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).packet_type) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_2), - "::", - stringify!(packet_type) - ) - ); - } - test_field_packet_type(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).packet_type) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_2), + "::", + stringify!(packet_type) + ) + ); } impl Default for rte_mbuf__bindgen_ty_2 { fn default() -> Self { @@ -500,19 +485,19 @@ pub struct rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 { #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1( ) { + const UNINIT: ::std::mem::MaybeUninit< + rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1, + > = ::std::mem::MaybeUninit::uninit(); assert_eq ! (:: std :: mem :: size_of :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > () , 4usize , concat ! ("Size of: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1))); assert_eq ! (:: std :: mem :: align_of :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > () , 2usize , concat ! ("Alignment of " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1))); - fn test_field_hash() { - assert_eq ! (unsafe { let uninit = :: std :: mem :: MaybeUninit :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > :: uninit () ; let ptr = uninit . as_ptr () ; :: std :: ptr :: addr_of ! ((* ptr) . hash) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (hash))); - } - test_field_hash(); - fn test_field_id() { - assert_eq ! (unsafe { let uninit = :: std :: mem :: MaybeUninit :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > :: uninit () ; let ptr = uninit . as_ptr () ; :: std :: ptr :: addr_of ! ((* ptr) . id) as usize - ptr as usize } , 2usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (id))); - } - test_field_id(); + assert_eq ! (unsafe { let ptr = UNINIT . as_ptr () ; :: std :: ptr :: addr_of ! ((* ptr) . hash) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (hash))); + assert_eq ! (unsafe { let ptr = UNINIT . as_ptr () ; :: std :: ptr :: addr_of ! ((* ptr) . id) as usize - ptr as usize } , 2usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (id))); } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit< + rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1, + > = ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::( ), @@ -532,25 +517,19 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1() { stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1) ) ); - fn test_field_lo() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).lo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(lo) - ) - ); - } - test_field_lo(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).lo) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(lo) + ) + ); } impl Default for rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 { fn default() -> Self { @@ -563,6 +542,9 @@ impl Default for rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit< + rte_mbuf__bindgen_ty_3__bindgen_ty_1, + > = ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -579,25 +561,19 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1() { stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1) ) ); - fn test_field_hi() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_mbuf__bindgen_ty_3__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).hi) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1), - "::", - stringify!(hi) - ) - ); - } - test_field_hi(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).hi) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1), + "::", + stringify!(hi) + ) + ); } impl Default for rte_mbuf__bindgen_ty_3__bindgen_ty_1 { fn default() -> Self { @@ -616,6 +592,9 @@ pub struct rte_mbuf__bindgen_ty_3__bindgen_ty_2 { } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_2() { + const UNINIT: ::std::mem::MaybeUninit< + rte_mbuf__bindgen_ty_3__bindgen_ty_2, + > = ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -632,47 +611,37 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_2() { stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2) ) ); - fn test_field_lo() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_mbuf__bindgen_ty_3__bindgen_ty_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).lo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2), - "::", - stringify!(lo) - ) - ); - } - test_field_lo(); - fn test_field_hi() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_mbuf__bindgen_ty_3__bindgen_ty_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).hi) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2), - "::", - stringify!(hi) - ) - ); - } - test_field_hi(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).lo) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2), + "::", + stringify!(lo) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).hi) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2), + "::", + stringify!(hi) + ) + ); } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_3() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -683,78 +652,58 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3() { 4usize, concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_3)) ); - fn test_field_rss() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rss) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(rss) - ) - ); - } - test_field_rss(); - fn test_field_fdir() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).fdir) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(fdir) - ) - ); - } - test_field_fdir(); - fn test_field_sched() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).sched) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(sched) - ) - ); - } - test_field_sched(); - fn test_field_usr() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).usr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(usr) - ) - ); - } - test_field_usr(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).rss) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3), + "::", + stringify!(rss) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).fdir) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3), + "::", + stringify!(fdir) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).sched) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3), + "::", + stringify!(sched) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).usr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3), + "::", + stringify!(usr) + ) + ); } impl Default for rte_mbuf__bindgen_ty_3 { fn default() -> Self { @@ -775,6 +724,8 @@ pub union rte_mbuf__bindgen_ty_4 { } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_4() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -785,42 +736,32 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_4() { 8usize, concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_4)) ); - fn test_field_userdata() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).userdata) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_4), - "::", - stringify!(userdata) - ) - ); - } - test_field_userdata(); - fn test_field_udata64() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).udata64) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_4), - "::", - stringify!(udata64) - ) - ); - } - test_field_udata64(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).userdata) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_4), + "::", + stringify!(userdata) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).udata64) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_4), + "::", + stringify!(udata64) + ) + ); } impl Default for rte_mbuf__bindgen_ty_4 { fn default() -> Self { @@ -985,6 +926,8 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_5() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -995,24 +938,19 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_5() { 8usize, concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_5)) ); - fn test_field_tx_offload() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).tx_offload) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_5), - "::", - stringify!(tx_offload) - ) - ); - } - test_field_tx_offload(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).tx_offload) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_5), + "::", + stringify!(tx_offload) + ) + ); } impl Default for rte_mbuf__bindgen_ty_5 { fn default() -> Self { @@ -1025,6 +963,8 @@ impl Default for rte_mbuf__bindgen_ty_5 { } #[test] fn bindgen_test_layout_rte_mbuf() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 128usize, @@ -1035,366 +975,280 @@ fn bindgen_test_layout_rte_mbuf() { 64usize, concat!("Alignment of ", stringify!(rte_mbuf)) ); - fn test_field_cacheline0() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).cacheline0) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(cacheline0) - ) - ); - } - test_field_cacheline0(); - fn test_field_buf_addr() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).buf_addr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(buf_addr) - ) - ); - } - test_field_buf_addr(); - fn test_field_buf_physaddr() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).buf_physaddr) as usize - - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(buf_physaddr) - ) - ); - } - test_field_buf_physaddr(); - fn test_field_buf_len() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).buf_len) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(buf_len) - ) - ); - } - test_field_buf_len(); - fn test_field_rearm_data() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rearm_data) as usize - ptr as usize - }, - 18usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(rearm_data) - ) - ); - } - test_field_rearm_data(); - fn test_field_data_off() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).data_off) as usize - ptr as usize - }, - 18usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(data_off) - ) - ); - } - test_field_data_off(); - fn test_field_nb_segs() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_segs) as usize - ptr as usize - }, - 22usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(nb_segs) - ) - ); - } - test_field_nb_segs(); - fn test_field_port() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).port) as usize - ptr as usize - }, - 23usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(port) - ) - ); - } - test_field_port(); - fn test_field_ol_flags() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ol_flags) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(ol_flags) - ) - ); - } - test_field_ol_flags(); - fn test_field_rx_descriptor_fields1() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rx_descriptor_fields1) as usize - - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(rx_descriptor_fields1) - ) - ); - } - test_field_rx_descriptor_fields1(); - fn test_field_pkt_len() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pkt_len) as usize - ptr as usize - }, - 36usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(pkt_len) - ) - ); - } - test_field_pkt_len(); - fn test_field_data_len() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).data_len) as usize - ptr as usize - }, - 40usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(data_len) - ) - ); - } - test_field_data_len(); - fn test_field_vlan_tci() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).vlan_tci) as usize - ptr as usize - }, - 42usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(vlan_tci) - ) - ); - } - test_field_vlan_tci(); - fn test_field_hash() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).hash) as usize - ptr as usize - }, - 44usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(hash) - ) - ); - } - test_field_hash(); - fn test_field_seqn() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).seqn) as usize - ptr as usize - }, - 52usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(seqn) - ) - ); - } - test_field_seqn(); - fn test_field_vlan_tci_outer() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).vlan_tci_outer) as usize - - ptr as usize - }, - 56usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(vlan_tci_outer) - ) - ); - } - test_field_vlan_tci_outer(); - fn test_field_cacheline1() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).cacheline1) as usize - ptr as usize - }, - 64usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(cacheline1) - ) - ); - } - test_field_cacheline1(); - fn test_field_pool() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pool) as usize - ptr as usize - }, - 72usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(pool) - ) - ); - } - test_field_pool(); - fn test_field_next() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize - }, - 80usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(next) - ) - ); - } - test_field_next(); - fn test_field_priv_size() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).priv_size) as usize - ptr as usize - }, - 96usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(priv_size) - ) - ); - } - test_field_priv_size(); - fn test_field_timesync() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).timesync) as usize - ptr as usize - }, - 98usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(timesync) - ) - ); - } - test_field_timesync(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).cacheline0) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(cacheline0) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).buf_addr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(buf_addr) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).buf_physaddr) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(buf_physaddr) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).buf_len) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(buf_len) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).rearm_data) as usize - ptr as usize + }, + 18usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(rearm_data) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).data_off) as usize - ptr as usize + }, + 18usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(data_off) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_segs) as usize - ptr as usize + }, + 22usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(nb_segs) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).port) as usize - ptr as usize + }, + 23usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(port) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).ol_flags) as usize - ptr as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(ol_flags) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).rx_descriptor_fields1) as usize - + ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(rx_descriptor_fields1) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).pkt_len) as usize - ptr as usize + }, + 36usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(pkt_len) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).data_len) as usize - ptr as usize + }, + 40usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(data_len) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).vlan_tci) as usize - ptr as usize + }, + 42usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(vlan_tci) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).hash) as usize - ptr as usize + }, + 44usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(hash) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).seqn) as usize - ptr as usize + }, + 52usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(seqn) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).vlan_tci_outer) as usize - ptr as usize + }, + 56usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(vlan_tci_outer) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).cacheline1) as usize - ptr as usize + }, + 64usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(cacheline1) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).pool) as usize - ptr as usize + }, + 72usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(pool) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize + }, + 80usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(next) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).priv_size) as usize - ptr as usize + }, + 96usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(priv_size) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).timesync) as usize - ptr as usize + }, + 98usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(timesync) + ) + ); } impl Default for rte_mbuf { fn default() -> Self { diff --git a/tests/expectations/tests/layout_mbuf_1_0.rs b/tests/expectations/tests/layout_mbuf_1_0.rs index b9fddeb3cb..353a576681 100644 --- a/tests/expectations/tests/layout_mbuf_1_0.rs +++ b/tests/expectations/tests/layout_mbuf_1_0.rs @@ -149,6 +149,8 @@ pub struct rte_atomic16_t { } #[test] fn bindgen_test_layout_rte_atomic16_t() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 2usize, @@ -159,24 +161,19 @@ fn bindgen_test_layout_rte_atomic16_t() { 2usize, concat!("Alignment of ", stringify!(rte_atomic16_t)) ); - fn test_field_cnt() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).cnt) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_atomic16_t), - "::", - stringify!(cnt) - ) - ); - } - test_field_cnt(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).cnt) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_atomic16_t), + "::", + stringify!(cnt) + ) + ); } impl Clone for rte_atomic16_t { fn clone(&self) -> Self { @@ -247,6 +244,8 @@ pub struct rte_mbuf__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 2usize, @@ -257,43 +256,32 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_1() { 2usize, concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_1)) ); - fn test_field_refcnt_atomic() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).refcnt_atomic) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_1), - "::", - stringify!(refcnt_atomic) - ) - ); - } - test_field_refcnt_atomic(); - fn test_field_refcnt() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).refcnt) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_1), - "::", - stringify!(refcnt) - ) - ); - } - test_field_refcnt(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).refcnt_atomic) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_1), + "::", + stringify!(refcnt_atomic) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).refcnt) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_1), + "::", + stringify!(refcnt) + ) + ); } impl Clone for rte_mbuf__bindgen_ty_1 { fn clone(&self) -> Self { @@ -480,6 +468,8 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_2() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -490,24 +480,19 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_2() { 4usize, concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_2)) ); - fn test_field_packet_type() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).packet_type) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_2), - "::", - stringify!(packet_type) - ) - ); - } - test_field_packet_type(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).packet_type) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_2), + "::", + stringify!(packet_type) + ) + ); } impl Clone for rte_mbuf__bindgen_ty_2 { fn clone(&self) -> Self { @@ -551,16 +536,13 @@ pub struct rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 { #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1( ) { + const UNINIT: ::std::mem::MaybeUninit< + rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1, + > = ::std::mem::MaybeUninit::uninit(); assert_eq ! (:: std :: mem :: size_of :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > () , 4usize , concat ! ("Size of: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1))); assert_eq ! (:: std :: mem :: align_of :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > () , 2usize , concat ! ("Alignment of " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1))); - fn test_field_hash() { - assert_eq ! (unsafe { let uninit = :: std :: mem :: MaybeUninit :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > :: uninit () ; let ptr = uninit . as_ptr () ; :: std :: ptr :: addr_of ! ((* ptr) . hash) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (hash))); - } - test_field_hash(); - fn test_field_id() { - assert_eq ! (unsafe { let uninit = :: std :: mem :: MaybeUninit :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > :: uninit () ; let ptr = uninit . as_ptr () ; :: std :: ptr :: addr_of ! ((* ptr) . id) as usize - ptr as usize } , 2usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (id))); - } - test_field_id(); + assert_eq ! (unsafe { let ptr = UNINIT . as_ptr () ; :: std :: ptr :: addr_of ! ((* ptr) . hash) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (hash))); + assert_eq ! (unsafe { let ptr = UNINIT . as_ptr () ; :: std :: ptr :: addr_of ! ((* ptr) . id) as usize - ptr as usize } , 2usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (id))); } impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 @@ -571,6 +553,9 @@ impl Clone } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit< + rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1, + > = ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::( ), @@ -590,25 +575,19 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1() { stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1) ) ); - fn test_field_lo() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).lo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(lo) - ) - ); - } - test_field_lo(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).lo) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(lo) + ) + ); } impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 { fn clone(&self) -> Self { @@ -617,6 +596,9 @@ impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit< + rte_mbuf__bindgen_ty_3__bindgen_ty_1, + > = ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -633,25 +615,19 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1() { stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1) ) ); - fn test_field_hi() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_mbuf__bindgen_ty_3__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).hi) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1), - "::", - stringify!(hi) - ) - ); - } - test_field_hi(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).hi) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1), + "::", + stringify!(hi) + ) + ); } impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_1 { fn clone(&self) -> Self { @@ -666,6 +642,9 @@ pub struct rte_mbuf__bindgen_ty_3__bindgen_ty_2 { } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_2() { + const UNINIT: ::std::mem::MaybeUninit< + rte_mbuf__bindgen_ty_3__bindgen_ty_2, + > = ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -682,44 +661,32 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_2() { stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2) ) ); - fn test_field_lo() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_mbuf__bindgen_ty_3__bindgen_ty_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).lo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2), - "::", - stringify!(lo) - ) - ); - } - test_field_lo(); - fn test_field_hi() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - rte_mbuf__bindgen_ty_3__bindgen_ty_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).hi) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2), - "::", - stringify!(hi) - ) - ); - } - test_field_hi(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).lo) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2), + "::", + stringify!(lo) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).hi) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2), + "::", + stringify!(hi) + ) + ); } impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_2 { fn clone(&self) -> Self { @@ -728,6 +695,8 @@ impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_2 { } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_3() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -738,78 +707,58 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3() { 4usize, concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_3)) ); - fn test_field_rss() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rss) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(rss) - ) - ); - } - test_field_rss(); - fn test_field_fdir() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).fdir) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(fdir) - ) - ); - } - test_field_fdir(); - fn test_field_sched() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).sched) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(sched) - ) - ); - } - test_field_sched(); - fn test_field_usr() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).usr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(usr) - ) - ); - } - test_field_usr(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).rss) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3), + "::", + stringify!(rss) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).fdir) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3), + "::", + stringify!(fdir) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).sched) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3), + "::", + stringify!(sched) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).usr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3), + "::", + stringify!(usr) + ) + ); } impl Clone for rte_mbuf__bindgen_ty_3 { fn clone(&self) -> Self { @@ -827,6 +776,8 @@ pub struct rte_mbuf__bindgen_ty_4 { } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_4() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -837,42 +788,32 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_4() { 8usize, concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_4)) ); - fn test_field_userdata() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).userdata) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_4), - "::", - stringify!(userdata) - ) - ); - } - test_field_userdata(); - fn test_field_udata64() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).udata64) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_4), - "::", - stringify!(udata64) - ) - ); - } - test_field_udata64(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).userdata) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_4), + "::", + stringify!(userdata) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).udata64) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_4), + "::", + stringify!(udata64) + ) + ); } impl Clone for rte_mbuf__bindgen_ty_4 { fn clone(&self) -> Self { @@ -1040,6 +981,8 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_5() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -1050,24 +993,19 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_5() { 8usize, concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_5)) ); - fn test_field_tx_offload() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).tx_offload) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_5), - "::", - stringify!(tx_offload) - ) - ); - } - test_field_tx_offload(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).tx_offload) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_5), + "::", + stringify!(tx_offload) + ) + ); } impl Clone for rte_mbuf__bindgen_ty_5 { fn clone(&self) -> Self { @@ -1076,371 +1014,287 @@ impl Clone for rte_mbuf__bindgen_ty_5 { } #[test] fn bindgen_test_layout_rte_mbuf() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 128usize, concat!("Size of: ", stringify!(rte_mbuf)) ); - fn test_field_cacheline0() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).cacheline0) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(cacheline0) - ) - ); - } - test_field_cacheline0(); - fn test_field_buf_addr() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).buf_addr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(buf_addr) - ) - ); - } - test_field_buf_addr(); - fn test_field_buf_physaddr() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).buf_physaddr) as usize - - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(buf_physaddr) - ) - ); - } - test_field_buf_physaddr(); - fn test_field_buf_len() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).buf_len) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(buf_len) - ) - ); - } - test_field_buf_len(); - fn test_field_rearm_data() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rearm_data) as usize - ptr as usize - }, - 18usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(rearm_data) - ) - ); - } - test_field_rearm_data(); - fn test_field_data_off() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).data_off) as usize - ptr as usize - }, - 18usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(data_off) - ) - ); - } - test_field_data_off(); - fn test_field_nb_segs() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_segs) as usize - ptr as usize - }, - 22usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(nb_segs) - ) - ); - } - test_field_nb_segs(); - fn test_field_port() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).port) as usize - ptr as usize - }, - 23usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(port) - ) - ); - } - test_field_port(); - fn test_field_ol_flags() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ol_flags) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(ol_flags) - ) - ); - } - test_field_ol_flags(); - fn test_field_rx_descriptor_fields1() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rx_descriptor_fields1) as usize - - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(rx_descriptor_fields1) - ) - ); - } - test_field_rx_descriptor_fields1(); - fn test_field_pkt_len() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pkt_len) as usize - ptr as usize - }, - 36usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(pkt_len) - ) - ); - } - test_field_pkt_len(); - fn test_field_data_len() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).data_len) as usize - ptr as usize - }, - 40usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(data_len) - ) - ); - } - test_field_data_len(); - fn test_field_vlan_tci() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).vlan_tci) as usize - ptr as usize - }, - 42usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(vlan_tci) - ) - ); - } - test_field_vlan_tci(); - fn test_field_hash() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).hash) as usize - ptr as usize - }, - 44usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(hash) - ) - ); - } - test_field_hash(); - fn test_field_seqn() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).seqn) as usize - ptr as usize - }, - 52usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(seqn) - ) - ); - } - test_field_seqn(); - fn test_field_vlan_tci_outer() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).vlan_tci_outer) as usize - - ptr as usize - }, - 56usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(vlan_tci_outer) - ) - ); - } - test_field_vlan_tci_outer(); - fn test_field_cacheline1() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).cacheline1) as usize - ptr as usize - }, - 64usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(cacheline1) - ) - ); - } - test_field_cacheline1(); - fn test_field_pool() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).pool) as usize - ptr as usize - }, - 72usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(pool) - ) - ); - } - test_field_pool(); - fn test_field_next() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize - }, - 80usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(next) - ) - ); - } - test_field_next(); - fn test_field_priv_size() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).priv_size) as usize - ptr as usize - }, - 96usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(priv_size) - ) - ); - } - test_field_priv_size(); - fn test_field_timesync() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).timesync) as usize - ptr as usize - }, - 98usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(timesync) - ) - ); - } - test_field_timesync(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).cacheline0) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(cacheline0) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).buf_addr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(buf_addr) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).buf_physaddr) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(buf_physaddr) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).buf_len) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(buf_len) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).rearm_data) as usize - ptr as usize + }, + 18usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(rearm_data) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).data_off) as usize - ptr as usize + }, + 18usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(data_off) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).nb_segs) as usize - ptr as usize + }, + 22usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(nb_segs) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).port) as usize - ptr as usize + }, + 23usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(port) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).ol_flags) as usize - ptr as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(ol_flags) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).rx_descriptor_fields1) as usize - + ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(rx_descriptor_fields1) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).pkt_len) as usize - ptr as usize + }, + 36usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(pkt_len) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).data_len) as usize - ptr as usize + }, + 40usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(data_len) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).vlan_tci) as usize - ptr as usize + }, + 42usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(vlan_tci) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).hash) as usize - ptr as usize + }, + 44usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(hash) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).seqn) as usize - ptr as usize + }, + 52usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(seqn) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).vlan_tci_outer) as usize - ptr as usize + }, + 56usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(vlan_tci_outer) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).cacheline1) as usize - ptr as usize + }, + 64usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(cacheline1) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).pool) as usize - ptr as usize + }, + 72usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(pool) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize + }, + 80usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(next) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).priv_size) as usize - ptr as usize + }, + 96usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(priv_size) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).timesync) as usize - ptr as usize + }, + 98usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(timesync) + ) + ); } impl Default for rte_mbuf { fn default() -> Self { diff --git a/tests/expectations/tests/libclang-9/call-conv-field.rs b/tests/expectations/tests/libclang-9/call-conv-field.rs index f83181ea0b..eb86ec2f43 100644 --- a/tests/expectations/tests/libclang-9/call-conv-field.rs +++ b/tests/expectations/tests/libclang-9/call-conv-field.rs @@ -18,6 +18,8 @@ pub struct JNINativeInterface_ { } #[test] fn bindgen_test_layout_JNINativeInterface_() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -28,42 +30,32 @@ fn bindgen_test_layout_JNINativeInterface_() { 8usize, concat!("Alignment of ", stringify!(JNINativeInterface_)) ); - fn test_field_GetVersion() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).GetVersion) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(JNINativeInterface_), - "::", - stringify!(GetVersion) - ) - ); - } - test_field_GetVersion(); - fn test_field___hack() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).__hack) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(JNINativeInterface_), - "::", - stringify!(__hack) - ) - ); - } - test_field___hack(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).GetVersion) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(JNINativeInterface_), + "::", + stringify!(GetVersion) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).__hack) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(JNINativeInterface_), + "::", + stringify!(__hack) + ) + ); } extern "stdcall" { pub fn bar(); diff --git a/tests/expectations/tests/libclang-9/class.rs b/tests/expectations/tests/libclang-9/class.rs index 82ab6806f2..81151d0f90 100644 --- a/tests/expectations/tests/libclang-9/class.rs +++ b/tests/expectations/tests/libclang-9/class.rs @@ -43,6 +43,8 @@ pub struct C { } #[test] fn bindgen_test_layout_C() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 40usize, @@ -53,35 +55,27 @@ fn bindgen_test_layout_C() { 4usize, concat!("Alignment of ", stringify!(C)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(a)) - ); - } - test_field_a(); - fn test_field_big_array() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(big_array) - ) - ); - } - test_field_big_array(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(a)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(big_array) + ) + ); } impl Default for C { fn default() -> Self { @@ -100,6 +94,8 @@ pub struct C_with_zero_length_array { } #[test] fn bindgen_test_layout_C_with_zero_length_array() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 40usize, @@ -110,64 +106,46 @@ fn bindgen_test_layout_C_with_zero_length_array() { 4usize, concat!("Alignment of ", stringify!(C_with_zero_length_array)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(a) - ) - ); - } - test_field_a(); - fn test_field_big_array() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(big_array) - ) - ); - } - test_field_big_array(); - fn test_field_zero_length_array() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize - }, - 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(zero_length_array) - ) - ); - } - test_field_zero_length_array(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array), + "::", + stringify!(big_array) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - + ptr as usize + }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array), + "::", + stringify!(zero_length_array) + ) + ); } impl Default for C_with_zero_length_array { fn default() -> Self { @@ -186,6 +164,8 @@ pub struct C_with_zero_length_array_2 { } #[test] fn bindgen_test_layout_C_with_zero_length_array_2() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -196,45 +176,33 @@ fn bindgen_test_layout_C_with_zero_length_array_2() { 4usize, concat!("Alignment of ", stringify!(C_with_zero_length_array_2)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C_with_zero_length_array_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_2), - "::", - stringify!(a) - ) - ); - } - test_field_a(); - fn test_field_zero_length_array() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C_with_zero_length_array_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_2), - "::", - stringify!(zero_length_array) - ) - ); - } - test_field_zero_length_array(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_2), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_2), + "::", + stringify!(zero_length_array) + ) + ); } #[repr(C)] pub struct C_with_incomplete_array { @@ -244,6 +212,8 @@ pub struct C_with_incomplete_array { } #[test] fn bindgen_test_layout_C_with_incomplete_array() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 40usize, @@ -254,64 +224,46 @@ fn bindgen_test_layout_C_with_incomplete_array() { 4usize, concat!("Alignment of ", stringify!(C_with_incomplete_array)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array), - "::", - stringify!(a) - ) - ); - } - test_field_a(); - fn test_field_big_array() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array), - "::", - stringify!(big_array) - ) - ); - } - test_field_big_array(); - fn test_field_incomplete_array() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - - ptr as usize - }, - 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array), - "::", - stringify!(incomplete_array) - ) - ); - } - test_field_incomplete_array(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array), + "::", + stringify!(big_array) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - + ptr as usize + }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array), + "::", + stringify!(incomplete_array) + ) + ); } impl Default for C_with_incomplete_array { fn default() -> Self { @@ -330,6 +282,8 @@ pub struct C_with_incomplete_array_2 { } #[test] fn bindgen_test_layout_C_with_incomplete_array_2() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -340,41 +294,33 @@ fn bindgen_test_layout_C_with_incomplete_array_2() { 4usize, concat!("Alignment of ", stringify!(C_with_incomplete_array_2)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = :: std :: mem :: MaybeUninit :: < C_with_incomplete_array_2 > :: uninit () ; - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array_2), - "::", - stringify!(a) - ) - ); - } - test_field_a(); - fn test_field_incomplete_array() { - assert_eq!( - unsafe { - let uninit = :: std :: mem :: MaybeUninit :: < C_with_incomplete_array_2 > :: uninit () ; - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array_2), - "::", - stringify!(incomplete_array) - ) - ); - } - test_field_incomplete_array(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array_2), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array_2), + "::", + stringify!(incomplete_array) + ) + ); } #[repr(C)] pub struct C_with_zero_length_array_and_incomplete_array { @@ -385,6 +331,9 @@ pub struct C_with_zero_length_array_and_incomplete_array { } #[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(); assert_eq!( ::std::mem::size_of::(), 40usize, @@ -401,84 +350,60 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { stringify!(C_with_zero_length_array_and_incomplete_array) ) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C_with_zero_length_array_and_incomplete_array, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(a) - ) - ); - } - test_field_a(); - fn test_field_big_array() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C_with_zero_length_array_and_incomplete_array, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(big_array) - ) - ); - } - test_field_big_array(); - fn test_field_zero_length_array() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C_with_zero_length_array_and_incomplete_array, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize - }, - 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(zero_length_array) - ) - ); - } - test_field_zero_length_array(); - fn test_field_incomplete_array() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C_with_zero_length_array_and_incomplete_array, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - - ptr as usize - }, - 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(incomplete_array) - ) - ); - } - test_field_incomplete_array(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(big_array) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - + ptr as usize + }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(zero_length_array) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - + ptr as usize + }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(incomplete_array) + ) + ); } impl Default for C_with_zero_length_array_and_incomplete_array { fn default() -> Self { @@ -498,6 +423,9 @@ pub struct C_with_zero_length_array_and_incomplete_array_2 { } #[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(); assert_eq!( ::std::mem::size_of::( ), @@ -516,65 +444,47 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { stringify!(C_with_zero_length_array_and_incomplete_array_2) ) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C_with_zero_length_array_and_incomplete_array_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), - "::", - stringify!(a) - ) - ); - } - test_field_a(); - fn test_field_zero_length_array() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C_with_zero_length_array_and_incomplete_array_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), - "::", - stringify!(zero_length_array) - ) - ); - } - test_field_zero_length_array(); - fn test_field_incomplete_array() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C_with_zero_length_array_and_incomplete_array_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), - "::", - stringify!(incomplete_array) - ) - ); - } - test_field_incomplete_array(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), + "::", + stringify!(zero_length_array) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), + "::", + stringify!(incomplete_array) + ) + ); } #[repr(C)] #[derive(Debug, Default, Hash, PartialOrd, Ord, PartialEq, Eq)] @@ -583,6 +493,8 @@ pub struct WithDtor { } #[test] fn bindgen_test_layout_WithDtor() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -593,23 +505,19 @@ fn bindgen_test_layout_WithDtor() { 4usize, concat!("Alignment of ", stringify!(WithDtor)) ); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithDtor), - "::", - stringify!(b) - ) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithDtor), + "::", + stringify!(b) + ) + ); } #[repr(C)] pub struct IncompleteArrayNonCopiable { @@ -618,6 +526,8 @@ pub struct IncompleteArrayNonCopiable { } #[test] fn bindgen_test_layout_IncompleteArrayNonCopiable() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -628,45 +538,33 @@ fn bindgen_test_layout_IncompleteArrayNonCopiable() { 8usize, concat!("Alignment of ", stringify!(IncompleteArrayNonCopiable)) ); - fn test_field_whatever() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - IncompleteArrayNonCopiable, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).whatever) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(IncompleteArrayNonCopiable), - "::", - stringify!(whatever) - ) - ); - } - test_field_whatever(); - fn test_field_incomplete_array() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - IncompleteArrayNonCopiable, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(IncompleteArrayNonCopiable), - "::", - stringify!(incomplete_array) - ) - ); - } - test_field_incomplete_array(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).whatever) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(IncompleteArrayNonCopiable), + "::", + stringify!(whatever) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - + ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(IncompleteArrayNonCopiable), + "::", + stringify!(incomplete_array) + ) + ); } impl Default for IncompleteArrayNonCopiable { fn default() -> Self { @@ -685,6 +583,8 @@ pub union Union { } #[test] fn bindgen_test_layout_Union() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -695,40 +595,22 @@ fn bindgen_test_layout_Union() { 4usize, concat!("Alignment of ", stringify!(Union)) ); - fn test_field_d() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Union), - "::", - stringify!(d) - ) - ); - } - test_field_d(); - fn test_field_i() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Union), - "::", - stringify!(i) - ) - ); - } - test_field_i(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Union), "::", stringify!(d)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Union), "::", stringify!(i)) + ); } impl Default for Union { fn default() -> Self { @@ -746,6 +628,8 @@ pub struct WithUnion { } #[test] fn bindgen_test_layout_WithUnion() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -756,23 +640,19 @@ fn bindgen_test_layout_WithUnion() { 4usize, concat!("Alignment of ", stringify!(WithUnion)) ); - fn test_field_data() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithUnion), - "::", - stringify!(data) - ) - ); - } - test_field_data(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithUnion), + "::", + stringify!(data) + ) + ); } impl Default for WithUnion { fn default() -> Self { diff --git a/tests/expectations/tests/libclang-9/class_1_0.rs b/tests/expectations/tests/libclang-9/class_1_0.rs index 604dde7b8e..31c33ccc82 100644 --- a/tests/expectations/tests/libclang-9/class_1_0.rs +++ b/tests/expectations/tests/libclang-9/class_1_0.rs @@ -86,6 +86,8 @@ pub struct C { } #[test] fn bindgen_test_layout_C() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 40usize, @@ -96,35 +98,27 @@ fn bindgen_test_layout_C() { 4usize, concat!("Alignment of ", stringify!(C)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(a)) - ); - } - test_field_a(); - fn test_field_big_array() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(big_array) - ) - ); - } - test_field_big_array(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(a)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(big_array) + ) + ); } impl Clone for C { fn clone(&self) -> Self { @@ -153,6 +147,8 @@ pub struct C_with_zero_length_array { } #[test] fn bindgen_test_layout_C_with_zero_length_array() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 40usize, @@ -163,64 +159,46 @@ fn bindgen_test_layout_C_with_zero_length_array() { 4usize, concat!("Alignment of ", stringify!(C_with_zero_length_array)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(a) - ) - ); - } - test_field_a(); - fn test_field_big_array() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(big_array) - ) - ); - } - test_field_big_array(); - fn test_field_zero_length_array() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize - }, - 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(zero_length_array) - ) - ); - } - test_field_zero_length_array(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array), + "::", + stringify!(big_array) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - + ptr as usize + }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array), + "::", + stringify!(zero_length_array) + ) + ); } impl Default for C_with_zero_length_array { fn default() -> Self { @@ -239,6 +217,8 @@ pub struct C_with_zero_length_array_2 { } #[test] fn bindgen_test_layout_C_with_zero_length_array_2() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -249,45 +229,33 @@ fn bindgen_test_layout_C_with_zero_length_array_2() { 4usize, concat!("Alignment of ", stringify!(C_with_zero_length_array_2)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C_with_zero_length_array_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_2), - "::", - stringify!(a) - ) - ); - } - test_field_a(); - fn test_field_zero_length_array() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C_with_zero_length_array_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_2), - "::", - stringify!(zero_length_array) - ) - ); - } - test_field_zero_length_array(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_2), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_2), + "::", + stringify!(zero_length_array) + ) + ); } #[repr(C)] pub struct C_with_incomplete_array { @@ -297,6 +265,8 @@ pub struct C_with_incomplete_array { } #[test] fn bindgen_test_layout_C_with_incomplete_array() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 40usize, @@ -307,64 +277,46 @@ fn bindgen_test_layout_C_with_incomplete_array() { 4usize, concat!("Alignment of ", stringify!(C_with_incomplete_array)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array), - "::", - stringify!(a) - ) - ); - } - test_field_a(); - fn test_field_big_array() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array), - "::", - stringify!(big_array) - ) - ); - } - test_field_big_array(); - fn test_field_incomplete_array() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - - ptr as usize - }, - 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array), - "::", - stringify!(incomplete_array) - ) - ); - } - test_field_incomplete_array(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array), + "::", + stringify!(big_array) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - + ptr as usize + }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array), + "::", + stringify!(incomplete_array) + ) + ); } impl Default for C_with_incomplete_array { fn default() -> Self { @@ -383,6 +335,8 @@ pub struct C_with_incomplete_array_2 { } #[test] fn bindgen_test_layout_C_with_incomplete_array_2() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -393,41 +347,33 @@ fn bindgen_test_layout_C_with_incomplete_array_2() { 4usize, concat!("Alignment of ", stringify!(C_with_incomplete_array_2)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = :: std :: mem :: MaybeUninit :: < C_with_incomplete_array_2 > :: uninit () ; - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array_2), - "::", - stringify!(a) - ) - ); - } - test_field_a(); - fn test_field_incomplete_array() { - assert_eq!( - unsafe { - let uninit = :: std :: mem :: MaybeUninit :: < C_with_incomplete_array_2 > :: uninit () ; - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array_2), - "::", - stringify!(incomplete_array) - ) - ); - } - test_field_incomplete_array(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array_2), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array_2), + "::", + stringify!(incomplete_array) + ) + ); } #[repr(C)] pub struct C_with_zero_length_array_and_incomplete_array { @@ -438,6 +384,9 @@ pub struct C_with_zero_length_array_and_incomplete_array { } #[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(); assert_eq!( ::std::mem::size_of::(), 40usize, @@ -454,84 +403,60 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { stringify!(C_with_zero_length_array_and_incomplete_array) ) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C_with_zero_length_array_and_incomplete_array, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(a) - ) - ); - } - test_field_a(); - fn test_field_big_array() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C_with_zero_length_array_and_incomplete_array, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(big_array) - ) - ); - } - test_field_big_array(); - fn test_field_zero_length_array() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C_with_zero_length_array_and_incomplete_array, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize - }, - 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(zero_length_array) - ) - ); - } - test_field_zero_length_array(); - fn test_field_incomplete_array() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C_with_zero_length_array_and_incomplete_array, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - - ptr as usize - }, - 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(incomplete_array) - ) - ); - } - test_field_incomplete_array(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(big_array) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - + ptr as usize + }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(zero_length_array) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - + ptr as usize + }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(incomplete_array) + ) + ); } impl Default for C_with_zero_length_array_and_incomplete_array { fn default() -> Self { @@ -551,6 +476,9 @@ pub struct C_with_zero_length_array_and_incomplete_array_2 { } #[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(); assert_eq!( ::std::mem::size_of::( ), @@ -569,65 +497,47 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { stringify!(C_with_zero_length_array_and_incomplete_array_2) ) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C_with_zero_length_array_and_incomplete_array_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), - "::", - stringify!(a) - ) - ); - } - test_field_a(); - fn test_field_zero_length_array() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C_with_zero_length_array_and_incomplete_array_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), - "::", - stringify!(zero_length_array) - ) - ); - } - test_field_zero_length_array(); - fn test_field_incomplete_array() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C_with_zero_length_array_and_incomplete_array_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), - "::", - stringify!(incomplete_array) - ) - ); - } - test_field_incomplete_array(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), + "::", + stringify!(zero_length_array) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), + "::", + stringify!(incomplete_array) + ) + ); } #[repr(C)] #[derive(Debug, Default, Hash, PartialEq, Eq)] @@ -636,6 +546,8 @@ pub struct WithDtor { } #[test] fn bindgen_test_layout_WithDtor() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -646,23 +558,19 @@ fn bindgen_test_layout_WithDtor() { 4usize, concat!("Alignment of ", stringify!(WithDtor)) ); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithDtor), - "::", - stringify!(b) - ) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithDtor), + "::", + stringify!(b) + ) + ); } #[repr(C)] pub struct IncompleteArrayNonCopiable { @@ -671,6 +579,8 @@ pub struct IncompleteArrayNonCopiable { } #[test] fn bindgen_test_layout_IncompleteArrayNonCopiable() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -681,45 +591,33 @@ fn bindgen_test_layout_IncompleteArrayNonCopiable() { 8usize, concat!("Alignment of ", stringify!(IncompleteArrayNonCopiable)) ); - fn test_field_whatever() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - IncompleteArrayNonCopiable, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).whatever) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(IncompleteArrayNonCopiable), - "::", - stringify!(whatever) - ) - ); - } - test_field_whatever(); - fn test_field_incomplete_array() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - IncompleteArrayNonCopiable, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(IncompleteArrayNonCopiable), - "::", - stringify!(incomplete_array) - ) - ); - } - test_field_incomplete_array(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).whatever) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(IncompleteArrayNonCopiable), + "::", + stringify!(whatever) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - + ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(IncompleteArrayNonCopiable), + "::", + stringify!(incomplete_array) + ) + ); } impl Default for IncompleteArrayNonCopiable { fn default() -> Self { @@ -739,6 +637,8 @@ pub struct Union { } #[test] fn bindgen_test_layout_Union() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -749,40 +649,22 @@ fn bindgen_test_layout_Union() { 4usize, concat!("Alignment of ", stringify!(Union)) ); - fn test_field_d() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Union), - "::", - stringify!(d) - ) - ); - } - test_field_d(); - fn test_field_i() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Union), - "::", - stringify!(i) - ) - ); - } - test_field_i(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Union), "::", stringify!(d)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Union), "::", stringify!(i)) + ); } impl Clone for Union { fn clone(&self) -> Self { @@ -796,6 +678,8 @@ pub struct WithUnion { } #[test] fn bindgen_test_layout_WithUnion() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -806,23 +690,19 @@ fn bindgen_test_layout_WithUnion() { 4usize, concat!("Alignment of ", stringify!(WithUnion)) ); - fn test_field_data() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithUnion), - "::", - stringify!(data) - ) - ); - } - test_field_data(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithUnion), + "::", + stringify!(data) + ) + ); } impl Clone for WithUnion { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs b/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs index 2365d9a3c2..0986449b7a 100644 --- a/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs +++ b/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs @@ -43,6 +43,8 @@ pub struct test { } #[test] fn bindgen_test_layout_test() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -53,36 +55,28 @@ fn bindgen_test_layout_test() { 4usize, concat!("Alignment of ", stringify!(test)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(test), "::", stringify!(a)) - ); - } - test_field_a(); - fn test_field_zero_length_array() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(test), - "::", - stringify!(zero_length_array) - ) - ); - } - test_field_zero_length_array(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(test), "::", stringify!(a)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(test), + "::", + stringify!(zero_length_array) + ) + ); } #[repr(C)] #[derive(Debug, Default)] @@ -92,6 +86,8 @@ pub struct test2 { } #[test] fn bindgen_test_layout_test2() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -102,41 +98,28 @@ fn bindgen_test_layout_test2() { 4usize, concat!("Alignment of ", stringify!(test2)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(test2), - "::", - stringify!(a) - ) - ); - } - test_field_a(); - fn test_field_incomplete_array() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(test2), - "::", - stringify!(incomplete_array) - ) - ); - } - test_field_incomplete_array(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(test2), "::", stringify!(a)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(test2), + "::", + stringify!(incomplete_array) + ) + ); } #[repr(C)] #[derive(Debug, Default)] @@ -147,6 +130,8 @@ pub struct test3 { } #[test] fn bindgen_test_layout_test3() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -157,57 +142,40 @@ fn bindgen_test_layout_test3() { 4usize, concat!("Alignment of ", stringify!(test3)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(test3), - "::", - stringify!(a) - ) - ); - } - test_field_a(); - fn test_field_zero_length_array() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(test3), - "::", - stringify!(zero_length_array) - ) - ); - } - test_field_zero_length_array(); - fn test_field_incomplete_array() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(test3), - "::", - stringify!(incomplete_array) - ) - ); - } - test_field_incomplete_array(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(test3), "::", stringify!(a)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(test3), + "::", + stringify!(zero_length_array) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(test3), + "::", + stringify!(incomplete_array) + ) + ); } diff --git a/tests/expectations/tests/libclang-9/incomplete-array-padding.rs b/tests/expectations/tests/libclang-9/incomplete-array-padding.rs index d796cc6031..5f33deeb8c 100644 --- a/tests/expectations/tests/libclang-9/incomplete-array-padding.rs +++ b/tests/expectations/tests/libclang-9/incomplete-array-padding.rs @@ -130,6 +130,8 @@ pub struct foo { } #[test] fn bindgen_test_layout_foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -140,18 +142,14 @@ fn bindgen_test_layout_foo() { 8usize, concat!("Alignment of ", stringify!(foo)) ); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 8usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 8usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) + ); } impl Default for foo { fn default() -> Self { diff --git a/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs b/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs index 53f125486f..aafd2d653f 100644 --- a/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs +++ b/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs @@ -50,6 +50,8 @@ pub struct rte_ring_prod { } #[test] fn bindgen_test_layout_rte_ring_prod() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -60,23 +62,19 @@ fn bindgen_test_layout_rte_ring_prod() { 4usize, concat!("Alignment of ", stringify!(rte_ring_prod)) ); - fn test_field_watermark() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).watermark) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ring_prod), - "::", - stringify!(watermark) - ) - ); - } - test_field_watermark(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).watermark) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ring_prod), + "::", + stringify!(watermark) + ) + ); } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -85,6 +83,8 @@ pub struct rte_ring_cons { } #[test] fn bindgen_test_layout_rte_ring_cons() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -95,26 +95,24 @@ fn bindgen_test_layout_rte_ring_cons() { 4usize, concat!("Alignment of ", stringify!(rte_ring_cons)) ); - fn test_field_sc_dequeue() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).sc_dequeue) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ring_cons), - "::", - stringify!(sc_dequeue) - ) - ); - } - test_field_sc_dequeue(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).sc_dequeue) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ring_cons), + "::", + stringify!(sc_dequeue) + ) + ); } #[test] fn bindgen_test_layout_rte_ring() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -125,74 +123,58 @@ fn bindgen_test_layout_rte_ring() { 8usize, concat!("Alignment of ", stringify!(rte_ring)) ); - fn test_field_memzone() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).memzone) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ring), - "::", - stringify!(memzone) - ) - ); - } - test_field_memzone(); - fn test_field_prod() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).prod) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_ring), - "::", - stringify!(prod) - ) - ); - } - test_field_prod(); - fn test_field_cons() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).cons) as usize - ptr as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(rte_ring), - "::", - stringify!(cons) - ) - ); - } - test_field_cons(); - fn test_field_ring() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ring) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_ring), - "::", - stringify!(ring) - ) - ); - } - test_field_ring(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).memzone) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ring), + "::", + stringify!(memzone) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).prod) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_ring), + "::", + stringify!(prod) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).cons) as usize - ptr as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(rte_ring), + "::", + stringify!(cons) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).ring) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_ring), + "::", + stringify!(ring) + ) + ); } impl Default for rte_ring { fn default() -> Self { diff --git a/tests/expectations/tests/libclang-9/layout_align.rs b/tests/expectations/tests/libclang-9/layout_align.rs index 2ecbb6f9b0..1828c17635 100644 --- a/tests/expectations/tests/libclang-9/layout_align.rs +++ b/tests/expectations/tests/libclang-9/layout_align.rs @@ -137,6 +137,8 @@ pub struct rte_kni_fifo { } #[test] fn bindgen_test_layout_rte_kni_fifo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -147,91 +149,71 @@ fn bindgen_test_layout_rte_kni_fifo() { 8usize, concat!("Alignment of ", stringify!(rte_kni_fifo)) ); - fn test_field_write() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).write) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_fifo), - "::", - stringify!(write) - ) - ); - } - test_field_write(); - fn test_field_read() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).read) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_fifo), - "::", - stringify!(read) - ) - ); - } - test_field_read(); - fn test_field_len() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_fifo), - "::", - stringify!(len) - ) - ); - } - test_field_len(); - fn test_field_elem_size() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).elem_size) as usize - ptr as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_fifo), - "::", - stringify!(elem_size) - ) - ); - } - test_field_elem_size(); - fn test_field_buffer() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).buffer) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_fifo), - "::", - stringify!(buffer) - ) - ); - } - test_field_buffer(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).write) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_fifo), + "::", + stringify!(write) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).read) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_fifo), + "::", + stringify!(read) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_fifo), + "::", + stringify!(len) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).elem_size) as usize - ptr as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_fifo), + "::", + stringify!(elem_size) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).buffer) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_fifo), + "::", + stringify!(buffer) + ) + ); } impl Default for rte_kni_fifo { fn default() -> Self { @@ -254,6 +236,8 @@ pub struct rte_eth_link { } #[test] fn bindgen_test_layout_rte_eth_link() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -264,23 +248,19 @@ fn bindgen_test_layout_rte_eth_link() { 8usize, concat!("Alignment of ", stringify!(rte_eth_link)) ); - fn test_field_link_speed() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).link_speed) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_link), - "::", - stringify!(link_speed) - ) - ); - } - test_field_link_speed(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).link_speed) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_link), + "::", + stringify!(link_speed) + ) + ); } impl rte_eth_link { #[inline] diff --git a/tests/expectations/tests/libclang-9/type_alias_template_specialized.rs b/tests/expectations/tests/libclang-9/type_alias_template_specialized.rs index 213d4cd685..3e6550936c 100644 --- a/tests/expectations/tests/libclang-9/type_alias_template_specialized.rs +++ b/tests/expectations/tests/libclang-9/type_alias_template_specialized.rs @@ -12,6 +12,8 @@ pub struct Rooted { } #[test] fn bindgen_test_layout_Rooted() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -22,23 +24,19 @@ fn bindgen_test_layout_Rooted() { 4usize, concat!("Alignment of ", stringify!(Rooted)) ); - fn test_field_ptr() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Rooted), - "::", - stringify!(ptr) - ) - ); - } - test_field_ptr(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Rooted), + "::", + stringify!(ptr) + ) + ); } impl Default for Rooted { fn default() -> Self { diff --git a/tests/expectations/tests/libclang-9/zero-sized-array.rs b/tests/expectations/tests/libclang-9/zero-sized-array.rs index 185b8e21ab..f67ac2b383 100644 --- a/tests/expectations/tests/libclang-9/zero-sized-array.rs +++ b/tests/expectations/tests/libclang-9/zero-sized-array.rs @@ -43,6 +43,8 @@ pub struct ZeroSizedArray { } #[test] fn bindgen_test_layout_ZeroSizedArray() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 0usize, @@ -53,24 +55,19 @@ fn bindgen_test_layout_ZeroSizedArray() { 1usize, concat!("Alignment of ", stringify!(ZeroSizedArray)) ); - fn test_field_arr() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ZeroSizedArray), - "::", - stringify!(arr) - ) - ); - } - test_field_arr(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ZeroSizedArray), + "::", + stringify!(arr) + ) + ); } /// And nor should this get an `_address` field. #[repr(C)] @@ -80,6 +77,8 @@ pub struct ContainsZeroSizedArray { } #[test] fn bindgen_test_layout_ContainsZeroSizedArray() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 0usize, @@ -90,24 +89,19 @@ fn bindgen_test_layout_ContainsZeroSizedArray() { 1usize, concat!("Alignment of ", stringify!(ContainsZeroSizedArray)) ); - fn test_field_zsa() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).zsa) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContainsZeroSizedArray), - "::", - stringify!(zsa) - ) - ); - } - test_field_zsa(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).zsa) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ContainsZeroSizedArray), + "::", + stringify!(zsa) + ) + ); } /// Inheriting from ZeroSizedArray shouldn't cause an `_address` to be inserted /// either. @@ -137,6 +131,8 @@ pub struct DynamicallySizedArray { } #[test] fn bindgen_test_layout_DynamicallySizedArray() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 0usize, @@ -147,24 +143,19 @@ fn bindgen_test_layout_DynamicallySizedArray() { 1usize, concat!("Alignment of ", stringify!(DynamicallySizedArray)) ); - fn test_field_arr() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(DynamicallySizedArray), - "::", - stringify!(arr) - ) - ); - } - test_field_arr(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(DynamicallySizedArray), + "::", + stringify!(arr) + ) + ); } /// No `_address` field here either. #[repr(C)] @@ -174,6 +165,8 @@ pub struct ContainsDynamicallySizedArray { } #[test] fn bindgen_test_layout_ContainsDynamicallySizedArray() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 0usize, @@ -184,23 +177,17 @@ fn bindgen_test_layout_ContainsDynamicallySizedArray() { 1usize, concat!("Alignment of ", stringify!(ContainsDynamicallySizedArray)) ); - fn test_field_dsa() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - ContainsDynamicallySizedArray, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).dsa) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContainsDynamicallySizedArray), - "::", - stringify!(dsa) - ) - ); - } - test_field_dsa(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).dsa) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ContainsDynamicallySizedArray), + "::", + stringify!(dsa) + ) + ); } diff --git a/tests/expectations/tests/long_double.rs b/tests/expectations/tests/long_double.rs index 7e2dfd2a31..54ed294868 100644 --- a/tests/expectations/tests/long_double.rs +++ b/tests/expectations/tests/long_double.rs @@ -13,6 +13,8 @@ pub struct foo { } #[test] fn bindgen_test_layout_foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -23,21 +25,12 @@ fn bindgen_test_layout_foo() { 16usize, concat!("Alignment of ", stringify!(foo)) ); - fn test_field_bar() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(bar) - ) - ); - } - test_field_bar(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) + ); } diff --git a/tests/expectations/tests/msvc-no-usr.rs b/tests/expectations/tests/msvc-no-usr.rs index 6e8a98c330..e0ffc04320 100644 --- a/tests/expectations/tests/msvc-no-usr.rs +++ b/tests/expectations/tests/msvc-no-usr.rs @@ -13,6 +13,8 @@ pub struct A { } #[test] fn bindgen_test_layout_A() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -23,16 +25,12 @@ fn bindgen_test_layout_A() { 8usize, concat!("Alignment of ", stringify!(A)) ); - fn test_field_foo() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(foo)) - ); - } - test_field_foo(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(A), "::", stringify!(foo)) + ); } diff --git a/tests/expectations/tests/mutable.rs b/tests/expectations/tests/mutable.rs index feae0609c1..cca9927ee4 100644 --- a/tests/expectations/tests/mutable.rs +++ b/tests/expectations/tests/mutable.rs @@ -13,6 +13,8 @@ pub struct C { } #[test] fn bindgen_test_layout_C() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -23,40 +25,32 @@ fn bindgen_test_layout_C() { 4usize, concat!("Alignment of ", stringify!(C)) ); - fn test_field_m_member() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(m_member) - ) - ); - } - test_field_m_member(); - fn test_field_m_other() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).m_other) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(m_other) - ) - ); - } - test_field_m_other(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(m_member) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).m_other) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(m_other) + ) + ); } #[repr(C)] #[derive(Debug, Default)] @@ -65,6 +59,8 @@ pub struct NonCopiable { } #[test] fn bindgen_test_layout_NonCopiable() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -75,23 +71,19 @@ fn bindgen_test_layout_NonCopiable() { 4usize, concat!("Alignment of ", stringify!(NonCopiable)) ); - fn test_field_m_member() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NonCopiable), - "::", - stringify!(m_member) - ) - ); - } - test_field_m_member(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(NonCopiable), + "::", + stringify!(m_member) + ) + ); } #[repr(C)] #[derive(Debug, Default)] @@ -100,6 +92,9 @@ pub struct NonCopiableWithNonCopiableMutableMember { } #[test] fn bindgen_test_layout_NonCopiableWithNonCopiableMutableMember() { + const UNINIT: ::std::mem::MaybeUninit< + NonCopiableWithNonCopiableMutableMember, + > = ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -116,23 +111,17 @@ fn bindgen_test_layout_NonCopiableWithNonCopiableMutableMember() { stringify!(NonCopiableWithNonCopiableMutableMember) ) ); - fn test_field_m_member() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - NonCopiableWithNonCopiableMutableMember, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NonCopiableWithNonCopiableMutableMember), - "::", - stringify!(m_member) - ) - ); - } - test_field_m_member(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(NonCopiableWithNonCopiableMutableMember), + "::", + stringify!(m_member) + ) + ); } diff --git a/tests/expectations/tests/namespace.rs b/tests/expectations/tests/namespace.rs index 72c17ee64a..555629d431 100644 --- a/tests/expectations/tests/namespace.rs +++ b/tests/expectations/tests/namespace.rs @@ -33,6 +33,8 @@ pub mod root { } #[test] fn bindgen_test_layout_A() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -43,23 +45,19 @@ pub mod root { 4usize, concat!("Alignment of ", stringify!(A)) ); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(A), - "::", - stringify!(b) - ) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(A), + "::", + stringify!(b) + ) + ); } } #[repr(C)] diff --git a/tests/expectations/tests/nested.rs b/tests/expectations/tests/nested.rs index 48061e9be1..82a483aee2 100644 --- a/tests/expectations/tests/nested.rs +++ b/tests/expectations/tests/nested.rs @@ -12,6 +12,8 @@ pub struct Calc { } #[test] fn bindgen_test_layout_Calc() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -22,18 +24,14 @@ fn bindgen_test_layout_Calc() { 4usize, concat!("Alignment of ", stringify!(Calc)) ); - fn test_field_w() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).w) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Calc), "::", stringify!(w)) - ); - } - test_field_w(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).w) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Calc), "::", stringify!(w)) + ); } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -66,6 +64,8 @@ fn bindgen_test_layout_Test_Size_Dimension() { } #[test] fn bindgen_test_layout_Test_Size() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -76,40 +76,32 @@ fn bindgen_test_layout_Test_Size() { 4usize, concat!("Alignment of ", stringify!(Test_Size)) ); - fn test_field_mWidth() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mWidth) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Test_Size), - "::", - stringify!(mWidth) - ) - ); - } - test_field_mWidth(); - fn test_field_mHeight() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mHeight) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(Test_Size), - "::", - stringify!(mHeight) - ) - ); - } - test_field_mHeight(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mWidth) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Test_Size), + "::", + stringify!(mWidth) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mHeight) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(Test_Size), + "::", + stringify!(mHeight) + ) + ); } #[test] fn bindgen_test_layout_Test() { diff --git a/tests/expectations/tests/nested_within_namespace.rs b/tests/expectations/tests/nested_within_namespace.rs index 3e6e0466d2..d4874d41b6 100644 --- a/tests/expectations/tests/nested_within_namespace.rs +++ b/tests/expectations/tests/nested_within_namespace.rs @@ -24,6 +24,8 @@ pub mod root { } #[test] fn bindgen_test_layout_Bar_Baz() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -34,27 +36,24 @@ pub mod root { 4usize, concat!("Alignment of ", stringify!(Bar_Baz)) ); - fn test_field_foo() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar_Baz), - "::", - stringify!(foo) - ) - ); - } - test_field_foo(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Bar_Baz), + "::", + stringify!(foo) + ) + ); } #[test] fn bindgen_test_layout_Bar() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -65,23 +64,19 @@ pub mod root { 4usize, concat!("Alignment of ", stringify!(Bar)) ); - fn test_field_foo() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(foo) - ) - ); - } - test_field_foo(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Bar), + "::", + stringify!(foo) + ) + ); } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -90,6 +85,8 @@ pub mod root { } #[test] fn bindgen_test_layout_Baz() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -100,23 +97,19 @@ pub mod root { 4usize, concat!("Alignment of ", stringify!(Baz)) ); - fn test_field_baz() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Baz), - "::", - stringify!(baz) - ) - ); - } - test_field_baz(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Baz), + "::", + stringify!(baz) + ) + ); } } } diff --git a/tests/expectations/tests/no-comments.rs b/tests/expectations/tests/no-comments.rs index f13b4f8b1d..2f22f1cfa4 100644 --- a/tests/expectations/tests/no-comments.rs +++ b/tests/expectations/tests/no-comments.rs @@ -12,6 +12,8 @@ pub struct Foo { } #[test] fn bindgen_test_layout_Foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -22,16 +24,12 @@ fn bindgen_test_layout_Foo() { 4usize, concat!("Alignment of ", stringify!(Foo)) ); - fn test_field_s() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).s) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(s)) - ); - } - test_field_s(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).s) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(s)) + ); } diff --git a/tests/expectations/tests/no-derive-debug.rs b/tests/expectations/tests/no-derive-debug.rs index 2aa1c10280..ffdc2c2f67 100644 --- a/tests/expectations/tests/no-derive-debug.rs +++ b/tests/expectations/tests/no-derive-debug.rs @@ -21,6 +21,8 @@ pub struct bar { } #[test] fn bindgen_test_layout_bar() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -31,40 +33,22 @@ fn bindgen_test_layout_bar() { 4usize, concat!("Alignment of ", stringify!(bar)) ); - fn test_field_foo() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(foo) - ) - ); - } - test_field_foo(); - fn test_field_baz() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(baz) - ) - ); - } - test_field_baz(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(bar), "::", stringify!(foo)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, + 4usize, + concat!("Offset of field: ", stringify!(bar), "::", stringify!(baz)) + ); } impl Default for bar { fn default() -> Self { diff --git a/tests/expectations/tests/no-derive-default.rs b/tests/expectations/tests/no-derive-default.rs index 6e5efbe60a..7e21f8ab00 100644 --- a/tests/expectations/tests/no-derive-default.rs +++ b/tests/expectations/tests/no-derive-default.rs @@ -21,6 +21,8 @@ pub struct bar { } #[test] fn bindgen_test_layout_bar() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -31,38 +33,20 @@ fn bindgen_test_layout_bar() { 4usize, concat!("Alignment of ", stringify!(bar)) ); - fn test_field_foo() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(foo) - ) - ); - } - test_field_foo(); - fn test_field_baz() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(baz) - ) - ); - } - test_field_baz(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(bar), "::", stringify!(foo)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, + 4usize, + concat!("Offset of field: ", stringify!(bar), "::", stringify!(baz)) + ); } diff --git a/tests/expectations/tests/no-hash-allowlisted.rs b/tests/expectations/tests/no-hash-allowlisted.rs index 43132cb052..b92ae996be 100644 --- a/tests/expectations/tests/no-hash-allowlisted.rs +++ b/tests/expectations/tests/no-hash-allowlisted.rs @@ -12,6 +12,8 @@ pub struct NoHash { } #[test] fn bindgen_test_layout_NoHash() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -22,21 +24,12 @@ fn bindgen_test_layout_NoHash() { 4usize, concat!("Alignment of ", stringify!(NoHash)) ); - fn test_field_i() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NoHash), - "::", - stringify!(i) - ) - ); - } - test_field_i(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(NoHash), "::", stringify!(i)) + ); } diff --git a/tests/expectations/tests/no-partialeq-allowlisted.rs b/tests/expectations/tests/no-partialeq-allowlisted.rs index e43e855727..16fae74146 100644 --- a/tests/expectations/tests/no-partialeq-allowlisted.rs +++ b/tests/expectations/tests/no-partialeq-allowlisted.rs @@ -12,6 +12,8 @@ pub struct NoPartialEq { } #[test] fn bindgen_test_layout_NoPartialEq() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -22,21 +24,17 @@ fn bindgen_test_layout_NoPartialEq() { 4usize, concat!("Alignment of ", stringify!(NoPartialEq)) ); - fn test_field_i() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NoPartialEq), - "::", - stringify!(i) - ) - ); - } - test_field_i(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(NoPartialEq), + "::", + stringify!(i) + ) + ); } diff --git a/tests/expectations/tests/no-recursive-allowlisting.rs b/tests/expectations/tests/no-recursive-allowlisting.rs index 197b099dc1..2246fbdacd 100644 --- a/tests/expectations/tests/no-recursive-allowlisting.rs +++ b/tests/expectations/tests/no-recursive-allowlisting.rs @@ -14,6 +14,8 @@ pub struct Foo { } #[test] fn bindgen_test_layout_Foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -24,23 +26,14 @@ fn bindgen_test_layout_Foo() { 8usize, concat!("Alignment of ", stringify!(Foo)) ); - fn test_field_baz() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(baz) - ) - ); - } - test_field_baz(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(baz)) + ); } impl Default for Foo { fn default() -> Self { diff --git a/tests/expectations/tests/no-std.rs b/tests/expectations/tests/no-std.rs index f3157bbeea..ef19aa3fa7 100644 --- a/tests/expectations/tests/no-std.rs +++ b/tests/expectations/tests/no-std.rs @@ -19,6 +19,8 @@ pub struct foo { } #[test] fn bindgen_test_layout_foo() { + const UNINIT: ::core::mem::MaybeUninit = + ::core::mem::MaybeUninit::uninit(); assert_eq!( ::core::mem::size_of::(), 16usize, @@ -29,47 +31,30 @@ fn bindgen_test_layout_foo() { 8usize, concat!("Alignment of ", stringify!(foo)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::core::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::core::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) - ); - } - test_field_a(); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = ::core::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::core::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 4usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) - ); - } - test_field_b(); - fn test_field_bar() { - assert_eq!( - unsafe { - let uninit = ::core::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(bar) - ) - ); - } - test_field_bar(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::core::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::core::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 4usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 8usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) + ); } impl Default for foo { fn default() -> Self { diff --git a/tests/expectations/tests/no_copy_allowlisted.rs b/tests/expectations/tests/no_copy_allowlisted.rs index ae086d2133..a0d89a310b 100644 --- a/tests/expectations/tests/no_copy_allowlisted.rs +++ b/tests/expectations/tests/no_copy_allowlisted.rs @@ -12,6 +12,8 @@ pub struct NoCopy { } #[test] fn bindgen_test_layout_NoCopy() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -22,21 +24,12 @@ fn bindgen_test_layout_NoCopy() { 4usize, concat!("Alignment of ", stringify!(NoCopy)) ); - fn test_field_i() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NoCopy), - "::", - stringify!(i) - ) - ); - } - test_field_i(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(NoCopy), "::", stringify!(i)) + ); } diff --git a/tests/expectations/tests/no_debug_allowlisted.rs b/tests/expectations/tests/no_debug_allowlisted.rs index 9f070d24af..b89dadd6da 100644 --- a/tests/expectations/tests/no_debug_allowlisted.rs +++ b/tests/expectations/tests/no_debug_allowlisted.rs @@ -12,6 +12,8 @@ pub struct NoDebug { } #[test] fn bindgen_test_layout_NoDebug() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -22,21 +24,17 @@ fn bindgen_test_layout_NoDebug() { 4usize, concat!("Alignment of ", stringify!(NoDebug)) ); - fn test_field_i() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NoDebug), - "::", - stringify!(i) - ) - ); - } - test_field_i(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(NoDebug), + "::", + stringify!(i) + ) + ); } diff --git a/tests/expectations/tests/no_default_allowlisted.rs b/tests/expectations/tests/no_default_allowlisted.rs index 07e01b72c8..9480136265 100644 --- a/tests/expectations/tests/no_default_allowlisted.rs +++ b/tests/expectations/tests/no_default_allowlisted.rs @@ -12,6 +12,8 @@ pub struct NoDefault { } #[test] fn bindgen_test_layout_NoDefault() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -22,21 +24,17 @@ fn bindgen_test_layout_NoDefault() { 4usize, concat!("Alignment of ", stringify!(NoDefault)) ); - fn test_field_i() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NoDefault), - "::", - stringify!(i) - ) - ); - } - test_field_i(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(NoDefault), + "::", + stringify!(i) + ) + ); } diff --git a/tests/expectations/tests/non-type-params.rs b/tests/expectations/tests/non-type-params.rs index f6478528c3..84388828ee 100644 --- a/tests/expectations/tests/non-type-params.rs +++ b/tests/expectations/tests/non-type-params.rs @@ -16,6 +16,8 @@ pub struct UsesArray { } #[test] fn bindgen_test_layout_UsesArray() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 40usize, @@ -26,57 +28,43 @@ fn bindgen_test_layout_UsesArray() { 4usize, concat!("Alignment of ", stringify!(UsesArray)) ); - fn test_field_array_char_16() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).array_char_16) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(UsesArray), - "::", - stringify!(array_char_16) - ) - ); - } - test_field_array_char_16(); - fn test_field_array_bool_8() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).array_bool_8) as usize - - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(UsesArray), - "::", - stringify!(array_bool_8) - ) - ); - } - test_field_array_bool_8(); - fn test_field_array_int_4() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).array_int_4) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(UsesArray), - "::", - stringify!(array_int_4) - ) - ); - } - test_field_array_int_4(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).array_char_16) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(UsesArray), + "::", + stringify!(array_char_16) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).array_bool_8) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(UsesArray), + "::", + stringify!(array_bool_8) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).array_int_4) as usize - ptr as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(UsesArray), + "::", + stringify!(array_int_4) + ) + ); } diff --git a/tests/expectations/tests/objc_interface_type.rs b/tests/expectations/tests/objc_interface_type.rs index 5cafeede56..1795eaad85 100644 --- a/tests/expectations/tests/objc_interface_type.rs +++ b/tests/expectations/tests/objc_interface_type.rs @@ -33,6 +33,8 @@ pub struct FooStruct { } #[test] fn bindgen_test_layout_FooStruct() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -43,23 +45,19 @@ fn bindgen_test_layout_FooStruct() { 8usize, concat!("Alignment of ", stringify!(FooStruct)) ); - fn test_field_foo() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(FooStruct), - "::", - stringify!(foo) - ) - ); - } - test_field_foo(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(FooStruct), + "::", + stringify!(foo) + ) + ); } impl Default for FooStruct { fn default() -> Self { diff --git a/tests/expectations/tests/opaque-template-inst-member-2.rs b/tests/expectations/tests/opaque-template-inst-member-2.rs index 391c46d1d0..b0380e64c3 100644 --- a/tests/expectations/tests/opaque-template-inst-member-2.rs +++ b/tests/expectations/tests/opaque-template-inst-member-2.rs @@ -21,6 +21,8 @@ pub struct ContainsOpaqueTemplate { } #[test] fn bindgen_test_layout_ContainsOpaqueTemplate() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -31,42 +33,32 @@ fn bindgen_test_layout_ContainsOpaqueTemplate() { 4usize, concat!("Alignment of ", stringify!(ContainsOpaqueTemplate)) ); - fn test_field_mBlah() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBlah) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContainsOpaqueTemplate), - "::", - stringify!(mBlah) - ) - ); - } - test_field_mBlah(); - fn test_field_mBaz() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBaz) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(ContainsOpaqueTemplate), - "::", - stringify!(mBaz) - ) - ); - } - test_field_mBaz(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBlah) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ContainsOpaqueTemplate), + "::", + stringify!(mBlah) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBaz) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(ContainsOpaqueTemplate), + "::", + stringify!(mBaz) + ) + ); } /// Should also derive Debug/Hash/PartialEq. #[repr(C)] @@ -77,6 +69,8 @@ pub struct InheritsOpaqueTemplate { } #[test] fn bindgen_test_layout_InheritsOpaqueTemplate() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -87,24 +81,19 @@ fn bindgen_test_layout_InheritsOpaqueTemplate() { 8usize, concat!("Alignment of ", stringify!(InheritsOpaqueTemplate)) ); - fn test_field_wow() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).wow) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(InheritsOpaqueTemplate), - "::", - stringify!(wow) - ) - ); - } - test_field_wow(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).wow) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(InheritsOpaqueTemplate), + "::", + stringify!(wow) + ) + ); } impl Default for InheritsOpaqueTemplate { fn default() -> Self { diff --git a/tests/expectations/tests/opaque-template-inst-member.rs b/tests/expectations/tests/opaque-template-inst-member.rs index 0942976816..f7f405dcdf 100644 --- a/tests/expectations/tests/opaque-template-inst-member.rs +++ b/tests/expectations/tests/opaque-template-inst-member.rs @@ -19,6 +19,8 @@ pub struct ContainsOpaqueTemplate { } #[test] fn bindgen_test_layout_ContainsOpaqueTemplate() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 408usize, @@ -29,42 +31,32 @@ fn bindgen_test_layout_ContainsOpaqueTemplate() { 4usize, concat!("Alignment of ", stringify!(ContainsOpaqueTemplate)) ); - fn test_field_mBlah() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBlah) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContainsOpaqueTemplate), - "::", - stringify!(mBlah) - ) - ); - } - test_field_mBlah(); - fn test_field_mBaz() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBaz) as usize - ptr as usize - }, - 404usize, - concat!( - "Offset of field: ", - stringify!(ContainsOpaqueTemplate), - "::", - stringify!(mBaz) - ) - ); - } - test_field_mBaz(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBlah) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ContainsOpaqueTemplate), + "::", + stringify!(mBlah) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBaz) as usize - ptr as usize + }, + 404usize, + concat!( + "Offset of field: ", + stringify!(ContainsOpaqueTemplate), + "::", + stringify!(mBaz) + ) + ); } impl Default for ContainsOpaqueTemplate { fn default() -> Self { @@ -89,6 +81,8 @@ pub struct InheritsOpaqueTemplate { } #[test] fn bindgen_test_layout_InheritsOpaqueTemplate() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 416usize, @@ -99,24 +93,19 @@ fn bindgen_test_layout_InheritsOpaqueTemplate() { 8usize, concat!("Alignment of ", stringify!(InheritsOpaqueTemplate)) ); - fn test_field_wow() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).wow) as usize - ptr as usize - }, - 408usize, - concat!( - "Offset of field: ", - stringify!(InheritsOpaqueTemplate), - "::", - stringify!(wow) - ) - ); - } - test_field_wow(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).wow) as usize - ptr as usize + }, + 408usize, + concat!( + "Offset of field: ", + stringify!(InheritsOpaqueTemplate), + "::", + stringify!(wow) + ) + ); } impl Default for InheritsOpaqueTemplate { fn default() -> Self { diff --git a/tests/expectations/tests/opaque-template-instantiation-namespaced.rs b/tests/expectations/tests/opaque-template-instantiation-namespaced.rs index 293f2a1ba6..cbb04872c3 100644 --- a/tests/expectations/tests/opaque-template-instantiation-namespaced.rs +++ b/tests/expectations/tests/opaque-template-instantiation-namespaced.rs @@ -35,6 +35,8 @@ pub mod root { } #[test] fn bindgen_test_layout_Foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -45,23 +47,19 @@ pub mod root { 1usize, concat!("Alignment of ", stringify!(Foo)) ); - fn test_field_c() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(c) - ) - ); - } - test_field_c(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Foo), + "::", + stringify!(c) + ) + ); } #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] @@ -70,6 +68,8 @@ pub mod root { } #[test] fn bindgen_test_layout_Bar() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -80,23 +80,19 @@ pub mod root { 4usize, concat!("Alignment of ", stringify!(Bar)) ); - fn test_field_i() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(i) - ) - ); - } - test_field_i(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Bar), + "::", + stringify!(i) + ) + ); } #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] @@ -105,6 +101,8 @@ pub mod root { } #[test] fn bindgen_test_layout_ContainsInstantiation() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -115,26 +113,20 @@ pub mod root { 1usize, concat!("Alignment of ", stringify!(ContainsInstantiation)) ); - fn test_field_not_opaque() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - ContainsInstantiation, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).not_opaque) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContainsInstantiation), - "::", - stringify!(not_opaque) - ) - ); - } - test_field_not_opaque(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).not_opaque) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ContainsInstantiation), + "::", + stringify!(not_opaque) + ) + ); } impl Default for ContainsInstantiation { fn default() -> Self { @@ -152,6 +144,8 @@ pub mod root { } #[test] fn bindgen_test_layout_ContainsOpaqueInstantiation() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -165,26 +159,19 @@ pub mod root { stringify!(ContainsOpaqueInstantiation) ) ); - fn test_field_opaque() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - ContainsOpaqueInstantiation, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).opaque) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContainsOpaqueInstantiation), - "::", - stringify!(opaque) - ) - ); - } - test_field_opaque(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).opaque) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ContainsOpaqueInstantiation), + "::", + stringify!(opaque) + ) + ); } } #[test] diff --git a/tests/expectations/tests/opaque-template-instantiation.rs b/tests/expectations/tests/opaque-template-instantiation.rs index 9f02920eb6..53082631c8 100644 --- a/tests/expectations/tests/opaque-template-instantiation.rs +++ b/tests/expectations/tests/opaque-template-instantiation.rs @@ -27,6 +27,8 @@ pub struct ContainsInstantiation { } #[test] fn bindgen_test_layout_ContainsInstantiation() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -37,24 +39,19 @@ fn bindgen_test_layout_ContainsInstantiation() { 1usize, concat!("Alignment of ", stringify!(ContainsInstantiation)) ); - fn test_field_not_opaque() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).not_opaque) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContainsInstantiation), - "::", - stringify!(not_opaque) - ) - ); - } - test_field_not_opaque(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).not_opaque) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ContainsInstantiation), + "::", + stringify!(not_opaque) + ) + ); } impl Default for ContainsInstantiation { fn default() -> Self { @@ -72,6 +69,8 @@ pub struct ContainsOpaqueInstantiation { } #[test] fn bindgen_test_layout_ContainsOpaqueInstantiation() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -82,25 +81,19 @@ fn bindgen_test_layout_ContainsOpaqueInstantiation() { 4usize, concat!("Alignment of ", stringify!(ContainsOpaqueInstantiation)) ); - fn test_field_opaque() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - ContainsOpaqueInstantiation, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).opaque) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContainsOpaqueInstantiation), - "::", - stringify!(opaque) - ) - ); - } - test_field_opaque(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).opaque) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ContainsOpaqueInstantiation), + "::", + stringify!(opaque) + ) + ); } #[test] fn __bindgen_test_layout_Template_open0_char_close0_instantiation() { diff --git a/tests/expectations/tests/opaque_in_struct.rs b/tests/expectations/tests/opaque_in_struct.rs index 4af91c4fac..9caecc1fb8 100644 --- a/tests/expectations/tests/opaque_in_struct.rs +++ b/tests/expectations/tests/opaque_in_struct.rs @@ -32,6 +32,8 @@ pub struct container { } #[test] fn bindgen_test_layout_container() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -42,21 +44,17 @@ fn bindgen_test_layout_container() { 4usize, concat!("Alignment of ", stringify!(container)) ); - fn test_field_contained() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).contained) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(container), - "::", - stringify!(contained) - ) - ); - } - test_field_contained(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).contained) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(container), + "::", + stringify!(contained) + ) + ); } diff --git a/tests/expectations/tests/opaque_pointer.rs b/tests/expectations/tests/opaque_pointer.rs index 7230c3c066..57bb2a9b96 100644 --- a/tests/expectations/tests/opaque_pointer.rs +++ b/tests/expectations/tests/opaque_pointer.rs @@ -40,6 +40,8 @@ pub struct WithOpaquePtr { } #[test] fn bindgen_test_layout_WithOpaquePtr() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -50,57 +52,45 @@ fn bindgen_test_layout_WithOpaquePtr() { 8usize, concat!("Alignment of ", stringify!(WithOpaquePtr)) ); - fn test_field_whatever() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).whatever) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithOpaquePtr), - "::", - stringify!(whatever) - ) - ); - } - test_field_whatever(); - fn test_field_other() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).other) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(WithOpaquePtr), - "::", - stringify!(other) - ) - ); - } - test_field_other(); - fn test_field_t() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).t) as usize - ptr as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(WithOpaquePtr), - "::", - stringify!(t) - ) - ); - } - test_field_t(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).whatever) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithOpaquePtr), + "::", + stringify!(whatever) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).other) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(WithOpaquePtr), + "::", + stringify!(other) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).t) as usize - ptr as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(WithOpaquePtr), + "::", + stringify!(t) + ) + ); } impl Default for WithOpaquePtr { fn default() -> Self { diff --git a/tests/expectations/tests/packed-n-with-padding.rs b/tests/expectations/tests/packed-n-with-padding.rs index 6e749b1b72..54414aebc9 100644 --- a/tests/expectations/tests/packed-n-with-padding.rs +++ b/tests/expectations/tests/packed-n-with-padding.rs @@ -15,6 +15,8 @@ pub struct Packed { } #[test] fn bindgen_test_layout_Packed() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 10usize, @@ -25,72 +27,36 @@ fn bindgen_test_layout_Packed() { 2usize, concat!("Alignment of ", stringify!(Packed)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Packed), - "::", - stringify!(a) - ) - ); - } - test_field_a(); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(Packed), - "::", - stringify!(b) - ) - ); - } - test_field_b(); - fn test_field_c() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(Packed), - "::", - stringify!(c) - ) - ); - } - test_field_c(); - fn test_field_d() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, - 6usize, - concat!( - "Offset of field: ", - stringify!(Packed), - "::", - stringify!(d) - ) - ); - } - test_field_d(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Packed), "::", stringify!(a)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 2usize, + concat!("Offset of field: ", stringify!(Packed), "::", stringify!(b)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize + }, + 4usize, + concat!("Offset of field: ", stringify!(Packed), "::", stringify!(c)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, + 6usize, + concat!("Offset of field: ", stringify!(Packed), "::", stringify!(d)) + ); } diff --git a/tests/expectations/tests/private.rs b/tests/expectations/tests/private.rs index 63b5676849..b43f840f86 100644 --- a/tests/expectations/tests/private.rs +++ b/tests/expectations/tests/private.rs @@ -14,6 +14,8 @@ pub struct HasPrivate { } #[test] fn bindgen_test_layout_HasPrivate() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -24,40 +26,32 @@ fn bindgen_test_layout_HasPrivate() { 4usize, concat!("Alignment of ", stringify!(HasPrivate)) ); - fn test_field_mNotPrivate() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mNotPrivate) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(HasPrivate), - "::", - stringify!(mNotPrivate) - ) - ); - } - test_field_mNotPrivate(); - fn test_field_mIsPrivate() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mIsPrivate) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(HasPrivate), - "::", - stringify!(mIsPrivate) - ) - ); - } - test_field_mIsPrivate(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mNotPrivate) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(HasPrivate), + "::", + stringify!(mNotPrivate) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mIsPrivate) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(HasPrivate), + "::", + stringify!(mIsPrivate) + ) + ); } ///
#[repr(C)] @@ -68,6 +62,8 @@ pub struct VeryPrivate { } #[test] fn bindgen_test_layout_VeryPrivate() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -78,41 +74,32 @@ fn bindgen_test_layout_VeryPrivate() { 4usize, concat!("Alignment of ", stringify!(VeryPrivate)) ); - fn test_field_mIsPrivate() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mIsPrivate) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(VeryPrivate), - "::", - stringify!(mIsPrivate) - ) - ); - } - test_field_mIsPrivate(); - fn test_field_mIsAlsoPrivate() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mIsAlsoPrivate) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(VeryPrivate), - "::", - stringify!(mIsAlsoPrivate) - ) - ); - } - test_field_mIsAlsoPrivate(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mIsPrivate) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(VeryPrivate), + "::", + stringify!(mIsPrivate) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mIsAlsoPrivate) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(VeryPrivate), + "::", + stringify!(mIsAlsoPrivate) + ) + ); } ///
#[repr(C)] @@ -124,6 +111,8 @@ pub struct ContradictPrivate { } #[test] fn bindgen_test_layout_ContradictPrivate() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -134,40 +123,30 @@ fn bindgen_test_layout_ContradictPrivate() { 4usize, concat!("Alignment of ", stringify!(ContradictPrivate)) ); - fn test_field_mNotPrivate() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mNotPrivate) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContradictPrivate), - "::", - stringify!(mNotPrivate) - ) - ); - } - test_field_mNotPrivate(); - fn test_field_mIsPrivate() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mIsPrivate) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(ContradictPrivate), - "::", - stringify!(mIsPrivate) - ) - ); - } - test_field_mIsPrivate(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mNotPrivate) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ContradictPrivate), + "::", + stringify!(mNotPrivate) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mIsPrivate) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(ContradictPrivate), + "::", + stringify!(mIsPrivate) + ) + ); } diff --git a/tests/expectations/tests/private_fields.rs b/tests/expectations/tests/private_fields.rs index bea0fa4c2c..137689cc45 100644 --- a/tests/expectations/tests/private_fields.rs +++ b/tests/expectations/tests/private_fields.rs @@ -99,6 +99,8 @@ pub struct PubPriv { } #[test] fn bindgen_test_layout_PubPriv() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -109,40 +111,32 @@ fn bindgen_test_layout_PubPriv() { 4usize, concat!("Alignment of ", stringify!(PubPriv)) ); - fn test_field_x() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(PubPriv), - "::", - stringify!(x) - ) - ); - } - test_field_x(); - fn test_field_y() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(PubPriv), - "::", - stringify!(y) - ) - ); - } - test_field_y(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(PubPriv), + "::", + stringify!(x) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(PubPriv), + "::", + stringify!(y) + ) + ); } #[repr(C)] #[repr(align(4))] @@ -349,6 +343,8 @@ pub struct Base { } #[test] fn bindgen_test_layout_Base() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -359,23 +355,19 @@ fn bindgen_test_layout_Base() { 4usize, concat!("Alignment of ", stringify!(Base)) ); - fn test_field_member() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Base), - "::", - stringify!(member) - ) - ); - } - test_field_member(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Base), + "::", + stringify!(member) + ) + ); } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -426,6 +418,8 @@ pub struct WithAnonStruct__bindgen_ty_1 { } #[test] fn bindgen_test_layout_WithAnonStruct__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -436,25 +430,19 @@ fn bindgen_test_layout_WithAnonStruct__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(WithAnonStruct__bindgen_ty_1)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - WithAnonStruct__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithAnonStruct__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - } - test_field_a(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithAnonStruct__bindgen_ty_1), + "::", + stringify!(a) + ) + ); } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -463,6 +451,8 @@ pub struct WithAnonStruct__bindgen_ty_2 { } #[test] fn bindgen_test_layout_WithAnonStruct__bindgen_ty_2() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -473,25 +463,19 @@ fn bindgen_test_layout_WithAnonStruct__bindgen_ty_2() { 4usize, concat!("Alignment of ", stringify!(WithAnonStruct__bindgen_ty_2)) ); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - WithAnonStruct__bindgen_ty_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithAnonStruct__bindgen_ty_2), - "::", - stringify!(b) - ) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithAnonStruct__bindgen_ty_2), + "::", + stringify!(b) + ) + ); } #[test] fn bindgen_test_layout_WithAnonStruct() { diff --git a/tests/expectations/tests/reparented_replacement.rs b/tests/expectations/tests/reparented_replacement.rs index f8426c2840..1691554166 100644 --- a/tests/expectations/tests/reparented_replacement.rs +++ b/tests/expectations/tests/reparented_replacement.rs @@ -20,6 +20,8 @@ pub mod root { } #[test] fn bindgen_test_layout_Bar() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -30,24 +32,19 @@ pub mod root { 4usize, concat!("Alignment of ", stringify!(Bar)) ); - fn test_field_bazz() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bazz) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(bazz) - ) - ); - } - test_field_bazz(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).bazz) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Bar), + "::", + stringify!(bazz) + ) + ); } } pub type ReferencesBar = root::foo::Bar; diff --git a/tests/expectations/tests/replace_use.rs b/tests/expectations/tests/replace_use.rs index 9478801f4b..7ff5b6d80a 100644 --- a/tests/expectations/tests/replace_use.rs +++ b/tests/expectations/tests/replace_use.rs @@ -18,6 +18,8 @@ pub struct Test { } #[test] fn bindgen_test_layout_Test() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -28,18 +30,14 @@ fn bindgen_test_layout_Test() { 4usize, concat!("Alignment of ", stringify!(Test)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(a)) - ); - } - test_field_a(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(a)) + ); } #[test] fn __bindgen_test_layout_nsTArray_open0_long_close0_instantiation() { diff --git a/tests/expectations/tests/repr-align.rs b/tests/expectations/tests/repr-align.rs index 3f00fce35c..fd5c080aea 100644 --- a/tests/expectations/tests/repr-align.rs +++ b/tests/expectations/tests/repr-align.rs @@ -15,6 +15,8 @@ pub struct a { } #[test] fn bindgen_test_layout_a() { + const UNINIT: ::std::mem::MaybeUninit
= + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -25,30 +27,22 @@ fn bindgen_test_layout_a() { 8usize, concat!("Alignment of ", stringify!(a)) ); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(a), "::", stringify!(b)) - ); - } - test_field_b(); - fn test_field_c() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize - }, - 4usize, - concat!("Offset of field: ", stringify!(a), "::", stringify!(c)) - ); - } - test_field_c(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(a), "::", stringify!(b)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize + }, + 4usize, + concat!("Offset of field: ", stringify!(a), "::", stringify!(c)) + ); } #[repr(C)] #[repr(align(8))] @@ -59,6 +53,8 @@ pub struct b { } #[test] fn bindgen_test_layout_b() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -69,28 +65,20 @@ fn bindgen_test_layout_b() { 8usize, concat!("Alignment of ", stringify!(b)) ); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(b), "::", stringify!(b)) - ); - } - test_field_b(); - fn test_field_c() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize - }, - 4usize, - concat!("Offset of field: ", stringify!(b), "::", stringify!(c)) - ); - } - test_field_c(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(b), "::", stringify!(b)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize + }, + 4usize, + concat!("Offset of field: ", stringify!(b), "::", stringify!(c)) + ); } diff --git a/tests/expectations/tests/same_struct_name_in_different_namespaces.rs b/tests/expectations/tests/same_struct_name_in_different_namespaces.rs index 294861d15b..30cfc67a51 100644 --- a/tests/expectations/tests/same_struct_name_in_different_namespaces.rs +++ b/tests/expectations/tests/same_struct_name_in_different_namespaces.rs @@ -18,6 +18,8 @@ pub struct JS_shadow_Zone { } #[test] fn bindgen_test_layout_JS_shadow_Zone() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -28,40 +30,30 @@ fn bindgen_test_layout_JS_shadow_Zone() { 4usize, concat!("Alignment of ", stringify!(JS_shadow_Zone)) ); - fn test_field_x() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(JS_shadow_Zone), - "::", - stringify!(x) - ) - ); - } - test_field_x(); - fn test_field_y() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(JS_shadow_Zone), - "::", - stringify!(y) - ) - ); - } - test_field_y(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(JS_shadow_Zone), + "::", + stringify!(x) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(JS_shadow_Zone), + "::", + stringify!(y) + ) + ); } diff --git a/tests/expectations/tests/sentry-defined-multiple-times.rs b/tests/expectations/tests/sentry-defined-multiple-times.rs index bf76d0e1e7..312823ebcf 100644 --- a/tests/expectations/tests/sentry-defined-multiple-times.rs +++ b/tests/expectations/tests/sentry-defined-multiple-times.rs @@ -29,6 +29,8 @@ pub mod root { } #[test] fn bindgen_test_layout_sentry() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -39,25 +41,20 @@ pub mod root { 1usize, concat!("Alignment of ", stringify!(sentry)) ); - fn test_field_i_am_plain_sentry() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i_am_plain_sentry) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(sentry), - "::", - stringify!(i_am_plain_sentry) - ) - ); - } - test_field_i_am_plain_sentry(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).i_am_plain_sentry) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(sentry), + "::", + stringify!(i_am_plain_sentry) + ) + ); } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -84,6 +81,8 @@ pub mod root { } #[test] fn bindgen_test_layout_NotTemplateWrapper_sentry() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -94,28 +93,22 @@ pub mod root { 1usize, concat!("Alignment of ", stringify!(NotTemplateWrapper_sentry)) ); - fn test_field_i_am_not_template_wrapper_sentry() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - NotTemplateWrapper_sentry, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!( - (*ptr).i_am_not_template_wrapper_sentry - ) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NotTemplateWrapper_sentry), - "::", - stringify!(i_am_not_template_wrapper_sentry) - ) - ); - } - test_field_i_am_not_template_wrapper_sentry(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!( + (*ptr).i_am_not_template_wrapper_sentry + ) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(NotTemplateWrapper_sentry), + "::", + stringify!(i_am_not_template_wrapper_sentry) + ) + ); } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -129,6 +122,9 @@ pub mod root { } #[test] fn bindgen_test_layout_InlineNotTemplateWrapper_sentry() { + const UNINIT: ::std::mem::MaybeUninit< + InlineNotTemplateWrapper_sentry, + > = ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -145,28 +141,22 @@ pub mod root { stringify!(InlineNotTemplateWrapper_sentry) ) ); - fn test_field_i_am_inline_not_template_wrapper_sentry() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - InlineNotTemplateWrapper_sentry, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!( - (*ptr).i_am_inline_not_template_wrapper_sentry - ) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(InlineNotTemplateWrapper_sentry), - "::", - stringify!(i_am_inline_not_template_wrapper_sentry) - ) - ); - } - test_field_i_am_inline_not_template_wrapper_sentry(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!( + (*ptr).i_am_inline_not_template_wrapper_sentry + ) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(InlineNotTemplateWrapper_sentry), + "::", + stringify!(i_am_inline_not_template_wrapper_sentry) + ) + ); } #[test] fn bindgen_test_layout_InlineNotTemplateWrapper() { @@ -240,6 +230,9 @@ pub mod root { } #[test] fn bindgen_test_layout_OuterDoubleWrapper_InnerDoubleWrapper_sentry() { + const UNINIT: ::std::mem::MaybeUninit< + OuterDoubleWrapper_InnerDoubleWrapper_sentry, + > = ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::< OuterDoubleWrapper_InnerDoubleWrapper_sentry, @@ -260,29 +253,21 @@ pub mod root { stringify!(OuterDoubleWrapper_InnerDoubleWrapper_sentry) ) ); - fn test_field_i_am_double_wrapper_sentry() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - OuterDoubleWrapper_InnerDoubleWrapper_sentry, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i_am_double_wrapper_sentry) - as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!( - OuterDoubleWrapper_InnerDoubleWrapper_sentry - ), - "::", - stringify!(i_am_double_wrapper_sentry) - ) - ); - } - test_field_i_am_double_wrapper_sentry(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).i_am_double_wrapper_sentry) + as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(OuterDoubleWrapper_InnerDoubleWrapper_sentry), + "::", + stringify!(i_am_double_wrapper_sentry) + ) + ); } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -302,12 +287,12 @@ pub mod root { #[test] fn bindgen_test_layout_OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry( ) { + const UNINIT: ::std::mem::MaybeUninit< + OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry, + > = ::std::mem::MaybeUninit::uninit(); assert_eq ! (:: std :: mem :: size_of :: < OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry > () , 4usize , concat ! ("Size of: " , stringify ! (OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry))); assert_eq ! (:: std :: mem :: align_of :: < OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry > () , 4usize , concat ! ("Alignment of " , stringify ! (OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry))); - fn test_field_i_am_double_wrapper_inline_sentry() { - assert_eq ! (unsafe { let uninit = :: std :: mem :: MaybeUninit :: < OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry > :: uninit () ; let ptr = uninit . as_ptr () ; :: std :: ptr :: addr_of ! ((* ptr) . i_am_double_wrapper_inline_sentry) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry) , "::" , stringify ! (i_am_double_wrapper_inline_sentry))); - } - test_field_i_am_double_wrapper_inline_sentry(); + assert_eq ! (unsafe { let ptr = UNINIT . as_ptr () ; :: std :: ptr :: addr_of ! ((* ptr) . i_am_double_wrapper_inline_sentry) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry) , "::" , stringify ! (i_am_double_wrapper_inline_sentry))); } #[test] fn bindgen_test_layout_OuterDoubleInlineWrapper_InnerDoubleInlineWrapper( @@ -368,6 +353,8 @@ pub mod root { } #[test] fn bindgen_test_layout_sentry() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -378,24 +365,20 @@ pub mod root { 4usize, concat!("Alignment of ", stringify!(sentry)) ); - fn test_field_i_am_outside_namespace_sentry() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i_am_outside_namespace_sentry) - as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(sentry), - "::", - stringify!(i_am_outside_namespace_sentry) - ) - ); - } - test_field_i_am_outside_namespace_sentry(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).i_am_outside_namespace_sentry) + as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(sentry), + "::", + stringify!(i_am_outside_namespace_sentry) + ) + ); } } diff --git a/tests/expectations/tests/size_t_is_usize.rs b/tests/expectations/tests/size_t_is_usize.rs index f4e4b79ba7..5c2c26708b 100644 --- a/tests/expectations/tests/size_t_is_usize.rs +++ b/tests/expectations/tests/size_t_is_usize.rs @@ -14,6 +14,8 @@ pub struct A { } #[test] fn bindgen_test_layout_A() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 24usize, @@ -24,47 +26,30 @@ fn bindgen_test_layout_A() { 8usize, concat!("Alignment of ", stringify!(A)) ); - fn test_field_len() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(len)) - ); - } - test_field_len(); - fn test_field_offset() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).offset) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(A), - "::", - stringify!(offset) - ) - ); - } - test_field_offset(); - fn test_field_next() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize - }, - 16usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(next)) - ); - } - test_field_next(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(A), "::", stringify!(len)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).offset) as usize - ptr as usize + }, + 8usize, + concat!("Offset of field: ", stringify!(A), "::", stringify!(offset)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize + }, + 16usize, + concat!("Offset of field: ", stringify!(A), "::", stringify!(next)) + ); } impl Default for A { fn default() -> Self { diff --git a/tests/expectations/tests/size_t_template.rs b/tests/expectations/tests/size_t_template.rs index 3c14d85727..3b0d34f38d 100644 --- a/tests/expectations/tests/size_t_template.rs +++ b/tests/expectations/tests/size_t_template.rs @@ -12,6 +12,8 @@ pub struct C { } #[test] fn bindgen_test_layout_C() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 12usize, @@ -22,16 +24,12 @@ fn bindgen_test_layout_C() { 4usize, concat!("Alignment of ", stringify!(C)) ); - fn test_field_arr() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(arr)) - ); - } - test_field_arr(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(arr)) + ); } diff --git a/tests/expectations/tests/struct_containing_forward_declared_struct.rs b/tests/expectations/tests/struct_containing_forward_declared_struct.rs index bd1419c6f1..3790427006 100644 --- a/tests/expectations/tests/struct_containing_forward_declared_struct.rs +++ b/tests/expectations/tests/struct_containing_forward_declared_struct.rs @@ -12,6 +12,8 @@ pub struct a { } #[test] fn bindgen_test_layout_a() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -22,23 +24,14 @@ fn bindgen_test_layout_a() { 8usize, concat!("Alignment of ", stringify!(a)) ); - fn test_field_val_a() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).val_a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(a), - "::", - stringify!(val_a) - ) - ); - } - test_field_val_a(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).val_a) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(a), "::", stringify!(val_a)) + ); } impl Default for a { fn default() -> Self { @@ -56,6 +49,8 @@ pub struct b { } #[test] fn bindgen_test_layout_b() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -66,21 +61,12 @@ fn bindgen_test_layout_b() { 4usize, concat!("Alignment of ", stringify!(b)) ); - fn test_field_val_b() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).val_b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(b), - "::", - stringify!(val_b) - ) - ); - } - test_field_val_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).val_b) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(b), "::", stringify!(val_b)) + ); } diff --git a/tests/expectations/tests/struct_typedef.rs b/tests/expectations/tests/struct_typedef.rs index 1eab593ebb..dfe4822c32 100644 --- a/tests/expectations/tests/struct_typedef.rs +++ b/tests/expectations/tests/struct_typedef.rs @@ -12,6 +12,8 @@ pub struct typedef_named_struct { } #[test] fn bindgen_test_layout_typedef_named_struct() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -22,24 +24,19 @@ fn bindgen_test_layout_typedef_named_struct() { 1usize, concat!("Alignment of ", stringify!(typedef_named_struct)) ); - fn test_field_has_name() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).has_name) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(typedef_named_struct), - "::", - stringify!(has_name) - ) - ); - } - test_field_has_name(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).has_name) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(typedef_named_struct), + "::", + stringify!(has_name) + ) + ); } #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] @@ -48,6 +45,8 @@ pub struct _bindgen_ty_1 { } #[test] fn bindgen_test_layout__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit<_bindgen_ty_1> = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::<_bindgen_ty_1>(), 8usize, @@ -58,23 +57,19 @@ fn bindgen_test_layout__bindgen_ty_1() { 8usize, concat!("Alignment of ", stringify!(_bindgen_ty_1)) ); - fn test_field_no_name() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::<_bindgen_ty_1>::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).no_name) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_bindgen_ty_1), - "::", - stringify!(no_name) - ) - ); - } - test_field_no_name(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).no_name) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_bindgen_ty_1), + "::", + stringify!(no_name) + ) + ); } impl Default for _bindgen_ty_1 { fn default() -> Self { diff --git a/tests/expectations/tests/struct_typedef_ns.rs b/tests/expectations/tests/struct_typedef_ns.rs index 8b113567ba..5ac7d9859b 100644 --- a/tests/expectations/tests/struct_typedef_ns.rs +++ b/tests/expectations/tests/struct_typedef_ns.rs @@ -19,6 +19,8 @@ pub mod root { } #[test] fn bindgen_test_layout_typedef_struct() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -29,24 +31,19 @@ pub mod root { 4usize, concat!("Alignment of ", stringify!(typedef_struct)) ); - fn test_field_foo() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(typedef_struct), - "::", - stringify!(foo) - ) - ); - } - test_field_foo(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(typedef_struct), + "::", + stringify!(foo) + ) + ); } #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] @@ -64,6 +61,8 @@ pub mod root { } #[test] fn bindgen_test_layout__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit<_bindgen_ty_1> = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::<_bindgen_ty_1>(), 4usize, @@ -74,24 +73,19 @@ pub mod root { 4usize, concat!("Alignment of ", stringify!(_bindgen_ty_1)) ); - fn test_field_foo() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::<_bindgen_ty_1>::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_bindgen_ty_1), - "::", - stringify!(foo) - ) - ); - } - test_field_foo(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_bindgen_ty_1), + "::", + stringify!(foo) + ) + ); } pub type typedef_struct = root::_bindgen_mod_id_12::_bindgen_ty_1; pub const _bindgen_mod_id_12_BAR: diff --git a/tests/expectations/tests/struct_with_anon_struct.rs b/tests/expectations/tests/struct_with_anon_struct.rs index 88e1d7b599..47193018cf 100644 --- a/tests/expectations/tests/struct_with_anon_struct.rs +++ b/tests/expectations/tests/struct_with_anon_struct.rs @@ -18,6 +18,8 @@ pub struct foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -28,45 +30,37 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - } - test_field_a(); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(b) + ) + ); } #[test] fn bindgen_test_layout_foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -77,21 +71,12 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - fn test_field_bar() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(bar) - ) - ); - } - test_field_bar(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) + ); } diff --git a/tests/expectations/tests/struct_with_anon_struct_array.rs b/tests/expectations/tests/struct_with_anon_struct_array.rs index b556699302..1470a9f2a2 100644 --- a/tests/expectations/tests/struct_with_anon_struct_array.rs +++ b/tests/expectations/tests/struct_with_anon_struct_array.rs @@ -19,6 +19,8 @@ pub struct foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -29,42 +31,32 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - } - test_field_a(); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(b) + ) + ); } #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] @@ -74,6 +66,8 @@ pub struct foo__bindgen_ty_2 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_2() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -84,45 +78,37 @@ fn bindgen_test_layout_foo__bindgen_ty_2() { 4usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_2)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_2), - "::", - stringify!(a) - ) - ); - } - test_field_a(); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_2), - "::", - stringify!(b) - ) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_2), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_2), + "::", + stringify!(b) + ) + ); } #[test] fn bindgen_test_layout_foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 208usize, @@ -133,38 +119,20 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - fn test_field_bar() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(bar) - ) - ); - } - test_field_bar(); - fn test_field_baz() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(baz) - ) - ); - } - test_field_baz(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, + 16usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(baz)) + ); } diff --git a/tests/expectations/tests/struct_with_anon_struct_pointer.rs b/tests/expectations/tests/struct_with_anon_struct_pointer.rs index 5050ef4598..77a2dcd5c0 100644 --- a/tests/expectations/tests/struct_with_anon_struct_pointer.rs +++ b/tests/expectations/tests/struct_with_anon_struct_pointer.rs @@ -18,6 +18,8 @@ pub struct foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -28,45 +30,37 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - } - test_field_a(); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(b) + ) + ); } #[test] fn bindgen_test_layout_foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -77,23 +71,14 @@ fn bindgen_test_layout_foo() { 8usize, concat!("Alignment of ", stringify!(foo)) ); - fn test_field_bar() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(bar) - ) - ); - } - test_field_bar(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) + ); } impl Default for foo { fn default() -> Self { diff --git a/tests/expectations/tests/struct_with_anon_union.rs b/tests/expectations/tests/struct_with_anon_union.rs index 37f07476fd..f97c5236f1 100644 --- a/tests/expectations/tests/struct_with_anon_union.rs +++ b/tests/expectations/tests/struct_with_anon_union.rs @@ -18,6 +18,8 @@ pub union foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -28,42 +30,32 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - } - test_field_a(); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(b) + ) + ); } impl Default for foo__bindgen_ty_1 { fn default() -> Self { @@ -76,6 +68,8 @@ impl Default for foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -86,23 +80,14 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - fn test_field_bar() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(bar) - ) - ); - } - test_field_bar(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) + ); } impl Default for foo { fn default() -> Self { diff --git a/tests/expectations/tests/struct_with_anon_union_1_0.rs b/tests/expectations/tests/struct_with_anon_union_1_0.rs index 03e0efc7d5..e6b6d4f772 100644 --- a/tests/expectations/tests/struct_with_anon_union_1_0.rs +++ b/tests/expectations/tests/struct_with_anon_union_1_0.rs @@ -62,6 +62,8 @@ pub struct foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -72,42 +74,32 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - } - test_field_a(); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(b) + ) + ); } impl Clone for foo__bindgen_ty_1 { fn clone(&self) -> Self { @@ -116,6 +108,8 @@ impl Clone for foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -126,23 +120,14 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - fn test_field_bar() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(bar) - ) - ); - } - test_field_bar(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) + ); } impl Clone for foo { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/struct_with_anon_unnamed_struct.rs b/tests/expectations/tests/struct_with_anon_unnamed_struct.rs index 8916bcd492..022f067fd1 100644 --- a/tests/expectations/tests/struct_with_anon_unnamed_struct.rs +++ b/tests/expectations/tests/struct_with_anon_unnamed_struct.rs @@ -18,6 +18,8 @@ pub struct foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -28,42 +30,32 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - } - test_field_a(); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(b) + ) + ); } #[test] fn bindgen_test_layout_foo() { diff --git a/tests/expectations/tests/struct_with_anon_unnamed_union.rs b/tests/expectations/tests/struct_with_anon_unnamed_union.rs index eb177c9bd5..f312ccd01e 100644 --- a/tests/expectations/tests/struct_with_anon_unnamed_union.rs +++ b/tests/expectations/tests/struct_with_anon_unnamed_union.rs @@ -18,6 +18,8 @@ pub union foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -28,42 +30,32 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - } - test_field_a(); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(b) + ) + ); } impl Default for foo__bindgen_ty_1 { fn default() -> Self { diff --git a/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs b/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs index 0098a4046f..b138ef0f92 100644 --- a/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs +++ b/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs @@ -62,6 +62,8 @@ pub struct foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -72,42 +74,32 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - } - test_field_a(); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(b) + ) + ); } impl Clone for foo__bindgen_ty_1 { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/struct_with_bitfields.rs b/tests/expectations/tests/struct_with_bitfields.rs index 00123956d8..921d6c8359 100644 --- a/tests/expectations/tests/struct_with_bitfields.rs +++ b/tests/expectations/tests/struct_with_bitfields.rs @@ -102,6 +102,8 @@ pub struct bitfield { } #[test] fn bindgen_test_layout_bitfield() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -112,23 +114,19 @@ fn bindgen_test_layout_bitfield() { 4usize, concat!("Alignment of ", stringify!(bitfield)) ); - fn test_field_e() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).e) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(bitfield), - "::", - stringify!(e) - ) - ); - } - test_field_e(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).e) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(bitfield), + "::", + stringify!(e) + ) + ); } impl bitfield { #[inline] diff --git a/tests/expectations/tests/struct_with_derive_debug.rs b/tests/expectations/tests/struct_with_derive_debug.rs index a2729bbeb8..890223ac99 100644 --- a/tests/expectations/tests/struct_with_derive_debug.rs +++ b/tests/expectations/tests/struct_with_derive_debug.rs @@ -12,6 +12,8 @@ pub struct LittleArray { } #[test] fn bindgen_test_layout_LittleArray() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 128usize, @@ -22,23 +24,19 @@ fn bindgen_test_layout_LittleArray() { 4usize, concat!("Alignment of ", stringify!(LittleArray)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(LittleArray), - "::", - stringify!(a) - ) - ); - } - test_field_a(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(LittleArray), + "::", + stringify!(a) + ) + ); } #[repr(C)] #[derive(Copy, Clone)] @@ -47,6 +45,8 @@ pub struct BigArray { } #[test] fn bindgen_test_layout_BigArray() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 132usize, @@ -57,23 +57,19 @@ fn bindgen_test_layout_BigArray() { 4usize, concat!("Alignment of ", stringify!(BigArray)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(BigArray), - "::", - stringify!(a) - ) - ); - } - test_field_a(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(BigArray), + "::", + stringify!(a) + ) + ); } impl Default for BigArray { fn default() -> Self { @@ -91,6 +87,8 @@ pub struct WithLittleArray { } #[test] fn bindgen_test_layout_WithLittleArray() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 128usize, @@ -101,24 +99,19 @@ fn bindgen_test_layout_WithLittleArray() { 4usize, concat!("Alignment of ", stringify!(WithLittleArray)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithLittleArray), - "::", - stringify!(a) - ) - ); - } - test_field_a(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithLittleArray), + "::", + stringify!(a) + ) + ); } #[repr(C)] #[derive(Copy, Clone)] @@ -127,6 +120,8 @@ pub struct WithBigArray { } #[test] fn bindgen_test_layout_WithBigArray() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 132usize, @@ -137,23 +132,19 @@ fn bindgen_test_layout_WithBigArray() { 4usize, concat!("Alignment of ", stringify!(WithBigArray)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigArray), - "::", - stringify!(a) - ) - ); - } - test_field_a(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithBigArray), + "::", + stringify!(a) + ) + ); } impl Default for WithBigArray { fn default() -> Self { diff --git a/tests/expectations/tests/struct_with_large_array.rs b/tests/expectations/tests/struct_with_large_array.rs index e792f71acc..1d98ae13c2 100644 --- a/tests/expectations/tests/struct_with_large_array.rs +++ b/tests/expectations/tests/struct_with_large_array.rs @@ -12,6 +12,8 @@ pub struct S { } #[test] fn bindgen_test_layout_S() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 33usize, @@ -22,23 +24,19 @@ fn bindgen_test_layout_S() { 1usize, concat!("Alignment of ", stringify!(S)) ); - fn test_field_large_array() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(S), - "::", - stringify!(large_array) - ) - ); - } - test_field_large_array(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(S), + "::", + stringify!(large_array) + ) + ); } impl Default for S { fn default() -> Self { diff --git a/tests/expectations/tests/struct_with_nesting.rs b/tests/expectations/tests/struct_with_nesting.rs index 5b98fc49c8..34d26f5f4f 100644 --- a/tests/expectations/tests/struct_with_nesting.rs +++ b/tests/expectations/tests/struct_with_nesting.rs @@ -26,6 +26,8 @@ pub struct foo__bindgen_ty_1__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -36,44 +38,32 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { 2usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)) ); - fn test_field_c1() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - foo__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).c1) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(c1) - ) - ); - } - test_field_c1(); - fn test_field_c2() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - foo__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).c2) as usize - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(c2) - ) - ); - } - test_field_c2(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).c1) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(c1) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).c2) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(c2) + ) + ); } #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] @@ -85,6 +75,8 @@ pub struct foo__bindgen_ty_1__bindgen_ty_2 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -95,85 +87,63 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { 1usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)) ); - fn test_field_d1() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - foo__bindgen_ty_1__bindgen_ty_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d1) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(d1) - ) - ); - } - test_field_d1(); - fn test_field_d2() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - foo__bindgen_ty_1__bindgen_ty_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d2) as usize - ptr as usize - }, - 1usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(d2) - ) - ); - } - test_field_d2(); - fn test_field_d3() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - foo__bindgen_ty_1__bindgen_ty_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d3) as usize - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(d3) - ) - ); - } - test_field_d3(); - fn test_field_d4() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - foo__bindgen_ty_1__bindgen_ty_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d4) as usize - ptr as usize - }, - 3usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(d4) - ) - ); - } - test_field_d4(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).d1) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(d1) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).d2) as usize - ptr as usize + }, + 1usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(d2) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).d3) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(d3) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).d4) as usize - ptr as usize + }, + 3usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(d4) + ) + ); } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -184,24 +154,19 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(b) + ) + ); } impl Default for foo__bindgen_ty_1 { fn default() -> Self { @@ -214,6 +179,8 @@ impl Default for foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -224,18 +191,14 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) - ); - } - test_field_a(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) + ); } impl Default for foo { fn default() -> Self { diff --git a/tests/expectations/tests/struct_with_nesting_1_0.rs b/tests/expectations/tests/struct_with_nesting_1_0.rs index 0a7e1ec992..e9acf62699 100644 --- a/tests/expectations/tests/struct_with_nesting_1_0.rs +++ b/tests/expectations/tests/struct_with_nesting_1_0.rs @@ -70,6 +70,8 @@ pub struct foo__bindgen_ty_1__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -80,44 +82,32 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { 2usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)) ); - fn test_field_c1() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - foo__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).c1) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(c1) - ) - ); - } - test_field_c1(); - fn test_field_c2() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - foo__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).c2) as usize - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(c2) - ) - ); - } - test_field_c2(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).c1) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(c1) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).c2) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(c2) + ) + ); } impl Clone for foo__bindgen_ty_1__bindgen_ty_1 { fn clone(&self) -> Self { @@ -134,6 +124,8 @@ pub struct foo__bindgen_ty_1__bindgen_ty_2 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -144,82 +136,58 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { 1usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)) ); - fn test_field_d1() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - foo__bindgen_ty_1__bindgen_ty_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d1) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(d1) - ) - ); - } - test_field_d1(); - fn test_field_d2() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - foo__bindgen_ty_1__bindgen_ty_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d2) as usize - ptr as usize - }, - 1usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(d2) - ) - ); - } - test_field_d2(); - fn test_field_d3() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - foo__bindgen_ty_1__bindgen_ty_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d3) as usize - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(d3) - ) - ); - } - test_field_d3(); - fn test_field_d4() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - foo__bindgen_ty_1__bindgen_ty_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d4) as usize - ptr as usize - }, - 3usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(d4) - ) - ); - } - test_field_d4(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).d1) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(d1) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).d2) as usize - ptr as usize + }, + 1usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(d2) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).d3) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(d3) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).d4) as usize - ptr as usize + }, + 3usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(d4) + ) + ); } impl Clone for foo__bindgen_ty_1__bindgen_ty_2 { fn clone(&self) -> Self { @@ -228,6 +196,8 @@ impl Clone for foo__bindgen_ty_1__bindgen_ty_2 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -238,24 +208,19 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(b) + ) + ); } impl Clone for foo__bindgen_ty_1 { fn clone(&self) -> Self { @@ -264,6 +229,8 @@ impl Clone for foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -274,18 +241,14 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) - ); - } - test_field_a(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) + ); } impl Clone for foo { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/struct_with_packing.rs b/tests/expectations/tests/struct_with_packing.rs index c82edf28b5..c34ea7bf7c 100644 --- a/tests/expectations/tests/struct_with_packing.rs +++ b/tests/expectations/tests/struct_with_packing.rs @@ -13,6 +13,8 @@ pub struct a { } #[test] fn bindgen_test_layout_a() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 3usize, @@ -23,28 +25,20 @@ fn bindgen_test_layout_a() { 1usize, concat!("Alignment of ", stringify!(a)) ); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(a), "::", stringify!(b)) - ); - } - test_field_b(); - fn test_field_c() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize - }, - 1usize, - concat!("Offset of field: ", stringify!(a), "::", stringify!(c)) - ); - } - test_field_c(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(a), "::", stringify!(b)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize + }, + 1usize, + concat!("Offset of field: ", stringify!(a), "::", stringify!(c)) + ); } diff --git a/tests/expectations/tests/struct_with_struct.rs b/tests/expectations/tests/struct_with_struct.rs index a8d0693786..a334d79c50 100644 --- a/tests/expectations/tests/struct_with_struct.rs +++ b/tests/expectations/tests/struct_with_struct.rs @@ -18,6 +18,8 @@ pub struct foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -28,45 +30,37 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - fn test_field_x() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(x) - ) - ); - } - test_field_x(); - fn test_field_y() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(y) - ) - ); - } - test_field_y(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(x) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(y) + ) + ); } #[test] fn bindgen_test_layout_foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -77,21 +71,12 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - fn test_field_bar() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(bar) - ) - ); - } - test_field_bar(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) + ); } diff --git a/tests/expectations/tests/template.rs b/tests/expectations/tests/template.rs index 4de7b7aad6..6b965f32c6 100644 --- a/tests/expectations/tests/template.rs +++ b/tests/expectations/tests/template.rs @@ -68,6 +68,8 @@ pub struct C { } #[test] fn bindgen_test_layout_C() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 104usize, @@ -78,276 +80,206 @@ fn bindgen_test_layout_C() { 8usize, concat!("Alignment of ", stringify!(C)) ); - fn test_field_mB() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mB) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(mB)) - ); - } - test_field_mB(); - fn test_field_mBConstPtr() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBConstPtr) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBConstPtr) - ) - ); - } - test_field_mBConstPtr(); - fn test_field_mBConstStructPtr() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBConstStructPtr) as usize - - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBConstStructPtr) - ) - ); - } - test_field_mBConstStructPtr(); - fn test_field_mBConstStructPtrArray() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBConstStructPtrArray) as usize - - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBConstStructPtrArray) - ) - ); - } - test_field_mBConstStructPtrArray(); - fn test_field_mBConst() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBConst) as usize - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBConst) - ) - ); - } - test_field_mBConst(); - fn test_field_mBVolatile() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBVolatile) as usize - ptr as usize - }, - 36usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBVolatile) - ) - ); - } - test_field_mBVolatile(); - fn test_field_mBConstBool() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBConstBool) as usize - ptr as usize - }, - 40usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBConstBool) - ) - ); - } - test_field_mBConstBool(); - fn test_field_mBConstChar() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBConstChar) as usize - ptr as usize - }, - 42usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBConstChar) - ) - ); - } - test_field_mBConstChar(); - fn test_field_mBArray() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBArray) as usize - ptr as usize - }, - 44usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBArray) - ) - ); - } - test_field_mBArray(); - fn test_field_mBPtrArray() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBPtrArray) as usize - ptr as usize - }, - 48usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBPtrArray) - ) - ); - } - test_field_mBPtrArray(); - fn test_field_mBArrayPtr() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBArrayPtr) as usize - ptr as usize - }, - 56usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBArrayPtr) - ) - ); - } - test_field_mBArrayPtr(); - fn test_field_mBRef() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBRef) as usize - ptr as usize - }, - 64usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBRef) - ) - ); - } - test_field_mBRef(); - fn test_field_mBConstRef() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBConstRef) as usize - ptr as usize - }, - 72usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBConstRef) - ) - ); - } - test_field_mBConstRef(); - fn test_field_mPtrRef() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mPtrRef) as usize - ptr as usize - }, - 80usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mPtrRef) - ) - ); - } - test_field_mPtrRef(); - fn test_field_mArrayRef() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mArrayRef) as usize - ptr as usize - }, - 88usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mArrayRef) - ) - ); - } - test_field_mArrayRef(); - fn test_field_mBConstArray() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBConstArray) as usize - - ptr as usize - }, - 96usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBConstArray) - ) - ); - } - test_field_mBConstArray(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mB) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(mB)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBConstPtr) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(mBConstPtr) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBConstStructPtr) as usize - + ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(mBConstStructPtr) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBConstStructPtrArray) as usize - + ptr as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(mBConstStructPtrArray) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBConst) as usize - ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(mBConst) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBVolatile) as usize - ptr as usize + }, + 36usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(mBVolatile) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBConstBool) as usize - ptr as usize + }, + 40usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(mBConstBool) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBConstChar) as usize - ptr as usize + }, + 42usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(mBConstChar) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBArray) as usize - ptr as usize + }, + 44usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(mBArray) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBPtrArray) as usize - ptr as usize + }, + 48usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(mBPtrArray) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBArrayPtr) as usize - ptr as usize + }, + 56usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(mBArrayPtr) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBRef) as usize - ptr as usize + }, + 64usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(mBRef)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBConstRef) as usize - ptr as usize + }, + 72usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(mBConstRef) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mPtrRef) as usize - ptr as usize + }, + 80usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(mPtrRef) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mArrayRef) as usize - ptr as usize + }, + 88usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(mArrayRef) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBConstArray) as usize - ptr as usize + }, + 96usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(mBConstArray) + ) + ); } impl Default for C { fn default() -> Self { @@ -413,6 +345,8 @@ pub struct RootedContainer { } #[test] fn bindgen_test_layout_RootedContainer() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 24usize, @@ -423,24 +357,19 @@ fn bindgen_test_layout_RootedContainer() { 8usize, concat!("Alignment of ", stringify!(RootedContainer)) ); - fn test_field_root() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).root) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(RootedContainer), - "::", - stringify!(root) - ) - ); - } - test_field_root(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).root) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(RootedContainer), + "::", + stringify!(root) + ) + ); } impl Default for RootedContainer { fn default() -> Self { @@ -474,6 +403,8 @@ pub struct PODButContainsDtor { } #[test] fn bindgen_test_layout_PODButContainsDtor() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -484,24 +415,19 @@ fn bindgen_test_layout_PODButContainsDtor() { 4usize, concat!("Alignment of ", stringify!(PODButContainsDtor)) ); - fn test_field_member() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(PODButContainsDtor), - "::", - stringify!(member) - ) - ); - } - test_field_member(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(PODButContainsDtor), + "::", + stringify!(member) + ) + ); } impl Default for PODButContainsDtor { fn default() -> Self { @@ -525,6 +451,8 @@ pub struct POD { } #[test] fn bindgen_test_layout_POD() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -535,24 +463,19 @@ fn bindgen_test_layout_POD() { 4usize, concat!("Alignment of ", stringify!(POD)) ); - fn test_field_opaque_member() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).opaque_member) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(POD), - "::", - stringify!(opaque_member) - ) - ); - } - test_field_opaque_member(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).opaque_member) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(POD), + "::", + stringify!(opaque_member) + ) + ); } ///
#[repr(C)] diff --git a/tests/expectations/tests/test_mixed_header_and_header_contents.rs b/tests/expectations/tests/test_mixed_header_and_header_contents.rs index 369d10d3ac..7475a5212b 100644 --- a/tests/expectations/tests/test_mixed_header_and_header_contents.rs +++ b/tests/expectations/tests/test_mixed_header_and_header_contents.rs @@ -33,6 +33,8 @@ pub struct Test { } #[test] fn bindgen_test_layout_Test() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 12usize, @@ -43,198 +45,105 @@ fn bindgen_test_layout_Test() { 1usize, concat!("Alignment of ", stringify!(Test)) ); - fn test_field_ch() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ch) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Test), - "::", - stringify!(ch) - ) - ); - } - test_field_ch(); - fn test_field_u() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize - }, - 1usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(u)) - ); - } - test_field_u(); - fn test_field_d() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, - 2usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(d)) - ); - } - test_field_d(); - fn test_field_cch() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).cch) as usize - ptr as usize - }, - 3usize, - concat!( - "Offset of field: ", - stringify!(Test), - "::", - stringify!(cch) - ) - ); - } - test_field_cch(); - fn test_field_cu() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).cu) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(Test), - "::", - stringify!(cu) - ) - ); - } - test_field_cu(); - fn test_field_cd() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).cd) as usize - ptr as usize - }, - 5usize, - concat!( - "Offset of field: ", - stringify!(Test), - "::", - stringify!(cd) - ) - ); - } - test_field_cd(); - fn test_field_Cch() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).Cch) as usize - ptr as usize - }, - 6usize, - concat!( - "Offset of field: ", - stringify!(Test), - "::", - stringify!(Cch) - ) - ); - } - test_field_Cch(); - fn test_field_Cu() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).Cu) as usize - ptr as usize - }, - 7usize, - concat!( - "Offset of field: ", - stringify!(Test), - "::", - stringify!(Cu) - ) - ); - } - test_field_Cu(); - fn test_field_Cd() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).Cd) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(Test), - "::", - stringify!(Cd) - ) - ); - } - test_field_Cd(); - fn test_field_Ccch() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).Ccch) as usize - ptr as usize - }, - 9usize, - concat!( - "Offset of field: ", - stringify!(Test), - "::", - stringify!(Ccch) - ) - ); - } - test_field_Ccch(); - fn test_field_Ccu() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).Ccu) as usize - ptr as usize - }, - 10usize, - concat!( - "Offset of field: ", - stringify!(Test), - "::", - stringify!(Ccu) - ) - ); - } - test_field_Ccu(); - fn test_field_Ccd() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).Ccd) as usize - ptr as usize - }, - 11usize, - concat!( - "Offset of field: ", - stringify!(Test), - "::", - stringify!(Ccd) - ) - ); - } - test_field_Ccd(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).ch) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(ch)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize + }, + 1usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(u)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, + 2usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(d)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).cch) as usize - ptr as usize + }, + 3usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(cch)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).cu) as usize - ptr as usize + }, + 4usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(cu)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).cd) as usize - ptr as usize + }, + 5usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(cd)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).Cch) as usize - ptr as usize + }, + 6usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cch)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).Cu) as usize - ptr as usize + }, + 7usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cu)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).Cd) as usize - ptr as usize + }, + 8usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cd)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).Ccch) as usize - ptr as usize + }, + 9usize, + concat!( + "Offset of field: ", + stringify!(Test), + "::", + stringify!(Ccch) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).Ccu) as usize - ptr as usize + }, + 10usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccu)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).Ccd) as usize - ptr as usize + }, + 11usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccd)) + ); } diff --git a/tests/expectations/tests/test_multiple_header_calls_in_builder.rs b/tests/expectations/tests/test_multiple_header_calls_in_builder.rs index b05dd971ea..a51a11f65c 100644 --- a/tests/expectations/tests/test_multiple_header_calls_in_builder.rs +++ b/tests/expectations/tests/test_multiple_header_calls_in_builder.rs @@ -27,6 +27,8 @@ pub struct Test { } #[test] fn bindgen_test_layout_Test() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 12usize, @@ -37,198 +39,105 @@ fn bindgen_test_layout_Test() { 1usize, concat!("Alignment of ", stringify!(Test)) ); - fn test_field_ch() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ch) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Test), - "::", - stringify!(ch) - ) - ); - } - test_field_ch(); - fn test_field_u() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize - }, - 1usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(u)) - ); - } - test_field_u(); - fn test_field_d() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, - 2usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(d)) - ); - } - test_field_d(); - fn test_field_cch() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).cch) as usize - ptr as usize - }, - 3usize, - concat!( - "Offset of field: ", - stringify!(Test), - "::", - stringify!(cch) - ) - ); - } - test_field_cch(); - fn test_field_cu() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).cu) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(Test), - "::", - stringify!(cu) - ) - ); - } - test_field_cu(); - fn test_field_cd() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).cd) as usize - ptr as usize - }, - 5usize, - concat!( - "Offset of field: ", - stringify!(Test), - "::", - stringify!(cd) - ) - ); - } - test_field_cd(); - fn test_field_Cch() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).Cch) as usize - ptr as usize - }, - 6usize, - concat!( - "Offset of field: ", - stringify!(Test), - "::", - stringify!(Cch) - ) - ); - } - test_field_Cch(); - fn test_field_Cu() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).Cu) as usize - ptr as usize - }, - 7usize, - concat!( - "Offset of field: ", - stringify!(Test), - "::", - stringify!(Cu) - ) - ); - } - test_field_Cu(); - fn test_field_Cd() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).Cd) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(Test), - "::", - stringify!(Cd) - ) - ); - } - test_field_Cd(); - fn test_field_Ccch() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).Ccch) as usize - ptr as usize - }, - 9usize, - concat!( - "Offset of field: ", - stringify!(Test), - "::", - stringify!(Ccch) - ) - ); - } - test_field_Ccch(); - fn test_field_Ccu() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).Ccu) as usize - ptr as usize - }, - 10usize, - concat!( - "Offset of field: ", - stringify!(Test), - "::", - stringify!(Ccu) - ) - ); - } - test_field_Ccu(); - fn test_field_Ccd() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).Ccd) as usize - ptr as usize - }, - 11usize, - concat!( - "Offset of field: ", - stringify!(Test), - "::", - stringify!(Ccd) - ) - ); - } - test_field_Ccd(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).ch) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(ch)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize + }, + 1usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(u)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, + 2usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(d)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).cch) as usize - ptr as usize + }, + 3usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(cch)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).cu) as usize - ptr as usize + }, + 4usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(cu)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).cd) as usize - ptr as usize + }, + 5usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(cd)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).Cch) as usize - ptr as usize + }, + 6usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cch)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).Cu) as usize - ptr as usize + }, + 7usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cu)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).Cd) as usize - ptr as usize + }, + 8usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cd)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).Ccch) as usize - ptr as usize + }, + 9usize, + concat!( + "Offset of field: ", + stringify!(Test), + "::", + stringify!(Ccch) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).Ccu) as usize - ptr as usize + }, + 10usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccu)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).Ccd) as usize - ptr as usize + }, + 11usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccd)) + ); } diff --git a/tests/expectations/tests/timex.rs b/tests/expectations/tests/timex.rs index 8f0677b160..916e4eec4f 100644 --- a/tests/expectations/tests/timex.rs +++ b/tests/expectations/tests/timex.rs @@ -100,6 +100,8 @@ pub struct timex { } #[test] fn bindgen_test_layout_timex() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 48usize, @@ -110,23 +112,19 @@ fn bindgen_test_layout_timex() { 4usize, concat!("Alignment of ", stringify!(timex)) ); - fn test_field_tai() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).tai) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(timex), - "::", - stringify!(tai) - ) - ); - } - test_field_tai(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).tai) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(timex), + "::", + stringify!(tai) + ) + ); } impl Default for timex { fn default() -> Self { @@ -146,6 +144,8 @@ pub struct timex_named { } #[test] fn bindgen_test_layout_timex_named() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 48usize, @@ -156,23 +156,19 @@ fn bindgen_test_layout_timex_named() { 4usize, concat!("Alignment of ", stringify!(timex_named)) ); - fn test_field_tai() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).tai) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(timex_named), - "::", - stringify!(tai) - ) - ); - } - test_field_tai(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).tai) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(timex_named), + "::", + stringify!(tai) + ) + ); } impl Default for timex_named { fn default() -> Self { diff --git a/tests/expectations/tests/type-referenced-by-allowlisted-function.rs b/tests/expectations/tests/type-referenced-by-allowlisted-function.rs index 421abdc940..0383e1ddd2 100644 --- a/tests/expectations/tests/type-referenced-by-allowlisted-function.rs +++ b/tests/expectations/tests/type-referenced-by-allowlisted-function.rs @@ -12,6 +12,8 @@ pub struct dl_phdr_info { } #[test] fn bindgen_test_layout_dl_phdr_info() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -22,23 +24,19 @@ fn bindgen_test_layout_dl_phdr_info() { 4usize, concat!("Alignment of ", stringify!(dl_phdr_info)) ); - fn test_field_x() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(dl_phdr_info), - "::", - stringify!(x) - ) - ); - } - test_field_x(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(dl_phdr_info), + "::", + stringify!(x) + ) + ); } extern "C" { pub fn dl_iterate_phdr(arg1: *mut dl_phdr_info) -> ::std::os::raw::c_int; diff --git a/tests/expectations/tests/typeref.rs b/tests/expectations/tests/typeref.rs index f4b048c636..ad1a976106 100644 --- a/tests/expectations/tests/typeref.rs +++ b/tests/expectations/tests/typeref.rs @@ -12,6 +12,8 @@ pub struct mozilla_FragmentOrURL { } #[test] fn bindgen_test_layout_mozilla_FragmentOrURL() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -22,24 +24,19 @@ fn bindgen_test_layout_mozilla_FragmentOrURL() { 1usize, concat!("Alignment of ", stringify!(mozilla_FragmentOrURL)) ); - fn test_field_mIsLocalRef() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mIsLocalRef) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(mozilla_FragmentOrURL), - "::", - stringify!(mIsLocalRef) - ) - ); - } - test_field_mIsLocalRef(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mIsLocalRef) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(mozilla_FragmentOrURL), + "::", + stringify!(mIsLocalRef) + ) + ); } #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] @@ -93,6 +90,8 @@ pub struct Bar { } #[test] fn bindgen_test_layout_Bar() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -103,23 +102,14 @@ fn bindgen_test_layout_Bar() { 8usize, concat!("Alignment of ", stringify!(Bar)) ); - fn test_field_mFoo() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mFoo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(mFoo) - ) - ); - } - test_field_mFoo(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mFoo) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(mFoo)) + ); } impl Default for Bar { fn default() -> Self { @@ -136,6 +126,8 @@ pub struct nsFoo { } #[test] fn bindgen_test_layout_nsFoo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -146,23 +138,19 @@ fn bindgen_test_layout_nsFoo() { 8usize, concat!("Alignment of ", stringify!(nsFoo)) ); - fn test_field_mBar() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsFoo), - "::", - stringify!(mBar) - ) - ); - } - test_field_mBar(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(nsFoo), + "::", + stringify!(mBar) + ) + ); } impl Default for nsFoo { fn default() -> Self { diff --git a/tests/expectations/tests/typeref_1_0.rs b/tests/expectations/tests/typeref_1_0.rs index 273a7741fd..c043b9e6b9 100644 --- a/tests/expectations/tests/typeref_1_0.rs +++ b/tests/expectations/tests/typeref_1_0.rs @@ -55,6 +55,8 @@ pub struct mozilla_FragmentOrURL { } #[test] fn bindgen_test_layout_mozilla_FragmentOrURL() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -65,24 +67,19 @@ fn bindgen_test_layout_mozilla_FragmentOrURL() { 1usize, concat!("Alignment of ", stringify!(mozilla_FragmentOrURL)) ); - fn test_field_mIsLocalRef() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mIsLocalRef) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(mozilla_FragmentOrURL), - "::", - stringify!(mIsLocalRef) - ) - ); - } - test_field_mIsLocalRef(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mIsLocalRef) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(mozilla_FragmentOrURL), + "::", + stringify!(mIsLocalRef) + ) + ); } impl Clone for mozilla_FragmentOrURL { fn clone(&self) -> Self { @@ -131,6 +128,8 @@ pub struct Bar { } #[test] fn bindgen_test_layout_Bar() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -141,23 +140,14 @@ fn bindgen_test_layout_Bar() { 8usize, concat!("Alignment of ", stringify!(Bar)) ); - fn test_field_mFoo() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mFoo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(mFoo) - ) - ); - } - test_field_mFoo(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mFoo) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(mFoo)) + ); } impl Clone for Bar { fn clone(&self) -> Self { @@ -180,6 +170,8 @@ pub struct nsFoo { } #[test] fn bindgen_test_layout_nsFoo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -190,23 +182,19 @@ fn bindgen_test_layout_nsFoo() { 8usize, concat!("Alignment of ", stringify!(nsFoo)) ); - fn test_field_mBar() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsFoo), - "::", - stringify!(mBar) - ) - ); - } - test_field_mBar(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(nsFoo), + "::", + stringify!(mBar) + ) + ); } impl Clone for nsFoo { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/underscore.rs b/tests/expectations/tests/underscore.rs index a9c20d0e62..8752d08e5e 100644 --- a/tests/expectations/tests/underscore.rs +++ b/tests/expectations/tests/underscore.rs @@ -13,6 +13,8 @@ pub struct ptr_t { } #[test] fn bindgen_test_layout_ptr_t() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -23,21 +25,12 @@ fn bindgen_test_layout_ptr_t() { 1usize, concat!("Alignment of ", stringify!(ptr_t)) ); - fn test_field__() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).__) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ptr_t), - "::", - stringify!(__) - ) - ); - } - test_field__(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).__) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(ptr_t), "::", stringify!(__)) + ); } diff --git a/tests/expectations/tests/union-align.rs b/tests/expectations/tests/union-align.rs index 53701694c7..4c2f8ba5c2 100644 --- a/tests/expectations/tests/union-align.rs +++ b/tests/expectations/tests/union-align.rs @@ -13,6 +13,8 @@ pub union Bar { } #[test] fn bindgen_test_layout_Bar() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -23,23 +25,14 @@ fn bindgen_test_layout_Bar() { 16usize, concat!("Alignment of ", stringify!(Bar)) ); - fn test_field_foo() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(foo) - ) - ); - } - test_field_foo(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(foo)) + ); } impl Default for Bar { fn default() -> Self { @@ -58,6 +51,8 @@ pub union Baz { } #[test] fn bindgen_test_layout_Baz() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -68,23 +63,14 @@ fn bindgen_test_layout_Baz() { 16usize, concat!("Alignment of ", stringify!(Baz)) ); - fn test_field_bar() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Baz), - "::", - stringify!(bar) - ) - ); - } - test_field_bar(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Baz), "::", stringify!(bar)) + ); } impl Default for Baz { fn default() -> Self { diff --git a/tests/expectations/tests/union-in-ns.rs b/tests/expectations/tests/union-in-ns.rs index 28e7fa2334..27ade8e277 100644 --- a/tests/expectations/tests/union-in-ns.rs +++ b/tests/expectations/tests/union-in-ns.rs @@ -16,6 +16,8 @@ pub mod root { } #[test] fn bindgen_test_layout_bar() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -26,23 +28,19 @@ pub mod root { 4usize, concat!("Alignment of ", stringify!(bar)) ); - fn test_field_baz() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(baz) - ) - ); - } - test_field_baz(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(bar), + "::", + stringify!(baz) + ) + ); } impl Default for bar { fn default() -> Self { diff --git a/tests/expectations/tests/union-in-ns_1_0.rs b/tests/expectations/tests/union-in-ns_1_0.rs index 2d0584a61a..d81d22a2e7 100644 --- a/tests/expectations/tests/union-in-ns_1_0.rs +++ b/tests/expectations/tests/union-in-ns_1_0.rs @@ -63,6 +63,8 @@ pub mod root { } #[test] fn bindgen_test_layout_bar() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -73,23 +75,19 @@ pub mod root { 4usize, concat!("Alignment of ", stringify!(bar)) ); - fn test_field_baz() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(baz) - ) - ); - } - test_field_baz(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(bar), + "::", + stringify!(baz) + ) + ); } impl Clone for bar { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/union_dtor.rs b/tests/expectations/tests/union_dtor.rs index 359005cb4a..95216024db 100644 --- a/tests/expectations/tests/union_dtor.rs +++ b/tests/expectations/tests/union_dtor.rs @@ -12,6 +12,8 @@ pub union UnionWithDtor { } #[test] fn bindgen_test_layout_UnionWithDtor() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -22,40 +24,32 @@ fn bindgen_test_layout_UnionWithDtor() { 8usize, concat!("Alignment of ", stringify!(UnionWithDtor)) ); - fn test_field_mFoo() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mFoo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(UnionWithDtor), - "::", - stringify!(mFoo) - ) - ); - } - test_field_mFoo(); - fn test_field_mBar() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(UnionWithDtor), - "::", - stringify!(mBar) - ) - ); - } - test_field_mBar(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mFoo) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(UnionWithDtor), + "::", + stringify!(mFoo) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(UnionWithDtor), + "::", + stringify!(mBar) + ) + ); } extern "C" { #[link_name = "\u{1}_ZN13UnionWithDtorD1Ev"] diff --git a/tests/expectations/tests/union_dtor_1_0.rs b/tests/expectations/tests/union_dtor_1_0.rs index 68ebced57c..3579cb64bd 100644 --- a/tests/expectations/tests/union_dtor_1_0.rs +++ b/tests/expectations/tests/union_dtor_1_0.rs @@ -57,6 +57,8 @@ pub struct UnionWithDtor { } #[test] fn bindgen_test_layout_UnionWithDtor() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -67,40 +69,32 @@ fn bindgen_test_layout_UnionWithDtor() { 8usize, concat!("Alignment of ", stringify!(UnionWithDtor)) ); - fn test_field_mFoo() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mFoo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(UnionWithDtor), - "::", - stringify!(mFoo) - ) - ); - } - test_field_mFoo(); - fn test_field_mBar() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(UnionWithDtor), - "::", - stringify!(mBar) - ) - ); - } - test_field_mBar(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mFoo) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(UnionWithDtor), + "::", + stringify!(mFoo) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mBar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(UnionWithDtor), + "::", + stringify!(mBar) + ) + ); } extern "C" { #[link_name = "\u{1}_ZN13UnionWithDtorD1Ev"] diff --git a/tests/expectations/tests/union_fields.rs b/tests/expectations/tests/union_fields.rs index 7864ac15b1..af1b1626a9 100644 --- a/tests/expectations/tests/union_fields.rs +++ b/tests/expectations/tests/union_fields.rs @@ -14,6 +14,8 @@ pub union nsStyleUnion { } #[test] fn bindgen_test_layout_nsStyleUnion() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -24,57 +26,45 @@ fn bindgen_test_layout_nsStyleUnion() { 8usize, concat!("Alignment of ", stringify!(nsStyleUnion)) ); - fn test_field_mInt() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mInt) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsStyleUnion), - "::", - stringify!(mInt) - ) - ); - } - test_field_mInt(); - fn test_field_mFloat() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mFloat) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsStyleUnion), - "::", - stringify!(mFloat) - ) - ); - } - test_field_mFloat(); - fn test_field_mPointer() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mPointer) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsStyleUnion), - "::", - stringify!(mPointer) - ) - ); - } - test_field_mPointer(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mInt) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(nsStyleUnion), + "::", + stringify!(mInt) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mFloat) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(nsStyleUnion), + "::", + stringify!(mFloat) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mPointer) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(nsStyleUnion), + "::", + stringify!(mPointer) + ) + ); } impl Default for nsStyleUnion { fn default() -> Self { diff --git a/tests/expectations/tests/union_fields_1_0.rs b/tests/expectations/tests/union_fields_1_0.rs index 5fccd4e1d4..c575efb8b4 100644 --- a/tests/expectations/tests/union_fields_1_0.rs +++ b/tests/expectations/tests/union_fields_1_0.rs @@ -58,6 +58,8 @@ pub struct nsStyleUnion { } #[test] fn bindgen_test_layout_nsStyleUnion() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -68,57 +70,45 @@ fn bindgen_test_layout_nsStyleUnion() { 8usize, concat!("Alignment of ", stringify!(nsStyleUnion)) ); - fn test_field_mInt() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mInt) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsStyleUnion), - "::", - stringify!(mInt) - ) - ); - } - test_field_mInt(); - fn test_field_mFloat() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mFloat) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsStyleUnion), - "::", - stringify!(mFloat) - ) - ); - } - test_field_mFloat(); - fn test_field_mPointer() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mPointer) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsStyleUnion), - "::", - stringify!(mPointer) - ) - ); - } - test_field_mPointer(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mInt) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(nsStyleUnion), + "::", + stringify!(mInt) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mFloat) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(nsStyleUnion), + "::", + stringify!(mFloat) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mPointer) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(nsStyleUnion), + "::", + stringify!(mPointer) + ) + ); } impl Clone for nsStyleUnion { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/union_with_anon_struct.rs b/tests/expectations/tests/union_with_anon_struct.rs index 7a67b2d618..f2502fc07a 100644 --- a/tests/expectations/tests/union_with_anon_struct.rs +++ b/tests/expectations/tests/union_with_anon_struct.rs @@ -18,6 +18,8 @@ pub struct foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -28,45 +30,37 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - } - test_field_a(); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(b) + ) + ); } #[test] fn bindgen_test_layout_foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -77,23 +71,14 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - fn test_field_bar() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(bar) - ) - ); - } - test_field_bar(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) + ); } impl Default for foo { fn default() -> Self { diff --git a/tests/expectations/tests/union_with_anon_struct_1_0.rs b/tests/expectations/tests/union_with_anon_struct_1_0.rs index aed67ec68b..6136653960 100644 --- a/tests/expectations/tests/union_with_anon_struct_1_0.rs +++ b/tests/expectations/tests/union_with_anon_struct_1_0.rs @@ -62,6 +62,8 @@ pub struct foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -72,42 +74,32 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - } - test_field_a(); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(b) + ) + ); } impl Clone for foo__bindgen_ty_1 { fn clone(&self) -> Self { @@ -116,6 +108,8 @@ impl Clone for foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -126,23 +120,14 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - fn test_field_bar() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(bar) - ) - ); - } - test_field_bar(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) + ); } impl Clone for foo { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/union_with_anon_struct_bitfield.rs b/tests/expectations/tests/union_with_anon_struct_bitfield.rs index 87186fe04f..ccceca2464 100644 --- a/tests/expectations/tests/union_with_anon_struct_bitfield.rs +++ b/tests/expectations/tests/union_with_anon_struct_bitfield.rs @@ -164,6 +164,8 @@ impl foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -174,18 +176,14 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) - ); - } - test_field_a(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) + ); } impl Default for foo { fn default() -> Self { diff --git a/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs b/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs index 66f3367461..0a8c2aeadc 100644 --- a/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs +++ b/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs @@ -213,6 +213,8 @@ impl foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -223,18 +225,14 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) - ); - } - test_field_a(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) + ); } impl Clone for foo { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/union_with_anon_union.rs b/tests/expectations/tests/union_with_anon_union.rs index 789fb495be..063fa54630 100644 --- a/tests/expectations/tests/union_with_anon_union.rs +++ b/tests/expectations/tests/union_with_anon_union.rs @@ -18,6 +18,8 @@ pub union foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -28,42 +30,32 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - } - test_field_a(); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(b) + ) + ); } impl Default for foo__bindgen_ty_1 { fn default() -> Self { @@ -76,6 +68,8 @@ impl Default for foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -86,23 +80,14 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - fn test_field_bar() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(bar) - ) - ); - } - test_field_bar(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) + ); } impl Default for foo { fn default() -> Self { diff --git a/tests/expectations/tests/union_with_anon_union_1_0.rs b/tests/expectations/tests/union_with_anon_union_1_0.rs index 4bb91cf370..c366fac02a 100644 --- a/tests/expectations/tests/union_with_anon_union_1_0.rs +++ b/tests/expectations/tests/union_with_anon_union_1_0.rs @@ -63,6 +63,8 @@ pub struct foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -73,42 +75,32 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 4usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - } - test_field_a(); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(b) + ) + ); } impl Clone for foo__bindgen_ty_1 { fn clone(&self) -> Self { @@ -117,6 +109,8 @@ impl Clone for foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -127,23 +121,14 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - fn test_field_bar() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(bar) - ) - ); - } - test_field_bar(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) + ); } impl Clone for foo { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/union_with_anon_unnamed_struct.rs b/tests/expectations/tests/union_with_anon_unnamed_struct.rs index 968e20fac5..d1aec85312 100644 --- a/tests/expectations/tests/union_with_anon_unnamed_struct.rs +++ b/tests/expectations/tests/union_with_anon_unnamed_struct.rs @@ -21,6 +21,8 @@ pub struct pixel__bindgen_ty_1 { } #[test] fn bindgen_test_layout_pixel__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -31,81 +33,63 @@ fn bindgen_test_layout_pixel__bindgen_ty_1() { 1usize, concat!("Alignment of ", stringify!(pixel__bindgen_ty_1)) ); - fn test_field_r() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).r) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(pixel__bindgen_ty_1), - "::", - stringify!(r) - ) - ); - } - test_field_r(); - fn test_field_g() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).g) as usize - ptr as usize - }, - 1usize, - concat!( - "Offset of field: ", - stringify!(pixel__bindgen_ty_1), - "::", - stringify!(g) - ) - ); - } - test_field_g(); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(pixel__bindgen_ty_1), - "::", - stringify!(b) - ) - ); - } - test_field_b(); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 3usize, - concat!( - "Offset of field: ", - stringify!(pixel__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - } - test_field_a(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).r) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(pixel__bindgen_ty_1), + "::", + stringify!(r) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).g) as usize - ptr as usize + }, + 1usize, + concat!( + "Offset of field: ", + stringify!(pixel__bindgen_ty_1), + "::", + stringify!(g) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(pixel__bindgen_ty_1), + "::", + stringify!(b) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 3usize, + concat!( + "Offset of field: ", + stringify!(pixel__bindgen_ty_1), + "::", + stringify!(a) + ) + ); } #[test] fn bindgen_test_layout_pixel() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -116,23 +100,19 @@ fn bindgen_test_layout_pixel() { 4usize, concat!("Alignment of ", stringify!(pixel)) ); - fn test_field_rgba() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rgba) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(pixel), - "::", - stringify!(rgba) - ) - ); - } - test_field_rgba(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).rgba) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(pixel), + "::", + stringify!(rgba) + ) + ); } impl Default for pixel { fn default() -> Self { diff --git a/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs b/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs index b6f315bf1d..cc4117f68e 100644 --- a/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs +++ b/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs @@ -65,6 +65,8 @@ pub struct pixel__bindgen_ty_1 { } #[test] fn bindgen_test_layout_pixel__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -75,78 +77,58 @@ fn bindgen_test_layout_pixel__bindgen_ty_1() { 1usize, concat!("Alignment of ", stringify!(pixel__bindgen_ty_1)) ); - fn test_field_r() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).r) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(pixel__bindgen_ty_1), - "::", - stringify!(r) - ) - ); - } - test_field_r(); - fn test_field_g() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).g) as usize - ptr as usize - }, - 1usize, - concat!( - "Offset of field: ", - stringify!(pixel__bindgen_ty_1), - "::", - stringify!(g) - ) - ); - } - test_field_g(); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(pixel__bindgen_ty_1), - "::", - stringify!(b) - ) - ); - } - test_field_b(); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 3usize, - concat!( - "Offset of field: ", - stringify!(pixel__bindgen_ty_1), - "::", - stringify!(a) - ) - ); - } - test_field_a(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).r) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(pixel__bindgen_ty_1), + "::", + stringify!(r) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).g) as usize - ptr as usize + }, + 1usize, + concat!( + "Offset of field: ", + stringify!(pixel__bindgen_ty_1), + "::", + stringify!(g) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(pixel__bindgen_ty_1), + "::", + stringify!(b) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 3usize, + concat!( + "Offset of field: ", + stringify!(pixel__bindgen_ty_1), + "::", + stringify!(a) + ) + ); } impl Clone for pixel__bindgen_ty_1 { fn clone(&self) -> Self { @@ -155,6 +137,8 @@ impl Clone for pixel__bindgen_ty_1 { } #[test] fn bindgen_test_layout_pixel() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -165,23 +149,19 @@ fn bindgen_test_layout_pixel() { 4usize, concat!("Alignment of ", stringify!(pixel)) ); - fn test_field_rgba() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).rgba) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(pixel), - "::", - stringify!(rgba) - ) - ); - } - test_field_rgba(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).rgba) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(pixel), + "::", + stringify!(rgba) + ) + ); } impl Clone for pixel { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/union_with_anon_unnamed_union.rs b/tests/expectations/tests/union_with_anon_unnamed_union.rs index f7defd0654..9da74dfc79 100644 --- a/tests/expectations/tests/union_with_anon_unnamed_union.rs +++ b/tests/expectations/tests/union_with_anon_unnamed_union.rs @@ -19,6 +19,8 @@ pub union foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 2usize, @@ -29,42 +31,32 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 2usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); - } - test_field_b(); - fn test_field_c() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(c) - ) - ); - } - test_field_c(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(b) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(c) + ) + ); } impl Default for foo__bindgen_ty_1 { fn default() -> Self { @@ -77,6 +69,8 @@ impl Default for foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -87,18 +81,14 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) - ); - } - test_field_a(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) + ); } impl Default for foo { fn default() -> Self { diff --git a/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs b/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs index 72239a304e..4f3d711cad 100644 --- a/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs +++ b/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs @@ -64,6 +64,8 @@ pub struct foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 2usize, @@ -74,42 +76,32 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 2usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) - ); - } - test_field_b(); - fn test_field_c() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(c) - ) - ); - } - test_field_c(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(b) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1), + "::", + stringify!(c) + ) + ); } impl Clone for foo__bindgen_ty_1 { fn clone(&self) -> Self { @@ -118,6 +110,8 @@ impl Clone for foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -128,18 +122,14 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) - ); - } - test_field_a(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) + ); } impl Clone for foo { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/union_with_big_member.rs b/tests/expectations/tests/union_with_big_member.rs index 72210c8367..f80cba6325 100644 --- a/tests/expectations/tests/union_with_big_member.rs +++ b/tests/expectations/tests/union_with_big_member.rs @@ -13,6 +13,8 @@ pub union WithBigArray { } #[test] fn bindgen_test_layout_WithBigArray() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 132usize, @@ -23,40 +25,32 @@ fn bindgen_test_layout_WithBigArray() { 4usize, concat!("Alignment of ", stringify!(WithBigArray)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigArray), - "::", - stringify!(a) - ) - ); - } - test_field_a(); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigArray), - "::", - stringify!(b) - ) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithBigArray), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithBigArray), + "::", + stringify!(b) + ) + ); } impl Default for WithBigArray { fn default() -> Self { @@ -75,6 +69,8 @@ pub union WithBigArray2 { } #[test] fn bindgen_test_layout_WithBigArray2() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 36usize, @@ -85,40 +81,32 @@ fn bindgen_test_layout_WithBigArray2() { 4usize, concat!("Alignment of ", stringify!(WithBigArray2)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigArray2), - "::", - stringify!(a) - ) - ); - } - test_field_a(); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigArray2), - "::", - stringify!(b) - ) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithBigArray2), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithBigArray2), + "::", + stringify!(b) + ) + ); } impl Default for WithBigArray2 { fn default() -> Self { @@ -137,6 +125,8 @@ pub union WithBigMember { } #[test] fn bindgen_test_layout_WithBigMember() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 132usize, @@ -147,40 +137,32 @@ fn bindgen_test_layout_WithBigMember() { 4usize, concat!("Alignment of ", stringify!(WithBigMember)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigMember), - "::", - stringify!(a) - ) - ); - } - test_field_a(); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigMember), - "::", - stringify!(b) - ) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithBigMember), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithBigMember), + "::", + stringify!(b) + ) + ); } impl Default for WithBigMember { fn default() -> Self { diff --git a/tests/expectations/tests/union_with_big_member_1_0.rs b/tests/expectations/tests/union_with_big_member_1_0.rs index 8be46be7bf..4cb330bf27 100644 --- a/tests/expectations/tests/union_with_big_member_1_0.rs +++ b/tests/expectations/tests/union_with_big_member_1_0.rs @@ -57,6 +57,8 @@ pub struct WithBigArray { } #[test] fn bindgen_test_layout_WithBigArray() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 132usize, @@ -67,40 +69,32 @@ fn bindgen_test_layout_WithBigArray() { 4usize, concat!("Alignment of ", stringify!(WithBigArray)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigArray), - "::", - stringify!(a) - ) - ); - } - test_field_a(); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigArray), - "::", - stringify!(b) - ) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithBigArray), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithBigArray), + "::", + stringify!(b) + ) + ); } impl Clone for WithBigArray { fn clone(&self) -> Self { @@ -125,6 +119,8 @@ pub struct WithBigArray2 { } #[test] fn bindgen_test_layout_WithBigArray2() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 36usize, @@ -135,40 +131,32 @@ fn bindgen_test_layout_WithBigArray2() { 4usize, concat!("Alignment of ", stringify!(WithBigArray2)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigArray2), - "::", - stringify!(a) - ) - ); - } - test_field_a(); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigArray2), - "::", - stringify!(b) - ) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithBigArray2), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithBigArray2), + "::", + stringify!(b) + ) + ); } impl Clone for WithBigArray2 { fn clone(&self) -> Self { @@ -184,6 +172,8 @@ pub struct WithBigMember { } #[test] fn bindgen_test_layout_WithBigMember() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 132usize, @@ -194,40 +184,32 @@ fn bindgen_test_layout_WithBigMember() { 4usize, concat!("Alignment of ", stringify!(WithBigMember)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigMember), - "::", - stringify!(a) - ) - ); - } - test_field_a(); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigMember), - "::", - stringify!(b) - ) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithBigMember), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithBigMember), + "::", + stringify!(b) + ) + ); } impl Clone for WithBigMember { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/union_with_nesting.rs b/tests/expectations/tests/union_with_nesting.rs index 3ef99f7faa..c399b633a4 100644 --- a/tests/expectations/tests/union_with_nesting.rs +++ b/tests/expectations/tests/union_with_nesting.rs @@ -25,6 +25,8 @@ pub union foo__bindgen_ty_1__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 2usize, @@ -35,44 +37,32 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { 2usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)) ); - fn test_field_b1() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - foo__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b1) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(b1) - ) - ); - } - test_field_b1(); - fn test_field_b2() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - foo__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b2) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(b2) - ) - ); - } - test_field_b2(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b1) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(b1) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b2) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(b2) + ) + ); } impl Default for foo__bindgen_ty_1__bindgen_ty_1 { fn default() -> Self { @@ -91,6 +81,8 @@ pub union foo__bindgen_ty_1__bindgen_ty_2 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 2usize, @@ -101,44 +93,32 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { 2usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)) ); - fn test_field_c1() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - foo__bindgen_ty_1__bindgen_ty_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).c1) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(c1) - ) - ); - } - test_field_c1(); - fn test_field_c2() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - foo__bindgen_ty_1__bindgen_ty_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).c2) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(c2) - ) - ); - } - test_field_c2(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).c1) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(c1) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).c2) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(c2) + ) + ); } impl Default for foo__bindgen_ty_1__bindgen_ty_2 { fn default() -> Self { @@ -173,6 +153,8 @@ impl Default for foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -183,18 +165,14 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) - ); - } - test_field_a(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) + ); } impl Default for foo { fn default() -> Self { diff --git a/tests/expectations/tests/union_with_nesting_1_0.rs b/tests/expectations/tests/union_with_nesting_1_0.rs index 9d4fc4d25a..2bc3097757 100644 --- a/tests/expectations/tests/union_with_nesting_1_0.rs +++ b/tests/expectations/tests/union_with_nesting_1_0.rs @@ -70,6 +70,8 @@ pub struct foo__bindgen_ty_1__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 2usize, @@ -80,44 +82,32 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { 2usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)) ); - fn test_field_b1() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - foo__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b1) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(b1) - ) - ); - } - test_field_b1(); - fn test_field_b2() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - foo__bindgen_ty_1__bindgen_ty_1, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b2) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(b2) - ) - ); - } - test_field_b2(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b1) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(b1) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b2) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(b2) + ) + ); } impl Clone for foo__bindgen_ty_1__bindgen_ty_1 { fn clone(&self) -> Self { @@ -133,6 +123,8 @@ pub struct foo__bindgen_ty_1__bindgen_ty_2 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 2usize, @@ -143,44 +135,32 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { 2usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)) ); - fn test_field_c1() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - foo__bindgen_ty_1__bindgen_ty_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).c1) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(c1) - ) - ); - } - test_field_c1(); - fn test_field_c2() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - foo__bindgen_ty_1__bindgen_ty_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).c2) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(c2) - ) - ); - } - test_field_c2(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).c1) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(c1) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).c2) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(c2) + ) + ); } impl Clone for foo__bindgen_ty_1__bindgen_ty_2 { fn clone(&self) -> Self { @@ -207,6 +187,8 @@ impl Clone for foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -217,18 +199,14 @@ fn bindgen_test_layout_foo() { 4usize, concat!("Alignment of ", stringify!(foo)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) - ); - } - test_field_a(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) + ); } impl Clone for foo { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/unknown_attr.rs b/tests/expectations/tests/unknown_attr.rs index cc29d8b3a9..a48e9733f5 100644 --- a/tests/expectations/tests/unknown_attr.rs +++ b/tests/expectations/tests/unknown_attr.rs @@ -15,6 +15,8 @@ pub struct max_align_t { } #[test] fn bindgen_test_layout_max_align_t() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 32usize, @@ -25,40 +27,32 @@ fn bindgen_test_layout_max_align_t() { 16usize, concat!("Alignment of ", stringify!(max_align_t)) ); - fn test_field___clang_max_align_nonce1() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).__clang_max_align_nonce1) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(max_align_t), - "::", - stringify!(__clang_max_align_nonce1) - ) - ); - } - test_field___clang_max_align_nonce1(); - fn test_field___clang_max_align_nonce2() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).__clang_max_align_nonce2) as usize - - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(max_align_t), - "::", - stringify!(__clang_max_align_nonce2) - ) - ); - } - test_field___clang_max_align_nonce2(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).__clang_max_align_nonce1) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(max_align_t), + "::", + stringify!(__clang_max_align_nonce1) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).__clang_max_align_nonce2) as usize - + ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(max_align_t), + "::", + stringify!(__clang_max_align_nonce2) + ) + ); } diff --git a/tests/expectations/tests/use-core.rs b/tests/expectations/tests/use-core.rs index cc58821943..b2a7d30350 100644 --- a/tests/expectations/tests/use-core.rs +++ b/tests/expectations/tests/use-core.rs @@ -16,6 +16,8 @@ pub struct foo { } #[test] fn bindgen_test_layout_foo() { + const UNINIT: ::core::mem::MaybeUninit = + ::core::mem::MaybeUninit::uninit(); assert_eq!( ::core::mem::size_of::(), 16usize, @@ -26,47 +28,30 @@ fn bindgen_test_layout_foo() { 8usize, concat!("Alignment of ", stringify!(foo)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::core::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::core::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) - ); - } - test_field_a(); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = ::core::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::core::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 4usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) - ); - } - test_field_b(); - fn test_field_bar() { - assert_eq!( - unsafe { - let uninit = ::core::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(bar) - ) - ); - } - test_field_bar(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::core::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::core::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 4usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 8usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) + ); } impl Default for foo { fn default() -> Self { @@ -85,6 +70,8 @@ pub union _bindgen_ty_1 { } #[test] fn bindgen_test_layout__bindgen_ty_1() { + const UNINIT: ::core::mem::MaybeUninit<_bindgen_ty_1> = + ::core::mem::MaybeUninit::uninit(); assert_eq!( ::core::mem::size_of::<_bindgen_ty_1>(), 8usize, @@ -95,42 +82,32 @@ fn bindgen_test_layout__bindgen_ty_1() { 8usize, concat!("Alignment of ", stringify!(_bindgen_ty_1)) ); - fn test_field_bar() { - assert_eq!( - unsafe { - let uninit = - ::core::mem::MaybeUninit::<_bindgen_ty_1>::uninit(); - let ptr = uninit.as_ptr(); - ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_bindgen_ty_1), - "::", - stringify!(bar) - ) - ); - } - test_field_bar(); - fn test_field_baz() { - assert_eq!( - unsafe { - let uninit = - ::core::mem::MaybeUninit::<_bindgen_ty_1>::uninit(); - let ptr = uninit.as_ptr(); - ::core::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_bindgen_ty_1), - "::", - stringify!(baz) - ) - ); - } - test_field_baz(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_bindgen_ty_1), + "::", + stringify!(bar) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::core::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_bindgen_ty_1), + "::", + stringify!(baz) + ) + ); } impl Default for _bindgen_ty_1 { fn default() -> Self { diff --git a/tests/expectations/tests/use-core_1_0.rs b/tests/expectations/tests/use-core_1_0.rs index bb5ce95734..ca85287180 100644 --- a/tests/expectations/tests/use-core_1_0.rs +++ b/tests/expectations/tests/use-core_1_0.rs @@ -59,6 +59,8 @@ pub struct foo { } #[test] fn bindgen_test_layout_foo() { + const UNINIT: ::core::mem::MaybeUninit = + ::core::mem::MaybeUninit::uninit(); assert_eq!( ::core::mem::size_of::(), 16usize, @@ -69,47 +71,30 @@ fn bindgen_test_layout_foo() { 8usize, concat!("Alignment of ", stringify!(foo)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::core::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::core::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) - ); - } - test_field_a(); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = ::core::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::core::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 4usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) - ); - } - test_field_b(); - fn test_field_bar() { - assert_eq!( - unsafe { - let uninit = ::core::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(bar) - ) - ); - } - test_field_bar(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::core::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::core::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 4usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 8usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) + ); } impl Clone for foo { fn clone(&self) -> Self { @@ -134,6 +119,8 @@ pub struct _bindgen_ty_1 { } #[test] fn bindgen_test_layout__bindgen_ty_1() { + const UNINIT: ::core::mem::MaybeUninit<_bindgen_ty_1> = + ::core::mem::MaybeUninit::uninit(); assert_eq!( ::core::mem::size_of::<_bindgen_ty_1>(), 8usize, @@ -144,42 +131,32 @@ fn bindgen_test_layout__bindgen_ty_1() { 8usize, concat!("Alignment of ", stringify!(_bindgen_ty_1)) ); - fn test_field_bar() { - assert_eq!( - unsafe { - let uninit = - ::core::mem::MaybeUninit::<_bindgen_ty_1>::uninit(); - let ptr = uninit.as_ptr(); - ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_bindgen_ty_1), - "::", - stringify!(bar) - ) - ); - } - test_field_bar(); - fn test_field_baz() { - assert_eq!( - unsafe { - let uninit = - ::core::mem::MaybeUninit::<_bindgen_ty_1>::uninit(); - let ptr = uninit.as_ptr(); - ::core::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_bindgen_ty_1), - "::", - stringify!(baz) - ) - ); - } - test_field_baz(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_bindgen_ty_1), + "::", + stringify!(bar) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::core::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_bindgen_ty_1), + "::", + stringify!(baz) + ) + ); } impl Clone for _bindgen_ty_1 { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/var-tracing.rs b/tests/expectations/tests/var-tracing.rs index 2ce6853991..9d8e7450a9 100644 --- a/tests/expectations/tests/var-tracing.rs +++ b/tests/expectations/tests/var-tracing.rs @@ -12,6 +12,8 @@ pub struct Bar { } #[test] fn bindgen_test_layout_Bar() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -22,23 +24,19 @@ fn bindgen_test_layout_Bar() { 4usize, concat!("Alignment of ", stringify!(Bar)) ); - fn test_field_m_baz() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).m_baz) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(m_baz) - ) - ); - } - test_field_m_baz(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).m_baz) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Bar), + "::", + stringify!(m_baz) + ) + ); } extern "C" { #[link_name = "\u{1}_ZN3BarC1Ei"] diff --git a/tests/expectations/tests/vector.rs b/tests/expectations/tests/vector.rs index 936d29c619..5f90c82f9d 100644 --- a/tests/expectations/tests/vector.rs +++ b/tests/expectations/tests/vector.rs @@ -12,6 +12,8 @@ pub struct foo { } #[test] fn bindgen_test_layout_foo() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -22,23 +24,19 @@ fn bindgen_test_layout_foo() { 8usize, concat!("Alignment of ", stringify!(foo)) ); - fn test_field_mMember() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(mMember) - ) - ); - } - test_field_mMember(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(mMember) + ) + ); } pub type __m128 = [f32; 4usize]; pub type __m128d = [f64; 2usize]; diff --git a/tests/expectations/tests/virtual_inheritance.rs b/tests/expectations/tests/virtual_inheritance.rs index 9e56c8269b..eeafa0b3de 100644 --- a/tests/expectations/tests/virtual_inheritance.rs +++ b/tests/expectations/tests/virtual_inheritance.rs @@ -12,6 +12,8 @@ pub struct A { } #[test] fn bindgen_test_layout_A() { + const UNINIT: ::std::mem::MaybeUninit
= + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -22,18 +24,14 @@ fn bindgen_test_layout_A() { 4usize, concat!("Alignment of ", stringify!(A)) ); - fn test_field_foo() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(foo)) - ); - } - test_field_foo(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(A), "::", stringify!(foo)) + ); } #[repr(C)] pub struct B__bindgen_vtable(::std::os::raw::c_void); @@ -45,6 +43,8 @@ pub struct B { } #[test] fn bindgen_test_layout_B() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -55,18 +55,14 @@ fn bindgen_test_layout_B() { 8usize, concat!("Alignment of ", stringify!(B)) ); - fn test_field_bar() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 8usize, - concat!("Offset of field: ", stringify!(B), "::", stringify!(bar)) - ); - } - test_field_bar(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize + }, + 8usize, + concat!("Offset of field: ", stringify!(B), "::", stringify!(bar)) + ); } impl Default for B { fn default() -> Self { @@ -87,6 +83,8 @@ pub struct C { } #[test] fn bindgen_test_layout_C() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -97,18 +95,14 @@ fn bindgen_test_layout_C() { 8usize, concat!("Alignment of ", stringify!(C)) ); - fn test_field_baz() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, - 8usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(baz)) - ); - } - test_field_baz(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize + }, + 8usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(baz)) + ); } impl Default for C { fn default() -> Self { diff --git a/tests/expectations/tests/weird_bitfields.rs b/tests/expectations/tests/weird_bitfields.rs index c524b90d83..0522899c24 100644 --- a/tests/expectations/tests/weird_bitfields.rs +++ b/tests/expectations/tests/weird_bitfields.rs @@ -121,6 +121,8 @@ pub struct Weird { } #[test] fn bindgen_test_layout_Weird() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 24usize, @@ -131,218 +133,165 @@ fn bindgen_test_layout_Weird() { 4usize, concat!("Alignment of ", stringify!(Weird)) ); - fn test_field_mStrokeDasharrayLength() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mStrokeDasharrayLength) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mStrokeDasharrayLength) - ) - ); - } - test_field_mStrokeDasharrayLength(); - fn test_field_mClipRule() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mClipRule) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mClipRule) - ) - ); - } - test_field_mClipRule(); - fn test_field_mColorInterpolation() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mColorInterpolation) as usize - - ptr as usize - }, - 9usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mColorInterpolation) - ) - ); - } - test_field_mColorInterpolation(); - fn test_field_mColorInterpolationFilters() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mColorInterpolationFilters) as usize - - ptr as usize - }, - 10usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mColorInterpolationFilters) - ) - ); - } - test_field_mColorInterpolationFilters(); - fn test_field_mFillRule() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mFillRule) as usize - ptr as usize - }, - 11usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mFillRule) - ) - ); - } - test_field_mFillRule(); - fn test_field_mImageRendering() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mImageRendering) as usize - - ptr as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mImageRendering) - ) - ); - } - test_field_mImageRendering(); - fn test_field_mPaintOrder() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mPaintOrder) as usize - ptr as usize - }, - 13usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mPaintOrder) - ) - ); - } - test_field_mPaintOrder(); - fn test_field_mShapeRendering() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mShapeRendering) as usize - - ptr as usize - }, - 14usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mShapeRendering) - ) - ); - } - test_field_mShapeRendering(); - fn test_field_mStrokeLinecap() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mStrokeLinecap) as usize - - ptr as usize - }, - 15usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mStrokeLinecap) - ) - ); - } - test_field_mStrokeLinecap(); - fn test_field_mStrokeLinejoin() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mStrokeLinejoin) as usize - - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mStrokeLinejoin) - ) - ); - } - test_field_mStrokeLinejoin(); - fn test_field_mTextAnchor() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mTextAnchor) as usize - ptr as usize - }, - 17usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mTextAnchor) - ) - ); - } - test_field_mTextAnchor(); - fn test_field_mTextRendering() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).mTextRendering) as usize - - ptr as usize - }, - 18usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mTextRendering) - ) - ); - } - test_field_mTextRendering(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mStrokeDasharrayLength) as usize - + ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Weird), + "::", + stringify!(mStrokeDasharrayLength) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mClipRule) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(Weird), + "::", + stringify!(mClipRule) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mColorInterpolation) as usize - + ptr as usize + }, + 9usize, + concat!( + "Offset of field: ", + stringify!(Weird), + "::", + stringify!(mColorInterpolation) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mColorInterpolationFilters) as usize - + ptr as usize + }, + 10usize, + concat!( + "Offset of field: ", + stringify!(Weird), + "::", + stringify!(mColorInterpolationFilters) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mFillRule) as usize - ptr as usize + }, + 11usize, + concat!( + "Offset of field: ", + stringify!(Weird), + "::", + stringify!(mFillRule) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mImageRendering) as usize - ptr as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(Weird), + "::", + stringify!(mImageRendering) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mPaintOrder) as usize - ptr as usize + }, + 13usize, + concat!( + "Offset of field: ", + stringify!(Weird), + "::", + stringify!(mPaintOrder) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mShapeRendering) as usize - ptr as usize + }, + 14usize, + concat!( + "Offset of field: ", + stringify!(Weird), + "::", + stringify!(mShapeRendering) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mStrokeLinecap) as usize - ptr as usize + }, + 15usize, + concat!( + "Offset of field: ", + stringify!(Weird), + "::", + stringify!(mStrokeLinecap) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mStrokeLinejoin) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(Weird), + "::", + stringify!(mStrokeLinejoin) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mTextAnchor) as usize - ptr as usize + }, + 17usize, + concat!( + "Offset of field: ", + stringify!(Weird), + "::", + stringify!(mTextAnchor) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).mTextRendering) as usize - ptr as usize + }, + 18usize, + concat!( + "Offset of field: ", + stringify!(Weird), + "::", + stringify!(mTextRendering) + ) + ); } impl Default for Weird { fn default() -> Self { diff --git a/tests/expectations/tests/zero-size-array-align.rs b/tests/expectations/tests/zero-size-array-align.rs index 31eff3898c..7158875e73 100644 --- a/tests/expectations/tests/zero-size-array-align.rs +++ b/tests/expectations/tests/zero-size-array-align.rs @@ -44,6 +44,8 @@ pub struct dm_deps { } #[test] fn bindgen_test_layout_dm_deps() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -54,55 +56,43 @@ fn bindgen_test_layout_dm_deps() { 8usize, concat!("Alignment of ", stringify!(dm_deps)) ); - fn test_field_count() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).count) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(dm_deps), - "::", - stringify!(count) - ) - ); - } - test_field_count(); - fn test_field_filler() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).filler) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(dm_deps), - "::", - stringify!(filler) - ) - ); - } - test_field_filler(); - fn test_field_device() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).device) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(dm_deps), - "::", - stringify!(device) - ) - ); - } - test_field_device(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).count) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(dm_deps), + "::", + stringify!(count) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).filler) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(dm_deps), + "::", + stringify!(filler) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).device) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(dm_deps), + "::", + stringify!(device) + ) + ); } From 17b01c72ec985b8604410a82cc91734cb76cfcc2 Mon Sep 17 00:00:00 2001 From: onalante-msft <89409054+onalante-msft@users.noreply.github.com> Date: Fri, 15 Jul 2022 21:44:18 -0700 Subject: [PATCH 313/942] Regenerate tests targeting libclang 5 --- tests/expectations/tests/class.rs | 336 ++++++++---------- tests/expectations/tests/class_1_0.rs | 336 ++++++++---------- ...erive-hash-struct-with-incomplete-array.rs | 54 ++- .../tests/issue-643-inner-struct.rs | 64 ++-- tests/expectations/tests/layout_align.rs | 32 +- .../tests/libclang-5/call-conv-field.rs | 64 ++-- .../type_alias_template_specialized.rs | 32 +- tests/expectations/tests/zero-sized-array.rs | 66 ++-- 8 files changed, 426 insertions(+), 558 deletions(-) diff --git a/tests/expectations/tests/class.rs b/tests/expectations/tests/class.rs index 3bfba7e149..f26c77b74b 100644 --- a/tests/expectations/tests/class.rs +++ b/tests/expectations/tests/class.rs @@ -43,6 +43,8 @@ pub struct C { } #[test] fn bindgen_test_layout_C() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 40usize, @@ -53,35 +55,27 @@ fn bindgen_test_layout_C() { 4usize, concat!("Alignment of ", stringify!(C)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(a)) - ); - } - test_field_a(); - fn test_field_big_array() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(big_array) - ) - ); - } - test_field_big_array(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(a)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(big_array) + ) + ); } impl Default for C { fn default() -> Self { @@ -100,6 +94,8 @@ pub struct C_with_zero_length_array { } #[test] fn bindgen_test_layout_C_with_zero_length_array() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 40usize, @@ -110,64 +106,46 @@ fn bindgen_test_layout_C_with_zero_length_array() { 4usize, concat!("Alignment of ", stringify!(C_with_zero_length_array)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(a) - ) - ); - } - test_field_a(); - fn test_field_big_array() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(big_array) - ) - ); - } - test_field_big_array(); - fn test_field_zero_length_array() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize - }, - 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(zero_length_array) - ) - ); - } - test_field_zero_length_array(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array), + "::", + stringify!(big_array) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - + ptr as usize + }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array), + "::", + stringify!(zero_length_array) + ) + ); } impl Default for C_with_zero_length_array { fn default() -> Self { @@ -186,6 +164,8 @@ pub struct C_with_zero_length_array_2 { } #[test] fn bindgen_test_layout_C_with_zero_length_array_2() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -196,45 +176,33 @@ fn bindgen_test_layout_C_with_zero_length_array_2() { 4usize, concat!("Alignment of ", stringify!(C_with_zero_length_array_2)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C_with_zero_length_array_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_2), - "::", - stringify!(a) - ) - ); - } - test_field_a(); - fn test_field_zero_length_array() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C_with_zero_length_array_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_2), - "::", - stringify!(zero_length_array) - ) - ); - } - test_field_zero_length_array(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_2), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_2), + "::", + stringify!(zero_length_array) + ) + ); } #[repr(C)] pub struct C_with_incomplete_array { @@ -353,6 +321,8 @@ pub struct WithDtor { } #[test] fn bindgen_test_layout_WithDtor() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -363,23 +333,19 @@ fn bindgen_test_layout_WithDtor() { 4usize, concat!("Alignment of ", stringify!(WithDtor)) ); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithDtor), - "::", - stringify!(b) - ) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithDtor), + "::", + stringify!(b) + ) + ); } #[repr(C)] pub struct IncompleteArrayNonCopiable { @@ -416,6 +382,8 @@ pub union Union { } #[test] fn bindgen_test_layout_Union() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -426,40 +394,22 @@ fn bindgen_test_layout_Union() { 4usize, concat!("Alignment of ", stringify!(Union)) ); - fn test_field_d() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Union), - "::", - stringify!(d) - ) - ); - } - test_field_d(); - fn test_field_i() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Union), - "::", - stringify!(i) - ) - ); - } - test_field_i(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Union), "::", stringify!(d)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Union), "::", stringify!(i)) + ); } impl Default for Union { fn default() -> Self { @@ -477,6 +427,8 @@ pub struct WithUnion { } #[test] fn bindgen_test_layout_WithUnion() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -487,23 +439,19 @@ fn bindgen_test_layout_WithUnion() { 4usize, concat!("Alignment of ", stringify!(WithUnion)) ); - fn test_field_data() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithUnion), - "::", - stringify!(data) - ) - ); - } - test_field_data(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithUnion), + "::", + stringify!(data) + ) + ); } impl Default for WithUnion { fn default() -> Self { diff --git a/tests/expectations/tests/class_1_0.rs b/tests/expectations/tests/class_1_0.rs index 5415500aca..c17e48d410 100644 --- a/tests/expectations/tests/class_1_0.rs +++ b/tests/expectations/tests/class_1_0.rs @@ -86,6 +86,8 @@ pub struct C { } #[test] fn bindgen_test_layout_C() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 40usize, @@ -96,35 +98,27 @@ fn bindgen_test_layout_C() { 4usize, concat!("Alignment of ", stringify!(C)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(a)) - ); - } - test_field_a(); - fn test_field_big_array() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(big_array) - ) - ); - } - test_field_big_array(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(a)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(big_array) + ) + ); } impl Clone for C { fn clone(&self) -> Self { @@ -153,6 +147,8 @@ pub struct C_with_zero_length_array { } #[test] fn bindgen_test_layout_C_with_zero_length_array() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 40usize, @@ -163,64 +159,46 @@ fn bindgen_test_layout_C_with_zero_length_array() { 4usize, concat!("Alignment of ", stringify!(C_with_zero_length_array)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(a) - ) - ); - } - test_field_a(); - fn test_field_big_array() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(big_array) - ) - ); - } - test_field_big_array(); - fn test_field_zero_length_array() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit( - ); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize - }, - 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(zero_length_array) - ) - ); - } - test_field_zero_length_array(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array), + "::", + stringify!(big_array) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - + ptr as usize + }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array), + "::", + stringify!(zero_length_array) + ) + ); } impl Default for C_with_zero_length_array { fn default() -> Self { @@ -239,6 +217,8 @@ pub struct C_with_zero_length_array_2 { } #[test] fn bindgen_test_layout_C_with_zero_length_array_2() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -249,45 +229,33 @@ fn bindgen_test_layout_C_with_zero_length_array_2() { 4usize, concat!("Alignment of ", stringify!(C_with_zero_length_array_2)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C_with_zero_length_array_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_2), - "::", - stringify!(a) - ) - ); - } - test_field_a(); - fn test_field_zero_length_array() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::< - C_with_zero_length_array_2, - >::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_2), - "::", - stringify!(zero_length_array) - ) - ); - } - test_field_zero_length_array(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_2), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_2), + "::", + stringify!(zero_length_array) + ) + ); } #[repr(C)] pub struct C_with_incomplete_array { @@ -406,6 +374,8 @@ pub struct WithDtor { } #[test] fn bindgen_test_layout_WithDtor() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -416,23 +386,19 @@ fn bindgen_test_layout_WithDtor() { 4usize, concat!("Alignment of ", stringify!(WithDtor)) ); - fn test_field_b() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithDtor), - "::", - stringify!(b) - ) - ); - } - test_field_b(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithDtor), + "::", + stringify!(b) + ) + ); } #[repr(C)] pub struct IncompleteArrayNonCopiable { @@ -470,6 +436,8 @@ pub struct Union { } #[test] fn bindgen_test_layout_Union() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -480,40 +448,22 @@ fn bindgen_test_layout_Union() { 4usize, concat!("Alignment of ", stringify!(Union)) ); - fn test_field_d() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Union), - "::", - stringify!(d) - ) - ); - } - test_field_d(); - fn test_field_i() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Union), - "::", - stringify!(i) - ) - ); - } - test_field_i(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Union), "::", stringify!(d)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(Union), "::", stringify!(i)) + ); } impl Clone for Union { fn clone(&self) -> Self { @@ -527,6 +477,8 @@ pub struct WithUnion { } #[test] fn bindgen_test_layout_WithUnion() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -537,23 +489,19 @@ fn bindgen_test_layout_WithUnion() { 4usize, concat!("Alignment of ", stringify!(WithUnion)) ); - fn test_field_data() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithUnion), - "::", - stringify!(data) - ) - ); - } - test_field_data(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithUnion), + "::", + stringify!(data) + ) + ); } impl Clone for WithUnion { fn clone(&self) -> Self { diff --git a/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs b/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs index abba4b28a8..48fc7ed1a7 100644 --- a/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs +++ b/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs @@ -43,6 +43,8 @@ pub struct test { } #[test] fn bindgen_test_layout_test() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -53,36 +55,28 @@ fn bindgen_test_layout_test() { 4usize, concat!("Alignment of ", stringify!(test)) ); - fn test_field_a() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!("Offset of field: ", stringify!(test), "::", stringify!(a)) - ); - } - test_field_a(); - fn test_field_zero_length_array() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(test), - "::", - stringify!(zero_length_array) - ) - ); - } - test_field_zero_length_array(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!("Offset of field: ", stringify!(test), "::", stringify!(a)) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - + ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(test), + "::", + stringify!(zero_length_array) + ) + ); } #[repr(C)] #[derive(Debug, Default)] diff --git a/tests/expectations/tests/issue-643-inner-struct.rs b/tests/expectations/tests/issue-643-inner-struct.rs index 0fb586c40f..ae1890c27c 100644 --- a/tests/expectations/tests/issue-643-inner-struct.rs +++ b/tests/expectations/tests/issue-643-inner-struct.rs @@ -50,6 +50,8 @@ pub struct rte_ring_prod { } #[test] fn bindgen_test_layout_rte_ring_prod() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -60,23 +62,19 @@ fn bindgen_test_layout_rte_ring_prod() { 4usize, concat!("Alignment of ", stringify!(rte_ring_prod)) ); - fn test_field_watermark() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).watermark) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ring_prod), - "::", - stringify!(watermark) - ) - ); - } - test_field_watermark(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).watermark) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ring_prod), + "::", + stringify!(watermark) + ) + ); } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -85,6 +83,8 @@ pub struct rte_ring_cons { } #[test] fn bindgen_test_layout_rte_ring_cons() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -95,23 +95,19 @@ fn bindgen_test_layout_rte_ring_cons() { 4usize, concat!("Alignment of ", stringify!(rte_ring_cons)) ); - fn test_field_sc_dequeue() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).sc_dequeue) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ring_cons), - "::", - stringify!(sc_dequeue) - ) - ); - } - test_field_sc_dequeue(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).sc_dequeue) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ring_cons), + "::", + stringify!(sc_dequeue) + ) + ); } #[test] fn bindgen_test_layout_rte_ring() { diff --git a/tests/expectations/tests/layout_align.rs b/tests/expectations/tests/layout_align.rs index 44df4c1cb7..a6d18d1483 100644 --- a/tests/expectations/tests/layout_align.rs +++ b/tests/expectations/tests/layout_align.rs @@ -169,6 +169,8 @@ pub struct rte_eth_link { } #[test] fn bindgen_test_layout_rte_eth_link() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -179,23 +181,19 @@ fn bindgen_test_layout_rte_eth_link() { 8usize, concat!("Alignment of ", stringify!(rte_eth_link)) ); - fn test_field_link_speed() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).link_speed) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_link), - "::", - stringify!(link_speed) - ) - ); - } - test_field_link_speed(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).link_speed) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_link), + "::", + stringify!(link_speed) + ) + ); } impl rte_eth_link { #[inline] diff --git a/tests/expectations/tests/libclang-5/call-conv-field.rs b/tests/expectations/tests/libclang-5/call-conv-field.rs index f83181ea0b..eb86ec2f43 100644 --- a/tests/expectations/tests/libclang-5/call-conv-field.rs +++ b/tests/expectations/tests/libclang-5/call-conv-field.rs @@ -18,6 +18,8 @@ pub struct JNINativeInterface_ { } #[test] fn bindgen_test_layout_JNINativeInterface_() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -28,42 +30,32 @@ fn bindgen_test_layout_JNINativeInterface_() { 8usize, concat!("Alignment of ", stringify!(JNINativeInterface_)) ); - fn test_field_GetVersion() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).GetVersion) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(JNINativeInterface_), - "::", - stringify!(GetVersion) - ) - ); - } - test_field_GetVersion(); - fn test_field___hack() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).__hack) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(JNINativeInterface_), - "::", - stringify!(__hack) - ) - ); - } - test_field___hack(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).GetVersion) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(JNINativeInterface_), + "::", + stringify!(GetVersion) + ) + ); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).__hack) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(JNINativeInterface_), + "::", + stringify!(__hack) + ) + ); } extern "stdcall" { pub fn bar(); diff --git a/tests/expectations/tests/libclang-5/type_alias_template_specialized.rs b/tests/expectations/tests/libclang-5/type_alias_template_specialized.rs index 213d4cd685..3e6550936c 100644 --- a/tests/expectations/tests/libclang-5/type_alias_template_specialized.rs +++ b/tests/expectations/tests/libclang-5/type_alias_template_specialized.rs @@ -12,6 +12,8 @@ pub struct Rooted { } #[test] fn bindgen_test_layout_Rooted() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -22,23 +24,19 @@ fn bindgen_test_layout_Rooted() { 4usize, concat!("Alignment of ", stringify!(Rooted)) ); - fn test_field_ptr() { - assert_eq!( - unsafe { - let uninit = ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Rooted), - "::", - stringify!(ptr) - ) - ); - } - test_field_ptr(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Rooted), + "::", + stringify!(ptr) + ) + ); } impl Default for Rooted { fn default() -> Self { diff --git a/tests/expectations/tests/zero-sized-array.rs b/tests/expectations/tests/zero-sized-array.rs index c12afa5995..358164d325 100644 --- a/tests/expectations/tests/zero-sized-array.rs +++ b/tests/expectations/tests/zero-sized-array.rs @@ -43,6 +43,8 @@ pub struct ZeroSizedArray { } #[test] fn bindgen_test_layout_ZeroSizedArray() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 0usize, @@ -53,24 +55,19 @@ fn bindgen_test_layout_ZeroSizedArray() { 1usize, concat!("Alignment of ", stringify!(ZeroSizedArray)) ); - fn test_field_arr() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ZeroSizedArray), - "::", - stringify!(arr) - ) - ); - } - test_field_arr(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ZeroSizedArray), + "::", + stringify!(arr) + ) + ); } /// And nor should this get an `_address` field. #[repr(C)] @@ -80,6 +77,8 @@ pub struct ContainsZeroSizedArray { } #[test] fn bindgen_test_layout_ContainsZeroSizedArray() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); assert_eq!( ::std::mem::size_of::(), 0usize, @@ -90,24 +89,19 @@ fn bindgen_test_layout_ContainsZeroSizedArray() { 1usize, concat!("Alignment of ", stringify!(ContainsZeroSizedArray)) ); - fn test_field_zsa() { - assert_eq!( - unsafe { - let uninit = - ::std::mem::MaybeUninit::::uninit(); - let ptr = uninit.as_ptr(); - ::std::ptr::addr_of!((*ptr).zsa) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContainsZeroSizedArray), - "::", - stringify!(zsa) - ) - ); - } - test_field_zsa(); + assert_eq!( + unsafe { + let ptr = UNINIT.as_ptr(); + ::std::ptr::addr_of!((*ptr).zsa) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ContainsZeroSizedArray), + "::", + stringify!(zsa) + ) + ); } /// Inheriting from ZeroSizedArray shouldn't cause an `_address` to be inserted /// either. From e26230597c9ace38ad570131e21a751ddaa6c3ed Mon Sep 17 00:00:00 2001 From: onalante-msft <89409054+onalante-msft@users.noreply.github.com> Date: Fri, 15 Jul 2022 21:59:14 -0700 Subject: [PATCH 314/942] Extract pointer once for all alignment tests --- src/codegen/mod.rs | 2 +- tests/expectations/tests/16-byte-alignment.rs | 43 +-- .../tests/16-byte-alignment_1_0.rs | 43 +-- tests/expectations/tests/accessors.rs | 20 +- tests/expectations/tests/allowlist-file.rs | 18 +- .../tests/allowlist-namespaces.rs | 2 +- .../allowlisted-item-references-no-hash.rs | 6 +- ...llowlisted-item-references-no-partialeq.rs | 6 +- .../allowlisted_item_references_no_copy.rs | 6 +- tests/expectations/tests/annotation_hide.rs | 6 +- .../expectations/tests/anon-fields-prefix.rs | 38 +-- tests/expectations/tests/anon_enum.rs | 11 +- .../tests/anon_struct_in_union.rs | 18 +- .../tests/anon_struct_in_union_1_0.rs | 18 +- .../tests/array-of-zero-sized-types.rs | 6 +- .../tests/bindgen-union-inside-namespace.rs | 3 +- tests/expectations/tests/bitfield-linux-32.rs | 6 +- tests/expectations/tests/bitfield_align.rs | 28 +- .../tests/blocklist-and-impl-debug.rs | 6 +- tests/expectations/tests/blocklist-file.rs | 22 +- tests/expectations/tests/blocks-signature.rs | 11 +- tests/expectations/tests/blocks.rs | 11 +- tests/expectations/tests/c_naming.rs | 17 +- tests/expectations/tests/canonical-types.rs | 18 +- tests/expectations/tests/char.rs | 61 +---- tests/expectations/tests/class.rs | 45 +--- tests/expectations/tests/class_1_0.rs | 45 +--- tests/expectations/tests/class_nested.rs | 16 +- tests/expectations/tests/class_no_members.rs | 2 +- tests/expectations/tests/class_use_as.rs | 8 +- tests/expectations/tests/class_with_dtor.rs | 2 +- .../tests/class_with_inner_struct.rs | 98 ++----- .../tests/class_with_inner_struct_1_0.rs | 98 ++----- .../expectations/tests/class_with_typedef.rs | 28 +- tests/expectations/tests/comment-indent.rs | 2 +- tests/expectations/tests/complex.rs | 24 +- .../expectations/tests/const-const-mut-ptr.rs | 6 +- .../tests/constified-enum-module-overflow.rs | 6 +- .../expectations/tests/constify-all-enums.rs | 2 +- .../tests/constify-module-enums-basic.rs | 2 +- .../tests/constify-module-enums-namespace.rs | 2 +- .../constify-module-enums-shadow-name.rs | 6 +- .../constify-module-enums-simple-alias.rs | 25 +- ...onstify-module-enums-simple-nonamespace.rs | 11 +- .../tests/constify-module-enums-types.rs | 59 +---- .../tests/contains-vs-inherits-zero-sized.rs | 17 +- tests/expectations/tests/convert-floats.rs | 23 +- .../expectations/tests/ctypes-prefix-path.rs | 16 +- .../tests/derive-bitfield-method-same-name.rs | 6 +- tests/expectations/tests/derive-clone.rs | 6 +- tests/expectations/tests/derive-clone_1_0.rs | 6 +- .../tests/derive-debug-bitfield-core.rs | 2 +- .../tests/derive-debug-bitfield.rs | 2 +- .../tests/derive-debug-function-pointer.rs | 7 +- .../tests/derive-debug-mangle-name.rs | 22 +- ...ive-debug-opaque-template-instantiation.rs | 6 +- .../expectations/tests/derive-debug-opaque.rs | 6 +- .../tests/derive-default-and-blocklist.rs | 6 +- tests/expectations/tests/derive-fn-ptr.rs | 4 +- .../tests/derive-hash-and-blocklist.rs | 6 +- .../tests/derive-hash-blocklisting.rs | 12 +- ...rive-hash-struct-with-anon-struct-float.rs | 17 +- .../derive-hash-struct-with-float-array.rs | 6 +- ...erive-hash-struct-with-incomplete-array.rs | 7 +- .../tests/derive-hash-struct-with-pointer.rs | 24 +- .../tests/derive-hash-template-inst-float.rs | 12 +- .../tests/derive-partialeq-and-blocklist.rs | 6 +- .../tests/derive-partialeq-base.rs | 6 +- .../tests/derive-partialeq-bitfield.rs | 2 +- .../tests/derive-partialeq-core.rs | 2 +- .../tests/derive-partialeq-pointer.rs | 12 +- .../tests/derive-partialeq-union.rs | 11 +- .../tests/derive-partialeq-union_1_0.rs | 11 +- .../tests/disable-nested-struct-naming.rs | 63 ++--- .../tests/disable-untagged-union.rs | 11 +- .../expectations/tests/do-not-derive-copy.rs | 6 +- tests/expectations/tests/doggo-or-null.rs | 6 +- .../duplicated-namespaces-definitions.rs | 5 +- .../tests/dynamic_loading_with_blocklist.rs | 6 +- .../tests/dynamic_loading_with_class.rs | 6 +- .../tests/enum-default-bitfield.rs | 6 +- .../expectations/tests/enum-default-consts.rs | 6 +- .../expectations/tests/enum-default-module.rs | 6 +- tests/expectations/tests/enum-default-rust.rs | 6 +- .../expectations/tests/enum-no-debug-rust.rs | 6 +- tests/expectations/tests/enum.rs | 6 +- .../tests/enum_and_vtable_mangling.rs | 6 +- tests/expectations/tests/explicit-padding.rs | 32 +-- .../expectations/tests/extern-const-struct.rs | 6 +- .../tests/forward-declaration-autoptr.rs | 2 +- .../tests/forward_declared_complex_types.rs | 6 +- .../forward_declared_complex_types_1_0.rs | 6 +- .../tests/forward_declared_struct.rs | 12 +- .../expectations/tests/func_ptr_in_struct.rs | 6 +- .../expectations/tests/gen-destructors-neg.rs | 6 +- tests/expectations/tests/gen-destructors.rs | 6 +- tests/expectations/tests/i128.rs | 3 +- tests/expectations/tests/inline_namespace.rs | 6 +- .../tests/inline_namespace_conservative.rs | 6 +- tests/expectations/tests/inner_const.rs | 6 +- .../expectations/tests/inner_template_self.rs | 6 +- .../tests/issue-1118-using-forward-decl.rs | 12 +- .../tests/issue-1216-variadic-member.rs | 6 +- tests/expectations/tests/issue-1281.rs | 18 +- tests/expectations/tests/issue-1285.rs | 17 +- tests/expectations/tests/issue-1291.rs | 76 ++---- .../tests/issue-1382-rust-primitive-types.rs | 71 ++--- tests/expectations/tests/issue-1443.rs | 44 +--- tests/expectations/tests/issue-1454.rs | 6 +- tests/expectations/tests/issue-1498.rs | 26 +- tests/expectations/tests/issue-1947.rs | 16 +- .../tests/issue-1977-larger-arrays.rs | 2 +- tests/expectations/tests/issue-1995.rs | 6 +- tests/expectations/tests/issue-2019.rs | 12 +- tests/expectations/tests/issue-372.rs | 28 +- .../tests/issue-537-repr-packed-n.rs | 34 +-- tests/expectations/tests/issue-537.rs | 34 +-- .../tests/issue-573-layout-test-failures.rs | 6 +- .../issue-574-assertion-failure-in-codegen.rs | 6 +- ...issue-584-stylo-template-analysis-panic.rs | 6 +- .../tests/issue-639-typedef-anon-field.rs | 18 +- .../tests/issue-643-inner-struct.rs | 4 +- .../issue-648-derive-debug-with-padding.rs | 17 +- tests/expectations/tests/issue-674-1.rs | 6 +- tests/expectations/tests/issue-674-2.rs | 12 +- tests/expectations/tests/issue-674-3.rs | 12 +- .../tests/issue-801-opaque-sloppiness.rs | 6 +- ...07-opaque-types-methods-being-generated.rs | 2 +- .../issue-944-derive-copy-and-blocklisting.rs | 6 +- .../expectations/tests/jsval_layout_opaque.rs | 52 +--- .../tests/jsval_layout_opaque_1_0.rs | 52 +--- tests/expectations/tests/layout_align.rs | 2 +- tests/expectations/tests/layout_arp.rs | 50 +--- tests/expectations/tests/layout_array.rs | 60 ++--- .../tests/layout_array_too_long.rs | 59 +---- .../tests/layout_cmdline_token.rs | 33 +-- tests/expectations/tests/layout_eth_conf.rs | 244 ++++-------------- .../expectations/tests/layout_eth_conf_1_0.rs | 244 ++++-------------- tests/expectations/tests/layout_kni_mbuf.rs | 51 +--- .../tests/layout_large_align_field.rs | 105 ++------ tests/expectations/tests/layout_mbuf.rs | 127 +++------ tests/expectations/tests/layout_mbuf_1_0.rs | 127 +++------ .../tests/libclang-5/call-conv-field.rs | 7 +- .../type_alias_template_specialized.rs | 6 +- .../tests/libclang-9/call-conv-field.rs | 7 +- tests/expectations/tests/libclang-9/class.rs | 80 ++---- .../tests/libclang-9/class_1_0.rs | 80 ++---- ...erive-hash-struct-with-incomplete-array.rs | 22 +- .../libclang-9/incomplete-array-padding.rs | 6 +- .../libclang-9/issue-643-inner-struct.rs | 25 +- .../tests/libclang-9/layout_align.rs | 24 +- .../type_alias_template_specialized.rs | 6 +- .../tests/libclang-9/zero-sized-array.rs | 24 +- tests/expectations/tests/long_double.rs | 6 +- tests/expectations/tests/msvc-no-usr.rs | 6 +- tests/expectations/tests/mutable.rs | 11 +- tests/expectations/tests/namespace.rs | 2 +- tests/expectations/tests/nested.rs | 17 +- .../tests/nested_within_namespace.rs | 6 +- tests/expectations/tests/no-comments.rs | 6 +- tests/expectations/tests/no-derive-debug.rs | 11 +- tests/expectations/tests/no-derive-default.rs | 11 +- .../expectations/tests/no-hash-allowlisted.rs | 6 +- .../tests/no-partialeq-allowlisted.rs | 6 +- .../tests/no-recursive-allowlisting.rs | 6 +- tests/expectations/tests/no-std.rs | 16 +- .../expectations/tests/no_copy_allowlisted.rs | 6 +- .../tests/no_debug_allowlisted.rs | 6 +- .../tests/no_default_allowlisted.rs | 6 +- tests/expectations/tests/non-type-params.rs | 4 +- .../expectations/tests/objc_interface_type.rs | 6 +- .../tests/opaque-template-inst-member-2.rs | 17 +- .../tests/opaque-template-inst-member.rs | 17 +- ...paque-template-instantiation-namespaced.rs | 8 +- .../tests/opaque-template-instantiation.rs | 8 +- tests/expectations/tests/opaque_in_struct.rs | 2 +- tests/expectations/tests/opaque_pointer.rs | 12 +- .../tests/packed-n-with-padding.rs | 21 +- tests/expectations/tests/private.rs | 9 +- tests/expectations/tests/private_fields.rs | 29 +-- .../tests/reparented_replacement.rs | 2 +- tests/expectations/tests/replace_use.rs | 6 +- tests/expectations/tests/repr-align.rs | 22 +- ...ame_struct_name_in_different_namespaces.rs | 11 +- .../tests/sentry-defined-multiple-times.rs | 13 +- tests/expectations/tests/size_t_is_usize.rs | 16 +- tests/expectations/tests/size_t_template.rs | 6 +- ...ruct_containing_forward_declared_struct.rs | 12 +- tests/expectations/tests/struct_typedef.rs | 8 +- tests/expectations/tests/struct_typedef_ns.rs | 4 +- .../tests/struct_with_anon_struct.rs | 17 +- .../tests/struct_with_anon_struct_array.rs | 33 +-- .../tests/struct_with_anon_struct_pointer.rs | 17 +- .../tests/struct_with_anon_union.rs | 17 +- .../tests/struct_with_anon_union_1_0.rs | 17 +- .../tests/struct_with_anon_unnamed_struct.rs | 11 +- .../tests/struct_with_anon_unnamed_union.rs | 11 +- .../struct_with_anon_unnamed_union_1_0.rs | 11 +- .../tests/struct_with_bitfields.rs | 6 +- .../tests/struct_with_derive_debug.rs | 24 +- .../tests/struct_with_large_array.rs | 2 +- .../expectations/tests/struct_with_nesting.rs | 44 +--- .../tests/struct_with_nesting_1_0.rs | 44 +--- .../expectations/tests/struct_with_packing.rs | 11 +- .../expectations/tests/struct_with_struct.rs | 17 +- tests/expectations/tests/template.rs | 51 +--- .../test_mixed_header_and_header_contents.rs | 61 +---- .../test_multiple_header_calls_in_builder.rs | 61 +---- tests/expectations/tests/timex.rs | 12 +- ...type-referenced-by-allowlisted-function.rs | 6 +- tests/expectations/tests/typeref.rs | 14 +- tests/expectations/tests/typeref_1_0.rs | 14 +- tests/expectations/tests/underscore.rs | 6 +- tests/expectations/tests/union-align.rs | 12 +- tests/expectations/tests/union-in-ns.rs | 6 +- tests/expectations/tests/union-in-ns_1_0.rs | 6 +- tests/expectations/tests/union_dtor.rs | 11 +- tests/expectations/tests/union_dtor_1_0.rs | 11 +- tests/expectations/tests/union_fields.rs | 12 +- tests/expectations/tests/union_fields_1_0.rs | 12 +- .../tests/union_with_anon_struct.rs | 17 +- .../tests/union_with_anon_struct_1_0.rs | 17 +- .../tests/union_with_anon_struct_bitfield.rs | 6 +- .../union_with_anon_struct_bitfield_1_0.rs | 6 +- .../tests/union_with_anon_union.rs | 17 +- .../tests/union_with_anon_union_1_0.rs | 17 +- .../tests/union_with_anon_unnamed_struct.rs | 27 +- .../union_with_anon_unnamed_struct_1_0.rs | 27 +- .../tests/union_with_anon_unnamed_union.rs | 17 +- .../union_with_anon_unnamed_union_1_0.rs | 17 +- .../tests/union_with_big_member.rs | 33 +-- .../tests/union_with_big_member_1_0.rs | 33 +-- .../expectations/tests/union_with_nesting.rs | 28 +- .../tests/union_with_nesting_1_0.rs | 28 +- tests/expectations/tests/unknown_attr.rs | 3 +- tests/expectations/tests/use-core.rs | 27 +- tests/expectations/tests/use-core_1_0.rs | 27 +- tests/expectations/tests/var-tracing.rs | 6 +- tests/expectations/tests/vector.rs | 6 +- .../expectations/tests/virtual_inheritance.rs | 18 +- tests/expectations/tests/weird_bitfields.rs | 13 +- .../tests/zero-size-array-align.rs | 16 +- tests/expectations/tests/zero-sized-array.rs | 12 +- 243 files changed, 1323 insertions(+), 3465 deletions(-) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 80b7233bc7..80c73bbc3d 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -2190,7 +2190,6 @@ impl CodeGenerator for CompInfo { quote! { assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::#prefix::ptr::addr_of!((*ptr).#field_name) as usize - ptr as usize }, #field_offset, @@ -2208,6 +2207,7 @@ impl CodeGenerator for CompInfo { // opt-level=0 doesn't take too much stack space, // see #2218. const UNINIT: ::#prefix::mem::MaybeUninit<#canonical_ident> = ::#prefix::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); }) } else { None diff --git a/tests/expectations/tests/16-byte-alignment.rs b/tests/expectations/tests/16-byte-alignment.rs index e1b6e283f9..a60a63aa3b 100644 --- a/tests/expectations/tests/16-byte-alignment.rs +++ b/tests/expectations/tests/16-byte-alignment.rs @@ -29,6 +29,7 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit< rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1, > = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -46,10 +47,7 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).dport) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).dport) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -59,10 +57,7 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).sport) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).sport) as usize - ptr as usize }, 2usize, concat!( "Offset of field: ", @@ -76,6 +71,7 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1() { fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -88,7 +84,6 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).sctp_tag) as usize - ptr as usize }, 0usize, @@ -113,6 +108,7 @@ impl Default for rte_ipv4_tuple__bindgen_ty_1 { fn bindgen_test_layout_rte_ipv4_tuple() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 12usize, @@ -125,7 +121,6 @@ fn bindgen_test_layout_rte_ipv4_tuple() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).src_addr) as usize - ptr as usize }, 0usize, @@ -138,7 +133,6 @@ fn bindgen_test_layout_rte_ipv4_tuple() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).dst_addr) as usize - ptr as usize }, 4usize, @@ -183,6 +177,7 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit< rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1, > = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -200,10 +195,7 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).dport) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).dport) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -213,10 +205,7 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).sport) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).sport) as usize - ptr as usize }, 2usize, concat!( "Offset of field: ", @@ -230,6 +219,7 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1() { fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -242,7 +232,6 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).sctp_tag) as usize - ptr as usize }, 0usize, @@ -267,6 +256,7 @@ impl Default for rte_ipv6_tuple__bindgen_ty_1 { fn bindgen_test_layout_rte_ipv6_tuple() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 36usize, @@ -279,7 +269,6 @@ fn bindgen_test_layout_rte_ipv6_tuple() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).src_addr) as usize - ptr as usize }, 0usize, @@ -292,7 +281,6 @@ fn bindgen_test_layout_rte_ipv6_tuple() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).dst_addr) as usize - ptr as usize }, 16usize, @@ -324,6 +312,7 @@ pub union rte_thash_tuple { fn bindgen_test_layout_rte_thash_tuple() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 48usize, @@ -335,10 +324,7 @@ fn bindgen_test_layout_rte_thash_tuple() { concat!("Alignment of ", stringify!(rte_thash_tuple)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).v4) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).v4) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -348,10 +334,7 @@ fn bindgen_test_layout_rte_thash_tuple() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).v6) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).v6) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/16-byte-alignment_1_0.rs b/tests/expectations/tests/16-byte-alignment_1_0.rs index 6b39efdadc..369e2c75ea 100644 --- a/tests/expectations/tests/16-byte-alignment_1_0.rs +++ b/tests/expectations/tests/16-byte-alignment_1_0.rs @@ -74,6 +74,7 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit< rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1, > = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -91,10 +92,7 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).dport) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).dport) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -104,10 +102,7 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).sport) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).sport) as usize - ptr as usize }, 2usize, concat!( "Offset of field: ", @@ -126,6 +121,7 @@ impl Clone for rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 { fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -138,7 +134,6 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).sctp_tag) as usize - ptr as usize }, 0usize, @@ -159,6 +154,7 @@ impl Clone for rte_ipv4_tuple__bindgen_ty_1 { fn bindgen_test_layout_rte_ipv4_tuple() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 12usize, @@ -171,7 +167,6 @@ fn bindgen_test_layout_rte_ipv4_tuple() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).src_addr) as usize - ptr as usize }, 0usize, @@ -184,7 +179,6 @@ fn bindgen_test_layout_rte_ipv4_tuple() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).dst_addr) as usize - ptr as usize }, 4usize, @@ -227,6 +221,7 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit< rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1, > = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -244,10 +239,7 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).dport) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).dport) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -257,10 +249,7 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).sport) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).sport) as usize - ptr as usize }, 2usize, concat!( "Offset of field: ", @@ -279,6 +268,7 @@ impl Clone for rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 { fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -291,7 +281,6 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).sctp_tag) as usize - ptr as usize }, 0usize, @@ -312,6 +301,7 @@ impl Clone for rte_ipv6_tuple__bindgen_ty_1 { fn bindgen_test_layout_rte_ipv6_tuple() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 36usize, @@ -324,7 +314,6 @@ fn bindgen_test_layout_rte_ipv6_tuple() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).src_addr) as usize - ptr as usize }, 0usize, @@ -337,7 +326,6 @@ fn bindgen_test_layout_rte_ipv6_tuple() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).dst_addr) as usize - ptr as usize }, 16usize, @@ -365,16 +353,14 @@ pub struct rte_thash_tuple { fn bindgen_test_layout_rte_thash_tuple() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 48usize, concat!("Size of: ", stringify!(rte_thash_tuple)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).v4) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).v4) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -384,10 +370,7 @@ fn bindgen_test_layout_rte_thash_tuple() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).v6) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).v6) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/accessors.rs b/tests/expectations/tests/accessors.rs index c38c1d6313..05fdaf4ca5 100644 --- a/tests/expectations/tests/accessors.rs +++ b/tests/expectations/tests/accessors.rs @@ -20,6 +20,7 @@ pub struct SomeAccessors { fn bindgen_test_layout_SomeAccessors() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -32,7 +33,6 @@ fn bindgen_test_layout_SomeAccessors() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mNoAccessor) as usize - ptr as usize }, 0usize, @@ -45,7 +45,6 @@ fn bindgen_test_layout_SomeAccessors() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mBothAccessors) as usize - ptr as usize }, 4usize, @@ -58,7 +57,6 @@ fn bindgen_test_layout_SomeAccessors() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mUnsafeAccessors) as usize - ptr as usize }, @@ -72,7 +70,6 @@ fn bindgen_test_layout_SomeAccessors() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mImmutableAccessor) as usize - ptr as usize }, @@ -120,6 +117,7 @@ pub struct AllAccessors { fn bindgen_test_layout_AllAccessors() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -132,7 +130,6 @@ fn bindgen_test_layout_AllAccessors() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mBothAccessors) as usize - ptr as usize }, 0usize, @@ -145,7 +142,6 @@ fn bindgen_test_layout_AllAccessors() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mAlsoBothAccessors) as usize - ptr as usize }, @@ -187,6 +183,7 @@ pub struct AllUnsafeAccessors { fn bindgen_test_layout_AllUnsafeAccessors() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -199,7 +196,6 @@ fn bindgen_test_layout_AllUnsafeAccessors() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mBothAccessors) as usize - ptr as usize }, 0usize, @@ -212,7 +208,6 @@ fn bindgen_test_layout_AllUnsafeAccessors() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mAlsoBothAccessors) as usize - ptr as usize }, @@ -263,6 +258,7 @@ pub struct ContradictAccessors { fn bindgen_test_layout_ContradictAccessors() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -275,7 +271,6 @@ fn bindgen_test_layout_ContradictAccessors() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mBothAccessors) as usize - ptr as usize }, 0usize, @@ -288,7 +283,6 @@ fn bindgen_test_layout_ContradictAccessors() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mNoAccessors) as usize - ptr as usize }, 4usize, @@ -301,7 +295,6 @@ fn bindgen_test_layout_ContradictAccessors() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mUnsafeAccessors) as usize - ptr as usize }, @@ -315,7 +308,6 @@ fn bindgen_test_layout_ContradictAccessors() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mImmutableAccessor) as usize - ptr as usize }, @@ -362,6 +354,7 @@ pub struct Replaced { fn bindgen_test_layout_Replaced() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -374,7 +367,6 @@ fn bindgen_test_layout_Replaced() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mAccessor) as usize - ptr as usize }, 0usize, @@ -406,6 +398,7 @@ pub struct Wrapper { fn bindgen_test_layout_Wrapper() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -418,7 +411,6 @@ fn bindgen_test_layout_Wrapper() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mReplaced) as usize - ptr as usize }, 0usize, diff --git a/tests/expectations/tests/allowlist-file.rs b/tests/expectations/tests/allowlist-file.rs index 2b6437c041..3b72fb75eb 100644 --- a/tests/expectations/tests/allowlist-file.rs +++ b/tests/expectations/tests/allowlist-file.rs @@ -60,6 +60,7 @@ pub struct StructWithAllowlistedDefinition { fn bindgen_test_layout_StructWithAllowlistedDefinition() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -71,10 +72,7 @@ fn bindgen_test_layout_StructWithAllowlistedDefinition() { concat!("Alignment of ", stringify!(StructWithAllowlistedDefinition)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).other) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).other) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -102,6 +100,7 @@ pub struct StructWithAllowlistedFwdDecl { fn bindgen_test_layout_StructWithAllowlistedFwdDecl() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -113,10 +112,7 @@ fn bindgen_test_layout_StructWithAllowlistedFwdDecl() { concat!("Alignment of ", stringify!(StructWithAllowlistedFwdDecl)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -135,6 +131,7 @@ pub struct AllowlistMe { fn bindgen_test_layout_AllowlistMe() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -146,10 +143,7 @@ fn bindgen_test_layout_AllowlistMe() { concat!("Alignment of ", stringify!(AllowlistMe)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/allowlist-namespaces.rs b/tests/expectations/tests/allowlist-namespaces.rs index dd6ca222b3..ee9fe4283c 100644 --- a/tests/expectations/tests/allowlist-namespaces.rs +++ b/tests/expectations/tests/allowlist-namespaces.rs @@ -43,6 +43,7 @@ pub mod root { fn bindgen_test_layout_Test() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -55,7 +56,6 @@ pub mod root { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).helper) as usize - ptr as usize }, 0usize, diff --git a/tests/expectations/tests/allowlisted-item-references-no-hash.rs b/tests/expectations/tests/allowlisted-item-references-no-hash.rs index f78e3cb483..56dc5bce30 100644 --- a/tests/expectations/tests/allowlisted-item-references-no-hash.rs +++ b/tests/expectations/tests/allowlisted-item-references-no-hash.rs @@ -32,6 +32,7 @@ pub struct AllowlistMe { fn bindgen_test_layout_AllowlistMe() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -43,10 +44,7 @@ fn bindgen_test_layout_AllowlistMe() { concat!("Alignment of ", stringify!(AllowlistMe)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/allowlisted-item-references-no-partialeq.rs b/tests/expectations/tests/allowlisted-item-references-no-partialeq.rs index e0a2accf4c..36cdda0e8f 100644 --- a/tests/expectations/tests/allowlisted-item-references-no-partialeq.rs +++ b/tests/expectations/tests/allowlisted-item-references-no-partialeq.rs @@ -32,6 +32,7 @@ pub struct AllowlistMe { fn bindgen_test_layout_AllowlistMe() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -43,10 +44,7 @@ fn bindgen_test_layout_AllowlistMe() { concat!("Alignment of ", stringify!(AllowlistMe)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/allowlisted_item_references_no_copy.rs b/tests/expectations/tests/allowlisted_item_references_no_copy.rs index 4a598831e5..625e0ce6fd 100644 --- a/tests/expectations/tests/allowlisted_item_references_no_copy.rs +++ b/tests/expectations/tests/allowlisted_item_references_no_copy.rs @@ -32,6 +32,7 @@ pub struct AllowlistMe { fn bindgen_test_layout_AllowlistMe() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -43,10 +44,7 @@ fn bindgen_test_layout_AllowlistMe() { concat!("Alignment of ", stringify!(AllowlistMe)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/annotation_hide.rs b/tests/expectations/tests/annotation_hide.rs index 3c02bd4d61..a90c4261e8 100644 --- a/tests/expectations/tests/annotation_hide.rs +++ b/tests/expectations/tests/annotation_hide.rs @@ -34,6 +34,7 @@ pub struct NotAnnotated { fn bindgen_test_layout_NotAnnotated() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -45,10 +46,7 @@ fn bindgen_test_layout_NotAnnotated() { concat!("Alignment of ", stringify!(NotAnnotated)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/anon-fields-prefix.rs b/tests/expectations/tests/anon-fields-prefix.rs index 78e786df03..d09cab4044 100644 --- a/tests/expectations/tests/anon-fields-prefix.rs +++ b/tests/expectations/tests/anon-fields-prefix.rs @@ -23,6 +23,7 @@ pub struct color__bindgen_ty_1 { fn bindgen_test_layout_color__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 3usize, @@ -34,10 +35,7 @@ fn bindgen_test_layout_color__bindgen_ty_1() { concat!("Alignment of ", stringify!(color__bindgen_ty_1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).r) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).r) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -47,10 +45,7 @@ fn bindgen_test_layout_color__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).g) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).g) as usize - ptr as usize }, 1usize, concat!( "Offset of field: ", @@ -60,10 +55,7 @@ fn bindgen_test_layout_color__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 2usize, concat!( "Offset of field: ", @@ -84,6 +76,7 @@ pub struct color__bindgen_ty_2 { fn bindgen_test_layout_color__bindgen_ty_2() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 3usize, @@ -95,10 +88,7 @@ fn bindgen_test_layout_color__bindgen_ty_2() { concat!("Alignment of ", stringify!(color__bindgen_ty_2)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -108,10 +98,7 @@ fn bindgen_test_layout_color__bindgen_ty_2() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize }, 1usize, concat!( "Offset of field: ", @@ -121,10 +108,7 @@ fn bindgen_test_layout_color__bindgen_ty_2() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).v) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).v) as usize - ptr as usize }, 2usize, concat!( "Offset of field: ", @@ -138,6 +122,7 @@ fn bindgen_test_layout_color__bindgen_ty_2() { fn bindgen_test_layout_color() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 3usize, @@ -149,10 +134,7 @@ fn bindgen_test_layout_color() { concat!("Alignment of ", stringify!(color)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).v3) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).v3) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(color), "::", stringify!(v3)) ); diff --git a/tests/expectations/tests/anon_enum.rs b/tests/expectations/tests/anon_enum.rs index bf643e998c..429f94cedb 100644 --- a/tests/expectations/tests/anon_enum.rs +++ b/tests/expectations/tests/anon_enum.rs @@ -21,6 +21,7 @@ pub enum Test__bindgen_ty_1 { fn bindgen_test_layout_Test() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -32,18 +33,12 @@ fn bindgen_test_layout_Test() { concat!("Alignment of ", stringify!(Test)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 4usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/anon_struct_in_union.rs b/tests/expectations/tests/anon_struct_in_union.rs index 15ec9221fe..f32b057b27 100644 --- a/tests/expectations/tests/anon_struct_in_union.rs +++ b/tests/expectations/tests/anon_struct_in_union.rs @@ -24,6 +24,7 @@ pub struct s__bindgen_ty_1_inner { fn bindgen_test_layout_s__bindgen_ty_1_inner() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -35,10 +36,7 @@ fn bindgen_test_layout_s__bindgen_ty_1_inner() { concat!("Alignment of ", stringify!(s__bindgen_ty_1_inner)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -52,6 +50,7 @@ fn bindgen_test_layout_s__bindgen_ty_1_inner() { fn bindgen_test_layout_s__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -63,10 +62,7 @@ fn bindgen_test_layout_s__bindgen_ty_1() { concat!("Alignment of ", stringify!(s__bindgen_ty_1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).field) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).field) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -89,6 +85,7 @@ impl Default for s__bindgen_ty_1 { 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::(), 4usize, @@ -100,10 +97,7 @@ fn bindgen_test_layout_s() { concat!("Alignment of ", stringify!(s)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(s), "::", stringify!(u)) ); diff --git a/tests/expectations/tests/anon_struct_in_union_1_0.rs b/tests/expectations/tests/anon_struct_in_union_1_0.rs index 8b04ea03a1..cbc5ac9b3f 100644 --- a/tests/expectations/tests/anon_struct_in_union_1_0.rs +++ b/tests/expectations/tests/anon_struct_in_union_1_0.rs @@ -68,6 +68,7 @@ pub struct s__bindgen_ty_1_inner { fn bindgen_test_layout_s__bindgen_ty_1_inner() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -79,10 +80,7 @@ fn bindgen_test_layout_s__bindgen_ty_1_inner() { concat!("Alignment of ", stringify!(s__bindgen_ty_1_inner)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -101,6 +99,7 @@ impl Clone for s__bindgen_ty_1_inner { fn bindgen_test_layout_s__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -112,10 +111,7 @@ fn bindgen_test_layout_s__bindgen_ty_1() { concat!("Alignment of ", stringify!(s__bindgen_ty_1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).field) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).field) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -134,6 +130,7 @@ impl Clone for s__bindgen_ty_1 { 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::(), 4usize, @@ -145,10 +142,7 @@ fn bindgen_test_layout_s() { concat!("Alignment of ", stringify!(s)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(s), "::", stringify!(u)) ); diff --git a/tests/expectations/tests/array-of-zero-sized-types.rs b/tests/expectations/tests/array-of-zero-sized-types.rs index aed6386a6a..ad1f22ed1f 100644 --- a/tests/expectations/tests/array-of-zero-sized-types.rs +++ b/tests/expectations/tests/array-of-zero-sized-types.rs @@ -35,6 +35,7 @@ pub struct HasArrayOfEmpty { fn bindgen_test_layout_HasArrayOfEmpty() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 10usize, @@ -46,10 +47,7 @@ fn bindgen_test_layout_HasArrayOfEmpty() { concat!("Alignment of ", stringify!(HasArrayOfEmpty)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).empties) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).empties) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/bindgen-union-inside-namespace.rs b/tests/expectations/tests/bindgen-union-inside-namespace.rs index fa20e6f754..8a091cb5e2 100644 --- a/tests/expectations/tests/bindgen-union-inside-namespace.rs +++ b/tests/expectations/tests/bindgen-union-inside-namespace.rs @@ -69,6 +69,7 @@ pub mod root { 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, @@ -81,7 +82,6 @@ pub mod root { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, 0usize, @@ -94,7 +94,6 @@ pub mod root { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, diff --git a/tests/expectations/tests/bitfield-linux-32.rs b/tests/expectations/tests/bitfield-linux-32.rs index b80f25145d..44c686265f 100644 --- a/tests/expectations/tests/bitfield-linux-32.rs +++ b/tests/expectations/tests/bitfield-linux-32.rs @@ -102,6 +102,7 @@ pub struct Test { fn bindgen_test_layout_Test() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -113,10 +114,7 @@ fn bindgen_test_layout_Test() { concat!("Alignment of ", stringify!(Test)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(foo)) ); diff --git a/tests/expectations/tests/bitfield_align.rs b/tests/expectations/tests/bitfield_align.rs index 0d67f44e9e..4baca11214 100644 --- a/tests/expectations/tests/bitfield_align.rs +++ b/tests/expectations/tests/bitfield_align.rs @@ -104,6 +104,7 @@ pub struct A { 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::(), 4usize, @@ -115,18 +116,12 @@ fn bindgen_test_layout_A() { concat!("Alignment of ", stringify!(A)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(x)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, 3usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(y)) ); @@ -397,6 +392,7 @@ pub struct C { 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::(), 8usize, @@ -408,18 +404,12 @@ fn bindgen_test_layout_C() { concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(x)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, 4usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(baz)) ); @@ -702,6 +692,7 @@ pub struct Date3 { fn bindgen_test_layout_Date3() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -713,10 +704,7 @@ fn bindgen_test_layout_Date3() { concat!("Alignment of ", stringify!(Date3)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).byte) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).byte) as usize - ptr as usize }, 3usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/blocklist-and-impl-debug.rs b/tests/expectations/tests/blocklist-and-impl-debug.rs index f72c59bbde..788cb30c4c 100644 --- a/tests/expectations/tests/blocklist-and-impl-debug.rs +++ b/tests/expectations/tests/blocklist-and-impl-debug.rs @@ -16,6 +16,7 @@ pub struct ShouldManuallyImplDebug { fn bindgen_test_layout_ShouldManuallyImplDebug() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -27,10 +28,7 @@ fn bindgen_test_layout_ShouldManuallyImplDebug() { concat!("Alignment of ", stringify!(ShouldManuallyImplDebug)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/blocklist-file.rs b/tests/expectations/tests/blocklist-file.rs index d897e5930f..4d2b67129a 100644 --- a/tests/expectations/tests/blocklist-file.rs +++ b/tests/expectations/tests/blocklist-file.rs @@ -16,6 +16,7 @@ pub struct SizedIntegers { fn bindgen_test_layout_SizedIntegers() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -27,10 +28,7 @@ fn bindgen_test_layout_SizedIntegers() { concat!("Alignment of ", stringify!(SizedIntegers)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -40,10 +38,7 @@ fn bindgen_test_layout_SizedIntegers() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, 2usize, concat!( "Offset of field: ", @@ -53,10 +48,7 @@ fn bindgen_test_layout_SizedIntegers() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).z) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).z) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -75,6 +67,7 @@ pub struct StructWithBlocklistedFwdDecl { fn bindgen_test_layout_StructWithBlocklistedFwdDecl() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -86,10 +79,7 @@ fn bindgen_test_layout_StructWithBlocklistedFwdDecl() { concat!("Alignment of ", stringify!(StructWithBlocklistedFwdDecl)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/blocks-signature.rs b/tests/expectations/tests/blocks-signature.rs index faf9521cd6..779d0ecbcc 100644 --- a/tests/expectations/tests/blocks-signature.rs +++ b/tests/expectations/tests/blocks-signature.rs @@ -39,6 +39,7 @@ pub struct contains_block_pointers { fn bindgen_test_layout_contains_block_pointers() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -50,10 +51,7 @@ fn bindgen_test_layout_contains_block_pointers() { concat!("Alignment of ", stringify!(contains_block_pointers)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).val) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).val) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -63,10 +61,7 @@ fn bindgen_test_layout_contains_block_pointers() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).ptr_val) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).ptr_val) as usize - ptr as usize }, 8usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/blocks.rs b/tests/expectations/tests/blocks.rs index da4d3e8577..dbafaf94c2 100644 --- a/tests/expectations/tests/blocks.rs +++ b/tests/expectations/tests/blocks.rs @@ -38,6 +38,7 @@ pub struct contains_block_pointers { fn bindgen_test_layout_contains_block_pointers() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -49,10 +50,7 @@ fn bindgen_test_layout_contains_block_pointers() { concat!("Alignment of ", stringify!(contains_block_pointers)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).val) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).val) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -62,10 +60,7 @@ fn bindgen_test_layout_contains_block_pointers() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).ptr_val) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).ptr_val) as usize - ptr as usize }, 8usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/c_naming.rs b/tests/expectations/tests/c_naming.rs index 6c221fcdfe..3e56b1d60a 100644 --- a/tests/expectations/tests/c_naming.rs +++ b/tests/expectations/tests/c_naming.rs @@ -14,6 +14,7 @@ pub struct struct_a { fn bindgen_test_layout_struct_a() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -25,10 +26,7 @@ fn bindgen_test_layout_struct_a() { concat!("Alignment of ", stringify!(struct_a)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -49,6 +47,7 @@ pub union union_b { fn bindgen_test_layout_union_b() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -60,10 +59,7 @@ fn bindgen_test_layout_union_b() { concat!("Alignment of ", stringify!(union_b)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -73,10 +69,7 @@ fn bindgen_test_layout_union_b() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/canonical-types.rs b/tests/expectations/tests/canonical-types.rs index b1b88f8ca6..a68e14244a 100644 --- a/tests/expectations/tests/canonical-types.rs +++ b/tests/expectations/tests/canonical-types.rs @@ -168,6 +168,7 @@ pub struct ClassAInner { fn bindgen_test_layout_ClassAInner() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -179,10 +180,7 @@ fn bindgen_test_layout_ClassAInner() { concat!("Alignment of ", stringify!(ClassAInner)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -210,6 +208,7 @@ pub struct ClassCInnerA { fn bindgen_test_layout_ClassCInnerA() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -221,10 +220,7 @@ fn bindgen_test_layout_ClassCInnerA() { concat!("Alignment of ", stringify!(ClassCInnerA)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -252,6 +248,7 @@ pub struct ClassCInnerB { fn bindgen_test_layout_ClassCInnerB() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -263,10 +260,7 @@ fn bindgen_test_layout_ClassCInnerB() { concat!("Alignment of ", stringify!(ClassCInnerB)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).cache) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).cache) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/char.rs b/tests/expectations/tests/char.rs index 99dbbc8529..960a681f6c 100644 --- a/tests/expectations/tests/char.rs +++ b/tests/expectations/tests/char.rs @@ -28,6 +28,7 @@ pub struct Test { fn bindgen_test_layout_Test() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 12usize, @@ -39,82 +40,52 @@ fn bindgen_test_layout_Test() { concat!("Alignment of ", stringify!(Test)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).ch) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).ch) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(ch)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize }, 1usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(u)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, 2usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(d)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).cch) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).cch) as usize - ptr as usize }, 3usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(cch)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).cu) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).cu) as usize - ptr as usize }, 4usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(cu)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).cd) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).cd) as usize - ptr as usize }, 5usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(cd)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).Cch) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).Cch) as usize - ptr as usize }, 6usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cch)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).Cu) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).Cu) as usize - ptr as usize }, 7usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cu)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).Cd) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).Cd) as usize - ptr as usize }, 8usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cd)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).Ccch) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).Ccch) as usize - ptr as usize }, 9usize, concat!( "Offset of field: ", @@ -124,18 +95,12 @@ fn bindgen_test_layout_Test() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).Ccu) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).Ccu) as usize - ptr as usize }, 10usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccu)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).Ccd) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).Ccd) as usize - ptr as usize }, 11usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccd)) ); diff --git a/tests/expectations/tests/class.rs b/tests/expectations/tests/class.rs index f26c77b74b..8542135b07 100644 --- a/tests/expectations/tests/class.rs +++ b/tests/expectations/tests/class.rs @@ -45,6 +45,7 @@ pub struct C { 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, @@ -56,16 +57,12 @@ fn bindgen_test_layout_C() { concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(a)) ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, 4usize, @@ -96,6 +93,7 @@ pub struct C_with_zero_length_array { 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, @@ -107,10 +105,7 @@ fn bindgen_test_layout_C_with_zero_length_array() { concat!("Alignment of ", stringify!(C_with_zero_length_array)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -121,7 +116,6 @@ fn bindgen_test_layout_C_with_zero_length_array() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, 4usize, @@ -134,7 +128,6 @@ fn bindgen_test_layout_C_with_zero_length_array() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize }, @@ -166,6 +159,7 @@ pub struct C_with_zero_length_array_2 { 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, @@ -177,10 +171,7 @@ fn bindgen_test_layout_C_with_zero_length_array_2() { concat!("Alignment of ", stringify!(C_with_zero_length_array_2)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -191,7 +182,6 @@ fn bindgen_test_layout_C_with_zero_length_array_2() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize }, @@ -323,6 +313,7 @@ pub struct WithDtor { 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, @@ -334,10 +325,7 @@ fn bindgen_test_layout_WithDtor() { concat!("Alignment of ", stringify!(WithDtor)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -384,6 +372,7 @@ pub union Union { 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, @@ -395,18 +384,12 @@ fn bindgen_test_layout_Union() { concat!("Alignment of ", stringify!(Union)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Union), "::", stringify!(d)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Union), "::", stringify!(i)) ); @@ -429,6 +412,7 @@ pub struct WithUnion { 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, @@ -440,10 +424,7 @@ fn bindgen_test_layout_WithUnion() { concat!("Alignment of ", stringify!(WithUnion)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/class_1_0.rs b/tests/expectations/tests/class_1_0.rs index c17e48d410..f6c3021eb3 100644 --- a/tests/expectations/tests/class_1_0.rs +++ b/tests/expectations/tests/class_1_0.rs @@ -88,6 +88,7 @@ pub struct C { 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, @@ -99,16 +100,12 @@ fn bindgen_test_layout_C() { concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(a)) ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, 4usize, @@ -149,6 +146,7 @@ pub struct C_with_zero_length_array { 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, @@ -160,10 +158,7 @@ fn bindgen_test_layout_C_with_zero_length_array() { concat!("Alignment of ", stringify!(C_with_zero_length_array)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -174,7 +169,6 @@ fn bindgen_test_layout_C_with_zero_length_array() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, 4usize, @@ -187,7 +181,6 @@ fn bindgen_test_layout_C_with_zero_length_array() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize }, @@ -219,6 +212,7 @@ pub struct C_with_zero_length_array_2 { 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, @@ -230,10 +224,7 @@ fn bindgen_test_layout_C_with_zero_length_array_2() { concat!("Alignment of ", stringify!(C_with_zero_length_array_2)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -244,7 +235,6 @@ fn bindgen_test_layout_C_with_zero_length_array_2() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize }, @@ -376,6 +366,7 @@ pub struct WithDtor { 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, @@ -387,10 +378,7 @@ fn bindgen_test_layout_WithDtor() { concat!("Alignment of ", stringify!(WithDtor)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -438,6 +426,7 @@ pub struct Union { 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, @@ -449,18 +438,12 @@ fn bindgen_test_layout_Union() { concat!("Alignment of ", stringify!(Union)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Union), "::", stringify!(d)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Union), "::", stringify!(i)) ); @@ -479,6 +462,7 @@ pub struct WithUnion { 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, @@ -490,10 +474,7 @@ fn bindgen_test_layout_WithUnion() { concat!("Alignment of ", stringify!(WithUnion)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/class_nested.rs b/tests/expectations/tests/class_nested.rs index 6e5b3f70ff..f2cc8326f9 100644 --- a/tests/expectations/tests/class_nested.rs +++ b/tests/expectations/tests/class_nested.rs @@ -19,6 +19,7 @@ pub struct A_B { fn bindgen_test_layout_A_B() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -31,7 +32,6 @@ fn bindgen_test_layout_A_B() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).member_b) as usize - ptr as usize }, 0usize, @@ -62,6 +62,7 @@ impl Default for A_D { 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::(), 4usize, @@ -74,7 +75,6 @@ fn bindgen_test_layout_A() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).member_a) as usize - ptr as usize }, 0usize, @@ -95,6 +95,7 @@ pub struct A_C { fn bindgen_test_layout_A_C() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -106,10 +107,7 @@ fn bindgen_test_layout_A_C() { concat!("Alignment of ", stringify!(A_C)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(A_C), "::", stringify!(baz)) ); @@ -148,6 +146,7 @@ pub struct D { 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::(), 4usize, @@ -159,10 +158,7 @@ fn bindgen_test_layout_D() { concat!("Alignment of ", stringify!(D)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(D), "::", stringify!(member)) ); diff --git a/tests/expectations/tests/class_no_members.rs b/tests/expectations/tests/class_no_members.rs index 951487452f..676590c829 100644 --- a/tests/expectations/tests/class_no_members.rs +++ b/tests/expectations/tests/class_no_members.rs @@ -50,6 +50,7 @@ pub struct whatever_child_with_member { fn bindgen_test_layout_whatever_child_with_member() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -62,7 +63,6 @@ fn bindgen_test_layout_whatever_child_with_member() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize }, 0usize, diff --git a/tests/expectations/tests/class_use_as.rs b/tests/expectations/tests/class_use_as.rs index d73a7f1cfa..ef130c16c6 100644 --- a/tests/expectations/tests/class_use_as.rs +++ b/tests/expectations/tests/class_use_as.rs @@ -15,6 +15,7 @@ pub struct whatever { fn bindgen_test_layout_whatever() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -27,7 +28,6 @@ fn bindgen_test_layout_whatever() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).replacement) as usize - ptr as usize }, 0usize, @@ -48,6 +48,7 @@ pub struct container { fn bindgen_test_layout_container() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -59,10 +60,7 @@ fn bindgen_test_layout_container() { concat!("Alignment of ", stringify!(container)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/class_with_dtor.rs b/tests/expectations/tests/class_with_dtor.rs index 78dd37d4ec..86d2a576db 100644 --- a/tests/expectations/tests/class_with_dtor.rs +++ b/tests/expectations/tests/class_with_dtor.rs @@ -30,6 +30,7 @@ pub struct WithoutDtor { fn bindgen_test_layout_WithoutDtor() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -42,7 +43,6 @@ fn bindgen_test_layout_WithoutDtor() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).shouldBeWithDtor) as usize - ptr as usize }, diff --git a/tests/expectations/tests/class_with_inner_struct.rs b/tests/expectations/tests/class_with_inner_struct.rs index c8b36e9d8a..eab9d59825 100644 --- a/tests/expectations/tests/class_with_inner_struct.rs +++ b/tests/expectations/tests/class_with_inner_struct.rs @@ -22,6 +22,7 @@ pub struct A_Segment { fn bindgen_test_layout_A_Segment() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -33,10 +34,7 @@ fn bindgen_test_layout_A_Segment() { concat!("Alignment of ", stringify!(A_Segment)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -46,10 +44,7 @@ fn bindgen_test_layout_A_Segment() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -68,6 +63,7 @@ pub union A__bindgen_ty_1 { fn bindgen_test_layout_A__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -79,10 +75,7 @@ fn bindgen_test_layout_A__bindgen_ty_1() { concat!("Alignment of ", stringify!(A__bindgen_ty_1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -110,6 +103,7 @@ pub union A__bindgen_ty_2 { fn bindgen_test_layout_A__bindgen_ty_2() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -121,10 +115,7 @@ fn bindgen_test_layout_A__bindgen_ty_2() { concat!("Alignment of ", stringify!(A__bindgen_ty_2)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -147,6 +138,7 @@ impl Default for A__bindgen_ty_2 { 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::(), 12usize, @@ -158,16 +150,12 @@ fn bindgen_test_layout_A() { concat!("Alignment of ", stringify!(A)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(c)) ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).named_union) as usize - ptr as usize }, 4usize, @@ -203,6 +191,7 @@ pub struct B_Segment { fn bindgen_test_layout_B_Segment() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -214,10 +203,7 @@ fn bindgen_test_layout_B_Segment() { concat!("Alignment of ", stringify!(B_Segment)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -227,10 +213,7 @@ fn bindgen_test_layout_B_Segment() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -244,6 +227,7 @@ fn bindgen_test_layout_B_Segment() { 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::(), 4usize, @@ -255,10 +239,7 @@ fn bindgen_test_layout_B() { concat!("Alignment of ", stringify!(B)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(B), "::", stringify!(d)) ); @@ -295,6 +276,7 @@ pub struct C__bindgen_ty_1__bindgen_ty_1 { fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -306,10 +288,7 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_1() { concat!("Alignment of ", stringify!(C__bindgen_ty_1__bindgen_ty_1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mX1) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mX1) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -319,10 +298,7 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mY1) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mY1) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -332,10 +308,7 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mX2) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mX2) as usize - ptr as usize }, 8usize, concat!( "Offset of field: ", @@ -345,10 +318,7 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mY2) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mY2) as usize - ptr as usize }, 12usize, concat!( "Offset of field: ", @@ -368,6 +338,7 @@ pub struct C__bindgen_ty_1__bindgen_ty_2 { fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_2() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -380,7 +351,6 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_2() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mStepSyntax) as usize - ptr as usize }, 0usize, @@ -392,10 +362,7 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_2() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mSteps) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mSteps) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -418,6 +385,7 @@ impl Default for C__bindgen_ty_1__bindgen_ty_2 { fn bindgen_test_layout_C__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -429,10 +397,7 @@ fn bindgen_test_layout_C__bindgen_ty_1() { concat!("Alignment of ", stringify!(C__bindgen_ty_1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mFunc) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mFunc) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -461,6 +426,7 @@ pub struct C_Segment { fn bindgen_test_layout_C_Segment() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -472,10 +438,7 @@ fn bindgen_test_layout_C_Segment() { concat!("Alignment of ", stringify!(C_Segment)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -485,10 +448,7 @@ fn bindgen_test_layout_C_Segment() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -502,6 +462,7 @@ fn bindgen_test_layout_C_Segment() { 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::(), 20usize, @@ -513,10 +474,7 @@ fn bindgen_test_layout_C() { concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(d)) ); diff --git a/tests/expectations/tests/class_with_inner_struct_1_0.rs b/tests/expectations/tests/class_with_inner_struct_1_0.rs index 5a3116fd1d..42656079df 100644 --- a/tests/expectations/tests/class_with_inner_struct_1_0.rs +++ b/tests/expectations/tests/class_with_inner_struct_1_0.rs @@ -65,6 +65,7 @@ pub struct A_Segment { fn bindgen_test_layout_A_Segment() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -76,10 +77,7 @@ fn bindgen_test_layout_A_Segment() { concat!("Alignment of ", stringify!(A_Segment)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -89,10 +87,7 @@ fn bindgen_test_layout_A_Segment() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -117,6 +112,7 @@ pub struct A__bindgen_ty_1 { fn bindgen_test_layout_A__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -128,10 +124,7 @@ fn bindgen_test_layout_A__bindgen_ty_1() { concat!("Alignment of ", stringify!(A__bindgen_ty_1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -156,6 +149,7 @@ pub struct A__bindgen_ty_2 { fn bindgen_test_layout_A__bindgen_ty_2() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -167,10 +161,7 @@ fn bindgen_test_layout_A__bindgen_ty_2() { concat!("Alignment of ", stringify!(A__bindgen_ty_2)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -189,6 +180,7 @@ impl Clone for A__bindgen_ty_2 { 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::(), 12usize, @@ -200,16 +192,12 @@ fn bindgen_test_layout_A() { concat!("Alignment of ", stringify!(A)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(c)) ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).named_union) as usize - ptr as usize }, 4usize, @@ -241,6 +229,7 @@ pub struct B_Segment { fn bindgen_test_layout_B_Segment() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -252,10 +241,7 @@ fn bindgen_test_layout_B_Segment() { concat!("Alignment of ", stringify!(B_Segment)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -265,10 +251,7 @@ fn bindgen_test_layout_B_Segment() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -287,6 +270,7 @@ impl Clone for B_Segment { 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::(), 4usize, @@ -298,10 +282,7 @@ fn bindgen_test_layout_B() { concat!("Alignment of ", stringify!(B)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(B), "::", stringify!(d)) ); @@ -344,6 +325,7 @@ pub struct C__bindgen_ty_1__bindgen_ty_1 { fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -355,10 +337,7 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_1() { concat!("Alignment of ", stringify!(C__bindgen_ty_1__bindgen_ty_1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mX1) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mX1) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -368,10 +347,7 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mY1) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mY1) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -381,10 +357,7 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mX2) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mX2) as usize - ptr as usize }, 8usize, concat!( "Offset of field: ", @@ -394,10 +367,7 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mY2) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mY2) as usize - ptr as usize }, 12usize, concat!( "Offset of field: ", @@ -422,6 +392,7 @@ pub struct C__bindgen_ty_1__bindgen_ty_2 { fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_2() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -434,7 +405,6 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_2() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mStepSyntax) as usize - ptr as usize }, 0usize, @@ -446,10 +416,7 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_2() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mSteps) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mSteps) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -477,6 +444,7 @@ impl Default for C__bindgen_ty_1__bindgen_ty_2 { fn bindgen_test_layout_C__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -488,10 +456,7 @@ fn bindgen_test_layout_C__bindgen_ty_1() { concat!("Alignment of ", stringify!(C__bindgen_ty_1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mFunc) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mFunc) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -516,6 +481,7 @@ pub struct C_Segment { fn bindgen_test_layout_C_Segment() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -527,10 +493,7 @@ fn bindgen_test_layout_C_Segment() { concat!("Alignment of ", stringify!(C_Segment)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -540,10 +503,7 @@ fn bindgen_test_layout_C_Segment() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -562,6 +522,7 @@ impl Clone for C_Segment { 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::(), 20usize, @@ -573,10 +534,7 @@ fn bindgen_test_layout_C() { concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(d)) ); diff --git a/tests/expectations/tests/class_with_typedef.rs b/tests/expectations/tests/class_with_typedef.rs index 74b938e6cf..65e86b2709 100644 --- a/tests/expectations/tests/class_with_typedef.rs +++ b/tests/expectations/tests/class_with_typedef.rs @@ -21,6 +21,7 @@ pub type C_Lookup = *const ::std::os::raw::c_char; 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::(), 72usize, @@ -32,40 +33,27 @@ fn bindgen_test_layout_C() { concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(c)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize }, 8usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(ptr)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize }, 16usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(arr)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, 56usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(d)) ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).other_ptr) as usize - ptr as usize }, 64usize, @@ -130,6 +118,7 @@ pub struct D { 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::(), 80usize, @@ -141,10 +130,7 @@ fn bindgen_test_layout_D() { concat!("Alignment of ", stringify!(D)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize }, 72usize, concat!("Offset of field: ", stringify!(D), "::", stringify!(ptr)) ); diff --git a/tests/expectations/tests/comment-indent.rs b/tests/expectations/tests/comment-indent.rs index e02bfee0af..3ad221aa3d 100644 --- a/tests/expectations/tests/comment-indent.rs +++ b/tests/expectations/tests/comment-indent.rs @@ -72,6 +72,7 @@ pub mod root { 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::(), 4usize, @@ -84,7 +85,6 @@ pub mod root { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, 0usize, diff --git a/tests/expectations/tests/complex.rs b/tests/expectations/tests/complex.rs index c5633a6cec..e9c4be9d44 100644 --- a/tests/expectations/tests/complex.rs +++ b/tests/expectations/tests/complex.rs @@ -20,6 +20,7 @@ pub struct TestDouble { fn bindgen_test_layout_TestDouble() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -31,10 +32,7 @@ fn bindgen_test_layout_TestDouble() { concat!("Alignment of ", stringify!(TestDouble)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -53,6 +51,7 @@ pub struct TestDoublePtr { fn bindgen_test_layout_TestDoublePtr() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -64,10 +63,7 @@ fn bindgen_test_layout_TestDoublePtr() { concat!("Alignment of ", stringify!(TestDoublePtr)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -95,6 +91,7 @@ pub struct TestFloat { fn bindgen_test_layout_TestFloat() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -106,10 +103,7 @@ fn bindgen_test_layout_TestFloat() { concat!("Alignment of ", stringify!(TestFloat)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -128,6 +122,7 @@ pub struct TestFloatPtr { fn bindgen_test_layout_TestFloatPtr() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -139,10 +134,7 @@ fn bindgen_test_layout_TestFloatPtr() { concat!("Alignment of ", stringify!(TestFloatPtr)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/const-const-mut-ptr.rs b/tests/expectations/tests/const-const-mut-ptr.rs index 5e0c7800f4..e8f13dff82 100644 --- a/tests/expectations/tests/const-const-mut-ptr.rs +++ b/tests/expectations/tests/const-const-mut-ptr.rs @@ -14,6 +14,7 @@ pub struct foo { 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::(), 8usize, @@ -25,10 +26,7 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/constified-enum-module-overflow.rs b/tests/expectations/tests/constified-enum-module-overflow.rs index ab81b17362..d47338f142 100644 --- a/tests/expectations/tests/constified-enum-module-overflow.rs +++ b/tests/expectations/tests/constified-enum-module-overflow.rs @@ -25,6 +25,7 @@ pub struct A { 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::(), 1usize, @@ -36,10 +37,7 @@ fn bindgen_test_layout_A() { concat!("Alignment of ", stringify!(A)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(u)) ); diff --git a/tests/expectations/tests/constify-all-enums.rs b/tests/expectations/tests/constify-all-enums.rs index bfa255d6f9..e3c82156f5 100644 --- a/tests/expectations/tests/constify-all-enums.rs +++ b/tests/expectations/tests/constify-all-enums.rs @@ -18,6 +18,7 @@ pub struct bar { 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, @@ -30,7 +31,6 @@ fn bindgen_test_layout_bar() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).this_should_work) as usize - ptr as usize }, diff --git a/tests/expectations/tests/constify-module-enums-basic.rs b/tests/expectations/tests/constify-module-enums-basic.rs index e74eb4433c..c5c32983b0 100644 --- a/tests/expectations/tests/constify-module-enums-basic.rs +++ b/tests/expectations/tests/constify-module-enums-basic.rs @@ -22,6 +22,7 @@ pub struct bar { 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, @@ -34,7 +35,6 @@ fn bindgen_test_layout_bar() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).this_should_work) as usize - ptr as usize }, diff --git a/tests/expectations/tests/constify-module-enums-namespace.rs b/tests/expectations/tests/constify-module-enums-namespace.rs index 30955dfe9d..0b8eec1eab 100644 --- a/tests/expectations/tests/constify-module-enums-namespace.rs +++ b/tests/expectations/tests/constify-module-enums-namespace.rs @@ -34,6 +34,7 @@ pub mod root { 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, @@ -46,7 +47,6 @@ pub mod root { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).this_should_work) as usize - ptr as usize }, diff --git a/tests/expectations/tests/constify-module-enums-shadow-name.rs b/tests/expectations/tests/constify-module-enums-shadow-name.rs index 21283c1cba..44643d0fff 100644 --- a/tests/expectations/tests/constify-module-enums-shadow-name.rs +++ b/tests/expectations/tests/constify-module-enums-shadow-name.rs @@ -21,6 +21,7 @@ pub struct bar { 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, @@ -32,10 +33,7 @@ fn bindgen_test_layout_bar() { concat!("Alignment of ", stringify!(bar)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/constify-module-enums-simple-alias.rs b/tests/expectations/tests/constify-module-enums-simple-alias.rs index 736a88801a..0262b128e4 100644 --- a/tests/expectations/tests/constify-module-enums-simple-alias.rs +++ b/tests/expectations/tests/constify-module-enums-simple-alias.rs @@ -30,6 +30,7 @@ pub struct Bar { 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::(), 48usize, @@ -41,40 +42,27 @@ fn bindgen_test_layout_Bar() { concat!("Alignment of ", stringify!(Bar)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz1) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).baz1) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz2) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).baz2) as usize - ptr as usize }, 4usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz2)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz3) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).baz3) as usize - ptr as usize }, 8usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz3)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz4) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).baz4) as usize - ptr as usize }, 12usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz4)) ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).baz_ptr1) as usize - ptr as usize }, 16usize, @@ -87,7 +75,6 @@ fn bindgen_test_layout_Bar() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).baz_ptr2) as usize - ptr as usize }, 24usize, @@ -100,7 +87,6 @@ fn bindgen_test_layout_Bar() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).baz_ptr3) as usize - ptr as usize }, 32usize, @@ -113,7 +99,6 @@ fn bindgen_test_layout_Bar() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).baz_ptr4) as usize - ptr as usize }, 40usize, diff --git a/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs b/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs index 71dc1d7011..75ebf48acf 100644 --- a/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs +++ b/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs @@ -20,6 +20,7 @@ pub struct Bar { 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, @@ -31,18 +32,12 @@ fn bindgen_test_layout_Bar() { concat!("Alignment of ", stringify!(Bar)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz1) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).baz1) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz2) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).baz2) as usize - ptr as usize }, 8usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz2)) ); diff --git a/tests/expectations/tests/constify-module-enums-types.rs b/tests/expectations/tests/constify-module-enums-types.rs index d22e206543..c3c6d3ca00 100644 --- a/tests/expectations/tests/constify-module-enums-types.rs +++ b/tests/expectations/tests/constify-module-enums-types.rs @@ -55,6 +55,7 @@ pub struct bar { 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::(), 48usize, @@ -66,10 +67,7 @@ fn bindgen_test_layout_bar() { concat!("Alignment of ", stringify!(bar)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).member1) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).member1) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -79,10 +77,7 @@ fn bindgen_test_layout_bar() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).member2) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).member2) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -92,10 +87,7 @@ fn bindgen_test_layout_bar() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).member3) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).member3) as usize - ptr as usize }, 8usize, concat!( "Offset of field: ", @@ -105,10 +97,7 @@ fn bindgen_test_layout_bar() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).member4) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).member4) as usize - ptr as usize }, 12usize, concat!( "Offset of field: ", @@ -118,10 +107,7 @@ fn bindgen_test_layout_bar() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).member5) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).member5) as usize - ptr as usize }, 16usize, concat!( "Offset of field: ", @@ -131,10 +117,7 @@ fn bindgen_test_layout_bar() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).member6) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).member6) as usize - ptr as usize }, 24usize, concat!( "Offset of field: ", @@ -144,10 +127,7 @@ fn bindgen_test_layout_bar() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).member7) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).member7) as usize - ptr as usize }, 32usize, concat!( "Offset of field: ", @@ -157,10 +137,7 @@ fn bindgen_test_layout_bar() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).member8) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).member8) as usize - ptr as usize }, 36usize, concat!( "Offset of field: ", @@ -170,10 +147,7 @@ fn bindgen_test_layout_bar() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).member9) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).member9) as usize - ptr as usize }, 40usize, concat!( "Offset of field: ", @@ -184,7 +158,6 @@ fn bindgen_test_layout_bar() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).member10) as usize - ptr as usize }, 44usize, @@ -214,6 +187,7 @@ pub struct Baz { 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::(), 4usize, @@ -225,10 +199,7 @@ fn bindgen_test_layout_Baz() { concat!("Alignment of ", stringify!(Baz)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).member1) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).member1) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -261,6 +232,7 @@ pub struct Bar { 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::(), 8usize, @@ -272,10 +244,7 @@ fn bindgen_test_layout_Bar() { concat!("Alignment of ", stringify!(Bar)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz)) ); diff --git a/tests/expectations/tests/contains-vs-inherits-zero-sized.rs b/tests/expectations/tests/contains-vs-inherits-zero-sized.rs index 3a0f5586d4..62fc374946 100644 --- a/tests/expectations/tests/contains-vs-inherits-zero-sized.rs +++ b/tests/expectations/tests/contains-vs-inherits-zero-sized.rs @@ -35,6 +35,7 @@ pub struct Inherits { fn bindgen_test_layout_Inherits() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -46,10 +47,7 @@ fn bindgen_test_layout_Inherits() { concat!("Alignment of ", stringify!(Inherits)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -71,6 +69,7 @@ pub struct Contains { fn bindgen_test_layout_Contains() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 2usize, @@ -82,10 +81,7 @@ fn bindgen_test_layout_Contains() { concat!("Alignment of ", stringify!(Contains)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).empty) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).empty) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -95,10 +91,7 @@ fn bindgen_test_layout_Contains() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 1usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/convert-floats.rs b/tests/expectations/tests/convert-floats.rs index bd9ed3c800..e710a442e2 100644 --- a/tests/expectations/tests/convert-floats.rs +++ b/tests/expectations/tests/convert-floats.rs @@ -25,6 +25,7 @@ pub struct foo { 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::(), 48usize, @@ -36,34 +37,22 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, 4usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(baz)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).bazz) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).bazz) as usize - ptr as usize }, 8usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bazz)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).bazzz) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).bazzz) as usize - ptr as usize }, 16usize, concat!( "Offset of field: ", @@ -74,7 +63,6 @@ fn bindgen_test_layout_foo() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).complexFloat) as usize - ptr as usize }, 24usize, @@ -87,7 +75,6 @@ fn bindgen_test_layout_foo() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).complexDouble) as usize - ptr as usize }, 32usize, diff --git a/tests/expectations/tests/ctypes-prefix-path.rs b/tests/expectations/tests/ctypes-prefix-path.rs index 203f075948..5b3d186a33 100644 --- a/tests/expectations/tests/ctypes-prefix-path.rs +++ b/tests/expectations/tests/ctypes-prefix-path.rs @@ -23,6 +23,7 @@ pub struct foo { fn bindgen_test_layout_foo() { const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::core::mem::size_of::(), 16usize, @@ -34,26 +35,17 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::core::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::core::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::core::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::core::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 4usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, + unsafe { ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 8usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/derive-bitfield-method-same-name.rs b/tests/expectations/tests/derive-bitfield-method-same-name.rs index 6b84111b70..ea6621dd1c 100644 --- a/tests/expectations/tests/derive-bitfield-method-same-name.rs +++ b/tests/expectations/tests/derive-bitfield-method-same-name.rs @@ -106,6 +106,7 @@ pub struct Foo { 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, @@ -117,10 +118,7 @@ fn bindgen_test_layout_Foo() { concat!("Alignment of ", stringify!(Foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).large) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).large) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/derive-clone.rs b/tests/expectations/tests/derive-clone.rs index 6bdf35df00..19c28b697f 100644 --- a/tests/expectations/tests/derive-clone.rs +++ b/tests/expectations/tests/derive-clone.rs @@ -15,6 +15,7 @@ pub struct ShouldDeriveClone { 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, @@ -26,10 +27,7 @@ fn bindgen_test_layout_ShouldDeriveClone() { concat!("Alignment of ", stringify!(ShouldDeriveClone)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).large) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).large) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/derive-clone_1_0.rs b/tests/expectations/tests/derive-clone_1_0.rs index 590e663715..3d72db2f89 100644 --- a/tests/expectations/tests/derive-clone_1_0.rs +++ b/tests/expectations/tests/derive-clone_1_0.rs @@ -16,6 +16,7 @@ pub struct ShouldImplClone { fn bindgen_test_layout_ShouldImplClone() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 132usize, @@ -27,10 +28,7 @@ fn bindgen_test_layout_ShouldImplClone() { concat!("Alignment of ", stringify!(ShouldImplClone)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).large) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).large) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/derive-debug-bitfield-core.rs b/tests/expectations/tests/derive-debug-bitfield-core.rs index b3cacd105e..2a78e93050 100644 --- a/tests/expectations/tests/derive-debug-bitfield-core.rs +++ b/tests/expectations/tests/derive-debug-bitfield-core.rs @@ -104,6 +104,7 @@ pub struct C { 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, @@ -116,7 +117,6 @@ fn bindgen_test_layout_C() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::core::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize }, 4usize, diff --git a/tests/expectations/tests/derive-debug-bitfield.rs b/tests/expectations/tests/derive-debug-bitfield.rs index 1805335a35..0ae8f32968 100644 --- a/tests/expectations/tests/derive-debug-bitfield.rs +++ b/tests/expectations/tests/derive-debug-bitfield.rs @@ -102,6 +102,7 @@ pub struct C { 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, @@ -114,7 +115,6 @@ fn bindgen_test_layout_C() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize }, 4usize, diff --git a/tests/expectations/tests/derive-debug-function-pointer.rs b/tests/expectations/tests/derive-debug-function-pointer.rs index 9b0df65065..16b127bf14 100644 --- a/tests/expectations/tests/derive-debug-function-pointer.rs +++ b/tests/expectations/tests/derive-debug-function-pointer.rs @@ -17,6 +17,7 @@ pub type Nice_Function = 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, @@ -28,10 +29,7 @@ fn bindgen_test_layout_Nice() { concat!("Alignment of ", stringify!(Nice)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).pointer) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).pointer) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -42,7 +40,6 @@ fn bindgen_test_layout_Nice() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize }, 8usize, diff --git a/tests/expectations/tests/derive-debug-mangle-name.rs b/tests/expectations/tests/derive-debug-mangle-name.rs index 30c7f816bc..a757d679b0 100644 --- a/tests/expectations/tests/derive-debug-mangle-name.rs +++ b/tests/expectations/tests/derive-debug-mangle-name.rs @@ -22,6 +22,7 @@ pub union perf_event_attr__bindgen_ty_1 { fn bindgen_test_layout_perf_event_attr__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -33,10 +34,7 @@ fn bindgen_test_layout_perf_event_attr__bindgen_ty_1() { concat!("Alignment of ", stringify!(perf_event_attr__bindgen_ty_1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -46,10 +44,7 @@ fn bindgen_test_layout_perf_event_attr__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -77,6 +72,7 @@ impl ::std::fmt::Debug for perf_event_attr__bindgen_ty_1 { fn bindgen_test_layout_perf_event_attr() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 12usize, @@ -88,10 +84,7 @@ fn bindgen_test_layout_perf_event_attr() { concat!("Alignment of ", stringify!(perf_event_attr)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -101,10 +94,7 @@ fn bindgen_test_layout_perf_event_attr() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/derive-debug-opaque-template-instantiation.rs b/tests/expectations/tests/derive-debug-opaque-template-instantiation.rs index 1242df834d..a0cc87ff2c 100644 --- a/tests/expectations/tests/derive-debug-opaque-template-instantiation.rs +++ b/tests/expectations/tests/derive-debug-opaque-template-instantiation.rs @@ -13,6 +13,7 @@ pub struct Instance { 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, @@ -24,10 +25,7 @@ fn bindgen_test_layout_Instance() { concat!("Alignment of ", stringify!(Instance)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).val) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).val) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/derive-debug-opaque.rs b/tests/expectations/tests/derive-debug-opaque.rs index 0fe6b73c17..5cebc9b8e6 100644 --- a/tests/expectations/tests/derive-debug-opaque.rs +++ b/tests/expectations/tests/derive-debug-opaque.rs @@ -45,6 +45,7 @@ pub struct OpaqueUser { 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, @@ -56,10 +57,7 @@ fn bindgen_test_layout_OpaqueUser() { concat!("Alignment of ", stringify!(OpaqueUser)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).opaque) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).opaque) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/derive-default-and-blocklist.rs b/tests/expectations/tests/derive-default-and-blocklist.rs index c50e2df2a9..fe3790c2e0 100644 --- a/tests/expectations/tests/derive-default-and-blocklist.rs +++ b/tests/expectations/tests/derive-default-and-blocklist.rs @@ -17,6 +17,7 @@ pub struct ShouldNotDeriveDefault { fn bindgen_test_layout_ShouldNotDeriveDefault() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -28,10 +29,7 @@ fn bindgen_test_layout_ShouldNotDeriveDefault() { concat!("Alignment of ", stringify!(ShouldNotDeriveDefault)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/derive-fn-ptr.rs b/tests/expectations/tests/derive-fn-ptr.rs index 4ce06e048d..9da0a40ae6 100644 --- a/tests/expectations/tests/derive-fn-ptr.rs +++ b/tests/expectations/tests/derive-fn-ptr.rs @@ -34,6 +34,7 @@ pub struct Foo { 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::(), 8usize, @@ -46,7 +47,6 @@ fn bindgen_test_layout_Foo() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).callback) as usize - ptr as usize }, 0usize, @@ -83,6 +83,7 @@ pub struct Bar { 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::(), 8usize, @@ -95,7 +96,6 @@ fn bindgen_test_layout_Bar() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).callback) as usize - ptr as usize }, 0usize, diff --git a/tests/expectations/tests/derive-hash-and-blocklist.rs b/tests/expectations/tests/derive-hash-and-blocklist.rs index 27cb8312e9..c677b15e49 100644 --- a/tests/expectations/tests/derive-hash-and-blocklist.rs +++ b/tests/expectations/tests/derive-hash-and-blocklist.rs @@ -16,6 +16,7 @@ pub struct ShouldNotDeriveHash { fn bindgen_test_layout_ShouldNotDeriveHash() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -27,10 +28,7 @@ fn bindgen_test_layout_ShouldNotDeriveHash() { concat!("Alignment of ", stringify!(ShouldNotDeriveHash)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/derive-hash-blocklisting.rs b/tests/expectations/tests/derive-hash-blocklisting.rs index b00da661ef..868bf9f2a9 100644 --- a/tests/expectations/tests/derive-hash-blocklisting.rs +++ b/tests/expectations/tests/derive-hash-blocklisting.rs @@ -22,6 +22,7 @@ pub struct AllowlistedOne { fn bindgen_test_layout_AllowlistedOne() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -33,10 +34,7 @@ fn bindgen_test_layout_AllowlistedOne() { concat!("Alignment of ", stringify!(AllowlistedOne)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -64,6 +62,7 @@ pub struct AllowlistedTwo { fn bindgen_test_layout_AllowlistedTwo() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -75,10 +74,7 @@ fn bindgen_test_layout_AllowlistedTwo() { concat!("Alignment of ", stringify!(AllowlistedTwo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs b/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs index d0860e58bb..78c8449b58 100644 --- a/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs +++ b/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs @@ -21,6 +21,7 @@ pub struct foo__bindgen_ty_1 { fn bindgen_test_layout_foo__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -32,10 +33,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -45,10 +43,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -62,6 +57,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 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::(), 8usize, @@ -73,10 +69,7 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/derive-hash-struct-with-float-array.rs b/tests/expectations/tests/derive-hash-struct-with-float-array.rs index 2a7168dde3..a3f6013b2a 100644 --- a/tests/expectations/tests/derive-hash-struct-with-float-array.rs +++ b/tests/expectations/tests/derive-hash-struct-with-float-array.rs @@ -15,6 +15,7 @@ pub struct foo { 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::(), 12usize, @@ -26,10 +27,7 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs b/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs index 48fc7ed1a7..06c8da1bad 100644 --- a/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs +++ b/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs @@ -45,6 +45,7 @@ pub struct test { fn bindgen_test_layout_test() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -56,16 +57,12 @@ fn bindgen_test_layout_test() { concat!("Alignment of ", stringify!(test)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(test), "::", stringify!(a)) ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize }, diff --git a/tests/expectations/tests/derive-hash-struct-with-pointer.rs b/tests/expectations/tests/derive-hash-struct-with-pointer.rs index 7bda695bac..3efd55c9d2 100644 --- a/tests/expectations/tests/derive-hash-struct-with-pointer.rs +++ b/tests/expectations/tests/derive-hash-struct-with-pointer.rs @@ -15,6 +15,7 @@ pub struct ConstPtrMutObj { fn bindgen_test_layout_ConstPtrMutObj() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -26,10 +27,7 @@ fn bindgen_test_layout_ConstPtrMutObj() { concat!("Alignment of ", stringify!(ConstPtrMutObj)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -57,6 +55,7 @@ pub struct MutPtrMutObj { fn bindgen_test_layout_MutPtrMutObj() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -68,10 +67,7 @@ fn bindgen_test_layout_MutPtrMutObj() { concat!("Alignment of ", stringify!(MutPtrMutObj)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -99,6 +95,7 @@ pub struct MutPtrConstObj { fn bindgen_test_layout_MutPtrConstObj() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -110,10 +107,7 @@ fn bindgen_test_layout_MutPtrConstObj() { concat!("Alignment of ", stringify!(MutPtrConstObj)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -141,6 +135,7 @@ pub struct ConstPtrConstObj { fn bindgen_test_layout_ConstPtrConstObj() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -152,10 +147,7 @@ fn bindgen_test_layout_ConstPtrConstObj() { concat!("Alignment of ", stringify!(ConstPtrConstObj)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/derive-hash-template-inst-float.rs b/tests/expectations/tests/derive-hash-template-inst-float.rs index 02b127e46d..b2e2d8d088 100644 --- a/tests/expectations/tests/derive-hash-template-inst-float.rs +++ b/tests/expectations/tests/derive-hash-template-inst-float.rs @@ -31,6 +31,7 @@ pub struct IntStr { fn bindgen_test_layout_IntStr() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -42,10 +43,7 @@ fn bindgen_test_layout_IntStr() { concat!("Alignment of ", stringify!(IntStr)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(IntStr), "::", stringify!(a)) ); @@ -69,6 +67,7 @@ pub struct FloatStr { fn bindgen_test_layout_FloatStr() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -80,10 +79,7 @@ fn bindgen_test_layout_FloatStr() { concat!("Alignment of ", stringify!(FloatStr)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/derive-partialeq-and-blocklist.rs b/tests/expectations/tests/derive-partialeq-and-blocklist.rs index ff1a33dc5f..c772c0b90e 100644 --- a/tests/expectations/tests/derive-partialeq-and-blocklist.rs +++ b/tests/expectations/tests/derive-partialeq-and-blocklist.rs @@ -17,6 +17,7 @@ pub struct ShouldNotDerivePartialEq { fn bindgen_test_layout_ShouldNotDerivePartialEq() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -28,10 +29,7 @@ fn bindgen_test_layout_ShouldNotDerivePartialEq() { concat!("Alignment of ", stringify!(ShouldNotDerivePartialEq)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/derive-partialeq-base.rs b/tests/expectations/tests/derive-partialeq-base.rs index 74b9d68ba3..840720f28d 100644 --- a/tests/expectations/tests/derive-partialeq-base.rs +++ b/tests/expectations/tests/derive-partialeq-base.rs @@ -14,6 +14,7 @@ pub struct Base { 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, @@ -25,10 +26,7 @@ fn bindgen_test_layout_Base() { concat!("Alignment of ", stringify!(Base)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).large) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).large) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/derive-partialeq-bitfield.rs b/tests/expectations/tests/derive-partialeq-bitfield.rs index a6484e63ec..cb9781dea6 100644 --- a/tests/expectations/tests/derive-partialeq-bitfield.rs +++ b/tests/expectations/tests/derive-partialeq-bitfield.rs @@ -102,6 +102,7 @@ pub struct C { 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, @@ -114,7 +115,6 @@ fn bindgen_test_layout_C() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize }, 4usize, diff --git a/tests/expectations/tests/derive-partialeq-core.rs b/tests/expectations/tests/derive-partialeq-core.rs index 1a4ae223b8..620b40faf9 100644 --- a/tests/expectations/tests/derive-partialeq-core.rs +++ b/tests/expectations/tests/derive-partialeq-core.rs @@ -16,6 +16,7 @@ pub struct C { 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, @@ -28,7 +29,6 @@ fn bindgen_test_layout_C() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::core::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize }, 0usize, diff --git a/tests/expectations/tests/derive-partialeq-pointer.rs b/tests/expectations/tests/derive-partialeq-pointer.rs index 89c9091ff2..e0d3c0629e 100644 --- a/tests/expectations/tests/derive-partialeq-pointer.rs +++ b/tests/expectations/tests/derive-partialeq-pointer.rs @@ -14,6 +14,7 @@ pub struct Bar { 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::(), 8usize, @@ -25,10 +26,7 @@ fn bindgen_test_layout_Bar() { concat!("Alignment of ", stringify!(Bar)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(b)) ); @@ -105,6 +103,7 @@ pub struct a { 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::(), 1usize, @@ -116,10 +115,7 @@ fn bindgen_test_layout_a() { concat!("Alignment of ", stringify!(a)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(a), "::", stringify!(d)) ); diff --git a/tests/expectations/tests/derive-partialeq-union.rs b/tests/expectations/tests/derive-partialeq-union.rs index a0c501ccbd..5ffd0bcd3b 100644 --- a/tests/expectations/tests/derive-partialeq-union.rs +++ b/tests/expectations/tests/derive-partialeq-union.rs @@ -16,6 +16,7 @@ pub union ShouldNotDerivePartialEq { fn bindgen_test_layout_ShouldNotDerivePartialEq() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -27,10 +28,7 @@ fn bindgen_test_layout_ShouldNotDerivePartialEq() { concat!("Alignment of ", stringify!(ShouldNotDerivePartialEq)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -40,10 +38,7 @@ fn bindgen_test_layout_ShouldNotDerivePartialEq() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/derive-partialeq-union_1_0.rs b/tests/expectations/tests/derive-partialeq-union_1_0.rs index bf5061bfb8..a53b9ba8e6 100644 --- a/tests/expectations/tests/derive-partialeq-union_1_0.rs +++ b/tests/expectations/tests/derive-partialeq-union_1_0.rs @@ -60,6 +60,7 @@ pub struct ShouldDerivePartialEq { fn bindgen_test_layout_ShouldDerivePartialEq() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 152usize, @@ -71,10 +72,7 @@ fn bindgen_test_layout_ShouldDerivePartialEq() { concat!("Alignment of ", stringify!(ShouldDerivePartialEq)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -84,10 +82,7 @@ fn bindgen_test_layout_ShouldDerivePartialEq() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/disable-nested-struct-naming.rs b/tests/expectations/tests/disable-nested-struct-naming.rs index ccb6e1b015..ce8a01ada3 100644 --- a/tests/expectations/tests/disable-nested-struct-naming.rs +++ b/tests/expectations/tests/disable-nested-struct-naming.rs @@ -37,6 +37,7 @@ pub struct bar4 { fn bindgen_test_layout_bar4() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -48,10 +49,7 @@ fn bindgen_test_layout_bar4() { concat!("Alignment of ", stringify!(bar4)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).x4) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).x4) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(bar4), "::", stringify!(x4)) ); @@ -60,6 +58,7 @@ fn bindgen_test_layout_bar4() { fn bindgen_test_layout_bar1__bindgen_ty_1__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -74,10 +73,7 @@ fn bindgen_test_layout_bar1__bindgen_ty_1__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).x3) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).x3) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -87,10 +83,7 @@ fn bindgen_test_layout_bar1__bindgen_ty_1__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b4) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b4) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -104,6 +97,7 @@ fn bindgen_test_layout_bar1__bindgen_ty_1__bindgen_ty_1() { fn bindgen_test_layout_bar1__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 12usize, @@ -115,10 +109,7 @@ fn bindgen_test_layout_bar1__bindgen_ty_1() { concat!("Alignment of ", stringify!(bar1__bindgen_ty_1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).x2) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).x2) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -128,10 +119,7 @@ fn bindgen_test_layout_bar1__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b3) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b3) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -145,6 +133,7 @@ fn bindgen_test_layout_bar1__bindgen_ty_1() { fn bindgen_test_layout_bar1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -156,18 +145,12 @@ fn bindgen_test_layout_bar1() { concat!("Alignment of ", stringify!(bar1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).x1) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).x1) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(bar1), "::", stringify!(x1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b2) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b2) as usize - ptr as usize }, 4usize, concat!("Offset of field: ", stringify!(bar1), "::", stringify!(b2)) ); @@ -176,6 +159,7 @@ fn bindgen_test_layout_bar1() { 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, @@ -187,10 +171,7 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b1) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b1) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(b1)) ); @@ -214,6 +195,7 @@ pub struct baz { 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::(), 4usize, @@ -225,10 +207,7 @@ fn bindgen_test_layout_baz() { concat!("Alignment of ", stringify!(baz)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(baz), "::", stringify!(x)) ); @@ -237,6 +216,7 @@ fn bindgen_test_layout_baz() { fn bindgen_test_layout__bindgen_ty_1__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit<_bindgen_ty_1__bindgen_ty_1> = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::<_bindgen_ty_1__bindgen_ty_1>(), 4usize, @@ -248,10 +228,7 @@ fn bindgen_test_layout__bindgen_ty_1__bindgen_ty_1() { concat!("Alignment of ", stringify!(_bindgen_ty_1__bindgen_ty_1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -265,6 +242,7 @@ fn bindgen_test_layout__bindgen_ty_1__bindgen_ty_1() { fn bindgen_test_layout__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit<_bindgen_ty_1> = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::<_bindgen_ty_1>(), 4usize, @@ -276,10 +254,7 @@ fn bindgen_test_layout__bindgen_ty_1() { concat!("Alignment of ", stringify!(_bindgen_ty_1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).anon2) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).anon2) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/disable-untagged-union.rs b/tests/expectations/tests/disable-untagged-union.rs index 0251c8dfdf..515f496b87 100644 --- a/tests/expectations/tests/disable-untagged-union.rs +++ b/tests/expectations/tests/disable-untagged-union.rs @@ -59,6 +59,7 @@ pub struct Foo { 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::(), 4usize, @@ -70,18 +71,12 @@ fn bindgen_test_layout_Foo() { concat!("Alignment of ", stringify!(Foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(baz)) ); diff --git a/tests/expectations/tests/do-not-derive-copy.rs b/tests/expectations/tests/do-not-derive-copy.rs index 4d55df55fc..4f9081adf4 100644 --- a/tests/expectations/tests/do-not-derive-copy.rs +++ b/tests/expectations/tests/do-not-derive-copy.rs @@ -14,6 +14,7 @@ pub struct WouldBeCopyButWeAreNotDerivingCopy { fn bindgen_test_layout_WouldBeCopyButWeAreNotDerivingCopy() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -28,10 +29,7 @@ fn bindgen_test_layout_WouldBeCopyButWeAreNotDerivingCopy() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/doggo-or-null.rs b/tests/expectations/tests/doggo-or-null.rs index ff1e536335..9028715958 100644 --- a/tests/expectations/tests/doggo-or-null.rs +++ b/tests/expectations/tests/doggo-or-null.rs @@ -14,6 +14,7 @@ pub struct Doggo { fn bindgen_test_layout_Doggo() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -25,10 +26,7 @@ fn bindgen_test_layout_Doggo() { concat!("Alignment of ", stringify!(Doggo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Doggo), "::", stringify!(x)) ); diff --git a/tests/expectations/tests/duplicated-namespaces-definitions.rs b/tests/expectations/tests/duplicated-namespaces-definitions.rs index 407e6f1212..8e7c895bf0 100644 --- a/tests/expectations/tests/duplicated-namespaces-definitions.rs +++ b/tests/expectations/tests/duplicated-namespaces-definitions.rs @@ -22,6 +22,7 @@ pub mod root { 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::(), 8usize, @@ -34,7 +35,6 @@ pub mod root { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, 0usize, @@ -47,7 +47,6 @@ pub mod root { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, 4usize, @@ -72,6 +71,7 @@ pub mod root { 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::(), 8usize, @@ -84,7 +84,6 @@ pub mod root { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize }, 0usize, diff --git a/tests/expectations/tests/dynamic_loading_with_blocklist.rs b/tests/expectations/tests/dynamic_loading_with_blocklist.rs index 703d1f7fb4..af482ad938 100644 --- a/tests/expectations/tests/dynamic_loading_with_blocklist.rs +++ b/tests/expectations/tests/dynamic_loading_with_blocklist.rs @@ -14,6 +14,7 @@ pub struct X { fn bindgen_test_layout_X() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -25,10 +26,7 @@ fn bindgen_test_layout_X() { concat!("Alignment of ", stringify!(X)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr)._x) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr)._x) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(X), "::", stringify!(_x)) ); diff --git a/tests/expectations/tests/dynamic_loading_with_class.rs b/tests/expectations/tests/dynamic_loading_with_class.rs index 6bcb1eef83..514cff7317 100644 --- a/tests/expectations/tests/dynamic_loading_with_class.rs +++ b/tests/expectations/tests/dynamic_loading_with_class.rs @@ -14,6 +14,7 @@ pub struct A { 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::(), 4usize, @@ -25,10 +26,7 @@ fn bindgen_test_layout_A() { concat!("Alignment of ", stringify!(A)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr)._x) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr)._x) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(_x)) ); diff --git a/tests/expectations/tests/enum-default-bitfield.rs b/tests/expectations/tests/enum-default-bitfield.rs index 90d442f55e..4c0757667e 100644 --- a/tests/expectations/tests/enum-default-bitfield.rs +++ b/tests/expectations/tests/enum-default-bitfield.rs @@ -45,6 +45,7 @@ pub struct foo__bindgen_ty_1(pub ::std::os::raw::c_uint); 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::(), 4usize, @@ -56,10 +57,7 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/enum-default-consts.rs b/tests/expectations/tests/enum-default-consts.rs index c40b903416..ddce26c20a 100644 --- a/tests/expectations/tests/enum-default-consts.rs +++ b/tests/expectations/tests/enum-default-consts.rs @@ -17,6 +17,7 @@ pub type foo__bindgen_ty_1 = ::std::os::raw::c_uint; 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::(), 4usize, @@ -28,10 +29,7 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/enum-default-module.rs b/tests/expectations/tests/enum-default-module.rs index 2990d8fc15..ae026d8bca 100644 --- a/tests/expectations/tests/enum-default-module.rs +++ b/tests/expectations/tests/enum-default-module.rs @@ -19,6 +19,7 @@ pub mod foo__bindgen_ty_1 { 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::(), 4usize, @@ -30,10 +31,7 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/enum-default-rust.rs b/tests/expectations/tests/enum-default-rust.rs index fd799aeeda..c3b728f826 100644 --- a/tests/expectations/tests/enum-default-rust.rs +++ b/tests/expectations/tests/enum-default-rust.rs @@ -22,6 +22,7 @@ pub enum foo__bindgen_ty_1 { 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::(), 4usize, @@ -33,10 +34,7 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/enum-no-debug-rust.rs b/tests/expectations/tests/enum-no-debug-rust.rs index d433d4ccac..33c7b5c7cc 100644 --- a/tests/expectations/tests/enum-no-debug-rust.rs +++ b/tests/expectations/tests/enum-no-debug-rust.rs @@ -22,6 +22,7 @@ pub enum foo__bindgen_ty_1 { 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::(), 4usize, @@ -33,10 +34,7 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/enum.rs b/tests/expectations/tests/enum.rs index 3c8e0814a2..65b734a325 100644 --- a/tests/expectations/tests/enum.rs +++ b/tests/expectations/tests/enum.rs @@ -17,6 +17,7 @@ pub type foo__bindgen_ty_1 = ::std::os::raw::c_uint; 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::(), 4usize, @@ -28,10 +29,7 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/enum_and_vtable_mangling.rs b/tests/expectations/tests/enum_and_vtable_mangling.rs index ca982c330a..f414812b82 100644 --- a/tests/expectations/tests/enum_and_vtable_mangling.rs +++ b/tests/expectations/tests/enum_and_vtable_mangling.rs @@ -27,6 +27,7 @@ pub struct C { 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::(), 16usize, @@ -38,10 +39,7 @@ fn bindgen_test_layout_C() { concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, 8usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(i)) ); diff --git a/tests/expectations/tests/explicit-padding.rs b/tests/expectations/tests/explicit-padding.rs index 73d2b69460..a6ea767129 100644 --- a/tests/expectations/tests/explicit-padding.rs +++ b/tests/expectations/tests/explicit-padding.rs @@ -18,6 +18,7 @@ pub struct pad_me { fn bindgen_test_layout_pad_me() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 12usize, @@ -29,10 +30,7 @@ fn bindgen_test_layout_pad_me() { concat!("Alignment of ", stringify!(pad_me)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).first) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).first) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -42,10 +40,7 @@ fn bindgen_test_layout_pad_me() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).second) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).second) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -55,10 +50,7 @@ fn bindgen_test_layout_pad_me() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).third) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).third) as usize - ptr as usize }, 8usize, concat!( "Offset of field: ", @@ -79,6 +71,7 @@ pub union dont_pad_me { fn bindgen_test_layout_dont_pad_me() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -90,10 +83,7 @@ fn bindgen_test_layout_dont_pad_me() { concat!("Alignment of ", stringify!(dont_pad_me)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).first) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).first) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -103,10 +93,7 @@ fn bindgen_test_layout_dont_pad_me() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).second) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).second) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -116,10 +103,7 @@ fn bindgen_test_layout_dont_pad_me() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).third) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).third) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/extern-const-struct.rs b/tests/expectations/tests/extern-const-struct.rs index e1af23c819..8060316a35 100644 --- a/tests/expectations/tests/extern-const-struct.rs +++ b/tests/expectations/tests/extern-const-struct.rs @@ -14,6 +14,7 @@ pub struct nsFoo { 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, @@ -25,10 +26,7 @@ fn bindgen_test_layout_nsFoo() { concat!("Alignment of ", stringify!(nsFoo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).details) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).details) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/forward-declaration-autoptr.rs b/tests/expectations/tests/forward-declaration-autoptr.rs index fc4203f540..9f4fdca0a6 100644 --- a/tests/expectations/tests/forward-declaration-autoptr.rs +++ b/tests/expectations/tests/forward-declaration-autoptr.rs @@ -34,6 +34,7 @@ pub struct Bar { 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::(), 8usize, @@ -46,7 +47,6 @@ fn bindgen_test_layout_Bar() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize }, 0usize, diff --git a/tests/expectations/tests/forward_declared_complex_types.rs b/tests/expectations/tests/forward_declared_complex_types.rs index f8f25bd672..c1b1f23d2d 100644 --- a/tests/expectations/tests/forward_declared_complex_types.rs +++ b/tests/expectations/tests/forward_declared_complex_types.rs @@ -37,6 +37,7 @@ pub struct Bar { 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::(), 8usize, @@ -48,10 +49,7 @@ fn bindgen_test_layout_Bar() { concat!("Alignment of ", stringify!(Bar)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(f)) ); diff --git a/tests/expectations/tests/forward_declared_complex_types_1_0.rs b/tests/expectations/tests/forward_declared_complex_types_1_0.rs index 5c749f8297..ecdbe49da7 100644 --- a/tests/expectations/tests/forward_declared_complex_types_1_0.rs +++ b/tests/expectations/tests/forward_declared_complex_types_1_0.rs @@ -47,6 +47,7 @@ pub struct Bar { 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::(), 8usize, @@ -58,10 +59,7 @@ fn bindgen_test_layout_Bar() { concat!("Alignment of ", stringify!(Bar)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(f)) ); diff --git a/tests/expectations/tests/forward_declared_struct.rs b/tests/expectations/tests/forward_declared_struct.rs index e65e0351bd..f877666adc 100644 --- a/tests/expectations/tests/forward_declared_struct.rs +++ b/tests/expectations/tests/forward_declared_struct.rs @@ -14,6 +14,7 @@ pub struct a { 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::(), 4usize, @@ -25,10 +26,7 @@ fn bindgen_test_layout_a() { concat!("Alignment of ", stringify!(a)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(a), "::", stringify!(b)) ); @@ -42,6 +40,7 @@ pub struct c { 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::(), 4usize, @@ -53,10 +52,7 @@ fn bindgen_test_layout_c() { concat!("Alignment of ", stringify!(c)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(c), "::", stringify!(d)) ); diff --git a/tests/expectations/tests/func_ptr_in_struct.rs b/tests/expectations/tests/func_ptr_in_struct.rs index 6e7357f7ef..745720d998 100644 --- a/tests/expectations/tests/func_ptr_in_struct.rs +++ b/tests/expectations/tests/func_ptr_in_struct.rs @@ -24,6 +24,7 @@ pub struct Foo { 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::(), 8usize, @@ -35,10 +36,7 @@ fn bindgen_test_layout_Foo() { concat!("Alignment of ", stringify!(Foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/gen-destructors-neg.rs b/tests/expectations/tests/gen-destructors-neg.rs index 3b5193ae44..b87eb1d46c 100644 --- a/tests/expectations/tests/gen-destructors-neg.rs +++ b/tests/expectations/tests/gen-destructors-neg.rs @@ -14,6 +14,7 @@ pub struct Foo { 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::(), 4usize, @@ -25,10 +26,7 @@ fn bindgen_test_layout_Foo() { concat!("Alignment of ", stringify!(Foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/gen-destructors.rs b/tests/expectations/tests/gen-destructors.rs index dbd02151ed..1711f76d0c 100644 --- a/tests/expectations/tests/gen-destructors.rs +++ b/tests/expectations/tests/gen-destructors.rs @@ -14,6 +14,7 @@ pub struct Foo { 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::(), 4usize, @@ -25,10 +26,7 @@ fn bindgen_test_layout_Foo() { concat!("Alignment of ", stringify!(Foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/i128.rs b/tests/expectations/tests/i128.rs index addc227d60..dee57a6ded 100644 --- a/tests/expectations/tests/i128.rs +++ b/tests/expectations/tests/i128.rs @@ -16,6 +16,7 @@ pub struct foo { 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, @@ -28,7 +29,6 @@ fn bindgen_test_layout_foo() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).my_signed) as usize - ptr as usize }, 0usize, @@ -41,7 +41,6 @@ fn bindgen_test_layout_foo() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).my_unsigned) as usize - ptr as usize }, 16usize, diff --git a/tests/expectations/tests/inline_namespace.rs b/tests/expectations/tests/inline_namespace.rs index 81446a9687..c569bba688 100644 --- a/tests/expectations/tests/inline_namespace.rs +++ b/tests/expectations/tests/inline_namespace.rs @@ -23,6 +23,7 @@ pub mod root { 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, @@ -34,10 +35,7 @@ pub mod root { concat!("Alignment of ", stringify!(Bar)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/inline_namespace_conservative.rs b/tests/expectations/tests/inline_namespace_conservative.rs index bbee2dee19..4ffafd46b7 100644 --- a/tests/expectations/tests/inline_namespace_conservative.rs +++ b/tests/expectations/tests/inline_namespace_conservative.rs @@ -28,6 +28,7 @@ pub mod root { 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, @@ -39,10 +40,7 @@ pub mod root { concat!("Alignment of ", stringify!(Bar)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/inner_const.rs b/tests/expectations/tests/inner_const.rs index 84dfdc3786..69a7c39a69 100644 --- a/tests/expectations/tests/inner_const.rs +++ b/tests/expectations/tests/inner_const.rs @@ -22,6 +22,7 @@ extern "C" { 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::(), 4usize, @@ -33,10 +34,7 @@ fn bindgen_test_layout_Foo() { concat!("Alignment of ", stringify!(Foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/inner_template_self.rs b/tests/expectations/tests/inner_template_self.rs index eed9885ddf..13d9ac1423 100644 --- a/tests/expectations/tests/inner_template_self.rs +++ b/tests/expectations/tests/inner_template_self.rs @@ -29,6 +29,7 @@ pub struct InstantiateIt { fn bindgen_test_layout_InstantiateIt() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -40,10 +41,7 @@ fn bindgen_test_layout_InstantiateIt() { concat!("Alignment of ", stringify!(InstantiateIt)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).m_list) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).m_list) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/issue-1118-using-forward-decl.rs b/tests/expectations/tests/issue-1118-using-forward-decl.rs index 2596a6ba0d..e881c8c482 100644 --- a/tests/expectations/tests/issue-1118-using-forward-decl.rs +++ b/tests/expectations/tests/issue-1118-using-forward-decl.rs @@ -15,6 +15,7 @@ pub struct nsTArray_base { fn bindgen_test_layout_nsTArray_base() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -26,10 +27,7 @@ fn bindgen_test_layout_nsTArray_base() { concat!("Alignment of ", stringify!(nsTArray_base)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -71,6 +69,7 @@ pub struct nsIContent { fn bindgen_test_layout_nsIContent() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -82,10 +81,7 @@ fn bindgen_test_layout_nsIContent() { concat!("Alignment of ", stringify!(nsIContent)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/issue-1216-variadic-member.rs b/tests/expectations/tests/issue-1216-variadic-member.rs index c7ffa3b613..bb57c8568a 100644 --- a/tests/expectations/tests/issue-1216-variadic-member.rs +++ b/tests/expectations/tests/issue-1216-variadic-member.rs @@ -24,6 +24,7 @@ pub struct Foo { 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::(), 8usize, @@ -35,10 +36,7 @@ fn bindgen_test_layout_Foo() { concat!("Alignment of ", stringify!(Foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(f)) ); diff --git a/tests/expectations/tests/issue-1281.rs b/tests/expectations/tests/issue-1281.rs index ff3eb88a4c..db99cbce99 100644 --- a/tests/expectations/tests/issue-1281.rs +++ b/tests/expectations/tests/issue-1281.rs @@ -19,6 +19,7 @@ pub struct foo { 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::(), 4usize, @@ -30,10 +31,7 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(foo)) ); @@ -42,6 +40,7 @@ fn bindgen_test_layout_foo() { 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, @@ -53,10 +52,7 @@ fn bindgen_test_layout_bar() { concat!("Alignment of ", stringify!(bar)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(bar), "::", stringify!(u)) ); @@ -71,6 +67,7 @@ pub struct baz { 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::(), 4usize, @@ -82,10 +79,7 @@ fn bindgen_test_layout_baz() { concat!("Alignment of ", stringify!(baz)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(baz), "::", stringify!(f)) ); diff --git a/tests/expectations/tests/issue-1285.rs b/tests/expectations/tests/issue-1285.rs index f97c5236f1..08aab0a94c 100644 --- a/tests/expectations/tests/issue-1285.rs +++ b/tests/expectations/tests/issue-1285.rs @@ -20,6 +20,7 @@ pub union foo__bindgen_ty_1 { fn bindgen_test_layout_foo__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -31,10 +32,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -44,10 +42,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -70,6 +65,7 @@ impl Default for foo__bindgen_ty_1 { 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::(), 4usize, @@ -81,10 +77,7 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/issue-1291.rs b/tests/expectations/tests/issue-1291.rs index e7914e48d2..25f4f1055d 100644 --- a/tests/expectations/tests/issue-1291.rs +++ b/tests/expectations/tests/issue-1291.rs @@ -29,6 +29,7 @@ pub struct RTCRay { 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, @@ -40,10 +41,7 @@ fn bindgen_test_layout_RTCRay() { concat!("Alignment of ", stringify!(RTCRay)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).org) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).org) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -53,10 +51,7 @@ fn bindgen_test_layout_RTCRay() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).align0) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).align0) as usize - ptr as usize }, 12usize, concat!( "Offset of field: ", @@ -66,10 +61,7 @@ fn bindgen_test_layout_RTCRay() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).dir) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).dir) as usize - ptr as usize }, 16usize, concat!( "Offset of field: ", @@ -79,10 +71,7 @@ fn bindgen_test_layout_RTCRay() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).align1) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).align1) as usize - ptr as usize }, 28usize, concat!( "Offset of field: ", @@ -92,10 +81,7 @@ fn bindgen_test_layout_RTCRay() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).tnear) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).tnear) as usize - ptr as usize }, 32usize, concat!( "Offset of field: ", @@ -105,10 +91,7 @@ fn bindgen_test_layout_RTCRay() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).tfar) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).tfar) as usize - ptr as usize }, 36usize, concat!( "Offset of field: ", @@ -118,10 +101,7 @@ fn bindgen_test_layout_RTCRay() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).time) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).time) as usize - ptr as usize }, 40usize, concat!( "Offset of field: ", @@ -131,10 +111,7 @@ fn bindgen_test_layout_RTCRay() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize }, 44usize, concat!( "Offset of field: ", @@ -144,10 +121,7 @@ fn bindgen_test_layout_RTCRay() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).Ng) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).Ng) as usize - ptr as usize }, 48usize, concat!( "Offset of field: ", @@ -157,10 +131,7 @@ fn bindgen_test_layout_RTCRay() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).align2) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).align2) as usize - ptr as usize }, 60usize, concat!( "Offset of field: ", @@ -170,26 +141,17 @@ fn bindgen_test_layout_RTCRay() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize }, 64usize, concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(u)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).v) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).v) as usize - ptr as usize }, 68usize, concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(v)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).geomID) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).geomID) as usize - ptr as usize }, 72usize, concat!( "Offset of field: ", @@ -199,10 +161,7 @@ fn bindgen_test_layout_RTCRay() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).primID) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).primID) as usize - ptr as usize }, 76usize, concat!( "Offset of field: ", @@ -212,10 +171,7 @@ fn bindgen_test_layout_RTCRay() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).instID) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).instID) as usize - ptr as usize }, 80usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/issue-1382-rust-primitive-types.rs b/tests/expectations/tests/issue-1382-rust-primitive-types.rs index 0891493472..b767d5e430 100644 --- a/tests/expectations/tests/issue-1382-rust-primitive-types.rs +++ b/tests/expectations/tests/issue-1382-rust-primitive-types.rs @@ -35,6 +35,7 @@ pub struct Foo { 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::(), 56usize, @@ -46,74 +47,47 @@ fn bindgen_test_layout_Foo() { concat!("Alignment of ", stringify!(Foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).i8_) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).i8_) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i8_)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).u8_) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).u8_) as usize - ptr as usize }, 4usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u8_)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).i16_) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).i16_) as usize - ptr as usize }, 8usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i16_)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).u16_) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).u16_) as usize - ptr as usize }, 12usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u16_)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).i32_) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).i32_) as usize - ptr as usize }, 16usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i32_)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).u32_) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).u32_) as usize - ptr as usize }, 20usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u32_)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).i64_) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).i64_) as usize - ptr as usize }, 24usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i64_)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).u64_) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).u64_) as usize - ptr as usize }, 28usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u64_)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).i128_) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).i128_) as usize - ptr as usize }, 32usize, concat!( "Offset of field: ", @@ -123,10 +97,7 @@ fn bindgen_test_layout_Foo() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).u128_) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).u128_) as usize - ptr as usize }, 36usize, concat!( "Offset of field: ", @@ -136,10 +107,7 @@ fn bindgen_test_layout_Foo() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).isize_) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).isize_) as usize - ptr as usize }, 40usize, concat!( "Offset of field: ", @@ -149,10 +117,7 @@ fn bindgen_test_layout_Foo() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).usize_) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).usize_) as usize - ptr as usize }, 44usize, concat!( "Offset of field: ", @@ -162,18 +127,12 @@ fn bindgen_test_layout_Foo() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).f32_) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).f32_) as usize - ptr as usize }, 48usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(f32_)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).f64_) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).f64_) as usize - ptr as usize }, 52usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(f64_)) ); diff --git a/tests/expectations/tests/issue-1443.rs b/tests/expectations/tests/issue-1443.rs index 3267ab0176..48cae79faa 100644 --- a/tests/expectations/tests/issue-1443.rs +++ b/tests/expectations/tests/issue-1443.rs @@ -20,6 +20,7 @@ pub struct Bar { 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, @@ -31,18 +32,12 @@ fn bindgen_test_layout_Bar() { concat!("Alignment of ", stringify!(Bar)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(f)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize }, 8usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(m)) ); @@ -66,6 +61,7 @@ pub struct Baz { 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, @@ -77,18 +73,12 @@ fn bindgen_test_layout_Baz() { concat!("Alignment of ", stringify!(Baz)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Baz), "::", stringify!(f)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize }, 8usize, concat!("Offset of field: ", stringify!(Baz), "::", stringify!(m)) ); @@ -112,6 +102,7 @@ pub struct Tar { fn bindgen_test_layout_Tar() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -123,18 +114,12 @@ fn bindgen_test_layout_Tar() { concat!("Alignment of ", stringify!(Tar)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Tar), "::", stringify!(f)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize }, 8usize, concat!("Offset of field: ", stringify!(Tar), "::", stringify!(m)) ); @@ -158,6 +143,7 @@ pub struct Taz { fn bindgen_test_layout_Taz() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -169,18 +155,12 @@ fn bindgen_test_layout_Taz() { concat!("Alignment of ", stringify!(Taz)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Taz), "::", stringify!(f)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize }, 8usize, concat!("Offset of field: ", stringify!(Taz), "::", stringify!(m)) ); diff --git a/tests/expectations/tests/issue-1454.rs b/tests/expectations/tests/issue-1454.rs index 2ba6c493fe..8da43cb090 100644 --- a/tests/expectations/tests/issue-1454.rs +++ b/tests/expectations/tests/issue-1454.rs @@ -18,6 +18,7 @@ pub struct local_type { fn bindgen_test_layout_local_type() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 0usize, @@ -29,10 +30,7 @@ fn bindgen_test_layout_local_type() { concat!("Alignment of ", stringify!(local_type)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).inner) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).inner) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/issue-1498.rs b/tests/expectations/tests/issue-1498.rs index 56fc922a20..08ba9ef42d 100644 --- a/tests/expectations/tests/issue-1498.rs +++ b/tests/expectations/tests/issue-1498.rs @@ -35,6 +35,7 @@ pub union rte_memseg__bindgen_ty_1 { fn bindgen_test_layout_rte_memseg__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -46,10 +47,7 @@ fn bindgen_test_layout_rte_memseg__bindgen_ty_1() { concat!("Alignment of ", stringify!(rte_memseg__bindgen_ty_1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).addr) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).addr) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -59,10 +57,7 @@ fn bindgen_test_layout_rte_memseg__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).addr_64) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).addr_64) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -85,6 +80,7 @@ impl Default for rte_memseg__bindgen_ty_1 { fn bindgen_test_layout_rte_memseg() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 44usize, @@ -97,7 +93,6 @@ fn bindgen_test_layout_rte_memseg() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).phys_addr) as usize - ptr as usize }, 0usize, @@ -109,10 +104,7 @@ fn bindgen_test_layout_rte_memseg() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize }, 16usize, concat!( "Offset of field: ", @@ -123,7 +115,6 @@ fn bindgen_test_layout_rte_memseg() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).hugepage_sz) as usize - ptr as usize }, 24usize, @@ -136,7 +127,6 @@ fn bindgen_test_layout_rte_memseg() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).socket_id) as usize - ptr as usize }, 32usize, @@ -149,7 +139,6 @@ fn bindgen_test_layout_rte_memseg() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).nchannel) as usize - ptr as usize }, 36usize, @@ -161,10 +150,7 @@ fn bindgen_test_layout_rte_memseg() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).nrank) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).nrank) as usize - ptr as usize }, 40usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/issue-1947.rs b/tests/expectations/tests/issue-1947.rs index f390a588a5..e133ed85ba 100644 --- a/tests/expectations/tests/issue-1947.rs +++ b/tests/expectations/tests/issue-1947.rs @@ -109,6 +109,7 @@ pub struct V56AMDY { fn bindgen_test_layout_V56AMDY() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -120,10 +121,7 @@ fn bindgen_test_layout_V56AMDY() { concat!("Alignment of ", stringify!(V56AMDY)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).MADK) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).MADK) as usize - ptr as usize }, 2usize, concat!( "Offset of field: ", @@ -133,10 +131,7 @@ fn bindgen_test_layout_V56AMDY() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).MABR) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).MABR) as usize - ptr as usize }, 3usize, concat!( "Offset of field: ", @@ -146,10 +141,7 @@ fn bindgen_test_layout_V56AMDY() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr)._rB_) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr)._rB_) as usize - ptr as usize }, 7usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/issue-1977-larger-arrays.rs b/tests/expectations/tests/issue-1977-larger-arrays.rs index 917cf52257..6375ea7e67 100644 --- a/tests/expectations/tests/issue-1977-larger-arrays.rs +++ b/tests/expectations/tests/issue-1977-larger-arrays.rs @@ -14,6 +14,7 @@ pub struct S { 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, @@ -26,7 +27,6 @@ fn bindgen_test_layout_S() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize }, 0usize, diff --git a/tests/expectations/tests/issue-1995.rs b/tests/expectations/tests/issue-1995.rs index 1cb803a7d8..890479b5df 100644 --- a/tests/expectations/tests/issue-1995.rs +++ b/tests/expectations/tests/issue-1995.rs @@ -21,6 +21,7 @@ pub struct Bar { 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, @@ -32,10 +33,7 @@ fn bindgen_test_layout_Bar() { concat!("Alignment of ", stringify!(Bar)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz)) ); diff --git a/tests/expectations/tests/issue-2019.rs b/tests/expectations/tests/issue-2019.rs index 371345349c..294e9f0e83 100644 --- a/tests/expectations/tests/issue-2019.rs +++ b/tests/expectations/tests/issue-2019.rs @@ -14,6 +14,7 @@ pub struct A { 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::(), 4usize, @@ -25,10 +26,7 @@ fn bindgen_test_layout_A() { concat!("Alignment of ", stringify!(A)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(a)) ); @@ -52,6 +50,7 @@ pub struct B { 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::(), 4usize, @@ -63,10 +62,7 @@ fn bindgen_test_layout_B() { concat!("Alignment of ", stringify!(B)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(B), "::", stringify!(b)) ); diff --git a/tests/expectations/tests/issue-372.rs b/tests/expectations/tests/issue-372.rs index b6fe4cf0c7..e87fb4d108 100644 --- a/tests/expectations/tests/issue-372.rs +++ b/tests/expectations/tests/issue-372.rs @@ -20,6 +20,7 @@ pub mod root { 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, @@ -31,26 +32,17 @@ pub mod root { concat!("Alignment of ", stringify!(i)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).j) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).j) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(i), "::", stringify!(j)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).k) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).k) as usize - ptr as usize }, 8usize, concat!("Offset of field: ", stringify!(i), "::", stringify!(k)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).l) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).l) as usize - ptr as usize }, 16usize, concat!("Offset of field: ", stringify!(i), "::", stringify!(l)) ); @@ -73,6 +65,7 @@ pub mod root { 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, @@ -84,10 +77,7 @@ pub mod root { concat!("Alignment of ", stringify!(d)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(d), "::", stringify!(m)) ); @@ -125,6 +115,7 @@ pub mod root { 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, @@ -136,10 +127,7 @@ pub mod root { concat!("Alignment of ", stringify!(F)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).w) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).w) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(F), "::", stringify!(w)) ); diff --git a/tests/expectations/tests/issue-537-repr-packed-n.rs b/tests/expectations/tests/issue-537-repr-packed-n.rs index ab19685ba5..b1e42ca72a 100644 --- a/tests/expectations/tests/issue-537-repr-packed-n.rs +++ b/tests/expectations/tests/issue-537-repr-packed-n.rs @@ -17,6 +17,7 @@ pub struct AlignedToOne { 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, @@ -28,10 +29,7 @@ fn bindgen_test_layout_AlignedToOne() { concat!("Alignment of ", stringify!(AlignedToOne)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -51,6 +49,7 @@ pub struct AlignedToTwo { 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, @@ -62,10 +61,7 @@ fn bindgen_test_layout_AlignedToTwo() { concat!("Alignment of ", stringify!(AlignedToTwo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -88,6 +84,7 @@ pub struct PackedToOne { 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, @@ -99,10 +96,7 @@ fn bindgen_test_layout_PackedToOne() { concat!("Alignment of ", stringify!(PackedToOne)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -112,10 +106,7 @@ fn bindgen_test_layout_PackedToOne() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -136,6 +127,7 @@ pub struct PackedToTwo { 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, @@ -147,10 +139,7 @@ fn bindgen_test_layout_PackedToTwo() { concat!("Alignment of ", stringify!(PackedToTwo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -160,10 +149,7 @@ fn bindgen_test_layout_PackedToTwo() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/issue-537.rs b/tests/expectations/tests/issue-537.rs index e2e1bce0c9..e2be9d63ba 100644 --- a/tests/expectations/tests/issue-537.rs +++ b/tests/expectations/tests/issue-537.rs @@ -16,6 +16,7 @@ pub struct AlignedToOne { 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, @@ -27,10 +28,7 @@ fn bindgen_test_layout_AlignedToOne() { concat!("Alignment of ", stringify!(AlignedToOne)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -51,6 +49,7 @@ pub struct AlignedToTwo { 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, @@ -62,10 +61,7 @@ fn bindgen_test_layout_AlignedToTwo() { concat!("Alignment of ", stringify!(AlignedToTwo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -88,6 +84,7 @@ pub struct PackedToOne { 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, @@ -99,10 +96,7 @@ fn bindgen_test_layout_PackedToOne() { concat!("Alignment of ", stringify!(PackedToOne)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -112,10 +106,7 @@ fn bindgen_test_layout_PackedToOne() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -138,6 +129,7 @@ pub struct PackedToTwo { 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, @@ -149,10 +141,7 @@ fn bindgen_test_layout_PackedToTwo() { concat!("Alignment of ", stringify!(PackedToTwo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -162,10 +151,7 @@ fn bindgen_test_layout_PackedToTwo() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/issue-573-layout-test-failures.rs b/tests/expectations/tests/issue-573-layout-test-failures.rs index 3c16b87209..fbff136279 100644 --- a/tests/expectations/tests/issue-573-layout-test-failures.rs +++ b/tests/expectations/tests/issue-573-layout-test-failures.rs @@ -19,6 +19,7 @@ pub struct AutoIdVector { fn bindgen_test_layout_AutoIdVector() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -30,10 +31,7 @@ fn bindgen_test_layout_AutoIdVector() { concat!("Alignment of ", stringify!(AutoIdVector)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).ar) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).ar) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs b/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs index 36a7f4f5a2..22aa9d16e6 100644 --- a/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs +++ b/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs @@ -19,6 +19,7 @@ pub struct _bindgen_ty_1 { fn bindgen_test_layout__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit<_bindgen_ty_1> = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::<_bindgen_ty_1>(), 1usize, @@ -30,10 +31,7 @@ fn bindgen_test_layout__bindgen_ty_1() { concat!("Alignment of ", stringify!(_bindgen_ty_1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).ar) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).ar) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs b/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs index 0d9a14e665..3765315c43 100644 --- a/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs +++ b/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs @@ -53,6 +53,7 @@ pub struct g { fn bindgen_test_layout_g() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -64,10 +65,7 @@ fn bindgen_test_layout_g() { concat!("Alignment of ", stringify!(g)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).h) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).h) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(g), "::", stringify!(h)) ); diff --git a/tests/expectations/tests/issue-639-typedef-anon-field.rs b/tests/expectations/tests/issue-639-typedef-anon-field.rs index 40fb6829f4..bac8a04c24 100644 --- a/tests/expectations/tests/issue-639-typedef-anon-field.rs +++ b/tests/expectations/tests/issue-639-typedef-anon-field.rs @@ -19,6 +19,7 @@ pub struct Foo_Bar { fn bindgen_test_layout_Foo_Bar() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -30,10 +31,7 @@ fn bindgen_test_layout_Foo_Bar() { concat!("Alignment of ", stringify!(Foo_Bar)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).abc) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).abc) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -47,6 +45,7 @@ fn bindgen_test_layout_Foo_Bar() { 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::(), 4usize, @@ -58,10 +57,7 @@ fn bindgen_test_layout_Foo() { concat!("Alignment of ", stringify!(Foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) ); @@ -80,6 +76,7 @@ pub struct Baz_Bar { fn bindgen_test_layout_Baz_Bar() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -91,10 +88,7 @@ fn bindgen_test_layout_Baz_Bar() { concat!("Alignment of ", stringify!(Baz_Bar)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).abc) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).abc) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/issue-643-inner-struct.rs b/tests/expectations/tests/issue-643-inner-struct.rs index ae1890c27c..b69aa16ef3 100644 --- a/tests/expectations/tests/issue-643-inner-struct.rs +++ b/tests/expectations/tests/issue-643-inner-struct.rs @@ -52,6 +52,7 @@ pub struct rte_ring_prod { fn bindgen_test_layout_rte_ring_prod() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -64,7 +65,6 @@ fn bindgen_test_layout_rte_ring_prod() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).watermark) as usize - ptr as usize }, 0usize, @@ -85,6 +85,7 @@ pub struct rte_ring_cons { fn bindgen_test_layout_rte_ring_cons() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -97,7 +98,6 @@ fn bindgen_test_layout_rte_ring_cons() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).sc_dequeue) as usize - ptr as usize }, 0usize, diff --git a/tests/expectations/tests/issue-648-derive-debug-with-padding.rs b/tests/expectations/tests/issue-648-derive-debug-with-padding.rs index 1eed229d6b..13cdf0c97b 100644 --- a/tests/expectations/tests/issue-648-derive-debug-with-padding.rs +++ b/tests/expectations/tests/issue-648-derive-debug-with-padding.rs @@ -17,6 +17,7 @@ pub struct NoDebug { 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, @@ -28,10 +29,7 @@ fn bindgen_test_layout_NoDebug() { concat!("Alignment of ", stringify!(NoDebug)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -70,6 +68,7 @@ pub struct ShouldDeriveDebugButDoesNot { 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, @@ -81,10 +80,7 @@ fn bindgen_test_layout_ShouldDeriveDebugButDoesNot() { concat!("Alignment of ", stringify!(ShouldDeriveDebugButDoesNot)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -94,10 +90,7 @@ fn bindgen_test_layout_ShouldDeriveDebugButDoesNot() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, 32usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/issue-674-1.rs b/tests/expectations/tests/issue-674-1.rs index a28b78ec8d..b37d7a27d7 100644 --- a/tests/expectations/tests/issue-674-1.rs +++ b/tests/expectations/tests/issue-674-1.rs @@ -28,6 +28,7 @@ pub mod root { fn bindgen_test_layout_CapturingContentInfo() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -39,10 +40,7 @@ pub mod root { concat!("Alignment of ", stringify!(CapturingContentInfo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/issue-674-2.rs b/tests/expectations/tests/issue-674-2.rs index 07ca59e831..12b2aa20a5 100644 --- a/tests/expectations/tests/issue-674-2.rs +++ b/tests/expectations/tests/issue-674-2.rs @@ -28,6 +28,7 @@ pub mod root { 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::(), 1usize, @@ -39,10 +40,7 @@ pub mod root { concat!("Alignment of ", stringify!(c)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(c), "::", stringify!(b)) ); @@ -56,6 +54,7 @@ pub mod root { 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::(), 1usize, @@ -67,10 +66,7 @@ pub mod root { concat!("Alignment of ", stringify!(B)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(B), "::", stringify!(a)) ); diff --git a/tests/expectations/tests/issue-674-3.rs b/tests/expectations/tests/issue-674-3.rs index cd8421be6f..e7af6b8dc0 100644 --- a/tests/expectations/tests/issue-674-3.rs +++ b/tests/expectations/tests/issue-674-3.rs @@ -24,6 +24,7 @@ pub mod root { 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::(), 1usize, @@ -35,10 +36,7 @@ pub mod root { concat!("Alignment of ", stringify!(a)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(a), "::", stringify!(b)) ); @@ -52,6 +50,7 @@ pub mod root { fn bindgen_test_layout_nsCSSValue() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -63,10 +62,7 @@ pub mod root { concat!("Alignment of ", stringify!(nsCSSValue)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/issue-801-opaque-sloppiness.rs b/tests/expectations/tests/issue-801-opaque-sloppiness.rs index 9252bab92c..b3192b7243 100644 --- a/tests/expectations/tests/issue-801-opaque-sloppiness.rs +++ b/tests/expectations/tests/issue-801-opaque-sloppiness.rs @@ -42,6 +42,7 @@ pub struct C { 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::(), 1usize, @@ -53,10 +54,7 @@ fn bindgen_test_layout_C() { concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(b)) ); diff --git a/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs b/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs index 6d66e61007..f886952822 100644 --- a/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs +++ b/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs @@ -111,6 +111,7 @@ pub struct Allowlisted { fn bindgen_test_layout_Allowlisted() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -123,7 +124,6 @@ fn bindgen_test_layout_Allowlisted() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).some_member) as usize - ptr as usize }, 0usize, diff --git a/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs b/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs index 5bc5977799..d9c365d828 100644 --- a/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs +++ b/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs @@ -16,6 +16,7 @@ pub struct ShouldNotBeCopy { fn bindgen_test_layout_ShouldNotBeCopy() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -27,10 +28,7 @@ fn bindgen_test_layout_ShouldNotBeCopy() { concat!("Alignment of ", stringify!(ShouldNotBeCopy)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/jsval_layout_opaque.rs b/tests/expectations/tests/jsval_layout_opaque.rs index 3340c9b275..2873f6a2ff 100644 --- a/tests/expectations/tests/jsval_layout_opaque.rs +++ b/tests/expectations/tests/jsval_layout_opaque.rs @@ -280,6 +280,7 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit< jsval_layout__bindgen_ty_2__bindgen_ty_1, > = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -297,10 +298,7 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).i32_) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).i32_) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -310,10 +308,7 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).u32_) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).u32_) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -323,10 +318,7 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).why) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).why) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -349,6 +341,7 @@ impl Default for jsval_layout__bindgen_ty_2__bindgen_ty_1 { fn bindgen_test_layout_jsval_layout__bindgen_ty_2() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -360,10 +353,7 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2() { concat!("Alignment of ", stringify!(jsval_layout__bindgen_ty_2)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).payload) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).payload) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -386,6 +376,7 @@ impl Default for jsval_layout__bindgen_ty_2 { fn bindgen_test_layout_jsval_layout() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -397,10 +388,7 @@ fn bindgen_test_layout_jsval_layout() { concat!("Alignment of ", stringify!(jsval_layout)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).asBits) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).asBits) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -411,7 +399,6 @@ fn bindgen_test_layout_jsval_layout() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).debugView) as usize - ptr as usize }, 0usize, @@ -423,10 +410,7 @@ fn bindgen_test_layout_jsval_layout() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).s) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).s) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -437,7 +421,6 @@ fn bindgen_test_layout_jsval_layout() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).asDouble) as usize - ptr as usize }, 0usize, @@ -449,10 +432,7 @@ fn bindgen_test_layout_jsval_layout() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).asPtr) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).asPtr) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -462,10 +442,7 @@ fn bindgen_test_layout_jsval_layout() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).asWord) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).asWord) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -476,7 +453,6 @@ fn bindgen_test_layout_jsval_layout() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).asUIntPtr) as usize - ptr as usize }, 0usize, @@ -506,6 +482,7 @@ pub struct Value { fn bindgen_test_layout_Value() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -517,10 +494,7 @@ fn bindgen_test_layout_Value() { concat!("Alignment of ", stringify!(Value)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/jsval_layout_opaque_1_0.rs b/tests/expectations/tests/jsval_layout_opaque_1_0.rs index 055d273a88..33594c0e05 100644 --- a/tests/expectations/tests/jsval_layout_opaque_1_0.rs +++ b/tests/expectations/tests/jsval_layout_opaque_1_0.rs @@ -330,6 +330,7 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit< jsval_layout__bindgen_ty_2__bindgen_ty_1, > = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -347,10 +348,7 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).i32_) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).i32_) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -360,10 +358,7 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).u32_) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).u32_) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -373,10 +368,7 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).why) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).why) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -395,6 +387,7 @@ impl Clone for jsval_layout__bindgen_ty_2__bindgen_ty_1 { fn bindgen_test_layout_jsval_layout__bindgen_ty_2() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -406,10 +399,7 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2() { concat!("Alignment of ", stringify!(jsval_layout__bindgen_ty_2)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).payload) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).payload) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -428,6 +418,7 @@ impl Clone for jsval_layout__bindgen_ty_2 { fn bindgen_test_layout_jsval_layout() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -439,10 +430,7 @@ fn bindgen_test_layout_jsval_layout() { concat!("Alignment of ", stringify!(jsval_layout)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).asBits) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).asBits) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -453,7 +441,6 @@ fn bindgen_test_layout_jsval_layout() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).debugView) as usize - ptr as usize }, 0usize, @@ -465,10 +452,7 @@ fn bindgen_test_layout_jsval_layout() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).s) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).s) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -479,7 +463,6 @@ fn bindgen_test_layout_jsval_layout() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).asDouble) as usize - ptr as usize }, 0usize, @@ -491,10 +474,7 @@ fn bindgen_test_layout_jsval_layout() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).asPtr) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).asPtr) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -504,10 +484,7 @@ fn bindgen_test_layout_jsval_layout() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).asWord) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).asWord) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -518,7 +495,6 @@ fn bindgen_test_layout_jsval_layout() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).asUIntPtr) as usize - ptr as usize }, 0usize, @@ -544,6 +520,7 @@ pub struct Value { fn bindgen_test_layout_Value() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -555,10 +532,7 @@ fn bindgen_test_layout_Value() { concat!("Alignment of ", stringify!(Value)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/layout_align.rs b/tests/expectations/tests/layout_align.rs index a6d18d1483..466e76862c 100644 --- a/tests/expectations/tests/layout_align.rs +++ b/tests/expectations/tests/layout_align.rs @@ -171,6 +171,7 @@ pub struct rte_eth_link { fn bindgen_test_layout_rte_eth_link() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -183,7 +184,6 @@ fn bindgen_test_layout_rte_eth_link() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).link_speed) as usize - ptr as usize }, 0usize, diff --git a/tests/expectations/tests/layout_arp.rs b/tests/expectations/tests/layout_arp.rs index f0277dd836..6852c23635 100644 --- a/tests/expectations/tests/layout_arp.rs +++ b/tests/expectations/tests/layout_arp.rs @@ -32,6 +32,7 @@ pub struct ether_addr { fn bindgen_test_layout_ether_addr() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 6usize, @@ -44,7 +45,6 @@ fn bindgen_test_layout_ether_addr() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).addr_bytes) as usize - ptr as usize }, 0usize, @@ -73,6 +73,7 @@ pub struct arp_ipv4 { fn bindgen_test_layout_arp_ipv4() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 20usize, @@ -84,10 +85,7 @@ fn bindgen_test_layout_arp_ipv4() { concat!("Alignment of ", stringify!(arp_ipv4)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).arp_sha) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).arp_sha) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -97,10 +95,7 @@ fn bindgen_test_layout_arp_ipv4() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).arp_sip) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).arp_sip) as usize - ptr as usize }, 6usize, concat!( "Offset of field: ", @@ -110,10 +105,7 @@ fn bindgen_test_layout_arp_ipv4() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).arp_tha) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).arp_tha) as usize - ptr as usize }, 10usize, concat!( "Offset of field: ", @@ -123,10 +115,7 @@ fn bindgen_test_layout_arp_ipv4() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).arp_tip) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).arp_tip) as usize - ptr as usize }, 16usize, concat!( "Offset of field: ", @@ -151,6 +140,7 @@ pub struct arp_hdr { fn bindgen_test_layout_arp_hdr() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 28usize, @@ -162,10 +152,7 @@ fn bindgen_test_layout_arp_hdr() { concat!("Alignment of ", stringify!(arp_hdr)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).arp_hrd) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).arp_hrd) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -175,10 +162,7 @@ fn bindgen_test_layout_arp_hdr() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).arp_pro) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).arp_pro) as usize - ptr as usize }, 2usize, concat!( "Offset of field: ", @@ -188,10 +172,7 @@ fn bindgen_test_layout_arp_hdr() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).arp_hln) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).arp_hln) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -201,10 +182,7 @@ fn bindgen_test_layout_arp_hdr() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).arp_pln) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).arp_pln) as usize - ptr as usize }, 5usize, concat!( "Offset of field: ", @@ -214,10 +192,7 @@ fn bindgen_test_layout_arp_hdr() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).arp_op) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).arp_op) as usize - ptr as usize }, 6usize, concat!( "Offset of field: ", @@ -228,7 +203,6 @@ fn bindgen_test_layout_arp_hdr() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).arp_data) as usize - ptr as usize }, 8usize, diff --git a/tests/expectations/tests/layout_array.rs b/tests/expectations/tests/layout_array.rs index 83fb15b826..f3bbf51e0d 100644 --- a/tests/expectations/tests/layout_array.rs +++ b/tests/expectations/tests/layout_array.rs @@ -71,6 +71,7 @@ pub struct rte_mempool_ops { 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, @@ -82,10 +83,7 @@ fn bindgen_test_layout_rte_mempool_ops() { concat!("Alignment of ", stringify!(rte_mempool_ops)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).name) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).name) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -95,10 +93,7 @@ fn bindgen_test_layout_rte_mempool_ops() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).alloc) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).alloc) as usize - ptr as usize }, 32usize, concat!( "Offset of field: ", @@ -108,10 +103,7 @@ fn bindgen_test_layout_rte_mempool_ops() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).free) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).free) as usize - ptr as usize }, 40usize, concat!( "Offset of field: ", @@ -121,10 +113,7 @@ fn bindgen_test_layout_rte_mempool_ops() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).enqueue) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).enqueue) as usize - ptr as usize }, 48usize, concat!( "Offset of field: ", @@ -134,10 +123,7 @@ fn bindgen_test_layout_rte_mempool_ops() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).dequeue) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).dequeue) as usize - ptr as usize }, 56usize, concat!( "Offset of field: ", @@ -148,7 +134,6 @@ fn bindgen_test_layout_rte_mempool_ops() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).get_count) as usize - ptr as usize }, 64usize, @@ -190,6 +175,7 @@ pub struct rte_spinlock_t { 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, @@ -201,10 +187,7 @@ fn bindgen_test_layout_rte_spinlock_t() { concat!("Alignment of ", stringify!(rte_spinlock_t)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).locked) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).locked) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -237,6 +220,7 @@ pub struct rte_mempool_ops_table { 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, @@ -248,10 +232,7 @@ fn bindgen_test_layout_rte_mempool_ops_table() { concat!("Alignment of ", stringify!(rte_mempool_ops_table)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).sl) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).sl) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -261,10 +242,7 @@ fn bindgen_test_layout_rte_mempool_ops_table() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).num_ops) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).num_ops) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -274,10 +252,7 @@ fn bindgen_test_layout_rte_mempool_ops_table() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).ops) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).ops) as usize - ptr as usize }, 64usize, concat!( "Offset of field: ", @@ -315,6 +290,7 @@ pub struct malloc_heap__bindgen_ty_1 { 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, @@ -327,7 +303,6 @@ fn bindgen_test_layout_malloc_heap__bindgen_ty_1() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).lh_first) as usize - ptr as usize }, 0usize, @@ -352,6 +327,7 @@ impl Default for malloc_heap__bindgen_ty_1 { 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, @@ -363,10 +339,7 @@ fn bindgen_test_layout_malloc_heap() { concat!("Alignment of ", stringify!(malloc_heap)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).lock) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).lock) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -377,7 +350,6 @@ fn bindgen_test_layout_malloc_heap() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).free_head) as usize - ptr as usize }, 8usize, @@ -390,7 +362,6 @@ fn bindgen_test_layout_malloc_heap() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).alloc_count) as usize - ptr as usize }, 112usize, @@ -403,7 +374,6 @@ fn bindgen_test_layout_malloc_heap() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).total_size) as usize - ptr as usize }, 120usize, diff --git a/tests/expectations/tests/layout_array_too_long.rs b/tests/expectations/tests/layout_array_too_long.rs index c1575a0274..56b3c021f5 100644 --- a/tests/expectations/tests/layout_array_too_long.rs +++ b/tests/expectations/tests/layout_array_too_long.rs @@ -37,6 +37,7 @@ pub struct ip_frag { 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, @@ -48,10 +49,7 @@ fn bindgen_test_layout_ip_frag() { concat!("Alignment of ", stringify!(ip_frag)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).ofs) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).ofs) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -61,10 +59,7 @@ fn bindgen_test_layout_ip_frag() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize }, 2usize, concat!( "Offset of field: ", @@ -74,10 +69,7 @@ fn bindgen_test_layout_ip_frag() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mb) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mb) as usize - ptr as usize }, 8usize, concat!( "Offset of field: ", @@ -111,6 +103,7 @@ pub struct ip_frag_key { 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, @@ -122,10 +115,7 @@ fn bindgen_test_layout_ip_frag_key() { concat!("Alignment of ", stringify!(ip_frag_key)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).src_dst) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).src_dst) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -135,10 +125,7 @@ fn bindgen_test_layout_ip_frag_key() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).id) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).id) as usize - ptr as usize }, 32usize, concat!( "Offset of field: ", @@ -148,10 +135,7 @@ fn bindgen_test_layout_ip_frag_key() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).key_len) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).key_len) as usize - ptr as usize }, 36usize, concat!( "Offset of field: ", @@ -192,6 +176,7 @@ pub struct ip_frag_pkt__bindgen_ty_1 { 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, @@ -204,7 +189,6 @@ fn bindgen_test_layout_ip_frag_pkt__bindgen_ty_1() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).tqe_next) as usize - ptr as usize }, 0usize, @@ -217,7 +201,6 @@ fn bindgen_test_layout_ip_frag_pkt__bindgen_ty_1() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).tqe_prev) as usize - ptr as usize }, 8usize, @@ -242,6 +225,7 @@ impl Default for ip_frag_pkt__bindgen_ty_1 { 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, @@ -253,10 +237,7 @@ fn bindgen_test_layout_ip_frag_pkt() { concat!("Alignment of ", stringify!(ip_frag_pkt)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).lru) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).lru) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -266,10 +247,7 @@ fn bindgen_test_layout_ip_frag_pkt() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).key) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).key) as usize - ptr as usize }, 16usize, concat!( "Offset of field: ", @@ -279,10 +257,7 @@ fn bindgen_test_layout_ip_frag_pkt() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).start) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).start) as usize - ptr as usize }, 56usize, concat!( "Offset of field: ", @@ -293,7 +268,6 @@ fn bindgen_test_layout_ip_frag_pkt() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).total_size) as usize - ptr as usize }, 64usize, @@ -306,7 +280,6 @@ fn bindgen_test_layout_ip_frag_pkt() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).frag_size) as usize - ptr as usize }, 68usize, @@ -319,7 +292,6 @@ fn bindgen_test_layout_ip_frag_pkt() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).last_idx) as usize - ptr as usize }, 72usize, @@ -331,10 +303,7 @@ fn bindgen_test_layout_ip_frag_pkt() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).frags) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).frags) as usize - ptr as usize }, 80usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/layout_cmdline_token.rs b/tests/expectations/tests/layout_cmdline_token.rs index 0f6e0ca4ab..899703bd04 100644 --- a/tests/expectations/tests/layout_cmdline_token.rs +++ b/tests/expectations/tests/layout_cmdline_token.rs @@ -17,6 +17,7 @@ pub struct cmdline_token_hdr { fn bindgen_test_layout_cmdline_token_hdr() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -28,10 +29,7 @@ fn bindgen_test_layout_cmdline_token_hdr() { concat!("Alignment of ", stringify!(cmdline_token_hdr)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).ops) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).ops) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -41,10 +39,7 @@ fn bindgen_test_layout_cmdline_token_hdr() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).offset) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).offset) as usize - ptr as usize }, 8usize, concat!( "Offset of field: ", @@ -123,6 +118,7 @@ pub struct cmdline_token_ops { fn bindgen_test_layout_cmdline_token_ops() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 32usize, @@ -134,10 +130,7 @@ fn bindgen_test_layout_cmdline_token_ops() { concat!("Alignment of ", stringify!(cmdline_token_ops)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).parse) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).parse) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -148,7 +141,6 @@ fn bindgen_test_layout_cmdline_token_ops() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).complete_get_nb) as usize - ptr as usize }, 8usize, @@ -161,7 +153,6 @@ fn bindgen_test_layout_cmdline_token_ops() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).complete_get_elt) as usize - ptr as usize }, @@ -175,7 +166,6 @@ fn bindgen_test_layout_cmdline_token_ops() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).get_help) as usize - ptr as usize }, 24usize, @@ -208,6 +198,7 @@ pub struct cmdline_token_num_data { fn bindgen_test_layout_cmdline_token_num_data() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -219,10 +210,7 @@ fn bindgen_test_layout_cmdline_token_num_data() { concat!("Alignment of ", stringify!(cmdline_token_num_data)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -251,6 +239,7 @@ pub struct cmdline_token_num { fn bindgen_test_layout_cmdline_token_num() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 24usize, @@ -262,10 +251,7 @@ fn bindgen_test_layout_cmdline_token_num() { concat!("Alignment of ", stringify!(cmdline_token_num)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).hdr) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).hdr) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -276,7 +262,6 @@ fn bindgen_test_layout_cmdline_token_num() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).num_data) as usize - ptr as usize }, 16usize, diff --git a/tests/expectations/tests/layout_eth_conf.rs b/tests/expectations/tests/layout_eth_conf.rs index 839a4ac690..62b99e9041 100644 --- a/tests/expectations/tests/layout_eth_conf.rs +++ b/tests/expectations/tests/layout_eth_conf.rs @@ -162,6 +162,7 @@ pub struct rte_eth_rxmode { 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, @@ -173,10 +174,7 @@ fn bindgen_test_layout_rte_eth_rxmode() { concat!("Alignment of ", stringify!(rte_eth_rxmode)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mq_mode) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mq_mode) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -187,7 +185,6 @@ fn bindgen_test_layout_rte_eth_rxmode() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).max_rx_pkt_len) as usize - ptr as usize }, 4usize, @@ -200,7 +197,6 @@ fn bindgen_test_layout_rte_eth_rxmode() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).split_hdr_size) as usize - ptr as usize }, 8usize, @@ -429,6 +425,7 @@ pub struct rte_eth_txmode { 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, @@ -440,10 +437,7 @@ fn bindgen_test_layout_rte_eth_txmode() { concat!("Alignment of ", stringify!(rte_eth_txmode)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mq_mode) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mq_mode) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -453,10 +447,7 @@ fn bindgen_test_layout_rte_eth_txmode() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).pvid) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).pvid) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -570,6 +561,7 @@ pub struct rte_eth_rss_conf { 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, @@ -581,10 +573,7 @@ fn bindgen_test_layout_rte_eth_rss_conf() { concat!("Alignment of ", stringify!(rte_eth_rss_conf)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).rss_key) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).rss_key) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -595,7 +584,6 @@ fn bindgen_test_layout_rte_eth_rss_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).rss_key_len) as usize - ptr as usize }, 8usize, @@ -607,10 +595,7 @@ fn bindgen_test_layout_rte_eth_rss_conf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).rss_hf) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).rss_hf) as usize - ptr as usize }, 16usize, concat!( "Offset of field: ", @@ -689,6 +674,7 @@ pub struct rte_eth_vmdq_dcb_conf__bindgen_ty_1 { 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, @@ -703,10 +689,7 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).vlan_id) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).vlan_id) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -716,10 +699,7 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).pools) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).pools) as usize - ptr as usize }, 8usize, concat!( "Offset of field: ", @@ -733,6 +713,7 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf__bindgen_ty_1() { 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, @@ -745,7 +726,6 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize }, 0usize, @@ -758,7 +738,6 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).enable_default_pool) as usize - ptr as usize }, @@ -772,7 +751,6 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).default_pool) as usize - ptr as usize }, 5usize, @@ -785,7 +763,6 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).nb_pool_maps) as usize - ptr as usize }, 6usize, @@ -798,7 +775,6 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).pool_map) as usize - ptr as usize }, 8usize, @@ -810,10 +786,7 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize }, 1032usize, concat!( "Offset of field: ", @@ -844,6 +817,7 @@ pub struct rte_eth_dcb_rx_conf { 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, @@ -855,10 +829,7 @@ fn bindgen_test_layout_rte_eth_dcb_rx_conf() { concat!("Alignment of ", stringify!(rte_eth_dcb_rx_conf)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -868,10 +839,7 @@ fn bindgen_test_layout_rte_eth_dcb_rx_conf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -902,6 +870,7 @@ pub struct rte_eth_vmdq_dcb_tx_conf { 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, @@ -914,7 +883,6 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_tx_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize }, 0usize, @@ -926,10 +894,7 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_tx_conf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -960,6 +925,7 @@ pub struct rte_eth_dcb_tx_conf { 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, @@ -971,10 +937,7 @@ fn bindgen_test_layout_rte_eth_dcb_tx_conf() { concat!("Alignment of ", stringify!(rte_eth_dcb_tx_conf)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -984,10 +947,7 @@ fn bindgen_test_layout_rte_eth_dcb_tx_conf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -1016,6 +976,7 @@ pub struct rte_eth_vmdq_tx_conf { 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, @@ -1028,7 +989,6 @@ fn bindgen_test_layout_rte_eth_vmdq_tx_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize }, 0usize, @@ -1079,6 +1039,7 @@ pub struct rte_eth_vmdq_rx_conf__bindgen_ty_1 { 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, @@ -1093,10 +1054,7 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).vlan_id) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).vlan_id) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -1106,10 +1064,7 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).pools) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).pools) as usize - ptr as usize }, 8usize, concat!( "Offset of field: ", @@ -1123,6 +1078,7 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf__bindgen_ty_1() { 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, @@ -1135,7 +1091,6 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize }, 0usize, @@ -1148,7 +1103,6 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).enable_default_pool) as usize - ptr as usize }, @@ -1162,7 +1116,6 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).default_pool) as usize - ptr as usize }, 5usize, @@ -1175,7 +1128,6 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).enable_loop_back) as usize - ptr as usize }, @@ -1189,7 +1141,6 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).nb_pool_maps) as usize - ptr as usize }, 7usize, @@ -1201,10 +1152,7 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).rx_mode) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).rx_mode) as usize - ptr as usize }, 8usize, concat!( "Offset of field: ", @@ -1215,7 +1163,6 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).pool_map) as usize - ptr as usize }, 16usize, @@ -1293,6 +1240,7 @@ pub struct rte_eth_ipv4_flow { 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, @@ -1304,10 +1252,7 @@ fn bindgen_test_layout_rte_eth_ipv4_flow() { concat!("Alignment of ", stringify!(rte_eth_ipv4_flow)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -1317,10 +1262,7 @@ fn bindgen_test_layout_rte_eth_ipv4_flow() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).dst_ip) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).dst_ip) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -1330,10 +1272,7 @@ fn bindgen_test_layout_rte_eth_ipv4_flow() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).tos) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).tos) as usize - ptr as usize }, 8usize, concat!( "Offset of field: ", @@ -1343,10 +1282,7 @@ fn bindgen_test_layout_rte_eth_ipv4_flow() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).ttl) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).ttl) as usize - ptr as usize }, 9usize, concat!( "Offset of field: ", @@ -1356,10 +1292,7 @@ fn bindgen_test_layout_rte_eth_ipv4_flow() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize }, 10usize, concat!( "Offset of field: ", @@ -1388,6 +1321,7 @@ pub struct rte_eth_ipv6_flow { 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, @@ -1399,10 +1333,7 @@ fn bindgen_test_layout_rte_eth_ipv6_flow() { concat!("Alignment of ", stringify!(rte_eth_ipv6_flow)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -1412,10 +1343,7 @@ fn bindgen_test_layout_rte_eth_ipv6_flow() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).dst_ip) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).dst_ip) as usize - ptr as usize }, 16usize, concat!( "Offset of field: ", @@ -1425,10 +1353,7 @@ fn bindgen_test_layout_rte_eth_ipv6_flow() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).tc) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).tc) as usize - ptr as usize }, 32usize, concat!( "Offset of field: ", @@ -1438,10 +1363,7 @@ fn bindgen_test_layout_rte_eth_ipv6_flow() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize }, 33usize, concat!( "Offset of field: ", @@ -1452,7 +1374,6 @@ fn bindgen_test_layout_rte_eth_ipv6_flow() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).hop_limits) as usize - ptr as usize }, 34usize, @@ -1492,6 +1413,7 @@ pub struct rte_eth_fdir_masks { 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, @@ -1504,7 +1426,6 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).vlan_tci_mask) as usize - ptr as usize }, 0usize, @@ -1517,7 +1438,6 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).ipv4_mask) as usize - ptr as usize }, 4usize, @@ -1530,7 +1450,6 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).ipv6_mask) as usize - ptr as usize }, 16usize, @@ -1543,7 +1462,6 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).src_port_mask) as usize - ptr as usize }, 52usize, @@ -1556,7 +1474,6 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).dst_port_mask) as usize - ptr as usize }, 54usize, @@ -1569,7 +1486,6 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mac_addr_byte_mask) as usize - ptr as usize }, @@ -1583,7 +1499,6 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).tunnel_id_mask) as usize - ptr as usize }, 60usize, @@ -1596,7 +1511,6 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).tunnel_type_mask) as usize - ptr as usize }, @@ -1633,6 +1547,7 @@ pub struct rte_eth_flex_payload_cfg { 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, @@ -1644,10 +1559,7 @@ fn bindgen_test_layout_rte_eth_flex_payload_cfg() { concat!("Alignment of ", stringify!(rte_eth_flex_payload_cfg)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -1658,7 +1570,6 @@ fn bindgen_test_layout_rte_eth_flex_payload_cfg() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).src_offset) as usize - ptr as usize }, 4usize, @@ -1691,6 +1602,7 @@ pub struct rte_eth_fdir_flex_mask { 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, @@ -1703,7 +1615,6 @@ fn bindgen_test_layout_rte_eth_fdir_flex_mask() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).flow_type) as usize - ptr as usize }, 0usize, @@ -1715,10 +1626,7 @@ fn bindgen_test_layout_rte_eth_fdir_flex_mask() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize }, 2usize, concat!( "Offset of field: ", @@ -1744,6 +1652,7 @@ pub struct rte_eth_fdir_flex_conf { 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, @@ -1756,7 +1665,6 @@ fn bindgen_test_layout_rte_eth_fdir_flex_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).nb_payloads) as usize - ptr as usize }, 0usize, @@ -1769,7 +1677,6 @@ fn bindgen_test_layout_rte_eth_fdir_flex_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).nb_flexmasks) as usize - ptr as usize }, 2usize, @@ -1782,7 +1689,6 @@ fn bindgen_test_layout_rte_eth_fdir_flex_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).flex_set) as usize - ptr as usize }, 4usize, @@ -1795,7 +1701,6 @@ fn bindgen_test_layout_rte_eth_fdir_flex_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).flex_mask) as usize - ptr as usize }, 292usize, @@ -1838,6 +1743,7 @@ pub struct rte_fdir_conf { 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, @@ -1849,10 +1755,7 @@ fn bindgen_test_layout_rte_fdir_conf() { concat!("Alignment of ", stringify!(rte_fdir_conf)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mode) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mode) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -1862,10 +1765,7 @@ fn bindgen_test_layout_rte_fdir_conf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).pballoc) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).pballoc) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -1875,10 +1775,7 @@ fn bindgen_test_layout_rte_fdir_conf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).status) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).status) as usize - ptr as usize }, 8usize, concat!( "Offset of field: ", @@ -1889,7 +1786,6 @@ fn bindgen_test_layout_rte_fdir_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).drop_queue) as usize - ptr as usize }, 12usize, @@ -1901,10 +1797,7 @@ fn bindgen_test_layout_rte_fdir_conf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize }, 16usize, concat!( "Offset of field: ", @@ -1915,7 +1808,6 @@ fn bindgen_test_layout_rte_fdir_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).flex_conf) as usize - ptr as usize }, 84usize, @@ -1949,6 +1841,7 @@ pub struct rte_intr_conf { 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, @@ -1960,10 +1853,7 @@ fn bindgen_test_layout_rte_intr_conf() { concat!("Alignment of ", stringify!(rte_intr_conf)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).lsc) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).lsc) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -1973,10 +1863,7 @@ fn bindgen_test_layout_rte_intr_conf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).rxq) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).rxq) as usize - ptr as usize }, 2usize, concat!( "Offset of field: ", @@ -2035,6 +1922,7 @@ pub struct rte_eth_conf__bindgen_ty_1 { 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, @@ -2047,7 +1935,6 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_1() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).rss_conf) as usize - ptr as usize }, 0usize, @@ -2060,7 +1947,6 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_1() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).vmdq_dcb_conf) as usize - ptr as usize }, 24usize, @@ -2073,7 +1959,6 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_1() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).dcb_rx_conf) as usize - ptr as usize }, 1064usize, @@ -2086,7 +1971,6 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_1() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).vmdq_rx_conf) as usize - ptr as usize }, 1080usize, @@ -2118,6 +2002,7 @@ pub union rte_eth_conf__bindgen_ty_2 { 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, @@ -2130,7 +2015,6 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_2() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).vmdq_dcb_tx_conf) as usize - ptr as usize }, @@ -2144,7 +2028,6 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_2() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).dcb_tx_conf) as usize - ptr as usize }, 0usize, @@ -2157,7 +2040,6 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_2() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).vmdq_tx_conf) as usize - ptr as usize }, 0usize, @@ -2182,6 +2064,7 @@ impl Default for rte_eth_conf__bindgen_ty_2 { 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, @@ -2194,7 +2077,6 @@ fn bindgen_test_layout_rte_eth_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).link_speeds) as usize - ptr as usize }, 0usize, @@ -2206,10 +2088,7 @@ fn bindgen_test_layout_rte_eth_conf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).rxmode) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).rxmode) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -2219,10 +2098,7 @@ fn bindgen_test_layout_rte_eth_conf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).txmode) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).txmode) as usize - ptr as usize }, 16usize, concat!( "Offset of field: ", @@ -2233,7 +2109,6 @@ fn bindgen_test_layout_rte_eth_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).lpbk_mode) as usize - ptr as usize }, 24usize, @@ -2246,7 +2121,6 @@ fn bindgen_test_layout_rte_eth_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).rx_adv_conf) as usize - ptr as usize }, 32usize, @@ -2259,7 +2133,6 @@ fn bindgen_test_layout_rte_eth_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).tx_adv_conf) as usize - ptr as usize }, 2152usize, @@ -2272,7 +2145,6 @@ fn bindgen_test_layout_rte_eth_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).dcb_capability_en) as usize - ptr as usize }, @@ -2286,7 +2158,6 @@ fn bindgen_test_layout_rte_eth_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).fdir_conf) as usize - ptr as usize }, 2168usize, @@ -2299,7 +2170,6 @@ fn bindgen_test_layout_rte_eth_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).intr_conf) as usize - ptr as usize }, 2940usize, diff --git a/tests/expectations/tests/layout_eth_conf_1_0.rs b/tests/expectations/tests/layout_eth_conf_1_0.rs index fcec665f31..d7fa0a634a 100644 --- a/tests/expectations/tests/layout_eth_conf_1_0.rs +++ b/tests/expectations/tests/layout_eth_conf_1_0.rs @@ -205,6 +205,7 @@ pub struct rte_eth_rxmode { 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, @@ -216,10 +217,7 @@ fn bindgen_test_layout_rte_eth_rxmode() { concat!("Alignment of ", stringify!(rte_eth_rxmode)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mq_mode) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mq_mode) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -230,7 +228,6 @@ fn bindgen_test_layout_rte_eth_rxmode() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).max_rx_pkt_len) as usize - ptr as usize }, 4usize, @@ -243,7 +240,6 @@ fn bindgen_test_layout_rte_eth_rxmode() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).split_hdr_size) as usize - ptr as usize }, 8usize, @@ -477,6 +473,7 @@ pub struct rte_eth_txmode { 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, @@ -488,10 +485,7 @@ fn bindgen_test_layout_rte_eth_txmode() { concat!("Alignment of ", stringify!(rte_eth_txmode)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mq_mode) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mq_mode) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -501,10 +495,7 @@ fn bindgen_test_layout_rte_eth_txmode() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).pvid) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).pvid) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -623,6 +614,7 @@ pub struct rte_eth_rss_conf { 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, @@ -634,10 +626,7 @@ fn bindgen_test_layout_rte_eth_rss_conf() { concat!("Alignment of ", stringify!(rte_eth_rss_conf)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).rss_key) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).rss_key) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -648,7 +637,6 @@ fn bindgen_test_layout_rte_eth_rss_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).rss_key_len) as usize - ptr as usize }, 8usize, @@ -660,10 +648,7 @@ fn bindgen_test_layout_rte_eth_rss_conf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).rss_hf) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).rss_hf) as usize - ptr as usize }, 16usize, concat!( "Offset of field: ", @@ -747,6 +732,7 @@ pub struct rte_eth_vmdq_dcb_conf__bindgen_ty_1 { 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, @@ -761,10 +747,7 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).vlan_id) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).vlan_id) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -774,10 +757,7 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).pools) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).pools) as usize - ptr as usize }, 8usize, concat!( "Offset of field: ", @@ -796,6 +776,7 @@ impl Clone for rte_eth_vmdq_dcb_conf__bindgen_ty_1 { 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, @@ -808,7 +789,6 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize }, 0usize, @@ -821,7 +801,6 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).enable_default_pool) as usize - ptr as usize }, @@ -835,7 +814,6 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).default_pool) as usize - ptr as usize }, 5usize, @@ -848,7 +826,6 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).nb_pool_maps) as usize - ptr as usize }, 6usize, @@ -861,7 +838,6 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).pool_map) as usize - ptr as usize }, 8usize, @@ -873,10 +849,7 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize }, 1032usize, concat!( "Offset of field: ", @@ -912,6 +885,7 @@ pub struct rte_eth_dcb_rx_conf { 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, @@ -923,10 +897,7 @@ fn bindgen_test_layout_rte_eth_dcb_rx_conf() { concat!("Alignment of ", stringify!(rte_eth_dcb_rx_conf)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -936,10 +907,7 @@ fn bindgen_test_layout_rte_eth_dcb_rx_conf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -975,6 +943,7 @@ pub struct rte_eth_vmdq_dcb_tx_conf { 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, @@ -987,7 +956,6 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_tx_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize }, 0usize, @@ -999,10 +967,7 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_tx_conf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -1038,6 +1003,7 @@ pub struct rte_eth_dcb_tx_conf { 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, @@ -1049,10 +1015,7 @@ fn bindgen_test_layout_rte_eth_dcb_tx_conf() { concat!("Alignment of ", stringify!(rte_eth_dcb_tx_conf)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -1062,10 +1025,7 @@ fn bindgen_test_layout_rte_eth_dcb_tx_conf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -1099,6 +1059,7 @@ pub struct rte_eth_vmdq_tx_conf { 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, @@ -1111,7 +1072,6 @@ fn bindgen_test_layout_rte_eth_vmdq_tx_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize }, 0usize, @@ -1167,6 +1127,7 @@ pub struct rte_eth_vmdq_rx_conf__bindgen_ty_1 { 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, @@ -1181,10 +1142,7 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).vlan_id) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).vlan_id) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -1194,10 +1152,7 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).pools) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).pools) as usize - ptr as usize }, 8usize, concat!( "Offset of field: ", @@ -1216,6 +1171,7 @@ impl Clone for rte_eth_vmdq_rx_conf__bindgen_ty_1 { 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, @@ -1228,7 +1184,6 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize }, 0usize, @@ -1241,7 +1196,6 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).enable_default_pool) as usize - ptr as usize }, @@ -1255,7 +1209,6 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).default_pool) as usize - ptr as usize }, 5usize, @@ -1268,7 +1221,6 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).enable_loop_back) as usize - ptr as usize }, @@ -1282,7 +1234,6 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).nb_pool_maps) as usize - ptr as usize }, 7usize, @@ -1294,10 +1245,7 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).rx_mode) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).rx_mode) as usize - ptr as usize }, 8usize, concat!( "Offset of field: ", @@ -1308,7 +1256,6 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).pool_map) as usize - ptr as usize }, 16usize, @@ -1391,6 +1338,7 @@ pub struct rte_eth_ipv4_flow { 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, @@ -1402,10 +1350,7 @@ fn bindgen_test_layout_rte_eth_ipv4_flow() { concat!("Alignment of ", stringify!(rte_eth_ipv4_flow)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -1415,10 +1360,7 @@ fn bindgen_test_layout_rte_eth_ipv4_flow() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).dst_ip) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).dst_ip) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -1428,10 +1370,7 @@ fn bindgen_test_layout_rte_eth_ipv4_flow() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).tos) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).tos) as usize - ptr as usize }, 8usize, concat!( "Offset of field: ", @@ -1441,10 +1380,7 @@ fn bindgen_test_layout_rte_eth_ipv4_flow() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).ttl) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).ttl) as usize - ptr as usize }, 9usize, concat!( "Offset of field: ", @@ -1454,10 +1390,7 @@ fn bindgen_test_layout_rte_eth_ipv4_flow() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize }, 10usize, concat!( "Offset of field: ", @@ -1491,6 +1424,7 @@ pub struct rte_eth_ipv6_flow { 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, @@ -1502,10 +1436,7 @@ fn bindgen_test_layout_rte_eth_ipv6_flow() { concat!("Alignment of ", stringify!(rte_eth_ipv6_flow)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -1515,10 +1446,7 @@ fn bindgen_test_layout_rte_eth_ipv6_flow() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).dst_ip) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).dst_ip) as usize - ptr as usize }, 16usize, concat!( "Offset of field: ", @@ -1528,10 +1456,7 @@ fn bindgen_test_layout_rte_eth_ipv6_flow() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).tc) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).tc) as usize - ptr as usize }, 32usize, concat!( "Offset of field: ", @@ -1541,10 +1466,7 @@ fn bindgen_test_layout_rte_eth_ipv6_flow() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize }, 33usize, concat!( "Offset of field: ", @@ -1555,7 +1477,6 @@ fn bindgen_test_layout_rte_eth_ipv6_flow() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).hop_limits) as usize - ptr as usize }, 34usize, @@ -1600,6 +1521,7 @@ pub struct rte_eth_fdir_masks { 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, @@ -1612,7 +1534,6 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).vlan_tci_mask) as usize - ptr as usize }, 0usize, @@ -1625,7 +1546,6 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).ipv4_mask) as usize - ptr as usize }, 4usize, @@ -1638,7 +1558,6 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).ipv6_mask) as usize - ptr as usize }, 16usize, @@ -1651,7 +1570,6 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).src_port_mask) as usize - ptr as usize }, 52usize, @@ -1664,7 +1582,6 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).dst_port_mask) as usize - ptr as usize }, 54usize, @@ -1677,7 +1594,6 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mac_addr_byte_mask) as usize - ptr as usize }, @@ -1691,7 +1607,6 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).tunnel_id_mask) as usize - ptr as usize }, 60usize, @@ -1704,7 +1619,6 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).tunnel_type_mask) as usize - ptr as usize }, @@ -1746,6 +1660,7 @@ pub struct rte_eth_flex_payload_cfg { 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, @@ -1757,10 +1672,7 @@ fn bindgen_test_layout_rte_eth_flex_payload_cfg() { concat!("Alignment of ", stringify!(rte_eth_flex_payload_cfg)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -1771,7 +1683,6 @@ fn bindgen_test_layout_rte_eth_flex_payload_cfg() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).src_offset) as usize - ptr as usize }, 4usize, @@ -1809,6 +1720,7 @@ pub struct rte_eth_fdir_flex_mask { 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, @@ -1821,7 +1733,6 @@ fn bindgen_test_layout_rte_eth_fdir_flex_mask() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).flow_type) as usize - ptr as usize }, 0usize, @@ -1833,10 +1744,7 @@ fn bindgen_test_layout_rte_eth_fdir_flex_mask() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize }, 2usize, concat!( "Offset of field: ", @@ -1867,6 +1775,7 @@ pub struct rte_eth_fdir_flex_conf { 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, @@ -1879,7 +1788,6 @@ fn bindgen_test_layout_rte_eth_fdir_flex_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).nb_payloads) as usize - ptr as usize }, 0usize, @@ -1892,7 +1800,6 @@ fn bindgen_test_layout_rte_eth_fdir_flex_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).nb_flexmasks) as usize - ptr as usize }, 2usize, @@ -1905,7 +1812,6 @@ fn bindgen_test_layout_rte_eth_fdir_flex_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).flex_set) as usize - ptr as usize }, 4usize, @@ -1918,7 +1824,6 @@ fn bindgen_test_layout_rte_eth_fdir_flex_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).flex_mask) as usize - ptr as usize }, 292usize, @@ -1966,6 +1871,7 @@ pub struct rte_fdir_conf { 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, @@ -1977,10 +1883,7 @@ fn bindgen_test_layout_rte_fdir_conf() { concat!("Alignment of ", stringify!(rte_fdir_conf)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mode) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mode) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -1990,10 +1893,7 @@ fn bindgen_test_layout_rte_fdir_conf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).pballoc) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).pballoc) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -2003,10 +1903,7 @@ fn bindgen_test_layout_rte_fdir_conf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).status) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).status) as usize - ptr as usize }, 8usize, concat!( "Offset of field: ", @@ -2017,7 +1914,6 @@ fn bindgen_test_layout_rte_fdir_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).drop_queue) as usize - ptr as usize }, 12usize, @@ -2029,10 +1925,7 @@ fn bindgen_test_layout_rte_fdir_conf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize }, 16usize, concat!( "Offset of field: ", @@ -2043,7 +1936,6 @@ fn bindgen_test_layout_rte_fdir_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).flex_conf) as usize - ptr as usize }, 84usize, @@ -2082,6 +1974,7 @@ pub struct rte_intr_conf { 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, @@ -2093,10 +1986,7 @@ fn bindgen_test_layout_rte_intr_conf() { concat!("Alignment of ", stringify!(rte_intr_conf)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).lsc) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).lsc) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -2106,10 +1996,7 @@ fn bindgen_test_layout_rte_intr_conf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).rxq) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).rxq) as usize - ptr as usize }, 2usize, concat!( "Offset of field: ", @@ -2173,6 +2060,7 @@ pub struct rte_eth_conf__bindgen_ty_1 { 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, @@ -2185,7 +2073,6 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_1() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).rss_conf) as usize - ptr as usize }, 0usize, @@ -2198,7 +2085,6 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_1() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).vmdq_dcb_conf) as usize - ptr as usize }, 24usize, @@ -2211,7 +2097,6 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_1() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).dcb_rx_conf) as usize - ptr as usize }, 1064usize, @@ -2224,7 +2109,6 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_1() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).vmdq_rx_conf) as usize - ptr as usize }, 1080usize, @@ -2262,6 +2146,7 @@ pub struct rte_eth_conf__bindgen_ty_2 { 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, @@ -2274,7 +2159,6 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_2() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).vmdq_dcb_tx_conf) as usize - ptr as usize }, @@ -2288,7 +2172,6 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_2() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).dcb_tx_conf) as usize - ptr as usize }, 0usize, @@ -2301,7 +2184,6 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_2() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).vmdq_tx_conf) as usize - ptr as usize }, 0usize, @@ -2322,6 +2204,7 @@ impl Clone for rte_eth_conf__bindgen_ty_2 { 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, @@ -2334,7 +2217,6 @@ fn bindgen_test_layout_rte_eth_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).link_speeds) as usize - ptr as usize }, 0usize, @@ -2346,10 +2228,7 @@ fn bindgen_test_layout_rte_eth_conf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).rxmode) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).rxmode) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -2359,10 +2238,7 @@ fn bindgen_test_layout_rte_eth_conf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).txmode) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).txmode) as usize - ptr as usize }, 16usize, concat!( "Offset of field: ", @@ -2373,7 +2249,6 @@ fn bindgen_test_layout_rte_eth_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).lpbk_mode) as usize - ptr as usize }, 24usize, @@ -2386,7 +2261,6 @@ fn bindgen_test_layout_rte_eth_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).rx_adv_conf) as usize - ptr as usize }, 32usize, @@ -2399,7 +2273,6 @@ fn bindgen_test_layout_rte_eth_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).tx_adv_conf) as usize - ptr as usize }, 2152usize, @@ -2412,7 +2285,6 @@ fn bindgen_test_layout_rte_eth_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).dcb_capability_en) as usize - ptr as usize }, @@ -2426,7 +2298,6 @@ fn bindgen_test_layout_rte_eth_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).fdir_conf) as usize - ptr as usize }, 2168usize, @@ -2439,7 +2310,6 @@ fn bindgen_test_layout_rte_eth_conf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).intr_conf) as usize - ptr as usize }, 2940usize, diff --git a/tests/expectations/tests/layout_kni_mbuf.rs b/tests/expectations/tests/layout_kni_mbuf.rs index eb17fa63e2..be88d20fff 100644 --- a/tests/expectations/tests/layout_kni_mbuf.rs +++ b/tests/expectations/tests/layout_kni_mbuf.rs @@ -36,6 +36,7 @@ pub struct rte_kni_mbuf { 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, @@ -48,7 +49,6 @@ fn bindgen_test_layout_rte_kni_mbuf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).buf_addr) as usize - ptr as usize }, 0usize, @@ -61,7 +61,6 @@ fn bindgen_test_layout_rte_kni_mbuf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).buf_physaddr) as usize - ptr as usize }, 8usize, @@ -73,10 +72,7 @@ fn bindgen_test_layout_rte_kni_mbuf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).pad0) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).pad0) as usize - ptr as usize }, 16usize, concat!( "Offset of field: ", @@ -87,7 +83,6 @@ fn bindgen_test_layout_rte_kni_mbuf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).data_off) as usize - ptr as usize }, 18usize, @@ -99,10 +94,7 @@ fn bindgen_test_layout_rte_kni_mbuf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).pad1) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).pad1) as usize - ptr as usize }, 20usize, concat!( "Offset of field: ", @@ -112,10 +104,7 @@ fn bindgen_test_layout_rte_kni_mbuf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_segs) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).nb_segs) as usize - ptr as usize }, 22usize, concat!( "Offset of field: ", @@ -125,10 +114,7 @@ fn bindgen_test_layout_rte_kni_mbuf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).pad4) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).pad4) as usize - ptr as usize }, 23usize, concat!( "Offset of field: ", @@ -139,7 +125,6 @@ fn bindgen_test_layout_rte_kni_mbuf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).ol_flags) as usize - ptr as usize }, 24usize, @@ -151,10 +136,7 @@ fn bindgen_test_layout_rte_kni_mbuf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).pad2) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).pad2) as usize - ptr as usize }, 32usize, concat!( "Offset of field: ", @@ -164,10 +146,7 @@ fn bindgen_test_layout_rte_kni_mbuf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).pkt_len) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).pkt_len) as usize - ptr as usize }, 36usize, concat!( "Offset of field: ", @@ -178,7 +157,6 @@ fn bindgen_test_layout_rte_kni_mbuf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).data_len) as usize - ptr as usize }, 40usize, @@ -190,10 +168,7 @@ fn bindgen_test_layout_rte_kni_mbuf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).pad3) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).pad3) as usize - ptr as usize }, 64usize, concat!( "Offset of field: ", @@ -203,10 +178,7 @@ fn bindgen_test_layout_rte_kni_mbuf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).pool) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).pool) as usize - ptr as usize }, 72usize, concat!( "Offset of field: ", @@ -216,10 +188,7 @@ fn bindgen_test_layout_rte_kni_mbuf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize }, 80usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/layout_large_align_field.rs b/tests/expectations/tests/layout_large_align_field.rs index 3f050269f6..075ef46ae4 100644 --- a/tests/expectations/tests/layout_large_align_field.rs +++ b/tests/expectations/tests/layout_large_align_field.rs @@ -67,6 +67,7 @@ pub struct ip_frag { 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, @@ -78,10 +79,7 @@ fn bindgen_test_layout_ip_frag() { concat!("Alignment of ", stringify!(ip_frag)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).ofs) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).ofs) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -91,10 +89,7 @@ fn bindgen_test_layout_ip_frag() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize }, 2usize, concat!( "Offset of field: ", @@ -104,10 +99,7 @@ fn bindgen_test_layout_ip_frag() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mb) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mb) as usize - ptr as usize }, 8usize, concat!( "Offset of field: ", @@ -141,6 +133,7 @@ pub struct ip_frag_key { 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, @@ -152,10 +145,7 @@ fn bindgen_test_layout_ip_frag_key() { concat!("Alignment of ", stringify!(ip_frag_key)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).src_dst) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).src_dst) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -165,10 +155,7 @@ fn bindgen_test_layout_ip_frag_key() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).id) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).id) as usize - ptr as usize }, 32usize, concat!( "Offset of field: ", @@ -178,10 +165,7 @@ fn bindgen_test_layout_ip_frag_key() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).key_len) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).key_len) as usize - ptr as usize }, 36usize, concat!( "Offset of field: ", @@ -222,6 +206,7 @@ pub struct ip_frag_pkt__bindgen_ty_1 { 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, @@ -234,7 +219,6 @@ fn bindgen_test_layout_ip_frag_pkt__bindgen_ty_1() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).tqe_next) as usize - ptr as usize }, 0usize, @@ -247,7 +231,6 @@ fn bindgen_test_layout_ip_frag_pkt__bindgen_ty_1() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).tqe_prev) as usize - ptr as usize }, 8usize, @@ -272,6 +255,7 @@ impl Default for ip_frag_pkt__bindgen_ty_1 { 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, @@ -283,10 +267,7 @@ fn bindgen_test_layout_ip_frag_pkt() { concat!("Alignment of ", stringify!(ip_frag_pkt)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).lru) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).lru) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -296,10 +277,7 @@ fn bindgen_test_layout_ip_frag_pkt() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).key) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).key) as usize - ptr as usize }, 16usize, concat!( "Offset of field: ", @@ -309,10 +287,7 @@ fn bindgen_test_layout_ip_frag_pkt() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).start) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).start) as usize - ptr as usize }, 56usize, concat!( "Offset of field: ", @@ -323,7 +298,6 @@ fn bindgen_test_layout_ip_frag_pkt() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).total_size) as usize - ptr as usize }, 64usize, @@ -336,7 +310,6 @@ fn bindgen_test_layout_ip_frag_pkt() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).frag_size) as usize - ptr as usize }, 68usize, @@ -349,7 +322,6 @@ fn bindgen_test_layout_ip_frag_pkt() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).last_idx) as usize - ptr as usize }, 72usize, @@ -361,10 +333,7 @@ fn bindgen_test_layout_ip_frag_pkt() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).frags) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).frags) as usize - ptr as usize }, 80usize, concat!( "Offset of field: ", @@ -393,6 +362,7 @@ pub struct ip_pkt_list { 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, @@ -405,7 +375,6 @@ fn bindgen_test_layout_ip_pkt_list() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).tqh_first) as usize - ptr as usize }, 0usize, @@ -418,7 +387,6 @@ fn bindgen_test_layout_ip_pkt_list() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).tqh_last) as usize - ptr as usize }, 8usize, @@ -461,6 +429,7 @@ pub struct ip_frag_tbl_stat { 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, @@ -473,7 +442,6 @@ fn bindgen_test_layout_ip_frag_tbl_stat() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).find_num) as usize - ptr as usize }, 0usize, @@ -485,10 +453,7 @@ fn bindgen_test_layout_ip_frag_tbl_stat() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).add_num) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).add_num) as usize - ptr as usize }, 8usize, concat!( "Offset of field: ", @@ -498,10 +463,7 @@ fn bindgen_test_layout_ip_frag_tbl_stat() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).del_num) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).del_num) as usize - ptr as usize }, 16usize, concat!( "Offset of field: ", @@ -512,7 +474,6 @@ fn bindgen_test_layout_ip_frag_tbl_stat() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).reuse_num) as usize - ptr as usize }, 24usize, @@ -525,7 +486,6 @@ fn bindgen_test_layout_ip_frag_tbl_stat() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).fail_total) as usize - ptr as usize }, 32usize, @@ -538,7 +498,6 @@ fn bindgen_test_layout_ip_frag_tbl_stat() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).fail_nospace) as usize - ptr as usize }, 40usize, @@ -591,6 +550,7 @@ pub struct rte_ip_frag_tbl { 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, @@ -603,7 +563,6 @@ fn bindgen_test_layout_rte_ip_frag_tbl() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).max_cycles) as usize - ptr as usize }, 0usize, @@ -616,7 +575,6 @@ fn bindgen_test_layout_rte_ip_frag_tbl() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).entry_mask) as usize - ptr as usize }, 8usize, @@ -629,7 +587,6 @@ fn bindgen_test_layout_rte_ip_frag_tbl() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).max_entries) as usize - ptr as usize }, 12usize, @@ -642,7 +599,6 @@ fn bindgen_test_layout_rte_ip_frag_tbl() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).use_entries) as usize - ptr as usize }, 16usize, @@ -655,7 +611,6 @@ fn bindgen_test_layout_rte_ip_frag_tbl() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).bucket_entries) as usize - ptr as usize }, 20usize, @@ -668,7 +623,6 @@ fn bindgen_test_layout_rte_ip_frag_tbl() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).nb_entries) as usize - ptr as usize }, 24usize, @@ -681,7 +635,6 @@ fn bindgen_test_layout_rte_ip_frag_tbl() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).nb_buckets) as usize - ptr as usize }, 28usize, @@ -693,10 +646,7 @@ fn bindgen_test_layout_rte_ip_frag_tbl() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).last) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).last) as usize - ptr as usize }, 32usize, concat!( "Offset of field: ", @@ -706,10 +656,7 @@ fn bindgen_test_layout_rte_ip_frag_tbl() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).lru) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).lru) as usize - ptr as usize }, 40usize, concat!( "Offset of field: ", @@ -719,10 +666,7 @@ fn bindgen_test_layout_rte_ip_frag_tbl() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).stat) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).stat) as usize - ptr as usize }, 64usize, concat!( "Offset of field: ", @@ -732,10 +676,7 @@ fn bindgen_test_layout_rte_ip_frag_tbl() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).pkt) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).pkt) as usize - ptr as usize }, 128usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/layout_mbuf.rs b/tests/expectations/tests/layout_mbuf.rs index 5a7d77b7ad..800a303be1 100644 --- a/tests/expectations/tests/layout_mbuf.rs +++ b/tests/expectations/tests/layout_mbuf.rs @@ -108,6 +108,7 @@ pub struct rte_atomic16_t { fn bindgen_test_layout_rte_atomic16_t() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 2usize, @@ -119,10 +120,7 @@ fn bindgen_test_layout_rte_atomic16_t() { concat!("Alignment of ", stringify!(rte_atomic16_t)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).cnt) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).cnt) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -197,6 +195,7 @@ pub union rte_mbuf__bindgen_ty_1 { fn bindgen_test_layout_rte_mbuf__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 2usize, @@ -209,7 +208,6 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_1() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).refcnt_atomic) as usize - ptr as usize }, 0usize, @@ -221,10 +219,7 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).refcnt) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).refcnt) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -418,6 +413,7 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { fn bindgen_test_layout_rte_mbuf__bindgen_ty_2() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -430,7 +426,6 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_2() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).packet_type) as usize - ptr as usize }, 0usize, @@ -488,16 +483,18 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindg const UNINIT: ::std::mem::MaybeUninit< rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1, > = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq ! (:: std :: mem :: size_of :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > () , 4usize , concat ! ("Size of: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1))); assert_eq ! (:: std :: mem :: align_of :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > () , 2usize , concat ! ("Alignment of " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1))); - assert_eq ! (unsafe { let ptr = UNINIT . as_ptr () ; :: std :: ptr :: addr_of ! ((* ptr) . hash) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (hash))); - assert_eq ! (unsafe { let ptr = UNINIT . as_ptr () ; :: std :: ptr :: addr_of ! ((* ptr) . id) as usize - ptr as usize } , 2usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (id))); + assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . hash) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (hash))); + assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . id) as usize - ptr as usize } , 2usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (id))); } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit< rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1, > = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::( ), @@ -518,10 +515,7 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).lo) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).lo) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -545,6 +539,7 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit< rte_mbuf__bindgen_ty_3__bindgen_ty_1, > = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -562,10 +557,7 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).hi) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).hi) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -595,6 +587,7 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_2() { const UNINIT: ::std::mem::MaybeUninit< rte_mbuf__bindgen_ty_3__bindgen_ty_2, > = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -612,10 +605,7 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_2() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).lo) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).lo) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -625,10 +615,7 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_2() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).hi) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).hi) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -642,6 +629,7 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_2() { fn bindgen_test_layout_rte_mbuf__bindgen_ty_3() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -653,10 +641,7 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3() { concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_3)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).rss) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).rss) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -666,10 +651,7 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).fdir) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).fdir) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -679,10 +661,7 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).sched) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).sched) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -692,10 +671,7 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).usr) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).usr) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -726,6 +702,7 @@ pub union rte_mbuf__bindgen_ty_4 { fn bindgen_test_layout_rte_mbuf__bindgen_ty_4() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -738,7 +715,6 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_4() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).userdata) as usize - ptr as usize }, 0usize, @@ -750,10 +726,7 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_4() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).udata64) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).udata64) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -928,6 +901,7 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { fn bindgen_test_layout_rte_mbuf__bindgen_ty_5() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -940,7 +914,6 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_5() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).tx_offload) as usize - ptr as usize }, 0usize, @@ -965,6 +938,7 @@ impl Default for rte_mbuf__bindgen_ty_5 { fn bindgen_test_layout_rte_mbuf() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 128usize, @@ -977,7 +951,6 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).cacheline0) as usize - ptr as usize }, 0usize, @@ -990,7 +963,6 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).buf_addr) as usize - ptr as usize }, 0usize, @@ -1003,7 +975,6 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).buf_physaddr) as usize - ptr as usize }, 8usize, @@ -1015,10 +986,7 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).buf_len) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).buf_len) as usize - ptr as usize }, 16usize, concat!( "Offset of field: ", @@ -1029,7 +997,6 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).rearm_data) as usize - ptr as usize }, 18usize, @@ -1042,7 +1009,6 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).data_off) as usize - ptr as usize }, 18usize, @@ -1054,10 +1020,7 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_segs) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).nb_segs) as usize - ptr as usize }, 22usize, concat!( "Offset of field: ", @@ -1067,10 +1030,7 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).port) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).port) as usize - ptr as usize }, 23usize, concat!( "Offset of field: ", @@ -1081,7 +1041,6 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).ol_flags) as usize - ptr as usize }, 24usize, @@ -1094,7 +1053,6 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).rx_descriptor_fields1) as usize - ptr as usize }, @@ -1107,10 +1065,7 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).pkt_len) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).pkt_len) as usize - ptr as usize }, 36usize, concat!( "Offset of field: ", @@ -1121,7 +1076,6 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).data_len) as usize - ptr as usize }, 40usize, @@ -1134,7 +1088,6 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).vlan_tci) as usize - ptr as usize }, 42usize, @@ -1146,10 +1099,7 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).hash) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).hash) as usize - ptr as usize }, 44usize, concat!( "Offset of field: ", @@ -1159,10 +1109,7 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).seqn) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).seqn) as usize - ptr as usize }, 52usize, concat!( "Offset of field: ", @@ -1173,7 +1120,6 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).vlan_tci_outer) as usize - ptr as usize }, 56usize, @@ -1186,7 +1132,6 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).cacheline1) as usize - ptr as usize }, 64usize, @@ -1198,10 +1143,7 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).pool) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).pool) as usize - ptr as usize }, 72usize, concat!( "Offset of field: ", @@ -1211,10 +1153,7 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize }, 80usize, concat!( "Offset of field: ", @@ -1225,7 +1164,6 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).priv_size) as usize - ptr as usize }, 96usize, @@ -1238,7 +1176,6 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).timesync) as usize - ptr as usize }, 98usize, diff --git a/tests/expectations/tests/layout_mbuf_1_0.rs b/tests/expectations/tests/layout_mbuf_1_0.rs index 353a576681..90f7ed09b2 100644 --- a/tests/expectations/tests/layout_mbuf_1_0.rs +++ b/tests/expectations/tests/layout_mbuf_1_0.rs @@ -151,6 +151,7 @@ pub struct rte_atomic16_t { fn bindgen_test_layout_rte_atomic16_t() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 2usize, @@ -162,10 +163,7 @@ fn bindgen_test_layout_rte_atomic16_t() { concat!("Alignment of ", stringify!(rte_atomic16_t)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).cnt) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).cnt) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -246,6 +244,7 @@ pub struct rte_mbuf__bindgen_ty_1 { fn bindgen_test_layout_rte_mbuf__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 2usize, @@ -258,7 +257,6 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_1() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).refcnt_atomic) as usize - ptr as usize }, 0usize, @@ -270,10 +268,7 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).refcnt) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).refcnt) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -470,6 +465,7 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { fn bindgen_test_layout_rte_mbuf__bindgen_ty_2() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -482,7 +478,6 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_2() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).packet_type) as usize - ptr as usize }, 0usize, @@ -539,10 +534,11 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindg const UNINIT: ::std::mem::MaybeUninit< rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1, > = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq ! (:: std :: mem :: size_of :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > () , 4usize , concat ! ("Size of: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1))); assert_eq ! (:: std :: mem :: align_of :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > () , 2usize , concat ! ("Alignment of " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1))); - assert_eq ! (unsafe { let ptr = UNINIT . as_ptr () ; :: std :: ptr :: addr_of ! ((* ptr) . hash) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (hash))); - assert_eq ! (unsafe { let ptr = UNINIT . as_ptr () ; :: std :: ptr :: addr_of ! ((* ptr) . id) as usize - ptr as usize } , 2usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (id))); + assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . hash) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (hash))); + assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . id) as usize - ptr as usize } , 2usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (id))); } impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 @@ -556,6 +552,7 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit< rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1, > = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::( ), @@ -576,10 +573,7 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).lo) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).lo) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -599,6 +593,7 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit< rte_mbuf__bindgen_ty_3__bindgen_ty_1, > = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -616,10 +611,7 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).hi) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).hi) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -645,6 +637,7 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_2() { const UNINIT: ::std::mem::MaybeUninit< rte_mbuf__bindgen_ty_3__bindgen_ty_2, > = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -662,10 +655,7 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_2() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).lo) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).lo) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -675,10 +665,7 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_2() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).hi) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).hi) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -697,6 +684,7 @@ impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_2 { fn bindgen_test_layout_rte_mbuf__bindgen_ty_3() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -708,10 +696,7 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3() { concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_3)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).rss) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).rss) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -721,10 +706,7 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).fdir) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).fdir) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -734,10 +716,7 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).sched) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).sched) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -747,10 +726,7 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).usr) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).usr) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -778,6 +754,7 @@ pub struct rte_mbuf__bindgen_ty_4 { fn bindgen_test_layout_rte_mbuf__bindgen_ty_4() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -790,7 +767,6 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_4() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).userdata) as usize - ptr as usize }, 0usize, @@ -802,10 +778,7 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_4() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).udata64) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).udata64) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -983,6 +956,7 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { fn bindgen_test_layout_rte_mbuf__bindgen_ty_5() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -995,7 +969,6 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_5() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).tx_offload) as usize - ptr as usize }, 0usize, @@ -1016,6 +989,7 @@ impl Clone for rte_mbuf__bindgen_ty_5 { fn bindgen_test_layout_rte_mbuf() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 128usize, @@ -1023,7 +997,6 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).cacheline0) as usize - ptr as usize }, 0usize, @@ -1036,7 +1009,6 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).buf_addr) as usize - ptr as usize }, 0usize, @@ -1049,7 +1021,6 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).buf_physaddr) as usize - ptr as usize }, 8usize, @@ -1061,10 +1032,7 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).buf_len) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).buf_len) as usize - ptr as usize }, 16usize, concat!( "Offset of field: ", @@ -1075,7 +1043,6 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).rearm_data) as usize - ptr as usize }, 18usize, @@ -1088,7 +1055,6 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).data_off) as usize - ptr as usize }, 18usize, @@ -1100,10 +1066,7 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).nb_segs) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).nb_segs) as usize - ptr as usize }, 22usize, concat!( "Offset of field: ", @@ -1113,10 +1076,7 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).port) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).port) as usize - ptr as usize }, 23usize, concat!( "Offset of field: ", @@ -1127,7 +1087,6 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).ol_flags) as usize - ptr as usize }, 24usize, @@ -1140,7 +1099,6 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).rx_descriptor_fields1) as usize - ptr as usize }, @@ -1153,10 +1111,7 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).pkt_len) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).pkt_len) as usize - ptr as usize }, 36usize, concat!( "Offset of field: ", @@ -1167,7 +1122,6 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).data_len) as usize - ptr as usize }, 40usize, @@ -1180,7 +1134,6 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).vlan_tci) as usize - ptr as usize }, 42usize, @@ -1192,10 +1145,7 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).hash) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).hash) as usize - ptr as usize }, 44usize, concat!( "Offset of field: ", @@ -1205,10 +1155,7 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).seqn) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).seqn) as usize - ptr as usize }, 52usize, concat!( "Offset of field: ", @@ -1219,7 +1166,6 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).vlan_tci_outer) as usize - ptr as usize }, 56usize, @@ -1232,7 +1178,6 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).cacheline1) as usize - ptr as usize }, 64usize, @@ -1244,10 +1189,7 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).pool) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).pool) as usize - ptr as usize }, 72usize, concat!( "Offset of field: ", @@ -1257,10 +1199,7 @@ fn bindgen_test_layout_rte_mbuf() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize }, 80usize, concat!( "Offset of field: ", @@ -1271,7 +1210,6 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).priv_size) as usize - ptr as usize }, 96usize, @@ -1284,7 +1222,6 @@ fn bindgen_test_layout_rte_mbuf() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).timesync) as usize - ptr as usize }, 98usize, diff --git a/tests/expectations/tests/libclang-5/call-conv-field.rs b/tests/expectations/tests/libclang-5/call-conv-field.rs index eb86ec2f43..62b5ace2b0 100644 --- a/tests/expectations/tests/libclang-5/call-conv-field.rs +++ b/tests/expectations/tests/libclang-5/call-conv-field.rs @@ -20,6 +20,7 @@ pub struct JNINativeInterface_ { fn bindgen_test_layout_JNINativeInterface_() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -32,7 +33,6 @@ fn bindgen_test_layout_JNINativeInterface_() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).GetVersion) as usize - ptr as usize }, 0usize, @@ -44,10 +44,7 @@ fn bindgen_test_layout_JNINativeInterface_() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).__hack) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).__hack) as usize - ptr as usize }, 8usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/libclang-5/type_alias_template_specialized.rs b/tests/expectations/tests/libclang-5/type_alias_template_specialized.rs index 3e6550936c..19f8881db6 100644 --- a/tests/expectations/tests/libclang-5/type_alias_template_specialized.rs +++ b/tests/expectations/tests/libclang-5/type_alias_template_specialized.rs @@ -14,6 +14,7 @@ pub struct Rooted { fn bindgen_test_layout_Rooted() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -25,10 +26,7 @@ fn bindgen_test_layout_Rooted() { concat!("Alignment of ", stringify!(Rooted)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/libclang-9/call-conv-field.rs b/tests/expectations/tests/libclang-9/call-conv-field.rs index eb86ec2f43..62b5ace2b0 100644 --- a/tests/expectations/tests/libclang-9/call-conv-field.rs +++ b/tests/expectations/tests/libclang-9/call-conv-field.rs @@ -20,6 +20,7 @@ pub struct JNINativeInterface_ { fn bindgen_test_layout_JNINativeInterface_() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -32,7 +33,6 @@ fn bindgen_test_layout_JNINativeInterface_() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).GetVersion) as usize - ptr as usize }, 0usize, @@ -44,10 +44,7 @@ fn bindgen_test_layout_JNINativeInterface_() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).__hack) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).__hack) as usize - ptr as usize }, 8usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/libclang-9/class.rs b/tests/expectations/tests/libclang-9/class.rs index 81151d0f90..0d64a9ffc8 100644 --- a/tests/expectations/tests/libclang-9/class.rs +++ b/tests/expectations/tests/libclang-9/class.rs @@ -45,6 +45,7 @@ pub struct C { 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, @@ -56,16 +57,12 @@ fn bindgen_test_layout_C() { concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(a)) ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, 4usize, @@ -96,6 +93,7 @@ pub struct C_with_zero_length_array { 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, @@ -107,10 +105,7 @@ fn bindgen_test_layout_C_with_zero_length_array() { concat!("Alignment of ", stringify!(C_with_zero_length_array)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -121,7 +116,6 @@ fn bindgen_test_layout_C_with_zero_length_array() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, 4usize, @@ -134,7 +128,6 @@ fn bindgen_test_layout_C_with_zero_length_array() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize }, @@ -166,6 +159,7 @@ pub struct C_with_zero_length_array_2 { 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, @@ -177,10 +171,7 @@ fn bindgen_test_layout_C_with_zero_length_array_2() { concat!("Alignment of ", stringify!(C_with_zero_length_array_2)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -191,7 +182,6 @@ fn bindgen_test_layout_C_with_zero_length_array_2() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize }, @@ -214,6 +204,7 @@ pub struct C_with_incomplete_array { 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, @@ -225,10 +216,7 @@ fn bindgen_test_layout_C_with_incomplete_array() { concat!("Alignment of ", stringify!(C_with_incomplete_array)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -239,7 +227,6 @@ fn bindgen_test_layout_C_with_incomplete_array() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, 4usize, @@ -252,7 +239,6 @@ fn bindgen_test_layout_C_with_incomplete_array() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, @@ -284,6 +270,7 @@ pub struct C_with_incomplete_array_2 { 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, @@ -295,10 +282,7 @@ fn bindgen_test_layout_C_with_incomplete_array_2() { concat!("Alignment of ", stringify!(C_with_incomplete_array_2)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -309,7 +293,6 @@ fn bindgen_test_layout_C_with_incomplete_array_2() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, @@ -334,6 +317,7 @@ 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, @@ -351,10 +335,7 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -365,7 +346,6 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, 4usize, @@ -378,7 +358,6 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize }, @@ -392,7 +371,6 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, @@ -426,6 +404,7 @@ 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::( ), @@ -445,10 +424,7 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -459,7 +435,6 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize }, @@ -473,7 +448,6 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, @@ -495,6 +469,7 @@ pub struct WithDtor { 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, @@ -506,10 +481,7 @@ fn bindgen_test_layout_WithDtor() { concat!("Alignment of ", stringify!(WithDtor)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -528,6 +500,7 @@ pub struct IncompleteArrayNonCopiable { 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, @@ -540,7 +513,6 @@ fn bindgen_test_layout_IncompleteArrayNonCopiable() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).whatever) as usize - ptr as usize }, 0usize, @@ -553,7 +525,6 @@ fn bindgen_test_layout_IncompleteArrayNonCopiable() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, @@ -585,6 +556,7 @@ pub union Union { 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, @@ -596,18 +568,12 @@ fn bindgen_test_layout_Union() { concat!("Alignment of ", stringify!(Union)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Union), "::", stringify!(d)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Union), "::", stringify!(i)) ); @@ -630,6 +596,7 @@ pub struct WithUnion { 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, @@ -641,10 +608,7 @@ fn bindgen_test_layout_WithUnion() { concat!("Alignment of ", stringify!(WithUnion)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/libclang-9/class_1_0.rs b/tests/expectations/tests/libclang-9/class_1_0.rs index 31c33ccc82..e8c2e07798 100644 --- a/tests/expectations/tests/libclang-9/class_1_0.rs +++ b/tests/expectations/tests/libclang-9/class_1_0.rs @@ -88,6 +88,7 @@ pub struct C { 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, @@ -99,16 +100,12 @@ fn bindgen_test_layout_C() { concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(a)) ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, 4usize, @@ -149,6 +146,7 @@ pub struct C_with_zero_length_array { 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, @@ -160,10 +158,7 @@ fn bindgen_test_layout_C_with_zero_length_array() { concat!("Alignment of ", stringify!(C_with_zero_length_array)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -174,7 +169,6 @@ fn bindgen_test_layout_C_with_zero_length_array() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, 4usize, @@ -187,7 +181,6 @@ fn bindgen_test_layout_C_with_zero_length_array() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize }, @@ -219,6 +212,7 @@ pub struct C_with_zero_length_array_2 { 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, @@ -230,10 +224,7 @@ fn bindgen_test_layout_C_with_zero_length_array_2() { concat!("Alignment of ", stringify!(C_with_zero_length_array_2)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -244,7 +235,6 @@ fn bindgen_test_layout_C_with_zero_length_array_2() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize }, @@ -267,6 +257,7 @@ pub struct C_with_incomplete_array { 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, @@ -278,10 +269,7 @@ fn bindgen_test_layout_C_with_incomplete_array() { concat!("Alignment of ", stringify!(C_with_incomplete_array)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -292,7 +280,6 @@ fn bindgen_test_layout_C_with_incomplete_array() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, 4usize, @@ -305,7 +292,6 @@ fn bindgen_test_layout_C_with_incomplete_array() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, @@ -337,6 +323,7 @@ pub struct C_with_incomplete_array_2 { 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, @@ -348,10 +335,7 @@ fn bindgen_test_layout_C_with_incomplete_array_2() { concat!("Alignment of ", stringify!(C_with_incomplete_array_2)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -362,7 +346,6 @@ fn bindgen_test_layout_C_with_incomplete_array_2() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, @@ -387,6 +370,7 @@ 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, @@ -404,10 +388,7 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -418,7 +399,6 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, 4usize, @@ -431,7 +411,6 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize }, @@ -445,7 +424,6 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, @@ -479,6 +457,7 @@ 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::( ), @@ -498,10 +477,7 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -512,7 +488,6 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize }, @@ -526,7 +501,6 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, @@ -548,6 +522,7 @@ pub struct WithDtor { 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, @@ -559,10 +534,7 @@ fn bindgen_test_layout_WithDtor() { concat!("Alignment of ", stringify!(WithDtor)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -581,6 +553,7 @@ pub struct IncompleteArrayNonCopiable { 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, @@ -593,7 +566,6 @@ fn bindgen_test_layout_IncompleteArrayNonCopiable() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).whatever) as usize - ptr as usize }, 0usize, @@ -606,7 +578,6 @@ fn bindgen_test_layout_IncompleteArrayNonCopiable() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, @@ -639,6 +610,7 @@ pub struct Union { 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, @@ -650,18 +622,12 @@ fn bindgen_test_layout_Union() { concat!("Alignment of ", stringify!(Union)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Union), "::", stringify!(d)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Union), "::", stringify!(i)) ); @@ -680,6 +646,7 @@ pub struct WithUnion { 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, @@ -691,10 +658,7 @@ fn bindgen_test_layout_WithUnion() { concat!("Alignment of ", stringify!(WithUnion)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs b/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs index 0986449b7a..2af22cc4c9 100644 --- a/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs +++ b/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs @@ -45,6 +45,7 @@ pub struct test { fn bindgen_test_layout_test() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -56,16 +57,12 @@ fn bindgen_test_layout_test() { concat!("Alignment of ", stringify!(test)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(test), "::", stringify!(a)) ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize }, @@ -88,6 +85,7 @@ pub struct test2 { fn bindgen_test_layout_test2() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -99,16 +97,12 @@ fn bindgen_test_layout_test2() { concat!("Alignment of ", stringify!(test2)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(test2), "::", stringify!(a)) ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, @@ -132,6 +126,7 @@ pub struct test3 { fn bindgen_test_layout_test3() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -143,16 +138,12 @@ fn bindgen_test_layout_test3() { concat!("Alignment of ", stringify!(test3)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(test3), "::", stringify!(a)) ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize }, @@ -166,7 +157,6 @@ fn bindgen_test_layout_test3() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, diff --git a/tests/expectations/tests/libclang-9/incomplete-array-padding.rs b/tests/expectations/tests/libclang-9/incomplete-array-padding.rs index 5f33deeb8c..1de963bf0f 100644 --- a/tests/expectations/tests/libclang-9/incomplete-array-padding.rs +++ b/tests/expectations/tests/libclang-9/incomplete-array-padding.rs @@ -132,6 +132,7 @@ pub struct foo { 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::(), 8usize, @@ -143,10 +144,7 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 8usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) ); diff --git a/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs b/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs index aafd2d653f..ab402cfb7c 100644 --- a/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs +++ b/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs @@ -52,6 +52,7 @@ pub struct rte_ring_prod { fn bindgen_test_layout_rte_ring_prod() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -64,7 +65,6 @@ fn bindgen_test_layout_rte_ring_prod() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).watermark) as usize - ptr as usize }, 0usize, @@ -85,6 +85,7 @@ pub struct rte_ring_cons { fn bindgen_test_layout_rte_ring_cons() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -97,7 +98,6 @@ fn bindgen_test_layout_rte_ring_cons() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).sc_dequeue) as usize - ptr as usize }, 0usize, @@ -113,6 +113,7 @@ fn bindgen_test_layout_rte_ring_cons() { fn bindgen_test_layout_rte_ring() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -124,10 +125,7 @@ fn bindgen_test_layout_rte_ring() { concat!("Alignment of ", stringify!(rte_ring)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).memzone) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).memzone) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -137,10 +135,7 @@ fn bindgen_test_layout_rte_ring() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).prod) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).prod) as usize - ptr as usize }, 8usize, concat!( "Offset of field: ", @@ -150,10 +145,7 @@ fn bindgen_test_layout_rte_ring() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).cons) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).cons) as usize - ptr as usize }, 12usize, concat!( "Offset of field: ", @@ -163,10 +155,7 @@ fn bindgen_test_layout_rte_ring() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).ring) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).ring) as usize - ptr as usize }, 16usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/libclang-9/layout_align.rs b/tests/expectations/tests/libclang-9/layout_align.rs index 1828c17635..f6a32704f1 100644 --- a/tests/expectations/tests/libclang-9/layout_align.rs +++ b/tests/expectations/tests/libclang-9/layout_align.rs @@ -139,6 +139,7 @@ pub struct rte_kni_fifo { fn bindgen_test_layout_rte_kni_fifo() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -150,10 +151,7 @@ fn bindgen_test_layout_rte_kni_fifo() { concat!("Alignment of ", stringify!(rte_kni_fifo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).write) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).write) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -163,10 +161,7 @@ fn bindgen_test_layout_rte_kni_fifo() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).read) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).read) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -176,10 +171,7 @@ fn bindgen_test_layout_rte_kni_fifo() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize }, 8usize, concat!( "Offset of field: ", @@ -190,7 +182,6 @@ fn bindgen_test_layout_rte_kni_fifo() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).elem_size) as usize - ptr as usize }, 12usize, @@ -202,10 +193,7 @@ fn bindgen_test_layout_rte_kni_fifo() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).buffer) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).buffer) as usize - ptr as usize }, 16usize, concat!( "Offset of field: ", @@ -238,6 +226,7 @@ pub struct rte_eth_link { fn bindgen_test_layout_rte_eth_link() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -250,7 +239,6 @@ fn bindgen_test_layout_rte_eth_link() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).link_speed) as usize - ptr as usize }, 0usize, diff --git a/tests/expectations/tests/libclang-9/type_alias_template_specialized.rs b/tests/expectations/tests/libclang-9/type_alias_template_specialized.rs index 3e6550936c..19f8881db6 100644 --- a/tests/expectations/tests/libclang-9/type_alias_template_specialized.rs +++ b/tests/expectations/tests/libclang-9/type_alias_template_specialized.rs @@ -14,6 +14,7 @@ pub struct Rooted { fn bindgen_test_layout_Rooted() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -25,10 +26,7 @@ fn bindgen_test_layout_Rooted() { concat!("Alignment of ", stringify!(Rooted)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/libclang-9/zero-sized-array.rs b/tests/expectations/tests/libclang-9/zero-sized-array.rs index f67ac2b383..3066fac40a 100644 --- a/tests/expectations/tests/libclang-9/zero-sized-array.rs +++ b/tests/expectations/tests/libclang-9/zero-sized-array.rs @@ -45,6 +45,7 @@ pub struct ZeroSizedArray { fn bindgen_test_layout_ZeroSizedArray() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 0usize, @@ -56,10 +57,7 @@ fn bindgen_test_layout_ZeroSizedArray() { concat!("Alignment of ", stringify!(ZeroSizedArray)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -79,6 +77,7 @@ pub struct ContainsZeroSizedArray { fn bindgen_test_layout_ContainsZeroSizedArray() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 0usize, @@ -90,10 +89,7 @@ fn bindgen_test_layout_ContainsZeroSizedArray() { concat!("Alignment of ", stringify!(ContainsZeroSizedArray)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).zsa) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).zsa) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -133,6 +129,7 @@ pub struct DynamicallySizedArray { fn bindgen_test_layout_DynamicallySizedArray() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 0usize, @@ -144,10 +141,7 @@ fn bindgen_test_layout_DynamicallySizedArray() { concat!("Alignment of ", stringify!(DynamicallySizedArray)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -167,6 +161,7 @@ pub struct ContainsDynamicallySizedArray { fn bindgen_test_layout_ContainsDynamicallySizedArray() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 0usize, @@ -178,10 +173,7 @@ fn bindgen_test_layout_ContainsDynamicallySizedArray() { concat!("Alignment of ", stringify!(ContainsDynamicallySizedArray)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).dsa) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).dsa) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/long_double.rs b/tests/expectations/tests/long_double.rs index 54ed294868..2c3b6c937f 100644 --- a/tests/expectations/tests/long_double.rs +++ b/tests/expectations/tests/long_double.rs @@ -15,6 +15,7 @@ pub struct foo { 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, @@ -26,10 +27,7 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/msvc-no-usr.rs b/tests/expectations/tests/msvc-no-usr.rs index e0ffc04320..285670ed68 100644 --- a/tests/expectations/tests/msvc-no-usr.rs +++ b/tests/expectations/tests/msvc-no-usr.rs @@ -15,6 +15,7 @@ pub struct A { 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, @@ -26,10 +27,7 @@ fn bindgen_test_layout_A() { concat!("Alignment of ", stringify!(A)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(foo)) ); diff --git a/tests/expectations/tests/mutable.rs b/tests/expectations/tests/mutable.rs index cca9927ee4..94c703266a 100644 --- a/tests/expectations/tests/mutable.rs +++ b/tests/expectations/tests/mutable.rs @@ -15,6 +15,7 @@ pub struct C { 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::(), 8usize, @@ -27,7 +28,6 @@ fn bindgen_test_layout_C() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize }, 0usize, @@ -39,10 +39,7 @@ fn bindgen_test_layout_C() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).m_other) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).m_other) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -61,6 +58,7 @@ pub struct NonCopiable { fn bindgen_test_layout_NonCopiable() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -73,7 +71,6 @@ fn bindgen_test_layout_NonCopiable() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize }, 0usize, @@ -95,6 +92,7 @@ fn bindgen_test_layout_NonCopiableWithNonCopiableMutableMember() { const UNINIT: ::std::mem::MaybeUninit< NonCopiableWithNonCopiableMutableMember, > = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -113,7 +111,6 @@ fn bindgen_test_layout_NonCopiableWithNonCopiableMutableMember() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize }, 0usize, diff --git a/tests/expectations/tests/namespace.rs b/tests/expectations/tests/namespace.rs index 555629d431..49c8a7ef48 100644 --- a/tests/expectations/tests/namespace.rs +++ b/tests/expectations/tests/namespace.rs @@ -35,6 +35,7 @@ pub mod root { 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::(), 4usize, @@ -47,7 +48,6 @@ pub mod root { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, diff --git a/tests/expectations/tests/nested.rs b/tests/expectations/tests/nested.rs index 82a483aee2..415a740561 100644 --- a/tests/expectations/tests/nested.rs +++ b/tests/expectations/tests/nested.rs @@ -14,6 +14,7 @@ pub struct Calc { fn bindgen_test_layout_Calc() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -25,10 +26,7 @@ fn bindgen_test_layout_Calc() { concat!("Alignment of ", stringify!(Calc)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).w) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).w) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Calc), "::", stringify!(w)) ); @@ -66,6 +64,7 @@ fn bindgen_test_layout_Test_Size_Dimension() { fn bindgen_test_layout_Test_Size() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -77,10 +76,7 @@ fn bindgen_test_layout_Test_Size() { concat!("Alignment of ", stringify!(Test_Size)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mWidth) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mWidth) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -90,10 +86,7 @@ fn bindgen_test_layout_Test_Size() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mHeight) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mHeight) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/nested_within_namespace.rs b/tests/expectations/tests/nested_within_namespace.rs index d4874d41b6..629c449a61 100644 --- a/tests/expectations/tests/nested_within_namespace.rs +++ b/tests/expectations/tests/nested_within_namespace.rs @@ -26,6 +26,7 @@ pub mod root { fn bindgen_test_layout_Bar_Baz() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -38,7 +39,6 @@ pub mod root { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, 0usize, @@ -54,6 +54,7 @@ pub mod root { 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, @@ -66,7 +67,6 @@ pub mod root { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, 0usize, @@ -87,6 +87,7 @@ pub mod root { 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::(), 4usize, @@ -99,7 +100,6 @@ pub mod root { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, 0usize, diff --git a/tests/expectations/tests/no-comments.rs b/tests/expectations/tests/no-comments.rs index 2f22f1cfa4..a375d8ea69 100644 --- a/tests/expectations/tests/no-comments.rs +++ b/tests/expectations/tests/no-comments.rs @@ -14,6 +14,7 @@ pub struct Foo { 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::(), 4usize, @@ -25,10 +26,7 @@ fn bindgen_test_layout_Foo() { concat!("Alignment of ", stringify!(Foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).s) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).s) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(s)) ); diff --git a/tests/expectations/tests/no-derive-debug.rs b/tests/expectations/tests/no-derive-debug.rs index ffdc2c2f67..c7a6d1843b 100644 --- a/tests/expectations/tests/no-derive-debug.rs +++ b/tests/expectations/tests/no-derive-debug.rs @@ -23,6 +23,7 @@ pub struct bar { 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::(), 8usize, @@ -34,18 +35,12 @@ fn bindgen_test_layout_bar() { concat!("Alignment of ", stringify!(bar)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(bar), "::", stringify!(foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, 4usize, concat!("Offset of field: ", stringify!(bar), "::", stringify!(baz)) ); diff --git a/tests/expectations/tests/no-derive-default.rs b/tests/expectations/tests/no-derive-default.rs index 7e21f8ab00..46b2cb4ee7 100644 --- a/tests/expectations/tests/no-derive-default.rs +++ b/tests/expectations/tests/no-derive-default.rs @@ -23,6 +23,7 @@ pub struct bar { 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::(), 8usize, @@ -34,18 +35,12 @@ fn bindgen_test_layout_bar() { concat!("Alignment of ", stringify!(bar)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(bar), "::", stringify!(foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, 4usize, concat!("Offset of field: ", stringify!(bar), "::", stringify!(baz)) ); diff --git a/tests/expectations/tests/no-hash-allowlisted.rs b/tests/expectations/tests/no-hash-allowlisted.rs index b92ae996be..549b72b53b 100644 --- a/tests/expectations/tests/no-hash-allowlisted.rs +++ b/tests/expectations/tests/no-hash-allowlisted.rs @@ -14,6 +14,7 @@ pub struct NoHash { fn bindgen_test_layout_NoHash() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -25,10 +26,7 @@ fn bindgen_test_layout_NoHash() { concat!("Alignment of ", stringify!(NoHash)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(NoHash), "::", stringify!(i)) ); diff --git a/tests/expectations/tests/no-partialeq-allowlisted.rs b/tests/expectations/tests/no-partialeq-allowlisted.rs index 16fae74146..c7895fe64b 100644 --- a/tests/expectations/tests/no-partialeq-allowlisted.rs +++ b/tests/expectations/tests/no-partialeq-allowlisted.rs @@ -14,6 +14,7 @@ pub struct NoPartialEq { fn bindgen_test_layout_NoPartialEq() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -25,10 +26,7 @@ fn bindgen_test_layout_NoPartialEq() { concat!("Alignment of ", stringify!(NoPartialEq)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/no-recursive-allowlisting.rs b/tests/expectations/tests/no-recursive-allowlisting.rs index 2246fbdacd..6f1e19ba95 100644 --- a/tests/expectations/tests/no-recursive-allowlisting.rs +++ b/tests/expectations/tests/no-recursive-allowlisting.rs @@ -16,6 +16,7 @@ pub struct Foo { 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::(), 8usize, @@ -27,10 +28,7 @@ fn bindgen_test_layout_Foo() { concat!("Alignment of ", stringify!(Foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(baz)) ); diff --git a/tests/expectations/tests/no-std.rs b/tests/expectations/tests/no-std.rs index ef19aa3fa7..457242c2ba 100644 --- a/tests/expectations/tests/no-std.rs +++ b/tests/expectations/tests/no-std.rs @@ -21,6 +21,7 @@ pub struct foo { fn bindgen_test_layout_foo() { const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::core::mem::size_of::(), 16usize, @@ -32,26 +33,17 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::core::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::core::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::core::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::core::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 4usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, + unsafe { ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 8usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/no_copy_allowlisted.rs b/tests/expectations/tests/no_copy_allowlisted.rs index a0d89a310b..1c46de75f1 100644 --- a/tests/expectations/tests/no_copy_allowlisted.rs +++ b/tests/expectations/tests/no_copy_allowlisted.rs @@ -14,6 +14,7 @@ pub struct NoCopy { fn bindgen_test_layout_NoCopy() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -25,10 +26,7 @@ fn bindgen_test_layout_NoCopy() { concat!("Alignment of ", stringify!(NoCopy)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(NoCopy), "::", stringify!(i)) ); diff --git a/tests/expectations/tests/no_debug_allowlisted.rs b/tests/expectations/tests/no_debug_allowlisted.rs index b89dadd6da..859dad8cb3 100644 --- a/tests/expectations/tests/no_debug_allowlisted.rs +++ b/tests/expectations/tests/no_debug_allowlisted.rs @@ -14,6 +14,7 @@ pub struct NoDebug { 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::(), 4usize, @@ -25,10 +26,7 @@ fn bindgen_test_layout_NoDebug() { concat!("Alignment of ", stringify!(NoDebug)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/no_default_allowlisted.rs b/tests/expectations/tests/no_default_allowlisted.rs index 9480136265..c4deceb4b0 100644 --- a/tests/expectations/tests/no_default_allowlisted.rs +++ b/tests/expectations/tests/no_default_allowlisted.rs @@ -14,6 +14,7 @@ pub struct NoDefault { fn bindgen_test_layout_NoDefault() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -25,10 +26,7 @@ fn bindgen_test_layout_NoDefault() { concat!("Alignment of ", stringify!(NoDefault)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/non-type-params.rs b/tests/expectations/tests/non-type-params.rs index 84388828ee..2b38e21667 100644 --- a/tests/expectations/tests/non-type-params.rs +++ b/tests/expectations/tests/non-type-params.rs @@ -18,6 +18,7 @@ pub struct UsesArray { fn bindgen_test_layout_UsesArray() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 40usize, @@ -30,7 +31,6 @@ fn bindgen_test_layout_UsesArray() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).array_char_16) as usize - ptr as usize }, 0usize, @@ -43,7 +43,6 @@ fn bindgen_test_layout_UsesArray() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).array_bool_8) as usize - ptr as usize }, 16usize, @@ -56,7 +55,6 @@ fn bindgen_test_layout_UsesArray() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).array_int_4) as usize - ptr as usize }, 24usize, diff --git a/tests/expectations/tests/objc_interface_type.rs b/tests/expectations/tests/objc_interface_type.rs index 1795eaad85..423ba910d4 100644 --- a/tests/expectations/tests/objc_interface_type.rs +++ b/tests/expectations/tests/objc_interface_type.rs @@ -35,6 +35,7 @@ pub struct FooStruct { fn bindgen_test_layout_FooStruct() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -46,10 +47,7 @@ fn bindgen_test_layout_FooStruct() { concat!("Alignment of ", stringify!(FooStruct)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/opaque-template-inst-member-2.rs b/tests/expectations/tests/opaque-template-inst-member-2.rs index b0380e64c3..c28d935664 100644 --- a/tests/expectations/tests/opaque-template-inst-member-2.rs +++ b/tests/expectations/tests/opaque-template-inst-member-2.rs @@ -23,6 +23,7 @@ pub struct ContainsOpaqueTemplate { 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::(), 8usize, @@ -34,10 +35,7 @@ fn bindgen_test_layout_ContainsOpaqueTemplate() { concat!("Alignment of ", stringify!(ContainsOpaqueTemplate)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBlah) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mBlah) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -47,10 +45,7 @@ fn bindgen_test_layout_ContainsOpaqueTemplate() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBaz) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mBaz) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -71,6 +66,7 @@ pub struct InheritsOpaqueTemplate { 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::(), 16usize, @@ -82,10 +78,7 @@ fn bindgen_test_layout_InheritsOpaqueTemplate() { concat!("Alignment of ", stringify!(InheritsOpaqueTemplate)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).wow) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).wow) as usize - ptr as usize }, 8usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/opaque-template-inst-member.rs b/tests/expectations/tests/opaque-template-inst-member.rs index f7f405dcdf..4ba85f660f 100644 --- a/tests/expectations/tests/opaque-template-inst-member.rs +++ b/tests/expectations/tests/opaque-template-inst-member.rs @@ -21,6 +21,7 @@ pub struct ContainsOpaqueTemplate { 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, @@ -32,10 +33,7 @@ fn bindgen_test_layout_ContainsOpaqueTemplate() { concat!("Alignment of ", stringify!(ContainsOpaqueTemplate)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBlah) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mBlah) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -45,10 +43,7 @@ fn bindgen_test_layout_ContainsOpaqueTemplate() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBaz) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mBaz) as usize - ptr as usize }, 404usize, concat!( "Offset of field: ", @@ -83,6 +78,7 @@ pub struct InheritsOpaqueTemplate { 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, @@ -94,10 +90,7 @@ fn bindgen_test_layout_InheritsOpaqueTemplate() { concat!("Alignment of ", stringify!(InheritsOpaqueTemplate)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).wow) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).wow) as usize - ptr as usize }, 408usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/opaque-template-instantiation-namespaced.rs b/tests/expectations/tests/opaque-template-instantiation-namespaced.rs index cbb04872c3..3575216cb0 100644 --- a/tests/expectations/tests/opaque-template-instantiation-namespaced.rs +++ b/tests/expectations/tests/opaque-template-instantiation-namespaced.rs @@ -37,6 +37,7 @@ pub mod root { 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::(), 1usize, @@ -49,7 +50,6 @@ pub mod root { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, 0usize, @@ -70,6 +70,7 @@ pub mod root { 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, @@ -82,7 +83,6 @@ pub mod root { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, 0usize, @@ -103,6 +103,7 @@ pub mod root { fn bindgen_test_layout_ContainsInstantiation() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -115,7 +116,6 @@ pub mod root { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).not_opaque) as usize - ptr as usize }, @@ -146,6 +146,7 @@ pub mod root { fn bindgen_test_layout_ContainsOpaqueInstantiation() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -161,7 +162,6 @@ pub mod root { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).opaque) as usize - ptr as usize }, 0usize, diff --git a/tests/expectations/tests/opaque-template-instantiation.rs b/tests/expectations/tests/opaque-template-instantiation.rs index 53082631c8..910c616fd8 100644 --- a/tests/expectations/tests/opaque-template-instantiation.rs +++ b/tests/expectations/tests/opaque-template-instantiation.rs @@ -29,6 +29,7 @@ pub struct ContainsInstantiation { fn bindgen_test_layout_ContainsInstantiation() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -41,7 +42,6 @@ fn bindgen_test_layout_ContainsInstantiation() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).not_opaque) as usize - ptr as usize }, 0usize, @@ -71,6 +71,7 @@ pub struct ContainsOpaqueInstantiation { fn bindgen_test_layout_ContainsOpaqueInstantiation() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -82,10 +83,7 @@ fn bindgen_test_layout_ContainsOpaqueInstantiation() { concat!("Alignment of ", stringify!(ContainsOpaqueInstantiation)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).opaque) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).opaque) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/opaque_in_struct.rs b/tests/expectations/tests/opaque_in_struct.rs index 9caecc1fb8..0d13b12106 100644 --- a/tests/expectations/tests/opaque_in_struct.rs +++ b/tests/expectations/tests/opaque_in_struct.rs @@ -34,6 +34,7 @@ pub struct container { fn bindgen_test_layout_container() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -46,7 +47,6 @@ fn bindgen_test_layout_container() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).contained) as usize - ptr as usize }, 0usize, diff --git a/tests/expectations/tests/opaque_pointer.rs b/tests/expectations/tests/opaque_pointer.rs index 57bb2a9b96..13b8cc366c 100644 --- a/tests/expectations/tests/opaque_pointer.rs +++ b/tests/expectations/tests/opaque_pointer.rs @@ -42,6 +42,7 @@ pub struct WithOpaquePtr { fn bindgen_test_layout_WithOpaquePtr() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -54,7 +55,6 @@ fn bindgen_test_layout_WithOpaquePtr() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).whatever) as usize - ptr as usize }, 0usize, @@ -66,10 +66,7 @@ fn bindgen_test_layout_WithOpaquePtr() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).other) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).other) as usize - ptr as usize }, 8usize, concat!( "Offset of field: ", @@ -79,10 +76,7 @@ fn bindgen_test_layout_WithOpaquePtr() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).t) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).t) as usize - ptr as usize }, 12usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/packed-n-with-padding.rs b/tests/expectations/tests/packed-n-with-padding.rs index 54414aebc9..b171b1da70 100644 --- a/tests/expectations/tests/packed-n-with-padding.rs +++ b/tests/expectations/tests/packed-n-with-padding.rs @@ -17,6 +17,7 @@ pub struct Packed { fn bindgen_test_layout_Packed() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 10usize, @@ -28,34 +29,22 @@ fn bindgen_test_layout_Packed() { concat!("Alignment of ", stringify!(Packed)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Packed), "::", stringify!(a)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 2usize, concat!("Offset of field: ", stringify!(Packed), "::", stringify!(b)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, 4usize, concat!("Offset of field: ", stringify!(Packed), "::", stringify!(c)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, 6usize, concat!("Offset of field: ", stringify!(Packed), "::", stringify!(d)) ); diff --git a/tests/expectations/tests/private.rs b/tests/expectations/tests/private.rs index b43f840f86..ab57d37f3b 100644 --- a/tests/expectations/tests/private.rs +++ b/tests/expectations/tests/private.rs @@ -16,6 +16,7 @@ pub struct HasPrivate { fn bindgen_test_layout_HasPrivate() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -28,7 +29,6 @@ fn bindgen_test_layout_HasPrivate() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mNotPrivate) as usize - ptr as usize }, 0usize, @@ -41,7 +41,6 @@ fn bindgen_test_layout_HasPrivate() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mIsPrivate) as usize - ptr as usize }, 4usize, @@ -64,6 +63,7 @@ pub struct VeryPrivate { fn bindgen_test_layout_VeryPrivate() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -76,7 +76,6 @@ fn bindgen_test_layout_VeryPrivate() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mIsPrivate) as usize - ptr as usize }, 0usize, @@ -89,7 +88,6 @@ fn bindgen_test_layout_VeryPrivate() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mIsAlsoPrivate) as usize - ptr as usize }, 4usize, @@ -113,6 +111,7 @@ pub struct ContradictPrivate { fn bindgen_test_layout_ContradictPrivate() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -125,7 +124,6 @@ fn bindgen_test_layout_ContradictPrivate() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mNotPrivate) as usize - ptr as usize }, 0usize, @@ -138,7 +136,6 @@ fn bindgen_test_layout_ContradictPrivate() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mIsPrivate) as usize - ptr as usize }, 4usize, diff --git a/tests/expectations/tests/private_fields.rs b/tests/expectations/tests/private_fields.rs index 137689cc45..8db332a5f3 100644 --- a/tests/expectations/tests/private_fields.rs +++ b/tests/expectations/tests/private_fields.rs @@ -101,6 +101,7 @@ pub struct PubPriv { fn bindgen_test_layout_PubPriv() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -112,10 +113,7 @@ fn bindgen_test_layout_PubPriv() { concat!("Alignment of ", stringify!(PubPriv)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -125,10 +123,7 @@ fn bindgen_test_layout_PubPriv() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -345,6 +340,7 @@ pub struct Base { 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::(), 4usize, @@ -356,10 +352,7 @@ fn bindgen_test_layout_Base() { concat!("Alignment of ", stringify!(Base)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -420,6 +413,7 @@ pub struct WithAnonStruct__bindgen_ty_1 { fn bindgen_test_layout_WithAnonStruct__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -431,10 +425,7 @@ fn bindgen_test_layout_WithAnonStruct__bindgen_ty_1() { concat!("Alignment of ", stringify!(WithAnonStruct__bindgen_ty_1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -453,6 +444,7 @@ pub struct WithAnonStruct__bindgen_ty_2 { fn bindgen_test_layout_WithAnonStruct__bindgen_ty_2() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -464,10 +456,7 @@ fn bindgen_test_layout_WithAnonStruct__bindgen_ty_2() { concat!("Alignment of ", stringify!(WithAnonStruct__bindgen_ty_2)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/reparented_replacement.rs b/tests/expectations/tests/reparented_replacement.rs index 1691554166..d9d13c1a9d 100644 --- a/tests/expectations/tests/reparented_replacement.rs +++ b/tests/expectations/tests/reparented_replacement.rs @@ -22,6 +22,7 @@ pub mod root { 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, @@ -34,7 +35,6 @@ pub mod root { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).bazz) as usize - ptr as usize }, 0usize, diff --git a/tests/expectations/tests/replace_use.rs b/tests/expectations/tests/replace_use.rs index 7ff5b6d80a..d4228e126e 100644 --- a/tests/expectations/tests/replace_use.rs +++ b/tests/expectations/tests/replace_use.rs @@ -20,6 +20,7 @@ pub struct Test { fn bindgen_test_layout_Test() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -31,10 +32,7 @@ fn bindgen_test_layout_Test() { concat!("Alignment of ", stringify!(Test)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(a)) ); diff --git a/tests/expectations/tests/repr-align.rs b/tests/expectations/tests/repr-align.rs index fd5c080aea..c6fee20dbc 100644 --- a/tests/expectations/tests/repr-align.rs +++ b/tests/expectations/tests/repr-align.rs @@ -17,6 +17,7 @@ pub struct a { 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, @@ -28,18 +29,12 @@ fn bindgen_test_layout_a() { concat!("Alignment of ", stringify!(a)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(a), "::", stringify!(b)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, 4usize, concat!("Offset of field: ", stringify!(a), "::", stringify!(c)) ); @@ -55,6 +50,7 @@ pub struct b { 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, @@ -66,18 +62,12 @@ fn bindgen_test_layout_b() { concat!("Alignment of ", stringify!(b)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(b), "::", stringify!(b)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, 4usize, concat!("Offset of field: ", stringify!(b), "::", stringify!(c)) ); diff --git a/tests/expectations/tests/same_struct_name_in_different_namespaces.rs b/tests/expectations/tests/same_struct_name_in_different_namespaces.rs index 30cfc67a51..8002476197 100644 --- a/tests/expectations/tests/same_struct_name_in_different_namespaces.rs +++ b/tests/expectations/tests/same_struct_name_in_different_namespaces.rs @@ -20,6 +20,7 @@ pub struct JS_shadow_Zone { fn bindgen_test_layout_JS_shadow_Zone() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -31,10 +32,7 @@ fn bindgen_test_layout_JS_shadow_Zone() { concat!("Alignment of ", stringify!(JS_shadow_Zone)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -44,10 +42,7 @@ fn bindgen_test_layout_JS_shadow_Zone() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/sentry-defined-multiple-times.rs b/tests/expectations/tests/sentry-defined-multiple-times.rs index 312823ebcf..48f8ca8133 100644 --- a/tests/expectations/tests/sentry-defined-multiple-times.rs +++ b/tests/expectations/tests/sentry-defined-multiple-times.rs @@ -31,6 +31,7 @@ pub mod root { fn bindgen_test_layout_sentry() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -43,7 +44,6 @@ pub mod root { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).i_am_plain_sentry) as usize - ptr as usize }, @@ -83,6 +83,7 @@ pub mod root { fn bindgen_test_layout_NotTemplateWrapper_sentry() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -95,7 +96,6 @@ pub mod root { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!( (*ptr).i_am_not_template_wrapper_sentry ) as usize - @@ -125,6 +125,7 @@ pub mod root { const UNINIT: ::std::mem::MaybeUninit< InlineNotTemplateWrapper_sentry, > = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -143,7 +144,6 @@ pub mod root { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!( (*ptr).i_am_inline_not_template_wrapper_sentry ) as usize - @@ -233,6 +233,7 @@ pub mod root { const UNINIT: ::std::mem::MaybeUninit< OuterDoubleWrapper_InnerDoubleWrapper_sentry, > = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::< OuterDoubleWrapper_InnerDoubleWrapper_sentry, @@ -255,7 +256,6 @@ pub mod root { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).i_am_double_wrapper_sentry) as usize - ptr as usize @@ -290,9 +290,10 @@ pub mod root { const UNINIT: ::std::mem::MaybeUninit< OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry, > = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq ! (:: std :: mem :: size_of :: < OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry > () , 4usize , concat ! ("Size of: " , stringify ! (OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry))); assert_eq ! (:: std :: mem :: align_of :: < OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry > () , 4usize , concat ! ("Alignment of " , stringify ! (OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry))); - assert_eq ! (unsafe { let ptr = UNINIT . as_ptr () ; :: std :: ptr :: addr_of ! ((* ptr) . i_am_double_wrapper_inline_sentry) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry) , "::" , stringify ! (i_am_double_wrapper_inline_sentry))); + assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . i_am_double_wrapper_inline_sentry) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry) , "::" , stringify ! (i_am_double_wrapper_inline_sentry))); } #[test] fn bindgen_test_layout_OuterDoubleInlineWrapper_InnerDoubleInlineWrapper( @@ -355,6 +356,7 @@ pub mod root { fn bindgen_test_layout_sentry() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -367,7 +369,6 @@ pub mod root { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).i_am_outside_namespace_sentry) as usize - ptr as usize diff --git a/tests/expectations/tests/size_t_is_usize.rs b/tests/expectations/tests/size_t_is_usize.rs index 5c2c26708b..2397e0a56c 100644 --- a/tests/expectations/tests/size_t_is_usize.rs +++ b/tests/expectations/tests/size_t_is_usize.rs @@ -16,6 +16,7 @@ pub struct A { 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::(), 24usize, @@ -27,26 +28,17 @@ fn bindgen_test_layout_A() { concat!("Alignment of ", stringify!(A)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(len)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).offset) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).offset) as usize - ptr as usize }, 8usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(offset)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize }, 16usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(next)) ); diff --git a/tests/expectations/tests/size_t_template.rs b/tests/expectations/tests/size_t_template.rs index 3b0d34f38d..1aa8b9acae 100644 --- a/tests/expectations/tests/size_t_template.rs +++ b/tests/expectations/tests/size_t_template.rs @@ -14,6 +14,7 @@ pub struct C { 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::(), 12usize, @@ -25,10 +26,7 @@ fn bindgen_test_layout_C() { concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(arr)) ); diff --git a/tests/expectations/tests/struct_containing_forward_declared_struct.rs b/tests/expectations/tests/struct_containing_forward_declared_struct.rs index 3790427006..8279fe1f7d 100644 --- a/tests/expectations/tests/struct_containing_forward_declared_struct.rs +++ b/tests/expectations/tests/struct_containing_forward_declared_struct.rs @@ -14,6 +14,7 @@ pub struct a { 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, @@ -25,10 +26,7 @@ fn bindgen_test_layout_a() { concat!("Alignment of ", stringify!(a)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).val_a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).val_a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(a), "::", stringify!(val_a)) ); @@ -51,6 +49,7 @@ pub struct b { 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::(), 4usize, @@ -62,10 +61,7 @@ fn bindgen_test_layout_b() { concat!("Alignment of ", stringify!(b)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).val_b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).val_b) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(b), "::", stringify!(val_b)) ); diff --git a/tests/expectations/tests/struct_typedef.rs b/tests/expectations/tests/struct_typedef.rs index dfe4822c32..f9d7fedb25 100644 --- a/tests/expectations/tests/struct_typedef.rs +++ b/tests/expectations/tests/struct_typedef.rs @@ -14,6 +14,7 @@ pub struct typedef_named_struct { fn bindgen_test_layout_typedef_named_struct() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -26,7 +27,6 @@ fn bindgen_test_layout_typedef_named_struct() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).has_name) as usize - ptr as usize }, 0usize, @@ -47,6 +47,7 @@ pub struct _bindgen_ty_1 { fn bindgen_test_layout__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit<_bindgen_ty_1> = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::<_bindgen_ty_1>(), 8usize, @@ -58,10 +59,7 @@ fn bindgen_test_layout__bindgen_ty_1() { concat!("Alignment of ", stringify!(_bindgen_ty_1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).no_name) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).no_name) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/struct_typedef_ns.rs b/tests/expectations/tests/struct_typedef_ns.rs index 5ac7d9859b..2bad358aee 100644 --- a/tests/expectations/tests/struct_typedef_ns.rs +++ b/tests/expectations/tests/struct_typedef_ns.rs @@ -21,6 +21,7 @@ pub mod root { fn bindgen_test_layout_typedef_struct() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -33,7 +34,6 @@ pub mod root { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, 0usize, @@ -63,6 +63,7 @@ pub mod root { fn bindgen_test_layout__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit<_bindgen_ty_1> = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::<_bindgen_ty_1>(), 4usize, @@ -75,7 +76,6 @@ pub mod root { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, 0usize, diff --git a/tests/expectations/tests/struct_with_anon_struct.rs b/tests/expectations/tests/struct_with_anon_struct.rs index 47193018cf..238400a17c 100644 --- a/tests/expectations/tests/struct_with_anon_struct.rs +++ b/tests/expectations/tests/struct_with_anon_struct.rs @@ -20,6 +20,7 @@ pub struct foo__bindgen_ty_1 { fn bindgen_test_layout_foo__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -31,10 +32,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -44,10 +42,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -61,6 +56,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 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::(), 8usize, @@ -72,10 +68,7 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/struct_with_anon_struct_array.rs b/tests/expectations/tests/struct_with_anon_struct_array.rs index 1470a9f2a2..f3af6b60ff 100644 --- a/tests/expectations/tests/struct_with_anon_struct_array.rs +++ b/tests/expectations/tests/struct_with_anon_struct_array.rs @@ -21,6 +21,7 @@ pub struct foo__bindgen_ty_1 { fn bindgen_test_layout_foo__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -32,10 +33,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -45,10 +43,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -68,6 +63,7 @@ pub struct foo__bindgen_ty_2 { fn bindgen_test_layout_foo__bindgen_ty_2() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -79,10 +75,7 @@ fn bindgen_test_layout_foo__bindgen_ty_2() { concat!("Alignment of ", stringify!(foo__bindgen_ty_2)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -92,10 +85,7 @@ fn bindgen_test_layout_foo__bindgen_ty_2() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -109,6 +99,7 @@ fn bindgen_test_layout_foo__bindgen_ty_2() { 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::(), 208usize, @@ -120,18 +111,12 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, 16usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(baz)) ); diff --git a/tests/expectations/tests/struct_with_anon_struct_pointer.rs b/tests/expectations/tests/struct_with_anon_struct_pointer.rs index 77a2dcd5c0..5bb10079a3 100644 --- a/tests/expectations/tests/struct_with_anon_struct_pointer.rs +++ b/tests/expectations/tests/struct_with_anon_struct_pointer.rs @@ -20,6 +20,7 @@ pub struct foo__bindgen_ty_1 { fn bindgen_test_layout_foo__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -31,10 +32,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -44,10 +42,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -61,6 +56,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 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::(), 8usize, @@ -72,10 +68,7 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/struct_with_anon_union.rs b/tests/expectations/tests/struct_with_anon_union.rs index f97c5236f1..08aab0a94c 100644 --- a/tests/expectations/tests/struct_with_anon_union.rs +++ b/tests/expectations/tests/struct_with_anon_union.rs @@ -20,6 +20,7 @@ pub union foo__bindgen_ty_1 { fn bindgen_test_layout_foo__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -31,10 +32,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -44,10 +42,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -70,6 +65,7 @@ impl Default for foo__bindgen_ty_1 { 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::(), 4usize, @@ -81,10 +77,7 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/struct_with_anon_union_1_0.rs b/tests/expectations/tests/struct_with_anon_union_1_0.rs index e6b6d4f772..8db33d113e 100644 --- a/tests/expectations/tests/struct_with_anon_union_1_0.rs +++ b/tests/expectations/tests/struct_with_anon_union_1_0.rs @@ -64,6 +64,7 @@ pub struct foo__bindgen_ty_1 { fn bindgen_test_layout_foo__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -75,10 +76,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -88,10 +86,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -110,6 +105,7 @@ impl Clone for foo__bindgen_ty_1 { 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::(), 4usize, @@ -121,10 +117,7 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/struct_with_anon_unnamed_struct.rs b/tests/expectations/tests/struct_with_anon_unnamed_struct.rs index 022f067fd1..5698106528 100644 --- a/tests/expectations/tests/struct_with_anon_unnamed_struct.rs +++ b/tests/expectations/tests/struct_with_anon_unnamed_struct.rs @@ -20,6 +20,7 @@ pub struct foo__bindgen_ty_1 { fn bindgen_test_layout_foo__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -31,10 +32,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -44,10 +42,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/struct_with_anon_unnamed_union.rs b/tests/expectations/tests/struct_with_anon_unnamed_union.rs index f312ccd01e..499fc7a174 100644 --- a/tests/expectations/tests/struct_with_anon_unnamed_union.rs +++ b/tests/expectations/tests/struct_with_anon_unnamed_union.rs @@ -20,6 +20,7 @@ pub union foo__bindgen_ty_1 { fn bindgen_test_layout_foo__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -31,10 +32,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -44,10 +42,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs b/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs index b138ef0f92..55432d47fc 100644 --- a/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs +++ b/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs @@ -64,6 +64,7 @@ pub struct foo__bindgen_ty_1 { fn bindgen_test_layout_foo__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -75,10 +76,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -88,10 +86,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/struct_with_bitfields.rs b/tests/expectations/tests/struct_with_bitfields.rs index 921d6c8359..a9be30069e 100644 --- a/tests/expectations/tests/struct_with_bitfields.rs +++ b/tests/expectations/tests/struct_with_bitfields.rs @@ -104,6 +104,7 @@ pub struct bitfield { fn bindgen_test_layout_bitfield() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -115,10 +116,7 @@ fn bindgen_test_layout_bitfield() { concat!("Alignment of ", stringify!(bitfield)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).e) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).e) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/struct_with_derive_debug.rs b/tests/expectations/tests/struct_with_derive_debug.rs index 890223ac99..1bb7c77d26 100644 --- a/tests/expectations/tests/struct_with_derive_debug.rs +++ b/tests/expectations/tests/struct_with_derive_debug.rs @@ -14,6 +14,7 @@ pub struct LittleArray { 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, @@ -25,10 +26,7 @@ fn bindgen_test_layout_LittleArray() { concat!("Alignment of ", stringify!(LittleArray)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -47,6 +45,7 @@ pub struct BigArray { 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, @@ -58,10 +57,7 @@ fn bindgen_test_layout_BigArray() { concat!("Alignment of ", stringify!(BigArray)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -89,6 +85,7 @@ pub struct WithLittleArray { 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, @@ -100,10 +97,7 @@ fn bindgen_test_layout_WithLittleArray() { concat!("Alignment of ", stringify!(WithLittleArray)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -122,6 +116,7 @@ pub struct WithBigArray { 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, @@ -133,10 +128,7 @@ fn bindgen_test_layout_WithBigArray() { concat!("Alignment of ", stringify!(WithBigArray)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/struct_with_large_array.rs b/tests/expectations/tests/struct_with_large_array.rs index 1d98ae13c2..9f2c0ecc28 100644 --- a/tests/expectations/tests/struct_with_large_array.rs +++ b/tests/expectations/tests/struct_with_large_array.rs @@ -14,6 +14,7 @@ pub struct S { 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, @@ -26,7 +27,6 @@ fn bindgen_test_layout_S() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize }, 0usize, diff --git a/tests/expectations/tests/struct_with_nesting.rs b/tests/expectations/tests/struct_with_nesting.rs index 34d26f5f4f..ff177ff131 100644 --- a/tests/expectations/tests/struct_with_nesting.rs +++ b/tests/expectations/tests/struct_with_nesting.rs @@ -28,6 +28,7 @@ pub struct foo__bindgen_ty_1__bindgen_ty_1 { fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -39,10 +40,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).c1) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).c1) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -52,10 +50,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).c2) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).c2) as usize - ptr as usize }, 2usize, concat!( "Offset of field: ", @@ -77,6 +72,7 @@ pub struct foo__bindgen_ty_1__bindgen_ty_2 { fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -88,10 +84,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).d1) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).d1) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -101,10 +94,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).d2) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).d2) as usize - ptr as usize }, 1usize, concat!( "Offset of field: ", @@ -114,10 +104,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).d3) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).d3) as usize - ptr as usize }, 2usize, concat!( "Offset of field: ", @@ -127,10 +114,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).d4) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).d4) as usize - ptr as usize }, 3usize, concat!( "Offset of field: ", @@ -144,6 +128,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { fn bindgen_test_layout_foo__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -155,10 +140,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -181,6 +163,7 @@ impl Default for foo__bindgen_ty_1 { 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::(), 8usize, @@ -192,10 +175,7 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) ); diff --git a/tests/expectations/tests/struct_with_nesting_1_0.rs b/tests/expectations/tests/struct_with_nesting_1_0.rs index e9acf62699..af795b6423 100644 --- a/tests/expectations/tests/struct_with_nesting_1_0.rs +++ b/tests/expectations/tests/struct_with_nesting_1_0.rs @@ -72,6 +72,7 @@ pub struct foo__bindgen_ty_1__bindgen_ty_1 { fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -83,10 +84,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).c1) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).c1) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -96,10 +94,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).c2) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).c2) as usize - ptr as usize }, 2usize, concat!( "Offset of field: ", @@ -126,6 +121,7 @@ pub struct foo__bindgen_ty_1__bindgen_ty_2 { fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -137,10 +133,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).d1) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).d1) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -150,10 +143,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).d2) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).d2) as usize - ptr as usize }, 1usize, concat!( "Offset of field: ", @@ -163,10 +153,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).d3) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).d3) as usize - ptr as usize }, 2usize, concat!( "Offset of field: ", @@ -176,10 +163,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).d4) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).d4) as usize - ptr as usize }, 3usize, concat!( "Offset of field: ", @@ -198,6 +182,7 @@ impl Clone for foo__bindgen_ty_1__bindgen_ty_2 { fn bindgen_test_layout_foo__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -209,10 +194,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -231,6 +213,7 @@ impl Clone for foo__bindgen_ty_1 { 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::(), 8usize, @@ -242,10 +225,7 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) ); diff --git a/tests/expectations/tests/struct_with_packing.rs b/tests/expectations/tests/struct_with_packing.rs index c34ea7bf7c..b8ea17cd83 100644 --- a/tests/expectations/tests/struct_with_packing.rs +++ b/tests/expectations/tests/struct_with_packing.rs @@ -15,6 +15,7 @@ pub struct a { 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::(), 3usize, @@ -26,18 +27,12 @@ fn bindgen_test_layout_a() { concat!("Alignment of ", stringify!(a)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(a), "::", stringify!(b)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, 1usize, concat!("Offset of field: ", stringify!(a), "::", stringify!(c)) ); diff --git a/tests/expectations/tests/struct_with_struct.rs b/tests/expectations/tests/struct_with_struct.rs index a334d79c50..b1ee5db48b 100644 --- a/tests/expectations/tests/struct_with_struct.rs +++ b/tests/expectations/tests/struct_with_struct.rs @@ -20,6 +20,7 @@ pub struct foo__bindgen_ty_1 { fn bindgen_test_layout_foo__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -31,10 +32,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -44,10 +42,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -61,6 +56,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 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::(), 8usize, @@ -72,10 +68,7 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/template.rs b/tests/expectations/tests/template.rs index 6b965f32c6..7637295a92 100644 --- a/tests/expectations/tests/template.rs +++ b/tests/expectations/tests/template.rs @@ -70,6 +70,7 @@ pub struct C { 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::(), 104usize, @@ -81,16 +82,12 @@ fn bindgen_test_layout_C() { concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mB) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mB) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(mB)) ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mBConstPtr) as usize - ptr as usize }, 8usize, @@ -103,7 +100,6 @@ fn bindgen_test_layout_C() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mBConstStructPtr) as usize - ptr as usize }, @@ -117,7 +113,6 @@ fn bindgen_test_layout_C() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mBConstStructPtrArray) as usize - ptr as usize }, @@ -130,10 +125,7 @@ fn bindgen_test_layout_C() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBConst) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mBConst) as usize - ptr as usize }, 32usize, concat!( "Offset of field: ", @@ -144,7 +136,6 @@ fn bindgen_test_layout_C() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mBVolatile) as usize - ptr as usize }, 36usize, @@ -157,7 +148,6 @@ fn bindgen_test_layout_C() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mBConstBool) as usize - ptr as usize }, 40usize, @@ -170,7 +160,6 @@ fn bindgen_test_layout_C() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mBConstChar) as usize - ptr as usize }, 42usize, @@ -182,10 +171,7 @@ fn bindgen_test_layout_C() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBArray) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mBArray) as usize - ptr as usize }, 44usize, concat!( "Offset of field: ", @@ -196,7 +182,6 @@ fn bindgen_test_layout_C() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mBPtrArray) as usize - ptr as usize }, 48usize, @@ -209,7 +194,6 @@ fn bindgen_test_layout_C() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mBArrayPtr) as usize - ptr as usize }, 56usize, @@ -221,16 +205,12 @@ fn bindgen_test_layout_C() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBRef) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mBRef) as usize - ptr as usize }, 64usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(mBRef)) ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mBConstRef) as usize - ptr as usize }, 72usize, @@ -242,10 +222,7 @@ fn bindgen_test_layout_C() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mPtrRef) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mPtrRef) as usize - ptr as usize }, 80usize, concat!( "Offset of field: ", @@ -256,7 +233,6 @@ fn bindgen_test_layout_C() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mArrayRef) as usize - ptr as usize }, 88usize, @@ -269,7 +245,6 @@ fn bindgen_test_layout_C() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mBConstArray) as usize - ptr as usize }, 96usize, @@ -347,6 +322,7 @@ pub struct RootedContainer { fn bindgen_test_layout_RootedContainer() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 24usize, @@ -358,10 +334,7 @@ fn bindgen_test_layout_RootedContainer() { concat!("Alignment of ", stringify!(RootedContainer)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).root) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).root) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -405,6 +378,7 @@ pub struct PODButContainsDtor { fn bindgen_test_layout_PODButContainsDtor() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -416,10 +390,7 @@ fn bindgen_test_layout_PODButContainsDtor() { concat!("Alignment of ", stringify!(PODButContainsDtor)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -453,6 +424,7 @@ pub struct POD { fn bindgen_test_layout_POD() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -465,7 +437,6 @@ fn bindgen_test_layout_POD() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).opaque_member) as usize - ptr as usize }, 0usize, diff --git a/tests/expectations/tests/test_mixed_header_and_header_contents.rs b/tests/expectations/tests/test_mixed_header_and_header_contents.rs index 7475a5212b..5f8da2affb 100644 --- a/tests/expectations/tests/test_mixed_header_and_header_contents.rs +++ b/tests/expectations/tests/test_mixed_header_and_header_contents.rs @@ -35,6 +35,7 @@ pub struct Test { fn bindgen_test_layout_Test() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 12usize, @@ -46,82 +47,52 @@ fn bindgen_test_layout_Test() { concat!("Alignment of ", stringify!(Test)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).ch) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).ch) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(ch)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize }, 1usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(u)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, 2usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(d)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).cch) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).cch) as usize - ptr as usize }, 3usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(cch)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).cu) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).cu) as usize - ptr as usize }, 4usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(cu)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).cd) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).cd) as usize - ptr as usize }, 5usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(cd)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).Cch) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).Cch) as usize - ptr as usize }, 6usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cch)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).Cu) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).Cu) as usize - ptr as usize }, 7usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cu)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).Cd) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).Cd) as usize - ptr as usize }, 8usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cd)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).Ccch) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).Ccch) as usize - ptr as usize }, 9usize, concat!( "Offset of field: ", @@ -131,18 +102,12 @@ fn bindgen_test_layout_Test() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).Ccu) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).Ccu) as usize - ptr as usize }, 10usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccu)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).Ccd) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).Ccd) as usize - ptr as usize }, 11usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccd)) ); diff --git a/tests/expectations/tests/test_multiple_header_calls_in_builder.rs b/tests/expectations/tests/test_multiple_header_calls_in_builder.rs index a51a11f65c..b594d70c93 100644 --- a/tests/expectations/tests/test_multiple_header_calls_in_builder.rs +++ b/tests/expectations/tests/test_multiple_header_calls_in_builder.rs @@ -29,6 +29,7 @@ pub struct Test { fn bindgen_test_layout_Test() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 12usize, @@ -40,82 +41,52 @@ fn bindgen_test_layout_Test() { concat!("Alignment of ", stringify!(Test)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).ch) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).ch) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(ch)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize }, 1usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(u)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, 2usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(d)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).cch) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).cch) as usize - ptr as usize }, 3usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(cch)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).cu) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).cu) as usize - ptr as usize }, 4usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(cu)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).cd) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).cd) as usize - ptr as usize }, 5usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(cd)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).Cch) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).Cch) as usize - ptr as usize }, 6usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cch)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).Cu) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).Cu) as usize - ptr as usize }, 7usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cu)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).Cd) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).Cd) as usize - ptr as usize }, 8usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cd)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).Ccch) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).Ccch) as usize - ptr as usize }, 9usize, concat!( "Offset of field: ", @@ -125,18 +96,12 @@ fn bindgen_test_layout_Test() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).Ccu) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).Ccu) as usize - ptr as usize }, 10usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccu)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).Ccd) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).Ccd) as usize - ptr as usize }, 11usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccd)) ); diff --git a/tests/expectations/tests/timex.rs b/tests/expectations/tests/timex.rs index 916e4eec4f..dfcebdd29c 100644 --- a/tests/expectations/tests/timex.rs +++ b/tests/expectations/tests/timex.rs @@ -102,6 +102,7 @@ pub struct timex { fn bindgen_test_layout_timex() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 48usize, @@ -113,10 +114,7 @@ fn bindgen_test_layout_timex() { concat!("Alignment of ", stringify!(timex)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).tai) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).tai) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -146,6 +144,7 @@ pub struct timex_named { fn bindgen_test_layout_timex_named() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 48usize, @@ -157,10 +156,7 @@ fn bindgen_test_layout_timex_named() { concat!("Alignment of ", stringify!(timex_named)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).tai) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).tai) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/type-referenced-by-allowlisted-function.rs b/tests/expectations/tests/type-referenced-by-allowlisted-function.rs index 0383e1ddd2..7ae042bc9c 100644 --- a/tests/expectations/tests/type-referenced-by-allowlisted-function.rs +++ b/tests/expectations/tests/type-referenced-by-allowlisted-function.rs @@ -14,6 +14,7 @@ pub struct dl_phdr_info { fn bindgen_test_layout_dl_phdr_info() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -25,10 +26,7 @@ fn bindgen_test_layout_dl_phdr_info() { concat!("Alignment of ", stringify!(dl_phdr_info)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/typeref.rs b/tests/expectations/tests/typeref.rs index ad1a976106..a3a31dafa7 100644 --- a/tests/expectations/tests/typeref.rs +++ b/tests/expectations/tests/typeref.rs @@ -14,6 +14,7 @@ pub struct mozilla_FragmentOrURL { fn bindgen_test_layout_mozilla_FragmentOrURL() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -26,7 +27,6 @@ fn bindgen_test_layout_mozilla_FragmentOrURL() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mIsLocalRef) as usize - ptr as usize }, 0usize, @@ -92,6 +92,7 @@ pub struct Bar { 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::(), 8usize, @@ -103,10 +104,7 @@ fn bindgen_test_layout_Bar() { concat!("Alignment of ", stringify!(Bar)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mFoo) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mFoo) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(mFoo)) ); @@ -128,6 +126,7 @@ pub struct nsFoo { 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::(), 8usize, @@ -139,10 +138,7 @@ fn bindgen_test_layout_nsFoo() { concat!("Alignment of ", stringify!(nsFoo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBar) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mBar) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/typeref_1_0.rs b/tests/expectations/tests/typeref_1_0.rs index c043b9e6b9..8e4143c082 100644 --- a/tests/expectations/tests/typeref_1_0.rs +++ b/tests/expectations/tests/typeref_1_0.rs @@ -57,6 +57,7 @@ pub struct mozilla_FragmentOrURL { fn bindgen_test_layout_mozilla_FragmentOrURL() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 1usize, @@ -69,7 +70,6 @@ fn bindgen_test_layout_mozilla_FragmentOrURL() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mIsLocalRef) as usize - ptr as usize }, 0usize, @@ -130,6 +130,7 @@ pub struct Bar { 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::(), 8usize, @@ -141,10 +142,7 @@ fn bindgen_test_layout_Bar() { concat!("Alignment of ", stringify!(Bar)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mFoo) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mFoo) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(mFoo)) ); @@ -172,6 +170,7 @@ pub struct nsFoo { 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::(), 8usize, @@ -183,10 +182,7 @@ fn bindgen_test_layout_nsFoo() { concat!("Alignment of ", stringify!(nsFoo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBar) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mBar) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/underscore.rs b/tests/expectations/tests/underscore.rs index 8752d08e5e..bfc05ac17a 100644 --- a/tests/expectations/tests/underscore.rs +++ b/tests/expectations/tests/underscore.rs @@ -15,6 +15,7 @@ pub struct ptr_t { fn bindgen_test_layout_ptr_t() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -26,10 +27,7 @@ fn bindgen_test_layout_ptr_t() { concat!("Alignment of ", stringify!(ptr_t)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).__) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).__) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(ptr_t), "::", stringify!(__)) ); diff --git a/tests/expectations/tests/union-align.rs b/tests/expectations/tests/union-align.rs index 4c2f8ba5c2..062ea97a86 100644 --- a/tests/expectations/tests/union-align.rs +++ b/tests/expectations/tests/union-align.rs @@ -15,6 +15,7 @@ pub union Bar { 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, @@ -26,10 +27,7 @@ fn bindgen_test_layout_Bar() { concat!("Alignment of ", stringify!(Bar)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(foo)) ); @@ -53,6 +51,7 @@ pub union Baz { 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, @@ -64,10 +63,7 @@ fn bindgen_test_layout_Baz() { concat!("Alignment of ", stringify!(Baz)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Baz), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/union-in-ns.rs b/tests/expectations/tests/union-in-ns.rs index 27ade8e277..65f3f8f288 100644 --- a/tests/expectations/tests/union-in-ns.rs +++ b/tests/expectations/tests/union-in-ns.rs @@ -18,6 +18,7 @@ pub mod root { 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, @@ -29,10 +30,7 @@ pub mod root { concat!("Alignment of ", stringify!(bar)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/union-in-ns_1_0.rs b/tests/expectations/tests/union-in-ns_1_0.rs index d81d22a2e7..a057cc348a 100644 --- a/tests/expectations/tests/union-in-ns_1_0.rs +++ b/tests/expectations/tests/union-in-ns_1_0.rs @@ -65,6 +65,7 @@ pub mod root { 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, @@ -76,10 +77,7 @@ pub mod root { concat!("Alignment of ", stringify!(bar)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/union_dtor.rs b/tests/expectations/tests/union_dtor.rs index 95216024db..085e5ca30a 100644 --- a/tests/expectations/tests/union_dtor.rs +++ b/tests/expectations/tests/union_dtor.rs @@ -14,6 +14,7 @@ pub union UnionWithDtor { fn bindgen_test_layout_UnionWithDtor() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -25,10 +26,7 @@ fn bindgen_test_layout_UnionWithDtor() { concat!("Alignment of ", stringify!(UnionWithDtor)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mFoo) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mFoo) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -38,10 +36,7 @@ fn bindgen_test_layout_UnionWithDtor() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBar) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mBar) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/union_dtor_1_0.rs b/tests/expectations/tests/union_dtor_1_0.rs index 3579cb64bd..67455aa8b8 100644 --- a/tests/expectations/tests/union_dtor_1_0.rs +++ b/tests/expectations/tests/union_dtor_1_0.rs @@ -59,6 +59,7 @@ pub struct UnionWithDtor { fn bindgen_test_layout_UnionWithDtor() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -70,10 +71,7 @@ fn bindgen_test_layout_UnionWithDtor() { concat!("Alignment of ", stringify!(UnionWithDtor)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mFoo) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mFoo) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -83,10 +81,7 @@ fn bindgen_test_layout_UnionWithDtor() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mBar) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mBar) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/union_fields.rs b/tests/expectations/tests/union_fields.rs index af1b1626a9..9135ca3c6c 100644 --- a/tests/expectations/tests/union_fields.rs +++ b/tests/expectations/tests/union_fields.rs @@ -16,6 +16,7 @@ pub union nsStyleUnion { fn bindgen_test_layout_nsStyleUnion() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -27,10 +28,7 @@ fn bindgen_test_layout_nsStyleUnion() { concat!("Alignment of ", stringify!(nsStyleUnion)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mInt) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mInt) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -40,10 +38,7 @@ fn bindgen_test_layout_nsStyleUnion() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mFloat) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mFloat) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -54,7 +49,6 @@ fn bindgen_test_layout_nsStyleUnion() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mPointer) as usize - ptr as usize }, 0usize, diff --git a/tests/expectations/tests/union_fields_1_0.rs b/tests/expectations/tests/union_fields_1_0.rs index c575efb8b4..b5f94bcd05 100644 --- a/tests/expectations/tests/union_fields_1_0.rs +++ b/tests/expectations/tests/union_fields_1_0.rs @@ -60,6 +60,7 @@ pub struct nsStyleUnion { fn bindgen_test_layout_nsStyleUnion() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -71,10 +72,7 @@ fn bindgen_test_layout_nsStyleUnion() { concat!("Alignment of ", stringify!(nsStyleUnion)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mInt) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mInt) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -84,10 +82,7 @@ fn bindgen_test_layout_nsStyleUnion() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mFloat) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mFloat) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -98,7 +93,6 @@ fn bindgen_test_layout_nsStyleUnion() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mPointer) as usize - ptr as usize }, 0usize, diff --git a/tests/expectations/tests/union_with_anon_struct.rs b/tests/expectations/tests/union_with_anon_struct.rs index f2502fc07a..35b5829beb 100644 --- a/tests/expectations/tests/union_with_anon_struct.rs +++ b/tests/expectations/tests/union_with_anon_struct.rs @@ -20,6 +20,7 @@ pub struct foo__bindgen_ty_1 { fn bindgen_test_layout_foo__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -31,10 +32,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -44,10 +42,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -61,6 +56,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { 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::(), 8usize, @@ -72,10 +68,7 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/union_with_anon_struct_1_0.rs b/tests/expectations/tests/union_with_anon_struct_1_0.rs index 6136653960..8b11e75796 100644 --- a/tests/expectations/tests/union_with_anon_struct_1_0.rs +++ b/tests/expectations/tests/union_with_anon_struct_1_0.rs @@ -64,6 +64,7 @@ pub struct foo__bindgen_ty_1 { fn bindgen_test_layout_foo__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -75,10 +76,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -88,10 +86,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -110,6 +105,7 @@ impl Clone for foo__bindgen_ty_1 { 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::(), 8usize, @@ -121,10 +117,7 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/union_with_anon_struct_bitfield.rs b/tests/expectations/tests/union_with_anon_struct_bitfield.rs index ccceca2464..e81b3bef50 100644 --- a/tests/expectations/tests/union_with_anon_struct_bitfield.rs +++ b/tests/expectations/tests/union_with_anon_struct_bitfield.rs @@ -166,6 +166,7 @@ impl foo__bindgen_ty_1 { 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::(), 4usize, @@ -177,10 +178,7 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) ); diff --git a/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs b/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs index 0a8c2aeadc..6ce6ed2282 100644 --- a/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs +++ b/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs @@ -215,6 +215,7 @@ impl foo__bindgen_ty_1 { 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::(), 4usize, @@ -226,10 +227,7 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) ); diff --git a/tests/expectations/tests/union_with_anon_union.rs b/tests/expectations/tests/union_with_anon_union.rs index 063fa54630..487650bfe4 100644 --- a/tests/expectations/tests/union_with_anon_union.rs +++ b/tests/expectations/tests/union_with_anon_union.rs @@ -20,6 +20,7 @@ pub union foo__bindgen_ty_1 { fn bindgen_test_layout_foo__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -31,10 +32,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -44,10 +42,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -70,6 +65,7 @@ impl Default for foo__bindgen_ty_1 { 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::(), 4usize, @@ -81,10 +77,7 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/union_with_anon_union_1_0.rs b/tests/expectations/tests/union_with_anon_union_1_0.rs index c366fac02a..f3e4b84003 100644 --- a/tests/expectations/tests/union_with_anon_union_1_0.rs +++ b/tests/expectations/tests/union_with_anon_union_1_0.rs @@ -65,6 +65,7 @@ pub struct foo__bindgen_ty_1 { fn bindgen_test_layout_foo__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -76,10 +77,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -89,10 +87,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -111,6 +106,7 @@ impl Clone for foo__bindgen_ty_1 { 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::(), 4usize, @@ -122,10 +118,7 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); diff --git a/tests/expectations/tests/union_with_anon_unnamed_struct.rs b/tests/expectations/tests/union_with_anon_unnamed_struct.rs index d1aec85312..cff5df0472 100644 --- a/tests/expectations/tests/union_with_anon_unnamed_struct.rs +++ b/tests/expectations/tests/union_with_anon_unnamed_struct.rs @@ -23,6 +23,7 @@ pub struct pixel__bindgen_ty_1 { fn bindgen_test_layout_pixel__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -34,10 +35,7 @@ fn bindgen_test_layout_pixel__bindgen_ty_1() { concat!("Alignment of ", stringify!(pixel__bindgen_ty_1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).r) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).r) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -47,10 +45,7 @@ fn bindgen_test_layout_pixel__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).g) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).g) as usize - ptr as usize }, 1usize, concat!( "Offset of field: ", @@ -60,10 +55,7 @@ fn bindgen_test_layout_pixel__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 2usize, concat!( "Offset of field: ", @@ -73,10 +65,7 @@ fn bindgen_test_layout_pixel__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 3usize, concat!( "Offset of field: ", @@ -90,6 +79,7 @@ fn bindgen_test_layout_pixel__bindgen_ty_1() { fn bindgen_test_layout_pixel() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -101,10 +91,7 @@ fn bindgen_test_layout_pixel() { concat!("Alignment of ", stringify!(pixel)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).rgba) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).rgba) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs b/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs index cc4117f68e..1562a8c971 100644 --- a/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs +++ b/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs @@ -67,6 +67,7 @@ pub struct pixel__bindgen_ty_1 { fn bindgen_test_layout_pixel__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -78,10 +79,7 @@ fn bindgen_test_layout_pixel__bindgen_ty_1() { concat!("Alignment of ", stringify!(pixel__bindgen_ty_1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).r) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).r) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -91,10 +89,7 @@ fn bindgen_test_layout_pixel__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).g) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).g) as usize - ptr as usize }, 1usize, concat!( "Offset of field: ", @@ -104,10 +99,7 @@ fn bindgen_test_layout_pixel__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 2usize, concat!( "Offset of field: ", @@ -117,10 +109,7 @@ fn bindgen_test_layout_pixel__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 3usize, concat!( "Offset of field: ", @@ -139,6 +128,7 @@ impl Clone for pixel__bindgen_ty_1 { fn bindgen_test_layout_pixel() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -150,10 +140,7 @@ fn bindgen_test_layout_pixel() { concat!("Alignment of ", stringify!(pixel)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).rgba) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).rgba) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/union_with_anon_unnamed_union.rs b/tests/expectations/tests/union_with_anon_unnamed_union.rs index 9da74dfc79..f1abfc5a25 100644 --- a/tests/expectations/tests/union_with_anon_unnamed_union.rs +++ b/tests/expectations/tests/union_with_anon_unnamed_union.rs @@ -21,6 +21,7 @@ pub union foo__bindgen_ty_1 { fn bindgen_test_layout_foo__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 2usize, @@ -32,10 +33,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -45,10 +43,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -71,6 +66,7 @@ impl Default for foo__bindgen_ty_1 { 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::(), 4usize, @@ -82,10 +78,7 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) ); diff --git a/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs b/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs index 4f3d711cad..197a6bbfbc 100644 --- a/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs +++ b/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs @@ -66,6 +66,7 @@ pub struct foo__bindgen_ty_1 { fn bindgen_test_layout_foo__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 2usize, @@ -77,10 +78,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -90,10 +88,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -112,6 +107,7 @@ impl Clone for foo__bindgen_ty_1 { 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::(), 4usize, @@ -123,10 +119,7 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) ); diff --git a/tests/expectations/tests/union_with_big_member.rs b/tests/expectations/tests/union_with_big_member.rs index f80cba6325..7110257bc7 100644 --- a/tests/expectations/tests/union_with_big_member.rs +++ b/tests/expectations/tests/union_with_big_member.rs @@ -15,6 +15,7 @@ pub union WithBigArray { 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, @@ -26,10 +27,7 @@ fn bindgen_test_layout_WithBigArray() { concat!("Alignment of ", stringify!(WithBigArray)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -39,10 +37,7 @@ fn bindgen_test_layout_WithBigArray() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -71,6 +66,7 @@ pub union WithBigArray2 { fn bindgen_test_layout_WithBigArray2() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 36usize, @@ -82,10 +78,7 @@ fn bindgen_test_layout_WithBigArray2() { concat!("Alignment of ", stringify!(WithBigArray2)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -95,10 +88,7 @@ fn bindgen_test_layout_WithBigArray2() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -127,6 +117,7 @@ pub union WithBigMember { fn bindgen_test_layout_WithBigMember() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 132usize, @@ -138,10 +129,7 @@ fn bindgen_test_layout_WithBigMember() { concat!("Alignment of ", stringify!(WithBigMember)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -151,10 +139,7 @@ fn bindgen_test_layout_WithBigMember() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/union_with_big_member_1_0.rs b/tests/expectations/tests/union_with_big_member_1_0.rs index 4cb330bf27..63b43baa82 100644 --- a/tests/expectations/tests/union_with_big_member_1_0.rs +++ b/tests/expectations/tests/union_with_big_member_1_0.rs @@ -59,6 +59,7 @@ pub struct WithBigArray { 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, @@ -70,10 +71,7 @@ fn bindgen_test_layout_WithBigArray() { concat!("Alignment of ", stringify!(WithBigArray)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -83,10 +81,7 @@ fn bindgen_test_layout_WithBigArray() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -121,6 +116,7 @@ pub struct WithBigArray2 { fn bindgen_test_layout_WithBigArray2() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 36usize, @@ -132,10 +128,7 @@ fn bindgen_test_layout_WithBigArray2() { concat!("Alignment of ", stringify!(WithBigArray2)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -145,10 +138,7 @@ fn bindgen_test_layout_WithBigArray2() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -174,6 +164,7 @@ pub struct WithBigMember { fn bindgen_test_layout_WithBigMember() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 132usize, @@ -185,10 +176,7 @@ fn bindgen_test_layout_WithBigMember() { concat!("Alignment of ", stringify!(WithBigMember)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -198,10 +186,7 @@ fn bindgen_test_layout_WithBigMember() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/union_with_nesting.rs b/tests/expectations/tests/union_with_nesting.rs index c399b633a4..ec9c148011 100644 --- a/tests/expectations/tests/union_with_nesting.rs +++ b/tests/expectations/tests/union_with_nesting.rs @@ -27,6 +27,7 @@ pub union foo__bindgen_ty_1__bindgen_ty_1 { fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 2usize, @@ -38,10 +39,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b1) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b1) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -51,10 +49,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b2) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b2) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -83,6 +78,7 @@ pub union foo__bindgen_ty_1__bindgen_ty_2 { fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 2usize, @@ -94,10 +90,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).c1) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).c1) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -107,10 +100,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).c2) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).c2) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -155,6 +145,7 @@ impl Default for foo__bindgen_ty_1 { 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::(), 4usize, @@ -166,10 +157,7 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) ); diff --git a/tests/expectations/tests/union_with_nesting_1_0.rs b/tests/expectations/tests/union_with_nesting_1_0.rs index 2bc3097757..a1e452fe03 100644 --- a/tests/expectations/tests/union_with_nesting_1_0.rs +++ b/tests/expectations/tests/union_with_nesting_1_0.rs @@ -72,6 +72,7 @@ pub struct foo__bindgen_ty_1__bindgen_ty_1 { fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 2usize, @@ -83,10 +84,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b1) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b1) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -96,10 +94,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).b2) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).b2) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -125,6 +120,7 @@ pub struct foo__bindgen_ty_1__bindgen_ty_2 { fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 2usize, @@ -136,10 +132,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).c1) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).c1) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -149,10 +142,7 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).c2) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).c2) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -189,6 +179,7 @@ impl Clone for foo__bindgen_ty_1 { 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::(), 4usize, @@ -200,10 +191,7 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) ); diff --git a/tests/expectations/tests/unknown_attr.rs b/tests/expectations/tests/unknown_attr.rs index a48e9733f5..c790f009c9 100644 --- a/tests/expectations/tests/unknown_attr.rs +++ b/tests/expectations/tests/unknown_attr.rs @@ -17,6 +17,7 @@ pub struct max_align_t { fn bindgen_test_layout_max_align_t() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 32usize, @@ -29,7 +30,6 @@ fn bindgen_test_layout_max_align_t() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).__clang_max_align_nonce1) as usize - ptr as usize }, @@ -43,7 +43,6 @@ fn bindgen_test_layout_max_align_t() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).__clang_max_align_nonce2) as usize - ptr as usize }, diff --git a/tests/expectations/tests/use-core.rs b/tests/expectations/tests/use-core.rs index b2a7d30350..e6124d5aec 100644 --- a/tests/expectations/tests/use-core.rs +++ b/tests/expectations/tests/use-core.rs @@ -18,6 +18,7 @@ pub struct foo { fn bindgen_test_layout_foo() { const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::core::mem::size_of::(), 16usize, @@ -29,26 +30,17 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::core::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::core::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::core::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::core::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 4usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, + unsafe { ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 8usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); @@ -72,6 +64,7 @@ pub union _bindgen_ty_1 { fn bindgen_test_layout__bindgen_ty_1() { const UNINIT: ::core::mem::MaybeUninit<_bindgen_ty_1> = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::core::mem::size_of::<_bindgen_ty_1>(), 8usize, @@ -83,10 +76,7 @@ fn bindgen_test_layout__bindgen_ty_1() { concat!("Alignment of ", stringify!(_bindgen_ty_1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, + unsafe { ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -96,10 +86,7 @@ fn bindgen_test_layout__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::core::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, + unsafe { ::core::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/use-core_1_0.rs b/tests/expectations/tests/use-core_1_0.rs index ca85287180..8c6d0fd272 100644 --- a/tests/expectations/tests/use-core_1_0.rs +++ b/tests/expectations/tests/use-core_1_0.rs @@ -61,6 +61,7 @@ pub struct foo { fn bindgen_test_layout_foo() { const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::core::mem::size_of::(), 16usize, @@ -72,26 +73,17 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::core::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, + unsafe { ::core::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::core::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, + unsafe { ::core::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 4usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, + unsafe { ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 8usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); @@ -121,6 +113,7 @@ pub struct _bindgen_ty_1 { fn bindgen_test_layout__bindgen_ty_1() { const UNINIT: ::core::mem::MaybeUninit<_bindgen_ty_1> = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::core::mem::size_of::<_bindgen_ty_1>(), 8usize, @@ -132,10 +125,7 @@ fn bindgen_test_layout__bindgen_ty_1() { concat!("Alignment of ", stringify!(_bindgen_ty_1)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, + unsafe { ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -145,10 +135,7 @@ fn bindgen_test_layout__bindgen_ty_1() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::core::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, + unsafe { ::core::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/var-tracing.rs b/tests/expectations/tests/var-tracing.rs index 9d8e7450a9..4280802ed2 100644 --- a/tests/expectations/tests/var-tracing.rs +++ b/tests/expectations/tests/var-tracing.rs @@ -14,6 +14,7 @@ pub struct Bar { 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, @@ -25,10 +26,7 @@ fn bindgen_test_layout_Bar() { concat!("Alignment of ", stringify!(Bar)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).m_baz) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).m_baz) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/vector.rs b/tests/expectations/tests/vector.rs index 5f90c82f9d..12d2e1b1f7 100644 --- a/tests/expectations/tests/vector.rs +++ b/tests/expectations/tests/vector.rs @@ -14,6 +14,7 @@ pub struct foo { 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::(), 8usize, @@ -25,10 +26,7 @@ fn bindgen_test_layout_foo() { concat!("Alignment of ", stringify!(foo)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/virtual_inheritance.rs b/tests/expectations/tests/virtual_inheritance.rs index eeafa0b3de..2c15b42878 100644 --- a/tests/expectations/tests/virtual_inheritance.rs +++ b/tests/expectations/tests/virtual_inheritance.rs @@ -14,6 +14,7 @@ pub struct A { 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::(), 4usize, @@ -25,10 +26,7 @@ fn bindgen_test_layout_A() { concat!("Alignment of ", stringify!(A)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(foo)) ); @@ -45,6 +43,7 @@ pub struct B { 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::(), 16usize, @@ -56,10 +55,7 @@ fn bindgen_test_layout_B() { concat!("Alignment of ", stringify!(B)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 8usize, concat!("Offset of field: ", stringify!(B), "::", stringify!(bar)) ); @@ -85,6 +81,7 @@ pub struct C { 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::(), 16usize, @@ -96,10 +93,7 @@ fn bindgen_test_layout_C() { concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, 8usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(baz)) ); diff --git a/tests/expectations/tests/weird_bitfields.rs b/tests/expectations/tests/weird_bitfields.rs index 0522899c24..9383bada44 100644 --- a/tests/expectations/tests/weird_bitfields.rs +++ b/tests/expectations/tests/weird_bitfields.rs @@ -123,6 +123,7 @@ pub struct Weird { fn bindgen_test_layout_Weird() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 24usize, @@ -135,7 +136,6 @@ fn bindgen_test_layout_Weird() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mStrokeDasharrayLength) as usize - ptr as usize }, @@ -149,7 +149,6 @@ fn bindgen_test_layout_Weird() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mClipRule) as usize - ptr as usize }, 8usize, @@ -162,7 +161,6 @@ fn bindgen_test_layout_Weird() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mColorInterpolation) as usize - ptr as usize }, @@ -176,7 +174,6 @@ fn bindgen_test_layout_Weird() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mColorInterpolationFilters) as usize - ptr as usize }, @@ -190,7 +187,6 @@ fn bindgen_test_layout_Weird() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mFillRule) as usize - ptr as usize }, 11usize, @@ -203,7 +199,6 @@ fn bindgen_test_layout_Weird() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mImageRendering) as usize - ptr as usize }, 12usize, @@ -216,7 +211,6 @@ fn bindgen_test_layout_Weird() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mPaintOrder) as usize - ptr as usize }, 13usize, @@ -229,7 +223,6 @@ fn bindgen_test_layout_Weird() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mShapeRendering) as usize - ptr as usize }, 14usize, @@ -242,7 +235,6 @@ fn bindgen_test_layout_Weird() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mStrokeLinecap) as usize - ptr as usize }, 15usize, @@ -255,7 +247,6 @@ fn bindgen_test_layout_Weird() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mStrokeLinejoin) as usize - ptr as usize }, 16usize, @@ -268,7 +259,6 @@ fn bindgen_test_layout_Weird() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mTextAnchor) as usize - ptr as usize }, 17usize, @@ -281,7 +271,6 @@ fn bindgen_test_layout_Weird() { ); assert_eq!( unsafe { - let ptr = UNINIT.as_ptr(); ::std::ptr::addr_of!((*ptr).mTextRendering) as usize - ptr as usize }, 18usize, diff --git a/tests/expectations/tests/zero-size-array-align.rs b/tests/expectations/tests/zero-size-array-align.rs index 7158875e73..d7d0f6613d 100644 --- a/tests/expectations/tests/zero-size-array-align.rs +++ b/tests/expectations/tests/zero-size-array-align.rs @@ -46,6 +46,7 @@ pub struct dm_deps { fn bindgen_test_layout_dm_deps() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 8usize, @@ -57,10 +58,7 @@ fn bindgen_test_layout_dm_deps() { concat!("Alignment of ", stringify!(dm_deps)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).count) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).count) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -70,10 +68,7 @@ fn bindgen_test_layout_dm_deps() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).filler) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).filler) as usize - ptr as usize }, 4usize, concat!( "Offset of field: ", @@ -83,10 +78,7 @@ fn bindgen_test_layout_dm_deps() { ) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).device) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).device) as usize - ptr as usize }, 8usize, concat!( "Offset of field: ", diff --git a/tests/expectations/tests/zero-sized-array.rs b/tests/expectations/tests/zero-sized-array.rs index 358164d325..4ba52498c4 100644 --- a/tests/expectations/tests/zero-sized-array.rs +++ b/tests/expectations/tests/zero-sized-array.rs @@ -45,6 +45,7 @@ pub struct ZeroSizedArray { fn bindgen_test_layout_ZeroSizedArray() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 0usize, @@ -56,10 +57,7 @@ fn bindgen_test_layout_ZeroSizedArray() { concat!("Alignment of ", stringify!(ZeroSizedArray)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", @@ -79,6 +77,7 @@ pub struct ContainsZeroSizedArray { fn bindgen_test_layout_ContainsZeroSizedArray() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 0usize, @@ -90,10 +89,7 @@ fn bindgen_test_layout_ContainsZeroSizedArray() { concat!("Alignment of ", stringify!(ContainsZeroSizedArray)) ); assert_eq!( - unsafe { - let ptr = UNINIT.as_ptr(); - ::std::ptr::addr_of!((*ptr).zsa) as usize - ptr as usize - }, + unsafe { ::std::ptr::addr_of!((*ptr).zsa) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", From 6df6d0ad998af04479108b4701c014e5343e917e Mon Sep 17 00:00:00 2001 From: onalante-msft <89409054+onalante-msft@users.noreply.github.com> Date: Fri, 15 Jul 2022 22:19:04 -0700 Subject: [PATCH 315/942] Add revision suggestion for MSRV >= 1.59.0 --- src/codegen/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 80c73bbc3d..6bbb7ab591 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -2202,6 +2202,8 @@ impl CodeGenerator for CompInfo { }; let uninit_decl = if !check_field_offset.is_empty() { + // FIXME: When MSRV >= 1.59.0, we can use + // > const PTR: *const #canonical_ident = ::#prefix::mem::MaybeUninit::uninit().as_ptr(); Some(quote! { // Use a shared MaybeUninit so that rustc with // opt-level=0 doesn't take too much stack space, From ae1ce7d12813c6b8ff36ebd0a7a92f81e4930eec Mon Sep 17 00:00:00 2001 From: Jim Blandy Date: Sat, 16 Jul 2022 12:20:11 -0700 Subject: [PATCH 316/942] Don't use `Arg::takes_value` when it's implied by other calls. Both `Arg::value_name` and `Arg::number_of_values` imply `Arg::takes_value`, so those calls are just noise. --- src/options.rs | 36 +++--------------------------------- 1 file changed, 3 insertions(+), 33 deletions(-) diff --git a/src/options.rs b/src/options.rs index 4e1fb93fbe..a11f3ddd7c 100644 --- a/src/options.rs +++ b/src/options.rs @@ -55,21 +55,18 @@ where bitfield flags.", ) .value_name("regex") - .takes_value(true) .multiple_occurrences(true) .number_of_values(1), Arg::new("newtype-enum") .long("newtype-enum") .help("Mark any enum whose name matches as a newtype.") .value_name("regex") - .takes_value(true) .multiple_occurrences(true) .number_of_values(1), Arg::new("rustified-enum") .long("rustified-enum") .help("Mark any enum whose name matches as a Rust enum.") .value_name("regex") - .takes_value(true) .multiple_occurrences(true) .number_of_values(1), Arg::new("constified-enum") @@ -79,7 +76,6 @@ where constants.", ) .value_name("regex") - .takes_value(true) .multiple_occurrences(true) .number_of_values(1), Arg::new("constified-enum-module") @@ -89,7 +85,6 @@ where constants.", ) .value_name("regex") - .takes_value(true) .multiple_occurrences(true) .number_of_values(1), Arg::new("default-macro-constant-type") @@ -117,7 +112,6 @@ where normal type aliasing.", ) .value_name("regex") - .takes_value(true) .multiple_occurrences(true) .number_of_values(1), Arg::new("new-type-alias") @@ -127,7 +121,6 @@ where a new type generated for it.", ) .value_name("regex") - .takes_value(true) .multiple_occurrences(true) .number_of_values(1), Arg::new("new-type-alias-deref") @@ -137,7 +130,6 @@ where a new type with Deref and DerefMut to the inner type.", ) .value_name("regex") - .takes_value(true) .multiple_occurrences(true) .number_of_values(1), Arg::new("blocklist-type") @@ -145,7 +137,6 @@ where .long("blocklist-type") .help("Mark as hidden.") .value_name("type") - .takes_value(true) .multiple_occurrences(true) .number_of_values(1), Arg::new("blocklist-function") @@ -153,7 +144,6 @@ where .long("blocklist-function") .help("Mark as hidden.") .value_name("function") - .takes_value(true) .multiple_occurrences(true) .number_of_values(1), Arg::new("blocklist-item") @@ -161,7 +151,6 @@ where .long("blocklist-item") .help("Mark as hidden.") .value_name("item") - .takes_value(true) .multiple_occurrences(true) .number_of_values(1), Arg::new("blocklist-file") @@ -169,7 +158,6 @@ where .long("blocklist-file") .help("Mark all contents of as hidden.") .value_name("path") - .takes_value(true) .multiple_occurrences(true) .number_of_values(1), Arg::new("no-layout-tests") @@ -256,14 +244,12 @@ where "Use the given prefix before raw types instead of \ ::std::os::raw.", ) - .value_name("prefix") - .takes_value(true), + .value_name("prefix"), Arg::new("anon-fields-prefix") .long("anon-fields-prefix") .help("Use the given prefix for the anon fields.") .value_name("prefix") - .default_value(DEFAULT_ANON_FIELDS_PREFIX) - .takes_value(true), + .default_value(DEFAULT_ANON_FIELDS_PREFIX), Arg::new("time-phases") .long("time-phases") .help("Time the different bindgen phases and print to stderr"), @@ -278,8 +264,7 @@ where Arg::new("emit-ir-graphviz") .long("emit-ir-graphviz") .help("Dump graphviz dot file.") - .value_name("path") - .takes_value(true), + .value_name("path"), Arg::new("enable-cxx-namespaces") .long("enable-cxx-namespaces") .help("Enable support for C++ namespaces."), @@ -343,7 +328,6 @@ where .long("opaque-type") .help("Mark as opaque.") .value_name("type") - .takes_value(true) .multiple_occurrences(true) .number_of_values(1), Arg::new("output") @@ -354,13 +338,11 @@ where Arg::new("raw-line") .long("raw-line") .help("Add a raw line of Rust code at the beginning of output.") - .takes_value(true) .multiple_occurrences(true) .number_of_values(1), Arg::new("module-raw-line") .long("module-raw-line") .help("Add a raw line of Rust code to a given module.") - .takes_value(true) .multiple_occurrences(true) .number_of_values(2) .value_names(&["module-name", "raw-line"]), @@ -389,7 +371,6 @@ where generated.", ) .value_name("regex") - .takes_value(true) .multiple_occurrences(true) .number_of_values(1), Arg::new("generate-inline-functions") @@ -403,7 +384,6 @@ where not be generated.", ) .value_name("regex") - .takes_value(true) .multiple_occurrences(true) .number_of_values(1), Arg::new("allowlist-var") @@ -415,7 +395,6 @@ where generated.", ) .value_name("regex") - .takes_value(true) .multiple_occurrences(true) .number_of_values(1), Arg::new("allowlist-file") @@ -423,7 +402,6 @@ where .long("allowlist-file") .help("Allowlist all contents of .") .value_name("path") - .takes_value(true) .multiple_occurrences(true) .number_of_values(1), Arg::new("verbose") @@ -464,49 +442,42 @@ where This parameter is incompatible with --no-rustfmt-bindings.", ) .value_name("path") - .takes_value(true) .multiple_occurrences(false) .number_of_values(1), Arg::new("no-partialeq") .long("no-partialeq") .help("Avoid deriving PartialEq for types matching .") .value_name("regex") - .takes_value(true) .multiple_occurrences(true) .number_of_values(1), Arg::new("no-copy") .long("no-copy") .help("Avoid deriving Copy for types matching .") .value_name("regex") - .takes_value(true) .multiple_occurrences(true) .number_of_values(1), Arg::new("no-debug") .long("no-debug") .help("Avoid deriving Debug for types matching .") .value_name("regex") - .takes_value(true) .multiple_occurrences(true) .number_of_values(1), Arg::new("no-default") .long("no-default") .help("Avoid deriving/implement Default for types matching .") .value_name("regex") - .takes_value(true) .multiple_occurrences(true) .number_of_values(1), Arg::new("no-hash") .long("no-hash") .help("Avoid deriving Hash for types matching .") .value_name("regex") - .takes_value(true) .multiple_occurrences(true) .number_of_values(1), Arg::new("must-use-type") .long("must-use-type") .help("Add #[must_use] annotation to types matching .") .value_name("regex") - .takes_value(true) .multiple_occurrences(true) .number_of_values(1), Arg::new("enable-function-attribute-detection") @@ -521,7 +492,6 @@ where Arg::new("wasm-import-module-name") .long("wasm-import-module-name") .value_name("name") - .takes_value(true) .help("The name to be used in a #[link(wasm_import_module = ...)] statement"), Arg::new("dynamic-loading") .long("dynamic-loading") From 87e2e91356d52ba8aaa32cf3d06a2dd978740bc8 Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Sat, 16 Jul 2022 21:18:59 -0400 Subject: [PATCH 317/942] Bump MSRV to 1.57.0 --- .github/workflows/bindgen.yml | 4 ++-- Cargo.toml | 2 +- README.md | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 3e2234133a..6adbb5dae2 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -48,11 +48,11 @@ jobs: profile: minimal # MSRV below is documented in Cargo.toml and README.md, please update those if you # change this. - toolchain: 1.56.1 + toolchain: 1.57.0 override: true - name: Build with msrv - run: rm Cargo.lock && cargo +1.56.1 build --lib + run: rm Cargo.lock && cargo +1.57.0 build --lib quickchecking: runs-on: ubuntu-latest diff --git a/Cargo.toml b/Cargo.toml index 2e18545dd9..ed7571ae99 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ version = "0.60.1" edition = "2018" build = "build.rs" # If you change this, also update README.md and msrv in .github/workflows/bindgen.yml -rust-version = "1.56.1" +rust-version = "1.57.0" include = [ "LICENSE", diff --git a/README.md b/README.md index 3ae5f96733..9e2cf10bf6 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ extern "C" { ## MSRV -The minimum supported Rust version is **1.56.1**. +The minimum supported Rust version is **1.57.0**. No MSRV bump policy has been established yet, so MSRV may increase in any release. From dcc78bd279571b2c209abbfb1aa2c493809989b7 Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Sat, 16 Jul 2022 21:37:32 -0400 Subject: [PATCH 318/942] Update clap and its dependencies cargo update --package=clap --aggressive --- Cargo.lock | 54 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e054462774..0c7c2f7851 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -24,9 +24,9 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bindgen" @@ -53,9 +53,9 @@ dependencies = [ [[package]] name = "bitflags" -version = "1.2.1" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "cexpr" @@ -85,19 +85,28 @@ dependencies = [ [[package]] name = "clap" -version = "3.0.4" +version = "3.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d01c9347757e131122b19cd19a05c85805b68c2352a97b623efdc3c295290299" +checksum = "ab8b79fe3946ceb4a0b1c080b4018992b8d27e9ff363644c1c9b6387c854614d" dependencies = [ "atty", "bitflags", + "clap_lex", "indexmap", - "os_str_bytes", "strsim", "termcolor", "textwrap", ] +[[package]] +name = "clap_lex" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +dependencies = [ + "os_str_bytes", +] + [[package]] name = "diff" version = "0.1.12" @@ -142,9 +151,9 @@ checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" [[package]] name = "hashbrown" -version = "0.11.2" +version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" +checksum = "607c8a29735385251a339424dd462993c0fed8fa09d378f259377df08c126022" [[package]] name = "hermit-abi" @@ -163,9 +172,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "indexmap" -version = "1.7.0" +version = "1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5" +checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" dependencies = [ "autocfg", "hashbrown", @@ -185,9 +194,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.98" +version = "0.2.126" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "320cfe77175da3a483efed4bc0adc1968ca050b098ce4f2f1c13a56626128790" +checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" [[package]] name = "libloading" @@ -210,9 +219,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.4.1" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "minimal-lexical" @@ -233,12 +242,9 @@ dependencies = [ [[package]] name = "os_str_bytes" -version = "6.0.0" +version = "6.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64" -dependencies = [ - "memchr", -] +checksum = "648001efe5d5c0102d8cea768e348da85d90af8ba91f0bea908f157951493cd4" [[package]] name = "peeking_take_while" @@ -379,18 +385,18 @@ dependencies = [ [[package]] name = "termcolor" -version = "1.1.2" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" dependencies = [ "winapi-util", ] [[package]] name = "textwrap" -version = "0.14.2" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80" +checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" [[package]] name = "unicode-xid" From 105b9422cd5f8cd7aca9def458c157be219a03ff Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Sat, 16 Jul 2022 21:39:15 -0400 Subject: [PATCH 319/942] Mark update to clap in CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 17b3223723..1b9b164ae9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -145,6 +145,8 @@ ## Changed + * clap has been updated, new msrv is 1.57. + ## Removed ## Fixed From ef2ee38f3a1a2e0d169a610b9bd7bf52ea966059 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 25 Jul 2022 11:17:11 +0200 Subject: [PATCH 320/942] ty: Use canonical type to access pointee. Using the canonical type fixes this but changes the output of some tests (in particular, pointer to typedefs now point to the underlying type). So do this only in known-bad cases. Fixes #2244 --- src/ir/ty.rs | 11 ++++++++++- tests/expectations/tests/pointer-attr.rs | 10 ++++++++++ tests/headers/pointer-attr.h | 1 + 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 tests/expectations/tests/pointer-attr.rs create mode 100644 tests/headers/pointer-attr.h diff --git a/src/ir/ty.rs b/src/ir/ty.rs index d573408c3b..38ab4564bd 100644 --- a/src/ir/ty.rs +++ b/src/ir/ty.rs @@ -1031,7 +1031,16 @@ impl Type { CXType_ObjCObjectPointer | CXType_MemberPointer | CXType_Pointer => { - let pointee = ty.pointee_type().unwrap(); + let mut pointee = ty.pointee_type().unwrap(); + if *ty != canonical_ty { + let canonical_pointee = + canonical_ty.pointee_type().unwrap(); + // clang sometimes loses pointee constness here, see + // #2244. + if canonical_pointee.is_const() != pointee.is_const() { + pointee = canonical_pointee; + } + } let inner = Item::from_ty_or_ref(pointee, location, None, ctx); TypeKind::Pointer(inner) diff --git a/tests/expectations/tests/pointer-attr.rs b/tests/expectations/tests/pointer-attr.rs new file mode 100644 index 0000000000..95fe9c5f0d --- /dev/null +++ b/tests/expectations/tests/pointer-attr.rs @@ -0,0 +1,10 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +extern "C" { + pub fn a(arg1: *const ::std::os::raw::c_char); +} diff --git a/tests/headers/pointer-attr.h b/tests/headers/pointer-attr.h new file mode 100644 index 0000000000..fe0004b8bf --- /dev/null +++ b/tests/headers/pointer-attr.h @@ -0,0 +1 @@ +void a(const char __attribute__((btf_type_tag("a"))) *); From 4093e870c091438dbb9b6bbd7d5095ee3bda5359 Mon Sep 17 00:00:00 2001 From: "Bryn M. Reeves" Date: Tue, 26 Jul 2022 15:48:06 +0100 Subject: [PATCH 321/942] adds 'await' to list of matches in 'rust_mangle' --- src/ir/context.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ir/context.rs b/src/ir/context.rs index 3bfe549b28..36d7eedb1e 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -821,7 +821,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" name.contains('$') || matches!( name, - "abstract" | "alignof" | "as" | "async" | "become" | + "abstract" | "alignof" | "as" | "async" | "await" | "become" | "box" | "break" | "const" | "continue" | "crate" | "do" | "dyn" | "else" | "enum" | "extern" | "false" | "final" | "fn" | "for" | "if" | "impl" | "in" | "let" | "loop" | From b18bf798bef43c65af98520f9b58b6810aa2b17b Mon Sep 17 00:00:00 2001 From: "Bryn M. Reeves" Date: Mon, 1 Aug 2022 12:17:21 +0100 Subject: [PATCH 322/942] Add test coverage for 'await' and 'async' keywords Add declarations for 'await' and 'async' variables to keywords.h and update the expectations in keywords.rs. --- tests/expectations/tests/keywords.rs | 8 ++++++++ tests/headers/keywords.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/tests/expectations/tests/keywords.rs b/tests/expectations/tests/keywords.rs index 055b0f003e..a1e7f877e1 100644 --- a/tests/expectations/tests/keywords.rs +++ b/tests/expectations/tests/keywords.rs @@ -69,6 +69,14 @@ extern "C" { #[link_name = "\u{1}as"] pub static mut as_: ::std::os::raw::c_int; } +extern "C" { + #[link_name = "\u{1}async"] + pub static mut async_: ::std::os::raw::c_int; +} +extern "C" { + #[link_name = "\u{1}await"] + pub static mut await_: ::std::os::raw::c_int; +} extern "C" { #[link_name = "\u{1}box"] pub static mut box_: ::std::os::raw::c_int; diff --git a/tests/headers/keywords.h b/tests/headers/keywords.h index d7fe2065b0..3b3fc4976e 100644 --- a/tests/headers/keywords.h +++ b/tests/headers/keywords.h @@ -15,6 +15,8 @@ int str; int dyn; int as; +int async; +int await; int box; int crate; int false; From 50878f37e639b8c868adec8a8c745e788c2d870a Mon Sep 17 00:00:00 2001 From: Amanjeev Sethi Date: Thu, 11 Aug 2022 15:14:23 -0400 Subject: [PATCH 323/942] docs(CONTRIBUTING): add a note for single test run test-one.sh needs to run `dot` command which is installed via Graphviz. Else, running the script throws error - `dot` command not found. --- CONTRIBUTING.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0ffd5b4fea..3fe7539f5f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -152,6 +152,9 @@ $ cargo test ### Testing a Single Header's Bindings Generation and Compiling its Bindings +Note: You will to need to install [Graphviz](https://graphviz.org/) since that +is a dependency for running `test-one.sh`. + Sometimes its useful to work with one test header from start (generating bindings for it) to finish (compiling the bindings and running their layout tests). This can be done with the `tests/test-one.sh` script. It supports fuzzy From 15a720bafa435d95cfb4896beeb1140bc0536595 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Wed, 10 Aug 2022 12:51:38 -0500 Subject: [PATCH 324/942] store warnings and emit them later --- src/codegen/mod.rs | 2 +- src/ir/context.rs | 27 ++++++++++++++++++++++----- src/lib.rs | 23 ++++++++++++++++++++++- 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 6bbb7ab591..77e9ba950d 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -4329,7 +4329,7 @@ impl CodeGenerator for ObjCInterface { pub(crate) fn codegen( context: BindgenContext, -) -> (Vec, BindgenOptions) { +) -> (Vec, BindgenOptions, Vec) { context.gen(|context| { let _t = context.timer("codegen"); let counter = Cell::new(0); diff --git a/src/ir/context.rs b/src/ir/context.rs index 36d7eedb1e..61fa8439eb 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -459,6 +459,9 @@ pub struct BindgenContext { /// Populated when we enter codegen by `compute_has_float`; always `None` /// before that and `Some` after. has_float: Option>, + + /// The set of warnings raised during binding generation. + warnings: Vec, } /// A traversal of allowlisted items. @@ -579,6 +582,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" have_destructor: None, has_type_param_in_array: None, has_float: None, + warnings: Vec::new(), } } @@ -1134,7 +1138,10 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// Enter the code generation phase, invoke the given callback `cb`, and /// leave the code generation phase. - pub(crate) fn gen(mut self, cb: F) -> (Out, BindgenOptions) + pub(crate) fn gen( + mut self, + cb: F, + ) -> (Out, BindgenOptions, Vec) where F: FnOnce(&Self) -> Out, { @@ -1171,7 +1178,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" self.compute_cannot_derive_partialord_partialeq_or_eq(); let ret = cb(&self); - (ret, self.options) + (ret, self.options, self.warnings) } /// When the `testing_only_extra_assertions` feature is enabled, this @@ -2430,17 +2437,27 @@ If you encounter an error missing from this list, please file an issue or a PR!" self.allowlisted = Some(allowlisted); self.codegen_items = Some(codegen_items); + let mut warnings = Vec::new(); + for item in self.options().allowlisted_functions.unmatched_items() { - warn!("unused option: --allowlist-function {}", item); + let warn = format!("unused option: --allowlist-function {}", item); + warn!("{}", warn); + warnings.push(warn); } for item in self.options().allowlisted_vars.unmatched_items() { - warn!("unused option: --allowlist-var {}", item); + let warn = format!("unused option: --allowlist-var {}", item); + warn!("{}", warn); + warnings.push(warn); } for item in self.options().allowlisted_types.unmatched_items() { - warn!("unused option: --allowlist-type {}", item); + let warn = format!("unused option: --allowlist-type {}", item); + warn!("{}", warn); + warnings.push(warn); } + + self.warnings.extend(warnings); } /// Convenient method for getting the prefix to use for most traits in diff --git a/src/lib.rs b/src/lib.rs index 3d09ab71f1..cbcf65e3af 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,6 +33,19 @@ mod log_stubs; #[macro_use] mod extra_assertions; +/// Print all the warning messages raised while generating the bindings in a build script. +/// +/// If you are using `bindgen` outside of a build script you should use [`Bindings::take_warnings`] +/// directly instead. +#[macro_export] +macro_rules! print_warnings { + ($bindings:expr) => { + for message in $bindings.take_warnings() { + println!("cargo:warning={}", message); + } + }; +} + // A macro to declare an internal module for which we *must* provide // documentation for. If we are building with the "testing_only_docs" feature, // then the module is declared public, and our `#![deny(missing_docs)]` pragma @@ -2222,6 +2235,7 @@ impl std::error::Error for BindgenError {} #[derive(Debug)] pub struct Bindings { options: BindgenOptions, + warnings: Vec, module: proc_macro2::TokenStream, } @@ -2435,10 +2449,11 @@ impl Bindings { parse(&mut context)?; } - let (items, options) = codegen::codegen(context); + let (items, options, warnings) = codegen::codegen(context); Ok(Bindings { options, + warnings, module: quote! { #( #items )* }, @@ -2583,6 +2598,12 @@ impl Bindings { _ => Ok(Cow::Owned(source)), } } + + /// Take all the warning messages. + #[inline] + pub fn take_warnings(&mut self) -> impl Iterator + '_ { + self.warnings.drain(..) + } } impl std::fmt::Display for Bindings { From c5995bda24d628ddecda8bbe10db9b4415cc973a Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Fri, 12 Aug 2022 13:36:16 -0500 Subject: [PATCH 325/942] test warning emission --- tests/expectations/tests/allowlist_warnings.rs | 6 ++++++ tests/headers/allowlist_warnings.h | 2 ++ tests/tests.rs | 16 ++++++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 tests/expectations/tests/allowlist_warnings.rs create mode 100644 tests/headers/allowlist_warnings.h diff --git a/tests/expectations/tests/allowlist_warnings.rs b/tests/expectations/tests/allowlist_warnings.rs new file mode 100644 index 0000000000..131dbdf39f --- /dev/null +++ b/tests/expectations/tests/allowlist_warnings.rs @@ -0,0 +1,6 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] diff --git a/tests/headers/allowlist_warnings.h b/tests/headers/allowlist_warnings.h new file mode 100644 index 0000000000..83c9e259f0 --- /dev/null +++ b/tests/headers/allowlist_warnings.h @@ -0,0 +1,2 @@ +// bindgen-flags: --allowlist-function "doesnt_match_anything" +int non_matched_function(int arg); diff --git a/tests/tests.rs b/tests/tests.rs index cc64cfdd29..7b46df5ea2 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -670,3 +670,19 @@ fn dump_preprocessed_input() { "cpp-empty-layout.hpp is in the preprocessed file" ); } + +#[test] +fn allowlist_warnings() { + let header = concat!( + env!("CARGO_MANIFEST_DIR"), + "/tests/headers/allowlist_warnings.h" + ); + + let mut bindings = builder() + .header(header) + .allowlist_function("doesnt_match_anything") + .generate() + .expect("unable to generate bindings"); + + assert_eq!(1, bindings.take_warnings().count()); +} From bc19e553da2e5c89470f413b1e07e4c9a5647b58 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Tue, 16 Aug 2022 11:24:06 -0500 Subject: [PATCH 326/942] remove macro in favor of a method --- src/lib.rs | 30 ++++++++++++++---------------- tests/tests.rs | 4 ++-- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index cbcf65e3af..c102c47d69 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,19 +33,6 @@ mod log_stubs; #[macro_use] mod extra_assertions; -/// Print all the warning messages raised while generating the bindings in a build script. -/// -/// If you are using `bindgen` outside of a build script you should use [`Bindings::take_warnings`] -/// directly instead. -#[macro_export] -macro_rules! print_warnings { - ($bindings:expr) => { - for message in $bindings.take_warnings() { - println!("cargo:warning={}", message); - } - }; -} - // A macro to declare an internal module for which we *must* provide // documentation for. If we are building with the "testing_only_docs" feature, // then the module is declared public, and our `#![deny(missing_docs)]` pragma @@ -2599,10 +2586,21 @@ impl Bindings { } } - /// Take all the warning messages. + /// Emit all the warning messages raised while generating the bindings in a build script. + /// + /// If you are using `bindgen` outside of a build script you should use [`Bindings::warnings`] + /// and handle the messages accordingly instead. + #[inline] + pub fn emit_warnings(&self) { + for message in &self.warnings { + println!("cargo:warning={}", message); + } + } + + /// Return all the warning messages raised while generating the bindings. #[inline] - pub fn take_warnings(&mut self) -> impl Iterator + '_ { - self.warnings.drain(..) + pub fn warnings(&self) -> &[String] { + &self.warnings } } diff --git a/tests/tests.rs b/tests/tests.rs index 7b46df5ea2..71fc54be13 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -678,11 +678,11 @@ fn allowlist_warnings() { "/tests/headers/allowlist_warnings.h" ); - let mut bindings = builder() + let bindings = builder() .header(header) .allowlist_function("doesnt_match_anything") .generate() .expect("unable to generate bindings"); - assert_eq!(1, bindings.take_warnings().count()); + assert_eq!(1, bindings.warnings().len()); } From 89269026daae91c29aa555ffd3fe978741f88032 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Tue, 16 Aug 2022 11:36:40 -0500 Subject: [PATCH 327/942] emit warnings later --- src/ir/context.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/ir/context.rs b/src/ir/context.rs index 61fa8439eb..a91d522412 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -2440,24 +2440,21 @@ If you encounter an error missing from this list, please file an issue or a PR!" let mut warnings = Vec::new(); for item in self.options().allowlisted_functions.unmatched_items() { - let warn = format!("unused option: --allowlist-function {}", item); - warn!("{}", warn); - warnings.push(warn); + warnings.push(format!("unused option: --allowlist-function {}", item)); } for item in self.options().allowlisted_vars.unmatched_items() { - let warn = format!("unused option: --allowlist-var {}", item); - warn!("{}", warn); - warnings.push(warn); + warnings.push(format!("unused option: --allowlist-var {}", item)); } for item in self.options().allowlisted_types.unmatched_items() { - let warn = format!("unused option: --allowlist-type {}", item); - warn!("{}", warn); - warnings.push(warn); + warnings.push(format!("unused option: --allowlist-type {}", item)); } - self.warnings.extend(warnings); + for msg in warnings { + warn!("{}", msg); + self.warnings.push(msg); + } } /// Convenient method for getting the prefix to use for most traits in From ebb1ce98c6e92ce2384a5867bdcfeb933ed12433 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Tue, 16 Aug 2022 11:39:23 -0500 Subject: [PATCH 328/942] rustfmt --- src/ir/context.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ir/context.rs b/src/ir/context.rs index a91d522412..aa03b209cc 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -2440,7 +2440,8 @@ If you encounter an error missing from this list, please file an issue or a PR!" let mut warnings = Vec::new(); for item in self.options().allowlisted_functions.unmatched_items() { - warnings.push(format!("unused option: --allowlist-function {}", item)); + warnings + .push(format!("unused option: --allowlist-function {}", item)); } for item in self.options().allowlisted_vars.unmatched_items() { From 6dfc3e70df1676a3321cb83624f7c83db6fb92df Mon Sep 17 00:00:00 2001 From: Amanjeev Sethi Date: Wed, 24 Aug 2022 18:45:03 -0400 Subject: [PATCH 329/942] Sorting the output semantically (#2254) Generated code needs some sorting in a way that is semantically appealing. The request[1] asks for basic sorting like "types are declared first, then all structs, then all consts, then all function signatures, etc. [1] https://github.com/rust-lang/rust-bindgen/issues/1743 Signed-off-by: Amanjeev Sethi Co-authored-by: Christian Poveda Co-authored-by: Darren Kulp --- CHANGELOG.md | 4 ++ Cargo.lock | 24 +++++-- Cargo.toml | 1 + src/lib.rs | 71 +++++++++++++++++++ src/options.rs | 7 ++ tests/expectations/tests/sorted-items.rs | 82 ++++++++++++++++++++++ tests/expectations/tests/unsorted-items.rs | 82 ++++++++++++++++++++++ tests/headers/sorted-items.h | 17 +++++ tests/headers/unsorted-items.h | 15 ++++ 9 files changed, 297 insertions(+), 6 deletions(-) create mode 100644 tests/expectations/tests/sorted-items.rs create mode 100644 tests/expectations/tests/unsorted-items.rs create mode 100644 tests/headers/sorted-items.h create mode 100644 tests/headers/unsorted-items.h diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b9b164ae9..6c2e64e670 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -143,6 +143,8 @@ ## Added + * new feature: `--sort-semantically` flag to sort the output in a predefined manner [(#1743)] + ## Changed * clap has been updated, new msrv is 1.57. @@ -153,6 +155,8 @@ ## Security +[(#1743)]: https://github.com/rust-lang/rust-bindgen/issues/1743 + # 0.60.1 Released 2022/06/06 diff --git a/Cargo.lock b/Cargo.lock index 0c7c2f7851..fa908ea9d7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -47,6 +47,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", + "syn", "tempfile", "which", ] @@ -260,11 +261,11 @@ checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" [[package]] name = "proc-macro2" -version = "1.0.28" +version = "1.0.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c7ed8b8c7b886ea3ed7dde405212185f423ab44682667c8c6dd14aa1d9f6612" +checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab" dependencies = [ - "unicode-xid", + "unicode-ident", ] [[package]] @@ -369,6 +370,17 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +[[package]] +name = "syn" +version = "1.0.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58dbef6ec655055e20b86b15a8cc6d439cca19b667537ac6a1369572d151ab13" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "tempfile" version = "3.2.0" @@ -399,10 +411,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" [[package]] -name = "unicode-xid" -version = "0.2.2" +name = "unicode-ident" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" +checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" [[package]] name = "version_check" diff --git a/Cargo.toml b/Cargo.toml index ed7571ae99..311110b3ec 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -57,6 +57,7 @@ lazycell = "1" lazy_static = "1" peeking_take_while = "0.1.2" quote = { version = "1", default-features = false } +syn = { version = "1.0.99", features = ["full", "extra-traits"]} regex = { version = "1.5", default-features = false , features = ["std", "unicode"] } which = { version = "4.2.1", optional = true, default-features = false } shlex = "1" diff --git a/src/lib.rs b/src/lib.rs index c102c47d69..b90faba613 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -86,6 +86,7 @@ use std::{env, iter}; // Some convenient typedefs for a fast hash map and hash set. type HashMap = ::rustc_hash::FxHashMap; type HashSet = ::rustc_hash::FxHashSet; +use quote::ToTokens; pub(crate) use std::collections::hash_map::Entry; /// Default prefix for the anon fields. @@ -587,6 +588,10 @@ impl Builder { output_vector.push("--vtable-generation".into()); } + if self.options.sort_semantically { + output_vector.push("--sort-semantically".into()); + } + // Add clang arguments output_vector.push("--".into()); @@ -1476,6 +1481,14 @@ impl Builder { self } + /// If true, enables the sorting of the output in a predefined manner + /// + /// TODO: Perhaps move the sorting order out into a config + pub fn sort_semantically(mut self, doit: bool) -> Self { + self.options.sort_semantically = doit; + self + } + /// Generate the Rust bindings using the options built up thus far. pub fn generate(mut self) -> Result { // Add any extra arguments from the environment to the clang command line. @@ -2005,6 +2018,9 @@ struct BindgenOptions { /// Emit vtable functions. vtable_generation: bool, + + /// Sort the code generation + sort_semantically: bool, } /// TODO(emilio): This is sort of a lie (see the error message that results from @@ -2153,6 +2169,7 @@ impl Default for BindgenOptions { c_naming: false, force_explicit_padding: false, vtable_generation: false, + sort_semantically: false, } } } @@ -2438,6 +2455,60 @@ impl Bindings { let (items, options, warnings) = codegen::codegen(context); + if options.sort_semantically { + let module_wrapped_tokens = + quote!(mod wrapper_for_sorting_hack { #( #items )* }); + + // This semantically sorting business is a hack, for now. This means that we are + // re-parsing already generated code using `syn` (as opposed to `quote`) because + // `syn` provides us more control over the elements. + // One caveat is that some of the items coming from `quote`d output might have + // multiple items within them. Hence, we have to wrap the incoming in a `mod`. + // The two `unwrap`s here are deliberate because + // The first one won't panic because we build the `mod` and know it is there + // The second one won't panic because we know original output has something in + // it already. + let mut syn_parsed_items = + syn::parse2::(module_wrapped_tokens) + .unwrap() + .content + .unwrap() + .1; + + syn_parsed_items.sort_by_key(|item| match item { + syn::Item::Type(_) => 0, + syn::Item::Struct(_) => 1, + syn::Item::Const(_) => 2, + syn::Item::Fn(_) => 3, + syn::Item::Enum(_) => 4, + syn::Item::Union(_) => 5, + syn::Item::Static(_) => 6, + syn::Item::Trait(_) => 7, + syn::Item::TraitAlias(_) => 8, + syn::Item::Impl(_) => 9, + syn::Item::Mod(_) => 10, + syn::Item::Use(_) => 11, + syn::Item::Verbatim(_) => 12, + syn::Item::ExternCrate(_) => 13, + syn::Item::ForeignMod(_) => 14, + syn::Item::Macro(_) => 15, + syn::Item::Macro2(_) => 16, + _ => 18, + }); + + let synful_items = syn_parsed_items + .into_iter() + .map(|item| item.into_token_stream()); + + return Ok(Bindings { + options, + warnings, + module: quote! { + #( #synful_items )* + }, + }); + } + Ok(Bindings { options, warnings, diff --git a/src/options.rs b/src/options.rs index a11f3ddd7c..83da21f42f 100644 --- a/src/options.rs +++ b/src/options.rs @@ -515,6 +515,9 @@ where Arg::new("vtable-generation") .long("vtable-generation") .help("Enables generation of vtable functions."), + Arg::new("sort-semantically") + .long("sort-semantically") + .help("Enables sorting of code generation in a predefined manner."), Arg::new("V") .long("version") .help("Prints the version, and exits"), @@ -1000,5 +1003,9 @@ where builder = builder.vtable_generation(true); } + if matches.is_present("sort-semantically") { + builder = builder.sort_semantically(true); + } + Ok((builder, output, verbose)) } diff --git a/tests/expectations/tests/sorted-items.rs b/tests/expectations/tests/sorted-items.rs new file mode 100644 index 0000000000..7df7c3d71e --- /dev/null +++ b/tests/expectations/tests/sorted-items.rs @@ -0,0 +1,82 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +pub type number = ::std::os::raw::c_int; +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Point { + pub x: number, + pub y: number, +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Angle { + pub a: number, + pub b: number, +} +pub const NUMBER: number = 42; +#[test] +fn bindgen_test_layout_Point() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Point)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Point)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Point), "::", stringify!(x)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(Point), "::", stringify!(y)) + ); +} +#[test] +fn bindgen_test_layout_Angle() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Angle)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Angle)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Angle), "::", stringify!(a)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(Angle), "::", stringify!(b)) + ); +} +extern "C" { + pub fn foo() -> ::std::os::raw::c_int; +} +extern "C" { + pub fn bar(x: number) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn baz(point: Point) -> ::std::os::raw::c_int; +} diff --git a/tests/expectations/tests/unsorted-items.rs b/tests/expectations/tests/unsorted-items.rs new file mode 100644 index 0000000000..ce0c5f3f66 --- /dev/null +++ b/tests/expectations/tests/unsorted-items.rs @@ -0,0 +1,82 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +extern "C" { + pub fn foo() -> ::std::os::raw::c_int; +} +pub type number = ::std::os::raw::c_int; +extern "C" { + pub fn bar(x: number) -> ::std::os::raw::c_int; +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Point { + pub x: number, + pub y: number, +} +#[test] +fn bindgen_test_layout_Point() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Point)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Point)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Point), "::", stringify!(x)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(Point), "::", stringify!(y)) + ); +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Angle { + pub a: number, + pub b: number, +} +#[test] +fn bindgen_test_layout_Angle() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Angle)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Angle)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Angle), "::", stringify!(a)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(Angle), "::", stringify!(b)) + ); +} +extern "C" { + pub fn baz(point: Point) -> ::std::os::raw::c_int; +} +pub const NUMBER: number = 42; diff --git a/tests/headers/sorted-items.h b/tests/headers/sorted-items.h new file mode 100644 index 0000000000..11fc2ef40b --- /dev/null +++ b/tests/headers/sorted-items.h @@ -0,0 +1,17 @@ +// bindgen-flags: --sort-semantically -- --target=x86_64-unknown-linux + +int foo(); +typedef int number; +int bar(number x); +struct Point +{ + number x; + number y; +}; +struct Angle +{ + number a; + number b; +}; +int baz(struct Point point); +const number NUMBER = 42; diff --git a/tests/headers/unsorted-items.h b/tests/headers/unsorted-items.h new file mode 100644 index 0000000000..23962d18d8 --- /dev/null +++ b/tests/headers/unsorted-items.h @@ -0,0 +1,15 @@ +int foo(); +typedef int number; +int bar(number x); +struct Point +{ + number x; + number y; +}; +struct Angle +{ + number a; + number b; +}; +int baz(struct Point point); +const number NUMBER = 42; From a5848cf44e02645cddf020609ea67340cf6e3d24 Mon Sep 17 00:00:00 2001 From: Collin Baker Date: Wed, 20 Jul 2022 11:57:16 -0400 Subject: [PATCH 330/942] Generate opaque type for template param dependent bit field width libclang's API does not provide a straightforward way to check for this, and calling clang_getFieldDeclBitWidth is actively unsafe in this case. See https://github.com/llvm/llvm-project/issues/56644 We probably can't generate reasonable bindings for such a type, so make the binding opaque. Ideally libclang would report if the bit width could not be evaluated. Unfortunately making such a change would mean bumping the minimum libclang version from 6.0 to 15.0. Instead, add logic to traverse the AST subtree starting from the field's bit width specifier looking for template parameters. If we find one, we make the resulting type opaque. --- src/clang.rs | 96 ++++++++++++++++++- src/ir/comp.rs | 26 ++++- ...issue-2239-template-dependent-bit-width.rs | 19 ++++ ...ssue-2239-template-dependent-bit-width.hpp | 10 ++ 4 files changed, 147 insertions(+), 4 deletions(-) create mode 100644 tests/expectations/tests/issue-2239-template-dependent-bit-width.rs create mode 100644 tests/headers/issue-2239-template-dependent-bit-width.hpp diff --git a/src/clang.rs b/src/clang.rs index 587cc0ba7d..00716a1bd5 100644 --- a/src/clang.rs +++ b/src/clang.rs @@ -276,6 +276,56 @@ impl Cursor { true } + /// Is the referent any kind of template parameter? + pub fn is_template_parameter(&self) -> bool { + match self.kind() { + CXCursor_TemplateTemplateParameter | + CXCursor_TemplateTypeParameter | + CXCursor_NonTypeTemplateParameter => true, + _ => false, + } + } + + /// Does the referent's type or value depend on a template parameter? + pub fn is_dependent_on_template_parameter(&self) -> bool { + fn visitor( + found_template_parameter: &mut bool, + cur: Cursor, + ) -> CXChildVisitResult { + // If we found a template parameter, it is dependent. + if cur.is_template_parameter() { + *found_template_parameter = true; + return CXChildVisit_Break; + } + + // Get the referent and traverse it as well. + if let Some(referenced) = cur.referenced() { + if referenced.is_template_parameter() { + *found_template_parameter = true; + return CXChildVisit_Break; + } + + referenced + .visit(|next| visitor(found_template_parameter, next)); + if *found_template_parameter { + return CXChildVisit_Break; + } + } + + // Continue traversing the AST at the original cursor. + CXChildVisit_Recurse + } + + if self.is_template_parameter() { + return true; + } + + let mut found_template_parameter = false; + self.visit(|next| visitor(&mut found_template_parameter, next)); + + found_template_parameter + } + /// Is this cursor pointing a valid referent? pub fn is_valid(&self) -> bool { unsafe { clang_isInvalid(self.kind()) == 0 } @@ -485,9 +535,45 @@ impl Cursor { !self.is_defaulted_function() } + /// Is the referent a bit field declaration? + pub fn is_bit_field(&self) -> bool { + unsafe { clang_Cursor_isBitField(self.x) != 0 } + } + + /// Get a cursor to the bit field's width expression, or `None` if it's not + /// a bit field. + pub fn bit_width_expr(&self) -> Option { + if !self.is_bit_field() { + return None; + } + + let mut result = None; + self.visit(|cur| { + // The first child may or may not be a TypeRef, depending on whether + // the field's type is builtin. Skip it. + if cur.kind() == CXCursor_TypeRef { + return CXChildVisit_Continue; + } + + // The next expression or literal is the bit width. + result = Some(cur); + + CXChildVisit_Break + }); + + result + } + /// Get the width of this cursor's referent bit field, or `None` if the - /// referent is not a bit field. + /// referent is not a bit field or if the width could not be evaluated. pub fn bit_width(&self) -> Option { + // It is not safe to check the bit width without ensuring it doesn't + // depend on a template parameter. See + // https://github.com/rust-lang/rust-bindgen/issues/2239 + if self.bit_width_expr()?.is_dependent_on_template_parameter() { + return None; + } + unsafe { let w = clang_getFieldDeclBitWidth(self.x); if w == -1 { @@ -1789,9 +1875,15 @@ pub fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult { format!(" {}number-of-template-args = {}", prefix, num), ); } - if let Some(width) = c.bit_width() { + + if c.is_bit_field() { + let width = match c.bit_width() { + Some(w) => w.to_string(), + None => "".to_string(), + }; print_indent(depth, format!(" {}bit-width = {}", prefix, width)); } + if let Some(ty) = c.enum_type() { print_indent( depth, diff --git a/src/ir/comp.rs b/src/ir/comp.rs index a221e52074..9808d5986b 100644 --- a/src/ir/comp.rs +++ b/src/ir/comp.rs @@ -1045,6 +1045,11 @@ pub struct CompInfo { /// size_t) has_non_type_template_params: bool, + /// Whether this type has a bit field member whose width couldn't be + /// evaluated (e.g. if it depends on a template parameter). We generate an + /// opaque type in this case. + has_unevaluable_bit_field_width: bool, + /// Whether we saw `__attribute__((packed))` on or within this type. packed_attr: bool, @@ -1078,6 +1083,7 @@ impl CompInfo { has_destructor: false, has_nonempty_base: false, has_non_type_template_params: false, + has_unevaluable_bit_field_width: false, packed_attr: false, found_unknown_attr: false, is_forward_declaration: false, @@ -1317,7 +1323,21 @@ impl CompInfo { } } - let bit_width = cur.bit_width(); + let bit_width = if cur.is_bit_field() { + let width = cur.bit_width(); + + // Make opaque type if the bit width couldn't be + // evaluated. + if width.is_none() { + ci.has_unevaluable_bit_field_width = true; + return CXChildVisit_Break; + } + + width + } else { + None + }; + let field_type = Item::from_ty_or_ref( cur.cur_type(), cur, @@ -1753,7 +1773,9 @@ impl IsOpaque for CompInfo { type Extra = Option; fn is_opaque(&self, ctx: &BindgenContext, layout: &Option) -> bool { - if self.has_non_type_template_params { + if self.has_non_type_template_params || + self.has_unevaluable_bit_field_width + { return true; } diff --git a/tests/expectations/tests/issue-2239-template-dependent-bit-width.rs b/tests/expectations/tests/issue-2239-template-dependent-bit-width.rs new file mode 100644 index 0000000000..75ec9e439e --- /dev/null +++ b/tests/expectations/tests/issue-2239-template-dependent-bit-width.rs @@ -0,0 +1,19 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct b { + pub _address: u8, +} +pub type b_td = a; +pub type b_ta = a; +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct b_foo { + pub _address: u8, +} diff --git a/tests/headers/issue-2239-template-dependent-bit-width.hpp b/tests/headers/issue-2239-template-dependent-bit-width.hpp new file mode 100644 index 0000000000..4e6feb3f1e --- /dev/null +++ b/tests/headers/issue-2239-template-dependent-bit-width.hpp @@ -0,0 +1,10 @@ +template class b { + typedef a td; + using ta = a; + struct foo { + a foo : sizeof(a); + a : sizeof(a); + td : sizeof(td); + ta : sizeof(ta); + }; +}; From 2aa244f8fcb8bdd2297cf1d5eebbc19c0a6fb5f3 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Thu, 1 Sep 2022 11:45:08 -0500 Subject: [PATCH 331/942] address clippy lints --- src/clang.rs | 10 +++++----- src/codegen/mod.rs | 9 +++++---- src/ir/analysis/derive.rs | 10 +++++----- src/ir/annotations.rs | 2 +- src/ir/comp.rs | 14 ++++++-------- src/ir/context.rs | 1 + src/ir/layout.rs | 2 +- src/ir/ty.rs | 2 +- 8 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/clang.rs b/src/clang.rs index 00716a1bd5..2aab9618f3 100644 --- a/src/clang.rs +++ b/src/clang.rs @@ -278,12 +278,12 @@ impl Cursor { /// Is the referent any kind of template parameter? pub fn is_template_parameter(&self) -> bool { - match self.kind() { + matches!( + self.kind(), CXCursor_TemplateTemplateParameter | - CXCursor_TemplateTypeParameter | - CXCursor_NonTypeTemplateParameter => true, - _ => false, - } + CXCursor_TemplateTypeParameter | + CXCursor_NonTypeTemplateParameter + ) } /// Does the referent's type or value depend on a template parameter? diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 77e9ba950d..ca4cbf23ac 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -1212,6 +1212,7 @@ impl CodeGenerator for TemplateInstantiation { trait FieldCodegen<'a> { type Extra; + #[allow(clippy::too_many_arguments)] fn codegen( &self, ctx: &BindgenContext, @@ -2563,7 +2564,7 @@ impl MethodCodegen for Method { } /// A helper type that represents different enum variations. -#[derive(Copy, Clone, PartialEq, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Debug)] pub enum EnumVariation { /// The code for this enum will use a Rust enum. Note that creating this in unsafe code /// (including FFI) with an invalid value will invoke undefined behaviour, whether or not @@ -3213,7 +3214,7 @@ impl CodeGenerator for Enum { ctx, enum_ty, &ident, - &Ident::new(&*mangled_name, Span::call_site()), + &Ident::new(&mangled_name, Span::call_site()), existing_variant_name, enum_rust_ty.clone(), result, @@ -3282,7 +3283,7 @@ impl CodeGenerator for Enum { } /// Enum for the default type of macro constants. -#[derive(Copy, Clone, PartialEq, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Debug)] pub enum MacroTypeVariation { /// Use i32 or i64 Signed, @@ -3326,7 +3327,7 @@ impl std::str::FromStr for MacroTypeVariation { } /// Enum for how aliases should be translated. -#[derive(Copy, Clone, PartialEq, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Debug)] pub enum AliasVariation { /// Convert to regular Rust alias TypeAlias, diff --git a/src/ir/analysis/derive.rs b/src/ir/analysis/derive.rs index f63458e5e7..d888cd558b 100644 --- a/src/ir/analysis/derive.rs +++ b/src/ir/analysis/derive.rs @@ -485,11 +485,11 @@ impl DeriveTrait { fn consider_edge_tmpl_inst(&self) -> EdgePredicate { match self { DeriveTrait::PartialEqOrPartialOrd => consider_edge_default, - _ => |kind| match kind { - EdgeKind::TemplateArgument | EdgeKind::TemplateDeclaration => { - true - } - _ => false, + _ => |kind| { + matches!( + kind, + EdgeKind::TemplateArgument | EdgeKind::TemplateDeclaration + ) }, } } diff --git a/src/ir/annotations.rs b/src/ir/annotations.rs index 9bcda508ee..4847333a2a 100644 --- a/src/ir/annotations.rs +++ b/src/ir/annotations.rs @@ -7,7 +7,7 @@ use crate::clang; /// What kind of accessor should we provide for a field? -#[derive(Copy, PartialEq, Clone, Debug)] +#[derive(Copy, PartialEq, Eq, Clone, Debug)] pub enum FieldAccessorKind { /// No accessor. None, diff --git a/src/ir/comp.rs b/src/ir/comp.rs index 9808d5986b..fdf6a9632c 100644 --- a/src/ir/comp.rs +++ b/src/ir/comp.rs @@ -20,7 +20,7 @@ use std::io; use std::mem; /// The kind of compound type. -#[derive(Debug, Copy, Clone, PartialEq)] +#[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum CompKind { /// A struct. Struct, @@ -29,7 +29,7 @@ pub enum CompKind { } /// The kind of C++ method. -#[derive(Debug, Copy, Clone, PartialEq)] +#[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum MethodKind { /// A constructor. We represent it as method for convenience, to avoid code /// duplication. @@ -55,12 +55,10 @@ pub enum MethodKind { impl MethodKind { /// Is this a destructor method? pub fn is_destructor(&self) -> bool { - match *self { - MethodKind::Destructor | MethodKind::VirtualDestructor { .. } => { - true - } - _ => false, - } + matches!( + *self, + MethodKind::Destructor | MethodKind::VirtualDestructor { .. } + ) } /// Is this a pure virtual method? diff --git a/src/ir/context.rs b/src/ir/context.rs index aa03b209cc..510764821b 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -467,6 +467,7 @@ pub struct BindgenContext { /// A traversal of allowlisted items. struct AllowlistedItemsTraversal<'ctx> { ctx: &'ctx BindgenContext, + #[allow(clippy::type_complexity)] traversal: ItemTraversal< 'ctx, ItemSet, diff --git a/src/ir/layout.rs b/src/ir/layout.rs index 6cf91131bb..472eae3d8a 100644 --- a/src/ir/layout.rs +++ b/src/ir/layout.rs @@ -7,7 +7,7 @@ use crate::ir::context::BindgenContext; use std::cmp; /// A type that represents the struct layout of a type. -#[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct Layout { /// The size (in bytes) of this layout. pub size: usize, diff --git a/src/ir/ty.rs b/src/ir/ty.rs index 38ab4564bd..c85bc68776 100644 --- a/src/ir/ty.rs +++ b/src/ir/ty.rs @@ -564,7 +564,7 @@ impl TemplateParameters for TypeKind { } /// The kind of float this type represents. -#[derive(Debug, Copy, Clone, PartialEq)] +#[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum FloatKind { /// A `float`. Float, From 3842b11b8a42dc99219a012cb71105ee84b889ec Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Thu, 1 Sep 2022 12:07:35 -0500 Subject: [PATCH 332/942] replace the `TraversalPredicate` trait with an alias type --- src/ir/context.rs | 8 +------ src/ir/traversal.rs | 58 +++++++++++---------------------------------- 2 files changed, 15 insertions(+), 51 deletions(-) diff --git a/src/ir/context.rs b/src/ir/context.rs index 510764821b..7837e59491 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -467,13 +467,7 @@ pub struct BindgenContext { /// A traversal of allowlisted items. struct AllowlistedItemsTraversal<'ctx> { ctx: &'ctx BindgenContext, - #[allow(clippy::type_complexity)] - traversal: ItemTraversal< - 'ctx, - ItemSet, - Vec, - for<'a> fn(&'a BindgenContext, Edge) -> bool, - >, + traversal: ItemTraversal<'ctx, ItemSet, Vec>, } impl<'ctx> Iterator for AllowlistedItemsTraversal<'ctx> { diff --git a/src/ir/traversal.rs b/src/ir/traversal.rs index 088e744a4b..f14483f295 100644 --- a/src/ir/traversal.rs +++ b/src/ir/traversal.rs @@ -179,17 +179,10 @@ pub enum EdgeKind { /// A predicate to allow visiting only sub-sets of the whole IR graph by /// excluding certain edges from being followed by the traversal. -pub trait TraversalPredicate { - /// Should the traversal follow this edge, and visit everything that is - /// reachable through it? - fn should_follow(&self, ctx: &BindgenContext, edge: Edge) -> bool; -} - -impl TraversalPredicate for for<'a> fn(&'a BindgenContext, Edge) -> bool { - fn should_follow(&self, ctx: &BindgenContext, edge: Edge) -> bool { - (*self)(ctx, edge) - } -} +/// +/// The predicate must return true if the traversal should follow this edge +/// and visit everything that is reachable through it. +pub type TraversalPredicate = for<'a> fn(&'a BindgenContext, Edge) -> bool; /// A `TraversalPredicate` implementation that follows all edges, and therefore /// traversals using this predicate will see the whole IR graph reachable from @@ -378,11 +371,10 @@ pub trait Trace { /// An graph traversal of the transitive closure of references between items. /// /// See `BindgenContext::allowlisted_items` for more information. -pub struct ItemTraversal<'ctx, Storage, Queue, Predicate> +pub struct ItemTraversal<'ctx, Storage, Queue> where Storage: TraversalStorage<'ctx>, Queue: TraversalQueue, - Predicate: TraversalPredicate, { ctx: &'ctx BindgenContext, @@ -393,25 +385,23 @@ where queue: Queue, /// The predicate that determines which edges this traversal will follow. - predicate: Predicate, + predicate: TraversalPredicate, /// The item we are currently traversing. currently_traversing: Option, } -impl<'ctx, Storage, Queue, Predicate> - ItemTraversal<'ctx, Storage, Queue, Predicate> +impl<'ctx, Storage, Queue> ItemTraversal<'ctx, Storage, Queue> where Storage: TraversalStorage<'ctx>, Queue: TraversalQueue, - Predicate: TraversalPredicate, { /// Begin a new traversal, starting from the given roots. pub fn new( ctx: &'ctx BindgenContext, roots: R, - predicate: Predicate, - ) -> ItemTraversal<'ctx, Storage, Queue, Predicate> + predicate: TraversalPredicate, + ) -> ItemTraversal<'ctx, Storage, Queue> where R: IntoIterator, { @@ -433,16 +423,14 @@ where } } -impl<'ctx, Storage, Queue, Predicate> Tracer - for ItemTraversal<'ctx, Storage, Queue, Predicate> +impl<'ctx, Storage, Queue> Tracer for ItemTraversal<'ctx, Storage, Queue> where Storage: TraversalStorage<'ctx>, Queue: TraversalQueue, - Predicate: TraversalPredicate, { fn visit_kind(&mut self, item: ItemId, kind: EdgeKind) { let edge = Edge::new(item, kind); - if !self.predicate.should_follow(self.ctx, edge) { + if !(self.predicate)(self.ctx, edge) { return; } @@ -454,12 +442,10 @@ where } } -impl<'ctx, Storage, Queue, Predicate> Iterator - for ItemTraversal<'ctx, Storage, Queue, Predicate> +impl<'ctx, Storage, Queue> Iterator for ItemTraversal<'ctx, Storage, Queue> where Storage: TraversalStorage<'ctx>, Queue: TraversalQueue, - Predicate: TraversalPredicate, { type Item = ItemId; @@ -488,21 +474,5 @@ where /// /// See `BindgenContext::assert_no_dangling_item_traversal` for more /// information. -pub type AssertNoDanglingItemsTraversal<'ctx> = ItemTraversal< - 'ctx, - Paths<'ctx>, - VecDeque, - for<'a> fn(&'a BindgenContext, Edge) -> bool, ->; - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - #[allow(dead_code)] - fn traversal_predicate_is_object_safe() { - // This should compile only if TraversalPredicate is object safe. - fn takes_by_trait_object(_: &dyn TraversalPredicate) {} - } -} +pub type AssertNoDanglingItemsTraversal<'ctx> = + ItemTraversal<'ctx, Paths<'ctx>, VecDeque>; From 9677e412c49e303e078e37ee30105cc635bb0ff8 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Tue, 6 Sep 2022 15:02:52 -0500 Subject: [PATCH 333/942] fix clippy lints --- src/ir/annotations.rs | 2 +- src/ir/function.rs | 2 +- src/ir/layout.rs | 2 +- tests/tests.rs | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ir/annotations.rs b/src/ir/annotations.rs index 4847333a2a..288c11ebae 100644 --- a/src/ir/annotations.rs +++ b/src/ir/annotations.rs @@ -25,7 +25,7 @@ pub enum FieldAccessorKind { /// documentation: /// /// http://www.stack.nl/~dimitri/doxygen/manual/docblocks.html -#[derive(Default, Clone, PartialEq, Debug)] +#[derive(Default, Clone, PartialEq, Eq, Debug)] pub struct Annotations { /// Whether this item is marked as opaque. Only applies to types. opaque: bool, diff --git a/src/ir/function.rs b/src/ir/function.rs index e8e2c2dfed..27192bcfb8 100644 --- a/src/ir/function.rs +++ b/src/ir/function.rs @@ -19,7 +19,7 @@ use std::io; const RUST_DERIVE_FUNPTR_LIMIT: usize = 12; /// What kind of a function are we looking at? -#[derive(Debug, Copy, Clone, PartialEq)] +#[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum FunctionKind { /// A plain, free function. Function, diff --git a/src/ir/layout.rs b/src/ir/layout.rs index 472eae3d8a..6f4503070a 100644 --- a/src/ir/layout.rs +++ b/src/ir/layout.rs @@ -93,7 +93,7 @@ impl Layout { } /// When we are treating a type as opaque, it is just a blob with a `Layout`. -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct Opaque(pub Layout); impl Opaque { diff --git a/tests/tests.rs b/tests/tests.rs index 71fc54be13..8dcc54370b 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -139,7 +139,7 @@ fn error_diff_mismatch( println!("+++ generated from: {:?}", header); } - for diff in diff::lines(&expected, &actual) { + for diff in diff::lines(expected, actual) { match diff { diff::Result::Left(l) => println!("-{}", l), diff::Result::Both(l, _) => println!(" {}", l), @@ -168,7 +168,7 @@ fn error_diff_mismatch( .output()?; } - return Err(Error::new(ErrorKind::Other, "Header and binding differ! Run with BINDGEN_OVERWRITE_EXPECTED=1 in the environment to automatically overwrite the expectation or with BINDGEN_TESTS_DIFFTOOL=meld to do this manually.")); + Err(Error::new(ErrorKind::Other, "Header and binding differ! Run with BINDGEN_OVERWRITE_EXPECTED=1 in the environment to automatically overwrite the expectation or with BINDGEN_TESTS_DIFFTOOL=meld to do this manually.")) } fn compare_generated_header( From df74d0e3f7f3359bf876a6165e9b53fb6c16f8e5 Mon Sep 17 00:00:00 2001 From: Justin Smith Date: Fri, 9 Sep 2022 11:44:55 -0400 Subject: [PATCH 334/942] Use str::strip_prefix --- tests/parse_callbacks/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/parse_callbacks/mod.rs b/tests/parse_callbacks/mod.rs index 2dc35a6d2c..4ec286e9ee 100644 --- a/tests/parse_callbacks/mod.rs +++ b/tests/parse_callbacks/mod.rs @@ -16,8 +16,8 @@ impl RemoveFunctionPrefixParseCallback { impl ParseCallbacks for RemoveFunctionPrefixParseCallback { fn generated_name_override(&self, function_name: &str) -> Option { if let Some(prefix) = &self.remove_function_prefix { - if function_name.starts_with(prefix) { - return Some(function_name[prefix.len()..].to_string()); + if let Some(name) = function_name.strip_prefix(prefix) { + return Some(name.to_string()) } } None From 5209ebdbdfbe0663824d2abb688ac30c2c602726 Mon Sep 17 00:00:00 2001 From: Justin Smith Date: Fri, 9 Sep 2022 11:57:38 -0400 Subject: [PATCH 335/942] Fix formatting --- tests/parse_callbacks/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/parse_callbacks/mod.rs b/tests/parse_callbacks/mod.rs index 4ec286e9ee..6ade71c27c 100644 --- a/tests/parse_callbacks/mod.rs +++ b/tests/parse_callbacks/mod.rs @@ -17,7 +17,7 @@ impl ParseCallbacks for RemoveFunctionPrefixParseCallback { fn generated_name_override(&self, function_name: &str) -> Option { if let Some(prefix) = &self.remove_function_prefix { if let Some(name) = function_name.strip_prefix(prefix) { - return Some(name.to_string()) + return Some(name.to_string()); } } None From 7464da38458d806aedc46cb8310e3855ab0fdf79 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Tue, 6 Sep 2022 15:30:29 -0500 Subject: [PATCH 336/942] add `BindgenOptions::require_syn` method --- src/lib.rs | 71 +++++++++++++++++++++++++++--------------------------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b90faba613..fb02fe16f5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2029,6 +2029,11 @@ struct BindgenOptions { impl ::std::panic::UnwindSafe for BindgenOptions {} impl BindgenOptions { + /// Whether any of the enabled options requires `syn`. + fn require_syn(&self) -> bool { + self.sort_semantically + } + fn build(&mut self) { let mut regex_sets = [ &mut self.allowlisted_vars, @@ -2455,13 +2460,13 @@ impl Bindings { let (items, options, warnings) = codegen::codegen(context); - if options.sort_semantically { + let module = if options.require_syn() { let module_wrapped_tokens = quote!(mod wrapper_for_sorting_hack { #( #items )* }); - // This semantically sorting business is a hack, for now. This means that we are - // re-parsing already generated code using `syn` (as opposed to `quote`) because - // `syn` provides us more control over the elements. + // This syn business is a hack, for now. This means that we are re-parsing already + // generated code using `syn` (as opposed to `quote`) because `syn` provides us more + // control over the elements. // One caveat is that some of the items coming from `quote`d output might have // multiple items within them. Hence, we have to wrap the incoming in a `mod`. // The two `unwrap`s here are deliberate because @@ -2475,46 +2480,42 @@ impl Bindings { .unwrap() .1; - syn_parsed_items.sort_by_key(|item| match item { - syn::Item::Type(_) => 0, - syn::Item::Struct(_) => 1, - syn::Item::Const(_) => 2, - syn::Item::Fn(_) => 3, - syn::Item::Enum(_) => 4, - syn::Item::Union(_) => 5, - syn::Item::Static(_) => 6, - syn::Item::Trait(_) => 7, - syn::Item::TraitAlias(_) => 8, - syn::Item::Impl(_) => 9, - syn::Item::Mod(_) => 10, - syn::Item::Use(_) => 11, - syn::Item::Verbatim(_) => 12, - syn::Item::ExternCrate(_) => 13, - syn::Item::ForeignMod(_) => 14, - syn::Item::Macro(_) => 15, - syn::Item::Macro2(_) => 16, - _ => 18, - }); + if options.sort_semantically { + syn_parsed_items.sort_by_key(|item| match item { + syn::Item::Type(_) => 0, + syn::Item::Struct(_) => 1, + syn::Item::Const(_) => 2, + syn::Item::Fn(_) => 3, + syn::Item::Enum(_) => 4, + syn::Item::Union(_) => 5, + syn::Item::Static(_) => 6, + syn::Item::Trait(_) => 7, + syn::Item::TraitAlias(_) => 8, + syn::Item::Impl(_) => 9, + syn::Item::Mod(_) => 10, + syn::Item::Use(_) => 11, + syn::Item::Verbatim(_) => 12, + syn::Item::ExternCrate(_) => 13, + syn::Item::ForeignMod(_) => 14, + syn::Item::Macro(_) => 15, + syn::Item::Macro2(_) => 16, + _ => 18, + }); + } let synful_items = syn_parsed_items .into_iter() .map(|item| item.into_token_stream()); - return Ok(Bindings { - options, - warnings, - module: quote! { - #( #synful_items )* - }, - }); - } + quote! { #( #synful_items )* } + } else { + quote! { #( #items )* } + }; Ok(Bindings { options, warnings, - module: quote! { - #( #items )* - }, + module, }) } From 8b29355ca0ce54e941d398ef9a605e9b5c0f20ae Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Tue, 6 Sep 2022 16:34:58 -0500 Subject: [PATCH 337/942] document usage of `syn` in `CONTRIBUTING.md` --- CONTRIBUTING.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3fe7539f5f..2974ba4254 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -318,7 +318,19 @@ parameters a given type uses. The analyses are defined in The final phase is generating Rust source text from the analyzed IR, and it is defined in `src/codegen/*`. We use the `quote` crate, which provides the `quote! -{ ... }` macro for quasi-quoting Rust forms. +{ ... }` macro for quasi-quoting Rust forms. Some options that affect the +generated Rust code are implemented using the [`syn`](https://docs.rs/syn) crate. + +### Implementing new options using `syn` + +Here is a list of recommendations to be followed if a new option can be +implemented using the `syn` crate: + +- The `BindgenOptions::require_syn` method must be updated to reflect that this + new option requires parsing the generated Rust code with `syn`. + +- The implementation of the new option should be added at the end of + `Bindings::generate`, inside the `if options.require_syn() { ... }` block. ## Pull Requests and Code Reviews From 61636e94ca315278d9ac5f1210ffca6cca697428 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Tue, 6 Sep 2022 16:59:49 -0500 Subject: [PATCH 338/942] add `--newtype-global-enum` option --- src/codegen/mod.rs | 51 +++++++++++++++---- src/ir/enum_ty.rs | 19 ++++++- src/lib.rs | 34 +++++++++++-- src/options.rs | 12 +++++ .../expectations/tests/newtype-global-enum.rs | 12 +++++ tests/headers/newtype-global-enum.hpp | 8 +++ 6 files changed, 118 insertions(+), 18 deletions(-) create mode 100644 tests/expectations/tests/newtype-global-enum.rs create mode 100644 tests/headers/newtype-global-enum.hpp diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index ca4cbf23ac..9a55ea3799 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -2577,6 +2577,8 @@ pub enum EnumVariation { NewType { /// Indicates whether the newtype will have bitwise operators is_bitfield: bool, + /// Indicates whether the variants will be represented as global constants + is_global: bool, }, /// The code for this enum will use consts Consts, @@ -2614,16 +2616,26 @@ impl std::str::FromStr for EnumVariation { "rust_non_exhaustive" => Ok(EnumVariation::Rust { non_exhaustive: true, }), - "bitfield" => Ok(EnumVariation::NewType { is_bitfield: true }), + "bitfield" => Ok(EnumVariation::NewType { + is_bitfield: true, + is_global: false, + }), "consts" => Ok(EnumVariation::Consts), "moduleconsts" => Ok(EnumVariation::ModuleConsts), - "newtype" => Ok(EnumVariation::NewType { is_bitfield: false }), + "newtype" => Ok(EnumVariation::NewType { + is_bitfield: false, + is_global: false, + }), + "newtype_global" => Ok(EnumVariation::NewType { + is_bitfield: false, + is_global: true, + }), _ => Err(std::io::Error::new( std::io::ErrorKind::InvalidInput, concat!( "Got an invalid EnumVariation. Accepted values ", "are 'rust', 'rust_non_exhaustive', 'bitfield', 'consts',", - "'moduleconsts', and 'newtype'." + "'moduleconsts', 'newtype' and 'newtype_global'." ), )), } @@ -2644,6 +2656,7 @@ enum EnumBuilder<'a> { canonical_name: &'a str, tokens: proc_macro2::TokenStream, is_bitfield: bool, + is_global: bool, }, Consts { variants: Vec, @@ -2684,7 +2697,10 @@ impl<'a> EnumBuilder<'a> { let ident = Ident::new(name, Span::call_site()); match enum_variation { - EnumVariation::NewType { is_bitfield } => EnumBuilder::NewType { + EnumVariation::NewType { + is_bitfield, + is_global, + } => EnumBuilder::NewType { codegen_depth: enum_codegen_depth, canonical_name: name, tokens: quote! { @@ -2692,6 +2708,7 @@ impl<'a> EnumBuilder<'a> { pub struct #ident (pub #repr); }, is_bitfield, + is_global, }, EnumVariation::Rust { .. } => { @@ -2792,17 +2809,29 @@ impl<'a> EnumBuilder<'a> { } } - EnumBuilder::NewType { canonical_name, .. } => { + EnumBuilder::NewType { + canonical_name, + is_global, + .. + } => { if ctx.options().rust_features().associated_const && is_ty_named { let enum_ident = ctx.rust_ident(canonical_name); let variant_ident = ctx.rust_ident(variant_name); - result.push(quote! { - impl #enum_ident { - #doc - pub const #variant_ident : #rust_ty = #rust_ty ( #expr ); - } - }); + let tokens = quote! { + #doc + pub const #variant_ident : #rust_ty = #rust_ty ( #expr ); + }; + + if is_global { + result.push(tokens); + } else { + result.push(quote! { + impl #enum_ident { + #tokens + } + }); + } } else { let ident = ctx.rust_ident(match mangling_prefix { Some(prefix) => { diff --git a/src/ir/enum_ty.rs b/src/ir/enum_ty.rs index 97455c9123..2b039a4fac 100644 --- a/src/ir/enum_ty.rs +++ b/src/ir/enum_ty.rs @@ -187,10 +187,25 @@ impl Enum { &ctx.options().bitfield_enums, item, ) { - EnumVariation::NewType { is_bitfield: true } + EnumVariation::NewType { + is_bitfield: true, + is_global: false, + } } else if self.is_matching_enum(ctx, &ctx.options().newtype_enums, item) { - EnumVariation::NewType { is_bitfield: false } + EnumVariation::NewType { + is_bitfield: false, + is_global: false, + } + } else if self.is_matching_enum( + ctx, + &ctx.options().newtype_global_enums, + item, + ) { + EnumVariation::NewType { + is_bitfield: false, + is_global: true, + } } else if self.is_matching_enum( ctx, &ctx.options().rustified_enums, diff --git a/src/lib.rs b/src/lib.rs index fb02fe16f5..112df665ee 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -279,11 +279,19 @@ impl Builder { codegen::EnumVariation::Rust { non_exhaustive: true, } => "rust_non_exhaustive", - codegen::EnumVariation::NewType { is_bitfield: true } => { - "bitfield" - } - codegen::EnumVariation::NewType { is_bitfield: false } => { - "newtype" + codegen::EnumVariation::NewType { + is_bitfield: true, + .. + } => "bitfield", + codegen::EnumVariation::NewType { + is_bitfield: false, + is_global, + } => { + if is_global { + "newtype_global" + } else { + "newtype" + } } codegen::EnumVariation::Consts => "consts", codegen::EnumVariation::ModuleConsts => "moduleconsts", @@ -984,6 +992,18 @@ impl Builder { self } + /// Mark the given enum (or set of enums, if using a pattern) as a newtype + /// whose variants are exposed as global constants. + /// + /// Regular expressions are supported. + /// + /// This makes bindgen generate a type that isn't a Rust `enum`. Regular + /// expressions are supported. + pub fn newtype_global_enum>(mut self, arg: T) -> Builder { + self.options.newtype_global_enums.insert(arg); + self + } + /// Mark the given enum (or set of enums, if using a pattern) as a Rust /// enum. /// @@ -1759,6 +1779,9 @@ struct BindgenOptions { /// The enum patterns to mark an enum as a newtype. newtype_enums: RegexSet, + /// The enum patterns to mark an enum as a global newtype. + newtype_global_enums: RegexSet, + /// The enum patterns to mark an enum as a Rust enum. rustified_enums: RegexSet, @@ -2102,6 +2125,7 @@ impl Default for BindgenOptions { default_enum_style: Default::default(), bitfield_enums: Default::default(), newtype_enums: Default::default(), + newtype_global_enums: Default::default(), rustified_enums: Default::default(), rustified_non_exhaustive_enums: Default::default(), constified_enums: Default::default(), diff --git a/src/options.rs b/src/options.rs index 83da21f42f..4db3fd5766 100644 --- a/src/options.rs +++ b/src/options.rs @@ -63,6 +63,12 @@ where .value_name("regex") .multiple_occurrences(true) .number_of_values(1), + Arg::new("newtype-global-enum") + .long("newtype-global-enum") + .help("Mark any enum whose name matches as a global newtype.") + .value_name("regex") + .multiple_occurrences(true) + .number_of_values(1), Arg::new("rustified-enum") .long("rustified-enum") .help("Mark any enum whose name matches as a Rust enum.") @@ -573,6 +579,12 @@ where } } + if let Some(newtypes) = matches.values_of("newtype-global-enum") { + for regex in newtypes { + builder = builder.newtype_global_enum(regex); + } + } + if let Some(rustifieds) = matches.values_of("rustified-enum") { for regex in rustifieds { builder = builder.rustified_enum(regex); diff --git a/tests/expectations/tests/newtype-global-enum.rs b/tests/expectations/tests/newtype-global-enum.rs new file mode 100644 index 0000000000..ff98063724 --- /dev/null +++ b/tests/expectations/tests/newtype-global-enum.rs @@ -0,0 +1,12 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +pub const Foo_Bar: Foo = 2; +pub const Foo_Baz: Foo = 4; +pub const Foo_Duplicated: Foo = 4; +pub const Foo_Negative: Foo = -3; +pub type Foo = ::std::os::raw::c_int; diff --git a/tests/headers/newtype-global-enum.hpp b/tests/headers/newtype-global-enum.hpp new file mode 100644 index 0000000000..8021a3cc72 --- /dev/null +++ b/tests/headers/newtype-global-enum.hpp @@ -0,0 +1,8 @@ +// bindgen-flags: --newtype-global-enum "Foo" --rust-target 1.28 -- -std=c++11 + +enum Foo { + Bar = 1 << 1, + Baz = 1 << 2, + Duplicated = 1 << 2, + Negative = -3, +}; From 0d805d70d5c6e4cc99cbad7a988c38bdfe52321b Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Mon, 12 Sep 2022 13:45:54 -0500 Subject: [PATCH 339/942] fix `--newtype-global-enum` option --- src/codegen/mod.rs | 23 ++++++++----------- src/lib.rs | 2 ++ .../expectations/tests/newtype-global-enum.rs | 12 ++++++---- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 9a55ea3799..f523232eb1 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -2814,24 +2814,19 @@ impl<'a> EnumBuilder<'a> { is_global, .. } => { - if ctx.options().rust_features().associated_const && is_ty_named + if ctx.options().rust_features().associated_const && + is_ty_named && + !is_global { let enum_ident = ctx.rust_ident(canonical_name); let variant_ident = ctx.rust_ident(variant_name); - let tokens = quote! { - #doc - pub const #variant_ident : #rust_ty = #rust_ty ( #expr ); - }; - if is_global { - result.push(tokens); - } else { - result.push(quote! { - impl #enum_ident { - #tokens - } - }); - } + result.push(quote! { + impl #enum_ident { + #doc + pub const #variant_ident : #rust_ty = #rust_ty ( #expr ); + } + }); } else { let ident = ctx.rust_ident(match mangling_prefix { Some(prefix) => { diff --git a/src/lib.rs b/src/lib.rs index 112df665ee..8c41565ab0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -315,6 +315,7 @@ impl Builder { let regex_sets = &[ (&self.options.bitfield_enums, "--bitfield-enum"), (&self.options.newtype_enums, "--newtype-enum"), + (&self.options.newtype_global_enums, "--newtype-global-enum"), (&self.options.rustified_enums, "--rustified-enum"), ( &self.options.rustified_non_exhaustive_enums, @@ -2072,6 +2073,7 @@ impl BindgenOptions { &mut self.constified_enums, &mut self.constified_enum_modules, &mut self.newtype_enums, + &mut self.newtype_global_enums, &mut self.rustified_enums, &mut self.rustified_non_exhaustive_enums, &mut self.type_alias, diff --git a/tests/expectations/tests/newtype-global-enum.rs b/tests/expectations/tests/newtype-global-enum.rs index ff98063724..cf23cca60b 100644 --- a/tests/expectations/tests/newtype-global-enum.rs +++ b/tests/expectations/tests/newtype-global-enum.rs @@ -5,8 +5,10 @@ non_upper_case_globals )] -pub const Foo_Bar: Foo = 2; -pub const Foo_Baz: Foo = 4; -pub const Foo_Duplicated: Foo = 4; -pub const Foo_Negative: Foo = -3; -pub type Foo = ::std::os::raw::c_int; +pub const Foo_Bar: Foo = Foo(2); +pub const Foo_Baz: Foo = Foo(4); +pub const Foo_Duplicated: Foo = Foo(4); +pub const Foo_Negative: Foo = Foo(-3); +#[repr(transparent)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +pub struct Foo(pub ::std::os::raw::c_int); From 6a100c0b32fae6dca5148636bb00c1f8ecd234ca Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Mon, 29 Aug 2022 11:37:01 -0500 Subject: [PATCH 340/942] add `is_divergent` field --- src/ir/function.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ir/function.rs b/src/ir/function.rs index 27192bcfb8..afbb90243e 100644 --- a/src/ir/function.rs +++ b/src/ir/function.rs @@ -228,6 +228,7 @@ pub struct FunctionSig { /// Whether this function is variadic. is_variadic: bool, + is_divergent: bool, /// Whether this function's return value must be used. must_use: bool, @@ -358,6 +359,7 @@ impl FunctionSig { return_type: TypeId, argument_types: Vec<(Option, TypeId)>, is_variadic: bool, + is_divergent: bool, must_use: bool, abi: Abi, ) -> Self { @@ -365,6 +367,7 @@ impl FunctionSig { return_type, argument_types, is_variadic, + is_divergent, must_use, abi, } @@ -528,7 +531,7 @@ impl FunctionSig { warn!("Unknown calling convention: {:?}", call_conv); } - Ok(Self::new(ret, args, ty.is_variadic(), must_use, abi)) + Ok(Self::new(ret, args, ty.is_variadic(), false, must_use, abi)) } /// Get this function signature's return type. From 250150d0159ef02b35f65cd83d71d60f0439ee95 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Wed, 31 Aug 2022 14:38:26 -0500 Subject: [PATCH 341/942] check for noreturn attribute --- src/clang.rs | 18 ++++++++++++++++++ src/codegen/mod.rs | 4 ++++ src/ir/function.rs | 14 +++++++++++++- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/clang.rs b/src/clang.rs index 2aab9618f3..5579c42b3f 100644 --- a/src/clang.rs +++ b/src/clang.rs @@ -645,6 +645,24 @@ impl Cursor { self.has_attr("warn_unused_result", Some(CXCursor_WarnUnusedResultAttr)) } + pub fn has_no_return_attr(&self) -> bool { + let mut found_attr = false; + self.visit(|cur| { + found_attr = cur.kind() == CXCursor_UnexposedAttr && + cur.tokens().iter().any(|t| { + t.kind == CXToken_Keyword && t.spelling() == b"_Noreturn" + }); + + if found_attr { + CXChildVisit_Break + } else { + CXChildVisit_Continue + } + }); + + found_attr + } + /// Does this cursor have the given attribute? /// /// `name` is checked against unexposed attributes. diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index f523232eb1..f1422d6b53 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -4729,6 +4729,10 @@ pub mod utils { ctx: &BindgenContext, sig: &FunctionSig, ) -> proc_macro2::TokenStream { + if sig.is_divergent() { + return quote! { -> ! }; + } + let return_item = ctx.resolve_item(sig.return_type()); if let TypeKind::Void = *return_item.kind().expect_type().kind() { quote! {} diff --git a/src/ir/function.rs b/src/ir/function.rs index afbb90243e..6b59649cd4 100644 --- a/src/ir/function.rs +++ b/src/ir/function.rs @@ -381,6 +381,7 @@ impl FunctionSig { ) -> Result { use clang_sys::*; debug!("FunctionSig::from_ty {:?} {:?}", ty, cursor); + let is_divergent = cursor.has_no_return_attr(); // Skip function templates let kind = cursor.kind(); @@ -531,7 +532,14 @@ impl FunctionSig { warn!("Unknown calling convention: {:?}", call_conv); } - Ok(Self::new(ret, args, ty.is_variadic(), false, must_use, abi)) + Ok(Self::new( + ret, + args, + ty.is_variadic(), + is_divergent, + must_use, + abi, + )) } /// Get this function signature's return type. @@ -578,6 +586,10 @@ impl FunctionSig { matches!(self.abi, Abi::C | Abi::Unknown(..)) } + + pub(crate) fn is_divergent(&self) -> bool { + self.is_divergent + } } impl ClangSubItemParser for Function { From 1704775d9183ae757cc67c16af267a517dac5a7c Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Wed, 31 Aug 2022 14:44:42 -0500 Subject: [PATCH 342/942] add tests --- tests/expectations/tests/noreturn.rs | 13 +++++++++++++ tests/headers/noreturn.h | 3 +++ 2 files changed, 16 insertions(+) create mode 100644 tests/expectations/tests/noreturn.rs create mode 100644 tests/headers/noreturn.h diff --git a/tests/expectations/tests/noreturn.rs b/tests/expectations/tests/noreturn.rs new file mode 100644 index 0000000000..fa81ee7621 --- /dev/null +++ b/tests/expectations/tests/noreturn.rs @@ -0,0 +1,13 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +extern "C" { + pub fn f() -> !; +} +extern "C" { + pub fn g(); +} diff --git a/tests/headers/noreturn.h b/tests/headers/noreturn.h new file mode 100644 index 0000000000..9ce68518f0 --- /dev/null +++ b/tests/headers/noreturn.h @@ -0,0 +1,3 @@ +_Noreturn void f(void); +// TODO (pvdrz): figure out how to handle this case. +__attribute__((noreturn)) void g(void); From b8f3920ad11b82673d06f2d25bb663e2b7efe491 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Thu, 1 Sep 2022 10:54:48 -0500 Subject: [PATCH 343/942] add `CxTokenKind` argument to `has_attr` --- src/clang.rs | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/src/clang.rs b/src/clang.rs index 5579c42b3f..4779e0b759 100644 --- a/src/clang.rs +++ b/src/clang.rs @@ -642,39 +642,34 @@ impl Cursor { pub fn has_warn_unused_result_attr(&self) -> bool { // FIXME(emilio): clang-sys doesn't expose this (from clang 9). const CXCursor_WarnUnusedResultAttr: CXCursorKind = 440; - self.has_attr("warn_unused_result", Some(CXCursor_WarnUnusedResultAttr)) + self.has_attr( + "warn_unused_result", + Some(CXCursor_WarnUnusedResultAttr), + CXToken_Identifier, + ) } + /// Check wether this cursor has the `_Noreturn` attribute. pub fn has_no_return_attr(&self) -> bool { - let mut found_attr = false; - self.visit(|cur| { - found_attr = cur.kind() == CXCursor_UnexposedAttr && - cur.tokens().iter().any(|t| { - t.kind == CXToken_Keyword && t.spelling() == b"_Noreturn" - }); - - if found_attr { - CXChildVisit_Break - } else { - CXChildVisit_Continue - } - }); - - found_attr + self.has_attr("_Noreturn", None, CXToken_Keyword) } /// Does this cursor have the given attribute? /// /// `name` is checked against unexposed attributes. - fn has_attr(&self, name: &str, clang_kind: Option) -> bool { + fn has_attr( + &self, + name: &str, + clang_kind: Option, + token_kind: CXTokenKind, + ) -> bool { let mut found_attr = false; self.visit(|cur| { let kind = cur.kind(); found_attr = clang_kind.map_or(false, |k| k == kind) || (kind == CXCursor_UnexposedAttr && cur.tokens().iter().any(|t| { - t.kind == CXToken_Identifier && - t.spelling() == name.as_bytes() + t.kind == token_kind && t.spelling() == name.as_bytes() })); if found_attr { From 3da6026afd5715715feeb4a8668a91024d71830e Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Thu, 1 Sep 2022 10:59:06 -0500 Subject: [PATCH 344/942] gate `_Noreturn` detection behind `--enable-fucntion-attribute-detection` --- src/ir/function.rs | 4 +++- tests/headers/noreturn.h | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ir/function.rs b/src/ir/function.rs index 6b59649cd4..b829e6013a 100644 --- a/src/ir/function.rs +++ b/src/ir/function.rs @@ -381,7 +381,9 @@ impl FunctionSig { ) -> Result { use clang_sys::*; debug!("FunctionSig::from_ty {:?} {:?}", ty, cursor); - let is_divergent = cursor.has_no_return_attr(); + + let is_divergent = ctx.options().enable_function_attribute_detection && + cursor.has_no_return_attr(); // Skip function templates let kind = cursor.kind(); diff --git a/tests/headers/noreturn.h b/tests/headers/noreturn.h index 9ce68518f0..0e4819e2a4 100644 --- a/tests/headers/noreturn.h +++ b/tests/headers/noreturn.h @@ -1,3 +1,4 @@ +// bindgen-flags: --enable-function-attribute-detection _Noreturn void f(void); // TODO (pvdrz): figure out how to handle this case. __attribute__((noreturn)) void g(void); From 2251aed4d0a2422d7b94cceeafcfe9ac98a69ad6 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Thu, 1 Sep 2022 11:26:47 -0500 Subject: [PATCH 345/942] find all attributes in a single pass --- src/clang.rs | 83 ++++++++++++++++++++++++++-------------------- src/ir/function.rs | 14 ++++---- 2 files changed, 55 insertions(+), 42 deletions(-) diff --git a/src/clang.rs b/src/clang.rs index 4779e0b759..05ef5d05e0 100644 --- a/src/clang.rs +++ b/src/clang.rs @@ -12,6 +12,27 @@ use std::hash::Hasher; use std::os::raw::{c_char, c_int, c_longlong, c_uint, c_ulong, c_ulonglong}; use std::{mem, ptr, slice}; +pub struct Attribute { + name: &'static [u8], + kind: CXCursorKind, + token_kind: CXTokenKind, +} + +impl Attribute { + pub const MUST_USE: Self = Self { + name: b"warn_unused_result", + // FIXME(emilio): clang-sys doesn't expose `CXCursor_WarnUnusedResultAttr` (from clang 9). + kind: 440, + token_kind: CXToken_Identifier, + }; + + pub const NO_RETURN: Self = Self { + name: b"_Noreturn", + kind: CXCursor_UnexposedAttr, + token_kind: CXToken_Keyword, + }; +} + /// A cursor into the Clang AST, pointing to an AST node. /// /// We call the AST node pointed to by the cursor the cursor's "referent". @@ -638,48 +659,38 @@ impl Cursor { } } - /// Whether this cursor has the `warn_unused_result` attribute. - pub fn has_warn_unused_result_attr(&self) -> bool { - // FIXME(emilio): clang-sys doesn't expose this (from clang 9). - const CXCursor_WarnUnusedResultAttr: CXCursorKind = 440; - self.has_attr( - "warn_unused_result", - Some(CXCursor_WarnUnusedResultAttr), - CXToken_Identifier, - ) - } - - /// Check wether this cursor has the `_Noreturn` attribute. - pub fn has_no_return_attr(&self) -> bool { - self.has_attr("_Noreturn", None, CXToken_Keyword) - } - - /// Does this cursor have the given attribute? - /// - /// `name` is checked against unexposed attributes. - fn has_attr( + pub fn has_attrs( &self, - name: &str, - clang_kind: Option, - token_kind: CXTokenKind, - ) -> bool { - let mut found_attr = false; + attrs: &[Attribute; N], + ) -> [bool; N] { + let mut found_attrs = [false; N]; + let mut found_count = 0; + self.visit(|cur| { let kind = cur.kind(); - found_attr = clang_kind.map_or(false, |k| k == kind) || - (kind == CXCursor_UnexposedAttr && - cur.tokens().iter().any(|t| { - t.kind == token_kind && t.spelling() == name.as_bytes() - })); - - if found_attr { - CXChildVisit_Break - } else { - CXChildVisit_Continue + for (idx, attr) in attrs.iter().enumerate() { + let found_attr = &mut found_attrs[idx]; + if !*found_attr { + if kind == attr.kind && + cur.tokens().iter().any(|t| { + t.kind == attr.token_kind && + t.spelling() == attr.name + }) + { + *found_attr = true; + found_count += 1; + + if found_count == N { + return CXChildVisit_Break; + } + } + } } + + CXChildVisit_Continue }); - found_attr + found_attrs } /// Given that this cursor's referent is a `typedef`, get the `Type` that is diff --git a/src/ir/function.rs b/src/ir/function.rs index b829e6013a..6ed3a5038e 100644 --- a/src/ir/function.rs +++ b/src/ir/function.rs @@ -6,7 +6,7 @@ use super::dot::DotAttributes; use super::item::Item; use super::traversal::{EdgeKind, Trace, Tracer}; use super::ty::TypeKind; -use crate::clang; +use crate::clang::{self, Attribute}; use crate::parse::{ ClangItemParser, ClangSubItemParser, ParseError, ParseResult, }; @@ -382,9 +382,6 @@ impl FunctionSig { use clang_sys::*; debug!("FunctionSig::from_ty {:?} {:?}", ty, cursor); - let is_divergent = ctx.options().enable_function_attribute_detection && - cursor.has_no_return_attr(); - // Skip function templates let kind = cursor.kind(); if kind == CXCursor_FunctionTemplate { @@ -453,8 +450,13 @@ impl FunctionSig { } }; - let must_use = ctx.options().enable_function_attribute_detection && - cursor.has_warn_unused_result_attr(); + let [must_use, is_divergent] = + if ctx.options().enable_function_attribute_detection { + cursor.has_attrs(&[Attribute::MUST_USE, Attribute::NO_RETURN]) + } else { + Default::default() + }; + let is_method = kind == CXCursor_CXXMethod; let is_constructor = kind == CXCursor_Constructor; let is_destructor = kind == CXCursor_Destructor; From 15f5094d45a8858ba2d244dc8c6f018a28d48eaa Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Thu, 1 Sep 2022 12:16:43 -0500 Subject: [PATCH 346/942] document `Attribute` --- src/clang.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/clang.rs b/src/clang.rs index 05ef5d05e0..d66fe445ec 100644 --- a/src/clang.rs +++ b/src/clang.rs @@ -12,6 +12,10 @@ use std::hash::Hasher; use std::os::raw::{c_char, c_int, c_longlong, c_uint, c_ulong, c_ulonglong}; use std::{mem, ptr, slice}; +/// Type representing a clang attribute. +/// +/// Values of this type can be used to check for different attributes using the `has_attrs` +/// function. pub struct Attribute { name: &'static [u8], kind: CXCursorKind, @@ -19,6 +23,7 @@ pub struct Attribute { } impl Attribute { + /// A `warn_unused_result` attribute. pub const MUST_USE: Self = Self { name: b"warn_unused_result", // FIXME(emilio): clang-sys doesn't expose `CXCursor_WarnUnusedResultAttr` (from clang 9). @@ -26,6 +31,7 @@ impl Attribute { token_kind: CXToken_Identifier, }; + /// A `_Noreturn` attribute. pub const NO_RETURN: Self = Self { name: b"_Noreturn", kind: CXCursor_UnexposedAttr, From fb5f9b963cfd6ca878d908be7b237177462f4ddb Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Thu, 1 Sep 2022 12:17:36 -0500 Subject: [PATCH 347/942] document `has_attrs` --- src/clang.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/clang.rs b/src/clang.rs index d66fe445ec..0fcccaa423 100644 --- a/src/clang.rs +++ b/src/clang.rs @@ -665,6 +665,7 @@ impl Cursor { } } + /// Does this cursor have the given attributes? pub fn has_attrs( &self, attrs: &[Attribute; N], From e503476a96636df41532b988f8f8f0c318fff24a Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Thu, 1 Sep 2022 12:36:11 -0500 Subject: [PATCH 348/942] bring back optional cursor kind --- src/clang.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/clang.rs b/src/clang.rs index 0fcccaa423..fddb261c28 100644 --- a/src/clang.rs +++ b/src/clang.rs @@ -18,7 +18,7 @@ use std::{mem, ptr, slice}; /// function. pub struct Attribute { name: &'static [u8], - kind: CXCursorKind, + kind: Option, token_kind: CXTokenKind, } @@ -27,14 +27,14 @@ impl Attribute { pub const MUST_USE: Self = Self { name: b"warn_unused_result", // FIXME(emilio): clang-sys doesn't expose `CXCursor_WarnUnusedResultAttr` (from clang 9). - kind: 440, + kind: Some(440), token_kind: CXToken_Identifier, }; /// A `_Noreturn` attribute. pub const NO_RETURN: Self = Self { name: b"_Noreturn", - kind: CXCursor_UnexposedAttr, + kind: None, token_kind: CXToken_Keyword, }; } @@ -678,11 +678,13 @@ impl Cursor { for (idx, attr) in attrs.iter().enumerate() { let found_attr = &mut found_attrs[idx]; if !*found_attr { - if kind == attr.kind && - cur.tokens().iter().any(|t| { - t.kind == attr.token_kind && - t.spelling() == attr.name - }) + // `attr.name` and` attr.token_kind` are checked against unexposed attributes only. + if attr.kind.map_or(false, |k| k == kind) || + (kind == CXCursor_UnexposedAttr && + cur.tokens().iter().any(|t| { + t.kind == attr.token_kind && + t.spelling() == attr.name + })) { *found_attr = true; found_count += 1; From 2ffc8d8946a44f2a695a0c148ad24e7e0e9637d2 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Thu, 1 Sep 2022 15:59:37 -0500 Subject: [PATCH 349/942] handle c++ `[[noreturn]]` attribute --- src/clang.rs | 7 +++++++ src/ir/function.rs | 9 +++++++-- tests/expectations/tests/noreturn.rs | 10 ++++++++-- tests/headers/{noreturn.h => noreturn.hpp} | 1 + 4 files changed, 23 insertions(+), 4 deletions(-) rename tests/headers/{noreturn.h => noreturn.hpp} (86%) diff --git a/src/clang.rs b/src/clang.rs index fddb261c28..ea505c878b 100644 --- a/src/clang.rs +++ b/src/clang.rs @@ -37,6 +37,13 @@ impl Attribute { kind: None, token_kind: CXToken_Keyword, }; + + /// A `[[noreturn]]` attribute. + pub const NO_RETURN_CPP: Self = Self { + name: b"noreturn", + kind: None, + token_kind: CXToken_Identifier, + }; } /// A cursor into the Clang AST, pointing to an AST node. diff --git a/src/ir/function.rs b/src/ir/function.rs index 6ed3a5038e..a967954ee0 100644 --- a/src/ir/function.rs +++ b/src/ir/function.rs @@ -450,9 +450,14 @@ impl FunctionSig { } }; - let [must_use, is_divergent] = + let (must_use, is_divergent) = if ctx.options().enable_function_attribute_detection { - cursor.has_attrs(&[Attribute::MUST_USE, Attribute::NO_RETURN]) + let [must_use, no_return, no_return_cpp] = cursor.has_attrs(&[ + Attribute::MUST_USE, + Attribute::NO_RETURN, + Attribute::NO_RETURN_CPP, + ]); + (must_use, no_return || no_return_cpp) } else { Default::default() }; diff --git a/tests/expectations/tests/noreturn.rs b/tests/expectations/tests/noreturn.rs index fa81ee7621..1ffce9c060 100644 --- a/tests/expectations/tests/noreturn.rs +++ b/tests/expectations/tests/noreturn.rs @@ -6,8 +6,14 @@ )] extern "C" { - pub fn f() -> !; + #[link_name = "\u{1}_Z1fv"] + pub fn f() -> !; } extern "C" { - pub fn g(); + #[link_name = "\u{1}_Z1gv"] + pub fn g(); +} +extern "C" { + #[link_name = "\u{1}_Z1hv"] + pub fn h() -> !; } diff --git a/tests/headers/noreturn.h b/tests/headers/noreturn.hpp similarity index 86% rename from tests/headers/noreturn.h rename to tests/headers/noreturn.hpp index 0e4819e2a4..deaa3b1ace 100644 --- a/tests/headers/noreturn.h +++ b/tests/headers/noreturn.hpp @@ -2,3 +2,4 @@ _Noreturn void f(void); // TODO (pvdrz): figure out how to handle this case. __attribute__((noreturn)) void g(void); +[[noreturn]] void h(void); From 953acc526a808dac53660cee79c68d15ac309a63 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Thu, 1 Sep 2022 16:11:05 -0500 Subject: [PATCH 350/942] handle `__attribute__((noreturn))` attribute --- src/ir/function.rs | 7 ++++++- tests/expectations/tests/noreturn.rs | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/ir/function.rs b/src/ir/function.rs index a967954ee0..928b5aad37 100644 --- a/src/ir/function.rs +++ b/src/ir/function.rs @@ -450,7 +450,7 @@ impl FunctionSig { } }; - let (must_use, is_divergent) = + let (must_use, mut is_divergent) = if ctx.options().enable_function_attribute_detection { let [must_use, no_return, no_return_cpp] = cursor.has_attrs(&[ Attribute::MUST_USE, @@ -462,6 +462,11 @@ impl FunctionSig { Default::default() }; + // This looks easy to break but the clang parser keeps the type spelling clean even if + // other attributes are added. + is_divergent = + is_divergent || ty.spelling().contains("__attribute__((noreturn))"); + let is_method = kind == CXCursor_CXXMethod; let is_constructor = kind == CXCursor_Constructor; let is_destructor = kind == CXCursor_Destructor; diff --git a/tests/expectations/tests/noreturn.rs b/tests/expectations/tests/noreturn.rs index 1ffce9c060..1945749518 100644 --- a/tests/expectations/tests/noreturn.rs +++ b/tests/expectations/tests/noreturn.rs @@ -11,7 +11,7 @@ extern "C" { } extern "C" { #[link_name = "\u{1}_Z1gv"] - pub fn g(); + pub fn g() -> !; } extern "C" { #[link_name = "\u{1}_Z1hv"] From 86f059f081160ba01de31fc2ec6e20e52b97968d Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Thu, 1 Sep 2022 16:24:38 -0500 Subject: [PATCH 351/942] add the `-- -std=c++11` flag --- tests/headers/noreturn.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/headers/noreturn.hpp b/tests/headers/noreturn.hpp index deaa3b1ace..4ce1e11e3f 100644 --- a/tests/headers/noreturn.hpp +++ b/tests/headers/noreturn.hpp @@ -1,5 +1,4 @@ -// bindgen-flags: --enable-function-attribute-detection +// bindgen-flags: --enable-function-attribute-detection -- -std=c++11 _Noreturn void f(void); -// TODO (pvdrz): figure out how to handle this case. __attribute__((noreturn)) void g(void); [[noreturn]] void h(void); From 04c0cd0ff45ff3f47d845c2b3b983e2dc06b9ca3 Mon Sep 17 00:00:00 2001 From: Poliorcetics Date: Fri, 23 Sep 2022 08:30:49 +0200 Subject: [PATCH 352/942] Option to wrap union members in ManuallyDrop (#2185) --- src/codegen/mod.rs | 153 ++++++++--- src/lib.rs | 59 ++++- src/options.rs | 61 ++++- .../tests/union_with_non_copy_member.rs | 239 ++++++++++++++++++ tests/headers/union_with_non_copy_member.h | 20 ++ 5 files changed, 499 insertions(+), 33 deletions(-) create mode 100644 tests/expectations/tests/union_with_non_copy_member.rs create mode 100644 tests/headers/union_with_non_copy_member.h diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index f1422d6b53..98ab922a10 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -1231,7 +1231,7 @@ trait FieldCodegen<'a> { } impl<'a> FieldCodegen<'a> for Field { - type Extra = (); + type Extra = &'a str; fn codegen( &self, @@ -1244,7 +1244,7 @@ impl<'a> FieldCodegen<'a> for Field { struct_layout: &mut StructLayoutTracker, fields: &mut F, methods: &mut M, - _: (), + parent_canonical_name: Self::Extra, ) where F: Extend, M: Extend, @@ -1261,7 +1261,7 @@ impl<'a> FieldCodegen<'a> for Field { struct_layout, fields, methods, - (), + parent_canonical_name, ); } Field::Bitfields(ref unit) => { @@ -1275,7 +1275,7 @@ impl<'a> FieldCodegen<'a> for Field { struct_layout, fields, methods, - (), + parent_canonical_name, ); } } @@ -1283,7 +1283,7 @@ impl<'a> FieldCodegen<'a> for Field { } impl<'a> FieldCodegen<'a> for FieldData { - type Extra = (); + type Extra = &'a str; fn codegen( &self, @@ -1296,7 +1296,7 @@ impl<'a> FieldCodegen<'a> for FieldData { struct_layout: &mut StructLayoutTracker, fields: &mut F, methods: &mut M, - _: (), + parent_canonical_name: Self::Extra, ) where F: Extend, M: Extend, @@ -1313,16 +1313,7 @@ impl<'a> FieldCodegen<'a> for FieldData { // NB: If supported, we use proper `union` types. let ty = if parent.is_union() && !struct_layout.is_rust_union() { - result.saw_bindgen_union(); - if ctx.options().enable_cxx_namespaces { - quote! { - root::__BindgenUnionField<#ty> - } - } else { - quote! { - __BindgenUnionField<#ty> - } - } + wrap_non_copy_type_for_union(ctx, parent_canonical_name, result, ty) } else if let Some(item) = field_ty.is_incomplete_array(ctx) { result.saw_incomplete_array(); @@ -1433,6 +1424,54 @@ impl<'a> FieldCodegen<'a> for FieldData { } } +fn wrap_non_copy_type_for_union( + ctx: &BindgenContext, + parent_canonical_name: &str, + result: &mut CodegenResult, + field_ty: proc_macro2::TokenStream, +) -> proc_macro2::TokenStream { + let union_style = union_style_from_ctx_and_name(ctx, parent_canonical_name); + + match union_style { + NonCopyUnionStyle::ManuallyDrop => { + if ctx.options().use_core { + quote! { + ::core::mem::ManuallyDrop<#field_ty> + } + } else { + quote! { + ::std::mem::ManuallyDrop<#field_ty> + } + } + } + NonCopyUnionStyle::BindgenWrapper => { + result.saw_bindgen_union(); + if ctx.options().enable_cxx_namespaces { + quote! { + root::__BindgenUnionField<#field_ty> + } + } else { + quote! { + __BindgenUnionField<#field_ty> + } + } + } + } +} + +fn union_style_from_ctx_and_name( + ctx: &BindgenContext, + canonical_name: &str, +) -> NonCopyUnionStyle { + if ctx.options().bindgen_wrapper_union.matches(canonical_name) { + NonCopyUnionStyle::BindgenWrapper + } else if ctx.options().manually_drop_union.matches(canonical_name) { + NonCopyUnionStyle::ManuallyDrop + } else { + ctx.options().default_non_copy_union_style + } +} + impl BitfieldUnit { /// Get the constructor name for this bitfield unit. fn ctor_name(&self) -> proc_macro2::TokenStream { @@ -1499,7 +1538,7 @@ fn access_specifier( } impl<'a> FieldCodegen<'a> for BitfieldUnit { - type Extra = (); + type Extra = &'a str; fn codegen( &self, @@ -1512,7 +1551,7 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit { struct_layout: &mut StructLayoutTracker, fields: &mut F, methods: &mut M, - _: (), + parent_canonical_name: Self::Extra, ) where F: Extend, M: Extend, @@ -1525,16 +1564,12 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit { let unit_field_ty = helpers::bitfield_unit(ctx, layout); let field_ty = { if parent.is_union() && !struct_layout.is_rust_union() { - result.saw_bindgen_union(); - if ctx.options().enable_cxx_namespaces { - quote! { - root::__BindgenUnionField<#unit_field_ty> - } - } else { - quote! { - __BindgenUnionField<#unit_field_ty> - } - } + wrap_non_copy_type_for_union( + ctx, + parent_canonical_name, + result, + unit_field_ty.clone(), + ) } else { unit_field_ty.clone() } @@ -1859,7 +1894,7 @@ impl CodeGenerator for CompInfo { &mut struct_layout, &mut fields, &mut methods, - (), + &canonical_name, ); } // Check whether an explicit padding field is needed @@ -1965,7 +2000,10 @@ impl CodeGenerator for CompInfo { explicit_align = Some(layout.align); } - if !struct_layout.is_rust_union() { + if !struct_layout.is_rust_union() && + union_style_from_ctx_and_name(ctx, &canonical_name) == + NonCopyUnionStyle::BindgenWrapper + { let ty = helpers::blob(ctx, layout); fields.push(quote! { pub bindgen_union_field: #ty , @@ -2092,6 +2130,15 @@ impl CodeGenerator for CompInfo { #( #attributes )* pub union #canonical_ident } + } else if is_union && + !struct_layout.is_rust_union() && + union_style_from_ctx_and_name(ctx, &canonical_name) == + NonCopyUnionStyle::ManuallyDrop + { + quote! { + #( #attributes )* + pub union #canonical_ident + } } else { quote! { #( #attributes )* @@ -3398,6 +3445,52 @@ impl std::str::FromStr for AliasVariation { } } +/// Enum for how non-Copy unions should be translated. +#[derive(Copy, Clone, PartialEq, Debug)] +pub enum NonCopyUnionStyle { + /// Wrap members in a type generated by bindgen. + BindgenWrapper, + /// Wrap members in [`::core::mem::ManuallyDrop`]. + /// + /// Note: `ManuallyDrop` was stabilized in Rust 1.20.0, do not use it if your + /// MSRV is lower. + ManuallyDrop, +} + +impl NonCopyUnionStyle { + /// Convert an `NonCopyUnionStyle` to its str representation. + pub fn as_str(&self) -> &'static str { + match self { + Self::BindgenWrapper => "bindgen_wrapper", + Self::ManuallyDrop => "manually_drop", + } + } +} + +impl Default for NonCopyUnionStyle { + fn default() -> Self { + Self::BindgenWrapper + } +} + +impl std::str::FromStr for NonCopyUnionStyle { + type Err = std::io::Error; + + fn from_str(s: &str) -> Result { + match s { + "bindgen_wrapper" => Ok(Self::BindgenWrapper), + "manually_drop" => Ok(Self::ManuallyDrop), + _ => Err(std::io::Error::new( + std::io::ErrorKind::InvalidInput, + concat!( + "Got an invalid NonCopyUnionStyle. Accepted values ", + "are 'bindgen_wrapper' and 'manually_drop'" + ), + )), + } + } +} + /// Fallible conversion to an opaque blob. /// /// Implementors of this trait should provide the `try_get_layout` method to diff --git a/src/lib.rs b/src/lib.rs index 8c41565ab0..c7fccb98f8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -66,7 +66,9 @@ doc_mod!(ir, ir_docs); doc_mod!(parse, parse_docs); doc_mod!(regex_set, regex_set_docs); -pub use crate::codegen::{AliasVariation, EnumVariation, MacroTypeVariation}; +pub use crate::codegen::{ + AliasVariation, EnumVariation, MacroTypeVariation, NonCopyUnionStyle, +}; use crate::features::RustFeatures; pub use crate::features::{ RustTarget, LATEST_STABLE_RUST, RUST_TARGET_STRINGS, @@ -312,6 +314,13 @@ impl Builder { .push(self.options.default_alias_style.as_str().into()); } + if self.options.default_non_copy_union_style != Default::default() { + output_vector.push("--default-non-copy-union-style".into()); + output_vector.push( + self.options.default_non_copy_union_style.as_str().into(), + ); + } + let regex_sets = &[ (&self.options.bitfield_enums, "--bitfield-enum"), (&self.options.newtype_enums, "--newtype-enum"), @@ -329,6 +338,11 @@ impl Builder { (&self.options.type_alias, "--type-alias"), (&self.options.new_type_alias, "--new-type-alias"), (&self.options.new_type_alias_deref, "--new-type-alias-deref"), + ( + &self.options.bindgen_wrapper_union, + "--bindgen-wrapper-union", + ), + (&self.options.manually_drop_union, "--manually-drop-union"), (&self.options.blocklisted_types, "--blocklist-type"), (&self.options.blocklisted_functions, "--blocklist-function"), (&self.options.blocklisted_items, "--blocklist-item"), @@ -1101,6 +1115,32 @@ impl Builder { self } + /// Set the default style of code to generate for unions with a non-Copy member. + pub fn default_non_copy_union_style( + mut self, + arg: codegen::NonCopyUnionStyle, + ) -> Self { + self.options.default_non_copy_union_style = arg; + self + } + + /// Mark the given union (or set of union, if using a pattern) to use + /// a bindgen-generated wrapper for its members if at least one is non-Copy. + pub fn bindgen_wrapper_union>(mut self, arg: T) -> Self { + self.options.bindgen_wrapper_union.insert(arg); + self + } + + /// Mark the given union (or set of union, if using a pattern) to use + /// [`::core::mem::ManuallyDrop`] for its members if at least one is non-Copy. + /// + /// Note: `ManuallyDrop` was stabilized in Rust 1.20.0, do not use it if your + /// MSRV is lower. + pub fn manually_drop_union>(mut self, arg: T) -> Self { + self.options.manually_drop_union.insert(arg); + self + } + /// Add a string to prepend to the generated bindings. The string is passed /// through without any modification. pub fn raw_line>(mut self, arg: T) -> Self { @@ -1811,6 +1851,18 @@ struct BindgenOptions { /// Deref and Deref to their aliased type. new_type_alias_deref: RegexSet, + /// The default style of code to generate for union containing non-Copy + /// members. + default_non_copy_union_style: codegen::NonCopyUnionStyle, + + /// The union patterns to mark an non-Copy union as using the bindgen + /// generated wrapper. + bindgen_wrapper_union: RegexSet, + + /// The union patterns to mark an non-Copy union as using the + /// `::core::mem::ManuallyDrop` wrapper. + manually_drop_union: RegexSet, + /// Whether we should generate builtins or not. builtins: bool, @@ -2079,6 +2131,8 @@ impl BindgenOptions { &mut self.type_alias, &mut self.new_type_alias, &mut self.new_type_alias_deref, + &mut self.bindgen_wrapper_union, + &mut self.manually_drop_union, &mut self.no_partialeq_types, &mut self.no_copy_types, &mut self.no_debug_types, @@ -2137,6 +2191,9 @@ impl Default for BindgenOptions { type_alias: Default::default(), new_type_alias: Default::default(), new_type_alias_deref: Default::default(), + default_non_copy_union_style: Default::default(), + bindgen_wrapper_union: Default::default(), + manually_drop_union: Default::default(), builtins: false, emit_ast: false, emit_ir: false, diff --git a/src/options.rs b/src/options.rs index 4db3fd5766..1e87b6ebe4 100644 --- a/src/options.rs +++ b/src/options.rs @@ -1,7 +1,7 @@ use bindgen::{ builder, AliasVariation, Builder, CodegenConfig, EnumVariation, - MacroTypeVariation, RustTarget, DEFAULT_ANON_FIELDS_PREFIX, - RUST_TARGET_STRINGS, + MacroTypeVariation, NonCopyUnionStyle, RustTarget, + DEFAULT_ANON_FIELDS_PREFIX, RUST_TARGET_STRINGS, }; use clap::{App, Arg}; use std::fs::File; @@ -138,6 +138,42 @@ where .value_name("regex") .multiple_occurrences(true) .number_of_values(1), + Arg::new("default-non-copy-union-style") + .long("default-non-copy-union-style") + .help( + "The default style of code used to generate unions with \ + non-Copy members. Note that ManuallyDrop was first \ + stabilized in Rust 1.20.0.", + ) + .value_name("style") + .default_value("bindgen_wrapper") + .possible_values(&[ + "bindgen_wrapper", + "manually_drop", + ]) + .multiple_occurrences(false), + Arg::new("bindgen-wrapper-union") + .long("bindgen-wrapper-union") + .help( + "Mark any union whose name matches and who has a \ + non-Copy member to use a bindgen-generated wrapper for \ + fields.", + ) + .value_name("regex") + .takes_value(true) + .multiple_occurrences(true) + .number_of_values(1), + Arg::new("manually-drop-union") + .long("manually-drop-union") + .help( + "Mark any union whose name matches and who has a \ + non-Copy member to use ManuallyDrop (stabilized in Rust \ + 1.20.0) for fields.", + ) + .value_name("regex") + .takes_value(true) + .multiple_occurrences(true) + .number_of_values(1), Arg::new("blocklist-type") .alias("blacklist-type") .long("blocklist-type") @@ -631,6 +667,27 @@ where } } + if let Some(variant) = matches.value_of("default-non-copy-union-style") { + builder = builder.default_non_copy_union_style( + NonCopyUnionStyle::from_str(variant)?, + ); + } + + if let Some(bindgen_wrapper_union) = + matches.values_of("bindgen-wrapper-union") + { + for regex in bindgen_wrapper_union { + builder = builder.bindgen_wrapper_union(regex); + } + } + + if let Some(manually_drop_union) = matches.values_of("manually-drop-union") + { + for regex in manually_drop_union { + builder = builder.manually_drop_union(regex); + } + } + if let Some(hidden_types) = matches.values_of("blocklist-type") { for ty in hidden_types { builder = builder.blocklist_type(ty); diff --git a/tests/expectations/tests/union_with_non_copy_member.rs b/tests/expectations/tests/union_with_non_copy_member.rs new file mode 100644 index 0000000000..3c500b2106 --- /dev/null +++ b/tests/expectations/tests/union_with_non_copy_member.rs @@ -0,0 +1,239 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +pub struct __BindgenUnionField(::std::marker::PhantomData); +impl __BindgenUnionField { + #[inline] + pub const fn new() -> Self { + __BindgenUnionField(::std::marker::PhantomData) + } + #[inline] + pub unsafe fn as_ref(&self) -> &T { + ::std::mem::transmute(self) + } + #[inline] + pub unsafe fn as_mut(&mut self) -> &mut T { + ::std::mem::transmute(self) + } +} +impl ::std::default::Default for __BindgenUnionField { + #[inline] + fn default() -> Self { + Self::new() + } +} +impl ::std::clone::Clone for __BindgenUnionField { + #[inline] + fn clone(&self) -> Self { + Self::new() + } +} +impl ::std::marker::Copy for __BindgenUnionField {} +impl ::std::fmt::Debug for __BindgenUnionField { + fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + fmt.write_str("__BindgenUnionField") + } +} +impl ::std::hash::Hash for __BindgenUnionField { + fn hash(&self, _state: &mut H) {} +} +impl ::std::cmp::PartialEq for __BindgenUnionField { + fn eq(&self, _other: &__BindgenUnionField) -> bool { + true + } +} +impl ::std::cmp::Eq for __BindgenUnionField {} +#[repr(C)] +#[derive(Debug, Default)] +pub struct NonCopyType { + pub foo: ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout_NonCopyType() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(NonCopyType)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(NonCopyType)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(NonCopyType), + "::", + stringify!(foo) + ) + ); +} +#[repr(C)] +pub struct WithBindgenGeneratedWrapper { + pub non_copy_type: __BindgenUnionField, + pub bar: __BindgenUnionField<::std::os::raw::c_int>, + pub bindgen_union_field: u32, +} +#[test] +fn bindgen_test_layout_WithBindgenGeneratedWrapper() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(WithBindgenGeneratedWrapper)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(WithBindgenGeneratedWrapper)) + ); + assert_eq!( + unsafe { + ::std::ptr::addr_of!((*ptr).non_copy_type) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithBindgenGeneratedWrapper), + "::", + stringify!(non_copy_type) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithBindgenGeneratedWrapper), + "::", + stringify!(bar) + ) + ); +} +impl Default for WithBindgenGeneratedWrapper { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] +pub union WithManuallyDrop { + pub non_copy_type: ::std::mem::ManuallyDrop, + pub bar: ::std::mem::ManuallyDrop<::std::os::raw::c_int>, +} +#[test] +fn bindgen_test_layout_WithManuallyDrop() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(WithManuallyDrop)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(WithManuallyDrop)) + ); + assert_eq!( + unsafe { + ::std::ptr::addr_of!((*ptr).non_copy_type) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithManuallyDrop), + "::", + stringify!(non_copy_type) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithManuallyDrop), + "::", + stringify!(bar) + ) + ); +} +impl Default for WithManuallyDrop { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] +pub struct WithDefaultWrapper { + pub non_copy_type: __BindgenUnionField, + pub bar: __BindgenUnionField<::std::os::raw::c_int>, + pub bindgen_union_field: u32, +} +#[test] +fn bindgen_test_layout_WithDefaultWrapper() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(WithDefaultWrapper)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(WithDefaultWrapper)) + ); + assert_eq!( + unsafe { + ::std::ptr::addr_of!((*ptr).non_copy_type) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithDefaultWrapper), + "::", + stringify!(non_copy_type) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithDefaultWrapper), + "::", + stringify!(bar) + ) + ); +} +impl Default for WithDefaultWrapper { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} diff --git a/tests/headers/union_with_non_copy_member.h b/tests/headers/union_with_non_copy_member.h new file mode 100644 index 0000000000..764820a46d --- /dev/null +++ b/tests/headers/union_with_non_copy_member.h @@ -0,0 +1,20 @@ +// bindgen-flags: --bindgen-wrapper-union 'WithBindgenGeneratedWrapper' --manually-drop-union 'WithManuallyDrop' --no-copy 'NonCopyType' + +struct NonCopyType { + int foo; +}; + +union WithBindgenGeneratedWrapper { + struct NonCopyType non_copy_type; + int bar; +}; + +union WithManuallyDrop { + struct NonCopyType non_copy_type; + int bar; +}; + +union WithDefaultWrapper { + struct NonCopyType non_copy_type; + int bar; +}; From 4b006da21bd7a6701c8e7f658085569830207c9c Mon Sep 17 00:00:00 2001 From: Christian Poveda <31802960+pvdrz@users.noreply.github.com> Date: Fri, 23 Sep 2022 02:04:28 -0500 Subject: [PATCH 353/942] Add option to deduplicate extern blocks (#2258) --- src/lib.rs | 73 ++++++++++++++++++- src/options.rs | 7 ++ .../expectations/tests/merge-extern-blocks.rs | 37 ++++++++++ tests/headers/merge-extern-blocks.h | 6 ++ 4 files changed, 120 insertions(+), 3 deletions(-) create mode 100644 tests/expectations/tests/merge-extern-blocks.rs create mode 100644 tests/headers/merge-extern-blocks.h diff --git a/src/lib.rs b/src/lib.rs index c7fccb98f8..3c89368f11 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -615,6 +615,10 @@ impl Builder { output_vector.push("--sort-semantically".into()); } + if self.options.merge_extern_blocks { + output_vector.push("--merge-extern-blocks".into()); + } + // Add clang arguments output_vector.push("--".into()); @@ -1542,7 +1546,7 @@ impl Builder { self } - /// If true, enables the sorting of the output in a predefined manner + /// If true, enables the sorting of the output in a predefined manner. /// /// TODO: Perhaps move the sorting order out into a config pub fn sort_semantically(mut self, doit: bool) -> Self { @@ -1550,6 +1554,12 @@ impl Builder { self } + /// If true, merges extern blocks. + pub fn merge_extern_blocks(mut self, doit: bool) -> Self { + self.options.merge_extern_blocks = doit; + self + } + /// Generate the Rust bindings using the options built up thus far. pub fn generate(mut self) -> Result { // Add any extra arguments from the environment to the clang command line. @@ -2095,8 +2105,11 @@ struct BindgenOptions { /// Emit vtable functions. vtable_generation: bool, - /// Sort the code generation + /// Sort the code generation. sort_semantically: bool, + + /// Deduplicate `extern` blocks. + merge_extern_blocks: bool, } /// TODO(emilio): This is sort of a lie (see the error message that results from @@ -2107,7 +2120,7 @@ impl ::std::panic::UnwindSafe for BindgenOptions {} impl BindgenOptions { /// Whether any of the enabled options requires `syn`. fn require_syn(&self) -> bool { - self.sort_semantically + self.sort_semantically || self.merge_extern_blocks } fn build(&mut self) { @@ -2258,6 +2271,7 @@ impl Default for BindgenOptions { force_explicit_padding: false, vtable_generation: false, sort_semantically: false, + merge_extern_blocks: false, } } } @@ -2563,6 +2577,59 @@ impl Bindings { .unwrap() .1; + if options.merge_extern_blocks { + // Here we will store all the items after deduplication. + let mut items = Vec::new(); + + // Keep all the extern blocks in a different `Vec` for faster search. + let mut foreign_mods = Vec::::new(); + for item in syn_parsed_items { + match item { + syn::Item::ForeignMod(syn::ItemForeignMod { + attrs, + abi, + brace_token, + items: foreign_items, + }) => { + let mut exists = false; + for foreign_mod in &mut foreign_mods { + // Check if there is a extern block with the same ABI and + // attributes. + if foreign_mod.attrs == attrs && + foreign_mod.abi == abi + { + // Merge the items of the two blocks. + foreign_mod + .items + .extend_from_slice(&foreign_items); + exists = true; + break; + } + } + // If no existing extern block had the same ABI and attributes, store + // it. + if !exists { + foreign_mods.push(syn::ItemForeignMod { + attrs, + abi, + brace_token, + items: foreign_items, + }); + } + } + // If the item is not an extern block, we don't have to do anything. + _ => items.push(item), + } + } + + // Move all the extern blocks alongiside the rest of the items. + for foreign_mod in foreign_mods { + items.push(syn::Item::ForeignMod(foreign_mod)); + } + + syn_parsed_items = items; + } + if options.sort_semantically { syn_parsed_items.sort_by_key(|item| match item { syn::Item::Type(_) => 0, diff --git a/src/options.rs b/src/options.rs index 1e87b6ebe4..f707ab9bdf 100644 --- a/src/options.rs +++ b/src/options.rs @@ -560,6 +560,9 @@ where Arg::new("sort-semantically") .long("sort-semantically") .help("Enables sorting of code generation in a predefined manner."), + Arg::new("merge-extern-blocks") + .long("merge-extern-blocks") + .help("Deduplicates extern blocks."), Arg::new("V") .long("version") .help("Prints the version, and exits"), @@ -1076,5 +1079,9 @@ where builder = builder.sort_semantically(true); } + if matches.is_present("merge-extern-blocks") { + builder = builder.merge_extern_blocks(true); + } + Ok((builder, output, verbose)) } diff --git a/tests/expectations/tests/merge-extern-blocks.rs b/tests/expectations/tests/merge-extern-blocks.rs new file mode 100644 index 0000000000..66ceeff07f --- /dev/null +++ b/tests/expectations/tests/merge-extern-blocks.rs @@ -0,0 +1,37 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Point { + pub x: ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout_Point() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Point)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Point)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Point), "::", stringify!(x)) + ); +} +extern "C" { + pub fn foo() -> ::std::os::raw::c_int; + pub fn bar() -> ::std::os::raw::c_int; +} diff --git a/tests/headers/merge-extern-blocks.h b/tests/headers/merge-extern-blocks.h new file mode 100644 index 0000000000..1d46b7d4a3 --- /dev/null +++ b/tests/headers/merge-extern-blocks.h @@ -0,0 +1,6 @@ +// bindgen-flags: --merge-extern-blocks -- --target=x86_64-unknown-linux +int foo(); +typedef struct Point { + int x; +} Point; +int bar(); From af12c29026517b4bb9ddef58fec23a7e8142fe0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 22 Sep 2022 20:53:50 -1000 Subject: [PATCH 354/942] codegen: Implement manuallydrop fields better. This doesn't change behavior but makes the code make more sense. --- src/codegen/mod.rs | 133 +++++++++++++---------------------- src/codegen/struct_layout.rs | 10 ++- src/ir/comp.rs | 35 ++++++--- 3 files changed, 84 insertions(+), 94 deletions(-) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 98ab922a10..843d5111a1 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -1231,7 +1231,7 @@ trait FieldCodegen<'a> { } impl<'a> FieldCodegen<'a> for Field { - type Extra = &'a str; + type Extra = (); fn codegen( &self, @@ -1244,7 +1244,7 @@ impl<'a> FieldCodegen<'a> for Field { struct_layout: &mut StructLayoutTracker, fields: &mut F, methods: &mut M, - parent_canonical_name: Self::Extra, + _: (), ) where F: Extend, M: Extend, @@ -1261,7 +1261,7 @@ impl<'a> FieldCodegen<'a> for Field { struct_layout, fields, methods, - parent_canonical_name, + (), ); } Field::Bitfields(ref unit) => { @@ -1275,15 +1275,44 @@ impl<'a> FieldCodegen<'a> for Field { struct_layout, fields, methods, - parent_canonical_name, + (), ); } } } } +fn wrap_union_field_if_needed( + ctx: &BindgenContext, + struct_layout: &StructLayoutTracker, + ty: proc_macro2::TokenStream, + result: &mut CodegenResult, +) -> proc_macro2::TokenStream { + if struct_layout.is_rust_union() { + if struct_layout.can_copy_union_fields() { + ty + } else { + let prefix = ctx.trait_prefix(); + quote! { + ::#prefix::mem::ManuallyDrop<#ty> + } + } + } else { + result.saw_bindgen_union(); + if ctx.options().enable_cxx_namespaces { + quote! { + root::__BindgenUnionField<#ty> + } + } else { + quote! { + __BindgenUnionField<#ty> + } + } + } +} + impl<'a> FieldCodegen<'a> for FieldData { - type Extra = &'a str; + type Extra = (); fn codegen( &self, @@ -1296,7 +1325,7 @@ impl<'a> FieldCodegen<'a> for FieldData { struct_layout: &mut StructLayoutTracker, fields: &mut F, methods: &mut M, - parent_canonical_name: Self::Extra, + _: (), ) where F: Extend, M: Extend, @@ -1312,8 +1341,8 @@ impl<'a> FieldCodegen<'a> for FieldData { ty.append_implicit_template_params(ctx, field_item); // NB: If supported, we use proper `union` types. - let ty = if parent.is_union() && !struct_layout.is_rust_union() { - wrap_non_copy_type_for_union(ctx, parent_canonical_name, result, ty) + let ty = if parent.is_union() { + wrap_union_field_if_needed(ctx, struct_layout, ty, result) } else if let Some(item) = field_ty.is_incomplete_array(ctx) { result.saw_incomplete_array(); @@ -1424,54 +1453,6 @@ impl<'a> FieldCodegen<'a> for FieldData { } } -fn wrap_non_copy_type_for_union( - ctx: &BindgenContext, - parent_canonical_name: &str, - result: &mut CodegenResult, - field_ty: proc_macro2::TokenStream, -) -> proc_macro2::TokenStream { - let union_style = union_style_from_ctx_and_name(ctx, parent_canonical_name); - - match union_style { - NonCopyUnionStyle::ManuallyDrop => { - if ctx.options().use_core { - quote! { - ::core::mem::ManuallyDrop<#field_ty> - } - } else { - quote! { - ::std::mem::ManuallyDrop<#field_ty> - } - } - } - NonCopyUnionStyle::BindgenWrapper => { - result.saw_bindgen_union(); - if ctx.options().enable_cxx_namespaces { - quote! { - root::__BindgenUnionField<#field_ty> - } - } else { - quote! { - __BindgenUnionField<#field_ty> - } - } - } - } -} - -fn union_style_from_ctx_and_name( - ctx: &BindgenContext, - canonical_name: &str, -) -> NonCopyUnionStyle { - if ctx.options().bindgen_wrapper_union.matches(canonical_name) { - NonCopyUnionStyle::BindgenWrapper - } else if ctx.options().manually_drop_union.matches(canonical_name) { - NonCopyUnionStyle::ManuallyDrop - } else { - ctx.options().default_non_copy_union_style - } -} - impl BitfieldUnit { /// Get the constructor name for this bitfield unit. fn ctor_name(&self) -> proc_macro2::TokenStream { @@ -1538,7 +1519,7 @@ fn access_specifier( } impl<'a> FieldCodegen<'a> for BitfieldUnit { - type Extra = &'a str; + type Extra = (); fn codegen( &self, @@ -1551,7 +1532,7 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit { struct_layout: &mut StructLayoutTracker, fields: &mut F, methods: &mut M, - parent_canonical_name: Self::Extra, + _: (), ) where F: Extend, M: Extend, @@ -1562,17 +1543,15 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit { let layout = self.layout(); let unit_field_ty = helpers::bitfield_unit(ctx, layout); - let field_ty = { - if parent.is_union() && !struct_layout.is_rust_union() { - wrap_non_copy_type_for_union( - ctx, - parent_canonical_name, - result, - unit_field_ty.clone(), - ) - } else { - unit_field_ty.clone() - } + let field_ty = if parent.is_union() { + wrap_union_field_if_needed( + ctx, + struct_layout, + unit_field_ty.clone(), + result, + ) + } else { + unit_field_ty.clone() }; { @@ -1894,7 +1873,7 @@ impl CodeGenerator for CompInfo { &mut struct_layout, &mut fields, &mut methods, - &canonical_name, + (), ); } // Check whether an explicit padding field is needed @@ -2000,10 +1979,7 @@ impl CodeGenerator for CompInfo { explicit_align = Some(layout.align); } - if !struct_layout.is_rust_union() && - union_style_from_ctx_and_name(ctx, &canonical_name) == - NonCopyUnionStyle::BindgenWrapper - { + if !struct_layout.is_rust_union() { let ty = helpers::blob(ctx, layout); fields.push(quote! { pub bindgen_union_field: #ty , @@ -2130,15 +2106,6 @@ impl CodeGenerator for CompInfo { #( #attributes )* pub union #canonical_ident } - } else if is_union && - !struct_layout.is_rust_union() && - union_style_from_ctx_and_name(ctx, &canonical_name) == - NonCopyUnionStyle::ManuallyDrop - { - quote! { - #( #attributes )* - pub union #canonical_ident - } } else { quote! { #( #attributes )* diff --git a/src/codegen/struct_layout.rs b/src/codegen/struct_layout.rs index 657be0b489..ddac1b0abb 100644 --- a/src/codegen/struct_layout.rs +++ b/src/codegen/struct_layout.rs @@ -20,6 +20,7 @@ pub struct StructLayoutTracker<'a> { is_packed: bool, known_type_layout: Option, is_rust_union: bool, + can_copy_union_fields: bool, latest_offset: usize, padding_count: usize, latest_field_layout: Option, @@ -90,8 +91,8 @@ impl<'a> StructLayoutTracker<'a> { ) -> Self { let known_type_layout = ty.layout(ctx); let is_packed = comp.is_packed(ctx, known_type_layout.as_ref()); - let is_rust_union = comp.is_union() && - comp.can_be_rust_union(ctx, known_type_layout.as_ref()); + let (is_rust_union, can_copy_union_fields) = + comp.is_rust_union(ctx, known_type_layout.as_ref(), name); StructLayoutTracker { name, ctx, @@ -99,6 +100,7 @@ impl<'a> StructLayoutTracker<'a> { is_packed, known_type_layout, is_rust_union, + can_copy_union_fields, latest_offset: 0, padding_count: 0, latest_field_layout: None, @@ -107,6 +109,10 @@ impl<'a> StructLayoutTracker<'a> { } } + pub fn can_copy_union_fields(&self) -> bool { + self.can_copy_union_fields + } + pub fn is_rust_union(&self) -> bool { self.is_rust_union } diff --git a/src/ir/comp.rs b/src/ir/comp.rs index fdf6a9632c..f44c5d6725 100644 --- a/src/ir/comp.rs +++ b/src/ir/comp.rs @@ -14,6 +14,7 @@ use crate::codegen::struct_layout::{align_to, bytes_from_bits_pow2}; use crate::ir::derive::CanDeriveCopy; use crate::parse::{ClangItemParser, ParseError}; use crate::HashMap; +use crate::NonCopyUnionStyle; use peeking_take_while::PeekableExt; use std::cmp; use std::io; @@ -1680,21 +1681,37 @@ impl CompInfo { /// /// Requirements: /// 1. Current RustTarget allows for `untagged_union` - /// 2. Each field can derive `Copy` + /// 2. Each field can derive `Copy` or we use ManuallyDrop. /// 3. It's not zero-sized. - pub fn can_be_rust_union( + /// + /// Second boolean returns whether all fields can be copied (and thus + /// ManuallyDrop is not needed). + pub fn is_rust_union( &self, ctx: &BindgenContext, layout: Option<&Layout>, - ) -> bool { + name: &str, + ) -> (bool, bool) { + if !self.is_union() { + return (false, false); + } + if !ctx.options().rust_features().untagged_union { - return false; + return (false, false); } if self.is_forward_declaration() { - return false; + return (false, false); } + let union_style = if ctx.options().bindgen_wrapper_union.matches(name) { + NonCopyUnionStyle::BindgenWrapper + } else if ctx.options().manually_drop_union.matches(name) { + NonCopyUnionStyle::ManuallyDrop + } else { + ctx.options().default_non_copy_union_style + }; + let all_can_copy = self.fields().iter().all(|f| match *f { Field::DataMember(ref field_data) => { field_data.ty().can_derive_copy(ctx) @@ -1702,15 +1719,15 @@ impl CompInfo { Field::Bitfields(_) => true, }); - if !all_can_copy { - return false; + if !all_can_copy && union_style == NonCopyUnionStyle::BindgenWrapper { + return (false, false); } if layout.map_or(false, |l| l.size == 0) { - return false; + return (false, false); } - true + (true, all_can_copy) } } From c84897d33846b4cf0d8494e20326cbc6fc3bb0d8 Mon Sep 17 00:00:00 2001 From: Amanjeev Sethi Date: Mon, 19 Sep 2022 19:26:44 -0400 Subject: [PATCH 355/942] test: add test for GH-422 GitHub issue 422 was fixed but needs a test. https://github.com/rust-lang/rust-bindgen/issues/422 Signed-off-by: Amanjeev Sethi --- .../expectations/tests/inner-typedef-gh422.rs | 37 +++++++++++++++++++ tests/headers/inner-typedef-gh422.hpp | 11 ++++++ 2 files changed, 48 insertions(+) create mode 100644 tests/expectations/tests/inner-typedef-gh422.rs create mode 100644 tests/headers/inner-typedef-gh422.hpp diff --git a/tests/expectations/tests/inner-typedef-gh422.rs b/tests/expectations/tests/inner-typedef-gh422.rs new file mode 100644 index 0000000000..1cfa549c32 --- /dev/null +++ b/tests/expectations/tests/inner-typedef-gh422.rs @@ -0,0 +1,37 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Foo { + pub _address: u8, +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct Foo_InnerType { + pub t: T, + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, +} +impl Default for Foo_InnerType { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +pub type Bar = InnerType; +extern "C" { + #[link_name = "\u{1}_Z4funcv"] + pub fn func() -> Bar; +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct InnerType { + pub _address: u8, +} diff --git a/tests/headers/inner-typedef-gh422.hpp b/tests/headers/inner-typedef-gh422.hpp new file mode 100644 index 0000000000..301630a5e0 --- /dev/null +++ b/tests/headers/inner-typedef-gh422.hpp @@ -0,0 +1,11 @@ +template +class Foo { +public: + class InnerType { + T t; + }; +}; + +typedef Foo::InnerType Bar; + +Bar func(); \ No newline at end of file From 3ec5c8746204ad82bfbf0239d3e9d95d92c2e331 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Wed, 7 Sep 2022 15:37:48 -0500 Subject: [PATCH 356/942] use `#[feature(core_ffi_c)]` when available --- src/codegen/helpers.rs | 16 +++++++++++++--- src/features.rs | 2 ++ tests/expectations/tests/core_ffi_c.rs | 20 ++++++++++++++++++++ tests/headers/core_ffi_c.h | 14 ++++++++++++++ 4 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 tests/expectations/tests/core_ffi_c.rs create mode 100644 tests/headers/core_ffi_c.h diff --git a/src/codegen/helpers.rs b/src/codegen/helpers.rs index 75c169c67d..5bf36acb42 100644 --- a/src/codegen/helpers.rs +++ b/src/codegen/helpers.rs @@ -166,9 +166,19 @@ pub mod ast_ty { #prefix::#ident } } - None => quote! { - ::std::os::raw::#ident - }, + None => { + if ctx.options().use_core && + ctx.options().rust_features().core_ffi_c + { + quote! { + ::core::ffi::#ident + } + } else { + quote! { + ::std::os::raw::#ident + } + } + } } } diff --git a/src/features.rs b/src/features.rs index 594677036d..f18ffa88dd 100644 --- a/src/features.rs +++ b/src/features.rs @@ -130,6 +130,7 @@ macro_rules! rust_target_base { /// Nightly rust /// * `thiscall` calling convention ([Tracking issue](https://github.com/rust-lang/rust/issues/42202)) /// * `vectorcall` calling convention (no tracking issue) + /// * `core_ffi_c` ([Tracking issue](https://github.com/rust-lang/rust/issues/94501)) => Nightly => nightly; ); } @@ -236,6 +237,7 @@ rust_feature_def!( Nightly { => thiscall_abi; => vectorcall_abi; + => core_ffi_c; } ); diff --git a/tests/expectations/tests/core_ffi_c.rs b/tests/expectations/tests/core_ffi_c.rs new file mode 100644 index 0000000000..7e138a894f --- /dev/null +++ b/tests/expectations/tests/core_ffi_c.rs @@ -0,0 +1,20 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +pub type c_char = ::core::ffi::c_char; +pub type c_double = ::core::ffi::c_double; +pub type c_float = ::core::ffi::c_float; +pub type c_int = ::core::ffi::c_int; +pub type c_long = ::core::ffi::c_long; +pub type c_longlong = ::core::ffi::c_longlong; +pub type c_schar = ::core::ffi::c_schar; +pub type c_short = ::core::ffi::c_short; +pub type c_uchar = ::core::ffi::c_uchar; +pub type c_uint = ::core::ffi::c_uint; +pub type c_ulong = ::core::ffi::c_ulong; +pub type c_ulonglong = ::core::ffi::c_ulonglong; +pub type c_ushort = ::core::ffi::c_ushort; diff --git a/tests/headers/core_ffi_c.h b/tests/headers/core_ffi_c.h new file mode 100644 index 0000000000..3e180fd8cf --- /dev/null +++ b/tests/headers/core_ffi_c.h @@ -0,0 +1,14 @@ +// bindgen-flags: --rust-target nightly --use-core --no-convert-floats +typedef char c_char; +typedef double c_double; +typedef float c_float; +typedef int c_int; +typedef long c_long; +typedef long long c_longlong; +typedef signed char c_schar; +typedef short c_short; +typedef unsigned char c_uchar; +typedef unsigned int c_uint; +typedef unsigned long c_ulong; +typedef unsigned long long c_ulonglong; +typedef unsigned short c_ushort; From 995943ce06b0b8d59ceeb056844e474ee0ae644e Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Wed, 7 Sep 2022 15:45:11 -0500 Subject: [PATCH 357/942] put tests behind the `nightly` feature --- tests/expectations/tests/core_ffi_c.rs | 1 + tests/headers/core_ffi_c.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/expectations/tests/core_ffi_c.rs b/tests/expectations/tests/core_ffi_c.rs index 7e138a894f..4a74c83993 100644 --- a/tests/expectations/tests/core_ffi_c.rs +++ b/tests/expectations/tests/core_ffi_c.rs @@ -4,6 +4,7 @@ non_camel_case_types, non_upper_case_globals )] +#![cfg(feature = "nightly")] pub type c_char = ::core::ffi::c_char; pub type c_double = ::core::ffi::c_double; diff --git a/tests/headers/core_ffi_c.h b/tests/headers/core_ffi_c.h index 3e180fd8cf..06623138d5 100644 --- a/tests/headers/core_ffi_c.h +++ b/tests/headers/core_ffi_c.h @@ -1,4 +1,4 @@ -// bindgen-flags: --rust-target nightly --use-core --no-convert-floats +// bindgen-flags: --rust-target nightly --raw-line '#![cfg(feature = "nightly")]' --use-core --no-convert-floats typedef char c_char; typedef double c_double; typedef float c_float; From 0f3b8a840c4456d1db6d005cfdf52c0f6b9dcd81 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Thu, 22 Sep 2022 11:13:50 -0500 Subject: [PATCH 358/942] update to rust 1.64 --- src/features.rs | 8 ++++++-- tests/expectations/tests/core_ffi_c.rs | 1 - tests/headers/core_ffi_c.h | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/features.rs b/src/features.rs index f18ffa88dd..bb836ce8e0 100644 --- a/src/features.rs +++ b/src/features.rs @@ -127,10 +127,12 @@ macro_rules! rust_target_base { /// Rust stable 1.47 /// * `larger_arrays` ([Tracking issue](https://github.com/rust-lang/rust/pull/74060)) => Stable_1_47 => 1.47; + /// Rust stable 1.64 + /// * `core_ffi_c` ([Tracking issue](https://github.com/rust-lang/rust/issues/94501)) + => Stable_1_64 => 1.64; /// Nightly rust /// * `thiscall` calling convention ([Tracking issue](https://github.com/rust-lang/rust/issues/42202)) /// * `vectorcall` calling convention (no tracking issue) - /// * `core_ffi_c` ([Tracking issue](https://github.com/rust-lang/rust/issues/94501)) => Nightly => nightly; ); } @@ -234,10 +236,12 @@ rust_feature_def!( Stable_1_47 { => larger_arrays; } + Stable_1_64 { + => core_ffi_c; + } Nightly { => thiscall_abi; => vectorcall_abi; - => core_ffi_c; } ); diff --git a/tests/expectations/tests/core_ffi_c.rs b/tests/expectations/tests/core_ffi_c.rs index 4a74c83993..7e138a894f 100644 --- a/tests/expectations/tests/core_ffi_c.rs +++ b/tests/expectations/tests/core_ffi_c.rs @@ -4,7 +4,6 @@ non_camel_case_types, non_upper_case_globals )] -#![cfg(feature = "nightly")] pub type c_char = ::core::ffi::c_char; pub type c_double = ::core::ffi::c_double; diff --git a/tests/headers/core_ffi_c.h b/tests/headers/core_ffi_c.h index 06623138d5..6df1e2f87a 100644 --- a/tests/headers/core_ffi_c.h +++ b/tests/headers/core_ffi_c.h @@ -1,4 +1,4 @@ -// bindgen-flags: --rust-target nightly --raw-line '#![cfg(feature = "nightly")]' --use-core --no-convert-floats +// bindgen-flags: --use-core --rust-target 1.64 --no-convert-floats typedef char c_char; typedef double c_double; typedef float c_float; From 6de2d3d1c17bb4dd432daabf2cd858254663f49e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 22 Sep 2022 21:20:05 -1000 Subject: [PATCH 359/942] features: Bump LATEST_STABLE_RUST after #2267. --- src/features.rs | 2 +- tests/expectations/tests/use-core.rs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/features.rs b/src/features.rs index bb836ce8e0..4f05b9eb07 100644 --- a/src/features.rs +++ b/src/features.rs @@ -142,7 +142,7 @@ rust_target_base!(rust_target_def); rust_target_base!(rust_target_values_def); /// Latest stable release of Rust -pub const LATEST_STABLE_RUST: RustTarget = RustTarget::Stable_1_47; +pub const LATEST_STABLE_RUST: RustTarget = RustTarget::Stable_1_64; /// Create RustFeatures struct definition, new(), and a getter for each field macro_rules! rust_feature_def { diff --git a/tests/expectations/tests/use-core.rs b/tests/expectations/tests/use-core.rs index e6124d5aec..569e8d2470 100644 --- a/tests/expectations/tests/use-core.rs +++ b/tests/expectations/tests/use-core.rs @@ -10,8 +10,8 @@ extern crate core; #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct foo { - pub a: ::std::os::raw::c_int, - pub b: ::std::os::raw::c_int, + pub a: ::core::ffi::c_int, + pub b: ::core::ffi::c_int, pub bar: *mut ::core::ffi::c_void, } #[test] @@ -57,8 +57,8 @@ impl Default for foo { #[repr(C)] #[derive(Copy, Clone)] pub union _bindgen_ty_1 { - pub bar: ::std::os::raw::c_int, - pub baz: ::std::os::raw::c_long, + pub bar: ::core::ffi::c_int, + pub baz: ::core::ffi::c_long, } #[test] fn bindgen_test_layout__bindgen_ty_1() { @@ -109,4 +109,4 @@ extern "C" { pub static mut bazz: _bindgen_ty_1; } pub type fooFunction = - ::core::option::Option; + ::core::option::Option; From e1f314eb44b09268c6d05ff152f3ddd61e635135 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Fri, 23 Sep 2022 15:20:56 -0500 Subject: [PATCH 360/942] move codegen postprocessing to its own module --- src/codegen/mod.rs | 5 +- src/codegen/postprocessing.rs | 148 ++++++++++++++++++++++++++++++++++ src/lib.rs | 113 +------------------------- 3 files changed, 152 insertions(+), 114 deletions(-) create mode 100644 src/codegen/postprocessing.rs diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 843d5111a1..bc2c9fe21b 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -3,6 +3,7 @@ mod error; mod helpers; mod impl_debug; mod impl_partialeq; +mod postprocessing; pub mod struct_layout; #[cfg(test)] @@ -4414,7 +4415,7 @@ impl CodeGenerator for ObjCInterface { pub(crate) fn codegen( context: BindgenContext, -) -> (Vec, BindgenOptions, Vec) { +) -> (proc_macro2::TokenStream, BindgenOptions, Vec) { context.gen(|context| { let _t = context.timer("codegen"); let counter = Cell::new(0); @@ -4464,7 +4465,7 @@ pub(crate) fn codegen( result.push(dynamic_items_tokens); } - result.items + postprocessing::postprocessing(result.items, context.options()) }) } diff --git a/src/codegen/postprocessing.rs b/src/codegen/postprocessing.rs new file mode 100644 index 0000000000..728322980f --- /dev/null +++ b/src/codegen/postprocessing.rs @@ -0,0 +1,148 @@ +use proc_macro2::TokenStream; +use quote::ToTokens; +use syn::Item; + +use crate::BindgenOptions; + +macro_rules! decl_postprocessing { + ($($ty:ty),*) => { + pub(crate) fn postprocessing( + items: Vec, + options: &BindgenOptions, + ) -> TokenStream { + // Whether any of the enabled options requires `syn`. + let require_syn = $(<$ty as PostProcessing>::should_run(options))||*; + + if !require_syn { + return items.into_iter().collect(); + } + + let module_wrapped_tokens = + quote!(mod wrapper_for_sorting_hack { #( #items )* }); + + // This syn business is a hack, for now. This means that we are re-parsing already + // generated code using `syn` (as opposed to `quote`) because `syn` provides us more + // control over the elements. + // One caveat is that some of the items coming from `quote`d output might have + // multiple items within them. Hence, we have to wrap the incoming in a `mod`. + // The two `unwrap`s here are deliberate because + // The first one won't panic because we build the `mod` and know it is there + // The second one won't panic because we know original output has something in + // it already. + let mut items = + syn::parse2::(module_wrapped_tokens) + .unwrap() + .content + .unwrap() + .1; + + $(if <$ty as PostProcessing>::should_run(options) { + <$ty as PostProcessing>::run(&mut items); + })* + + let synful_items = items + .into_iter() + .map(|item| item.into_token_stream()); + + quote! { #( #synful_items )* } + } + }; +} + +decl_postprocessing! { + MergeExternBlocks, + SortSemantically +} + +trait PostProcessing { + fn should_run(options: &BindgenOptions) -> bool; + + fn run(items: &mut Vec); +} + +struct SortSemantically; + +impl PostProcessing for SortSemantically { + #[inline] + fn should_run(options: &BindgenOptions) -> bool { + options.sort_semantically + } + + fn run(items: &mut Vec) { + items.sort_by_key(|item| match item { + Item::Type(_) => 0, + Item::Struct(_) => 1, + Item::Const(_) => 2, + Item::Fn(_) => 3, + Item::Enum(_) => 4, + Item::Union(_) => 5, + Item::Static(_) => 6, + Item::Trait(_) => 7, + Item::TraitAlias(_) => 8, + Item::Impl(_) => 9, + Item::Mod(_) => 10, + Item::Use(_) => 11, + Item::Verbatim(_) => 12, + Item::ExternCrate(_) => 13, + Item::ForeignMod(_) => 14, + Item::Macro(_) => 15, + Item::Macro2(_) => 16, + _ => 18, + }); + } +} + +struct MergeExternBlocks; + +impl PostProcessing for MergeExternBlocks { + #[inline] + fn should_run(options: &BindgenOptions) -> bool { + options.merge_extern_blocks + } + + fn run(items: &mut Vec) { + // Keep all the extern blocks in a different `Vec` for faster search. + let mut foreign_mods = Vec::::new(); + + for item in std::mem::take(items) { + match item { + Item::ForeignMod(syn::ItemForeignMod { + attrs, + abi, + brace_token, + items: foreign_items, + }) => { + let mut exists = false; + for foreign_mod in &mut foreign_mods { + // Check if there is a extern block with the same ABI and + // attributes. + if foreign_mod.attrs == attrs && foreign_mod.abi == abi + { + // Merge the items of the two blocks. + foreign_mod.items.extend_from_slice(&foreign_items); + exists = true; + break; + } + } + // If no existing extern block had the same ABI and attributes, store + // it. + if !exists { + foreign_mods.push(syn::ItemForeignMod { + attrs, + abi, + brace_token, + items: foreign_items, + }); + } + } + // If the item is not an extern block, we don't have to do anything. + _ => items.push(item), + } + } + + // Move all the extern blocks alongiside the rest of the items. + for foreign_mod in foreign_mods { + items.push(Item::ForeignMod(foreign_mod)); + } + } +} diff --git a/src/lib.rs b/src/lib.rs index 3c89368f11..d0be8604d5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -88,7 +88,6 @@ use std::{env, iter}; // Some convenient typedefs for a fast hash map and hash set. type HashMap = ::rustc_hash::FxHashMap; type HashSet = ::rustc_hash::FxHashSet; -use quote::ToTokens; pub(crate) use std::collections::hash_map::Entry; /// Default prefix for the anon fields. @@ -2118,11 +2117,6 @@ struct BindgenOptions { impl ::std::panic::UnwindSafe for BindgenOptions {} impl BindgenOptions { - /// Whether any of the enabled options requires `syn`. - fn require_syn(&self) -> bool { - self.sort_semantically || self.merge_extern_blocks - } - fn build(&mut self) { let mut regex_sets = [ &mut self.allowlisted_vars, @@ -2555,112 +2549,7 @@ impl Bindings { parse(&mut context)?; } - let (items, options, warnings) = codegen::codegen(context); - - let module = if options.require_syn() { - let module_wrapped_tokens = - quote!(mod wrapper_for_sorting_hack { #( #items )* }); - - // This syn business is a hack, for now. This means that we are re-parsing already - // generated code using `syn` (as opposed to `quote`) because `syn` provides us more - // control over the elements. - // One caveat is that some of the items coming from `quote`d output might have - // multiple items within them. Hence, we have to wrap the incoming in a `mod`. - // The two `unwrap`s here are deliberate because - // The first one won't panic because we build the `mod` and know it is there - // The second one won't panic because we know original output has something in - // it already. - let mut syn_parsed_items = - syn::parse2::(module_wrapped_tokens) - .unwrap() - .content - .unwrap() - .1; - - if options.merge_extern_blocks { - // Here we will store all the items after deduplication. - let mut items = Vec::new(); - - // Keep all the extern blocks in a different `Vec` for faster search. - let mut foreign_mods = Vec::::new(); - for item in syn_parsed_items { - match item { - syn::Item::ForeignMod(syn::ItemForeignMod { - attrs, - abi, - brace_token, - items: foreign_items, - }) => { - let mut exists = false; - for foreign_mod in &mut foreign_mods { - // Check if there is a extern block with the same ABI and - // attributes. - if foreign_mod.attrs == attrs && - foreign_mod.abi == abi - { - // Merge the items of the two blocks. - foreign_mod - .items - .extend_from_slice(&foreign_items); - exists = true; - break; - } - } - // If no existing extern block had the same ABI and attributes, store - // it. - if !exists { - foreign_mods.push(syn::ItemForeignMod { - attrs, - abi, - brace_token, - items: foreign_items, - }); - } - } - // If the item is not an extern block, we don't have to do anything. - _ => items.push(item), - } - } - - // Move all the extern blocks alongiside the rest of the items. - for foreign_mod in foreign_mods { - items.push(syn::Item::ForeignMod(foreign_mod)); - } - - syn_parsed_items = items; - } - - if options.sort_semantically { - syn_parsed_items.sort_by_key(|item| match item { - syn::Item::Type(_) => 0, - syn::Item::Struct(_) => 1, - syn::Item::Const(_) => 2, - syn::Item::Fn(_) => 3, - syn::Item::Enum(_) => 4, - syn::Item::Union(_) => 5, - syn::Item::Static(_) => 6, - syn::Item::Trait(_) => 7, - syn::Item::TraitAlias(_) => 8, - syn::Item::Impl(_) => 9, - syn::Item::Mod(_) => 10, - syn::Item::Use(_) => 11, - syn::Item::Verbatim(_) => 12, - syn::Item::ExternCrate(_) => 13, - syn::Item::ForeignMod(_) => 14, - syn::Item::Macro(_) => 15, - syn::Item::Macro2(_) => 16, - _ => 18, - }); - } - - let synful_items = syn_parsed_items - .into_iter() - .map(|item| item.into_token_stream()); - - quote! { #( #synful_items )* } - } else { - quote! { #( #items )* } - }; + let (module, options, warnings) = codegen::codegen(context); Ok(Bindings { options, From 0e4c1ae92c8ab89bf2285cf3b4540821fb480850 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Fri, 23 Sep 2022 15:24:19 -0500 Subject: [PATCH 361/942] update `CONTRIBUTING.md` section about `syn` --- CONTRIBUTING.md | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2974ba4254..3d757ccdff 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -323,14 +323,12 @@ generated Rust code are implemented using the [`syn`](https://docs.rs/syn) crate ### Implementing new options using `syn` -Here is a list of recommendations to be followed if a new option can be -implemented using the `syn` crate: +If a new option can be implemented using the `syn` crate it should be added to +the `codegen::postprocessing` module by following these steps: -- The `BindgenOptions::require_syn` method must be updated to reflect that this - new option requires parsing the generated Rust code with `syn`. - -- The implementation of the new option should be added at the end of - `Bindings::generate`, inside the `if options.require_syn() { ... }` block. +- Introduce a new `struct` with no fields. +- Implement the `PostProcessing` trait for the `struct`. +- Add the `struct` to the `decl_postprocessing` macro invocation. ## Pull Requests and Code Reviews From cc78b6fdb6e829e5fb8fa1639f2182cb49333569 Mon Sep 17 00:00:00 2001 From: Geoffrey Thomas Date: Thu, 3 Jun 2021 10:47:26 -0400 Subject: [PATCH 362/942] Map size_t to usize by default and check compatibility (fixes #1901, #1903) This addresses the underlying issue identified in #1671, that size_t (integer that can hold any object size) isn't guaranteed to match usize, which is defined more like uintptr_t (integer that can hold any pointer). However, on almost all platforms, this is true, and in fact Rust already uses usize extensively in contexts where size_t would be more appropriate, such as slice indexing. So, it's better for ergonomics when interfacing with C code to map the C size_t type to usize. (See also discussion in rust-lang/rust#65473 about how usize really should be defined as size_t, not uintptr_t.) The previous fix for #1671 removed the special case for size_t and defaulted to binding it as a normal typedef. This change effectively reverts that and goes back to mapping size_t to usize (and ssize_t to isize), but also ensures that if size_t is emitted, the typedef'd type of size_t in fact is compatible with usize (defined by checking that the size and alignment match the target pointer width). For (hypothetical) platforms where this is not true, or for compatibility with the default behavior of bindgen between 0.53 and this commit, onwards, you can disable this mapping with --no-size_t-is-usize. --- asd.fish | 31 +++++++++++++++++++ src/codegen/mod.rs | 27 +++++++++++++++- src/lib.rs | 6 ++-- src/options.rs | 11 +++++-- tests/expectations/tests/blocks-signature.rs | 12 ++----- tests/expectations/tests/blocks.rs | 1 - tests/expectations/tests/issue-1498.rs | 3 +- .../expectations/tests/jsval_layout_opaque.rs | 3 +- .../tests/jsval_layout_opaque_1_0.rs | 3 +- tests/expectations/tests/layout_array.rs | 3 +- tests/expectations/tests/msvc-no-usr.rs | 3 +- ...ze_t_is_usize.rs => no_size_t_is_usize.rs} | 6 ++-- tests/expectations/tests/nsBaseHashtable.rs | 1 - ...size_t_is_usize.h => no_size_t_is_usize.h} | 2 +- 14 files changed, 81 insertions(+), 31 deletions(-) create mode 100644 asd.fish rename tests/expectations/tests/{size_t_is_usize.rs => no_size_t_is_usize.rs} (91%) rename tests/headers/{size_t_is_usize.h => no_size_t_is_usize.h} (75%) diff --git a/asd.fish b/asd.fish new file mode 100644 index 0000000000..b6c9a270e7 --- /dev/null +++ b/asd.fish @@ -0,0 +1,31 @@ +for name in (rg -lF addr_of! tests/expectations | sd '.*/(.*).rs' '$1') + set path (fd --glob "$name.*" tests/headers) + if test -n "$path" + + set flags (rg -F "// bindgen-flags" $path) + if test -n "$flags" + set minor (rg ".*\-\-rust\-target[ =]1.(\d+).*" $path -r '$1') + if test -n "$minor" + if test $minor -gt 47 + echo $path needs to change the version from 1.$minor to 1.47 + sd -s "1.$minor" "1.47" $path + else + echo $path uses version 1.$minor and that is fine + end + else + echo $path does not have the `--rust-target` flag + sd "// bindgen-flags: (.*)" '// bindgen-flags: --rust-target 1.47 $1' $path + end + else + echo $path does not have the flags at all + set contents (echo -e "// bindgen-flags: --rust-target 1.47\n"; cat $path) + rm $path + touch $path + for line in $contents + echo $line >> $path + end + end + else + echo $name headers not found + end +end diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 843d5111a1..8eb7b0134c 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -836,9 +836,34 @@ impl CodeGenerator for Type { } // If this is a known named type, disallow generating anything - // for it too. + // for it too. If size_t -> usize conversions are enabled, we + // need to check that these conversions are permissible, but + // nothing needs to be generated, still. let spelling = self.name().expect("Unnamed alias?"); if utils::type_from_named(ctx, spelling).is_some() { + if let "size_t" | "ssize_t" = spelling { + let layout = inner_item + .kind() + .expect_type() + .layout(ctx) + .expect("No layout?"); + assert_eq!( + layout.size, + ctx.target_pointer_size(), + "Target platform requires `--no-size_t-is-usize`. The size of `{}` ({}) does not match the target pointer size ({})", + spelling, + layout.size, + ctx.target_pointer_size(), + ); + assert_eq!( + layout.align, + ctx.target_pointer_size(), + "Target platform requires `--no-size_t-is-usize`. The alignment of `{}` ({}) does not match the target pointer size ({})", + spelling, + layout.align, + ctx.target_pointer_size(), + ); + } return; } diff --git a/src/lib.rs b/src/lib.rs index 3c89368f11..9a5887df8e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -564,8 +564,8 @@ impl Builder { output_vector.push("--no-record-matches".into()); } - if self.options.size_t_is_usize { - output_vector.push("--size_t-is-usize".into()); + if !self.options.size_t_is_usize { + output_vector.push("--no-size_t-is-usize".into()); } if !self.options.rustfmt_bindings { @@ -2253,7 +2253,7 @@ impl Default for BindgenOptions { time_phases: false, record_matches: true, rustfmt_bindings: true, - size_t_is_usize: false, + size_t_is_usize: true, rustfmt_configuration_file: None, no_partialeq_types: Default::default(), no_copy_types: Default::default(), diff --git a/src/options.rs b/src/options.rs index f707ab9bdf..29edb78b1c 100644 --- a/src/options.rs +++ b/src/options.rs @@ -465,7 +465,12 @@ where ), Arg::new("size_t-is-usize") .long("size_t-is-usize") - .help("Translate size_t to usize."), + .help("Ignored - this is enabled by default.") + .hidden(true), + Arg::with_name("no-size_t-is-usize") + .long("no-size_t-is-usize") + .help("Do not bind size_t as usize (useful on platforms \ + where those types are incompatible)."), Arg::new("no-rustfmt-bindings") .long("no-rustfmt-bindings") .help("Do not format the generated bindings with rustfmt."), @@ -975,8 +980,8 @@ where builder = builder.record_matches(false); } - if matches.is_present("size_t-is-usize") { - builder = builder.size_t_is_usize(true); + if matches.is_present("no-size_t-is-usize") { + builder = builder.size_t_is_usize(false); } let no_rustfmt_bindings = matches.is_present("no-rustfmt-bindings"); diff --git a/tests/expectations/tests/blocks-signature.rs b/tests/expectations/tests/blocks-signature.rs index 779d0ecbcc..ff7114a7d4 100644 --- a/tests/expectations/tests/blocks-signature.rs +++ b/tests/expectations/tests/blocks-signature.rs @@ -7,7 +7,6 @@ #![cfg(target_os = "macos")] extern crate block; -pub type size_t = ::std::os::raw::c_ulonglong; extern "C" { #[link_name = "\u{1}_Z8atexit_bU13block_pointerFvvE"] pub fn atexit_b(arg1: _bindgen_ty_id_33); @@ -82,16 +81,11 @@ impl Default for contains_block_pointers { } pub type _bindgen_ty_id_33 = *const ::block::Block<(), ()>; pub type _bindgen_ty_id_40 = *const ::block::Block< - ( - dispatch_data_t, - size_t, - *const ::std::os::raw::c_void, - size_t, - ), + (dispatch_data_t, usize, *const ::std::os::raw::c_void, usize), bool, >; -pub type _bindgen_ty_id_50 = *const ::block::Block<(size_t,), ()>; -pub type _bindgen_ty_id_56 = *const ::block::Block<(size_t,), ()>; +pub type _bindgen_ty_id_50 = *const ::block::Block<(usize,), ()>; +pub type _bindgen_ty_id_56 = *const ::block::Block<(usize,), ()>; pub type contains_block_pointers__bindgen_ty_id_61 = *const ::block::Block<(::std::os::raw::c_int,), ()>; pub type _bindgen_ty_id_68 = diff --git a/tests/expectations/tests/blocks.rs b/tests/expectations/tests/blocks.rs index dbafaf94c2..6f242989b6 100644 --- a/tests/expectations/tests/blocks.rs +++ b/tests/expectations/tests/blocks.rs @@ -6,7 +6,6 @@ )] #![cfg(target_os = "macos")] -pub type size_t = ::std::os::raw::c_ulonglong; extern "C" { #[link_name = "\u{1}_Z8atexit_bU13block_pointerFvvE"] pub fn atexit_b(arg1: *mut ::std::os::raw::c_void); diff --git a/tests/expectations/tests/issue-1498.rs b/tests/expectations/tests/issue-1498.rs index 08ba9ef42d..eb5e280457 100644 --- a/tests/expectations/tests/issue-1498.rs +++ b/tests/expectations/tests/issue-1498.rs @@ -5,7 +5,6 @@ non_upper_case_globals )] -pub type size_t = u64; #[repr(C, packed)] #[derive(Copy, Clone)] pub struct rte_memseg { @@ -13,7 +12,7 @@ pub struct rte_memseg { pub phys_addr: u64, pub __bindgen_anon_1: rte_memseg__bindgen_ty_1, ///< Length of the segment. - pub len: size_t, + pub len: usize, ///< The pagesize of underlying memory pub hugepage_sz: u64, ///< NUMA socket ID. diff --git a/tests/expectations/tests/jsval_layout_opaque.rs b/tests/expectations/tests/jsval_layout_opaque.rs index 2873f6a2ff..a812e90560 100644 --- a/tests/expectations/tests/jsval_layout_opaque.rs +++ b/tests/expectations/tests/jsval_layout_opaque.rs @@ -94,7 +94,6 @@ where pub const JSVAL_TAG_SHIFT: u32 = 47; pub const JSVAL_PAYLOAD_MASK: u64 = 140737488355327; pub const JSVAL_TAG_MASK: i64 = -140737488355328; -pub type size_t = ::std::os::raw::c_ulonglong; #[repr(u8)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum JSValueType { @@ -186,7 +185,7 @@ pub union jsval_layout { pub s: jsval_layout__bindgen_ty_2, pub asDouble: f64, pub asPtr: *mut ::std::os::raw::c_void, - pub asWord: size_t, + pub asWord: usize, pub asUIntPtr: usize, } #[repr(C)] diff --git a/tests/expectations/tests/jsval_layout_opaque_1_0.rs b/tests/expectations/tests/jsval_layout_opaque_1_0.rs index 33594c0e05..b439499355 100644 --- a/tests/expectations/tests/jsval_layout_opaque_1_0.rs +++ b/tests/expectations/tests/jsval_layout_opaque_1_0.rs @@ -137,7 +137,6 @@ impl ::std::cmp::Eq for __BindgenUnionField {} pub const JSVAL_TAG_SHIFT: u32 = 47; pub const JSVAL_PAYLOAD_MASK: u64 = 140737488355327; pub const JSVAL_TAG_MASK: i64 = -140737488355328; -pub type size_t = ::std::os::raw::c_ulonglong; #[repr(u8)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum JSValueType { @@ -229,7 +228,7 @@ pub struct jsval_layout { pub s: __BindgenUnionField, pub asDouble: __BindgenUnionField, pub asPtr: __BindgenUnionField<*mut ::std::os::raw::c_void>, - pub asWord: __BindgenUnionField, + pub asWord: __BindgenUnionField, pub asUIntPtr: __BindgenUnionField, pub bindgen_union_field: u64, } diff --git a/tests/expectations/tests/layout_array.rs b/tests/expectations/tests/layout_array.rs index f3bbf51e0d..daf0ad06fd 100644 --- a/tests/expectations/tests/layout_array.rs +++ b/tests/expectations/tests/layout_array.rs @@ -9,7 +9,6 @@ pub const RTE_CACHE_LINE_SIZE: u32 = 64; pub const RTE_MEMPOOL_OPS_NAMESIZE: u32 = 32; pub const RTE_MEMPOOL_MAX_OPS_IDX: u32 = 16; pub const RTE_HEAP_NUM_FREELISTS: u32 = 13; -pub type size_t = ::std::os::raw::c_longlong; #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct rte_mempool { @@ -279,7 +278,7 @@ pub struct malloc_heap { pub lock: rte_spinlock_t, pub free_head: [malloc_heap__bindgen_ty_1; 13usize], pub alloc_count: ::std::os::raw::c_uint, - pub total_size: size_t, + pub total_size: usize, } #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] diff --git a/tests/expectations/tests/msvc-no-usr.rs b/tests/expectations/tests/msvc-no-usr.rs index 285670ed68..64db43a6b6 100644 --- a/tests/expectations/tests/msvc-no-usr.rs +++ b/tests/expectations/tests/msvc-no-usr.rs @@ -5,11 +5,10 @@ non_upper_case_globals )] -pub type size_t = ::std::os::raw::c_ulonglong; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct A { - pub foo: size_t, + pub foo: usize, } #[test] fn bindgen_test_layout_A() { diff --git a/tests/expectations/tests/size_t_is_usize.rs b/tests/expectations/tests/no_size_t_is_usize.rs similarity index 91% rename from tests/expectations/tests/size_t_is_usize.rs rename to tests/expectations/tests/no_size_t_is_usize.rs index 2397e0a56c..f399a66724 100644 --- a/tests/expectations/tests/size_t_is_usize.rs +++ b/tests/expectations/tests/no_size_t_is_usize.rs @@ -5,11 +5,13 @@ non_upper_case_globals )] +pub type size_t = ::std::os::raw::c_ulong; +pub type ssize_t = ::std::os::raw::c_long; #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct A { - pub len: usize, - pub offset: isize, + pub len: size_t, + pub offset: ssize_t, pub next: *mut A, } #[test] diff --git a/tests/expectations/tests/nsBaseHashtable.rs b/tests/expectations/tests/nsBaseHashtable.rs index d7607b91ab..26179b763e 100644 --- a/tests/expectations/tests/nsBaseHashtable.rs +++ b/tests/expectations/tests/nsBaseHashtable.rs @@ -5,7 +5,6 @@ non_upper_case_globals )] -pub type size_t = ::std::os::raw::c_ulonglong; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct nsBaseHashtableET { diff --git a/tests/headers/size_t_is_usize.h b/tests/headers/no_size_t_is_usize.h similarity index 75% rename from tests/headers/size_t_is_usize.h rename to tests/headers/no_size_t_is_usize.h index 564b486784..d4370baf9f 100644 --- a/tests/headers/size_t_is_usize.h +++ b/tests/headers/no_size_t_is_usize.h @@ -1,4 +1,4 @@ -// bindgen-flags: --size_t-is-usize +// bindgen-flags: --no-size_t-is-usize typedef unsigned long size_t; typedef long ssize_t; From 45b9c3430255bae53777a48feb820ea2fdf837b5 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Fri, 23 Sep 2022 21:29:17 -0500 Subject: [PATCH 363/942] remove file added by mistake --- asd.fish | 31 ------------------------------- 1 file changed, 31 deletions(-) delete mode 100644 asd.fish diff --git a/asd.fish b/asd.fish deleted file mode 100644 index b6c9a270e7..0000000000 --- a/asd.fish +++ /dev/null @@ -1,31 +0,0 @@ -for name in (rg -lF addr_of! tests/expectations | sd '.*/(.*).rs' '$1') - set path (fd --glob "$name.*" tests/headers) - if test -n "$path" - - set flags (rg -F "// bindgen-flags" $path) - if test -n "$flags" - set minor (rg ".*\-\-rust\-target[ =]1.(\d+).*" $path -r '$1') - if test -n "$minor" - if test $minor -gt 47 - echo $path needs to change the version from 1.$minor to 1.47 - sd -s "1.$minor" "1.47" $path - else - echo $path uses version 1.$minor and that is fine - end - else - echo $path does not have the `--rust-target` flag - sd "// bindgen-flags: (.*)" '// bindgen-flags: --rust-target 1.47 $1' $path - end - else - echo $path does not have the flags at all - set contents (echo -e "// bindgen-flags: --rust-target 1.47\n"; cat $path) - rm $path - touch $path - for line in $contents - echo $line >> $path - end - end - else - echo $name headers not found - end -end From a372499b938c817719ccc1958bbdcf71f21e8447 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Fri, 23 Sep 2022 15:20:56 -0500 Subject: [PATCH 364/942] move codegen postprocessing to its own module --- src/codegen/mod.rs | 5 +- src/codegen/postprocessing.rs | 148 ++++++++++++++++++++++++++++++++++ src/lib.rs | 113 +------------------------- 3 files changed, 152 insertions(+), 114 deletions(-) create mode 100644 src/codegen/postprocessing.rs diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 8eb7b0134c..5660b1262f 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -3,6 +3,7 @@ mod error; mod helpers; mod impl_debug; mod impl_partialeq; +mod postprocessing; pub mod struct_layout; #[cfg(test)] @@ -4439,7 +4440,7 @@ impl CodeGenerator for ObjCInterface { pub(crate) fn codegen( context: BindgenContext, -) -> (Vec, BindgenOptions, Vec) { +) -> (proc_macro2::TokenStream, BindgenOptions, Vec) { context.gen(|context| { let _t = context.timer("codegen"); let counter = Cell::new(0); @@ -4489,7 +4490,7 @@ pub(crate) fn codegen( result.push(dynamic_items_tokens); } - result.items + postprocessing::postprocessing(result.items, context.options()) }) } diff --git a/src/codegen/postprocessing.rs b/src/codegen/postprocessing.rs new file mode 100644 index 0000000000..728322980f --- /dev/null +++ b/src/codegen/postprocessing.rs @@ -0,0 +1,148 @@ +use proc_macro2::TokenStream; +use quote::ToTokens; +use syn::Item; + +use crate::BindgenOptions; + +macro_rules! decl_postprocessing { + ($($ty:ty),*) => { + pub(crate) fn postprocessing( + items: Vec, + options: &BindgenOptions, + ) -> TokenStream { + // Whether any of the enabled options requires `syn`. + let require_syn = $(<$ty as PostProcessing>::should_run(options))||*; + + if !require_syn { + return items.into_iter().collect(); + } + + let module_wrapped_tokens = + quote!(mod wrapper_for_sorting_hack { #( #items )* }); + + // This syn business is a hack, for now. This means that we are re-parsing already + // generated code using `syn` (as opposed to `quote`) because `syn` provides us more + // control over the elements. + // One caveat is that some of the items coming from `quote`d output might have + // multiple items within them. Hence, we have to wrap the incoming in a `mod`. + // The two `unwrap`s here are deliberate because + // The first one won't panic because we build the `mod` and know it is there + // The second one won't panic because we know original output has something in + // it already. + let mut items = + syn::parse2::(module_wrapped_tokens) + .unwrap() + .content + .unwrap() + .1; + + $(if <$ty as PostProcessing>::should_run(options) { + <$ty as PostProcessing>::run(&mut items); + })* + + let synful_items = items + .into_iter() + .map(|item| item.into_token_stream()); + + quote! { #( #synful_items )* } + } + }; +} + +decl_postprocessing! { + MergeExternBlocks, + SortSemantically +} + +trait PostProcessing { + fn should_run(options: &BindgenOptions) -> bool; + + fn run(items: &mut Vec); +} + +struct SortSemantically; + +impl PostProcessing for SortSemantically { + #[inline] + fn should_run(options: &BindgenOptions) -> bool { + options.sort_semantically + } + + fn run(items: &mut Vec) { + items.sort_by_key(|item| match item { + Item::Type(_) => 0, + Item::Struct(_) => 1, + Item::Const(_) => 2, + Item::Fn(_) => 3, + Item::Enum(_) => 4, + Item::Union(_) => 5, + Item::Static(_) => 6, + Item::Trait(_) => 7, + Item::TraitAlias(_) => 8, + Item::Impl(_) => 9, + Item::Mod(_) => 10, + Item::Use(_) => 11, + Item::Verbatim(_) => 12, + Item::ExternCrate(_) => 13, + Item::ForeignMod(_) => 14, + Item::Macro(_) => 15, + Item::Macro2(_) => 16, + _ => 18, + }); + } +} + +struct MergeExternBlocks; + +impl PostProcessing for MergeExternBlocks { + #[inline] + fn should_run(options: &BindgenOptions) -> bool { + options.merge_extern_blocks + } + + fn run(items: &mut Vec) { + // Keep all the extern blocks in a different `Vec` for faster search. + let mut foreign_mods = Vec::::new(); + + for item in std::mem::take(items) { + match item { + Item::ForeignMod(syn::ItemForeignMod { + attrs, + abi, + brace_token, + items: foreign_items, + }) => { + let mut exists = false; + for foreign_mod in &mut foreign_mods { + // Check if there is a extern block with the same ABI and + // attributes. + if foreign_mod.attrs == attrs && foreign_mod.abi == abi + { + // Merge the items of the two blocks. + foreign_mod.items.extend_from_slice(&foreign_items); + exists = true; + break; + } + } + // If no existing extern block had the same ABI and attributes, store + // it. + if !exists { + foreign_mods.push(syn::ItemForeignMod { + attrs, + abi, + brace_token, + items: foreign_items, + }); + } + } + // If the item is not an extern block, we don't have to do anything. + _ => items.push(item), + } + } + + // Move all the extern blocks alongiside the rest of the items. + for foreign_mod in foreign_mods { + items.push(Item::ForeignMod(foreign_mod)); + } + } +} diff --git a/src/lib.rs b/src/lib.rs index 9a5887df8e..3ee46f7540 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -88,7 +88,6 @@ use std::{env, iter}; // Some convenient typedefs for a fast hash map and hash set. type HashMap = ::rustc_hash::FxHashMap; type HashSet = ::rustc_hash::FxHashSet; -use quote::ToTokens; pub(crate) use std::collections::hash_map::Entry; /// Default prefix for the anon fields. @@ -2118,11 +2117,6 @@ struct BindgenOptions { impl ::std::panic::UnwindSafe for BindgenOptions {} impl BindgenOptions { - /// Whether any of the enabled options requires `syn`. - fn require_syn(&self) -> bool { - self.sort_semantically || self.merge_extern_blocks - } - fn build(&mut self) { let mut regex_sets = [ &mut self.allowlisted_vars, @@ -2555,112 +2549,7 @@ impl Bindings { parse(&mut context)?; } - let (items, options, warnings) = codegen::codegen(context); - - let module = if options.require_syn() { - let module_wrapped_tokens = - quote!(mod wrapper_for_sorting_hack { #( #items )* }); - - // This syn business is a hack, for now. This means that we are re-parsing already - // generated code using `syn` (as opposed to `quote`) because `syn` provides us more - // control over the elements. - // One caveat is that some of the items coming from `quote`d output might have - // multiple items within them. Hence, we have to wrap the incoming in a `mod`. - // The two `unwrap`s here are deliberate because - // The first one won't panic because we build the `mod` and know it is there - // The second one won't panic because we know original output has something in - // it already. - let mut syn_parsed_items = - syn::parse2::(module_wrapped_tokens) - .unwrap() - .content - .unwrap() - .1; - - if options.merge_extern_blocks { - // Here we will store all the items after deduplication. - let mut items = Vec::new(); - - // Keep all the extern blocks in a different `Vec` for faster search. - let mut foreign_mods = Vec::::new(); - for item in syn_parsed_items { - match item { - syn::Item::ForeignMod(syn::ItemForeignMod { - attrs, - abi, - brace_token, - items: foreign_items, - }) => { - let mut exists = false; - for foreign_mod in &mut foreign_mods { - // Check if there is a extern block with the same ABI and - // attributes. - if foreign_mod.attrs == attrs && - foreign_mod.abi == abi - { - // Merge the items of the two blocks. - foreign_mod - .items - .extend_from_slice(&foreign_items); - exists = true; - break; - } - } - // If no existing extern block had the same ABI and attributes, store - // it. - if !exists { - foreign_mods.push(syn::ItemForeignMod { - attrs, - abi, - brace_token, - items: foreign_items, - }); - } - } - // If the item is not an extern block, we don't have to do anything. - _ => items.push(item), - } - } - - // Move all the extern blocks alongiside the rest of the items. - for foreign_mod in foreign_mods { - items.push(syn::Item::ForeignMod(foreign_mod)); - } - - syn_parsed_items = items; - } - - if options.sort_semantically { - syn_parsed_items.sort_by_key(|item| match item { - syn::Item::Type(_) => 0, - syn::Item::Struct(_) => 1, - syn::Item::Const(_) => 2, - syn::Item::Fn(_) => 3, - syn::Item::Enum(_) => 4, - syn::Item::Union(_) => 5, - syn::Item::Static(_) => 6, - syn::Item::Trait(_) => 7, - syn::Item::TraitAlias(_) => 8, - syn::Item::Impl(_) => 9, - syn::Item::Mod(_) => 10, - syn::Item::Use(_) => 11, - syn::Item::Verbatim(_) => 12, - syn::Item::ExternCrate(_) => 13, - syn::Item::ForeignMod(_) => 14, - syn::Item::Macro(_) => 15, - syn::Item::Macro2(_) => 16, - _ => 18, - }); - } - - let synful_items = syn_parsed_items - .into_iter() - .map(|item| item.into_token_stream()); - - quote! { #( #synful_items )* } - } else { - quote! { #( #items )* } - }; + let (module, options, warnings) = codegen::codegen(context); Ok(Bindings { options, From 3dfbc602ae004f142811ad5ef17435dd04bc16ed Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Fri, 23 Sep 2022 15:24:19 -0500 Subject: [PATCH 365/942] update `CONTRIBUTING.md` section about `syn` --- CONTRIBUTING.md | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2974ba4254..3d757ccdff 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -323,14 +323,12 @@ generated Rust code are implemented using the [`syn`](https://docs.rs/syn) crate ### Implementing new options using `syn` -Here is a list of recommendations to be followed if a new option can be -implemented using the `syn` crate: +If a new option can be implemented using the `syn` crate it should be added to +the `codegen::postprocessing` module by following these steps: -- The `BindgenOptions::require_syn` method must be updated to reflect that this - new option requires parsing the generated Rust code with `syn`. - -- The implementation of the new option should be added at the end of - `Bindings::generate`, inside the `if options.require_syn() { ... }` block. +- Introduce a new `struct` with no fields. +- Implement the `PostProcessing` trait for the `struct`. +- Add the `struct` to the `decl_postprocessing` macro invocation. ## Pull Requests and Code Reviews From 0798bdaccfd352c9b2394b1741508000b99ba1bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Fri, 23 Sep 2022 18:10:38 -1000 Subject: [PATCH 366/942] Clean-up postprocessing to use less macro magic. --- src/codegen/postprocessing.rs | 227 ++++++++++++++++------------------ 1 file changed, 104 insertions(+), 123 deletions(-) diff --git a/src/codegen/postprocessing.rs b/src/codegen/postprocessing.rs index 728322980f..6d935a6149 100644 --- a/src/codegen/postprocessing.rs +++ b/src/codegen/postprocessing.rs @@ -4,145 +4,126 @@ use syn::Item; use crate::BindgenOptions; -macro_rules! decl_postprocessing { - ($($ty:ty),*) => { - pub(crate) fn postprocessing( - items: Vec, - options: &BindgenOptions, - ) -> TokenStream { - // Whether any of the enabled options requires `syn`. - let require_syn = $(<$ty as PostProcessing>::should_run(options))||*; - - if !require_syn { - return items.into_iter().collect(); - } - - let module_wrapped_tokens = - quote!(mod wrapper_for_sorting_hack { #( #items )* }); - - // This syn business is a hack, for now. This means that we are re-parsing already - // generated code using `syn` (as opposed to `quote`) because `syn` provides us more - // control over the elements. - // One caveat is that some of the items coming from `quote`d output might have - // multiple items within them. Hence, we have to wrap the incoming in a `mod`. - // The two `unwrap`s here are deliberate because - // The first one won't panic because we build the `mod` and know it is there - // The second one won't panic because we know original output has something in - // it already. - let mut items = - syn::parse2::(module_wrapped_tokens) - .unwrap() - .content - .unwrap() - .1; - - $(if <$ty as PostProcessing>::should_run(options) { - <$ty as PostProcessing>::run(&mut items); - })* - - let synful_items = items - .into_iter() - .map(|item| item.into_token_stream()); +struct PostProcessingPass { + should_run: fn(&BindgenOptions) -> bool, + run: fn(&mut Vec), +} - quote! { #( #synful_items )* } +// TODO: This can be a const fn when mutable references are allowed in const +// context. +macro_rules! pass { + ($pass:ident) => { + PostProcessingPass { + should_run: |options| options.$pass, + run: $pass, } }; } -decl_postprocessing! { - MergeExternBlocks, - SortSemantically -} - -trait PostProcessing { - fn should_run(options: &BindgenOptions) -> bool; - - fn run(items: &mut Vec); -} - -struct SortSemantically; +static PASSES: [PostProcessingPass; 2] = + [pass!(merge_extern_blocks), pass!(sort_semantically)]; -impl PostProcessing for SortSemantically { - #[inline] - fn should_run(options: &BindgenOptions) -> bool { - options.sort_semantically +pub(crate) fn postprocessing( + items: Vec, + options: &BindgenOptions, +) -> TokenStream { + let require_syn = PASSES.iter().any(|pass| (pass.should_run)(options)); + if !require_syn { + return items.into_iter().collect(); } - - fn run(items: &mut Vec) { - items.sort_by_key(|item| match item { - Item::Type(_) => 0, - Item::Struct(_) => 1, - Item::Const(_) => 2, - Item::Fn(_) => 3, - Item::Enum(_) => 4, - Item::Union(_) => 5, - Item::Static(_) => 6, - Item::Trait(_) => 7, - Item::TraitAlias(_) => 8, - Item::Impl(_) => 9, - Item::Mod(_) => 10, - Item::Use(_) => 11, - Item::Verbatim(_) => 12, - Item::ExternCrate(_) => 13, - Item::ForeignMod(_) => 14, - Item::Macro(_) => 15, - Item::Macro2(_) => 16, - _ => 18, - }); + let module_wrapped_tokens = + quote!(mod wrapper_for_sorting_hack { #( #items )* }); + + // This syn business is a hack, for now. This means that we are re-parsing already + // generated code using `syn` (as opposed to `quote`) because `syn` provides us more + // control over the elements. + // One caveat is that some of the items coming from `quote`d output might have + // multiple items within them. Hence, we have to wrap the incoming in a `mod`. + // The two `unwrap`s here are deliberate because + // The first one won't panic because we build the `mod` and know it is there + // The second one won't panic because we know original output has something in + // it already. + let mut items = syn::parse2::(module_wrapped_tokens) + .unwrap() + .content + .unwrap() + .1; + + for pass in PASSES.iter() { + if (pass.should_run)(options) { + (pass.run)(&mut items); + } } -} -struct MergeExternBlocks; + let synful_items = items.into_iter().map(|item| item.into_token_stream()); -impl PostProcessing for MergeExternBlocks { - #[inline] - fn should_run(options: &BindgenOptions) -> bool { - options.merge_extern_blocks - } + quote! { #( #synful_items )* } +} - fn run(items: &mut Vec) { - // Keep all the extern blocks in a different `Vec` for faster search. - let mut foreign_mods = Vec::::new(); +fn sort_semantically(items: &mut Vec) { + items.sort_by_key(|item| match item { + Item::Type(_) => 0, + Item::Struct(_) => 1, + Item::Const(_) => 2, + Item::Fn(_) => 3, + Item::Enum(_) => 4, + Item::Union(_) => 5, + Item::Static(_) => 6, + Item::Trait(_) => 7, + Item::TraitAlias(_) => 8, + Item::Impl(_) => 9, + Item::Mod(_) => 10, + Item::Use(_) => 11, + Item::Verbatim(_) => 12, + Item::ExternCrate(_) => 13, + Item::ForeignMod(_) => 14, + Item::Macro(_) => 15, + Item::Macro2(_) => 16, + _ => 18, + }); +} - for item in std::mem::take(items) { - match item { - Item::ForeignMod(syn::ItemForeignMod { - attrs, - abi, - brace_token, - items: foreign_items, - }) => { - let mut exists = false; - for foreign_mod in &mut foreign_mods { - // Check if there is a extern block with the same ABI and - // attributes. - if foreign_mod.attrs == attrs && foreign_mod.abi == abi - { - // Merge the items of the two blocks. - foreign_mod.items.extend_from_slice(&foreign_items); - exists = true; - break; - } - } - // If no existing extern block had the same ABI and attributes, store - // it. - if !exists { - foreign_mods.push(syn::ItemForeignMod { - attrs, - abi, - brace_token, - items: foreign_items, - }); +fn merge_extern_blocks(items: &mut Vec) { + // Keep all the extern blocks in a different `Vec` for faster search. + let mut foreign_mods = Vec::::new(); + + for item in std::mem::take(items) { + match item { + Item::ForeignMod(syn::ItemForeignMod { + attrs, + abi, + brace_token, + items: foreign_items, + }) => { + let mut exists = false; + for foreign_mod in &mut foreign_mods { + // Check if there is a extern block with the same ABI and + // attributes. + if foreign_mod.attrs == attrs && foreign_mod.abi == abi { + // Merge the items of the two blocks. + foreign_mod.items.extend_from_slice(&foreign_items); + exists = true; + break; } } - // If the item is not an extern block, we don't have to do anything. - _ => items.push(item), + // If no existing extern block had the same ABI and attributes, store + // it. + if !exists { + foreign_mods.push(syn::ItemForeignMod { + attrs, + abi, + brace_token, + items: foreign_items, + }); + } } + // If the item is not an extern block, we don't have to do anything. + _ => items.push(item), } + } - // Move all the extern blocks alongiside the rest of the items. - for foreign_mod in foreign_mods { - items.push(Item::ForeignMod(foreign_mod)); - } + // Move all the extern blocks alongside the rest of the items. + for foreign_mod in foreign_mods { + items.push(Item::ForeignMod(foreign_mod)); } } From 4312df317a2fdf26ec889cb2f8d3ffe0b12ea4d3 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Mon, 26 Sep 2022 10:55:05 -0500 Subject: [PATCH 367/942] update CONTRIBUTING.md --- CONTRIBUTING.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3d757ccdff..48e4a4025e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -326,9 +326,11 @@ generated Rust code are implemented using the [`syn`](https://docs.rs/syn) crate If a new option can be implemented using the `syn` crate it should be added to the `codegen::postprocessing` module by following these steps: -- Introduce a new `struct` with no fields. -- Implement the `PostProcessing` trait for the `struct`. -- Add the `struct` to the `decl_postprocessing` macro invocation. +- Introduce a new field to `BindgenOptions` for the option. +- Write a free function inside `codegen::postprocessing` implementing the + option. This function with the same name of the `BindgenOptions` field. +- Add a new value to the `codegen::postprocessing::PASSES` for the option using + the `pass!` macro. ## Pull Requests and Code Reviews From 06a6479e9e6fe9b556a54b3d7f28c23b1268b048 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Mon, 26 Sep 2022 11:02:42 -0500 Subject: [PATCH 368/942] s/static/const --- src/codegen/postprocessing.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/codegen/postprocessing.rs b/src/codegen/postprocessing.rs index 6d935a6149..6550ca57db 100644 --- a/src/codegen/postprocessing.rs +++ b/src/codegen/postprocessing.rs @@ -20,8 +20,8 @@ macro_rules! pass { }; } -static PASSES: [PostProcessingPass; 2] = - [pass!(merge_extern_blocks), pass!(sort_semantically)]; +const PASSES: &'static [PostProcessingPass] = + &[pass!(merge_extern_blocks), pass!(sort_semantically)]; pub(crate) fn postprocessing( items: Vec, @@ -43,13 +43,12 @@ pub(crate) fn postprocessing( // The first one won't panic because we build the `mod` and know it is there // The second one won't panic because we know original output has something in // it already. - let mut items = syn::parse2::(module_wrapped_tokens) + let (_, mut items) = syn::parse2::(module_wrapped_tokens) .unwrap() .content - .unwrap() - .1; + .unwrap(); - for pass in PASSES.iter() { + for pass in PASSES { if (pass.should_run)(options) { (pass.run)(&mut items); } From 4cfd06e9e13f0c4177f052677fb7d67dc0367176 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Mon, 26 Sep 2022 13:22:15 -0500 Subject: [PATCH 369/942] make `BindgenOptions` clonable --- src/deps.rs | 2 +- src/ir/context.rs | 7 +++++-- src/lib.rs | 30 +++++++++++++----------------- src/regex_set.rs | 2 +- 4 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/deps.rs b/src/deps.rs index 479c396cbb..987225b28e 100644 --- a/src/deps.rs +++ b/src/deps.rs @@ -1,7 +1,7 @@ /// Generating build depfiles from parsed bindings. use std::{collections::BTreeSet, path::PathBuf}; -#[derive(Debug)] +#[derive(Clone, Debug)] pub(crate) struct DepfileSpec { pub output_module: String, pub depfile_path: PathBuf, diff --git a/src/ir/context.rs b/src/ir/context.rs index 7837e59491..ec0fca1610 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -505,7 +505,10 @@ impl<'ctx> AllowlistedItemsTraversal<'ctx> { impl BindgenContext { /// Construct the context for the given `options`. - pub(crate) fn new(options: BindgenOptions) -> Self { + pub(crate) fn new( + options: BindgenOptions, + input_unsaved_files: &[clang::UnsavedFile], + ) -> Self { // TODO(emilio): Use the CXTargetInfo here when available. // // see: https://reviews.llvm.org/D32389 @@ -522,7 +525,7 @@ impl BindgenContext { &index, "", &options.clang_args, - &options.input_unsaved_files, + &input_unsaved_files, parse_options, ).expect("libclang error; possible causes include: - Invalid flag syntax diff --git a/src/lib.rs b/src/lib.rs index 9a5887df8e..81a5811601 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -83,6 +83,7 @@ use std::fs::{File, OpenOptions}; use std::io::{self, Write}; use std::path::{Path, PathBuf}; use std::process::{Command, Stdio}; +use std::rc::Rc; use std::{env, iter}; // Some convenient typedefs for a fast hash map and hash set. @@ -1466,7 +1467,7 @@ impl Builder { mut self, cb: Box, ) -> Self { - self.options.parse_callbacks = Some(cb); + self.options.parse_callbacks = Some(Rc::from(cb)); self } @@ -1575,15 +1576,13 @@ impl Builder { }), ); - self.options.input_unsaved_files.extend( - self.input_header_contents - .drain(..) - .map(|(name, contents)| { - clang::UnsavedFile::new(&name, &contents) - }), - ); + let input_unsaved_files = self + .input_header_contents + .into_iter() + .map(|(name, contents)| clang::UnsavedFile::new(&name, &contents)) + .collect::>(); - Bindings::generate(self.options) + Bindings::generate(self.options, input_unsaved_files) } /// Preprocess and dump the input header files to disk. @@ -1775,7 +1774,7 @@ impl Builder { } /// Configuration options for generated bindings. -#[derive(Debug)] +#[derive(Clone, Debug)] struct BindgenOptions { /// The set of types that have been blocklisted and should not appear /// anywhere in the generated code. @@ -1978,12 +1977,9 @@ struct BindgenOptions { /// Any additional input header files. extra_input_headers: Vec, - /// Unsaved files for input. - input_unsaved_files: Vec, - /// A user-provided visitor to allow customizing different kinds of /// situations. - parse_callbacks: Option>, + parse_callbacks: Option>, /// Which kind of items should we generate? By default, we'll generate all /// of them. @@ -2236,7 +2232,6 @@ impl Default for BindgenOptions { clang_args: vec![], input_header: None, extra_input_headers: vec![], - input_unsaved_files: vec![], parse_callbacks: None, codegen_config: CodegenConfig::all(), conservative_inline_namespaces: false, @@ -2394,6 +2389,7 @@ impl Bindings { /// Generate bindings for the given options. pub(crate) fn generate( mut options: BindgenOptions, + input_unsaved_files: Vec, ) -> Result { ensure_libclang_is_loaded(); @@ -2528,7 +2524,7 @@ impl Bindings { } } - for (idx, f) in options.input_unsaved_files.iter().enumerate() { + for (idx, f) in input_unsaved_files.iter().enumerate() { if idx != 0 || options.input_header.is_some() { options.clang_args.push("-include".to_owned()); } @@ -2538,7 +2534,7 @@ impl Bindings { debug!("Fixed-up options: {:?}", options); let time_phases = options.time_phases; - let mut context = BindgenContext::new(options); + let mut context = BindgenContext::new(options, &input_unsaved_files); if is_host_build { debug_assert_eq!( diff --git a/src/regex_set.rs b/src/regex_set.rs index 127c001829..9262c4eeda 100644 --- a/src/regex_set.rs +++ b/src/regex_set.rs @@ -4,7 +4,7 @@ use regex::RegexSet as RxSet; use std::cell::Cell; /// A dynamic set of regular expressions. -#[derive(Debug, Default)] +#[derive(Clone, Debug, Default)] pub struct RegexSet { items: Vec, /// Whether any of the items in the set was ever matched. The length of this From ddb319ce3579b687cdd06d934ac40c253e96221f Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Tue, 27 Sep 2022 13:43:33 -0500 Subject: [PATCH 370/942] split `processing` module --- src/codegen/postprocessing.rs | 128 ------------------ .../postprocessing/merge_extern_blocks.rs | 46 +++++++ src/codegen/postprocessing/mod.rs | 66 +++++++++ .../postprocessing/sort_semantically.rs | 24 ++++ 4 files changed, 136 insertions(+), 128 deletions(-) delete mode 100644 src/codegen/postprocessing.rs create mode 100644 src/codegen/postprocessing/merge_extern_blocks.rs create mode 100644 src/codegen/postprocessing/mod.rs create mode 100644 src/codegen/postprocessing/sort_semantically.rs diff --git a/src/codegen/postprocessing.rs b/src/codegen/postprocessing.rs deleted file mode 100644 index 6550ca57db..0000000000 --- a/src/codegen/postprocessing.rs +++ /dev/null @@ -1,128 +0,0 @@ -use proc_macro2::TokenStream; -use quote::ToTokens; -use syn::Item; - -use crate::BindgenOptions; - -struct PostProcessingPass { - should_run: fn(&BindgenOptions) -> bool, - run: fn(&mut Vec), -} - -// TODO: This can be a const fn when mutable references are allowed in const -// context. -macro_rules! pass { - ($pass:ident) => { - PostProcessingPass { - should_run: |options| options.$pass, - run: $pass, - } - }; -} - -const PASSES: &'static [PostProcessingPass] = - &[pass!(merge_extern_blocks), pass!(sort_semantically)]; - -pub(crate) fn postprocessing( - items: Vec, - options: &BindgenOptions, -) -> TokenStream { - let require_syn = PASSES.iter().any(|pass| (pass.should_run)(options)); - if !require_syn { - return items.into_iter().collect(); - } - let module_wrapped_tokens = - quote!(mod wrapper_for_sorting_hack { #( #items )* }); - - // This syn business is a hack, for now. This means that we are re-parsing already - // generated code using `syn` (as opposed to `quote`) because `syn` provides us more - // control over the elements. - // One caveat is that some of the items coming from `quote`d output might have - // multiple items within them. Hence, we have to wrap the incoming in a `mod`. - // The two `unwrap`s here are deliberate because - // The first one won't panic because we build the `mod` and know it is there - // The second one won't panic because we know original output has something in - // it already. - let (_, mut items) = syn::parse2::(module_wrapped_tokens) - .unwrap() - .content - .unwrap(); - - for pass in PASSES { - if (pass.should_run)(options) { - (pass.run)(&mut items); - } - } - - let synful_items = items.into_iter().map(|item| item.into_token_stream()); - - quote! { #( #synful_items )* } -} - -fn sort_semantically(items: &mut Vec) { - items.sort_by_key(|item| match item { - Item::Type(_) => 0, - Item::Struct(_) => 1, - Item::Const(_) => 2, - Item::Fn(_) => 3, - Item::Enum(_) => 4, - Item::Union(_) => 5, - Item::Static(_) => 6, - Item::Trait(_) => 7, - Item::TraitAlias(_) => 8, - Item::Impl(_) => 9, - Item::Mod(_) => 10, - Item::Use(_) => 11, - Item::Verbatim(_) => 12, - Item::ExternCrate(_) => 13, - Item::ForeignMod(_) => 14, - Item::Macro(_) => 15, - Item::Macro2(_) => 16, - _ => 18, - }); -} - -fn merge_extern_blocks(items: &mut Vec) { - // Keep all the extern blocks in a different `Vec` for faster search. - let mut foreign_mods = Vec::::new(); - - for item in std::mem::take(items) { - match item { - Item::ForeignMod(syn::ItemForeignMod { - attrs, - abi, - brace_token, - items: foreign_items, - }) => { - let mut exists = false; - for foreign_mod in &mut foreign_mods { - // Check if there is a extern block with the same ABI and - // attributes. - if foreign_mod.attrs == attrs && foreign_mod.abi == abi { - // Merge the items of the two blocks. - foreign_mod.items.extend_from_slice(&foreign_items); - exists = true; - break; - } - } - // If no existing extern block had the same ABI and attributes, store - // it. - if !exists { - foreign_mods.push(syn::ItemForeignMod { - attrs, - abi, - brace_token, - items: foreign_items, - }); - } - } - // If the item is not an extern block, we don't have to do anything. - _ => items.push(item), - } - } - - // Move all the extern blocks alongside the rest of the items. - for foreign_mod in foreign_mods { - items.push(Item::ForeignMod(foreign_mod)); - } -} diff --git a/src/codegen/postprocessing/merge_extern_blocks.rs b/src/codegen/postprocessing/merge_extern_blocks.rs new file mode 100644 index 0000000000..2b7614941e --- /dev/null +++ b/src/codegen/postprocessing/merge_extern_blocks.rs @@ -0,0 +1,46 @@ +use syn::{Item, ItemForeignMod}; + +pub(super) fn merge_extern_blocks(items: &mut Vec) { + // Keep all the extern blocks in a different `Vec` for faster search. + let mut foreign_mods = Vec::::new(); + + for item in std::mem::take(items) { + match item { + Item::ForeignMod(ItemForeignMod { + attrs, + abi, + brace_token, + items: foreign_items, + }) => { + let mut exists = false; + for foreign_mod in &mut foreign_mods { + // Check if there is a extern block with the same ABI and + // attributes. + if foreign_mod.attrs == attrs && foreign_mod.abi == abi { + // Merge the items of the two blocks. + foreign_mod.items.extend_from_slice(&foreign_items); + exists = true; + break; + } + } + // If no existing extern block had the same ABI and attributes, store + // it. + if !exists { + foreign_mods.push(ItemForeignMod { + attrs, + abi, + brace_token, + items: foreign_items, + }); + } + } + // If the item is not an extern block, we don't have to do anything. + _ => items.push(item), + } + } + + // Move all the extern blocks alongside the rest of the items. + for foreign_mod in foreign_mods { + items.push(Item::ForeignMod(foreign_mod)); + } +} diff --git a/src/codegen/postprocessing/mod.rs b/src/codegen/postprocessing/mod.rs new file mode 100644 index 0000000000..c6612f2b91 --- /dev/null +++ b/src/codegen/postprocessing/mod.rs @@ -0,0 +1,66 @@ +use proc_macro2::TokenStream; +use quote::ToTokens; +use syn::Item; + +use crate::BindgenOptions; + +mod merge_extern_blocks; +mod sort_semantically; + +use merge_extern_blocks::merge_extern_blocks; +use sort_semantically::sort_semantically; + +struct PostProcessingPass { + should_run: fn(&BindgenOptions) -> bool, + run: fn(&mut Vec), +} + +// TODO: This can be a const fn when mutable references are allowed in const +// context. +macro_rules! pass { + ($pass:ident) => { + PostProcessingPass { + should_run: |options| options.$pass, + run: |items| $pass(items), + } + }; +} + +const PASSES: &[PostProcessingPass] = + &[pass!(merge_extern_blocks), pass!(sort_semantically)]; + +pub(crate) fn postprocessing( + items: Vec, + options: &BindgenOptions, +) -> TokenStream { + let require_syn = PASSES.iter().any(|pass| (pass.should_run)(options)); + if !require_syn { + return items.into_iter().collect(); + } + let module_wrapped_tokens = + quote!(mod wrapper_for_sorting_hack { #( #items )* }); + + // This syn business is a hack, for now. This means that we are re-parsing already + // generated code using `syn` (as opposed to `quote`) because `syn` provides us more + // control over the elements. + // One caveat is that some of the items coming from `quote`d output might have + // multiple items within them. Hence, we have to wrap the incoming in a `mod`. + // The two `unwrap`s here are deliberate because + // The first one won't panic because we build the `mod` and know it is there + // The second one won't panic because we know original output has something in + // it already. + let (_, mut items) = syn::parse2::(module_wrapped_tokens) + .unwrap() + .content + .unwrap(); + + for pass in PASSES { + if (pass.should_run)(options) { + (pass.run)(&mut items); + } + } + + let synful_items = items.into_iter().map(|item| item.into_token_stream()); + + quote! { #( #synful_items )* } +} diff --git a/src/codegen/postprocessing/sort_semantically.rs b/src/codegen/postprocessing/sort_semantically.rs new file mode 100644 index 0000000000..96596cb01e --- /dev/null +++ b/src/codegen/postprocessing/sort_semantically.rs @@ -0,0 +1,24 @@ +use syn::Item; + +pub(super) fn sort_semantically(items: &mut [Item]) { + items.sort_by_key(|item| match item { + Item::Type(_) => 0, + Item::Struct(_) => 1, + Item::Const(_) => 2, + Item::Fn(_) => 3, + Item::Enum(_) => 4, + Item::Union(_) => 5, + Item::Static(_) => 6, + Item::Trait(_) => 7, + Item::TraitAlias(_) => 8, + Item::Impl(_) => 9, + Item::Mod(_) => 10, + Item::Use(_) => 11, + Item::Verbatim(_) => 12, + Item::ExternCrate(_) => 13, + Item::ForeignMod(_) => 14, + Item::Macro(_) => 15, + Item::Macro2(_) => 16, + _ => 18, + }); +} From 70115a08631f6928efbe5d685043676bf68e3123 Mon Sep 17 00:00:00 2001 From: Geoffry Song Date: Tue, 27 Sep 2022 21:17:41 +0000 Subject: [PATCH 371/942] Don't traverse through special-cased types. --- src/ir/context.rs | 34 ++++++++++-------- src/ir/ty.rs | 7 ++++ tests/expectations/tests/stdint_typedef.rs | 41 ++++++++++++++++++++++ tests/headers/stdint_typedef.h | 10 ++++++ 4 files changed, 78 insertions(+), 14 deletions(-) create mode 100644 tests/expectations/tests/stdint_typedef.rs create mode 100644 tests/headers/stdint_typedef.h diff --git a/src/ir/context.rs b/src/ir/context.rs index 7837e59491..d470efa9a8 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -2250,24 +2250,27 @@ If you encounter an error missing from this list, please file an issue or a PR!" // Sized integer types from get mapped to Rust primitive // types regardless of whether they are blocklisted, so ensure that // standard traits are considered derivable for them too. - None => match name { - "int8_t" | "uint8_t" | "int16_t" | "uint16_t" | - "int32_t" | "uint32_t" | "int64_t" | - "uint64_t" | "uintptr_t" | "intptr_t" | - "ptrdiff_t" => Some(CanDerive::Yes), - "size_t" if self.options.size_t_is_usize => { - Some(CanDerive::Yes) - } - "ssize_t" if self.options.size_t_is_usize => { - Some(CanDerive::Yes) - } - _ => Some(CanDerive::No), - }, + None => Some(if self.is_stdint_type(name) { + CanDerive::Yes + } else { + CanDerive::No + }), }) .unwrap_or(CanDerive::No) }) } + /// Is the given type a type from that corresponds to a Rust primitive type? + pub fn is_stdint_type(&self, name: &str) -> bool { + match name { + "int8_t" | "uint8_t" | "int16_t" | "uint16_t" | "int32_t" | + "uint32_t" | "int64_t" | "uint64_t" | "uintptr_t" | + "intptr_t" | "ptrdiff_t" => true, + "size_t" | "ssize_t" => self.options.size_t_is_usize, + _ => false, + } + } + /// Get a reference to the set of items we should generate. pub fn codegen_items(&self) -> &ItemSet { assert!(self.in_codegen_phase()); @@ -2355,7 +2358,10 @@ If you encounter an error missing from this list, please file an issue or a PR!" TypeKind::Opaque | TypeKind::TypeParam => return true, _ => {} - }; + } + if self.is_stdint_type(&name) { + return true; + } } // Unnamed top-level enums are special and we diff --git a/src/ir/ty.rs b/src/ir/ty.rs index c85bc68776..6a3fd0e8c8 100644 --- a/src/ir/ty.rs +++ b/src/ir/ty.rs @@ -1206,6 +1206,13 @@ impl Trace for Type { where T: Tracer, { + if self + .name() + .map_or(false, |name| context.is_stdint_type(name)) + { + // These types are special-cased in codegen and don't need to be traversed. + return; + } match *self.kind() { TypeKind::Pointer(inner) | TypeKind::Reference(inner) | diff --git a/tests/expectations/tests/stdint_typedef.rs b/tests/expectations/tests/stdint_typedef.rs new file mode 100644 index 0000000000..a52db49691 --- /dev/null +++ b/tests/expectations/tests/stdint_typedef.rs @@ -0,0 +1,41 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +extern "C" { + pub fn fun() -> u64; +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Struct { + pub field: u64, +} +#[test] +fn bindgen_test_layout_Struct() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Struct)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Struct)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).field) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Struct), + "::", + stringify!(field) + ) + ); +} diff --git a/tests/headers/stdint_typedef.h b/tests/headers/stdint_typedef.h new file mode 100644 index 0000000000..f716a7f1a0 --- /dev/null +++ b/tests/headers/stdint_typedef.h @@ -0,0 +1,10 @@ +// bindgen-flags: --allowlist-type="Struct" --allowlist-function="fun" + +// no typedef should be emitted for `__uint64_t` +typedef unsigned long long __uint64_t; +typedef __uint64_t uint64_t; + +uint64_t fun(); +struct Struct { + uint64_t field; +}; From 8b69ba05aa685d3bf02f7f21bc5cab63262e1de5 Mon Sep 17 00:00:00 2001 From: Cameron Mulhern Date: Mon, 27 Dec 2021 10:49:50 -0500 Subject: [PATCH 372/942] Enables blocklisting of Objective-C methods --- book/src/objc.md | 2 ++ src/codegen/mod.rs | 32 +++++++++++++---- tests/expectations/tests/objc_blocklist.rs | 42 ++++++++++++++++++++++ tests/headers/objc_blocklist.h | 9 +++++ 4 files changed, 78 insertions(+), 7 deletions(-) create mode 100644 tests/expectations/tests/objc_blocklist.rs create mode 100644 tests/headers/objc_blocklist.h diff --git a/book/src/objc.md b/book/src/objc.md index 60e5638dba..ce6d756761 100644 --- a/book/src/objc.md +++ b/book/src/objc.md @@ -32,6 +32,8 @@ methods found in `NSObject`. In order to initialize a class `Foo`, you will have to do something like `let foo = Foo(Foo::alloc().initWithStuff())`. +To blocklist an Objective-C method, you should add the bindgen generated method +path (e.g. `IFoo::method` or `IFoo::class_method`) as a blocklist item. ## Supported Features diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 5660b1262f..a8a7b07696 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -4191,9 +4191,19 @@ impl CodeGenerator for Function { fn objc_method_codegen( ctx: &BindgenContext, method: &ObjCMethod, + methods: &mut Vec, class_name: Option<&str>, + rust_class_name: &str, prefix: &str, -) -> proc_macro2::TokenStream { +) { + // This would ideally resolve the method into an Item, and use + // Item::process_before_codegen; however, ObjC methods are not currently + // made into function items. + let name = format!("{}::{}{}", rust_class_name, prefix, method.rust_name()); + if ctx.options().blocklisted_items.matches(name) { + return; + } + let signature = method.signature(); let fn_args = utils::fnsig_arguments(ctx, signature); let fn_ret = utils::fnsig_return_ty(ctx, signature); @@ -4229,11 +4239,11 @@ fn objc_method_codegen( let method_name = ctx.rust_ident(format!("{}{}", prefix, method.rust_name())); - quote! { + methods.push(quote! { unsafe fn #method_name #sig where ::Target: objc::Message + Sized { #body } - } + }); } impl CodeGenerator for ObjCInterface { @@ -4249,10 +4259,17 @@ impl CodeGenerator for ObjCInterface { debug_assert!(item.is_enabled_for_codegen(ctx)); let mut impl_items = vec![]; + let rust_class_name = item.path_for_allowlisting(ctx)[1..].join("::"); for method in self.methods() { - let impl_item = objc_method_codegen(ctx, method, None, ""); - impl_items.push(impl_item); + objc_method_codegen( + ctx, + method, + &mut impl_items, + None, + &rust_class_name, + "", + ); } for class_method in self.class_methods() { @@ -4262,13 +4279,14 @@ impl CodeGenerator for ObjCInterface { .map(|m| m.rust_name()) .any(|x| x == class_method.rust_name()); let prefix = if ambiquity { "class_" } else { "" }; - let impl_item = objc_method_codegen( + objc_method_codegen( ctx, class_method, + &mut impl_items, Some(self.name()), + &rust_class_name, prefix, ); - impl_items.push(impl_item); } let trait_name = ctx.rust_ident(self.rust_name()); diff --git a/tests/expectations/tests/objc_blocklist.rs b/tests/expectations/tests/objc_blocklist.rs new file mode 100644 index 0000000000..7d5d19b083 --- /dev/null +++ b/tests/expectations/tests/objc_blocklist.rs @@ -0,0 +1,42 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] +#![cfg(target_os = "macos")] + +#[macro_use] +extern crate objc; +#[allow(non_camel_case_types)] +pub type id = *mut objc::runtime::Object; +#[repr(transparent)] +#[derive(Debug, Copy, Clone)] +pub struct SomeClass(pub id); +impl std::ops::Deref for SomeClass { + type Target = objc::runtime::Object; + fn deref(&self) -> &Self::Target { + unsafe { &*self.0 } + } +} +unsafe impl objc::Message for SomeClass {} +impl SomeClass { + pub fn alloc() -> Self { + Self(unsafe { msg_send!(class!(SomeClass), alloc) }) + } +} +impl ISomeClass for SomeClass {} +pub trait ISomeClass: Sized + std::ops::Deref { + unsafe fn ambiguouslyBlockedMethod(&self) + where + ::Target: objc::Message + Sized, + { + msg_send!(*self, ambiguouslyBlockedMethod) + } + unsafe fn instanceMethod(&self) + where + ::Target: objc::Message + Sized, + { + msg_send!(*self, instanceMethod) + } +} diff --git a/tests/headers/objc_blocklist.h b/tests/headers/objc_blocklist.h new file mode 100644 index 0000000000..605f2993cf --- /dev/null +++ b/tests/headers/objc_blocklist.h @@ -0,0 +1,9 @@ +// bindgen-flags: --objc-extern-crate --blocklist-item ISomeClass::class_ambiguouslyBlockedMethod --blocklist-item ISomeClass::blockedInstanceMethod -- -x objective-c +// bindgen-osx-only + +@interface SomeClass ++ (void)ambiguouslyBlockedMethod; +- (void)ambiguouslyBlockedMethod; +- (void)instanceMethod; +- (void)blockedInstanceMethod; +@end From 17252c73fa2820da7a4c4f0027545b976fd95dc3 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Mon, 3 Oct 2022 10:01:46 -0500 Subject: [PATCH 373/942] remove reference --- src/ir/context.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ir/context.rs b/src/ir/context.rs index ec0fca1610..6f16e19203 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -525,7 +525,7 @@ impl BindgenContext { &index, "", &options.clang_args, - &input_unsaved_files, + input_unsaved_files, parse_options, ).expect("libclang error; possible causes include: - Invalid flag syntax From cebdedcc40f55d85d1370455c9d596a7c4ac1a19 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Mon, 3 Oct 2022 13:02:03 -0500 Subject: [PATCH 374/942] address clippy lints --- src/codegen/mod.rs | 2 +- src/ir/enum_ty.rs | 2 +- src/ir/var.rs | 10 +++------- src/lib.rs | 2 +- src/options.rs | 8 ++++---- tests/tests.rs | 8 ++++---- 6 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index a8a7b07696..7e0d7aa0c9 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -3439,7 +3439,7 @@ impl std::str::FromStr for AliasVariation { } /// Enum for how non-Copy unions should be translated. -#[derive(Copy, Clone, PartialEq, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Debug)] pub enum NonCopyUnionStyle { /// Wrap members in a type generated by bindgen. BindgenWrapper, diff --git a/src/ir/enum_ty.rs b/src/ir/enum_ty.rs index 2b039a4fac..123d1d793d 100644 --- a/src/ir/enum_ty.rs +++ b/src/ir/enum_ty.rs @@ -165,7 +165,7 @@ impl Enum { return false; } - self.variants().iter().any(|v| enums.matches(&v.name())) + self.variants().iter().any(|v| enums.matches(v.name())) } /// Returns the final representation of the enum. diff --git a/src/ir/var.rs b/src/ir/var.rs index e44d57afe4..eecca4df54 100644 --- a/src/ir/var.rs +++ b/src/ir/var.rs @@ -325,8 +325,7 @@ impl ClangSubItemParser for Var { let mut val = cursor.evaluate().and_then(|v| v.as_int()); if val.is_none() || !kind.signedness_matches(val.unwrap()) { - let tu = ctx.translation_unit(); - val = get_integer_literal_from_cursor(&cursor, tu); + val = get_integer_literal_from_cursor(&cursor); } val.map(|val| { @@ -391,10 +390,7 @@ fn parse_int_literal_tokens(cursor: &clang::Cursor) -> Option { } } -fn get_integer_literal_from_cursor( - cursor: &clang::Cursor, - unit: &clang::TranslationUnit, -) -> Option { +fn get_integer_literal_from_cursor(cursor: &clang::Cursor) -> Option { use clang_sys::*; let mut value = None; cursor.visit(|c| { @@ -403,7 +399,7 @@ fn get_integer_literal_from_cursor( value = parse_int_literal_tokens(&c); } CXCursor_UnexposedExpr => { - value = get_integer_literal_from_cursor(&c, unit); + value = get_integer_literal_from_cursor(&c); } _ => (), } diff --git a/src/lib.rs b/src/lib.rs index b2467fbcad..6e6fa225d6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2647,7 +2647,7 @@ impl Bindings { .as_ref() .and_then(|f| f.to_str()) { - cmd.args(&["--config-path", path]); + cmd.args(["--config-path", path]); } let mut child = cmd.spawn()?; diff --git a/src/options.rs b/src/options.rs index 29edb78b1c..1025a36dc9 100644 --- a/src/options.rs +++ b/src/options.rs @@ -39,7 +39,7 @@ where .help("The default style of code used to generate enums.") .value_name("variant") .default_value("consts") - .possible_values(&[ + .possible_values([ "consts", "moduleconsts", "bitfield", @@ -98,14 +98,14 @@ where .help("The default signed/unsigned type for C macro constants.") .value_name("variant") .default_value("unsigned") - .possible_values(&["signed", "unsigned"]) + .possible_values(["signed", "unsigned"]) .multiple_occurrences(false), Arg::new("default-alias-style") .long("default-alias-style") .help("The default style of code used to generate typedefs.") .value_name("variant") .default_value("type_alias") - .possible_values(&[ + .possible_values([ "type_alias", "new_type", "new_type_deref", @@ -147,7 +147,7 @@ where ) .value_name("style") .default_value("bindgen_wrapper") - .possible_values(&[ + .possible_values([ "bindgen_wrapper", "manually_drop", ]) diff --git a/tests/tests.rs b/tests/tests.rs index 8dcc54370b..ac53d73965 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -31,7 +31,7 @@ fn rustfmt(source: String) -> (String, String) { let mut rustfmt = { let mut p = process::Command::new("rustup"); - p.args(&["run", "nightly", "rustfmt", "--version"]); + p.args(["run", "nightly", "rustfmt", "--version"]); p }; @@ -59,13 +59,13 @@ The latest `rustfmt` is required to run the `bindgen` test suite. Install Some(r) => process::Command::new(r), None => { let mut p = process::Command::new("rustup"); - p.args(&["run", "nightly", "rustfmt"]); + p.args(["run", "nightly", "rustfmt"]); p } }; let mut child = child - .args(&[ + .args([ "--config-path", concat!(env!("CARGO_MANIFEST_DIR"), "/tests/rustfmt.toml"), ]) @@ -164,7 +164,7 @@ fn error_diff_mismatch( let mut actual_result_file = fs::File::create(&actual_result_path)?; actual_result_file.write_all(actual.as_bytes())?; std::process::Command::new(var) - .args(&[filename, &actual_result_path]) + .args([filename, &actual_result_path]) .output()?; } From 0296f9e86c7756e718b6b82836ce1e09b5f8d08a Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Fri, 23 Sep 2022 21:36:14 -0500 Subject: [PATCH 375/942] split the repo into a workspace remove `clap` dependency :tada: update the book installation instructions --- .github/workflows/bindgen.yml | 4 +- .gitignore | 3 +- Cargo.lock | 364 ++++++++++++++++-- Cargo.toml | 97 +---- bindgen-cli/Cargo.toml | 44 +++ {src => bindgen-cli}/main.rs | 46 +-- {src => bindgen-cli}/options.rs | 2 +- bindgen-integration/Cargo.toml | 2 +- bindgen-integration/build.rs | 29 +- bindgen-tests/Cargo.toml | 28 ++ bindgen-tests/build.rs | 49 +++ .../expectations => bindgen-tests}/src/lib.rs | 0 {tests => bindgen-tests/tests}/.gitattributes | 0 .../tests}/expectations/Cargo.toml | 0 .../tests}/expectations/build.rs | 6 +- .../tests}/expectations/lib.rs | 0 .../tests/expectations/src/lib.rs | 0 .../struct_with_anon_struct_array_float.rs | 1 + .../tests}/expectations/tests/.gitattributes | 0 .../expectations/tests/16-byte-alignment.rs | 0 .../tests/16-byte-alignment_1_0.rs | 0 .../expectations/tests/381-decltype-alias.rs | 0 .../tests}/expectations/tests/accessors.rs | 0 .../expectations/tests/allowlist-file.rs | 0 .../tests/allowlist-namespaces-basic.rs | 0 .../tests/allowlist-namespaces.rs | 0 .../expectations/tests/allowlist_basic.rs | 0 .../expectations/tests/allowlist_fix.rs | 0 .../expectations/tests/allowlist_vars.rs | 0 .../expectations/tests/allowlist_warnings.rs | 0 .../allowlisted-item-references-no-hash.rs | 0 ...llowlisted-item-references-no-partialeq.rs | 0 .../allowlisted_item_references_no_copy.rs | 0 .../expectations/tests/annotation_hide.rs | 0 .../expectations/tests/anon-fields-prefix.rs | 0 .../tests}/expectations/tests/anon_enum.rs | 0 .../expectations/tests/anon_enum_allowlist.rs | 0 .../expectations/tests/anon_enum_trait.rs | 0 .../tests/anon_struct_in_union.rs | 0 .../tests/anon_struct_in_union_1_0.rs | 0 .../tests}/expectations/tests/anon_union.rs | 0 .../expectations/tests/anon_union_1_0.rs | 0 .../tests/anonymous-template-types.rs | 0 .../tests}/expectations/tests/arg_keyword.rs | 0 .../tests/array-of-zero-sized-types.rs | 0 .../tests/attribute_warn_unused_result.rs | 0 ...rn_unused_result_no_attribute_detection.rs | 0 .../attribute_warn_unused_result_pre_1_27.rs | 0 .../bad-namespace-parenthood-inheritance.rs | 0 .../expectations/tests/base-to-derived.rs | 0 .../tests/bindgen-union-inside-namespace.rs | 0 .../tests/bitfield-32bit-overflow.rs | 0 .../expectations/tests/bitfield-enum-basic.rs | 0 .../tests/bitfield-enum-repr-c.rs | 0 .../tests/bitfield-enum-repr-transparent.rs | 0 .../expectations/tests/bitfield-large.rs | 0 .../expectations/tests/bitfield-linux-32.rs | 0 .../tests/bitfield-method-same-name.rs | 0 .../expectations/tests/bitfield_align.rs | 0 .../expectations/tests/bitfield_align_2.rs | 0 .../tests/bitfield_large_overflow.rs | 0 .../tests/bitfield_method_mangling.rs | 0 .../tests/bitfield_pragma_packed.rs | 0 .../expectations/tests/block_return_type.rs | 0 .../tests/blocklist-and-impl-debug.rs | 0 .../expectations/tests/blocklist-file.rs | 0 .../expectations/tests/blocklist-function.rs | 0 .../expectations/tests/blocklist-item.rs | 0 .../expectations/tests/blocks-signature.rs | 0 .../tests}/expectations/tests/blocks.rs | 0 .../tests}/expectations/tests/bug-1529681.rs | 0 .../expectations/tests/builtin-template.rs | 0 .../expectations/tests/c-empty-layout.rs | 0 .../tests}/expectations/tests/c_naming.rs | 0 .../expectations/tests/call-conv-typedef.rs | 0 .../expectations/tests/canonical-types.rs | 0 .../canonical_path_without_namespacing.rs | 0 .../tests}/expectations/tests/char.rs | 0 .../tests}/expectations/tests/class.rs | 0 .../tests}/expectations/tests/class_1_0.rs | 0 .../tests}/expectations/tests/class_nested.rs | 0 .../expectations/tests/class_no_members.rs | 0 .../tests}/expectations/tests/class_static.rs | 0 .../expectations/tests/class_static_const.rs | 0 .../tests}/expectations/tests/class_use_as.rs | 0 .../expectations/tests/class_with_dtor.rs | 0 .../tests/class_with_inner_struct.rs | 0 .../tests/class_with_inner_struct_1_0.rs | 0 .../expectations/tests/class_with_typedef.rs | 0 .../expectations/tests/comment-indent.rs | 0 .../tests}/expectations/tests/complex.rs | 0 .../expectations/tests/complex_global.rs | 0 .../expectations/tests/const-const-mut-ptr.rs | 0 .../tests}/expectations/tests/const_array.rs | 0 .../expectations/tests/const_array_fn_arg.rs | 0 .../expectations/tests/const_enum_unnamed.rs | 0 .../tests/const_multidim_array_fn_arg.rs | 0 .../tests}/expectations/tests/const_ptr.rs | 0 .../expectations/tests/const_resolved_ty.rs | 0 .../tests}/expectations/tests/const_tparam.rs | 0 .../tests/constant-non-specialized-tp.rs | 0 .../tests/constified-enum-module-overflow.rs | 0 .../expectations/tests/constify-all-enums.rs | 0 .../expectations/tests/constify-enum.rs | 0 .../tests/constify-module-enums-basic.rs | 0 .../tests/constify-module-enums-namespace.rs | 0 .../constify-module-enums-shadow-name.rs | 0 .../constify-module-enums-simple-alias.rs | 0 ...onstify-module-enums-simple-nonamespace.rs | 0 .../tests/constify-module-enums-types.rs | 0 .../expectations/tests/constructor-tp.rs | 0 .../tests}/expectations/tests/constructors.rs | 0 .../expectations/tests/constructors_1_33.rs | 0 .../tests/contains-vs-inherits-zero-sized.rs | 0 .../tests/convert-cpp-comment-to-rust.rs | 0 .../expectations/tests/convert-floats.rs | 0 .../tests}/expectations/tests/core_ffi_c.rs | 0 .../expectations/tests/cpp-empty-layout.rs | 0 .../tests}/expectations/tests/crtp.rs | 0 .../expectations/tests/ctypes-prefix-path.rs | 0 .../expectations/tests/dash_language.rs | 0 .../tests/decl_extern_int_twice.rs | 0 .../expectations/tests/decl_ptr_to_array.rs | 0 .../default-enum-style-constified-module.rs | 0 .../default-macro-constant-type-signed.rs | 0 .../default-macro-constant-type-unsigned.rs | 0 .../tests/default-macro-constant-type.rs | 0 .../tests/default-template-parameter.rs | 0 .../expectations/tests/deleted-function.rs | 0 .../tests/derive-bitfield-method-same-name.rs | 0 .../tests}/expectations/tests/derive-clone.rs | 0 .../expectations/tests/derive-clone_1_0.rs | 0 .../expectations/tests/derive-custom.rs | 0 .../tests/derive-debug-bitfield-core.rs | 0 .../tests/derive-debug-bitfield.rs | 0 .../tests/derive-debug-function-pointer.rs | 0 .../tests/derive-debug-generic.rs | 0 .../tests/derive-debug-mangle-name.rs | 0 ...ive-debug-opaque-template-instantiation.rs | 0 .../expectations/tests/derive-debug-opaque.rs | 0 .../tests/derive-default-and-blocklist.rs | 0 .../expectations/tests/derive-fn-ptr.rs | 0 .../tests/derive-hash-and-blocklist.rs | 0 .../tests/derive-hash-blocklisting.rs | 0 ...rive-hash-struct-with-anon-struct-float.rs | 0 .../derive-hash-struct-with-float-array.rs | 0 ...erive-hash-struct-with-incomplete-array.rs | 0 .../tests/derive-hash-struct-with-pointer.rs | 0 .../tests/derive-hash-template-def-float.rs | 0 .../tests/derive-hash-template-inst-float.rs | 0 .../tests/derive-partialeq-and-blocklist.rs | 0 .../tests/derive-partialeq-anonfield.rs | 0 .../tests/derive-partialeq-base.rs | 0 .../tests/derive-partialeq-bitfield.rs | 0 .../tests/derive-partialeq-core.rs | 0 .../tests/derive-partialeq-pointer.rs | 0 .../tests/derive-partialeq-union.rs | 0 .../tests/derive-partialeq-union_1_0.rs | 0 .../expectations/tests/disable-namespacing.rs | 0 .../tests/disable-nested-struct-naming.rs | 0 .../tests/disable-untagged-union.rs | 0 .../tests/divide-by-zero-in-struct-layout.rs | 0 .../expectations/tests/do-not-derive-copy.rs | 0 .../expectations/tests/doggo-or-null.rs | 0 .../tests/dupe-enum-variant-in-namespace.rs | 0 .../duplicated-namespaces-definitions.rs | 0 .../tests/duplicated-namespaces.rs | 0 .../tests/duplicated_constants_in_ns.rs | 0 .../tests/dynamic_loading_attributes.rs | 10 +- .../tests/dynamic_loading_required.rs | 0 .../tests/dynamic_loading_simple.rs | 0 .../tests/dynamic_loading_template.rs | 0 .../tests/dynamic_loading_with_allowlist.rs | 0 .../tests/dynamic_loading_with_blocklist.rs | 0 .../tests/dynamic_loading_with_class.rs | 0 .../tests}/expectations/tests/elaborated.rs | 0 .../tests}/expectations/tests/empty-enum.rs | 0 .../tests}/expectations/tests/empty-union.rs | 0 .../tests/empty_template_param_name.rs | 0 .../tests/enum-default-bitfield.rs | 0 .../expectations/tests/enum-default-consts.rs | 0 .../expectations/tests/enum-default-module.rs | 0 .../expectations/tests/enum-default-rust.d | 0 .../expectations/tests/enum-default-rust.rs | 0 .../expectations/tests/enum-doc-bitfield.rs | 0 .../tests}/expectations/tests/enum-doc-mod.rs | 0 .../expectations/tests/enum-doc-rusty.rs | 0 .../tests}/expectations/tests/enum-doc.rs | 0 .../expectations/tests/enum-no-debug-rust.rs | 0 .../expectations/tests/enum-translate-type.rs | 0 .../expectations/tests/enum-undefault.rs | 0 .../tests/enum-variant-replaces.rs | 0 .../tests}/expectations/tests/enum.rs | 0 .../tests}/expectations/tests/enum_alias.rs | 0 .../tests/enum_and_vtable_mangling.rs | 0 .../tests}/expectations/tests/enum_dupe.rs | 0 .../expectations/tests/enum_explicit_type.rs | 0 .../tests/enum_explicit_type_constants.rs | 0 .../expectations/tests/enum_in_template.rs | 0 .../tests/enum_in_template_with_typedef.rs | 0 .../expectations/tests/enum_negative.rs | 0 .../tests}/expectations/tests/enum_packed.rs | 0 .../tests/eval-value-dependent.rs | 0 .../tests/eval-variadic-template-parameter.rs | 0 .../expectations/tests/explicit-padding.rs | 0 .../expectations/tests/extern-const-struct.rs | 0 .../tests}/expectations/tests/extern.rs | 0 .../tests/fit-macro-constant-types-signed.rs | 0 .../tests/fit-macro-constant-types.rs | 0 .../tests}/expectations/tests/float128.rs | 0 .../tests/forward-declaration-autoptr.rs | 0 .../expectations/tests/forward-enum-decl.rs | 0 .../forward-inherit-struct-with-fields.rs | 0 .../tests/forward-inherit-struct.rs | 0 .../tests/forward_declared_complex_types.rs | 0 .../forward_declared_complex_types_1_0.rs | 0 .../tests/forward_declared_opaque.rs | 0 .../tests/forward_declared_struct.rs | 0 .../tests}/expectations/tests/func_proto.rs | 0 .../tests}/expectations/tests/func_ptr.rs | 0 .../expectations/tests/func_ptr_in_struct.rs | 0 .../tests/func_ptr_return_type.rs | 0 .../tests/func_return_must_use.rs | 0 .../expectations/tests/func_with_array_arg.rs | 0 .../tests/func_with_func_ptr_arg.rs | 0 .../tests/function-typedef-stdcall.rs | 0 .../tests/gen-constructors-neg.rs | 0 .../expectations/tests/gen-constructors.rs | 0 .../expectations/tests/gen-destructors-neg.rs | 0 .../expectations/tests/gen-destructors.rs | 0 .../expectations/tests/generate-inline.rs | 0 .../tests}/expectations/tests/i128.rs | 0 .../expectations/tests/in_class_typedef.rs | 0 .../tests/incomplete-array-padding.rs | 0 .../expectations/tests/infinite-macro.rs | 0 ...from-template-instantiation-with-vtable.rs | 0 .../expectations/tests/inherit-namespaced.rs | 0 .../expectations/tests/inherit_named.rs | 0 .../expectations/tests/inherit_typedef.rs | 0 .../expectations/tests/inline-function.rs | 0 .../expectations/tests/inline_namespace.rs | 0 .../tests/inline_namespace_allowlist.rs | 0 .../tests/inline_namespace_conservative.rs | 0 .../tests/inline_namespace_no_ns_enabled.rs | 0 .../expectations/tests/inner-typedef-gh422.rs | 0 .../tests}/expectations/tests/inner_const.rs | 0 .../expectations/tests/inner_template_self.rs | 0 .../tests}/expectations/tests/int128_t.rs | 0 .../tests/issue-1025-unknown-enum-repr.rs | 0 .../tests}/expectations/tests/issue-1034.rs | 0 .../tests}/expectations/tests/issue-1040.rs | 0 .../issue-1076-unnamed-bitfield-alignment.rs | 0 .../tests/issue-1113-template-references.rs | 0 .../tests/issue-1118-using-forward-decl.rs | 0 .../tests/issue-1197-pure-virtual-stuff.rs | 0 .../issue-1198-alias-rust-bitfield-enum.rs | 0 ...1198-alias-rust-const-mod-bitfield-enum.rs | 0 .../issue-1198-alias-rust-const-mod-enum.rs | 0 .../tests/issue-1198-alias-rust-enum.rs | 0 .../tests/issue-1216-variadic-member.rs | 0 .../tests/issue-1238-fwd-no-copy.rs | 0 .../tests}/expectations/tests/issue-1281.rs | 0 .../tests}/expectations/tests/issue-1285.rs | 0 .../tests}/expectations/tests/issue-1291.rs | 0 .../issue-1350-attribute-overloadable.rs | 0 .../tests/issue-1382-rust-primitive-types.rs | 0 .../tests}/expectations/tests/issue-1435.rs | 0 .../tests}/expectations/tests/issue-1443.rs | 0 .../tests}/expectations/tests/issue-1454.rs | 0 .../tests}/expectations/tests/issue-1464.rs | 0 .../tests/issue-1488-enum-new-type.rs | 0 .../expectations/tests/issue-1488-options.rs | 0 .../issue-1488-template-alias-new-type.rs | 0 .../tests}/expectations/tests/issue-1498.rs | 0 .../tests}/expectations/tests/issue-1514.rs | 0 .../tests}/expectations/tests/issue-1554.rs | 0 .../issue-1599-opaque-typedef-to-enum.rs | 0 .../issue-1676-macro-namespace-prefix.rs | 0 .../tests}/expectations/tests/issue-1947.rs | 0 .../tests/issue-1977-larger-arrays.rs | 0 .../tests}/expectations/tests/issue-1995.rs | 0 .../tests}/expectations/tests/issue-2019.rs | 0 ...issue-2239-template-dependent-bit-width.rs | 0 .../tests}/expectations/tests/issue-358.rs | 0 .../tests}/expectations/tests/issue-372.rs | 0 .../tests}/expectations/tests/issue-410.rs | 0 .../tests}/expectations/tests/issue-446.rs | 0 .../tests}/expectations/tests/issue-447.rs | 0 .../tests}/expectations/tests/issue-493.rs | 0 .../expectations/tests/issue-493_1_0.rs | 0 .../tests}/expectations/tests/issue-511.rs | 0 .../tests/issue-537-repr-packed-n.rs | 0 .../tests}/expectations/tests/issue-537.rs | 0 .../tests/issue-544-stylo-creduce-2.rs | 0 .../tests/issue-544-stylo-creduce.rs | 0 ...ate-params-causing-layout-test-failures.rs | 0 .../tests/issue-573-layout-test-failures.rs | 0 .../issue-574-assertion-failure-in-codegen.rs | 0 ...issue-584-stylo-template-analysis-panic.rs | 0 ...e-638-stylo-cannot-find-T-in-this-scope.rs | 0 .../tests/issue-639-typedef-anon-field.rs | 0 .../tests/issue-643-inner-struct.rs | 0 ...ue-645-cannot-find-type-T-in-this-scope.rs | 0 .../issue-648-derive-debug-with-padding.rs | 0 .../tests/issue-654-struct-fn-collision.rs | 0 .../issue-662-cannot-find-T-in-this-scope.rs | 0 .../expectations/tests/issue-662-part-2.rs | 0 .../tests}/expectations/tests/issue-674-1.rs | 0 .../tests}/expectations/tests/issue-674-2.rs | 0 .../tests}/expectations/tests/issue-674-3.rs | 0 .../tests/issue-677-nested-ns-specifier.rs | 0 .../issue-691-template-parameter-virtual.rs | 0 .../tests/issue-710-must-use-type.rs | 0 .../tests/issue-739-pointer-wide-bitfield.rs | 0 .../tests/issue-801-opaque-sloppiness.rs | 0 ...07-opaque-types-methods-being-generated.rs | 0 .../tests}/expectations/tests/issue-816.rs | 0 ...ssue-820-unused-template-param-in-alias.rs | 0 ...26-generating-methods-when-asked-not-to.rs | 0 .../tests}/expectations/tests/issue-833-1.rs | 0 .../tests}/expectations/tests/issue-833-2.rs | 0 .../tests}/expectations/tests/issue-833.rs | 0 .../tests}/expectations/tests/issue-834.rs | 0 .../issue-848-replacement-system-include.rs | 0 .../tests/issue-888-enum-var-decl-jump.rs | 0 .../issue-944-derive-copy-and-blocklisting.rs | 0 .../tests}/expectations/tests/issue-946.rs | 0 .../tests}/expectations/tests/issue_311.rs | 0 .../tests}/expectations/tests/issue_315.rs | 0 .../expectations/tests/jsval_layout_opaque.rs | 0 .../tests/jsval_layout_opaque_1_0.rs | 0 .../tests}/expectations/tests/keywords.rs | 0 .../tests}/expectations/tests/layout.rs | 0 .../tests}/expectations/tests/layout_align.rs | 0 .../tests}/expectations/tests/layout_arp.rs | 0 .../tests}/expectations/tests/layout_array.rs | 0 .../tests/layout_array_too_long.rs | 0 .../tests/layout_cmdline_token.rs | 0 .../expectations/tests/layout_eth_conf.rs | 0 .../expectations/tests/layout_eth_conf_1_0.rs | 0 .../expectations/tests/layout_kni_mbuf.rs | 0 .../tests/layout_large_align_field.rs | 0 .../tests}/expectations/tests/layout_mbuf.rs | 0 .../expectations/tests/layout_mbuf_1_0.rs | 0 .../tests/libclang-5/abi_variadic_function.rs | 0 .../expectations/tests/libclang-5/auto.rs | 0 .../tests/libclang-5/call-conv-field.rs | 0 .../tests/libclang-5/const_bool.rs | 0 .../tests/libclang-5/constant-evaluate.rs | 0 ...0600-cannot-apply-unary-negation-to-u32.rs | 0 .../issue-769-bad-instantiation-test.rs | 0 .../tests/libclang-5/mangling-win32.rs | 0 .../tests/libclang-5/objc_inheritance.rs | 0 .../tests/libclang-5/objc_template.rs | 0 .../partial-specialization-and-inheritance.rs | 0 .../type_alias_template_specialized.rs | 0 .../tests/libclang-9/abi_variadic_function.rs | 0 .../expectations/tests/libclang-9/auto.rs | 0 .../tests/libclang-9/call-conv-field.rs | 0 .../expectations/tests/libclang-9/class.rs | 0 .../tests/libclang-9/class_1_0.rs | 0 .../tests/libclang-9/const_bool.rs | 0 .../tests/libclang-9/constant-evaluate.rs | 0 ...erive-hash-struct-with-incomplete-array.rs | 0 ...0600-cannot-apply-unary-negation-to-u32.rs | 0 .../libclang-9/incomplete-array-padding.rs | 0 .../libclang-9/issue-643-inner-struct.rs | 0 .../issue-769-bad-instantiation-test.rs | 0 .../tests/libclang-9/layout_align.rs | 0 .../tests/libclang-9/mangling-win32.rs | 0 .../tests/libclang-9/objc_inheritance.rs | 0 .../tests/libclang-9/objc_template.rs | 0 .../partial-specialization-and-inheritance.rs | 0 .../type_alias_template_specialized.rs | 0 .../tests/libclang-9/zero-sized-array.rs | 0 ...bclang_version_specific_generated_tests.rs | 0 .../tests}/expectations/tests/long_double.rs | 0 .../expectations/tests/macro-expr-basic.rs | 0 .../tests/macro-expr-uncommon-token.rs | 0 .../tests}/expectations/tests/macro-redef.rs | 0 .../tests}/expectations/tests/macro_const.rs | 0 .../expectations/tests/macro_const_1_0.rs | 0 .../tests/maddness-is-avoidable.rs | 0 .../tests}/expectations/tests/mangling-ios.rs | 0 .../expectations/tests/mangling-linux32.rs | 0 .../expectations/tests/mangling-linux64.rs | 0 .../expectations/tests/mangling-macos.rs | 0 .../expectations/tests/mangling-win64.rs | 0 .../expectations/tests/merge-extern-blocks.rs | 0 .../expectations/tests/method-mangling.rs | 0 .../expectations/tests/module-allowlisted.rs | 0 .../tests}/expectations/tests/msvc-no-usr.rs | 0 .../multiple-inherit-empty-correct-layout.rs | 0 .../tests}/expectations/tests/mutable.rs | 0 .../tests}/expectations/tests/namespace.rs | 0 .../tests/nested-template-typedef.rs | 0 .../tests}/expectations/tests/nested.rs | 0 .../expectations/tests/nested_vtable.rs | 0 .../tests/nested_within_namespace.rs | 0 .../tests}/expectations/tests/newtype-enum.rs | 0 .../expectations/tests/newtype-global-enum.rs | 0 .../tests}/expectations/tests/no-comments.rs | 0 .../expectations/tests/no-derive-debug.rs | 0 .../expectations/tests/no-derive-default.rs | 0 .../expectations/tests/no-hash-allowlisted.rs | 0 .../expectations/tests/no-hash-opaque.rs | 0 .../tests/no-partialeq-allowlisted.rs | 0 .../expectations/tests/no-partialeq-opaque.rs | 0 .../tests/no-recursive-allowlisting.rs | 0 .../tests}/expectations/tests/no-std.rs | 0 .../tests}/expectations/tests/no_copy.rs | 0 .../expectations/tests/no_copy_allowlisted.rs | 0 .../expectations/tests/no_copy_opaque.rs | 0 .../tests}/expectations/tests/no_debug.rs | 0 .../tests/no_debug_allowlisted.rs | 0 .../tests/no_debug_bypass_impl_debug.rs | 0 .../expectations/tests/no_debug_opaque.rs | 0 .../tests}/expectations/tests/no_default.rs | 0 .../tests/no_default_allowlisted.rs | 0 .../tests/no_default_bypass_derive_default.rs | 0 .../expectations/tests/no_default_opaque.rs | 0 .../expectations/tests/no_size_t_is_usize.rs | 0 .../expectations/tests/non-type-params.rs | 0 .../tests}/expectations/tests/noreturn.rs | 4 +- .../expectations/tests/nsBaseHashtable.rs | 0 .../expectations/tests/nsStyleAutoArray.rs | 0 .../expectations/tests/objc_allowlist.rs | 0 .../expectations/tests/objc_blocklist.rs | 0 .../expectations/tests/objc_category.rs | 0 .../tests}/expectations/tests/objc_class.rs | 0 .../expectations/tests/objc_class_method.rs | 0 .../expectations/tests/objc_interface.rs | 0 .../expectations/tests/objc_interface_type.rs | 0 .../tests}/expectations/tests/objc_method.rs | 0 .../expectations/tests/objc_method_clash.rs | 0 .../tests/objc_pointer_return_types.rs | 0 .../expectations/tests/objc_property_fnptr.rs | 0 .../expectations/tests/objc_protocol.rs | 0 .../tests/objc_protocol_inheritance.rs | 0 .../expectations/tests/objc_sel_and_id.rs | 0 .../expectations/tests/only_bitfields.rs | 0 .../tests/opaque-template-inst-member-2.rs | 0 .../tests/opaque-template-inst-member.rs | 0 ...paque-template-instantiation-namespaced.rs | 0 .../tests/opaque-template-instantiation.rs | 0 .../expectations/tests/opaque-tracing.rs | 0 .../expectations/tests/opaque_in_struct.rs | 0 .../expectations/tests/opaque_pointer.rs | 0 .../expectations/tests/opaque_typedef.rs | 0 .../tests}/expectations/tests/operator.rs | 0 .../tests}/expectations/tests/ord-enum.rs | 0 .../expectations/tests/overflowed_enum.rs | 0 .../tests}/expectations/tests/overloading.rs | 0 .../expectations/tests/packed-bitfield.rs | 0 .../tests/packed-n-with-padding.rs | 0 .../expectations/tests/packed-vtable.rs | 0 .../tests}/expectations/tests/parm-union.rs | 0 .../parsecb-anonymous-enum-variant-rename.rs | 0 .../tests}/expectations/tests/pointer-attr.rs | 0 .../tests/prepend-enum-constified-variant.rs | 0 .../expectations/tests/prepend_enum_name.rs | 0 .../tests}/expectations/tests/private.rs | 0 .../expectations/tests/private_fields.rs | 0 .../tests}/expectations/tests/public-dtor.rs | 0 .../tests/qualified-dependent-types.rs | 0 .../expectations/tests/redeclaration.rs | 0 .../expectations/tests/ref_argument_array.rs | 0 .../tests/reparented_replacement.rs | 0 .../tests/replace_template_alias.rs | 0 .../tests}/expectations/tests/replace_use.rs | 0 .../expectations/tests/replaces_double.rs | 0 .../tests}/expectations/tests/repr-align.rs | 0 .../tests/resolved_type_def_function.rs | 0 ...ame_struct_name_in_different_namespaces.rs | 0 .../tests/sentry-defined-multiple-times.rs | 0 .../tests}/expectations/tests/short-enums.rs | 0 .../expectations/tests/size_t_template.rs | 0 .../tests}/expectations/tests/sorted-items.rs | 0 .../expectations/tests/stdint_typedef.rs | 0 ...ruct_containing_forward_declared_struct.rs | 0 .../expectations/tests/struct_typedef.rs | 0 .../expectations/tests/struct_typedef_ns.rs | 0 .../tests/struct_with_anon_struct.rs | 0 .../tests/struct_with_anon_struct_array.rs | 0 .../tests/struct_with_anon_struct_pointer.rs | 0 .../tests/struct_with_anon_union.rs | 0 .../tests/struct_with_anon_union_1_0.rs | 0 .../tests/struct_with_anon_unnamed_struct.rs | 0 .../tests/struct_with_anon_unnamed_union.rs | 0 .../struct_with_anon_unnamed_union_1_0.rs | 0 .../tests/struct_with_bitfields.rs | 0 .../tests/struct_with_derive_debug.rs | 0 .../tests/struct_with_large_array.rs | 0 .../expectations/tests/struct_with_nesting.rs | 0 .../tests/struct_with_nesting_1_0.rs | 0 .../expectations/tests/struct_with_packing.rs | 0 .../expectations/tests/struct_with_struct.rs | 0 .../tests/struct_with_typedef_template_arg.rs | 0 .../expectations/tests/template-fun-ty.rs | 0 .../tests/template-param-usage-0.rs | 0 .../tests/template-param-usage-1.rs | 0 .../tests/template-param-usage-10.rs | 0 .../tests/template-param-usage-11.rs | 0 .../tests/template-param-usage-12.rs | 0 .../tests/template-param-usage-13.rs | 0 .../tests/template-param-usage-14.rs | 0 .../tests/template-param-usage-15.rs | 0 .../tests/template-param-usage-2.rs | 0 .../tests/template-param-usage-3.rs | 0 .../tests/template-param-usage-4.rs | 0 .../tests/template-param-usage-5.rs | 0 .../tests/template-param-usage-6.rs | 0 .../tests/template-param-usage-7.rs | 0 .../tests/template-param-usage-8.rs | 0 .../tests/template-param-usage-9.rs | 0 .../expectations/tests/template-with-var.rs | 0 .../tests}/expectations/tests/template.rs | 0 .../expectations/tests/template_alias.rs | 0 .../tests/template_alias_basic.rs | 0 .../tests/template_alias_namespace.rs | 0 .../tests}/expectations/tests/template_fun.rs | 0 ...mplate_instantiation_with_fn_local_type.rs | 0 .../tests/template_partial_specification.rs | 0 .../template_typedef_transitive_param.rs | 0 .../expectations/tests/template_typedefs.rs | 0 .../expectations/tests/templateref_opaque.rs | 0 .../tests/templatized-bitfield.rs | 0 .../test_mixed_header_and_header_contents.rs | 0 .../test_multiple_header_calls_in_builder.rs | 0 .../tests}/expectations/tests/timex.rs | 0 .../tests}/expectations/tests/transform-op.rs | 0 ...type-referenced-by-allowlisted-function.rs | 0 .../expectations/tests/type_alias_empty.rs | 0 ..._alias_partial_template_especialization.rs | 0 .../tests/typedefd-array-as-function-arg.rs | 0 .../tests}/expectations/tests/typeref.rs | 0 .../tests}/expectations/tests/typeref_1_0.rs | 0 .../tests}/expectations/tests/underscore.rs | 0 .../tests}/expectations/tests/union-align.rs | 0 .../tests}/expectations/tests/union-in-ns.rs | 0 .../expectations/tests/union-in-ns_1_0.rs | 0 .../expectations/tests/union_bitfield.rs | 0 .../expectations/tests/union_bitfield_1_0.rs | 0 .../tests}/expectations/tests/union_dtor.rs | 0 .../expectations/tests/union_dtor_1_0.rs | 0 .../tests}/expectations/tests/union_fields.rs | 0 .../expectations/tests/union_fields_1_0.rs | 0 .../expectations/tests/union_template.rs | 0 .../expectations/tests/union_template_1_0.rs | 0 .../tests/union_with_anon_struct.rs | 0 .../tests/union_with_anon_struct_1_0.rs | 0 .../tests/union_with_anon_struct_bitfield.rs | 0 .../union_with_anon_struct_bitfield_1_0.rs | 0 .../tests/union_with_anon_union.rs | 0 .../tests/union_with_anon_union_1_0.rs | 0 .../tests/union_with_anon_unnamed_struct.rs | 0 .../union_with_anon_unnamed_struct_1_0.rs | 0 .../tests/union_with_anon_unnamed_union.rs | 0 .../union_with_anon_unnamed_union_1_0.rs | 0 .../tests/union_with_big_member.rs | 0 .../tests/union_with_big_member_1_0.rs | 0 .../expectations/tests/union_with_nesting.rs | 0 .../tests/union_with_nesting_1_0.rs | 0 .../tests/union_with_non_copy_member.rs | 0 .../tests}/expectations/tests/unknown_attr.rs | 0 .../expectations/tests/unsorted-items.rs | 0 .../tests}/expectations/tests/use-core.rs | 0 .../tests}/expectations/tests/use-core_1_0.rs | 0 .../tests}/expectations/tests/using.rs | 0 .../tests}/expectations/tests/var-tracing.rs | 0 .../expectations/tests/variadic-method.rs | 0 .../tests/variadic_template_function.rs | 0 .../tests}/expectations/tests/vector.rs | 0 .../tests}/expectations/tests/virtual_dtor.rs | 0 .../expectations/tests/virtual_inheritance.rs | 0 .../expectations/tests/virtual_interface.rs | 0 .../expectations/tests/virtual_overloaded.rs | 0 .../tests/vtable_recursive_sig.rs | 0 .../tests/wasm-constructor-returns.rs | 0 .../expectations/tests/wasm-import-module.rs | 0 .../expectations/tests/weird_bitfields.rs | 0 .../expectations/tests/what_is_going_on.rs | 0 .../expectations/tests/win32-thiscall_1_0.rs | 0 .../tests/win32-thiscall_nightly.rs | 0 .../tests/win32-vectorcall-1_0.rs | 0 .../tests/win32-vectorcall-nightly.rs | 0 .../tests/with_array_pointers_arguments.rs | 0 .../tests/without_array_pointers_arguments.rs | 0 .../tests/zero-size-array-align.rs | 0 .../expectations/tests/zero-sized-array.rs | 0 .../tests}/headers/16-byte-alignment.h | 0 .../tests}/headers/16-byte-alignment_1_0.h | 0 .../tests}/headers/381-decltype-alias.hpp | 0 .../tests}/headers/abi_variadic_function.hpp | 0 .../tests}/headers/accessors.hpp | 0 .../tests}/headers/allowlist-file.hpp | 0 .../headers/allowlist-namespaces-basic.hpp | 0 .../tests}/headers/allowlist-namespaces.hpp | 0 .../tests}/headers/allowlist_basic.hpp | 0 .../tests}/headers/allowlist_fix.hpp | 0 .../tests}/headers/allowlist_vars.h | 0 .../tests}/headers/allowlist_warnings.h | 0 .../allowlisted-item-references-no-hash.hpp | 0 ...lowlisted-item-references-no-partialeq.hpp | 0 .../tests}/headers/allowlisted/file.hpp | 0 .../allowlisted_item_references_no_copy.hpp | 0 .../tests}/headers/annotation_hide.hpp | 0 .../tests}/headers/anon-fields-prefix.h | 0 .../tests}/headers/anon_enum.hpp | 0 .../tests}/headers/anon_enum_allowlist.h | 0 .../tests}/headers/anon_enum_trait.hpp | 0 .../tests}/headers/anon_struct_in_union.h | 0 .../tests}/headers/anon_struct_in_union_1_0.h | 0 .../tests}/headers/anon_union.hpp | 0 .../tests}/headers/anon_union_1_0.hpp | 0 .../headers/anonymous-template-types.hpp | 0 .../tests}/headers/arg_keyword.hpp | 0 .../headers/array-of-zero-sized-types.hpp | 0 .../headers/attribute_warn_unused_result.hpp | 0 ...n_unused_result_no_attribute_detection.hpp | 0 .../attribute_warn_unused_result_pre_1_27.hpp | 0 .../tests}/headers/auto.hpp | 0 .../bad-namespace-parenthood-inheritance.hpp | 0 .../tests}/headers/base-to-derived.hpp | 0 .../bindgen-union-inside-namespace.hpp | 0 .../tests}/headers/bitfield-32bit-overflow.h | 0 .../tests}/headers/bitfield-enum-basic.hpp | 0 .../tests}/headers/bitfield-enum-repr-c.hpp | 0 .../bitfield-enum-repr-transparent.hpp | 0 .../tests}/headers/bitfield-large.hpp | 0 .../tests}/headers/bitfield-linux-32.hpp | 0 .../headers/bitfield-method-same-name.hpp | 0 .../tests}/headers/bitfield_align.h | 0 .../tests}/headers/bitfield_align_2.h | 0 .../headers/bitfield_large_overflow.hpp | 0 .../tests}/headers/bitfield_method_mangling.h | 0 .../tests}/headers/bitfield_pragma_packed.h | 0 .../tests}/headers/block_return_type.h | 0 .../headers/blocklist-and-impl-debug.hpp | 0 .../tests}/headers/blocklist-file.hpp | 0 .../tests}/headers/blocklist-function.hpp | 0 .../tests}/headers/blocklist-item.hpp | 0 .../tests}/headers/blocklisted/fake-stdint.h | 0 .../tests}/headers/blocklisted/file.hpp | 0 .../tests}/headers/blocks-signature.hpp | 0 .../tests}/headers/blocks.hpp | 0 .../tests}/headers/bug-1529681.hpp | 0 .../tests}/headers/builtin-template.hpp | 0 .../tests}/headers/c-empty-layout.h | 0 .../tests}/headers/c_naming.h | 0 .../tests}/headers/call-conv-field.h | 0 .../tests}/headers/call-conv-typedef.h | 0 .../tests}/headers/canonical-types.hpp | 0 .../canonical_path_without_namespacing.hpp | 0 {tests => bindgen-tests/tests}/headers/char.h | 0 .../tests}/headers/class.hpp | 0 .../tests}/headers/class_1_0.hpp | 0 .../tests}/headers/class_nested.hpp | 0 .../tests}/headers/class_no_members.hpp | 0 .../tests}/headers/class_static.hpp | 0 .../tests}/headers/class_static_const.hpp | 0 .../tests}/headers/class_use_as.hpp | 0 .../tests}/headers/class_with_dtor.hpp | 0 .../headers/class_with_inner_struct.hpp | 0 .../headers/class_with_inner_struct_1_0.hpp | 0 .../tests}/headers/class_with_typedef.hpp | 0 .../tests}/headers/comment-indent.hpp | 0 .../tests}/headers/complex.h | 0 .../tests}/headers/complex_global.h | 0 .../tests}/headers/const-const-mut-ptr.h | 0 .../tests}/headers/const_array.h | 0 .../tests}/headers/const_array_fn_arg.h | 0 .../tests}/headers/const_bool.hpp | 0 .../tests}/headers/const_enum_unnamed.hpp | 0 .../headers/const_multidim_array_fn_arg.h | 0 .../tests}/headers/const_ptr.hpp | 0 .../tests}/headers/const_resolved_ty.h | 0 .../tests}/headers/const_tparam.hpp | 0 .../tests}/headers/constant-evaluate.h | 0 .../headers/constant-non-specialized-tp.hpp | 0 .../constified-enum-module-overflow.hpp | 0 .../tests}/headers/constify-all-enums.h | 0 .../tests}/headers/constify-enum.h | 0 .../headers/constify-module-enums-basic.h | 0 .../constify-module-enums-namespace.hpp | 0 .../constify-module-enums-shadow-name.h | 0 .../constify-module-enums-simple-alias.hpp | 0 ...nstify-module-enums-simple-nonamespace.hpp | 0 .../headers/constify-module-enums-types.hpp | 0 .../tests}/headers/constructor-tp.hpp | 0 .../tests}/headers/constructors.hpp | 0 .../tests}/headers/constructors_1_33.hpp | 0 .../contains-vs-inherits-zero-sized.hpp | 0 .../headers/convert-cpp-comment-to-rust.hpp | 0 .../tests}/headers/convert-floats.h | 0 .../tests}/headers/core_ffi_c.h | 0 .../tests}/headers/cpp-empty-layout.hpp | 0 .../tests}/headers/crtp.hpp | 0 .../tests}/headers/ctypes-prefix-path.h | 0 .../tests}/headers/dash_language.h | 0 .../tests}/headers/decl_extern_int_twice.h | 0 .../tests}/headers/decl_ptr_to_array.h | 0 .../default-enum-style-constified-module.h | 0 .../default-macro-constant-type-signed.h | 0 .../default-macro-constant-type-unsigned.h | 0 .../headers/default-macro-constant-type.h | 0 .../headers/default-template-parameter.hpp | 0 .../tests}/headers/deleted-function.hpp | 0 .../derive-bitfield-method-same-name.hpp | 0 .../tests}/headers/derive-clone.h | 0 .../tests}/headers/derive-clone_1_0.h | 0 .../tests}/headers/derive-custom.h | 0 .../headers/derive-debug-bitfield-core.hpp | 0 .../tests}/headers/derive-debug-bitfield.hpp | 0 .../headers/derive-debug-function-pointer.hpp | 0 .../tests}/headers/derive-debug-generic.hpp | 0 .../tests}/headers/derive-debug-mangle-name.h | 0 ...ve-debug-opaque-template-instantiation.hpp | 0 .../tests}/headers/derive-debug-opaque.hpp | 0 .../headers/derive-default-and-blocklist.hpp | 0 .../tests}/headers/derive-fn-ptr.h | 0 .../headers/derive-hash-and-blocklist.hpp | 0 .../headers/derive-hash-blocklisting.hpp | 0 ...erive-hash-struct-with-anon-struct-float.h | 0 .../derive-hash-struct-with-float-array.h | 0 ...derive-hash-struct-with-incomplete-array.h | 0 .../headers/derive-hash-struct-with-pointer.h | 0 .../derive-hash-template-def-float.hpp | 0 .../derive-hash-template-inst-float.hpp | 0 .../derive-partialeq-and-blocklist.hpp | 0 .../headers/derive-partialeq-anonfield.h | 0 .../tests}/headers/derive-partialeq-base.hpp | 0 .../headers/derive-partialeq-bitfield.hpp | 0 .../tests}/headers/derive-partialeq-core.h | 0 .../headers/derive-partialeq-pointer.hpp | 0 .../tests}/headers/derive-partialeq-union.hpp | 0 .../headers/derive-partialeq-union_1_0.hpp | 0 .../tests}/headers/disable-namespacing.hpp | 0 .../headers/disable-nested-struct-naming.h | 0 .../tests}/headers/disable-untagged-union.hpp | 0 .../headers/divide-by-zero-in-struct-layout.h | 0 .../tests}/headers/do-not-derive-copy.hpp | 0 .../tests}/headers/doggo-or-null.hpp | 0 .../headers/dupe-enum-variant-in-namespace.h | 0 .../duplicated-namespaces-definitions.hpp | 0 .../tests}/headers/duplicated-namespaces.hpp | 0 .../headers/duplicated_constants_in_ns.hpp | 0 .../headers/dynamic_loading_attributes.h | 0 .../tests}/headers/dynamic_loading_required.h | 0 .../tests}/headers/dynamic_loading_simple.h | 0 .../headers/dynamic_loading_template.hpp | 0 .../dynamic_loading_with_allowlist.hpp | 0 .../dynamic_loading_with_blocklist.hpp | 0 .../headers/dynamic_loading_with_class.hpp | 0 .../tests}/headers/elaborated.hpp | 0 .../tests}/headers/empty-enum.h | 0 .../tests}/headers/empty-union.hpp | 0 .../headers/empty_template_param_name.hpp | 0 .../tests}/headers/enum-default-bitfield.h | 0 .../tests}/headers/enum-default-consts.h | 0 .../tests}/headers/enum-default-module.h | 0 .../tests}/headers/enum-default-rust.h | 0 .../tests}/headers/enum-doc-bitfield.h | 0 .../tests}/headers/enum-doc-mod.h | 0 .../tests}/headers/enum-doc-rusty.h | 0 .../tests}/headers/enum-doc.h | 0 .../tests}/headers/enum-no-debug-rust.h | 0 .../tests}/headers/enum-translate-type.hpp | 0 .../tests}/headers/enum-undefault.h | 0 .../tests}/headers/enum-variant-replaces.h | 0 {tests => bindgen-tests/tests}/headers/enum.h | 0 .../tests}/headers/enum_alias.hpp | 0 .../headers/enum_and_vtable_mangling.hpp | 0 .../tests}/headers/enum_dupe.h | 0 .../tests}/headers/enum_explicit_type.hpp | 0 .../headers/enum_explicit_type_constants.hpp | 0 .../tests}/headers/enum_in_template.hpp | 0 .../headers/enum_in_template_with_typedef.hpp | 0 .../tests}/headers/enum_negative.h | 0 .../tests}/headers/enum_packed.h | 0 ...E0600-cannot-apply-unary-negation-to-u32.h | 0 .../tests}/headers/eval-value-dependent.hpp | 0 .../eval-variadic-template-parameter.hpp | 0 .../tests}/headers/explicit-padding.h | 0 .../tests}/headers/extern-const-struct.h | 0 .../tests}/headers/extern.hpp | 0 .../headers/fit-macro-constant-types-signed.h | 0 .../tests}/headers/fit-macro-constant-types.h | 0 .../tests}/headers/float128.hpp | 0 .../headers/forward-declaration-autoptr.hpp | 0 .../tests}/headers/forward-enum-decl.hpp | 0 .../forward-inherit-struct-with-fields.hpp | 0 .../tests}/headers/forward-inherit-struct.hpp | 0 .../forward_declared_complex_types.hpp | 0 .../forward_declared_complex_types_1_0.hpp | 0 .../tests}/headers/forward_declared_opaque.h | 0 .../tests}/headers/forward_declared_struct.h | 0 .../tests}/headers/func_proto.h | 0 .../tests}/headers/func_ptr.h | 0 .../tests}/headers/func_ptr_in_struct.h | 0 .../tests}/headers/func_ptr_return_type.h | 0 .../tests}/headers/func_return_must_use.h | 0 .../tests}/headers/func_with_array_arg.h | 0 .../tests}/headers/func_with_func_ptr_arg.h | 0 .../tests}/headers/function-typedef-stdcall.h | 0 .../tests}/headers/gen-constructors-neg.hpp | 0 .../tests}/headers/gen-constructors.hpp | 0 .../tests}/headers/gen-destructors-neg.hpp | 0 .../tests}/headers/gen-destructors.hpp | 0 .../tests}/headers/generate-inline.hpp | 0 {tests => bindgen-tests/tests}/headers/i128.h | 0 .../tests}/headers/in_class_typedef.hpp | 0 .../tests}/headers/incomplete-array-padding.h | 0 .../tests}/headers/infinite-macro.h | 0 ...rom-template-instantiation-with-vtable.hpp | 0 .../tests}/headers/inherit-namespaced.hpp | 0 .../tests}/headers/inherit_named.hpp | 0 .../tests}/headers/inherit_typedef.hpp | 0 .../tests}/headers/inline-function.h | 0 .../tests}/headers/inline_namespace.hpp | 0 .../headers/inline_namespace_allowlist.hpp | 0 .../headers/inline_namespace_conservative.hpp | 0 .../inline_namespace_no_ns_enabled.hpp | 0 .../tests}/headers/inner-typedef-gh422.hpp | 0 .../tests}/headers/inner_const.hpp | 0 .../tests}/headers/inner_template_self.hpp | 0 .../tests}/headers/int128_t.h | 0 .../headers/issue-1025-unknown-enum-repr.hpp | 0 .../tests}/headers/issue-1034.h | 0 .../tests}/headers/issue-1040.h | 0 .../issue-1076-unnamed-bitfield-alignment.h | 0 .../issue-1113-template-references.hpp | 0 .../headers/issue-1118-using-forward-decl.hpp | 0 .../headers/issue-1197-pure-virtual-stuff.hpp | 0 .../issue-1198-alias-rust-bitfield-enum.h | 0 ...-1198-alias-rust-const-mod-bitfield-enum.h | 0 .../issue-1198-alias-rust-const-mod-enum.h | 0 .../headers/issue-1198-alias-rust-enum.h | 0 .../headers/issue-1216-variadic-member.h | 0 .../tests}/headers/issue-1238-fwd-no-copy.h | 0 .../tests}/headers/issue-1281.h | 0 .../tests}/headers/issue-1285.h | 0 .../tests}/headers/issue-1291.hpp | 0 .../issue-1350-attribute-overloadable.h | 0 .../headers/issue-1382-rust-primitive-types.h | 0 .../tests}/headers/issue-1435.hpp | 0 .../tests}/headers/issue-1443.hpp | 0 .../tests}/headers/issue-1454.h | 0 .../tests}/headers/issue-1464.hpp | 0 .../tests}/headers/issue-1488-enum-new-type.h | 0 .../tests}/headers/issue-1488-options.h | 0 .../issue-1488-template-alias-new-type.hpp | 0 .../tests}/headers/issue-1498.h | 0 .../tests}/headers/issue-1514.hpp | 0 .../tests}/headers/issue-1554.h | 0 .../issue-1599-opaque-typedef-to-enum.h | 0 .../issue-1676-macro-namespace-prefix.hpp | 0 .../tests}/headers/issue-1947.h | 0 .../headers/issue-1977-larger-arrays.hpp | 0 .../tests}/headers/issue-1995.h | 0 .../tests}/headers/issue-2019.hpp | 0 ...ssue-2239-template-dependent-bit-width.hpp | 0 .../tests}/headers/issue-358.hpp | 0 .../tests}/headers/issue-372.hpp | 0 .../tests}/headers/issue-410.hpp | 0 .../tests}/headers/issue-446.hpp | 0 .../tests}/headers/issue-447.hpp | 0 .../tests}/headers/issue-493.hpp | 0 .../tests}/headers/issue-493_1_0.hpp | 0 .../tests}/headers/issue-511.h | 0 .../tests}/headers/issue-537-repr-packed-n.h | 0 .../tests}/headers/issue-537.h | 0 .../headers/issue-544-stylo-creduce-2.hpp | 0 .../headers/issue-544-stylo-creduce.hpp | 0 ...te-params-causing-layout-test-failures.hpp | 0 .../issue-573-layout-test-failures.hpp | 0 ...issue-574-assertion-failure-in-codegen.hpp | 0 ...ssue-584-stylo-template-analysis-panic.hpp | 0 ...-638-stylo-cannot-find-T-in-this-scope.hpp | 0 .../headers/issue-639-typedef-anon-field.hpp | 0 .../tests}/headers/issue-643-inner-struct.h | 0 ...e-645-cannot-find-type-T-in-this-scope.hpp | 0 .../issue-648-derive-debug-with-padding.h | 0 .../headers/issue-654-struct-fn-collision.h | 0 .../issue-662-cannot-find-T-in-this-scope.hpp | 0 .../tests}/headers/issue-662-part-2.hpp | 0 .../tests}/headers/issue-674-1.hpp | 0 .../tests}/headers/issue-674-2.hpp | 0 .../tests}/headers/issue-674-3.hpp | 0 .../headers/issue-677-nested-ns-specifier.hpp | 0 .../issue-691-template-parameter-virtual.hpp | 0 .../tests}/headers/issue-710-must-use-type.h | 0 .../headers/issue-739-pointer-wide-bitfield.h | 0 .../issue-769-bad-instantiation-test.hpp | 0 .../headers/issue-801-opaque-sloppiness.hpp | 0 ...7-opaque-types-methods-being-generated.hpp | 0 .../tests}/headers/issue-816.h | 0 ...sue-820-unused-template-param-in-alias.hpp | 0 ...6-generating-methods-when-asked-not-to.hpp | 0 .../tests}/headers/issue-833-1.hpp | 0 .../tests}/headers/issue-833-2.hpp | 0 .../tests}/headers/issue-833.hpp | 0 .../tests}/headers/issue-834.hpp | 0 .../issue-848-replacement-system-include.hpp | 0 .../tests}/headers/issue-848/an-include.h | 0 .../headers/issue-888-enum-var-decl-jump.hpp | 0 ...issue-944-derive-copy-and-blocklisting.hpp | 0 .../tests}/headers/issue-946.h | 0 .../tests}/headers/issue_311.hpp | 0 .../tests}/headers/issue_315.hpp | 0 .../tests}/headers/jsval_layout_opaque.hpp | 0 .../headers/jsval_layout_opaque_1_0.hpp | 0 .../tests}/headers/keywords.h | 0 .../tests}/headers/layout.h | 0 .../tests}/headers/layout_align.h | 0 .../tests}/headers/layout_arp.h | 0 .../tests}/headers/layout_array.h | 0 .../tests}/headers/layout_array_too_long.h | 0 .../tests}/headers/layout_cmdline_token.h | 0 .../tests}/headers/layout_eth_conf.h | 0 .../tests}/headers/layout_eth_conf_1_0.h | 0 .../tests}/headers/layout_kni_mbuf.h | 0 .../tests}/headers/layout_large_align_field.h | 0 .../tests}/headers/layout_mbuf.h | 0 .../tests}/headers/layout_mbuf_1_0.h | 0 .../tests}/headers/long_double.h | 0 .../tests}/headers/macro-expr-basic.h | 0 .../headers/macro-expr-uncommon-token.h | 0 .../tests}/headers/macro-redef.h | 0 .../tests}/headers/macro_const.h | 0 .../tests}/headers/macro_const_1_0.h | 0 .../tests}/headers/maddness-is-avoidable.hpp | 0 .../tests}/headers/mangling-ios.h | 0 .../tests}/headers/mangling-linux32.hpp | 0 .../tests}/headers/mangling-linux64.hpp | 0 .../tests}/headers/mangling-macos.hpp | 0 .../tests}/headers/mangling-win32.hpp | 0 .../tests}/headers/mangling-win64.hpp | 0 .../tests}/headers/merge-extern-blocks.h | 0 .../tests}/headers/method-mangling.hpp | 0 .../tests}/headers/module-allowlisted.hpp | 0 .../tests}/headers/msvc-no-usr.hpp | 0 .../multiple-inherit-empty-correct-layout.hpp | 0 .../tests}/headers/mutable.hpp | 0 .../tests}/headers/namespace.hpp | 0 .../tests}/headers/namespace/nsbegin.h | 0 .../tests}/headers/namespace/nsend.h | 0 .../headers/nested-template-typedef.hpp | 0 .../tests}/headers/nested.hpp | 0 .../tests}/headers/nested_vtable.hpp | 0 .../headers/nested_within_namespace.hpp | 0 .../tests}/headers/newtype-enum.hpp | 0 .../tests}/headers/newtype-global-enum.hpp | 0 .../tests}/headers/no-comments.h | 0 .../tests}/headers/no-derive-debug.h | 0 .../tests}/headers/no-derive-default.h | 0 .../tests}/headers/no-hash-allowlisted.hpp | 0 .../tests}/headers/no-hash-opaque.hpp | 0 .../headers/no-partialeq-allowlisted.hpp | 0 .../tests}/headers/no-partialeq-opaque.hpp | 0 .../headers/no-recursive-allowlisting.h | 0 .../tests}/headers/no-std.h | 0 .../tests}/headers/no_copy.hpp | 0 .../tests}/headers/no_copy_allowlisted.hpp | 0 .../tests}/headers/no_copy_opaque.hpp | 0 .../tests}/headers/no_debug.hpp | 0 .../tests}/headers/no_debug_allowlisted.hpp | 0 .../headers/no_debug_bypass_impl_debug.hpp | 0 .../tests}/headers/no_debug_opaque.hpp | 0 .../tests}/headers/no_default.hpp | 0 .../tests}/headers/no_default_allowlisted.hpp | 0 .../no_default_bypass_derive_default.hpp | 0 .../tests}/headers/no_default_opaque.hpp | 0 .../tests}/headers/no_size_t_is_usize.h | 0 .../tests}/headers/non-type-params.hpp | 0 .../tests}/headers/noreturn.hpp | 0 .../tests}/headers/nsBaseHashtable.hpp | 0 .../tests}/headers/nsStyleAutoArray.hpp | 0 .../tests}/headers/objc_allowlist.h | 0 .../tests}/headers/objc_blocklist.h | 0 .../tests}/headers/objc_category.h | 0 .../tests}/headers/objc_class.h | 0 .../tests}/headers/objc_class_method.h | 0 .../tests}/headers/objc_inheritance.h | 0 .../tests}/headers/objc_interface.h | 0 .../tests}/headers/objc_interface_type.h | 0 .../tests}/headers/objc_method.h | 0 .../tests}/headers/objc_method_clash.h | 0 .../headers/objc_pointer_return_types.h | 0 .../tests}/headers/objc_property_fnptr.h | 0 .../tests}/headers/objc_protocol.h | 0 .../headers/objc_protocol_inheritance.h | 0 .../tests}/headers/objc_sel_and_id.h | 0 .../tests}/headers/objc_template.h | 0 .../tests}/headers/only_bitfields.hpp | 0 .../headers/opaque-template-inst-member-2.hpp | 0 .../headers/opaque-template-inst-member.hpp | 0 ...aque-template-instantiation-namespaced.hpp | 0 .../headers/opaque-template-instantiation.hpp | 0 .../tests}/headers/opaque-tracing.hpp | 0 .../tests}/headers/opaque_in_struct.hpp | 0 .../tests}/headers/opaque_pointer.hpp | 0 .../tests}/headers/opaque_typedef.hpp | 0 .../tests}/headers/operator.hpp | 0 .../tests}/headers/ord-enum.h | 0 .../tests}/headers/overflowed_enum.hpp | 0 .../tests}/headers/overloading.hpp | 0 .../tests}/headers/packed-bitfield.h | 0 .../tests}/headers/packed-n-with-padding.h | 0 .../tests}/headers/packed-vtable.h | 0 .../tests}/headers/parm-union.hpp | 0 .../parsecb-anonymous-enum-variant-rename.h | 0 ...partial-specialization-and-inheritance.hpp | 0 .../tests}/headers/pointer-attr.h | 0 .../headers/prepend-enum-constified-variant.h | 0 .../tests}/headers/prepend_enum_name.hpp | 0 .../tests}/headers/private.hpp | 0 .../tests}/headers/private_fields.hpp | 0 .../tests}/headers/public-dtor.hpp | 0 .../headers/qualified-dependent-types.hpp | 0 .../tests}/headers/redeclaration.hpp | 0 .../tests}/headers/ref_argument_array.hpp | 0 .../tests}/headers/reparented_replacement.hpp | 0 .../tests}/headers/replace_template_alias.hpp | 0 .../tests}/headers/replace_use.hpp | 0 .../tests}/headers/replaces_double.hpp | 0 .../tests}/headers/repr-align.hpp | 0 .../headers/resolved_type_def_function.h | 0 ...me_struct_name_in_different_namespaces.hpp | 0 .../headers/sentry-defined-multiple-times.hpp | 0 .../tests}/headers/short-enums.hpp | 0 .../tests}/headers/size_t_template.hpp | 0 .../tests}/headers/sorted-items.h | 0 .../tests}/headers/stdint_typedef.h | 0 ...truct_containing_forward_declared_struct.h | 0 .../tests}/headers/struct_typedef.h | 0 .../tests}/headers/struct_typedef_ns.hpp | 0 .../tests}/headers/struct_with_anon_struct.h | 0 .../headers/struct_with_anon_struct_array.h | 0 .../headers/struct_with_anon_struct_pointer.h | 0 .../tests}/headers/struct_with_anon_union.h | 0 .../headers/struct_with_anon_union_1_0.h | 0 .../headers/struct_with_anon_unnamed_struct.h | 0 .../headers/struct_with_anon_unnamed_union.h | 0 .../struct_with_anon_unnamed_union_1_0.h | 0 .../tests}/headers/struct_with_bitfields.h | 0 .../tests}/headers/struct_with_derive_debug.h | 0 .../headers/struct_with_large_array.hpp | 0 .../tests}/headers/struct_with_nesting.h | 0 .../tests}/headers/struct_with_nesting_1_0.h | 0 .../tests}/headers/struct_with_packing.h | 0 .../tests}/headers/struct_with_struct.h | 0 .../struct_with_typedef_template_arg.hpp | 0 .../tests}/headers/template-fun-ty.hpp | 0 .../tests}/headers/template-param-usage-0.hpp | 0 .../tests}/headers/template-param-usage-1.hpp | 0 .../headers/template-param-usage-10.hpp | 0 .../headers/template-param-usage-11.hpp | 0 .../headers/template-param-usage-12.hpp | 0 .../headers/template-param-usage-13.hpp | 0 .../headers/template-param-usage-14.hpp | 0 .../headers/template-param-usage-15.hpp | 0 .../tests}/headers/template-param-usage-2.hpp | 0 .../tests}/headers/template-param-usage-3.hpp | 0 .../tests}/headers/template-param-usage-4.hpp | 0 .../tests}/headers/template-param-usage-5.hpp | 0 .../tests}/headers/template-param-usage-6.hpp | 0 .../tests}/headers/template-param-usage-7.hpp | 0 .../tests}/headers/template-param-usage-8.hpp | 0 .../tests}/headers/template-param-usage-9.hpp | 0 .../tests}/headers/template-with-var.hpp | 0 .../tests}/headers/template.hpp | 0 .../tests}/headers/template_alias.hpp | 0 .../tests}/headers/template_alias_basic.hpp | 0 .../headers/template_alias_namespace.hpp | 0 .../tests}/headers/template_fun.hpp | 0 ...plate_instantiation_with_fn_local_type.hpp | 0 .../template_partial_specification.hpp | 0 .../template_typedef_transitive_param.hpp | 0 .../tests}/headers/template_typedefs.hpp | 0 .../tests}/headers/templateref_opaque.hpp | 0 .../tests}/headers/templatized-bitfield.hpp | 0 .../tests}/headers/timex.h | 0 .../tests}/headers/transform-op.hpp | 0 .../type-referenced-by-allowlisted-function.h | 0 .../tests}/headers/type_alias_empty.hpp | 0 ...alias_partial_template_especialization.hpp | 0 .../type_alias_template_specialized.hpp | 0 .../headers/typedefd-array-as-function-arg.h | 0 .../tests}/headers/typeref.hpp | 0 .../tests}/headers/typeref_1_0.hpp | 0 .../tests}/headers/underscore.hpp | 0 .../tests}/headers/union-align.h | 0 .../tests}/headers/union-in-ns.hpp | 0 .../tests}/headers/union-in-ns_1_0.hpp | 0 .../tests}/headers/union_bitfield.h | 0 .../tests}/headers/union_bitfield_1_0.h | 0 .../tests}/headers/union_dtor.hpp | 0 .../tests}/headers/union_dtor_1_0.hpp | 0 .../tests}/headers/union_fields.hpp | 0 .../tests}/headers/union_fields_1_0.hpp | 0 .../tests}/headers/union_template.hpp | 0 .../tests}/headers/union_template_1_0.hpp | 0 .../tests}/headers/union_with_anon_struct.h | 0 .../headers/union_with_anon_struct_1_0.h | 0 .../headers/union_with_anon_struct_bitfield.h | 0 .../union_with_anon_struct_bitfield_1_0.h | 0 .../tests}/headers/union_with_anon_union.h | 0 .../headers/union_with_anon_union_1_0.h | 0 .../headers/union_with_anon_unnamed_struct.h | 0 .../union_with_anon_unnamed_struct_1_0.h | 0 .../headers/union_with_anon_unnamed_union.h | 0 .../union_with_anon_unnamed_union_1_0.h | 0 .../tests}/headers/union_with_big_member.h | 0 .../headers/union_with_big_member_1_0.h | 0 .../tests}/headers/union_with_nesting.h | 0 .../tests}/headers/union_with_nesting_1_0.h | 0 .../headers/union_with_non_copy_member.h | 0 .../tests}/headers/unknown_attr.h | 0 .../tests}/headers/unsorted-items.h | 0 .../tests}/headers/use-core.h | 0 .../tests}/headers/use-core_1_0.h | 0 .../tests}/headers/using.hpp | 0 .../tests}/headers/var-tracing.hpp | 0 .../tests}/headers/variadic-method.hpp | 0 .../headers/variadic_template_function.hpp | 0 .../tests}/headers/vector.hpp | 0 .../tests}/headers/virtual_dtor.hpp | 0 .../tests}/headers/virtual_inheritance.hpp | 0 .../tests}/headers/virtual_interface.hpp | 0 .../tests}/headers/virtual_overloaded.hpp | 0 .../tests}/headers/vtable_recursive_sig.hpp | 0 .../headers/wasm-constructor-returns.hpp | 0 .../tests}/headers/wasm-import-module.h | 0 .../tests}/headers/weird_bitfields.hpp | 0 .../tests}/headers/what_is_going_on.hpp | 0 .../tests}/headers/win32-thiscall_1_0.hpp | 0 .../tests}/headers/win32-thiscall_nightly.hpp | 0 .../tests}/headers/win32-vectorcall-1_0.h | 0 .../tests}/headers/win32-vectorcall-nightly.h | 0 .../headers/with_array_pointers_arguments.h | 0 .../without_array_pointers_arguments.h | 0 .../tests}/headers/zero-size-array-align.h | 0 .../tests}/headers/zero-sized-array.hpp | 0 .../tests}/parse_callbacks/mod.rs | 0 .../tests}/quickchecking/.gitignore | 0 .../tests}/quickchecking/Cargo.toml | 4 +- .../tests}/quickchecking/README.md | 0 .../tests}/quickchecking/src/bin.rs | 6 +- .../tests}/quickchecking/src/fuzzers.rs | 22 +- .../tests}/quickchecking/src/lib.rs | 23 +- .../quickchecking/tests/fuzzed-c-headers.rs | 11 +- {tests => bindgen-tests/tests}/rustfmt.toml | 0 {tests => bindgen-tests/tests}/stylo.hpp | 0 .../tests}/stylo_sanity.rs | 0 {tests => bindgen-tests/tests}/test-one.sh | 0 {tests => bindgen-tests/tests}/tests.rs | 37 +- .../tests}/uses/.gitignore | 0 bindgen/Cargo.toml | 69 ++++ bindgen/build.rs | 29 ++ {src => bindgen}/callbacks.rs | 0 {src => bindgen}/clang.rs | 0 {src => bindgen}/codegen/bitfield_unit.rs | 0 .../codegen/bitfield_unit_tests.rs | 0 {src => bindgen}/codegen/dyngen.rs | 0 {src => bindgen}/codegen/error.rs | 0 {src => bindgen}/codegen/helpers.rs | 0 {src => bindgen}/codegen/impl_debug.rs | 0 {src => bindgen}/codegen/impl_partialeq.rs | 0 {src => bindgen}/codegen/mod.rs | 0 .../postprocessing/merge_extern_blocks.rs | 0 .../codegen/postprocessing/mod.rs | 0 .../postprocessing/sort_semantically.rs | 0 {src => bindgen}/codegen/struct_layout.rs | 0 .../csmith-fuzzing}/README.md | 0 .../csmith-fuzzing}/csmith.h | 0 .../csmith-fuzzing}/driver.py | 0 .../csmith-fuzzing}/predicate.py | 0 {src => bindgen}/deps.rs | 0 {src => bindgen}/extra_assertions.rs | 0 {src => bindgen}/features.rs | 0 {src => bindgen}/ir/analysis/derive.rs | 0 .../ir/analysis/has_destructor.rs | 0 {src => bindgen}/ir/analysis/has_float.rs | 0 .../ir/analysis/has_type_param_in_array.rs | 0 {src => bindgen}/ir/analysis/has_vtable.rs | 0 {src => bindgen}/ir/analysis/mod.rs | 0 {src => bindgen}/ir/analysis/sizedness.rs | 0 .../ir/analysis/template_params.rs | 0 {src => bindgen}/ir/annotations.rs | 0 {src => bindgen}/ir/comment.rs | 0 {src => bindgen}/ir/comp.rs | 0 {src => bindgen}/ir/context.rs | 0 {src => bindgen}/ir/derive.rs | 0 {src => bindgen}/ir/dot.rs | 0 {src => bindgen}/ir/enum_ty.rs | 0 {src => bindgen}/ir/function.rs | 0 {src => bindgen}/ir/int.rs | 0 {src => bindgen}/ir/item.rs | 0 {src => bindgen}/ir/item_kind.rs | 0 {src => bindgen}/ir/layout.rs | 0 {src => bindgen}/ir/mod.rs | 0 {src => bindgen}/ir/module.rs | 0 {src => bindgen}/ir/objc.rs | 0 {src => bindgen}/ir/template.rs | 0 {src => bindgen}/ir/traversal.rs | 0 {src => bindgen}/ir/ty.rs | 0 {src => bindgen}/ir/var.rs | 0 {src => bindgen}/lib.rs | 0 {src => bindgen}/log_stubs.rs | 0 {src => bindgen}/parse.rs | 0 {src => bindgen}/regex_set.rs | 0 {src => bindgen}/time.rs | 0 book/src/command-line-usage.md | 2 +- build.rs | 90 ----- ci/no-includes.sh | 2 +- ci/test.sh | 4 +- 1217 files changed, 682 insertions(+), 306 deletions(-) create mode 100644 bindgen-cli/Cargo.toml rename {src => bindgen-cli}/main.rs (61%) rename {src => bindgen-cli}/options.rs (99%) create mode 100644 bindgen-tests/Cargo.toml create mode 100644 bindgen-tests/build.rs rename {tests/expectations => bindgen-tests}/src/lib.rs (100%) rename {tests => bindgen-tests/tests}/.gitattributes (100%) rename {tests => bindgen-tests/tests}/expectations/Cargo.toml (100%) rename {tests => bindgen-tests/tests}/expectations/build.rs (95%) rename {tests => bindgen-tests/tests}/expectations/lib.rs (100%) rename tests/expectations/struct_with_anon_struct_array_float.rs => bindgen-tests/tests/expectations/src/lib.rs (100%) create mode 100644 bindgen-tests/tests/expectations/struct_with_anon_struct_array_float.rs rename {tests => bindgen-tests/tests}/expectations/tests/.gitattributes (100%) rename {tests => bindgen-tests/tests}/expectations/tests/16-byte-alignment.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/16-byte-alignment_1_0.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/381-decltype-alias.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/accessors.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/allowlist-file.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/allowlist-namespaces-basic.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/allowlist-namespaces.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/allowlist_basic.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/allowlist_fix.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/allowlist_vars.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/allowlist_warnings.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/allowlisted-item-references-no-hash.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/allowlisted-item-references-no-partialeq.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/allowlisted_item_references_no_copy.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/annotation_hide.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/anon-fields-prefix.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/anon_enum.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/anon_enum_allowlist.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/anon_enum_trait.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/anon_struct_in_union.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/anon_struct_in_union_1_0.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/anon_union.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/anon_union_1_0.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/anonymous-template-types.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/arg_keyword.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/array-of-zero-sized-types.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/attribute_warn_unused_result.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/attribute_warn_unused_result_no_attribute_detection.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/attribute_warn_unused_result_pre_1_27.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/bad-namespace-parenthood-inheritance.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/base-to-derived.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/bindgen-union-inside-namespace.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/bitfield-32bit-overflow.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/bitfield-enum-basic.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/bitfield-enum-repr-c.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/bitfield-enum-repr-transparent.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/bitfield-large.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/bitfield-linux-32.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/bitfield-method-same-name.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/bitfield_align.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/bitfield_align_2.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/bitfield_large_overflow.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/bitfield_method_mangling.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/bitfield_pragma_packed.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/block_return_type.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/blocklist-and-impl-debug.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/blocklist-file.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/blocklist-function.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/blocklist-item.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/blocks-signature.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/blocks.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/bug-1529681.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/builtin-template.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/c-empty-layout.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/c_naming.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/call-conv-typedef.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/canonical-types.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/canonical_path_without_namespacing.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/char.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/class.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/class_1_0.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/class_nested.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/class_no_members.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/class_static.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/class_static_const.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/class_use_as.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/class_with_dtor.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/class_with_inner_struct.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/class_with_inner_struct_1_0.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/class_with_typedef.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/comment-indent.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/complex.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/complex_global.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/const-const-mut-ptr.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/const_array.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/const_array_fn_arg.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/const_enum_unnamed.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/const_multidim_array_fn_arg.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/const_ptr.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/const_resolved_ty.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/const_tparam.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/constant-non-specialized-tp.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/constified-enum-module-overflow.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/constify-all-enums.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/constify-enum.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/constify-module-enums-basic.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/constify-module-enums-namespace.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/constify-module-enums-shadow-name.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/constify-module-enums-simple-alias.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/constify-module-enums-simple-nonamespace.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/constify-module-enums-types.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/constructor-tp.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/constructors.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/constructors_1_33.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/contains-vs-inherits-zero-sized.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/convert-cpp-comment-to-rust.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/convert-floats.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/core_ffi_c.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/cpp-empty-layout.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/crtp.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/ctypes-prefix-path.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/dash_language.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/decl_extern_int_twice.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/decl_ptr_to_array.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/default-enum-style-constified-module.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/default-macro-constant-type-signed.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/default-macro-constant-type-unsigned.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/default-macro-constant-type.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/default-template-parameter.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/deleted-function.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/derive-bitfield-method-same-name.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/derive-clone.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/derive-clone_1_0.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/derive-custom.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/derive-debug-bitfield-core.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/derive-debug-bitfield.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/derive-debug-function-pointer.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/derive-debug-generic.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/derive-debug-mangle-name.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/derive-debug-opaque-template-instantiation.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/derive-debug-opaque.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/derive-default-and-blocklist.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/derive-fn-ptr.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/derive-hash-and-blocklist.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/derive-hash-blocklisting.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/derive-hash-struct-with-anon-struct-float.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/derive-hash-struct-with-float-array.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/derive-hash-struct-with-incomplete-array.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/derive-hash-struct-with-pointer.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/derive-hash-template-def-float.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/derive-hash-template-inst-float.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/derive-partialeq-and-blocklist.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/derive-partialeq-anonfield.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/derive-partialeq-base.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/derive-partialeq-bitfield.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/derive-partialeq-core.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/derive-partialeq-pointer.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/derive-partialeq-union.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/derive-partialeq-union_1_0.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/disable-namespacing.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/disable-nested-struct-naming.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/disable-untagged-union.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/divide-by-zero-in-struct-layout.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/do-not-derive-copy.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/doggo-or-null.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/dupe-enum-variant-in-namespace.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/duplicated-namespaces-definitions.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/duplicated-namespaces.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/duplicated_constants_in_ns.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/dynamic_loading_attributes.rs (91%) rename {tests => bindgen-tests/tests}/expectations/tests/dynamic_loading_required.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/dynamic_loading_simple.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/dynamic_loading_template.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/dynamic_loading_with_allowlist.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/dynamic_loading_with_blocklist.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/dynamic_loading_with_class.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/elaborated.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/empty-enum.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/empty-union.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/empty_template_param_name.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/enum-default-bitfield.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/enum-default-consts.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/enum-default-module.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/enum-default-rust.d (100%) rename {tests => bindgen-tests/tests}/expectations/tests/enum-default-rust.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/enum-doc-bitfield.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/enum-doc-mod.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/enum-doc-rusty.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/enum-doc.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/enum-no-debug-rust.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/enum-translate-type.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/enum-undefault.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/enum-variant-replaces.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/enum.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/enum_alias.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/enum_and_vtable_mangling.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/enum_dupe.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/enum_explicit_type.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/enum_explicit_type_constants.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/enum_in_template.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/enum_in_template_with_typedef.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/enum_negative.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/enum_packed.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/eval-value-dependent.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/eval-variadic-template-parameter.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/explicit-padding.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/extern-const-struct.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/extern.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/fit-macro-constant-types-signed.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/fit-macro-constant-types.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/float128.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/forward-declaration-autoptr.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/forward-enum-decl.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/forward-inherit-struct-with-fields.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/forward-inherit-struct.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/forward_declared_complex_types.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/forward_declared_complex_types_1_0.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/forward_declared_opaque.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/forward_declared_struct.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/func_proto.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/func_ptr.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/func_ptr_in_struct.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/func_ptr_return_type.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/func_return_must_use.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/func_with_array_arg.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/func_with_func_ptr_arg.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/function-typedef-stdcall.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/gen-constructors-neg.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/gen-constructors.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/gen-destructors-neg.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/gen-destructors.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/generate-inline.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/i128.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/in_class_typedef.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/incomplete-array-padding.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/infinite-macro.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/inherit-from-template-instantiation-with-vtable.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/inherit-namespaced.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/inherit_named.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/inherit_typedef.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/inline-function.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/inline_namespace.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/inline_namespace_allowlist.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/inline_namespace_conservative.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/inline_namespace_no_ns_enabled.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/inner-typedef-gh422.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/inner_const.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/inner_template_self.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/int128_t.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-1025-unknown-enum-repr.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-1034.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-1040.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-1113-template-references.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-1118-using-forward-decl.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-1197-pure-virtual-stuff.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-1198-alias-rust-bitfield-enum.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-1198-alias-rust-const-mod-bitfield-enum.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-1198-alias-rust-const-mod-enum.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-1198-alias-rust-enum.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-1216-variadic-member.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-1238-fwd-no-copy.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-1281.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-1285.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-1291.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-1350-attribute-overloadable.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-1382-rust-primitive-types.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-1435.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-1443.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-1454.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-1464.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-1488-enum-new-type.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-1488-options.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-1488-template-alias-new-type.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-1498.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-1514.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-1554.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-1599-opaque-typedef-to-enum.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-1676-macro-namespace-prefix.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-1947.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-1977-larger-arrays.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-1995.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-2019.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-2239-template-dependent-bit-width.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-358.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-372.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-410.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-446.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-447.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-493.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-493_1_0.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-511.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-537-repr-packed-n.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-537.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-544-stylo-creduce-2.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-544-stylo-creduce.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-573-layout-test-failures.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-574-assertion-failure-in-codegen.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-584-stylo-template-analysis-panic.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-638-stylo-cannot-find-T-in-this-scope.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-639-typedef-anon-field.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-643-inner-struct.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-645-cannot-find-type-T-in-this-scope.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-648-derive-debug-with-padding.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-654-struct-fn-collision.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-662-cannot-find-T-in-this-scope.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-662-part-2.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-674-1.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-674-2.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-674-3.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-677-nested-ns-specifier.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-691-template-parameter-virtual.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-710-must-use-type.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-739-pointer-wide-bitfield.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-801-opaque-sloppiness.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-807-opaque-types-methods-being-generated.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-816.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-820-unused-template-param-in-alias.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-826-generating-methods-when-asked-not-to.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-833-1.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-833-2.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-833.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-834.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-848-replacement-system-include.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-888-enum-var-decl-jump.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-944-derive-copy-and-blocklisting.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue-946.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue_311.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/issue_315.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/jsval_layout_opaque.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/jsval_layout_opaque_1_0.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/keywords.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/layout.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/layout_align.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/layout_arp.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/layout_array.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/layout_array_too_long.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/layout_cmdline_token.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/layout_eth_conf.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/layout_eth_conf_1_0.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/layout_kni_mbuf.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/layout_large_align_field.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/layout_mbuf.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/layout_mbuf_1_0.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/libclang-5/abi_variadic_function.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/libclang-5/auto.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/libclang-5/call-conv-field.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/libclang-5/const_bool.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/libclang-5/constant-evaluate.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/libclang-5/error-E0600-cannot-apply-unary-negation-to-u32.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/libclang-5/issue-769-bad-instantiation-test.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/libclang-5/mangling-win32.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/libclang-5/objc_inheritance.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/libclang-5/objc_template.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/libclang-5/partial-specialization-and-inheritance.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/libclang-5/type_alias_template_specialized.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/libclang-9/abi_variadic_function.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/libclang-9/auto.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/libclang-9/call-conv-field.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/libclang-9/class.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/libclang-9/class_1_0.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/libclang-9/const_bool.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/libclang-9/constant-evaluate.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/libclang-9/error-E0600-cannot-apply-unary-negation-to-u32.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/libclang-9/incomplete-array-padding.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/libclang-9/issue-643-inner-struct.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/libclang-9/issue-769-bad-instantiation-test.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/libclang-9/layout_align.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/libclang-9/mangling-win32.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/libclang-9/objc_inheritance.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/libclang-9/objc_template.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/libclang-9/partial-specialization-and-inheritance.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/libclang-9/type_alias_template_specialized.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/libclang-9/zero-sized-array.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/libclang_version_specific_generated_tests.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/long_double.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/macro-expr-basic.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/macro-expr-uncommon-token.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/macro-redef.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/macro_const.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/macro_const_1_0.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/maddness-is-avoidable.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/mangling-ios.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/mangling-linux32.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/mangling-linux64.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/mangling-macos.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/mangling-win64.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/merge-extern-blocks.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/method-mangling.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/module-allowlisted.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/msvc-no-usr.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/multiple-inherit-empty-correct-layout.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/mutable.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/namespace.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/nested-template-typedef.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/nested.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/nested_vtable.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/nested_within_namespace.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/newtype-enum.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/newtype-global-enum.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/no-comments.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/no-derive-debug.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/no-derive-default.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/no-hash-allowlisted.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/no-hash-opaque.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/no-partialeq-allowlisted.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/no-partialeq-opaque.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/no-recursive-allowlisting.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/no-std.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/no_copy.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/no_copy_allowlisted.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/no_copy_opaque.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/no_debug.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/no_debug_allowlisted.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/no_debug_bypass_impl_debug.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/no_debug_opaque.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/no_default.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/no_default_allowlisted.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/no_default_bypass_derive_default.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/no_default_opaque.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/no_size_t_is_usize.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/non-type-params.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/noreturn.rs (85%) rename {tests => bindgen-tests/tests}/expectations/tests/nsBaseHashtable.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/nsStyleAutoArray.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/objc_allowlist.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/objc_blocklist.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/objc_category.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/objc_class.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/objc_class_method.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/objc_interface.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/objc_interface_type.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/objc_method.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/objc_method_clash.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/objc_pointer_return_types.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/objc_property_fnptr.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/objc_protocol.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/objc_protocol_inheritance.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/objc_sel_and_id.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/only_bitfields.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/opaque-template-inst-member-2.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/opaque-template-inst-member.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/opaque-template-instantiation-namespaced.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/opaque-template-instantiation.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/opaque-tracing.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/opaque_in_struct.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/opaque_pointer.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/opaque_typedef.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/operator.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/ord-enum.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/overflowed_enum.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/overloading.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/packed-bitfield.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/packed-n-with-padding.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/packed-vtable.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/parm-union.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/parsecb-anonymous-enum-variant-rename.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/pointer-attr.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/prepend-enum-constified-variant.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/prepend_enum_name.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/private.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/private_fields.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/public-dtor.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/qualified-dependent-types.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/redeclaration.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/ref_argument_array.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/reparented_replacement.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/replace_template_alias.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/replace_use.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/replaces_double.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/repr-align.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/resolved_type_def_function.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/same_struct_name_in_different_namespaces.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/sentry-defined-multiple-times.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/short-enums.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/size_t_template.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/sorted-items.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/stdint_typedef.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/struct_containing_forward_declared_struct.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/struct_typedef.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/struct_typedef_ns.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/struct_with_anon_struct.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/struct_with_anon_struct_array.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/struct_with_anon_struct_pointer.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/struct_with_anon_union.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/struct_with_anon_union_1_0.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/struct_with_anon_unnamed_struct.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/struct_with_anon_unnamed_union.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/struct_with_anon_unnamed_union_1_0.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/struct_with_bitfields.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/struct_with_derive_debug.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/struct_with_large_array.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/struct_with_nesting.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/struct_with_nesting_1_0.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/struct_with_packing.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/struct_with_struct.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/struct_with_typedef_template_arg.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/template-fun-ty.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/template-param-usage-0.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/template-param-usage-1.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/template-param-usage-10.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/template-param-usage-11.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/template-param-usage-12.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/template-param-usage-13.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/template-param-usage-14.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/template-param-usage-15.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/template-param-usage-2.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/template-param-usage-3.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/template-param-usage-4.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/template-param-usage-5.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/template-param-usage-6.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/template-param-usage-7.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/template-param-usage-8.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/template-param-usage-9.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/template-with-var.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/template.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/template_alias.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/template_alias_basic.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/template_alias_namespace.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/template_fun.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/template_instantiation_with_fn_local_type.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/template_partial_specification.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/template_typedef_transitive_param.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/template_typedefs.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/templateref_opaque.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/templatized-bitfield.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/test_mixed_header_and_header_contents.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/test_multiple_header_calls_in_builder.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/timex.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/transform-op.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/type-referenced-by-allowlisted-function.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/type_alias_empty.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/type_alias_partial_template_especialization.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/typedefd-array-as-function-arg.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/typeref.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/typeref_1_0.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/underscore.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/union-align.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/union-in-ns.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/union-in-ns_1_0.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/union_bitfield.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/union_bitfield_1_0.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/union_dtor.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/union_dtor_1_0.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/union_fields.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/union_fields_1_0.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/union_template.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/union_template_1_0.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/union_with_anon_struct.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/union_with_anon_struct_1_0.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/union_with_anon_struct_bitfield.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/union_with_anon_struct_bitfield_1_0.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/union_with_anon_union.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/union_with_anon_union_1_0.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/union_with_anon_unnamed_struct.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/union_with_anon_unnamed_struct_1_0.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/union_with_anon_unnamed_union.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/union_with_anon_unnamed_union_1_0.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/union_with_big_member.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/union_with_big_member_1_0.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/union_with_nesting.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/union_with_nesting_1_0.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/union_with_non_copy_member.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/unknown_attr.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/unsorted-items.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/use-core.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/use-core_1_0.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/using.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/var-tracing.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/variadic-method.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/variadic_template_function.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/vector.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/virtual_dtor.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/virtual_inheritance.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/virtual_interface.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/virtual_overloaded.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/vtable_recursive_sig.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/wasm-constructor-returns.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/wasm-import-module.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/weird_bitfields.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/what_is_going_on.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/win32-thiscall_1_0.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/win32-thiscall_nightly.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/win32-vectorcall-1_0.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/win32-vectorcall-nightly.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/with_array_pointers_arguments.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/without_array_pointers_arguments.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/zero-size-array-align.rs (100%) rename {tests => bindgen-tests/tests}/expectations/tests/zero-sized-array.rs (100%) rename {tests => bindgen-tests/tests}/headers/16-byte-alignment.h (100%) rename {tests => bindgen-tests/tests}/headers/16-byte-alignment_1_0.h (100%) rename {tests => bindgen-tests/tests}/headers/381-decltype-alias.hpp (100%) rename {tests => bindgen-tests/tests}/headers/abi_variadic_function.hpp (100%) rename {tests => bindgen-tests/tests}/headers/accessors.hpp (100%) rename {tests => bindgen-tests/tests}/headers/allowlist-file.hpp (100%) rename {tests => bindgen-tests/tests}/headers/allowlist-namespaces-basic.hpp (100%) rename {tests => bindgen-tests/tests}/headers/allowlist-namespaces.hpp (100%) rename {tests => bindgen-tests/tests}/headers/allowlist_basic.hpp (100%) rename {tests => bindgen-tests/tests}/headers/allowlist_fix.hpp (100%) rename {tests => bindgen-tests/tests}/headers/allowlist_vars.h (100%) rename {tests => bindgen-tests/tests}/headers/allowlist_warnings.h (100%) rename {tests => bindgen-tests/tests}/headers/allowlisted-item-references-no-hash.hpp (100%) rename {tests => bindgen-tests/tests}/headers/allowlisted-item-references-no-partialeq.hpp (100%) rename {tests => bindgen-tests/tests}/headers/allowlisted/file.hpp (100%) rename {tests => bindgen-tests/tests}/headers/allowlisted_item_references_no_copy.hpp (100%) rename {tests => bindgen-tests/tests}/headers/annotation_hide.hpp (100%) rename {tests => bindgen-tests/tests}/headers/anon-fields-prefix.h (100%) rename {tests => bindgen-tests/tests}/headers/anon_enum.hpp (100%) rename {tests => bindgen-tests/tests}/headers/anon_enum_allowlist.h (100%) rename {tests => bindgen-tests/tests}/headers/anon_enum_trait.hpp (100%) rename {tests => bindgen-tests/tests}/headers/anon_struct_in_union.h (100%) rename {tests => bindgen-tests/tests}/headers/anon_struct_in_union_1_0.h (100%) rename {tests => bindgen-tests/tests}/headers/anon_union.hpp (100%) rename {tests => bindgen-tests/tests}/headers/anon_union_1_0.hpp (100%) rename {tests => bindgen-tests/tests}/headers/anonymous-template-types.hpp (100%) rename {tests => bindgen-tests/tests}/headers/arg_keyword.hpp (100%) rename {tests => bindgen-tests/tests}/headers/array-of-zero-sized-types.hpp (100%) rename {tests => bindgen-tests/tests}/headers/attribute_warn_unused_result.hpp (100%) rename {tests => bindgen-tests/tests}/headers/attribute_warn_unused_result_no_attribute_detection.hpp (100%) rename {tests => bindgen-tests/tests}/headers/attribute_warn_unused_result_pre_1_27.hpp (100%) rename {tests => bindgen-tests/tests}/headers/auto.hpp (100%) rename {tests => bindgen-tests/tests}/headers/bad-namespace-parenthood-inheritance.hpp (100%) rename {tests => bindgen-tests/tests}/headers/base-to-derived.hpp (100%) rename {tests => bindgen-tests/tests}/headers/bindgen-union-inside-namespace.hpp (100%) rename {tests => bindgen-tests/tests}/headers/bitfield-32bit-overflow.h (100%) rename {tests => bindgen-tests/tests}/headers/bitfield-enum-basic.hpp (100%) rename {tests => bindgen-tests/tests}/headers/bitfield-enum-repr-c.hpp (100%) rename {tests => bindgen-tests/tests}/headers/bitfield-enum-repr-transparent.hpp (100%) rename {tests => bindgen-tests/tests}/headers/bitfield-large.hpp (100%) rename {tests => bindgen-tests/tests}/headers/bitfield-linux-32.hpp (100%) rename {tests => bindgen-tests/tests}/headers/bitfield-method-same-name.hpp (100%) rename {tests => bindgen-tests/tests}/headers/bitfield_align.h (100%) rename {tests => bindgen-tests/tests}/headers/bitfield_align_2.h (100%) rename {tests => bindgen-tests/tests}/headers/bitfield_large_overflow.hpp (100%) rename {tests => bindgen-tests/tests}/headers/bitfield_method_mangling.h (100%) rename {tests => bindgen-tests/tests}/headers/bitfield_pragma_packed.h (100%) rename {tests => bindgen-tests/tests}/headers/block_return_type.h (100%) rename {tests => bindgen-tests/tests}/headers/blocklist-and-impl-debug.hpp (100%) rename {tests => bindgen-tests/tests}/headers/blocklist-file.hpp (100%) rename {tests => bindgen-tests/tests}/headers/blocklist-function.hpp (100%) rename {tests => bindgen-tests/tests}/headers/blocklist-item.hpp (100%) rename {tests => bindgen-tests/tests}/headers/blocklisted/fake-stdint.h (100%) rename {tests => bindgen-tests/tests}/headers/blocklisted/file.hpp (100%) rename {tests => bindgen-tests/tests}/headers/blocks-signature.hpp (100%) rename {tests => bindgen-tests/tests}/headers/blocks.hpp (100%) rename {tests => bindgen-tests/tests}/headers/bug-1529681.hpp (100%) rename {tests => bindgen-tests/tests}/headers/builtin-template.hpp (100%) rename {tests => bindgen-tests/tests}/headers/c-empty-layout.h (100%) rename {tests => bindgen-tests/tests}/headers/c_naming.h (100%) rename {tests => bindgen-tests/tests}/headers/call-conv-field.h (100%) rename {tests => bindgen-tests/tests}/headers/call-conv-typedef.h (100%) rename {tests => bindgen-tests/tests}/headers/canonical-types.hpp (100%) rename {tests => bindgen-tests/tests}/headers/canonical_path_without_namespacing.hpp (100%) rename {tests => bindgen-tests/tests}/headers/char.h (100%) rename {tests => bindgen-tests/tests}/headers/class.hpp (100%) rename {tests => bindgen-tests/tests}/headers/class_1_0.hpp (100%) rename {tests => bindgen-tests/tests}/headers/class_nested.hpp (100%) rename {tests => bindgen-tests/tests}/headers/class_no_members.hpp (100%) rename {tests => bindgen-tests/tests}/headers/class_static.hpp (100%) rename {tests => bindgen-tests/tests}/headers/class_static_const.hpp (100%) rename {tests => bindgen-tests/tests}/headers/class_use_as.hpp (100%) rename {tests => bindgen-tests/tests}/headers/class_with_dtor.hpp (100%) rename {tests => bindgen-tests/tests}/headers/class_with_inner_struct.hpp (100%) rename {tests => bindgen-tests/tests}/headers/class_with_inner_struct_1_0.hpp (100%) rename {tests => bindgen-tests/tests}/headers/class_with_typedef.hpp (100%) rename {tests => bindgen-tests/tests}/headers/comment-indent.hpp (100%) rename {tests => bindgen-tests/tests}/headers/complex.h (100%) rename {tests => bindgen-tests/tests}/headers/complex_global.h (100%) rename {tests => bindgen-tests/tests}/headers/const-const-mut-ptr.h (100%) rename {tests => bindgen-tests/tests}/headers/const_array.h (100%) rename {tests => bindgen-tests/tests}/headers/const_array_fn_arg.h (100%) rename {tests => bindgen-tests/tests}/headers/const_bool.hpp (100%) rename {tests => bindgen-tests/tests}/headers/const_enum_unnamed.hpp (100%) rename {tests => bindgen-tests/tests}/headers/const_multidim_array_fn_arg.h (100%) rename {tests => bindgen-tests/tests}/headers/const_ptr.hpp (100%) rename {tests => bindgen-tests/tests}/headers/const_resolved_ty.h (100%) rename {tests => bindgen-tests/tests}/headers/const_tparam.hpp (100%) rename {tests => bindgen-tests/tests}/headers/constant-evaluate.h (100%) rename {tests => bindgen-tests/tests}/headers/constant-non-specialized-tp.hpp (100%) rename {tests => bindgen-tests/tests}/headers/constified-enum-module-overflow.hpp (100%) rename {tests => bindgen-tests/tests}/headers/constify-all-enums.h (100%) rename {tests => bindgen-tests/tests}/headers/constify-enum.h (100%) rename {tests => bindgen-tests/tests}/headers/constify-module-enums-basic.h (100%) rename {tests => bindgen-tests/tests}/headers/constify-module-enums-namespace.hpp (100%) rename {tests => bindgen-tests/tests}/headers/constify-module-enums-shadow-name.h (100%) rename {tests => bindgen-tests/tests}/headers/constify-module-enums-simple-alias.hpp (100%) rename {tests => bindgen-tests/tests}/headers/constify-module-enums-simple-nonamespace.hpp (100%) rename {tests => bindgen-tests/tests}/headers/constify-module-enums-types.hpp (100%) rename {tests => bindgen-tests/tests}/headers/constructor-tp.hpp (100%) rename {tests => bindgen-tests/tests}/headers/constructors.hpp (100%) rename {tests => bindgen-tests/tests}/headers/constructors_1_33.hpp (100%) rename {tests => bindgen-tests/tests}/headers/contains-vs-inherits-zero-sized.hpp (100%) rename {tests => bindgen-tests/tests}/headers/convert-cpp-comment-to-rust.hpp (100%) rename {tests => bindgen-tests/tests}/headers/convert-floats.h (100%) rename {tests => bindgen-tests/tests}/headers/core_ffi_c.h (100%) rename {tests => bindgen-tests/tests}/headers/cpp-empty-layout.hpp (100%) rename {tests => bindgen-tests/tests}/headers/crtp.hpp (100%) rename {tests => bindgen-tests/tests}/headers/ctypes-prefix-path.h (100%) rename {tests => bindgen-tests/tests}/headers/dash_language.h (100%) rename {tests => bindgen-tests/tests}/headers/decl_extern_int_twice.h (100%) rename {tests => bindgen-tests/tests}/headers/decl_ptr_to_array.h (100%) rename {tests => bindgen-tests/tests}/headers/default-enum-style-constified-module.h (100%) rename {tests => bindgen-tests/tests}/headers/default-macro-constant-type-signed.h (100%) rename {tests => bindgen-tests/tests}/headers/default-macro-constant-type-unsigned.h (100%) rename {tests => bindgen-tests/tests}/headers/default-macro-constant-type.h (100%) rename {tests => bindgen-tests/tests}/headers/default-template-parameter.hpp (100%) rename {tests => bindgen-tests/tests}/headers/deleted-function.hpp (100%) rename {tests => bindgen-tests/tests}/headers/derive-bitfield-method-same-name.hpp (100%) rename {tests => bindgen-tests/tests}/headers/derive-clone.h (100%) rename {tests => bindgen-tests/tests}/headers/derive-clone_1_0.h (100%) rename {tests => bindgen-tests/tests}/headers/derive-custom.h (100%) rename {tests => bindgen-tests/tests}/headers/derive-debug-bitfield-core.hpp (100%) rename {tests => bindgen-tests/tests}/headers/derive-debug-bitfield.hpp (100%) rename {tests => bindgen-tests/tests}/headers/derive-debug-function-pointer.hpp (100%) rename {tests => bindgen-tests/tests}/headers/derive-debug-generic.hpp (100%) rename {tests => bindgen-tests/tests}/headers/derive-debug-mangle-name.h (100%) rename {tests => bindgen-tests/tests}/headers/derive-debug-opaque-template-instantiation.hpp (100%) rename {tests => bindgen-tests/tests}/headers/derive-debug-opaque.hpp (100%) rename {tests => bindgen-tests/tests}/headers/derive-default-and-blocklist.hpp (100%) rename {tests => bindgen-tests/tests}/headers/derive-fn-ptr.h (100%) rename {tests => bindgen-tests/tests}/headers/derive-hash-and-blocklist.hpp (100%) rename {tests => bindgen-tests/tests}/headers/derive-hash-blocklisting.hpp (100%) rename {tests => bindgen-tests/tests}/headers/derive-hash-struct-with-anon-struct-float.h (100%) rename {tests => bindgen-tests/tests}/headers/derive-hash-struct-with-float-array.h (100%) rename {tests => bindgen-tests/tests}/headers/derive-hash-struct-with-incomplete-array.h (100%) rename {tests => bindgen-tests/tests}/headers/derive-hash-struct-with-pointer.h (100%) rename {tests => bindgen-tests/tests}/headers/derive-hash-template-def-float.hpp (100%) rename {tests => bindgen-tests/tests}/headers/derive-hash-template-inst-float.hpp (100%) rename {tests => bindgen-tests/tests}/headers/derive-partialeq-and-blocklist.hpp (100%) rename {tests => bindgen-tests/tests}/headers/derive-partialeq-anonfield.h (100%) rename {tests => bindgen-tests/tests}/headers/derive-partialeq-base.hpp (100%) rename {tests => bindgen-tests/tests}/headers/derive-partialeq-bitfield.hpp (100%) rename {tests => bindgen-tests/tests}/headers/derive-partialeq-core.h (100%) rename {tests => bindgen-tests/tests}/headers/derive-partialeq-pointer.hpp (100%) rename {tests => bindgen-tests/tests}/headers/derive-partialeq-union.hpp (100%) rename {tests => bindgen-tests/tests}/headers/derive-partialeq-union_1_0.hpp (100%) rename {tests => bindgen-tests/tests}/headers/disable-namespacing.hpp (100%) rename {tests => bindgen-tests/tests}/headers/disable-nested-struct-naming.h (100%) rename {tests => bindgen-tests/tests}/headers/disable-untagged-union.hpp (100%) rename {tests => bindgen-tests/tests}/headers/divide-by-zero-in-struct-layout.h (100%) rename {tests => bindgen-tests/tests}/headers/do-not-derive-copy.hpp (100%) rename {tests => bindgen-tests/tests}/headers/doggo-or-null.hpp (100%) rename {tests => bindgen-tests/tests}/headers/dupe-enum-variant-in-namespace.h (100%) rename {tests => bindgen-tests/tests}/headers/duplicated-namespaces-definitions.hpp (100%) rename {tests => bindgen-tests/tests}/headers/duplicated-namespaces.hpp (100%) rename {tests => bindgen-tests/tests}/headers/duplicated_constants_in_ns.hpp (100%) rename {tests => bindgen-tests/tests}/headers/dynamic_loading_attributes.h (100%) rename {tests => bindgen-tests/tests}/headers/dynamic_loading_required.h (100%) rename {tests => bindgen-tests/tests}/headers/dynamic_loading_simple.h (100%) rename {tests => bindgen-tests/tests}/headers/dynamic_loading_template.hpp (100%) rename {tests => bindgen-tests/tests}/headers/dynamic_loading_with_allowlist.hpp (100%) rename {tests => bindgen-tests/tests}/headers/dynamic_loading_with_blocklist.hpp (100%) rename {tests => bindgen-tests/tests}/headers/dynamic_loading_with_class.hpp (100%) rename {tests => bindgen-tests/tests}/headers/elaborated.hpp (100%) rename {tests => bindgen-tests/tests}/headers/empty-enum.h (100%) rename {tests => bindgen-tests/tests}/headers/empty-union.hpp (100%) rename {tests => bindgen-tests/tests}/headers/empty_template_param_name.hpp (100%) rename {tests => bindgen-tests/tests}/headers/enum-default-bitfield.h (100%) rename {tests => bindgen-tests/tests}/headers/enum-default-consts.h (100%) rename {tests => bindgen-tests/tests}/headers/enum-default-module.h (100%) rename {tests => bindgen-tests/tests}/headers/enum-default-rust.h (100%) rename {tests => bindgen-tests/tests}/headers/enum-doc-bitfield.h (100%) rename {tests => bindgen-tests/tests}/headers/enum-doc-mod.h (100%) rename {tests => bindgen-tests/tests}/headers/enum-doc-rusty.h (100%) rename {tests => bindgen-tests/tests}/headers/enum-doc.h (100%) rename {tests => bindgen-tests/tests}/headers/enum-no-debug-rust.h (100%) rename {tests => bindgen-tests/tests}/headers/enum-translate-type.hpp (100%) rename {tests => bindgen-tests/tests}/headers/enum-undefault.h (100%) rename {tests => bindgen-tests/tests}/headers/enum-variant-replaces.h (100%) rename {tests => bindgen-tests/tests}/headers/enum.h (100%) rename {tests => bindgen-tests/tests}/headers/enum_alias.hpp (100%) rename {tests => bindgen-tests/tests}/headers/enum_and_vtable_mangling.hpp (100%) rename {tests => bindgen-tests/tests}/headers/enum_dupe.h (100%) rename {tests => bindgen-tests/tests}/headers/enum_explicit_type.hpp (100%) rename {tests => bindgen-tests/tests}/headers/enum_explicit_type_constants.hpp (100%) rename {tests => bindgen-tests/tests}/headers/enum_in_template.hpp (100%) rename {tests => bindgen-tests/tests}/headers/enum_in_template_with_typedef.hpp (100%) rename {tests => bindgen-tests/tests}/headers/enum_negative.h (100%) rename {tests => bindgen-tests/tests}/headers/enum_packed.h (100%) rename {tests => bindgen-tests/tests}/headers/error-E0600-cannot-apply-unary-negation-to-u32.h (100%) rename {tests => bindgen-tests/tests}/headers/eval-value-dependent.hpp (100%) rename {tests => bindgen-tests/tests}/headers/eval-variadic-template-parameter.hpp (100%) rename {tests => bindgen-tests/tests}/headers/explicit-padding.h (100%) rename {tests => bindgen-tests/tests}/headers/extern-const-struct.h (100%) rename {tests => bindgen-tests/tests}/headers/extern.hpp (100%) rename {tests => bindgen-tests/tests}/headers/fit-macro-constant-types-signed.h (100%) rename {tests => bindgen-tests/tests}/headers/fit-macro-constant-types.h (100%) rename {tests => bindgen-tests/tests}/headers/float128.hpp (100%) rename {tests => bindgen-tests/tests}/headers/forward-declaration-autoptr.hpp (100%) rename {tests => bindgen-tests/tests}/headers/forward-enum-decl.hpp (100%) rename {tests => bindgen-tests/tests}/headers/forward-inherit-struct-with-fields.hpp (100%) rename {tests => bindgen-tests/tests}/headers/forward-inherit-struct.hpp (100%) rename {tests => bindgen-tests/tests}/headers/forward_declared_complex_types.hpp (100%) rename {tests => bindgen-tests/tests}/headers/forward_declared_complex_types_1_0.hpp (100%) rename {tests => bindgen-tests/tests}/headers/forward_declared_opaque.h (100%) rename {tests => bindgen-tests/tests}/headers/forward_declared_struct.h (100%) rename {tests => bindgen-tests/tests}/headers/func_proto.h (100%) rename {tests => bindgen-tests/tests}/headers/func_ptr.h (100%) rename {tests => bindgen-tests/tests}/headers/func_ptr_in_struct.h (100%) rename {tests => bindgen-tests/tests}/headers/func_ptr_return_type.h (100%) rename {tests => bindgen-tests/tests}/headers/func_return_must_use.h (100%) rename {tests => bindgen-tests/tests}/headers/func_with_array_arg.h (100%) rename {tests => bindgen-tests/tests}/headers/func_with_func_ptr_arg.h (100%) rename {tests => bindgen-tests/tests}/headers/function-typedef-stdcall.h (100%) rename {tests => bindgen-tests/tests}/headers/gen-constructors-neg.hpp (100%) rename {tests => bindgen-tests/tests}/headers/gen-constructors.hpp (100%) rename {tests => bindgen-tests/tests}/headers/gen-destructors-neg.hpp (100%) rename {tests => bindgen-tests/tests}/headers/gen-destructors.hpp (100%) rename {tests => bindgen-tests/tests}/headers/generate-inline.hpp (100%) rename {tests => bindgen-tests/tests}/headers/i128.h (100%) rename {tests => bindgen-tests/tests}/headers/in_class_typedef.hpp (100%) rename {tests => bindgen-tests/tests}/headers/incomplete-array-padding.h (100%) rename {tests => bindgen-tests/tests}/headers/infinite-macro.h (100%) rename {tests => bindgen-tests/tests}/headers/inherit-from-template-instantiation-with-vtable.hpp (100%) rename {tests => bindgen-tests/tests}/headers/inherit-namespaced.hpp (100%) rename {tests => bindgen-tests/tests}/headers/inherit_named.hpp (100%) rename {tests => bindgen-tests/tests}/headers/inherit_typedef.hpp (100%) rename {tests => bindgen-tests/tests}/headers/inline-function.h (100%) rename {tests => bindgen-tests/tests}/headers/inline_namespace.hpp (100%) rename {tests => bindgen-tests/tests}/headers/inline_namespace_allowlist.hpp (100%) rename {tests => bindgen-tests/tests}/headers/inline_namespace_conservative.hpp (100%) rename {tests => bindgen-tests/tests}/headers/inline_namespace_no_ns_enabled.hpp (100%) rename {tests => bindgen-tests/tests}/headers/inner-typedef-gh422.hpp (100%) rename {tests => bindgen-tests/tests}/headers/inner_const.hpp (100%) rename {tests => bindgen-tests/tests}/headers/inner_template_self.hpp (100%) rename {tests => bindgen-tests/tests}/headers/int128_t.h (100%) rename {tests => bindgen-tests/tests}/headers/issue-1025-unknown-enum-repr.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-1034.h (100%) rename {tests => bindgen-tests/tests}/headers/issue-1040.h (100%) rename {tests => bindgen-tests/tests}/headers/issue-1076-unnamed-bitfield-alignment.h (100%) rename {tests => bindgen-tests/tests}/headers/issue-1113-template-references.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-1118-using-forward-decl.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-1197-pure-virtual-stuff.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-1198-alias-rust-bitfield-enum.h (100%) rename {tests => bindgen-tests/tests}/headers/issue-1198-alias-rust-const-mod-bitfield-enum.h (100%) rename {tests => bindgen-tests/tests}/headers/issue-1198-alias-rust-const-mod-enum.h (100%) rename {tests => bindgen-tests/tests}/headers/issue-1198-alias-rust-enum.h (100%) rename {tests => bindgen-tests/tests}/headers/issue-1216-variadic-member.h (100%) rename {tests => bindgen-tests/tests}/headers/issue-1238-fwd-no-copy.h (100%) rename {tests => bindgen-tests/tests}/headers/issue-1281.h (100%) rename {tests => bindgen-tests/tests}/headers/issue-1285.h (100%) rename {tests => bindgen-tests/tests}/headers/issue-1291.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-1350-attribute-overloadable.h (100%) rename {tests => bindgen-tests/tests}/headers/issue-1382-rust-primitive-types.h (100%) rename {tests => bindgen-tests/tests}/headers/issue-1435.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-1443.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-1454.h (100%) rename {tests => bindgen-tests/tests}/headers/issue-1464.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-1488-enum-new-type.h (100%) rename {tests => bindgen-tests/tests}/headers/issue-1488-options.h (100%) rename {tests => bindgen-tests/tests}/headers/issue-1488-template-alias-new-type.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-1498.h (100%) rename {tests => bindgen-tests/tests}/headers/issue-1514.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-1554.h (100%) rename {tests => bindgen-tests/tests}/headers/issue-1599-opaque-typedef-to-enum.h (100%) rename {tests => bindgen-tests/tests}/headers/issue-1676-macro-namespace-prefix.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-1947.h (100%) rename {tests => bindgen-tests/tests}/headers/issue-1977-larger-arrays.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-1995.h (100%) rename {tests => bindgen-tests/tests}/headers/issue-2019.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-2239-template-dependent-bit-width.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-358.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-372.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-410.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-446.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-447.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-493.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-493_1_0.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-511.h (100%) rename {tests => bindgen-tests/tests}/headers/issue-537-repr-packed-n.h (100%) rename {tests => bindgen-tests/tests}/headers/issue-537.h (100%) rename {tests => bindgen-tests/tests}/headers/issue-544-stylo-creduce-2.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-544-stylo-creduce.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-569-non-type-template-params-causing-layout-test-failures.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-573-layout-test-failures.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-574-assertion-failure-in-codegen.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-584-stylo-template-analysis-panic.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-638-stylo-cannot-find-T-in-this-scope.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-639-typedef-anon-field.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-643-inner-struct.h (100%) rename {tests => bindgen-tests/tests}/headers/issue-645-cannot-find-type-T-in-this-scope.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-648-derive-debug-with-padding.h (100%) rename {tests => bindgen-tests/tests}/headers/issue-654-struct-fn-collision.h (100%) rename {tests => bindgen-tests/tests}/headers/issue-662-cannot-find-T-in-this-scope.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-662-part-2.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-674-1.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-674-2.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-674-3.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-677-nested-ns-specifier.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-691-template-parameter-virtual.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-710-must-use-type.h (100%) rename {tests => bindgen-tests/tests}/headers/issue-739-pointer-wide-bitfield.h (100%) rename {tests => bindgen-tests/tests}/headers/issue-769-bad-instantiation-test.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-801-opaque-sloppiness.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-807-opaque-types-methods-being-generated.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-816.h (100%) rename {tests => bindgen-tests/tests}/headers/issue-820-unused-template-param-in-alias.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-826-generating-methods-when-asked-not-to.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-833-1.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-833-2.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-833.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-834.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-848-replacement-system-include.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-848/an-include.h (100%) rename {tests => bindgen-tests/tests}/headers/issue-888-enum-var-decl-jump.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-944-derive-copy-and-blocklisting.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue-946.h (100%) rename {tests => bindgen-tests/tests}/headers/issue_311.hpp (100%) rename {tests => bindgen-tests/tests}/headers/issue_315.hpp (100%) rename {tests => bindgen-tests/tests}/headers/jsval_layout_opaque.hpp (100%) rename {tests => bindgen-tests/tests}/headers/jsval_layout_opaque_1_0.hpp (100%) rename {tests => bindgen-tests/tests}/headers/keywords.h (100%) rename {tests => bindgen-tests/tests}/headers/layout.h (100%) rename {tests => bindgen-tests/tests}/headers/layout_align.h (100%) rename {tests => bindgen-tests/tests}/headers/layout_arp.h (100%) rename {tests => bindgen-tests/tests}/headers/layout_array.h (100%) rename {tests => bindgen-tests/tests}/headers/layout_array_too_long.h (100%) rename {tests => bindgen-tests/tests}/headers/layout_cmdline_token.h (100%) rename {tests => bindgen-tests/tests}/headers/layout_eth_conf.h (100%) rename {tests => bindgen-tests/tests}/headers/layout_eth_conf_1_0.h (100%) rename {tests => bindgen-tests/tests}/headers/layout_kni_mbuf.h (100%) rename {tests => bindgen-tests/tests}/headers/layout_large_align_field.h (100%) rename {tests => bindgen-tests/tests}/headers/layout_mbuf.h (100%) rename {tests => bindgen-tests/tests}/headers/layout_mbuf_1_0.h (100%) rename {tests => bindgen-tests/tests}/headers/long_double.h (100%) rename {tests => bindgen-tests/tests}/headers/macro-expr-basic.h (100%) rename {tests => bindgen-tests/tests}/headers/macro-expr-uncommon-token.h (100%) rename {tests => bindgen-tests/tests}/headers/macro-redef.h (100%) rename {tests => bindgen-tests/tests}/headers/macro_const.h (100%) rename {tests => bindgen-tests/tests}/headers/macro_const_1_0.h (100%) rename {tests => bindgen-tests/tests}/headers/maddness-is-avoidable.hpp (100%) rename {tests => bindgen-tests/tests}/headers/mangling-ios.h (100%) rename {tests => bindgen-tests/tests}/headers/mangling-linux32.hpp (100%) rename {tests => bindgen-tests/tests}/headers/mangling-linux64.hpp (100%) rename {tests => bindgen-tests/tests}/headers/mangling-macos.hpp (100%) rename {tests => bindgen-tests/tests}/headers/mangling-win32.hpp (100%) rename {tests => bindgen-tests/tests}/headers/mangling-win64.hpp (100%) rename {tests => bindgen-tests/tests}/headers/merge-extern-blocks.h (100%) rename {tests => bindgen-tests/tests}/headers/method-mangling.hpp (100%) rename {tests => bindgen-tests/tests}/headers/module-allowlisted.hpp (100%) rename {tests => bindgen-tests/tests}/headers/msvc-no-usr.hpp (100%) rename {tests => bindgen-tests/tests}/headers/multiple-inherit-empty-correct-layout.hpp (100%) rename {tests => bindgen-tests/tests}/headers/mutable.hpp (100%) rename {tests => bindgen-tests/tests}/headers/namespace.hpp (100%) rename {tests => bindgen-tests/tests}/headers/namespace/nsbegin.h (100%) rename {tests => bindgen-tests/tests}/headers/namespace/nsend.h (100%) rename {tests => bindgen-tests/tests}/headers/nested-template-typedef.hpp (100%) rename {tests => bindgen-tests/tests}/headers/nested.hpp (100%) rename {tests => bindgen-tests/tests}/headers/nested_vtable.hpp (100%) rename {tests => bindgen-tests/tests}/headers/nested_within_namespace.hpp (100%) rename {tests => bindgen-tests/tests}/headers/newtype-enum.hpp (100%) rename {tests => bindgen-tests/tests}/headers/newtype-global-enum.hpp (100%) rename {tests => bindgen-tests/tests}/headers/no-comments.h (100%) rename {tests => bindgen-tests/tests}/headers/no-derive-debug.h (100%) rename {tests => bindgen-tests/tests}/headers/no-derive-default.h (100%) rename {tests => bindgen-tests/tests}/headers/no-hash-allowlisted.hpp (100%) rename {tests => bindgen-tests/tests}/headers/no-hash-opaque.hpp (100%) rename {tests => bindgen-tests/tests}/headers/no-partialeq-allowlisted.hpp (100%) rename {tests => bindgen-tests/tests}/headers/no-partialeq-opaque.hpp (100%) rename {tests => bindgen-tests/tests}/headers/no-recursive-allowlisting.h (100%) rename {tests => bindgen-tests/tests}/headers/no-std.h (100%) rename {tests => bindgen-tests/tests}/headers/no_copy.hpp (100%) rename {tests => bindgen-tests/tests}/headers/no_copy_allowlisted.hpp (100%) rename {tests => bindgen-tests/tests}/headers/no_copy_opaque.hpp (100%) rename {tests => bindgen-tests/tests}/headers/no_debug.hpp (100%) rename {tests => bindgen-tests/tests}/headers/no_debug_allowlisted.hpp (100%) rename {tests => bindgen-tests/tests}/headers/no_debug_bypass_impl_debug.hpp (100%) rename {tests => bindgen-tests/tests}/headers/no_debug_opaque.hpp (100%) rename {tests => bindgen-tests/tests}/headers/no_default.hpp (100%) rename {tests => bindgen-tests/tests}/headers/no_default_allowlisted.hpp (100%) rename {tests => bindgen-tests/tests}/headers/no_default_bypass_derive_default.hpp (100%) rename {tests => bindgen-tests/tests}/headers/no_default_opaque.hpp (100%) rename {tests => bindgen-tests/tests}/headers/no_size_t_is_usize.h (100%) rename {tests => bindgen-tests/tests}/headers/non-type-params.hpp (100%) rename {tests => bindgen-tests/tests}/headers/noreturn.hpp (100%) rename {tests => bindgen-tests/tests}/headers/nsBaseHashtable.hpp (100%) rename {tests => bindgen-tests/tests}/headers/nsStyleAutoArray.hpp (100%) rename {tests => bindgen-tests/tests}/headers/objc_allowlist.h (100%) rename {tests => bindgen-tests/tests}/headers/objc_blocklist.h (100%) rename {tests => bindgen-tests/tests}/headers/objc_category.h (100%) rename {tests => bindgen-tests/tests}/headers/objc_class.h (100%) rename {tests => bindgen-tests/tests}/headers/objc_class_method.h (100%) rename {tests => bindgen-tests/tests}/headers/objc_inheritance.h (100%) rename {tests => bindgen-tests/tests}/headers/objc_interface.h (100%) rename {tests => bindgen-tests/tests}/headers/objc_interface_type.h (100%) rename {tests => bindgen-tests/tests}/headers/objc_method.h (100%) rename {tests => bindgen-tests/tests}/headers/objc_method_clash.h (100%) rename {tests => bindgen-tests/tests}/headers/objc_pointer_return_types.h (100%) rename {tests => bindgen-tests/tests}/headers/objc_property_fnptr.h (100%) rename {tests => bindgen-tests/tests}/headers/objc_protocol.h (100%) rename {tests => bindgen-tests/tests}/headers/objc_protocol_inheritance.h (100%) rename {tests => bindgen-tests/tests}/headers/objc_sel_and_id.h (100%) rename {tests => bindgen-tests/tests}/headers/objc_template.h (100%) rename {tests => bindgen-tests/tests}/headers/only_bitfields.hpp (100%) rename {tests => bindgen-tests/tests}/headers/opaque-template-inst-member-2.hpp (100%) rename {tests => bindgen-tests/tests}/headers/opaque-template-inst-member.hpp (100%) rename {tests => bindgen-tests/tests}/headers/opaque-template-instantiation-namespaced.hpp (100%) rename {tests => bindgen-tests/tests}/headers/opaque-template-instantiation.hpp (100%) rename {tests => bindgen-tests/tests}/headers/opaque-tracing.hpp (100%) rename {tests => bindgen-tests/tests}/headers/opaque_in_struct.hpp (100%) rename {tests => bindgen-tests/tests}/headers/opaque_pointer.hpp (100%) rename {tests => bindgen-tests/tests}/headers/opaque_typedef.hpp (100%) rename {tests => bindgen-tests/tests}/headers/operator.hpp (100%) rename {tests => bindgen-tests/tests}/headers/ord-enum.h (100%) rename {tests => bindgen-tests/tests}/headers/overflowed_enum.hpp (100%) rename {tests => bindgen-tests/tests}/headers/overloading.hpp (100%) rename {tests => bindgen-tests/tests}/headers/packed-bitfield.h (100%) rename {tests => bindgen-tests/tests}/headers/packed-n-with-padding.h (100%) rename {tests => bindgen-tests/tests}/headers/packed-vtable.h (100%) rename {tests => bindgen-tests/tests}/headers/parm-union.hpp (100%) rename {tests => bindgen-tests/tests}/headers/parsecb-anonymous-enum-variant-rename.h (100%) rename {tests => bindgen-tests/tests}/headers/partial-specialization-and-inheritance.hpp (100%) rename {tests => bindgen-tests/tests}/headers/pointer-attr.h (100%) rename {tests => bindgen-tests/tests}/headers/prepend-enum-constified-variant.h (100%) rename {tests => bindgen-tests/tests}/headers/prepend_enum_name.hpp (100%) rename {tests => bindgen-tests/tests}/headers/private.hpp (100%) rename {tests => bindgen-tests/tests}/headers/private_fields.hpp (100%) rename {tests => bindgen-tests/tests}/headers/public-dtor.hpp (100%) rename {tests => bindgen-tests/tests}/headers/qualified-dependent-types.hpp (100%) rename {tests => bindgen-tests/tests}/headers/redeclaration.hpp (100%) rename {tests => bindgen-tests/tests}/headers/ref_argument_array.hpp (100%) rename {tests => bindgen-tests/tests}/headers/reparented_replacement.hpp (100%) rename {tests => bindgen-tests/tests}/headers/replace_template_alias.hpp (100%) rename {tests => bindgen-tests/tests}/headers/replace_use.hpp (100%) rename {tests => bindgen-tests/tests}/headers/replaces_double.hpp (100%) rename {tests => bindgen-tests/tests}/headers/repr-align.hpp (100%) rename {tests => bindgen-tests/tests}/headers/resolved_type_def_function.h (100%) rename {tests => bindgen-tests/tests}/headers/same_struct_name_in_different_namespaces.hpp (100%) rename {tests => bindgen-tests/tests}/headers/sentry-defined-multiple-times.hpp (100%) rename {tests => bindgen-tests/tests}/headers/short-enums.hpp (100%) rename {tests => bindgen-tests/tests}/headers/size_t_template.hpp (100%) rename {tests => bindgen-tests/tests}/headers/sorted-items.h (100%) rename {tests => bindgen-tests/tests}/headers/stdint_typedef.h (100%) rename {tests => bindgen-tests/tests}/headers/struct_containing_forward_declared_struct.h (100%) rename {tests => bindgen-tests/tests}/headers/struct_typedef.h (100%) rename {tests => bindgen-tests/tests}/headers/struct_typedef_ns.hpp (100%) rename {tests => bindgen-tests/tests}/headers/struct_with_anon_struct.h (100%) rename {tests => bindgen-tests/tests}/headers/struct_with_anon_struct_array.h (100%) rename {tests => bindgen-tests/tests}/headers/struct_with_anon_struct_pointer.h (100%) rename {tests => bindgen-tests/tests}/headers/struct_with_anon_union.h (100%) rename {tests => bindgen-tests/tests}/headers/struct_with_anon_union_1_0.h (100%) rename {tests => bindgen-tests/tests}/headers/struct_with_anon_unnamed_struct.h (100%) rename {tests => bindgen-tests/tests}/headers/struct_with_anon_unnamed_union.h (100%) rename {tests => bindgen-tests/tests}/headers/struct_with_anon_unnamed_union_1_0.h (100%) rename {tests => bindgen-tests/tests}/headers/struct_with_bitfields.h (100%) rename {tests => bindgen-tests/tests}/headers/struct_with_derive_debug.h (100%) rename {tests => bindgen-tests/tests}/headers/struct_with_large_array.hpp (100%) rename {tests => bindgen-tests/tests}/headers/struct_with_nesting.h (100%) rename {tests => bindgen-tests/tests}/headers/struct_with_nesting_1_0.h (100%) rename {tests => bindgen-tests/tests}/headers/struct_with_packing.h (100%) rename {tests => bindgen-tests/tests}/headers/struct_with_struct.h (100%) rename {tests => bindgen-tests/tests}/headers/struct_with_typedef_template_arg.hpp (100%) rename {tests => bindgen-tests/tests}/headers/template-fun-ty.hpp (100%) rename {tests => bindgen-tests/tests}/headers/template-param-usage-0.hpp (100%) rename {tests => bindgen-tests/tests}/headers/template-param-usage-1.hpp (100%) rename {tests => bindgen-tests/tests}/headers/template-param-usage-10.hpp (100%) rename {tests => bindgen-tests/tests}/headers/template-param-usage-11.hpp (100%) rename {tests => bindgen-tests/tests}/headers/template-param-usage-12.hpp (100%) rename {tests => bindgen-tests/tests}/headers/template-param-usage-13.hpp (100%) rename {tests => bindgen-tests/tests}/headers/template-param-usage-14.hpp (100%) rename {tests => bindgen-tests/tests}/headers/template-param-usage-15.hpp (100%) rename {tests => bindgen-tests/tests}/headers/template-param-usage-2.hpp (100%) rename {tests => bindgen-tests/tests}/headers/template-param-usage-3.hpp (100%) rename {tests => bindgen-tests/tests}/headers/template-param-usage-4.hpp (100%) rename {tests => bindgen-tests/tests}/headers/template-param-usage-5.hpp (100%) rename {tests => bindgen-tests/tests}/headers/template-param-usage-6.hpp (100%) rename {tests => bindgen-tests/tests}/headers/template-param-usage-7.hpp (100%) rename {tests => bindgen-tests/tests}/headers/template-param-usage-8.hpp (100%) rename {tests => bindgen-tests/tests}/headers/template-param-usage-9.hpp (100%) rename {tests => bindgen-tests/tests}/headers/template-with-var.hpp (100%) rename {tests => bindgen-tests/tests}/headers/template.hpp (100%) rename {tests => bindgen-tests/tests}/headers/template_alias.hpp (100%) rename {tests => bindgen-tests/tests}/headers/template_alias_basic.hpp (100%) rename {tests => bindgen-tests/tests}/headers/template_alias_namespace.hpp (100%) rename {tests => bindgen-tests/tests}/headers/template_fun.hpp (100%) rename {tests => bindgen-tests/tests}/headers/template_instantiation_with_fn_local_type.hpp (100%) rename {tests => bindgen-tests/tests}/headers/template_partial_specification.hpp (100%) rename {tests => bindgen-tests/tests}/headers/template_typedef_transitive_param.hpp (100%) rename {tests => bindgen-tests/tests}/headers/template_typedefs.hpp (100%) rename {tests => bindgen-tests/tests}/headers/templateref_opaque.hpp (100%) rename {tests => bindgen-tests/tests}/headers/templatized-bitfield.hpp (100%) rename {tests => bindgen-tests/tests}/headers/timex.h (100%) rename {tests => bindgen-tests/tests}/headers/transform-op.hpp (100%) rename {tests => bindgen-tests/tests}/headers/type-referenced-by-allowlisted-function.h (100%) rename {tests => bindgen-tests/tests}/headers/type_alias_empty.hpp (100%) rename {tests => bindgen-tests/tests}/headers/type_alias_partial_template_especialization.hpp (100%) rename {tests => bindgen-tests/tests}/headers/type_alias_template_specialized.hpp (100%) rename {tests => bindgen-tests/tests}/headers/typedefd-array-as-function-arg.h (100%) rename {tests => bindgen-tests/tests}/headers/typeref.hpp (100%) rename {tests => bindgen-tests/tests}/headers/typeref_1_0.hpp (100%) rename {tests => bindgen-tests/tests}/headers/underscore.hpp (100%) rename {tests => bindgen-tests/tests}/headers/union-align.h (100%) rename {tests => bindgen-tests/tests}/headers/union-in-ns.hpp (100%) rename {tests => bindgen-tests/tests}/headers/union-in-ns_1_0.hpp (100%) rename {tests => bindgen-tests/tests}/headers/union_bitfield.h (100%) rename {tests => bindgen-tests/tests}/headers/union_bitfield_1_0.h (100%) rename {tests => bindgen-tests/tests}/headers/union_dtor.hpp (100%) rename {tests => bindgen-tests/tests}/headers/union_dtor_1_0.hpp (100%) rename {tests => bindgen-tests/tests}/headers/union_fields.hpp (100%) rename {tests => bindgen-tests/tests}/headers/union_fields_1_0.hpp (100%) rename {tests => bindgen-tests/tests}/headers/union_template.hpp (100%) rename {tests => bindgen-tests/tests}/headers/union_template_1_0.hpp (100%) rename {tests => bindgen-tests/tests}/headers/union_with_anon_struct.h (100%) rename {tests => bindgen-tests/tests}/headers/union_with_anon_struct_1_0.h (100%) rename {tests => bindgen-tests/tests}/headers/union_with_anon_struct_bitfield.h (100%) rename {tests => bindgen-tests/tests}/headers/union_with_anon_struct_bitfield_1_0.h (100%) rename {tests => bindgen-tests/tests}/headers/union_with_anon_union.h (100%) rename {tests => bindgen-tests/tests}/headers/union_with_anon_union_1_0.h (100%) rename {tests => bindgen-tests/tests}/headers/union_with_anon_unnamed_struct.h (100%) rename {tests => bindgen-tests/tests}/headers/union_with_anon_unnamed_struct_1_0.h (100%) rename {tests => bindgen-tests/tests}/headers/union_with_anon_unnamed_union.h (100%) rename {tests => bindgen-tests/tests}/headers/union_with_anon_unnamed_union_1_0.h (100%) rename {tests => bindgen-tests/tests}/headers/union_with_big_member.h (100%) rename {tests => bindgen-tests/tests}/headers/union_with_big_member_1_0.h (100%) rename {tests => bindgen-tests/tests}/headers/union_with_nesting.h (100%) rename {tests => bindgen-tests/tests}/headers/union_with_nesting_1_0.h (100%) rename {tests => bindgen-tests/tests}/headers/union_with_non_copy_member.h (100%) rename {tests => bindgen-tests/tests}/headers/unknown_attr.h (100%) rename {tests => bindgen-tests/tests}/headers/unsorted-items.h (100%) rename {tests => bindgen-tests/tests}/headers/use-core.h (100%) rename {tests => bindgen-tests/tests}/headers/use-core_1_0.h (100%) rename {tests => bindgen-tests/tests}/headers/using.hpp (100%) rename {tests => bindgen-tests/tests}/headers/var-tracing.hpp (100%) rename {tests => bindgen-tests/tests}/headers/variadic-method.hpp (100%) rename {tests => bindgen-tests/tests}/headers/variadic_template_function.hpp (100%) rename {tests => bindgen-tests/tests}/headers/vector.hpp (100%) rename {tests => bindgen-tests/tests}/headers/virtual_dtor.hpp (100%) rename {tests => bindgen-tests/tests}/headers/virtual_inheritance.hpp (100%) rename {tests => bindgen-tests/tests}/headers/virtual_interface.hpp (100%) rename {tests => bindgen-tests/tests}/headers/virtual_overloaded.hpp (100%) rename {tests => bindgen-tests/tests}/headers/vtable_recursive_sig.hpp (100%) rename {tests => bindgen-tests/tests}/headers/wasm-constructor-returns.hpp (100%) rename {tests => bindgen-tests/tests}/headers/wasm-import-module.h (100%) rename {tests => bindgen-tests/tests}/headers/weird_bitfields.hpp (100%) rename {tests => bindgen-tests/tests}/headers/what_is_going_on.hpp (100%) rename {tests => bindgen-tests/tests}/headers/win32-thiscall_1_0.hpp (100%) rename {tests => bindgen-tests/tests}/headers/win32-thiscall_nightly.hpp (100%) rename {tests => bindgen-tests/tests}/headers/win32-vectorcall-1_0.h (100%) rename {tests => bindgen-tests/tests}/headers/win32-vectorcall-nightly.h (100%) rename {tests => bindgen-tests/tests}/headers/with_array_pointers_arguments.h (100%) rename {tests => bindgen-tests/tests}/headers/without_array_pointers_arguments.h (100%) rename {tests => bindgen-tests/tests}/headers/zero-size-array-align.h (100%) rename {tests => bindgen-tests/tests}/headers/zero-sized-array.hpp (100%) rename {tests => bindgen-tests/tests}/parse_callbacks/mod.rs (100%) rename {tests => bindgen-tests/tests}/quickchecking/.gitignore (100%) rename {tests => bindgen-tests/tests}/quickchecking/Cargo.toml (94%) rename {tests => bindgen-tests/tests}/quickchecking/README.md (100%) rename {tests => bindgen-tests/tests}/quickchecking/src/bin.rs (94%) rename {tests => bindgen-tests/tests}/quickchecking/src/fuzzers.rs (97%) rename {tests => bindgen-tests/tests}/quickchecking/src/lib.rs (93%) rename {tests => bindgen-tests/tests}/quickchecking/tests/fuzzed-c-headers.rs (87%) rename {tests => bindgen-tests/tests}/rustfmt.toml (100%) rename {tests => bindgen-tests/tests}/stylo.hpp (100%) rename {tests => bindgen-tests/tests}/stylo_sanity.rs (100%) rename {tests => bindgen-tests/tests}/test-one.sh (100%) rename {tests => bindgen-tests/tests}/tests.rs (95%) rename {tests => bindgen-tests/tests}/uses/.gitignore (100%) create mode 100644 bindgen/Cargo.toml create mode 100644 bindgen/build.rs rename {src => bindgen}/callbacks.rs (100%) rename {src => bindgen}/clang.rs (100%) rename {src => bindgen}/codegen/bitfield_unit.rs (100%) rename {src => bindgen}/codegen/bitfield_unit_tests.rs (100%) rename {src => bindgen}/codegen/dyngen.rs (100%) rename {src => bindgen}/codegen/error.rs (100%) rename {src => bindgen}/codegen/helpers.rs (100%) rename {src => bindgen}/codegen/impl_debug.rs (100%) rename {src => bindgen}/codegen/impl_partialeq.rs (100%) rename {src => bindgen}/codegen/mod.rs (100%) rename {src => bindgen}/codegen/postprocessing/merge_extern_blocks.rs (100%) rename {src => bindgen}/codegen/postprocessing/mod.rs (100%) rename {src => bindgen}/codegen/postprocessing/sort_semantically.rs (100%) rename {src => bindgen}/codegen/struct_layout.rs (100%) rename {csmith-fuzzing => bindgen/csmith-fuzzing}/README.md (100%) rename {csmith-fuzzing => bindgen/csmith-fuzzing}/csmith.h (100%) rename {csmith-fuzzing => bindgen/csmith-fuzzing}/driver.py (100%) rename {csmith-fuzzing => bindgen/csmith-fuzzing}/predicate.py (100%) rename {src => bindgen}/deps.rs (100%) rename {src => bindgen}/extra_assertions.rs (100%) rename {src => bindgen}/features.rs (100%) rename {src => bindgen}/ir/analysis/derive.rs (100%) rename {src => bindgen}/ir/analysis/has_destructor.rs (100%) rename {src => bindgen}/ir/analysis/has_float.rs (100%) rename {src => bindgen}/ir/analysis/has_type_param_in_array.rs (100%) rename {src => bindgen}/ir/analysis/has_vtable.rs (100%) rename {src => bindgen}/ir/analysis/mod.rs (100%) rename {src => bindgen}/ir/analysis/sizedness.rs (100%) rename {src => bindgen}/ir/analysis/template_params.rs (100%) rename {src => bindgen}/ir/annotations.rs (100%) rename {src => bindgen}/ir/comment.rs (100%) rename {src => bindgen}/ir/comp.rs (100%) rename {src => bindgen}/ir/context.rs (100%) rename {src => bindgen}/ir/derive.rs (100%) rename {src => bindgen}/ir/dot.rs (100%) rename {src => bindgen}/ir/enum_ty.rs (100%) rename {src => bindgen}/ir/function.rs (100%) rename {src => bindgen}/ir/int.rs (100%) rename {src => bindgen}/ir/item.rs (100%) rename {src => bindgen}/ir/item_kind.rs (100%) rename {src => bindgen}/ir/layout.rs (100%) rename {src => bindgen}/ir/mod.rs (100%) rename {src => bindgen}/ir/module.rs (100%) rename {src => bindgen}/ir/objc.rs (100%) rename {src => bindgen}/ir/template.rs (100%) rename {src => bindgen}/ir/traversal.rs (100%) rename {src => bindgen}/ir/ty.rs (100%) rename {src => bindgen}/ir/var.rs (100%) rename {src => bindgen}/lib.rs (100%) rename {src => bindgen}/log_stubs.rs (100%) rename {src => bindgen}/parse.rs (100%) rename {src => bindgen}/regex_set.rs (100%) rename {src => bindgen}/time.rs (100%) delete mode 100644 build.rs diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 6adbb5dae2..94a338bff4 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -68,7 +68,7 @@ jobs: # TODO: Actually run quickchecks once `bindgen` is reliable enough. - name: Build quickcheck tests - run: cd tests/quickchecking && cargo test + run: cd bindgen-tests/tests/quickchecking && cargo test test-expectations: runs-on: ${{matrix.os}} @@ -88,7 +88,7 @@ jobs: override: true - name: Test expectations - run: cd tests/expectations && cargo test + run: cd bindgen-tests/tests/expectations && cargo test test: runs-on: ${{matrix.os}} diff --git a/.gitignore b/.gitignore index f5c3381c81..a924030cc9 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,8 @@ target/ *~ bindgen-integration/Cargo.lock -tests/expectations/Cargo.lock +bindgen-tests/tests/expectations/Cargo.lock +bindgen-tests/tests/quickchecking/Cargo.lock #*# # Test script output diff --git a/Cargo.lock b/Cargo.lock index fa908ea9d7..b9deb405ee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,13 +2,31 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "aho-corasick" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca972c2ea5f742bfce5687b9aef75506a764f61d37f8f649047846a9686ddb66" +dependencies = [ + "memchr 0.1.11", +] + [[package]] name = "aho-corasick" version = "0.7.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" dependencies = [ - "memchr", + "memchr 2.5.0", +] + +[[package]] +name = "ansi_term" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" +dependencies = [ + "winapi 0.3.9", ] [[package]] @@ -19,7 +37,7 @@ checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ "hermit-abi", "libc", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -35,29 +53,67 @@ dependencies = [ "bitflags", "cexpr", "clang-sys", - "clap", - "diff", - "env_logger", "lazy_static", "lazycell", - "log", + "log 0.4.14", "peeking_take_while", "proc-macro2", "quote", - "regex", + "regex 1.5.5", "rustc-hash", "shlex", "syn", - "tempfile", "which", ] +[[package]] +name = "bindgen-cli" +version = "0.60.1" +dependencies = [ + "bindgen", + "clap 3.2.12", + "env_logger 0.9.0", + "log 0.4.14", + "shlex", +] + +[[package]] +name = "bindgen-integration" +version = "0.1.0" +dependencies = [ + "bindgen", + "cc", +] + +[[package]] +name = "bindgen-tests" +version = "0.1.0" +dependencies = [ + "bindgen", + "clap 3.2.12", + "diff", + "shlex", + "tempfile", +] + [[package]] name = "bitflags" version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "block" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" + +[[package]] +name = "cc" +version = "1.0.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" + [[package]] name = "cexpr" version = "0.6.0" @@ -81,7 +137,22 @@ checksum = "5a050e2153c5be08febd6734e29298e844fdb0fa21aeddd63b4eb7baa106c69b" dependencies = [ "glob", "libc", - "libloading", + "libloading 0.7.0", +] + +[[package]] +name = "clap" +version = "2.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" +dependencies = [ + "ansi_term", + "atty", + "bitflags", + "strsim 0.8.0", + "textwrap 0.11.0", + "unicode-width", + "vec_map", ] [[package]] @@ -94,9 +165,9 @@ dependencies = [ "bitflags", "clap_lex", "indexmap", - "strsim", + "strsim 0.10.0", "termcolor", - "textwrap", + "textwrap 0.15.0", ] [[package]] @@ -120,6 +191,16 @@ version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" +[[package]] +name = "env_logger" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15abd780e45b3ea4f76b4e9a26ff4843258dd8a3eed2775a0e7368c2e7936c2f" +dependencies = [ + "log 0.3.9", + "regex 0.1.80", +] + [[package]] name = "env_logger" version = "0.9.0" @@ -128,11 +209,17 @@ checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3" dependencies = [ "atty", "humantime", - "log", - "regex", + "log 0.4.14", + "regex 1.5.5", "termcolor", ] +[[package]] +name = "fuchsia-cprng" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" + [[package]] name = "getrandom" version = "0.2.3" @@ -181,6 +268,16 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "kernel32-sys" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" +dependencies = [ + "winapi 0.2.8", + "winapi-build", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -199,6 +296,16 @@ version = "0.2.126" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" +[[package]] +name = "libloading" +version = "0.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "351a32417a12d5f7e82c368a66781e307834dae04c6ce0cd4456d52989229883" +dependencies = [ + "cfg-if", + "winapi 0.3.9", +] + [[package]] name = "libloading" version = "0.7.0" @@ -206,7 +313,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6f84d96438c15fcd6c3f244c8fce01d1e2b9c6b5623e9c711dc9286d8fc92d6a" dependencies = [ "cfg-if", - "winapi", + "winapi 0.3.9", +] + +[[package]] +name = "log" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" +dependencies = [ + "log 0.4.14", ] [[package]] @@ -218,6 +334,24 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "malloc_buf" +version = "0.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb" +dependencies = [ + "libc", +] + +[[package]] +name = "memchr" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8b629fb514376c675b98c1421e80b151d3817ac42d7c667717d282761418d20" +dependencies = [ + "libc", +] + [[package]] name = "memchr" version = "2.5.0" @@ -236,11 +370,20 @@ version = "7.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ffd9d26838a953b4af82cbeb9f1592c6798916983959be223a7124e992742c1" dependencies = [ - "memchr", + "memchr 2.5.0", "minimal-lexical", "version_check", ] +[[package]] +name = "objc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1" +dependencies = [ + "malloc_buf", +] + [[package]] name = "os_str_bytes" version = "6.2.0" @@ -268,6 +411,28 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quickcheck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02c2411d418cea2364325b18a205664f9ef8252e06b2e911db97c0b0d98b1406" +dependencies = [ + "env_logger 0.3.5", + "log 0.3.9", + "rand 0.3.23", +] + +[[package]] +name = "quickchecking" +version = "0.1.0" +dependencies = [ + "clap 2.34.0", + "lazy_static", + "quickcheck", + "rand 0.3.23", + "tempdir", +] + [[package]] name = "quote" version = "1.0.9" @@ -277,6 +442,29 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rand" +version = "0.3.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ac302d8f83c0c1974bf758f6b041c6c8ada916fbb44a609158ca8b064cc76c" +dependencies = [ + "libc", + "rand 0.4.6", +] + +[[package]] +name = "rand" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" +dependencies = [ + "fuchsia-cprng", + "libc", + "rand_core 0.3.1", + "rdrand", + "winapi 0.3.9", +] + [[package]] name = "rand" version = "0.8.4" @@ -285,7 +473,7 @@ checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8" dependencies = [ "libc", "rand_chacha", - "rand_core", + "rand_core 0.6.3", "rand_hc", ] @@ -296,9 +484,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core", + "rand_core 0.6.3", +] + +[[package]] +name = "rand_core" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +dependencies = [ + "rand_core 0.4.2", ] +[[package]] +name = "rand_core" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" + [[package]] name = "rand_core" version = "0.6.3" @@ -314,7 +517,16 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7" dependencies = [ - "rand_core", + "rand_core 0.6.3", +] + +[[package]] +name = "rdrand" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" +dependencies = [ + "rand_core 0.3.1", ] [[package]] @@ -326,17 +538,36 @@ dependencies = [ "bitflags", ] +[[package]] +name = "regex" +version = "0.1.80" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fd4ace6a8cf7860714a2c2280d6c1f7e6a413486c13298bbc86fd3da019402f" +dependencies = [ + "aho-corasick 0.5.3", + "memchr 0.1.11", + "regex-syntax 0.3.9", + "thread_local", + "utf8-ranges", +] + [[package]] name = "regex" version = "1.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a11647b6b25ff05a515cb92c365cec08801e83423a235b51e231e1808747286" dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", + "aho-corasick 0.7.18", + "memchr 2.5.0", + "regex-syntax 0.6.25", ] +[[package]] +name = "regex-syntax" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9ec002c35e86791825ed294b50008eea9ddfc8def4420124fbc6b08db834957" + [[package]] name = "regex-syntax" version = "0.6.25" @@ -349,7 +580,7 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" dependencies = [ - "winapi", + "winapi 0.3.9", ] [[package]] @@ -364,6 +595,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42a568c8f2cd051a4d283bd6eb0343ac214c1b0f1ac19f93e1175b2dee38c73d" +[[package]] +name = "strsim" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" + [[package]] name = "strsim" version = "0.10.0" @@ -381,6 +618,16 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "tempdir" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8" +dependencies = [ + "rand 0.4.6", + "remove_dir_all", +] + [[package]] name = "tempfile" version = "3.2.0" @@ -389,10 +636,10 @@ checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" dependencies = [ "cfg-if", "libc", - "rand", + "rand 0.8.4", "redox_syscall", "remove_dir_all", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -404,18 +651,73 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "tests_expectations" +version = "0.1.0" +dependencies = [ + "block", + "libloading 0.6.7", + "objc", +] + +[[package]] +name = "textwrap" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +dependencies = [ + "unicode-width", +] + [[package]] name = "textwrap" version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" +[[package]] +name = "thread-id" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9539db560102d1cef46b8b78ce737ff0bb64e7e18d35b2a5688f7d097d0ff03" +dependencies = [ + "kernel32-sys", + "libc", +] + +[[package]] +name = "thread_local" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8576dbbfcaef9641452d5cf0df9b0e7eeab7694956dd33bb61515fb8f18cfdd5" +dependencies = [ + "thread-id", +] + [[package]] name = "unicode-ident" version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" +[[package]] +name = "unicode-width" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" + +[[package]] +name = "utf8-ranges" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1ca13c08c41c9c3e04224ed9ff80461d97e121589ff27c753a16cb10830ae0f" + +[[package]] +name = "vec_map" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" + [[package]] name = "version_check" version = "0.9.3" @@ -439,6 +741,12 @@ dependencies = [ "libc", ] +[[package]] +name = "winapi" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" + [[package]] name = "winapi" version = "0.3.9" @@ -449,6 +757,12 @@ dependencies = [ "winapi-x86_64-pc-windows-gnu", ] +[[package]] +name = "winapi-build" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" + [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" @@ -461,7 +775,7 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" dependencies = [ - "winapi", + "winapi 0.3.9", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 311110b3ec..a9d9d41ee6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,88 +1,15 @@ -[package] -authors = [ - "Jyun-Yan You ", - "Emilio Cobos Álvarez ", - "Nick Fitzgerald ", - "The Servo project developers", +[workspace] +members = [ + "bindgen", + "bindgen-cli", + "bindgen-integration", + "bindgen-tests", + "bindgen-tests/tests/quickchecking", + "bindgen-tests/tests/expectations", ] -description = "Automatically generates Rust FFI bindings to C and C++ libraries." -keywords = ["bindings", "ffi", "code-generation"] -categories = ["external-ffi-bindings", "development-tools::ffi"] -license = "BSD-3-Clause" -name = "bindgen" -readme = "README.md" -repository = "https://github.com/rust-lang/rust-bindgen" -documentation = "https://docs.rs/bindgen" -homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.60.1" -edition = "2018" -build = "build.rs" -# If you change this, also update README.md and msrv in .github/workflows/bindgen.yml -rust-version = "1.57.0" -include = [ - "LICENSE", - "README.md", - "Cargo.toml", - "build.rs", - "src/*.rs", - "src/**/*.rs", +default-members = [ + "bindgen", + "bindgen-cli", + "bindgen-tests", ] - -[badges] -travis-ci = { repository = "rust-lang/rust-bindgen" } - -[lib] -path = "src/lib.rs" - -[[bin]] -name = "bindgen" -path = "src/main.rs" -doc = false -required-features = ["clap"] - -[dev-dependencies] -diff = "0.1" -clap = "3" -shlex = "1" -tempfile = "3" - -[dependencies] -bitflags = "1.0.3" -cexpr = "0.6" -# This kinda sucks: https://github.com/rust-lang/cargo/issues/1982 -clap = { version = "3", optional = true } -clang-sys = { version = "1", features = ["clang_6_0"] } -lazycell = "1" -lazy_static = "1" -peeking_take_while = "0.1.2" -quote = { version = "1", default-features = false } -syn = { version = "1.0.99", features = ["full", "extra-traits"]} -regex = { version = "1.5", default-features = false , features = ["std", "unicode"] } -which = { version = "4.2.1", optional = true, default-features = false } -shlex = "1" -rustc-hash = "1.0.1" -proc-macro2 = { version = "1", default-features = false } - -[dependencies.env_logger] -optional = true -version = "0.9.0" - -[dependencies.log] -optional = true -version = "0.4" - -[features] -default = ["logging", "clap", "runtime", "which-rustfmt"] -logging = ["env_logger", "log"] -static = ["clang-sys/static"] -runtime = ["clang-sys/runtime"] -# Dynamically discover a `rustfmt` binary using the `which` crate -which-rustfmt = ["which"] - -# These features only exist for CI testing -- don't use them if you're not hacking -# on bindgen! -testing_only_docs = [] -testing_only_extra_assertions = [] -testing_only_libclang_9 = [] -testing_only_libclang_5 = [] diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml new file mode 100644 index 0000000000..3ebf4a3f77 --- /dev/null +++ b/bindgen-cli/Cargo.toml @@ -0,0 +1,44 @@ +[package] +authors = [ + "The rust-bindgen project contributors", +] +description = "Automatically generates Rust FFI bindings to C and C++ libraries." +keywords = ["bindings", "ffi", "code-generation"] +categories = ["external-ffi-bindings", "development-tools::ffi"] +license = "BSD-3-Clause" +name = "bindgen-cli" +readme = "README.md" +repository = "https://github.com/rust-lang/rust-bindgen" +documentation = "https://docs.rs/bindgen" +homepage = "https://rust-lang.github.io/rust-bindgen/" +version = "0.60.1" +edition = "2018" +# If you change this, also update README.md and msrv in .github/workflows/bindgen.yml +rust-version = "1.57.0" + +include = [ + "Cargo.toml", + "build.rs", +] + +[[bin]] +path = "main.rs" +name = "bindgen" + +[badges] +travis-ci = { repository = "rust-lang/rust-bindgen" } + +[dependencies] +bindgen = { path = "../bindgen" } +shlex = "1" +clap = "3" +env_logger = { version = "0.9.0", optional = true } +log = { version = "0.4", optional = true } + +[features] +default = ["logging", "runtime", "which-rustfmt"] +logging = ["bindgen/logging", "env_logger", "log"] +static = ["bindgen/static"] +runtime = ["bindgen/runtime"] +# Dynamically discover a `rustfmt` binary using the `which` crate +which-rustfmt = ["bindgen/which-rustfmt"] diff --git a/src/main.rs b/bindgen-cli/main.rs similarity index 61% rename from src/main.rs rename to bindgen-cli/main.rs index 50f3e71440..a61f67ad51 100644 --- a/src/main.rs +++ b/bindgen-cli/main.rs @@ -1,24 +1,19 @@ extern crate bindgen; +extern crate clap; #[cfg(feature = "logging")] extern crate env_logger; -#[macro_use] #[cfg(feature = "logging")] extern crate log; -extern crate clap; -use bindgen::clang_version; use std::env; use std::panic; -#[macro_use] -#[cfg(not(feature = "logging"))] -mod log_stubs; - mod options; use crate::options::builder_from_flags; +#[cfg(feature = "logging")] fn clang_version_check() { - let version = clang_version(); + let version = bindgen::clang_version(); let expected_version = if cfg!(feature = "testing_only_libclang_9") { Some((9, 0)) } else if cfg!(feature = "testing_only_libclang_5") { @@ -27,9 +22,10 @@ fn clang_version_check() { None }; - info!( + log::info!( "Clang Version: {}, parsed: {:?}", - version.full, version.parsed + version.full, + version.parsed ); if expected_version.is_some() { @@ -43,6 +39,7 @@ pub fn main() { match builder_from_flags(env::args()) { Ok((builder, output, verbose)) => { + #[cfg(feature = "logging")] clang_version_check(); let builder_result = panic::catch_unwind(|| { builder.generate().expect("Unable to generate bindings") @@ -78,32 +75,3 @@ fn print_verbose_err() { https://github.com/rust-lang/rust-bindgen/issues/new" ); } - -#[cfg(test)] -mod test { - fn build_flags_output_helper(builder: &bindgen::Builder) { - let mut command_line_flags = builder.command_line_flags(); - command_line_flags.insert(0, "bindgen".to_string()); - - let flags_quoted: Vec = command_line_flags - .iter() - .map(|x| format!("{}", shlex::quote(x))) - .collect(); - let flags_str = flags_quoted.join(" "); - println!("{}", flags_str); - - let (builder, _output, _verbose) = - crate::options::builder_from_flags(command_line_flags.into_iter()) - .unwrap(); - builder.generate().expect("failed to generate bindings"); - } - - #[test] - fn commandline_multiple_headers() { - let bindings = bindgen::Builder::default() - .header("tests/headers/char.h") - .header("tests/headers/func_ptr.h") - .header("tests/headers/16-byte-alignment.h"); - build_flags_output_helper(&bindings); - } -} diff --git a/src/options.rs b/bindgen-cli/options.rs similarity index 99% rename from src/options.rs rename to bindgen-cli/options.rs index 1025a36dc9..5c3960e92b 100644 --- a/src/options.rs +++ b/bindgen-cli/options.rs @@ -581,7 +581,7 @@ where option_env!("CARGO_PKG_VERSION").unwrap_or("unknown") ); if verbose { - println!("Clang: {}", crate::clang_version().full); + println!("Clang: {}", bindgen::clang_version().full); } std::process::exit(0); } diff --git a/bindgen-integration/Cargo.toml b/bindgen-integration/Cargo.toml index 733fba58db..e2abb6e2ed 100644 --- a/bindgen-integration/Cargo.toml +++ b/bindgen-integration/Cargo.toml @@ -7,7 +7,7 @@ publish = false build = "build.rs" [build-dependencies] -bindgen = { path = ".." } +bindgen = { path = "../bindgen" } cc = "1.0" [features] diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs index d0ec3bc0dd..980d40b956 100644 --- a/bindgen-integration/build.rs +++ b/bindgen-integration/build.rs @@ -123,13 +123,9 @@ impl ParseCallbacks for MacroCallback { // Test the "custom derives" capability by adding `PartialEq` to the `Test` struct. fn add_derives(&self, name: &str) -> Vec { if name == "Test" { - vec![ - "PartialEq".into(), - ] + vec!["PartialEq".into()] } else if name == "MyOrderedEnum" { - vec![ - "std::cmp::PartialOrd".into(), - ] + vec!["std::cmp::PartialOrd".into()] } else { vec![] } @@ -162,7 +158,9 @@ fn main() { let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); let out_rust_file = out_path.join("test.rs"); - let out_rust_file_relative = out_rust_file.strip_prefix(std::env::current_dir().unwrap()).unwrap(); + let out_rust_file_relative = out_rust_file + .strip_prefix(std::env::current_dir().unwrap().parent().unwrap()) + .unwrap(); let out_dep_file = out_path.join("test.d"); let bindings = Builder::default() @@ -189,13 +187,18 @@ fn main() { .expect("Unable to generate bindings"); assert!(macros.read().unwrap().contains("TESTMACRO")); - bindings.write_to_file(&out_rust_file).expect("Couldn't write bindings!"); - - let observed_deps = std::fs::read_to_string(out_dep_file).expect("Couldn't read depfile!"); - let expected_deps = format!("{}: cpp/Test.h include/stub.h", out_rust_file_relative.display()); + bindings + .write_to_file(&out_rust_file) + .expect("Couldn't write bindings!"); + + let observed_deps = + std::fs::read_to_string(out_dep_file).expect("Couldn't read depfile!"); + let expected_deps = format!( + "{}: cpp/Test.h include/stub.h", + out_rust_file_relative.display() + ); assert_eq!( - observed_deps, - expected_deps, + observed_deps, expected_deps, "including stub via include dir must produce correct dep path", ); } diff --git a/bindgen-tests/Cargo.toml b/bindgen-tests/Cargo.toml new file mode 100644 index 0000000000..53dfca15bf --- /dev/null +++ b/bindgen-tests/Cargo.toml @@ -0,0 +1,28 @@ +[package] +name = "bindgen-tests" +edition = "2018" +version = "0.1.0" +publish = false + +include = [ + "Cargo.toml", + "build.rs", +] + +[dev-dependencies] +bindgen = { path = "../bindgen" } +diff = "0.1" +shlex = "1" +clap = "3" +tempfile = "3" + +[features] +logging = ["bindgen/logging"] +static = ["bindgen/static"] +runtime = ["bindgen/runtime"] +which-rustfmt = ["bindgen/which-rustfmt"] + +testing_only_docs = ["bindgen/testing_only_docs"] +testing_only_extra_assertions = ["bindgen/testing_only_extra_assertions"] +testing_only_libclang_9 = ["bindgen/testing_only_libclang_9"] +testing_only_libclang_5 = ["bindgen/testing_only_libclang_5"] diff --git a/bindgen-tests/build.rs b/bindgen-tests/build.rs new file mode 100644 index 0000000000..6b2f2c7274 --- /dev/null +++ b/bindgen-tests/build.rs @@ -0,0 +1,49 @@ +use std::char; +use std::env; +use std::ffi::OsStr; +use std::fs::{self, File}; +use std::io::Write; +use std::path::{Path, PathBuf}; + +pub fn main() { + let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); + let mut dst = File::create(Path::new(&out_dir).join("tests.rs")).unwrap(); + + let manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()); + let headers_dir = manifest_dir.join("tests").join("headers"); + + let headers = match fs::read_dir(headers_dir) { + Ok(dir) => dir, + // We may not have headers directory after packaging. + Err(..) => return, + }; + + let entries = + headers.map(|result| result.expect("Couldn't read header file")); + + println!("cargo:rerun-if-changed=tests/headers"); + + for entry in entries { + match entry.path().extension().and_then(OsStr::to_str) { + Some("h") | Some("hpp") => { + let func = entry + .file_name() + .to_str() + .unwrap() + .replace(|c| !char::is_alphanumeric(c), "_") + .replace("__", "_") + .to_lowercase(); + writeln!( + dst, + "test_header!(header_{}, {:?});", + func, + entry.path(), + ) + .unwrap(); + } + _ => {} + } + } + + dst.flush().unwrap(); +} diff --git a/tests/expectations/src/lib.rs b/bindgen-tests/src/lib.rs similarity index 100% rename from tests/expectations/src/lib.rs rename to bindgen-tests/src/lib.rs diff --git a/tests/.gitattributes b/bindgen-tests/tests/.gitattributes similarity index 100% rename from tests/.gitattributes rename to bindgen-tests/tests/.gitattributes diff --git a/tests/expectations/Cargo.toml b/bindgen-tests/tests/expectations/Cargo.toml similarity index 100% rename from tests/expectations/Cargo.toml rename to bindgen-tests/tests/expectations/Cargo.toml diff --git a/tests/expectations/build.rs b/bindgen-tests/tests/expectations/build.rs similarity index 95% rename from tests/expectations/build.rs rename to bindgen-tests/tests/expectations/build.rs index e44bcc8596..edbcafb9e7 100644 --- a/tests/expectations/build.rs +++ b/bindgen-tests/tests/expectations/build.rs @@ -8,10 +8,8 @@ use std::fs; use std::io::Write; use std::path::Path; -const LIBCLANG_VERSION_DIRS: &'static [&'static str] = &[ - "libclang-5", - "libclang-9", -]; +const LIBCLANG_VERSION_DIRS: &'static [&'static str] = + &["libclang-5", "libclang-9"]; fn main() { println!("cargo:rerun-if-changed=build.rs"); diff --git a/tests/expectations/lib.rs b/bindgen-tests/tests/expectations/lib.rs similarity index 100% rename from tests/expectations/lib.rs rename to bindgen-tests/tests/expectations/lib.rs diff --git a/tests/expectations/struct_with_anon_struct_array_float.rs b/bindgen-tests/tests/expectations/src/lib.rs similarity index 100% rename from tests/expectations/struct_with_anon_struct_array_float.rs rename to bindgen-tests/tests/expectations/src/lib.rs diff --git a/bindgen-tests/tests/expectations/struct_with_anon_struct_array_float.rs b/bindgen-tests/tests/expectations/struct_with_anon_struct_array_float.rs new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/bindgen-tests/tests/expectations/struct_with_anon_struct_array_float.rs @@ -0,0 +1 @@ + diff --git a/tests/expectations/tests/.gitattributes b/bindgen-tests/tests/expectations/tests/.gitattributes similarity index 100% rename from tests/expectations/tests/.gitattributes rename to bindgen-tests/tests/expectations/tests/.gitattributes diff --git a/tests/expectations/tests/16-byte-alignment.rs b/bindgen-tests/tests/expectations/tests/16-byte-alignment.rs similarity index 100% rename from tests/expectations/tests/16-byte-alignment.rs rename to bindgen-tests/tests/expectations/tests/16-byte-alignment.rs diff --git a/tests/expectations/tests/16-byte-alignment_1_0.rs b/bindgen-tests/tests/expectations/tests/16-byte-alignment_1_0.rs similarity index 100% rename from tests/expectations/tests/16-byte-alignment_1_0.rs rename to bindgen-tests/tests/expectations/tests/16-byte-alignment_1_0.rs diff --git a/tests/expectations/tests/381-decltype-alias.rs b/bindgen-tests/tests/expectations/tests/381-decltype-alias.rs similarity index 100% rename from tests/expectations/tests/381-decltype-alias.rs rename to bindgen-tests/tests/expectations/tests/381-decltype-alias.rs diff --git a/tests/expectations/tests/accessors.rs b/bindgen-tests/tests/expectations/tests/accessors.rs similarity index 100% rename from tests/expectations/tests/accessors.rs rename to bindgen-tests/tests/expectations/tests/accessors.rs diff --git a/tests/expectations/tests/allowlist-file.rs b/bindgen-tests/tests/expectations/tests/allowlist-file.rs similarity index 100% rename from tests/expectations/tests/allowlist-file.rs rename to bindgen-tests/tests/expectations/tests/allowlist-file.rs diff --git a/tests/expectations/tests/allowlist-namespaces-basic.rs b/bindgen-tests/tests/expectations/tests/allowlist-namespaces-basic.rs similarity index 100% rename from tests/expectations/tests/allowlist-namespaces-basic.rs rename to bindgen-tests/tests/expectations/tests/allowlist-namespaces-basic.rs diff --git a/tests/expectations/tests/allowlist-namespaces.rs b/bindgen-tests/tests/expectations/tests/allowlist-namespaces.rs similarity index 100% rename from tests/expectations/tests/allowlist-namespaces.rs rename to bindgen-tests/tests/expectations/tests/allowlist-namespaces.rs diff --git a/tests/expectations/tests/allowlist_basic.rs b/bindgen-tests/tests/expectations/tests/allowlist_basic.rs similarity index 100% rename from tests/expectations/tests/allowlist_basic.rs rename to bindgen-tests/tests/expectations/tests/allowlist_basic.rs diff --git a/tests/expectations/tests/allowlist_fix.rs b/bindgen-tests/tests/expectations/tests/allowlist_fix.rs similarity index 100% rename from tests/expectations/tests/allowlist_fix.rs rename to bindgen-tests/tests/expectations/tests/allowlist_fix.rs diff --git a/tests/expectations/tests/allowlist_vars.rs b/bindgen-tests/tests/expectations/tests/allowlist_vars.rs similarity index 100% rename from tests/expectations/tests/allowlist_vars.rs rename to bindgen-tests/tests/expectations/tests/allowlist_vars.rs diff --git a/tests/expectations/tests/allowlist_warnings.rs b/bindgen-tests/tests/expectations/tests/allowlist_warnings.rs similarity index 100% rename from tests/expectations/tests/allowlist_warnings.rs rename to bindgen-tests/tests/expectations/tests/allowlist_warnings.rs diff --git a/tests/expectations/tests/allowlisted-item-references-no-hash.rs b/bindgen-tests/tests/expectations/tests/allowlisted-item-references-no-hash.rs similarity index 100% rename from tests/expectations/tests/allowlisted-item-references-no-hash.rs rename to bindgen-tests/tests/expectations/tests/allowlisted-item-references-no-hash.rs diff --git a/tests/expectations/tests/allowlisted-item-references-no-partialeq.rs b/bindgen-tests/tests/expectations/tests/allowlisted-item-references-no-partialeq.rs similarity index 100% rename from tests/expectations/tests/allowlisted-item-references-no-partialeq.rs rename to bindgen-tests/tests/expectations/tests/allowlisted-item-references-no-partialeq.rs diff --git a/tests/expectations/tests/allowlisted_item_references_no_copy.rs b/bindgen-tests/tests/expectations/tests/allowlisted_item_references_no_copy.rs similarity index 100% rename from tests/expectations/tests/allowlisted_item_references_no_copy.rs rename to bindgen-tests/tests/expectations/tests/allowlisted_item_references_no_copy.rs diff --git a/tests/expectations/tests/annotation_hide.rs b/bindgen-tests/tests/expectations/tests/annotation_hide.rs similarity index 100% rename from tests/expectations/tests/annotation_hide.rs rename to bindgen-tests/tests/expectations/tests/annotation_hide.rs diff --git a/tests/expectations/tests/anon-fields-prefix.rs b/bindgen-tests/tests/expectations/tests/anon-fields-prefix.rs similarity index 100% rename from tests/expectations/tests/anon-fields-prefix.rs rename to bindgen-tests/tests/expectations/tests/anon-fields-prefix.rs diff --git a/tests/expectations/tests/anon_enum.rs b/bindgen-tests/tests/expectations/tests/anon_enum.rs similarity index 100% rename from tests/expectations/tests/anon_enum.rs rename to bindgen-tests/tests/expectations/tests/anon_enum.rs diff --git a/tests/expectations/tests/anon_enum_allowlist.rs b/bindgen-tests/tests/expectations/tests/anon_enum_allowlist.rs similarity index 100% rename from tests/expectations/tests/anon_enum_allowlist.rs rename to bindgen-tests/tests/expectations/tests/anon_enum_allowlist.rs diff --git a/tests/expectations/tests/anon_enum_trait.rs b/bindgen-tests/tests/expectations/tests/anon_enum_trait.rs similarity index 100% rename from tests/expectations/tests/anon_enum_trait.rs rename to bindgen-tests/tests/expectations/tests/anon_enum_trait.rs diff --git a/tests/expectations/tests/anon_struct_in_union.rs b/bindgen-tests/tests/expectations/tests/anon_struct_in_union.rs similarity index 100% rename from tests/expectations/tests/anon_struct_in_union.rs rename to bindgen-tests/tests/expectations/tests/anon_struct_in_union.rs diff --git a/tests/expectations/tests/anon_struct_in_union_1_0.rs b/bindgen-tests/tests/expectations/tests/anon_struct_in_union_1_0.rs similarity index 100% rename from tests/expectations/tests/anon_struct_in_union_1_0.rs rename to bindgen-tests/tests/expectations/tests/anon_struct_in_union_1_0.rs diff --git a/tests/expectations/tests/anon_union.rs b/bindgen-tests/tests/expectations/tests/anon_union.rs similarity index 100% rename from tests/expectations/tests/anon_union.rs rename to bindgen-tests/tests/expectations/tests/anon_union.rs diff --git a/tests/expectations/tests/anon_union_1_0.rs b/bindgen-tests/tests/expectations/tests/anon_union_1_0.rs similarity index 100% rename from tests/expectations/tests/anon_union_1_0.rs rename to bindgen-tests/tests/expectations/tests/anon_union_1_0.rs diff --git a/tests/expectations/tests/anonymous-template-types.rs b/bindgen-tests/tests/expectations/tests/anonymous-template-types.rs similarity index 100% rename from tests/expectations/tests/anonymous-template-types.rs rename to bindgen-tests/tests/expectations/tests/anonymous-template-types.rs diff --git a/tests/expectations/tests/arg_keyword.rs b/bindgen-tests/tests/expectations/tests/arg_keyword.rs similarity index 100% rename from tests/expectations/tests/arg_keyword.rs rename to bindgen-tests/tests/expectations/tests/arg_keyword.rs diff --git a/tests/expectations/tests/array-of-zero-sized-types.rs b/bindgen-tests/tests/expectations/tests/array-of-zero-sized-types.rs similarity index 100% rename from tests/expectations/tests/array-of-zero-sized-types.rs rename to bindgen-tests/tests/expectations/tests/array-of-zero-sized-types.rs diff --git a/tests/expectations/tests/attribute_warn_unused_result.rs b/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result.rs similarity index 100% rename from tests/expectations/tests/attribute_warn_unused_result.rs rename to bindgen-tests/tests/expectations/tests/attribute_warn_unused_result.rs diff --git a/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 similarity index 100% rename from tests/expectations/tests/attribute_warn_unused_result_no_attribute_detection.rs rename to bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_no_attribute_detection.rs diff --git a/tests/expectations/tests/attribute_warn_unused_result_pre_1_27.rs b/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_pre_1_27.rs similarity index 100% rename from tests/expectations/tests/attribute_warn_unused_result_pre_1_27.rs rename to bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_pre_1_27.rs diff --git a/tests/expectations/tests/bad-namespace-parenthood-inheritance.rs b/bindgen-tests/tests/expectations/tests/bad-namespace-parenthood-inheritance.rs similarity index 100% rename from tests/expectations/tests/bad-namespace-parenthood-inheritance.rs rename to bindgen-tests/tests/expectations/tests/bad-namespace-parenthood-inheritance.rs diff --git a/tests/expectations/tests/base-to-derived.rs b/bindgen-tests/tests/expectations/tests/base-to-derived.rs similarity index 100% rename from tests/expectations/tests/base-to-derived.rs rename to bindgen-tests/tests/expectations/tests/base-to-derived.rs diff --git a/tests/expectations/tests/bindgen-union-inside-namespace.rs b/bindgen-tests/tests/expectations/tests/bindgen-union-inside-namespace.rs similarity index 100% rename from tests/expectations/tests/bindgen-union-inside-namespace.rs rename to bindgen-tests/tests/expectations/tests/bindgen-union-inside-namespace.rs diff --git a/tests/expectations/tests/bitfield-32bit-overflow.rs b/bindgen-tests/tests/expectations/tests/bitfield-32bit-overflow.rs similarity index 100% rename from tests/expectations/tests/bitfield-32bit-overflow.rs rename to bindgen-tests/tests/expectations/tests/bitfield-32bit-overflow.rs diff --git a/tests/expectations/tests/bitfield-enum-basic.rs b/bindgen-tests/tests/expectations/tests/bitfield-enum-basic.rs similarity index 100% rename from tests/expectations/tests/bitfield-enum-basic.rs rename to bindgen-tests/tests/expectations/tests/bitfield-enum-basic.rs diff --git a/tests/expectations/tests/bitfield-enum-repr-c.rs b/bindgen-tests/tests/expectations/tests/bitfield-enum-repr-c.rs similarity index 100% rename from tests/expectations/tests/bitfield-enum-repr-c.rs rename to bindgen-tests/tests/expectations/tests/bitfield-enum-repr-c.rs diff --git a/tests/expectations/tests/bitfield-enum-repr-transparent.rs b/bindgen-tests/tests/expectations/tests/bitfield-enum-repr-transparent.rs similarity index 100% rename from tests/expectations/tests/bitfield-enum-repr-transparent.rs rename to bindgen-tests/tests/expectations/tests/bitfield-enum-repr-transparent.rs diff --git a/tests/expectations/tests/bitfield-large.rs b/bindgen-tests/tests/expectations/tests/bitfield-large.rs similarity index 100% rename from tests/expectations/tests/bitfield-large.rs rename to bindgen-tests/tests/expectations/tests/bitfield-large.rs diff --git a/tests/expectations/tests/bitfield-linux-32.rs b/bindgen-tests/tests/expectations/tests/bitfield-linux-32.rs similarity index 100% rename from tests/expectations/tests/bitfield-linux-32.rs rename to bindgen-tests/tests/expectations/tests/bitfield-linux-32.rs diff --git a/tests/expectations/tests/bitfield-method-same-name.rs b/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs similarity index 100% rename from tests/expectations/tests/bitfield-method-same-name.rs rename to bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs diff --git a/tests/expectations/tests/bitfield_align.rs b/bindgen-tests/tests/expectations/tests/bitfield_align.rs similarity index 100% rename from tests/expectations/tests/bitfield_align.rs rename to bindgen-tests/tests/expectations/tests/bitfield_align.rs diff --git a/tests/expectations/tests/bitfield_align_2.rs b/bindgen-tests/tests/expectations/tests/bitfield_align_2.rs similarity index 100% rename from tests/expectations/tests/bitfield_align_2.rs rename to bindgen-tests/tests/expectations/tests/bitfield_align_2.rs diff --git a/tests/expectations/tests/bitfield_large_overflow.rs b/bindgen-tests/tests/expectations/tests/bitfield_large_overflow.rs similarity index 100% rename from tests/expectations/tests/bitfield_large_overflow.rs rename to bindgen-tests/tests/expectations/tests/bitfield_large_overflow.rs diff --git a/tests/expectations/tests/bitfield_method_mangling.rs b/bindgen-tests/tests/expectations/tests/bitfield_method_mangling.rs similarity index 100% rename from tests/expectations/tests/bitfield_method_mangling.rs rename to bindgen-tests/tests/expectations/tests/bitfield_method_mangling.rs diff --git a/tests/expectations/tests/bitfield_pragma_packed.rs b/bindgen-tests/tests/expectations/tests/bitfield_pragma_packed.rs similarity index 100% rename from tests/expectations/tests/bitfield_pragma_packed.rs rename to bindgen-tests/tests/expectations/tests/bitfield_pragma_packed.rs diff --git a/tests/expectations/tests/block_return_type.rs b/bindgen-tests/tests/expectations/tests/block_return_type.rs similarity index 100% rename from tests/expectations/tests/block_return_type.rs rename to bindgen-tests/tests/expectations/tests/block_return_type.rs diff --git a/tests/expectations/tests/blocklist-and-impl-debug.rs b/bindgen-tests/tests/expectations/tests/blocklist-and-impl-debug.rs similarity index 100% rename from tests/expectations/tests/blocklist-and-impl-debug.rs rename to bindgen-tests/tests/expectations/tests/blocklist-and-impl-debug.rs diff --git a/tests/expectations/tests/blocklist-file.rs b/bindgen-tests/tests/expectations/tests/blocklist-file.rs similarity index 100% rename from tests/expectations/tests/blocklist-file.rs rename to bindgen-tests/tests/expectations/tests/blocklist-file.rs diff --git a/tests/expectations/tests/blocklist-function.rs b/bindgen-tests/tests/expectations/tests/blocklist-function.rs similarity index 100% rename from tests/expectations/tests/blocklist-function.rs rename to bindgen-tests/tests/expectations/tests/blocklist-function.rs diff --git a/tests/expectations/tests/blocklist-item.rs b/bindgen-tests/tests/expectations/tests/blocklist-item.rs similarity index 100% rename from tests/expectations/tests/blocklist-item.rs rename to bindgen-tests/tests/expectations/tests/blocklist-item.rs diff --git a/tests/expectations/tests/blocks-signature.rs b/bindgen-tests/tests/expectations/tests/blocks-signature.rs similarity index 100% rename from tests/expectations/tests/blocks-signature.rs rename to bindgen-tests/tests/expectations/tests/blocks-signature.rs diff --git a/tests/expectations/tests/blocks.rs b/bindgen-tests/tests/expectations/tests/blocks.rs similarity index 100% rename from tests/expectations/tests/blocks.rs rename to bindgen-tests/tests/expectations/tests/blocks.rs diff --git a/tests/expectations/tests/bug-1529681.rs b/bindgen-tests/tests/expectations/tests/bug-1529681.rs similarity index 100% rename from tests/expectations/tests/bug-1529681.rs rename to bindgen-tests/tests/expectations/tests/bug-1529681.rs diff --git a/tests/expectations/tests/builtin-template.rs b/bindgen-tests/tests/expectations/tests/builtin-template.rs similarity index 100% rename from tests/expectations/tests/builtin-template.rs rename to bindgen-tests/tests/expectations/tests/builtin-template.rs diff --git a/tests/expectations/tests/c-empty-layout.rs b/bindgen-tests/tests/expectations/tests/c-empty-layout.rs similarity index 100% rename from tests/expectations/tests/c-empty-layout.rs rename to bindgen-tests/tests/expectations/tests/c-empty-layout.rs diff --git a/tests/expectations/tests/c_naming.rs b/bindgen-tests/tests/expectations/tests/c_naming.rs similarity index 100% rename from tests/expectations/tests/c_naming.rs rename to bindgen-tests/tests/expectations/tests/c_naming.rs diff --git a/tests/expectations/tests/call-conv-typedef.rs b/bindgen-tests/tests/expectations/tests/call-conv-typedef.rs similarity index 100% rename from tests/expectations/tests/call-conv-typedef.rs rename to bindgen-tests/tests/expectations/tests/call-conv-typedef.rs diff --git a/tests/expectations/tests/canonical-types.rs b/bindgen-tests/tests/expectations/tests/canonical-types.rs similarity index 100% rename from tests/expectations/tests/canonical-types.rs rename to bindgen-tests/tests/expectations/tests/canonical-types.rs diff --git a/tests/expectations/tests/canonical_path_without_namespacing.rs b/bindgen-tests/tests/expectations/tests/canonical_path_without_namespacing.rs similarity index 100% rename from tests/expectations/tests/canonical_path_without_namespacing.rs rename to bindgen-tests/tests/expectations/tests/canonical_path_without_namespacing.rs diff --git a/tests/expectations/tests/char.rs b/bindgen-tests/tests/expectations/tests/char.rs similarity index 100% rename from tests/expectations/tests/char.rs rename to bindgen-tests/tests/expectations/tests/char.rs diff --git a/tests/expectations/tests/class.rs b/bindgen-tests/tests/expectations/tests/class.rs similarity index 100% rename from tests/expectations/tests/class.rs rename to bindgen-tests/tests/expectations/tests/class.rs diff --git a/tests/expectations/tests/class_1_0.rs b/bindgen-tests/tests/expectations/tests/class_1_0.rs similarity index 100% rename from tests/expectations/tests/class_1_0.rs rename to bindgen-tests/tests/expectations/tests/class_1_0.rs diff --git a/tests/expectations/tests/class_nested.rs b/bindgen-tests/tests/expectations/tests/class_nested.rs similarity index 100% rename from tests/expectations/tests/class_nested.rs rename to bindgen-tests/tests/expectations/tests/class_nested.rs diff --git a/tests/expectations/tests/class_no_members.rs b/bindgen-tests/tests/expectations/tests/class_no_members.rs similarity index 100% rename from tests/expectations/tests/class_no_members.rs rename to bindgen-tests/tests/expectations/tests/class_no_members.rs diff --git a/tests/expectations/tests/class_static.rs b/bindgen-tests/tests/expectations/tests/class_static.rs similarity index 100% rename from tests/expectations/tests/class_static.rs rename to bindgen-tests/tests/expectations/tests/class_static.rs diff --git a/tests/expectations/tests/class_static_const.rs b/bindgen-tests/tests/expectations/tests/class_static_const.rs similarity index 100% rename from tests/expectations/tests/class_static_const.rs rename to bindgen-tests/tests/expectations/tests/class_static_const.rs diff --git a/tests/expectations/tests/class_use_as.rs b/bindgen-tests/tests/expectations/tests/class_use_as.rs similarity index 100% rename from tests/expectations/tests/class_use_as.rs rename to bindgen-tests/tests/expectations/tests/class_use_as.rs diff --git a/tests/expectations/tests/class_with_dtor.rs b/bindgen-tests/tests/expectations/tests/class_with_dtor.rs similarity index 100% rename from tests/expectations/tests/class_with_dtor.rs rename to bindgen-tests/tests/expectations/tests/class_with_dtor.rs diff --git a/tests/expectations/tests/class_with_inner_struct.rs b/bindgen-tests/tests/expectations/tests/class_with_inner_struct.rs similarity index 100% rename from tests/expectations/tests/class_with_inner_struct.rs rename to bindgen-tests/tests/expectations/tests/class_with_inner_struct.rs diff --git a/tests/expectations/tests/class_with_inner_struct_1_0.rs b/bindgen-tests/tests/expectations/tests/class_with_inner_struct_1_0.rs similarity index 100% rename from tests/expectations/tests/class_with_inner_struct_1_0.rs rename to bindgen-tests/tests/expectations/tests/class_with_inner_struct_1_0.rs diff --git a/tests/expectations/tests/class_with_typedef.rs b/bindgen-tests/tests/expectations/tests/class_with_typedef.rs similarity index 100% rename from tests/expectations/tests/class_with_typedef.rs rename to bindgen-tests/tests/expectations/tests/class_with_typedef.rs diff --git a/tests/expectations/tests/comment-indent.rs b/bindgen-tests/tests/expectations/tests/comment-indent.rs similarity index 100% rename from tests/expectations/tests/comment-indent.rs rename to bindgen-tests/tests/expectations/tests/comment-indent.rs diff --git a/tests/expectations/tests/complex.rs b/bindgen-tests/tests/expectations/tests/complex.rs similarity index 100% rename from tests/expectations/tests/complex.rs rename to bindgen-tests/tests/expectations/tests/complex.rs diff --git a/tests/expectations/tests/complex_global.rs b/bindgen-tests/tests/expectations/tests/complex_global.rs similarity index 100% rename from tests/expectations/tests/complex_global.rs rename to bindgen-tests/tests/expectations/tests/complex_global.rs diff --git a/tests/expectations/tests/const-const-mut-ptr.rs b/bindgen-tests/tests/expectations/tests/const-const-mut-ptr.rs similarity index 100% rename from tests/expectations/tests/const-const-mut-ptr.rs rename to bindgen-tests/tests/expectations/tests/const-const-mut-ptr.rs diff --git a/tests/expectations/tests/const_array.rs b/bindgen-tests/tests/expectations/tests/const_array.rs similarity index 100% rename from tests/expectations/tests/const_array.rs rename to bindgen-tests/tests/expectations/tests/const_array.rs diff --git a/tests/expectations/tests/const_array_fn_arg.rs b/bindgen-tests/tests/expectations/tests/const_array_fn_arg.rs similarity index 100% rename from tests/expectations/tests/const_array_fn_arg.rs rename to bindgen-tests/tests/expectations/tests/const_array_fn_arg.rs diff --git a/tests/expectations/tests/const_enum_unnamed.rs b/bindgen-tests/tests/expectations/tests/const_enum_unnamed.rs similarity index 100% rename from tests/expectations/tests/const_enum_unnamed.rs rename to bindgen-tests/tests/expectations/tests/const_enum_unnamed.rs diff --git a/tests/expectations/tests/const_multidim_array_fn_arg.rs b/bindgen-tests/tests/expectations/tests/const_multidim_array_fn_arg.rs similarity index 100% rename from tests/expectations/tests/const_multidim_array_fn_arg.rs rename to bindgen-tests/tests/expectations/tests/const_multidim_array_fn_arg.rs diff --git a/tests/expectations/tests/const_ptr.rs b/bindgen-tests/tests/expectations/tests/const_ptr.rs similarity index 100% rename from tests/expectations/tests/const_ptr.rs rename to bindgen-tests/tests/expectations/tests/const_ptr.rs diff --git a/tests/expectations/tests/const_resolved_ty.rs b/bindgen-tests/tests/expectations/tests/const_resolved_ty.rs similarity index 100% rename from tests/expectations/tests/const_resolved_ty.rs rename to bindgen-tests/tests/expectations/tests/const_resolved_ty.rs diff --git a/tests/expectations/tests/const_tparam.rs b/bindgen-tests/tests/expectations/tests/const_tparam.rs similarity index 100% rename from tests/expectations/tests/const_tparam.rs rename to bindgen-tests/tests/expectations/tests/const_tparam.rs diff --git a/tests/expectations/tests/constant-non-specialized-tp.rs b/bindgen-tests/tests/expectations/tests/constant-non-specialized-tp.rs similarity index 100% rename from tests/expectations/tests/constant-non-specialized-tp.rs rename to bindgen-tests/tests/expectations/tests/constant-non-specialized-tp.rs diff --git a/tests/expectations/tests/constified-enum-module-overflow.rs b/bindgen-tests/tests/expectations/tests/constified-enum-module-overflow.rs similarity index 100% rename from tests/expectations/tests/constified-enum-module-overflow.rs rename to bindgen-tests/tests/expectations/tests/constified-enum-module-overflow.rs diff --git a/tests/expectations/tests/constify-all-enums.rs b/bindgen-tests/tests/expectations/tests/constify-all-enums.rs similarity index 100% rename from tests/expectations/tests/constify-all-enums.rs rename to bindgen-tests/tests/expectations/tests/constify-all-enums.rs diff --git a/tests/expectations/tests/constify-enum.rs b/bindgen-tests/tests/expectations/tests/constify-enum.rs similarity index 100% rename from tests/expectations/tests/constify-enum.rs rename to bindgen-tests/tests/expectations/tests/constify-enum.rs diff --git a/tests/expectations/tests/constify-module-enums-basic.rs b/bindgen-tests/tests/expectations/tests/constify-module-enums-basic.rs similarity index 100% rename from tests/expectations/tests/constify-module-enums-basic.rs rename to bindgen-tests/tests/expectations/tests/constify-module-enums-basic.rs diff --git a/tests/expectations/tests/constify-module-enums-namespace.rs b/bindgen-tests/tests/expectations/tests/constify-module-enums-namespace.rs similarity index 100% rename from tests/expectations/tests/constify-module-enums-namespace.rs rename to bindgen-tests/tests/expectations/tests/constify-module-enums-namespace.rs diff --git a/tests/expectations/tests/constify-module-enums-shadow-name.rs b/bindgen-tests/tests/expectations/tests/constify-module-enums-shadow-name.rs similarity index 100% rename from tests/expectations/tests/constify-module-enums-shadow-name.rs rename to bindgen-tests/tests/expectations/tests/constify-module-enums-shadow-name.rs diff --git a/tests/expectations/tests/constify-module-enums-simple-alias.rs b/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-alias.rs similarity index 100% rename from tests/expectations/tests/constify-module-enums-simple-alias.rs rename to bindgen-tests/tests/expectations/tests/constify-module-enums-simple-alias.rs diff --git a/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs b/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs similarity index 100% rename from tests/expectations/tests/constify-module-enums-simple-nonamespace.rs rename to bindgen-tests/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs diff --git a/tests/expectations/tests/constify-module-enums-types.rs b/bindgen-tests/tests/expectations/tests/constify-module-enums-types.rs similarity index 100% rename from tests/expectations/tests/constify-module-enums-types.rs rename to bindgen-tests/tests/expectations/tests/constify-module-enums-types.rs diff --git a/tests/expectations/tests/constructor-tp.rs b/bindgen-tests/tests/expectations/tests/constructor-tp.rs similarity index 100% rename from tests/expectations/tests/constructor-tp.rs rename to bindgen-tests/tests/expectations/tests/constructor-tp.rs diff --git a/tests/expectations/tests/constructors.rs b/bindgen-tests/tests/expectations/tests/constructors.rs similarity index 100% rename from tests/expectations/tests/constructors.rs rename to bindgen-tests/tests/expectations/tests/constructors.rs diff --git a/tests/expectations/tests/constructors_1_33.rs b/bindgen-tests/tests/expectations/tests/constructors_1_33.rs similarity index 100% rename from tests/expectations/tests/constructors_1_33.rs rename to bindgen-tests/tests/expectations/tests/constructors_1_33.rs diff --git a/tests/expectations/tests/contains-vs-inherits-zero-sized.rs b/bindgen-tests/tests/expectations/tests/contains-vs-inherits-zero-sized.rs similarity index 100% rename from tests/expectations/tests/contains-vs-inherits-zero-sized.rs rename to bindgen-tests/tests/expectations/tests/contains-vs-inherits-zero-sized.rs diff --git a/tests/expectations/tests/convert-cpp-comment-to-rust.rs b/bindgen-tests/tests/expectations/tests/convert-cpp-comment-to-rust.rs similarity index 100% rename from tests/expectations/tests/convert-cpp-comment-to-rust.rs rename to bindgen-tests/tests/expectations/tests/convert-cpp-comment-to-rust.rs diff --git a/tests/expectations/tests/convert-floats.rs b/bindgen-tests/tests/expectations/tests/convert-floats.rs similarity index 100% rename from tests/expectations/tests/convert-floats.rs rename to bindgen-tests/tests/expectations/tests/convert-floats.rs diff --git a/tests/expectations/tests/core_ffi_c.rs b/bindgen-tests/tests/expectations/tests/core_ffi_c.rs similarity index 100% rename from tests/expectations/tests/core_ffi_c.rs rename to bindgen-tests/tests/expectations/tests/core_ffi_c.rs diff --git a/tests/expectations/tests/cpp-empty-layout.rs b/bindgen-tests/tests/expectations/tests/cpp-empty-layout.rs similarity index 100% rename from tests/expectations/tests/cpp-empty-layout.rs rename to bindgen-tests/tests/expectations/tests/cpp-empty-layout.rs diff --git a/tests/expectations/tests/crtp.rs b/bindgen-tests/tests/expectations/tests/crtp.rs similarity index 100% rename from tests/expectations/tests/crtp.rs rename to bindgen-tests/tests/expectations/tests/crtp.rs diff --git a/tests/expectations/tests/ctypes-prefix-path.rs b/bindgen-tests/tests/expectations/tests/ctypes-prefix-path.rs similarity index 100% rename from tests/expectations/tests/ctypes-prefix-path.rs rename to bindgen-tests/tests/expectations/tests/ctypes-prefix-path.rs diff --git a/tests/expectations/tests/dash_language.rs b/bindgen-tests/tests/expectations/tests/dash_language.rs similarity index 100% rename from tests/expectations/tests/dash_language.rs rename to bindgen-tests/tests/expectations/tests/dash_language.rs diff --git a/tests/expectations/tests/decl_extern_int_twice.rs b/bindgen-tests/tests/expectations/tests/decl_extern_int_twice.rs similarity index 100% rename from tests/expectations/tests/decl_extern_int_twice.rs rename to bindgen-tests/tests/expectations/tests/decl_extern_int_twice.rs diff --git a/tests/expectations/tests/decl_ptr_to_array.rs b/bindgen-tests/tests/expectations/tests/decl_ptr_to_array.rs similarity index 100% rename from tests/expectations/tests/decl_ptr_to_array.rs rename to bindgen-tests/tests/expectations/tests/decl_ptr_to_array.rs diff --git a/tests/expectations/tests/default-enum-style-constified-module.rs b/bindgen-tests/tests/expectations/tests/default-enum-style-constified-module.rs similarity index 100% rename from tests/expectations/tests/default-enum-style-constified-module.rs rename to bindgen-tests/tests/expectations/tests/default-enum-style-constified-module.rs diff --git a/tests/expectations/tests/default-macro-constant-type-signed.rs b/bindgen-tests/tests/expectations/tests/default-macro-constant-type-signed.rs similarity index 100% rename from tests/expectations/tests/default-macro-constant-type-signed.rs rename to bindgen-tests/tests/expectations/tests/default-macro-constant-type-signed.rs diff --git a/tests/expectations/tests/default-macro-constant-type-unsigned.rs b/bindgen-tests/tests/expectations/tests/default-macro-constant-type-unsigned.rs similarity index 100% rename from tests/expectations/tests/default-macro-constant-type-unsigned.rs rename to bindgen-tests/tests/expectations/tests/default-macro-constant-type-unsigned.rs diff --git a/tests/expectations/tests/default-macro-constant-type.rs b/bindgen-tests/tests/expectations/tests/default-macro-constant-type.rs similarity index 100% rename from tests/expectations/tests/default-macro-constant-type.rs rename to bindgen-tests/tests/expectations/tests/default-macro-constant-type.rs diff --git a/tests/expectations/tests/default-template-parameter.rs b/bindgen-tests/tests/expectations/tests/default-template-parameter.rs similarity index 100% rename from tests/expectations/tests/default-template-parameter.rs rename to bindgen-tests/tests/expectations/tests/default-template-parameter.rs diff --git a/tests/expectations/tests/deleted-function.rs b/bindgen-tests/tests/expectations/tests/deleted-function.rs similarity index 100% rename from tests/expectations/tests/deleted-function.rs rename to bindgen-tests/tests/expectations/tests/deleted-function.rs diff --git a/tests/expectations/tests/derive-bitfield-method-same-name.rs b/bindgen-tests/tests/expectations/tests/derive-bitfield-method-same-name.rs similarity index 100% rename from tests/expectations/tests/derive-bitfield-method-same-name.rs rename to bindgen-tests/tests/expectations/tests/derive-bitfield-method-same-name.rs diff --git a/tests/expectations/tests/derive-clone.rs b/bindgen-tests/tests/expectations/tests/derive-clone.rs similarity index 100% rename from tests/expectations/tests/derive-clone.rs rename to bindgen-tests/tests/expectations/tests/derive-clone.rs diff --git a/tests/expectations/tests/derive-clone_1_0.rs b/bindgen-tests/tests/expectations/tests/derive-clone_1_0.rs similarity index 100% rename from tests/expectations/tests/derive-clone_1_0.rs rename to bindgen-tests/tests/expectations/tests/derive-clone_1_0.rs diff --git a/tests/expectations/tests/derive-custom.rs b/bindgen-tests/tests/expectations/tests/derive-custom.rs similarity index 100% rename from tests/expectations/tests/derive-custom.rs rename to bindgen-tests/tests/expectations/tests/derive-custom.rs diff --git a/tests/expectations/tests/derive-debug-bitfield-core.rs b/bindgen-tests/tests/expectations/tests/derive-debug-bitfield-core.rs similarity index 100% rename from tests/expectations/tests/derive-debug-bitfield-core.rs rename to bindgen-tests/tests/expectations/tests/derive-debug-bitfield-core.rs diff --git a/tests/expectations/tests/derive-debug-bitfield.rs b/bindgen-tests/tests/expectations/tests/derive-debug-bitfield.rs similarity index 100% rename from tests/expectations/tests/derive-debug-bitfield.rs rename to bindgen-tests/tests/expectations/tests/derive-debug-bitfield.rs diff --git a/tests/expectations/tests/derive-debug-function-pointer.rs b/bindgen-tests/tests/expectations/tests/derive-debug-function-pointer.rs similarity index 100% rename from tests/expectations/tests/derive-debug-function-pointer.rs rename to bindgen-tests/tests/expectations/tests/derive-debug-function-pointer.rs diff --git a/tests/expectations/tests/derive-debug-generic.rs b/bindgen-tests/tests/expectations/tests/derive-debug-generic.rs similarity index 100% rename from tests/expectations/tests/derive-debug-generic.rs rename to bindgen-tests/tests/expectations/tests/derive-debug-generic.rs diff --git a/tests/expectations/tests/derive-debug-mangle-name.rs b/bindgen-tests/tests/expectations/tests/derive-debug-mangle-name.rs similarity index 100% rename from tests/expectations/tests/derive-debug-mangle-name.rs rename to bindgen-tests/tests/expectations/tests/derive-debug-mangle-name.rs diff --git a/tests/expectations/tests/derive-debug-opaque-template-instantiation.rs b/bindgen-tests/tests/expectations/tests/derive-debug-opaque-template-instantiation.rs similarity index 100% rename from tests/expectations/tests/derive-debug-opaque-template-instantiation.rs rename to bindgen-tests/tests/expectations/tests/derive-debug-opaque-template-instantiation.rs diff --git a/tests/expectations/tests/derive-debug-opaque.rs b/bindgen-tests/tests/expectations/tests/derive-debug-opaque.rs similarity index 100% rename from tests/expectations/tests/derive-debug-opaque.rs rename to bindgen-tests/tests/expectations/tests/derive-debug-opaque.rs diff --git a/tests/expectations/tests/derive-default-and-blocklist.rs b/bindgen-tests/tests/expectations/tests/derive-default-and-blocklist.rs similarity index 100% rename from tests/expectations/tests/derive-default-and-blocklist.rs rename to bindgen-tests/tests/expectations/tests/derive-default-and-blocklist.rs diff --git a/tests/expectations/tests/derive-fn-ptr.rs b/bindgen-tests/tests/expectations/tests/derive-fn-ptr.rs similarity index 100% rename from tests/expectations/tests/derive-fn-ptr.rs rename to bindgen-tests/tests/expectations/tests/derive-fn-ptr.rs diff --git a/tests/expectations/tests/derive-hash-and-blocklist.rs b/bindgen-tests/tests/expectations/tests/derive-hash-and-blocklist.rs similarity index 100% rename from tests/expectations/tests/derive-hash-and-blocklist.rs rename to bindgen-tests/tests/expectations/tests/derive-hash-and-blocklist.rs diff --git a/tests/expectations/tests/derive-hash-blocklisting.rs b/bindgen-tests/tests/expectations/tests/derive-hash-blocklisting.rs similarity index 100% rename from tests/expectations/tests/derive-hash-blocklisting.rs rename to bindgen-tests/tests/expectations/tests/derive-hash-blocklisting.rs diff --git a/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs similarity index 100% rename from tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs rename to bindgen-tests/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs diff --git a/tests/expectations/tests/derive-hash-struct-with-float-array.rs b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-float-array.rs similarity index 100% rename from tests/expectations/tests/derive-hash-struct-with-float-array.rs rename to bindgen-tests/tests/expectations/tests/derive-hash-struct-with-float-array.rs diff --git a/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs similarity index 100% rename from tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs rename to bindgen-tests/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs diff --git a/tests/expectations/tests/derive-hash-struct-with-pointer.rs b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-pointer.rs similarity index 100% rename from tests/expectations/tests/derive-hash-struct-with-pointer.rs rename to bindgen-tests/tests/expectations/tests/derive-hash-struct-with-pointer.rs diff --git a/tests/expectations/tests/derive-hash-template-def-float.rs b/bindgen-tests/tests/expectations/tests/derive-hash-template-def-float.rs similarity index 100% rename from tests/expectations/tests/derive-hash-template-def-float.rs rename to bindgen-tests/tests/expectations/tests/derive-hash-template-def-float.rs diff --git a/tests/expectations/tests/derive-hash-template-inst-float.rs b/bindgen-tests/tests/expectations/tests/derive-hash-template-inst-float.rs similarity index 100% rename from tests/expectations/tests/derive-hash-template-inst-float.rs rename to bindgen-tests/tests/expectations/tests/derive-hash-template-inst-float.rs diff --git a/tests/expectations/tests/derive-partialeq-and-blocklist.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-and-blocklist.rs similarity index 100% rename from tests/expectations/tests/derive-partialeq-and-blocklist.rs rename to bindgen-tests/tests/expectations/tests/derive-partialeq-and-blocklist.rs diff --git a/tests/expectations/tests/derive-partialeq-anonfield.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-anonfield.rs similarity index 100% rename from tests/expectations/tests/derive-partialeq-anonfield.rs rename to bindgen-tests/tests/expectations/tests/derive-partialeq-anonfield.rs diff --git a/tests/expectations/tests/derive-partialeq-base.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-base.rs similarity index 100% rename from tests/expectations/tests/derive-partialeq-base.rs rename to bindgen-tests/tests/expectations/tests/derive-partialeq-base.rs diff --git a/tests/expectations/tests/derive-partialeq-bitfield.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-bitfield.rs similarity index 100% rename from tests/expectations/tests/derive-partialeq-bitfield.rs rename to bindgen-tests/tests/expectations/tests/derive-partialeq-bitfield.rs diff --git a/tests/expectations/tests/derive-partialeq-core.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-core.rs similarity index 100% rename from tests/expectations/tests/derive-partialeq-core.rs rename to bindgen-tests/tests/expectations/tests/derive-partialeq-core.rs diff --git a/tests/expectations/tests/derive-partialeq-pointer.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-pointer.rs similarity index 100% rename from tests/expectations/tests/derive-partialeq-pointer.rs rename to bindgen-tests/tests/expectations/tests/derive-partialeq-pointer.rs diff --git a/tests/expectations/tests/derive-partialeq-union.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-union.rs similarity index 100% rename from tests/expectations/tests/derive-partialeq-union.rs rename to bindgen-tests/tests/expectations/tests/derive-partialeq-union.rs diff --git a/tests/expectations/tests/derive-partialeq-union_1_0.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-union_1_0.rs similarity index 100% rename from tests/expectations/tests/derive-partialeq-union_1_0.rs rename to bindgen-tests/tests/expectations/tests/derive-partialeq-union_1_0.rs diff --git a/tests/expectations/tests/disable-namespacing.rs b/bindgen-tests/tests/expectations/tests/disable-namespacing.rs similarity index 100% rename from tests/expectations/tests/disable-namespacing.rs rename to bindgen-tests/tests/expectations/tests/disable-namespacing.rs diff --git a/tests/expectations/tests/disable-nested-struct-naming.rs b/bindgen-tests/tests/expectations/tests/disable-nested-struct-naming.rs similarity index 100% rename from tests/expectations/tests/disable-nested-struct-naming.rs rename to bindgen-tests/tests/expectations/tests/disable-nested-struct-naming.rs diff --git a/tests/expectations/tests/disable-untagged-union.rs b/bindgen-tests/tests/expectations/tests/disable-untagged-union.rs similarity index 100% rename from tests/expectations/tests/disable-untagged-union.rs rename to bindgen-tests/tests/expectations/tests/disable-untagged-union.rs diff --git a/tests/expectations/tests/divide-by-zero-in-struct-layout.rs b/bindgen-tests/tests/expectations/tests/divide-by-zero-in-struct-layout.rs similarity index 100% rename from tests/expectations/tests/divide-by-zero-in-struct-layout.rs rename to bindgen-tests/tests/expectations/tests/divide-by-zero-in-struct-layout.rs diff --git a/tests/expectations/tests/do-not-derive-copy.rs b/bindgen-tests/tests/expectations/tests/do-not-derive-copy.rs similarity index 100% rename from tests/expectations/tests/do-not-derive-copy.rs rename to bindgen-tests/tests/expectations/tests/do-not-derive-copy.rs diff --git a/tests/expectations/tests/doggo-or-null.rs b/bindgen-tests/tests/expectations/tests/doggo-or-null.rs similarity index 100% rename from tests/expectations/tests/doggo-or-null.rs rename to bindgen-tests/tests/expectations/tests/doggo-or-null.rs diff --git a/tests/expectations/tests/dupe-enum-variant-in-namespace.rs b/bindgen-tests/tests/expectations/tests/dupe-enum-variant-in-namespace.rs similarity index 100% rename from tests/expectations/tests/dupe-enum-variant-in-namespace.rs rename to bindgen-tests/tests/expectations/tests/dupe-enum-variant-in-namespace.rs diff --git a/tests/expectations/tests/duplicated-namespaces-definitions.rs b/bindgen-tests/tests/expectations/tests/duplicated-namespaces-definitions.rs similarity index 100% rename from tests/expectations/tests/duplicated-namespaces-definitions.rs rename to bindgen-tests/tests/expectations/tests/duplicated-namespaces-definitions.rs diff --git a/tests/expectations/tests/duplicated-namespaces.rs b/bindgen-tests/tests/expectations/tests/duplicated-namespaces.rs similarity index 100% rename from tests/expectations/tests/duplicated-namespaces.rs rename to bindgen-tests/tests/expectations/tests/duplicated-namespaces.rs diff --git a/tests/expectations/tests/duplicated_constants_in_ns.rs b/bindgen-tests/tests/expectations/tests/duplicated_constants_in_ns.rs similarity index 100% rename from tests/expectations/tests/duplicated_constants_in_ns.rs rename to bindgen-tests/tests/expectations/tests/duplicated_constants_in_ns.rs diff --git a/tests/expectations/tests/dynamic_loading_attributes.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_attributes.rs similarity index 91% rename from tests/expectations/tests/dynamic_loading_attributes.rs rename to bindgen-tests/tests/expectations/tests/dynamic_loading_attributes.rs index b50fbd08c4..c834752e3c 100644 --- a/tests/expectations/tests/dynamic_loading_attributes.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_attributes.rs @@ -38,11 +38,11 @@ impl TestLib { }) } #[must_use] - #[doc = " @brief A function"] - #[doc = ""] - #[doc = " @param x"] - #[doc = " @param y"] - #[doc = " @return int"] + /// @brief A function + /// + /// @param x + /// @param y + /// @return int pub unsafe fn foo( &self, x: ::std::os::raw::c_int, diff --git a/tests/expectations/tests/dynamic_loading_required.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_required.rs similarity index 100% rename from tests/expectations/tests/dynamic_loading_required.rs rename to bindgen-tests/tests/expectations/tests/dynamic_loading_required.rs diff --git a/tests/expectations/tests/dynamic_loading_simple.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_simple.rs similarity index 100% rename from tests/expectations/tests/dynamic_loading_simple.rs rename to bindgen-tests/tests/expectations/tests/dynamic_loading_simple.rs diff --git a/tests/expectations/tests/dynamic_loading_template.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_template.rs similarity index 100% rename from tests/expectations/tests/dynamic_loading_template.rs rename to bindgen-tests/tests/expectations/tests/dynamic_loading_template.rs diff --git a/tests/expectations/tests/dynamic_loading_with_allowlist.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_allowlist.rs similarity index 100% rename from tests/expectations/tests/dynamic_loading_with_allowlist.rs rename to bindgen-tests/tests/expectations/tests/dynamic_loading_with_allowlist.rs diff --git a/tests/expectations/tests/dynamic_loading_with_blocklist.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_blocklist.rs similarity index 100% rename from tests/expectations/tests/dynamic_loading_with_blocklist.rs rename to bindgen-tests/tests/expectations/tests/dynamic_loading_with_blocklist.rs diff --git a/tests/expectations/tests/dynamic_loading_with_class.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs similarity index 100% rename from tests/expectations/tests/dynamic_loading_with_class.rs rename to bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs diff --git a/tests/expectations/tests/elaborated.rs b/bindgen-tests/tests/expectations/tests/elaborated.rs similarity index 100% rename from tests/expectations/tests/elaborated.rs rename to bindgen-tests/tests/expectations/tests/elaborated.rs diff --git a/tests/expectations/tests/empty-enum.rs b/bindgen-tests/tests/expectations/tests/empty-enum.rs similarity index 100% rename from tests/expectations/tests/empty-enum.rs rename to bindgen-tests/tests/expectations/tests/empty-enum.rs diff --git a/tests/expectations/tests/empty-union.rs b/bindgen-tests/tests/expectations/tests/empty-union.rs similarity index 100% rename from tests/expectations/tests/empty-union.rs rename to bindgen-tests/tests/expectations/tests/empty-union.rs diff --git a/tests/expectations/tests/empty_template_param_name.rs b/bindgen-tests/tests/expectations/tests/empty_template_param_name.rs similarity index 100% rename from tests/expectations/tests/empty_template_param_name.rs rename to bindgen-tests/tests/expectations/tests/empty_template_param_name.rs diff --git a/tests/expectations/tests/enum-default-bitfield.rs b/bindgen-tests/tests/expectations/tests/enum-default-bitfield.rs similarity index 100% rename from tests/expectations/tests/enum-default-bitfield.rs rename to bindgen-tests/tests/expectations/tests/enum-default-bitfield.rs diff --git a/tests/expectations/tests/enum-default-consts.rs b/bindgen-tests/tests/expectations/tests/enum-default-consts.rs similarity index 100% rename from tests/expectations/tests/enum-default-consts.rs rename to bindgen-tests/tests/expectations/tests/enum-default-consts.rs diff --git a/tests/expectations/tests/enum-default-module.rs b/bindgen-tests/tests/expectations/tests/enum-default-module.rs similarity index 100% rename from tests/expectations/tests/enum-default-module.rs rename to bindgen-tests/tests/expectations/tests/enum-default-module.rs diff --git a/tests/expectations/tests/enum-default-rust.d b/bindgen-tests/tests/expectations/tests/enum-default-rust.d similarity index 100% rename from tests/expectations/tests/enum-default-rust.d rename to bindgen-tests/tests/expectations/tests/enum-default-rust.d diff --git a/tests/expectations/tests/enum-default-rust.rs b/bindgen-tests/tests/expectations/tests/enum-default-rust.rs similarity index 100% rename from tests/expectations/tests/enum-default-rust.rs rename to bindgen-tests/tests/expectations/tests/enum-default-rust.rs diff --git a/tests/expectations/tests/enum-doc-bitfield.rs b/bindgen-tests/tests/expectations/tests/enum-doc-bitfield.rs similarity index 100% rename from tests/expectations/tests/enum-doc-bitfield.rs rename to bindgen-tests/tests/expectations/tests/enum-doc-bitfield.rs diff --git a/tests/expectations/tests/enum-doc-mod.rs b/bindgen-tests/tests/expectations/tests/enum-doc-mod.rs similarity index 100% rename from tests/expectations/tests/enum-doc-mod.rs rename to bindgen-tests/tests/expectations/tests/enum-doc-mod.rs diff --git a/tests/expectations/tests/enum-doc-rusty.rs b/bindgen-tests/tests/expectations/tests/enum-doc-rusty.rs similarity index 100% rename from tests/expectations/tests/enum-doc-rusty.rs rename to bindgen-tests/tests/expectations/tests/enum-doc-rusty.rs diff --git a/tests/expectations/tests/enum-doc.rs b/bindgen-tests/tests/expectations/tests/enum-doc.rs similarity index 100% rename from tests/expectations/tests/enum-doc.rs rename to bindgen-tests/tests/expectations/tests/enum-doc.rs diff --git a/tests/expectations/tests/enum-no-debug-rust.rs b/bindgen-tests/tests/expectations/tests/enum-no-debug-rust.rs similarity index 100% rename from tests/expectations/tests/enum-no-debug-rust.rs rename to bindgen-tests/tests/expectations/tests/enum-no-debug-rust.rs diff --git a/tests/expectations/tests/enum-translate-type.rs b/bindgen-tests/tests/expectations/tests/enum-translate-type.rs similarity index 100% rename from tests/expectations/tests/enum-translate-type.rs rename to bindgen-tests/tests/expectations/tests/enum-translate-type.rs diff --git a/tests/expectations/tests/enum-undefault.rs b/bindgen-tests/tests/expectations/tests/enum-undefault.rs similarity index 100% rename from tests/expectations/tests/enum-undefault.rs rename to bindgen-tests/tests/expectations/tests/enum-undefault.rs diff --git a/tests/expectations/tests/enum-variant-replaces.rs b/bindgen-tests/tests/expectations/tests/enum-variant-replaces.rs similarity index 100% rename from tests/expectations/tests/enum-variant-replaces.rs rename to bindgen-tests/tests/expectations/tests/enum-variant-replaces.rs diff --git a/tests/expectations/tests/enum.rs b/bindgen-tests/tests/expectations/tests/enum.rs similarity index 100% rename from tests/expectations/tests/enum.rs rename to bindgen-tests/tests/expectations/tests/enum.rs diff --git a/tests/expectations/tests/enum_alias.rs b/bindgen-tests/tests/expectations/tests/enum_alias.rs similarity index 100% rename from tests/expectations/tests/enum_alias.rs rename to bindgen-tests/tests/expectations/tests/enum_alias.rs diff --git a/tests/expectations/tests/enum_and_vtable_mangling.rs b/bindgen-tests/tests/expectations/tests/enum_and_vtable_mangling.rs similarity index 100% rename from tests/expectations/tests/enum_and_vtable_mangling.rs rename to bindgen-tests/tests/expectations/tests/enum_and_vtable_mangling.rs diff --git a/tests/expectations/tests/enum_dupe.rs b/bindgen-tests/tests/expectations/tests/enum_dupe.rs similarity index 100% rename from tests/expectations/tests/enum_dupe.rs rename to bindgen-tests/tests/expectations/tests/enum_dupe.rs diff --git a/tests/expectations/tests/enum_explicit_type.rs b/bindgen-tests/tests/expectations/tests/enum_explicit_type.rs similarity index 100% rename from tests/expectations/tests/enum_explicit_type.rs rename to bindgen-tests/tests/expectations/tests/enum_explicit_type.rs diff --git a/tests/expectations/tests/enum_explicit_type_constants.rs b/bindgen-tests/tests/expectations/tests/enum_explicit_type_constants.rs similarity index 100% rename from tests/expectations/tests/enum_explicit_type_constants.rs rename to bindgen-tests/tests/expectations/tests/enum_explicit_type_constants.rs diff --git a/tests/expectations/tests/enum_in_template.rs b/bindgen-tests/tests/expectations/tests/enum_in_template.rs similarity index 100% rename from tests/expectations/tests/enum_in_template.rs rename to bindgen-tests/tests/expectations/tests/enum_in_template.rs diff --git a/tests/expectations/tests/enum_in_template_with_typedef.rs b/bindgen-tests/tests/expectations/tests/enum_in_template_with_typedef.rs similarity index 100% rename from tests/expectations/tests/enum_in_template_with_typedef.rs rename to bindgen-tests/tests/expectations/tests/enum_in_template_with_typedef.rs diff --git a/tests/expectations/tests/enum_negative.rs b/bindgen-tests/tests/expectations/tests/enum_negative.rs similarity index 100% rename from tests/expectations/tests/enum_negative.rs rename to bindgen-tests/tests/expectations/tests/enum_negative.rs diff --git a/tests/expectations/tests/enum_packed.rs b/bindgen-tests/tests/expectations/tests/enum_packed.rs similarity index 100% rename from tests/expectations/tests/enum_packed.rs rename to bindgen-tests/tests/expectations/tests/enum_packed.rs diff --git a/tests/expectations/tests/eval-value-dependent.rs b/bindgen-tests/tests/expectations/tests/eval-value-dependent.rs similarity index 100% rename from tests/expectations/tests/eval-value-dependent.rs rename to bindgen-tests/tests/expectations/tests/eval-value-dependent.rs diff --git a/tests/expectations/tests/eval-variadic-template-parameter.rs b/bindgen-tests/tests/expectations/tests/eval-variadic-template-parameter.rs similarity index 100% rename from tests/expectations/tests/eval-variadic-template-parameter.rs rename to bindgen-tests/tests/expectations/tests/eval-variadic-template-parameter.rs diff --git a/tests/expectations/tests/explicit-padding.rs b/bindgen-tests/tests/expectations/tests/explicit-padding.rs similarity index 100% rename from tests/expectations/tests/explicit-padding.rs rename to bindgen-tests/tests/expectations/tests/explicit-padding.rs diff --git a/tests/expectations/tests/extern-const-struct.rs b/bindgen-tests/tests/expectations/tests/extern-const-struct.rs similarity index 100% rename from tests/expectations/tests/extern-const-struct.rs rename to bindgen-tests/tests/expectations/tests/extern-const-struct.rs diff --git a/tests/expectations/tests/extern.rs b/bindgen-tests/tests/expectations/tests/extern.rs similarity index 100% rename from tests/expectations/tests/extern.rs rename to bindgen-tests/tests/expectations/tests/extern.rs diff --git a/tests/expectations/tests/fit-macro-constant-types-signed.rs b/bindgen-tests/tests/expectations/tests/fit-macro-constant-types-signed.rs similarity index 100% rename from tests/expectations/tests/fit-macro-constant-types-signed.rs rename to bindgen-tests/tests/expectations/tests/fit-macro-constant-types-signed.rs diff --git a/tests/expectations/tests/fit-macro-constant-types.rs b/bindgen-tests/tests/expectations/tests/fit-macro-constant-types.rs similarity index 100% rename from tests/expectations/tests/fit-macro-constant-types.rs rename to bindgen-tests/tests/expectations/tests/fit-macro-constant-types.rs diff --git a/tests/expectations/tests/float128.rs b/bindgen-tests/tests/expectations/tests/float128.rs similarity index 100% rename from tests/expectations/tests/float128.rs rename to bindgen-tests/tests/expectations/tests/float128.rs diff --git a/tests/expectations/tests/forward-declaration-autoptr.rs b/bindgen-tests/tests/expectations/tests/forward-declaration-autoptr.rs similarity index 100% rename from tests/expectations/tests/forward-declaration-autoptr.rs rename to bindgen-tests/tests/expectations/tests/forward-declaration-autoptr.rs diff --git a/tests/expectations/tests/forward-enum-decl.rs b/bindgen-tests/tests/expectations/tests/forward-enum-decl.rs similarity index 100% rename from tests/expectations/tests/forward-enum-decl.rs rename to bindgen-tests/tests/expectations/tests/forward-enum-decl.rs diff --git a/tests/expectations/tests/forward-inherit-struct-with-fields.rs b/bindgen-tests/tests/expectations/tests/forward-inherit-struct-with-fields.rs similarity index 100% rename from tests/expectations/tests/forward-inherit-struct-with-fields.rs rename to bindgen-tests/tests/expectations/tests/forward-inherit-struct-with-fields.rs diff --git a/tests/expectations/tests/forward-inherit-struct.rs b/bindgen-tests/tests/expectations/tests/forward-inherit-struct.rs similarity index 100% rename from tests/expectations/tests/forward-inherit-struct.rs rename to bindgen-tests/tests/expectations/tests/forward-inherit-struct.rs diff --git a/tests/expectations/tests/forward_declared_complex_types.rs b/bindgen-tests/tests/expectations/tests/forward_declared_complex_types.rs similarity index 100% rename from tests/expectations/tests/forward_declared_complex_types.rs rename to bindgen-tests/tests/expectations/tests/forward_declared_complex_types.rs diff --git a/tests/expectations/tests/forward_declared_complex_types_1_0.rs b/bindgen-tests/tests/expectations/tests/forward_declared_complex_types_1_0.rs similarity index 100% rename from tests/expectations/tests/forward_declared_complex_types_1_0.rs rename to bindgen-tests/tests/expectations/tests/forward_declared_complex_types_1_0.rs diff --git a/tests/expectations/tests/forward_declared_opaque.rs b/bindgen-tests/tests/expectations/tests/forward_declared_opaque.rs similarity index 100% rename from tests/expectations/tests/forward_declared_opaque.rs rename to bindgen-tests/tests/expectations/tests/forward_declared_opaque.rs diff --git a/tests/expectations/tests/forward_declared_struct.rs b/bindgen-tests/tests/expectations/tests/forward_declared_struct.rs similarity index 100% rename from tests/expectations/tests/forward_declared_struct.rs rename to bindgen-tests/tests/expectations/tests/forward_declared_struct.rs diff --git a/tests/expectations/tests/func_proto.rs b/bindgen-tests/tests/expectations/tests/func_proto.rs similarity index 100% rename from tests/expectations/tests/func_proto.rs rename to bindgen-tests/tests/expectations/tests/func_proto.rs diff --git a/tests/expectations/tests/func_ptr.rs b/bindgen-tests/tests/expectations/tests/func_ptr.rs similarity index 100% rename from tests/expectations/tests/func_ptr.rs rename to bindgen-tests/tests/expectations/tests/func_ptr.rs diff --git a/tests/expectations/tests/func_ptr_in_struct.rs b/bindgen-tests/tests/expectations/tests/func_ptr_in_struct.rs similarity index 100% rename from tests/expectations/tests/func_ptr_in_struct.rs rename to bindgen-tests/tests/expectations/tests/func_ptr_in_struct.rs diff --git a/tests/expectations/tests/func_ptr_return_type.rs b/bindgen-tests/tests/expectations/tests/func_ptr_return_type.rs similarity index 100% rename from tests/expectations/tests/func_ptr_return_type.rs rename to bindgen-tests/tests/expectations/tests/func_ptr_return_type.rs diff --git a/tests/expectations/tests/func_return_must_use.rs b/bindgen-tests/tests/expectations/tests/func_return_must_use.rs similarity index 100% rename from tests/expectations/tests/func_return_must_use.rs rename to bindgen-tests/tests/expectations/tests/func_return_must_use.rs diff --git a/tests/expectations/tests/func_with_array_arg.rs b/bindgen-tests/tests/expectations/tests/func_with_array_arg.rs similarity index 100% rename from tests/expectations/tests/func_with_array_arg.rs rename to bindgen-tests/tests/expectations/tests/func_with_array_arg.rs diff --git a/tests/expectations/tests/func_with_func_ptr_arg.rs b/bindgen-tests/tests/expectations/tests/func_with_func_ptr_arg.rs similarity index 100% rename from tests/expectations/tests/func_with_func_ptr_arg.rs rename to bindgen-tests/tests/expectations/tests/func_with_func_ptr_arg.rs diff --git a/tests/expectations/tests/function-typedef-stdcall.rs b/bindgen-tests/tests/expectations/tests/function-typedef-stdcall.rs similarity index 100% rename from tests/expectations/tests/function-typedef-stdcall.rs rename to bindgen-tests/tests/expectations/tests/function-typedef-stdcall.rs diff --git a/tests/expectations/tests/gen-constructors-neg.rs b/bindgen-tests/tests/expectations/tests/gen-constructors-neg.rs similarity index 100% rename from tests/expectations/tests/gen-constructors-neg.rs rename to bindgen-tests/tests/expectations/tests/gen-constructors-neg.rs diff --git a/tests/expectations/tests/gen-constructors.rs b/bindgen-tests/tests/expectations/tests/gen-constructors.rs similarity index 100% rename from tests/expectations/tests/gen-constructors.rs rename to bindgen-tests/tests/expectations/tests/gen-constructors.rs diff --git a/tests/expectations/tests/gen-destructors-neg.rs b/bindgen-tests/tests/expectations/tests/gen-destructors-neg.rs similarity index 100% rename from tests/expectations/tests/gen-destructors-neg.rs rename to bindgen-tests/tests/expectations/tests/gen-destructors-neg.rs diff --git a/tests/expectations/tests/gen-destructors.rs b/bindgen-tests/tests/expectations/tests/gen-destructors.rs similarity index 100% rename from tests/expectations/tests/gen-destructors.rs rename to bindgen-tests/tests/expectations/tests/gen-destructors.rs diff --git a/tests/expectations/tests/generate-inline.rs b/bindgen-tests/tests/expectations/tests/generate-inline.rs similarity index 100% rename from tests/expectations/tests/generate-inline.rs rename to bindgen-tests/tests/expectations/tests/generate-inline.rs diff --git a/tests/expectations/tests/i128.rs b/bindgen-tests/tests/expectations/tests/i128.rs similarity index 100% rename from tests/expectations/tests/i128.rs rename to bindgen-tests/tests/expectations/tests/i128.rs diff --git a/tests/expectations/tests/in_class_typedef.rs b/bindgen-tests/tests/expectations/tests/in_class_typedef.rs similarity index 100% rename from tests/expectations/tests/in_class_typedef.rs rename to bindgen-tests/tests/expectations/tests/in_class_typedef.rs diff --git a/tests/expectations/tests/incomplete-array-padding.rs b/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs similarity index 100% rename from tests/expectations/tests/incomplete-array-padding.rs rename to bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs diff --git a/tests/expectations/tests/infinite-macro.rs b/bindgen-tests/tests/expectations/tests/infinite-macro.rs similarity index 100% rename from tests/expectations/tests/infinite-macro.rs rename to bindgen-tests/tests/expectations/tests/infinite-macro.rs diff --git a/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs b/bindgen-tests/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs similarity index 100% rename from tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs rename to bindgen-tests/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs diff --git a/tests/expectations/tests/inherit-namespaced.rs b/bindgen-tests/tests/expectations/tests/inherit-namespaced.rs similarity index 100% rename from tests/expectations/tests/inherit-namespaced.rs rename to bindgen-tests/tests/expectations/tests/inherit-namespaced.rs diff --git a/tests/expectations/tests/inherit_named.rs b/bindgen-tests/tests/expectations/tests/inherit_named.rs similarity index 100% rename from tests/expectations/tests/inherit_named.rs rename to bindgen-tests/tests/expectations/tests/inherit_named.rs diff --git a/tests/expectations/tests/inherit_typedef.rs b/bindgen-tests/tests/expectations/tests/inherit_typedef.rs similarity index 100% rename from tests/expectations/tests/inherit_typedef.rs rename to bindgen-tests/tests/expectations/tests/inherit_typedef.rs diff --git a/tests/expectations/tests/inline-function.rs b/bindgen-tests/tests/expectations/tests/inline-function.rs similarity index 100% rename from tests/expectations/tests/inline-function.rs rename to bindgen-tests/tests/expectations/tests/inline-function.rs diff --git a/tests/expectations/tests/inline_namespace.rs b/bindgen-tests/tests/expectations/tests/inline_namespace.rs similarity index 100% rename from tests/expectations/tests/inline_namespace.rs rename to bindgen-tests/tests/expectations/tests/inline_namespace.rs diff --git a/tests/expectations/tests/inline_namespace_allowlist.rs b/bindgen-tests/tests/expectations/tests/inline_namespace_allowlist.rs similarity index 100% rename from tests/expectations/tests/inline_namespace_allowlist.rs rename to bindgen-tests/tests/expectations/tests/inline_namespace_allowlist.rs diff --git a/tests/expectations/tests/inline_namespace_conservative.rs b/bindgen-tests/tests/expectations/tests/inline_namespace_conservative.rs similarity index 100% rename from tests/expectations/tests/inline_namespace_conservative.rs rename to bindgen-tests/tests/expectations/tests/inline_namespace_conservative.rs diff --git a/tests/expectations/tests/inline_namespace_no_ns_enabled.rs b/bindgen-tests/tests/expectations/tests/inline_namespace_no_ns_enabled.rs similarity index 100% rename from tests/expectations/tests/inline_namespace_no_ns_enabled.rs rename to bindgen-tests/tests/expectations/tests/inline_namespace_no_ns_enabled.rs diff --git a/tests/expectations/tests/inner-typedef-gh422.rs b/bindgen-tests/tests/expectations/tests/inner-typedef-gh422.rs similarity index 100% rename from tests/expectations/tests/inner-typedef-gh422.rs rename to bindgen-tests/tests/expectations/tests/inner-typedef-gh422.rs diff --git a/tests/expectations/tests/inner_const.rs b/bindgen-tests/tests/expectations/tests/inner_const.rs similarity index 100% rename from tests/expectations/tests/inner_const.rs rename to bindgen-tests/tests/expectations/tests/inner_const.rs diff --git a/tests/expectations/tests/inner_template_self.rs b/bindgen-tests/tests/expectations/tests/inner_template_self.rs similarity index 100% rename from tests/expectations/tests/inner_template_self.rs rename to bindgen-tests/tests/expectations/tests/inner_template_self.rs diff --git a/tests/expectations/tests/int128_t.rs b/bindgen-tests/tests/expectations/tests/int128_t.rs similarity index 100% rename from tests/expectations/tests/int128_t.rs rename to bindgen-tests/tests/expectations/tests/int128_t.rs diff --git a/tests/expectations/tests/issue-1025-unknown-enum-repr.rs b/bindgen-tests/tests/expectations/tests/issue-1025-unknown-enum-repr.rs similarity index 100% rename from tests/expectations/tests/issue-1025-unknown-enum-repr.rs rename to bindgen-tests/tests/expectations/tests/issue-1025-unknown-enum-repr.rs diff --git a/tests/expectations/tests/issue-1034.rs b/bindgen-tests/tests/expectations/tests/issue-1034.rs similarity index 100% rename from tests/expectations/tests/issue-1034.rs rename to bindgen-tests/tests/expectations/tests/issue-1034.rs diff --git a/tests/expectations/tests/issue-1040.rs b/bindgen-tests/tests/expectations/tests/issue-1040.rs similarity index 100% rename from tests/expectations/tests/issue-1040.rs rename to bindgen-tests/tests/expectations/tests/issue-1040.rs diff --git a/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs b/bindgen-tests/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs similarity index 100% rename from tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs rename to bindgen-tests/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs diff --git a/tests/expectations/tests/issue-1113-template-references.rs b/bindgen-tests/tests/expectations/tests/issue-1113-template-references.rs similarity index 100% rename from tests/expectations/tests/issue-1113-template-references.rs rename to bindgen-tests/tests/expectations/tests/issue-1113-template-references.rs diff --git a/tests/expectations/tests/issue-1118-using-forward-decl.rs b/bindgen-tests/tests/expectations/tests/issue-1118-using-forward-decl.rs similarity index 100% rename from tests/expectations/tests/issue-1118-using-forward-decl.rs rename to bindgen-tests/tests/expectations/tests/issue-1118-using-forward-decl.rs diff --git a/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs b/bindgen-tests/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs similarity index 100% rename from tests/expectations/tests/issue-1197-pure-virtual-stuff.rs rename to bindgen-tests/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs diff --git a/tests/expectations/tests/issue-1198-alias-rust-bitfield-enum.rs b/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-bitfield-enum.rs similarity index 100% rename from tests/expectations/tests/issue-1198-alias-rust-bitfield-enum.rs rename to bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-bitfield-enum.rs diff --git a/tests/expectations/tests/issue-1198-alias-rust-const-mod-bitfield-enum.rs b/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-const-mod-bitfield-enum.rs similarity index 100% rename from tests/expectations/tests/issue-1198-alias-rust-const-mod-bitfield-enum.rs rename to bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-const-mod-bitfield-enum.rs diff --git a/tests/expectations/tests/issue-1198-alias-rust-const-mod-enum.rs b/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-const-mod-enum.rs similarity index 100% rename from tests/expectations/tests/issue-1198-alias-rust-const-mod-enum.rs rename to bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-const-mod-enum.rs diff --git a/tests/expectations/tests/issue-1198-alias-rust-enum.rs b/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-enum.rs similarity index 100% rename from tests/expectations/tests/issue-1198-alias-rust-enum.rs rename to bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-enum.rs diff --git a/tests/expectations/tests/issue-1216-variadic-member.rs b/bindgen-tests/tests/expectations/tests/issue-1216-variadic-member.rs similarity index 100% rename from tests/expectations/tests/issue-1216-variadic-member.rs rename to bindgen-tests/tests/expectations/tests/issue-1216-variadic-member.rs diff --git a/tests/expectations/tests/issue-1238-fwd-no-copy.rs b/bindgen-tests/tests/expectations/tests/issue-1238-fwd-no-copy.rs similarity index 100% rename from tests/expectations/tests/issue-1238-fwd-no-copy.rs rename to bindgen-tests/tests/expectations/tests/issue-1238-fwd-no-copy.rs diff --git a/tests/expectations/tests/issue-1281.rs b/bindgen-tests/tests/expectations/tests/issue-1281.rs similarity index 100% rename from tests/expectations/tests/issue-1281.rs rename to bindgen-tests/tests/expectations/tests/issue-1281.rs diff --git a/tests/expectations/tests/issue-1285.rs b/bindgen-tests/tests/expectations/tests/issue-1285.rs similarity index 100% rename from tests/expectations/tests/issue-1285.rs rename to bindgen-tests/tests/expectations/tests/issue-1285.rs diff --git a/tests/expectations/tests/issue-1291.rs b/bindgen-tests/tests/expectations/tests/issue-1291.rs similarity index 100% rename from tests/expectations/tests/issue-1291.rs rename to bindgen-tests/tests/expectations/tests/issue-1291.rs diff --git a/tests/expectations/tests/issue-1350-attribute-overloadable.rs b/bindgen-tests/tests/expectations/tests/issue-1350-attribute-overloadable.rs similarity index 100% rename from tests/expectations/tests/issue-1350-attribute-overloadable.rs rename to bindgen-tests/tests/expectations/tests/issue-1350-attribute-overloadable.rs diff --git a/tests/expectations/tests/issue-1382-rust-primitive-types.rs b/bindgen-tests/tests/expectations/tests/issue-1382-rust-primitive-types.rs similarity index 100% rename from tests/expectations/tests/issue-1382-rust-primitive-types.rs rename to bindgen-tests/tests/expectations/tests/issue-1382-rust-primitive-types.rs diff --git a/tests/expectations/tests/issue-1435.rs b/bindgen-tests/tests/expectations/tests/issue-1435.rs similarity index 100% rename from tests/expectations/tests/issue-1435.rs rename to bindgen-tests/tests/expectations/tests/issue-1435.rs diff --git a/tests/expectations/tests/issue-1443.rs b/bindgen-tests/tests/expectations/tests/issue-1443.rs similarity index 100% rename from tests/expectations/tests/issue-1443.rs rename to bindgen-tests/tests/expectations/tests/issue-1443.rs diff --git a/tests/expectations/tests/issue-1454.rs b/bindgen-tests/tests/expectations/tests/issue-1454.rs similarity index 100% rename from tests/expectations/tests/issue-1454.rs rename to bindgen-tests/tests/expectations/tests/issue-1454.rs diff --git a/tests/expectations/tests/issue-1464.rs b/bindgen-tests/tests/expectations/tests/issue-1464.rs similarity index 100% rename from tests/expectations/tests/issue-1464.rs rename to bindgen-tests/tests/expectations/tests/issue-1464.rs diff --git a/tests/expectations/tests/issue-1488-enum-new-type.rs b/bindgen-tests/tests/expectations/tests/issue-1488-enum-new-type.rs similarity index 100% rename from tests/expectations/tests/issue-1488-enum-new-type.rs rename to bindgen-tests/tests/expectations/tests/issue-1488-enum-new-type.rs diff --git a/tests/expectations/tests/issue-1488-options.rs b/bindgen-tests/tests/expectations/tests/issue-1488-options.rs similarity index 100% rename from tests/expectations/tests/issue-1488-options.rs rename to bindgen-tests/tests/expectations/tests/issue-1488-options.rs diff --git a/tests/expectations/tests/issue-1488-template-alias-new-type.rs b/bindgen-tests/tests/expectations/tests/issue-1488-template-alias-new-type.rs similarity index 100% rename from tests/expectations/tests/issue-1488-template-alias-new-type.rs rename to bindgen-tests/tests/expectations/tests/issue-1488-template-alias-new-type.rs diff --git a/tests/expectations/tests/issue-1498.rs b/bindgen-tests/tests/expectations/tests/issue-1498.rs similarity index 100% rename from tests/expectations/tests/issue-1498.rs rename to bindgen-tests/tests/expectations/tests/issue-1498.rs diff --git a/tests/expectations/tests/issue-1514.rs b/bindgen-tests/tests/expectations/tests/issue-1514.rs similarity index 100% rename from tests/expectations/tests/issue-1514.rs rename to bindgen-tests/tests/expectations/tests/issue-1514.rs diff --git a/tests/expectations/tests/issue-1554.rs b/bindgen-tests/tests/expectations/tests/issue-1554.rs similarity index 100% rename from tests/expectations/tests/issue-1554.rs rename to bindgen-tests/tests/expectations/tests/issue-1554.rs diff --git a/tests/expectations/tests/issue-1599-opaque-typedef-to-enum.rs b/bindgen-tests/tests/expectations/tests/issue-1599-opaque-typedef-to-enum.rs similarity index 100% rename from tests/expectations/tests/issue-1599-opaque-typedef-to-enum.rs rename to bindgen-tests/tests/expectations/tests/issue-1599-opaque-typedef-to-enum.rs diff --git a/tests/expectations/tests/issue-1676-macro-namespace-prefix.rs b/bindgen-tests/tests/expectations/tests/issue-1676-macro-namespace-prefix.rs similarity index 100% rename from tests/expectations/tests/issue-1676-macro-namespace-prefix.rs rename to bindgen-tests/tests/expectations/tests/issue-1676-macro-namespace-prefix.rs diff --git a/tests/expectations/tests/issue-1947.rs b/bindgen-tests/tests/expectations/tests/issue-1947.rs similarity index 100% rename from tests/expectations/tests/issue-1947.rs rename to bindgen-tests/tests/expectations/tests/issue-1947.rs diff --git a/tests/expectations/tests/issue-1977-larger-arrays.rs b/bindgen-tests/tests/expectations/tests/issue-1977-larger-arrays.rs similarity index 100% rename from tests/expectations/tests/issue-1977-larger-arrays.rs rename to bindgen-tests/tests/expectations/tests/issue-1977-larger-arrays.rs diff --git a/tests/expectations/tests/issue-1995.rs b/bindgen-tests/tests/expectations/tests/issue-1995.rs similarity index 100% rename from tests/expectations/tests/issue-1995.rs rename to bindgen-tests/tests/expectations/tests/issue-1995.rs diff --git a/tests/expectations/tests/issue-2019.rs b/bindgen-tests/tests/expectations/tests/issue-2019.rs similarity index 100% rename from tests/expectations/tests/issue-2019.rs rename to bindgen-tests/tests/expectations/tests/issue-2019.rs diff --git a/tests/expectations/tests/issue-2239-template-dependent-bit-width.rs b/bindgen-tests/tests/expectations/tests/issue-2239-template-dependent-bit-width.rs similarity index 100% rename from tests/expectations/tests/issue-2239-template-dependent-bit-width.rs rename to bindgen-tests/tests/expectations/tests/issue-2239-template-dependent-bit-width.rs diff --git a/tests/expectations/tests/issue-358.rs b/bindgen-tests/tests/expectations/tests/issue-358.rs similarity index 100% rename from tests/expectations/tests/issue-358.rs rename to bindgen-tests/tests/expectations/tests/issue-358.rs diff --git a/tests/expectations/tests/issue-372.rs b/bindgen-tests/tests/expectations/tests/issue-372.rs similarity index 100% rename from tests/expectations/tests/issue-372.rs rename to bindgen-tests/tests/expectations/tests/issue-372.rs diff --git a/tests/expectations/tests/issue-410.rs b/bindgen-tests/tests/expectations/tests/issue-410.rs similarity index 100% rename from tests/expectations/tests/issue-410.rs rename to bindgen-tests/tests/expectations/tests/issue-410.rs diff --git a/tests/expectations/tests/issue-446.rs b/bindgen-tests/tests/expectations/tests/issue-446.rs similarity index 100% rename from tests/expectations/tests/issue-446.rs rename to bindgen-tests/tests/expectations/tests/issue-446.rs diff --git a/tests/expectations/tests/issue-447.rs b/bindgen-tests/tests/expectations/tests/issue-447.rs similarity index 100% rename from tests/expectations/tests/issue-447.rs rename to bindgen-tests/tests/expectations/tests/issue-447.rs diff --git a/tests/expectations/tests/issue-493.rs b/bindgen-tests/tests/expectations/tests/issue-493.rs similarity index 100% rename from tests/expectations/tests/issue-493.rs rename to bindgen-tests/tests/expectations/tests/issue-493.rs diff --git a/tests/expectations/tests/issue-493_1_0.rs b/bindgen-tests/tests/expectations/tests/issue-493_1_0.rs similarity index 100% rename from tests/expectations/tests/issue-493_1_0.rs rename to bindgen-tests/tests/expectations/tests/issue-493_1_0.rs diff --git a/tests/expectations/tests/issue-511.rs b/bindgen-tests/tests/expectations/tests/issue-511.rs similarity index 100% rename from tests/expectations/tests/issue-511.rs rename to bindgen-tests/tests/expectations/tests/issue-511.rs diff --git a/tests/expectations/tests/issue-537-repr-packed-n.rs b/bindgen-tests/tests/expectations/tests/issue-537-repr-packed-n.rs similarity index 100% rename from tests/expectations/tests/issue-537-repr-packed-n.rs rename to bindgen-tests/tests/expectations/tests/issue-537-repr-packed-n.rs diff --git a/tests/expectations/tests/issue-537.rs b/bindgen-tests/tests/expectations/tests/issue-537.rs similarity index 100% rename from tests/expectations/tests/issue-537.rs rename to bindgen-tests/tests/expectations/tests/issue-537.rs diff --git a/tests/expectations/tests/issue-544-stylo-creduce-2.rs b/bindgen-tests/tests/expectations/tests/issue-544-stylo-creduce-2.rs similarity index 100% rename from tests/expectations/tests/issue-544-stylo-creduce-2.rs rename to bindgen-tests/tests/expectations/tests/issue-544-stylo-creduce-2.rs diff --git a/tests/expectations/tests/issue-544-stylo-creduce.rs b/bindgen-tests/tests/expectations/tests/issue-544-stylo-creduce.rs similarity index 100% rename from tests/expectations/tests/issue-544-stylo-creduce.rs rename to bindgen-tests/tests/expectations/tests/issue-544-stylo-creduce.rs diff --git a/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs b/bindgen-tests/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs similarity index 100% rename from tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs rename to bindgen-tests/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs diff --git a/tests/expectations/tests/issue-573-layout-test-failures.rs b/bindgen-tests/tests/expectations/tests/issue-573-layout-test-failures.rs similarity index 100% rename from tests/expectations/tests/issue-573-layout-test-failures.rs rename to bindgen-tests/tests/expectations/tests/issue-573-layout-test-failures.rs diff --git a/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs b/bindgen-tests/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs similarity index 100% rename from tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs rename to bindgen-tests/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs diff --git a/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs b/bindgen-tests/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs similarity index 100% rename from tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs rename to bindgen-tests/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs diff --git a/tests/expectations/tests/issue-638-stylo-cannot-find-T-in-this-scope.rs b/bindgen-tests/tests/expectations/tests/issue-638-stylo-cannot-find-T-in-this-scope.rs similarity index 100% rename from tests/expectations/tests/issue-638-stylo-cannot-find-T-in-this-scope.rs rename to bindgen-tests/tests/expectations/tests/issue-638-stylo-cannot-find-T-in-this-scope.rs diff --git a/tests/expectations/tests/issue-639-typedef-anon-field.rs b/bindgen-tests/tests/expectations/tests/issue-639-typedef-anon-field.rs similarity index 100% rename from tests/expectations/tests/issue-639-typedef-anon-field.rs rename to bindgen-tests/tests/expectations/tests/issue-639-typedef-anon-field.rs diff --git a/tests/expectations/tests/issue-643-inner-struct.rs b/bindgen-tests/tests/expectations/tests/issue-643-inner-struct.rs similarity index 100% rename from tests/expectations/tests/issue-643-inner-struct.rs rename to bindgen-tests/tests/expectations/tests/issue-643-inner-struct.rs diff --git a/tests/expectations/tests/issue-645-cannot-find-type-T-in-this-scope.rs b/bindgen-tests/tests/expectations/tests/issue-645-cannot-find-type-T-in-this-scope.rs similarity index 100% rename from tests/expectations/tests/issue-645-cannot-find-type-T-in-this-scope.rs rename to bindgen-tests/tests/expectations/tests/issue-645-cannot-find-type-T-in-this-scope.rs diff --git a/tests/expectations/tests/issue-648-derive-debug-with-padding.rs b/bindgen-tests/tests/expectations/tests/issue-648-derive-debug-with-padding.rs similarity index 100% rename from tests/expectations/tests/issue-648-derive-debug-with-padding.rs rename to bindgen-tests/tests/expectations/tests/issue-648-derive-debug-with-padding.rs diff --git a/tests/expectations/tests/issue-654-struct-fn-collision.rs b/bindgen-tests/tests/expectations/tests/issue-654-struct-fn-collision.rs similarity index 100% rename from tests/expectations/tests/issue-654-struct-fn-collision.rs rename to bindgen-tests/tests/expectations/tests/issue-654-struct-fn-collision.rs diff --git a/tests/expectations/tests/issue-662-cannot-find-T-in-this-scope.rs b/bindgen-tests/tests/expectations/tests/issue-662-cannot-find-T-in-this-scope.rs similarity index 100% rename from tests/expectations/tests/issue-662-cannot-find-T-in-this-scope.rs rename to bindgen-tests/tests/expectations/tests/issue-662-cannot-find-T-in-this-scope.rs diff --git a/tests/expectations/tests/issue-662-part-2.rs b/bindgen-tests/tests/expectations/tests/issue-662-part-2.rs similarity index 100% rename from tests/expectations/tests/issue-662-part-2.rs rename to bindgen-tests/tests/expectations/tests/issue-662-part-2.rs diff --git a/tests/expectations/tests/issue-674-1.rs b/bindgen-tests/tests/expectations/tests/issue-674-1.rs similarity index 100% rename from tests/expectations/tests/issue-674-1.rs rename to bindgen-tests/tests/expectations/tests/issue-674-1.rs diff --git a/tests/expectations/tests/issue-674-2.rs b/bindgen-tests/tests/expectations/tests/issue-674-2.rs similarity index 100% rename from tests/expectations/tests/issue-674-2.rs rename to bindgen-tests/tests/expectations/tests/issue-674-2.rs diff --git a/tests/expectations/tests/issue-674-3.rs b/bindgen-tests/tests/expectations/tests/issue-674-3.rs similarity index 100% rename from tests/expectations/tests/issue-674-3.rs rename to bindgen-tests/tests/expectations/tests/issue-674-3.rs diff --git a/tests/expectations/tests/issue-677-nested-ns-specifier.rs b/bindgen-tests/tests/expectations/tests/issue-677-nested-ns-specifier.rs similarity index 100% rename from tests/expectations/tests/issue-677-nested-ns-specifier.rs rename to bindgen-tests/tests/expectations/tests/issue-677-nested-ns-specifier.rs diff --git a/tests/expectations/tests/issue-691-template-parameter-virtual.rs b/bindgen-tests/tests/expectations/tests/issue-691-template-parameter-virtual.rs similarity index 100% rename from tests/expectations/tests/issue-691-template-parameter-virtual.rs rename to bindgen-tests/tests/expectations/tests/issue-691-template-parameter-virtual.rs diff --git a/tests/expectations/tests/issue-710-must-use-type.rs b/bindgen-tests/tests/expectations/tests/issue-710-must-use-type.rs similarity index 100% rename from tests/expectations/tests/issue-710-must-use-type.rs rename to bindgen-tests/tests/expectations/tests/issue-710-must-use-type.rs diff --git a/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs b/bindgen-tests/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs similarity index 100% rename from tests/expectations/tests/issue-739-pointer-wide-bitfield.rs rename to bindgen-tests/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs diff --git a/tests/expectations/tests/issue-801-opaque-sloppiness.rs b/bindgen-tests/tests/expectations/tests/issue-801-opaque-sloppiness.rs similarity index 100% rename from tests/expectations/tests/issue-801-opaque-sloppiness.rs rename to bindgen-tests/tests/expectations/tests/issue-801-opaque-sloppiness.rs diff --git a/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs b/bindgen-tests/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs similarity index 100% rename from tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs rename to bindgen-tests/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs diff --git a/tests/expectations/tests/issue-816.rs b/bindgen-tests/tests/expectations/tests/issue-816.rs similarity index 100% rename from tests/expectations/tests/issue-816.rs rename to bindgen-tests/tests/expectations/tests/issue-816.rs diff --git a/tests/expectations/tests/issue-820-unused-template-param-in-alias.rs b/bindgen-tests/tests/expectations/tests/issue-820-unused-template-param-in-alias.rs similarity index 100% rename from tests/expectations/tests/issue-820-unused-template-param-in-alias.rs rename to bindgen-tests/tests/expectations/tests/issue-820-unused-template-param-in-alias.rs diff --git a/tests/expectations/tests/issue-826-generating-methods-when-asked-not-to.rs b/bindgen-tests/tests/expectations/tests/issue-826-generating-methods-when-asked-not-to.rs similarity index 100% rename from tests/expectations/tests/issue-826-generating-methods-when-asked-not-to.rs rename to bindgen-tests/tests/expectations/tests/issue-826-generating-methods-when-asked-not-to.rs diff --git a/tests/expectations/tests/issue-833-1.rs b/bindgen-tests/tests/expectations/tests/issue-833-1.rs similarity index 100% rename from tests/expectations/tests/issue-833-1.rs rename to bindgen-tests/tests/expectations/tests/issue-833-1.rs diff --git a/tests/expectations/tests/issue-833-2.rs b/bindgen-tests/tests/expectations/tests/issue-833-2.rs similarity index 100% rename from tests/expectations/tests/issue-833-2.rs rename to bindgen-tests/tests/expectations/tests/issue-833-2.rs diff --git a/tests/expectations/tests/issue-833.rs b/bindgen-tests/tests/expectations/tests/issue-833.rs similarity index 100% rename from tests/expectations/tests/issue-833.rs rename to bindgen-tests/tests/expectations/tests/issue-833.rs diff --git a/tests/expectations/tests/issue-834.rs b/bindgen-tests/tests/expectations/tests/issue-834.rs similarity index 100% rename from tests/expectations/tests/issue-834.rs rename to bindgen-tests/tests/expectations/tests/issue-834.rs diff --git a/tests/expectations/tests/issue-848-replacement-system-include.rs b/bindgen-tests/tests/expectations/tests/issue-848-replacement-system-include.rs similarity index 100% rename from tests/expectations/tests/issue-848-replacement-system-include.rs rename to bindgen-tests/tests/expectations/tests/issue-848-replacement-system-include.rs diff --git a/tests/expectations/tests/issue-888-enum-var-decl-jump.rs b/bindgen-tests/tests/expectations/tests/issue-888-enum-var-decl-jump.rs similarity index 100% rename from tests/expectations/tests/issue-888-enum-var-decl-jump.rs rename to bindgen-tests/tests/expectations/tests/issue-888-enum-var-decl-jump.rs diff --git a/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs b/bindgen-tests/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs similarity index 100% rename from tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs rename to bindgen-tests/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs diff --git a/tests/expectations/tests/issue-946.rs b/bindgen-tests/tests/expectations/tests/issue-946.rs similarity index 100% rename from tests/expectations/tests/issue-946.rs rename to bindgen-tests/tests/expectations/tests/issue-946.rs diff --git a/tests/expectations/tests/issue_311.rs b/bindgen-tests/tests/expectations/tests/issue_311.rs similarity index 100% rename from tests/expectations/tests/issue_311.rs rename to bindgen-tests/tests/expectations/tests/issue_311.rs diff --git a/tests/expectations/tests/issue_315.rs b/bindgen-tests/tests/expectations/tests/issue_315.rs similarity index 100% rename from tests/expectations/tests/issue_315.rs rename to bindgen-tests/tests/expectations/tests/issue_315.rs diff --git a/tests/expectations/tests/jsval_layout_opaque.rs b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs similarity index 100% rename from tests/expectations/tests/jsval_layout_opaque.rs rename to bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs diff --git a/tests/expectations/tests/jsval_layout_opaque_1_0.rs b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs similarity index 100% rename from tests/expectations/tests/jsval_layout_opaque_1_0.rs rename to bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs diff --git a/tests/expectations/tests/keywords.rs b/bindgen-tests/tests/expectations/tests/keywords.rs similarity index 100% rename from tests/expectations/tests/keywords.rs rename to bindgen-tests/tests/expectations/tests/keywords.rs diff --git a/tests/expectations/tests/layout.rs b/bindgen-tests/tests/expectations/tests/layout.rs similarity index 100% rename from tests/expectations/tests/layout.rs rename to bindgen-tests/tests/expectations/tests/layout.rs diff --git a/tests/expectations/tests/layout_align.rs b/bindgen-tests/tests/expectations/tests/layout_align.rs similarity index 100% rename from tests/expectations/tests/layout_align.rs rename to bindgen-tests/tests/expectations/tests/layout_align.rs diff --git a/tests/expectations/tests/layout_arp.rs b/bindgen-tests/tests/expectations/tests/layout_arp.rs similarity index 100% rename from tests/expectations/tests/layout_arp.rs rename to bindgen-tests/tests/expectations/tests/layout_arp.rs diff --git a/tests/expectations/tests/layout_array.rs b/bindgen-tests/tests/expectations/tests/layout_array.rs similarity index 100% rename from tests/expectations/tests/layout_array.rs rename to bindgen-tests/tests/expectations/tests/layout_array.rs diff --git a/tests/expectations/tests/layout_array_too_long.rs b/bindgen-tests/tests/expectations/tests/layout_array_too_long.rs similarity index 100% rename from tests/expectations/tests/layout_array_too_long.rs rename to bindgen-tests/tests/expectations/tests/layout_array_too_long.rs diff --git a/tests/expectations/tests/layout_cmdline_token.rs b/bindgen-tests/tests/expectations/tests/layout_cmdline_token.rs similarity index 100% rename from tests/expectations/tests/layout_cmdline_token.rs rename to bindgen-tests/tests/expectations/tests/layout_cmdline_token.rs diff --git a/tests/expectations/tests/layout_eth_conf.rs b/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs similarity index 100% rename from tests/expectations/tests/layout_eth_conf.rs rename to bindgen-tests/tests/expectations/tests/layout_eth_conf.rs diff --git a/tests/expectations/tests/layout_eth_conf_1_0.rs b/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs similarity index 100% rename from tests/expectations/tests/layout_eth_conf_1_0.rs rename to bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs diff --git a/tests/expectations/tests/layout_kni_mbuf.rs b/bindgen-tests/tests/expectations/tests/layout_kni_mbuf.rs similarity index 100% rename from tests/expectations/tests/layout_kni_mbuf.rs rename to bindgen-tests/tests/expectations/tests/layout_kni_mbuf.rs diff --git a/tests/expectations/tests/layout_large_align_field.rs b/bindgen-tests/tests/expectations/tests/layout_large_align_field.rs similarity index 100% rename from tests/expectations/tests/layout_large_align_field.rs rename to bindgen-tests/tests/expectations/tests/layout_large_align_field.rs diff --git a/tests/expectations/tests/layout_mbuf.rs b/bindgen-tests/tests/expectations/tests/layout_mbuf.rs similarity index 100% rename from tests/expectations/tests/layout_mbuf.rs rename to bindgen-tests/tests/expectations/tests/layout_mbuf.rs diff --git a/tests/expectations/tests/layout_mbuf_1_0.rs b/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs similarity index 100% rename from tests/expectations/tests/layout_mbuf_1_0.rs rename to bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs diff --git a/tests/expectations/tests/libclang-5/abi_variadic_function.rs b/bindgen-tests/tests/expectations/tests/libclang-5/abi_variadic_function.rs similarity index 100% rename from tests/expectations/tests/libclang-5/abi_variadic_function.rs rename to bindgen-tests/tests/expectations/tests/libclang-5/abi_variadic_function.rs diff --git a/tests/expectations/tests/libclang-5/auto.rs b/bindgen-tests/tests/expectations/tests/libclang-5/auto.rs similarity index 100% rename from tests/expectations/tests/libclang-5/auto.rs rename to bindgen-tests/tests/expectations/tests/libclang-5/auto.rs diff --git a/tests/expectations/tests/libclang-5/call-conv-field.rs b/bindgen-tests/tests/expectations/tests/libclang-5/call-conv-field.rs similarity index 100% rename from tests/expectations/tests/libclang-5/call-conv-field.rs rename to bindgen-tests/tests/expectations/tests/libclang-5/call-conv-field.rs diff --git a/tests/expectations/tests/libclang-5/const_bool.rs b/bindgen-tests/tests/expectations/tests/libclang-5/const_bool.rs similarity index 100% rename from tests/expectations/tests/libclang-5/const_bool.rs rename to bindgen-tests/tests/expectations/tests/libclang-5/const_bool.rs diff --git a/tests/expectations/tests/libclang-5/constant-evaluate.rs b/bindgen-tests/tests/expectations/tests/libclang-5/constant-evaluate.rs similarity index 100% rename from tests/expectations/tests/libclang-5/constant-evaluate.rs rename to bindgen-tests/tests/expectations/tests/libclang-5/constant-evaluate.rs diff --git a/tests/expectations/tests/libclang-5/error-E0600-cannot-apply-unary-negation-to-u32.rs b/bindgen-tests/tests/expectations/tests/libclang-5/error-E0600-cannot-apply-unary-negation-to-u32.rs similarity index 100% rename from tests/expectations/tests/libclang-5/error-E0600-cannot-apply-unary-negation-to-u32.rs rename to bindgen-tests/tests/expectations/tests/libclang-5/error-E0600-cannot-apply-unary-negation-to-u32.rs diff --git a/tests/expectations/tests/libclang-5/issue-769-bad-instantiation-test.rs b/bindgen-tests/tests/expectations/tests/libclang-5/issue-769-bad-instantiation-test.rs similarity index 100% rename from tests/expectations/tests/libclang-5/issue-769-bad-instantiation-test.rs rename to bindgen-tests/tests/expectations/tests/libclang-5/issue-769-bad-instantiation-test.rs diff --git a/tests/expectations/tests/libclang-5/mangling-win32.rs b/bindgen-tests/tests/expectations/tests/libclang-5/mangling-win32.rs similarity index 100% rename from tests/expectations/tests/libclang-5/mangling-win32.rs rename to bindgen-tests/tests/expectations/tests/libclang-5/mangling-win32.rs diff --git a/tests/expectations/tests/libclang-5/objc_inheritance.rs b/bindgen-tests/tests/expectations/tests/libclang-5/objc_inheritance.rs similarity index 100% rename from tests/expectations/tests/libclang-5/objc_inheritance.rs rename to bindgen-tests/tests/expectations/tests/libclang-5/objc_inheritance.rs diff --git a/tests/expectations/tests/libclang-5/objc_template.rs b/bindgen-tests/tests/expectations/tests/libclang-5/objc_template.rs similarity index 100% rename from tests/expectations/tests/libclang-5/objc_template.rs rename to bindgen-tests/tests/expectations/tests/libclang-5/objc_template.rs diff --git a/tests/expectations/tests/libclang-5/partial-specialization-and-inheritance.rs b/bindgen-tests/tests/expectations/tests/libclang-5/partial-specialization-and-inheritance.rs similarity index 100% rename from tests/expectations/tests/libclang-5/partial-specialization-and-inheritance.rs rename to bindgen-tests/tests/expectations/tests/libclang-5/partial-specialization-and-inheritance.rs diff --git a/tests/expectations/tests/libclang-5/type_alias_template_specialized.rs b/bindgen-tests/tests/expectations/tests/libclang-5/type_alias_template_specialized.rs similarity index 100% rename from tests/expectations/tests/libclang-5/type_alias_template_specialized.rs rename to bindgen-tests/tests/expectations/tests/libclang-5/type_alias_template_specialized.rs diff --git a/tests/expectations/tests/libclang-9/abi_variadic_function.rs b/bindgen-tests/tests/expectations/tests/libclang-9/abi_variadic_function.rs similarity index 100% rename from tests/expectations/tests/libclang-9/abi_variadic_function.rs rename to bindgen-tests/tests/expectations/tests/libclang-9/abi_variadic_function.rs diff --git a/tests/expectations/tests/libclang-9/auto.rs b/bindgen-tests/tests/expectations/tests/libclang-9/auto.rs similarity index 100% rename from tests/expectations/tests/libclang-9/auto.rs rename to bindgen-tests/tests/expectations/tests/libclang-9/auto.rs diff --git a/tests/expectations/tests/libclang-9/call-conv-field.rs b/bindgen-tests/tests/expectations/tests/libclang-9/call-conv-field.rs similarity index 100% rename from tests/expectations/tests/libclang-9/call-conv-field.rs rename to bindgen-tests/tests/expectations/tests/libclang-9/call-conv-field.rs diff --git a/tests/expectations/tests/libclang-9/class.rs b/bindgen-tests/tests/expectations/tests/libclang-9/class.rs similarity index 100% rename from tests/expectations/tests/libclang-9/class.rs rename to bindgen-tests/tests/expectations/tests/libclang-9/class.rs diff --git a/tests/expectations/tests/libclang-9/class_1_0.rs b/bindgen-tests/tests/expectations/tests/libclang-9/class_1_0.rs similarity index 100% rename from tests/expectations/tests/libclang-9/class_1_0.rs rename to bindgen-tests/tests/expectations/tests/libclang-9/class_1_0.rs diff --git a/tests/expectations/tests/libclang-9/const_bool.rs b/bindgen-tests/tests/expectations/tests/libclang-9/const_bool.rs similarity index 100% rename from tests/expectations/tests/libclang-9/const_bool.rs rename to bindgen-tests/tests/expectations/tests/libclang-9/const_bool.rs diff --git a/tests/expectations/tests/libclang-9/constant-evaluate.rs b/bindgen-tests/tests/expectations/tests/libclang-9/constant-evaluate.rs similarity index 100% rename from tests/expectations/tests/libclang-9/constant-evaluate.rs rename to bindgen-tests/tests/expectations/tests/libclang-9/constant-evaluate.rs diff --git a/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs b/bindgen-tests/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs similarity index 100% rename from tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs rename to bindgen-tests/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs diff --git a/tests/expectations/tests/libclang-9/error-E0600-cannot-apply-unary-negation-to-u32.rs b/bindgen-tests/tests/expectations/tests/libclang-9/error-E0600-cannot-apply-unary-negation-to-u32.rs similarity index 100% rename from tests/expectations/tests/libclang-9/error-E0600-cannot-apply-unary-negation-to-u32.rs rename to bindgen-tests/tests/expectations/tests/libclang-9/error-E0600-cannot-apply-unary-negation-to-u32.rs diff --git a/tests/expectations/tests/libclang-9/incomplete-array-padding.rs b/bindgen-tests/tests/expectations/tests/libclang-9/incomplete-array-padding.rs similarity index 100% rename from tests/expectations/tests/libclang-9/incomplete-array-padding.rs rename to bindgen-tests/tests/expectations/tests/libclang-9/incomplete-array-padding.rs diff --git a/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs b/bindgen-tests/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs similarity index 100% rename from tests/expectations/tests/libclang-9/issue-643-inner-struct.rs rename to bindgen-tests/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs diff --git a/tests/expectations/tests/libclang-9/issue-769-bad-instantiation-test.rs b/bindgen-tests/tests/expectations/tests/libclang-9/issue-769-bad-instantiation-test.rs similarity index 100% rename from tests/expectations/tests/libclang-9/issue-769-bad-instantiation-test.rs rename to bindgen-tests/tests/expectations/tests/libclang-9/issue-769-bad-instantiation-test.rs diff --git a/tests/expectations/tests/libclang-9/layout_align.rs b/bindgen-tests/tests/expectations/tests/libclang-9/layout_align.rs similarity index 100% rename from tests/expectations/tests/libclang-9/layout_align.rs rename to bindgen-tests/tests/expectations/tests/libclang-9/layout_align.rs diff --git a/tests/expectations/tests/libclang-9/mangling-win32.rs b/bindgen-tests/tests/expectations/tests/libclang-9/mangling-win32.rs similarity index 100% rename from tests/expectations/tests/libclang-9/mangling-win32.rs rename to bindgen-tests/tests/expectations/tests/libclang-9/mangling-win32.rs diff --git a/tests/expectations/tests/libclang-9/objc_inheritance.rs b/bindgen-tests/tests/expectations/tests/libclang-9/objc_inheritance.rs similarity index 100% rename from tests/expectations/tests/libclang-9/objc_inheritance.rs rename to bindgen-tests/tests/expectations/tests/libclang-9/objc_inheritance.rs diff --git a/tests/expectations/tests/libclang-9/objc_template.rs b/bindgen-tests/tests/expectations/tests/libclang-9/objc_template.rs similarity index 100% rename from tests/expectations/tests/libclang-9/objc_template.rs rename to bindgen-tests/tests/expectations/tests/libclang-9/objc_template.rs diff --git a/tests/expectations/tests/libclang-9/partial-specialization-and-inheritance.rs b/bindgen-tests/tests/expectations/tests/libclang-9/partial-specialization-and-inheritance.rs similarity index 100% rename from tests/expectations/tests/libclang-9/partial-specialization-and-inheritance.rs rename to bindgen-tests/tests/expectations/tests/libclang-9/partial-specialization-and-inheritance.rs diff --git a/tests/expectations/tests/libclang-9/type_alias_template_specialized.rs b/bindgen-tests/tests/expectations/tests/libclang-9/type_alias_template_specialized.rs similarity index 100% rename from tests/expectations/tests/libclang-9/type_alias_template_specialized.rs rename to bindgen-tests/tests/expectations/tests/libclang-9/type_alias_template_specialized.rs diff --git a/tests/expectations/tests/libclang-9/zero-sized-array.rs b/bindgen-tests/tests/expectations/tests/libclang-9/zero-sized-array.rs similarity index 100% rename from tests/expectations/tests/libclang-9/zero-sized-array.rs rename to bindgen-tests/tests/expectations/tests/libclang-9/zero-sized-array.rs diff --git a/tests/expectations/tests/libclang_version_specific_generated_tests.rs b/bindgen-tests/tests/expectations/tests/libclang_version_specific_generated_tests.rs similarity index 100% rename from tests/expectations/tests/libclang_version_specific_generated_tests.rs rename to bindgen-tests/tests/expectations/tests/libclang_version_specific_generated_tests.rs diff --git a/tests/expectations/tests/long_double.rs b/bindgen-tests/tests/expectations/tests/long_double.rs similarity index 100% rename from tests/expectations/tests/long_double.rs rename to bindgen-tests/tests/expectations/tests/long_double.rs diff --git a/tests/expectations/tests/macro-expr-basic.rs b/bindgen-tests/tests/expectations/tests/macro-expr-basic.rs similarity index 100% rename from tests/expectations/tests/macro-expr-basic.rs rename to bindgen-tests/tests/expectations/tests/macro-expr-basic.rs diff --git a/tests/expectations/tests/macro-expr-uncommon-token.rs b/bindgen-tests/tests/expectations/tests/macro-expr-uncommon-token.rs similarity index 100% rename from tests/expectations/tests/macro-expr-uncommon-token.rs rename to bindgen-tests/tests/expectations/tests/macro-expr-uncommon-token.rs diff --git a/tests/expectations/tests/macro-redef.rs b/bindgen-tests/tests/expectations/tests/macro-redef.rs similarity index 100% rename from tests/expectations/tests/macro-redef.rs rename to bindgen-tests/tests/expectations/tests/macro-redef.rs diff --git a/tests/expectations/tests/macro_const.rs b/bindgen-tests/tests/expectations/tests/macro_const.rs similarity index 100% rename from tests/expectations/tests/macro_const.rs rename to bindgen-tests/tests/expectations/tests/macro_const.rs diff --git a/tests/expectations/tests/macro_const_1_0.rs b/bindgen-tests/tests/expectations/tests/macro_const_1_0.rs similarity index 100% rename from tests/expectations/tests/macro_const_1_0.rs rename to bindgen-tests/tests/expectations/tests/macro_const_1_0.rs diff --git a/tests/expectations/tests/maddness-is-avoidable.rs b/bindgen-tests/tests/expectations/tests/maddness-is-avoidable.rs similarity index 100% rename from tests/expectations/tests/maddness-is-avoidable.rs rename to bindgen-tests/tests/expectations/tests/maddness-is-avoidable.rs diff --git a/tests/expectations/tests/mangling-ios.rs b/bindgen-tests/tests/expectations/tests/mangling-ios.rs similarity index 100% rename from tests/expectations/tests/mangling-ios.rs rename to bindgen-tests/tests/expectations/tests/mangling-ios.rs diff --git a/tests/expectations/tests/mangling-linux32.rs b/bindgen-tests/tests/expectations/tests/mangling-linux32.rs similarity index 100% rename from tests/expectations/tests/mangling-linux32.rs rename to bindgen-tests/tests/expectations/tests/mangling-linux32.rs diff --git a/tests/expectations/tests/mangling-linux64.rs b/bindgen-tests/tests/expectations/tests/mangling-linux64.rs similarity index 100% rename from tests/expectations/tests/mangling-linux64.rs rename to bindgen-tests/tests/expectations/tests/mangling-linux64.rs diff --git a/tests/expectations/tests/mangling-macos.rs b/bindgen-tests/tests/expectations/tests/mangling-macos.rs similarity index 100% rename from tests/expectations/tests/mangling-macos.rs rename to bindgen-tests/tests/expectations/tests/mangling-macos.rs diff --git a/tests/expectations/tests/mangling-win64.rs b/bindgen-tests/tests/expectations/tests/mangling-win64.rs similarity index 100% rename from tests/expectations/tests/mangling-win64.rs rename to bindgen-tests/tests/expectations/tests/mangling-win64.rs diff --git a/tests/expectations/tests/merge-extern-blocks.rs b/bindgen-tests/tests/expectations/tests/merge-extern-blocks.rs similarity index 100% rename from tests/expectations/tests/merge-extern-blocks.rs rename to bindgen-tests/tests/expectations/tests/merge-extern-blocks.rs diff --git a/tests/expectations/tests/method-mangling.rs b/bindgen-tests/tests/expectations/tests/method-mangling.rs similarity index 100% rename from tests/expectations/tests/method-mangling.rs rename to bindgen-tests/tests/expectations/tests/method-mangling.rs diff --git a/tests/expectations/tests/module-allowlisted.rs b/bindgen-tests/tests/expectations/tests/module-allowlisted.rs similarity index 100% rename from tests/expectations/tests/module-allowlisted.rs rename to bindgen-tests/tests/expectations/tests/module-allowlisted.rs diff --git a/tests/expectations/tests/msvc-no-usr.rs b/bindgen-tests/tests/expectations/tests/msvc-no-usr.rs similarity index 100% rename from tests/expectations/tests/msvc-no-usr.rs rename to bindgen-tests/tests/expectations/tests/msvc-no-usr.rs diff --git a/tests/expectations/tests/multiple-inherit-empty-correct-layout.rs b/bindgen-tests/tests/expectations/tests/multiple-inherit-empty-correct-layout.rs similarity index 100% rename from tests/expectations/tests/multiple-inherit-empty-correct-layout.rs rename to bindgen-tests/tests/expectations/tests/multiple-inherit-empty-correct-layout.rs diff --git a/tests/expectations/tests/mutable.rs b/bindgen-tests/tests/expectations/tests/mutable.rs similarity index 100% rename from tests/expectations/tests/mutable.rs rename to bindgen-tests/tests/expectations/tests/mutable.rs diff --git a/tests/expectations/tests/namespace.rs b/bindgen-tests/tests/expectations/tests/namespace.rs similarity index 100% rename from tests/expectations/tests/namespace.rs rename to bindgen-tests/tests/expectations/tests/namespace.rs diff --git a/tests/expectations/tests/nested-template-typedef.rs b/bindgen-tests/tests/expectations/tests/nested-template-typedef.rs similarity index 100% rename from tests/expectations/tests/nested-template-typedef.rs rename to bindgen-tests/tests/expectations/tests/nested-template-typedef.rs diff --git a/tests/expectations/tests/nested.rs b/bindgen-tests/tests/expectations/tests/nested.rs similarity index 100% rename from tests/expectations/tests/nested.rs rename to bindgen-tests/tests/expectations/tests/nested.rs diff --git a/tests/expectations/tests/nested_vtable.rs b/bindgen-tests/tests/expectations/tests/nested_vtable.rs similarity index 100% rename from tests/expectations/tests/nested_vtable.rs rename to bindgen-tests/tests/expectations/tests/nested_vtable.rs diff --git a/tests/expectations/tests/nested_within_namespace.rs b/bindgen-tests/tests/expectations/tests/nested_within_namespace.rs similarity index 100% rename from tests/expectations/tests/nested_within_namespace.rs rename to bindgen-tests/tests/expectations/tests/nested_within_namespace.rs diff --git a/tests/expectations/tests/newtype-enum.rs b/bindgen-tests/tests/expectations/tests/newtype-enum.rs similarity index 100% rename from tests/expectations/tests/newtype-enum.rs rename to bindgen-tests/tests/expectations/tests/newtype-enum.rs diff --git a/tests/expectations/tests/newtype-global-enum.rs b/bindgen-tests/tests/expectations/tests/newtype-global-enum.rs similarity index 100% rename from tests/expectations/tests/newtype-global-enum.rs rename to bindgen-tests/tests/expectations/tests/newtype-global-enum.rs diff --git a/tests/expectations/tests/no-comments.rs b/bindgen-tests/tests/expectations/tests/no-comments.rs similarity index 100% rename from tests/expectations/tests/no-comments.rs rename to bindgen-tests/tests/expectations/tests/no-comments.rs diff --git a/tests/expectations/tests/no-derive-debug.rs b/bindgen-tests/tests/expectations/tests/no-derive-debug.rs similarity index 100% rename from tests/expectations/tests/no-derive-debug.rs rename to bindgen-tests/tests/expectations/tests/no-derive-debug.rs diff --git a/tests/expectations/tests/no-derive-default.rs b/bindgen-tests/tests/expectations/tests/no-derive-default.rs similarity index 100% rename from tests/expectations/tests/no-derive-default.rs rename to bindgen-tests/tests/expectations/tests/no-derive-default.rs diff --git a/tests/expectations/tests/no-hash-allowlisted.rs b/bindgen-tests/tests/expectations/tests/no-hash-allowlisted.rs similarity index 100% rename from tests/expectations/tests/no-hash-allowlisted.rs rename to bindgen-tests/tests/expectations/tests/no-hash-allowlisted.rs diff --git a/tests/expectations/tests/no-hash-opaque.rs b/bindgen-tests/tests/expectations/tests/no-hash-opaque.rs similarity index 100% rename from tests/expectations/tests/no-hash-opaque.rs rename to bindgen-tests/tests/expectations/tests/no-hash-opaque.rs diff --git a/tests/expectations/tests/no-partialeq-allowlisted.rs b/bindgen-tests/tests/expectations/tests/no-partialeq-allowlisted.rs similarity index 100% rename from tests/expectations/tests/no-partialeq-allowlisted.rs rename to bindgen-tests/tests/expectations/tests/no-partialeq-allowlisted.rs diff --git a/tests/expectations/tests/no-partialeq-opaque.rs b/bindgen-tests/tests/expectations/tests/no-partialeq-opaque.rs similarity index 100% rename from tests/expectations/tests/no-partialeq-opaque.rs rename to bindgen-tests/tests/expectations/tests/no-partialeq-opaque.rs diff --git a/tests/expectations/tests/no-recursive-allowlisting.rs b/bindgen-tests/tests/expectations/tests/no-recursive-allowlisting.rs similarity index 100% rename from tests/expectations/tests/no-recursive-allowlisting.rs rename to bindgen-tests/tests/expectations/tests/no-recursive-allowlisting.rs diff --git a/tests/expectations/tests/no-std.rs b/bindgen-tests/tests/expectations/tests/no-std.rs similarity index 100% rename from tests/expectations/tests/no-std.rs rename to bindgen-tests/tests/expectations/tests/no-std.rs diff --git a/tests/expectations/tests/no_copy.rs b/bindgen-tests/tests/expectations/tests/no_copy.rs similarity index 100% rename from tests/expectations/tests/no_copy.rs rename to bindgen-tests/tests/expectations/tests/no_copy.rs diff --git a/tests/expectations/tests/no_copy_allowlisted.rs b/bindgen-tests/tests/expectations/tests/no_copy_allowlisted.rs similarity index 100% rename from tests/expectations/tests/no_copy_allowlisted.rs rename to bindgen-tests/tests/expectations/tests/no_copy_allowlisted.rs diff --git a/tests/expectations/tests/no_copy_opaque.rs b/bindgen-tests/tests/expectations/tests/no_copy_opaque.rs similarity index 100% rename from tests/expectations/tests/no_copy_opaque.rs rename to bindgen-tests/tests/expectations/tests/no_copy_opaque.rs diff --git a/tests/expectations/tests/no_debug.rs b/bindgen-tests/tests/expectations/tests/no_debug.rs similarity index 100% rename from tests/expectations/tests/no_debug.rs rename to bindgen-tests/tests/expectations/tests/no_debug.rs diff --git a/tests/expectations/tests/no_debug_allowlisted.rs b/bindgen-tests/tests/expectations/tests/no_debug_allowlisted.rs similarity index 100% rename from tests/expectations/tests/no_debug_allowlisted.rs rename to bindgen-tests/tests/expectations/tests/no_debug_allowlisted.rs diff --git a/tests/expectations/tests/no_debug_bypass_impl_debug.rs b/bindgen-tests/tests/expectations/tests/no_debug_bypass_impl_debug.rs similarity index 100% rename from tests/expectations/tests/no_debug_bypass_impl_debug.rs rename to bindgen-tests/tests/expectations/tests/no_debug_bypass_impl_debug.rs diff --git a/tests/expectations/tests/no_debug_opaque.rs b/bindgen-tests/tests/expectations/tests/no_debug_opaque.rs similarity index 100% rename from tests/expectations/tests/no_debug_opaque.rs rename to bindgen-tests/tests/expectations/tests/no_debug_opaque.rs diff --git a/tests/expectations/tests/no_default.rs b/bindgen-tests/tests/expectations/tests/no_default.rs similarity index 100% rename from tests/expectations/tests/no_default.rs rename to bindgen-tests/tests/expectations/tests/no_default.rs diff --git a/tests/expectations/tests/no_default_allowlisted.rs b/bindgen-tests/tests/expectations/tests/no_default_allowlisted.rs similarity index 100% rename from tests/expectations/tests/no_default_allowlisted.rs rename to bindgen-tests/tests/expectations/tests/no_default_allowlisted.rs diff --git a/tests/expectations/tests/no_default_bypass_derive_default.rs b/bindgen-tests/tests/expectations/tests/no_default_bypass_derive_default.rs similarity index 100% rename from tests/expectations/tests/no_default_bypass_derive_default.rs rename to bindgen-tests/tests/expectations/tests/no_default_bypass_derive_default.rs diff --git a/tests/expectations/tests/no_default_opaque.rs b/bindgen-tests/tests/expectations/tests/no_default_opaque.rs similarity index 100% rename from tests/expectations/tests/no_default_opaque.rs rename to bindgen-tests/tests/expectations/tests/no_default_opaque.rs diff --git a/tests/expectations/tests/no_size_t_is_usize.rs b/bindgen-tests/tests/expectations/tests/no_size_t_is_usize.rs similarity index 100% rename from tests/expectations/tests/no_size_t_is_usize.rs rename to bindgen-tests/tests/expectations/tests/no_size_t_is_usize.rs diff --git a/tests/expectations/tests/non-type-params.rs b/bindgen-tests/tests/expectations/tests/non-type-params.rs similarity index 100% rename from tests/expectations/tests/non-type-params.rs rename to bindgen-tests/tests/expectations/tests/non-type-params.rs diff --git a/tests/expectations/tests/noreturn.rs b/bindgen-tests/tests/expectations/tests/noreturn.rs similarity index 85% rename from tests/expectations/tests/noreturn.rs rename to bindgen-tests/tests/expectations/tests/noreturn.rs index 1945749518..a390578211 100644 --- a/tests/expectations/tests/noreturn.rs +++ b/bindgen-tests/tests/expectations/tests/noreturn.rs @@ -7,11 +7,11 @@ extern "C" { #[link_name = "\u{1}_Z1fv"] - pub fn f() -> !; + pub fn f() -> !; } extern "C" { #[link_name = "\u{1}_Z1gv"] - pub fn g() -> !; + pub fn g() -> !; } extern "C" { #[link_name = "\u{1}_Z1hv"] diff --git a/tests/expectations/tests/nsBaseHashtable.rs b/bindgen-tests/tests/expectations/tests/nsBaseHashtable.rs similarity index 100% rename from tests/expectations/tests/nsBaseHashtable.rs rename to bindgen-tests/tests/expectations/tests/nsBaseHashtable.rs diff --git a/tests/expectations/tests/nsStyleAutoArray.rs b/bindgen-tests/tests/expectations/tests/nsStyleAutoArray.rs similarity index 100% rename from tests/expectations/tests/nsStyleAutoArray.rs rename to bindgen-tests/tests/expectations/tests/nsStyleAutoArray.rs diff --git a/tests/expectations/tests/objc_allowlist.rs b/bindgen-tests/tests/expectations/tests/objc_allowlist.rs similarity index 100% rename from tests/expectations/tests/objc_allowlist.rs rename to bindgen-tests/tests/expectations/tests/objc_allowlist.rs diff --git a/tests/expectations/tests/objc_blocklist.rs b/bindgen-tests/tests/expectations/tests/objc_blocklist.rs similarity index 100% rename from tests/expectations/tests/objc_blocklist.rs rename to bindgen-tests/tests/expectations/tests/objc_blocklist.rs diff --git a/tests/expectations/tests/objc_category.rs b/bindgen-tests/tests/expectations/tests/objc_category.rs similarity index 100% rename from tests/expectations/tests/objc_category.rs rename to bindgen-tests/tests/expectations/tests/objc_category.rs diff --git a/tests/expectations/tests/objc_class.rs b/bindgen-tests/tests/expectations/tests/objc_class.rs similarity index 100% rename from tests/expectations/tests/objc_class.rs rename to bindgen-tests/tests/expectations/tests/objc_class.rs diff --git a/tests/expectations/tests/objc_class_method.rs b/bindgen-tests/tests/expectations/tests/objc_class_method.rs similarity index 100% rename from tests/expectations/tests/objc_class_method.rs rename to bindgen-tests/tests/expectations/tests/objc_class_method.rs diff --git a/tests/expectations/tests/objc_interface.rs b/bindgen-tests/tests/expectations/tests/objc_interface.rs similarity index 100% rename from tests/expectations/tests/objc_interface.rs rename to bindgen-tests/tests/expectations/tests/objc_interface.rs diff --git a/tests/expectations/tests/objc_interface_type.rs b/bindgen-tests/tests/expectations/tests/objc_interface_type.rs similarity index 100% rename from tests/expectations/tests/objc_interface_type.rs rename to bindgen-tests/tests/expectations/tests/objc_interface_type.rs diff --git a/tests/expectations/tests/objc_method.rs b/bindgen-tests/tests/expectations/tests/objc_method.rs similarity index 100% rename from tests/expectations/tests/objc_method.rs rename to bindgen-tests/tests/expectations/tests/objc_method.rs diff --git a/tests/expectations/tests/objc_method_clash.rs b/bindgen-tests/tests/expectations/tests/objc_method_clash.rs similarity index 100% rename from tests/expectations/tests/objc_method_clash.rs rename to bindgen-tests/tests/expectations/tests/objc_method_clash.rs diff --git a/tests/expectations/tests/objc_pointer_return_types.rs b/bindgen-tests/tests/expectations/tests/objc_pointer_return_types.rs similarity index 100% rename from tests/expectations/tests/objc_pointer_return_types.rs rename to bindgen-tests/tests/expectations/tests/objc_pointer_return_types.rs diff --git a/tests/expectations/tests/objc_property_fnptr.rs b/bindgen-tests/tests/expectations/tests/objc_property_fnptr.rs similarity index 100% rename from tests/expectations/tests/objc_property_fnptr.rs rename to bindgen-tests/tests/expectations/tests/objc_property_fnptr.rs diff --git a/tests/expectations/tests/objc_protocol.rs b/bindgen-tests/tests/expectations/tests/objc_protocol.rs similarity index 100% rename from tests/expectations/tests/objc_protocol.rs rename to bindgen-tests/tests/expectations/tests/objc_protocol.rs diff --git a/tests/expectations/tests/objc_protocol_inheritance.rs b/bindgen-tests/tests/expectations/tests/objc_protocol_inheritance.rs similarity index 100% rename from tests/expectations/tests/objc_protocol_inheritance.rs rename to bindgen-tests/tests/expectations/tests/objc_protocol_inheritance.rs diff --git a/tests/expectations/tests/objc_sel_and_id.rs b/bindgen-tests/tests/expectations/tests/objc_sel_and_id.rs similarity index 100% rename from tests/expectations/tests/objc_sel_and_id.rs rename to bindgen-tests/tests/expectations/tests/objc_sel_and_id.rs diff --git a/tests/expectations/tests/only_bitfields.rs b/bindgen-tests/tests/expectations/tests/only_bitfields.rs similarity index 100% rename from tests/expectations/tests/only_bitfields.rs rename to bindgen-tests/tests/expectations/tests/only_bitfields.rs diff --git a/tests/expectations/tests/opaque-template-inst-member-2.rs b/bindgen-tests/tests/expectations/tests/opaque-template-inst-member-2.rs similarity index 100% rename from tests/expectations/tests/opaque-template-inst-member-2.rs rename to bindgen-tests/tests/expectations/tests/opaque-template-inst-member-2.rs diff --git a/tests/expectations/tests/opaque-template-inst-member.rs b/bindgen-tests/tests/expectations/tests/opaque-template-inst-member.rs similarity index 100% rename from tests/expectations/tests/opaque-template-inst-member.rs rename to bindgen-tests/tests/expectations/tests/opaque-template-inst-member.rs diff --git a/tests/expectations/tests/opaque-template-instantiation-namespaced.rs b/bindgen-tests/tests/expectations/tests/opaque-template-instantiation-namespaced.rs similarity index 100% rename from tests/expectations/tests/opaque-template-instantiation-namespaced.rs rename to bindgen-tests/tests/expectations/tests/opaque-template-instantiation-namespaced.rs diff --git a/tests/expectations/tests/opaque-template-instantiation.rs b/bindgen-tests/tests/expectations/tests/opaque-template-instantiation.rs similarity index 100% rename from tests/expectations/tests/opaque-template-instantiation.rs rename to bindgen-tests/tests/expectations/tests/opaque-template-instantiation.rs diff --git a/tests/expectations/tests/opaque-tracing.rs b/bindgen-tests/tests/expectations/tests/opaque-tracing.rs similarity index 100% rename from tests/expectations/tests/opaque-tracing.rs rename to bindgen-tests/tests/expectations/tests/opaque-tracing.rs diff --git a/tests/expectations/tests/opaque_in_struct.rs b/bindgen-tests/tests/expectations/tests/opaque_in_struct.rs similarity index 100% rename from tests/expectations/tests/opaque_in_struct.rs rename to bindgen-tests/tests/expectations/tests/opaque_in_struct.rs diff --git a/tests/expectations/tests/opaque_pointer.rs b/bindgen-tests/tests/expectations/tests/opaque_pointer.rs similarity index 100% rename from tests/expectations/tests/opaque_pointer.rs rename to bindgen-tests/tests/expectations/tests/opaque_pointer.rs diff --git a/tests/expectations/tests/opaque_typedef.rs b/bindgen-tests/tests/expectations/tests/opaque_typedef.rs similarity index 100% rename from tests/expectations/tests/opaque_typedef.rs rename to bindgen-tests/tests/expectations/tests/opaque_typedef.rs diff --git a/tests/expectations/tests/operator.rs b/bindgen-tests/tests/expectations/tests/operator.rs similarity index 100% rename from tests/expectations/tests/operator.rs rename to bindgen-tests/tests/expectations/tests/operator.rs diff --git a/tests/expectations/tests/ord-enum.rs b/bindgen-tests/tests/expectations/tests/ord-enum.rs similarity index 100% rename from tests/expectations/tests/ord-enum.rs rename to bindgen-tests/tests/expectations/tests/ord-enum.rs diff --git a/tests/expectations/tests/overflowed_enum.rs b/bindgen-tests/tests/expectations/tests/overflowed_enum.rs similarity index 100% rename from tests/expectations/tests/overflowed_enum.rs rename to bindgen-tests/tests/expectations/tests/overflowed_enum.rs diff --git a/tests/expectations/tests/overloading.rs b/bindgen-tests/tests/expectations/tests/overloading.rs similarity index 100% rename from tests/expectations/tests/overloading.rs rename to bindgen-tests/tests/expectations/tests/overloading.rs diff --git a/tests/expectations/tests/packed-bitfield.rs b/bindgen-tests/tests/expectations/tests/packed-bitfield.rs similarity index 100% rename from tests/expectations/tests/packed-bitfield.rs rename to bindgen-tests/tests/expectations/tests/packed-bitfield.rs diff --git a/tests/expectations/tests/packed-n-with-padding.rs b/bindgen-tests/tests/expectations/tests/packed-n-with-padding.rs similarity index 100% rename from tests/expectations/tests/packed-n-with-padding.rs rename to bindgen-tests/tests/expectations/tests/packed-n-with-padding.rs diff --git a/tests/expectations/tests/packed-vtable.rs b/bindgen-tests/tests/expectations/tests/packed-vtable.rs similarity index 100% rename from tests/expectations/tests/packed-vtable.rs rename to bindgen-tests/tests/expectations/tests/packed-vtable.rs diff --git a/tests/expectations/tests/parm-union.rs b/bindgen-tests/tests/expectations/tests/parm-union.rs similarity index 100% rename from tests/expectations/tests/parm-union.rs rename to bindgen-tests/tests/expectations/tests/parm-union.rs diff --git a/tests/expectations/tests/parsecb-anonymous-enum-variant-rename.rs b/bindgen-tests/tests/expectations/tests/parsecb-anonymous-enum-variant-rename.rs similarity index 100% rename from tests/expectations/tests/parsecb-anonymous-enum-variant-rename.rs rename to bindgen-tests/tests/expectations/tests/parsecb-anonymous-enum-variant-rename.rs diff --git a/tests/expectations/tests/pointer-attr.rs b/bindgen-tests/tests/expectations/tests/pointer-attr.rs similarity index 100% rename from tests/expectations/tests/pointer-attr.rs rename to bindgen-tests/tests/expectations/tests/pointer-attr.rs diff --git a/tests/expectations/tests/prepend-enum-constified-variant.rs b/bindgen-tests/tests/expectations/tests/prepend-enum-constified-variant.rs similarity index 100% rename from tests/expectations/tests/prepend-enum-constified-variant.rs rename to bindgen-tests/tests/expectations/tests/prepend-enum-constified-variant.rs diff --git a/tests/expectations/tests/prepend_enum_name.rs b/bindgen-tests/tests/expectations/tests/prepend_enum_name.rs similarity index 100% rename from tests/expectations/tests/prepend_enum_name.rs rename to bindgen-tests/tests/expectations/tests/prepend_enum_name.rs diff --git a/tests/expectations/tests/private.rs b/bindgen-tests/tests/expectations/tests/private.rs similarity index 100% rename from tests/expectations/tests/private.rs rename to bindgen-tests/tests/expectations/tests/private.rs diff --git a/tests/expectations/tests/private_fields.rs b/bindgen-tests/tests/expectations/tests/private_fields.rs similarity index 100% rename from tests/expectations/tests/private_fields.rs rename to bindgen-tests/tests/expectations/tests/private_fields.rs diff --git a/tests/expectations/tests/public-dtor.rs b/bindgen-tests/tests/expectations/tests/public-dtor.rs similarity index 100% rename from tests/expectations/tests/public-dtor.rs rename to bindgen-tests/tests/expectations/tests/public-dtor.rs diff --git a/tests/expectations/tests/qualified-dependent-types.rs b/bindgen-tests/tests/expectations/tests/qualified-dependent-types.rs similarity index 100% rename from tests/expectations/tests/qualified-dependent-types.rs rename to bindgen-tests/tests/expectations/tests/qualified-dependent-types.rs diff --git a/tests/expectations/tests/redeclaration.rs b/bindgen-tests/tests/expectations/tests/redeclaration.rs similarity index 100% rename from tests/expectations/tests/redeclaration.rs rename to bindgen-tests/tests/expectations/tests/redeclaration.rs diff --git a/tests/expectations/tests/ref_argument_array.rs b/bindgen-tests/tests/expectations/tests/ref_argument_array.rs similarity index 100% rename from tests/expectations/tests/ref_argument_array.rs rename to bindgen-tests/tests/expectations/tests/ref_argument_array.rs diff --git a/tests/expectations/tests/reparented_replacement.rs b/bindgen-tests/tests/expectations/tests/reparented_replacement.rs similarity index 100% rename from tests/expectations/tests/reparented_replacement.rs rename to bindgen-tests/tests/expectations/tests/reparented_replacement.rs diff --git a/tests/expectations/tests/replace_template_alias.rs b/bindgen-tests/tests/expectations/tests/replace_template_alias.rs similarity index 100% rename from tests/expectations/tests/replace_template_alias.rs rename to bindgen-tests/tests/expectations/tests/replace_template_alias.rs diff --git a/tests/expectations/tests/replace_use.rs b/bindgen-tests/tests/expectations/tests/replace_use.rs similarity index 100% rename from tests/expectations/tests/replace_use.rs rename to bindgen-tests/tests/expectations/tests/replace_use.rs diff --git a/tests/expectations/tests/replaces_double.rs b/bindgen-tests/tests/expectations/tests/replaces_double.rs similarity index 100% rename from tests/expectations/tests/replaces_double.rs rename to bindgen-tests/tests/expectations/tests/replaces_double.rs diff --git a/tests/expectations/tests/repr-align.rs b/bindgen-tests/tests/expectations/tests/repr-align.rs similarity index 100% rename from tests/expectations/tests/repr-align.rs rename to bindgen-tests/tests/expectations/tests/repr-align.rs diff --git a/tests/expectations/tests/resolved_type_def_function.rs b/bindgen-tests/tests/expectations/tests/resolved_type_def_function.rs similarity index 100% rename from tests/expectations/tests/resolved_type_def_function.rs rename to bindgen-tests/tests/expectations/tests/resolved_type_def_function.rs diff --git a/tests/expectations/tests/same_struct_name_in_different_namespaces.rs b/bindgen-tests/tests/expectations/tests/same_struct_name_in_different_namespaces.rs similarity index 100% rename from tests/expectations/tests/same_struct_name_in_different_namespaces.rs rename to bindgen-tests/tests/expectations/tests/same_struct_name_in_different_namespaces.rs diff --git a/tests/expectations/tests/sentry-defined-multiple-times.rs b/bindgen-tests/tests/expectations/tests/sentry-defined-multiple-times.rs similarity index 100% rename from tests/expectations/tests/sentry-defined-multiple-times.rs rename to bindgen-tests/tests/expectations/tests/sentry-defined-multiple-times.rs diff --git a/tests/expectations/tests/short-enums.rs b/bindgen-tests/tests/expectations/tests/short-enums.rs similarity index 100% rename from tests/expectations/tests/short-enums.rs rename to bindgen-tests/tests/expectations/tests/short-enums.rs diff --git a/tests/expectations/tests/size_t_template.rs b/bindgen-tests/tests/expectations/tests/size_t_template.rs similarity index 100% rename from tests/expectations/tests/size_t_template.rs rename to bindgen-tests/tests/expectations/tests/size_t_template.rs diff --git a/tests/expectations/tests/sorted-items.rs b/bindgen-tests/tests/expectations/tests/sorted-items.rs similarity index 100% rename from tests/expectations/tests/sorted-items.rs rename to bindgen-tests/tests/expectations/tests/sorted-items.rs diff --git a/tests/expectations/tests/stdint_typedef.rs b/bindgen-tests/tests/expectations/tests/stdint_typedef.rs similarity index 100% rename from tests/expectations/tests/stdint_typedef.rs rename to bindgen-tests/tests/expectations/tests/stdint_typedef.rs diff --git a/tests/expectations/tests/struct_containing_forward_declared_struct.rs b/bindgen-tests/tests/expectations/tests/struct_containing_forward_declared_struct.rs similarity index 100% rename from tests/expectations/tests/struct_containing_forward_declared_struct.rs rename to bindgen-tests/tests/expectations/tests/struct_containing_forward_declared_struct.rs diff --git a/tests/expectations/tests/struct_typedef.rs b/bindgen-tests/tests/expectations/tests/struct_typedef.rs similarity index 100% rename from tests/expectations/tests/struct_typedef.rs rename to bindgen-tests/tests/expectations/tests/struct_typedef.rs diff --git a/tests/expectations/tests/struct_typedef_ns.rs b/bindgen-tests/tests/expectations/tests/struct_typedef_ns.rs similarity index 100% rename from tests/expectations/tests/struct_typedef_ns.rs rename to bindgen-tests/tests/expectations/tests/struct_typedef_ns.rs diff --git a/tests/expectations/tests/struct_with_anon_struct.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_struct.rs similarity index 100% rename from tests/expectations/tests/struct_with_anon_struct.rs rename to bindgen-tests/tests/expectations/tests/struct_with_anon_struct.rs diff --git a/tests/expectations/tests/struct_with_anon_struct_array.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_struct_array.rs similarity index 100% rename from tests/expectations/tests/struct_with_anon_struct_array.rs rename to bindgen-tests/tests/expectations/tests/struct_with_anon_struct_array.rs diff --git a/tests/expectations/tests/struct_with_anon_struct_pointer.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_struct_pointer.rs similarity index 100% rename from tests/expectations/tests/struct_with_anon_struct_pointer.rs rename to bindgen-tests/tests/expectations/tests/struct_with_anon_struct_pointer.rs diff --git a/tests/expectations/tests/struct_with_anon_union.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_union.rs similarity index 100% rename from tests/expectations/tests/struct_with_anon_union.rs rename to bindgen-tests/tests/expectations/tests/struct_with_anon_union.rs diff --git a/tests/expectations/tests/struct_with_anon_union_1_0.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_union_1_0.rs similarity index 100% rename from tests/expectations/tests/struct_with_anon_union_1_0.rs rename to bindgen-tests/tests/expectations/tests/struct_with_anon_union_1_0.rs diff --git a/tests/expectations/tests/struct_with_anon_unnamed_struct.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_struct.rs similarity index 100% rename from tests/expectations/tests/struct_with_anon_unnamed_struct.rs rename to bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_struct.rs diff --git a/tests/expectations/tests/struct_with_anon_unnamed_union.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union.rs similarity index 100% rename from tests/expectations/tests/struct_with_anon_unnamed_union.rs rename to bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union.rs diff --git a/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs similarity index 100% rename from tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs rename to bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs diff --git a/tests/expectations/tests/struct_with_bitfields.rs b/bindgen-tests/tests/expectations/tests/struct_with_bitfields.rs similarity index 100% rename from tests/expectations/tests/struct_with_bitfields.rs rename to bindgen-tests/tests/expectations/tests/struct_with_bitfields.rs diff --git a/tests/expectations/tests/struct_with_derive_debug.rs b/bindgen-tests/tests/expectations/tests/struct_with_derive_debug.rs similarity index 100% rename from tests/expectations/tests/struct_with_derive_debug.rs rename to bindgen-tests/tests/expectations/tests/struct_with_derive_debug.rs diff --git a/tests/expectations/tests/struct_with_large_array.rs b/bindgen-tests/tests/expectations/tests/struct_with_large_array.rs similarity index 100% rename from tests/expectations/tests/struct_with_large_array.rs rename to bindgen-tests/tests/expectations/tests/struct_with_large_array.rs diff --git a/tests/expectations/tests/struct_with_nesting.rs b/bindgen-tests/tests/expectations/tests/struct_with_nesting.rs similarity index 100% rename from tests/expectations/tests/struct_with_nesting.rs rename to bindgen-tests/tests/expectations/tests/struct_with_nesting.rs diff --git a/tests/expectations/tests/struct_with_nesting_1_0.rs b/bindgen-tests/tests/expectations/tests/struct_with_nesting_1_0.rs similarity index 100% rename from tests/expectations/tests/struct_with_nesting_1_0.rs rename to bindgen-tests/tests/expectations/tests/struct_with_nesting_1_0.rs diff --git a/tests/expectations/tests/struct_with_packing.rs b/bindgen-tests/tests/expectations/tests/struct_with_packing.rs similarity index 100% rename from tests/expectations/tests/struct_with_packing.rs rename to bindgen-tests/tests/expectations/tests/struct_with_packing.rs diff --git a/tests/expectations/tests/struct_with_struct.rs b/bindgen-tests/tests/expectations/tests/struct_with_struct.rs similarity index 100% rename from tests/expectations/tests/struct_with_struct.rs rename to bindgen-tests/tests/expectations/tests/struct_with_struct.rs diff --git a/tests/expectations/tests/struct_with_typedef_template_arg.rs b/bindgen-tests/tests/expectations/tests/struct_with_typedef_template_arg.rs similarity index 100% rename from tests/expectations/tests/struct_with_typedef_template_arg.rs rename to bindgen-tests/tests/expectations/tests/struct_with_typedef_template_arg.rs diff --git a/tests/expectations/tests/template-fun-ty.rs b/bindgen-tests/tests/expectations/tests/template-fun-ty.rs similarity index 100% rename from tests/expectations/tests/template-fun-ty.rs rename to bindgen-tests/tests/expectations/tests/template-fun-ty.rs diff --git a/tests/expectations/tests/template-param-usage-0.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-0.rs similarity index 100% rename from tests/expectations/tests/template-param-usage-0.rs rename to bindgen-tests/tests/expectations/tests/template-param-usage-0.rs diff --git a/tests/expectations/tests/template-param-usage-1.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-1.rs similarity index 100% rename from tests/expectations/tests/template-param-usage-1.rs rename to bindgen-tests/tests/expectations/tests/template-param-usage-1.rs diff --git a/tests/expectations/tests/template-param-usage-10.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-10.rs similarity index 100% rename from tests/expectations/tests/template-param-usage-10.rs rename to bindgen-tests/tests/expectations/tests/template-param-usage-10.rs diff --git a/tests/expectations/tests/template-param-usage-11.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-11.rs similarity index 100% rename from tests/expectations/tests/template-param-usage-11.rs rename to bindgen-tests/tests/expectations/tests/template-param-usage-11.rs diff --git a/tests/expectations/tests/template-param-usage-12.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-12.rs similarity index 100% rename from tests/expectations/tests/template-param-usage-12.rs rename to bindgen-tests/tests/expectations/tests/template-param-usage-12.rs diff --git a/tests/expectations/tests/template-param-usage-13.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-13.rs similarity index 100% rename from tests/expectations/tests/template-param-usage-13.rs rename to bindgen-tests/tests/expectations/tests/template-param-usage-13.rs diff --git a/tests/expectations/tests/template-param-usage-14.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-14.rs similarity index 100% rename from tests/expectations/tests/template-param-usage-14.rs rename to bindgen-tests/tests/expectations/tests/template-param-usage-14.rs diff --git a/tests/expectations/tests/template-param-usage-15.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-15.rs similarity index 100% rename from tests/expectations/tests/template-param-usage-15.rs rename to bindgen-tests/tests/expectations/tests/template-param-usage-15.rs diff --git a/tests/expectations/tests/template-param-usage-2.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-2.rs similarity index 100% rename from tests/expectations/tests/template-param-usage-2.rs rename to bindgen-tests/tests/expectations/tests/template-param-usage-2.rs diff --git a/tests/expectations/tests/template-param-usage-3.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-3.rs similarity index 100% rename from tests/expectations/tests/template-param-usage-3.rs rename to bindgen-tests/tests/expectations/tests/template-param-usage-3.rs diff --git a/tests/expectations/tests/template-param-usage-4.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-4.rs similarity index 100% rename from tests/expectations/tests/template-param-usage-4.rs rename to bindgen-tests/tests/expectations/tests/template-param-usage-4.rs diff --git a/tests/expectations/tests/template-param-usage-5.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-5.rs similarity index 100% rename from tests/expectations/tests/template-param-usage-5.rs rename to bindgen-tests/tests/expectations/tests/template-param-usage-5.rs diff --git a/tests/expectations/tests/template-param-usage-6.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-6.rs similarity index 100% rename from tests/expectations/tests/template-param-usage-6.rs rename to bindgen-tests/tests/expectations/tests/template-param-usage-6.rs diff --git a/tests/expectations/tests/template-param-usage-7.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-7.rs similarity index 100% rename from tests/expectations/tests/template-param-usage-7.rs rename to bindgen-tests/tests/expectations/tests/template-param-usage-7.rs diff --git a/tests/expectations/tests/template-param-usage-8.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-8.rs similarity index 100% rename from tests/expectations/tests/template-param-usage-8.rs rename to bindgen-tests/tests/expectations/tests/template-param-usage-8.rs diff --git a/tests/expectations/tests/template-param-usage-9.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-9.rs similarity index 100% rename from tests/expectations/tests/template-param-usage-9.rs rename to bindgen-tests/tests/expectations/tests/template-param-usage-9.rs diff --git a/tests/expectations/tests/template-with-var.rs b/bindgen-tests/tests/expectations/tests/template-with-var.rs similarity index 100% rename from tests/expectations/tests/template-with-var.rs rename to bindgen-tests/tests/expectations/tests/template-with-var.rs diff --git a/tests/expectations/tests/template.rs b/bindgen-tests/tests/expectations/tests/template.rs similarity index 100% rename from tests/expectations/tests/template.rs rename to bindgen-tests/tests/expectations/tests/template.rs diff --git a/tests/expectations/tests/template_alias.rs b/bindgen-tests/tests/expectations/tests/template_alias.rs similarity index 100% rename from tests/expectations/tests/template_alias.rs rename to bindgen-tests/tests/expectations/tests/template_alias.rs diff --git a/tests/expectations/tests/template_alias_basic.rs b/bindgen-tests/tests/expectations/tests/template_alias_basic.rs similarity index 100% rename from tests/expectations/tests/template_alias_basic.rs rename to bindgen-tests/tests/expectations/tests/template_alias_basic.rs diff --git a/tests/expectations/tests/template_alias_namespace.rs b/bindgen-tests/tests/expectations/tests/template_alias_namespace.rs similarity index 100% rename from tests/expectations/tests/template_alias_namespace.rs rename to bindgen-tests/tests/expectations/tests/template_alias_namespace.rs diff --git a/tests/expectations/tests/template_fun.rs b/bindgen-tests/tests/expectations/tests/template_fun.rs similarity index 100% rename from tests/expectations/tests/template_fun.rs rename to bindgen-tests/tests/expectations/tests/template_fun.rs diff --git a/tests/expectations/tests/template_instantiation_with_fn_local_type.rs b/bindgen-tests/tests/expectations/tests/template_instantiation_with_fn_local_type.rs similarity index 100% rename from tests/expectations/tests/template_instantiation_with_fn_local_type.rs rename to bindgen-tests/tests/expectations/tests/template_instantiation_with_fn_local_type.rs diff --git a/tests/expectations/tests/template_partial_specification.rs b/bindgen-tests/tests/expectations/tests/template_partial_specification.rs similarity index 100% rename from tests/expectations/tests/template_partial_specification.rs rename to bindgen-tests/tests/expectations/tests/template_partial_specification.rs diff --git a/tests/expectations/tests/template_typedef_transitive_param.rs b/bindgen-tests/tests/expectations/tests/template_typedef_transitive_param.rs similarity index 100% rename from tests/expectations/tests/template_typedef_transitive_param.rs rename to bindgen-tests/tests/expectations/tests/template_typedef_transitive_param.rs diff --git a/tests/expectations/tests/template_typedefs.rs b/bindgen-tests/tests/expectations/tests/template_typedefs.rs similarity index 100% rename from tests/expectations/tests/template_typedefs.rs rename to bindgen-tests/tests/expectations/tests/template_typedefs.rs diff --git a/tests/expectations/tests/templateref_opaque.rs b/bindgen-tests/tests/expectations/tests/templateref_opaque.rs similarity index 100% rename from tests/expectations/tests/templateref_opaque.rs rename to bindgen-tests/tests/expectations/tests/templateref_opaque.rs diff --git a/tests/expectations/tests/templatized-bitfield.rs b/bindgen-tests/tests/expectations/tests/templatized-bitfield.rs similarity index 100% rename from tests/expectations/tests/templatized-bitfield.rs rename to bindgen-tests/tests/expectations/tests/templatized-bitfield.rs diff --git a/tests/expectations/tests/test_mixed_header_and_header_contents.rs b/bindgen-tests/tests/expectations/tests/test_mixed_header_and_header_contents.rs similarity index 100% rename from tests/expectations/tests/test_mixed_header_and_header_contents.rs rename to bindgen-tests/tests/expectations/tests/test_mixed_header_and_header_contents.rs diff --git a/tests/expectations/tests/test_multiple_header_calls_in_builder.rs b/bindgen-tests/tests/expectations/tests/test_multiple_header_calls_in_builder.rs similarity index 100% rename from tests/expectations/tests/test_multiple_header_calls_in_builder.rs rename to bindgen-tests/tests/expectations/tests/test_multiple_header_calls_in_builder.rs diff --git a/tests/expectations/tests/timex.rs b/bindgen-tests/tests/expectations/tests/timex.rs similarity index 100% rename from tests/expectations/tests/timex.rs rename to bindgen-tests/tests/expectations/tests/timex.rs diff --git a/tests/expectations/tests/transform-op.rs b/bindgen-tests/tests/expectations/tests/transform-op.rs similarity index 100% rename from tests/expectations/tests/transform-op.rs rename to bindgen-tests/tests/expectations/tests/transform-op.rs diff --git a/tests/expectations/tests/type-referenced-by-allowlisted-function.rs b/bindgen-tests/tests/expectations/tests/type-referenced-by-allowlisted-function.rs similarity index 100% rename from tests/expectations/tests/type-referenced-by-allowlisted-function.rs rename to bindgen-tests/tests/expectations/tests/type-referenced-by-allowlisted-function.rs diff --git a/tests/expectations/tests/type_alias_empty.rs b/bindgen-tests/tests/expectations/tests/type_alias_empty.rs similarity index 100% rename from tests/expectations/tests/type_alias_empty.rs rename to bindgen-tests/tests/expectations/tests/type_alias_empty.rs diff --git a/tests/expectations/tests/type_alias_partial_template_especialization.rs b/bindgen-tests/tests/expectations/tests/type_alias_partial_template_especialization.rs similarity index 100% rename from tests/expectations/tests/type_alias_partial_template_especialization.rs rename to bindgen-tests/tests/expectations/tests/type_alias_partial_template_especialization.rs diff --git a/tests/expectations/tests/typedefd-array-as-function-arg.rs b/bindgen-tests/tests/expectations/tests/typedefd-array-as-function-arg.rs similarity index 100% rename from tests/expectations/tests/typedefd-array-as-function-arg.rs rename to bindgen-tests/tests/expectations/tests/typedefd-array-as-function-arg.rs diff --git a/tests/expectations/tests/typeref.rs b/bindgen-tests/tests/expectations/tests/typeref.rs similarity index 100% rename from tests/expectations/tests/typeref.rs rename to bindgen-tests/tests/expectations/tests/typeref.rs diff --git a/tests/expectations/tests/typeref_1_0.rs b/bindgen-tests/tests/expectations/tests/typeref_1_0.rs similarity index 100% rename from tests/expectations/tests/typeref_1_0.rs rename to bindgen-tests/tests/expectations/tests/typeref_1_0.rs diff --git a/tests/expectations/tests/underscore.rs b/bindgen-tests/tests/expectations/tests/underscore.rs similarity index 100% rename from tests/expectations/tests/underscore.rs rename to bindgen-tests/tests/expectations/tests/underscore.rs diff --git a/tests/expectations/tests/union-align.rs b/bindgen-tests/tests/expectations/tests/union-align.rs similarity index 100% rename from tests/expectations/tests/union-align.rs rename to bindgen-tests/tests/expectations/tests/union-align.rs diff --git a/tests/expectations/tests/union-in-ns.rs b/bindgen-tests/tests/expectations/tests/union-in-ns.rs similarity index 100% rename from tests/expectations/tests/union-in-ns.rs rename to bindgen-tests/tests/expectations/tests/union-in-ns.rs diff --git a/tests/expectations/tests/union-in-ns_1_0.rs b/bindgen-tests/tests/expectations/tests/union-in-ns_1_0.rs similarity index 100% rename from tests/expectations/tests/union-in-ns_1_0.rs rename to bindgen-tests/tests/expectations/tests/union-in-ns_1_0.rs diff --git a/tests/expectations/tests/union_bitfield.rs b/bindgen-tests/tests/expectations/tests/union_bitfield.rs similarity index 100% rename from tests/expectations/tests/union_bitfield.rs rename to bindgen-tests/tests/expectations/tests/union_bitfield.rs diff --git a/tests/expectations/tests/union_bitfield_1_0.rs b/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs similarity index 100% rename from tests/expectations/tests/union_bitfield_1_0.rs rename to bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs diff --git a/tests/expectations/tests/union_dtor.rs b/bindgen-tests/tests/expectations/tests/union_dtor.rs similarity index 100% rename from tests/expectations/tests/union_dtor.rs rename to bindgen-tests/tests/expectations/tests/union_dtor.rs diff --git a/tests/expectations/tests/union_dtor_1_0.rs b/bindgen-tests/tests/expectations/tests/union_dtor_1_0.rs similarity index 100% rename from tests/expectations/tests/union_dtor_1_0.rs rename to bindgen-tests/tests/expectations/tests/union_dtor_1_0.rs diff --git a/tests/expectations/tests/union_fields.rs b/bindgen-tests/tests/expectations/tests/union_fields.rs similarity index 100% rename from tests/expectations/tests/union_fields.rs rename to bindgen-tests/tests/expectations/tests/union_fields.rs diff --git a/tests/expectations/tests/union_fields_1_0.rs b/bindgen-tests/tests/expectations/tests/union_fields_1_0.rs similarity index 100% rename from tests/expectations/tests/union_fields_1_0.rs rename to bindgen-tests/tests/expectations/tests/union_fields_1_0.rs diff --git a/tests/expectations/tests/union_template.rs b/bindgen-tests/tests/expectations/tests/union_template.rs similarity index 100% rename from tests/expectations/tests/union_template.rs rename to bindgen-tests/tests/expectations/tests/union_template.rs diff --git a/tests/expectations/tests/union_template_1_0.rs b/bindgen-tests/tests/expectations/tests/union_template_1_0.rs similarity index 100% rename from tests/expectations/tests/union_template_1_0.rs rename to bindgen-tests/tests/expectations/tests/union_template_1_0.rs diff --git a/tests/expectations/tests/union_with_anon_struct.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_struct.rs similarity index 100% rename from tests/expectations/tests/union_with_anon_struct.rs rename to bindgen-tests/tests/expectations/tests/union_with_anon_struct.rs diff --git a/tests/expectations/tests/union_with_anon_struct_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_1_0.rs similarity index 100% rename from tests/expectations/tests/union_with_anon_struct_1_0.rs rename to bindgen-tests/tests/expectations/tests/union_with_anon_struct_1_0.rs diff --git a/tests/expectations/tests/union_with_anon_struct_bitfield.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield.rs similarity index 100% rename from tests/expectations/tests/union_with_anon_struct_bitfield.rs rename to bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield.rs diff --git a/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs similarity index 100% rename from tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs rename to bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs diff --git a/tests/expectations/tests/union_with_anon_union.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_union.rs similarity index 100% rename from tests/expectations/tests/union_with_anon_union.rs rename to bindgen-tests/tests/expectations/tests/union_with_anon_union.rs diff --git a/tests/expectations/tests/union_with_anon_union_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_union_1_0.rs similarity index 100% rename from tests/expectations/tests/union_with_anon_union_1_0.rs rename to bindgen-tests/tests/expectations/tests/union_with_anon_union_1_0.rs diff --git a/tests/expectations/tests/union_with_anon_unnamed_struct.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct.rs similarity index 100% rename from tests/expectations/tests/union_with_anon_unnamed_struct.rs rename to bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct.rs diff --git a/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs similarity index 100% rename from tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs rename to bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs diff --git a/tests/expectations/tests/union_with_anon_unnamed_union.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union.rs similarity index 100% rename from tests/expectations/tests/union_with_anon_unnamed_union.rs rename to bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union.rs diff --git a/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs similarity index 100% rename from tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs rename to bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs diff --git a/tests/expectations/tests/union_with_big_member.rs b/bindgen-tests/tests/expectations/tests/union_with_big_member.rs similarity index 100% rename from tests/expectations/tests/union_with_big_member.rs rename to bindgen-tests/tests/expectations/tests/union_with_big_member.rs diff --git a/tests/expectations/tests/union_with_big_member_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_big_member_1_0.rs similarity index 100% rename from tests/expectations/tests/union_with_big_member_1_0.rs rename to bindgen-tests/tests/expectations/tests/union_with_big_member_1_0.rs diff --git a/tests/expectations/tests/union_with_nesting.rs b/bindgen-tests/tests/expectations/tests/union_with_nesting.rs similarity index 100% rename from tests/expectations/tests/union_with_nesting.rs rename to bindgen-tests/tests/expectations/tests/union_with_nesting.rs diff --git a/tests/expectations/tests/union_with_nesting_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_nesting_1_0.rs similarity index 100% rename from tests/expectations/tests/union_with_nesting_1_0.rs rename to bindgen-tests/tests/expectations/tests/union_with_nesting_1_0.rs diff --git a/tests/expectations/tests/union_with_non_copy_member.rs b/bindgen-tests/tests/expectations/tests/union_with_non_copy_member.rs similarity index 100% rename from tests/expectations/tests/union_with_non_copy_member.rs rename to bindgen-tests/tests/expectations/tests/union_with_non_copy_member.rs diff --git a/tests/expectations/tests/unknown_attr.rs b/bindgen-tests/tests/expectations/tests/unknown_attr.rs similarity index 100% rename from tests/expectations/tests/unknown_attr.rs rename to bindgen-tests/tests/expectations/tests/unknown_attr.rs diff --git a/tests/expectations/tests/unsorted-items.rs b/bindgen-tests/tests/expectations/tests/unsorted-items.rs similarity index 100% rename from tests/expectations/tests/unsorted-items.rs rename to bindgen-tests/tests/expectations/tests/unsorted-items.rs diff --git a/tests/expectations/tests/use-core.rs b/bindgen-tests/tests/expectations/tests/use-core.rs similarity index 100% rename from tests/expectations/tests/use-core.rs rename to bindgen-tests/tests/expectations/tests/use-core.rs diff --git a/tests/expectations/tests/use-core_1_0.rs b/bindgen-tests/tests/expectations/tests/use-core_1_0.rs similarity index 100% rename from tests/expectations/tests/use-core_1_0.rs rename to bindgen-tests/tests/expectations/tests/use-core_1_0.rs diff --git a/tests/expectations/tests/using.rs b/bindgen-tests/tests/expectations/tests/using.rs similarity index 100% rename from tests/expectations/tests/using.rs rename to bindgen-tests/tests/expectations/tests/using.rs diff --git a/tests/expectations/tests/var-tracing.rs b/bindgen-tests/tests/expectations/tests/var-tracing.rs similarity index 100% rename from tests/expectations/tests/var-tracing.rs rename to bindgen-tests/tests/expectations/tests/var-tracing.rs diff --git a/tests/expectations/tests/variadic-method.rs b/bindgen-tests/tests/expectations/tests/variadic-method.rs similarity index 100% rename from tests/expectations/tests/variadic-method.rs rename to bindgen-tests/tests/expectations/tests/variadic-method.rs diff --git a/tests/expectations/tests/variadic_template_function.rs b/bindgen-tests/tests/expectations/tests/variadic_template_function.rs similarity index 100% rename from tests/expectations/tests/variadic_template_function.rs rename to bindgen-tests/tests/expectations/tests/variadic_template_function.rs diff --git a/tests/expectations/tests/vector.rs b/bindgen-tests/tests/expectations/tests/vector.rs similarity index 100% rename from tests/expectations/tests/vector.rs rename to bindgen-tests/tests/expectations/tests/vector.rs diff --git a/tests/expectations/tests/virtual_dtor.rs b/bindgen-tests/tests/expectations/tests/virtual_dtor.rs similarity index 100% rename from tests/expectations/tests/virtual_dtor.rs rename to bindgen-tests/tests/expectations/tests/virtual_dtor.rs diff --git a/tests/expectations/tests/virtual_inheritance.rs b/bindgen-tests/tests/expectations/tests/virtual_inheritance.rs similarity index 100% rename from tests/expectations/tests/virtual_inheritance.rs rename to bindgen-tests/tests/expectations/tests/virtual_inheritance.rs diff --git a/tests/expectations/tests/virtual_interface.rs b/bindgen-tests/tests/expectations/tests/virtual_interface.rs similarity index 100% rename from tests/expectations/tests/virtual_interface.rs rename to bindgen-tests/tests/expectations/tests/virtual_interface.rs diff --git a/tests/expectations/tests/virtual_overloaded.rs b/bindgen-tests/tests/expectations/tests/virtual_overloaded.rs similarity index 100% rename from tests/expectations/tests/virtual_overloaded.rs rename to bindgen-tests/tests/expectations/tests/virtual_overloaded.rs diff --git a/tests/expectations/tests/vtable_recursive_sig.rs b/bindgen-tests/tests/expectations/tests/vtable_recursive_sig.rs similarity index 100% rename from tests/expectations/tests/vtable_recursive_sig.rs rename to bindgen-tests/tests/expectations/tests/vtable_recursive_sig.rs diff --git a/tests/expectations/tests/wasm-constructor-returns.rs b/bindgen-tests/tests/expectations/tests/wasm-constructor-returns.rs similarity index 100% rename from tests/expectations/tests/wasm-constructor-returns.rs rename to bindgen-tests/tests/expectations/tests/wasm-constructor-returns.rs diff --git a/tests/expectations/tests/wasm-import-module.rs b/bindgen-tests/tests/expectations/tests/wasm-import-module.rs similarity index 100% rename from tests/expectations/tests/wasm-import-module.rs rename to bindgen-tests/tests/expectations/tests/wasm-import-module.rs diff --git a/tests/expectations/tests/weird_bitfields.rs b/bindgen-tests/tests/expectations/tests/weird_bitfields.rs similarity index 100% rename from tests/expectations/tests/weird_bitfields.rs rename to bindgen-tests/tests/expectations/tests/weird_bitfields.rs diff --git a/tests/expectations/tests/what_is_going_on.rs b/bindgen-tests/tests/expectations/tests/what_is_going_on.rs similarity index 100% rename from tests/expectations/tests/what_is_going_on.rs rename to bindgen-tests/tests/expectations/tests/what_is_going_on.rs diff --git a/tests/expectations/tests/win32-thiscall_1_0.rs b/bindgen-tests/tests/expectations/tests/win32-thiscall_1_0.rs similarity index 100% rename from tests/expectations/tests/win32-thiscall_1_0.rs rename to bindgen-tests/tests/expectations/tests/win32-thiscall_1_0.rs diff --git a/tests/expectations/tests/win32-thiscall_nightly.rs b/bindgen-tests/tests/expectations/tests/win32-thiscall_nightly.rs similarity index 100% rename from tests/expectations/tests/win32-thiscall_nightly.rs rename to bindgen-tests/tests/expectations/tests/win32-thiscall_nightly.rs diff --git a/tests/expectations/tests/win32-vectorcall-1_0.rs b/bindgen-tests/tests/expectations/tests/win32-vectorcall-1_0.rs similarity index 100% rename from tests/expectations/tests/win32-vectorcall-1_0.rs rename to bindgen-tests/tests/expectations/tests/win32-vectorcall-1_0.rs diff --git a/tests/expectations/tests/win32-vectorcall-nightly.rs b/bindgen-tests/tests/expectations/tests/win32-vectorcall-nightly.rs similarity index 100% rename from tests/expectations/tests/win32-vectorcall-nightly.rs rename to bindgen-tests/tests/expectations/tests/win32-vectorcall-nightly.rs diff --git a/tests/expectations/tests/with_array_pointers_arguments.rs b/bindgen-tests/tests/expectations/tests/with_array_pointers_arguments.rs similarity index 100% rename from tests/expectations/tests/with_array_pointers_arguments.rs rename to bindgen-tests/tests/expectations/tests/with_array_pointers_arguments.rs diff --git a/tests/expectations/tests/without_array_pointers_arguments.rs b/bindgen-tests/tests/expectations/tests/without_array_pointers_arguments.rs similarity index 100% rename from tests/expectations/tests/without_array_pointers_arguments.rs rename to bindgen-tests/tests/expectations/tests/without_array_pointers_arguments.rs diff --git a/tests/expectations/tests/zero-size-array-align.rs b/bindgen-tests/tests/expectations/tests/zero-size-array-align.rs similarity index 100% rename from tests/expectations/tests/zero-size-array-align.rs rename to bindgen-tests/tests/expectations/tests/zero-size-array-align.rs diff --git a/tests/expectations/tests/zero-sized-array.rs b/bindgen-tests/tests/expectations/tests/zero-sized-array.rs similarity index 100% rename from tests/expectations/tests/zero-sized-array.rs rename to bindgen-tests/tests/expectations/tests/zero-sized-array.rs diff --git a/tests/headers/16-byte-alignment.h b/bindgen-tests/tests/headers/16-byte-alignment.h similarity index 100% rename from tests/headers/16-byte-alignment.h rename to bindgen-tests/tests/headers/16-byte-alignment.h diff --git a/tests/headers/16-byte-alignment_1_0.h b/bindgen-tests/tests/headers/16-byte-alignment_1_0.h similarity index 100% rename from tests/headers/16-byte-alignment_1_0.h rename to bindgen-tests/tests/headers/16-byte-alignment_1_0.h diff --git a/tests/headers/381-decltype-alias.hpp b/bindgen-tests/tests/headers/381-decltype-alias.hpp similarity index 100% rename from tests/headers/381-decltype-alias.hpp rename to bindgen-tests/tests/headers/381-decltype-alias.hpp diff --git a/tests/headers/abi_variadic_function.hpp b/bindgen-tests/tests/headers/abi_variadic_function.hpp similarity index 100% rename from tests/headers/abi_variadic_function.hpp rename to bindgen-tests/tests/headers/abi_variadic_function.hpp diff --git a/tests/headers/accessors.hpp b/bindgen-tests/tests/headers/accessors.hpp similarity index 100% rename from tests/headers/accessors.hpp rename to bindgen-tests/tests/headers/accessors.hpp diff --git a/tests/headers/allowlist-file.hpp b/bindgen-tests/tests/headers/allowlist-file.hpp similarity index 100% rename from tests/headers/allowlist-file.hpp rename to bindgen-tests/tests/headers/allowlist-file.hpp diff --git a/tests/headers/allowlist-namespaces-basic.hpp b/bindgen-tests/tests/headers/allowlist-namespaces-basic.hpp similarity index 100% rename from tests/headers/allowlist-namespaces-basic.hpp rename to bindgen-tests/tests/headers/allowlist-namespaces-basic.hpp diff --git a/tests/headers/allowlist-namespaces.hpp b/bindgen-tests/tests/headers/allowlist-namespaces.hpp similarity index 100% rename from tests/headers/allowlist-namespaces.hpp rename to bindgen-tests/tests/headers/allowlist-namespaces.hpp diff --git a/tests/headers/allowlist_basic.hpp b/bindgen-tests/tests/headers/allowlist_basic.hpp similarity index 100% rename from tests/headers/allowlist_basic.hpp rename to bindgen-tests/tests/headers/allowlist_basic.hpp diff --git a/tests/headers/allowlist_fix.hpp b/bindgen-tests/tests/headers/allowlist_fix.hpp similarity index 100% rename from tests/headers/allowlist_fix.hpp rename to bindgen-tests/tests/headers/allowlist_fix.hpp diff --git a/tests/headers/allowlist_vars.h b/bindgen-tests/tests/headers/allowlist_vars.h similarity index 100% rename from tests/headers/allowlist_vars.h rename to bindgen-tests/tests/headers/allowlist_vars.h diff --git a/tests/headers/allowlist_warnings.h b/bindgen-tests/tests/headers/allowlist_warnings.h similarity index 100% rename from tests/headers/allowlist_warnings.h rename to bindgen-tests/tests/headers/allowlist_warnings.h diff --git a/tests/headers/allowlisted-item-references-no-hash.hpp b/bindgen-tests/tests/headers/allowlisted-item-references-no-hash.hpp similarity index 100% rename from tests/headers/allowlisted-item-references-no-hash.hpp rename to bindgen-tests/tests/headers/allowlisted-item-references-no-hash.hpp diff --git a/tests/headers/allowlisted-item-references-no-partialeq.hpp b/bindgen-tests/tests/headers/allowlisted-item-references-no-partialeq.hpp similarity index 100% rename from tests/headers/allowlisted-item-references-no-partialeq.hpp rename to bindgen-tests/tests/headers/allowlisted-item-references-no-partialeq.hpp diff --git a/tests/headers/allowlisted/file.hpp b/bindgen-tests/tests/headers/allowlisted/file.hpp similarity index 100% rename from tests/headers/allowlisted/file.hpp rename to bindgen-tests/tests/headers/allowlisted/file.hpp diff --git a/tests/headers/allowlisted_item_references_no_copy.hpp b/bindgen-tests/tests/headers/allowlisted_item_references_no_copy.hpp similarity index 100% rename from tests/headers/allowlisted_item_references_no_copy.hpp rename to bindgen-tests/tests/headers/allowlisted_item_references_no_copy.hpp diff --git a/tests/headers/annotation_hide.hpp b/bindgen-tests/tests/headers/annotation_hide.hpp similarity index 100% rename from tests/headers/annotation_hide.hpp rename to bindgen-tests/tests/headers/annotation_hide.hpp diff --git a/tests/headers/anon-fields-prefix.h b/bindgen-tests/tests/headers/anon-fields-prefix.h similarity index 100% rename from tests/headers/anon-fields-prefix.h rename to bindgen-tests/tests/headers/anon-fields-prefix.h diff --git a/tests/headers/anon_enum.hpp b/bindgen-tests/tests/headers/anon_enum.hpp similarity index 100% rename from tests/headers/anon_enum.hpp rename to bindgen-tests/tests/headers/anon_enum.hpp diff --git a/tests/headers/anon_enum_allowlist.h b/bindgen-tests/tests/headers/anon_enum_allowlist.h similarity index 100% rename from tests/headers/anon_enum_allowlist.h rename to bindgen-tests/tests/headers/anon_enum_allowlist.h diff --git a/tests/headers/anon_enum_trait.hpp b/bindgen-tests/tests/headers/anon_enum_trait.hpp similarity index 100% rename from tests/headers/anon_enum_trait.hpp rename to bindgen-tests/tests/headers/anon_enum_trait.hpp diff --git a/tests/headers/anon_struct_in_union.h b/bindgen-tests/tests/headers/anon_struct_in_union.h similarity index 100% rename from tests/headers/anon_struct_in_union.h rename to bindgen-tests/tests/headers/anon_struct_in_union.h diff --git a/tests/headers/anon_struct_in_union_1_0.h b/bindgen-tests/tests/headers/anon_struct_in_union_1_0.h similarity index 100% rename from tests/headers/anon_struct_in_union_1_0.h rename to bindgen-tests/tests/headers/anon_struct_in_union_1_0.h diff --git a/tests/headers/anon_union.hpp b/bindgen-tests/tests/headers/anon_union.hpp similarity index 100% rename from tests/headers/anon_union.hpp rename to bindgen-tests/tests/headers/anon_union.hpp diff --git a/tests/headers/anon_union_1_0.hpp b/bindgen-tests/tests/headers/anon_union_1_0.hpp similarity index 100% rename from tests/headers/anon_union_1_0.hpp rename to bindgen-tests/tests/headers/anon_union_1_0.hpp diff --git a/tests/headers/anonymous-template-types.hpp b/bindgen-tests/tests/headers/anonymous-template-types.hpp similarity index 100% rename from tests/headers/anonymous-template-types.hpp rename to bindgen-tests/tests/headers/anonymous-template-types.hpp diff --git a/tests/headers/arg_keyword.hpp b/bindgen-tests/tests/headers/arg_keyword.hpp similarity index 100% rename from tests/headers/arg_keyword.hpp rename to bindgen-tests/tests/headers/arg_keyword.hpp diff --git a/tests/headers/array-of-zero-sized-types.hpp b/bindgen-tests/tests/headers/array-of-zero-sized-types.hpp similarity index 100% rename from tests/headers/array-of-zero-sized-types.hpp rename to bindgen-tests/tests/headers/array-of-zero-sized-types.hpp diff --git a/tests/headers/attribute_warn_unused_result.hpp b/bindgen-tests/tests/headers/attribute_warn_unused_result.hpp similarity index 100% rename from tests/headers/attribute_warn_unused_result.hpp rename to bindgen-tests/tests/headers/attribute_warn_unused_result.hpp diff --git a/tests/headers/attribute_warn_unused_result_no_attribute_detection.hpp b/bindgen-tests/tests/headers/attribute_warn_unused_result_no_attribute_detection.hpp similarity index 100% rename from tests/headers/attribute_warn_unused_result_no_attribute_detection.hpp rename to bindgen-tests/tests/headers/attribute_warn_unused_result_no_attribute_detection.hpp diff --git a/tests/headers/attribute_warn_unused_result_pre_1_27.hpp b/bindgen-tests/tests/headers/attribute_warn_unused_result_pre_1_27.hpp similarity index 100% rename from tests/headers/attribute_warn_unused_result_pre_1_27.hpp rename to bindgen-tests/tests/headers/attribute_warn_unused_result_pre_1_27.hpp diff --git a/tests/headers/auto.hpp b/bindgen-tests/tests/headers/auto.hpp similarity index 100% rename from tests/headers/auto.hpp rename to bindgen-tests/tests/headers/auto.hpp diff --git a/tests/headers/bad-namespace-parenthood-inheritance.hpp b/bindgen-tests/tests/headers/bad-namespace-parenthood-inheritance.hpp similarity index 100% rename from tests/headers/bad-namespace-parenthood-inheritance.hpp rename to bindgen-tests/tests/headers/bad-namespace-parenthood-inheritance.hpp diff --git a/tests/headers/base-to-derived.hpp b/bindgen-tests/tests/headers/base-to-derived.hpp similarity index 100% rename from tests/headers/base-to-derived.hpp rename to bindgen-tests/tests/headers/base-to-derived.hpp diff --git a/tests/headers/bindgen-union-inside-namespace.hpp b/bindgen-tests/tests/headers/bindgen-union-inside-namespace.hpp similarity index 100% rename from tests/headers/bindgen-union-inside-namespace.hpp rename to bindgen-tests/tests/headers/bindgen-union-inside-namespace.hpp diff --git a/tests/headers/bitfield-32bit-overflow.h b/bindgen-tests/tests/headers/bitfield-32bit-overflow.h similarity index 100% rename from tests/headers/bitfield-32bit-overflow.h rename to bindgen-tests/tests/headers/bitfield-32bit-overflow.h diff --git a/tests/headers/bitfield-enum-basic.hpp b/bindgen-tests/tests/headers/bitfield-enum-basic.hpp similarity index 100% rename from tests/headers/bitfield-enum-basic.hpp rename to bindgen-tests/tests/headers/bitfield-enum-basic.hpp diff --git a/tests/headers/bitfield-enum-repr-c.hpp b/bindgen-tests/tests/headers/bitfield-enum-repr-c.hpp similarity index 100% rename from tests/headers/bitfield-enum-repr-c.hpp rename to bindgen-tests/tests/headers/bitfield-enum-repr-c.hpp diff --git a/tests/headers/bitfield-enum-repr-transparent.hpp b/bindgen-tests/tests/headers/bitfield-enum-repr-transparent.hpp similarity index 100% rename from tests/headers/bitfield-enum-repr-transparent.hpp rename to bindgen-tests/tests/headers/bitfield-enum-repr-transparent.hpp diff --git a/tests/headers/bitfield-large.hpp b/bindgen-tests/tests/headers/bitfield-large.hpp similarity index 100% rename from tests/headers/bitfield-large.hpp rename to bindgen-tests/tests/headers/bitfield-large.hpp diff --git a/tests/headers/bitfield-linux-32.hpp b/bindgen-tests/tests/headers/bitfield-linux-32.hpp similarity index 100% rename from tests/headers/bitfield-linux-32.hpp rename to bindgen-tests/tests/headers/bitfield-linux-32.hpp diff --git a/tests/headers/bitfield-method-same-name.hpp b/bindgen-tests/tests/headers/bitfield-method-same-name.hpp similarity index 100% rename from tests/headers/bitfield-method-same-name.hpp rename to bindgen-tests/tests/headers/bitfield-method-same-name.hpp diff --git a/tests/headers/bitfield_align.h b/bindgen-tests/tests/headers/bitfield_align.h similarity index 100% rename from tests/headers/bitfield_align.h rename to bindgen-tests/tests/headers/bitfield_align.h diff --git a/tests/headers/bitfield_align_2.h b/bindgen-tests/tests/headers/bitfield_align_2.h similarity index 100% rename from tests/headers/bitfield_align_2.h rename to bindgen-tests/tests/headers/bitfield_align_2.h diff --git a/tests/headers/bitfield_large_overflow.hpp b/bindgen-tests/tests/headers/bitfield_large_overflow.hpp similarity index 100% rename from tests/headers/bitfield_large_overflow.hpp rename to bindgen-tests/tests/headers/bitfield_large_overflow.hpp diff --git a/tests/headers/bitfield_method_mangling.h b/bindgen-tests/tests/headers/bitfield_method_mangling.h similarity index 100% rename from tests/headers/bitfield_method_mangling.h rename to bindgen-tests/tests/headers/bitfield_method_mangling.h diff --git a/tests/headers/bitfield_pragma_packed.h b/bindgen-tests/tests/headers/bitfield_pragma_packed.h similarity index 100% rename from tests/headers/bitfield_pragma_packed.h rename to bindgen-tests/tests/headers/bitfield_pragma_packed.h diff --git a/tests/headers/block_return_type.h b/bindgen-tests/tests/headers/block_return_type.h similarity index 100% rename from tests/headers/block_return_type.h rename to bindgen-tests/tests/headers/block_return_type.h diff --git a/tests/headers/blocklist-and-impl-debug.hpp b/bindgen-tests/tests/headers/blocklist-and-impl-debug.hpp similarity index 100% rename from tests/headers/blocklist-and-impl-debug.hpp rename to bindgen-tests/tests/headers/blocklist-and-impl-debug.hpp diff --git a/tests/headers/blocklist-file.hpp b/bindgen-tests/tests/headers/blocklist-file.hpp similarity index 100% rename from tests/headers/blocklist-file.hpp rename to bindgen-tests/tests/headers/blocklist-file.hpp diff --git a/tests/headers/blocklist-function.hpp b/bindgen-tests/tests/headers/blocklist-function.hpp similarity index 100% rename from tests/headers/blocklist-function.hpp rename to bindgen-tests/tests/headers/blocklist-function.hpp diff --git a/tests/headers/blocklist-item.hpp b/bindgen-tests/tests/headers/blocklist-item.hpp similarity index 100% rename from tests/headers/blocklist-item.hpp rename to bindgen-tests/tests/headers/blocklist-item.hpp diff --git a/tests/headers/blocklisted/fake-stdint.h b/bindgen-tests/tests/headers/blocklisted/fake-stdint.h similarity index 100% rename from tests/headers/blocklisted/fake-stdint.h rename to bindgen-tests/tests/headers/blocklisted/fake-stdint.h diff --git a/tests/headers/blocklisted/file.hpp b/bindgen-tests/tests/headers/blocklisted/file.hpp similarity index 100% rename from tests/headers/blocklisted/file.hpp rename to bindgen-tests/tests/headers/blocklisted/file.hpp diff --git a/tests/headers/blocks-signature.hpp b/bindgen-tests/tests/headers/blocks-signature.hpp similarity index 100% rename from tests/headers/blocks-signature.hpp rename to bindgen-tests/tests/headers/blocks-signature.hpp diff --git a/tests/headers/blocks.hpp b/bindgen-tests/tests/headers/blocks.hpp similarity index 100% rename from tests/headers/blocks.hpp rename to bindgen-tests/tests/headers/blocks.hpp diff --git a/tests/headers/bug-1529681.hpp b/bindgen-tests/tests/headers/bug-1529681.hpp similarity index 100% rename from tests/headers/bug-1529681.hpp rename to bindgen-tests/tests/headers/bug-1529681.hpp diff --git a/tests/headers/builtin-template.hpp b/bindgen-tests/tests/headers/builtin-template.hpp similarity index 100% rename from tests/headers/builtin-template.hpp rename to bindgen-tests/tests/headers/builtin-template.hpp diff --git a/tests/headers/c-empty-layout.h b/bindgen-tests/tests/headers/c-empty-layout.h similarity index 100% rename from tests/headers/c-empty-layout.h rename to bindgen-tests/tests/headers/c-empty-layout.h diff --git a/tests/headers/c_naming.h b/bindgen-tests/tests/headers/c_naming.h similarity index 100% rename from tests/headers/c_naming.h rename to bindgen-tests/tests/headers/c_naming.h diff --git a/tests/headers/call-conv-field.h b/bindgen-tests/tests/headers/call-conv-field.h similarity index 100% rename from tests/headers/call-conv-field.h rename to bindgen-tests/tests/headers/call-conv-field.h diff --git a/tests/headers/call-conv-typedef.h b/bindgen-tests/tests/headers/call-conv-typedef.h similarity index 100% rename from tests/headers/call-conv-typedef.h rename to bindgen-tests/tests/headers/call-conv-typedef.h diff --git a/tests/headers/canonical-types.hpp b/bindgen-tests/tests/headers/canonical-types.hpp similarity index 100% rename from tests/headers/canonical-types.hpp rename to bindgen-tests/tests/headers/canonical-types.hpp diff --git a/tests/headers/canonical_path_without_namespacing.hpp b/bindgen-tests/tests/headers/canonical_path_without_namespacing.hpp similarity index 100% rename from tests/headers/canonical_path_without_namespacing.hpp rename to bindgen-tests/tests/headers/canonical_path_without_namespacing.hpp diff --git a/tests/headers/char.h b/bindgen-tests/tests/headers/char.h similarity index 100% rename from tests/headers/char.h rename to bindgen-tests/tests/headers/char.h diff --git a/tests/headers/class.hpp b/bindgen-tests/tests/headers/class.hpp similarity index 100% rename from tests/headers/class.hpp rename to bindgen-tests/tests/headers/class.hpp diff --git a/tests/headers/class_1_0.hpp b/bindgen-tests/tests/headers/class_1_0.hpp similarity index 100% rename from tests/headers/class_1_0.hpp rename to bindgen-tests/tests/headers/class_1_0.hpp diff --git a/tests/headers/class_nested.hpp b/bindgen-tests/tests/headers/class_nested.hpp similarity index 100% rename from tests/headers/class_nested.hpp rename to bindgen-tests/tests/headers/class_nested.hpp diff --git a/tests/headers/class_no_members.hpp b/bindgen-tests/tests/headers/class_no_members.hpp similarity index 100% rename from tests/headers/class_no_members.hpp rename to bindgen-tests/tests/headers/class_no_members.hpp diff --git a/tests/headers/class_static.hpp b/bindgen-tests/tests/headers/class_static.hpp similarity index 100% rename from tests/headers/class_static.hpp rename to bindgen-tests/tests/headers/class_static.hpp diff --git a/tests/headers/class_static_const.hpp b/bindgen-tests/tests/headers/class_static_const.hpp similarity index 100% rename from tests/headers/class_static_const.hpp rename to bindgen-tests/tests/headers/class_static_const.hpp diff --git a/tests/headers/class_use_as.hpp b/bindgen-tests/tests/headers/class_use_as.hpp similarity index 100% rename from tests/headers/class_use_as.hpp rename to bindgen-tests/tests/headers/class_use_as.hpp diff --git a/tests/headers/class_with_dtor.hpp b/bindgen-tests/tests/headers/class_with_dtor.hpp similarity index 100% rename from tests/headers/class_with_dtor.hpp rename to bindgen-tests/tests/headers/class_with_dtor.hpp diff --git a/tests/headers/class_with_inner_struct.hpp b/bindgen-tests/tests/headers/class_with_inner_struct.hpp similarity index 100% rename from tests/headers/class_with_inner_struct.hpp rename to bindgen-tests/tests/headers/class_with_inner_struct.hpp diff --git a/tests/headers/class_with_inner_struct_1_0.hpp b/bindgen-tests/tests/headers/class_with_inner_struct_1_0.hpp similarity index 100% rename from tests/headers/class_with_inner_struct_1_0.hpp rename to bindgen-tests/tests/headers/class_with_inner_struct_1_0.hpp diff --git a/tests/headers/class_with_typedef.hpp b/bindgen-tests/tests/headers/class_with_typedef.hpp similarity index 100% rename from tests/headers/class_with_typedef.hpp rename to bindgen-tests/tests/headers/class_with_typedef.hpp diff --git a/tests/headers/comment-indent.hpp b/bindgen-tests/tests/headers/comment-indent.hpp similarity index 100% rename from tests/headers/comment-indent.hpp rename to bindgen-tests/tests/headers/comment-indent.hpp diff --git a/tests/headers/complex.h b/bindgen-tests/tests/headers/complex.h similarity index 100% rename from tests/headers/complex.h rename to bindgen-tests/tests/headers/complex.h diff --git a/tests/headers/complex_global.h b/bindgen-tests/tests/headers/complex_global.h similarity index 100% rename from tests/headers/complex_global.h rename to bindgen-tests/tests/headers/complex_global.h diff --git a/tests/headers/const-const-mut-ptr.h b/bindgen-tests/tests/headers/const-const-mut-ptr.h similarity index 100% rename from tests/headers/const-const-mut-ptr.h rename to bindgen-tests/tests/headers/const-const-mut-ptr.h diff --git a/tests/headers/const_array.h b/bindgen-tests/tests/headers/const_array.h similarity index 100% rename from tests/headers/const_array.h rename to bindgen-tests/tests/headers/const_array.h diff --git a/tests/headers/const_array_fn_arg.h b/bindgen-tests/tests/headers/const_array_fn_arg.h similarity index 100% rename from tests/headers/const_array_fn_arg.h rename to bindgen-tests/tests/headers/const_array_fn_arg.h diff --git a/tests/headers/const_bool.hpp b/bindgen-tests/tests/headers/const_bool.hpp similarity index 100% rename from tests/headers/const_bool.hpp rename to bindgen-tests/tests/headers/const_bool.hpp diff --git a/tests/headers/const_enum_unnamed.hpp b/bindgen-tests/tests/headers/const_enum_unnamed.hpp similarity index 100% rename from tests/headers/const_enum_unnamed.hpp rename to bindgen-tests/tests/headers/const_enum_unnamed.hpp diff --git a/tests/headers/const_multidim_array_fn_arg.h b/bindgen-tests/tests/headers/const_multidim_array_fn_arg.h similarity index 100% rename from tests/headers/const_multidim_array_fn_arg.h rename to bindgen-tests/tests/headers/const_multidim_array_fn_arg.h diff --git a/tests/headers/const_ptr.hpp b/bindgen-tests/tests/headers/const_ptr.hpp similarity index 100% rename from tests/headers/const_ptr.hpp rename to bindgen-tests/tests/headers/const_ptr.hpp diff --git a/tests/headers/const_resolved_ty.h b/bindgen-tests/tests/headers/const_resolved_ty.h similarity index 100% rename from tests/headers/const_resolved_ty.h rename to bindgen-tests/tests/headers/const_resolved_ty.h diff --git a/tests/headers/const_tparam.hpp b/bindgen-tests/tests/headers/const_tparam.hpp similarity index 100% rename from tests/headers/const_tparam.hpp rename to bindgen-tests/tests/headers/const_tparam.hpp diff --git a/tests/headers/constant-evaluate.h b/bindgen-tests/tests/headers/constant-evaluate.h similarity index 100% rename from tests/headers/constant-evaluate.h rename to bindgen-tests/tests/headers/constant-evaluate.h diff --git a/tests/headers/constant-non-specialized-tp.hpp b/bindgen-tests/tests/headers/constant-non-specialized-tp.hpp similarity index 100% rename from tests/headers/constant-non-specialized-tp.hpp rename to bindgen-tests/tests/headers/constant-non-specialized-tp.hpp diff --git a/tests/headers/constified-enum-module-overflow.hpp b/bindgen-tests/tests/headers/constified-enum-module-overflow.hpp similarity index 100% rename from tests/headers/constified-enum-module-overflow.hpp rename to bindgen-tests/tests/headers/constified-enum-module-overflow.hpp diff --git a/tests/headers/constify-all-enums.h b/bindgen-tests/tests/headers/constify-all-enums.h similarity index 100% rename from tests/headers/constify-all-enums.h rename to bindgen-tests/tests/headers/constify-all-enums.h diff --git a/tests/headers/constify-enum.h b/bindgen-tests/tests/headers/constify-enum.h similarity index 100% rename from tests/headers/constify-enum.h rename to bindgen-tests/tests/headers/constify-enum.h diff --git a/tests/headers/constify-module-enums-basic.h b/bindgen-tests/tests/headers/constify-module-enums-basic.h similarity index 100% rename from tests/headers/constify-module-enums-basic.h rename to bindgen-tests/tests/headers/constify-module-enums-basic.h diff --git a/tests/headers/constify-module-enums-namespace.hpp b/bindgen-tests/tests/headers/constify-module-enums-namespace.hpp similarity index 100% rename from tests/headers/constify-module-enums-namespace.hpp rename to bindgen-tests/tests/headers/constify-module-enums-namespace.hpp diff --git a/tests/headers/constify-module-enums-shadow-name.h b/bindgen-tests/tests/headers/constify-module-enums-shadow-name.h similarity index 100% rename from tests/headers/constify-module-enums-shadow-name.h rename to bindgen-tests/tests/headers/constify-module-enums-shadow-name.h diff --git a/tests/headers/constify-module-enums-simple-alias.hpp b/bindgen-tests/tests/headers/constify-module-enums-simple-alias.hpp similarity index 100% rename from tests/headers/constify-module-enums-simple-alias.hpp rename to bindgen-tests/tests/headers/constify-module-enums-simple-alias.hpp diff --git a/tests/headers/constify-module-enums-simple-nonamespace.hpp b/bindgen-tests/tests/headers/constify-module-enums-simple-nonamespace.hpp similarity index 100% rename from tests/headers/constify-module-enums-simple-nonamespace.hpp rename to bindgen-tests/tests/headers/constify-module-enums-simple-nonamespace.hpp diff --git a/tests/headers/constify-module-enums-types.hpp b/bindgen-tests/tests/headers/constify-module-enums-types.hpp similarity index 100% rename from tests/headers/constify-module-enums-types.hpp rename to bindgen-tests/tests/headers/constify-module-enums-types.hpp diff --git a/tests/headers/constructor-tp.hpp b/bindgen-tests/tests/headers/constructor-tp.hpp similarity index 100% rename from tests/headers/constructor-tp.hpp rename to bindgen-tests/tests/headers/constructor-tp.hpp diff --git a/tests/headers/constructors.hpp b/bindgen-tests/tests/headers/constructors.hpp similarity index 100% rename from tests/headers/constructors.hpp rename to bindgen-tests/tests/headers/constructors.hpp diff --git a/tests/headers/constructors_1_33.hpp b/bindgen-tests/tests/headers/constructors_1_33.hpp similarity index 100% rename from tests/headers/constructors_1_33.hpp rename to bindgen-tests/tests/headers/constructors_1_33.hpp diff --git a/tests/headers/contains-vs-inherits-zero-sized.hpp b/bindgen-tests/tests/headers/contains-vs-inherits-zero-sized.hpp similarity index 100% rename from tests/headers/contains-vs-inherits-zero-sized.hpp rename to bindgen-tests/tests/headers/contains-vs-inherits-zero-sized.hpp diff --git a/tests/headers/convert-cpp-comment-to-rust.hpp b/bindgen-tests/tests/headers/convert-cpp-comment-to-rust.hpp similarity index 100% rename from tests/headers/convert-cpp-comment-to-rust.hpp rename to bindgen-tests/tests/headers/convert-cpp-comment-to-rust.hpp diff --git a/tests/headers/convert-floats.h b/bindgen-tests/tests/headers/convert-floats.h similarity index 100% rename from tests/headers/convert-floats.h rename to bindgen-tests/tests/headers/convert-floats.h diff --git a/tests/headers/core_ffi_c.h b/bindgen-tests/tests/headers/core_ffi_c.h similarity index 100% rename from tests/headers/core_ffi_c.h rename to bindgen-tests/tests/headers/core_ffi_c.h diff --git a/tests/headers/cpp-empty-layout.hpp b/bindgen-tests/tests/headers/cpp-empty-layout.hpp similarity index 100% rename from tests/headers/cpp-empty-layout.hpp rename to bindgen-tests/tests/headers/cpp-empty-layout.hpp diff --git a/tests/headers/crtp.hpp b/bindgen-tests/tests/headers/crtp.hpp similarity index 100% rename from tests/headers/crtp.hpp rename to bindgen-tests/tests/headers/crtp.hpp diff --git a/tests/headers/ctypes-prefix-path.h b/bindgen-tests/tests/headers/ctypes-prefix-path.h similarity index 100% rename from tests/headers/ctypes-prefix-path.h rename to bindgen-tests/tests/headers/ctypes-prefix-path.h diff --git a/tests/headers/dash_language.h b/bindgen-tests/tests/headers/dash_language.h similarity index 100% rename from tests/headers/dash_language.h rename to bindgen-tests/tests/headers/dash_language.h diff --git a/tests/headers/decl_extern_int_twice.h b/bindgen-tests/tests/headers/decl_extern_int_twice.h similarity index 100% rename from tests/headers/decl_extern_int_twice.h rename to bindgen-tests/tests/headers/decl_extern_int_twice.h diff --git a/tests/headers/decl_ptr_to_array.h b/bindgen-tests/tests/headers/decl_ptr_to_array.h similarity index 100% rename from tests/headers/decl_ptr_to_array.h rename to bindgen-tests/tests/headers/decl_ptr_to_array.h diff --git a/tests/headers/default-enum-style-constified-module.h b/bindgen-tests/tests/headers/default-enum-style-constified-module.h similarity index 100% rename from tests/headers/default-enum-style-constified-module.h rename to bindgen-tests/tests/headers/default-enum-style-constified-module.h diff --git a/tests/headers/default-macro-constant-type-signed.h b/bindgen-tests/tests/headers/default-macro-constant-type-signed.h similarity index 100% rename from tests/headers/default-macro-constant-type-signed.h rename to bindgen-tests/tests/headers/default-macro-constant-type-signed.h diff --git a/tests/headers/default-macro-constant-type-unsigned.h b/bindgen-tests/tests/headers/default-macro-constant-type-unsigned.h similarity index 100% rename from tests/headers/default-macro-constant-type-unsigned.h rename to bindgen-tests/tests/headers/default-macro-constant-type-unsigned.h diff --git a/tests/headers/default-macro-constant-type.h b/bindgen-tests/tests/headers/default-macro-constant-type.h similarity index 100% rename from tests/headers/default-macro-constant-type.h rename to bindgen-tests/tests/headers/default-macro-constant-type.h diff --git a/tests/headers/default-template-parameter.hpp b/bindgen-tests/tests/headers/default-template-parameter.hpp similarity index 100% rename from tests/headers/default-template-parameter.hpp rename to bindgen-tests/tests/headers/default-template-parameter.hpp diff --git a/tests/headers/deleted-function.hpp b/bindgen-tests/tests/headers/deleted-function.hpp similarity index 100% rename from tests/headers/deleted-function.hpp rename to bindgen-tests/tests/headers/deleted-function.hpp diff --git a/tests/headers/derive-bitfield-method-same-name.hpp b/bindgen-tests/tests/headers/derive-bitfield-method-same-name.hpp similarity index 100% rename from tests/headers/derive-bitfield-method-same-name.hpp rename to bindgen-tests/tests/headers/derive-bitfield-method-same-name.hpp diff --git a/tests/headers/derive-clone.h b/bindgen-tests/tests/headers/derive-clone.h similarity index 100% rename from tests/headers/derive-clone.h rename to bindgen-tests/tests/headers/derive-clone.h diff --git a/tests/headers/derive-clone_1_0.h b/bindgen-tests/tests/headers/derive-clone_1_0.h similarity index 100% rename from tests/headers/derive-clone_1_0.h rename to bindgen-tests/tests/headers/derive-clone_1_0.h diff --git a/tests/headers/derive-custom.h b/bindgen-tests/tests/headers/derive-custom.h similarity index 100% rename from tests/headers/derive-custom.h rename to bindgen-tests/tests/headers/derive-custom.h diff --git a/tests/headers/derive-debug-bitfield-core.hpp b/bindgen-tests/tests/headers/derive-debug-bitfield-core.hpp similarity index 100% rename from tests/headers/derive-debug-bitfield-core.hpp rename to bindgen-tests/tests/headers/derive-debug-bitfield-core.hpp diff --git a/tests/headers/derive-debug-bitfield.hpp b/bindgen-tests/tests/headers/derive-debug-bitfield.hpp similarity index 100% rename from tests/headers/derive-debug-bitfield.hpp rename to bindgen-tests/tests/headers/derive-debug-bitfield.hpp diff --git a/tests/headers/derive-debug-function-pointer.hpp b/bindgen-tests/tests/headers/derive-debug-function-pointer.hpp similarity index 100% rename from tests/headers/derive-debug-function-pointer.hpp rename to bindgen-tests/tests/headers/derive-debug-function-pointer.hpp diff --git a/tests/headers/derive-debug-generic.hpp b/bindgen-tests/tests/headers/derive-debug-generic.hpp similarity index 100% rename from tests/headers/derive-debug-generic.hpp rename to bindgen-tests/tests/headers/derive-debug-generic.hpp diff --git a/tests/headers/derive-debug-mangle-name.h b/bindgen-tests/tests/headers/derive-debug-mangle-name.h similarity index 100% rename from tests/headers/derive-debug-mangle-name.h rename to bindgen-tests/tests/headers/derive-debug-mangle-name.h diff --git a/tests/headers/derive-debug-opaque-template-instantiation.hpp b/bindgen-tests/tests/headers/derive-debug-opaque-template-instantiation.hpp similarity index 100% rename from tests/headers/derive-debug-opaque-template-instantiation.hpp rename to bindgen-tests/tests/headers/derive-debug-opaque-template-instantiation.hpp diff --git a/tests/headers/derive-debug-opaque.hpp b/bindgen-tests/tests/headers/derive-debug-opaque.hpp similarity index 100% rename from tests/headers/derive-debug-opaque.hpp rename to bindgen-tests/tests/headers/derive-debug-opaque.hpp diff --git a/tests/headers/derive-default-and-blocklist.hpp b/bindgen-tests/tests/headers/derive-default-and-blocklist.hpp similarity index 100% rename from tests/headers/derive-default-and-blocklist.hpp rename to bindgen-tests/tests/headers/derive-default-and-blocklist.hpp diff --git a/tests/headers/derive-fn-ptr.h b/bindgen-tests/tests/headers/derive-fn-ptr.h similarity index 100% rename from tests/headers/derive-fn-ptr.h rename to bindgen-tests/tests/headers/derive-fn-ptr.h diff --git a/tests/headers/derive-hash-and-blocklist.hpp b/bindgen-tests/tests/headers/derive-hash-and-blocklist.hpp similarity index 100% rename from tests/headers/derive-hash-and-blocklist.hpp rename to bindgen-tests/tests/headers/derive-hash-and-blocklist.hpp diff --git a/tests/headers/derive-hash-blocklisting.hpp b/bindgen-tests/tests/headers/derive-hash-blocklisting.hpp similarity index 100% rename from tests/headers/derive-hash-blocklisting.hpp rename to bindgen-tests/tests/headers/derive-hash-blocklisting.hpp diff --git a/tests/headers/derive-hash-struct-with-anon-struct-float.h b/bindgen-tests/tests/headers/derive-hash-struct-with-anon-struct-float.h similarity index 100% rename from tests/headers/derive-hash-struct-with-anon-struct-float.h rename to bindgen-tests/tests/headers/derive-hash-struct-with-anon-struct-float.h diff --git a/tests/headers/derive-hash-struct-with-float-array.h b/bindgen-tests/tests/headers/derive-hash-struct-with-float-array.h similarity index 100% rename from tests/headers/derive-hash-struct-with-float-array.h rename to bindgen-tests/tests/headers/derive-hash-struct-with-float-array.h diff --git a/tests/headers/derive-hash-struct-with-incomplete-array.h b/bindgen-tests/tests/headers/derive-hash-struct-with-incomplete-array.h similarity index 100% rename from tests/headers/derive-hash-struct-with-incomplete-array.h rename to bindgen-tests/tests/headers/derive-hash-struct-with-incomplete-array.h diff --git a/tests/headers/derive-hash-struct-with-pointer.h b/bindgen-tests/tests/headers/derive-hash-struct-with-pointer.h similarity index 100% rename from tests/headers/derive-hash-struct-with-pointer.h rename to bindgen-tests/tests/headers/derive-hash-struct-with-pointer.h diff --git a/tests/headers/derive-hash-template-def-float.hpp b/bindgen-tests/tests/headers/derive-hash-template-def-float.hpp similarity index 100% rename from tests/headers/derive-hash-template-def-float.hpp rename to bindgen-tests/tests/headers/derive-hash-template-def-float.hpp diff --git a/tests/headers/derive-hash-template-inst-float.hpp b/bindgen-tests/tests/headers/derive-hash-template-inst-float.hpp similarity index 100% rename from tests/headers/derive-hash-template-inst-float.hpp rename to bindgen-tests/tests/headers/derive-hash-template-inst-float.hpp diff --git a/tests/headers/derive-partialeq-and-blocklist.hpp b/bindgen-tests/tests/headers/derive-partialeq-and-blocklist.hpp similarity index 100% rename from tests/headers/derive-partialeq-and-blocklist.hpp rename to bindgen-tests/tests/headers/derive-partialeq-and-blocklist.hpp diff --git a/tests/headers/derive-partialeq-anonfield.h b/bindgen-tests/tests/headers/derive-partialeq-anonfield.h similarity index 100% rename from tests/headers/derive-partialeq-anonfield.h rename to bindgen-tests/tests/headers/derive-partialeq-anonfield.h diff --git a/tests/headers/derive-partialeq-base.hpp b/bindgen-tests/tests/headers/derive-partialeq-base.hpp similarity index 100% rename from tests/headers/derive-partialeq-base.hpp rename to bindgen-tests/tests/headers/derive-partialeq-base.hpp diff --git a/tests/headers/derive-partialeq-bitfield.hpp b/bindgen-tests/tests/headers/derive-partialeq-bitfield.hpp similarity index 100% rename from tests/headers/derive-partialeq-bitfield.hpp rename to bindgen-tests/tests/headers/derive-partialeq-bitfield.hpp diff --git a/tests/headers/derive-partialeq-core.h b/bindgen-tests/tests/headers/derive-partialeq-core.h similarity index 100% rename from tests/headers/derive-partialeq-core.h rename to bindgen-tests/tests/headers/derive-partialeq-core.h diff --git a/tests/headers/derive-partialeq-pointer.hpp b/bindgen-tests/tests/headers/derive-partialeq-pointer.hpp similarity index 100% rename from tests/headers/derive-partialeq-pointer.hpp rename to bindgen-tests/tests/headers/derive-partialeq-pointer.hpp diff --git a/tests/headers/derive-partialeq-union.hpp b/bindgen-tests/tests/headers/derive-partialeq-union.hpp similarity index 100% rename from tests/headers/derive-partialeq-union.hpp rename to bindgen-tests/tests/headers/derive-partialeq-union.hpp diff --git a/tests/headers/derive-partialeq-union_1_0.hpp b/bindgen-tests/tests/headers/derive-partialeq-union_1_0.hpp similarity index 100% rename from tests/headers/derive-partialeq-union_1_0.hpp rename to bindgen-tests/tests/headers/derive-partialeq-union_1_0.hpp diff --git a/tests/headers/disable-namespacing.hpp b/bindgen-tests/tests/headers/disable-namespacing.hpp similarity index 100% rename from tests/headers/disable-namespacing.hpp rename to bindgen-tests/tests/headers/disable-namespacing.hpp diff --git a/tests/headers/disable-nested-struct-naming.h b/bindgen-tests/tests/headers/disable-nested-struct-naming.h similarity index 100% rename from tests/headers/disable-nested-struct-naming.h rename to bindgen-tests/tests/headers/disable-nested-struct-naming.h diff --git a/tests/headers/disable-untagged-union.hpp b/bindgen-tests/tests/headers/disable-untagged-union.hpp similarity index 100% rename from tests/headers/disable-untagged-union.hpp rename to bindgen-tests/tests/headers/disable-untagged-union.hpp diff --git a/tests/headers/divide-by-zero-in-struct-layout.h b/bindgen-tests/tests/headers/divide-by-zero-in-struct-layout.h similarity index 100% rename from tests/headers/divide-by-zero-in-struct-layout.h rename to bindgen-tests/tests/headers/divide-by-zero-in-struct-layout.h diff --git a/tests/headers/do-not-derive-copy.hpp b/bindgen-tests/tests/headers/do-not-derive-copy.hpp similarity index 100% rename from tests/headers/do-not-derive-copy.hpp rename to bindgen-tests/tests/headers/do-not-derive-copy.hpp diff --git a/tests/headers/doggo-or-null.hpp b/bindgen-tests/tests/headers/doggo-or-null.hpp similarity index 100% rename from tests/headers/doggo-or-null.hpp rename to bindgen-tests/tests/headers/doggo-or-null.hpp diff --git a/tests/headers/dupe-enum-variant-in-namespace.h b/bindgen-tests/tests/headers/dupe-enum-variant-in-namespace.h similarity index 100% rename from tests/headers/dupe-enum-variant-in-namespace.h rename to bindgen-tests/tests/headers/dupe-enum-variant-in-namespace.h diff --git a/tests/headers/duplicated-namespaces-definitions.hpp b/bindgen-tests/tests/headers/duplicated-namespaces-definitions.hpp similarity index 100% rename from tests/headers/duplicated-namespaces-definitions.hpp rename to bindgen-tests/tests/headers/duplicated-namespaces-definitions.hpp diff --git a/tests/headers/duplicated-namespaces.hpp b/bindgen-tests/tests/headers/duplicated-namespaces.hpp similarity index 100% rename from tests/headers/duplicated-namespaces.hpp rename to bindgen-tests/tests/headers/duplicated-namespaces.hpp diff --git a/tests/headers/duplicated_constants_in_ns.hpp b/bindgen-tests/tests/headers/duplicated_constants_in_ns.hpp similarity index 100% rename from tests/headers/duplicated_constants_in_ns.hpp rename to bindgen-tests/tests/headers/duplicated_constants_in_ns.hpp diff --git a/tests/headers/dynamic_loading_attributes.h b/bindgen-tests/tests/headers/dynamic_loading_attributes.h similarity index 100% rename from tests/headers/dynamic_loading_attributes.h rename to bindgen-tests/tests/headers/dynamic_loading_attributes.h diff --git a/tests/headers/dynamic_loading_required.h b/bindgen-tests/tests/headers/dynamic_loading_required.h similarity index 100% rename from tests/headers/dynamic_loading_required.h rename to bindgen-tests/tests/headers/dynamic_loading_required.h diff --git a/tests/headers/dynamic_loading_simple.h b/bindgen-tests/tests/headers/dynamic_loading_simple.h similarity index 100% rename from tests/headers/dynamic_loading_simple.h rename to bindgen-tests/tests/headers/dynamic_loading_simple.h diff --git a/tests/headers/dynamic_loading_template.hpp b/bindgen-tests/tests/headers/dynamic_loading_template.hpp similarity index 100% rename from tests/headers/dynamic_loading_template.hpp rename to bindgen-tests/tests/headers/dynamic_loading_template.hpp diff --git a/tests/headers/dynamic_loading_with_allowlist.hpp b/bindgen-tests/tests/headers/dynamic_loading_with_allowlist.hpp similarity index 100% rename from tests/headers/dynamic_loading_with_allowlist.hpp rename to bindgen-tests/tests/headers/dynamic_loading_with_allowlist.hpp diff --git a/tests/headers/dynamic_loading_with_blocklist.hpp b/bindgen-tests/tests/headers/dynamic_loading_with_blocklist.hpp similarity index 100% rename from tests/headers/dynamic_loading_with_blocklist.hpp rename to bindgen-tests/tests/headers/dynamic_loading_with_blocklist.hpp diff --git a/tests/headers/dynamic_loading_with_class.hpp b/bindgen-tests/tests/headers/dynamic_loading_with_class.hpp similarity index 100% rename from tests/headers/dynamic_loading_with_class.hpp rename to bindgen-tests/tests/headers/dynamic_loading_with_class.hpp diff --git a/tests/headers/elaborated.hpp b/bindgen-tests/tests/headers/elaborated.hpp similarity index 100% rename from tests/headers/elaborated.hpp rename to bindgen-tests/tests/headers/elaborated.hpp diff --git a/tests/headers/empty-enum.h b/bindgen-tests/tests/headers/empty-enum.h similarity index 100% rename from tests/headers/empty-enum.h rename to bindgen-tests/tests/headers/empty-enum.h diff --git a/tests/headers/empty-union.hpp b/bindgen-tests/tests/headers/empty-union.hpp similarity index 100% rename from tests/headers/empty-union.hpp rename to bindgen-tests/tests/headers/empty-union.hpp diff --git a/tests/headers/empty_template_param_name.hpp b/bindgen-tests/tests/headers/empty_template_param_name.hpp similarity index 100% rename from tests/headers/empty_template_param_name.hpp rename to bindgen-tests/tests/headers/empty_template_param_name.hpp diff --git a/tests/headers/enum-default-bitfield.h b/bindgen-tests/tests/headers/enum-default-bitfield.h similarity index 100% rename from tests/headers/enum-default-bitfield.h rename to bindgen-tests/tests/headers/enum-default-bitfield.h diff --git a/tests/headers/enum-default-consts.h b/bindgen-tests/tests/headers/enum-default-consts.h similarity index 100% rename from tests/headers/enum-default-consts.h rename to bindgen-tests/tests/headers/enum-default-consts.h diff --git a/tests/headers/enum-default-module.h b/bindgen-tests/tests/headers/enum-default-module.h similarity index 100% rename from tests/headers/enum-default-module.h rename to bindgen-tests/tests/headers/enum-default-module.h diff --git a/tests/headers/enum-default-rust.h b/bindgen-tests/tests/headers/enum-default-rust.h similarity index 100% rename from tests/headers/enum-default-rust.h rename to bindgen-tests/tests/headers/enum-default-rust.h diff --git a/tests/headers/enum-doc-bitfield.h b/bindgen-tests/tests/headers/enum-doc-bitfield.h similarity index 100% rename from tests/headers/enum-doc-bitfield.h rename to bindgen-tests/tests/headers/enum-doc-bitfield.h diff --git a/tests/headers/enum-doc-mod.h b/bindgen-tests/tests/headers/enum-doc-mod.h similarity index 100% rename from tests/headers/enum-doc-mod.h rename to bindgen-tests/tests/headers/enum-doc-mod.h diff --git a/tests/headers/enum-doc-rusty.h b/bindgen-tests/tests/headers/enum-doc-rusty.h similarity index 100% rename from tests/headers/enum-doc-rusty.h rename to bindgen-tests/tests/headers/enum-doc-rusty.h diff --git a/tests/headers/enum-doc.h b/bindgen-tests/tests/headers/enum-doc.h similarity index 100% rename from tests/headers/enum-doc.h rename to bindgen-tests/tests/headers/enum-doc.h diff --git a/tests/headers/enum-no-debug-rust.h b/bindgen-tests/tests/headers/enum-no-debug-rust.h similarity index 100% rename from tests/headers/enum-no-debug-rust.h rename to bindgen-tests/tests/headers/enum-no-debug-rust.h diff --git a/tests/headers/enum-translate-type.hpp b/bindgen-tests/tests/headers/enum-translate-type.hpp similarity index 100% rename from tests/headers/enum-translate-type.hpp rename to bindgen-tests/tests/headers/enum-translate-type.hpp diff --git a/tests/headers/enum-undefault.h b/bindgen-tests/tests/headers/enum-undefault.h similarity index 100% rename from tests/headers/enum-undefault.h rename to bindgen-tests/tests/headers/enum-undefault.h diff --git a/tests/headers/enum-variant-replaces.h b/bindgen-tests/tests/headers/enum-variant-replaces.h similarity index 100% rename from tests/headers/enum-variant-replaces.h rename to bindgen-tests/tests/headers/enum-variant-replaces.h diff --git a/tests/headers/enum.h b/bindgen-tests/tests/headers/enum.h similarity index 100% rename from tests/headers/enum.h rename to bindgen-tests/tests/headers/enum.h diff --git a/tests/headers/enum_alias.hpp b/bindgen-tests/tests/headers/enum_alias.hpp similarity index 100% rename from tests/headers/enum_alias.hpp rename to bindgen-tests/tests/headers/enum_alias.hpp diff --git a/tests/headers/enum_and_vtable_mangling.hpp b/bindgen-tests/tests/headers/enum_and_vtable_mangling.hpp similarity index 100% rename from tests/headers/enum_and_vtable_mangling.hpp rename to bindgen-tests/tests/headers/enum_and_vtable_mangling.hpp diff --git a/tests/headers/enum_dupe.h b/bindgen-tests/tests/headers/enum_dupe.h similarity index 100% rename from tests/headers/enum_dupe.h rename to bindgen-tests/tests/headers/enum_dupe.h diff --git a/tests/headers/enum_explicit_type.hpp b/bindgen-tests/tests/headers/enum_explicit_type.hpp similarity index 100% rename from tests/headers/enum_explicit_type.hpp rename to bindgen-tests/tests/headers/enum_explicit_type.hpp diff --git a/tests/headers/enum_explicit_type_constants.hpp b/bindgen-tests/tests/headers/enum_explicit_type_constants.hpp similarity index 100% rename from tests/headers/enum_explicit_type_constants.hpp rename to bindgen-tests/tests/headers/enum_explicit_type_constants.hpp diff --git a/tests/headers/enum_in_template.hpp b/bindgen-tests/tests/headers/enum_in_template.hpp similarity index 100% rename from tests/headers/enum_in_template.hpp rename to bindgen-tests/tests/headers/enum_in_template.hpp diff --git a/tests/headers/enum_in_template_with_typedef.hpp b/bindgen-tests/tests/headers/enum_in_template_with_typedef.hpp similarity index 100% rename from tests/headers/enum_in_template_with_typedef.hpp rename to bindgen-tests/tests/headers/enum_in_template_with_typedef.hpp diff --git a/tests/headers/enum_negative.h b/bindgen-tests/tests/headers/enum_negative.h similarity index 100% rename from tests/headers/enum_negative.h rename to bindgen-tests/tests/headers/enum_negative.h diff --git a/tests/headers/enum_packed.h b/bindgen-tests/tests/headers/enum_packed.h similarity index 100% rename from tests/headers/enum_packed.h rename to bindgen-tests/tests/headers/enum_packed.h diff --git a/tests/headers/error-E0600-cannot-apply-unary-negation-to-u32.h b/bindgen-tests/tests/headers/error-E0600-cannot-apply-unary-negation-to-u32.h similarity index 100% rename from tests/headers/error-E0600-cannot-apply-unary-negation-to-u32.h rename to bindgen-tests/tests/headers/error-E0600-cannot-apply-unary-negation-to-u32.h diff --git a/tests/headers/eval-value-dependent.hpp b/bindgen-tests/tests/headers/eval-value-dependent.hpp similarity index 100% rename from tests/headers/eval-value-dependent.hpp rename to bindgen-tests/tests/headers/eval-value-dependent.hpp diff --git a/tests/headers/eval-variadic-template-parameter.hpp b/bindgen-tests/tests/headers/eval-variadic-template-parameter.hpp similarity index 100% rename from tests/headers/eval-variadic-template-parameter.hpp rename to bindgen-tests/tests/headers/eval-variadic-template-parameter.hpp diff --git a/tests/headers/explicit-padding.h b/bindgen-tests/tests/headers/explicit-padding.h similarity index 100% rename from tests/headers/explicit-padding.h rename to bindgen-tests/tests/headers/explicit-padding.h diff --git a/tests/headers/extern-const-struct.h b/bindgen-tests/tests/headers/extern-const-struct.h similarity index 100% rename from tests/headers/extern-const-struct.h rename to bindgen-tests/tests/headers/extern-const-struct.h diff --git a/tests/headers/extern.hpp b/bindgen-tests/tests/headers/extern.hpp similarity index 100% rename from tests/headers/extern.hpp rename to bindgen-tests/tests/headers/extern.hpp diff --git a/tests/headers/fit-macro-constant-types-signed.h b/bindgen-tests/tests/headers/fit-macro-constant-types-signed.h similarity index 100% rename from tests/headers/fit-macro-constant-types-signed.h rename to bindgen-tests/tests/headers/fit-macro-constant-types-signed.h diff --git a/tests/headers/fit-macro-constant-types.h b/bindgen-tests/tests/headers/fit-macro-constant-types.h similarity index 100% rename from tests/headers/fit-macro-constant-types.h rename to bindgen-tests/tests/headers/fit-macro-constant-types.h diff --git a/tests/headers/float128.hpp b/bindgen-tests/tests/headers/float128.hpp similarity index 100% rename from tests/headers/float128.hpp rename to bindgen-tests/tests/headers/float128.hpp diff --git a/tests/headers/forward-declaration-autoptr.hpp b/bindgen-tests/tests/headers/forward-declaration-autoptr.hpp similarity index 100% rename from tests/headers/forward-declaration-autoptr.hpp rename to bindgen-tests/tests/headers/forward-declaration-autoptr.hpp diff --git a/tests/headers/forward-enum-decl.hpp b/bindgen-tests/tests/headers/forward-enum-decl.hpp similarity index 100% rename from tests/headers/forward-enum-decl.hpp rename to bindgen-tests/tests/headers/forward-enum-decl.hpp diff --git a/tests/headers/forward-inherit-struct-with-fields.hpp b/bindgen-tests/tests/headers/forward-inherit-struct-with-fields.hpp similarity index 100% rename from tests/headers/forward-inherit-struct-with-fields.hpp rename to bindgen-tests/tests/headers/forward-inherit-struct-with-fields.hpp diff --git a/tests/headers/forward-inherit-struct.hpp b/bindgen-tests/tests/headers/forward-inherit-struct.hpp similarity index 100% rename from tests/headers/forward-inherit-struct.hpp rename to bindgen-tests/tests/headers/forward-inherit-struct.hpp diff --git a/tests/headers/forward_declared_complex_types.hpp b/bindgen-tests/tests/headers/forward_declared_complex_types.hpp similarity index 100% rename from tests/headers/forward_declared_complex_types.hpp rename to bindgen-tests/tests/headers/forward_declared_complex_types.hpp diff --git a/tests/headers/forward_declared_complex_types_1_0.hpp b/bindgen-tests/tests/headers/forward_declared_complex_types_1_0.hpp similarity index 100% rename from tests/headers/forward_declared_complex_types_1_0.hpp rename to bindgen-tests/tests/headers/forward_declared_complex_types_1_0.hpp diff --git a/tests/headers/forward_declared_opaque.h b/bindgen-tests/tests/headers/forward_declared_opaque.h similarity index 100% rename from tests/headers/forward_declared_opaque.h rename to bindgen-tests/tests/headers/forward_declared_opaque.h diff --git a/tests/headers/forward_declared_struct.h b/bindgen-tests/tests/headers/forward_declared_struct.h similarity index 100% rename from tests/headers/forward_declared_struct.h rename to bindgen-tests/tests/headers/forward_declared_struct.h diff --git a/tests/headers/func_proto.h b/bindgen-tests/tests/headers/func_proto.h similarity index 100% rename from tests/headers/func_proto.h rename to bindgen-tests/tests/headers/func_proto.h diff --git a/tests/headers/func_ptr.h b/bindgen-tests/tests/headers/func_ptr.h similarity index 100% rename from tests/headers/func_ptr.h rename to bindgen-tests/tests/headers/func_ptr.h diff --git a/tests/headers/func_ptr_in_struct.h b/bindgen-tests/tests/headers/func_ptr_in_struct.h similarity index 100% rename from tests/headers/func_ptr_in_struct.h rename to bindgen-tests/tests/headers/func_ptr_in_struct.h diff --git a/tests/headers/func_ptr_return_type.h b/bindgen-tests/tests/headers/func_ptr_return_type.h similarity index 100% rename from tests/headers/func_ptr_return_type.h rename to bindgen-tests/tests/headers/func_ptr_return_type.h diff --git a/tests/headers/func_return_must_use.h b/bindgen-tests/tests/headers/func_return_must_use.h similarity index 100% rename from tests/headers/func_return_must_use.h rename to bindgen-tests/tests/headers/func_return_must_use.h diff --git a/tests/headers/func_with_array_arg.h b/bindgen-tests/tests/headers/func_with_array_arg.h similarity index 100% rename from tests/headers/func_with_array_arg.h rename to bindgen-tests/tests/headers/func_with_array_arg.h diff --git a/tests/headers/func_with_func_ptr_arg.h b/bindgen-tests/tests/headers/func_with_func_ptr_arg.h similarity index 100% rename from tests/headers/func_with_func_ptr_arg.h rename to bindgen-tests/tests/headers/func_with_func_ptr_arg.h diff --git a/tests/headers/function-typedef-stdcall.h b/bindgen-tests/tests/headers/function-typedef-stdcall.h similarity index 100% rename from tests/headers/function-typedef-stdcall.h rename to bindgen-tests/tests/headers/function-typedef-stdcall.h diff --git a/tests/headers/gen-constructors-neg.hpp b/bindgen-tests/tests/headers/gen-constructors-neg.hpp similarity index 100% rename from tests/headers/gen-constructors-neg.hpp rename to bindgen-tests/tests/headers/gen-constructors-neg.hpp diff --git a/tests/headers/gen-constructors.hpp b/bindgen-tests/tests/headers/gen-constructors.hpp similarity index 100% rename from tests/headers/gen-constructors.hpp rename to bindgen-tests/tests/headers/gen-constructors.hpp diff --git a/tests/headers/gen-destructors-neg.hpp b/bindgen-tests/tests/headers/gen-destructors-neg.hpp similarity index 100% rename from tests/headers/gen-destructors-neg.hpp rename to bindgen-tests/tests/headers/gen-destructors-neg.hpp diff --git a/tests/headers/gen-destructors.hpp b/bindgen-tests/tests/headers/gen-destructors.hpp similarity index 100% rename from tests/headers/gen-destructors.hpp rename to bindgen-tests/tests/headers/gen-destructors.hpp diff --git a/tests/headers/generate-inline.hpp b/bindgen-tests/tests/headers/generate-inline.hpp similarity index 100% rename from tests/headers/generate-inline.hpp rename to bindgen-tests/tests/headers/generate-inline.hpp diff --git a/tests/headers/i128.h b/bindgen-tests/tests/headers/i128.h similarity index 100% rename from tests/headers/i128.h rename to bindgen-tests/tests/headers/i128.h diff --git a/tests/headers/in_class_typedef.hpp b/bindgen-tests/tests/headers/in_class_typedef.hpp similarity index 100% rename from tests/headers/in_class_typedef.hpp rename to bindgen-tests/tests/headers/in_class_typedef.hpp diff --git a/tests/headers/incomplete-array-padding.h b/bindgen-tests/tests/headers/incomplete-array-padding.h similarity index 100% rename from tests/headers/incomplete-array-padding.h rename to bindgen-tests/tests/headers/incomplete-array-padding.h diff --git a/tests/headers/infinite-macro.h b/bindgen-tests/tests/headers/infinite-macro.h similarity index 100% rename from tests/headers/infinite-macro.h rename to bindgen-tests/tests/headers/infinite-macro.h diff --git a/tests/headers/inherit-from-template-instantiation-with-vtable.hpp b/bindgen-tests/tests/headers/inherit-from-template-instantiation-with-vtable.hpp similarity index 100% rename from tests/headers/inherit-from-template-instantiation-with-vtable.hpp rename to bindgen-tests/tests/headers/inherit-from-template-instantiation-with-vtable.hpp diff --git a/tests/headers/inherit-namespaced.hpp b/bindgen-tests/tests/headers/inherit-namespaced.hpp similarity index 100% rename from tests/headers/inherit-namespaced.hpp rename to bindgen-tests/tests/headers/inherit-namespaced.hpp diff --git a/tests/headers/inherit_named.hpp b/bindgen-tests/tests/headers/inherit_named.hpp similarity index 100% rename from tests/headers/inherit_named.hpp rename to bindgen-tests/tests/headers/inherit_named.hpp diff --git a/tests/headers/inherit_typedef.hpp b/bindgen-tests/tests/headers/inherit_typedef.hpp similarity index 100% rename from tests/headers/inherit_typedef.hpp rename to bindgen-tests/tests/headers/inherit_typedef.hpp diff --git a/tests/headers/inline-function.h b/bindgen-tests/tests/headers/inline-function.h similarity index 100% rename from tests/headers/inline-function.h rename to bindgen-tests/tests/headers/inline-function.h diff --git a/tests/headers/inline_namespace.hpp b/bindgen-tests/tests/headers/inline_namespace.hpp similarity index 100% rename from tests/headers/inline_namespace.hpp rename to bindgen-tests/tests/headers/inline_namespace.hpp diff --git a/tests/headers/inline_namespace_allowlist.hpp b/bindgen-tests/tests/headers/inline_namespace_allowlist.hpp similarity index 100% rename from tests/headers/inline_namespace_allowlist.hpp rename to bindgen-tests/tests/headers/inline_namespace_allowlist.hpp diff --git a/tests/headers/inline_namespace_conservative.hpp b/bindgen-tests/tests/headers/inline_namespace_conservative.hpp similarity index 100% rename from tests/headers/inline_namespace_conservative.hpp rename to bindgen-tests/tests/headers/inline_namespace_conservative.hpp diff --git a/tests/headers/inline_namespace_no_ns_enabled.hpp b/bindgen-tests/tests/headers/inline_namespace_no_ns_enabled.hpp similarity index 100% rename from tests/headers/inline_namespace_no_ns_enabled.hpp rename to bindgen-tests/tests/headers/inline_namespace_no_ns_enabled.hpp diff --git a/tests/headers/inner-typedef-gh422.hpp b/bindgen-tests/tests/headers/inner-typedef-gh422.hpp similarity index 100% rename from tests/headers/inner-typedef-gh422.hpp rename to bindgen-tests/tests/headers/inner-typedef-gh422.hpp diff --git a/tests/headers/inner_const.hpp b/bindgen-tests/tests/headers/inner_const.hpp similarity index 100% rename from tests/headers/inner_const.hpp rename to bindgen-tests/tests/headers/inner_const.hpp diff --git a/tests/headers/inner_template_self.hpp b/bindgen-tests/tests/headers/inner_template_self.hpp similarity index 100% rename from tests/headers/inner_template_self.hpp rename to bindgen-tests/tests/headers/inner_template_self.hpp diff --git a/tests/headers/int128_t.h b/bindgen-tests/tests/headers/int128_t.h similarity index 100% rename from tests/headers/int128_t.h rename to bindgen-tests/tests/headers/int128_t.h diff --git a/tests/headers/issue-1025-unknown-enum-repr.hpp b/bindgen-tests/tests/headers/issue-1025-unknown-enum-repr.hpp similarity index 100% rename from tests/headers/issue-1025-unknown-enum-repr.hpp rename to bindgen-tests/tests/headers/issue-1025-unknown-enum-repr.hpp diff --git a/tests/headers/issue-1034.h b/bindgen-tests/tests/headers/issue-1034.h similarity index 100% rename from tests/headers/issue-1034.h rename to bindgen-tests/tests/headers/issue-1034.h diff --git a/tests/headers/issue-1040.h b/bindgen-tests/tests/headers/issue-1040.h similarity index 100% rename from tests/headers/issue-1040.h rename to bindgen-tests/tests/headers/issue-1040.h diff --git a/tests/headers/issue-1076-unnamed-bitfield-alignment.h b/bindgen-tests/tests/headers/issue-1076-unnamed-bitfield-alignment.h similarity index 100% rename from tests/headers/issue-1076-unnamed-bitfield-alignment.h rename to bindgen-tests/tests/headers/issue-1076-unnamed-bitfield-alignment.h diff --git a/tests/headers/issue-1113-template-references.hpp b/bindgen-tests/tests/headers/issue-1113-template-references.hpp similarity index 100% rename from tests/headers/issue-1113-template-references.hpp rename to bindgen-tests/tests/headers/issue-1113-template-references.hpp diff --git a/tests/headers/issue-1118-using-forward-decl.hpp b/bindgen-tests/tests/headers/issue-1118-using-forward-decl.hpp similarity index 100% rename from tests/headers/issue-1118-using-forward-decl.hpp rename to bindgen-tests/tests/headers/issue-1118-using-forward-decl.hpp diff --git a/tests/headers/issue-1197-pure-virtual-stuff.hpp b/bindgen-tests/tests/headers/issue-1197-pure-virtual-stuff.hpp similarity index 100% rename from tests/headers/issue-1197-pure-virtual-stuff.hpp rename to bindgen-tests/tests/headers/issue-1197-pure-virtual-stuff.hpp diff --git a/tests/headers/issue-1198-alias-rust-bitfield-enum.h b/bindgen-tests/tests/headers/issue-1198-alias-rust-bitfield-enum.h similarity index 100% rename from tests/headers/issue-1198-alias-rust-bitfield-enum.h rename to bindgen-tests/tests/headers/issue-1198-alias-rust-bitfield-enum.h diff --git a/tests/headers/issue-1198-alias-rust-const-mod-bitfield-enum.h b/bindgen-tests/tests/headers/issue-1198-alias-rust-const-mod-bitfield-enum.h similarity index 100% rename from tests/headers/issue-1198-alias-rust-const-mod-bitfield-enum.h rename to bindgen-tests/tests/headers/issue-1198-alias-rust-const-mod-bitfield-enum.h diff --git a/tests/headers/issue-1198-alias-rust-const-mod-enum.h b/bindgen-tests/tests/headers/issue-1198-alias-rust-const-mod-enum.h similarity index 100% rename from tests/headers/issue-1198-alias-rust-const-mod-enum.h rename to bindgen-tests/tests/headers/issue-1198-alias-rust-const-mod-enum.h diff --git a/tests/headers/issue-1198-alias-rust-enum.h b/bindgen-tests/tests/headers/issue-1198-alias-rust-enum.h similarity index 100% rename from tests/headers/issue-1198-alias-rust-enum.h rename to bindgen-tests/tests/headers/issue-1198-alias-rust-enum.h diff --git a/tests/headers/issue-1216-variadic-member.h b/bindgen-tests/tests/headers/issue-1216-variadic-member.h similarity index 100% rename from tests/headers/issue-1216-variadic-member.h rename to bindgen-tests/tests/headers/issue-1216-variadic-member.h diff --git a/tests/headers/issue-1238-fwd-no-copy.h b/bindgen-tests/tests/headers/issue-1238-fwd-no-copy.h similarity index 100% rename from tests/headers/issue-1238-fwd-no-copy.h rename to bindgen-tests/tests/headers/issue-1238-fwd-no-copy.h diff --git a/tests/headers/issue-1281.h b/bindgen-tests/tests/headers/issue-1281.h similarity index 100% rename from tests/headers/issue-1281.h rename to bindgen-tests/tests/headers/issue-1281.h diff --git a/tests/headers/issue-1285.h b/bindgen-tests/tests/headers/issue-1285.h similarity index 100% rename from tests/headers/issue-1285.h rename to bindgen-tests/tests/headers/issue-1285.h diff --git a/tests/headers/issue-1291.hpp b/bindgen-tests/tests/headers/issue-1291.hpp similarity index 100% rename from tests/headers/issue-1291.hpp rename to bindgen-tests/tests/headers/issue-1291.hpp diff --git a/tests/headers/issue-1350-attribute-overloadable.h b/bindgen-tests/tests/headers/issue-1350-attribute-overloadable.h similarity index 100% rename from tests/headers/issue-1350-attribute-overloadable.h rename to bindgen-tests/tests/headers/issue-1350-attribute-overloadable.h diff --git a/tests/headers/issue-1382-rust-primitive-types.h b/bindgen-tests/tests/headers/issue-1382-rust-primitive-types.h similarity index 100% rename from tests/headers/issue-1382-rust-primitive-types.h rename to bindgen-tests/tests/headers/issue-1382-rust-primitive-types.h diff --git a/tests/headers/issue-1435.hpp b/bindgen-tests/tests/headers/issue-1435.hpp similarity index 100% rename from tests/headers/issue-1435.hpp rename to bindgen-tests/tests/headers/issue-1435.hpp diff --git a/tests/headers/issue-1443.hpp b/bindgen-tests/tests/headers/issue-1443.hpp similarity index 100% rename from tests/headers/issue-1443.hpp rename to bindgen-tests/tests/headers/issue-1443.hpp diff --git a/tests/headers/issue-1454.h b/bindgen-tests/tests/headers/issue-1454.h similarity index 100% rename from tests/headers/issue-1454.h rename to bindgen-tests/tests/headers/issue-1454.h diff --git a/tests/headers/issue-1464.hpp b/bindgen-tests/tests/headers/issue-1464.hpp similarity index 100% rename from tests/headers/issue-1464.hpp rename to bindgen-tests/tests/headers/issue-1464.hpp diff --git a/tests/headers/issue-1488-enum-new-type.h b/bindgen-tests/tests/headers/issue-1488-enum-new-type.h similarity index 100% rename from tests/headers/issue-1488-enum-new-type.h rename to bindgen-tests/tests/headers/issue-1488-enum-new-type.h diff --git a/tests/headers/issue-1488-options.h b/bindgen-tests/tests/headers/issue-1488-options.h similarity index 100% rename from tests/headers/issue-1488-options.h rename to bindgen-tests/tests/headers/issue-1488-options.h diff --git a/tests/headers/issue-1488-template-alias-new-type.hpp b/bindgen-tests/tests/headers/issue-1488-template-alias-new-type.hpp similarity index 100% rename from tests/headers/issue-1488-template-alias-new-type.hpp rename to bindgen-tests/tests/headers/issue-1488-template-alias-new-type.hpp diff --git a/tests/headers/issue-1498.h b/bindgen-tests/tests/headers/issue-1498.h similarity index 100% rename from tests/headers/issue-1498.h rename to bindgen-tests/tests/headers/issue-1498.h diff --git a/tests/headers/issue-1514.hpp b/bindgen-tests/tests/headers/issue-1514.hpp similarity index 100% rename from tests/headers/issue-1514.hpp rename to bindgen-tests/tests/headers/issue-1514.hpp diff --git a/tests/headers/issue-1554.h b/bindgen-tests/tests/headers/issue-1554.h similarity index 100% rename from tests/headers/issue-1554.h rename to bindgen-tests/tests/headers/issue-1554.h diff --git a/tests/headers/issue-1599-opaque-typedef-to-enum.h b/bindgen-tests/tests/headers/issue-1599-opaque-typedef-to-enum.h similarity index 100% rename from tests/headers/issue-1599-opaque-typedef-to-enum.h rename to bindgen-tests/tests/headers/issue-1599-opaque-typedef-to-enum.h diff --git a/tests/headers/issue-1676-macro-namespace-prefix.hpp b/bindgen-tests/tests/headers/issue-1676-macro-namespace-prefix.hpp similarity index 100% rename from tests/headers/issue-1676-macro-namespace-prefix.hpp rename to bindgen-tests/tests/headers/issue-1676-macro-namespace-prefix.hpp diff --git a/tests/headers/issue-1947.h b/bindgen-tests/tests/headers/issue-1947.h similarity index 100% rename from tests/headers/issue-1947.h rename to bindgen-tests/tests/headers/issue-1947.h diff --git a/tests/headers/issue-1977-larger-arrays.hpp b/bindgen-tests/tests/headers/issue-1977-larger-arrays.hpp similarity index 100% rename from tests/headers/issue-1977-larger-arrays.hpp rename to bindgen-tests/tests/headers/issue-1977-larger-arrays.hpp diff --git a/tests/headers/issue-1995.h b/bindgen-tests/tests/headers/issue-1995.h similarity index 100% rename from tests/headers/issue-1995.h rename to bindgen-tests/tests/headers/issue-1995.h diff --git a/tests/headers/issue-2019.hpp b/bindgen-tests/tests/headers/issue-2019.hpp similarity index 100% rename from tests/headers/issue-2019.hpp rename to bindgen-tests/tests/headers/issue-2019.hpp diff --git a/tests/headers/issue-2239-template-dependent-bit-width.hpp b/bindgen-tests/tests/headers/issue-2239-template-dependent-bit-width.hpp similarity index 100% rename from tests/headers/issue-2239-template-dependent-bit-width.hpp rename to bindgen-tests/tests/headers/issue-2239-template-dependent-bit-width.hpp diff --git a/tests/headers/issue-358.hpp b/bindgen-tests/tests/headers/issue-358.hpp similarity index 100% rename from tests/headers/issue-358.hpp rename to bindgen-tests/tests/headers/issue-358.hpp diff --git a/tests/headers/issue-372.hpp b/bindgen-tests/tests/headers/issue-372.hpp similarity index 100% rename from tests/headers/issue-372.hpp rename to bindgen-tests/tests/headers/issue-372.hpp diff --git a/tests/headers/issue-410.hpp b/bindgen-tests/tests/headers/issue-410.hpp similarity index 100% rename from tests/headers/issue-410.hpp rename to bindgen-tests/tests/headers/issue-410.hpp diff --git a/tests/headers/issue-446.hpp b/bindgen-tests/tests/headers/issue-446.hpp similarity index 100% rename from tests/headers/issue-446.hpp rename to bindgen-tests/tests/headers/issue-446.hpp diff --git a/tests/headers/issue-447.hpp b/bindgen-tests/tests/headers/issue-447.hpp similarity index 100% rename from tests/headers/issue-447.hpp rename to bindgen-tests/tests/headers/issue-447.hpp diff --git a/tests/headers/issue-493.hpp b/bindgen-tests/tests/headers/issue-493.hpp similarity index 100% rename from tests/headers/issue-493.hpp rename to bindgen-tests/tests/headers/issue-493.hpp diff --git a/tests/headers/issue-493_1_0.hpp b/bindgen-tests/tests/headers/issue-493_1_0.hpp similarity index 100% rename from tests/headers/issue-493_1_0.hpp rename to bindgen-tests/tests/headers/issue-493_1_0.hpp diff --git a/tests/headers/issue-511.h b/bindgen-tests/tests/headers/issue-511.h similarity index 100% rename from tests/headers/issue-511.h rename to bindgen-tests/tests/headers/issue-511.h diff --git a/tests/headers/issue-537-repr-packed-n.h b/bindgen-tests/tests/headers/issue-537-repr-packed-n.h similarity index 100% rename from tests/headers/issue-537-repr-packed-n.h rename to bindgen-tests/tests/headers/issue-537-repr-packed-n.h diff --git a/tests/headers/issue-537.h b/bindgen-tests/tests/headers/issue-537.h similarity index 100% rename from tests/headers/issue-537.h rename to bindgen-tests/tests/headers/issue-537.h diff --git a/tests/headers/issue-544-stylo-creduce-2.hpp b/bindgen-tests/tests/headers/issue-544-stylo-creduce-2.hpp similarity index 100% rename from tests/headers/issue-544-stylo-creduce-2.hpp rename to bindgen-tests/tests/headers/issue-544-stylo-creduce-2.hpp diff --git a/tests/headers/issue-544-stylo-creduce.hpp b/bindgen-tests/tests/headers/issue-544-stylo-creduce.hpp similarity index 100% rename from tests/headers/issue-544-stylo-creduce.hpp rename to bindgen-tests/tests/headers/issue-544-stylo-creduce.hpp diff --git a/tests/headers/issue-569-non-type-template-params-causing-layout-test-failures.hpp b/bindgen-tests/tests/headers/issue-569-non-type-template-params-causing-layout-test-failures.hpp similarity index 100% rename from tests/headers/issue-569-non-type-template-params-causing-layout-test-failures.hpp rename to bindgen-tests/tests/headers/issue-569-non-type-template-params-causing-layout-test-failures.hpp diff --git a/tests/headers/issue-573-layout-test-failures.hpp b/bindgen-tests/tests/headers/issue-573-layout-test-failures.hpp similarity index 100% rename from tests/headers/issue-573-layout-test-failures.hpp rename to bindgen-tests/tests/headers/issue-573-layout-test-failures.hpp diff --git a/tests/headers/issue-574-assertion-failure-in-codegen.hpp b/bindgen-tests/tests/headers/issue-574-assertion-failure-in-codegen.hpp similarity index 100% rename from tests/headers/issue-574-assertion-failure-in-codegen.hpp rename to bindgen-tests/tests/headers/issue-574-assertion-failure-in-codegen.hpp diff --git a/tests/headers/issue-584-stylo-template-analysis-panic.hpp b/bindgen-tests/tests/headers/issue-584-stylo-template-analysis-panic.hpp similarity index 100% rename from tests/headers/issue-584-stylo-template-analysis-panic.hpp rename to bindgen-tests/tests/headers/issue-584-stylo-template-analysis-panic.hpp diff --git a/tests/headers/issue-638-stylo-cannot-find-T-in-this-scope.hpp b/bindgen-tests/tests/headers/issue-638-stylo-cannot-find-T-in-this-scope.hpp similarity index 100% rename from tests/headers/issue-638-stylo-cannot-find-T-in-this-scope.hpp rename to bindgen-tests/tests/headers/issue-638-stylo-cannot-find-T-in-this-scope.hpp diff --git a/tests/headers/issue-639-typedef-anon-field.hpp b/bindgen-tests/tests/headers/issue-639-typedef-anon-field.hpp similarity index 100% rename from tests/headers/issue-639-typedef-anon-field.hpp rename to bindgen-tests/tests/headers/issue-639-typedef-anon-field.hpp diff --git a/tests/headers/issue-643-inner-struct.h b/bindgen-tests/tests/headers/issue-643-inner-struct.h similarity index 100% rename from tests/headers/issue-643-inner-struct.h rename to bindgen-tests/tests/headers/issue-643-inner-struct.h diff --git a/tests/headers/issue-645-cannot-find-type-T-in-this-scope.hpp b/bindgen-tests/tests/headers/issue-645-cannot-find-type-T-in-this-scope.hpp similarity index 100% rename from tests/headers/issue-645-cannot-find-type-T-in-this-scope.hpp rename to bindgen-tests/tests/headers/issue-645-cannot-find-type-T-in-this-scope.hpp diff --git a/tests/headers/issue-648-derive-debug-with-padding.h b/bindgen-tests/tests/headers/issue-648-derive-debug-with-padding.h similarity index 100% rename from tests/headers/issue-648-derive-debug-with-padding.h rename to bindgen-tests/tests/headers/issue-648-derive-debug-with-padding.h diff --git a/tests/headers/issue-654-struct-fn-collision.h b/bindgen-tests/tests/headers/issue-654-struct-fn-collision.h similarity index 100% rename from tests/headers/issue-654-struct-fn-collision.h rename to bindgen-tests/tests/headers/issue-654-struct-fn-collision.h diff --git a/tests/headers/issue-662-cannot-find-T-in-this-scope.hpp b/bindgen-tests/tests/headers/issue-662-cannot-find-T-in-this-scope.hpp similarity index 100% rename from tests/headers/issue-662-cannot-find-T-in-this-scope.hpp rename to bindgen-tests/tests/headers/issue-662-cannot-find-T-in-this-scope.hpp diff --git a/tests/headers/issue-662-part-2.hpp b/bindgen-tests/tests/headers/issue-662-part-2.hpp similarity index 100% rename from tests/headers/issue-662-part-2.hpp rename to bindgen-tests/tests/headers/issue-662-part-2.hpp diff --git a/tests/headers/issue-674-1.hpp b/bindgen-tests/tests/headers/issue-674-1.hpp similarity index 100% rename from tests/headers/issue-674-1.hpp rename to bindgen-tests/tests/headers/issue-674-1.hpp diff --git a/tests/headers/issue-674-2.hpp b/bindgen-tests/tests/headers/issue-674-2.hpp similarity index 100% rename from tests/headers/issue-674-2.hpp rename to bindgen-tests/tests/headers/issue-674-2.hpp diff --git a/tests/headers/issue-674-3.hpp b/bindgen-tests/tests/headers/issue-674-3.hpp similarity index 100% rename from tests/headers/issue-674-3.hpp rename to bindgen-tests/tests/headers/issue-674-3.hpp diff --git a/tests/headers/issue-677-nested-ns-specifier.hpp b/bindgen-tests/tests/headers/issue-677-nested-ns-specifier.hpp similarity index 100% rename from tests/headers/issue-677-nested-ns-specifier.hpp rename to bindgen-tests/tests/headers/issue-677-nested-ns-specifier.hpp diff --git a/tests/headers/issue-691-template-parameter-virtual.hpp b/bindgen-tests/tests/headers/issue-691-template-parameter-virtual.hpp similarity index 100% rename from tests/headers/issue-691-template-parameter-virtual.hpp rename to bindgen-tests/tests/headers/issue-691-template-parameter-virtual.hpp diff --git a/tests/headers/issue-710-must-use-type.h b/bindgen-tests/tests/headers/issue-710-must-use-type.h similarity index 100% rename from tests/headers/issue-710-must-use-type.h rename to bindgen-tests/tests/headers/issue-710-must-use-type.h diff --git a/tests/headers/issue-739-pointer-wide-bitfield.h b/bindgen-tests/tests/headers/issue-739-pointer-wide-bitfield.h similarity index 100% rename from tests/headers/issue-739-pointer-wide-bitfield.h rename to bindgen-tests/tests/headers/issue-739-pointer-wide-bitfield.h diff --git a/tests/headers/issue-769-bad-instantiation-test.hpp b/bindgen-tests/tests/headers/issue-769-bad-instantiation-test.hpp similarity index 100% rename from tests/headers/issue-769-bad-instantiation-test.hpp rename to bindgen-tests/tests/headers/issue-769-bad-instantiation-test.hpp diff --git a/tests/headers/issue-801-opaque-sloppiness.hpp b/bindgen-tests/tests/headers/issue-801-opaque-sloppiness.hpp similarity index 100% rename from tests/headers/issue-801-opaque-sloppiness.hpp rename to bindgen-tests/tests/headers/issue-801-opaque-sloppiness.hpp diff --git a/tests/headers/issue-807-opaque-types-methods-being-generated.hpp b/bindgen-tests/tests/headers/issue-807-opaque-types-methods-being-generated.hpp similarity index 100% rename from tests/headers/issue-807-opaque-types-methods-being-generated.hpp rename to bindgen-tests/tests/headers/issue-807-opaque-types-methods-being-generated.hpp diff --git a/tests/headers/issue-816.h b/bindgen-tests/tests/headers/issue-816.h similarity index 100% rename from tests/headers/issue-816.h rename to bindgen-tests/tests/headers/issue-816.h diff --git a/tests/headers/issue-820-unused-template-param-in-alias.hpp b/bindgen-tests/tests/headers/issue-820-unused-template-param-in-alias.hpp similarity index 100% rename from tests/headers/issue-820-unused-template-param-in-alias.hpp rename to bindgen-tests/tests/headers/issue-820-unused-template-param-in-alias.hpp diff --git a/tests/headers/issue-826-generating-methods-when-asked-not-to.hpp b/bindgen-tests/tests/headers/issue-826-generating-methods-when-asked-not-to.hpp similarity index 100% rename from tests/headers/issue-826-generating-methods-when-asked-not-to.hpp rename to bindgen-tests/tests/headers/issue-826-generating-methods-when-asked-not-to.hpp diff --git a/tests/headers/issue-833-1.hpp b/bindgen-tests/tests/headers/issue-833-1.hpp similarity index 100% rename from tests/headers/issue-833-1.hpp rename to bindgen-tests/tests/headers/issue-833-1.hpp diff --git a/tests/headers/issue-833-2.hpp b/bindgen-tests/tests/headers/issue-833-2.hpp similarity index 100% rename from tests/headers/issue-833-2.hpp rename to bindgen-tests/tests/headers/issue-833-2.hpp diff --git a/tests/headers/issue-833.hpp b/bindgen-tests/tests/headers/issue-833.hpp similarity index 100% rename from tests/headers/issue-833.hpp rename to bindgen-tests/tests/headers/issue-833.hpp diff --git a/tests/headers/issue-834.hpp b/bindgen-tests/tests/headers/issue-834.hpp similarity index 100% rename from tests/headers/issue-834.hpp rename to bindgen-tests/tests/headers/issue-834.hpp diff --git a/tests/headers/issue-848-replacement-system-include.hpp b/bindgen-tests/tests/headers/issue-848-replacement-system-include.hpp similarity index 100% rename from tests/headers/issue-848-replacement-system-include.hpp rename to bindgen-tests/tests/headers/issue-848-replacement-system-include.hpp diff --git a/tests/headers/issue-848/an-include.h b/bindgen-tests/tests/headers/issue-848/an-include.h similarity index 100% rename from tests/headers/issue-848/an-include.h rename to bindgen-tests/tests/headers/issue-848/an-include.h diff --git a/tests/headers/issue-888-enum-var-decl-jump.hpp b/bindgen-tests/tests/headers/issue-888-enum-var-decl-jump.hpp similarity index 100% rename from tests/headers/issue-888-enum-var-decl-jump.hpp rename to bindgen-tests/tests/headers/issue-888-enum-var-decl-jump.hpp diff --git a/tests/headers/issue-944-derive-copy-and-blocklisting.hpp b/bindgen-tests/tests/headers/issue-944-derive-copy-and-blocklisting.hpp similarity index 100% rename from tests/headers/issue-944-derive-copy-and-blocklisting.hpp rename to bindgen-tests/tests/headers/issue-944-derive-copy-and-blocklisting.hpp diff --git a/tests/headers/issue-946.h b/bindgen-tests/tests/headers/issue-946.h similarity index 100% rename from tests/headers/issue-946.h rename to bindgen-tests/tests/headers/issue-946.h diff --git a/tests/headers/issue_311.hpp b/bindgen-tests/tests/headers/issue_311.hpp similarity index 100% rename from tests/headers/issue_311.hpp rename to bindgen-tests/tests/headers/issue_311.hpp diff --git a/tests/headers/issue_315.hpp b/bindgen-tests/tests/headers/issue_315.hpp similarity index 100% rename from tests/headers/issue_315.hpp rename to bindgen-tests/tests/headers/issue_315.hpp diff --git a/tests/headers/jsval_layout_opaque.hpp b/bindgen-tests/tests/headers/jsval_layout_opaque.hpp similarity index 100% rename from tests/headers/jsval_layout_opaque.hpp rename to bindgen-tests/tests/headers/jsval_layout_opaque.hpp diff --git a/tests/headers/jsval_layout_opaque_1_0.hpp b/bindgen-tests/tests/headers/jsval_layout_opaque_1_0.hpp similarity index 100% rename from tests/headers/jsval_layout_opaque_1_0.hpp rename to bindgen-tests/tests/headers/jsval_layout_opaque_1_0.hpp diff --git a/tests/headers/keywords.h b/bindgen-tests/tests/headers/keywords.h similarity index 100% rename from tests/headers/keywords.h rename to bindgen-tests/tests/headers/keywords.h diff --git a/tests/headers/layout.h b/bindgen-tests/tests/headers/layout.h similarity index 100% rename from tests/headers/layout.h rename to bindgen-tests/tests/headers/layout.h diff --git a/tests/headers/layout_align.h b/bindgen-tests/tests/headers/layout_align.h similarity index 100% rename from tests/headers/layout_align.h rename to bindgen-tests/tests/headers/layout_align.h diff --git a/tests/headers/layout_arp.h b/bindgen-tests/tests/headers/layout_arp.h similarity index 100% rename from tests/headers/layout_arp.h rename to bindgen-tests/tests/headers/layout_arp.h diff --git a/tests/headers/layout_array.h b/bindgen-tests/tests/headers/layout_array.h similarity index 100% rename from tests/headers/layout_array.h rename to bindgen-tests/tests/headers/layout_array.h diff --git a/tests/headers/layout_array_too_long.h b/bindgen-tests/tests/headers/layout_array_too_long.h similarity index 100% rename from tests/headers/layout_array_too_long.h rename to bindgen-tests/tests/headers/layout_array_too_long.h diff --git a/tests/headers/layout_cmdline_token.h b/bindgen-tests/tests/headers/layout_cmdline_token.h similarity index 100% rename from tests/headers/layout_cmdline_token.h rename to bindgen-tests/tests/headers/layout_cmdline_token.h diff --git a/tests/headers/layout_eth_conf.h b/bindgen-tests/tests/headers/layout_eth_conf.h similarity index 100% rename from tests/headers/layout_eth_conf.h rename to bindgen-tests/tests/headers/layout_eth_conf.h diff --git a/tests/headers/layout_eth_conf_1_0.h b/bindgen-tests/tests/headers/layout_eth_conf_1_0.h similarity index 100% rename from tests/headers/layout_eth_conf_1_0.h rename to bindgen-tests/tests/headers/layout_eth_conf_1_0.h diff --git a/tests/headers/layout_kni_mbuf.h b/bindgen-tests/tests/headers/layout_kni_mbuf.h similarity index 100% rename from tests/headers/layout_kni_mbuf.h rename to bindgen-tests/tests/headers/layout_kni_mbuf.h diff --git a/tests/headers/layout_large_align_field.h b/bindgen-tests/tests/headers/layout_large_align_field.h similarity index 100% rename from tests/headers/layout_large_align_field.h rename to bindgen-tests/tests/headers/layout_large_align_field.h diff --git a/tests/headers/layout_mbuf.h b/bindgen-tests/tests/headers/layout_mbuf.h similarity index 100% rename from tests/headers/layout_mbuf.h rename to bindgen-tests/tests/headers/layout_mbuf.h diff --git a/tests/headers/layout_mbuf_1_0.h b/bindgen-tests/tests/headers/layout_mbuf_1_0.h similarity index 100% rename from tests/headers/layout_mbuf_1_0.h rename to bindgen-tests/tests/headers/layout_mbuf_1_0.h diff --git a/tests/headers/long_double.h b/bindgen-tests/tests/headers/long_double.h similarity index 100% rename from tests/headers/long_double.h rename to bindgen-tests/tests/headers/long_double.h diff --git a/tests/headers/macro-expr-basic.h b/bindgen-tests/tests/headers/macro-expr-basic.h similarity index 100% rename from tests/headers/macro-expr-basic.h rename to bindgen-tests/tests/headers/macro-expr-basic.h diff --git a/tests/headers/macro-expr-uncommon-token.h b/bindgen-tests/tests/headers/macro-expr-uncommon-token.h similarity index 100% rename from tests/headers/macro-expr-uncommon-token.h rename to bindgen-tests/tests/headers/macro-expr-uncommon-token.h diff --git a/tests/headers/macro-redef.h b/bindgen-tests/tests/headers/macro-redef.h similarity index 100% rename from tests/headers/macro-redef.h rename to bindgen-tests/tests/headers/macro-redef.h diff --git a/tests/headers/macro_const.h b/bindgen-tests/tests/headers/macro_const.h similarity index 100% rename from tests/headers/macro_const.h rename to bindgen-tests/tests/headers/macro_const.h diff --git a/tests/headers/macro_const_1_0.h b/bindgen-tests/tests/headers/macro_const_1_0.h similarity index 100% rename from tests/headers/macro_const_1_0.h rename to bindgen-tests/tests/headers/macro_const_1_0.h diff --git a/tests/headers/maddness-is-avoidable.hpp b/bindgen-tests/tests/headers/maddness-is-avoidable.hpp similarity index 100% rename from tests/headers/maddness-is-avoidable.hpp rename to bindgen-tests/tests/headers/maddness-is-avoidable.hpp diff --git a/tests/headers/mangling-ios.h b/bindgen-tests/tests/headers/mangling-ios.h similarity index 100% rename from tests/headers/mangling-ios.h rename to bindgen-tests/tests/headers/mangling-ios.h diff --git a/tests/headers/mangling-linux32.hpp b/bindgen-tests/tests/headers/mangling-linux32.hpp similarity index 100% rename from tests/headers/mangling-linux32.hpp rename to bindgen-tests/tests/headers/mangling-linux32.hpp diff --git a/tests/headers/mangling-linux64.hpp b/bindgen-tests/tests/headers/mangling-linux64.hpp similarity index 100% rename from tests/headers/mangling-linux64.hpp rename to bindgen-tests/tests/headers/mangling-linux64.hpp diff --git a/tests/headers/mangling-macos.hpp b/bindgen-tests/tests/headers/mangling-macos.hpp similarity index 100% rename from tests/headers/mangling-macos.hpp rename to bindgen-tests/tests/headers/mangling-macos.hpp diff --git a/tests/headers/mangling-win32.hpp b/bindgen-tests/tests/headers/mangling-win32.hpp similarity index 100% rename from tests/headers/mangling-win32.hpp rename to bindgen-tests/tests/headers/mangling-win32.hpp diff --git a/tests/headers/mangling-win64.hpp b/bindgen-tests/tests/headers/mangling-win64.hpp similarity index 100% rename from tests/headers/mangling-win64.hpp rename to bindgen-tests/tests/headers/mangling-win64.hpp diff --git a/tests/headers/merge-extern-blocks.h b/bindgen-tests/tests/headers/merge-extern-blocks.h similarity index 100% rename from tests/headers/merge-extern-blocks.h rename to bindgen-tests/tests/headers/merge-extern-blocks.h diff --git a/tests/headers/method-mangling.hpp b/bindgen-tests/tests/headers/method-mangling.hpp similarity index 100% rename from tests/headers/method-mangling.hpp rename to bindgen-tests/tests/headers/method-mangling.hpp diff --git a/tests/headers/module-allowlisted.hpp b/bindgen-tests/tests/headers/module-allowlisted.hpp similarity index 100% rename from tests/headers/module-allowlisted.hpp rename to bindgen-tests/tests/headers/module-allowlisted.hpp diff --git a/tests/headers/msvc-no-usr.hpp b/bindgen-tests/tests/headers/msvc-no-usr.hpp similarity index 100% rename from tests/headers/msvc-no-usr.hpp rename to bindgen-tests/tests/headers/msvc-no-usr.hpp diff --git a/tests/headers/multiple-inherit-empty-correct-layout.hpp b/bindgen-tests/tests/headers/multiple-inherit-empty-correct-layout.hpp similarity index 100% rename from tests/headers/multiple-inherit-empty-correct-layout.hpp rename to bindgen-tests/tests/headers/multiple-inherit-empty-correct-layout.hpp diff --git a/tests/headers/mutable.hpp b/bindgen-tests/tests/headers/mutable.hpp similarity index 100% rename from tests/headers/mutable.hpp rename to bindgen-tests/tests/headers/mutable.hpp diff --git a/tests/headers/namespace.hpp b/bindgen-tests/tests/headers/namespace.hpp similarity index 100% rename from tests/headers/namespace.hpp rename to bindgen-tests/tests/headers/namespace.hpp diff --git a/tests/headers/namespace/nsbegin.h b/bindgen-tests/tests/headers/namespace/nsbegin.h similarity index 100% rename from tests/headers/namespace/nsbegin.h rename to bindgen-tests/tests/headers/namespace/nsbegin.h diff --git a/tests/headers/namespace/nsend.h b/bindgen-tests/tests/headers/namespace/nsend.h similarity index 100% rename from tests/headers/namespace/nsend.h rename to bindgen-tests/tests/headers/namespace/nsend.h diff --git a/tests/headers/nested-template-typedef.hpp b/bindgen-tests/tests/headers/nested-template-typedef.hpp similarity index 100% rename from tests/headers/nested-template-typedef.hpp rename to bindgen-tests/tests/headers/nested-template-typedef.hpp diff --git a/tests/headers/nested.hpp b/bindgen-tests/tests/headers/nested.hpp similarity index 100% rename from tests/headers/nested.hpp rename to bindgen-tests/tests/headers/nested.hpp diff --git a/tests/headers/nested_vtable.hpp b/bindgen-tests/tests/headers/nested_vtable.hpp similarity index 100% rename from tests/headers/nested_vtable.hpp rename to bindgen-tests/tests/headers/nested_vtable.hpp diff --git a/tests/headers/nested_within_namespace.hpp b/bindgen-tests/tests/headers/nested_within_namespace.hpp similarity index 100% rename from tests/headers/nested_within_namespace.hpp rename to bindgen-tests/tests/headers/nested_within_namespace.hpp diff --git a/tests/headers/newtype-enum.hpp b/bindgen-tests/tests/headers/newtype-enum.hpp similarity index 100% rename from tests/headers/newtype-enum.hpp rename to bindgen-tests/tests/headers/newtype-enum.hpp diff --git a/tests/headers/newtype-global-enum.hpp b/bindgen-tests/tests/headers/newtype-global-enum.hpp similarity index 100% rename from tests/headers/newtype-global-enum.hpp rename to bindgen-tests/tests/headers/newtype-global-enum.hpp diff --git a/tests/headers/no-comments.h b/bindgen-tests/tests/headers/no-comments.h similarity index 100% rename from tests/headers/no-comments.h rename to bindgen-tests/tests/headers/no-comments.h diff --git a/tests/headers/no-derive-debug.h b/bindgen-tests/tests/headers/no-derive-debug.h similarity index 100% rename from tests/headers/no-derive-debug.h rename to bindgen-tests/tests/headers/no-derive-debug.h diff --git a/tests/headers/no-derive-default.h b/bindgen-tests/tests/headers/no-derive-default.h similarity index 100% rename from tests/headers/no-derive-default.h rename to bindgen-tests/tests/headers/no-derive-default.h diff --git a/tests/headers/no-hash-allowlisted.hpp b/bindgen-tests/tests/headers/no-hash-allowlisted.hpp similarity index 100% rename from tests/headers/no-hash-allowlisted.hpp rename to bindgen-tests/tests/headers/no-hash-allowlisted.hpp diff --git a/tests/headers/no-hash-opaque.hpp b/bindgen-tests/tests/headers/no-hash-opaque.hpp similarity index 100% rename from tests/headers/no-hash-opaque.hpp rename to bindgen-tests/tests/headers/no-hash-opaque.hpp diff --git a/tests/headers/no-partialeq-allowlisted.hpp b/bindgen-tests/tests/headers/no-partialeq-allowlisted.hpp similarity index 100% rename from tests/headers/no-partialeq-allowlisted.hpp rename to bindgen-tests/tests/headers/no-partialeq-allowlisted.hpp diff --git a/tests/headers/no-partialeq-opaque.hpp b/bindgen-tests/tests/headers/no-partialeq-opaque.hpp similarity index 100% rename from tests/headers/no-partialeq-opaque.hpp rename to bindgen-tests/tests/headers/no-partialeq-opaque.hpp diff --git a/tests/headers/no-recursive-allowlisting.h b/bindgen-tests/tests/headers/no-recursive-allowlisting.h similarity index 100% rename from tests/headers/no-recursive-allowlisting.h rename to bindgen-tests/tests/headers/no-recursive-allowlisting.h diff --git a/tests/headers/no-std.h b/bindgen-tests/tests/headers/no-std.h similarity index 100% rename from tests/headers/no-std.h rename to bindgen-tests/tests/headers/no-std.h diff --git a/tests/headers/no_copy.hpp b/bindgen-tests/tests/headers/no_copy.hpp similarity index 100% rename from tests/headers/no_copy.hpp rename to bindgen-tests/tests/headers/no_copy.hpp diff --git a/tests/headers/no_copy_allowlisted.hpp b/bindgen-tests/tests/headers/no_copy_allowlisted.hpp similarity index 100% rename from tests/headers/no_copy_allowlisted.hpp rename to bindgen-tests/tests/headers/no_copy_allowlisted.hpp diff --git a/tests/headers/no_copy_opaque.hpp b/bindgen-tests/tests/headers/no_copy_opaque.hpp similarity index 100% rename from tests/headers/no_copy_opaque.hpp rename to bindgen-tests/tests/headers/no_copy_opaque.hpp diff --git a/tests/headers/no_debug.hpp b/bindgen-tests/tests/headers/no_debug.hpp similarity index 100% rename from tests/headers/no_debug.hpp rename to bindgen-tests/tests/headers/no_debug.hpp diff --git a/tests/headers/no_debug_allowlisted.hpp b/bindgen-tests/tests/headers/no_debug_allowlisted.hpp similarity index 100% rename from tests/headers/no_debug_allowlisted.hpp rename to bindgen-tests/tests/headers/no_debug_allowlisted.hpp diff --git a/tests/headers/no_debug_bypass_impl_debug.hpp b/bindgen-tests/tests/headers/no_debug_bypass_impl_debug.hpp similarity index 100% rename from tests/headers/no_debug_bypass_impl_debug.hpp rename to bindgen-tests/tests/headers/no_debug_bypass_impl_debug.hpp diff --git a/tests/headers/no_debug_opaque.hpp b/bindgen-tests/tests/headers/no_debug_opaque.hpp similarity index 100% rename from tests/headers/no_debug_opaque.hpp rename to bindgen-tests/tests/headers/no_debug_opaque.hpp diff --git a/tests/headers/no_default.hpp b/bindgen-tests/tests/headers/no_default.hpp similarity index 100% rename from tests/headers/no_default.hpp rename to bindgen-tests/tests/headers/no_default.hpp diff --git a/tests/headers/no_default_allowlisted.hpp b/bindgen-tests/tests/headers/no_default_allowlisted.hpp similarity index 100% rename from tests/headers/no_default_allowlisted.hpp rename to bindgen-tests/tests/headers/no_default_allowlisted.hpp diff --git a/tests/headers/no_default_bypass_derive_default.hpp b/bindgen-tests/tests/headers/no_default_bypass_derive_default.hpp similarity index 100% rename from tests/headers/no_default_bypass_derive_default.hpp rename to bindgen-tests/tests/headers/no_default_bypass_derive_default.hpp diff --git a/tests/headers/no_default_opaque.hpp b/bindgen-tests/tests/headers/no_default_opaque.hpp similarity index 100% rename from tests/headers/no_default_opaque.hpp rename to bindgen-tests/tests/headers/no_default_opaque.hpp diff --git a/tests/headers/no_size_t_is_usize.h b/bindgen-tests/tests/headers/no_size_t_is_usize.h similarity index 100% rename from tests/headers/no_size_t_is_usize.h rename to bindgen-tests/tests/headers/no_size_t_is_usize.h diff --git a/tests/headers/non-type-params.hpp b/bindgen-tests/tests/headers/non-type-params.hpp similarity index 100% rename from tests/headers/non-type-params.hpp rename to bindgen-tests/tests/headers/non-type-params.hpp diff --git a/tests/headers/noreturn.hpp b/bindgen-tests/tests/headers/noreturn.hpp similarity index 100% rename from tests/headers/noreturn.hpp rename to bindgen-tests/tests/headers/noreturn.hpp diff --git a/tests/headers/nsBaseHashtable.hpp b/bindgen-tests/tests/headers/nsBaseHashtable.hpp similarity index 100% rename from tests/headers/nsBaseHashtable.hpp rename to bindgen-tests/tests/headers/nsBaseHashtable.hpp diff --git a/tests/headers/nsStyleAutoArray.hpp b/bindgen-tests/tests/headers/nsStyleAutoArray.hpp similarity index 100% rename from tests/headers/nsStyleAutoArray.hpp rename to bindgen-tests/tests/headers/nsStyleAutoArray.hpp diff --git a/tests/headers/objc_allowlist.h b/bindgen-tests/tests/headers/objc_allowlist.h similarity index 100% rename from tests/headers/objc_allowlist.h rename to bindgen-tests/tests/headers/objc_allowlist.h diff --git a/tests/headers/objc_blocklist.h b/bindgen-tests/tests/headers/objc_blocklist.h similarity index 100% rename from tests/headers/objc_blocklist.h rename to bindgen-tests/tests/headers/objc_blocklist.h diff --git a/tests/headers/objc_category.h b/bindgen-tests/tests/headers/objc_category.h similarity index 100% rename from tests/headers/objc_category.h rename to bindgen-tests/tests/headers/objc_category.h diff --git a/tests/headers/objc_class.h b/bindgen-tests/tests/headers/objc_class.h similarity index 100% rename from tests/headers/objc_class.h rename to bindgen-tests/tests/headers/objc_class.h diff --git a/tests/headers/objc_class_method.h b/bindgen-tests/tests/headers/objc_class_method.h similarity index 100% rename from tests/headers/objc_class_method.h rename to bindgen-tests/tests/headers/objc_class_method.h diff --git a/tests/headers/objc_inheritance.h b/bindgen-tests/tests/headers/objc_inheritance.h similarity index 100% rename from tests/headers/objc_inheritance.h rename to bindgen-tests/tests/headers/objc_inheritance.h diff --git a/tests/headers/objc_interface.h b/bindgen-tests/tests/headers/objc_interface.h similarity index 100% rename from tests/headers/objc_interface.h rename to bindgen-tests/tests/headers/objc_interface.h diff --git a/tests/headers/objc_interface_type.h b/bindgen-tests/tests/headers/objc_interface_type.h similarity index 100% rename from tests/headers/objc_interface_type.h rename to bindgen-tests/tests/headers/objc_interface_type.h diff --git a/tests/headers/objc_method.h b/bindgen-tests/tests/headers/objc_method.h similarity index 100% rename from tests/headers/objc_method.h rename to bindgen-tests/tests/headers/objc_method.h diff --git a/tests/headers/objc_method_clash.h b/bindgen-tests/tests/headers/objc_method_clash.h similarity index 100% rename from tests/headers/objc_method_clash.h rename to bindgen-tests/tests/headers/objc_method_clash.h diff --git a/tests/headers/objc_pointer_return_types.h b/bindgen-tests/tests/headers/objc_pointer_return_types.h similarity index 100% rename from tests/headers/objc_pointer_return_types.h rename to bindgen-tests/tests/headers/objc_pointer_return_types.h diff --git a/tests/headers/objc_property_fnptr.h b/bindgen-tests/tests/headers/objc_property_fnptr.h similarity index 100% rename from tests/headers/objc_property_fnptr.h rename to bindgen-tests/tests/headers/objc_property_fnptr.h diff --git a/tests/headers/objc_protocol.h b/bindgen-tests/tests/headers/objc_protocol.h similarity index 100% rename from tests/headers/objc_protocol.h rename to bindgen-tests/tests/headers/objc_protocol.h diff --git a/tests/headers/objc_protocol_inheritance.h b/bindgen-tests/tests/headers/objc_protocol_inheritance.h similarity index 100% rename from tests/headers/objc_protocol_inheritance.h rename to bindgen-tests/tests/headers/objc_protocol_inheritance.h diff --git a/tests/headers/objc_sel_and_id.h b/bindgen-tests/tests/headers/objc_sel_and_id.h similarity index 100% rename from tests/headers/objc_sel_and_id.h rename to bindgen-tests/tests/headers/objc_sel_and_id.h diff --git a/tests/headers/objc_template.h b/bindgen-tests/tests/headers/objc_template.h similarity index 100% rename from tests/headers/objc_template.h rename to bindgen-tests/tests/headers/objc_template.h diff --git a/tests/headers/only_bitfields.hpp b/bindgen-tests/tests/headers/only_bitfields.hpp similarity index 100% rename from tests/headers/only_bitfields.hpp rename to bindgen-tests/tests/headers/only_bitfields.hpp diff --git a/tests/headers/opaque-template-inst-member-2.hpp b/bindgen-tests/tests/headers/opaque-template-inst-member-2.hpp similarity index 100% rename from tests/headers/opaque-template-inst-member-2.hpp rename to bindgen-tests/tests/headers/opaque-template-inst-member-2.hpp diff --git a/tests/headers/opaque-template-inst-member.hpp b/bindgen-tests/tests/headers/opaque-template-inst-member.hpp similarity index 100% rename from tests/headers/opaque-template-inst-member.hpp rename to bindgen-tests/tests/headers/opaque-template-inst-member.hpp diff --git a/tests/headers/opaque-template-instantiation-namespaced.hpp b/bindgen-tests/tests/headers/opaque-template-instantiation-namespaced.hpp similarity index 100% rename from tests/headers/opaque-template-instantiation-namespaced.hpp rename to bindgen-tests/tests/headers/opaque-template-instantiation-namespaced.hpp diff --git a/tests/headers/opaque-template-instantiation.hpp b/bindgen-tests/tests/headers/opaque-template-instantiation.hpp similarity index 100% rename from tests/headers/opaque-template-instantiation.hpp rename to bindgen-tests/tests/headers/opaque-template-instantiation.hpp diff --git a/tests/headers/opaque-tracing.hpp b/bindgen-tests/tests/headers/opaque-tracing.hpp similarity index 100% rename from tests/headers/opaque-tracing.hpp rename to bindgen-tests/tests/headers/opaque-tracing.hpp diff --git a/tests/headers/opaque_in_struct.hpp b/bindgen-tests/tests/headers/opaque_in_struct.hpp similarity index 100% rename from tests/headers/opaque_in_struct.hpp rename to bindgen-tests/tests/headers/opaque_in_struct.hpp diff --git a/tests/headers/opaque_pointer.hpp b/bindgen-tests/tests/headers/opaque_pointer.hpp similarity index 100% rename from tests/headers/opaque_pointer.hpp rename to bindgen-tests/tests/headers/opaque_pointer.hpp diff --git a/tests/headers/opaque_typedef.hpp b/bindgen-tests/tests/headers/opaque_typedef.hpp similarity index 100% rename from tests/headers/opaque_typedef.hpp rename to bindgen-tests/tests/headers/opaque_typedef.hpp diff --git a/tests/headers/operator.hpp b/bindgen-tests/tests/headers/operator.hpp similarity index 100% rename from tests/headers/operator.hpp rename to bindgen-tests/tests/headers/operator.hpp diff --git a/tests/headers/ord-enum.h b/bindgen-tests/tests/headers/ord-enum.h similarity index 100% rename from tests/headers/ord-enum.h rename to bindgen-tests/tests/headers/ord-enum.h diff --git a/tests/headers/overflowed_enum.hpp b/bindgen-tests/tests/headers/overflowed_enum.hpp similarity index 100% rename from tests/headers/overflowed_enum.hpp rename to bindgen-tests/tests/headers/overflowed_enum.hpp diff --git a/tests/headers/overloading.hpp b/bindgen-tests/tests/headers/overloading.hpp similarity index 100% rename from tests/headers/overloading.hpp rename to bindgen-tests/tests/headers/overloading.hpp diff --git a/tests/headers/packed-bitfield.h b/bindgen-tests/tests/headers/packed-bitfield.h similarity index 100% rename from tests/headers/packed-bitfield.h rename to bindgen-tests/tests/headers/packed-bitfield.h diff --git a/tests/headers/packed-n-with-padding.h b/bindgen-tests/tests/headers/packed-n-with-padding.h similarity index 100% rename from tests/headers/packed-n-with-padding.h rename to bindgen-tests/tests/headers/packed-n-with-padding.h diff --git a/tests/headers/packed-vtable.h b/bindgen-tests/tests/headers/packed-vtable.h similarity index 100% rename from tests/headers/packed-vtable.h rename to bindgen-tests/tests/headers/packed-vtable.h diff --git a/tests/headers/parm-union.hpp b/bindgen-tests/tests/headers/parm-union.hpp similarity index 100% rename from tests/headers/parm-union.hpp rename to bindgen-tests/tests/headers/parm-union.hpp diff --git a/tests/headers/parsecb-anonymous-enum-variant-rename.h b/bindgen-tests/tests/headers/parsecb-anonymous-enum-variant-rename.h similarity index 100% rename from tests/headers/parsecb-anonymous-enum-variant-rename.h rename to bindgen-tests/tests/headers/parsecb-anonymous-enum-variant-rename.h diff --git a/tests/headers/partial-specialization-and-inheritance.hpp b/bindgen-tests/tests/headers/partial-specialization-and-inheritance.hpp similarity index 100% rename from tests/headers/partial-specialization-and-inheritance.hpp rename to bindgen-tests/tests/headers/partial-specialization-and-inheritance.hpp diff --git a/tests/headers/pointer-attr.h b/bindgen-tests/tests/headers/pointer-attr.h similarity index 100% rename from tests/headers/pointer-attr.h rename to bindgen-tests/tests/headers/pointer-attr.h diff --git a/tests/headers/prepend-enum-constified-variant.h b/bindgen-tests/tests/headers/prepend-enum-constified-variant.h similarity index 100% rename from tests/headers/prepend-enum-constified-variant.h rename to bindgen-tests/tests/headers/prepend-enum-constified-variant.h diff --git a/tests/headers/prepend_enum_name.hpp b/bindgen-tests/tests/headers/prepend_enum_name.hpp similarity index 100% rename from tests/headers/prepend_enum_name.hpp rename to bindgen-tests/tests/headers/prepend_enum_name.hpp diff --git a/tests/headers/private.hpp b/bindgen-tests/tests/headers/private.hpp similarity index 100% rename from tests/headers/private.hpp rename to bindgen-tests/tests/headers/private.hpp diff --git a/tests/headers/private_fields.hpp b/bindgen-tests/tests/headers/private_fields.hpp similarity index 100% rename from tests/headers/private_fields.hpp rename to bindgen-tests/tests/headers/private_fields.hpp diff --git a/tests/headers/public-dtor.hpp b/bindgen-tests/tests/headers/public-dtor.hpp similarity index 100% rename from tests/headers/public-dtor.hpp rename to bindgen-tests/tests/headers/public-dtor.hpp diff --git a/tests/headers/qualified-dependent-types.hpp b/bindgen-tests/tests/headers/qualified-dependent-types.hpp similarity index 100% rename from tests/headers/qualified-dependent-types.hpp rename to bindgen-tests/tests/headers/qualified-dependent-types.hpp diff --git a/tests/headers/redeclaration.hpp b/bindgen-tests/tests/headers/redeclaration.hpp similarity index 100% rename from tests/headers/redeclaration.hpp rename to bindgen-tests/tests/headers/redeclaration.hpp diff --git a/tests/headers/ref_argument_array.hpp b/bindgen-tests/tests/headers/ref_argument_array.hpp similarity index 100% rename from tests/headers/ref_argument_array.hpp rename to bindgen-tests/tests/headers/ref_argument_array.hpp diff --git a/tests/headers/reparented_replacement.hpp b/bindgen-tests/tests/headers/reparented_replacement.hpp similarity index 100% rename from tests/headers/reparented_replacement.hpp rename to bindgen-tests/tests/headers/reparented_replacement.hpp diff --git a/tests/headers/replace_template_alias.hpp b/bindgen-tests/tests/headers/replace_template_alias.hpp similarity index 100% rename from tests/headers/replace_template_alias.hpp rename to bindgen-tests/tests/headers/replace_template_alias.hpp diff --git a/tests/headers/replace_use.hpp b/bindgen-tests/tests/headers/replace_use.hpp similarity index 100% rename from tests/headers/replace_use.hpp rename to bindgen-tests/tests/headers/replace_use.hpp diff --git a/tests/headers/replaces_double.hpp b/bindgen-tests/tests/headers/replaces_double.hpp similarity index 100% rename from tests/headers/replaces_double.hpp rename to bindgen-tests/tests/headers/replaces_double.hpp diff --git a/tests/headers/repr-align.hpp b/bindgen-tests/tests/headers/repr-align.hpp similarity index 100% rename from tests/headers/repr-align.hpp rename to bindgen-tests/tests/headers/repr-align.hpp diff --git a/tests/headers/resolved_type_def_function.h b/bindgen-tests/tests/headers/resolved_type_def_function.h similarity index 100% rename from tests/headers/resolved_type_def_function.h rename to bindgen-tests/tests/headers/resolved_type_def_function.h diff --git a/tests/headers/same_struct_name_in_different_namespaces.hpp b/bindgen-tests/tests/headers/same_struct_name_in_different_namespaces.hpp similarity index 100% rename from tests/headers/same_struct_name_in_different_namespaces.hpp rename to bindgen-tests/tests/headers/same_struct_name_in_different_namespaces.hpp diff --git a/tests/headers/sentry-defined-multiple-times.hpp b/bindgen-tests/tests/headers/sentry-defined-multiple-times.hpp similarity index 100% rename from tests/headers/sentry-defined-multiple-times.hpp rename to bindgen-tests/tests/headers/sentry-defined-multiple-times.hpp diff --git a/tests/headers/short-enums.hpp b/bindgen-tests/tests/headers/short-enums.hpp similarity index 100% rename from tests/headers/short-enums.hpp rename to bindgen-tests/tests/headers/short-enums.hpp diff --git a/tests/headers/size_t_template.hpp b/bindgen-tests/tests/headers/size_t_template.hpp similarity index 100% rename from tests/headers/size_t_template.hpp rename to bindgen-tests/tests/headers/size_t_template.hpp diff --git a/tests/headers/sorted-items.h b/bindgen-tests/tests/headers/sorted-items.h similarity index 100% rename from tests/headers/sorted-items.h rename to bindgen-tests/tests/headers/sorted-items.h diff --git a/tests/headers/stdint_typedef.h b/bindgen-tests/tests/headers/stdint_typedef.h similarity index 100% rename from tests/headers/stdint_typedef.h rename to bindgen-tests/tests/headers/stdint_typedef.h diff --git a/tests/headers/struct_containing_forward_declared_struct.h b/bindgen-tests/tests/headers/struct_containing_forward_declared_struct.h similarity index 100% rename from tests/headers/struct_containing_forward_declared_struct.h rename to bindgen-tests/tests/headers/struct_containing_forward_declared_struct.h diff --git a/tests/headers/struct_typedef.h b/bindgen-tests/tests/headers/struct_typedef.h similarity index 100% rename from tests/headers/struct_typedef.h rename to bindgen-tests/tests/headers/struct_typedef.h diff --git a/tests/headers/struct_typedef_ns.hpp b/bindgen-tests/tests/headers/struct_typedef_ns.hpp similarity index 100% rename from tests/headers/struct_typedef_ns.hpp rename to bindgen-tests/tests/headers/struct_typedef_ns.hpp diff --git a/tests/headers/struct_with_anon_struct.h b/bindgen-tests/tests/headers/struct_with_anon_struct.h similarity index 100% rename from tests/headers/struct_with_anon_struct.h rename to bindgen-tests/tests/headers/struct_with_anon_struct.h diff --git a/tests/headers/struct_with_anon_struct_array.h b/bindgen-tests/tests/headers/struct_with_anon_struct_array.h similarity index 100% rename from tests/headers/struct_with_anon_struct_array.h rename to bindgen-tests/tests/headers/struct_with_anon_struct_array.h diff --git a/tests/headers/struct_with_anon_struct_pointer.h b/bindgen-tests/tests/headers/struct_with_anon_struct_pointer.h similarity index 100% rename from tests/headers/struct_with_anon_struct_pointer.h rename to bindgen-tests/tests/headers/struct_with_anon_struct_pointer.h diff --git a/tests/headers/struct_with_anon_union.h b/bindgen-tests/tests/headers/struct_with_anon_union.h similarity index 100% rename from tests/headers/struct_with_anon_union.h rename to bindgen-tests/tests/headers/struct_with_anon_union.h diff --git a/tests/headers/struct_with_anon_union_1_0.h b/bindgen-tests/tests/headers/struct_with_anon_union_1_0.h similarity index 100% rename from tests/headers/struct_with_anon_union_1_0.h rename to bindgen-tests/tests/headers/struct_with_anon_union_1_0.h diff --git a/tests/headers/struct_with_anon_unnamed_struct.h b/bindgen-tests/tests/headers/struct_with_anon_unnamed_struct.h similarity index 100% rename from tests/headers/struct_with_anon_unnamed_struct.h rename to bindgen-tests/tests/headers/struct_with_anon_unnamed_struct.h diff --git a/tests/headers/struct_with_anon_unnamed_union.h b/bindgen-tests/tests/headers/struct_with_anon_unnamed_union.h similarity index 100% rename from tests/headers/struct_with_anon_unnamed_union.h rename to bindgen-tests/tests/headers/struct_with_anon_unnamed_union.h diff --git a/tests/headers/struct_with_anon_unnamed_union_1_0.h b/bindgen-tests/tests/headers/struct_with_anon_unnamed_union_1_0.h similarity index 100% rename from tests/headers/struct_with_anon_unnamed_union_1_0.h rename to bindgen-tests/tests/headers/struct_with_anon_unnamed_union_1_0.h diff --git a/tests/headers/struct_with_bitfields.h b/bindgen-tests/tests/headers/struct_with_bitfields.h similarity index 100% rename from tests/headers/struct_with_bitfields.h rename to bindgen-tests/tests/headers/struct_with_bitfields.h diff --git a/tests/headers/struct_with_derive_debug.h b/bindgen-tests/tests/headers/struct_with_derive_debug.h similarity index 100% rename from tests/headers/struct_with_derive_debug.h rename to bindgen-tests/tests/headers/struct_with_derive_debug.h diff --git a/tests/headers/struct_with_large_array.hpp b/bindgen-tests/tests/headers/struct_with_large_array.hpp similarity index 100% rename from tests/headers/struct_with_large_array.hpp rename to bindgen-tests/tests/headers/struct_with_large_array.hpp diff --git a/tests/headers/struct_with_nesting.h b/bindgen-tests/tests/headers/struct_with_nesting.h similarity index 100% rename from tests/headers/struct_with_nesting.h rename to bindgen-tests/tests/headers/struct_with_nesting.h diff --git a/tests/headers/struct_with_nesting_1_0.h b/bindgen-tests/tests/headers/struct_with_nesting_1_0.h similarity index 100% rename from tests/headers/struct_with_nesting_1_0.h rename to bindgen-tests/tests/headers/struct_with_nesting_1_0.h diff --git a/tests/headers/struct_with_packing.h b/bindgen-tests/tests/headers/struct_with_packing.h similarity index 100% rename from tests/headers/struct_with_packing.h rename to bindgen-tests/tests/headers/struct_with_packing.h diff --git a/tests/headers/struct_with_struct.h b/bindgen-tests/tests/headers/struct_with_struct.h similarity index 100% rename from tests/headers/struct_with_struct.h rename to bindgen-tests/tests/headers/struct_with_struct.h diff --git a/tests/headers/struct_with_typedef_template_arg.hpp b/bindgen-tests/tests/headers/struct_with_typedef_template_arg.hpp similarity index 100% rename from tests/headers/struct_with_typedef_template_arg.hpp rename to bindgen-tests/tests/headers/struct_with_typedef_template_arg.hpp diff --git a/tests/headers/template-fun-ty.hpp b/bindgen-tests/tests/headers/template-fun-ty.hpp similarity index 100% rename from tests/headers/template-fun-ty.hpp rename to bindgen-tests/tests/headers/template-fun-ty.hpp diff --git a/tests/headers/template-param-usage-0.hpp b/bindgen-tests/tests/headers/template-param-usage-0.hpp similarity index 100% rename from tests/headers/template-param-usage-0.hpp rename to bindgen-tests/tests/headers/template-param-usage-0.hpp diff --git a/tests/headers/template-param-usage-1.hpp b/bindgen-tests/tests/headers/template-param-usage-1.hpp similarity index 100% rename from tests/headers/template-param-usage-1.hpp rename to bindgen-tests/tests/headers/template-param-usage-1.hpp diff --git a/tests/headers/template-param-usage-10.hpp b/bindgen-tests/tests/headers/template-param-usage-10.hpp similarity index 100% rename from tests/headers/template-param-usage-10.hpp rename to bindgen-tests/tests/headers/template-param-usage-10.hpp diff --git a/tests/headers/template-param-usage-11.hpp b/bindgen-tests/tests/headers/template-param-usage-11.hpp similarity index 100% rename from tests/headers/template-param-usage-11.hpp rename to bindgen-tests/tests/headers/template-param-usage-11.hpp diff --git a/tests/headers/template-param-usage-12.hpp b/bindgen-tests/tests/headers/template-param-usage-12.hpp similarity index 100% rename from tests/headers/template-param-usage-12.hpp rename to bindgen-tests/tests/headers/template-param-usage-12.hpp diff --git a/tests/headers/template-param-usage-13.hpp b/bindgen-tests/tests/headers/template-param-usage-13.hpp similarity index 100% rename from tests/headers/template-param-usage-13.hpp rename to bindgen-tests/tests/headers/template-param-usage-13.hpp diff --git a/tests/headers/template-param-usage-14.hpp b/bindgen-tests/tests/headers/template-param-usage-14.hpp similarity index 100% rename from tests/headers/template-param-usage-14.hpp rename to bindgen-tests/tests/headers/template-param-usage-14.hpp diff --git a/tests/headers/template-param-usage-15.hpp b/bindgen-tests/tests/headers/template-param-usage-15.hpp similarity index 100% rename from tests/headers/template-param-usage-15.hpp rename to bindgen-tests/tests/headers/template-param-usage-15.hpp diff --git a/tests/headers/template-param-usage-2.hpp b/bindgen-tests/tests/headers/template-param-usage-2.hpp similarity index 100% rename from tests/headers/template-param-usage-2.hpp rename to bindgen-tests/tests/headers/template-param-usage-2.hpp diff --git a/tests/headers/template-param-usage-3.hpp b/bindgen-tests/tests/headers/template-param-usage-3.hpp similarity index 100% rename from tests/headers/template-param-usage-3.hpp rename to bindgen-tests/tests/headers/template-param-usage-3.hpp diff --git a/tests/headers/template-param-usage-4.hpp b/bindgen-tests/tests/headers/template-param-usage-4.hpp similarity index 100% rename from tests/headers/template-param-usage-4.hpp rename to bindgen-tests/tests/headers/template-param-usage-4.hpp diff --git a/tests/headers/template-param-usage-5.hpp b/bindgen-tests/tests/headers/template-param-usage-5.hpp similarity index 100% rename from tests/headers/template-param-usage-5.hpp rename to bindgen-tests/tests/headers/template-param-usage-5.hpp diff --git a/tests/headers/template-param-usage-6.hpp b/bindgen-tests/tests/headers/template-param-usage-6.hpp similarity index 100% rename from tests/headers/template-param-usage-6.hpp rename to bindgen-tests/tests/headers/template-param-usage-6.hpp diff --git a/tests/headers/template-param-usage-7.hpp b/bindgen-tests/tests/headers/template-param-usage-7.hpp similarity index 100% rename from tests/headers/template-param-usage-7.hpp rename to bindgen-tests/tests/headers/template-param-usage-7.hpp diff --git a/tests/headers/template-param-usage-8.hpp b/bindgen-tests/tests/headers/template-param-usage-8.hpp similarity index 100% rename from tests/headers/template-param-usage-8.hpp rename to bindgen-tests/tests/headers/template-param-usage-8.hpp diff --git a/tests/headers/template-param-usage-9.hpp b/bindgen-tests/tests/headers/template-param-usage-9.hpp similarity index 100% rename from tests/headers/template-param-usage-9.hpp rename to bindgen-tests/tests/headers/template-param-usage-9.hpp diff --git a/tests/headers/template-with-var.hpp b/bindgen-tests/tests/headers/template-with-var.hpp similarity index 100% rename from tests/headers/template-with-var.hpp rename to bindgen-tests/tests/headers/template-with-var.hpp diff --git a/tests/headers/template.hpp b/bindgen-tests/tests/headers/template.hpp similarity index 100% rename from tests/headers/template.hpp rename to bindgen-tests/tests/headers/template.hpp diff --git a/tests/headers/template_alias.hpp b/bindgen-tests/tests/headers/template_alias.hpp similarity index 100% rename from tests/headers/template_alias.hpp rename to bindgen-tests/tests/headers/template_alias.hpp diff --git a/tests/headers/template_alias_basic.hpp b/bindgen-tests/tests/headers/template_alias_basic.hpp similarity index 100% rename from tests/headers/template_alias_basic.hpp rename to bindgen-tests/tests/headers/template_alias_basic.hpp diff --git a/tests/headers/template_alias_namespace.hpp b/bindgen-tests/tests/headers/template_alias_namespace.hpp similarity index 100% rename from tests/headers/template_alias_namespace.hpp rename to bindgen-tests/tests/headers/template_alias_namespace.hpp diff --git a/tests/headers/template_fun.hpp b/bindgen-tests/tests/headers/template_fun.hpp similarity index 100% rename from tests/headers/template_fun.hpp rename to bindgen-tests/tests/headers/template_fun.hpp diff --git a/tests/headers/template_instantiation_with_fn_local_type.hpp b/bindgen-tests/tests/headers/template_instantiation_with_fn_local_type.hpp similarity index 100% rename from tests/headers/template_instantiation_with_fn_local_type.hpp rename to bindgen-tests/tests/headers/template_instantiation_with_fn_local_type.hpp diff --git a/tests/headers/template_partial_specification.hpp b/bindgen-tests/tests/headers/template_partial_specification.hpp similarity index 100% rename from tests/headers/template_partial_specification.hpp rename to bindgen-tests/tests/headers/template_partial_specification.hpp diff --git a/tests/headers/template_typedef_transitive_param.hpp b/bindgen-tests/tests/headers/template_typedef_transitive_param.hpp similarity index 100% rename from tests/headers/template_typedef_transitive_param.hpp rename to bindgen-tests/tests/headers/template_typedef_transitive_param.hpp diff --git a/tests/headers/template_typedefs.hpp b/bindgen-tests/tests/headers/template_typedefs.hpp similarity index 100% rename from tests/headers/template_typedefs.hpp rename to bindgen-tests/tests/headers/template_typedefs.hpp diff --git a/tests/headers/templateref_opaque.hpp b/bindgen-tests/tests/headers/templateref_opaque.hpp similarity index 100% rename from tests/headers/templateref_opaque.hpp rename to bindgen-tests/tests/headers/templateref_opaque.hpp diff --git a/tests/headers/templatized-bitfield.hpp b/bindgen-tests/tests/headers/templatized-bitfield.hpp similarity index 100% rename from tests/headers/templatized-bitfield.hpp rename to bindgen-tests/tests/headers/templatized-bitfield.hpp diff --git a/tests/headers/timex.h b/bindgen-tests/tests/headers/timex.h similarity index 100% rename from tests/headers/timex.h rename to bindgen-tests/tests/headers/timex.h diff --git a/tests/headers/transform-op.hpp b/bindgen-tests/tests/headers/transform-op.hpp similarity index 100% rename from tests/headers/transform-op.hpp rename to bindgen-tests/tests/headers/transform-op.hpp diff --git a/tests/headers/type-referenced-by-allowlisted-function.h b/bindgen-tests/tests/headers/type-referenced-by-allowlisted-function.h similarity index 100% rename from tests/headers/type-referenced-by-allowlisted-function.h rename to bindgen-tests/tests/headers/type-referenced-by-allowlisted-function.h diff --git a/tests/headers/type_alias_empty.hpp b/bindgen-tests/tests/headers/type_alias_empty.hpp similarity index 100% rename from tests/headers/type_alias_empty.hpp rename to bindgen-tests/tests/headers/type_alias_empty.hpp diff --git a/tests/headers/type_alias_partial_template_especialization.hpp b/bindgen-tests/tests/headers/type_alias_partial_template_especialization.hpp similarity index 100% rename from tests/headers/type_alias_partial_template_especialization.hpp rename to bindgen-tests/tests/headers/type_alias_partial_template_especialization.hpp diff --git a/tests/headers/type_alias_template_specialized.hpp b/bindgen-tests/tests/headers/type_alias_template_specialized.hpp similarity index 100% rename from tests/headers/type_alias_template_specialized.hpp rename to bindgen-tests/tests/headers/type_alias_template_specialized.hpp diff --git a/tests/headers/typedefd-array-as-function-arg.h b/bindgen-tests/tests/headers/typedefd-array-as-function-arg.h similarity index 100% rename from tests/headers/typedefd-array-as-function-arg.h rename to bindgen-tests/tests/headers/typedefd-array-as-function-arg.h diff --git a/tests/headers/typeref.hpp b/bindgen-tests/tests/headers/typeref.hpp similarity index 100% rename from tests/headers/typeref.hpp rename to bindgen-tests/tests/headers/typeref.hpp diff --git a/tests/headers/typeref_1_0.hpp b/bindgen-tests/tests/headers/typeref_1_0.hpp similarity index 100% rename from tests/headers/typeref_1_0.hpp rename to bindgen-tests/tests/headers/typeref_1_0.hpp diff --git a/tests/headers/underscore.hpp b/bindgen-tests/tests/headers/underscore.hpp similarity index 100% rename from tests/headers/underscore.hpp rename to bindgen-tests/tests/headers/underscore.hpp diff --git a/tests/headers/union-align.h b/bindgen-tests/tests/headers/union-align.h similarity index 100% rename from tests/headers/union-align.h rename to bindgen-tests/tests/headers/union-align.h diff --git a/tests/headers/union-in-ns.hpp b/bindgen-tests/tests/headers/union-in-ns.hpp similarity index 100% rename from tests/headers/union-in-ns.hpp rename to bindgen-tests/tests/headers/union-in-ns.hpp diff --git a/tests/headers/union-in-ns_1_0.hpp b/bindgen-tests/tests/headers/union-in-ns_1_0.hpp similarity index 100% rename from tests/headers/union-in-ns_1_0.hpp rename to bindgen-tests/tests/headers/union-in-ns_1_0.hpp diff --git a/tests/headers/union_bitfield.h b/bindgen-tests/tests/headers/union_bitfield.h similarity index 100% rename from tests/headers/union_bitfield.h rename to bindgen-tests/tests/headers/union_bitfield.h diff --git a/tests/headers/union_bitfield_1_0.h b/bindgen-tests/tests/headers/union_bitfield_1_0.h similarity index 100% rename from tests/headers/union_bitfield_1_0.h rename to bindgen-tests/tests/headers/union_bitfield_1_0.h diff --git a/tests/headers/union_dtor.hpp b/bindgen-tests/tests/headers/union_dtor.hpp similarity index 100% rename from tests/headers/union_dtor.hpp rename to bindgen-tests/tests/headers/union_dtor.hpp diff --git a/tests/headers/union_dtor_1_0.hpp b/bindgen-tests/tests/headers/union_dtor_1_0.hpp similarity index 100% rename from tests/headers/union_dtor_1_0.hpp rename to bindgen-tests/tests/headers/union_dtor_1_0.hpp diff --git a/tests/headers/union_fields.hpp b/bindgen-tests/tests/headers/union_fields.hpp similarity index 100% rename from tests/headers/union_fields.hpp rename to bindgen-tests/tests/headers/union_fields.hpp diff --git a/tests/headers/union_fields_1_0.hpp b/bindgen-tests/tests/headers/union_fields_1_0.hpp similarity index 100% rename from tests/headers/union_fields_1_0.hpp rename to bindgen-tests/tests/headers/union_fields_1_0.hpp diff --git a/tests/headers/union_template.hpp b/bindgen-tests/tests/headers/union_template.hpp similarity index 100% rename from tests/headers/union_template.hpp rename to bindgen-tests/tests/headers/union_template.hpp diff --git a/tests/headers/union_template_1_0.hpp b/bindgen-tests/tests/headers/union_template_1_0.hpp similarity index 100% rename from tests/headers/union_template_1_0.hpp rename to bindgen-tests/tests/headers/union_template_1_0.hpp diff --git a/tests/headers/union_with_anon_struct.h b/bindgen-tests/tests/headers/union_with_anon_struct.h similarity index 100% rename from tests/headers/union_with_anon_struct.h rename to bindgen-tests/tests/headers/union_with_anon_struct.h diff --git a/tests/headers/union_with_anon_struct_1_0.h b/bindgen-tests/tests/headers/union_with_anon_struct_1_0.h similarity index 100% rename from tests/headers/union_with_anon_struct_1_0.h rename to bindgen-tests/tests/headers/union_with_anon_struct_1_0.h diff --git a/tests/headers/union_with_anon_struct_bitfield.h b/bindgen-tests/tests/headers/union_with_anon_struct_bitfield.h similarity index 100% rename from tests/headers/union_with_anon_struct_bitfield.h rename to bindgen-tests/tests/headers/union_with_anon_struct_bitfield.h diff --git a/tests/headers/union_with_anon_struct_bitfield_1_0.h b/bindgen-tests/tests/headers/union_with_anon_struct_bitfield_1_0.h similarity index 100% rename from tests/headers/union_with_anon_struct_bitfield_1_0.h rename to bindgen-tests/tests/headers/union_with_anon_struct_bitfield_1_0.h diff --git a/tests/headers/union_with_anon_union.h b/bindgen-tests/tests/headers/union_with_anon_union.h similarity index 100% rename from tests/headers/union_with_anon_union.h rename to bindgen-tests/tests/headers/union_with_anon_union.h diff --git a/tests/headers/union_with_anon_union_1_0.h b/bindgen-tests/tests/headers/union_with_anon_union_1_0.h similarity index 100% rename from tests/headers/union_with_anon_union_1_0.h rename to bindgen-tests/tests/headers/union_with_anon_union_1_0.h diff --git a/tests/headers/union_with_anon_unnamed_struct.h b/bindgen-tests/tests/headers/union_with_anon_unnamed_struct.h similarity index 100% rename from tests/headers/union_with_anon_unnamed_struct.h rename to bindgen-tests/tests/headers/union_with_anon_unnamed_struct.h diff --git a/tests/headers/union_with_anon_unnamed_struct_1_0.h b/bindgen-tests/tests/headers/union_with_anon_unnamed_struct_1_0.h similarity index 100% rename from tests/headers/union_with_anon_unnamed_struct_1_0.h rename to bindgen-tests/tests/headers/union_with_anon_unnamed_struct_1_0.h diff --git a/tests/headers/union_with_anon_unnamed_union.h b/bindgen-tests/tests/headers/union_with_anon_unnamed_union.h similarity index 100% rename from tests/headers/union_with_anon_unnamed_union.h rename to bindgen-tests/tests/headers/union_with_anon_unnamed_union.h diff --git a/tests/headers/union_with_anon_unnamed_union_1_0.h b/bindgen-tests/tests/headers/union_with_anon_unnamed_union_1_0.h similarity index 100% rename from tests/headers/union_with_anon_unnamed_union_1_0.h rename to bindgen-tests/tests/headers/union_with_anon_unnamed_union_1_0.h diff --git a/tests/headers/union_with_big_member.h b/bindgen-tests/tests/headers/union_with_big_member.h similarity index 100% rename from tests/headers/union_with_big_member.h rename to bindgen-tests/tests/headers/union_with_big_member.h diff --git a/tests/headers/union_with_big_member_1_0.h b/bindgen-tests/tests/headers/union_with_big_member_1_0.h similarity index 100% rename from tests/headers/union_with_big_member_1_0.h rename to bindgen-tests/tests/headers/union_with_big_member_1_0.h diff --git a/tests/headers/union_with_nesting.h b/bindgen-tests/tests/headers/union_with_nesting.h similarity index 100% rename from tests/headers/union_with_nesting.h rename to bindgen-tests/tests/headers/union_with_nesting.h diff --git a/tests/headers/union_with_nesting_1_0.h b/bindgen-tests/tests/headers/union_with_nesting_1_0.h similarity index 100% rename from tests/headers/union_with_nesting_1_0.h rename to bindgen-tests/tests/headers/union_with_nesting_1_0.h diff --git a/tests/headers/union_with_non_copy_member.h b/bindgen-tests/tests/headers/union_with_non_copy_member.h similarity index 100% rename from tests/headers/union_with_non_copy_member.h rename to bindgen-tests/tests/headers/union_with_non_copy_member.h diff --git a/tests/headers/unknown_attr.h b/bindgen-tests/tests/headers/unknown_attr.h similarity index 100% rename from tests/headers/unknown_attr.h rename to bindgen-tests/tests/headers/unknown_attr.h diff --git a/tests/headers/unsorted-items.h b/bindgen-tests/tests/headers/unsorted-items.h similarity index 100% rename from tests/headers/unsorted-items.h rename to bindgen-tests/tests/headers/unsorted-items.h diff --git a/tests/headers/use-core.h b/bindgen-tests/tests/headers/use-core.h similarity index 100% rename from tests/headers/use-core.h rename to bindgen-tests/tests/headers/use-core.h diff --git a/tests/headers/use-core_1_0.h b/bindgen-tests/tests/headers/use-core_1_0.h similarity index 100% rename from tests/headers/use-core_1_0.h rename to bindgen-tests/tests/headers/use-core_1_0.h diff --git a/tests/headers/using.hpp b/bindgen-tests/tests/headers/using.hpp similarity index 100% rename from tests/headers/using.hpp rename to bindgen-tests/tests/headers/using.hpp diff --git a/tests/headers/var-tracing.hpp b/bindgen-tests/tests/headers/var-tracing.hpp similarity index 100% rename from tests/headers/var-tracing.hpp rename to bindgen-tests/tests/headers/var-tracing.hpp diff --git a/tests/headers/variadic-method.hpp b/bindgen-tests/tests/headers/variadic-method.hpp similarity index 100% rename from tests/headers/variadic-method.hpp rename to bindgen-tests/tests/headers/variadic-method.hpp diff --git a/tests/headers/variadic_template_function.hpp b/bindgen-tests/tests/headers/variadic_template_function.hpp similarity index 100% rename from tests/headers/variadic_template_function.hpp rename to bindgen-tests/tests/headers/variadic_template_function.hpp diff --git a/tests/headers/vector.hpp b/bindgen-tests/tests/headers/vector.hpp similarity index 100% rename from tests/headers/vector.hpp rename to bindgen-tests/tests/headers/vector.hpp diff --git a/tests/headers/virtual_dtor.hpp b/bindgen-tests/tests/headers/virtual_dtor.hpp similarity index 100% rename from tests/headers/virtual_dtor.hpp rename to bindgen-tests/tests/headers/virtual_dtor.hpp diff --git a/tests/headers/virtual_inheritance.hpp b/bindgen-tests/tests/headers/virtual_inheritance.hpp similarity index 100% rename from tests/headers/virtual_inheritance.hpp rename to bindgen-tests/tests/headers/virtual_inheritance.hpp diff --git a/tests/headers/virtual_interface.hpp b/bindgen-tests/tests/headers/virtual_interface.hpp similarity index 100% rename from tests/headers/virtual_interface.hpp rename to bindgen-tests/tests/headers/virtual_interface.hpp diff --git a/tests/headers/virtual_overloaded.hpp b/bindgen-tests/tests/headers/virtual_overloaded.hpp similarity index 100% rename from tests/headers/virtual_overloaded.hpp rename to bindgen-tests/tests/headers/virtual_overloaded.hpp diff --git a/tests/headers/vtable_recursive_sig.hpp b/bindgen-tests/tests/headers/vtable_recursive_sig.hpp similarity index 100% rename from tests/headers/vtable_recursive_sig.hpp rename to bindgen-tests/tests/headers/vtable_recursive_sig.hpp diff --git a/tests/headers/wasm-constructor-returns.hpp b/bindgen-tests/tests/headers/wasm-constructor-returns.hpp similarity index 100% rename from tests/headers/wasm-constructor-returns.hpp rename to bindgen-tests/tests/headers/wasm-constructor-returns.hpp diff --git a/tests/headers/wasm-import-module.h b/bindgen-tests/tests/headers/wasm-import-module.h similarity index 100% rename from tests/headers/wasm-import-module.h rename to bindgen-tests/tests/headers/wasm-import-module.h diff --git a/tests/headers/weird_bitfields.hpp b/bindgen-tests/tests/headers/weird_bitfields.hpp similarity index 100% rename from tests/headers/weird_bitfields.hpp rename to bindgen-tests/tests/headers/weird_bitfields.hpp diff --git a/tests/headers/what_is_going_on.hpp b/bindgen-tests/tests/headers/what_is_going_on.hpp similarity index 100% rename from tests/headers/what_is_going_on.hpp rename to bindgen-tests/tests/headers/what_is_going_on.hpp diff --git a/tests/headers/win32-thiscall_1_0.hpp b/bindgen-tests/tests/headers/win32-thiscall_1_0.hpp similarity index 100% rename from tests/headers/win32-thiscall_1_0.hpp rename to bindgen-tests/tests/headers/win32-thiscall_1_0.hpp diff --git a/tests/headers/win32-thiscall_nightly.hpp b/bindgen-tests/tests/headers/win32-thiscall_nightly.hpp similarity index 100% rename from tests/headers/win32-thiscall_nightly.hpp rename to bindgen-tests/tests/headers/win32-thiscall_nightly.hpp diff --git a/tests/headers/win32-vectorcall-1_0.h b/bindgen-tests/tests/headers/win32-vectorcall-1_0.h similarity index 100% rename from tests/headers/win32-vectorcall-1_0.h rename to bindgen-tests/tests/headers/win32-vectorcall-1_0.h diff --git a/tests/headers/win32-vectorcall-nightly.h b/bindgen-tests/tests/headers/win32-vectorcall-nightly.h similarity index 100% rename from tests/headers/win32-vectorcall-nightly.h rename to bindgen-tests/tests/headers/win32-vectorcall-nightly.h diff --git a/tests/headers/with_array_pointers_arguments.h b/bindgen-tests/tests/headers/with_array_pointers_arguments.h similarity index 100% rename from tests/headers/with_array_pointers_arguments.h rename to bindgen-tests/tests/headers/with_array_pointers_arguments.h diff --git a/tests/headers/without_array_pointers_arguments.h b/bindgen-tests/tests/headers/without_array_pointers_arguments.h similarity index 100% rename from tests/headers/without_array_pointers_arguments.h rename to bindgen-tests/tests/headers/without_array_pointers_arguments.h diff --git a/tests/headers/zero-size-array-align.h b/bindgen-tests/tests/headers/zero-size-array-align.h similarity index 100% rename from tests/headers/zero-size-array-align.h rename to bindgen-tests/tests/headers/zero-size-array-align.h diff --git a/tests/headers/zero-sized-array.hpp b/bindgen-tests/tests/headers/zero-sized-array.hpp similarity index 100% rename from tests/headers/zero-sized-array.hpp rename to bindgen-tests/tests/headers/zero-sized-array.hpp diff --git a/tests/parse_callbacks/mod.rs b/bindgen-tests/tests/parse_callbacks/mod.rs similarity index 100% rename from tests/parse_callbacks/mod.rs rename to bindgen-tests/tests/parse_callbacks/mod.rs diff --git a/tests/quickchecking/.gitignore b/bindgen-tests/tests/quickchecking/.gitignore similarity index 100% rename from tests/quickchecking/.gitignore rename to bindgen-tests/tests/quickchecking/.gitignore diff --git a/tests/quickchecking/Cargo.toml b/bindgen-tests/tests/quickchecking/Cargo.toml similarity index 94% rename from tests/quickchecking/Cargo.toml rename to bindgen-tests/tests/quickchecking/Cargo.toml index ddefb33d69..455a824039 100644 --- a/tests/quickchecking/Cargo.toml +++ b/bindgen-tests/tests/quickchecking/Cargo.toml @@ -24,8 +24,8 @@ tempdir = "0.3" default = [] # Enable the generation of code that allows for zero sized arrays as struct -# fields. Until issues #684 and #1153 are resolved this can result in failing tests. -zero-sized-arrays = [] +# fields. Until issues #684 and #1153 are resolved this can result in failing tests. +zero-sized-arrays = [] # Enable the generation of code that allows for long double types as struct # fields. Until issue #550 is resolved this can result in failing tests. diff --git a/tests/quickchecking/README.md b/bindgen-tests/tests/quickchecking/README.md similarity index 100% rename from tests/quickchecking/README.md rename to bindgen-tests/tests/quickchecking/README.md diff --git a/tests/quickchecking/src/bin.rs b/bindgen-tests/tests/quickchecking/src/bin.rs similarity index 94% rename from tests/quickchecking/src/bin.rs rename to bindgen-tests/tests/quickchecking/src/bin.rs index d2774eb0d9..f2b52e828f 100644 --- a/tests/quickchecking/src/bin.rs +++ b/bindgen-tests/tests/quickchecking/src/bin.rs @@ -103,8 +103,10 @@ fn main() { .get_matches(); let output_path: Option<&str> = matches.value_of("path"); - let generate_range: usize = matches.value_of("range").unwrap().parse::().unwrap(); - let tests: usize = matches.value_of("count").unwrap().parse::().unwrap(); + let generate_range: usize = + matches.value_of("range").unwrap().parse::().unwrap(); + let tests: usize = + matches.value_of("count").unwrap().parse::().unwrap(); quickchecking::test_bindgen(generate_range, tests, output_path) } diff --git a/tests/quickchecking/src/fuzzers.rs b/bindgen-tests/tests/quickchecking/src/fuzzers.rs similarity index 97% rename from tests/quickchecking/src/fuzzers.rs rename to bindgen-tests/tests/quickchecking/src/fuzzers.rs index 7c76442515..b609dd5abc 100644 --- a/tests/quickchecking/src/fuzzers.rs +++ b/bindgen-tests/tests/quickchecking/src/fuzzers.rs @@ -1,6 +1,6 @@ use quickcheck::{Arbitrary, Gen, StdGen}; -use std::fmt; use rand::thread_rng; +use std::fmt; /// BaseTypeC is used in generation of C headers to represent the C language's /// primitive types as well as `void*`. @@ -185,10 +185,14 @@ impl Arbitrary for DeclarationC { fn arbitrary(g: &mut G) -> DeclarationC { match g.gen_range(0, 5) { 0 => DeclarationC::FunctionDecl(FunctionPrototypeC::arbitrary(g)), - 1 => DeclarationC::FunctionPtrDecl(FunctionPointerDeclarationC::arbitrary(g)), + 1 => DeclarationC::FunctionPtrDecl( + FunctionPointerDeclarationC::arbitrary(g), + ), 2 => DeclarationC::StructDecl(StructDeclarationC::arbitrary(g)), 3 => DeclarationC::UnionDecl(UnionDeclarationC::arbitrary(g)), - 4 => DeclarationC::VariableDecl(BasicTypeDeclarationC::arbitrary(g)), + 4 => { + DeclarationC::VariableDecl(BasicTypeDeclarationC::arbitrary(g)) + } _ => unreachable!(), } } @@ -425,9 +429,7 @@ impl fmt::Display for StructDeclarationC { write!( f, "struct {{ {} }} struct_{}{};", - self.fields, - self.ident_id, - self.array_dimension + self.fields, self.ident_id, self.array_dimension ) } } @@ -475,9 +477,7 @@ impl fmt::Display for UnionDeclarationC { write!( f, "union {{ {} }} union_{}{};", - self.fields, - self.ident_id, - self.array_dimension + self.fields, self.ident_id, self.array_dimension ) } } @@ -574,9 +574,7 @@ impl fmt::Display for ParameterC { write!( f, "{} {} {}", - self.type_qualifier, - self.type_name, - self.pointer_level + self.type_qualifier, self.type_name, self.pointer_level ) } } diff --git a/tests/quickchecking/src/lib.rs b/bindgen-tests/tests/quickchecking/src/lib.rs similarity index 93% rename from tests/quickchecking/src/lib.rs rename to bindgen-tests/tests/quickchecking/src/lib.rs index d8633dfb92..b09d1c4922 100644 --- a/tests/quickchecking/src/lib.rs +++ b/bindgen-tests/tests/quickchecking/src/lib.rs @@ -26,15 +26,15 @@ extern crate quickcheck; extern crate rand; extern crate tempdir; -use std::sync::Mutex; use quickcheck::{QuickCheck, StdGen, TestResult}; +use rand::thread_rng; +use std::error::Error; use std::fs::File; use std::io::Write; -use tempdir::TempDir; -use std::process::{Command, Output}; use std::path::PathBuf; -use std::error::Error; -use rand::thread_rng; +use std::process::{Command, Output}; +use std::sync::Mutex; +use tempdir::TempDir; /// Contains definitions of and impls for types used to fuzz C declarations. pub mod fuzzers; @@ -47,12 +47,15 @@ struct Context { // Initialize global context. lazy_static! { - static ref CONTEXT: Mutex = Mutex::new(Context { output_path: None }); + static ref CONTEXT: Mutex = + Mutex::new(Context { output_path: None }); } // Passes fuzzed header to the `csmith-fuzzing/predicate.py` script, returns // output of the associated command. -fn run_predicate_script(header: fuzzers::HeaderC) -> Result> { +fn run_predicate_script( + header: fuzzers::HeaderC, +) -> Result> { let dir = TempDir::new("bindgen_prop")?; let header_path = dir.path().join("prop_test.h"); @@ -110,7 +113,11 @@ fn bindgen_prop(header: fuzzers::HeaderC) -> TestResult { /// fuzzed C headers generated with types defined in the `fuzzers` module. /// Success/Failure is dictated by the result of passing the fuzzed headers /// to the `csmith-fuzzing/predicate.py` script. -pub fn test_bindgen(generate_range: usize, tests: usize, output_path: Option<&str>) { +pub fn test_bindgen( + generate_range: usize, + tests: usize, + output_path: Option<&str>, +) { match output_path { Some(path) => { CONTEXT.lock().unwrap().output_path = diff --git a/tests/quickchecking/tests/fuzzed-c-headers.rs b/bindgen-tests/tests/quickchecking/tests/fuzzed-c-headers.rs similarity index 87% rename from tests/quickchecking/tests/fuzzed-c-headers.rs rename to bindgen-tests/tests/quickchecking/tests/fuzzed-c-headers.rs index 6b58d24b23..800c70b43f 100644 --- a/tests/quickchecking/tests/fuzzed-c-headers.rs +++ b/bindgen-tests/tests/quickchecking/tests/fuzzed-c-headers.rs @@ -1,13 +1,14 @@ - extern crate quickcheck; extern crate quickchecking; extern crate rand; -use quickchecking::fuzzers::{ArrayDimensionC, BaseTypeC, BasicTypeDeclarationC, DeclarationC, - DeclarationListC, FunctionPointerDeclarationC, FunctionPrototypeC, - HeaderC, ParameterC, ParameterListC, PointerLevelC, - StructDeclarationC, TypeQualifierC, UnionDeclarationC}; use quickcheck::{Arbitrary, StdGen}; +use quickchecking::fuzzers::{ + ArrayDimensionC, BaseTypeC, BasicTypeDeclarationC, DeclarationC, + DeclarationListC, FunctionPointerDeclarationC, FunctionPrototypeC, HeaderC, + ParameterC, ParameterListC, PointerLevelC, StructDeclarationC, + TypeQualifierC, UnionDeclarationC, +}; use rand::thread_rng; #[test] diff --git a/tests/rustfmt.toml b/bindgen-tests/tests/rustfmt.toml similarity index 100% rename from tests/rustfmt.toml rename to bindgen-tests/tests/rustfmt.toml diff --git a/tests/stylo.hpp b/bindgen-tests/tests/stylo.hpp similarity index 100% rename from tests/stylo.hpp rename to bindgen-tests/tests/stylo.hpp diff --git a/tests/stylo_sanity.rs b/bindgen-tests/tests/stylo_sanity.rs similarity index 100% rename from tests/stylo_sanity.rs rename to bindgen-tests/tests/stylo_sanity.rs diff --git a/tests/test-one.sh b/bindgen-tests/tests/test-one.sh similarity index 100% rename from tests/test-one.sh rename to bindgen-tests/tests/test-one.sh diff --git a/tests/tests.rs b/bindgen-tests/tests/tests.rs similarity index 95% rename from tests/tests.rs rename to bindgen-tests/tests/tests.rs index ac53d73965..ca081e2683 100644 --- a/tests/tests.rs +++ b/bindgen-tests/tests/tests.rs @@ -13,10 +13,11 @@ use std::path::{Path, PathBuf}; use std::process; use std::sync::Once; -#[path = "../src/options.rs"] -mod options; use crate::options::builder_from_flags; +#[path = "../../bindgen-cli/options.rs"] +mod options; + mod parse_callbacks; // Run `rustfmt` on the given source string and return a tuple of the formatted @@ -600,12 +601,12 @@ fn test_mixed_header_and_header_contents() { #[cfg(not(target_os = "windows"))] fn no_system_header_includes() { use std::process::Command; - assert!(Command::new("./ci/no-includes.sh") + assert!(Command::new("../ci/no-includes.sh") .current_dir(env!("CARGO_MANIFEST_DIR")) .spawn() - .expect("should spawn ./ci/no-includes.sh OK") + .expect("should spawn ../ci/no-includes.sh OK") .wait() - .expect("should wait for ./ci/no-includes OK") + .expect("should wait for ../ci/no-includes OK") .success()); } @@ -686,3 +687,29 @@ fn allowlist_warnings() { assert_eq!(1, bindings.warnings().len()); } + +fn build_flags_output_helper(builder: &bindgen::Builder) { + let mut command_line_flags = builder.command_line_flags(); + command_line_flags.insert(0, "bindgen".to_string()); + + let flags_quoted: Vec = command_line_flags + .iter() + .map(|x| format!("{}", shlex::quote(x))) + .collect(); + let flags_str = flags_quoted.join(" "); + println!("{}", flags_str); + + let (builder, _output, _verbose) = + crate::options::builder_from_flags(command_line_flags.into_iter()) + .unwrap(); + builder.generate().expect("failed to generate bindings"); +} + +#[test] +fn commandline_multiple_headers() { + let bindings = bindgen::Builder::default() + .header("tests/headers/char.h") + .header("tests/headers/func_ptr.h") + .header("tests/headers/16-byte-alignment.h"); + build_flags_output_helper(&bindings); +} diff --git a/tests/uses/.gitignore b/bindgen-tests/tests/uses/.gitignore similarity index 100% rename from tests/uses/.gitignore rename to bindgen-tests/tests/uses/.gitignore diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml new file mode 100644 index 0000000000..dca779bd0c --- /dev/null +++ b/bindgen/Cargo.toml @@ -0,0 +1,69 @@ +[package] +authors = [ + "Jyun-Yan You ", + "Emilio Cobos Álvarez ", + "Nick Fitzgerald ", + "The Servo project developers", +] +description = "Automatically generates Rust FFI bindings to C and C++ libraries." +keywords = ["bindings", "ffi", "code-generation"] +categories = ["external-ffi-bindings", "development-tools::ffi"] +license = "BSD-3-Clause" +name = "bindgen" +readme = "README.md" +repository = "https://github.com/rust-lang/rust-bindgen" +documentation = "https://docs.rs/bindgen" +homepage = "https://rust-lang.github.io/rust-bindgen/" +version = "0.60.1" +edition = "2018" +build = "build.rs" +# If you change this, also update README.md and msrv in .github/workflows/bindgen.yml +rust-version = "1.57.0" + +include = [ + "LICENSE", + "README.md", + "Cargo.toml", + "build.rs", + "src/*.rs", + "src/**/*.rs", +] + + +[lib] +name = "bindgen" +path = "./lib.rs" + +[badges] +travis-ci = { repository = "rust-lang/rust-bindgen" } + +[dependencies] +bitflags = "1.0.3" +cexpr = "0.6" +clang-sys = { version = "1", features = ["clang_6_0"] } +lazycell = "1" +lazy_static = "1" +peeking_take_while = "0.1.2" +quote = { version = "1", default-features = false } +syn = { version = "1.0.99", features = ["full", "extra-traits"]} +regex = { version = "1.5", default-features = false , features = ["std", "unicode"] } +which = { version = "4.2.1", optional = true, default-features = false } +shlex = "1" +rustc-hash = "1.0.1" +proc-macro2 = { version = "1", default-features = false } +log = { version = "0.4", optional = true } + +[features] +default = ["logging", "runtime", "which-rustfmt"] +logging = ["log"] +static = ["clang-sys/static"] +runtime = ["clang-sys/runtime"] +# Dynamically discover a `rustfmt` binary using the `which` crate +which-rustfmt = ["which"] + +# These features only exist for CI testing -- don't use them if you're not hacking +# on bindgen! +testing_only_docs = [] +testing_only_extra_assertions = [] +testing_only_libclang_9 = [] +testing_only_libclang_5 = [] diff --git a/bindgen/build.rs b/bindgen/build.rs new file mode 100644 index 0000000000..8407ceae8f --- /dev/null +++ b/bindgen/build.rs @@ -0,0 +1,29 @@ +use std::env; +use std::fs::File; +use std::io::Write; +use std::path::{Path, PathBuf}; + +fn main() { + let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); + + let mut dst = + File::create(Path::new(&out_dir).join("host-target.txt")).unwrap(); + dst.write_all(env::var("TARGET").unwrap().as_bytes()) + .unwrap(); + + // On behalf of clang_sys, rebuild ourselves if important configuration + // variables change, to ensure that bindings get rebuilt if the + // underlying libclang changes. + println!("cargo:rerun-if-env-changed=LLVM_CONFIG_PATH"); + println!("cargo:rerun-if-env-changed=LIBCLANG_PATH"); + println!("cargo:rerun-if-env-changed=LIBCLANG_STATIC_PATH"); + println!("cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS"); + println!( + "cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_{}", + std::env::var("TARGET").unwrap() + ); + println!( + "cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_{}", + std::env::var("TARGET").unwrap().replace('-', "_") + ); +} diff --git a/src/callbacks.rs b/bindgen/callbacks.rs similarity index 100% rename from src/callbacks.rs rename to bindgen/callbacks.rs diff --git a/src/clang.rs b/bindgen/clang.rs similarity index 100% rename from src/clang.rs rename to bindgen/clang.rs diff --git a/src/codegen/bitfield_unit.rs b/bindgen/codegen/bitfield_unit.rs similarity index 100% rename from src/codegen/bitfield_unit.rs rename to bindgen/codegen/bitfield_unit.rs diff --git a/src/codegen/bitfield_unit_tests.rs b/bindgen/codegen/bitfield_unit_tests.rs similarity index 100% rename from src/codegen/bitfield_unit_tests.rs rename to bindgen/codegen/bitfield_unit_tests.rs diff --git a/src/codegen/dyngen.rs b/bindgen/codegen/dyngen.rs similarity index 100% rename from src/codegen/dyngen.rs rename to bindgen/codegen/dyngen.rs diff --git a/src/codegen/error.rs b/bindgen/codegen/error.rs similarity index 100% rename from src/codegen/error.rs rename to bindgen/codegen/error.rs diff --git a/src/codegen/helpers.rs b/bindgen/codegen/helpers.rs similarity index 100% rename from src/codegen/helpers.rs rename to bindgen/codegen/helpers.rs diff --git a/src/codegen/impl_debug.rs b/bindgen/codegen/impl_debug.rs similarity index 100% rename from src/codegen/impl_debug.rs rename to bindgen/codegen/impl_debug.rs diff --git a/src/codegen/impl_partialeq.rs b/bindgen/codegen/impl_partialeq.rs similarity index 100% rename from src/codegen/impl_partialeq.rs rename to bindgen/codegen/impl_partialeq.rs diff --git a/src/codegen/mod.rs b/bindgen/codegen/mod.rs similarity index 100% rename from src/codegen/mod.rs rename to bindgen/codegen/mod.rs diff --git a/src/codegen/postprocessing/merge_extern_blocks.rs b/bindgen/codegen/postprocessing/merge_extern_blocks.rs similarity index 100% rename from src/codegen/postprocessing/merge_extern_blocks.rs rename to bindgen/codegen/postprocessing/merge_extern_blocks.rs diff --git a/src/codegen/postprocessing/mod.rs b/bindgen/codegen/postprocessing/mod.rs similarity index 100% rename from src/codegen/postprocessing/mod.rs rename to bindgen/codegen/postprocessing/mod.rs diff --git a/src/codegen/postprocessing/sort_semantically.rs b/bindgen/codegen/postprocessing/sort_semantically.rs similarity index 100% rename from src/codegen/postprocessing/sort_semantically.rs rename to bindgen/codegen/postprocessing/sort_semantically.rs diff --git a/src/codegen/struct_layout.rs b/bindgen/codegen/struct_layout.rs similarity index 100% rename from src/codegen/struct_layout.rs rename to bindgen/codegen/struct_layout.rs diff --git a/csmith-fuzzing/README.md b/bindgen/csmith-fuzzing/README.md similarity index 100% rename from csmith-fuzzing/README.md rename to bindgen/csmith-fuzzing/README.md diff --git a/csmith-fuzzing/csmith.h b/bindgen/csmith-fuzzing/csmith.h similarity index 100% rename from csmith-fuzzing/csmith.h rename to bindgen/csmith-fuzzing/csmith.h diff --git a/csmith-fuzzing/driver.py b/bindgen/csmith-fuzzing/driver.py similarity index 100% rename from csmith-fuzzing/driver.py rename to bindgen/csmith-fuzzing/driver.py diff --git a/csmith-fuzzing/predicate.py b/bindgen/csmith-fuzzing/predicate.py similarity index 100% rename from csmith-fuzzing/predicate.py rename to bindgen/csmith-fuzzing/predicate.py diff --git a/src/deps.rs b/bindgen/deps.rs similarity index 100% rename from src/deps.rs rename to bindgen/deps.rs diff --git a/src/extra_assertions.rs b/bindgen/extra_assertions.rs similarity index 100% rename from src/extra_assertions.rs rename to bindgen/extra_assertions.rs diff --git a/src/features.rs b/bindgen/features.rs similarity index 100% rename from src/features.rs rename to bindgen/features.rs diff --git a/src/ir/analysis/derive.rs b/bindgen/ir/analysis/derive.rs similarity index 100% rename from src/ir/analysis/derive.rs rename to bindgen/ir/analysis/derive.rs diff --git a/src/ir/analysis/has_destructor.rs b/bindgen/ir/analysis/has_destructor.rs similarity index 100% rename from src/ir/analysis/has_destructor.rs rename to bindgen/ir/analysis/has_destructor.rs diff --git a/src/ir/analysis/has_float.rs b/bindgen/ir/analysis/has_float.rs similarity index 100% rename from src/ir/analysis/has_float.rs rename to bindgen/ir/analysis/has_float.rs diff --git a/src/ir/analysis/has_type_param_in_array.rs b/bindgen/ir/analysis/has_type_param_in_array.rs similarity index 100% rename from src/ir/analysis/has_type_param_in_array.rs rename to bindgen/ir/analysis/has_type_param_in_array.rs diff --git a/src/ir/analysis/has_vtable.rs b/bindgen/ir/analysis/has_vtable.rs similarity index 100% rename from src/ir/analysis/has_vtable.rs rename to bindgen/ir/analysis/has_vtable.rs diff --git a/src/ir/analysis/mod.rs b/bindgen/ir/analysis/mod.rs similarity index 100% rename from src/ir/analysis/mod.rs rename to bindgen/ir/analysis/mod.rs diff --git a/src/ir/analysis/sizedness.rs b/bindgen/ir/analysis/sizedness.rs similarity index 100% rename from src/ir/analysis/sizedness.rs rename to bindgen/ir/analysis/sizedness.rs diff --git a/src/ir/analysis/template_params.rs b/bindgen/ir/analysis/template_params.rs similarity index 100% rename from src/ir/analysis/template_params.rs rename to bindgen/ir/analysis/template_params.rs diff --git a/src/ir/annotations.rs b/bindgen/ir/annotations.rs similarity index 100% rename from src/ir/annotations.rs rename to bindgen/ir/annotations.rs diff --git a/src/ir/comment.rs b/bindgen/ir/comment.rs similarity index 100% rename from src/ir/comment.rs rename to bindgen/ir/comment.rs diff --git a/src/ir/comp.rs b/bindgen/ir/comp.rs similarity index 100% rename from src/ir/comp.rs rename to bindgen/ir/comp.rs diff --git a/src/ir/context.rs b/bindgen/ir/context.rs similarity index 100% rename from src/ir/context.rs rename to bindgen/ir/context.rs diff --git a/src/ir/derive.rs b/bindgen/ir/derive.rs similarity index 100% rename from src/ir/derive.rs rename to bindgen/ir/derive.rs diff --git a/src/ir/dot.rs b/bindgen/ir/dot.rs similarity index 100% rename from src/ir/dot.rs rename to bindgen/ir/dot.rs diff --git a/src/ir/enum_ty.rs b/bindgen/ir/enum_ty.rs similarity index 100% rename from src/ir/enum_ty.rs rename to bindgen/ir/enum_ty.rs diff --git a/src/ir/function.rs b/bindgen/ir/function.rs similarity index 100% rename from src/ir/function.rs rename to bindgen/ir/function.rs diff --git a/src/ir/int.rs b/bindgen/ir/int.rs similarity index 100% rename from src/ir/int.rs rename to bindgen/ir/int.rs diff --git a/src/ir/item.rs b/bindgen/ir/item.rs similarity index 100% rename from src/ir/item.rs rename to bindgen/ir/item.rs diff --git a/src/ir/item_kind.rs b/bindgen/ir/item_kind.rs similarity index 100% rename from src/ir/item_kind.rs rename to bindgen/ir/item_kind.rs diff --git a/src/ir/layout.rs b/bindgen/ir/layout.rs similarity index 100% rename from src/ir/layout.rs rename to bindgen/ir/layout.rs diff --git a/src/ir/mod.rs b/bindgen/ir/mod.rs similarity index 100% rename from src/ir/mod.rs rename to bindgen/ir/mod.rs diff --git a/src/ir/module.rs b/bindgen/ir/module.rs similarity index 100% rename from src/ir/module.rs rename to bindgen/ir/module.rs diff --git a/src/ir/objc.rs b/bindgen/ir/objc.rs similarity index 100% rename from src/ir/objc.rs rename to bindgen/ir/objc.rs diff --git a/src/ir/template.rs b/bindgen/ir/template.rs similarity index 100% rename from src/ir/template.rs rename to bindgen/ir/template.rs diff --git a/src/ir/traversal.rs b/bindgen/ir/traversal.rs similarity index 100% rename from src/ir/traversal.rs rename to bindgen/ir/traversal.rs diff --git a/src/ir/ty.rs b/bindgen/ir/ty.rs similarity index 100% rename from src/ir/ty.rs rename to bindgen/ir/ty.rs diff --git a/src/ir/var.rs b/bindgen/ir/var.rs similarity index 100% rename from src/ir/var.rs rename to bindgen/ir/var.rs diff --git a/src/lib.rs b/bindgen/lib.rs similarity index 100% rename from src/lib.rs rename to bindgen/lib.rs diff --git a/src/log_stubs.rs b/bindgen/log_stubs.rs similarity index 100% rename from src/log_stubs.rs rename to bindgen/log_stubs.rs diff --git a/src/parse.rs b/bindgen/parse.rs similarity index 100% rename from src/parse.rs rename to bindgen/parse.rs diff --git a/src/regex_set.rs b/bindgen/regex_set.rs similarity index 100% rename from src/regex_set.rs rename to bindgen/regex_set.rs diff --git a/src/time.rs b/bindgen/time.rs similarity index 100% rename from src/time.rs rename to bindgen/time.rs diff --git a/book/src/command-line-usage.md b/book/src/command-line-usage.md index d90eb442b8..b3356d70c7 100644 --- a/book/src/command-line-usage.md +++ b/book/src/command-line-usage.md @@ -3,7 +3,7 @@ Install the `bindgen` executable with `cargo`: ```bash -$ cargo install bindgen +$ cargo install bindgen-cli ``` The `bindgen` executable is installed to `~/.cargo/bin`. You have to add that diff --git a/build.rs b/build.rs deleted file mode 100644 index 8c05d59b4c..0000000000 --- a/build.rs +++ /dev/null @@ -1,90 +0,0 @@ -mod target { - use std::env; - use std::fs::File; - use std::io::Write; - use std::path::{Path, PathBuf}; - - pub fn main() { - let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); - - let mut dst = - File::create(Path::new(&out_dir).join("host-target.txt")).unwrap(); - dst.write_all(env::var("TARGET").unwrap().as_bytes()) - .unwrap(); - } -} - -mod testgen { - use std::char; - use std::env; - use std::ffi::OsStr; - use std::fs::{self, File}; - use std::io::Write; - use std::path::{Path, PathBuf}; - - pub fn main() { - let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); - let mut dst = - File::create(Path::new(&out_dir).join("tests.rs")).unwrap(); - - let manifest_dir = - PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()); - let headers_dir = manifest_dir.join("tests").join("headers"); - - let headers = match fs::read_dir(headers_dir) { - Ok(dir) => dir, - // We may not have headers directory after packaging. - Err(..) => return, - }; - - let entries = - headers.map(|result| result.expect("Couldn't read header file")); - - println!("cargo:rerun-if-changed=tests/headers"); - - for entry in entries { - match entry.path().extension().and_then(OsStr::to_str) { - Some("h") | Some("hpp") => { - let func = entry - .file_name() - .to_str() - .unwrap() - .replace(|c| !char::is_alphanumeric(c), "_") - .replace("__", "_") - .to_lowercase(); - writeln!( - dst, - "test_header!(header_{}, {:?});", - func, - entry.path(), - ) - .unwrap(); - } - _ => {} - } - } - - dst.flush().unwrap(); - } -} - -fn main() { - target::main(); - testgen::main(); - - // On behalf of clang_sys, rebuild ourselves if important configuration - // variables change, to ensure that bindings get rebuilt if the - // underlying libclang changes. - println!("cargo:rerun-if-env-changed=LLVM_CONFIG_PATH"); - println!("cargo:rerun-if-env-changed=LIBCLANG_PATH"); - println!("cargo:rerun-if-env-changed=LIBCLANG_STATIC_PATH"); - println!("cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS"); - println!( - "cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_{}", - std::env::var("TARGET").unwrap() - ); - println!( - "cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_{}", - std::env::var("TARGET").unwrap().replace('-', "_") - ); -} diff --git a/ci/no-includes.sh b/ci/no-includes.sh index 6aa0fc125e..97966cb090 100755 --- a/ci/no-includes.sh +++ b/ci/no-includes.sh @@ -7,7 +7,7 @@ cd "$(dirname "$0")/.." echo "Checking for #include directives of system headers..." -grep -rn '#include\s*<.*>' tests/headers || { +grep -rn '#include\s*<.*>' bindgen-tests/tests/headers || { echo "Found none; OK!" exit 0 } diff --git a/ci/test.sh b/ci/test.sh index b58ed0f14d..788c28fe27 100755 --- a/ci/test.sh +++ b/ci/test.sh @@ -126,11 +126,11 @@ fi CARGO_ARGS=`get_cargo_args` # Ensure we build without warnings -cargo rustc --lib $CARGO_ARGS -- -Dwarnings +RUSTFLAGS="-Dwarnings" cargo check $CARGO_ARGS if [ "$BINDGEN_MAIN_TESTS" == "1" ]; then # Run the tests - cargo test $CARGO_ARGS + (cd bindgen-tests && cargo test $CARGO_ARGS) fi assert_no_diff From 576fd8d424c8248726542b0951c594a9734cd02a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 5 Oct 2022 05:00:28 +0200 Subject: [PATCH 376/942] context: Fix tokenization of C++20 inline namespace. (#2294) Fixes #2293 --- .../tests/inline_namespace_nested.rs | 21 ++++++ .../libclang-5/inline_namespace_nested.rs | 1 + .../tests/headers/inline_namespace_nested.hpp | 5 ++ bindgen-tests/tests/tests.rs | 2 +- bindgen/ir/context.rs | 71 +++++++++---------- 5 files changed, 63 insertions(+), 37 deletions(-) create mode 100644 bindgen-tests/tests/expectations/tests/inline_namespace_nested.rs create mode 100644 bindgen-tests/tests/expectations/tests/libclang-5/inline_namespace_nested.rs create mode 100644 bindgen-tests/tests/headers/inline_namespace_nested.hpp diff --git a/bindgen-tests/tests/expectations/tests/inline_namespace_nested.rs b/bindgen-tests/tests/expectations/tests/inline_namespace_nested.rs new file mode 100644 index 0000000000..29b5b35ffa --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/inline_namespace_nested.rs @@ -0,0 +1,21 @@ +#![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 { + #[allow(unused_imports)] + use self::super::root; + pub mod ranges { + #[allow(unused_imports)] + use self::super::super::root; + pub mod bar { + #[allow(unused_imports)] + use self::super::super::super::root; + pub const bar: ::std::os::raw::c_int = 0; + } + } +} diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/inline_namespace_nested.rs b/bindgen-tests/tests/expectations/tests/libclang-5/inline_namespace_nested.rs new file mode 100644 index 0000000000..996b877e50 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/libclang-5/inline_namespace_nested.rs @@ -0,0 +1 @@ +/* error generating bindings */ diff --git a/bindgen-tests/tests/headers/inline_namespace_nested.hpp b/bindgen-tests/tests/headers/inline_namespace_nested.hpp new file mode 100644 index 0000000000..5c542e195c --- /dev/null +++ b/bindgen-tests/tests/headers/inline_namespace_nested.hpp @@ -0,0 +1,5 @@ +// bindgen-flags: --enable-cxx-namespaces -- -std=c++2a + +namespace ranges::inline foo::bar { + static int bar = 0; +} diff --git a/bindgen-tests/tests/tests.rs b/bindgen-tests/tests/tests.rs index ca081e2683..25c073cc84 100644 --- a/bindgen-tests/tests/tests.rs +++ b/bindgen-tests/tests/tests.rs @@ -252,7 +252,7 @@ fn compare_generated_header( let actual = bindings.to_string(); rustfmt(actual) } - Err(_) => ("".to_string(), "".to_string()), + Err(_) => ("/* error generating bindings */\n".into(), "".to_string()), }; println!("{}", rustfmt_stderr); diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index 12373952ff..e2a13b8d17 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -2107,13 +2107,18 @@ If you encounter an error missing from this list, please file an issue or a PR!" } let mut kind = ModuleKind::Normal; - let mut found_namespace_keyword = false; + let mut looking_for_name = false; for token in cursor.tokens().iter() { match token.spelling() { b"inline" => { - assert!(!found_namespace_keyword); - assert!(kind != ModuleKind::Inline); + debug_assert!( + kind != ModuleKind::Inline, + "Multiple inline keywords?" + ); kind = ModuleKind::Inline; + // When hitting a nested inline namespace we get a spelling + // that looks like ["inline", "foo"]. Deal with it properly. + looking_for_name = true; } // The double colon allows us to handle nested namespaces like // namespace foo::bar { } @@ -2122,45 +2127,39 @@ If you encounter an error missing from this list, please file an issue or a PR!" // but the tokenization of the second begins with the double // colon. That's ok, so we only need to handle the weird // tokenization here. - // - // Fortunately enough, inline nested namespace specifiers aren't - // a thing, and are invalid C++ :) b"namespace" | b"::" => { - found_namespace_keyword = true; + looking_for_name = true; } b"{" => { - assert!(found_namespace_keyword); + // This should be an anonymous namespace. + assert!(looking_for_name); break; } - name if found_namespace_keyword => { - if module_name.is_none() { - module_name = - Some(String::from_utf8_lossy(name).into_owned()); + name => { + if looking_for_name { + if module_name.is_none() { + module_name = Some( + String::from_utf8_lossy(name).into_owned(), + ); + } + break; + } else { + // This is _likely_, but not certainly, a macro that's + // been placed just before the namespace keyword. + // Unfortunately, clang tokens don't let us easily see + // through the ifdef tokens, so we don't know what this + // token should really be. Instead of panicking though, + // we warn the user that we assumed the token was blank, + // and then move on. + // + // See also https://github.com/rust-lang/rust-bindgen/issues/1676. + warn!( + "Ignored unknown namespace prefix '{}' at {:?} in {:?}", + String::from_utf8_lossy(name), + token, + cursor + ); } - break; - } - spelling if !found_namespace_keyword => { - // This is _likely_, but not certainly, a macro that's been placed just before - // the namespace keyword. Unfortunately, clang tokens don't let us easily see - // through the ifdef tokens, so we don't know what this token should really be. - // Instead of panicking though, we warn the user that we assumed the token was - // blank, and then move on. - // - // See also https://github.com/rust-lang/rust-bindgen/issues/1676. - warn!( - "Ignored unknown namespace prefix '{}' at {:?} in {:?}", - String::from_utf8_lossy(spelling), - token, - cursor - ); - } - spelling => { - panic!( - "Unknown token '{}' while processing namespace at {:?} in {:?}", - String::from_utf8_lossy(spelling), - token, - cursor - ); } } } From 4dd91ff6d72fb5df122e5957f31d1368e84d80a2 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Thu, 6 Oct 2022 14:52:29 -0500 Subject: [PATCH 377/942] Make postprocessing more robust This is done by merging extern blocks and sorting items in every module instead of just in the root module. The tests were changed to use `cxx` namespaces so they effectively check that items are manipulated correctly in every single module. --- .../expectations/tests/merge-extern-blocks.rs | 113 ++++++--- .../tests/expectations/tests/sort-items.rs | 220 ++++++++++++++++++ .../tests/expectations/tests/sorted-items.rs | 82 ------- .../tests/expectations/tests/sorted_items.rs | 220 ++++++++++++++++++ .../tests/headers/merge-extern-blocks.h | 6 - .../tests/headers/merge-extern-blocks.hpp | 14 ++ bindgen-tests/tests/headers/sorted-items.h | 17 -- bindgen-tests/tests/headers/sorted_items.hpp | 35 +++ bindgen/Cargo.toml | 2 +- .../postprocessing/merge_extern_blocks.rs | 94 +++++--- bindgen/codegen/postprocessing/mod.rs | 28 +-- .../postprocessing/sort_semantically.rs | 58 +++-- 12 files changed, 681 insertions(+), 208 deletions(-) create mode 100644 bindgen-tests/tests/expectations/tests/sort-items.rs delete mode 100644 bindgen-tests/tests/expectations/tests/sorted-items.rs create mode 100644 bindgen-tests/tests/expectations/tests/sorted_items.rs delete mode 100644 bindgen-tests/tests/headers/merge-extern-blocks.h create mode 100644 bindgen-tests/tests/headers/merge-extern-blocks.hpp delete mode 100644 bindgen-tests/tests/headers/sorted-items.h create mode 100644 bindgen-tests/tests/headers/sorted_items.hpp diff --git a/bindgen-tests/tests/expectations/tests/merge-extern-blocks.rs b/bindgen-tests/tests/expectations/tests/merge-extern-blocks.rs index 66ceeff07f..ae9799d275 100644 --- a/bindgen-tests/tests/expectations/tests/merge-extern-blocks.rs +++ b/bindgen-tests/tests/expectations/tests/merge-extern-blocks.rs @@ -5,33 +5,88 @@ non_upper_case_globals )] -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct Point { - pub x: ::std::os::raw::c_int, -} -#[test] -fn bindgen_test_layout_Point() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Point)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Point)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Point), "::", stringify!(x)) - ); -} -extern "C" { - pub fn foo() -> ::std::os::raw::c_int; - pub fn bar() -> ::std::os::raw::c_int; +#[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub mod root { + #[allow(unused_imports)] + use self::super::root; + #[repr(C)] + #[derive(Debug, Default, Copy, Clone)] + pub struct Point { + pub x: ::std::os::raw::c_int, + } + #[test] + fn bindgen_test_layout_Point() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Point)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Point)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Point), + "::", + stringify!(x) + ) + ); + } + pub mod ns { + #[allow(unused_imports)] + use self::super::super::root; + #[repr(C)] + #[derive(Debug, Default, Copy, Clone)] + pub struct Point { + pub x: ::std::os::raw::c_int, + } + #[test] + fn bindgen_test_layout_Point() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Point)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Point)) + ); + assert_eq!( + unsafe { + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Point), + "::", + stringify!(x) + ) + ); + } + extern "C" { + #[link_name = "\u{1}_ZN2ns3fooEv"] + pub fn foo() -> ::std::os::raw::c_int; + #[link_name = "\u{1}_ZN2ns3barEv"] + pub fn bar() -> ::std::os::raw::c_int; + } + } + extern "C" { + #[link_name = "\u{1}_Z3foov"] + pub fn foo() -> ::std::os::raw::c_int; + #[link_name = "\u{1}_Z3barv"] + pub fn bar() -> ::std::os::raw::c_int; + } } diff --git a/bindgen-tests/tests/expectations/tests/sort-items.rs b/bindgen-tests/tests/expectations/tests/sort-items.rs new file mode 100644 index 0000000000..e04e3b6090 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/sort-items.rs @@ -0,0 +1,220 @@ +#![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 { + pub type number = ::std::os::raw::c_int; + #[repr(C)] + #[derive(Debug, Default, Copy, Clone)] + pub struct Point { + pub x: root::number, + pub y: root::number, + } + #[repr(C)] + #[derive(Debug, Default, Copy, Clone)] + pub struct Angle { + pub a: root::number, + pub b: root::number, + } + pub const NUMBER: root::number = 42; + #[test] + fn bindgen_test_layout_Point() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Point)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Point)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Point), + "::", + stringify!(x) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(Point), + "::", + stringify!(y) + ) + ); + } + #[test] + fn bindgen_test_layout_Angle() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Angle)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Angle)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Angle), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(Angle), + "::", + stringify!(b) + ) + ); + } + pub mod ns { + pub type number = ::std::os::raw::c_int; + #[repr(C)] + #[derive(Debug, Default, Copy, Clone)] + pub struct Point { + pub x: root::ns::number, + pub y: root::ns::number, + } + #[repr(C)] + #[derive(Debug, Default, Copy, Clone)] + pub struct Angle { + pub a: root::ns::number, + pub b: root::ns::number, + } + pub const NUMBER: root::ns::number = 42; + #[test] + fn bindgen_test_layout_Point() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Point)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Point)) + ); + assert_eq!( + unsafe { + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Point), + "::", + stringify!(x) + ) + ); + assert_eq!( + unsafe { + ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(Point), + "::", + stringify!(y) + ) + ); + } + #[test] + fn bindgen_test_layout_Angle() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Angle)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Angle)) + ); + assert_eq!( + unsafe { + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Angle), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(Angle), + "::", + stringify!(b) + ) + ); + } + #[allow(unused_imports)] + use self::super::super::root; + extern "C" { + #[link_name = "\u{1}_ZN2ns3fooEv"] + pub fn foo() -> ::std::os::raw::c_int; + } + extern "C" { + #[link_name = "\u{1}_ZN2ns3barEi"] + pub fn bar(x: root::ns::number) -> ::std::os::raw::c_int; + } + extern "C" { + #[link_name = "\u{1}_ZN2ns3bazENS_5PointE"] + pub fn baz(point: root::ns::Point) -> ::std::os::raw::c_int; + } + } + #[allow(unused_imports)] + use self::super::root; + extern "C" { + #[link_name = "\u{1}_Z3foov"] + pub fn foo() -> ::std::os::raw::c_int; + } + extern "C" { + #[link_name = "\u{1}_Z3bari"] + pub fn bar(x: root::number) -> ::std::os::raw::c_int; + } + extern "C" { + #[link_name = "\u{1}_Z3baz5Point"] + pub fn baz(point: root::Point) -> ::std::os::raw::c_int; + } +} diff --git a/bindgen-tests/tests/expectations/tests/sorted-items.rs b/bindgen-tests/tests/expectations/tests/sorted-items.rs deleted file mode 100644 index 7df7c3d71e..0000000000 --- a/bindgen-tests/tests/expectations/tests/sorted-items.rs +++ /dev/null @@ -1,82 +0,0 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -pub type number = ::std::os::raw::c_int; -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct Point { - pub x: number, - pub y: number, -} -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct Angle { - pub a: number, - pub b: number, -} -pub const NUMBER: number = 42; -#[test] -fn bindgen_test_layout_Point() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Point)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Point)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Point), "::", stringify!(x)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(Point), "::", stringify!(y)) - ); -} -#[test] -fn bindgen_test_layout_Angle() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Angle)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Angle)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Angle), "::", stringify!(a)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(Angle), "::", stringify!(b)) - ); -} -extern "C" { - pub fn foo() -> ::std::os::raw::c_int; -} -extern "C" { - pub fn bar(x: number) -> ::std::os::raw::c_int; -} -extern "C" { - pub fn baz(point: Point) -> ::std::os::raw::c_int; -} diff --git a/bindgen-tests/tests/expectations/tests/sorted_items.rs b/bindgen-tests/tests/expectations/tests/sorted_items.rs new file mode 100644 index 0000000000..e04e3b6090 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/sorted_items.rs @@ -0,0 +1,220 @@ +#![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 { + pub type number = ::std::os::raw::c_int; + #[repr(C)] + #[derive(Debug, Default, Copy, Clone)] + pub struct Point { + pub x: root::number, + pub y: root::number, + } + #[repr(C)] + #[derive(Debug, Default, Copy, Clone)] + pub struct Angle { + pub a: root::number, + pub b: root::number, + } + pub const NUMBER: root::number = 42; + #[test] + fn bindgen_test_layout_Point() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Point)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Point)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Point), + "::", + stringify!(x) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(Point), + "::", + stringify!(y) + ) + ); + } + #[test] + fn bindgen_test_layout_Angle() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Angle)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Angle)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Angle), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(Angle), + "::", + stringify!(b) + ) + ); + } + pub mod ns { + pub type number = ::std::os::raw::c_int; + #[repr(C)] + #[derive(Debug, Default, Copy, Clone)] + pub struct Point { + pub x: root::ns::number, + pub y: root::ns::number, + } + #[repr(C)] + #[derive(Debug, Default, Copy, Clone)] + pub struct Angle { + pub a: root::ns::number, + pub b: root::ns::number, + } + pub const NUMBER: root::ns::number = 42; + #[test] + fn bindgen_test_layout_Point() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Point)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Point)) + ); + assert_eq!( + unsafe { + ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Point), + "::", + stringify!(x) + ) + ); + assert_eq!( + unsafe { + ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(Point), + "::", + stringify!(y) + ) + ); + } + #[test] + fn bindgen_test_layout_Angle() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Angle)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Angle)) + ); + assert_eq!( + unsafe { + ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Angle), + "::", + stringify!(a) + ) + ); + assert_eq!( + unsafe { + ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(Angle), + "::", + stringify!(b) + ) + ); + } + #[allow(unused_imports)] + use self::super::super::root; + extern "C" { + #[link_name = "\u{1}_ZN2ns3fooEv"] + pub fn foo() -> ::std::os::raw::c_int; + } + extern "C" { + #[link_name = "\u{1}_ZN2ns3barEi"] + pub fn bar(x: root::ns::number) -> ::std::os::raw::c_int; + } + extern "C" { + #[link_name = "\u{1}_ZN2ns3bazENS_5PointE"] + pub fn baz(point: root::ns::Point) -> ::std::os::raw::c_int; + } + } + #[allow(unused_imports)] + use self::super::root; + extern "C" { + #[link_name = "\u{1}_Z3foov"] + pub fn foo() -> ::std::os::raw::c_int; + } + extern "C" { + #[link_name = "\u{1}_Z3bari"] + pub fn bar(x: root::number) -> ::std::os::raw::c_int; + } + extern "C" { + #[link_name = "\u{1}_Z3baz5Point"] + pub fn baz(point: root::Point) -> ::std::os::raw::c_int; + } +} diff --git a/bindgen-tests/tests/headers/merge-extern-blocks.h b/bindgen-tests/tests/headers/merge-extern-blocks.h deleted file mode 100644 index 1d46b7d4a3..0000000000 --- a/bindgen-tests/tests/headers/merge-extern-blocks.h +++ /dev/null @@ -1,6 +0,0 @@ -// bindgen-flags: --merge-extern-blocks -- --target=x86_64-unknown-linux -int foo(); -typedef struct Point { - int x; -} Point; -int bar(); diff --git a/bindgen-tests/tests/headers/merge-extern-blocks.hpp b/bindgen-tests/tests/headers/merge-extern-blocks.hpp new file mode 100644 index 0000000000..392e34a390 --- /dev/null +++ b/bindgen-tests/tests/headers/merge-extern-blocks.hpp @@ -0,0 +1,14 @@ +// bindgen-flags: --merge-extern-blocks --enable-cxx-namespaces -- --target=x86_64-unknown-linux +int foo(); +typedef struct Point { + int x; +} Point; +int bar(); + +namespace ns { + int foo(); + typedef struct Point { + int x; + } Point; + int bar(); +} diff --git a/bindgen-tests/tests/headers/sorted-items.h b/bindgen-tests/tests/headers/sorted-items.h deleted file mode 100644 index 11fc2ef40b..0000000000 --- a/bindgen-tests/tests/headers/sorted-items.h +++ /dev/null @@ -1,17 +0,0 @@ -// bindgen-flags: --sort-semantically -- --target=x86_64-unknown-linux - -int foo(); -typedef int number; -int bar(number x); -struct Point -{ - number x; - number y; -}; -struct Angle -{ - number a; - number b; -}; -int baz(struct Point point); -const number NUMBER = 42; diff --git a/bindgen-tests/tests/headers/sorted_items.hpp b/bindgen-tests/tests/headers/sorted_items.hpp new file mode 100644 index 0000000000..9b5ced9637 --- /dev/null +++ b/bindgen-tests/tests/headers/sorted_items.hpp @@ -0,0 +1,35 @@ +// bindgen-flags: --sort-semantically --enable-cxx-namespaces -- --target=x86_64-unknown-linux + +int foo(); +typedef int number; +int bar(number x); +struct Point +{ + number x; + number y; +}; +struct Angle +{ + number a; + number b; +}; +int baz(struct Point point); +const number NUMBER = 42; + +namespace ns { + int foo(); + typedef int number; + int bar(number x); + struct Point + { + number x; + number y; + }; + struct Angle + { + number a; + number b; + }; + int baz(struct Point point); + const number NUMBER = 42; +} diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index dca779bd0c..3965ad4d4c 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -45,7 +45,7 @@ lazycell = "1" lazy_static = "1" peeking_take_while = "0.1.2" quote = { version = "1", default-features = false } -syn = { version = "1.0.99", features = ["full", "extra-traits"]} +syn = { version = "1.0.99", features = ["full", "extra-traits", "visit-mut"]} regex = { version = "1.5", default-features = false , features = ["std", "unicode"] } which = { version = "4.2.1", optional = true, default-features = false } shlex = "1" diff --git a/bindgen/codegen/postprocessing/merge_extern_blocks.rs b/bindgen/codegen/postprocessing/merge_extern_blocks.rs index 2b7614941e..05e7e9ef39 100644 --- a/bindgen/codegen/postprocessing/merge_extern_blocks.rs +++ b/bindgen/codegen/postprocessing/merge_extern_blocks.rs @@ -1,46 +1,66 @@ -use syn::{Item, ItemForeignMod}; +use syn::{ + visit_mut::{visit_item_mod_mut, VisitMut}, + Item, ItemForeignMod, ItemMod, +}; -pub(super) fn merge_extern_blocks(items: &mut Vec) { - // Keep all the extern blocks in a different `Vec` for faster search. - let mut foreign_mods = Vec::::new(); +pub(super) fn merge_extern_blocks(item_mod: &mut ItemMod) { + Visitor.visit_item_mod_mut(item_mod) +} + +struct Visitor; - for item in std::mem::take(items) { - match item { - Item::ForeignMod(ItemForeignMod { - attrs, - abi, - brace_token, - items: foreign_items, - }) => { - let mut exists = false; - for foreign_mod in &mut foreign_mods { - // Check if there is a extern block with the same ABI and - // attributes. - if foreign_mod.attrs == attrs && foreign_mod.abi == abi { - // Merge the items of the two blocks. - foreign_mod.items.extend_from_slice(&foreign_items); - exists = true; - break; +impl VisitMut for Visitor { + fn visit_item_mod_mut(&mut self, item_mod: &mut ItemMod) { + if let Some((_, ref mut items)) = item_mod.content { + // Keep all the extern blocks in a different `Vec` for faster search. + let mut extern_blocks = Vec::::new(); + + for item in std::mem::take(items) { + if let Item::ForeignMod(ItemForeignMod { + attrs, + abi, + brace_token, + items: extern_block_items, + }) = item + { + let mut exists = false; + for extern_block in &mut extern_blocks { + // Check if there is a extern block with the same ABI and + // attributes. + if extern_block.attrs == attrs && + extern_block.abi == abi + { + // Merge the items of the two blocks. + extern_block + .items + .extend_from_slice(&extern_block_items); + exists = true; + break; + } } + // If no existing extern block had the same ABI and attributes, store + // it. + if !exists { + extern_blocks.push(ItemForeignMod { + attrs, + abi, + brace_token, + items: extern_block_items, + }); + } + } else { + // If the item is not an extern block, we don't have to do anything and just + // push it back. + items.push(item); } - // If no existing extern block had the same ABI and attributes, store - // it. - if !exists { - foreign_mods.push(ItemForeignMod { - attrs, - abi, - brace_token, - items: foreign_items, - }); - } } - // If the item is not an extern block, we don't have to do anything. - _ => items.push(item), + + // Move all the extern blocks alongside the rest of the items. + for extern_block in extern_blocks { + items.push(Item::ForeignMod(extern_block)); + } } - } - // Move all the extern blocks alongside the rest of the items. - for foreign_mod in foreign_mods { - items.push(Item::ForeignMod(foreign_mod)); + visit_item_mod_mut(self, item_mod) } } diff --git a/bindgen/codegen/postprocessing/mod.rs b/bindgen/codegen/postprocessing/mod.rs index c6612f2b91..1d5a4983bd 100644 --- a/bindgen/codegen/postprocessing/mod.rs +++ b/bindgen/codegen/postprocessing/mod.rs @@ -1,6 +1,6 @@ use proc_macro2::TokenStream; use quote::ToTokens; -use syn::Item; +use syn::{parse2, ItemMod}; use crate::BindgenOptions; @@ -12,7 +12,7 @@ use sort_semantically::sort_semantically; struct PostProcessingPass { should_run: fn(&BindgenOptions) -> bool, - run: fn(&mut Vec), + run: fn(&mut ItemMod), } // TODO: This can be a const fn when mutable references are allowed in const @@ -21,7 +21,7 @@ macro_rules! pass { ($pass:ident) => { PostProcessingPass { should_run: |options| options.$pass, - run: |items| $pass(items), + run: |item_mod| $pass(item_mod), } }; } @@ -38,29 +38,29 @@ pub(crate) fn postprocessing( return items.into_iter().collect(); } let module_wrapped_tokens = - quote!(mod wrapper_for_sorting_hack { #( #items )* }); + quote!(mod wrapper_for_postprocessing_hack { #( #items )* }); // This syn business is a hack, for now. This means that we are re-parsing already // generated code using `syn` (as opposed to `quote`) because `syn` provides us more // control over the elements. // One caveat is that some of the items coming from `quote`d output might have // multiple items within them. Hence, we have to wrap the incoming in a `mod`. - // The two `unwrap`s here are deliberate because - // The first one won't panic because we build the `mod` and know it is there - // The second one won't panic because we know original output has something in - // it already. - let (_, mut items) = syn::parse2::(module_wrapped_tokens) - .unwrap() - .content - .unwrap(); + // The `unwrap` here is deliberate because bindgen should generate valid rust items at all + // times. + let mut item_mod = parse2::(module_wrapped_tokens).unwrap(); for pass in PASSES { if (pass.should_run)(options) { - (pass.run)(&mut items); + (pass.run)(&mut item_mod); } } - let synful_items = items.into_iter().map(|item| item.into_token_stream()); + let synful_items = item_mod + .content + .map(|(_, items)| items) + .unwrap_or_default() + .into_iter() + .map(|item| item.into_token_stream()); quote! { #( #synful_items )* } } diff --git a/bindgen/codegen/postprocessing/sort_semantically.rs b/bindgen/codegen/postprocessing/sort_semantically.rs index 96596cb01e..4f23ab73a3 100644 --- a/bindgen/codegen/postprocessing/sort_semantically.rs +++ b/bindgen/codegen/postprocessing/sort_semantically.rs @@ -1,24 +1,38 @@ -use syn::Item; +use syn::{ + visit_mut::{visit_item_mod_mut, VisitMut}, + Item, ItemMod, +}; -pub(super) fn sort_semantically(items: &mut [Item]) { - items.sort_by_key(|item| match item { - Item::Type(_) => 0, - Item::Struct(_) => 1, - Item::Const(_) => 2, - Item::Fn(_) => 3, - Item::Enum(_) => 4, - Item::Union(_) => 5, - Item::Static(_) => 6, - Item::Trait(_) => 7, - Item::TraitAlias(_) => 8, - Item::Impl(_) => 9, - Item::Mod(_) => 10, - Item::Use(_) => 11, - Item::Verbatim(_) => 12, - Item::ExternCrate(_) => 13, - Item::ForeignMod(_) => 14, - Item::Macro(_) => 15, - Item::Macro2(_) => 16, - _ => 18, - }); +pub(super) fn sort_semantically(item_mod: &mut ItemMod) { + Visitor.visit_item_mod_mut(item_mod) +} + +struct Visitor; + +impl VisitMut for Visitor { + fn visit_item_mod_mut(&mut self, item_mod: &mut ItemMod) { + if let Some((_, ref mut items)) = item_mod.content { + items.sort_by_key(|item| match item { + Item::Type(_) => 0, + Item::Struct(_) => 1, + Item::Const(_) => 2, + Item::Fn(_) => 3, + Item::Enum(_) => 4, + Item::Union(_) => 5, + Item::Static(_) => 6, + Item::Trait(_) => 7, + Item::TraitAlias(_) => 8, + Item::Impl(_) => 9, + Item::Mod(_) => 10, + Item::Use(_) => 11, + Item::Verbatim(_) => 12, + Item::ExternCrate(_) => 13, + Item::ForeignMod(_) => 14, + Item::Macro(_) => 15, + Item::Macro2(_) => 16, + _ => 18, + }); + } + visit_item_mod_mut(self, item_mod) + } } From c8d569930e006a7e0975dfbaaf5e5d591749b30a Mon Sep 17 00:00:00 2001 From: Christian Poveda <31802960+pvdrz@users.noreply.github.com> Date: Thu, 6 Oct 2022 18:30:25 -0500 Subject: [PATCH 378/942] update `CHANGELOG.md` (#2298) --- CHANGELOG.md | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c2e64e670..d83e33d365 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -143,11 +143,38 @@ ## Added - * new feature: `--sort-semantically` flag to sort the output in a predefined manner [(#1743)] + * new feature: `--sort-semantically` flag to sort the output in a predefined + manner [(#1743)]. + * new feature: `Bindgen::emit_warnings` method to emit warnings to stderr in + build scripts. + * new feature: `--newtype-global-enum` flag to generate enum variants as + global constants. + * new feature: `--default-non-copy-union-style` flag to set the default style + of code used to generate unions with non-`Copy` members. + * new feature: `--bindgen-wrapper-union` flag to mark any union that matches a + regex and has a non-Copy member to use a bindgen-generated wrapper for its + fields. + * new feature: `--manually-drop-union` flag to mark any union that matches a + regex and has a non-`Copy` member to use `ManuallyDrop`. + * new feature: `--merge-extern-blocks` flag to merge several `extern` blocks + that have the same ABI. + * new feature: `--no-size_t-is-usize` flag to not bind `size_t` as `usize`. ## Changed - * clap has been updated, new msrv is 1.57. + * clap and regex have been updated, new msrv is 1.57. + * The `--enable-function-attribute-detection` flag is also used to detect + diverging functions so the generated bindings use `!` as the return type. + * The `--size_t-is-usize` flag is enabled by default. + * Unused type aliases for `` types are no longer emitted. + * The `blocklist` options now can be used to block objective-C methods. + * The `core::ffi` module is used the sized raw integer types + instead of `std::os::raw` if the Rust target version is `1.64` or higher and + the `--use-core` flag is enabled. + * The `bindgen` CLI utility must be installed using `cargo install + bindgen-cli` now. + * Using `bindgen` as a library no longer pulls clap and any other CLI + related dependencies. ## Removed From 46cd3af9c6969f1a433fe3792668844162f36ddf Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Mon, 3 Oct 2022 13:57:04 -0500 Subject: [PATCH 379/942] Implement `Clone` for `Builder` This is done by moving all the remaining `Builder` state into `BindgenOptions` so any internal logic that affects `Builder` state only runs once the builder is consumed by `Builder::generate`: - move `input_headers` to `BindgenOptions`. - move `input_header_contents` to `BindgenOptions`. - derive `Clone` for `Builder`. --- CHANGELOG.md | 1 + bindgen/clang.rs | 2 +- bindgen/ir/context.rs | 6 +--- bindgen/lib.rs | 73 +++++++++++++++++++++---------------------- 4 files changed, 38 insertions(+), 44 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d83e33d365..4b221e6d22 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -159,6 +159,7 @@ * new feature: `--merge-extern-blocks` flag to merge several `extern` blocks that have the same ABI. * new feature: `--no-size_t-is-usize` flag to not bind `size_t` as `usize`. + * new feature: `Builder` implements `Clone`. ## Changed diff --git a/bindgen/clang.rs b/bindgen/clang.rs index ea505c878b..e511339186 100644 --- a/bindgen/clang.rs +++ b/bindgen/clang.rs @@ -1823,7 +1823,7 @@ pub struct UnsavedFile { impl UnsavedFile { /// Construct a new unsaved file with the given `name` and `contents`. - pub fn new(name: &str, contents: &str) -> UnsavedFile { + pub fn new(name: String, contents: String) -> UnsavedFile { let name = CString::new(name).unwrap(); let contents = CString::new(contents).unwrap(); let x = CXUnsavedFile { diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index e2a13b8d17..ba2db1126c 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -541,11 +541,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" let root_module_id = root_module.id().as_module_id_unchecked(); // depfiles need to include the explicitly listed headers too - let mut deps = BTreeSet::default(); - if let Some(filename) = &options.input_header { - deps.insert(filename.clone()); - } - deps.extend(options.extra_input_headers.iter().cloned()); + let deps = options.input_headers.iter().cloned().collect(); BindgenContext { items: vec![Some(root_module)], diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 6e6fa225d6..880d52a9ee 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -79,12 +79,12 @@ use crate::parse::{ClangItemParser, ParseError}; use crate::regex_set::RegexSet; use std::borrow::Cow; +use std::env; use std::fs::{File, OpenOptions}; use std::io::{self, Write}; use std::path::{Path, PathBuf}; use std::process::{Command, Stdio}; use std::rc::Rc; -use std::{env, iter}; // Some convenient typedefs for a fast hash map and hash set. type HashMap = ::rustc_hash::FxHashMap; @@ -222,12 +222,9 @@ impl Default for CodegenConfig { /// End-users of the crate may need to set the `BINDGEN_EXTRA_CLANG_ARGS` environment variable to /// add additional arguments. For example, to build against a different sysroot a user could set /// `BINDGEN_EXTRA_CLANG_ARGS` to `--sysroot=/path/to/sysroot`. -#[derive(Debug, Default)] +#[derive(Debug, Default, Clone)] pub struct Builder { options: BindgenOptions, - input_headers: Vec, - // Tuples of unsaved file contents of the form (name, contents). - input_header_contents: Vec<(String, String)>, } /// Construct a new [`Builder`](./struct.Builder.html). @@ -254,7 +251,7 @@ impl Builder { pub fn command_line_flags(&self) -> Vec { let mut output_vector: Vec = Vec::new(); - if let Some(header) = self.input_headers.last().cloned() { + if let Some(header) = self.options.input_headers.last().cloned() { // Positional argument 'header' output_vector.push(header); } @@ -627,13 +624,13 @@ impl Builder { output_vector.extend(self.options.clang_args.iter().cloned()); } - if self.input_headers.len() > 1 { - // To pass more than one header, we need to pass all but the last - // header via the `-include` clang arg - for header in &self.input_headers[..self.input_headers.len() - 1] { - output_vector.push("-include".to_string()); - output_vector.push(header.clone()); - } + // To pass more than one header, we need to pass all but the last + // header via the `-include` clang arg + for header in &self.options.input_headers + [..self.options.input_headers.len().saturating_sub(1)] + { + output_vector.push("-include".to_string()); + output_vector.push(header.clone()); } output_vector @@ -662,7 +659,7 @@ impl Builder { /// .unwrap(); /// ``` pub fn header>(mut self, header: T) -> Builder { - self.input_headers.push(header.into()); + self.options.input_headers.push(header.into()); self } @@ -691,7 +688,8 @@ impl Builder { .to_str() .expect("Cannot convert current directory name to string") .to_owned(); - self.input_header_contents + self.options + .input_header_contents .push((absolute_path, contents.into())); self } @@ -1566,20 +1564,18 @@ impl Builder { self.options.clang_args.extend(get_extra_clang_args()); // Transform input headers to arguments on the clang command line. - self.options.input_header = self.input_headers.pop(); - self.options.extra_input_headers = self.input_headers; self.options.clang_args.extend( - self.options.extra_input_headers.iter().flat_map(|header| { - iter::once("-include".into()) - .chain(iter::once(header.to_string())) - }), + self.options.input_headers + [..self.options.input_headers.len().saturating_sub(1)] + .iter() + .flat_map(|header| ["-include".into(), header.to_string()]), ); - let input_unsaved_files = self - .input_header_contents - .into_iter() - .map(|(name, contents)| clang::UnsavedFile::new(&name, &contents)) - .collect::>(); + let input_unsaved_files = + std::mem::take(&mut self.options.input_header_contents) + .into_iter() + .map(|(name, contents)| clang::UnsavedFile::new(name, contents)) + .collect::>(); Bindings::generate(self.options, input_unsaved_files) } @@ -1606,7 +1602,7 @@ impl Builder { let mut is_cpp = args_are_cpp(&self.options.clang_args); // For each input header, add `#include "$header"`. - for header in &self.input_headers { + for header in &self.options.input_headers { is_cpp |= file_is_cpp(header); wrapper_contents.push_str("#include \""); @@ -1616,7 +1612,7 @@ impl Builder { // For each input header content, add a prefix line of `#line 0 "$name"` // followed by the contents. - for &(ref name, ref contents) in &self.input_header_contents { + for &(ref name, ref contents) in &self.options.input_header_contents { is_cpp |= file_is_cpp(name); wrapper_contents.push_str("#line 0 \""); @@ -1970,11 +1966,11 @@ struct BindgenOptions { /// The set of arguments to pass straight through to Clang. clang_args: Vec, - /// The input header file. - input_header: Option, + /// The input header files. + input_headers: Vec, - /// Any additional input header files. - extra_input_headers: Vec, + /// Tuples of unsaved file contents of the form (name, contents). + input_header_contents: Vec<(String, String)>, /// A user-provided visitor to allow customizing different kinds of /// situations. @@ -2224,8 +2220,8 @@ impl Default for BindgenOptions { raw_lines: vec![], module_lines: HashMap::default(), clang_args: vec![], - input_header: None, - extra_input_headers: vec![], + input_headers: vec![], + input_header_contents: Default::default(), parse_callbacks: None, codegen_config: CodegenConfig::all(), conservative_inline_namespaces: false, @@ -2470,7 +2466,7 @@ impl Bindings { // Whether we are working with C or C++ inputs. let is_cpp = args_are_cpp(&options.clang_args) || - options.input_header.as_deref().map_or(false, file_is_cpp); + options.input_headers.iter().any(|h| file_is_cpp(h)); let search_paths = if is_cpp { clang.cpp_search_paths @@ -2501,7 +2497,7 @@ impl Bindings { true } - if let Some(h) = options.input_header.as_ref() { + if let Some(h) = options.input_headers.last() { let path = Path::new(h); if let Ok(md) = std::fs::metadata(path) { if md.is_dir() { @@ -2512,14 +2508,15 @@ impl Bindings { path.into(), )); } - options.clang_args.push(h.clone()) + let h = h.clone(); + options.clang_args.push(h); } else { return Err(BindgenError::NotExist(path.into())); } } for (idx, f) in input_unsaved_files.iter().enumerate() { - if idx != 0 || options.input_header.is_some() { + if idx != 0 || !options.input_headers.is_empty() { options.clang_args.push("-include".to_owned()); } options.clang_args.push(f.name.to_str().unwrap().to_owned()) From 17dd0931306977abd13c90532d35b86237fcd7a7 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Fri, 7 Oct 2022 12:08:52 -0500 Subject: [PATCH 380/942] Handle incomplete external array constants This adds a new special case for constants like: ```c extern const char some_static_string[]; ``` so `bindgen` emits a `static` instead of a `static mut` for them. --- bindgen-tests/tests/expectations/tests/var-tracing.rs | 2 +- bindgen/ir/var.rs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/bindgen-tests/tests/expectations/tests/var-tracing.rs b/bindgen-tests/tests/expectations/tests/var-tracing.rs index 4280802ed2..37fdd95105 100644 --- a/bindgen-tests/tests/expectations/tests/var-tracing.rs +++ b/bindgen-tests/tests/expectations/tests/var-tracing.rs @@ -55,7 +55,7 @@ pub struct Baz { } extern "C" { #[link_name = "\u{1}_ZN3Baz3FOOE"] - pub static mut Baz_FOO: [Bar; 0usize]; + pub static Baz_FOO: [Bar; 0usize]; } #[test] fn bindgen_test_layout_Baz() { diff --git a/bindgen/ir/var.rs b/bindgen/ir/var.rs index eecca4df54..daaad8c56a 100644 --- a/bindgen/ir/var.rs +++ b/bindgen/ir/var.rs @@ -285,7 +285,8 @@ impl ClangSubItemParser for Var { // TODO(emilio): do we have to special-case constant arrays in // some other places? let is_const = ty.is_const() || - (ty.kind() == CXType_ConstantArray && + ([CXType_ConstantArray, CXType_IncompleteArray] + .contains(&ty.kind()) && ty.elem_type() .map_or(false, |element| element.is_const())); From 6f6f9fb402846e94662a6cfaa9f2e322beb5f1a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 16 Oct 2022 20:45:38 +0200 Subject: [PATCH 381/942] Move the csmith-fuzzing directory to the top level. --- {bindgen/csmith-fuzzing => csmith-fuzzing}/README.md | 0 {bindgen/csmith-fuzzing => csmith-fuzzing}/csmith.h | 0 {bindgen/csmith-fuzzing => csmith-fuzzing}/driver.py | 0 {bindgen/csmith-fuzzing => csmith-fuzzing}/predicate.py | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename {bindgen/csmith-fuzzing => csmith-fuzzing}/README.md (100%) rename {bindgen/csmith-fuzzing => csmith-fuzzing}/csmith.h (100%) rename {bindgen/csmith-fuzzing => csmith-fuzzing}/driver.py (100%) rename {bindgen/csmith-fuzzing => csmith-fuzzing}/predicate.py (100%) diff --git a/bindgen/csmith-fuzzing/README.md b/csmith-fuzzing/README.md similarity index 100% rename from bindgen/csmith-fuzzing/README.md rename to csmith-fuzzing/README.md diff --git a/bindgen/csmith-fuzzing/csmith.h b/csmith-fuzzing/csmith.h similarity index 100% rename from bindgen/csmith-fuzzing/csmith.h rename to csmith-fuzzing/csmith.h diff --git a/bindgen/csmith-fuzzing/driver.py b/csmith-fuzzing/driver.py similarity index 100% rename from bindgen/csmith-fuzzing/driver.py rename to csmith-fuzzing/driver.py diff --git a/bindgen/csmith-fuzzing/predicate.py b/csmith-fuzzing/predicate.py similarity index 100% rename from bindgen/csmith-fuzzing/predicate.py rename to csmith-fuzzing/predicate.py From 2c01810c3af78c087d99fdf484d879f5f8d7f2cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 16 Oct 2022 20:47:06 +0200 Subject: [PATCH 382/942] Remove no-longer-correct include entry in Cargo.toml. --- bindgen-cli/Cargo.toml | 5 ----- bindgen-tests/Cargo.toml | 5 ----- bindgen/Cargo.toml | 10 ---------- 3 files changed, 20 deletions(-) diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index 3ebf4a3f77..4e9d679842 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -16,11 +16,6 @@ edition = "2018" # If you change this, also update README.md and msrv in .github/workflows/bindgen.yml rust-version = "1.57.0" -include = [ - "Cargo.toml", - "build.rs", -] - [[bin]] path = "main.rs" name = "bindgen" diff --git a/bindgen-tests/Cargo.toml b/bindgen-tests/Cargo.toml index 53dfca15bf..a9b258b98c 100644 --- a/bindgen-tests/Cargo.toml +++ b/bindgen-tests/Cargo.toml @@ -4,11 +4,6 @@ edition = "2018" version = "0.1.0" publish = false -include = [ - "Cargo.toml", - "build.rs", -] - [dev-dependencies] bindgen = { path = "../bindgen" } diff = "0.1" diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index 3965ad4d4c..e2280389c9 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -20,16 +20,6 @@ build = "build.rs" # If you change this, also update README.md and msrv in .github/workflows/bindgen.yml rust-version = "1.57.0" -include = [ - "LICENSE", - "README.md", - "Cargo.toml", - "build.rs", - "src/*.rs", - "src/**/*.rs", -] - - [lib] name = "bindgen" path = "./lib.rs" From c424e034155660348ed77cfa92ec9869f617a625 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 16 Oct 2022 20:52:42 +0200 Subject: [PATCH 383/942] Add a few missing changelog entries. --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b221e6d22..29e7537a8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -181,6 +181,9 @@ ## Fixed + * Const correctness of incomplete arrays has been fixed. (#2301) + * C++ inline namespaces don't panic. (#2294) + ## Security [(#1743)]: https://github.com/rust-lang/rust-bindgen/issues/1743 From 142f62abdf452d4d6a8cb00215ec465af80434ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 16 Oct 2022 20:59:57 +0200 Subject: [PATCH 384/942] ci: clippy fixes. The allowed casts are because c_longlong etc aren't guaranteed to map to i64 / etc. I believe c_double maps to f64 in all platforms tho. --- .github/workflows/bindgen.yml | 2 +- bindgen/clang.rs | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 94a338bff4..bc8477d503 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -9,7 +9,7 @@ on: - master jobs: - rustfmt: + rustfmt-clippy: runs-on: ubuntu-latest steps: diff --git a/bindgen/clang.rs b/bindgen/clang.rs index e511339186..ae140520bd 100644 --- a/bindgen/clang.rs +++ b/bindgen/clang.rs @@ -652,6 +652,7 @@ impl Cursor { pub fn enum_val_signed(&self) -> Option { unsafe { if self.kind() == CXCursor_EnumConstantDecl { + #[allow(clippy::unnecessary_cast)] Some(clang_getEnumConstantDeclValue(self.x) as i64) } else { None @@ -665,6 +666,7 @@ impl Cursor { pub fn enum_val_unsigned(&self) -> Option { unsafe { if self.kind() == CXCursor_EnumConstantDecl { + #[allow(clippy::unnecessary_cast)] Some(clang_getEnumConstantDeclUnsignedValue(self.x) as u64) } else { None @@ -2134,7 +2136,7 @@ impl EvalResult { pub fn as_double(&self) -> Option { match self.kind() { CXEval_Float => { - Some(unsafe { clang_EvalResult_getAsDouble(self.x) } as f64) + Some(unsafe { clang_EvalResult_getAsDouble(self.x) }) } _ => None, } @@ -2162,6 +2164,7 @@ impl EvalResult { if value < i64::min_value() as c_longlong { return None; } + #[allow(clippy::unnecessary_cast)] Some(value as i64) } From 4f9b970f959aecb41804fb0e898156acf5d13569 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 16 Oct 2022 21:33:39 +0200 Subject: [PATCH 385/942] v0.61.0 --- CHANGELOG.md | 164 ++++++++++++++++++++++------------------- Cargo.lock | 4 +- bindgen-cli/Cargo.toml | 2 +- bindgen/Cargo.toml | 2 +- 4 files changed, 94 insertions(+), 78 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 29e7537a8b..d9c5aca4a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,133 +7,139 @@ - [Removed](#removed) - [Fixed](#fixed) - [Security](#security) -- [0.60.0](#0600) +- [0.61.0](#0610) - [Added](#added-1) - - [Fixed](#fixed-1) - [Changed](#changed-1) - - [Removed](#removed-1) -- [0.59.2](#0592) -- [0.59.1](#0591) + - [Fixed](#fixed-1) +- [0.60.1](#0601) - [Fixed](#fixed-2) -- [0.59.0](#0590) +- [0.60.0](#0600) - [Added](#added-2) - [Fixed](#fixed-3) - [Changed](#changed-2) -- [0.58.1](#0581) - - [Added](#added-3) -- [0.58.0](#0580) - - [Added](#added-4) + - [Removed](#removed-1) +- [0.59.2](#0592) +- [0.59.1](#0591) - [Fixed](#fixed-4) +- [0.59.0](#0590) + - [Added](#added-3) + - [Fixed](#fixed-5) - [Changed](#changed-3) +- [0.58.1](#0581) + - [Added](#added-4) +- [0.58.0](#0580) + - [Added](#added-5) + - [Fixed](#fixed-6) + - [Changed](#changed-4) - [Deprecated](#deprecated) - [Removed](#removed-2) - - [Fixed](#fixed-5) + - [Fixed](#fixed-7) - [Security](#security-1) - [0.57.0](#0570) - - [Added](#added-5) - - [Fixed](#fixed-6) -- [0.56.0](#0560) - [Added](#added-6) - - [Changed](#changed-4) - - [Fixed](#fixed-7) -- [0.55.1](#0551) - [Fixed](#fixed-8) -- [0.55.0](#0550) - - [Removed](#removed-3) +- [0.56.0](#0560) - [Added](#added-7) - [Changed](#changed-5) - [Fixed](#fixed-9) -- [0.54.1](#0541) +- [0.55.1](#0551) + - [Fixed](#fixed-10) +- [0.55.0](#0550) + - [Removed](#removed-3) - [Added](#added-8) - [Changed](#changed-6) - - [Fixed](#fixed-10) -- [0.54.0](#0540) + - [Fixed](#fixed-11) +- [0.54.1](#0541) - [Added](#added-9) - [Changed](#changed-7) - - [Fixed](#fixed-11) -- [0.53.3](#0533) - - [Added](#added-10) - [Fixed](#fixed-12) -- [0.53.2](#0532) +- [0.54.0](#0540) + - [Added](#added-10) - [Changed](#changed-8) -- [0.53.1](#0531) + - [Fixed](#fixed-13) +- [0.53.3](#0533) - [Added](#added-11) -- [0.53.0](#0530) - - [Added](#added-12) + - [Fixed](#fixed-14) +- [0.53.2](#0532) - [Changed](#changed-9) - - [Fixed](#fixed-13) -- [0.52.0](#0520) +- [0.53.1](#0531) + - [Added](#added-12) +- [0.53.0](#0530) - [Added](#added-13) - [Changed](#changed-10) - - [Fixed](#fixed-14) -- [0.51.1](#0511) - [Fixed](#fixed-15) +- [0.52.0](#0520) + - [Added](#added-14) - [Changed](#changed-11) -- [0.51.0](#0510) - [Fixed](#fixed-16) +- [0.51.1](#0511) + - [Fixed](#fixed-17) - [Changed](#changed-12) - - [Added](#added-14) -- [0.50.0](#0500) +- [0.51.0](#0510) + - [Fixed](#fixed-18) + - [Changed](#changed-13) - [Added](#added-15) -- [0.49.3](#0493) +- [0.50.0](#0500) - [Added](#added-16) +- [0.49.3](#0493) + - [Added](#added-17) - [0.49.2](#0492) - - [Changed](#changed-13) -- [0.49.1](#0491) - - [Fixed](#fixed-17) - [Changed](#changed-14) -- [0.49.0](#0490) - - [Added](#added-17) - - [Fixed](#fixed-18) +- [0.49.1](#0491) + - [Fixed](#fixed-19) - [Changed](#changed-15) +- [0.49.0](#0490) + - [Added](#added-18) + - [Fixed](#fixed-20) + - [Changed](#changed-16) - [0.48.1](#0481) - - [Fixed](#fixed-19) + - [Fixed](#fixed-21) - [0.48.0](#0480) - - [Changed](#changed-16) - - [Fixed](#fixed-20) + - [Changed](#changed-17) + - [Fixed](#fixed-22) - [0.47.4](#0474) - - [Added](#added-18) + - [Added](#added-19) - [0.47.3](#0473) - - [Changed](#changed-17) + - [Changed](#changed-18) - [0.47.2](#0472) - - [Fixed](#fixed-21) + - [Fixed](#fixed-23) - [0.47.1](#0471) - - [Changed](#changed-18) - - [Fixed](#fixed-22) -- [0.47.0](#0470) - [Changed](#changed-19) - - [Fixed](#fixed-23) + - [Fixed](#fixed-24) +- [0.47.0](#0470) + - [Changed](#changed-20) + - [Fixed](#fixed-25) - [0.33.1 .. 0.46.0](#0331--0460) - - [Added](#added-19) + - [Added](#added-20) - [Removed](#removed-4) - - [Changed](#changed-20) - - [Fixed](#fixed-24) + - [Changed](#changed-21) + - [Fixed](#fixed-26) - [0.33.1](#0331) - - [Fixed](#fixed-25) + - [Fixed](#fixed-27) - [0.33.0](#0330) - [0.32.2](#0322) - - [Fixed](#fixed-26) + - [Fixed](#fixed-28) - [0.32.1](#0321) - - [Fixed](#fixed-27) + - [Fixed](#fixed-29) - [0.32.0](#0320) - - [Added](#added-20) - - [Changed](#changed-21) - - [Fixed](#fixed-28) -- [0.31.0](#0310) - [Added](#added-21) - [Changed](#changed-22) + - [Fixed](#fixed-30) +- [0.31.0](#0310) + - [Added](#added-22) + - [Changed](#changed-23) - [Deprecated](#deprecated-1) - [Removed](#removed-5) - - [Fixed](#fixed-29) + - [Fixed](#fixed-31) - [0.30.0](#0300) - - [Added](#added-22) - - [Changed](#changed-23) - - [Deprecated](#deprecated-2) - - [Fixed](#fixed-30) -- [0.29.0](#0290) - [Added](#added-23) - [Changed](#changed-24) - - [Fixed](#fixed-31) + - [Deprecated](#deprecated-2) + - [Fixed](#fixed-32) +- [0.29.0](#0290) + - [Added](#added-24) + - [Changed](#changed-25) + - [Fixed](#fixed-33) @@ -141,6 +147,20 @@ # Unreleased +## Added + +## Changed + +## Removed + +## Fixed + +## Security + +# 0.61.0 + +Released 2022/10/16 + ## Added * new feature: `--sort-semantically` flag to sort the output in a predefined @@ -177,15 +197,11 @@ * Using `bindgen` as a library no longer pulls clap and any other CLI related dependencies. -## Removed - ## Fixed * Const correctness of incomplete arrays has been fixed. (#2301) * C++ inline namespaces don't panic. (#2294) -## Security - [(#1743)]: https://github.com/rust-lang/rust-bindgen/issues/1743 # 0.60.1 diff --git a/Cargo.lock b/Cargo.lock index b9deb405ee..765f391fd2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -48,7 +48,7 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bindgen" -version = "0.60.1" +version = "0.61.0" dependencies = [ "bitflags", "cexpr", @@ -68,7 +68,7 @@ dependencies = [ [[package]] name = "bindgen-cli" -version = "0.60.1" +version = "0.61.0" dependencies = [ "bindgen", "clap 3.2.12", diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index 4e9d679842..b7509ae2a9 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -11,7 +11,7 @@ readme = "README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.60.1" +version = "0.61.0" edition = "2018" # If you change this, also update README.md and msrv in .github/workflows/bindgen.yml rust-version = "1.57.0" diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index e2280389c9..9956c441df 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -14,7 +14,7 @@ readme = "README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.60.1" +version = "0.61.0" edition = "2018" build = "build.rs" # If you change this, also update README.md and msrv in .github/workflows/bindgen.yml From 66388deae3b363cebc07d3e0b5570565bc5bb482 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 16 Oct 2022 21:53:39 +0200 Subject: [PATCH 386/942] Specify readme properly. --- bindgen-cli/Cargo.toml | 2 +- bindgen/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index b7509ae2a9..4233490bea 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -7,7 +7,7 @@ keywords = ["bindings", "ffi", "code-generation"] categories = ["external-ffi-bindings", "development-tools::ffi"] license = "BSD-3-Clause" name = "bindgen-cli" -readme = "README.md" +readme = "../README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index 9956c441df..e47642f975 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -10,7 +10,7 @@ keywords = ["bindings", "ffi", "code-generation"] categories = ["external-ffi-bindings", "development-tools::ffi"] license = "BSD-3-Clause" name = "bindgen" -readme = "README.md" +readme = "../README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" From c1d1f1b694952cd91dc4e24614d65e70e2dadf84 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Tue, 18 Oct 2022 12:05:27 -0500 Subject: [PATCH 387/942] fix clippy lints --- bindgen-tests/tests/expectations/build.rs | 5 +- .../tests/quickchecking/src/fuzzers.rs | 11 ++--- bindgen-tests/tests/quickchecking/src/lib.rs | 46 ++++++++----------- .../quickchecking/tests/fuzzed-c-headers.rs | 28 +++++------ 4 files changed, 38 insertions(+), 52 deletions(-) diff --git a/bindgen-tests/tests/expectations/build.rs b/bindgen-tests/tests/expectations/build.rs index edbcafb9e7..2111185384 100644 --- a/bindgen-tests/tests/expectations/build.rs +++ b/bindgen-tests/tests/expectations/build.rs @@ -8,8 +8,7 @@ use std::fs; use std::io::Write; use std::path::Path; -const LIBCLANG_VERSION_DIRS: &'static [&'static str] = - &["libclang-5", "libclang-9"]; +const LIBCLANG_VERSION_DIRS: &[&str] = &["libclang-5", "libclang-9"]; fn main() { println!("cargo:rerun-if-changed=build.rs"); @@ -26,7 +25,7 @@ fn main() { for entry in fs::read_dir(dir).unwrap() { let entry = entry.unwrap(); let path = entry.path(); - let path = path.canonicalize().unwrap_or_else(|_| path.into()); + let path = path.canonicalize().unwrap_or(path); if path.extension().map(|e| e.to_string_lossy()) != Some("rs".into()) { diff --git a/bindgen-tests/tests/quickchecking/src/fuzzers.rs b/bindgen-tests/tests/quickchecking/src/fuzzers.rs index b609dd5abc..4188f8f557 100644 --- a/bindgen-tests/tests/quickchecking/src/fuzzers.rs +++ b/bindgen-tests/tests/quickchecking/src/fuzzers.rs @@ -327,12 +327,7 @@ impl Arbitrary for ArrayDimensionC { let dimensions = g.gen_range(0, 5); let mut def = String::new(); - let lower_bound; - if cfg!(feature = "zero-sized-arrays") { - lower_bound = 0; - } else { - lower_bound = 1; - } + let lower_bound = i32::from(cfg!(feature = "zero-sized-arrays")); for _ in 1..dimensions { // 16 is an arbitrary "not too big" number for capping array size. @@ -400,7 +395,7 @@ impl Arbitrary for StructDeclarationC { fn arbitrary(g: &mut G) -> StructDeclarationC { // Reduce generator size as a method of putting a bound on recursion. // When size < 1 the empty list is generated. - let reduced_size: usize = (g.size() / 2) as usize + 1; + let reduced_size: usize = (g.size() / 2) + 1; let mut decl_list: DeclarationListC = Arbitrary::arbitrary(&mut StdGen::new(thread_rng(), reduced_size)); let mut fields: DeclarationListC = DeclarationListC { decls: vec![] }; @@ -448,7 +443,7 @@ impl Arbitrary for UnionDeclarationC { fn arbitrary(g: &mut G) -> UnionDeclarationC { // Reduce generator size as a method of putting a bound on recursion. // When size < 1 the empty list is generated. - let reduced_size: usize = (g.size() / 2) as usize + 1; + let reduced_size: usize = (g.size() / 2) + 1; let mut decl_list: DeclarationListC = Arbitrary::arbitrary(&mut StdGen::new(thread_rng(), reduced_size)); let mut fields: DeclarationListC = DeclarationListC { decls: vec![] }; diff --git a/bindgen-tests/tests/quickchecking/src/lib.rs b/bindgen-tests/tests/quickchecking/src/lib.rs index b09d1c4922..75bfc2376b 100644 --- a/bindgen-tests/tests/quickchecking/src/lib.rs +++ b/bindgen-tests/tests/quickchecking/src/lib.rs @@ -63,32 +63,27 @@ fn run_predicate_script( header_file.write_all(header.to_string().as_bytes())?; header_file.sync_all()?; - let header_path_string; - match header_path.into_os_string().into_string() { - Ok(s) => header_path_string = s, - Err(_) => return Err(From::from("error converting path into String")), - } + let header_path_string = header_path + .into_os_string() + .into_string() + .map_err(|_| "error converting path into String")?; let mut predicate_script_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); predicate_script_path.push("../../csmith-fuzzing/predicate.py"); - let predicate_script_path_string; - match predicate_script_path.into_os_string().into_string() { - Ok(s) => predicate_script_path_string = s, - Err(_) => return Err(From::from("error converting path into String")), - } + let predicate_script_path_string = predicate_script_path + .into_os_string() + .into_string() + .map_err(|_| "error converting path into String")?; // Copy generated temp files to output_path directory for inspection. // If `None`, output path not specified, don't copy. - match CONTEXT.lock().unwrap().output_path { - Some(ref path) => { - Command::new("cp") - .arg("-a") - .arg(&dir.path().to_str().unwrap()) - .arg(&path) - .output()?; - } - None => {} + if let Some(ref path) = CONTEXT.lock().unwrap().output_path { + Command::new("cp") + .arg("-a") + .arg(dir.path().to_str().unwrap()) + .arg(path) + .output()?; } Ok(Command::new(&predicate_script_path_string) @@ -101,10 +96,10 @@ fn run_predicate_script( // status of that command. fn bindgen_prop(header: fuzzers::HeaderC) -> TestResult { match run_predicate_script(header) { - Ok(o) => return TestResult::from_bool(o.status.success()), + Ok(o) => TestResult::from_bool(o.status.success()), Err(e) => { println!("{:?}", e); - return TestResult::from_bool(false); + TestResult::from_bool(false) } } } @@ -118,12 +113,9 @@ pub fn test_bindgen( tests: usize, output_path: Option<&str>, ) { - match output_path { - Some(path) => { - CONTEXT.lock().unwrap().output_path = - Some(String::from(PathBuf::from(path).to_str().unwrap())); - } - None => {} // Path not specified, don't provide output. + if let Some(path) = output_path { + CONTEXT.lock().unwrap().output_path = + Some(String::from(PathBuf::from(path).to_str().unwrap())); } QuickCheck::new() diff --git a/bindgen-tests/tests/quickchecking/tests/fuzzed-c-headers.rs b/bindgen-tests/tests/quickchecking/tests/fuzzed-c-headers.rs index 800c70b43f..0d43f30050 100644 --- a/bindgen-tests/tests/quickchecking/tests/fuzzed-c-headers.rs +++ b/bindgen-tests/tests/quickchecking/tests/fuzzed-c-headers.rs @@ -13,84 +13,84 @@ use rand::thread_rng; #[test] fn test_declaraion_c_does_not_panic() { - let ref mut gen = StdGen::new(thread_rng(), 50); + let gen = &mut StdGen::new(thread_rng(), 50); let _: DeclarationC = Arbitrary::arbitrary(gen); } #[test] fn test_declaraion_list_c_does_not_panic() { - let ref mut gen = StdGen::new(thread_rng(), 50); + let gen = &mut StdGen::new(thread_rng(), 50); let _: DeclarationListC = Arbitrary::arbitrary(gen); } #[test] fn test_base_type_c_does_not_panic() { - let ref mut gen = StdGen::new(thread_rng(), 50); + let gen = &mut StdGen::new(thread_rng(), 50); let _: BaseTypeC = Arbitrary::arbitrary(gen); } #[test] fn test_type_qualifier_c_does_not_panic() { - let ref mut gen = StdGen::new(thread_rng(), 50); + let gen = &mut StdGen::new(thread_rng(), 50); let _: TypeQualifierC = Arbitrary::arbitrary(gen); } #[test] fn test_pointer_level_c_does_not_panic() { - let ref mut gen = StdGen::new(thread_rng(), 50); + let gen = &mut StdGen::new(thread_rng(), 50); let _: PointerLevelC = Arbitrary::arbitrary(gen); } #[test] fn test_array_dimension_c_does_not_panic() { - let ref mut gen = StdGen::new(thread_rng(), 50); + let gen = &mut StdGen::new(thread_rng(), 50); let _: ArrayDimensionC = Arbitrary::arbitrary(gen); } #[test] fn test_basic_type_declaration_c_does_not_panic() { - let ref mut gen = StdGen::new(thread_rng(), 50); + let gen = &mut StdGen::new(thread_rng(), 50); let _: BasicTypeDeclarationC = Arbitrary::arbitrary(gen); } #[test] fn test_struct_declaration_c_does_not_panic() { - let ref mut gen = StdGen::new(thread_rng(), 50); + let gen = &mut StdGen::new(thread_rng(), 50); let _: StructDeclarationC = Arbitrary::arbitrary(gen); } #[test] fn test_union_declaration_c_does_not_panic() { - let ref mut gen = StdGen::new(thread_rng(), 50); + let gen = &mut StdGen::new(thread_rng(), 50); let _: UnionDeclarationC = Arbitrary::arbitrary(gen); } #[test] fn test_function_pointer_declaration_c_does_not_panic() { - let ref mut gen = StdGen::new(thread_rng(), 50); + let gen = &mut StdGen::new(thread_rng(), 50); let _: FunctionPointerDeclarationC = Arbitrary::arbitrary(gen); } #[test] fn test_function_prototype_c_does_not_panic() { - let ref mut gen = StdGen::new(thread_rng(), 50); + let gen = &mut StdGen::new(thread_rng(), 50); let _: FunctionPrototypeC = Arbitrary::arbitrary(gen); } #[test] fn test_parameter_c_does_not_panic() { - let ref mut gen = StdGen::new(thread_rng(), 50); + let gen = &mut StdGen::new(thread_rng(), 50); let _: ParameterC = Arbitrary::arbitrary(gen); } #[test] fn test_parameter_list_c_does_not_panic() { - let ref mut gen = StdGen::new(thread_rng(), 50); + let gen = &mut StdGen::new(thread_rng(), 50); let _: ParameterListC = Arbitrary::arbitrary(gen); } #[test] fn test_header_c_does_not_panic() { - let ref mut gen = StdGen::new(thread_rng(), 50); + let gen = &mut StdGen::new(thread_rng(), 50); let _: HeaderC = Arbitrary::arbitrary(gen); } From c2d6f43a23f04729853c6191dfd7b12065a1c750 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Thu, 20 Oct 2022 12:11:56 -0500 Subject: [PATCH 388/942] add FAQ about custom targets --- book/src/faq.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/book/src/faq.md b/book/src/faq.md index 7a13afb4cd..767cd6e24c 100644 --- a/book/src/faq.md +++ b/book/src/faq.md @@ -7,6 +7,7 @@ - [Why isn't `bindgen` generating bindings to inline functions?](#why-isnt-bindgen-generating-bindings-to-inline-functions) - [Does `bindgen` support the C++ Standard Template Library (STL)?](#does-bindgen-support-the-c-standard-template-library-stl) - [How to deal with bindgen generated padding fields?](#how-to-deal-with-bindgen-generated-padding-fields) +- [How to generate bindings for a custom target?](#how-to-generate-bindings-for-a-custom-target) @@ -68,7 +69,7 @@ you're binding to that is pulling in STL headers. ### How to deal with bindgen generated padding fields? Depending the architecture, toolchain versions and source struct, it is -possible that bindgen will generate padding fields named `__bindgen_padding_N`. +possible that bindgen will generate padding fields named `__bindgen_padding_N`. As these fields might be present when compiling for one architecture but not for an other, you should not initialize these fields manually when initializing the struct. Instead, use the `Default` trait. You can either enable this when @@ -95,3 +96,15 @@ SRC_DATA { In the case bindgen generates a padding field, then this field will be automatically initialized by `..Default::default()`. + +### How to generate bindings for a custom target? + +To generate bindings for a custom target you only need to pass the `--target` +argument to `libclang`. For example, if you want to generate bindings for the +`armv7a-none-eabi` target using the command line, you need to invoke `bindgen` +like so: +```bash +$ bindgen -- --target=armv7a-none-eabi +``` +If you are using `bindgen` as a library, you should call +`builder.clang_arg("--target=armv7a-none-eabi")` on your `builder`. From 0142c0aaf72a3859e319640224740965c2ddeab3 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Fri, 21 Oct 2022 13:02:54 -0500 Subject: [PATCH 389/942] Use panic hooks instead of using `catch_unwind` One of the advantages of doing this is that `ParseCallbacks` no longer needs to implement `UnwindSafe` which means that users can rely on `RefCell` and `Cell` to extract information from the callbacks. Users relying on `catch_unwind` can still achieve similar behavior using `std::thread::spawn`. Fixes #2147. --- bindgen-cli/main.rs | 17 ++++++++--------- bindgen/callbacks.rs | 3 +-- bindgen/lib.rs | 5 ----- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/bindgen-cli/main.rs b/bindgen-cli/main.rs index a61f67ad51..fed454afca 100644 --- a/bindgen-cli/main.rs +++ b/bindgen-cli/main.rs @@ -6,7 +6,6 @@ extern crate env_logger; extern crate log; use std::env; -use std::panic; mod options; use crate::options::builder_from_flags; @@ -41,18 +40,18 @@ pub fn main() { Ok((builder, output, verbose)) => { #[cfg(feature = "logging")] clang_version_check(); - let builder_result = panic::catch_unwind(|| { - builder.generate().expect("Unable to generate bindings") - }); - if builder_result.is_err() { + std::panic::set_hook(Box::new(move |_info| { if verbose { - print_verbose_err(); + print_verbose_err() } - std::process::exit(1); - } + })); + + let bindings = + builder.generate().expect("Unable to generate bindings"); + + let _ = std::panic::take_hook(); - let bindings = builder_result.unwrap(); bindings.write(output).expect("Unable to write output"); } Err(error) => { diff --git a/bindgen/callbacks.rs b/bindgen/callbacks.rs index d0eb466734..fb84c8c331 100644 --- a/bindgen/callbacks.rs +++ b/bindgen/callbacks.rs @@ -5,7 +5,6 @@ pub use crate::ir::derive::CanDerive as ImplementsTrait; pub use crate::ir::enum_ty::{EnumVariantCustomBehavior, EnumVariantValue}; pub use crate::ir::int::IntKind; use std::fmt; -use std::panic::UnwindSafe; /// An enum to allow ignoring parsing of macros. #[derive(Copy, Clone, Debug, PartialEq, Eq)] @@ -25,7 +24,7 @@ impl Default for MacroParsingBehavior { /// A trait to allow configuring different kinds of types in different /// situations. -pub trait ParseCallbacks: fmt::Debug + UnwindSafe { +pub trait ParseCallbacks: fmt::Debug { /// This function will be run on every macro that is identified. fn will_parse_macro(&self, _name: &str) -> MacroParsingBehavior { MacroParsingBehavior::Default diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 880d52a9ee..22ce603c4d 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -2103,11 +2103,6 @@ struct BindgenOptions { merge_extern_blocks: bool, } -/// TODO(emilio): This is sort of a lie (see the error message that results from -/// removing this), but since we don't share references across panic boundaries -/// it's ok. -impl ::std::panic::UnwindSafe for BindgenOptions {} - impl BindgenOptions { fn build(&mut self) { let mut regex_sets = [ From 80738016a36e803fe3bf8b8f6f388c6589d86a1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 18 Oct 2022 02:17:18 +0200 Subject: [PATCH 390/942] clang: Detect anonymous items explicitly, rather than relying on empty names. In Clang 16, anonymous items may return names like `(anonymous union at ..)` rather than empty names. The right way to detect them is using clang_Cursor_isAnonymous. Fixes #2312 Closes #2316 Co-Authored-by: Patrick Walton --- bindgen/clang.rs | 5 +++++ bindgen/ir/comp.rs | 3 +-- bindgen/ir/ty.rs | 27 +++++++++++++++++---------- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/bindgen/clang.rs b/bindgen/clang.rs index ae140520bd..32a25449bc 100644 --- a/bindgen/clang.rs +++ b/bindgen/clang.rs @@ -86,6 +86,11 @@ impl Cursor { unsafe { clang_isDeclaration(self.kind()) != 0 } } + /// Is this cursor's referent an anonymous record or so? + pub fn is_anonymous(&self) -> bool { + unsafe { clang_Cursor_isAnonymous(self.x) != 0 } + } + /// Get this cursor's referent's spelling. pub fn spelling(&self) -> String { unsafe { cxstring_into_string(clang_getCursorSpelling(self.x)) } diff --git a/bindgen/ir/comp.rs b/bindgen/ir/comp.rs index f44c5d6725..039742a48d 100644 --- a/bindgen/ir/comp.rs +++ b/bindgen/ir/comp.rs @@ -1422,8 +1422,7 @@ impl CompInfo { // A declaration of an union or a struct without name // could also be an unnamed field, unfortunately. - if cur.spelling().is_empty() && - cur.kind() != CXCursor_EnumDecl + if cur.is_anonymous() && cur.kind() != CXCursor_EnumDecl { let ty = cur.cur_type(); let public = cur.public_accessible(); diff --git a/bindgen/ir/ty.rs b/bindgen/ir/ty.rs index 6a3fd0e8c8..9edc43d419 100644 --- a/bindgen/ir/ty.rs +++ b/bindgen/ir/ty.rs @@ -698,7 +698,12 @@ impl Type { let layout = ty.fallible_layout(ctx).ok(); let cursor = ty.declaration(); - let mut name = cursor.spelling(); + let is_anonymous = cursor.is_anonymous(); + let mut name = if is_anonymous { + None + } else { + Some(cursor.spelling()).filter(|n| !n.is_empty()) + }; debug!( "from_clang_ty: {:?}, ty: {:?}, loc: {:?}", @@ -732,7 +737,7 @@ impl Type { if is_canonical_objcpointer && is_template_type_param { // Objective-C generics are just ids with fancy name. // To keep it simple, just name them ids - name = "id".to_owned(); + name = Some("id".to_owned()); } } @@ -861,7 +866,7 @@ impl Type { return Err(ParseError::Recurse); } } else { - name = location.spelling(); + name = Some(location.spelling()); } let complex = CompInfo::from_ty( @@ -903,7 +908,7 @@ impl Type { CXType_Typedef ); - name = current.spelling(); + name = Some(location.spelling()); let inner_ty = cur .typedef_type() @@ -1105,10 +1110,10 @@ impl Type { CXType_Enum => { let enum_ = Enum::from_ty(ty, ctx).expect("Not an enum?"); - if name.is_empty() { + if !is_anonymous { let pretty_name = ty.spelling(); if clang::is_valid_identifier(&pretty_name) { - name = pretty_name; + name = Some(pretty_name); } } @@ -1123,12 +1128,12 @@ impl Type { ) .expect("Not a complex type?"); - if name.is_empty() { + if !is_anonymous { // The pretty-printed name may contain typedefed name, // but may also be "struct (anonymous at .h:1)" let pretty_name = ty.spelling(); if clang::is_valid_identifier(&pretty_name) { - name = pretty_name; + name = Some(pretty_name); } } @@ -1168,7 +1173,9 @@ impl Type { CXType_ObjCClass | CXType_ObjCInterface => { let interface = ObjCInterface::from_ty(&location, ctx) .expect("Not a valid objc interface?"); - name = interface.rust_name(); + if !is_anonymous { + name = Some(interface.rust_name()); + } TypeKind::ObjCInterface(interface) } CXType_Dependent => { @@ -1186,7 +1193,7 @@ impl Type { } }; - let name = if name.is_empty() { None } else { Some(name) }; + name = name.filter(|n| !n.is_empty()); let is_const = ty.is_const() || (ty.kind() == CXType_ConstantArray && From 3994a3315e268ee509f7d0e74b3818540cc97d3c Mon Sep 17 00:00:00 2001 From: Darren Kulp Date: Sat, 22 Oct 2022 11:11:39 -0400 Subject: [PATCH 391/942] Remove Travis-CI badges Travis-CI was fully removed as of faf8b3edbaeb591315fc6f370c1228b8caf9860f. The only badge now [mentioned in the Cargo book][1] is `maintenance`. The `travis-ci` badge reference was [removed from Cargo two years ago][2]. The Cargo book advises putting badges in README.md instead. [1]: https://doc.rust-lang.org/cargo/reference/manifest.html#the-badges-section [2]: https://github.com/rust-lang/cargo/commit/60779a006f98fba1680182c174134363d08e0a9b --- bindgen-cli/Cargo.toml | 3 --- bindgen/Cargo.toml | 3 --- 2 files changed, 6 deletions(-) diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index 4233490bea..b4feb6d9ce 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -20,9 +20,6 @@ rust-version = "1.57.0" path = "main.rs" name = "bindgen" -[badges] -travis-ci = { repository = "rust-lang/rust-bindgen" } - [dependencies] bindgen = { path = "../bindgen" } shlex = "1" diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index e47642f975..5a8e96be8c 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -24,9 +24,6 @@ rust-version = "1.57.0" name = "bindgen" path = "./lib.rs" -[badges] -travis-ci = { repository = "rust-lang/rust-bindgen" } - [dependencies] bitflags = "1.0.3" cexpr = "0.6" From caffa9b7ab70220ccb3792bad69ee039ffbe12dc Mon Sep 17 00:00:00 2001 From: George Bateman Date: Sun, 23 Oct 2022 00:04:31 +0100 Subject: [PATCH 392/942] Document visibility annotation --- book/src/SUMMARY.md | 1 + book/src/visibility.md | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 book/src/visibility.md diff --git a/book/src/SUMMARY.md b/book/src/SUMMARY.md index f9cc869f12..e7feff9523 100644 --- a/book/src/SUMMARY.md +++ b/book/src/SUMMARY.md @@ -20,6 +20,7 @@ - [Preventing the Derivation of `Debug`](./nodebug.md) - [Preventing the Derivation of `Default`](./nodefault.md) - [Annotating types with `#[must-use]`](./must-use-types.md) + - [Field visibility](./visibility.md) - [Generating Bindings to C++](./cpp.md) - [Generating Bindings to Objective-c](./objc.md) - [Using Unions](./using-unions.md) diff --git a/book/src/visibility.md b/book/src/visibility.md new file mode 100644 index 0000000000..039018fcdf --- /dev/null +++ b/book/src/visibility.md @@ -0,0 +1,31 @@ +# Making fields private + +Fields can be made private for various reasons. You may wish to enforce some invariant on the fields of a structure, which cannot be achieved if the field is public and can be set by any code. For example, you may wish to ensure that a pointer always points to something appropriate. + +### Annotation + +```c +struct OneFieldPrivate { + /** Null-terminated, static string.
*/ + const char *s; + bool b; +}; + +/**
*/ +struct MostFieldsPrivate { + int a; + bool b; + /**
*/ + char c; +}; +``` + +Then in Rust: + +```rust +impl OneFieldPrivate { + pub fn new(s: &'static core::ffi::CStr, b: bool) -> Self { + OneFieldPrivate { s: s.as_ptr(), b } + } +} +``` From fc56c70500d8a6845ab2a7b886425905818a56b5 Mon Sep 17 00:00:00 2001 From: George Bateman Date: Sun, 23 Oct 2022 00:13:47 +0100 Subject: [PATCH 393/942] Make doctests pass --- book/src/visibility.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/book/src/visibility.md b/book/src/visibility.md index 039018fcdf..ac0aac15da 100644 --- a/book/src/visibility.md +++ b/book/src/visibility.md @@ -23,8 +23,14 @@ struct MostFieldsPrivate { Then in Rust: ```rust +# #[repr(C)] +# pub struct OneFieldPrivate { +# s: *const ::std::os::raw::c_char, +# pub b: bool, +# } + impl OneFieldPrivate { - pub fn new(s: &'static core::ffi::CStr, b: bool) -> Self { + pub fn new(s: &'static std::ffi::CStr, b: bool) -> Self { OneFieldPrivate { s: s.as_ptr(), b } } } From 6086694d40f8df09db79bc9a7b7eec29131f424a Mon Sep 17 00:00:00 2001 From: Adam Gausmann Date: Mon, 24 Oct 2022 10:39:52 -0500 Subject: [PATCH 394/942] Sanitize RegexSet input so alternation is properly handled (#1756) * tests: Avoid using globs as regexes * Sanitize regex set input to properly handle alternation * Add test case for alternates/anchors interaction * emit warning if wildcard pattern is used * update changelog and bump versions Co-authored-by: Darren Kulp Co-authored-by: Christian Poveda --- CHANGELOG.md | 3 ++ Cargo.lock | 4 +- bindgen-cli/Cargo.toml | 2 +- .../tests/whitelist-alternates.rs | 39 +++++++++++++++++++ bindgen-tests/tests/headers/empty-union.hpp | 2 +- .../tests/headers/forward_declared_opaque.h | 4 +- bindgen-tests/tests/headers/ord-enum.h | 4 +- .../tests/headers/whitelist-alternates.h | 8 ++++ bindgen/Cargo.toml | 2 +- bindgen/regex_set.rs | 8 +++- 10 files changed, 65 insertions(+), 11 deletions(-) create mode 100644 bindgen-tests/tests/expectations/tests/whitelist-alternates.rs create mode 100644 bindgen-tests/tests/headers/whitelist-alternates.h diff --git a/CHANGELOG.md b/CHANGELOG.md index d9c5aca4a4..87a74acd42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -151,6 +151,9 @@ ## Changed + * Regex inputs are sanitized so alternation (`a|b`) is handled correctly but + wildcard patterns (`*`) are now considered invalid. + ## Removed ## Fixed diff --git a/Cargo.lock b/Cargo.lock index 765f391fd2..d656f9dd32 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -48,7 +48,7 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bindgen" -version = "0.61.0" +version = "0.62.0" dependencies = [ "bitflags", "cexpr", @@ -68,7 +68,7 @@ dependencies = [ [[package]] name = "bindgen-cli" -version = "0.61.0" +version = "0.62.0" dependencies = [ "bindgen", "clap 3.2.12", diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index b4feb6d9ce..7bff8f46b8 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -11,7 +11,7 @@ readme = "../README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.61.0" +version = "0.62.0" edition = "2018" # If you change this, also update README.md and msrv in .github/workflows/bindgen.yml rust-version = "1.57.0" diff --git a/bindgen-tests/tests/expectations/tests/whitelist-alternates.rs b/bindgen-tests/tests/expectations/tests/whitelist-alternates.rs new file mode 100644 index 0000000000..77d963d81e --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/whitelist-alternates.rs @@ -0,0 +1,39 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct WhitelistedType {} +#[test] +fn bindgen_test_layout_WhitelistedType() { + assert_eq!( + ::std::mem::size_of::(), + 0usize, + concat!("Size of: ", stringify!(WhitelistedType)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(WhitelistedType)) + ); +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct AllowType {} +#[test] +fn bindgen_test_layout_AllowType() { + assert_eq!( + ::std::mem::size_of::(), + 0usize, + concat!("Size of: ", stringify!(AllowType)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(AllowType)) + ); +} diff --git a/bindgen-tests/tests/headers/empty-union.hpp b/bindgen-tests/tests/headers/empty-union.hpp index 3b067e39da..113a95ee30 100644 --- a/bindgen-tests/tests/headers/empty-union.hpp +++ b/bindgen-tests/tests/headers/empty-union.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --opaque-type "*" +// bindgen-flags: --opaque-type ".*" template class a { union {}; diff --git a/bindgen-tests/tests/headers/forward_declared_opaque.h b/bindgen-tests/tests/headers/forward_declared_opaque.h index 1b58edb9a8..69a12cc7e2 100644 --- a/bindgen-tests/tests/headers/forward_declared_opaque.h +++ b/bindgen-tests/tests/headers/forward_declared_opaque.h @@ -1,4 +1,4 @@ -// bindgen-flags: --opaque-type "*" +// bindgen-flags: --opaque-type ".*" union a; -struct b; \ No newline at end of file +struct b; diff --git a/bindgen-tests/tests/headers/ord-enum.h b/bindgen-tests/tests/headers/ord-enum.h index 364f711efa..b14e77c2f8 100644 --- a/bindgen-tests/tests/headers/ord-enum.h +++ b/bindgen-tests/tests/headers/ord-enum.h @@ -1,4 +1,4 @@ -// bindgen-flags: --rustified-enum * --with-derive-ord +// bindgen-flags: --rustified-enum ".*" --with-derive-ord enum A { A0 = 0, @@ -12,4 +12,4 @@ enum B { B1 = B0 + 3, B2 = B0 + 2, B3 = B0 - 2, -}; \ No newline at end of file +}; diff --git a/bindgen-tests/tests/headers/whitelist-alternates.h b/bindgen-tests/tests/headers/whitelist-alternates.h new file mode 100644 index 0000000000..7aa3bf8711 --- /dev/null +++ b/bindgen-tests/tests/headers/whitelist-alternates.h @@ -0,0 +1,8 @@ +// bindgen-flags: --whitelist-type 'Whitelisted.*|Allow.*' +// Test for changes introduced in #1756 + +struct WhitelistedType {}; +struct AllowType {}; +// this would have been accepted because the start anchor +// wouldn't be applied to the second alternative: +struct NoAllowType {}; diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index 5a8e96be8c..13e5f44590 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -14,7 +14,7 @@ readme = "../README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.61.0" +version = "0.62.0" edition = "2018" build = "build.rs" # If you change this, also update README.md and msrv in .github/workflows/bindgen.yml diff --git a/bindgen/regex_set.rs b/bindgen/regex_set.rs index 9262c4eeda..9f1e2251cd 100644 --- a/bindgen/regex_set.rs +++ b/bindgen/regex_set.rs @@ -26,7 +26,11 @@ impl RegexSet { where S: AsRef, { - self.items.push(string.as_ref().to_owned()); + let string = string.as_ref().to_owned(); + if string == "*" { + warn!("using wildcard patterns (`*`) is no longer considered valid. Use `.*` instead"); + } + self.items.push(string); self.matched.push(Cell::new(false)); self.set = None; } @@ -53,7 +57,7 @@ impl RegexSet { /// Must be called before calling `matches()`, or it will always return /// false. pub fn build(&mut self, record_matches: bool) { - let items = self.items.iter().map(|item| format!("^{}$", item)); + let items = self.items.iter().map(|item| format!("^({})$", item)); self.record_matches = record_matches; self.set = match RxSet::new(items) { Ok(x) => Some(x), From da548d20f482c09241a9dad08dd4c76dbb89ec8d Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Mon, 24 Oct 2022 11:52:46 -0500 Subject: [PATCH 395/942] Avoid suppressing panic messages (#2323) * print `PanicInfo` using hook * update changelog --- CHANGELOG.md | 1 + bindgen-cli/main.rs | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 87a74acd42..de08d829e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -153,6 +153,7 @@ * Regex inputs are sanitized so alternation (`a|b`) is handled correctly but wildcard patterns (`*`) are now considered invalid. + * the `ParseCallbacks`trait does not require to implement `UnwindSafe`. ## Removed diff --git a/bindgen-cli/main.rs b/bindgen-cli/main.rs index fed454afca..a3b3612694 100644 --- a/bindgen-cli/main.rs +++ b/bindgen-cli/main.rs @@ -41,10 +41,11 @@ pub fn main() { #[cfg(feature = "logging")] clang_version_check(); - std::panic::set_hook(Box::new(move |_info| { + std::panic::set_hook(Box::new(move |info| { if verbose { print_verbose_err() } + println!("{}", info); })); let bindings = From d86db07859025445230c8833e7a629792f5a2990 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Mon, 24 Oct 2022 15:31:02 -0500 Subject: [PATCH 396/942] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 9e2cf10bf6..c78f00dd44 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,8 @@ The minimum supported Rust version is **1.57.0**. No MSRV bump policy has been established yet, so MSRV may increase in any release. +The MSRV is the minimum Rust version that can be used to *compile* `bindgen`. However, `bindgen` can generate bindings that are compatible with Rust versions below the current MSRV. + ## API Reference [API reference documentation is on docs.rs](https://docs.rs/bindgen) From b3ac3efcf95220db6b32b63832bff15c5a482d97 Mon Sep 17 00:00:00 2001 From: Charlie Barto Date: Sun, 30 Oct 2022 15:51:09 -0700 Subject: [PATCH 397/942] Replace confusing note in cpp.md on "RVO" The original commit adding this note referenced #778, but then went on to talk about how the problem was RVO and that the problem is not possible to solve in bindgen because bindgen can't know if RVO happened or not. However this is incorrect in several ways. The problem in #778 has nothing whatsoever to do with RVO but rather with bindgen simply not understanding the calling convention for passing or returning types that are "non trivial for the purposes of calls". This is completely consistent and does not depend on what the optimizer decided to do (after all, if callsite side calling-convention did depend on what the optimizer happened to do inside the function it would be impossible for C++ compilers to emit correct calls to external C++ functions!). You can see this quite clearly [here](https://godbolt.org/#z:OYLghAFBqd5QCxAYwPYBMCmBRdBLAF1QCcAaPECAMzwBtMA7AQwFtMQByARg9KtQYEAysib0QXACx8BBAKoBnTAAUAHpwAMvAFYTStJg1DIApACYAQuYukl9ZATwDKjdAGFUtAK4sGIM6SuADJ4DJgAcj4ARpjEEgDspAAOqAqETgwe3r7%2ByanpAiFhkSwxcVyJdpgOGUIETMQEWT5%2BAVU1AnUNBEUR0bEJtvWNzTltwz2hfaUDFQCUtqhexMjsHAD06wDUACoAnkmYW3tLxFtoWFsIsZikWyRbtKhM6FuGW5iqrEn0AHQmGgAggoCMQvA4tgRMCCokwlFsTPErPEACImADMViBILBEKhIIRSIBgK2pMh0IIEDmGKxJLJ%2BMpaAYBIZ5gAbNTMcSyVsAG6oPDoABUkJpxMRaK5QIZWwUAEcvA1MFTCbSeTKCIjkZK1WTiJgCMsGKKpYCJeKgaECFsWExQiqtdz6RTIQj0SjZQqlVSxUCnaT9YbiMa0gAvTCoKgQBmc2kSjgLWicACsvD8HC0pFQnDc1msstOqwRZnRPFIBE0CYWAGsQOj0b9603my22fpOJI05Ws5xeAoQBpy5WFnBYEg0CwknRYuRKBOp/Q4sAFMwkgoEKgCKQsLy8KsAGp4TAAdwA8od02WaLQocR%2BxAot2oqEGntOGWJ2xBKeGLQ3xneCwW0jHEADtzwfUal5aFu0%2BaovChd9eCtTAkzA2g8CiYhXw8LBu1BPAWCQhYqAMZdDxPc9GCQmRBBEMR2CkWj5CUNRu10Lh9EMYw80sfRMP7SAFlQJJHAEfsOD7VDqjEvwIFcUY/E44IphKMo9BSNJZMUjT8lk3o1NmWxpI6BguhGTwWj0dpZPMyZin6cohm6HTOJBboDMciQFgUQtGMTFMuzA7MOC2VQAA42QAWjZSQtmAZBkC2aMwQYas5mS3BCAecxSzmXgKwAuYazrBsW3Kps2zQztSHTTMQr7AchyK0hR0QFBUEnacyAoCB526kBl1XddN23TBdwPI8zwvGjr1ve9HzA59mGIf8P06r8CB/P9uyA7jQMzfBIMcaCJMzODkAQtYyxQtDMwwrCcIwNZMwIojuATPgyIUCjpuoj7mPo8QmP4QRFBUdQwN0AIDCMFBeJsB7BKpLNRIyCSoqoBhUCi1DBUwKKmRxcEiDvKT7FklwGHcSycmU6nPJmJzNIKTJaaUvItIyRn1LckzbImVzjIp2oJh5oz3Is7IOcl%2Bzpl5ny/O89sOFTWruxCsLIpiuKEqSlKvDSjKICy0nizygrhxK%2BtGwq8qVZqureAa2wmsKrRipVswgvq3tmo9hZoLvDIQEkIA) Notice how the body of `main` is identical no matter if copy elision is enabled or not. To get `test` passed in a register you must remove the copy constructor. I spent a few hours being really confused by this note before I tracked down the original PR and realized what it was trying to talk about. Hopefully this saves the next person to come across it the same trouble. As an aside I suspect the clang c bindings can already give you information on special member functions and base classes, making it fairly easy to do this correctly. AFAICT bindgen already does not rely on llvm's code generation facilities to figure out the ABI of calls for C (except perhaps indirectly, via rustc), so this seems reasonable to just do in bindgen, explicitly. --- book/src/cpp.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/book/src/cpp.md b/book/src/cpp.md index 75ef855494..6928584627 100644 --- a/book/src/cpp.md +++ b/book/src/cpp.md @@ -72,7 +72,10 @@ cannot translate into Rust: [the tracking issue for exceptions](https://github.com/rust-lang/rust-bindgen/issues/1208) for more details. -* Return value optimization. C++ compilers will in certain circumstances optimize functions - returning a struct type value to instead take an extra hidden argument that refers - to the return value struct. `bindgen` cannot necessarily know about this optimization and - thus at present `bindgen`-interfaces for these kinds of functions are invalid. +* Many C++ specific aspects of calling conventions. For example in the Itanium abi types that are + "[non trivial for the purposes of calls](https://itanium-cxx-abi.github.io/cxx-abi/abi.html#non-trivial)" + should be passed by pointer, even if they are otherwise eligable to be passed in a register. + Similarly in both the Itanium and MSVC ABIs such types are returned by "hidden parameter", much like + large structs in C that would not fit into a register. This also applies to types with any base classes + in the MSVC ABI (see [x64 calling convention](https://learn.microsoft.com/en-us/cpp/build/x64-calling-convention?view=msvc-170#return-values)). + Because bindgen does not know about these rules generated interfaces using such types are currently invalid. From 4f92dfb7c59afa01e1e1ac305e9eea60d935d12d Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Tue, 1 Nov 2022 08:16:41 -0500 Subject: [PATCH 398/942] Add tutorial about non-system libraries (#2318) * add tutorial about non-system libraries * fix broken comment * ignore code snippet --- book/src/SUMMARY.md | 1 + book/src/non-system-libraries.md | 106 +++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 book/src/non-system-libraries.md diff --git a/book/src/SUMMARY.md b/book/src/SUMMARY.md index e7feff9523..551ea0d5f6 100644 --- a/book/src/SUMMARY.md +++ b/book/src/SUMMARY.md @@ -10,6 +10,7 @@ - [Include the Generated Bindings in `src/lib.rs`](./tutorial-4.md) - [Write a Sanity Test](./tutorial-5.md) - [Publish Your Crate!](./tutorial-6.md) + - [Bindings for non-system libraries](./non-system-libraries.md) - [Command Line Usage](./command-line-usage.md) - [Customizing the Generated Bindings](./customizing-generated-bindings.md) - [Allowlisting](./allowlisting.md) diff --git a/book/src/non-system-libraries.md b/book/src/non-system-libraries.md new file mode 100644 index 0000000000..c724a2fc77 --- /dev/null +++ b/book/src/non-system-libraries.md @@ -0,0 +1,106 @@ +Now let's suppose we want to generate bindings for a non-system library. We +will be the same crate setup as the previous tutorial. First let's create a new +directory `hello` with two files inside it. A `c` source file `hello.c` +containing +```c +int hello() { + return 42; +} +``` +and a `c` header file `hello.h` containing +```c +int hello(); +``` +given that the library has not been compiled yet, we need to modify the +`build.rs` build script to compile the `hello.c` source file into a static +libary: + +```rust,ignore +extern crate bindgen; + +use std::env; +use std::path::PathBuf; + +use bindgen::CargoCallbacks; + +fn main() { + // This is the directory where the `c` library is located. + let libdir_path = PathBuf::from("hello") + // Canonicalize the path as `rustc-link-search` requires an absolute + // path. + .canonicalize() + .expect("cannot canonicalize path"); + + // This is the path to the `c` headers file. + let headers_path = libdir_path.join("hello.h"); + let headers_path_str = headers_path.to_str().expect("Path is not a valid string"); + + // This is the path to the intermediate object file for our library. + let obj_path = libdir_path.join("hello.o"); + // This is the path to the static library file. + let lib_path = libdir_path.join("libhello.a"); + + // Tell cargo to look for shared libraries in the specified directory + println!("cargo:rustc-link-search={}", libdir_path.to_str().unwrap()); + + // Tell cargo to tell rustc to link our `hello` library. Cargo will + // automatically know it must look for a `libhello.a` file. + println!("cargo:rustc-link-lib=hello"); + + // Tell cargo to invalidate the built crate whenever the header changes. + println!("cargo:rerun-if-changed={}", headers_path_str); + + // Run `clang` to compile the `hello.c` file into a `hello.o` object file. + // Unwrap if it is not possible to spawn the process. + if !std::process::Command::new("clang") + .arg("-c") + .arg("-o") + .arg(&obj_path) + .arg(libdir_path.join("hello.c")) + .output() + .expect("could not spawn `clang`") + .status + .success() + { + // Panic if the command was not successful. + panic!("could not compile object file"); + } + + // Run `ar` to generate the `libhello.a` file from the `hello.o` file. + // Unwrap if it is not possible to spawn the process. + if !std::process::Command::new("ar") + .arg("rcs") + .arg(lib_path) + .arg(obj_path) + .output() + .expect("could not spawn `ar`") + .status + .success() + { + // Panic if the command was not successful. + panic!("could not emit library file"); + } + + // The bindgen::Builder is the main entry point + // to bindgen, and lets you build up options for + // the resulting bindings. + let bindings = bindgen::Builder::default() + // The input header we would like to generate + // bindings for. + .header(headers_path_str) + // Tell cargo to invalidate the built crate whenever any of the + // included header files changed. + .parse_callbacks(Box::new(CargoCallbacks)) + // Finish the builder and generate the bindings. + .generate() + // Unwrap the Result and panic on failure. + .expect("Unable to generate bindings"); + + // Write the bindings to the $OUT_DIR/bindings.rs file. + let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("bindings.rs"); + bindings + .write_to_file(out_path) + .expect("Couldn't write bindings!"); +} +``` + From a2fe04cbafaf0c7b40979e1cc505a90d76f4d099 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Tue, 1 Nov 2022 08:49:57 -0500 Subject: [PATCH 399/942] Add a mechanism to rerun bindgen with the same user options (#2292) * Run `Bindings::generate` again if required. This adds a mechanism so `bindgen` is able to run `Bindings::generate` multiple times with the same user input if the `generate_static_inline` option is enabled and `GenerateResult::ShouldRestart` is returned by `Bindings::generate`. This is done to eventually solve #1090 which would require to check for any static inline functions and generate a new header file to be used as an extra input and run `Bindings::generate` again. --- bindgen/lib.rs | 57 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 22ce603c4d..3551ecbc5f 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -1559,25 +1559,33 @@ impl Builder { } /// Generate the Rust bindings using the options built up thus far. - pub fn generate(mut self) -> Result { + pub fn generate(self) -> Result { + let mut options = self.options.clone(); // Add any extra arguments from the environment to the clang command line. - self.options.clang_args.extend(get_extra_clang_args()); + options.clang_args.extend(get_extra_clang_args()); // Transform input headers to arguments on the clang command line. - self.options.clang_args.extend( - self.options.input_headers - [..self.options.input_headers.len().saturating_sub(1)] + options.clang_args.extend( + options.input_headers + [..options.input_headers.len().saturating_sub(1)] .iter() .flat_map(|header| ["-include".into(), header.to_string()]), ); let input_unsaved_files = - std::mem::take(&mut self.options.input_header_contents) + std::mem::take(&mut options.input_header_contents) .into_iter() .map(|(name, contents)| clang::UnsavedFile::new(name, contents)) .collect::>(); - Bindings::generate(self.options, input_unsaved_files) + match Bindings::generate(options, input_unsaved_files) { + GenerateResult::Ok(bindings) => Ok(bindings), + GenerateResult::ShouldRestart { header } => self + .header(header) + .generate_inline_functions(false) + .generate(), + GenerateResult::Err(err) => Err(err), + } } /// Preprocess and dump the input header files to disk. @@ -2282,6 +2290,18 @@ fn ensure_libclang_is_loaded() { #[cfg(not(feature = "runtime"))] fn ensure_libclang_is_loaded() {} +#[derive(Debug)] +enum GenerateResult { + Ok(Bindings), + /// Error variant raised when bindgen requires to run again with a newly generated header + /// input. + #[allow(dead_code)] + ShouldRestart { + header: String, + }, + Err(BindgenError), +} + /// Error type for rust-bindgen. #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[non_exhaustive] @@ -2375,7 +2395,7 @@ impl Bindings { pub(crate) fn generate( mut options: BindgenOptions, input_unsaved_files: Vec, - ) -> Result { + ) -> GenerateResult { ensure_libclang_is_loaded(); #[cfg(feature = "runtime")] @@ -2496,17 +2516,22 @@ impl Bindings { let path = Path::new(h); if let Ok(md) = std::fs::metadata(path) { if md.is_dir() { - return Err(BindgenError::FolderAsHeader(path.into())); + return GenerateResult::Err( + BindgenError::FolderAsHeader(path.into()).into(), + ); } if !can_read(&md.permissions()) { - return Err(BindgenError::InsufficientPermissions( - path.into(), - )); + return GenerateResult::Err( + BindgenError::InsufficientPermissions(path.into()) + .into(), + ); } let h = h.clone(); options.clang_args.push(h); } else { - return Err(BindgenError::NotExist(path.into())); + return GenerateResult::Err( + BindgenError::NotExist(path.into()).into(), + ); } } @@ -2534,12 +2559,14 @@ impl Bindings { { let _t = time::Timer::new("parse").with_output(time_phases); - parse(&mut context)?; + if let Err(err) = parse(&mut context) { + return GenerateResult::Err(err); + } } let (module, options, warnings) = codegen::codegen(context); - Ok(Bindings { + GenerateResult::Ok(Bindings { options, warnings, module, From 83426897af20d938fb4dca879d54de456ab96d6b Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Wed, 2 Nov 2022 13:32:32 -0500 Subject: [PATCH 400/942] Fix clippy warnings (#2331) --- bindgen/codegen/mod.rs | 10 +++++----- bindgen/ir/context.rs | 18 +++++++++--------- bindgen/ir/enum_ty.rs | 2 +- bindgen/ir/item.rs | 2 +- bindgen/lib.rs | 22 ++++++++++------------ 5 files changed, 26 insertions(+), 28 deletions(-) diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 7e0d7aa0c9..bf0b33564b 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -85,7 +85,7 @@ fn root_import( let mut path = top_level_path(ctx, module); let root = ctx.root_module().canonical_name(ctx); - let root_ident = ctx.rust_ident(&root); + let root_ident = ctx.rust_ident(root); path.push(quote! { #root_ident }); let mut tokens = quote! {}; @@ -797,7 +797,7 @@ impl CodeGenerator for Type { } }; - let rust_name = ctx.rust_ident(&name); + let rust_name = ctx.rust_ident(name); let mut tokens = if let Some(comment) = item.comment(ctx) { attributes::doc(comment) @@ -1076,7 +1076,7 @@ impl<'a> CodeGenerator for Vtable<'a> { ) { assert_eq!(item.id(), self.item_id); debug_assert!(item.is_enabled_for_codegen(ctx)); - let name = ctx.rust_ident(&self.canonical_name(ctx)); + let name = ctx.rust_ident(self.canonical_name(ctx)); // For now, we will only generate vtables for classes that: // - do not inherit from others (compilers merge VTable from primary parent class). @@ -1582,7 +1582,7 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit { { let align_field_name = format!("_bitfield_align_{}", self.nth()); - let align_field_ident = ctx.rust_ident(&align_field_name); + let align_field_ident = ctx.rust_ident(align_field_name); let align_ty = match self.layout().align { n if n >= 8 => quote! { u64 }, 4 => quote! { u32 }, @@ -3875,7 +3875,7 @@ impl TryToRustTy for Type { } TypeKind::TypeParam => { let name = item.canonical_name(ctx); - let ident = ctx.rust_ident(&name); + let ident = ctx.rust_ident(name); Ok(quote! { #ident }) diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index ba2db1126c..d987534db0 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -2076,7 +2076,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" self.in_codegen_phase(), "You're not supposed to call this yet" ); - self.options.opaque_types.matches(&path[1..].join("::")) + self.options.opaque_types.matches(path[1..].join("::")) } /// Get the options used to configure this bindgen context. @@ -2314,7 +2314,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" if self .options() .allowlisted_files - .matches(&filename) + .matches(filename) { return true; } @@ -2389,7 +2389,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" ); let name = prefix_path[1..].join("::"); prefix_path.pop().unwrap(); - self.options().allowlisted_vars.matches(&name) + self.options().allowlisted_vars.matches(name) }) } } @@ -2671,37 +2671,37 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// Check if `--no-partialeq` flag is enabled for this item. pub fn no_partialeq_by_name(&self, item: &Item) -> bool { let name = item.path_for_allowlisting(self)[1..].join("::"); - self.options().no_partialeq_types.matches(&name) + self.options().no_partialeq_types.matches(name) } /// Check if `--no-copy` flag is enabled for this item. pub fn no_copy_by_name(&self, item: &Item) -> bool { let name = item.path_for_allowlisting(self)[1..].join("::"); - self.options().no_copy_types.matches(&name) + self.options().no_copy_types.matches(name) } /// Check if `--no-debug` flag is enabled for this item. pub fn no_debug_by_name(&self, item: &Item) -> bool { let name = item.path_for_allowlisting(self)[1..].join("::"); - self.options().no_debug_types.matches(&name) + self.options().no_debug_types.matches(name) } /// Check if `--no-default` flag is enabled for this item. pub fn no_default_by_name(&self, item: &Item) -> bool { let name = item.path_for_allowlisting(self)[1..].join("::"); - self.options().no_default_types.matches(&name) + self.options().no_default_types.matches(name) } /// Check if `--no-hash` flag is enabled for this item. pub fn no_hash_by_name(&self, item: &Item) -> bool { let name = item.path_for_allowlisting(self)[1..].join("::"); - self.options().no_hash_types.matches(&name) + self.options().no_hash_types.matches(name) } /// Check if `--must-use-type` flag is enabled for this item. pub fn must_use_type_by_name(&self, item: &Item) -> bool { let name = item.path_for_allowlisting(self)[1..].join("::"); - self.options().must_use_types.matches(&name) + self.options().must_use_types.matches(name) } } diff --git a/bindgen/ir/enum_ty.rs b/bindgen/ir/enum_ty.rs index 123d1d793d..059ee012b2 100644 --- a/bindgen/ir/enum_ty.rs +++ b/bindgen/ir/enum_ty.rs @@ -156,7 +156,7 @@ impl Enum { let path = item.path_for_allowlisting(ctx); let enum_ty = item.expect_type(); - if enums.matches(&path[1..].join("::")) { + if enums.matches(path[1..].join("::")) { return true; } diff --git a/bindgen/ir/item.rs b/bindgen/ir/item.rs index 3b15cd6ed6..1f4ac154bf 100644 --- a/bindgen/ir/item.rs +++ b/bindgen/ir/item.rs @@ -650,7 +650,7 @@ impl Item { if let Some(location) = &self.location { let (file, _, _, _) = location.location(); if let Some(filename) = file.name() { - if ctx.options().blocklisted_files.matches(&filename) { + if ctx.options().blocklisted_files.matches(filename) { return true; } } diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 3551ecbc5f..4d72df0b09 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -1640,7 +1640,7 @@ impl Builder { wrapper_file.write_all(wrapper_contents.as_bytes())?; } - let mut cmd = Command::new(&clang.path); + let mut cmd = Command::new(clang.path); cmd.arg("-save-temps") .arg("-E") .arg("-C") @@ -2516,22 +2516,21 @@ impl Bindings { let path = Path::new(h); if let Ok(md) = std::fs::metadata(path) { if md.is_dir() { - return GenerateResult::Err( - BindgenError::FolderAsHeader(path.into()).into(), - ); + return GenerateResult::Err(BindgenError::FolderAsHeader( + path.into(), + )); } if !can_read(&md.permissions()) { return GenerateResult::Err( - BindgenError::InsufficientPermissions(path.into()) - .into(), + BindgenError::InsufficientPermissions(path.into()), ); } let h = h.clone(); options.clang_args.push(h); } else { - return GenerateResult::Err( - BindgenError::NotExist(path.into()).into(), - ); + return GenerateResult::Err(BindgenError::NotExist( + path.into(), + )); } } @@ -2855,11 +2854,10 @@ pub fn clang_version() -> ClangVersion { /// Looks for the env var `var_${TARGET}`, and falls back to just `var` when it is not found. fn get_target_dependent_env_var(var: &str) -> Option { if let Ok(target) = env::var("TARGET") { - if let Ok(v) = env::var(&format!("{}_{}", var, target)) { + if let Ok(v) = env::var(format!("{}_{}", var, target)) { return Some(v); } - if let Ok(v) = - env::var(&format!("{}_{}", var, target.replace('-', "_"))) + if let Ok(v) = env::var(format!("{}_{}", var, target.replace('-', "_"))) { return Some(v); } From a673a6bc9b83675a7468379e79dcf5d5659c4623 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Wed, 2 Nov 2022 13:46:22 -0500 Subject: [PATCH 401/942] Allow callback composition (#2330) * Allow callback composition Store all the callbacks added to the builder in a `Vec` so bindgen invokes each one of them in a last-to-first manner. --- CHANGELOG.md | 2 ++ bindgen/codegen/mod.rs | 21 +++++++++------------ bindgen/ir/context.rs | 39 +++++++++++++++++++-------------------- bindgen/ir/enum_ty.rs | 8 ++++---- bindgen/ir/function.rs | 9 +++++---- bindgen/ir/item.rs | 4 ++-- bindgen/ir/var.rs | 10 +++++----- bindgen/lib.rs | 26 +++++++++++++++++++++++--- 8 files changed, 69 insertions(+), 50 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index de08d829e1..560ce38ba2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -154,6 +154,8 @@ * Regex inputs are sanitized so alternation (`a|b`) is handled correctly but wildcard patterns (`*`) are now considered invalid. * the `ParseCallbacks`trait does not require to implement `UnwindSafe`. + * the `Builder::parse_callbacks` method no longer overwrites previously added + callbacks and composes them in a last-to-first manner. ## Removed diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index bf0b33564b..a59265ab82 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -2112,12 +2112,11 @@ impl CodeGenerator for CompInfo { // The custom derives callback may return a list of derive attributes; // add them to the end of the list. - let custom_derives; - if let Some(cb) = &ctx.options().parse_callbacks { - custom_derives = cb.add_derives(&canonical_name); - // In most cases this will be a no-op, since custom_derives will be empty. - derives.extend(custom_derives.iter().map(|s| s.as_str())); - }; + let custom_derives = ctx + .options() + .all_callbacks(|cb| cb.add_derives(&canonical_name)); + // In most cases this will be a no-op, since custom_derives will be empty. + derives.extend(custom_derives.iter().map(|s| s.as_str())); if !derives.is_empty() { attributes.push(attributes::derives(&derives)) @@ -3152,12 +3151,10 @@ impl CodeGenerator for Enum { // The custom derives callback may return a list of derive attributes; // add them to the end of the list. - let custom_derives; - if let Some(cb) = &ctx.options().parse_callbacks { - custom_derives = cb.add_derives(&name); - // In most cases this will be a no-op, since custom_derives will be empty. - derives.extend(custom_derives.iter().map(|s| s.as_str())); - }; + let custom_derives = + ctx.options().all_callbacks(|cb| cb.add_derives(&name)); + // In most cases this will be a no-op, since custom_derives will be empty. + derives.extend(custom_derives.iter().map(|s| s.as_str())); attrs.push(attributes::derives(&derives)); } diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index d987534db0..928f24067b 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -19,7 +19,6 @@ use super::module::{Module, ModuleKind}; use super::template::{TemplateInstantiation, TemplateParameters}; use super::traversal::{self, Edge, ItemTraversal}; use super::ty::{FloatKind, Type, TypeKind}; -use crate::callbacks::ParseCallbacks; use crate::clang::{self, Cursor}; use crate::parse::ClangItemParser; use crate::BindgenOptions; @@ -619,15 +618,10 @@ If you encounter an error missing from this list, please file an issue or a PR!" ) } - /// Get the user-provided callbacks by reference, if any. - pub fn parse_callbacks(&self) -> Option<&dyn ParseCallbacks> { - self.options().parse_callbacks.as_deref() - } - /// Add another path to the set of included files. pub fn include_file(&mut self, filename: String) { - if let Some(cbs) = self.parse_callbacks() { - cbs.include_file(&filename); + for cb in &self.options().parse_callbacks { + cb.include_file(&filename); } self.deps.insert(filename); } @@ -2240,19 +2234,24 @@ If you encounter an error missing from this list, please file an issue or a PR!" .or_insert_with(|| { item.expect_type() .name() - .and_then(|name| match self.options.parse_callbacks { - Some(ref cb) => cb.blocklisted_type_implements_trait( - name, - derive_trait, - ), - // Sized integer types from get mapped to Rust primitive - // types regardless of whether they are blocklisted, so ensure that - // standard traits are considered derivable for them too. - None => Some(if self.is_stdint_type(name) { - CanDerive::Yes + .and_then(|name| { + if self.options.parse_callbacks.is_empty() { + // Sized integer types from get mapped to Rust primitive + // types regardless of whether they are blocklisted, so ensure that + // standard traits are considered derivable for them too. + if self.is_stdint_type(name) { + Some(CanDerive::Yes) + } else { + Some(CanDerive::No) + } } else { - CanDerive::No - }), + self.options.last_callback(|cb| { + cb.blocklisted_type_implements_trait( + name, + derive_trait, + ) + }) + } }) .unwrap_or(CanDerive::No) }) diff --git a/bindgen/ir/enum_ty.rs b/bindgen/ir/enum_ty.rs index 059ee012b2..39677e93fd 100644 --- a/bindgen/ir/enum_ty.rs +++ b/bindgen/ir/enum_ty.rs @@ -102,8 +102,8 @@ impl Enum { let name = cursor.spelling(); let annotations = Annotations::new(&cursor); let custom_behavior = ctx - .parse_callbacks() - .and_then(|callbacks| { + .options() + .last_callback(|callbacks| { callbacks .enum_variant_behavior(type_name, &name, val) }) @@ -119,8 +119,8 @@ impl Enum { }); let new_name = ctx - .parse_callbacks() - .and_then(|callbacks| { + .options() + .last_callback(|callbacks| { callbacks.enum_variant_name(type_name, &name, val) }) .or_else(|| { diff --git a/bindgen/ir/function.rs b/bindgen/ir/function.rs index c160ed8149..f488b38498 100644 --- a/bindgen/ir/function.rs +++ b/bindgen/ir/function.rs @@ -664,10 +664,11 @@ impl ClangSubItemParser for Function { // but seems easy enough to handle it here. name.push_str("_destructor"); } - if let Some(callbacks) = context.parse_callbacks() { - if let Some(nm) = callbacks.generated_name_override(&name) { - name = nm; - } + if let Some(nm) = context + .options() + .last_callback(|callbacks| callbacks.generated_name_override(&name)) + { + name = nm; } assert!(!name.is_empty(), "Empty function name."); diff --git a/bindgen/ir/item.rs b/bindgen/ir/item.rs index 1f4ac154bf..446d78bda5 100644 --- a/bindgen/ir/item.rs +++ b/bindgen/ir/item.rs @@ -932,8 +932,8 @@ impl Item { let name = names.join("_"); let name = if opt.user_mangled == UserMangled::Yes { - ctx.parse_callbacks() - .and_then(|callbacks| callbacks.item_name(&name)) + ctx.options() + .last_callback(|callbacks| callbacks.item_name(&name)) .unwrap_or(name) } else { name diff --git a/bindgen/ir/var.rs b/bindgen/ir/var.rs index daaad8c56a..198206b9f1 100644 --- a/bindgen/ir/var.rs +++ b/bindgen/ir/var.rs @@ -182,7 +182,7 @@ impl ClangSubItemParser for Var { use clang_sys::*; match cursor.kind() { CXCursor_MacroDefinition => { - if let Some(callbacks) = ctx.parse_callbacks() { + for callbacks in &ctx.options().parse_callbacks { match callbacks.will_parse_macro(&cursor.spelling()) { MacroParsingBehavior::Ignore => { return Err(ParseError::Continue); @@ -191,7 +191,7 @@ impl ClangSubItemParser for Var { } if cursor.is_macro_function_like() { - handle_function_macro(&cursor, callbacks); + handle_function_macro(&cursor, callbacks.as_ref()); // We handled the macro, skip macro processing below. return Err(ParseError::Continue); } @@ -249,15 +249,15 @@ impl ClangSubItemParser for Var { true, ctx, ); - if let Some(callbacks) = ctx.parse_callbacks() { + for callbacks in &ctx.options().parse_callbacks { callbacks.str_macro(&name, &val); } (TypeKind::Pointer(char_ty), VarType::String(val)) } EvalResult::Int(Wrapping(value)) => { let kind = ctx - .parse_callbacks() - .and_then(|c| c.int_macro(&name, value)) + .options() + .last_callback(|c| c.int_macro(&name, value)) .unwrap_or_else(|| { default_macro_constant_type(ctx, value) }); diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 4d72df0b09..5e04acfe83 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -1464,7 +1464,7 @@ impl Builder { mut self, cb: Box, ) -> Self { - self.options.parse_callbacks = Some(Rc::from(cb)); + self.options.parse_callbacks.push(Rc::from(cb)); self } @@ -1982,7 +1982,7 @@ struct BindgenOptions { /// A user-provided visitor to allow customizing different kinds of /// situations. - parse_callbacks: Option>, + parse_callbacks: Vec>, /// Which kind of items should we generate? By default, we'll generate all /// of them. @@ -2160,6 +2160,26 @@ impl BindgenOptions { pub fn rust_features(&self) -> RustFeatures { self.rust_features } + + fn last_callback( + &self, + f: impl Fn(&dyn callbacks::ParseCallbacks) -> Option, + ) -> Option { + self.parse_callbacks + .iter() + .filter_map(|cb| f(cb.as_ref())) + .last() + } + + fn all_callbacks( + &self, + f: impl Fn(&dyn callbacks::ParseCallbacks) -> Vec, + ) -> Vec { + self.parse_callbacks + .iter() + .flat_map(|cb| f(cb.as_ref())) + .collect() + } } impl Default for BindgenOptions { @@ -2225,7 +2245,7 @@ impl Default for BindgenOptions { clang_args: vec![], input_headers: vec![], input_header_contents: Default::default(), - parse_callbacks: None, + parse_callbacks: Default::default(), codegen_config: CodegenConfig::all(), conservative_inline_namespaces: false, generate_comments: true, From 9c32b460481903d90c6ac5df277bfa853a0558d8 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Wed, 2 Nov 2022 15:30:34 -0500 Subject: [PATCH 402/942] Add the `--override-abi` option (#2329) * Add the `--override-abi` option. This option can be used from the CLI with the : syntax and it overrides the ABI of a function if it matches . Fixes #2257 --- CHANGELOG.md | 2 + bindgen-cli/options.rs | 18 +++ .../tests/expectations/tests/abi-override.rs | 16 ++ bindgen-tests/tests/headers/abi-override.h | 5 + bindgen/codegen/dyngen.rs | 6 +- bindgen/codegen/mod.rs | 46 +++--- bindgen/ir/function.rs | 148 +++++++++++------- bindgen/lib.rs | 25 ++- 8 files changed, 190 insertions(+), 76 deletions(-) create mode 100644 bindgen-tests/tests/expectations/tests/abi-override.rs create mode 100644 bindgen-tests/tests/headers/abi-override.h diff --git a/CHANGELOG.md b/CHANGELOG.md index 560ce38ba2..baa5cb204e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -148,6 +148,8 @@ # Unreleased ## Added + * new feature: `--override-abi` flag to override the ABI used by functions + matching a regular expression. ## Changed diff --git a/bindgen-cli/options.rs b/bindgen-cli/options.rs index 5c3960e92b..c186cfd92c 100644 --- a/bindgen-cli/options.rs +++ b/bindgen-cli/options.rs @@ -568,6 +568,12 @@ where Arg::new("merge-extern-blocks") .long("merge-extern-blocks") .help("Deduplicates extern blocks."), + Arg::new("override-abi") + .long("override-abi") + .help("Overrides the ABI of functions matching . The value must be of the shape : where can be one of C, stdcall, fastcall, thiscall, aapcs or win64.") + .value_name("override") + .multiple_occurrences(true) + .number_of_values(1), Arg::new("V") .long("version") .help("Prints the version, and exits"), @@ -1088,5 +1094,17 @@ where builder = builder.merge_extern_blocks(true); } + if let Some(abi_overrides) = matches.values_of("override-abi") { + for abi_override in abi_overrides { + let (regex, abi_str) = abi_override + .rsplit_once("=") + .expect("Invalid ABI override: Missing `=`"); + let abi = abi_str + .parse() + .unwrap_or_else(|err| panic!("Invalid ABI override: {}", err)); + builder = builder.override_abi(abi, regex); + } + } + Ok((builder, output, verbose)) } diff --git a/bindgen-tests/tests/expectations/tests/abi-override.rs b/bindgen-tests/tests/expectations/tests/abi-override.rs new file mode 100644 index 0000000000..49693692e4 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/abi-override.rs @@ -0,0 +1,16 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +extern "fastcall" { + pub fn foo(); +} +extern "stdcall" { + pub fn bar(); +} +extern "C" { + pub fn baz(); +} diff --git a/bindgen-tests/tests/headers/abi-override.h b/bindgen-tests/tests/headers/abi-override.h new file mode 100644 index 0000000000..cee72caeef --- /dev/null +++ b/bindgen-tests/tests/headers/abi-override.h @@ -0,0 +1,5 @@ +// bindgen-flags: --override-abi=foo=fastcall --override-abi=bar=stdcall + +void foo(); +void bar(); +void baz(); diff --git a/bindgen/codegen/dyngen.rs b/bindgen/codegen/dyngen.rs index 26cfe5cc9e..d02c51e420 100644 --- a/bindgen/codegen/dyngen.rs +++ b/bindgen/codegen/dyngen.rs @@ -1,5 +1,5 @@ use crate::codegen; -use crate::ir::function::Abi; +use crate::ir::function::ClangAbi; use proc_macro2::Ident; /// Used to build the output tokens for dynamic bindings. @@ -113,10 +113,10 @@ impl DynamicItems { } #[allow(clippy::too_many_arguments)] - pub fn push( + pub(crate) fn push( &mut self, ident: Ident, - abi: Abi, + abi: ClangAbi, is_variadic: bool, is_required: bool, args: Vec, diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index a59265ab82..4e90102d36 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -32,7 +32,9 @@ use crate::ir::derive::{ }; use crate::ir::dot; use crate::ir::enum_ty::{Enum, EnumVariant, EnumVariantValue}; -use crate::ir::function::{Abi, Function, FunctionKind, FunctionSig, Linkage}; +use crate::ir::function::{ + Abi, ClangAbi, Function, FunctionKind, FunctionSig, Linkage, +}; use crate::ir::int::IntKind; use crate::ir::item::{IsOpaque, Item, ItemCanonicalName, ItemCanonicalPath}; use crate::ir::item_kind::ItemKind; @@ -2474,9 +2476,13 @@ impl MethodCodegen for Method { _ => panic!("How in the world?"), }; - let supported_abi = match signature.abi() { - Abi::ThisCall => ctx.options().rust_features().thiscall_abi, - Abi::Vectorcall => ctx.options().rust_features().vectorcall_abi, + let supported_abi = match signature.abi(ctx, Some(&*name)) { + ClangAbi::Known(Abi::ThisCall) => { + ctx.options().rust_features().thiscall_abi + } + ClangAbi::Known(Abi::Vectorcall) => { + ctx.options().rust_features().vectorcall_abi + } _ => true, }; @@ -3988,14 +3994,16 @@ impl TryToRustTy for FunctionSig { // TODO: we might want to consider ignoring the reference return value. let ret = utils::fnsig_return_ty(ctx, self); let arguments = utils::fnsig_arguments(ctx, self); - let abi = self.abi(); + let abi = self.abi(ctx, None); match abi { - Abi::ThisCall if !ctx.options().rust_features().thiscall_abi => { + ClangAbi::Known(Abi::ThisCall) + if !ctx.options().rust_features().thiscall_abi => + { warn!("Skipping function with thiscall ABI that isn't supported by the configured Rust target"); Ok(proc_macro2::TokenStream::new()) } - Abi::Vectorcall + ClangAbi::Known(Abi::Vectorcall) if !ctx.options().rust_features().vectorcall_abi => { warn!("Skipping function with vectorcall ABI that isn't supported by the configured Rust target"); @@ -4099,22 +4107,24 @@ impl CodeGenerator for Function { attributes.push(attributes::doc(comment)); } - let abi = match signature.abi() { - Abi::ThisCall if !ctx.options().rust_features().thiscall_abi => { + let abi = match signature.abi(ctx, Some(name)) { + ClangAbi::Known(Abi::ThisCall) + if !ctx.options().rust_features().thiscall_abi => + { warn!("Skipping function with thiscall ABI that isn't supported by the configured Rust target"); return None; } - Abi::Vectorcall + ClangAbi::Known(Abi::Vectorcall) if !ctx.options().rust_features().vectorcall_abi => { warn!("Skipping function with vectorcall ABI that isn't supported by the configured Rust target"); return None; } - Abi::Win64 if signature.is_variadic() => { + ClangAbi::Known(Abi::Win64) if signature.is_variadic() => { warn!("Skipping variadic function with Win64 ABI that isn't supported"); return None; } - Abi::Unknown(unknown_abi) => { + ClangAbi::Unknown(unknown_abi) => { panic!( "Invalid or unknown abi {:?} for function {:?} ({:?})", unknown_abi, canonical_name, self @@ -4512,7 +4522,7 @@ pub(crate) fn codegen( pub mod utils { use super::{error, ToRustTyOrOpaque}; use crate::ir::context::BindgenContext; - use crate::ir::function::{Abi, FunctionSig}; + use crate::ir::function::{Abi, ClangAbi, FunctionSig}; use crate::ir::item::{Item, ItemCanonicalPath}; use crate::ir::ty::TypeKind; use proc_macro2; @@ -4973,10 +4983,10 @@ pub mod utils { // Returns true if `canonical_name` will end up as `mangled_name` at the // machine code level, i.e. after LLVM has applied any target specific // mangling. - pub fn names_will_be_identical_after_mangling( + pub(crate) fn names_will_be_identical_after_mangling( canonical_name: &str, mangled_name: &str, - call_conv: Option, + call_conv: Option, ) -> bool { // If the mangled name and the canonical name are the same then no // mangling can have happened between the two versions. @@ -4989,13 +4999,13 @@ pub mod utils { let mangled_name = mangled_name.as_bytes(); let (mangling_prefix, expect_suffix) = match call_conv { - Some(Abi::C) | + Some(ClangAbi::Known(Abi::C)) | // None is the case for global variables None => { (b'_', false) } - Some(Abi::Stdcall) => (b'_', true), - Some(Abi::Fastcall) => (b'@', true), + Some(ClangAbi::Known(Abi::Stdcall)) => (b'_', true), + Some(ClangAbi::Known(Abi::Fastcall)) => (b'@', true), // This is something we don't recognize, stay on the safe side // by emitting the `#[link_name]` attribute diff --git a/bindgen/ir/function.rs b/bindgen/ir/function.rs index f488b38498..8a70d60ac6 100644 --- a/bindgen/ir/function.rs +++ b/bindgen/ir/function.rs @@ -15,6 +15,7 @@ use proc_macro2; use quote; use quote::TokenStreamExt; use std::io; +use std::str::FromStr; const RUST_DERIVE_FUNPTR_LIMIT: usize = 12; @@ -170,8 +171,8 @@ impl DotAttributes for Function { } } -/// An ABI extracted from a clang cursor. -#[derive(Debug, Copy, Clone)] +/// A valid rust ABI. +#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq)] pub enum Abi { /// The default C ABI. C, @@ -187,32 +188,72 @@ pub enum Abi { Aapcs, /// The "win64" ABI. Win64, +} + +impl FromStr for Abi { + type Err = String; + + fn from_str(s: &str) -> Result { + match s { + "C" => Ok(Self::C), + "stdcall" => Ok(Self::Stdcall), + "fastcall" => Ok(Self::Fastcall), + "thiscall" => Ok(Self::ThisCall), + "vectorcall" => Ok(Self::Vectorcall), + "aapcs" => Ok(Self::Aapcs), + "win64" => Ok(Self::Win64), + _ => Err(format!("Invalid or unknown ABI {:?}", s)), + } + } +} + +impl std::fmt::Display for Abi { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let s = match *self { + Self::C => "C", + Self::Stdcall => "stdcall", + Self::Fastcall => "fastcall", + Self::ThisCall => "thiscall", + Self::Vectorcall => "vectorcall", + Self::Aapcs => "aapcs", + Self::Win64 => "win64", + }; + + s.fmt(f) + } +} + +impl quote::ToTokens for Abi { + fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) { + let abi = self.to_string(); + tokens.append_all(quote! { #abi }); + } +} + +/// An ABI extracted from a clang cursor. +#[derive(Debug, Copy, Clone)] +pub(crate) enum ClangAbi { + Known(Abi), /// An unknown or invalid ABI. Unknown(CXCallingConv), } -impl Abi { +impl ClangAbi { /// Returns whether this Abi is known or not. fn is_unknown(&self) -> bool { - matches!(*self, Abi::Unknown(..)) + matches!(*self, ClangAbi::Unknown(..)) } } -impl quote::ToTokens for Abi { +impl quote::ToTokens for ClangAbi { fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) { - tokens.append_all(match *self { - Abi::C => quote! { "C" }, - Abi::Stdcall => quote! { "stdcall" }, - Abi::Fastcall => quote! { "fastcall" }, - Abi::ThisCall => quote! { "thiscall" }, - Abi::Vectorcall => quote! { "vectorcall" }, - Abi::Aapcs => quote! { "aapcs" }, - Abi::Win64 => quote! { "win64" }, - Abi::Unknown(cc) => panic!( + match *self { + Self::Known(abi) => abi.to_tokens(tokens), + Self::Unknown(cc) => panic!( "Cannot turn unknown calling convention to tokens: {:?}", cc ), - }); + } } } @@ -234,21 +275,21 @@ pub struct FunctionSig { must_use: bool, /// The ABI of this function. - abi: Abi, + abi: ClangAbi, } -fn get_abi(cc: CXCallingConv) -> Abi { +fn get_abi(cc: CXCallingConv) -> ClangAbi { use clang_sys::*; match cc { - CXCallingConv_Default => Abi::C, - CXCallingConv_C => Abi::C, - CXCallingConv_X86StdCall => Abi::Stdcall, - CXCallingConv_X86FastCall => Abi::Fastcall, - CXCallingConv_X86ThisCall => Abi::ThisCall, - CXCallingConv_X86VectorCall => Abi::Vectorcall, - CXCallingConv_AAPCS => Abi::Aapcs, - CXCallingConv_X86_64Win64 => Abi::Win64, - other => Abi::Unknown(other), + CXCallingConv_Default => ClangAbi::Known(Abi::C), + CXCallingConv_C => ClangAbi::Known(Abi::C), + CXCallingConv_X86StdCall => ClangAbi::Known(Abi::Stdcall), + CXCallingConv_X86FastCall => ClangAbi::Known(Abi::Fastcall), + CXCallingConv_X86ThisCall => ClangAbi::Known(Abi::ThisCall), + CXCallingConv_X86VectorCall => ClangAbi::Known(Abi::Vectorcall), + CXCallingConv_AAPCS => ClangAbi::Known(Abi::Aapcs), + CXCallingConv_X86_64Win64 => ClangAbi::Known(Abi::Win64), + other => ClangAbi::Unknown(other), } } @@ -354,25 +395,6 @@ fn args_from_ty_and_cursor( } impl FunctionSig { - /// Construct a new function signature. - pub fn new( - return_type: TypeId, - argument_types: Vec<(Option, TypeId)>, - is_variadic: bool, - is_divergent: bool, - must_use: bool, - abi: Abi, - ) -> Self { - FunctionSig { - return_type, - argument_types, - is_variadic, - is_divergent, - must_use, - abi, - } - } - /// Construct a new function signature from the given Clang type. pub fn from_ty( ty: &clang::Type, @@ -540,20 +562,21 @@ impl FunctionSig { call_conv = cursor_call_conv; } } + let abi = get_abi(call_conv); if abi.is_unknown() { warn!("Unknown calling convention: {:?}", call_conv); } - Ok(Self::new( - ret, - args, - ty.is_variadic(), + Ok(FunctionSig { + return_type: ret, + argument_types: args, + is_variadic: ty.is_variadic(), is_divergent, must_use, abi, - )) + }) } /// Get this function signature's return type. @@ -567,8 +590,27 @@ impl FunctionSig { } /// Get this function signature's ABI. - pub fn abi(&self) -> Abi { - self.abi + pub(crate) fn abi( + &self, + ctx: &BindgenContext, + name: Option<&str>, + ) -> ClangAbi { + // FIXME (pvdrz): Try to do this check lazily instead. Maybe store the ABI inside `ctx` + // instead?. + if let Some(name) = name { + if let Some((abi, _)) = ctx + .options() + .abi_overrides + .iter() + .find(|(_, regex_set)| regex_set.matches(name)) + { + ClangAbi::Known(*abi) + } else { + self.abi + } + } else { + self.abi + } } /// Is this function signature variadic? @@ -598,7 +640,7 @@ impl FunctionSig { return false; } - matches!(self.abi, Abi::C | Abi::Unknown(..)) + matches!(self.abi, ClangAbi::Known(Abi::C) | ClangAbi::Unknown(..)) } pub(crate) fn is_divergent(&self) -> bool { diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 5e04acfe83..10410734a1 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -74,6 +74,7 @@ pub use crate::features::{ RustTarget, LATEST_STABLE_RUST, RUST_TARGET_STRINGS, }; use crate::ir::context::{BindgenContext, ItemId}; +pub use crate::ir::function::Abi; use crate::ir::item::Item; use crate::parse::{ClangItemParser, ParseError}; use crate::regex_set::RegexSet; @@ -364,6 +365,13 @@ impl Builder { } } + for (abi, set) in &self.options.abi_overrides { + for item in set.get_items() { + output_vector.push("--override-abi".to_owned()); + output_vector.push(format!("{}={}", item, abi)); + } + } + if !self.options.layout_tests { output_vector.push("--no-layout-tests".into()); } @@ -1774,6 +1782,16 @@ impl Builder { self.options.c_naming = doit; self } + + /// Override the ABI of a given function. Regular expressions are supported. + pub fn override_abi>(mut self, abi: Abi, arg: T) -> Self { + self.options + .abi_overrides + .entry(abi) + .or_default() + .insert(arg.into()); + self + } } /// Configuration options for generated bindings. @@ -2109,11 +2127,13 @@ struct BindgenOptions { /// Deduplicate `extern` blocks. merge_extern_blocks: bool, + + abi_overrides: HashMap, } impl BindgenOptions { fn build(&mut self) { - let mut regex_sets = [ + let regex_sets = [ &mut self.allowlisted_vars, &mut self.allowlisted_types, &mut self.allowlisted_functions, @@ -2143,7 +2163,7 @@ impl BindgenOptions { &mut self.must_use_types, ]; let record_matches = self.record_matches; - for regex_set in &mut regex_sets { + for regex_set in self.abi_overrides.values_mut().chain(regex_sets) { regex_set.build(record_matches); } } @@ -2280,6 +2300,7 @@ impl Default for BindgenOptions { vtable_generation: false, sort_semantically: false, merge_extern_blocks: false, + abi_overrides: Default::default(), } } } From 7c26cd218de85dca14a1c81b86e9d143626ce036 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Fri, 4 Nov 2022 10:19:28 -0500 Subject: [PATCH 403/942] Add support for the `"C-unwind"` ABI (#2334) * Add support for the `"C-unwind"` ABI This allows using `"C-unwind"` as an ABI override if the rust target is nightly. --- CHANGELOG.md | 2 ++ bindgen-cli/options.rs | 2 +- .../tests/c-unwind-abi-override-nightly.rs | 18 ++++++++++++++++++ .../headers/c-unwind-abi-override-nightly.h | 5 +++++ bindgen/codegen/mod.rs | 15 +++++++++++++++ bindgen/features.rs | 5 ++++- bindgen/ir/function.rs | 4 ++++ 7 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 bindgen-tests/tests/expectations/tests/c-unwind-abi-override-nightly.rs create mode 100644 bindgen-tests/tests/headers/c-unwind-abi-override-nightly.h diff --git a/CHANGELOG.md b/CHANGELOG.md index baa5cb204e..5f559a3fe1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -150,6 +150,8 @@ ## Added * new feature: `--override-abi` flag to override the ABI used by functions matching a regular expression. + * new feature: allow using the `C-unwind` ABI in `--override-abi` on nightly + rust. ## Changed diff --git a/bindgen-cli/options.rs b/bindgen-cli/options.rs index c186cfd92c..90f38cb2f9 100644 --- a/bindgen-cli/options.rs +++ b/bindgen-cli/options.rs @@ -570,7 +570,7 @@ where .help("Deduplicates extern blocks."), Arg::new("override-abi") .long("override-abi") - .help("Overrides the ABI of functions matching . The value must be of the shape : where can be one of C, stdcall, fastcall, thiscall, aapcs or win64.") + .help("Overrides the ABI of functions matching . The value must be of the shape = where can be one of C, stdcall, fastcall, thiscall, aapcs, win64 or C-unwind.") .value_name("override") .multiple_occurrences(true) .number_of_values(1), diff --git a/bindgen-tests/tests/expectations/tests/c-unwind-abi-override-nightly.rs b/bindgen-tests/tests/expectations/tests/c-unwind-abi-override-nightly.rs new file mode 100644 index 0000000000..6b34192fe4 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/c-unwind-abi-override-nightly.rs @@ -0,0 +1,18 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] +#![cfg(feature = "nightly")] +#![feature(abi_thiscall)] + +extern "C-unwind" { + pub fn foo(); +} +extern "C-unwind" { + pub fn bar(); +} +extern "C" { + pub fn baz(); +} diff --git a/bindgen-tests/tests/headers/c-unwind-abi-override-nightly.h b/bindgen-tests/tests/headers/c-unwind-abi-override-nightly.h new file mode 100644 index 0000000000..ac79a420c0 --- /dev/null +++ b/bindgen-tests/tests/headers/c-unwind-abi-override-nightly.h @@ -0,0 +1,5 @@ +// bindgen-flags: --override-abi="foo|bar=C-unwind" --rust-target=nightly --raw-line '#![cfg(feature = "nightly")]' --raw-line '#![feature(abi_thiscall)]' + +void foo(); +void bar(); +void baz(); diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 4e90102d36..d0c191360e 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -2483,6 +2483,9 @@ impl MethodCodegen for Method { ClangAbi::Known(Abi::Vectorcall) => { ctx.options().rust_features().vectorcall_abi } + ClangAbi::Known(Abi::CUnwind) => { + ctx.options().rust_features().c_unwind_abi + } _ => true, }; @@ -4009,6 +4012,12 @@ impl TryToRustTy for FunctionSig { warn!("Skipping function with vectorcall ABI that isn't supported by the configured Rust target"); Ok(proc_macro2::TokenStream::new()) } + ClangAbi::Known(Abi::CUnwind) + if !ctx.options().rust_features().c_unwind_abi => + { + warn!("Skipping function with C-unwind ABI that isn't supported by the configured Rust target"); + Ok(proc_macro2::TokenStream::new()) + } _ => Ok(quote! { unsafe extern #abi fn ( #( #arguments ),* ) #ret }), @@ -4120,6 +4129,12 @@ impl CodeGenerator for Function { warn!("Skipping function with vectorcall ABI that isn't supported by the configured Rust target"); return None; } + ClangAbi::Known(Abi::CUnwind) + if !ctx.options().rust_features().c_unwind_abi => + { + warn!("Skipping function with C-unwind ABI that isn't supported by the configured Rust target"); + return None; + } ClangAbi::Known(Abi::Win64) if signature.is_variadic() => { warn!("Skipping variadic function with Win64 ABI that isn't supported"); return None; diff --git a/bindgen/features.rs b/bindgen/features.rs index 4f05b9eb07..9f6535aa40 100644 --- a/bindgen/features.rs +++ b/bindgen/features.rs @@ -133,6 +133,7 @@ macro_rules! rust_target_base { /// Nightly rust /// * `thiscall` calling convention ([Tracking issue](https://github.com/rust-lang/rust/issues/42202)) /// * `vectorcall` calling convention (no tracking issue) + /// * `c_unwind` calling convention ([Tracking issue](https://github.com/rust-lang/rust/issues/74990)) => Nightly => nightly; ); } @@ -242,6 +243,7 @@ rust_feature_def!( Nightly { => thiscall_abi; => vectorcall_abi; + => c_unwind_abi; } ); @@ -291,7 +293,8 @@ mod test { f_nightly.maybe_uninit && f_nightly.repr_align && f_nightly.thiscall_abi && - f_nightly.vectorcall_abi + f_nightly.vectorcall_abi && + f_nightly.c_unwind_abi ); } diff --git a/bindgen/ir/function.rs b/bindgen/ir/function.rs index 8a70d60ac6..52346f6c88 100644 --- a/bindgen/ir/function.rs +++ b/bindgen/ir/function.rs @@ -188,6 +188,8 @@ pub enum Abi { Aapcs, /// The "win64" ABI. Win64, + /// The "C-unwind" ABI. + CUnwind, } impl FromStr for Abi { @@ -202,6 +204,7 @@ impl FromStr for Abi { "vectorcall" => Ok(Self::Vectorcall), "aapcs" => Ok(Self::Aapcs), "win64" => Ok(Self::Win64), + "C-unwind" => Ok(Self::CUnwind), _ => Err(format!("Invalid or unknown ABI {:?}", s)), } } @@ -217,6 +220,7 @@ impl std::fmt::Display for Abi { Self::Vectorcall => "vectorcall", Self::Aapcs => "aapcs", Self::Win64 => "win64", + Self::CUnwind => "C-unwind", }; s.fmt(f) From bae6170907dd27a1e854236e2cc7b4f637220977 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Fri, 4 Nov 2022 13:08:14 -0500 Subject: [PATCH 404/942] Clean the implementation of `Default` for `BindgenOptions` (#2332) * Clean the implementation of `Default` for `BindgenOptions` --- bindgen/lib.rs | 169 ++++++++++++++++++++++++++----------------------- 1 file changed, 90 insertions(+), 79 deletions(-) diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 10410734a1..3696c499c5 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -2204,103 +2204,114 @@ impl BindgenOptions { impl Default for BindgenOptions { fn default() -> BindgenOptions { + macro_rules! options { + ($($field:ident $(: $value:expr)?,)* --default-fields-- $($default_field:ident,)*) => { + BindgenOptions { + $($field $(: $value)*,)* + $($default_field: Default::default(),)* + } + }; + } + let rust_target = RustTarget::default(); - BindgenOptions { + options! { rust_target, rust_features: rust_target.into(), - blocklisted_types: Default::default(), - blocklisted_functions: Default::default(), - blocklisted_items: Default::default(), - blocklisted_files: Default::default(), - opaque_types: Default::default(), - rustfmt_path: Default::default(), - depfile: Default::default(), - allowlisted_types: Default::default(), - allowlisted_functions: Default::default(), - allowlisted_vars: Default::default(), - allowlisted_files: Default::default(), - default_enum_style: Default::default(), - bitfield_enums: Default::default(), - newtype_enums: Default::default(), - newtype_global_enums: Default::default(), - rustified_enums: Default::default(), - rustified_non_exhaustive_enums: Default::default(), - constified_enums: Default::default(), - constified_enum_modules: Default::default(), - default_macro_constant_type: Default::default(), - default_alias_style: Default::default(), - type_alias: Default::default(), - new_type_alias: Default::default(), - new_type_alias_deref: Default::default(), - default_non_copy_union_style: Default::default(), - bindgen_wrapper_union: Default::default(), - manually_drop_union: Default::default(), - builtins: false, - emit_ast: false, - emit_ir: false, - emit_ir_graphviz: None, layout_tests: true, - impl_debug: false, - impl_partialeq: false, derive_copy: true, derive_debug: true, - derive_default: false, - derive_hash: false, - derive_partialord: false, - derive_ord: false, - derive_partialeq: false, - derive_eq: false, - enable_cxx_namespaces: false, - enable_function_attribute_detection: false, - disable_name_namespacing: false, - disable_nested_struct_naming: false, - disable_header_comment: false, - use_core: false, - ctypes_prefix: None, anon_fields_prefix: DEFAULT_ANON_FIELDS_PREFIX.into(), convert_floats: true, - raw_lines: vec![], - module_lines: HashMap::default(), - clang_args: vec![], - input_headers: vec![], - input_header_contents: Default::default(), - parse_callbacks: Default::default(), codegen_config: CodegenConfig::all(), - conservative_inline_namespaces: false, generate_comments: true, - generate_inline_functions: false, allowlist_recursively: true, - generate_block: false, - objc_extern_crate: false, - block_extern_crate: false, enable_mangling: true, detect_include_paths: true, - fit_macro_constants: false, prepend_enum_name: true, - time_phases: false, record_matches: true, rustfmt_bindings: true, size_t_is_usize: true, - rustfmt_configuration_file: None, - no_partialeq_types: Default::default(), - no_copy_types: Default::default(), - no_debug_types: Default::default(), - no_default_types: Default::default(), - no_hash_types: Default::default(), - must_use_types: Default::default(), - array_pointers_in_arguments: false, - wasm_import_module_name: None, - dynamic_library_name: None, - dynamic_link_require_all: false, - respect_cxx_access_specs: false, - translate_enum_integer_types: false, - c_naming: false, - force_explicit_padding: false, - vtable_generation: false, - sort_semantically: false, - merge_extern_blocks: false, - abi_overrides: Default::default(), + + --default-fields-- + blocklisted_types, + blocklisted_functions, + blocklisted_items, + blocklisted_files, + opaque_types, + rustfmt_path, + depfile, + allowlisted_types, + allowlisted_functions, + allowlisted_vars, + allowlisted_files, + default_enum_style, + bitfield_enums, + newtype_enums, + newtype_global_enums, + rustified_enums, + rustified_non_exhaustive_enums, + constified_enums, + constified_enum_modules, + default_macro_constant_type, + default_alias_style, + type_alias, + new_type_alias, + new_type_alias_deref, + default_non_copy_union_style, + bindgen_wrapper_union, + manually_drop_union, + builtins, + emit_ast, + emit_ir, + emit_ir_graphviz, + impl_debug, + impl_partialeq, + derive_default, + derive_hash, + derive_partialord, + derive_ord, + derive_partialeq, + derive_eq, + enable_cxx_namespaces, + enable_function_attribute_detection, + disable_name_namespacing, + disable_nested_struct_naming, + disable_header_comment, + use_core, + ctypes_prefix, + raw_lines, + module_lines, + clang_args, + input_headers, + input_header_contents, + parse_callbacks, + conservative_inline_namespaces, + generate_inline_functions, + generate_block, + objc_extern_crate, + block_extern_crate, + fit_macro_constants, + time_phases, + rustfmt_configuration_file, + no_partialeq_types, + no_copy_types, + no_debug_types, + no_default_types, + no_hash_types, + must_use_types, + array_pointers_in_arguments, + wasm_import_module_name, + dynamic_library_name, + dynamic_link_require_all, + respect_cxx_access_specs, + translate_enum_integer_types, + c_naming, + force_explicit_padding, + vtable_generation, + sort_semantically, + merge_extern_blocks, + abi_overrides, } } } From e8ffb42ab66405ac56d04494a30e54b584f2d4dd Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Fri, 4 Nov 2022 15:22:49 -0500 Subject: [PATCH 405/942] Wrap `unsafe` function's bodies in `unsafe` blocks (#2266) This guarantees that bindings generated by `bindgen` compile even if the `unsafe_op_in_unsafe_fn` lint is denied. --- .github/workflows/bindgen.yml | 2 + CHANGELOG.md | 2 + .../tests/16-byte-alignment_1_0.rs | 4 +- .../expectations/tests/allowlist-file.rs | 2 +- .../tests/anon_struct_in_union_1_0.rs | 4 +- .../expectations/tests/anon_union_1_0.rs | 4 +- .../tests/attribute_warn_unused_result.rs | 2 +- ...rn_unused_result_no_attribute_detection.rs | 2 +- .../attribute_warn_unused_result_pre_1_27.rs | 2 +- .../tests/bindgen-union-inside-namespace.rs | 4 +- .../tests/bitfield-method-same-name.rs | 6 +- .../tests/expectations/tests/class.rs | 12 +- .../tests/expectations/tests/class_1_0.rs | 16 +-- .../tests/class_with_inner_struct_1_0.rs | 4 +- .../expectations/tests/class_with_typedef.rs | 8 +- .../expectations/tests/constructor-tp.rs | 8 +- .../tests/expectations/tests/constructors.rs | 24 ++-- .../expectations/tests/constructors_1_33.rs | 24 ++-- .../expectations/tests/deleted-function.rs | 12 +- .../tests/derive-bitfield-method-same-name.rs | 6 +- ...erive-hash-struct-with-incomplete-array.rs | 4 +- .../tests/derive-partialeq-union_1_0.rs | 4 +- .../tests/disable-untagged-union.rs | 4 +- .../tests/dynamic_loading_attributes.rs | 10 +- .../tests/dynamic_loading_required.rs | 14 +-- .../tests/dynamic_loading_simple.rs | 18 +-- .../tests/dynamic_loading_template.rs | 14 ++- .../tests/dynamic_loading_with_allowlist.rs | 16 ++- .../tests/dynamic_loading_with_blocklist.rs | 26 +++-- .../tests/dynamic_loading_with_class.rs | 24 ++-- .../expectations/tests/gen-constructors.rs | 8 +- .../expectations/tests/gen-destructors.rs | 2 +- .../expectations/tests/generate-inline.rs | 2 +- .../tests/incomplete-array-padding.rs | 4 +- .../tests/expectations/tests/issue-2019.rs | 4 +- .../tests/expectations/tests/issue-410.rs | 2 +- .../tests/expectations/tests/issue-447.rs | 14 ++- .../tests/expectations/tests/issue-493.rs | 4 +- .../tests/expectations/tests/issue-493_1_0.rs | 4 +- .../tests/issue-643-inner-struct.rs | 4 +- ...07-opaque-types-methods-being-generated.rs | 10 +- .../tests/jsval_layout_opaque_1_0.rs | 4 +- .../tests/expectations/tests/layout_align.rs | 4 +- .../expectations/tests/layout_eth_conf_1_0.rs | 4 +- .../tests/layout_large_align_field.rs | 4 +- .../expectations/tests/layout_mbuf_1_0.rs | 4 +- .../tests/libclang-5/objc_template.rs | 4 +- .../expectations/tests/libclang-9/class.rs | 12 +- .../tests/libclang-9/class_1_0.rs | 16 +-- ...erive-hash-struct-with-incomplete-array.rs | 4 +- .../libclang-9/incomplete-array-padding.rs | 4 +- .../libclang-9/issue-643-inner-struct.rs | 4 +- .../tests/libclang-9/layout_align.rs | 104 +++++++++--------- .../tests/libclang-9/objc_template.rs | 4 +- .../tests/libclang-9/zero-sized-array.rs | 4 +- .../expectations/tests/method-mangling.rs | 2 +- .../expectations/tests/objc_allowlist.rs | 8 +- .../expectations/tests/objc_blocklist.rs | 4 +- .../tests/expectations/tests/objc_category.rs | 4 +- .../tests/expectations/tests/objc_class.rs | 2 +- .../expectations/tests/objc_class_method.rs | 14 ++- .../tests/expectations/tests/objc_method.rs | 18 +-- .../expectations/tests/objc_method_clash.rs | 4 +- .../tests/objc_pointer_return_types.rs | 4 +- .../expectations/tests/objc_property_fnptr.rs | 4 +- .../tests/expectations/tests/parm-union.rs | 2 +- .../tests/expectations/tests/public-dtor.rs | 2 +- .../tests/struct_with_anon_union_1_0.rs | 4 +- .../struct_with_anon_unnamed_union_1_0.rs | 4 +- .../tests/struct_with_nesting_1_0.rs | 4 +- .../tests/expectations/tests/transform-op.rs | 4 +- .../tests/expectations/tests/typeref_1_0.rs | 4 +- .../expectations/tests/union-in-ns_1_0.rs | 4 +- .../expectations/tests/union_bitfield_1_0.rs | 4 +- .../tests/expectations/tests/union_dtor.rs | 2 +- .../expectations/tests/union_dtor_1_0.rs | 6 +- .../expectations/tests/union_fields_1_0.rs | 4 +- .../expectations/tests/union_template_1_0.rs | 4 +- .../tests/union_with_anon_struct_1_0.rs | 4 +- .../union_with_anon_struct_bitfield_1_0.rs | 4 +- .../tests/union_with_anon_union_1_0.rs | 4 +- .../union_with_anon_unnamed_struct_1_0.rs | 4 +- .../union_with_anon_unnamed_union_1_0.rs | 4 +- .../tests/union_with_big_member_1_0.rs | 4 +- .../tests/union_with_nesting_1_0.rs | 4 +- .../tests/union_with_non_copy_member.rs | 4 +- .../tests/expectations/tests/use-core_1_0.rs | 4 +- .../tests/expectations/tests/var-tracing.rs | 8 +- .../tests/wasm-constructor-returns.rs | 8 +- .../tests/win32-thiscall_nightly.rs | 4 +- .../tests/zero-size-array-align.rs | 4 +- .../expectations/tests/zero-sized-array.rs | 4 +- bindgen/codegen/dyngen.rs | 12 +- bindgen/codegen/mod.rs | 24 +++- 94 files changed, 401 insertions(+), 327 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index bc8477d503..f292d001aa 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -89,6 +89,8 @@ jobs: - name: Test expectations run: cd bindgen-tests/tests/expectations && cargo test + env: + RUSTFLAGS: "-D unsafe_op_in_unsafe_fn -D unused_unsafe" test: runs-on: ${{matrix.os}} diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f559a3fe1..506878c408 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -160,6 +160,8 @@ * the `ParseCallbacks`trait does not require to implement `UnwindSafe`. * the `Builder::parse_callbacks` method no longer overwrites previously added callbacks and composes them in a last-to-first manner. + * any generated rust code containing unsafe operations inside unsafe functions + is wrapped in unsafe blocks now. ## Removed diff --git a/bindgen-tests/tests/expectations/tests/16-byte-alignment_1_0.rs b/bindgen-tests/tests/expectations/tests/16-byte-alignment_1_0.rs index 369e2c75ea..ac6beee12d 100644 --- a/bindgen-tests/tests/expectations/tests/16-byte-alignment_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/16-byte-alignment_1_0.rs @@ -14,11 +14,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/allowlist-file.rs b/bindgen-tests/tests/expectations/tests/allowlist-file.rs index 3b72fb75eb..db35c22654 100644 --- a/bindgen-tests/tests/expectations/tests/allowlist-file.rs +++ b/bindgen-tests/tests/expectations/tests/allowlist-file.rs @@ -41,7 +41,7 @@ extern "C" { impl someClass { #[inline] pub unsafe fn somePublicMethod(&mut self, foo: ::std::os::raw::c_int) { - someClass_somePublicMethod(self, foo) + unsafe { someClass_somePublicMethod(self, foo) } } } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/anon_struct_in_union_1_0.rs b/bindgen-tests/tests/expectations/tests/anon_struct_in_union_1_0.rs index cbc5ac9b3f..782ebdb4bb 100644 --- a/bindgen-tests/tests/expectations/tests/anon_struct_in_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/anon_struct_in_union_1_0.rs @@ -14,11 +14,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/anon_union_1_0.rs b/bindgen-tests/tests/expectations/tests/anon_union_1_0.rs index 63273e608f..ea6456bd75 100644 --- a/bindgen-tests/tests/expectations/tests/anon_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/anon_union_1_0.rs @@ -14,11 +14,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } } impl ::std::default::Default for __BindgenUnionField { 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 12d5eab04b..f60d564a9a 100644 --- a/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result.rs +++ b/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result.rs @@ -38,7 +38,7 @@ impl Foo { &mut self, arg1: ::std::os::raw::c_int, ) -> ::std::os::raw::c_int { - Foo_foo(self, arg1) + unsafe { Foo_foo(self, arg1) } } } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_no_attribute_detection.rs b/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_no_attribute_detection.rs index d860acd1b4..317d52297c 100644 --- a/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_no_attribute_detection.rs +++ b/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_no_attribute_detection.rs @@ -36,7 +36,7 @@ impl Foo { &mut self, arg1: ::std::os::raw::c_int, ) -> ::std::os::raw::c_int { - Foo_foo(self, arg1) + unsafe { Foo_foo(self, arg1) } } } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_pre_1_27.rs b/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_pre_1_27.rs index d860acd1b4..317d52297c 100644 --- a/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_pre_1_27.rs +++ b/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_pre_1_27.rs @@ -36,7 +36,7 @@ impl Foo { &mut self, arg1: ::std::os::raw::c_int, ) -> ::std::os::raw::c_int { - Foo_foo(self, arg1) + unsafe { Foo_foo(self, arg1) } } } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/bindgen-union-inside-namespace.rs b/bindgen-tests/tests/expectations/tests/bindgen-union-inside-namespace.rs index 8a091cb5e2..e143e415eb 100644 --- a/bindgen-tests/tests/expectations/tests/bindgen-union-inside-namespace.rs +++ b/bindgen-tests/tests/expectations/tests/bindgen-union-inside-namespace.rs @@ -16,11 +16,11 @@ pub mod root { } #[inline] pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs b/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs index e9c1a76d1c..91efa9b9da 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs @@ -151,14 +151,14 @@ impl Foo { } #[inline] pub unsafe fn type_(&mut self) -> ::std::os::raw::c_char { - Foo_type(self) + unsafe { Foo_type(self) } } #[inline] pub unsafe fn set_type_(&mut self, c: ::std::os::raw::c_char) { - Foo_set_type_(self, c) + unsafe { Foo_set_type_(self, c) } } #[inline] pub unsafe fn set_type(&mut self, c: ::std::os::raw::c_char) { - Foo_set_type(self, c) + unsafe { Foo_set_type(self, c) } } } diff --git a/bindgen-tests/tests/expectations/tests/class.rs b/bindgen-tests/tests/expectations/tests/class.rs index 8542135b07..9b2158fedb 100644 --- a/bindgen-tests/tests/expectations/tests/class.rs +++ b/bindgen-tests/tests/expectations/tests/class.rs @@ -23,11 +23,11 @@ impl __IncompleteArrayField { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - ::std::slice::from_raw_parts(self.as_ptr(), len) + unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) + unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } } impl ::std::fmt::Debug for __IncompleteArrayField { @@ -490,18 +490,18 @@ extern "C" { impl RealAbstractionWithTonsOfMethods { #[inline] pub unsafe fn bar(&self) { - RealAbstractionWithTonsOfMethods_bar(self) + unsafe { RealAbstractionWithTonsOfMethods_bar(self) } } #[inline] pub unsafe fn bar1(&mut self) { - RealAbstractionWithTonsOfMethods_bar1(self) + unsafe { RealAbstractionWithTonsOfMethods_bar1(self) } } #[inline] pub unsafe fn bar2(&mut self, foo: ::std::os::raw::c_int) { - RealAbstractionWithTonsOfMethods_bar2(self, foo) + unsafe { RealAbstractionWithTonsOfMethods_bar2(self, foo) } } #[inline] pub unsafe fn sta() { - RealAbstractionWithTonsOfMethods_sta() + unsafe { RealAbstractionWithTonsOfMethods_sta() } } } diff --git a/bindgen-tests/tests/expectations/tests/class_1_0.rs b/bindgen-tests/tests/expectations/tests/class_1_0.rs index f6c3021eb3..5163bae9be 100644 --- a/bindgen-tests/tests/expectations/tests/class_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/class_1_0.rs @@ -23,11 +23,11 @@ impl __IncompleteArrayField { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - ::std::slice::from_raw_parts(self.as_ptr(), len) + unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) + unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } } impl ::std::fmt::Debug for __IncompleteArrayField { @@ -44,11 +44,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } } impl ::std::default::Default for __BindgenUnionField { @@ -541,18 +541,18 @@ impl Clone for RealAbstractionWithTonsOfMethods { impl RealAbstractionWithTonsOfMethods { #[inline] pub unsafe fn bar(&self) { - RealAbstractionWithTonsOfMethods_bar(self) + unsafe { RealAbstractionWithTonsOfMethods_bar(self) } } #[inline] pub unsafe fn bar1(&mut self) { - RealAbstractionWithTonsOfMethods_bar1(self) + unsafe { RealAbstractionWithTonsOfMethods_bar1(self) } } #[inline] pub unsafe fn bar2(&mut self, foo: ::std::os::raw::c_int) { - RealAbstractionWithTonsOfMethods_bar2(self, foo) + unsafe { RealAbstractionWithTonsOfMethods_bar2(self, foo) } } #[inline] pub unsafe fn sta() { - RealAbstractionWithTonsOfMethods_sta() + unsafe { RealAbstractionWithTonsOfMethods_sta() } } } diff --git a/bindgen-tests/tests/expectations/tests/class_with_inner_struct_1_0.rs b/bindgen-tests/tests/expectations/tests/class_with_inner_struct_1_0.rs index 42656079df..cf2122c625 100644 --- a/bindgen-tests/tests/expectations/tests/class_with_inner_struct_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/class_with_inner_struct_1_0.rs @@ -14,11 +14,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/class_with_typedef.rs b/bindgen-tests/tests/expectations/tests/class_with_typedef.rs index 65e86b2709..033b0c3c0b 100644 --- a/bindgen-tests/tests/expectations/tests/class_with_typedef.rs +++ b/bindgen-tests/tests/expectations/tests/class_with_typedef.rs @@ -93,19 +93,19 @@ impl Default for C { impl C { #[inline] pub unsafe fn method(&mut self, c: C_MyInt) { - C_method(self, c) + unsafe { C_method(self, c) } } #[inline] pub unsafe fn methodRef(&mut self, c: *mut C_MyInt) { - C_methodRef(self, c) + unsafe { C_methodRef(self, c) } } #[inline] pub unsafe fn complexMethodRef(&mut self, c: *mut C_Lookup) { - C_complexMethodRef(self, c) + unsafe { C_complexMethodRef(self, c) } } #[inline] pub unsafe fn anotherMethod(&mut self, c: AnotherInt) { - C_anotherMethod(self, c) + unsafe { C_anotherMethod(self, c) } } } #[repr(C)] diff --git a/bindgen-tests/tests/expectations/tests/constructor-tp.rs b/bindgen-tests/tests/expectations/tests/constructor-tp.rs index 4b339dc3c4..35c096d704 100644 --- a/bindgen-tests/tests/expectations/tests/constructor-tp.rs +++ b/bindgen-tests/tests/expectations/tests/constructor-tp.rs @@ -35,8 +35,10 @@ extern "C" { impl Bar { #[inline] pub unsafe fn new() -> Self { - let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); - Bar_Bar(__bindgen_tmp.as_mut_ptr()); - __bindgen_tmp.assume_init() + unsafe { + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + Bar_Bar(__bindgen_tmp.as_mut_ptr()); + __bindgen_tmp.assume_init() + } } } diff --git a/bindgen-tests/tests/expectations/tests/constructors.rs b/bindgen-tests/tests/expectations/tests/constructors.rs index 2f13effbef..615af667d0 100644 --- a/bindgen-tests/tests/expectations/tests/constructors.rs +++ b/bindgen-tests/tests/expectations/tests/constructors.rs @@ -37,15 +37,19 @@ extern "C" { impl TestOverload { #[inline] pub unsafe fn new(arg1: ::std::os::raw::c_int) -> Self { - let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); - TestOverload_TestOverload(__bindgen_tmp.as_mut_ptr(), arg1); - __bindgen_tmp.assume_init() + unsafe { + 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::MaybeUninit::uninit(); - TestOverload_TestOverload1(__bindgen_tmp.as_mut_ptr(), arg1); - __bindgen_tmp.assume_init() + unsafe { + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + TestOverload_TestOverload1(__bindgen_tmp.as_mut_ptr(), arg1); + __bindgen_tmp.assume_init() + } } } #[repr(C)] @@ -73,8 +77,10 @@ extern "C" { impl TestPublicNoArgs { #[inline] pub unsafe fn new() -> Self { - let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); - TestPublicNoArgs_TestPublicNoArgs(__bindgen_tmp.as_mut_ptr()); - __bindgen_tmp.assume_init() + unsafe { + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + TestPublicNoArgs_TestPublicNoArgs(__bindgen_tmp.as_mut_ptr()); + __bindgen_tmp.assume_init() + } } } diff --git a/bindgen-tests/tests/expectations/tests/constructors_1_33.rs b/bindgen-tests/tests/expectations/tests/constructors_1_33.rs index b5d333325b..c9818ccaab 100644 --- a/bindgen-tests/tests/expectations/tests/constructors_1_33.rs +++ b/bindgen-tests/tests/expectations/tests/constructors_1_33.rs @@ -39,15 +39,19 @@ 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 + unsafe { + let mut __bindgen_tmp = ::std::mem::uninitialized(); + TestOverload_TestOverload(&mut __bindgen_tmp, arg1); + __bindgen_tmp + } } #[inline] pub unsafe fn new1(arg1: f64) -> Self { - let mut __bindgen_tmp = ::std::mem::uninitialized(); - TestOverload_TestOverload1(&mut __bindgen_tmp, arg1); - __bindgen_tmp + unsafe { + let mut __bindgen_tmp = ::std::mem::uninitialized(); + TestOverload_TestOverload1(&mut __bindgen_tmp, arg1); + __bindgen_tmp + } } } #[repr(C)] @@ -75,8 +79,10 @@ extern "C" { impl TestPublicNoArgs { #[inline] pub unsafe fn new() -> Self { - let mut __bindgen_tmp = ::std::mem::uninitialized(); - TestPublicNoArgs_TestPublicNoArgs(&mut __bindgen_tmp); - __bindgen_tmp + unsafe { + let mut __bindgen_tmp = ::std::mem::uninitialized(); + TestPublicNoArgs_TestPublicNoArgs(&mut __bindgen_tmp); + __bindgen_tmp + } } } diff --git a/bindgen-tests/tests/expectations/tests/deleted-function.rs b/bindgen-tests/tests/expectations/tests/deleted-function.rs index 96967bb461..69a6961803 100644 --- a/bindgen-tests/tests/expectations/tests/deleted-function.rs +++ b/bindgen-tests/tests/expectations/tests/deleted-function.rs @@ -34,11 +34,11 @@ extern "C" { impl A { #[inline] pub unsafe fn inline_definition(&mut self) { - A_inline_definition(self) + unsafe { A_inline_definition(self) } } #[inline] pub unsafe fn out_of_line_definition(&mut self) { - A_out_of_line_definition(self) + unsafe { A_out_of_line_definition(self) } } } #[repr(C)] @@ -84,8 +84,10 @@ extern "C" { impl C { #[inline] pub unsafe fn new(arg1: *mut C) -> Self { - let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); - C_C(__bindgen_tmp.as_mut_ptr(), arg1); - __bindgen_tmp.assume_init() + unsafe { + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + C_C(__bindgen_tmp.as_mut_ptr(), arg1); + __bindgen_tmp.assume_init() + } } } diff --git a/bindgen-tests/tests/expectations/tests/derive-bitfield-method-same-name.rs b/bindgen-tests/tests/expectations/tests/derive-bitfield-method-same-name.rs index ea6621dd1c..97a539d91d 100644 --- a/bindgen-tests/tests/expectations/tests/derive-bitfield-method-same-name.rs +++ b/bindgen-tests/tests/expectations/tests/derive-bitfield-method-same-name.rs @@ -202,14 +202,14 @@ impl Foo { } #[inline] pub unsafe fn type_(&mut self) -> ::std::os::raw::c_char { - Foo_type(self) + unsafe { Foo_type(self) } } #[inline] pub unsafe fn set_type_(&mut self, c: ::std::os::raw::c_char) { - Foo_set_type_(self, c) + unsafe { Foo_set_type_(self, c) } } #[inline] pub unsafe fn set_type(&mut self, c: ::std::os::raw::c_char) { - Foo_set_type(self, c) + unsafe { Foo_set_type(self, c) } } } diff --git a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs index 06c8da1bad..067aab36f8 100644 --- a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs +++ b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs @@ -23,11 +23,11 @@ impl __IncompleteArrayField { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - ::std::slice::from_raw_parts(self.as_ptr(), len) + unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) + unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } } impl ::std::fmt::Debug for __IncompleteArrayField { diff --git a/bindgen-tests/tests/expectations/tests/derive-partialeq-union_1_0.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-union_1_0.rs index a53b9ba8e6..604aa28d44 100644 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/derive-partialeq-union_1_0.rs @@ -14,11 +14,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/disable-untagged-union.rs b/bindgen-tests/tests/expectations/tests/disable-untagged-union.rs index 515f496b87..78cbe47fa4 100644 --- a/bindgen-tests/tests/expectations/tests/disable-untagged-union.rs +++ b/bindgen-tests/tests/expectations/tests/disable-untagged-union.rs @@ -14,11 +14,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_attributes.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_attributes.rs index c834752e3c..5ad4b23f7b 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_attributes.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_attributes.rs @@ -20,7 +20,7 @@ impl TestLib { P: AsRef<::std::ffi::OsStr>, { let library = ::libloading::Library::new(path)?; - Self::from_library(library) + unsafe { Self::from_library(library) } } pub unsafe fn from_library( library: L, @@ -29,8 +29,8 @@ impl TestLib { L: Into<::libloading::Library>, { let __library = library.into(); - let foo = __library.get(b"foo\0").map(|sym| *sym)?; - let baz = __library.get(b"baz\0").map(|sym| *sym)?; + let foo = unsafe { __library.get(b"foo\0") }.map(|sym| *sym)?; + let baz = unsafe { __library.get(b"baz\0") }.map(|sym| *sym)?; Ok(TestLib { __library, foo, @@ -48,9 +48,9 @@ impl TestLib { x: ::std::os::raw::c_int, y: ::std::os::raw::c_int, ) -> ::std::os::raw::c_int { - (self.foo)(x, y) + unsafe { (self.foo)(x, y) } } pub unsafe fn baz(&self) -> ::std::os::raw::c_int { - (self.baz)() + unsafe { (self.baz)() } } } diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_required.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_required.rs index e46ffd49e0..723f44ad09 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_required.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_required.rs @@ -23,7 +23,7 @@ impl TestLib { P: AsRef<::std::ffi::OsStr>, { let library = ::libloading::Library::new(path)?; - Self::from_library(library) + unsafe { Self::from_library(library) } } pub unsafe fn from_library( library: L, @@ -32,9 +32,9 @@ impl TestLib { L: Into<::libloading::Library>, { let __library = library.into(); - let foo = __library.get(b"foo\0").map(|sym| *sym)?; - let bar = __library.get(b"bar\0").map(|sym| *sym)?; - let baz = __library.get(b"baz\0").map(|sym| *sym)?; + let foo = unsafe { __library.get(b"foo\0") }.map(|sym| *sym)?; + let bar = unsafe { __library.get(b"bar\0") }.map(|sym| *sym)?; + let baz = unsafe { __library.get(b"baz\0") }.map(|sym| *sym)?; Ok(TestLib { __library, foo, @@ -47,15 +47,15 @@ impl TestLib { x: ::std::os::raw::c_int, y: ::std::os::raw::c_int, ) -> ::std::os::raw::c_int { - (self.foo)(x, y) + unsafe { (self.foo)(x, y) } } pub unsafe fn bar( &self, x: *mut ::std::os::raw::c_void, ) -> ::std::os::raw::c_int { - (self.bar)(x) + unsafe { (self.bar)(x) } } pub unsafe fn baz(&self) -> ::std::os::raw::c_int { - (self.baz)() + unsafe { (self.baz)() } } } diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_simple.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_simple.rs index cae5bd6937..5864ba0a8d 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_simple.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_simple.rs @@ -32,7 +32,7 @@ impl TestLib { P: AsRef<::std::ffi::OsStr>, { let library = ::libloading::Library::new(path)?; - Self::from_library(library) + unsafe { Self::from_library(library) } } pub unsafe fn from_library( library: L, @@ -41,9 +41,9 @@ impl TestLib { L: Into<::libloading::Library>, { let __library = library.into(); - let foo = __library.get(b"foo\0").map(|sym| *sym); - let bar = __library.get(b"bar\0").map(|sym| *sym); - let baz = __library.get(b"baz\0").map(|sym| *sym); + let foo = unsafe { __library.get(b"foo\0") }.map(|sym| *sym); + let bar = unsafe { __library.get(b"bar\0") }.map(|sym| *sym); + let baz = unsafe { __library.get(b"baz\0") }.map(|sym| *sym); Ok(TestLib { __library, foo, @@ -56,15 +56,19 @@ impl TestLib { x: ::std::os::raw::c_int, y: ::std::os::raw::c_int, ) -> ::std::os::raw::c_int { - (self.foo.as_ref().expect("Expected function, got error."))(x, y) + unsafe { + (self.foo.as_ref().expect("Expected function, got error."))(x, y) + } } pub unsafe fn bar( &self, x: *mut ::std::os::raw::c_void, ) -> ::std::os::raw::c_int { - (self.bar.as_ref().expect("Expected function, got error."))(x) + unsafe { + (self.bar.as_ref().expect("Expected function, got error."))(x) + } } pub unsafe fn baz(&self) -> ::std::os::raw::c_int { - (self.baz.as_ref().expect("Expected function, got error."))() + unsafe { (self.baz.as_ref().expect("Expected function, got error."))() } } } diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_template.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_template.rs index 06e67ed791..6c9ea27496 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_template.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_template.rs @@ -20,7 +20,7 @@ impl TestLib { P: AsRef<::std::ffi::OsStr>, { let library = ::libloading::Library::new(path)?; - Self::from_library(library) + unsafe { Self::from_library(library) } } pub unsafe fn from_library( library: L, @@ -29,8 +29,8 @@ impl TestLib { L: Into<::libloading::Library>, { let __library = library.into(); - let foo = __library.get(b"foo\0").map(|sym| *sym); - let foo1 = __library.get(b"foo1\0").map(|sym| *sym); + let foo = unsafe { __library.get(b"foo\0") }.map(|sym| *sym); + let foo1 = unsafe { __library.get(b"foo1\0") }.map(|sym| *sym); Ok(TestLib { __library, foo, @@ -41,9 +41,13 @@ impl TestLib { &self, x: ::std::os::raw::c_int, ) -> ::std::os::raw::c_int { - (self.foo.as_ref().expect("Expected function, got error."))(x) + unsafe { + (self.foo.as_ref().expect("Expected function, got error."))(x) + } } pub unsafe fn foo1(&self, x: f32) -> f32 { - (self.foo1.as_ref().expect("Expected function, got error."))(x) + unsafe { + (self.foo1.as_ref().expect("Expected function, got error."))(x) + } } } diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_allowlist.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_allowlist.rs index 97bb67abdc..c9b2471419 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_allowlist.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_allowlist.rs @@ -34,7 +34,7 @@ impl TestLib { P: AsRef<::std::ffi::OsStr>, { let library = ::libloading::Library::new(path)?; - Self::from_library(library) + unsafe { Self::from_library(library) } } pub unsafe fn from_library( library: L, @@ -43,9 +43,9 @@ impl TestLib { L: Into<::libloading::Library>, { let __library = library.into(); - let foo = __library.get(b"foo\0").map(|sym| *sym); - let baz = __library.get(b"baz\0").map(|sym| *sym); - let bazz = __library.get(b"bazz\0").map(|sym| *sym); + let foo = unsafe { __library.get(b"foo\0") }.map(|sym| *sym); + let baz = unsafe { __library.get(b"baz\0") }.map(|sym| *sym); + let bazz = unsafe { __library.get(b"bazz\0") }.map(|sym| *sym); Ok(TestLib { __library, foo, @@ -57,12 +57,16 @@ impl TestLib { &self, x: *mut ::std::os::raw::c_void, ) -> ::std::os::raw::c_int { - (self.foo.as_ref().expect("Expected function, got error."))(x) + unsafe { + (self.foo.as_ref().expect("Expected function, got error."))(x) + } } pub unsafe fn baz( &self, x: *mut ::std::os::raw::c_void, ) -> ::std::os::raw::c_int { - (self.baz.as_ref().expect("Expected function, got error."))(x) + unsafe { + (self.baz.as_ref().expect("Expected function, got error."))(x) + } } } diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_blocklist.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_blocklist.rs index af482ad938..30f2be1d1e 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_blocklist.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_blocklist.rs @@ -46,17 +46,19 @@ extern "C" { impl X { #[inline] pub unsafe fn some_function(&mut self) { - X_some_function(self) + unsafe { X_some_function(self) } } #[inline] pub unsafe fn some_other_function(&mut self) { - X_some_other_function(self) + unsafe { X_some_other_function(self) } } #[inline] pub unsafe fn new(x: ::std::os::raw::c_int) -> Self { - let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); - X_X(__bindgen_tmp.as_mut_ptr(), x); - __bindgen_tmp.assume_init() + unsafe { + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + X_X(__bindgen_tmp.as_mut_ptr(), x); + __bindgen_tmp.assume_init() + } } } extern crate libloading; @@ -81,7 +83,7 @@ impl TestLib { P: AsRef<::std::ffi::OsStr>, { let library = ::libloading::Library::new(path)?; - Self::from_library(library) + unsafe { Self::from_library(library) } } pub unsafe fn from_library( library: L, @@ -90,8 +92,8 @@ impl TestLib { L: Into<::libloading::Library>, { let __library = library.into(); - let foo = __library.get(b"foo\0").map(|sym| *sym); - let bar = __library.get(b"bar\0").map(|sym| *sym); + let foo = unsafe { __library.get(b"foo\0") }.map(|sym| *sym); + let bar = unsafe { __library.get(b"bar\0") }.map(|sym| *sym); Ok(TestLib { __library, foo, @@ -102,12 +104,16 @@ impl TestLib { &self, x: *mut ::std::os::raw::c_void, ) -> ::std::os::raw::c_int { - (self.foo.as_ref().expect("Expected function, got error."))(x) + unsafe { + (self.foo.as_ref().expect("Expected function, got error."))(x) + } } pub unsafe fn bar( &self, x: *mut ::std::os::raw::c_void, ) -> ::std::os::raw::c_int { - (self.bar.as_ref().expect("Expected function, got error."))(x) + unsafe { + (self.bar.as_ref().expect("Expected function, got error."))(x) + } } } diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs index 514cff7317..d928751892 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs @@ -46,17 +46,19 @@ extern "C" { impl A { #[inline] pub unsafe fn some_function(&mut self) { - A_some_function(self) + unsafe { A_some_function(self) } } #[inline] pub unsafe fn some_other_function(&mut self) { - A_some_other_function(self) + unsafe { A_some_other_function(self) } } #[inline] pub unsafe fn new(x: ::std::os::raw::c_int) -> Self { - let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); - A_A(__bindgen_tmp.as_mut_ptr(), x); - __bindgen_tmp.assume_init() + unsafe { + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + A_A(__bindgen_tmp.as_mut_ptr(), x); + __bindgen_tmp.assume_init() + } } } extern crate libloading; @@ -76,7 +78,7 @@ impl TestLib { P: AsRef<::std::ffi::OsStr>, { let library = ::libloading::Library::new(path)?; - Self::from_library(library) + unsafe { Self::from_library(library) } } pub unsafe fn from_library( library: L, @@ -85,8 +87,8 @@ impl TestLib { L: Into<::libloading::Library>, { let __library = library.into(); - let foo = __library.get(b"foo\0").map(|sym| *sym); - let bar = __library.get(b"bar\0").map(|sym| *sym); + let foo = unsafe { __library.get(b"foo\0") }.map(|sym| *sym); + let bar = unsafe { __library.get(b"bar\0") }.map(|sym| *sym); Ok(TestLib { __library, foo, @@ -97,9 +99,11 @@ impl TestLib { &self, x: *mut ::std::os::raw::c_void, ) -> ::std::os::raw::c_int { - (self.foo.as_ref().expect("Expected function, got error."))(x) + unsafe { + (self.foo.as_ref().expect("Expected function, got error."))(x) + } } pub unsafe fn bar(&self) -> () { - (self.bar.as_ref().expect("Expected function, got error."))() + unsafe { (self.bar.as_ref().expect("Expected function, got error."))() } } } diff --git a/bindgen-tests/tests/expectations/tests/gen-constructors.rs b/bindgen-tests/tests/expectations/tests/gen-constructors.rs index 89b8637954..59af8ef30c 100644 --- a/bindgen-tests/tests/expectations/tests/gen-constructors.rs +++ b/bindgen-tests/tests/expectations/tests/gen-constructors.rs @@ -30,8 +30,10 @@ extern "C" { impl Foo { #[inline] pub unsafe fn new(a: ::std::os::raw::c_int) -> Self { - let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); - Foo_Foo(__bindgen_tmp.as_mut_ptr(), a); - __bindgen_tmp.assume_init() + unsafe { + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + Foo_Foo(__bindgen_tmp.as_mut_ptr(), a); + __bindgen_tmp.assume_init() + } } } diff --git a/bindgen-tests/tests/expectations/tests/gen-destructors.rs b/bindgen-tests/tests/expectations/tests/gen-destructors.rs index 1711f76d0c..4109520987 100644 --- a/bindgen-tests/tests/expectations/tests/gen-destructors.rs +++ b/bindgen-tests/tests/expectations/tests/gen-destructors.rs @@ -38,6 +38,6 @@ extern "C" { impl Foo { #[inline] pub unsafe fn destruct(&mut self) { - Foo_Foo_destructor(self) + unsafe { Foo_Foo_destructor(self) } } } diff --git a/bindgen-tests/tests/expectations/tests/generate-inline.rs b/bindgen-tests/tests/expectations/tests/generate-inline.rs index 3cb865a4d7..9ac66b0f7b 100644 --- a/bindgen-tests/tests/expectations/tests/generate-inline.rs +++ b/bindgen-tests/tests/expectations/tests/generate-inline.rs @@ -30,7 +30,7 @@ extern "C" { impl Foo { #[inline] pub unsafe fn bar() -> ::std::os::raw::c_int { - Foo_bar() + unsafe { Foo_bar() } } } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs b/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs index 18061ea12a..d1ae7ebd2b 100644 --- a/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs +++ b/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs @@ -109,11 +109,11 @@ impl __IncompleteArrayField { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - ::std::slice::from_raw_parts(self.as_ptr(), len) + unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) + unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } } impl ::std::fmt::Debug for __IncompleteArrayField { diff --git a/bindgen-tests/tests/expectations/tests/issue-2019.rs b/bindgen-tests/tests/expectations/tests/issue-2019.rs index 294e9f0e83..89f1ac6268 100644 --- a/bindgen-tests/tests/expectations/tests/issue-2019.rs +++ b/bindgen-tests/tests/expectations/tests/issue-2019.rs @@ -38,7 +38,7 @@ extern "C" { impl A { #[inline] pub unsafe fn make() -> A { - make() + unsafe { make() } } } #[repr(C)] @@ -74,6 +74,6 @@ extern "C" { impl B { #[inline] pub unsafe fn make() -> B { - make1() + unsafe { make1() } } } diff --git a/bindgen-tests/tests/expectations/tests/issue-410.rs b/bindgen-tests/tests/expectations/tests/issue-410.rs index ad7463c266..739ddf29ce 100644 --- a/bindgen-tests/tests/expectations/tests/issue-410.rs +++ b/bindgen-tests/tests/expectations/tests/issue-410.rs @@ -37,7 +37,7 @@ pub mod root { impl Value { #[inline] pub unsafe fn a(&mut self, arg1: root::JSWhyMagic) { - Value_a(self, arg1) + unsafe { Value_a(self, arg1) } } } } diff --git a/bindgen-tests/tests/expectations/tests/issue-447.rs b/bindgen-tests/tests/expectations/tests/issue-447.rs index 949db73b79..0a6dd5e6b8 100644 --- a/bindgen-tests/tests/expectations/tests/issue-447.rs +++ b/bindgen-tests/tests/expectations/tests/issue-447.rs @@ -65,12 +65,14 @@ pub mod root { pub unsafe fn new( arg1: root::mozilla::detail::GuardObjectNotifier, ) -> Self { - let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); - JSAutoCompartment_JSAutoCompartment( - __bindgen_tmp.as_mut_ptr(), - arg1, - ); - __bindgen_tmp.assume_init() + unsafe { + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + JSAutoCompartment_JSAutoCompartment( + __bindgen_tmp.as_mut_ptr(), + arg1, + ); + __bindgen_tmp.assume_init() + } } } } diff --git a/bindgen-tests/tests/expectations/tests/issue-493.rs b/bindgen-tests/tests/expectations/tests/issue-493.rs index 61c7f7929e..019982dbb9 100644 --- a/bindgen-tests/tests/expectations/tests/issue-493.rs +++ b/bindgen-tests/tests/expectations/tests/issue-493.rs @@ -14,11 +14,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/issue-493_1_0.rs b/bindgen-tests/tests/expectations/tests/issue-493_1_0.rs index 1a0131c327..12a1e7a267 100644 --- a/bindgen-tests/tests/expectations/tests/issue-493_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/issue-493_1_0.rs @@ -14,11 +14,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/issue-643-inner-struct.rs b/bindgen-tests/tests/expectations/tests/issue-643-inner-struct.rs index b69aa16ef3..03162c4c9f 100644 --- a/bindgen-tests/tests/expectations/tests/issue-643-inner-struct.rs +++ b/bindgen-tests/tests/expectations/tests/issue-643-inner-struct.rs @@ -23,11 +23,11 @@ impl __IncompleteArrayField { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - ::std::slice::from_raw_parts(self.as_ptr(), len) + unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) + unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } } impl ::std::fmt::Debug for __IncompleteArrayField { diff --git a/bindgen-tests/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs b/bindgen-tests/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs index f886952822..dc0b7f08d9 100644 --- a/bindgen-tests/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs +++ b/bindgen-tests/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs @@ -89,13 +89,15 @@ extern "C" { impl Opaque { #[inline] pub unsafe fn eleven_out_of_ten(&mut self) -> SuchWow { - Opaque_eleven_out_of_ten(self) + unsafe { Opaque_eleven_out_of_ten(self) } } #[inline] pub unsafe fn new(pup: Pupper) -> Self { - let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); - Opaque_Opaque(__bindgen_tmp.as_mut_ptr(), pup); - __bindgen_tmp.assume_init() + unsafe { + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + Opaque_Opaque(__bindgen_tmp.as_mut_ptr(), pup); + __bindgen_tmp.assume_init() + } } } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs index b439499355..32af443f29 100644 --- a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs @@ -100,11 +100,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/layout_align.rs b/bindgen-tests/tests/expectations/tests/layout_align.rs index 466e76862c..718a8024a6 100644 --- a/bindgen-tests/tests/expectations/tests/layout_align.rs +++ b/bindgen-tests/tests/expectations/tests/layout_align.rs @@ -109,11 +109,11 @@ impl __IncompleteArrayField { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - ::std::slice::from_raw_parts(self.as_ptr(), len) + unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) + unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } } impl ::std::fmt::Debug for __IncompleteArrayField { diff --git a/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs b/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs index d7fa0a634a..de814146e1 100644 --- a/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs @@ -100,11 +100,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } } impl ::std::default::Default for __BindgenUnionField { 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 075ef46ae4..f0b312a037 100644 --- a/bindgen-tests/tests/expectations/tests/layout_large_align_field.rs +++ b/bindgen-tests/tests/expectations/tests/layout_large_align_field.rs @@ -23,11 +23,11 @@ impl __IncompleteArrayField { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - ::std::slice::from_raw_parts(self.as_ptr(), len) + unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) + unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } } impl ::std::fmt::Debug for __IncompleteArrayField { diff --git a/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs b/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs index 90f7ed09b2..3788d3d0a4 100644 --- a/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs @@ -100,11 +100,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/objc_template.rs b/bindgen-tests/tests/expectations/tests/libclang-5/objc_template.rs index 53caa661c6..85ca160107 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-5/objc_template.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-5/objc_template.rs @@ -30,7 +30,7 @@ pub trait IFoo: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - msg_send!(*self, get) + unsafe { msg_send!(*self, get) } } } #[repr(transparent)] @@ -59,6 +59,6 @@ pub trait IFooMultiGeneric: where ::Target: objc::Message + Sized, { - msg_send!(*self, objectForKey: key) + unsafe { msg_send!(*self, objectForKey: key) } } } diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/class.rs b/bindgen-tests/tests/expectations/tests/libclang-9/class.rs index 0d64a9ffc8..7d732bb09a 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/class.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/class.rs @@ -23,11 +23,11 @@ impl __IncompleteArrayField { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - ::std::slice::from_raw_parts(self.as_ptr(), len) + unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) + unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } } impl ::std::fmt::Debug for __IncompleteArrayField { @@ -674,18 +674,18 @@ extern "C" { impl RealAbstractionWithTonsOfMethods { #[inline] pub unsafe fn bar(&self) { - RealAbstractionWithTonsOfMethods_bar(self) + unsafe { RealAbstractionWithTonsOfMethods_bar(self) } } #[inline] pub unsafe fn bar1(&mut self) { - RealAbstractionWithTonsOfMethods_bar1(self) + unsafe { RealAbstractionWithTonsOfMethods_bar1(self) } } #[inline] pub unsafe fn bar2(&mut self, foo: ::std::os::raw::c_int) { - RealAbstractionWithTonsOfMethods_bar2(self, foo) + unsafe { RealAbstractionWithTonsOfMethods_bar2(self, foo) } } #[inline] pub unsafe fn sta() { - RealAbstractionWithTonsOfMethods_sta() + unsafe { RealAbstractionWithTonsOfMethods_sta() } } } diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/class_1_0.rs b/bindgen-tests/tests/expectations/tests/libclang-9/class_1_0.rs index e8c2e07798..4364c69a74 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/class_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/class_1_0.rs @@ -23,11 +23,11 @@ impl __IncompleteArrayField { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - ::std::slice::from_raw_parts(self.as_ptr(), len) + unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) + unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } } impl ::std::fmt::Debug for __IncompleteArrayField { @@ -44,11 +44,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } } impl ::std::default::Default for __BindgenUnionField { @@ -725,18 +725,18 @@ impl Clone for RealAbstractionWithTonsOfMethods { impl RealAbstractionWithTonsOfMethods { #[inline] pub unsafe fn bar(&self) { - RealAbstractionWithTonsOfMethods_bar(self) + unsafe { RealAbstractionWithTonsOfMethods_bar(self) } } #[inline] pub unsafe fn bar1(&mut self) { - RealAbstractionWithTonsOfMethods_bar1(self) + unsafe { RealAbstractionWithTonsOfMethods_bar1(self) } } #[inline] pub unsafe fn bar2(&mut self, foo: ::std::os::raw::c_int) { - RealAbstractionWithTonsOfMethods_bar2(self, foo) + unsafe { RealAbstractionWithTonsOfMethods_bar2(self, foo) } } #[inline] pub unsafe fn sta() { - RealAbstractionWithTonsOfMethods_sta() + unsafe { RealAbstractionWithTonsOfMethods_sta() } } } diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs b/bindgen-tests/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs index 2af22cc4c9..17154e4d1a 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs @@ -23,11 +23,11 @@ impl __IncompleteArrayField { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - ::std::slice::from_raw_parts(self.as_ptr(), len) + unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) + unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } } impl ::std::fmt::Debug for __IncompleteArrayField { diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/incomplete-array-padding.rs b/bindgen-tests/tests/expectations/tests/libclang-9/incomplete-array-padding.rs index 1de963bf0f..441c3f69b2 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/incomplete-array-padding.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/incomplete-array-padding.rs @@ -109,11 +109,11 @@ impl __IncompleteArrayField { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - ::std::slice::from_raw_parts(self.as_ptr(), len) + unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) + unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } } impl ::std::fmt::Debug for __IncompleteArrayField { diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs b/bindgen-tests/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs index ab402cfb7c..4161c6dbfc 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs @@ -23,11 +23,11 @@ impl __IncompleteArrayField { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - ::std::slice::from_raw_parts(self.as_ptr(), len) + unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) + unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } } impl ::std::fmt::Debug for __IncompleteArrayField { diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/layout_align.rs b/bindgen-tests/tests/expectations/tests/libclang-9/layout_align.rs index f6a32704f1..df940912b3 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/layout_align.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/layout_align.rs @@ -109,11 +109,11 @@ impl __IncompleteArrayField { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - ::std::slice::from_raw_parts(self.as_ptr(), len) + unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) + unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } } impl ::std::fmt::Debug for __IncompleteArrayField { @@ -151,56 +151,56 @@ fn bindgen_test_layout_rte_kni_fifo() { concat!("Alignment of ", stringify!(rte_kni_fifo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).write) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_fifo), - "::", - stringify!(write) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).read) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_fifo), - "::", - stringify!(read) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_fifo), - "::", - stringify!(len) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).elem_size) as usize - ptr as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_fifo), - "::", - stringify!(elem_size) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).buffer) as usize - ptr as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_fifo), - "::", - stringify!(buffer) - ) + unsafe { ::std::ptr::addr_of!((*ptr).write) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_fifo), + "::", + stringify!(write) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).read) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_fifo), + "::", + stringify!(read) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_fifo), + "::", + stringify!(len) + ) + ); + assert_eq!( + unsafe { + ::std::ptr::addr_of!((*ptr).elem_size) as usize - ptr as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_fifo), + "::", + stringify!(elem_size) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).buffer) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_fifo), + "::", + stringify!(buffer) + ) ); } impl Default for rte_kni_fifo { diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/objc_template.rs b/bindgen-tests/tests/expectations/tests/libclang-9/objc_template.rs index 3c615035ce..90d9d9931b 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/objc_template.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/objc_template.rs @@ -30,7 +30,7 @@ pub trait IFoo: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - msg_send!(*self, get) + unsafe { msg_send!(*self, get) } } } #[repr(transparent)] @@ -59,6 +59,6 @@ pub trait IFooMultiGeneric: where ::Target: objc::Message + Sized, { - msg_send!(*self, objectForKey: key) + unsafe { msg_send!(*self, objectForKey: key) } } } diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/zero-sized-array.rs b/bindgen-tests/tests/expectations/tests/libclang-9/zero-sized-array.rs index 3066fac40a..71a2d6d6aa 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/zero-sized-array.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/zero-sized-array.rs @@ -23,11 +23,11 @@ impl __IncompleteArrayField { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - ::std::slice::from_raw_parts(self.as_ptr(), len) + unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) + unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } } impl ::std::fmt::Debug for __IncompleteArrayField { diff --git a/bindgen-tests/tests/expectations/tests/method-mangling.rs b/bindgen-tests/tests/expectations/tests/method-mangling.rs index e4627ac8a7..5f8a847452 100644 --- a/bindgen-tests/tests/expectations/tests/method-mangling.rs +++ b/bindgen-tests/tests/expectations/tests/method-mangling.rs @@ -30,6 +30,6 @@ extern "C" { impl Foo { #[inline] pub unsafe fn type_(&mut self) -> ::std::os::raw::c_int { - Foo_type(self) + unsafe { Foo_type(self) } } } diff --git a/bindgen-tests/tests/expectations/tests/objc_allowlist.rs b/bindgen-tests/tests/expectations/tests/objc_allowlist.rs index 370cab9332..76971a5f38 100644 --- a/bindgen-tests/tests/expectations/tests/objc_allowlist.rs +++ b/bindgen-tests/tests/expectations/tests/objc_allowlist.rs @@ -14,13 +14,13 @@ pub trait PSomeProtocol: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - msg_send!(*self, protocolMethod) + unsafe { msg_send!(*self, protocolMethod) } } unsafe fn protocolClassMethod() where ::Target: objc::Message + Sized, { - msg_send!(class!(SomeProtocol), protocolClassMethod) + unsafe { msg_send!(class!(SomeProtocol), protocolClassMethod) } } } #[repr(transparent)] @@ -45,13 +45,13 @@ pub trait IAllowlistMe: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - msg_send!(*self, method) + unsafe { msg_send!(*self, method) } } unsafe fn classMethod() where ::Target: objc::Message + Sized, { - msg_send!(class!(AllowlistMe), classMethod) + unsafe { msg_send!(class!(AllowlistMe), classMethod) } } } impl AllowlistMe_InterestingCategory for AllowlistMe {} diff --git a/bindgen-tests/tests/expectations/tests/objc_blocklist.rs b/bindgen-tests/tests/expectations/tests/objc_blocklist.rs index 7d5d19b083..f16eb0f929 100644 --- a/bindgen-tests/tests/expectations/tests/objc_blocklist.rs +++ b/bindgen-tests/tests/expectations/tests/objc_blocklist.rs @@ -31,12 +31,12 @@ pub trait ISomeClass: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - msg_send!(*self, ambiguouslyBlockedMethod) + unsafe { msg_send!(*self, ambiguouslyBlockedMethod) } } unsafe fn instanceMethod(&self) where ::Target: objc::Message + Sized, { - msg_send!(*self, instanceMethod) + unsafe { msg_send!(*self, instanceMethod) } } } diff --git a/bindgen-tests/tests/expectations/tests/objc_category.rs b/bindgen-tests/tests/expectations/tests/objc_category.rs index 9d60233bed..f05c2bbd9b 100644 --- a/bindgen-tests/tests/expectations/tests/objc_category.rs +++ b/bindgen-tests/tests/expectations/tests/objc_category.rs @@ -30,7 +30,7 @@ pub trait IFoo: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - msg_send!(*self, method) + unsafe { msg_send!(*self, method) } } } impl Foo_BarCategory for Foo {} @@ -39,6 +39,6 @@ pub trait Foo_BarCategory: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - msg_send!(*self, categoryMethod) + unsafe { msg_send!(*self, categoryMethod) } } } diff --git a/bindgen-tests/tests/expectations/tests/objc_class.rs b/bindgen-tests/tests/expectations/tests/objc_class.rs index b322bddcb6..0fe8e254c3 100644 --- a/bindgen-tests/tests/expectations/tests/objc_class.rs +++ b/bindgen-tests/tests/expectations/tests/objc_class.rs @@ -33,6 +33,6 @@ pub trait IFoo: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - msg_send!(*self, method) + unsafe { msg_send!(*self, method) } } } diff --git a/bindgen-tests/tests/expectations/tests/objc_class_method.rs b/bindgen-tests/tests/expectations/tests/objc_class_method.rs index 29e70256ff..796698d271 100644 --- a/bindgen-tests/tests/expectations/tests/objc_class_method.rs +++ b/bindgen-tests/tests/expectations/tests/objc_class_method.rs @@ -30,31 +30,31 @@ pub trait IFoo: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - msg_send!(class!(Foo), method) + unsafe { msg_send!(class!(Foo), method) } } unsafe fn methodWithInt_(foo: ::std::os::raw::c_int) where ::Target: objc::Message + Sized, { - msg_send!(class!(Foo), methodWithInt: foo) + unsafe { msg_send!(class!(Foo), methodWithInt: foo) } } unsafe fn methodWithFoo_(foo: Foo) where ::Target: objc::Message + Sized, { - msg_send!(class!(Foo), methodWithFoo: foo) + unsafe { msg_send!(class!(Foo), methodWithFoo: foo) } } unsafe fn methodReturningInt() -> ::std::os::raw::c_int where ::Target: objc::Message + Sized, { - msg_send!(class!(Foo), methodReturningInt) + unsafe { msg_send!(class!(Foo), methodReturningInt) } } unsafe fn methodReturningFoo() -> Foo where ::Target: objc::Message + Sized, { - msg_send!(class!(Foo), methodReturningFoo) + unsafe { msg_send!(class!(Foo), methodReturningFoo) } } unsafe fn methodWithArg1_andArg2_andArg3_( intvalue: ::std::os::raw::c_int, @@ -63,6 +63,8 @@ pub trait IFoo: Sized + std::ops::Deref { ) where ::Target: objc::Message + Sized, { - msg_send ! (class ! (Foo) , methodWithArg1 : intvalue andArg2 : ptr andArg3 : floatvalue) + unsafe { + msg_send ! (class ! (Foo) , methodWithArg1 : intvalue andArg2 : ptr andArg3 : floatvalue) + } } } diff --git a/bindgen-tests/tests/expectations/tests/objc_method.rs b/bindgen-tests/tests/expectations/tests/objc_method.rs index 593fd27738..8962413e24 100644 --- a/bindgen-tests/tests/expectations/tests/objc_method.rs +++ b/bindgen-tests/tests/expectations/tests/objc_method.rs @@ -30,31 +30,31 @@ pub trait IFoo: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - msg_send!(*self, method) + unsafe { msg_send!(*self, method) } } unsafe fn methodWithInt_(&self, foo: ::std::os::raw::c_int) where ::Target: objc::Message + Sized, { - msg_send!(*self, methodWithInt: foo) + unsafe { msg_send!(*self, methodWithInt: foo) } } unsafe fn methodWithFoo_(&self, foo: Foo) where ::Target: objc::Message + Sized, { - msg_send!(*self, methodWithFoo: foo) + unsafe { msg_send!(*self, methodWithFoo: foo) } } unsafe fn methodReturningInt(&self) -> ::std::os::raw::c_int where ::Target: objc::Message + Sized, { - msg_send!(*self, methodReturningInt) + unsafe { msg_send!(*self, methodReturningInt) } } unsafe fn methodReturningFoo(&self) -> Foo where ::Target: objc::Message + Sized, { - msg_send!(*self, methodReturningFoo) + unsafe { msg_send!(*self, methodReturningFoo) } } unsafe fn methodWithArg1_andArg2_andArg3_( &self, @@ -64,7 +64,9 @@ pub trait IFoo: Sized + std::ops::Deref { ) where ::Target: objc::Message + Sized, { - msg_send ! (* self , methodWithArg1 : intvalue andArg2 : ptr andArg3 : floatvalue) + unsafe { + msg_send ! (* self , methodWithArg1 : intvalue andArg2 : ptr andArg3 : floatvalue) + } } unsafe fn methodWithAndWithoutKeywords_arg2Name__arg4Name_( &self, @@ -76,7 +78,9 @@ pub trait IFoo: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - msg_send ! (* self , methodWithAndWithoutKeywords : arg1 arg2Name : arg2 arg3 : arg3 arg4Name : arg4) + unsafe { + msg_send ! (* self , methodWithAndWithoutKeywords : arg1 arg2Name : arg2 arg3 : arg3 arg4Name : arg4) + } } } pub type instancetype = id; diff --git a/bindgen-tests/tests/expectations/tests/objc_method_clash.rs b/bindgen-tests/tests/expectations/tests/objc_method_clash.rs index ac77cc19e3..bd2df7d0d6 100644 --- a/bindgen-tests/tests/expectations/tests/objc_method_clash.rs +++ b/bindgen-tests/tests/expectations/tests/objc_method_clash.rs @@ -30,12 +30,12 @@ pub trait IFoo: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - msg_send!(*self, foo) + unsafe { msg_send!(*self, foo) } } unsafe fn class_foo() where ::Target: objc::Message + Sized, { - msg_send!(class!(Foo), foo) + unsafe { msg_send!(class!(Foo), foo) } } } diff --git a/bindgen-tests/tests/expectations/tests/objc_pointer_return_types.rs b/bindgen-tests/tests/expectations/tests/objc_pointer_return_types.rs index 1ec8494d25..d49f17c1a6 100644 --- a/bindgen-tests/tests/expectations/tests/objc_pointer_return_types.rs +++ b/bindgen-tests/tests/expectations/tests/objc_pointer_return_types.rs @@ -47,12 +47,12 @@ pub trait IFoo: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - msg_send!(*self, methodUsingBar: my_bar) + unsafe { msg_send!(*self, methodUsingBar: my_bar) } } unsafe fn methodReturningBar() -> Bar where ::Target: objc::Message + Sized, { - msg_send!(class!(Foo), methodReturningBar) + unsafe { msg_send!(class!(Foo), methodReturningBar) } } } diff --git a/bindgen-tests/tests/expectations/tests/objc_property_fnptr.rs b/bindgen-tests/tests/expectations/tests/objc_property_fnptr.rs index 9f3fabd272..90a3dc8dea 100644 --- a/bindgen-tests/tests/expectations/tests/objc_property_fnptr.rs +++ b/bindgen-tests/tests/expectations/tests/objc_property_fnptr.rs @@ -38,7 +38,7 @@ pub trait IFoo: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - msg_send!(*self, func) + unsafe { msg_send!(*self, func) } } unsafe fn setFunc_( &self, @@ -52,6 +52,6 @@ pub trait IFoo: Sized + std::ops::Deref { ) where ::Target: objc::Message + Sized, { - msg_send!(*self, setFunc: func) + unsafe { msg_send!(*self, setFunc: func) } } } diff --git a/bindgen-tests/tests/expectations/tests/parm-union.rs b/bindgen-tests/tests/expectations/tests/parm-union.rs index 9f7dd20ad9..4738b301e7 100644 --- a/bindgen-tests/tests/expectations/tests/parm-union.rs +++ b/bindgen-tests/tests/expectations/tests/parm-union.rs @@ -30,7 +30,7 @@ extern "C" { impl Struct { #[inline] pub unsafe fn Function(&mut self, arg1: *mut Union) { - Struct_Function(self, arg1) + unsafe { Struct_Function(self, arg1) } } } #[repr(C)] diff --git a/bindgen-tests/tests/expectations/tests/public-dtor.rs b/bindgen-tests/tests/expectations/tests/public-dtor.rs index 64a503899e..f9559a08dc 100644 --- a/bindgen-tests/tests/expectations/tests/public-dtor.rs +++ b/bindgen-tests/tests/expectations/tests/public-dtor.rs @@ -30,6 +30,6 @@ extern "C" { impl cv_String { #[inline] pub unsafe fn destruct(&mut self) { - cv_String_String_destructor(self) + unsafe { cv_String_String_destructor(self) } } } diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_union_1_0.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_union_1_0.rs index 8db33d113e..fd4d561b79 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_anon_union_1_0.rs @@ -14,11 +14,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs index 55432d47fc..52c6904c26 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs @@ -14,11 +14,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/struct_with_nesting_1_0.rs b/bindgen-tests/tests/expectations/tests/struct_with_nesting_1_0.rs index af795b6423..a777adf360 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_nesting_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_nesting_1_0.rs @@ -14,11 +14,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/transform-op.rs b/bindgen-tests/tests/expectations/tests/transform-op.rs index 84a9460362..eec37a3dae 100644 --- a/bindgen-tests/tests/expectations/tests/transform-op.rs +++ b/bindgen-tests/tests/expectations/tests/transform-op.rs @@ -14,11 +14,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/typeref_1_0.rs b/bindgen-tests/tests/expectations/tests/typeref_1_0.rs index 8e4143c082..3376bf0438 100644 --- a/bindgen-tests/tests/expectations/tests/typeref_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/typeref_1_0.rs @@ -14,11 +14,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/union-in-ns_1_0.rs b/bindgen-tests/tests/expectations/tests/union-in-ns_1_0.rs index a057cc348a..63e3978199 100644 --- a/bindgen-tests/tests/expectations/tests/union-in-ns_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union-in-ns_1_0.rs @@ -16,11 +16,11 @@ pub mod root { } #[inline] pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs b/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs index 2227746849..f15ce0f020 100644 --- a/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs @@ -100,11 +100,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/union_dtor.rs b/bindgen-tests/tests/expectations/tests/union_dtor.rs index 085e5ca30a..cb363de6b5 100644 --- a/bindgen-tests/tests/expectations/tests/union_dtor.rs +++ b/bindgen-tests/tests/expectations/tests/union_dtor.rs @@ -62,6 +62,6 @@ impl Default for UnionWithDtor { impl UnionWithDtor { #[inline] pub unsafe fn destruct(&mut self) { - UnionWithDtor_UnionWithDtor_destructor(self) + unsafe { UnionWithDtor_UnionWithDtor_destructor(self) } } } diff --git a/bindgen-tests/tests/expectations/tests/union_dtor_1_0.rs b/bindgen-tests/tests/expectations/tests/union_dtor_1_0.rs index 67455aa8b8..519bd8692f 100644 --- a/bindgen-tests/tests/expectations/tests/union_dtor_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_dtor_1_0.rs @@ -14,11 +14,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } } impl ::std::default::Default for __BindgenUnionField { @@ -98,6 +98,6 @@ extern "C" { impl UnionWithDtor { #[inline] pub unsafe fn destruct(&mut self) { - UnionWithDtor_UnionWithDtor_destructor(self) + unsafe { UnionWithDtor_UnionWithDtor_destructor(self) } } } diff --git a/bindgen-tests/tests/expectations/tests/union_fields_1_0.rs b/bindgen-tests/tests/expectations/tests/union_fields_1_0.rs index b5f94bcd05..621a961f4f 100644 --- a/bindgen-tests/tests/expectations/tests/union_fields_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_fields_1_0.rs @@ -14,11 +14,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/union_template_1_0.rs b/bindgen-tests/tests/expectations/tests/union_template_1_0.rs index 487579f7e5..543f154d05 100644 --- a/bindgen-tests/tests/expectations/tests/union_template_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_template_1_0.rs @@ -14,11 +14,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_1_0.rs index 8b11e75796..316f8453e5 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_1_0.rs @@ -14,11 +14,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs index 6ce6ed2282..c06f6489b9 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs @@ -100,11 +100,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_union_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_union_1_0.rs index f3e4b84003..6c856634da 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_union_1_0.rs @@ -14,11 +14,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs index 1562a8c971..d4c6fec977 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs @@ -14,11 +14,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs index 197a6bbfbc..96f03680aa 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs @@ -14,11 +14,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/union_with_big_member_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_big_member_1_0.rs index 63b43baa82..869720d442 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_big_member_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_big_member_1_0.rs @@ -14,11 +14,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/union_with_nesting_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_nesting_1_0.rs index a1e452fe03..4b1ab55336 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_nesting_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_nesting_1_0.rs @@ -14,11 +14,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/union_with_non_copy_member.rs b/bindgen-tests/tests/expectations/tests/union_with_non_copy_member.rs index 3c500b2106..227afaffcc 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_non_copy_member.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_non_copy_member.rs @@ -14,11 +14,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) + unsafe { ::std::mem::transmute(self) } } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/use-core_1_0.rs b/bindgen-tests/tests/expectations/tests/use-core_1_0.rs index 8c6d0fd272..0310211d88 100644 --- a/bindgen-tests/tests/expectations/tests/use-core_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/use-core_1_0.rs @@ -16,11 +16,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - ::core::mem::transmute(self) + unsafe { ::core::mem::transmute(self) } } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - ::core::mem::transmute(self) + unsafe { ::core::mem::transmute(self) } } } impl ::core::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/var-tracing.rs b/bindgen-tests/tests/expectations/tests/var-tracing.rs index 37fdd95105..22e7e6ed69 100644 --- a/bindgen-tests/tests/expectations/tests/var-tracing.rs +++ b/bindgen-tests/tests/expectations/tests/var-tracing.rs @@ -43,9 +43,11 @@ extern "C" { impl Bar { #[inline] pub unsafe fn new(baz: ::std::os::raw::c_int) -> Self { - let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); - Bar_Bar(__bindgen_tmp.as_mut_ptr(), baz); - __bindgen_tmp.assume_init() + unsafe { + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + Bar_Bar(__bindgen_tmp.as_mut_ptr(), baz); + __bindgen_tmp.assume_init() + } } } #[repr(C)] diff --git a/bindgen-tests/tests/expectations/tests/wasm-constructor-returns.rs b/bindgen-tests/tests/expectations/tests/wasm-constructor-returns.rs index 6d15c51f9d..909d04ded4 100644 --- a/bindgen-tests/tests/expectations/tests/wasm-constructor-returns.rs +++ b/bindgen-tests/tests/expectations/tests/wasm-constructor-returns.rs @@ -33,8 +33,10 @@ extern "C" { impl Foo { #[inline] pub unsafe fn new(var: ::std::os::raw::c_int) -> Self { - let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); - Foo_Foo(__bindgen_tmp.as_mut_ptr(), var); - __bindgen_tmp.assume_init() + unsafe { + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + Foo_Foo(__bindgen_tmp.as_mut_ptr(), var); + __bindgen_tmp.assume_init() + } } } diff --git a/bindgen-tests/tests/expectations/tests/win32-thiscall_nightly.rs b/bindgen-tests/tests/expectations/tests/win32-thiscall_nightly.rs index 92bb13cc61..f144edd4d0 100644 --- a/bindgen-tests/tests/expectations/tests/win32-thiscall_nightly.rs +++ b/bindgen-tests/tests/expectations/tests/win32-thiscall_nightly.rs @@ -39,13 +39,13 @@ extern "thiscall" { impl Foo { #[inline] pub unsafe fn test(&mut self) { - Foo_test(self) + unsafe { 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) + unsafe { Foo_test2(self, var) } } } diff --git a/bindgen-tests/tests/expectations/tests/zero-size-array-align.rs b/bindgen-tests/tests/expectations/tests/zero-size-array-align.rs index d7d0f6613d..e99abb8721 100644 --- a/bindgen-tests/tests/expectations/tests/zero-size-array-align.rs +++ b/bindgen-tests/tests/expectations/tests/zero-size-array-align.rs @@ -23,11 +23,11 @@ impl __IncompleteArrayField { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - ::std::slice::from_raw_parts(self.as_ptr(), len) + unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) + unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } } impl ::std::fmt::Debug for __IncompleteArrayField { diff --git a/bindgen-tests/tests/expectations/tests/zero-sized-array.rs b/bindgen-tests/tests/expectations/tests/zero-sized-array.rs index 4ba52498c4..27c48f0e25 100644 --- a/bindgen-tests/tests/expectations/tests/zero-sized-array.rs +++ b/bindgen-tests/tests/expectations/tests/zero-sized-array.rs @@ -23,11 +23,11 @@ impl __IncompleteArrayField { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - ::std::slice::from_raw_parts(self.as_ptr(), len) + unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) + unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } } impl ::std::fmt::Debug for __IncompleteArrayField { diff --git a/bindgen/codegen/dyngen.rs b/bindgen/codegen/dyngen.rs index d02c51e420..f310f14e08 100644 --- a/bindgen/codegen/dyngen.rs +++ b/bindgen/codegen/dyngen.rs @@ -92,7 +92,9 @@ impl DynamicItems { ) -> Result where P: AsRef<::std::ffi::OsStr> { let library = ::libloading::Library::new(path)?; - Self::from_library(library) + unsafe { + Self::from_library(library) + } } pub unsafe fn from_library( @@ -157,7 +159,9 @@ impl DynamicItems { self.struct_implementation.push(quote! { #(#attributes)* pub unsafe fn #ident ( &self, #( #args ),* ) -> #ret_ty { - #call_body + unsafe { + #call_body + } } }); } @@ -166,11 +170,11 @@ impl DynamicItems { let ident_str = codegen::helpers::ast_ty::cstr_expr(ident.to_string()); self.constructor_inits.push(if is_required { quote! { - let #ident = __library.get(#ident_str).map(|sym| *sym)?; + let #ident = unsafe { __library.get(#ident_str) }.map(|sym| *sym)?; } } else { quote! { - let #ident = __library.get(#ident_str).map(|sym| *sym); + let #ident = unsafe { __library.get(#ident_str) }.map(|sym| *sym); } }); diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index d0c191360e..e0d96cd1b8 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -2605,7 +2605,9 @@ impl MethodCodegen for Method { methods.push(quote! { #(#attrs)* pub unsafe fn #name ( #( #args ),* ) #ret { - #block + unsafe { + #block + } } }); } @@ -4263,7 +4265,9 @@ fn objc_method_codegen( methods.push(quote! { unsafe fn #method_name #sig where ::Target: objc::Message + Sized { - #body + unsafe { + #body + } } }); } @@ -4638,12 +4642,16 @@ pub mod utils { #[inline] pub unsafe fn as_ref(&self) -> &T { - ::#prefix::mem::transmute(self) + unsafe { + ::#prefix::mem::transmute(self) + } } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - ::#prefix::mem::transmute(self) + unsafe { + ::#prefix::mem::transmute(self) + } } } }; @@ -4757,12 +4765,16 @@ pub mod utils { #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - ::#prefix::slice::from_raw_parts(self.as_ptr(), len) + unsafe { + ::#prefix::slice::from_raw_parts(self.as_ptr(), len) + } } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - ::#prefix::slice::from_raw_parts_mut(self.as_mut_ptr(), len) + unsafe { + ::#prefix::slice::from_raw_parts_mut(self.as_mut_ptr(), len) + } } } }; From 0631a27bee19601e393e31e7dfc2563412b2fe01 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Fri, 4 Nov 2022 15:41:49 -0500 Subject: [PATCH 406/942] Fix clippy warnings (#2336) --- bindgen-cli/options.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindgen-cli/options.rs b/bindgen-cli/options.rs index 90f38cb2f9..482f9a7d98 100644 --- a/bindgen-cli/options.rs +++ b/bindgen-cli/options.rs @@ -1097,7 +1097,7 @@ where if let Some(abi_overrides) = matches.values_of("override-abi") { for abi_override in abi_overrides { let (regex, abi_str) = abi_override - .rsplit_once("=") + .rsplit_once('=') .expect("Invalid ABI override: Missing `=`"); let abi = abi_str .parse() From c03b37697a1e117995ea76203e5c0ce7d6696c4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 9 Nov 2022 13:33:19 +0100 Subject: [PATCH 407/942] ir: Don't crash with built-in unexposed types from libclang. This fixes #2325. The issue is that `__bf16` is not exposed at all by libclang, which causes us to crash. It's a bit of a shame libclang doesn't expose it but there's no rust equivalent I think, so this should be ok for now. Unfortunately no test because the header crashes older clang versions. --- bindgen/ir/ty.rs | 3 +-- bindgen/ir/var.rs | 8 ++++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/bindgen/ir/ty.rs b/bindgen/ir/ty.rs index 9edc43d419..c9403f66c9 100644 --- a/bindgen/ir/ty.rs +++ b/bindgen/ir/ty.rs @@ -1145,8 +1145,7 @@ impl Type { location, None, ctx, - ) - .expect("Not able to resolve vector element?"); + )?; TypeKind::Vector(inner, ty.num_elements().unwrap()) } CXType_ConstantArray => { diff --git a/bindgen/ir/var.rs b/bindgen/ir/var.rs index 198206b9f1..c86742ff69 100644 --- a/bindgen/ir/var.rs +++ b/bindgen/ir/var.rs @@ -293,11 +293,11 @@ impl ClangSubItemParser for Var { let ty = match Item::from_ty(&ty, cursor, None, ctx) { Ok(ty) => ty, Err(e) => { - assert_eq!( - ty.kind(), - CXType_Auto, + assert!( + matches!(ty.kind(), CXType_Auto | CXType_Unexposed), "Couldn't resolve constant type, and it \ - wasn't an nondeductible auto type!" + wasn't an nondeductible auto type or unexposed \ + type!" ); return Err(e); } From ed3aa90cd4c4e1e59d15942414a6dbc586ac1ed4 Mon Sep 17 00:00:00 2001 From: kohanis Date: Wed, 9 Nov 2022 17:24:27 +0300 Subject: [PATCH 408/942] Fix inline function identification --- .../tests/expectations/tests/public-dtor.rs | 88 +++++++++++-------- .../tests/headers/constructor-tp.hpp | 3 +- bindgen-tests/tests/headers/public-dtor.hpp | 21 +++-- bindgen/ir/function.rs | 6 +- 4 files changed, 71 insertions(+), 47 deletions(-) diff --git a/bindgen-tests/tests/expectations/tests/public-dtor.rs b/bindgen-tests/tests/expectations/tests/public-dtor.rs index f9559a08dc..1d095b8d0b 100644 --- a/bindgen-tests/tests/expectations/tests/public-dtor.rs +++ b/bindgen-tests/tests/expectations/tests/public-dtor.rs @@ -1,35 +1,53 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -#[repr(C)] -#[derive(Debug, Default)] -pub struct cv_String { - pub _address: u8, -} -#[test] -fn bindgen_test_layout_cv_String() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(cv_String)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(cv_String)) - ); -} -extern "C" { - #[link_name = "\u{1}_ZN2cv6StringD1Ev"] - pub fn cv_String_String_destructor(this: *mut cv_String); -} -impl cv_String { - #[inline] - pub unsafe fn destruct(&mut self) { - unsafe { cv_String_String_destructor(self) } - } -} +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +#[derive(Debug, Default)] +pub struct cv_Foo { + pub _address: u8, +} +#[test] +fn bindgen_test_layout_cv_Foo() { + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(cv_Foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(cv_Foo)) + ); +} +extern "C" { + #[link_name = "\u{1}_ZN2cv3FooD1Ev"] + pub fn cv_Foo_Foo_destructor(this: *mut cv_Foo); +} +impl cv_Foo { + #[inline] + pub unsafe fn destruct(&mut self) { + unsafe { cv_Foo_Foo_destructor(self) } + } +} +#[repr(C)] +#[derive(Debug, Default)] +pub struct cv_Bar { + pub _address: u8, +} +#[test] +fn bindgen_test_layout_cv_Bar() { + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(cv_Bar)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(cv_Bar)) + ); +} diff --git a/bindgen-tests/tests/headers/constructor-tp.hpp b/bindgen-tests/tests/headers/constructor-tp.hpp index 6e55ea7852..3b5d54071a 100644 --- a/bindgen-tests/tests/headers/constructor-tp.hpp +++ b/bindgen-tests/tests/headers/constructor-tp.hpp @@ -8,7 +8,7 @@ class Foo { }; template -inline void +void Foo::doBaz() { } @@ -21,6 +21,5 @@ template Foo::Foo() { } -inline Bar::Bar() { } diff --git a/bindgen-tests/tests/headers/public-dtor.hpp b/bindgen-tests/tests/headers/public-dtor.hpp index 5d4fb592a1..60d69d799f 100644 --- a/bindgen-tests/tests/headers/public-dtor.hpp +++ b/bindgen-tests/tests/headers/public-dtor.hpp @@ -1,15 +1,18 @@ - namespace cv { -class String { -public: - ~String(); -}; + class Foo { + public: + ~Foo(); + }; + Foo::~Foo() {} -inline -String::~String() -{ -} + class Bar { + public: + ~Bar(); + }; + + inline + Bar::~Bar() {} } diff --git a/bindgen/ir/function.rs b/bindgen/ir/function.rs index 52346f6c88..7dbbb8f849 100644 --- a/bindgen/ir/function.rs +++ b/bindgen/ir/function.rs @@ -675,7 +675,11 @@ impl ClangSubItemParser for Function { return Err(ParseError::Continue); } - if cursor.is_inlined_function() { + if cursor.is_inlined_function() || + cursor + .definition() + .map_or(false, |x| x.is_inlined_function()) + { if !context.options().generate_inline_functions { return Err(ParseError::Continue); } From db4ea32e2d810e765a4c40479e053d0a61a875cf Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Thu, 10 Nov 2022 10:43:02 -0500 Subject: [PATCH 409/942] Handle the `const struct *` and `struct *` patterns (#2304) Given that C keeps a different namespace for `struct`/`enum`/`union` and `typedef` aliases. The following patterns ```c typedef const struct foo { void *inner; } *foo; typedef struct bar { void *inner; } *bar; ``` are valid C code and produces both a `struct` and a pointer called `foo` and `bar` in different namespaces. Given that Rust does not make this distinction, we add the `_ptr` prefix to the pointer type aliases to avoid any name collisions. --- .../tests/typedef-pointer-overlap.rs | 153 ++++++++++++++++++ .../tests/headers/typedef-pointer-overlap.h | 30 ++++ bindgen/ir/ty.rs | 21 ++- 3 files changed, 201 insertions(+), 3 deletions(-) create mode 100644 bindgen-tests/tests/expectations/tests/typedef-pointer-overlap.rs create mode 100644 bindgen-tests/tests/headers/typedef-pointer-overlap.h diff --git a/bindgen-tests/tests/expectations/tests/typedef-pointer-overlap.rs b/bindgen-tests/tests/expectations/tests/typedef-pointer-overlap.rs new file mode 100644 index 0000000000..2d5c5aae8c --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/typedef-pointer-overlap.rs @@ -0,0 +1,153 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct foo { + pub inner: ::std::os::raw::c_char, +} +#[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::(), + 1usize, + concat!("Size of: ", stringify!(foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(foo)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).inner) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo), + "::", + stringify!(inner) + ) + ); +} +pub type foo_ptr = *const foo; +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct bar { + pub inner: ::std::os::raw::c_char, +} +#[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::(), + 1usize, + concat!("Size of: ", stringify!(bar)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(bar)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).inner) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(bar), + "::", + stringify!(inner) + ) + ); +} +pub type bar_ptr = *mut bar; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct baz { + _unused: [u8; 0], +} +pub type baz_ptr = *mut baz; +#[repr(C)] +#[derive(Copy, Clone)] +pub union cat { + pub standard_issue: ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout_cat() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(cat)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(cat)) + ); + assert_eq!( + unsafe { + ::std::ptr::addr_of!((*ptr).standard_issue) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(cat), + "::", + stringify!(standard_issue) + ) + ); +} +impl Default for cat { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +pub type cat_ptr = *mut cat; +pub const mad_scientist: mad = 0; +pub type mad = ::std::os::raw::c_uint; +pub type mad_ptr = *mut mad; +extern "C" { + pub fn takes_foo_ptr(arg1: foo_ptr); +} +extern "C" { + pub fn takes_foo_struct(arg1: foo); +} +extern "C" { + pub fn takes_bar_ptr(arg1: bar_ptr); +} +extern "C" { + pub fn takes_bar_struct(arg1: bar); +} +extern "C" { + pub fn takes_baz_ptr(arg1: baz_ptr); +} +extern "C" { + pub fn takes_baz_struct(arg1: baz); +} +extern "C" { + pub fn takes_cat_ptr(arg1: cat_ptr); +} +extern "C" { + pub fn takes_cat_union(arg1: cat); +} +extern "C" { + pub fn takes_mad_ptr(arg1: mad_ptr); +} +extern "C" { + pub fn takes_mad_enum(arg1: mad); +} diff --git a/bindgen-tests/tests/headers/typedef-pointer-overlap.h b/bindgen-tests/tests/headers/typedef-pointer-overlap.h new file mode 100644 index 0000000000..8c556c9b38 --- /dev/null +++ b/bindgen-tests/tests/headers/typedef-pointer-overlap.h @@ -0,0 +1,30 @@ +typedef const struct foo { + char inner; +} *foo; + +typedef struct bar { + char inner; +} *bar; + +typedef struct baz *baz; + +typedef union cat { + int standard_issue; +} *cat; + +typedef enum mad { scientist } *mad; + +void takes_foo_ptr(foo); +void takes_foo_struct(struct foo); + +void takes_bar_ptr(bar); +void takes_bar_struct(struct bar); + +void takes_baz_ptr(baz); +void takes_baz_struct(struct baz); + +void takes_cat_ptr(cat); +void takes_cat_union(union cat); + +void takes_mad_ptr(mad); +void takes_mad_enum(enum mad); diff --git a/bindgen/ir/ty.rs b/bindgen/ir/ty.rs index c9403f66c9..fd6108f774 100644 --- a/bindgen/ir/ty.rs +++ b/bindgen/ir/ty.rs @@ -1094,9 +1094,9 @@ impl Type { } CXType_Typedef => { let inner = cursor.typedef_type().expect("Not valid Type?"); - let inner = + let inner_id = Item::from_ty_or_ref(inner, location, None, ctx); - if inner == potential_id { + if inner_id == potential_id { warn!( "Generating oqaque type instead of self-referential \ typedef"); @@ -1104,7 +1104,22 @@ impl Type { // within the clang parsing. TypeKind::Opaque } else { - TypeKind::Alias(inner) + // Check if this type definition is an alias to a pointer of a `struct` / + // `union` / `enum` with the same name and add the `_ptr` suffix to it to + // avoid name collisions. + if let Some(ref mut name) = name { + if inner.kind() == CXType_Pointer && + !ctx.options().c_naming + { + let pointee = inner.pointee_type().unwrap(); + if pointee.kind() == CXType_Elaborated && + pointee.declaration().spelling() == *name + { + *name += "_ptr"; + } + } + } + TypeKind::Alias(inner_id) } } CXType_Enum => { From 67dfa7ed41303a74277bf9ad4e2e2344c8ffb505 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Fri, 11 Nov 2022 11:48:39 -0500 Subject: [PATCH 410/942] Fix duplicated function names (#2341) Even though this change does name deduplication in a slower way, it avoids name collisions without any breaking changes in the test suite. Fixes #2202 --- .../tests/duplicated-definition-count.rs | 67 +++++++++++++++++++ .../headers/duplicated-definition-count.hpp | 6 ++ bindgen/codegen/mod.rs | 24 ++++--- 3 files changed, 88 insertions(+), 9 deletions(-) create mode 100644 bindgen-tests/tests/expectations/tests/duplicated-definition-count.rs create mode 100644 bindgen-tests/tests/headers/duplicated-definition-count.hpp diff --git a/bindgen-tests/tests/expectations/tests/duplicated-definition-count.rs b/bindgen-tests/tests/expectations/tests/duplicated-definition-count.rs new file mode 100644 index 0000000000..8fdffe56e4 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/duplicated-definition-count.rs @@ -0,0 +1,67 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct BitStream { + pub _address: u8, +} +#[test] +fn bindgen_test_layout_BitStream() { + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(BitStream)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(BitStream)) + ); +} +extern "C" { + #[link_name = "\u{1}_ZN9BitStream5WriteEPKcj"] + pub fn BitStream_Write( + this: *mut BitStream, + inputByteArray: *const ::std::os::raw::c_char, + numberOfBytes: ::std::os::raw::c_uint, + ); +} +extern "C" { + #[link_name = "\u{1}_ZN9BitStream5WriteEPS_j"] + pub fn BitStream_Write1( + this: *mut BitStream, + bitStream: *mut BitStream, + numberOfBits: ::std::os::raw::c_uint, + ); +} +extern "C" { + #[link_name = "\u{1}_ZN9BitStream6Write1Ev"] + pub fn BitStream_Write11(this: *mut BitStream); +} +impl BitStream { + #[inline] + pub unsafe fn Write( + &mut self, + inputByteArray: *const ::std::os::raw::c_char, + numberOfBytes: ::std::os::raw::c_uint, + ) { + unsafe { BitStream_Write(self, inputByteArray, numberOfBytes) } + } + #[inline] + pub unsafe fn Write1( + &mut self, + bitStream: *mut BitStream, + numberOfBits: ::std::os::raw::c_uint, + ) { + unsafe { BitStream_Write1(self, bitStream, numberOfBits) } + } + #[inline] + pub unsafe fn Write11(&mut self) { + unsafe { BitStream_Write11(self) } + } +} diff --git a/bindgen-tests/tests/headers/duplicated-definition-count.hpp b/bindgen-tests/tests/headers/duplicated-definition-count.hpp new file mode 100644 index 0000000000..2916762617 --- /dev/null +++ b/bindgen-tests/tests/headers/duplicated-definition-count.hpp @@ -0,0 +1,6 @@ +class BitStream { + public: + void Write(const char *inputByteArray, unsigned int numberOfBytes); + void Write(BitStream *bitStream, unsigned numberOfBits); + void Write1(); +}; diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index e0d96cd1b8..c7ac59db42 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -2421,7 +2421,7 @@ trait MethodCodegen { &self, ctx: &BindgenContext, methods: &mut Vec, - method_names: &mut HashMap, + method_names: &mut HashSet, result: &mut CodegenResult<'a>, parent: &CompInfo, ); @@ -2432,7 +2432,7 @@ impl MethodCodegen for Method { &self, ctx: &BindgenContext, methods: &mut Vec, - method_names: &mut HashMap, + method_names: &mut HashSet, result: &mut CodegenResult<'a>, _parent: &CompInfo, ) { @@ -2499,16 +2499,22 @@ impl MethodCodegen for Method { return; } - let count = { - let count = method_names.entry(name.clone()).or_insert(0); - *count += 1; - *count - 1 - }; + if method_names.contains(&name) { + let mut count = 1; + let mut new_name; + + while { + new_name = format!("{}{}", name, count); + method_names.contains(&new_name) + } { + count += 1; + } - if count != 0 { - name.push_str(&count.to_string()); + name = new_name; } + method_names.insert(name.clone()); + let mut function_name = function_item.canonical_name(ctx); if times_seen > 0 { write!(&mut function_name, "{}", times_seen).unwrap(); From 4574d766d53bf368c9e3909886229891ddc2bb57 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Fri, 11 Nov 2022 13:01:53 -0500 Subject: [PATCH 411/942] Document and test allowlisting and blocklisting methods (#2344) --- .../expectations/tests/blocklist-methods.rs | 35 +++++++++++++++++++ .../tests/headers/blocklist-methods.hpp | 8 +++++ bindgen/lib.rs | 8 +++++ 3 files changed, 51 insertions(+) create mode 100644 bindgen-tests/tests/expectations/tests/blocklist-methods.rs create mode 100644 bindgen-tests/tests/headers/blocklist-methods.hpp diff --git a/bindgen-tests/tests/expectations/tests/blocklist-methods.rs b/bindgen-tests/tests/expectations/tests/blocklist-methods.rs new file mode 100644 index 0000000000..5b625f0a4e --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/blocklist-methods.rs @@ -0,0 +1,35 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[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, + concat!("Size of: ", stringify!(Foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)) + ); +} +extern "C" { + #[link_name = "\u{1}_ZN3Foo3fooEv"] + pub fn Foo_foo(this: *mut Foo) -> ::std::os::raw::c_int; +} +impl Foo { + #[inline] + pub unsafe fn foo(&mut self) -> ::std::os::raw::c_int { + unsafe { Foo_foo(self) } + } +} diff --git a/bindgen-tests/tests/headers/blocklist-methods.hpp b/bindgen-tests/tests/headers/blocklist-methods.hpp new file mode 100644 index 0000000000..4be21b945e --- /dev/null +++ b/bindgen-tests/tests/headers/blocklist-methods.hpp @@ -0,0 +1,8 @@ +// bindgen-flags: --blocklist-function="Foo_ba.*" + +class Foo { + public: + int foo(); + int bar(); + int baz(); +}; diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 3696c499c5..03de8430d8 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -850,6 +850,10 @@ impl Builder { /// Hide the given function from the generated bindings. Regular expressions /// are supported. /// + /// Methods can be blocklisted by prefixing the name of the type implementing + /// them followed by an underscore. So if `Foo` has a method `bar`, it can + /// be blocklisted as `Foo_bar`. + /// /// To blocklist functions prefixed with "mylib" use `"mylib_.*"`. /// For more complicated expressions check /// [regex](https://docs.rs/regex/*/regex/) docs @@ -929,6 +933,10 @@ impl Builder { /// transitively refers to) appears in the generated bindings. Regular /// expressions are supported. /// + /// Methods can be allowlisted by prefixing the name of the type + /// implementing them followed by an underscore. So if `Foo` has a method + /// `bar`, it can be allowlisted as `Foo_bar`. + /// /// To allowlist functions prefixed with "mylib" use `"mylib_.*"`. /// For more complicated expressions check /// [regex](https://docs.rs/regex/*/regex/) docs From 678daf56a2384252304fc27ed2b46e769da1890f Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Mon, 14 Nov 2022 12:34:05 -0500 Subject: [PATCH 412/942] document regex arguments handling (#2345) --- bindgen/lib.rs | 547 +++++++++++++++++++++++++++---------------------- 1 file changed, 305 insertions(+), 242 deletions(-) diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 03de8430d8..e18a2a992c 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -49,6 +49,18 @@ macro_rules! doc_mod { }; } +macro_rules! fn_with_regex_arg { + ($(#[$attrs:meta])* pub fn $($tokens:tt)*) => { + $(#[$attrs])* + /// Check the [regular expression arguments] section and the [regex] crate + /// documentation for further information. + /// + /// [regular expression arguments]: ./struct.Builder.html#regular-expression-arguments + /// [regex]: + pub fn $($tokens)* + }; +} + mod clang; mod codegen; mod deps; @@ -223,6 +235,13 @@ impl Default for CodegenConfig { /// End-users of the crate may need to set the `BINDGEN_EXTRA_CLANG_ARGS` environment variable to /// add additional arguments. For example, to build against a different sysroot a user could set /// `BINDGEN_EXTRA_CLANG_ARGS` to `--sysroot=/path/to/sysroot`. +/// +/// # Regular expression arguments +/// +/// Some [`Builder`] methods like the `allowlist_*` and `blocklist_*` family of methods allow +/// regular expressions as arguments. These regular expressions will be parenthesized and wrapped +/// in `^` and `$`. So if `` is passed as argument, the regular expression to be stored will +/// be `^()$`. #[derive(Debug, Default, Clone)] pub struct Builder { options: BindgenOptions, @@ -829,37 +848,39 @@ impl Builder { self.blocklist_type(arg) } - /// Hide the given type from the generated bindings. Regular expressions are - /// supported. - /// - /// To blocklist types prefixed with "mylib" use `"mylib_.*"`. - /// For more complicated expressions check - /// [regex](https://docs.rs/regex/*/regex/) docs - pub fn blocklist_type>(mut self, arg: T) -> Builder { - self.options.blocklisted_types.insert(arg); - self + fn_with_regex_arg! { + /// Hide the given type from the generated bindings. Regular expressions are + /// supported. + /// + /// To blocklist types prefixed with "mylib" use `"mylib_.*"`. + pub fn blocklist_type>(mut self, arg: T) -> Builder { + self.options.blocklisted_types.insert(arg); + self + } } - /// Hide the given function from the generated bindings. Regular expressions - /// are supported. - #[deprecated(note = "Use blocklist_function instead")] - pub fn blacklist_function>(self, arg: T) -> Builder { - self.blocklist_function(arg) + fn_with_regex_arg! { + /// Hide the given function from the generated bindings. Regular expressions + /// are supported. + #[deprecated(note = "Use blocklist_function instead")] + pub fn blacklist_function>(self, arg: T) -> Builder { + self.blocklist_function(arg) + } } - /// Hide the given function from the generated bindings. Regular expressions - /// are supported. - /// - /// Methods can be blocklisted by prefixing the name of the type implementing - /// them followed by an underscore. So if `Foo` has a method `bar`, it can - /// be blocklisted as `Foo_bar`. - /// - /// To blocklist functions prefixed with "mylib" use `"mylib_.*"`. - /// For more complicated expressions check - /// [regex](https://docs.rs/regex/*/regex/) docs - pub fn blocklist_function>(mut self, arg: T) -> Builder { - self.options.blocklisted_functions.insert(arg); - self + fn_with_regex_arg! { + /// Hide the given function from the generated bindings. Regular expressions + /// are supported. + /// + /// Methods can be blocklisted by prefixing the name of the type implementing + /// them followed by an underscore. So if `Foo` has a method `bar`, it can + /// be blocklisted as `Foo_bar`. + /// + /// To blocklist functions prefixed with "mylib" use `"mylib_.*"`. + pub fn blocklist_function>(mut self, arg: T) -> Builder { + self.options.blocklisted_functions.insert(arg); + self + } } /// Hide the given item from the generated bindings, regardless of @@ -871,34 +892,36 @@ impl Builder { self } - /// Hide the given item from the generated bindings, regardless of - /// whether it's a type, function, module, etc. Regular - /// expressions are supported. - /// - /// To blocklist items prefixed with "mylib" use `"mylib_.*"`. - /// For more complicated expressions check - /// [regex](https://docs.rs/regex/*/regex/) docs - pub fn blocklist_item>(mut self, arg: T) -> Builder { - self.options.blocklisted_items.insert(arg); - self + fn_with_regex_arg! { + /// Hide the given item from the generated bindings, regardless of + /// whether it's a type, function, module, etc. Regular + /// expressions are supported. + /// + /// To blocklist items prefixed with "mylib" use `"mylib_.*"`. + pub fn blocklist_item>(mut self, arg: T) -> Builder { + self.options.blocklisted_items.insert(arg); + self + } } - /// Hide any contents of the given file from the generated bindings, - /// regardless of whether it's a type, function, module etc. - pub fn blocklist_file>(mut self, arg: T) -> Builder { - self.options.blocklisted_files.insert(arg); - self + fn_with_regex_arg! { + /// Hide any contents of the given file from the generated bindings, + /// regardless of whether it's a type, function, module etc. + pub fn blocklist_file>(mut self, arg: T) -> Builder { + self.options.blocklisted_files.insert(arg); + self + } } - /// Treat the given type as opaque in the generated bindings. Regular - /// expressions are supported. - /// - /// To change types prefixed with "mylib" into opaque, use `"mylib_.*"`. - /// For more complicated expressions check - /// [regex](https://docs.rs/regex/*/regex/) docs - pub fn opaque_type>(mut self, arg: T) -> Builder { - self.options.opaque_types.insert(arg); - self + fn_with_regex_arg! { + /// Treat the given type as opaque in the generated bindings. Regular + /// expressions are supported. + /// + /// To change types prefixed with "mylib" into opaque, use `"mylib_.*"`. + pub fn opaque_type>(mut self, arg: T) -> Builder { + self.options.opaque_types.insert(arg); + self + } } /// Allowlist the given type so that it (and all types that it transitively @@ -917,32 +940,32 @@ impl Builder { self.allowlist_type(arg) } - /// Allowlist the given type so that it (and all types that it transitively - /// refers to) appears in the generated bindings. Regular expressions are - /// supported. - /// - /// To allowlist types prefixed with "mylib" use `"mylib_.*"`. - /// For more complicated expressions check - /// [regex](https://docs.rs/regex/*/regex/) docs - pub fn allowlist_type>(mut self, arg: T) -> Builder { - self.options.allowlisted_types.insert(arg); - self + fn_with_regex_arg! { + /// Allowlist the given type so that it (and all types that it transitively + /// refers to) appears in the generated bindings. Regular expressions are + /// supported. + /// + /// To allowlist types prefixed with "mylib" use `"mylib_.*"`. + pub fn allowlist_type>(mut self, arg: T) -> Builder { + self.options.allowlisted_types.insert(arg); + self + } } - /// Allowlist the given function so that it (and all types that it - /// transitively refers to) appears in the generated bindings. Regular - /// expressions are supported. - /// - /// Methods can be allowlisted by prefixing the name of the type - /// implementing them followed by an underscore. So if `Foo` has a method - /// `bar`, it can be allowlisted as `Foo_bar`. - /// - /// To allowlist functions prefixed with "mylib" use `"mylib_.*"`. - /// For more complicated expressions check - /// [regex](https://docs.rs/regex/*/regex/) docs - pub fn allowlist_function>(mut self, arg: T) -> Builder { - self.options.allowlisted_functions.insert(arg); - self + fn_with_regex_arg! { + /// Allowlist the given function so that it (and all types that it + /// transitively refers to) appears in the generated bindings. Regular + /// expressions are supported. + /// + /// Methods can be allowlisted by prefixing the name of the type + /// implementing them followed by an underscore. So if `Foo` has a method + /// `bar`, it can be allowlisted as `Foo_bar`. + /// + /// To allowlist functions prefixed with "mylib" use `"mylib_.*"`. + pub fn allowlist_function>(mut self, arg: T) -> Builder { + self.options.allowlisted_functions.insert(arg); + self + } } /// Allowlist the given function. @@ -961,22 +984,24 @@ impl Builder { self.allowlist_function(arg) } - /// Allowlist the given variable so that it (and all types that it - /// transitively refers to) appears in the generated bindings. Regular - /// expressions are supported. - /// - /// To allowlist variables prefixed with "mylib" use `"mylib_.*"`. - /// For more complicated expressions check - /// [regex](https://docs.rs/regex/*/regex/) docs - pub fn allowlist_var>(mut self, arg: T) -> Builder { - self.options.allowlisted_vars.insert(arg); - self + fn_with_regex_arg! { + /// Allowlist the given variable so that it (and all types that it + /// transitively refers to) appears in the generated bindings. Regular + /// expressions are supported. + /// + /// To allowlist variables prefixed with "mylib" use `"mylib_.*"`. + pub fn allowlist_var>(mut self, arg: T) -> Builder { + self.options.allowlisted_vars.insert(arg); + self + } } - /// Allowlist the given file so that its contents appear in the generated bindings. - pub fn allowlist_file>(mut self, arg: T) -> Builder { - self.options.allowlisted_files.insert(arg); - self + fn_with_regex_arg! { + /// Allowlist the given file so that its contents appear in the generated bindings. + pub fn allowlist_file>(mut self, arg: T) -> Builder { + self.options.allowlisted_files.insert(arg); + self + } } /// Deprecated: use allowlist_var instead. @@ -1002,87 +1027,101 @@ impl Builder { self } - /// Mark the given enum (or set of enums, if using a pattern) as being - /// bitfield-like. Regular expressions are supported. - /// - /// This makes bindgen generate a type that isn't a rust `enum`. Regular - /// expressions are supported. - /// - /// This is similar to the newtype enum style, but with the bitwise - /// operators implemented. - pub fn bitfield_enum>(mut self, arg: T) -> Builder { - self.options.bitfield_enums.insert(arg); - self - } - - /// Mark the given enum (or set of enums, if using a pattern) as a newtype. - /// Regular expressions are supported. - /// - /// This makes bindgen generate a type that isn't a Rust `enum`. Regular - /// expressions are supported. - pub fn newtype_enum>(mut self, arg: T) -> Builder { - self.options.newtype_enums.insert(arg); - self - } - - /// Mark the given enum (or set of enums, if using a pattern) as a newtype - /// whose variants are exposed as global constants. - /// - /// Regular expressions are supported. - /// - /// This makes bindgen generate a type that isn't a Rust `enum`. Regular - /// expressions are supported. - pub fn newtype_global_enum>(mut self, arg: T) -> Builder { - self.options.newtype_global_enums.insert(arg); - self - } - - /// Mark the given enum (or set of enums, if using a pattern) as a Rust - /// enum. - /// - /// This makes bindgen generate enums instead of constants. Regular - /// expressions are supported. - /// - /// **Use this with caution**, creating this in unsafe code - /// (including FFI) with an invalid value will invoke undefined behaviour. - /// You may want to use the newtype enum style instead. - pub fn rustified_enum>(mut self, arg: T) -> Builder { - self.options.rustified_enums.insert(arg); - self - } - - /// Mark the given enum (or set of enums, if using a pattern) as a Rust - /// enum with the `#[non_exhaustive]` attribute. - /// - /// This makes bindgen generate enums instead of constants. Regular - /// expressions are supported. - /// - /// **Use this with caution**, creating this in unsafe code - /// (including FFI) with an invalid value will invoke undefined behaviour. - /// You may want to use the newtype enum style instead. - pub fn rustified_non_exhaustive_enum>( - mut self, - arg: T, - ) -> Builder { - self.options.rustified_non_exhaustive_enums.insert(arg); - self - } - - /// Mark the given enum (or set of enums, if using a pattern) as a set of - /// constants that are not to be put into a module. - pub fn constified_enum>(mut self, arg: T) -> Builder { - self.options.constified_enums.insert(arg); - self - } - - /// Mark the given enum (or set of enums, if using a pattern) as a set of - /// constants that should be put into a module. - /// - /// This makes bindgen generate modules containing constants instead of - /// just constants. Regular expressions are supported. - pub fn constified_enum_module>(mut self, arg: T) -> Builder { - self.options.constified_enum_modules.insert(arg); - self + fn_with_regex_arg! { + /// Mark the given enum (or set of enums, if using a pattern) as being + /// bitfield-like. Regular expressions are supported. + /// + /// This makes bindgen generate a type that isn't a rust `enum`. Regular + /// expressions are supported. + /// + /// This is similar to the newtype enum style, but with the bitwise + /// operators implemented. + pub fn bitfield_enum>(mut self, arg: T) -> Builder { + self.options.bitfield_enums.insert(arg); + self + } + } + + fn_with_regex_arg! { + /// Mark the given enum (or set of enums, if using a pattern) as a newtype. + /// Regular expressions are supported. + /// + /// This makes bindgen generate a type that isn't a Rust `enum`. Regular + /// expressions are supported. + pub fn newtype_enum>(mut self, arg: T) -> Builder { + self.options.newtype_enums.insert(arg); + self + } + } + + fn_with_regex_arg! { + /// Mark the given enum (or set of enums, if using a pattern) as a newtype + /// whose variants are exposed as global constants. + /// + /// Regular expressions are supported. + /// + /// This makes bindgen generate a type that isn't a Rust `enum`. Regular + /// expressions are supported. + pub fn newtype_global_enum>(mut self, arg: T) -> Builder { + self.options.newtype_global_enums.insert(arg); + self + } + } + + fn_with_regex_arg! { + /// Mark the given enum (or set of enums, if using a pattern) as a Rust + /// enum. + /// + /// This makes bindgen generate enums instead of constants. Regular + /// expressions are supported. + /// + /// **Use this with caution**, creating this in unsafe code + /// (including FFI) with an invalid value will invoke undefined behaviour. + /// You may want to use the newtype enum style instead. + pub fn rustified_enum>(mut self, arg: T) -> Builder { + self.options.rustified_enums.insert(arg); + self + } + } + + fn_with_regex_arg! { + /// Mark the given enum (or set of enums, if using a pattern) as a Rust + /// enum with the `#[non_exhaustive]` attribute. + /// + /// This makes bindgen generate enums instead of constants. Regular + /// expressions are supported. + /// + /// **Use this with caution**, creating this in unsafe code + /// (including FFI) with an invalid value will invoke undefined behaviour. + /// You may want to use the newtype enum style instead. + pub fn rustified_non_exhaustive_enum>( + mut self, + arg: T, + ) -> Builder { + self.options.rustified_non_exhaustive_enums.insert(arg); + self + } + } + + fn_with_regex_arg! { + /// Mark the given enum (or set of enums, if using a pattern) as a set of + /// constants that are not to be put into a module. + pub fn constified_enum>(mut self, arg: T) -> Builder { + self.options.constified_enums.insert(arg); + self + } + } + + fn_with_regex_arg! { + /// Mark the given enum (or set of enums, if using a pattern) as a set of + /// constants that should be put into a module. + /// + /// This makes bindgen generate modules containing constants instead of + /// just constants. Regular expressions are supported. + pub fn constified_enum_module>(mut self, arg: T) -> Builder { + self.options.constified_enum_modules.insert(arg); + self + } } /// Set the default type for macro constants @@ -1103,34 +1142,40 @@ impl Builder { self } - /// Mark the given typedef alias (or set of aliases, if using a pattern) to - /// use regular Rust type aliasing. - /// - /// This is the default behavior and should be used if `default_alias_style` - /// was set to NewType or NewTypeDeref and you want to override it for a - /// set of typedefs. - pub fn type_alias>(mut self, arg: T) -> Builder { - self.options.type_alias.insert(arg); - self + fn_with_regex_arg! { + /// Mark the given typedef alias (or set of aliases, if using a pattern) to + /// use regular Rust type aliasing. + /// + /// This is the default behavior and should be used if `default_alias_style` + /// was set to NewType or NewTypeDeref and you want to override it for a + /// set of typedefs. + pub fn type_alias>(mut self, arg: T) -> Builder { + self.options.type_alias.insert(arg); + self + } } - /// Mark the given typedef alias (or set of aliases, if using a pattern) to - /// be generated as a new type by having the aliased type be wrapped in a - /// #[repr(transparent)] struct. - /// - /// Used to enforce stricter type checking. - pub fn new_type_alias>(mut self, arg: T) -> Builder { - self.options.new_type_alias.insert(arg); - self + fn_with_regex_arg! { + /// Mark the given typedef alias (or set of aliases, if using a pattern) to + /// be generated as a new type by having the aliased type be wrapped in a + /// #[repr(transparent)] struct. + /// + /// Used to enforce stricter type checking. + pub fn new_type_alias>(mut self, arg: T) -> Builder { + self.options.new_type_alias.insert(arg); + self + } } - /// Mark the given typedef alias (or set of aliases, if using a pattern) to - /// be generated as a new type by having the aliased type be wrapped in a - /// #[repr(transparent)] struct and also have an automatically generated - /// impl's of `Deref` and `DerefMut` to their aliased type. - pub fn new_type_alias_deref>(mut self, arg: T) -> Builder { - self.options.new_type_alias_deref.insert(arg); - self + fn_with_regex_arg! { + /// Mark the given typedef alias (or set of aliases, if using a pattern) to + /// be generated as a new type by having the aliased type be wrapped in a + /// #[repr(transparent)] struct and also have an automatically generated + /// impl's of `Deref` and `DerefMut` to their aliased type. + pub fn new_type_alias_deref>(mut self, arg: T) -> Builder { + self.options.new_type_alias_deref.insert(arg); + self + } } /// Set the default style of code to generate for unions with a non-Copy member. @@ -1142,28 +1187,34 @@ impl Builder { self } - /// Mark the given union (or set of union, if using a pattern) to use - /// a bindgen-generated wrapper for its members if at least one is non-Copy. - pub fn bindgen_wrapper_union>(mut self, arg: T) -> Self { - self.options.bindgen_wrapper_union.insert(arg); - self + fn_with_regex_arg! { + /// Mark the given union (or set of union, if using a pattern) to use + /// a bindgen-generated wrapper for its members if at least one is non-Copy. + pub fn bindgen_wrapper_union>(mut self, arg: T) -> Self { + self.options.bindgen_wrapper_union.insert(arg); + self + } } - /// Mark the given union (or set of union, if using a pattern) to use - /// [`::core::mem::ManuallyDrop`] for its members if at least one is non-Copy. - /// - /// Note: `ManuallyDrop` was stabilized in Rust 1.20.0, do not use it if your - /// MSRV is lower. - pub fn manually_drop_union>(mut self, arg: T) -> Self { - self.options.manually_drop_union.insert(arg); - self + fn_with_regex_arg! { + /// Mark the given union (or set of union, if using a pattern) to use + /// [`::core::mem::ManuallyDrop`] for its members if at least one is non-Copy. + /// + /// Note: `ManuallyDrop` was stabilized in Rust 1.20.0, do not use it if your + /// MSRV is lower. + pub fn manually_drop_union>(mut self, arg: T) -> Self { + self.options.manually_drop_union.insert(arg); + self + } } - /// Add a string to prepend to the generated bindings. The string is passed - /// through without any modification. - pub fn raw_line>(mut self, arg: T) -> Self { - self.options.raw_lines.push(arg.into()); - self + fn_with_regex_arg! { + /// Add a string to prepend to the generated bindings. The string is passed + /// through without any modification. + pub fn raw_line>(mut self, arg: T) -> Self { + self.options.raw_lines.push(arg.into()); + self + } } /// Add a given line to the beginning of module `mod`. @@ -1692,46 +1743,58 @@ impl Builder { } } - /// Don't derive `PartialEq` for a given type. Regular - /// expressions are supported. - pub fn no_partialeq>(mut self, arg: T) -> Builder { - self.options.no_partialeq_types.insert(arg.into()); - self + fn_with_regex_arg! { + /// Don't derive `PartialEq` for a given type. Regular + /// expressions are supported. + pub fn no_partialeq>(mut self, arg: T) -> Builder { + self.options.no_partialeq_types.insert(arg.into()); + self + } } - /// Don't derive `Copy` for a given type. Regular - /// expressions are supported. - pub fn no_copy>(mut self, arg: T) -> Self { - self.options.no_copy_types.insert(arg.into()); - self + fn_with_regex_arg! { + /// Don't derive `Copy` for a given type. Regular + /// expressions are supported. + pub fn no_copy>(mut self, arg: T) -> Self { + self.options.no_copy_types.insert(arg.into()); + self + } } - /// Don't derive `Debug` for a given type. Regular - /// expressions are supported. - pub fn no_debug>(mut self, arg: T) -> Self { - self.options.no_debug_types.insert(arg.into()); - self + fn_with_regex_arg! { + /// Don't derive `Debug` for a given type. Regular + /// expressions are supported. + pub fn no_debug>(mut self, arg: T) -> Self { + self.options.no_debug_types.insert(arg.into()); + self + } } - /// Don't derive/impl `Default` for a given type. Regular - /// expressions are supported. - pub fn no_default>(mut self, arg: T) -> Self { - self.options.no_default_types.insert(arg.into()); - self + fn_with_regex_arg! { + /// Don't derive/impl `Default` for a given type. Regular + /// expressions are supported. + pub fn no_default>(mut self, arg: T) -> Self { + self.options.no_default_types.insert(arg.into()); + self + } } - /// Don't derive `Hash` for a given type. Regular - /// expressions are supported. - pub fn no_hash>(mut self, arg: T) -> Builder { - self.options.no_hash_types.insert(arg.into()); - self + fn_with_regex_arg! { + /// Don't derive `Hash` for a given type. Regular + /// expressions are supported. + pub fn no_hash>(mut self, arg: T) -> Builder { + self.options.no_hash_types.insert(arg.into()); + self + } } - /// Add `#[must_use]` for the given type. Regular - /// expressions are supported. - pub fn must_use_type>(mut self, arg: T) -> Builder { - self.options.must_use_types.insert(arg.into()); - self + fn_with_regex_arg! { + /// Add `#[must_use]` for the given type. Regular + /// expressions are supported. + pub fn must_use_type>(mut self, arg: T) -> Builder { + self.options.must_use_types.insert(arg.into()); + self + } } /// Set whether `arr[size]` should be treated as `*mut T` or `*mut [T; size]` (same for mut) From c09bd2f5b58fb90fbcd906a4826d4ac26fe6ef1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 17 Nov 2022 04:35:26 +0100 Subject: [PATCH 413/942] v0.62.0 --- CHANGELOG.md | 149 ++++++++++++++++++++++++++++----------------------- 1 file changed, 82 insertions(+), 67 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 506878c408..d1c8ffb943 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,139 +7,143 @@ - [Removed](#removed) - [Fixed](#fixed) - [Security](#security) -- [0.61.0](#0610) +- [0.62.0](#0620) - [Added](#added-1) - [Changed](#changed-1) - [Fixed](#fixed-1) -- [0.60.1](#0601) - - [Fixed](#fixed-2) -- [0.60.0](#0600) +- [0.61.0](#0610) - [Added](#added-2) - - [Fixed](#fixed-3) - [Changed](#changed-2) + - [Fixed](#fixed-2) +- [0.60.1](#0601) + - [Fixed](#fixed-3) +- [0.60.0](#0600) + - [Added](#added-3) + - [Fixed](#fixed-4) + - [Changed](#changed-3) - [Removed](#removed-1) - [0.59.2](#0592) - [0.59.1](#0591) - - [Fixed](#fixed-4) -- [0.59.0](#0590) - - [Added](#added-3) - [Fixed](#fixed-5) - - [Changed](#changed-3) -- [0.58.1](#0581) +- [0.59.0](#0590) - [Added](#added-4) -- [0.58.0](#0580) - - [Added](#added-5) - [Fixed](#fixed-6) - [Changed](#changed-4) +- [0.58.1](#0581) + - [Added](#added-5) +- [0.58.0](#0580) + - [Added](#added-6) + - [Fixed](#fixed-7) + - [Changed](#changed-5) - [Deprecated](#deprecated) - [Removed](#removed-2) - - [Fixed](#fixed-7) + - [Fixed](#fixed-8) - [Security](#security-1) - [0.57.0](#0570) - - [Added](#added-6) - - [Fixed](#fixed-8) -- [0.56.0](#0560) - [Added](#added-7) - - [Changed](#changed-5) - [Fixed](#fixed-9) -- [0.55.1](#0551) - - [Fixed](#fixed-10) -- [0.55.0](#0550) - - [Removed](#removed-3) +- [0.56.0](#0560) - [Added](#added-8) - [Changed](#changed-6) + - [Fixed](#fixed-10) +- [0.55.1](#0551) - [Fixed](#fixed-11) -- [0.54.1](#0541) +- [0.55.0](#0550) + - [Removed](#removed-3) - [Added](#added-9) - [Changed](#changed-7) - [Fixed](#fixed-12) -- [0.54.0](#0540) +- [0.54.1](#0541) - [Added](#added-10) - [Changed](#changed-8) - [Fixed](#fixed-13) -- [0.53.3](#0533) +- [0.54.0](#0540) - [Added](#added-11) + - [Changed](#changed-9) - [Fixed](#fixed-14) +- [0.53.3](#0533) + - [Added](#added-12) + - [Fixed](#fixed-15) - [0.53.2](#0532) - - [Changed](#changed-9) + - [Changed](#changed-10) - [0.53.1](#0531) - - [Added](#added-12) -- [0.53.0](#0530) - [Added](#added-13) - - [Changed](#changed-10) - - [Fixed](#fixed-15) -- [0.52.0](#0520) +- [0.53.0](#0530) - [Added](#added-14) - [Changed](#changed-11) - [Fixed](#fixed-16) -- [0.51.1](#0511) - - [Fixed](#fixed-17) +- [0.52.0](#0520) + - [Added](#added-15) - [Changed](#changed-12) -- [0.51.0](#0510) + - [Fixed](#fixed-17) +- [0.51.1](#0511) - [Fixed](#fixed-18) - [Changed](#changed-13) - - [Added](#added-15) -- [0.50.0](#0500) +- [0.51.0](#0510) + - [Fixed](#fixed-19) + - [Changed](#changed-14) - [Added](#added-16) -- [0.49.3](#0493) +- [0.50.0](#0500) - [Added](#added-17) +- [0.49.3](#0493) + - [Added](#added-18) - [0.49.2](#0492) - - [Changed](#changed-14) -- [0.49.1](#0491) - - [Fixed](#fixed-19) - [Changed](#changed-15) -- [0.49.0](#0490) - - [Added](#added-18) +- [0.49.1](#0491) - [Fixed](#fixed-20) - [Changed](#changed-16) -- [0.48.1](#0481) +- [0.49.0](#0490) + - [Added](#added-19) - [Fixed](#fixed-21) -- [0.48.0](#0480) - [Changed](#changed-17) +- [0.48.1](#0481) - [Fixed](#fixed-22) -- [0.47.4](#0474) - - [Added](#added-19) -- [0.47.3](#0473) +- [0.48.0](#0480) - [Changed](#changed-18) -- [0.47.2](#0472) - [Fixed](#fixed-23) -- [0.47.1](#0471) +- [0.47.4](#0474) + - [Added](#added-20) +- [0.47.3](#0473) - [Changed](#changed-19) +- [0.47.2](#0472) - [Fixed](#fixed-24) -- [0.47.0](#0470) +- [0.47.1](#0471) - [Changed](#changed-20) - [Fixed](#fixed-25) -- [0.33.1 .. 0.46.0](#0331--0460) - - [Added](#added-20) - - [Removed](#removed-4) +- [0.47.0](#0470) - [Changed](#changed-21) - [Fixed](#fixed-26) -- [0.33.1](#0331) +- [0.33.1 .. 0.46.0](#0331--0460) + - [Added](#added-21) + - [Removed](#removed-4) + - [Changed](#changed-22) - [Fixed](#fixed-27) +- [0.33.1](#0331) + - [Fixed](#fixed-28) - [0.33.0](#0330) - [0.32.2](#0322) - - [Fixed](#fixed-28) -- [0.32.1](#0321) - [Fixed](#fixed-29) -- [0.32.0](#0320) - - [Added](#added-21) - - [Changed](#changed-22) +- [0.32.1](#0321) - [Fixed](#fixed-30) -- [0.31.0](#0310) +- [0.32.0](#0320) - [Added](#added-22) - [Changed](#changed-23) - - [Deprecated](#deprecated-1) - - [Removed](#removed-5) - [Fixed](#fixed-31) -- [0.30.0](#0300) +- [0.31.0](#0310) - [Added](#added-23) - [Changed](#changed-24) - - [Deprecated](#deprecated-2) + - [Deprecated](#deprecated-1) + - [Removed](#removed-5) - [Fixed](#fixed-32) -- [0.29.0](#0290) +- [0.30.0](#0300) - [Added](#added-24) - [Changed](#changed-25) + - [Deprecated](#deprecated-2) - [Fixed](#fixed-33) +- [0.29.0](#0290) + - [Added](#added-25) + - [Changed](#changed-26) + - [Fixed](#fixed-34) @@ -148,6 +152,19 @@ # Unreleased ## Added + +## Changed + +## Removed + +## Fixed + +## Security + +# 0.62.0 + +## Added + * new feature: `--override-abi` flag to override the ABI used by functions matching a regular expression. * new feature: allow using the `C-unwind` ABI in `--override-abi` on nightly @@ -163,11 +180,9 @@ * any generated rust code containing unsafe operations inside unsafe functions is wrapped in unsafe blocks now. -## Removed - ## Fixed -## Security + * Various issues with upcoming clang/libclang versions have been fixed. # 0.61.0 From ce534c1a139745198285ae64b09e81e0a0afe28a Mon Sep 17 00:00:00 2001 From: Fabio Valentini Date: Thu, 17 Nov 2022 14:31:01 +0100 Subject: [PATCH 414/942] add LICENSE symlinks to all individually published crates --- bindgen-cli/LICENSE | 1 + bindgen/LICENSE | 1 + 2 files changed, 2 insertions(+) create mode 120000 bindgen-cli/LICENSE create mode 120000 bindgen/LICENSE diff --git a/bindgen-cli/LICENSE b/bindgen-cli/LICENSE new file mode 120000 index 0000000000..ea5b60640b --- /dev/null +++ b/bindgen-cli/LICENSE @@ -0,0 +1 @@ +../LICENSE \ No newline at end of file diff --git a/bindgen/LICENSE b/bindgen/LICENSE new file mode 120000 index 0000000000..ea5b60640b --- /dev/null +++ b/bindgen/LICENSE @@ -0,0 +1 @@ +../LICENSE \ No newline at end of file From 8fe230830fa56e94efcaaa6833d536eec894a71e Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Thu, 17 Nov 2022 10:02:29 -0500 Subject: [PATCH 415/942] Remove deprecated methods (#2346) --- CHANGELOG.md | 6 ++ Cargo.lock | 4 +- bindgen-cli/Cargo.toml | 2 +- bindgen-cli/options.rs | 23 +---- .../tests/whitelist-alternates.rs | 39 -------- .../tests/headers/whitelist-alternates.h | 8 -- bindgen/Cargo.toml | 2 +- bindgen/lib.rs | 95 ------------------- 8 files changed, 11 insertions(+), 168 deletions(-) delete mode 100644 bindgen-tests/tests/expectations/tests/whitelist-alternates.rs delete mode 100644 bindgen-tests/tests/headers/whitelist-alternates.h diff --git a/CHANGELOG.md b/CHANGELOG.md index d1c8ffb943..237e3801c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -157,6 +157,12 @@ ## Removed + * The following deprecated methods and their equivalent CLI arguments were + removed: `whitelist_recursively`, `hide_type`, `blacklist_type`, + `blacklist_function`, `blacklist_item`, `whitelisted_type`, + `whitelist_type`, `whitelist_function`, `whitelisted_function`, + `whitelist_var`, `whitelisted_var`, `unstable_rust`. + ## Fixed ## Security diff --git a/Cargo.lock b/Cargo.lock index d656f9dd32..ff13ebcb5e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -48,7 +48,7 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bindgen" -version = "0.62.0" +version = "0.63.0" dependencies = [ "bitflags", "cexpr", @@ -68,7 +68,7 @@ dependencies = [ [[package]] name = "bindgen-cli" -version = "0.62.0" +version = "0.63.0" dependencies = [ "bindgen", "clap 3.2.12", diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index 7bff8f46b8..b2b56a9434 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -11,7 +11,7 @@ readme = "../README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.62.0" +version = "0.63.0" edition = "2018" # If you change this, also update README.md and msrv in .github/workflows/bindgen.yml rust-version = "1.57.0" diff --git a/bindgen-cli/options.rs b/bindgen-cli/options.rs index 482f9a7d98..426e5cf795 100644 --- a/bindgen-cli/options.rs +++ b/bindgen-cli/options.rs @@ -5,7 +5,7 @@ use bindgen::{ }; use clap::{App, Arg}; use std::fs::File; -use std::io::{self, stderr, Error, ErrorKind, Write}; +use std::io::{self, Error, ErrorKind}; use std::path::PathBuf; use std::str::FromStr; @@ -175,28 +175,24 @@ where .multiple_occurrences(true) .number_of_values(1), Arg::new("blocklist-type") - .alias("blacklist-type") .long("blocklist-type") .help("Mark as hidden.") .value_name("type") .multiple_occurrences(true) .number_of_values(1), Arg::new("blocklist-function") - .alias("blacklist-function") .long("blocklist-function") .help("Mark as hidden.") .value_name("function") .multiple_occurrences(true) .number_of_values(1), Arg::new("blocklist-item") - .alias("blacklist-item") .long("blocklist-item") .help("Mark as hidden.") .value_name("item") .multiple_occurrences(true) .number_of_values(1), Arg::new("blocklist-file") - .alias("blacklist-file") .long("blocklist-file") .help("Mark all contents of as hidden.") .value_name("path") @@ -257,7 +253,6 @@ where ), Arg::new("no-recursive-allowlist") .long("no-recursive-allowlist") - .alias("no-recursive-whitelist") .help( "Disable allowlisting types recursively. This will cause \ bindgen to emit Rust code that won't compile! See the \ @@ -362,10 +357,6 @@ where Arg::new("fit-macro-constant-types") .long("fit-macro-constant-types") .help("Try to fit macro constants into types smaller than u32/i32"), - Arg::new("unstable-rust") - .long("unstable-rust") - .help("Generate unstable Rust code (deprecated; use --rust-target instead).") - .multiple_occurrences(true), // FIXME: Pass legacy test suite Arg::new("opaque-type") .long("opaque-type") .help("Mark as opaque.") @@ -406,7 +397,6 @@ where .help("MSVC C++ ABI mangling. DEPRECATED: Has no effect."), Arg::new("allowlist-function") .long("allowlist-function") - .alias("whitelist-function") .help( "Allowlist all the free-standing functions matching \ . Other non-allowlisted functions will not be \ @@ -420,7 +410,6 @@ where .help("Generate inline functions."), Arg::new("allowlist-type") .long("allowlist-type") - .alias("whitelist-type") .help( "Only generate types matching . Other non-allowlisted types will \ not be generated.", @@ -430,7 +419,6 @@ where .number_of_values(1), Arg::new("allowlist-var") .long("allowlist-var") - .alias("whitelist-var") .help( "Allowlist all the free-standing variables matching \ . Other non-allowlisted variables will not be \ @@ -600,15 +588,6 @@ where return Err(Error::new(ErrorKind::Other, "Header not found")); } - if matches.is_present("unstable-rust") { - builder = builder.rust_target(RustTarget::Nightly); - writeln!( - &mut stderr(), - "warning: the `--unstable-rust` option is deprecated" - ) - .expect("Unable to write error message"); - } - if let Some(rust_target) = matches.value_of("rust-target") { builder = builder.rust_target(RustTarget::from_str(rust_target)?); } diff --git a/bindgen-tests/tests/expectations/tests/whitelist-alternates.rs b/bindgen-tests/tests/expectations/tests/whitelist-alternates.rs deleted file mode 100644 index 77d963d81e..0000000000 --- a/bindgen-tests/tests/expectations/tests/whitelist-alternates.rs +++ /dev/null @@ -1,39 +0,0 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct WhitelistedType {} -#[test] -fn bindgen_test_layout_WhitelistedType() { - assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(WhitelistedType)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(WhitelistedType)) - ); -} -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct AllowType {} -#[test] -fn bindgen_test_layout_AllowType() { - assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(AllowType)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(AllowType)) - ); -} diff --git a/bindgen-tests/tests/headers/whitelist-alternates.h b/bindgen-tests/tests/headers/whitelist-alternates.h deleted file mode 100644 index 7aa3bf8711..0000000000 --- a/bindgen-tests/tests/headers/whitelist-alternates.h +++ /dev/null @@ -1,8 +0,0 @@ -// bindgen-flags: --whitelist-type 'Whitelisted.*|Allow.*' -// Test for changes introduced in #1756 - -struct WhitelistedType {}; -struct AllowType {}; -// this would have been accepted because the start anchor -// wouldn't be applied to the second alternative: -struct NoAllowType {}; diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index 13e5f44590..652220955b 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -14,7 +14,7 @@ readme = "../README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.62.0" +version = "0.63.0" edition = "2018" build = "build.rs" # If you change this, also update README.md and msrv in .github/workflows/bindgen.yml diff --git a/bindgen/lib.rs b/bindgen/lib.rs index e18a2a992c..bfc22bb6b4 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -796,12 +796,6 @@ impl Builder { self } - /// Deprecated alias for allowlist_recursively. - #[deprecated(note = "Use allowlist_recursively instead")] - pub fn whitelist_recursively(self, doit: bool) -> Self { - self.allowlist_recursively(doit) - } - /// Generate `#[macro_use] extern crate objc;` instead of `use objc;` /// in the prologue of the files generated from objective-c files pub fn objc_extern_crate(mut self, doit: bool) -> Self { @@ -834,20 +828,6 @@ impl Builder { self } - /// Hide the given type from the generated bindings. Regular expressions are - /// supported. - #[deprecated(note = "Use blocklist_type instead")] - pub fn hide_type>(self, arg: T) -> Builder { - self.blocklist_type(arg) - } - - /// Hide the given type from the generated bindings. Regular expressions are - /// supported. - #[deprecated(note = "Use blocklist_type instead")] - pub fn blacklist_type>(self, arg: T) -> Builder { - self.blocklist_type(arg) - } - fn_with_regex_arg! { /// Hide the given type from the generated bindings. Regular expressions are /// supported. @@ -859,15 +839,6 @@ impl Builder { } } - fn_with_regex_arg! { - /// Hide the given function from the generated bindings. Regular expressions - /// are supported. - #[deprecated(note = "Use blocklist_function instead")] - pub fn blacklist_function>(self, arg: T) -> Builder { - self.blocklist_function(arg) - } - } - fn_with_regex_arg! { /// Hide the given function from the generated bindings. Regular expressions /// are supported. @@ -883,15 +854,6 @@ impl Builder { } } - /// Hide the given item from the generated bindings, regardless of - /// whether it's a type, function, module, etc. Regular - /// expressions are supported. - #[deprecated(note = "Use blocklist_item instead")] - pub fn blacklist_item>(mut self, arg: T) -> Builder { - self.options.blocklisted_items.insert(arg); - self - } - fn_with_regex_arg! { /// Hide the given item from the generated bindings, regardless of /// whether it's a type, function, module, etc. Regular @@ -924,22 +886,6 @@ impl Builder { } } - /// Allowlist the given type so that it (and all types that it transitively - /// refers to) appears in the generated bindings. Regular expressions are - /// supported. - #[deprecated(note = "use allowlist_type instead")] - pub fn whitelisted_type>(self, arg: T) -> Builder { - self.allowlist_type(arg) - } - - /// Allowlist the given type so that it (and all types that it transitively - /// refers to) appears in the generated bindings. Regular expressions are - /// supported. - #[deprecated(note = "use allowlist_type instead")] - pub fn whitelist_type>(self, arg: T) -> Builder { - self.allowlist_type(arg) - } - fn_with_regex_arg! { /// Allowlist the given type so that it (and all types that it transitively /// refers to) appears in the generated bindings. Regular expressions are @@ -968,22 +914,6 @@ impl Builder { } } - /// Allowlist the given function. - /// - /// Deprecated: use allowlist_function instead. - #[deprecated(note = "use allowlist_function instead")] - pub fn whitelist_function>(self, arg: T) -> Builder { - self.allowlist_function(arg) - } - - /// Allowlist the given function. - /// - /// Deprecated: use allowlist_function instead. - #[deprecated(note = "use allowlist_function instead")] - pub fn whitelisted_function>(self, arg: T) -> Builder { - self.allowlist_function(arg) - } - fn_with_regex_arg! { /// Allowlist the given variable so that it (and all types that it /// transitively refers to) appears in the generated bindings. Regular @@ -1004,20 +934,6 @@ impl Builder { } } - /// Deprecated: use allowlist_var instead. - #[deprecated(note = "use allowlist_var instead")] - pub fn whitelist_var>(self, arg: T) -> Builder { - self.allowlist_var(arg) - } - - /// Allowlist the given variable. - /// - /// Deprecated: use allowlist_var instead. - #[deprecated(note = "use allowlist_var instead")] - pub fn whitelisted_var>(self, arg: T) -> Builder { - self.allowlist_var(arg) - } - /// Set the default style of code to generate for enums pub fn default_enum_style( mut self, @@ -1496,17 +1412,6 @@ impl Builder { self } - /// Avoid generating any unstable Rust, such as Rust unions, in the generated bindings. - #[deprecated(note = "please use `rust_target` instead")] - pub fn unstable_rust(self, doit: bool) -> Self { - let rust_target = if doit { - RustTarget::Nightly - } else { - LATEST_STABLE_RUST - }; - self.rust_target(rust_target) - } - /// Use core instead of libstd in the generated bindings. pub fn use_core(mut self) -> Builder { self.options.use_core = true; From 34f0bacb7eb72413c9c27684cb01a205ee43037e Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Mon, 21 Nov 2022 10:38:42 -0500 Subject: [PATCH 416/942] Introduce `DeriveInfo` (#2355) This PR introduces a new non-exhaustive `struct` called `DeriveInfo` to be used as the sole argument of `ParseCallbacks::add_derives` with the purpose of being able to extend the information passed to this method in a backwards-compatible manner, meaning that adding new fields to `DeriveInfo` won't be a breaking change when releasing a new version. --- CHANGELOG.md | 3 +++ bindgen-integration/build.rs | 10 ++++++---- bindgen/callbacks.rs | 10 +++++++++- bindgen/codegen/mod.rs | 13 ++++++++----- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 237e3801c3..9224c018a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -155,6 +155,9 @@ ## Changed + * Replace the `name: &str` argument for `ParseCallbacks::add_derives` by + `info: DeriveInfo`. + ## Removed * The following deprecated methods and their equivalent CLI arguments were diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs index 980d40b956..0f30ad470f 100644 --- a/bindgen-integration/build.rs +++ b/bindgen-integration/build.rs @@ -1,7 +1,9 @@ extern crate bindgen; extern crate cc; -use bindgen::callbacks::{IntKind, MacroParsingBehavior, ParseCallbacks}; +use bindgen::callbacks::{ + DeriveInfo, IntKind, MacroParsingBehavior, ParseCallbacks, +}; use bindgen::{Builder, EnumVariation}; use std::collections::HashSet; use std::env; @@ -121,10 +123,10 @@ impl ParseCallbacks for MacroCallback { } // Test the "custom derives" capability by adding `PartialEq` to the `Test` struct. - fn add_derives(&self, name: &str) -> Vec { - if name == "Test" { + fn add_derives(&self, info: &DeriveInfo<'_>) -> Vec { + if info.name == "Test" { vec!["PartialEq".into()] - } else if name == "MyOrderedEnum" { + } else if info.name == "MyOrderedEnum" { vec!["std::cmp::PartialOrd".into()] } else { vec![] diff --git a/bindgen/callbacks.rs b/bindgen/callbacks.rs index fb84c8c331..bebd6978aa 100644 --- a/bindgen/callbacks.rs +++ b/bindgen/callbacks.rs @@ -105,7 +105,15 @@ pub trait ParseCallbacks: fmt::Debug { /// /// If no additional attributes are wanted, this function should return an /// empty `Vec`. - fn add_derives(&self, _name: &str) -> Vec { + fn add_derives(&self, _info: &DeriveInfo<'_>) -> Vec { vec![] } } + +/// Relevant information about a type to which new derive attributes will be added using +/// [`ParseCallbacks::add_derives`]. +#[non_exhaustive] +pub struct DeriveInfo<'a> { + /// The name of the type. + pub name: &'a str, +} diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index c7ac59db42..e758963ac0 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -2114,9 +2114,11 @@ impl CodeGenerator for CompInfo { // The custom derives callback may return a list of derive attributes; // add them to the end of the list. - let custom_derives = ctx - .options() - .all_callbacks(|cb| cb.add_derives(&canonical_name)); + let custom_derives = ctx.options().all_callbacks(|cb| { + cb.add_derives(&crate::callbacks::DeriveInfo { + name: &canonical_name, + }) + }); // In most cases this will be a no-op, since custom_derives will be empty. derives.extend(custom_derives.iter().map(|s| s.as_str())); @@ -3168,8 +3170,9 @@ impl CodeGenerator for Enum { // The custom derives callback may return a list of derive attributes; // add them to the end of the list. - let custom_derives = - ctx.options().all_callbacks(|cb| cb.add_derives(&name)); + let custom_derives = ctx.options().all_callbacks(|cb| { + cb.add_derives(&crate::callbacks::DeriveInfo { name: &name }) + }); // In most cases this will be a no-op, since custom_derives will be empty. derives.extend(custom_derives.iter().map(|s| s.as_str())); From f160d11d56007fe1b1125d04f0cb31af0b18fc6e Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Tue, 22 Nov 2022 11:25:13 -0500 Subject: [PATCH 417/942] Add `ParseCallbacks::process_comment` (#2347) This method can be used to process comments and replace them with whatever the user wants. --- CHANGELOG.md | 2 ++ bindgen/callbacks.rs | 5 ++++ bindgen/codegen/helpers.rs | 8 +++--- bindgen/codegen/mod.rs | 52 +++----------------------------------- bindgen/ir/comment.rs | 51 ++++++++++++------------------------- bindgen/ir/item.rs | 7 +++-- bindgen/lib.rs | 10 ++++++++ 7 files changed, 45 insertions(+), 90 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9224c018a7..2c9889f263 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -178,6 +178,8 @@ matching a regular expression. * new feature: allow using the `C-unwind` ABI in `--override-abi` on nightly rust. + * new feature: `process_comments` method to the `ParseCallbacks` trait to + handle source code comments. ## Changed diff --git a/bindgen/callbacks.rs b/bindgen/callbacks.rs index bebd6978aa..5e8ac78839 100644 --- a/bindgen/callbacks.rs +++ b/bindgen/callbacks.rs @@ -108,6 +108,11 @@ pub trait ParseCallbacks: fmt::Debug { fn add_derives(&self, _info: &DeriveInfo<'_>) -> Vec { vec![] } + + /// Process a source code comment. + fn process_comment(&self, _comment: &str) -> Option { + None + } } /// Relevant information about a type to which new derive attributes will be added using diff --git a/bindgen/codegen/helpers.rs b/bindgen/codegen/helpers.rs index 5bf36acb42..088c7f9363 100644 --- a/bindgen/codegen/helpers.rs +++ b/bindgen/codegen/helpers.rs @@ -55,9 +55,11 @@ pub mod attributes { } pub fn doc(comment: String) -> TokenStream { - // NOTE(emilio): By this point comments are already preprocessed and in - // `///` form. Quote turns them into `#[doc]` comments, but oh well. - TokenStream::from_str(&comment).unwrap() + if comment.is_empty() { + quote!() + } else { + quote!(#[doc = #comment]) + } } pub fn link_name(name: &str) -> TokenStream { diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index e758963ac0..c1e92b77d5 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -20,7 +20,6 @@ use super::BindgenOptions; use crate::ir::analysis::{HasVtable, Sizedness}; use crate::ir::annotations::FieldAccessorKind; -use crate::ir::comment; use crate::ir::comp::{ Bitfield, BitfieldUnit, CompInfo, CompKind, Field, FieldData, FieldMethods, Method, MethodKind, @@ -1245,7 +1244,6 @@ trait FieldCodegen<'a> { &self, ctx: &BindgenContext, fields_should_be_private: bool, - codegen_depth: usize, accessor_kind: FieldAccessorKind, parent: &CompInfo, result: &mut CodegenResult, @@ -1265,7 +1263,6 @@ impl<'a> FieldCodegen<'a> for Field { &self, ctx: &BindgenContext, fields_should_be_private: bool, - codegen_depth: usize, accessor_kind: FieldAccessorKind, parent: &CompInfo, result: &mut CodegenResult, @@ -1282,7 +1279,6 @@ impl<'a> FieldCodegen<'a> for Field { data.codegen( ctx, fields_should_be_private, - codegen_depth, accessor_kind, parent, result, @@ -1296,7 +1292,6 @@ impl<'a> FieldCodegen<'a> for Field { unit.codegen( ctx, fields_should_be_private, - codegen_depth, accessor_kind, parent, result, @@ -1346,7 +1341,6 @@ impl<'a> FieldCodegen<'a> for FieldData { &self, ctx: &BindgenContext, fields_should_be_private: bool, - codegen_depth: usize, accessor_kind: FieldAccessorKind, parent: &CompInfo, result: &mut CodegenResult, @@ -1392,8 +1386,7 @@ impl<'a> FieldCodegen<'a> for FieldData { let mut field = quote! {}; if ctx.options().generate_comments { if let Some(raw_comment) = self.comment() { - let comment = - comment::preprocess(raw_comment, codegen_depth + 1); + let comment = ctx.options().process_comment(raw_comment); field = attributes::doc(comment); } } @@ -1553,7 +1546,6 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit { &self, ctx: &BindgenContext, fields_should_be_private: bool, - codegen_depth: usize, accessor_kind: FieldAccessorKind, parent: &CompInfo, result: &mut CodegenResult, @@ -1630,7 +1622,6 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit { bf.codegen( ctx, fields_should_be_private, - codegen_depth, accessor_kind, parent, result, @@ -1705,7 +1696,6 @@ impl<'a> FieldCodegen<'a> for Bitfield { &self, ctx: &BindgenContext, fields_should_be_private: bool, - _codegen_depth: usize, _accessor_kind: FieldAccessorKind, parent: &CompInfo, _result: &mut CodegenResult, @@ -1883,7 +1873,6 @@ impl CodeGenerator for CompInfo { let mut methods = vec![]; if !is_opaque { - let codegen_depth = item.codegen_depth(ctx); let fields_should_be_private = item.annotations().private_fields().unwrap_or(false); let struct_accessor_kind = item @@ -1894,7 +1883,6 @@ impl CodeGenerator for CompInfo { field.codegen( ctx, fields_should_be_private, - codegen_depth, struct_accessor_kind, self, result, @@ -2703,14 +2691,12 @@ impl std::str::FromStr for EnumVariation { /// A helper type to construct different enum variations. enum EnumBuilder<'a> { Rust { - codegen_depth: usize, attrs: Vec, ident: Ident, tokens: proc_macro2::TokenStream, emitted_any_variants: bool, }, NewType { - codegen_depth: usize, canonical_name: &'a str, tokens: proc_macro2::TokenStream, is_bitfield: bool, @@ -2718,26 +2704,14 @@ enum EnumBuilder<'a> { }, Consts { variants: Vec, - codegen_depth: usize, }, ModuleConsts { - codegen_depth: usize, module_name: &'a str, module_items: Vec, }, } impl<'a> EnumBuilder<'a> { - /// Returns the depth of the code generation for a variant of this enum. - fn codegen_depth(&self) -> usize { - match *self { - EnumBuilder::Rust { codegen_depth, .. } | - EnumBuilder::NewType { codegen_depth, .. } | - EnumBuilder::ModuleConsts { codegen_depth, .. } | - EnumBuilder::Consts { codegen_depth, .. } => codegen_depth, - } - } - /// Returns true if the builder is for a rustified enum. fn is_rust_enum(&self) -> bool { matches!(*self, EnumBuilder::Rust { .. }) @@ -2750,7 +2724,6 @@ impl<'a> EnumBuilder<'a> { mut attrs: Vec, repr: proc_macro2::TokenStream, enum_variation: EnumVariation, - enum_codegen_depth: usize, ) -> Self { let ident = Ident::new(name, Span::call_site()); @@ -2759,7 +2732,6 @@ impl<'a> EnumBuilder<'a> { is_bitfield, is_global, } => EnumBuilder::NewType { - codegen_depth: enum_codegen_depth, canonical_name: name, tokens: quote! { #( #attrs )* @@ -2774,7 +2746,6 @@ impl<'a> EnumBuilder<'a> { attrs.insert(0, quote! { #[repr( #repr )] }); let tokens = quote!(); EnumBuilder::Rust { - codegen_depth: enum_codegen_depth + 1, attrs, ident, tokens, @@ -2790,10 +2761,7 @@ impl<'a> EnumBuilder<'a> { pub type #ident = #repr; }); - EnumBuilder::Consts { - variants, - codegen_depth: enum_codegen_depth, - } + EnumBuilder::Consts { variants } } EnumVariation::ModuleConsts => { @@ -2807,7 +2775,6 @@ impl<'a> EnumBuilder<'a> { }; EnumBuilder::ModuleConsts { - codegen_depth: enum_codegen_depth + 1, module_name: name, module_items: vec![type_definition], } @@ -2839,8 +2806,7 @@ impl<'a> EnumBuilder<'a> { let mut doc = quote! {}; if ctx.options().generate_comments { if let Some(raw_comment) = variant.comment() { - let comment = - comment::preprocess(raw_comment, self.codegen_depth()); + let comment = ctx.options().process_comment(raw_comment); doc = attributes::doc(comment); } } @@ -2851,13 +2817,11 @@ impl<'a> EnumBuilder<'a> { ident, tokens, emitted_any_variants: _, - codegen_depth, } => { let name = ctx.rust_ident(variant_name); EnumBuilder::Rust { attrs, ident, - codegen_depth, tokens: quote! { #tokens #doc @@ -2918,7 +2882,6 @@ impl<'a> EnumBuilder<'a> { self } EnumBuilder::ModuleConsts { - codegen_depth, module_name, mut module_items, } => { @@ -2932,7 +2895,6 @@ impl<'a> EnumBuilder<'a> { EnumBuilder::ModuleConsts { module_name, module_items, - codegen_depth, } } } @@ -3211,13 +3173,7 @@ impl CodeGenerator for Enum { let repr = repr.to_rust_ty_or_opaque(ctx, item); - let mut builder = EnumBuilder::new( - &name, - attrs, - repr, - variation, - item.codegen_depth(ctx), - ); + let mut builder = EnumBuilder::new(&name, attrs, repr, variation); // A map where we keep a value -> variant relation. let mut seen_values = HashMap::<_, Ident>::default(); diff --git a/bindgen/ir/comment.rs b/bindgen/ir/comment.rs index c96e3ebb9e..3eb17aacb9 100644 --- a/bindgen/ir/comment.rs +++ b/bindgen/ir/comment.rs @@ -12,10 +12,10 @@ enum Kind { } /// Preprocesses a C/C++ comment so that it is a valid Rust comment. -pub fn preprocess(comment: &str, indent: usize) -> String { +pub fn preprocess(comment: &str) -> String { match self::kind(comment) { - Some(Kind::SingleLines) => preprocess_single_lines(comment, indent), - Some(Kind::MultiLine) => preprocess_multi_line(comment, indent), + Some(Kind::SingleLines) => preprocess_single_lines(comment), + Some(Kind::MultiLine) => preprocess_multi_line(comment), None => comment.to_owned(), } } @@ -31,56 +31,34 @@ fn kind(comment: &str) -> Option { } } -fn make_indent(indent: usize) -> String { - const RUST_INDENTATION: usize = 4; - " ".repeat(indent * RUST_INDENTATION) -} - /// Preprocesses multiple single line comments. /// /// Handles lines starting with both `//` and `///`. -fn preprocess_single_lines(comment: &str, indent: usize) -> String { +fn preprocess_single_lines(comment: &str) -> String { debug_assert!(comment.starts_with("//"), "comment is not single line"); - let indent = make_indent(indent); - let mut is_first = true; let lines: Vec<_> = comment .lines() .map(|l| l.trim().trim_start_matches('/')) - .map(|l| { - let indent = if is_first { "" } else { &*indent }; - is_first = false; - format!("{}///{}", indent, l) - }) .collect(); lines.join("\n") } -fn preprocess_multi_line(comment: &str, indent: usize) -> String { +fn preprocess_multi_line(comment: &str) -> String { let comment = comment .trim_start_matches('/') .trim_end_matches('/') .trim_end_matches('*'); - let indent = make_indent(indent); // Strip any potential `*` characters preceding each line. - let mut is_first = true; let mut lines: Vec<_> = comment .lines() .map(|line| line.trim().trim_start_matches('*').trim_start_matches('!')) .skip_while(|line| line.trim().is_empty()) // Skip the first empty lines. - .map(|line| { - let indent = if is_first { "" } else { &*indent }; - is_first = false; - format!("{}///{}", indent, line) - }) .collect(); // Remove the trailing line corresponding to the `*/`. - if lines - .last() - .map_or(false, |l| l.trim().is_empty() || l.trim() == "///") - { + if lines.last().map_or(false, |l| l.trim().is_empty()) { lines.pop(); } @@ -99,21 +77,24 @@ mod test { #[test] fn processes_single_lines_correctly() { - assert_eq!(preprocess("/// hello", 0), "/// hello"); - assert_eq!(preprocess("// hello", 0), "/// hello"); - assert_eq!(preprocess("// hello", 0), "/// hello"); + assert_eq!(preprocess("///"), ""); + assert_eq!(preprocess("/// hello"), " hello"); + assert_eq!(preprocess("// hello"), " hello"); + assert_eq!(preprocess("// hello"), " hello"); } #[test] fn processes_multi_lines_correctly() { + assert_eq!(preprocess("/**/"), ""); + assert_eq!( - preprocess("/** hello \n * world \n * foo \n */", 0), - "/// hello\n/// world\n/// foo" + preprocess("/** hello \n * world \n * foo \n */"), + " hello\n world\n foo" ); assert_eq!( - preprocess("/**\nhello\n*world\n*foo\n*/", 0), - "///hello\n///world\n///foo" + preprocess("/**\nhello\n*world\n*foo\n*/"), + "hello\nworld\nfoo" ); } } diff --git a/bindgen/ir/item.rs b/bindgen/ir/item.rs index 446d78bda5..5e9aff9102 100644 --- a/bindgen/ir/item.rs +++ b/bindgen/ir/item.rs @@ -3,7 +3,6 @@ use super::super::codegen::{EnumVariation, CONSTIFIED_ENUM_MODULE_REPR_NAME}; use super::analysis::{HasVtable, HasVtableResult, Sizedness, SizednessResult}; use super::annotations::Annotations; -use super::comment; use super::comp::{CompKind, MethodKind}; use super::context::{BindgenContext, ItemId, PartialType, TypeId}; use super::derive::{ @@ -515,9 +514,9 @@ impl Item { return None; } - self.comment.as_ref().map(|comment| { - comment::preprocess(comment, self.codegen_depth(ctx)) - }) + self.comment + .as_ref() + .map(|comment| ctx.options().process_comment(comment)) } /// What kind of item is this? diff --git a/bindgen/lib.rs b/bindgen/lib.rs index bfc22bb6b4..d281e94967 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -78,6 +78,8 @@ doc_mod!(ir, ir_docs); doc_mod!(parse, parse_docs); doc_mod!(regex_set, regex_set_docs); +use ir::comment; + pub use crate::codegen::{ AliasVariation, EnumVariation, MacroTypeVariation, NonCopyUnionStyle, }; @@ -2176,6 +2178,14 @@ impl BindgenOptions { .flat_map(|cb| f(cb.as_ref())) .collect() } + + fn process_comment(&self, comment: &str) -> String { + let comment = comment::preprocess(comment); + self.parse_callbacks + .last() + .and_then(|cb| cb.process_comment(&comment)) + .unwrap_or(comment) + } } impl Default for BindgenOptions { From 046d6f9eea1803253c06dd99a0d38f5dcb5ed9c1 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Tue, 22 Nov 2022 11:41:32 -0500 Subject: [PATCH 418/942] Add `--wrap-unsafe-ops` option (#2354) This reverts commit e8ffb42ab66405ac56d04494a30e54b584f2d4dd and adds a new `--wrap-unsafe-ops` option as a workaround. --- .github/workflows/bindgen.yml | 2 - CHANGELOG.md | 2 + bindgen-cli/options.rs | 7 + .../tests/16-byte-alignment_1_0.rs | 4 +- .../expectations/tests/allowlist-file.rs | 2 +- .../tests/anon_struct_in_union_1_0.rs | 4 +- .../expectations/tests/anon_union_1_0.rs | 4 +- .../tests/attribute_warn_unused_result.rs | 2 +- ...rn_unused_result_no_attribute_detection.rs | 2 +- .../attribute_warn_unused_result_pre_1_27.rs | 2 +- .../tests/bindgen-union-inside-namespace.rs | 4 +- .../tests/bitfield-method-same-name.rs | 6 +- .../expectations/tests/blocklist-methods.rs | 2 +- .../tests/expectations/tests/class.rs | 12 +- .../tests/expectations/tests/class_1_0.rs | 16 +- .../tests/class_with_inner_struct_1_0.rs | 4 +- .../expectations/tests/class_with_typedef.rs | 8 +- .../expectations/tests/constructor-tp.rs | 8 +- .../tests/expectations/tests/constructors.rs | 24 +- .../expectations/tests/constructors_1_33.rs | 24 +- .../expectations/tests/deleted-function.rs | 12 +- .../tests/derive-bitfield-method-same-name.rs | 6 +- ...erive-hash-struct-with-incomplete-array.rs | 4 +- .../tests/derive-partialeq-union_1_0.rs | 4 +- .../tests/disable-untagged-union.rs | 4 +- .../tests/duplicated-definition-count.rs | 6 +- .../tests/dynamic_loading_attributes.rs | 10 +- .../tests/dynamic_loading_required.rs | 14 +- .../tests/dynamic_loading_simple.rs | 18 +- .../tests/dynamic_loading_template.rs | 14 +- .../tests/dynamic_loading_with_allowlist.rs | 16 +- .../tests/dynamic_loading_with_blocklist.rs | 26 +-- .../tests/dynamic_loading_with_class.rs | 24 +- .../expectations/tests/gen-constructors.rs | 8 +- .../expectations/tests/gen-destructors.rs | 2 +- .../expectations/tests/generate-inline.rs | 2 +- .../tests/incomplete-array-padding.rs | 4 +- .../tests/expectations/tests/issue-2019.rs | 4 +- .../tests/expectations/tests/issue-410.rs | 2 +- .../tests/expectations/tests/issue-447.rs | 14 +- .../tests/expectations/tests/issue-493.rs | 4 +- .../tests/expectations/tests/issue-493_1_0.rs | 4 +- .../tests/issue-643-inner-struct.rs | 4 +- ...07-opaque-types-methods-being-generated.rs | 10 +- .../tests/jsval_layout_opaque_1_0.rs | 4 +- .../tests/expectations/tests/layout_align.rs | 4 +- .../expectations/tests/layout_eth_conf_1_0.rs | 4 +- .../tests/layout_large_align_field.rs | 4 +- .../expectations/tests/layout_mbuf_1_0.rs | 4 +- .../tests/libclang-5/objc_template.rs | 4 +- .../expectations/tests/libclang-9/class.rs | 12 +- .../tests/libclang-9/class_1_0.rs | 16 +- ...erive-hash-struct-with-incomplete-array.rs | 4 +- .../libclang-9/incomplete-array-padding.rs | 4 +- .../libclang-9/issue-643-inner-struct.rs | 4 +- .../tests/libclang-9/layout_align.rs | 104 ++++----- .../tests/libclang-9/objc_template.rs | 4 +- .../tests/libclang-9/zero-sized-array.rs | 4 +- .../expectations/tests/method-mangling.rs | 2 +- .../expectations/tests/objc_allowlist.rs | 8 +- .../expectations/tests/objc_blocklist.rs | 4 +- .../tests/expectations/tests/objc_category.rs | 4 +- .../tests/expectations/tests/objc_class.rs | 2 +- .../expectations/tests/objc_class_method.rs | 14 +- .../tests/expectations/tests/objc_method.rs | 18 +- .../expectations/tests/objc_method_clash.rs | 4 +- .../tests/objc_pointer_return_types.rs | 4 +- .../expectations/tests/objc_property_fnptr.rs | 4 +- .../tests/expectations/tests/parm-union.rs | 2 +- .../tests/expectations/tests/public-dtor.rs | 106 ++++----- .../tests/struct_with_anon_union_1_0.rs | 4 +- .../struct_with_anon_unnamed_union_1_0.rs | 4 +- .../tests/struct_with_nesting_1_0.rs | 4 +- .../tests/expectations/tests/transform-op.rs | 4 +- .../tests/expectations/tests/typeref_1_0.rs | 4 +- .../expectations/tests/union-in-ns_1_0.rs | 4 +- .../expectations/tests/union_bitfield_1_0.rs | 4 +- .../tests/expectations/tests/union_dtor.rs | 2 +- .../expectations/tests/union_dtor_1_0.rs | 6 +- .../expectations/tests/union_fields_1_0.rs | 4 +- .../expectations/tests/union_template_1_0.rs | 4 +- .../tests/union_with_anon_struct_1_0.rs | 4 +- .../union_with_anon_struct_bitfield_1_0.rs | 4 +- .../tests/union_with_anon_union_1_0.rs | 4 +- .../union_with_anon_unnamed_struct_1_0.rs | 4 +- .../union_with_anon_unnamed_union_1_0.rs | 4 +- .../tests/union_with_big_member_1_0.rs | 4 +- .../tests/union_with_nesting_1_0.rs | 4 +- .../tests/union_with_non_copy_member.rs | 4 +- .../tests/expectations/tests/use-core_1_0.rs | 4 +- .../tests/expectations/tests/var-tracing.rs | 8 +- .../tests/wasm-constructor-returns.rs | 8 +- .../tests/win32-thiscall_nightly.rs | 4 +- .../tests/wrap_unsafe_ops_anon_union_1_0.rs | 107 +++++++++ .../tests/wrap_unsafe_ops_class.rs | 215 ++++++++++++++++++ .../wrap_unsafe_ops_dynamic_loading_simple.rs | 74 ++++++ .../tests/wrap_unsafe_ops_objc_class.rs | 38 ++++ .../tests/zero-size-array-align.rs | 4 +- .../expectations/tests/zero-sized-array.rs | 4 +- .../wrap_unsafe_ops_anon_union_1_0.hpp | 22 ++ .../tests/headers/wrap_unsafe_ops_class.hpp | 74 ++++++ .../wrap_unsafe_ops_dynamic_loading_simple.h | 5 + .../headers/wrap_unsafe_ops_objc_class.h | 10 + bindgen/codegen/dyngen.rs | 38 +++- bindgen/codegen/mod.rs | 64 +++--- bindgen/ir/context.rs | 11 +- bindgen/lib.rs | 14 ++ 107 files changed, 1009 insertions(+), 474 deletions(-) create mode 100644 bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_anon_union_1_0.rs create mode 100644 bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_class.rs create mode 100644 bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_dynamic_loading_simple.rs create mode 100644 bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_objc_class.rs create mode 100644 bindgen-tests/tests/headers/wrap_unsafe_ops_anon_union_1_0.hpp create mode 100644 bindgen-tests/tests/headers/wrap_unsafe_ops_class.hpp create mode 100644 bindgen-tests/tests/headers/wrap_unsafe_ops_dynamic_loading_simple.h create mode 100644 bindgen-tests/tests/headers/wrap_unsafe_ops_objc_class.h diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index f292d001aa..bc8477d503 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -89,8 +89,6 @@ jobs: - name: Test expectations run: cd bindgen-tests/tests/expectations && cargo test - env: - RUSTFLAGS: "-D unsafe_op_in_unsafe_fn -D unused_unsafe" test: runs-on: ${{matrix.os}} diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c9889f263..0664a6d8c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -154,6 +154,8 @@ ## Added ## Changed + * Only wrap unsafe operations in unsafe blocks if the `--wrap_unsafe_ops` + option is enabled. * Replace the `name: &str` argument for `ParseCallbacks::add_derives` by `info: DeriveInfo`. diff --git a/bindgen-cli/options.rs b/bindgen-cli/options.rs index 426e5cf795..f7fccc4ff4 100644 --- a/bindgen-cli/options.rs +++ b/bindgen-cli/options.rs @@ -562,6 +562,9 @@ where .value_name("override") .multiple_occurrences(true) .number_of_values(1), + Arg::new("wrap-unsafe-ops") + .long("wrap-unsafe-ops") + .help("Wrap unsafe operations in unsafe blocks."), Arg::new("V") .long("version") .help("Prints the version, and exits"), @@ -1085,5 +1088,9 @@ where } } + if matches.is_present("wrap-unsafe-ops") { + builder = builder.wrap_unsafe_ops(true); + } + Ok((builder, output, verbose)) } diff --git a/bindgen-tests/tests/expectations/tests/16-byte-alignment_1_0.rs b/bindgen-tests/tests/expectations/tests/16-byte-alignment_1_0.rs index ac6beee12d..369e2c75ea 100644 --- a/bindgen-tests/tests/expectations/tests/16-byte-alignment_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/16-byte-alignment_1_0.rs @@ -14,11 +14,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/allowlist-file.rs b/bindgen-tests/tests/expectations/tests/allowlist-file.rs index db35c22654..3b72fb75eb 100644 --- a/bindgen-tests/tests/expectations/tests/allowlist-file.rs +++ b/bindgen-tests/tests/expectations/tests/allowlist-file.rs @@ -41,7 +41,7 @@ extern "C" { impl someClass { #[inline] pub unsafe fn somePublicMethod(&mut self, foo: ::std::os::raw::c_int) { - unsafe { someClass_somePublicMethod(self, foo) } + someClass_somePublicMethod(self, foo) } } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/anon_struct_in_union_1_0.rs b/bindgen-tests/tests/expectations/tests/anon_struct_in_union_1_0.rs index 782ebdb4bb..cbc5ac9b3f 100644 --- a/bindgen-tests/tests/expectations/tests/anon_struct_in_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/anon_struct_in_union_1_0.rs @@ -14,11 +14,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/anon_union_1_0.rs b/bindgen-tests/tests/expectations/tests/anon_union_1_0.rs index ea6456bd75..63273e608f 100644 --- a/bindgen-tests/tests/expectations/tests/anon_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/anon_union_1_0.rs @@ -14,11 +14,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl ::std::default::Default for __BindgenUnionField { 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 f60d564a9a..12d5eab04b 100644 --- a/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result.rs +++ b/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result.rs @@ -38,7 +38,7 @@ impl Foo { &mut self, arg1: ::std::os::raw::c_int, ) -> ::std::os::raw::c_int { - unsafe { Foo_foo(self, arg1) } + Foo_foo(self, arg1) } } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_no_attribute_detection.rs b/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_no_attribute_detection.rs index 317d52297c..d860acd1b4 100644 --- a/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_no_attribute_detection.rs +++ b/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_no_attribute_detection.rs @@ -36,7 +36,7 @@ impl Foo { &mut self, arg1: ::std::os::raw::c_int, ) -> ::std::os::raw::c_int { - unsafe { Foo_foo(self, arg1) } + Foo_foo(self, arg1) } } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_pre_1_27.rs b/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_pre_1_27.rs index 317d52297c..d860acd1b4 100644 --- a/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_pre_1_27.rs +++ b/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_pre_1_27.rs @@ -36,7 +36,7 @@ impl Foo { &mut self, arg1: ::std::os::raw::c_int, ) -> ::std::os::raw::c_int { - unsafe { Foo_foo(self, arg1) } + Foo_foo(self, arg1) } } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/bindgen-union-inside-namespace.rs b/bindgen-tests/tests/expectations/tests/bindgen-union-inside-namespace.rs index e143e415eb..8a091cb5e2 100644 --- a/bindgen-tests/tests/expectations/tests/bindgen-union-inside-namespace.rs +++ b/bindgen-tests/tests/expectations/tests/bindgen-union-inside-namespace.rs @@ -16,11 +16,11 @@ pub mod root { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs b/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs index 91efa9b9da..e9c1a76d1c 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs @@ -151,14 +151,14 @@ impl Foo { } #[inline] pub unsafe fn type_(&mut self) -> ::std::os::raw::c_char { - unsafe { Foo_type(self) } + Foo_type(self) } #[inline] pub unsafe fn set_type_(&mut self, c: ::std::os::raw::c_char) { - unsafe { Foo_set_type_(self, c) } + Foo_set_type_(self, c) } #[inline] pub unsafe fn set_type(&mut self, c: ::std::os::raw::c_char) { - unsafe { Foo_set_type(self, c) } + Foo_set_type(self, c) } } diff --git a/bindgen-tests/tests/expectations/tests/blocklist-methods.rs b/bindgen-tests/tests/expectations/tests/blocklist-methods.rs index 5b625f0a4e..eadc0694ed 100644 --- a/bindgen-tests/tests/expectations/tests/blocklist-methods.rs +++ b/bindgen-tests/tests/expectations/tests/blocklist-methods.rs @@ -30,6 +30,6 @@ extern "C" { impl Foo { #[inline] pub unsafe fn foo(&mut self) -> ::std::os::raw::c_int { - unsafe { Foo_foo(self) } + Foo_foo(self) } } diff --git a/bindgen-tests/tests/expectations/tests/class.rs b/bindgen-tests/tests/expectations/tests/class.rs index 9b2158fedb..8542135b07 100644 --- a/bindgen-tests/tests/expectations/tests/class.rs +++ b/bindgen-tests/tests/expectations/tests/class.rs @@ -23,11 +23,11 @@ impl __IncompleteArrayField { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } + ::std::slice::from_raw_parts(self.as_ptr(), len) } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } + ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } impl ::std::fmt::Debug for __IncompleteArrayField { @@ -490,18 +490,18 @@ extern "C" { impl RealAbstractionWithTonsOfMethods { #[inline] pub unsafe fn bar(&self) { - unsafe { RealAbstractionWithTonsOfMethods_bar(self) } + RealAbstractionWithTonsOfMethods_bar(self) } #[inline] pub unsafe fn bar1(&mut self) { - unsafe { RealAbstractionWithTonsOfMethods_bar1(self) } + RealAbstractionWithTonsOfMethods_bar1(self) } #[inline] pub unsafe fn bar2(&mut self, foo: ::std::os::raw::c_int) { - unsafe { RealAbstractionWithTonsOfMethods_bar2(self, foo) } + RealAbstractionWithTonsOfMethods_bar2(self, foo) } #[inline] pub unsafe fn sta() { - unsafe { RealAbstractionWithTonsOfMethods_sta() } + RealAbstractionWithTonsOfMethods_sta() } } diff --git a/bindgen-tests/tests/expectations/tests/class_1_0.rs b/bindgen-tests/tests/expectations/tests/class_1_0.rs index 5163bae9be..f6c3021eb3 100644 --- a/bindgen-tests/tests/expectations/tests/class_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/class_1_0.rs @@ -23,11 +23,11 @@ impl __IncompleteArrayField { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } + ::std::slice::from_raw_parts(self.as_ptr(), len) } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } + ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } impl ::std::fmt::Debug for __IncompleteArrayField { @@ -44,11 +44,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl ::std::default::Default for __BindgenUnionField { @@ -541,18 +541,18 @@ impl Clone for RealAbstractionWithTonsOfMethods { impl RealAbstractionWithTonsOfMethods { #[inline] pub unsafe fn bar(&self) { - unsafe { RealAbstractionWithTonsOfMethods_bar(self) } + RealAbstractionWithTonsOfMethods_bar(self) } #[inline] pub unsafe fn bar1(&mut self) { - unsafe { RealAbstractionWithTonsOfMethods_bar1(self) } + RealAbstractionWithTonsOfMethods_bar1(self) } #[inline] pub unsafe fn bar2(&mut self, foo: ::std::os::raw::c_int) { - unsafe { RealAbstractionWithTonsOfMethods_bar2(self, foo) } + RealAbstractionWithTonsOfMethods_bar2(self, foo) } #[inline] pub unsafe fn sta() { - unsafe { RealAbstractionWithTonsOfMethods_sta() } + RealAbstractionWithTonsOfMethods_sta() } } diff --git a/bindgen-tests/tests/expectations/tests/class_with_inner_struct_1_0.rs b/bindgen-tests/tests/expectations/tests/class_with_inner_struct_1_0.rs index cf2122c625..42656079df 100644 --- a/bindgen-tests/tests/expectations/tests/class_with_inner_struct_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/class_with_inner_struct_1_0.rs @@ -14,11 +14,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/class_with_typedef.rs b/bindgen-tests/tests/expectations/tests/class_with_typedef.rs index 033b0c3c0b..65e86b2709 100644 --- a/bindgen-tests/tests/expectations/tests/class_with_typedef.rs +++ b/bindgen-tests/tests/expectations/tests/class_with_typedef.rs @@ -93,19 +93,19 @@ impl Default for C { impl C { #[inline] pub unsafe fn method(&mut self, c: C_MyInt) { - unsafe { C_method(self, c) } + C_method(self, c) } #[inline] pub unsafe fn methodRef(&mut self, c: *mut C_MyInt) { - unsafe { C_methodRef(self, c) } + C_methodRef(self, c) } #[inline] pub unsafe fn complexMethodRef(&mut self, c: *mut C_Lookup) { - unsafe { C_complexMethodRef(self, c) } + C_complexMethodRef(self, c) } #[inline] pub unsafe fn anotherMethod(&mut self, c: AnotherInt) { - unsafe { C_anotherMethod(self, c) } + C_anotherMethod(self, c) } } #[repr(C)] diff --git a/bindgen-tests/tests/expectations/tests/constructor-tp.rs b/bindgen-tests/tests/expectations/tests/constructor-tp.rs index 35c096d704..4b339dc3c4 100644 --- a/bindgen-tests/tests/expectations/tests/constructor-tp.rs +++ b/bindgen-tests/tests/expectations/tests/constructor-tp.rs @@ -35,10 +35,8 @@ extern "C" { impl Bar { #[inline] pub unsafe fn new() -> Self { - unsafe { - let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); - Bar_Bar(__bindgen_tmp.as_mut_ptr()); - __bindgen_tmp.assume_init() - } + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + Bar_Bar(__bindgen_tmp.as_mut_ptr()); + __bindgen_tmp.assume_init() } } diff --git a/bindgen-tests/tests/expectations/tests/constructors.rs b/bindgen-tests/tests/expectations/tests/constructors.rs index 615af667d0..2f13effbef 100644 --- a/bindgen-tests/tests/expectations/tests/constructors.rs +++ b/bindgen-tests/tests/expectations/tests/constructors.rs @@ -37,19 +37,15 @@ extern "C" { impl TestOverload { #[inline] pub unsafe fn new(arg1: ::std::os::raw::c_int) -> Self { - unsafe { - let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); - TestOverload_TestOverload(__bindgen_tmp.as_mut_ptr(), arg1); - __bindgen_tmp.assume_init() - } + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + TestOverload_TestOverload(__bindgen_tmp.as_mut_ptr(), arg1); + __bindgen_tmp.assume_init() } #[inline] pub unsafe fn new1(arg1: f64) -> Self { - unsafe { - let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); - TestOverload_TestOverload1(__bindgen_tmp.as_mut_ptr(), arg1); - __bindgen_tmp.assume_init() - } + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + TestOverload_TestOverload1(__bindgen_tmp.as_mut_ptr(), arg1); + __bindgen_tmp.assume_init() } } #[repr(C)] @@ -77,10 +73,8 @@ extern "C" { impl TestPublicNoArgs { #[inline] pub unsafe fn new() -> Self { - unsafe { - let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); - TestPublicNoArgs_TestPublicNoArgs(__bindgen_tmp.as_mut_ptr()); - __bindgen_tmp.assume_init() - } + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + TestPublicNoArgs_TestPublicNoArgs(__bindgen_tmp.as_mut_ptr()); + __bindgen_tmp.assume_init() } } diff --git a/bindgen-tests/tests/expectations/tests/constructors_1_33.rs b/bindgen-tests/tests/expectations/tests/constructors_1_33.rs index c9818ccaab..b5d333325b 100644 --- a/bindgen-tests/tests/expectations/tests/constructors_1_33.rs +++ b/bindgen-tests/tests/expectations/tests/constructors_1_33.rs @@ -39,19 +39,15 @@ extern "C" { impl TestOverload { #[inline] pub unsafe fn new(arg1: ::std::os::raw::c_int) -> Self { - unsafe { - let mut __bindgen_tmp = ::std::mem::uninitialized(); - TestOverload_TestOverload(&mut __bindgen_tmp, arg1); - __bindgen_tmp - } + let mut __bindgen_tmp = ::std::mem::uninitialized(); + TestOverload_TestOverload(&mut __bindgen_tmp, arg1); + __bindgen_tmp } #[inline] pub unsafe fn new1(arg1: f64) -> Self { - unsafe { - let mut __bindgen_tmp = ::std::mem::uninitialized(); - TestOverload_TestOverload1(&mut __bindgen_tmp, arg1); - __bindgen_tmp - } + let mut __bindgen_tmp = ::std::mem::uninitialized(); + TestOverload_TestOverload1(&mut __bindgen_tmp, arg1); + __bindgen_tmp } } #[repr(C)] @@ -79,10 +75,8 @@ extern "C" { impl TestPublicNoArgs { #[inline] pub unsafe fn new() -> Self { - unsafe { - let mut __bindgen_tmp = ::std::mem::uninitialized(); - TestPublicNoArgs_TestPublicNoArgs(&mut __bindgen_tmp); - __bindgen_tmp - } + let mut __bindgen_tmp = ::std::mem::uninitialized(); + TestPublicNoArgs_TestPublicNoArgs(&mut __bindgen_tmp); + __bindgen_tmp } } diff --git a/bindgen-tests/tests/expectations/tests/deleted-function.rs b/bindgen-tests/tests/expectations/tests/deleted-function.rs index 69a6961803..96967bb461 100644 --- a/bindgen-tests/tests/expectations/tests/deleted-function.rs +++ b/bindgen-tests/tests/expectations/tests/deleted-function.rs @@ -34,11 +34,11 @@ extern "C" { impl A { #[inline] pub unsafe fn inline_definition(&mut self) { - unsafe { A_inline_definition(self) } + A_inline_definition(self) } #[inline] pub unsafe fn out_of_line_definition(&mut self) { - unsafe { A_out_of_line_definition(self) } + A_out_of_line_definition(self) } } #[repr(C)] @@ -84,10 +84,8 @@ extern "C" { impl C { #[inline] pub unsafe fn new(arg1: *mut C) -> Self { - unsafe { - let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); - C_C(__bindgen_tmp.as_mut_ptr(), arg1); - __bindgen_tmp.assume_init() - } + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + C_C(__bindgen_tmp.as_mut_ptr(), arg1); + __bindgen_tmp.assume_init() } } diff --git a/bindgen-tests/tests/expectations/tests/derive-bitfield-method-same-name.rs b/bindgen-tests/tests/expectations/tests/derive-bitfield-method-same-name.rs index 97a539d91d..ea6621dd1c 100644 --- a/bindgen-tests/tests/expectations/tests/derive-bitfield-method-same-name.rs +++ b/bindgen-tests/tests/expectations/tests/derive-bitfield-method-same-name.rs @@ -202,14 +202,14 @@ impl Foo { } #[inline] pub unsafe fn type_(&mut self) -> ::std::os::raw::c_char { - unsafe { Foo_type(self) } + Foo_type(self) } #[inline] pub unsafe fn set_type_(&mut self, c: ::std::os::raw::c_char) { - unsafe { Foo_set_type_(self, c) } + Foo_set_type_(self, c) } #[inline] pub unsafe fn set_type(&mut self, c: ::std::os::raw::c_char) { - unsafe { Foo_set_type(self, c) } + Foo_set_type(self, c) } } diff --git a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs index 067aab36f8..06c8da1bad 100644 --- a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs +++ b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs @@ -23,11 +23,11 @@ impl __IncompleteArrayField { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } + ::std::slice::from_raw_parts(self.as_ptr(), len) } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } + ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } impl ::std::fmt::Debug for __IncompleteArrayField { diff --git a/bindgen-tests/tests/expectations/tests/derive-partialeq-union_1_0.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-union_1_0.rs index 604aa28d44..a53b9ba8e6 100644 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/derive-partialeq-union_1_0.rs @@ -14,11 +14,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/disable-untagged-union.rs b/bindgen-tests/tests/expectations/tests/disable-untagged-union.rs index 78cbe47fa4..515f496b87 100644 --- a/bindgen-tests/tests/expectations/tests/disable-untagged-union.rs +++ b/bindgen-tests/tests/expectations/tests/disable-untagged-union.rs @@ -14,11 +14,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/duplicated-definition-count.rs b/bindgen-tests/tests/expectations/tests/duplicated-definition-count.rs index 8fdffe56e4..829022a279 100644 --- a/bindgen-tests/tests/expectations/tests/duplicated-definition-count.rs +++ b/bindgen-tests/tests/expectations/tests/duplicated-definition-count.rs @@ -50,7 +50,7 @@ impl BitStream { inputByteArray: *const ::std::os::raw::c_char, numberOfBytes: ::std::os::raw::c_uint, ) { - unsafe { BitStream_Write(self, inputByteArray, numberOfBytes) } + BitStream_Write(self, inputByteArray, numberOfBytes) } #[inline] pub unsafe fn Write1( @@ -58,10 +58,10 @@ impl BitStream { bitStream: *mut BitStream, numberOfBits: ::std::os::raw::c_uint, ) { - unsafe { BitStream_Write1(self, bitStream, numberOfBits) } + BitStream_Write1(self, bitStream, numberOfBits) } #[inline] pub unsafe fn Write11(&mut self) { - unsafe { BitStream_Write11(self) } + BitStream_Write11(self) } } diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_attributes.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_attributes.rs index 5ad4b23f7b..c834752e3c 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_attributes.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_attributes.rs @@ -20,7 +20,7 @@ impl TestLib { P: AsRef<::std::ffi::OsStr>, { let library = ::libloading::Library::new(path)?; - unsafe { Self::from_library(library) } + Self::from_library(library) } pub unsafe fn from_library( library: L, @@ -29,8 +29,8 @@ impl TestLib { L: Into<::libloading::Library>, { let __library = library.into(); - let foo = unsafe { __library.get(b"foo\0") }.map(|sym| *sym)?; - let baz = unsafe { __library.get(b"baz\0") }.map(|sym| *sym)?; + let foo = __library.get(b"foo\0").map(|sym| *sym)?; + let baz = __library.get(b"baz\0").map(|sym| *sym)?; Ok(TestLib { __library, foo, @@ -48,9 +48,9 @@ impl TestLib { x: ::std::os::raw::c_int, y: ::std::os::raw::c_int, ) -> ::std::os::raw::c_int { - unsafe { (self.foo)(x, y) } + (self.foo)(x, y) } pub unsafe fn baz(&self) -> ::std::os::raw::c_int { - unsafe { (self.baz)() } + (self.baz)() } } diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_required.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_required.rs index 723f44ad09..e46ffd49e0 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_required.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_required.rs @@ -23,7 +23,7 @@ impl TestLib { P: AsRef<::std::ffi::OsStr>, { let library = ::libloading::Library::new(path)?; - unsafe { Self::from_library(library) } + Self::from_library(library) } pub unsafe fn from_library( library: L, @@ -32,9 +32,9 @@ impl TestLib { L: Into<::libloading::Library>, { let __library = library.into(); - let foo = unsafe { __library.get(b"foo\0") }.map(|sym| *sym)?; - let bar = unsafe { __library.get(b"bar\0") }.map(|sym| *sym)?; - let baz = unsafe { __library.get(b"baz\0") }.map(|sym| *sym)?; + let foo = __library.get(b"foo\0").map(|sym| *sym)?; + let bar = __library.get(b"bar\0").map(|sym| *sym)?; + let baz = __library.get(b"baz\0").map(|sym| *sym)?; Ok(TestLib { __library, foo, @@ -47,15 +47,15 @@ impl TestLib { x: ::std::os::raw::c_int, y: ::std::os::raw::c_int, ) -> ::std::os::raw::c_int { - unsafe { (self.foo)(x, y) } + (self.foo)(x, y) } pub unsafe fn bar( &self, x: *mut ::std::os::raw::c_void, ) -> ::std::os::raw::c_int { - unsafe { (self.bar)(x) } + (self.bar)(x) } pub unsafe fn baz(&self) -> ::std::os::raw::c_int { - unsafe { (self.baz)() } + (self.baz)() } } diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_simple.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_simple.rs index 5864ba0a8d..cae5bd6937 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_simple.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_simple.rs @@ -32,7 +32,7 @@ impl TestLib { P: AsRef<::std::ffi::OsStr>, { let library = ::libloading::Library::new(path)?; - unsafe { Self::from_library(library) } + Self::from_library(library) } pub unsafe fn from_library( library: L, @@ -41,9 +41,9 @@ impl TestLib { L: Into<::libloading::Library>, { let __library = library.into(); - let foo = unsafe { __library.get(b"foo\0") }.map(|sym| *sym); - let bar = unsafe { __library.get(b"bar\0") }.map(|sym| *sym); - let baz = unsafe { __library.get(b"baz\0") }.map(|sym| *sym); + let foo = __library.get(b"foo\0").map(|sym| *sym); + let bar = __library.get(b"bar\0").map(|sym| *sym); + let baz = __library.get(b"baz\0").map(|sym| *sym); Ok(TestLib { __library, foo, @@ -56,19 +56,15 @@ impl TestLib { x: ::std::os::raw::c_int, y: ::std::os::raw::c_int, ) -> ::std::os::raw::c_int { - unsafe { - (self.foo.as_ref().expect("Expected function, got error."))(x, y) - } + (self.foo.as_ref().expect("Expected function, got error."))(x, y) } pub unsafe fn bar( &self, x: *mut ::std::os::raw::c_void, ) -> ::std::os::raw::c_int { - unsafe { - (self.bar.as_ref().expect("Expected function, got error."))(x) - } + (self.bar.as_ref().expect("Expected function, got error."))(x) } pub unsafe fn baz(&self) -> ::std::os::raw::c_int { - unsafe { (self.baz.as_ref().expect("Expected function, got error."))() } + (self.baz.as_ref().expect("Expected function, got error."))() } } diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_template.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_template.rs index 6c9ea27496..06e67ed791 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_template.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_template.rs @@ -20,7 +20,7 @@ impl TestLib { P: AsRef<::std::ffi::OsStr>, { let library = ::libloading::Library::new(path)?; - unsafe { Self::from_library(library) } + Self::from_library(library) } pub unsafe fn from_library( library: L, @@ -29,8 +29,8 @@ impl TestLib { L: Into<::libloading::Library>, { let __library = library.into(); - let foo = unsafe { __library.get(b"foo\0") }.map(|sym| *sym); - let foo1 = unsafe { __library.get(b"foo1\0") }.map(|sym| *sym); + let foo = __library.get(b"foo\0").map(|sym| *sym); + let foo1 = __library.get(b"foo1\0").map(|sym| *sym); Ok(TestLib { __library, foo, @@ -41,13 +41,9 @@ impl TestLib { &self, x: ::std::os::raw::c_int, ) -> ::std::os::raw::c_int { - unsafe { - (self.foo.as_ref().expect("Expected function, got error."))(x) - } + (self.foo.as_ref().expect("Expected function, got error."))(x) } pub unsafe fn foo1(&self, x: f32) -> f32 { - unsafe { - (self.foo1.as_ref().expect("Expected function, got error."))(x) - } + (self.foo1.as_ref().expect("Expected function, got error."))(x) } } diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_allowlist.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_allowlist.rs index c9b2471419..97bb67abdc 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_allowlist.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_allowlist.rs @@ -34,7 +34,7 @@ impl TestLib { P: AsRef<::std::ffi::OsStr>, { let library = ::libloading::Library::new(path)?; - unsafe { Self::from_library(library) } + Self::from_library(library) } pub unsafe fn from_library( library: L, @@ -43,9 +43,9 @@ impl TestLib { L: Into<::libloading::Library>, { let __library = library.into(); - let foo = unsafe { __library.get(b"foo\0") }.map(|sym| *sym); - let baz = unsafe { __library.get(b"baz\0") }.map(|sym| *sym); - let bazz = unsafe { __library.get(b"bazz\0") }.map(|sym| *sym); + let foo = __library.get(b"foo\0").map(|sym| *sym); + let baz = __library.get(b"baz\0").map(|sym| *sym); + let bazz = __library.get(b"bazz\0").map(|sym| *sym); Ok(TestLib { __library, foo, @@ -57,16 +57,12 @@ impl TestLib { &self, x: *mut ::std::os::raw::c_void, ) -> ::std::os::raw::c_int { - unsafe { - (self.foo.as_ref().expect("Expected function, got error."))(x) - } + (self.foo.as_ref().expect("Expected function, got error."))(x) } pub unsafe fn baz( &self, x: *mut ::std::os::raw::c_void, ) -> ::std::os::raw::c_int { - unsafe { - (self.baz.as_ref().expect("Expected function, got error."))(x) - } + (self.baz.as_ref().expect("Expected function, got error."))(x) } } diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_blocklist.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_blocklist.rs index 30f2be1d1e..af482ad938 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_blocklist.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_blocklist.rs @@ -46,19 +46,17 @@ extern "C" { impl X { #[inline] pub unsafe fn some_function(&mut self) { - unsafe { X_some_function(self) } + X_some_function(self) } #[inline] pub unsafe fn some_other_function(&mut self) { - unsafe { X_some_other_function(self) } + X_some_other_function(self) } #[inline] pub unsafe fn new(x: ::std::os::raw::c_int) -> Self { - unsafe { - let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); - X_X(__bindgen_tmp.as_mut_ptr(), x); - __bindgen_tmp.assume_init() - } + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + X_X(__bindgen_tmp.as_mut_ptr(), x); + __bindgen_tmp.assume_init() } } extern crate libloading; @@ -83,7 +81,7 @@ impl TestLib { P: AsRef<::std::ffi::OsStr>, { let library = ::libloading::Library::new(path)?; - unsafe { Self::from_library(library) } + Self::from_library(library) } pub unsafe fn from_library( library: L, @@ -92,8 +90,8 @@ impl TestLib { L: Into<::libloading::Library>, { let __library = library.into(); - let foo = unsafe { __library.get(b"foo\0") }.map(|sym| *sym); - let bar = unsafe { __library.get(b"bar\0") }.map(|sym| *sym); + let foo = __library.get(b"foo\0").map(|sym| *sym); + let bar = __library.get(b"bar\0").map(|sym| *sym); Ok(TestLib { __library, foo, @@ -104,16 +102,12 @@ impl TestLib { &self, x: *mut ::std::os::raw::c_void, ) -> ::std::os::raw::c_int { - unsafe { - (self.foo.as_ref().expect("Expected function, got error."))(x) - } + (self.foo.as_ref().expect("Expected function, got error."))(x) } pub unsafe fn bar( &self, x: *mut ::std::os::raw::c_void, ) -> ::std::os::raw::c_int { - unsafe { - (self.bar.as_ref().expect("Expected function, got error."))(x) - } + (self.bar.as_ref().expect("Expected function, got error."))(x) } } diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs index d928751892..514cff7317 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs @@ -46,19 +46,17 @@ extern "C" { impl A { #[inline] pub unsafe fn some_function(&mut self) { - unsafe { A_some_function(self) } + A_some_function(self) } #[inline] pub unsafe fn some_other_function(&mut self) { - unsafe { A_some_other_function(self) } + A_some_other_function(self) } #[inline] pub unsafe fn new(x: ::std::os::raw::c_int) -> Self { - unsafe { - let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); - A_A(__bindgen_tmp.as_mut_ptr(), x); - __bindgen_tmp.assume_init() - } + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + A_A(__bindgen_tmp.as_mut_ptr(), x); + __bindgen_tmp.assume_init() } } extern crate libloading; @@ -78,7 +76,7 @@ impl TestLib { P: AsRef<::std::ffi::OsStr>, { let library = ::libloading::Library::new(path)?; - unsafe { Self::from_library(library) } + Self::from_library(library) } pub unsafe fn from_library( library: L, @@ -87,8 +85,8 @@ impl TestLib { L: Into<::libloading::Library>, { let __library = library.into(); - let foo = unsafe { __library.get(b"foo\0") }.map(|sym| *sym); - let bar = unsafe { __library.get(b"bar\0") }.map(|sym| *sym); + let foo = __library.get(b"foo\0").map(|sym| *sym); + let bar = __library.get(b"bar\0").map(|sym| *sym); Ok(TestLib { __library, foo, @@ -99,11 +97,9 @@ impl TestLib { &self, x: *mut ::std::os::raw::c_void, ) -> ::std::os::raw::c_int { - unsafe { - (self.foo.as_ref().expect("Expected function, got error."))(x) - } + (self.foo.as_ref().expect("Expected function, got error."))(x) } pub unsafe fn bar(&self) -> () { - unsafe { (self.bar.as_ref().expect("Expected function, got error."))() } + (self.bar.as_ref().expect("Expected function, got error."))() } } diff --git a/bindgen-tests/tests/expectations/tests/gen-constructors.rs b/bindgen-tests/tests/expectations/tests/gen-constructors.rs index 59af8ef30c..89b8637954 100644 --- a/bindgen-tests/tests/expectations/tests/gen-constructors.rs +++ b/bindgen-tests/tests/expectations/tests/gen-constructors.rs @@ -30,10 +30,8 @@ extern "C" { impl Foo { #[inline] pub unsafe fn new(a: ::std::os::raw::c_int) -> Self { - unsafe { - let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); - Foo_Foo(__bindgen_tmp.as_mut_ptr(), a); - __bindgen_tmp.assume_init() - } + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + Foo_Foo(__bindgen_tmp.as_mut_ptr(), a); + __bindgen_tmp.assume_init() } } diff --git a/bindgen-tests/tests/expectations/tests/gen-destructors.rs b/bindgen-tests/tests/expectations/tests/gen-destructors.rs index 4109520987..1711f76d0c 100644 --- a/bindgen-tests/tests/expectations/tests/gen-destructors.rs +++ b/bindgen-tests/tests/expectations/tests/gen-destructors.rs @@ -38,6 +38,6 @@ extern "C" { impl Foo { #[inline] pub unsafe fn destruct(&mut self) { - unsafe { Foo_Foo_destructor(self) } + Foo_Foo_destructor(self) } } diff --git a/bindgen-tests/tests/expectations/tests/generate-inline.rs b/bindgen-tests/tests/expectations/tests/generate-inline.rs index 9ac66b0f7b..3cb865a4d7 100644 --- a/bindgen-tests/tests/expectations/tests/generate-inline.rs +++ b/bindgen-tests/tests/expectations/tests/generate-inline.rs @@ -30,7 +30,7 @@ extern "C" { impl Foo { #[inline] pub unsafe fn bar() -> ::std::os::raw::c_int { - unsafe { Foo_bar() } + Foo_bar() } } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs b/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs index d1ae7ebd2b..18061ea12a 100644 --- a/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs +++ b/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs @@ -109,11 +109,11 @@ impl __IncompleteArrayField { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } + ::std::slice::from_raw_parts(self.as_ptr(), len) } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } + ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } impl ::std::fmt::Debug for __IncompleteArrayField { diff --git a/bindgen-tests/tests/expectations/tests/issue-2019.rs b/bindgen-tests/tests/expectations/tests/issue-2019.rs index 89f1ac6268..294e9f0e83 100644 --- a/bindgen-tests/tests/expectations/tests/issue-2019.rs +++ b/bindgen-tests/tests/expectations/tests/issue-2019.rs @@ -38,7 +38,7 @@ extern "C" { impl A { #[inline] pub unsafe fn make() -> A { - unsafe { make() } + make() } } #[repr(C)] @@ -74,6 +74,6 @@ extern "C" { impl B { #[inline] pub unsafe fn make() -> B { - unsafe { make1() } + make1() } } diff --git a/bindgen-tests/tests/expectations/tests/issue-410.rs b/bindgen-tests/tests/expectations/tests/issue-410.rs index 739ddf29ce..ad7463c266 100644 --- a/bindgen-tests/tests/expectations/tests/issue-410.rs +++ b/bindgen-tests/tests/expectations/tests/issue-410.rs @@ -37,7 +37,7 @@ pub mod root { impl Value { #[inline] pub unsafe fn a(&mut self, arg1: root::JSWhyMagic) { - unsafe { Value_a(self, arg1) } + Value_a(self, arg1) } } } diff --git a/bindgen-tests/tests/expectations/tests/issue-447.rs b/bindgen-tests/tests/expectations/tests/issue-447.rs index 0a6dd5e6b8..949db73b79 100644 --- a/bindgen-tests/tests/expectations/tests/issue-447.rs +++ b/bindgen-tests/tests/expectations/tests/issue-447.rs @@ -65,14 +65,12 @@ pub mod root { pub unsafe fn new( arg1: root::mozilla::detail::GuardObjectNotifier, ) -> Self { - unsafe { - let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); - JSAutoCompartment_JSAutoCompartment( - __bindgen_tmp.as_mut_ptr(), - arg1, - ); - __bindgen_tmp.assume_init() - } + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + JSAutoCompartment_JSAutoCompartment( + __bindgen_tmp.as_mut_ptr(), + arg1, + ); + __bindgen_tmp.assume_init() } } } diff --git a/bindgen-tests/tests/expectations/tests/issue-493.rs b/bindgen-tests/tests/expectations/tests/issue-493.rs index 019982dbb9..61c7f7929e 100644 --- a/bindgen-tests/tests/expectations/tests/issue-493.rs +++ b/bindgen-tests/tests/expectations/tests/issue-493.rs @@ -14,11 +14,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/issue-493_1_0.rs b/bindgen-tests/tests/expectations/tests/issue-493_1_0.rs index 12a1e7a267..1a0131c327 100644 --- a/bindgen-tests/tests/expectations/tests/issue-493_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/issue-493_1_0.rs @@ -14,11 +14,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/issue-643-inner-struct.rs b/bindgen-tests/tests/expectations/tests/issue-643-inner-struct.rs index 03162c4c9f..b69aa16ef3 100644 --- a/bindgen-tests/tests/expectations/tests/issue-643-inner-struct.rs +++ b/bindgen-tests/tests/expectations/tests/issue-643-inner-struct.rs @@ -23,11 +23,11 @@ impl __IncompleteArrayField { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } + ::std::slice::from_raw_parts(self.as_ptr(), len) } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } + ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } impl ::std::fmt::Debug for __IncompleteArrayField { diff --git a/bindgen-tests/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs b/bindgen-tests/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs index dc0b7f08d9..f886952822 100644 --- a/bindgen-tests/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs +++ b/bindgen-tests/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs @@ -89,15 +89,13 @@ extern "C" { impl Opaque { #[inline] pub unsafe fn eleven_out_of_ten(&mut self) -> SuchWow { - unsafe { Opaque_eleven_out_of_ten(self) } + Opaque_eleven_out_of_ten(self) } #[inline] pub unsafe fn new(pup: Pupper) -> Self { - unsafe { - let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); - Opaque_Opaque(__bindgen_tmp.as_mut_ptr(), pup); - __bindgen_tmp.assume_init() - } + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + Opaque_Opaque(__bindgen_tmp.as_mut_ptr(), pup); + __bindgen_tmp.assume_init() } } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs index 32af443f29..b439499355 100644 --- a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs @@ -100,11 +100,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/layout_align.rs b/bindgen-tests/tests/expectations/tests/layout_align.rs index 718a8024a6..466e76862c 100644 --- a/bindgen-tests/tests/expectations/tests/layout_align.rs +++ b/bindgen-tests/tests/expectations/tests/layout_align.rs @@ -109,11 +109,11 @@ impl __IncompleteArrayField { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } + ::std::slice::from_raw_parts(self.as_ptr(), len) } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } + ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } impl ::std::fmt::Debug for __IncompleteArrayField { diff --git a/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs b/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs index de814146e1..d7fa0a634a 100644 --- a/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs @@ -100,11 +100,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl ::std::default::Default for __BindgenUnionField { 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 f0b312a037..075ef46ae4 100644 --- a/bindgen-tests/tests/expectations/tests/layout_large_align_field.rs +++ b/bindgen-tests/tests/expectations/tests/layout_large_align_field.rs @@ -23,11 +23,11 @@ impl __IncompleteArrayField { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } + ::std::slice::from_raw_parts(self.as_ptr(), len) } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } + ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } impl ::std::fmt::Debug for __IncompleteArrayField { diff --git a/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs b/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs index 3788d3d0a4..90f7ed09b2 100644 --- a/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs @@ -100,11 +100,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/objc_template.rs b/bindgen-tests/tests/expectations/tests/libclang-5/objc_template.rs index 85ca160107..53caa661c6 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-5/objc_template.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-5/objc_template.rs @@ -30,7 +30,7 @@ pub trait IFoo: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - unsafe { msg_send!(*self, get) } + msg_send!(*self, get) } } #[repr(transparent)] @@ -59,6 +59,6 @@ pub trait IFooMultiGeneric: where ::Target: objc::Message + Sized, { - unsafe { msg_send!(*self, objectForKey: key) } + msg_send!(*self, objectForKey: key) } } diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/class.rs b/bindgen-tests/tests/expectations/tests/libclang-9/class.rs index 7d732bb09a..0d64a9ffc8 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/class.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/class.rs @@ -23,11 +23,11 @@ impl __IncompleteArrayField { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } + ::std::slice::from_raw_parts(self.as_ptr(), len) } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } + ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } impl ::std::fmt::Debug for __IncompleteArrayField { @@ -674,18 +674,18 @@ extern "C" { impl RealAbstractionWithTonsOfMethods { #[inline] pub unsafe fn bar(&self) { - unsafe { RealAbstractionWithTonsOfMethods_bar(self) } + RealAbstractionWithTonsOfMethods_bar(self) } #[inline] pub unsafe fn bar1(&mut self) { - unsafe { RealAbstractionWithTonsOfMethods_bar1(self) } + RealAbstractionWithTonsOfMethods_bar1(self) } #[inline] pub unsafe fn bar2(&mut self, foo: ::std::os::raw::c_int) { - unsafe { RealAbstractionWithTonsOfMethods_bar2(self, foo) } + RealAbstractionWithTonsOfMethods_bar2(self, foo) } #[inline] pub unsafe fn sta() { - unsafe { RealAbstractionWithTonsOfMethods_sta() } + RealAbstractionWithTonsOfMethods_sta() } } diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/class_1_0.rs b/bindgen-tests/tests/expectations/tests/libclang-9/class_1_0.rs index 4364c69a74..e8c2e07798 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/class_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/class_1_0.rs @@ -23,11 +23,11 @@ impl __IncompleteArrayField { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } + ::std::slice::from_raw_parts(self.as_ptr(), len) } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } + ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } impl ::std::fmt::Debug for __IncompleteArrayField { @@ -44,11 +44,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl ::std::default::Default for __BindgenUnionField { @@ -725,18 +725,18 @@ impl Clone for RealAbstractionWithTonsOfMethods { impl RealAbstractionWithTonsOfMethods { #[inline] pub unsafe fn bar(&self) { - unsafe { RealAbstractionWithTonsOfMethods_bar(self) } + RealAbstractionWithTonsOfMethods_bar(self) } #[inline] pub unsafe fn bar1(&mut self) { - unsafe { RealAbstractionWithTonsOfMethods_bar1(self) } + RealAbstractionWithTonsOfMethods_bar1(self) } #[inline] pub unsafe fn bar2(&mut self, foo: ::std::os::raw::c_int) { - unsafe { RealAbstractionWithTonsOfMethods_bar2(self, foo) } + RealAbstractionWithTonsOfMethods_bar2(self, foo) } #[inline] pub unsafe fn sta() { - unsafe { RealAbstractionWithTonsOfMethods_sta() } + RealAbstractionWithTonsOfMethods_sta() } } diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs b/bindgen-tests/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs index 17154e4d1a..2af22cc4c9 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs @@ -23,11 +23,11 @@ impl __IncompleteArrayField { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } + ::std::slice::from_raw_parts(self.as_ptr(), len) } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } + ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } impl ::std::fmt::Debug for __IncompleteArrayField { diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/incomplete-array-padding.rs b/bindgen-tests/tests/expectations/tests/libclang-9/incomplete-array-padding.rs index 441c3f69b2..1de963bf0f 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/incomplete-array-padding.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/incomplete-array-padding.rs @@ -109,11 +109,11 @@ impl __IncompleteArrayField { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } + ::std::slice::from_raw_parts(self.as_ptr(), len) } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } + ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } impl ::std::fmt::Debug for __IncompleteArrayField { diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs b/bindgen-tests/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs index 4161c6dbfc..ab402cfb7c 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs @@ -23,11 +23,11 @@ impl __IncompleteArrayField { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } + ::std::slice::from_raw_parts(self.as_ptr(), len) } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } + ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } impl ::std::fmt::Debug for __IncompleteArrayField { diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/layout_align.rs b/bindgen-tests/tests/expectations/tests/libclang-9/layout_align.rs index df940912b3..f6a32704f1 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/layout_align.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/layout_align.rs @@ -109,11 +109,11 @@ impl __IncompleteArrayField { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } + ::std::slice::from_raw_parts(self.as_ptr(), len) } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } + ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } impl ::std::fmt::Debug for __IncompleteArrayField { @@ -151,56 +151,56 @@ fn bindgen_test_layout_rte_kni_fifo() { concat!("Alignment of ", stringify!(rte_kni_fifo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).write) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_fifo), - "::", - stringify!(write) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).read) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_fifo), - "::", - stringify!(read) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_fifo), - "::", - stringify!(len) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).elem_size) as usize - ptr as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_fifo), - "::", - stringify!(elem_size) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).buffer) as usize - ptr as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_fifo), - "::", - stringify!(buffer) - ) + unsafe { ::std::ptr::addr_of!((*ptr).write) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_fifo), + "::", + stringify!(write) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).read) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_fifo), + "::", + stringify!(read) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_fifo), + "::", + stringify!(len) + ) + ); + assert_eq!( + unsafe { + ::std::ptr::addr_of!((*ptr).elem_size) as usize - ptr as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_fifo), + "::", + stringify!(elem_size) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).buffer) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_fifo), + "::", + stringify!(buffer) + ) ); } impl Default for rte_kni_fifo { diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/objc_template.rs b/bindgen-tests/tests/expectations/tests/libclang-9/objc_template.rs index 90d9d9931b..3c615035ce 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/objc_template.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/objc_template.rs @@ -30,7 +30,7 @@ pub trait IFoo: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - unsafe { msg_send!(*self, get) } + msg_send!(*self, get) } } #[repr(transparent)] @@ -59,6 +59,6 @@ pub trait IFooMultiGeneric: where ::Target: objc::Message + Sized, { - unsafe { msg_send!(*self, objectForKey: key) } + msg_send!(*self, objectForKey: key) } } diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/zero-sized-array.rs b/bindgen-tests/tests/expectations/tests/libclang-9/zero-sized-array.rs index 71a2d6d6aa..3066fac40a 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/zero-sized-array.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/zero-sized-array.rs @@ -23,11 +23,11 @@ impl __IncompleteArrayField { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } + ::std::slice::from_raw_parts(self.as_ptr(), len) } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } + ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } impl ::std::fmt::Debug for __IncompleteArrayField { diff --git a/bindgen-tests/tests/expectations/tests/method-mangling.rs b/bindgen-tests/tests/expectations/tests/method-mangling.rs index 5f8a847452..e4627ac8a7 100644 --- a/bindgen-tests/tests/expectations/tests/method-mangling.rs +++ b/bindgen-tests/tests/expectations/tests/method-mangling.rs @@ -30,6 +30,6 @@ extern "C" { impl Foo { #[inline] pub unsafe fn type_(&mut self) -> ::std::os::raw::c_int { - unsafe { Foo_type(self) } + Foo_type(self) } } diff --git a/bindgen-tests/tests/expectations/tests/objc_allowlist.rs b/bindgen-tests/tests/expectations/tests/objc_allowlist.rs index 76971a5f38..370cab9332 100644 --- a/bindgen-tests/tests/expectations/tests/objc_allowlist.rs +++ b/bindgen-tests/tests/expectations/tests/objc_allowlist.rs @@ -14,13 +14,13 @@ pub trait PSomeProtocol: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - unsafe { msg_send!(*self, protocolMethod) } + msg_send!(*self, protocolMethod) } unsafe fn protocolClassMethod() where ::Target: objc::Message + Sized, { - unsafe { msg_send!(class!(SomeProtocol), protocolClassMethod) } + msg_send!(class!(SomeProtocol), protocolClassMethod) } } #[repr(transparent)] @@ -45,13 +45,13 @@ pub trait IAllowlistMe: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - unsafe { msg_send!(*self, method) } + msg_send!(*self, method) } unsafe fn classMethod() where ::Target: objc::Message + Sized, { - unsafe { msg_send!(class!(AllowlistMe), classMethod) } + msg_send!(class!(AllowlistMe), classMethod) } } impl AllowlistMe_InterestingCategory for AllowlistMe {} diff --git a/bindgen-tests/tests/expectations/tests/objc_blocklist.rs b/bindgen-tests/tests/expectations/tests/objc_blocklist.rs index f16eb0f929..7d5d19b083 100644 --- a/bindgen-tests/tests/expectations/tests/objc_blocklist.rs +++ b/bindgen-tests/tests/expectations/tests/objc_blocklist.rs @@ -31,12 +31,12 @@ pub trait ISomeClass: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - unsafe { msg_send!(*self, ambiguouslyBlockedMethod) } + msg_send!(*self, ambiguouslyBlockedMethod) } unsafe fn instanceMethod(&self) where ::Target: objc::Message + Sized, { - unsafe { msg_send!(*self, instanceMethod) } + msg_send!(*self, instanceMethod) } } diff --git a/bindgen-tests/tests/expectations/tests/objc_category.rs b/bindgen-tests/tests/expectations/tests/objc_category.rs index f05c2bbd9b..9d60233bed 100644 --- a/bindgen-tests/tests/expectations/tests/objc_category.rs +++ b/bindgen-tests/tests/expectations/tests/objc_category.rs @@ -30,7 +30,7 @@ pub trait IFoo: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - unsafe { msg_send!(*self, method) } + msg_send!(*self, method) } } impl Foo_BarCategory for Foo {} @@ -39,6 +39,6 @@ pub trait Foo_BarCategory: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - unsafe { msg_send!(*self, categoryMethod) } + msg_send!(*self, categoryMethod) } } diff --git a/bindgen-tests/tests/expectations/tests/objc_class.rs b/bindgen-tests/tests/expectations/tests/objc_class.rs index 0fe8e254c3..b322bddcb6 100644 --- a/bindgen-tests/tests/expectations/tests/objc_class.rs +++ b/bindgen-tests/tests/expectations/tests/objc_class.rs @@ -33,6 +33,6 @@ pub trait IFoo: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - unsafe { msg_send!(*self, method) } + msg_send!(*self, method) } } diff --git a/bindgen-tests/tests/expectations/tests/objc_class_method.rs b/bindgen-tests/tests/expectations/tests/objc_class_method.rs index 796698d271..29e70256ff 100644 --- a/bindgen-tests/tests/expectations/tests/objc_class_method.rs +++ b/bindgen-tests/tests/expectations/tests/objc_class_method.rs @@ -30,31 +30,31 @@ pub trait IFoo: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - unsafe { msg_send!(class!(Foo), method) } + msg_send!(class!(Foo), method) } unsafe fn methodWithInt_(foo: ::std::os::raw::c_int) where ::Target: objc::Message + Sized, { - unsafe { msg_send!(class!(Foo), methodWithInt: foo) } + msg_send!(class!(Foo), methodWithInt: foo) } unsafe fn methodWithFoo_(foo: Foo) where ::Target: objc::Message + Sized, { - unsafe { msg_send!(class!(Foo), methodWithFoo: foo) } + msg_send!(class!(Foo), methodWithFoo: foo) } unsafe fn methodReturningInt() -> ::std::os::raw::c_int where ::Target: objc::Message + Sized, { - unsafe { msg_send!(class!(Foo), methodReturningInt) } + msg_send!(class!(Foo), methodReturningInt) } unsafe fn methodReturningFoo() -> Foo where ::Target: objc::Message + Sized, { - unsafe { msg_send!(class!(Foo), methodReturningFoo) } + msg_send!(class!(Foo), methodReturningFoo) } unsafe fn methodWithArg1_andArg2_andArg3_( intvalue: ::std::os::raw::c_int, @@ -63,8 +63,6 @@ pub trait IFoo: Sized + std::ops::Deref { ) where ::Target: objc::Message + Sized, { - unsafe { - msg_send ! (class ! (Foo) , methodWithArg1 : intvalue andArg2 : ptr andArg3 : floatvalue) - } + msg_send ! (class ! (Foo) , methodWithArg1 : intvalue andArg2 : ptr andArg3 : floatvalue) } } diff --git a/bindgen-tests/tests/expectations/tests/objc_method.rs b/bindgen-tests/tests/expectations/tests/objc_method.rs index 8962413e24..593fd27738 100644 --- a/bindgen-tests/tests/expectations/tests/objc_method.rs +++ b/bindgen-tests/tests/expectations/tests/objc_method.rs @@ -30,31 +30,31 @@ pub trait IFoo: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - unsafe { msg_send!(*self, method) } + msg_send!(*self, method) } unsafe fn methodWithInt_(&self, foo: ::std::os::raw::c_int) where ::Target: objc::Message + Sized, { - unsafe { msg_send!(*self, methodWithInt: foo) } + msg_send!(*self, methodWithInt: foo) } unsafe fn methodWithFoo_(&self, foo: Foo) where ::Target: objc::Message + Sized, { - unsafe { msg_send!(*self, methodWithFoo: foo) } + msg_send!(*self, methodWithFoo: foo) } unsafe fn methodReturningInt(&self) -> ::std::os::raw::c_int where ::Target: objc::Message + Sized, { - unsafe { msg_send!(*self, methodReturningInt) } + msg_send!(*self, methodReturningInt) } unsafe fn methodReturningFoo(&self) -> Foo where ::Target: objc::Message + Sized, { - unsafe { msg_send!(*self, methodReturningFoo) } + msg_send!(*self, methodReturningFoo) } unsafe fn methodWithArg1_andArg2_andArg3_( &self, @@ -64,9 +64,7 @@ pub trait IFoo: Sized + std::ops::Deref { ) where ::Target: objc::Message + Sized, { - unsafe { - msg_send ! (* self , methodWithArg1 : intvalue andArg2 : ptr andArg3 : floatvalue) - } + msg_send ! (* self , methodWithArg1 : intvalue andArg2 : ptr andArg3 : floatvalue) } unsafe fn methodWithAndWithoutKeywords_arg2Name__arg4Name_( &self, @@ -78,9 +76,7 @@ pub trait IFoo: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - unsafe { - msg_send ! (* self , methodWithAndWithoutKeywords : arg1 arg2Name : arg2 arg3 : arg3 arg4Name : arg4) - } + msg_send ! (* self , methodWithAndWithoutKeywords : arg1 arg2Name : arg2 arg3 : arg3 arg4Name : arg4) } } pub type instancetype = id; diff --git a/bindgen-tests/tests/expectations/tests/objc_method_clash.rs b/bindgen-tests/tests/expectations/tests/objc_method_clash.rs index bd2df7d0d6..ac77cc19e3 100644 --- a/bindgen-tests/tests/expectations/tests/objc_method_clash.rs +++ b/bindgen-tests/tests/expectations/tests/objc_method_clash.rs @@ -30,12 +30,12 @@ pub trait IFoo: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - unsafe { msg_send!(*self, foo) } + msg_send!(*self, foo) } unsafe fn class_foo() where ::Target: objc::Message + Sized, { - unsafe { msg_send!(class!(Foo), foo) } + msg_send!(class!(Foo), foo) } } diff --git a/bindgen-tests/tests/expectations/tests/objc_pointer_return_types.rs b/bindgen-tests/tests/expectations/tests/objc_pointer_return_types.rs index d49f17c1a6..1ec8494d25 100644 --- a/bindgen-tests/tests/expectations/tests/objc_pointer_return_types.rs +++ b/bindgen-tests/tests/expectations/tests/objc_pointer_return_types.rs @@ -47,12 +47,12 @@ pub trait IFoo: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - unsafe { msg_send!(*self, methodUsingBar: my_bar) } + msg_send!(*self, methodUsingBar: my_bar) } unsafe fn methodReturningBar() -> Bar where ::Target: objc::Message + Sized, { - unsafe { msg_send!(class!(Foo), methodReturningBar) } + msg_send!(class!(Foo), methodReturningBar) } } diff --git a/bindgen-tests/tests/expectations/tests/objc_property_fnptr.rs b/bindgen-tests/tests/expectations/tests/objc_property_fnptr.rs index 90a3dc8dea..9f3fabd272 100644 --- a/bindgen-tests/tests/expectations/tests/objc_property_fnptr.rs +++ b/bindgen-tests/tests/expectations/tests/objc_property_fnptr.rs @@ -38,7 +38,7 @@ pub trait IFoo: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - unsafe { msg_send!(*self, func) } + msg_send!(*self, func) } unsafe fn setFunc_( &self, @@ -52,6 +52,6 @@ pub trait IFoo: Sized + std::ops::Deref { ) where ::Target: objc::Message + Sized, { - unsafe { msg_send!(*self, setFunc: func) } + msg_send!(*self, setFunc: func) } } diff --git a/bindgen-tests/tests/expectations/tests/parm-union.rs b/bindgen-tests/tests/expectations/tests/parm-union.rs index 4738b301e7..9f7dd20ad9 100644 --- a/bindgen-tests/tests/expectations/tests/parm-union.rs +++ b/bindgen-tests/tests/expectations/tests/parm-union.rs @@ -30,7 +30,7 @@ extern "C" { impl Struct { #[inline] pub unsafe fn Function(&mut self, arg1: *mut Union) { - unsafe { Struct_Function(self, arg1) } + Struct_Function(self, arg1) } } #[repr(C)] diff --git a/bindgen-tests/tests/expectations/tests/public-dtor.rs b/bindgen-tests/tests/expectations/tests/public-dtor.rs index 1d095b8d0b..979dd4b564 100644 --- a/bindgen-tests/tests/expectations/tests/public-dtor.rs +++ b/bindgen-tests/tests/expectations/tests/public-dtor.rs @@ -1,53 +1,53 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -#[repr(C)] -#[derive(Debug, Default)] -pub struct cv_Foo { - pub _address: u8, -} -#[test] -fn bindgen_test_layout_cv_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(cv_Foo)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(cv_Foo)) - ); -} -extern "C" { - #[link_name = "\u{1}_ZN2cv3FooD1Ev"] - pub fn cv_Foo_Foo_destructor(this: *mut cv_Foo); -} -impl cv_Foo { - #[inline] - pub unsafe fn destruct(&mut self) { - unsafe { cv_Foo_Foo_destructor(self) } - } -} -#[repr(C)] -#[derive(Debug, Default)] -pub struct cv_Bar { - pub _address: u8, -} -#[test] -fn bindgen_test_layout_cv_Bar() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(cv_Bar)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(cv_Bar)) - ); -} +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +#[derive(Debug, Default)] +pub struct cv_Foo { + pub _address: u8, +} +#[test] +fn bindgen_test_layout_cv_Foo() { + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(cv_Foo)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(cv_Foo)) + ); +} +extern "C" { + #[link_name = "\u{1}_ZN2cv3FooD1Ev"] + pub fn cv_Foo_Foo_destructor(this: *mut cv_Foo); +} +impl cv_Foo { + #[inline] + pub unsafe fn destruct(&mut self) { + cv_Foo_Foo_destructor(self) + } +} +#[repr(C)] +#[derive(Debug, Default)] +pub struct cv_Bar { + pub _address: u8, +} +#[test] +fn bindgen_test_layout_cv_Bar() { + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(cv_Bar)) + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(cv_Bar)) + ); +} diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_union_1_0.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_union_1_0.rs index fd4d561b79..8db33d113e 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_anon_union_1_0.rs @@ -14,11 +14,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs index 52c6904c26..55432d47fc 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs @@ -14,11 +14,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/struct_with_nesting_1_0.rs b/bindgen-tests/tests/expectations/tests/struct_with_nesting_1_0.rs index a777adf360..af795b6423 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_nesting_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_nesting_1_0.rs @@ -14,11 +14,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/transform-op.rs b/bindgen-tests/tests/expectations/tests/transform-op.rs index eec37a3dae..84a9460362 100644 --- a/bindgen-tests/tests/expectations/tests/transform-op.rs +++ b/bindgen-tests/tests/expectations/tests/transform-op.rs @@ -14,11 +14,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/typeref_1_0.rs b/bindgen-tests/tests/expectations/tests/typeref_1_0.rs index 3376bf0438..8e4143c082 100644 --- a/bindgen-tests/tests/expectations/tests/typeref_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/typeref_1_0.rs @@ -14,11 +14,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/union-in-ns_1_0.rs b/bindgen-tests/tests/expectations/tests/union-in-ns_1_0.rs index 63e3978199..a057cc348a 100644 --- a/bindgen-tests/tests/expectations/tests/union-in-ns_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union-in-ns_1_0.rs @@ -16,11 +16,11 @@ pub mod root { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs b/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs index f15ce0f020..2227746849 100644 --- a/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs @@ -100,11 +100,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/union_dtor.rs b/bindgen-tests/tests/expectations/tests/union_dtor.rs index cb363de6b5..085e5ca30a 100644 --- a/bindgen-tests/tests/expectations/tests/union_dtor.rs +++ b/bindgen-tests/tests/expectations/tests/union_dtor.rs @@ -62,6 +62,6 @@ impl Default for UnionWithDtor { impl UnionWithDtor { #[inline] pub unsafe fn destruct(&mut self) { - unsafe { UnionWithDtor_UnionWithDtor_destructor(self) } + UnionWithDtor_UnionWithDtor_destructor(self) } } diff --git a/bindgen-tests/tests/expectations/tests/union_dtor_1_0.rs b/bindgen-tests/tests/expectations/tests/union_dtor_1_0.rs index 519bd8692f..67455aa8b8 100644 --- a/bindgen-tests/tests/expectations/tests/union_dtor_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_dtor_1_0.rs @@ -14,11 +14,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl ::std::default::Default for __BindgenUnionField { @@ -98,6 +98,6 @@ extern "C" { impl UnionWithDtor { #[inline] pub unsafe fn destruct(&mut self) { - unsafe { UnionWithDtor_UnionWithDtor_destructor(self) } + UnionWithDtor_UnionWithDtor_destructor(self) } } diff --git a/bindgen-tests/tests/expectations/tests/union_fields_1_0.rs b/bindgen-tests/tests/expectations/tests/union_fields_1_0.rs index 621a961f4f..b5f94bcd05 100644 --- a/bindgen-tests/tests/expectations/tests/union_fields_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_fields_1_0.rs @@ -14,11 +14,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/union_template_1_0.rs b/bindgen-tests/tests/expectations/tests/union_template_1_0.rs index 543f154d05..487579f7e5 100644 --- a/bindgen-tests/tests/expectations/tests/union_template_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_template_1_0.rs @@ -14,11 +14,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_1_0.rs index 316f8453e5..8b11e75796 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_1_0.rs @@ -14,11 +14,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs index c06f6489b9..6ce6ed2282 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs @@ -100,11 +100,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_union_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_union_1_0.rs index 6c856634da..f3e4b84003 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_union_1_0.rs @@ -14,11 +14,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs index d4c6fec977..1562a8c971 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs @@ -14,11 +14,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs index 96f03680aa..197a6bbfbc 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs @@ -14,11 +14,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/union_with_big_member_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_big_member_1_0.rs index 869720d442..63b43baa82 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_big_member_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_big_member_1_0.rs @@ -14,11 +14,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/union_with_nesting_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_nesting_1_0.rs index 4b1ab55336..a1e452fe03 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_nesting_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_nesting_1_0.rs @@ -14,11 +14,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/union_with_non_copy_member.rs b/bindgen-tests/tests/expectations/tests/union_with_non_copy_member.rs index 227afaffcc..3c500b2106 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_non_copy_member.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_non_copy_member.rs @@ -14,11 +14,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } + ::std::mem::transmute(self) } } impl ::std::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/use-core_1_0.rs b/bindgen-tests/tests/expectations/tests/use-core_1_0.rs index 0310211d88..8c6d0fd272 100644 --- a/bindgen-tests/tests/expectations/tests/use-core_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/use-core_1_0.rs @@ -16,11 +16,11 @@ impl __BindgenUnionField { } #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { ::core::mem::transmute(self) } + ::core::mem::transmute(self) } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::core::mem::transmute(self) } + ::core::mem::transmute(self) } } impl ::core::default::Default for __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/var-tracing.rs b/bindgen-tests/tests/expectations/tests/var-tracing.rs index 22e7e6ed69..37fdd95105 100644 --- a/bindgen-tests/tests/expectations/tests/var-tracing.rs +++ b/bindgen-tests/tests/expectations/tests/var-tracing.rs @@ -43,11 +43,9 @@ extern "C" { impl Bar { #[inline] pub unsafe fn new(baz: ::std::os::raw::c_int) -> Self { - unsafe { - let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); - Bar_Bar(__bindgen_tmp.as_mut_ptr(), baz); - __bindgen_tmp.assume_init() - } + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + Bar_Bar(__bindgen_tmp.as_mut_ptr(), baz); + __bindgen_tmp.assume_init() } } #[repr(C)] diff --git a/bindgen-tests/tests/expectations/tests/wasm-constructor-returns.rs b/bindgen-tests/tests/expectations/tests/wasm-constructor-returns.rs index 909d04ded4..6d15c51f9d 100644 --- a/bindgen-tests/tests/expectations/tests/wasm-constructor-returns.rs +++ b/bindgen-tests/tests/expectations/tests/wasm-constructor-returns.rs @@ -33,10 +33,8 @@ extern "C" { impl Foo { #[inline] pub unsafe fn new(var: ::std::os::raw::c_int) -> Self { - unsafe { - let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); - Foo_Foo(__bindgen_tmp.as_mut_ptr(), var); - __bindgen_tmp.assume_init() - } + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + Foo_Foo(__bindgen_tmp.as_mut_ptr(), var); + __bindgen_tmp.assume_init() } } diff --git a/bindgen-tests/tests/expectations/tests/win32-thiscall_nightly.rs b/bindgen-tests/tests/expectations/tests/win32-thiscall_nightly.rs index f144edd4d0..92bb13cc61 100644 --- a/bindgen-tests/tests/expectations/tests/win32-thiscall_nightly.rs +++ b/bindgen-tests/tests/expectations/tests/win32-thiscall_nightly.rs @@ -39,13 +39,13 @@ extern "thiscall" { impl Foo { #[inline] pub unsafe fn test(&mut self) { - unsafe { Foo_test(self) } + Foo_test(self) } #[inline] pub unsafe fn test2( &mut self, var: ::std::os::raw::c_int, ) -> ::std::os::raw::c_int { - unsafe { Foo_test2(self, var) } + Foo_test2(self, var) } } diff --git a/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_anon_union_1_0.rs b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_anon_union_1_0.rs new file mode 100644 index 0000000000..0eef6d2e78 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_anon_union_1_0.rs @@ -0,0 +1,107 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +pub struct __BindgenUnionField(::std::marker::PhantomData); +impl __BindgenUnionField { + #[inline] + pub fn new() -> Self { + __BindgenUnionField(::std::marker::PhantomData) + } + #[inline] + pub unsafe fn as_ref(&self) -> &T { + unsafe { ::std::mem::transmute(self) } + } + #[inline] + pub unsafe fn as_mut(&mut self) -> &mut T { + unsafe { ::std::mem::transmute(self) } + } +} +impl ::std::default::Default for __BindgenUnionField { + #[inline] + fn default() -> Self { + Self::new() + } +} +impl ::std::clone::Clone for __BindgenUnionField { + #[inline] + fn clone(&self) -> Self { + Self::new() + } +} +impl ::std::marker::Copy for __BindgenUnionField {} +impl ::std::fmt::Debug for __BindgenUnionField { + fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + fmt.write_str("__BindgenUnionField") + } +} +impl ::std::hash::Hash for __BindgenUnionField { + fn hash(&self, _state: &mut H) {} +} +impl ::std::cmp::PartialEq for __BindgenUnionField { + fn eq(&self, _other: &__BindgenUnionField) -> bool { + true + } +} +impl ::std::cmp::Eq for __BindgenUnionField {} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct TErrorResult { + pub mResult: ::std::os::raw::c_int, + pub __bindgen_anon_1: TErrorResult__bindgen_ty_1, + pub mMightHaveUnreported: bool, + pub mUnionState: TErrorResult_UnionState, +} +pub const TErrorResult_UnionState_HasMessage: TErrorResult_UnionState = 0; +pub const TErrorResult_UnionState_HasException: TErrorResult_UnionState = 0; +pub type TErrorResult_UnionState = i32; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct TErrorResult_Message { + _unused: [u8; 0], +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct TErrorResult_DOMExceptionInfo { + _unused: [u8; 0], +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct TErrorResult__bindgen_ty_1 { + pub mMessage: __BindgenUnionField<*mut TErrorResult_Message>, + pub mDOMExceptionInfo: + __BindgenUnionField<*mut TErrorResult_DOMExceptionInfo>, + pub bindgen_union_field: u64, +} +impl Default for TErrorResult { + fn default() -> Self { + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } + } +} +#[repr(C)] +#[derive(Debug, Copy)] +pub struct ErrorResult { + pub _base: TErrorResult, +} +impl Clone for ErrorResult { + fn clone(&self) -> Self { + *self + } +} +impl Default for ErrorResult { + fn default() -> Self { + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } + } +} diff --git a/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_class.rs b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_class.rs new file mode 100644 index 0000000000..d621b450a2 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_class.rs @@ -0,0 +1,215 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +#[derive(Default)] +pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); +impl __IncompleteArrayField { + #[inline] + pub const fn new() -> Self { + __IncompleteArrayField(::std::marker::PhantomData, []) + } + #[inline] + pub fn as_ptr(&self) -> *const T { + self as *const _ as *const T + } + #[inline] + pub fn as_mut_ptr(&mut self) -> *mut T { + self as *mut _ as *mut T + } + #[inline] + pub unsafe fn as_slice(&self, len: usize) -> &[T] { + unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } + } + #[inline] + pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { + unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } + } +} +impl ::std::fmt::Debug for __IncompleteArrayField { + fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + fmt.write_str("__IncompleteArrayField") + } +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct C { + pub a: ::std::os::raw::c_int, + pub big_array: [::std::os::raw::c_char; 33usize], +} +impl Default for C { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] +#[derive(Debug)] +pub struct C_with_zero_length_array { + pub a: ::std::os::raw::c_int, + pub big_array: [::std::os::raw::c_char; 33usize], + pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, +} +impl Default for C_with_zero_length_array { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] +#[derive(Debug, Default)] +pub struct C_with_zero_length_array_2 { + pub a: ::std::os::raw::c_int, + pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, +} +#[repr(C)] +#[derive(Debug)] +pub struct C_with_incomplete_array { + pub a: ::std::os::raw::c_int, + pub big_array: [::std::os::raw::c_char; 33usize], + pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, +} +impl Default for C_with_incomplete_array { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] +#[derive(Debug, Default)] +pub struct C_with_incomplete_array_2 { + pub a: ::std::os::raw::c_int, + pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, +} +#[repr(C)] +#[derive(Debug)] +pub struct C_with_zero_length_array_and_incomplete_array { + pub a: ::std::os::raw::c_int, + pub big_array: [::std::os::raw::c_char; 33usize], + pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, + pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, +} +impl Default for C_with_zero_length_array_and_incomplete_array { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] +#[derive(Debug, Default)] +pub struct C_with_zero_length_array_and_incomplete_array_2 { + pub a: ::std::os::raw::c_int, + pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, + pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, +} +#[repr(C)] +#[derive(Debug, Default)] +pub struct WithDtor { + pub b: ::std::os::raw::c_int, +} +#[repr(C)] +#[derive(Debug)] +pub struct IncompleteArrayNonCopiable { + pub whatever: *mut ::std::os::raw::c_void, + pub incomplete_array: __IncompleteArrayField, +} +impl Default for IncompleteArrayNonCopiable { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] +#[derive(Copy, Clone)] +pub union Union { + pub d: f32, + pub i: ::std::os::raw::c_int, +} +impl Default for Union { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct WithUnion { + pub data: Union, +} +impl Default for WithUnion { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct RealAbstractionWithTonsOfMethods { + pub _address: u8, +} +extern "C" { + #[link_name = "\u{1}_ZNK32RealAbstractionWithTonsOfMethods3barEv"] + pub fn RealAbstractionWithTonsOfMethods_bar( + this: *const RealAbstractionWithTonsOfMethods, + ); +} +extern "C" { + #[link_name = "\u{1}_ZN32RealAbstractionWithTonsOfMethods3barEv"] + pub fn RealAbstractionWithTonsOfMethods_bar1( + this: *mut RealAbstractionWithTonsOfMethods, + ); +} +extern "C" { + #[link_name = "\u{1}_ZN32RealAbstractionWithTonsOfMethods3barEi"] + pub fn RealAbstractionWithTonsOfMethods_bar2( + this: *mut RealAbstractionWithTonsOfMethods, + foo: ::std::os::raw::c_int, + ); +} +extern "C" { + #[link_name = "\u{1}_ZN32RealAbstractionWithTonsOfMethods3staEv"] + pub fn RealAbstractionWithTonsOfMethods_sta(); +} +impl RealAbstractionWithTonsOfMethods { + #[inline] + pub unsafe fn bar(&self) { + unsafe { RealAbstractionWithTonsOfMethods_bar(self) } + } + #[inline] + pub unsafe fn bar1(&mut self) { + unsafe { RealAbstractionWithTonsOfMethods_bar1(self) } + } + #[inline] + pub unsafe fn bar2(&mut self, foo: ::std::os::raw::c_int) { + unsafe { RealAbstractionWithTonsOfMethods_bar2(self, foo) } + } + #[inline] + pub unsafe fn sta() { + unsafe { RealAbstractionWithTonsOfMethods_sta() } + } +} diff --git a/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_dynamic_loading_simple.rs b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_dynamic_loading_simple.rs new file mode 100644 index 0000000000..5864ba0a8d --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_dynamic_loading_simple.rs @@ -0,0 +1,74 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +extern crate libloading; +pub struct TestLib { + __library: ::libloading::Library, + pub foo: Result< + unsafe extern "C" fn( + x: ::std::os::raw::c_int, + y: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + ::libloading::Error, + >, + pub bar: Result< + unsafe extern "C" fn( + x: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int, + ::libloading::Error, + >, + pub baz: Result< + unsafe extern "C" fn() -> ::std::os::raw::c_int, + ::libloading::Error, + >, +} +impl TestLib { + pub unsafe fn new

(path: P) -> Result + where + P: AsRef<::std::ffi::OsStr>, + { + let library = ::libloading::Library::new(path)?; + unsafe { Self::from_library(library) } + } + pub unsafe fn from_library( + library: L, + ) -> Result + where + L: Into<::libloading::Library>, + { + let __library = library.into(); + let foo = unsafe { __library.get(b"foo\0") }.map(|sym| *sym); + let bar = unsafe { __library.get(b"bar\0") }.map(|sym| *sym); + let baz = unsafe { __library.get(b"baz\0") }.map(|sym| *sym); + Ok(TestLib { + __library, + foo, + bar, + baz, + }) + } + pub unsafe fn foo( + &self, + x: ::std::os::raw::c_int, + y: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int { + unsafe { + (self.foo.as_ref().expect("Expected function, got error."))(x, y) + } + } + pub unsafe fn bar( + &self, + x: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int { + unsafe { + (self.bar.as_ref().expect("Expected function, got error."))(x) + } + } + pub unsafe fn baz(&self) -> ::std::os::raw::c_int { + unsafe { (self.baz.as_ref().expect("Expected function, got error."))() } + } +} diff --git a/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_objc_class.rs b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_objc_class.rs new file mode 100644 index 0000000000..0fe8e254c3 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_objc_class.rs @@ -0,0 +1,38 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] +#![cfg(target_os = "macos")] + +use objc::{self, class, msg_send, sel, sel_impl}; +#[allow(non_camel_case_types)] +pub type id = *mut objc::runtime::Object; +extern "C" { + pub static mut fooVar: Foo; +} +#[repr(transparent)] +#[derive(Debug, Copy, Clone)] +pub struct Foo(pub id); +impl std::ops::Deref for Foo { + type Target = objc::runtime::Object; + fn deref(&self) -> &Self::Target { + unsafe { &*self.0 } + } +} +unsafe impl objc::Message for Foo {} +impl Foo { + pub fn alloc() -> Self { + Self(unsafe { msg_send!(class!(Foo), alloc) }) + } +} +impl IFoo for Foo {} +pub trait IFoo: Sized + std::ops::Deref { + unsafe fn method(&self) + where + ::Target: objc::Message + Sized, + { + unsafe { msg_send!(*self, method) } + } +} diff --git a/bindgen-tests/tests/expectations/tests/zero-size-array-align.rs b/bindgen-tests/tests/expectations/tests/zero-size-array-align.rs index e99abb8721..d7d0f6613d 100644 --- a/bindgen-tests/tests/expectations/tests/zero-size-array-align.rs +++ b/bindgen-tests/tests/expectations/tests/zero-size-array-align.rs @@ -23,11 +23,11 @@ impl __IncompleteArrayField { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } + ::std::slice::from_raw_parts(self.as_ptr(), len) } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } + ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } impl ::std::fmt::Debug for __IncompleteArrayField { diff --git a/bindgen-tests/tests/expectations/tests/zero-sized-array.rs b/bindgen-tests/tests/expectations/tests/zero-sized-array.rs index 27c48f0e25..4ba52498c4 100644 --- a/bindgen-tests/tests/expectations/tests/zero-sized-array.rs +++ b/bindgen-tests/tests/expectations/tests/zero-sized-array.rs @@ -23,11 +23,11 @@ impl __IncompleteArrayField { } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) } + ::std::slice::from_raw_parts(self.as_ptr(), len) } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } + ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } } impl ::std::fmt::Debug for __IncompleteArrayField { diff --git a/bindgen-tests/tests/headers/wrap_unsafe_ops_anon_union_1_0.hpp b/bindgen-tests/tests/headers/wrap_unsafe_ops_anon_union_1_0.hpp new file mode 100644 index 0000000000..3b595f2ea7 --- /dev/null +++ b/bindgen-tests/tests/headers/wrap_unsafe_ops_anon_union_1_0.hpp @@ -0,0 +1,22 @@ +// bindgen-flags: --rust-target 1.0 --wrap-unsafe-ops --no-layout-tests + +template +struct TErrorResult { + enum UnionState { + HasMessage, + HasException, + }; + int mResult; + struct Message; + struct DOMExceptionInfo; + union { + Message* mMessage; + DOMExceptionInfo* mDOMExceptionInfo; + }; + + bool mMightHaveUnreported; + UnionState mUnionState; +}; + +struct ErrorResult : public TErrorResult { +}; diff --git a/bindgen-tests/tests/headers/wrap_unsafe_ops_class.hpp b/bindgen-tests/tests/headers/wrap_unsafe_ops_class.hpp new file mode 100644 index 0000000000..e3d11c571b --- /dev/null +++ b/bindgen-tests/tests/headers/wrap_unsafe_ops_class.hpp @@ -0,0 +1,74 @@ +// bindgen-flags: --wrap-unsafe-ops --no-layout-tests + +class C { + int a; + // More than rust limits (32) + char big_array[33]; +}; + +class C_with_zero_length_array { + int a; + // More than rust limits (32) + char big_array[33]; + char zero_length_array[0]; +}; + +class C_with_zero_length_array_2 { + int a; + char zero_length_array[0]; +}; + +class C_with_incomplete_array { + int a; + // More than rust limits (32) + char big_array[33]; + char incomplete_array[]; +}; + +class C_with_incomplete_array_2 { + int a; + char incomplete_array[]; +}; + +class C_with_zero_length_array_and_incomplete_array { + int a; + // More than rust limits (32) + char big_array[33]; + char zero_length_array[0]; + char incomplete_array[]; +}; + +class C_with_zero_length_array_and_incomplete_array_2 { + int a; + char zero_length_array[0]; + char incomplete_array[]; +}; + +class WithDtor { + int b; + + ~WithDtor() {} +}; + +class IncompleteArrayNonCopiable { + void* whatever; + C incomplete_array[]; +}; + +union Union { + float d; + int i; +}; + +class WithUnion { + Union data; +}; + +class RealAbstractionWithTonsOfMethods { + void foo(); +public: + void bar() const; + void bar(); + void bar(int foo); + static void sta(); +}; diff --git a/bindgen-tests/tests/headers/wrap_unsafe_ops_dynamic_loading_simple.h b/bindgen-tests/tests/headers/wrap_unsafe_ops_dynamic_loading_simple.h new file mode 100644 index 0000000000..2b8c107185 --- /dev/null +++ b/bindgen-tests/tests/headers/wrap_unsafe_ops_dynamic_loading_simple.h @@ -0,0 +1,5 @@ +// bindgen-flags: --dynamic-loading TestLib --wrap-unsafe-ops + +int foo(int x, int y); +int bar(void *x); +int baz(); diff --git a/bindgen-tests/tests/headers/wrap_unsafe_ops_objc_class.h b/bindgen-tests/tests/headers/wrap_unsafe_ops_objc_class.h new file mode 100644 index 0000000000..017795c85d --- /dev/null +++ b/bindgen-tests/tests/headers/wrap_unsafe_ops_objc_class.h @@ -0,0 +1,10 @@ +// bindgen-flags: --wrap-unsafe-ops -- -x objective-c +// bindgen-osx-only + +@class Foo; + +Foo* fooVar; + +@interface Foo +-(void)method; +@end diff --git a/bindgen/codegen/dyngen.rs b/bindgen/codegen/dyngen.rs index f310f14e08..5e734ccd15 100644 --- a/bindgen/codegen/dyngen.rs +++ b/bindgen/codegen/dyngen.rs @@ -1,4 +1,5 @@ use crate::codegen; +use crate::ir::context::BindgenContext; use crate::ir::function::ClangAbi; use proc_macro2::Ident; @@ -72,12 +73,22 @@ impl DynamicItems { Self::default() } - pub fn get_tokens(&self, lib_ident: Ident) -> proc_macro2::TokenStream { + pub fn get_tokens( + &self, + lib_ident: Ident, + ctx: &BindgenContext, + ) -> proc_macro2::TokenStream { let struct_members = &self.struct_members; let constructor_inits = &self.constructor_inits; let init_fields = &self.init_fields; let struct_implementation = &self.struct_implementation; + let from_library = if ctx.options().wrap_unsafe_ops { + quote!(unsafe { Self::from_library(library) }) + } else { + quote!(Self::from_library(library)) + }; + quote! { extern crate libloading; @@ -92,9 +103,7 @@ impl DynamicItems { ) -> Result where P: AsRef<::std::ffi::OsStr> { let library = ::libloading::Library::new(path)?; - unsafe { - Self::from_library(library) - } + #from_library } pub unsafe fn from_library( @@ -126,6 +135,7 @@ impl DynamicItems { ret: proc_macro2::TokenStream, ret_ty: proc_macro2::TokenStream, attributes: Vec, + ctx: &BindgenContext, ) { if !is_variadic { assert_eq!(args.len(), args_identifiers.len()); @@ -149,8 +159,10 @@ impl DynamicItems { } else { quote! { self.#ident.as_ref().expect("Expected function, got error.") } }; - let call_body = quote! { - (#fn_)(#( #args_identifiers ),*) + let call_body = if ctx.options().wrap_unsafe_ops { + quote!(unsafe { (#fn_)(#( #args_identifiers ),*) }) + } else { + quote!((#fn_)(#( #args_identifiers ),*) ) }; // We can't implement variadic functions from C easily, so we allow to @@ -159,22 +171,26 @@ impl DynamicItems { self.struct_implementation.push(quote! { #(#attributes)* pub unsafe fn #ident ( &self, #( #args ),* ) -> #ret_ty { - unsafe { - #call_body - } + #call_body } }); } // N.B: Unwrap the signature upon construction if it is required to be resolved. let ident_str = codegen::helpers::ast_ty::cstr_expr(ident.to_string()); + let library_get = if ctx.options().wrap_unsafe_ops { + quote!(unsafe { __library.get(#ident_str) }) + } else { + quote!(__library.get(#ident_str)) + }; + self.constructor_inits.push(if is_required { quote! { - let #ident = unsafe { __library.get(#ident_str) }.map(|sym| *sym)?; + let #ident = #library_get.map(|sym| *sym)?; } } else { quote! { - let #ident = unsafe { __library.get(#ident_str) }.map(|sym| *sym); + let #ident = #library_get.map(|sym| *sym); } }); diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index c1e92b77d5..e537242710 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -2585,9 +2585,7 @@ impl MethodCodegen for Method { }) } - let block = quote! { - #( #stmts );* - }; + let block = ctx.wrap_unsafe_ops(quote! ( #( #stmts );*)); let mut attrs = vec![attributes::inline()]; @@ -2601,9 +2599,7 @@ impl MethodCodegen for Method { methods.push(quote! { #(#attrs)* pub unsafe fn #name ( #( #args ),* ) #ret { - unsafe { - #block - } + #block } }); } @@ -4169,6 +4165,7 @@ impl CodeGenerator for Function { ret, ret_ty, attributes, + ctx, ); } else { result.push(tokens); @@ -4212,17 +4209,18 @@ fn objc_method_codegen( let methods_and_args = method.format_method_call(&fn_args); - let body = if method.is_class_method() { - let class_name = ctx.rust_ident( - class_name.expect("Generating a class method without class name?"), - ); - quote! { - msg_send!(class!(#class_name), #methods_and_args) - } - } else { - quote! { - msg_send!(*self, #methods_and_args) - } + let body = { + let body = if method.is_class_method() { + let class_name = ctx.rust_ident( + class_name + .expect("Generating a class method without class name?"), + ); + quote!(msg_send!(class!(#class_name), #methods_and_args)) + } else { + quote!(msg_send!(*self, #methods_and_args)) + }; + + ctx.wrap_unsafe_ops(body) }; let method_name = @@ -4230,9 +4228,7 @@ fn objc_method_codegen( methods.push(quote! { unsafe fn #method_name #sig where ::Target: objc::Message + Sized { - unsafe { - #body - } + #body } }); } @@ -4495,7 +4491,7 @@ pub(crate) fn codegen( if let Some(ref lib_name) = context.options().dynamic_library_name { let lib_ident = context.rust_ident(lib_name); let dynamic_items_tokens = - result.dynamic_items().get_tokens(lib_ident); + result.dynamic_items().get_tokens(lib_ident, context); result.push(dynamic_items_tokens); } @@ -4598,6 +4594,9 @@ pub mod utils { pub struct __BindgenUnionField(::#prefix::marker::PhantomData); }; + let transmute = + ctx.wrap_unsafe_ops(quote!(::#prefix::mem::transmute(self))); + let union_field_impl = quote! { impl __BindgenUnionField { #[inline] @@ -4607,16 +4606,12 @@ pub mod utils { #[inline] pub unsafe fn as_ref(&self) -> &T { - unsafe { - ::#prefix::mem::transmute(self) - } + #transmute } #[inline] pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { - ::#prefix::mem::transmute(self) - } + #transmute } } }; @@ -4711,6 +4706,13 @@ pub mod utils { ::#prefix::marker::PhantomData, [T; 0]); }; + let from_raw_parts = ctx.wrap_unsafe_ops(quote! ( + ::#prefix::slice::from_raw_parts(self.as_ptr(), len) + )); + let from_raw_parts_mut = ctx.wrap_unsafe_ops(quote! ( + ::#prefix::slice::from_raw_parts_mut(self.as_mut_ptr(), len) + )); + let incomplete_array_impl = quote! { impl __IncompleteArrayField { #[inline] @@ -4730,16 +4732,12 @@ pub mod utils { #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { - unsafe { - ::#prefix::slice::from_raw_parts(self.as_ptr(), len) - } + #from_raw_parts } #[inline] pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - unsafe { - ::#prefix::slice::from_raw_parts_mut(self.as_mut_ptr(), len) - } + #from_raw_parts_mut } } }; diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index 928f24067b..4623b25344 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -25,7 +25,8 @@ use crate::BindgenOptions; use crate::{Entry, HashMap, HashSet}; use cexpr; use clang_sys; -use proc_macro2::{Ident, Span}; +use proc_macro2::{Ident, Span, TokenStream}; +use quote::ToTokens; use std::borrow::Cow; use std::cell::{Cell, RefCell}; use std::collections::{BTreeSet, HashMap as StdHashMap}; @@ -2702,6 +2703,14 @@ If you encounter an error missing from this list, please file an issue or a PR!" let name = item.path_for_allowlisting(self)[1..].join("::"); self.options().must_use_types.matches(name) } + + pub(crate) fn wrap_unsafe_ops(&self, tokens: impl ToTokens) -> TokenStream { + if self.options.wrap_unsafe_ops { + quote!(unsafe { #tokens }) + } else { + tokens.into_token_stream() + } + } } /// A builder struct for configuring item resolution options. diff --git a/bindgen/lib.rs b/bindgen/lib.rs index d281e94967..53bbd8874c 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -645,6 +645,10 @@ impl Builder { output_vector.push("--merge-extern-blocks".into()); } + if self.options.wrap_unsafe_ops { + output_vector.push("--wrap-unsafe-ops".into()); + } + // Add clang arguments output_vector.push("--".into()); @@ -1770,6 +1774,12 @@ impl Builder { .insert(arg.into()); self } + + /// If true, wraps unsafe operations in unsafe blocks. + pub fn wrap_unsafe_ops(mut self, doit: bool) -> Self { + self.options.wrap_unsafe_ops = doit; + self + } } /// Configuration options for generated bindings. @@ -2107,6 +2117,9 @@ struct BindgenOptions { merge_extern_blocks: bool, abi_overrides: HashMap, + + /// Whether to wrap unsafe operations in unsafe blocks or not. + wrap_unsafe_ops: bool, } impl BindgenOptions { @@ -2298,6 +2311,7 @@ impl Default for BindgenOptions { sort_semantically, merge_extern_blocks, abi_overrides, + wrap_unsafe_ops, } } } From 7e4174990c68bcc56314a31774639d88b2dbc692 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Tue, 22 Nov 2022 12:31:14 -0500 Subject: [PATCH 419/942] Deprecate Rust targets lower or equal than `1.30` (#2356) --- CHANGELOG.md | 3 +++ bindgen/features.rs | 21 +++++++++++---------- bindgen/lib.rs | 7 +++++++ 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0664a6d8c9..387d8e94a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -159,6 +159,9 @@ * Replace the `name: &str` argument for `ParseCallbacks::add_derives` by `info: DeriveInfo`. + * All the rust targets equal or lower than `1.30` are being deprecated and + will be removed in the future. If you have a good reason to use any of these + targets, please report it in the issue tracker. ## Removed diff --git a/bindgen/features.rs b/bindgen/features.rs index 9f6535aa40..4fee5d63fc 100644 --- a/bindgen/features.rs +++ b/bindgen/features.rs @@ -2,6 +2,7 @@ #![deny(missing_docs)] #![deny(unused_extern_crates)] +#![allow(deprecated)] use std::io; use std::str::FromStr; @@ -86,35 +87,35 @@ macro_rules! rust_target_base { ( $x_macro:ident ) => { $x_macro!( /// Rust stable 1.0 - => Stable_1_0 => 1.0; + #[deprecated = "This rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues"] => Stable_1_0 => 1.0; /// Rust stable 1.17 /// * Static lifetime elision ([RFC 1623](https://github.com/rust-lang/rfcs/blob/master/text/1623-static.md)) - => Stable_1_17 => 1.17; + #[deprecated = "This rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues"] => Stable_1_17 => 1.17; /// Rust stable 1.19 /// * Untagged unions ([RFC 1444](https://github.com/rust-lang/rfcs/blob/master/text/1444-union.md)) - => Stable_1_19 => 1.19; + #[deprecated = "This rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues"] => Stable_1_19 => 1.19; /// Rust stable 1.20 /// * Associated constants ([PR](https://github.com/rust-lang/rust/pull/42809)) - => Stable_1_20 => 1.20; + #[deprecated = "This rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues"] => Stable_1_20 => 1.20; /// Rust stable 1.21 /// * Builtin impls for `Clone` ([PR](https://github.com/rust-lang/rust/pull/43690)) - => Stable_1_21 => 1.21; + #[deprecated = "This rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues"] => Stable_1_21 => 1.21; /// Rust stable 1.25 /// * `repr(align)` ([PR](https://github.com/rust-lang/rust/pull/47006)) - => Stable_1_25 => 1.25; + #[deprecated = "This rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues"] => Stable_1_25 => 1.25; /// Rust stable 1.26 /// * [i128 / u128 support](https://doc.rust-lang.org/std/primitive.i128.html) - => Stable_1_26 => 1.26; + #[deprecated = "This rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues"] => Stable_1_26 => 1.26; /// Rust stable 1.27 /// * `must_use` attribute on functions ([PR](https://github.com/rust-lang/rust/pull/48925)) - => Stable_1_27 => 1.27; + #[deprecated = "This rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues"] => Stable_1_27 => 1.27; /// Rust stable 1.28 /// * `repr(transparent)` ([PR](https://github.com/rust-lang/rust/pull/51562)) - => Stable_1_28 => 1.28; + #[deprecated = "This rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues"] => Stable_1_28 => 1.28; /// Rust stable 1.30 /// * `const fn` support for limited cases ([PR](https://github.com/rust-lang/rust/pull/54835/) /// * [c_void available in core](https://doc.rust-lang.org/core/ffi/enum.c_void.html) - => Stable_1_30 => 1.30; + #[deprecated = "This rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues"] => Stable_1_30 => 1.30; /// Rust stable 1.33 /// * repr(packed(N)) ([PR](https://github.com/rust-lang/rust/pull/57049)) => Stable_1_33 => 1.33; diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 53bbd8874c..4b71fb97ce 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -731,6 +731,13 @@ impl Builder { /// /// The default is the latest stable Rust version pub fn rust_target(mut self, rust_target: RustTarget) -> Self { + #[allow(deprecated)] + if rust_target <= RustTarget::Stable_1_30 { + warn!( + "The {} rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues", + String::from(rust_target) + ); + } self.options.set_rust_target(rust_target); self } From d828f3f7adc7957a257a0337f41f3d9a28ebf8db Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Tue, 22 Nov 2022 12:44:10 -0500 Subject: [PATCH 420/942] Release v0.63.0 (#2357) --- CHANGELOG.md | 17 ++++++++++++----- bindgen-cli/Cargo.toml | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 387d8e94a6..7cac405a60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -153,10 +153,21 @@ ## Added +## Changed + +## Removed + +## Fixed + +## Security + +# 0.63.0 + +## Added + ## Changed * Only wrap unsafe operations in unsafe blocks if the `--wrap_unsafe_ops` option is enabled. - * Replace the `name: &str` argument for `ParseCallbacks::add_derives` by `info: DeriveInfo`. * All the rust targets equal or lower than `1.30` are being deprecated and @@ -171,10 +182,6 @@ `whitelist_type`, `whitelist_function`, `whitelisted_function`, `whitelist_var`, `whitelisted_var`, `unstable_rust`. -## Fixed - -## Security - # 0.62.0 ## Added diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index b2b56a9434..99a6c62277 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -21,7 +21,7 @@ path = "main.rs" name = "bindgen" [dependencies] -bindgen = { path = "../bindgen" } +bindgen = { path = "../bindgen", version = "=0.63.0" } shlex = "1" clap = "3" env_logger = { version = "0.9.0", optional = true } From c51591941e18a75c312c7c237c4969dd22c40467 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 22 Nov 2022 19:27:27 +0100 Subject: [PATCH 421/942] CONTRIBUTING: Add docs for doing a release. (#2358) --- CONTRIBUTING.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 48e4a4025e..e3e51d8fd1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -518,3 +518,49 @@ case down to 5 lines. Happy bug hunting and test case reducing! [More information on using `creduce`.](https://embed.cs.utah.edu/creduce/using/) + +## Cutting a new bindgen release + +To cut a release, the following needs to happen: + +### Updating the changelog + +Update the CHANGELOG.md file with the changes from the last release. Something +like the following is a useful way to check what has landed: + + ``` + $ git log --oneline v0.62.0..HEAD + ``` + +Also worth checking the [next-release tag](https://github.com/rust-lang/rust-bindgen/pulls?q=is%3Apr+label%3Anext-release). + +Once that's done and the changelog is up-to-date, run `doctoc` on it. + +If needed, install it locally by running: + +``` +$ npm install doctoc +$ ./node_modules/doctoc/doctoc.js CHANGELOG.md +``` + +### Bumping the version numbers. + +Bump version numbers as needed. Run tests just to ensure everything is working +as expected. + +### Merge to `master` + +For regular releases, the changes above should end up in `master` before +publishing. For dot-releases of an old version (e.g., cherry-picking an +important fix) you can skip this. + +### Publish and add a git tag for the right commit + +Once you're in the right commit, do: + +``` +$ git tag -a v0.62.1 # With the right version of course +$ pushd bindgen && cargo publish && popd +$ pushd bindgen-cli && cargo publish && popd +$ git push --tags upstream # To publish the tag +``` From 6e5a666507bb5f4611dc31ca2e11e73cb5ffdbd1 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Wed, 23 Nov 2022 12:48:24 -0500 Subject: [PATCH 422/942] Escape method fragments that happen to be rust keywords (#2359) --- .../tests/expectations/tests/objc_escape.rs | 38 +++++++++++++++++++ bindgen-tests/tests/headers/objc_escape.h | 6 +++ bindgen/ir/objc.rs | 12 +++++- 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 bindgen-tests/tests/expectations/tests/objc_escape.rs create mode 100644 bindgen-tests/tests/headers/objc_escape.h diff --git a/bindgen-tests/tests/expectations/tests/objc_escape.rs b/bindgen-tests/tests/expectations/tests/objc_escape.rs new file mode 100644 index 0000000000..c2f0ce313c --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/objc_escape.rs @@ -0,0 +1,38 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] +#![cfg(target_os = "macos")] + +use objc::{self, class, msg_send, sel, sel_impl}; +#[allow(non_camel_case_types)] +pub type id = *mut objc::runtime::Object; +#[repr(transparent)] +#[derive(Debug, Copy, Clone)] +pub struct A(pub id); +impl std::ops::Deref for A { + type Target = objc::runtime::Object; + fn deref(&self) -> &Self::Target { + unsafe { &*self.0 } + } +} +unsafe impl objc::Message for A {} +impl A { + pub fn alloc() -> Self { + Self(unsafe { msg_send!(class!(A), alloc) }) + } +} +impl IA for A {} +pub trait IA: Sized + std::ops::Deref { + unsafe fn f_as_( + &self, + arg1: ::std::os::raw::c_int, + arg2: ::std::os::raw::c_int, + ) where + ::Target: objc::Message + Sized, + { + msg_send ! (* self , f : arg1 r#as : arg2) + } +} diff --git a/bindgen-tests/tests/headers/objc_escape.h b/bindgen-tests/tests/headers/objc_escape.h new file mode 100644 index 0000000000..184d1da8b1 --- /dev/null +++ b/bindgen-tests/tests/headers/objc_escape.h @@ -0,0 +1,6 @@ +// bindgen-flags: -- -x objective-c +// bindgen-osx-only + +@interface A +-(void)f:(int)arg1 as:(int)arg2; +@end diff --git a/bindgen/ir/objc.rs b/bindgen/ir/objc.rs index 0845ad0fde..7afa959b77 100644 --- a/bindgen/ir/objc.rs +++ b/bindgen/ir/objc.rs @@ -261,7 +261,17 @@ impl ObjCMethod { if name.is_empty() { None } else { - Some(Ident::new(name, Span::call_site())) + // Try to parse the current name as an identifier. This might fail if the + // name is a keyword so we try to prepend "r#" to it and parse again. If + // this also fails, we panic with the first error. + Some( + syn::parse_str::(name) + .or_else(|err| { + syn::parse_str::(&format!("r#{}", name)) + .map_err(|_| err) + }) + .expect("Invalid identifier"), + ) } }) .collect(); From 73f33e5a0288f4030e1e4389db0d9bfca1d69d2d Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Thu, 24 Nov 2022 10:50:15 -0500 Subject: [PATCH 423/942] Fix clippy warnings (#2362) --- bindgen/codegen/mod.rs | 64 +++++++++++++------------- bindgen/ir/analysis/template_params.rs | 5 +- bindgen/lib.rs | 2 +- 3 files changed, 35 insertions(+), 36 deletions(-) diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index e537242710..e201578e46 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -434,10 +434,10 @@ trait CodeGenerator { /// Extra information returned to the caller. type Return; - fn codegen<'a>( + fn codegen( &self, ctx: &BindgenContext, - result: &mut CodegenResult<'a>, + result: &mut CodegenResult<'_>, extra: &Self::Extra, ) -> Self::Return; } @@ -477,10 +477,10 @@ impl CodeGenerator for Item { type Extra = (); type Return = (); - fn codegen<'a>( + fn codegen( &self, ctx: &BindgenContext, - result: &mut CodegenResult<'a>, + result: &mut CodegenResult<'_>, _extra: &(), ) { debug!("::codegen: self = {:?}", self); @@ -509,10 +509,10 @@ impl CodeGenerator for Module { type Extra = Item; type Return = (); - fn codegen<'a>( + fn codegen( &self, ctx: &BindgenContext, - result: &mut CodegenResult<'a>, + result: &mut CodegenResult<'_>, item: &Item, ) { debug!("::codegen: item = {:?}", item); @@ -601,10 +601,10 @@ impl CodeGenerator for Var { type Extra = Item; type Return = (); - fn codegen<'a>( + fn codegen( &self, ctx: &BindgenContext, - result: &mut CodegenResult<'a>, + result: &mut CodegenResult<'_>, item: &Item, ) { use crate::ir::var::VarType; @@ -748,10 +748,10 @@ impl CodeGenerator for Type { type Extra = Item; type Return = (); - fn codegen<'a>( + fn codegen( &self, ctx: &BindgenContext, - result: &mut CodegenResult<'a>, + result: &mut CodegenResult<'_>, item: &Item, ) { debug!("::codegen: item = {:?}", item); @@ -1069,10 +1069,10 @@ impl<'a> CodeGenerator for Vtable<'a> { type Extra = Item; type Return = (); - fn codegen<'b>( + fn codegen( &self, ctx: &BindgenContext, - result: &mut CodegenResult<'b>, + result: &mut CodegenResult<'_>, item: &Item, ) { assert_eq!(item.id(), self.item_id); @@ -1168,10 +1168,10 @@ impl CodeGenerator for TemplateInstantiation { type Extra = Item; type Return = (); - fn codegen<'a>( + fn codegen( &self, ctx: &BindgenContext, - result: &mut CodegenResult<'a>, + result: &mut CodegenResult<'_>, item: &Item, ) { debug_assert!(item.is_enabled_for_codegen(ctx)); @@ -1796,10 +1796,10 @@ impl CodeGenerator for CompInfo { type Extra = Item; type Return = (); - fn codegen<'a>( + fn codegen( &self, ctx: &BindgenContext, - result: &mut CodegenResult<'a>, + result: &mut CodegenResult<'_>, item: &Item, ) { debug!("::codegen: item = {:?}", item); @@ -2407,23 +2407,23 @@ impl CodeGenerator for CompInfo { } trait MethodCodegen { - fn codegen_method<'a>( + fn codegen_method( &self, ctx: &BindgenContext, methods: &mut Vec, method_names: &mut HashSet, - result: &mut CodegenResult<'a>, + result: &mut CodegenResult<'_>, parent: &CompInfo, ); } impl MethodCodegen for Method { - fn codegen_method<'a>( + fn codegen_method( &self, ctx: &BindgenContext, methods: &mut Vec, method_names: &mut HashSet, - result: &mut CodegenResult<'a>, + result: &mut CodegenResult<'_>, _parent: &CompInfo, ) { assert!({ @@ -2779,13 +2779,13 @@ impl<'a> EnumBuilder<'a> { } /// Add a variant to this enum. - fn with_variant<'b>( + fn with_variant( self, ctx: &BindgenContext, variant: &EnumVariant, mangling_prefix: Option<&str>, rust_ty: proc_macro2::TokenStream, - result: &mut CodegenResult<'b>, + result: &mut CodegenResult<'_>, is_ty_named: bool, ) -> Self { let variant_name = ctx.rust_mangle(variant.name()); @@ -2896,11 +2896,11 @@ impl<'a> EnumBuilder<'a> { } } - fn build<'b>( + fn build( self, ctx: &BindgenContext, rust_ty: proc_macro2::TokenStream, - result: &mut CodegenResult<'b>, + result: &mut CodegenResult<'_>, ) -> proc_macro2::TokenStream { match self { EnumBuilder::Rust { @@ -2999,10 +2999,10 @@ impl CodeGenerator for Enum { type Extra = Item; type Return = (); - fn codegen<'a>( + fn codegen( &self, ctx: &BindgenContext, - result: &mut CodegenResult<'a>, + result: &mut CodegenResult<'_>, item: &Item, ) { debug!("::codegen: item = {:?}", item); @@ -3137,7 +3137,7 @@ impl CodeGenerator for Enum { attrs.push(attributes::derives(&derives)); } - fn add_constant<'a>( + fn add_constant( ctx: &BindgenContext, enum_: &Type, // Only to avoid recomputing every time. @@ -3148,7 +3148,7 @@ impl CodeGenerator for Enum { variant_name: &Ident, referenced_name: &Ident, enum_rust_ty: proc_macro2::TokenStream, - result: &mut CodegenResult<'a>, + result: &mut CodegenResult<'_>, ) { let constant_name = if enum_.name().is_some() { if ctx.options().prepend_enum_name { @@ -3995,10 +3995,10 @@ impl CodeGenerator for Function { /// it. type Return = Option; - fn codegen<'a>( + fn codegen( &self, ctx: &BindgenContext, - result: &mut CodegenResult<'a>, + result: &mut CodegenResult<'_>, item: &Item, ) -> Self::Return { debug!("::codegen: item = {:?}", item); @@ -4237,10 +4237,10 @@ impl CodeGenerator for ObjCInterface { type Extra = Item; type Return = (); - fn codegen<'a>( + fn codegen( &self, ctx: &BindgenContext, - result: &mut CodegenResult<'a>, + result: &mut CodegenResult<'_>, item: &Item, ) { debug_assert!(item.is_enabled_for_codegen(ctx)); diff --git a/bindgen/ir/analysis/template_params.rs b/bindgen/ir/analysis/template_params.rs index e88b774dee..f4f0c59d71 100644 --- a/bindgen/ir/analysis/template_params.rs +++ b/bindgen/ir/analysis/template_params.rs @@ -424,8 +424,7 @@ impl<'ctx> MonotoneFramework for UsedTemplateParameters<'ctx> { // generic template parameters are used. let item_kind = ctx.resolve_item(item).as_type().map(|ty| ty.kind()); - if let Some(&TypeKind::TemplateInstantiation(ref inst)) = item_kind - { + if let Some(TypeKind::TemplateInstantiation(inst)) = item_kind { let decl = ctx.resolve_type(inst.template_definition()); let args = inst.template_arguments(); @@ -540,7 +539,7 @@ impl<'ctx> MonotoneFramework for UsedTemplateParameters<'ctx> { } // Template instantiations only use their template arguments if the // template definition uses the corresponding template parameter. - Some(&TypeKind::TemplateInstantiation(ref inst)) => { + Some(TypeKind::TemplateInstantiation(inst)) => { if self .allowlisted_items .contains(&inst.template_definition().into()) diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 4b71fb97ce..4402dfc76d 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -1605,7 +1605,7 @@ impl Builder { // For each input header content, add a prefix line of `#line 0 "$name"` // followed by the contents. - for &(ref name, ref contents) in &self.options.input_header_contents { + for (name, contents) in &self.options.input_header_contents { is_cpp |= file_is_cpp(name); wrapper_contents.push_str("#line 0 \""); From 95fd17b874910184cc0fcd33b287fa4e205d9d7a Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Thu, 24 Nov 2022 11:17:08 -0500 Subject: [PATCH 424/942] Remove traits that have a single implementation (#2363) --- bindgen/codegen/mod.rs | 13 +-------- bindgen/ir/comp.rs | 2 +- bindgen/ir/context.rs | 1 - bindgen/ir/enum_ty.rs | 2 +- bindgen/ir/function.rs | 4 +-- bindgen/ir/item.rs | 20 ++++++------- bindgen/ir/objc.rs | 1 - bindgen/ir/template.rs | 1 - bindgen/ir/ty.rs | 2 +- bindgen/ir/var.rs | 4 +-- bindgen/lib.rs | 2 +- bindgen/parse.rs | 64 +----------------------------------------- 12 files changed, 17 insertions(+), 99 deletions(-) diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index e201578e46..b405063737 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -2406,18 +2406,7 @@ impl CodeGenerator for CompInfo { } } -trait MethodCodegen { - fn codegen_method( - &self, - ctx: &BindgenContext, - methods: &mut Vec, - method_names: &mut HashSet, - result: &mut CodegenResult<'_>, - parent: &CompInfo, - ); -} - -impl MethodCodegen for Method { +impl Method { fn codegen_method( &self, ctx: &BindgenContext, diff --git a/bindgen/ir/comp.rs b/bindgen/ir/comp.rs index 039742a48d..18a4291cf9 100644 --- a/bindgen/ir/comp.rs +++ b/bindgen/ir/comp.rs @@ -12,7 +12,7 @@ use super::ty::RUST_DERIVE_IN_ARRAY_LIMIT; use crate::clang; use crate::codegen::struct_layout::{align_to, bytes_from_bits_pow2}; use crate::ir::derive::CanDeriveCopy; -use crate::parse::{ClangItemParser, ParseError}; +use crate::parse::ParseError; use crate::HashMap; use crate::NonCopyUnionStyle; use peeking_take_while::PeekableExt; diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index 4623b25344..3cc30f1c0b 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -20,7 +20,6 @@ use super::template::{TemplateInstantiation, TemplateParameters}; use super::traversal::{self, Edge, ItemTraversal}; use super::ty::{FloatKind, Type, TypeKind}; use crate::clang::{self, Cursor}; -use crate::parse::ClangItemParser; use crate::BindgenOptions; use crate::{Entry, HashMap, HashSet}; use cexpr; diff --git a/bindgen/ir/enum_ty.rs b/bindgen/ir/enum_ty.rs index 39677e93fd..63871fd465 100644 --- a/bindgen/ir/enum_ty.rs +++ b/bindgen/ir/enum_ty.rs @@ -6,7 +6,7 @@ use super::item::Item; use super::ty::{Type, TypeKind}; use crate::clang; use crate::ir::annotations::Annotations; -use crate::parse::{ClangItemParser, ParseError}; +use crate::parse::ParseError; use crate::regex_set::RegexSet; /// An enum representing custom handling that can be given to a variant. diff --git a/bindgen/ir/function.rs b/bindgen/ir/function.rs index 7dbbb8f849..ecb3202ff1 100644 --- a/bindgen/ir/function.rs +++ b/bindgen/ir/function.rs @@ -7,9 +7,7 @@ use super::item::Item; use super::traversal::{EdgeKind, Trace, Tracer}; use super::ty::TypeKind; use crate::clang::{self, Attribute}; -use crate::parse::{ - ClangItemParser, ClangSubItemParser, ParseError, ParseResult, -}; +use crate::parse::{ClangSubItemParser, ParseError, ParseResult}; use clang_sys::{self, CXCallingConv}; use proc_macro2; use quote; diff --git a/bindgen/ir/item.rs b/bindgen/ir/item.rs index 5e9aff9102..40f6f7d927 100644 --- a/bindgen/ir/item.rs +++ b/bindgen/ir/item.rs @@ -18,9 +18,7 @@ use super::template::{AsTemplateParam, TemplateParameters}; use super::traversal::{EdgeKind, Trace, Tracer}; use super::ty::{Type, TypeKind}; use crate::clang; -use crate::parse::{ - ClangItemParser, ClangSubItemParser, ParseError, ParseResult, -}; +use crate::parse::{ClangSubItemParser, ParseError, ParseResult}; use clang_sys; use lazycell::LazyCell; use regex; @@ -1307,8 +1305,8 @@ fn visit_child( } } -impl ClangItemParser for Item { - fn builtin_type( +impl Item { + pub(crate) fn builtin_type( kind: TypeKind, is_const: bool, ctx: &mut BindgenContext, @@ -1333,7 +1331,7 @@ impl ClangItemParser for Item { id.as_type_id_unchecked() } - fn parse( + pub(crate) fn parse( cursor: clang::Cursor, parent_id: Option, ctx: &mut BindgenContext, @@ -1479,7 +1477,7 @@ impl ClangItemParser for Item { } } - fn from_ty_or_ref( + pub(crate) fn from_ty_or_ref( ty: clang::Type, location: clang::Cursor, parent_id: Option, @@ -1499,7 +1497,7 @@ impl ClangItemParser for Item { /// /// Typerefs are resolved once parsing is completely done, see /// `BindgenContext::resolve_typerefs`. - fn from_ty_or_ref_with_id( + pub(crate) fn from_ty_or_ref_with_id( potential_id: ItemId, ty: clang::Type, location: clang::Cursor, @@ -1554,7 +1552,7 @@ impl ClangItemParser for Item { potential_id.as_type_id_unchecked() } - fn from_ty( + pub(crate) fn from_ty( ty: &clang::Type, location: clang::Cursor, parent_id: Option, @@ -1572,7 +1570,7 @@ impl ClangItemParser for Item { /// critical some times to obtain information, an optional parent item id, /// that will, if it's `None`, become the current module id, and the /// context. - fn from_ty_with_id( + pub(crate) fn from_ty_with_id( id: ItemId, ty: &clang::Type, location: clang::Cursor, @@ -1742,7 +1740,7 @@ impl ClangItemParser for Item { /// A named type is a template parameter, e.g., the "T" in Foo. They're /// always local so it's the only exception when there's no declaration for /// a type. - fn type_param( + pub(crate) fn type_param( with_id: Option, location: clang::Cursor, ctx: &mut BindgenContext, diff --git a/bindgen/ir/objc.rs b/bindgen/ir/objc.rs index 7afa959b77..4f340f6f7a 100644 --- a/bindgen/ir/objc.rs +++ b/bindgen/ir/objc.rs @@ -6,7 +6,6 @@ use super::item::Item; use super::traversal::{Trace, Tracer}; use super::ty::TypeKind; use crate::clang; -use crate::parse::ClangItemParser; use clang_sys::CXChildVisit_Continue; use clang_sys::CXCursor_ObjCCategoryDecl; use clang_sys::CXCursor_ObjCClassMethodDecl; diff --git a/bindgen/ir/template.rs b/bindgen/ir/template.rs index 8b06748e2c..e3ef6a9c96 100644 --- a/bindgen/ir/template.rs +++ b/bindgen/ir/template.rs @@ -31,7 +31,6 @@ use super::context::{BindgenContext, ItemId, TypeId}; use super::item::{IsOpaque, Item, ItemAncestors}; use super::traversal::{EdgeKind, Trace, Tracer}; use crate::clang; -use crate::parse::ClangItemParser; /// Template declaration (and such declaration's template parameters) related /// methods. diff --git a/bindgen/ir/ty.rs b/bindgen/ir/ty.rs index fd6108f774..ed3331adb2 100644 --- a/bindgen/ir/ty.rs +++ b/bindgen/ir/ty.rs @@ -14,7 +14,7 @@ use super::template::{ }; use super::traversal::{EdgeKind, Trace, Tracer}; use crate::clang::{self, Cursor}; -use crate::parse::{ClangItemParser, ParseError, ParseResult}; +use crate::parse::{ParseError, ParseResult}; use std::borrow::Cow; use std::io; diff --git a/bindgen/ir/var.rs b/bindgen/ir/var.rs index c86742ff69..610b9dfad6 100644 --- a/bindgen/ir/var.rs +++ b/bindgen/ir/var.rs @@ -10,9 +10,7 @@ use super::ty::{FloatKind, TypeKind}; use crate::callbacks::MacroParsingBehavior; use crate::clang; use crate::clang::ClangToken; -use crate::parse::{ - ClangItemParser, ClangSubItemParser, ParseError, ParseResult, -}; +use crate::parse::{ClangSubItemParser, ParseError, ParseResult}; use cexpr; use std::io; use std::num::Wrapping; diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 4402dfc76d..3068d14ec8 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -90,7 +90,7 @@ pub use crate::features::{ use crate::ir::context::{BindgenContext, ItemId}; pub use crate::ir::function::Abi; use crate::ir::item::Item; -use crate::parse::{ClangItemParser, ParseError}; +use crate::parse::ParseError; use crate::regex_set::RegexSet; use std::borrow::Cow; diff --git a/bindgen/parse.rs b/bindgen/parse.rs index f60de43177..1fd83cddda 100644 --- a/bindgen/parse.rs +++ b/bindgen/parse.rs @@ -1,8 +1,7 @@ //! Common traits and types related to parsing our IR from Clang cursors. use crate::clang; -use crate::ir::context::{BindgenContext, ItemId, TypeId}; -use crate::ir::ty::TypeKind; +use crate::ir::context::{BindgenContext, ItemId}; /// Not so much an error in the traditional sense, but a control flow message /// when walking over Clang's AST with a cursor. @@ -39,64 +38,3 @@ pub trait ClangSubItemParser: Sized { context: &mut BindgenContext, ) -> Result, ParseError>; } - -/// An intermediate representation item that can be parsed from a Clang cursor. -pub trait ClangItemParser: Sized { - /// Parse this item from the given Clang cursor. - fn parse( - cursor: clang::Cursor, - parent: Option, - context: &mut BindgenContext, - ) -> Result; - - /// Parse this item from the given Clang type. - fn from_ty( - ty: &clang::Type, - location: clang::Cursor, - parent: Option, - ctx: &mut BindgenContext, - ) -> Result; - - /// Identical to `from_ty`, but use the given `id` as the `ItemId` for the - /// newly parsed item. - fn from_ty_with_id( - id: ItemId, - ty: &clang::Type, - location: clang::Cursor, - parent: Option, - ctx: &mut BindgenContext, - ) -> Result; - - /// Parse this item from the given Clang type, or if we haven't resolved all - /// the other items this one depends on, an unresolved reference. - fn from_ty_or_ref( - ty: clang::Type, - location: clang::Cursor, - parent_id: Option, - context: &mut BindgenContext, - ) -> TypeId; - - /// Identical to `from_ty_or_ref`, but use the given `potential_id` as the - /// `ItemId` for the newly parsed item. - fn from_ty_or_ref_with_id( - potential_id: ItemId, - ty: clang::Type, - location: clang::Cursor, - parent_id: Option, - context: &mut BindgenContext, - ) -> TypeId; - - /// Create a named template type. - fn type_param( - with_id: Option, - location: clang::Cursor, - ctx: &mut BindgenContext, - ) -> Option; - - /// Create a builtin type. - fn builtin_type( - kind: TypeKind, - is_const: bool, - context: &mut BindgenContext, - ) -> TypeId; -} From 0a78cde484fd5b6a5bbfd4301b3c4cf043a60a38 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 28 Nov 2022 06:40:20 -0800 Subject: [PATCH 425/942] Fix name collision between C enum and typedef (#2326) Fixes #2008. Example: ```c enum Enum { Variant }; typedef int16_t Enum; ``` This is valid and idiomatic C (though not valid C++). `cbindgen` uses this idiom as the default C translation of Rust enums, the equivalent of what would be `enum Enum : int16_t { Variant };` in C++. `bindgen header.h` before: ```rust pub const Enum_Variant: Enum = 0; pub type Enum = ::std::os::raw::c_uint; pub type Enum = i16; ``` ```console error[E0428]: the name `Enum` is defined multiple times --> generated.rs:3:1 | 2 | pub type Enum = ::std::os::raw::c_uint; | --------------------------------------- previous definition of the type `Enum` here 3 | pub type Enum = i16; | ^^^^^^^^^^^^^^^^^^^^ `Enum` redefined here | = note: `Enum` must be defined only once in the type namespace of this module ``` After: ```rust pub const Enum_Variant: Enum = 0; pub type Enum = i16; ``` --- .../tests/expectations/tests/enum-typedef.rs | 11 +++ bindgen-tests/tests/headers/enum-typedef.h | 18 ++++ bindgen/codegen/mod.rs | 15 ++-- bindgen/ir/context.rs | 82 +++++++++++++++++++ bindgen/ir/ty.rs | 5 ++ 5 files changed, 126 insertions(+), 5 deletions(-) create mode 100644 bindgen-tests/tests/expectations/tests/enum-typedef.rs create mode 100644 bindgen-tests/tests/headers/enum-typedef.h diff --git a/bindgen-tests/tests/expectations/tests/enum-typedef.rs b/bindgen-tests/tests/expectations/tests/enum-typedef.rs new file mode 100644 index 0000000000..dc78eb11eb --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/enum-typedef.rs @@ -0,0 +1,11 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +pub const Enum_Variant: Enum = 0; +pub type Enum = i16; +pub type TypedefFirst = i16; +pub const TypedefFirst_Variant2: TypedefFirst = 0; diff --git a/bindgen-tests/tests/headers/enum-typedef.h b/bindgen-tests/tests/headers/enum-typedef.h new file mode 100644 index 0000000000..f345f4de27 --- /dev/null +++ b/bindgen-tests/tests/headers/enum-typedef.h @@ -0,0 +1,18 @@ +typedef short int16_t; + +// `cbindgen` emits this C idiom as the translation of: +// +// #[repr(i16)] +// pub enum Enum { +// Variant, +// } +enum Enum { + Variant, +}; +typedef int16_t Enum; + +// C is also fine with the typedef coming before the enum. +typedef int16_t TypedefFirst; +enum TypedefFirst { + Variant2, +}; diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index b405063737..154d7fd1ab 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -2709,6 +2709,7 @@ impl<'a> EnumBuilder<'a> { mut attrs: Vec, repr: proc_macro2::TokenStream, enum_variation: EnumVariation, + has_typedef: bool, ) -> Self { let ident = Ident::new(name, Span::call_site()); @@ -2741,10 +2742,12 @@ impl<'a> EnumBuilder<'a> { EnumVariation::Consts => { let mut variants = Vec::new(); - variants.push(quote! { - #( #attrs )* - pub type #ident = #repr; - }); + if !has_typedef { + variants.push(quote! { + #( #attrs )* + pub type #ident = #repr; + }); + } EnumBuilder::Consts { variants } } @@ -3157,8 +3160,10 @@ impl CodeGenerator for Enum { } let repr = repr.to_rust_ty_or_opaque(ctx, item); + let has_typedef = ctx.is_enum_typedef_combo(item.id()); - let mut builder = EnumBuilder::new(&name, attrs, repr, variation); + let mut builder = + EnumBuilder::new(&name, attrs, repr, variation, has_typedef); // A map where we keep a value -> variant relation. let mut seen_values = HashMap::<_, Ident>::default(); diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index 3cc30f1c0b..c5df37d7e9 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -398,6 +398,22 @@ pub struct BindgenContext { /// bitfield allocation units computed. Drained in `compute_bitfield_units`. need_bitfield_allocation: Vec, + /// The set of enums that are defined by a pair of `enum` and `typedef`, + /// which is legal in C (but not C++). + /// + /// ```c++ + /// // in either order + /// enum Enum { Variants... }; + /// typedef int16_t Enum; + /// ``` + /// + /// The stored `ItemId` is that of the `TypeKind::Enum`, not of the + /// `TypeKind::Alias`. + /// + /// This is populated when we enter codegen by `compute_enum_typedef_combos` + /// and is always `None` before that and `Some` after. + enum_typedef_combos: Option>, + /// The set of (`ItemId`s of) types that can't derive debug. /// /// This is populated when we enter codegen by `compute_cannot_derive_debug` @@ -565,6 +581,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" codegen_items: None, used_template_parameters: None, need_bitfield_allocation: Default::default(), + enum_typedef_combos: None, cannot_derive_debug: None, cannot_derive_default: None, cannot_derive_copy: None, @@ -1157,6 +1174,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" self.compute_sizedness(); self.compute_has_destructor(); self.find_used_template_parameters(); + self.compute_enum_typedef_combos(); self.compute_cannot_derive_debug(); self.compute_cannot_derive_default(); self.compute_cannot_derive_copy(); @@ -2476,6 +2494,70 @@ If you encounter an error missing from this list, please file an issue or a PR!" self.generated_bindgen_complex.get() } + /// Compute which `enum`s have an associated `typedef` definition. + fn compute_enum_typedef_combos(&mut self) { + let _t = self.timer("compute_enum_typedef_combos"); + assert!(self.enum_typedef_combos.is_none()); + + let mut enum_typedef_combos = HashSet::default(); + for item in &self.items { + if let Some(ItemKind::Module(module)) = + item.as_ref().map(Item::kind) + { + // Find typedefs in this module, and build set of their names. + let mut names_of_typedefs = HashSet::default(); + for child_id in module.children() { + if let Some(ItemKind::Type(ty)) = + self.items[child_id.0].as_ref().map(Item::kind) + { + if let (Some(name), TypeKind::Alias(type_id)) = + (ty.name(), ty.kind()) + { + // We disregard aliases that refer to the enum + // itself, such as in `typedef enum { ... } Enum;`. + if type_id + .into_resolver() + .through_type_refs() + .through_type_aliases() + .resolve(self) + .expect_type() + .is_int() + { + names_of_typedefs.insert(name); + } + } + } + } + + // Find enums in this module, and record the id of each one that + // has a typedef. + for child_id in module.children() { + if let Some(ItemKind::Type(ty)) = + self.items[child_id.0].as_ref().map(Item::kind) + { + if let (Some(name), true) = (ty.name(), ty.is_enum()) { + if names_of_typedefs.contains(name) { + enum_typedef_combos.insert(*child_id); + } + } + } + } + } + } + + self.enum_typedef_combos = Some(enum_typedef_combos); + } + + /// Look up whether `id` refers to an `enum` whose underlying type is + /// defined by a `typedef`. + pub fn is_enum_typedef_combo(&self, id: ItemId) -> bool { + assert!( + self.in_codegen_phase(), + "We only compute enum_typedef_combos when we enter codegen", + ); + self.enum_typedef_combos.as_ref().unwrap().contains(&id) + } + /// Compute whether we can derive debug. fn compute_cannot_derive_debug(&mut self) { let _t = self.timer("compute_cannot_derive_debug"); diff --git a/bindgen/ir/ty.rs b/bindgen/ir/ty.rs index ed3331adb2..fef340dee9 100644 --- a/bindgen/ir/ty.rs +++ b/bindgen/ir/ty.rs @@ -95,6 +95,11 @@ impl Type { matches!(self.kind, TypeKind::BlockPointer(..)) } + /// Is this an integer type, including `bool` or `char`? + pub fn is_int(&self) -> bool { + matches!(self.kind, TypeKind::Int(_)) + } + /// Is this a compound type? pub fn is_comp(&self) -> bool { matches!(self.kind, TypeKind::Comp(..)) From 690feb398bb5d56eeb928124291663c71f8af054 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Mon, 28 Nov 2022 09:49:51 -0500 Subject: [PATCH 426/942] Update CHANGELOG.md (#2365) --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cac405a60..c7519b620e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -154,6 +154,8 @@ ## Added ## Changed + * Fixed name collisions when having a C `enum` and a `typedef` with the same + name. ## Removed From 199dfcc8e598ba834f7a7210a6ce004e99499d4f Mon Sep 17 00:00:00 2001 From: Justin W Smith <103147162+justsmth@users.noreply.github.com> Date: Mon, 28 Nov 2022 13:16:10 -0500 Subject: [PATCH 427/942] Extend `generated_name_override` callback to variables (#2351) * This change updates `ParseCallbacks::generated_name_override` to accept a second parameter indicating the kind of item the name applies to (currently, either `Function` or `Var`). * A `CallbackItemKind` enum was added to serve as the type for this second parameter. * Tests have been updated to verify that the names of both function and variable can be updated by this callback. --- .../tests/issue-1375-prefixed-functions.rs | 8 ++++++ .../headers/issue-1375-prefixed-functions.h | 4 +++ bindgen-tests/tests/parse_callbacks/mod.rs | 28 +++++++++++-------- bindgen/callbacks.rs | 24 ++++++++++++++-- bindgen/ir/function.rs | 11 +++++--- bindgen/ir/var.rs | 17 +++++++++-- 6 files changed, 72 insertions(+), 20 deletions(-) diff --git a/bindgen-tests/tests/expectations/tests/issue-1375-prefixed-functions.rs b/bindgen-tests/tests/expectations/tests/issue-1375-prefixed-functions.rs index 835b75790d..edcca46d8a 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1375-prefixed-functions.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1375-prefixed-functions.rs @@ -5,6 +5,14 @@ non_upper_case_globals )] +extern "C" { + #[link_name = "\u{1}my_custom_prefix_var_const_name"] + pub static var_const_name: ::std::os::raw::c_int; +} +extern "C" { + #[link_name = "\u{1}my_custom_prefix_var_mut_name"] + pub static mut var_mut_name: ::std::os::raw::c_int; +} extern "C" { #[link_name = "\u{1}my_custom_prefix_function_name"] pub fn function_name(x: ::std::os::raw::c_int); diff --git a/bindgen-tests/tests/headers/issue-1375-prefixed-functions.h b/bindgen-tests/tests/headers/issue-1375-prefixed-functions.h index 4264e52d65..cc37c8ad80 100644 --- a/bindgen-tests/tests/headers/issue-1375-prefixed-functions.h +++ b/bindgen-tests/tests/headers/issue-1375-prefixed-functions.h @@ -1,4 +1,8 @@ // bindgen-parse-callbacks: remove-function-prefix-my_custom_prefix_ +extern const int my_custom_prefix_var_const_name; + +extern int my_custom_prefix_var_mut_name; + void my_custom_prefix_function_name(const int x); diff --git a/bindgen-tests/tests/parse_callbacks/mod.rs b/bindgen-tests/tests/parse_callbacks/mod.rs index 6ade71c27c..00967fe8d7 100644 --- a/bindgen-tests/tests/parse_callbacks/mod.rs +++ b/bindgen-tests/tests/parse_callbacks/mod.rs @@ -1,22 +1,29 @@ use bindgen::callbacks::*; #[derive(Debug)] -pub struct RemoveFunctionPrefixParseCallback { - pub remove_function_prefix: Option, +pub struct RemovePrefixParseCallback { + pub remove_prefix: Option, } -impl RemoveFunctionPrefixParseCallback { +impl RemovePrefixParseCallback { pub fn new(prefix: &str) -> Self { - RemoveFunctionPrefixParseCallback { - remove_function_prefix: Some(prefix.to_string()), + RemovePrefixParseCallback { + remove_prefix: Some(prefix.to_string()), } } } -impl ParseCallbacks for RemoveFunctionPrefixParseCallback { - fn generated_name_override(&self, function_name: &str) -> Option { - if let Some(prefix) = &self.remove_function_prefix { - if let Some(name) = function_name.strip_prefix(prefix) { +impl ParseCallbacks for RemovePrefixParseCallback { + fn generated_name_override(&self, item_info: ItemInfo) -> Option { + if let Some(prefix) = &self.remove_prefix { + let (expected_prefix, expected_suffix) = match item_info.kind { + ItemKind::Function => ("function_", "_name"), + ItemKind::Var => ("var_", "_name"), + _ => todo!(), + }; + if let Some(name) = item_info.name.strip_prefix(prefix) { + assert!(name.starts_with(expected_prefix)); + assert!(name.ends_with(expected_suffix)); return Some(name.to_string()); } } @@ -67,8 +74,7 @@ pub fn lookup(cb: &str) -> Box { .split("remove-function-prefix-") .last() .to_owned(); - let lnopc = - RemoveFunctionPrefixParseCallback::new(prefix.unwrap()); + let lnopc = RemovePrefixParseCallback::new(prefix.unwrap()); Box::new(lnopc) } else { panic!("Couldn't find name ParseCallbacks: {}", cb) diff --git a/bindgen/callbacks.rs b/bindgen/callbacks.rs index 5e8ac78839..1e48a30259 100644 --- a/bindgen/callbacks.rs +++ b/bindgen/callbacks.rs @@ -30,9 +30,9 @@ pub trait ParseCallbacks: fmt::Debug { MacroParsingBehavior::Default } - /// This function will run for every function. The returned value determines the name visible - /// in the bindings. - fn generated_name_override(&self, _function_name: &str) -> Option { + /// This function will run for every extern variable and function. The returned value determines + /// the name visible in the bindings. + fn generated_name_override(&self, _item_info: ItemInfo) -> Option { None } @@ -122,3 +122,21 @@ pub struct DeriveInfo<'a> { /// The name of the type. pub name: &'a str, } + +/// An struct providing information about the item being passed to `ParseCallbacks::generated_name_override`. +#[non_exhaustive] +pub struct ItemInfo<'a> { + /// The name of the item + pub name: &'a str, + /// The kind of item + pub kind: ItemKind, +} + +/// An enum indicating the kind of item for an ItemInfo. +#[non_exhaustive] +pub enum ItemKind { + /// A Function + Function, + /// A Variable + Var, +} diff --git a/bindgen/ir/function.rs b/bindgen/ir/function.rs index ecb3202ff1..8e83d980bc 100644 --- a/bindgen/ir/function.rs +++ b/bindgen/ir/function.rs @@ -6,6 +6,7 @@ use super::dot::DotAttributes; use super::item::Item; use super::traversal::{EdgeKind, Trace, Tracer}; use super::ty::TypeKind; +use crate::callbacks::{ItemInfo, ItemKind}; use crate::clang::{self, Attribute}; use crate::parse::{ClangSubItemParser, ParseError, ParseResult}; use clang_sys::{self, CXCallingConv}; @@ -712,10 +713,12 @@ impl ClangSubItemParser for Function { // but seems easy enough to handle it here. name.push_str("_destructor"); } - if let Some(nm) = context - .options() - .last_callback(|callbacks| callbacks.generated_name_override(&name)) - { + if let Some(nm) = context.options().last_callback(|callbacks| { + callbacks.generated_name_override(ItemInfo { + name: name.as_str(), + kind: ItemKind::Function, + }) + }) { name = nm; } assert!(!name.is_empty(), "Empty function name."); diff --git a/bindgen/ir/var.rs b/bindgen/ir/var.rs index 610b9dfad6..903e1ff549 100644 --- a/bindgen/ir/var.rs +++ b/bindgen/ir/var.rs @@ -7,7 +7,7 @@ use super::function::cursor_mangling; use super::int::IntKind; use super::item::Item; use super::ty::{FloatKind, TypeKind}; -use crate::callbacks::MacroParsingBehavior; +use crate::callbacks::{ItemInfo, ItemKind, MacroParsingBehavior}; use crate::clang; use crate::clang::ClangToken; use crate::parse::{ClangSubItemParser, ParseError, ParseResult}; @@ -272,7 +272,20 @@ impl ClangSubItemParser for Var { )) } CXCursor_VarDecl => { - let name = cursor.spelling(); + let mut name = cursor.spelling(); + if cursor.linkage() == CXLinkage_External { + if let Some(nm) = ctx.options().last_callback(|callbacks| { + callbacks.generated_name_override(ItemInfo { + name: name.as_str(), + kind: ItemKind::Var, + }) + }) { + name = nm; + } + } + // No more changes to name + let name = name; + if name.is_empty() { warn!("Empty constant name?"); return Err(ParseError::Continue); From a9d41985313f2f4e35a15fe1a94724fb373d051c Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Mon, 28 Nov 2022 14:01:25 -0500 Subject: [PATCH 428/942] Document callback changes and avoid static lifetime (#2366) --- CHANGELOG.md | 2 ++ bindgen/callbacks.rs | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c7519b620e..ff6d35ff69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -156,6 +156,8 @@ ## Changed * Fixed name collisions when having a C `enum` and a `typedef` with the same name. + * The `ParseCallbacks::generated_name_override` now receives `ItemInfo<'_>` as + argument instead of a `&str`. ## Removed diff --git a/bindgen/callbacks.rs b/bindgen/callbacks.rs index 1e48a30259..cba406cbd1 100644 --- a/bindgen/callbacks.rs +++ b/bindgen/callbacks.rs @@ -32,7 +32,10 @@ pub trait ParseCallbacks: fmt::Debug { /// This function will run for every extern variable and function. The returned value determines /// the name visible in the bindings. - fn generated_name_override(&self, _item_info: ItemInfo) -> Option { + fn generated_name_override( + &self, + _item_info: ItemInfo<'_>, + ) -> Option { None } From aa9849ba06cb99a5b0917a2e7b33406fe6f76d0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 30 Nov 2022 13:13:51 +0100 Subject: [PATCH 429/942] codegen: Do generate field offset checks for classes with multiple bases. The bug only affects virtual inheritance, so instead disable layout tests in the test that we know is broken. Not generating layout tests is wrong anyways, because the offset would be wrong. --- .../tests/inherit_multiple_interfaces.rs | 130 ++++++++++++++++++ .../expectations/tests/virtual_inheritance.rs | 76 ---------- .../headers/inherit_multiple_interfaces.hpp | 15 ++ .../tests/headers/virtual_inheritance.hpp | 3 +- bindgen/codegen/mod.rs | 11 +- 5 files changed, 148 insertions(+), 87 deletions(-) create mode 100644 bindgen-tests/tests/expectations/tests/inherit_multiple_interfaces.rs create mode 100644 bindgen-tests/tests/headers/inherit_multiple_interfaces.hpp diff --git a/bindgen-tests/tests/expectations/tests/inherit_multiple_interfaces.rs b/bindgen-tests/tests/expectations/tests/inherit_multiple_interfaces.rs new file mode 100644 index 0000000000..46aa15db77 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/inherit_multiple_interfaces.rs @@ -0,0 +1,130 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +pub struct A__bindgen_vtable {} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct A { + pub vtable_: *const A__bindgen_vtable, + pub member: ::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::(), + 16usize, + concat!("Size of: ", stringify!(A)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(A)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, + 8usize, + concat!("Offset of field: ", stringify!(A), "::", stringify!(member)) + ); +} +impl Default for A { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] +pub struct B__bindgen_vtable {} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct B { + pub vtable_: *const B__bindgen_vtable, + pub member2: *mut ::std::os::raw::c_void, +} +#[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::(), + 16usize, + concat!("Size of: ", stringify!(B)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(B)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).member2) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(B), + "::", + stringify!(member2) + ) + ); +} +impl Default for B { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct C { + pub _base: A, + pub _base_1: B, + pub member3: f32, +} +#[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, + concat!("Size of: ", stringify!(C)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(C)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).member3) as usize - ptr as usize }, + 32usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(member3) + ) + ); +} +impl Default for C { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} diff --git a/bindgen-tests/tests/expectations/tests/virtual_inheritance.rs b/bindgen-tests/tests/expectations/tests/virtual_inheritance.rs index 2c15b42878..07b94ec89c 100644 --- a/bindgen-tests/tests/expectations/tests/virtual_inheritance.rs +++ b/bindgen-tests/tests/expectations/tests/virtual_inheritance.rs @@ -10,27 +10,6 @@ pub struct A { pub foo: ::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::(), - 4usize, - concat!("Size of: ", stringify!(A)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(A)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(foo)) - ); -} #[repr(C)] pub struct B__bindgen_vtable(::std::os::raw::c_void); #[repr(C)] @@ -39,27 +18,6 @@ pub struct B { pub vtable_: *const B__bindgen_vtable, pub bar: ::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::(), - 16usize, - concat!("Size of: ", stringify!(B)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(B)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(B), "::", stringify!(bar)) - ); -} impl Default for B { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -77,27 +35,6 @@ pub struct C { pub vtable_: *const C__bindgen_vtable, pub baz: ::std::os::raw::c_int, } -#[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::(), - 16usize, - concat!("Size of: ", stringify!(C)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(C)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(baz)) - ); -} impl Default for C { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -114,19 +51,6 @@ pub struct D { pub _base_1: B, pub bazz: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_D() { - assert_eq!( - ::std::mem::size_of::(), - 40usize, - concat!("Size of: ", stringify!(D)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(D)) - ); -} impl Default for D { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/headers/inherit_multiple_interfaces.hpp b/bindgen-tests/tests/headers/inherit_multiple_interfaces.hpp new file mode 100644 index 0000000000..725992c7cd --- /dev/null +++ b/bindgen-tests/tests/headers/inherit_multiple_interfaces.hpp @@ -0,0 +1,15 @@ +class A { + virtual void Foo(); + + int member; +}; + +class B { + virtual void Bar(); + + void* member2; +}; + +class C : public A, public B { + float member3; +}; diff --git a/bindgen-tests/tests/headers/virtual_inheritance.hpp b/bindgen-tests/tests/headers/virtual_inheritance.hpp index 5198c51e27..b35378d881 100644 --- a/bindgen-tests/tests/headers/virtual_inheritance.hpp +++ b/bindgen-tests/tests/headers/virtual_inheritance.hpp @@ -1,4 +1,5 @@ - +// bindgen-flags: --no-layout-tests +// FIXME: Enable layout tests when #465 is fixed. class A { int foo; }; diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 154d7fd1ab..c297aaab33 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -2193,16 +2193,7 @@ impl CodeGenerator for CompInfo { }) }; - // FIXME when [issue #465](https://github.com/rust-lang/rust-bindgen/issues/465) ready - let too_many_base_vtables = self - .base_members() - .iter() - .filter(|base| base.ty.has_vtable(ctx)) - .count() > - 1; - - let should_skip_field_offset_checks = - is_opaque || too_many_base_vtables; + let should_skip_field_offset_checks = is_opaque; let check_field_offset = if should_skip_field_offset_checks { From 8582fb383dd00cc948eccd3c173ed46cdf61499e Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Wed, 7 Dec 2022 06:27:01 -0500 Subject: [PATCH 430/942] Bump `clang-sys` version (#2368) * Bump `clang-sys` version * add libtinfo5 package to fix CI --- .github/workflows/bindgen.yml | 6 +++++- CHANGELOG.md | 1 + Cargo.lock | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index bc8477d503..85f5d437a4 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -166,7 +166,11 @@ jobs: toolchain: stable target: ${{matrix.target.rust}} override: true - + - name: Install libtinfo + if: matrix.os == 'ubuntu-latest' + run: | + sudo apt-get update + sudo apt-get install libtinfo5 - name: Run all the tests env: GITHUB_ACTIONS_OS: ${{matrix.os}} diff --git a/CHANGELOG.md b/CHANGELOG.md index ff6d35ff69..3b7b53860f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -158,6 +158,7 @@ name. * The `ParseCallbacks::generated_name_override` now receives `ItemInfo<'_>` as argument instead of a `&str`. + * Updated the `clang-sys` crate version to 1.4.0 to support clang 15. ## Removed diff --git a/Cargo.lock b/Cargo.lock index ff13ebcb5e..ec6ba174fd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -131,9 +131,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clang-sys" -version = "1.3.3" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a050e2153c5be08febd6734e29298e844fdb0fa21aeddd63b4eb7baa106c69b" +checksum = "fa2e27ae6ab525c3d369ded447057bca5438d86dc3a68f6faafb8269ba82ebf3" dependencies = [ "glob", "libc", From c17c292c7328c5c91c42a875dd10aeb03c9e4e6f Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Fri, 9 Dec 2022 16:15:59 -0500 Subject: [PATCH 431/942] Fix clippy warnings (#2371) --- bindgen/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 3068d14ec8..6f943e6942 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -1564,7 +1564,7 @@ impl Builder { .collect::>(); match Bindings::generate(options, input_unsaved_files) { - GenerateResult::Ok(bindings) => Ok(bindings), + GenerateResult::Ok(bindings) => Ok(*bindings), GenerateResult::ShouldRestart { header } => self .header(header) .generate_inline_functions(false) @@ -2351,7 +2351,7 @@ fn ensure_libclang_is_loaded() {} #[derive(Debug)] enum GenerateResult { - Ok(Bindings), + Ok(Box), /// Error variant raised when bindgen requires to run again with a newly generated header /// input. #[allow(dead_code)] @@ -2624,11 +2624,11 @@ impl Bindings { let (module, options, warnings) = codegen::codegen(context); - GenerateResult::Ok(Bindings { + GenerateResult::Ok(Box::new(Bindings { options, warnings, module, - }) + })) } /// Write these bindings as source text to a file. From 87b535c3c1089a09632e4d3a1541bd53bb40f55e Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Thu, 15 Dec 2022 16:02:28 -0500 Subject: [PATCH 432/942] Extend documentation about deprecation of wildcard patterns (#2374) --- CHANGELOG.md | 3 ++- bindgen/lib.rs | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b7b53860f..144805d1ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -201,7 +201,8 @@ ## Changed * Regex inputs are sanitized so alternation (`a|b`) is handled correctly but - wildcard patterns (`*`) are now considered invalid. + wildcard patterns (`*`) are now considered invalid. The `.*` pattern can be + used as a replacement. * the `ParseCallbacks`trait does not require to implement `UnwindSafe`. * the `Builder::parse_callbacks` method no longer overwrites previously added callbacks and composes them in a last-to-first manner. diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 6f943e6942..46444a93bb 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -244,6 +244,10 @@ impl Default for CodegenConfig { /// regular expressions as arguments. These regular expressions will be parenthesized and wrapped /// in `^` and `$`. So if `` is passed as argument, the regular expression to be stored will /// be `^()$`. +/// +/// Releases of `bindgen` with a version lesser or equal to `0.62.0` used to accept the wildcard +/// pattern `*` as a valid regular expression. This behavior has been deprecated and the `.*` +/// pattern must be used instead. #[derive(Debug, Default, Clone)] pub struct Builder { options: BindgenOptions, From 3f1b9ae995d344e936a8fe0d40a83f61942a7ba2 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Thu, 15 Dec 2022 16:16:38 -0500 Subject: [PATCH 433/942] Document how to format code (#2375) * Document how to format code * Fix typo * Fix formatting * Ignore code snippet --- book/src/SUMMARY.md | 1 + book/src/code-formatting.md | 69 +++++++++++++++++++++++++++++++++++++ book/src/faq.md | 16 +++++++++ 3 files changed, 86 insertions(+) create mode 100644 book/src/code-formatting.md diff --git a/book/src/SUMMARY.md b/book/src/SUMMARY.md index 551ea0d5f6..dbdf3f700c 100644 --- a/book/src/SUMMARY.md +++ b/book/src/SUMMARY.md @@ -22,6 +22,7 @@ - [Preventing the Derivation of `Default`](./nodefault.md) - [Annotating types with `#[must-use]`](./must-use-types.md) - [Field visibility](./visibility.md) + - [Code formatting](./code-formatting.md) - [Generating Bindings to C++](./cpp.md) - [Generating Bindings to Objective-c](./objc.md) - [Using Unions](./using-unions.md) diff --git a/book/src/code-formatting.md b/book/src/code-formatting.md new file mode 100644 index 0000000000..9039984a16 --- /dev/null +++ b/book/src/code-formatting.md @@ -0,0 +1,69 @@ +# Code Formatting + +`bindgen` uses `rustfmt` to format the emitted bindings. This section describes +how to adjust the `rustfmt` behavior when being used from `bindgen`. + +## Passing a `rustfmt.toml` configuration file + +`rustfmt` should automatically use any `rustfmt.toml` file that is present in +the directory from where `bindgen` will be run. If you want to use a +configuration file that has a different name or that is in a different +directory you can use the `--rustfmt-configuration-file` flag or the +[`Builder::rustfmt_configuration_file`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.rustfmt_configuration_file) +method. + +## Using a nightly release of `rustfmt` + +If the `rustfmt` command does not correspond to a nightly release of `rustfmt` +but you have `rustup` available, you can use `nightly` by following these +steps: + +### When using `bindgen` as a CLI application + +Use `rustup run` to run `bindgen`: + +```bash +$ rustup run nightly bindgen [ARGS] +``` + +### When using `bindgen` as a library + +Take the output of the following command: +```bash +$ rustup which rustfmt --toolchain=nightly +``` +and pass it to +[`Builder::with_rustfmt`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.with_rustfmt): + +```rust,ignore +use bindgen::Builder; +use std::process::Command; + +fn main() { + let output = Command::new("rustup") + .args(["which", "rustfmt", "--toolchain", "nightly"]) + .output() + .expect("Could not spawn `rustup` command"); + + assert!( + output.status.success(), + "Unsuccessful status code when running `rustup`: {:?}", + output + ); + + let rustfmt_path = + String::from_utf8(output.stdout).expect("The `rustfmt` path is not valid `utf-8`"); + + let bindings = Builder::default() + .header("path/to/input.h") + .with_rustfmt(rustfmt_path) + .generate() + .expect("Could not generate bindings"); + + bindings + .write_to_file("path/to/output.rs") + .expect("Could not write bindings"); +} +``` + +These two methods also apply to any other toolchain available in your system. diff --git a/book/src/faq.md b/book/src/faq.md index 767cd6e24c..fcb8255f1f 100644 --- a/book/src/faq.md +++ b/book/src/faq.md @@ -108,3 +108,19 @@ $ bindgen -- --target=armv7a-none-eabi ``` If you are using `bindgen` as a library, you should call `builder.clang_arg("--target=armv7a-none-eabi")` on your `builder`. + +### How can I normalize `#[doc]` attributes? + +`bindgen` emits all the documentation using `#[doc]` attributes by default. If +you want to use the more user-friendly `///` syntax, you have to create a +`rustfmt.toml` file with the following contents: + +```toml +normalize_doc_attributes = true +``` + +Then, you have set up bindgen so it passes this file to `rustfmt`. Given that +the `normalize_doc_attributes` option is +[unstable](https://github.com/rust-lang/rustfmt/issues/3351), you also have to +set up bindgen to use a `nightly` release of `rustfmt`. Please check the [code +formatting](./code-formatting.md) section for further information. From 1abaf7ebbfee423ec524bd6e3b13f626cf32bc69 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Fri, 16 Dec 2022 12:15:04 -0500 Subject: [PATCH 434/942] Run doctoc (#2376) --- book/src/faq.md | 1 + 1 file changed, 1 insertion(+) diff --git a/book/src/faq.md b/book/src/faq.md index fcb8255f1f..f133561d84 100644 --- a/book/src/faq.md +++ b/book/src/faq.md @@ -8,6 +8,7 @@ - [Does `bindgen` support the C++ Standard Template Library (STL)?](#does-bindgen-support-the-c-standard-template-library-stl) - [How to deal with bindgen generated padding fields?](#how-to-deal-with-bindgen-generated-padding-fields) - [How to generate bindings for a custom target?](#how-to-generate-bindings-for-a-custom-target) +- [How can I normalize `#[doc]` attributes?](#how-can-i-normalize-doc-attributes) From 5875949e8e598fa9b0e3a018b3547815e2654fc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Fri, 6 Jan 2023 19:07:28 +0100 Subject: [PATCH 435/942] codegen: Look through typedefs to detect void return type. (#2379) * codegen: Look through typedefs to detect void return type. And reuse a bit more code. Should fix #2377, but needs a test (can't run tests atm). * Add tests * Run rustfmt * Update changelog Co-authored-by: Christian Poveda --- CHANGELOG.md | 3 +- .../tests/dynamic_loading_with_class.rs | 2 +- .../tests/expectations/tests/void_typedef.rs | 18 ++++++ bindgen-tests/tests/headers/void_typedef.h | 9 +++ bindgen/codegen/dyngen.rs | 2 +- bindgen/codegen/mod.rs | 62 ++++++++++++------- 6 files changed, 71 insertions(+), 25 deletions(-) create mode 100644 bindgen-tests/tests/expectations/tests/void_typedef.rs create mode 100644 bindgen-tests/tests/headers/void_typedef.h diff --git a/CHANGELOG.md b/CHANGELOG.md index 144805d1ce..322e65de16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -159,7 +159,8 @@ * The `ParseCallbacks::generated_name_override` now receives `ItemInfo<'_>` as argument instead of a `&str`. * Updated the `clang-sys` crate version to 1.4.0 to support clang 15. - + * The return type is now ommited in signatures of functions returning `void`. + ## Removed ## Fixed diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs index 514cff7317..098ffa24ce 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs @@ -99,7 +99,7 @@ impl TestLib { ) -> ::std::os::raw::c_int { (self.foo.as_ref().expect("Expected function, got error."))(x) } - pub unsafe fn bar(&self) -> () { + pub unsafe fn bar(&self) { (self.bar.as_ref().expect("Expected function, got error."))() } } diff --git a/bindgen-tests/tests/expectations/tests/void_typedef.rs b/bindgen-tests/tests/expectations/tests/void_typedef.rs new file mode 100644 index 0000000000..7e148e7238 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/void_typedef.rs @@ -0,0 +1,18 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +pub type VOID = ::std::os::raw::c_void; +pub type ALSO_VOID = VOID; +extern "C" { + pub fn this_api_returns_nothing(); +} +extern "C" { + pub fn this_api_also_returns_nothing(); +} +extern "C" { + pub fn this_other_api_also_returns_nothing(); +} diff --git a/bindgen-tests/tests/headers/void_typedef.h b/bindgen-tests/tests/headers/void_typedef.h new file mode 100644 index 0000000000..405cbd0c46 --- /dev/null +++ b/bindgen-tests/tests/headers/void_typedef.h @@ -0,0 +1,9 @@ +typedef void VOID; + +typedef VOID ALSO_VOID; + +void this_api_returns_nothing(void); + +VOID this_api_also_returns_nothing(VOID); + +ALSO_VOID this_other_api_also_returns_nothing(ALSO_VOID); diff --git a/bindgen/codegen/dyngen.rs b/bindgen/codegen/dyngen.rs index 5e734ccd15..d8ea81175e 100644 --- a/bindgen/codegen/dyngen.rs +++ b/bindgen/codegen/dyngen.rs @@ -170,7 +170,7 @@ impl DynamicItems { if !is_variadic { self.struct_implementation.push(quote! { #(#attributes)* - pub unsafe fn #ident ( &self, #( #args ),* ) -> #ret_ty { + pub unsafe fn #ident ( &self, #( #args ),* ) #ret_ty { #call_body } }); diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index c297aaab33..041d36691c 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -4135,11 +4135,7 @@ impl CodeGenerator for Function { if is_dynamic_function { let args_identifiers = utils::fnsig_argument_identifiers(ctx, signature); - let return_item = ctx.resolve_item(signature.return_type()); - let ret_ty = match *return_item.kind().expect_type().kind() { - TypeKind::Void => quote! {()}, - _ => return_item.to_rust_ty_or_opaque(ctx, &()), - }; + let ret_ty = utils::fnsig_return_ty(ctx, signature); result.dynamic_items().push( ident, abi, @@ -4811,25 +4807,52 @@ pub mod utils { }) } - pub fn fnsig_return_ty( + fn fnsig_return_ty_internal( ctx: &BindgenContext, sig: &FunctionSig, + include_arrow: bool, ) -> proc_macro2::TokenStream { if sig.is_divergent() { - return quote! { -> ! }; + return if include_arrow { + quote! { -> ! } + } else { + quote! { ! } + }; } - let return_item = ctx.resolve_item(sig.return_type()); - if let TypeKind::Void = *return_item.kind().expect_type().kind() { - quote! {} + let canonical_type_kind = sig + .return_type() + .into_resolver() + .through_type_refs() + .through_type_aliases() + .resolve(ctx) + .kind() + .expect_type() + .kind(); + + if let TypeKind::Void = canonical_type_kind { + return if include_arrow { + quote! {} + } else { + quote! { () } + }; + } + + let ret_ty = sig.return_type().to_rust_ty_or_opaque(ctx, &()); + if include_arrow { + quote! { -> #ret_ty } } else { - let ret_ty = return_item.to_rust_ty_or_opaque(ctx, &()); - quote! { - -> #ret_ty - } + ret_ty } } + pub fn fnsig_return_ty( + ctx: &BindgenContext, + sig: &FunctionSig, + ) -> proc_macro2::TokenStream { + fnsig_return_ty_internal(ctx, sig, /* include_arrow = */ true) + } + pub fn fnsig_arguments( ctx: &BindgenContext, sig: &FunctionSig, @@ -4942,14 +4965,9 @@ pub mod utils { arg_item.to_rust_ty_or_opaque(ctx, &()) }); - let return_item = ctx.resolve_item(sig.return_type()); - let ret_ty = - if let TypeKind::Void = *return_item.kind().expect_type().kind() { - quote! { () } - } else { - return_item.to_rust_ty_or_opaque(ctx, &()) - }; - + let ret_ty = fnsig_return_ty_internal( + ctx, sig, /* include_arrow = */ false, + ); quote! { *const ::block::Block<(#(#args,)*), #ret_ty> } From 8ebeef4502e8661ea43dcc614d3a82b23c9dbaf5 Mon Sep 17 00:00:00 2001 From: Amanjeev Sethi Date: Sat, 7 Jan 2023 13:41:15 -0500 Subject: [PATCH 436/942] fix: test runner for fuzzy tests and update documentation Signed-off-by: Amanjeev Sethi --- CONTRIBUTING.md | 32 ++++++++++++++++---------------- bindgen-tests/tests/test-one.sh | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e3e51d8fd1..ea0fcd9725 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -86,10 +86,10 @@ $ cargo build --features testing_only_docs ### Overview -Input C/C++ test headers reside in the `tests/headers` directory. Expected -output Rust bindings live in `tests/expectations/tests`. For example, -`tests/headers/my_header.h`'s expected generated Rust bindings would be -`tests/expectations/tests/my_header.rs`. +Input C/C++ test headers reside in the `bindgen-tests/tests/headers` directory. Expected +output Rust bindings live in `bindgen-tests/tests/expectations/tests`. For example, +`bindgen-tests/tests/headers/my_header.h`'s expected generated Rust bindings would be +`bindgen-tests/tests/expectations/tests/my_header.rs`. There are also some integration tests in the `./bindgen-integration` crate, which uses `bindgen` to generate bindings to some C++ code, and then uses the bindings, asserting that @@ -109,8 +109,8 @@ These steps must be performed manually when needed. ### Testing Bindings Generation -To regenerate bindings from the corpus of test headers in `tests/headers` and -compare them against the expected bindings in `tests/expectations/tests`, run: +To regenerate bindings from the corpus of test headers in `bindgen-tests/tests/headers` and +compare them against the expected bindings in `bindgen-tests/tests/expectations/tests`, run: ``` $ cargo test @@ -139,14 +139,14 @@ those. ### Testing Generated Bindings If your local changes are introducing expected modifications in the -`tests/expectations/tests/*` bindings files, then you should test that the +`bindgen-tests/tests/expectations/tests/*` bindings files, then you should test that the generated bindings files still compile, and that their struct layout tests still pass. Also, run the integration tests (see below). You can do this with these commands: ``` -$ cd tests/expectations +$ cd bindgen-tests/tests/expectations $ cargo test ``` @@ -157,12 +157,12 @@ is a dependency for running `test-one.sh`. Sometimes its useful to work with one test header from start (generating bindings for it) to finish (compiling the bindings and running their layout -tests). This can be done with the `tests/test-one.sh` script. It supports fuzzy +tests). This can be done with the `bindgen-tests/tests/test-one.sh` script. It supports fuzzy searching for test headers. For example, to test `tests/headers/what_is_going_on.hpp`, execute this command: ``` -$ ./tests/test-one.sh going +$ ./bindgen-tests/tests/test-one.sh going ``` Note that `test-one.sh` does not recompile `bindgen`, so if you change the code, @@ -170,9 +170,9 @@ you'll need to rebuild it before running the script again. ### Authoring New Tests -To add a new test header to the suite, simply put it in the `tests/headers` +To add a new test header to the suite, simply put it in the `bindgen-tests/tests/headers` directory. Next, run `bindgen` to generate the initial expected output Rust -bindings. Put those in `tests/expectations/tests`. +bindings. Put those in `bindgen-tests/tests/expectations/tests`. If your new test requires certain flags to be passed to `bindgen`, you can specify them at the top of the test header, with a comment like this: @@ -186,7 +186,7 @@ specify them at the top of the test header, with a comment like this: Then verify the new Rust bindings compile and pass their layout tests: ``` -$ cd tests/expectations +$ cd bindgen-tests/tests/expectations $ cargo test new_test_header ``` @@ -195,11 +195,11 @@ $ cargo test new_test_header If a test generates different bindings across different `libclang` versions (for example, because we take advantage of better/newer APIs when possible), then you can add multiple test expectations, one for each supported `libclang` -version. Instead of having a single `tests/expectations/tests/my_test.rs` file, +version. Instead of having a single `bindgen-tests/tests/expectations/tests/my_test.rs` file, add each of: -* `tests/expectations/tests/libclang-9/my_test.rs` -* `tests/expectations/tests/libclang-5/my_test.rs` +* `bindgen-tests/tests/expectations/tests/libclang-9/my_test.rs` +* `bindgen-tests/tests/expectations/tests/libclang-5/my_test.rs` If you need to update the test expectations for a test file that generates different bindings for different `libclang` versions, you *don't* need to have diff --git a/bindgen-tests/tests/test-one.sh b/bindgen-tests/tests/test-one.sh index 91da55b1a5..163d23a200 100755 --- a/bindgen-tests/tests/test-one.sh +++ b/bindgen-tests/tests/test-one.sh @@ -48,7 +48,7 @@ FLAGS="${FLAGS/\/\/ bindgen\-flags:/}" FLAGS="--rustfmt-bindings --with-derive-default --raw-line '' --raw-line '#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]' --raw-line '' $FLAGS" -eval ./target/debug/bindgen \ +eval ../target/debug/bindgen \ "\"$TEST\"" \ --emit-ir \ --emit-ir-graphviz ir.dot \ From e6dd2c636302401a54f72ec1f3c74323bb7e49ab Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Tue, 10 Jan 2023 17:00:27 -0500 Subject: [PATCH 437/942] Document semantic difference between constructors and wrappers (#2385) --- book/src/cpp.md | 78 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/book/src/cpp.md b/book/src/cpp.md index 6928584627..f5091b355e 100644 --- a/book/src/cpp.md +++ b/book/src/cpp.md @@ -79,3 +79,81 @@ cannot translate into Rust: large structs in C that would not fit into a register. This also applies to types with any base classes in the MSVC ABI (see [x64 calling convention](https://learn.microsoft.com/en-us/cpp/build/x64-calling-convention?view=msvc-170#return-values)). Because bindgen does not know about these rules generated interfaces using such types are currently invalid. + +## Constructor semantics + +`bindgen` will generate a wrapper for any class constructor declared in the +input headers. For example, this headers file + +```c++ +class MyClass { + public: + MyClass(); + void method(); +}; +``` + +Will produce the following code: +```rust,ignore +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct MyClass { + pub _address: u8, +} +extern "C" { + #[link_name = "\u{1}_ZN7MyClass6methodEv"] + pub fn MyClass_method(this: *mut MyClass); +} +extern "C" { + #[link_name = "\u{1}_ZN7MyClassC1Ev"] + pub fn MyClass_MyClass(this: *mut MyClass); +} +impl MyClass { + #[inline] + pub unsafe fn method(&mut self) { + MyClass_method(self) + } + #[inline] + pub unsafe fn new() -> Self { + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + MyClass_MyClass(__bindgen_tmp.as_mut_ptr()); + __bindgen_tmp.assume_init() + } +} +``` +This `MyClass::new` Rust method can be used as a substitute for the `MyClass` +C++ constructor. However, the address of the value from inside the method will +be different than from the outside. This is because the `__bindgen_tmp` value +is moved when the `MyClass::new` method returns. + +In contrast, the C++ constructor will not move the value, meaning that the +address of the value will be the same inside and outside the constructor. +If the original C++ relies on this semantic difference somehow, you should use the +`MyClass_MyClass` binding directly instead of the `MyClass::new` method. + +In other words, the Rust equivalent for the following C++ code + +```c++ +MyClass instance = MyClass(); +instance.method(); +``` + +is not this + +```rust,ignore +let instance = MyClass::new(); +instance.method(); +``` + +but this + +```rust,ignore +let instance = std::mem::MaybeUninit::::uninit(); +MyClass_MyClass(instance.as_mut_ptr()); +instance.assume_init_mut().method(); +``` + +You can easily verify this fact if you provide a implementation for `MyClass` +and `method` that prints the the `this` pointer address. However, you can +ignore this fact if you know that the original C++ code does not rely on the +instance address in its internal logic. From ed2d06eae31e94022961ef4ed1d8c784b3bc00d4 Mon Sep 17 00:00:00 2001 From: Andrew Walbran Date: Thu, 12 Jan 2023 20:37:48 +0000 Subject: [PATCH 438/942] Update to clap 4. (#2380) * Update to clap 4. * Bump MSRV to minimum required by clap 4. * Mention clap update in CHANGELOG. --- .github/workflows/bindgen.yml | 4 +- CHANGELOG.md | 3 +- Cargo.lock | 169 +++++++++--- README.md | 2 +- bindgen-cli/Cargo.toml | 4 +- bindgen-cli/options.rs | 486 +++++++++++++++++++--------------- bindgen-tests/Cargo.toml | 2 +- bindgen/Cargo.toml | 2 +- 8 files changed, 421 insertions(+), 251 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 85f5d437a4..9ee3ce642d 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -48,11 +48,11 @@ jobs: profile: minimal # MSRV below is documented in Cargo.toml and README.md, please update those if you # change this. - toolchain: 1.57.0 + toolchain: 1.60.0 override: true - name: Build with msrv - run: rm Cargo.lock && cargo +1.57.0 build --lib + run: rm Cargo.lock && cargo +1.60.0 build --lib quickchecking: runs-on: ubuntu-latest diff --git a/CHANGELOG.md b/CHANGELOG.md index 322e65de16..740a4cb182 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -160,7 +160,8 @@ argument instead of a `&str`. * Updated the `clang-sys` crate version to 1.4.0 to support clang 15. * The return type is now ommited in signatures of functions returning `void`. - + * Updated the `clap` dependency for `bindgen-cli` to 4. + ## Removed ## Fixed diff --git a/Cargo.lock b/Cargo.lock index ec6ba174fd..d6f628b0b3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -35,17 +35,11 @@ version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ - "hermit-abi", + "hermit-abi 0.1.19", "libc", "winapi 0.3.9", ] -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - [[package]] name = "bindgen" version = "0.63.0" @@ -71,7 +65,7 @@ name = "bindgen-cli" version = "0.63.0" dependencies = [ "bindgen", - "clap 3.2.12", + "clap 4.0.32", "env_logger 0.9.0", "log 0.4.14", "shlex", @@ -90,7 +84,7 @@ name = "bindgen-tests" version = "0.1.0" dependencies = [ "bindgen", - "clap 3.2.12", + "clap 4.0.32", "diff", "shlex", "tempfile", @@ -150,31 +144,29 @@ dependencies = [ "atty", "bitflags", "strsim 0.8.0", - "textwrap 0.11.0", + "textwrap", "unicode-width", "vec_map", ] [[package]] name = "clap" -version = "3.2.12" +version = "4.0.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab8b79fe3946ceb4a0b1c080b4018992b8d27e9ff363644c1c9b6387c854614d" +checksum = "a7db700bc935f9e43e88d00b0850dae18a63773cfbec6d8e070fccf7fef89a39" dependencies = [ - "atty", "bitflags", "clap_lex", - "indexmap", + "is-terminal", "strsim 0.10.0", "termcolor", - "textwrap 0.15.0", ] [[package]] name = "clap_lex" -version = "0.2.4" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8" dependencies = [ "os_str_bytes", ] @@ -214,6 +206,27 @@ dependencies = [ "termcolor", ] +[[package]] +name = "errno" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" +dependencies = [ + "errno-dragonfly", + "libc", + "winapi 0.3.9", +] + +[[package]] +name = "errno-dragonfly" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "fuchsia-cprng" version = "0.1.1" @@ -238,16 +251,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" [[package]] -name = "hashbrown" -version = "0.12.2" +name = "hermit-abi" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "607c8a29735385251a339424dd462993c0fed8fa09d378f259377df08c126022" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] [[package]] name = "hermit-abi" -version = "0.1.19" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" dependencies = [ "libc", ] @@ -259,13 +275,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] -name = "indexmap" -version = "1.9.1" +name = "io-lifetimes" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46112a93252b123d31a119a8d1a1ac19deac4fac6e0e8b0df58f0d4e5870e63c" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "is-terminal" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" +checksum = "28dfb6c8100ccc63462345b67d1bbc3679177c75ee4bf59bf29c8b1d110b8189" dependencies = [ - "autocfg", - "hashbrown", + "hermit-abi 0.2.6", + "io-lifetimes", + "rustix", + "windows-sys", ] [[package]] @@ -292,9 +320,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.126" +version = "0.2.139" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" +checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" [[package]] name = "libloading" @@ -316,6 +344,12 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "linux-raw-sys" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" + [[package]] name = "log" version = "0.3.9" @@ -589,6 +623,20 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" +[[package]] +name = "rustix" +version = "0.36.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4feacf7db682c6c329c4ede12649cd36ecab0f3be5b7d74e6a20304725db4549" +dependencies = [ + "bitflags", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys", + "windows-sys", +] + [[package]] name = "shlex" version = "1.0.0" @@ -669,12 +717,6 @@ dependencies = [ "unicode-width", ] -[[package]] -name = "textwrap" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" - [[package]] name = "thread-id" version = "2.0.0" @@ -783,3 +825,60 @@ name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" + +[[package]] +name = "windows_i686_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" + +[[package]] +name = "windows_i686_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" diff --git a/README.md b/README.md index c78f00dd44..67f227c4fa 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ extern "C" { ## MSRV -The minimum supported Rust version is **1.57.0**. +The minimum supported Rust version is **1.60.0**. No MSRV bump policy has been established yet, so MSRV may increase in any release. diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index 99a6c62277..12122eb4df 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -14,7 +14,7 @@ homepage = "https://rust-lang.github.io/rust-bindgen/" version = "0.63.0" edition = "2018" # If you change this, also update README.md and msrv in .github/workflows/bindgen.yml -rust-version = "1.57.0" +rust-version = "1.60.0" [[bin]] path = "main.rs" @@ -23,7 +23,7 @@ name = "bindgen" [dependencies] bindgen = { path = "../bindgen", version = "=0.63.0" } shlex = "1" -clap = "3" +clap = "4" env_logger = { version = "0.9.0", optional = true } log = { version = "0.4", optional = true } diff --git a/bindgen-cli/options.rs b/bindgen-cli/options.rs index f7fccc4ff4..f04d7268dc 100644 --- a/bindgen-cli/options.rs +++ b/bindgen-cli/options.rs @@ -3,7 +3,7 @@ use bindgen::{ MacroTypeVariation, NonCopyUnionStyle, RustTarget, DEFAULT_ANON_FIELDS_PREFIX, RUST_TARGET_STRINGS, }; -use clap::{App, Arg}; +use clap::{builder::PossibleValuesParser, Arg, ArgAction, Command}; use std::fs::File; use std::io::{self, Error, ErrorKind}; use std::path::PathBuf; @@ -22,9 +22,9 @@ where String::from(RustTarget::default()) ); - let matches = App::new("bindgen") + let matches = Command::new("bindgen") .about("Generates Rust bindings from C/C++ headers.") - .setting(clap::AppSettings::NoAutoVersion) + .disable_version_flag(true) .override_usage("bindgen [FLAGS] [OPTIONS]

-- ...") .args(&[ Arg::new("header") @@ -32,22 +32,22 @@ where .required_unless_present("V"), Arg::new("depfile") .long("depfile") - .takes_value(true) + .action(ArgAction::Set) .help("Path to write depfile to"), Arg::new("default-enum-style") .long("default-enum-style") .help("The default style of code used to generate enums.") .value_name("variant") .default_value("consts") - .possible_values([ + .value_parser(PossibleValuesParser::new([ "consts", "moduleconsts", "bitfield", "newtype", "rust", "rust_non_exhaustive", - ]) - .multiple_occurrences(false), + ])) + .action(ArgAction::Set), Arg::new("bitfield-enum") .long("bitfield-enum") .help( @@ -55,25 +55,25 @@ where bitfield flags.", ) .value_name("regex") - .multiple_occurrences(true) + .action(ArgAction::Append) .number_of_values(1), Arg::new("newtype-enum") .long("newtype-enum") .help("Mark any enum whose name matches as a newtype.") .value_name("regex") - .multiple_occurrences(true) + .action(ArgAction::Append) .number_of_values(1), Arg::new("newtype-global-enum") .long("newtype-global-enum") .help("Mark any enum whose name matches as a global newtype.") .value_name("regex") - .multiple_occurrences(true) + .action(ArgAction::Append) .number_of_values(1), Arg::new("rustified-enum") .long("rustified-enum") .help("Mark any enum whose name matches as a Rust enum.") .value_name("regex") - .multiple_occurrences(true) + .action(ArgAction::Append) .number_of_values(1), Arg::new("constified-enum") .long("constified-enum") @@ -82,7 +82,7 @@ where constants.", ) .value_name("regex") - .multiple_occurrences(true) + .action(ArgAction::Append) .number_of_values(1), Arg::new("constified-enum-module") .long("constified-enum-module") @@ -91,26 +91,26 @@ where constants.", ) .value_name("regex") - .multiple_occurrences(true) + .action(ArgAction::Append) .number_of_values(1), Arg::new("default-macro-constant-type") .long("default-macro-constant-type") .help("The default signed/unsigned type for C macro constants.") .value_name("variant") .default_value("unsigned") - .possible_values(["signed", "unsigned"]) - .multiple_occurrences(false), + .value_parser(PossibleValuesParser::new(["signed", "unsigned"])) + .action(ArgAction::Set), Arg::new("default-alias-style") .long("default-alias-style") .help("The default style of code used to generate typedefs.") .value_name("variant") .default_value("type_alias") - .possible_values([ + .value_parser(PossibleValuesParser::new([ "type_alias", "new_type", "new_type_deref", - ]) - .multiple_occurrences(false), + ])) + .action(ArgAction::Set), Arg::new("normal-alias") .long("normal-alias") .help( @@ -118,7 +118,7 @@ where normal type aliasing.", ) .value_name("regex") - .multiple_occurrences(true) + .action(ArgAction::Append) .number_of_values(1), Arg::new("new-type-alias") .long("new-type-alias") @@ -127,7 +127,7 @@ where a new type generated for it.", ) .value_name("regex") - .multiple_occurrences(true) + .action(ArgAction::Append) .number_of_values(1), Arg::new("new-type-alias-deref") .long("new-type-alias-deref") @@ -136,7 +136,7 @@ where a new type with Deref and DerefMut to the inner type.", ) .value_name("regex") - .multiple_occurrences(true) + .action(ArgAction::Append) .number_of_values(1), Arg::new("default-non-copy-union-style") .long("default-non-copy-union-style") @@ -147,11 +147,11 @@ where ) .value_name("style") .default_value("bindgen_wrapper") - .possible_values([ + .value_parser(PossibleValuesParser::new([ "bindgen_wrapper", "manually_drop", - ]) - .multiple_occurrences(false), + ])) + .action(ArgAction::Set), Arg::new("bindgen-wrapper-union") .long("bindgen-wrapper-union") .help( @@ -160,8 +160,7 @@ where fields.", ) .value_name("regex") - .takes_value(true) - .multiple_occurrences(true) + .action(ArgAction::Append) .number_of_values(1), Arg::new("manually-drop-union") .long("manually-drop-union") @@ -171,86 +170,98 @@ where 1.20.0) for fields.", ) .value_name("regex") - .takes_value(true) - .multiple_occurrences(true) + .action(ArgAction::Append) .number_of_values(1), Arg::new("blocklist-type") .long("blocklist-type") .help("Mark as hidden.") .value_name("type") - .multiple_occurrences(true) + .action(ArgAction::Append) .number_of_values(1), Arg::new("blocklist-function") .long("blocklist-function") .help("Mark as hidden.") .value_name("function") - .multiple_occurrences(true) + .action(ArgAction::Append) .number_of_values(1), Arg::new("blocklist-item") .long("blocklist-item") .help("Mark as hidden.") .value_name("item") - .multiple_occurrences(true) + .action(ArgAction::Append) .number_of_values(1), Arg::new("blocklist-file") .long("blocklist-file") .help("Mark all contents of as hidden.") .value_name("path") - .multiple_occurrences(true) + .action(ArgAction::Append) .number_of_values(1), Arg::new("no-layout-tests") .long("no-layout-tests") - .help("Avoid generating layout tests for any type."), + .help("Avoid generating layout tests for any type.") + .action(ArgAction::SetTrue), Arg::new("no-derive-copy") .long("no-derive-copy") - .help("Avoid deriving Copy on any type."), + .help("Avoid deriving Copy on any type.") + .action(ArgAction::SetTrue), Arg::new("no-derive-debug") .long("no-derive-debug") - .help("Avoid deriving Debug on any type."), + .help("Avoid deriving Debug on any type.") + .action(ArgAction::SetTrue), Arg::new("no-derive-default") .long("no-derive-default") .hide(true) - .help("Avoid deriving Default on any type."), + .help("Avoid deriving Default on any type.") + .action(ArgAction::SetTrue), Arg::new("impl-debug").long("impl-debug").help( "Create Debug implementation, if it can not be derived \ automatically.", - ), + ) + .action(ArgAction::SetTrue), Arg::new("impl-partialeq") .long("impl-partialeq") .help( "Create PartialEq implementation, if it can not be derived \ automatically.", - ), + ) + .action(ArgAction::SetTrue), Arg::new("with-derive-default") .long("with-derive-default") - .help("Derive Default on any type."), + .help("Derive Default on any type.") + .action(ArgAction::SetTrue), Arg::new("with-derive-hash") .long("with-derive-hash") - .help("Derive hash on any type."), + .help("Derive hash on any type.") + .action(ArgAction::SetTrue), Arg::new("with-derive-partialeq") .long("with-derive-partialeq") - .help("Derive partialeq on any type."), + .help("Derive partialeq on any type.") + .action(ArgAction::SetTrue), Arg::new("with-derive-partialord") .long("with-derive-partialord") - .help("Derive partialord on any type."), + .help("Derive partialord on any type.") + .action(ArgAction::SetTrue), Arg::new("with-derive-eq") .long("with-derive-eq") .help( "Derive eq on any type. Enable this option also \ enables --with-derive-partialeq", - ), + ) + .action(ArgAction::SetTrue), Arg::new("with-derive-ord") .long("with-derive-ord") .help( "Derive ord on any type. Enable this option also \ enables --with-derive-partialord", - ), + ) + .action(ArgAction::SetTrue), Arg::new("no-doc-comments") .long("no-doc-comments") .help( "Avoid including doc comments in the output, see: \ https://github.com/rust-lang/rust-bindgen/issues/426", - ), + ) + .action(ArgAction::SetTrue), Arg::new("no-recursive-allowlist") .long("no-recursive-allowlist") .help( @@ -258,23 +269,29 @@ where bindgen to emit Rust code that won't compile! See the \ `bindgen::Builder::allowlist_recursively` method's \ documentation for details.", - ), + ) + .action(ArgAction::SetTrue), Arg::new("objc-extern-crate") .long("objc-extern-crate") - .help("Use extern crate instead of use for objc."), + .help("Use extern crate instead of use for objc.") + .action(ArgAction::SetTrue), Arg::new("generate-block") .long("generate-block") - .help("Generate block signatures instead of void pointers."), + .help("Generate block signatures instead of void pointers.") + .action(ArgAction::SetTrue), Arg::new("block-extern-crate") .long("block-extern-crate") - .help("Use extern crate instead of use for block."), + .help("Use extern crate instead of use for block.") + .action(ArgAction::SetTrue), Arg::new("distrust-clang-mangling") .long("distrust-clang-mangling") - .help("Do not trust the libclang-provided mangling"), + .help("Do not trust the libclang-provided mangling") + .action(ArgAction::SetTrue), Arg::new("builtins").long("builtins").help( "Output bindings for builtin definitions, e.g. \ __builtin_va_list.", - ), + ) + .action(ArgAction::SetTrue), Arg::new("ctypes-prefix") .long("ctypes-prefix") .help( @@ -289,51 +306,59 @@ where .default_value(DEFAULT_ANON_FIELDS_PREFIX), Arg::new("time-phases") .long("time-phases") - .help("Time the different bindgen phases and print to stderr"), + .help("Time the different bindgen phases and print to stderr") + .action(ArgAction::SetTrue), // All positional arguments after the end of options marker, `--` - Arg::new("clang-args").last(true).multiple_occurrences(true), + Arg::new("clang-args").last(true).action(ArgAction::Append), Arg::new("emit-clang-ast") .long("emit-clang-ast") - .help("Output the Clang AST for debugging purposes."), + .help("Output the Clang AST for debugging purposes.") + .action(ArgAction::SetTrue), Arg::new("emit-ir") .long("emit-ir") - .help("Output our internal IR for debugging purposes."), + .help("Output our internal IR for debugging purposes.") + .action(ArgAction::SetTrue), Arg::new("emit-ir-graphviz") .long("emit-ir-graphviz") .help("Dump graphviz dot file.") .value_name("path"), Arg::new("enable-cxx-namespaces") .long("enable-cxx-namespaces") - .help("Enable support for C++ namespaces."), + .help("Enable support for C++ namespaces.") + .action(ArgAction::SetTrue), Arg::new("disable-name-namespacing") .long("disable-name-namespacing") .help( "Disable namespacing via mangling, causing bindgen to \ generate names like \"Baz\" instead of \"foo_bar_Baz\" \ for an input name \"foo::bar::Baz\".", - ), + ) + .action(ArgAction::SetTrue), Arg::new("disable-nested-struct-naming") .long("disable-nested-struct-naming") .help( "Disable nested struct naming, causing bindgen to generate \ names like \"bar\" instead of \"foo_bar\" for a nested \ definition \"struct foo { struct bar { } b; };\"." - ), + ) + .action(ArgAction::SetTrue), Arg::new("disable-untagged-union") .long("disable-untagged-union") .help( "Disable support for native Rust unions.", - ), + ) + .action(ArgAction::SetTrue), Arg::new("disable-header-comment") .long("disable-header-comment") .help("Suppress insertion of bindgen's version identifier into generated bindings.") - .multiple_occurrences(true), + .action(ArgAction::SetTrue), Arg::new("ignore-functions") .long("ignore-functions") .help( "Do not generate bindings for functions or methods. This \ is useful when you only care about struct layouts.", - ), + ) + .action(ArgAction::SetTrue), Arg::new("generate") .long("generate") .help( @@ -341,60 +366,68 @@ where Valid values are \"functions\",\"types\", \"vars\", \ \"methods\", \"constructors\" and \"destructors\".", ) - .takes_value(true), + .action(ArgAction::Set), Arg::new("ignore-methods") .long("ignore-methods") - .help("Do not generate bindings for methods."), + .help("Do not generate bindings for methods.") + .action(ArgAction::SetTrue), Arg::new("no-convert-floats") .long("no-convert-floats") - .help("Do not automatically convert floats to f32/f64."), + .help("Do not automatically convert floats to f32/f64.") + .action(ArgAction::SetTrue), Arg::new("no-prepend-enum-name") .long("no-prepend-enum-name") - .help("Do not prepend the enum name to constant or newtype variants."), + .help("Do not prepend the enum name to constant or newtype variants.") + .action(ArgAction::SetTrue), Arg::new("no-include-path-detection") .long("no-include-path-detection") - .help("Do not try to detect default include paths"), + .help("Do not try to detect default include paths") + .action(ArgAction::SetTrue), Arg::new("fit-macro-constant-types") .long("fit-macro-constant-types") - .help("Try to fit macro constants into types smaller than u32/i32"), + .help("Try to fit macro constants into types smaller than u32/i32") + .action(ArgAction::SetTrue), Arg::new("opaque-type") .long("opaque-type") .help("Mark as opaque.") .value_name("type") - .multiple_occurrences(true) + .action(ArgAction::Append) .number_of_values(1), Arg::new("output") .short('o') .long("output") .help("Write Rust bindings to .") - .takes_value(true), + .action(ArgAction::Set), Arg::new("raw-line") .long("raw-line") .help("Add a raw line of Rust code at the beginning of output.") - .multiple_occurrences(true) + .action(ArgAction::Append) .number_of_values(1), Arg::new("module-raw-line") .long("module-raw-line") .help("Add a raw line of Rust code to a given module.") - .multiple_occurrences(true) + .action(ArgAction::Append) .number_of_values(2) .value_names(&["module-name", "raw-line"]), Arg::new("rust-target") .long("rust-target") - .help(rust_target_help.as_ref()) - .takes_value(true), + .help(&rust_target_help) + .action(ArgAction::Set), Arg::new("use-core") .long("use-core") - .help("Use types from Rust core instead of std."), + .help("Use types from Rust core instead of std.") + .action(ArgAction::SetTrue), Arg::new("conservative-inline-namespaces") .long("conservative-inline-namespaces") .help( "Conservatively generate inline namespaces to avoid name \ conflicts.", - ), + ) + .action(ArgAction::SetTrue), Arg::new("use-msvc-mangling") .long("use-msvc-mangling") - .help("MSVC C++ ABI mangling. DEPRECATED: Has no effect."), + .help("MSVC C++ ABI mangling. DEPRECATED: Has no effect.") + .action(ArgAction::SetTrue), Arg::new("allowlist-function") .long("allowlist-function") .help( @@ -403,11 +436,12 @@ where generated.", ) .value_name("regex") - .multiple_occurrences(true) + .action(ArgAction::Append) .number_of_values(1), Arg::new("generate-inline-functions") .long("generate-inline-functions") - .help("Generate inline functions."), + .help("Generate inline functions.") + .action(ArgAction::SetTrue), Arg::new("allowlist-type") .long("allowlist-type") .help( @@ -415,7 +449,7 @@ where not be generated.", ) .value_name("regex") - .multiple_occurrences(true) + .action(ArgAction::Append) .number_of_values(1), Arg::new("allowlist-var") .long("allowlist-var") @@ -425,18 +459,19 @@ where generated.", ) .value_name("regex") - .multiple_occurrences(true) + .action(ArgAction::Append) .number_of_values(1), Arg::new("allowlist-file") .alias("allowlist-file") .long("allowlist-file") .help("Allowlist all contents of .") .value_name("path") - .multiple_occurrences(true) + .action(ArgAction::Append) .number_of_values(1), Arg::new("verbose") .long("verbose") - .help("Print verbose error messages."), + .help("Print verbose error messages.") + .action(ArgAction::SetTrue), Arg::new("dump-preprocessed-input") .long("dump-preprocessed-input") .help( @@ -444,24 +479,29 @@ where Useful when debugging bindgen, using C-Reduce, or when \ filing issues. The resulting file will be named \ something like `__bindgen.i` or `__bindgen.ii`.", - ), + ) + .action(ArgAction::SetTrue), Arg::new("no-record-matches") .long("no-record-matches") .help( "Do not record matching items in the regex sets. \ This disables reporting of unused items.", - ), + ) + .action(ArgAction::SetTrue), Arg::new("size_t-is-usize") .long("size_t-is-usize") .help("Ignored - this is enabled by default.") - .hidden(true), - Arg::with_name("no-size_t-is-usize") + .hide(true) + .action(ArgAction::SetTrue), + Arg::new("no-size_t-is-usize") .long("no-size_t-is-usize") .help("Do not bind size_t as usize (useful on platforms \ - where those types are incompatible)."), + where those types are incompatible).") + .action(ArgAction::SetTrue), Arg::new("no-rustfmt-bindings") .long("no-rustfmt-bindings") - .help("Do not format the generated bindings with rustfmt."), + .help("Do not format the generated bindings with rustfmt.") + .action(ArgAction::SetTrue), Arg::new("rustfmt-bindings") .long("rustfmt-bindings") .help( @@ -477,102 +517,114 @@ where This parameter is incompatible with --no-rustfmt-bindings.", ) .value_name("path") - .multiple_occurrences(false) + .action(ArgAction::Set) .number_of_values(1), Arg::new("no-partialeq") .long("no-partialeq") .help("Avoid deriving PartialEq for types matching .") .value_name("regex") - .multiple_occurrences(true) + .action(ArgAction::Append) .number_of_values(1), Arg::new("no-copy") .long("no-copy") .help("Avoid deriving Copy for types matching .") .value_name("regex") - .multiple_occurrences(true) + .action(ArgAction::Append) .number_of_values(1), Arg::new("no-debug") .long("no-debug") .help("Avoid deriving Debug for types matching .") .value_name("regex") - .multiple_occurrences(true) + .action(ArgAction::Append) .number_of_values(1), Arg::new("no-default") .long("no-default") .help("Avoid deriving/implement Default for types matching .") .value_name("regex") - .multiple_occurrences(true) + .action(ArgAction::Append) .number_of_values(1), Arg::new("no-hash") .long("no-hash") .help("Avoid deriving Hash for types matching .") .value_name("regex") - .multiple_occurrences(true) + .action(ArgAction::Append) .number_of_values(1), Arg::new("must-use-type") .long("must-use-type") .help("Add #[must_use] annotation to types matching .") .value_name("regex") - .multiple_occurrences(true) + .action(ArgAction::Append) .number_of_values(1), Arg::new("enable-function-attribute-detection") .long("enable-function-attribute-detection") .help( "Enables detecting unexposed attributes in functions (slow). Used to generate #[must_use] annotations.", - ), + ) + .action(ArgAction::SetTrue), Arg::new("use-array-pointers-in-arguments") .long("use-array-pointers-in-arguments") - .help("Use `*const [T; size]` instead of `*const T` for C arrays"), + .help("Use `*const [T; size]` instead of `*const T` for C arrays") + .action(ArgAction::SetTrue), Arg::new("wasm-import-module-name") .long("wasm-import-module-name") .value_name("name") .help("The name to be used in a #[link(wasm_import_module = ...)] statement"), Arg::new("dynamic-loading") .long("dynamic-loading") - .takes_value(true) + .action(ArgAction::Set) .help("Use dynamic loading mode with the given library name."), Arg::new("dynamic-link-require-all") .long("dynamic-link-require-all") - .help("Require successful linkage to all functions in the library."), + .help("Require successful linkage to all functions in the library.") + .action(ArgAction::SetTrue), Arg::new("respect-cxx-access-specs") .long("respect-cxx-access-specs") - .help("Makes generated bindings `pub` only for items if the items are publically accessible in C++."), + .help("Makes generated bindings `pub` only for items if the items are publically accessible in C++.") + .action(ArgAction::SetTrue), Arg::new("translate-enum-integer-types") .long("translate-enum-integer-types") - .help("Always translate enum integer types to native Rust integer types."), + .help("Always translate enum integer types to native Rust integer types.") + .action(ArgAction::SetTrue), Arg::new("c-naming") .long("c-naming") - .help("Generate types with C style naming."), + .help("Generate types with C style naming.") + .action(ArgAction::SetTrue), Arg::new("explicit-padding") .long("explicit-padding") - .help("Always output explicit padding fields."), + .help("Always output explicit padding fields.") + .action(ArgAction::SetTrue), Arg::new("vtable-generation") .long("vtable-generation") - .help("Enables generation of vtable functions."), + .help("Enables generation of vtable functions.") + .action(ArgAction::SetTrue), Arg::new("sort-semantically") .long("sort-semantically") - .help("Enables sorting of code generation in a predefined manner."), + .help("Enables sorting of code generation in a predefined manner.") + .action(ArgAction::SetTrue), Arg::new("merge-extern-blocks") .long("merge-extern-blocks") - .help("Deduplicates extern blocks."), + .help("Deduplicates extern blocks.") + .action(ArgAction::SetTrue), Arg::new("override-abi") .long("override-abi") .help("Overrides the ABI of functions matching . The value must be of the shape = where can be one of C, stdcall, fastcall, thiscall, aapcs, win64 or C-unwind.") .value_name("override") - .multiple_occurrences(true) + .action(ArgAction::Append) .number_of_values(1), Arg::new("wrap-unsafe-ops") .long("wrap-unsafe-ops") - .help("Wrap unsafe operations in unsafe blocks."), + .help("Wrap unsafe operations in unsafe blocks.") + .action(ArgAction::SetTrue), Arg::new("V") .long("version") - .help("Prints the version, and exits"), + .help("Prints the version, and exits") + .action(ArgAction::SetTrue), ]) // .args() .get_matches_from(args); - let verbose = matches.is_present("verbose"); - if matches.is_present("V") { + let verbose = matches.get_flag("verbose"); + if matches.get_flag("V") { println!( "bindgen {}", option_env!("CARGO_PKG_VERSION").unwrap_or("unknown") @@ -585,215 +637,229 @@ where let mut builder = builder(); - if let Some(header) = matches.value_of("header") { + if let Some(header) = matches.get_one::("header") { builder = builder.header(header); } else { return Err(Error::new(ErrorKind::Other, "Header not found")); } - if let Some(rust_target) = matches.value_of("rust-target") { + if let Some(rust_target) = matches.get_one::("rust-target") { builder = builder.rust_target(RustTarget::from_str(rust_target)?); } - if let Some(variant) = matches.value_of("default-enum-style") { + if let Some(variant) = matches.get_one::("default-enum-style") { builder = builder.default_enum_style(EnumVariation::from_str(variant)?) } - if let Some(bitfields) = matches.values_of("bitfield-enum") { + if let Some(bitfields) = matches.get_many::("bitfield-enum") { for regex in bitfields { builder = builder.bitfield_enum(regex); } } - if let Some(newtypes) = matches.values_of("newtype-enum") { + if let Some(newtypes) = matches.get_many::("newtype-enum") { for regex in newtypes { builder = builder.newtype_enum(regex); } } - if let Some(newtypes) = matches.values_of("newtype-global-enum") { + if let Some(newtypes) = matches.get_many::("newtype-global-enum") { for regex in newtypes { builder = builder.newtype_global_enum(regex); } } - if let Some(rustifieds) = matches.values_of("rustified-enum") { + if let Some(rustifieds) = matches.get_many::("rustified-enum") { for regex in rustifieds { builder = builder.rustified_enum(regex); } } - if let Some(const_enums) = matches.values_of("constified-enum") { + if let Some(const_enums) = matches.get_many::("constified-enum") { for regex in const_enums { builder = builder.constified_enum(regex); } } - if let Some(constified_mods) = matches.values_of("constified-enum-module") { + if let Some(constified_mods) = + matches.get_many::("constified-enum-module") + { for regex in constified_mods { builder = builder.constified_enum_module(regex); } } - if let Some(variant) = matches.value_of("default-macro-constant-type") { + if let Some(variant) = + matches.get_one::("default-macro-constant-type") + { builder = builder .default_macro_constant_type(MacroTypeVariation::from_str(variant)?) } - if let Some(variant) = matches.value_of("default-alias-style") { + if let Some(variant) = matches.get_one::("default-alias-style") { builder = builder.default_alias_style(AliasVariation::from_str(variant)?); } - if let Some(type_alias) = matches.values_of("normal-alias") { + if let Some(type_alias) = matches.get_many::("normal-alias") { for regex in type_alias { builder = builder.type_alias(regex); } } - if let Some(new_type) = matches.values_of("new-type-alias") { + if let Some(new_type) = matches.get_many::("new-type-alias") { for regex in new_type { builder = builder.new_type_alias(regex); } } - if let Some(new_type_deref) = matches.values_of("new-type-alias-deref") { + if let Some(new_type_deref) = + matches.get_many::("new-type-alias-deref") + { for regex in new_type_deref { builder = builder.new_type_alias_deref(regex); } } - if let Some(variant) = matches.value_of("default-non-copy-union-style") { + if let Some(variant) = + matches.get_one::("default-non-copy-union-style") + { builder = builder.default_non_copy_union_style( NonCopyUnionStyle::from_str(variant)?, ); } if let Some(bindgen_wrapper_union) = - matches.values_of("bindgen-wrapper-union") + matches.get_many::("bindgen-wrapper-union") { for regex in bindgen_wrapper_union { builder = builder.bindgen_wrapper_union(regex); } } - if let Some(manually_drop_union) = matches.values_of("manually-drop-union") + if let Some(manually_drop_union) = + matches.get_many::("manually-drop-union") { for regex in manually_drop_union { builder = builder.manually_drop_union(regex); } } - if let Some(hidden_types) = matches.values_of("blocklist-type") { + if let Some(hidden_types) = matches.get_many::("blocklist-type") { for ty in hidden_types { builder = builder.blocklist_type(ty); } } - if let Some(hidden_functions) = matches.values_of("blocklist-function") { + if let Some(hidden_functions) = + matches.get_many::("blocklist-function") + { for fun in hidden_functions { builder = builder.blocklist_function(fun); } } - if let Some(hidden_identifiers) = matches.values_of("blocklist-item") { + if let Some(hidden_identifiers) = + matches.get_many::("blocklist-item") + { for id in hidden_identifiers { builder = builder.blocklist_item(id); } } - if let Some(hidden_files) = matches.values_of("blocklist-file") { + if let Some(hidden_files) = matches.get_many::("blocklist-file") { for file in hidden_files { builder = builder.blocklist_file(file); } } - if matches.is_present("builtins") { + if matches.get_flag("builtins") { builder = builder.emit_builtins(); } - if matches.is_present("no-layout-tests") { + if matches.get_flag("no-layout-tests") { builder = builder.layout_tests(false); } - if matches.is_present("no-derive-copy") { + if matches.get_flag("no-derive-copy") { builder = builder.derive_copy(false); } - if matches.is_present("no-derive-debug") { + if matches.get_flag("no-derive-debug") { builder = builder.derive_debug(false); } - if matches.is_present("impl-debug") { + if matches.get_flag("impl-debug") { builder = builder.impl_debug(true); } - if matches.is_present("impl-partialeq") { + if matches.get_flag("impl-partialeq") { builder = builder.impl_partialeq(true); } - if matches.is_present("with-derive-default") { + if matches.get_flag("with-derive-default") { builder = builder.derive_default(true); } - if matches.is_present("with-derive-hash") { + if matches.get_flag("with-derive-hash") { builder = builder.derive_hash(true); } - if matches.is_present("with-derive-partialeq") { + if matches.get_flag("with-derive-partialeq") { builder = builder.derive_partialeq(true); } - if matches.is_present("with-derive-partialord") { + if matches.get_flag("with-derive-partialord") { builder = builder.derive_partialord(true); } - if matches.is_present("with-derive-eq") { + if matches.get_flag("with-derive-eq") { builder = builder.derive_eq(true); } - if matches.is_present("with-derive-ord") { + if matches.get_flag("with-derive-ord") { builder = builder.derive_ord(true); } - if matches.is_present("no-derive-default") { + if matches.get_flag("no-derive-default") { builder = builder.derive_default(false); } - if matches.is_present("no-prepend-enum-name") { + if matches.get_flag("no-prepend-enum-name") { builder = builder.prepend_enum_name(false); } - if matches.is_present("no-include-path-detection") { + if matches.get_flag("no-include-path-detection") { builder = builder.detect_include_paths(false); } - if matches.is_present("fit-macro-constant-types") { + if matches.get_flag("fit-macro-constant-types") { builder = builder.fit_macro_constants(true); } - if matches.is_present("time-phases") { + if matches.get_flag("time-phases") { builder = builder.time_phases(true); } - if matches.is_present("use-array-pointers-in-arguments") { + if matches.get_flag("use-array-pointers-in-arguments") { builder = builder.array_pointers_in_arguments(true); } - if let Some(wasm_import_name) = matches.value_of("wasm-import-module-name") + if let Some(wasm_import_name) = + matches.get_one::("wasm-import-module-name") { builder = builder.wasm_import_module_name(wasm_import_name); } - if let Some(prefix) = matches.value_of("ctypes-prefix") { + if let Some(prefix) = matches.get_one::("ctypes-prefix") { builder = builder.ctypes_prefix(prefix); } - if let Some(prefix) = matches.value_of("anon-fields-prefix") { + if let Some(prefix) = matches.get_one::("anon-fields-prefix") { builder = builder.anon_fields_prefix(prefix); } - if let Some(what_to_generate) = matches.value_of("generate") { + if let Some(what_to_generate) = matches.get_one::("generate") { let mut config = CodegenConfig::empty(); for what in what_to_generate.split(',') { match what { @@ -814,170 +880,172 @@ where builder = builder.with_codegen_config(config); } - if matches.is_present("emit-clang-ast") { + if matches.get_flag("emit-clang-ast") { builder = builder.emit_clang_ast(); } - if matches.is_present("emit-ir") { + if matches.get_flag("emit-ir") { builder = builder.emit_ir(); } - if let Some(path) = matches.value_of("emit-ir-graphviz") { + if let Some(path) = matches.get_one::("emit-ir-graphviz") { builder = builder.emit_ir_graphviz(path); } - if matches.is_present("enable-cxx-namespaces") { + if matches.get_flag("enable-cxx-namespaces") { builder = builder.enable_cxx_namespaces(); } - if matches.is_present("enable-function-attribute-detection") { + if matches.get_flag("enable-function-attribute-detection") { builder = builder.enable_function_attribute_detection(); } - if matches.is_present("disable-name-namespacing") { + if matches.get_flag("disable-name-namespacing") { builder = builder.disable_name_namespacing(); } - if matches.is_present("disable-nested-struct-naming") { + if matches.get_flag("disable-nested-struct-naming") { builder = builder.disable_nested_struct_naming(); } - if matches.is_present("disable-untagged-union") { + if matches.get_flag("disable-untagged-union") { builder = builder.disable_untagged_union(); } - if matches.is_present("disable-header-comment") { + if matches.get_flag("disable-header-comment") { builder = builder.disable_header_comment(); } - if matches.is_present("ignore-functions") { + if matches.get_flag("ignore-functions") { builder = builder.ignore_functions(); } - if matches.is_present("ignore-methods") { + if matches.get_flag("ignore-methods") { builder = builder.ignore_methods(); } - if matches.is_present("no-convert-floats") { + if matches.get_flag("no-convert-floats") { builder = builder.no_convert_floats(); } - if matches.is_present("no-doc-comments") { + if matches.get_flag("no-doc-comments") { builder = builder.generate_comments(false); } - if matches.is_present("no-recursive-allowlist") { + if matches.get_flag("no-recursive-allowlist") { builder = builder.allowlist_recursively(false); } - if matches.is_present("objc-extern-crate") { + if matches.get_flag("objc-extern-crate") { builder = builder.objc_extern_crate(true); } - if matches.is_present("generate-block") { + if matches.get_flag("generate-block") { builder = builder.generate_block(true); } - if matches.is_present("block-extern-crate") { + if matches.get_flag("block-extern-crate") { builder = builder.block_extern_crate(true); } - if let Some(opaque_types) = matches.values_of("opaque-type") { + if let Some(opaque_types) = matches.get_many::("opaque-type") { for ty in opaque_types { builder = builder.opaque_type(ty); } } - if let Some(lines) = matches.values_of("raw-line") { + if let Some(lines) = matches.get_many::("raw-line") { for line in lines { builder = builder.raw_line(line); } } - if let Some(mut values) = matches.values_of("module-raw-line") { + if let Some(mut values) = matches.get_many::("module-raw-line") { while let Some(module) = values.next() { let line = values.next().unwrap(); builder = builder.module_raw_line(module, line); } } - if matches.is_present("use-core") { + if matches.get_flag("use-core") { builder = builder.use_core(); } - if matches.is_present("distrust-clang-mangling") { + if matches.get_flag("distrust-clang-mangling") { builder = builder.trust_clang_mangling(false); } - if matches.is_present("conservative-inline-namespaces") { + if matches.get_flag("conservative-inline-namespaces") { builder = builder.conservative_inline_namespaces(); } - if matches.is_present("generate-inline-functions") { + if matches.get_flag("generate-inline-functions") { builder = builder.generate_inline_functions(true); } - if let Some(allowlist) = matches.values_of("allowlist-function") { + if let Some(allowlist) = matches.get_many::("allowlist-function") { for regex in allowlist { builder = builder.allowlist_function(regex); } } - if let Some(allowlist) = matches.values_of("allowlist-type") { + if let Some(allowlist) = matches.get_many::("allowlist-type") { for regex in allowlist { builder = builder.allowlist_type(regex); } } - if let Some(allowlist) = matches.values_of("allowlist-var") { + if let Some(allowlist) = matches.get_many::("allowlist-var") { for regex in allowlist { builder = builder.allowlist_var(regex); } } - if let Some(hidden_files) = matches.values_of("allowlist-file") { + if let Some(hidden_files) = matches.get_many::("allowlist-file") { for file in hidden_files { builder = builder.allowlist_file(file); } } - if let Some(args) = matches.values_of("clang-args") { + if let Some(args) = matches.get_many::("clang-args") { for arg in args { builder = builder.clang_arg(arg); } } - let output = if let Some(path) = matches.value_of("output") { + let output = if let Some(path) = matches.get_one::("output") { let file = File::create(path)?; - if let Some(depfile) = matches.value_of("depfile") { + if let Some(depfile) = matches.get_one::("depfile") { builder = builder.depfile(path, depfile); } Box::new(io::BufWriter::new(file)) as Box } else { - if let Some(depfile) = matches.value_of("depfile") { + if let Some(depfile) = matches.get_one::("depfile") { builder = builder.depfile("-", depfile); } Box::new(io::BufWriter::new(io::stdout())) as Box }; - if matches.is_present("dump-preprocessed-input") { + if matches.get_flag("dump-preprocessed-input") { builder.dump_preprocessed_input()?; } - if matches.is_present("no-record-matches") { + if matches.get_flag("no-record-matches") { builder = builder.record_matches(false); } - if matches.is_present("no-size_t-is-usize") { + if matches.get_flag("no-size_t-is-usize") { builder = builder.size_t_is_usize(false); } - let no_rustfmt_bindings = matches.is_present("no-rustfmt-bindings"); + let no_rustfmt_bindings = matches.get_flag("no-rustfmt-bindings"); if no_rustfmt_bindings { builder = builder.rustfmt_bindings(false); } - if let Some(path_str) = matches.value_of("rustfmt-configuration-file") { + if let Some(path_str) = + matches.get_one::("rustfmt-configuration-file") + { let path = PathBuf::from(path_str); if no_rustfmt_bindings { @@ -1004,79 +1072,81 @@ where builder = builder.rustfmt_configuration_file(Some(path)); } - if let Some(no_partialeq) = matches.values_of("no-partialeq") { + if let Some(no_partialeq) = matches.get_many::("no-partialeq") { for regex in no_partialeq { builder = builder.no_partialeq(regex); } } - if let Some(no_copy) = matches.values_of("no-copy") { + if let Some(no_copy) = matches.get_many::("no-copy") { for regex in no_copy { builder = builder.no_copy(regex); } } - if let Some(no_debug) = matches.values_of("no-debug") { + if let Some(no_debug) = matches.get_many::("no-debug") { for regex in no_debug { builder = builder.no_debug(regex); } } - if let Some(no_default) = matches.values_of("no-default") { + if let Some(no_default) = matches.get_many::("no-default") { for regex in no_default { builder = builder.no_default(regex); } } - if let Some(no_hash) = matches.values_of("no-hash") { + if let Some(no_hash) = matches.get_many::("no-hash") { for regex in no_hash { builder = builder.no_hash(regex); } } - if let Some(must_use_type) = matches.values_of("must-use-type") { + if let Some(must_use_type) = matches.get_many::("must-use-type") { for regex in must_use_type { builder = builder.must_use_type(regex); } } - if let Some(dynamic_library_name) = matches.value_of("dynamic-loading") { + if let Some(dynamic_library_name) = + matches.get_one::("dynamic-loading") + { builder = builder.dynamic_library_name(dynamic_library_name); } - if matches.is_present("dynamic-link-require-all") { + if matches.get_flag("dynamic-link-require-all") { builder = builder.dynamic_link_require_all(true); } - if matches.is_present("respect-cxx-access-specs") { + if matches.get_flag("respect-cxx-access-specs") { builder = builder.respect_cxx_access_specs(true); } - if matches.is_present("translate-enum-integer-types") { + if matches.get_flag("translate-enum-integer-types") { builder = builder.translate_enum_integer_types(true); } - if matches.is_present("c-naming") { + if matches.get_flag("c-naming") { builder = builder.c_naming(true); } - if matches.is_present("explicit-padding") { + if matches.get_flag("explicit-padding") { builder = builder.explicit_padding(true); } - if matches.is_present("vtable-generation") { + if matches.get_flag("vtable-generation") { builder = builder.vtable_generation(true); } - if matches.is_present("sort-semantically") { + if matches.get_flag("sort-semantically") { builder = builder.sort_semantically(true); } - if matches.is_present("merge-extern-blocks") { + if matches.get_flag("merge-extern-blocks") { builder = builder.merge_extern_blocks(true); } - if let Some(abi_overrides) = matches.values_of("override-abi") { + if let Some(abi_overrides) = matches.get_many::("override-abi") { for abi_override in abi_overrides { let (regex, abi_str) = abi_override .rsplit_once('=') @@ -1088,7 +1158,7 @@ where } } - if matches.is_present("wrap-unsafe-ops") { + if matches.get_flag("wrap-unsafe-ops") { builder = builder.wrap_unsafe_ops(true); } diff --git a/bindgen-tests/Cargo.toml b/bindgen-tests/Cargo.toml index a9b258b98c..774bbf0928 100644 --- a/bindgen-tests/Cargo.toml +++ b/bindgen-tests/Cargo.toml @@ -8,7 +8,7 @@ publish = false bindgen = { path = "../bindgen" } diff = "0.1" shlex = "1" -clap = "3" +clap = "4" tempfile = "3" [features] diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index 652220955b..5a03d2481e 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -18,7 +18,7 @@ version = "0.63.0" edition = "2018" build = "build.rs" # If you change this, also update README.md and msrv in .github/workflows/bindgen.yml -rust-version = "1.57.0" +rust-version = "1.60.0" [lib] name = "bindgen" From 6322b2d9eb3bbc59408606e72dae270511eccec1 Mon Sep 17 00:00:00 2001 From: Amanjeev Sethi Date: Mon, 16 Jan 2023 11:21:36 -0500 Subject: [PATCH 439/942] Add trigger for push to `main` branch for sync'ing with `master` (#2387) * gh action for merging main to master on pr merge * remove pull_request as trigger. only use push, that is after merging the pull_request --- .github/workflows/sync-master-from-main.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .github/workflows/sync-master-from-main.yml diff --git a/.github/workflows/sync-master-from-main.yml b/.github/workflows/sync-master-from-main.yml new file mode 100644 index 0000000000..56142450ca --- /dev/null +++ b/.github/workflows/sync-master-from-main.yml @@ -0,0 +1,21 @@ +name: sync master from main + +on: + push: + branches: + - main + +jobs: + sync-branches: + runs-on: ubuntu-latest + name: Keep master and main in sync until master is done + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Merge master <- main + uses: devmasx/merge-branch@master + with: + type: now + from_branch: main + target_branch: master + github_token: ${{ secrets.GITHUB_TOKEN }} From 758ec87c952bb9e82c2b1a7bd8c63ee20f0b25fb Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Wed, 18 Jan 2023 12:23:13 -0500 Subject: [PATCH 440/942] Remove any references to `master` (#2391) --- .github/workflows/bindgen.yml | 4 ++-- .github/workflows/deploy-book.yml | 2 +- CHANGELOG.md | 2 +- CONTRIBUTING.md | 8 ++++---- appveyor.yml | 2 +- releases/release-announcement-template.md | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 9ee3ce642d..8faa4988ec 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -3,10 +3,10 @@ name: bindgen on: push: branches: - - master + - main pull_request: branches: - - master + - main jobs: rustfmt-clippy: diff --git a/.github/workflows/deploy-book.yml b/.github/workflows/deploy-book.yml index ce7083c8c8..a0d87a2094 100644 --- a/.github/workflows/deploy-book.yml +++ b/.github/workflows/deploy-book.yml @@ -3,7 +3,7 @@ name: Deploy book on: push: branches: - - master + - main jobs: deploy-book: diff --git a/CHANGELOG.md b/CHANGELOG.md index 740a4cb182..bfc611cdc1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1302,7 +1302,7 @@ Released 2017/10/27 have. [#1094][] [faq]: https://rust-lang.github.io/rust-bindgen/faq.html -[fuzzing]: https://github.com/rust-lang/rust-bindgen/blob/master/csmith-fuzzing/README.md +[fuzzing]: https://github.com/rust-lang/rust-bindgen/blob/main/csmith-fuzzing/README.md [#938]: https://github.com/rust-lang/rust-bindgen/issues/938 [#888]: https://github.com/rust-lang/rust-bindgen/issues/888 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ea0fcd9725..af7a62321a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -336,7 +336,7 @@ the `codegen::postprocessing` module by following these steps: Ensure that each commit stands alone, and passes tests. This enables better `git bisect`ing when needed. If your commits do not stand on their own, then rebase -them on top of the latest master and squash them into a single commit. +them on top of the latest main and squash them into a single commit. All pull requests undergo code review before merging. To request review, comment `r? @github_username_of_reviewer`. They we will respond with `r+` to approve the @@ -419,7 +419,7 @@ $ brew install creduce $ # Etc... ``` -Otherwise, follow [these instructions](https://github.com/csmith-project/creduce/blob/master/INSTALL.md) for building and/or installing `creduce`. +Otherwise, follow [these instructions](https://github.com/csmith-project/creduce/blob/main/INSTALL.md) for building and/or installing `creduce`. Running `creduce` requires two things: @@ -548,9 +548,9 @@ $ ./node_modules/doctoc/doctoc.js CHANGELOG.md Bump version numbers as needed. Run tests just to ensure everything is working as expected. -### Merge to `master` +### Merge to `main` -For regular releases, the changes above should end up in `master` before +For regular releases, the changes above should end up in `main` before publishing. For dot-releases of an old version (e.g., cherry-picking an important fix) you can skip this. diff --git a/appveyor.yml b/appveyor.yml index 62efeea2c4..741c59fda4 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -25,7 +25,7 @@ platform: branches: only: - - master + - main install: - if %PLATFORM% == x86 (set RUST_PLATFORM=i686&set MINGW_BITS=32) else (set RUST_PLATFORM=x86_64&set MINGW_BITS=64) diff --git a/releases/release-announcement-template.md b/releases/release-announcement-template.md index 9f4e87cc4b..c33ef85f4c 100644 --- a/releases/release-announcement-template.md +++ b/releases/release-announcement-template.md @@ -41,7 +41,7 @@ Found a bug with `bindgen`? [File an issue here.][file-issue] [crates.io]: https://crates.io/crates/bindgen [guide]: https://rust-lang.github.io/rust-bindgen [docs]: https://docs.rs/bindgen -[contributing]: https://github.com/rust-lang/rust-bindgen/blob/master/CONTRIBUTING.md +[contributing]: https://github.com/rust-lang/rust-bindgen/blob/main/CONTRIBUTING.md [easy]: https://github.com/rust-lang/rust-bindgen/issues?q=is%3Aopen+is%3Aissue+label%3AE-easy [less-easy]: https://github.com/rust-lang/rust-bindgen/issues?q=is%3Aopen+is%3Aissue+label%3AE-less-easy [looking]: https://github.com/rust-lang/rust-bindgen/issues/747 From 190a017a100b00aeebe2c5e5acfd5ee699a655c9 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Wed, 18 Jan 2023 12:38:19 -0500 Subject: [PATCH 441/942] Migrate CLI argument parse to the clap `derive` API (#2390) * Migrate CLI argument parsing to the derive API * Fix docs * Fix tests * Use `override_usage` * Update changelog --- CHANGELOG.md | 2 + Cargo.lock | 51 ++ bindgen-cli/Cargo.toml | 2 +- bindgen-cli/options.rs | 1444 ++++++++++++++++---------------------- bindgen-tests/Cargo.toml | 2 +- 5 files changed, 643 insertions(+), 858 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bfc611cdc1..e70b118764 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -161,6 +161,8 @@ * Updated the `clang-sys` crate version to 1.4.0 to support clang 15. * The return type is now ommited in signatures of functions returning `void`. * Updated the `clap` dependency for `bindgen-cli` to 4. + * Rewrote the `bindgen-cli` argument parser which could introduce unexpected + behavior changes. ## Removed diff --git a/Cargo.lock b/Cargo.lock index d6f628b0b3..b6a3a8d06c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -156,12 +156,27 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7db700bc935f9e43e88d00b0850dae18a63773cfbec6d8e070fccf7fef89a39" dependencies = [ "bitflags", + "clap_derive", "clap_lex", "is-terminal", + "once_cell", "strsim 0.10.0", "termcolor", ] +[[package]] +name = "clap_derive" +version = "4.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0177313f9f02afc995627906bbd8967e2be069f5261954222dac78290c2b9014" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "clap_lex" version = "0.3.0" @@ -250,6 +265,12 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" +[[package]] +name = "heck" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" + [[package]] name = "hermit-abi" version = "0.1.19" @@ -418,6 +439,12 @@ dependencies = [ "malloc_buf", ] +[[package]] +name = "once_cell" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" + [[package]] name = "os_str_bytes" version = "6.2.0" @@ -436,6 +463,30 @@ version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + [[package]] name = "proc-macro2" version = "1.0.43" diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index 12122eb4df..76099eb060 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -23,7 +23,7 @@ name = "bindgen" [dependencies] bindgen = { path = "../bindgen", version = "=0.63.0" } shlex = "1" -clap = "4" +clap = { version = "4", features = ["derive"] } env_logger = { version = "0.9.0", optional = true } log = { version = "0.4", optional = true } diff --git a/bindgen-cli/options.rs b/bindgen-cli/options.rs index f04d7268dc..c536ed6275 100644 --- a/bindgen-cli/options.rs +++ b/bindgen-cli/options.rs @@ -3,11 +3,349 @@ use bindgen::{ MacroTypeVariation, NonCopyUnionStyle, RustTarget, DEFAULT_ANON_FIELDS_PREFIX, RUST_TARGET_STRINGS, }; -use clap::{builder::PossibleValuesParser, Arg, ArgAction, Command}; +use clap::Parser; use std::fs::File; use std::io::{self, Error, ErrorKind}; use std::path::PathBuf; -use std::str::FromStr; + +fn rust_target_help() -> String { + format!( + "Version of the Rust compiler to target. Valid options are: {:?}. Defaults to {:?}.", + RUST_TARGET_STRINGS, + String::from(RustTarget::default()) + ) +} + +fn parse_codegen_config(what_to_generate: &str) -> io::Result { + let mut config = CodegenConfig::empty(); + for what in what_to_generate.split(',') { + match what { + "functions" => config.insert(CodegenConfig::FUNCTIONS), + "types" => config.insert(CodegenConfig::TYPES), + "vars" => config.insert(CodegenConfig::VARS), + "methods" => config.insert(CodegenConfig::METHODS), + "constructors" => config.insert(CodegenConfig::CONSTRUCTORS), + "destructors" => config.insert(CodegenConfig::DESTRUCTORS), + otherwise => { + return Err(Error::new( + ErrorKind::Other, + format!("Unknown generate item: {}", otherwise), + )); + } + } + } + + Ok(config) +} + +#[derive(Parser, Debug)] +#[clap( + about = "Generates Rust bindings from C/C++ headers.", + override_usage = "bindgen [FLAGS] [OPTIONS] [HEADER] -- [CLANG_ARGS]...", + trailing_var_arg = true +)] +struct BindgenCommand { + /// C or C++ header file. + header: Option, + /// Path to write depfile to. + #[arg(long)] + depfile: Option, + /// The default style of code used to generate enums. + #[arg(long, value_name = "VARIANT")] + default_enum_style: Option, + /// Mark any enum whose name matches as a set of bitfield flags. + #[arg(long, value_name = "REGEX")] + bitfield_enum: Vec, + /// Mark any enum whose name matches as a newtype. + #[arg(long, value_name = "REGEX")] + newtype_enum: Vec, + /// Mark any enum whose name matches as a global newtype. + #[arg(long, value_name = "REGEX")] + newtype_global_enum: Vec, + /// Mark any enum whose name matches as a Rust enum. + #[arg(long, value_name = "REGEX")] + rustified_enum: Vec, + /// Mark any enum whose name matches as a series of constants. + #[arg(long, value_name = "REGEX")] + constified_enum: Vec, + /// Mark any enum whose name matches as a module of constants. + #[arg(long, value_name = "REGEX")] + constified_enum_module: Vec, + /// The default signed/unsigned type for C macro constants. + #[arg(long, value_name = "VARIANT")] + default_macro_constant_type: Option, + /// The default style of code used to generate typedefs. + #[arg(long, value_name = "VARIANT")] + default_alias_style: Option, + /// Mark any typedef alias whose name matches to use normal type aliasing. + #[arg(long, value_name = "REGEX")] + normal_alias: Vec, + /// Mark any typedef alias whose name matches to have a new type generated for it. + #[arg(long, value_name = "REGEX")] + new_type_alias: Vec, + /// Mark any typedef alias whose name matches to have a new type with Deref and DerefMut to the inner type. + #[arg(long, value_name = "REGEX")] + new_type_alias_deref: Vec, + /// The default style of code used to generate unions with non-Copy members. Note that ManuallyDrop was first stabilized in Rust 1.20.0. + #[arg(long, value_name = "STYLE")] + default_non_copy_union_style: Option, + /// Mark any union whose name matches and who has a non-Copy member to use a bindgen-generated wrapper for fields. + #[arg(long, value_name = "REGEX")] + bindgen_wrapper_union: Vec, + /// Mark any union whose name matches and who has a non-Copy member to use ManuallyDrop (stabilized in Rust 1.20.0) for fields. + #[arg(long, value_name = "REGEX")] + manually_drop_union: Vec, + /// Mark as hidden. + #[arg(long, value_name = "TYPE")] + blocklist_type: Vec, + /// Mark as hidden. + #[arg(long, value_name = "FUNCTION")] + blocklist_function: Vec, + /// Mark as hidden. + #[arg(long, value_name = "ITEM")] + blocklist_item: Vec, + /// Mark as hidden. + #[arg(long, value_name = "FILE")] + blocklist_file: Vec, + /// Avoid generating layout tests for any type. + #[arg(long)] + no_layout_tests: bool, + /// Avoid deriving Copy on any type. + #[arg(long)] + no_derive_copy: bool, + /// Avoid deriving Debug on any type. + #[arg(long)] + no_derive_debug: bool, + /// Avoid deriving Default on any type. + #[arg(long, hide = true)] + no_derive_default: bool, + /// Create a Debug implementation if it cannot be derived automatically. + #[arg(long)] + impl_debug: bool, + /// Create a PartialEq implementation if it cannot be derived automatically. + #[arg(long)] + impl_partialeq: bool, + /// Derive Default on any type. + #[arg(long)] + with_derive_default: bool, + /// Derive Hash on any type.docstring + #[arg(long)] + with_derive_hash: bool, + /// Derive PartialEq on any type. + #[arg(long)] + with_derive_partialeq: bool, + /// Derive PartialOrd on any type. + #[arg(long)] + with_derive_partialord: bool, + /// Derive Eq on any type. + #[arg(long)] + with_derive_eq: bool, + /// Derive Ord on any type. + #[arg(long)] + with_derive_ord: bool, + /// Avoid including doc comments in the output, see: https://github.com/rust-lang/rust-bindgen/issues/426 + #[arg(long)] + no_doc_comments: bool, + /// Disable allowlisting types recursively. This will cause bindgen to emit Rust code that won't compile! See the `bindgen::Builder::allowlist_recursively` method's documentation for details. + #[arg(long)] + no_recursive_allowlist: bool, + /// Use extern crate instead of use for objc. + #[arg(long)] + objc_extern_crate: bool, + /// Generate block signatures instead of void pointers. + #[arg(long)] + generate_block: bool, + /// Use extern crate instead of use for block. + #[arg(long)] + block_extern_crate: bool, + /// Do not trust the libclang-provided mangling + #[arg(long)] + distrust_clang_mangling: bool, + /// Output bindings for builtin definitions, e.g. __builtin_va_list. + #[arg(long)] + builtins: bool, + /// Use the given prefix before raw types instead of ::std::os::raw. + #[arg(long, value_name = "PREFIX")] + ctypes_prefix: Option, + /// Use the given prefix for anonymous fields. + #[arg(long, default_value = DEFAULT_ANON_FIELDS_PREFIX, value_name = "PREFIX")] + anon_fields_prefix: String, + /// Time the different bindgen phases and print to stderr + #[arg(long)] + time_phases: bool, + /// Output the Clang AST for debugging purposes. + #[arg(long)] + emit_clang_ast: bool, + /// Output our internal IR for debugging purposes. + #[arg(long)] + emit_ir: bool, + /// Dump graphviz dot file. + #[arg(long, value_name = "PATH")] + emit_ir_graphviz: Option, + /// Enable support for C++ namespaces. + #[arg(long)] + enable_cxx_namespaces: bool, + /// Disable namespacing via mangling, causing bindgen to generate names like `Baz` instead of `foo_bar_Baz` for an input name `foo::bar::Baz`. + #[arg(long)] + disable_name_namespacing: bool, + /// Disable nested struct naming, causing bindgen to generate names like `bar` instead of `foo_bar` for a nested definition `struct foo { struct bar { } b; };`. + #[arg(long)] + disable_nested_struct_naming: bool, + /// Disable support for native Rust unions. + #[arg(long)] + disable_untagged_union: bool, + /// Suppress insertion of bindgen's version identifier into generated bindings. + #[arg(long)] + disable_header_comment: bool, + /// Do not generate bindings for functions or methods. This is useful when you only care about struct layouts.docstring + #[arg(long)] + ignore_functions: bool, + /// Generate only given items, split by commas. Valid values are `functions`,`types`, `vars`, `methods`, `constructors` and `destructors`. + #[arg(long, value_parser = parse_codegen_config)] + generate: Option, + /// Do not generate bindings for methods. + #[arg(long)] + ignore_methods: bool, + /// Do not automatically convert floats to f32/f64. + #[arg(long)] + no_convert_floats: bool, + /// Do not prepend the enum name to constant or newtype variants. + #[arg(long)] + no_prepend_enum_name: bool, + /// Do not try to detect default include paths + #[arg(long)] + no_include_path_detection: bool, + /// Try to fit macro constants into types smaller than u32/i32 + #[arg(long)] + fit_macro_constant_types: bool, + /// Mark as opaque. + #[arg(long, value_name = "TYPE")] + opaque_type: Vec, + /// Write Rust bindings to . + #[arg(long, short, value_name = "OUTPUT")] + output: Option, + /// Add a raw line of Rust code at the beginning of output. + #[arg(long)] + raw_line: Vec, + /// Add a raw line of Rust code to a given module. + #[arg(long, number_of_values = 2, value_names = ["MODULE-NAME", "RAW-LINE"])] + module_raw_line: Vec, + #[arg(long, help = rust_target_help())] + rust_target: Option, + /// Use types from Rust core instead of std. + #[arg(long)] + use_core: bool, + /// Conservatively generate inline namespaces to avoid name conflicts. + #[arg(long)] + conservative_inline_namespaces: bool, + /// MSVC C++ ABI mangling. DEPRECATED: Has no effect. + #[arg(long)] + use_msvc_mangling: bool, + /// Allowlist all the free-standing functions matching . Other non-allowlisted functions will not be generated. + #[arg(long, value_name = "REGEX")] + allowlist_function: Vec, + /// Generate inline functions. + #[arg(long)] + generate_inline_functions: bool, + /// Only generate types matching . Other non-allowlisted types will not be generated. + #[arg(long, value_name = "REGEX")] + allowlist_type: Vec, + /// Allowlist all the free-standing variables matching . Other non-allowlisted variables will not be generated. + #[arg(long, value_name = "REGEX")] + allowlist_var: Vec, + /// Allowlist all contents of . + #[arg(long, value_name = "PATH")] + allowlist_file: Vec, + /// Print verbose error messages. + #[arg(long)] + verbose: bool, + /// Preprocess and dump the input header files to disk. Useful when debugging bindgen, using C-Reduce, or when filing issues. The resulting file will be named something like `__bindgen.i` or `__bindgen.ii`. + #[arg(long)] + dump_preprocessed_input: bool, + /// Do not record matching items in the regex sets. This disables reporting of unused items. + #[arg(long)] + no_record_matches: bool, + /// Ignored - this is enabled by default. + #[arg(long = "size_t-is-usize")] + size_t_is_usize: bool, + /// Do not bind size_t as usize (useful on platforms where those types are incompatible). + #[arg(long = "no-size_t-is-usize")] + no_size_t_is_usize: bool, + /// Do not format the generated bindings with rustfmt. + #[arg(long)] + no_rustfmt_bindings: bool, + /// Format the generated bindings with rustfmt. DEPRECATED: --rustfmt-bindings is now enabled by default. Disable with --no-rustfmt-bindings. + #[arg(long)] + rustfmt_bindings: bool, + /// The absolute path to the rustfmt configuration file. The configuration file will be used for formatting the bindings. This parameter is incompatible with --no-rustfmt-bindings. + #[arg(long, value_name = "PATH")] + rustfmt_configuration_file: Option, + /// Avoid deriving PartialEq for types matching . + #[arg(long, value_name = "REGEX")] + no_partialeq: Vec, + /// Avoid deriving Copy for types matching . + #[arg(long, value_name = "REGEX")] + no_copy: Vec, + /// Avoid deriving Debug for types matching . + #[arg(long, value_name = "REGEX")] + no_debug: Vec, + /// Avoid deriving/implementing Default for types matching . + #[arg(long, value_name = "REGEX")] + no_default: Vec, + /// Avoid deriving Hash for types matching . + #[arg(long, value_name = "REGEX")] + no_hash: Vec, + /// Add #[must_use] annotation to types matching . + #[arg(long, value_name = "REGEX")] + must_use_type: Vec, + /// Enables detecting unexposed attributes in functions (slow). Used to generate #[must_use] annotations. + #[arg(long)] + enable_function_attribute_detection: bool, + /// Use `*const [T; size]` instead of `*const T` for C arrays + #[arg(long)] + use_array_pointers_in_arguments: bool, + /// The name to be used in a #[link(wasm_import_module = ...)] statement + #[arg(long, value_name = "NAME")] + wasm_import_module_name: Option, + /// Use dynamic loading mode with the given library name. + #[arg(long, value_name = "NAME")] + dynamic_loading: Option, + /// Require successful linkage to all functions in the library. + #[arg(long)] + dynamic_link_require_all: bool, + /// Makes generated bindings `pub` only for items if the items are publically accessible in C++. + #[arg(long)] + respect_cxx_access_specs: bool, + /// Always translate enum integer types to native Rust integer types. + #[arg(long)] + translate_enum_integer_types: bool, + /// Generate types with C style naming. + #[arg(long)] + c_naming: bool, + /// Always output explicit padding fields. + #[arg(long)] + explicit_padding: bool, + /// Enables generation of vtable functions. + #[arg(long)] + vtable_generation: bool, + /// Enables sorting of code generation in a predefined manner. + #[arg(long)] + sort_semantically: bool, + /// Deduplicates extern blocks. + #[arg(long)] + merge_extern_blocks: bool, + /// Overrides the ABI of functions matching . The value must be of the shape = where can be one of C, stdcall, fastcall, thiscall, aapcs, win64 or C-unwind. + #[arg(long, value_name = "OVERRIDE")] + override_abi: Vec, + /// Wrap unsafe operations in unsafe blocks. + #[arg(long)] + wrap_unsafe_ops: bool, + /// Prints the version, and exits + #[arg(short = 'V', long)] + version: bool, + /// Arguments to be passed straight through to clang. + clang_args: Vec, +} /// Construct a new [`Builder`](./struct.Builder.html) from command line flags. pub fn builder_from_flags( @@ -16,615 +354,113 @@ pub fn builder_from_flags( where I: Iterator, { - let rust_target_help = format!( - "Version of the Rust compiler to target. Valid options are: {:?}. Defaults to {:?}.", - RUST_TARGET_STRINGS, - String::from(RustTarget::default()) - ); - - let matches = Command::new("bindgen") - .about("Generates Rust bindings from C/C++ headers.") - .disable_version_flag(true) - .override_usage("bindgen [FLAGS] [OPTIONS]
-- ...") - .args(&[ - Arg::new("header") - .help("C or C++ header file") - .required_unless_present("V"), - Arg::new("depfile") - .long("depfile") - .action(ArgAction::Set) - .help("Path to write depfile to"), - Arg::new("default-enum-style") - .long("default-enum-style") - .help("The default style of code used to generate enums.") - .value_name("variant") - .default_value("consts") - .value_parser(PossibleValuesParser::new([ - "consts", - "moduleconsts", - "bitfield", - "newtype", - "rust", - "rust_non_exhaustive", - ])) - .action(ArgAction::Set), - Arg::new("bitfield-enum") - .long("bitfield-enum") - .help( - "Mark any enum whose name matches as a set of \ - bitfield flags.", - ) - .value_name("regex") - .action(ArgAction::Append) - .number_of_values(1), - Arg::new("newtype-enum") - .long("newtype-enum") - .help("Mark any enum whose name matches as a newtype.") - .value_name("regex") - .action(ArgAction::Append) - .number_of_values(1), - Arg::new("newtype-global-enum") - .long("newtype-global-enum") - .help("Mark any enum whose name matches as a global newtype.") - .value_name("regex") - .action(ArgAction::Append) - .number_of_values(1), - Arg::new("rustified-enum") - .long("rustified-enum") - .help("Mark any enum whose name matches as a Rust enum.") - .value_name("regex") - .action(ArgAction::Append) - .number_of_values(1), - Arg::new("constified-enum") - .long("constified-enum") - .help( - "Mark any enum whose name matches as a series of \ - constants.", - ) - .value_name("regex") - .action(ArgAction::Append) - .number_of_values(1), - Arg::new("constified-enum-module") - .long("constified-enum-module") - .help( - "Mark any enum whose name matches as a module of \ - constants.", - ) - .value_name("regex") - .action(ArgAction::Append) - .number_of_values(1), - Arg::new("default-macro-constant-type") - .long("default-macro-constant-type") - .help("The default signed/unsigned type for C macro constants.") - .value_name("variant") - .default_value("unsigned") - .value_parser(PossibleValuesParser::new(["signed", "unsigned"])) - .action(ArgAction::Set), - Arg::new("default-alias-style") - .long("default-alias-style") - .help("The default style of code used to generate typedefs.") - .value_name("variant") - .default_value("type_alias") - .value_parser(PossibleValuesParser::new([ - "type_alias", - "new_type", - "new_type_deref", - ])) - .action(ArgAction::Set), - Arg::new("normal-alias") - .long("normal-alias") - .help( - "Mark any typedef alias whose name matches to use \ - normal type aliasing.", - ) - .value_name("regex") - .action(ArgAction::Append) - .number_of_values(1), - Arg::new("new-type-alias") - .long("new-type-alias") - .help( - "Mark any typedef alias whose name matches to have \ - a new type generated for it.", - ) - .value_name("regex") - .action(ArgAction::Append) - .number_of_values(1), - Arg::new("new-type-alias-deref") - .long("new-type-alias-deref") - .help( - "Mark any typedef alias whose name matches to have \ - a new type with Deref and DerefMut to the inner type.", - ) - .value_name("regex") - .action(ArgAction::Append) - .number_of_values(1), - Arg::new("default-non-copy-union-style") - .long("default-non-copy-union-style") - .help( - "The default style of code used to generate unions with \ - non-Copy members. Note that ManuallyDrop was first \ - stabilized in Rust 1.20.0.", - ) - .value_name("style") - .default_value("bindgen_wrapper") - .value_parser(PossibleValuesParser::new([ - "bindgen_wrapper", - "manually_drop", - ])) - .action(ArgAction::Set), - Arg::new("bindgen-wrapper-union") - .long("bindgen-wrapper-union") - .help( - "Mark any union whose name matches and who has a \ - non-Copy member to use a bindgen-generated wrapper for \ - fields.", - ) - .value_name("regex") - .action(ArgAction::Append) - .number_of_values(1), - Arg::new("manually-drop-union") - .long("manually-drop-union") - .help( - "Mark any union whose name matches and who has a \ - non-Copy member to use ManuallyDrop (stabilized in Rust \ - 1.20.0) for fields.", - ) - .value_name("regex") - .action(ArgAction::Append) - .number_of_values(1), - Arg::new("blocklist-type") - .long("blocklist-type") - .help("Mark as hidden.") - .value_name("type") - .action(ArgAction::Append) - .number_of_values(1), - Arg::new("blocklist-function") - .long("blocklist-function") - .help("Mark as hidden.") - .value_name("function") - .action(ArgAction::Append) - .number_of_values(1), - Arg::new("blocklist-item") - .long("blocklist-item") - .help("Mark as hidden.") - .value_name("item") - .action(ArgAction::Append) - .number_of_values(1), - Arg::new("blocklist-file") - .long("blocklist-file") - .help("Mark all contents of as hidden.") - .value_name("path") - .action(ArgAction::Append) - .number_of_values(1), - Arg::new("no-layout-tests") - .long("no-layout-tests") - .help("Avoid generating layout tests for any type.") - .action(ArgAction::SetTrue), - Arg::new("no-derive-copy") - .long("no-derive-copy") - .help("Avoid deriving Copy on any type.") - .action(ArgAction::SetTrue), - Arg::new("no-derive-debug") - .long("no-derive-debug") - .help("Avoid deriving Debug on any type.") - .action(ArgAction::SetTrue), - Arg::new("no-derive-default") - .long("no-derive-default") - .hide(true) - .help("Avoid deriving Default on any type.") - .action(ArgAction::SetTrue), - Arg::new("impl-debug").long("impl-debug").help( - "Create Debug implementation, if it can not be derived \ - automatically.", - ) - .action(ArgAction::SetTrue), - Arg::new("impl-partialeq") - .long("impl-partialeq") - .help( - "Create PartialEq implementation, if it can not be derived \ - automatically.", - ) - .action(ArgAction::SetTrue), - Arg::new("with-derive-default") - .long("with-derive-default") - .help("Derive Default on any type.") - .action(ArgAction::SetTrue), - Arg::new("with-derive-hash") - .long("with-derive-hash") - .help("Derive hash on any type.") - .action(ArgAction::SetTrue), - Arg::new("with-derive-partialeq") - .long("with-derive-partialeq") - .help("Derive partialeq on any type.") - .action(ArgAction::SetTrue), - Arg::new("with-derive-partialord") - .long("with-derive-partialord") - .help("Derive partialord on any type.") - .action(ArgAction::SetTrue), - Arg::new("with-derive-eq") - .long("with-derive-eq") - .help( - "Derive eq on any type. Enable this option also \ - enables --with-derive-partialeq", - ) - .action(ArgAction::SetTrue), - Arg::new("with-derive-ord") - .long("with-derive-ord") - .help( - "Derive ord on any type. Enable this option also \ - enables --with-derive-partialord", - ) - .action(ArgAction::SetTrue), - Arg::new("no-doc-comments") - .long("no-doc-comments") - .help( - "Avoid including doc comments in the output, see: \ - https://github.com/rust-lang/rust-bindgen/issues/426", - ) - .action(ArgAction::SetTrue), - Arg::new("no-recursive-allowlist") - .long("no-recursive-allowlist") - .help( - "Disable allowlisting types recursively. This will cause \ - bindgen to emit Rust code that won't compile! See the \ - `bindgen::Builder::allowlist_recursively` method's \ - documentation for details.", - ) - .action(ArgAction::SetTrue), - Arg::new("objc-extern-crate") - .long("objc-extern-crate") - .help("Use extern crate instead of use for objc.") - .action(ArgAction::SetTrue), - Arg::new("generate-block") - .long("generate-block") - .help("Generate block signatures instead of void pointers.") - .action(ArgAction::SetTrue), - Arg::new("block-extern-crate") - .long("block-extern-crate") - .help("Use extern crate instead of use for block.") - .action(ArgAction::SetTrue), - Arg::new("distrust-clang-mangling") - .long("distrust-clang-mangling") - .help("Do not trust the libclang-provided mangling") - .action(ArgAction::SetTrue), - Arg::new("builtins").long("builtins").help( - "Output bindings for builtin definitions, e.g. \ - __builtin_va_list.", - ) - .action(ArgAction::SetTrue), - Arg::new("ctypes-prefix") - .long("ctypes-prefix") - .help( - "Use the given prefix before raw types instead of \ - ::std::os::raw.", - ) - .value_name("prefix"), - Arg::new("anon-fields-prefix") - .long("anon-fields-prefix") - .help("Use the given prefix for the anon fields.") - .value_name("prefix") - .default_value(DEFAULT_ANON_FIELDS_PREFIX), - Arg::new("time-phases") - .long("time-phases") - .help("Time the different bindgen phases and print to stderr") - .action(ArgAction::SetTrue), - // All positional arguments after the end of options marker, `--` - Arg::new("clang-args").last(true).action(ArgAction::Append), - Arg::new("emit-clang-ast") - .long("emit-clang-ast") - .help("Output the Clang AST for debugging purposes.") - .action(ArgAction::SetTrue), - Arg::new("emit-ir") - .long("emit-ir") - .help("Output our internal IR for debugging purposes.") - .action(ArgAction::SetTrue), - Arg::new("emit-ir-graphviz") - .long("emit-ir-graphviz") - .help("Dump graphviz dot file.") - .value_name("path"), - Arg::new("enable-cxx-namespaces") - .long("enable-cxx-namespaces") - .help("Enable support for C++ namespaces.") - .action(ArgAction::SetTrue), - Arg::new("disable-name-namespacing") - .long("disable-name-namespacing") - .help( - "Disable namespacing via mangling, causing bindgen to \ - generate names like \"Baz\" instead of \"foo_bar_Baz\" \ - for an input name \"foo::bar::Baz\".", - ) - .action(ArgAction::SetTrue), - Arg::new("disable-nested-struct-naming") - .long("disable-nested-struct-naming") - .help( - "Disable nested struct naming, causing bindgen to generate \ - names like \"bar\" instead of \"foo_bar\" for a nested \ - definition \"struct foo { struct bar { } b; };\"." - ) - .action(ArgAction::SetTrue), - Arg::new("disable-untagged-union") - .long("disable-untagged-union") - .help( - "Disable support for native Rust unions.", - ) - .action(ArgAction::SetTrue), - Arg::new("disable-header-comment") - .long("disable-header-comment") - .help("Suppress insertion of bindgen's version identifier into generated bindings.") - .action(ArgAction::SetTrue), - Arg::new("ignore-functions") - .long("ignore-functions") - .help( - "Do not generate bindings for functions or methods. This \ - is useful when you only care about struct layouts.", - ) - .action(ArgAction::SetTrue), - Arg::new("generate") - .long("generate") - .help( - "Generate only given items, split by commas. \ - Valid values are \"functions\",\"types\", \"vars\", \ - \"methods\", \"constructors\" and \"destructors\".", - ) - .action(ArgAction::Set), - Arg::new("ignore-methods") - .long("ignore-methods") - .help("Do not generate bindings for methods.") - .action(ArgAction::SetTrue), - Arg::new("no-convert-floats") - .long("no-convert-floats") - .help("Do not automatically convert floats to f32/f64.") - .action(ArgAction::SetTrue), - Arg::new("no-prepend-enum-name") - .long("no-prepend-enum-name") - .help("Do not prepend the enum name to constant or newtype variants.") - .action(ArgAction::SetTrue), - Arg::new("no-include-path-detection") - .long("no-include-path-detection") - .help("Do not try to detect default include paths") - .action(ArgAction::SetTrue), - Arg::new("fit-macro-constant-types") - .long("fit-macro-constant-types") - .help("Try to fit macro constants into types smaller than u32/i32") - .action(ArgAction::SetTrue), - Arg::new("opaque-type") - .long("opaque-type") - .help("Mark as opaque.") - .value_name("type") - .action(ArgAction::Append) - .number_of_values(1), - Arg::new("output") - .short('o') - .long("output") - .help("Write Rust bindings to .") - .action(ArgAction::Set), - Arg::new("raw-line") - .long("raw-line") - .help("Add a raw line of Rust code at the beginning of output.") - .action(ArgAction::Append) - .number_of_values(1), - Arg::new("module-raw-line") - .long("module-raw-line") - .help("Add a raw line of Rust code to a given module.") - .action(ArgAction::Append) - .number_of_values(2) - .value_names(&["module-name", "raw-line"]), - Arg::new("rust-target") - .long("rust-target") - .help(&rust_target_help) - .action(ArgAction::Set), - Arg::new("use-core") - .long("use-core") - .help("Use types from Rust core instead of std.") - .action(ArgAction::SetTrue), - Arg::new("conservative-inline-namespaces") - .long("conservative-inline-namespaces") - .help( - "Conservatively generate inline namespaces to avoid name \ - conflicts.", - ) - .action(ArgAction::SetTrue), - Arg::new("use-msvc-mangling") - .long("use-msvc-mangling") - .help("MSVC C++ ABI mangling. DEPRECATED: Has no effect.") - .action(ArgAction::SetTrue), - Arg::new("allowlist-function") - .long("allowlist-function") - .help( - "Allowlist all the free-standing functions matching \ - . Other non-allowlisted functions will not be \ - generated.", - ) - .value_name("regex") - .action(ArgAction::Append) - .number_of_values(1), - Arg::new("generate-inline-functions") - .long("generate-inline-functions") - .help("Generate inline functions.") - .action(ArgAction::SetTrue), - Arg::new("allowlist-type") - .long("allowlist-type") - .help( - "Only generate types matching . Other non-allowlisted types will \ - not be generated.", - ) - .value_name("regex") - .action(ArgAction::Append) - .number_of_values(1), - Arg::new("allowlist-var") - .long("allowlist-var") - .help( - "Allowlist all the free-standing variables matching \ - . Other non-allowlisted variables will not be \ - generated.", - ) - .value_name("regex") - .action(ArgAction::Append) - .number_of_values(1), - Arg::new("allowlist-file") - .alias("allowlist-file") - .long("allowlist-file") - .help("Allowlist all contents of .") - .value_name("path") - .action(ArgAction::Append) - .number_of_values(1), - Arg::new("verbose") - .long("verbose") - .help("Print verbose error messages.") - .action(ArgAction::SetTrue), - Arg::new("dump-preprocessed-input") - .long("dump-preprocessed-input") - .help( - "Preprocess and dump the input header files to disk. \ - Useful when debugging bindgen, using C-Reduce, or when \ - filing issues. The resulting file will be named \ - something like `__bindgen.i` or `__bindgen.ii`.", - ) - .action(ArgAction::SetTrue), - Arg::new("no-record-matches") - .long("no-record-matches") - .help( - "Do not record matching items in the regex sets. \ - This disables reporting of unused items.", - ) - .action(ArgAction::SetTrue), - Arg::new("size_t-is-usize") - .long("size_t-is-usize") - .help("Ignored - this is enabled by default.") - .hide(true) - .action(ArgAction::SetTrue), - Arg::new("no-size_t-is-usize") - .long("no-size_t-is-usize") - .help("Do not bind size_t as usize (useful on platforms \ - where those types are incompatible).") - .action(ArgAction::SetTrue), - Arg::new("no-rustfmt-bindings") - .long("no-rustfmt-bindings") - .help("Do not format the generated bindings with rustfmt.") - .action(ArgAction::SetTrue), - Arg::new("rustfmt-bindings") - .long("rustfmt-bindings") - .help( - "Format the generated bindings with rustfmt. DEPRECATED: \ - --rustfmt-bindings is now enabled by default. Disable \ - with --no-rustfmt-bindings.", - ), - Arg::new("rustfmt-configuration-file") - .long("rustfmt-configuration-file") - .help( - "The absolute path to the rustfmt configuration file. \ - The configuration file will be used for formatting the bindings. \ - This parameter is incompatible with --no-rustfmt-bindings.", - ) - .value_name("path") - .action(ArgAction::Set) - .number_of_values(1), - Arg::new("no-partialeq") - .long("no-partialeq") - .help("Avoid deriving PartialEq for types matching .") - .value_name("regex") - .action(ArgAction::Append) - .number_of_values(1), - Arg::new("no-copy") - .long("no-copy") - .help("Avoid deriving Copy for types matching .") - .value_name("regex") - .action(ArgAction::Append) - .number_of_values(1), - Arg::new("no-debug") - .long("no-debug") - .help("Avoid deriving Debug for types matching .") - .value_name("regex") - .action(ArgAction::Append) - .number_of_values(1), - Arg::new("no-default") - .long("no-default") - .help("Avoid deriving/implement Default for types matching .") - .value_name("regex") - .action(ArgAction::Append) - .number_of_values(1), - Arg::new("no-hash") - .long("no-hash") - .help("Avoid deriving Hash for types matching .") - .value_name("regex") - .action(ArgAction::Append) - .number_of_values(1), - Arg::new("must-use-type") - .long("must-use-type") - .help("Add #[must_use] annotation to types matching .") - .value_name("regex") - .action(ArgAction::Append) - .number_of_values(1), - Arg::new("enable-function-attribute-detection") - .long("enable-function-attribute-detection") - .help( - "Enables detecting unexposed attributes in functions (slow). - Used to generate #[must_use] annotations.", - ) - .action(ArgAction::SetTrue), - Arg::new("use-array-pointers-in-arguments") - .long("use-array-pointers-in-arguments") - .help("Use `*const [T; size]` instead of `*const T` for C arrays") - .action(ArgAction::SetTrue), - Arg::new("wasm-import-module-name") - .long("wasm-import-module-name") - .value_name("name") - .help("The name to be used in a #[link(wasm_import_module = ...)] statement"), - Arg::new("dynamic-loading") - .long("dynamic-loading") - .action(ArgAction::Set) - .help("Use dynamic loading mode with the given library name."), - Arg::new("dynamic-link-require-all") - .long("dynamic-link-require-all") - .help("Require successful linkage to all functions in the library.") - .action(ArgAction::SetTrue), - Arg::new("respect-cxx-access-specs") - .long("respect-cxx-access-specs") - .help("Makes generated bindings `pub` only for items if the items are publically accessible in C++.") - .action(ArgAction::SetTrue), - Arg::new("translate-enum-integer-types") - .long("translate-enum-integer-types") - .help("Always translate enum integer types to native Rust integer types.") - .action(ArgAction::SetTrue), - Arg::new("c-naming") - .long("c-naming") - .help("Generate types with C style naming.") - .action(ArgAction::SetTrue), - Arg::new("explicit-padding") - .long("explicit-padding") - .help("Always output explicit padding fields.") - .action(ArgAction::SetTrue), - Arg::new("vtable-generation") - .long("vtable-generation") - .help("Enables generation of vtable functions.") - .action(ArgAction::SetTrue), - Arg::new("sort-semantically") - .long("sort-semantically") - .help("Enables sorting of code generation in a predefined manner.") - .action(ArgAction::SetTrue), - Arg::new("merge-extern-blocks") - .long("merge-extern-blocks") - .help("Deduplicates extern blocks.") - .action(ArgAction::SetTrue), - Arg::new("override-abi") - .long("override-abi") - .help("Overrides the ABI of functions matching . The value must be of the shape = where can be one of C, stdcall, fastcall, thiscall, aapcs, win64 or C-unwind.") - .value_name("override") - .action(ArgAction::Append) - .number_of_values(1), - Arg::new("wrap-unsafe-ops") - .long("wrap-unsafe-ops") - .help("Wrap unsafe operations in unsafe blocks.") - .action(ArgAction::SetTrue), - Arg::new("V") - .long("version") - .help("Prints the version, and exits") - .action(ArgAction::SetTrue), - ]) // .args() - .get_matches_from(args); - - let verbose = matches.get_flag("verbose"); - if matches.get_flag("V") { + let command = BindgenCommand::parse_from(args); + + let BindgenCommand { + header, + depfile, + default_enum_style, + bitfield_enum, + newtype_enum, + newtype_global_enum, + rustified_enum, + constified_enum, + constified_enum_module, + default_macro_constant_type, + default_alias_style, + normal_alias, + new_type_alias, + new_type_alias_deref, + default_non_copy_union_style, + bindgen_wrapper_union, + manually_drop_union, + blocklist_type, + blocklist_function, + blocklist_item, + blocklist_file, + no_layout_tests, + no_derive_copy, + no_derive_debug, + no_derive_default, + impl_debug, + impl_partialeq, + with_derive_default, + with_derive_hash, + with_derive_partialeq, + with_derive_partialord, + with_derive_eq, + with_derive_ord, + no_doc_comments, + no_recursive_allowlist, + objc_extern_crate, + generate_block, + block_extern_crate, + distrust_clang_mangling, + builtins, + ctypes_prefix, + anon_fields_prefix, + time_phases, + emit_clang_ast, + emit_ir, + emit_ir_graphviz, + enable_cxx_namespaces, + disable_name_namespacing, + disable_nested_struct_naming, + disable_untagged_union, + disable_header_comment, + ignore_functions, + generate, + ignore_methods, + no_convert_floats, + no_prepend_enum_name, + no_include_path_detection, + fit_macro_constant_types, + opaque_type, + output, + raw_line, + module_raw_line, + rust_target, + use_core, + conservative_inline_namespaces, + use_msvc_mangling: _, + allowlist_function, + generate_inline_functions, + allowlist_type, + allowlist_var, + allowlist_file, + verbose, + dump_preprocessed_input, + no_record_matches, + size_t_is_usize: _, + no_size_t_is_usize, + no_rustfmt_bindings, + rustfmt_bindings: _, + rustfmt_configuration_file, + no_partialeq, + no_copy, + no_debug, + no_default, + no_hash, + must_use_type, + enable_function_attribute_detection, + use_array_pointers_in_arguments, + wasm_import_module_name, + dynamic_loading, + dynamic_link_require_all, + respect_cxx_access_specs, + translate_enum_integer_types, + c_naming, + explicit_padding, + vtable_generation, + sort_semantically, + merge_extern_blocks, + override_abi, + wrap_unsafe_ops, + version, + clang_args, + } = command; + + if version { println!( "bindgen {}", option_env!("CARGO_PKG_VERSION").unwrap_or("unknown") @@ -637,415 +473,327 @@ where let mut builder = builder(); - if let Some(header) = matches.get_one::("header") { + if let Some(header) = header { builder = builder.header(header); } else { return Err(Error::new(ErrorKind::Other, "Header not found")); } - if let Some(rust_target) = matches.get_one::("rust-target") { - builder = builder.rust_target(RustTarget::from_str(rust_target)?); + if let Some(rust_target) = rust_target { + builder = builder.rust_target(rust_target); } - if let Some(variant) = matches.get_one::("default-enum-style") { - builder = builder.default_enum_style(EnumVariation::from_str(variant)?) + if let Some(variant) = default_enum_style { + builder = builder.default_enum_style(variant); } - if let Some(bitfields) = matches.get_many::("bitfield-enum") { - for regex in bitfields { - builder = builder.bitfield_enum(regex); - } + for regex in bitfield_enum { + builder = builder.bitfield_enum(regex); } - if let Some(newtypes) = matches.get_many::("newtype-enum") { - for regex in newtypes { - builder = builder.newtype_enum(regex); - } + for regex in newtype_enum { + builder = builder.newtype_enum(regex); } - if let Some(newtypes) = matches.get_many::("newtype-global-enum") { - for regex in newtypes { - builder = builder.newtype_global_enum(regex); - } + for regex in newtype_global_enum { + builder = builder.newtype_global_enum(regex); } - if let Some(rustifieds) = matches.get_many::("rustified-enum") { - for regex in rustifieds { - builder = builder.rustified_enum(regex); - } + for regex in rustified_enum { + builder = builder.rustified_enum(regex); } - if let Some(const_enums) = matches.get_many::("constified-enum") { - for regex in const_enums { - builder = builder.constified_enum(regex); - } + for regex in constified_enum { + builder = builder.constified_enum(regex); } - if let Some(constified_mods) = - matches.get_many::("constified-enum-module") - { - for regex in constified_mods { - builder = builder.constified_enum_module(regex); - } + for regex in constified_enum_module { + builder = builder.constified_enum_module(regex); } - if let Some(variant) = - matches.get_one::("default-macro-constant-type") - { - builder = builder - .default_macro_constant_type(MacroTypeVariation::from_str(variant)?) + if let Some(default_macro_constant_type) = default_macro_constant_type { + builder = + builder.default_macro_constant_type(default_macro_constant_type) } - if let Some(variant) = matches.get_one::("default-alias-style") { - builder = - builder.default_alias_style(AliasVariation::from_str(variant)?); + if let Some(variant) = default_alias_style { + builder = builder.default_alias_style(variant); } - if let Some(type_alias) = matches.get_many::("normal-alias") { - for regex in type_alias { - builder = builder.type_alias(regex); - } + for regex in normal_alias { + builder = builder.type_alias(regex); } - if let Some(new_type) = matches.get_many::("new-type-alias") { - for regex in new_type { - builder = builder.new_type_alias(regex); - } + for regex in new_type_alias { + builder = builder.new_type_alias(regex); } - if let Some(new_type_deref) = - matches.get_many::("new-type-alias-deref") - { - for regex in new_type_deref { - builder = builder.new_type_alias_deref(regex); - } + for regex in new_type_alias_deref { + builder = builder.new_type_alias_deref(regex); } - if let Some(variant) = - matches.get_one::("default-non-copy-union-style") - { - builder = builder.default_non_copy_union_style( - NonCopyUnionStyle::from_str(variant)?, - ); + if let Some(variant) = default_non_copy_union_style { + builder = builder.default_non_copy_union_style(variant); } - if let Some(bindgen_wrapper_union) = - matches.get_many::("bindgen-wrapper-union") - { - for regex in bindgen_wrapper_union { - builder = builder.bindgen_wrapper_union(regex); - } + for regex in bindgen_wrapper_union { + builder = builder.bindgen_wrapper_union(regex); } - if let Some(manually_drop_union) = - matches.get_many::("manually-drop-union") - { - for regex in manually_drop_union { - builder = builder.manually_drop_union(regex); - } + for regex in manually_drop_union { + builder = builder.manually_drop_union(regex); } - if let Some(hidden_types) = matches.get_many::("blocklist-type") { - for ty in hidden_types { - builder = builder.blocklist_type(ty); - } + for ty in blocklist_type { + builder = builder.blocklist_type(ty); } - if let Some(hidden_functions) = - matches.get_many::("blocklist-function") - { - for fun in hidden_functions { - builder = builder.blocklist_function(fun); - } + for fun in blocklist_function { + builder = builder.blocklist_function(fun); } - if let Some(hidden_identifiers) = - matches.get_many::("blocklist-item") - { - for id in hidden_identifiers { - builder = builder.blocklist_item(id); - } + for id in blocklist_item { + builder = builder.blocklist_item(id); } - if let Some(hidden_files) = matches.get_many::("blocklist-file") { - for file in hidden_files { - builder = builder.blocklist_file(file); - } + for file in blocklist_file { + builder = builder.blocklist_file(file); } - if matches.get_flag("builtins") { + if builtins { builder = builder.emit_builtins(); } - if matches.get_flag("no-layout-tests") { + if no_layout_tests { builder = builder.layout_tests(false); } - if matches.get_flag("no-derive-copy") { + if no_derive_copy { builder = builder.derive_copy(false); } - if matches.get_flag("no-derive-debug") { + if no_derive_debug { builder = builder.derive_debug(false); } - if matches.get_flag("impl-debug") { + if impl_debug { builder = builder.impl_debug(true); } - if matches.get_flag("impl-partialeq") { + if impl_partialeq { builder = builder.impl_partialeq(true); } - if matches.get_flag("with-derive-default") { + if with_derive_default { builder = builder.derive_default(true); } - if matches.get_flag("with-derive-hash") { + if with_derive_hash { builder = builder.derive_hash(true); } - if matches.get_flag("with-derive-partialeq") { + if with_derive_partialeq { builder = builder.derive_partialeq(true); } - if matches.get_flag("with-derive-partialord") { + if with_derive_partialord { builder = builder.derive_partialord(true); } - if matches.get_flag("with-derive-eq") { + if with_derive_eq { builder = builder.derive_eq(true); } - if matches.get_flag("with-derive-ord") { + if with_derive_ord { builder = builder.derive_ord(true); } - if matches.get_flag("no-derive-default") { + if no_derive_default { builder = builder.derive_default(false); } - if matches.get_flag("no-prepend-enum-name") { + if no_prepend_enum_name { builder = builder.prepend_enum_name(false); } - if matches.get_flag("no-include-path-detection") { + if no_include_path_detection { builder = builder.detect_include_paths(false); } - if matches.get_flag("fit-macro-constant-types") { + if fit_macro_constant_types { builder = builder.fit_macro_constants(true); } - if matches.get_flag("time-phases") { + if time_phases { builder = builder.time_phases(true); } - if matches.get_flag("use-array-pointers-in-arguments") { + if use_array_pointers_in_arguments { builder = builder.array_pointers_in_arguments(true); } - if let Some(wasm_import_name) = - matches.get_one::("wasm-import-module-name") - { + if let Some(wasm_import_name) = wasm_import_module_name { builder = builder.wasm_import_module_name(wasm_import_name); } - if let Some(prefix) = matches.get_one::("ctypes-prefix") { + if let Some(prefix) = ctypes_prefix { builder = builder.ctypes_prefix(prefix); } - if let Some(prefix) = matches.get_one::("anon-fields-prefix") { - builder = builder.anon_fields_prefix(prefix); - } - - if let Some(what_to_generate) = matches.get_one::("generate") { - let mut config = CodegenConfig::empty(); - for what in what_to_generate.split(',') { - match what { - "functions" => config.insert(CodegenConfig::FUNCTIONS), - "types" => config.insert(CodegenConfig::TYPES), - "vars" => config.insert(CodegenConfig::VARS), - "methods" => config.insert(CodegenConfig::METHODS), - "constructors" => config.insert(CodegenConfig::CONSTRUCTORS), - "destructors" => config.insert(CodegenConfig::DESTRUCTORS), - otherwise => { - return Err(Error::new( - ErrorKind::Other, - format!("Unknown generate item: {}", otherwise), - )); - } - } - } + builder = builder.anon_fields_prefix(anon_fields_prefix); + + if let Some(config) = generate { builder = builder.with_codegen_config(config); } - if matches.get_flag("emit-clang-ast") { + if emit_clang_ast { builder = builder.emit_clang_ast(); } - if matches.get_flag("emit-ir") { + if emit_ir { builder = builder.emit_ir(); } - if let Some(path) = matches.get_one::("emit-ir-graphviz") { + if let Some(path) = emit_ir_graphviz { builder = builder.emit_ir_graphviz(path); } - if matches.get_flag("enable-cxx-namespaces") { + if enable_cxx_namespaces { builder = builder.enable_cxx_namespaces(); } - if matches.get_flag("enable-function-attribute-detection") { + if enable_function_attribute_detection { builder = builder.enable_function_attribute_detection(); } - if matches.get_flag("disable-name-namespacing") { + if disable_name_namespacing { builder = builder.disable_name_namespacing(); } - if matches.get_flag("disable-nested-struct-naming") { + if disable_nested_struct_naming { builder = builder.disable_nested_struct_naming(); } - if matches.get_flag("disable-untagged-union") { + if disable_untagged_union { builder = builder.disable_untagged_union(); } - if matches.get_flag("disable-header-comment") { + if disable_header_comment { builder = builder.disable_header_comment(); } - if matches.get_flag("ignore-functions") { + if ignore_functions { builder = builder.ignore_functions(); } - if matches.get_flag("ignore-methods") { + if ignore_methods { builder = builder.ignore_methods(); } - if matches.get_flag("no-convert-floats") { + if no_convert_floats { builder = builder.no_convert_floats(); } - if matches.get_flag("no-doc-comments") { + if no_doc_comments { builder = builder.generate_comments(false); } - if matches.get_flag("no-recursive-allowlist") { + if no_recursive_allowlist { builder = builder.allowlist_recursively(false); } - if matches.get_flag("objc-extern-crate") { + if objc_extern_crate { builder = builder.objc_extern_crate(true); } - if matches.get_flag("generate-block") { + if generate_block { builder = builder.generate_block(true); } - if matches.get_flag("block-extern-crate") { + if block_extern_crate { builder = builder.block_extern_crate(true); } - if let Some(opaque_types) = matches.get_many::("opaque-type") { - for ty in opaque_types { - builder = builder.opaque_type(ty); - } + for ty in opaque_type { + builder = builder.opaque_type(ty); } - if let Some(lines) = matches.get_many::("raw-line") { - for line in lines { - builder = builder.raw_line(line); - } + for line in raw_line { + builder = builder.raw_line(line); } - if let Some(mut values) = matches.get_many::("module-raw-line") { - while let Some(module) = values.next() { - let line = values.next().unwrap(); - builder = builder.module_raw_line(module, line); - } + let mut values = module_raw_line.into_iter(); + while let Some(module) = values.next() { + let line = values.next().unwrap(); + builder = builder.module_raw_line(module, line); } - if matches.get_flag("use-core") { + if use_core { builder = builder.use_core(); } - if matches.get_flag("distrust-clang-mangling") { + if distrust_clang_mangling { builder = builder.trust_clang_mangling(false); } - if matches.get_flag("conservative-inline-namespaces") { + if conservative_inline_namespaces { builder = builder.conservative_inline_namespaces(); } - if matches.get_flag("generate-inline-functions") { + if generate_inline_functions { builder = builder.generate_inline_functions(true); } - if let Some(allowlist) = matches.get_many::("allowlist-function") { - for regex in allowlist { - builder = builder.allowlist_function(regex); - } + for regex in allowlist_function { + builder = builder.allowlist_function(regex); } - if let Some(allowlist) = matches.get_many::("allowlist-type") { - for regex in allowlist { - builder = builder.allowlist_type(regex); - } + for regex in allowlist_type { + builder = builder.allowlist_type(regex); } - if let Some(allowlist) = matches.get_many::("allowlist-var") { - for regex in allowlist { - builder = builder.allowlist_var(regex); - } + for regex in allowlist_var { + builder = builder.allowlist_var(regex); } - if let Some(hidden_files) = matches.get_many::("allowlist-file") { - for file in hidden_files { - builder = builder.allowlist_file(file); - } + for file in allowlist_file { + builder = builder.allowlist_file(file); } - if let Some(args) = matches.get_many::("clang-args") { - for arg in args { - builder = builder.clang_arg(arg); - } + for arg in clang_args { + builder = builder.clang_arg(arg); } - let output = if let Some(path) = matches.get_one::("output") { + let output = if let Some(path) = &output { let file = File::create(path)?; - if let Some(depfile) = matches.get_one::("depfile") { + if let Some(depfile) = depfile { builder = builder.depfile(path, depfile); } Box::new(io::BufWriter::new(file)) as Box } else { - if let Some(depfile) = matches.get_one::("depfile") { + if let Some(depfile) = depfile { builder = builder.depfile("-", depfile); } Box::new(io::BufWriter::new(io::stdout())) as Box }; - if matches.get_flag("dump-preprocessed-input") { + if dump_preprocessed_input { builder.dump_preprocessed_input()?; } - if matches.get_flag("no-record-matches") { + if no_record_matches { builder = builder.record_matches(false); } - if matches.get_flag("no-size_t-is-usize") { + if no_size_t_is_usize { builder = builder.size_t_is_usize(false); } - let no_rustfmt_bindings = matches.get_flag("no-rustfmt-bindings"); if no_rustfmt_bindings { builder = builder.rustfmt_bindings(false); } - if let Some(path_str) = - matches.get_one::("rustfmt-configuration-file") - { + if let Some(path_str) = rustfmt_configuration_file { let path = PathBuf::from(path_str); if no_rustfmt_bindings { @@ -1072,93 +820,77 @@ where builder = builder.rustfmt_configuration_file(Some(path)); } - if let Some(no_partialeq) = matches.get_many::("no-partialeq") { - for regex in no_partialeq { - builder = builder.no_partialeq(regex); - } + for regex in no_partialeq { + builder = builder.no_partialeq(regex); } - if let Some(no_copy) = matches.get_many::("no-copy") { - for regex in no_copy { - builder = builder.no_copy(regex); - } + for regex in no_copy { + builder = builder.no_copy(regex); } - if let Some(no_debug) = matches.get_many::("no-debug") { - for regex in no_debug { - builder = builder.no_debug(regex); - } + for regex in no_debug { + builder = builder.no_debug(regex); } - if let Some(no_default) = matches.get_many::("no-default") { - for regex in no_default { - builder = builder.no_default(regex); - } + for regex in no_default { + builder = builder.no_default(regex); } - if let Some(no_hash) = matches.get_many::("no-hash") { - for regex in no_hash { - builder = builder.no_hash(regex); - } + for regex in no_hash { + builder = builder.no_hash(regex); } - if let Some(must_use_type) = matches.get_many::("must-use-type") { - for regex in must_use_type { - builder = builder.must_use_type(regex); - } + for regex in must_use_type { + builder = builder.must_use_type(regex); } - if let Some(dynamic_library_name) = - matches.get_one::("dynamic-loading") - { + if let Some(dynamic_library_name) = dynamic_loading { builder = builder.dynamic_library_name(dynamic_library_name); } - if matches.get_flag("dynamic-link-require-all") { + if dynamic_link_require_all { builder = builder.dynamic_link_require_all(true); } - if matches.get_flag("respect-cxx-access-specs") { + if respect_cxx_access_specs { builder = builder.respect_cxx_access_specs(true); } - if matches.get_flag("translate-enum-integer-types") { + if translate_enum_integer_types { builder = builder.translate_enum_integer_types(true); } - if matches.get_flag("c-naming") { + if c_naming { builder = builder.c_naming(true); } - if matches.get_flag("explicit-padding") { + if explicit_padding { builder = builder.explicit_padding(true); } - if matches.get_flag("vtable-generation") { + if vtable_generation { builder = builder.vtable_generation(true); } - if matches.get_flag("sort-semantically") { + if sort_semantically { builder = builder.sort_semantically(true); } - if matches.get_flag("merge-extern-blocks") { + if merge_extern_blocks { builder = builder.merge_extern_blocks(true); } - if let Some(abi_overrides) = matches.get_many::("override-abi") { - for abi_override in abi_overrides { - let (regex, abi_str) = abi_override - .rsplit_once('=') - .expect("Invalid ABI override: Missing `=`"); - let abi = abi_str - .parse() - .unwrap_or_else(|err| panic!("Invalid ABI override: {}", err)); - builder = builder.override_abi(abi, regex); - } + for abi_override in override_abi { + let (regex, abi_str) = abi_override + .rsplit_once('=') + .expect("Invalid ABI override: Missing `=`"); + let abi = abi_str + .parse() + .unwrap_or_else(|err| panic!("Invalid ABI override: {}", err)); + builder = builder.override_abi(abi, regex); } - if matches.get_flag("wrap-unsafe-ops") { + if wrap_unsafe_ops { builder = builder.wrap_unsafe_ops(true); } diff --git a/bindgen-tests/Cargo.toml b/bindgen-tests/Cargo.toml index 774bbf0928..32694dad31 100644 --- a/bindgen-tests/Cargo.toml +++ b/bindgen-tests/Cargo.toml @@ -8,7 +8,7 @@ publish = false bindgen = { path = "../bindgen" } diff = "0.1" shlex = "1" -clap = "4" +clap = { version = "4", features = ["derive"] } tempfile = "3" [features] From bca47cd9c2e718012f7f953be25bb3a6a9ca400b Mon Sep 17 00:00:00 2001 From: Dan Dumont Date: Fri, 20 Jan 2023 15:12:42 -0500 Subject: [PATCH 442/942] Implement cli option for custom derive (#2328) * custom derives after DeriveInfo * Introduce `TypeKind` instead of `CompKind` * Add tests * Emit CLI flags for callbacks * update changelog * run rustfmt * fix tests * fix features Co-authored-by: Christian Poveda --- CHANGELOG.md | 7 +- bindgen-cli/Cargo.toml | 2 +- bindgen-cli/options.rs | 86 ++++++++++++- bindgen-tests/Cargo.toml | 2 +- .../expectations/tests/derive-custom-cli.rs | 115 ++++++++++++++++++ .../tests/headers/derive-custom-cli.h | 14 +++ bindgen/Cargo.toml | 1 + bindgen/callbacks.rs | 20 +++ bindgen/codegen/mod.rs | 17 ++- bindgen/lib.rs | 9 +- bindgen/regex_set.rs | 7 ++ 11 files changed, 271 insertions(+), 9 deletions(-) create mode 100644 bindgen-tests/tests/expectations/tests/derive-custom-cli.rs create mode 100644 bindgen-tests/tests/headers/derive-custom-cli.h diff --git a/CHANGELOG.md b/CHANGELOG.md index e70b118764..9850539fcc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -156,13 +156,18 @@ ## Changed * Fixed name collisions when having a C `enum` and a `typedef` with the same name. - * The `ParseCallbacks::generated_name_override` now receives `ItemInfo<'_>` as + * The `ParseCallbacks::generated_name_override` method now receives `ItemInfo<'_>` as argument instead of a `&str`. * Updated the `clang-sys` crate version to 1.4.0 to support clang 15. * The return type is now ommited in signatures of functions returning `void`. * Updated the `clap` dependency for `bindgen-cli` to 4. * Rewrote the `bindgen-cli` argument parser which could introduce unexpected behavior changes. + * The `ParseCallbacks::add_derives` method now receives `DeriveInfo<'_>` as + argument instead of a `&str`. This type also includes the kind of target type. + * Added a new set of flags `--with-derive-custom`, + `--with-derive-custom-struct`, `--with-derive-custom-enum` and + `--with-derive-custom-enum` to add custom derives from the CLI. ## Removed diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index 76099eb060..b900d9406d 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -21,7 +21,7 @@ path = "main.rs" name = "bindgen" [dependencies] -bindgen = { path = "../bindgen", version = "=0.63.0" } +bindgen = { path = "../bindgen", version = "=0.63.0", features = ["cli"] } shlex = "1" clap = { version = "4", features = ["derive"] } env_logger = { version = "0.9.0", optional = true } diff --git a/bindgen-cli/options.rs b/bindgen-cli/options.rs index c536ed6275..2b09d85fd9 100644 --- a/bindgen-cli/options.rs +++ b/bindgen-cli/options.rs @@ -1,6 +1,7 @@ +use bindgen::callbacks::TypeKind; use bindgen::{ builder, AliasVariation, Builder, CodegenConfig, EnumVariation, - MacroTypeVariation, NonCopyUnionStyle, RustTarget, + MacroTypeVariation, NonCopyUnionStyle, RegexSet, RustTarget, DEFAULT_ANON_FIELDS_PREFIX, RUST_TARGET_STRINGS, }; use clap::Parser; @@ -340,6 +341,18 @@ struct BindgenCommand { /// Wrap unsafe operations in unsafe blocks. #[arg(long)] wrap_unsafe_ops: bool, + /// Derive custom traits on any kind of type. The value must be of the shape = where is a coma-separated list of derive macros. + #[arg(long, value_name = "CUSTOM")] + with_derive_custom: Vec, + /// Derive custom traits on a `struct`. The value must be of the shape = where is a coma-separated list of derive macros. + #[arg(long, value_name = "CUSTOM")] + with_derive_custom_struct: Vec, + /// Derive custom traits on an `enum. The value must be of the shape = where is a coma-separated list of derive macros. + #[arg(long, value_name = "CUSTOM")] + with_derive_custom_enum: Vec, + /// Derive custom traits on a `union`. The value must be of the shape = where is a coma-separated list of derive macros. + #[arg(long, value_name = "CUSTOM")] + with_derive_custom_union: Vec, /// Prints the version, and exits #[arg(short = 'V', long)] version: bool, @@ -456,6 +469,10 @@ where merge_extern_blocks, override_abi, wrap_unsafe_ops, + with_derive_custom, + with_derive_custom_struct, + with_derive_custom_enum, + with_derive_custom_union, version, clang_args, } = command; @@ -894,5 +911,72 @@ where builder = builder.wrap_unsafe_ops(true); } + #[derive(Debug)] + struct CustomDeriveCallback { + derives: Vec, + kind: Option, + regex_set: bindgen::RegexSet, + } + + impl bindgen::callbacks::ParseCallbacks for CustomDeriveCallback { + fn cli_args(&self) -> Vec { + let mut args = vec![]; + + let flag = match &self.kind { + None => "--with-derive-custom", + Some(TypeKind::Struct) => "--with-derive-custom-struct", + Some(TypeKind::Enum) => "--with-derive-custom-enum", + Some(TypeKind::Union) => "--with-derive-custom-union", + }; + + let derives = self.derives.join(","); + + for item in self.regex_set.get_items() { + args.extend_from_slice(&[ + flag.to_owned(), + format!("{}={}", item, derives), + ]); + } + + args + } + + fn add_derives( + &self, + info: &bindgen::callbacks::DeriveInfo<'_>, + ) -> Vec { + if self.kind.map(|kind| kind == info.kind).unwrap_or(true) && + self.regex_set.matches(info.name) + { + return self.derives.clone(); + } + vec![] + } + } + + for (custom_derives, kind) in [ + (with_derive_custom, None), + (with_derive_custom_struct, Some(TypeKind::Struct)), + (with_derive_custom_enum, Some(TypeKind::Enum)), + (with_derive_custom_union, Some(TypeKind::Union)), + ] { + for custom_derive in custom_derives { + let (regex, derives) = custom_derive + .rsplit_once('=') + .expect("Invalid custom derive argument: Missing `=`"); + let derives = derives.split(',').map(|s| s.to_owned()).collect(); + + let mut regex_set = RegexSet::new(); + regex_set.insert(regex); + regex_set.build(false); + + builder = builder.parse_callbacks(Box::new(CustomDeriveCallback { + derives, + kind, + regex_set, + })); + } + } + Ok((builder, output, verbose)) } diff --git a/bindgen-tests/Cargo.toml b/bindgen-tests/Cargo.toml index 32694dad31..0678274fd6 100644 --- a/bindgen-tests/Cargo.toml +++ b/bindgen-tests/Cargo.toml @@ -5,7 +5,7 @@ version = "0.1.0" publish = false [dev-dependencies] -bindgen = { path = "../bindgen" } +bindgen = { path = "../bindgen", features = ["cli"] } diff = "0.1" shlex = "1" clap = { version = "4", features = ["derive"] } diff --git a/bindgen-tests/tests/expectations/tests/derive-custom-cli.rs b/bindgen-tests/tests/expectations/tests/derive-custom-cli.rs new file mode 100644 index 0000000000..36f84c7d93 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/derive-custom-cli.rs @@ -0,0 +1,115 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[repr(C)] +#[derive(Clone, Default)] +pub struct foo_struct { + pub inner: ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout_foo_struct() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo_struct)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo_struct)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).inner) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo_struct), + "::", + stringify!(inner) + ) + ); +} +#[repr(u32)] +#[derive(Clone, Hash, PartialEq, Eq, Copy)] +pub enum foo_enum { + inner = 0, +} +#[repr(C)] +#[derive(Clone, Copy)] +pub union foo_union { + pub fst: ::std::mem::ManuallyDrop<::std::os::raw::c_int>, + pub snd: ::std::mem::ManuallyDrop, +} +#[test] +fn bindgen_test_layout_foo_union() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo_union)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo_union)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).fst) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo_union), + "::", + stringify!(fst) + ) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).snd) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo_union), + "::", + stringify!(snd) + ) + ); +} +#[repr(C)] +pub struct non_matching { + pub inner: ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout_non_matching() { + const UNINIT: ::std::mem::MaybeUninit = + ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(non_matching)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(non_matching)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).inner) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(non_matching), + "::", + stringify!(inner) + ) + ); +} diff --git a/bindgen-tests/tests/headers/derive-custom-cli.h b/bindgen-tests/tests/headers/derive-custom-cli.h new file mode 100644 index 0000000000..9b65536f94 --- /dev/null +++ b/bindgen-tests/tests/headers/derive-custom-cli.h @@ -0,0 +1,14 @@ +// bindgen-flags: --default-enum-style rust --default-non-copy-union-style manually_drop --no-default=".*" --no-hash=".*" --no-partialeq=".*" --no-debug=".*" --no-copy=".*" --with-derive-custom="foo_[^e].*=Clone" --with-derive-custom-struct="foo.*=Default" --with-derive-custom-enum="foo.*=Copy" --with-derive-custom-union="foo.*=Copy" +struct foo_struct { + int inner; +}; +enum foo_enum { + inner = 0 +}; +union foo_union { + int fst; + float snd; +}; +struct non_matching { + int inner; +}; diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index 5a03d2481e..2292a5efe4 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -47,6 +47,7 @@ static = ["clang-sys/static"] runtime = ["clang-sys/runtime"] # Dynamically discover a `rustfmt` binary using the `which` crate which-rustfmt = ["which"] +cli = [] # These features only exist for CI testing -- don't use them if you're not hacking # on bindgen! diff --git a/bindgen/callbacks.rs b/bindgen/callbacks.rs index cba406cbd1..dc20e2581e 100644 --- a/bindgen/callbacks.rs +++ b/bindgen/callbacks.rs @@ -25,6 +25,12 @@ impl Default for MacroParsingBehavior { /// A trait to allow configuring different kinds of types in different /// situations. pub trait ParseCallbacks: fmt::Debug { + #[cfg(feature = "cli")] + #[doc(hidden)] + fn cli_args(&self) -> Vec { + vec![] + } + /// This function will be run on every macro that is identified. fn will_parse_macro(&self, _name: &str) -> MacroParsingBehavior { MacroParsingBehavior::Default @@ -120,10 +126,24 @@ pub trait ParseCallbacks: fmt::Debug { /// Relevant information about a type to which new derive attributes will be added using /// [`ParseCallbacks::add_derives`]. +#[derive(Debug)] #[non_exhaustive] pub struct DeriveInfo<'a> { /// The name of the type. pub name: &'a str, + /// The kind of the type. + pub kind: TypeKind, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +/// The kind of the current type. +pub enum TypeKind { + /// The type is a Rust `struct`. + Struct, + /// The type is a Rust `enum`. + Enum, + /// The type is a Rust `union`. + Union, } /// An struct providing information about the item being passed to `ParseCallbacks::generated_name_override`. diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 041d36691c..6b24ae1bd0 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -18,6 +18,7 @@ use self::struct_layout::StructLayoutTracker; use super::BindgenOptions; +use crate::callbacks::{DeriveInfo, TypeKind as DeriveTypeKind}; use crate::ir::analysis::{HasVtable, Sizedness}; use crate::ir::annotations::FieldAccessorKind; use crate::ir::comp::{ @@ -2100,11 +2101,18 @@ impl CodeGenerator for CompInfo { let mut derives: Vec<_> = derivable_traits.into(); derives.extend(item.annotations().derives().iter().map(String::as_str)); + let is_rust_union = is_union && struct_layout.is_rust_union(); + // The custom derives callback may return a list of derive attributes; // add them to the end of the list. let custom_derives = ctx.options().all_callbacks(|cb| { - cb.add_derives(&crate::callbacks::DeriveInfo { + cb.add_derives(&DeriveInfo { name: &canonical_name, + kind: if is_rust_union { + DeriveTypeKind::Union + } else { + DeriveTypeKind::Struct + }, }) }); // In most cases this will be a no-op, since custom_derives will be empty. @@ -2118,7 +2126,7 @@ impl CodeGenerator for CompInfo { attributes.push(attributes::must_use()); } - let mut tokens = if is_union && struct_layout.is_rust_union() { + let mut tokens = if is_rust_union { quote! { #( #attributes )* pub union #canonical_ident @@ -3112,7 +3120,10 @@ impl CodeGenerator for Enum { // The custom derives callback may return a list of derive attributes; // add them to the end of the list. let custom_derives = ctx.options().all_callbacks(|cb| { - cb.add_derives(&crate::callbacks::DeriveInfo { name: &name }) + cb.add_derives(&DeriveInfo { + name: &name, + kind: DeriveTypeKind::Enum, + }) }); // In most cases this will be a no-op, since custom_derives will be empty. derives.extend(custom_derives.iter().map(|s| s.as_str())); diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 46444a93bb..cf1486c2d2 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -65,7 +65,7 @@ mod clang; mod codegen; mod deps; mod features; -mod ir; +pub mod ir; mod parse; mod regex_set; mod time; @@ -91,7 +91,7 @@ use crate::ir::context::{BindgenContext, ItemId}; pub use crate::ir::function::Abi; use crate::ir::item::Item; use crate::parse::ParseError; -use crate::regex_set::RegexSet; +pub use crate::regex_set::RegexSet; use std::borrow::Cow; use std::env; @@ -653,6 +653,11 @@ impl Builder { output_vector.push("--wrap-unsafe-ops".into()); } + #[cfg(feature = "cli")] + for callbacks in &self.options.parse_callbacks { + output_vector.extend(callbacks.cli_args()); + } + // Add clang arguments output_vector.push("--".into()); diff --git a/bindgen/regex_set.rs b/bindgen/regex_set.rs index 9f1e2251cd..6246dd255b 100644 --- a/bindgen/regex_set.rs +++ b/bindgen/regex_set.rs @@ -16,6 +16,13 @@ pub struct RegexSet { } impl RegexSet { + /// Create a new RegexSet + pub fn new() -> RegexSet { + RegexSet { + ..Default::default() + } + } + /// Is this set empty? pub fn is_empty(&self) -> bool { self.items.is_empty() From a7ff8e136027c9542f65eca97a7ff3c0b870518d Mon Sep 17 00:00:00 2001 From: Josh Guilfoyle Date: Wed, 25 Jan 2023 14:54:19 -0800 Subject: [PATCH 443/942] Add *-espidf target triple mappings (#2397) Fixes #2396. This makes it possible to workaround cc/bindgen issues with esp-rs projects by using only environment varaibles (TARGET_CC, CLANG_PATH, etc). Without this, it requires modifying each crate's build.rs that you try to depend on to add a target option passed along to clang. --- bindgen/lib.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/bindgen/lib.rs b/bindgen/lib.rs index cf1486c2d2..8c8ffe5c7d 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -2428,6 +2428,15 @@ fn rust_to_clang_target(rust_target: &str) -> String { let mut clang_target = "riscv64-".to_owned(); clang_target.push_str(rust_target.strip_prefix("riscv64gc-").unwrap()); return clang_target; + } else if rust_target.ends_with("-espidf") { + let mut clang_target = + rust_target.strip_suffix("-espidf").unwrap().to_owned(); + clang_target.push_str("-elf"); + if clang_target.starts_with("riscv32imc-") { + clang_target = "riscv32-".to_owned() + + clang_target.strip_prefix("riscv32imc-").unwrap(); + } + return clang_target; } rust_target.to_owned() } @@ -3011,3 +3020,15 @@ fn test_rust_to_clang_target_riscv() { "riscv64-unknown-linux-gnu" ) } + +#[test] +fn test_rust_to_clang_target_espidf() { + assert_eq!( + rust_to_clang_target("riscv32imc-esp-espidf"), + "riscv32-esp-elf" + ); + assert_eq!( + rust_to_clang_target("xtensa-esp32-espidf"), + "xtensa-esp32-elf" + ); +} From 62b48c56703eb5f734b9a333b1ae2be10ffa303e Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Mon, 6 Feb 2023 15:40:30 -0500 Subject: [PATCH 444/942] Fix wrong entry in changelog (#2404) --- CHANGELOG.md | 118 ++++++++++++++++++++++++++------------------------- 1 file changed, 61 insertions(+), 57 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9850539fcc..a7723ccd03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,116 +7,120 @@ - [Removed](#removed) - [Fixed](#fixed) - [Security](#security) -- [0.62.0](#0620) +- [0.63.0](#0630) - [Added](#added-1) - [Changed](#changed-1) - - [Fixed](#fixed-1) -- [0.61.0](#0610) + - [Removed](#removed-1) +- [0.62.0](#0620) - [Added](#added-2) - [Changed](#changed-2) + - [Fixed](#fixed-1) +- [0.61.0](#0610) + - [Added](#added-3) + - [Changed](#changed-3) - [Fixed](#fixed-2) - [0.60.1](#0601) - [Fixed](#fixed-3) - [0.60.0](#0600) - - [Added](#added-3) + - [Added](#added-4) - [Fixed](#fixed-4) - - [Changed](#changed-3) - - [Removed](#removed-1) + - [Changed](#changed-4) + - [Removed](#removed-2) - [0.59.2](#0592) - [0.59.1](#0591) - [Fixed](#fixed-5) - [0.59.0](#0590) - - [Added](#added-4) + - [Added](#added-5) - [Fixed](#fixed-6) - - [Changed](#changed-4) + - [Changed](#changed-5) - [0.58.1](#0581) - - [Added](#added-5) -- [0.58.0](#0580) - [Added](#added-6) +- [0.58.0](#0580) + - [Added](#added-7) - [Fixed](#fixed-7) - - [Changed](#changed-5) + - [Changed](#changed-6) - [Deprecated](#deprecated) - - [Removed](#removed-2) + - [Removed](#removed-3) - [Fixed](#fixed-8) - [Security](#security-1) - [0.57.0](#0570) - - [Added](#added-7) + - [Added](#added-8) - [Fixed](#fixed-9) - [0.56.0](#0560) - - [Added](#added-8) - - [Changed](#changed-6) + - [Added](#added-9) + - [Changed](#changed-7) - [Fixed](#fixed-10) - [0.55.1](#0551) - [Fixed](#fixed-11) - [0.55.0](#0550) - - [Removed](#removed-3) - - [Added](#added-9) - - [Changed](#changed-7) - - [Fixed](#fixed-12) -- [0.54.1](#0541) + - [Removed](#removed-4) - [Added](#added-10) - [Changed](#changed-8) - - [Fixed](#fixed-13) -- [0.54.0](#0540) + - [Fixed](#fixed-12) +- [0.54.1](#0541) - [Added](#added-11) - [Changed](#changed-9) + - [Fixed](#fixed-13) +- [0.54.0](#0540) + - [Added](#added-12) + - [Changed](#changed-10) - [Fixed](#fixed-14) - [0.53.3](#0533) - - [Added](#added-12) + - [Added](#added-13) - [Fixed](#fixed-15) - [0.53.2](#0532) - - [Changed](#changed-10) + - [Changed](#changed-11) - [0.53.1](#0531) - - [Added](#added-13) -- [0.53.0](#0530) - [Added](#added-14) - - [Changed](#changed-11) - - [Fixed](#fixed-16) -- [0.52.0](#0520) +- [0.53.0](#0530) - [Added](#added-15) - [Changed](#changed-12) + - [Fixed](#fixed-16) +- [0.52.0](#0520) + - [Added](#added-16) + - [Changed](#changed-13) - [Fixed](#fixed-17) - [0.51.1](#0511) - [Fixed](#fixed-18) - - [Changed](#changed-13) + - [Changed](#changed-14) - [0.51.0](#0510) - [Fixed](#fixed-19) - - [Changed](#changed-14) - - [Added](#added-16) -- [0.50.0](#0500) + - [Changed](#changed-15) - [Added](#added-17) -- [0.49.3](#0493) +- [0.50.0](#0500) - [Added](#added-18) +- [0.49.3](#0493) + - [Added](#added-19) - [0.49.2](#0492) - - [Changed](#changed-15) + - [Changed](#changed-16) - [0.49.1](#0491) - [Fixed](#fixed-20) - - [Changed](#changed-16) + - [Changed](#changed-17) - [0.49.0](#0490) - - [Added](#added-19) + - [Added](#added-20) - [Fixed](#fixed-21) - - [Changed](#changed-17) + - [Changed](#changed-18) - [0.48.1](#0481) - [Fixed](#fixed-22) - [0.48.0](#0480) - - [Changed](#changed-18) + - [Changed](#changed-19) - [Fixed](#fixed-23) - [0.47.4](#0474) - - [Added](#added-20) + - [Added](#added-21) - [0.47.3](#0473) - - [Changed](#changed-19) + - [Changed](#changed-20) - [0.47.2](#0472) - [Fixed](#fixed-24) - [0.47.1](#0471) - - [Changed](#changed-20) + - [Changed](#changed-21) - [Fixed](#fixed-25) - [0.47.0](#0470) - - [Changed](#changed-21) + - [Changed](#changed-22) - [Fixed](#fixed-26) - [0.33.1 .. 0.46.0](#0331--0460) - - [Added](#added-21) - - [Removed](#removed-4) - - [Changed](#changed-22) + - [Added](#added-22) + - [Removed](#removed-5) + - [Changed](#changed-23) - [Fixed](#fixed-27) - [0.33.1](#0331) - [Fixed](#fixed-28) @@ -126,23 +130,23 @@ - [0.32.1](#0321) - [Fixed](#fixed-30) - [0.32.0](#0320) - - [Added](#added-22) - - [Changed](#changed-23) - - [Fixed](#fixed-31) -- [0.31.0](#0310) - [Added](#added-23) - [Changed](#changed-24) + - [Fixed](#fixed-31) +- [0.31.0](#0310) + - [Added](#added-24) + - [Changed](#changed-25) - [Deprecated](#deprecated-1) - - [Removed](#removed-5) + - [Removed](#removed-6) - [Fixed](#fixed-32) - [0.30.0](#0300) - - [Added](#added-24) - - [Changed](#changed-25) + - [Added](#added-25) + - [Changed](#changed-26) - [Deprecated](#deprecated-2) - [Fixed](#fixed-33) - [0.29.0](#0290) - - [Added](#added-25) - - [Changed](#changed-26) + - [Added](#added-26) + - [Changed](#changed-27) - [Fixed](#fixed-34) @@ -178,6 +182,8 @@ # 0.63.0 ## Added + * new feature: `process_comments` method to the `ParseCallbacks` trait to + handle source code comments. ## Changed * Only wrap unsafe operations in unsafe blocks if the `--wrap_unsafe_ops` @@ -204,8 +210,6 @@ matching a regular expression. * new feature: allow using the `C-unwind` ABI in `--override-abi` on nightly rust. - * new feature: `process_comments` method to the `ParseCallbacks` trait to - handle source code comments. ## Changed From 2be14a33451b0259bfed8e0fe517502e46fab7b6 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Tue, 7 Feb 2023 10:13:48 -0500 Subject: [PATCH 445/942] Generate extern wrappers for inlined functions (#2335) * Generate extern wrappers for inlined functions If bindgen finds an inlined function and the `--generate-extern-functions` options is enabled, then: - It will generate two new source and header files with external functions that wrap the inlined functions. - Rerun `Bindings::generate` using the new header file to include these wrappers in the generated bindings. The following additional options were added: - `--extern-function-suffix=`: Adds to the name of each external wrapper function (`__extern` is used by default). - `--extern-functions-file-name=`: Uses as the file name for the header and source files (`extern` is used by default). - `--extern-function-directory=`: Creates the source and header files inside (`/tmp/bindgen` is used by default). The C code serialization is experimental and only supports a very limited set of C functions. Fixes #1090. --------- Co-authored-by: Amanjeev Sethi --- bindgen-cli/Cargo.toml | 2 +- bindgen-cli/options.rs | 30 ++ bindgen-integration/Cargo.toml | 2 +- bindgen-integration/build.rs | 128 +++++-- bindgen-integration/src/lib.rs | 36 ++ bindgen-tests/Cargo.toml | 2 +- .../expectations/tests/generated/README.md | 4 + .../tests/generated/wrap_static_fns.c | 14 + .../expectations/tests/wrap-static-fns.rs | 52 +++ bindgen-tests/tests/headers/wrap-static-fns.h | 33 ++ bindgen-tests/tests/tests.rs | 37 ++ bindgen/Cargo.toml | 1 + bindgen/codegen/mod.rs | 108 +++++- bindgen/codegen/serialize.rs | 356 ++++++++++++++++++ bindgen/ir/context.rs | 16 +- bindgen/ir/function.rs | 31 +- bindgen/lib.rs | 120 +++--- 17 files changed, 876 insertions(+), 96 deletions(-) create mode 100644 bindgen-tests/tests/expectations/tests/generated/README.md create mode 100644 bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c create mode 100644 bindgen-tests/tests/expectations/tests/wrap-static-fns.rs create mode 100644 bindgen-tests/tests/headers/wrap-static-fns.h create mode 100644 bindgen/codegen/serialize.rs diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index b900d9406d..10b4d4cd28 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -21,7 +21,7 @@ path = "main.rs" name = "bindgen" [dependencies] -bindgen = { path = "../bindgen", version = "=0.63.0", features = ["cli"] } +bindgen = { path = "../bindgen", version = "=0.63.0", features = ["cli", "experimental"] } shlex = "1" clap = { version = "4", features = ["derive"] } env_logger = { version = "0.9.0", optional = true } diff --git a/bindgen-cli/options.rs b/bindgen-cli/options.rs index 2b09d85fd9..458c7bab1f 100644 --- a/bindgen-cli/options.rs +++ b/bindgen-cli/options.rs @@ -353,6 +353,20 @@ struct BindgenCommand { /// Derive custom traits on a `union`. The value must be of the shape = where is a coma-separated list of derive macros. #[arg(long, value_name = "CUSTOM")] with_derive_custom_union: Vec, + /// Generate wrappers for `static` and `static inline` functions. + #[arg(long, requires = "experimental")] + wrap_static_fns: bool, + /// Sets the path for the source file that must be created due to the presence of `static` and + /// `static inline` functions. + #[arg(long, requires = "experimental", value_name = "PATH")] + wrap_static_fns_path: Option, + /// Sets the suffix added to the extern wrapper functions generated for `static` and `static + /// inline` functions. + #[arg(long, requires = "experimental", value_name = "SUFFIX")] + wrap_static_fns_suffix: Option, + /// Enables experimental features. + #[arg(long)] + experimental: bool, /// Prints the version, and exits #[arg(short = 'V', long)] version: bool, @@ -473,6 +487,10 @@ where with_derive_custom_struct, with_derive_custom_enum, with_derive_custom_union, + wrap_static_fns, + wrap_static_fns_path, + wrap_static_fns_suffix, + experimental: _, version, clang_args, } = command; @@ -978,5 +996,17 @@ where } } + if wrap_static_fns { + builder = builder.wrap_static_fns(true); + } + + if let Some(path) = wrap_static_fns_path { + builder = builder.wrap_static_fns_path(path); + } + + if let Some(suffix) = wrap_static_fns_suffix { + builder = builder.wrap_static_fns_suffix(suffix); + } + Ok((builder, output, verbose)) } diff --git a/bindgen-integration/Cargo.toml b/bindgen-integration/Cargo.toml index e2abb6e2ed..60f0426a76 100644 --- a/bindgen-integration/Cargo.toml +++ b/bindgen-integration/Cargo.toml @@ -7,7 +7,7 @@ publish = false build = "build.rs" [build-dependencies] -bindgen = { path = "../bindgen" } +bindgen = { path = "../bindgen", features = ["experimental"] } cc = "1.0" [features] diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs index 0f30ad470f..3cc0edb99b 100644 --- a/bindgen-integration/build.rs +++ b/bindgen-integration/build.rs @@ -4,7 +4,7 @@ extern crate cc; use bindgen::callbacks::{ DeriveInfo, IntKind, MacroParsingBehavior, ParseCallbacks, }; -use bindgen::{Builder, EnumVariation}; +use bindgen::{Builder, CargoCallbacks, EnumVariation}; use std::collections::HashSet; use std::env; use std::path::PathBuf; @@ -28,21 +28,14 @@ impl ParseCallbacks for MacroCallback { MacroParsingBehavior::Default } - fn item_name(&self, original_item_name: &str) -> Option { - if original_item_name.starts_with("my_prefixed_") { - Some( - original_item_name - .trim_start_matches("my_prefixed_") - .to_string(), - ) - } else if original_item_name.starts_with("MY_PREFIXED_") { - Some( - original_item_name - .trim_start_matches("MY_PREFIXED_") - .to_string(), - ) - } else { - None + fn int_macro(&self, name: &str, _value: i64) -> Option { + match name { + "TESTMACRO_CUSTOMINTKIND_PATH" => Some(IntKind::Custom { + name: "crate::MacroInteger", + is_signed: true, + }), + + _ => None, } } @@ -67,17 +60,6 @@ impl ParseCallbacks for MacroCallback { } } - fn int_macro(&self, name: &str, _value: i64) -> Option { - match name { - "TESTMACRO_CUSTOMINTKIND_PATH" => Some(IntKind::Custom { - name: "crate::MacroInteger", - is_signed: true, - }), - - _ => None, - } - } - fn func_macro(&self, name: &str, value: &[&[u8]]) { match name { "TESTMACRO_NONFUNCTIONAL" => { @@ -122,6 +104,24 @@ impl ParseCallbacks for MacroCallback { } } + fn item_name(&self, original_item_name: &str) -> Option { + if original_item_name.starts_with("my_prefixed_") { + Some( + original_item_name + .trim_start_matches("my_prefixed_") + .to_string(), + ) + } else if original_item_name.starts_with("MY_PREFIXED_") { + Some( + original_item_name + .trim_start_matches("MY_PREFIXED_") + .to_string(), + ) + } else { + None + } + } + // Test the "custom derives" capability by adding `PartialEq` to the `Test` struct. fn add_derives(&self, info: &DeriveInfo<'_>) -> Vec { if info.name == "Test" { @@ -149,7 +149,7 @@ impl Drop for MacroCallback { } } -fn main() { +fn setup_macro_test() { cc::Build::new() .cpp(true) .file("cpp/Test.cc") @@ -204,3 +204,75 @@ fn main() { "including stub via include dir must produce correct dep path", ); } + +fn setup_wrap_static_fns_test() { + // GH-1090: https://github.com/rust-lang/rust-bindgen/issues/1090 + // set output directory under /target so it is easy to clean generated files + let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); + let out_rust_file = out_path.join("extern.rs"); + + let input_header_dir = PathBuf::from("../bindgen-tests/tests/headers/") + .canonicalize() + .expect("Cannot canonicalize libdir path"); + let input_header_file_path = input_header_dir.join("wrap-static-fns.h"); + let input_header_file_path_str = input_header_file_path + .to_str() + .expect("Path could not be converted to a str"); + + // generate external bindings with the external .c and .h files + let bindings = Builder::default() + .header(input_header_file_path_str) + .parse_callbacks(Box::new(CargoCallbacks)) + .wrap_static_fns(true) + .wrap_static_fns_path( + out_path.join("wrap_static_fns").display().to_string(), + ) + .generate() + .expect("Unable to generate bindings"); + + println!("cargo:rustc-link-lib=static=wrap_static_fns"); // tell cargo to link libextern + println!("bindings generated: {}", bindings); + + let obj_path = out_path.join("wrap_static_fns.o"); + let lib_path = out_path.join("libwrap_static_fns.a"); + + // build the external files to check if they work + let clang_output = std::process::Command::new("clang") + .arg("-c") + .arg("-o") + .arg(&obj_path) + .arg(out_path.join("wrap_static_fns.c")) + .arg("-include") + .arg(input_header_file_path) + .output() + .expect("`clang` command error"); + if !clang_output.status.success() { + panic!( + "Could not compile object file:\n{}", + String::from_utf8_lossy(&clang_output.stderr) + ); + } + + let ar_output = std::process::Command::new("ar") + .arg("rcs") + .arg(lib_path) + .arg(obj_path) + .output() + .expect("`ar` command error"); + + if !ar_output.status.success() { + panic!( + "Could not emit library file:\n{}", + String::from_utf8_lossy(&ar_output.stderr) + ); + } + + bindings + .write_to_file(out_rust_file) + .expect("Cound not write bindings to the Rust file"); +} + +fn main() { + setup_macro_test(); + setup_wrap_static_fns_test(); +} diff --git a/bindgen-integration/src/lib.rs b/bindgen-integration/src/lib.rs index 43f71580d2..e89351c3b3 100755 --- a/bindgen-integration/src/lib.rs +++ b/bindgen-integration/src/lib.rs @@ -4,6 +4,10 @@ mod bindings { include!(concat!(env!("OUT_DIR"), "/test.rs")); } +mod extern_bindings { + include!(concat!(env!("OUT_DIR"), "/extern.rs")); +} + use std::ffi::CStr; use std::mem; use std::os::raw::c_int; @@ -286,3 +290,35 @@ fn test_custom_derive() { assert!(meter < lightyear); assert!(meter > micron); } + +#[test] +fn test_wrap_static_fns() { + // GH-1090: https://github.com/rust-lang/rust-bindgen/issues/1090 + unsafe { + let f = extern_bindings::foo(); + assert_eq!(11, f); + + let b = extern_bindings::bar(); + assert_eq!(1, b); + + let t = extern_bindings::takes_ptr(&mut 1); + assert_eq!(2, t); + + extern "C" fn function(x: i32) -> i32 { + x + 1 + } + + let tp = extern_bindings::takes_fn_ptr(Some(function)); + assert_eq!(2, tp); + + let tf = extern_bindings::takes_fn(Some(function)); + assert_eq!(3, tf); + + let ta = extern_bindings::takes_alias(Some(function)); + assert_eq!(4, ta); + + let tq = + extern_bindings::takes_qualified(&(&5 as *const _) as *const _); + assert_eq!(5, tq); + } +} diff --git a/bindgen-tests/Cargo.toml b/bindgen-tests/Cargo.toml index 0678274fd6..6df84e8e9b 100644 --- a/bindgen-tests/Cargo.toml +++ b/bindgen-tests/Cargo.toml @@ -5,7 +5,7 @@ version = "0.1.0" publish = false [dev-dependencies] -bindgen = { path = "../bindgen", features = ["cli"] } +bindgen = { path = "../bindgen", features = ["cli", "experimental"] } diff = "0.1" shlex = "1" clap = { version = "4", features = ["derive"] } diff --git a/bindgen-tests/tests/expectations/tests/generated/README.md b/bindgen-tests/tests/expectations/tests/generated/README.md new file mode 100644 index 0000000000..b4e8cabbf6 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/generated/README.md @@ -0,0 +1,4 @@ +# Generated C, C++, Header files + +This directory contains files for features where extra files are generated +as a part of the feature. For example, `--wrap-static-fns`. diff --git a/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c b/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c new file mode 100644 index 0000000000..22b2f67f75 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c @@ -0,0 +1,14 @@ +int foo__extern(void) asm("foo__extern"); +int foo__extern() { return foo(); } +int bar__extern(void) asm("bar__extern"); +int bar__extern() { return bar(); } +int takes_ptr__extern(int *arg) asm("takes_ptr__extern"); +int takes_ptr__extern(int *arg) { return takes_ptr(arg); } +int takes_fn_ptr__extern(int (*f) (int)) asm("takes_fn_ptr__extern"); +int takes_fn_ptr__extern(int (*f) (int)) { return takes_fn_ptr(f); } +int takes_fn__extern(int (f) (int)) asm("takes_fn__extern"); +int takes_fn__extern(int (f) (int)) { return takes_fn(f); } +int takes_alias__extern(func f) asm("takes_alias__extern"); +int takes_alias__extern(func f) { return takes_alias(f); } +int takes_qualified__extern(const int *const *arg) asm("takes_qualified__extern"); +int takes_qualified__extern(const int *const *arg) { return takes_qualified(arg); } diff --git a/bindgen-tests/tests/expectations/tests/wrap-static-fns.rs b/bindgen-tests/tests/expectations/tests/wrap-static-fns.rs new file mode 100644 index 0000000000..54ed9fd4dd --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/wrap-static-fns.rs @@ -0,0 +1,52 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +extern "C" { + #[link_name = "\u{1}foo__extern"] + pub fn foo() -> ::std::os::raw::c_int; +} +extern "C" { + #[link_name = "\u{1}bar__extern"] + pub fn bar() -> ::std::os::raw::c_int; +} +extern "C" { + #[link_name = "\u{1}takes_ptr__extern"] + pub fn takes_ptr(arg: *mut ::std::os::raw::c_int) -> ::std::os::raw::c_int; +} +extern "C" { + #[link_name = "\u{1}takes_fn_ptr__extern"] + pub fn takes_fn_ptr( + f: ::std::option::Option< + unsafe extern "C" fn( + arg1: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + ) -> ::std::os::raw::c_int; +} +extern "C" { + #[link_name = "\u{1}takes_fn__extern"] + pub fn takes_fn( + f: ::std::option::Option< + unsafe extern "C" fn( + arg1: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int, + >, + ) -> ::std::os::raw::c_int; +} +pub type func = ::std::option::Option< + unsafe extern "C" fn(arg1: ::std::os::raw::c_int) -> ::std::os::raw::c_int, +>; +extern "C" { + #[link_name = "\u{1}takes_alias__extern"] + pub fn takes_alias(f: func) -> ::std::os::raw::c_int; +} +extern "C" { + #[link_name = "\u{1}takes_qualified__extern"] + pub fn takes_qualified( + arg: *const *const ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} diff --git a/bindgen-tests/tests/headers/wrap-static-fns.h b/bindgen-tests/tests/headers/wrap-static-fns.h new file mode 100644 index 0000000000..8b90c7bc38 --- /dev/null +++ b/bindgen-tests/tests/headers/wrap-static-fns.h @@ -0,0 +1,33 @@ +// bindgen-flags: --experimental --wrap-static-fns + +static inline int foo() { + return 11; +} +static int bar() { + return 1; +} +inline int baz() { + return 2; +} + +static inline int takes_ptr(int* arg) { + return *arg + 1; +} + +static inline int takes_fn_ptr(int (*f)(int)) { + return f(1); +} + +static inline int takes_fn(int (f)(int)) { + return f(2); +} + +typedef int (func)(int); + +static inline int takes_alias(func f) { + return f(3); +} + +static inline int takes_qualified(const int *const *arg) { + return **arg; +} diff --git a/bindgen-tests/tests/tests.rs b/bindgen-tests/tests/tests.rs index 25c073cc84..ed8566c607 100644 --- a/bindgen-tests/tests/tests.rs +++ b/bindgen-tests/tests/tests.rs @@ -713,3 +713,40 @@ fn commandline_multiple_headers() { .header("tests/headers/16-byte-alignment.h"); build_flags_output_helper(&bindings); } + +#[test] +fn test_wrap_static_fns() { + // This test is for testing diffs of the generated C source and header files + // TODO: If another such feature is added, convert this test into a more generic + // test that looks at `tests/headers/generated` directory. + let expect_path = PathBuf::from("tests/expectations/tests/generated") + .join("wrap_static_fns"); + println!("In path is ::: {}", expect_path.display()); + + let generated_path = + PathBuf::from(env::var("OUT_DIR").unwrap()).join("wrap_static_fns"); + println!("Out path is ::: {}", generated_path.display()); + + let _bindings = Builder::default() + .header("tests/headers/wrap-static-fns.h") + .wrap_static_fns(true) + .wrap_static_fns_path(generated_path.display().to_string()) + .generate() + .expect("Failed to generate bindings"); + + let expected_c = fs::read_to_string(expect_path.with_extension("c")) + .expect("Could not read generated wrap_static_fns.c"); + + let actual_c = fs::read_to_string(generated_path.with_extension("c")) + .expect("Could not read actual wrap_static_fns.c"); + + if expected_c != actual_c { + error_diff_mismatch( + &actual_c, + &expected_c, + None, + &expect_path.with_extension("c"), + ) + .unwrap(); + } +} diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index 2292a5efe4..6d4902d452 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -48,6 +48,7 @@ runtime = ["clang-sys/runtime"] # Dynamically discover a `rustfmt` binary using the `which` crate which-rustfmt = ["which"] cli = [] +experimental = [] # These features only exist for CI testing -- don't use them if you're not hacking # on bindgen! diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 6b24ae1bd0..b6fb70eb01 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -4,6 +4,7 @@ mod helpers; mod impl_debug; mod impl_partialeq; mod postprocessing; +mod serialize; pub mod struct_layout; #[cfg(test)] @@ -59,6 +60,29 @@ use std::iter; use std::ops; use std::str::FromStr; +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub enum CodegenError { + Serialize { msg: String, loc: String }, + Io(String), +} + +impl From for CodegenError { + fn from(err: std::io::Error) -> Self { + Self::Io(err.to_string()) + } +} + +impl std::fmt::Display for CodegenError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + CodegenError::Serialize { msg, loc } => { + write!(f, "serialization error at {}: {}", loc, msg) + } + CodegenError::Io(err) => err.fmt(f), + } + } +} + // Name of type defined in constified enum module pub static CONSTIFIED_ENUM_MODULE_REPR_NAME: &str = "Type"; @@ -241,6 +265,8 @@ struct CodegenResult<'a> { /// function name to the number of overloads we have already codegen'd for /// that name. This lets us give each overload a unique suffix. overload_counters: HashMap, + + items_to_serialize: Vec, } impl<'a> CodegenResult<'a> { @@ -258,6 +284,7 @@ impl<'a> CodegenResult<'a> { functions_seen: Default::default(), vars_seen: Default::default(), overload_counters: Default::default(), + items_to_serialize: Default::default(), } } @@ -4000,11 +4027,16 @@ impl CodeGenerator for Function { debug!("::codegen: item = {:?}", item); debug_assert!(item.is_enabled_for_codegen(ctx)); - // We can't currently do anything with Internal functions so just - // avoid generating anything for them. - match self.linkage() { - Linkage::Internal => return None, - Linkage::External => {} + let is_internal = matches!(self.linkage(), Linkage::Internal); + + if is_internal { + if ctx.options().wrap_static_fns { + result.items_to_serialize.push(item.id()); + } else { + // We can't do anything with Internal functions if we are not wrapping them so just + // avoid generating anything for them. + return None; + } } // Pure virtual methods have no actual symbol, so we can't generate @@ -4114,6 +4146,7 @@ impl CodeGenerator for Function { write!(&mut canonical_name, "{}", times_seen).unwrap(); } + let mut has_link_name_attr = false; let link_name = mangled_name.unwrap_or(name); if !is_dynamic_function && !utils::names_will_be_identical_after_mangling( @@ -4123,6 +4156,7 @@ impl CodeGenerator for Function { ) { attributes.push(attributes::link_name(link_name)); + has_link_name_attr = true; } // Unfortunately this can't piggyback on the `attributes` list because @@ -4133,6 +4167,11 @@ impl CodeGenerator for Function { quote! { #[link(wasm_import_module = #name)] } }); + if is_internal && ctx.options().wrap_static_fns && !has_link_name_attr { + let name = canonical_name.clone() + ctx.wrap_static_fns_suffix(); + attributes.push(attributes::link_name(&name)); + } + let ident = ctx.rust_ident(canonical_name); let tokens = quote! { #wasm_link_attribute @@ -4437,7 +4476,8 @@ impl CodeGenerator for ObjCInterface { pub(crate) fn codegen( context: BindgenContext, -) -> (proc_macro2::TokenStream, BindgenOptions, Vec) { +) -> Result<(proc_macro2::TokenStream, BindgenOptions, Vec), CodegenError> +{ context.gen(|context| { let _t = context.timer("codegen"); let counter = Cell::new(0); @@ -4487,21 +4527,73 @@ pub(crate) fn codegen( result.push(dynamic_items_tokens); } - postprocessing::postprocessing(result.items, context.options()) + utils::serialize_items(&result, context)?; + + Ok(postprocessing::postprocessing( + result.items, + context.options(), + )) }) } pub mod utils { - use super::{error, ToRustTyOrOpaque}; + use super::serialize::CSerialize; + use super::{error, CodegenError, CodegenResult, ToRustTyOrOpaque}; use crate::ir::context::BindgenContext; use crate::ir::function::{Abi, ClangAbi, FunctionSig}; use crate::ir::item::{Item, ItemCanonicalPath}; use crate::ir::ty::TypeKind; + use crate::{args_are_cpp, file_is_cpp}; use proc_macro2; use std::borrow::Cow; use std::mem; + use std::path::PathBuf; use std::str::FromStr; + pub(super) fn serialize_items( + result: &CodegenResult, + context: &BindgenContext, + ) -> Result<(), CodegenError> { + if result.items_to_serialize.is_empty() { + return Ok(()); + } + + let path = context + .options() + .wrap_static_fns_path + .as_ref() + .map(PathBuf::from) + .unwrap_or_else(|| { + std::env::temp_dir().join("bindgen").join("extern") + }); + + let dir = path.parent().unwrap(); + + if !dir.exists() { + std::fs::create_dir_all(&dir)?; + } + + let is_cpp = args_are_cpp(&context.options().clang_args) || + context + .options() + .input_headers + .iter() + .any(|h| file_is_cpp(h)); + + let source_path = path.with_extension(if is_cpp { "cpp" } else { "c" }); + + let mut code = Vec::new(); + + for &id in &result.items_to_serialize { + let item = context.resolve_item(id); + item.serialize(context, (), &mut vec![], &mut code)?; + } + + std::fs::write(source_path, code)?; + + Ok(()) + } + pub fn prepend_bitfield_unit_type( ctx: &BindgenContext, result: &mut Vec, diff --git a/bindgen/codegen/serialize.rs b/bindgen/codegen/serialize.rs new file mode 100644 index 0000000000..217098e590 --- /dev/null +++ b/bindgen/codegen/serialize.rs @@ -0,0 +1,356 @@ +use std::io::Write; + +use crate::callbacks::IntKind; + +use crate::ir::comp::CompKind; +use crate::ir::context::{BindgenContext, TypeId}; +use crate::ir::function::{Function, FunctionKind}; +use crate::ir::item::Item; +use crate::ir::item::ItemCanonicalName; +use crate::ir::item_kind::ItemKind; +use crate::ir::ty::{FloatKind, Type, TypeKind}; + +use super::CodegenError; + +fn get_loc(item: &Item) -> String { + item.location() + .map(|x| x.to_string()) + .unwrap_or_else(|| "unknown".to_owned()) +} + +pub(crate) trait CSerialize<'a> { + type Extra; + + fn serialize( + &self, + ctx: &BindgenContext, + extra: Self::Extra, + stack: &mut Vec, + writer: &mut W, + ) -> Result<(), CodegenError>; +} + +impl<'a> CSerialize<'a> for Item { + type Extra = (); + + fn serialize( + &self, + ctx: &BindgenContext, + (): Self::Extra, + stack: &mut Vec, + writer: &mut W, + ) -> Result<(), CodegenError> { + match self.kind() { + ItemKind::Function(func) => { + func.serialize(ctx, self, stack, writer) + } + kind => { + return Err(CodegenError::Serialize { + msg: format!("Cannot serialize item kind {:?}", kind), + loc: get_loc(self), + }); + } + } + } +} + +impl<'a> CSerialize<'a> for Function { + type Extra = &'a Item; + + fn serialize( + &self, + ctx: &BindgenContext, + item: Self::Extra, + stack: &mut Vec, + writer: &mut W, + ) -> Result<(), CodegenError> { + if self.kind() != FunctionKind::Function { + return Err(CodegenError::Serialize { + msg: format!( + "Cannot serialize function kind {:?}", + self.kind(), + ), + loc: get_loc(item), + }); + } + + let signature = match ctx.resolve_type(self.signature()).kind() { + TypeKind::Function(signature) => signature, + _ => unreachable!(), + }; + + let name = self.name(); + + // Function argoments stored as `(name, type_id)` tuples. + let args = { + let mut count = 0; + + signature + .argument_types() + .iter() + .cloned() + .map(|(opt_name, type_id)| { + ( + opt_name.unwrap_or_else(|| { + let name = format!("arg_{}", count); + count += 1; + name + }), + type_id, + ) + }) + .collect::>() + }; + + // The name used for the wrapper self. + let wrap_name = format!("{}{}", name, ctx.wrap_static_fns_suffix()); + // The function's return type + let ret_ty = signature.return_type(); + + // Write `ret_ty wrap_name(args) asm("wrap_name");` + ret_ty.serialize(ctx, (), stack, writer)?; + write!(writer, " {}(", wrap_name)?; + if args.is_empty() { + write!(writer, "void")?; + } else { + serialize_sep( + ", ", + args.iter(), + ctx, + writer, + |(name, type_id), ctx, buf| { + type_id.serialize(ctx, (), &mut vec![name.clone()], buf) + }, + )?; + } + writeln!(writer, ") asm(\"{}\");", wrap_name)?; + + // Write `ret_ty wrap_name(args) { return name(arg_names)' }` + ret_ty.serialize(ctx, (), stack, writer)?; + write!(writer, " {}(", wrap_name)?; + serialize_sep( + ", ", + args.iter(), + ctx, + writer, + |(name, type_id), _, buf| { + type_id.serialize(ctx, (), &mut vec![name.clone()], buf) + }, + )?; + write!(writer, ") {{ return {}(", name)?; + serialize_sep(", ", args.iter(), ctx, writer, |(name, _), _, buf| { + write!(buf, "{}", name).map_err(From::from) + })?; + writeln!(writer, "); }}")?; + + Ok(()) + } +} + +impl<'a> CSerialize<'a> for TypeId { + type Extra = (); + + fn serialize( + &self, + ctx: &BindgenContext, + (): Self::Extra, + stack: &mut Vec, + writer: &mut W, + ) -> Result<(), CodegenError> { + let item = ctx.resolve_item(*self); + item.expect_type().serialize(ctx, item, stack, writer) + } +} + +impl<'a> CSerialize<'a> for Type { + type Extra = &'a Item; + + fn serialize( + &self, + ctx: &BindgenContext, + item: Self::Extra, + stack: &mut Vec, + writer: &mut W, + ) -> Result<(), CodegenError> { + match self.kind() { + TypeKind::Void => { + if self.is_const() { + write!(writer, "const ")?; + } + write!(writer, "void")? + } + TypeKind::NullPtr => { + if self.is_const() { + write!(writer, "const ")?; + } + write!(writer, "nullptr_t")? + } + TypeKind::Int(int_kind) => { + if self.is_const() { + write!(writer, "const ")?; + } + match int_kind { + IntKind::Bool => write!(writer, "bool")?, + IntKind::SChar => write!(writer, "signed char")?, + IntKind::UChar => write!(writer, "unsigned char")?, + IntKind::WChar => write!(writer, "wchar_t")?, + IntKind::Short => write!(writer, "short")?, + IntKind::UShort => write!(writer, "unsigned short")?, + IntKind::Int => write!(writer, "int")?, + IntKind::UInt => write!(writer, "unsigned int")?, + IntKind::Long => write!(writer, "long")?, + IntKind::ULong => write!(writer, "unsigned long")?, + IntKind::LongLong => write!(writer, "long long")?, + IntKind::ULongLong => write!(writer, "unsigned long long")?, + IntKind::Char { .. } => write!(writer, "char")?, + int_kind => { + return Err(CodegenError::Serialize { + msg: format!( + "Cannot serialize integer kind {:?}", + int_kind + ), + loc: get_loc(item), + }) + } + } + } + TypeKind::Float(float_kind) => { + if self.is_const() { + write!(writer, "const ")?; + } + match float_kind { + FloatKind::Float => write!(writer, "float")?, + FloatKind::Double => write!(writer, "double")?, + FloatKind::LongDouble => write!(writer, "long double")?, + FloatKind::Float128 => write!(writer, "__float128")?, + } + } + TypeKind::Complex(float_kind) => { + if self.is_const() { + write!(writer, "const ")?; + } + match float_kind { + FloatKind::Float => write!(writer, "float complex")?, + FloatKind::Double => write!(writer, "double complex")?, + FloatKind::LongDouble => { + write!(writer, "long double complex")? + } + FloatKind::Float128 => write!(writer, "__complex128")?, + } + } + TypeKind::Alias(type_id) => { + if let Some(name) = self.name() { + if self.is_const() { + write!(writer, "const {}", name)?; + } else { + write!(writer, "{}", name)?; + } + } else { + type_id.serialize(ctx, (), stack, writer)?; + } + } + TypeKind::Array(type_id, length) => { + type_id.serialize(ctx, (), stack, writer)?; + write!(writer, " [{}]", length)? + } + TypeKind::Function(signature) => { + if self.is_const() { + stack.push("const ".to_string()); + } + + signature.return_type().serialize( + ctx, + (), + &mut vec![], + writer, + )?; + + write!(writer, " (")?; + while let Some(item) = stack.pop() { + write!(writer, "{}", item)?; + } + write!(writer, ")")?; + + write!(writer, " (")?; + serialize_sep( + ", ", + signature.argument_types().iter(), + ctx, + writer, + |(name, type_id), ctx, buf| { + let mut stack = vec![]; + if let Some(name) = name { + stack.push(name.clone()); + } + type_id.serialize(ctx, (), &mut stack, buf) + }, + )?; + write!(writer, ")")? + } + TypeKind::ResolvedTypeRef(type_id) => { + if self.is_const() { + write!(writer, "const ")?; + } + type_id.serialize(ctx, (), stack, writer)? + } + TypeKind::Pointer(type_id) => { + if self.is_const() { + stack.push("*const ".to_owned()); + } else { + stack.push("*".to_owned()); + } + type_id.serialize(ctx, (), stack, writer)? + } + TypeKind::Comp(comp_info) => { + if self.is_const() { + write!(writer, "const ")?; + } + + let name = item.canonical_name(ctx); + + match comp_info.kind() { + CompKind::Struct => write!(writer, "struct {}", name)?, + CompKind::Union => write!(writer, "union {}", name)?, + }; + } + ty => { + return Err(CodegenError::Serialize { + msg: format!("Cannot serialize type kind {:?}", ty), + loc: get_loc(item), + }) + } + }; + + if !stack.is_empty() { + write!(writer, " ")?; + while let Some(item) = stack.pop() { + write!(writer, "{}", item)?; + } + } + + Ok(()) + } +} + +fn serialize_sep< + W: Write, + F: FnMut(I::Item, &BindgenContext, &mut W) -> Result<(), CodegenError>, + I: Iterator, +>( + sep: &str, + mut iter: I, + ctx: &BindgenContext, + buf: &mut W, + mut f: F, +) -> Result<(), CodegenError> { + if let Some(item) = iter.next() { + f(item, ctx, buf)?; + let sep = sep.as_bytes(); + for item in iter { + buf.write_all(sep)?; + f(item, ctx, buf)?; + } + } + + Ok(()) +} diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index c5df37d7e9..b693a7047e 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -20,6 +20,7 @@ use super::template::{TemplateInstantiation, TemplateParameters}; use super::traversal::{self, Edge, ItemTraversal}; use super::ty::{FloatKind, Type, TypeKind}; use crate::clang::{self, Cursor}; +use crate::codegen::CodegenError; use crate::BindgenOptions; use crate::{Entry, HashMap, HashSet}; use cexpr; @@ -1146,9 +1147,9 @@ If you encounter an error missing from this list, please file an issue or a PR!" pub(crate) fn gen( mut self, cb: F, - ) -> (Out, BindgenOptions, Vec) + ) -> Result<(Out, BindgenOptions, Vec), CodegenError> where - F: FnOnce(&Self) -> Out, + F: FnOnce(&Self) -> Result, { self.in_codegen = true; @@ -1183,8 +1184,8 @@ If you encounter an error missing from this list, please file an issue or a PR!" self.compute_cannot_derive_hash(); self.compute_cannot_derive_partialord_partialeq_or_eq(); - let ret = cb(&self); - (ret, self.options, self.warnings) + let ret = cb(&self)?; + Ok((ret, self.options, self.warnings)) } /// When the `testing_only_extra_assertions` feature is enabled, this @@ -2792,6 +2793,13 @@ If you encounter an error missing from this list, please file an issue or a PR!" tokens.into_token_stream() } } + + pub(crate) fn wrap_static_fns_suffix(&self) -> &str { + self.options() + .wrap_static_fns_suffix + .as_deref() + .unwrap_or(crate::DEFAULT_NON_EXTERN_FNS_SUFFIX) + } } /// A builder struct for configuring item resolution options. diff --git a/bindgen/ir/function.rs b/bindgen/ir/function.rs index 8e83d980bc..baa2c36ca4 100644 --- a/bindgen/ir/function.rs +++ b/bindgen/ir/function.rs @@ -664,7 +664,6 @@ impl ClangSubItemParser for Function { }; debug!("Function::parse({:?}, {:?})", cursor, cursor.cur_type()); - let visibility = cursor.visibility(); if visibility != CXVisibility_Default { return Err(ParseError::Continue); @@ -674,25 +673,36 @@ impl ClangSubItemParser for Function { return Err(ParseError::Continue); } + let linkage = cursor.linkage(); + let linkage = match linkage { + CXLinkage_External | CXLinkage_UniqueExternal => Linkage::External, + CXLinkage_Internal => Linkage::Internal, + _ => return Err(ParseError::Continue), + }; + if cursor.is_inlined_function() || cursor .definition() .map_or(false, |x| x.is_inlined_function()) { - if !context.options().generate_inline_functions { + if !context.options().generate_inline_functions && + !context.options().wrap_static_fns + { return Err(ParseError::Continue); } + if cursor.is_deleted_function() { return Err(ParseError::Continue); } - } - let linkage = cursor.linkage(); - let linkage = match linkage { - CXLinkage_External | CXLinkage_UniqueExternal => Linkage::External, - CXLinkage_Internal => Linkage::Internal, - _ => return Err(ParseError::Continue), - }; + // We cannot handle `inline` functions that are not `static`. + if context.options().wrap_static_fns && + cursor.is_inlined_function() && + matches!(linkage, Linkage::External) + { + return Err(ParseError::Continue); + } + } // Grab the signature using Item::from_ty. let sig = Item::from_ty(&cursor.cur_type(), cursor, None, context)?; @@ -727,7 +737,8 @@ impl ClangSubItemParser for Function { let comment = cursor.raw_comment(); let function = - Self::new(name, mangled_name, sig, comment, kind, linkage); + Self::new(name.clone(), mangled_name, sig, comment, kind, linkage); + Ok(ParseResult::New(function, Some(cursor))) } } diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 8c8ffe5c7d..5374742016 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -78,6 +78,7 @@ doc_mod!(ir, ir_docs); doc_mod!(parse, parse_docs); doc_mod!(regex_set, regex_set_docs); +use codegen::CodegenError; use ir::comment; pub use crate::codegen::{ @@ -108,6 +109,7 @@ pub(crate) use std::collections::hash_map::Entry; /// Default prefix for the anon fields. pub const DEFAULT_ANON_FIELDS_PREFIX: &str = "__bindgen_anon_"; +const DEFAULT_NON_EXTERN_FNS_SUFFIX: &str = "__extern"; fn file_is_cpp(name_file: &str) -> bool { name_file.ends_with(".hpp") || @@ -657,6 +659,23 @@ impl Builder { for callbacks in &self.options.parse_callbacks { output_vector.extend(callbacks.cli_args()); } + if self.options.wrap_static_fns { + output_vector.push("--wrap-static-fns".into()) + } + + if let Some(ref path) = self.options.wrap_static_fns_path { + output_vector.push("--wrap-static-fns-path".into()); + output_vector.push(path.display().to_string()); + } + + if let Some(ref suffix) = self.options.wrap_static_fns_suffix { + output_vector.push("--wrap-static-fns-suffix".into()); + output_vector.push(suffix.clone()); + } + + if cfg!(feature = "experimental") { + output_vector.push("--experimental".into()); + } // Add clang arguments @@ -1553,33 +1572,25 @@ impl Builder { } /// Generate the Rust bindings using the options built up thus far. - pub fn generate(self) -> Result { - let mut options = self.options.clone(); + pub fn generate(mut self) -> Result { // Add any extra arguments from the environment to the clang command line. - options.clang_args.extend(get_extra_clang_args()); + self.options.clang_args.extend(get_extra_clang_args()); // Transform input headers to arguments on the clang command line. - options.clang_args.extend( - options.input_headers - [..options.input_headers.len().saturating_sub(1)] + self.options.clang_args.extend( + self.options.input_headers + [..self.options.input_headers.len().saturating_sub(1)] .iter() .flat_map(|header| ["-include".into(), header.to_string()]), ); let input_unsaved_files = - std::mem::take(&mut options.input_header_contents) + std::mem::take(&mut self.options.input_header_contents) .into_iter() .map(|(name, contents)| clang::UnsavedFile::new(name, contents)) .collect::>(); - match Bindings::generate(options, input_unsaved_files) { - GenerateResult::Ok(bindings) => Ok(*bindings), - GenerateResult::ShouldRestart { header } => self - .header(header) - .generate_inline_functions(false) - .generate(), - GenerateResult::Err(err) => Err(err), - } + Bindings::generate(self.options, input_unsaved_files) } /// Preprocess and dump the input header files to disk. @@ -1796,6 +1807,32 @@ impl Builder { self.options.wrap_unsafe_ops = doit; self } + + #[cfg(feature = "experimental")] + /// Whether to generate extern wrappers for `static` and `static inline` functions. Defaults to + /// false. + pub fn wrap_static_fns(mut self, doit: bool) -> Self { + self.options.wrap_static_fns = doit; + self + } + + #[cfg(feature = "experimental")] + /// Set the path for the source code file that would be created if any wrapper functions must + /// be generated due to the presence of static functions. + /// + /// Bindgen will automatically add the right extension to the header and source code files. + pub fn wrap_static_fns_path>(mut self, path: T) -> Self { + self.options.wrap_static_fns_path = Some(path.as_ref().to_owned()); + self + } + + #[cfg(feature = "experimental")] + /// Set the suffix added to the extern wrapper functions generated for `static` and `static + /// inline` functions. + pub fn wrap_static_fns_suffix>(mut self, suffix: T) -> Self { + self.options.wrap_static_fns_suffix = Some(suffix.as_ref().to_owned()); + self + } } /// Configuration options for generated bindings. @@ -2136,6 +2173,12 @@ struct BindgenOptions { /// Whether to wrap unsafe operations in unsafe blocks or not. wrap_unsafe_ops: bool, + + wrap_static_fns: bool, + + wrap_static_fns_suffix: Option, + + wrap_static_fns_path: Option, } impl BindgenOptions { @@ -2328,6 +2371,9 @@ impl Default for BindgenOptions { merge_extern_blocks, abi_overrides, wrap_unsafe_ops, + wrap_static_fns, + wrap_static_fns_suffix, + wrap_static_fns_path, } } } @@ -2358,18 +2404,6 @@ fn ensure_libclang_is_loaded() { #[cfg(not(feature = "runtime"))] fn ensure_libclang_is_loaded() {} -#[derive(Debug)] -enum GenerateResult { - Ok(Box), - /// Error variant raised when bindgen requires to run again with a newly generated header - /// input. - #[allow(dead_code)] - ShouldRestart { - header: String, - }, - Err(BindgenError), -} - /// Error type for rust-bindgen. #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[non_exhaustive] @@ -2382,6 +2416,8 @@ pub enum BindgenError { NotExist(PathBuf), /// Clang diagnosed an error. ClangDiagnostic(String), + /// Code generation reported an error. + Codegen(CodegenError), } impl std::fmt::Display for BindgenError { @@ -2399,6 +2435,9 @@ impl std::fmt::Display for BindgenError { BindgenError::ClangDiagnostic(message) => { write!(f, "clang diagnosed error: {}", message) } + BindgenError::Codegen(err) => { + write!(f, "codegen error: {}", err) + } } } } @@ -2472,7 +2511,7 @@ impl Bindings { pub(crate) fn generate( mut options: BindgenOptions, input_unsaved_files: Vec, - ) -> GenerateResult { + ) -> Result { ensure_libclang_is_loaded(); #[cfg(feature = "runtime")] @@ -2593,21 +2632,17 @@ impl Bindings { let path = Path::new(h); if let Ok(md) = std::fs::metadata(path) { if md.is_dir() { - return GenerateResult::Err(BindgenError::FolderAsHeader( - path.into(), - )); + return Err(BindgenError::FolderAsHeader(path.into())); } if !can_read(&md.permissions()) { - return GenerateResult::Err( - BindgenError::InsufficientPermissions(path.into()), - ); + return Err(BindgenError::InsufficientPermissions( + path.into(), + )); } let h = h.clone(); options.clang_args.push(h); } else { - return GenerateResult::Err(BindgenError::NotExist( - path.into(), - )); + return Err(BindgenError::NotExist(path.into())); } } @@ -2635,18 +2670,17 @@ impl Bindings { { let _t = time::Timer::new("parse").with_output(time_phases); - if let Err(err) = parse(&mut context) { - return GenerateResult::Err(err); - } + parse(&mut context)?; } - let (module, options, warnings) = codegen::codegen(context); + let (module, options, warnings) = + codegen::codegen(context).map_err(BindgenError::Codegen)?; - GenerateResult::Ok(Box::new(Bindings { + Ok(Bindings { options, warnings, module, - })) + }) } /// Write these bindings as source text to a file. From ae6817256ac557981906e93a1f866349db85053e Mon Sep 17 00:00:00 2001 From: Justin W Smith <103147162+justsmth@users.noreply.github.com> Date: Tue, 7 Feb 2023 10:36:50 -0500 Subject: [PATCH 446/942] Release 0.64.0 Request (#2399) Prepare 0.64.0 Release --------- Co-authored-by: Christian Poveda --- CHANGELOG.md | 171 +++++++++++++++------------ CONTRIBUTING.md | 7 +- Cargo.lock | 254 +++++++++++++++++------------------------ bindgen-cli/Cargo.toml | 4 +- bindgen/Cargo.toml | 2 +- 5 files changed, 211 insertions(+), 227 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a7723ccd03..d901bab1e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,147 +7,153 @@ - [Removed](#removed) - [Fixed](#fixed) - [Security](#security) -- [0.63.0](#0630) +- [0.64.0](#0640) - [Added](#added-1) - [Changed](#changed-1) - [Removed](#removed-1) -- [0.62.0](#0620) + - [Fixed](#fixed-1) + - [Security](#security-1) +- [0.63.0](#0630) - [Added](#added-2) - [Changed](#changed-2) - - [Fixed](#fixed-1) -- [0.61.0](#0610) + - [Removed](#removed-2) +- [0.62.0](#0620) - [Added](#added-3) - [Changed](#changed-3) - [Fixed](#fixed-2) -- [0.60.1](#0601) - - [Fixed](#fixed-3) -- [0.60.0](#0600) +- [0.61.0](#0610) - [Added](#added-4) - - [Fixed](#fixed-4) - [Changed](#changed-4) - - [Removed](#removed-2) + - [Fixed](#fixed-3) +- [0.60.1](#0601) + - [Fixed](#fixed-4) +- [0.60.0](#0600) + - [Added](#added-5) + - [Fixed](#fixed-5) + - [Changed](#changed-5) + - [Removed](#removed-3) - [0.59.2](#0592) - [0.59.1](#0591) - - [Fixed](#fixed-5) -- [0.59.0](#0590) - - [Added](#added-5) - [Fixed](#fixed-6) - - [Changed](#changed-5) -- [0.58.1](#0581) +- [0.59.0](#0590) - [Added](#added-6) -- [0.58.0](#0580) - - [Added](#added-7) - [Fixed](#fixed-7) - [Changed](#changed-6) - - [Deprecated](#deprecated) - - [Removed](#removed-3) - - [Fixed](#fixed-8) - - [Security](#security-1) -- [0.57.0](#0570) +- [0.58.1](#0581) + - [Added](#added-7) +- [0.58.0](#0580) - [Added](#added-8) + - [Fixed](#fixed-8) + - [Changed](#changed-7) + - [Deprecated](#deprecated) + - [Removed](#removed-4) - [Fixed](#fixed-9) -- [0.56.0](#0560) + - [Security](#security-2) +- [0.57.0](#0570) - [Added](#added-9) - - [Changed](#changed-7) - [Fixed](#fixed-10) -- [0.55.1](#0551) - - [Fixed](#fixed-11) -- [0.55.0](#0550) - - [Removed](#removed-4) +- [0.56.0](#0560) - [Added](#added-10) - [Changed](#changed-8) + - [Fixed](#fixed-11) +- [0.55.1](#0551) - [Fixed](#fixed-12) -- [0.54.1](#0541) +- [0.55.0](#0550) + - [Removed](#removed-5) - [Added](#added-11) - [Changed](#changed-9) - [Fixed](#fixed-13) -- [0.54.0](#0540) +- [0.54.1](#0541) - [Added](#added-12) - [Changed](#changed-10) - [Fixed](#fixed-14) -- [0.53.3](#0533) +- [0.54.0](#0540) - [Added](#added-13) + - [Changed](#changed-11) - [Fixed](#fixed-15) +- [0.53.3](#0533) + - [Added](#added-14) + - [Fixed](#fixed-16) - [0.53.2](#0532) - - [Changed](#changed-11) + - [Changed](#changed-12) - [0.53.1](#0531) - - [Added](#added-14) -- [0.53.0](#0530) - [Added](#added-15) - - [Changed](#changed-12) - - [Fixed](#fixed-16) -- [0.52.0](#0520) +- [0.53.0](#0530) - [Added](#added-16) - [Changed](#changed-13) - [Fixed](#fixed-17) -- [0.51.1](#0511) - - [Fixed](#fixed-18) +- [0.52.0](#0520) + - [Added](#added-17) - [Changed](#changed-14) -- [0.51.0](#0510) + - [Fixed](#fixed-18) +- [0.51.1](#0511) - [Fixed](#fixed-19) - [Changed](#changed-15) - - [Added](#added-17) -- [0.50.0](#0500) +- [0.51.0](#0510) + - [Fixed](#fixed-20) + - [Changed](#changed-16) - [Added](#added-18) -- [0.49.3](#0493) +- [0.50.0](#0500) - [Added](#added-19) +- [0.49.3](#0493) + - [Added](#added-20) - [0.49.2](#0492) - - [Changed](#changed-16) -- [0.49.1](#0491) - - [Fixed](#fixed-20) - [Changed](#changed-17) -- [0.49.0](#0490) - - [Added](#added-20) +- [0.49.1](#0491) - [Fixed](#fixed-21) - [Changed](#changed-18) -- [0.48.1](#0481) +- [0.49.0](#0490) + - [Added](#added-21) - [Fixed](#fixed-22) -- [0.48.0](#0480) - [Changed](#changed-19) +- [0.48.1](#0481) - [Fixed](#fixed-23) -- [0.47.4](#0474) - - [Added](#added-21) -- [0.47.3](#0473) +- [0.48.0](#0480) - [Changed](#changed-20) -- [0.47.2](#0472) - [Fixed](#fixed-24) -- [0.47.1](#0471) +- [0.47.4](#0474) + - [Added](#added-22) +- [0.47.3](#0473) - [Changed](#changed-21) +- [0.47.2](#0472) - [Fixed](#fixed-25) -- [0.47.0](#0470) +- [0.47.1](#0471) - [Changed](#changed-22) - [Fixed](#fixed-26) -- [0.33.1 .. 0.46.0](#0331--0460) - - [Added](#added-22) - - [Removed](#removed-5) +- [0.47.0](#0470) - [Changed](#changed-23) - [Fixed](#fixed-27) -- [0.33.1](#0331) +- [0.33.1 .. 0.46.0](#0331--0460) + - [Added](#added-23) + - [Removed](#removed-6) + - [Changed](#changed-24) - [Fixed](#fixed-28) +- [0.33.1](#0331) + - [Fixed](#fixed-29) - [0.33.0](#0330) - [0.32.2](#0322) - - [Fixed](#fixed-29) -- [0.32.1](#0321) - [Fixed](#fixed-30) -- [0.32.0](#0320) - - [Added](#added-23) - - [Changed](#changed-24) +- [0.32.1](#0321) - [Fixed](#fixed-31) -- [0.31.0](#0310) +- [0.32.0](#0320) - [Added](#added-24) - [Changed](#changed-25) - - [Deprecated](#deprecated-1) - - [Removed](#removed-6) - [Fixed](#fixed-32) -- [0.30.0](#0300) +- [0.31.0](#0310) - [Added](#added-25) - [Changed](#changed-26) - - [Deprecated](#deprecated-2) + - [Deprecated](#deprecated-1) + - [Removed](#removed-7) - [Fixed](#fixed-33) -- [0.29.0](#0290) +- [0.30.0](#0300) - [Added](#added-26) - [Changed](#changed-27) + - [Deprecated](#deprecated-2) - [Fixed](#fixed-34) +- [0.29.0](#0290) + - [Added](#added-27) + - [Changed](#changed-28) + - [Fixed](#fixed-35) @@ -157,6 +163,28 @@ ## Added +## Changed + +## Removed + +## Fixed + +## Security + +# 0.64.0 + +## Added + * Added a new set of flags `--with-derive-custom`, + `--with-derive-custom-struct`, `--with-derive-custom-enum` and + `--with-derive-custom-enum` to add custom derives from the CLI. + * Added the `--experimental` flag on `bindgen-cli` and the `experimental` + feature on `bindgen` to gate experimental features whose implementation is + incomplete or are prone to change in a non-backwards compatible manner. + * Added a new set of flags and their equivalent builder methods + `--wrap-static-fns`, `--wrap-static-fns-suffix` and `--wrap-static-fns-path` + to generate C function wrappers for `static` or `static inline` functions. + This feature is experimental. + ## Changed * Fixed name collisions when having a C `enum` and a `typedef` with the same name. @@ -169,9 +197,6 @@ behavior changes. * The `ParseCallbacks::add_derives` method now receives `DeriveInfo<'_>` as argument instead of a `&str`. This type also includes the kind of target type. - * Added a new set of flags `--with-derive-custom`, - `--with-derive-custom-struct`, `--with-derive-custom-enum` and - `--with-derive-custom-enum` to add custom derives from the CLI. ## Removed diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index af7a62321a..6189619da8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -8,7 +8,6 @@ and introduce yourself. - - [Code of Conduct](#code-of-conduct) - [Filing an Issue](#filing-an-issue) - [Looking to Start Contributing to `bindgen`?](#looking-to-start-contributing-to-bindgen) @@ -24,6 +23,7 @@ and introduce yourself. - [Fuzzing `bindgen` with `csmith`](#fuzzing-bindgen-with-csmith) - [Property tests for `bindgen` with `quickchecking`](#property-tests-for-bindgen-with-quickchecking) - [Code Overview](#code-overview) + - [Implementing new options using `syn`](#implementing-new-options-using-syn) - [Pull Requests and Code Reviews](#pull-requests-and-code-reviews) - [Generating Graphviz Dot Files](#generating-graphviz-dot-files) - [Debug Logging](#debug-logging) @@ -31,6 +31,11 @@ and introduce yourself. - [Getting `creduce`](#getting-creduce) - [Isolating Your Test Case](#isolating-your-test-case) - [Writing a Predicate Script](#writing-a-predicate-script) +- [Cutting a new bindgen release](#cutting-a-new-bindgen-release) + - [Updating the changelog](#updating-the-changelog) + - [Bumping the version numbers.](#bumping-the-version-numbers) + - [Merge to `main`](#merge-to-main) + - [Publish and add a git tag for the right commit](#publish-and-add-a-git-tag-for-the-right-commit) diff --git a/Cargo.lock b/Cargo.lock index b6a3a8d06c..5517f93dfa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,9 +13,9 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "0.7.18" +version = "0.7.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" dependencies = [ "memchr 2.5.0", ] @@ -42,18 +42,18 @@ dependencies = [ [[package]] name = "bindgen" -version = "0.63.0" +version = "0.64.0" dependencies = [ "bitflags", "cexpr", "clang-sys", "lazy_static", "lazycell", - "log 0.4.14", + "log 0.4.17", "peeking_take_while", "proc-macro2", "quote", - "regex 1.5.5", + "regex 1.7.1", "rustc-hash", "shlex", "syn", @@ -62,12 +62,12 @@ dependencies = [ [[package]] name = "bindgen-cli" -version = "0.63.0" +version = "0.64.0" dependencies = [ "bindgen", - "clap 4.0.32", - "env_logger 0.9.0", - "log 0.4.14", + "clap 4.1.4", + "env_logger 0.9.3", + "log 0.4.17", "shlex", ] @@ -84,7 +84,7 @@ name = "bindgen-tests" version = "0.1.0" dependencies = [ "bindgen", - "clap 4.0.32", + "clap 4.1.4", "diff", "shlex", "tempfile", @@ -104,9 +104,9 @@ checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" [[package]] name = "cc" -version = "1.0.73" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" +checksum = "a20104e2335ce8a659d6dd92a51a767a0c062599c73b343fd152cb401e828c3d" [[package]] name = "cexpr" @@ -131,7 +131,7 @@ checksum = "fa2e27ae6ab525c3d369ded447057bca5438d86dc3a68f6faafb8269ba82ebf3" dependencies = [ "glob", "libc", - "libloading 0.7.0", + "libloading 0.7.4", ] [[package]] @@ -151,9 +151,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.0.32" +version = "4.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7db700bc935f9e43e88d00b0850dae18a63773cfbec6d8e070fccf7fef89a39" +checksum = "f13b9c79b5d1dd500d20ef541215a6423c75829ef43117e1b4d17fd8af0b5d76" dependencies = [ "bitflags", "clap_derive", @@ -166,9 +166,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.0.21" +version = "4.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0177313f9f02afc995627906bbd8967e2be069f5261954222dac78290c2b9014" +checksum = "684a277d672e91966334af371f1a7b5833f9aa00b07c84e92fbce95e00208ce8" dependencies = [ "heck", "proc-macro-error", @@ -179,24 +179,24 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8" +checksum = "783fe232adfca04f90f56201b26d79682d4cd2625e0bc7290b95123afe558ade" dependencies = [ "os_str_bytes", ] [[package]] name = "diff" -version = "0.1.12" +version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e25ea47919b1560c4e3b7fe0aaab9becf5b84a10325ddf7db0f0ba5e1026499" +checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" [[package]] name = "either" -version = "1.6.1" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" +checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" [[package]] name = "env_logger" @@ -210,14 +210,14 @@ dependencies = [ [[package]] name = "env_logger" -version = "0.9.0" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3" +checksum = "a12e6657c4c97ebab115a42dcee77225f7f482cdd841cf7088c657a42e9e00e7" dependencies = [ "atty", "humantime", - "log 0.4.14", - "regex 1.5.5", + "log 0.4.17", + "regex 1.7.1", "termcolor", ] @@ -243,27 +243,25 @@ dependencies = [ ] [[package]] -name = "fuchsia-cprng" -version = "0.1.1" +name = "fastrand" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" +checksum = "a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499" +dependencies = [ + "instant", +] [[package]] -name = "getrandom" -version = "0.2.3" +name = "fuchsia-cprng" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] +checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" [[package]] name = "glob" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" [[package]] name = "heck" @@ -295,11 +293,20 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" +[[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if", +] + [[package]] name = "io-lifetimes" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46112a93252b123d31a119a8d1a1ac19deac4fac6e0e8b0df58f0d4e5870e63c" +checksum = "e7d6c6f8c91b4b9ed43484ad1a938e393caf35960fce7f82a040497207bd8e9e" dependencies = [ "libc", "windows-sys", @@ -357,9 +364,9 @@ dependencies = [ [[package]] name = "libloading" -version = "0.7.0" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f84d96438c15fcd6c3f244c8fce01d1e2b9c6b5623e9c711dc9286d8fc92d6a" +checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" dependencies = [ "cfg-if", "winapi 0.3.9", @@ -377,14 +384,14 @@ version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" dependencies = [ - "log 0.4.14", + "log 0.4.17", ] [[package]] name = "log" -version = "0.4.14" +version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ "cfg-if", ] @@ -415,19 +422,18 @@ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "minimal-lexical" -version = "0.1.4" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c64630dcdd71f1a64c435f54885086a0de5d6a12d104d69b165fb7d5286d677" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "nom" -version = "7.0.0" +version = "7.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ffd9d26838a953b4af82cbeb9f1592c6798916983959be223a7124e992742c1" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" dependencies = [ "memchr 2.5.0", "minimal-lexical", - "version_check", ] [[package]] @@ -447,9 +453,9 @@ checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" [[package]] name = "os_str_bytes" -version = "6.2.0" +version = "6.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "648001efe5d5c0102d8cea768e348da85d90af8ba91f0bea908f157951493cd4" +checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee" [[package]] name = "peeking_take_while" @@ -457,12 +463,6 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" -[[package]] -name = "ppv-lite86" -version = "0.2.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" - [[package]] name = "proc-macro-error" version = "1.0.4" @@ -489,9 +489,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.43" +version = "1.0.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab" +checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" dependencies = [ "unicode-ident", ] @@ -520,9 +520,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.9" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" +checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" dependencies = [ "proc-macro2", ] @@ -550,28 +550,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "rand" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8" -dependencies = [ - "libc", - "rand_chacha", - "rand_core 0.6.3", - "rand_hc", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core 0.6.3", -] - [[package]] name = "rand_core" version = "0.3.1" @@ -587,24 +565,6 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" -[[package]] -name = "rand_core" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" -dependencies = [ - "getrandom", -] - -[[package]] -name = "rand_hc" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7" -dependencies = [ - "rand_core 0.6.3", -] - [[package]] name = "rdrand" version = "0.4.0" @@ -616,9 +576,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.2.9" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ab49abadf3f9e1c4bc499e8845e152ad87d2ad2d30371841171169e9d75feee" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" dependencies = [ "bitflags", ] @@ -638,13 +598,13 @@ dependencies = [ [[package]] name = "regex" -version = "1.5.5" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a11647b6b25ff05a515cb92c365cec08801e83423a235b51e231e1808747286" +checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733" dependencies = [ - "aho-corasick 0.7.18", + "aho-corasick 0.7.20", "memchr 2.5.0", - "regex-syntax 0.6.25", + "regex-syntax 0.6.28", ] [[package]] @@ -655,9 +615,9 @@ checksum = "f9ec002c35e86791825ed294b50008eea9ddfc8def4420124fbc6b08db834957" [[package]] name = "regex-syntax" -version = "0.6.25" +version = "0.6.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" +checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" [[package]] name = "remove_dir_all" @@ -676,9 +636,9 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" [[package]] name = "rustix" -version = "0.36.6" +version = "0.36.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4feacf7db682c6c329c4ede12649cd36ecab0f3be5b7d74e6a20304725db4549" +checksum = "d4fdebc4b395b7fbb9ab11e462e20ed9051e7b16e42d24042c776eca0ac81b03" dependencies = [ "bitflags", "errno", @@ -690,9 +650,9 @@ dependencies = [ [[package]] name = "shlex" -version = "1.0.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42a568c8f2cd051a4d283bd6eb0343ac214c1b0f1ac19f93e1175b2dee38c73d" +checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" [[package]] name = "strsim" @@ -708,9 +668,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "1.0.99" +version = "1.0.107" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58dbef6ec655055e20b86b15a8cc6d439cca19b667537ac6a1369572d151ab13" +checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" dependencies = [ "proc-macro2", "quote", @@ -729,13 +689,13 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.2.0" +version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" +checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" dependencies = [ "cfg-if", + "fastrand", "libc", - "rand 0.8.4", "redox_syscall", "remove_dir_all", "winapi 0.3.9", @@ -743,9 +703,9 @@ dependencies = [ [[package]] name = "termcolor" -version = "1.1.3" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" dependencies = [ "winapi-util", ] @@ -789,9 +749,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.3" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" +checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" [[package]] name = "unicode-width" @@ -813,25 +773,19 @@ checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" [[package]] name = "version_check" -version = "0.9.3" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" - -[[package]] -name = "wasi" -version = "0.10.2+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "which" -version = "4.2.2" +version = "4.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea187a8ef279bc014ec368c27a920da2024d2a711109bfbe3440585d5cf27ad9" +checksum = "2441c784c52b289a054b7201fc93253e288f094e2f4be9058343127c4226a269" dependencies = [ "either", - "lazy_static", "libc", + "once_cell", ] [[package]] @@ -894,42 +848,42 @@ dependencies = [ [[package]] name = "windows_aarch64_gnullvm" -version = "0.42.0" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" +checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608" [[package]] name = "windows_aarch64_msvc" -version = "0.42.0" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" +checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7" [[package]] name = "windows_i686_gnu" -version = "0.42.0" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" +checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640" [[package]] name = "windows_i686_msvc" -version = "0.42.0" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" +checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605" [[package]] name = "windows_x86_64_gnu" -version = "0.42.0" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" +checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45" [[package]] name = "windows_x86_64_gnullvm" -version = "0.42.0" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" +checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463" [[package]] name = "windows_x86_64_msvc" -version = "0.42.0" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" +checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index 10b4d4cd28..139945695e 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -11,7 +11,7 @@ readme = "../README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.63.0" +version = "0.64.0" edition = "2018" # If you change this, also update README.md and msrv in .github/workflows/bindgen.yml rust-version = "1.60.0" @@ -21,7 +21,7 @@ path = "main.rs" name = "bindgen" [dependencies] -bindgen = { path = "../bindgen", version = "=0.63.0", features = ["cli", "experimental"] } +bindgen = { path = "../bindgen", version = "=0.64.0", features = ["cli", "experimental"] } shlex = "1" clap = { version = "4", features = ["derive"] } env_logger = { version = "0.9.0", optional = true } diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index 6d4902d452..bc53be5dd4 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -14,7 +14,7 @@ readme = "../README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.63.0" +version = "0.64.0" edition = "2018" build = "build.rs" # If you change this, also update README.md and msrv in .github/workflows/bindgen.yml From a25276622cfbfaab19e0d67f13d4847d8b36a8ce Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Thu, 9 Feb 2023 10:56:07 -0500 Subject: [PATCH 447/942] Remove unnecessary `./` (#2407) --- bindgen/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index bc53be5dd4..c2e8543bb0 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -22,7 +22,7 @@ rust-version = "1.60.0" [lib] name = "bindgen" -path = "./lib.rs" +path = "lib.rs" [dependencies] bitflags = "1.0.3" From 01c45391284674041f89454bfe6eeb900aa0be28 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Thu, 9 Feb 2023 11:16:14 -0500 Subject: [PATCH 448/942] Remove deprecated flags (#2408) --- CHANGELOG.md | 2 ++ bindgen-cli/options.rs | 21 +-------------------- 2 files changed, 3 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d901bab1e5..037755ca76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -166,6 +166,8 @@ ## Changed ## Removed + * The following deprecated flags were removed: `--use-msvc-mangling`, + `--rustfmt-bindings` and `--size_t-is-usize`. ## Fixed diff --git a/bindgen-cli/options.rs b/bindgen-cli/options.rs index 458c7bab1f..966e6aeced 100644 --- a/bindgen-cli/options.rs +++ b/bindgen-cli/options.rs @@ -239,9 +239,6 @@ struct BindgenCommand { /// Conservatively generate inline namespaces to avoid name conflicts. #[arg(long)] conservative_inline_namespaces: bool, - /// MSVC C++ ABI mangling. DEPRECATED: Has no effect. - #[arg(long)] - use_msvc_mangling: bool, /// Allowlist all the free-standing functions matching . Other non-allowlisted functions will not be generated. #[arg(long, value_name = "REGEX")] allowlist_function: Vec, @@ -266,20 +263,14 @@ struct BindgenCommand { /// Do not record matching items in the regex sets. This disables reporting of unused items. #[arg(long)] no_record_matches: bool, - /// Ignored - this is enabled by default. - #[arg(long = "size_t-is-usize")] - size_t_is_usize: bool, /// Do not bind size_t as usize (useful on platforms where those types are incompatible). #[arg(long = "no-size_t-is-usize")] no_size_t_is_usize: bool, /// Do not format the generated bindings with rustfmt. #[arg(long)] no_rustfmt_bindings: bool, - /// Format the generated bindings with rustfmt. DEPRECATED: --rustfmt-bindings is now enabled by default. Disable with --no-rustfmt-bindings. - #[arg(long)] - rustfmt_bindings: bool, /// The absolute path to the rustfmt configuration file. The configuration file will be used for formatting the bindings. This parameter is incompatible with --no-rustfmt-bindings. - #[arg(long, value_name = "PATH")] + #[arg(long, value_name = "PATH", conflicts_with("no_rustfmt_bindings"))] rustfmt_configuration_file: Option, /// Avoid deriving PartialEq for types matching . #[arg(long, value_name = "REGEX")] @@ -449,7 +440,6 @@ where rust_target, use_core, conservative_inline_namespaces, - use_msvc_mangling: _, allowlist_function, generate_inline_functions, allowlist_type, @@ -458,10 +448,8 @@ where verbose, dump_preprocessed_input, no_record_matches, - size_t_is_usize: _, no_size_t_is_usize, no_rustfmt_bindings, - rustfmt_bindings: _, rustfmt_configuration_file, no_partialeq, no_copy, @@ -831,13 +819,6 @@ where if let Some(path_str) = rustfmt_configuration_file { let path = PathBuf::from(path_str); - if no_rustfmt_bindings { - return Err(Error::new( - ErrorKind::Other, - "Cannot supply both --rustfmt-configuration-file and --no-rustfmt-bindings", - )); - } - if !path.is_absolute() { return Err(Error::new( ErrorKind::Other, From ce0ae76899a39a93e7db8f8ad24c5e681a3d7294 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Fri, 10 Feb 2023 10:17:32 -0500 Subject: [PATCH 449/942] Disallow constant values that were changed in clang 15 (#2410) * Disallow constant values that could cause problems with clang 15 * Fix clippy warnings --- bindgen/codegen/serialize.rs | 10 ++++------ bindgen/lib.rs | 1 + clippy.toml | 4 ++++ 3 files changed, 9 insertions(+), 6 deletions(-) create mode 100644 clippy.toml diff --git a/bindgen/codegen/serialize.rs b/bindgen/codegen/serialize.rs index 217098e590..e521c70326 100644 --- a/bindgen/codegen/serialize.rs +++ b/bindgen/codegen/serialize.rs @@ -44,12 +44,10 @@ impl<'a> CSerialize<'a> for Item { ItemKind::Function(func) => { func.serialize(ctx, self, stack, writer) } - kind => { - return Err(CodegenError::Serialize { - msg: format!("Cannot serialize item kind {:?}", kind), - loc: get_loc(self), - }); - } + kind => Err(CodegenError::Serialize { + msg: format!("Cannot serialize item kind {:?}", kind), + loc: get_loc(self), + }), } } } diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 5374742016..14d7a15576 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -9,6 +9,7 @@ //! additional documentation. #![deny(missing_docs)] #![deny(unused_extern_crates)] +#![deny(clippy::disallowed_methods)] // To avoid rather annoying warnings when matching with CXCursor_xxx as a // constant. #![allow(non_upper_case_globals)] diff --git a/clippy.toml b/clippy.toml new file mode 100644 index 0000000000..1060a6b4e7 --- /dev/null +++ b/clippy.toml @@ -0,0 +1,4 @@ +disallowed-methods = [ + { path = "clang_sys::CXCursor_TranslationUnit", reason = "This value was changed in clang 15"}, + { path = "clang_sys::CXCursor_LastStmt", reason = "This value was changed in clang 15"} +] From 36937a72e0f50d95f2402e9c3e4316014765c8cc Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Fri, 10 Feb 2023 12:19:13 -0500 Subject: [PATCH 450/942] Update `quickcheck` version (#2411) This is done to deal with the existing vulnerabilities in older versions of `thread_local` and `regex` --- Cargo.lock | 193 ++++++------------ bindgen-tests/tests/quickchecking/Cargo.toml | 3 +- bindgen-tests/tests/quickchecking/src/bin.rs | 3 +- .../tests/quickchecking/src/fuzzers.rs | 51 ++--- bindgen-tests/tests/quickchecking/src/lib.rs | 14 +- .../quickchecking/tests/fuzzed-c-headers.rs | 33 ++- 6 files changed, 112 insertions(+), 185 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5517f93dfa..819411836c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,22 +2,13 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "aho-corasick" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca972c2ea5f742bfce5687b9aef75506a764f61d37f8f649047846a9686ddb66" -dependencies = [ - "memchr 0.1.11", -] - [[package]] name = "aho-corasick" version = "0.7.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" dependencies = [ - "memchr 2.5.0", + "memchr", ] [[package]] @@ -26,7 +17,7 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] @@ -37,7 +28,7 @@ checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ "hermit-abi 0.1.19", "libc", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -49,11 +40,11 @@ dependencies = [ "clang-sys", "lazy_static", "lazycell", - "log 0.4.17", + "log", "peeking_take_while", "proc-macro2", "quote", - "regex 1.7.1", + "regex", "rustc-hash", "shlex", "syn", @@ -67,7 +58,7 @@ dependencies = [ "bindgen", "clap 4.1.4", "env_logger 0.9.3", - "log 0.4.17", + "log", "shlex", ] @@ -200,12 +191,12 @@ checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" [[package]] name = "env_logger" -version = "0.3.5" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15abd780e45b3ea4f76b4e9a26ff4843258dd8a3eed2775a0e7368c2e7936c2f" +checksum = "a19187fea3ac7e84da7dacf48de0c45d63c6a76f9490dae389aead16c243fce3" dependencies = [ - "log 0.3.9", - "regex 0.1.80", + "log", + "regex", ] [[package]] @@ -216,8 +207,8 @@ checksum = "a12e6657c4c97ebab115a42dcee77225f7f482cdd841cf7088c657a42e9e00e7" dependencies = [ "atty", "humantime", - "log 0.4.17", - "regex 1.7.1", + "log", + "regex", "termcolor", ] @@ -229,7 +220,7 @@ checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" dependencies = [ "errno-dragonfly", "libc", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -257,6 +248,17 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" +[[package]] +name = "getrandom" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "glob" version = "0.3.1" @@ -324,16 +326,6 @@ dependencies = [ "windows-sys", ] -[[package]] -name = "kernel32-sys" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -dependencies = [ - "winapi 0.2.8", - "winapi-build", -] - [[package]] name = "lazy_static" version = "1.4.0" @@ -359,7 +351,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "351a32417a12d5f7e82c368a66781e307834dae04c6ce0cd4456d52989229883" dependencies = [ "cfg-if", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -369,7 +361,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" dependencies = [ "cfg-if", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -378,15 +370,6 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" -[[package]] -name = "log" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" -dependencies = [ - "log 0.4.17", -] - [[package]] name = "log" version = "0.4.17" @@ -405,15 +388,6 @@ dependencies = [ "libc", ] -[[package]] -name = "memchr" -version = "0.1.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8b629fb514376c675b98c1421e80b151d3817ac42d7c667717d282761418d20" -dependencies = [ - "libc", -] - [[package]] name = "memchr" version = "2.5.0" @@ -432,7 +406,7 @@ version = "7.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" dependencies = [ - "memchr 2.5.0", + "memchr", "minimal-lexical", ] @@ -498,13 +472,13 @@ dependencies = [ [[package]] name = "quickcheck" -version = "0.4.1" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02c2411d418cea2364325b18a205664f9ef8252e06b2e911db97c0b0d98b1406" +checksum = "588f6378e4dd99458b60ec275b4477add41ce4fa9f64dcba6f15adccb19b50d6" dependencies = [ - "env_logger 0.3.5", - "log 0.3.9", - "rand 0.3.23", + "env_logger 0.8.4", + "log", + "rand 0.8.5", ] [[package]] @@ -514,7 +488,6 @@ dependencies = [ "clap 2.34.0", "lazy_static", "quickcheck", - "rand 0.3.23", "tempdir", ] @@ -529,25 +502,24 @@ dependencies = [ [[package]] name = "rand" -version = "0.3.23" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64ac302d8f83c0c1974bf758f6b041c6c8ada916fbb44a609158ca8b064cc76c" +checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" dependencies = [ + "fuchsia-cprng", "libc", - "rand 0.4.6", + "rand_core 0.3.1", + "rdrand", + "winapi", ] [[package]] name = "rand" -version = "0.4.6" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ - "fuchsia-cprng", - "libc", - "rand_core 0.3.1", - "rdrand", - "winapi 0.3.9", + "rand_core 0.6.4", ] [[package]] @@ -565,6 +537,15 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + [[package]] name = "rdrand" version = "0.4.0" @@ -583,36 +564,17 @@ dependencies = [ "bitflags", ] -[[package]] -name = "regex" -version = "0.1.80" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fd4ace6a8cf7860714a2c2280d6c1f7e6a413486c13298bbc86fd3da019402f" -dependencies = [ - "aho-corasick 0.5.3", - "memchr 0.1.11", - "regex-syntax 0.3.9", - "thread_local", - "utf8-ranges", -] - [[package]] name = "regex" version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733" dependencies = [ - "aho-corasick 0.7.20", - "memchr 2.5.0", - "regex-syntax 0.6.28", + "aho-corasick", + "memchr", + "regex-syntax", ] -[[package]] -name = "regex-syntax" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9ec002c35e86791825ed294b50008eea9ddfc8def4420124fbc6b08db834957" - [[package]] name = "regex-syntax" version = "0.6.28" @@ -625,7 +587,7 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] @@ -698,7 +660,7 @@ dependencies = [ "libc", "redox_syscall", "remove_dir_all", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -728,25 +690,6 @@ dependencies = [ "unicode-width", ] -[[package]] -name = "thread-id" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9539db560102d1cef46b8b78ce737ff0bb64e7e18d35b2a5688f7d097d0ff03" -dependencies = [ - "kernel32-sys", - "libc", -] - -[[package]] -name = "thread_local" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8576dbbfcaef9641452d5cf0df9b0e7eeab7694956dd33bb61515fb8f18cfdd5" -dependencies = [ - "thread-id", -] - [[package]] name = "unicode-ident" version = "1.0.6" @@ -759,12 +702,6 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" -[[package]] -name = "utf8-ranges" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1ca13c08c41c9c3e04224ed9ff80461d97e121589ff27c753a16cb10830ae0f" - [[package]] name = "vec_map" version = "0.8.2" @@ -777,6 +714,12 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + [[package]] name = "which" version = "4.4.0" @@ -788,12 +731,6 @@ dependencies = [ "once_cell", ] -[[package]] -name = "winapi" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" - [[package]] name = "winapi" version = "0.3.9" @@ -804,12 +741,6 @@ dependencies = [ "winapi-x86_64-pc-windows-gnu", ] -[[package]] -name = "winapi-build" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" - [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" @@ -822,7 +753,7 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] diff --git a/bindgen-tests/tests/quickchecking/Cargo.toml b/bindgen-tests/tests/quickchecking/Cargo.toml index 455a824039..b579d4ea96 100644 --- a/bindgen-tests/tests/quickchecking/Cargo.toml +++ b/bindgen-tests/tests/quickchecking/Cargo.toml @@ -15,8 +15,7 @@ path = "src/bin.rs" [dependencies] clap = "2.28" lazy_static = "1.0" -quickcheck = "0.4" -rand = "0.3" +quickcheck = "1.0" tempdir = "0.3" [features] diff --git a/bindgen-tests/tests/quickchecking/src/bin.rs b/bindgen-tests/tests/quickchecking/src/bin.rs index f2b52e828f..7c189ee886 100644 --- a/bindgen-tests/tests/quickchecking/src/bin.rs +++ b/bindgen-tests/tests/quickchecking/src/bin.rs @@ -105,8 +105,7 @@ fn main() { let output_path: Option<&str> = matches.value_of("path"); let generate_range: usize = matches.value_of("range").unwrap().parse::().unwrap(); - let tests: usize = - matches.value_of("count").unwrap().parse::().unwrap(); + let tests: u64 = matches.value_of("count").unwrap().parse::().unwrap(); quickchecking::test_bindgen(generate_range, tests, output_path) } diff --git a/bindgen-tests/tests/quickchecking/src/fuzzers.rs b/bindgen-tests/tests/quickchecking/src/fuzzers.rs index 4188f8f557..003e9bf3f1 100644 --- a/bindgen-tests/tests/quickchecking/src/fuzzers.rs +++ b/bindgen-tests/tests/quickchecking/src/fuzzers.rs @@ -1,5 +1,4 @@ -use quickcheck::{Arbitrary, Gen, StdGen}; -use rand::thread_rng; +use quickcheck::{Arbitrary, Gen}; use std::fmt; /// BaseTypeC is used in generation of C headers to represent the C language's @@ -182,8 +181,8 @@ impl MakeUnique for DeclarationC { /// A qucickcheck trait for describing how DeclarationC types can be /// randomly generated and shrunk. impl Arbitrary for DeclarationC { - fn arbitrary(g: &mut G) -> DeclarationC { - match g.gen_range(0, 5) { + fn arbitrary(g: &mut Gen) -> DeclarationC { + match gen_range(g, 0, 5) { 0 => DeclarationC::FunctionDecl(FunctionPrototypeC::arbitrary(g)), 1 => DeclarationC::FunctionPtrDecl( FunctionPointerDeclarationC::arbitrary(g), @@ -214,7 +213,7 @@ impl fmt::Display for DeclarationC { /// A qucickcheck trait for describing how DeclarationListC types can be /// randomly generated and shrunk. impl Arbitrary for DeclarationListC { - fn arbitrary(g: &mut G) -> DeclarationListC { + fn arbitrary(g: &mut Gen) -> DeclarationListC { DeclarationListC { decls: Arbitrary::arbitrary(g), } @@ -235,7 +234,7 @@ impl fmt::Display for DeclarationListC { /// A qucickcheck trait for describing how BaseTypeC types can be /// randomly generated and shrunk. impl Arbitrary for BaseTypeC { - fn arbitrary(g: &mut G) -> BaseTypeC { + fn arbitrary(g: &mut Gen) -> BaseTypeC { // Special case `long double` until issue #550 is resolved. let base_type = vec![ "char", @@ -286,7 +285,7 @@ impl fmt::Display for BaseTypeC { /// A qucickcheck trait for describing how TypeQualifierC types can be /// randomly generated and shrunk. impl Arbitrary for TypeQualifierC { - fn arbitrary(g: &mut G) -> TypeQualifierC { + fn arbitrary(g: &mut Gen) -> TypeQualifierC { let qualifier = vec!["const", ""]; TypeQualifierC { def: String::from(*g.choose(&qualifier).unwrap()), @@ -304,10 +303,10 @@ impl fmt::Display for TypeQualifierC { /// A qucickcheck trait for describing how PointerLevelC types can be /// randomly generated and shrunk. impl Arbitrary for PointerLevelC { - fn arbitrary(g: &mut G) -> PointerLevelC { + fn arbitrary(g: &mut Gen) -> PointerLevelC { PointerLevelC { // 16 is an arbitrary "not too big" number for capping pointer level. - def: (0..g.gen_range(0, 16)).map(|_| "*").collect::(), + def: (0..gen_range(g, 0, 16)).map(|_| "*").collect::(), } } } @@ -322,16 +321,16 @@ impl fmt::Display for PointerLevelC { /// A qucickcheck trait for describing how ArrayDimensionC types can be /// randomly generated and shrunk. impl Arbitrary for ArrayDimensionC { - fn arbitrary(g: &mut G) -> ArrayDimensionC { + fn arbitrary(g: &mut Gen) -> ArrayDimensionC { // Keep these small, clang complains when they get too big. - let dimensions = g.gen_range(0, 5); + let dimensions = gen_range(g, 0, 5); let mut def = String::new(); - let lower_bound = i32::from(cfg!(feature = "zero-sized-arrays")); + let lower_bound = u64::from(cfg!(feature = "zero-sized-arrays")); for _ in 1..dimensions { // 16 is an arbitrary "not too big" number for capping array size. - def += &format!("[{}]", g.gen_range(lower_bound, 16)); + def += &format!("[{}]", gen_range(g, lower_bound, 16)); } ArrayDimensionC { def } } @@ -355,7 +354,7 @@ impl MakeUnique for BasicTypeDeclarationC { /// A qucickcheck trait for describing how BasicTypeDeclarationC types can be /// randomly generated and shrunk. impl Arbitrary for BasicTypeDeclarationC { - fn arbitrary(g: &mut G) -> BasicTypeDeclarationC { + fn arbitrary(g: &mut Gen) -> BasicTypeDeclarationC { BasicTypeDeclarationC { type_qualifier: Arbitrary::arbitrary(g), type_name: Arbitrary::arbitrary(g), @@ -392,12 +391,12 @@ impl MakeUnique for StructDeclarationC { /// A qucickcheck trait for describing how StructDeclarationC types can be /// randomly generated and shrunk. impl Arbitrary for StructDeclarationC { - fn arbitrary(g: &mut G) -> StructDeclarationC { + fn arbitrary(g: &mut Gen) -> StructDeclarationC { // Reduce generator size as a method of putting a bound on recursion. // When size < 1 the empty list is generated. let reduced_size: usize = (g.size() / 2) + 1; let mut decl_list: DeclarationListC = - Arbitrary::arbitrary(&mut StdGen::new(thread_rng(), reduced_size)); + Arbitrary::arbitrary(&mut Gen::new(reduced_size)); let mut fields: DeclarationListC = DeclarationListC { decls: vec![] }; for (i, decl) in decl_list.decls.iter_mut().enumerate() { @@ -440,12 +439,12 @@ impl MakeUnique for UnionDeclarationC { /// A qucickcheck trait for describing how UnionDeclarationC types can be /// randomly generated and shrunk. impl Arbitrary for UnionDeclarationC { - fn arbitrary(g: &mut G) -> UnionDeclarationC { + fn arbitrary(g: &mut Gen) -> UnionDeclarationC { // Reduce generator size as a method of putting a bound on recursion. // When size < 1 the empty list is generated. let reduced_size: usize = (g.size() / 2) + 1; let mut decl_list: DeclarationListC = - Arbitrary::arbitrary(&mut StdGen::new(thread_rng(), reduced_size)); + Arbitrary::arbitrary(&mut Gen::new(reduced_size)); let mut fields: DeclarationListC = DeclarationListC { decls: vec![] }; for (i, decl) in decl_list.decls.iter_mut().enumerate() { @@ -488,7 +487,7 @@ impl MakeUnique for FunctionPointerDeclarationC { /// A qucickcheck trait for describing how FunctionPointerDeclarationC types can /// be randomly generated and shrunk. impl Arbitrary for FunctionPointerDeclarationC { - fn arbitrary(g: &mut G) -> FunctionPointerDeclarationC { + fn arbitrary(g: &mut Gen) -> FunctionPointerDeclarationC { FunctionPointerDeclarationC { type_qualifier: Arbitrary::arbitrary(g), type_name: Arbitrary::arbitrary(g), @@ -525,7 +524,7 @@ impl MakeUnique for FunctionPrototypeC { /// A qucickcheck trait for describing how FunctionPrototypeC types can be /// randomly generated and shrunk. impl Arbitrary for FunctionPrototypeC { - fn arbitrary(g: &mut G) -> FunctionPrototypeC { + fn arbitrary(g: &mut Gen) -> FunctionPrototypeC { FunctionPrototypeC { type_qualifier: Arbitrary::arbitrary(g), type_name: Arbitrary::arbitrary(g), @@ -554,7 +553,7 @@ impl fmt::Display for FunctionPrototypeC { /// A qucickcheck trait for describing how ParameterC types can be /// randomly generated and shrunk. impl Arbitrary for ParameterC { - fn arbitrary(g: &mut G) -> ParameterC { + fn arbitrary(g: &mut Gen) -> ParameterC { ParameterC { type_qualifier: Arbitrary::arbitrary(g), type_name: Arbitrary::arbitrary(g), @@ -577,7 +576,7 @@ impl fmt::Display for ParameterC { /// A qucickcheck trait for describing how ParameterListC types can be /// randomly generated and shrunk. impl Arbitrary for ParameterListC { - fn arbitrary(g: &mut G) -> ParameterListC { + fn arbitrary(g: &mut Gen) -> ParameterListC { ParameterListC { params: Arbitrary::arbitrary(g), } @@ -601,7 +600,7 @@ impl fmt::Display for ParameterListC { /// A qucickcheck trait for describing how HeaderC types can be /// randomly generated and shrunk. impl Arbitrary for HeaderC { - fn arbitrary(g: &mut G) -> HeaderC { + fn arbitrary(g: &mut Gen) -> HeaderC { let mut decl_list: DeclarationListC = Arbitrary::arbitrary(g); for (i, decl) in decl_list.decls.iter_mut().enumerate() { decl.make_unique(i); @@ -628,3 +627,9 @@ impl fmt::Debug for HeaderC { write!(f, "{}", self) } } + +/// FIXME: is this actually uniform? +fn gen_range(gen: &mut Gen, lo: u64, hi: u64) -> u64 { + let len = hi - lo; + (u64::arbitrary(gen) % len) + lo +} diff --git a/bindgen-tests/tests/quickchecking/src/lib.rs b/bindgen-tests/tests/quickchecking/src/lib.rs index 75bfc2376b..e9f3798dbf 100644 --- a/bindgen-tests/tests/quickchecking/src/lib.rs +++ b/bindgen-tests/tests/quickchecking/src/lib.rs @@ -5,16 +5,14 @@ //! ```rust //! extern crate quickcheck; //! extern crate quickchecking; -//! extern crate rand; -//! use quickcheck::{Arbitrary, Gen, StdGen}; +//! use quickcheck::{Arbitrary, Gen}; //! use quickchecking::fuzzers; -//! use rand::thread_rng; //! //! fn main() { //! let generate_range: usize = 10; // Determines things like the length of //! // arbitrary vectors generated. //! let header = fuzzers::HeaderC::arbitrary( -//! &mut StdGen::new(thread_rng(), generate_range)); +//! &mut Gen::new(generate_range)); //! println!("{}", header); //! } //! ``` @@ -23,11 +21,9 @@ #[macro_use] extern crate lazy_static; extern crate quickcheck; -extern crate rand; extern crate tempdir; -use quickcheck::{QuickCheck, StdGen, TestResult}; -use rand::thread_rng; +use quickcheck::{Gen, QuickCheck, TestResult}; use std::error::Error; use std::fs::File; use std::io::Write; @@ -110,7 +106,7 @@ fn bindgen_prop(header: fuzzers::HeaderC) -> TestResult { /// to the `csmith-fuzzing/predicate.py` script. pub fn test_bindgen( generate_range: usize, - tests: usize, + tests: u64, output_path: Option<&str>, ) { if let Some(path) = output_path { @@ -120,6 +116,6 @@ pub fn test_bindgen( QuickCheck::new() .tests(tests) - .gen(StdGen::new(thread_rng(), generate_range)) + .gen(Gen::new(generate_range)) .quickcheck(bindgen_prop as fn(fuzzers::HeaderC) -> TestResult) } diff --git a/bindgen-tests/tests/quickchecking/tests/fuzzed-c-headers.rs b/bindgen-tests/tests/quickchecking/tests/fuzzed-c-headers.rs index 0d43f30050..e394efe387 100644 --- a/bindgen-tests/tests/quickchecking/tests/fuzzed-c-headers.rs +++ b/bindgen-tests/tests/quickchecking/tests/fuzzed-c-headers.rs @@ -1,96 +1,93 @@ extern crate quickcheck; extern crate quickchecking; -extern crate rand; -use quickcheck::{Arbitrary, StdGen}; +use quickcheck::{Arbitrary, Gen}; use quickchecking::fuzzers::{ ArrayDimensionC, BaseTypeC, BasicTypeDeclarationC, DeclarationC, DeclarationListC, FunctionPointerDeclarationC, FunctionPrototypeC, HeaderC, ParameterC, ParameterListC, PointerLevelC, StructDeclarationC, TypeQualifierC, UnionDeclarationC, }; -use rand::thread_rng; - #[test] fn test_declaraion_c_does_not_panic() { - let gen = &mut StdGen::new(thread_rng(), 50); + let gen = &mut Gen::new(50); let _: DeclarationC = Arbitrary::arbitrary(gen); } #[test] fn test_declaraion_list_c_does_not_panic() { - let gen = &mut StdGen::new(thread_rng(), 50); + let gen = &mut Gen::new(50); let _: DeclarationListC = Arbitrary::arbitrary(gen); } #[test] fn test_base_type_c_does_not_panic() { - let gen = &mut StdGen::new(thread_rng(), 50); + let gen = &mut Gen::new(50); let _: BaseTypeC = Arbitrary::arbitrary(gen); } #[test] fn test_type_qualifier_c_does_not_panic() { - let gen = &mut StdGen::new(thread_rng(), 50); + let gen = &mut Gen::new(50); let _: TypeQualifierC = Arbitrary::arbitrary(gen); } #[test] fn test_pointer_level_c_does_not_panic() { - let gen = &mut StdGen::new(thread_rng(), 50); + let gen = &mut Gen::new(50); let _: PointerLevelC = Arbitrary::arbitrary(gen); } #[test] fn test_array_dimension_c_does_not_panic() { - let gen = &mut StdGen::new(thread_rng(), 50); + let gen = &mut Gen::new(50); let _: ArrayDimensionC = Arbitrary::arbitrary(gen); } #[test] fn test_basic_type_declaration_c_does_not_panic() { - let gen = &mut StdGen::new(thread_rng(), 50); + let gen = &mut Gen::new(50); let _: BasicTypeDeclarationC = Arbitrary::arbitrary(gen); } #[test] fn test_struct_declaration_c_does_not_panic() { - let gen = &mut StdGen::new(thread_rng(), 50); + let gen = &mut Gen::new(50); let _: StructDeclarationC = Arbitrary::arbitrary(gen); } #[test] fn test_union_declaration_c_does_not_panic() { - let gen = &mut StdGen::new(thread_rng(), 50); + let gen = &mut Gen::new(50); let _: UnionDeclarationC = Arbitrary::arbitrary(gen); } #[test] fn test_function_pointer_declaration_c_does_not_panic() { - let gen = &mut StdGen::new(thread_rng(), 50); + let gen = &mut Gen::new(50); let _: FunctionPointerDeclarationC = Arbitrary::arbitrary(gen); } #[test] fn test_function_prototype_c_does_not_panic() { - let gen = &mut StdGen::new(thread_rng(), 50); + let gen = &mut Gen::new(50); let _: FunctionPrototypeC = Arbitrary::arbitrary(gen); } #[test] fn test_parameter_c_does_not_panic() { - let gen = &mut StdGen::new(thread_rng(), 50); + let gen = &mut Gen::new(50); let _: ParameterC = Arbitrary::arbitrary(gen); } #[test] fn test_parameter_list_c_does_not_panic() { - let gen = &mut StdGen::new(thread_rng(), 50); + let gen = &mut Gen::new(50); let _: ParameterListC = Arbitrary::arbitrary(gen); } #[test] fn test_header_c_does_not_panic() { - let gen = &mut StdGen::new(thread_rng(), 50); + let gen = &mut Gen::new(50); let _: HeaderC = Arbitrary::arbitrary(gen); } From b865dbdc474ee08f09ac675a47cb0e20bd1059ad Mon Sep 17 00:00:00 2001 From: jahs-tech Date: Thu, 16 Feb 2023 11:05:46 -0500 Subject: [PATCH 451/942] Fix typo in bitfields documentation (#2412) "Far each ..." should be "For each ..." --- book/src/using-bitfields.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/src/using-bitfields.md b/book/src/using-bitfields.md index 41e07ad703..0ee9f0329c 100644 --- a/book/src/using-bitfields.md +++ b/book/src/using-bitfields.md @@ -5,7 +5,7 @@ As Rust does not support bitfields, Bindgen generates a struct for each with the following characteristics * Immutable getter functions for each bitfield named `````` * Setter functions for each contiguous block of bitfields named ```set_``` -* Far each contiguous block of bitfields, Bindgen emits an opaque physical field that contains one or more logical bitfields +* For each contiguous block of bitfields, Bindgen emits an opaque physical field that contains one or more logical bitfields * A static constructor ```new_bitfield_{1, 2, ...}``` with a parameter for each bitfield contained within the opaque physical field. ## Bitfield examples From 52a8cde6a4ddd5dd9e130f2874816d4afd910cb0 Mon Sep 17 00:00:00 2001 From: Urgau <3616612+Urgau@users.noreply.github.com> Date: Thu, 16 Feb 2023 17:13:54 +0100 Subject: [PATCH 452/942] Add support for enums with the wrapped static functions feature (#2415) --- .../tests/expectations/tests/generated/wrap_static_fns.c | 2 ++ bindgen-tests/tests/expectations/tests/wrap-static-fns.rs | 6 ++++++ bindgen-tests/tests/headers/wrap-static-fns.h | 8 ++++++++ bindgen/codegen/serialize.rs | 8 ++++++++ 4 files changed, 24 insertions(+) diff --git a/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c b/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c index 22b2f67f75..f5f33f8444 100644 --- a/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c +++ b/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c @@ -12,3 +12,5 @@ int takes_alias__extern(func f) asm("takes_alias__extern"); int takes_alias__extern(func f) { return takes_alias(f); } int takes_qualified__extern(const int *const *arg) asm("takes_qualified__extern"); int takes_qualified__extern(const int *const *arg) { return takes_qualified(arg); } +enum foo takes_enum__extern(const enum foo f) asm("takes_enum__extern"); +enum foo takes_enum__extern(const enum foo f) { return takes_enum(f); } diff --git a/bindgen-tests/tests/expectations/tests/wrap-static-fns.rs b/bindgen-tests/tests/expectations/tests/wrap-static-fns.rs index 54ed9fd4dd..fbfdcb13e0 100644 --- a/bindgen-tests/tests/expectations/tests/wrap-static-fns.rs +++ b/bindgen-tests/tests/expectations/tests/wrap-static-fns.rs @@ -50,3 +50,9 @@ extern "C" { arg: *const *const ::std::os::raw::c_int, ) -> ::std::os::raw::c_int; } +pub const foo_BAR: foo = 0; +pub type foo = ::std::os::raw::c_uint; +extern "C" { + #[link_name = "\u{1}takes_enum__extern"] + pub fn takes_enum(f: foo) -> foo; +} diff --git a/bindgen-tests/tests/headers/wrap-static-fns.h b/bindgen-tests/tests/headers/wrap-static-fns.h index 8b90c7bc38..0389231553 100644 --- a/bindgen-tests/tests/headers/wrap-static-fns.h +++ b/bindgen-tests/tests/headers/wrap-static-fns.h @@ -31,3 +31,11 @@ static inline int takes_alias(func f) { static inline int takes_qualified(const int *const *arg) { return **arg; } + +enum foo { + BAR = 0x0, +}; + +static inline enum foo takes_enum(const enum foo f) { + return f; +} diff --git a/bindgen/codegen/serialize.rs b/bindgen/codegen/serialize.rs index e521c70326..1310648463 100644 --- a/bindgen/codegen/serialize.rs +++ b/bindgen/codegen/serialize.rs @@ -311,6 +311,14 @@ impl<'a> CSerialize<'a> for Type { CompKind::Union => write!(writer, "union {}", name)?, }; } + TypeKind::Enum(_enum_ty) => { + if self.is_const() { + write!(writer, "const ")?; + } + + let name = item.canonical_name(ctx); + write!(writer, "enum {}", name)?; + } ty => { return Err(CodegenError::Serialize { msg: format!("Cannot serialize type kind {:?}", ty), From 62d91c5dcbf84bb9cda59996d60ab33df321e9f2 Mon Sep 17 00:00:00 2001 From: Urgau <3616612+Urgau@users.noreply.github.com> Date: Thu, 16 Feb 2023 17:16:34 +0100 Subject: [PATCH 453/942] Also de-duplicate functions with wrapped static functions feature (#2416) --- bindgen-tests/tests/headers/wrap-static-fns.h | 1 + bindgen/codegen/mod.rs | 16 ++++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/bindgen-tests/tests/headers/wrap-static-fns.h b/bindgen-tests/tests/headers/wrap-static-fns.h index 0389231553..faa7b7f1ad 100644 --- a/bindgen-tests/tests/headers/wrap-static-fns.h +++ b/bindgen-tests/tests/headers/wrap-static-fns.h @@ -3,6 +3,7 @@ static inline int foo() { return 11; } +static int bar(); static int bar() { return 1; } diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index b6fb70eb01..b5a7b27cf4 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -4029,14 +4029,10 @@ impl CodeGenerator for Function { let is_internal = matches!(self.linkage(), Linkage::Internal); - if is_internal { - if ctx.options().wrap_static_fns { - result.items_to_serialize.push(item.id()); - } else { - // We can't do anything with Internal functions if we are not wrapping them so just - // avoid generating anything for them. - return None; - } + if is_internal && !ctx.options().wrap_static_fns { + // We can't do anything with Internal functions if we are not wrapping them so just + // avoid generating anything for them. + return None; } // Pure virtual methods have no actual symbol, so we can't generate @@ -4139,6 +4135,10 @@ impl CodeGenerator for Function { abi => abi, }; + if is_internal && ctx.options().wrap_static_fns { + result.items_to_serialize.push(item.id()); + } + // Handle overloaded functions by giving each overload its own unique // suffix. let times_seen = result.overload_number(&canonical_name); From 2d99bbd738b5dbbe02257f26489f7d3904bf9f2b Mon Sep 17 00:00:00 2001 From: jahs-tech Date: Thu, 16 Feb 2023 11:22:23 -0500 Subject: [PATCH 454/942] Add warning section to build dependency tutorial doc (#2413) --- book/src/tutorial-1.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/book/src/tutorial-1.md b/book/src/tutorial-1.md index cac4f255c1..182a777fe7 100644 --- a/book/src/tutorial-1.md +++ b/book/src/tutorial-1.md @@ -13,3 +13,9 @@ you're unsure. [build-dependencies] bindgen = "0.53.1" ``` + +> ⚠ **Warning** +> +> `bindgen` needs to be added to the `[build-dependencies]` section, not the normal +> `[dependencies]` section. If you add it as a regular dependency, you will get +> errors like the following: `` error[E0463]: can't find crate for `bindgen` `` From 020a1b1acb211ba7db7f86f046f8b02717112c51 Mon Sep 17 00:00:00 2001 From: CarePackage17 Date: Mon, 27 Feb 2023 17:57:02 +0100 Subject: [PATCH 455/942] Add winget install bindgen setup docs (#2424) * Add winget install option for bindgen setup Recent versions of Windows 10 and Windows 11 ship with the winget CLI tool, which can be used to install LLVM in a way similar to Linux. This PR adds this option to the requirements docs. * Address PR feedback --- book/src/requirements.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/book/src/requirements.md b/book/src/requirements.md index 7cce87aed9..b701234fad 100644 --- a/book/src/requirements.md +++ b/book/src/requirements.md @@ -13,7 +13,12 @@ It is required to use Clang 5.0 or greater. #### Windows -Download and install the official pre-built binary from +If you use winget: +```powershell +winget install LLVM.LLVM +``` + +Alternatively, you can download and install the official pre-built binary from [LLVM download page](http://releases.llvm.org/download.html). You will also need to set `LIBCLANG_PATH` as an [environment From 84fb33280a3db5000d7110ad66f41c01d06f7ddc Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Tue, 28 Feb 2023 18:37:33 -0500 Subject: [PATCH 456/942] Update `tempfile` dependency to avoid vulnerability (#2427) --- Cargo.lock | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 819411836c..4043491301 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -651,16 +651,15 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.3.0" +version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" +checksum = "af18f7ae1acd354b992402e9ec5864359d693cd8a79dcbef59f76891701c1e95" dependencies = [ "cfg-if", "fastrand", - "libc", "redox_syscall", - "remove_dir_all", - "winapi", + "rustix", + "windows-sys", ] [[package]] From 3433695cfaa2e815256f6bf6632f69b65b993965 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Tue, 28 Feb 2023 19:00:53 -0500 Subject: [PATCH 457/942] Remove `tempfile` dependency to fix vulnerability (#2428) * Update `tempfile` dependency to avoid vulnerability * Replace `tempdir` dependency by `tempfile` --- Cargo.lock | 82 ++------------------ bindgen-tests/tests/expectations/Cargo.toml | 2 +- bindgen-tests/tests/quickchecking/Cargo.toml | 2 +- bindgen-tests/tests/quickchecking/src/lib.rs | 6 +- 4 files changed, 10 insertions(+), 82 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4043491301..0e5f84b23b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -122,7 +122,7 @@ checksum = "fa2e27ae6ab525c3d369ded447057bca5438d86dc3a68f6faafb8269ba82ebf3" dependencies = [ "glob", "libc", - "libloading 0.7.4", + "libloading", ] [[package]] @@ -242,12 +242,6 @@ dependencies = [ "instant", ] -[[package]] -name = "fuchsia-cprng" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" - [[package]] name = "getrandom" version = "0.2.8" @@ -344,16 +338,6 @@ version = "0.2.139" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" -[[package]] -name = "libloading" -version = "0.6.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "351a32417a12d5f7e82c368a66781e307834dae04c6ce0cd4456d52989229883" -dependencies = [ - "cfg-if", - "winapi", -] - [[package]] name = "libloading" version = "0.7.4" @@ -478,7 +462,7 @@ checksum = "588f6378e4dd99458b60ec275b4477add41ce4fa9f64dcba6f15adccb19b50d6" dependencies = [ "env_logger 0.8.4", "log", - "rand 0.8.5", + "rand", ] [[package]] @@ -488,7 +472,7 @@ dependencies = [ "clap 2.34.0", "lazy_static", "quickcheck", - "tempdir", + "tempfile", ] [[package]] @@ -500,43 +484,15 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "rand" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" -dependencies = [ - "fuchsia-cprng", - "libc", - "rand_core 0.3.1", - "rdrand", - "winapi", -] - [[package]] name = "rand" version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ - "rand_core 0.6.4", + "rand_core", ] -[[package]] -name = "rand_core" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" -dependencies = [ - "rand_core 0.4.2", -] - -[[package]] -name = "rand_core" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" - [[package]] name = "rand_core" version = "0.6.4" @@ -546,15 +502,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rdrand" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" -dependencies = [ - "rand_core 0.3.1", -] - [[package]] name = "redox_syscall" version = "0.2.16" @@ -581,15 +528,6 @@ version = "0.6.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" -[[package]] -name = "remove_dir_all" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" -dependencies = [ - "winapi", -] - [[package]] name = "rustc-hash" version = "1.1.0" @@ -639,16 +577,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tempdir" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8" -dependencies = [ - "rand 0.4.6", - "remove_dir_all", -] - [[package]] name = "tempfile" version = "3.4.0" @@ -676,7 +604,7 @@ name = "tests_expectations" version = "0.1.0" dependencies = [ "block", - "libloading 0.6.7", + "libloading", "objc", ] diff --git a/bindgen-tests/tests/expectations/Cargo.toml b/bindgen-tests/tests/expectations/Cargo.toml index f8006afeab..086d0e8c31 100644 --- a/bindgen-tests/tests/expectations/Cargo.toml +++ b/bindgen-tests/tests/expectations/Cargo.toml @@ -12,4 +12,4 @@ edition = "2018" [dependencies] objc = "0.2" block = "0.1" -libloading = "0.6.2" +libloading = "0.7" diff --git a/bindgen-tests/tests/quickchecking/Cargo.toml b/bindgen-tests/tests/quickchecking/Cargo.toml index b579d4ea96..abbb44be91 100644 --- a/bindgen-tests/tests/quickchecking/Cargo.toml +++ b/bindgen-tests/tests/quickchecking/Cargo.toml @@ -16,7 +16,7 @@ path = "src/bin.rs" clap = "2.28" lazy_static = "1.0" quickcheck = "1.0" -tempdir = "0.3" +tempfile = "3" [features] # No features by default. diff --git a/bindgen-tests/tests/quickchecking/src/lib.rs b/bindgen-tests/tests/quickchecking/src/lib.rs index e9f3798dbf..8589377123 100644 --- a/bindgen-tests/tests/quickchecking/src/lib.rs +++ b/bindgen-tests/tests/quickchecking/src/lib.rs @@ -21,7 +21,7 @@ #[macro_use] extern crate lazy_static; extern crate quickcheck; -extern crate tempdir; +extern crate tempfile; use quickcheck::{Gen, QuickCheck, TestResult}; use std::error::Error; @@ -30,7 +30,7 @@ use std::io::Write; use std::path::PathBuf; use std::process::{Command, Output}; use std::sync::Mutex; -use tempdir::TempDir; +use tempfile::Builder; /// Contains definitions of and impls for types used to fuzz C declarations. pub mod fuzzers; @@ -52,7 +52,7 @@ lazy_static! { fn run_predicate_script( header: fuzzers::HeaderC, ) -> Result> { - let dir = TempDir::new("bindgen_prop")?; + let dir = Builder::new().prefix("bindgen_prop").tempdir()?; let header_path = dir.path().join("prop_test.h"); let mut header_file = File::create(&header_path)?; From d4cb0f774d6bc869c1f1f5da2b862c23063431c1 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Tue, 28 Feb 2023 19:25:37 -0500 Subject: [PATCH 458/942] Deduplicate dependencies (#2429) * Deduplicate dependencies * Update `clap` usage of `quickchecking` --- Cargo.lock | 89 ++------------------ bindgen-cli/Cargo.toml | 2 +- bindgen-tests/tests/quickchecking/Cargo.toml | 2 +- bindgen-tests/tests/quickchecking/src/bin.rs | 60 ++++++------- bindgen-tests/tests/quickchecking/src/lib.rs | 7 +- 5 files changed, 44 insertions(+), 116 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0e5f84b23b..e435ba0b43 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,26 +11,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "ansi_term" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" -dependencies = [ - "winapi", -] - -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi 0.1.19", - "libc", - "winapi", -] - [[package]] name = "bindgen" version = "0.64.0" @@ -56,8 +36,8 @@ name = "bindgen-cli" version = "0.64.0" dependencies = [ "bindgen", - "clap 4.1.4", - "env_logger 0.9.3", + "clap", + "env_logger 0.10.0", "log", "shlex", ] @@ -75,7 +55,7 @@ name = "bindgen-tests" version = "0.1.0" dependencies = [ "bindgen", - "clap 4.1.4", + "clap", "diff", "shlex", "tempfile", @@ -125,21 +105,6 @@ dependencies = [ "libloading", ] -[[package]] -name = "clap" -version = "2.34.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" -dependencies = [ - "ansi_term", - "atty", - "bitflags", - "strsim 0.8.0", - "textwrap", - "unicode-width", - "vec_map", -] - [[package]] name = "clap" version = "4.1.4" @@ -151,7 +116,7 @@ dependencies = [ "clap_lex", "is-terminal", "once_cell", - "strsim 0.10.0", + "strsim", "termcolor", ] @@ -201,12 +166,12 @@ dependencies = [ [[package]] name = "env_logger" -version = "0.9.3" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a12e6657c4c97ebab115a42dcee77225f7f482cdd841cf7088c657a42e9e00e7" +checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0" dependencies = [ - "atty", "humantime", + "is-terminal", "log", "regex", "termcolor", @@ -265,15 +230,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" -[[package]] -name = "hermit-abi" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] - [[package]] name = "hermit-abi" version = "0.2.6" @@ -314,7 +270,7 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28dfb6c8100ccc63462345b67d1bbc3679177c75ee4bf59bf29c8b1d110b8189" dependencies = [ - "hermit-abi 0.2.6", + "hermit-abi", "io-lifetimes", "rustix", "windows-sys", @@ -469,7 +425,7 @@ dependencies = [ name = "quickchecking" version = "0.1.0" dependencies = [ - "clap 2.34.0", + "clap", "lazy_static", "quickcheck", "tempfile", @@ -554,12 +510,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" -[[package]] -name = "strsim" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" - [[package]] name = "strsim" version = "0.10.0" @@ -608,33 +558,12 @@ dependencies = [ "objc", ] -[[package]] -name = "textwrap" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" -dependencies = [ - "unicode-width", -] - [[package]] name = "unicode-ident" version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" -[[package]] -name = "unicode-width" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" - -[[package]] -name = "vec_map" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" - [[package]] name = "version_check" version = "0.9.4" diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index 139945695e..19778d3cb5 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -24,7 +24,7 @@ name = "bindgen" bindgen = { path = "../bindgen", version = "=0.64.0", features = ["cli", "experimental"] } shlex = "1" clap = { version = "4", features = ["derive"] } -env_logger = { version = "0.9.0", optional = true } +env_logger = { version = "0.10.0", optional = true } log = { version = "0.4", optional = true } [features] diff --git a/bindgen-tests/tests/quickchecking/Cargo.toml b/bindgen-tests/tests/quickchecking/Cargo.toml index abbb44be91..3b87704f27 100644 --- a/bindgen-tests/tests/quickchecking/Cargo.toml +++ b/bindgen-tests/tests/quickchecking/Cargo.toml @@ -13,7 +13,7 @@ name = "quickchecking" path = "src/bin.rs" [dependencies] -clap = "2.28" +clap = "4" lazy_static = "1.0" quickcheck = "1.0" tempfile = "3" diff --git a/bindgen-tests/tests/quickchecking/src/bin.rs b/bindgen-tests/tests/quickchecking/src/bin.rs index 7c189ee886..7f1307e15f 100644 --- a/bindgen-tests/tests/quickchecking/src/bin.rs +++ b/bindgen-tests/tests/quickchecking/src/bin.rs @@ -17,39 +17,40 @@ extern crate clap; extern crate quickchecking; -use clap::{App, Arg}; -use std::path::Path; +use clap::{Arg, ArgAction, Command}; +use std::path::PathBuf; -// Validate CLI argument input for generation range. -fn validate_generate_range(v: String) -> Result<(), String> { +// Parse CLI argument input for generation range. +fn parse_generate_range(v: &str) -> Result { match v.parse::() { - Ok(_) => Ok(()), + Ok(v) => Ok(v), Err(_) => Err(String::from( "Generate range could not be converted to a usize.", )), } } -// Validate CLI argument input for tests count. -fn validate_tests_count(v: String) -> Result<(), String> { - match v.parse::() { - Ok(_) => Ok(()), +// Parse CLI argument input for tests count. +fn parse_tests_count(v: &str) -> Result { + match v.parse::() { + Ok(v) => Ok(v), Err(_) => Err(String::from( "Tests count could not be converted to a usize.", )), } } -// Validate CLI argument input for fuzzed headers output path. -fn validate_path(v: String) -> Result<(), String> { - match Path::new(&v).is_dir() { - true => Ok(()), +// Parse CLI argument input for fuzzed headers output path. +fn parse_path(v: &str) -> Result { + let path = PathBuf::from(v); + match path.is_dir() { + true => Ok(path), false => Err(String::from("Provided directory path does not exist.")), } } fn main() { - let matches = App::new("quickchecking") + let matches = Command::new("quickchecking") .version("0.2.0") .about( "Bindgen property tests with quickcheck. \ @@ -57,20 +58,20 @@ fn main() { csmith/predicate.py script", ) .arg( - Arg::with_name("path") - .short("p") + Arg::new("path") + .short('p') .long("path") .value_name("PATH") .help( "Optional. Preserve generated headers for inspection, \ provide directory path for header output. [default: None] ", ) - .takes_value(true) - .validator(validate_path), + .action(ArgAction::Set) + .value_parser(parse_path), ) .arg( - Arg::with_name("range") - .short("r") + Arg::new("range") + .short('r') .long("range") .value_name("RANGE") .help( @@ -80,13 +81,13 @@ fn main() { to grow much for execution time to increase \ significantly.", ) - .takes_value(true) + .action(ArgAction::Set) .default_value("32") - .validator(validate_generate_range), + .value_parser(parse_generate_range), ) .arg( - Arg::with_name("count") - .short("c") + Arg::new("count") + .short('c') .long("count") .value_name("COUNT") .help( @@ -96,16 +97,15 @@ fn main() { large. Increase this number if you're willing to \ wait a while.", ) - .takes_value(true) + .action(ArgAction::Set) .default_value("2") - .validator(validate_tests_count), + .value_parser(parse_tests_count), ) .get_matches(); - let output_path: Option<&str> = matches.value_of("path"); - let generate_range: usize = - matches.value_of("range").unwrap().parse::().unwrap(); - let tests: u64 = matches.value_of("count").unwrap().parse::().unwrap(); + let output_path = matches.get_one::("path").map(PathBuf::as_path); + let generate_range = *matches.get_one::("range").unwrap(); + let tests = *matches.get_one::("count").unwrap(); quickchecking::test_bindgen(generate_range, tests, output_path) } diff --git a/bindgen-tests/tests/quickchecking/src/lib.rs b/bindgen-tests/tests/quickchecking/src/lib.rs index 8589377123..348ecaa687 100644 --- a/bindgen-tests/tests/quickchecking/src/lib.rs +++ b/bindgen-tests/tests/quickchecking/src/lib.rs @@ -27,7 +27,7 @@ use quickcheck::{Gen, QuickCheck, TestResult}; use std::error::Error; use std::fs::File; use std::io::Write; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use std::process::{Command, Output}; use std::sync::Mutex; use tempfile::Builder; @@ -107,11 +107,10 @@ fn bindgen_prop(header: fuzzers::HeaderC) -> TestResult { pub fn test_bindgen( generate_range: usize, tests: u64, - output_path: Option<&str>, + output_path: Option<&Path>, ) { if let Some(path) = output_path { - CONTEXT.lock().unwrap().output_path = - Some(String::from(PathBuf::from(path).to_str().unwrap())); + CONTEXT.lock().unwrap().output_path = Some(path.display().to_string()); } QuickCheck::new() From 0e193dce221197d4de352082bbb4c7c1a7a291e0 Mon Sep 17 00:00:00 2001 From: CGMossa Date: Wed, 1 Mar 2023 15:47:11 +0100 Subject: [PATCH 459/942] Fix broken link to doxygen docblocks (#2430) Link broken. Fixed it and used modern style --- bindgen/ir/annotations.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/bindgen/ir/annotations.rs b/bindgen/ir/annotations.rs index 288c11ebae..17edb31ca5 100644 --- a/bindgen/ir/annotations.rs +++ b/bindgen/ir/annotations.rs @@ -21,10 +21,7 @@ pub enum FieldAccessorKind { /// Annotations for a given item, or a field. /// -/// You can see the kind of comments that are accepted in the Doxygen -/// documentation: -/// -/// http://www.stack.nl/~dimitri/doxygen/manual/docblocks.html +/// You can see the kind of comments that are accepted in the [Doxygen documentation](https://www.doxygen.nl/manual/docblocks.html). #[derive(Default, Clone, PartialEq, Eq, Debug)] pub struct Annotations { /// Whether this item is marked as opaque. Only applies to types. From a8c8638d28f135823e913dab69b8a0d4fa4bbf15 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Wed, 1 Mar 2023 21:29:39 -0500 Subject: [PATCH 460/942] Remove unused code (#2398) * Use the `clippy::missing_docs_in_private_items` instead of the `doc_mod` macro * remove dead code * Fix clippy warnings * Run rustfmt * update config field * some nits * more nits * remove the `testing_only_docs` feature --- .github/workflows/bindgen.yml | 5 - CONTRIBUTING.md | 8 - bindgen-integration/Cargo.toml | 1 - bindgen-tests/Cargo.toml | 1 - bindgen/Cargo.toml | 1 - bindgen/callbacks.rs | 2 +- bindgen/clang.rs | 311 +++++++++--------- bindgen/codegen/dyngen.rs | 6 +- bindgen/codegen/error.rs | 4 +- bindgen/codegen/helpers.rs | 50 +-- bindgen/codegen/impl_debug.rs | 4 +- bindgen/codegen/impl_partialeq.rs | 2 +- bindgen/codegen/mod.rs | 41 +-- bindgen/codegen/struct_layout.rs | 28 +- bindgen/features.rs | 2 +- bindgen/ir/analysis/derive.rs | 4 +- bindgen/ir/analysis/has_destructor.rs | 2 +- bindgen/ir/analysis/has_float.rs | 2 +- .../ir/analysis/has_type_param_in_array.rs | 2 +- bindgen/ir/analysis/has_vtable.rs | 8 +- bindgen/ir/analysis/mod.rs | 27 +- bindgen/ir/analysis/sizedness.rs | 8 +- bindgen/ir/analysis/template_params.rs | 4 +- bindgen/ir/annotations.rs | 28 +- bindgen/ir/comment.rs | 2 +- bindgen/ir/comp.rs | 129 ++++---- bindgen/ir/context.rs | 207 +++++++----- bindgen/ir/derive.rs | 18 +- bindgen/ir/dot.rs | 4 +- bindgen/ir/enum_ty.rs | 31 +- bindgen/ir/function.rs | 51 ++- bindgen/ir/int.rs | 6 +- bindgen/ir/item.rs | 110 ++++--- bindgen/ir/item_kind.rs | 38 +-- bindgen/ir/layout.rs | 39 +-- bindgen/ir/mod.rs | 39 +-- bindgen/ir/module.rs | 14 +- bindgen/ir/objc.rs | 43 ++- bindgen/ir/template.rs | 14 +- bindgen/ir/traversal.rs | 31 +- bindgen/ir/ty.rs | 91 ++--- bindgen/ir/var.rs | 16 +- bindgen/lib.rs | 31 +- bindgen/parse.rs | 7 +- bindgen/regex_set.rs | 1 + ci/test.sh | 3 - clippy.toml | 1 + 47 files changed, 714 insertions(+), 763 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 8faa4988ec..9a8b2bb00f 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -107,7 +107,6 @@ jobs: # `static` feature is not testable atm. feature_runtime: [0, 1] feature_extra_asserts: [0] - feature_testing_only_docs: [0] include: # Test with extra asserts + docs just with latest llvm versions to @@ -117,7 +116,6 @@ jobs: release_build: 0 no_default_features: 0 feature_extra_asserts: 1 - feature_testing_only_docs: 1 # FIXME: Seems installing multiarch packages fails: # @@ -132,7 +130,6 @@ jobs: # main_tests: 0 # release_build: 0 # feature_extra_asserts: 0 - # feature_testing_only_docs: 0 # Ensure stuff works on macos too - os: macos-latest @@ -140,7 +137,6 @@ jobs: release_build: 0 no_default_features: 0 feature_extra_asserts: 0 - feature_testing_only_docs: 0 steps: - uses: actions/checkout@v3 @@ -181,7 +177,6 @@ jobs: BINDGEN_RELEASE_BUILD: ${{matrix.release_build}} BINDGEN_FEATURE_RUNTIME: ${{matrix.feature_runtime}} BINDGEN_FEATURE_EXTRA_ASSERTS: ${{matrix.feature_extra_asserts}} - BINDGEN_FEATURE_TESTING_ONLY_DOCS: ${{matrix.feature_testing_only_docs}} BINDGEN_NO_DEFAULT_FEATURES: ${{matrix.no_default_features}} run: ./ci/test.sh diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6189619da8..127e5c5ef0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -79,14 +79,6 @@ versions of llvm, or specify the path of the desired libclang explicitly: $ export LIBCLANG_PATH=path/to/clang-9.0/lib ``` -Additionally, you may want to build and test with the `testing_only_docs` -feature to ensure that you aren't forgetting to document types and functions. CI -will catch it if you forget, but the turn around will be a lot slower ;) - -``` -$ cargo build --features testing_only_docs -``` - ## Testing ### Overview diff --git a/bindgen-integration/Cargo.toml b/bindgen-integration/Cargo.toml index 60f0426a76..ac1b03eeaa 100644 --- a/bindgen-integration/Cargo.toml +++ b/bindgen-integration/Cargo.toml @@ -14,7 +14,6 @@ cc = "1.0" static = ["bindgen/static"] runtime = ["bindgen/runtime"] -testing_only_docs = ["bindgen/testing_only_docs"] testing_only_extra_assertions = ["bindgen/testing_only_extra_assertions"] testing_only_libclang_9 = ["bindgen/testing_only_libclang_9"] testing_only_libclang_5 = ["bindgen/testing_only_libclang_5"] diff --git a/bindgen-tests/Cargo.toml b/bindgen-tests/Cargo.toml index 6df84e8e9b..ace5b3810a 100644 --- a/bindgen-tests/Cargo.toml +++ b/bindgen-tests/Cargo.toml @@ -17,7 +17,6 @@ static = ["bindgen/static"] runtime = ["bindgen/runtime"] which-rustfmt = ["bindgen/which-rustfmt"] -testing_only_docs = ["bindgen/testing_only_docs"] testing_only_extra_assertions = ["bindgen/testing_only_extra_assertions"] testing_only_libclang_9 = ["bindgen/testing_only_libclang_9"] testing_only_libclang_5 = ["bindgen/testing_only_libclang_5"] diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index c2e8543bb0..e1bdc3cbca 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -52,7 +52,6 @@ experimental = [] # These features only exist for CI testing -- don't use them if you're not hacking # on bindgen! -testing_only_docs = [] testing_only_extra_assertions = [] testing_only_libclang_9 = [] testing_only_libclang_5 = [] diff --git a/bindgen/callbacks.rs b/bindgen/callbacks.rs index dc20e2581e..b1339e4663 100644 --- a/bindgen/callbacks.rs +++ b/bindgen/callbacks.rs @@ -146,7 +146,7 @@ pub enum TypeKind { Union, } -/// An struct providing information about the item being passed to `ParseCallbacks::generated_name_override`. +/// A struct providing information about the item being passed to [`ParseCallbacks::generated_name_override`]. #[non_exhaustive] pub struct ItemInfo<'a> { /// The name of the item diff --git a/bindgen/clang.rs b/bindgen/clang.rs index 32a25449bc..62bf84f6d3 100644 --- a/bindgen/clang.rs +++ b/bindgen/clang.rs @@ -2,6 +2,7 @@ //! `clang_sys` module. #![allow(non_upper_case_globals, dead_code)] +#![deny(clippy::missing_docs_in_private_items)] use crate::ir::context::BindgenContext; use clang_sys::*; @@ -16,7 +17,7 @@ use std::{mem, ptr, slice}; /// /// Values of this type can be used to check for different attributes using the `has_attrs` /// function. -pub struct Attribute { +pub(crate) struct Attribute { name: &'static [u8], kind: Option, token_kind: CXTokenKind, @@ -24,7 +25,7 @@ pub struct Attribute { impl Attribute { /// A `warn_unused_result` attribute. - pub const MUST_USE: Self = Self { + pub(crate) const MUST_USE: Self = Self { name: b"warn_unused_result", // FIXME(emilio): clang-sys doesn't expose `CXCursor_WarnUnusedResultAttr` (from clang 9). kind: Some(440), @@ -32,14 +33,14 @@ impl Attribute { }; /// A `_Noreturn` attribute. - pub const NO_RETURN: Self = Self { + pub(crate) const NO_RETURN: Self = Self { name: b"_Noreturn", kind: None, token_kind: CXToken_Keyword, }; /// A `[[noreturn]]` attribute. - pub const NO_RETURN_CPP: Self = Self { + pub(crate) const NO_RETURN_CPP: Self = Self { name: b"noreturn", kind: None, token_kind: CXToken_Identifier, @@ -50,7 +51,7 @@ impl Attribute { /// /// We call the AST node pointed to by the cursor the cursor's "referent". #[derive(Copy, Clone)] -pub struct Cursor { +pub(crate) struct Cursor { x: CXCursor, } @@ -72,7 +73,7 @@ impl Cursor { /// available. /// /// The USR can be used to compare entities across translation units. - pub fn usr(&self) -> Option { + pub(crate) fn usr(&self) -> Option { let s = unsafe { cxstring_into_string(clang_getCursorUSR(self.x)) }; if s.is_empty() { None @@ -82,17 +83,17 @@ impl Cursor { } /// Is this cursor's referent a declaration? - pub fn is_declaration(&self) -> bool { + pub(crate) fn is_declaration(&self) -> bool { unsafe { clang_isDeclaration(self.kind()) != 0 } } /// Is this cursor's referent an anonymous record or so? - pub fn is_anonymous(&self) -> bool { + pub(crate) fn is_anonymous(&self) -> bool { unsafe { clang_Cursor_isAnonymous(self.x) != 0 } } /// Get this cursor's referent's spelling. - pub fn spelling(&self) -> String { + pub(crate) fn spelling(&self) -> String { unsafe { cxstring_into_string(clang_getCursorSpelling(self.x)) } } @@ -100,18 +101,18 @@ impl Cursor { /// /// This is not necessarily a valid identifier. It includes extra /// information, such as parameters for a function, etc. - pub fn display_name(&self) -> String { + pub(crate) fn display_name(&self) -> String { unsafe { cxstring_into_string(clang_getCursorDisplayName(self.x)) } } /// Get the mangled name of this cursor's referent. - pub fn mangling(&self) -> String { + pub(crate) fn mangling(&self) -> String { unsafe { cxstring_into_string(clang_Cursor_getMangling(self.x)) } } /// Gets the C++ manglings for this cursor, or an error if the manglings /// are not available. - pub fn cxx_manglings(&self) -> Result, ()> { + pub(crate) fn cxx_manglings(&self) -> Result, ()> { use clang_sys::*; unsafe { let manglings = clang_Cursor_getCXXManglings(self.x); @@ -131,7 +132,7 @@ impl Cursor { } /// Returns whether the cursor refers to a built-in definition. - pub fn is_builtin(&self) -> bool { + pub(crate) fn is_builtin(&self) -> bool { let (file, _, _, _) = self.location().location(); file.name().is_none() } @@ -153,7 +154,7 @@ impl Cursor { /// /// void Foo::method() { /* ... */ } /// ``` - pub fn lexical_parent(&self) -> Cursor { + pub(crate) fn lexical_parent(&self) -> Cursor { unsafe { Cursor { x: clang_getCursorLexicalParent(self.x), @@ -165,7 +166,7 @@ impl Cursor { /// /// See documentation for `lexical_parent` for details on semantic vs /// lexical parents. - pub fn fallible_semantic_parent(&self) -> Option { + pub(crate) fn fallible_semantic_parent(&self) -> Option { let sp = unsafe { Cursor { x: clang_getCursorSemanticParent(self.x), @@ -181,7 +182,7 @@ impl Cursor { /// /// See documentation for `lexical_parent` for details on semantic vs /// lexical parents. - pub fn semantic_parent(&self) -> Cursor { + pub(crate) fn semantic_parent(&self) -> Cursor { self.fallible_semantic_parent().unwrap() } @@ -191,7 +192,7 @@ impl Cursor { /// /// NOTE: This may not return `Some` for partial template specializations, /// see #193 and #194. - pub fn num_template_args(&self) -> Option { + pub(crate) fn num_template_args(&self) -> Option { // XXX: `clang_Type_getNumTemplateArguments` is sort of reliable, while // `clang_Cursor_getNumTemplateArguments` is totally unreliable. // Therefore, try former first, and only fallback to the latter if we @@ -225,7 +226,7 @@ impl Cursor { /// bindgen assumes there will only be one of them alive at a time, and /// disposes it on drop. That can change if this would be required, but I /// think we can survive fine without it. - pub fn translation_unit(&self) -> Cursor { + pub(crate) fn translation_unit(&self) -> Cursor { assert!(self.is_valid()); unsafe { let tu = clang_Cursor_getTranslationUnit(self.x); @@ -238,7 +239,7 @@ impl Cursor { } /// Is the referent a top level construct? - pub fn is_toplevel(&self) -> bool { + pub(crate) fn is_toplevel(&self) -> bool { let mut semantic_parent = self.fallible_semantic_parent(); while semantic_parent.is_some() && @@ -259,7 +260,7 @@ impl Cursor { /// There are a few kinds of types that we need to treat specially, mainly /// not tracking the type declaration but the location of the cursor, given /// clang doesn't expose a proper declaration for these types. - pub fn is_template_like(&self) -> bool { + pub(crate) fn is_template_like(&self) -> bool { matches!( self.kind(), CXCursor_ClassTemplate | @@ -269,28 +270,28 @@ impl Cursor { } /// Is this Cursor pointing to a function-like macro definition? - pub fn is_macro_function_like(&self) -> bool { + pub(crate) fn is_macro_function_like(&self) -> bool { unsafe { clang_Cursor_isMacroFunctionLike(self.x) != 0 } } /// Get the kind of referent this cursor is pointing to. - pub fn kind(&self) -> CXCursorKind { + pub(crate) fn kind(&self) -> CXCursorKind { self.x.kind } /// Returns true if the cursor is a definition - pub fn is_definition(&self) -> bool { + pub(crate) fn is_definition(&self) -> bool { unsafe { clang_isCursorDefinition(self.x) != 0 } } /// Is the referent a template specialization? - pub fn is_template_specialization(&self) -> bool { + pub(crate) fn is_template_specialization(&self) -> bool { self.specialized().is_some() } /// Is the referent a fully specialized template specialization without any /// remaining free template arguments? - pub fn is_fully_specialized_template(&self) -> bool { + pub(crate) fn is_fully_specialized_template(&self) -> bool { self.is_template_specialization() && self.kind() != CXCursor_ClassTemplatePartialSpecialization && self.num_template_args().unwrap_or(0) > 0 @@ -298,7 +299,7 @@ impl Cursor { /// Is the referent a template specialization that still has remaining free /// template arguments? - pub fn is_in_non_fully_specialized_template(&self) -> bool { + pub(crate) fn is_in_non_fully_specialized_template(&self) -> bool { if self.is_toplevel() { return false; } @@ -316,7 +317,7 @@ impl Cursor { } /// Is the referent any kind of template parameter? - pub fn is_template_parameter(&self) -> bool { + pub(crate) fn is_template_parameter(&self) -> bool { matches!( self.kind(), CXCursor_TemplateTemplateParameter | @@ -326,7 +327,7 @@ impl Cursor { } /// Does the referent's type or value depend on a template parameter? - pub fn is_dependent_on_template_parameter(&self) -> bool { + pub(crate) fn is_dependent_on_template_parameter(&self) -> bool { fn visitor( found_template_parameter: &mut bool, cur: Cursor, @@ -366,12 +367,12 @@ impl Cursor { } /// Is this cursor pointing a valid referent? - pub fn is_valid(&self) -> bool { + pub(crate) fn is_valid(&self) -> bool { unsafe { clang_isInvalid(self.kind()) == 0 } } /// Get the source location for the referent. - pub fn location(&self) -> SourceLocation { + pub(crate) fn location(&self) -> SourceLocation { unsafe { SourceLocation { x: clang_getCursorLocation(self.x), @@ -380,12 +381,12 @@ impl Cursor { } /// Get the source location range for the referent. - pub fn extent(&self) -> CXSourceRange { + pub(crate) fn extent(&self) -> CXSourceRange { unsafe { clang_getCursorExtent(self.x) } } /// Get the raw declaration comment for this referent, if one exists. - pub fn raw_comment(&self) -> Option { + pub(crate) fn raw_comment(&self) -> Option { let s = unsafe { cxstring_into_string(clang_Cursor_getRawCommentText(self.x)) }; @@ -397,7 +398,7 @@ impl Cursor { } /// Get the referent's parsed comment. - pub fn comment(&self) -> Comment { + pub(crate) fn comment(&self) -> Comment { unsafe { Comment { x: clang_Cursor_getParsedComment(self.x), @@ -406,7 +407,7 @@ impl Cursor { } /// Get the referent's type. - pub fn cur_type(&self) -> Type { + pub(crate) fn cur_type(&self) -> Type { unsafe { Type { x: clang_getCursorType(self.x), @@ -417,7 +418,7 @@ impl Cursor { /// Given that this cursor's referent is a reference to another type, or is /// a declaration, get the cursor pointing to the referenced type or type of /// the declared thing. - pub fn definition(&self) -> Option { + pub(crate) fn definition(&self) -> Option { unsafe { let ret = Cursor { x: clang_getCursorDefinition(self.x), @@ -433,7 +434,7 @@ impl Cursor { /// Given that this cursor's referent is reference type, get the cursor /// pointing to the referenced type. - pub fn referenced(&self) -> Option { + pub(crate) fn referenced(&self) -> Option { unsafe { let ret = Cursor { x: clang_getCursorReferenced(self.x), @@ -452,7 +453,7 @@ impl Cursor { /// Many types can be declared multiple times before finally being properly /// defined. This method allows us to get the canonical cursor for the /// referent type. - pub fn canonical(&self) -> Cursor { + pub(crate) fn canonical(&self) -> Cursor { unsafe { Cursor { x: clang_getCanonicalCursor(self.x), @@ -463,7 +464,7 @@ impl Cursor { /// Given that this cursor points to either a template specialization or a /// template instantiation, get a cursor pointing to the template definition /// that is being specialized. - pub fn specialized(&self) -> Option { + pub(crate) fn specialized(&self) -> Option { unsafe { let ret = Cursor { x: clang_getSpecializedCursorTemplate(self.x), @@ -478,14 +479,14 @@ impl Cursor { /// Assuming that this cursor's referent is a template declaration, get the /// kind of cursor that would be generated for its specializations. - pub fn template_kind(&self) -> CXCursorKind { + pub(crate) fn template_kind(&self) -> CXCursorKind { unsafe { clang_getTemplateCursorKind(self.x) } } /// Traverse this cursor's referent and its children. /// /// Call the given function on each AST node traversed. - pub fn visit(&self, mut visitor: Visitor) + pub(crate) fn visit(&self, mut visitor: Visitor) where Visitor: FnMut(Cursor) -> CXChildVisitResult, { @@ -496,7 +497,7 @@ impl Cursor { } /// Collect all of this cursor's children into a vec and return them. - pub fn collect_children(&self) -> Vec { + pub(crate) fn collect_children(&self) -> Vec { let mut children = vec![]; self.visit(|c| { children.push(c); @@ -506,7 +507,7 @@ impl Cursor { } /// Does this cursor have any children? - pub fn has_children(&self) -> bool { + pub(crate) fn has_children(&self) -> bool { let mut has_children = false; self.visit(|_| { has_children = true; @@ -516,7 +517,7 @@ impl Cursor { } /// Does this cursor have at least `n` children? - pub fn has_at_least_num_children(&self, n: usize) -> bool { + pub(crate) fn has_at_least_num_children(&self, n: usize) -> bool { assert!(n > 0); let mut num_left = n; self.visit(|_| { @@ -533,7 +534,7 @@ impl Cursor { /// Returns whether the given location contains a cursor with the given /// kind in the first level of nesting underneath (doesn't look /// recursively). - pub fn contains_cursor(&self, kind: CXCursorKind) -> bool { + pub(crate) fn contains_cursor(&self, kind: CXCursorKind) -> bool { let mut found = false; self.visit(|c| { @@ -549,17 +550,17 @@ impl Cursor { } /// Is the referent an inlined function? - pub fn is_inlined_function(&self) -> bool { + pub(crate) fn is_inlined_function(&self) -> bool { unsafe { clang_Cursor_isFunctionInlined(self.x) != 0 } } /// Is the referent a defaulted function? - pub fn is_defaulted_function(&self) -> bool { + pub(crate) fn is_defaulted_function(&self) -> bool { unsafe { clang_CXXMethod_isDefaulted(self.x) != 0 } } /// Is the referent a deleted function? - pub fn is_deleted_function(&self) -> bool { + pub(crate) fn is_deleted_function(&self) -> bool { // Unfortunately, libclang doesn't yet have an API for checking if a // member function is deleted, but the following should be a good // enough approximation. @@ -575,13 +576,13 @@ impl Cursor { } /// Is the referent a bit field declaration? - pub fn is_bit_field(&self) -> bool { + pub(crate) fn is_bit_field(&self) -> bool { unsafe { clang_Cursor_isBitField(self.x) != 0 } } /// Get a cursor to the bit field's width expression, or `None` if it's not /// a bit field. - pub fn bit_width_expr(&self) -> Option { + pub(crate) fn bit_width_expr(&self) -> Option { if !self.is_bit_field() { return None; } @@ -605,7 +606,7 @@ impl Cursor { /// Get the width of this cursor's referent bit field, or `None` if the /// referent is not a bit field or if the width could not be evaluated. - pub fn bit_width(&self) -> Option { + pub(crate) fn bit_width(&self) -> Option { // It is not safe to check the bit width without ensuring it doesn't // depend on a template parameter. See // https://github.com/rust-lang/rust-bindgen/issues/2239 @@ -625,7 +626,7 @@ impl Cursor { /// Get the integer representation type used to hold this cursor's referent /// enum type. - pub fn enum_type(&self) -> Option { + pub(crate) fn enum_type(&self) -> Option { unsafe { let t = Type { x: clang_getEnumDeclIntegerType(self.x), @@ -641,7 +642,7 @@ impl Cursor { /// Get the boolean constant value for this cursor's enum variant referent. /// /// Returns None if the cursor's referent is not an enum variant. - pub fn enum_val_boolean(&self) -> Option { + pub(crate) fn enum_val_boolean(&self) -> Option { unsafe { if self.kind() == CXCursor_EnumConstantDecl { Some(clang_getEnumConstantDeclValue(self.x) != 0) @@ -654,7 +655,7 @@ impl Cursor { /// Get the signed constant value for this cursor's enum variant referent. /// /// Returns None if the cursor's referent is not an enum variant. - pub fn enum_val_signed(&self) -> Option { + pub(crate) fn enum_val_signed(&self) -> Option { unsafe { if self.kind() == CXCursor_EnumConstantDecl { #[allow(clippy::unnecessary_cast)] @@ -668,7 +669,7 @@ impl Cursor { /// Get the unsigned constant value for this cursor's enum variant referent. /// /// Returns None if the cursor's referent is not an enum variant. - pub fn enum_val_unsigned(&self) -> Option { + pub(crate) fn enum_val_unsigned(&self) -> Option { unsafe { if self.kind() == CXCursor_EnumConstantDecl { #[allow(clippy::unnecessary_cast)] @@ -680,7 +681,7 @@ impl Cursor { } /// Does this cursor have the given attributes? - pub fn has_attrs( + pub(crate) fn has_attrs( &self, attrs: &[Attribute; N], ) -> [bool; N] { @@ -718,7 +719,7 @@ impl Cursor { /// Given that this cursor's referent is a `typedef`, get the `Type` that is /// being aliased. - pub fn typedef_type(&self) -> Option { + pub(crate) fn typedef_type(&self) -> Option { let inner = Type { x: unsafe { clang_getTypedefDeclUnderlyingType(self.x) }, }; @@ -733,12 +734,12 @@ impl Cursor { /// Get the linkage kind for this cursor's referent. /// /// This only applies to functions and variables. - pub fn linkage(&self) -> CXLinkageKind { + pub(crate) fn linkage(&self) -> CXLinkageKind { unsafe { clang_getCursorLinkage(self.x) } } /// Get the visibility of this cursor's referent. - pub fn visibility(&self) -> CXVisibilityKind { + pub(crate) fn visibility(&self) -> CXVisibilityKind { unsafe { clang_getCursorVisibility(self.x) } } @@ -747,7 +748,7 @@ impl Cursor { /// /// Returns None if the cursor's referent is not a function/method call or /// declaration. - pub fn args(&self) -> Option> { + pub(crate) fn args(&self) -> Option> { // match self.kind() { // CXCursor_FunctionDecl | // CXCursor_CXXMethod => { @@ -765,7 +766,7 @@ impl Cursor { /// /// Returns Err if the cursor's referent is not a function/method call or /// declaration. - pub fn num_args(&self) -> Result { + pub(crate) fn num_args(&self) -> Result { unsafe { let w = clang_Cursor_getNumArguments(self.x); if w == -1 { @@ -777,7 +778,7 @@ impl Cursor { } /// Get the access specifier for this cursor's referent. - pub fn access_specifier(&self) -> CX_CXXAccessSpecifier { + pub(crate) fn access_specifier(&self) -> CX_CXXAccessSpecifier { unsafe { clang_getCXXAccessSpecifier(self.x) } } @@ -785,19 +786,19 @@ impl Cursor { /// /// Returns true if self.access_specifier() is `CX_CXXPublic` or /// `CX_CXXInvalidAccessSpecifier`. - pub fn public_accessible(&self) -> bool { + pub(crate) fn public_accessible(&self) -> bool { let access = self.access_specifier(); access == CX_CXXPublic || access == CX_CXXInvalidAccessSpecifier } /// Is this cursor's referent a field declaration that is marked as /// `mutable`? - pub fn is_mutable_field(&self) -> bool { + pub(crate) fn is_mutable_field(&self) -> bool { unsafe { clang_CXXField_isMutable(self.x) != 0 } } /// Get the offset of the field represented by the Cursor. - pub fn offset_of_field(&self) -> Result { + pub(crate) fn offset_of_field(&self) -> Result { let offset = unsafe { clang_Cursor_getOffsetOfField(self.x) }; if offset < 0 { @@ -808,37 +809,37 @@ impl Cursor { } /// Is this cursor's referent a member function that is declared `static`? - pub fn method_is_static(&self) -> bool { + pub(crate) fn method_is_static(&self) -> bool { unsafe { clang_CXXMethod_isStatic(self.x) != 0 } } /// Is this cursor's referent a member function that is declared `const`? - pub fn method_is_const(&self) -> bool { + pub(crate) fn method_is_const(&self) -> bool { unsafe { clang_CXXMethod_isConst(self.x) != 0 } } /// Is this cursor's referent a member function that is virtual? - pub fn method_is_virtual(&self) -> bool { + pub(crate) fn method_is_virtual(&self) -> bool { unsafe { clang_CXXMethod_isVirtual(self.x) != 0 } } /// Is this cursor's referent a member function that is pure virtual? - pub fn method_is_pure_virtual(&self) -> bool { + pub(crate) fn method_is_pure_virtual(&self) -> bool { unsafe { clang_CXXMethod_isPureVirtual(self.x) != 0 } } /// Is this cursor's referent a struct or class with virtual members? - pub fn is_virtual_base(&self) -> bool { + pub(crate) fn is_virtual_base(&self) -> bool { unsafe { clang_isVirtualBase(self.x) != 0 } } /// Try to evaluate this cursor. - pub fn evaluate(&self) -> Option { + pub(crate) fn evaluate(&self) -> Option { EvalResult::new(*self) } /// Return the result type for this cursor - pub fn ret_type(&self) -> Option { + pub(crate) fn ret_type(&self) -> Option { let rt = Type { x: unsafe { clang_getCursorResultType(self.x) }, }; @@ -850,12 +851,12 @@ impl Cursor { } /// Gets the tokens that correspond to that cursor. - pub fn tokens(&self) -> RawTokens { + pub(crate) fn tokens(&self) -> RawTokens { RawTokens::new(self) } /// Gets the tokens that correspond to that cursor as `cexpr` tokens. - pub fn cexpr_tokens(self) -> Vec { + pub(crate) fn cexpr_tokens(self) -> Vec { self.tokens() .iter() .filter_map(|token| token.as_cexpr_token()) @@ -865,7 +866,7 @@ impl Cursor { /// Obtain the real path name of a cursor of InclusionDirective kind. /// /// Returns None if the cursor does not include a file, otherwise the file's full name - pub fn get_included_file_name(&self) -> Option { + pub(crate) fn get_included_file_name(&self) -> Option { let file = unsafe { clang_sys::clang_getIncludedFile(self.x) }; if file.is_null() { None @@ -878,7 +879,7 @@ impl Cursor { } /// A struct that owns the tokenizer result from a given cursor. -pub struct RawTokens<'a> { +pub(crate) struct RawTokens<'a> { cursor: &'a Cursor, tu: CXTranslationUnit, tokens: *mut CXToken, @@ -908,7 +909,7 @@ impl<'a> RawTokens<'a> { } /// Get an iterator over these tokens. - pub fn iter(&self) -> ClangTokenIterator { + pub(crate) fn iter(&self) -> ClangTokenIterator { ClangTokenIterator { tu: self.tu, raw: self.as_slice().iter(), @@ -934,19 +935,19 @@ impl<'a> Drop for RawTokens<'a> { /// slightly more convenient version of `CXToken` which owns the spelling /// string and extent. #[derive(Debug)] -pub struct ClangToken { +pub(crate) struct ClangToken { spelling: CXString, /// The extent of the token. This is the same as the relevant member from /// `CXToken`. - pub extent: CXSourceRange, + pub(crate) extent: CXSourceRange, /// The kind of the token. This is the same as the relevant member from /// `CXToken`. - pub kind: CXTokenKind, + pub(crate) kind: CXTokenKind, } impl ClangToken { /// Get the token spelling, without being converted to utf-8. - pub fn spelling(&self) -> &[u8] { + pub(crate) fn spelling(&self) -> &[u8] { let c_str = unsafe { CStr::from_ptr(clang_getCString(self.spelling) as *const _) }; @@ -954,7 +955,7 @@ impl ClangToken { } /// Converts a ClangToken to a `cexpr` token if possible. - pub fn as_cexpr_token(&self) -> Option { + pub(crate) fn as_cexpr_token(&self) -> Option { use cexpr::token; let kind = match self.kind { @@ -985,7 +986,7 @@ impl Drop for ClangToken { } /// An iterator over a set of Tokens. -pub struct ClangTokenIterator<'a> { +pub(crate) struct ClangTokenIterator<'a> { tu: CXTranslationUnit, raw: slice::Iter<'a, CXToken>, } @@ -1010,7 +1011,7 @@ impl<'a> Iterator for ClangTokenIterator<'a> { /// Checks whether the name looks like an identifier, i.e. is alphanumeric /// (including '_') and does not start with a digit. -pub fn is_valid_identifier(name: &str) -> bool { +pub(crate) fn is_valid_identifier(name: &str) -> bool { let mut chars = name.chars(); let first_valid = chars .next() @@ -1050,7 +1051,7 @@ impl Hash for Cursor { /// The type of a node in clang's AST. #[derive(Clone, Copy)] -pub struct Type { +pub(crate) struct Type { x: CXType, } @@ -1078,7 +1079,7 @@ impl fmt::Debug for Type { /// An error about the layout of a struct, class, or type. #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] -pub enum LayoutError { +pub(crate) enum LayoutError { /// Asked for the layout of an invalid type. Invalid, /// Asked for the layout of an incomplete type. @@ -1111,12 +1112,12 @@ impl ::std::convert::From for LayoutError { impl Type { /// Get this type's kind. - pub fn kind(&self) -> CXTypeKind { + pub(crate) fn kind(&self) -> CXTypeKind { self.x.kind } /// Get a cursor pointing to this type's declaration. - pub fn declaration(&self) -> Cursor { + pub(crate) fn declaration(&self) -> Cursor { unsafe { Cursor { x: clang_getTypeDeclaration(self.x), @@ -1125,7 +1126,7 @@ impl Type { } /// Get the canonical declaration of this type, if it is available. - pub fn canonical_declaration( + pub(crate) fn canonical_declaration( &self, location: Option<&Cursor>, ) -> Option { @@ -1151,7 +1152,7 @@ impl Type { } /// Get a raw display name for this type. - pub fn spelling(&self) -> String { + pub(crate) fn spelling(&self) -> String { let s = unsafe { cxstring_into_string(clang_getTypeSpelling(self.x)) }; // Clang 5.0 introduced changes in the spelling API so it returned the // full qualified name. Let's undo that here. @@ -1165,7 +1166,7 @@ impl Type { } /// Is this type const qualified? - pub fn is_const(&self) -> bool { + pub(crate) fn is_const(&self) -> bool { unsafe { clang_isConstQualifiedType(self.x) != 0 } } @@ -1203,7 +1204,7 @@ impl Type { /// What is the size of this type? Paper over invalid types by returning `0` /// for them. - pub fn size(&self, ctx: &BindgenContext) -> usize { + pub(crate) fn size(&self, ctx: &BindgenContext) -> usize { let val = self.clang_size_of(ctx); if val < 0 { 0 @@ -1213,7 +1214,7 @@ impl Type { } /// What is the size of this type? - pub fn fallible_size( + pub(crate) fn fallible_size( &self, ctx: &BindgenContext, ) -> Result { @@ -1227,7 +1228,7 @@ impl Type { /// What is the alignment of this type? Paper over invalid types by /// returning `0`. - pub fn align(&self, ctx: &BindgenContext) -> usize { + pub(crate) fn align(&self, ctx: &BindgenContext) -> usize { let val = self.clang_align_of(ctx); if val < 0 { 0 @@ -1237,7 +1238,7 @@ impl Type { } /// What is the alignment of this type? - pub fn fallible_align( + pub(crate) fn fallible_align( &self, ctx: &BindgenContext, ) -> Result { @@ -1251,7 +1252,7 @@ impl Type { /// Get the layout for this type, or an error describing why it does not /// have a valid layout. - pub fn fallible_layout( + pub(crate) fn fallible_layout( &self, ctx: &BindgenContext, ) -> Result { @@ -1263,7 +1264,7 @@ impl Type { /// Get the number of template arguments this type has, or `None` if it is /// not some kind of template. - pub fn num_template_args(&self) -> Option { + pub(crate) fn num_template_args(&self) -> Option { let n = unsafe { clang_Type_getNumTemplateArguments(self.x) }; if n >= 0 { Some(n as u32) @@ -1275,7 +1276,7 @@ impl Type { /// If this type is a class template specialization, return its /// template arguments. Otherwise, return None. - pub fn template_args(&self) -> Option { + pub(crate) fn template_args(&self) -> Option { self.num_template_args().map(|n| TypeTemplateArgIterator { x: self.x, length: n, @@ -1286,7 +1287,7 @@ impl Type { /// Given that this type is a function prototype, return the types of its parameters. /// /// Returns None if the type is not a function prototype. - pub fn args(&self) -> Option> { + pub(crate) fn args(&self) -> Option> { self.num_args().ok().map(|num| { (0..num) .map(|i| Type { @@ -1299,7 +1300,7 @@ impl Type { /// Given that this type is a function prototype, return the number of arguments it takes. /// /// Returns Err if the type is not a function prototype. - pub fn num_args(&self) -> Result { + pub(crate) fn num_args(&self) -> Result { unsafe { let w = clang_getNumArgTypes(self.x); if w == -1 { @@ -1312,7 +1313,7 @@ impl Type { /// Given that this type is a pointer type, return the type that it points /// to. - pub fn pointee_type(&self) -> Option { + pub(crate) fn pointee_type(&self) -> Option { match self.kind() { CXType_Pointer | CXType_RValueReference | @@ -1332,7 +1333,7 @@ impl Type { /// Given that this type is an array, vector, or complex type, return the /// type of its elements. - pub fn elem_type(&self) -> Option { + pub(crate) fn elem_type(&self) -> Option { let current_type = Type { x: unsafe { clang_getElementType(self.x) }, }; @@ -1345,7 +1346,7 @@ impl Type { /// Given that this type is an array or vector type, return its number of /// elements. - pub fn num_elements(&self) -> Option { + pub(crate) fn num_elements(&self) -> Option { let num_elements_returned = unsafe { clang_getNumElements(self.x) }; if num_elements_returned != -1 { Some(num_elements_returned as usize) @@ -1356,7 +1357,7 @@ impl Type { /// Get the canonical version of this type. This sees through `typedef`s and /// aliases to get the underlying, canonical type. - pub fn canonical_type(&self) -> Type { + pub(crate) fn canonical_type(&self) -> Type { unsafe { Type { x: clang_getCanonicalType(self.x), @@ -1365,13 +1366,13 @@ impl Type { } /// Is this type a variadic function type? - pub fn is_variadic(&self) -> bool { + pub(crate) fn is_variadic(&self) -> bool { unsafe { clang_isFunctionTypeVariadic(self.x) != 0 } } /// Given that this type is a function type, get the type of its return /// value. - pub fn ret_type(&self) -> Option { + pub(crate) fn ret_type(&self) -> Option { let rt = Type { x: unsafe { clang_getResultType(self.x) }, }; @@ -1384,13 +1385,13 @@ impl Type { /// Given that this type is a function type, get its calling convention. If /// this is not a function type, `CXCallingConv_Invalid` is returned. - pub fn call_conv(&self) -> CXCallingConv { + pub(crate) fn call_conv(&self) -> CXCallingConv { unsafe { clang_getFunctionTypeCallingConv(self.x) } } /// For elaborated types (types which use `class`, `struct`, or `union` to /// disambiguate types from local bindings), get the underlying type. - pub fn named(&self) -> Type { + pub(crate) fn named(&self) -> Type { unsafe { Type { x: clang_Type_getNamedType(self.x), @@ -1399,17 +1400,17 @@ impl Type { } /// Is this a valid type? - pub fn is_valid(&self) -> bool { + pub(crate) fn is_valid(&self) -> bool { self.kind() != CXType_Invalid } /// Is this a valid and exposed type? - pub fn is_valid_and_exposed(&self) -> bool { + pub(crate) fn is_valid_and_exposed(&self) -> bool { self.is_valid() && self.kind() != CXType_Unexposed } /// Is this type a fully instantiated template? - pub fn is_fully_instantiated_template(&self) -> bool { + pub(crate) fn is_fully_instantiated_template(&self) -> bool { // Yep, the spelling of this containing type-parameter is extremely // nasty... But can happen in . Unfortunately I couldn't // reduce it enough :( @@ -1431,7 +1432,7 @@ impl Type { /// typename T::Associated member; /// }; /// ``` - pub fn is_associated_type(&self) -> bool { + pub(crate) fn is_associated_type(&self) -> bool { // This is terrible :( fn hacky_parse_associated_type>(spelling: S) -> bool { lazy_static! { @@ -1457,22 +1458,22 @@ impl Type { /// cursor match up in a canonical declaration relationship, and it simply /// cannot be otherwise. #[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub struct CanonicalTypeDeclaration(Type, Cursor); +pub(crate) struct CanonicalTypeDeclaration(Type, Cursor); impl CanonicalTypeDeclaration { /// Get the type. - pub fn ty(&self) -> &Type { + pub(crate) fn ty(&self) -> &Type { &self.0 } /// Get the type's canonical declaration cursor. - pub fn cursor(&self) -> &Cursor { + pub(crate) fn cursor(&self) -> &Cursor { &self.1 } } /// An iterator for a type's template arguments. -pub struct TypeTemplateArgIterator { +pub(crate) struct TypeTemplateArgIterator { x: CXType, length: u32, index: u32, @@ -1502,14 +1503,14 @@ impl ExactSizeIterator for TypeTemplateArgIterator { /// A `SourceLocation` is a file, line, column, and byte offset location for /// some source text. -pub struct SourceLocation { +pub(crate) struct SourceLocation { x: CXSourceLocation, } impl SourceLocation { /// Get the (file, line, column, byte offset) tuple for this source /// location. - pub fn location(&self) -> (File, usize, usize, usize) { + pub(crate) fn location(&self) -> (File, usize, usize, usize) { unsafe { let mut file = mem::zeroed(); let mut line = 0; @@ -1543,18 +1544,18 @@ impl fmt::Debug for SourceLocation { /// A comment in the source text. /// /// Comments are sort of parsed by Clang, and have a tree structure. -pub struct Comment { +pub(crate) struct Comment { x: CXComment, } impl Comment { /// What kind of comment is this? - pub fn kind(&self) -> CXCommentKind { + pub(crate) fn kind(&self) -> CXCommentKind { unsafe { clang_Comment_getKind(self.x) } } /// Get this comment's children comment - pub fn get_children(&self) -> CommentChildrenIterator { + pub(crate) fn get_children(&self) -> CommentChildrenIterator { CommentChildrenIterator { parent: self.x, length: unsafe { clang_Comment_getNumChildren(self.x) }, @@ -1564,12 +1565,12 @@ impl Comment { /// Given that this comment is the start or end of an HTML tag, get its tag /// name. - pub fn get_tag_name(&self) -> String { + pub(crate) fn get_tag_name(&self) -> String { unsafe { cxstring_into_string(clang_HTMLTagComment_getTagName(self.x)) } } /// Given that this comment is an HTML start tag, get its attributes. - pub fn get_tag_attrs(&self) -> CommentAttributesIterator { + pub(crate) fn get_tag_attrs(&self) -> CommentAttributesIterator { CommentAttributesIterator { x: self.x, length: unsafe { clang_HTMLStartTag_getNumAttrs(self.x) }, @@ -1579,7 +1580,7 @@ impl Comment { } /// An iterator for a comment's children -pub struct CommentChildrenIterator { +pub(crate) struct CommentChildrenIterator { parent: CXComment, length: c_uint, index: c_uint, @@ -1601,15 +1602,15 @@ impl Iterator for CommentChildrenIterator { } /// An HTML start tag comment attribute -pub struct CommentAttribute { +pub(crate) struct CommentAttribute { /// HTML start tag attribute name - pub name: String, + pub(crate) name: String, /// HTML start tag attribute value - pub value: String, + pub(crate) value: String, } /// An iterator for a comment's attributes -pub struct CommentAttributesIterator { +pub(crate) struct CommentAttributesIterator { x: CXComment, length: c_uint, index: c_uint, @@ -1640,13 +1641,13 @@ impl Iterator for CommentAttributesIterator { } /// A source file. -pub struct File { +pub(crate) struct File { x: CXFile, } impl File { /// Get the name of this source file. - pub fn name(&self) -> Option { + pub(crate) fn name(&self) -> Option { if self.x.is_null() { return None; } @@ -1670,7 +1671,7 @@ fn cxstring_into_string(s: CXString) -> String { /// An `Index` is an environment for a set of translation units that will /// typically end up linked together in one final binary. -pub struct Index { +pub(crate) struct Index { x: CXIndex, } @@ -1681,7 +1682,7 @@ impl Index { /// headers are included when enumerating a translation unit's "locals". /// /// The `diag` parameter controls whether debugging diagnostics are enabled. - pub fn new(pch: bool, diag: bool) -> Index { + pub(crate) fn new(pch: bool, diag: bool) -> Index { unsafe { Index { x: clang_createIndex(pch as c_int, diag as c_int), @@ -1705,7 +1706,7 @@ impl Drop for Index { } /// A translation unit (or "compilation unit"). -pub struct TranslationUnit { +pub(crate) struct TranslationUnit { x: CXTranslationUnit, } @@ -1717,7 +1718,7 @@ impl fmt::Debug for TranslationUnit { impl TranslationUnit { /// Parse a source file into a translation unit. - pub fn parse( + pub(crate) fn parse( ix: &Index, file: &str, cmd_args: &[String], @@ -1753,7 +1754,7 @@ impl TranslationUnit { /// Get the Clang diagnostic information associated with this translation /// unit. - pub fn diags(&self) -> Vec { + pub(crate) fn diags(&self) -> Vec { unsafe { let num = clang_getNumDiagnostics(self.x) as usize; let mut diags = vec![]; @@ -1767,7 +1768,7 @@ impl TranslationUnit { } /// Get a cursor pointing to the root of this translation unit's AST. - pub fn cursor(&self) -> Cursor { + pub(crate) fn cursor(&self) -> Cursor { unsafe { Cursor { x: clang_getTranslationUnitCursor(self.x), @@ -1776,7 +1777,7 @@ impl TranslationUnit { } /// Is this the null translation unit? - pub fn is_null(&self) -> bool { + pub(crate) fn is_null(&self) -> bool { self.x.is_null() } } @@ -1790,14 +1791,14 @@ impl Drop for TranslationUnit { } /// A diagnostic message generated while parsing a translation unit. -pub struct Diagnostic { +pub(crate) struct Diagnostic { x: CXDiagnostic, } impl Diagnostic { /// Format this diagnostic message as a string, using the given option bit /// flags. - pub fn format(&self) -> String { + pub(crate) fn format(&self) -> String { unsafe { let opts = clang_defaultDiagnosticDisplayOptions(); cxstring_into_string(clang_formatDiagnostic(self.x, opts)) @@ -1805,7 +1806,7 @@ impl Diagnostic { } /// What is the severity of this diagnostic message? - pub fn severity(&self) -> CXDiagnosticSeverity { + pub(crate) fn severity(&self) -> CXDiagnosticSeverity { unsafe { clang_getDiagnosticSeverity(self.x) } } } @@ -1820,17 +1821,17 @@ impl Drop for Diagnostic { } /// A file which has not been saved to disk. -pub struct UnsavedFile { +pub(crate) struct UnsavedFile { x: CXUnsavedFile, /// The name of the unsaved file. Kept here to avoid leaving dangling pointers in /// `CXUnsavedFile`. - pub name: CString, + pub(crate) name: CString, contents: CString, } impl UnsavedFile { /// Construct a new unsaved file with the given `name` and `contents`. - pub fn new(name: String, contents: String) -> UnsavedFile { + pub(crate) fn new(name: String, contents: String) -> UnsavedFile { let name = CString::new(name).unwrap(); let contents = CString::new(contents).unwrap(); let x = CXUnsavedFile { @@ -1853,17 +1854,17 @@ impl fmt::Debug for UnsavedFile { } /// Convert a cursor kind into a static string. -pub fn kind_to_str(x: CXCursorKind) -> String { +pub(crate) fn kind_to_str(x: CXCursorKind) -> String { unsafe { cxstring_into_string(clang_getCursorKindSpelling(x)) } } /// Convert a type kind to a static string. -pub fn type_to_str(x: CXTypeKind) -> String { +pub(crate) fn type_to_str(x: CXTypeKind) -> String { unsafe { cxstring_into_string(clang_getTypeKindSpelling(x)) } } /// Dump the Clang AST to stdout for debugging purposes. -pub fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult { +pub(crate) fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult { fn print_indent>(depth: isize, s: S) { for _ in 0..depth { print!(" "); @@ -2095,19 +2096,19 @@ pub fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult { } /// Try to extract the clang version to a string -pub fn extract_clang_version() -> String { +pub(crate) fn extract_clang_version() -> String { unsafe { cxstring_into_string(clang_getClangVersion()) } } /// A wrapper for the result of evaluating an expression. #[derive(Debug)] -pub struct EvalResult { +pub(crate) struct EvalResult { x: CXEvalResult, } impl EvalResult { /// Evaluate `cursor` and return the result. - pub fn new(cursor: Cursor) -> Option { + pub(crate) fn new(cursor: Cursor) -> Option { // Work around https://bugs.llvm.org/show_bug.cgi?id=42532, see: // * https://github.com/rust-lang/rust-bindgen/issues/283 // * https://github.com/rust-lang/rust-bindgen/issues/1590 @@ -2138,7 +2139,7 @@ impl EvalResult { } /// Try to get back the result as a double. - pub fn as_double(&self) -> Option { + pub(crate) fn as_double(&self) -> Option { match self.kind() { CXEval_Float => { Some(unsafe { clang_EvalResult_getAsDouble(self.x) }) @@ -2148,7 +2149,7 @@ impl EvalResult { } /// Try to get back the result as an integer. - pub fn as_int(&self) -> Option { + pub(crate) fn as_int(&self) -> Option { if self.kind() != CXEval_Int { return None; } @@ -2175,7 +2176,7 @@ impl EvalResult { /// Evaluates the expression as a literal string, that may or may not be /// valid utf-8. - pub fn as_literal_string(&self) -> Option> { + pub(crate) fn as_literal_string(&self) -> Option> { match self.kind() { CXEval_StrLiteral => { let ret = unsafe { @@ -2196,16 +2197,16 @@ impl Drop for EvalResult { /// Target information obtained from libclang. #[derive(Debug)] -pub struct TargetInfo { +pub(crate) struct TargetInfo { /// The target triple. - pub triple: String, + pub(crate) triple: String, /// The width of the pointer _in bits_. - pub pointer_width: usize, + pub(crate) pointer_width: usize, } impl TargetInfo { /// Tries to obtain target information from libclang. - pub fn new(tu: &TranslationUnit) -> Self { + pub(crate) fn new(tu: &TranslationUnit) -> Self { let triple; let pointer_width; unsafe { diff --git a/bindgen/codegen/dyngen.rs b/bindgen/codegen/dyngen.rs index d8ea81175e..c067fada0e 100644 --- a/bindgen/codegen/dyngen.rs +++ b/bindgen/codegen/dyngen.rs @@ -5,7 +5,7 @@ use proc_macro2::Ident; /// Used to build the output tokens for dynamic bindings. #[derive(Default)] -pub struct DynamicItems { +pub(crate) struct DynamicItems { /// Tracks the tokens that will appears inside the library struct -- e.g.: /// ```ignore /// struct Lib { @@ -69,11 +69,11 @@ pub struct DynamicItems { } impl DynamicItems { - pub fn new() -> Self { + pub(crate) fn new() -> Self { Self::default() } - pub fn get_tokens( + pub(crate) fn get_tokens( &self, lib_ident: Ident, ctx: &BindgenContext, diff --git a/bindgen/codegen/error.rs b/bindgen/codegen/error.rs index c1bcf4e1cb..ead34965ba 100644 --- a/bindgen/codegen/error.rs +++ b/bindgen/codegen/error.rs @@ -3,7 +3,7 @@ use std::fmt; /// Errors that can occur during code generation. #[derive(Clone, Debug, PartialEq, Eq)] -pub enum Error { +pub(crate) enum Error { /// Tried to generate an opaque blob for a type that did not have a layout. NoLayoutForOpaqueBlob, @@ -30,4 +30,4 @@ impl fmt::Display for Error { impl error::Error for Error {} /// A `Result` of `T` or an error of `bindgen::codegen::error::Error`. -pub type Result = ::std::result::Result; +pub(crate) type Result = ::std::result::Result; diff --git a/bindgen/codegen/helpers.rs b/bindgen/codegen/helpers.rs index 088c7f9363..9c907ae23e 100644 --- a/bindgen/codegen/helpers.rs +++ b/bindgen/codegen/helpers.rs @@ -5,18 +5,18 @@ use crate::ir::layout::Layout; use proc_macro2::{Ident, Span, TokenStream}; use quote::TokenStreamExt; -pub mod attributes { +pub(crate) mod attributes { use proc_macro2::{Ident, Span, TokenStream}; use std::str::FromStr; - pub fn repr(which: &str) -> TokenStream { + pub(crate) fn repr(which: &str) -> TokenStream { let which = Ident::new(which, Span::call_site()); quote! { #[repr( #which )] } } - pub fn repr_list(which_ones: &[&str]) -> TokenStream { + pub(crate) fn repr_list(which_ones: &[&str]) -> TokenStream { let which_ones = which_ones .iter() .cloned() @@ -26,7 +26,7 @@ pub mod attributes { } } - pub fn derives(which_ones: &[&str]) -> TokenStream { + pub(crate) fn derives(which_ones: &[&str]) -> TokenStream { let which_ones = which_ones .iter() .cloned() @@ -36,25 +36,25 @@ pub mod attributes { } } - pub fn inline() -> TokenStream { + pub(crate) fn inline() -> TokenStream { quote! { #[inline] } } - pub fn must_use() -> TokenStream { + pub(crate) fn must_use() -> TokenStream { quote! { #[must_use] } } - pub fn non_exhaustive() -> TokenStream { + pub(crate) fn non_exhaustive() -> TokenStream { quote! { #[non_exhaustive] } } - pub fn doc(comment: String) -> TokenStream { + pub(crate) fn doc(comment: String) -> TokenStream { if comment.is_empty() { quote!() } else { @@ -62,7 +62,7 @@ pub mod attributes { } } - pub fn link_name(name: &str) -> TokenStream { + pub(crate) fn link_name(name: &str) -> TokenStream { // LLVM mangles the name by default but it's already mangled. // Prefixing the name with \u{1} should tell LLVM to not mangle it. let name = format!("\u{1}{}", name); @@ -74,7 +74,7 @@ pub mod attributes { /// Generates a proper type for a field or type with a given `Layout`, that is, /// a type with the correct size and alignment restrictions. -pub fn blob(ctx: &BindgenContext, layout: Layout) -> TokenStream { +pub(crate) fn blob(ctx: &BindgenContext, layout: Layout) -> TokenStream { let opaque = layout.opaque(); // FIXME(emilio, #412): We fall back to byte alignment, but there are @@ -105,7 +105,7 @@ pub fn blob(ctx: &BindgenContext, layout: Layout) -> TokenStream { } /// Integer type of the same size as the given `Layout`. -pub fn integer_type( +pub(crate) fn integer_type( ctx: &BindgenContext, layout: Layout, ) -> Option { @@ -115,7 +115,10 @@ pub fn integer_type( } /// Generates a bitfield allocation unit type for a type with the given `Layout`. -pub fn bitfield_unit(ctx: &BindgenContext, layout: Layout) -> TokenStream { +pub(crate) fn bitfield_unit( + ctx: &BindgenContext, + layout: Layout, +) -> TokenStream { let mut tokens = quote! {}; if ctx.options().enable_cxx_namespaces { @@ -130,7 +133,7 @@ pub fn bitfield_unit(ctx: &BindgenContext, layout: Layout) -> TokenStream { tokens } -pub mod ast_ty { +pub(crate) mod ast_ty { use crate::ir::context::BindgenContext; use crate::ir::function::FunctionSig; use crate::ir::layout::Layout; @@ -138,7 +141,7 @@ pub mod ast_ty { use proc_macro2::{self, TokenStream}; use std::str::FromStr; - pub fn c_void(ctx: &BindgenContext) -> TokenStream { + pub(crate) fn c_void(ctx: &BindgenContext) -> TokenStream { // ctypes_prefix takes precedence match ctx.options().ctypes_prefix { Some(ref prefix) => { @@ -159,7 +162,7 @@ pub mod ast_ty { } } - pub fn raw_type(ctx: &BindgenContext, name: &str) -> TokenStream { + pub(crate) fn raw_type(ctx: &BindgenContext, name: &str) -> TokenStream { let ident = ctx.rust_ident_raw(name); match ctx.options().ctypes_prefix { Some(ref prefix) => { @@ -184,7 +187,7 @@ pub mod ast_ty { } } - pub fn float_kind_rust_type( + pub(crate) fn float_kind_rust_type( ctx: &BindgenContext, fk: FloatKind, layout: Option, @@ -229,25 +232,25 @@ pub mod ast_ty { } } - pub fn int_expr(val: i64) -> TokenStream { + pub(crate) fn int_expr(val: i64) -> TokenStream { // Don't use quote! { #val } because that adds the type suffix. let val = proc_macro2::Literal::i64_unsuffixed(val); quote!(#val) } - pub fn uint_expr(val: u64) -> TokenStream { + pub(crate) fn uint_expr(val: u64) -> TokenStream { // Don't use quote! { #val } because that adds the type suffix. let val = proc_macro2::Literal::u64_unsuffixed(val); quote!(#val) } - pub fn byte_array_expr(bytes: &[u8]) -> TokenStream { + pub(crate) fn byte_array_expr(bytes: &[u8]) -> TokenStream { let mut bytes: Vec<_> = bytes.to_vec(); bytes.push(0); quote! { [ #(#bytes),* ] } } - pub fn cstr_expr(mut string: String) -> TokenStream { + pub(crate) fn cstr_expr(mut string: String) -> TokenStream { string.push('\0'); let b = proc_macro2::Literal::byte_string(string.as_bytes()); quote! { @@ -255,7 +258,10 @@ pub mod ast_ty { } } - pub fn float_expr(ctx: &BindgenContext, f: f64) -> Result { + pub(crate) fn float_expr( + ctx: &BindgenContext, + f: f64, + ) -> Result { if f.is_finite() { let val = proc_macro2::Literal::f64_unsuffixed(f); @@ -286,7 +292,7 @@ pub mod ast_ty { Err(()) } - pub fn arguments_from_signature( + pub(crate) fn arguments_from_signature( signature: &FunctionSig, ctx: &BindgenContext, ) -> Vec { diff --git a/bindgen/codegen/impl_debug.rs b/bindgen/codegen/impl_debug.rs index 0e2cd33ad5..67ec214ee8 100644 --- a/bindgen/codegen/impl_debug.rs +++ b/bindgen/codegen/impl_debug.rs @@ -3,7 +3,7 @@ use crate::ir::context::BindgenContext; use crate::ir::item::{HasTypeParamInArray, IsOpaque, Item, ItemCanonicalName}; use crate::ir::ty::{TypeKind, RUST_DERIVE_IN_ARRAY_LIMIT}; -pub fn gen_debug_impl( +pub(crate) fn gen_debug_impl( ctx: &BindgenContext, fields: &[Field], item: &Item, @@ -51,7 +51,7 @@ pub fn gen_debug_impl( /// A trait for the things which we can codegen tokens that contribute towards a /// generated `impl Debug`. -pub trait ImplDebug<'a> { +pub(crate) trait ImplDebug<'a> { /// Any extra parameter required by this a particular `ImplDebug` implementation. type Extra; diff --git a/bindgen/codegen/impl_partialeq.rs b/bindgen/codegen/impl_partialeq.rs index 960306ffc6..24abf20df7 100644 --- a/bindgen/codegen/impl_partialeq.rs +++ b/bindgen/codegen/impl_partialeq.rs @@ -5,7 +5,7 @@ use crate::ir::ty::{TypeKind, RUST_DERIVE_IN_ARRAY_LIMIT}; /// Generate a manual implementation of `PartialEq` trait for the /// specified compound type. -pub fn gen_partialeq_impl( +pub(crate) fn gen_partialeq_impl( ctx: &BindgenContext, comp_info: &CompInfo, item: &Item, diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index b5a7b27cf4..4b05c4abc9 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -5,7 +5,7 @@ mod impl_debug; mod impl_partialeq; mod postprocessing; mod serialize; -pub mod struct_layout; +pub(crate) mod struct_layout; #[cfg(test)] #[allow(warnings)] @@ -84,7 +84,7 @@ impl std::fmt::Display for CodegenError { } // Name of type defined in constified enum module -pub static CONSTIFIED_ENUM_MODULE_REPR_NAME: &str = "Type"; +pub(crate) static CONSTIFIED_ENUM_MODULE_REPR_NAME: &str = "Type"; fn top_level_path( ctx: &BindgenContext, @@ -3349,7 +3349,7 @@ pub enum MacroTypeVariation { impl MacroTypeVariation { /// Convert a `MacroTypeVariation` to its str representation. - pub fn as_str(&self) -> &str { + pub(crate) fn as_str(&self) -> &str { match self { MacroTypeVariation::Signed => "signed", MacroTypeVariation::Unsigned => "unsigned", @@ -3395,7 +3395,7 @@ pub enum AliasVariation { impl AliasVariation { /// Convert an `AliasVariation` to its str representation. - pub fn as_str(&self) -> &str { + pub(crate) fn as_str(&self) -> &str { match self { AliasVariation::TypeAlias => "type_alias", AliasVariation::NewType => "new_type", @@ -3444,7 +3444,7 @@ pub enum NonCopyUnionStyle { impl NonCopyUnionStyle { /// Convert an `NonCopyUnionStyle` to its str representation. - pub fn as_str(&self) -> &'static str { + pub(crate) fn as_str(&self) -> &'static str { match self { Self::BindgenWrapper => "bindgen_wrapper", Self::ManuallyDrop => "manually_drop", @@ -4536,7 +4536,7 @@ pub(crate) fn codegen( }) } -pub mod utils { +pub(crate) mod utils { use super::serialize::CSerialize; use super::{error, CodegenError, CodegenResult, ToRustTyOrOpaque}; use crate::ir::context::BindgenContext; @@ -4544,7 +4544,6 @@ pub mod utils { use crate::ir::item::{Item, ItemCanonicalPath}; use crate::ir::ty::TypeKind; use crate::{args_are_cpp, file_is_cpp}; - use proc_macro2; use std::borrow::Cow; use std::mem; use std::path::PathBuf; @@ -4570,7 +4569,7 @@ pub mod utils { let dir = path.parent().unwrap(); if !dir.exists() { - std::fs::create_dir_all(&dir)?; + std::fs::create_dir_all(dir)?; } let is_cpp = args_are_cpp(&context.options().clang_args) || @@ -4594,7 +4593,7 @@ pub mod utils { Ok(()) } - pub fn prepend_bitfield_unit_type( + pub(crate) fn prepend_bitfield_unit_type( ctx: &BindgenContext, result: &mut Vec, ) { @@ -4613,7 +4612,7 @@ pub mod utils { result.extend(old_items); } - pub fn prepend_objc_header( + pub(crate) fn prepend_objc_header( ctx: &BindgenContext, result: &mut Vec, ) { @@ -4638,7 +4637,7 @@ pub mod utils { result.extend(old_items.into_iter()); } - pub fn prepend_block_header( + pub(crate) fn prepend_block_header( ctx: &BindgenContext, result: &mut Vec, ) { @@ -4657,7 +4656,7 @@ pub mod utils { result.extend(old_items.into_iter()); } - pub fn prepend_union_types( + pub(crate) fn prepend_union_types( ctx: &BindgenContext, result: &mut Vec, ) { @@ -4769,7 +4768,7 @@ pub mod utils { result.extend(old_items.into_iter()); } - pub fn prepend_incomplete_array_types( + pub(crate) fn prepend_incomplete_array_types( ctx: &BindgenContext, result: &mut Vec, ) { @@ -4845,7 +4844,9 @@ pub mod utils { result.extend(old_items.into_iter()); } - pub fn prepend_complex_type(result: &mut Vec) { + pub(crate) fn prepend_complex_type( + result: &mut Vec, + ) { let complex_type = quote! { #[derive(PartialEq, Copy, Clone, Hash, Debug, Default)] #[repr(C)] @@ -4860,7 +4861,7 @@ pub mod utils { result.extend(old_items.into_iter()); } - pub fn build_path( + pub(crate) fn build_path( item: &Item, ctx: &BindgenContext, ) -> error::Result { @@ -4881,7 +4882,7 @@ pub mod utils { } } - pub fn type_from_named( + pub(crate) fn type_from_named( ctx: &BindgenContext, name: &str, ) -> Option { @@ -4949,14 +4950,14 @@ pub mod utils { } } - pub fn fnsig_return_ty( + pub(crate) fn fnsig_return_ty( ctx: &BindgenContext, sig: &FunctionSig, ) -> proc_macro2::TokenStream { fnsig_return_ty_internal(ctx, sig, /* include_arrow = */ true) } - pub fn fnsig_arguments( + pub(crate) fn fnsig_arguments( ctx: &BindgenContext, sig: &FunctionSig, ) -> Vec { @@ -5029,7 +5030,7 @@ pub mod utils { args } - pub fn fnsig_argument_identifiers( + pub(crate) fn fnsig_argument_identifiers( ctx: &BindgenContext, sig: &FunctionSig, ) -> Vec { @@ -5058,7 +5059,7 @@ pub mod utils { args } - pub fn fnsig_block( + pub(crate) fn fnsig_block( ctx: &BindgenContext, sig: &FunctionSig, ) -> proc_macro2::TokenStream { diff --git a/bindgen/codegen/struct_layout.rs b/bindgen/codegen/struct_layout.rs index ddac1b0abb..cca4a59b73 100644 --- a/bindgen/codegen/struct_layout.rs +++ b/bindgen/codegen/struct_layout.rs @@ -13,7 +13,7 @@ const MAX_GUARANTEED_ALIGN: usize = 8; /// Trace the layout of struct. #[derive(Debug)] -pub struct StructLayoutTracker<'a> { +pub(crate) struct StructLayoutTracker<'a> { name: &'a str, ctx: &'a BindgenContext, comp: &'a CompInfo, @@ -29,7 +29,7 @@ pub struct StructLayoutTracker<'a> { } /// Returns a size aligned to a given value. -pub fn align_to(size: usize, align: usize) -> usize { +pub(crate) fn align_to(size: usize, align: usize) -> usize { if align == 0 { return size; } @@ -43,7 +43,7 @@ pub fn align_to(size: usize, align: usize) -> usize { } /// Returns the lower power of two byte count that can hold at most n bits. -pub fn bytes_from_bits_pow2(mut n: usize) -> usize { +pub(crate) fn bytes_from_bits_pow2(mut n: usize) -> usize { if n == 0 { return 0; } @@ -83,7 +83,7 @@ fn test_bytes_from_bits_pow2() { } impl<'a> StructLayoutTracker<'a> { - pub fn new( + pub(crate) fn new( ctx: &'a BindgenContext, comp: &'a CompInfo, ty: &'a Type, @@ -109,15 +109,15 @@ impl<'a> StructLayoutTracker<'a> { } } - pub fn can_copy_union_fields(&self) -> bool { + pub(crate) fn can_copy_union_fields(&self) -> bool { self.can_copy_union_fields } - pub fn is_rust_union(&self) -> bool { + pub(crate) fn is_rust_union(&self) -> bool { self.is_rust_union } - pub fn saw_vtable(&mut self) { + pub(crate) fn saw_vtable(&mut self) { debug!("saw vtable for {}", self.name); let ptr_size = self.ctx.target_pointer_size(); @@ -126,7 +126,7 @@ impl<'a> StructLayoutTracker<'a> { self.max_field_align = ptr_size; } - pub fn saw_base(&mut self, base_ty: &Type) { + pub(crate) fn saw_base(&mut self, base_ty: &Type) { debug!("saw base for {}", self.name); if let Some(layout) = base_ty.layout(self.ctx) { self.align_to_latest_field(layout); @@ -137,7 +137,7 @@ impl<'a> StructLayoutTracker<'a> { } } - pub fn saw_bitfield_unit(&mut self, layout: Layout) { + pub(crate) fn saw_bitfield_unit(&mut self, layout: Layout) { debug!("saw bitfield unit for {}: {:?}", self.name, layout); self.align_to_latest_field(layout); @@ -159,7 +159,7 @@ impl<'a> StructLayoutTracker<'a> { /// Returns a padding field if necessary for a given new field _before_ /// adding that field. - pub fn saw_field( + pub(crate) fn saw_field( &mut self, field_name: &str, field_ty: &Type, @@ -189,7 +189,7 @@ impl<'a> StructLayoutTracker<'a> { self.saw_field_with_layout(field_name, field_layout, field_offset) } - pub fn saw_field_with_layout( + pub(crate) fn saw_field_with_layout( &mut self, field_name: &str, field_layout: Layout, @@ -274,7 +274,7 @@ impl<'a> StructLayoutTracker<'a> { padding_layout.map(|layout| self.padding_field(layout)) } - pub fn add_tail_padding( + pub(crate) fn add_tail_padding( &mut self, comp_name: &str, comp_layout: Layout, @@ -305,7 +305,7 @@ impl<'a> StructLayoutTracker<'a> { Some(self.padding_field(Layout::new(size, 0))) } - pub fn pad_struct( + pub(crate) fn pad_struct( &mut self, layout: Layout, ) -> Option { @@ -360,7 +360,7 @@ impl<'a> StructLayoutTracker<'a> { } } - pub fn requires_explicit_align(&self, layout: Layout) -> bool { + pub(crate) fn requires_explicit_align(&self, layout: Layout) -> bool { let repr_align = self.ctx.options().rust_features().repr_align; // Always force explicit repr(align) for stuff more than 16-byte aligned diff --git a/bindgen/features.rs b/bindgen/features.rs index 4fee5d63fc..ef44571a39 100644 --- a/bindgen/features.rs +++ b/bindgen/features.rs @@ -1,7 +1,7 @@ //! Contains code for selecting features -#![deny(missing_docs)] #![deny(unused_extern_crates)] +#![deny(clippy::missing_docs_in_private_items)] #![allow(deprecated)] use std::io; diff --git a/bindgen/ir/analysis/derive.rs b/bindgen/ir/analysis/derive.rs index d888cd558b..0f496a7ead 100644 --- a/bindgen/ir/analysis/derive.rs +++ b/bindgen/ir/analysis/derive.rs @@ -61,7 +61,7 @@ pub enum DeriveTrait { /// * For all other (simple) types, compiler and standard library limitations /// dictate whether the trait is implemented. #[derive(Debug, Clone)] -pub struct CannotDerive<'ctx> { +pub(crate) struct CannotDerive<'ctx> { ctx: &'ctx BindgenContext, derive_trait: DeriveTrait, @@ -722,7 +722,7 @@ impl<'ctx> From> for HashMap { /// /// Elements that are not `CanDerive::Yes` are kept in the set, so that it /// represents all items that cannot derive. -pub fn as_cannot_derive_set( +pub(crate) fn as_cannot_derive_set( can_derive: HashMap, ) -> HashSet { can_derive diff --git a/bindgen/ir/analysis/has_destructor.rs b/bindgen/ir/analysis/has_destructor.rs index 74fd73d14e..cbcbe55af2 100644 --- a/bindgen/ir/analysis/has_destructor.rs +++ b/bindgen/ir/analysis/has_destructor.rs @@ -22,7 +22,7 @@ use crate::{HashMap, HashSet}; /// * If T is the type of a field, that field has a destructor if it's not a bitfield, /// and if T has a destructor. #[derive(Debug, Clone)] -pub struct HasDestructorAnalysis<'ctx> { +pub(crate) struct HasDestructorAnalysis<'ctx> { ctx: &'ctx BindgenContext, // The incremental result of this analysis's computation. Everything in this diff --git a/bindgen/ir/analysis/has_float.rs b/bindgen/ir/analysis/has_float.rs index bbf2126f70..219c5a5a8d 100644 --- a/bindgen/ir/analysis/has_float.rs +++ b/bindgen/ir/analysis/has_float.rs @@ -22,7 +22,7 @@ use crate::{HashMap, HashSet}; /// float if any of the template arguments or template definition /// has. #[derive(Debug, Clone)] -pub struct HasFloat<'ctx> { +pub(crate) struct HasFloat<'ctx> { ctx: &'ctx BindgenContext, // The incremental result of this analysis's computation. Everything in this diff --git a/bindgen/ir/analysis/has_type_param_in_array.rs b/bindgen/ir/analysis/has_type_param_in_array.rs index aa52304758..088c08f542 100644 --- a/bindgen/ir/analysis/has_type_param_in_array.rs +++ b/bindgen/ir/analysis/has_type_param_in_array.rs @@ -22,7 +22,7 @@ use crate::{HashMap, HashSet}; /// type parameter in array if any of the template arguments or template definition /// has. #[derive(Debug, Clone)] -pub struct HasTypeParameterInArray<'ctx> { +pub(crate) struct HasTypeParameterInArray<'ctx> { ctx: &'ctx BindgenContext, // The incremental result of this analysis's computation. Everything in this diff --git a/bindgen/ir/analysis/has_vtable.rs b/bindgen/ir/analysis/has_vtable.rs index 8ac47a65da..980a551b88 100644 --- a/bindgen/ir/analysis/has_vtable.rs +++ b/bindgen/ir/analysis/has_vtable.rs @@ -10,7 +10,7 @@ use std::ops; /// The result of the `HasVtableAnalysis` for an individual item. #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] -pub enum HasVtableResult { +pub(crate) enum HasVtableResult { /// The item does not have a vtable pointer. No, @@ -30,7 +30,7 @@ impl Default for HasVtableResult { impl HasVtableResult { /// Take the least upper bound of `self` and `rhs`. - pub fn join(self, rhs: Self) -> Self { + pub(crate) fn join(self, rhs: Self) -> Self { cmp::max(self, rhs) } } @@ -60,7 +60,7 @@ impl ops::BitOrAssign for HasVtableResult { /// * If T is an instantiation of an abstract template definition, T has /// vtable if template definition has vtable #[derive(Debug, Clone)] -pub struct HasVtableAnalysis<'ctx> { +pub(crate) struct HasVtableAnalysis<'ctx> { ctx: &'ctx BindgenContext, // The incremental result of this analysis's computation. Everything in this @@ -230,7 +230,7 @@ impl<'ctx> From> for HashMap { /// This is not for _computing_ whether the thing has a vtable, it is for /// looking up the results of the HasVtableAnalysis's computations for a /// specific thing. -pub trait HasVtable { +pub(crate) trait HasVtable { /// Return `true` if this thing has vtable, `false` otherwise. fn has_vtable(&self, ctx: &BindgenContext) -> bool; diff --git a/bindgen/ir/analysis/mod.rs b/bindgen/ir/analysis/mod.rs index 40dfc6d644..0263088a99 100644 --- a/bindgen/ir/analysis/mod.rs +++ b/bindgen/ir/analysis/mod.rs @@ -39,19 +39,24 @@ // Re-export individual analyses. mod template_params; -pub use self::template_params::UsedTemplateParameters; +pub(crate) use self::template_params::UsedTemplateParameters; mod derive; -pub use self::derive::{as_cannot_derive_set, CannotDerive, DeriveTrait}; +pub use self::derive::DeriveTrait; +pub(crate) use self::derive::{as_cannot_derive_set, CannotDerive}; mod has_vtable; -pub use self::has_vtable::{HasVtable, HasVtableAnalysis, HasVtableResult}; +pub(crate) use self::has_vtable::{ + HasVtable, HasVtableAnalysis, HasVtableResult, +}; mod has_destructor; -pub use self::has_destructor::HasDestructorAnalysis; +pub(crate) use self::has_destructor::HasDestructorAnalysis; mod has_type_param_in_array; -pub use self::has_type_param_in_array::HasTypeParameterInArray; +pub(crate) use self::has_type_param_in_array::HasTypeParameterInArray; mod has_float; -pub use self::has_float::HasFloat; +pub(crate) use self::has_float::HasFloat; mod sizedness; -pub use self::sizedness::{Sizedness, SizednessAnalysis, SizednessResult}; +pub(crate) use self::sizedness::{ + Sizedness, SizednessAnalysis, SizednessResult, +}; use crate::ir::context::{BindgenContext, ItemId}; @@ -73,7 +78,7 @@ use std::ops; /// /// For a simple example analysis, see the `ReachableFrom` type in the `tests` /// module below. -pub trait MonotoneFramework: Sized + fmt::Debug { +pub(crate) trait MonotoneFramework: Sized + fmt::Debug { /// The type of node in our dependency graph. /// /// This is just generic (and not `ItemId`) so that we can easily unit test @@ -121,7 +126,7 @@ pub trait MonotoneFramework: Sized + fmt::Debug { /// Whether an analysis's `constrain` function modified the incremental results /// or not. #[derive(Debug, Copy, Clone, PartialEq, Eq)] -pub enum ConstrainResult { +pub(crate) enum ConstrainResult { /// The incremental results were updated, and the fix-point computation /// should continue. Changed, @@ -155,7 +160,7 @@ impl ops::BitOrAssign for ConstrainResult { } /// Run an analysis in the monotone framework. -pub fn analyze(extra: Analysis::Extra) -> Analysis::Output +pub(crate) fn analyze(extra: Analysis::Extra) -> Analysis::Output where Analysis: MonotoneFramework, { @@ -174,7 +179,7 @@ where } /// Generate the dependency map for analysis -pub fn generate_dependencies( +pub(crate) fn generate_dependencies( ctx: &BindgenContext, consider_edge: F, ) -> HashMap> diff --git a/bindgen/ir/analysis/sizedness.rs b/bindgen/ir/analysis/sizedness.rs index 251c3747b2..b4c953e647 100644 --- a/bindgen/ir/analysis/sizedness.rs +++ b/bindgen/ir/analysis/sizedness.rs @@ -25,7 +25,7 @@ use std::{cmp, ops}; /// We initially assume that all types are `ZeroSized` and then update our /// understanding as we learn more about each type. #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] -pub enum SizednessResult { +pub(crate) enum SizednessResult { /// The type is zero-sized. /// /// This means that if it is a C++ type, and is not being used as a base @@ -70,7 +70,7 @@ impl Default for SizednessResult { impl SizednessResult { /// Take the least upper bound of `self` and `rhs`. - pub fn join(self, rhs: Self) -> Self { + pub(crate) fn join(self, rhs: Self) -> Self { cmp::max(self, rhs) } } @@ -102,7 +102,7 @@ impl ops::BitOrAssign for SizednessResult { /// /// * For type parameters, `DependsOnTypeParam` is assigned. #[derive(Debug)] -pub struct SizednessAnalysis<'ctx> { +pub(crate) struct SizednessAnalysis<'ctx> { ctx: &'ctx BindgenContext, dependencies: HashMap>, // Incremental results of the analysis. Missing entries are implicitly @@ -350,7 +350,7 @@ impl<'ctx> From> for HashMap { /// /// This is not for _computing_ whether the thing is sized, it is for looking up /// the results of the `Sizedness` analysis's computations for a specific thing. -pub trait Sizedness { +pub(crate) trait Sizedness { /// Get the sizedness of this type. fn sizedness(&self, ctx: &BindgenContext) -> SizednessResult; diff --git a/bindgen/ir/analysis/template_params.rs b/bindgen/ir/analysis/template_params.rs index f4f0c59d71..4ac5f08809 100644 --- a/bindgen/ir/analysis/template_params.rs +++ b/bindgen/ir/analysis/template_params.rs @@ -14,7 +14,7 @@ //! If we generate the naive Rust code for this alias, we get: //! //! ```ignore -//! pub type Fml = ::std::os::raw::int; +//! pub(crate) type Fml = ::std::os::raw::int; //! ``` //! //! And this is rejected by `rustc` due to the unused type parameter. @@ -146,7 +146,7 @@ use crate::{HashMap, HashSet}; /// specially; see `constrain_instantiation_of_blocklisted_template` and its /// documentation for details. #[derive(Debug, Clone)] -pub struct UsedTemplateParameters<'ctx> { +pub(crate) struct UsedTemplateParameters<'ctx> { ctx: &'ctx BindgenContext, // The Option is only there for temporary moves out of the hash map. See the diff --git a/bindgen/ir/annotations.rs b/bindgen/ir/annotations.rs index 17edb31ca5..58d1e695e9 100644 --- a/bindgen/ir/annotations.rs +++ b/bindgen/ir/annotations.rs @@ -8,7 +8,7 @@ use crate::clang; /// What kind of accessor should we provide for a field? #[derive(Copy, PartialEq, Eq, Clone, Debug)] -pub enum FieldAccessorKind { +pub(crate) enum FieldAccessorKind { /// No accessor. None, /// Plain accessor. @@ -23,7 +23,7 @@ pub enum FieldAccessorKind { /// /// You can see the kind of comments that are accepted in the [Doxygen documentation](https://www.doxygen.nl/manual/docblocks.html). #[derive(Default, Clone, PartialEq, Eq, Debug)] -pub struct Annotations { +pub(crate) struct Annotations { /// Whether this item is marked as opaque. Only applies to types. opaque: bool, /// Whether this item should be hidden from the output. Only applies to @@ -77,7 +77,7 @@ fn parse_accessor(s: &str) -> FieldAccessorKind { impl Annotations { /// Construct new annotations for the given cursor and its bindgen comments /// (if any). - pub fn new(cursor: &clang::Cursor) -> Option { + pub(crate) fn new(cursor: &clang::Cursor) -> Option { let mut anno = Annotations::default(); let mut matched_one = false; anno.parse(&cursor.comment(), &mut matched_one); @@ -90,12 +90,12 @@ impl Annotations { } /// Should this type be hidden? - pub fn hide(&self) -> bool { + pub(crate) fn hide(&self) -> bool { self.hide } /// Should this type be opaque? - pub fn opaque(&self) -> bool { + pub(crate) fn opaque(&self) -> bool { self.opaque } @@ -121,42 +121,42 @@ impl Annotations { /// ``` /// /// That is, code for `Foo` is used to generate `Bar`. - pub fn use_instead_of(&self) -> Option<&[String]> { + pub(crate) fn use_instead_of(&self) -> Option<&[String]> { self.use_instead_of.as_deref() } /// The list of derives that have been specified in this annotation. - pub fn derives(&self) -> &[String] { + pub(crate) fn derives(&self) -> &[String] { &self.derives } /// Should we avoid implementing the `Copy` trait? - pub fn disallow_copy(&self) -> bool { + pub(crate) fn disallow_copy(&self) -> bool { self.disallow_copy } /// Should we avoid implementing the `Debug` trait? - pub fn disallow_debug(&self) -> bool { + pub(crate) fn disallow_debug(&self) -> bool { self.disallow_debug } /// Should we avoid implementing the `Default` trait? - pub fn disallow_default(&self) -> bool { + pub(crate) fn disallow_default(&self) -> bool { self.disallow_default } /// Should this type get a `#[must_use]` annotation? - pub fn must_use_type(&self) -> bool { + pub(crate) fn must_use_type(&self) -> bool { self.must_use_type } /// Should the fields be private? - pub fn private_fields(&self) -> Option { + pub(crate) fn private_fields(&self) -> Option { self.private_fields } /// What kind of accessors should we provide for this type's fields? - pub fn accessor_kind(&self) -> Option { + pub(crate) fn accessor_kind(&self) -> Option { self.accessor_kind } @@ -202,7 +202,7 @@ impl Annotations { } /// Returns whether we've parsed a "constant" attribute. - pub fn constify_enum_variant(&self) -> bool { + pub(crate) fn constify_enum_variant(&self) -> bool { self.constify_enum_variant } } diff --git a/bindgen/ir/comment.rs b/bindgen/ir/comment.rs index 3eb17aacb9..7b6f105a4d 100644 --- a/bindgen/ir/comment.rs +++ b/bindgen/ir/comment.rs @@ -12,7 +12,7 @@ enum Kind { } /// Preprocesses a C/C++ comment so that it is a valid Rust comment. -pub fn preprocess(comment: &str) -> String { +pub(crate) fn preprocess(comment: &str) -> String { match self::kind(comment) { Some(Kind::SingleLines) => preprocess_single_lines(comment), Some(Kind::MultiLine) => preprocess_multi_line(comment), diff --git a/bindgen/ir/comp.rs b/bindgen/ir/comp.rs index 18a4291cf9..fd1d1b8e52 100644 --- a/bindgen/ir/comp.rs +++ b/bindgen/ir/comp.rs @@ -22,7 +22,7 @@ use std::mem; /// The kind of compound type. #[derive(Debug, Copy, Clone, PartialEq, Eq)] -pub enum CompKind { +pub(crate) enum CompKind { /// A struct. Struct, /// A union. @@ -31,7 +31,7 @@ pub enum CompKind { /// The kind of C++ method. #[derive(Debug, Copy, Clone, PartialEq, Eq)] -pub enum MethodKind { +pub(crate) enum MethodKind { /// A constructor. We represent it as method for convenience, to avoid code /// duplication. Constructor, @@ -55,7 +55,7 @@ pub enum MethodKind { impl MethodKind { /// Is this a destructor method? - pub fn is_destructor(&self) -> bool { + pub(crate) fn is_destructor(&self) -> bool { matches!( *self, MethodKind::Destructor | MethodKind::VirtualDestructor { .. } @@ -63,7 +63,7 @@ impl MethodKind { } /// Is this a pure virtual method? - pub fn is_pure_virtual(&self) -> bool { + pub(crate) fn is_pure_virtual(&self) -> bool { match *self { MethodKind::Virtual { pure_virtual } | MethodKind::VirtualDestructor { pure_virtual } => pure_virtual, @@ -74,7 +74,7 @@ impl MethodKind { /// A struct representing a C++ method, either static, normal, or virtual. #[derive(Debug)] -pub struct Method { +pub(crate) struct Method { kind: MethodKind, /// The signature of the method. Take into account this is not a `Type` /// item, but a `Function` one. @@ -86,7 +86,7 @@ pub struct Method { impl Method { /// Construct a new `Method`. - pub fn new( + pub(crate) fn new( kind: MethodKind, signature: FunctionId, is_const: bool, @@ -99,17 +99,17 @@ impl Method { } /// What kind of method is this? - pub fn kind(&self) -> MethodKind { + pub(crate) fn kind(&self) -> MethodKind { self.kind } /// Is this a constructor? - pub fn is_constructor(&self) -> bool { + pub(crate) fn is_constructor(&self) -> bool { self.kind == MethodKind::Constructor } /// Is this a virtual method? - pub fn is_virtual(&self) -> bool { + pub(crate) fn is_virtual(&self) -> bool { matches!( self.kind, MethodKind::Virtual { .. } | MethodKind::VirtualDestructor { .. } @@ -117,23 +117,23 @@ impl Method { } /// Is this a static method? - pub fn is_static(&self) -> bool { + pub(crate) fn is_static(&self) -> bool { self.kind == MethodKind::Static } /// Get the id for the `Function` signature for this method. - pub fn signature(&self) -> FunctionId { + pub(crate) fn signature(&self) -> FunctionId { self.signature } /// Is this a const qualified method? - pub fn is_const(&self) -> bool { + pub(crate) fn is_const(&self) -> bool { self.is_const } } /// Methods common to the various field types. -pub trait FieldMethods { +pub(crate) trait FieldMethods { /// Get the name of this field. fn name(&self) -> Option<&str>; @@ -161,7 +161,7 @@ pub trait FieldMethods { /// 2.4.II.1 in the Itanium C++ /// ABI](http://itanium-cxx-abi.github.io/cxx-abi/abi.html#class-types). #[derive(Debug)] -pub struct BitfieldUnit { +pub(crate) struct BitfieldUnit { nth: usize, layout: Layout, bitfields: Vec, @@ -171,24 +171,24 @@ impl BitfieldUnit { /// Get the 1-based index of this bitfield unit within its containing /// struct. Useful for generating a Rust struct's field name for this unit /// of bitfields. - pub fn nth(&self) -> usize { + pub(crate) fn nth(&self) -> usize { self.nth } /// Get the layout within which these bitfields reside. - pub fn layout(&self) -> Layout { + pub(crate) fn layout(&self) -> Layout { self.layout } /// Get the bitfields within this unit. - pub fn bitfields(&self) -> &[Bitfield] { + pub(crate) fn bitfields(&self) -> &[Bitfield] { &self.bitfields } } /// A struct representing a C++ field. #[derive(Debug)] -pub enum Field { +pub(crate) enum Field { /// A normal data member. DataMember(FieldData), @@ -198,7 +198,7 @@ pub enum Field { impl Field { /// Get this field's layout. - pub fn layout(&self, ctx: &BindgenContext) -> Option { + pub(crate) fn layout(&self, ctx: &BindgenContext) -> Option { match *self { Field::Bitfields(BitfieldUnit { layout, .. }) => Some(layout), Field::DataMember(ref data) => { @@ -307,7 +307,7 @@ impl DotAttributes for Bitfield { /// A logical bitfield within some physical bitfield allocation unit. #[derive(Debug)] -pub struct Bitfield { +pub(crate) struct Bitfield { /// Index of the bit within this bitfield's allocation unit where this /// bitfield's bits begin. offset_into_unit: usize, @@ -341,27 +341,12 @@ impl Bitfield { /// Get the index of the bit within this bitfield's allocation unit where /// this bitfield begins. - pub fn offset_into_unit(&self) -> usize { + pub(crate) fn offset_into_unit(&self) -> usize { self.offset_into_unit } - /// Get the mask value that when &'ed with this bitfield's allocation unit - /// produces this bitfield's value. - pub fn mask(&self) -> u64 { - use std::u64; - - let unoffseted_mask = - if self.width() as u64 == mem::size_of::() as u64 * 8 { - u64::MAX - } else { - (1u64 << self.width()) - 1u64 - }; - - unoffseted_mask << self.offset_into_unit() - } - /// Get the bit width of this bitfield. - pub fn width(&self) -> u32 { + pub(crate) fn width(&self) -> u32 { self.data.bitfield_width().unwrap() } @@ -369,7 +354,7 @@ impl Bitfield { /// /// Panics if called before assigning bitfield accessor names or if /// this bitfield have no name. - pub fn getter_name(&self) -> &str { + pub(crate) fn getter_name(&self) -> &str { assert!( self.name().is_some(), "`Bitfield::getter_name` called on anonymous field" @@ -384,7 +369,7 @@ impl Bitfield { /// /// Panics if called before assigning bitfield accessor names or if /// this bitfield have no name. - pub fn setter_name(&self) -> &str { + pub(crate) fn setter_name(&self) -> &str { assert!( self.name().is_some(), "`Bitfield::setter_name` called on anonymous field" @@ -866,7 +851,7 @@ impl Trace for CompFields { /// Common data shared across different field types. #[derive(Clone, Debug)] -pub struct FieldData { +pub(crate) struct FieldData { /// The name of the field, empty if it's an unnamed bitfield width. name: Option, @@ -921,7 +906,7 @@ impl FieldMethods for FieldData { /// The kind of inheritance a base class is using. #[derive(Clone, Debug, PartialEq, Eq)] -pub enum BaseKind { +pub(crate) enum BaseKind { /// Normal inheritance, like: /// /// ```cpp @@ -938,25 +923,25 @@ pub enum BaseKind { /// A base class. #[derive(Clone, Debug)] -pub struct Base { +pub(crate) struct Base { /// The type of this base class. - pub ty: TypeId, + pub(crate) ty: TypeId, /// The kind of inheritance we're doing. - pub kind: BaseKind, + pub(crate) kind: BaseKind, /// Name of the field in which this base should be stored. - pub field_name: String, + pub(crate) field_name: String, /// Whether this base is inherited from publically. - pub is_pub: bool, + pub(crate) is_pub: bool, } impl Base { /// Whether this base class is inheriting virtually. - pub fn is_virtual(&self) -> bool { + pub(crate) fn is_virtual(&self) -> bool { self.kind == BaseKind::Virtual } /// Whether this base class should have it's own field for storage. - pub fn requires_storage(&self, ctx: &BindgenContext) -> bool { + pub(crate) fn requires_storage(&self, ctx: &BindgenContext) -> bool { // Virtual bases are already taken into account by the vtable // pointer. // @@ -976,7 +961,7 @@ impl Base { } /// Whether this base is inherited from publically. - pub fn is_public(&self) -> bool { + pub(crate) fn is_public(&self) -> bool { self.is_pub } } @@ -987,7 +972,7 @@ impl Base { /// of fields which also are associated with their own (potentially compound) /// type. #[derive(Debug)] -pub struct CompInfo { +pub(crate) struct CompInfo { /// Whether this is a struct or a union. kind: CompKind, @@ -1067,7 +1052,7 @@ pub struct CompInfo { impl CompInfo { /// Construct a new compound type. - pub fn new(kind: CompKind) -> Self { + pub(crate) fn new(kind: CompKind) -> Self { CompInfo { kind, fields: CompFields::default(), @@ -1097,7 +1082,7 @@ impl CompInfo { /// If we're a union without known layout, we try to compute it from our /// members. This is not ideal, but clang fails to report the size for these /// kind of unions, see test/headers/template_union.hpp - pub fn layout(&self, ctx: &BindgenContext) -> Option { + pub(crate) fn layout(&self, ctx: &BindgenContext) -> Option { // We can't do better than clang here, sorry. if self.kind == CompKind::Struct { return None; @@ -1126,7 +1111,7 @@ impl CompInfo { } /// Get this type's set of fields. - pub fn fields(&self) -> &[Field] { + pub(crate) fn fields(&self) -> &[Field] { match self.fields { CompFields::Error => &[], CompFields::After { ref fields, .. } => fields, @@ -1184,7 +1169,7 @@ impl CompInfo { /// Returns whether we have a too large bitfield unit, in which case we may /// not be able to derive some of the things we should be able to normally /// derive. - pub fn has_too_large_bitfield_unit(&self) -> bool { + pub(crate) fn has_too_large_bitfield_unit(&self) -> bool { if !self.has_bitfields() { return false; } @@ -1198,53 +1183,53 @@ impl CompInfo { /// Does this type have any template parameters that aren't types /// (e.g. int)? - pub fn has_non_type_template_params(&self) -> bool { + pub(crate) fn has_non_type_template_params(&self) -> bool { self.has_non_type_template_params } /// Do we see a virtual function during parsing? /// Get the has_own_virtual_method boolean. - pub fn has_own_virtual_method(&self) -> bool { + pub(crate) fn has_own_virtual_method(&self) -> bool { self.has_own_virtual_method } /// Did we see a destructor when parsing this type? - pub fn has_own_destructor(&self) -> bool { + pub(crate) fn has_own_destructor(&self) -> bool { self.has_destructor } /// Get this type's set of methods. - pub fn methods(&self) -> &[Method] { + pub(crate) fn methods(&self) -> &[Method] { &self.methods } /// Get this type's set of constructors. - pub fn constructors(&self) -> &[FunctionId] { + pub(crate) fn constructors(&self) -> &[FunctionId] { &self.constructors } /// Get this type's destructor. - pub fn destructor(&self) -> Option<(MethodKind, FunctionId)> { + pub(crate) fn destructor(&self) -> Option<(MethodKind, FunctionId)> { self.destructor } /// What kind of compound type is this? - pub fn kind(&self) -> CompKind { + pub(crate) fn kind(&self) -> CompKind { self.kind } /// Is this a union? - pub fn is_union(&self) -> bool { + pub(crate) fn is_union(&self) -> bool { self.kind() == CompKind::Union } /// The set of types that this one inherits from. - pub fn base_members(&self) -> &[Base] { + pub(crate) fn base_members(&self) -> &[Base] { &self.base_members } /// Construct a new compound type from a Clang type. - pub fn from_ty( + pub(crate) fn from_ty( potential_id: ItemId, ty: &clang::Type, location: Option, @@ -1611,23 +1596,23 @@ impl CompInfo { /// Get the set of types that were declared within this compound type /// (e.g. nested class definitions). - pub fn inner_types(&self) -> &[TypeId] { + pub(crate) fn inner_types(&self) -> &[TypeId] { &self.inner_types } /// Get the set of static variables declared within this compound type. - pub fn inner_vars(&self) -> &[VarId] { + pub(crate) fn inner_vars(&self) -> &[VarId] { &self.inner_vars } /// Have we found a field with an opaque type that could potentially mess up /// the layout of this compound type? - pub fn found_unknown_attr(&self) -> bool { + pub(crate) fn found_unknown_attr(&self) -> bool { self.found_unknown_attr } /// Is this compound type packed? - pub fn is_packed( + pub(crate) fn is_packed( &self, ctx: &BindgenContext, layout: Option<&Layout>, @@ -1657,12 +1642,12 @@ impl CompInfo { } /// Returns true if compound type has been forward declared - pub fn is_forward_declaration(&self) -> bool { + pub(crate) fn is_forward_declaration(&self) -> bool { self.is_forward_declaration } /// Compute this compound structure's bitfield allocation units. - pub fn compute_bitfield_units( + pub(crate) fn compute_bitfield_units( &mut self, ctx: &BindgenContext, layout: Option<&Layout>, @@ -1672,7 +1657,7 @@ impl CompInfo { } /// Assign for each anonymous field a generated name. - pub fn deanonymize_fields(&mut self, ctx: &BindgenContext) { + pub(crate) fn deanonymize_fields(&mut self, ctx: &BindgenContext) { self.fields.deanonymize_fields(ctx, &self.methods); } @@ -1685,7 +1670,7 @@ impl CompInfo { /// /// Second boolean returns whether all fields can be copied (and thus /// ManuallyDrop is not needed). - pub fn is_rust_union( + pub(crate) fn is_rust_union( &self, ctx: &BindgenContext, layout: Option<&Layout>, diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index b693a7047e..b821429a42 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -35,12 +35,13 @@ use std::mem; /// An identifier for some kind of IR item. #[derive(Debug, Copy, Clone, Eq, PartialOrd, Ord, Hash)] -pub struct ItemId(usize); +pub(crate) struct ItemId(usize); +/// Declare a newtype around `ItemId` with convesion methods. macro_rules! item_id_newtype { ( $( #[$attr:meta] )* - pub struct $name:ident(ItemId) + pub(crate) struct $name:ident(ItemId) where $( #[$checked_attr:meta] )* checked = $checked:ident with $check_method:ident, @@ -51,11 +52,12 @@ macro_rules! item_id_newtype { ) => { $( #[$attr] )* #[derive(Debug, Copy, Clone, Eq, PartialOrd, Ord, Hash)] - pub struct $name(ItemId); + pub(crate) struct $name(ItemId); impl $name { /// Create an `ItemResolver` from this id. - pub fn into_resolver(self) -> ItemResolver { + #[allow(dead_code)] + pub(crate) fn into_resolver(self) -> ItemResolver { let id: ItemId = self.into(); id.into() } @@ -83,9 +85,10 @@ macro_rules! item_id_newtype { } } + #[allow(dead_code)] impl ItemId { $( #[$checked_attr] )* - pub fn $checked(&self, ctx: &BindgenContext) -> Option<$name> { + pub(crate) fn $checked(&self, ctx: &BindgenContext) -> Option<$name> { if ctx.resolve_item(*self).kind().$check_method() { Some($name(*self)) } else { @@ -94,7 +97,7 @@ macro_rules! item_id_newtype { } $( #[$expected_attr] )* - pub fn $expected(&self, ctx: &BindgenContext) -> $name { + pub(crate) fn $expected(&self, ctx: &BindgenContext) -> $name { self.$checked(ctx) .expect(concat!( stringify!($expected), @@ -103,7 +106,7 @@ macro_rules! item_id_newtype { } $( #[$unchecked_attr] )* - pub fn $unchecked(&self) -> $name { + pub(crate) fn $unchecked(&self) -> $name { $name(*self) } } @@ -113,7 +116,7 @@ macro_rules! item_id_newtype { item_id_newtype! { /// An identifier for an `Item` whose `ItemKind` is known to be /// `ItemKind::Type`. - pub struct TypeId(ItemId) + pub(crate) struct TypeId(ItemId) where /// Convert this `ItemId` into a `TypeId` if its associated item is a type, /// otherwise return `None`. @@ -132,7 +135,7 @@ item_id_newtype! { item_id_newtype! { /// An identifier for an `Item` whose `ItemKind` is known to be /// `ItemKind::Module`. - pub struct ModuleId(ItemId) + pub(crate) struct ModuleId(ItemId) where /// Convert this `ItemId` into a `ModuleId` if its associated item is a /// module, otherwise return `None`. @@ -151,7 +154,7 @@ item_id_newtype! { item_id_newtype! { /// An identifier for an `Item` whose `ItemKind` is known to be /// `ItemKind::Var`. - pub struct VarId(ItemId) + pub(crate) struct VarId(ItemId) where /// Convert this `ItemId` into a `VarId` if its associated item is a var, /// otherwise return `None`. @@ -170,7 +173,7 @@ item_id_newtype! { item_id_newtype! { /// An identifier for an `Item` whose `ItemKind` is known to be /// `ItemKind::Function`. - pub struct FunctionId(ItemId) + pub(crate) struct FunctionId(ItemId) where /// Convert this `ItemId` into a `FunctionId` if its associated item is a function, /// otherwise return `None`. @@ -194,7 +197,7 @@ impl From for usize { impl ItemId { /// Get a numeric representation of this id. - pub fn as_usize(&self) -> usize { + pub(crate) fn as_usize(&self) -> usize { (*self).into() } } @@ -305,7 +308,7 @@ enum TypeKey { /// A context used during parsing and generation of structs. #[derive(Debug)] -pub struct BindgenContext { +pub(crate) struct BindgenContext { /// The map of all the items parsed so far, keyed off ItemId. items: Vec>, @@ -504,7 +507,7 @@ impl<'ctx> Iterator for AllowlistedItemsTraversal<'ctx> { impl<'ctx> AllowlistedItemsTraversal<'ctx> { /// Construct a new allowlisted items traversal. - pub fn new( + pub(crate) fn new( ctx: &'ctx BindgenContext, roots: R, predicate: for<'a> fn(&'a BindgenContext, Edge) -> bool, @@ -598,46 +601,46 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Returns `true` if the target architecture is wasm32 - pub fn is_target_wasm32(&self) -> bool { + pub(crate) fn is_target_wasm32(&self) -> bool { self.target_info.triple.starts_with("wasm32-") } /// Creates a timer for the current bindgen phase. If time_phases is `true`, /// the timer will print to stderr when it is dropped, otherwise it will do /// nothing. - pub fn timer<'a>(&self, name: &'a str) -> Timer<'a> { + pub(crate) fn timer<'a>(&self, name: &'a str) -> Timer<'a> { Timer::new(name).with_output(self.options.time_phases) } /// Returns the pointer width to use for the target for the current /// translation. - pub fn target_pointer_size(&self) -> usize { + pub(crate) fn target_pointer_size(&self) -> usize { self.target_info.pointer_width / 8 } /// Get the stack of partially parsed types that we are in the middle of /// parsing. - pub fn currently_parsed_types(&self) -> &[PartialType] { + pub(crate) fn currently_parsed_types(&self) -> &[PartialType] { &self.currently_parsed_types[..] } /// Begin parsing the given partial type, and push it onto the /// `currently_parsed_types` stack so that we won't infinite recurse if we /// run into a reference to it while parsing it. - pub fn begin_parsing(&mut self, partial_ty: PartialType) { + pub(crate) fn begin_parsing(&mut self, partial_ty: PartialType) { self.currently_parsed_types.push(partial_ty); } /// Finish parsing the current partial type, pop it off the /// `currently_parsed_types` stack, and return it. - pub fn finish_parsing(&mut self) -> PartialType { + pub(crate) fn finish_parsing(&mut self) -> PartialType { self.currently_parsed_types.pop().expect( "should have been parsing a type, if we finished parsing a type", ) } /// Add another path to the set of included files. - pub fn include_file(&mut self, filename: String) { + pub(crate) fn include_file(&mut self, filename: String) { for cb in &self.options().parse_callbacks { cb.include_file(&filename); } @@ -645,7 +648,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Get any included files. - pub fn deps(&self) -> &BTreeSet { + pub(crate) fn deps(&self) -> &BTreeSet { &self.deps } @@ -653,7 +656,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// /// This inserts it into the internal items set, and its type into the /// internal types set. - pub fn add_item( + pub(crate) fn add_item( &mut self, item: Item, declaration: Option, @@ -778,7 +781,11 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Add a new named template type parameter to this context's item set. - pub fn add_type_param(&mut self, item: Item, definition: clang::Cursor) { + pub(crate) fn add_type_param( + &mut self, + item: Item, + definition: clang::Cursor, + ) { debug!( "BindgenContext::add_type_param: item = {:?}; definition = {:?}", item, definition @@ -813,7 +820,10 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// Get the named type defined at the given cursor location, if we've /// already added one. - pub fn get_type_param(&self, definition: &clang::Cursor) -> Option { + pub(crate) fn get_type_param( + &self, + definition: &clang::Cursor, + ) -> Option { assert_eq!( definition.kind(), clang_sys::CXCursor_TemplateTypeParameter @@ -825,7 +835,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// Mangles a name so it doesn't conflict with any keyword. #[rustfmt::skip] - pub fn rust_mangle<'a>(&self, name: &'a str) -> Cow<'a, str> { + pub(crate) fn rust_mangle<'a>(&self, name: &'a str) -> Cow<'a, str> { if name.contains('@') || name.contains('?') || name.contains('$') || @@ -856,7 +866,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Returns a mangled name as a rust identifier. - pub fn rust_ident(&self, name: S) -> Ident + pub(crate) fn rust_ident(&self, name: S) -> Ident where S: AsRef, { @@ -864,7 +874,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Returns a mangled name as a rust identifier. - pub fn rust_ident_raw(&self, name: T) -> Ident + pub(crate) fn rust_ident_raw(&self, name: T) -> Ident where T: AsRef, { @@ -872,7 +882,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Iterate over all items that have been defined. - pub fn items(&self) -> impl Iterator { + pub(crate) fn items(&self) -> impl Iterator { self.items.iter().enumerate().filter_map(|(index, item)| { let item = item.as_ref()?; Some((ItemId(index), item)) @@ -880,7 +890,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Have we collected all unresolved type references yet? - pub fn collected_typerefs(&self) -> bool { + pub(crate) fn collected_typerefs(&self) -> bool { self.collected_typerefs } @@ -1264,7 +1274,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Look up whether the type with the given id is sized or not. - pub fn lookup_sizedness(&self, id: TypeId) -> SizednessResult { + pub(crate) fn lookup_sizedness(&self, id: TypeId) -> SizednessResult { assert!( self.in_codegen_phase(), "We only compute sizedness after we've entered codegen" @@ -1286,7 +1296,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Look up whether the item with `id` has vtable or not. - pub fn lookup_has_vtable(&self, id: TypeId) -> HasVtableResult { + pub(crate) fn lookup_has_vtable(&self, id: TypeId) -> HasVtableResult { assert!( self.in_codegen_phase(), "We only compute vtables when we enter codegen" @@ -1310,7 +1320,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Look up whether the item with `id` has a destructor. - pub fn lookup_has_destructor(&self, id: TypeId) -> bool { + pub(crate) fn lookup_has_destructor(&self, id: TypeId) -> bool { assert!( self.in_codegen_phase(), "We only compute destructors when we enter codegen" @@ -1354,7 +1364,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// manually provide a definition for them. To give them the most /// flexibility when doing that, we assume that they use every template /// parameter and always pass template arguments through in instantiations. - pub fn uses_template_parameter( + pub(crate) fn uses_template_parameter( &self, item: ItemId, template_param: TypeId, @@ -1386,7 +1396,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// `false` otherwise. /// /// Has the same restrictions that `uses_template_parameter` has. - pub fn uses_any_template_parameters(&self, item: ItemId) -> bool { + pub(crate) fn uses_any_template_parameters(&self, item: ItemId) -> bool { assert!( self.in_codegen_phase(), "We only compute template parameter usage as we enter codegen" @@ -1424,7 +1434,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Get the root module. - pub fn root_module(&self) -> ModuleId { + pub(crate) fn root_module(&self) -> ModuleId { self.root_module } @@ -1432,7 +1442,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// /// Panics if there is no item for the given `TypeId` or if the resolved /// item is not a `Type`. - pub fn resolve_type(&self, type_id: TypeId) -> &Type { + pub(crate) fn resolve_type(&self, type_id: TypeId) -> &Type { self.resolve_item(type_id).kind().expect_type() } @@ -1440,7 +1450,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// /// Panics if there is no item for the given `FunctionId` or if the resolved /// item is not a `Function`. - pub fn resolve_func(&self, func_id: FunctionId) -> &Function { + pub(crate) fn resolve_func(&self, func_id: FunctionId) -> &Function { self.resolve_item(func_id).kind().expect_function() } @@ -1448,14 +1458,14 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// the given id. /// /// Panics if the id resolves to an item that is not a type. - pub fn safe_resolve_type(&self, type_id: TypeId) -> Option<&Type> { + pub(crate) fn safe_resolve_type(&self, type_id: TypeId) -> Option<&Type> { self.resolve_item_fallible(type_id) .map(|t| t.kind().expect_type()) } /// Resolve the given `ItemId` into an `Item`, or `None` if no such item /// exists. - pub fn resolve_item_fallible>( + pub(crate) fn resolve_item_fallible>( &self, id: Id, ) -> Option<&Item> { @@ -1465,7 +1475,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// Resolve the given `ItemId` into an `Item`. /// /// Panics if the given id does not resolve to any item. - pub fn resolve_item>(&self, item_id: Id) -> &Item { + pub(crate) fn resolve_item>(&self, item_id: Id) -> &Item { let item_id = item_id.into(); match self.resolve_item_fallible(item_id) { Some(item) => item, @@ -1474,7 +1484,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Get the current module. - pub fn current_module(&self) -> ModuleId { + pub(crate) fn current_module(&self) -> ModuleId { self.current_module } @@ -1486,7 +1496,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// TODO(emilio): We could consider doing this only when /// declaration.lexical_parent() != definition.lexical_parent(), but it's /// not sure it's worth it. - pub fn add_semantic_parent( + pub(crate) fn add_semantic_parent( &mut self, definition: clang::Cursor, parent_id: ItemId, @@ -1495,7 +1505,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Returns a known semantic parent for a given definition. - pub fn known_semantic_parent( + pub(crate) fn known_semantic_parent( &self, definition: clang::Cursor, ) -> Option { @@ -1808,7 +1818,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// If we have already resolved the type for the given type declaration, /// return its `ItemId`. Otherwise, return `None`. - pub fn get_resolved_type( + pub(crate) fn get_resolved_type( &self, decl: &clang::CanonicalTypeDeclaration, ) -> Option { @@ -1824,7 +1834,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// Looks up for an already resolved type, either because it's builtin, or /// because we already have it in the map. - pub fn builtin_or_resolved_ty( + pub(crate) fn builtin_or_resolved_ty( &mut self, with_id: ItemId, parent_id: Option, @@ -1894,7 +1904,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// We should probably make the constness tracking separate, so it doesn't /// bloat that much, but hey, we already bloat the heck out of builtin /// types. - pub fn build_ty_wrapper( + pub(crate) fn build_ty_wrapper( &mut self, with_id: ItemId, wrapped_id: TypeId, @@ -1907,7 +1917,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// A wrapper over a type that adds a const qualifier explicitly. /// /// Needed to handle const methods in C++, wrapping the type . - pub fn build_const_wrapper( + pub(crate) fn build_const_wrapper( &mut self, with_id: ItemId, wrapped_id: TypeId, @@ -1945,7 +1955,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Returns the next item id to be used for an item. - pub fn next_item_id(&mut self) -> ItemId { + pub(crate) fn next_item_id(&mut self) -> ItemId { let ret = ItemId(self.items.len()); self.items.push(None); ret @@ -2015,17 +2025,17 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Get the current Clang translation unit that is being processed. - pub fn translation_unit(&self) -> &clang::TranslationUnit { + pub(crate) fn translation_unit(&self) -> &clang::TranslationUnit { &self.translation_unit } /// Have we parsed the macro named `macro_name` already? - pub fn parsed_macro(&self, macro_name: &[u8]) -> bool { + pub(crate) fn parsed_macro(&self, macro_name: &[u8]) -> bool { self.parsed_macros.contains_key(macro_name) } /// Get the currently parsed macros. - pub fn parsed_macros( + pub(crate) fn parsed_macros( &self, ) -> &StdHashMap, cexpr::expr::EvalResult> { debug_assert!(!self.in_codegen_phase()); @@ -2033,7 +2043,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Mark the macro named `macro_name` as parsed. - pub fn note_parsed_macro( + pub(crate) fn note_parsed_macro( &mut self, id: Vec, value: cexpr::expr::EvalResult, @@ -2042,7 +2052,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Are we in the codegen phase? - pub fn in_codegen_phase(&self) -> bool { + pub(crate) fn in_codegen_phase(&self) -> bool { self.in_codegen } @@ -2051,7 +2061,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// /// Replacement types are declared using the `replaces="xxx"` annotation, /// and implies that the original type is hidden. - pub fn replace(&mut self, name: &[String], potential_ty: ItemId) { + pub(crate) fn replace(&mut self, name: &[String], potential_ty: ItemId) { match self.replacements.entry(name.into()) { Entry::Vacant(entry) => { debug!( @@ -2074,7 +2084,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// Has the item with the given `name` and `id` been replaced by another /// type? - pub fn is_replaced_type>( + pub(crate) fn is_replaced_type>( &self, path: &[String], id: Id, @@ -2084,7 +2094,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Is the type with the given `name` marked as opaque? - pub fn opaque_by_name(&self, path: &[String]) -> bool { + pub(crate) fn opaque_by_name(&self, path: &[String]) -> bool { debug_assert!( self.in_codegen_phase(), "You're not supposed to call this yet" @@ -2178,7 +2188,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// Given a CXCursor_Namespace cursor, return the item id of the /// corresponding module, or create one on the fly. - pub fn module(&mut self, cursor: clang::Cursor) -> ModuleId { + pub(crate) fn module(&mut self, cursor: clang::Cursor) -> ModuleId { use clang_sys::*; assert_eq!(cursor.kind(), CXCursor_Namespace, "Be a nice person"); let cursor = cursor.canonical(); @@ -2209,7 +2219,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// Start traversing the module with the given `module_id`, invoke the /// callback `cb`, and then return to traversing the original module. - pub fn with_module(&mut self, module_id: ModuleId, cb: F) + pub(crate) fn with_module(&mut self, module_id: ModuleId, cb: F) where F: FnOnce(&mut Self), { @@ -2227,7 +2237,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// /// If no items are explicitly allowlisted, then all items are considered /// allowlisted. - pub fn allowlisted_items(&self) -> &ItemSet { + pub(crate) fn allowlisted_items(&self) -> &ItemSet { assert!(self.in_codegen_phase()); assert!(self.current_module == self.root_module); @@ -2236,7 +2246,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// Check whether a particular blocklisted type implements a trait or not. /// Results may be cached. - pub fn blocklisted_type_implements_trait( + pub(crate) fn blocklisted_type_implements_trait( &self, item: &Item, derive_trait: DeriveTrait, @@ -2277,7 +2287,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Is the given type a type from that corresponds to a Rust primitive type? - pub fn is_stdint_type(&self, name: &str) -> bool { + pub(crate) fn is_stdint_type(&self, name: &str) -> bool { match name { "int8_t" | "uint8_t" | "int16_t" | "uint16_t" | "int32_t" | "uint32_t" | "int64_t" | "uint64_t" | "uintptr_t" | @@ -2288,7 +2298,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Get a reference to the set of items we should generate. - pub fn codegen_items(&self) -> &ItemSet { + pub(crate) fn codegen_items(&self) -> &ItemSet { assert!(self.in_codegen_phase()); assert!(self.current_module == self.root_module); self.codegen_items.as_ref().unwrap() @@ -2477,7 +2487,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// Convenient method for getting the prefix to use for most traits in /// codegen depending on the `use_core` option. - pub fn trait_prefix(&self) -> Ident { + pub(crate) fn trait_prefix(&self) -> Ident { if self.options().use_core { self.rust_ident_raw("core") } else { @@ -2486,12 +2496,12 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Call if a bindgen complex is generated - pub fn generated_bindgen_complex(&self) { + pub(crate) fn generated_bindgen_complex(&self) { self.generated_bindgen_complex.set(true) } /// Whether we need to generate the bindgen complex type - pub fn need_bindgen_complex_type(&self) -> bool { + pub(crate) fn need_bindgen_complex_type(&self) -> bool { self.generated_bindgen_complex.get() } @@ -2551,7 +2561,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// Look up whether `id` refers to an `enum` whose underlying type is /// defined by a `typedef`. - pub fn is_enum_typedef_combo(&self, id: ItemId) -> bool { + pub(crate) fn is_enum_typedef_combo(&self, id: ItemId) -> bool { assert!( self.in_codegen_phase(), "We only compute enum_typedef_combos when we enter codegen", @@ -2574,7 +2584,10 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// Look up whether the item with `id` can /// derive debug or not. - pub fn lookup_can_derive_debug>(&self, id: Id) -> bool { + pub(crate) fn lookup_can_derive_debug>( + &self, + id: Id, + ) -> bool { let id = id.into(); assert!( self.in_codegen_phase(), @@ -2601,7 +2614,10 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// Look up whether the item with `id` can /// derive default or not. - pub fn lookup_can_derive_default>(&self, id: Id) -> bool { + pub(crate) fn lookup_can_derive_default>( + &self, + id: Id, + ) -> bool { let id = id.into(); assert!( self.in_codegen_phase(), @@ -2639,7 +2655,10 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// Look up whether the item with `id` can /// derive hash or not. - pub fn lookup_can_derive_hash>(&self, id: Id) -> bool { + pub(crate) fn lookup_can_derive_hash>( + &self, + id: Id, + ) -> bool { let id = id.into(); assert!( self.in_codegen_phase(), @@ -2668,7 +2687,9 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Look up whether the item with `id` can derive `Partial{Eq,Ord}`. - pub fn lookup_can_derive_partialeq_or_partialord>( + pub(crate) fn lookup_can_derive_partialeq_or_partialord< + Id: Into, + >( &self, id: Id, ) -> CanDerive { @@ -2689,7 +2710,10 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Look up whether the item with `id` can derive `Copy` or not. - pub fn lookup_can_derive_copy>(&self, id: Id) -> bool { + pub(crate) fn lookup_can_derive_copy>( + &self, + id: Id, + ) -> bool { assert!( self.in_codegen_phase(), "We only compute can_derive_debug when we enter codegen" @@ -2712,7 +2736,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Look up whether the item with `id` has type parameter in array or not. - pub fn lookup_has_type_param_in_array>( + pub(crate) fn lookup_has_type_param_in_array>( &self, id: Id, ) -> bool { @@ -2739,7 +2763,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Look up whether the item with `id` has array or not. - pub fn lookup_has_float>(&self, id: Id) -> bool { + pub(crate) fn lookup_has_float>(&self, id: Id) -> bool { assert!( self.in_codegen_phase(), "We only compute has float when we enter codegen" @@ -2751,41 +2775,42 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Check if `--no-partialeq` flag is enabled for this item. - pub fn no_partialeq_by_name(&self, item: &Item) -> bool { + pub(crate) fn no_partialeq_by_name(&self, item: &Item) -> bool { let name = item.path_for_allowlisting(self)[1..].join("::"); self.options().no_partialeq_types.matches(name) } /// Check if `--no-copy` flag is enabled for this item. - pub fn no_copy_by_name(&self, item: &Item) -> bool { + pub(crate) fn no_copy_by_name(&self, item: &Item) -> bool { let name = item.path_for_allowlisting(self)[1..].join("::"); self.options().no_copy_types.matches(name) } /// Check if `--no-debug` flag is enabled for this item. - pub fn no_debug_by_name(&self, item: &Item) -> bool { + pub(crate) fn no_debug_by_name(&self, item: &Item) -> bool { let name = item.path_for_allowlisting(self)[1..].join("::"); self.options().no_debug_types.matches(name) } /// Check if `--no-default` flag is enabled for this item. - pub fn no_default_by_name(&self, item: &Item) -> bool { + pub(crate) fn no_default_by_name(&self, item: &Item) -> bool { let name = item.path_for_allowlisting(self)[1..].join("::"); self.options().no_default_types.matches(name) } /// Check if `--no-hash` flag is enabled for this item. - pub fn no_hash_by_name(&self, item: &Item) -> bool { + pub(crate) fn no_hash_by_name(&self, item: &Item) -> bool { let name = item.path_for_allowlisting(self)[1..].join("::"); self.options().no_hash_types.matches(name) } /// Check if `--must-use-type` flag is enabled for this item. - pub fn must_use_type_by_name(&self, item: &Item) -> bool { + pub(crate) fn must_use_type_by_name(&self, item: &Item) -> bool { let name = item.path_for_allowlisting(self)[1..].join("::"); self.options().must_use_types.matches(name) } + /// Wrap some tokens in an `unsafe` block if the `--wrap-unsafe-ops` option is enabled. pub(crate) fn wrap_unsafe_ops(&self, tokens: impl ToTokens) -> TokenStream { if self.options.wrap_unsafe_ops { quote!(unsafe { #tokens }) @@ -2794,6 +2819,8 @@ If you encounter an error missing from this list, please file an issue or a PR!" } } + /// Get the suffix to be added to `static` functions if the `--wrap-static-fns` option is + /// enabled. pub(crate) fn wrap_static_fns_suffix(&self) -> &str { self.options() .wrap_static_fns_suffix @@ -2804,7 +2831,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// A builder struct for configuring item resolution options. #[derive(Debug, Copy, Clone)] -pub struct ItemResolver { +pub(crate) struct ItemResolver { id: ItemId, through_type_refs: bool, through_type_aliases: bool, @@ -2812,7 +2839,7 @@ pub struct ItemResolver { impl ItemId { /// Create an `ItemResolver` from this item id. - pub fn into_resolver(self) -> ItemResolver { + pub(crate) fn into_resolver(self) -> ItemResolver { self.into() } } @@ -2828,7 +2855,7 @@ where impl ItemResolver { /// Construct a new `ItemResolver` from the given id. - pub fn new>(id: Id) -> ItemResolver { + pub(crate) fn new>(id: Id) -> ItemResolver { let id = id.into(); ItemResolver { id, @@ -2838,19 +2865,19 @@ impl ItemResolver { } /// Keep resolving through `Type::TypeRef` items. - pub fn through_type_refs(mut self) -> ItemResolver { + pub(crate) fn through_type_refs(mut self) -> ItemResolver { self.through_type_refs = true; self } /// Keep resolving through `Type::Alias` items. - pub fn through_type_aliases(mut self) -> ItemResolver { + pub(crate) fn through_type_aliases(mut self) -> ItemResolver { self.through_type_aliases = true; self } /// Finish configuring and perform the actual item resolution. - pub fn resolve(self, ctx: &BindgenContext) -> &Item { + pub(crate) fn resolve(self, ctx: &BindgenContext) -> &Item { assert!(ctx.collected_typerefs()); let mut id = self.id; @@ -2887,7 +2914,7 @@ impl ItemResolver { /// A type that we are in the middle of parsing. #[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub struct PartialType { +pub(crate) struct PartialType { decl: Cursor, // Just an ItemId, and not a TypeId, because we haven't finished this type // yet, so there's still time for things to go wrong. @@ -2896,19 +2923,19 @@ pub struct PartialType { impl PartialType { /// Construct a new `PartialType`. - pub fn new(decl: Cursor, id: ItemId) -> PartialType { + pub(crate) fn new(decl: Cursor, id: ItemId) -> PartialType { // assert!(decl == decl.canonical()); PartialType { decl, id } } /// The cursor pointing to this partial type's declaration location. - pub fn decl(&self) -> &Cursor { + pub(crate) fn decl(&self) -> &Cursor { &self.decl } /// The item ID allocated for this type. This is *NOT* a key for an entry in /// the context's item set yet! - pub fn id(&self) -> ItemId { + pub(crate) fn id(&self) -> ItemId { self.id } } diff --git a/bindgen/ir/derive.rs b/bindgen/ir/derive.rs index 594ce2ab8f..3877b42f8f 100644 --- a/bindgen/ir/derive.rs +++ b/bindgen/ir/derive.rs @@ -18,7 +18,7 @@ use std::ops; /// A trait that encapsulates the logic for whether or not we can derive `Debug` /// for a given thing. -pub trait CanDeriveDebug { +pub(crate) trait CanDeriveDebug { /// Return `true` if `Debug` can be derived for this thing, `false` /// otherwise. fn can_derive_debug(&self, ctx: &BindgenContext) -> bool; @@ -26,7 +26,7 @@ pub trait CanDeriveDebug { /// A trait that encapsulates the logic for whether or not we can derive `Copy` /// for a given thing. -pub trait CanDeriveCopy { +pub(crate) trait CanDeriveCopy { /// Return `true` if `Copy` can be derived for this thing, `false` /// otherwise. fn can_derive_copy(&self, ctx: &BindgenContext) -> bool; @@ -34,7 +34,7 @@ pub trait CanDeriveCopy { /// A trait that encapsulates the logic for whether or not we can derive /// `Default` for a given thing. -pub trait CanDeriveDefault { +pub(crate) trait CanDeriveDefault { /// Return `true` if `Default` can be derived for this thing, `false` /// otherwise. fn can_derive_default(&self, ctx: &BindgenContext) -> bool; @@ -42,7 +42,7 @@ pub trait CanDeriveDefault { /// A trait that encapsulates the logic for whether or not we can derive `Hash` /// for a given thing. -pub trait CanDeriveHash { +pub(crate) trait CanDeriveHash { /// Return `true` if `Hash` can be derived for this thing, `false` /// otherwise. fn can_derive_hash(&self, ctx: &BindgenContext) -> bool; @@ -50,7 +50,7 @@ pub trait CanDeriveHash { /// A trait that encapsulates the logic for whether or not we can derive /// `PartialEq` for a given thing. -pub trait CanDerivePartialEq { +pub(crate) trait CanDerivePartialEq { /// Return `true` if `PartialEq` can be derived for this thing, `false` /// otherwise. fn can_derive_partialeq(&self, ctx: &BindgenContext) -> bool; @@ -58,7 +58,7 @@ pub trait CanDerivePartialEq { /// A trait that encapsulates the logic for whether or not we can derive /// `PartialOrd` for a given thing. -pub trait CanDerivePartialOrd { +pub(crate) trait CanDerivePartialOrd { /// Return `true` if `PartialOrd` can be derived for this thing, `false` /// otherwise. fn can_derive_partialord(&self, ctx: &BindgenContext) -> bool; @@ -66,14 +66,14 @@ pub trait CanDerivePartialOrd { /// A trait that encapsulates the logic for whether or not we can derive `Eq` /// for a given thing. -pub trait CanDeriveEq { +pub(crate) trait CanDeriveEq { /// Return `true` if `Eq` can be derived for this thing, `false` otherwise. fn can_derive_eq(&self, ctx: &BindgenContext) -> bool; } /// A trait that encapsulates the logic for whether or not we can derive `Ord` /// for a given thing. -pub trait CanDeriveOrd { +pub(crate) trait CanDeriveOrd { /// Return `true` if `Ord` can be derived for this thing, `false` otherwise. fn can_derive_ord(&self, ctx: &BindgenContext) -> bool; } @@ -115,7 +115,7 @@ impl Default for CanDerive { impl CanDerive { /// Take the least upper bound of `self` and `rhs`. - pub fn join(self, rhs: Self) -> Self { + pub(crate) fn join(self, rhs: Self) -> Self { cmp::max(self, rhs) } } diff --git a/bindgen/ir/dot.rs b/bindgen/ir/dot.rs index f7d07f19e2..d5c1a42fdc 100644 --- a/bindgen/ir/dot.rs +++ b/bindgen/ir/dot.rs @@ -8,7 +8,7 @@ use std::path::Path; /// A trait for anything that can write attributes as `` rows to a dot /// file. -pub trait DotAttributes { +pub(crate) trait DotAttributes { /// Write this thing's attributes to the given output. Each attribute must /// be its own `...`. fn dot_attributes( @@ -21,7 +21,7 @@ pub trait DotAttributes { } /// Write a graphviz dot file containing our IR. -pub fn write_dot_file

(ctx: &BindgenContext, path: P) -> io::Result<()> +pub(crate) fn write_dot_file

(ctx: &BindgenContext, path: P) -> io::Result<()> where P: AsRef, { diff --git a/bindgen/ir/enum_ty.rs b/bindgen/ir/enum_ty.rs index 63871fd465..70cf0eae88 100644 --- a/bindgen/ir/enum_ty.rs +++ b/bindgen/ir/enum_ty.rs @@ -22,7 +22,7 @@ pub enum EnumVariantCustomBehavior { /// A C/C++ enumeration. #[derive(Debug)] -pub struct Enum { +pub(crate) struct Enum { /// The representation used for this enum; it should be an `IntKind` type or /// an alias to one. /// @@ -36,22 +36,25 @@ pub struct Enum { impl Enum { /// Construct a new `Enum` with the given representation and variants. - pub fn new(repr: Option, variants: Vec) -> Self { + pub(crate) fn new( + repr: Option, + variants: Vec, + ) -> Self { Enum { repr, variants } } /// Get this enumeration's representation. - pub fn repr(&self) -> Option { + pub(crate) fn repr(&self) -> Option { self.repr } /// Get this enumeration's variants. - pub fn variants(&self) -> &[EnumVariant] { + pub(crate) fn variants(&self) -> &[EnumVariant] { &self.variants } /// Construct an enumeration from the given Clang type. - pub fn from_ty( + pub(crate) fn from_ty( ty: &clang::Type, ctx: &mut BindgenContext, ) -> Result { @@ -169,7 +172,7 @@ impl Enum { } /// Returns the final representation of the enum. - pub fn computed_enum_variation( + pub(crate) fn computed_enum_variation( &self, ctx: &BindgenContext, item: &Item, @@ -236,7 +239,7 @@ impl Enum { /// A single enum variant, to be contained only in an enum. #[derive(Debug)] -pub struct EnumVariant { +pub(crate) struct EnumVariant { /// The name of the variant. name: String, @@ -268,7 +271,7 @@ pub enum EnumVariantValue { impl EnumVariant { /// Construct a new enumeration variant from the given parts. - pub fn new( + pub(crate) fn new( name: String, name_for_allowlisting: String, comment: Option, @@ -285,35 +288,35 @@ impl EnumVariant { } /// Get this variant's name. - pub fn name(&self) -> &str { + pub(crate) fn name(&self) -> &str { &self.name } /// Get this variant's name. - pub fn name_for_allowlisting(&self) -> &str { + pub(crate) fn name_for_allowlisting(&self) -> &str { &self.name_for_allowlisting } /// Get this variant's value. - pub fn val(&self) -> EnumVariantValue { + pub(crate) fn val(&self) -> EnumVariantValue { self.val } /// Get this variant's documentation. - pub fn comment(&self) -> Option<&str> { + pub(crate) fn comment(&self) -> Option<&str> { self.comment.as_deref() } /// Returns whether this variant should be enforced to be a constant by code /// generation. - pub fn force_constification(&self) -> bool { + pub(crate) fn force_constification(&self) -> bool { self.custom_behavior .map_or(false, |b| b == EnumVariantCustomBehavior::Constify) } /// Returns whether the current variant should be hidden completely from the /// resulting rust enum. - pub fn hidden(&self) -> bool { + pub(crate) fn hidden(&self) -> bool { self.custom_behavior .map_or(false, |b| b == EnumVariantCustomBehavior::Hide) } diff --git a/bindgen/ir/function.rs b/bindgen/ir/function.rs index baa2c36ca4..dccd9b2467 100644 --- a/bindgen/ir/function.rs +++ b/bindgen/ir/function.rs @@ -20,7 +20,7 @@ const RUST_DERIVE_FUNPTR_LIMIT: usize = 12; /// What kind of a function are we looking at? #[derive(Debug, Copy, Clone, PartialEq, Eq)] -pub enum FunctionKind { +pub(crate) enum FunctionKind { /// A plain, free function. Function, /// A method of some kind. @@ -30,7 +30,7 @@ pub enum FunctionKind { impl FunctionKind { /// Given a clang cursor, return the kind of function it represents, or /// `None` otherwise. - pub fn from_cursor(cursor: &clang::Cursor) -> Option { + pub(crate) fn from_cursor(cursor: &clang::Cursor) -> Option { // FIXME(emilio): Deduplicate logic with `ir::comp`. Some(match cursor.kind() { clang_sys::CXCursor_FunctionDecl => FunctionKind::Function, @@ -64,7 +64,7 @@ impl FunctionKind { /// The style of linkage #[derive(Debug, Clone, Copy)] -pub enum Linkage { +pub(crate) enum Linkage { /// Externally visible and can be linked against External, /// Not exposed externally. 'static inline' functions will have this kind of linkage @@ -76,7 +76,7 @@ pub enum Linkage { /// The argument names vector must be the same length as the ones in the /// signature. #[derive(Debug)] -pub struct Function { +pub(crate) struct Function { /// The name of this function. name: String, @@ -86,9 +86,6 @@ pub struct Function { /// The id pointing to the current function signature. signature: TypeId, - /// The doc comment on the function, if any. - comment: Option, - /// The kind of function this is. kind: FunctionKind, @@ -98,11 +95,10 @@ pub struct Function { impl Function { /// Construct a new function. - pub fn new( + pub(crate) fn new( name: String, mangled_name: Option, signature: TypeId, - comment: Option, kind: FunctionKind, linkage: Linkage, ) -> Self { @@ -110,39 +106,33 @@ impl Function { name, mangled_name, signature, - comment, kind, linkage, } } /// Get this function's name. - pub fn name(&self) -> &str { + pub(crate) fn name(&self) -> &str { &self.name } /// Get this function's name. - pub fn mangled_name(&self) -> Option<&str> { + pub(crate) fn mangled_name(&self) -> Option<&str> { self.mangled_name.as_deref() } /// Get this function's signature type. - pub fn signature(&self) -> TypeId { + pub(crate) fn signature(&self) -> TypeId { self.signature } - /// Get this function's comment. - pub fn comment(&self) -> Option<&str> { - self.comment.as_deref() - } - /// Get this function's kind. - pub fn kind(&self) -> FunctionKind { + pub(crate) fn kind(&self) -> FunctionKind { self.kind } /// Get this function's linkage. - pub fn linkage(&self) -> Linkage { + pub(crate) fn linkage(&self) -> Linkage { self.linkage } } @@ -236,6 +226,7 @@ impl quote::ToTokens for Abi { /// An ABI extracted from a clang cursor. #[derive(Debug, Copy, Clone)] pub(crate) enum ClangAbi { + /// An ABI known by rust. Known(Abi), /// An unknown or invalid ABI. Unknown(CXCallingConv), @@ -262,7 +253,7 @@ impl quote::ToTokens for ClangAbi { /// A function signature. #[derive(Debug)] -pub struct FunctionSig { +pub(crate) struct FunctionSig { /// The return type of the function. return_type: TypeId, @@ -297,7 +288,7 @@ fn get_abi(cc: CXCallingConv) -> ClangAbi { } /// Get the mangled name for the cursor's referent. -pub fn cursor_mangling( +pub(crate) fn cursor_mangling( ctx: &BindgenContext, cursor: &clang::Cursor, ) -> Option { @@ -399,7 +390,7 @@ fn args_from_ty_and_cursor( impl FunctionSig { /// Construct a new function signature from the given Clang type. - pub fn from_ty( + pub(crate) fn from_ty( ty: &clang::Type, cursor: &clang::Cursor, ctx: &mut BindgenContext, @@ -583,12 +574,12 @@ impl FunctionSig { } /// Get this function signature's return type. - pub fn return_type(&self) -> TypeId { + pub(crate) fn return_type(&self) -> TypeId { self.return_type } /// Get this function signature's argument (name, type) pairs. - pub fn argument_types(&self) -> &[(Option, TypeId)] { + pub(crate) fn argument_types(&self) -> &[(Option, TypeId)] { &self.argument_types } @@ -617,7 +608,7 @@ impl FunctionSig { } /// Is this function signature variadic? - pub fn is_variadic(&self) -> bool { + pub(crate) fn is_variadic(&self) -> bool { // Clang reports some functions as variadic when they *might* be // variadic. We do the argument check because rust doesn't codegen well // variadic functions without an initial argument. @@ -625,7 +616,7 @@ impl FunctionSig { } /// Must this function's return value be used? - pub fn must_use(&self) -> bool { + pub(crate) fn must_use(&self) -> bool { self.must_use } @@ -638,7 +629,7 @@ impl FunctionSig { /// * https://github.com/rust-lang/rust-bindgen/issues/547, /// * https://github.com/rust-lang/rust/issues/38848, /// * and https://github.com/rust-lang/rust/issues/40158 - pub fn function_pointers_can_derive(&self) -> bool { + pub(crate) fn function_pointers_can_derive(&self) -> bool { if self.argument_types.len() > RUST_DERIVE_FUNPTR_LIMIT { return false; } @@ -646,6 +637,7 @@ impl FunctionSig { matches!(self.abi, ClangAbi::Known(Abi::C) | ClangAbi::Unknown(..)) } + /// Whether this function has attributes marking it as divergent. pub(crate) fn is_divergent(&self) -> bool { self.is_divergent } @@ -734,10 +726,9 @@ impl ClangSubItemParser for Function { assert!(!name.is_empty(), "Empty function name."); let mangled_name = cursor_mangling(context, &cursor); - let comment = cursor.raw_comment(); let function = - Self::new(name.clone(), mangled_name, sig, comment, kind, linkage); + Self::new(name.clone(), mangled_name, sig, kind, linkage); Ok(ParseResult::New(function, Some(cursor))) } diff --git a/bindgen/ir/int.rs b/bindgen/ir/int.rs index 22838e897c..bb3032dbcf 100644 --- a/bindgen/ir/int.rs +++ b/bindgen/ir/int.rs @@ -87,7 +87,7 @@ pub enum IntKind { impl IntKind { /// Is this integral type signed? - pub fn is_signed(&self) -> bool { + pub(crate) fn is_signed(&self) -> bool { use self::IntKind::*; match *self { // TODO(emilio): wchar_t can in theory be signed, but we have no way @@ -108,7 +108,7 @@ impl IntKind { /// If this type has a known size, return it (in bytes). This is to /// alleviate libclang sometimes not giving us a layout (like in the case /// when an enum is defined inside a class with template parameters). - pub fn known_size(&self) -> Option { + pub(crate) fn known_size(&self) -> Option { use self::IntKind::*; Some(match *self { Bool | UChar | SChar | U8 | I8 | Char { .. } => 1, @@ -121,7 +121,7 @@ impl IntKind { } /// Whether this type's signedness matches the value. - pub fn signedness_matches(&self, val: i64) -> bool { + pub(crate) fn signedness_matches(&self, val: i64) -> bool { val >= 0 || self.is_signed() } } diff --git a/bindgen/ir/item.rs b/bindgen/ir/item.rs index 40f6f7d927..2492fe8fe4 100644 --- a/bindgen/ir/item.rs +++ b/bindgen/ir/item.rs @@ -38,7 +38,7 @@ use std::iter; /// /// This name is required to be safe for Rust, that is, is not expected to /// return any rust keyword from here. -pub trait ItemCanonicalName { +pub(crate) trait ItemCanonicalName { /// Get the canonical name for this item. fn canonical_name(&self, ctx: &BindgenContext) -> String; } @@ -55,7 +55,7 @@ pub trait ItemCanonicalName { /// /// For bar, the canonical path is `vec!["foo", "BAR"]`, while the canonical /// name is just `"BAR"`. -pub trait ItemCanonicalPath { +pub(crate) trait ItemCanonicalPath { /// Get the namespace-aware canonical path for this item. This means that if /// namespaces are disabled, you'll get a single item, and otherwise you get /// the whole path. @@ -69,7 +69,7 @@ pub trait ItemCanonicalPath { } /// A trait for determining if some IR thing is opaque or not. -pub trait IsOpaque { +pub(crate) trait IsOpaque { /// Extra context the IR thing needs to determine if it is opaque or not. type Extra; @@ -80,20 +80,20 @@ pub trait IsOpaque { } /// A trait for determining if some IR thing has type parameter in array or not. -pub trait HasTypeParamInArray { +pub(crate) trait HasTypeParamInArray { /// Returns `true` if the thing has Array, and `false` otherwise. fn has_type_param_in_array(&self, ctx: &BindgenContext) -> bool; } /// A trait for determining if some IR thing has float or not. -pub trait HasFloat { +pub(crate) trait HasFloat { /// Returns `true` if the thing has float, and `false` otherwise. fn has_float(&self, ctx: &BindgenContext) -> bool; } /// A trait for iterating over an item and its parents and up its ancestor chain /// up to (but not including) the implicit root module. -pub trait ItemAncestors { +pub(crate) trait ItemAncestors { /// Get an iterable over this item's ancestors. fn ancestors<'a>(&self, ctx: &'a BindgenContext) -> ItemAncestorsIter<'a>; } @@ -118,7 +118,7 @@ impl DebugOnlyItemSet { } /// An iterator over an item and its ancestors. -pub struct ItemAncestorsIter<'a> { +pub(crate) struct ItemAncestorsIter<'a> { item: ItemId, ctx: &'a BindgenContext, seen: DebugOnlyItemSet, @@ -375,7 +375,7 @@ impl CanDeriveOrd for Item { /// all of them apply to every item. Those rules are described in the /// `annotations` module. #[derive(Debug)] -pub struct Item { +pub(crate) struct Item { /// This item's id. id: ItemId, @@ -426,7 +426,7 @@ impl AsRef for Item { impl Item { /// Construct a new `Item`. - pub fn new( + pub(crate) fn new( id: ItemId, comment: Option, annotations: Option, @@ -450,7 +450,7 @@ impl Item { } /// Construct a new opaque item type. - pub fn new_opaque_type( + pub(crate) fn new_opaque_type( with_id: ItemId, ty: &clang::Type, ctx: &mut BindgenContext, @@ -468,28 +468,31 @@ impl Item { } /// Get this `Item`'s identifier. - pub fn id(&self) -> ItemId { + pub(crate) fn id(&self) -> ItemId { self.id } /// Get this `Item`'s parent's identifier. /// /// For the root module, the parent's ID is its own ID. - pub fn parent_id(&self) -> ItemId { + pub(crate) fn parent_id(&self) -> ItemId { self.parent_id } /// Set this item's parent id. /// /// This is only used so replacements get generated in the proper module. - pub fn set_parent_for_replacement>(&mut self, id: Id) { + pub(crate) fn set_parent_for_replacement>( + &mut self, + id: Id, + ) { self.parent_id = id.into(); } /// Returns the depth this item is indented to. /// /// FIXME(emilio): This may need fixes for the enums within modules stuff. - pub fn codegen_depth(&self, ctx: &BindgenContext) -> usize { + pub(crate) fn codegen_depth(&self, ctx: &BindgenContext) -> usize { if !ctx.options().enable_cxx_namespaces { return 0; } @@ -507,7 +510,7 @@ impl Item { /// Get this `Item`'s comment, if it has any, already preprocessed and with /// the right indentation. - pub fn comment(&self, ctx: &BindgenContext) -> Option { + pub(crate) fn comment(&self, ctx: &BindgenContext) -> Option { if !ctx.options().generate_comments { return None; } @@ -518,17 +521,17 @@ impl Item { } /// What kind of item is this? - pub fn kind(&self) -> &ItemKind { + pub(crate) fn kind(&self) -> &ItemKind { &self.kind } /// Get a mutable reference to this item's kind. - pub fn kind_mut(&mut self) -> &mut ItemKind { + pub(crate) fn kind_mut(&mut self) -> &mut ItemKind { &mut self.kind } /// Where in the source is this item located? - pub fn location(&self) -> Option<&clang::SourceLocation> { + pub(crate) fn location(&self) -> Option<&clang::SourceLocation> { self.location.as_ref() } @@ -537,7 +540,7 @@ impl Item { /// This should stay relatively stable in the face of code motion outside or /// below this item's lexical scope, meaning that this can be useful for /// generating relatively stable identifiers within a scope. - pub fn local_id(&self, ctx: &BindgenContext) -> usize { + pub(crate) fn local_id(&self, ctx: &BindgenContext) -> usize { *self.local_id.borrow_with(|| { let parent = ctx.resolve_item(self.parent_id); parent.next_child_local_id() @@ -550,7 +553,7 @@ impl Item { /// This is currently used for anonymous items, and template instantiation /// tests, in both cases in order to reduce noise when system headers are at /// place. - pub fn next_child_local_id(&self) -> usize { + pub(crate) fn next_child_local_id(&self) -> usize { let local_id = self.next_child_local_id.get(); self.next_child_local_id.set(local_id + 1); local_id @@ -574,7 +577,7 @@ impl Item { /// This function is used to determine when the codegen phase should call /// `codegen` on an item, since any item that is not top-level will be /// generated by its parent. - pub fn is_toplevel(&self, ctx: &BindgenContext) -> bool { + pub(crate) fn is_toplevel(&self, ctx: &BindgenContext) -> bool { // FIXME: Workaround for some types falling behind when parsing weird // stl classes, for example. if ctx.options().enable_cxx_namespaces && @@ -605,36 +608,36 @@ impl Item { /// Get a reference to this item's underlying `Type`. Panic if this is some /// other kind of item. - pub fn expect_type(&self) -> &Type { + pub(crate) fn expect_type(&self) -> &Type { self.kind().expect_type() } /// Get a reference to this item's underlying `Type`, or `None` if this is /// some other kind of item. - pub fn as_type(&self) -> Option<&Type> { + pub(crate) fn as_type(&self) -> Option<&Type> { self.kind().as_type() } /// Get a reference to this item's underlying `Function`. Panic if this is /// some other kind of item. - pub fn expect_function(&self) -> &Function { + pub(crate) fn expect_function(&self) -> &Function { self.kind().expect_function() } /// Is this item a module? - pub fn is_module(&self) -> bool { + pub(crate) fn is_module(&self) -> bool { matches!(self.kind, ItemKind::Module(..)) } /// Get this item's annotations. - pub fn annotations(&self) -> &Annotations { + pub(crate) fn annotations(&self) -> &Annotations { &self.annotations } /// Whether this item should be blocklisted. /// /// This may be due to either annotations or to other kind of configuration. - pub fn is_blocklisted(&self, ctx: &BindgenContext) -> bool { + pub(crate) fn is_blocklisted(&self, ctx: &BindgenContext) -> bool { debug_assert!( ctx.in_codegen_phase(), "You're not supposed to call this yet" @@ -670,18 +673,11 @@ impl Item { } } - /// Is this a reference to another type? - pub fn is_type_ref(&self) -> bool { - self.as_type().map_or(false, |ty| ty.is_type_ref()) - } - - /// Is this item a var type? - pub fn is_var(&self) -> bool { - matches!(*self.kind(), ItemKind::Var(..)) - } - /// Take out item NameOptions - pub fn name<'a>(&'a self, ctx: &'a BindgenContext) -> NameOptions<'a> { + pub(crate) fn name<'a>( + &'a self, + ctx: &'a BindgenContext, + ) -> NameOptions<'a> { NameOptions::new(self, ctx) } @@ -715,7 +711,10 @@ impl Item { /// Create a fully disambiguated name for an item, including template /// parameters if it is a type - pub fn full_disambiguated_name(&self, ctx: &BindgenContext) -> String { + pub(crate) fn full_disambiguated_name( + &self, + ctx: &BindgenContext, + ) -> String { let mut s = String::new(); let level = 0; self.push_disambiguated_name(ctx, &mut s, level); @@ -839,7 +838,7 @@ impl Item { /// If `BindgenOptions::disable_nested_struct_naming` is true then returned /// name is the inner most non-anonymous name plus all the anonymous base names /// that follows. - pub fn real_canonical_name( + pub(crate) fn real_canonical_name( &self, ctx: &BindgenContext, opt: &NameOptions, @@ -941,7 +940,7 @@ impl Item { /// The exposed id that represents an unique id among the siblings of a /// given item. - pub fn exposed_id(&self, ctx: &BindgenContext) -> String { + pub(crate) fn exposed_id(&self, ctx: &BindgenContext) -> String { // Only use local ids for enums, classes, structs and union types. All // other items use their global id. let ty_kind = self.kind().as_type().map(|t| t.kind()); @@ -962,7 +961,7 @@ impl Item { /// Get a reference to this item's `Module`, or `None` if this is not a /// `Module` item. - pub fn as_module(&self) -> Option<&Module> { + pub(crate) fn as_module(&self) -> Option<&Module> { match self.kind { ItemKind::Module(ref module) => Some(module), _ => None, @@ -971,7 +970,7 @@ impl Item { /// Get a mutable reference to this item's `Module`, or `None` if this is /// not a `Module` item. - pub fn as_module_mut(&mut self) -> Option<&mut Module> { + pub(crate) fn as_module_mut(&mut self) -> Option<&mut Module> { match self.kind { ItemKind::Module(ref mut module) => Some(module), _ => None, @@ -1010,7 +1009,7 @@ impl Item { } /// Is this item of a kind that is enabled for code generation? - pub fn is_enabled_for_codegen(&self, ctx: &BindgenContext) -> bool { + pub(crate) fn is_enabled_for_codegen(&self, ctx: &BindgenContext) -> bool { let cc = &ctx.options().codegen_config; match *self.kind() { ItemKind::Module(..) => true, @@ -1036,7 +1035,10 @@ impl Item { /// Returns the path we should use for allowlisting / blocklisting, which /// doesn't include user-mangling. - pub fn path_for_allowlisting(&self, ctx: &BindgenContext) -> &Vec { + pub(crate) fn path_for_allowlisting( + &self, + ctx: &BindgenContext, + ) -> &Vec { self.path_for_allowlisting .borrow_with(|| self.compute_path(ctx, UserMangled::No)) } @@ -1095,7 +1097,7 @@ impl Item { } /// Whether this is a #[must_use] type. - pub fn must_use(&self, ctx: &BindgenContext) -> bool { + pub(crate) fn must_use(&self, ctx: &BindgenContext) -> bool { self.annotations().must_use_type() || ctx.must_use_type_by_name(self) } } @@ -1222,7 +1224,7 @@ impl HasFloat for Item { } /// A set of items. -pub type ItemSet = BTreeSet; +pub(crate) type ItemSet = BTreeSet; impl DotAttributes for Item { fn dot_attributes( @@ -1306,6 +1308,7 @@ fn visit_child( } impl Item { + /// Create a builtin type. pub(crate) fn builtin_type( kind: TypeKind, is_const: bool, @@ -1331,6 +1334,7 @@ impl Item { id.as_type_id_unchecked() } + /// Parse this item from the given Clang cursor. pub(crate) fn parse( cursor: clang::Cursor, parent_id: Option, @@ -1349,6 +1353,7 @@ impl Item { let current_module = ctx.current_module().into(); let relevant_parent_id = parent_id.unwrap_or(current_module); + #[allow(clippy::missing_docs_in_private_items)] macro_rules! try_parse { ($what:ident) => { match $what::parse(cursor, ctx) { @@ -1477,6 +1482,8 @@ impl Item { } } + /// Parse this item from the given Clang type, or if we haven't resolved all + /// the other items this one depends on, an unresolved reference. pub(crate) fn from_ty_or_ref( ty: clang::Type, location: clang::Cursor, @@ -1552,6 +1559,7 @@ impl Item { potential_id.as_type_id_unchecked() } + /// Parse this item from the given Clang type. See [`Item::from_ty_with_id`]. pub(crate) fn from_ty( ty: &clang::Type, location: clang::Cursor, @@ -1978,7 +1986,7 @@ enum UserMangled { /// Builder struct for naming variations, which hold inside different /// flags for naming options. #[derive(Debug)] -pub struct NameOptions<'a> { +pub(crate) struct NameOptions<'a> { item: &'a Item, ctx: &'a BindgenContext, within_namespaces: bool, @@ -1987,7 +1995,7 @@ pub struct NameOptions<'a> { impl<'a> NameOptions<'a> { /// Construct a new `NameOptions` - pub fn new(item: &'a Item, ctx: &'a BindgenContext) -> Self { + pub(crate) fn new(item: &'a Item, ctx: &'a BindgenContext) -> Self { NameOptions { item, ctx, @@ -1998,7 +2006,7 @@ impl<'a> NameOptions<'a> { /// Construct the name without the item's containing C++ namespaces mangled /// into it. In other words, the item's name within the item's namespace. - pub fn within_namespaces(&mut self) -> &mut Self { + pub(crate) fn within_namespaces(&mut self) -> &mut Self { self.within_namespaces = true; self } @@ -2009,7 +2017,7 @@ impl<'a> NameOptions<'a> { } /// Construct a name `String` - pub fn get(&self) -> String { + pub(crate) fn get(&self) -> String { self.item.real_canonical_name(self.ctx, self) } } diff --git a/bindgen/ir/item_kind.rs b/bindgen/ir/item_kind.rs index 4a12fef40d..e8618498ad 100644 --- a/bindgen/ir/item_kind.rs +++ b/bindgen/ir/item_kind.rs @@ -10,7 +10,7 @@ use std::io; /// A item we parse and translate. #[derive(Debug)] -pub enum ItemKind { +pub(crate) enum ItemKind { /// A module, created implicitly once (the root module), or via C++ /// namespaces. Module(Module), @@ -28,7 +28,7 @@ pub enum ItemKind { impl ItemKind { /// Get a reference to this `ItemKind`'s underying `Module`, or `None` if it /// is some other kind. - pub fn as_module(&self) -> Option<&Module> { + pub(crate) fn as_module(&self) -> Option<&Module> { match *self { ItemKind::Module(ref module) => Some(module), _ => None, @@ -36,7 +36,7 @@ impl ItemKind { } /// Transform our `ItemKind` into a string. - pub fn kind_name(&self) -> &'static str { + pub(crate) fn kind_name(&self) -> &'static str { match *self { ItemKind::Module(..) => "Module", ItemKind::Type(..) => "Type", @@ -46,19 +46,13 @@ impl ItemKind { } /// Is this a module? - pub fn is_module(&self) -> bool { + pub(crate) fn is_module(&self) -> bool { self.as_module().is_some() } - /// Get a reference to this `ItemKind`'s underying `Module`, or panic if it - /// is some other kind. - pub fn expect_module(&self) -> &Module { - self.as_module().expect("Not a module") - } - /// Get a reference to this `ItemKind`'s underying `Function`, or `None` if /// it is some other kind. - pub fn as_function(&self) -> Option<&Function> { + pub(crate) fn as_function(&self) -> Option<&Function> { match *self { ItemKind::Function(ref func) => Some(func), _ => None, @@ -66,19 +60,19 @@ impl ItemKind { } /// Is this a function? - pub fn is_function(&self) -> bool { + pub(crate) fn is_function(&self) -> bool { self.as_function().is_some() } /// Get a reference to this `ItemKind`'s underying `Function`, or panic if /// it is some other kind. - pub fn expect_function(&self) -> &Function { + pub(crate) fn expect_function(&self) -> &Function { self.as_function().expect("Not a function") } /// Get a reference to this `ItemKind`'s underying `Type`, or `None` if /// it is some other kind. - pub fn as_type(&self) -> Option<&Type> { + pub(crate) fn as_type(&self) -> Option<&Type> { match *self { ItemKind::Type(ref ty) => Some(ty), _ => None, @@ -87,7 +81,7 @@ impl ItemKind { /// Get a mutable reference to this `ItemKind`'s underying `Type`, or `None` /// if it is some other kind. - pub fn as_type_mut(&mut self) -> Option<&mut Type> { + pub(crate) fn as_type_mut(&mut self) -> Option<&mut Type> { match *self { ItemKind::Type(ref mut ty) => Some(ty), _ => None, @@ -95,19 +89,19 @@ impl ItemKind { } /// Is this a type? - pub fn is_type(&self) -> bool { + pub(crate) fn is_type(&self) -> bool { self.as_type().is_some() } /// Get a reference to this `ItemKind`'s underying `Type`, or panic if it is /// some other kind. - pub fn expect_type(&self) -> &Type { + pub(crate) fn expect_type(&self) -> &Type { self.as_type().expect("Not a type") } /// Get a reference to this `ItemKind`'s underying `Var`, or `None` if it is /// some other kind. - pub fn as_var(&self) -> Option<&Var> { + pub(crate) fn as_var(&self) -> Option<&Var> { match *self { ItemKind::Var(ref v) => Some(v), _ => None, @@ -115,15 +109,9 @@ impl ItemKind { } /// Is this a variable? - pub fn is_var(&self) -> bool { + pub(crate) fn is_var(&self) -> bool { self.as_var().is_some() } - - /// Get a reference to this `ItemKind`'s underying `Var`, or panic if it is - /// some other kind. - pub fn expect_var(&self) -> &Var { - self.as_var().expect("Not a var") - } } impl DotAttributes for ItemKind { diff --git a/bindgen/ir/layout.rs b/bindgen/ir/layout.rs index 6f4503070a..ba944b06bc 100644 --- a/bindgen/ir/layout.rs +++ b/bindgen/ir/layout.rs @@ -8,13 +8,13 @@ use std::cmp; /// A type that represents the struct layout of a type. #[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub struct Layout { +pub(crate) struct Layout { /// The size (in bytes) of this layout. - pub size: usize, + pub(crate) size: usize, /// The alignment (in bytes) of this layout. - pub align: usize, + pub(crate) align: usize, /// Whether this layout's members are packed or not. - pub packed: bool, + pub(crate) packed: bool, } #[test] @@ -34,7 +34,7 @@ fn test_layout_for_size() { impl Layout { /// Gets the integer type name for a given known size. - pub fn known_type_for_size( + pub(crate) fn known_type_for_size( ctx: &BindgenContext, size: usize, ) -> Option<&'static str> { @@ -50,7 +50,7 @@ impl Layout { /// Construct a new `Layout` with the given `size` and `align`. It is not /// packed. - pub fn new(size: usize, align: usize) -> Self { + pub(crate) fn new(size: usize, align: usize) -> Self { Layout { size, align, @@ -72,33 +72,26 @@ impl Layout { /// Creates a non-packed layout for a given size, trying to use the maximum /// alignment possible. - pub fn for_size(ctx: &BindgenContext, size: usize) -> Self { + pub(crate) fn for_size(ctx: &BindgenContext, size: usize) -> Self { Self::for_size_internal(ctx.target_pointer_size(), size) } - /// Is this a zero-sized layout? - pub fn is_zero(&self) -> bool { - self.size == 0 && self.align == 0 - } - - /// Construct a zero-sized layout. - pub fn zero() -> Self { - Self::new(0, 0) - } - /// Get this layout as an opaque type. - pub fn opaque(&self) -> Opaque { + pub(crate) fn opaque(&self) -> Opaque { Opaque(*self) } } /// When we are treating a type as opaque, it is just a blob with a `Layout`. #[derive(Clone, Debug, PartialEq, Eq)] -pub struct Opaque(pub Layout); +pub(crate) struct Opaque(pub(crate) Layout); impl Opaque { /// Construct a new opaque type from the given clang type. - pub fn from_clang_ty(ty: &clang::Type, ctx: &BindgenContext) -> Type { + pub(crate) fn from_clang_ty( + ty: &clang::Type, + ctx: &BindgenContext, + ) -> Type { let layout = Layout::new(ty.size(ctx), ty.align(ctx)); let ty_kind = TypeKind::Opaque; let is_const = ty.is_const(); @@ -107,7 +100,7 @@ impl Opaque { /// Return the known rust type we should use to create a correctly-aligned /// field with this layout. - pub fn known_rust_type_for_array( + pub(crate) fn known_rust_type_for_array( &self, ctx: &BindgenContext, ) -> Option<&'static str> { @@ -116,7 +109,7 @@ impl Opaque { /// Return the array size that an opaque type for this layout should have if /// we know the correct type for it, or `None` otherwise. - pub fn array_size(&self, ctx: &BindgenContext) -> Option { + pub(crate) fn array_size(&self, ctx: &BindgenContext) -> Option { if self.known_rust_type_for_array(ctx).is_some() { Some(self.0.size / cmp::max(self.0.align, 1)) } else { @@ -127,7 +120,7 @@ impl Opaque { /// Return `true` if this opaque layout's array size will fit within the /// maximum number of array elements that Rust allows deriving traits /// with. Return `false` otherwise. - pub fn array_size_within_derive_limit( + pub(crate) fn array_size_within_derive_limit( &self, ctx: &BindgenContext, ) -> CanDerive { diff --git a/bindgen/ir/mod.rs b/bindgen/ir/mod.rs index 8f6a2dac88..acdb4896cd 100644 --- a/bindgen/ir/mod.rs +++ b/bindgen/ir/mod.rs @@ -2,23 +2,24 @@ //! //! Parsing C/C++ generates the IR, while code generation outputs Rust code from //! the IR. +#![deny(clippy::missing_docs_in_private_items)] -pub mod analysis; -pub mod annotations; -pub mod comment; -pub mod comp; -pub mod context; -pub mod derive; -pub mod dot; -pub mod enum_ty; -pub mod function; -pub mod int; -pub mod item; -pub mod item_kind; -pub mod layout; -pub mod module; -pub mod objc; -pub mod template; -pub mod traversal; -pub mod ty; -pub mod var; +pub(crate) mod analysis; +pub(crate) mod annotations; +pub(crate) mod comment; +pub(crate) mod comp; +pub(crate) mod context; +pub(crate) mod derive; +pub(crate) mod dot; +pub(crate) mod enum_ty; +pub(crate) mod function; +pub(crate) mod int; +pub(crate) mod item; +pub(crate) mod item_kind; +pub(crate) mod layout; +pub(crate) mod module; +pub(crate) mod objc; +pub(crate) mod template; +pub(crate) mod traversal; +pub(crate) mod ty; +pub(crate) mod var; diff --git a/bindgen/ir/module.rs b/bindgen/ir/module.rs index d5aca94a6e..f25ef40f77 100644 --- a/bindgen/ir/module.rs +++ b/bindgen/ir/module.rs @@ -10,7 +10,7 @@ use std::io; /// Whether this module is inline or not. #[derive(Debug, Copy, Clone, PartialEq, Eq)] -pub enum ModuleKind { +pub(crate) enum ModuleKind { /// This module is not inline. Normal, /// This module is inline, as in `inline namespace foo {}`. @@ -19,7 +19,7 @@ pub enum ModuleKind { /// A module, as in, a C++ namespace. #[derive(Clone, Debug)] -pub struct Module { +pub(crate) struct Module { /// The name of the module, or none if it's anonymous. name: Option, /// The kind of module this is. @@ -30,7 +30,7 @@ pub struct Module { impl Module { /// Construct a new `Module`. - pub fn new(name: Option, kind: ModuleKind) -> Self { + pub(crate) fn new(name: Option, kind: ModuleKind) -> Self { Module { name, kind, @@ -39,22 +39,22 @@ impl Module { } /// Get this module's name. - pub fn name(&self) -> Option<&str> { + pub(crate) fn name(&self) -> Option<&str> { self.name.as_deref() } /// Get a mutable reference to this module's children. - pub fn children_mut(&mut self) -> &mut ItemSet { + pub(crate) fn children_mut(&mut self) -> &mut ItemSet { &mut self.children } /// Get this module's children. - pub fn children(&self) -> &ItemSet { + pub(crate) fn children(&self) -> &ItemSet { &self.children } /// Whether this namespace is inline. - pub fn is_inline(&self) -> bool { + pub(crate) fn is_inline(&self) -> bool { self.kind == ModuleKind::Inline } } diff --git a/bindgen/ir/objc.rs b/bindgen/ir/objc.rs index 4f340f6f7a..eaf3b8a545 100644 --- a/bindgen/ir/objc.rs +++ b/bindgen/ir/objc.rs @@ -21,7 +21,7 @@ use proc_macro2::{Ident, Span, TokenStream}; /// /// Also protocols and categories are parsed as this type #[derive(Debug)] -pub struct ObjCInterface { +pub(crate) struct ObjCInterface { /// The name /// like, NSObject name: String, @@ -31,13 +31,13 @@ pub struct ObjCInterface { is_protocol: bool, /// The list of template names almost always, ObjectType or KeyType - pub template_names: Vec, + pub(crate) template_names: Vec, /// The list of protocols that this interface conforms to. - pub conforms_to: Vec, + pub(crate) conforms_to: Vec, /// The direct parent for this interface. - pub parent_class: Option, + pub(crate) parent_class: Option, /// List of the methods defined in this interfae methods: Vec, @@ -47,7 +47,7 @@ pub struct ObjCInterface { /// The objective c methods #[derive(Debug)] -pub struct ObjCMethod { +pub(crate) struct ObjCMethod { /// The original method selector name /// like, dataWithBytes:length: name: String, @@ -78,14 +78,14 @@ impl ObjCInterface { /// The name /// like, NSObject - pub fn name(&self) -> &str { + pub(crate) fn name(&self) -> &str { self.name.as_ref() } /// Formats the name for rust /// Can be like NSObject, but with categories might be like NSObject_NSCoderMethods /// and protocols are like PNSObject - pub fn rust_name(&self) -> String { + pub(crate) fn rust_name(&self) -> String { if let Some(ref cat) = self.category { format!("{}_{}", self.name(), cat) } else if self.is_protocol { @@ -96,32 +96,32 @@ impl ObjCInterface { } /// Is this a template interface? - pub fn is_template(&self) -> bool { + pub(crate) fn is_template(&self) -> bool { !self.template_names.is_empty() } /// List of the methods defined in this interface - pub fn methods(&self) -> &Vec { + pub(crate) fn methods(&self) -> &Vec { &self.methods } /// Is this a protocol? - pub fn is_protocol(&self) -> bool { + pub(crate) fn is_protocol(&self) -> bool { self.is_protocol } /// Is this a category? - pub fn is_category(&self) -> bool { + pub(crate) fn is_category(&self) -> bool { self.category.is_some() } /// List of the class methods defined in this interface - pub fn class_methods(&self) -> &Vec { + pub(crate) fn class_methods(&self) -> &Vec { &self.class_methods } /// Parses the Objective C interface from the cursor - pub fn from_ty( + pub(crate) fn from_ty( cursor: &clang::Cursor, ctx: &mut BindgenContext, ) -> Option { @@ -229,30 +229,27 @@ impl ObjCMethod { } } - /// The original method selector name - /// like, dataWithBytes:length: - pub fn name(&self) -> &str { - self.name.as_ref() - } - /// Method name as converted to rust /// like, dataWithBytes_length_ - pub fn rust_name(&self) -> &str { + pub(crate) fn rust_name(&self) -> &str { self.rust_name.as_ref() } /// Returns the methods signature as FunctionSig - pub fn signature(&self) -> &FunctionSig { + pub(crate) fn signature(&self) -> &FunctionSig { &self.signature } /// Is this a class method? - pub fn is_class_method(&self) -> bool { + pub(crate) fn is_class_method(&self) -> bool { self.is_class_method } /// Formats the method call - pub fn format_method_call(&self, args: &[TokenStream]) -> TokenStream { + pub(crate) fn format_method_call( + &self, + args: &[TokenStream], + ) -> TokenStream { let split_name: Vec> = self .name .split(':') diff --git a/bindgen/ir/template.rs b/bindgen/ir/template.rs index e3ef6a9c96..0a2c269eed 100644 --- a/bindgen/ir/template.rs +++ b/bindgen/ir/template.rs @@ -98,7 +98,7 @@ use crate::clang; /// ... |Wtf | ... | [T] | /// ... |Qux | ... | [] | /// ----+------+-----+----------------------+ -pub trait TemplateParameters: Sized { +pub(crate) trait TemplateParameters: Sized { /// Get the set of `ItemId`s that make up this template declaration's free /// template parameters. /// @@ -163,7 +163,7 @@ pub trait TemplateParameters: Sized { } /// A trait for things which may or may not be a named template type parameter. -pub trait AsTemplateParam { +pub(crate) trait AsTemplateParam { /// Any extra information the implementor might need to make this decision. type Extra; @@ -186,7 +186,7 @@ pub trait AsTemplateParam { /// A concrete instantiation of a generic template. #[derive(Clone, Debug)] -pub struct TemplateInstantiation { +pub(crate) struct TemplateInstantiation { /// The template definition which this is instantiating. definition: TypeId, /// The concrete template arguments, which will be substituted in the @@ -196,7 +196,7 @@ pub struct TemplateInstantiation { impl TemplateInstantiation { /// Construct a new template instantiation from the given parts. - pub fn new(definition: TypeId, args: I) -> TemplateInstantiation + pub(crate) fn new(definition: TypeId, args: I) -> TemplateInstantiation where I: IntoIterator, { @@ -207,17 +207,17 @@ impl TemplateInstantiation { } /// Get the template definition for this instantiation. - pub fn template_definition(&self) -> TypeId { + pub(crate) fn template_definition(&self) -> TypeId { self.definition } /// Get the concrete template arguments used in this instantiation. - pub fn template_arguments(&self) -> &[TypeId] { + pub(crate) fn template_arguments(&self) -> &[TypeId] { &self.args[..] } /// Parse a `TemplateInstantiation` from a clang `Type`. - pub fn from_ty( + pub(crate) fn from_ty( ty: &clang::Type, ctx: &mut BindgenContext, ) -> Option { diff --git a/bindgen/ir/traversal.rs b/bindgen/ir/traversal.rs index f14483f295..17e24f701e 100644 --- a/bindgen/ir/traversal.rs +++ b/bindgen/ir/traversal.rs @@ -12,14 +12,14 @@ use std::collections::{BTreeMap, VecDeque}; /// The `from` is left implicit: it is the concrete `Trace` implementer which /// yielded this outgoing edge. #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct Edge { +pub(crate) struct Edge { to: ItemId, kind: EdgeKind, } impl Edge { /// Construct a new edge whose referent is `to` and is of the given `kind`. - pub fn new(to: ItemId, kind: EdgeKind) -> Edge { + pub(crate) fn new(to: ItemId, kind: EdgeKind) -> Edge { Edge { to, kind } } } @@ -33,7 +33,7 @@ impl From for ItemId { /// The kind of edge reference. This is useful when we wish to only consider /// certain kinds of edges for a particular traversal or analysis. #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub enum EdgeKind { +pub(crate) enum EdgeKind { /// A generic, catch-all edge. Generic, @@ -182,12 +182,13 @@ pub enum EdgeKind { /// /// The predicate must return true if the traversal should follow this edge /// and visit everything that is reachable through it. -pub type TraversalPredicate = for<'a> fn(&'a BindgenContext, Edge) -> bool; +pub(crate) type TraversalPredicate = + for<'a> fn(&'a BindgenContext, Edge) -> bool; /// A `TraversalPredicate` implementation that follows all edges, and therefore /// traversals using this predicate will see the whole IR graph reachable from /// the traversal's roots. -pub fn all_edges(_: &BindgenContext, _: Edge) -> bool { +pub(crate) fn all_edges(_: &BindgenContext, _: Edge) -> bool { true } @@ -196,14 +197,14 @@ pub fn all_edges(_: &BindgenContext, _: Edge) -> bool { /// will only visit the traversal's roots and their inner types. This is used /// in no-recursive-allowlist mode, where inner types such as anonymous /// structs/unions still need to be processed. -pub fn only_inner_type_edges(_: &BindgenContext, edge: Edge) -> bool { +pub(crate) fn only_inner_type_edges(_: &BindgenContext, edge: Edge) -> bool { edge.kind == EdgeKind::InnerType } /// A `TraversalPredicate` implementation that only follows edges to items that /// are enabled for code generation. This lets us skip considering items for /// which are not reachable from code generation. -pub fn codegen_edges(ctx: &BindgenContext, edge: Edge) -> bool { +pub(crate) fn codegen_edges(ctx: &BindgenContext, edge: Edge) -> bool { let cc = &ctx.options().codegen_config; match edge.kind { EdgeKind::Generic => { @@ -233,7 +234,7 @@ pub fn codegen_edges(ctx: &BindgenContext, edge: Edge) -> bool { /// The storage for the set of items that have been seen (although their /// outgoing edges might not have been fully traversed yet) in an active /// traversal. -pub trait TraversalStorage<'ctx> { +pub(crate) trait TraversalStorage<'ctx> { /// Construct a new instance of this TraversalStorage, for a new traversal. fn new(ctx: &'ctx BindgenContext) -> Self; @@ -259,7 +260,7 @@ impl<'ctx> TraversalStorage<'ctx> for ItemSet { /// each item. This is useful for providing debug assertions with meaningful /// diagnostic messages about dangling items. #[derive(Debug)] -pub struct Paths<'ctx>(BTreeMap, &'ctx BindgenContext); +pub(crate) struct Paths<'ctx>(BTreeMap, &'ctx BindgenContext); impl<'ctx> TraversalStorage<'ctx> for Paths<'ctx> { fn new(ctx: &'ctx BindgenContext) -> Self { @@ -300,7 +301,7 @@ impl<'ctx> TraversalStorage<'ctx> for Paths<'ctx> { /// Using a FIFO queue with a traversal will yield a breadth-first traversal, /// while using a LIFO queue will result in a depth-first traversal of the IR /// graph. -pub trait TraversalQueue: Default { +pub(crate) trait TraversalQueue: Default { /// Add a newly discovered item to the queue. fn push(&mut self, item: ItemId); @@ -329,7 +330,7 @@ impl TraversalQueue for VecDeque { } /// Something that can receive edges from a `Trace` implementation. -pub trait Tracer { +pub(crate) trait Tracer { /// Note an edge between items. Called from within a `Trace` implementation. fn visit_kind(&mut self, item: ItemId, kind: EdgeKind); @@ -351,7 +352,7 @@ where /// Trace all of the outgoing edges to other items. Implementations should call /// one of `tracer.visit(edge)` or `tracer.visit_kind(edge, EdgeKind::Whatever)` /// for each of their outgoing edges. -pub trait Trace { +pub(crate) trait Trace { /// If a particular type needs extra information beyond what it has in /// `self` and `context` to find its referenced items, its implementation /// can define this associated type, forcing callers to pass the needed @@ -371,7 +372,7 @@ pub trait Trace { /// An graph traversal of the transitive closure of references between items. /// /// See `BindgenContext::allowlisted_items` for more information. -pub struct ItemTraversal<'ctx, Storage, Queue> +pub(crate) struct ItemTraversal<'ctx, Storage, Queue> where Storage: TraversalStorage<'ctx>, Queue: TraversalQueue, @@ -397,7 +398,7 @@ where Queue: TraversalQueue, { /// Begin a new traversal, starting from the given roots. - pub fn new( + pub(crate) fn new( ctx: &'ctx BindgenContext, roots: R, predicate: TraversalPredicate, @@ -474,5 +475,5 @@ where /// /// See `BindgenContext::assert_no_dangling_item_traversal` for more /// information. -pub type AssertNoDanglingItemsTraversal<'ctx> = +pub(crate) type AssertNoDanglingItemsTraversal<'ctx> = ItemTraversal<'ctx, Paths<'ctx>, VecDeque>; diff --git a/bindgen/ir/ty.rs b/bindgen/ir/ty.rs index fef340dee9..ca66e1106b 100644 --- a/bindgen/ir/ty.rs +++ b/bindgen/ir/ty.rs @@ -24,7 +24,7 @@ use std::io; /// (size, alignment and packedness) if known, a `Kind`, which determines which /// kind of type it is, and whether the type is const. #[derive(Debug)] -pub struct Type { +pub(crate) struct Type { /// The name of the type, or None if it was an unnamed struct or union. name: Option, /// The layout of the type, if known. @@ -39,21 +39,12 @@ pub struct Type { /// traits, and so if we have a type containing an array with more than this /// many items, we won't be able to derive common traits on that type. /// -pub const RUST_DERIVE_IN_ARRAY_LIMIT: usize = 32; +pub(crate) const RUST_DERIVE_IN_ARRAY_LIMIT: usize = 32; impl Type { - /// Get the underlying `CompInfo` for this type, or `None` if this is some - /// other kind of type. - pub fn as_comp(&self) -> Option<&CompInfo> { - match self.kind { - TypeKind::Comp(ref ci) => Some(ci), - _ => None, - } - } - /// Get the underlying `CompInfo` for this type as a mutable reference, or /// `None` if this is some other kind of type. - pub fn as_comp_mut(&mut self) -> Option<&mut CompInfo> { + pub(crate) fn as_comp_mut(&mut self) -> Option<&mut CompInfo> { match self.kind { TypeKind::Comp(ref mut ci) => Some(ci), _ => None, @@ -61,7 +52,7 @@ impl Type { } /// Construct a new `Type`. - pub fn new( + pub(crate) fn new( name: Option, layout: Option, kind: TypeKind, @@ -76,37 +67,37 @@ impl Type { } /// Which kind of type is this? - pub fn kind(&self) -> &TypeKind { + pub(crate) fn kind(&self) -> &TypeKind { &self.kind } /// Get a mutable reference to this type's kind. - pub fn kind_mut(&mut self) -> &mut TypeKind { + pub(crate) fn kind_mut(&mut self) -> &mut TypeKind { &mut self.kind } /// Get this type's name. - pub fn name(&self) -> Option<&str> { + pub(crate) fn name(&self) -> Option<&str> { self.name.as_deref() } /// Whether this is a block pointer type. - pub fn is_block_pointer(&self) -> bool { + pub(crate) fn is_block_pointer(&self) -> bool { matches!(self.kind, TypeKind::BlockPointer(..)) } /// Is this an integer type, including `bool` or `char`? - pub fn is_int(&self) -> bool { + pub(crate) fn is_int(&self) -> bool { matches!(self.kind, TypeKind::Int(_)) } /// Is this a compound type? - pub fn is_comp(&self) -> bool { + pub(crate) fn is_comp(&self) -> bool { matches!(self.kind, TypeKind::Comp(..)) } /// Is this a union? - pub fn is_union(&self) -> bool { + pub(crate) fn is_union(&self) -> bool { match self.kind { TypeKind::Comp(ref comp) => comp.is_union(), _ => false, @@ -114,32 +105,27 @@ impl Type { } /// Is this type of kind `TypeKind::TypeParam`? - pub fn is_type_param(&self) -> bool { + pub(crate) fn is_type_param(&self) -> bool { matches!(self.kind, TypeKind::TypeParam) } /// Is this a template instantiation type? - pub fn is_template_instantiation(&self) -> bool { + pub(crate) fn is_template_instantiation(&self) -> bool { matches!(self.kind, TypeKind::TemplateInstantiation(..)) } - /// Is this a template alias type? - pub fn is_template_alias(&self) -> bool { - matches!(self.kind, TypeKind::TemplateAlias(..)) - } - /// Is this a function type? - pub fn is_function(&self) -> bool { + pub(crate) fn is_function(&self) -> bool { matches!(self.kind, TypeKind::Function(..)) } /// Is this an enum type? - pub fn is_enum(&self) -> bool { + pub(crate) fn is_enum(&self) -> bool { matches!(self.kind, TypeKind::Enum(..)) } /// Is this either a builtin or named type? - pub fn is_builtin_or_type_param(&self) -> bool { + pub(crate) fn is_builtin_or_type_param(&self) -> bool { matches!( self.kind, TypeKind::Void | @@ -155,29 +141,29 @@ impl Type { } /// Creates a new named type, with name `name`. - pub fn named(name: String) -> Self { + pub(crate) fn named(name: String) -> Self { let name = if name.is_empty() { None } else { Some(name) }; Self::new(name, None, TypeKind::TypeParam, false) } /// Is this a floating point type? - pub fn is_float(&self) -> bool { + pub(crate) fn is_float(&self) -> bool { matches!(self.kind, TypeKind::Float(..)) } /// Is this a boolean type? - pub fn is_bool(&self) -> bool { + pub(crate) fn is_bool(&self) -> bool { matches!(self.kind, TypeKind::Int(IntKind::Bool)) } /// Is this an integer type? - pub fn is_integer(&self) -> bool { + pub(crate) fn is_integer(&self) -> bool { matches!(self.kind, TypeKind::Int(..)) } /// Cast this type to an integer kind, or `None` if it is not an integer /// type. - pub fn as_integer(&self) -> Option { + pub(crate) fn as_integer(&self) -> Option { match self.kind { TypeKind::Int(int_kind) => Some(int_kind), _ => None, @@ -185,25 +171,20 @@ impl Type { } /// Is this a `const` qualified type? - pub fn is_const(&self) -> bool { + pub(crate) fn is_const(&self) -> bool { self.is_const } - /// Is this a reference to another type? - pub fn is_type_ref(&self) -> bool { - matches!( - self.kind, - TypeKind::ResolvedTypeRef(_) | TypeKind::UnresolvedTypeRef(_, _, _) - ) - } - /// Is this an unresolved reference? - pub fn is_unresolved_ref(&self) -> bool { + pub(crate) fn is_unresolved_ref(&self) -> bool { matches!(self.kind, TypeKind::UnresolvedTypeRef(_, _, _)) } /// Is this a incomplete array type? - pub fn is_incomplete_array(&self, ctx: &BindgenContext) -> Option { + pub(crate) fn is_incomplete_array( + &self, + ctx: &BindgenContext, + ) -> Option { match self.kind { TypeKind::Array(item, len) => { if len == 0 { @@ -220,7 +201,7 @@ impl Type { } /// What is the layout of this type? - pub fn layout(&self, ctx: &BindgenContext) -> Option { + pub(crate) fn layout(&self, ctx: &BindgenContext) -> Option { self.layout.or_else(|| { match self.kind { TypeKind::Comp(ref ci) => ci.layout(ctx), @@ -245,7 +226,7 @@ impl Type { /// avoid generating invalid code with some cases we can't handle, see: /// /// tests/headers/381-decltype-alias.hpp - pub fn is_invalid_type_param(&self) -> bool { + pub(crate) fn is_invalid_type_param(&self) -> bool { match self.kind { TypeKind::TypeParam => { let name = self.name().expect("Unnamed named type?"); @@ -266,7 +247,7 @@ impl Type { } /// Get this type's santizied name. - pub fn sanitized_name<'a>( + pub(crate) fn sanitized_name<'a>( &'a self, ctx: &BindgenContext, ) -> Option> { @@ -289,7 +270,7 @@ impl Type { } /// See safe_canonical_type. - pub fn canonical_type<'tr>( + pub(crate) fn canonical_type<'tr>( &'tr self, ctx: &'tr BindgenContext, ) -> &'tr Type { @@ -302,7 +283,7 @@ impl Type { /// For example, for a `typedef`, the canonical type would be the /// `typedef`ed type, for a template instantiation, would be the template /// its specializing, and so on. Return None if the type is unresolved. - pub fn safe_canonical_type<'tr>( + pub(crate) fn safe_canonical_type<'tr>( &'tr self, ctx: &'tr BindgenContext, ) -> Option<&'tr Type> { @@ -341,7 +322,7 @@ impl Type { /// There are some types we don't want to stop at when finding an opaque /// item, so we can arrive to the proper item that needs to be generated. - pub fn should_be_traced_unconditionally(&self) -> bool { + pub(crate) fn should_be_traced_unconditionally(&self) -> bool { matches!( self.kind, TypeKind::Comp(..) | @@ -570,7 +551,7 @@ impl TemplateParameters for TypeKind { /// The kind of float this type represents. #[derive(Debug, Copy, Clone, PartialEq, Eq)] -pub enum FloatKind { +pub(crate) enum FloatKind { /// A `float`. Float, /// A `double`. @@ -583,7 +564,7 @@ pub enum FloatKind { /// The different kinds of types that we can parse. #[derive(Debug)] -pub enum TypeKind { +pub(crate) enum TypeKind { /// The void type. Void, @@ -680,7 +661,7 @@ impl Type { /// /// It's sort of nasty and full of special-casing, but hopefully the /// comments in every special case justify why they're there. - pub fn from_clang_ty( + pub(crate) fn from_clang_ty( potential_id: ItemId, ty: &clang::Type, location: Cursor, diff --git a/bindgen/ir/var.rs b/bindgen/ir/var.rs index 903e1ff549..b80737627a 100644 --- a/bindgen/ir/var.rs +++ b/bindgen/ir/var.rs @@ -17,7 +17,7 @@ use std::num::Wrapping; /// The type for a constant variable. #[derive(Debug)] -pub enum VarType { +pub(crate) enum VarType { /// A boolean. Bool(bool), /// An integer. @@ -32,7 +32,7 @@ pub enum VarType { /// A `Var` is our intermediate representation of a variable. #[derive(Debug)] -pub struct Var { +pub(crate) struct Var { /// The name of the variable. name: String, /// The mangled name of the variable. @@ -47,7 +47,7 @@ pub struct Var { impl Var { /// Construct a new `Var`. - pub fn new( + pub(crate) fn new( name: String, mangled_name: Option, ty: TypeId, @@ -65,27 +65,27 @@ impl Var { } /// Is this variable `const` qualified? - pub fn is_const(&self) -> bool { + pub(crate) fn is_const(&self) -> bool { self.is_const } /// The value of this constant variable, if any. - pub fn val(&self) -> Option<&VarType> { + pub(crate) fn val(&self) -> Option<&VarType> { self.val.as_ref() } /// Get this variable's type. - pub fn ty(&self) -> TypeId { + pub(crate) fn ty(&self) -> TypeId { self.ty } /// Get this variable's name. - pub fn name(&self) -> &str { + pub(crate) fn name(&self) -> &str { &self.name } /// Get this variable's mangled name. - pub fn mangled_name(&self) -> Option<&str> { + pub(crate) fn mangled_name(&self) -> Option<&str> { self.mangled_name.as_deref() } } diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 14d7a15576..0a89462fce 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -34,22 +34,6 @@ mod log_stubs; #[macro_use] mod extra_assertions; -// A macro to declare an internal module for which we *must* provide -// documentation for. If we are building with the "testing_only_docs" feature, -// then the module is declared public, and our `#![deny(missing_docs)]` pragma -// applies to it. This feature is used in CI, so we won't let anything slip by -// undocumented. Normal builds, however, will leave the module private, so that -// we don't expose internals to library consumers. -macro_rules! doc_mod { - ($m:ident, $doc_mod_name:ident) => { - #[cfg(feature = "testing_only_docs")] - pub mod $doc_mod_name { - //! Autogenerated documentation module. - pub use super::$m::*; - } - }; -} - macro_rules! fn_with_regex_arg { ($(#[$attrs:meta])* pub fn $($tokens:tt)*) => { $(#[$attrs])* @@ -62,22 +46,17 @@ macro_rules! fn_with_regex_arg { }; } -mod clang; mod codegen; mod deps; -mod features; -pub mod ir; -mod parse; -mod regex_set; mod time; pub mod callbacks; -doc_mod!(clang, clang_docs); -doc_mod!(features, features_docs); -doc_mod!(ir, ir_docs); -doc_mod!(parse, parse_docs); -doc_mod!(regex_set, regex_set_docs); +mod clang; +mod features; +mod ir; +mod parse; +mod regex_set; use codegen::CodegenError; use ir::comment; diff --git a/bindgen/parse.rs b/bindgen/parse.rs index 1fd83cddda..d29b090fcb 100644 --- a/bindgen/parse.rs +++ b/bindgen/parse.rs @@ -1,4 +1,5 @@ //! Common traits and types related to parsing our IR from Clang cursors. +#![deny(clippy::missing_docs_in_private_items)] use crate::clang; use crate::ir::context::{BindgenContext, ItemId}; @@ -6,7 +7,7 @@ use crate::ir::context::{BindgenContext, ItemId}; /// Not so much an error in the traditional sense, but a control flow message /// when walking over Clang's AST with a cursor. #[derive(Debug)] -pub enum ParseError { +pub(crate) enum ParseError { /// Recurse down the current AST node's children. Recurse, /// Continue on to the next sibling AST node, or back up to the parent's @@ -16,7 +17,7 @@ pub enum ParseError { /// The result of parsing a Clang AST node. #[derive(Debug)] -pub enum ParseResult { +pub(crate) enum ParseResult { /// We've already resolved this item before, here is the extant `ItemId` for /// it. AlreadyResolved(ItemId), @@ -28,7 +29,7 @@ pub enum ParseResult { /// An intermediate representation "sub-item" (i.e. one of the types contained /// inside an `ItemKind` variant) that can be parsed from a Clang cursor. -pub trait ClangSubItemParser: Sized { +pub(crate) trait ClangSubItemParser: Sized { /// Attempt to parse this type from the given cursor. /// /// The fact that is a reference guarantees it's held by the context, and diff --git a/bindgen/regex_set.rs b/bindgen/regex_set.rs index 6246dd255b..31da247cbc 100644 --- a/bindgen/regex_set.rs +++ b/bindgen/regex_set.rs @@ -1,4 +1,5 @@ //! A type that represents the union of a set of regular expressions. +#![deny(clippy::missing_docs_in_private_items)] use regex::RegexSet as RxSet; use std::cell::Cell; diff --git a/ci/test.sh b/ci/test.sh index 788c28fe27..835d606ed1 100755 --- a/ci/test.sh +++ b/ci/test.sh @@ -110,9 +110,6 @@ get_cargo_args() { if [ "$BINDGEN_FEATURE_EXTRA_ASSERTS" == "1" ]; then features+=" testing_only_extra_assertions" fi - if [ "$BINDGEN_FEATURE_TESTING_ONLY_DOCS" == "1" ]; then - features+=" testing_only_docs" - fi if [ ! -z "$features" ]; then args+=" --features $(echo $features | tr ' ' ',')" fi diff --git a/clippy.toml b/clippy.toml index 1060a6b4e7..26a0605343 100644 --- a/clippy.toml +++ b/clippy.toml @@ -2,3 +2,4 @@ disallowed-methods = [ { path = "clang_sys::CXCursor_TranslationUnit", reason = "This value was changed in clang 15"}, { path = "clang_sys::CXCursor_LastStmt", reason = "This value was changed in clang 15"} ] +missing-docs-in-crate-items = true From fa04ceda26157de34c9a9887c4bae7b94d085b2d Mon Sep 17 00:00:00 2001 From: Amanjeev Sethi Date: Tue, 7 Mar 2023 09:49:53 -0500 Subject: [PATCH 461/942] Clippy placation (#2433) * clippy placation * clippy placation; cargo fmt --- bindgen/ir/context.rs | 3 +-- bindgen/ir/function.rs | 3 +-- bindgen/ir/item.rs | 4 ++-- bindgen/ir/var.rs | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index b821429a42..057c4d4ac5 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -23,8 +23,7 @@ use crate::clang::{self, Cursor}; use crate::codegen::CodegenError; use crate::BindgenOptions; use crate::{Entry, HashMap, HashSet}; -use cexpr; -use clang_sys; + use proc_macro2::{Ident, Span, TokenStream}; use quote::ToTokens; use std::borrow::Cow; diff --git a/bindgen/ir/function.rs b/bindgen/ir/function.rs index dccd9b2467..dbb155dc1c 100644 --- a/bindgen/ir/function.rs +++ b/bindgen/ir/function.rs @@ -10,8 +10,7 @@ use crate::callbacks::{ItemInfo, ItemKind}; use crate::clang::{self, Attribute}; use crate::parse::{ClangSubItemParser, ParseError, ParseResult}; use clang_sys::{self, CXCallingConv}; -use proc_macro2; -use quote; + use quote::TokenStreamExt; use std::io; use std::str::FromStr; diff --git a/bindgen/ir/item.rs b/bindgen/ir/item.rs index 2492fe8fe4..fec014911b 100644 --- a/bindgen/ir/item.rs +++ b/bindgen/ir/item.rs @@ -19,9 +19,9 @@ use super::traversal::{EdgeKind, Trace, Tracer}; use super::ty::{Type, TypeKind}; use crate::clang; use crate::parse::{ClangSubItemParser, ParseError, ParseResult}; -use clang_sys; + use lazycell::LazyCell; -use regex; + use std::cell::Cell; use std::collections::BTreeSet; use std::fmt::Write; diff --git a/bindgen/ir/var.rs b/bindgen/ir/var.rs index b80737627a..620b25cb53 100644 --- a/bindgen/ir/var.rs +++ b/bindgen/ir/var.rs @@ -11,7 +11,7 @@ use crate::callbacks::{ItemInfo, ItemKind, MacroParsingBehavior}; use crate::clang; use crate::clang::ClangToken; use crate::parse::{ClangSubItemParser, ParseError, ParseResult}; -use cexpr; + use std::io; use std::num::Wrapping; From 91df88da705be23bd9f9e9e219d6bfd6ed23a8cc Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Tue, 14 Mar 2023 18:17:45 +0100 Subject: [PATCH 462/942] Do not build an extra identical structure (#2440) This makes the code more complex than needed. Part of a clippy lint being developed. --- bindgen/regex_set.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bindgen/regex_set.rs b/bindgen/regex_set.rs index 31da247cbc..f827107efd 100644 --- a/bindgen/regex_set.rs +++ b/bindgen/regex_set.rs @@ -19,9 +19,7 @@ pub struct RegexSet { impl RegexSet { /// Create a new RegexSet pub fn new() -> RegexSet { - RegexSet { - ..Default::default() - } + RegexSet::default() } /// Is this set empty? From f019a9bebc9dd1f5143d87b5a918f1667985e690 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Tue, 14 Mar 2023 19:32:26 +0100 Subject: [PATCH 463/942] Fix typos. (#2439) --- .../expectations/tests/layout_eth_conf.rs | 6 +-- .../expectations/tests/layout_eth_conf_1_0.rs | 6 +-- bindgen-tests/tests/headers/layout_eth_conf.h | 6 +-- .../tests/headers/layout_eth_conf_1_0.h | 6 +-- .../tests/quickchecking/src/fuzzers.rs | 2 +- bindgen/codegen/mod.rs | 4 +- bindgen/ir/analysis/sizedness.rs | 2 +- bindgen/ir/analysis/template_params.rs | 4 +- bindgen/ir/comp.rs | 2 +- bindgen/ir/context.rs | 46 +++++++++---------- bindgen/ir/function.rs | 4 +- bindgen/ir/int.rs | 2 +- bindgen/ir/item.rs | 32 ++++++------- bindgen/ir/template.rs | 2 +- bindgen/ir/ty.rs | 2 +- 15 files changed, 63 insertions(+), 63 deletions(-) diff --git a/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs b/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs index 62b99e9041..7dd45b709e 100644 --- a/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs +++ b/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs @@ -642,7 +642,7 @@ pub enum rte_eth_nb_pools { /// of an Ethernet port. /// /// Using this feature, packets are routed to a pool of queues, based -/// on the vlan id in the vlan tag, and then to a specific queue within +/// on the vlan ID in the vlan tag, and then to a specific queue within /// that pool, using the user priority vlan tag field. /// /// A default pool may be used, if desired, to route all traffic which @@ -665,7 +665,7 @@ pub struct rte_eth_vmdq_dcb_conf { #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_eth_vmdq_dcb_conf__bindgen_ty_1 { - ///< The vlan id of the received frame + ///< The vlan ID of the received frame pub vlan_id: u16, ///< Bitmask of pools for packet rx pub pools: u64, @@ -1030,7 +1030,7 @@ pub struct rte_eth_vmdq_rx_conf { #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_eth_vmdq_rx_conf__bindgen_ty_1 { - ///< The vlan id of the received frame + ///< The vlan ID of the received frame pub vlan_id: u16, ///< Bitmask of pools for packet rx pub pools: u64, diff --git a/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs b/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs index d7fa0a634a..1ffb508d5d 100644 --- a/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs @@ -700,7 +700,7 @@ pub enum rte_eth_nb_pools { /// of an Ethernet port. /// /// Using this feature, packets are routed to a pool of queues, based -/// on the vlan id in the vlan tag, and then to a specific queue within +/// on the vlan ID in the vlan tag, and then to a specific queue within /// that pool, using the user priority vlan tag field. /// /// A default pool may be used, if desired, to route all traffic which @@ -723,7 +723,7 @@ pub struct rte_eth_vmdq_dcb_conf { #[repr(C)] #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct rte_eth_vmdq_dcb_conf__bindgen_ty_1 { - ///< The vlan id of the received frame + ///< The vlan ID of the received frame pub vlan_id: u16, ///< Bitmask of pools for packet rx pub pools: u64, @@ -1118,7 +1118,7 @@ pub struct rte_eth_vmdq_rx_conf { #[repr(C)] #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct rte_eth_vmdq_rx_conf__bindgen_ty_1 { - ///< The vlan id of the received frame + ///< The vlan ID of the received frame pub vlan_id: u16, ///< Bitmask of pools for packet rx pub pools: u64, diff --git a/bindgen-tests/tests/headers/layout_eth_conf.h b/bindgen-tests/tests/headers/layout_eth_conf.h index 9446bffb4c..1c821c9769 100644 --- a/bindgen-tests/tests/headers/layout_eth_conf.h +++ b/bindgen-tests/tests/headers/layout_eth_conf.h @@ -139,7 +139,7 @@ enum rte_eth_nb_pools { * of an Ethernet port. * * Using this feature, packets are routed to a pool of queues, based - * on the vlan id in the vlan tag, and then to a specific queue within + * on the vlan ID in the vlan tag, and then to a specific queue within * that pool, using the user priority vlan tag field. * * A default pool may be used, if desired, to route all traffic which @@ -151,7 +151,7 @@ struct rte_eth_vmdq_dcb_conf { uint8_t default_pool; /**< The default pool, if applicable */ uint8_t nb_pool_maps; /**< We can have up to 64 filters/mappings */ struct { - uint16_t vlan_id; /**< The vlan id of the received frame */ + uint16_t vlan_id; /**< The vlan ID of the received frame */ uint64_t pools; /**< Bitmask of pools for packet rx */ } pool_map[ETH_VMDQ_MAX_VLAN_FILTERS]; /**< VMDq vlan pool maps. */ uint8_t dcb_tc[ETH_DCB_NUM_USER_PRIORITIES]; @@ -189,7 +189,7 @@ struct rte_eth_vmdq_rx_conf { uint8_t nb_pool_maps; /**< We can have up to 64 filters/mappings */ uint32_t rx_mode; /**< Flags from ETH_VMDQ_ACCEPT_* */ struct { - uint16_t vlan_id; /**< The vlan id of the received frame */ + uint16_t vlan_id; /**< The vlan ID of the received frame */ uint64_t pools; /**< Bitmask of pools for packet rx */ } pool_map[ETH_VMDQ_MAX_VLAN_FILTERS]; /**< VMDq vlan pool maps. */ }; diff --git a/bindgen-tests/tests/headers/layout_eth_conf_1_0.h b/bindgen-tests/tests/headers/layout_eth_conf_1_0.h index 48ba39ff87..7da582ba19 100644 --- a/bindgen-tests/tests/headers/layout_eth_conf_1_0.h +++ b/bindgen-tests/tests/headers/layout_eth_conf_1_0.h @@ -140,7 +140,7 @@ enum rte_eth_nb_pools { * of an Ethernet port. * * Using this feature, packets are routed to a pool of queues, based - * on the vlan id in the vlan tag, and then to a specific queue within + * on the vlan ID in the vlan tag, and then to a specific queue within * that pool, using the user priority vlan tag field. * * A default pool may be used, if desired, to route all traffic which @@ -152,7 +152,7 @@ struct rte_eth_vmdq_dcb_conf { uint8_t default_pool; /**< The default pool, if applicable */ uint8_t nb_pool_maps; /**< We can have up to 64 filters/mappings */ struct { - uint16_t vlan_id; /**< The vlan id of the received frame */ + uint16_t vlan_id; /**< The vlan ID of the received frame */ uint64_t pools; /**< Bitmask of pools for packet rx */ } pool_map[ETH_VMDQ_MAX_VLAN_FILTERS]; /**< VMDq vlan pool maps. */ uint8_t dcb_tc[ETH_DCB_NUM_USER_PRIORITIES]; @@ -190,7 +190,7 @@ struct rte_eth_vmdq_rx_conf { uint8_t nb_pool_maps; /**< We can have up to 64 filters/mappings */ uint32_t rx_mode; /**< Flags from ETH_VMDQ_ACCEPT_* */ struct { - uint16_t vlan_id; /**< The vlan id of the received frame */ + uint16_t vlan_id; /**< The vlan ID of the received frame */ uint64_t pools; /**< Bitmask of pools for packet rx */ } pool_map[ETH_VMDQ_MAX_VLAN_FILTERS]; /**< VMDq vlan pool maps. */ }; diff --git a/bindgen-tests/tests/quickchecking/src/fuzzers.rs b/bindgen-tests/tests/quickchecking/src/fuzzers.rs index 003e9bf3f1..569ed6e09b 100644 --- a/bindgen-tests/tests/quickchecking/src/fuzzers.rs +++ b/bindgen-tests/tests/quickchecking/src/fuzzers.rs @@ -231,7 +231,7 @@ impl fmt::Display for DeclarationListC { } } -/// A qucickcheck trait for describing how BaseTypeC types can be +/// A quickcheck trait for describing how BaseTypeC types can be /// randomly generated and shrunk. impl Arbitrary for BaseTypeC { fn arbitrary(g: &mut Gen) -> BaseTypeC { diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 4b05c4abc9..3b6f72764b 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -222,7 +222,7 @@ struct CodegenResult<'a> { items: Vec, dynamic_items: DynamicItems, - /// A monotonic counter used to add stable unique id's to stuff that doesn't + /// A monotonic counter used to add stable unique ID's to stuff that doesn't /// need to be referenced by anything. codegen_id: &'a Cell, @@ -694,7 +694,7 @@ impl CodeGenerator for Var { // Account the trailing zero. // // TODO: Here we ignore the type we just made up, probably - // we should refactor how the variable type and ty id work. + // we should refactor how the variable type and ty ID work. let len = bytes.len() + 1; let ty = quote! { [u8; #len] diff --git a/bindgen/ir/analysis/sizedness.rs b/bindgen/ir/analysis/sizedness.rs index b4c953e647..d296fe3244 100644 --- a/bindgen/ir/analysis/sizedness.rs +++ b/bindgen/ir/analysis/sizedness.rs @@ -346,7 +346,7 @@ impl<'ctx> From> for HashMap { } } -/// A convenience trait for querying whether some type or id is sized. +/// A convenience trait for querying whether some type or ID is sized. /// /// This is not for _computing_ whether the thing is sized, it is for looking up /// the results of the `Sizedness` analysis's computations for a specific thing. diff --git a/bindgen/ir/analysis/template_params.rs b/bindgen/ir/analysis/template_params.rs index 4ac5f08809..3e6cd5e100 100644 --- a/bindgen/ir/analysis/template_params.rs +++ b/bindgen/ir/analysis/template_params.rs @@ -329,7 +329,7 @@ impl<'ctx> UsedTemplateParameters<'ctx> { } } - /// The join operation on our lattice: the set union of all of this id's + /// The join operation on our lattice: the set union of all of this ID's /// successors. fn constrain_join(&self, used_by_this_id: &mut ItemSet, item: &Item) { trace!(" other item: join with successors' usage"); @@ -518,7 +518,7 @@ impl<'ctx> MonotoneFramework for UsedTemplateParameters<'ctx> { // exiting this method. extra_assert!(self.used.values().all(|v| v.is_some())); - // Take the set for this id out of the hash map while we mutate it based + // Take the set for this ID out of the hash map while we mutate it based // on other hash map entries. We *must* put it back into the hash map at // the end of this method. This allows us to side-step HashMap's lack of // an analog to slice::split_at_mut. diff --git a/bindgen/ir/comp.rs b/bindgen/ir/comp.rs index fd1d1b8e52..27ee1dae0e 100644 --- a/bindgen/ir/comp.rs +++ b/bindgen/ir/comp.rs @@ -121,7 +121,7 @@ impl Method { self.kind == MethodKind::Static } - /// Get the id for the `Function` signature for this method. + /// Get the ID for the `Function` signature for this method. pub(crate) fn signature(&self) -> FunctionId { self.signature } diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index 057c4d4ac5..c6015ded72 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -54,7 +54,7 @@ macro_rules! item_id_newtype { pub(crate) struct $name(ItemId); impl $name { - /// Create an `ItemResolver` from this id. + /// Create an `ItemResolver` from this ID. #[allow(dead_code)] pub(crate) fn into_resolver(self) -> ItemResolver { let id: ItemId = self.into(); @@ -127,7 +127,7 @@ item_id_newtype! { expected = expect_type_id, /// Convert this `ItemId` into a `TypeId` without actually checking whether - /// this id actually points to a `Type`. + /// this ID actually points to a `Type`. unchecked = as_type_id_unchecked; } @@ -146,7 +146,7 @@ item_id_newtype! { expected = expect_module_id, /// Convert this `ItemId` into a `ModuleId` without actually checking - /// whether this id actually points to a `Module`. + /// whether this ID actually points to a `Module`. unchecked = as_module_id_unchecked; } @@ -165,7 +165,7 @@ item_id_newtype! { expected = expect_var_id, /// Convert this `ItemId` into a `VarId` without actually checking whether - /// this id actually points to a `Var`. + /// this ID actually points to a `Var`. unchecked = as_var_id_unchecked; } @@ -184,7 +184,7 @@ item_id_newtype! { expected = expect_function_id, /// Convert this `ItemId` into a `FunctionId` without actually checking whether - /// this id actually points to a `Function`. + /// this ID actually points to a `Function`. unchecked = as_function_id_unchecked; } @@ -195,7 +195,7 @@ impl From for usize { } impl ItemId { - /// Get a numeric representation of this id. + /// Get a numeric representation of this ID. pub(crate) fn as_usize(&self) -> usize { (*self).into() } @@ -315,7 +315,7 @@ pub(crate) struct BindgenContext { /// item ids during parsing. types: HashMap, - /// Maps from a cursor to the item id of the named template type parameter + /// Maps from a cursor to the item ID of the named template type parameter /// for that cursor. type_params: HashMap, @@ -328,7 +328,7 @@ pub(crate) struct BindgenContext { /// Current module being traversed. current_module: ModuleId, - /// A HashMap keyed on a type definition, and whose value is the parent id + /// A HashMap keyed on a type definition, and whose value is the parent ID /// of the declaration. /// /// This is used to handle the cases where the semantic and the lexical @@ -392,7 +392,7 @@ pub(crate) struct BindgenContext { /// It's computed right after computing the allowlisted items. codegen_items: Option, - /// Map from an item's id to the set of template parameter items that it + /// Map from an item's ID to the set of template parameter items that it /// uses. See `ir::named` for more details. Always `Some` during the codegen /// phase. used_template_parameters: Option>, @@ -1086,7 +1086,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" // Relocate the replacement item from where it was declared, to // where the thing it is replacing was declared. // - // First, we'll make sure that its parent id is correct. + // First, we'll make sure that its parent ID is correct. let old_parent = self.resolve_item(replacement_id).parent_id(); if new_parent == old_parent { @@ -1272,7 +1272,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" self.sizedness = Some(analyze::(self)); } - /// Look up whether the type with the given id is sized or not. + /// Look up whether the type with the given ID is sized or not. pub(crate) fn lookup_sizedness(&self, id: TypeId) -> SizednessResult { assert!( self.in_codegen_phase(), @@ -1437,7 +1437,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" self.root_module } - /// Resolve a type with the given id. + /// Resolve a type with the given ID. /// /// Panics if there is no item for the given `TypeId` or if the resolved /// item is not a `Type`. @@ -1445,7 +1445,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" self.resolve_item(type_id).kind().expect_type() } - /// Resolve a function with the given id. + /// Resolve a function with the given ID. /// /// Panics if there is no item for the given `FunctionId` or if the resolved /// item is not a `Function`. @@ -1454,9 +1454,9 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Resolve the given `ItemId` as a type, or `None` if there is no item with - /// the given id. + /// the given ID. /// - /// Panics if the id resolves to an item that is not a type. + /// Panics if the ID resolves to an item that is not a type. pub(crate) fn safe_resolve_type(&self, type_id: TypeId) -> Option<&Type> { self.resolve_item_fallible(type_id) .map(|t| t.kind().expect_type()) @@ -1473,7 +1473,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// Resolve the given `ItemId` into an `Item`. /// - /// Panics if the given id does not resolve to any item. + /// Panics if the given ID does not resolve to any item. pub(crate) fn resolve_item>(&self, item_id: Id) -> &Item { let item_id = item_id.into(); match self.resolve_item_fallible(item_id) { @@ -1658,7 +1658,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" clang_sys::CXCursor_TypeRef | clang_sys::CXCursor_TypedefDecl | clang_sys::CXCursor_TypeAliasDecl => { - // The `with_id` id will potentially end up unused if we give up + // The `with_id` ID will potentially end up unused if we give up // on this type (for example, because it has const value // template args), so if we pass `with_id` as the parent, it is // potentially a dangling reference. Instead, use the canonical @@ -1953,7 +1953,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" with_id.as_type_id_unchecked() } - /// Returns the next item id to be used for an item. + /// Returns the next item ID to be used for an item. pub(crate) fn next_item_id(&mut self) -> ItemId { let ret = ItemId(self.items.len()); self.items.push(None); @@ -2055,7 +2055,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" self.in_codegen } - /// Mark the type with the given `name` as replaced by the type with id + /// Mark the type with the given `name` as replaced by the type with ID /// `potential_ty`. /// /// Replacement types are declared using the `replaces="xxx"` annotation, @@ -2185,7 +2185,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" (module_name, kind) } - /// Given a CXCursor_Namespace cursor, return the item id of the + /// Given a CXCursor_Namespace cursor, return the item ID of the /// corresponding module, or create one on the fly. pub(crate) fn module(&mut self, cursor: clang::Cursor) -> ModuleId { use clang_sys::*; @@ -2539,7 +2539,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" } } - // Find enums in this module, and record the id of each one that + // Find enums in this module, and record the ID of each one that // has a typedef. for child_id in module.children() { if let Some(ItemKind::Type(ty)) = @@ -2837,7 +2837,7 @@ pub(crate) struct ItemResolver { } impl ItemId { - /// Create an `ItemResolver` from this item id. + /// Create an `ItemResolver` from this item ID. pub(crate) fn into_resolver(self) -> ItemResolver { self.into() } @@ -2853,7 +2853,7 @@ where } impl ItemResolver { - /// Construct a new `ItemResolver` from the given id. + /// Construct a new `ItemResolver` from the given ID. pub(crate) fn new>(id: Id) -> ItemResolver { let id = id.into(); ItemResolver { diff --git a/bindgen/ir/function.rs b/bindgen/ir/function.rs index dbb155dc1c..bde53547b5 100644 --- a/bindgen/ir/function.rs +++ b/bindgen/ir/function.rs @@ -82,7 +82,7 @@ pub(crate) struct Function { /// The mangled name, that is, the symbol. mangled_name: Option, - /// The id pointing to the current function signature. + /// The ID pointing to the current function signature. signature: TypeId, /// The kind of function this is. @@ -225,7 +225,7 @@ impl quote::ToTokens for Abi { /// An ABI extracted from a clang cursor. #[derive(Debug, Copy, Clone)] pub(crate) enum ClangAbi { - /// An ABI known by rust. + /// An ABI known by Rust. Known(Abi), /// An unknown or invalid ABI. Unknown(CXCallingConv), diff --git a/bindgen/ir/int.rs b/bindgen/ir/int.rs index bb3032dbcf..4251b3753a 100644 --- a/bindgen/ir/int.rs +++ b/bindgen/ir/int.rs @@ -12,7 +12,7 @@ pub enum IntKind { /// An `unsigned char`. UChar, - /// An `wchar_t`. + /// A `wchar_t`. WChar, /// A platform-dependent `char` type, with the signedness support. diff --git a/bindgen/ir/item.rs b/bindgen/ir/item.rs index fec014911b..4ab4f0a907 100644 --- a/bindgen/ir/item.rs +++ b/bindgen/ir/item.rs @@ -362,7 +362,7 @@ impl CanDeriveOrd for Item { /// information). /// /// Items refer to each other by `ItemId`. Every item has its parent's -/// id. Depending on the kind of item this is, it may also refer to other items, +/// ID. Depending on the kind of item this is, it may also refer to other items, /// such as a compound type item referring to other types. Collectively, these /// references form a graph. /// @@ -376,19 +376,19 @@ impl CanDeriveOrd for Item { /// `annotations` module. #[derive(Debug)] pub(crate) struct Item { - /// This item's id. + /// This item's ID. id: ItemId, - /// The item's local id, unique only amongst its siblings. Only used for + /// The item's local ID, unique only amongst its siblings. Only used for /// anonymous items. /// /// Lazily initialized in local_id(). /// - /// Note that only structs, unions, and enums get a local type id. In any + /// Note that only structs, unions, and enums get a local type ID. In any /// case this is an implementation detail. local_id: LazyCell, - /// The next local id to use for a child or template instantiation. + /// The next local ID to use for a child or template instantiation. next_child_local_id: Cell, /// A cached copy of the canonical name, as returned by `canonical_name`. @@ -406,11 +406,11 @@ pub(crate) struct Item { /// Annotations extracted from the doc comment, or the default ones /// otherwise. annotations: Annotations, - /// An item's parent id. This will most likely be a class where this item + /// An item's parent ID. This will most likely be a class where this item /// was declared, or a module, etc. /// /// All the items have a parent, except the root module, in which case the - /// parent id is its own id. + /// parent ID is its own ID. parent_id: ItemId, /// The item kind. kind: ItemKind, @@ -479,7 +479,7 @@ impl Item { self.parent_id } - /// Set this item's parent id. + /// Set this item's parent ID. /// /// This is only used so replacements get generated in the proper module. pub(crate) fn set_parent_for_replacement>( @@ -681,7 +681,7 @@ impl Item { NameOptions::new(self, ctx) } - /// Get the target item id for name generation. + /// Get the target item ID for name generation. fn name_target(&self, ctx: &BindgenContext) -> ItemId { let mut targets_seen = DebugOnlyItemSet::new(); let mut item = self; @@ -861,7 +861,7 @@ impl Item { return base_name; } - // Ancestors' id iter + // Ancestors' ID iter let mut ids_iter = target .parent_id() .ancestors(ctx) @@ -938,11 +938,11 @@ impl Item { ctx.rust_mangle(&name).into_owned() } - /// The exposed id that represents an unique id among the siblings of a + /// The exposed ID that represents an unique ID among the siblings of a /// given item. pub(crate) fn exposed_id(&self, ctx: &BindgenContext) -> String { // Only use local ids for enums, classes, structs and union types. All - // other items use their global id. + // other items use their global ID. let ty_kind = self.kind().as_type().map(|t| t.kind()); if let Some(ty_kind) = ty_kind { match *ty_kind { @@ -954,7 +954,7 @@ impl Item { } // Note that this `id_` prefix prevents (really unlikely) collisions - // between the global id and the local id of an item with the same + // between the global ID and the local ID of an item with the same // parent. format!("id_{}", self.id().as_usize()) } @@ -1573,10 +1573,10 @@ impl Item { /// This is one of the trickiest methods you'll find (probably along with /// some of the ones that handle templates in `BindgenContext`). /// - /// This method parses a type, given the potential id of that type (if + /// This method parses a type, given the potential ID of that type (if /// parsing it was correct), an optional location we're scanning, which is - /// critical some times to obtain information, an optional parent item id, - /// that will, if it's `None`, become the current module id, and the + /// critical some times to obtain information, an optional parent item ID, + /// that will, if it's `None`, become the current module ID, and the /// context. pub(crate) fn from_ty_with_id( id: ItemId, diff --git a/bindgen/ir/template.rs b/bindgen/ir/template.rs index 0a2c269eed..d0be17ecc6 100644 --- a/bindgen/ir/template.rs +++ b/bindgen/ir/template.rs @@ -167,7 +167,7 @@ pub(crate) trait AsTemplateParam { /// Any extra information the implementor might need to make this decision. type Extra; - /// Convert this thing to the item id of a named template type parameter. + /// Convert this thing to the item ID of a named template type parameter. fn as_template_param( &self, ctx: &BindgenContext, diff --git a/bindgen/ir/ty.rs b/bindgen/ir/ty.rs index ca66e1106b..8c505aa49f 100644 --- a/bindgen/ir/ty.rs +++ b/bindgen/ir/ty.rs @@ -711,7 +711,7 @@ impl Type { // Objective C template type parameter // FIXME: This is probably wrong, we are attempting to find the // objc template params, which seem to manifest as a typedef. - // We are rewriting them as id to suppress multiple conflicting + // We are rewriting them as ID to suppress multiple conflicting // typedefs at root level if ty_kind == CXType_Typedef { let is_template_type_param = From 33c9fe47da138d4009643119434d2303946a02ae Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Wed, 15 Mar 2023 16:56:59 -0500 Subject: [PATCH 464/942] Remove the wrapping mod hack (#2441) --- .../postprocessing/merge_extern_blocks.rs | 96 ++++++++++--------- bindgen/codegen/postprocessing/mod.rs | 27 ++---- .../postprocessing/sort_semantically.rs | 57 ++++++----- 3 files changed, 92 insertions(+), 88 deletions(-) diff --git a/bindgen/codegen/postprocessing/merge_extern_blocks.rs b/bindgen/codegen/postprocessing/merge_extern_blocks.rs index 05e7e9ef39..f9c8d30793 100644 --- a/bindgen/codegen/postprocessing/merge_extern_blocks.rs +++ b/bindgen/codegen/postprocessing/merge_extern_blocks.rs @@ -1,66 +1,70 @@ use syn::{ - visit_mut::{visit_item_mod_mut, VisitMut}, - Item, ItemForeignMod, ItemMod, + visit_mut::{visit_file_mut, visit_item_mod_mut, VisitMut}, + File, Item, ItemForeignMod, ItemMod, }; -pub(super) fn merge_extern_blocks(item_mod: &mut ItemMod) { - Visitor.visit_item_mod_mut(item_mod) +pub(super) fn merge_extern_blocks(file: &mut File) { + Visitor.visit_file_mut(file) } struct Visitor; impl VisitMut for Visitor { + fn visit_file_mut(&mut self, file: &mut File) { + visit_items(&mut file.items); + visit_file_mut(self, file) + } + fn visit_item_mod_mut(&mut self, item_mod: &mut ItemMod) { if let Some((_, ref mut items)) = item_mod.content { - // Keep all the extern blocks in a different `Vec` for faster search. - let mut extern_blocks = Vec::::new(); + visit_items(items); + } + visit_item_mod_mut(self, item_mod) + } +} + +fn visit_items(items: &mut Vec) { + // Keep all the extern blocks in a different `Vec` for faster search. + let mut extern_blocks = Vec::::new(); - for item in std::mem::take(items) { - if let Item::ForeignMod(ItemForeignMod { + for item in std::mem::take(items) { + if let Item::ForeignMod(ItemForeignMod { + attrs, + abi, + brace_token, + items: extern_block_items, + }) = item + { + let mut exists = false; + for extern_block in &mut extern_blocks { + // Check if there is a extern block with the same ABI and + // attributes. + if extern_block.attrs == attrs && extern_block.abi == abi { + // Merge the items of the two blocks. + extern_block.items.extend_from_slice(&extern_block_items); + exists = true; + break; + } + } + // If no existing extern block had the same ABI and attributes, store + // it. + if !exists { + extern_blocks.push(ItemForeignMod { attrs, abi, brace_token, items: extern_block_items, - }) = item - { - let mut exists = false; - for extern_block in &mut extern_blocks { - // Check if there is a extern block with the same ABI and - // attributes. - if extern_block.attrs == attrs && - extern_block.abi == abi - { - // Merge the items of the two blocks. - extern_block - .items - .extend_from_slice(&extern_block_items); - exists = true; - break; - } - } - // If no existing extern block had the same ABI and attributes, store - // it. - if !exists { - extern_blocks.push(ItemForeignMod { - attrs, - abi, - brace_token, - items: extern_block_items, - }); - } - } else { - // If the item is not an extern block, we don't have to do anything and just - // push it back. - items.push(item); - } - } - - // Move all the extern blocks alongside the rest of the items. - for extern_block in extern_blocks { - items.push(Item::ForeignMod(extern_block)); + }); } + } else { + // If the item is not an extern block, we don't have to do anything and just + // push it back. + items.push(item); } + } - visit_item_mod_mut(self, item_mod) + // Move all the extern blocks alongside the rest of the items. + for extern_block in extern_blocks { + items.push(Item::ForeignMod(extern_block)); } } diff --git a/bindgen/codegen/postprocessing/mod.rs b/bindgen/codegen/postprocessing/mod.rs index 1d5a4983bd..9641698521 100644 --- a/bindgen/codegen/postprocessing/mod.rs +++ b/bindgen/codegen/postprocessing/mod.rs @@ -1,6 +1,6 @@ use proc_macro2::TokenStream; use quote::ToTokens; -use syn::{parse2, ItemMod}; +use syn::{parse2, File}; use crate::BindgenOptions; @@ -12,7 +12,7 @@ use sort_semantically::sort_semantically; struct PostProcessingPass { should_run: fn(&BindgenOptions) -> bool, - run: fn(&mut ItemMod), + run: fn(&mut File), } // TODO: This can be a const fn when mutable references are allowed in const @@ -21,7 +21,7 @@ macro_rules! pass { ($pass:ident) => { PostProcessingPass { should_run: |options| options.$pass, - run: |item_mod| $pass(item_mod), + run: |file| $pass(file), } }; } @@ -33,34 +33,25 @@ pub(crate) fn postprocessing( items: Vec, options: &BindgenOptions, ) -> TokenStream { + let items = items.into_iter().collect(); let require_syn = PASSES.iter().any(|pass| (pass.should_run)(options)); + if !require_syn { - return items.into_iter().collect(); + return items; } - let module_wrapped_tokens = - quote!(mod wrapper_for_postprocessing_hack { #( #items )* }); // This syn business is a hack, for now. This means that we are re-parsing already // generated code using `syn` (as opposed to `quote`) because `syn` provides us more // control over the elements. - // One caveat is that some of the items coming from `quote`d output might have - // multiple items within them. Hence, we have to wrap the incoming in a `mod`. // The `unwrap` here is deliberate because bindgen should generate valid rust items at all // times. - let mut item_mod = parse2::(module_wrapped_tokens).unwrap(); + let mut file = parse2::(items).unwrap(); for pass in PASSES { if (pass.should_run)(options) { - (pass.run)(&mut item_mod); + (pass.run)(&mut file); } } - let synful_items = item_mod - .content - .map(|(_, items)| items) - .unwrap_or_default() - .into_iter() - .map(|item| item.into_token_stream()); - - quote! { #( #synful_items )* } + file.into_token_stream() } diff --git a/bindgen/codegen/postprocessing/sort_semantically.rs b/bindgen/codegen/postprocessing/sort_semantically.rs index 4f23ab73a3..0fd4212c9d 100644 --- a/bindgen/codegen/postprocessing/sort_semantically.rs +++ b/bindgen/codegen/postprocessing/sort_semantically.rs @@ -1,38 +1,47 @@ use syn::{ - visit_mut::{visit_item_mod_mut, VisitMut}, - Item, ItemMod, + visit_mut::{visit_file_mut, visit_item_mod_mut, VisitMut}, + File, Item, ItemMod, }; -pub(super) fn sort_semantically(item_mod: &mut ItemMod) { - Visitor.visit_item_mod_mut(item_mod) +pub(super) fn sort_semantically(file: &mut File) { + Visitor.visit_file_mut(file) } struct Visitor; impl VisitMut for Visitor { + fn visit_file_mut(&mut self, file: &mut File) { + visit_items(&mut file.items); + visit_file_mut(self, file) + } + fn visit_item_mod_mut(&mut self, item_mod: &mut ItemMod) { if let Some((_, ref mut items)) = item_mod.content { - items.sort_by_key(|item| match item { - Item::Type(_) => 0, - Item::Struct(_) => 1, - Item::Const(_) => 2, - Item::Fn(_) => 3, - Item::Enum(_) => 4, - Item::Union(_) => 5, - Item::Static(_) => 6, - Item::Trait(_) => 7, - Item::TraitAlias(_) => 8, - Item::Impl(_) => 9, - Item::Mod(_) => 10, - Item::Use(_) => 11, - Item::Verbatim(_) => 12, - Item::ExternCrate(_) => 13, - Item::ForeignMod(_) => 14, - Item::Macro(_) => 15, - Item::Macro2(_) => 16, - _ => 18, - }); + visit_items(items); } visit_item_mod_mut(self, item_mod) } } + +fn visit_items(items: &mut [Item]) { + items.sort_by_key(|item| match item { + Item::Type(_) => 0, + Item::Struct(_) => 1, + Item::Const(_) => 2, + Item::Fn(_) => 3, + Item::Enum(_) => 4, + Item::Union(_) => 5, + Item::Static(_) => 6, + Item::Trait(_) => 7, + Item::TraitAlias(_) => 8, + Item::Impl(_) => 9, + Item::Mod(_) => 10, + Item::Use(_) => 11, + Item::Verbatim(_) => 12, + Item::ExternCrate(_) => 13, + Item::ForeignMod(_) => 14, + Item::Macro(_) => 15, + Item::Macro2(_) => 16, + _ => 18, + }); +} From 9f90b3264ea7976e561eea5af468ae85a6722c0e Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Wed, 15 Mar 2023 17:10:09 -0500 Subject: [PATCH 465/942] Avoid emitting old-style C declarations (#2443) * Avoid emiting old-style C declarations * Update Changelog --- CHANGELOG.md | 3 +- .../tests/generated/wrap_static_fns.c | 4 +- bindgen/codegen/serialize.rs | 46 ++++++++++--------- 3 files changed, 28 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 037755ca76..43cff3d9d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -164,7 +164,8 @@ ## Added ## Changed - + * Static functions with no arguments use `void` as their single argument + instead of having no arguments when the `--wrap-static-fns` flag is used. ## Removed * The following deprecated flags were removed: `--use-msvc-mangling`, `--rustfmt-bindings` and `--size_t-is-usize`. diff --git a/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c b/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c index f5f33f8444..60c1685eaa 100644 --- a/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c +++ b/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c @@ -1,7 +1,7 @@ int foo__extern(void) asm("foo__extern"); -int foo__extern() { return foo(); } +int foo__extern(void) { return foo(); } int bar__extern(void) asm("bar__extern"); -int bar__extern() { return bar(); } +int bar__extern(void) { return bar(); } int takes_ptr__extern(int *arg) asm("takes_ptr__extern"); int takes_ptr__extern(int *arg) { return takes_ptr(arg); } int takes_fn_ptr__extern(int (*f) (int)) asm("takes_fn_ptr__extern"); diff --git a/bindgen/codegen/serialize.rs b/bindgen/codegen/serialize.rs index 1310648463..dedf25685f 100644 --- a/bindgen/codegen/serialize.rs +++ b/bindgen/codegen/serialize.rs @@ -108,33 +108,13 @@ impl<'a> CSerialize<'a> for Function { // Write `ret_ty wrap_name(args) asm("wrap_name");` ret_ty.serialize(ctx, (), stack, writer)?; write!(writer, " {}(", wrap_name)?; - if args.is_empty() { - write!(writer, "void")?; - } else { - serialize_sep( - ", ", - args.iter(), - ctx, - writer, - |(name, type_id), ctx, buf| { - type_id.serialize(ctx, (), &mut vec![name.clone()], buf) - }, - )?; - } + serialize_args(&args, ctx, writer)?; writeln!(writer, ") asm(\"{}\");", wrap_name)?; // Write `ret_ty wrap_name(args) { return name(arg_names)' }` ret_ty.serialize(ctx, (), stack, writer)?; write!(writer, " {}(", wrap_name)?; - serialize_sep( - ", ", - args.iter(), - ctx, - writer, - |(name, type_id), _, buf| { - type_id.serialize(ctx, (), &mut vec![name.clone()], buf) - }, - )?; + serialize_args(&args, ctx, writer)?; write!(writer, ") {{ return {}(", name)?; serialize_sep(", ", args.iter(), ctx, writer, |(name, _), _, buf| { write!(buf, "{}", name).map_err(From::from) @@ -338,6 +318,28 @@ impl<'a> CSerialize<'a> for Type { } } +fn serialize_args( + args: &[(String, TypeId)], + ctx: &BindgenContext, + writer: &mut W, +) -> Result<(), CodegenError> { + if args.is_empty() { + write!(writer, "void")?; + } else { + serialize_sep( + ", ", + args.iter(), + ctx, + writer, + |(name, type_id), ctx, buf| { + type_id.serialize(ctx, (), &mut vec![name.clone()], buf) + }, + )?; + } + + Ok(()) +} + fn serialize_sep< W: Write, F: FnMut(I::Item, &BindgenContext, &mut W) -> Result<(), CodegenError>, From b3239c5b529b45de98859b31b4d0f4bf2350d445 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Fri, 17 Mar 2023 00:11:27 -0500 Subject: [PATCH 466/942] Add `#include` directives with headers for static wrappers (#2447) --- CHANGELOG.md | 3 +++ bindgen-integration/build.rs | 2 -- .../tests/generated/wrap_static_fns.c | 4 ++++ bindgen/codegen/mod.rs | 19 +++++++++++++++++++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 43cff3d9d4..25e9a16995 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -166,6 +166,9 @@ ## Changed * Static functions with no arguments use `void` as their single argument instead of having no arguments when the `--wrap-static-fns` flag is used. + * The source file generated when the `--wrap-static-fns` flag is enabled now + contains `#include` directives with all the input headers and all the source + code added with the `header_contents` method. ## Removed * The following deprecated flags were removed: `--use-msvc-mangling`, `--rustfmt-bindings` and `--size_t-is-usize`. diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs index 3cc0edb99b..2620ce24f5 100644 --- a/bindgen-integration/build.rs +++ b/bindgen-integration/build.rs @@ -242,8 +242,6 @@ fn setup_wrap_static_fns_test() { .arg("-o") .arg(&obj_path) .arg(out_path.join("wrap_static_fns.c")) - .arg("-include") - .arg(input_header_file_path) .output() .expect("`clang` command error"); if !clang_output.status.success() { diff --git a/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c b/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c index 60c1685eaa..1057475fba 100644 --- a/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c +++ b/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c @@ -1,3 +1,7 @@ +#include "tests/headers/wrap-static-fns.h" + +// Static wrappers + int foo__extern(void) asm("foo__extern"); int foo__extern(void) { return foo(); } int bar__extern(void) asm("bar__extern"); diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 3b6f72764b..352f6db038 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -4545,6 +4545,7 @@ pub(crate) mod utils { use crate::ir::ty::TypeKind; use crate::{args_are_cpp, file_is_cpp}; use std::borrow::Cow; + use std::io::Write; use std::mem; use std::path::PathBuf; use std::str::FromStr; @@ -4583,6 +4584,24 @@ pub(crate) mod utils { let mut code = Vec::new(); + if !context.options().input_headers.is_empty() { + for header in &context.options().input_headers { + writeln!(code, "#include \"{}\"", header)?; + } + + writeln!(code)?; + } + + if !context.options().input_header_contents.is_empty() { + for (name, contents) in &context.options().input_header_contents { + writeln!(code, "// {}\n{}", name, contents)?; + } + + writeln!(code)?; + } + + writeln!(code, "// Static wrappers\n")?; + for &id in &result.items_to_serialize { let item = context.resolve_item(id); item.serialize(context, (), &mut vec![], &mut code)?; From a1010634a11048a992edd95d88464e8b76c42ccc Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Fri, 17 Mar 2023 00:24:06 -0500 Subject: [PATCH 467/942] Let LLVM mangle the link name of static wrappers (#2448) --- CHANGELOG.md | 3 +++ .../tests/generated/wrap_static_fns.c | 8 -------- .../tests/expectations/tests/wrap-static-fns.rs | 16 ++++++++-------- bindgen/codegen/helpers.rs | 11 ++++++++--- bindgen/codegen/mod.rs | 6 +++--- bindgen/codegen/serialize.rs | 6 ------ 6 files changed, 22 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 25e9a16995..0a6c86b3f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -169,6 +169,9 @@ * The source file generated when the `--wrap-static-fns` flag is enabled now contains `#include` directives with all the input headers and all the source code added with the `header_contents` method. + * The source file generated when the `--wrap-static-fns` flag no longer uses + `asm` labeling and the link name of static wrapper functions is allowed to + be mangled. ## Removed * The following deprecated flags were removed: `--use-msvc-mangling`, `--rustfmt-bindings` and `--size_t-is-usize`. diff --git a/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c b/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c index 1057475fba..abc5224229 100644 --- a/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c +++ b/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c @@ -2,19 +2,11 @@ // Static wrappers -int foo__extern(void) asm("foo__extern"); int foo__extern(void) { return foo(); } -int bar__extern(void) asm("bar__extern"); int bar__extern(void) { return bar(); } -int takes_ptr__extern(int *arg) asm("takes_ptr__extern"); int takes_ptr__extern(int *arg) { return takes_ptr(arg); } -int takes_fn_ptr__extern(int (*f) (int)) asm("takes_fn_ptr__extern"); int takes_fn_ptr__extern(int (*f) (int)) { return takes_fn_ptr(f); } -int takes_fn__extern(int (f) (int)) asm("takes_fn__extern"); int takes_fn__extern(int (f) (int)) { return takes_fn(f); } -int takes_alias__extern(func f) asm("takes_alias__extern"); int takes_alias__extern(func f) { return takes_alias(f); } -int takes_qualified__extern(const int *const *arg) asm("takes_qualified__extern"); int takes_qualified__extern(const int *const *arg) { return takes_qualified(arg); } -enum foo takes_enum__extern(const enum foo f) asm("takes_enum__extern"); enum foo takes_enum__extern(const enum foo f) { return takes_enum(f); } diff --git a/bindgen-tests/tests/expectations/tests/wrap-static-fns.rs b/bindgen-tests/tests/expectations/tests/wrap-static-fns.rs index fbfdcb13e0..0db78054ac 100644 --- a/bindgen-tests/tests/expectations/tests/wrap-static-fns.rs +++ b/bindgen-tests/tests/expectations/tests/wrap-static-fns.rs @@ -6,19 +6,19 @@ )] extern "C" { - #[link_name = "\u{1}foo__extern"] + #[link_name = "foo__extern"] pub fn foo() -> ::std::os::raw::c_int; } extern "C" { - #[link_name = "\u{1}bar__extern"] + #[link_name = "bar__extern"] pub fn bar() -> ::std::os::raw::c_int; } extern "C" { - #[link_name = "\u{1}takes_ptr__extern"] + #[link_name = "takes_ptr__extern"] pub fn takes_ptr(arg: *mut ::std::os::raw::c_int) -> ::std::os::raw::c_int; } extern "C" { - #[link_name = "\u{1}takes_fn_ptr__extern"] + #[link_name = "takes_fn_ptr__extern"] pub fn takes_fn_ptr( f: ::std::option::Option< unsafe extern "C" fn( @@ -28,7 +28,7 @@ extern "C" { ) -> ::std::os::raw::c_int; } extern "C" { - #[link_name = "\u{1}takes_fn__extern"] + #[link_name = "takes_fn__extern"] pub fn takes_fn( f: ::std::option::Option< unsafe extern "C" fn( @@ -41,11 +41,11 @@ pub type func = ::std::option::Option< unsafe extern "C" fn(arg1: ::std::os::raw::c_int) -> ::std::os::raw::c_int, >; extern "C" { - #[link_name = "\u{1}takes_alias__extern"] + #[link_name = "takes_alias__extern"] pub fn takes_alias(f: func) -> ::std::os::raw::c_int; } extern "C" { - #[link_name = "\u{1}takes_qualified__extern"] + #[link_name = "takes_qualified__extern"] pub fn takes_qualified( arg: *const *const ::std::os::raw::c_int, ) -> ::std::os::raw::c_int; @@ -53,6 +53,6 @@ extern "C" { pub const foo_BAR: foo = 0; pub type foo = ::std::os::raw::c_uint; extern "C" { - #[link_name = "\u{1}takes_enum__extern"] + #[link_name = "takes_enum__extern"] pub fn takes_enum(f: foo) -> foo; } diff --git a/bindgen/codegen/helpers.rs b/bindgen/codegen/helpers.rs index 9c907ae23e..726fe75eb0 100644 --- a/bindgen/codegen/helpers.rs +++ b/bindgen/codegen/helpers.rs @@ -7,7 +7,7 @@ use quote::TokenStreamExt; pub(crate) mod attributes { use proc_macro2::{Ident, Span, TokenStream}; - use std::str::FromStr; + use std::{borrow::Cow, str::FromStr}; pub(crate) fn repr(which: &str) -> TokenStream { let which = Ident::new(which, Span::call_site()); @@ -62,10 +62,15 @@ pub(crate) mod attributes { } } - pub(crate) fn link_name(name: &str) -> TokenStream { + pub(crate) fn link_name(name: &str) -> TokenStream { // LLVM mangles the name by default but it's already mangled. // Prefixing the name with \u{1} should tell LLVM to not mangle it. - let name = format!("\u{1}{}", name); + let name: Cow<'_, str> = if MANGLE { + name.into() + } else { + format!("\u{1}{}", name).into() + }; + quote! { #[link_name = #name] } diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 352f6db038..f4a64b355c 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -751,7 +751,7 @@ impl CodeGenerator for Var { link_name, None, ) { - attrs.push(attributes::link_name(link_name)); + attrs.push(attributes::link_name::(link_name)); } let maybe_mut = if self.is_const() { @@ -4155,7 +4155,7 @@ impl CodeGenerator for Function { Some(abi), ) { - attributes.push(attributes::link_name(link_name)); + attributes.push(attributes::link_name::(link_name)); has_link_name_attr = true; } @@ -4169,7 +4169,7 @@ impl CodeGenerator for Function { if is_internal && ctx.options().wrap_static_fns && !has_link_name_attr { let name = canonical_name.clone() + ctx.wrap_static_fns_suffix(); - attributes.push(attributes::link_name(&name)); + attributes.push(attributes::link_name::(&name)); } let ident = ctx.rust_ident(canonical_name); diff --git a/bindgen/codegen/serialize.rs b/bindgen/codegen/serialize.rs index dedf25685f..ac6202356e 100644 --- a/bindgen/codegen/serialize.rs +++ b/bindgen/codegen/serialize.rs @@ -105,12 +105,6 @@ impl<'a> CSerialize<'a> for Function { // The function's return type let ret_ty = signature.return_type(); - // Write `ret_ty wrap_name(args) asm("wrap_name");` - ret_ty.serialize(ctx, (), stack, writer)?; - write!(writer, " {}(", wrap_name)?; - serialize_args(&args, ctx, writer)?; - writeln!(writer, ") asm(\"{}\");", wrap_name)?; - // Write `ret_ty wrap_name(args) { return name(arg_names)' }` ret_ty.serialize(ctx, (), stack, writer)?; write!(writer, " {}(", wrap_name)?; From 9b6d3d9ebb10d5cda76c3a3a7d1af77fb0077aef Mon Sep 17 00:00:00 2001 From: Amanjeev Sethi Date: Sat, 18 Mar 2023 23:31:17 -0400 Subject: [PATCH 468/942] doc/contributing: rustfmt +nightly, prerequisites section (#2449) * add(doc/contributing): rustfmt +nightly, prerequisites section * update(doc/contributing): doctoc update --- CONTRIBUTING.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 127e5c5ef0..4c3398d15a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -11,6 +11,8 @@ and introduce yourself. - [Code of Conduct](#code-of-conduct) - [Filing an Issue](#filing-an-issue) - [Looking to Start Contributing to `bindgen`?](#looking-to-start-contributing-to-bindgen) +- [Prerequisites](#prerequisites) + - [`rustfmt` / `cargo fmt`](#rustfmt--cargo-fmt) - [Building](#building) - [Testing](#testing) - [Overview](#overview) @@ -63,6 +65,16 @@ issue, provide us with: * [Issues labeled "help wanted"](https://github.com/rust-lang/rust-bindgen/labels/help%20wanted) * Still can't find something to work on? [Drop a comment here](https://github.com/rust-lang/rust-bindgen/issues/747) +## Prerequisites + +### `rustfmt` / `cargo fmt` + +We use `nightly` channel for `rustfmt` so please set the appropriate setting your editor/IDE for that. + +For rust-analyzer, you can set `rustfmt.extraArgs = ['+nightly']`. + +To check via command line, you can run `cargo +nightly fmt --check`. + ## Building To build the `bindgen` library and the `bindgen` executable: From 81e3df4f48f48e00975cd4d36632fc4d01c25232 Mon Sep 17 00:00:00 2001 From: "thb@sb" <108470890+thb-sb@users.noreply.github.com> Date: Sun, 19 Mar 2023 04:32:51 +0100 Subject: [PATCH 469/942] Add `generated_link_name_override` method for `ParseCallbacks`. (#2425) * Add `generated_link_name_override` method for `ParseCallbacks`. `generated_link_name_override` lets the developer choose the link name for a symbol. If a link name is specified, the attribute `#[link_name = "\u{1}VALUE"]` will be set, overriding any other potential link name, including the mangled name. This commit also adds an option to the bindgen cli called `prefix-link-name`, to prefix the link name of exported symbols. I think this should properly solve https://github.com/rust-lang/rust-bindgen/issues/1375. * Fix expectation file for `prefix-link-name-c`. * Fix expectation file for `prefix-link-name-cpp` * Add a new `parse_callbacks` callback to solve the roundtrip test. --- bindgen-cli/options.rs | 26 +++++++++++++ .../expectations/tests/prefix-link-name-c.rs | 11 ++++++ .../tests/prefix-link-name-cpp.rs | 11 ++++++ .../tests/headers/prefix-link-name-c.h | 4 ++ .../tests/headers/prefix-link-name-cpp.hpp | 8 ++++ bindgen-tests/tests/parse_callbacks/mod.rs | 29 ++++++++++++++ bindgen/callbacks.rs | 9 +++++ bindgen/codegen/mod.rs | 38 ++++++++++++------- bindgen/ir/function.rs | 27 ++++++++++++- bindgen/ir/var.rs | 21 +++++++++- 10 files changed, 166 insertions(+), 18 deletions(-) create mode 100644 bindgen-tests/tests/expectations/tests/prefix-link-name-c.rs create mode 100644 bindgen-tests/tests/expectations/tests/prefix-link-name-cpp.rs create mode 100644 bindgen-tests/tests/headers/prefix-link-name-c.h create mode 100644 bindgen-tests/tests/headers/prefix-link-name-cpp.hpp diff --git a/bindgen-cli/options.rs b/bindgen-cli/options.rs index 966e6aeced..3f22e7eee4 100644 --- a/bindgen-cli/options.rs +++ b/bindgen-cli/options.rs @@ -305,6 +305,9 @@ struct BindgenCommand { /// Require successful linkage to all functions in the library. #[arg(long)] dynamic_link_require_all: bool, + /// Prefix the name of exported symbols. + #[arg(long)] + prefix_link_name: Option, /// Makes generated bindings `pub` only for items if the items are publically accessible in C++. #[arg(long)] respect_cxx_access_specs: bool, @@ -462,6 +465,7 @@ where wasm_import_module_name, dynamic_loading, dynamic_link_require_all, + prefix_link_name, respect_cxx_access_specs, translate_enum_integer_types, c_naming, @@ -868,6 +872,28 @@ where builder = builder.dynamic_link_require_all(true); } + if let Some(prefix_link_name) = prefix_link_name { + #[derive(Debug)] + struct PrefixLinkNameCallback { + prefix: String, + } + + impl bindgen::callbacks::ParseCallbacks for PrefixLinkNameCallback { + fn generated_link_name_override( + &self, + item_info: bindgen::callbacks::ItemInfo<'_>, + ) -> Option { + let mut prefix = self.prefix.clone(); + prefix.push_str(item_info.name); + Some(prefix) + } + } + + builder = builder.parse_callbacks(Box::new(PrefixLinkNameCallback { + prefix: prefix_link_name, + })) + } + if respect_cxx_access_specs { builder = builder.respect_cxx_access_specs(true); } diff --git a/bindgen-tests/tests/expectations/tests/prefix-link-name-c.rs b/bindgen-tests/tests/expectations/tests/prefix-link-name-c.rs new file mode 100644 index 0000000000..c363a7874b --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/prefix-link-name-c.rs @@ -0,0 +1,11 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +extern "C" { + #[link_name = "\u{1}foo_bar"] + pub fn bar() -> ::std::os::raw::c_int; +} diff --git a/bindgen-tests/tests/expectations/tests/prefix-link-name-cpp.rs b/bindgen-tests/tests/expectations/tests/prefix-link-name-cpp.rs new file mode 100644 index 0000000000..535fccbdb7 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/prefix-link-name-cpp.rs @@ -0,0 +1,11 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +extern "C" { + #[link_name = "\u{1}foo_foo"] + pub fn baz_foo() -> ::std::os::raw::c_int; +} diff --git a/bindgen-tests/tests/headers/prefix-link-name-c.h b/bindgen-tests/tests/headers/prefix-link-name-c.h new file mode 100644 index 0000000000..2432798fce --- /dev/null +++ b/bindgen-tests/tests/headers/prefix-link-name-c.h @@ -0,0 +1,4 @@ +// bindgen-parse-callbacks: prefix-link-name-foo_ +// bindgen-flags: --prefix-link-name foo_ + +int bar(void); diff --git a/bindgen-tests/tests/headers/prefix-link-name-cpp.hpp b/bindgen-tests/tests/headers/prefix-link-name-cpp.hpp new file mode 100644 index 0000000000..4fd2612327 --- /dev/null +++ b/bindgen-tests/tests/headers/prefix-link-name-cpp.hpp @@ -0,0 +1,8 @@ +// bindgen-parse-callbacks: prefix-link-name-foo_ +// bindgen-flags: --prefix-link-name foo_ + +namespace baz { + +int foo(); + +} // end namespace baz diff --git a/bindgen-tests/tests/parse_callbacks/mod.rs b/bindgen-tests/tests/parse_callbacks/mod.rs index 00967fe8d7..85082b63f7 100644 --- a/bindgen-tests/tests/parse_callbacks/mod.rs +++ b/bindgen-tests/tests/parse_callbacks/mod.rs @@ -31,6 +31,30 @@ impl ParseCallbacks for RemovePrefixParseCallback { } } +#[derive(Debug)] +pub struct PrefixLinkNameParseCallback { + pub prefix: Option, +} + +impl PrefixLinkNameParseCallback { + pub fn new(prefix: &str) -> Self { + PrefixLinkNameParseCallback { + prefix: Some(prefix.to_string()), + } + } +} + +impl ParseCallbacks for PrefixLinkNameParseCallback { + fn generated_link_name_override( + &self, + item_info: ItemInfo, + ) -> Option { + self.prefix + .as_deref() + .map(|prefix| format!("{}{}", prefix, item_info.name)) + } +} + #[derive(Debug)] struct EnumVariantRename; @@ -76,6 +100,11 @@ pub fn lookup(cb: &str) -> Box { .to_owned(); let lnopc = RemovePrefixParseCallback::new(prefix.unwrap()); Box::new(lnopc) + } else if call_back.starts_with("prefix-link-name-") { + let prefix = + call_back.split("prefix-link-name-").last().to_owned(); + let plnpc = PrefixLinkNameParseCallback::new(prefix.unwrap()); + Box::new(plnpc) } else { panic!("Couldn't find name ParseCallbacks: {}", cb) } diff --git a/bindgen/callbacks.rs b/bindgen/callbacks.rs index b1339e4663..92ed6f4e44 100644 --- a/bindgen/callbacks.rs +++ b/bindgen/callbacks.rs @@ -45,6 +45,15 @@ pub trait ParseCallbacks: fmt::Debug { None } + /// This function will run for every extern variable and function. The returned value determines + /// the link name in the bindings. + fn generated_link_name_override( + &self, + _item_info: ItemInfo<'_>, + ) -> Option { + None + } + /// The integer kind an integer macro should have, given a name and the /// value of that macro, or `None` if you want the default to be chosen. fn int_macro(&self, _name: &str, _value: i64) -> Option { diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index f4a64b355c..35531e290f 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -745,13 +745,18 @@ impl CodeGenerator for Var { } } else { // If necessary, apply a `#[link_name]` attribute - let link_name = self.mangled_name().unwrap_or_else(|| self.name()); - if !utils::names_will_be_identical_after_mangling( - &canonical_name, - link_name, - None, - ) { + if let Some(link_name) = self.link_name() { attrs.push(attributes::link_name::(link_name)); + } else { + let link_name = + self.mangled_name().unwrap_or_else(|| self.name()); + if !utils::names_will_be_identical_after_mangling( + &canonical_name, + link_name, + None, + ) { + attrs.push(attributes::link_name::(link_name)); + } } let maybe_mut = if self.is_const() { @@ -4147,16 +4152,21 @@ impl CodeGenerator for Function { } let mut has_link_name_attr = false; - let link_name = mangled_name.unwrap_or(name); - if !is_dynamic_function && - !utils::names_will_be_identical_after_mangling( - &canonical_name, - link_name, - Some(abi), - ) - { + if let Some(link_name) = self.link_name() { attributes.push(attributes::link_name::(link_name)); has_link_name_attr = true; + } else { + let link_name = mangled_name.unwrap_or(name); + if !is_dynamic_function && + !utils::names_will_be_identical_after_mangling( + &canonical_name, + link_name, + Some(abi), + ) + { + attributes.push(attributes::link_name::(link_name)); + has_link_name_attr = true; + } } // Unfortunately this can't piggyback on the `attributes` list because diff --git a/bindgen/ir/function.rs b/bindgen/ir/function.rs index bde53547b5..bb2303fad6 100644 --- a/bindgen/ir/function.rs +++ b/bindgen/ir/function.rs @@ -82,6 +82,9 @@ pub(crate) struct Function { /// The mangled name, that is, the symbol. mangled_name: Option, + /// The link name. If specified, overwrite mangled_name. + link_name: Option, + /// The ID pointing to the current function signature. signature: TypeId, @@ -97,6 +100,7 @@ impl Function { pub(crate) fn new( name: String, mangled_name: Option, + link_name: Option, signature: TypeId, kind: FunctionKind, linkage: Linkage, @@ -104,6 +108,7 @@ impl Function { Function { name, mangled_name, + link_name, signature, kind, linkage, @@ -120,6 +125,11 @@ impl Function { self.mangled_name.as_deref() } + /// Get this function's link name. + pub fn link_name(&self) -> Option<&str> { + self.link_name.as_deref() + } + /// Get this function's signature type. pub(crate) fn signature(&self) -> TypeId { self.signature @@ -726,8 +736,21 @@ impl ClangSubItemParser for Function { let mangled_name = cursor_mangling(context, &cursor); - let function = - Self::new(name.clone(), mangled_name, sig, kind, linkage); + let link_name = context.options().last_callback(|callbacks| { + callbacks.generated_link_name_override(ItemInfo { + name: name.as_str(), + kind: ItemKind::Function, + }) + }); + + let function = Self::new( + name.clone(), + mangled_name, + link_name, + sig, + kind, + linkage, + ); Ok(ParseResult::New(function, Some(cursor))) } diff --git a/bindgen/ir/var.rs b/bindgen/ir/var.rs index 620b25cb53..db20124cfb 100644 --- a/bindgen/ir/var.rs +++ b/bindgen/ir/var.rs @@ -37,6 +37,8 @@ pub(crate) struct Var { name: String, /// The mangled name of the variable. mangled_name: Option, + /// The link name of the variable. + link_name: Option, /// The type of the variable. ty: TypeId, /// The value of the variable, that needs to be suitable for `ty`. @@ -50,6 +52,7 @@ impl Var { pub(crate) fn new( name: String, mangled_name: Option, + link_name: Option, ty: TypeId, val: Option, is_const: bool, @@ -58,6 +61,7 @@ impl Var { Var { name, mangled_name, + link_name, ty, val, is_const, @@ -88,6 +92,11 @@ impl Var { pub(crate) fn mangled_name(&self) -> Option<&str> { self.mangled_name.as_deref() } + + /// Get this variable's link name. + pub fn link_name(&self) -> Option<&str> { + self.link_name.as_deref() + } } impl DotAttributes for Var { @@ -267,7 +276,7 @@ impl ClangSubItemParser for Var { let ty = Item::builtin_type(type_kind, true, ctx); Ok(ParseResult::New( - Var::new(name, None, ty, Some(val), true), + Var::new(name, None, None, ty, Some(val), true), Some(cursor), )) } @@ -291,6 +300,13 @@ impl ClangSubItemParser for Var { return Err(ParseError::Continue); } + let link_name = ctx.options().last_callback(|callbacks| { + callbacks.generated_link_name_override(ItemInfo { + name: name.as_str(), + kind: ItemKind::Var, + }) + }); + let ty = cursor.cur_type(); // TODO(emilio): do we have to special-case constant arrays in @@ -360,7 +376,8 @@ impl ClangSubItemParser for Var { }; let mangling = cursor_mangling(ctx, &cursor); - let var = Var::new(name, mangling, ty, value, is_const); + let var = + Var::new(name, mangling, link_name, ty, value, is_const); Ok(ParseResult::New(var, Some(cursor))) } From 9f2d2d3861d45ebd827466277f6843421dcaac96 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Sat, 18 Mar 2023 22:47:07 -0500 Subject: [PATCH 470/942] Avoid unnecessary clones (#2450) --- bindgen/codegen/mod.rs | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 35531e290f..ce5066cadb 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -56,7 +56,6 @@ use std::borrow::Cow; use std::cell::Cell; use std::collections::VecDeque; use std::fmt::Write; -use std::iter; use std::ops; use std::str::FromStr; @@ -1596,15 +1595,18 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit { let layout = self.layout(); let unit_field_ty = helpers::bitfield_unit(ctx, layout); - let field_ty = if parent.is_union() { - wrap_union_field_if_needed( - ctx, - struct_layout, - unit_field_ty.clone(), - result, - ) - } else { - unit_field_ty.clone() + let field_ty = { + let unit_field_ty = unit_field_ty.clone(); + if parent.is_union() { + wrap_union_field_if_needed( + ctx, + struct_layout, + unit_field_ty, + result, + ) + } else { + unit_field_ty + } }; { @@ -4236,13 +4238,12 @@ fn objc_method_codegen( let fn_ret = utils::fnsig_return_ty(ctx, signature); let sig = if method.is_class_method() { - let fn_args = fn_args.clone(); quote! { ( #( #fn_args ),* ) #fn_ret } } else { - let fn_args = fn_args.clone(); - let args = iter::once(quote! { &self }).chain(fn_args.into_iter()); + let self_arr = [quote! { &self }]; + let args = self_arr.iter().chain(fn_args.iter()); quote! { ( #( #args ),* ) #fn_ret } From 1e2480a45466dfe8fb0d93c93bf9cb07ec0b1c92 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Mon, 20 Mar 2023 23:47:24 -0500 Subject: [PATCH 471/942] Update book section about inlined functions (#2454) --- book/src/faq.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/book/src/faq.md b/book/src/faq.md index f133561d84..4ef29286fd 100644 --- a/book/src/faq.md +++ b/book/src/faq.md @@ -54,6 +54,13 @@ Note that these functions and methods are usually marked inline for a reason: they tend to be hot. The above workaround makes them an out-of-line call, which might not provide acceptable performance. +As an alternative, you can invoke `bindgen` with either the +`bindgen::Builder::wrap_static_fns` method or the `--wrap-static-fns` flag. +Which generates a C source file that can be compiled against the input headers +to produce Rust headers for `static` and `static inline` functions. See [How to +handle `static inline` functions](https://github.com/rust-lang/rust-bindgen/discussions/2405) +for further information. + ### Does `bindgen` support the C++ Standard Template Library (STL)? Sort of. A little. Depends what you mean by "support". From 169ec3af6afc19caa04541ef77425858336136bc Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Tue, 21 Mar 2023 21:32:38 -0500 Subject: [PATCH 472/942] Update `syn` to 2.0 (#2455) --- Cargo.lock | 25 +++++++++++++------ bindgen/Cargo.toml | 2 +- .../postprocessing/merge_extern_blocks.rs | 2 ++ .../postprocessing/sort_semantically.rs | 1 - 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e435ba0b43..548481aab0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -27,7 +27,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn", + "syn 2.0.4", "which", ] @@ -130,7 +130,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -386,7 +386,7 @@ dependencies = [ "proc-macro-error-attr", "proc-macro2", "quote", - "syn", + "syn 1.0.107", "version_check", ] @@ -403,9 +403,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.50" +version = "1.0.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" +checksum = "1d0e1ae9e836cc3beddd63db0df682593d7e2d3d891ae8c9083d2113e1744224" dependencies = [ "unicode-ident", ] @@ -433,9 +433,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.23" +version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" dependencies = [ "proc-macro2", ] @@ -527,6 +527,17 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "syn" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c622ae390c9302e214c31013517c2061ecb2699935882c60a9b37f82f8625ae" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "tempfile" version = "3.4.0" diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index e1bdc3cbca..b6b7530fcc 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -32,7 +32,7 @@ lazycell = "1" lazy_static = "1" peeking_take_while = "0.1.2" quote = { version = "1", default-features = false } -syn = { version = "1.0.99", features = ["full", "extra-traits", "visit-mut"]} +syn = { version = "2.0", features = ["full", "extra-traits", "visit-mut"]} regex = { version = "1.5", default-features = false , features = ["std", "unicode"] } which = { version = "4.2.1", optional = true, default-features = false } shlex = "1" diff --git a/bindgen/codegen/postprocessing/merge_extern_blocks.rs b/bindgen/codegen/postprocessing/merge_extern_blocks.rs index f9c8d30793..10fa0ec80b 100644 --- a/bindgen/codegen/postprocessing/merge_extern_blocks.rs +++ b/bindgen/codegen/postprocessing/merge_extern_blocks.rs @@ -32,6 +32,7 @@ fn visit_items(items: &mut Vec) { attrs, abi, brace_token, + unsafety, items: extern_block_items, }) = item { @@ -53,6 +54,7 @@ fn visit_items(items: &mut Vec) { attrs, abi, brace_token, + unsafety, items: extern_block_items, }); } diff --git a/bindgen/codegen/postprocessing/sort_semantically.rs b/bindgen/codegen/postprocessing/sort_semantically.rs index 0fd4212c9d..be94ce69c5 100644 --- a/bindgen/codegen/postprocessing/sort_semantically.rs +++ b/bindgen/codegen/postprocessing/sort_semantically.rs @@ -41,7 +41,6 @@ fn visit_items(items: &mut [Item]) { Item::ExternCrate(_) => 13, Item::ForeignMod(_) => 14, Item::Macro(_) => 15, - Item::Macro2(_) => 16, _ => 18, }); } From aad98d2686c5da1922527bbe45a4b00468c5f84a Mon Sep 17 00:00:00 2001 From: Nils Bars Date: Thu, 23 Mar 2023 04:19:01 +0100 Subject: [PATCH 473/942] Allow to set default visibility of struct fields. (#2338) * WIP: Allow to set default visibility of structs and their fields. * Also change visibility of NewType types * Add CLI flag `--default-visibility` * Fix clippy warning * Fix roundtrip * Add tests * Run rustfmt * Update method and flag descriptions * Test bitfields too * Update changelog --------- Co-authored-by: Christian Poveda --- CHANGELOG.md | 3 +- bindgen-cli/options.rs | 13 +- .../tests/default_visibility_crate.rs | 168 ++++++++++++++++++ .../tests/default_visibility_private.rs | 168 ++++++++++++++++++ ...bility_private_respects_cxx_access_spec.rs | 168 ++++++++++++++++++ .../tests/headers/default_visibility_crate.h | 12 ++ .../headers/default_visibility_private.h | 12 ++ ...ibility_private_respects_cxx_access_spec.h | 12 ++ bindgen/codegen/mod.rs | 150 +++++++++++----- bindgen/ir/annotations.rs | 60 ++++++- bindgen/lib.rs | 23 +++ 11 files changed, 739 insertions(+), 50 deletions(-) create mode 100644 bindgen-tests/tests/expectations/tests/default_visibility_crate.rs create mode 100644 bindgen-tests/tests/expectations/tests/default_visibility_private.rs create mode 100644 bindgen-tests/tests/expectations/tests/default_visibility_private_respects_cxx_access_spec.rs create mode 100644 bindgen-tests/tests/headers/default_visibility_crate.h create mode 100644 bindgen-tests/tests/headers/default_visibility_private.h create mode 100644 bindgen-tests/tests/headers/default_visibility_private_respects_cxx_access_spec.h diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a6c86b3f3..fba3b814a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -162,7 +162,8 @@ # Unreleased ## Added - + * Added the `Bindgen::default_visibility` nethod and the + `--default-visibility` flag to set the default visibility of fields. ## Changed * Static functions with no arguments use `void` as their single argument instead of having no arguments when the `--wrap-static-fns` flag is used. diff --git a/bindgen-cli/options.rs b/bindgen-cli/options.rs index 3f22e7eee4..523b7b7138 100644 --- a/bindgen-cli/options.rs +++ b/bindgen-cli/options.rs @@ -1,8 +1,8 @@ use bindgen::callbacks::TypeKind; use bindgen::{ builder, AliasVariation, Builder, CodegenConfig, EnumVariation, - MacroTypeVariation, NonCopyUnionStyle, RegexSet, RustTarget, - DEFAULT_ANON_FIELDS_PREFIX, RUST_TARGET_STRINGS, + FieldVisibilityKind, MacroTypeVariation, NonCopyUnionStyle, RegexSet, + RustTarget, DEFAULT_ANON_FIELDS_PREFIX, RUST_TARGET_STRINGS, }; use clap::Parser; use std::fs::File; @@ -358,6 +358,10 @@ struct BindgenCommand { /// inline` functions. #[arg(long, requires = "experimental", value_name = "SUFFIX")] wrap_static_fns_suffix: Option, + /// Set the default visibility of fields, including bitfields and accessor methods for + /// bitfields. This flag is ignored if the `--respect-cxx-access-specs` flag is used. + #[arg(long, value_name = "VISIBILITY")] + default_visibility: Option, /// Enables experimental features. #[arg(long)] experimental: bool, @@ -482,6 +486,7 @@ where wrap_static_fns, wrap_static_fns_path, wrap_static_fns_suffix, + default_visibility, experimental: _, version, clang_args, @@ -1015,5 +1020,9 @@ where builder = builder.wrap_static_fns_suffix(suffix); } + if let Some(visibility) = default_visibility { + builder = builder.default_visibility(visibility); + } + Ok((builder, output, verbose)) } diff --git a/bindgen-tests/tests/expectations/tests/default_visibility_crate.rs b/bindgen-tests/tests/expectations/tests/default_visibility_crate.rs new file mode 100644 index 0000000000..9da61b5aaa --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/default_visibility_crate.rs @@ -0,0 +1,168 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[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] + 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]; + 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 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]; + 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 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 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); + } + } +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Point { + pub(crate) x: ::std::os::raw::c_int, + pub(crate) y: ::std::os::raw::c_int, +} +#[repr(C, packed)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Color { + pub(crate) _bitfield_align_1: [u8; 0], + pub(crate) _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, +} +impl Color { + #[inline] + pub(crate) fn r(&self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) + } + } + #[inline] + pub(crate) fn set_r(&mut self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + self._bitfield_1.set(0usize, 1u8, val as u64) + } + } + #[inline] + pub(crate) fn g(&self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u8) + } + } + #[inline] + pub(crate) fn set_g(&mut self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + self._bitfield_1.set(1usize, 1u8, val as u64) + } + } + #[inline] + pub(crate) fn b(&self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u8) + } + } + #[inline] + pub(crate) fn set_b(&mut self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + self._bitfield_1.set(2usize, 1u8, val as u64) + } + } + #[inline] + pub(crate) fn new_bitfield_1( + r: ::std::os::raw::c_char, + g: ::std::os::raw::c_char, + b: ::std::os::raw::c_char, + ) -> __BindgenBitfieldUnit<[u8; 1usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = + Default::default(); + __bindgen_bitfield_unit.set(0usize, 1u8, { + let r: u8 = unsafe { ::std::mem::transmute(r) }; + r as u64 + }); + __bindgen_bitfield_unit.set(1usize, 1u8, { + let g: u8 = unsafe { ::std::mem::transmute(g) }; + g as u64 + }); + __bindgen_bitfield_unit.set(2usize, 1u8, { + let b: u8 = unsafe { ::std::mem::transmute(b) }; + b as u64 + }); + __bindgen_bitfield_unit + } +} diff --git a/bindgen-tests/tests/expectations/tests/default_visibility_private.rs b/bindgen-tests/tests/expectations/tests/default_visibility_private.rs new file mode 100644 index 0000000000..382778f9d9 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/default_visibility_private.rs @@ -0,0 +1,168 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[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] + 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]; + 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 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]; + 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 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 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); + } + } +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Point { + x: ::std::os::raw::c_int, + y: ::std::os::raw::c_int, +} +#[repr(C, packed)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Color { + _bitfield_align_1: [u8; 0], + _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, +} +impl Color { + #[inline] + fn r(&self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) + } + } + #[inline] + fn set_r(&mut self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + self._bitfield_1.set(0usize, 1u8, val as u64) + } + } + #[inline] + fn g(&self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u8) + } + } + #[inline] + fn set_g(&mut self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + self._bitfield_1.set(1usize, 1u8, val as u64) + } + } + #[inline] + fn b(&self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u8) + } + } + #[inline] + fn set_b(&mut self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + self._bitfield_1.set(2usize, 1u8, val as u64) + } + } + #[inline] + fn new_bitfield_1( + r: ::std::os::raw::c_char, + g: ::std::os::raw::c_char, + b: ::std::os::raw::c_char, + ) -> __BindgenBitfieldUnit<[u8; 1usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = + Default::default(); + __bindgen_bitfield_unit.set(0usize, 1u8, { + let r: u8 = unsafe { ::std::mem::transmute(r) }; + r as u64 + }); + __bindgen_bitfield_unit.set(1usize, 1u8, { + let g: u8 = unsafe { ::std::mem::transmute(g) }; + g as u64 + }); + __bindgen_bitfield_unit.set(2usize, 1u8, { + let b: u8 = unsafe { ::std::mem::transmute(b) }; + b as u64 + }); + __bindgen_bitfield_unit + } +} diff --git a/bindgen-tests/tests/expectations/tests/default_visibility_private_respects_cxx_access_spec.rs b/bindgen-tests/tests/expectations/tests/default_visibility_private_respects_cxx_access_spec.rs new file mode 100644 index 0000000000..02460445c9 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/default_visibility_private_respects_cxx_access_spec.rs @@ -0,0 +1,168 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[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] + 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]; + 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 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]; + 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 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 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); + } + } +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Point { + pub x: ::std::os::raw::c_int, + pub y: ::std::os::raw::c_int, +} +#[repr(C, packed)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Color { + _bitfield_align_1: [u8; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, +} +impl Color { + #[inline] + pub fn r(&self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) + } + } + #[inline] + pub fn set_r(&mut self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + self._bitfield_1.set(0usize, 1u8, val as u64) + } + } + #[inline] + pub fn g(&self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u8) + } + } + #[inline] + pub fn set_g(&mut self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + self._bitfield_1.set(1usize, 1u8, val as u64) + } + } + #[inline] + pub fn b(&self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u8) + } + } + #[inline] + pub fn set_b(&mut self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + self._bitfield_1.set(2usize, 1u8, val as u64) + } + } + #[inline] + pub fn new_bitfield_1( + r: ::std::os::raw::c_char, + g: ::std::os::raw::c_char, + b: ::std::os::raw::c_char, + ) -> __BindgenBitfieldUnit<[u8; 1usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = + Default::default(); + __bindgen_bitfield_unit.set(0usize, 1u8, { + let r: u8 = unsafe { ::std::mem::transmute(r) }; + r as u64 + }); + __bindgen_bitfield_unit.set(1usize, 1u8, { + let g: u8 = unsafe { ::std::mem::transmute(g) }; + g as u64 + }); + __bindgen_bitfield_unit.set(2usize, 1u8, { + let b: u8 = unsafe { ::std::mem::transmute(b) }; + b as u64 + }); + __bindgen_bitfield_unit + } +} diff --git a/bindgen-tests/tests/headers/default_visibility_crate.h b/bindgen-tests/tests/headers/default_visibility_crate.h new file mode 100644 index 0000000000..c6f0be87c5 --- /dev/null +++ b/bindgen-tests/tests/headers/default_visibility_crate.h @@ -0,0 +1,12 @@ +// bindgen-flags: --no-layout-tests --default-visibility=crate + +struct Point { + int x; + int y; +}; + +struct Color { + char r :1; + char g :1; + char b :1; +}; diff --git a/bindgen-tests/tests/headers/default_visibility_private.h b/bindgen-tests/tests/headers/default_visibility_private.h new file mode 100644 index 0000000000..7ba75f7cb8 --- /dev/null +++ b/bindgen-tests/tests/headers/default_visibility_private.h @@ -0,0 +1,12 @@ +// bindgen-flags: --no-layout-tests --default-visibility=private + +struct Point { + int x; + int y; +}; + +struct Color { + char r :1; + char g :1; + char b :1; +}; diff --git a/bindgen-tests/tests/headers/default_visibility_private_respects_cxx_access_spec.h b/bindgen-tests/tests/headers/default_visibility_private_respects_cxx_access_spec.h new file mode 100644 index 0000000000..875484099a --- /dev/null +++ b/bindgen-tests/tests/headers/default_visibility_private_respects_cxx_access_spec.h @@ -0,0 +1,12 @@ +// bindgen-flags: --respect-cxx-access-specs --no-layout-tests --default-visibility=private + +struct Point { + int x; + int y; +}; + +struct Color { + char r :1; + char g :1; + char b :1; +}; diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index ce5066cadb..8edde222c5 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -21,7 +21,9 @@ use super::BindgenOptions; use crate::callbacks::{DeriveInfo, TypeKind as DeriveTypeKind}; use crate::ir::analysis::{HasVtable, Sizedness}; -use crate::ir::annotations::FieldAccessorKind; +use crate::ir::annotations::{ + Annotations, FieldAccessorKind, FieldVisibilityKind, +}; use crate::ir::comp::{ Bitfield, BitfieldUnit, CompInfo, CompKind, Field, FieldData, FieldMethods, Method, MethodKind, @@ -1038,13 +1040,15 @@ impl CodeGenerator for Type { }); } + let access_spec = + access_specifier(ctx.options().default_visibility); tokens.append_all(match alias_style { AliasVariation::TypeAlias => quote! { = #inner_rust_type ; }, AliasVariation::NewType | AliasVariation::NewTypeDeref => { quote! { - (pub #inner_rust_type) ; + (#access_spec #inner_rust_type) ; } } }); @@ -1275,7 +1279,7 @@ trait FieldCodegen<'a> { fn codegen( &self, ctx: &BindgenContext, - fields_should_be_private: bool, + visibility_kind: FieldVisibilityKind, accessor_kind: FieldAccessorKind, parent: &CompInfo, result: &mut CodegenResult, @@ -1294,7 +1298,7 @@ impl<'a> FieldCodegen<'a> for Field { fn codegen( &self, ctx: &BindgenContext, - fields_should_be_private: bool, + visibility_kind: FieldVisibilityKind, accessor_kind: FieldAccessorKind, parent: &CompInfo, result: &mut CodegenResult, @@ -1310,7 +1314,7 @@ impl<'a> FieldCodegen<'a> for Field { Field::DataMember(ref data) => { data.codegen( ctx, - fields_should_be_private, + visibility_kind, accessor_kind, parent, result, @@ -1323,7 +1327,7 @@ impl<'a> FieldCodegen<'a> for Field { Field::Bitfields(ref unit) => { unit.codegen( ctx, - fields_should_be_private, + visibility_kind, accessor_kind, parent, result, @@ -1372,7 +1376,7 @@ impl<'a> FieldCodegen<'a> for FieldData { fn codegen( &self, ctx: &BindgenContext, - fields_should_be_private: bool, + parent_visibility_kind: FieldVisibilityKind, accessor_kind: FieldAccessorKind, parent: &CompInfo, result: &mut CodegenResult, @@ -1435,23 +1439,31 @@ impl<'a> FieldCodegen<'a> for FieldData { fields.extend(Some(padding_field)); } - let is_private = (!self.is_public() && - ctx.options().respect_cxx_access_specs) || - self.annotations() - .private_fields() - .unwrap_or(fields_should_be_private); - + let visibility = compute_visibility( + ctx, + self.is_public(), + Some(self.annotations()), + parent_visibility_kind, + ); let accessor_kind = self.annotations().accessor_kind().unwrap_or(accessor_kind); - if is_private { - field.append_all(quote! { - #field_ident : #ty , - }); - } else { - field.append_all(quote! { - pub #field_ident : #ty , - }); + match visibility { + FieldVisibilityKind::Private => { + field.append_all(quote! { + #field_ident : #ty , + }); + } + FieldVisibilityKind::PublicCrate => { + field.append_all(quote! { + pub(crate) #field_ident : #ty , + }); + } + FieldVisibilityKind::Public => { + field.append_all(quote! { + pub #field_ident : #ty , + }); + } } fields.extend(Some(field)); @@ -1561,13 +1573,48 @@ impl Bitfield { } fn access_specifier( - ctx: &BindgenContext, - is_pub: bool, + visibility: FieldVisibilityKind, ) -> proc_macro2::TokenStream { - if is_pub || !ctx.options().respect_cxx_access_specs { - quote! { pub } - } else { - quote! {} + match visibility { + FieldVisibilityKind::Private => quote! {}, + FieldVisibilityKind::PublicCrate => quote! { pub(crate) }, + FieldVisibilityKind::Public => quote! { pub }, + } +} + +/// Compute a fields or structs visibility based on multiple conditions. +/// 1. If the element was declared public, and we respect such CXX accesses specs +/// (context option) => By default Public, but this can be overruled by an `annotation`. +/// +/// 2. If the element was declared private, and we respect such CXX accesses specs +/// (context option) => By default Private, but this can be overruled by an `annotation`. +/// +/// 3. If we do not respect visibility modifiers, the result depends on the `annotation`, +/// if any, or the passed `default_kind`. +/// +fn compute_visibility( + ctx: &BindgenContext, + is_declared_public: bool, + annotations: Option<&Annotations>, + default_kind: FieldVisibilityKind, +) -> FieldVisibilityKind { + match ( + is_declared_public, + ctx.options().respect_cxx_access_specs, + annotations.and_then(|e| e.visibility_kind()), + ) { + (true, true, annotated_visibility) => { + // declared as public, cxx specs are respected + annotated_visibility.unwrap_or(FieldVisibilityKind::Public) + } + (false, true, annotated_visibility) => { + // declared as private, cxx specs are respected + annotated_visibility.unwrap_or(FieldVisibilityKind::Private) + } + (_, false, annotated_visibility) => { + // cxx specs are not respected, declaration does not matter. + annotated_visibility.unwrap_or(default_kind) + } } } @@ -1577,7 +1624,7 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit { fn codegen( &self, ctx: &BindgenContext, - fields_should_be_private: bool, + visibility_kind: FieldVisibilityKind, accessor_kind: FieldAccessorKind, parent: &CompInfo, result: &mut CodegenResult, @@ -1618,8 +1665,9 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit { 2 => quote! { u16 }, _ => quote! { u8 }, }; + let access_spec = access_specifier(visibility_kind); let align_field = quote! { - pub #align_field_ident: [#align_ty; 0], + #access_spec #align_field_ident: [#align_ty; 0], }; fields.extend(Some(align_field)); } @@ -1638,7 +1686,7 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit { // the 32 items limitation. let mut generate_ctor = layout.size <= RUST_DERIVE_IN_ARRAY_LIMIT; - let mut access_spec = !fields_should_be_private; + let mut all_fields_declared_as_public = true; for bf in self.bitfields() { // Codegen not allowed for anonymous bitfields if bf.name().is_none() { @@ -1651,12 +1699,11 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit { continue; } - access_spec &= bf.is_public(); + all_fields_declared_as_public &= bf.is_public(); let mut bitfield_representable_as_int = true; - bf.codegen( ctx, - fields_should_be_private, + visibility_kind, accessor_kind, parent, result, @@ -1684,7 +1731,13 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit { ctor_impl = bf.extend_ctor_impl(ctx, param_name, ctor_impl); } - let access_spec = access_specifier(ctx, access_spec); + let visibility_kind = compute_visibility( + ctx, + all_fields_declared_as_public, + None, + visibility_kind, + ); + let access_spec = access_specifier(visibility_kind); let field = quote! { #access_spec #unit_field_ident : #field_ty , @@ -1730,7 +1783,7 @@ impl<'a> FieldCodegen<'a> for Bitfield { fn codegen( &self, ctx: &BindgenContext, - fields_should_be_private: bool, + visibility_kind: FieldVisibilityKind, _accessor_kind: FieldAccessorKind, parent: &CompInfo, _result: &mut CodegenResult, @@ -1770,10 +1823,14 @@ impl<'a> FieldCodegen<'a> for Bitfield { let offset = self.offset_into_unit(); let width = self.width() as u8; - let access_spec = access_specifier( + + let visibility_kind = compute_visibility( ctx, - self.is_public() && !fields_should_be_private, + self.is_public(), + Some(self.annotations()), + visibility_kind, ); + let access_spec = access_specifier(visibility_kind); if parent.is_union() && !struct_layout.is_rust_union() { methods.extend(Some(quote! { @@ -1899,7 +1956,16 @@ impl CodeGenerator for CompInfo { struct_layout.saw_base(inner_item.expect_type()); - let access_spec = access_specifier(ctx, base.is_public()); + let visibility = match ( + base.is_public(), + ctx.options().respect_cxx_access_specs, + ) { + (true, true) => FieldVisibilityKind::Public, + (false, true) => FieldVisibilityKind::Private, + _ => ctx.options().default_visibility, + }; + + let access_spec = access_specifier(visibility); fields.push(quote! { #access_spec #field_name: #inner, }); @@ -1908,8 +1974,10 @@ impl CodeGenerator for CompInfo { let mut methods = vec![]; if !is_opaque { - let fields_should_be_private = - item.annotations().private_fields().unwrap_or(false); + let visibility = item + .annotations() + .visibility_kind() + .unwrap_or(ctx.options().default_visibility); let struct_accessor_kind = item .annotations() .accessor_kind() @@ -1917,7 +1985,7 @@ impl CodeGenerator for CompInfo { for field in self.fields() { field.codegen( ctx, - fields_should_be_private, + visibility, struct_accessor_kind, self, result, diff --git a/bindgen/ir/annotations.rs b/bindgen/ir/annotations.rs index 58d1e695e9..844f857b01 100644 --- a/bindgen/ir/annotations.rs +++ b/bindgen/ir/annotations.rs @@ -4,8 +4,52 @@ //! replace other types with, mark as opaque, etc. This module deals with all of //! that stuff. +use std::str::FromStr; + use crate::clang; +/// What kind of visibility modifer should be used for a struct or field? +#[derive(Copy, PartialEq, Eq, Clone, Debug)] +pub enum FieldVisibilityKind { + /// Fields are marked as private, i.e., struct Foo {bar: bool} + Private, + /// Fields are marked as crate public, i.e., struct Foo {pub(crate) bar: bool} + PublicCrate, + /// Fields are marked as public, i.e., struct Foo {pub bar: bool} + Public, +} + +impl FromStr for FieldVisibilityKind { + type Err = String; + + fn from_str(s: &str) -> Result { + match s { + "private" => Ok(Self::Private), + "crate" => Ok(Self::PublicCrate), + "public" => Ok(Self::Public), + _ => Err(format!("Invalid visibility kind: `{}`", s)), + } + } +} + +impl std::fmt::Display for FieldVisibilityKind { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let s = match self { + FieldVisibilityKind::Private => "private", + FieldVisibilityKind::PublicCrate => "crate", + FieldVisibilityKind::Public => "public", + }; + + s.fmt(f) + } +} + +impl Default for FieldVisibilityKind { + fn default() -> Self { + FieldVisibilityKind::Public + } +} + /// What kind of accessor should we provide for a field? #[derive(Copy, PartialEq, Eq, Clone, Debug)] pub(crate) enum FieldAccessorKind { @@ -41,9 +85,9 @@ pub(crate) struct Annotations { disallow_default: bool, /// Whether to add a #[must_use] annotation to this type. must_use_type: bool, - /// Whether fields should be marked as private or not. You can set this on + /// Visibility of struct fields. You can set this on /// structs (it will apply to all the fields), or individual fields. - private_fields: Option, + visibility_kind: Option, /// The kind of accessor this field will have. Also can be applied to /// structs so all the fields inside share it by default. accessor_kind: Option, @@ -150,9 +194,9 @@ impl Annotations { self.must_use_type } - /// Should the fields be private? - pub(crate) fn private_fields(&self) -> Option { - self.private_fields + /// What kind of accessors should we provide for this type's fields? + pub(crate) fn visibility_kind(&self) -> Option { + self.visibility_kind } /// What kind of accessors should we provide for this type's fields? @@ -185,7 +229,11 @@ impl Annotations { } "derive" => self.derives.push(attr.value), "private" => { - self.private_fields = Some(attr.value != "false") + self.visibility_kind = if attr.value != "false" { + Some(FieldVisibilityKind::Private) + } else { + Some(FieldVisibilityKind::Public) + }; } "accessor" => { self.accessor_kind = Some(parse_accessor(&attr.value)) diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 0a89462fce..cb7405f5a8 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -61,6 +61,8 @@ mod regex_set; use codegen::CodegenError; use ir::comment; +pub use ir::annotations::FieldVisibilityKind; + pub use crate::codegen::{ AliasVariation, EnumVariation, MacroTypeVariation, NonCopyUnionStyle, }; @@ -653,6 +655,11 @@ impl Builder { output_vector.push(suffix.clone()); } + if self.options.default_visibility != FieldVisibilityKind::Public { + output_vector.push("--default-visibility".into()); + output_vector.push(self.options.default_visibility.to_string()); + } + if cfg!(feature = "experimental") { output_vector.push("--experimental".into()); } @@ -1813,6 +1820,18 @@ impl Builder { self.options.wrap_static_fns_suffix = Some(suffix.as_ref().to_owned()); self } + + /// Set the default visibility of fields, including bitfields and accessor methods for + /// bitfields. + /// + /// This option is ignored if the [`Builder::respect_cxx_access_specs`] method is enabled. + pub fn default_visibility( + mut self, + visibility: FieldVisibilityKind, + ) -> Self { + self.options.default_visibility = visibility; + self + } } /// Configuration options for generated bindings. @@ -2159,6 +2178,9 @@ struct BindgenOptions { wrap_static_fns_suffix: Option, wrap_static_fns_path: Option, + + /// Default visibility of structs and their fields. + default_visibility: FieldVisibilityKind, } impl BindgenOptions { @@ -2354,6 +2376,7 @@ impl Default for BindgenOptions { wrap_static_fns, wrap_static_fns_suffix, wrap_static_fns_path, + default_visibility, } } } From b3ed209dcbc6108956d6b1ff0aa583eb696394fc Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Thu, 23 Mar 2023 15:35:21 -0500 Subject: [PATCH 474/942] Various documentation fixes (#2460) * Remove typos from CLI docs * Include `override_abi` as a regex based option * Document that `--no-copy` also removes `Clone` --- bindgen-cli/options.rs | 6 +++--- bindgen/lib.rs | 21 +++++++++++---------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/bindgen-cli/options.rs b/bindgen-cli/options.rs index 523b7b7138..1338269550 100644 --- a/bindgen-cli/options.rs +++ b/bindgen-cli/options.rs @@ -129,7 +129,7 @@ struct BindgenCommand { /// Derive Default on any type. #[arg(long)] with_derive_default: bool, - /// Derive Hash on any type.docstring + /// Derive Hash on any type. #[arg(long)] with_derive_hash: bool, /// Derive PartialEq on any type. @@ -198,7 +198,7 @@ struct BindgenCommand { /// Suppress insertion of bindgen's version identifier into generated bindings. #[arg(long)] disable_header_comment: bool, - /// Do not generate bindings for functions or methods. This is useful when you only care about struct layouts.docstring + /// Do not generate bindings for functions or methods. This is useful when you only care about struct layouts. #[arg(long)] ignore_functions: bool, /// Generate only given items, split by commas. Valid values are `functions`,`types`, `vars`, `methods`, `constructors` and `destructors`. @@ -275,7 +275,7 @@ struct BindgenCommand { /// Avoid deriving PartialEq for types matching . #[arg(long, value_name = "REGEX")] no_partialeq: Vec, - /// Avoid deriving Copy for types matching . + /// Avoid deriving Copy and Clone for types matching . #[arg(long, value_name = "REGEX")] no_copy: Vec, /// Avoid deriving Debug for types matching . diff --git a/bindgen/lib.rs b/bindgen/lib.rs index cb7405f5a8..50f415a0b4 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -1678,8 +1678,7 @@ impl Builder { } fn_with_regex_arg! { - /// Don't derive `Copy` for a given type. Regular - /// expressions are supported. + /// Don't derive `Copy` and `Clone` for a given type. Regular expressions are supported. pub fn no_copy>(mut self, arg: T) -> Self { self.options.no_copy_types.insert(arg.into()); self @@ -1779,14 +1778,16 @@ impl Builder { self } - /// Override the ABI of a given function. Regular expressions are supported. - pub fn override_abi>(mut self, abi: Abi, arg: T) -> Self { - self.options - .abi_overrides - .entry(abi) - .or_default() - .insert(arg.into()); - self + fn_with_regex_arg! { + /// Override the ABI of a given function. Regular expressions are supported. + pub fn override_abi>(mut self, abi: Abi, arg: T) -> Self { + self.options + .abi_overrides + .entry(abi) + .or_default() + .insert(arg.into()); + self + } } /// If true, wraps unsafe operations in unsafe blocks. From 18b2f9cf7ab9b130421573de53bb73be8cfc7eb5 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Thu, 23 Mar 2023 16:44:43 -0500 Subject: [PATCH 475/942] Use location comments before the declaration ones (#2463) * Use location comments before the declaration ones * Add tests * Update changelog --- CHANGELOG.md | 3 +++ .../expectations/tests/alias_comments.rs | 20 ++++++++++++++ bindgen-tests/tests/headers/alias_comments.h | 26 +++++++++++++++++++ bindgen/ir/item.rs | 6 ++++- 4 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 bindgen-tests/tests/expectations/tests/alias_comments.rs create mode 100644 bindgen-tests/tests/headers/alias_comments.h diff --git a/CHANGELOG.md b/CHANGELOG.md index fba3b814a9..4cb5cfb715 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -173,6 +173,9 @@ * The source file generated when the `--wrap-static-fns` flag no longer uses `asm` labeling and the link name of static wrapper functions is allowed to be mangled. + * The documentation of the generated `type` aliases now matches the comments + of their `typedef` counterparts instead of using the comments of the aliased + types. ## Removed * The following deprecated flags were removed: `--use-msvc-mangling`, `--rustfmt-bindings` and `--size_t-is-usize`. diff --git a/bindgen-tests/tests/expectations/tests/alias_comments.rs b/bindgen-tests/tests/expectations/tests/alias_comments.rs new file mode 100644 index 0000000000..c04e9bb8f1 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/alias_comments.rs @@ -0,0 +1,20 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +/// This is Struct +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Struct { + /// This is field + pub field: ::std::os::raw::c_int, +} +/// This is AliasToStruct +pub type AliasToStruct = Struct; +/// This is AliasToInt +pub type AliasToInt = ::std::os::raw::c_int; +/// This is AliasToAliasToInt +pub type AliasToAliasToInt = AliasToInt; diff --git a/bindgen-tests/tests/headers/alias_comments.h b/bindgen-tests/tests/headers/alias_comments.h new file mode 100644 index 0000000000..2547c3c1a2 --- /dev/null +++ b/bindgen-tests/tests/headers/alias_comments.h @@ -0,0 +1,26 @@ +// bindgen-flags: --no-layout-tests + +/** + * This is Struct + */ +typedef struct { + /** + * This is field + */ + int field; +} Struct; + +/** + * This is AliasToStruct + */ +typedef Struct AliasToStruct; + +/** + * This is AliasToInt + */ +typedef int AliasToInt; + +/** + * This is AliasToAliasToInt + */ +typedef AliasToInt AliasToAliasToInt; diff --git a/bindgen/ir/item.rs b/bindgen/ir/item.rs index 4ab4f0a907..146aff1d88 100644 --- a/bindgen/ir/item.rs +++ b/bindgen/ir/item.rs @@ -1625,7 +1625,11 @@ impl Item { canonical_def.unwrap_or_else(|| ty.declaration()) }; - let comment = decl.raw_comment().or_else(|| location.raw_comment()); + let comment = location + .raw_comment() + .or_else(|| decl.raw_comment()) + .or_else(|| dbg!(location.raw_comment())); + let annotations = Annotations::new(&decl).or_else(|| Annotations::new(&location)); From a1216813fa9b4a856f84c086754d9f2c876be794 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Thu, 23 Mar 2023 16:44:59 -0500 Subject: [PATCH 476/942] Make harder to forget to update `Builder::command_line_flags` (#2461) --- bindgen/lib.rs | 375 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 246 insertions(+), 129 deletions(-) diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 50f415a0b4..9d89b089a5 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -261,27 +261,142 @@ impl Builder { pub fn command_line_flags(&self) -> Vec { let mut output_vector: Vec = Vec::new(); - if let Some(header) = self.options.input_headers.last().cloned() { + // We should not forget to use any new options that can be represented as CLI flags. + #[deny(unused_variables)] + let BindgenOptions { + blocklisted_types, + blocklisted_functions, + blocklisted_items, + blocklisted_files, + opaque_types, + // The rustfmt path cannot be set from the CLI. + rustfmt_path: _, + depfile, + allowlisted_types, + allowlisted_functions, + allowlisted_vars, + allowlisted_files, + default_enum_style, + bitfield_enums, + newtype_enums, + newtype_global_enums, + rustified_enums, + rustified_non_exhaustive_enums, + constified_enum_modules, + constified_enums, + default_macro_constant_type, + default_alias_style, + type_alias, + new_type_alias, + new_type_alias_deref, + default_non_copy_union_style, + bindgen_wrapper_union, + manually_drop_union, + builtins, + emit_ast, + emit_ir, + emit_ir_graphviz, + enable_cxx_namespaces, + enable_function_attribute_detection, + disable_name_namespacing, + disable_nested_struct_naming, + disable_header_comment, + layout_tests, + impl_debug, + impl_partialeq, + derive_copy, + derive_debug, + derive_default, + derive_hash, + derive_partialord, + derive_ord, + derive_partialeq, + derive_eq, + use_core, + ctypes_prefix, + anon_fields_prefix, + time_phases, + convert_floats, + raw_lines, + module_lines, + clang_args, + input_headers, + // These cannot be added from the CLI. + input_header_contents: _, + #[cfg(feature = "cli")] + parse_callbacks, + // ParseCallbacks cannot represent CLI flags if the `"cli"` feature is disabled. + #[cfg(not(feature = "cli"))] + parse_callbacks: _, + codegen_config, + conservative_inline_namespaces, + generate_comments, + generate_inline_functions, + allowlist_recursively, + objc_extern_crate, + generate_block, + block_extern_crate, + enable_mangling, + detect_include_paths, + fit_macro_constants, + prepend_enum_name, + rust_target, + rust_features, + record_matches, + size_t_is_usize, + rustfmt_bindings, + rustfmt_configuration_file, + no_partialeq_types, + no_copy_types, + no_debug_types, + no_default_types, + no_hash_types, + must_use_types, + array_pointers_in_arguments, + wasm_import_module_name, + dynamic_library_name, + dynamic_link_require_all, + respect_cxx_access_specs, + translate_enum_integer_types, + c_naming, + force_explicit_padding, + vtable_generation, + sort_semantically, + merge_extern_blocks, + abi_overrides, + wrap_unsafe_ops, + wrap_static_fns, + wrap_static_fns_suffix, + wrap_static_fns_path, + default_visibility, + } = &self.options; + + if let Some(header) = input_headers.last().cloned() { // Positional argument 'header' output_vector.push(header); } + if let Some(depfile) = depfile { + output_vector.push("--depfile".into()); + output_vector.push(depfile.depfile_path.display().to_string()); + } + output_vector.push("--rust-target".into()); - output_vector.push(self.options.rust_target.into()); + output_vector.push((*rust_target).into()); // FIXME(emilio): This is a bit hacky, maybe we should stop re-using the // RustFeatures to store the "disable_untagged_union" call, and make it // a different flag that we check elsewhere / in generate(). - if !self.options.rust_features.untagged_union && - RustFeatures::from(self.options.rust_target).untagged_union + if !rust_features.untagged_union && + RustFeatures::from(*rust_target).untagged_union { output_vector.push("--disable-untagged-union".into()); } - if self.options.default_enum_style != Default::default() { + if *default_enum_style != Default::default() { output_vector.push("--default-enum-style".into()); output_vector.push( - match self.options.default_enum_style { + match default_enum_style { codegen::EnumVariation::Rust { non_exhaustive: false, } => "rust", @@ -296,7 +411,7 @@ impl Builder { is_bitfield: false, is_global, } => { - if is_global { + if *is_global { "newtype_global" } else { "newtype" @@ -309,62 +424,52 @@ impl Builder { ) } - if self.options.default_macro_constant_type != Default::default() { + if *default_macro_constant_type != Default::default() { output_vector.push("--default-macro-constant-type".into()); - output_vector - .push(self.options.default_macro_constant_type.as_str().into()); + output_vector.push(default_macro_constant_type.as_str().into()); } - if self.options.default_alias_style != Default::default() { + if *default_alias_style != Default::default() { output_vector.push("--default-alias-style".into()); - output_vector - .push(self.options.default_alias_style.as_str().into()); + output_vector.push(default_alias_style.as_str().into()); } - if self.options.default_non_copy_union_style != Default::default() { + if *default_non_copy_union_style != Default::default() { output_vector.push("--default-non-copy-union-style".into()); - output_vector.push( - self.options.default_non_copy_union_style.as_str().into(), - ); + output_vector.push(default_non_copy_union_style.as_str().into()); } let regex_sets = &[ - (&self.options.bitfield_enums, "--bitfield-enum"), - (&self.options.newtype_enums, "--newtype-enum"), - (&self.options.newtype_global_enums, "--newtype-global-enum"), - (&self.options.rustified_enums, "--rustified-enum"), + (bitfield_enums, "--bitfield-enum"), + (newtype_enums, "--newtype-enum"), + (newtype_global_enums, "--newtype-global-enum"), + (rustified_enums, "--rustified-enum"), ( - &self.options.rustified_non_exhaustive_enums, + rustified_non_exhaustive_enums, "--rustified-enum-non-exhaustive", ), - ( - &self.options.constified_enum_modules, - "--constified-enum-module", - ), - (&self.options.constified_enums, "--constified-enum"), - (&self.options.type_alias, "--type-alias"), - (&self.options.new_type_alias, "--new-type-alias"), - (&self.options.new_type_alias_deref, "--new-type-alias-deref"), - ( - &self.options.bindgen_wrapper_union, - "--bindgen-wrapper-union", - ), - (&self.options.manually_drop_union, "--manually-drop-union"), - (&self.options.blocklisted_types, "--blocklist-type"), - (&self.options.blocklisted_functions, "--blocklist-function"), - (&self.options.blocklisted_items, "--blocklist-item"), - (&self.options.blocklisted_files, "--blocklist-file"), - (&self.options.opaque_types, "--opaque-type"), - (&self.options.allowlisted_functions, "--allowlist-function"), - (&self.options.allowlisted_types, "--allowlist-type"), - (&self.options.allowlisted_vars, "--allowlist-var"), - (&self.options.allowlisted_files, "--allowlist-file"), - (&self.options.no_partialeq_types, "--no-partialeq"), - (&self.options.no_copy_types, "--no-copy"), - (&self.options.no_debug_types, "--no-debug"), - (&self.options.no_default_types, "--no-default"), - (&self.options.no_hash_types, "--no-hash"), - (&self.options.must_use_types, "--must-use-type"), + (constified_enum_modules, "--constified-enum-module"), + (constified_enums, "--constified-enum"), + (type_alias, "--type-alias"), + (new_type_alias, "--new-type-alias"), + (new_type_alias_deref, "--new-type-alias-deref"), + (bindgen_wrapper_union, "--bindgen-wrapper-union"), + (manually_drop_union, "--manually-drop-union"), + (blocklisted_types, "--blocklist-type"), + (blocklisted_functions, "--blocklist-function"), + (blocklisted_items, "--blocklist-item"), + (blocklisted_files, "--blocklist-file"), + (opaque_types, "--opaque-type"), + (allowlisted_functions, "--allowlist-function"), + (allowlisted_types, "--allowlist-type"), + (allowlisted_vars, "--allowlist-var"), + (allowlisted_files, "--allowlist-file"), + (no_partialeq_types, "--no-partialeq"), + (no_copy_types, "--no-copy"), + (no_debug_types, "--no-debug"), + (no_default_types, "--no-default"), + (no_hash_types, "--no-hash"), + (must_use_types, "--must-use-type"), ]; for (set, flag) in regex_sets { @@ -374,126 +479,139 @@ impl Builder { } } - for (abi, set) in &self.options.abi_overrides { + for (abi, set) in abi_overrides { for item in set.get_items() { output_vector.push("--override-abi".to_owned()); output_vector.push(format!("{}={}", item, abi)); } } - if !self.options.layout_tests { + if !layout_tests { output_vector.push("--no-layout-tests".into()); } - if self.options.impl_debug { + if *impl_debug { output_vector.push("--impl-debug".into()); } - if self.options.impl_partialeq { + if *impl_partialeq { output_vector.push("--impl-partialeq".into()); } - if !self.options.derive_copy { + if !derive_copy { output_vector.push("--no-derive-copy".into()); } - if !self.options.derive_debug { + if !derive_debug { output_vector.push("--no-derive-debug".into()); } - if !self.options.derive_default { + if !derive_default { output_vector.push("--no-derive-default".into()); } else { output_vector.push("--with-derive-default".into()); } - if self.options.derive_hash { + if *derive_hash { output_vector.push("--with-derive-hash".into()); } - if self.options.derive_partialord { + if *derive_partialord { output_vector.push("--with-derive-partialord".into()); } - if self.options.derive_ord { + if *derive_ord { output_vector.push("--with-derive-ord".into()); } - if self.options.derive_partialeq { + if *derive_partialeq { output_vector.push("--with-derive-partialeq".into()); } - if self.options.derive_eq { + if *derive_eq { output_vector.push("--with-derive-eq".into()); } - if self.options.time_phases { + if *time_phases { output_vector.push("--time-phases".into()); } - if !self.options.generate_comments { + if !generate_comments { output_vector.push("--no-doc-comments".into()); } - if !self.options.allowlist_recursively { + if !allowlist_recursively { output_vector.push("--no-recursive-allowlist".into()); } - if self.options.objc_extern_crate { + if *objc_extern_crate { output_vector.push("--objc-extern-crate".into()); } - if self.options.generate_block { + if *generate_block { output_vector.push("--generate-block".into()); } - if self.options.block_extern_crate { + if *block_extern_crate { output_vector.push("--block-extern-crate".into()); } - if self.options.builtins { + if !enable_mangling { + output_vector.push("--distrust-clang-mangling".into()); + } + + if !detect_include_paths { + output_vector.push("--no-include-path-detection".into()); + } + + if *builtins { output_vector.push("--builtins".into()); } - if let Some(ref prefix) = self.options.ctypes_prefix { + if let Some(prefix) = ctypes_prefix { output_vector.push("--ctypes-prefix".into()); output_vector.push(prefix.clone()); } - if self.options.anon_fields_prefix != DEFAULT_ANON_FIELDS_PREFIX { + if *anon_fields_prefix != DEFAULT_ANON_FIELDS_PREFIX { output_vector.push("--anon-fields-prefix".into()); - output_vector.push(self.options.anon_fields_prefix.clone()); + output_vector.push(anon_fields_prefix.clone()); } - if self.options.emit_ast { + if *emit_ast { output_vector.push("--emit-clang-ast".into()); } - if self.options.emit_ir { + if *emit_ir { output_vector.push("--emit-ir".into()); } - if let Some(ref graph) = self.options.emit_ir_graphviz { + + if let Some(graph) = emit_ir_graphviz { output_vector.push("--emit-ir-graphviz".into()); output_vector.push(graph.clone()) } - if self.options.enable_cxx_namespaces { + + if *enable_cxx_namespaces { output_vector.push("--enable-cxx-namespaces".into()); } - if self.options.enable_function_attribute_detection { + + if *enable_function_attribute_detection { output_vector.push("--enable-function-attribute-detection".into()); } - if self.options.disable_name_namespacing { + + if *disable_name_namespacing { output_vector.push("--disable-name-namespacing".into()); } - if self.options.disable_nested_struct_naming { + + if *disable_nested_struct_naming { output_vector.push("--disable-nested-struct-naming".into()); } - if self.options.disable_header_comment { + if *disable_header_comment { output_vector.push("--disable-header-comment".into()); } - if !self.options.codegen_config.functions() { + if !codegen_config.functions() { output_vector.push("--ignore-functions".into()); } @@ -501,60 +619,63 @@ impl Builder { //Temporary placeholder for below 4 options let mut options: Vec = Vec::new(); - if self.options.codegen_config.functions() { + if codegen_config.functions() { options.push("functions".into()); } - if self.options.codegen_config.types() { + + if codegen_config.types() { options.push("types".into()); } - if self.options.codegen_config.vars() { + + if codegen_config.vars() { options.push("vars".into()); } - if self.options.codegen_config.methods() { + + if codegen_config.methods() { options.push("methods".into()); } - if self.options.codegen_config.constructors() { + + if codegen_config.constructors() { options.push("constructors".into()); } - if self.options.codegen_config.destructors() { + + if codegen_config.destructors() { options.push("destructors".into()); } output_vector.push(options.join(",")); - if !self.options.codegen_config.methods() { + if !codegen_config.methods() { output_vector.push("--ignore-methods".into()); } - if !self.options.convert_floats { + if !convert_floats { output_vector.push("--no-convert-floats".into()); } - if !self.options.prepend_enum_name { + if !prepend_enum_name { output_vector.push("--no-prepend-enum-name".into()); } - if self.options.fit_macro_constants { + if *fit_macro_constants { output_vector.push("--fit-macro-constant-types".into()); } - if self.options.array_pointers_in_arguments { + if *array_pointers_in_arguments { output_vector.push("--use-array-pointers-in-arguments".into()); } - if let Some(ref wasm_import_module_name) = - self.options.wasm_import_module_name - { + if let Some(ref wasm_import_module_name) = wasm_import_module_name { output_vector.push("--wasm-import-module-name".into()); output_vector.push(wasm_import_module_name.clone()); } - for line in &self.options.raw_lines { + for line in raw_lines { output_vector.push("--raw-line".into()); output_vector.push(line.clone()); } - for (module, lines) in &self.options.module_lines { + for (module, lines) in module_lines { for line in lines.iter() { output_vector.push("--module-raw-line".into()); output_vector.push(module.clone()); @@ -562,102 +683,100 @@ impl Builder { } } - if self.options.use_core { + if *use_core { output_vector.push("--use-core".into()); } - if self.options.conservative_inline_namespaces { + if *conservative_inline_namespaces { output_vector.push("--conservative-inline-namespaces".into()); } - if self.options.generate_inline_functions { + if *generate_inline_functions { output_vector.push("--generate-inline-functions".into()); } - if !self.options.record_matches { + if !record_matches { output_vector.push("--no-record-matches".into()); } - if !self.options.size_t_is_usize { + if !size_t_is_usize { output_vector.push("--no-size_t-is-usize".into()); } - if !self.options.rustfmt_bindings { + if !rustfmt_bindings { output_vector.push("--no-rustfmt-bindings".into()); } - if let Some(path) = self - .options - .rustfmt_configuration_file - .as_ref() - .and_then(|f| f.to_str()) + if let Some(path) = + rustfmt_configuration_file.as_ref().and_then(|f| f.to_str()) { output_vector.push("--rustfmt-configuration-file".into()); output_vector.push(path.into()); } - if let Some(ref name) = self.options.dynamic_library_name { + if let Some(ref name) = dynamic_library_name { output_vector.push("--dynamic-loading".into()); output_vector.push(name.clone()); } - if self.options.dynamic_link_require_all { + if *dynamic_link_require_all { output_vector.push("--dynamic-link-require-all".into()); } - if self.options.respect_cxx_access_specs { + if *respect_cxx_access_specs { output_vector.push("--respect-cxx-access-specs".into()); } - if self.options.translate_enum_integer_types { + if *translate_enum_integer_types { output_vector.push("--translate-enum-integer-types".into()); } - if self.options.c_naming { + if *c_naming { output_vector.push("--c-naming".into()); } - if self.options.force_explicit_padding { + if *force_explicit_padding { output_vector.push("--explicit-padding".into()); } - if self.options.vtable_generation { + if *vtable_generation { output_vector.push("--vtable-generation".into()); } - if self.options.sort_semantically { + if *sort_semantically { output_vector.push("--sort-semantically".into()); } - if self.options.merge_extern_blocks { + if *merge_extern_blocks { output_vector.push("--merge-extern-blocks".into()); } - if self.options.wrap_unsafe_ops { + if *wrap_unsafe_ops { output_vector.push("--wrap-unsafe-ops".into()); } #[cfg(feature = "cli")] - for callbacks in &self.options.parse_callbacks { + for callbacks in parse_callbacks { output_vector.extend(callbacks.cli_args()); } - if self.options.wrap_static_fns { + + if *wrap_static_fns { output_vector.push("--wrap-static-fns".into()) } - if let Some(ref path) = self.options.wrap_static_fns_path { + if let Some(path) = wrap_static_fns_path { output_vector.push("--wrap-static-fns-path".into()); output_vector.push(path.display().to_string()); } - if let Some(ref suffix) = self.options.wrap_static_fns_suffix { + if let Some(suffix) = wrap_static_fns_suffix { output_vector.push("--wrap-static-fns-suffix".into()); output_vector.push(suffix.clone()); } - if self.options.default_visibility != FieldVisibilityKind::Public { + if *default_visibility != FieldVisibilityKind::Public { output_vector.push("--default-visibility".into()); - output_vector.push(self.options.default_visibility.to_string()); + output_vector.push(default_visibility.to_string()); } if cfg!(feature = "experimental") { @@ -668,15 +787,13 @@ impl Builder { output_vector.push("--".into()); - if !self.options.clang_args.is_empty() { - output_vector.extend(self.options.clang_args.iter().cloned()); + if !clang_args.is_empty() { + output_vector.extend(clang_args.iter().cloned()); } // To pass more than one header, we need to pass all but the last // header via the `-include` clang arg - for header in &self.options.input_headers - [..self.options.input_headers.len().saturating_sub(1)] - { + for header in &input_headers[..input_headers.len().saturating_sub(1)] { output_vector.push("-include".to_string()); output_vector.push(header.clone()); } From 0de11f0a521611ac8738b7b01d19dddaf3899e66 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Thu, 23 Mar 2023 17:07:57 -0500 Subject: [PATCH 477/942] Add `prettyplease` support (#2453) --- CHANGELOG.md | 4 ++ Cargo.lock | 17 +++++- bindgen-cli/Cargo.toml | 3 +- bindgen-cli/options.rs | 21 +++++-- bindgen-integration/build.rs | 4 +- bindgen-tests/tests/tests.rs | 2 +- bindgen/Cargo.toml | 1 + bindgen/lib.rs | 104 ++++++++++++++++++++++++++--------- book/src/code-formatting.md | 35 ++++++++++++ book/src/faq.md | 17 ------ 10 files changed, 155 insertions(+), 53 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4cb5cfb715..daf5902057 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -164,6 +164,9 @@ ## Added * Added the `Bindgen::default_visibility` nethod and the `--default-visibility` flag to set the default visibility of fields. + * Added the `--formatter` flag with the values `none`, `rustfmt` and + `prettyplease` to select which tool will be used to format the bindings. The + default value is `rustfmt`. ## Changed * Static functions with no arguments use `void` as their single argument instead of having no arguments when the `--wrap-static-fns` flag is used. @@ -179,6 +182,7 @@ ## Removed * The following deprecated flags were removed: `--use-msvc-mangling`, `--rustfmt-bindings` and `--size_t-is-usize`. + * The `--no-rustfmt-bindings` flag was removed in favor of `--formatter=none`. ## Fixed diff --git a/Cargo.lock b/Cargo.lock index 548481aab0..984295e86c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -22,12 +22,13 @@ dependencies = [ "lazycell", "log", "peeking_take_while", + "prettyplease", "proc-macro2", "quote", "regex", "rustc-hash", "shlex", - "syn 2.0.4", + "syn 2.0.7", "which", ] @@ -377,6 +378,16 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" +[[package]] +name = "prettyplease" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4508c0eff4d1e708551034de4bddd61bf8bda8c7b5ae72bd844cf68ea21117ac" +dependencies = [ + "proc-macro2", + "syn 2.0.7", +] + [[package]] name = "proc-macro-error" version = "1.0.4" @@ -529,9 +540,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.4" +version = "2.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c622ae390c9302e214c31013517c2061ecb2699935882c60a9b37f82f8625ae" +checksum = "9a9a90d19f27bb60792270bb90225f96d97fc5705395134b2ca1dcbb3acc27f4" dependencies = [ "proc-macro2", "quote", diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index 19778d3cb5..fd56d546f5 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -28,9 +28,10 @@ env_logger = { version = "0.10.0", optional = true } log = { version = "0.4", optional = true } [features] -default = ["logging", "runtime", "which-rustfmt"] +default = ["logging", "runtime", "which-rustfmt", "prettyplease"] logging = ["bindgen/logging", "env_logger", "log"] static = ["bindgen/static"] runtime = ["bindgen/runtime"] # Dynamically discover a `rustfmt` binary using the `which` crate which-rustfmt = ["bindgen/which-rustfmt"] +prettyplease = ["bindgen/prettyplease"] diff --git a/bindgen-cli/options.rs b/bindgen-cli/options.rs index 1338269550..468ea1cc56 100644 --- a/bindgen-cli/options.rs +++ b/bindgen-cli/options.rs @@ -1,8 +1,8 @@ use bindgen::callbacks::TypeKind; use bindgen::{ builder, AliasVariation, Builder, CodegenConfig, EnumVariation, - FieldVisibilityKind, MacroTypeVariation, NonCopyUnionStyle, RegexSet, - RustTarget, DEFAULT_ANON_FIELDS_PREFIX, RUST_TARGET_STRINGS, + FieldVisibilityKind, Formatter, MacroTypeVariation, NonCopyUnionStyle, + RegexSet, RustTarget, DEFAULT_ANON_FIELDS_PREFIX, RUST_TARGET_STRINGS, }; use clap::Parser; use std::fs::File; @@ -269,8 +269,15 @@ struct BindgenCommand { /// Do not format the generated bindings with rustfmt. #[arg(long)] no_rustfmt_bindings: bool, - /// The absolute path to the rustfmt configuration file. The configuration file will be used for formatting the bindings. This parameter is incompatible with --no-rustfmt-bindings. - #[arg(long, value_name = "PATH", conflicts_with("no_rustfmt_bindings"))] + /// Which tool should be used to format the bindings + #[arg( + long, + value_name = "FORMATTER", + conflicts_with = "no_rustfmt_bindings" + )] + formatter: Option, + /// The absolute path to the rustfmt configuration file. The configuration file will be used for formatting the bindings. This parameter sets `formatter` to `rustfmt`. + #[arg(long, value_name = "PATH", conflicts_with = "no_rustfmt_bindings")] rustfmt_configuration_file: Option, /// Avoid deriving PartialEq for types matching . #[arg(long, value_name = "REGEX")] @@ -457,6 +464,7 @@ where no_record_matches, no_size_t_is_usize, no_rustfmt_bindings, + formatter, rustfmt_configuration_file, no_partialeq, no_copy, @@ -821,10 +829,15 @@ where builder = builder.size_t_is_usize(false); } + #[allow(deprecated)] if no_rustfmt_bindings { builder = builder.rustfmt_bindings(false); } + if let Some(formatter) = formatter { + builder = builder.formatter(formatter); + } + if let Some(path_str) = rustfmt_configuration_file { let path = PathBuf::from(path_str); diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs index 2620ce24f5..e03f7f9a79 100644 --- a/bindgen-integration/build.rs +++ b/bindgen-integration/build.rs @@ -4,7 +4,7 @@ extern crate cc; use bindgen::callbacks::{ DeriveInfo, IntKind, MacroParsingBehavior, ParseCallbacks, }; -use bindgen::{Builder, CargoCallbacks, EnumVariation}; +use bindgen::{Builder, CargoCallbacks, EnumVariation, Formatter}; use std::collections::HashSet; use std::env; use std::path::PathBuf; @@ -166,7 +166,7 @@ fn setup_macro_test() { let out_dep_file = out_path.join("test.d"); let bindings = Builder::default() - .rustfmt_bindings(false) + .formatter(Formatter::None) .enable_cxx_namespaces() .default_enum_style(EnumVariation::Rust { non_exhaustive: false, diff --git a/bindgen-tests/tests/tests.rs b/bindgen-tests/tests/tests.rs index ed8566c607..e27f29a6a6 100644 --- a/bindgen-tests/tests/tests.rs +++ b/bindgen-tests/tests/tests.rs @@ -383,7 +383,7 @@ fn create_bindgen_builder(header: &Path) -> Result { "bindgen", // We format in `compare_generated_header` ourselves to have a little // more control. - "--no-rustfmt-bindings", + "--formatter=none", "--with-derive-default", "--disable-header-comment", "--vtable-generation", diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index b6b7530fcc..ccc0d5b6ba 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -35,6 +35,7 @@ quote = { version = "1", default-features = false } syn = { version = "2.0", features = ["full", "extra-traits", "visit-mut"]} regex = { version = "1.5", default-features = false , features = ["std", "unicode"] } which = { version = "4.2.1", optional = true, default-features = false } +prettyplease = { version = "0.2.0", optional = true} shlex = "1" rustc-hash = "1.0.1" proc-macro2 = { version = "1", default-features = false } diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 9d89b089a5..673eacce94 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -88,6 +88,7 @@ use std::rc::Rc; type HashMap = ::rustc_hash::FxHashMap; type HashSet = ::rustc_hash::FxHashSet; pub(crate) use std::collections::hash_map::Entry; +use std::str::FromStr; /// Default prefix for the anon fields. pub const DEFAULT_ANON_FIELDS_PREFIX: &str = "__bindgen_anon_"; @@ -171,6 +172,39 @@ impl Default for CodegenConfig { } } +/// Formatting tools that can be used to format the bindings +#[derive(Debug, Clone, Copy)] +#[non_exhaustive] +pub enum Formatter { + /// Do not format the bindings. + None, + /// Use `rustfmt` to format the bindings. + Rustfmt, + #[cfg(feature = "prettyplease")] + /// Use `prettyplease` to format the bindings. + Prettyplease, +} + +impl Default for Formatter { + fn default() -> Self { + Self::Rustfmt + } +} + +impl FromStr for Formatter { + type Err = String; + + fn from_str(s: &str) -> Result { + match s { + "none" => Ok(Self::None), + "rustfmt" => Ok(Self::Rustfmt), + #[cfg(feature = "prettyplease")] + "prettyplease" => Ok(Self::Prettyplease), + _ => Err(format!("`{}` is not a valid formatter", s)), + } + } +} + /// Configure and generate Rust bindings for a C/C++ header. /// /// This is the main entry point to the library. @@ -344,7 +378,7 @@ impl Builder { rust_features, record_matches, size_t_is_usize, - rustfmt_bindings, + formatter, rustfmt_configuration_file, no_partialeq_types, no_copy_types, @@ -703,8 +737,13 @@ impl Builder { output_vector.push("--no-size_t-is-usize".into()); } - if !rustfmt_bindings { - output_vector.push("--no-rustfmt-bindings".into()); + match formatter { + Formatter::None => output_vector.push("--formatter=none".into()), + Formatter::Rustfmt => (), + #[cfg(feature = "prettyplease")] + Formatter::Prettyplease => { + output_vector.push("--formatter=prettyplease".into()) + } } if let Some(path) = @@ -1616,9 +1655,20 @@ impl Builder { self } + #[cfg_attr(feature = "prettyplease", deprecated)] /// Set whether rustfmt should format the generated bindings. pub fn rustfmt_bindings(mut self, doit: bool) -> Self { - self.options.rustfmt_bindings = doit; + self.options.formatter = if doit { + Formatter::Rustfmt + } else { + Formatter::None + }; + self + } + + /// Set which tool should be used to format the generated bindings. + pub fn formatter(mut self, formatter: Formatter) -> Self { + self.options.formatter = formatter; self } @@ -1631,7 +1681,7 @@ impl Builder { /// Set the absolute path to the rustfmt configuration file, if None, the standard rustfmt /// options are used. pub fn rustfmt_configuration_file(mut self, path: Option) -> Self { - self = self.rustfmt_bindings(true); + self = self.formatter(Formatter::Rustfmt); self.options.rustfmt_configuration_file = path; self } @@ -2224,8 +2274,8 @@ struct BindgenOptions { /// Whether `size_t` should be translated to `usize` automatically. size_t_is_usize: bool, - /// Whether rustfmt should format the generated bindings. - rustfmt_bindings: bool, + /// The tool that should be used to format the generated bindings. + formatter: Formatter, /// The absolute path to the rustfmt configuration file, if None, the standard rustfmt /// options are used. @@ -2408,7 +2458,6 @@ impl Default for BindgenOptions { detect_include_paths: true, prepend_enum_name: true, record_matches: true, - rustfmt_bindings: true, size_t_is_usize: true, --default-fields-- @@ -2471,6 +2520,7 @@ impl Default for BindgenOptions { block_extern_crate, fit_macro_constants, time_phases, + formatter, rustfmt_configuration_file, no_partialeq_types, no_copy_types, @@ -2835,18 +2885,16 @@ impl Bindings { writer.write_all("\n".as_bytes())?; } - let bindings = self.module.to_string(); - - match self.rustfmt_generated_string(&bindings) { - Ok(rustfmt_bindings) => { - writer.write_all(rustfmt_bindings.as_bytes())?; + match self.format_tokens(&self.module) { + Ok(formatted_bindings) => { + writer.write_all(formatted_bindings.as_bytes())?; } Err(err) => { eprintln!( "Failed to run rustfmt: {} (non-fatal, continuing)", err ); - writer.write_all(bindings.as_bytes())?; + writer.write_all(self.module.to_string().as_bytes())?; } } Ok(()) @@ -2854,7 +2902,7 @@ impl Bindings { /// Gets the rustfmt path to rustfmt the generated bindings. fn rustfmt_path(&self) -> io::Result> { - debug_assert!(self.options.rustfmt_bindings); + debug_assert!(matches!(self.options.formatter, Formatter::Rustfmt)); if let Some(ref p) = self.options.rustfmt_path { return Ok(Cow::Borrowed(p)); } @@ -2874,16 +2922,22 @@ impl Bindings { Ok(Cow::Owned("rustfmt".into())) } - /// Checks if rustfmt_bindings is set and runs rustfmt on the string - fn rustfmt_generated_string<'a>( + /// Formats a token stream with the formatter set up in `BindgenOptions`. + fn format_tokens( &self, - source: &'a str, - ) -> io::Result> { + tokens: &proc_macro2::TokenStream, + ) -> io::Result { let _t = time::Timer::new("rustfmt_generated_string") .with_output(self.options.time_phases); - if !self.options.rustfmt_bindings { - return Ok(Cow::Borrowed(source)); + match self.options.formatter { + Formatter::None => return Ok(tokens.to_string()), + + #[cfg(feature = "prettyplease")] + Formatter::Prettyplease => { + return Ok(prettyplease::unparse(&syn::parse_quote!(#tokens))); + } + Formatter::Rustfmt => (), } let rustfmt = self.rustfmt_path()?; @@ -2904,7 +2958,7 @@ impl Bindings { let mut child_stdin = child.stdin.take().unwrap(); let mut child_stdout = child.stdout.take().unwrap(); - let source = source.to_owned(); + let source = tokens.to_string(); // Write to stdin in a new thread, so that we can read from stdout on this // thread. This keeps the child from blocking on writing to its stdout which @@ -2925,21 +2979,21 @@ impl Bindings { match String::from_utf8(output) { Ok(bindings) => match status.code() { - Some(0) => Ok(Cow::Owned(bindings)), + Some(0) => Ok(bindings), Some(2) => Err(io::Error::new( io::ErrorKind::Other, "Rustfmt parsing errors.".to_string(), )), Some(3) => { warn!("Rustfmt could not format some lines."); - Ok(Cow::Owned(bindings)) + Ok(bindings) } _ => Err(io::Error::new( io::ErrorKind::Other, "Internal rustfmt error".to_string(), )), }, - _ => Ok(Cow::Owned(source)), + _ => Ok(source), } } diff --git a/book/src/code-formatting.md b/book/src/code-formatting.md index 9039984a16..2972a48b4f 100644 --- a/book/src/code-formatting.md +++ b/book/src/code-formatting.md @@ -67,3 +67,38 @@ fn main() { ``` These two methods also apply to any other toolchain available in your system. + +## Using `prettyplease` + +The [`prettyplease`](https://github.com/dtolnay/prettyplease) crate is a +minimal formatter for generated code. To format bindings using `prettyplease` +you have to invoke `bindgen` with either the `--formatter=prettyplease` flag or +the the `bindgen::Builder::formatter(bindgen::Formatter::Prettyplease)`. One of +its advantages is that `prettyplease` can be used in minimal environments where +the Rust toolchain is not installed. + +## How can I normalize `#[doc]` attributes? + +`bindgen` emits all the documentation using `#[doc]` attributes by default. If +you want to use the more user-friendly `///` syntax, you have two options: + +### Use `rustfmt` + +`rustfmt` can be configured to normalize documentation. To do so, you have to +create a `rustfmt.toml` file with the following contents: + +```toml +normalize_doc_attributes = true +``` + +Then, you have set up `bindgen` so it passes this file to `rustfmt`. Given that +the `normalize_doc_attributes` option is +[unstable](https://github.com/rust-lang/rustfmt/issues/3351), you also have to +set up bindgen to use a `nightly` release of `rustfmt`. + + +### Use `prettyplease` + +`prettyplease` normalizes documentation without any additional configuration. +Then you just have to tell `bindgen` to use `prettyplease` as the code +formatter. diff --git a/book/src/faq.md b/book/src/faq.md index 4ef29286fd..e82b4a446a 100644 --- a/book/src/faq.md +++ b/book/src/faq.md @@ -8,7 +8,6 @@ - [Does `bindgen` support the C++ Standard Template Library (STL)?](#does-bindgen-support-the-c-standard-template-library-stl) - [How to deal with bindgen generated padding fields?](#how-to-deal-with-bindgen-generated-padding-fields) - [How to generate bindings for a custom target?](#how-to-generate-bindings-for-a-custom-target) -- [How can I normalize `#[doc]` attributes?](#how-can-i-normalize-doc-attributes) @@ -116,19 +115,3 @@ $ bindgen -- --target=armv7a-none-eabi ``` If you are using `bindgen` as a library, you should call `builder.clang_arg("--target=armv7a-none-eabi")` on your `builder`. - -### How can I normalize `#[doc]` attributes? - -`bindgen` emits all the documentation using `#[doc]` attributes by default. If -you want to use the more user-friendly `///` syntax, you have to create a -`rustfmt.toml` file with the following contents: - -```toml -normalize_doc_attributes = true -``` - -Then, you have set up bindgen so it passes this file to `rustfmt`. Given that -the `normalize_doc_attributes` option is -[unstable](https://github.com/rust-lang/rustfmt/issues/3351), you also have to -set up bindgen to use a `nightly` release of `rustfmt`. Please check the [code -formatting](./code-formatting.md) section for further information. From 4d2986cdb0bb7ec6fc26be9309a225ee21248dca Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Thu, 23 Mar 2023 23:44:26 -0500 Subject: [PATCH 478/942] Rename `cli` feature to `__cli` (#2466) --- bindgen-cli/Cargo.toml | 2 +- bindgen-tests/Cargo.toml | 2 +- bindgen/Cargo.toml | 2 +- bindgen/callbacks.rs | 2 +- bindgen/lib.rs | 8 ++++---- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index fd56d546f5..cc00fddaa1 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -21,7 +21,7 @@ path = "main.rs" name = "bindgen" [dependencies] -bindgen = { path = "../bindgen", version = "=0.64.0", features = ["cli", "experimental"] } +bindgen = { path = "../bindgen", version = "=0.64.0", features = ["__cli", "experimental"] } shlex = "1" clap = { version = "4", features = ["derive"] } env_logger = { version = "0.10.0", optional = true } diff --git a/bindgen-tests/Cargo.toml b/bindgen-tests/Cargo.toml index ace5b3810a..3e529fb3d8 100644 --- a/bindgen-tests/Cargo.toml +++ b/bindgen-tests/Cargo.toml @@ -5,7 +5,7 @@ version = "0.1.0" publish = false [dev-dependencies] -bindgen = { path = "../bindgen", features = ["cli", "experimental"] } +bindgen = { path = "../bindgen", features = ["__cli", "experimental"] } diff = "0.1" shlex = "1" clap = { version = "4", features = ["derive"] } diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index ccc0d5b6ba..2b27f2a1fd 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -48,7 +48,7 @@ static = ["clang-sys/static"] runtime = ["clang-sys/runtime"] # Dynamically discover a `rustfmt` binary using the `which` crate which-rustfmt = ["which"] -cli = [] +__cli = [] experimental = [] # These features only exist for CI testing -- don't use them if you're not hacking diff --git a/bindgen/callbacks.rs b/bindgen/callbacks.rs index 92ed6f4e44..d85e565565 100644 --- a/bindgen/callbacks.rs +++ b/bindgen/callbacks.rs @@ -25,7 +25,7 @@ impl Default for MacroParsingBehavior { /// A trait to allow configuring different kinds of types in different /// situations. pub trait ParseCallbacks: fmt::Debug { - #[cfg(feature = "cli")] + #[cfg(feature = "__cli")] #[doc(hidden)] fn cli_args(&self) -> Vec { vec![] diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 673eacce94..e1f0a6606a 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -357,10 +357,10 @@ impl Builder { input_headers, // These cannot be added from the CLI. input_header_contents: _, - #[cfg(feature = "cli")] + #[cfg(feature = "__cli")] parse_callbacks, - // ParseCallbacks cannot represent CLI flags if the `"cli"` feature is disabled. - #[cfg(not(feature = "cli"))] + // ParseCallbacks cannot represent CLI flags if the `"__cli"` feature is disabled. + #[cfg(not(feature = "__cli"))] parse_callbacks: _, codegen_config, conservative_inline_namespaces, @@ -794,7 +794,7 @@ impl Builder { output_vector.push("--wrap-unsafe-ops".into()); } - #[cfg(feature = "cli")] + #[cfg(feature = "__cli")] for callbacks in parse_callbacks { output_vector.extend(callbacks.cli_args()); } From 2108a9ea2f4f69eba9b5170ca0877001ef733bc8 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Fri, 24 Mar 2023 12:43:29 -0500 Subject: [PATCH 479/942] Make clearer how to use `prettyplease` (#2468) --- CHANGELOG.md | 6 +++++- bindgen/lib.rs | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index daf5902057..96ecd945e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -164,9 +164,13 @@ ## Added * Added the `Bindgen::default_visibility` nethod and the `--default-visibility` flag to set the default visibility of fields. - * Added the `--formatter` flag with the values `none`, `rustfmt` and + * Added the `--formatter` CLI flag with the values `none`, `rustfmt` and `prettyplease` to select which tool will be used to format the bindings. The default value is `rustfmt`. + * Added the `Builder::formatter` method and the `Formatter` type to select + which tool will be used to format the bindings. The + `Formatter::Prettyplease` variant is only available if the + `"prettyplease"` feature is enabled. ## Changed * Static functions with no arguments use `void` as their single argument instead of having no arguments when the `--wrap-static-fns` flag is used. diff --git a/bindgen/lib.rs b/bindgen/lib.rs index e1f0a6606a..9b00c4b34b 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -1667,6 +1667,9 @@ impl Builder { } /// Set which tool should be used to format the generated bindings. + /// + /// To be able to choose `prettyplease` as a formatter, the `"prettyplease"` feature must be + /// enabled. pub fn formatter(mut self, formatter: Formatter) -> Self { self.options.formatter = formatter; self From c94367c8e9607d3b6d5cf80f0c589971dca40f7c Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Mon, 27 Mar 2023 09:22:49 -0500 Subject: [PATCH 480/942] Remove dangling debug (#2470) --- bindgen/ir/item.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindgen/ir/item.rs b/bindgen/ir/item.rs index 146aff1d88..9a1377e17f 100644 --- a/bindgen/ir/item.rs +++ b/bindgen/ir/item.rs @@ -1628,7 +1628,7 @@ impl Item { let comment = location .raw_comment() .or_else(|| decl.raw_comment()) - .or_else(|| dbg!(location.raw_comment())); + .or_else(|| location.raw_comment()); let annotations = Annotations::new(&decl).or_else(|| Annotations::new(&location)); From 040149b097b2c460a73ed27539112dc5104994ad Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Mon, 3 Apr 2023 10:51:24 -0500 Subject: [PATCH 481/942] Generate `BindgenOptions` and the `Builder` methods using macros (#2473) * Generate `BindgenOptions` and the `Builder` methods using macros This is done so the definition, default value and `Builder` methods for each field of `BindgenOptions` are kept in the same region of code. Before this change, adding (or modifying) a new option for `bindgen` required: - Updating the fields of the `BindgenOptions` type. - Updating the `Default` implementation for `BindgenOptions`. - Updating one or several `Builder` methods with proper documentation explaining the default value of the option. - Updating the `Builder::command_line_flags` method. Each one of these steps was done in a different place inside `bindgen/lib.rs`. With this change, all these 4 steps are done in the same place. This should make less likely to have bugs. Clearly using macros implies properly documenting how to use such macros and makes adding new options a bit harder because most (all?) editors are not able to format code and suggest completions inside macros. This change also moves all the code related to setting `BindgenOptions` to the new `bindgen/options.rs` file. * Factor out the "Regex are supported" docs. All the options that support regular expressions had the following sentence in their documentation: > Regular expressions are supported This comment was factored out to the macro that documents options based on `RegexSet`s. * Rename `fn_with_regex_arg` to `regex_option` * Allow optional commas in the `options` macro. This is done to avoid hard to detect macro parsing issues due to missing commas. * Fix typo * Add the `AsArg` trait. This trait eases the conversion of `BindgenOptions` fields into CLI args. This commit also changes the `options` macro so the flag can be passed to `as_args` instead of a closure. * Document the `option` macro * Document the `options` module * Rewrite some documentation * Run rustfmt * Avoid examples with `bool` parameters * More documentation changes * Reorganize the `options` module * Run rustfmt --- bindgen/codegen/mod.rs | 85 +- bindgen/lib.rs | 2433 +++--------------------------------- bindgen/options/as_args.rs | 52 + bindgen/options/helpers.rs | 46 + bindgen/options/mod.rs | 2104 +++++++++++++++++++++++++++++++ 5 files changed, 2441 insertions(+), 2279 deletions(-) create mode 100644 bindgen/options/as_args.rs create mode 100644 bindgen/options/helpers.rs create mode 100644 bindgen/options/mod.rs diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 8edde222c5..508c1ed892 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -57,7 +57,7 @@ use crate::{Entry, HashMap, HashSet}; use std::borrow::Cow; use std::cell::Cell; use std::collections::VecDeque; -use std::fmt::Write; +use std::fmt::{self, Write}; use std::ops; use std::str::FromStr; @@ -73,13 +73,13 @@ impl From for CodegenError { } } -impl std::fmt::Display for CodegenError { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl fmt::Display for CodegenError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - CodegenError::Serialize { msg, loc } => { + Self::Serialize { msg, loc } => { write!(f, "serialization error at {}: {}", loc, msg) } - CodegenError::Io(err) => err.fmt(f), + Self::Io(err) => err.fmt(f), } } } @@ -2736,6 +2736,35 @@ impl Default for EnumVariation { } } +impl fmt::Display for EnumVariation { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let s = match self { + Self::Rust { + non_exhaustive: false, + } => "rust", + Self::Rust { + non_exhaustive: true, + } => "rust_non_exhaustive", + Self::NewType { + is_bitfield: true, .. + } => "bitfield", + Self::NewType { + is_bitfield: false, + is_global, + } => { + if *is_global { + "newtype_global" + } else { + "newtype" + } + } + Self::Consts => "consts", + Self::ModuleConsts => "moduleconsts", + }; + s.fmt(f) + } +} + impl std::str::FromStr for EnumVariation { type Err = std::io::Error; @@ -3422,13 +3451,13 @@ pub enum MacroTypeVariation { Unsigned, } -impl MacroTypeVariation { - /// Convert a `MacroTypeVariation` to its str representation. - pub(crate) fn as_str(&self) -> &str { - match self { - MacroTypeVariation::Signed => "signed", - MacroTypeVariation::Unsigned => "unsigned", - } +impl fmt::Display for MacroTypeVariation { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let s = match self { + Self::Signed => "signed", + Self::Unsigned => "unsigned", + }; + s.fmt(f) } } @@ -3468,14 +3497,15 @@ pub enum AliasVariation { NewTypeDeref, } -impl AliasVariation { - /// Convert an `AliasVariation` to its str representation. - pub(crate) fn as_str(&self) -> &str { - match self { - AliasVariation::TypeAlias => "type_alias", - AliasVariation::NewType => "new_type", - AliasVariation::NewTypeDeref => "new_type_deref", - } +impl fmt::Display for AliasVariation { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let s = match self { + Self::TypeAlias => "type_alias", + Self::NewType => "new_type", + Self::NewTypeDeref => "new_type_deref", + }; + + s.fmt(f) } } @@ -3505,10 +3535,10 @@ impl std::str::FromStr for AliasVariation { } } -/// Enum for how non-Copy unions should be translated. +/// Enum for how non-`Copy` `union`s should be translated. #[derive(Copy, Clone, PartialEq, Eq, Debug)] pub enum NonCopyUnionStyle { - /// Wrap members in a type generated by bindgen. + /// Wrap members in a type generated by `bindgen`. BindgenWrapper, /// Wrap members in [`::core::mem::ManuallyDrop`]. /// @@ -3517,13 +3547,14 @@ pub enum NonCopyUnionStyle { ManuallyDrop, } -impl NonCopyUnionStyle { - /// Convert an `NonCopyUnionStyle` to its str representation. - pub(crate) fn as_str(&self) -> &'static str { - match self { +impl fmt::Display for NonCopyUnionStyle { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let s = match self { Self::BindgenWrapper => "bindgen_wrapper", Self::ManuallyDrop => "manually_drop", - } + }; + + s.fmt(f) } } diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 9b00c4b34b..2b1d68079a 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -34,20 +34,9 @@ mod log_stubs; #[macro_use] mod extra_assertions; -macro_rules! fn_with_regex_arg { - ($(#[$attrs:meta])* pub fn $($tokens:tt)*) => { - $(#[$attrs])* - /// Check the [regular expression arguments] section and the [regex] crate - /// documentation for further information. - /// - /// [regular expression arguments]: ./struct.Builder.html#regular-expression-arguments - /// [regex]: - pub fn $($tokens)* - }; -} - mod codegen; mod deps; +mod options; mod time; pub mod callbacks; @@ -58,40 +47,38 @@ mod ir; mod parse; mod regex_set; -use codegen::CodegenError; -use ir::comment; - -pub use ir::annotations::FieldVisibilityKind; - -pub use crate::codegen::{ +pub use codegen::{ AliasVariation, EnumVariation, MacroTypeVariation, NonCopyUnionStyle, }; -use crate::features::RustFeatures; -pub use crate::features::{ - RustTarget, LATEST_STABLE_RUST, RUST_TARGET_STRINGS, -}; -use crate::ir::context::{BindgenContext, ItemId}; -pub use crate::ir::function::Abi; -use crate::ir::item::Item; -use crate::parse::ParseError; -pub use crate::regex_set::RegexSet; +pub use features::{RustTarget, LATEST_STABLE_RUST, RUST_TARGET_STRINGS}; +pub use ir::annotations::FieldVisibilityKind; +pub use ir::function::Abi; +pub use regex_set::RegexSet; + +use codegen::CodegenError; +use features::RustFeatures; +use ir::comment; +use ir::context::{BindgenContext, ItemId}; +use ir::item::Item; +use options::BindgenOptions; +use parse::ParseError; use std::borrow::Cow; +use std::collections::hash_map::Entry; use std::env; use std::fs::{File, OpenOptions}; use std::io::{self, Write}; use std::path::{Path, PathBuf}; use std::process::{Command, Stdio}; -use std::rc::Rc; +use std::str::FromStr; // Some convenient typedefs for a fast hash map and hash set. -type HashMap = ::rustc_hash::FxHashMap; -type HashSet = ::rustc_hash::FxHashSet; -pub(crate) use std::collections::hash_map::Entry; -use std::str::FromStr; +type HashMap = rustc_hash::FxHashMap; +type HashSet = rustc_hash::FxHashSet; /// Default prefix for the anon fields. pub const DEFAULT_ANON_FIELDS_PREFIX: &str = "__bindgen_anon_"; + const DEFAULT_NON_EXTERN_FNS_SUFFIX: &str = "__extern"; fn file_is_cpp(name_file: &str) -> bool { @@ -173,7 +160,7 @@ impl Default for CodegenConfig { } /// Formatting tools that can be used to format the bindings -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[non_exhaustive] pub enum Formatter { /// Do not format the bindings. @@ -205,6 +192,19 @@ impl FromStr for Formatter { } } +impl std::fmt::Display for Formatter { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let s = match self { + Self::None => "none", + Self::Rustfmt => "rustfmt", + #[cfg(feature = "prettyplease")] + Self::Prettyplease => "prettyplease", + }; + + s.fmt(f) + } +} + /// Configure and generate Rust bindings for a C/C++ header. /// /// This is the main entry point to the library. @@ -291,2138 +291,186 @@ fn get_extra_clang_args() -> Vec { } impl Builder { - /// Generates the command line flags use for creating `Builder`. - pub fn command_line_flags(&self) -> Vec { - let mut output_vector: Vec = Vec::new(); - - // We should not forget to use any new options that can be represented as CLI flags. - #[deny(unused_variables)] - let BindgenOptions { - blocklisted_types, - blocklisted_functions, - blocklisted_items, - blocklisted_files, - opaque_types, - // The rustfmt path cannot be set from the CLI. - rustfmt_path: _, - depfile, - allowlisted_types, - allowlisted_functions, - allowlisted_vars, - allowlisted_files, - default_enum_style, - bitfield_enums, - newtype_enums, - newtype_global_enums, - rustified_enums, - rustified_non_exhaustive_enums, - constified_enum_modules, - constified_enums, - default_macro_constant_type, - default_alias_style, - type_alias, - new_type_alias, - new_type_alias_deref, - default_non_copy_union_style, - bindgen_wrapper_union, - manually_drop_union, - builtins, - emit_ast, - emit_ir, - emit_ir_graphviz, - enable_cxx_namespaces, - enable_function_attribute_detection, - disable_name_namespacing, - disable_nested_struct_naming, - disable_header_comment, - layout_tests, - impl_debug, - impl_partialeq, - derive_copy, - derive_debug, - derive_default, - derive_hash, - derive_partialord, - derive_ord, - derive_partialeq, - derive_eq, - use_core, - ctypes_prefix, - anon_fields_prefix, - time_phases, - convert_floats, - raw_lines, - module_lines, - clang_args, - input_headers, - // These cannot be added from the CLI. - input_header_contents: _, - #[cfg(feature = "__cli")] - parse_callbacks, - // ParseCallbacks cannot represent CLI flags if the `"__cli"` feature is disabled. - #[cfg(not(feature = "__cli"))] - parse_callbacks: _, - codegen_config, - conservative_inline_namespaces, - generate_comments, - generate_inline_functions, - allowlist_recursively, - objc_extern_crate, - generate_block, - block_extern_crate, - enable_mangling, - detect_include_paths, - fit_macro_constants, - prepend_enum_name, - rust_target, - rust_features, - record_matches, - size_t_is_usize, - formatter, - rustfmt_configuration_file, - no_partialeq_types, - no_copy_types, - no_debug_types, - no_default_types, - no_hash_types, - must_use_types, - array_pointers_in_arguments, - wasm_import_module_name, - dynamic_library_name, - dynamic_link_require_all, - respect_cxx_access_specs, - translate_enum_integer_types, - c_naming, - force_explicit_padding, - vtable_generation, - sort_semantically, - merge_extern_blocks, - abi_overrides, - wrap_unsafe_ops, - wrap_static_fns, - wrap_static_fns_suffix, - wrap_static_fns_path, - default_visibility, - } = &self.options; - - if let Some(header) = input_headers.last().cloned() { - // Positional argument 'header' - output_vector.push(header); - } - - if let Some(depfile) = depfile { - output_vector.push("--depfile".into()); - output_vector.push(depfile.depfile_path.display().to_string()); - } - - output_vector.push("--rust-target".into()); - output_vector.push((*rust_target).into()); - - // FIXME(emilio): This is a bit hacky, maybe we should stop re-using the - // RustFeatures to store the "disable_untagged_union" call, and make it - // a different flag that we check elsewhere / in generate(). - if !rust_features.untagged_union && - RustFeatures::from(*rust_target).untagged_union - { - output_vector.push("--disable-untagged-union".into()); - } - - if *default_enum_style != Default::default() { - output_vector.push("--default-enum-style".into()); - output_vector.push( - match default_enum_style { - codegen::EnumVariation::Rust { - non_exhaustive: false, - } => "rust", - codegen::EnumVariation::Rust { - non_exhaustive: true, - } => "rust_non_exhaustive", - codegen::EnumVariation::NewType { - is_bitfield: true, - .. - } => "bitfield", - codegen::EnumVariation::NewType { - is_bitfield: false, - is_global, - } => { - if *is_global { - "newtype_global" - } else { - "newtype" - } - } - codegen::EnumVariation::Consts => "consts", - codegen::EnumVariation::ModuleConsts => "moduleconsts", - } - .into(), - ) - } - - if *default_macro_constant_type != Default::default() { - output_vector.push("--default-macro-constant-type".into()); - output_vector.push(default_macro_constant_type.as_str().into()); - } + /// Generate the Rust bindings using the options built up thus far. + pub fn generate(mut self) -> Result { + // Add any extra arguments from the environment to the clang command line. + self.options.clang_args.extend(get_extra_clang_args()); - if *default_alias_style != Default::default() { - output_vector.push("--default-alias-style".into()); - output_vector.push(default_alias_style.as_str().into()); - } + // Transform input headers to arguments on the clang command line. + self.options.clang_args.extend( + self.options.input_headers + [..self.options.input_headers.len().saturating_sub(1)] + .iter() + .flat_map(|header| ["-include".into(), header.to_string()]), + ); - if *default_non_copy_union_style != Default::default() { - output_vector.push("--default-non-copy-union-style".into()); - output_vector.push(default_non_copy_union_style.as_str().into()); - } + let input_unsaved_files = + std::mem::take(&mut self.options.input_header_contents) + .into_iter() + .map(|(name, contents)| clang::UnsavedFile::new(name, contents)) + .collect::>(); - let regex_sets = &[ - (bitfield_enums, "--bitfield-enum"), - (newtype_enums, "--newtype-enum"), - (newtype_global_enums, "--newtype-global-enum"), - (rustified_enums, "--rustified-enum"), - ( - rustified_non_exhaustive_enums, - "--rustified-enum-non-exhaustive", - ), - (constified_enum_modules, "--constified-enum-module"), - (constified_enums, "--constified-enum"), - (type_alias, "--type-alias"), - (new_type_alias, "--new-type-alias"), - (new_type_alias_deref, "--new-type-alias-deref"), - (bindgen_wrapper_union, "--bindgen-wrapper-union"), - (manually_drop_union, "--manually-drop-union"), - (blocklisted_types, "--blocklist-type"), - (blocklisted_functions, "--blocklist-function"), - (blocklisted_items, "--blocklist-item"), - (blocklisted_files, "--blocklist-file"), - (opaque_types, "--opaque-type"), - (allowlisted_functions, "--allowlist-function"), - (allowlisted_types, "--allowlist-type"), - (allowlisted_vars, "--allowlist-var"), - (allowlisted_files, "--allowlist-file"), - (no_partialeq_types, "--no-partialeq"), - (no_copy_types, "--no-copy"), - (no_debug_types, "--no-debug"), - (no_default_types, "--no-default"), - (no_hash_types, "--no-hash"), - (must_use_types, "--must-use-type"), - ]; + Bindings::generate(self.options, input_unsaved_files) + } - for (set, flag) in regex_sets { - for item in set.get_items() { - output_vector.push((*flag).to_owned()); - output_vector.push(item.to_owned()); - } - } + /// Preprocess and dump the input header files to disk. + /// + /// This is useful when debugging bindgen, using C-Reduce, or when filing + /// issues. The resulting file will be named something like `__bindgen.i` or + /// `__bindgen.ii` + pub fn dump_preprocessed_input(&self) -> io::Result<()> { + let clang = + clang_sys::support::Clang::find(None, &[]).ok_or_else(|| { + io::Error::new( + io::ErrorKind::Other, + "Cannot find clang executable", + ) + })?; - for (abi, set) in abi_overrides { - for item in set.get_items() { - output_vector.push("--override-abi".to_owned()); - output_vector.push(format!("{}={}", item, abi)); - } - } + // The contents of a wrapper file that includes all the input header + // files. + let mut wrapper_contents = String::new(); - if !layout_tests { - output_vector.push("--no-layout-tests".into()); - } + // Whether we are working with C or C++ inputs. + let mut is_cpp = args_are_cpp(&self.options.clang_args); - if *impl_debug { - output_vector.push("--impl-debug".into()); - } + // For each input header, add `#include "$header"`. + for header in &self.options.input_headers { + is_cpp |= file_is_cpp(header); - if *impl_partialeq { - output_vector.push("--impl-partialeq".into()); + wrapper_contents.push_str("#include \""); + wrapper_contents.push_str(header); + wrapper_contents.push_str("\"\n"); } - if !derive_copy { - output_vector.push("--no-derive-copy".into()); - } + // For each input header content, add a prefix line of `#line 0 "$name"` + // followed by the contents. + for (name, contents) in &self.options.input_header_contents { + is_cpp |= file_is_cpp(name); - if !derive_debug { - output_vector.push("--no-derive-debug".into()); + wrapper_contents.push_str("#line 0 \""); + wrapper_contents.push_str(name); + wrapper_contents.push_str("\"\n"); + wrapper_contents.push_str(contents); } - if !derive_default { - output_vector.push("--no-derive-default".into()); + let wrapper_path = PathBuf::from(if is_cpp { + "__bindgen.cpp" } else { - output_vector.push("--with-derive-default".into()); - } - - if *derive_hash { - output_vector.push("--with-derive-hash".into()); - } - - if *derive_partialord { - output_vector.push("--with-derive-partialord".into()); - } - - if *derive_ord { - output_vector.push("--with-derive-ord".into()); - } - - if *derive_partialeq { - output_vector.push("--with-derive-partialeq".into()); - } - - if *derive_eq { - output_vector.push("--with-derive-eq".into()); - } - - if *time_phases { - output_vector.push("--time-phases".into()); - } - - if !generate_comments { - output_vector.push("--no-doc-comments".into()); - } - - if !allowlist_recursively { - output_vector.push("--no-recursive-allowlist".into()); - } - - if *objc_extern_crate { - output_vector.push("--objc-extern-crate".into()); - } - - if *generate_block { - output_vector.push("--generate-block".into()); - } - - if *block_extern_crate { - output_vector.push("--block-extern-crate".into()); - } - - if !enable_mangling { - output_vector.push("--distrust-clang-mangling".into()); - } - - if !detect_include_paths { - output_vector.push("--no-include-path-detection".into()); - } - - if *builtins { - output_vector.push("--builtins".into()); - } - - if let Some(prefix) = ctypes_prefix { - output_vector.push("--ctypes-prefix".into()); - output_vector.push(prefix.clone()); - } - - if *anon_fields_prefix != DEFAULT_ANON_FIELDS_PREFIX { - output_vector.push("--anon-fields-prefix".into()); - output_vector.push(anon_fields_prefix.clone()); - } - - if *emit_ast { - output_vector.push("--emit-clang-ast".into()); - } - - if *emit_ir { - output_vector.push("--emit-ir".into()); - } - - if let Some(graph) = emit_ir_graphviz { - output_vector.push("--emit-ir-graphviz".into()); - output_vector.push(graph.clone()) - } - - if *enable_cxx_namespaces { - output_vector.push("--enable-cxx-namespaces".into()); - } - - if *enable_function_attribute_detection { - output_vector.push("--enable-function-attribute-detection".into()); - } - - if *disable_name_namespacing { - output_vector.push("--disable-name-namespacing".into()); - } - - if *disable_nested_struct_naming { - output_vector.push("--disable-nested-struct-naming".into()); - } - - if *disable_header_comment { - output_vector.push("--disable-header-comment".into()); - } + "__bindgen.c" + }); - if !codegen_config.functions() { - output_vector.push("--ignore-functions".into()); + { + let mut wrapper_file = File::create(&wrapper_path)?; + wrapper_file.write_all(wrapper_contents.as_bytes())?; } - output_vector.push("--generate".into()); - - //Temporary placeholder for below 4 options - let mut options: Vec = Vec::new(); - if codegen_config.functions() { - options.push("functions".into()); - } + let mut cmd = Command::new(clang.path); + cmd.arg("-save-temps") + .arg("-E") + .arg("-C") + .arg("-c") + .arg(&wrapper_path) + .stdout(Stdio::piped()); - if codegen_config.types() { - options.push("types".into()); + for a in &self.options.clang_args { + cmd.arg(a); } - if codegen_config.vars() { - options.push("vars".into()); + for a in get_extra_clang_args() { + cmd.arg(a); } - if codegen_config.methods() { - options.push("methods".into()); - } + let mut child = cmd.spawn()?; - if codegen_config.constructors() { - options.push("constructors".into()); - } + let mut preprocessed = child.stdout.take().unwrap(); + let mut file = File::create(if is_cpp { + "__bindgen.ii" + } else { + "__bindgen.i" + })?; + io::copy(&mut preprocessed, &mut file)?; - if codegen_config.destructors() { - options.push("destructors".into()); + if child.wait()?.success() { + Ok(()) + } else { + Err(io::Error::new( + io::ErrorKind::Other, + "clang exited with non-zero status", + )) } + } +} - output_vector.push(options.join(",")); - - if !codegen_config.methods() { - output_vector.push("--ignore-methods".into()); +impl BindgenOptions { + fn build(&mut self) { + let regex_sets = [ + &mut self.allowlisted_vars, + &mut self.allowlisted_types, + &mut self.allowlisted_functions, + &mut self.allowlisted_files, + &mut self.blocklisted_types, + &mut self.blocklisted_functions, + &mut self.blocklisted_items, + &mut self.blocklisted_files, + &mut self.opaque_types, + &mut self.bitfield_enums, + &mut self.constified_enums, + &mut self.constified_enum_modules, + &mut self.newtype_enums, + &mut self.newtype_global_enums, + &mut self.rustified_enums, + &mut self.rustified_non_exhaustive_enums, + &mut self.type_alias, + &mut self.new_type_alias, + &mut self.new_type_alias_deref, + &mut self.bindgen_wrapper_union, + &mut self.manually_drop_union, + &mut self.no_partialeq_types, + &mut self.no_copy_types, + &mut self.no_debug_types, + &mut self.no_default_types, + &mut self.no_hash_types, + &mut self.must_use_types, + ]; + let record_matches = self.record_matches; + for regex_set in self.abi_overrides.values_mut().chain(regex_sets) { + regex_set.build(record_matches); } + } - if !convert_floats { - output_vector.push("--no-convert-floats".into()); - } + /// Update rust target version + pub fn set_rust_target(&mut self, rust_target: RustTarget) { + self.rust_target = rust_target; - if !prepend_enum_name { - output_vector.push("--no-prepend-enum-name".into()); - } + // Keep rust_features synced with rust_target + self.rust_features = rust_target.into(); + } - if *fit_macro_constants { - output_vector.push("--fit-macro-constant-types".into()); - } + /// Get features supported by target Rust version + pub fn rust_features(&self) -> RustFeatures { + self.rust_features + } - if *array_pointers_in_arguments { - output_vector.push("--use-array-pointers-in-arguments".into()); - } + fn last_callback( + &self, + f: impl Fn(&dyn callbacks::ParseCallbacks) -> Option, + ) -> Option { + self.parse_callbacks + .iter() + .filter_map(|cb| f(cb.as_ref())) + .last() + } - if let Some(ref wasm_import_module_name) = wasm_import_module_name { - output_vector.push("--wasm-import-module-name".into()); - output_vector.push(wasm_import_module_name.clone()); - } - - for line in raw_lines { - output_vector.push("--raw-line".into()); - output_vector.push(line.clone()); - } - - for (module, lines) in module_lines { - for line in lines.iter() { - output_vector.push("--module-raw-line".into()); - output_vector.push(module.clone()); - output_vector.push(line.clone()); - } - } - - if *use_core { - output_vector.push("--use-core".into()); - } - - if *conservative_inline_namespaces { - output_vector.push("--conservative-inline-namespaces".into()); - } - - if *generate_inline_functions { - output_vector.push("--generate-inline-functions".into()); - } - - if !record_matches { - output_vector.push("--no-record-matches".into()); - } - - if !size_t_is_usize { - output_vector.push("--no-size_t-is-usize".into()); - } - - match formatter { - Formatter::None => output_vector.push("--formatter=none".into()), - Formatter::Rustfmt => (), - #[cfg(feature = "prettyplease")] - Formatter::Prettyplease => { - output_vector.push("--formatter=prettyplease".into()) - } - } - - if let Some(path) = - rustfmt_configuration_file.as_ref().and_then(|f| f.to_str()) - { - output_vector.push("--rustfmt-configuration-file".into()); - output_vector.push(path.into()); - } - - if let Some(ref name) = dynamic_library_name { - output_vector.push("--dynamic-loading".into()); - output_vector.push(name.clone()); - } - - if *dynamic_link_require_all { - output_vector.push("--dynamic-link-require-all".into()); - } - - if *respect_cxx_access_specs { - output_vector.push("--respect-cxx-access-specs".into()); - } - - if *translate_enum_integer_types { - output_vector.push("--translate-enum-integer-types".into()); - } - - if *c_naming { - output_vector.push("--c-naming".into()); - } - - if *force_explicit_padding { - output_vector.push("--explicit-padding".into()); - } - - if *vtable_generation { - output_vector.push("--vtable-generation".into()); - } - - if *sort_semantically { - output_vector.push("--sort-semantically".into()); - } - - if *merge_extern_blocks { - output_vector.push("--merge-extern-blocks".into()); - } - - if *wrap_unsafe_ops { - output_vector.push("--wrap-unsafe-ops".into()); - } - - #[cfg(feature = "__cli")] - for callbacks in parse_callbacks { - output_vector.extend(callbacks.cli_args()); - } - - if *wrap_static_fns { - output_vector.push("--wrap-static-fns".into()) - } - - if let Some(path) = wrap_static_fns_path { - output_vector.push("--wrap-static-fns-path".into()); - output_vector.push(path.display().to_string()); - } - - if let Some(suffix) = wrap_static_fns_suffix { - output_vector.push("--wrap-static-fns-suffix".into()); - output_vector.push(suffix.clone()); - } - - if *default_visibility != FieldVisibilityKind::Public { - output_vector.push("--default-visibility".into()); - output_vector.push(default_visibility.to_string()); - } - - if cfg!(feature = "experimental") { - output_vector.push("--experimental".into()); - } - - // Add clang arguments - - output_vector.push("--".into()); - - if !clang_args.is_empty() { - output_vector.extend(clang_args.iter().cloned()); - } - - // To pass more than one header, we need to pass all but the last - // header via the `-include` clang arg - for header in &input_headers[..input_headers.len().saturating_sub(1)] { - output_vector.push("-include".to_string()); - output_vector.push(header.clone()); - } - - output_vector - } - - /// Add an input C/C++ header to generate bindings for. - /// - /// This can be used to generate bindings to a single header: - /// - /// ```ignore - /// let bindings = bindgen::Builder::default() - /// .header("input.h") - /// .generate() - /// .unwrap(); - /// ``` - /// - /// Or you can invoke it multiple times to generate bindings to multiple - /// headers: - /// - /// ```ignore - /// let bindings = bindgen::Builder::default() - /// .header("first.h") - /// .header("second.h") - /// .header("third.h") - /// .generate() - /// .unwrap(); - /// ``` - pub fn header>(mut self, header: T) -> Builder { - self.options.input_headers.push(header.into()); - self - } - - /// Add a depfile output which will be written alongside the generated bindings. - pub fn depfile, D: Into>( - mut self, - output_module: H, - depfile: D, - ) -> Builder { - self.options.depfile = Some(deps::DepfileSpec { - output_module: output_module.into(), - depfile_path: depfile.into(), - }); - self - } - - /// Add `contents` as an input C/C++ header named `name`. - /// - /// The file `name` will be added to the clang arguments. - pub fn header_contents(mut self, name: &str, contents: &str) -> Builder { - // Apparently clang relies on having virtual FS correspondent to - // the real one, so we need absolute paths here - let absolute_path = env::current_dir() - .expect("Cannot retrieve current directory") - .join(name) - .to_str() - .expect("Cannot convert current directory name to string") - .to_owned(); - self.options - .input_header_contents - .push((absolute_path, contents.into())); - self - } - - /// Specify the rust target - /// - /// The default is the latest stable Rust version - pub fn rust_target(mut self, rust_target: RustTarget) -> Self { - #[allow(deprecated)] - if rust_target <= RustTarget::Stable_1_30 { - warn!( - "The {} rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues", - String::from(rust_target) - ); - } - self.options.set_rust_target(rust_target); - self - } - - /// Disable support for native Rust unions, if supported. - pub fn disable_untagged_union(mut self) -> Self { - self.options.rust_features.untagged_union = false; - self - } - - /// Disable insertion of bindgen's version identifier into generated - /// bindings. - pub fn disable_header_comment(mut self) -> Self { - self.options.disable_header_comment = true; - self - } - - /// Set the output graphviz file. - pub fn emit_ir_graphviz>(mut self, path: T) -> Builder { - let path = path.into(); - self.options.emit_ir_graphviz = Some(path); - self - } - - /// Whether the generated bindings should contain documentation comments - /// (docstrings) or not. This is set to true by default. - /// - /// Note that clang by default excludes comments from system headers, pass - /// `-fretain-comments-from-system-headers` as - /// [`clang_arg`][Builder::clang_arg] to include them. It can also be told - /// to process all comments (not just documentation ones) using the - /// `-fparse-all-comments` flag. See [slides on clang comment parsing]( - /// https://llvm.org/devmtg/2012-11/Gribenko_CommentParsing.pdf) for - /// background and examples. - pub fn generate_comments(mut self, doit: bool) -> Self { - self.options.generate_comments = doit; - self - } - - /// Whether to allowlist recursively or not. Defaults to true. - /// - /// Given that we have explicitly allowlisted the "initiate_dance_party" - /// function in this C header: - /// - /// ```c - /// typedef struct MoonBoots { - /// int bouncy_level; - /// } MoonBoots; - /// - /// void initiate_dance_party(MoonBoots* boots); - /// ``` - /// - /// We would normally generate bindings to both the `initiate_dance_party` - /// function and the `MoonBoots` struct that it transitively references. By - /// configuring with `allowlist_recursively(false)`, `bindgen` will not emit - /// bindings for anything except the explicitly allowlisted items, and there - /// would be no emitted struct definition for `MoonBoots`. However, the - /// `initiate_dance_party` function would still reference `MoonBoots`! - /// - /// **Disabling this feature will almost certainly cause `bindgen` to emit - /// bindings that will not compile!** If you disable this feature, then it - /// is *your* responsibility to provide definitions for every type that is - /// referenced from an explicitly allowlisted item. One way to provide the - /// definitions is by using the [`Builder::raw_line`](#method.raw_line) - /// method, another would be to define them in Rust and then `include!(...)` - /// the bindings immediately afterwards. - pub fn allowlist_recursively(mut self, doit: bool) -> Self { - self.options.allowlist_recursively = doit; - self - } - - /// Generate `#[macro_use] extern crate objc;` instead of `use objc;` - /// in the prologue of the files generated from objective-c files - pub fn objc_extern_crate(mut self, doit: bool) -> Self { - self.options.objc_extern_crate = doit; - self - } - - /// Generate proper block signatures instead of void pointers. - pub fn generate_block(mut self, doit: bool) -> Self { - self.options.generate_block = doit; - self - } - - /// Generate `#[macro_use] extern crate block;` instead of `use block;` - /// in the prologue of the files generated from apple block files - pub fn block_extern_crate(mut self, doit: bool) -> Self { - self.options.block_extern_crate = doit; - self - } - - /// Whether to use the clang-provided name mangling. This is true by default - /// and probably needed for C++ features. - /// - /// However, some old libclang versions seem to return incorrect results in - /// some cases for non-mangled functions, see [1], so we allow disabling it. - /// - /// [1]: https://github.com/rust-lang/rust-bindgen/issues/528 - pub fn trust_clang_mangling(mut self, doit: bool) -> Self { - self.options.enable_mangling = doit; - self - } - - fn_with_regex_arg! { - /// Hide the given type from the generated bindings. Regular expressions are - /// supported. - /// - /// To blocklist types prefixed with "mylib" use `"mylib_.*"`. - pub fn blocklist_type>(mut self, arg: T) -> Builder { - self.options.blocklisted_types.insert(arg); - self - } - } - - fn_with_regex_arg! { - /// Hide the given function from the generated bindings. Regular expressions - /// are supported. - /// - /// Methods can be blocklisted by prefixing the name of the type implementing - /// them followed by an underscore. So if `Foo` has a method `bar`, it can - /// be blocklisted as `Foo_bar`. - /// - /// To blocklist functions prefixed with "mylib" use `"mylib_.*"`. - pub fn blocklist_function>(mut self, arg: T) -> Builder { - self.options.blocklisted_functions.insert(arg); - self - } - } - - fn_with_regex_arg! { - /// Hide the given item from the generated bindings, regardless of - /// whether it's a type, function, module, etc. Regular - /// expressions are supported. - /// - /// To blocklist items prefixed with "mylib" use `"mylib_.*"`. - pub fn blocklist_item>(mut self, arg: T) -> Builder { - self.options.blocklisted_items.insert(arg); - self - } - } - - fn_with_regex_arg! { - /// Hide any contents of the given file from the generated bindings, - /// regardless of whether it's a type, function, module etc. - pub fn blocklist_file>(mut self, arg: T) -> Builder { - self.options.blocklisted_files.insert(arg); - self - } - } - - fn_with_regex_arg! { - /// Treat the given type as opaque in the generated bindings. Regular - /// expressions are supported. - /// - /// To change types prefixed with "mylib" into opaque, use `"mylib_.*"`. - pub fn opaque_type>(mut self, arg: T) -> Builder { - self.options.opaque_types.insert(arg); - self - } - } - - fn_with_regex_arg! { - /// Allowlist the given type so that it (and all types that it transitively - /// refers to) appears in the generated bindings. Regular expressions are - /// supported. - /// - /// To allowlist types prefixed with "mylib" use `"mylib_.*"`. - pub fn allowlist_type>(mut self, arg: T) -> Builder { - self.options.allowlisted_types.insert(arg); - self - } - } - - fn_with_regex_arg! { - /// Allowlist the given function so that it (and all types that it - /// transitively refers to) appears in the generated bindings. Regular - /// expressions are supported. - /// - /// Methods can be allowlisted by prefixing the name of the type - /// implementing them followed by an underscore. So if `Foo` has a method - /// `bar`, it can be allowlisted as `Foo_bar`. - /// - /// To allowlist functions prefixed with "mylib" use `"mylib_.*"`. - pub fn allowlist_function>(mut self, arg: T) -> Builder { - self.options.allowlisted_functions.insert(arg); - self - } - } - - fn_with_regex_arg! { - /// Allowlist the given variable so that it (and all types that it - /// transitively refers to) appears in the generated bindings. Regular - /// expressions are supported. - /// - /// To allowlist variables prefixed with "mylib" use `"mylib_.*"`. - pub fn allowlist_var>(mut self, arg: T) -> Builder { - self.options.allowlisted_vars.insert(arg); - self - } - } - - fn_with_regex_arg! { - /// Allowlist the given file so that its contents appear in the generated bindings. - pub fn allowlist_file>(mut self, arg: T) -> Builder { - self.options.allowlisted_files.insert(arg); - self - } - } - - /// Set the default style of code to generate for enums - pub fn default_enum_style( - mut self, - arg: codegen::EnumVariation, - ) -> Builder { - self.options.default_enum_style = arg; - self - } - - fn_with_regex_arg! { - /// Mark the given enum (or set of enums, if using a pattern) as being - /// bitfield-like. Regular expressions are supported. - /// - /// This makes bindgen generate a type that isn't a rust `enum`. Regular - /// expressions are supported. - /// - /// This is similar to the newtype enum style, but with the bitwise - /// operators implemented. - pub fn bitfield_enum>(mut self, arg: T) -> Builder { - self.options.bitfield_enums.insert(arg); - self - } - } - - fn_with_regex_arg! { - /// Mark the given enum (or set of enums, if using a pattern) as a newtype. - /// Regular expressions are supported. - /// - /// This makes bindgen generate a type that isn't a Rust `enum`. Regular - /// expressions are supported. - pub fn newtype_enum>(mut self, arg: T) -> Builder { - self.options.newtype_enums.insert(arg); - self - } - } - - fn_with_regex_arg! { - /// Mark the given enum (or set of enums, if using a pattern) as a newtype - /// whose variants are exposed as global constants. - /// - /// Regular expressions are supported. - /// - /// This makes bindgen generate a type that isn't a Rust `enum`. Regular - /// expressions are supported. - pub fn newtype_global_enum>(mut self, arg: T) -> Builder { - self.options.newtype_global_enums.insert(arg); - self - } - } - - fn_with_regex_arg! { - /// Mark the given enum (or set of enums, if using a pattern) as a Rust - /// enum. - /// - /// This makes bindgen generate enums instead of constants. Regular - /// expressions are supported. - /// - /// **Use this with caution**, creating this in unsafe code - /// (including FFI) with an invalid value will invoke undefined behaviour. - /// You may want to use the newtype enum style instead. - pub fn rustified_enum>(mut self, arg: T) -> Builder { - self.options.rustified_enums.insert(arg); - self - } - } - - fn_with_regex_arg! { - /// Mark the given enum (or set of enums, if using a pattern) as a Rust - /// enum with the `#[non_exhaustive]` attribute. - /// - /// This makes bindgen generate enums instead of constants. Regular - /// expressions are supported. - /// - /// **Use this with caution**, creating this in unsafe code - /// (including FFI) with an invalid value will invoke undefined behaviour. - /// You may want to use the newtype enum style instead. - pub fn rustified_non_exhaustive_enum>( - mut self, - arg: T, - ) -> Builder { - self.options.rustified_non_exhaustive_enums.insert(arg); - self - } - } - - fn_with_regex_arg! { - /// Mark the given enum (or set of enums, if using a pattern) as a set of - /// constants that are not to be put into a module. - pub fn constified_enum>(mut self, arg: T) -> Builder { - self.options.constified_enums.insert(arg); - self - } - } - - fn_with_regex_arg! { - /// Mark the given enum (or set of enums, if using a pattern) as a set of - /// constants that should be put into a module. - /// - /// This makes bindgen generate modules containing constants instead of - /// just constants. Regular expressions are supported. - pub fn constified_enum_module>(mut self, arg: T) -> Builder { - self.options.constified_enum_modules.insert(arg); - self - } - } - - /// Set the default type for macro constants - pub fn default_macro_constant_type( - mut self, - arg: codegen::MacroTypeVariation, - ) -> Builder { - self.options.default_macro_constant_type = arg; - self - } - - /// Set the default style of code to generate for typedefs - pub fn default_alias_style( - mut self, - arg: codegen::AliasVariation, - ) -> Builder { - self.options.default_alias_style = arg; - self - } - - fn_with_regex_arg! { - /// Mark the given typedef alias (or set of aliases, if using a pattern) to - /// use regular Rust type aliasing. - /// - /// This is the default behavior and should be used if `default_alias_style` - /// was set to NewType or NewTypeDeref and you want to override it for a - /// set of typedefs. - pub fn type_alias>(mut self, arg: T) -> Builder { - self.options.type_alias.insert(arg); - self - } - } - - fn_with_regex_arg! { - /// Mark the given typedef alias (or set of aliases, if using a pattern) to - /// be generated as a new type by having the aliased type be wrapped in a - /// #[repr(transparent)] struct. - /// - /// Used to enforce stricter type checking. - pub fn new_type_alias>(mut self, arg: T) -> Builder { - self.options.new_type_alias.insert(arg); - self - } - } - - fn_with_regex_arg! { - /// Mark the given typedef alias (or set of aliases, if using a pattern) to - /// be generated as a new type by having the aliased type be wrapped in a - /// #[repr(transparent)] struct and also have an automatically generated - /// impl's of `Deref` and `DerefMut` to their aliased type. - pub fn new_type_alias_deref>(mut self, arg: T) -> Builder { - self.options.new_type_alias_deref.insert(arg); - self - } - } - - /// Set the default style of code to generate for unions with a non-Copy member. - pub fn default_non_copy_union_style( - mut self, - arg: codegen::NonCopyUnionStyle, - ) -> Self { - self.options.default_non_copy_union_style = arg; - self - } - - fn_with_regex_arg! { - /// Mark the given union (or set of union, if using a pattern) to use - /// a bindgen-generated wrapper for its members if at least one is non-Copy. - pub fn bindgen_wrapper_union>(mut self, arg: T) -> Self { - self.options.bindgen_wrapper_union.insert(arg); - self - } - } - - fn_with_regex_arg! { - /// Mark the given union (or set of union, if using a pattern) to use - /// [`::core::mem::ManuallyDrop`] for its members if at least one is non-Copy. - /// - /// Note: `ManuallyDrop` was stabilized in Rust 1.20.0, do not use it if your - /// MSRV is lower. - pub fn manually_drop_union>(mut self, arg: T) -> Self { - self.options.manually_drop_union.insert(arg); - self - } - } - - fn_with_regex_arg! { - /// Add a string to prepend to the generated bindings. The string is passed - /// through without any modification. - pub fn raw_line>(mut self, arg: T) -> Self { - self.options.raw_lines.push(arg.into()); - self - } - } - - /// Add a given line to the beginning of module `mod`. - pub fn module_raw_line(mut self, mod_: T, line: U) -> Self - where - T: Into, - U: Into, - { - self.options - .module_lines - .entry(mod_.into()) - .or_insert_with(Vec::new) - .push(line.into()); - self - } - - /// Add a given set of lines to the beginning of module `mod`. - pub fn module_raw_lines(mut self, mod_: T, lines: I) -> Self - where - T: Into, - I: IntoIterator, - I::Item: Into, - { - self.options - .module_lines - .entry(mod_.into()) - .or_insert_with(Vec::new) - .extend(lines.into_iter().map(Into::into)); - self - } - - /// Add an argument to be passed straight through to clang. - pub fn clang_arg>(mut self, arg: T) -> Builder { - self.options.clang_args.push(arg.into()); - self - } - - /// Add arguments to be passed straight through to clang. - pub fn clang_args(mut self, iter: I) -> Builder - where - I: IntoIterator, - I::Item: AsRef, - { - for arg in iter { - self = self.clang_arg(arg.as_ref()) - } - self - } - - /// Emit bindings for builtin definitions (for example `__builtin_va_list`) - /// in the generated Rust. - pub fn emit_builtins(mut self) -> Builder { - self.options.builtins = true; - self - } - - /// Avoid converting floats to `f32`/`f64` by default. - pub fn no_convert_floats(mut self) -> Self { - self.options.convert_floats = false; - self - } - - /// Set whether layout tests should be generated. - pub fn layout_tests(mut self, doit: bool) -> Self { - self.options.layout_tests = doit; - self - } - - /// Set whether `Debug` should be implemented, if it can not be derived automatically. - pub fn impl_debug(mut self, doit: bool) -> Self { - self.options.impl_debug = doit; - self - } - - /// Set whether `PartialEq` should be implemented, if it can not be derived automatically. - pub fn impl_partialeq(mut self, doit: bool) -> Self { - self.options.impl_partialeq = doit; - self - } - - /// Set whether `Copy` should be derived by default. - pub fn derive_copy(mut self, doit: bool) -> Self { - self.options.derive_copy = doit; - self - } - - /// Set whether `Debug` should be derived by default. - pub fn derive_debug(mut self, doit: bool) -> Self { - self.options.derive_debug = doit; - self - } - - /// Set whether `Default` should be derived by default. - pub fn derive_default(mut self, doit: bool) -> Self { - self.options.derive_default = doit; - self - } - - /// Set whether `Hash` should be derived by default. - pub fn derive_hash(mut self, doit: bool) -> Self { - self.options.derive_hash = doit; - self - } - - /// Set whether `PartialOrd` should be derived by default. - /// If we don't compute partialord, we also cannot compute - /// ord. Set the derive_ord to `false` when doit is `false`. - pub fn derive_partialord(mut self, doit: bool) -> Self { - self.options.derive_partialord = doit; - if !doit { - self.options.derive_ord = false; - } - self - } - - /// Set whether `Ord` should be derived by default. - /// We can't compute `Ord` without computing `PartialOrd`, - /// so we set the same option to derive_partialord. - pub fn derive_ord(mut self, doit: bool) -> Self { - self.options.derive_ord = doit; - self.options.derive_partialord = doit; - self - } - - /// Set whether `PartialEq` should be derived by default. - /// - /// If we don't derive `PartialEq`, we also cannot derive `Eq`, so deriving - /// `Eq` is also disabled when `doit` is `false`. - pub fn derive_partialeq(mut self, doit: bool) -> Self { - self.options.derive_partialeq = doit; - if !doit { - self.options.derive_eq = false; - } - self - } - - /// Set whether `Eq` should be derived by default. - /// - /// We can't derive `Eq` without also deriving `PartialEq`, so we also - /// enable deriving `PartialEq` when `doit` is `true`. - pub fn derive_eq(mut self, doit: bool) -> Self { - self.options.derive_eq = doit; - if doit { - self.options.derive_partialeq = doit; - } - self - } - - /// Set whether or not to time bindgen phases, and print information to - /// stderr. - pub fn time_phases(mut self, doit: bool) -> Self { - self.options.time_phases = doit; - self - } - - /// Emit Clang AST. - pub fn emit_clang_ast(mut self) -> Builder { - self.options.emit_ast = true; - self - } - - /// Emit IR. - pub fn emit_ir(mut self) -> Builder { - self.options.emit_ir = true; - self - } - - /// Enable C++ namespaces. - pub fn enable_cxx_namespaces(mut self) -> Builder { - self.options.enable_cxx_namespaces = true; - self - } - - /// Enable detecting must_use attributes on C functions. - /// - /// This is quite slow in some cases (see #1465), so it's disabled by - /// default. - /// - /// Note that for this to do something meaningful for now at least, the rust - /// target version has to have support for `#[must_use]`. - pub fn enable_function_attribute_detection(mut self) -> Self { - self.options.enable_function_attribute_detection = true; - self - } - - /// Disable name auto-namespacing. - /// - /// By default, bindgen mangles names like `foo::bar::Baz` to look like - /// `foo_bar_Baz` instead of just `Baz`. - /// - /// This method disables that behavior. - /// - /// Note that this intentionally does not change the names used for - /// allowlisting and blocklisting, which should still be mangled with the - /// namespaces. - /// - /// Note, also, that this option may cause bindgen to generate duplicate - /// names. - pub fn disable_name_namespacing(mut self) -> Builder { - self.options.disable_name_namespacing = true; - self - } - - /// Disable nested struct naming. - /// - /// The following structs have different names for C and C++. In case of C - /// they are visible as `foo` and `bar`. In case of C++ they are visible as - /// `foo` and `foo::bar`. - /// - /// ```c - /// struct foo { - /// struct bar { - /// } b; - /// }; - /// ``` - /// - /// Bindgen wants to avoid duplicate names by default so it follows C++ naming - /// and it generates `foo`/`foo_bar` instead of just `foo`/`bar`. - /// - /// This method disables this behavior and it is indented to be used only - /// for headers that were written for C. - pub fn disable_nested_struct_naming(mut self) -> Builder { - self.options.disable_nested_struct_naming = true; - self - } - - /// Treat inline namespaces conservatively. - /// - /// This is tricky, because in C++ is technically legal to override an item - /// defined in an inline namespace: - /// - /// ```cpp - /// inline namespace foo { - /// using Bar = int; - /// } - /// using Bar = long; - /// ``` - /// - /// Even though referencing `Bar` is a compiler error. - /// - /// We want to support this (arguably esoteric) use case, but we don't want - /// to make the rest of bindgen users pay an usability penalty for that. - /// - /// To support this, we need to keep all the inline namespaces around, but - /// then bindgen usage is a bit more difficult, because you cannot - /// reference, e.g., `std::string` (you'd need to use the proper inline - /// namespace). - /// - /// We could complicate a lot of the logic to detect name collisions, and if - /// not detected generate a `pub use inline_ns::*` or something like that. - /// - /// That's probably something we can do if we see this option is needed in a - /// lot of cases, to improve it's usability, but my guess is that this is - /// not going to be too useful. - pub fn conservative_inline_namespaces(mut self) -> Builder { - self.options.conservative_inline_namespaces = true; - self - } - - /// Whether inline functions should be generated or not. - /// - /// Note that they will usually not work. However you can use - /// `-fkeep-inline-functions` or `-fno-inline-functions` if you are - /// responsible of compiling the library to make them callable. - pub fn generate_inline_functions(mut self, doit: bool) -> Self { - self.options.generate_inline_functions = doit; - self - } - - /// Ignore functions. - pub fn ignore_functions(mut self) -> Builder { - self.options.codegen_config.remove(CodegenConfig::FUNCTIONS); - self - } - - /// Ignore methods. - pub fn ignore_methods(mut self) -> Builder { - self.options.codegen_config.remove(CodegenConfig::METHODS); - self - } - - /// Use core instead of libstd in the generated bindings. - pub fn use_core(mut self) -> Builder { - self.options.use_core = true; - self - } - - /// Use the given prefix for the raw types instead of `::std::os::raw`. - pub fn ctypes_prefix>(mut self, prefix: T) -> Builder { - self.options.ctypes_prefix = Some(prefix.into()); - self - } - - /// Use the given prefix for the anon fields. - pub fn anon_fields_prefix>(mut self, prefix: T) -> Builder { - self.options.anon_fields_prefix = prefix.into(); - self - } - - /// Allows configuring types in different situations, see the - /// [`ParseCallbacks`](./callbacks/trait.ParseCallbacks.html) documentation. - pub fn parse_callbacks( - mut self, - cb: Box, - ) -> Self { - self.options.parse_callbacks.push(Rc::from(cb)); - self - } - - /// Choose what to generate using a - /// [`CodegenConfig`](./struct.CodegenConfig.html). - pub fn with_codegen_config(mut self, config: CodegenConfig) -> Self { - self.options.codegen_config = config; - self - } - - /// Whether to detect include paths using clang_sys. - pub fn detect_include_paths(mut self, doit: bool) -> Self { - self.options.detect_include_paths = doit; - self - } - - /// Whether to try to fit macro constants to types smaller than u32/i32 - pub fn fit_macro_constants(mut self, doit: bool) -> Self { - self.options.fit_macro_constants = doit; - self - } - - /// Prepend the enum name to constant or newtype variants. - pub fn prepend_enum_name(mut self, doit: bool) -> Self { - self.options.prepend_enum_name = doit; - self - } - - /// Set whether `size_t` should be translated to `usize` automatically. - pub fn size_t_is_usize(mut self, is: bool) -> Self { - self.options.size_t_is_usize = is; - self - } - - #[cfg_attr(feature = "prettyplease", deprecated)] - /// Set whether rustfmt should format the generated bindings. - pub fn rustfmt_bindings(mut self, doit: bool) -> Self { - self.options.formatter = if doit { - Formatter::Rustfmt - } else { - Formatter::None - }; - self - } - - /// Set which tool should be used to format the generated bindings. - /// - /// To be able to choose `prettyplease` as a formatter, the `"prettyplease"` feature must be - /// enabled. - pub fn formatter(mut self, formatter: Formatter) -> Self { - self.options.formatter = formatter; - self - } - - /// Set whether we should record matched items in our regex sets. - pub fn record_matches(mut self, doit: bool) -> Self { - self.options.record_matches = doit; - self - } - - /// Set the absolute path to the rustfmt configuration file, if None, the standard rustfmt - /// options are used. - pub fn rustfmt_configuration_file(mut self, path: Option) -> Self { - self = self.formatter(Formatter::Rustfmt); - self.options.rustfmt_configuration_file = path; - self - } - - /// Sets an explicit path to rustfmt, to be used when rustfmt is enabled. - pub fn with_rustfmt>(mut self, path: P) -> Self { - self.options.rustfmt_path = Some(path.into()); - self - } - - /// If true, always emit explicit padding fields. - /// - /// If a struct needs to be serialized in its native format (padding bytes - /// and all), for example writing it to a file or sending it on the network, - /// then this should be enabled, as anything reading the padding bytes of - /// a struct may lead to Undefined Behavior. - pub fn explicit_padding(mut self, doit: bool) -> Self { - self.options.force_explicit_padding = doit; - self - } - - /// If true, enables experimental support to generate vtable functions. - /// - /// Should mostly work, though some edge cases are likely to be broken. - pub fn vtable_generation(mut self, doit: bool) -> Self { - self.options.vtable_generation = doit; - self - } - - /// If true, enables the sorting of the output in a predefined manner. - /// - /// TODO: Perhaps move the sorting order out into a config - pub fn sort_semantically(mut self, doit: bool) -> Self { - self.options.sort_semantically = doit; - self - } - - /// If true, merges extern blocks. - pub fn merge_extern_blocks(mut self, doit: bool) -> Self { - self.options.merge_extern_blocks = doit; - self - } - - /// Generate the Rust bindings using the options built up thus far. - pub fn generate(mut self) -> Result { - // Add any extra arguments from the environment to the clang command line. - self.options.clang_args.extend(get_extra_clang_args()); - - // Transform input headers to arguments on the clang command line. - self.options.clang_args.extend( - self.options.input_headers - [..self.options.input_headers.len().saturating_sub(1)] - .iter() - .flat_map(|header| ["-include".into(), header.to_string()]), - ); - - let input_unsaved_files = - std::mem::take(&mut self.options.input_header_contents) - .into_iter() - .map(|(name, contents)| clang::UnsavedFile::new(name, contents)) - .collect::>(); - - Bindings::generate(self.options, input_unsaved_files) - } - - /// Preprocess and dump the input header files to disk. - /// - /// This is useful when debugging bindgen, using C-Reduce, or when filing - /// issues. The resulting file will be named something like `__bindgen.i` or - /// `__bindgen.ii` - pub fn dump_preprocessed_input(&self) -> io::Result<()> { - let clang = - clang_sys::support::Clang::find(None, &[]).ok_or_else(|| { - io::Error::new( - io::ErrorKind::Other, - "Cannot find clang executable", - ) - })?; - - // The contents of a wrapper file that includes all the input header - // files. - let mut wrapper_contents = String::new(); - - // Whether we are working with C or C++ inputs. - let mut is_cpp = args_are_cpp(&self.options.clang_args); - - // For each input header, add `#include "$header"`. - for header in &self.options.input_headers { - is_cpp |= file_is_cpp(header); - - wrapper_contents.push_str("#include \""); - wrapper_contents.push_str(header); - wrapper_contents.push_str("\"\n"); - } - - // For each input header content, add a prefix line of `#line 0 "$name"` - // followed by the contents. - for (name, contents) in &self.options.input_header_contents { - is_cpp |= file_is_cpp(name); - - wrapper_contents.push_str("#line 0 \""); - wrapper_contents.push_str(name); - wrapper_contents.push_str("\"\n"); - wrapper_contents.push_str(contents); - } - - let wrapper_path = PathBuf::from(if is_cpp { - "__bindgen.cpp" - } else { - "__bindgen.c" - }); - - { - let mut wrapper_file = File::create(&wrapper_path)?; - wrapper_file.write_all(wrapper_contents.as_bytes())?; - } - - let mut cmd = Command::new(clang.path); - cmd.arg("-save-temps") - .arg("-E") - .arg("-C") - .arg("-c") - .arg(&wrapper_path) - .stdout(Stdio::piped()); - - for a in &self.options.clang_args { - cmd.arg(a); - } - - for a in get_extra_clang_args() { - cmd.arg(a); - } - - let mut child = cmd.spawn()?; - - let mut preprocessed = child.stdout.take().unwrap(); - let mut file = File::create(if is_cpp { - "__bindgen.ii" - } else { - "__bindgen.i" - })?; - io::copy(&mut preprocessed, &mut file)?; - - if child.wait()?.success() { - Ok(()) - } else { - Err(io::Error::new( - io::ErrorKind::Other, - "clang exited with non-zero status", - )) - } - } - - fn_with_regex_arg! { - /// Don't derive `PartialEq` for a given type. Regular - /// expressions are supported. - pub fn no_partialeq>(mut self, arg: T) -> Builder { - self.options.no_partialeq_types.insert(arg.into()); - self - } - } - - fn_with_regex_arg! { - /// Don't derive `Copy` and `Clone` for a given type. Regular expressions are supported. - pub fn no_copy>(mut self, arg: T) -> Self { - self.options.no_copy_types.insert(arg.into()); - self - } - } - - fn_with_regex_arg! { - /// Don't derive `Debug` for a given type. Regular - /// expressions are supported. - pub fn no_debug>(mut self, arg: T) -> Self { - self.options.no_debug_types.insert(arg.into()); - self - } - } - - fn_with_regex_arg! { - /// Don't derive/impl `Default` for a given type. Regular - /// expressions are supported. - pub fn no_default>(mut self, arg: T) -> Self { - self.options.no_default_types.insert(arg.into()); - self - } - } - - fn_with_regex_arg! { - /// Don't derive `Hash` for a given type. Regular - /// expressions are supported. - pub fn no_hash>(mut self, arg: T) -> Builder { - self.options.no_hash_types.insert(arg.into()); - self - } - } - - fn_with_regex_arg! { - /// Add `#[must_use]` for the given type. Regular - /// expressions are supported. - pub fn must_use_type>(mut self, arg: T) -> Builder { - self.options.must_use_types.insert(arg.into()); - self - } - } - - /// Set whether `arr[size]` should be treated as `*mut T` or `*mut [T; size]` (same for mut) - pub fn array_pointers_in_arguments(mut self, doit: bool) -> Self { - self.options.array_pointers_in_arguments = doit; - self - } - - /// Set the wasm import module name - pub fn wasm_import_module_name>( - mut self, - import_name: T, - ) -> Self { - self.options.wasm_import_module_name = Some(import_name.into()); - self - } - - /// Specify the dynamic library name if we are generating bindings for a shared library. - pub fn dynamic_library_name>( - mut self, - dynamic_library_name: T, - ) -> Self { - self.options.dynamic_library_name = Some(dynamic_library_name.into()); - self - } - - /// Require successful linkage for all routines in a shared library. - /// This allows us to optimize function calls by being able to safely assume function pointers - /// are valid. - pub fn dynamic_link_require_all(mut self, req: bool) -> Self { - self.options.dynamic_link_require_all = req; - self - } - - /// Generate bindings as `pub` only if the bound item is publically accessible by C++. - pub fn respect_cxx_access_specs(mut self, doit: bool) -> Self { - self.options.respect_cxx_access_specs = doit; - self - } - - /// Always translate enum integer types to native Rust integer types. - /// - /// This will result in enums having types such as `u32` and `i16` instead - /// of `c_uint` and `c_short`. Types for Rustified enums are always - /// translated. - pub fn translate_enum_integer_types(mut self, doit: bool) -> Self { - self.options.translate_enum_integer_types = doit; - self - } - - /// Generate types with C style naming. - /// - /// This will add prefixes to the generated type names. For example instead of a struct `A` we - /// will generate struct `struct_A`. Currently applies to structs, unions, and enums. - pub fn c_naming(mut self, doit: bool) -> Self { - self.options.c_naming = doit; - self - } - - fn_with_regex_arg! { - /// Override the ABI of a given function. Regular expressions are supported. - pub fn override_abi>(mut self, abi: Abi, arg: T) -> Self { - self.options - .abi_overrides - .entry(abi) - .or_default() - .insert(arg.into()); - self - } - } - - /// If true, wraps unsafe operations in unsafe blocks. - pub fn wrap_unsafe_ops(mut self, doit: bool) -> Self { - self.options.wrap_unsafe_ops = doit; - self - } - - #[cfg(feature = "experimental")] - /// Whether to generate extern wrappers for `static` and `static inline` functions. Defaults to - /// false. - pub fn wrap_static_fns(mut self, doit: bool) -> Self { - self.options.wrap_static_fns = doit; - self - } - - #[cfg(feature = "experimental")] - /// Set the path for the source code file that would be created if any wrapper functions must - /// be generated due to the presence of static functions. - /// - /// Bindgen will automatically add the right extension to the header and source code files. - pub fn wrap_static_fns_path>(mut self, path: T) -> Self { - self.options.wrap_static_fns_path = Some(path.as_ref().to_owned()); - self - } - - #[cfg(feature = "experimental")] - /// Set the suffix added to the extern wrapper functions generated for `static` and `static - /// inline` functions. - pub fn wrap_static_fns_suffix>(mut self, suffix: T) -> Self { - self.options.wrap_static_fns_suffix = Some(suffix.as_ref().to_owned()); - self - } - - /// Set the default visibility of fields, including bitfields and accessor methods for - /// bitfields. - /// - /// This option is ignored if the [`Builder::respect_cxx_access_specs`] method is enabled. - pub fn default_visibility( - mut self, - visibility: FieldVisibilityKind, - ) -> Self { - self.options.default_visibility = visibility; - self - } -} - -/// Configuration options for generated bindings. -#[derive(Clone, Debug)] -struct BindgenOptions { - /// The set of types that have been blocklisted and should not appear - /// anywhere in the generated code. - blocklisted_types: RegexSet, - - /// The set of functions that have been blocklisted and should not appear - /// in the generated code. - blocklisted_functions: RegexSet, - - /// The set of items, regardless of item-type, that have been - /// blocklisted and should not appear in the generated code. - blocklisted_items: RegexSet, - - /// The set of files whose contents should be blocklisted and should not - /// appear in the generated code. - blocklisted_files: RegexSet, - - /// The set of types that should be treated as opaque structures in the - /// generated code. - opaque_types: RegexSet, - - /// The explicit rustfmt path. - rustfmt_path: Option, - - /// The path to which we should write a Makefile-syntax depfile (if any). - depfile: Option, - - /// The set of types that we should have bindings for in the generated - /// code. - /// - /// This includes all types transitively reachable from any type in this - /// set. One might think of allowlisted types/vars/functions as GC roots, - /// and the generated Rust code as including everything that gets marked. - allowlisted_types: RegexSet, - - /// Allowlisted functions. See docs for `allowlisted_types` for more. - allowlisted_functions: RegexSet, - - /// Allowlisted variables. See docs for `allowlisted_types` for more. - allowlisted_vars: RegexSet, - - /// The set of files whose contents should be allowlisted. - allowlisted_files: RegexSet, - - /// The default style of code to generate for enums - default_enum_style: codegen::EnumVariation, - - /// The enum patterns to mark an enum as a bitfield - /// (newtype with bitwise operations). - bitfield_enums: RegexSet, - - /// The enum patterns to mark an enum as a newtype. - newtype_enums: RegexSet, - - /// The enum patterns to mark an enum as a global newtype. - newtype_global_enums: RegexSet, - - /// The enum patterns to mark an enum as a Rust enum. - rustified_enums: RegexSet, - - /// The enum patterns to mark an enum as a non-exhaustive Rust enum. - rustified_non_exhaustive_enums: RegexSet, - - /// The enum patterns to mark an enum as a module of constants. - constified_enum_modules: RegexSet, - - /// The enum patterns to mark an enum as a set of constants. - constified_enums: RegexSet, - - /// The default type for C macro constants. - default_macro_constant_type: codegen::MacroTypeVariation, - - /// The default style of code to generate for typedefs. - default_alias_style: codegen::AliasVariation, - - /// Typedef patterns that will use regular type aliasing. - type_alias: RegexSet, - - /// Typedef patterns that will be aliased by creating a new struct. - new_type_alias: RegexSet, - - /// Typedef patterns that will be wrapped in a new struct and have - /// Deref and Deref to their aliased type. - new_type_alias_deref: RegexSet, - - /// The default style of code to generate for union containing non-Copy - /// members. - default_non_copy_union_style: codegen::NonCopyUnionStyle, - - /// The union patterns to mark an non-Copy union as using the bindgen - /// generated wrapper. - bindgen_wrapper_union: RegexSet, - - /// The union patterns to mark an non-Copy union as using the - /// `::core::mem::ManuallyDrop` wrapper. - manually_drop_union: RegexSet, - - /// Whether we should generate builtins or not. - builtins: bool, - - /// True if we should dump the Clang AST for debugging purposes. - emit_ast: bool, - - /// True if we should dump our internal IR for debugging purposes. - emit_ir: bool, - - /// Output graphviz dot file. - emit_ir_graphviz: Option, - - /// True if we should emulate C++ namespaces with Rust modules in the - /// generated bindings. - enable_cxx_namespaces: bool, - - /// True if we should try to find unexposed attributes in functions, in - /// order to be able to generate #[must_use] attributes in Rust. - enable_function_attribute_detection: bool, - - /// True if we should avoid mangling names with namespaces. - disable_name_namespacing: bool, - - /// True if we should avoid generating nested struct names. - disable_nested_struct_naming: bool, - - /// True if we should avoid embedding version identifiers into source code. - disable_header_comment: bool, - - /// True if we should generate layout tests for generated structures. - layout_tests: bool, - - /// True if we should implement the Debug trait for C/C++ structures and types - /// that do not support automatically deriving Debug. - impl_debug: bool, - - /// True if we should implement the PartialEq trait for C/C++ structures and types - /// that do not support automatically deriving PartialEq. - impl_partialeq: bool, - - /// True if we should derive Copy trait implementations for C/C++ structures - /// and types. - derive_copy: bool, - - /// True if we should derive Debug trait implementations for C/C++ structures - /// and types. - derive_debug: bool, - - /// True if we should derive Default trait implementations for C/C++ structures - /// and types. - derive_default: bool, - - /// True if we should derive Hash trait implementations for C/C++ structures - /// and types. - derive_hash: bool, - - /// True if we should derive PartialOrd trait implementations for C/C++ structures - /// and types. - derive_partialord: bool, - - /// True if we should derive Ord trait implementations for C/C++ structures - /// and types. - derive_ord: bool, - - /// True if we should derive PartialEq trait implementations for C/C++ structures - /// and types. - derive_partialeq: bool, - - /// True if we should derive Eq trait implementations for C/C++ structures - /// and types. - derive_eq: bool, - - /// True if we should avoid using libstd to use libcore instead. - use_core: bool, - - /// An optional prefix for the "raw" types, like `c_int`, `c_void`... - ctypes_prefix: Option, - - /// The prefix for the anon fields. - anon_fields_prefix: String, - - /// Whether to time the bindgen phases. - time_phases: bool, - - /// Whether we should convert float types to f32/f64 types. - convert_floats: bool, - - /// The set of raw lines to prepend to the top-level module of generated - /// Rust code. - raw_lines: Vec, - - /// The set of raw lines to prepend to each of the modules. - /// - /// This only makes sense if the `enable_cxx_namespaces` option is set. - module_lines: HashMap>, - - /// The set of arguments to pass straight through to Clang. - clang_args: Vec, - - /// The input header files. - input_headers: Vec, - - /// Tuples of unsaved file contents of the form (name, contents). - input_header_contents: Vec<(String, String)>, - - /// A user-provided visitor to allow customizing different kinds of - /// situations. - parse_callbacks: Vec>, - - /// Which kind of items should we generate? By default, we'll generate all - /// of them. - codegen_config: CodegenConfig, - - /// Whether to treat inline namespaces conservatively. - /// - /// See the builder method description for more details. - conservative_inline_namespaces: bool, - - /// Whether to keep documentation comments in the generated output. See the - /// documentation for more details. Defaults to true. - generate_comments: bool, - - /// Whether to generate inline functions. Defaults to false. - generate_inline_functions: bool, - - /// Whether to allowlist types recursively. Defaults to true. - allowlist_recursively: bool, - - /// Instead of emitting 'use objc;' to files generated from objective c files, - /// generate '#[macro_use] extern crate objc;' - objc_extern_crate: bool, - - /// Instead of emitting 'use block;' to files generated from objective c files, - /// generate '#[macro_use] extern crate block;' - generate_block: bool, - - /// Instead of emitting 'use block;' to files generated from objective c files, - /// generate '#[macro_use] extern crate block;' - block_extern_crate: bool, - - /// Whether to use the clang-provided name mangling. This is true and - /// probably needed for C++ features. - /// - /// However, some old libclang versions seem to return incorrect results in - /// some cases for non-mangled functions, see [1], so we allow disabling it. - /// - /// [1]: https://github.com/rust-lang/rust-bindgen/issues/528 - enable_mangling: bool, - - /// Whether to detect include paths using clang_sys. - detect_include_paths: bool, - - /// Whether to try to fit macro constants into types smaller than u32/i32 - fit_macro_constants: bool, - - /// Whether to prepend the enum name to constant or newtype variants. - prepend_enum_name: bool, - - /// Version of the Rust compiler to target - rust_target: RustTarget, - - /// Features to enable, derived from `rust_target` - rust_features: RustFeatures, - - /// Whether we should record which items in the regex sets ever matched. - /// - /// This may be a bit slower, but will enable reporting of unused allowlist - /// items via the `error!` log. - record_matches: bool, - - /// Whether `size_t` should be translated to `usize` automatically. - size_t_is_usize: bool, - - /// The tool that should be used to format the generated bindings. - formatter: Formatter, - - /// The absolute path to the rustfmt configuration file, if None, the standard rustfmt - /// options are used. - rustfmt_configuration_file: Option, - - /// The set of types that we should not derive `PartialEq` for. - no_partialeq_types: RegexSet, - - /// The set of types that we should not derive `Copy` for. - no_copy_types: RegexSet, - - /// The set of types that we should not derive `Debug` for. - no_debug_types: RegexSet, - - /// The set of types that we should not derive/impl `Default` for. - no_default_types: RegexSet, - - /// The set of types that we should not derive `Hash` for. - no_hash_types: RegexSet, - - /// The set of types that we should be annotated with `#[must_use]`. - must_use_types: RegexSet, - - /// Decide if C arrays should be regular pointers in rust or array pointers - array_pointers_in_arguments: bool, - - /// Wasm import module name. - wasm_import_module_name: Option, - - /// The name of the dynamic library (if we are generating bindings for a shared library). If - /// this is None, no dynamic bindings are created. - dynamic_library_name: Option, - - /// Require successful linkage for all routines in a shared library. - /// This allows us to optimize function calls by being able to safely assume function pointers - /// are valid. No effect if `dynamic_library_name` is None. - dynamic_link_require_all: bool, - - /// Only make generated bindings `pub` if the items would be publically accessible - /// by C++. - respect_cxx_access_specs: bool, - - /// Always translate enum integer types to native Rust integer types. - translate_enum_integer_types: bool, - - /// Generate types with C style naming. - c_naming: bool, - - /// Always output explicit padding fields - force_explicit_padding: bool, - - /// Emit vtable functions. - vtable_generation: bool, - - /// Sort the code generation. - sort_semantically: bool, - - /// Deduplicate `extern` blocks. - merge_extern_blocks: bool, - - abi_overrides: HashMap, - - /// Whether to wrap unsafe operations in unsafe blocks or not. - wrap_unsafe_ops: bool, - - wrap_static_fns: bool, - - wrap_static_fns_suffix: Option, - - wrap_static_fns_path: Option, - - /// Default visibility of structs and their fields. - default_visibility: FieldVisibilityKind, -} - -impl BindgenOptions { - fn build(&mut self) { - let regex_sets = [ - &mut self.allowlisted_vars, - &mut self.allowlisted_types, - &mut self.allowlisted_functions, - &mut self.allowlisted_files, - &mut self.blocklisted_types, - &mut self.blocklisted_functions, - &mut self.blocklisted_items, - &mut self.blocklisted_files, - &mut self.opaque_types, - &mut self.bitfield_enums, - &mut self.constified_enums, - &mut self.constified_enum_modules, - &mut self.newtype_enums, - &mut self.newtype_global_enums, - &mut self.rustified_enums, - &mut self.rustified_non_exhaustive_enums, - &mut self.type_alias, - &mut self.new_type_alias, - &mut self.new_type_alias_deref, - &mut self.bindgen_wrapper_union, - &mut self.manually_drop_union, - &mut self.no_partialeq_types, - &mut self.no_copy_types, - &mut self.no_debug_types, - &mut self.no_default_types, - &mut self.no_hash_types, - &mut self.must_use_types, - ]; - let record_matches = self.record_matches; - for regex_set in self.abi_overrides.values_mut().chain(regex_sets) { - regex_set.build(record_matches); - } - } - - /// Update rust target version - pub fn set_rust_target(&mut self, rust_target: RustTarget) { - self.rust_target = rust_target; - - // Keep rust_features synced with rust_target - self.rust_features = rust_target.into(); - } - - /// Get features supported by target Rust version - pub fn rust_features(&self) -> RustFeatures { - self.rust_features - } - - fn last_callback( - &self, - f: impl Fn(&dyn callbacks::ParseCallbacks) -> Option, - ) -> Option { - self.parse_callbacks - .iter() - .filter_map(|cb| f(cb.as_ref())) - .last() - } - - fn all_callbacks( - &self, - f: impl Fn(&dyn callbacks::ParseCallbacks) -> Vec, - ) -> Vec { - self.parse_callbacks - .iter() - .flat_map(|cb| f(cb.as_ref())) - .collect() - } + fn all_callbacks( + &self, + f: impl Fn(&dyn callbacks::ParseCallbacks) -> Vec, + ) -> Vec { + self.parse_callbacks + .iter() + .flat_map(|cb| f(cb.as_ref())) + .collect() + } fn process_comment(&self, comment: &str) -> String { let comment = comment::preprocess(comment); @@ -2433,125 +481,6 @@ impl BindgenOptions { } } -impl Default for BindgenOptions { - fn default() -> BindgenOptions { - macro_rules! options { - ($($field:ident $(: $value:expr)?,)* --default-fields-- $($default_field:ident,)*) => { - BindgenOptions { - $($field $(: $value)*,)* - $($default_field: Default::default(),)* - } - }; - } - - let rust_target = RustTarget::default(); - - options! { - rust_target, - rust_features: rust_target.into(), - layout_tests: true, - derive_copy: true, - derive_debug: true, - anon_fields_prefix: DEFAULT_ANON_FIELDS_PREFIX.into(), - convert_floats: true, - codegen_config: CodegenConfig::all(), - generate_comments: true, - allowlist_recursively: true, - enable_mangling: true, - detect_include_paths: true, - prepend_enum_name: true, - record_matches: true, - size_t_is_usize: true, - - --default-fields-- - blocklisted_types, - blocklisted_functions, - blocklisted_items, - blocklisted_files, - opaque_types, - rustfmt_path, - depfile, - allowlisted_types, - allowlisted_functions, - allowlisted_vars, - allowlisted_files, - default_enum_style, - bitfield_enums, - newtype_enums, - newtype_global_enums, - rustified_enums, - rustified_non_exhaustive_enums, - constified_enums, - constified_enum_modules, - default_macro_constant_type, - default_alias_style, - type_alias, - new_type_alias, - new_type_alias_deref, - default_non_copy_union_style, - bindgen_wrapper_union, - manually_drop_union, - builtins, - emit_ast, - emit_ir, - emit_ir_graphviz, - impl_debug, - impl_partialeq, - derive_default, - derive_hash, - derive_partialord, - derive_ord, - derive_partialeq, - derive_eq, - enable_cxx_namespaces, - enable_function_attribute_detection, - disable_name_namespacing, - disable_nested_struct_naming, - disable_header_comment, - use_core, - ctypes_prefix, - raw_lines, - module_lines, - clang_args, - input_headers, - input_header_contents, - parse_callbacks, - conservative_inline_namespaces, - generate_inline_functions, - generate_block, - objc_extern_crate, - block_extern_crate, - fit_macro_constants, - time_phases, - formatter, - rustfmt_configuration_file, - no_partialeq_types, - no_copy_types, - no_debug_types, - no_default_types, - no_hash_types, - must_use_types, - array_pointers_in_arguments, - wasm_import_module_name, - dynamic_library_name, - dynamic_link_require_all, - respect_cxx_access_specs, - translate_enum_integer_types, - c_naming, - force_explicit_padding, - vtable_generation, - sort_semantically, - merge_extern_blocks, - abi_overrides, - wrap_unsafe_ops, - wrap_static_fns, - wrap_static_fns_suffix, - wrap_static_fns_path, - default_visibility, - } - } -} - #[cfg(feature = "runtime")] fn ensure_libclang_is_loaded() { if clang_sys::is_loaded() { diff --git a/bindgen/options/as_args.rs b/bindgen/options/as_args.rs new file mode 100644 index 0000000000..4166843aa3 --- /dev/null +++ b/bindgen/options/as_args.rs @@ -0,0 +1,52 @@ +use std::path::PathBuf; + +use crate::RegexSet; + +/// Trait used to turn [`BindgenOptions`] fields into CLI args. +pub(super) trait AsArgs { + fn as_args(&self, args: &mut Vec, flag: &str); +} + +/// If the `bool` is `true`, `flag` is pushed into `args`. +/// +/// be careful about the truth value of the field as some options, like `--no-layout-tests`, are +/// actually negations of the fields. +impl AsArgs for bool { + fn as_args(&self, args: &mut Vec, flag: &str) { + if *self { + args.push(flag.to_string()); + } + } +} + +/// Iterate over all the items of the `RegexSet` and push `flag` followed by the item into `args` +/// for each item. +impl AsArgs for RegexSet { + fn as_args(&self, args: &mut Vec, flag: &str) { + for item in self.get_items() { + args.extend_from_slice(&[flag.to_owned(), item.clone()]); + } + } +} + +/// If the `Option` is `Some(value)`, push `flag` followed by `value`. +impl AsArgs for Option { + fn as_args(&self, args: &mut Vec, flag: &str) { + if let Some(string) = self { + args.extend_from_slice(&[flag.to_owned(), string.clone()]); + } + } +} + +/// If the `Option` is `Some(path)`, push `flag` followed by the [`PathBuf::display`] +/// representation of `path`. +impl AsArgs for Option { + fn as_args(&self, args: &mut Vec, flag: &str) { + if let Some(path) = self { + args.extend_from_slice(&[ + flag.to_owned(), + path.display().to_string(), + ]); + } + } +} diff --git a/bindgen/options/helpers.rs b/bindgen/options/helpers.rs new file mode 100644 index 0000000000..5a62f52b4e --- /dev/null +++ b/bindgen/options/helpers.rs @@ -0,0 +1,46 @@ +/// Helper function that appends extra documentation to [`Builder`] methods that support regular +/// expressions in their input. +macro_rules! regex_option { + ($(#[$attrs:meta])* pub fn $($tokens:tt)*) => { + $(#[$attrs])* + /// + /// Regular expressions are supported. To match any items that start with `prefix` use the + /// `"prefix.*"` regular expression. + /// + /// Check the [regular expression arguments](./struct.Builder.html#regular-expression-arguments) + /// section and the [regex](https://docs.rs/regex) crate documentation for further + /// information. + pub fn $($tokens)* + }; +} + +/// Helper macro to set the default value of each option. +/// +/// This macro is an internal implementation detail of the `options` macro and should not be used +/// directly. +macro_rules! default { + () => { + Default::default() + }; + ($expr:expr) => { + $expr + }; +} + +/// Helper macro to set the conversion to CLI arguments for each option. +/// +/// This macro is an internal implementation detail of the `options` macro and should not be used +/// directly. +macro_rules! as_args { + ($flag:literal) => { + |field, args| AsArgs::as_args(field, args, $flag) + }; + ($expr:expr) => { + $expr + }; +} + +/// Helper function to ignore an option when converting it into CLI arguments. +/// +/// This function is only used inside `options` and should not be used in other contexts. +pub(super) fn ignore(_: &T, _: &mut Vec) {} diff --git a/bindgen/options/mod.rs b/bindgen/options/mod.rs new file mode 100644 index 0000000000..d28d4aa96a --- /dev/null +++ b/bindgen/options/mod.rs @@ -0,0 +1,2104 @@ +//! Declarations and setter methods for `bindgen` options. +//! +//! The main entry point of this module is the [`options`] macro. +#[macro_use] +mod helpers; +mod as_args; + +use crate::callbacks::ParseCallbacks; +use crate::codegen::{ + AliasVariation, EnumVariation, MacroTypeVariation, NonCopyUnionStyle, +}; +use crate::deps::DepfileSpec; +use crate::features::{RustFeatures, RustTarget}; +use crate::regex_set::RegexSet; +use crate::Abi; +use crate::Builder; +use crate::CodegenConfig; +use crate::FieldVisibilityKind; +use crate::Formatter; +use crate::HashMap; +use crate::DEFAULT_ANON_FIELDS_PREFIX; + +use std::env; +use std::path::{Path, PathBuf}; +use std::rc::Rc; + +use as_args::AsArgs; +use helpers::ignore; + +/// Macro used to generate the [`BindgenOptions`] type and the [`Builder`] setter methods for each +/// one of the fields of `BindgenOptions`. +/// +/// The input format of this macro resembles a `struct` pattern. Each field of the `BindgenOptions` +/// type is declared using 4 items: +/// +/// - `ty`: The type of the field. +/// - `default`: The default value for the field. If this item is omitted, `Default::default()` is +/// used instead, meaning that the type of the field must implement `Default`. +/// - `methods`: A block of code containing methods for the `Builder` type. These methods should be +/// related to the field being declared. +/// - `as_args`: This item declares how the field should be converted into a valid CLI argument for +/// `bindgen` and is used in the [`Builder::command_line_flags`] method which is used to do a +/// roundtrip test of the CLI args in the `bindgen-test` crate. This item can take one of the +/// following: +/// - A string literal with the flag if the type of the field implements the [`AsArgs`] trait. +/// - A closure with the signature `|field, args: &mut Vec| -> ()` that pushes arguments +/// into the `args` buffer based on the value of the field. This is used if the field does not +/// implement `AsArgs` or if the implementation of the trait is not logically correct for the +/// option and a custom behavior must be taken into account. +/// - The `ignore` literal, which does not emit any CLI arguments for this field. This is useful +/// if the field cannot be used from the `bindgen` CLI. +/// +/// As an example, this would be the declaration of a `bool` field called `be_fun` whose default +/// value is `false` (the `Default` value for `bool`): +/// ```rust,ignore +/// be_fun: { +/// ty: bool, +/// methods: { +/// /// Ask `bindgen` to be fun. This option is disabled by default. +/// fn be_fun(mut self) -> Self { +/// self.options.be_fun = true; +/// self +/// } +/// }, +/// as_args: "--be-fun", +/// } +/// ``` +/// +/// However, we could also set the `be_fun` field to `true` by default and use a `--not-fun` flag +/// instead. This means that we have to add the `default` item and use a closure in the `as_args` +/// item: +/// ```rust,ignore +/// be_fun: { +/// ty: bool, +/// default: true, +/// methods: { +/// /// Ask `bindgen` to not be fun. `bindgen` is fun by default. +/// fn not_fun(mut self) -> Self { +/// self.options.be_fun = false; +/// self +/// } +/// }, +/// as_args: |be_fun, args| (!be_fun).as_args(args, "--not-fun"), +/// } +/// ``` +/// More complex examples can be found in the sole invocation of this macro. +macro_rules! options { + ($( + $(#[doc = $docs:literal])+ + $field:ident: { + ty: $ty:ty, + $(default: $default:expr,)? + methods: {$($methods_tokens:tt)*}$(,)? + as_args: $as_args:expr$(,)? + }$(,)? + )*) => { + #[derive(Debug, Clone)] + pub(crate) struct BindgenOptions { + $($(#[doc = $docs])* pub(crate) $field: $ty,)* + } + + impl Default for BindgenOptions { + fn default() -> Self { + Self { + $($field: default!($($default)*),)* + } + } + } + + impl Builder { + /// Generates the command line flags used to create this [`Builder`]. + pub fn command_line_flags(&self) -> Vec { + let mut args = vec![]; + + let headers = match self.options.input_headers.split_last() { + Some((header, headers)) => { + // The last input header is passed as an argument in the first position. + args.push(header.clone()); + headers + }, + None => &[] + }; + + $({ + eprintln!("doing {}", stringify!($field)); + let func: fn(&$ty, &mut Vec) = as_args!($as_args); + func(&self.options.$field, &mut args); + })* + + // Add the `--experimental` flag if `bindgen` is built with the `experimental` + // feature. + if cfg!(feature = "experimental") { + args.push("--experimental".to_owned()); + } + + // Add all the clang arguments. + args.push("--".to_owned()); + + if !self.options.clang_args.is_empty() { + args.extend_from_slice(&self.options.clang_args); + } + + // We need to pass all but the last header via the `-include` clang argument. + for header in headers { + args.push("-include".to_owned()); + args.push(header.clone()); + } + + args + } + + $($($methods_tokens)*)* + } + }; +} + +options! { + /// Types that have been blocklisted and should not appear anywhere in the generated code. + blocklisted_types: { + ty: RegexSet, + methods: { + regex_option! { + /// Do not generate any bindings for the given type. + pub fn blocklist_type>(mut self, arg: T) -> Builder { + self.options.blocklisted_types.insert(arg); + self + } + } + }, + as_args: "--blocklist-type", + }, + /// Functions that have been blocklisted and should not appear in the generated code. + blocklisted_functions: { + ty: RegexSet, + methods : { + regex_option! { + /// Do not generate any bindings for the given function. + /// + /// Methods can be blocklisted by prefixing the name of the type where they belong + /// followed by an underscore. So if the type `Foo` has a method `bar`, it can be + /// blocklisted as `Foo_bar`. + pub fn blocklist_function>(mut self, arg: T) -> Builder { + self.options.blocklisted_functions.insert(arg); + self + } + } + }, + as_args: "--blocklist-function", + }, + /// Items that have been blocklisted and should not appear in the generated code. + blocklisted_items: { + ty: RegexSet, + methods: { + regex_option! { + /// Do not generate any bindings for the given item, regardless of whether it is a + /// type, function, module, etc. + pub fn blocklist_item>(mut self, arg: T) -> Builder { + self.options.blocklisted_items.insert(arg); + self + } + } + }, + as_args: "--blocklist-item", + }, + /// Files whose contents should be blocklisted and should not appear in the generated code. + blocklisted_files: { + ty: RegexSet, + methods: { + regex_option! { + /// Do not generate any bindings for the contents of the given file, regardless of + /// whether the contents of the file are types, functions, modules, etc. + pub fn blocklist_file>(mut self, arg: T) -> Builder { + self.options.blocklisted_files.insert(arg); + self + } + } + }, + as_args: "--blocklist-file", + }, + /// Types that should be treated as opaque structures in the generated code. + opaque_types: { + ty: RegexSet, + methods: { + regex_option! { + /// Treat the given type as opaque in the generated bindings. + /// + /// Opaque in this context means that none of the generated bindings will contain + /// information about the inner representation of the type and the type itself will + /// be represented as a chunk of bytes with the alignment and size of the type. + pub fn opaque_type>(mut self, arg: T) -> Builder { + self.options.opaque_types.insert(arg); + self + } + } + }, + as_args: "--opaque-type", + }, + /// The explicit `rustfmt` path. + rustfmt_path: { + ty: Option, + methods: { + /// Set an explicit path to the `rustfmt` binary. + /// + /// This option only comes into effect if `rustfmt` is set to be the formatter used by + /// `bindgen`. Check the documentation of the [`Builder::formatter`] method for more + /// information. + pub fn with_rustfmt>(mut self, path: P) -> Self { + self.options.rustfmt_path = Some(path.into()); + self + } + }, + // This option cannot be set from the CLI. + as_args: ignore, + }, + /// The path to which we should write a Makefile-syntax depfile (if any). + depfile: { + ty: Option, + methods: { + /// Add a depfile output which will be written alongside the generated bindings. + pub fn depfile, D: Into>( + mut self, + output_module: H, + depfile: D, + ) -> Builder { + self.options.depfile = Some(DepfileSpec { + output_module: output_module.into(), + depfile_path: depfile.into(), + }); + self + } + }, + as_args: |depfile, args| { + if let Some(depfile) = depfile { + args.push("--depfile".into()); + args.push(depfile.depfile_path.display().to_string()); + } + }, + }, + /// Types that have been allowlisted and should appear in the generated code. + allowlisted_types: { + ty: RegexSet, + methods: { + regex_option! { + /// Generate bindings for the given type. + /// + /// This option is transitive by default. Check the documentation of the + /// [`Builder::allowlist_recursively`] method for further information. + pub fn allowlist_type>(mut self, arg: T) -> Builder { + self.options.allowlisted_types.insert(arg); + self + } + } + }, + as_args: "--allowlist-type", + }, + /// Functions that have been allowlisted and should appear in the generated code. + allowlisted_functions: { + ty: RegexSet, + methods: { + regex_option! { + /// Generate bindings for the given function. + /// + /// Methods can be allowlisted by prefixing the name of the type where they belong + /// followed by an underscore. So if the type `Foo` has a method `bar`, it can be + /// allowlisted as `Foo_bar`. + /// + /// This option is transitive by default. Check the documentation of the + /// [`Builder::allowlist_recursively`] method for further information. + pub fn allowlist_function>(mut self, arg: T) -> Builder { + self.options.allowlisted_functions.insert(arg); + self + } + } + }, + as_args: "--allowlist-function", + }, + /// Variables that have been allowlisted and should appear in the generated code. + allowlisted_vars: { + ty: RegexSet, + methods: { + regex_option! { + /// Generate bindings for the given variable. + /// + /// This option is transitive by default. Check the documentation of the + /// [`Builder::allowlist_recursively`] method for further information. + pub fn allowlist_var>(mut self, arg: T) -> Builder { + self.options.allowlisted_vars.insert(arg); + self + } + } + }, + as_args: "--allowlist-var", + }, + /// Files whose contents have been allowlisted and should appear in the generated code. + allowlisted_files: { + ty: RegexSet, + methods: { + regex_option! { + /// Generate bindings for the content of the given file. + /// + /// This option is transitive by default. Check the documentation of the + /// [`Builder::allowlist_recursively`] method for further information. + pub fn allowlist_file>(mut self, arg: T) -> Builder { + self.options.allowlisted_files.insert(arg); + self + } + } + }, + as_args: "--allowlist-file", + }, + /// The default style of for generated `enum`s. + default_enum_style: { + ty: EnumVariation, + methods: { + /// Set the default style for generated `enum`s. + /// + /// If this method is not called, the [`EnumVariation::Consts`] style will be used by + /// default. + /// + /// To set the style for individual `enum`s, use [`Builder::bitfield_enum`], + /// [`Builder::newtype_enum`], [`Builder::newtype_global_enum`], + /// [`Builder::rustified_enum`], [`Builder::rustified_non_exhaustive_enum`], + /// [`Builder::constified_enum_module`] or [`Builder::constified_enum`]. + pub fn default_enum_style( + mut self, + arg: EnumVariation, + ) -> Builder { + self.options.default_enum_style = arg; + self + } + }, + as_args: |variation, args| { + if *variation != Default::default() { + args.push("--default-enum-style".to_owned()); + args.push(variation.to_string()); + } + }, + }, + /// `enum`s marked as bitfield-like. This is, newtypes with bitwise operations. + bitfield_enums: { + ty: RegexSet, + methods: { + regex_option! { + /// Mark the given `enum` as being bitfield-like. + /// + /// This is similar to the [`Builder::newtype_enum`] style, but with the bitwise + /// operators implemented. + pub fn bitfield_enum>(mut self, arg: T) -> Builder { + self.options.bitfield_enums.insert(arg); + self + } + } + }, + as_args: "--bitfield-enum", + }, + /// `enum`s marked as newtypes. + newtype_enums: { + ty: RegexSet, + methods: { + regex_option! { + /// Mark the given `enum` as a newtype. + /// + /// This means that an integer newtype will be declared to represent the `enum` + /// type and its variants will be represented as constants inside of this type's + /// `impl` block. + pub fn newtype_enum>(mut self, arg: T) -> Builder { + self.options.newtype_enums.insert(arg); + self + } + } + }, + as_args: "--newtype-enum", + }, + /// `enum`s marked as global newtypes . + newtype_global_enums: { + ty: RegexSet, + methods: { + regex_option! { + /// Mark the given `enum` as a global newtype. + /// + /// This is similar to the [`Builder::newtype_enum`] style, but the constants for + /// each variant are free constants instead of being declared inside an `impl` + /// block for the newtype. + pub fn newtype_global_enum>(mut self, arg: T) -> Builder { + self.options.newtype_global_enums.insert(arg); + self + } + } + }, + as_args: "--newtype-global-enum", + }, + /// `enum`s marked as Rust `enum`s. + rustified_enums: { + ty: RegexSet, + methods: { + regex_option! { + /// Mark the given `enum` as a Rust `enum`. + /// + /// This means that each variant of the `enum` will be represented as a Rust `enum + /// variant. + /// + /// **Use this with caution**, creating an instance of a Rust `enum` with an + /// invalid value will cause undefined behaviour. To avoid this, use the + /// [`Builder::newtype_enum`] style instead. + pub fn rustified_enum>(mut self, arg: T) -> Builder { + self.options.rustified_enums.insert(arg); + self + } + } + }, + as_args: "--rustified-enum", + }, + /// `enum`s marked as non-exhaustive Rust `enum`s. + rustified_non_exhaustive_enums: { + ty: RegexSet, + methods: { + regex_option! { + /// Mark the given `enum` as a non-exhaustive Rust `enum`. + /// + /// This is similar to the [`Builder::rustified_enum`] style, but the `enum` is + /// tagged with the `#[non_exhaustive]` attribute. + pub fn rustified_non_exhaustive_enum>(mut self, arg: T) -> Builder { + self.options.rustified_non_exhaustive_enums.insert(arg); + self + } + } + }, + as_args: "--rustified-non-exhaustive-enums", + }, + /// `enum`s marked as modules of constants. + constified_enum_modules: { + ty: RegexSet, + methods: { + regex_option! { + /// Mark the given `enum` as a module with a set of integer constants. + pub fn constified_enum_module>(mut self, arg: T) -> Builder { + self.options.constified_enum_modules.insert(arg); + self + } + } + }, + as_args: "--constified-enum-module", + }, + /// `enum`s marked as a set of constants. + constified_enums: { + ty: RegexSet, + methods: { + regex_option! { + /// Mark the given `enum` as a set o integer constants. + /// + /// This is similar to the [`Builder::constified_enum_module`] style, but the + /// constants are generated in the current module instead of in a new module. + pub fn constified_enum>(mut self, arg: T) -> Builder { + self.options.constified_enums.insert(arg); + self + } + } + }, + as_args: "--constified-enum", + }, + /// The default type signedness for C macro constants. + default_macro_constant_type: { + ty: MacroTypeVariation, + methods: { + /// Set the default type signedness to be used for macro constants. + /// + /// If this method is not called, [`MacroTypeVariation::Unsigned`] is used by default. + /// + /// To set the type for individual macro constants, use the + /// [`ParseCallbacks::int_macro`] method. + pub fn default_macro_constant_type(mut self, arg: MacroTypeVariation) -> Builder { + self.options.default_macro_constant_type = arg; + self + } + + }, + as_args: |variation, args| { + if *variation != Default::default() { + args.push("--default-macro-constant-type".to_owned()); + args.push(variation.to_string()); + } + }, + }, + /// The default style of code generation for `typedef`s. + default_alias_style: { + ty: AliasVariation, + methods: { + /// Set the default style of code generation for `typedef`s. + /// + /// If this method is not called, the [`AliasVaration::TypeAlias`] style is used by + /// default. + /// + /// To set the style for individual `typedefs`s, use [`Builder::type_alias`], + /// [`Builder::new_type_alias`] or [`Builder::new_type_alias_deref`]. + pub fn default_alias_style( + mut self, + arg: AliasVariation, + ) -> Builder { + self.options.default_alias_style = arg; + self + } + }, + as_args: |variation, args| { + if *variation != Default::default() { + args.push("--default-alias-style".to_owned()); + args.push(variation.to_string()); + } + }, + }, + /// `typedef` patterns that will use regular type aliasing. + type_alias: { + ty: RegexSet, + methods: { + regex_option! { + /// Mark the given `typedef` as a regular Rust `type` alias. + /// + /// This is the default behavior, meaning that this method only comes into effect + /// if a style different from [`AliasVariation::TypeAlias`] was passed to the + /// [`Builder::default_alias_style`] method. + pub fn type_alias>(mut self, arg: T) -> Builder { + self.options.type_alias.insert(arg); + self + } + } + }, + as_args: "--type-alias", + }, + /// `typedef` patterns that will be aliased by creating a newtype. + new_type_alias: { + ty: RegexSet, + methods: { + regex_option! { + /// Mark the given `typedef` as a Rust newtype by having the aliased + /// type be wrapped in a `struct` with `#[repr(transparent)]`. + /// + /// This method can be used to enforce stricter type checking. + pub fn new_type_alias>(mut self, arg: T) -> Builder { + self.options.new_type_alias.insert(arg); + self + } + } + }, + as_args: "--new-type-alias", + }, + /// `typedef` patterns that will be wrapped in a newtype implementing `Deref` and `DerefMut`. + new_type_alias_deref: { + ty: RegexSet, + methods: { + regex_option! { + /// Mark the given `typedef` to be generated as a newtype that can be dereferenced. + /// + /// This is similar to the [`Builder:new_type_alias`] style, but the newtype + /// implements `Deref` and `DerefMut` with the aliased type as a target. + pub fn new_type_alias_deref>(mut self, arg: T) -> Builder { + self.options.new_type_alias_deref.insert(arg); + self + } + } + }, + as_args: "--new-type-alias-deref", + }, + /// The default style of code to generate for `union`s containing non-`Copy` members. + default_non_copy_union_style: { + ty: NonCopyUnionStyle, + methods: { + /// Set the default style of code to generate for `union`s with non-`Copy` members. + /// + /// If this method is not called, the [`NonCopyUnionStyle::BindgenWrapper`] style is + /// used by default. + /// + /// To set the style for individual `union`s, use [`Builder::bindgen_wrapper_union`] or + /// [`Builder::manually_drop_union`]. + pub fn default_non_copy_union_style(mut self, arg: NonCopyUnionStyle) -> Self { + self.options.default_non_copy_union_style = arg; + self + } + }, + as_args: |style, args| { + if *style != Default::default() { + args.push("--default-non-copy-union-style".to_owned()); + args.push(style.to_string()); + } + }, + }, + /// The patterns marking non-`Copy` `union`s as using the `bindgen` generated wrapper. + bindgen_wrapper_union: { + ty: RegexSet, + methods: { + regex_option! { + /// Mark the given `union` to use a `bindgen`-generated wrapper for its members if at + /// least one them is not `Copy`. + /// + /// This is the default behavior, meaning that this method only comes into effect + /// if a style different from [`NonCopyUnionStyle::BindgenWrapper`] was passed to + /// the [`Builder::default_non_copy_union_style`] method. + pub fn bindgen_wrapper_union>(mut self, arg: T) -> Self { + self.options.bindgen_wrapper_union.insert(arg); + self + } + } + }, + as_args: "--bindgen-wrapper-union", + }, + /// The patterns marking non-`Copy` `union`s as using the `ManuallyDrop` wrapper. + manually_drop_union: { + ty: RegexSet, + methods: { + regex_option! { + /// Mark the given `union` to use [`::core::mem::ManuallyDrop`] for its members if + /// at least one of them is not `Copy`. + /// + /// The `ManuallyDrop` type was stabilized in Rust 1.20.0, do not use this option + /// if your target version is lower than this. + pub fn manually_drop_union>(mut self, arg: T) -> Self { + self.options.manually_drop_union.insert(arg); + self + } + } + + }, + as_args: "--manually-drop-union", + }, + + + /// Whether we should generate built-in definitions. + builtins: { + ty: bool, + methods: { + /// Generate Rust bindings for built-in definitions (for example `__builtin_va_list`). + /// + /// Bindings for built-in definitions are not emitted by default. + pub fn emit_builtins(mut self) -> Builder { + self.options.builtins = true; + self + } + }, + as_args: "--builtins", + }, + /// Whether we should dump the Clang AST for debugging purposes. + emit_ast: { + ty: bool, + methods: { + /// Emit the Clang AST to `stdout` for debugging purposes. + /// + /// The Clang AST is not emitted by default. + pub fn emit_clang_ast(mut self) -> Builder { + self.options.emit_ast = true; + self + } + }, + as_args: "--emit-clang-ast", + }, + /// Whether we should dump our IR for debugging purposes. + emit_ir: { + ty: bool, + methods: { + /// Emit the `bindgen` internal representation to `stdout` for debugging purposes. + /// + /// This internal representation is not emitted by default. + pub fn emit_ir(mut self) -> Builder { + self.options.emit_ir = true; + self + } + }, + as_args: "--emit-ir", + }, + /// Output path for the `graphviz` DOT file. + emit_ir_graphviz: { + ty: Option, + methods: { + /// Set the path for the file where the`bindgen` internal representation will be + /// emitted as a graph using the `graphviz` DOT language. + /// + /// This graph representation is not emitted by default. + pub fn emit_ir_graphviz>(mut self, path: T) -> Builder { + let path = path.into(); + self.options.emit_ir_graphviz = Some(path); + self + } + }, + as_args: "--emit-ir-graphviz", + }, + + /// Whether we should emulate C++ namespaces with Rust modules. + enable_cxx_namespaces: { + ty: bool, + methods: { + /// Emulate C++ namespaces using Rust modules in the generated bindings. + /// + /// C++ namespaces are not emulated by default. + pub fn enable_cxx_namespaces(mut self) -> Builder { + self.options.enable_cxx_namespaces = true; + self + } + }, + as_args: "--enable-cxx-namespaces", + }, + /// Whether we should try to find unexposed attributes in functions. + enable_function_attribute_detection: { + ty: bool, + methods: { + /// Enable detecting function attributes on C functions. + /// + /// This enables the following features: + /// - Add `#[must_use]` attributes to Rust items whose C counterparts are marked as so. + /// This feature also requires that the Rust target version supports the attribute. + /// - Set `!` as the return type for Rust functions whose C counterparts are marked as + /// diverging. + /// + /// This option can be quite slow in some cases (check [#1465]), so it is disabled by + /// default. + /// + /// [#1465]: https://github.com/rust-lang/rust-bindgen/issues/1465 + pub fn enable_function_attribute_detection(mut self) -> Self { + self.options.enable_function_attribute_detection = true; + self + } + + }, + as_args: "--enable-function-attribute-detection", + }, + /// Whether we should avoid mangling names with namespaces. + disable_name_namespacing: { + ty: bool, + methods: { + /// Disable name auto-namespacing. + /// + /// By default, `bindgen` mangles names like `foo::bar::Baz` to look like `foo_bar_Baz` + /// instead of just `Baz`. This method disables that behavior. + /// + /// Note that this does not change the names used for allowlisting and blocklisting, + /// which should still be mangled with the namespaces. Additionally, this option may + /// cause `bindgen` to generate duplicate names. + pub fn disable_name_namespacing(mut self) -> Builder { + self.options.disable_name_namespacing = true; + self + } + }, + as_args: "--disable-name-namespacing", + }, + /// Whether we should avoid generating nested `struct` names. + disable_nested_struct_naming: { + ty: bool, + methods: { + /// Disable nested `struct` naming. + /// + /// The following `struct`s have different names for C and C++. In C, they are visible + /// as `foo` and `bar`. In C++, they are visible as `foo` and `foo::bar`. + /// + /// ```c + /// struct foo { + /// struct bar { + /// } b; + /// }; + /// ``` + /// + /// `bindgen` tries to avoid duplicate names by default, so it follows the C++ naming + /// convention and it generates `foo` and `foo_bar` instead of just `foo` and `bar`. + /// + /// This method disables this behavior and it is indented to be used only for headers + /// that were written in C. + pub fn disable_nested_struct_naming(mut self) -> Builder { + self.options.disable_nested_struct_naming = true; + self + } + }, + as_args: "--disable-nested-struct-naming", + }, + /// Whether we should avoid embedding version identifiers into source code. + disable_header_comment: { + ty: bool, + methods: { + /// Do not insert the `bindgen` version identifier into the generated bindings. + /// + /// This identifier is inserted by default. + pub fn disable_header_comment(mut self) -> Self { + self.options.disable_header_comment = true; + self + } + + }, + as_args: "--disable-header-comment", + }, + /// Whether we should generate layout tests for generated `struct`s. + layout_tests: { + ty: bool, + default: true, + methods: { + /// Set whether layout tests should be generated. + /// + /// Layout tests are generated by default. + pub fn layout_tests(mut self, doit: bool) -> Self { + self.options.layout_tests = doit; + self + } + }, + as_args: |value, args| (!value).as_args(args, "--no-layout-tests"), + }, + /// Whether we should implement `Debug` for types that cannot derive it. + impl_debug: { + ty: bool, + methods: { + /// Set whether `Debug` should be implemented for types that cannot derive it. + /// + /// This option is disabled by default. + pub fn impl_debug(mut self, doit: bool) -> Self { + self.options.impl_debug = doit; + self + } + + }, + as_args: "--impl-debug", + }, + /// Whether we should implement `PartialEq` types that cannot derive it. + impl_partialeq: { + ty: bool, + methods: { + /// Set whether `PartialEq` should be implemented for types that cannot derive it. + /// + /// This option is disabled by default. + pub fn impl_partialeq(mut self, doit: bool) -> Self { + self.options.impl_partialeq = doit; + self + } + }, + as_args: "--impl-partialeq", + }, + /// Whether we should derive `Copy` when possible. + derive_copy: { + ty: bool, + default: true, + methods: { + /// Set whether the `Copy` trait should be derived when possible. + /// + /// `Copy` is derived by default. + pub fn derive_copy(mut self, doit: bool) -> Self { + self.options.derive_copy = doit; + self + } + }, + as_args: |value, args| (!value).as_args(args, "--no-derive-copy"), + }, + + /// Whether we should derive `Debug` when possible. + derive_debug: { + ty: bool, + default: true, + methods: { + /// Set whether the `Debug` trait should be derived when possible. + /// + /// The [`Builder::impl_debug`] method can be used to implement `Debug` for types that + /// cannot derive it. + /// + /// `Debug` is derived by default. + pub fn derive_debug(mut self, doit: bool) -> Self { + self.options.derive_debug = doit; + self + } + }, + as_args: |value, args| (!value).as_args(args, "--no-derive-debug"), + }, + + /// Whether we should derive `Default` when possible. + derive_default: { + ty: bool, + methods: { + /// Set whether the `Default` trait should be derived when possible. + /// + /// `Default` is not derived by default. + pub fn derive_default(mut self, doit: bool) -> Self { + self.options.derive_default = doit; + self + } + }, + as_args: |&value, args| { + let arg = if value { + "--with-derive-default" + } else { + "--no-derive-default" + }; + + args.push(arg.to_owned()); + }, + }, + /// Whether we should derive `Hash` when possible. + derive_hash: { + ty: bool, + methods: { + /// Set whether the `Hash` trait should be derived when possible. + /// + /// `Hash` is not derived by default. + pub fn derive_hash(mut self, doit: bool) -> Self { + self.options.derive_hash = doit; + self + } + }, + as_args: "--with-derive-hash", + }, + /// Whether we should derive `PartialOrd` when possible. + derive_partialord: { + ty: bool, + methods: { + /// Set whether the `PartialOrd` trait should be derived when possible. + /// + /// Take into account that `Ord` cannot be derived for a type that does not implement + /// `PartialOrd`. For this reason, setting this method to `false` also sets + /// automatically [`Builder::derive_ord`] to `false`. + /// + /// `PartialOrd` is not derived by default. + pub fn derive_partialord(mut self, doit: bool) -> Self { + self.options.derive_partialord = doit; + if !doit { + self.options.derive_ord = false; + } + self + } + }, + as_args: "--with-derive-partialord", + }, + /// Whether we should derive `Ord` when possible. + derive_ord: { + ty: bool, + methods: { + /// Set whether the `Ord` trait should be derived when possible. + /// + /// Take into account that `Ord` cannot be derived for a type that does not implement + /// `PartialOrd`. For this reason, the value set with this method will also be set + /// automatically for [`Builder::derive_partialord`]. + /// + /// `Ord` is not derived by default. + pub fn derive_ord(mut self, doit: bool) -> Self { + self.options.derive_ord = doit; + self.options.derive_partialord = doit; + self + } + }, + as_args: "--with-derive-ord", + }, + /// Whether we should derive `PartialEq` when possible. + derive_partialeq: { + ty: bool, + methods: { + /// Set whether the `PartialEq` trait should be derived when possible. + /// + /// Take into account that `Eq` cannot be derived for a type that does not implement + /// `PartialEq`. For this reason, setting this method to `false` also sets + /// automatically [`Builder::derive_eq`] to `false`. + /// + /// The [`Builder::impl_partialeq`] method can be used to implement `PartialEq` for + /// types that cannot derive it. + /// + /// `PartialEq` is not derived by default. + pub fn derive_partialeq(mut self, doit: bool) -> Self { + self.options.derive_partialeq = doit; + if !doit { + self.options.derive_eq = false; + } + self + } + }, + as_args: "--with-derive-partialeq", + }, + /// Whether we should derive `Eq` when possible. + derive_eq: { + ty: bool, + methods: { + /// Set whether the `Eq` trait should be derived when possible. + /// + /// Take into account that `Eq` cannot be derived for a type that does not implement + /// `PartialEq`. For this reason, the value set with this method will also be set + /// automatically for [`Builder::derive_partialeq`]. + /// + /// `Eq` is not derived by default. + pub fn derive_eq(mut self, doit: bool) -> Self { + self.options.derive_eq = doit; + if doit { + self.options.derive_partialeq = doit; + } + self + } + }, + as_args: "--with-derive-eq", + }, + /// Whether we should use `core` instead of `std`. + /// + /// If this option is enabled and the Rust target version is greater than 1.64, the prefix for + /// C platform-specific types will be `::core::ffi` instead of `::core::os::raw`. + use_core: { + ty: bool, + methods: { + /// Use `core` instead of `std` in the generated bindings. + /// + /// `std` is used by default. + pub fn use_core(mut self) -> Builder { + self.options.use_core = true; + self + } + + }, + as_args: "--use-core", + }, + /// An optional prefix for the C platform-specific types. + ctypes_prefix: { + ty: Option, + methods: { + /// Use the given prefix for the C platform-specific types instead of `::std::os::raw`. + /// + /// Alternatively, the [`Builder::use_core`] method can be used to set the prefix to + /// `::core::ffi` or `::core::os::raw`. + pub fn ctypes_prefix>(mut self, prefix: T) -> Builder { + self.options.ctypes_prefix = Some(prefix.into()); + self + } + }, + as_args: "--ctypes-prefix", + }, + /// The prefix for anonymous fields. + anon_fields_prefix: { + ty: String, + default: DEFAULT_ANON_FIELDS_PREFIX.into(), + methods: { + /// Use the given prefix for the anonymous fields. + /// + /// An anonymous field, is a field of a C/C++ type that does not have a name. For + /// example, in the following C code: + /// ```c + /// struct integer { + /// struct { + /// int inner; + /// }; + /// } + /// ``` + /// + /// The only field of the `integer` `struct` is an anonymous field and its Rust + /// representation will be named using this prefix followed by an integer identifier. + /// + /// The default prefix is `__bindgen_anon_`. + pub fn anon_fields_prefix>(mut self, prefix: T) -> Builder { + self.options.anon_fields_prefix = prefix.into(); + self + } + }, + as_args: |prefix, args| { + if prefix != DEFAULT_ANON_FIELDS_PREFIX { + args.push("--anon-fields-prefix".to_owned()); + args.push(prefix.clone()); + } + }, + }, + /// Whether to measure the time for each one of the `bindgen` phases. + time_phases: { + ty: bool, + methods: { + /// Set whether to measure the elapsed time for each one of the `bindgen` phases. This + /// information is printed to `stderr`. + /// + /// The elapsed time is not measured by default. + pub fn time_phases(mut self, doit: bool) -> Self { + self.options.time_phases = doit; + self + } + }, + as_args: "--time-phases", + }, + /// Whether to convert C float types to `f32` and `f64`. + convert_floats: { + ty: bool, + default: true, + methods: { + /// Avoid converting C float types to `f32` and `f64`. + pub fn no_convert_floats(mut self) -> Self { + self.options.convert_floats = false; + self + } + }, + as_args: |value, args| (!value).as_args(args, "--no-convert-floats"), + }, + /// The set of raw lines to be prepended to the top-level module of the generated Rust code. + raw_lines: { + ty: Vec, + methods: { + /// Add a line of Rust code at the beginning of the generated bindings. The string is + /// passed through without any modification. + pub fn raw_line>(mut self, arg: T) -> Self { + self.options.raw_lines.push(arg.into()); + self + } + }, + as_args: |raw_lines, args| { + for line in raw_lines { + args.push("--raw-line".to_owned()); + args.push(line.clone()); + } + }, + }, + /// The set of raw lines to prepend to different modules. + module_lines: { + ty: HashMap>, + methods: { + /// Add a given line to the beginning of a given module. + /// + /// This option only comes into effect if the [`Builder::enable_cxx_namespaces`] method + /// is also being called. + pub fn module_raw_line(mut self, module: T, line: U) -> Self + where + T: Into, + U: Into, + { + self.options + .module_lines + .entry(module.into()) + .or_insert_with(Vec::new) + .push(line.into()); + self + } + }, + as_args: |module_lines, args| { + for (module, lines) in module_lines { + for line in lines.iter() { + args.push("--module-raw-line".to_owned()); + args.push(module.clone()); + args.push(line.clone()); + } + } + }, + }, + /// The input header files. + input_headers: { + ty: Vec, + methods: { + /// Add an input C/C++ header to generate bindings for. + /// + /// This can be used to generate bindings for a single header: + /// + /// ```ignore + /// let bindings = bindgen::Builder::default() + /// .header("input.h") + /// .generate() + /// .unwrap(); + /// ``` + /// + /// Or for multiple headers: + /// + /// ```ignore + /// let bindings = bindgen::Builder::default() + /// .header("first.h") + /// .header("second.h") + /// .header("third.h") + /// .generate() + /// .unwrap(); + /// ``` + pub fn header>(mut self, header: T) -> Builder { + self.options.input_headers.push(header.into()); + self + } + }, + // This field is handled specially inside the macro. + as_args: ignore, + }, + /// The set of arguments to be passed straight through to Clang. + clang_args: { + ty: Vec, + methods: { + /// Add an argument to be passed straight through to Clang. + pub fn clang_arg>(self, arg: T) -> Builder { + self.clang_args([arg.into()]) + } + + /// Add several arguments to be passed straight through to Clang. + pub fn clang_args(mut self, args: I) -> Builder + where + I::Item: AsRef, + { + for arg in args { + self.options.clang_args.push(arg.as_ref().to_owned()); + } + self + } + }, + // This field is handled specially inside the macro. + as_args: ignore, + }, + /// Tuples of unsaved file contents of the form (name, contents). + input_header_contents: { + ty: Vec<(String, String)>, + methods: { + /// Add `contents` as an input C/C++ header named `name`. + /// + /// This can be used to inject additional C/C++ code as an input without having to + /// create additional header files. + pub fn header_contents(mut self, name: &str, contents: &str) -> Builder { + // Apparently clang relies on having virtual FS correspondent to + // the real one, so we need absolute paths here + let absolute_path = env::current_dir() + .expect("Cannot retrieve current directory") + .join(name) + .to_str() + .expect("Cannot convert current directory name to string") + .to_owned(); + self.options + .input_header_contents + .push((absolute_path, contents.into())); + self + } + }, + // Header contents cannot be added from the CLI. + as_args: ignore, + }, + /// A user-provided visitor to allow customizing different kinds of situations. + parse_callbacks: { + ty: Vec>, + methods: { + /// Add a new [`ParseCallbacks`] instance to configure types in different situations. + pub fn parse_callbacks(mut self, cb: Box) -> Self { + self.options.parse_callbacks.push(Rc::from(cb)); + self + } + }, + as_args: |parse_callbacks, args| { + #[cfg(feature = "__cli")] + for callbacks in parse_callbacks { + args.extend(callbacks.cli_args()); + } + }, + }, + /// Which kind of items should we generate. We generate all of them by default. + codegen_config: { + ty: CodegenConfig, + default: CodegenConfig::all(), + methods: { + /// Do not generate any functions. + /// + /// Functions are generated by default. + pub fn ignore_functions(mut self) -> Builder { + self.options.codegen_config.remove(CodegenConfig::FUNCTIONS); + self + } + + /// Do not generate any methods. + /// + /// Methods are generated by default. + pub fn ignore_methods(mut self) -> Builder { + self.options.codegen_config.remove(CodegenConfig::METHODS); + self + } + + /// Choose what to generate using a [`CodegenConfig`]. + /// + /// This option overlaps with [`Builder::ignore_functions`] and + /// [`Builder::ignore_methods`]. + /// + /// All the items in `CodegenConfig` are generated by default. + pub fn with_codegen_config(mut self, config: CodegenConfig) -> Self { + self.options.codegen_config = config; + self + } + }, + as_args: |codegen_config, args| { + if !codegen_config.functions() { + args.push("--ignore-functions".to_owned()); + } + + args.push("--generate".to_owned()); + + //Temporary placeholder for the 4 options below. + let mut options: Vec = Vec::new(); + if codegen_config.functions() { + options.push("functions".to_owned()); + } + + if codegen_config.types() { + options.push("types".to_owned()); + } + + if codegen_config.vars() { + options.push("vars".to_owned()); + } + + if codegen_config.methods() { + options.push("methods".to_owned()); + } + + if codegen_config.constructors() { + options.push("constructors".to_owned()); + } + + if codegen_config.destructors() { + options.push("destructors".to_owned()); + } + + args.push(options.join(",")); + + if !codegen_config.methods() { + args.push("--ignore-methods".to_owned()); + } + }, + }, + /// Whether to treat inline namespaces conservatively. + conservative_inline_namespaces: { + ty: bool, + methods: { + /// Treat inline namespaces conservatively. + /// + /// This is tricky, because in C++ is technically legal to override an item + /// defined in an inline namespace: + /// + /// ```cpp + /// inline namespace foo { + /// using Bar = int; + /// } + /// using Bar = long; + /// ``` + /// + /// Even though referencing `Bar` is a compiler error. + /// + /// We want to support this (arguably esoteric) use case, but we do not want to make + /// the rest of `bindgen` users pay an usability penalty for that. + /// + /// To support this, we need to keep all the inline namespaces around, but then using + /// `bindgen` becomes a bit more difficult, because you cannot reference paths like + /// `std::string` (you'd need to use the proper inline namespace). + /// + /// We could complicate a lot of the logic to detect name collisions and, in the + /// absence of collisions, generate a `pub use inline_ns::*` or something like that. + /// + /// That is probably something we can do to improve the usability of this option if we + /// realize it is needed way more often. Our guess is that this extra logic is not + /// going to be very useful. + /// + /// This option is disabled by default. + pub fn conservative_inline_namespaces(mut self) -> Builder { + self.options.conservative_inline_namespaces = true; + self + } + }, + as_args: "--conservative-inline-namespaces", + }, + /// Whether to keep documentation comments in the generated output. + generate_comments: { + ty: bool, + default: true, + methods: { + /// Set whether the generated bindings should contain documentation comments. + /// + /// Documentation comments are included by default. + /// + /// Note that clang excludes comments from system headers by default, pass + /// `"-fretain-comments-from-system-headers"` to the [`Builder::clang_arg`] method to + /// include them. + /// + /// It is also possible to process all comments and not just documentation using the + /// `"-fparse-all-comments"` flag. Check [these slides on clang comment parsing]( + /// https://llvm.org/devmtg/2012-11/Gribenko_CommentParsing.pdf) for more information + /// and examples. + pub fn generate_comments(mut self, doit: bool) -> Self { + self.options.generate_comments = doit; + self + } + }, + as_args: |value, args| (!value).as_args(args, "--no-doc-comments"), + }, + /// Whether to generate inline functions. + generate_inline_functions: { + ty: bool, + methods: { + /// Set whether to generate inline functions. + /// + /// This option is disabled by default. + /// + /// Note that they will usually not work. However you can use `-fkeep-inline-functions` + /// or `-fno-inline-functions` if you are responsible of compiling the library to make + /// them callable. + #[cfg_attr( + features = "experimental", + doc = "\nCheck the [`Builder::wrap_static_fns`] method for an alternative." + )] + pub fn generate_inline_functions(mut self, doit: bool) -> Self { + self.options.generate_inline_functions = doit; + self + } + }, + as_args: "--generate-inline-functions", + }, + /// Whether to allowlist types recursively. + allowlist_recursively: { + ty: bool, + default: true, + methods: { + /// Set whether to recursively allowlist items. + /// + /// Items are allowlisted recursively by default. + /// + /// Given that we have explicitly allowlisted the `initiate_dance_party` function in + /// this C header: + /// + /// ```c + /// typedef struct MoonBoots { + /// int bouncy_level; + /// } MoonBoots; + /// + /// void initiate_dance_party(MoonBoots* boots); + /// ``` + /// + /// We would normally generate bindings to both the `initiate_dance_party` function and + /// the `MoonBoots` type that it transitively references. If `false` is passed to this + /// method, `bindgen` will not emit bindings for anything except the explicitly + /// allowlisted items, meaning that the definition for `MoonBoots` would not be + /// generated. However, the `initiate_dance_party` function would still reference + /// `MoonBoots`! + /// + /// **Disabling this feature will almost certainly cause `bindgen` to emit bindings + /// that will not compile!** If you disable this feature, then it is *your* + /// responsibility to provide definitions for every type that is referenced from an + /// explicitly allowlisted item. One way to provide the missing definitions is by using + /// the [`Builder::raw_line`] method, another would be to define them in Rust and then + /// `include!(...)` the bindings immediately afterwards. + pub fn allowlist_recursively(mut self, doit: bool) -> Self { + self.options.allowlist_recursively = doit; + self + } + }, + as_args: |value, args| (!value).as_args(args, "--no-recursive-allowlist"), + }, + /// Whether to emit `#[macro_use] extern crate objc;` instead of `use objc;` in the prologue of + /// the files generated from objective-c files. + objc_extern_crate: { + ty: bool, + methods: { + /// Emit `#[macro_use] extern crate objc;` instead of `use objc;` in the prologue of + /// the files generated from objective-c files. + /// + /// `use objc;` is emitted by default. + pub fn objc_extern_crate(mut self, doit: bool) -> Self { + self.options.objc_extern_crate = doit; + self + } + }, + as_args: "--objc-extern-crate", + }, + /// Whether to generate proper block signatures instead of `void` pointers. + generate_block: { + ty: bool, + methods: { + /// Generate proper block signatures instead of `void` pointers. + /// + /// `void` pointers are used by default. + pub fn generate_block(mut self, doit: bool) -> Self { + self.options.generate_block = doit; + self + } + }, + as_args: "--generate-block", + }, + /// Whether to emit `#[macro_use] extern crate block;` instead of `use block;` in the prologue + /// of the files generated from apple block files. + block_extern_crate: { + ty: bool, + methods: { + /// Emit `#[macro_use] extern crate block;` instead of `use block;` in the prologue of + /// the files generated from apple block files. + /// + /// `use block;` is emitted by default. + pub fn block_extern_crate(mut self, doit: bool) -> Self { + self.options.block_extern_crate = doit; + self + } + }, + as_args: "--block-extern-crate", + }, + /// Whether to use the clang-provided name mangling. + enable_mangling: { + ty: bool, + default: true, + methods: { + /// Set whether to use the clang-provided name mangling. This is probably needed for + /// C++ features. + /// + /// The mangling provided by clang is used by default. + /// + /// We allow disabling this option because some old `libclang` versions seem to return + /// incorrect results in some cases for non-mangled functions, check [#528] for more + /// information. + /// + /// [#528]: https://github.com/rust-lang/rust-bindgen/issues/528 + pub fn trust_clang_mangling(mut self, doit: bool) -> Self { + self.options.enable_mangling = doit; + self + } + + }, + as_args: |value, args| (!value).as_args(args, "--distrust-clang-mangling"), + }, + /// Whether to detect include paths using `clang_sys`. + detect_include_paths: { + ty: bool, + default: true, + methods: { + /// Set whether to detect include paths using `clang_sys`. + /// + /// `clang_sys` is used to detect include paths by default. + pub fn detect_include_paths(mut self, doit: bool) -> Self { + self.options.detect_include_paths = doit; + self + } + }, + as_args: |value, args| (!value).as_args(args, "--no-include-path-detection"), + }, + /// Whether we should try to fit macro constants into types smaller than `u32` and `i32`. + fit_macro_constants: { + ty: bool, + methods: { + /// Set whether `bindgen` should try to fit macro constants into types smaller than `u32` + /// and `i32`. + /// + /// This option is disabled by default. + pub fn fit_macro_constants(mut self, doit: bool) -> Self { + self.options.fit_macro_constants = doit; + self + } + }, + as_args: "--fit-macro-constant-types", + }, + /// Whether to prepend the `enum` name to constant or newtype variants. + prepend_enum_name: { + ty: bool, + default: true, + methods: { + /// Set whether to prepend the `enum` name to constant or newtype variants. + /// + /// The `enum` name is prepended by default. + pub fn prepend_enum_name(mut self, doit: bool) -> Self { + self.options.prepend_enum_name = doit; + self + } + }, + as_args: |value, args| (!value).as_args(args, "--no-prepend-enum-name"), + }, + /// Version of the Rust compiler to target. + rust_target: { + ty: RustTarget, + methods: { + /// Specify the Rust target version. + /// + /// The default target is the latest stable Rust version. + pub fn rust_target(mut self, rust_target: RustTarget) -> Self { + #[allow(deprecated)] + if rust_target <= RustTarget::Stable_1_30 { + warn!( + "The {} rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues", + String::from(rust_target) + ); + } + self.options.set_rust_target(rust_target); + self + } + }, + as_args: |rust_target, args| { + args.push("--rust-target".to_owned()); + args.push((*rust_target).into()); + }, + }, + /// Features to be enabled. They are derived from `rust_target`. + rust_features: { + ty: RustFeatures, + default: RustTarget::default().into(), + methods: { + /// Disable support for native Rust unions, if supported. + /// + /// The default value of this option is set based on the value passed to + /// [`Builder::rust_target`]. + pub fn disable_untagged_union(mut self) -> Self { + self.options.rust_features.untagged_union = false; + self + } + }, + as_args: |features, args| { + // FIXME(emilio): This is a bit hacky, maybe we should stop re-using the + // RustFeatures to store the "disable_untagged_union" call, and make it + // a different flag that we check elsewhere / in generate(). + if !features.untagged_union { + args.push("--disable-untagged-union".to_owned()); + } + }, + }, + /// Whether we should record which items in the regex sets did match any C items. + record_matches: { + ty: bool, + default: true, + methods: { + /// Set whether we should record which items in our regex sets did match any C items. + /// + /// Matches are recorded by default. + pub fn record_matches(mut self, doit: bool) -> Self { + self.options.record_matches = doit; + self + } + + }, + as_args: |value, args| (!value).as_args(args, "--no-record-matches"), + }, + /// Whether `size_t` should be translated to `usize` automatically. + size_t_is_usize: { + ty: bool, + default: true, + methods: { + /// Set whether `size_t` should be translated to `usize`. + /// + /// `size_t` is translated to `usize` by default. + pub fn size_t_is_usize(mut self, is: bool) -> Self { + self.options.size_t_is_usize = is; + self + } + }, + as_args: |value, args| (!value).as_args(args, "--no-size_t-is-usize"), + }, + /// The tool that should be used to format the generated bindings. + formatter: { + ty: Formatter, + methods: { + #[cfg_attr(feature = "prettyplease", deprecated)] + /// Set whether `rustfmt` should be used to format the generated bindings. + /// + /// `rustfmt` is used by default. + /// + /// This method overlaps in functionality with the more general [`Builder::formatter`]. + /// Thus, the latter should be preferred. + pub fn rustfmt_bindings(mut self, doit: bool) -> Self { + self.options.formatter = if doit { + Formatter::Rustfmt + } else { + Formatter::None + }; + self + } + + /// Set which tool should be used to format the generated bindings. + /// + /// The default formatter is [`Formatter::Rustfmt`]. + /// + /// To be able to use `prettyplease` as a formatter, the `"prettyplease"` feature for + /// `bindgen` must be enabled in the Cargo manifest. + pub fn formatter(mut self, formatter: Formatter) -> Self { + self.options.formatter = formatter; + self + } + }, + as_args: |formatter, args| { + if *formatter != Default::default() { + args.push("--formatter".to_owned()); + args.push(formatter.to_string()); + } + }, + }, + /// The absolute path to the `rustfmt` configuration file. + rustfmt_configuration_file: { + ty: Option, + methods: { + /// Set the absolute path to the `rustfmt` configuration file. + /// + /// The default `rustfmt` options are used if `None` is passed to this method or if + /// this method is not called at all. + /// + /// Calling this method will set the [`Bindings::rustfmt_bindings`] option to `true` + /// and the [`Bindings::formatter`] option to [`Formatter::Rustfmt`]. + pub fn rustfmt_configuration_file(mut self, path: Option) -> Self { + self = self.formatter(Formatter::Rustfmt); + self.options.rustfmt_configuration_file = path; + self + } + }, + as_args: "--rustfmt-configuration-file", + }, + /// Types that should not derive `PartialEq`. + no_partialeq_types: { + ty: RegexSet, + methods: { + regex_option! { + /// Do not derive `PartialEq` for a given type. + pub fn no_partialeq>(mut self, arg: T) -> Builder { + self.options.no_partialeq_types.insert(arg.into()); + self + } + } + }, + as_args: "--no-partialeq", + }, + /// Types that should not derive `Copy`. + no_copy_types: { + ty: RegexSet, + methods: { + regex_option! { + /// Do not derive `Copy` and `Clone` for a given type. + pub fn no_copy>(mut self, arg: T) -> Self { + self.options.no_copy_types.insert(arg.into()); + self + } + } + }, + as_args: "--no-copy", + }, + /// Types that should not derive `Debug`. + no_debug_types: { + ty: RegexSet, + methods: { + regex_option! { + /// Do not derive `Debug` for a given type. + pub fn no_debug>(mut self, arg: T) -> Self { + self.options.no_debug_types.insert(arg.into()); + self + } + } + }, + as_args: "--no-debug", + }, + /// Types that should not derive or implement `Default`. + no_default_types: { + ty: RegexSet, + methods: { + regex_option! { + /// Do not derive or implement `Default` for a given type. + pub fn no_default>(mut self, arg: T) -> Self { + self.options.no_default_types.insert(arg.into()); + self + } + } + }, + as_args: "--no-default", + }, + /// Types that should not derive `Hash`. + no_hash_types: { + ty: RegexSet, + methods: { + regex_option! { + /// Do not derive `Hash` for a given type. + pub fn no_hash>(mut self, arg: T) -> Builder { + self.options.no_hash_types.insert(arg.into()); + self + } + } + }, + as_args: "--no-hash", + }, + /// Types that should be annotated with `#[must_use]`. + must_use_types: { + ty: RegexSet, + methods: { + regex_option! { + /// Annotate the given type with the `#[must_use]` attribute. + pub fn must_use_type>(mut self, arg: T) -> Builder { + self.options.must_use_types.insert(arg.into()); + self + } + } + }, + as_args: "--must-use-type", + }, + /// Whether C arrays should be regular pointers in rust or array pointers + array_pointers_in_arguments: { + ty: bool, + methods: { + /// Translate arrays `T arr[size]` into array pointers `*mut [T; size]` instead of + /// translating them as `*mut T` which is the default. + /// + /// The same is done for `*const` pointers. + pub fn array_pointers_in_arguments(mut self, doit: bool) -> Self { + self.options.array_pointers_in_arguments = doit; + self + } + + }, + as_args: "--use-array-pointers-in-arguments", + }, + /// The name of the `wasm_import_module`. + wasm_import_module_name: { + ty: Option, + methods: { + /// Adds the `#[link(wasm_import_module = import_name)]` attribute to all the `extern` + /// blocks generated by `bindgen`. + /// + /// This attribute is not added by default. + pub fn wasm_import_module_name>( + mut self, + import_name: T, + ) -> Self { + self.options.wasm_import_module_name = Some(import_name.into()); + self + } + }, + as_args: "--wasm-import-module-name", + }, + /// The name of the dynamic library (if we are generating bindings for a shared library). + dynamic_library_name: { + ty: Option, + methods: { + /// Generate bindings for a shared library with the given name. + /// + /// This option is disabled by default. + pub fn dynamic_library_name>( + mut self, + dynamic_library_name: T, + ) -> Self { + self.options.dynamic_library_name = Some(dynamic_library_name.into()); + self + } + }, + as_args: "--dynamic-loading", + }, + /// Whether to equire successful linkage for all routines in a shared library. + dynamic_link_require_all: { + ty: bool, + methods: { + /// Set whether to require successful linkage for all routines in a shared library. + /// This allows us to optimize function calls by being able to safely assume function + /// pointers are valid. + /// + /// This option only comes into effect if the [`Builder::dynamic_library_name`] option + /// is set. + /// + /// This option is disabled by default. + pub fn dynamic_link_require_all(mut self, req: bool) -> Self { + self.options.dynamic_link_require_all = req; + self + } + }, + as_args: "--dynamic-link-require-all", + }, + /// Whether to only make generated bindings `pub` if the items would be publicly accessible by + /// C++. + respect_cxx_access_specs: { + ty: bool, + methods: { + /// Set whether to respect the C++ access specifications. + /// + /// Passing `true` to this method will set the visibility of the generated Rust items + /// as `pub` only if the corresponding C++ items are publicly accessible instead of + /// marking all the items as public, which is the default. + pub fn respect_cxx_access_specs(mut self, doit: bool) -> Self { + self.options.respect_cxx_access_specs = doit; + self + } + + }, + as_args: "--respect-cxx-access-specs", + }, + /// Whether to translate `enum` integer types to native Rust integer types. + translate_enum_integer_types: { + ty: bool, + methods: { + /// Set whether to always translate `enum` integer types to native Rust integer types. + /// + /// Passing `true` to this method will result in `enum`s having types such as `u32` and + /// `i16` instead of `c_uint` and `c_short` which is the default. The `#[repr]` types + /// of Rust `enum`s are always translated to Rust integer types. + pub fn translate_enum_integer_types(mut self, doit: bool) -> Self { + self.options.translate_enum_integer_types = doit; + self + } + }, + as_args: "--translate-enum-integer-types", + }, + /// Whether to generate types with C style naming. + c_naming: { + ty: bool, + methods: { + /// Set whether to generate types with C style naming. + /// + /// Passing `true` to this method will add prefixes to the generated type names. For + /// example, instead of a `struct` with name `A` we will generate a `struct` with + /// `struct_A`. Currently applies to `struct`s, `union`s, and `enum`s. + pub fn c_naming(mut self, doit: bool) -> Self { + self.options.c_naming = doit; + self + } + }, + as_args: "--c-naming", + }, + /// Wether to always emit explicit padding fields. + force_explicit_padding: { + ty: bool, + methods: { + /// Set whether to always emit explicit padding fields. + /// + /// This option should be enabled if a `struct` needs to be serialized in its native + /// format (padding bytes and all). This could be required if such `struct` will be + /// written to a file or sent over the network, as anything reading the padding bytes + /// of a struct may cause undefined behavior. + /// + /// Padding fields are not emitted by default. + pub fn explicit_padding(mut self, doit: bool) -> Self { + self.options.force_explicit_padding = doit; + self + } + }, + as_args: "--explicit-padding", + }, + /// Whether to emit vtable functions. + vtable_generation: { + ty: bool, + methods: { + /// Set whether to enable experimental support to generate virtual table functions. + /// + /// This option should mostly work, though some edge cases are likely to be broken. + /// + /// Virtual table generation is disabled by default. + pub fn vtable_generation(mut self, doit: bool) -> Self { + self.options.vtable_generation = doit; + self + } + }, + as_args: "--vtable-generation", + }, + /// Whether to sort the generated Rust items. + sort_semantically: { + ty: bool, + methods: { + /// Set whether to sort the generated Rust items in a predefined manner. + /// + /// Items are not ordered by default. + pub fn sort_semantically(mut self, doit: bool) -> Self { + self.options.sort_semantically = doit; + self + } + }, + as_args: "--sort-semantically", + }, + /// Whether to deduplicate `extern` blocks. + merge_extern_blocks: { + ty: bool, + methods: { + /// Merge all extern blocks under the same module into a single one. + /// + /// Extern blocks are not merged by default. + pub fn merge_extern_blocks(mut self, doit: bool) -> Self { + self.options.merge_extern_blocks = doit; + self + } + }, + as_args: "--merge-extern-blocks", + }, + /// Whether to wrap unsafe operations in unsafe blocks. + wrap_unsafe_ops: { + ty: bool, + methods: { + /// Wrap all unsafe operations in unsafe blocks. + /// + /// Unsafe operations are not wrapped by default. + pub fn wrap_unsafe_ops(mut self, doit: bool) -> Self { + self.options.wrap_unsafe_ops = doit; + self + } + }, + as_args: "--wrap-unsafe-ops", + }, + /// Patterns for functions whose ABI should be overriden. + abi_overrides: { + ty: HashMap, + methods: { + regex_option! { + /// Override the ABI of a given function. + pub fn override_abi>(mut self, abi: Abi, arg: T) -> Self { + self.options + .abi_overrides + .entry(abi) + .or_default() + .insert(arg.into()); + self + } + } + }, + as_args: |overrides, args| { + for (abi, set) in overrides { + for item in set.get_items() { + args.push("--override-abi".to_owned()); + args.push(format!("{}={}", item, abi)); + } + } + }, + }, + /// Whether to generate wrappers for `static` functions. + wrap_static_fns: { + ty: bool, + methods: { + #[cfg(feature = "experimental")] + /// Set whether to generate wrappers for `static`` functions. + /// + /// Passing `true` to this method will generate a C source file with non-`static` + /// functions that call the `static` functions found in the input headers and can be + /// called from Rust once the source file is compiled. + /// + /// The path of this source file can be set using the [`Builder::wrap_static_fns_path`] + /// method. + pub fn wrap_static_fns(mut self, doit: bool) -> Self { + self.options.wrap_static_fns = doit; + self + } + }, + as_args: "--wrap-static-fns", + }, + /// The suffix to be added to the function wrappers for `static` functions. + wrap_static_fns_suffix: { + ty: Option, + methods: { + #[cfg(feature = "experimental")] + /// Set the suffix added to the wrappers for `static` functions. + /// + /// This option only comes into effect if `true` is passed to the + /// [`Builder::wrap_static_fns`] method. + /// + /// The default suffix is `__extern`. + pub fn wrap_static_fns_suffix>(mut self, suffix: T) -> Self { + self.options.wrap_static_fns_suffix = Some(suffix.as_ref().to_owned()); + self + } + }, + as_args: "--wrap-static-fns-suffix", + }, + /// The path of the file where the wrappers for `static` functions will be emitted. + wrap_static_fns_path: { + ty: Option, + methods: { + #[cfg(feature = "experimental")] + /// Set the path for the source code file that would be created if any wrapper + /// functions must be generated due to the presence of `static` functions. + /// + /// `bindgen` will automatically add the right extension to the header and source code + /// files. + /// + /// This option only comes into effect if `true` is passed to the + /// [`Builder::wrap_static_fns`] method. + /// + /// The default path is `temp_dir/bindgen/extern`, where `temp_dir` is the path + /// returned by [`std::fs::temp_dir`] . + pub fn wrap_static_fns_path>(mut self, path: T) -> Self { + self.options.wrap_static_fns_path = Some(path.as_ref().to_owned()); + self + } + }, + as_args: "--wrap-static-fns-path", + }, + /// Default visibility of fields. + default_visibility: { + ty: FieldVisibilityKind, + methods: { + /// Set the default visibility of fields, including bitfields and accessor methods for + /// bitfields. + /// + /// This option only comes into effect if the [`Builder::respect_cxx_access_specs`] + /// option is disabled. + pub fn default_visibility( + mut self, + visibility: FieldVisibilityKind, + ) -> Self { + self.options.default_visibility = visibility; + self + } + }, + as_args: |visibility, args| { + if *visibility != Default::default() { + args.push("--default-visibility".to_owned()); + args.push(visibility.to_string()); + } + }, + }, +} From 2ab66fdffba5f2a03982f2cc3f7cdd98aa277b42 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Mon, 3 Apr 2023 12:10:16 -0500 Subject: [PATCH 482/942] Add the `--emit-diagnostics` flag (#2436) * Add the `--emit-diagnostics` flag * remove test * add(diagnostics): var.rs and lib.rs module have a function each * add(diagnostics): rustfmt * add(diagnostics): docs moved to book * add(diagnostics): wip, saving location * add(diagnostics): wip, saving location * add(diagnostics): add line number and origin file to slice * add(diagnostics): unused var name cleanup * revert(diagnostics): changes to line number, before merging Christian's * Add API for slice locations * Emit diagnostic for unsupported ABIs * add(diagnostics): line number and file names to diagnostics * chore: fmt * add(diagnostics): label to say 'from bindgen' * add(diagnostics): add_footer, add a warning with footer info * add(diagnostics): add a warning with footer info * add(diagnostics): add a warning in the Diagnostics instead of copying everywhere * Remove IDs that are not shown and use `diagnostic` instead of `warning` * Remove unused function * Deduplciate log entry * Introduce `Level` * Fix clippy warning * Simplify duplicated macro diagnostic * Unify source extraction * Simplify non-fatal rustfmt error diagnostic * Print all diagnostic lines when using `cargo:warning` * Put all the diagnostic logic under the experimental flag * Avoid `bool` parameters * Clean rebase debris * Disable duplicated macros warning for now * Emit warning when using a deprecated Rust target * Document the `emit_diagnostics` method * Update Changelog * Remove diagnostics section from book. Diagnostics are prone to change so keeping the book up to date might require some automation. * Run rustfmt * Fix clippy warning * Remove file added by accident --------- Co-authored-by: Amanjeev Sethi --- CHANGELOG.md | 5 + Cargo.lock | 26 +++++ bindgen-cli/options.rs | 33 +++++-- bindgen-tests/tests/tests.rs | 16 --- bindgen/Cargo.toml | 5 +- bindgen/codegen/mod.rs | 76 ++++++++++++-- bindgen/diagnostics.rs | 185 +++++++++++++++++++++++++++++++++++ bindgen/ir/context.rs | 43 ++++---- bindgen/ir/var.rs | 48 ++++++++- bindgen/lib.rs | 124 ++++++++++++++++++----- bindgen/options/mod.rs | 28 ++++-- bindgen/regex_set.rs | 109 ++++++++++++++++++++- 12 files changed, 615 insertions(+), 83 deletions(-) create mode 100644 bindgen/diagnostics.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 96ecd945e8..ffdd28666d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -171,6 +171,9 @@ which tool will be used to format the bindings. The `Formatter::Prettyplease` variant is only available if the `"prettyplease"` feature is enabled. + * Added the `Builder::emit_diagnostics` method and the `--emit-diagnostics` + flag to enable emission of diagnostic messages. + ## Changed * Static functions with no arguments use `void` as their single argument instead of having no arguments when the `--wrap-static-fns` flag is used. @@ -187,6 +190,8 @@ * The following deprecated flags were removed: `--use-msvc-mangling`, `--rustfmt-bindings` and `--size_t-is-usize`. * The `--no-rustfmt-bindings` flag was removed in favor of `--formatter=none`. + * The `Bindings::emit_warnings` and `Bindings::warnings` methods were removed + in favor of `--emit-diagnostics`. ## Fixed diff --git a/Cargo.lock b/Cargo.lock index 984295e86c..38cc59ff62 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,10 +11,21 @@ dependencies = [ "memchr", ] +[[package]] +name = "annotate-snippets" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3b9d411ecbaf79885c6df4d75fff75858d5995ff25385657a28af47e82f9c36" +dependencies = [ + "unicode-width", + "yansi-term", +] + [[package]] name = "bindgen" version = "0.64.0" dependencies = [ + "annotate-snippets", "bitflags", "cexpr", "clang-sys", @@ -586,6 +597,12 @@ version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" +[[package]] +name = "unicode-width" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" + [[package]] name = "version_check" version = "0.9.4" @@ -696,3 +713,12 @@ name = "windows_x86_64_msvc" version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" + +[[package]] +name = "yansi-term" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe5c30ade05e61656247b2e334a031dfd0cc466fadef865bdcdea8d537951bf1" +dependencies = [ + "winapi", +] diff --git a/bindgen-cli/options.rs b/bindgen-cli/options.rs index 468ea1cc56..3d87fc1bc6 100644 --- a/bindgen-cli/options.rs +++ b/bindgen-cli/options.rs @@ -369,6 +369,9 @@ struct BindgenCommand { /// bitfields. This flag is ignored if the `--respect-cxx-access-specs` flag is used. #[arg(long, value_name = "VISIBILITY")] default_visibility: Option, + /// Whether to emit diagnostics or not. + #[arg(long, requires = "experimental")] + emit_diagnostics: bool, /// Enables experimental features. #[arg(long)] experimental: bool, @@ -495,6 +498,7 @@ where wrap_static_fns_path, wrap_static_fns_suffix, default_visibility, + emit_diagnostics, experimental: _, version, clang_args, @@ -997,12 +1001,25 @@ where } } - for (custom_derives, kind) in [ - (with_derive_custom, None), - (with_derive_custom_struct, Some(TypeKind::Struct)), - (with_derive_custom_enum, Some(TypeKind::Enum)), - (with_derive_custom_union, Some(TypeKind::Union)), + for (custom_derives, kind, name) in [ + (with_derive_custom, None, "--with-derive-custom"), + ( + with_derive_custom_struct, + Some(TypeKind::Struct), + "--with-derive-custom-struct", + ), + ( + with_derive_custom_enum, + Some(TypeKind::Enum), + "--with-derive-custom-enum", + ), + ( + with_derive_custom_union, + Some(TypeKind::Union), + "--with-derive-custom-union", + ), ] { + let name = emit_diagnostics.then(|| name); for custom_derive in custom_derives { let (regex, derives) = custom_derive .rsplit_once('=') @@ -1011,7 +1028,7 @@ where let mut regex_set = RegexSet::new(); regex_set.insert(regex); - regex_set.build(false); + regex_set.build_with_diagnostics(false, name); builder = builder.parse_callbacks(Box::new(CustomDeriveCallback { derives, @@ -1037,5 +1054,9 @@ where builder = builder.default_visibility(visibility); } + if emit_diagnostics { + builder = builder.emit_diagnostics(); + } + Ok((builder, output, verbose)) } diff --git a/bindgen-tests/tests/tests.rs b/bindgen-tests/tests/tests.rs index e27f29a6a6..7a03952196 100644 --- a/bindgen-tests/tests/tests.rs +++ b/bindgen-tests/tests/tests.rs @@ -672,22 +672,6 @@ fn dump_preprocessed_input() { ); } -#[test] -fn allowlist_warnings() { - let header = concat!( - env!("CARGO_MANIFEST_DIR"), - "/tests/headers/allowlist_warnings.h" - ); - - let bindings = builder() - .header(header) - .allowlist_function("doesnt_match_anything") - .generate() - .expect("unable to generate bindings"); - - assert_eq!(1, bindings.warnings().len()); -} - fn build_flags_output_helper(builder: &bindgen::Builder) { let mut command_line_flags = builder.command_line_flags(); command_line_flags.insert(0, "bindgen".to_string()); diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index 2b27f2a1fd..93275c1615 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -35,7 +35,8 @@ quote = { version = "1", default-features = false } syn = { version = "2.0", features = ["full", "extra-traits", "visit-mut"]} regex = { version = "1.5", default-features = false , features = ["std", "unicode"] } which = { version = "4.2.1", optional = true, default-features = false } -prettyplease = { version = "0.2.0", optional = true} +prettyplease = { version = "0.2.0", optional = true } +annotate-snippets = { version = "0.9.1", features = ["color"], optional = true } shlex = "1" rustc-hash = "1.0.1" proc-macro2 = { version = "1", default-features = false } @@ -49,7 +50,7 @@ runtime = ["clang-sys/runtime"] # Dynamically discover a `rustfmt` binary using the `which` crate which-rustfmt = ["which"] __cli = [] -experimental = [] +experimental = ["annotate-snippets"] # These features only exist for CI testing -- don't use them if you're not hacking # on bindgen! diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 508c1ed892..9d1956f37b 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -4213,23 +4213,43 @@ impl CodeGenerator for Function { ClangAbi::Known(Abi::ThisCall) if !ctx.options().rust_features().thiscall_abi => { - warn!("Skipping function with thiscall ABI that isn't supported by the configured Rust target"); + unsupported_abi_diagnostic::( + name, + item.location(), + "thiscall", + ctx, + ); return None; } ClangAbi::Known(Abi::Vectorcall) if !ctx.options().rust_features().vectorcall_abi => { - warn!("Skipping function with vectorcall ABI that isn't supported by the configured Rust target"); + unsupported_abi_diagnostic::( + name, + item.location(), + "vectorcall", + ctx, + ); return None; } ClangAbi::Known(Abi::CUnwind) if !ctx.options().rust_features().c_unwind_abi => { - warn!("Skipping function with C-unwind ABI that isn't supported by the configured Rust target"); + unsupported_abi_diagnostic::( + name, + item.location(), + "C-unwind", + ctx, + ); return None; } ClangAbi::Known(Abi::Win64) if signature.is_variadic() => { - warn!("Skipping variadic function with Win64 ABI that isn't supported"); + unsupported_abi_diagnostic::( + name, + item.location(), + "Win64", + ctx, + ); return None; } ClangAbi::Unknown(unknown_abi) => { @@ -4316,6 +4336,51 @@ impl CodeGenerator for Function { } } +fn unsupported_abi_diagnostic( + fn_name: &str, + location: Option<&crate::clang::SourceLocation>, + abi: &str, + ctx: &BindgenContext, +) { + warn!( + "Skipping {}function `{}` with the {} ABI that isn't supported by the configured Rust target", + if VARIADIC { "variadic " } else { "" }, + fn_name, + abi + ); + + #[cfg(feature = "experimental")] + if ctx.options().emit_diagnostics { + use crate::diagnostics::{get_line, Diagnostic, Level, Slice}; + + let mut diag = Diagnostic::default(); + diag + .with_title(format!( + "The `{}` {}function uses the {} ABI which is not supported by the configured Rust target", + fn_name, + if VARIADIC { "variadic " } else { "" }, + abi), Level::Warn) + .add_annotation("No code will be generated for this function.", Level::Warn) + .add_annotation(format!("The configured Rust version is {}.", String::from(ctx.options().rust_target)), Level::Note); + + if let Some(loc) = location { + let (file, line, col, _) = loc.location(); + + if let Some(filename) = file.name() { + if let Ok(Some(source)) = get_line(&filename, line) { + let mut slice = Slice::default(); + slice + .with_source(source) + .with_location(filename, line, col); + diag.add_slice(slice); + } + } + } + + diag.display() + } +} + fn objc_method_codegen( ctx: &BindgenContext, method: &ObjCMethod, @@ -4586,8 +4651,7 @@ impl CodeGenerator for ObjCInterface { pub(crate) fn codegen( context: BindgenContext, -) -> Result<(proc_macro2::TokenStream, BindgenOptions, Vec), CodegenError> -{ +) -> Result<(proc_macro2::TokenStream, BindgenOptions), CodegenError> { context.gen(|context| { let _t = context.timer("codegen"); let counter = Cell::new(0); diff --git a/bindgen/diagnostics.rs b/bindgen/diagnostics.rs new file mode 100644 index 0000000000..82d5359d97 --- /dev/null +++ b/bindgen/diagnostics.rs @@ -0,0 +1,185 @@ +//! Types and function used to emit pretty diagnostics for `bindgen`. +//! +//! The entry point of this module is the [`Diagnostic`] type. + +use std::fmt::Write; +use std::io::{self, BufRead, BufReader}; +use std::{borrow::Cow, fs::File}; + +use annotate_snippets::{ + display_list::{DisplayList, FormatOptions}, + snippet::{Annotation, Slice as ExtSlice, Snippet}, +}; + +use annotate_snippets::snippet::AnnotationType; + +#[derive(Clone, Copy, Debug)] +pub(crate) enum Level { + Error, + Warn, + Info, + Note, + Help, +} + +impl From for AnnotationType { + fn from(level: Level) -> Self { + match level { + Level::Error => Self::Error, + Level::Warn => Self::Warning, + Level::Info => Self::Info, + Level::Note => Self::Note, + Level::Help => Self::Help, + } + } +} + +/// A `bindgen` diagnostic. +#[derive(Default)] +pub(crate) struct Diagnostic<'a> { + title: Option<(Cow<'a, str>, Level)>, + slices: Vec>, + footer: Vec<(Cow<'a, str>, Level)>, +} + +impl<'a> Diagnostic<'a> { + /// Add a title to the diagnostic and set its type. + pub(crate) fn with_title( + &mut self, + title: impl Into>, + level: Level, + ) -> &mut Self { + self.title = Some((title.into(), level)); + self + } + + /// Add a slice of source code to the diagnostic. + pub(crate) fn add_slice(&mut self, slice: Slice<'a>) -> &mut Self { + self.slices.push(slice); + self + } + + /// Add a footer annotation to the diagnostic. This annotation will have its own type. + pub(crate) fn add_annotation( + &mut self, + msg: impl Into>, + level: Level, + ) -> &mut Self { + self.footer.push((msg.into(), level)); + self + } + + /// Print this diagnostic. + /// + /// The diagnostic is printed using `cargo:warning` if `bindgen` is being invoked by a build + /// script or using `eprintln` otherwise. + pub(crate) fn display(&self) { + std::thread_local! { + static INVOKED_BY_BUILD_SCRIPT: bool = std::env::var_os("CARGO_CFG_TARGET_ARCH").is_some(); + } + + let mut title = None; + let mut footer = vec![]; + let mut slices = vec![]; + if let Some((msg, level)) = &self.title { + title = Some(Annotation { + id: Some("bindgen"), + label: Some(msg.as_ref()), + annotation_type: (*level).into(), + }) + } + + for (msg, level) in &self.footer { + footer.push(Annotation { + id: None, + label: Some(msg.as_ref()), + annotation_type: (*level).into(), + }); + } + + // add additional info that this is generated by bindgen + // so as to not confuse with rustc warnings + footer.push(Annotation { + id: None, + label: Some("This diagnostic was generated by bindgen."), + annotation_type: AnnotationType::Info, + }); + + for slice in &self.slices { + if let Some(source) = &slice.source { + slices.push(ExtSlice { + source: source.as_ref(), + line_start: slice.line.unwrap_or_default(), + origin: slice.filename.as_deref(), + annotations: vec![], + fold: false, + }) + } + } + + let snippet = Snippet { + title, + footer, + slices, + opt: FormatOptions { + color: true, + ..Default::default() + }, + }; + let dl = DisplayList::from(snippet); + + if INVOKED_BY_BUILD_SCRIPT.with(Clone::clone) { + let string = dl.to_string(); + for line in string.lines() { + println!("cargo:warning={}\n", line); + } + } else { + eprintln!("{}\n", dl); + } + } +} + +/// A slice of source code. +#[derive(Default)] +pub(crate) struct Slice<'a> { + source: Option>, + filename: Option, + line: Option, +} + +impl<'a> Slice<'a> { + /// Set the source code. + pub(crate) fn with_source( + &mut self, + source: impl Into>, + ) -> &mut Self { + self.source = Some(source.into()); + self + } + + /// Set the file, line and column. + pub(crate) fn with_location( + &mut self, + mut name: String, + line: usize, + col: usize, + ) -> &mut Self { + write!(name, ":{}:{}", line, col) + .expect("Writing to a string cannot fail"); + self.filename = Some(name); + self.line = Some(line); + self + } +} + +pub(crate) fn get_line( + filename: &str, + line: usize, +) -> io::Result> { + let file = BufReader::new(File::open(filename)?); + if let Some(line) = file.lines().nth(line.wrapping_sub(1)) { + return line.map(Some); + } + + Ok(None) +} diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index c6015ded72..a34f210bc7 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -477,9 +477,6 @@ pub(crate) struct BindgenContext { /// Populated when we enter codegen by `compute_has_float`; always `None` /// before that and `Some` after. has_float: Option>, - - /// The set of warnings raised during binding generation. - warnings: Vec, } /// A traversal of allowlisted items. @@ -595,7 +592,6 @@ If you encounter an error missing from this list, please file an issue or a PR!" have_destructor: None, has_type_param_in_array: None, has_float: None, - warnings: Vec::new(), } } @@ -1156,7 +1152,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" pub(crate) fn gen( mut self, cb: F, - ) -> Result<(Out, BindgenOptions, Vec), CodegenError> + ) -> Result<(Out, BindgenOptions), CodegenError> where F: FnOnce(&Self) -> Result, { @@ -1194,7 +1190,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" self.compute_cannot_derive_partialord_partialeq_or_eq(); let ret = cb(&self)?; - Ok((ret, self.options, self.warnings)) + Ok((ret, self.options)) } /// When the `testing_only_extra_assertions` feature is enabled, this @@ -2463,24 +2459,16 @@ If you encounter an error missing from this list, please file an issue or a PR!" self.allowlisted = Some(allowlisted); self.codegen_items = Some(codegen_items); - let mut warnings = Vec::new(); - for item in self.options().allowlisted_functions.unmatched_items() { - warnings - .push(format!("unused option: --allowlist-function {}", item)); + unused_regex_diagnostic(item, "--allowlist-function", self); } for item in self.options().allowlisted_vars.unmatched_items() { - warnings.push(format!("unused option: --allowlist-var {}", item)); + unused_regex_diagnostic(item, "--allowlist-var", self); } for item in self.options().allowlisted_types.unmatched_items() { - warnings.push(format!("unused option: --allowlist-type {}", item)); - } - - for msg in warnings { - warn!("{}", msg); - self.warnings.push(msg); + unused_regex_diagnostic(item, "--allowlist-type", self); } } @@ -2971,3 +2959,24 @@ impl TemplateParameters for PartialType { } } } + +fn unused_regex_diagnostic(item: &str, name: &str, ctx: &BindgenContext) { + warn!("unused option: {} {}", name, item); + + #[cfg(feature = "experimental")] + if ctx.options().emit_diagnostics { + use crate::diagnostics::{Diagnostic, Level, Slice}; + + let mut slice = Slice::default(); + slice.with_source(item); + + Diagnostic::default() + .with_title("unused regular expression:", Level::Warn) + .add_slice(slice) + .add_annotation( + format!("this regular expression was passed via `{}`", name), + Level::Note, + ) + .display(); + } +} diff --git a/bindgen/ir/var.rs b/bindgen/ir/var.rs index db20124cfb..c0bf4fc297 100644 --- a/bindgen/ir/var.rs +++ b/bindgen/ir/var.rs @@ -222,7 +222,7 @@ impl ClangSubItemParser for Var { if previously_defined { let name = String::from_utf8(id).unwrap(); - warn!("Duplicated macro definition: {}", name); + duplicated_macro_diagnostic(&name, cursor.location(), ctx); return Err(ParseError::Continue); } @@ -440,3 +440,49 @@ fn get_integer_literal_from_cursor(cursor: &clang::Cursor) -> Option { }); value } + +fn duplicated_macro_diagnostic( + macro_name: &str, + location: crate::clang::SourceLocation, + ctx: &BindgenContext, +) { + warn!("Duplicated macro definition: {}", macro_name); + + #[cfg(feature = "experimental")] + // FIXME (pvdrz & amanjeev): This diagnostic message shows way too often to be actually + // useful. We have to change the logic where this function is called to be able to emit this + // message only when the duplication is an actuall issue. + // + // If I understood correctly, `bindgen` ignores all `#undef` directives. Meaning that this: + // ```c + // #define FOO 1 + // #undef FOO + // #define FOO 2 + // ``` + // + // Will trigger this message even though there's nothing wrong with it. + #[allow(clippy::overly_complex_bool_expr)] + if false && ctx.options().emit_diagnostics { + use crate::diagnostics::{get_line, Diagnostic, Level, Slice}; + use std::borrow::Cow; + + let mut slice = Slice::default(); + let mut source = Cow::from(macro_name); + + let (file, line, col, _) = location.location(); + if let Some(filename) = file.name() { + if let Ok(Some(code)) = get_line(&filename, line) { + source = code.into(); + } + slice.with_location(filename, line, col); + } + + slice.with_source(source); + + Diagnostic::default() + .with_title("Duplicated macro definition", Level::Warn) + .add_slice(slice) + .add_annotation("This macro had a duplicate", Level::Note) + .display(); + } +} diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 2b1d68079a..f40b7ffbf1 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -42,6 +42,8 @@ mod time; pub mod callbacks; mod clang; +#[cfg(feature = "experimental")] +mod diagnostics; mod features; mod ir; mod parse; @@ -404,7 +406,10 @@ impl Builder { impl BindgenOptions { fn build(&mut self) { - let regex_sets = [ + const REGEX_SETS_LEN: usize = 27; + let sets_len = REGEX_SETS_LEN + self.abi_overrides.len(); + + let regex_sets: [_; REGEX_SETS_LEN] = [ &mut self.allowlisted_vars, &mut self.allowlisted_types, &mut self.allowlisted_functions, @@ -433,10 +438,63 @@ impl BindgenOptions { &mut self.no_hash_types, &mut self.must_use_types, ]; + let record_matches = self.record_matches; + #[cfg(feature = "experimental")] + { + let names = if self.emit_diagnostics { + <[&str; 27]>::into_iter([ + "--blocklist-type", + "--blocklist-function", + "--blocklist-item", + "--blocklist-file", + "--opaque-type", + "--allowlist-type", + "--allowlist-function", + "--allowlist-var", + "--allowlist-file", + "--bitfield-enum", + "--newtype-enum", + "--newtype-global-enum", + "--rustified-enum", + "--rustified-enum-non-exhaustive", + "--constified-enum-module", + "--constified-enum", + "--type-alias", + "--new-type-alias", + "--new-type-alias-deref", + "--bindgen-wrapper-union", + "--manually-drop-union", + "--no-partialeq", + "--no-copy", + "--no-debug", + "--no-default", + "--no-hash", + "--must-use", + ]) + .chain((0..self.abi_overrides.len()).map(|_| "--override-abi")) + .map(Some) + .collect() + } else { + vec![None; sets_len] + }; + + for (regex_set, name) in + self.abi_overrides.values_mut().chain(regex_sets).zip(names) + { + regex_set.build_with_diagnostics(record_matches, name); + } + } + #[cfg(not(feature = "experimental"))] for regex_set in self.abi_overrides.values_mut().chain(regex_sets) { regex_set.build(record_matches); } + + let rust_target = self.rust_target; + #[allow(deprecated)] + if rust_target <= RustTarget::Stable_1_30 { + deprecated_target_diagnostic(rust_target, self); + } } /// Update rust target version @@ -481,6 +539,28 @@ impl BindgenOptions { } } +fn deprecated_target_diagnostic(target: RustTarget, options: &BindgenOptions) { + let target = String::from(target); + warn!("The {} Rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues", target,); + + #[cfg(feature = "experimental")] + if options.emit_diagnostics { + use crate::diagnostics::{Diagnostic, Level}; + + let mut diagnostic = Diagnostic::default(); + diagnostic.with_title( + format!("The {} Rust target is deprecated.", target), + Level::Warn, + ); + diagnostic.add_annotation( + "This Rust target was passed as an argument to `--rust-target`", + Level::Info, + ); + diagnostic.add_annotation("If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues", Level::Help); + diagnostic.display(); + } +} + #[cfg(feature = "runtime")] fn ensure_libclang_is_loaded() { if clang_sys::is_loaded() { @@ -551,7 +631,6 @@ impl std::error::Error for BindgenError {} #[derive(Debug)] pub struct Bindings { options: BindgenOptions, - warnings: Vec, module: proc_macro2::TokenStream, } @@ -776,14 +855,10 @@ impl Bindings { parse(&mut context)?; } - let (module, options, warnings) = + let (module, options) = codegen::codegen(context).map_err(BindgenError::Codegen)?; - Ok(Bindings { - options, - warnings, - module, - }) + Ok(Bindings { options, module }) } /// Write these bindings as source text to a file. @@ -917,7 +992,10 @@ impl Bindings { "Rustfmt parsing errors.".to_string(), )), Some(3) => { - warn!("Rustfmt could not format some lines."); + rustfmt_non_fatal_error_diagnostic( + "Rustfmt could not format some lines", + &self.options, + ); Ok(bindings) } _ => Err(io::Error::new( @@ -928,22 +1006,22 @@ impl Bindings { _ => Ok(source), } } +} - /// Emit all the warning messages raised while generating the bindings in a build script. - /// - /// If you are using `bindgen` outside of a build script you should use [`Bindings::warnings`] - /// and handle the messages accordingly instead. - #[inline] - pub fn emit_warnings(&self) { - for message in &self.warnings { - println!("cargo:warning={}", message); - } - } +fn rustfmt_non_fatal_error_diagnostic(msg: &str, options: &BindgenOptions) { + warn!("{}", msg); - /// Return all the warning messages raised while generating the bindings. - #[inline] - pub fn warnings(&self) -> &[String] { - &self.warnings + #[cfg(feature = "experimental")] + if options.emit_diagnostics { + use crate::diagnostics::{Diagnostic, Level}; + + Diagnostic::default() + .with_title(msg, Level::Warn) + .add_annotation( + "The bindings will be generated but not formatted", + Level::Note, + ) + .display(); } } diff --git a/bindgen/options/mod.rs b/bindgen/options/mod.rs index d28d4aa96a..6c3de1240d 100644 --- a/bindgen/options/mod.rs +++ b/bindgen/options/mod.rs @@ -1583,13 +1583,6 @@ options! { /// /// The default target is the latest stable Rust version. pub fn rust_target(mut self, rust_target: RustTarget) -> Self { - #[allow(deprecated)] - if rust_target <= RustTarget::Stable_1_30 { - warn!( - "The {} rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues", - String::from(rust_target) - ); - } self.options.set_rust_target(rust_target); self } @@ -2101,4 +2094,25 @@ options! { } }, }, + /// Whether to emit diagnostics or not. + emit_diagnostics: { + ty: bool, + methods: { + #[cfg(feature = "experimental")] + /// Emit diagnostics. + /// + /// These diagnostics are emitted to `stderr` if you are using `bindgen-cli` or printed + /// using `cargo:warning=` if you are using `bindgen` as a `build-dependency`. + /// + /// Diagnostics are not emitted by default. + /// + /// The layout and contents of these diagnostic messages are not covered by versioning + /// and can change without notice. + pub fn emit_diagnostics(mut self) -> Self { + self.options.emit_diagnostics = true; + self + } + }, + as_args: "--emit-diagnostics", + } } diff --git a/bindgen/regex_set.rs b/bindgen/regex_set.rs index f827107efd..f68ed8fa5f 100644 --- a/bindgen/regex_set.rs +++ b/bindgen/regex_set.rs @@ -32,11 +32,7 @@ impl RegexSet { where S: AsRef, { - let string = string.as_ref().to_owned(); - if string == "*" { - warn!("using wildcard patterns (`*`) is no longer considered valid. Use `.*` instead"); - } - self.items.push(string); + self.items.push(string.as_ref().to_owned()); self.matched.push(Cell::new(false)); self.set = None; } @@ -62,13 +58,56 @@ impl RegexSet { /// /// Must be called before calling `matches()`, or it will always return /// false. + #[inline] pub fn build(&mut self, record_matches: bool) { + self.build_inner(record_matches, None) + } + + #[cfg(all(feature = "__cli", feature = "experimental"))] + /// Construct a RegexSet from the set of entries we've accumulated and emit diagnostics if the + /// name of the regex set is passed to it. + /// + /// Must be called before calling `matches()`, or it will always return + /// false. + #[inline] + pub fn build_with_diagnostics( + &mut self, + record_matches: bool, + name: Option<&'static str>, + ) { + self.build_inner(record_matches, name) + } + + #[cfg(all(not(feature = "__cli"), feature = "experimental"))] + /// Construct a RegexSet from the set of entries we've accumulated and emit diagnostics if the + /// name of the regex set is passed to it. + /// + /// Must be called before calling `matches()`, or it will always return + /// false. + #[inline] + pub(crate) fn build_with_diagnostics( + &mut self, + record_matches: bool, + name: Option<&'static str>, + ) { + self.build_inner(record_matches, name) + } + + fn build_inner( + &mut self, + record_matches: bool, + name: Option<&'static str>, + ) { let items = self.items.iter().map(|item| format!("^({})$", item)); self.record_matches = record_matches; self.set = match RxSet::new(items) { Ok(x) => Some(x), Err(e) => { warn!("Invalid regex in {:?}: {:?}", self.items, e); + if let Some(name) = name { + #[cfg(feature = "experimental")] + invalid_regex_warning(self, e, name); + } None } } @@ -100,3 +139,63 @@ impl RegexSet { true } } + +#[cfg(feature = "experimental")] +fn invalid_regex_warning( + set: &RegexSet, + err: regex::Error, + name: &'static str, +) { + use crate::diagnostics::{Diagnostic, Level, Slice}; + + let mut diagnostic = Diagnostic::default(); + + match err { + regex::Error::Syntax(string) => { + if string.starts_with("regex parse error:\n") { + let mut source = String::new(); + + let mut parsing_source = true; + + for line in string.lines().skip(1) { + if parsing_source { + if line.starts_with(' ') { + source.push_str(line); + source.push('\n'); + continue; + } + parsing_source = false; + } + let error = "error: "; + if line.starts_with(error) { + let (_, msg) = line.split_at(error.len()); + diagnostic.add_annotation(msg.to_owned(), Level::Error); + } else { + diagnostic.add_annotation(line.to_owned(), Level::Info); + } + } + let mut slice = Slice::default(); + slice.with_source(source); + diagnostic.add_slice(slice); + + diagnostic.with_title("regex parse error:", Level::Warn); + } else { + diagnostic.with_title(string, Level::Warn); + } + } + err => { + let err = err.to_string(); + diagnostic.with_title(err, Level::Warn); + } + } + + diagnostic.add_annotation( + format!("this regular expression was passed via `{}`", name), + Level::Note, + ); + + if set.items.iter().any(|item| item == "*") { + diagnostic.add_annotation("using wildcard patterns \"*\" is no longer considered valid. Consider using \".*\" instead", Level::Help); + } + diagnostic.display(); +} From 5df1821bda7d2a7544fd431fa98d473fdbdccecc Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Mon, 3 Apr 2023 19:08:38 -0500 Subject: [PATCH 483/942] Fixes for diagnostics (#2478) * Hide `warning:` * Make diagnostics format more homogeneous --- bindgen/codegen/mod.rs | 2 +- bindgen/diagnostics.rs | 6 +++++- bindgen/ir/context.rs | 13 ++++++------- bindgen/ir/var.rs | 4 ++-- bindgen/lib.rs | 4 ++-- bindgen/regex_set.rs | 9 ++++++--- 6 files changed, 22 insertions(+), 16 deletions(-) diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 9d1956f37b..47dba5f14e 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -4356,7 +4356,7 @@ fn unsupported_abi_diagnostic( let mut diag = Diagnostic::default(); diag .with_title(format!( - "The `{}` {}function uses the {} ABI which is not supported by the configured Rust target", + "The `{}` {}function uses the {} ABI which is not supported by the configured Rust target.", fn_name, if VARIADIC { "variadic " } else { "" }, abi), Level::Warn) diff --git a/bindgen/diagnostics.rs b/bindgen/diagnostics.rs index 82d5359d97..f765afe970 100644 --- a/bindgen/diagnostics.rs +++ b/bindgen/diagnostics.rs @@ -129,9 +129,13 @@ impl<'a> Diagnostic<'a> { let dl = DisplayList::from(snippet); if INVOKED_BY_BUILD_SCRIPT.with(Clone::clone) { + // This is just a hack which hides the `warning:` added by cargo at the beginning of + // every line. This should be fine as our diagnostics already have a colorful title. + // FIXME (pvdrz): Could it be that this doesn't work in other languages? + let hide_warning = "\r \r"; let string = dl.to_string(); for line in string.lines() { - println!("cargo:warning={}\n", line); + println!("cargo:warning={}{}", hide_warning, line); } } else { eprintln!("{}\n", dl); diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index a34f210bc7..d7c8ed5bb1 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -2965,16 +2965,15 @@ fn unused_regex_diagnostic(item: &str, name: &str, ctx: &BindgenContext) { #[cfg(feature = "experimental")] if ctx.options().emit_diagnostics { - use crate::diagnostics::{Diagnostic, Level, Slice}; - - let mut slice = Slice::default(); - slice.with_source(item); + use crate::diagnostics::{Diagnostic, Level}; Diagnostic::default() - .with_title("unused regular expression:", Level::Warn) - .add_slice(slice) + .with_title( + format!("Unused regular expression: `{}`.", item), + Level::Warn, + ) .add_annotation( - format!("this regular expression was passed via `{}`", name), + format!("This regular expression was passed to `{}`.", name), Level::Note, ) .display(); diff --git a/bindgen/ir/var.rs b/bindgen/ir/var.rs index c0bf4fc297..0e977391dc 100644 --- a/bindgen/ir/var.rs +++ b/bindgen/ir/var.rs @@ -480,9 +480,9 @@ fn duplicated_macro_diagnostic( slice.with_source(source); Diagnostic::default() - .with_title("Duplicated macro definition", Level::Warn) + .with_title("Duplicated macro definition.", Level::Warn) .add_slice(slice) - .add_annotation("This macro had a duplicate", Level::Note) + .add_annotation("This macro had a duplicate.", Level::Note) .display(); } } diff --git a/bindgen/lib.rs b/bindgen/lib.rs index f40b7ffbf1..f129678cb4 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -553,7 +553,7 @@ fn deprecated_target_diagnostic(target: RustTarget, options: &BindgenOptions) { Level::Warn, ); diagnostic.add_annotation( - "This Rust target was passed as an argument to `--rust-target`", + "This Rust target was passed to `--rust-target`", Level::Info, ); diagnostic.add_annotation("If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues", Level::Help); @@ -1018,7 +1018,7 @@ fn rustfmt_non_fatal_error_diagnostic(msg: &str, options: &BindgenOptions) { Diagnostic::default() .with_title(msg, Level::Warn) .add_annotation( - "The bindings will be generated but not formatted", + "The bindings will be generated but not formatted.", Level::Note, ) .display(); diff --git a/bindgen/regex_set.rs b/bindgen/regex_set.rs index f68ed8fa5f..0a8b7b130f 100644 --- a/bindgen/regex_set.rs +++ b/bindgen/regex_set.rs @@ -178,7 +178,10 @@ fn invalid_regex_warning( slice.with_source(source); diagnostic.add_slice(slice); - diagnostic.with_title("regex parse error:", Level::Warn); + diagnostic.with_title( + "Error while parsing a regular expression.", + Level::Warn, + ); } else { diagnostic.with_title(string, Level::Warn); } @@ -190,12 +193,12 @@ fn invalid_regex_warning( } diagnostic.add_annotation( - format!("this regular expression was passed via `{}`", name), + format!("This regular expression was passed via `{}`.", name), Level::Note, ); if set.items.iter().any(|item| item == "*") { - diagnostic.add_annotation("using wildcard patterns \"*\" is no longer considered valid. Consider using \".*\" instead", Level::Help); + diagnostic.add_annotation("Wildcard patterns \"*\" are no longer considered valid. Use \".*\" instead.", Level::Help); } diagnostic.display(); } From c3352cebaf8d06b2261ce82e774400819dc0d234 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Mon, 3 Apr 2023 19:13:23 -0500 Subject: [PATCH 484/942] Move `untagged_union` to its own field (#2479) --- bindgen/codegen/impl_partialeq.rs | 2 +- bindgen/ir/analysis/derive.rs | 6 +++--- bindgen/ir/comp.rs | 2 +- bindgen/lib.rs | 5 +++++ bindgen/options/mod.rs | 21 +++++++++++---------- 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/bindgen/codegen/impl_partialeq.rs b/bindgen/codegen/impl_partialeq.rs index 24abf20df7..42fabf6ad0 100644 --- a/bindgen/codegen/impl_partialeq.rs +++ b/bindgen/codegen/impl_partialeq.rs @@ -18,7 +18,7 @@ pub(crate) fn gen_partialeq_impl( &self._bindgen_opaque_blob[..] == &other._bindgen_opaque_blob[..] }); } else if comp_info.kind() == CompKind::Union { - assert!(!ctx.options().rust_features().untagged_union); + assert!(!ctx.options().untagged_union); tokens.push(quote! { &self.bindgen_union_field[..] == &other.bindgen_union_field[..] }); diff --git a/bindgen/ir/analysis/derive.rs b/bindgen/ir/analysis/derive.rs index 0f496a7ead..d8d29ed9a8 100644 --- a/bindgen/ir/analysis/derive.rs +++ b/bindgen/ir/analysis/derive.rs @@ -172,7 +172,7 @@ impl<'ctx> CannotDerive<'ctx> { if item.is_opaque(self.ctx, &()) { if !self.derive_trait.can_derive_union() && ty.is_union() && - self.ctx.options().rust_features().untagged_union + self.ctx.options().untagged_union { trace!( " cannot derive {} for Rust unions", @@ -322,7 +322,7 @@ impl<'ctx> CannotDerive<'ctx> { if info.kind() == CompKind::Union { if self.derive_trait.can_derive_union() { - if self.ctx.options().rust_features().untagged_union && + if self.ctx.options().untagged_union && // https://github.com/rust-lang/rust/issues/36640 (!info.self_template_params(self.ctx).is_empty() || !item.all_template_params(self.ctx).is_empty()) @@ -334,7 +334,7 @@ impl<'ctx> CannotDerive<'ctx> { } // fall through to be same as non-union handling } else { - if self.ctx.options().rust_features().untagged_union { + if self.ctx.options().untagged_union { trace!( " cannot derive {} for Rust unions", self.derive_trait diff --git a/bindgen/ir/comp.rs b/bindgen/ir/comp.rs index 27ee1dae0e..89e77e160f 100644 --- a/bindgen/ir/comp.rs +++ b/bindgen/ir/comp.rs @@ -1680,7 +1680,7 @@ impl CompInfo { return (false, false); } - if !ctx.options().rust_features().untagged_union { + if !ctx.options().untagged_union { return (false, false); } diff --git a/bindgen/lib.rs b/bindgen/lib.rs index f129678cb4..1d55638887 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -495,6 +495,11 @@ impl BindgenOptions { if rust_target <= RustTarget::Stable_1_30 { deprecated_target_diagnostic(rust_target, self); } + + // Disable `untagged_union` if the target does not support it. + if !self.rust_features.untagged_union { + self.untagged_union = false; + } } /// Update rust target version diff --git a/bindgen/options/mod.rs b/bindgen/options/mod.rs index 6c3de1240d..4931055422 100644 --- a/bindgen/options/mod.rs +++ b/bindgen/options/mod.rs @@ -1596,24 +1596,25 @@ options! { rust_features: { ty: RustFeatures, default: RustTarget::default().into(), + methods: {}, + // This field cannot be set from the CLI, + as_args: ignore, + }, + /// Enable support for native Rust unions if they are supported. + untagged_union: { + ty: bool, + default: true, methods: { /// Disable support for native Rust unions, if supported. /// /// The default value of this option is set based on the value passed to /// [`Builder::rust_target`]. pub fn disable_untagged_union(mut self) -> Self { - self.options.rust_features.untagged_union = false; + self.options.untagged_union = false; self } - }, - as_args: |features, args| { - // FIXME(emilio): This is a bit hacky, maybe we should stop re-using the - // RustFeatures to store the "disable_untagged_union" call, and make it - // a different flag that we check elsewhere / in generate(). - if !features.untagged_union { - args.push("--disable-untagged-union".to_owned()); - } - }, + } + as_args: |value, args| (!value).as_args(args, "--disable-untagged-union"), }, /// Whether we should record which items in the regex sets did match any C items. record_matches: { From 0f1a4045251822dcaffe64f1a1bb4d52d6d854b9 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Mon, 3 Apr 2023 21:07:59 -0500 Subject: [PATCH 485/942] Apply the C-EVOCATIVE guideline to `options!` (#2480) The Rust API Guidelines state that macors should keep the input syntax of a macro similar to the Rust syntax when possible. The `options!` macro input followed this format: ```rust field: { ty: Ty, ... } ``` However, the following syntax should be better: ```rust field: ty { ... } ``` This is done because the `options!` macro defines a `struct` and these changes still evoke the common `field: ty` syntax followed by Rust. See https://rust-lang.github.io/api-guidelines/macros.html#input-syntax-is-evocative-of-the-output-c-evocative. --- bindgen/options/mod.rs | 318 ++++++++++++++--------------------------- 1 file changed, 107 insertions(+), 211 deletions(-) diff --git a/bindgen/options/mod.rs b/bindgen/options/mod.rs index 4931055422..49e77c11c9 100644 --- a/bindgen/options/mod.rs +++ b/bindgen/options/mod.rs @@ -31,9 +31,9 @@ use helpers::ignore; /// one of the fields of `BindgenOptions`. /// /// The input format of this macro resembles a `struct` pattern. Each field of the `BindgenOptions` -/// type is declared using 4 items: +/// type is declared by adding the name of the field and its type using the `name: type` syntax and +/// a block of code with the following items: /// -/// - `ty`: The type of the field. /// - `default`: The default value for the field. If this item is omitted, `Default::default()` is /// used instead, meaning that the type of the field must implement `Default`. /// - `methods`: A block of code containing methods for the `Builder` type. These methods should be @@ -53,8 +53,7 @@ use helpers::ignore; /// As an example, this would be the declaration of a `bool` field called `be_fun` whose default /// value is `false` (the `Default` value for `bool`): /// ```rust,ignore -/// be_fun: { -/// ty: bool, +/// be_fun: bool { /// methods: { /// /// Ask `bindgen` to be fun. This option is disabled by default. /// fn be_fun(mut self) -> Self { @@ -70,8 +69,7 @@ use helpers::ignore; /// instead. This means that we have to add the `default` item and use a closure in the `as_args` /// item: /// ```rust,ignore -/// be_fun: { -/// ty: bool, +/// be_fun: bool { /// default: true, /// methods: { /// /// Ask `bindgen` to not be fun. `bindgen` is fun by default. @@ -87,8 +85,7 @@ use helpers::ignore; macro_rules! options { ($( $(#[doc = $docs:literal])+ - $field:ident: { - ty: $ty:ty, + $field:ident: $ty:ty { $(default: $default:expr,)? methods: {$($methods_tokens:tt)*}$(,)? as_args: $as_args:expr$(,)? @@ -156,8 +153,7 @@ macro_rules! options { options! { /// Types that have been blocklisted and should not appear anywhere in the generated code. - blocklisted_types: { - ty: RegexSet, + blocklisted_types: RegexSet { methods: { regex_option! { /// Do not generate any bindings for the given type. @@ -170,9 +166,8 @@ options! { as_args: "--blocklist-type", }, /// Functions that have been blocklisted and should not appear in the generated code. - blocklisted_functions: { - ty: RegexSet, - methods : { + blocklisted_functions: RegexSet { + methods: { regex_option! { /// Do not generate any bindings for the given function. /// @@ -188,8 +183,7 @@ options! { as_args: "--blocklist-function", }, /// Items that have been blocklisted and should not appear in the generated code. - blocklisted_items: { - ty: RegexSet, + blocklisted_items: RegexSet { methods: { regex_option! { /// Do not generate any bindings for the given item, regardless of whether it is a @@ -203,8 +197,7 @@ options! { as_args: "--blocklist-item", }, /// Files whose contents should be blocklisted and should not appear in the generated code. - blocklisted_files: { - ty: RegexSet, + blocklisted_files: RegexSet { methods: { regex_option! { /// Do not generate any bindings for the contents of the given file, regardless of @@ -218,8 +211,7 @@ options! { as_args: "--blocklist-file", }, /// Types that should be treated as opaque structures in the generated code. - opaque_types: { - ty: RegexSet, + opaque_types: RegexSet { methods: { regex_option! { /// Treat the given type as opaque in the generated bindings. @@ -236,8 +228,7 @@ options! { as_args: "--opaque-type", }, /// The explicit `rustfmt` path. - rustfmt_path: { - ty: Option, + rustfmt_path: Option { methods: { /// Set an explicit path to the `rustfmt` binary. /// @@ -253,8 +244,7 @@ options! { as_args: ignore, }, /// The path to which we should write a Makefile-syntax depfile (if any). - depfile: { - ty: Option, + depfile: Option { methods: { /// Add a depfile output which will be written alongside the generated bindings. pub fn depfile, D: Into>( @@ -277,8 +267,7 @@ options! { }, }, /// Types that have been allowlisted and should appear in the generated code. - allowlisted_types: { - ty: RegexSet, + allowlisted_types: RegexSet { methods: { regex_option! { /// Generate bindings for the given type. @@ -294,8 +283,7 @@ options! { as_args: "--allowlist-type", }, /// Functions that have been allowlisted and should appear in the generated code. - allowlisted_functions: { - ty: RegexSet, + allowlisted_functions: RegexSet { methods: { regex_option! { /// Generate bindings for the given function. @@ -315,8 +303,7 @@ options! { as_args: "--allowlist-function", }, /// Variables that have been allowlisted and should appear in the generated code. - allowlisted_vars: { - ty: RegexSet, + allowlisted_vars: RegexSet { methods: { regex_option! { /// Generate bindings for the given variable. @@ -332,8 +319,7 @@ options! { as_args: "--allowlist-var", }, /// Files whose contents have been allowlisted and should appear in the generated code. - allowlisted_files: { - ty: RegexSet, + allowlisted_files: RegexSet { methods: { regex_option! { /// Generate bindings for the content of the given file. @@ -349,8 +335,7 @@ options! { as_args: "--allowlist-file", }, /// The default style of for generated `enum`s. - default_enum_style: { - ty: EnumVariation, + default_enum_style: EnumVariation { methods: { /// Set the default style for generated `enum`s. /// @@ -377,8 +362,7 @@ options! { }, }, /// `enum`s marked as bitfield-like. This is, newtypes with bitwise operations. - bitfield_enums: { - ty: RegexSet, + bitfield_enums: RegexSet { methods: { regex_option! { /// Mark the given `enum` as being bitfield-like. @@ -394,8 +378,7 @@ options! { as_args: "--bitfield-enum", }, /// `enum`s marked as newtypes. - newtype_enums: { - ty: RegexSet, + newtype_enums: RegexSet { methods: { regex_option! { /// Mark the given `enum` as a newtype. @@ -412,8 +395,7 @@ options! { as_args: "--newtype-enum", }, /// `enum`s marked as global newtypes . - newtype_global_enums: { - ty: RegexSet, + newtype_global_enums: RegexSet { methods: { regex_option! { /// Mark the given `enum` as a global newtype. @@ -430,8 +412,7 @@ options! { as_args: "--newtype-global-enum", }, /// `enum`s marked as Rust `enum`s. - rustified_enums: { - ty: RegexSet, + rustified_enums: RegexSet { methods: { regex_option! { /// Mark the given `enum` as a Rust `enum`. @@ -451,8 +432,7 @@ options! { as_args: "--rustified-enum", }, /// `enum`s marked as non-exhaustive Rust `enum`s. - rustified_non_exhaustive_enums: { - ty: RegexSet, + rustified_non_exhaustive_enums: RegexSet { methods: { regex_option! { /// Mark the given `enum` as a non-exhaustive Rust `enum`. @@ -468,8 +448,7 @@ options! { as_args: "--rustified-non-exhaustive-enums", }, /// `enum`s marked as modules of constants. - constified_enum_modules: { - ty: RegexSet, + constified_enum_modules: RegexSet { methods: { regex_option! { /// Mark the given `enum` as a module with a set of integer constants. @@ -482,8 +461,7 @@ options! { as_args: "--constified-enum-module", }, /// `enum`s marked as a set of constants. - constified_enums: { - ty: RegexSet, + constified_enums: RegexSet { methods: { regex_option! { /// Mark the given `enum` as a set o integer constants. @@ -499,8 +477,7 @@ options! { as_args: "--constified-enum", }, /// The default type signedness for C macro constants. - default_macro_constant_type: { - ty: MacroTypeVariation, + default_macro_constant_type: MacroTypeVariation { methods: { /// Set the default type signedness to be used for macro constants. /// @@ -522,8 +499,7 @@ options! { }, }, /// The default style of code generation for `typedef`s. - default_alias_style: { - ty: AliasVariation, + default_alias_style: AliasVariation { methods: { /// Set the default style of code generation for `typedef`s. /// @@ -548,8 +524,7 @@ options! { }, }, /// `typedef` patterns that will use regular type aliasing. - type_alias: { - ty: RegexSet, + type_alias: RegexSet { methods: { regex_option! { /// Mark the given `typedef` as a regular Rust `type` alias. @@ -566,8 +541,7 @@ options! { as_args: "--type-alias", }, /// `typedef` patterns that will be aliased by creating a newtype. - new_type_alias: { - ty: RegexSet, + new_type_alias: RegexSet { methods: { regex_option! { /// Mark the given `typedef` as a Rust newtype by having the aliased @@ -583,8 +557,7 @@ options! { as_args: "--new-type-alias", }, /// `typedef` patterns that will be wrapped in a newtype implementing `Deref` and `DerefMut`. - new_type_alias_deref: { - ty: RegexSet, + new_type_alias_deref: RegexSet { methods: { regex_option! { /// Mark the given `typedef` to be generated as a newtype that can be dereferenced. @@ -600,8 +573,7 @@ options! { as_args: "--new-type-alias-deref", }, /// The default style of code to generate for `union`s containing non-`Copy` members. - default_non_copy_union_style: { - ty: NonCopyUnionStyle, + default_non_copy_union_style: NonCopyUnionStyle { methods: { /// Set the default style of code to generate for `union`s with non-`Copy` members. /// @@ -623,8 +595,7 @@ options! { }, }, /// The patterns marking non-`Copy` `union`s as using the `bindgen` generated wrapper. - bindgen_wrapper_union: { - ty: RegexSet, + bindgen_wrapper_union: RegexSet { methods: { regex_option! { /// Mark the given `union` to use a `bindgen`-generated wrapper for its members if at @@ -642,8 +613,7 @@ options! { as_args: "--bindgen-wrapper-union", }, /// The patterns marking non-`Copy` `union`s as using the `ManuallyDrop` wrapper. - manually_drop_union: { - ty: RegexSet, + manually_drop_union: RegexSet { methods: { regex_option! { /// Mark the given `union` to use [`::core::mem::ManuallyDrop`] for its members if @@ -663,8 +633,7 @@ options! { /// Whether we should generate built-in definitions. - builtins: { - ty: bool, + builtins: bool { methods: { /// Generate Rust bindings for built-in definitions (for example `__builtin_va_list`). /// @@ -677,8 +646,7 @@ options! { as_args: "--builtins", }, /// Whether we should dump the Clang AST for debugging purposes. - emit_ast: { - ty: bool, + emit_ast: bool { methods: { /// Emit the Clang AST to `stdout` for debugging purposes. /// @@ -691,8 +659,7 @@ options! { as_args: "--emit-clang-ast", }, /// Whether we should dump our IR for debugging purposes. - emit_ir: { - ty: bool, + emit_ir: bool { methods: { /// Emit the `bindgen` internal representation to `stdout` for debugging purposes. /// @@ -705,8 +672,7 @@ options! { as_args: "--emit-ir", }, /// Output path for the `graphviz` DOT file. - emit_ir_graphviz: { - ty: Option, + emit_ir_graphviz: Option { methods: { /// Set the path for the file where the`bindgen` internal representation will be /// emitted as a graph using the `graphviz` DOT language. @@ -722,8 +688,7 @@ options! { }, /// Whether we should emulate C++ namespaces with Rust modules. - enable_cxx_namespaces: { - ty: bool, + enable_cxx_namespaces: bool { methods: { /// Emulate C++ namespaces using Rust modules in the generated bindings. /// @@ -736,8 +701,7 @@ options! { as_args: "--enable-cxx-namespaces", }, /// Whether we should try to find unexposed attributes in functions. - enable_function_attribute_detection: { - ty: bool, + enable_function_attribute_detection: bool { methods: { /// Enable detecting function attributes on C functions. /// @@ -760,8 +724,7 @@ options! { as_args: "--enable-function-attribute-detection", }, /// Whether we should avoid mangling names with namespaces. - disable_name_namespacing: { - ty: bool, + disable_name_namespacing: bool { methods: { /// Disable name auto-namespacing. /// @@ -779,8 +742,7 @@ options! { as_args: "--disable-name-namespacing", }, /// Whether we should avoid generating nested `struct` names. - disable_nested_struct_naming: { - ty: bool, + disable_nested_struct_naming: bool { methods: { /// Disable nested `struct` naming. /// @@ -807,8 +769,7 @@ options! { as_args: "--disable-nested-struct-naming", }, /// Whether we should avoid embedding version identifiers into source code. - disable_header_comment: { - ty: bool, + disable_header_comment: bool { methods: { /// Do not insert the `bindgen` version identifier into the generated bindings. /// @@ -822,8 +783,7 @@ options! { as_args: "--disable-header-comment", }, /// Whether we should generate layout tests for generated `struct`s. - layout_tests: { - ty: bool, + layout_tests: bool { default: true, methods: { /// Set whether layout tests should be generated. @@ -837,8 +797,7 @@ options! { as_args: |value, args| (!value).as_args(args, "--no-layout-tests"), }, /// Whether we should implement `Debug` for types that cannot derive it. - impl_debug: { - ty: bool, + impl_debug: bool { methods: { /// Set whether `Debug` should be implemented for types that cannot derive it. /// @@ -852,8 +811,7 @@ options! { as_args: "--impl-debug", }, /// Whether we should implement `PartialEq` types that cannot derive it. - impl_partialeq: { - ty: bool, + impl_partialeq: bool { methods: { /// Set whether `PartialEq` should be implemented for types that cannot derive it. /// @@ -866,8 +824,7 @@ options! { as_args: "--impl-partialeq", }, /// Whether we should derive `Copy` when possible. - derive_copy: { - ty: bool, + derive_copy: bool { default: true, methods: { /// Set whether the `Copy` trait should be derived when possible. @@ -882,8 +839,7 @@ options! { }, /// Whether we should derive `Debug` when possible. - derive_debug: { - ty: bool, + derive_debug: bool { default: true, methods: { /// Set whether the `Debug` trait should be derived when possible. @@ -901,8 +857,7 @@ options! { }, /// Whether we should derive `Default` when possible. - derive_default: { - ty: bool, + derive_default: bool { methods: { /// Set whether the `Default` trait should be derived when possible. /// @@ -923,8 +878,7 @@ options! { }, }, /// Whether we should derive `Hash` when possible. - derive_hash: { - ty: bool, + derive_hash: bool { methods: { /// Set whether the `Hash` trait should be derived when possible. /// @@ -937,8 +891,7 @@ options! { as_args: "--with-derive-hash", }, /// Whether we should derive `PartialOrd` when possible. - derive_partialord: { - ty: bool, + derive_partialord: bool { methods: { /// Set whether the `PartialOrd` trait should be derived when possible. /// @@ -958,8 +911,7 @@ options! { as_args: "--with-derive-partialord", }, /// Whether we should derive `Ord` when possible. - derive_ord: { - ty: bool, + derive_ord: bool { methods: { /// Set whether the `Ord` trait should be derived when possible. /// @@ -977,8 +929,7 @@ options! { as_args: "--with-derive-ord", }, /// Whether we should derive `PartialEq` when possible. - derive_partialeq: { - ty: bool, + derive_partialeq: bool { methods: { /// Set whether the `PartialEq` trait should be derived when possible. /// @@ -1001,8 +952,7 @@ options! { as_args: "--with-derive-partialeq", }, /// Whether we should derive `Eq` when possible. - derive_eq: { - ty: bool, + derive_eq: bool { methods: { /// Set whether the `Eq` trait should be derived when possible. /// @@ -1025,8 +975,7 @@ options! { /// /// If this option is enabled and the Rust target version is greater than 1.64, the prefix for /// C platform-specific types will be `::core::ffi` instead of `::core::os::raw`. - use_core: { - ty: bool, + use_core: bool { methods: { /// Use `core` instead of `std` in the generated bindings. /// @@ -1040,8 +989,7 @@ options! { as_args: "--use-core", }, /// An optional prefix for the C platform-specific types. - ctypes_prefix: { - ty: Option, + ctypes_prefix: Option { methods: { /// Use the given prefix for the C platform-specific types instead of `::std::os::raw`. /// @@ -1055,8 +1003,7 @@ options! { as_args: "--ctypes-prefix", }, /// The prefix for anonymous fields. - anon_fields_prefix: { - ty: String, + anon_fields_prefix: String { default: DEFAULT_ANON_FIELDS_PREFIX.into(), methods: { /// Use the given prefix for the anonymous fields. @@ -1088,8 +1035,7 @@ options! { }, }, /// Whether to measure the time for each one of the `bindgen` phases. - time_phases: { - ty: bool, + time_phases: bool { methods: { /// Set whether to measure the elapsed time for each one of the `bindgen` phases. This /// information is printed to `stderr`. @@ -1103,8 +1049,7 @@ options! { as_args: "--time-phases", }, /// Whether to convert C float types to `f32` and `f64`. - convert_floats: { - ty: bool, + convert_floats: bool { default: true, methods: { /// Avoid converting C float types to `f32` and `f64`. @@ -1116,8 +1061,7 @@ options! { as_args: |value, args| (!value).as_args(args, "--no-convert-floats"), }, /// The set of raw lines to be prepended to the top-level module of the generated Rust code. - raw_lines: { - ty: Vec, + raw_lines: Vec { methods: { /// Add a line of Rust code at the beginning of the generated bindings. The string is /// passed through without any modification. @@ -1134,8 +1078,7 @@ options! { }, }, /// The set of raw lines to prepend to different modules. - module_lines: { - ty: HashMap>, + module_lines: HashMap> { methods: { /// Add a given line to the beginning of a given module. /// @@ -1165,8 +1108,7 @@ options! { }, }, /// The input header files. - input_headers: { - ty: Vec, + input_headers: Vec { methods: { /// Add an input C/C++ header to generate bindings for. /// @@ -1198,8 +1140,7 @@ options! { as_args: ignore, }, /// The set of arguments to be passed straight through to Clang. - clang_args: { - ty: Vec, + clang_args: Vec { methods: { /// Add an argument to be passed straight through to Clang. pub fn clang_arg>(self, arg: T) -> Builder { @@ -1221,8 +1162,7 @@ options! { as_args: ignore, }, /// Tuples of unsaved file contents of the form (name, contents). - input_header_contents: { - ty: Vec<(String, String)>, + input_header_contents: Vec<(String, String)> { methods: { /// Add `contents` as an input C/C++ header named `name`. /// @@ -1247,8 +1187,7 @@ options! { as_args: ignore, }, /// A user-provided visitor to allow customizing different kinds of situations. - parse_callbacks: { - ty: Vec>, + parse_callbacks: Vec> { methods: { /// Add a new [`ParseCallbacks`] instance to configure types in different situations. pub fn parse_callbacks(mut self, cb: Box) -> Self { @@ -1264,8 +1203,7 @@ options! { }, }, /// Which kind of items should we generate. We generate all of them by default. - codegen_config: { - ty: CodegenConfig, + codegen_config: CodegenConfig { default: CodegenConfig::all(), methods: { /// Do not generate any functions. @@ -1336,8 +1274,7 @@ options! { }, }, /// Whether to treat inline namespaces conservatively. - conservative_inline_namespaces: { - ty: bool, + conservative_inline_namespaces: bool { methods: { /// Treat inline namespaces conservatively. /// @@ -1376,8 +1313,7 @@ options! { as_args: "--conservative-inline-namespaces", }, /// Whether to keep documentation comments in the generated output. - generate_comments: { - ty: bool, + generate_comments: bool { default: true, methods: { /// Set whether the generated bindings should contain documentation comments. @@ -1400,8 +1336,7 @@ options! { as_args: |value, args| (!value).as_args(args, "--no-doc-comments"), }, /// Whether to generate inline functions. - generate_inline_functions: { - ty: bool, + generate_inline_functions: bool { methods: { /// Set whether to generate inline functions. /// @@ -1422,8 +1357,7 @@ options! { as_args: "--generate-inline-functions", }, /// Whether to allowlist types recursively. - allowlist_recursively: { - ty: bool, + allowlist_recursively: bool { default: true, methods: { /// Set whether to recursively allowlist items. @@ -1463,8 +1397,7 @@ options! { }, /// Whether to emit `#[macro_use] extern crate objc;` instead of `use objc;` in the prologue of /// the files generated from objective-c files. - objc_extern_crate: { - ty: bool, + objc_extern_crate: bool { methods: { /// Emit `#[macro_use] extern crate objc;` instead of `use objc;` in the prologue of /// the files generated from objective-c files. @@ -1478,8 +1411,7 @@ options! { as_args: "--objc-extern-crate", }, /// Whether to generate proper block signatures instead of `void` pointers. - generate_block: { - ty: bool, + generate_block: bool { methods: { /// Generate proper block signatures instead of `void` pointers. /// @@ -1493,8 +1425,7 @@ options! { }, /// Whether to emit `#[macro_use] extern crate block;` instead of `use block;` in the prologue /// of the files generated from apple block files. - block_extern_crate: { - ty: bool, + block_extern_crate: bool { methods: { /// Emit `#[macro_use] extern crate block;` instead of `use block;` in the prologue of /// the files generated from apple block files. @@ -1508,8 +1439,7 @@ options! { as_args: "--block-extern-crate", }, /// Whether to use the clang-provided name mangling. - enable_mangling: { - ty: bool, + enable_mangling: bool { default: true, methods: { /// Set whether to use the clang-provided name mangling. This is probably needed for @@ -1531,8 +1461,7 @@ options! { as_args: |value, args| (!value).as_args(args, "--distrust-clang-mangling"), }, /// Whether to detect include paths using `clang_sys`. - detect_include_paths: { - ty: bool, + detect_include_paths: bool { default: true, methods: { /// Set whether to detect include paths using `clang_sys`. @@ -1546,8 +1475,7 @@ options! { as_args: |value, args| (!value).as_args(args, "--no-include-path-detection"), }, /// Whether we should try to fit macro constants into types smaller than `u32` and `i32`. - fit_macro_constants: { - ty: bool, + fit_macro_constants: bool { methods: { /// Set whether `bindgen` should try to fit macro constants into types smaller than `u32` /// and `i32`. @@ -1561,8 +1489,7 @@ options! { as_args: "--fit-macro-constant-types", }, /// Whether to prepend the `enum` name to constant or newtype variants. - prepend_enum_name: { - ty: bool, + prepend_enum_name: bool { default: true, methods: { /// Set whether to prepend the `enum` name to constant or newtype variants. @@ -1576,8 +1503,7 @@ options! { as_args: |value, args| (!value).as_args(args, "--no-prepend-enum-name"), }, /// Version of the Rust compiler to target. - rust_target: { - ty: RustTarget, + rust_target: RustTarget { methods: { /// Specify the Rust target version. /// @@ -1593,16 +1519,14 @@ options! { }, }, /// Features to be enabled. They are derived from `rust_target`. - rust_features: { - ty: RustFeatures, + rust_features: RustFeatures { default: RustTarget::default().into(), methods: {}, // This field cannot be set from the CLI, as_args: ignore, }, /// Enable support for native Rust unions if they are supported. - untagged_union: { - ty: bool, + untagged_union: bool { default: true, methods: { /// Disable support for native Rust unions, if supported. @@ -1617,8 +1541,7 @@ options! { as_args: |value, args| (!value).as_args(args, "--disable-untagged-union"), }, /// Whether we should record which items in the regex sets did match any C items. - record_matches: { - ty: bool, + record_matches: bool { default: true, methods: { /// Set whether we should record which items in our regex sets did match any C items. @@ -1633,8 +1556,7 @@ options! { as_args: |value, args| (!value).as_args(args, "--no-record-matches"), }, /// Whether `size_t` should be translated to `usize` automatically. - size_t_is_usize: { - ty: bool, + size_t_is_usize: bool { default: true, methods: { /// Set whether `size_t` should be translated to `usize`. @@ -1648,8 +1570,7 @@ options! { as_args: |value, args| (!value).as_args(args, "--no-size_t-is-usize"), }, /// The tool that should be used to format the generated bindings. - formatter: { - ty: Formatter, + formatter: Formatter { methods: { #[cfg_attr(feature = "prettyplease", deprecated)] /// Set whether `rustfmt` should be used to format the generated bindings. @@ -1686,8 +1607,7 @@ options! { }, }, /// The absolute path to the `rustfmt` configuration file. - rustfmt_configuration_file: { - ty: Option, + rustfmt_configuration_file: Option { methods: { /// Set the absolute path to the `rustfmt` configuration file. /// @@ -1705,8 +1625,7 @@ options! { as_args: "--rustfmt-configuration-file", }, /// Types that should not derive `PartialEq`. - no_partialeq_types: { - ty: RegexSet, + no_partialeq_types: RegexSet { methods: { regex_option! { /// Do not derive `PartialEq` for a given type. @@ -1719,8 +1638,7 @@ options! { as_args: "--no-partialeq", }, /// Types that should not derive `Copy`. - no_copy_types: { - ty: RegexSet, + no_copy_types: RegexSet { methods: { regex_option! { /// Do not derive `Copy` and `Clone` for a given type. @@ -1733,8 +1651,7 @@ options! { as_args: "--no-copy", }, /// Types that should not derive `Debug`. - no_debug_types: { - ty: RegexSet, + no_debug_types: RegexSet { methods: { regex_option! { /// Do not derive `Debug` for a given type. @@ -1747,8 +1664,7 @@ options! { as_args: "--no-debug", }, /// Types that should not derive or implement `Default`. - no_default_types: { - ty: RegexSet, + no_default_types: RegexSet { methods: { regex_option! { /// Do not derive or implement `Default` for a given type. @@ -1761,8 +1677,7 @@ options! { as_args: "--no-default", }, /// Types that should not derive `Hash`. - no_hash_types: { - ty: RegexSet, + no_hash_types: RegexSet { methods: { regex_option! { /// Do not derive `Hash` for a given type. @@ -1775,8 +1690,7 @@ options! { as_args: "--no-hash", }, /// Types that should be annotated with `#[must_use]`. - must_use_types: { - ty: RegexSet, + must_use_types: RegexSet { methods: { regex_option! { /// Annotate the given type with the `#[must_use]` attribute. @@ -1789,8 +1703,7 @@ options! { as_args: "--must-use-type", }, /// Whether C arrays should be regular pointers in rust or array pointers - array_pointers_in_arguments: { - ty: bool, + array_pointers_in_arguments: bool { methods: { /// Translate arrays `T arr[size]` into array pointers `*mut [T; size]` instead of /// translating them as `*mut T` which is the default. @@ -1805,8 +1718,7 @@ options! { as_args: "--use-array-pointers-in-arguments", }, /// The name of the `wasm_import_module`. - wasm_import_module_name: { - ty: Option, + wasm_import_module_name: Option { methods: { /// Adds the `#[link(wasm_import_module = import_name)]` attribute to all the `extern` /// blocks generated by `bindgen`. @@ -1823,8 +1735,7 @@ options! { as_args: "--wasm-import-module-name", }, /// The name of the dynamic library (if we are generating bindings for a shared library). - dynamic_library_name: { - ty: Option, + dynamic_library_name: Option { methods: { /// Generate bindings for a shared library with the given name. /// @@ -1840,8 +1751,7 @@ options! { as_args: "--dynamic-loading", }, /// Whether to equire successful linkage for all routines in a shared library. - dynamic_link_require_all: { - ty: bool, + dynamic_link_require_all: bool { methods: { /// Set whether to require successful linkage for all routines in a shared library. /// This allows us to optimize function calls by being able to safely assume function @@ -1860,8 +1770,7 @@ options! { }, /// Whether to only make generated bindings `pub` if the items would be publicly accessible by /// C++. - respect_cxx_access_specs: { - ty: bool, + respect_cxx_access_specs: bool { methods: { /// Set whether to respect the C++ access specifications. /// @@ -1877,8 +1786,7 @@ options! { as_args: "--respect-cxx-access-specs", }, /// Whether to translate `enum` integer types to native Rust integer types. - translate_enum_integer_types: { - ty: bool, + translate_enum_integer_types: bool { methods: { /// Set whether to always translate `enum` integer types to native Rust integer types. /// @@ -1893,8 +1801,7 @@ options! { as_args: "--translate-enum-integer-types", }, /// Whether to generate types with C style naming. - c_naming: { - ty: bool, + c_naming: bool { methods: { /// Set whether to generate types with C style naming. /// @@ -1909,8 +1816,7 @@ options! { as_args: "--c-naming", }, /// Wether to always emit explicit padding fields. - force_explicit_padding: { - ty: bool, + force_explicit_padding: bool { methods: { /// Set whether to always emit explicit padding fields. /// @@ -1928,8 +1834,7 @@ options! { as_args: "--explicit-padding", }, /// Whether to emit vtable functions. - vtable_generation: { - ty: bool, + vtable_generation: bool { methods: { /// Set whether to enable experimental support to generate virtual table functions. /// @@ -1944,8 +1849,7 @@ options! { as_args: "--vtable-generation", }, /// Whether to sort the generated Rust items. - sort_semantically: { - ty: bool, + sort_semantically: bool { methods: { /// Set whether to sort the generated Rust items in a predefined manner. /// @@ -1958,8 +1862,7 @@ options! { as_args: "--sort-semantically", }, /// Whether to deduplicate `extern` blocks. - merge_extern_blocks: { - ty: bool, + merge_extern_blocks: bool { methods: { /// Merge all extern blocks under the same module into a single one. /// @@ -1972,8 +1875,7 @@ options! { as_args: "--merge-extern-blocks", }, /// Whether to wrap unsafe operations in unsafe blocks. - wrap_unsafe_ops: { - ty: bool, + wrap_unsafe_ops: bool { methods: { /// Wrap all unsafe operations in unsafe blocks. /// @@ -1986,8 +1888,7 @@ options! { as_args: "--wrap-unsafe-ops", }, /// Patterns for functions whose ABI should be overriden. - abi_overrides: { - ty: HashMap, + abi_overrides: HashMap { methods: { regex_option! { /// Override the ABI of a given function. @@ -2011,8 +1912,7 @@ options! { }, }, /// Whether to generate wrappers for `static` functions. - wrap_static_fns: { - ty: bool, + wrap_static_fns: bool { methods: { #[cfg(feature = "experimental")] /// Set whether to generate wrappers for `static`` functions. @@ -2031,8 +1931,7 @@ options! { as_args: "--wrap-static-fns", }, /// The suffix to be added to the function wrappers for `static` functions. - wrap_static_fns_suffix: { - ty: Option, + wrap_static_fns_suffix: Option { methods: { #[cfg(feature = "experimental")] /// Set the suffix added to the wrappers for `static` functions. @@ -2049,8 +1948,7 @@ options! { as_args: "--wrap-static-fns-suffix", }, /// The path of the file where the wrappers for `static` functions will be emitted. - wrap_static_fns_path: { - ty: Option, + wrap_static_fns_path: Option { methods: { #[cfg(feature = "experimental")] /// Set the path for the source code file that would be created if any wrapper @@ -2072,8 +1970,7 @@ options! { as_args: "--wrap-static-fns-path", }, /// Default visibility of fields. - default_visibility: { - ty: FieldVisibilityKind, + default_visibility: FieldVisibilityKind { methods: { /// Set the default visibility of fields, including bitfields and accessor methods for /// bitfields. @@ -2096,8 +1993,7 @@ options! { }, }, /// Whether to emit diagnostics or not. - emit_diagnostics: { - ty: bool, + emit_diagnostics: bool { methods: { #[cfg(feature = "experimental")] /// Emit diagnostics. From be2f59c076882f1970b1da2b81c4f8ba2b8c9f31 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Wed, 5 Apr 2023 12:25:38 -0500 Subject: [PATCH 486/942] Fix `unused_code` warnings without `experimental` (#2482) This fixes the `unused_code` warnings that appear when compiling `bindgen` without the `experimental` and `__cli` features. --- bindgen/codegen/mod.rs | 10 +++++----- bindgen/ir/context.rs | 4 ++-- bindgen/ir/var.rs | 8 ++++---- bindgen/lib.rs | 12 ++++++------ bindgen/options/mod.rs | 10 ++++++---- bindgen/regex_set.rs | 6 +++--- 6 files changed, 26 insertions(+), 24 deletions(-) diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 47dba5f14e..1c54eb8ff0 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -4338,9 +4338,9 @@ impl CodeGenerator for Function { fn unsupported_abi_diagnostic( fn_name: &str, - location: Option<&crate::clang::SourceLocation>, + _location: Option<&crate::clang::SourceLocation>, abi: &str, - ctx: &BindgenContext, + _ctx: &BindgenContext, ) { warn!( "Skipping {}function `{}` with the {} ABI that isn't supported by the configured Rust target", @@ -4350,7 +4350,7 @@ fn unsupported_abi_diagnostic( ); #[cfg(feature = "experimental")] - if ctx.options().emit_diagnostics { + if _ctx.options().emit_diagnostics { use crate::diagnostics::{get_line, Diagnostic, Level, Slice}; let mut diag = Diagnostic::default(); @@ -4361,9 +4361,9 @@ fn unsupported_abi_diagnostic( if VARIADIC { "variadic " } else { "" }, abi), Level::Warn) .add_annotation("No code will be generated for this function.", Level::Warn) - .add_annotation(format!("The configured Rust version is {}.", String::from(ctx.options().rust_target)), Level::Note); + .add_annotation(format!("The configured Rust version is {}.", String::from(_ctx.options().rust_target)), Level::Note); - if let Some(loc) = location { + if let Some(loc) = _location { let (file, line, col, _) = loc.location(); if let Some(filename) = file.name() { diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index d7c8ed5bb1..a5c14a8f06 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -2960,11 +2960,11 @@ impl TemplateParameters for PartialType { } } -fn unused_regex_diagnostic(item: &str, name: &str, ctx: &BindgenContext) { +fn unused_regex_diagnostic(item: &str, name: &str, _ctx: &BindgenContext) { warn!("unused option: {} {}", name, item); #[cfg(feature = "experimental")] - if ctx.options().emit_diagnostics { + if _ctx.options().emit_diagnostics { use crate::diagnostics::{Diagnostic, Level}; Diagnostic::default() diff --git a/bindgen/ir/var.rs b/bindgen/ir/var.rs index 0e977391dc..a548ec881b 100644 --- a/bindgen/ir/var.rs +++ b/bindgen/ir/var.rs @@ -443,8 +443,8 @@ fn get_integer_literal_from_cursor(cursor: &clang::Cursor) -> Option { fn duplicated_macro_diagnostic( macro_name: &str, - location: crate::clang::SourceLocation, - ctx: &BindgenContext, + _location: crate::clang::SourceLocation, + _ctx: &BindgenContext, ) { warn!("Duplicated macro definition: {}", macro_name); @@ -462,14 +462,14 @@ fn duplicated_macro_diagnostic( // // Will trigger this message even though there's nothing wrong with it. #[allow(clippy::overly_complex_bool_expr)] - if false && ctx.options().emit_diagnostics { + if false && _ctx.options().emit_diagnostics { use crate::diagnostics::{get_line, Diagnostic, Level, Slice}; use std::borrow::Cow; let mut slice = Slice::default(); let mut source = Cow::from(macro_name); - let (file, line, col, _) = location.location(); + let (file, line, col, _) = _location.location(); if let Some(filename) = file.name() { if let Ok(Some(code)) = get_line(&filename, line) { source = code.into(); diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 1d55638887..cd0a06c942 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -407,7 +407,6 @@ impl Builder { impl BindgenOptions { fn build(&mut self) { const REGEX_SETS_LEN: usize = 27; - let sets_len = REGEX_SETS_LEN + self.abi_overrides.len(); let regex_sets: [_; REGEX_SETS_LEN] = [ &mut self.allowlisted_vars, @@ -442,8 +441,9 @@ impl BindgenOptions { let record_matches = self.record_matches; #[cfg(feature = "experimental")] { + let sets_len = REGEX_SETS_LEN + self.abi_overrides.len(); let names = if self.emit_diagnostics { - <[&str; 27]>::into_iter([ + <[&str; REGEX_SETS_LEN]>::into_iter([ "--blocklist-type", "--blocklist-function", "--blocklist-item", @@ -544,12 +544,12 @@ impl BindgenOptions { } } -fn deprecated_target_diagnostic(target: RustTarget, options: &BindgenOptions) { +fn deprecated_target_diagnostic(target: RustTarget, _options: &BindgenOptions) { let target = String::from(target); warn!("The {} Rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues", target,); #[cfg(feature = "experimental")] - if options.emit_diagnostics { + if _options.emit_diagnostics { use crate::diagnostics::{Diagnostic, Level}; let mut diagnostic = Diagnostic::default(); @@ -1013,11 +1013,11 @@ impl Bindings { } } -fn rustfmt_non_fatal_error_diagnostic(msg: &str, options: &BindgenOptions) { +fn rustfmt_non_fatal_error_diagnostic(msg: &str, _options: &BindgenOptions) { warn!("{}", msg); #[cfg(feature = "experimental")] - if options.emit_diagnostics { + if _options.emit_diagnostics { use crate::diagnostics::{Diagnostic, Level}; Diagnostic::default() diff --git a/bindgen/options/mod.rs b/bindgen/options/mod.rs index 49e77c11c9..4b9dd65738 100644 --- a/bindgen/options/mod.rs +++ b/bindgen/options/mod.rs @@ -21,7 +21,9 @@ use crate::HashMap; use crate::DEFAULT_ANON_FIELDS_PREFIX; use std::env; -use std::path::{Path, PathBuf}; +#[cfg(feature = "experimental")] +use std::path::Path; +use std::path::PathBuf; use std::rc::Rc; use as_args::AsArgs; @@ -1195,10 +1197,10 @@ options! { self } }, - as_args: |parse_callbacks, args| { + as_args: |_callbacks, _args| { #[cfg(feature = "__cli")] - for callbacks in parse_callbacks { - args.extend(callbacks.cli_args()); + for cb in _callbacks { + _args.extend(cb.cli_args()); } }, }, diff --git a/bindgen/regex_set.rs b/bindgen/regex_set.rs index 0a8b7b130f..1d5cad2fc8 100644 --- a/bindgen/regex_set.rs +++ b/bindgen/regex_set.rs @@ -96,7 +96,7 @@ impl RegexSet { fn build_inner( &mut self, record_matches: bool, - name: Option<&'static str>, + _name: Option<&'static str>, ) { let items = self.items.iter().map(|item| format!("^({})$", item)); self.record_matches = record_matches; @@ -104,8 +104,8 @@ impl RegexSet { Ok(x) => Some(x), Err(e) => { warn!("Invalid regex in {:?}: {:?}", self.items, e); - if let Some(name) = name { - #[cfg(feature = "experimental")] + #[cfg(feature = "experimental")] + if let Some(name) = _name { invalid_regex_warning(self, e, name); } None From 281180c1dc746440669e595c0cd7cb04da565e53 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Wed, 5 Apr 2023 12:39:03 -0500 Subject: [PATCH 487/942] Add minimal workflow (#2483) This workflow runs `cargo check` for the `bindgen` crate without its default features (except for the `runtime` feature) and denies any warnings that occur. This would help us catch any build warnings that happen when building `bindgen` without the CLI and experimental features disabled. --- .github/workflows/bindgen.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 9a8b2bb00f..38cb15f519 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -54,6 +54,23 @@ jobs: - name: Build with msrv run: rm Cargo.lock && cargo +1.60.0 build --lib + minimal: + runs-on: ubuntu-latest + env: + RUSTFLAGS: -D warnings + steps: + - uses: actions/checkout@v3 + + - name: Install stable + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + - name: Check without default features + run: cargo check -p bindgen --no-default-features --features=runtime + quickchecking: runs-on: ubuntu-latest steps: From f03d4f4298fe0102f861d2023358513eb260713e Mon Sep 17 00:00:00 2001 From: CGMossa Date: Mon, 10 Apr 2023 16:52:57 +0200 Subject: [PATCH 488/942] Typo: Update CHANGELOG.md (#2489) Fixed a typo. --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ffdd28666d..f2c00d132c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -162,7 +162,7 @@ # Unreleased ## Added - * Added the `Bindgen::default_visibility` nethod and the + * Added the `Bindgen::default_visibility` method and the `--default-visibility` flag to set the default visibility of fields. * Added the `--formatter` CLI flag with the values `none`, `rustfmt` and `prettyplease` to select which tool will be used to format the bindings. The From dcc21c1e910f8f82627afe0e4b249e29bd73413a Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Mon, 10 Apr 2023 17:04:11 +0200 Subject: [PATCH 489/942] Don't generate wrong strings. (#2487) A header with ```cpp #include const char S1[] = "Hello"; const unsigned char S2[] = u8"Hello"; const char16_t S3[] = u"Hello"; const char32_t S4[] = U"Hello"; const wchar_t S5[] = L"Hello"; ``` will wrongly generate (`-- -std=c++11`) ```rust pub const S1: &[u8; 6usize] = b"Hello\0"; pub const S2: &[u8; 6usize] = b"Hello\0"; pub const S3: &[u8; 2usize] = b"H\0"; pub const S4: &[u8; 2usize] = b"H\0"; pub const S5: &[u8; 2usize] = b"H\0"; ``` since `clang_EvalResult_getAsStr` only works for ordinary and UTF-8 strings. This seems like a `libclang` limitation since there isn't a similar function for other string literal types. This disables generating code for unsupported string types. --- CHANGELOG.md | 3 +++ bindgen/clang.rs | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f2c00d132c..0c84ba2d1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -186,12 +186,15 @@ * The documentation of the generated `type` aliases now matches the comments of their `typedef` counterparts instead of using the comments of the aliased types. + ## Removed * The following deprecated flags were removed: `--use-msvc-mangling`, `--rustfmt-bindings` and `--size_t-is-usize`. * The `--no-rustfmt-bindings` flag was removed in favor of `--formatter=none`. * The `Bindings::emit_warnings` and `Bindings::warnings` methods were removed in favor of `--emit-diagnostics`. + * Bindgen no longer generates C string constants that cannot be represented as + byte slices. ## Fixed diff --git a/bindgen/clang.rs b/bindgen/clang.rs index 62bf84f6d3..0060213336 100644 --- a/bindgen/clang.rs +++ b/bindgen/clang.rs @@ -2104,6 +2104,7 @@ pub(crate) fn extract_clang_version() -> String { #[derive(Debug)] pub(crate) struct EvalResult { x: CXEvalResult, + ty: Type, } impl EvalResult { @@ -2131,6 +2132,7 @@ impl EvalResult { } Some(EvalResult { x: unsafe { clang_Cursor_Evaluate(cursor.x) }, + ty: cursor.cur_type().canonical_type(), }) } @@ -2177,13 +2179,22 @@ impl EvalResult { /// Evaluates the expression as a literal string, that may or may not be /// valid utf-8. pub(crate) fn as_literal_string(&self) -> Option> { - match self.kind() { - CXEval_StrLiteral => { + if self.kind() != CXEval_StrLiteral { + return None; + } + + let char_ty = self.ty.pointee_type().or_else(|| self.ty.elem_type())?; + match char_ty.kind() { + CXType_Char_S | CXType_SChar | CXType_Char_U | CXType_UChar => { let ret = unsafe { CStr::from_ptr(clang_EvalResult_getAsStr(self.x)) }; Some(ret.to_bytes().to_vec()) } + // FIXME: Support generating these. + CXType_Char16 => None, + CXType_Char32 => None, + CXType_WChar => None, _ => None, } } From 594eb7b22b3e1a2688aed2281fae85444f452b2f Mon Sep 17 00:00:00 2001 From: John Bobbo Date: Mon, 10 Apr 2023 15:05:43 +0000 Subject: [PATCH 490/942] Add support for the "efiapi" ABI. (#2481) This allows for use of `extern "efiapi" ...` which is now stable since the following commit: `https://github.com/rust-lang/rust/commit/46f9e878f68e6ece9e8dad54c67e97e5dd5838e1` --- bindgen-cli/options.rs | 2 +- .../tests/expectations/tests/abi-override.rs | 2 ++ bindgen-tests/tests/headers/abi-override.h | 5 +++- bindgen/codegen/mod.rs | 25 ++++++++++++++++--- bindgen/features.rs | 8 +++++- bindgen/ir/function.rs | 17 ++++++++++++- 6 files changed, 52 insertions(+), 7 deletions(-) diff --git a/bindgen-cli/options.rs b/bindgen-cli/options.rs index 3d87fc1bc6..a0af03e7ff 100644 --- a/bindgen-cli/options.rs +++ b/bindgen-cli/options.rs @@ -336,7 +336,7 @@ struct BindgenCommand { /// Deduplicates extern blocks. #[arg(long)] merge_extern_blocks: bool, - /// Overrides the ABI of functions matching . The value must be of the shape = where can be one of C, stdcall, fastcall, thiscall, aapcs, win64 or C-unwind. + /// Overrides the ABI of functions matching . The value must be of the shape = where can be one of C, stdcall, efiapi, fastcall, thiscall, aapcs, win64 or C-unwind. #[arg(long, value_name = "OVERRIDE")] override_abi: Vec, /// Wrap unsafe operations in unsafe blocks. diff --git a/bindgen-tests/tests/expectations/tests/abi-override.rs b/bindgen-tests/tests/expectations/tests/abi-override.rs index 49693692e4..8f370cd7b2 100644 --- a/bindgen-tests/tests/expectations/tests/abi-override.rs +++ b/bindgen-tests/tests/expectations/tests/abi-override.rs @@ -14,3 +14,5 @@ extern "stdcall" { extern "C" { pub fn baz(); } +pub type boo = ::std::option::Option; +pub type foobar = ::std::option::Option; diff --git a/bindgen-tests/tests/headers/abi-override.h b/bindgen-tests/tests/headers/abi-override.h index cee72caeef..bbfe82c2f9 100644 --- a/bindgen-tests/tests/headers/abi-override.h +++ b/bindgen-tests/tests/headers/abi-override.h @@ -1,5 +1,8 @@ -// bindgen-flags: --override-abi=foo=fastcall --override-abi=bar=stdcall +// bindgen-flags: --override-abi=foo=fastcall --override-abi=bar=stdcall --override-abi=boo=efiapi --override-abi=foobar=efiapi void foo(); void bar(); void baz(); + +typedef void (*boo)(); +typedef void (*foobar)(boo boo); diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 1c54eb8ff0..11e49b8d75 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -2566,6 +2566,9 @@ impl Method { ClangAbi::Known(Abi::CUnwind) => { ctx.options().rust_features().c_unwind_abi } + ClangAbi::Known(Abi::EfiApi) => { + ctx.options().rust_features().abi_efiapi + } _ => true, }; @@ -4089,9 +4092,8 @@ impl TryToRustTy for FunctionSig { // TODO: we might want to consider ignoring the reference return value. let ret = utils::fnsig_return_ty(ctx, self); let arguments = utils::fnsig_arguments(ctx, self); - let abi = self.abi(ctx, None); - match abi { + match self.abi(ctx, None) { ClangAbi::Known(Abi::ThisCall) if !ctx.options().rust_features().thiscall_abi => { @@ -4110,7 +4112,13 @@ impl TryToRustTy for FunctionSig { warn!("Skipping function with C-unwind ABI that isn't supported by the configured Rust target"); Ok(proc_macro2::TokenStream::new()) } - _ => Ok(quote! { + ClangAbi::Known(Abi::EfiApi) + if !ctx.options().rust_features().abi_efiapi => + { + warn!("Skipping function with efiapi ABI that isn't supported by the configured Rust target"); + Ok(proc_macro2::TokenStream::new()) + } + abi => Ok(quote! { unsafe extern #abi fn ( #( #arguments ),* ) #ret }), } @@ -4243,6 +4251,17 @@ impl CodeGenerator for Function { ); return None; } + ClangAbi::Known(Abi::EfiApi) + if !ctx.options().rust_features().abi_efiapi => + { + unsupported_abi_diagnostic::( + name, + item.location(), + "efiapi", + ctx, + ); + return None; + } ClangAbi::Known(Abi::Win64) if signature.is_variadic() => { unsupported_abi_diagnostic::( name, diff --git a/bindgen/features.rs b/bindgen/features.rs index ef44571a39..fe6f415887 100644 --- a/bindgen/features.rs +++ b/bindgen/features.rs @@ -131,6 +131,9 @@ macro_rules! rust_target_base { /// Rust stable 1.64 /// * `core_ffi_c` ([Tracking issue](https://github.com/rust-lang/rust/issues/94501)) => Stable_1_64 => 1.64; + /// Rust stable 1.68 + /// * `abi_efiapi` calling convention ([Tracking issue](https://github.com/rust-lang/rust/issues/65815)) + => Stable_1_68 => 1.68; /// Nightly rust /// * `thiscall` calling convention ([Tracking issue](https://github.com/rust-lang/rust/issues/42202)) /// * `vectorcall` calling convention (no tracking issue) @@ -144,7 +147,7 @@ rust_target_base!(rust_target_def); rust_target_base!(rust_target_values_def); /// Latest stable release of Rust -pub const LATEST_STABLE_RUST: RustTarget = RustTarget::Stable_1_64; +pub const LATEST_STABLE_RUST: RustTarget = RustTarget::Stable_1_68; /// Create RustFeatures struct definition, new(), and a getter for each field macro_rules! rust_feature_def { @@ -241,6 +244,9 @@ rust_feature_def!( Stable_1_64 { => core_ffi_c; } + Stable_1_68 { + => abi_efiapi; + } Nightly { => thiscall_abi; => vectorcall_abi; diff --git a/bindgen/ir/function.rs b/bindgen/ir/function.rs index bb2303fad6..bfcc1694fb 100644 --- a/bindgen/ir/function.rs +++ b/bindgen/ir/function.rs @@ -176,6 +176,8 @@ pub enum Abi { C, /// The "stdcall" ABI. Stdcall, + /// The "efiapi" ABI. + EfiApi, /// The "fastcall" ABI. Fastcall, /// The "thiscall" ABI. @@ -197,6 +199,7 @@ impl FromStr for Abi { match s { "C" => Ok(Self::C), "stdcall" => Ok(Self::Stdcall), + "efiapi" => Ok(Self::EfiApi), "fastcall" => Ok(Self::Fastcall), "thiscall" => Ok(Self::ThisCall), "vectorcall" => Ok(Self::Vectorcall), @@ -213,6 +216,7 @@ impl std::fmt::Display for Abi { let s = match *self { Self::C => "C", Self::Stdcall => "stdcall", + Self::EfiApi => "efiapi", Self::Fastcall => "fastcall", Self::ThisCall => "thiscall", Self::Vectorcall => "vectorcall", @@ -263,6 +267,9 @@ impl quote::ToTokens for ClangAbi { /// A function signature. #[derive(Debug)] pub(crate) struct FunctionSig { + /// The name of this function signature. + name: String, + /// The return type of the function. return_type: TypeId, @@ -572,7 +579,8 @@ impl FunctionSig { warn!("Unknown calling convention: {:?}", call_conv); } - Ok(FunctionSig { + Ok(Self { + name: spelling, return_type: ret, argument_types: args, is_variadic: ty.is_variadic(), @@ -611,6 +619,13 @@ impl FunctionSig { } else { self.abi } + } else if let Some((abi, _)) = ctx + .options() + .abi_overrides + .iter() + .find(|(_, regex_set)| regex_set.matches(&self.name)) + { + ClangAbi::Known(*abi) } else { self.abi } From 1e3e25fcb9c3503d6bf06c402fc878e233745c22 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Mon, 10 Apr 2023 10:09:19 -0500 Subject: [PATCH 491/942] Document `efiapi` ABI stabilization (#2490) --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c84ba2d1d..b15d5e1bba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -173,6 +173,7 @@ `"prettyplease"` feature is enabled. * Added the `Builder::emit_diagnostics` method and the `--emit-diagnostics` flag to enable emission of diagnostic messages. + * Added support for the `"efiapi"` calling convention. ## Changed * Static functions with no arguments use `void` as their single argument From 5d1c79a59eb9ffc4926ad666e869c85118923f3b Mon Sep 17 00:00:00 2001 From: Cody Schafer Date: Mon, 10 Apr 2023 12:35:18 -0400 Subject: [PATCH 492/942] bindgen::ParseCallbacks: support tracking env variable usage for cargo (#2400) bindgen currently has a `bindgen/build.rs` which attempts to have cargo rebuild bindgen when TARGET specific env variables change, specifically `BINDGEN_EXTRA_CLANG_ARGS_`. Unfortunately, this doesn't have the desired effect in most cases. Specifically, when a crate `A` has `bindgen` in `build-dependencies`, and we're cross compiling `A` for target `T` on a host `H`, `bindgen`'s `build.rs` will observe `TARGET` set to `H` (the host target name) instead of `T` (because `bindgen` itself is being built for `H` and not `T`). Then, within the build script of crate `A`, one would use `bindgen` to generate bindings, and now `TARGET` is set to `T`, so different env variables are used. Allow crates using `bindgen` in build scripts to correctly handle env variable changes by adding `ParseCallbacks::read_env_var()` to track env var reads and adding a basic implementation to `CargoCallbacks` to emit `cargo:rerun-if-env-changed` lines. --- CHANGELOG.md | 4 ++- bindgen/callbacks.rs | 4 +++ bindgen/lib.rs | 59 +++++++++++++++++++++++++++++++++----------- 3 files changed, 51 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b15d5e1bba..1cb8209733 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,7 +65,7 @@ - [Fixed](#fixed-13) - [0.54.1](#0541) - [Added](#added-12) - - [Changed](#changed-10) + - [Changed](#chainged-10) - [Fixed](#fixed-14) - [0.54.0](#0540) - [Added](#added-13) @@ -174,6 +174,8 @@ * Added the `Builder::emit_diagnostics` method and the `--emit-diagnostics` flag to enable emission of diagnostic messages. * Added support for the `"efiapi"` calling convention. + * Added the `ParseCallbacks::read_env_var` method which runs everytime + `bindgen` reads and environment variable. ## Changed * Static functions with no arguments use `void` as their single argument diff --git a/bindgen/callbacks.rs b/bindgen/callbacks.rs index d85e565565..582446687c 100644 --- a/bindgen/callbacks.rs +++ b/bindgen/callbacks.rs @@ -102,6 +102,10 @@ pub trait ParseCallbacks: fmt::Debug { /// This will be called on every file inclusion, with the full path of the included file. fn include_file(&self, _filename: &str) {} + /// This will be called every time `bindgen` reads an environment variable whether it has any + /// content or not. + fn read_env_var(&self, _key: &str) {} + /// This will be called to determine whether a particular blocklisted type /// implements a trait or not. This will be used to implement traits on /// other types containing the blocklisted type. diff --git a/bindgen/lib.rs b/bindgen/lib.rs index cd0a06c942..5b54f45ad1 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -68,10 +68,12 @@ use parse::ParseError; use std::borrow::Cow; use std::collections::hash_map::Entry; use std::env; +use std::ffi::OsStr; use std::fs::{File, OpenOptions}; use std::io::{self, Write}; use std::path::{Path, PathBuf}; use std::process::{Command, Stdio}; +use std::rc::Rc; use std::str::FromStr; // Some convenient typedefs for a fast hash map and hash set. @@ -278,13 +280,18 @@ pub fn builder() -> Builder { Default::default() } -fn get_extra_clang_args() -> Vec { +fn get_extra_clang_args( + parse_callbacks: &[Rc], +) -> Vec { // Add any extra arguments from the environment to the clang command line. - let extra_clang_args = - match get_target_dependent_env_var("BINDGEN_EXTRA_CLANG_ARGS") { - None => return vec![], - Some(s) => s, - }; + let extra_clang_args = match get_target_dependent_env_var( + parse_callbacks, + "BINDGEN_EXTRA_CLANG_ARGS", + ) { + None => return vec![], + Some(s) => s, + }; + // Try to parse it with shell quoting. If we fail, make it one single big argument. if let Some(strings) = shlex::split(&extra_clang_args) { return strings; @@ -296,7 +303,9 @@ impl Builder { /// Generate the Rust bindings using the options built up thus far. pub fn generate(mut self) -> Result { // Add any extra arguments from the environment to the clang command line. - self.options.clang_args.extend(get_extra_clang_args()); + self.options + .clang_args + .extend(get_extra_clang_args(&self.options.parse_callbacks)); // Transform input headers to arguments on the clang command line. self.options.clang_args.extend( @@ -379,7 +388,7 @@ impl Builder { cmd.arg(a); } - for a in get_extra_clang_args() { + for a in get_extra_clang_args(&self.options.parse_callbacks) { cmd.arg(a); } @@ -1152,22 +1161,38 @@ pub fn clang_version() -> ClangVersion { } } +fn env_var + AsRef>( + parse_callbacks: &[Rc], + key: K, +) -> Result { + for callback in parse_callbacks { + callback.read_env_var(key.as_ref()); + } + std::env::var(key) +} + /// Looks for the env var `var_${TARGET}`, and falls back to just `var` when it is not found. -fn get_target_dependent_env_var(var: &str) -> Option { - if let Ok(target) = env::var("TARGET") { - if let Ok(v) = env::var(format!("{}_{}", var, target)) { +fn get_target_dependent_env_var( + parse_callbacks: &[Rc], + var: &str, +) -> Option { + if let Ok(target) = env_var(parse_callbacks, "TARGET") { + if let Ok(v) = env_var(parse_callbacks, format!("{}_{}", var, target)) { return Some(v); } - if let Ok(v) = env::var(format!("{}_{}", var, target.replace('-', "_"))) - { + if let Ok(v) = env_var( + parse_callbacks, + format!("{}_{}", var, target.replace('-', "_")), + ) { return Some(v); } } - env::var(var).ok() + + env_var(parse_callbacks, var).ok() } /// A ParseCallbacks implementation that will act on file includes by echoing a rerun-if-changed -/// line +/// line and on env variable usage by echoing a rerun-if-env-changed line /// /// When running inside a `build.rs` script, this can be used to make cargo invalidate the /// generated bindings whenever any of the files included from the header change: @@ -1185,6 +1210,10 @@ impl callbacks::ParseCallbacks for CargoCallbacks { fn include_file(&self, filename: &str) { println!("cargo:rerun-if-changed={}", filename); } + + fn read_env_var(&self, key: &str) { + println!("cargo:rerun-if-env-changed={}", key); + } } /// Test command_line_flag function. From 54bf9ca77ede605b59cacc1379feb05bf7d38d85 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Mon, 10 Apr 2023 12:05:27 -0500 Subject: [PATCH 493/942] Make `prettyplease` non-optional (#2491) * Make `prettyplease` non-optional This PR makes the `prettyplease` dependency on `bindgen` non-optional. Meaning that the `Builder::no_rustfmt_bindings` method and its equivalent flag are now deprecated. --- CHANGELOG.md | 12 ++++++------ bindgen-cli/Cargo.toml | 3 +-- bindgen-cli/options.rs | 6 +++--- bindgen/Cargo.toml | 2 +- bindgen/options/mod.rs | 2 +- 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1cb8209733..019564888d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -162,17 +162,16 @@ # Unreleased ## Added - * Added the `Bindgen::default_visibility` method and the + * Added the `Builder::default_visibility` method and the `--default-visibility` flag to set the default visibility of fields. * Added the `--formatter` CLI flag with the values `none`, `rustfmt` and `prettyplease` to select which tool will be used to format the bindings. The default value is `rustfmt`. * Added the `Builder::formatter` method and the `Formatter` type to select - which tool will be used to format the bindings. The - `Formatter::Prettyplease` variant is only available if the - `"prettyplease"` feature is enabled. + which tool will be used to format the bindings. * Added the `Builder::emit_diagnostics` method and the `--emit-diagnostics` - flag to enable emission of diagnostic messages. + flag to enable emission of diagnostic messages under the `experimental` + feature. * Added support for the `"efiapi"` calling convention. * Added the `ParseCallbacks::read_env_var` method which runs everytime `bindgen` reads and environment variable. @@ -189,11 +188,12 @@ * The documentation of the generated `type` aliases now matches the comments of their `typedef` counterparts instead of using the comments of the aliased types. + * The `Builder::rustfmt_bindings` methods and the `--no-rustfmt-bindings` flag + are now deprecated in favor of the formatter API. ## Removed * The following deprecated flags were removed: `--use-msvc-mangling`, `--rustfmt-bindings` and `--size_t-is-usize`. - * The `--no-rustfmt-bindings` flag was removed in favor of `--formatter=none`. * The `Bindings::emit_warnings` and `Bindings::warnings` methods were removed in favor of `--emit-diagnostics`. * Bindgen no longer generates C string constants that cannot be represented as diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index cc00fddaa1..f5af6c87b0 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -28,10 +28,9 @@ env_logger = { version = "0.10.0", optional = true } log = { version = "0.4", optional = true } [features] -default = ["logging", "runtime", "which-rustfmt", "prettyplease"] +default = ["logging", "runtime", "which-rustfmt"] logging = ["bindgen/logging", "env_logger", "log"] static = ["bindgen/static"] runtime = ["bindgen/runtime"] # Dynamically discover a `rustfmt` binary using the `which` crate which-rustfmt = ["bindgen/which-rustfmt"] -prettyplease = ["bindgen/prettyplease"] diff --git a/bindgen-cli/options.rs b/bindgen-cli/options.rs index a0af03e7ff..affcb452e4 100644 --- a/bindgen-cli/options.rs +++ b/bindgen-cli/options.rs @@ -266,7 +266,8 @@ struct BindgenCommand { /// Do not bind size_t as usize (useful on platforms where those types are incompatible). #[arg(long = "no-size_t-is-usize")] no_size_t_is_usize: bool, - /// Do not format the generated bindings with rustfmt. + /// Do not format the generated bindings with rustfmt. This option is deprecated, please use + /// `--formatter=none` instead. #[arg(long)] no_rustfmt_bindings: bool, /// Which tool should be used to format the bindings @@ -833,9 +834,8 @@ where builder = builder.size_t_is_usize(false); } - #[allow(deprecated)] if no_rustfmt_bindings { - builder = builder.rustfmt_bindings(false); + builder = builder.formatter(Formatter::None); } if let Some(formatter) = formatter { diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index 93275c1615..0e95333b5d 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -35,7 +35,7 @@ quote = { version = "1", default-features = false } syn = { version = "2.0", features = ["full", "extra-traits", "visit-mut"]} regex = { version = "1.5", default-features = false , features = ["std", "unicode"] } which = { version = "4.2.1", optional = true, default-features = false } -prettyplease = { version = "0.2.0", optional = true } +prettyplease = { version = "0.2.0" } annotate-snippets = { version = "0.9.1", features = ["color"], optional = true } shlex = "1" rustc-hash = "1.0.1" diff --git a/bindgen/options/mod.rs b/bindgen/options/mod.rs index 4b9dd65738..257b86a823 100644 --- a/bindgen/options/mod.rs +++ b/bindgen/options/mod.rs @@ -1574,13 +1574,13 @@ options! { /// The tool that should be used to format the generated bindings. formatter: Formatter { methods: { - #[cfg_attr(feature = "prettyplease", deprecated)] /// Set whether `rustfmt` should be used to format the generated bindings. /// /// `rustfmt` is used by default. /// /// This method overlaps in functionality with the more general [`Builder::formatter`]. /// Thus, the latter should be preferred. + #[cfg(deprecated)] pub fn rustfmt_bindings(mut self, doit: bool) -> Self { self.options.formatter = if doit { Formatter::Rustfmt From 2bcff0f2ce64629c6e9d8450f8ddd5eb90bca9e0 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Mon, 10 Apr 2023 12:22:48 -0500 Subject: [PATCH 494/942] Prepare to release 0.65.0 (#2492) * Remove debugging prints * Clean changelog * Bump versions * Run doctoc --- CHANGELOG.md | 169 +++++++++++++++++++++++------------------ Cargo.lock | 4 +- bindgen-cli/Cargo.toml | 7 +- bindgen/Cargo.toml | 2 +- bindgen/options/mod.rs | 1 - 5 files changed, 99 insertions(+), 84 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 019564888d..4c2dc0d986 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,126 +7,130 @@ - [Removed](#removed) - [Fixed](#fixed) - [Security](#security) -- [0.64.0](#0640) +- [0.65.0](#0650) - [Added](#added-1) - [Changed](#changed-1) - [Removed](#removed-1) - - [Fixed](#fixed-1) - - [Security](#security-1) -- [0.63.0](#0630) +- [0.64.0](#0640) - [Added](#added-2) - [Changed](#changed-2) - [Removed](#removed-2) -- [0.62.0](#0620) + - [Fixed](#fixed-1) + - [Security](#security-1) +- [0.63.0](#0630) - [Added](#added-3) - [Changed](#changed-3) - - [Fixed](#fixed-2) -- [0.61.0](#0610) + - [Removed](#removed-3) +- [0.62.0](#0620) - [Added](#added-4) - [Changed](#changed-4) + - [Fixed](#fixed-2) +- [0.61.0](#0610) + - [Added](#added-5) + - [Changed](#changed-5) - [Fixed](#fixed-3) - [0.60.1](#0601) - [Fixed](#fixed-4) - [0.60.0](#0600) - - [Added](#added-5) + - [Added](#added-6) - [Fixed](#fixed-5) - - [Changed](#changed-5) - - [Removed](#removed-3) + - [Changed](#changed-6) + - [Removed](#removed-4) - [0.59.2](#0592) - [0.59.1](#0591) - [Fixed](#fixed-6) - [0.59.0](#0590) - - [Added](#added-6) + - [Added](#added-7) - [Fixed](#fixed-7) - - [Changed](#changed-6) + - [Changed](#changed-7) - [0.58.1](#0581) - - [Added](#added-7) -- [0.58.0](#0580) - [Added](#added-8) +- [0.58.0](#0580) + - [Added](#added-9) - [Fixed](#fixed-8) - - [Changed](#changed-7) + - [Changed](#changed-8) - [Deprecated](#deprecated) - - [Removed](#removed-4) + - [Removed](#removed-5) - [Fixed](#fixed-9) - [Security](#security-2) - [0.57.0](#0570) - - [Added](#added-9) + - [Added](#added-10) - [Fixed](#fixed-10) - [0.56.0](#0560) - - [Added](#added-10) - - [Changed](#changed-8) + - [Added](#added-11) + - [Changed](#changed-9) - [Fixed](#fixed-11) - [0.55.1](#0551) - [Fixed](#fixed-12) - [0.55.0](#0550) - - [Removed](#removed-5) - - [Added](#added-11) - - [Changed](#changed-9) + - [Removed](#removed-6) + - [Added](#added-12) + - [Changed](#changed-10) - [Fixed](#fixed-13) - [0.54.1](#0541) - - [Added](#added-12) - - [Changed](#chainged-10) - - [Fixed](#fixed-14) -- [0.54.0](#0540) - [Added](#added-13) - [Changed](#changed-11) + - [Fixed](#fixed-14) +- [0.54.0](#0540) + - [Added](#added-14) + - [Changed](#changed-12) - [Fixed](#fixed-15) - [0.53.3](#0533) - - [Added](#added-14) + - [Added](#added-15) - [Fixed](#fixed-16) - [0.53.2](#0532) - - [Changed](#changed-12) + - [Changed](#changed-13) - [0.53.1](#0531) - - [Added](#added-15) -- [0.53.0](#0530) - [Added](#added-16) - - [Changed](#changed-13) - - [Fixed](#fixed-17) -- [0.52.0](#0520) +- [0.53.0](#0530) - [Added](#added-17) - [Changed](#changed-14) + - [Fixed](#fixed-17) +- [0.52.0](#0520) + - [Added](#added-18) + - [Changed](#changed-15) - [Fixed](#fixed-18) - [0.51.1](#0511) - [Fixed](#fixed-19) - - [Changed](#changed-15) + - [Changed](#changed-16) - [0.51.0](#0510) - [Fixed](#fixed-20) - - [Changed](#changed-16) - - [Added](#added-18) -- [0.50.0](#0500) + - [Changed](#changed-17) - [Added](#added-19) -- [0.49.3](#0493) +- [0.50.0](#0500) - [Added](#added-20) +- [0.49.3](#0493) + - [Added](#added-21) - [0.49.2](#0492) - - [Changed](#changed-17) + - [Changed](#changed-18) - [0.49.1](#0491) - [Fixed](#fixed-21) - - [Changed](#changed-18) + - [Changed](#changed-19) - [0.49.0](#0490) - - [Added](#added-21) + - [Added](#added-22) - [Fixed](#fixed-22) - - [Changed](#changed-19) + - [Changed](#changed-20) - [0.48.1](#0481) - [Fixed](#fixed-23) - [0.48.0](#0480) - - [Changed](#changed-20) + - [Changed](#changed-21) - [Fixed](#fixed-24) - [0.47.4](#0474) - - [Added](#added-22) + - [Added](#added-23) - [0.47.3](#0473) - - [Changed](#changed-21) + - [Changed](#changed-22) - [0.47.2](#0472) - [Fixed](#fixed-25) - [0.47.1](#0471) - - [Changed](#changed-22) + - [Changed](#changed-23) - [Fixed](#fixed-26) - [0.47.0](#0470) - - [Changed](#changed-23) + - [Changed](#changed-24) - [Fixed](#fixed-27) - [0.33.1 .. 0.46.0](#0331--0460) - - [Added](#added-23) - - [Removed](#removed-6) - - [Changed](#changed-24) + - [Added](#added-24) + - [Removed](#removed-7) + - [Changed](#changed-25) - [Fixed](#fixed-28) - [0.33.1](#0331) - [Fixed](#fixed-29) @@ -136,23 +140,23 @@ - [0.32.1](#0321) - [Fixed](#fixed-31) - [0.32.0](#0320) - - [Added](#added-24) - - [Changed](#changed-25) - - [Fixed](#fixed-32) -- [0.31.0](#0310) - [Added](#added-25) - [Changed](#changed-26) + - [Fixed](#fixed-32) +- [0.31.0](#0310) + - [Added](#added-26) + - [Changed](#changed-27) - [Deprecated](#deprecated-1) - - [Removed](#removed-7) + - [Removed](#removed-8) - [Fixed](#fixed-33) - [0.30.0](#0300) - - [Added](#added-26) - - [Changed](#changed-27) + - [Added](#added-27) + - [Changed](#changed-28) - [Deprecated](#deprecated-2) - [Fixed](#fixed-34) - [0.29.0](#0290) - - [Added](#added-27) - - [Changed](#changed-28) + - [Added](#added-28) + - [Changed](#changed-29) - [Fixed](#fixed-35) @@ -161,47 +165,60 @@ # Unreleased +## Added + +## Changed + +## Removed + +## Fixed + +## Security + +# 0.65.0 + ## Added * Added the `Builder::default_visibility` method and the - `--default-visibility` flag to set the default visibility of fields. + `--default-visibility` flag to set the default visibility of fields. (#2338) * Added the `--formatter` CLI flag with the values `none`, `rustfmt` and `prettyplease` to select which tool will be used to format the bindings. The - default value is `rustfmt`. + default value is `rustfmt`. (#2453) * Added the `Builder::formatter` method and the `Formatter` type to select - which tool will be used to format the bindings. + which tool will be used to format the bindings. (#2453) * Added the `Builder::emit_diagnostics` method and the `--emit-diagnostics` flag to enable emission of diagnostic messages under the `experimental` - feature. - * Added support for the `"efiapi"` calling convention. + feature. (#2436) + * Added support for the `"efiapi"` calling convention (#2490). * Added the `ParseCallbacks::read_env_var` method which runs everytime - `bindgen` reads and environment variable. + `bindgen` reads and environment variable. (#2400) + * Added the `ParseCallbacks::generated_link_name_override` method which allow + overriding the link name of items. (#2425) + * Add support for C `enum`s when generating code while using the + `--wrap-static-fns` feature. (#2415) ## Changed * Static functions with no arguments use `void` as their single argument instead of having no arguments when the `--wrap-static-fns` flag is used. + (#2443) * The source file generated when the `--wrap-static-fns` flag is enabled now contains `#include` directives with all the input headers and all the source - code added with the `header_contents` method. + code added with the `header_contents` method. (#2447) * The source file generated when the `--wrap-static-fns` flag no longer uses `asm` labeling and the link name of static wrapper functions is allowed to - be mangled. + be mangled. (#2448) * The documentation of the generated `type` aliases now matches the comments of their `typedef` counterparts instead of using the comments of the aliased - types. + types. (#2463) * The `Builder::rustfmt_bindings` methods and the `--no-rustfmt-bindings` flag - are now deprecated in favor of the formatter API. + are now deprecated in favor of the formatter API. (#2453) ## Removed * The following deprecated flags were removed: `--use-msvc-mangling`, - `--rustfmt-bindings` and `--size_t-is-usize`. + `--rustfmt-bindings` and `--size_t-is-usize`. (#2408) * The `Bindings::emit_warnings` and `Bindings::warnings` methods were removed - in favor of `--emit-diagnostics`. + in favor of `--emit-diagnostics`. (#2436) * Bindgen no longer generates C string constants that cannot be represented as - byte slices. - -## Fixed - -## Security + byte slices. (#2487) # 0.64.0 diff --git a/Cargo.lock b/Cargo.lock index 38cc59ff62..7ddfeb747f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -23,7 +23,7 @@ dependencies = [ [[package]] name = "bindgen" -version = "0.64.0" +version = "0.65.0" dependencies = [ "annotate-snippets", "bitflags", @@ -45,7 +45,7 @@ dependencies = [ [[package]] name = "bindgen-cli" -version = "0.64.0" +version = "0.65.0" dependencies = [ "bindgen", "clap", diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index f5af6c87b0..fd211941d5 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -11,17 +11,16 @@ readme = "../README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.64.0" +version = "0.65.0" edition = "2018" -# If you change this, also update README.md and msrv in .github/workflows/bindgen.yml -rust-version = "1.60.0" +rust-version = "1.64.0" [[bin]] path = "main.rs" name = "bindgen" [dependencies] -bindgen = { path = "../bindgen", version = "=0.64.0", features = ["__cli", "experimental"] } +bindgen = { path = "../bindgen", version = "=0.65.0", features = ["__cli", "experimental"] } shlex = "1" clap = { version = "4", features = ["derive"] } env_logger = { version = "0.10.0", optional = true } diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index 0e95333b5d..2faa6fc68d 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -14,7 +14,7 @@ readme = "../README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.64.0" +version = "0.65.0" edition = "2018" build = "build.rs" # If you change this, also update README.md and msrv in .github/workflows/bindgen.yml diff --git a/bindgen/options/mod.rs b/bindgen/options/mod.rs index 257b86a823..272c485761 100644 --- a/bindgen/options/mod.rs +++ b/bindgen/options/mod.rs @@ -121,7 +121,6 @@ macro_rules! options { }; $({ - eprintln!("doing {}", stringify!($field)); let func: fn(&$ty, &mut Vec) = as_args!($as_args); func(&self.options.$field, &mut args); })* From fa8dd505bc4867d71901ea59443b7cf026c124a5 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Mon, 10 Apr 2023 14:36:50 -0500 Subject: [PATCH 495/942] Add `docs` workflow (#2493) * Add `docs` workflow * Fix documentation warnings --- .github/workflows/bindgen.yml | 17 ++++++++ bindgen-cli/options.rs | 68 ++++++++++++++++---------------- bindgen/ir/analysis/sizedness.rs | 2 +- bindgen/ir/annotations.rs | 2 +- bindgen/ir/function.rs | 6 +-- bindgen/ir/item.rs | 7 ++-- bindgen/ir/template.rs | 30 +++++++------- bindgen/options/as_args.rs | 4 +- bindgen/options/helpers.rs | 2 +- bindgen/options/mod.rs | 14 +++---- 10 files changed, 84 insertions(+), 68 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 38cb15f519..59ff7c005d 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -71,6 +71,23 @@ jobs: - name: Check without default features run: cargo check -p bindgen --no-default-features --features=runtime + docs: + runs-on: ubuntu-latest + env: + RUSTDOCFLAGS: -D warnings + steps: + - uses: actions/checkout@v3 + + - name: Install stable + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + - name: Generate documentation + run: cargo doc --document-private-items + quickchecking: runs-on: ubuntu-latest steps: diff --git a/bindgen-cli/options.rs b/bindgen-cli/options.rs index affcb452e4..407817be5d 100644 --- a/bindgen-cli/options.rs +++ b/bindgen-cli/options.rs @@ -54,22 +54,22 @@ struct BindgenCommand { /// The default style of code used to generate enums. #[arg(long, value_name = "VARIANT")] default_enum_style: Option, - /// Mark any enum whose name matches as a set of bitfield flags. + /// Mark any enum whose name matches REGEX as a set of bitfield flags. #[arg(long, value_name = "REGEX")] bitfield_enum: Vec, - /// Mark any enum whose name matches as a newtype. + /// Mark any enum whose name matches REGEX as a newtype. #[arg(long, value_name = "REGEX")] newtype_enum: Vec, - /// Mark any enum whose name matches as a global newtype. + /// Mark any enum whose name matches REGEX as a global newtype. #[arg(long, value_name = "REGEX")] newtype_global_enum: Vec, - /// Mark any enum whose name matches as a Rust enum. + /// Mark any enum whose name matches REGEX as a Rust enum. #[arg(long, value_name = "REGEX")] rustified_enum: Vec, - /// Mark any enum whose name matches as a series of constants. + /// Mark any enum whose name matches REGEX as a series of constants. #[arg(long, value_name = "REGEX")] constified_enum: Vec, - /// Mark any enum whose name matches as a module of constants. + /// Mark any enum whose name matches REGEX as a module of constants. #[arg(long, value_name = "REGEX")] constified_enum_module: Vec, /// The default signed/unsigned type for C macro constants. @@ -78,34 +78,34 @@ struct BindgenCommand { /// The default style of code used to generate typedefs. #[arg(long, value_name = "VARIANT")] default_alias_style: Option, - /// Mark any typedef alias whose name matches to use normal type aliasing. + /// Mark any typedef alias whose name matches REGEX to use normal type aliasing. #[arg(long, value_name = "REGEX")] normal_alias: Vec, - /// Mark any typedef alias whose name matches to have a new type generated for it. + /// Mark any typedef alias whose name matches REGEX to have a new type generated for it. #[arg(long, value_name = "REGEX")] new_type_alias: Vec, - /// Mark any typedef alias whose name matches to have a new type with Deref and DerefMut to the inner type. + /// Mark any typedef alias whose name matches REGEX to have a new type with Deref and DerefMut to the inner type. #[arg(long, value_name = "REGEX")] new_type_alias_deref: Vec, /// The default style of code used to generate unions with non-Copy members. Note that ManuallyDrop was first stabilized in Rust 1.20.0. #[arg(long, value_name = "STYLE")] default_non_copy_union_style: Option, - /// Mark any union whose name matches and who has a non-Copy member to use a bindgen-generated wrapper for fields. + /// Mark any union whose name matches REGEX and who has a non-Copy member to use a bindgen-generated wrapper for fields. #[arg(long, value_name = "REGEX")] bindgen_wrapper_union: Vec, - /// Mark any union whose name matches and who has a non-Copy member to use ManuallyDrop (stabilized in Rust 1.20.0) for fields. + /// Mark any union whose name matches REGEX and who has a non-Copy member to use ManuallyDrop (stabilized in Rust 1.20.0) for fields. #[arg(long, value_name = "REGEX")] manually_drop_union: Vec, - /// Mark as hidden. + /// Mark TYPE as hidden. #[arg(long, value_name = "TYPE")] blocklist_type: Vec, - /// Mark as hidden. + /// Mark FUNCTION as hidden. #[arg(long, value_name = "FUNCTION")] blocklist_function: Vec, - /// Mark as hidden. + /// Mark ITEM as hidden. #[arg(long, value_name = "ITEM")] blocklist_item: Vec, - /// Mark as hidden. + /// Mark FILE as hidden. #[arg(long, value_name = "FILE")] blocklist_file: Vec, /// Avoid generating layout tests for any type. @@ -144,7 +144,7 @@ struct BindgenCommand { /// Derive Ord on any type. #[arg(long)] with_derive_ord: bool, - /// Avoid including doc comments in the output, see: https://github.com/rust-lang/rust-bindgen/issues/426 + /// Avoid including doc comments in the output, see: #[arg(long)] no_doc_comments: bool, /// Disable allowlisting types recursively. This will cause bindgen to emit Rust code that won't compile! See the `bindgen::Builder::allowlist_recursively` method's documentation for details. @@ -219,10 +219,10 @@ struct BindgenCommand { /// Try to fit macro constants into types smaller than u32/i32 #[arg(long)] fit_macro_constant_types: bool, - /// Mark as opaque. + /// Mark TYPE as opaque. #[arg(long, value_name = "TYPE")] opaque_type: Vec, - /// Write Rust bindings to . + /// Write Rust bindings to OUTPUT. #[arg(long, short, value_name = "OUTPUT")] output: Option, /// Add a raw line of Rust code at the beginning of output. @@ -239,19 +239,19 @@ struct BindgenCommand { /// Conservatively generate inline namespaces to avoid name conflicts. #[arg(long)] conservative_inline_namespaces: bool, - /// Allowlist all the free-standing functions matching . Other non-allowlisted functions will not be generated. + /// Allowlist all the free-standing functions matching REGEX. Other non-allowlisted functions will not be generated. #[arg(long, value_name = "REGEX")] allowlist_function: Vec, /// Generate inline functions. #[arg(long)] generate_inline_functions: bool, - /// Only generate types matching . Other non-allowlisted types will not be generated. + /// Only generate types matching REGEX. Other non-allowlisted types will not be generated. #[arg(long, value_name = "REGEX")] allowlist_type: Vec, - /// Allowlist all the free-standing variables matching . Other non-allowlisted variables will not be generated. + /// Allowlist all the free-standing variables matching REGEX. Other non-allowlisted variables will not be generated. #[arg(long, value_name = "REGEX")] allowlist_var: Vec, - /// Allowlist all contents of . + /// Allowlist all contents of PATH. #[arg(long, value_name = "PATH")] allowlist_file: Vec, /// Print verbose error messages. @@ -280,25 +280,25 @@ struct BindgenCommand { /// The absolute path to the rustfmt configuration file. The configuration file will be used for formatting the bindings. This parameter sets `formatter` to `rustfmt`. #[arg(long, value_name = "PATH", conflicts_with = "no_rustfmt_bindings")] rustfmt_configuration_file: Option, - /// Avoid deriving PartialEq for types matching . + /// Avoid deriving PartialEq for types matching REGEX. #[arg(long, value_name = "REGEX")] no_partialeq: Vec, - /// Avoid deriving Copy and Clone for types matching . + /// Avoid deriving Copy and Clone for types matching REGEX. #[arg(long, value_name = "REGEX")] no_copy: Vec, - /// Avoid deriving Debug for types matching . + /// Avoid deriving Debug for types matching REGEX. #[arg(long, value_name = "REGEX")] no_debug: Vec, - /// Avoid deriving/implementing Default for types matching . + /// Avoid deriving/implementing Default for types matching REGEX. #[arg(long, value_name = "REGEX")] no_default: Vec, - /// Avoid deriving Hash for types matching . + /// Avoid deriving Hash for types matching REGEX. #[arg(long, value_name = "REGEX")] no_hash: Vec, - /// Add #[must_use] annotation to types matching . + /// Add `#[must_use]` annotation to types matching REGEX. #[arg(long, value_name = "REGEX")] must_use_type: Vec, - /// Enables detecting unexposed attributes in functions (slow). Used to generate #[must_use] annotations. + /// Enables detecting unexposed attributes in functions (slow). Used to generate `#[must_use]` annotations. #[arg(long)] enable_function_attribute_detection: bool, /// Use `*const [T; size]` instead of `*const T` for C arrays @@ -337,22 +337,22 @@ struct BindgenCommand { /// Deduplicates extern blocks. #[arg(long)] merge_extern_blocks: bool, - /// Overrides the ABI of functions matching . The value must be of the shape = where can be one of C, stdcall, efiapi, fastcall, thiscall, aapcs, win64 or C-unwind. + /// Overrides the ABI of functions matching REGEX. The OVERRIDE value must be of the shape REGEX=ABI where ABI can be one of C, stdcall, efiapi, fastcall, thiscall, aapcs, win64 or C-unwind. #[arg(long, value_name = "OVERRIDE")] override_abi: Vec, /// Wrap unsafe operations in unsafe blocks. #[arg(long)] wrap_unsafe_ops: bool, - /// Derive custom traits on any kind of type. The value must be of the shape = where is a coma-separated list of derive macros. + /// Derive custom traits on any kind of type. The CUSTOM value must be of the shape REGEX=DERIVE where DERIVE is a coma-separated list of derive macros. #[arg(long, value_name = "CUSTOM")] with_derive_custom: Vec, - /// Derive custom traits on a `struct`. The value must be of the shape = where is a coma-separated list of derive macros. + /// Derive custom traits on a `struct`. The CUSTOM value must be of the shape REGEX=DERIVE where DERIVE is a coma-separated list of derive macros. #[arg(long, value_name = "CUSTOM")] with_derive_custom_struct: Vec, - /// Derive custom traits on an `enum. The value must be of the shape = where is a coma-separated list of derive macros. + /// Derive custom traits on an `enum. The CUSTOM value must be of the shape REGEX=DERIVE where DERIVE is a coma-separated list of derive macros. #[arg(long, value_name = "CUSTOM")] with_derive_custom_enum: Vec, - /// Derive custom traits on a `union`. The value must be of the shape = where is a coma-separated list of derive macros. + /// Derive custom traits on a `union`. The CUSTOM value must be of the shape REGEX=DERIVE where DERIVE is a coma-separated list of derive macros. #[arg(long, value_name = "CUSTOM")] with_derive_custom_union: Vec, /// Generate wrappers for `static` and `static inline` functions. diff --git a/bindgen/ir/analysis/sizedness.rs b/bindgen/ir/analysis/sizedness.rs index d296fe3244..995d700794 100644 --- a/bindgen/ir/analysis/sizedness.rs +++ b/bindgen/ir/analysis/sizedness.rs @@ -52,7 +52,7 @@ pub(crate) enum SizednessResult { /// have an `_address` byte inserted. /// /// We don't properly handle this situation correctly right now: - /// https://github.com/rust-lang/rust-bindgen/issues/586 + /// DependsOnTypeParam, /// Has some size that is known to be greater than zero. That doesn't mean diff --git a/bindgen/ir/annotations.rs b/bindgen/ir/annotations.rs index 844f857b01..423f6c4b60 100644 --- a/bindgen/ir/annotations.rs +++ b/bindgen/ir/annotations.rs @@ -83,7 +83,7 @@ pub(crate) struct Annotations { disallow_debug: bool, /// Manually disable deriving/implement default on this type. disallow_default: bool, - /// Whether to add a #[must_use] annotation to this type. + /// Whether to add a `#[must_use]` annotation to this type. must_use_type: bool, /// Visibility of struct fields. You can set this on /// structs (it will apply to all the fields), or individual fields. diff --git a/bindgen/ir/function.rs b/bindgen/ir/function.rs index bfcc1694fb..fab380e45f 100644 --- a/bindgen/ir/function.rs +++ b/bindgen/ir/function.rs @@ -650,9 +650,9 @@ impl FunctionSig { /// /// For more details, see: /// - /// * https://github.com/rust-lang/rust-bindgen/issues/547, - /// * https://github.com/rust-lang/rust/issues/38848, - /// * and https://github.com/rust-lang/rust/issues/40158 + /// * , + /// * , + /// * and pub(crate) fn function_pointers_can_derive(&self) -> bool { if self.argument_types.len() > RUST_DERIVE_FUNPTR_LIMIT { return false; diff --git a/bindgen/ir/item.rs b/bindgen/ir/item.rs index 9a1377e17f..a50d267a5c 100644 --- a/bindgen/ir/item.rs +++ b/bindgen/ir/item.rs @@ -1096,7 +1096,7 @@ impl Item { }) } - /// Whether this is a #[must_use] type. + /// Whether this is a `#[must_use]` type. pub(crate) fn must_use(&self, ctx: &BindgenContext) -> bool { self.annotations().must_use_type() || ctx.must_use_type_by_name(self) } @@ -1749,9 +1749,8 @@ impl Item { ret } - /// A named type is a template parameter, e.g., the "T" in Foo. They're - /// always local so it's the only exception when there's no declaration for - /// a type. + /// A named type is a template parameter, e.g., the `T` in `Foo`. They're always local so + /// it's the only exception when there's no declaration for a type. pub(crate) fn type_param( with_id: Option, location: clang::Cursor, diff --git a/bindgen/ir/template.rs b/bindgen/ir/template.rs index d0be17ecc6..4dd8442c58 100644 --- a/bindgen/ir/template.rs +++ b/bindgen/ir/template.rs @@ -77,26 +77,26 @@ use crate::clang; /// The following table depicts the results of each trait method when invoked on /// each of the declarations above: /// -/// +------+----------------------+--------------------------+------------------------+---- -/// |Decl. | self_template_params | num_self_template_params | all_template_parameters| ... -/// +------+----------------------+--------------------------+------------------------+---- -/// |Foo | [T, U] | 2 | [T, U] | ... -/// |Bar | [V] | 1 | [T, U, V] | ... -/// |Inner | [] | 0 | [T, U] | ... -/// |Lol | [W] | 1 | [T, U, W] | ... -/// |Wtf | [X] | 1 | [T, U, X] | ... -/// |Qux | [] | 0 | [] | ... +/// +------+----------------------+--------------------------+-------------------------+---- +/// |Decl. | self_template_params | num_self_template_params | all_template_parameters | ... +/// +------+----------------------+--------------------------+-------------------------+---- +/// |Foo | T, U | 2 | T, U | ... +/// |Bar | V | 1 | T, U, V | ... +/// |Inner | | 0 | T, U | ... +/// |Lol | W | 1 | T, U, W | ... +/// |Wtf | X | 1 | T, U, X | ... +/// |Qux | | 0 | | ... /// +------+----------------------+--------------------------+------------------------+---- /// /// ----+------+-----+----------------------+ /// ... |Decl. | ... | used_template_params | /// ----+------+-----+----------------------+ -/// ... |Foo | ... | [T, U] | -/// ... |Bar | ... | [V] | -/// ... |Inner | ... | [] | -/// ... |Lol | ... | [T] | -/// ... |Wtf | ... | [T] | -/// ... |Qux | ... | [] | +/// ... |Foo | ... | T, U | +/// ... |Bar | ... | V | +/// ... |Inner | ... | | +/// ... |Lol | ... | T | +/// ... |Wtf | ... | T | +/// ... |Qux | ... | | /// ----+------+-----+----------------------+ pub(crate) trait TemplateParameters: Sized { /// Get the set of `ItemId`s that make up this template declaration's free diff --git a/bindgen/options/as_args.rs b/bindgen/options/as_args.rs index 4166843aa3..13439c45f8 100644 --- a/bindgen/options/as_args.rs +++ b/bindgen/options/as_args.rs @@ -2,7 +2,7 @@ use std::path::PathBuf; use crate::RegexSet; -/// Trait used to turn [`BindgenOptions`] fields into CLI args. +/// Trait used to turn [`crate::BindgenOptions`] fields into CLI args. pub(super) trait AsArgs { fn as_args(&self, args: &mut Vec, flag: &str); } @@ -38,7 +38,7 @@ impl AsArgs for Option { } } -/// If the `Option` is `Some(path)`, push `flag` followed by the [`PathBuf::display`] +/// If the `Option` is `Some(path)`, push `flag` followed by the [`std::path::Path::display`] /// representation of `path`. impl AsArgs for Option { fn as_args(&self, args: &mut Vec, flag: &str) { diff --git a/bindgen/options/helpers.rs b/bindgen/options/helpers.rs index 5a62f52b4e..276cb47c77 100644 --- a/bindgen/options/helpers.rs +++ b/bindgen/options/helpers.rs @@ -1,4 +1,4 @@ -/// Helper function that appends extra documentation to [`Builder`] methods that support regular +/// Helper function that appends extra documentation to [`crate::Builder`] methods that support regular /// expressions in their input. macro_rules! regex_option { ($(#[$attrs:meta])* pub fn $($tokens:tt)*) => { diff --git a/bindgen/options/mod.rs b/bindgen/options/mod.rs index 272c485761..9f45e6e89a 100644 --- a/bindgen/options/mod.rs +++ b/bindgen/options/mod.rs @@ -1,6 +1,6 @@ //! Declarations and setter methods for `bindgen` options. //! -//! The main entry point of this module is the [`options`] macro. +//! The main entry point of this module is the `options` macro. #[macro_use] mod helpers; mod as_args; @@ -504,7 +504,7 @@ options! { methods: { /// Set the default style of code generation for `typedef`s. /// - /// If this method is not called, the [`AliasVaration::TypeAlias`] style is used by + /// If this method is not called, the [`AliasVariation::TypeAlias`] style is used by /// default. /// /// To set the style for individual `typedefs`s, use [`Builder::type_alias`], @@ -563,7 +563,7 @@ options! { regex_option! { /// Mark the given `typedef` to be generated as a newtype that can be dereferenced. /// - /// This is similar to the [`Builder:new_type_alias`] style, but the newtype + /// This is similar to the [`Builder::new_type_alias`] style, but the newtype /// implements `Deref` and `DerefMut` with the aliased type as a target. pub fn new_type_alias_deref>(mut self, arg: T) -> Builder { self.options.new_type_alias_deref.insert(arg); @@ -1579,7 +1579,7 @@ options! { /// /// This method overlaps in functionality with the more general [`Builder::formatter`]. /// Thus, the latter should be preferred. - #[cfg(deprecated)] + #[deprecated] pub fn rustfmt_bindings(mut self, doit: bool) -> Self { self.options.formatter = if doit { Formatter::Rustfmt @@ -1615,8 +1615,8 @@ options! { /// The default `rustfmt` options are used if `None` is passed to this method or if /// this method is not called at all. /// - /// Calling this method will set the [`Bindings::rustfmt_bindings`] option to `true` - /// and the [`Bindings::formatter`] option to [`Formatter::Rustfmt`]. + /// Calling this method will set the [`Builder::rustfmt_bindings`] option to `true` + /// and the [`Builder::formatter`] option to [`Formatter::Rustfmt`]. pub fn rustfmt_configuration_file(mut self, path: Option) -> Self { self = self.formatter(Formatter::Rustfmt); self.options.rustfmt_configuration_file = path; @@ -1962,7 +1962,7 @@ options! { /// [`Builder::wrap_static_fns`] method. /// /// The default path is `temp_dir/bindgen/extern`, where `temp_dir` is the path - /// returned by [`std::fs::temp_dir`] . + /// returned by [`std::env::temp_dir`] . pub fn wrap_static_fns_path>(mut self, path: T) -> Self { self.options.wrap_static_fns_path = Some(path.as_ref().to_owned()); self From d0d3448d8c668b28598032cf40ddb5593d841b2a Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Mon, 10 Apr 2023 15:20:55 -0500 Subject: [PATCH 496/942] Improve documentation about regex (#2494) Remove repeating documentation and keep it in a single section. --- bindgen/lib.rs | 23 ++++++++++++++++++----- bindgen/options/helpers.rs | 9 +++------ bindgen/options/mod.rs | 10 +--------- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 5b54f45ad1..03d6d736c3 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -262,14 +262,27 @@ impl std::fmt::Display for Formatter { /// /// # Regular expression arguments /// -/// Some [`Builder`] methods like the `allowlist_*` and `blocklist_*` family of methods allow -/// regular expressions as arguments. These regular expressions will be parenthesized and wrapped -/// in `^` and `$`. So if `` is passed as argument, the regular expression to be stored will -/// be `^()$`. +/// Some [`Builder`] methods such as the `allowlist_*` and `blocklist_*` methods allow regular +/// expressions as arguments. These regular expressions will be enclosed in parentheses and +/// anchored with `^` and `$`. So if the argument passed is ``, the regular expression to be +/// stored will be `^()$`. +/// +/// As a consequence, regular expressions passed to `bindgen` will try to match the whole name of +/// an item instead of a section of it, which means that to match any items with the prefix +/// `prefix`, the `prefix.*` regular expression must be used. +/// +/// Certain methods, like [`Builder::allowlist_function`], use regular expressions over function +/// names. To match C++ methods, prefix the name of the type where they belong followed by an +/// underscore. So if the type `Foo` has a method `bar`, it can be matched with the `Foo_bar` +/// regular expression. +/// +/// Additionally, Objective-C interfaces can be matched by prefixing the regular expression with +/// `I`. For example, the `IFoo` regular expression matches the `Foo` interface and the `IFoo_foo` +/// regular expression matches the `foo` method of the `Foo` interface. /// /// Releases of `bindgen` with a version lesser or equal to `0.62.0` used to accept the wildcard /// pattern `*` as a valid regular expression. This behavior has been deprecated and the `.*` -/// pattern must be used instead. +/// regular expression must be used instead. #[derive(Debug, Default, Clone)] pub struct Builder { options: BindgenOptions, diff --git a/bindgen/options/helpers.rs b/bindgen/options/helpers.rs index 276cb47c77..1816c72b57 100644 --- a/bindgen/options/helpers.rs +++ b/bindgen/options/helpers.rs @@ -4,12 +4,9 @@ macro_rules! regex_option { ($(#[$attrs:meta])* pub fn $($tokens:tt)*) => { $(#[$attrs])* /// - /// Regular expressions are supported. To match any items that start with `prefix` use the - /// `"prefix.*"` regular expression. - /// - /// Check the [regular expression arguments](./struct.Builder.html#regular-expression-arguments) - /// section and the [regex](https://docs.rs/regex) crate documentation for further - /// information. + /// Regular expressions are supported. Check the [regular expression + /// arguments](./struct.Builder.html#regular-expression-arguments) section and the + /// [regex](https://docs.rs/regex) crate documentation for further information. pub fn $($tokens)* }; } diff --git a/bindgen/options/mod.rs b/bindgen/options/mod.rs index 9f45e6e89a..c60da71e81 100644 --- a/bindgen/options/mod.rs +++ b/bindgen/options/mod.rs @@ -171,10 +171,6 @@ options! { methods: { regex_option! { /// Do not generate any bindings for the given function. - /// - /// Methods can be blocklisted by prefixing the name of the type where they belong - /// followed by an underscore. So if the type `Foo` has a method `bar`, it can be - /// blocklisted as `Foo_bar`. pub fn blocklist_function>(mut self, arg: T) -> Builder { self.options.blocklisted_functions.insert(arg); self @@ -289,10 +285,6 @@ options! { regex_option! { /// Generate bindings for the given function. /// - /// Methods can be allowlisted by prefixing the name of the type where they belong - /// followed by an underscore. So if the type `Foo` has a method `bar`, it can be - /// allowlisted as `Foo_bar`. - /// /// This option is transitive by default. Check the documentation of the /// [`Builder::allowlist_recursively`] method for further information. pub fn allowlist_function>(mut self, arg: T) -> Builder { @@ -418,7 +410,7 @@ options! { regex_option! { /// Mark the given `enum` as a Rust `enum`. /// - /// This means that each variant of the `enum` will be represented as a Rust `enum + /// This means that each variant of the `enum` will be represented as a Rust `enum` /// variant. /// /// **Use this with caution**, creating an instance of a Rust `enum` with an From d9996ab318b4525218363dc26980273d12f35b9d Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Mon, 10 Apr 2023 15:22:53 -0500 Subject: [PATCH 497/942] Fix Clippy lints (#2495) --- bindgen-cli/options.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindgen-cli/options.rs b/bindgen-cli/options.rs index 407817be5d..9ab202f1b8 100644 --- a/bindgen-cli/options.rs +++ b/bindgen-cli/options.rs @@ -1019,7 +1019,7 @@ where "--with-derive-custom-union", ), ] { - let name = emit_diagnostics.then(|| name); + let name = emit_diagnostics.then_some(name); for custom_derive in custom_derives { let (regex, derives) = custom_derive .rsplit_once('=') From 7d243056d335fdc4537f7bca73c06d01aae24ddc Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Mon, 10 Apr 2023 15:42:30 -0500 Subject: [PATCH 498/942] Prepare to release 0.65.1 (#2496) * Bump versions * Update changelog --- CHANGELOG.md | 33 +++++++++++++++++---------------- Cargo.lock | 4 ++-- bindgen-cli/Cargo.toml | 4 ++-- bindgen/Cargo.toml | 2 +- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c2dc0d986..aea2e321cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ - [Removed](#removed) - [Fixed](#fixed) - [Security](#security) +- [0.65.1](#0651) + - [Fixed](#fixed-1) - [0.65.0](#0650) - [Added](#added-1) - [Changed](#changed-1) @@ -14,13 +16,10 @@ - [0.64.0](#0640) - [Added](#added-2) - [Changed](#changed-2) - - [Removed](#removed-2) - - [Fixed](#fixed-1) - - [Security](#security-1) - [0.63.0](#0630) - [Added](#added-3) - [Changed](#changed-3) - - [Removed](#removed-3) + - [Removed](#removed-2) - [0.62.0](#0620) - [Added](#added-4) - [Changed](#changed-4) @@ -35,7 +34,7 @@ - [Added](#added-6) - [Fixed](#fixed-5) - [Changed](#changed-6) - - [Removed](#removed-4) + - [Removed](#removed-3) - [0.59.2](#0592) - [0.59.1](#0591) - [Fixed](#fixed-6) @@ -50,9 +49,9 @@ - [Fixed](#fixed-8) - [Changed](#changed-8) - [Deprecated](#deprecated) - - [Removed](#removed-5) + - [Removed](#removed-4) - [Fixed](#fixed-9) - - [Security](#security-2) + - [Security](#security-1) - [0.57.0](#0570) - [Added](#added-10) - [Fixed](#fixed-10) @@ -63,7 +62,7 @@ - [0.55.1](#0551) - [Fixed](#fixed-12) - [0.55.0](#0550) - - [Removed](#removed-6) + - [Removed](#removed-5) - [Added](#added-12) - [Changed](#changed-10) - [Fixed](#fixed-13) @@ -129,7 +128,7 @@ - [Fixed](#fixed-27) - [0.33.1 .. 0.46.0](#0331--0460) - [Added](#added-24) - - [Removed](#removed-7) + - [Removed](#removed-6) - [Changed](#changed-25) - [Fixed](#fixed-28) - [0.33.1](#0331) @@ -147,7 +146,7 @@ - [Added](#added-26) - [Changed](#changed-27) - [Deprecated](#deprecated-1) - - [Removed](#removed-8) + - [Removed](#removed-7) - [Fixed](#fixed-33) - [0.30.0](#0300) - [Added](#added-27) @@ -175,6 +174,14 @@ ## Security +# 0.65.1 + +## Fixed + +* The `Builder::rustfmt_bindings` method was added back and tagged as + deprecated instead of being removed. +* Broken documentation links were fixed. + # 0.65.0 ## Added @@ -247,12 +254,6 @@ * The `ParseCallbacks::add_derives` method now receives `DeriveInfo<'_>` as argument instead of a `&str`. This type also includes the kind of target type. -## Removed - -## Fixed - -## Security - # 0.63.0 ## Added diff --git a/Cargo.lock b/Cargo.lock index 7ddfeb747f..7d8903d6ae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -23,7 +23,7 @@ dependencies = [ [[package]] name = "bindgen" -version = "0.65.0" +version = "0.65.1" dependencies = [ "annotate-snippets", "bitflags", @@ -45,7 +45,7 @@ dependencies = [ [[package]] name = "bindgen-cli" -version = "0.65.0" +version = "0.65.1" dependencies = [ "bindgen", "clap", diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index fd211941d5..731f1bee1a 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -11,7 +11,7 @@ readme = "../README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.65.0" +version = "0.65.1" edition = "2018" rust-version = "1.64.0" @@ -20,7 +20,7 @@ path = "main.rs" name = "bindgen" [dependencies] -bindgen = { path = "../bindgen", version = "=0.65.0", features = ["__cli", "experimental"] } +bindgen = { path = "../bindgen", version = "=0.65.1", features = ["__cli", "experimental"] } shlex = "1" clap = { version = "4", features = ["derive"] } env_logger = { version = "0.10.0", optional = true } diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index 2faa6fc68d..838524fd44 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -14,7 +14,7 @@ readme = "../README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.65.0" +version = "0.65.1" edition = "2018" build = "build.rs" # If you change this, also update README.md and msrv in .github/workflows/bindgen.yml From a9681090bf1d925b3da7444e75a64dfc3e46a827 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Mon, 10 Apr 2023 16:53:49 -0500 Subject: [PATCH 499/942] Do not return when calling void functions (#2497) * Do not return when calling `void` functions Update the code generation for the `--wrap-static-fns` feature so the wrapper for a static function that returns `void` no longer contains a `return` statement and only calls the function instead. --- CHANGELOG.md | 2 ++ .../tests/generated/wrap_static_fns.c | 1 + .../expectations/tests/wrap-static-fns.rs | 4 +++ bindgen-tests/tests/headers/wrap-static-fns.h | 4 +++ bindgen/codegen/serialize.rs | 25 ++++++++++++++++--- bindgen/ir/ty.rs | 4 +++ 6 files changed, 36 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aea2e321cc..bbd4f198e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -167,6 +167,8 @@ ## Added ## Changed +* Wrappers for static functions that return `void` no longer contain a `return` + statement and only call the static function instead. ## Removed diff --git a/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c b/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c index abc5224229..8d6e97aad1 100644 --- a/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c +++ b/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c @@ -10,3 +10,4 @@ int takes_fn__extern(int (f) (int)) { return takes_fn(f); } int takes_alias__extern(func f) { return takes_alias(f); } int takes_qualified__extern(const int *const *arg) { return takes_qualified(arg); } enum foo takes_enum__extern(const enum foo f) { return takes_enum(f); } +void nevermore__extern(void) { nevermore(); } diff --git a/bindgen-tests/tests/expectations/tests/wrap-static-fns.rs b/bindgen-tests/tests/expectations/tests/wrap-static-fns.rs index 0db78054ac..2800d7034d 100644 --- a/bindgen-tests/tests/expectations/tests/wrap-static-fns.rs +++ b/bindgen-tests/tests/expectations/tests/wrap-static-fns.rs @@ -56,3 +56,7 @@ extern "C" { #[link_name = "takes_enum__extern"] pub fn takes_enum(f: foo) -> foo; } +extern "C" { + #[link_name = "nevermore__extern"] + pub fn nevermore(); +} diff --git a/bindgen-tests/tests/headers/wrap-static-fns.h b/bindgen-tests/tests/headers/wrap-static-fns.h index faa7b7f1ad..4a1862b050 100644 --- a/bindgen-tests/tests/headers/wrap-static-fns.h +++ b/bindgen-tests/tests/headers/wrap-static-fns.h @@ -40,3 +40,7 @@ enum foo { static inline enum foo takes_enum(const enum foo f) { return f; } + +static inline void nevermore() { + while (1) { } +} diff --git a/bindgen/codegen/serialize.rs b/bindgen/codegen/serialize.rs index ac6202356e..0baa70a899 100644 --- a/bindgen/codegen/serialize.rs +++ b/bindgen/codegen/serialize.rs @@ -102,14 +102,31 @@ impl<'a> CSerialize<'a> for Function { // The name used for the wrapper self. let wrap_name = format!("{}{}", name, ctx.wrap_static_fns_suffix()); + // The function's return type - let ret_ty = signature.return_type(); + let ret_ty = { + let type_id = signature.return_type(); + let item = ctx.resolve_item(type_id); + let ret_ty = item.expect_type(); + + // Write `ret_ty`. + ret_ty.serialize(ctx, item, stack, writer)?; + + ret_ty + }; - // Write `ret_ty wrap_name(args) { return name(arg_names)' }` - ret_ty.serialize(ctx, (), stack, writer)?; + // Write `wrap_name(args`. write!(writer, " {}(", wrap_name)?; serialize_args(&args, ctx, writer)?; - write!(writer, ") {{ return {}(", name)?; + + // Write `) { name(` if the function returns void and `) { return name(` if it does not. + if ret_ty.is_void() { + write!(writer, ") {{ {}(", name)?; + } else { + write!(writer, ") {{ return {}(", name)?; + } + + // Write `arg_names); }`. serialize_sep(", ", args.iter(), ctx, writer, |(name, _), _, buf| { write!(buf, "{}", name).map_err(From::from) })?; diff --git a/bindgen/ir/ty.rs b/bindgen/ir/ty.rs index 8c505aa49f..572d7de451 100644 --- a/bindgen/ir/ty.rs +++ b/bindgen/ir/ty.rs @@ -124,6 +124,10 @@ impl Type { matches!(self.kind, TypeKind::Enum(..)) } + /// Is this void? + pub(crate) fn is_void(&self) -> bool { + matches!(self.kind, TypeKind::Void) + } /// Is this either a builtin or named type? pub(crate) fn is_builtin_or_type_param(&self) -> bool { matches!( From 46a08b0c47426a0d1dd1e2dbc8a404301fe43379 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Thu, 13 Apr 2023 18:58:45 +0200 Subject: [PATCH 500/942] Generate `CStr`s instead of byte arrays. (#2471) --- CHANGELOG.md | 8 ++- bindgen-cli/options.rs | 8 +++ .../tests/libclang-5/constant-evaluate.rs | 4 +- .../tests/libclang-9/constant-evaluate.rs | 4 +- .../tests/expectations/tests/macro_const.rs | 4 +- .../expectations/tests/macro_const_1_0.rs | 4 +- .../tests/expectations/tests/strings_array.rs | 10 +++ .../tests/expectations/tests/strings_cstr.rs | 17 +++++ bindgen-tests/tests/headers/strings_array.h | 5 ++ bindgen-tests/tests/headers/strings_cstr.h | 5 ++ bindgen/codegen/helpers.rs | 6 -- bindgen/codegen/mod.rs | 72 ++++++++++--------- bindgen/features.rs | 6 ++ bindgen/options/mod.rs | 17 +++++ 14 files changed, 123 insertions(+), 47 deletions(-) create mode 100644 bindgen-tests/tests/expectations/tests/strings_array.rs create mode 100644 bindgen-tests/tests/expectations/tests/strings_cstr.rs create mode 100644 bindgen-tests/tests/headers/strings_array.h create mode 100644 bindgen-tests/tests/headers/strings_cstr.h diff --git a/CHANGELOG.md b/CHANGELOG.md index bbd4f198e9..393d266e68 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -166,7 +166,13 @@ ## Added +* Added the `--generate-cstr` CLI flag to generate string constants as `&CStr` + instead of `&[u8]`. (Requires Rust 1.59 or higher.) + ## Changed + +* Non-UTF-8 string constants are now generated as references (`&[u8; SIZE]`) + instead of arrays (`[u8; SIZE]`) to match UTF-8 strings. * Wrappers for static functions that return `void` no longer contain a `return` statement and only call the static function instead. @@ -252,7 +258,7 @@ * The return type is now ommited in signatures of functions returning `void`. * Updated the `clap` dependency for `bindgen-cli` to 4. * Rewrote the `bindgen-cli` argument parser which could introduce unexpected - behavior changes. + behavior changes. * The `ParseCallbacks::add_derives` method now receives `DeriveInfo<'_>` as argument instead of a `&str`. This type also includes the kind of target type. diff --git a/bindgen-cli/options.rs b/bindgen-cli/options.rs index 9ab202f1b8..8e292f958a 100644 --- a/bindgen-cli/options.rs +++ b/bindgen-cli/options.rs @@ -156,6 +156,9 @@ struct BindgenCommand { /// Generate block signatures instead of void pointers. #[arg(long)] generate_block: bool, + /// Generate string constants as `&CStr` instead of `&[u8]`. + #[arg(long)] + generate_cstr: bool, /// Use extern crate instead of use for block. #[arg(long)] block_extern_crate: bool, @@ -430,6 +433,7 @@ where no_recursive_allowlist, objc_extern_crate, generate_block, + generate_cstr, block_extern_crate, distrust_clang_mangling, builtins, @@ -755,6 +759,10 @@ where builder = builder.generate_block(true); } + if generate_cstr { + builder = builder.generate_cstr(true); + } + if block_extern_crate { builder = builder.block_extern_crate(true); } diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/constant-evaluate.rs b/bindgen-tests/tests/expectations/tests/libclang-5/constant-evaluate.rs index 9debe39d3e..6263faed6a 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-5/constant-evaluate.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-5/constant-evaluate.rs @@ -21,5 +21,5 @@ pub const BAZ: ::std::os::raw::c_longlong = 24; pub const fuzz: f64 = 51.0; pub const BAZZ: ::std::os::raw::c_char = 53; pub const WAT: ::std::os::raw::c_char = 0; -pub const bytestring: &[u8; 4usize] = b"Foo\0"; -pub const NOT_UTF8: [u8; 5usize] = [240u8, 40u8, 140u8, 40u8, 0u8]; +pub const bytestring: &[u8; 4] = b"Foo\0"; +pub const NOT_UTF8: &[u8; 5] = b"\xF0(\x8C(\0"; diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/constant-evaluate.rs b/bindgen-tests/tests/expectations/tests/libclang-9/constant-evaluate.rs index 9debe39d3e..6263faed6a 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/constant-evaluate.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/constant-evaluate.rs @@ -21,5 +21,5 @@ pub const BAZ: ::std::os::raw::c_longlong = 24; pub const fuzz: f64 = 51.0; pub const BAZZ: ::std::os::raw::c_char = 53; pub const WAT: ::std::os::raw::c_char = 0; -pub const bytestring: &[u8; 4usize] = b"Foo\0"; -pub const NOT_UTF8: [u8; 5usize] = [240u8, 40u8, 140u8, 40u8, 0u8]; +pub const bytestring: &[u8; 4] = b"Foo\0"; +pub const NOT_UTF8: &[u8; 5] = b"\xF0(\x8C(\0"; diff --git a/bindgen-tests/tests/expectations/tests/macro_const.rs b/bindgen-tests/tests/expectations/tests/macro_const.rs index de423a2af0..eecd8bd74e 100644 --- a/bindgen-tests/tests/expectations/tests/macro_const.rs +++ b/bindgen-tests/tests/expectations/tests/macro_const.rs @@ -5,10 +5,10 @@ non_upper_case_globals )] -pub const foo: &[u8; 4usize] = b"bar\0"; +pub const foo: &[u8; 4] = b"bar\0"; pub const CHAR: u8 = 98u8; pub const CHARR: u8 = 0u8; pub const FLOAT: f64 = 5.09; pub const FLOAT_EXPR: f64 = 0.005; pub const LONG: u32 = 3; -pub const INVALID_UTF8: [u8; 5usize] = [240u8, 40u8, 140u8, 40u8, 0u8]; +pub const INVALID_UTF8: &[u8; 5] = b"\xF0(\x8C(\0"; diff --git a/bindgen-tests/tests/expectations/tests/macro_const_1_0.rs b/bindgen-tests/tests/expectations/tests/macro_const_1_0.rs index e135661121..8523a68af9 100644 --- a/bindgen-tests/tests/expectations/tests/macro_const_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/macro_const_1_0.rs @@ -5,10 +5,10 @@ non_upper_case_globals )] -pub const foo: &'static [u8; 4usize] = b"bar\0"; +pub const foo: &'static [u8; 4] = b"bar\0"; pub const CHAR: u8 = 98u8; pub const CHARR: u8 = 0u8; pub const FLOAT: f64 = 5.09; pub const FLOAT_EXPR: f64 = 0.005; pub const LONG: u32 = 3; -pub const INVALID_UTF8: [u8; 5usize] = [240u8, 40u8, 140u8, 40u8, 0u8]; +pub const INVALID_UTF8: &'static [u8; 5] = b"\xF0(\x8C(\0"; diff --git a/bindgen-tests/tests/expectations/tests/strings_array.rs b/bindgen-tests/tests/expectations/tests/strings_array.rs new file mode 100644 index 0000000000..76e8debd78 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/strings_array.rs @@ -0,0 +1,10 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +pub const MY_STRING_UTF8: &'static [u8; 14] = b"Hello, world!\0"; +pub const MY_STRING_INTERIOR_NULL: &'static [u8; 7] = b"Hello,\0"; +pub const MY_STRING_NON_UTF8: &'static [u8; 7] = b"ABCDE\xFF\0"; diff --git a/bindgen-tests/tests/expectations/tests/strings_cstr.rs b/bindgen-tests/tests/expectations/tests/strings_cstr.rs new file mode 100644 index 0000000000..e7f275f32c --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/strings_cstr.rs @@ -0,0 +1,17 @@ +#![allow( + dead_code, + non_snake_case, + non_camel_case_types, + non_upper_case_globals +)] + +#[allow(unsafe_code)] +pub const MY_STRING_UTF8: &::std::ffi::CStr = unsafe { + ::std::ffi::CStr::from_bytes_with_nul_unchecked(b"Hello, world!\0") +}; +#[allow(unsafe_code)] +pub const MY_STRING_INTERIOR_NULL: &::std::ffi::CStr = + unsafe { ::std::ffi::CStr::from_bytes_with_nul_unchecked(b"Hello,\0") }; +#[allow(unsafe_code)] +pub const MY_STRING_NON_UTF8: &::std::ffi::CStr = + unsafe { ::std::ffi::CStr::from_bytes_with_nul_unchecked(b"ABCDE\xFF\0") }; diff --git a/bindgen-tests/tests/headers/strings_array.h b/bindgen-tests/tests/headers/strings_array.h new file mode 100644 index 0000000000..6a61d71049 --- /dev/null +++ b/bindgen-tests/tests/headers/strings_array.h @@ -0,0 +1,5 @@ +// bindgen-flags: --rust-target=1.0 + +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/strings_cstr.h b/bindgen-tests/tests/headers/strings_cstr.h new file mode 100644 index 0000000000..8b1d40e689 --- /dev/null +++ b/bindgen-tests/tests/headers/strings_cstr.h @@ -0,0 +1,5 @@ +// bindgen-flags: --rust-target=1.59 --generate-cstr + +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/codegen/helpers.rs b/bindgen/codegen/helpers.rs index 726fe75eb0..8231e07c11 100644 --- a/bindgen/codegen/helpers.rs +++ b/bindgen/codegen/helpers.rs @@ -249,12 +249,6 @@ pub(crate) mod ast_ty { quote!(#val) } - pub(crate) fn byte_array_expr(bytes: &[u8]) -> TokenStream { - let mut bytes: Vec<_> = bytes.to_vec(); - bytes.push(0); - quote! { [ #(#bytes),* ] } - } - pub(crate) fn cstr_expr(mut string: String) -> TokenStream { string.push('\0'); let b = proc_macro2::Literal::byte_string(string.as_bytes()); diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 11e49b8d75..81aa897e8e 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -57,9 +57,10 @@ use crate::{Entry, HashMap, HashSet}; use std::borrow::Cow; use std::cell::Cell; use std::collections::VecDeque; +use std::ffi::CStr; use std::fmt::{self, Write}; use std::ops; -use std::str::FromStr; +use std::str::{self, FromStr}; #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum CodegenError { @@ -692,41 +693,48 @@ impl CodeGenerator for Var { }); } VarType::String(ref bytes) => { - // Account the trailing zero. - // + let prefix = ctx.trait_prefix(); + + let options = ctx.options(); + let rust_features = options.rust_features; + + let mut cstr_bytes = bytes.clone(); + cstr_bytes.push(0); + let len = proc_macro2::Literal::usize_unsuffixed( + cstr_bytes.len(), + ); + let cstr = CStr::from_bytes_with_nul(&cstr_bytes).unwrap(); + // TODO: Here we ignore the type we just made up, probably // we should refactor how the variable type and ty ID work. - let len = bytes.len() + 1; - let ty = quote! { - [u8; #len] - }; + let array_ty = quote! { [u8; #len] }; + let cstr_ty = quote! { ::#prefix::ffi::CStr }; - match String::from_utf8(bytes.clone()) { - Ok(string) => { - let cstr = helpers::ast_ty::cstr_expr(string); - if ctx - .options() - .rust_features - .static_lifetime_elision - { - result.push(quote! { - #(#attrs)* - pub const #canonical_ident : &#ty = #cstr ; - }); - } else { - result.push(quote! { - #(#attrs)* - pub const #canonical_ident : &'static #ty = #cstr ; - }); - } - } - Err(..) => { - let bytes = helpers::ast_ty::byte_array_expr(bytes); - result.push(quote! { - #(#attrs)* - pub const #canonical_ident : #ty = #bytes ; - }); + let bytes = proc_macro2::Literal::byte_string( + cstr.to_bytes_with_nul(), + ); + + if rust_features.const_cstr && options.generate_cstr { + result.push(quote! { + #(#attrs)* + #[allow(unsafe_code)] + pub const #canonical_ident: &#cstr_ty = unsafe { + #cstr_ty::from_bytes_with_nul_unchecked(#bytes) + }; + }); + } else { + let lifetime = if rust_features.static_lifetime_elision + { + None + } else { + Some(quote! { 'static }) } + .into_iter(); + + result.push(quote! { + #(#attrs)* + pub const #canonical_ident: &#(#lifetime )*#array_ty = #bytes ; + }); } } VarType::Float(f) => { diff --git a/bindgen/features.rs b/bindgen/features.rs index fe6f415887..bee0e859b9 100644 --- a/bindgen/features.rs +++ b/bindgen/features.rs @@ -128,6 +128,9 @@ macro_rules! rust_target_base { /// Rust stable 1.47 /// * `larger_arrays` ([Tracking issue](https://github.com/rust-lang/rust/pull/74060)) => Stable_1_47 => 1.47; + /// Rust stable 1.59 + /// * `CStr::from_bytes_with_nul_unchecked` in `const` contexts ([PR](https://github.com/rust-lang/rust/pull/54745)) + => Stable_1_59 => 1.59; /// Rust stable 1.64 /// * `core_ffi_c` ([Tracking issue](https://github.com/rust-lang/rust/issues/94501)) => Stable_1_64 => 1.64; @@ -241,6 +244,9 @@ rust_feature_def!( Stable_1_47 { => larger_arrays; } + Stable_1_59 { + => const_cstr; + } Stable_1_64 { => core_ffi_c; } diff --git a/bindgen/options/mod.rs b/bindgen/options/mod.rs index c60da71e81..83674e0e31 100644 --- a/bindgen/options/mod.rs +++ b/bindgen/options/mod.rs @@ -1416,6 +1416,23 @@ options! { }, as_args: "--generate-block", }, + /// Whether to generate strings as `CStr`. + generate_cstr: bool { + methods: { + /// Set whether string constants should be generated as `&CStr` instead of `&[u8]`. + /// + /// A minimum Rust target of 1.59 is required for this to have any effect as support + /// for `CStr::from_bytes_with_nul_unchecked` in `const` contexts is needed. + /// + /// This option is disabled by default but will become enabled by default in a future + /// release, so enabling this is recommended. + pub fn generate_cstr(mut self, doit: bool) -> Self { + self.options.generate_cstr = doit; + self + } + }, + as_args: "--generate-cstr", + }, /// Whether to emit `#[macro_use] extern crate block;` instead of `use block;` in the prologue /// of the files generated from apple block files. block_extern_crate: bool { From 4f9fcbfb596c53dcce3f32194f6218220ae2d6a8 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Thu, 13 Apr 2023 12:48:39 -0500 Subject: [PATCH 501/942] Do not wrap static variadic functions (#2499) Currently there is no way to generate a wrapper for a static variadic function while using the `--wrap-static-fns` feature. These changes modify `bindgen`'s behavior so such functions are skipped instead of generating invalid code for them. At the same time, a warning is emitted if the `--emit-diagnostics` feature is enabled. Co-authored-by: Urgau <3616612+Urgau@users.noreply.github.com> --- CHANGELOG.md | 2 + bindgen-tests/tests/headers/wrap-static-fns.h | 4 ++ bindgen/codegen/mod.rs | 69 ++++++++++++++++--- bindgen/codegen/serialize.rs | 2 + 4 files changed, 66 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 393d266e68..098882a161 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -175,6 +175,8 @@ instead of arrays (`[u8; SIZE]`) to match UTF-8 strings. * Wrappers for static functions that return `void` no longer contain a `return` statement and only call the static function instead. +* The `--wrap-static-fns` option no longer emits wrappers for static variadic + functions. ## Removed diff --git a/bindgen-tests/tests/headers/wrap-static-fns.h b/bindgen-tests/tests/headers/wrap-static-fns.h index 4a1862b050..85dfeac2af 100644 --- a/bindgen-tests/tests/headers/wrap-static-fns.h +++ b/bindgen-tests/tests/headers/wrap-static-fns.h @@ -44,3 +44,7 @@ static inline enum foo takes_enum(const enum foo f) { static inline void nevermore() { while (1) { } } + +static inline int variadic(int x, ...) { + return x; +} diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 81aa897e8e..16757dd811 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -4151,10 +4151,26 @@ impl CodeGenerator for Function { let is_internal = matches!(self.linkage(), Linkage::Internal); - if is_internal && !ctx.options().wrap_static_fns { - // We can't do anything with Internal functions if we are not wrapping them so just - // avoid generating anything for them. - return None; + let signature_item = ctx.resolve_item(self.signature()); + let signature = signature_item.kind().expect_type().canonical_type(ctx); + let signature = match *signature.kind() { + TypeKind::Function(ref sig) => sig, + _ => panic!("Signature kind is not a Function: {:?}", signature), + }; + + if is_internal { + if !ctx.options().wrap_static_fns { + // We cannot do anything with internal functions if we are not wrapping them so + // just avoid generating anything for them. + return None; + } + + if signature.is_variadic() { + // We cannot generate wrappers for variadic static functions so we avoid + // generating any code for them. + variadic_fn_diagnostic(self.name(), item.location(), ctx); + return None; + } } // Pure virtual methods have no actual symbol, so we can't generate @@ -4194,13 +4210,6 @@ impl CodeGenerator for Function { result.saw_function(seen_symbol_name); } - let signature_item = ctx.resolve_item(self.signature()); - let signature = signature_item.kind().expect_type().canonical_type(ctx); - let signature = match *signature.kind() { - TypeKind::Function(ref sig) => sig, - _ => panic!("Signature kind is not a Function: {:?}", signature), - }; - let args = utils::fnsig_arguments(ctx, signature); let ret = utils::fnsig_return_ty(ctx, signature); @@ -4408,6 +4417,44 @@ fn unsupported_abi_diagnostic( } } +fn variadic_fn_diagnostic( + fn_name: &str, + _location: Option<&crate::clang::SourceLocation>, + _ctx: &BindgenContext, +) { + warn!( + "Cannot generate wrapper for the static variadic function `{}`.", + fn_name, + ); + + #[cfg(feature = "experimental")] + if _ctx.options().emit_diagnostics { + use crate::diagnostics::{get_line, Diagnostic, Level, Slice}; + + let mut diag = Diagnostic::default(); + + diag.with_title(format!("Cannot generate wrapper for the static function `{}`.", fn_name), Level::Warn) + .add_annotation("The `--wrap-static-fns` feature does not support variadic functions.", Level::Note) + .add_annotation("No code will be generated for this function.", Level::Note); + + if let Some(loc) = _location { + let (file, line, col, _) = loc.location(); + + if let Some(filename) = file.name() { + if let Ok(Some(source)) = get_line(&filename, line) { + let mut slice = Slice::default(); + slice + .with_source(source) + .with_location(filename, line, col); + diag.add_slice(slice); + } + } + } + + diag.display() + } +} + fn objc_method_codegen( ctx: &BindgenContext, method: &ObjCMethod, diff --git a/bindgen/codegen/serialize.rs b/bindgen/codegen/serialize.rs index 0baa70a899..1136234e05 100644 --- a/bindgen/codegen/serialize.rs +++ b/bindgen/codegen/serialize.rs @@ -77,6 +77,8 @@ impl<'a> CSerialize<'a> for Function { _ => unreachable!(), }; + assert!(!signature.is_variadic()); + let name = self.name(); // Function argoments stored as `(name, type_id)` tuples. From 078fb77e82507c1b96f571a18700a03870c96fdd Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Thu, 13 Apr 2023 20:06:12 -0400 Subject: [PATCH 502/942] Escape spaces in the depfile output (#2503) Header file paths included from C/C++ files may include spaces in them, and if they do, the spaces need to be escaped in order to generate a proper depfile. Otherwise, the dep file ends up pointing to non-existant paths. For example: ../../third_party/depot_tools/win_toolchain/vs_files/27370823e7\Windows Kits\10\Include\10.0.22621.0\shared\winapifamily.h This path ends up being parsed as two files, neither of which exist: ../../third_party/depot_tools/win_toolchain/vs_files/27370823e7\Windows Kits\10\Include\10.0.22621.0\shared\winapifamily.h This leads to build failures with ninja when it's verifying that the build is complete: ``` $ ninja -C out rust_mojo_unittests -w dupbuild=err -n -d explain ninja explain: output ../../third_party/depot_tools/win_toolchain/vs_files/27370823e7\Windows doesn't exist ninja explain: output Kits/10/Include/10.0.22621.0/shared/winapifamily.h is dirty ``` ninja accepts spaces being escaped with backslash, so the path Windows Kits\10\Include\10.0.22621.0\shared\winapifamily.h can be valid if escaped as: Windows\ Kits\10\Include\10.0.22621.0\shared\winapifamily.h However this is less clear for humans as there is inconsistent use of backslashes, so we opt to escape backslashes as well, which ninja also accepts, and is standard for Windows paths. Windows\ Kits\\10\\Include\\10.0.22621.0\\shared\\winapifamily.h The same is also true for the target name, or `output_module` as its named in bindgen. Issue https://github.com/ninja-build/ninja/issues/168 demonstrates this case as well. So we also escape the target name if there is a space present. --- CHANGELOG.md | 4 ++++ bindgen/deps.rs | 47 ++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 098882a161..e271253915 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -177,6 +177,10 @@ statement and only call the static function instead. * The `--wrap-static-fns` option no longer emits wrappers for static variadic functions. +* Depfiles generated with `--depfile` or `Builder::depfile` will now be + properly generate module names and paths that include spaces by escaping + them. To make the escaping clear and consistent, backslashes are also + escaped. ## Removed diff --git a/bindgen/deps.rs b/bindgen/deps.rs index 987225b28e..2edeaa8886 100644 --- a/bindgen/deps.rs +++ b/bindgen/deps.rs @@ -9,12 +9,53 @@ pub(crate) struct DepfileSpec { impl DepfileSpec { pub fn write(&self, deps: &BTreeSet) -> std::io::Result<()> { - let mut buf = format!("{}:", self.output_module); + std::fs::write(&self.depfile_path, &self.to_string(deps)) + } + + fn to_string(&self, deps: &BTreeSet) -> String { + // Transforms a string by escaping spaces and backslashes. + let escape = |s: &str| s.replace('\\', "\\\\").replace(' ', "\\ "); + let mut buf = format!("{}:", escape(&self.output_module)); for file in deps { - buf = format!("{} {}", buf, file); + buf = format!("{} {}", buf, escape(file)); } + buf + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn escaping_depfile() { + let spec = DepfileSpec { + output_module: "Mod Name".to_owned(), + depfile_path: PathBuf::new(), + }; - std::fs::write(&self.depfile_path, &buf) + let deps: BTreeSet = vec![ + r"/absolute/path".to_owned(), + r"C:\win\absolute\path".to_owned(), + r"../relative/path".to_owned(), + r"..\win\relative\path".to_owned(), + r"../path/with spaces/in/it".to_owned(), + r"..\win\path\with spaces\in\it".to_owned(), + r"path\with/mixed\separators".to_owned(), + ] + .into_iter() + .collect(); + assert_eq!( + spec.to_string(&deps), + "Mod\\ Name: \ + ../path/with\\ spaces/in/it \ + ../relative/path \ + ..\\\\win\\\\path\\\\with\\ spaces\\\\in\\\\it \ + ..\\\\win\\\\relative\\\\path \ + /absolute/path \ + C:\\\\win\\\\absolute\\\\path \ + path\\\\with/mixed\\\\separators" + ); } } From 24d4be62a5817526f5fc5ad6fa02f5d596b9e084 Mon Sep 17 00:00:00 2001 From: Artem Vorotnikov Date: Mon, 17 Apr 2023 22:46:13 +0400 Subject: [PATCH 503/942] Fix Formatter::Prettyplease (#2505) The `Formatter::Prettyplease` variant was unavailable because it was kept under a feature that no longer existed. --- CHANGELOG.md | 2 ++ bindgen/lib.rs | 5 ----- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e271253915..754338a0b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -186,6 +186,8 @@ ## Fixed +* Prettyplease is available as a `Formatter` variant now. + ## Security # 0.65.1 diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 03d6d736c3..a52aa1e3a5 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -171,7 +171,6 @@ pub enum Formatter { None, /// Use `rustfmt` to format the bindings. Rustfmt, - #[cfg(feature = "prettyplease")] /// Use `prettyplease` to format the bindings. Prettyplease, } @@ -189,7 +188,6 @@ impl FromStr for Formatter { match s { "none" => Ok(Self::None), "rustfmt" => Ok(Self::Rustfmt), - #[cfg(feature = "prettyplease")] "prettyplease" => Ok(Self::Prettyplease), _ => Err(format!("`{}` is not a valid formatter", s)), } @@ -201,7 +199,6 @@ impl std::fmt::Display for Formatter { let s = match self { Self::None => "none", Self::Rustfmt => "rustfmt", - #[cfg(feature = "prettyplease")] Self::Prettyplease => "prettyplease", }; @@ -966,8 +963,6 @@ impl Bindings { match self.options.formatter { Formatter::None => return Ok(tokens.to_string()), - - #[cfg(feature = "prettyplease")] Formatter::Prettyplease => { return Ok(prettyplease::unparse(&syn::parse_quote!(#tokens))); } From e6a9d70f3750bac717265b2cccbd7f538075688d Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Mon, 17 Apr 2023 15:15:23 -0500 Subject: [PATCH 504/942] Add workflow to check features (#2506) Add a new workflow that checks which features are being used in `#[cfg]` attributes or `cfg!` macros and errors if one of the features does not exists. This should avoid any future issues like #2505 where a feature was removed and I forgot to remove the `#[cfg]` attributes in the Rust code. --- .github/workflows/bindgen.yml | 17 +++++++++++++++++ CONTRIBUTING.md | 2 +- appveyor.yml | 8 ++++---- bindgen-cli/Cargo.toml | 7 +++++++ bindgen-cli/main.rs | 4 ++-- bindgen-integration/Cargo.toml | 6 +++--- bindgen-tests/Cargo.toml | 6 +++--- bindgen-tests/tests/stylo_sanity.rs | 9 ++++++--- bindgen-tests/tests/tests.rs | 6 +++--- bindgen/Cargo.toml | 14 ++++++++------ bindgen/extra_assertions.rs | 14 +++++++------- bindgen/ir/analysis/template_params.rs | 2 +- bindgen/ir/context.rs | 8 ++++---- bindgen/ir/item.rs | 6 +++--- ci/test.bat | 4 ++-- ci/test.sh | 2 +- 16 files changed, 72 insertions(+), 43 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 59ff7c005d..525984f203 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -214,6 +214,23 @@ jobs: BINDGEN_NO_DEFAULT_FEATURES: ${{matrix.no_default_features}} run: ./ci/test.sh + check-cfg: + runs-on: ubuntu-latest + env: + RUSTFLAGS: -D warnings + steps: + - uses: actions/checkout@v3 + + - name: Install nightly + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly + override: true + + - name: Check cfg + run: cargo check -Z unstable-options -Z check-cfg=features + test-book: runs-on: ubuntu-latest steps: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4c3398d15a..33690d9a46 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -222,7 +222,7 @@ have. If for some reason it can't, you can force a specific `libclang` version to check the bindings against with a cargo feature: ``` -$ cargo test --features testing_only_libclang_$VERSION +$ cargo test --features __testing_only_libclang_$VERSION ``` Where `$VERSION` is one of: diff --git a/appveyor.yml b/appveyor.yml index 741c59fda4..973b4cdf07 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -4,16 +4,16 @@ environment: matrix: - TARGET: gnu LLVM_VERSION: 5.0.0-1 - BINDGEN_FEATURES: testing_only_libclang_5 + BINDGEN_FEATURES: __testing_only_libclang_5 - TARGET: gnu LLVM_VERSION: 9.0.0-1 - BINDGEN_FEATURES: testing_only_libclang_9 + BINDGEN_FEATURES: __testing_only_libclang_9 - TARGET: msvc LLVM_VERSION: 5.0.0 - BINDGEN_FEATURES: testing_only_libclang_5 + BINDGEN_FEATURES: __testing_only_libclang_5 - TARGET: msvc LLVM_VERSION: 9.0.0 - BINDGEN_FEATURES: testing_only_libclang_9 + BINDGEN_FEATURES: __testing_only_libclang_9 configuration: - stable diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index 731f1bee1a..c6e510e9b7 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -33,3 +33,10 @@ static = ["bindgen/static"] runtime = ["bindgen/runtime"] # Dynamically discover a `rustfmt` binary using the `which` crate which-rustfmt = ["bindgen/which-rustfmt"] + +## The following features are for intearnal use and they shouldn't be used if +## you're not hacking on bindgen +# Features used for CI testing +__testing_only_extra_assertions = ["bindgen/__testing_only_extra_assertions"] +__testing_only_libclang_9 = ["bindgen/__testing_only_libclang_9"] +__testing_only_libclang_5 = ["bindgen/__testing_only_libclang_5"] diff --git a/bindgen-cli/main.rs b/bindgen-cli/main.rs index a3b3612694..a3407232de 100644 --- a/bindgen-cli/main.rs +++ b/bindgen-cli/main.rs @@ -13,9 +13,9 @@ use crate::options::builder_from_flags; #[cfg(feature = "logging")] fn clang_version_check() { let version = bindgen::clang_version(); - let expected_version = if cfg!(feature = "testing_only_libclang_9") { + let expected_version = if cfg!(feature = "__testing_only_libclang_9") { Some((9, 0)) - } else if cfg!(feature = "testing_only_libclang_5") { + } else if cfg!(feature = "__testing_only_libclang_5") { Some((5, 0)) } else { None diff --git a/bindgen-integration/Cargo.toml b/bindgen-integration/Cargo.toml index ac1b03eeaa..6c9508ab93 100644 --- a/bindgen-integration/Cargo.toml +++ b/bindgen-integration/Cargo.toml @@ -14,6 +14,6 @@ cc = "1.0" static = ["bindgen/static"] runtime = ["bindgen/runtime"] -testing_only_extra_assertions = ["bindgen/testing_only_extra_assertions"] -testing_only_libclang_9 = ["bindgen/testing_only_libclang_9"] -testing_only_libclang_5 = ["bindgen/testing_only_libclang_5"] +__testing_only_extra_assertions = ["bindgen/__testing_only_extra_assertions"] +__testing_only_libclang_9 = ["bindgen/__testing_only_libclang_9"] +__testing_only_libclang_5 = ["bindgen/__testing_only_libclang_5"] diff --git a/bindgen-tests/Cargo.toml b/bindgen-tests/Cargo.toml index 3e529fb3d8..9018e8e3fe 100644 --- a/bindgen-tests/Cargo.toml +++ b/bindgen-tests/Cargo.toml @@ -17,6 +17,6 @@ static = ["bindgen/static"] runtime = ["bindgen/runtime"] which-rustfmt = ["bindgen/which-rustfmt"] -testing_only_extra_assertions = ["bindgen/testing_only_extra_assertions"] -testing_only_libclang_9 = ["bindgen/testing_only_libclang_9"] -testing_only_libclang_5 = ["bindgen/testing_only_libclang_5"] +__testing_only_extra_assertions = ["bindgen/__testing_only_extra_assertions"] +__testing_only_libclang_9 = ["bindgen/__testing_only_libclang_9"] +__testing_only_libclang_5 = ["bindgen/__testing_only_libclang_5"] diff --git a/bindgen-tests/tests/stylo_sanity.rs b/bindgen-tests/tests/stylo_sanity.rs index 52b96355e0..e1ad86b04d 100755 --- a/bindgen-tests/tests/stylo_sanity.rs +++ b/bindgen-tests/tests/stylo_sanity.rs @@ -14,10 +14,13 @@ extern crate bindgen; /// how long bindings generation takes for Stylo. Stylo bindings generation /// takes too long to be a proper `#[bench]`. #[test] -#[cfg(not(any(debug_assertions, feature = "testing_only_extra_assertions",)))] +#[cfg(not(any( + debug_assertions, + feature = "__testing_only_extra_assertions", +)))] #[cfg(any( - feature = "testing_only_libclang_5", - feature = "testing_only_libclang_9" + feature = "__testing_only_libclang_5", + feature = "__testing_only_libclang_9" ))] fn sanity_check_can_generate_stylo_bindings() { use std::time::Instant; diff --git a/bindgen-tests/tests/tests.rs b/bindgen-tests/tests/tests.rs index 7a03952196..e1c35faa41 100644 --- a/bindgen-tests/tests/tests.rs +++ b/bindgen-tests/tests/tests.rs @@ -194,9 +194,9 @@ fn compare_generated_header( { let mut expectation = expectation.clone(); - if cfg!(feature = "testing_only_libclang_9") { + if cfg!(feature = "__testing_only_libclang_9") { expectation.push("libclang-9"); - } else if cfg!(feature = "testing_only_libclang_5") { + } else if cfg!(feature = "__testing_only_libclang_5") { expectation.push("libclang-5"); } else { match clang_version().parsed { @@ -237,7 +237,7 @@ fn compare_generated_header( BufReader::new(f).read_to_string(&mut expected)?; } None => panic!( - "missing test expectation file and/or 'testing_only_libclang_$VERSION' \ + "missing test expectation file and/or '__testing_only_libclang_$VERSION' \ feature for header '{}'; looking for expectation file at '{:?}'", header.display(), looked_at, diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index 838524fd44..0db33d0ec1 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -49,11 +49,13 @@ static = ["clang-sys/static"] runtime = ["clang-sys/runtime"] # Dynamically discover a `rustfmt` binary using the `which` crate which-rustfmt = ["which"] -__cli = [] experimental = ["annotate-snippets"] -# These features only exist for CI testing -- don't use them if you're not hacking -# on bindgen! -testing_only_extra_assertions = [] -testing_only_libclang_9 = [] -testing_only_libclang_5 = [] +## The following features are for intearnal use and they shouldn't be used if +## you're not hacking on bindgen +# Features used by `bindgen-cli` +__cli = [] +# Features used for CI testing +__testing_only_extra_assertions = [] +__testing_only_libclang_9 = [] +__testing_only_libclang_5 = [] diff --git a/bindgen/extra_assertions.rs b/bindgen/extra_assertions.rs index 0888bf3969..19e47636d2 100644 --- a/bindgen/extra_assertions.rs +++ b/bindgen/extra_assertions.rs @@ -1,33 +1,33 @@ //! Macros for defining extra assertions that should only be checked in testing -//! and/or CI when the `testing_only_extra_assertions` feature is enabled. +//! and/or CI when the `__testing_only_extra_assertions` feature is enabled. /// Simple macro that forwards to assert! when using -/// testing_only_extra_assertions. +/// __testing_only_extra_assertions. #[macro_export] macro_rules! extra_assert { ( $cond:expr ) => { - if cfg!(feature = "testing_only_extra_assertions") { + if cfg!(feature = "__testing_only_extra_assertions") { assert!($cond); } }; ( $cond:expr , $( $arg:tt )+ ) => { - if cfg!(feature = "testing_only_extra_assertions") { + if cfg!(feature = "__testing_only_extra_assertions") { assert!($cond, $( $arg )* ) } }; } /// Simple macro that forwards to assert_eq! when using -/// testing_only_extra_assertions. +/// __testing_only_extra_assertions. #[macro_export] macro_rules! extra_assert_eq { ( $lhs:expr , $rhs:expr ) => { - if cfg!(feature = "testing_only_extra_assertions") { + if cfg!(feature = "__testing_only_extra_assertions") { assert_eq!($lhs, $rhs); } }; ( $lhs:expr , $rhs:expr , $( $arg:tt )+ ) => { - if cfg!(feature = "testing_only_extra_assertions") { + if cfg!(feature = "__testing_only_extra_assertions") { assert!($lhs, $rhs, $( $arg )* ); } }; diff --git a/bindgen/ir/analysis/template_params.rs b/bindgen/ir/analysis/template_params.rs index 3e6cd5e100..e4261cf675 100644 --- a/bindgen/ir/analysis/template_params.rs +++ b/bindgen/ir/analysis/template_params.rs @@ -459,7 +459,7 @@ impl<'ctx> MonotoneFramework for UsedTemplateParameters<'ctx> { } } - if cfg!(feature = "testing_only_extra_assertions") { + if cfg!(feature = "__testing_only_extra_assertions") { // Invariant: The `used` map has an entry for every allowlisted // item, as well as all explicitly blocklisted items that are // reachable from allowlisted items. diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index a5c14a8f06..ee07625430 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -1193,11 +1193,11 @@ If you encounter an error missing from this list, please file an issue or a PR!" Ok((ret, self.options)) } - /// When the `testing_only_extra_assertions` feature is enabled, this + /// When the `__testing_only_extra_assertions` feature is enabled, this /// function walks the IR graph and asserts that we do not have any edges /// referencing an ItemId for which we do not have an associated IR item. fn assert_no_dangling_references(&self) { - if cfg!(feature = "testing_only_extra_assertions") { + if cfg!(feature = "__testing_only_extra_assertions") { for _ in self.assert_no_dangling_item_traversal() { // The iterator's next method does the asserting for us. } @@ -1218,11 +1218,11 @@ If you encounter an error missing from this list, please file an issue or a PR!" ) } - /// When the `testing_only_extra_assertions` feature is enabled, walk over + /// When the `__testing_only_extra_assertions` feature is enabled, walk over /// every item and ensure that it is in the children set of one of its /// module ancestors. fn assert_every_item_in_a_module(&self) { - if cfg!(feature = "testing_only_extra_assertions") { + if cfg!(feature = "__testing_only_extra_assertions") { assert!(self.in_codegen_phase()); assert!(self.current_module == self.root_module); diff --git a/bindgen/ir/item.rs b/bindgen/ir/item.rs index a50d267a5c..f4dce45d83 100644 --- a/bindgen/ir/item.rs +++ b/bindgen/ir/item.rs @@ -98,13 +98,13 @@ pub(crate) trait ItemAncestors { fn ancestors<'a>(&self, ctx: &'a BindgenContext) -> ItemAncestorsIter<'a>; } -#[cfg(testing_only_extra_assertions)] +#[cfg(__testing_only_extra_assertions)] type DebugOnlyItemSet = ItemSet; -#[cfg(not(testing_only_extra_assertions))] +#[cfg(not(__testing_only_extra_assertions))] struct DebugOnlyItemSet; -#[cfg(not(testing_only_extra_assertions))] +#[cfg(not(__testing_only_extra_assertions))] impl DebugOnlyItemSet { fn new() -> Self { DebugOnlyItemSet diff --git a/ci/test.bat b/ci/test.bat index 507537c08e..d4a1c4a08a 100644 --- a/ci/test.bat +++ b/ci/test.bat @@ -29,10 +29,10 @@ findstr /r /c:"#include *<.*>" tests\headers\* >nul 2>&1 && ( cargo test --features "%BINDGEN_FEATURES%" || exit /b 1 call .\ci\assert-no-diff.bat -cargo test --features "%BINDGEN_FEATURES% testing_only_extra_assertions" || exit /b 1 +cargo test --features "%BINDGEN_FEATURES% __testing_only_extra_assertions" || exit /b 1 call .\ci\assert-no-diff.bat -cargo test --release --features "%BINDGEN_FEATURES% testing_only_extra_assertions" || exit /b 1 +cargo test --release --features "%BINDGEN_FEATURES% __testing_only_extra_assertions" || exit /b 1 call .\ci\assert-no-diff.bat ::Now test the expectations' size and alignment tests. diff --git a/ci/test.sh b/ci/test.sh index 835d606ed1..33d0f7c690 100755 --- a/ci/test.sh +++ b/ci/test.sh @@ -108,7 +108,7 @@ get_cargo_args() { features+="runtime" fi if [ "$BINDGEN_FEATURE_EXTRA_ASSERTS" == "1" ]; then - features+=" testing_only_extra_assertions" + features+=" __testing_only_extra_assertions" fi if [ ! -z "$features" ]; then args+=" --features $(echo $features | tr ' ' ',')" From ae87b33364c4107dd9ec78a4f2e0af7bf81ce731 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Mon, 17 Apr 2023 16:32:29 -0500 Subject: [PATCH 505/942] Add command to generate shell completions (#2507) Add the `--generate-shell-completions=shell` command which generates completions for the given shell, emits the completion script to `stdout` and exits. The supported shells are: `bash`, `elvish`, `fish`, `powershell` and `zsh`. We depend on the `clap_complete` crate so we can only support the shells they support. For example, to generate `bash` completions you can run: ```bash $ bindgen --generate-shell-completions=bash > /usr/share/bash-completion/completions/bindgen.bash ``` --- CHANGELOG.md | 2 ++ Cargo.lock | 11 +++++++++++ bindgen-cli/Cargo.toml | 1 + bindgen-cli/options.rs | 18 +++++++++++++++++- bindgen-tests/Cargo.toml | 1 + 5 files changed, 32 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 754338a0b0..a916fb6861 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -168,6 +168,8 @@ * Added the `--generate-cstr` CLI flag to generate string constants as `&CStr` instead of `&[u8]`. (Requires Rust 1.59 or higher.) +* Added the `--generate-shell-completions` CLI flag to generate completions for + different shells. ## Changed diff --git a/Cargo.lock b/Cargo.lock index 7d8903d6ae..f128b18cb6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -49,6 +49,7 @@ version = "0.65.1" dependencies = [ "bindgen", "clap", + "clap_complete", "env_logger 0.10.0", "log", "shlex", @@ -68,6 +69,7 @@ version = "0.1.0" dependencies = [ "bindgen", "clap", + "clap_complete", "diff", "shlex", "tempfile", @@ -132,6 +134,15 @@ dependencies = [ "termcolor", ] +[[package]] +name = "clap_complete" +version = "4.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01c22dcfb410883764b29953103d9ef7bb8fe21b3fa1158bc99986c2067294bd" +dependencies = [ + "clap", +] + [[package]] name = "clap_derive" version = "4.1.0" diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index c6e510e9b7..fbd2a5b134 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -23,6 +23,7 @@ name = "bindgen" bindgen = { path = "../bindgen", version = "=0.65.1", features = ["__cli", "experimental"] } shlex = "1" clap = { version = "4", features = ["derive"] } +clap_complete = "4" env_logger = { version = "0.10.0", optional = true } log = { version = "0.4", optional = true } diff --git a/bindgen-cli/options.rs b/bindgen-cli/options.rs index 8e292f958a..5ddf9ad306 100644 --- a/bindgen-cli/options.rs +++ b/bindgen-cli/options.rs @@ -4,10 +4,11 @@ use bindgen::{ FieldVisibilityKind, Formatter, MacroTypeVariation, NonCopyUnionStyle, RegexSet, RustTarget, DEFAULT_ANON_FIELDS_PREFIX, RUST_TARGET_STRINGS, }; -use clap::Parser; +use clap::{CommandFactory, Parser}; use std::fs::File; use std::io::{self, Error, ErrorKind}; use std::path::PathBuf; +use std::process::exit; fn rust_target_help() -> String { format!( @@ -376,6 +377,9 @@ struct BindgenCommand { /// Whether to emit diagnostics or not. #[arg(long, requires = "experimental")] emit_diagnostics: bool, + /// Generates completions for the specified SHELL, sends them to `stdout` and exits. + #[arg(long, value_name = "SHELL")] + generate_shell_completions: Option, /// Enables experimental features. #[arg(long)] experimental: bool, @@ -504,11 +508,23 @@ where wrap_static_fns_suffix, default_visibility, emit_diagnostics, + generate_shell_completions, experimental: _, version, clang_args, } = command; + if let Some(shell) = generate_shell_completions { + clap_complete::generate( + shell, + &mut BindgenCommand::command(), + "bindgen", + &mut std::io::stdout(), + ); + + exit(0); + } + if version { println!( "bindgen {}", diff --git a/bindgen-tests/Cargo.toml b/bindgen-tests/Cargo.toml index 9018e8e3fe..ed542946a5 100644 --- a/bindgen-tests/Cargo.toml +++ b/bindgen-tests/Cargo.toml @@ -9,6 +9,7 @@ bindgen = { path = "../bindgen", features = ["__cli", "experimental"] } diff = "0.1" shlex = "1" clap = { version = "4", features = ["derive"] } +clap_complete = "4" tempfile = "3" [features] From ea16c3a069219483314ee515b242924b99692c45 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Fri, 21 Apr 2023 20:57:09 -0500 Subject: [PATCH 506/942] Avoid generating docs for dependencies in CI (#2510) Some dependencies might cause `rustdoc` to emit errors or crash as shown [here](https://github.com/rust-lang/rust-bindgen/actions/runs/4769225847/jobs/8479397251). This PR avoids generating documentation for dependencies on CI. --- .github/workflows/bindgen.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 525984f203..9513e1f25a 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -86,7 +86,7 @@ jobs: override: true - name: Generate documentation - run: cargo doc --document-private-items + run: cargo doc --document-private-items --no-deps -p bindgen quickchecking: runs-on: ubuntu-latest From 4563da94ecef84ceb48e695d2712b243841a43b0 Mon Sep 17 00:00:00 2001 From: Niki4tap Date: Sat, 22 Apr 2023 05:05:52 +0300 Subject: [PATCH 507/942] fix typos (#2509) --- bindgen-cli/Cargo.toml | 2 +- bindgen/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index fbd2a5b134..523a01b767 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -35,7 +35,7 @@ runtime = ["bindgen/runtime"] # Dynamically discover a `rustfmt` binary using the `which` crate which-rustfmt = ["bindgen/which-rustfmt"] -## The following features are for intearnal use and they shouldn't be used if +## The following features are for internal use and they shouldn't be used if ## you're not hacking on bindgen # Features used for CI testing __testing_only_extra_assertions = ["bindgen/__testing_only_extra_assertions"] diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index 0db33d0ec1..1647570f2c 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -51,7 +51,7 @@ runtime = ["clang-sys/runtime"] which-rustfmt = ["which"] experimental = ["annotate-snippets"] -## The following features are for intearnal use and they shouldn't be used if +## The following features are for internal use and they shouldn't be used if ## you're not hacking on bindgen # Features used by `bindgen-cli` __cli = [] From 39b6612070ff9cf9ef790485e7da6627e3c4ce7f Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Fri, 21 Apr 2023 21:16:34 -0500 Subject: [PATCH 508/942] Generate docs for `bindgen-cli` (#2511) --- .github/workflows/bindgen.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 9513e1f25a..8ab00dcef2 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -85,9 +85,12 @@ jobs: toolchain: stable override: true - - name: Generate documentation + - name: Generate documentation for `bindgen` run: cargo doc --document-private-items --no-deps -p bindgen + - name: Generate documentation for `bindgen-cli` + run: cargo doc --document-private-items --no-deps -p bindgen-cli + quickchecking: runs-on: ubuntu-latest steps: From 3ea5d17d44ba14e43ceb65ab628575f4075d779e Mon Sep 17 00:00:00 2001 From: Andrew Walbran Date: Thu, 27 Apr 2023 21:38:04 +0100 Subject: [PATCH 509/942] Update the bitflags to 2.2.1. (#2512) --- CHANGELOG.md | 1 + Cargo.lock | 14 ++++++++++---- bindgen/Cargo.toml | 2 +- bindgen/codegen/mod.rs | 1 + bindgen/lib.rs | 1 + 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a916fb6861..a611ea4080 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -183,6 +183,7 @@ properly generate module names and paths that include spaces by escaping them. To make the escaping clear and consistent, backslashes are also escaped. +* Updated `bitflags` dependency to 2.2.1. This changes the API of `CodegenConfig`. ## Removed diff --git a/Cargo.lock b/Cargo.lock index f128b18cb6..2bbb278dbf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -26,7 +26,7 @@ name = "bindgen" version = "0.65.1" dependencies = [ "annotate-snippets", - "bitflags", + "bitflags 2.2.1", "cexpr", "clang-sys", "lazy_static", @@ -81,6 +81,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24a6904aef64d73cf10ab17ebace7befb918b82164785cb89907993be7f83813" + [[package]] name = "block" version = "0.1.6" @@ -125,7 +131,7 @@ version = "4.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f13b9c79b5d1dd500d20ef541215a6423c75829ef43117e1b4d17fd8af0b5d76" dependencies = [ - "bitflags", + "bitflags 1.3.2", "clap_derive", "clap_lex", "is-terminal", @@ -497,7 +503,7 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] @@ -529,7 +535,7 @@ version = "0.36.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4fdebc4b395b7fbb9ab11e462e20ed9051e7b16e42d24042c776eca0ac81b03" dependencies = [ - "bitflags", + "bitflags 1.3.2", "errno", "io-lifetimes", "libc", diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index 1647570f2c..fd20049e78 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -25,7 +25,7 @@ name = "bindgen" path = "lib.rs" [dependencies] -bitflags = "1.0.3" +bitflags = "2.2.1" cexpr = "0.6" clang-sys = { version = "1", features = ["clang_6_0"] } lazycell = "1" diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 16757dd811..47f23193cb 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -126,6 +126,7 @@ fn root_import( } bitflags! { + #[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] struct DerivableTraits: u16 { const DEBUG = 1 << 0; const DEFAULT = 1 << 1; diff --git a/bindgen/lib.rs b/bindgen/lib.rs index a52aa1e3a5..e4b71b0496 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -109,6 +109,7 @@ fn args_are_cpp(clang_args: &[String]) -> bool { bitflags! { /// A type used to indicate which kind of items we have to generate. + #[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct CodegenConfig: u32 { /// Whether to generate functions. const FUNCTIONS = 1 << 0; From b0604b422801c6639c21dd4bdfe6a02a25341cc4 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Fri, 28 Apr 2023 15:02:48 -0500 Subject: [PATCH 510/942] Document the `bindgen-cli` MSRV (#2516) --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 67f227c4fa..620ad0ab94 100644 --- a/README.md +++ b/README.md @@ -39,11 +39,15 @@ extern "C" { ## MSRV -The minimum supported Rust version is **1.60.0**. +The `bindgen` minimum supported Rust version is **1.60.0**. + +The `bindgen-cli` minimum supported Rust version is **1.64.0**. No MSRV bump policy has been established yet, so MSRV may increase in any release. -The MSRV is the minimum Rust version that can be used to *compile* `bindgen`. However, `bindgen` can generate bindings that are compatible with Rust versions below the current MSRV. +The MSRV is the minimum Rust version that can be used to *compile* each crate. However, `bindgen` and `bindgen-cli` can generate bindings that are compatible with Rust versions below the current MSRV. + +Most of the time, the `bindgen-cli` crate will have a more recent MSRV than `bindgen` as crates such as `clap` require it. ## API Reference From 948d0d489a327e81157ef36dda840f04ed9a1a18 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Mon, 1 May 2023 00:22:51 -0500 Subject: [PATCH 511/942] Include adding a new GH release to new version steps (#2519) --- CONTRIBUTING.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 33690d9a46..429962ae00 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -573,3 +573,6 @@ $ pushd bindgen && cargo publish && popd $ pushd bindgen-cli && cargo publish && popd $ git push --tags upstream # To publish the tag ``` +### Create a new release on Github + +See [Releasing projects on Github](https://docs.github.com/en/repositories/releasing-projects-on-github) From a710e508c3e3fdff75884e3de2c43977cb9de558 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Tue, 30 May 2023 12:20:12 -0500 Subject: [PATCH 512/942] Use `prettyplease` to format expectations (#2536) This PR replaces `rustfmt` by `prettyplease` as the used formatter for the expectation tests. This was done because we currently rely on the nightly version of `rustfmt` which recently broke our test suite by changing how code in macros is formatted. The `prettyplease` crate does not have that issue because we are using a specific version in the Cargo manifest. --- Cargo.lock | 2 + bindgen-tests/Cargo.toml | 2 + bindgen-tests/tests/expectations/rustfmt.toml | 2 + .../expectations/tests/16-byte-alignment.rs | 247 +-- .../tests/16-byte-alignment_1_0.rs | 252 +-- .../expectations/tests/381-decltype-alias.rs | 8 +- .../tests/expectations/tests/abi-override.rs | 8 +- .../tests/expectations/tests/accessors.rs | 286 +-- .../expectations/tests/alias_comments.rs | 8 +- .../expectations/tests/allowlist-file.rs | 86 +- .../tests/allowlist-namespaces-basic.rs | 16 +- .../tests/allowlist-namespaces.rs | 42 +- .../expectations/tests/allowlist_basic.rs | 8 +- .../tests/expectations/tests/allowlist_fix.rs | 9 +- .../expectations/tests/allowlist_vars.rs | 8 +- .../expectations/tests/allowlist_warnings.rs | 7 +- .../allowlisted-item-references-no-hash.rs | 41 +- ...llowlisted-item-references-no-partialeq.rs | 41 +- .../allowlisted_item_references_no_copy.rs | 41 +- .../expectations/tests/annotation_hide.rs | 39 +- .../expectations/tests/anon-fields-prefix.rs | 112 +- .../tests/expectations/tests/anon_enum.rs | 26 +- .../expectations/tests/anon_enum_allowlist.rs | 8 +- .../expectations/tests/anon_enum_trait.rs | 32 +- .../tests/anon_struct_in_union.rs | 68 +- .../tests/anon_struct_in_union_1_0.rs | 68 +- .../tests/expectations/tests/anon_union.rs | 37 +- .../expectations/tests/anon_union_1_0.rs | 40 +- .../tests/anonymous-template-types.rs | 8 +- .../tests/expectations/tests/arg_keyword.rs | 8 +- .../tests/array-of-zero-sized-types.rs | 46 +- .../tests/attribute_warn_unused_result.rs | 27 +- ...rn_unused_result_no_attribute_detection.rs | 27 +- .../attribute_warn_unused_result_pre_1_27.rs | 27 +- .../bad-namespace-parenthood-inheritance.rs | 8 +- .../expectations/tests/base-to-derived.rs | 18 +- .../tests/bindgen-union-inside-namespace.rs | 52 +- .../tests/bitfield-32bit-overflow.rs | 588 +++--- .../expectations/tests/bitfield-enum-basic.rs | 18 +- .../tests/bitfield-enum-repr-c.rs | 8 +- .../tests/bitfield-enum-repr-transparent.rs | 8 +- .../expectations/tests/bitfield-large.rs | 94 +- .../expectations/tests/bitfield-linux-32.rs | 72 +- .../tests/bitfield-method-same-name.rs | 46 +- .../expectations/tests/bitfield_align.rs | 576 +++--- .../expectations/tests/bitfield_align_2.rs | 61 +- .../tests/bitfield_large_overflow.rs | 18 +- .../tests/bitfield_method_mangling.rs | 57 +- .../tests/bitfield_pragma_packed.rs | 112 +- .../expectations/tests/block_return_type.rs | 8 +- .../tests/blocklist-and-impl-debug.rs | 29 +- .../expectations/tests/blocklist-file.rs | 71 +- .../expectations/tests/blocklist-function.rs | 17 +- .../expectations/tests/blocklist-item.rs | 8 +- .../expectations/tests/blocklist-methods.rs | 17 +- .../expectations/tests/blocks-signature.rs | 48 +- .../tests/expectations/tests/blocks.rs | 39 +- .../tests/expectations/tests/bug-1529681.rs | 18 +- .../expectations/tests/builtin-template.rs | 8 +- .../expectations/tests/c-empty-layout.rs | 17 +- .../tests/c-unwind-abi-override-nightly.rs | 8 +- .../tests/expectations/tests/c_naming.rs | 64 +- .../expectations/tests/call-conv-typedef.rs | 8 +- .../expectations/tests/canonical-types.rs | 115 +- .../canonical_path_without_namespacing.rs | 17 +- .../tests/expectations/tests/char.rs | 64 +- .../tests/expectations/tests/class.rs | 247 +-- .../tests/expectations/tests/class_1_0.rs | 247 +-- .../tests/expectations/tests/class_nested.rs | 102 +- .../expectations/tests/class_no_members.rs | 50 +- .../tests/expectations/tests/class_static.rs | 21 +- .../expectations/tests/class_static_const.rs | 16 +- .../tests/expectations/tests/class_use_as.rs | 57 +- .../expectations/tests/class_with_dtor.rs | 53 +- .../tests/class_with_inner_struct.rs | 334 +--- .../tests/class_with_inner_struct_1_0.rs | 322 +--- .../expectations/tests/class_with_typedef.rs | 57 +- .../expectations/tests/comment-indent.rs | 108 +- .../tests/expectations/tests/complex.rs | 101 +- .../expectations/tests/complex_global.rs | 8 +- .../expectations/tests/const-const-mut-ptr.rs | 23 +- .../tests/expectations/tests/const_array.rs | 8 +- .../expectations/tests/const_array_fn_arg.rs | 8 +- .../expectations/tests/const_enum_unnamed.rs | 17 +- .../tests/const_multidim_array_fn_arg.rs | 8 +- .../tests/expectations/tests/const_ptr.rs | 8 +- .../expectations/tests/const_resolved_ty.rs | 8 +- .../tests/expectations/tests/const_tparam.rs | 8 +- .../tests/constant-non-specialized-tp.rs | 8 +- .../tests/constified-enum-module-overflow.rs | 28 +- .../expectations/tests/constify-all-enums.rs | 34 +- .../tests/expectations/tests/constify-enum.rs | 15 +- .../tests/constify-module-enums-basic.rs | 34 +- .../tests/constify-module-enums-namespace.rs | 35 +- .../constify-module-enums-shadow-name.rs | 30 +- .../constify-module-enums-simple-alias.rs | 84 +- ...onstify-module-enums-simple-nonamespace.rs | 26 +- .../tests/constify-module-enums-types.rs | 166 +- .../expectations/tests/constructor-tp.rs | 17 +- .../tests/expectations/tests/constructors.rs | 28 +- .../expectations/tests/constructors_1_33.rs | 28 +- .../tests/contains-vs-inherits-zero-sized.rs | 82 +- .../tests/convert-cpp-comment-to-rust.rs | 8 +- .../expectations/tests/convert-floats.rs | 65 +- .../tests/expectations/tests/core_ffi_c.rs | 8 +- .../expectations/tests/cpp-empty-layout.rs | 17 +- .../tests/expectations/tests/crtp.rs | 49 +- .../expectations/tests/ctypes-prefix-path.rs | 29 +- .../tests/expectations/tests/dash_language.rs | 8 +- .../tests/decl_extern_int_twice.rs | 8 +- .../expectations/tests/decl_ptr_to_array.rs | 8 +- .../default-enum-style-constified-module.rs | 8 +- .../default-macro-constant-type-signed.rs | 8 +- .../default-macro-constant-type-unsigned.rs | 8 +- .../tests/default-macro-constant-type.rs | 8 +- .../tests/default-template-parameter.rs | 26 +- .../tests/default_visibility_crate.rs | 68 +- .../tests/default_visibility_private.rs | 68 +- ...bility_private_respects_cxx_access_spec.rs | 68 +- .../expectations/tests/deleted-function.rs | 32 +- .../tests/derive-bitfield-method-same-name.rs | 84 +- .../tests/expectations/tests/derive-clone.rs | 32 +- .../expectations/tests/derive-clone_1_0.rs | 36 +- .../expectations/tests/derive-custom-cli.rs | 87 +- .../tests/expectations/tests/derive-custom.rs | 12 +- .../tests/derive-debug-bitfield-core.rs | 88 +- .../tests/derive-debug-bitfield.rs | 96 +- .../tests/derive-debug-function-pointer.rs | 64 +- .../tests/derive-debug-generic.rs | 8 +- .../tests/derive-debug-mangle-name.rs | 78 +- ...ive-debug-opaque-template-instantiation.rs | 31 +- .../expectations/tests/derive-debug-opaque.rs | 41 +- .../tests/derive-default-and-blocklist.rs | 35 +- .../tests/expectations/tests/derive-fn-ptr.rs | 56 +- .../tests/derive-hash-and-blocklist.rs | 31 +- .../tests/derive-hash-blocklisting.rs | 59 +- ...rive-hash-struct-with-anon-struct-float.rs | 56 +- .../derive-hash-struct-with-float-array.rs | 23 +- ...erive-hash-struct-with-incomplete-array.rs | 57 +- .../tests/derive-hash-struct-with-pointer.rs | 100 +- .../tests/derive-hash-template-def-float.rs | 8 +- .../tests/derive-hash-template-inst-float.rs | 78 +- .../tests/derive-partialeq-and-blocklist.rs | 33 +- .../tests/derive-partialeq-anonfield.rs | 26 +- .../tests/derive-partialeq-base.rs | 37 +- .../tests/derive-partialeq-bitfield.rs | 85 +- .../tests/derive-partialeq-core.rs | 33 +- .../tests/derive-partialeq-pointer.rs | 55 +- .../tests/derive-partialeq-union.rs | 39 +- .../tests/derive-partialeq-union_1_0.rs | 39 +- .../expectations/tests/disable-namespacing.rs | 8 +- .../tests/disable-nested-struct-naming.rs | 184 +- .../tests/disable-untagged-union.rs | 26 +- .../tests/divide-by-zero-in-struct-layout.rs | 23 +- .../expectations/tests/do-not-derive-copy.rs | 33 +- .../tests/expectations/tests/doggo-or-null.rs | 55 +- .../tests/dupe-enum-variant-in-namespace.rs | 8 +- .../tests/duplicated-definition-count.rs | 18 +- .../duplicated-namespaces-definitions.rs | 73 +- .../tests/duplicated-namespaces.rs | 8 +- .../tests/duplicated_constants_in_ns.rs | 8 +- .../tests/dynamic_loading_attributes.rs | 28 +- .../tests/dynamic_loading_required.rs | 17 +- .../tests/dynamic_loading_simple.rs | 21 +- .../tests/dynamic_loading_template.rs | 23 +- .../tests/dynamic_loading_with_allowlist.rs | 35 +- .../tests/dynamic_loading_with_blocklist.rs | 50 +- .../tests/dynamic_loading_with_class.rs | 41 +- .../tests/expectations/tests/elaborated.rs | 8 +- .../tests/expectations/tests/empty-enum.rs | 8 +- .../tests/expectations/tests/empty-union.rs | 8 +- .../tests/empty_template_param_name.rs | 8 +- .../tests/enum-default-bitfield.rs | 30 +- .../expectations/tests/enum-default-consts.rs | 30 +- .../expectations/tests/enum-default-module.rs | 30 +- .../expectations/tests/enum-default-rust.rs | 30 +- .../expectations/tests/enum-doc-bitfield.rs | 16 +- .../tests/expectations/tests/enum-doc-mod.rs | 16 +- .../expectations/tests/enum-doc-rusty.rs | 16 +- .../tests/expectations/tests/enum-doc.rs | 16 +- .../expectations/tests/enum-no-debug-rust.rs | 30 +- .../expectations/tests/enum-translate-type.rs | 8 +- .../tests/expectations/tests/enum-typedef.rs | 8 +- .../expectations/tests/enum-undefault.rs | 8 +- .../tests/enum-variant-replaces.rs | 18 +- .../tests/expectations/tests/enum.rs | 30 +- .../tests/expectations/tests/enum_alias.rs | 8 +- .../tests/enum_and_vtable_mangling.rs | 22 +- .../tests/expectations/tests/enum_dupe.rs | 8 +- .../expectations/tests/enum_explicit_type.rs | 14 +- .../tests/enum_explicit_type_constants.rs | 8 +- .../expectations/tests/enum_in_template.rs | 8 +- .../tests/enum_in_template_with_typedef.rs | 8 +- .../tests/expectations/tests/enum_negative.rs | 8 +- .../tests/expectations/tests/enum_packed.rs | 8 +- .../tests/eval-value-dependent.rs | 8 +- .../tests/eval-variadic-template-parameter.rs | 8 +- .../expectations/tests/explicit-padding.rs | 94 +- .../expectations/tests/extern-const-struct.rs | 31 +- .../tests/expectations/tests/extern.rs | 8 +- .../tests/fit-macro-constant-types-signed.rs | 8 +- .../tests/fit-macro-constant-types.rs | 8 +- .../tests/expectations/tests/float128.rs | 7 +- .../tests/forward-declaration-autoptr.rs | 45 +- .../expectations/tests/forward-enum-decl.rs | 8 +- .../forward-inherit-struct-with-fields.rs | 8 +- .../tests/forward-inherit-struct.rs | 8 +- .../tests/forward_declared_complex_types.rs | 33 +- .../forward_declared_complex_types_1_0.rs | 33 +- .../tests/forward_declared_opaque.rs | 8 +- .../tests/forward_declared_struct.rs | 36 +- .../tests/expectations/tests/func_proto.rs | 8 +- .../tests/expectations/tests/func_ptr.rs | 8 +- .../expectations/tests/func_ptr_in_struct.rs | 28 +- .../tests/func_ptr_return_type.rs | 8 +- .../tests/func_return_must_use.rs | 28 +- .../expectations/tests/func_with_array_arg.rs | 8 +- .../tests/func_with_func_ptr_arg.rs | 18 +- .../tests/function-typedef-stdcall.rs | 8 +- .../tests/gen-constructors-neg.rs | 17 +- .../expectations/tests/gen-constructors.rs | 17 +- .../expectations/tests/gen-destructors-neg.rs | 23 +- .../expectations/tests/gen-destructors.rs | 23 +- .../expectations/tests/generate-inline.rs | 17 +- .../tests/expectations/tests/i128.rs | 46 +- .../expectations/tests/in_class_typedef.rs | 8 +- .../tests/incomplete-array-padding.rs | 43 +- .../expectations/tests/infinite-macro.rs | 8 +- ...from-template-instantiation-with-vtable.rs | 127 +- .../expectations/tests/inherit-namespaced.rs | 8 +- .../tests/inherit_multiple_interfaces.rs | 64 +- .../tests/expectations/tests/inherit_named.rs | 8 +- .../expectations/tests/inherit_typedef.rs | 26 +- .../expectations/tests/inline-function.rs | 7 +- .../expectations/tests/inline_namespace.rs | 31 +- .../tests/inline_namespace_allowlist.rs | 8 +- .../tests/inline_namespace_conservative.rs | 31 +- .../tests/inline_namespace_nested.rs | 8 +- .../tests/inline_namespace_no_ns_enabled.rs | 8 +- .../expectations/tests/inner-typedef-gh422.rs | 8 +- .../tests/expectations/tests/inner_const.rs | 23 +- .../expectations/tests/inner_template_self.rs | 42 +- .../tests/expectations/tests/int128_t.rs | 7 +- .../tests/issue-1025-unknown-enum-repr.rs | 8 +- .../tests/expectations/tests/issue-1034.rs | 26 +- .../tests/expectations/tests/issue-1040.rs | 8 +- .../issue-1076-unnamed-bitfield-alignment.rs | 26 +- .../tests/issue-1113-template-references.rs | 8 +- .../tests/issue-1118-using-forward-decl.rs | 79 +- .../tests/issue-1197-pure-virtual-stuff.rs | 17 +- .../issue-1198-alias-rust-bitfield-enum.rs | 8 +- ...1198-alias-rust-const-mod-bitfield-enum.rs | 8 +- .../issue-1198-alias-rust-const-mod-enum.rs | 8 +- .../tests/issue-1198-alias-rust-enum.rs | 8 +- .../tests/issue-1216-variadic-member.rs | 23 +- .../tests/issue-1238-fwd-no-copy.rs | 8 +- .../tests/expectations/tests/issue-1281.rs | 53 +- .../tests/expectations/tests/issue-1285.rs | 56 +- .../tests/expectations/tests/issue-1291.rs | 213 +-- .../issue-1350-attribute-overloadable.rs | 8 +- .../tests/issue-1375-prefixed-functions.rs | 8 +- .../tests/issue-1382-rust-primitive-types.rs | 106 +- .../tests/expectations/tests/issue-1435.rs | 10 +- .../tests/expectations/tests/issue-1443.rs | 80 +- .../tests/expectations/tests/issue-1454.rs | 32 +- .../tests/expectations/tests/issue-1464.rs | 7 +- .../tests/issue-1488-enum-new-type.rs | 8 +- .../expectations/tests/issue-1488-options.rs | 8 +- .../issue-1488-template-alias-new-type.rs | 8 +- .../tests/expectations/tests/issue-1498.rs | 124 +- .../tests/expectations/tests/issue-1514.rs | 8 +- .../tests/expectations/tests/issue-1554.rs | 8 +- .../issue-1599-opaque-typedef-to-enum.rs | 8 +- .../issue-1676-macro-namespace-prefix.rs | 7 +- .../tests/expectations/tests/issue-1947.rs | 233 ++- .../tests/issue-1977-larger-arrays.rs | 32 +- .../tests/expectations/tests/issue-1995.rs | 33 +- .../tests/expectations/tests/issue-2019.rs | 36 +- ...issue-2239-template-dependent-bit-width.rs | 8 +- .../tests/expectations/tests/issue-358.rs | 8 +- .../tests/expectations/tests/issue-372.rs | 59 +- .../tests/expectations/tests/issue-410.rs | 18 +- .../tests/expectations/tests/issue-446.rs | 8 +- .../tests/expectations/tests/issue-447.rs | 31 +- .../tests/expectations/tests/issue-493.rs | 14 +- .../tests/expectations/tests/issue-493_1_0.rs | 14 +- .../tests/expectations/tests/issue-511.rs | 8 +- .../tests/issue-537-repr-packed-n.rs | 130 +- .../tests/expectations/tests/issue-537.rs | 140 +- .../tests/issue-544-stylo-creduce-2.rs | 8 +- .../tests/issue-544-stylo-creduce.rs | 8 +- ...ate-params-causing-layout-test-failures.rs | 29 +- .../tests/issue-573-layout-test-failures.rs | 37 +- .../issue-574-assertion-failure-in-codegen.rs | 37 +- ...issue-584-stylo-template-analysis-panic.rs | 45 +- ...e-638-stylo-cannot-find-T-in-this-scope.rs | 8 +- .../tests/issue-639-typedef-anon-field.rs | 78 +- .../tests/issue-643-inner-struct.rs | 70 +- ...ue-645-cannot-find-type-T-in-this-scope.rs | 9 +- .../issue-648-derive-debug-with-padding.rs | 74 +- .../tests/issue-654-struct-fn-collision.rs | 8 +- .../issue-662-cannot-find-T-in-this-scope.rs | 8 +- .../expectations/tests/issue-662-part-2.rs | 9 +- .../tests/expectations/tests/issue-674-1.rs | 28 +- .../tests/expectations/tests/issue-674-2.rs | 55 +- .../tests/expectations/tests/issue-674-3.rs | 46 +- .../tests/issue-677-nested-ns-specifier.rs | 8 +- .../issue-691-template-parameter-virtual.rs | 30 +- .../tests/issue-710-must-use-type.rs | 8 +- .../tests/issue-739-pointer-wide-bitfield.rs | 94 +- .../tests/issue-801-opaque-sloppiness.rs | 30 +- ...07-opaque-types-methods-being-generated.rs | 74 +- .../tests/expectations/tests/issue-816.rs | 724 ++++--- ...ssue-820-unused-template-param-in-alias.rs | 8 +- ...26-generating-methods-when-asked-not-to.rs | 17 +- .../tests/expectations/tests/issue-833-1.rs | 9 +- .../tests/expectations/tests/issue-833-2.rs | 10 +- .../tests/expectations/tests/issue-833.rs | 9 +- .../tests/expectations/tests/issue-834.rs | 16 +- .../issue-848-replacement-system-include.rs | 18 +- .../tests/issue-888-enum-var-decl-jump.rs | 18 +- .../issue-944-derive-copy-and-blocklisting.rs | 32 +- .../tests/expectations/tests/issue-946.rs | 17 +- .../tests/expectations/tests/issue_311.rs | 24 +- .../tests/expectations/tests/issue_315.rs | 8 +- .../expectations/tests/jsval_layout_opaque.rs | 245 +-- .../tests/jsval_layout_opaque_1_0.rs | 245 +-- .../tests/expectations/tests/keywords.rs | 8 +- .../tests/expectations/tests/layout.rs | 13 +- .../tests/expectations/tests/layout_align.rs | 109 +- .../tests/expectations/tests/layout_arp.rs | 211 +-- .../tests/expectations/tests/layout_array.rs | 288 +-- .../tests/layout_array_too_long.rs | 236 +-- .../tests/layout_cmdline_token.rs | 208 +- .../expectations/tests/layout_eth_conf.rs | 1671 ++++++----------- .../expectations/tests/layout_eth_conf_1_0.rs | 1663 ++++++---------- .../expectations/tests/layout_kni_mbuf.rs | 214 +-- .../tests/layout_large_align_field.rs | 524 ++---- .../tests/expectations/tests/layout_mbuf.rs | 978 ++++------ .../expectations/tests/layout_mbuf_1_0.rs | 908 ++++----- .../tests/libclang-5/abi_variadic_function.rs | 8 +- .../expectations/tests/libclang-5/auto.rs | 17 +- .../tests/libclang-5/call-conv-field.rs | 43 +- .../tests/libclang-5/const_bool.rs | 16 +- .../tests/libclang-5/constant-evaluate.rs | 8 +- ...0600-cannot-apply-unary-negation-to-u32.rs | 8 +- .../issue-769-bad-instantiation-test.rs | 47 +- .../tests/libclang-5/mangling-win32.rs | 17 +- .../tests/libclang-5/objc_inheritance.rs | 19 +- .../tests/libclang-5/objc_template.rs | 27 +- .../partial-specialization-and-inheritance.rs | 18 +- .../type_alias_template_specialized.rs | 49 +- .../tests/libclang-9/abi_variadic_function.rs | 8 +- .../expectations/tests/libclang-9/auto.rs | 17 +- .../tests/libclang-9/call-conv-field.rs | 43 +- .../expectations/tests/libclang-9/class.rs | 442 ++--- .../tests/libclang-9/class_1_0.rs | 442 ++--- .../tests/libclang-9/const_bool.rs | 16 +- .../tests/libclang-9/constant-evaluate.rs | 8 +- ...erive-hash-struct-with-incomplete-array.rs | 111 +- ...0600-cannot-apply-unary-negation-to-u32.rs | 8 +- .../libclang-9/incomplete-array-padding.rs | 49 +- .../libclang-9/issue-643-inner-struct.rs | 113 +- .../issue-769-bad-instantiation-test.rs | 47 +- .../tests/libclang-9/layout_align.rs | 165 +- .../tests/libclang-9/mangling-win32.rs | 17 +- .../tests/libclang-9/objc_inheritance.rs | 19 +- .../tests/libclang-9/objc_template.rs | 27 +- .../partial-specialization-and-inheritance.rs | 18 +- .../type_alias_template_specialized.rs | 49 +- .../tests/libclang-9/zero-sized-array.rs | 107 +- .../tests/expectations/tests/long_double.rs | 23 +- .../expectations/tests/macro-expr-basic.rs | 8 +- .../tests/macro-expr-uncommon-token.rs | 8 +- .../tests/expectations/tests/macro-redef.rs | 8 +- .../tests/expectations/tests/macro_const.rs | 8 +- .../expectations/tests/macro_const_1_0.rs | 8 +- .../tests/maddness-is-avoidable.rs | 8 +- .../tests/expectations/tests/mangling-ios.rs | 8 +- .../expectations/tests/mangling-linux32.rs | 17 +- .../expectations/tests/mangling-linux64.rs | 17 +- .../expectations/tests/mangling-macos.rs | 17 +- .../expectations/tests/mangling-win64.rs | 17 +- .../expectations/tests/merge-extern-blocks.rs | 57 +- .../expectations/tests/method-mangling.rs | 17 +- .../expectations/tests/module-allowlisted.rs | 18 +- .../tests/expectations/tests/msvc-no-usr.rs | 22 +- .../multiple-inherit-empty-correct-layout.rs | 35 +- .../tests/expectations/tests/mutable.rs | 100 +- .../tests/expectations/tests/namespace.rs | 36 +- .../tests/nested-template-typedef.rs | 8 +- .../tests/expectations/tests/nested.rs | 73 +- .../tests/expectations/tests/nested_vtable.rs | 43 +- .../tests/nested_within_namespace.rs | 86 +- .../tests/expectations/tests/newtype-enum.rs | 8 +- .../expectations/tests/newtype-global-enum.rs | 8 +- .../tests/expectations/tests/no-comments.rs | 23 +- .../expectations/tests/no-derive-debug.rs | 33 +- .../expectations/tests/no-derive-default.rs | 33 +- .../expectations/tests/no-hash-allowlisted.rs | 24 +- .../expectations/tests/no-hash-opaque.rs | 18 +- .../tests/no-partialeq-allowlisted.rs | 31 +- .../expectations/tests/no-partialeq-opaque.rs | 18 +- .../tests/no-recursive-allowlisting.rs | 24 +- .../tests/expectations/tests/no-std.rs | 29 +- .../tests/expectations/tests/no_copy.rs | 8 +- .../expectations/tests/no_copy_allowlisted.rs | 24 +- .../expectations/tests/no_copy_opaque.rs | 18 +- .../tests/expectations/tests/no_debug.rs | 8 +- .../tests/no_debug_allowlisted.rs | 31 +- .../tests/no_debug_bypass_impl_debug.rs | 8 +- .../expectations/tests/no_debug_opaque.rs | 18 +- .../tests/expectations/tests/no_default.rs | 8 +- .../tests/no_default_allowlisted.rs | 31 +- .../tests/no_default_bypass_derive_default.rs | 8 +- .../expectations/tests/no_default_opaque.rs | 18 +- .../expectations/tests/no_size_t_is_usize.rs | 28 +- .../expectations/tests/non-type-params.rs | 60 +- .../tests/expectations/tests/noreturn.rs | 8 +- .../expectations/tests/nsBaseHashtable.rs | 8 +- .../expectations/tests/nsStyleAutoArray.rs | 8 +- .../expectations/tests/objc_allowlist.rs | 14 +- .../expectations/tests/objc_blocklist.rs | 12 +- .../tests/expectations/tests/objc_category.rs | 14 +- .../tests/expectations/tests/objc_class.rs | 12 +- .../expectations/tests/objc_class_method.rs | 21 +- .../tests/expectations/tests/objc_escape.rs | 19 +- .../expectations/tests/objc_interface.rs | 10 +- .../expectations/tests/objc_interface_type.rs | 33 +- .../tests/expectations/tests/objc_method.rs | 30 +- .../expectations/tests/objc_method_clash.rs | 12 +- .../tests/objc_pointer_return_types.rs | 12 +- .../expectations/tests/objc_property_fnptr.rs | 17 +- .../tests/expectations/tests/objc_protocol.rs | 10 +- .../tests/objc_protocol_inheritance.rs | 13 +- .../expectations/tests/objc_sel_and_id.rs | 10 +- .../expectations/tests/only_bitfields.rs | 64 +- .../tests/opaque-template-inst-member-2.rs | 65 +- .../tests/opaque-template-inst-member.rs | 67 +- ...paque-template-instantiation-namespaced.rs | 133 +- .../tests/opaque-template-instantiation.rs | 70 +- .../expectations/tests/opaque-tracing.rs | 18 +- .../expectations/tests/opaque_in_struct.rs | 44 +- .../expectations/tests/opaque_pointer.rs | 64 +- .../expectations/tests/opaque_typedef.rs | 8 +- .../tests/expectations/tests/operator.rs | 8 +- .../tests/expectations/tests/ord-enum.rs | 8 +- .../expectations/tests/overflowed_enum.rs | 8 +- .../tests/expectations/tests/overloading.rs | 13 +- .../expectations/tests/packed-bitfield.rs | 77 +- .../tests/packed-n-with-padding.rs | 33 +- .../tests/expectations/tests/packed-vtable.rs | 18 +- .../tests/expectations/tests/parm-union.rs | 18 +- .../parsecb-anonymous-enum-variant-rename.rs | 8 +- .../tests/expectations/tests/pointer-attr.rs | 8 +- .../expectations/tests/prefix-link-name-c.rs | 8 +- .../tests/prefix-link-name-cpp.rs | 8 +- .../tests/prepend-enum-constified-variant.rs | 8 +- .../expectations/tests/prepend_enum_name.rs | 8 +- .../tests/expectations/tests/private.rs | 125 +- .../expectations/tests/private_fields.rs | 294 ++- .../tests/expectations/tests/public-dtor.rs | 28 +- .../tests/qualified-dependent-types.rs | 8 +- .../tests/expectations/tests/redeclaration.rs | 8 +- .../expectations/tests/ref_argument_array.rs | 17 +- .../tests/reparented_replacement.rs | 34 +- .../tests/replace_template_alias.rs | 12 +- .../tests/expectations/tests/replace_use.rs | 34 +- .../expectations/tests/replaces_double.rs | 8 +- .../tests/expectations/tests/repr-align.rs | 42 +- .../tests/resolved_type_def_function.rs | 8 +- ...ame_struct_name_in_different_namespaces.rs | 41 +- .../tests/sentry-defined-multiple-times.rs | 261 +-- .../tests/expectations/tests/short-enums.rs | 8 +- .../expectations/tests/size_t_template.rs | 22 +- .../tests/expectations/tests/sorted_items.rs | 152 +- .../expectations/tests/stdint_typedef.rs | 31 +- .../tests/expectations/tests/strings_array.rs | 8 +- .../tests/expectations/tests/strings_cstr.rs | 18 +- ...ruct_containing_forward_declared_struct.rs | 36 +- .../expectations/tests/struct_typedef.rs | 56 +- .../expectations/tests/struct_typedef_ns.rs | 59 +- .../tests/struct_with_anon_struct.rs | 56 +- .../tests/struct_with_anon_struct_array.rs | 92 +- .../tests/struct_with_anon_struct_pointer.rs | 56 +- .../tests/struct_with_anon_union.rs | 56 +- .../tests/struct_with_anon_union_1_0.rs | 56 +- .../tests/struct_with_anon_unnamed_struct.rs | 50 +- .../tests/struct_with_anon_unnamed_union.rs | 50 +- .../struct_with_anon_unnamed_union_1_0.rs | 50 +- .../tests/struct_with_bitfields.rs | 145 +- .../tests/struct_with_derive_debug.rs | 100 +- .../tests/struct_with_large_array.rs | 32 +- .../expectations/tests/struct_with_nesting.rs | 142 +- .../tests/struct_with_nesting_1_0.rs | 130 +- .../expectations/tests/struct_with_packing.rs | 25 +- .../expectations/tests/struct_with_struct.rs | 56 +- .../tests/struct_with_typedef_template_arg.rs | 11 +- .../expectations/tests/template-fun-ty.rs | 16 +- .../tests/template-param-usage-0.rs | 8 +- .../tests/template-param-usage-1.rs | 8 +- .../tests/template-param-usage-10.rs | 8 +- .../tests/template-param-usage-11.rs | 8 +- .../tests/template-param-usage-12.rs | 8 +- .../tests/template-param-usage-13.rs | 8 +- .../tests/template-param-usage-14.rs | 8 +- .../tests/template-param-usage-15.rs | 8 +- .../tests/template-param-usage-2.rs | 8 +- .../tests/template-param-usage-3.rs | 12 +- .../tests/template-param-usage-4.rs | 8 +- .../tests/template-param-usage-5.rs | 8 +- .../tests/template-param-usage-6.rs | 8 +- .../tests/template-param-usage-7.rs | 8 +- .../tests/template-param-usage-8.rs | 8 +- .../tests/template-param-usage-9.rs | 8 +- .../expectations/tests/template-with-var.rs | 8 +- .../tests/expectations/tests/template.rs | 678 ++----- .../expectations/tests/template_alias.rs | 8 +- .../tests/template_alias_basic.rs | 8 +- .../tests/template_alias_namespace.rs | 11 +- .../tests/expectations/tests/template_fun.rs | 7 +- ...mplate_instantiation_with_fn_local_type.rs | 47 +- .../tests/template_partial_specification.rs | 7 +- .../template_typedef_transitive_param.rs | 8 +- .../expectations/tests/template_typedefs.rs | 16 +- .../expectations/tests/templateref_opaque.rs | 8 +- .../tests/templatized-bitfield.rs | 14 +- .../tests/expectations/tests/timex.rs | 104 +- .../tests/expectations/tests/transform-op.rs | 40 +- ...type-referenced-by-allowlisted-function.rs | 31 +- .../expectations/tests/type_alias_empty.rs | 8 +- ..._alias_partial_template_especialization.rs | 8 +- .../tests/typedef-pointer-overlap.rs | 77 +- .../tests/typedefd-array-as-function-arg.rs | 8 +- .../tests/expectations/tests/typeref.rs | 101 +- .../tests/expectations/tests/typeref_1_0.rs | 101 +- .../tests/expectations/tests/underscore.rs | 24 +- .../tests/expectations/tests/union-align.rs | 38 +- .../tests/expectations/tests/union-in-ns.rs | 31 +- .../expectations/tests/union-in-ns_1_0.rs | 36 +- .../expectations/tests/union_bitfield.rs | 88 +- .../expectations/tests/union_bitfield_1_0.rs | 93 +- .../tests/expectations/tests/union_dtor.rs | 41 +- .../expectations/tests/union_dtor_1_0.rs | 41 +- .../tests/expectations/tests/union_fields.rs | 54 +- .../expectations/tests/union_fields_1_0.rs | 54 +- .../expectations/tests/union_template.rs | 8 +- .../expectations/tests/union_template_1_0.rs | 8 +- .../tests/union_with_anon_struct.rs | 56 +- .../tests/union_with_anon_struct_1_0.rs | 56 +- .../tests/union_with_anon_struct_bitfield.rs | 76 +- .../union_with_anon_struct_bitfield_1_0.rs | 76 +- .../tests/union_with_anon_union.rs | 56 +- .../tests/union_with_anon_union_1_0.rs | 56 +- .../tests/union_with_anon_unnamed_struct.rs | 86 +- .../union_with_anon_unnamed_struct_1_0.rs | 86 +- .../tests/union_with_anon_unnamed_union.rs | 56 +- .../union_with_anon_unnamed_union_1_0.rs | 56 +- .../tests/union_with_big_member.rs | 107 +- .../tests/union_with_big_member_1_0.rs | 107 +- .../expectations/tests/union_with_nesting.rs | 95 +- .../tests/union_with_nesting_1_0.rs | 95 +- .../tests/union_with_non_copy_member.rs | 135 +- .../tests/expectations/tests/unknown_attr.rs | 49 +- .../expectations/tests/unsorted-items.rs | 46 +- .../tests/expectations/tests/use-core.rs | 67 +- .../tests/expectations/tests/use-core_1_0.rs | 68 +- .../tests/expectations/tests/using.rs | 8 +- .../tests/expectations/tests/var-tracing.rs | 39 +- .../expectations/tests/variadic-method.rs | 17 +- .../tests/variadic_template_function.rs | 8 +- .../tests/expectations/tests/vector.rs | 30 +- .../tests/expectations/tests/virtual_dtor.rs | 18 +- .../expectations/tests/virtual_inheritance.rs | 8 +- .../expectations/tests/virtual_interface.rs | 48 +- .../expectations/tests/virtual_overloaded.rs | 32 +- .../tests/expectations/tests/void_typedef.rs | 8 +- .../tests/vtable_recursive_sig.rs | 27 +- .../tests/wasm-constructor-returns.rs | 17 +- .../expectations/tests/wasm-import-module.rs | 8 +- .../expectations/tests/weird_bitfields.rs | 326 ++-- .../expectations/tests/what_is_going_on.rs | 18 +- .../expectations/tests/win32-thiscall_1_0.rs | 17 +- .../tests/win32-thiscall_nightly.rs | 22 +- .../tests/win32-vectorcall-1_0.rs | 7 +- .../tests/win32-vectorcall-nightly.rs | 8 +- .../tests/with_array_pointers_arguments.rs | 8 +- .../tests/without_array_pointers_arguments.rs | 23 +- .../expectations/tests/wrap-static-fns.rs | 16 +- .../tests/wrap_unsafe_ops_anon_union_1_0.rs | 11 +- .../tests/wrap_unsafe_ops_class.rs | 8 +- .../wrap_unsafe_ops_dynamic_loading_simple.rs | 29 +- .../tests/wrap_unsafe_ops_objc_class.rs | 12 +- .../tests/zero-size-array-align.rs | 51 +- .../expectations/tests/zero-sized-array.rs | 79 +- bindgen-tests/tests/tests.rs | 167 +- ci/test.sh | 9 - 597 files changed, 10185 insertions(+), 22410 deletions(-) create mode 100644 bindgen-tests/tests/expectations/rustfmt.toml diff --git a/Cargo.lock b/Cargo.lock index 2bbb278dbf..923cb84818 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -71,7 +71,9 @@ dependencies = [ "clap", "clap_complete", "diff", + "prettyplease", "shlex", + "syn 2.0.7", "tempfile", ] diff --git a/bindgen-tests/Cargo.toml b/bindgen-tests/Cargo.toml index ed542946a5..ab53660a0a 100644 --- a/bindgen-tests/Cargo.toml +++ b/bindgen-tests/Cargo.toml @@ -10,6 +10,8 @@ diff = "0.1" shlex = "1" clap = { version = "4", features = ["derive"] } clap_complete = "4" +prettyplease = { version = "0.2.0" } +syn = { version = "2.0" } tempfile = "3" [features] diff --git a/bindgen-tests/tests/expectations/rustfmt.toml b/bindgen-tests/tests/expectations/rustfmt.toml new file mode 100644 index 0000000000..85a7173599 --- /dev/null +++ b/bindgen-tests/tests/expectations/rustfmt.toml @@ -0,0 +1,2 @@ +# disable rustfmt for this crate so running `cargo fmt` doesn't affect the expected binding files +disable_all_formatting = true diff --git a/bindgen-tests/tests/expectations/tests/16-byte-alignment.rs b/bindgen-tests/tests/expectations/tests/16-byte-alignment.rs index a60a63aa3b..b280f2f5be 100644 --- a/bindgen-tests/tests/expectations/tests/16-byte-alignment.rs +++ b/bindgen-tests/tests/expectations/tests/16-byte-alignment.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone)] pub struct rte_ipv4_tuple { @@ -26,73 +20,43 @@ pub struct rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit< - rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1, - > = ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!( - "Size of: ", - stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1) - ) + ::std::mem::size_of:: < rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 > (), 4usize, + concat!("Size of: ", stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!( - "Alignment of ", - stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1) - ) + ::std::mem::align_of:: < rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 > (), 2usize, + concat!("Alignment of ", stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dport) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(dport) - ) + unsafe { ::std::ptr::addr_of!((* ptr).dport) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", + stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1), "::", stringify!(dport)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).sport) as usize - ptr as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(sport) - ) + unsafe { ::std::ptr::addr_of!((* ptr).sport) as usize - ptr as usize }, 2usize, + concat!("Offset of field: ", + stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1), "::", stringify!(sport)) ); } #[test] fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, + ::std::mem::size_of:: < rte_ipv4_tuple__bindgen_ty_1 > (), 4usize, concat!("Size of: ", stringify!(rte_ipv4_tuple__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < rte_ipv4_tuple__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", stringify!(rte_ipv4_tuple__bindgen_ty_1)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).sctp_tag) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple__bindgen_ty_1), - "::", - stringify!(sctp_tag) - ) + unsafe { ::std::ptr::addr_of!((* ptr).sctp_tag) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_ipv4_tuple__bindgen_ty_1), + "::", stringify!(sctp_tag)) ); } impl Default for rte_ipv4_tuple__bindgen_ty_1 { @@ -106,42 +70,25 @@ impl Default for rte_ipv4_tuple__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_ipv4_tuple() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 12usize, - concat!("Size of: ", stringify!(rte_ipv4_tuple)) + ::std::mem::size_of:: < rte_ipv4_tuple > (), 12usize, concat!("Size of: ", + stringify!(rte_ipv4_tuple)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(rte_ipv4_tuple)) + ::std::mem::align_of:: < rte_ipv4_tuple > (), 4usize, concat!("Alignment of ", + stringify!(rte_ipv4_tuple)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).src_addr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple), - "::", - stringify!(src_addr) - ) + unsafe { ::std::ptr::addr_of!((* ptr).src_addr) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_ipv4_tuple), "::", + stringify!(src_addr)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).dst_addr) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple), - "::", - stringify!(dst_addr) - ) + unsafe { ::std::ptr::addr_of!((* ptr).dst_addr) as usize - ptr as usize }, + 4usize, concat!("Offset of field: ", stringify!(rte_ipv4_tuple), "::", + stringify!(dst_addr)) ); } impl Default for rte_ipv4_tuple { @@ -174,73 +121,43 @@ pub struct rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit< - rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1, - > = ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!( - "Size of: ", - stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1) - ) + ::std::mem::size_of:: < rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 > (), 4usize, + concat!("Size of: ", stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!( - "Alignment of ", - stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1) - ) + ::std::mem::align_of:: < rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 > (), 2usize, + concat!("Alignment of ", stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dport) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(dport) - ) + unsafe { ::std::ptr::addr_of!((* ptr).dport) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", + stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1), "::", stringify!(dport)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).sport) as usize - ptr as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(sport) - ) + unsafe { ::std::ptr::addr_of!((* ptr).sport) as usize - ptr as usize }, 2usize, + concat!("Offset of field: ", + stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1), "::", stringify!(sport)) ); } #[test] fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, + ::std::mem::size_of:: < rte_ipv6_tuple__bindgen_ty_1 > (), 4usize, concat!("Size of: ", stringify!(rte_ipv6_tuple__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < rte_ipv6_tuple__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", stringify!(rte_ipv6_tuple__bindgen_ty_1)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).sctp_tag) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple__bindgen_ty_1), - "::", - stringify!(sctp_tag) - ) + unsafe { ::std::ptr::addr_of!((* ptr).sctp_tag) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_ipv6_tuple__bindgen_ty_1), + "::", stringify!(sctp_tag)) ); } impl Default for rte_ipv6_tuple__bindgen_ty_1 { @@ -254,42 +171,25 @@ impl Default for rte_ipv6_tuple__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_ipv6_tuple() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 36usize, - concat!("Size of: ", stringify!(rte_ipv6_tuple)) + ::std::mem::size_of:: < rte_ipv6_tuple > (), 36usize, concat!("Size of: ", + stringify!(rte_ipv6_tuple)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(rte_ipv6_tuple)) + ::std::mem::align_of:: < rte_ipv6_tuple > (), 4usize, concat!("Alignment of ", + stringify!(rte_ipv6_tuple)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).src_addr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple), - "::", - stringify!(src_addr) - ) + unsafe { ::std::ptr::addr_of!((* ptr).src_addr) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_ipv6_tuple), "::", + stringify!(src_addr)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).dst_addr) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple), - "::", - stringify!(dst_addr) - ) + unsafe { ::std::ptr::addr_of!((* ptr).dst_addr) as usize - ptr as usize }, + 16usize, concat!("Offset of field: ", stringify!(rte_ipv6_tuple), "::", + stringify!(dst_addr)) ); } impl Default for rte_ipv6_tuple { @@ -310,38 +210,23 @@ pub union rte_thash_tuple { } #[test] fn bindgen_test_layout_rte_thash_tuple() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 48usize, - concat!("Size of: ", stringify!(rte_thash_tuple)) + ::std::mem::size_of:: < rte_thash_tuple > (), 48usize, concat!("Size of: ", + stringify!(rte_thash_tuple)) ); assert_eq!( - ::std::mem::align_of::(), - 16usize, - concat!("Alignment of ", stringify!(rte_thash_tuple)) + ::std::mem::align_of:: < rte_thash_tuple > (), 16usize, concat!("Alignment of ", + stringify!(rte_thash_tuple)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).v4) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_thash_tuple), - "::", - stringify!(v4) - ) + unsafe { ::std::ptr::addr_of!((* ptr).v4) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_thash_tuple), "::", stringify!(v4)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).v6) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_thash_tuple), - "::", - stringify!(v6) - ) + unsafe { ::std::ptr::addr_of!((* ptr).v6) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_thash_tuple), "::", stringify!(v6)) ); } impl Default for rte_thash_tuple { diff --git a/bindgen-tests/tests/expectations/tests/16-byte-alignment_1_0.rs b/bindgen-tests/tests/expectations/tests/16-byte-alignment_1_0.rs index 369e2c75ea..906d9a121b 100644 --- a/bindgen-tests/tests/expectations/tests/16-byte-alignment_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/16-byte-alignment_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -58,8 +52,9 @@ pub struct rte_ipv4_tuple { #[repr(C)] #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct rte_ipv4_tuple__bindgen_ty_1 { - pub __bindgen_anon_1: - __BindgenUnionField, + pub __bindgen_anon_1: __BindgenUnionField< + rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1, + >, pub sctp_tag: __BindgenUnionField, pub bindgen_union_field: u32, } @@ -71,45 +66,25 @@ pub struct rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit< - rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1, - > = ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!( - "Size of: ", - stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1) - ) + ::std::mem::size_of:: < rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 > (), 4usize, + concat!("Size of: ", stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!( - "Alignment of ", - stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1) - ) + ::std::mem::align_of:: < rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 > (), 2usize, + concat!("Alignment of ", stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dport) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(dport) - ) + unsafe { ::std::ptr::addr_of!((* ptr).dport) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", + stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1), "::", stringify!(dport)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).sport) as usize - ptr as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(sport) - ) + unsafe { ::std::ptr::addr_of!((* ptr).sport) as usize - ptr as usize }, 2usize, + concat!("Offset of field: ", + stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1), "::", stringify!(sport)) ); } impl Clone for rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 { @@ -119,30 +94,20 @@ impl Clone for rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, + ::std::mem::size_of:: < rte_ipv4_tuple__bindgen_ty_1 > (), 4usize, concat!("Size of: ", stringify!(rte_ipv4_tuple__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < rte_ipv4_tuple__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", stringify!(rte_ipv4_tuple__bindgen_ty_1)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).sctp_tag) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple__bindgen_ty_1), - "::", - stringify!(sctp_tag) - ) + unsafe { ::std::ptr::addr_of!((* ptr).sctp_tag) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_ipv4_tuple__bindgen_ty_1), + "::", stringify!(sctp_tag)) ); } impl Clone for rte_ipv4_tuple__bindgen_ty_1 { @@ -152,42 +117,25 @@ impl Clone for rte_ipv4_tuple__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_ipv4_tuple() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 12usize, - concat!("Size of: ", stringify!(rte_ipv4_tuple)) + ::std::mem::size_of:: < rte_ipv4_tuple > (), 12usize, concat!("Size of: ", + stringify!(rte_ipv4_tuple)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(rte_ipv4_tuple)) + ::std::mem::align_of:: < rte_ipv4_tuple > (), 4usize, concat!("Alignment of ", + stringify!(rte_ipv4_tuple)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).src_addr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple), - "::", - stringify!(src_addr) - ) + unsafe { ::std::ptr::addr_of!((* ptr).src_addr) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_ipv4_tuple), "::", + stringify!(src_addr)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).dst_addr) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple), - "::", - stringify!(dst_addr) - ) + unsafe { ::std::ptr::addr_of!((* ptr).dst_addr) as usize - ptr as usize }, + 4usize, concat!("Offset of field: ", stringify!(rte_ipv4_tuple), "::", + stringify!(dst_addr)) ); } impl Clone for rte_ipv4_tuple { @@ -205,8 +153,9 @@ pub struct rte_ipv6_tuple { #[repr(C)] #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct rte_ipv6_tuple__bindgen_ty_1 { - pub __bindgen_anon_1: - __BindgenUnionField, + pub __bindgen_anon_1: __BindgenUnionField< + rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1, + >, pub sctp_tag: __BindgenUnionField, pub bindgen_union_field: u32, } @@ -218,45 +167,25 @@ pub struct rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit< - rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1, - > = ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!( - "Size of: ", - stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1) - ) + ::std::mem::size_of:: < rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 > (), 4usize, + concat!("Size of: ", stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!( - "Alignment of ", - stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1) - ) + ::std::mem::align_of:: < rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 > (), 2usize, + concat!("Alignment of ", stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dport) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(dport) - ) + unsafe { ::std::ptr::addr_of!((* ptr).dport) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", + stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1), "::", stringify!(dport)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).sport) as usize - ptr as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(sport) - ) + unsafe { ::std::ptr::addr_of!((* ptr).sport) as usize - ptr as usize }, 2usize, + concat!("Offset of field: ", + stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1), "::", stringify!(sport)) ); } impl Clone for rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 { @@ -266,30 +195,20 @@ impl Clone for rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, + ::std::mem::size_of:: < rte_ipv6_tuple__bindgen_ty_1 > (), 4usize, concat!("Size of: ", stringify!(rte_ipv6_tuple__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < rte_ipv6_tuple__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", stringify!(rte_ipv6_tuple__bindgen_ty_1)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).sctp_tag) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple__bindgen_ty_1), - "::", - stringify!(sctp_tag) - ) + unsafe { ::std::ptr::addr_of!((* ptr).sctp_tag) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_ipv6_tuple__bindgen_ty_1), + "::", stringify!(sctp_tag)) ); } impl Clone for rte_ipv6_tuple__bindgen_ty_1 { @@ -299,42 +218,25 @@ impl Clone for rte_ipv6_tuple__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_ipv6_tuple() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 36usize, - concat!("Size of: ", stringify!(rte_ipv6_tuple)) + ::std::mem::size_of:: < rte_ipv6_tuple > (), 36usize, concat!("Size of: ", + stringify!(rte_ipv6_tuple)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(rte_ipv6_tuple)) + ::std::mem::align_of:: < rte_ipv6_tuple > (), 4usize, concat!("Alignment of ", + stringify!(rte_ipv6_tuple)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).src_addr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple), - "::", - stringify!(src_addr) - ) + unsafe { ::std::ptr::addr_of!((* ptr).src_addr) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_ipv6_tuple), "::", + stringify!(src_addr)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).dst_addr) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple), - "::", - stringify!(dst_addr) - ) + unsafe { ::std::ptr::addr_of!((* ptr).dst_addr) as usize - ptr as usize }, + 16usize, concat!("Offset of field: ", stringify!(rte_ipv6_tuple), "::", + stringify!(dst_addr)) ); } impl Clone for rte_ipv6_tuple { @@ -351,33 +253,19 @@ pub struct rte_thash_tuple { } #[test] fn bindgen_test_layout_rte_thash_tuple() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 48usize, - concat!("Size of: ", stringify!(rte_thash_tuple)) + ::std::mem::size_of:: < rte_thash_tuple > (), 48usize, concat!("Size of: ", + stringify!(rte_thash_tuple)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).v4) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_thash_tuple), - "::", - stringify!(v4) - ) + unsafe { ::std::ptr::addr_of!((* ptr).v4) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_thash_tuple), "::", stringify!(v4)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).v6) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_thash_tuple), - "::", - stringify!(v6) - ) + unsafe { ::std::ptr::addr_of!((* ptr).v6) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_thash_tuple), "::", stringify!(v6)) ); } impl Clone for rte_thash_tuple { diff --git a/bindgen-tests/tests/expectations/tests/381-decltype-alias.rs b/bindgen-tests/tests/expectations/tests/381-decltype-alias.rs index f4312a115a..ed893c21df 100644 --- a/bindgen-tests/tests/expectations/tests/381-decltype-alias.rs +++ b/bindgen-tests/tests/expectations/tests/381-decltype-alias.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct std_allocator_traits { diff --git a/bindgen-tests/tests/expectations/tests/abi-override.rs b/bindgen-tests/tests/expectations/tests/abi-override.rs index 8f370cd7b2..7853efbbe4 100644 --- a/bindgen-tests/tests/expectations/tests/abi-override.rs +++ b/bindgen-tests/tests/expectations/tests/abi-override.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "fastcall" { pub fn foo(); } diff --git a/bindgen-tests/tests/expectations/tests/accessors.rs b/bindgen-tests/tests/expectations/tests/accessors.rs index 05fdaf4ca5..f9a3e23aa8 100644 --- a/bindgen-tests/tests/expectations/tests/accessors.rs +++ b/bindgen-tests/tests/expectations/tests/accessors.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct SomeAccessors { @@ -18,68 +12,35 @@ pub struct SomeAccessors { } #[test] fn bindgen_test_layout_SomeAccessors() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(SomeAccessors)) + ::std::mem::size_of:: < SomeAccessors > (), 16usize, concat!("Size of: ", + stringify!(SomeAccessors)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(SomeAccessors)) + ::std::mem::align_of:: < SomeAccessors > (), 4usize, concat!("Alignment of ", + stringify!(SomeAccessors)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mNoAccessor) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(SomeAccessors), - "::", - stringify!(mNoAccessor) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mNoAccessor) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(SomeAccessors), "::", + stringify!(mNoAccessor)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mBothAccessors) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(SomeAccessors), - "::", - stringify!(mBothAccessors) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mBothAccessors) as usize - ptr as usize }, + 4usize, concat!("Offset of field: ", stringify!(SomeAccessors), "::", + stringify!(mBothAccessors)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mUnsafeAccessors) as usize - - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(SomeAccessors), - "::", - stringify!(mUnsafeAccessors) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mUnsafeAccessors) as usize - ptr as usize + }, 8usize, concat!("Offset of field: ", stringify!(SomeAccessors), "::", + stringify!(mUnsafeAccessors)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mImmutableAccessor) as usize - - ptr as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(SomeAccessors), - "::", - stringify!(mImmutableAccessor) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mImmutableAccessor) as usize - ptr as usize + }, 12usize, concat!("Offset of field: ", stringify!(SomeAccessors), "::", + stringify!(mImmutableAccessor)) ); } impl SomeAccessors { @@ -96,9 +57,7 @@ impl SomeAccessors { &self.mUnsafeAccessors } #[inline] - pub unsafe fn get_mUnsafeAccessors_mut( - &mut self, - ) -> &mut ::std::os::raw::c_int { + pub unsafe fn get_mUnsafeAccessors_mut(&mut self) -> &mut ::std::os::raw::c_int { &mut self.mUnsafeAccessors } #[inline] @@ -115,43 +74,25 @@ pub struct AllAccessors { } #[test] fn bindgen_test_layout_AllAccessors() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(AllAccessors)) + ::std::mem::size_of:: < AllAccessors > (), 8usize, concat!("Size of: ", + stringify!(AllAccessors)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(AllAccessors)) + ::std::mem::align_of:: < AllAccessors > (), 4usize, concat!("Alignment of ", + stringify!(AllAccessors)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mBothAccessors) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AllAccessors), - "::", - stringify!(mBothAccessors) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mBothAccessors) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(AllAccessors), "::", + stringify!(mBothAccessors)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mAlsoBothAccessors) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(AllAccessors), - "::", - stringify!(mAlsoBothAccessors) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mAlsoBothAccessors) as usize - ptr as usize + }, 4usize, concat!("Offset of field: ", stringify!(AllAccessors), "::", + stringify!(mAlsoBothAccessors)) ); } impl AllAccessors { @@ -181,43 +122,25 @@ pub struct AllUnsafeAccessors { } #[test] fn bindgen_test_layout_AllUnsafeAccessors() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(AllUnsafeAccessors)) + ::std::mem::size_of:: < AllUnsafeAccessors > (), 8usize, concat!("Size of: ", + stringify!(AllUnsafeAccessors)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < AllUnsafeAccessors > (), 4usize, concat!("Alignment of ", stringify!(AllUnsafeAccessors)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mBothAccessors) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AllUnsafeAccessors), - "::", - stringify!(mBothAccessors) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mBothAccessors) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(AllUnsafeAccessors), "::", + stringify!(mBothAccessors)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mAlsoBothAccessors) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(AllUnsafeAccessors), - "::", - stringify!(mAlsoBothAccessors) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mAlsoBothAccessors) as usize - ptr as usize + }, 4usize, concat!("Offset of field: ", stringify!(AllUnsafeAccessors), "::", + stringify!(mAlsoBothAccessors)) ); } impl AllUnsafeAccessors { @@ -226,9 +149,7 @@ impl AllUnsafeAccessors { &self.mBothAccessors } #[inline] - pub unsafe fn get_mBothAccessors_mut( - &mut self, - ) -> &mut ::std::os::raw::c_int { + pub unsafe fn get_mBothAccessors_mut(&mut self) -> &mut ::std::os::raw::c_int { &mut self.mBothAccessors } #[inline] @@ -236,9 +157,7 @@ impl AllUnsafeAccessors { &self.mAlsoBothAccessors } #[inline] - pub unsafe fn get_mAlsoBothAccessors_mut( - &mut self, - ) -> &mut ::std::os::raw::c_int { + pub unsafe fn get_mAlsoBothAccessors_mut(&mut self) -> &mut ::std::os::raw::c_int { &mut self.mAlsoBothAccessors } } @@ -256,68 +175,35 @@ pub struct ContradictAccessors { } #[test] fn bindgen_test_layout_ContradictAccessors() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(ContradictAccessors)) + ::std::mem::size_of:: < ContradictAccessors > (), 16usize, concat!("Size of: ", + stringify!(ContradictAccessors)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < ContradictAccessors > (), 4usize, concat!("Alignment of ", stringify!(ContradictAccessors)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mBothAccessors) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContradictAccessors), - "::", - stringify!(mBothAccessors) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mBothAccessors) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(ContradictAccessors), "::", + stringify!(mBothAccessors)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mNoAccessors) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(ContradictAccessors), - "::", - stringify!(mNoAccessors) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mNoAccessors) as usize - ptr as usize }, + 4usize, concat!("Offset of field: ", stringify!(ContradictAccessors), "::", + stringify!(mNoAccessors)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mUnsafeAccessors) as usize - - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(ContradictAccessors), - "::", - stringify!(mUnsafeAccessors) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mUnsafeAccessors) as usize - ptr as usize + }, 8usize, concat!("Offset of field: ", stringify!(ContradictAccessors), "::", + stringify!(mUnsafeAccessors)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mImmutableAccessor) as usize - - ptr as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(ContradictAccessors), - "::", - stringify!(mImmutableAccessor) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mImmutableAccessor) as usize - ptr as usize + }, 12usize, concat!("Offset of field: ", stringify!(ContradictAccessors), "::", + stringify!(mImmutableAccessor)) ); } impl ContradictAccessors { @@ -334,9 +220,7 @@ impl ContradictAccessors { &self.mUnsafeAccessors } #[inline] - pub unsafe fn get_mUnsafeAccessors_mut( - &mut self, - ) -> &mut ::std::os::raw::c_int { + pub unsafe fn get_mUnsafeAccessors_mut(&mut self) -> &mut ::std::os::raw::c_int { &mut self.mUnsafeAccessors } #[inline] @@ -352,30 +236,20 @@ pub struct Replaced { } #[test] fn bindgen_test_layout_Replaced() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Replaced)) + ::std::mem::size_of:: < Replaced > (), 4usize, concat!("Size of: ", + stringify!(Replaced)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Replaced)) + ::std::mem::align_of:: < Replaced > (), 4usize, concat!("Alignment of ", + stringify!(Replaced)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mAccessor) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Replaced), - "::", - stringify!(mAccessor) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mAccessor) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(Replaced), "::", + stringify!(mAccessor)) ); } impl Replaced { @@ -396,30 +270,20 @@ pub struct Wrapper { } #[test] fn bindgen_test_layout_Wrapper() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Wrapper)) + ::std::mem::size_of:: < Wrapper > (), 4usize, concat!("Size of: ", + stringify!(Wrapper)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Wrapper)) + ::std::mem::align_of:: < Wrapper > (), 4usize, concat!("Alignment of ", + stringify!(Wrapper)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mReplaced) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Wrapper), - "::", - stringify!(mReplaced) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mReplaced) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(Wrapper), "::", + stringify!(mReplaced)) ); } impl Wrapper { diff --git a/bindgen-tests/tests/expectations/tests/alias_comments.rs b/bindgen-tests/tests/expectations/tests/alias_comments.rs index c04e9bb8f1..31ff72b2c6 100644 --- a/bindgen-tests/tests/expectations/tests/alias_comments.rs +++ b/bindgen-tests/tests/expectations/tests/alias_comments.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] /// This is Struct #[repr(C)] #[derive(Debug, Default, Copy, Clone)] diff --git a/bindgen-tests/tests/expectations/tests/allowlist-file.rs b/bindgen-tests/tests/expectations/tests/allowlist-file.rs index 3b72fb75eb..1ee7a192ed 100644 --- a/bindgen-tests/tests/expectations/tests/allowlist-file.rs +++ b/bindgen-tests/tests/expectations/tests/allowlist-file.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const SOME_DEFUN: u32 = 123; extern "C" { #[link_name = "\u{1}_Z12SomeFunctionv"] @@ -21,22 +15,17 @@ pub struct someClass { #[test] fn bindgen_test_layout_someClass() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(someClass)) + ::std::mem::size_of:: < someClass > (), 1usize, concat!("Size of: ", + stringify!(someClass)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(someClass)) + ::std::mem::align_of:: < someClass > (), 1usize, concat!("Alignment of ", + stringify!(someClass)) ); } extern "C" { #[link_name = "\u{1}_ZN9someClass16somePublicMethodEi"] - pub fn someClass_somePublicMethod( - this: *mut someClass, - foo: ::std::os::raw::c_int, - ); + pub fn someClass_somePublicMethod(this: *mut someClass, foo: ::std::os::raw::c_int); } impl someClass { #[inline] @@ -58,28 +47,20 @@ pub struct StructWithAllowlistedDefinition { } #[test] fn bindgen_test_layout_StructWithAllowlistedDefinition() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, + ::std::mem::size_of:: < StructWithAllowlistedDefinition > (), 8usize, concat!("Size of: ", stringify!(StructWithAllowlistedDefinition)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, + ::std::mem::align_of:: < StructWithAllowlistedDefinition > (), 8usize, concat!("Alignment of ", stringify!(StructWithAllowlistedDefinition)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).other) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(StructWithAllowlistedDefinition), - "::", - stringify!(other) - ) + unsafe { ::std::ptr::addr_of!((* ptr).other) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(StructWithAllowlistedDefinition), "::", + stringify!(other)) ); } impl Default for StructWithAllowlistedDefinition { @@ -98,28 +79,20 @@ pub struct StructWithAllowlistedFwdDecl { } #[test] fn bindgen_test_layout_StructWithAllowlistedFwdDecl() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, + ::std::mem::size_of:: < StructWithAllowlistedFwdDecl > (), 4usize, concat!("Size of: ", stringify!(StructWithAllowlistedFwdDecl)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < StructWithAllowlistedFwdDecl > (), 4usize, concat!("Alignment of ", stringify!(StructWithAllowlistedFwdDecl)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(StructWithAllowlistedFwdDecl), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(StructWithAllowlistedFwdDecl), "::", + stringify!(b)) ); } #[repr(C)] @@ -129,27 +102,18 @@ pub struct AllowlistMe { } #[test] fn bindgen_test_layout_AllowlistMe() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(AllowlistMe)) + ::std::mem::size_of:: < AllowlistMe > (), 4usize, concat!("Size of: ", + stringify!(AllowlistMe)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(AllowlistMe)) + ::std::mem::align_of:: < AllowlistMe > (), 4usize, concat!("Alignment of ", + stringify!(AllowlistMe)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AllowlistMe), - "::", - stringify!(foo) - ) + unsafe { ::std::ptr::addr_of!((* ptr).foo) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(AllowlistMe), "::", stringify!(foo)) ); } diff --git a/bindgen-tests/tests/expectations/tests/allowlist-namespaces-basic.rs b/bindgen-tests/tests/expectations/tests/allowlist-namespaces-basic.rs index 36d03fefb5..38b15d0ef4 100644 --- a/bindgen-tests/tests/expectations/tests/allowlist-namespaces-basic.rs +++ b/bindgen-tests/tests/expectations/tests/allowlist-namespaces-basic.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![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 { #[allow(unused_imports)] @@ -23,13 +17,11 @@ pub mod root { #[test] fn bindgen_test_layout_Helper() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Helper)) + ::std::mem::size_of:: < Helper > (), 1usize, concat!("Size of: ", + stringify!(Helper)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < Helper > (), 1usize, concat!("Alignment of ", stringify!(Helper)) ); } diff --git a/bindgen-tests/tests/expectations/tests/allowlist-namespaces.rs b/bindgen-tests/tests/expectations/tests/allowlist-namespaces.rs index ee9fe4283c..0c760b7d1b 100644 --- a/bindgen-tests/tests/expectations/tests/allowlist-namespaces.rs +++ b/bindgen-tests/tests/expectations/tests/allowlist-namespaces.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![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 { #[allow(unused_imports)] @@ -23,13 +17,11 @@ pub mod root { #[test] fn bindgen_test_layout_Helper() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Helper)) + ::std::mem::size_of:: < Helper > (), 1usize, concat!("Size of: ", + stringify!(Helper)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < Helper > (), 1usize, concat!("Alignment of ", stringify!(Helper)) ); } @@ -41,30 +33,20 @@ pub mod root { } #[test] fn bindgen_test_layout_Test() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Test)) + ::std::mem::size_of:: < Test > (), 1usize, concat!("Size of: ", + stringify!(Test)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Test)) + ::std::mem::align_of:: < Test > (), 1usize, concat!("Alignment of ", + stringify!(Test)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).helper) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Test), - "::", - stringify!(helper) - ) + unsafe { ::std::ptr::addr_of!((* ptr).helper) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(Test), "::", + stringify!(helper)) ); } } diff --git a/bindgen-tests/tests/expectations/tests/allowlist_basic.rs b/bindgen-tests/tests/expectations/tests/allowlist_basic.rs index 5bfe42e870..902c6ba503 100644 --- a/bindgen-tests/tests/expectations/tests/allowlist_basic.rs +++ b/bindgen-tests/tests/expectations/tests/allowlist_basic.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct AllowlistMe { diff --git a/bindgen-tests/tests/expectations/tests/allowlist_fix.rs b/bindgen-tests/tests/expectations/tests/allowlist_fix.rs index 9cff795bd6..e3ce7bc100 100644 --- a/bindgen-tests/tests/expectations/tests/allowlist_fix.rs +++ b/bindgen-tests/tests/expectations/tests/allowlist_fix.rs @@ -1,12 +1,5 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub enum Test {} - extern "C" { pub fn Servo_Test(a: *mut Test); } diff --git a/bindgen-tests/tests/expectations/tests/allowlist_vars.rs b/bindgen-tests/tests/expectations/tests/allowlist_vars.rs index 590cbafcfa..342d904a73 100644 --- a/bindgen-tests/tests/expectations/tests/allowlist_vars.rs +++ b/bindgen-tests/tests/expectations/tests/allowlist_vars.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const NONE: u32 = 0; pub const FOO: u32 = 5; pub const FOOB: i32 = -2; diff --git a/bindgen-tests/tests/expectations/tests/allowlist_warnings.rs b/bindgen-tests/tests/expectations/tests/allowlist_warnings.rs index 131dbdf39f..fe64295a68 100644 --- a/bindgen-tests/tests/expectations/tests/allowlist_warnings.rs +++ b/bindgen-tests/tests/expectations/tests/allowlist_warnings.rs @@ -1,6 +1 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] \ No newline at end of file diff --git a/bindgen-tests/tests/expectations/tests/allowlisted-item-references-no-hash.rs b/bindgen-tests/tests/expectations/tests/allowlisted-item-references-no-hash.rs index 56dc5bce30..3c542aaefd 100644 --- a/bindgen-tests/tests/expectations/tests/allowlisted-item-references-no-hash.rs +++ b/bindgen-tests/tests/expectations/tests/allowlisted-item-references-no-hash.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct NoHash { @@ -13,14 +7,12 @@ pub struct NoHash { #[test] fn bindgen_test_layout_NoHash() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(NoHash)) + ::std::mem::size_of:: < NoHash > (), 1usize, concat!("Size of: ", + stringify!(NoHash)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(NoHash)) + ::std::mem::align_of:: < NoHash > (), 1usize, concat!("Alignment of ", + stringify!(NoHash)) ); } #[repr(C)] @@ -30,27 +22,18 @@ pub struct AllowlistMe { } #[test] fn bindgen_test_layout_AllowlistMe() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(AllowlistMe)) + ::std::mem::size_of:: < AllowlistMe > (), 1usize, concat!("Size of: ", + stringify!(AllowlistMe)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(AllowlistMe)) + ::std::mem::align_of:: < AllowlistMe > (), 1usize, concat!("Alignment of ", + stringify!(AllowlistMe)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AllowlistMe), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(AllowlistMe), "::", stringify!(a)) ); } diff --git a/bindgen-tests/tests/expectations/tests/allowlisted-item-references-no-partialeq.rs b/bindgen-tests/tests/expectations/tests/allowlisted-item-references-no-partialeq.rs index 36cdda0e8f..a582414c10 100644 --- a/bindgen-tests/tests/expectations/tests/allowlisted-item-references-no-partialeq.rs +++ b/bindgen-tests/tests/expectations/tests/allowlisted-item-references-no-partialeq.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct NoPartialEq { @@ -13,14 +7,12 @@ pub struct NoPartialEq { #[test] fn bindgen_test_layout_NoPartialEq() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(NoPartialEq)) + ::std::mem::size_of:: < NoPartialEq > (), 1usize, concat!("Size of: ", + stringify!(NoPartialEq)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(NoPartialEq)) + ::std::mem::align_of:: < NoPartialEq > (), 1usize, concat!("Alignment of ", + stringify!(NoPartialEq)) ); } #[repr(C)] @@ -30,27 +22,18 @@ pub struct AllowlistMe { } #[test] fn bindgen_test_layout_AllowlistMe() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(AllowlistMe)) + ::std::mem::size_of:: < AllowlistMe > (), 1usize, concat!("Size of: ", + stringify!(AllowlistMe)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(AllowlistMe)) + ::std::mem::align_of:: < AllowlistMe > (), 1usize, concat!("Alignment of ", + stringify!(AllowlistMe)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AllowlistMe), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(AllowlistMe), "::", stringify!(a)) ); } diff --git a/bindgen-tests/tests/expectations/tests/allowlisted_item_references_no_copy.rs b/bindgen-tests/tests/expectations/tests/allowlisted_item_references_no_copy.rs index 625e0ce6fd..e2b8ac9343 100644 --- a/bindgen-tests/tests/expectations/tests/allowlisted_item_references_no_copy.rs +++ b/bindgen-tests/tests/expectations/tests/allowlisted_item_references_no_copy.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default)] pub struct NoCopy { @@ -13,14 +7,12 @@ pub struct NoCopy { #[test] fn bindgen_test_layout_NoCopy() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(NoCopy)) + ::std::mem::size_of:: < NoCopy > (), 1usize, concat!("Size of: ", + stringify!(NoCopy)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(NoCopy)) + ::std::mem::align_of:: < NoCopy > (), 1usize, concat!("Alignment of ", + stringify!(NoCopy)) ); } #[repr(C)] @@ -30,27 +22,18 @@ pub struct AllowlistMe { } #[test] fn bindgen_test_layout_AllowlistMe() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(AllowlistMe)) + ::std::mem::size_of:: < AllowlistMe > (), 1usize, concat!("Size of: ", + stringify!(AllowlistMe)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(AllowlistMe)) + ::std::mem::align_of:: < AllowlistMe > (), 1usize, concat!("Alignment of ", + stringify!(AllowlistMe)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AllowlistMe), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(AllowlistMe), "::", stringify!(a)) ); } diff --git a/bindgen-tests/tests/expectations/tests/annotation_hide.rs b/bindgen-tests/tests/expectations/tests/annotation_hide.rs index a90c4261e8..ce74ca123c 100644 --- a/bindgen-tests/tests/expectations/tests/annotation_hide.rs +++ b/bindgen-tests/tests/expectations/tests/annotation_hide.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] ///

#[repr(C)] #[repr(align(4))] @@ -15,14 +9,10 @@ pub struct D { #[test] fn bindgen_test_layout_D() { assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(D)) + ::std::mem::size_of:: < D > (), 4usize, concat!("Size of: ", stringify!(D)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(D)) + ::std::mem::align_of:: < D > (), 4usize, concat!("Alignment of ", stringify!(D)) ); } #[repr(C)] @@ -32,27 +22,18 @@ pub struct NotAnnotated { } #[test] fn bindgen_test_layout_NotAnnotated() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(NotAnnotated)) + ::std::mem::size_of:: < NotAnnotated > (), 4usize, concat!("Size of: ", + stringify!(NotAnnotated)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(NotAnnotated)) + ::std::mem::align_of:: < NotAnnotated > (), 4usize, concat!("Alignment of ", + stringify!(NotAnnotated)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NotAnnotated), - "::", - stringify!(f) - ) + unsafe { ::std::ptr::addr_of!((* ptr).f) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(NotAnnotated), "::", stringify!(f)) ); } diff --git a/bindgen-tests/tests/expectations/tests/anon-fields-prefix.rs b/bindgen-tests/tests/expectations/tests/anon-fields-prefix.rs index d09cab4044..4cd2724dcf 100644 --- a/bindgen-tests/tests/expectations/tests/anon-fields-prefix.rs +++ b/bindgen-tests/tests/expectations/tests/anon-fields-prefix.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone)] pub union color { @@ -21,48 +15,30 @@ pub struct color__bindgen_ty_1 { } #[test] fn bindgen_test_layout_color__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 3usize, - concat!("Size of: ", stringify!(color__bindgen_ty_1)) + ::std::mem::size_of:: < color__bindgen_ty_1 > (), 3usize, concat!("Size of: ", + stringify!(color__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < color__bindgen_ty_1 > (), 1usize, concat!("Alignment of ", stringify!(color__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).r) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(color__bindgen_ty_1), - "::", - stringify!(r) - ) + unsafe { ::std::ptr::addr_of!((* ptr).r) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(color__bindgen_ty_1), "::", + stringify!(r)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).g) as usize - ptr as usize }, - 1usize, - concat!( - "Offset of field: ", - stringify!(color__bindgen_ty_1), - "::", - stringify!(g) - ) + unsafe { ::std::ptr::addr_of!((* ptr).g) as usize - ptr as usize }, 1usize, + concat!("Offset of field: ", stringify!(color__bindgen_ty_1), "::", + stringify!(g)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(color__bindgen_ty_1), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 2usize, + concat!("Offset of field: ", stringify!(color__bindgen_ty_1), "::", + stringify!(b)) ); } #[repr(C)] @@ -74,68 +50,46 @@ pub struct color__bindgen_ty_2 { } #[test] fn bindgen_test_layout_color__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 3usize, - concat!("Size of: ", stringify!(color__bindgen_ty_2)) + ::std::mem::size_of:: < color__bindgen_ty_2 > (), 3usize, concat!("Size of: ", + stringify!(color__bindgen_ty_2)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < color__bindgen_ty_2 > (), 1usize, concat!("Alignment of ", stringify!(color__bindgen_ty_2)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(color__bindgen_ty_2), - "::", - stringify!(y) - ) + unsafe { ::std::ptr::addr_of!((* ptr).y) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(color__bindgen_ty_2), "::", + stringify!(y)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize }, - 1usize, - concat!( - "Offset of field: ", - stringify!(color__bindgen_ty_2), - "::", - stringify!(u) - ) + unsafe { ::std::ptr::addr_of!((* ptr).u) as usize - ptr as usize }, 1usize, + concat!("Offset of field: ", stringify!(color__bindgen_ty_2), "::", + stringify!(u)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).v) as usize - ptr as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(color__bindgen_ty_2), - "::", - stringify!(v) - ) + unsafe { ::std::ptr::addr_of!((* ptr).v) as usize - ptr as usize }, 2usize, + concat!("Offset of field: ", stringify!(color__bindgen_ty_2), "::", + stringify!(v)) ); } #[test] fn bindgen_test_layout_color() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 3usize, - concat!("Size of: ", stringify!(color)) + ::std::mem::size_of:: < color > (), 3usize, concat!("Size of: ", + stringify!(color)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(color)) + ::std::mem::align_of:: < color > (), 1usize, concat!("Alignment of ", + stringify!(color)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).v3) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).v3) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(color), "::", stringify!(v3)) ); } diff --git a/bindgen-tests/tests/expectations/tests/anon_enum.rs b/bindgen-tests/tests/expectations/tests/anon_enum.rs index 429f94cedb..b8a18dd63e 100644 --- a/bindgen-tests/tests/expectations/tests/anon_enum.rs +++ b/bindgen-tests/tests/expectations/tests/anon_enum.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone, PartialEq)] pub struct Test { @@ -19,27 +13,21 @@ pub enum Test__bindgen_ty_1 { } #[test] fn bindgen_test_layout_Test() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Test)) + ::std::mem::size_of:: < Test > (), 8usize, concat!("Size of: ", stringify!(Test)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Test)) + ::std::mem::align_of:: < Test > (), 4usize, concat!("Alignment of ", + stringify!(Test)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).foo) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 4usize, + unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 4usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(bar)) ); } diff --git a/bindgen-tests/tests/expectations/tests/anon_enum_allowlist.rs b/bindgen-tests/tests/expectations/tests/anon_enum_allowlist.rs index f0c06c5634..4b172d7aeb 100644 --- a/bindgen-tests/tests/expectations/tests/anon_enum_allowlist.rs +++ b/bindgen-tests/tests/expectations/tests/anon_enum_allowlist.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const NODE_FLAG_FOO: _bindgen_ty_1 = _bindgen_ty_1::NODE_FLAG_FOO; pub const NODE_FLAG_BAR: _bindgen_ty_1 = _bindgen_ty_1::NODE_FLAG_BAR; #[repr(u32)] diff --git a/bindgen-tests/tests/expectations/tests/anon_enum_trait.rs b/bindgen-tests/tests/expectations/tests/anon_enum_trait.rs index 9d6b8f574a..06fc3faba9 100644 --- a/bindgen-tests/tests/expectations/tests/anon_enum_trait.rs +++ b/bindgen-tests/tests/expectations/tests/anon_enum_trait.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct DataType { @@ -14,16 +8,11 @@ pub type DataType_value_type<_Tp> = _Tp; pub type DataType_work_type<_Tp> = DataType_value_type<_Tp>; pub type DataType_channel_type<_Tp> = DataType_value_type<_Tp>; pub type DataType_vec_type<_Tp> = DataType_value_type<_Tp>; -pub const DataType_generic_type: DataType__bindgen_ty_1 = - DataType__bindgen_ty_1::generic_type; -pub const DataType_depth: DataType__bindgen_ty_1 = - DataType__bindgen_ty_1::generic_type; -pub const DataType_channels: DataType__bindgen_ty_1 = - DataType__bindgen_ty_1::generic_type; -pub const DataType_fmt: DataType__bindgen_ty_1 = - DataType__bindgen_ty_1::generic_type; -pub const DataType_type_: DataType__bindgen_ty_1 = - DataType__bindgen_ty_1::generic_type; +pub const DataType_generic_type: DataType__bindgen_ty_1 = DataType__bindgen_ty_1::generic_type; +pub const DataType_depth: DataType__bindgen_ty_1 = DataType__bindgen_ty_1::generic_type; +pub const DataType_channels: DataType__bindgen_ty_1 = DataType__bindgen_ty_1::generic_type; +pub const DataType_fmt: DataType__bindgen_ty_1 = DataType__bindgen_ty_1::generic_type; +pub const DataType_type_: DataType__bindgen_ty_1 = DataType__bindgen_ty_1::generic_type; #[repr(i32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum DataType__bindgen_ty_1 { @@ -44,13 +33,10 @@ pub enum Foo__bindgen_ty_1 { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) + ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", + stringify!(Foo)) ); } diff --git a/bindgen-tests/tests/expectations/tests/anon_struct_in_union.rs b/bindgen-tests/tests/expectations/tests/anon_struct_in_union.rs index f32b057b27..b4e30c1a86 100644 --- a/bindgen-tests/tests/expectations/tests/anon_struct_in_union.rs +++ b/bindgen-tests/tests/expectations/tests/anon_struct_in_union.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone)] pub struct s { @@ -22,54 +16,38 @@ pub struct s__bindgen_ty_1_inner { } #[test] fn bindgen_test_layout_s__bindgen_ty_1_inner() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(s__bindgen_ty_1_inner)) + ::std::mem::size_of:: < s__bindgen_ty_1_inner > (), 4usize, concat!("Size of: ", + stringify!(s__bindgen_ty_1_inner)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < s__bindgen_ty_1_inner > (), 4usize, concat!("Alignment of ", stringify!(s__bindgen_ty_1_inner)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(s__bindgen_ty_1_inner), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(s__bindgen_ty_1_inner), "::", + stringify!(b)) ); } #[test] fn bindgen_test_layout_s__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(s__bindgen_ty_1)) + ::std::mem::size_of:: < s__bindgen_ty_1 > (), 4usize, concat!("Size of: ", + stringify!(s__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(s__bindgen_ty_1)) + ::std::mem::align_of:: < s__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", + stringify!(s__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).field) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(s__bindgen_ty_1), - "::", - stringify!(field) - ) + unsafe { ::std::ptr::addr_of!((* ptr).field) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(s__bindgen_ty_1), "::", + stringify!(field)) ); } impl Default for s__bindgen_ty_1 { @@ -83,22 +61,16 @@ impl Default for s__bindgen_ty_1 { } #[test] fn bindgen_test_layout_s() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(s)) + ::std::mem::size_of:: < s > (), 4usize, concat!("Size of: ", stringify!(s)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(s)) + ::std::mem::align_of:: < s > (), 4usize, concat!("Alignment of ", stringify!(s)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).u) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(s), "::", stringify!(u)) ); } diff --git a/bindgen-tests/tests/expectations/tests/anon_struct_in_union_1_0.rs b/bindgen-tests/tests/expectations/tests/anon_struct_in_union_1_0.rs index cbc5ac9b3f..43d495eb0c 100644 --- a/bindgen-tests/tests/expectations/tests/anon_struct_in_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/anon_struct_in_union_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -66,28 +60,20 @@ pub struct s__bindgen_ty_1_inner { } #[test] fn bindgen_test_layout_s__bindgen_ty_1_inner() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(s__bindgen_ty_1_inner)) + ::std::mem::size_of:: < s__bindgen_ty_1_inner > (), 4usize, concat!("Size of: ", + stringify!(s__bindgen_ty_1_inner)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < s__bindgen_ty_1_inner > (), 4usize, concat!("Alignment of ", stringify!(s__bindgen_ty_1_inner)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(s__bindgen_ty_1_inner), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(s__bindgen_ty_1_inner), "::", + stringify!(b)) ); } impl Clone for s__bindgen_ty_1_inner { @@ -97,28 +83,20 @@ impl Clone for s__bindgen_ty_1_inner { } #[test] fn bindgen_test_layout_s__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(s__bindgen_ty_1)) + ::std::mem::size_of:: < s__bindgen_ty_1 > (), 4usize, concat!("Size of: ", + stringify!(s__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(s__bindgen_ty_1)) + ::std::mem::align_of:: < s__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", + stringify!(s__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).field) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(s__bindgen_ty_1), - "::", - stringify!(field) - ) + unsafe { ::std::ptr::addr_of!((* ptr).field) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(s__bindgen_ty_1), "::", + stringify!(field)) ); } impl Clone for s__bindgen_ty_1 { @@ -128,22 +106,16 @@ impl Clone for s__bindgen_ty_1 { } #[test] fn bindgen_test_layout_s() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(s)) + ::std::mem::size_of:: < s > (), 4usize, concat!("Size of: ", stringify!(s)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(s)) + ::std::mem::align_of:: < s > (), 4usize, concat!("Alignment of ", stringify!(s)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).u) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(s), "::", stringify!(u)) ); } diff --git a/bindgen-tests/tests/expectations/tests/anon_union.rs b/bindgen-tests/tests/expectations/tests/anon_union.rs index 8caf7d110d..b8e43f3df5 100644 --- a/bindgen-tests/tests/expectations/tests/anon_union.rs +++ b/bindgen-tests/tests/expectations/tests/anon_union.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct TErrorResult { pub mResult: ::std::os::raw::c_int, @@ -13,8 +7,7 @@ pub struct TErrorResult { pub mUnionState: TErrorResult_UnionState, } impl TErrorResult_UnionState { - pub const HasException: TErrorResult_UnionState = - TErrorResult_UnionState::HasMessage; + pub const HasException: TErrorResult_UnionState = TErrorResult_UnionState::HasMessage; } #[repr(i32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] @@ -61,14 +54,12 @@ pub struct ErrorResult { #[test] fn bindgen_test_layout_ErrorResult() { assert_eq!( - ::std::mem::size_of::(), - 24usize, - concat!("Size of: ", stringify!(ErrorResult)) + ::std::mem::size_of:: < ErrorResult > (), 24usize, concat!("Size of: ", + stringify!(ErrorResult)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(ErrorResult)) + ::std::mem::align_of:: < ErrorResult > (), 8usize, concat!("Alignment of ", + stringify!(ErrorResult)) ); } impl Default for ErrorResult { @@ -83,19 +74,11 @@ impl Default for ErrorResult { #[test] fn __bindgen_test_layout_TErrorResult_open0_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of::(), - 24usize, - concat!( - "Size of template specialization: ", - stringify!(TErrorResult) - ) + ::std::mem::size_of:: < TErrorResult > (), 24usize, + concat!("Size of template specialization: ", stringify!(TErrorResult)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(TErrorResult) - ) + ::std::mem::align_of:: < TErrorResult > (), 8usize, + concat!("Alignment of template specialization: ", stringify!(TErrorResult)) ); } diff --git a/bindgen-tests/tests/expectations/tests/anon_union_1_0.rs b/bindgen-tests/tests/expectations/tests/anon_union_1_0.rs index 63273e608f..90094777ed 100644 --- a/bindgen-tests/tests/expectations/tests/anon_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/anon_union_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -56,8 +50,7 @@ pub struct TErrorResult { pub mMightHaveUnreported: bool, pub mUnionState: TErrorResult_UnionState, } -pub const TErrorResult_UnionState_HasException: TErrorResult_UnionState = - TErrorResult_UnionState::HasMessage; +pub const TErrorResult_UnionState_HasException: TErrorResult_UnionState = TErrorResult_UnionState::HasMessage; #[repr(i32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum TErrorResult_UnionState { @@ -77,8 +70,7 @@ pub struct TErrorResult_DOMExceptionInfo { #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct TErrorResult__bindgen_ty_1 { pub mMessage: __BindgenUnionField<*mut TErrorResult_Message>, - pub mDOMExceptionInfo: - __BindgenUnionField<*mut TErrorResult_DOMExceptionInfo>, + pub mDOMExceptionInfo: __BindgenUnionField<*mut TErrorResult_DOMExceptionInfo>, pub bindgen_union_field: u64, } impl Default for TErrorResult { @@ -98,14 +90,12 @@ pub struct ErrorResult { #[test] fn bindgen_test_layout_ErrorResult() { assert_eq!( - ::std::mem::size_of::(), - 24usize, - concat!("Size of: ", stringify!(ErrorResult)) + ::std::mem::size_of:: < ErrorResult > (), 24usize, concat!("Size of: ", + stringify!(ErrorResult)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(ErrorResult)) + ::std::mem::align_of:: < ErrorResult > (), 8usize, concat!("Alignment of ", + stringify!(ErrorResult)) ); } impl Clone for ErrorResult { @@ -125,19 +115,11 @@ impl Default for ErrorResult { #[test] fn __bindgen_test_layout_TErrorResult_open0_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of::(), - 24usize, - concat!( - "Size of template specialization: ", - stringify!(TErrorResult) - ) + ::std::mem::size_of:: < TErrorResult > (), 24usize, + concat!("Size of template specialization: ", stringify!(TErrorResult)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(TErrorResult) - ) + ::std::mem::align_of:: < TErrorResult > (), 8usize, + concat!("Alignment of template specialization: ", stringify!(TErrorResult)) ); } diff --git a/bindgen-tests/tests/expectations/tests/anonymous-template-types.rs b/bindgen-tests/tests/expectations/tests/anonymous-template-types.rs index 14afd6b316..9009b0d7c2 100644 --- a/bindgen-tests/tests/expectations/tests/anonymous-template-types.rs +++ b/bindgen-tests/tests/expectations/tests/anonymous-template-types.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Foo { diff --git a/bindgen-tests/tests/expectations/tests/arg_keyword.rs b/bindgen-tests/tests/expectations/tests/arg_keyword.rs index 43ff58313d..e7dd10b048 100644 --- a/bindgen-tests/tests/expectations/tests/arg_keyword.rs +++ b/bindgen-tests/tests/expectations/tests/arg_keyword.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { #[link_name = "\u{1}_Z3fooPKc"] pub fn foo(type_: *const ::std::os::raw::c_char); diff --git a/bindgen-tests/tests/expectations/tests/array-of-zero-sized-types.rs b/bindgen-tests/tests/expectations/tests/array-of-zero-sized-types.rs index ad1f22ed1f..fd6b658ccd 100644 --- a/bindgen-tests/tests/expectations/tests/array-of-zero-sized-types.rs +++ b/bindgen-tests/tests/expectations/tests/array-of-zero-sized-types.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] /// This should get an `_address` byte. #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -14,18 +8,16 @@ pub struct Empty { #[test] fn bindgen_test_layout_Empty() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Empty)) + ::std::mem::size_of:: < Empty > (), 1usize, concat!("Size of: ", + stringify!(Empty)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Empty)) + ::std::mem::align_of:: < Empty > (), 1usize, concat!("Alignment of ", + stringify!(Empty)) ); } -/// This should not get an `_address` byte, since each `Empty` gets one, meaning -/// that this object is addressable. +/** This should not get an `_address` byte, since each `Empty` gets one, meaning + that this object is addressable.*/ #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct HasArrayOfEmpty { @@ -33,27 +25,19 @@ pub struct HasArrayOfEmpty { } #[test] fn bindgen_test_layout_HasArrayOfEmpty() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 10usize, - concat!("Size of: ", stringify!(HasArrayOfEmpty)) + ::std::mem::size_of:: < HasArrayOfEmpty > (), 10usize, concat!("Size of: ", + stringify!(HasArrayOfEmpty)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(HasArrayOfEmpty)) + ::std::mem::align_of:: < HasArrayOfEmpty > (), 1usize, concat!("Alignment of ", + stringify!(HasArrayOfEmpty)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).empties) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(HasArrayOfEmpty), - "::", - stringify!(empties) - ) + unsafe { ::std::ptr::addr_of!((* ptr).empties) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(HasArrayOfEmpty), "::", + stringify!(empties)) ); } 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 12d5eab04b..b6c5c3cb2b 100644 --- a/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result.rs +++ b/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { @@ -13,31 +7,22 @@ pub struct Foo { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) + ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", + stringify!(Foo)) ); } 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; + pub fn Foo_foo(this: *mut Foo, arg1: ::std::os::raw::c_int) -> ::std::os::raw::c_int; } impl Foo { #[inline] #[must_use] - pub unsafe fn foo( - &mut self, - arg1: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int { + pub unsafe fn foo(&mut self, arg1: ::std::os::raw::c_int) -> ::std::os::raw::c_int { Foo_foo(self, arg1) } } 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 d860acd1b4..9d13c2b6e6 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 @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { @@ -13,29 +7,20 @@ pub struct Foo { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) + ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", + stringify!(Foo)) ); } 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; + pub fn Foo_foo(this: *mut Foo, arg1: ::std::os::raw::c_int) -> ::std::os::raw::c_int; } impl Foo { #[inline] - pub unsafe fn foo( - &mut self, - arg1: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int { + pub unsafe fn foo(&mut self, arg1: ::std::os::raw::c_int) -> ::std::os::raw::c_int { Foo_foo(self, arg1) } } diff --git a/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_pre_1_27.rs b/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_pre_1_27.rs index d860acd1b4..9d13c2b6e6 100644 --- a/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_pre_1_27.rs +++ b/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_pre_1_27.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { @@ -13,29 +7,20 @@ pub struct Foo { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) + ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", + stringify!(Foo)) ); } 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; + pub fn Foo_foo(this: *mut Foo, arg1: ::std::os::raw::c_int) -> ::std::os::raw::c_int; } impl Foo { #[inline] - pub unsafe fn foo( - &mut self, - arg1: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int { + pub unsafe fn foo(&mut self, arg1: ::std::os::raw::c_int) -> ::std::os::raw::c_int { Foo_foo(self, arg1) } } diff --git a/bindgen-tests/tests/expectations/tests/bad-namespace-parenthood-inheritance.rs b/bindgen-tests/tests/expectations/tests/bad-namespace-parenthood-inheritance.rs index 4d0d6bcd18..9ad8429e3c 100644 --- a/bindgen-tests/tests/expectations/tests/bad-namespace-parenthood-inheritance.rs +++ b/bindgen-tests/tests/expectations/tests/bad-namespace-parenthood-inheritance.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct std_char_traits { diff --git a/bindgen-tests/tests/expectations/tests/base-to-derived.rs b/bindgen-tests/tests/expectations/tests/base-to-derived.rs index 97830cd4fb..ebe7ffe6f1 100644 --- a/bindgen-tests/tests/expectations/tests/base-to-derived.rs +++ b/bindgen-tests/tests/expectations/tests/base-to-derived.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct false_type { @@ -13,13 +7,11 @@ pub struct false_type { #[test] fn bindgen_test_layout_false_type() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(false_type)) + ::std::mem::size_of:: < false_type > (), 1usize, concat!("Size of: ", + stringify!(false_type)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(false_type)) + ::std::mem::align_of:: < false_type > (), 1usize, concat!("Alignment of ", + stringify!(false_type)) ); } 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 8a091cb5e2..5bb19af498 100644 --- a/bindgen-tests/tests/expectations/tests/bindgen-union-inside-namespace.rs +++ b/bindgen-tests/tests/expectations/tests/bindgen-union-inside-namespace.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![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 { #[repr(C)] @@ -37,10 +31,7 @@ pub mod root { } impl ::std::marker::Copy for __BindgenUnionField {} impl ::std::fmt::Debug for __BindgenUnionField { - fn fmt( - &self, - fmt: &mut ::std::fmt::Formatter<'_>, - ) -> ::std::fmt::Result { + fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { fmt.write_str("__BindgenUnionField") } } @@ -67,42 +58,25 @@ pub mod root { } #[test] fn bindgen_test_layout_Bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Bar)) + ::std::mem::size_of:: < Bar > (), 4usize, concat!("Size of: ", + stringify!(Bar)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Bar)) + ::std::mem::align_of:: < Bar > (), 4usize, concat!("Alignment of ", + stringify!(Bar)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(foo) - ) + unsafe { ::std::ptr::addr_of!((* ptr).foo) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(Bar), "::", + stringify!(foo)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(bar) - ) + unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(Bar), "::", + stringify!(bar)) ); } impl Clone for Bar { diff --git a/bindgen-tests/tests/expectations/tests/bitfield-32bit-overflow.rs b/bindgen-tests/tests/expectations/tests/bitfield-32bit-overflow.rs index 680b25d8fd..64d5456a6c 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-32bit-overflow.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-32bit-overflow.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -100,22 +92,18 @@ pub struct MuchBitfield { #[test] fn bindgen_test_layout_MuchBitfield() { assert_eq!( - ::std::mem::size_of::(), - 5usize, - concat!("Size of: ", stringify!(MuchBitfield)) + ::std::mem::size_of:: < MuchBitfield > (), 5usize, concat!("Size of: ", + stringify!(MuchBitfield)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(MuchBitfield)) + ::std::mem::align_of:: < MuchBitfield > (), 1usize, concat!("Alignment of ", + stringify!(MuchBitfield)) ); } impl MuchBitfield { #[inline] pub fn m0(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) } } #[inline] pub fn set_m0(&mut self, val: ::std::os::raw::c_char) { @@ -126,9 +114,7 @@ impl MuchBitfield { } #[inline] pub fn m1(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u8) } } #[inline] pub fn set_m1(&mut self, val: ::std::os::raw::c_char) { @@ -139,9 +125,7 @@ impl MuchBitfield { } #[inline] pub fn m2(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u8) } } #[inline] pub fn set_m2(&mut self, val: ::std::os::raw::c_char) { @@ -152,9 +136,7 @@ impl MuchBitfield { } #[inline] pub fn m3(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(3usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(3usize, 1u8) as u8) } } #[inline] pub fn set_m3(&mut self, val: ::std::os::raw::c_char) { @@ -165,9 +147,7 @@ impl MuchBitfield { } #[inline] pub fn m4(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(4usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(4usize, 1u8) as u8) } } #[inline] pub fn set_m4(&mut self, val: ::std::os::raw::c_char) { @@ -178,9 +158,7 @@ impl MuchBitfield { } #[inline] pub fn m5(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(5usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(5usize, 1u8) as u8) } } #[inline] pub fn set_m5(&mut self, val: ::std::os::raw::c_char) { @@ -191,9 +169,7 @@ impl MuchBitfield { } #[inline] pub fn m6(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(6usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(6usize, 1u8) as u8) } } #[inline] pub fn set_m6(&mut self, val: ::std::os::raw::c_char) { @@ -204,9 +180,7 @@ impl MuchBitfield { } #[inline] pub fn m7(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(7usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(7usize, 1u8) as u8) } } #[inline] pub fn set_m7(&mut self, val: ::std::os::raw::c_char) { @@ -217,9 +191,7 @@ impl MuchBitfield { } #[inline] pub fn m8(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(8usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(8usize, 1u8) as u8) } } #[inline] pub fn set_m8(&mut self, val: ::std::os::raw::c_char) { @@ -230,9 +202,7 @@ impl MuchBitfield { } #[inline] pub fn m9(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(9usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(9usize, 1u8) as u8) } } #[inline] pub fn set_m9(&mut self, val: ::std::os::raw::c_char) { @@ -243,9 +213,7 @@ impl MuchBitfield { } #[inline] pub fn m10(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(10usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(10usize, 1u8) as u8) } } #[inline] pub fn set_m10(&mut self, val: ::std::os::raw::c_char) { @@ -256,9 +224,7 @@ impl MuchBitfield { } #[inline] pub fn m11(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(11usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(11usize, 1u8) as u8) } } #[inline] pub fn set_m11(&mut self, val: ::std::os::raw::c_char) { @@ -269,9 +235,7 @@ impl MuchBitfield { } #[inline] pub fn m12(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(12usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(12usize, 1u8) as u8) } } #[inline] pub fn set_m12(&mut self, val: ::std::os::raw::c_char) { @@ -282,9 +246,7 @@ impl MuchBitfield { } #[inline] pub fn m13(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(13usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(13usize, 1u8) as u8) } } #[inline] pub fn set_m13(&mut self, val: ::std::os::raw::c_char) { @@ -295,9 +257,7 @@ impl MuchBitfield { } #[inline] pub fn m14(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(14usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(14usize, 1u8) as u8) } } #[inline] pub fn set_m14(&mut self, val: ::std::os::raw::c_char) { @@ -308,9 +268,7 @@ impl MuchBitfield { } #[inline] pub fn m15(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(15usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(15usize, 1u8) as u8) } } #[inline] pub fn set_m15(&mut self, val: ::std::os::raw::c_char) { @@ -321,9 +279,7 @@ impl MuchBitfield { } #[inline] pub fn m16(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(16usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(16usize, 1u8) as u8) } } #[inline] pub fn set_m16(&mut self, val: ::std::os::raw::c_char) { @@ -334,9 +290,7 @@ impl MuchBitfield { } #[inline] pub fn m17(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(17usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(17usize, 1u8) as u8) } } #[inline] pub fn set_m17(&mut self, val: ::std::os::raw::c_char) { @@ -347,9 +301,7 @@ impl MuchBitfield { } #[inline] pub fn m18(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(18usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(18usize, 1u8) as u8) } } #[inline] pub fn set_m18(&mut self, val: ::std::os::raw::c_char) { @@ -360,9 +312,7 @@ impl MuchBitfield { } #[inline] pub fn m19(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(19usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(19usize, 1u8) as u8) } } #[inline] pub fn set_m19(&mut self, val: ::std::os::raw::c_char) { @@ -373,9 +323,7 @@ impl MuchBitfield { } #[inline] pub fn m20(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(20usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(20usize, 1u8) as u8) } } #[inline] pub fn set_m20(&mut self, val: ::std::os::raw::c_char) { @@ -386,9 +334,7 @@ impl MuchBitfield { } #[inline] pub fn m21(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(21usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(21usize, 1u8) as u8) } } #[inline] pub fn set_m21(&mut self, val: ::std::os::raw::c_char) { @@ -399,9 +345,7 @@ impl MuchBitfield { } #[inline] pub fn m22(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(22usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(22usize, 1u8) as u8) } } #[inline] pub fn set_m22(&mut self, val: ::std::os::raw::c_char) { @@ -412,9 +356,7 @@ impl MuchBitfield { } #[inline] pub fn m23(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(23usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(23usize, 1u8) as u8) } } #[inline] pub fn set_m23(&mut self, val: ::std::os::raw::c_char) { @@ -425,9 +367,7 @@ impl MuchBitfield { } #[inline] pub fn m24(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(24usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(24usize, 1u8) as u8) } } #[inline] pub fn set_m24(&mut self, val: ::std::os::raw::c_char) { @@ -438,9 +378,7 @@ impl MuchBitfield { } #[inline] pub fn m25(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(25usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(25usize, 1u8) as u8) } } #[inline] pub fn set_m25(&mut self, val: ::std::os::raw::c_char) { @@ -451,9 +389,7 @@ impl MuchBitfield { } #[inline] pub fn m26(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(26usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(26usize, 1u8) as u8) } } #[inline] pub fn set_m26(&mut self, val: ::std::os::raw::c_char) { @@ -464,9 +400,7 @@ impl MuchBitfield { } #[inline] pub fn m27(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(27usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(27usize, 1u8) as u8) } } #[inline] pub fn set_m27(&mut self, val: ::std::os::raw::c_char) { @@ -477,9 +411,7 @@ impl MuchBitfield { } #[inline] pub fn m28(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(28usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(28usize, 1u8) as u8) } } #[inline] pub fn set_m28(&mut self, val: ::std::os::raw::c_char) { @@ -490,9 +422,7 @@ impl MuchBitfield { } #[inline] pub fn m29(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(29usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(29usize, 1u8) as u8) } } #[inline] pub fn set_m29(&mut self, val: ::std::os::raw::c_char) { @@ -503,9 +433,7 @@ impl MuchBitfield { } #[inline] pub fn m30(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(30usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(30usize, 1u8) as u8) } } #[inline] pub fn set_m30(&mut self, val: ::std::os::raw::c_char) { @@ -516,9 +444,7 @@ impl MuchBitfield { } #[inline] pub fn m31(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(31usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(31usize, 1u8) as u8) } } #[inline] pub fn set_m31(&mut self, val: ::std::os::raw::c_char) { @@ -529,9 +455,7 @@ impl MuchBitfield { } #[inline] pub fn m32(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(32usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(32usize, 1u8) as u8) } } #[inline] pub fn set_m32(&mut self, val: ::std::os::raw::c_char) { @@ -576,140 +500,304 @@ impl MuchBitfield { m31: ::std::os::raw::c_char, m32: ::std::os::raw::c_char, ) -> __BindgenBitfieldUnit<[u8; 5usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 5usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 1u8, { - let m0: u8 = unsafe { ::std::mem::transmute(m0) }; - m0 as u64 - }); - __bindgen_bitfield_unit.set(1usize, 1u8, { - let m1: u8 = unsafe { ::std::mem::transmute(m1) }; - m1 as u64 - }); - __bindgen_bitfield_unit.set(2usize, 1u8, { - let m2: u8 = unsafe { ::std::mem::transmute(m2) }; - m2 as u64 - }); - __bindgen_bitfield_unit.set(3usize, 1u8, { - let m3: u8 = unsafe { ::std::mem::transmute(m3) }; - m3 as u64 - }); - __bindgen_bitfield_unit.set(4usize, 1u8, { - let m4: u8 = unsafe { ::std::mem::transmute(m4) }; - m4 as u64 - }); - __bindgen_bitfield_unit.set(5usize, 1u8, { - let m5: u8 = unsafe { ::std::mem::transmute(m5) }; - m5 as u64 - }); - __bindgen_bitfield_unit.set(6usize, 1u8, { - let m6: u8 = unsafe { ::std::mem::transmute(m6) }; - m6 as u64 - }); - __bindgen_bitfield_unit.set(7usize, 1u8, { - let m7: u8 = unsafe { ::std::mem::transmute(m7) }; - m7 as u64 - }); - __bindgen_bitfield_unit.set(8usize, 1u8, { - let m8: u8 = unsafe { ::std::mem::transmute(m8) }; - m8 as u64 - }); - __bindgen_bitfield_unit.set(9usize, 1u8, { - let m9: u8 = unsafe { ::std::mem::transmute(m9) }; - m9 as u64 - }); - __bindgen_bitfield_unit.set(10usize, 1u8, { - let m10: u8 = unsafe { ::std::mem::transmute(m10) }; - m10 as u64 - }); - __bindgen_bitfield_unit.set(11usize, 1u8, { - let m11: u8 = unsafe { ::std::mem::transmute(m11) }; - m11 as u64 - }); - __bindgen_bitfield_unit.set(12usize, 1u8, { - let m12: u8 = unsafe { ::std::mem::transmute(m12) }; - m12 as u64 - }); - __bindgen_bitfield_unit.set(13usize, 1u8, { - let m13: u8 = unsafe { ::std::mem::transmute(m13) }; - m13 as u64 - }); - __bindgen_bitfield_unit.set(14usize, 1u8, { - let m14: u8 = unsafe { ::std::mem::transmute(m14) }; - m14 as u64 - }); - __bindgen_bitfield_unit.set(15usize, 1u8, { - let m15: u8 = unsafe { ::std::mem::transmute(m15) }; - m15 as u64 - }); - __bindgen_bitfield_unit.set(16usize, 1u8, { - let m16: u8 = unsafe { ::std::mem::transmute(m16) }; - m16 as u64 - }); - __bindgen_bitfield_unit.set(17usize, 1u8, { - let m17: u8 = unsafe { ::std::mem::transmute(m17) }; - m17 as u64 - }); - __bindgen_bitfield_unit.set(18usize, 1u8, { - let m18: u8 = unsafe { ::std::mem::transmute(m18) }; - m18 as u64 - }); - __bindgen_bitfield_unit.set(19usize, 1u8, { - let m19: u8 = unsafe { ::std::mem::transmute(m19) }; - m19 as u64 - }); - __bindgen_bitfield_unit.set(20usize, 1u8, { - let m20: u8 = unsafe { ::std::mem::transmute(m20) }; - m20 as u64 - }); - __bindgen_bitfield_unit.set(21usize, 1u8, { - let m21: u8 = unsafe { ::std::mem::transmute(m21) }; - m21 as u64 - }); - __bindgen_bitfield_unit.set(22usize, 1u8, { - let m22: u8 = unsafe { ::std::mem::transmute(m22) }; - m22 as u64 - }); - __bindgen_bitfield_unit.set(23usize, 1u8, { - let m23: u8 = unsafe { ::std::mem::transmute(m23) }; - m23 as u64 - }); - __bindgen_bitfield_unit.set(24usize, 1u8, { - let m24: u8 = unsafe { ::std::mem::transmute(m24) }; - m24 as u64 - }); - __bindgen_bitfield_unit.set(25usize, 1u8, { - let m25: u8 = unsafe { ::std::mem::transmute(m25) }; - m25 as u64 - }); - __bindgen_bitfield_unit.set(26usize, 1u8, { - let m26: u8 = unsafe { ::std::mem::transmute(m26) }; - m26 as u64 - }); - __bindgen_bitfield_unit.set(27usize, 1u8, { - let m27: u8 = unsafe { ::std::mem::transmute(m27) }; - m27 as u64 - }); - __bindgen_bitfield_unit.set(28usize, 1u8, { - let m28: u8 = unsafe { ::std::mem::transmute(m28) }; - m28 as u64 - }); - __bindgen_bitfield_unit.set(29usize, 1u8, { - let m29: u8 = unsafe { ::std::mem::transmute(m29) }; - m29 as u64 - }); - __bindgen_bitfield_unit.set(30usize, 1u8, { - let m30: u8 = unsafe { ::std::mem::transmute(m30) }; - m30 as u64 - }); - __bindgen_bitfield_unit.set(31usize, 1u8, { - let m31: u8 = unsafe { ::std::mem::transmute(m31) }; - m31 as u64 - }); - __bindgen_bitfield_unit.set(32usize, 1u8, { - let m32: u8 = unsafe { ::std::mem::transmute(m32) }; - m32 as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 5usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let m0: u8 = unsafe { ::std::mem::transmute(m0) }; + m0 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 1usize, + 1u8, + { + let m1: u8 = unsafe { ::std::mem::transmute(m1) }; + m1 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 2usize, + 1u8, + { + let m2: u8 = unsafe { ::std::mem::transmute(m2) }; + m2 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 3usize, + 1u8, + { + let m3: u8 = unsafe { ::std::mem::transmute(m3) }; + m3 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 4usize, + 1u8, + { + let m4: u8 = unsafe { ::std::mem::transmute(m4) }; + m4 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 5usize, + 1u8, + { + let m5: u8 = unsafe { ::std::mem::transmute(m5) }; + m5 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 6usize, + 1u8, + { + let m6: u8 = unsafe { ::std::mem::transmute(m6) }; + m6 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 7usize, + 1u8, + { + let m7: u8 = unsafe { ::std::mem::transmute(m7) }; + m7 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 8usize, + 1u8, + { + let m8: u8 = unsafe { ::std::mem::transmute(m8) }; + m8 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 9usize, + 1u8, + { + let m9: u8 = unsafe { ::std::mem::transmute(m9) }; + m9 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 10usize, + 1u8, + { + let m10: u8 = unsafe { ::std::mem::transmute(m10) }; + m10 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 11usize, + 1u8, + { + let m11: u8 = unsafe { ::std::mem::transmute(m11) }; + m11 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 12usize, + 1u8, + { + let m12: u8 = unsafe { ::std::mem::transmute(m12) }; + m12 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 13usize, + 1u8, + { + let m13: u8 = unsafe { ::std::mem::transmute(m13) }; + m13 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 14usize, + 1u8, + { + let m14: u8 = unsafe { ::std::mem::transmute(m14) }; + m14 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 15usize, + 1u8, + { + let m15: u8 = unsafe { ::std::mem::transmute(m15) }; + m15 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 16usize, + 1u8, + { + let m16: u8 = unsafe { ::std::mem::transmute(m16) }; + m16 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 17usize, + 1u8, + { + let m17: u8 = unsafe { ::std::mem::transmute(m17) }; + m17 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 18usize, + 1u8, + { + let m18: u8 = unsafe { ::std::mem::transmute(m18) }; + m18 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 19usize, + 1u8, + { + let m19: u8 = unsafe { ::std::mem::transmute(m19) }; + m19 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 20usize, + 1u8, + { + let m20: u8 = unsafe { ::std::mem::transmute(m20) }; + m20 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 21usize, + 1u8, + { + let m21: u8 = unsafe { ::std::mem::transmute(m21) }; + m21 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 22usize, + 1u8, + { + let m22: u8 = unsafe { ::std::mem::transmute(m22) }; + m22 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 23usize, + 1u8, + { + let m23: u8 = unsafe { ::std::mem::transmute(m23) }; + m23 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 24usize, + 1u8, + { + let m24: u8 = unsafe { ::std::mem::transmute(m24) }; + m24 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 25usize, + 1u8, + { + let m25: u8 = unsafe { ::std::mem::transmute(m25) }; + m25 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 26usize, + 1u8, + { + let m26: u8 = unsafe { ::std::mem::transmute(m26) }; + m26 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 27usize, + 1u8, + { + let m27: u8 = unsafe { ::std::mem::transmute(m27) }; + m27 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 28usize, + 1u8, + { + let m28: u8 = unsafe { ::std::mem::transmute(m28) }; + m28 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 29usize, + 1u8, + { + let m29: u8 = unsafe { ::std::mem::transmute(m29) }; + m29 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 30usize, + 1u8, + { + let m30: u8 = unsafe { ::std::mem::transmute(m30) }; + m30 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 31usize, + 1u8, + { + let m31: u8 = unsafe { ::std::mem::transmute(m31) }; + m31 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 32usize, + 1u8, + { + let m32: u8 = unsafe { ::std::mem::transmute(m32) }; + m32 as u64 + }, + ); __bindgen_bitfield_unit } } diff --git a/bindgen-tests/tests/expectations/tests/bitfield-enum-basic.rs b/bindgen-tests/tests/expectations/tests/bitfield-enum-basic.rs index b6c25870b0..6a07c8be69 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-enum-basic.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-enum-basic.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] impl Foo { pub const Bar: Foo = Foo(2); } @@ -157,13 +151,11 @@ pub struct Dummy__bindgen_ty_1(pub ::std::os::raw::c_uint); #[test] fn bindgen_test_layout_Dummy() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Dummy)) + ::std::mem::size_of:: < Dummy > (), 1usize, concat!("Size of: ", + stringify!(Dummy)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Dummy)) + ::std::mem::align_of:: < Dummy > (), 1usize, concat!("Alignment of ", + stringify!(Dummy)) ); } diff --git a/bindgen-tests/tests/expectations/tests/bitfield-enum-repr-c.rs b/bindgen-tests/tests/expectations/tests/bitfield-enum-repr-c.rs index 1f0228e8e6..0403e844e2 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-enum-repr-c.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-enum-repr-c.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] impl Foo { pub const Bar: Foo = Foo(2); } diff --git a/bindgen-tests/tests/expectations/tests/bitfield-enum-repr-transparent.rs b/bindgen-tests/tests/expectations/tests/bitfield-enum-repr-transparent.rs index 53e113ed5e..0b5202dfe3 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-enum-repr-transparent.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-enum-repr-transparent.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] impl Foo { pub const Bar: Foo = Foo(2); } diff --git a/bindgen-tests/tests/expectations/tests/bitfield-large.rs b/bindgen-tests/tests/expectations/tests/bitfield-large.rs index b2c353a221..d7d37c12fc 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-large.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-large.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -101,22 +93,18 @@ pub struct HasBigBitfield { #[test] fn bindgen_test_layout_HasBigBitfield() { assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(HasBigBitfield)) + ::std::mem::size_of:: < HasBigBitfield > (), 16usize, concat!("Size of: ", + stringify!(HasBigBitfield)) ); assert_eq!( - ::std::mem::align_of::(), - 16usize, - concat!("Alignment of ", stringify!(HasBigBitfield)) + ::std::mem::align_of:: < HasBigBitfield > (), 16usize, concat!("Alignment of ", + stringify!(HasBigBitfield)) ); } impl HasBigBitfield { #[inline] pub fn x(&self) -> i128 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 128u8) as u128) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 128u8) as u128) } } #[inline] pub fn set_x(&mut self, val: i128) { @@ -127,12 +115,16 @@ impl HasBigBitfield { } #[inline] pub fn new_bitfield_1(x: i128) -> __BindgenBitfieldUnit<[u8; 16usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 16usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 128u8, { - let x: u128 = unsafe { ::std::mem::transmute(x) }; - x as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 16usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 128u8, + { + let x: u128 = unsafe { ::std::mem::transmute(x) }; + x as u64 + }, + ); __bindgen_bitfield_unit } } @@ -146,22 +138,18 @@ pub struct HasTwoBigBitfields { #[test] fn bindgen_test_layout_HasTwoBigBitfields() { assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(HasTwoBigBitfields)) + ::std::mem::size_of:: < HasTwoBigBitfields > (), 16usize, concat!("Size of: ", + stringify!(HasTwoBigBitfields)) ); assert_eq!( - ::std::mem::align_of::(), - 16usize, + ::std::mem::align_of:: < HasTwoBigBitfields > (), 16usize, concat!("Alignment of ", stringify!(HasTwoBigBitfields)) ); } impl HasTwoBigBitfields { #[inline] pub fn x(&self) -> i128 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 80u8) as u128) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 80u8) as u128) } } #[inline] pub fn set_x(&mut self, val: i128) { @@ -172,9 +160,7 @@ impl HasTwoBigBitfields { } #[inline] pub fn y(&self) -> i128 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(80usize, 48u8) as u128) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(80usize, 48u8) as u128) } } #[inline] pub fn set_y(&mut self, val: i128) { @@ -184,20 +170,26 @@ impl HasTwoBigBitfields { } } #[inline] - pub fn new_bitfield_1( - x: i128, - y: i128, - ) -> __BindgenBitfieldUnit<[u8; 16usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 16usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 80u8, { - let x: u128 = unsafe { ::std::mem::transmute(x) }; - x as u64 - }); - __bindgen_bitfield_unit.set(80usize, 48u8, { - let y: u128 = unsafe { ::std::mem::transmute(y) }; - y as u64 - }); + pub fn new_bitfield_1(x: i128, y: i128) -> __BindgenBitfieldUnit<[u8; 16usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 16usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 80u8, + { + let x: u128 = unsafe { ::std::mem::transmute(x) }; + x as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 80usize, + 48u8, + { + let y: u128 = unsafe { ::std::mem::transmute(y) }; + y as u64 + }, + ); __bindgen_bitfield_unit } } diff --git a/bindgen-tests/tests/expectations/tests/bitfield-linux-32.rs b/bindgen-tests/tests/expectations/tests/bitfield-linux-32.rs index 44c686265f..e76aab6df7 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-linux-32.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-linux-32.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -100,31 +92,25 @@ pub struct Test { } #[test] fn bindgen_test_layout_Test() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(Test)) + ::std::mem::size_of:: < Test > (), 16usize, concat!("Size of: ", + stringify!(Test)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Test)) + ::std::mem::align_of:: < Test > (), 4usize, concat!("Alignment of ", + stringify!(Test)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).foo) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(foo)) ); } impl Test { #[inline] pub fn x(&self) -> u64 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 56u8) as u64) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 56u8) as u64) } } #[inline] pub fn set_x(&mut self, val: u64) { @@ -135,9 +121,7 @@ impl Test { } #[inline] pub fn y(&self) -> u64 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(56usize, 8u8) as u64) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(56usize, 8u8) as u64) } } #[inline] pub fn set_y(&mut self, val: u64) { @@ -147,20 +131,26 @@ impl Test { } } #[inline] - pub fn new_bitfield_1( - x: u64, - y: u64, - ) -> __BindgenBitfieldUnit<[u8; 8usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 8usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 56u8, { - let x: u64 = unsafe { ::std::mem::transmute(x) }; - x as u64 - }); - __bindgen_bitfield_unit.set(56usize, 8u8, { - let y: u64 = unsafe { ::std::mem::transmute(y) }; - y as u64 - }); + pub fn new_bitfield_1(x: u64, y: u64) -> __BindgenBitfieldUnit<[u8; 8usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 8usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 56u8, + { + let x: u64 = unsafe { ::std::mem::transmute(x) }; + x as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 56usize, + 8u8, + { + let y: u64 = unsafe { ::std::mem::transmute(y) }; + y as u64 + }, + ); __bindgen_bitfield_unit } } diff --git a/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs b/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs index e9c1a76d1c..48bcf0583d 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -100,14 +92,11 @@ pub struct Foo { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) + ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", + stringify!(Foo)) ); } extern "C" { @@ -125,9 +114,7 @@ extern "C" { impl Foo { #[inline] pub fn type__bindgen_bitfield(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 3u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 3u8) as u8) } } #[inline] pub fn set_type__bindgen_bitfield(&mut self, val: ::std::os::raw::c_char) { @@ -140,13 +127,18 @@ impl Foo { pub fn new_bitfield_1( type__bindgen_bitfield: ::std::os::raw::c_char, ) -> __BindgenBitfieldUnit<[u8; 1usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 3u8, { - let type__bindgen_bitfield: u8 = - unsafe { ::std::mem::transmute(type__bindgen_bitfield) }; - type__bindgen_bitfield as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 3u8, + { + let type__bindgen_bitfield: u8 = unsafe { + ::std::mem::transmute(type__bindgen_bitfield) + }; + type__bindgen_bitfield as u64 + }, + ); __bindgen_bitfield_unit } #[inline] diff --git a/bindgen-tests/tests/expectations/tests/bitfield_align.rs b/bindgen-tests/tests/expectations/tests/bitfield_align.rs index 4baca11214..5c54d92623 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_align.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_align.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -102,36 +94,27 @@ pub struct A { } #[test] fn bindgen_test_layout_A() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(A)) + ::std::mem::size_of:: < A > (), 4usize, concat!("Size of: ", stringify!(A)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(A)) + ::std::mem::align_of:: < A > (), 4usize, concat!("Alignment of ", stringify!(A)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).x) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(x)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, - 3usize, + unsafe { ::std::ptr::addr_of!((* ptr).y) as usize - ptr as usize }, 3usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(y)) ); } impl A { #[inline] pub fn b1(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u32) } } #[inline] pub fn set_b1(&mut self, val: ::std::os::raw::c_uint) { @@ -142,9 +125,7 @@ impl A { } #[inline] pub fn b2(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u32) } } #[inline] pub fn set_b2(&mut self, val: ::std::os::raw::c_uint) { @@ -155,9 +136,7 @@ impl A { } #[inline] pub fn b3(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u32) } } #[inline] pub fn set_b3(&mut self, val: ::std::os::raw::c_uint) { @@ -168,9 +147,7 @@ impl A { } #[inline] pub fn b4(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(3usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(3usize, 1u8) as u32) } } #[inline] pub fn set_b4(&mut self, val: ::std::os::raw::c_uint) { @@ -181,9 +158,7 @@ impl A { } #[inline] pub fn b5(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(4usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(4usize, 1u8) as u32) } } #[inline] pub fn set_b5(&mut self, val: ::std::os::raw::c_uint) { @@ -194,9 +169,7 @@ impl A { } #[inline] pub fn b6(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(5usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(5usize, 1u8) as u32) } } #[inline] pub fn set_b6(&mut self, val: ::std::os::raw::c_uint) { @@ -207,9 +180,7 @@ impl A { } #[inline] pub fn b7(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(6usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(6usize, 1u8) as u32) } } #[inline] pub fn set_b7(&mut self, val: ::std::os::raw::c_uint) { @@ -220,9 +191,7 @@ impl A { } #[inline] pub fn b8(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(7usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(7usize, 1u8) as u32) } } #[inline] pub fn set_b8(&mut self, val: ::std::os::raw::c_uint) { @@ -233,9 +202,7 @@ impl A { } #[inline] pub fn b9(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(8usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(8usize, 1u8) as u32) } } #[inline] pub fn set_b9(&mut self, val: ::std::os::raw::c_uint) { @@ -246,9 +213,7 @@ impl A { } #[inline] pub fn b10(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(9usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(9usize, 1u8) as u32) } } #[inline] pub fn set_b10(&mut self, val: ::std::os::raw::c_uint) { @@ -270,48 +235,97 @@ impl A { b9: ::std::os::raw::c_uint, b10: ::std::os::raw::c_uint, ) -> __BindgenBitfieldUnit<[u8; 2usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 2usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 1u8, { - let b1: u32 = unsafe { ::std::mem::transmute(b1) }; - b1 as u64 - }); - __bindgen_bitfield_unit.set(1usize, 1u8, { - let b2: u32 = unsafe { ::std::mem::transmute(b2) }; - b2 as u64 - }); - __bindgen_bitfield_unit.set(2usize, 1u8, { - let b3: u32 = unsafe { ::std::mem::transmute(b3) }; - b3 as u64 - }); - __bindgen_bitfield_unit.set(3usize, 1u8, { - let b4: u32 = unsafe { ::std::mem::transmute(b4) }; - b4 as u64 - }); - __bindgen_bitfield_unit.set(4usize, 1u8, { - let b5: u32 = unsafe { ::std::mem::transmute(b5) }; - b5 as u64 - }); - __bindgen_bitfield_unit.set(5usize, 1u8, { - let b6: u32 = unsafe { ::std::mem::transmute(b6) }; - b6 as u64 - }); - __bindgen_bitfield_unit.set(6usize, 1u8, { - let b7: u32 = unsafe { ::std::mem::transmute(b7) }; - b7 as u64 - }); - __bindgen_bitfield_unit.set(7usize, 1u8, { - let b8: u32 = unsafe { ::std::mem::transmute(b8) }; - b8 as u64 - }); - __bindgen_bitfield_unit.set(8usize, 1u8, { - let b9: u32 = unsafe { ::std::mem::transmute(b9) }; - b9 as u64 - }); - __bindgen_bitfield_unit.set(9usize, 1u8, { - let b10: u32 = unsafe { ::std::mem::transmute(b10) }; - b10 as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 2usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let b1: u32 = unsafe { ::std::mem::transmute(b1) }; + b1 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 1usize, + 1u8, + { + let b2: u32 = unsafe { ::std::mem::transmute(b2) }; + b2 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 2usize, + 1u8, + { + let b3: u32 = unsafe { ::std::mem::transmute(b3) }; + b3 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 3usize, + 1u8, + { + let b4: u32 = unsafe { ::std::mem::transmute(b4) }; + b4 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 4usize, + 1u8, + { + let b5: u32 = unsafe { ::std::mem::transmute(b5) }; + b5 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 5usize, + 1u8, + { + let b6: u32 = unsafe { ::std::mem::transmute(b6) }; + b6 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 6usize, + 1u8, + { + let b7: u32 = unsafe { ::std::mem::transmute(b7) }; + b7 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 7usize, + 1u8, + { + let b8: u32 = unsafe { ::std::mem::transmute(b8) }; + b8 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 8usize, + 1u8, + { + let b9: u32 = unsafe { ::std::mem::transmute(b9) }; + b9 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 9usize, + 1u8, + { + let b10: u32 = unsafe { ::std::mem::transmute(b10) }; + b10 as u64 + }, + ); __bindgen_bitfield_unit } } @@ -325,22 +339,16 @@ pub struct B { #[test] fn bindgen_test_layout_B() { assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(B)) + ::std::mem::size_of:: < B > (), 4usize, concat!("Size of: ", stringify!(B)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(B)) + ::std::mem::align_of:: < B > (), 4usize, concat!("Alignment of ", stringify!(B)) ); } impl B { #[inline] pub fn foo(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 31u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 31u8) as u32) } } #[inline] pub fn set_foo(&mut self, val: ::std::os::raw::c_uint) { @@ -351,9 +359,7 @@ impl B { } #[inline] pub fn bar(&self) -> ::std::os::raw::c_uchar { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(31usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(31usize, 1u8) as u8) } } #[inline] pub fn set_bar(&mut self, val: ::std::os::raw::c_uchar) { @@ -367,16 +373,25 @@ impl B { foo: ::std::os::raw::c_uint, bar: ::std::os::raw::c_uchar, ) -> __BindgenBitfieldUnit<[u8; 4usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 31u8, { - let foo: u32 = unsafe { ::std::mem::transmute(foo) }; - foo as u64 - }); - __bindgen_bitfield_unit.set(31usize, 1u8, { - let bar: u8 = unsafe { ::std::mem::transmute(bar) }; - bar as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 31u8, + { + let foo: u32 = unsafe { ::std::mem::transmute(foo) }; + foo as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 31usize, + 1u8, + { + let bar: u8 = unsafe { ::std::mem::transmute(bar) }; + bar as u64 + }, + ); __bindgen_bitfield_unit } } @@ -390,36 +405,27 @@ pub struct C { } #[test] fn bindgen_test_layout_C() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(C)) + ::std::mem::size_of:: < C > (), 8usize, concat!("Size of: ", stringify!(C)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C)) + ::std::mem::align_of:: < C > (), 4usize, concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).x) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(x)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 4usize, + unsafe { ::std::ptr::addr_of!((* ptr).baz) as usize - ptr as usize }, 4usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(baz)) ); } impl C { #[inline] pub fn b1(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u32) } } #[inline] pub fn set_b1(&mut self, val: ::std::os::raw::c_uint) { @@ -430,9 +436,7 @@ impl C { } #[inline] pub fn b2(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u32) } } #[inline] pub fn set_b2(&mut self, val: ::std::os::raw::c_uint) { @@ -446,16 +450,25 @@ impl C { b1: ::std::os::raw::c_uint, b2: ::std::os::raw::c_uint, ) -> __BindgenBitfieldUnit<[u8; 1usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 1u8, { - let b1: u32 = unsafe { ::std::mem::transmute(b1) }; - b1 as u64 - }); - __bindgen_bitfield_unit.set(1usize, 1u8, { - let b2: u32 = unsafe { ::std::mem::transmute(b2) }; - b2 as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let b1: u32 = unsafe { ::std::mem::transmute(b1) }; + b1 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 1usize, + 1u8, + { + let b2: u32 = unsafe { ::std::mem::transmute(b2) }; + b2 as u64 + }, + ); __bindgen_bitfield_unit } } @@ -470,22 +483,18 @@ pub struct Date1 { #[test] fn bindgen_test_layout_Date1() { assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Date1)) + ::std::mem::size_of:: < Date1 > (), 4usize, concat!("Size of: ", + stringify!(Date1)) ); assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(Date1)) + ::std::mem::align_of:: < Date1 > (), 2usize, concat!("Alignment of ", + stringify!(Date1)) ); } impl Date1 { #[inline] pub fn nWeekDay(&self) -> ::std::os::raw::c_ushort { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 3u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 3u8) as u16) } } #[inline] pub fn set_nWeekDay(&mut self, val: ::std::os::raw::c_ushort) { @@ -496,9 +505,7 @@ impl Date1 { } #[inline] pub fn nMonthDay(&self) -> ::std::os::raw::c_ushort { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(3usize, 6u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(3usize, 6u8) as u16) } } #[inline] pub fn set_nMonthDay(&mut self, val: ::std::os::raw::c_ushort) { @@ -509,9 +516,7 @@ impl Date1 { } #[inline] pub fn nMonth(&self) -> ::std::os::raw::c_ushort { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(9usize, 5u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(9usize, 5u8) as u16) } } #[inline] pub fn set_nMonth(&mut self, val: ::std::os::raw::c_ushort) { @@ -522,9 +527,7 @@ impl Date1 { } #[inline] pub fn nYear(&self) -> ::std::os::raw::c_ushort { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(16usize, 8u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(16usize, 8u8) as u16) } } #[inline] pub fn set_nYear(&mut self, val: ::std::os::raw::c_ushort) { @@ -540,24 +543,43 @@ impl Date1 { nMonth: ::std::os::raw::c_ushort, nYear: ::std::os::raw::c_ushort, ) -> __BindgenBitfieldUnit<[u8; 3usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 3usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 3u8, { - let nWeekDay: u16 = unsafe { ::std::mem::transmute(nWeekDay) }; - nWeekDay as u64 - }); - __bindgen_bitfield_unit.set(3usize, 6u8, { - let nMonthDay: u16 = unsafe { ::std::mem::transmute(nMonthDay) }; - nMonthDay as u64 - }); - __bindgen_bitfield_unit.set(9usize, 5u8, { - let nMonth: u16 = unsafe { ::std::mem::transmute(nMonth) }; - nMonth as u64 - }); - __bindgen_bitfield_unit.set(16usize, 8u8, { - let nYear: u16 = unsafe { ::std::mem::transmute(nYear) }; - nYear as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 3usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 3u8, + { + let nWeekDay: u16 = unsafe { ::std::mem::transmute(nWeekDay) }; + nWeekDay as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 3usize, + 6u8, + { + let nMonthDay: u16 = unsafe { ::std::mem::transmute(nMonthDay) }; + nMonthDay as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 9usize, + 5u8, + { + let nMonth: u16 = unsafe { ::std::mem::transmute(nMonth) }; + nMonth as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 16usize, + 8u8, + { + let nYear: u16 = unsafe { ::std::mem::transmute(nYear) }; + nYear as u64 + }, + ); __bindgen_bitfield_unit } } @@ -571,22 +593,18 @@ pub struct Date2 { #[test] fn bindgen_test_layout_Date2() { assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Date2)) + ::std::mem::size_of:: < Date2 > (), 4usize, concat!("Size of: ", + stringify!(Date2)) ); assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(Date2)) + ::std::mem::align_of:: < Date2 > (), 2usize, concat!("Alignment of ", + stringify!(Date2)) ); } impl Date2 { #[inline] pub fn nWeekDay(&self) -> ::std::os::raw::c_ushort { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 3u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 3u8) as u16) } } #[inline] pub fn set_nWeekDay(&mut self, val: ::std::os::raw::c_ushort) { @@ -597,9 +615,7 @@ impl Date2 { } #[inline] pub fn nMonthDay(&self) -> ::std::os::raw::c_ushort { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(3usize, 6u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(3usize, 6u8) as u16) } } #[inline] pub fn set_nMonthDay(&mut self, val: ::std::os::raw::c_ushort) { @@ -610,9 +626,7 @@ impl Date2 { } #[inline] pub fn nMonth(&self) -> ::std::os::raw::c_ushort { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(9usize, 5u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(9usize, 5u8) as u16) } } #[inline] pub fn set_nMonth(&mut self, val: ::std::os::raw::c_ushort) { @@ -623,9 +637,7 @@ impl Date2 { } #[inline] pub fn nYear(&self) -> ::std::os::raw::c_ushort { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(16usize, 8u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(16usize, 8u8) as u16) } } #[inline] pub fn set_nYear(&mut self, val: ::std::os::raw::c_ushort) { @@ -636,9 +648,7 @@ impl Date2 { } #[inline] pub fn byte(&self) -> ::std::os::raw::c_uchar { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(24usize, 8u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(24usize, 8u8) as u8) } } #[inline] pub fn set_byte(&mut self, val: ::std::os::raw::c_uchar) { @@ -655,28 +665,52 @@ impl Date2 { nYear: ::std::os::raw::c_ushort, byte: ::std::os::raw::c_uchar, ) -> __BindgenBitfieldUnit<[u8; 4usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 3u8, { - let nWeekDay: u16 = unsafe { ::std::mem::transmute(nWeekDay) }; - nWeekDay as u64 - }); - __bindgen_bitfield_unit.set(3usize, 6u8, { - let nMonthDay: u16 = unsafe { ::std::mem::transmute(nMonthDay) }; - nMonthDay as u64 - }); - __bindgen_bitfield_unit.set(9usize, 5u8, { - let nMonth: u16 = unsafe { ::std::mem::transmute(nMonth) }; - nMonth as u64 - }); - __bindgen_bitfield_unit.set(16usize, 8u8, { - let nYear: u16 = unsafe { ::std::mem::transmute(nYear) }; - nYear as u64 - }); - __bindgen_bitfield_unit.set(24usize, 8u8, { - let byte: u8 = unsafe { ::std::mem::transmute(byte) }; - byte as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 3u8, + { + let nWeekDay: u16 = unsafe { ::std::mem::transmute(nWeekDay) }; + nWeekDay as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 3usize, + 6u8, + { + let nMonthDay: u16 = unsafe { ::std::mem::transmute(nMonthDay) }; + nMonthDay as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 9usize, + 5u8, + { + let nMonth: u16 = unsafe { ::std::mem::transmute(nMonth) }; + nMonth as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 16usize, + 8u8, + { + let nYear: u16 = unsafe { ::std::mem::transmute(nYear) }; + nYear as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 24usize, + 8u8, + { + let byte: u8 = unsafe { ::std::mem::transmute(byte) }; + byte as u64 + }, + ); __bindgen_bitfield_unit } } @@ -690,36 +724,25 @@ pub struct Date3 { } #[test] fn bindgen_test_layout_Date3() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Date3)) + ::std::mem::size_of:: < Date3 > (), 4usize, concat!("Size of: ", + stringify!(Date3)) ); assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(Date3)) + ::std::mem::align_of:: < Date3 > (), 2usize, concat!("Alignment of ", + stringify!(Date3)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).byte) as usize - ptr as usize }, - 3usize, - concat!( - "Offset of field: ", - stringify!(Date3), - "::", - stringify!(byte) - ) + unsafe { ::std::ptr::addr_of!((* ptr).byte) as usize - ptr as usize }, 3usize, + concat!("Offset of field: ", stringify!(Date3), "::", stringify!(byte)) ); } impl Date3 { #[inline] pub fn nWeekDay(&self) -> ::std::os::raw::c_ushort { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 3u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 3u8) as u16) } } #[inline] pub fn set_nWeekDay(&mut self, val: ::std::os::raw::c_ushort) { @@ -730,9 +753,7 @@ impl Date3 { } #[inline] pub fn nMonthDay(&self) -> ::std::os::raw::c_ushort { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(3usize, 6u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(3usize, 6u8) as u16) } } #[inline] pub fn set_nMonthDay(&mut self, val: ::std::os::raw::c_ushort) { @@ -743,9 +764,7 @@ impl Date3 { } #[inline] pub fn nMonth(&self) -> ::std::os::raw::c_ushort { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(9usize, 5u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(9usize, 5u8) as u16) } } #[inline] pub fn set_nMonth(&mut self, val: ::std::os::raw::c_ushort) { @@ -756,9 +775,7 @@ impl Date3 { } #[inline] pub fn nYear(&self) -> ::std::os::raw::c_ushort { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(16usize, 8u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(16usize, 8u8) as u16) } } #[inline] pub fn set_nYear(&mut self, val: ::std::os::raw::c_ushort) { @@ -774,24 +791,43 @@ impl Date3 { nMonth: ::std::os::raw::c_ushort, nYear: ::std::os::raw::c_ushort, ) -> __BindgenBitfieldUnit<[u8; 3usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 3usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 3u8, { - let nWeekDay: u16 = unsafe { ::std::mem::transmute(nWeekDay) }; - nWeekDay as u64 - }); - __bindgen_bitfield_unit.set(3usize, 6u8, { - let nMonthDay: u16 = unsafe { ::std::mem::transmute(nMonthDay) }; - nMonthDay as u64 - }); - __bindgen_bitfield_unit.set(9usize, 5u8, { - let nMonth: u16 = unsafe { ::std::mem::transmute(nMonth) }; - nMonth as u64 - }); - __bindgen_bitfield_unit.set(16usize, 8u8, { - let nYear: u16 = unsafe { ::std::mem::transmute(nYear) }; - nYear as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 3usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 3u8, + { + let nWeekDay: u16 = unsafe { ::std::mem::transmute(nWeekDay) }; + nWeekDay as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 3usize, + 6u8, + { + let nMonthDay: u16 = unsafe { ::std::mem::transmute(nMonthDay) }; + nMonthDay as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 9usize, + 5u8, + { + let nMonth: u16 = unsafe { ::std::mem::transmute(nMonth) }; + nMonth as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 16usize, + 8u8, + { + let nYear: u16 = unsafe { ::std::mem::transmute(nYear) }; + nYear as u64 + }, + ); __bindgen_bitfield_unit } } diff --git a/bindgen-tests/tests/expectations/tests/bitfield_align_2.rs b/bindgen-tests/tests/expectations/tests/bitfield_align_2.rs index aa11f80c51..e50930d5af 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_align_2.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_align_2.rs @@ -1,11 +1,5 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(not(target_os = "windows"))] - #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -56,8 +50,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -77,8 +70,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -110,14 +102,12 @@ pub struct TaggedPtr { #[test] fn bindgen_test_layout_TaggedPtr() { assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(TaggedPtr)) + ::std::mem::size_of:: < TaggedPtr > (), 8usize, concat!("Size of: ", + stringify!(TaggedPtr)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(TaggedPtr)) + ::std::mem::align_of:: < TaggedPtr > (), 8usize, concat!("Alignment of ", + stringify!(TaggedPtr)) ); } impl Default for TaggedPtr { @@ -132,9 +122,7 @@ impl Default for TaggedPtr { impl TaggedPtr { #[inline] pub fn tag(&self) -> MyEnum { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 2u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 2u8) as u32) } } #[inline] pub fn set_tag(&mut self, val: MyEnum) { @@ -145,9 +133,7 @@ impl TaggedPtr { } #[inline] pub fn ptr(&self) -> ::std::os::raw::c_long { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(2usize, 62u8) as u64) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 62u8) as u64) } } #[inline] pub fn set_ptr(&mut self, val: ::std::os::raw::c_long) { @@ -161,16 +147,25 @@ impl TaggedPtr { tag: MyEnum, ptr: ::std::os::raw::c_long, ) -> __BindgenBitfieldUnit<[u8; 8usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 8usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 2u8, { - let tag: u32 = unsafe { ::std::mem::transmute(tag) }; - tag as u64 - }); - __bindgen_bitfield_unit.set(2usize, 62u8, { - let ptr: u64 = unsafe { ::std::mem::transmute(ptr) }; - ptr as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 8usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 2u8, + { + let tag: u32 = unsafe { ::std::mem::transmute(tag) }; + tag as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 2usize, + 62u8, + { + let ptr: u64 = unsafe { ::std::mem::transmute(ptr) }; + ptr as u64 + }, + ); __bindgen_bitfield_unit } } diff --git a/bindgen-tests/tests/expectations/tests/bitfield_large_overflow.rs b/bindgen-tests/tests/expectations/tests/bitfield_large_overflow.rs index 4ee1f59844..725edd2b6a 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_large_overflow.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_large_overflow.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[repr(align(8))] #[derive(Debug, Default, Copy, Clone)] @@ -14,14 +8,12 @@ pub struct _bindgen_ty_1 { #[test] fn bindgen_test_layout__bindgen_ty_1() { assert_eq!( - ::std::mem::size_of::<_bindgen_ty_1>(), - 80usize, - concat!("Size of: ", stringify!(_bindgen_ty_1)) + ::std::mem::size_of:: < _bindgen_ty_1 > (), 80usize, concat!("Size of: ", + stringify!(_bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::<_bindgen_ty_1>(), - 8usize, - concat!("Alignment of ", stringify!(_bindgen_ty_1)) + ::std::mem::align_of:: < _bindgen_ty_1 > (), 8usize, concat!("Alignment of ", + stringify!(_bindgen_ty_1)) ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/bitfield_method_mangling.rs b/bindgen-tests/tests/expectations/tests/bitfield_method_mangling.rs index 42fa3c4cb4..9938ca15d2 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_method_mangling.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_method_mangling.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -101,22 +93,18 @@ pub struct mach_msg_type_descriptor_t { #[test] fn bindgen_test_layout_mach_msg_type_descriptor_t() { assert_eq!( - ::std::mem::size_of::(), - 4usize, + ::std::mem::size_of:: < mach_msg_type_descriptor_t > (), 4usize, concat!("Size of: ", stringify!(mach_msg_type_descriptor_t)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < mach_msg_type_descriptor_t > (), 4usize, concat!("Alignment of ", stringify!(mach_msg_type_descriptor_t)) ); } impl mach_msg_type_descriptor_t { #[inline] pub fn pad3(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 24u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 24u8) as u32) } } #[inline] pub fn set_pad3(&mut self, val: ::std::os::raw::c_uint) { @@ -127,9 +115,7 @@ impl mach_msg_type_descriptor_t { } #[inline] pub fn type_(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(24usize, 8u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(24usize, 8u8) as u32) } } #[inline] pub fn set_type(&mut self, val: ::std::os::raw::c_uint) { @@ -143,16 +129,25 @@ impl mach_msg_type_descriptor_t { pad3: ::std::os::raw::c_uint, type_: ::std::os::raw::c_uint, ) -> __BindgenBitfieldUnit<[u8; 4usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 24u8, { - let pad3: u32 = unsafe { ::std::mem::transmute(pad3) }; - pad3 as u64 - }); - __bindgen_bitfield_unit.set(24usize, 8u8, { - let type_: u32 = unsafe { ::std::mem::transmute(type_) }; - type_ as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 24u8, + { + let pad3: u32 = unsafe { ::std::mem::transmute(pad3) }; + pad3 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 24usize, + 8u8, + { + let type_: u32 = unsafe { ::std::mem::transmute(type_) }; + type_ as u64 + }, + ); __bindgen_bitfield_unit } } diff --git a/bindgen-tests/tests/expectations/tests/bitfield_pragma_packed.rs b/bindgen-tests/tests/expectations/tests/bitfield_pragma_packed.rs index 27cd90f140..44bf30e71a 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_pragma_packed.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_pragma_packed.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -100,22 +92,18 @@ pub struct Struct { #[test] fn bindgen_test_layout_Struct() { assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Struct)) + ::std::mem::size_of:: < Struct > (), 4usize, concat!("Size of: ", + stringify!(Struct)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Struct)) + ::std::mem::align_of:: < Struct > (), 1usize, concat!("Alignment of ", + stringify!(Struct)) ); } impl Struct { #[inline] pub fn a(&self) -> ::std::os::raw::c_uchar { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) } } #[inline] pub fn set_a(&mut self, val: ::std::os::raw::c_uchar) { @@ -126,9 +114,7 @@ impl Struct { } #[inline] pub fn b(&self) -> ::std::os::raw::c_uchar { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u8) } } #[inline] pub fn set_b(&mut self, val: ::std::os::raw::c_uchar) { @@ -139,9 +125,7 @@ impl Struct { } #[inline] pub fn c(&self) -> ::std::os::raw::c_uchar { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(2usize, 6u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 6u8) as u8) } } #[inline] pub fn set_c(&mut self, val: ::std::os::raw::c_uchar) { @@ -152,9 +136,7 @@ impl Struct { } #[inline] pub fn d(&self) -> ::std::os::raw::c_ushort { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(8usize, 16u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(8usize, 16u8) as u16) } } #[inline] pub fn set_d(&mut self, val: ::std::os::raw::c_ushort) { @@ -165,9 +147,7 @@ impl Struct { } #[inline] pub fn e(&self) -> ::std::os::raw::c_uchar { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(24usize, 8u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(24usize, 8u8) as u8) } } #[inline] pub fn set_e(&mut self, val: ::std::os::raw::c_uchar) { @@ -184,28 +164,52 @@ impl Struct { d: ::std::os::raw::c_ushort, e: ::std::os::raw::c_uchar, ) -> __BindgenBitfieldUnit<[u8; 4usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 1u8, { - let a: u8 = unsafe { ::std::mem::transmute(a) }; - a as u64 - }); - __bindgen_bitfield_unit.set(1usize, 1u8, { - let b: u8 = unsafe { ::std::mem::transmute(b) }; - b as u64 - }); - __bindgen_bitfield_unit.set(2usize, 6u8, { - let c: u8 = unsafe { ::std::mem::transmute(c) }; - c as u64 - }); - __bindgen_bitfield_unit.set(8usize, 16u8, { - let d: u16 = unsafe { ::std::mem::transmute(d) }; - d as u64 - }); - __bindgen_bitfield_unit.set(24usize, 8u8, { - let e: u8 = unsafe { ::std::mem::transmute(e) }; - e as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let a: u8 = unsafe { ::std::mem::transmute(a) }; + a as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 1usize, + 1u8, + { + let b: u8 = unsafe { ::std::mem::transmute(b) }; + b as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 2usize, + 6u8, + { + let c: u8 = unsafe { ::std::mem::transmute(c) }; + c as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 8usize, + 16u8, + { + let d: u16 = unsafe { ::std::mem::transmute(d) }; + d as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 24usize, + 8u8, + { + let e: u8 = unsafe { ::std::mem::transmute(e) }; + e as u64 + }, + ); __bindgen_bitfield_unit } } diff --git a/bindgen-tests/tests/expectations/tests/block_return_type.rs b/bindgen-tests/tests/expectations/tests/block_return_type.rs index bc4347335e..fa6c0ac67c 100644 --- a/bindgen-tests/tests/expectations/tests/block_return_type.rs +++ b/bindgen-tests/tests/expectations/tests/block_return_type.rs @@ -1,11 +1,5 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] - extern crate block; extern "C" { pub fn func() -> _bindgen_ty_id_4; diff --git a/bindgen-tests/tests/expectations/tests/blocklist-and-impl-debug.rs b/bindgen-tests/tests/expectations/tests/blocklist-and-impl-debug.rs index 788cb30c4c..a0bccaff0c 100644 --- a/bindgen-tests/tests/expectations/tests/blocklist-and-impl-debug.rs +++ b/bindgen-tests/tests/expectations/tests/blocklist-and-impl-debug.rs @@ -1,12 +1,5 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub struct BlocklistMe(u8); - /// Because this type contains a blocklisted type, it should not derive Debug. #[repr(C)] pub struct ShouldManuallyImplDebug { @@ -14,28 +7,20 @@ pub struct ShouldManuallyImplDebug { } #[test] fn bindgen_test_layout_ShouldManuallyImplDebug() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 1usize, + ::std::mem::size_of:: < ShouldManuallyImplDebug > (), 1usize, concat!("Size of: ", stringify!(ShouldManuallyImplDebug)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < ShouldManuallyImplDebug > (), 1usize, concat!("Alignment of ", stringify!(ShouldManuallyImplDebug)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldManuallyImplDebug), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(ShouldManuallyImplDebug), "::", + stringify!(a)) ); } impl Default for ShouldManuallyImplDebug { diff --git a/bindgen-tests/tests/expectations/tests/blocklist-file.rs b/bindgen-tests/tests/expectations/tests/blocklist-file.rs index 4d2b67129a..de8deabade 100644 --- a/bindgen-tests/tests/expectations/tests/blocklist-file.rs +++ b/bindgen-tests/tests/expectations/tests/blocklist-file.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct SizedIntegers { @@ -14,48 +8,27 @@ pub struct SizedIntegers { } #[test] fn bindgen_test_layout_SizedIntegers() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(SizedIntegers)) + ::std::mem::size_of:: < SizedIntegers > (), 8usize, concat!("Size of: ", + stringify!(SizedIntegers)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(SizedIntegers)) + ::std::mem::align_of:: < SizedIntegers > (), 4usize, concat!("Alignment of ", + stringify!(SizedIntegers)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(SizedIntegers), - "::", - stringify!(x) - ) + unsafe { ::std::ptr::addr_of!((* ptr).x) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(SizedIntegers), "::", stringify!(x)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(SizedIntegers), - "::", - stringify!(y) - ) + unsafe { ::std::ptr::addr_of!((* ptr).y) as usize - ptr as usize }, 2usize, + concat!("Offset of field: ", stringify!(SizedIntegers), "::", stringify!(y)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).z) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(SizedIntegers), - "::", - stringify!(z) - ) + unsafe { ::std::ptr::addr_of!((* ptr).z) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(SizedIntegers), "::", stringify!(z)) ); } #[repr(C)] @@ -65,27 +38,19 @@ pub struct StructWithBlocklistedFwdDecl { } #[test] fn bindgen_test_layout_StructWithBlocklistedFwdDecl() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 1usize, + ::std::mem::size_of:: < StructWithBlocklistedFwdDecl > (), 1usize, concat!("Size of: ", stringify!(StructWithBlocklistedFwdDecl)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < StructWithBlocklistedFwdDecl > (), 1usize, concat!("Alignment of ", stringify!(StructWithBlocklistedFwdDecl)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(StructWithBlocklistedFwdDecl), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(StructWithBlocklistedFwdDecl), "::", + stringify!(b)) ); } diff --git a/bindgen-tests/tests/expectations/tests/blocklist-function.rs b/bindgen-tests/tests/expectations/tests/blocklist-function.rs index 5299b1517e..002752bc6f 100644 --- a/bindgen-tests/tests/expectations/tests/blocklist-function.rs +++ b/bindgen-tests/tests/expectations/tests/blocklist-function.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![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 { #[allow(unused_imports)] @@ -29,14 +23,11 @@ pub mod root { #[test] fn bindgen_test_layout_C() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(C)) + ::std::mem::size_of:: < C > (), 1usize, concat!("Size of: ", stringify!(C)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(C)) + ::std::mem::align_of:: < C > (), 1usize, concat!("Alignment of ", + stringify!(C)) ); } } diff --git a/bindgen-tests/tests/expectations/tests/blocklist-item.rs b/bindgen-tests/tests/expectations/tests/blocklist-item.rs index 0edee9ec32..39de8002b3 100644 --- a/bindgen-tests/tests/expectations/tests/blocklist-item.rs +++ b/bindgen-tests/tests/expectations/tests/blocklist-item.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![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 { #[allow(unused_imports)] diff --git a/bindgen-tests/tests/expectations/tests/blocklist-methods.rs b/bindgen-tests/tests/expectations/tests/blocklist-methods.rs index eadc0694ed..dee53c0b81 100644 --- a/bindgen-tests/tests/expectations/tests/blocklist-methods.rs +++ b/bindgen-tests/tests/expectations/tests/blocklist-methods.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { @@ -13,14 +7,11 @@ pub struct Foo { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) + ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", + stringify!(Foo)) ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/blocks-signature.rs b/bindgen-tests/tests/expectations/tests/blocks-signature.rs index ff7114a7d4..6a5b873b94 100644 --- a/bindgen-tests/tests/expectations/tests/blocks-signature.rs +++ b/bindgen-tests/tests/expectations/tests/blocks-signature.rs @@ -1,11 +1,5 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] - extern crate block; extern "C" { #[link_name = "\u{1}_Z8atexit_bU13block_pointerFvvE"] @@ -36,38 +30,25 @@ pub struct contains_block_pointers { } #[test] fn bindgen_test_layout_contains_block_pointers() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 16usize, + ::std::mem::size_of:: < contains_block_pointers > (), 16usize, concat!("Size of: ", stringify!(contains_block_pointers)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, + ::std::mem::align_of:: < contains_block_pointers > (), 8usize, concat!("Alignment of ", stringify!(contains_block_pointers)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).val) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(contains_block_pointers), - "::", - stringify!(val) - ) + unsafe { ::std::ptr::addr_of!((* ptr).val) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(contains_block_pointers), "::", + stringify!(val)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ptr_val) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(contains_block_pointers), - "::", - stringify!(ptr_val) - ) + unsafe { ::std::ptr::addr_of!((* ptr).ptr_val) as usize - ptr as usize }, 8usize, + concat!("Offset of field: ", stringify!(contains_block_pointers), "::", + stringify!(ptr_val)) ); } impl Default for contains_block_pointers { @@ -86,7 +67,8 @@ pub type _bindgen_ty_id_40 = *const ::block::Block< >; pub type _bindgen_ty_id_50 = *const ::block::Block<(usize,), ()>; pub type _bindgen_ty_id_56 = *const ::block::Block<(usize,), ()>; -pub type contains_block_pointers__bindgen_ty_id_61 = - *const ::block::Block<(::std::os::raw::c_int,), ()>; -pub type _bindgen_ty_id_68 = - *const ::block::Block<(::std::os::raw::c_int,), ()>; +pub type contains_block_pointers__bindgen_ty_id_61 = *const ::block::Block< + (::std::os::raw::c_int,), + (), +>; +pub type _bindgen_ty_id_68 = *const ::block::Block<(::std::os::raw::c_int,), ()>; diff --git a/bindgen-tests/tests/expectations/tests/blocks.rs b/bindgen-tests/tests/expectations/tests/blocks.rs index 6f242989b6..9bbfdaaddd 100644 --- a/bindgen-tests/tests/expectations/tests/blocks.rs +++ b/bindgen-tests/tests/expectations/tests/blocks.rs @@ -1,11 +1,5 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] - extern "C" { #[link_name = "\u{1}_Z8atexit_bU13block_pointerFvvE"] pub fn atexit_b(arg1: *mut ::std::os::raw::c_void); @@ -35,38 +29,25 @@ pub struct contains_block_pointers { } #[test] fn bindgen_test_layout_contains_block_pointers() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 16usize, + ::std::mem::size_of:: < contains_block_pointers > (), 16usize, concat!("Size of: ", stringify!(contains_block_pointers)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, + ::std::mem::align_of:: < contains_block_pointers > (), 8usize, concat!("Alignment of ", stringify!(contains_block_pointers)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).val) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(contains_block_pointers), - "::", - stringify!(val) - ) + unsafe { ::std::ptr::addr_of!((* ptr).val) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(contains_block_pointers), "::", + stringify!(val)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ptr_val) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(contains_block_pointers), - "::", - stringify!(ptr_val) - ) + unsafe { ::std::ptr::addr_of!((* ptr).ptr_val) as usize - ptr as usize }, 8usize, + concat!("Offset of field: ", stringify!(contains_block_pointers), "::", + stringify!(ptr_val)) ); } impl Default for contains_block_pointers { diff --git a/bindgen-tests/tests/expectations/tests/bug-1529681.rs b/bindgen-tests/tests/expectations/tests/bug-1529681.rs index 6a0f5e134a..b4d84ea4f1 100644 --- a/bindgen-tests/tests/expectations/tests/bug-1529681.rs +++ b/bindgen-tests/tests/expectations/tests/bug-1529681.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct BrowsingContext { @@ -13,13 +7,11 @@ pub struct BrowsingContext { #[test] fn bindgen_test_layout_BrowsingContext() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(BrowsingContext)) + ::std::mem::size_of:: < BrowsingContext > (), 1usize, concat!("Size of: ", + stringify!(BrowsingContext)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(BrowsingContext)) + ::std::mem::align_of:: < BrowsingContext > (), 1usize, concat!("Alignment of ", + stringify!(BrowsingContext)) ); } diff --git a/bindgen-tests/tests/expectations/tests/builtin-template.rs b/bindgen-tests/tests/expectations/tests/builtin-template.rs index 112b767008..53e3fbf9bf 100644 --- a/bindgen-tests/tests/expectations/tests/builtin-template.rs +++ b/bindgen-tests/tests/expectations/tests/builtin-template.rs @@ -1,8 +1,2 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type std_make_integer_sequence = u8; diff --git a/bindgen-tests/tests/expectations/tests/c-empty-layout.rs b/bindgen-tests/tests/expectations/tests/c-empty-layout.rs index ebef2b6d82..72ccd3f405 100644 --- a/bindgen-tests/tests/expectations/tests/c-empty-layout.rs +++ b/bindgen-tests/tests/expectations/tests/c-empty-layout.rs @@ -1,23 +1,14 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo {} #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of:: < Foo > (), 0usize, concat!("Size of: ", stringify!(Foo)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) + ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", + stringify!(Foo)) ); } diff --git a/bindgen-tests/tests/expectations/tests/c-unwind-abi-override-nightly.rs b/bindgen-tests/tests/expectations/tests/c-unwind-abi-override-nightly.rs index 6b34192fe4..8511b30f5f 100644 --- a/bindgen-tests/tests/expectations/tests/c-unwind-abi-override-nightly.rs +++ b/bindgen-tests/tests/expectations/tests/c-unwind-abi-override-nightly.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(feature = "nightly")] #![feature(abi_thiscall)] - extern "C-unwind" { pub fn foo(); } diff --git a/bindgen-tests/tests/expectations/tests/c_naming.rs b/bindgen-tests/tests/expectations/tests/c_naming.rs index 3e56b1d60a..c60f4f5980 100644 --- a/bindgen-tests/tests/expectations/tests/c_naming.rs +++ b/bindgen-tests/tests/expectations/tests/c_naming.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct struct_a { @@ -12,28 +6,19 @@ pub struct struct_a { } #[test] fn bindgen_test_layout_struct_a() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(struct_a)) + ::std::mem::size_of:: < struct_a > (), 4usize, concat!("Size of: ", + stringify!(struct_a)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(struct_a)) + ::std::mem::align_of:: < struct_a > (), 4usize, concat!("Alignment of ", + stringify!(struct_a)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(struct_a), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(struct_a), "::", stringify!(a)) ); } pub type a = *const struct_a; @@ -45,38 +30,23 @@ pub union union_b { } #[test] fn bindgen_test_layout_union_b() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(union_b)) + ::std::mem::size_of:: < union_b > (), 4usize, concat!("Size of: ", + stringify!(union_b)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(union_b)) + ::std::mem::align_of:: < union_b > (), 4usize, concat!("Alignment of ", + stringify!(union_b)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(union_b), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(union_b), "::", stringify!(a)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(union_b), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(union_b), "::", stringify!(b)) ); } impl Default for union_b { diff --git a/bindgen-tests/tests/expectations/tests/call-conv-typedef.rs b/bindgen-tests/tests/expectations/tests/call-conv-typedef.rs index 6eabb1f6ad..c62756f364 100644 --- a/bindgen-tests/tests/expectations/tests/call-conv-typedef.rs +++ b/bindgen-tests/tests/expectations/tests/call-conv-typedef.rs @@ -1,11 +1,5 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(not(test))] - pub type void_fn = ::std::option::Option; pub type fn_ = ::std::option::Option< unsafe extern "stdcall" fn(id: ::std::os::raw::c_int) -> void_fn, diff --git a/bindgen-tests/tests/expectations/tests/canonical-types.rs b/bindgen-tests/tests/expectations/tests/canonical-types.rs index a68e14244a..61faef16b0 100644 --- a/bindgen-tests/tests/expectations/tests/canonical-types.rs +++ b/bindgen-tests/tests/expectations/tests/canonical-types.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct ClassA { @@ -85,14 +79,12 @@ pub struct ClassD { #[test] fn bindgen_test_layout_ClassD() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(ClassD)) + ::std::mem::size_of:: < ClassD > (), 1usize, concat!("Size of: ", + stringify!(ClassD)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(ClassD)) + ::std::mem::align_of:: < ClassD > (), 1usize, concat!("Alignment of ", + stringify!(ClassD)) ); } impl Default for ClassD { @@ -105,16 +97,13 @@ impl Default for ClassD { } } #[test] -fn __bindgen_test_layout_ClassB_open0_ClassD_ClassCInnerCRTP_close0_instantiation( -) { +fn __bindgen_test_layout_ClassB_open0_ClassD_ClassCInnerCRTP_close0_instantiation() { assert_eq!( - ::std::mem::size_of::(), - 1usize, + ::std::mem::size_of:: < ClassB > (), 1usize, concat!("Size of template specialization: ", stringify!(ClassB)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < ClassB > (), 1usize, concat!("Alignment of template specialization: ", stringify!(ClassB)) ); } @@ -126,14 +115,12 @@ pub struct ClassCInnerCRTP { #[test] fn bindgen_test_layout_ClassCInnerCRTP() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(ClassCInnerCRTP)) + ::std::mem::size_of:: < ClassCInnerCRTP > (), 1usize, concat!("Size of: ", + stringify!(ClassCInnerCRTP)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(ClassCInnerCRTP)) + ::std::mem::align_of:: < ClassCInnerCRTP > (), 1usize, concat!("Alignment of ", + stringify!(ClassCInnerCRTP)) ); } impl Default for ClassCInnerCRTP { @@ -146,16 +133,13 @@ impl Default for ClassCInnerCRTP { } } #[test] -fn __bindgen_test_layout_ClassB_open0_ClassCInnerCRTP_ClassAInner_close0_instantiation( -) { +fn __bindgen_test_layout_ClassB_open0_ClassCInnerCRTP_ClassAInner_close0_instantiation() { assert_eq!( - ::std::mem::size_of::(), - 1usize, + ::std::mem::size_of:: < ClassB > (), 1usize, concat!("Size of template specialization: ", stringify!(ClassB)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < ClassB > (), 1usize, concat!("Alignment of template specialization: ", stringify!(ClassB)) ); } @@ -166,28 +150,19 @@ pub struct ClassAInner { } #[test] fn bindgen_test_layout_ClassAInner() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(ClassAInner)) + ::std::mem::size_of:: < ClassAInner > (), 8usize, concat!("Size of: ", + stringify!(ClassAInner)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(ClassAInner)) + ::std::mem::align_of:: < ClassAInner > (), 8usize, concat!("Alignment of ", + stringify!(ClassAInner)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ClassAInner), - "::", - stringify!(x) - ) + unsafe { ::std::ptr::addr_of!((* ptr).x) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(ClassAInner), "::", stringify!(x)) ); } impl Default for ClassAInner { @@ -206,28 +181,19 @@ pub struct ClassCInnerA { } #[test] fn bindgen_test_layout_ClassCInnerA() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(ClassCInnerA)) + ::std::mem::size_of:: < ClassCInnerA > (), 8usize, concat!("Size of: ", + stringify!(ClassCInnerA)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(ClassCInnerA)) + ::std::mem::align_of:: < ClassCInnerA > (), 8usize, concat!("Alignment of ", + stringify!(ClassCInnerA)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ClassCInnerA), - "::", - stringify!(member) - ) + unsafe { ::std::ptr::addr_of!((* ptr).member) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(ClassCInnerA), "::", stringify!(member)) ); } impl Default for ClassCInnerA { @@ -246,28 +212,19 @@ pub struct ClassCInnerB { } #[test] fn bindgen_test_layout_ClassCInnerB() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(ClassCInnerB)) + ::std::mem::size_of:: < ClassCInnerB > (), 8usize, concat!("Size of: ", + stringify!(ClassCInnerB)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(ClassCInnerB)) + ::std::mem::align_of:: < ClassCInnerB > (), 8usize, concat!("Alignment of ", + stringify!(ClassCInnerB)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).cache) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ClassCInnerB), - "::", - stringify!(cache) - ) + unsafe { ::std::ptr::addr_of!((* ptr).cache) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(ClassCInnerB), "::", stringify!(cache)) ); } impl Default for ClassCInnerB { diff --git a/bindgen-tests/tests/expectations/tests/canonical_path_without_namespacing.rs b/bindgen-tests/tests/expectations/tests/canonical_path_without_namespacing.rs index 12f10a8873..3b9db4be47 100644 --- a/bindgen-tests/tests/expectations/tests/canonical_path_without_namespacing.rs +++ b/bindgen-tests/tests/expectations/tests/canonical_path_without_namespacing.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Bar { @@ -13,14 +7,11 @@ pub struct Bar { #[test] fn bindgen_test_layout_Bar() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Bar)) + ::std::mem::size_of:: < Bar > (), 1usize, concat!("Size of: ", stringify!(Bar)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Bar)) + ::std::mem::align_of:: < Bar > (), 1usize, concat!("Alignment of ", + stringify!(Bar)) ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/char.rs b/bindgen-tests/tests/expectations/tests/char.rs index 960a681f6c..9e1e3177d2 100644 --- a/bindgen-tests/tests/expectations/tests/char.rs +++ b/bindgen-tests/tests/expectations/tests/char.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type Char = ::std::os::raw::c_char; pub type SChar = ::std::os::raw::c_schar; pub type UChar = ::std::os::raw::c_uchar; @@ -26,82 +20,62 @@ pub struct Test { } #[test] fn bindgen_test_layout_Test() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 12usize, - concat!("Size of: ", stringify!(Test)) + ::std::mem::size_of:: < Test > (), 12usize, concat!("Size of: ", + stringify!(Test)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Test)) + ::std::mem::align_of:: < Test > (), 1usize, concat!("Alignment of ", + stringify!(Test)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ch) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).ch) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(ch)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize }, - 1usize, + unsafe { ::std::ptr::addr_of!((* ptr).u) as usize - ptr as usize }, 1usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(u)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 2usize, + unsafe { ::std::ptr::addr_of!((* ptr).d) as usize - ptr as usize }, 2usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(d)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).cch) as usize - ptr as usize }, - 3usize, + unsafe { ::std::ptr::addr_of!((* ptr).cch) as usize - ptr as usize }, 3usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(cch)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).cu) as usize - ptr as usize }, - 4usize, + unsafe { ::std::ptr::addr_of!((* ptr).cu) as usize - ptr as usize }, 4usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(cu)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).cd) as usize - ptr as usize }, - 5usize, + unsafe { ::std::ptr::addr_of!((* ptr).cd) as usize - ptr as usize }, 5usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(cd)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).Cch) as usize - ptr as usize }, - 6usize, + unsafe { ::std::ptr::addr_of!((* ptr).Cch) as usize - ptr as usize }, 6usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cch)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).Cu) as usize - ptr as usize }, - 7usize, + unsafe { ::std::ptr::addr_of!((* ptr).Cu) as usize - ptr as usize }, 7usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cu)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).Cd) as usize - ptr as usize }, - 8usize, + unsafe { ::std::ptr::addr_of!((* ptr).Cd) as usize - ptr as usize }, 8usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cd)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).Ccch) as usize - ptr as usize }, - 9usize, - concat!( - "Offset of field: ", - stringify!(Test), - "::", - stringify!(Ccch) - ) + unsafe { ::std::ptr::addr_of!((* ptr).Ccch) as usize - ptr as usize }, 9usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccch)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).Ccu) as usize - ptr as usize }, - 10usize, + unsafe { ::std::ptr::addr_of!((* ptr).Ccu) as usize - ptr as usize }, 10usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccu)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).Ccd) as usize - ptr as usize }, - 11usize, + unsafe { ::std::ptr::addr_of!((* ptr).Ccd) as usize - ptr as usize }, 11usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccd)) ); } diff --git a/bindgen-tests/tests/expectations/tests/class.rs b/bindgen-tests/tests/expectations/tests/class.rs index 8542135b07..34051571bf 100644 --- a/bindgen-tests/tests/expectations/tests/class.rs +++ b/bindgen-tests/tests/expectations/tests/class.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Default)] pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); @@ -43,35 +37,21 @@ pub struct C { } #[test] fn bindgen_test_layout_C() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 40usize, - concat!("Size of: ", stringify!(C)) + ::std::mem::size_of:: < C > (), 40usize, concat!("Size of: ", stringify!(C)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C)) + ::std::mem::align_of:: < C > (), 4usize, concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(a)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(big_array) - ) + unsafe { ::std::ptr::addr_of!((* ptr).big_array) as usize - ptr as usize }, + 4usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(big_array)) ); } impl Default for C { @@ -91,53 +71,30 @@ pub struct C_with_zero_length_array { } #[test] fn bindgen_test_layout_C_with_zero_length_array() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 40usize, + ::std::mem::size_of:: < C_with_zero_length_array > (), 40usize, concat!("Size of: ", stringify!(C_with_zero_length_array)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < C_with_zero_length_array > (), 4usize, concat!("Alignment of ", stringify!(C_with_zero_length_array)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(C_with_zero_length_array), "::", + stringify!(a)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(big_array) - ) + unsafe { ::std::ptr::addr_of!((* ptr).big_array) as usize - ptr as usize }, + 4usize, concat!("Offset of field: ", stringify!(C_with_zero_length_array), "::", + stringify!(big_array)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize - }, - 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(zero_length_array) - ) + unsafe { ::std::ptr::addr_of!((* ptr).zero_length_array) as usize - ptr as usize + }, 37usize, concat!("Offset of field: ", stringify!(C_with_zero_length_array), + "::", stringify!(zero_length_array)) ); } impl Default for C_with_zero_length_array { @@ -157,41 +114,25 @@ pub struct C_with_zero_length_array_2 { } #[test] fn bindgen_test_layout_C_with_zero_length_array_2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, + ::std::mem::size_of:: < C_with_zero_length_array_2 > (), 4usize, concat!("Size of: ", stringify!(C_with_zero_length_array_2)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < C_with_zero_length_array_2 > (), 4usize, concat!("Alignment of ", stringify!(C_with_zero_length_array_2)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_2), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(C_with_zero_length_array_2), "::", + stringify!(a)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_2), - "::", - stringify!(zero_length_array) - ) + unsafe { ::std::ptr::addr_of!((* ptr).zero_length_array) as usize - ptr as usize + }, 4usize, concat!("Offset of field: ", stringify!(C_with_zero_length_array_2), + "::", stringify!(zero_length_array)) ); } #[repr(C)] @@ -203,13 +144,11 @@ pub struct C_with_incomplete_array { #[test] fn bindgen_test_layout_C_with_incomplete_array() { assert_eq!( - ::std::mem::size_of::(), - 40usize, + ::std::mem::size_of:: < C_with_incomplete_array > (), 40usize, concat!("Size of: ", stringify!(C_with_incomplete_array)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < C_with_incomplete_array > (), 4usize, concat!("Alignment of ", stringify!(C_with_incomplete_array)) ); } @@ -231,13 +170,11 @@ pub struct C_with_incomplete_array_2 { #[test] fn bindgen_test_layout_C_with_incomplete_array_2() { assert_eq!( - ::std::mem::size_of::(), - 4usize, + ::std::mem::size_of:: < C_with_incomplete_array_2 > (), 4usize, concat!("Size of: ", stringify!(C_with_incomplete_array_2)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < C_with_incomplete_array_2 > (), 4usize, concat!("Alignment of ", stringify!(C_with_incomplete_array_2)) ); } @@ -251,20 +188,14 @@ pub struct C_with_zero_length_array_and_incomplete_array { #[test] fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { assert_eq!( - ::std::mem::size_of::(), - 40usize, - concat!( - "Size of: ", - stringify!(C_with_zero_length_array_and_incomplete_array) - ) + ::std::mem::size_of:: < C_with_zero_length_array_and_incomplete_array > (), + 40usize, concat!("Size of: ", + stringify!(C_with_zero_length_array_and_incomplete_array)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!( - "Alignment of ", - stringify!(C_with_zero_length_array_and_incomplete_array) - ) + ::std::mem::align_of:: < C_with_zero_length_array_and_incomplete_array > (), + 4usize, concat!("Alignment of ", + stringify!(C_with_zero_length_array_and_incomplete_array)) ); } impl Default for C_with_zero_length_array_and_incomplete_array { @@ -286,22 +217,14 @@ pub struct C_with_zero_length_array_and_incomplete_array_2 { #[test] fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { assert_eq!( - ::std::mem::size_of::( - ), - 4usize, - concat!( - "Size of: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2) - ) + ::std::mem::size_of:: < C_with_zero_length_array_and_incomplete_array_2 > (), + 4usize, concat!("Size of: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2)) ); assert_eq!( - ::std::mem::align_of::( - ), - 4usize, - concat!( - "Alignment of ", - stringify!(C_with_zero_length_array_and_incomplete_array_2) - ) + ::std::mem::align_of:: < C_with_zero_length_array_and_incomplete_array_2 > (), + 4usize, concat!("Alignment of ", + stringify!(C_with_zero_length_array_and_incomplete_array_2)) ); } #[repr(C)] @@ -311,28 +234,19 @@ pub struct WithDtor { } #[test] fn bindgen_test_layout_WithDtor() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(WithDtor)) + ::std::mem::size_of:: < WithDtor > (), 4usize, concat!("Size of: ", + stringify!(WithDtor)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithDtor)) + ::std::mem::align_of:: < WithDtor > (), 4usize, concat!("Alignment of ", + stringify!(WithDtor)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithDtor), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(WithDtor), "::", stringify!(b)) ); } #[repr(C)] @@ -343,13 +257,11 @@ pub struct IncompleteArrayNonCopiable { #[test] fn bindgen_test_layout_IncompleteArrayNonCopiable() { assert_eq!( - ::std::mem::size_of::(), - 8usize, + ::std::mem::size_of:: < IncompleteArrayNonCopiable > (), 8usize, concat!("Size of: ", stringify!(IncompleteArrayNonCopiable)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, + ::std::mem::align_of:: < IncompleteArrayNonCopiable > (), 8usize, concat!("Alignment of ", stringify!(IncompleteArrayNonCopiable)) ); } @@ -370,27 +282,22 @@ pub union Union { } #[test] fn bindgen_test_layout_Union() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Union)) + ::std::mem::size_of:: < Union > (), 4usize, concat!("Size of: ", + stringify!(Union)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Union)) + ::std::mem::align_of:: < Union > (), 4usize, concat!("Alignment of ", + stringify!(Union)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).d) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Union), "::", stringify!(d)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).i) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Union), "::", stringify!(i)) ); } @@ -410,28 +317,19 @@ pub struct WithUnion { } #[test] fn bindgen_test_layout_WithUnion() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(WithUnion)) + ::std::mem::size_of:: < WithUnion > (), 4usize, concat!("Size of: ", + stringify!(WithUnion)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithUnion)) + ::std::mem::align_of:: < WithUnion > (), 4usize, concat!("Alignment of ", + stringify!(WithUnion)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithUnion), - "::", - stringify!(data) - ) + unsafe { ::std::ptr::addr_of!((* ptr).data) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(WithUnion), "::", stringify!(data)) ); } impl Default for WithUnion { @@ -451,17 +349,12 @@ pub struct RealAbstractionWithTonsOfMethods { #[test] fn bindgen_test_layout_RealAbstractionWithTonsOfMethods() { assert_eq!( - ::std::mem::size_of::(), - 1usize, + ::std::mem::size_of:: < RealAbstractionWithTonsOfMethods > (), 1usize, concat!("Size of: ", stringify!(RealAbstractionWithTonsOfMethods)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!( - "Alignment of ", - stringify!(RealAbstractionWithTonsOfMethods) - ) + ::std::mem::align_of:: < RealAbstractionWithTonsOfMethods > (), 1usize, + concat!("Alignment of ", stringify!(RealAbstractionWithTonsOfMethods)) ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/class_1_0.rs b/bindgen-tests/tests/expectations/tests/class_1_0.rs index f6c3021eb3..e36fd2fa5d 100644 --- a/bindgen-tests/tests/expectations/tests/class_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/class_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Default)] pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); @@ -86,35 +80,21 @@ pub struct C { } #[test] fn bindgen_test_layout_C() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 40usize, - concat!("Size of: ", stringify!(C)) + ::std::mem::size_of:: < C > (), 40usize, concat!("Size of: ", stringify!(C)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C)) + ::std::mem::align_of:: < C > (), 4usize, concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(a)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(big_array) - ) + unsafe { ::std::ptr::addr_of!((* ptr).big_array) as usize - ptr as usize }, + 4usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(big_array)) ); } impl Clone for C { @@ -144,53 +124,30 @@ pub struct C_with_zero_length_array { } #[test] fn bindgen_test_layout_C_with_zero_length_array() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 40usize, + ::std::mem::size_of:: < C_with_zero_length_array > (), 40usize, concat!("Size of: ", stringify!(C_with_zero_length_array)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < C_with_zero_length_array > (), 4usize, concat!("Alignment of ", stringify!(C_with_zero_length_array)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(C_with_zero_length_array), "::", + stringify!(a)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(big_array) - ) + unsafe { ::std::ptr::addr_of!((* ptr).big_array) as usize - ptr as usize }, + 4usize, concat!("Offset of field: ", stringify!(C_with_zero_length_array), "::", + stringify!(big_array)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize - }, - 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(zero_length_array) - ) + unsafe { ::std::ptr::addr_of!((* ptr).zero_length_array) as usize - ptr as usize + }, 37usize, concat!("Offset of field: ", stringify!(C_with_zero_length_array), + "::", stringify!(zero_length_array)) ); } impl Default for C_with_zero_length_array { @@ -210,41 +167,25 @@ pub struct C_with_zero_length_array_2 { } #[test] fn bindgen_test_layout_C_with_zero_length_array_2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, + ::std::mem::size_of:: < C_with_zero_length_array_2 > (), 4usize, concat!("Size of: ", stringify!(C_with_zero_length_array_2)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < C_with_zero_length_array_2 > (), 4usize, concat!("Alignment of ", stringify!(C_with_zero_length_array_2)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_2), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(C_with_zero_length_array_2), "::", + stringify!(a)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_2), - "::", - stringify!(zero_length_array) - ) + unsafe { ::std::ptr::addr_of!((* ptr).zero_length_array) as usize - ptr as usize + }, 4usize, concat!("Offset of field: ", stringify!(C_with_zero_length_array_2), + "::", stringify!(zero_length_array)) ); } #[repr(C)] @@ -256,13 +197,11 @@ pub struct C_with_incomplete_array { #[test] fn bindgen_test_layout_C_with_incomplete_array() { assert_eq!( - ::std::mem::size_of::(), - 40usize, + ::std::mem::size_of:: < C_with_incomplete_array > (), 40usize, concat!("Size of: ", stringify!(C_with_incomplete_array)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < C_with_incomplete_array > (), 4usize, concat!("Alignment of ", stringify!(C_with_incomplete_array)) ); } @@ -284,13 +223,11 @@ pub struct C_with_incomplete_array_2 { #[test] fn bindgen_test_layout_C_with_incomplete_array_2() { assert_eq!( - ::std::mem::size_of::(), - 4usize, + ::std::mem::size_of:: < C_with_incomplete_array_2 > (), 4usize, concat!("Size of: ", stringify!(C_with_incomplete_array_2)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < C_with_incomplete_array_2 > (), 4usize, concat!("Alignment of ", stringify!(C_with_incomplete_array_2)) ); } @@ -304,20 +241,14 @@ pub struct C_with_zero_length_array_and_incomplete_array { #[test] fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { assert_eq!( - ::std::mem::size_of::(), - 40usize, - concat!( - "Size of: ", - stringify!(C_with_zero_length_array_and_incomplete_array) - ) + ::std::mem::size_of:: < C_with_zero_length_array_and_incomplete_array > (), + 40usize, concat!("Size of: ", + stringify!(C_with_zero_length_array_and_incomplete_array)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!( - "Alignment of ", - stringify!(C_with_zero_length_array_and_incomplete_array) - ) + ::std::mem::align_of:: < C_with_zero_length_array_and_incomplete_array > (), + 4usize, concat!("Alignment of ", + stringify!(C_with_zero_length_array_and_incomplete_array)) ); } impl Default for C_with_zero_length_array_and_incomplete_array { @@ -339,22 +270,14 @@ pub struct C_with_zero_length_array_and_incomplete_array_2 { #[test] fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { assert_eq!( - ::std::mem::size_of::( - ), - 4usize, - concat!( - "Size of: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2) - ) + ::std::mem::size_of:: < C_with_zero_length_array_and_incomplete_array_2 > (), + 4usize, concat!("Size of: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2)) ); assert_eq!( - ::std::mem::align_of::( - ), - 4usize, - concat!( - "Alignment of ", - stringify!(C_with_zero_length_array_and_incomplete_array_2) - ) + ::std::mem::align_of:: < C_with_zero_length_array_and_incomplete_array_2 > (), + 4usize, concat!("Alignment of ", + stringify!(C_with_zero_length_array_and_incomplete_array_2)) ); } #[repr(C)] @@ -364,28 +287,19 @@ pub struct WithDtor { } #[test] fn bindgen_test_layout_WithDtor() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(WithDtor)) + ::std::mem::size_of:: < WithDtor > (), 4usize, concat!("Size of: ", + stringify!(WithDtor)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithDtor)) + ::std::mem::align_of:: < WithDtor > (), 4usize, concat!("Alignment of ", + stringify!(WithDtor)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithDtor), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(WithDtor), "::", stringify!(b)) ); } #[repr(C)] @@ -396,13 +310,11 @@ pub struct IncompleteArrayNonCopiable { #[test] fn bindgen_test_layout_IncompleteArrayNonCopiable() { assert_eq!( - ::std::mem::size_of::(), - 8usize, + ::std::mem::size_of:: < IncompleteArrayNonCopiable > (), 8usize, concat!("Size of: ", stringify!(IncompleteArrayNonCopiable)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, + ::std::mem::align_of:: < IncompleteArrayNonCopiable > (), 8usize, concat!("Alignment of ", stringify!(IncompleteArrayNonCopiable)) ); } @@ -424,27 +336,22 @@ pub struct Union { } #[test] fn bindgen_test_layout_Union() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Union)) + ::std::mem::size_of:: < Union > (), 4usize, concat!("Size of: ", + stringify!(Union)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Union)) + ::std::mem::align_of:: < Union > (), 4usize, concat!("Alignment of ", + stringify!(Union)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).d) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Union), "::", stringify!(d)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).i) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Union), "::", stringify!(i)) ); } @@ -460,28 +367,19 @@ pub struct WithUnion { } #[test] fn bindgen_test_layout_WithUnion() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(WithUnion)) + ::std::mem::size_of:: < WithUnion > (), 4usize, concat!("Size of: ", + stringify!(WithUnion)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithUnion)) + ::std::mem::align_of:: < WithUnion > (), 4usize, concat!("Alignment of ", + stringify!(WithUnion)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithUnion), - "::", - stringify!(data) - ) + unsafe { ::std::ptr::addr_of!((* ptr).data) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(WithUnion), "::", stringify!(data)) ); } impl Clone for WithUnion { @@ -497,17 +395,12 @@ pub struct RealAbstractionWithTonsOfMethods { #[test] fn bindgen_test_layout_RealAbstractionWithTonsOfMethods() { assert_eq!( - ::std::mem::size_of::(), - 1usize, + ::std::mem::size_of:: < RealAbstractionWithTonsOfMethods > (), 1usize, concat!("Size of: ", stringify!(RealAbstractionWithTonsOfMethods)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!( - "Alignment of ", - stringify!(RealAbstractionWithTonsOfMethods) - ) + ::std::mem::align_of:: < RealAbstractionWithTonsOfMethods > (), 1usize, + concat!("Alignment of ", stringify!(RealAbstractionWithTonsOfMethods)) ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/class_nested.rs b/bindgen-tests/tests/expectations/tests/class_nested.rs index f2cc8326f9..66700efc09 100644 --- a/bindgen-tests/tests/expectations/tests/class_nested.rs +++ b/bindgen-tests/tests/expectations/tests/class_nested.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct A { @@ -17,30 +11,18 @@ pub struct A_B { } #[test] fn bindgen_test_layout_A_B() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(A_B)) + ::std::mem::size_of:: < A_B > (), 4usize, concat!("Size of: ", stringify!(A_B)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(A_B)) + ::std::mem::align_of:: < A_B > (), 4usize, concat!("Alignment of ", + stringify!(A_B)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).member_b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(A_B), - "::", - stringify!(member_b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).member_b) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(A_B), "::", stringify!(member_b)) ); } #[repr(C)] @@ -60,30 +42,17 @@ impl Default for A_D { } #[test] fn bindgen_test_layout_A() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(A)) + ::std::mem::size_of:: < A > (), 4usize, concat!("Size of: ", stringify!(A)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(A)) + ::std::mem::align_of:: < A > (), 4usize, concat!("Alignment of ", stringify!(A)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).member_a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(A), - "::", - stringify!(member_a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).member_a) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(member_a)) ); } #[repr(C)] @@ -93,22 +62,17 @@ pub struct A_C { } #[test] fn bindgen_test_layout_A_C() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(A_C)) + ::std::mem::size_of:: < A_C > (), 4usize, concat!("Size of: ", stringify!(A_C)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(A_C)) + ::std::mem::align_of:: < A_C > (), 4usize, concat!("Alignment of ", + stringify!(A_C)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).baz) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(A_C), "::", stringify!(baz)) ); } @@ -118,20 +82,14 @@ extern "C" { #[test] fn __bindgen_test_layout_A_D_open0_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!( - "Size of template specialization: ", - stringify!(A_D<::std::os::raw::c_int>) - ) + ::std::mem::size_of:: < A_D < ::std::os::raw::c_int > > (), 4usize, + concat!("Size of template specialization: ", stringify!(A_D < + ::std::os::raw::c_int >)) ); assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(A_D<::std::os::raw::c_int>) - ) + ::std::mem::align_of:: < A_D < ::std::os::raw::c_int > > (), 4usize, + concat!("Alignment of template specialization: ", stringify!(A_D < + ::std::os::raw::c_int >)) ); } extern "C" { @@ -144,22 +102,16 @@ pub struct D { } #[test] fn bindgen_test_layout_D() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(D)) + ::std::mem::size_of:: < D > (), 4usize, concat!("Size of: ", stringify!(D)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(D)) + ::std::mem::align_of:: < D > (), 4usize, concat!("Alignment of ", stringify!(D)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).member) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(D), "::", stringify!(member)) ); } diff --git a/bindgen-tests/tests/expectations/tests/class_no_members.rs b/bindgen-tests/tests/expectations/tests/class_no_members.rs index 676590c829..32750cfbff 100644 --- a/bindgen-tests/tests/expectations/tests/class_no_members.rs +++ b/bindgen-tests/tests/expectations/tests/class_no_members.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct whatever { @@ -13,14 +7,12 @@ pub struct whatever { #[test] fn bindgen_test_layout_whatever() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(whatever)) + ::std::mem::size_of:: < whatever > (), 1usize, concat!("Size of: ", + stringify!(whatever)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(whatever)) + ::std::mem::align_of:: < whatever > (), 1usize, concat!("Alignment of ", + stringify!(whatever)) ); } #[repr(C)] @@ -31,14 +23,12 @@ pub struct whatever_child { #[test] fn bindgen_test_layout_whatever_child() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(whatever_child)) + ::std::mem::size_of:: < whatever_child > (), 1usize, concat!("Size of: ", + stringify!(whatever_child)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(whatever_child)) + ::std::mem::align_of:: < whatever_child > (), 1usize, concat!("Alignment of ", + stringify!(whatever_child)) ); } #[repr(C)] @@ -48,29 +38,19 @@ pub struct whatever_child_with_member { } #[test] fn bindgen_test_layout_whatever_child_with_member() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, + ::std::mem::size_of:: < whatever_child_with_member > (), 4usize, concat!("Size of: ", stringify!(whatever_child_with_member)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < whatever_child_with_member > (), 4usize, concat!("Alignment of ", stringify!(whatever_child_with_member)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(whatever_child_with_member), - "::", - stringify!(m_member) - ) + unsafe { ::std::ptr::addr_of!((* ptr).m_member) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(whatever_child_with_member), + "::", stringify!(m_member)) ); } diff --git a/bindgen-tests/tests/expectations/tests/class_static.rs b/bindgen-tests/tests/expectations/tests/class_static.rs index 2388f3b3a4..9ddc19c1ab 100644 --- a/bindgen-tests/tests/expectations/tests/class_static.rs +++ b/bindgen-tests/tests/expectations/tests/class_static.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct MyClass { @@ -16,20 +10,17 @@ extern "C" { } extern "C" { #[link_name = "\u{1}_ZN7MyClass26example_check_no_collisionE"] - pub static mut MyClass_example_check_no_collision: - *const ::std::os::raw::c_int; + pub static mut MyClass_example_check_no_collision: *const ::std::os::raw::c_int; } #[test] fn bindgen_test_layout_MyClass() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(MyClass)) + ::std::mem::size_of:: < MyClass > (), 1usize, concat!("Size of: ", + stringify!(MyClass)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(MyClass)) + ::std::mem::align_of:: < MyClass > (), 1usize, concat!("Alignment of ", + stringify!(MyClass)) ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/class_static_const.rs b/bindgen-tests/tests/expectations/tests/class_static_const.rs index 812d78e1ab..0f7635e640 100644 --- a/bindgen-tests/tests/expectations/tests/class_static_const.rs +++ b/bindgen-tests/tests/expectations/tests/class_static_const.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct A { @@ -16,13 +10,9 @@ pub const A_c: u32 = 255; #[test] fn bindgen_test_layout_A() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(A)) + ::std::mem::size_of:: < A > (), 1usize, concat!("Size of: ", stringify!(A)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(A)) + ::std::mem::align_of:: < A > (), 1usize, concat!("Alignment of ", stringify!(A)) ); } diff --git a/bindgen-tests/tests/expectations/tests/class_use_as.rs b/bindgen-tests/tests/expectations/tests/class_use_as.rs index ef130c16c6..46a0acff66 100644 --- a/bindgen-tests/tests/expectations/tests/class_use_as.rs +++ b/bindgen-tests/tests/expectations/tests/class_use_as.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] ///
#[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] @@ -13,30 +7,20 @@ pub struct whatever { } #[test] fn bindgen_test_layout_whatever() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(whatever)) + ::std::mem::size_of:: < whatever > (), 4usize, concat!("Size of: ", + stringify!(whatever)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(whatever)) + ::std::mem::align_of:: < whatever > (), 4usize, concat!("Alignment of ", + stringify!(whatever)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).replacement) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(whatever), - "::", - stringify!(replacement) - ) + unsafe { ::std::ptr::addr_of!((* ptr).replacement) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(whatever), "::", + stringify!(replacement)) ); } #[repr(C)] @@ -46,27 +30,18 @@ pub struct container { } #[test] fn bindgen_test_layout_container() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(container)) + ::std::mem::size_of:: < container > (), 4usize, concat!("Size of: ", + stringify!(container)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(container)) + ::std::mem::align_of:: < container > (), 4usize, concat!("Alignment of ", + stringify!(container)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(container), - "::", - stringify!(c) - ) + unsafe { ::std::ptr::addr_of!((* ptr).c) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(container), "::", stringify!(c)) ); } diff --git a/bindgen-tests/tests/expectations/tests/class_with_dtor.rs b/bindgen-tests/tests/expectations/tests/class_with_dtor.rs index 86d2a576db..4060cf5398 100644 --- a/bindgen-tests/tests/expectations/tests/class_with_dtor.rs +++ b/bindgen-tests/tests/expectations/tests/class_with_dtor.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Hash, PartialEq, Eq)] pub struct HandleWithDtor { @@ -28,31 +22,20 @@ pub struct WithoutDtor { } #[test] fn bindgen_test_layout_WithoutDtor() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(WithoutDtor)) + ::std::mem::size_of:: < WithoutDtor > (), 8usize, concat!("Size of: ", + stringify!(WithoutDtor)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(WithoutDtor)) + ::std::mem::align_of:: < WithoutDtor > (), 8usize, concat!("Alignment of ", + stringify!(WithoutDtor)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).shouldBeWithDtor) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithoutDtor), - "::", - stringify!(shouldBeWithDtor) - ) + unsafe { ::std::ptr::addr_of!((* ptr).shouldBeWithDtor) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(WithoutDtor), "::", + stringify!(shouldBeWithDtor)) ); } impl Default for WithoutDtor { @@ -67,19 +50,13 @@ impl Default for WithoutDtor { #[test] fn __bindgen_test_layout_HandleWithDtor_open0_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of::>(), - 8usize, - concat!( - "Size of template specialization: ", - stringify!(HandleWithDtor<::std::os::raw::c_int>) - ) + ::std::mem::size_of:: < HandleWithDtor < ::std::os::raw::c_int > > (), 8usize, + concat!("Size of template specialization: ", stringify!(HandleWithDtor < + ::std::os::raw::c_int >)) ); assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(HandleWithDtor<::std::os::raw::c_int>) - ) + ::std::mem::align_of:: < HandleWithDtor < ::std::os::raw::c_int > > (), 8usize, + concat!("Alignment of template specialization: ", stringify!(HandleWithDtor < + ::std::os::raw::c_int >)) ); } diff --git a/bindgen-tests/tests/expectations/tests/class_with_inner_struct.rs b/bindgen-tests/tests/expectations/tests/class_with_inner_struct.rs index eab9d59825..68e749b1d8 100644 --- a/bindgen-tests/tests/expectations/tests/class_with_inner_struct.rs +++ b/bindgen-tests/tests/expectations/tests/class_with_inner_struct.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone)] pub struct A { @@ -20,38 +14,23 @@ pub struct A_Segment { } #[test] fn bindgen_test_layout_A_Segment() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(A_Segment)) + ::std::mem::size_of:: < A_Segment > (), 8usize, concat!("Size of: ", + stringify!(A_Segment)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(A_Segment)) + ::std::mem::align_of:: < A_Segment > (), 4usize, concat!("Alignment of ", + stringify!(A_Segment)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(A_Segment), - "::", - stringify!(begin) - ) + unsafe { ::std::ptr::addr_of!((* ptr).begin) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(A_Segment), "::", stringify!(begin)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(A_Segment), - "::", - stringify!(end) - ) + unsafe { ::std::ptr::addr_of!((* ptr).end) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(A_Segment), "::", stringify!(end)) ); } #[repr(C)] @@ -61,28 +40,19 @@ pub union A__bindgen_ty_1 { } #[test] fn bindgen_test_layout_A__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(A__bindgen_ty_1)) + ::std::mem::size_of:: < A__bindgen_ty_1 > (), 4usize, concat!("Size of: ", + stringify!(A__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(A__bindgen_ty_1)) + ::std::mem::align_of:: < A__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", + stringify!(A__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(A__bindgen_ty_1), - "::", - stringify!(f) - ) + unsafe { ::std::ptr::addr_of!((* ptr).f) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(A__bindgen_ty_1), "::", stringify!(f)) ); } impl Default for A__bindgen_ty_1 { @@ -101,28 +71,19 @@ pub union A__bindgen_ty_2 { } #[test] fn bindgen_test_layout_A__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(A__bindgen_ty_2)) + ::std::mem::size_of:: < A__bindgen_ty_2 > (), 4usize, concat!("Size of: ", + stringify!(A__bindgen_ty_2)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(A__bindgen_ty_2)) + ::std::mem::align_of:: < A__bindgen_ty_2 > (), 4usize, concat!("Alignment of ", + stringify!(A__bindgen_ty_2)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(A__bindgen_ty_2), - "::", - stringify!(d) - ) + unsafe { ::std::ptr::addr_of!((* ptr).d) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(A__bindgen_ty_2), "::", stringify!(d)) ); } impl Default for A__bindgen_ty_2 { @@ -136,35 +97,22 @@ impl Default for A__bindgen_ty_2 { } #[test] fn bindgen_test_layout_A() { - const UNINIT: ::std::mem::MaybeUninit
= - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 12usize, - concat!("Size of: ", stringify!(A)) + ::std::mem::size_of:: < A > (), 12usize, concat!("Size of: ", stringify!(A)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(A)) + ::std::mem::align_of:: < A > (), 4usize, concat!("Alignment of ", stringify!(A)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).c) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(c)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).named_union) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(A), - "::", - stringify!(named_union) - ) + unsafe { ::std::ptr::addr_of!((* ptr).named_union) as usize - ptr as usize }, + 4usize, concat!("Offset of field: ", stringify!(A), "::", + stringify!(named_union)) ); } impl Default for A { @@ -189,58 +137,37 @@ pub struct B_Segment { } #[test] fn bindgen_test_layout_B_Segment() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(B_Segment)) + ::std::mem::size_of:: < B_Segment > (), 8usize, concat!("Size of: ", + stringify!(B_Segment)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(B_Segment)) + ::std::mem::align_of:: < B_Segment > (), 4usize, concat!("Alignment of ", + stringify!(B_Segment)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(B_Segment), - "::", - stringify!(begin) - ) + unsafe { ::std::ptr::addr_of!((* ptr).begin) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(B_Segment), "::", stringify!(begin)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(B_Segment), - "::", - stringify!(end) - ) + unsafe { ::std::ptr::addr_of!((* ptr).end) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(B_Segment), "::", stringify!(end)) ); } #[test] fn bindgen_test_layout_B() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(B)) + ::std::mem::size_of:: < B > (), 4usize, concat!("Size of: ", stringify!(B)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(B)) + ::std::mem::align_of:: < B > (), 4usize, concat!("Alignment of ", stringify!(B)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).d) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(B), "::", stringify!(d)) ); } @@ -274,58 +201,35 @@ pub struct C__bindgen_ty_1__bindgen_ty_1 { } #[test] fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 16usize, + ::std::mem::size_of:: < C__bindgen_ty_1__bindgen_ty_1 > (), 16usize, concat!("Size of: ", stringify!(C__bindgen_ty_1__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < C__bindgen_ty_1__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", stringify!(C__bindgen_ty_1__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mX1) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(mX1) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mY1) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(mY1) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mX2) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(mX2) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mY2) as usize - ptr as usize }, - 12usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(mY2) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mX1) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(C__bindgen_ty_1__bindgen_ty_1), "::", + stringify!(mX1)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).mY1) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(C__bindgen_ty_1__bindgen_ty_1), "::", + stringify!(mY1)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).mX2) as usize - ptr as usize }, 8usize, + concat!("Offset of field: ", stringify!(C__bindgen_ty_1__bindgen_ty_1), "::", + stringify!(mX2)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).mY2) as usize - ptr as usize }, 12usize, + concat!("Offset of field: ", stringify!(C__bindgen_ty_1__bindgen_ty_1), "::", + stringify!(mY2)) ); } #[repr(C)] @@ -336,40 +240,25 @@ pub struct C__bindgen_ty_1__bindgen_ty_2 { } #[test] fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, + ::std::mem::size_of:: < C__bindgen_ty_1__bindgen_ty_2 > (), 8usize, concat!("Size of: ", stringify!(C__bindgen_ty_1__bindgen_ty_2)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < C__bindgen_ty_1__bindgen_ty_2 > (), 4usize, concat!("Alignment of ", stringify!(C__bindgen_ty_1__bindgen_ty_2)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mStepSyntax) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(mStepSyntax) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mSteps) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(mSteps) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mStepSyntax) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(C__bindgen_ty_1__bindgen_ty_2), + "::", stringify!(mStepSyntax)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).mSteps) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(C__bindgen_ty_1__bindgen_ty_2), "::", + stringify!(mSteps)) ); } impl Default for C__bindgen_ty_1__bindgen_ty_2 { @@ -383,28 +272,20 @@ impl Default for C__bindgen_ty_1__bindgen_ty_2 { } #[test] fn bindgen_test_layout_C__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(C__bindgen_ty_1)) + ::std::mem::size_of:: < C__bindgen_ty_1 > (), 16usize, concat!("Size of: ", + stringify!(C__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C__bindgen_ty_1)) + ::std::mem::align_of:: < C__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", + stringify!(C__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mFunc) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1), - "::", - stringify!(mFunc) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mFunc) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(C__bindgen_ty_1), "::", + stringify!(mFunc)) ); } impl Default for C__bindgen_ty_1 { @@ -424,58 +305,37 @@ pub struct C_Segment { } #[test] fn bindgen_test_layout_C_Segment() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(C_Segment)) + ::std::mem::size_of:: < C_Segment > (), 8usize, concat!("Size of: ", + stringify!(C_Segment)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C_Segment)) + ::std::mem::align_of:: < C_Segment > (), 4usize, concat!("Alignment of ", + stringify!(C_Segment)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_Segment), - "::", - stringify!(begin) - ) + unsafe { ::std::ptr::addr_of!((* ptr).begin) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(C_Segment), "::", stringify!(begin)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_Segment), - "::", - stringify!(end) - ) + unsafe { ::std::ptr::addr_of!((* ptr).end) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(C_Segment), "::", stringify!(end)) ); } #[test] fn bindgen_test_layout_C() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 20usize, - concat!("Size of: ", stringify!(C)) + ::std::mem::size_of:: < C > (), 20usize, concat!("Size of: ", stringify!(C)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C)) + ::std::mem::align_of:: < C > (), 4usize, concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).d) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(d)) ); } diff --git a/bindgen-tests/tests/expectations/tests/class_with_inner_struct_1_0.rs b/bindgen-tests/tests/expectations/tests/class_with_inner_struct_1_0.rs index 42656079df..c1600618ba 100644 --- a/bindgen-tests/tests/expectations/tests/class_with_inner_struct_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/class_with_inner_struct_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -63,38 +57,23 @@ pub struct A_Segment { } #[test] fn bindgen_test_layout_A_Segment() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(A_Segment)) + ::std::mem::size_of:: < A_Segment > (), 8usize, concat!("Size of: ", + stringify!(A_Segment)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(A_Segment)) + ::std::mem::align_of:: < A_Segment > (), 4usize, concat!("Alignment of ", + stringify!(A_Segment)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(A_Segment), - "::", - stringify!(begin) - ) + unsafe { ::std::ptr::addr_of!((* ptr).begin) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(A_Segment), "::", stringify!(begin)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(A_Segment), - "::", - stringify!(end) - ) + unsafe { ::std::ptr::addr_of!((* ptr).end) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(A_Segment), "::", stringify!(end)) ); } impl Clone for A_Segment { @@ -110,28 +89,19 @@ pub struct A__bindgen_ty_1 { } #[test] fn bindgen_test_layout_A__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(A__bindgen_ty_1)) + ::std::mem::size_of:: < A__bindgen_ty_1 > (), 4usize, concat!("Size of: ", + stringify!(A__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(A__bindgen_ty_1)) + ::std::mem::align_of:: < A__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", + stringify!(A__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(A__bindgen_ty_1), - "::", - stringify!(f) - ) + unsafe { ::std::ptr::addr_of!((* ptr).f) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(A__bindgen_ty_1), "::", stringify!(f)) ); } impl Clone for A__bindgen_ty_1 { @@ -147,28 +117,19 @@ pub struct A__bindgen_ty_2 { } #[test] fn bindgen_test_layout_A__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(A__bindgen_ty_2)) + ::std::mem::size_of:: < A__bindgen_ty_2 > (), 4usize, concat!("Size of: ", + stringify!(A__bindgen_ty_2)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(A__bindgen_ty_2)) + ::std::mem::align_of:: < A__bindgen_ty_2 > (), 4usize, concat!("Alignment of ", + stringify!(A__bindgen_ty_2)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(A__bindgen_ty_2), - "::", - stringify!(d) - ) + unsafe { ::std::ptr::addr_of!((* ptr).d) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(A__bindgen_ty_2), "::", stringify!(d)) ); } impl Clone for A__bindgen_ty_2 { @@ -178,35 +139,22 @@ impl Clone for A__bindgen_ty_2 { } #[test] fn bindgen_test_layout_A() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 12usize, - concat!("Size of: ", stringify!(A)) + ::std::mem::size_of:: < A > (), 12usize, concat!("Size of: ", stringify!(A)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(A)) + ::std::mem::align_of:: < A > (), 4usize, concat!("Alignment of ", stringify!(A)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).c) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(c)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).named_union) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(A), - "::", - stringify!(named_union) - ) + unsafe { ::std::ptr::addr_of!((* ptr).named_union) as usize - ptr as usize }, + 4usize, concat!("Offset of field: ", stringify!(A), "::", + stringify!(named_union)) ); } impl Clone for A { @@ -227,38 +175,23 @@ pub struct B_Segment { } #[test] fn bindgen_test_layout_B_Segment() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(B_Segment)) + ::std::mem::size_of:: < B_Segment > (), 8usize, concat!("Size of: ", + stringify!(B_Segment)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(B_Segment)) + ::std::mem::align_of:: < B_Segment > (), 4usize, concat!("Alignment of ", + stringify!(B_Segment)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(B_Segment), - "::", - stringify!(begin) - ) + unsafe { ::std::ptr::addr_of!((* ptr).begin) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(B_Segment), "::", stringify!(begin)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(B_Segment), - "::", - stringify!(end) - ) + unsafe { ::std::ptr::addr_of!((* ptr).end) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(B_Segment), "::", stringify!(end)) ); } impl Clone for B_Segment { @@ -268,22 +201,16 @@ impl Clone for B_Segment { } #[test] fn bindgen_test_layout_B() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(B)) + ::std::mem::size_of:: < B > (), 4usize, concat!("Size of: ", stringify!(B)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(B)) + ::std::mem::align_of:: < B > (), 4usize, concat!("Alignment of ", stringify!(B)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).d) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(B), "::", stringify!(d)) ); } @@ -323,58 +250,35 @@ pub struct C__bindgen_ty_1__bindgen_ty_1 { } #[test] fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 16usize, + ::std::mem::size_of:: < C__bindgen_ty_1__bindgen_ty_1 > (), 16usize, concat!("Size of: ", stringify!(C__bindgen_ty_1__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < C__bindgen_ty_1__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", stringify!(C__bindgen_ty_1__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mX1) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(mX1) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mX1) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(C__bindgen_ty_1__bindgen_ty_1), "::", + stringify!(mX1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mY1) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(mY1) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mY1) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(C__bindgen_ty_1__bindgen_ty_1), "::", + stringify!(mY1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mX2) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(mX2) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mX2) as usize - ptr as usize }, 8usize, + concat!("Offset of field: ", stringify!(C__bindgen_ty_1__bindgen_ty_1), "::", + stringify!(mX2)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mY2) as usize - ptr as usize }, - 12usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(mY2) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mY2) as usize - ptr as usize }, 12usize, + concat!("Offset of field: ", stringify!(C__bindgen_ty_1__bindgen_ty_1), "::", + stringify!(mY2)) ); } impl Clone for C__bindgen_ty_1__bindgen_ty_1 { @@ -390,40 +294,25 @@ pub struct C__bindgen_ty_1__bindgen_ty_2 { } #[test] fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, + ::std::mem::size_of:: < C__bindgen_ty_1__bindgen_ty_2 > (), 8usize, concat!("Size of: ", stringify!(C__bindgen_ty_1__bindgen_ty_2)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < C__bindgen_ty_1__bindgen_ty_2 > (), 4usize, concat!("Alignment of ", stringify!(C__bindgen_ty_1__bindgen_ty_2)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mStepSyntax) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(mStepSyntax) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mSteps) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(mSteps) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mStepSyntax) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(C__bindgen_ty_1__bindgen_ty_2), + "::", stringify!(mStepSyntax)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).mSteps) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(C__bindgen_ty_1__bindgen_ty_2), "::", + stringify!(mSteps)) ); } impl Clone for C__bindgen_ty_1__bindgen_ty_2 { @@ -442,28 +331,20 @@ impl Default for C__bindgen_ty_1__bindgen_ty_2 { } #[test] fn bindgen_test_layout_C__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(C__bindgen_ty_1)) + ::std::mem::size_of:: < C__bindgen_ty_1 > (), 16usize, concat!("Size of: ", + stringify!(C__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C__bindgen_ty_1)) + ::std::mem::align_of:: < C__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", + stringify!(C__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mFunc) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1), - "::", - stringify!(mFunc) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mFunc) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(C__bindgen_ty_1), "::", + stringify!(mFunc)) ); } impl Clone for C__bindgen_ty_1 { @@ -479,38 +360,23 @@ pub struct C_Segment { } #[test] fn bindgen_test_layout_C_Segment() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(C_Segment)) + ::std::mem::size_of:: < C_Segment > (), 8usize, concat!("Size of: ", + stringify!(C_Segment)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C_Segment)) + ::std::mem::align_of:: < C_Segment > (), 4usize, concat!("Alignment of ", + stringify!(C_Segment)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_Segment), - "::", - stringify!(begin) - ) + unsafe { ::std::ptr::addr_of!((* ptr).begin) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(C_Segment), "::", stringify!(begin)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_Segment), - "::", - stringify!(end) - ) + unsafe { ::std::ptr::addr_of!((* ptr).end) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(C_Segment), "::", stringify!(end)) ); } impl Clone for C_Segment { @@ -520,22 +386,16 @@ impl Clone for C_Segment { } #[test] fn bindgen_test_layout_C() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 20usize, - concat!("Size of: ", stringify!(C)) + ::std::mem::size_of:: < C > (), 20usize, concat!("Size of: ", stringify!(C)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C)) + ::std::mem::align_of:: < C > (), 4usize, concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).d) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(d)) ); } diff --git a/bindgen-tests/tests/expectations/tests/class_with_typedef.rs b/bindgen-tests/tests/expectations/tests/class_with_typedef.rs index 65e86b2709..e2e8d9e99e 100644 --- a/bindgen-tests/tests/expectations/tests/class_with_typedef.rs +++ b/bindgen-tests/tests/expectations/tests/class_with_typedef.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type AnotherInt = ::std::os::raw::c_int; #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] @@ -19,50 +13,33 @@ pub type C_MyInt = ::std::os::raw::c_int; pub type C_Lookup = *const ::std::os::raw::c_char; #[test] fn bindgen_test_layout_C() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 72usize, - concat!("Size of: ", stringify!(C)) + ::std::mem::size_of:: < C > (), 72usize, concat!("Size of: ", stringify!(C)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(C)) + ::std::mem::align_of:: < C > (), 8usize, concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).c) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(c)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize }, - 8usize, + unsafe { ::std::ptr::addr_of!((* ptr).ptr) as usize - ptr as usize }, 8usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(ptr)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize }, - 16usize, + unsafe { ::std::ptr::addr_of!((* ptr).arr) as usize - ptr as usize }, 16usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(arr)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 56usize, + unsafe { ::std::ptr::addr_of!((* ptr).d) as usize - ptr as usize }, 56usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(d)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).other_ptr) as usize - ptr as usize - }, - 64usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(other_ptr) - ) + unsafe { ::std::ptr::addr_of!((* ptr).other_ptr) as usize - ptr as usize }, + 64usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(other_ptr)) ); } extern "C" { @@ -116,22 +93,16 @@ pub struct D { } #[test] fn bindgen_test_layout_D() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 80usize, - concat!("Size of: ", stringify!(D)) + ::std::mem::size_of:: < D > (), 80usize, concat!("Size of: ", stringify!(D)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(D)) + ::std::mem::align_of:: < D > (), 8usize, concat!("Alignment of ", stringify!(D)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize }, - 72usize, + unsafe { ::std::ptr::addr_of!((* ptr).ptr) as usize - ptr as usize }, 72usize, concat!("Offset of field: ", stringify!(D), "::", stringify!(ptr)) ); } diff --git a/bindgen-tests/tests/expectations/tests/comment-indent.rs b/bindgen-tests/tests/expectations/tests/comment-indent.rs index 3ad221aa3d..a99269fcf2 100644 --- a/bindgen-tests/tests/expectations/tests/comment-indent.rs +++ b/bindgen-tests/tests/expectations/tests/comment-indent.rs @@ -1,25 +1,19 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![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 { #[allow(unused_imports)] use self::super::root; - /// This is a multi-line doc comment. - /// - /// This class is really really interesting, look! + /** This is a multi-line doc comment. + + This class is really really interesting, look!*/ #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { pub _address: u8, } - /// This nested class is also a multi-line doc comment. - /// - /// This class is not so interesting, but worth a bit of docs too! + /** This nested class is also a multi-line doc comment. + + This class is not so interesting, but worth a bit of docs too!*/ #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo_Bar { @@ -28,77 +22,63 @@ pub mod root { #[test] fn bindgen_test_layout_Foo_Bar() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo_Bar)) + ::std::mem::size_of:: < Foo_Bar > (), 1usize, concat!("Size of: ", + stringify!(Foo_Bar)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo_Bar)) + ::std::mem::align_of:: < Foo_Bar > (), 1usize, concat!("Alignment of ", + stringify!(Foo_Bar)) ); } #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", + stringify!(Foo)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) + ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", + stringify!(Foo)) ); } pub mod test { #[allow(unused_imports)] use self::super::super::root; - /// I'm in a namespace, and thus I may be on a rust module, most of the time. - /// My documentation is pretty extensive, I guess. + /** I'm in a namespace, and thus I may be on a rust module, most of the time. + My documentation is pretty extensive, I guess.*/ #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Baz { - /// This member is plain awesome, just amazing. - /// - /// It also has super-extensive docs, with even a nice ascii-art diagram. - /// - /// +------+ +-------+ - /// | foo | ----> | bar | - /// +------+ +-------+ + /** This member is plain awesome, just amazing. + + It also has super-extensive docs, with even a nice ascii-art diagram. + + +------+ +-------+ + | foo | ----> | bar | + +------+ +-------+*/ pub member: ::std::os::raw::c_int, } #[test] fn bindgen_test_layout_Baz() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Baz)) + ::std::mem::size_of:: < Baz > (), 4usize, concat!("Size of: ", + stringify!(Baz)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Baz)) + ::std::mem::align_of:: < Baz > (), 4usize, concat!("Alignment of ", + stringify!(Baz)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Baz), - "::", - stringify!(member) - ) + unsafe { ::std::ptr::addr_of!((* ptr).member) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(Baz), "::", + stringify!(member)) ); } - /// I'm in an inline namespace, and as such I shouldn't get generated inside - /// a rust module, except when the relevant option is specified. Also, this - /// comment shouldn't be misaligned. + /** I'm in an inline namespace, and as such I shouldn't get generated inside + a rust module, except when the relevant option is specified. Also, this + comment shouldn't be misaligned.*/ #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct InInlineNS { @@ -107,13 +87,11 @@ pub mod root { #[test] fn bindgen_test_layout_InInlineNS() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(InInlineNS)) + ::std::mem::size_of:: < InInlineNS > (), 1usize, concat!("Size of: ", + stringify!(InInlineNS)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < InInlineNS > (), 1usize, concat!("Alignment of ", stringify!(InInlineNS)) ); } @@ -125,14 +103,12 @@ pub mod root { #[test] fn bindgen_test_layout_Bazz() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Bazz)) + ::std::mem::size_of:: < Bazz > (), 1usize, concat!("Size of: ", + stringify!(Bazz)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Bazz)) + ::std::mem::align_of:: < Bazz > (), 1usize, concat!("Alignment of ", + stringify!(Bazz)) ); } } diff --git a/bindgen-tests/tests/expectations/tests/complex.rs b/bindgen-tests/tests/expectations/tests/complex.rs index e9c4be9d44..4bf0280da6 100644 --- a/bindgen-tests/tests/expectations/tests/complex.rs +++ b/bindgen-tests/tests/expectations/tests/complex.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[derive(PartialEq, Copy, Clone, Hash, Debug, Default)] #[repr(C)] pub struct __BindgenComplex { @@ -18,28 +12,19 @@ pub struct TestDouble { } #[test] fn bindgen_test_layout_TestDouble() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(TestDouble)) + ::std::mem::size_of:: < TestDouble > (), 16usize, concat!("Size of: ", + stringify!(TestDouble)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(TestDouble)) + ::std::mem::align_of:: < TestDouble > (), 8usize, concat!("Alignment of ", + stringify!(TestDouble)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(TestDouble), - "::", - stringify!(mMember) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mMember) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(TestDouble), "::", stringify!(mMember)) ); } #[repr(C)] @@ -49,28 +34,20 @@ pub struct TestDoublePtr { } #[test] fn bindgen_test_layout_TestDoublePtr() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(TestDoublePtr)) + ::std::mem::size_of:: < TestDoublePtr > (), 8usize, concat!("Size of: ", + stringify!(TestDoublePtr)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(TestDoublePtr)) + ::std::mem::align_of:: < TestDoublePtr > (), 8usize, concat!("Alignment of ", + stringify!(TestDoublePtr)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(TestDoublePtr), - "::", - stringify!(mMember) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mMember) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(TestDoublePtr), "::", + stringify!(mMember)) ); } impl Default for TestDoublePtr { @@ -89,28 +66,19 @@ pub struct TestFloat { } #[test] fn bindgen_test_layout_TestFloat() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(TestFloat)) + ::std::mem::size_of:: < TestFloat > (), 8usize, concat!("Size of: ", + stringify!(TestFloat)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(TestFloat)) + ::std::mem::align_of:: < TestFloat > (), 4usize, concat!("Alignment of ", + stringify!(TestFloat)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(TestFloat), - "::", - stringify!(mMember) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mMember) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(TestFloat), "::", stringify!(mMember)) ); } #[repr(C)] @@ -120,28 +88,19 @@ pub struct TestFloatPtr { } #[test] fn bindgen_test_layout_TestFloatPtr() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(TestFloatPtr)) + ::std::mem::size_of:: < TestFloatPtr > (), 8usize, concat!("Size of: ", + stringify!(TestFloatPtr)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(TestFloatPtr)) + ::std::mem::align_of:: < TestFloatPtr > (), 8usize, concat!("Alignment of ", + stringify!(TestFloatPtr)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(TestFloatPtr), - "::", - stringify!(mMember) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mMember) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(TestFloatPtr), "::", stringify!(mMember)) ); } impl Default for TestFloatPtr { diff --git a/bindgen-tests/tests/expectations/tests/complex_global.rs b/bindgen-tests/tests/expectations/tests/complex_global.rs index f21735da53..101ad0f49f 100644 --- a/bindgen-tests/tests/expectations/tests/complex_global.rs +++ b/bindgen-tests/tests/expectations/tests/complex_global.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[derive(PartialEq, Copy, Clone, Hash, Debug, Default)] #[repr(C)] pub struct __BindgenComplex { diff --git a/bindgen-tests/tests/expectations/tests/const-const-mut-ptr.rs b/bindgen-tests/tests/expectations/tests/const-const-mut-ptr.rs index e8f13dff82..374b5194ae 100644 --- a/bindgen-tests/tests/expectations/tests/const-const-mut-ptr.rs +++ b/bindgen-tests/tests/expectations/tests/const-const-mut-ptr.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct foo { @@ -12,22 +6,17 @@ pub struct foo { } #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of:: < foo > (), 8usize, concat!("Size of: ", stringify!(foo)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(foo)) + ::std::mem::align_of:: < foo > (), 8usize, concat!("Alignment of ", + stringify!(foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); } diff --git a/bindgen-tests/tests/expectations/tests/const_array.rs b/bindgen-tests/tests/expectations/tests/const_array.rs index 191bac9c3f..8dae42d116 100644 --- a/bindgen-tests/tests/expectations/tests/const_array.rs +++ b/bindgen-tests/tests/expectations/tests/const_array.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub static foo: [::std::os::raw::c_int; 1usize]; } diff --git a/bindgen-tests/tests/expectations/tests/const_array_fn_arg.rs b/bindgen-tests/tests/expectations/tests/const_array_fn_arg.rs index 3286dce1be..035a56fa78 100644 --- a/bindgen-tests/tests/expectations/tests/const_array_fn_arg.rs +++ b/bindgen-tests/tests/expectations/tests/const_array_fn_arg.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub fn f(a: *const ::std::os::raw::c_int); } diff --git a/bindgen-tests/tests/expectations/tests/const_enum_unnamed.rs b/bindgen-tests/tests/expectations/tests/const_enum_unnamed.rs index da0ec2b82d..0c3462dc47 100644 --- a/bindgen-tests/tests/expectations/tests/const_enum_unnamed.rs +++ b/bindgen-tests/tests/expectations/tests/const_enum_unnamed.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const FOO_BAR: _bindgen_ty_1 = _bindgen_ty_1::FOO_BAR; pub const FOO_BAZ: _bindgen_ty_1 = _bindgen_ty_1::FOO_BAZ; #[repr(u32)] @@ -27,13 +21,10 @@ pub enum Foo__bindgen_ty_1 { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) + ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", + stringify!(Foo)) ); } diff --git a/bindgen-tests/tests/expectations/tests/const_multidim_array_fn_arg.rs b/bindgen-tests/tests/expectations/tests/const_multidim_array_fn_arg.rs index 11ae184d85..0c4670b0ed 100644 --- a/bindgen-tests/tests/expectations/tests/const_multidim_array_fn_arg.rs +++ b/bindgen-tests/tests/expectations/tests/const_multidim_array_fn_arg.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub fn f(a: *const [::std::os::raw::c_int; 1usize]); } diff --git a/bindgen-tests/tests/expectations/tests/const_ptr.rs b/bindgen-tests/tests/expectations/tests/const_ptr.rs index 0087aa99ee..c08aa73d7e 100644 --- a/bindgen-tests/tests/expectations/tests/const_ptr.rs +++ b/bindgen-tests/tests/expectations/tests/const_ptr.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub fn foo(bar: *const ::std::os::raw::c_void); } diff --git a/bindgen-tests/tests/expectations/tests/const_resolved_ty.rs b/bindgen-tests/tests/expectations/tests/const_resolved_ty.rs index 66939ef932..20a124b474 100644 --- a/bindgen-tests/tests/expectations/tests/const_resolved_ty.rs +++ b/bindgen-tests/tests/expectations/tests/const_resolved_ty.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub fn foo(foo: *const u8); } diff --git a/bindgen-tests/tests/expectations/tests/const_tparam.rs b/bindgen-tests/tests/expectations/tests/const_tparam.rs index ec256872df..12c0c2e509 100644 --- a/bindgen-tests/tests/expectations/tests/const_tparam.rs +++ b/bindgen-tests/tests/expectations/tests/const_tparam.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct C { diff --git a/bindgen-tests/tests/expectations/tests/constant-non-specialized-tp.rs b/bindgen-tests/tests/expectations/tests/constant-non-specialized-tp.rs index 6c1e3d382a..968ec350aa 100644 --- a/bindgen-tests/tests/expectations/tests/constant-non-specialized-tp.rs +++ b/bindgen-tests/tests/expectations/tests/constant-non-specialized-tp.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Test { diff --git a/bindgen-tests/tests/expectations/tests/constified-enum-module-overflow.rs b/bindgen-tests/tests/expectations/tests/constified-enum-module-overflow.rs index d47338f142..67c8fa9746 100644 --- a/bindgen-tests/tests/expectations/tests/constified-enum-module-overflow.rs +++ b/bindgen-tests/tests/expectations/tests/constified-enum-module-overflow.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct B { @@ -23,35 +17,27 @@ pub struct A { } #[test] fn bindgen_test_layout_A() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(A)) + ::std::mem::size_of:: < A > (), 1usize, concat!("Size of: ", stringify!(A)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(A)) + ::std::mem::align_of:: < A > (), 1usize, concat!("Alignment of ", stringify!(A)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).u) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(u)) ); } #[test] fn __bindgen_test_layout_C_open0_A_close0_instantiation() { assert_eq!( - ::std::mem::size_of::(), - 1usize, + ::std::mem::size_of:: < C > (), 1usize, concat!("Size of template specialization: ", stringify!(C)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < C > (), 1usize, concat!("Alignment of template specialization: ", stringify!(C)) ); } diff --git a/bindgen-tests/tests/expectations/tests/constify-all-enums.rs b/bindgen-tests/tests/expectations/tests/constify-all-enums.rs index e3c82156f5..6e2a1963c6 100644 --- a/bindgen-tests/tests/expectations/tests/constify-all-enums.rs +++ b/bindgen-tests/tests/expectations/tests/constify-all-enums.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const foo_THIS: foo = 0; pub const foo_SHOULD_BE: foo = 1; pub const foo_A_CONSTANT: foo = 2; @@ -16,31 +10,19 @@ pub struct bar { } #[test] fn bindgen_test_layout_bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(bar)) + ::std::mem::size_of:: < bar > (), 4usize, concat!("Size of: ", stringify!(bar)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(bar)) + ::std::mem::align_of:: < bar > (), 4usize, concat!("Alignment of ", + stringify!(bar)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).this_should_work) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(this_should_work) - ) + unsafe { ::std::ptr::addr_of!((* ptr).this_should_work) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(bar), "::", + stringify!(this_should_work)) ); } impl Default for bar { diff --git a/bindgen-tests/tests/expectations/tests/constify-enum.rs b/bindgen-tests/tests/expectations/tests/constify-enum.rs index 091743e945..67d2749c51 100644 --- a/bindgen-tests/tests/expectations/tests/constify-enum.rs +++ b/bindgen-tests/tests/expectations/tests/constify-enum.rs @@ -1,16 +1,7 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -pub const nsCSSPropertyID_eCSSProperty_COUNT_unexistingVariantValue: - nsCSSPropertyID = - nsCSSPropertyID::eCSSProperty_COUNT_unexistingVariantValue; +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub const nsCSSPropertyID_eCSSProperty_COUNT_unexistingVariantValue: nsCSSPropertyID = nsCSSPropertyID::eCSSProperty_COUNT_unexistingVariantValue; impl nsCSSPropertyID { - pub const eCSSProperty_COUNT: nsCSSPropertyID = - nsCSSPropertyID::eCSSPropertyAlias_aa; + pub const eCSSProperty_COUNT: nsCSSPropertyID = nsCSSPropertyID::eCSSPropertyAlias_aa; } #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] diff --git a/bindgen-tests/tests/expectations/tests/constify-module-enums-basic.rs b/bindgen-tests/tests/expectations/tests/constify-module-enums-basic.rs index c5c32983b0..cce1da523b 100644 --- a/bindgen-tests/tests/expectations/tests/constify-module-enums-basic.rs +++ b/bindgen-tests/tests/expectations/tests/constify-module-enums-basic.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod foo { pub type Type = ::std::os::raw::c_uint; pub const THIS: Type = 0; @@ -20,31 +14,19 @@ pub struct bar { } #[test] fn bindgen_test_layout_bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(bar)) + ::std::mem::size_of:: < bar > (), 4usize, concat!("Size of: ", stringify!(bar)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(bar)) + ::std::mem::align_of:: < bar > (), 4usize, concat!("Alignment of ", + stringify!(bar)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).this_should_work) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(this_should_work) - ) + unsafe { ::std::ptr::addr_of!((* ptr).this_should_work) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(bar), "::", + stringify!(this_should_work)) ); } impl Default for bar { diff --git a/bindgen-tests/tests/expectations/tests/constify-module-enums-namespace.rs b/bindgen-tests/tests/expectations/tests/constify-module-enums-namespace.rs index 0b8eec1eab..e2634dbf22 100644 --- a/bindgen-tests/tests/expectations/tests/constify-module-enums-namespace.rs +++ b/bindgen-tests/tests/expectations/tests/constify-module-enums-namespace.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![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 { #[allow(unused_imports)] @@ -32,31 +26,20 @@ pub mod root { } #[test] fn bindgen_test_layout_bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(bar)) + ::std::mem::size_of:: < bar > (), 4usize, concat!("Size of: ", + stringify!(bar)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(bar)) + ::std::mem::align_of:: < bar > (), 4usize, concat!("Alignment of ", + stringify!(bar)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).this_should_work) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(this_should_work) - ) + unsafe { ::std::ptr::addr_of!((* ptr).this_should_work) as usize - + ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(bar), + "::", stringify!(this_should_work)) ); } impl Default for bar { diff --git a/bindgen-tests/tests/expectations/tests/constify-module-enums-shadow-name.rs b/bindgen-tests/tests/expectations/tests/constify-module-enums-shadow-name.rs index 44643d0fff..464a2d0631 100644 --- a/bindgen-tests/tests/expectations/tests/constify-module-enums-shadow-name.rs +++ b/bindgen-tests/tests/expectations/tests/constify-module-enums-shadow-name.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod foo { pub type Type = ::std::os::raw::c_uint; pub const Type: Type = 0; @@ -19,28 +13,18 @@ pub struct bar { } #[test] fn bindgen_test_layout_bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(bar)) + ::std::mem::size_of:: < bar > (), 4usize, concat!("Size of: ", stringify!(bar)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(bar)) + ::std::mem::align_of:: < bar > (), 4usize, concat!("Alignment of ", + stringify!(bar)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(member) - ) + unsafe { ::std::ptr::addr_of!((* ptr).member) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(bar), "::", stringify!(member)) ); } impl Default for bar { diff --git a/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-alias.rs b/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-alias.rs index 0262b128e4..38feeb651c 100644 --- a/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-alias.rs +++ b/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-alias.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod Foo { pub type Type = ::std::os::raw::c_int; pub const Variant1: Type = 0; @@ -28,86 +22,50 @@ pub struct Bar { } #[test] fn bindgen_test_layout_Bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 48usize, - concat!("Size of: ", stringify!(Bar)) + ::std::mem::size_of:: < Bar > (), 48usize, concat!("Size of: ", stringify!(Bar)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Bar)) + ::std::mem::align_of:: < Bar > (), 8usize, concat!("Alignment of ", + stringify!(Bar)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz1) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).baz1) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz2) as usize - ptr as usize }, - 4usize, + unsafe { ::std::ptr::addr_of!((* ptr).baz2) as usize - ptr as usize }, 4usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz2)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz3) as usize - ptr as usize }, - 8usize, + unsafe { ::std::ptr::addr_of!((* ptr).baz3) as usize - ptr as usize }, 8usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz3)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz4) as usize - ptr as usize }, - 12usize, + unsafe { ::std::ptr::addr_of!((* ptr).baz4) as usize - ptr as usize }, 12usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz4)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).baz_ptr1) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(baz_ptr1) - ) + unsafe { ::std::ptr::addr_of!((* ptr).baz_ptr1) as usize - ptr as usize }, + 16usize, concat!("Offset of field: ", stringify!(Bar), "::", + stringify!(baz_ptr1)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).baz_ptr2) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(baz_ptr2) - ) + unsafe { ::std::ptr::addr_of!((* ptr).baz_ptr2) as usize - ptr as usize }, + 24usize, concat!("Offset of field: ", stringify!(Bar), "::", + stringify!(baz_ptr2)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).baz_ptr3) as usize - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(baz_ptr3) - ) + unsafe { ::std::ptr::addr_of!((* ptr).baz_ptr3) as usize - ptr as usize }, + 32usize, concat!("Offset of field: ", stringify!(Bar), "::", + stringify!(baz_ptr3)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).baz_ptr4) as usize - ptr as usize - }, - 40usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(baz_ptr4) - ) + unsafe { ::std::ptr::addr_of!((* ptr).baz_ptr4) as usize - ptr as usize }, + 40usize, concat!("Offset of field: ", stringify!(Bar), "::", + stringify!(baz_ptr4)) ); } impl Default for Bar { diff --git a/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs b/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs index 75ebf48acf..fd629d86fd 100644 --- a/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs +++ b/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod one_Foo { pub type Type = ::std::os::raw::c_int; pub const Variant1: Type = 0; @@ -18,27 +12,21 @@ pub struct Bar { } #[test] fn bindgen_test_layout_Bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(Bar)) + ::std::mem::size_of:: < Bar > (), 16usize, concat!("Size of: ", stringify!(Bar)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Bar)) + ::std::mem::align_of:: < Bar > (), 8usize, concat!("Alignment of ", + stringify!(Bar)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz1) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).baz1) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz2) as usize - ptr as usize }, - 8usize, + unsafe { ::std::ptr::addr_of!((* ptr).baz2) as usize - ptr as usize }, 8usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz2)) ); } diff --git a/bindgen-tests/tests/expectations/tests/constify-module-enums-types.rs b/bindgen-tests/tests/expectations/tests/constify-module-enums-types.rs index c3c6d3ca00..610024b358 100644 --- a/bindgen-tests/tests/expectations/tests/constify-module-enums-types.rs +++ b/bindgen-tests/tests/expectations/tests/constify-module-enums-types.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod foo { pub type Type = ::std::os::raw::c_uint; pub const THIS: Type = 0; @@ -31,12 +25,12 @@ pub mod ns2_Foo { pub const Variant1: Type = 0; pub const Variant2: Type = 1; } -pub use self::anon_enum::Type as anon_enum_alias1; -pub use self::anon_enum_alias1 as anon_enum_alias2; -pub use self::anon_enum_alias2 as anon_enum_alias3; pub use self::foo::Type as foo_alias1; pub use self::foo_alias1 as foo_alias2; pub use self::foo_alias2 as foo_alias3; +pub use self::anon_enum::Type as anon_enum_alias1; +pub use self::anon_enum_alias1 as anon_enum_alias2; +pub use self::anon_enum_alias2 as anon_enum_alias3; #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct bar { @@ -53,120 +47,55 @@ pub struct bar { } #[test] fn bindgen_test_layout_bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 48usize, - concat!("Size of: ", stringify!(bar)) + ::std::mem::size_of:: < bar > (), 48usize, concat!("Size of: ", stringify!(bar)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(bar)) + ::std::mem::align_of:: < bar > (), 8usize, concat!("Alignment of ", + stringify!(bar)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member1) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(member1) - ) + unsafe { ::std::ptr::addr_of!((* ptr).member1) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(bar), "::", stringify!(member1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member2) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(member2) - ) + unsafe { ::std::ptr::addr_of!((* ptr).member2) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(bar), "::", stringify!(member2)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member3) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(member3) - ) + unsafe { ::std::ptr::addr_of!((* ptr).member3) as usize - ptr as usize }, 8usize, + concat!("Offset of field: ", stringify!(bar), "::", stringify!(member3)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member4) as usize - ptr as usize }, - 12usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(member4) - ) + unsafe { ::std::ptr::addr_of!((* ptr).member4) as usize - ptr as usize }, + 12usize, concat!("Offset of field: ", stringify!(bar), "::", stringify!(member4)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member5) as usize - ptr as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(member5) - ) + unsafe { ::std::ptr::addr_of!((* ptr).member5) as usize - ptr as usize }, + 16usize, concat!("Offset of field: ", stringify!(bar), "::", stringify!(member5)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member6) as usize - ptr as usize }, - 24usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(member6) - ) + unsafe { ::std::ptr::addr_of!((* ptr).member6) as usize - ptr as usize }, + 24usize, concat!("Offset of field: ", stringify!(bar), "::", stringify!(member6)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member7) as usize - ptr as usize }, - 32usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(member7) - ) + unsafe { ::std::ptr::addr_of!((* ptr).member7) as usize - ptr as usize }, + 32usize, concat!("Offset of field: ", stringify!(bar), "::", stringify!(member7)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member8) as usize - ptr as usize }, - 36usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(member8) - ) + unsafe { ::std::ptr::addr_of!((* ptr).member8) as usize - ptr as usize }, + 36usize, concat!("Offset of field: ", stringify!(bar), "::", stringify!(member8)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member9) as usize - ptr as usize }, - 40usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(member9) - ) + unsafe { ::std::ptr::addr_of!((* ptr).member9) as usize - ptr as usize }, + 40usize, concat!("Offset of field: ", stringify!(bar), "::", stringify!(member9)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).member10) as usize - ptr as usize - }, - 44usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(member10) - ) + unsafe { ::std::ptr::addr_of!((* ptr).member10) as usize - ptr as usize }, + 44usize, concat!("Offset of field: ", stringify!(bar), "::", + stringify!(member10)) ); } impl Default for bar { @@ -185,28 +114,18 @@ pub struct Baz { } #[test] fn bindgen_test_layout_Baz() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Baz)) + ::std::mem::size_of:: < Baz > (), 4usize, concat!("Size of: ", stringify!(Baz)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Baz)) + ::std::mem::align_of:: < Baz > (), 4usize, concat!("Alignment of ", + stringify!(Baz)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member1) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Baz), - "::", - stringify!(member1) - ) + unsafe { ::std::ptr::addr_of!((* ptr).member1) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(Baz), "::", stringify!(member1)) ); } impl Default for Baz { @@ -230,22 +149,17 @@ pub struct Bar { } #[test] fn bindgen_test_layout_Bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Bar)) + ::std::mem::size_of:: < Bar > (), 8usize, concat!("Size of: ", stringify!(Bar)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Bar)) + ::std::mem::align_of:: < Bar > (), 8usize, concat!("Alignment of ", + stringify!(Bar)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).baz) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz)) ); } diff --git a/bindgen-tests/tests/expectations/tests/constructor-tp.rs b/bindgen-tests/tests/expectations/tests/constructor-tp.rs index 4b339dc3c4..1275aa2087 100644 --- a/bindgen-tests/tests/expectations/tests/constructor-tp.rs +++ b/bindgen-tests/tests/expectations/tests/constructor-tp.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { @@ -18,14 +12,11 @@ pub struct Bar { #[test] fn bindgen_test_layout_Bar() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Bar)) + ::std::mem::size_of:: < Bar > (), 1usize, concat!("Size of: ", stringify!(Bar)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Bar)) + ::std::mem::align_of:: < Bar > (), 1usize, concat!("Alignment of ", + stringify!(Bar)) ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/constructors.rs b/bindgen-tests/tests/expectations/tests/constructors.rs index 2f13effbef..56041394df 100644 --- a/bindgen-tests/tests/expectations/tests/constructors.rs +++ b/bindgen-tests/tests/expectations/tests/constructors.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct TestOverload { @@ -13,14 +7,12 @@ pub struct TestOverload { #[test] fn bindgen_test_layout_TestOverload() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(TestOverload)) + ::std::mem::size_of:: < TestOverload > (), 1usize, concat!("Size of: ", + stringify!(TestOverload)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(TestOverload)) + ::std::mem::align_of:: < TestOverload > (), 1usize, concat!("Alignment of ", + stringify!(TestOverload)) ); } extern "C" { @@ -56,14 +48,12 @@ pub struct TestPublicNoArgs { #[test] fn bindgen_test_layout_TestPublicNoArgs() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(TestPublicNoArgs)) + ::std::mem::size_of:: < TestPublicNoArgs > (), 1usize, concat!("Size of: ", + stringify!(TestPublicNoArgs)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(TestPublicNoArgs)) + ::std::mem::align_of:: < TestPublicNoArgs > (), 1usize, concat!("Alignment of ", + stringify!(TestPublicNoArgs)) ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/constructors_1_33.rs b/bindgen-tests/tests/expectations/tests/constructors_1_33.rs index b5d333325b..36b9b1a357 100644 --- a/bindgen-tests/tests/expectations/tests/constructors_1_33.rs +++ b/bindgen-tests/tests/expectations/tests/constructors_1_33.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct TestOverload { @@ -13,14 +7,12 @@ pub struct TestOverload { #[test] fn bindgen_test_layout_TestOverload() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(TestOverload)) + ::std::mem::size_of:: < TestOverload > (), 1usize, concat!("Size of: ", + stringify!(TestOverload)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(TestOverload)) + ::std::mem::align_of:: < TestOverload > (), 1usize, concat!("Alignment of ", + stringify!(TestOverload)) ); } extern "C" { @@ -58,14 +50,12 @@ pub struct TestPublicNoArgs { #[test] fn bindgen_test_layout_TestPublicNoArgs() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(TestPublicNoArgs)) + ::std::mem::size_of:: < TestPublicNoArgs > (), 1usize, concat!("Size of: ", + stringify!(TestPublicNoArgs)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(TestPublicNoArgs)) + ::std::mem::align_of:: < TestPublicNoArgs > (), 1usize, concat!("Alignment of ", + stringify!(TestPublicNoArgs)) ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/contains-vs-inherits-zero-sized.rs b/bindgen-tests/tests/expectations/tests/contains-vs-inherits-zero-sized.rs index 62fc374946..30da3eb3b5 100644 --- a/bindgen-tests/tests/expectations/tests/contains-vs-inherits-zero-sized.rs +++ b/bindgen-tests/tests/expectations/tests/contains-vs-inherits-zero-sized.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] /// This should get an `_address` byte. #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -14,18 +8,16 @@ pub struct Empty { #[test] fn bindgen_test_layout_Empty() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Empty)) + ::std::mem::size_of:: < Empty > (), 1usize, concat!("Size of: ", + stringify!(Empty)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Empty)) + ::std::mem::align_of:: < Empty > (), 1usize, concat!("Alignment of ", + stringify!(Empty)) ); } -/// This should not get an `_address` byte, so `sizeof(Inherits)` should be -/// `1`. +/** This should not get an `_address` byte, so `sizeof(Inherits)` should be + `1`.*/ #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Inherits { @@ -33,32 +25,23 @@ pub struct Inherits { } #[test] fn bindgen_test_layout_Inherits() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Inherits)) + ::std::mem::size_of:: < Inherits > (), 1usize, concat!("Size of: ", + stringify!(Inherits)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Inherits)) + ::std::mem::align_of:: < Inherits > (), 1usize, concat!("Alignment of ", + stringify!(Inherits)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Inherits), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(Inherits), "::", stringify!(b)) ); } -/// This should not get an `_address` byte, but contains `Empty` which *does* get -/// one, so `sizeof(Contains)` should be `1 + 1`. +/** This should not get an `_address` byte, but contains `Empty` which *does* get + one, so `sizeof(Contains)` should be `1 + 1`.*/ #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Contains { @@ -67,37 +50,22 @@ pub struct Contains { } #[test] fn bindgen_test_layout_Contains() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 2usize, - concat!("Size of: ", stringify!(Contains)) + ::std::mem::size_of:: < Contains > (), 2usize, concat!("Size of: ", + stringify!(Contains)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Contains)) + ::std::mem::align_of:: < Contains > (), 1usize, concat!("Alignment of ", + stringify!(Contains)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).empty) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Contains), - "::", - stringify!(empty) - ) + unsafe { ::std::ptr::addr_of!((* ptr).empty) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(Contains), "::", stringify!(empty)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 1usize, - concat!( - "Offset of field: ", - stringify!(Contains), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 1usize, + concat!("Offset of field: ", stringify!(Contains), "::", stringify!(b)) ); } diff --git a/bindgen-tests/tests/expectations/tests/convert-cpp-comment-to-rust.rs b/bindgen-tests/tests/expectations/tests/convert-cpp-comment-to-rust.rs index 09a22c4f65..96f9e6fd2a 100644 --- a/bindgen-tests/tests/expectations/tests/convert-cpp-comment-to-rust.rs +++ b/bindgen-tests/tests/expectations/tests/convert-cpp-comment-to-rust.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type mbedtls_mpi_uint = ::std::os::raw::c_uint; /// \brief MPI structure #[repr(C)] diff --git a/bindgen-tests/tests/expectations/tests/convert-floats.rs b/bindgen-tests/tests/expectations/tests/convert-floats.rs index e710a442e2..63f3e755d9 100644 --- a/bindgen-tests/tests/expectations/tests/convert-floats.rs +++ b/bindgen-tests/tests/expectations/tests/convert-floats.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[derive(PartialEq, Copy, Clone, Hash, Debug, Default)] #[repr(C)] pub struct __BindgenComplex { @@ -23,67 +17,40 @@ pub struct foo { } #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 48usize, - concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of:: < foo > (), 48usize, concat!("Size of: ", stringify!(foo)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(foo)) + ::std::mem::align_of:: < foo > (), 8usize, concat!("Alignment of ", + stringify!(foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 4usize, + unsafe { ::std::ptr::addr_of!((* ptr).baz) as usize - ptr as usize }, 4usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(baz)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bazz) as usize - ptr as usize }, - 8usize, + unsafe { ::std::ptr::addr_of!((* ptr).bazz) as usize - ptr as usize }, 8usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bazz)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bazzz) as usize - ptr as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(bazzz) - ) + unsafe { ::std::ptr::addr_of!((* ptr).bazzz) as usize - ptr as usize }, 16usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(bazzz)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).complexFloat) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(complexFloat) - ) + unsafe { ::std::ptr::addr_of!((* ptr).complexFloat) as usize - ptr as usize }, + 24usize, concat!("Offset of field: ", stringify!(foo), "::", + stringify!(complexFloat)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).complexDouble) as usize - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(complexDouble) - ) + unsafe { ::std::ptr::addr_of!((* ptr).complexDouble) as usize - ptr as usize }, + 32usize, concat!("Offset of field: ", stringify!(foo), "::", + stringify!(complexDouble)) ); } impl Default for foo { diff --git a/bindgen-tests/tests/expectations/tests/core_ffi_c.rs b/bindgen-tests/tests/expectations/tests/core_ffi_c.rs index 7e138a894f..42c9272034 100644 --- a/bindgen-tests/tests/expectations/tests/core_ffi_c.rs +++ b/bindgen-tests/tests/expectations/tests/core_ffi_c.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type c_char = ::core::ffi::c_char; pub type c_double = ::core::ffi::c_double; pub type c_float = ::core::ffi::c_float; diff --git a/bindgen-tests/tests/expectations/tests/cpp-empty-layout.rs b/bindgen-tests/tests/expectations/tests/cpp-empty-layout.rs index f5ba025a25..d16596b591 100644 --- a/bindgen-tests/tests/expectations/tests/cpp-empty-layout.rs +++ b/bindgen-tests/tests/expectations/tests/cpp-empty-layout.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { @@ -13,13 +7,10 @@ pub struct Foo { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) + ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", + stringify!(Foo)) ); } diff --git a/bindgen-tests/tests/expectations/tests/crtp.rs b/bindgen-tests/tests/expectations/tests/crtp.rs index 2372e21153..08931f8893 100644 --- a/bindgen-tests/tests/expectations/tests/crtp.rs +++ b/bindgen-tests/tests/expectations/tests/crtp.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Base { @@ -18,14 +12,12 @@ pub struct Derived { #[test] fn bindgen_test_layout_Derived() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Derived)) + ::std::mem::size_of:: < Derived > (), 1usize, concat!("Size of: ", + stringify!(Derived)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Derived)) + ::std::mem::align_of:: < Derived > (), 1usize, concat!("Alignment of ", + stringify!(Derived)) ); } #[repr(C)] @@ -41,46 +33,33 @@ pub struct DerivedFromBaseWithDestructor { #[test] fn bindgen_test_layout_DerivedFromBaseWithDestructor() { assert_eq!( - ::std::mem::size_of::(), - 1usize, + ::std::mem::size_of:: < DerivedFromBaseWithDestructor > (), 1usize, concat!("Size of: ", stringify!(DerivedFromBaseWithDestructor)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < DerivedFromBaseWithDestructor > (), 1usize, concat!("Alignment of ", stringify!(DerivedFromBaseWithDestructor)) ); } #[test] fn __bindgen_test_layout_Base_open0_Derived_close0_instantiation() { assert_eq!( - ::std::mem::size_of::(), - 1usize, + ::std::mem::size_of:: < Base > (), 1usize, concat!("Size of template specialization: ", stringify!(Base)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < Base > (), 1usize, concat!("Alignment of template specialization: ", stringify!(Base)) ); } #[test] -fn __bindgen_test_layout_BaseWithDestructor_open0_DerivedFromBaseWithDestructor_close0_instantiation( -) { +fn __bindgen_test_layout_BaseWithDestructor_open0_DerivedFromBaseWithDestructor_close0_instantiation() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!( - "Size of template specialization: ", - stringify!(BaseWithDestructor) - ) + ::std::mem::size_of:: < BaseWithDestructor > (), 1usize, + concat!("Size of template specialization: ", stringify!(BaseWithDestructor)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!( - "Alignment of template specialization: ", - stringify!(BaseWithDestructor) - ) + ::std::mem::align_of:: < BaseWithDestructor > (), 1usize, + concat!("Alignment of template specialization: ", stringify!(BaseWithDestructor)) ); } diff --git a/bindgen-tests/tests/expectations/tests/ctypes-prefix-path.rs b/bindgen-tests/tests/expectations/tests/ctypes-prefix-path.rs index 5b3d186a33..834bc77504 100644 --- a/bindgen-tests/tests/expectations/tests/ctypes-prefix-path.rs +++ b/bindgen-tests/tests/expectations/tests/ctypes-prefix-path.rs @@ -1,9 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![no_std] mod libc { pub mod foo { @@ -11,7 +6,6 @@ mod libc { pub enum c_void {} } } - #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct foo { @@ -21,32 +15,25 @@ pub struct foo { } #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::core::mem::MaybeUninit = - ::core::mem::MaybeUninit::uninit(); + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::core::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(foo)) + ::core::mem::size_of:: < foo > (), 16usize, concat!("Size of: ", stringify!(foo)) ); assert_eq!( - ::core::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(foo)) + ::core::mem::align_of:: < foo > (), 8usize, concat!("Alignment of ", + stringify!(foo)) ); assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, + unsafe { ::core::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) ); assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 4usize, + unsafe { ::core::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 4usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) ); assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 8usize, + unsafe { ::core::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 8usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); } diff --git a/bindgen-tests/tests/expectations/tests/dash_language.rs b/bindgen-tests/tests/expectations/tests/dash_language.rs index eb2bbc7689..f405a35604 100644 --- a/bindgen-tests/tests/expectations/tests/dash_language.rs +++ b/bindgen-tests/tests/expectations/tests/dash_language.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { diff --git a/bindgen-tests/tests/expectations/tests/decl_extern_int_twice.rs b/bindgen-tests/tests/expectations/tests/decl_extern_int_twice.rs index d812b03238..8be0ea58e9 100644 --- a/bindgen-tests/tests/expectations/tests/decl_extern_int_twice.rs +++ b/bindgen-tests/tests/expectations/tests/decl_extern_int_twice.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub static mut foo: ::std::os::raw::c_int; } diff --git a/bindgen-tests/tests/expectations/tests/decl_ptr_to_array.rs b/bindgen-tests/tests/expectations/tests/decl_ptr_to_array.rs index b520f1e033..08cf113a4c 100644 --- a/bindgen-tests/tests/expectations/tests/decl_ptr_to_array.rs +++ b/bindgen-tests/tests/expectations/tests/decl_ptr_to_array.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub static mut foo: *mut [::std::os::raw::c_int; 1usize]; } diff --git a/bindgen-tests/tests/expectations/tests/default-enum-style-constified-module.rs b/bindgen-tests/tests/expectations/tests/default-enum-style-constified-module.rs index 5e225e3db6..c9897de70b 100644 --- a/bindgen-tests/tests/expectations/tests/default-enum-style-constified-module.rs +++ b/bindgen-tests/tests/expectations/tests/default-enum-style-constified-module.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod Foo { pub type Type = ::std::os::raw::c_uint; pub const bar: Type = 0; diff --git a/bindgen-tests/tests/expectations/tests/default-macro-constant-type-signed.rs b/bindgen-tests/tests/expectations/tests/default-macro-constant-type-signed.rs index 38ebc531b3..db4eaa99bd 100644 --- a/bindgen-tests/tests/expectations/tests/default-macro-constant-type-signed.rs +++ b/bindgen-tests/tests/expectations/tests/default-macro-constant-type-signed.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const N0: i32 = 0; pub const N1: i32 = 1; pub const N2: i32 = 2; diff --git a/bindgen-tests/tests/expectations/tests/default-macro-constant-type-unsigned.rs b/bindgen-tests/tests/expectations/tests/default-macro-constant-type-unsigned.rs index 5571563bcd..bc122e981f 100644 --- a/bindgen-tests/tests/expectations/tests/default-macro-constant-type-unsigned.rs +++ b/bindgen-tests/tests/expectations/tests/default-macro-constant-type-unsigned.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const N0: u32 = 0; pub const N1: u32 = 1; pub const N2: u32 = 2; diff --git a/bindgen-tests/tests/expectations/tests/default-macro-constant-type.rs b/bindgen-tests/tests/expectations/tests/default-macro-constant-type.rs index 5571563bcd..bc122e981f 100644 --- a/bindgen-tests/tests/expectations/tests/default-macro-constant-type.rs +++ b/bindgen-tests/tests/expectations/tests/default-macro-constant-type.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const N0: u32 = 0; pub const N1: u32 = 1; pub const N2: u32 = 2; diff --git a/bindgen-tests/tests/expectations/tests/default-template-parameter.rs b/bindgen-tests/tests/expectations/tests/default-template-parameter.rs index 2cbe463cd9..4ed8c18bdc 100644 --- a/bindgen-tests/tests/expectations/tests/default-template-parameter.rs +++ b/bindgen-tests/tests/expectations/tests/default-template-parameter.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Foo { @@ -25,20 +19,14 @@ impl Default for Foo { #[test] fn __bindgen_test_layout_Foo_open0_bool__int_close0_instantiation() { assert_eq!( - ::std::mem::size_of::>(), - 8usize, - concat!( - "Size of template specialization: ", - stringify ! (Foo < bool , :: std :: os :: raw :: c_int >) - ) + ::std::mem::size_of:: < Foo < bool, ::std::os::raw::c_int > > (), 8usize, + concat!("Size of template specialization: ", stringify!(Foo < bool, + ::std::os::raw::c_int >)) ); assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify ! (Foo < bool , :: std :: os :: raw :: c_int >) - ) + ::std::mem::align_of:: < Foo < bool, ::std::os::raw::c_int > > (), 4usize, + concat!("Alignment of template specialization: ", stringify!(Foo < bool, + ::std::os::raw::c_int >)) ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/default_visibility_crate.rs b/bindgen-tests/tests/expectations/tests/default_visibility_crate.rs index 9da61b5aaa..a3131a1bae 100644 --- a/bindgen-tests/tests/expectations/tests/default_visibility_crate.rs +++ b/bindgen-tests/tests/expectations/tests/default_visibility_crate.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -106,9 +98,7 @@ pub struct Color { impl Color { #[inline] pub(crate) fn r(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) } } #[inline] pub(crate) fn set_r(&mut self, val: ::std::os::raw::c_char) { @@ -119,9 +109,7 @@ impl Color { } #[inline] pub(crate) fn g(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u8) } } #[inline] pub(crate) fn set_g(&mut self, val: ::std::os::raw::c_char) { @@ -132,9 +120,7 @@ impl Color { } #[inline] pub(crate) fn b(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u8) } } #[inline] pub(crate) fn set_b(&mut self, val: ::std::os::raw::c_char) { @@ -149,20 +135,34 @@ impl Color { g: ::std::os::raw::c_char, b: ::std::os::raw::c_char, ) -> __BindgenBitfieldUnit<[u8; 1usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 1u8, { - let r: u8 = unsafe { ::std::mem::transmute(r) }; - r as u64 - }); - __bindgen_bitfield_unit.set(1usize, 1u8, { - let g: u8 = unsafe { ::std::mem::transmute(g) }; - g as u64 - }); - __bindgen_bitfield_unit.set(2usize, 1u8, { - let b: u8 = unsafe { ::std::mem::transmute(b) }; - b as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let r: u8 = unsafe { ::std::mem::transmute(r) }; + r as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 1usize, + 1u8, + { + let g: u8 = unsafe { ::std::mem::transmute(g) }; + g as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 2usize, + 1u8, + { + let b: u8 = unsafe { ::std::mem::transmute(b) }; + b as u64 + }, + ); __bindgen_bitfield_unit } } diff --git a/bindgen-tests/tests/expectations/tests/default_visibility_private.rs b/bindgen-tests/tests/expectations/tests/default_visibility_private.rs index 382778f9d9..280b6b69d9 100644 --- a/bindgen-tests/tests/expectations/tests/default_visibility_private.rs +++ b/bindgen-tests/tests/expectations/tests/default_visibility_private.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -106,9 +98,7 @@ pub struct Color { impl Color { #[inline] fn r(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) } } #[inline] fn set_r(&mut self, val: ::std::os::raw::c_char) { @@ -119,9 +109,7 @@ impl Color { } #[inline] fn g(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u8) } } #[inline] fn set_g(&mut self, val: ::std::os::raw::c_char) { @@ -132,9 +120,7 @@ impl Color { } #[inline] fn b(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u8) } } #[inline] fn set_b(&mut self, val: ::std::os::raw::c_char) { @@ -149,20 +135,34 @@ impl Color { g: ::std::os::raw::c_char, b: ::std::os::raw::c_char, ) -> __BindgenBitfieldUnit<[u8; 1usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 1u8, { - let r: u8 = unsafe { ::std::mem::transmute(r) }; - r as u64 - }); - __bindgen_bitfield_unit.set(1usize, 1u8, { - let g: u8 = unsafe { ::std::mem::transmute(g) }; - g as u64 - }); - __bindgen_bitfield_unit.set(2usize, 1u8, { - let b: u8 = unsafe { ::std::mem::transmute(b) }; - b as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let r: u8 = unsafe { ::std::mem::transmute(r) }; + r as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 1usize, + 1u8, + { + let g: u8 = unsafe { ::std::mem::transmute(g) }; + g as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 2usize, + 1u8, + { + let b: u8 = unsafe { ::std::mem::transmute(b) }; + b as u64 + }, + ); __bindgen_bitfield_unit } } diff --git a/bindgen-tests/tests/expectations/tests/default_visibility_private_respects_cxx_access_spec.rs b/bindgen-tests/tests/expectations/tests/default_visibility_private_respects_cxx_access_spec.rs index 02460445c9..d38790f384 100644 --- a/bindgen-tests/tests/expectations/tests/default_visibility_private_respects_cxx_access_spec.rs +++ b/bindgen-tests/tests/expectations/tests/default_visibility_private_respects_cxx_access_spec.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -106,9 +98,7 @@ pub struct Color { impl Color { #[inline] pub fn r(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) } } #[inline] pub fn set_r(&mut self, val: ::std::os::raw::c_char) { @@ -119,9 +109,7 @@ impl Color { } #[inline] pub fn g(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u8) } } #[inline] pub fn set_g(&mut self, val: ::std::os::raw::c_char) { @@ -132,9 +120,7 @@ impl Color { } #[inline] pub fn b(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u8) } } #[inline] pub fn set_b(&mut self, val: ::std::os::raw::c_char) { @@ -149,20 +135,34 @@ impl Color { g: ::std::os::raw::c_char, b: ::std::os::raw::c_char, ) -> __BindgenBitfieldUnit<[u8; 1usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 1u8, { - let r: u8 = unsafe { ::std::mem::transmute(r) }; - r as u64 - }); - __bindgen_bitfield_unit.set(1usize, 1u8, { - let g: u8 = unsafe { ::std::mem::transmute(g) }; - g as u64 - }); - __bindgen_bitfield_unit.set(2usize, 1u8, { - let b: u8 = unsafe { ::std::mem::transmute(b) }; - b as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let r: u8 = unsafe { ::std::mem::transmute(r) }; + r as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 1usize, + 1u8, + { + let g: u8 = unsafe { ::std::mem::transmute(g) }; + g as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 2usize, + 1u8, + { + let b: u8 = unsafe { ::std::mem::transmute(b) }; + b as u64 + }, + ); __bindgen_bitfield_unit } } diff --git a/bindgen-tests/tests/expectations/tests/deleted-function.rs b/bindgen-tests/tests/expectations/tests/deleted-function.rs index 96967bb461..03d5a8f0f1 100644 --- a/bindgen-tests/tests/expectations/tests/deleted-function.rs +++ b/bindgen-tests/tests/expectations/tests/deleted-function.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct A { @@ -13,14 +7,10 @@ pub struct A { #[test] fn bindgen_test_layout_A() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(A)) + ::std::mem::size_of:: < A > (), 1usize, concat!("Size of: ", stringify!(A)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(A)) + ::std::mem::align_of:: < A > (), 1usize, concat!("Alignment of ", stringify!(A)) ); } extern "C" { @@ -49,14 +39,10 @@ pub struct B { #[test] fn bindgen_test_layout_B() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(B)) + ::std::mem::size_of:: < B > (), 1usize, concat!("Size of: ", stringify!(B)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(B)) + ::std::mem::align_of:: < B > (), 1usize, concat!("Alignment of ", stringify!(B)) ); } #[repr(C)] @@ -67,14 +53,10 @@ pub struct C { #[test] fn bindgen_test_layout_C() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(C)) + ::std::mem::size_of:: < C > (), 1usize, concat!("Size of: ", stringify!(C)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(C)) + ::std::mem::align_of:: < C > (), 1usize, concat!("Alignment of ", stringify!(C)) ); } extern "C" { 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 ea6621dd1c..ec68b474d3 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 @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -91,9 +83,9 @@ where } } } -/// 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`. +/** 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)] pub struct Foo { @@ -104,28 +96,18 @@ pub struct Foo { } #[test] fn bindgen_test_layout_Foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 136usize, - concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of:: < Foo > (), 136usize, concat!("Size of: ", stringify!(Foo)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Foo)) + ::std::mem::align_of:: < Foo > (), 4usize, concat!("Alignment of ", + stringify!(Foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).large) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(large) - ) + unsafe { ::std::ptr::addr_of!((* ptr).large) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(large)) ); } extern "C" { @@ -152,33 +134,22 @@ 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_ : {:?}, }}", - self.large - .iter() - .enumerate() - .map(|(i, v)| format!( - "{}{:?}", - if i > 0 { ", " } else { "" }, - v - )) - .collect::(), - self.type__bindgen_bitfield() + f, "Foo {{ large: [{}], type_ : {:?}, }}", self.large.iter().enumerate() + .map(| (i, v) | format!("{}{:?}", if i > 0 { ", " } else { "" }, v)) + .collect:: < String > (), 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() + &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 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 3u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 3u8) as u8) } } #[inline] pub fn set_type__bindgen_bitfield(&mut self, val: ::std::os::raw::c_char) { @@ -191,13 +162,18 @@ impl Foo { pub fn new_bitfield_1( type__bindgen_bitfield: ::std::os::raw::c_char, ) -> __BindgenBitfieldUnit<[u8; 2usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 2usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 3u8, { - let type__bindgen_bitfield: u8 = - unsafe { ::std::mem::transmute(type__bindgen_bitfield) }; - type__bindgen_bitfield as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 2usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 3u8, + { + let type__bindgen_bitfield: u8 = unsafe { + ::std::mem::transmute(type__bindgen_bitfield) + }; + type__bindgen_bitfield as u64 + }, + ); __bindgen_bitfield_unit } #[inline] diff --git a/bindgen-tests/tests/expectations/tests/derive-clone.rs b/bindgen-tests/tests/expectations/tests/derive-clone.rs index 19c28b697f..ecb9ebadc0 100644 --- a/bindgen-tests/tests/expectations/tests/derive-clone.rs +++ b/bindgen-tests/tests/expectations/tests/derive-clone.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] /// This struct should derive `Clone`. #[repr(C)] #[derive(Copy, Clone)] @@ -13,28 +7,20 @@ pub struct ShouldDeriveClone { } #[test] fn bindgen_test_layout_ShouldDeriveClone() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 132usize, - concat!("Size of: ", stringify!(ShouldDeriveClone)) + ::std::mem::size_of:: < ShouldDeriveClone > (), 132usize, concat!("Size of: ", + stringify!(ShouldDeriveClone)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(ShouldDeriveClone)) + ::std::mem::align_of:: < ShouldDeriveClone > (), 4usize, concat!("Alignment of ", + stringify!(ShouldDeriveClone)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).large) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldDeriveClone), - "::", - stringify!(large) - ) + unsafe { ::std::ptr::addr_of!((* ptr).large) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(ShouldDeriveClone), "::", + stringify!(large)) ); } impl Default for ShouldDeriveClone { diff --git a/bindgen-tests/tests/expectations/tests/derive-clone_1_0.rs b/bindgen-tests/tests/expectations/tests/derive-clone_1_0.rs index 3d72db2f89..59b26c9922 100644 --- a/bindgen-tests/tests/expectations/tests/derive-clone_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/derive-clone_1_0.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -/// Since builtin `Clone` impls were introduced in Rust 1.21 this struct -/// should impl `Clone` "manually". +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +/** Since builtin `Clone` impls were introduced in Rust 1.21 this struct + should impl `Clone` "manually".*/ #[repr(C)] #[derive(Copy)] pub struct ShouldImplClone { @@ -14,28 +8,20 @@ pub struct ShouldImplClone { } #[test] fn bindgen_test_layout_ShouldImplClone() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 132usize, - concat!("Size of: ", stringify!(ShouldImplClone)) + ::std::mem::size_of:: < ShouldImplClone > (), 132usize, concat!("Size of: ", + stringify!(ShouldImplClone)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(ShouldImplClone)) + ::std::mem::align_of:: < ShouldImplClone > (), 4usize, concat!("Alignment of ", + stringify!(ShouldImplClone)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).large) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldImplClone), - "::", - stringify!(large) - ) + unsafe { ::std::ptr::addr_of!((* ptr).large) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(ShouldImplClone), "::", + stringify!(large)) ); } impl Clone for ShouldImplClone { diff --git a/bindgen-tests/tests/expectations/tests/derive-custom-cli.rs b/bindgen-tests/tests/expectations/tests/derive-custom-cli.rs index 36f84c7d93..710dc6890f 100644 --- a/bindgen-tests/tests/expectations/tests/derive-custom-cli.rs +++ b/bindgen-tests/tests/expectations/tests/derive-custom-cli.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Clone, Default)] pub struct foo_struct { @@ -12,28 +6,19 @@ pub struct foo_struct { } #[test] fn bindgen_test_layout_foo_struct() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo_struct)) + ::std::mem::size_of:: < foo_struct > (), 4usize, concat!("Size of: ", + stringify!(foo_struct)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo_struct)) + ::std::mem::align_of:: < foo_struct > (), 4usize, concat!("Alignment of ", + stringify!(foo_struct)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).inner) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo_struct), - "::", - stringify!(inner) - ) + unsafe { ::std::ptr::addr_of!((* ptr).inner) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo_struct), "::", stringify!(inner)) ); } #[repr(u32)] @@ -49,38 +34,23 @@ pub union foo_union { } #[test] fn bindgen_test_layout_foo_union() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo_union)) + ::std::mem::size_of:: < foo_union > (), 4usize, concat!("Size of: ", + stringify!(foo_union)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo_union)) + ::std::mem::align_of:: < foo_union > (), 4usize, concat!("Alignment of ", + stringify!(foo_union)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).fst) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo_union), - "::", - stringify!(fst) - ) + unsafe { ::std::ptr::addr_of!((* ptr).fst) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo_union), "::", stringify!(fst)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).snd) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo_union), - "::", - stringify!(snd) - ) + unsafe { ::std::ptr::addr_of!((* ptr).snd) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo_union), "::", stringify!(snd)) ); } #[repr(C)] @@ -89,27 +59,18 @@ pub struct non_matching { } #[test] fn bindgen_test_layout_non_matching() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(non_matching)) + ::std::mem::size_of:: < non_matching > (), 4usize, concat!("Size of: ", + stringify!(non_matching)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(non_matching)) + ::std::mem::align_of:: < non_matching > (), 4usize, concat!("Alignment of ", + stringify!(non_matching)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).inner) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(non_matching), - "::", - stringify!(inner) - ) + unsafe { ::std::ptr::addr_of!((* ptr).inner) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(non_matching), "::", stringify!(inner)) ); } diff --git a/bindgen-tests/tests/expectations/tests/derive-custom.rs b/bindgen-tests/tests/expectations/tests/derive-custom.rs index 542b6bb25f..9a69ebbb73 100644 --- a/bindgen-tests/tests/expectations/tests/derive-custom.rs +++ b/bindgen-tests/tests/expectations/tests/derive-custom.rs @@ -1,18 +1,12 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] ///
#[repr(C)] #[derive(Default, Debug)] pub struct my_type { pub a: ::std::os::raw::c_int, } -///
-///
+/**
+
*/ #[repr(C)] #[derive(Default, Debug, Clone)] pub struct my_type2 { 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 2a78e93050..17a2d4d582 100644 --- a/bindgen-tests/tests/expectations/tests/derive-debug-bitfield-core.rs +++ b/bindgen-tests/tests/expectations/tests/derive-debug-bitfield-core.rs @@ -1,12 +1,5 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern crate core; - #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -57,8 +50,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -78,8 +70,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -102,30 +93,18 @@ pub struct C { } #[test] fn bindgen_test_layout_C() { - const UNINIT: ::core::mem::MaybeUninit = - ::core::mem::MaybeUninit::uninit(); + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::core::mem::size_of::(), - 204usize, - concat!("Size of: ", stringify!(C)) + ::core::mem::size_of:: < C > (), 204usize, concat!("Size of: ", stringify!(C)) ); assert_eq!( - ::core::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C)) + ::core::mem::align_of:: < C > (), 4usize, concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { - ::core::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(large_array) - ) + unsafe { ::core::ptr::addr_of!((* ptr).large_array) as usize - ptr as usize }, + 4usize, concat!("Offset of field: ", stringify!(C), "::", + stringify!(large_array)) ); } impl Default for C { @@ -139,20 +118,13 @@ 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() - ) + write!(f, "C {{ a : {:?}, b : {:?}, large_array: [...] }}", self.a(), self.b()) } } impl C { #[inline] pub fn a(&self) -> bool { - unsafe { - ::core::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) - } + unsafe { ::core::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) } } #[inline] pub fn set_a(&mut self, val: bool) { @@ -163,9 +135,7 @@ impl C { } #[inline] pub fn b(&self) -> bool { - unsafe { - ::core::mem::transmute(self._bitfield_1.get(1usize, 7u8) as u8) - } + unsafe { ::core::mem::transmute(self._bitfield_1.get(1usize, 7u8) as u8) } } #[inline] pub fn set_b(&mut self, val: bool) { @@ -175,20 +145,26 @@ impl C { } } #[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.set(0usize, 1u8, { - let a: u8 = unsafe { ::core::mem::transmute(a) }; - a as u64 - }); - __bindgen_bitfield_unit.set(1usize, 7u8, { - let b: u8 = unsafe { ::core::mem::transmute(b) }; - b as u64 - }); + 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 + .set( + 0usize, + 1u8, + { + let a: u8 = unsafe { ::core::mem::transmute(a) }; + a as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 1usize, + 7u8, + { + let b: u8 = unsafe { ::core::mem::transmute(b) }; + b as u64 + }, + ); __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 0ae8f32968..2e10b245ed 100644 --- a/bindgen-tests/tests/expectations/tests/derive-debug-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/derive-debug-bitfield.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -100,30 +92,18 @@ pub struct C { } #[test] fn bindgen_test_layout_C() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 204usize, - concat!("Size of: ", stringify!(C)) + ::std::mem::size_of:: < C > (), 204usize, concat!("Size of: ", stringify!(C)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C)) + ::std::mem::align_of:: < C > (), 4usize, concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(large_array) - ) + unsafe { ::std::ptr::addr_of!((* ptr).large_array) as usize - ptr as usize }, + 4usize, concat!("Offset of field: ", stringify!(C), "::", + stringify!(large_array)) ); } impl Default for C { @@ -138,28 +118,16 @@ 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(), - self.large_array - .iter() - .enumerate() - .map(|(i, v)| format!( - "{}{:?}", - if i > 0 { ", " } else { "" }, - v - )) - .collect::() + f, "C {{ a : {:?}, b : {:?}, large_array: [{}] }}", self.a(), self.b(), self + .large_array.iter().enumerate().map(| (i, v) | format!("{}{:?}", if i > 0 { + ", " } else { "" }, v)).collect:: < String > () ) } } impl C { #[inline] pub fn a(&self) -> bool { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) } } #[inline] pub fn set_a(&mut self, val: bool) { @@ -170,9 +138,7 @@ impl C { } #[inline] pub fn b(&self) -> bool { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(1usize, 7u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 7u8) as u8) } } #[inline] pub fn set_b(&mut self, val: bool) { @@ -182,20 +148,26 @@ impl C { } } #[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.set(0usize, 1u8, { - let a: u8 = unsafe { ::std::mem::transmute(a) }; - a as u64 - }); - __bindgen_bitfield_unit.set(1usize, 7u8, { - let b: u8 = unsafe { ::std::mem::transmute(b) }; - b as u64 - }); + 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 + .set( + 0usize, + 1u8, + { + let a: u8 = unsafe { ::std::mem::transmute(a) }; + a as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 1usize, + 7u8, + { + let b: u8 = unsafe { ::std::mem::transmute(b) }; + b as u64 + }, + ); __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 16b127bf14..085dd95a1f 100644 --- a/bindgen-tests/tests/expectations/tests/derive-debug-function-pointer.rs +++ b/bindgen-tests/tests/expectations/tests/derive-debug-function-pointer.rs @@ -1,54 +1,33 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone)] pub struct Nice { pub pointer: Nice_Function, pub large_array: [::std::os::raw::c_int; 34usize], } -pub type Nice_Function = - ::std::option::Option; +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(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 144usize, - concat!("Size of: ", stringify!(Nice)) + ::std::mem::size_of:: < Nice > (), 144usize, concat!("Size of: ", + stringify!(Nice)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Nice)) + ::std::mem::align_of:: < Nice > (), 8usize, concat!("Alignment of ", + stringify!(Nice)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).pointer) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Nice), - "::", - stringify!(pointer) - ) + unsafe { ::std::ptr::addr_of!((* ptr).pointer) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(Nice), "::", stringify!(pointer)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(Nice), - "::", - stringify!(large_array) - ) + unsafe { ::std::ptr::addr_of!((* ptr).large_array) as usize - ptr as usize }, + 8usize, concat!("Offset of field: ", stringify!(Nice), "::", + stringify!(large_array)) ); } impl Default for Nice { @@ -63,18 +42,9 @@ 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, - self.large_array - .iter() - .enumerate() - .map(|(i, v)| format!( - "{}{:?}", - if i > 0 { ", " } else { "" }, - v - )) - .collect::() + f, "Nice {{ pointer: {:?}, large_array: [{}] }}", self.pointer, self + .large_array.iter().enumerate().map(| (i, v) | format!("{}{:?}", if i > 0 { + ", " } else { "" }, v)).collect:: < String > () ) } } diff --git a/bindgen-tests/tests/expectations/tests/derive-debug-generic.rs b/bindgen-tests/tests/expectations/tests/derive-debug-generic.rs index 49d4e9b89e..f35b28b3e5 100644 --- a/bindgen-tests/tests/expectations/tests/derive-debug-generic.rs +++ b/bindgen-tests/tests/expectations/tests/derive-debug-generic.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct Generic { pub t: [T; 40usize], diff --git a/bindgen-tests/tests/expectations/tests/derive-debug-mangle-name.rs b/bindgen-tests/tests/expectations/tests/derive-debug-mangle-name.rs index a757d679b0..d97721166e 100644 --- a/bindgen-tests/tests/expectations/tests/derive-debug-mangle-name.rs +++ b/bindgen-tests/tests/expectations/tests/derive-debug-mangle-name.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone)] pub struct perf_event_attr { @@ -20,38 +14,25 @@ pub union perf_event_attr__bindgen_ty_1 { } #[test] fn bindgen_test_layout_perf_event_attr__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, + ::std::mem::size_of:: < perf_event_attr__bindgen_ty_1 > (), 4usize, concat!("Size of: ", stringify!(perf_event_attr__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < perf_event_attr__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", stringify!(perf_event_attr__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(perf_event_attr__bindgen_ty_1), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(perf_event_attr__bindgen_ty_1), "::", + stringify!(b)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(perf_event_attr__bindgen_ty_1), - "::", - stringify!(c) - ) + unsafe { ::std::ptr::addr_of!((* ptr).c) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(perf_event_attr__bindgen_ty_1), "::", + stringify!(c)) ); } impl Default for perf_event_attr__bindgen_ty_1 { @@ -70,38 +51,24 @@ impl ::std::fmt::Debug for perf_event_attr__bindgen_ty_1 { } #[test] fn bindgen_test_layout_perf_event_attr() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 12usize, - concat!("Size of: ", stringify!(perf_event_attr)) + ::std::mem::size_of:: < perf_event_attr > (), 12usize, concat!("Size of: ", + stringify!(perf_event_attr)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(perf_event_attr)) + ::std::mem::align_of:: < perf_event_attr > (), 4usize, concat!("Alignment of ", + stringify!(perf_event_attr)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(perf_event_attr), - "::", - stringify!(type_) - ) + unsafe { ::std::ptr::addr_of!((* ptr).type_) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(perf_event_attr), "::", + stringify!(type_)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(perf_event_attr), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(perf_event_attr), "::", stringify!(a)) ); } impl Default for perf_event_attr { @@ -116,9 +83,8 @@ impl Default for perf_event_attr { impl ::std::fmt::Debug for perf_event_attr { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { write!( - f, - "perf_event_attr {{ type: {:?}, a: {:?}, __bindgen_anon_1: {:?} }}", - self.type_, self.a, self.__bindgen_anon_1 + f, "perf_event_attr {{ type: {:?}, a: {:?}, __bindgen_anon_1: {:?} }}", self + .type_, self.a, self.__bindgen_anon_1 ) } } 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 a0cc87ff2c..3d49764cd8 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,38 +1,23 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct Instance { pub val: [u32; 50usize], } #[test] fn bindgen_test_layout_Instance() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 200usize, - concat!("Size of: ", stringify!(Instance)) + ::std::mem::size_of:: < Instance > (), 200usize, concat!("Size of: ", + stringify!(Instance)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Instance)) + ::std::mem::align_of:: < Instance > (), 4usize, concat!("Alignment of ", + stringify!(Instance)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).val) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Instance), - "::", - stringify!(val) - ) + unsafe { ::std::ptr::addr_of!((* ptr).val) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(Instance), "::", stringify!(val)) ); } impl Default for Instance { diff --git a/bindgen-tests/tests/expectations/tests/derive-debug-opaque.rs b/bindgen-tests/tests/expectations/tests/derive-debug-opaque.rs index 5cebc9b8e6..07123e496e 100644 --- a/bindgen-tests/tests/expectations/tests/derive-debug-opaque.rs +++ b/bindgen-tests/tests/expectations/tests/derive-debug-opaque.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[repr(align(4))] pub struct Opaque { @@ -13,14 +7,12 @@ pub struct Opaque { #[test] fn bindgen_test_layout_Opaque() { assert_eq!( - ::std::mem::size_of::(), - 164usize, - concat!("Size of: ", stringify!(Opaque)) + ::std::mem::size_of:: < Opaque > (), 164usize, concat!("Size of: ", + stringify!(Opaque)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Opaque)) + ::std::mem::align_of:: < Opaque > (), 4usize, concat!("Alignment of ", + stringify!(Opaque)) ); } impl Default for Opaque { @@ -43,28 +35,19 @@ pub struct OpaqueUser { } #[test] fn bindgen_test_layout_OpaqueUser() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 164usize, - concat!("Size of: ", stringify!(OpaqueUser)) + ::std::mem::size_of:: < OpaqueUser > (), 164usize, concat!("Size of: ", + stringify!(OpaqueUser)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(OpaqueUser)) + ::std::mem::align_of:: < OpaqueUser > (), 4usize, concat!("Alignment of ", + stringify!(OpaqueUser)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).opaque) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(OpaqueUser), - "::", - stringify!(opaque) - ) + unsafe { ::std::ptr::addr_of!((* ptr).opaque) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(OpaqueUser), "::", stringify!(opaque)) ); } impl Default for OpaqueUser { diff --git a/bindgen-tests/tests/expectations/tests/derive-default-and-blocklist.rs b/bindgen-tests/tests/expectations/tests/derive-default-and-blocklist.rs index fe3790c2e0..d769c01459 100644 --- a/bindgen-tests/tests/expectations/tests/derive-default-and-blocklist.rs +++ b/bindgen-tests/tests/expectations/tests/derive-default-and-blocklist.rs @@ -1,42 +1,27 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub struct BlocklistMe(u8); - -/// Because this type contains a blocklisted type, it should not derive -/// Default. Instead, we should emit a `mem::zeroed` implementation. +/** Because this type contains a blocklisted type, it should not derive + Default. Instead, we should emit a `mem::zeroed` implementation.*/ #[repr(C)] pub struct ShouldNotDeriveDefault { pub a: BlocklistMe, } #[test] fn bindgen_test_layout_ShouldNotDeriveDefault() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(ShouldNotDeriveDefault)) + ::std::mem::size_of:: < ShouldNotDeriveDefault > (), 1usize, concat!("Size of: ", + stringify!(ShouldNotDeriveDefault)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < ShouldNotDeriveDefault > (), 1usize, concat!("Alignment of ", stringify!(ShouldNotDeriveDefault)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldNotDeriveDefault), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(ShouldNotDeriveDefault), "::", + stringify!(a)) ); } impl Default for ShouldNotDeriveDefault { diff --git a/bindgen-tests/tests/expectations/tests/derive-fn-ptr.rs b/bindgen-tests/tests/expectations/tests/derive-fn-ptr.rs index 9da0a40ae6..d5944eee9d 100644 --- a/bindgen-tests/tests/expectations/tests/derive-fn-ptr.rs +++ b/bindgen-tests/tests/expectations/tests/derive-fn-ptr.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type my_fun_t = ::std::option::Option< unsafe extern "C" fn( arg1: ::std::os::raw::c_int, @@ -32,30 +26,18 @@ pub struct Foo { } #[test] fn bindgen_test_layout_Foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of:: < Foo > (), 8usize, concat!("Size of: ", stringify!(Foo)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Foo)) + ::std::mem::align_of:: < Foo > (), 8usize, concat!("Alignment of ", + stringify!(Foo)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).callback) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(callback) - ) + unsafe { ::std::ptr::addr_of!((* ptr).callback) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(callback)) ); } pub type my_fun2_t = ::std::option::Option< @@ -81,29 +63,17 @@ pub struct Bar { } #[test] fn bindgen_test_layout_Bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Bar)) + ::std::mem::size_of:: < Bar > (), 8usize, concat!("Size of: ", stringify!(Bar)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Bar)) + ::std::mem::align_of:: < Bar > (), 8usize, concat!("Alignment of ", + stringify!(Bar)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).callback) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(callback) - ) + unsafe { ::std::ptr::addr_of!((* ptr).callback) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(callback)) ); } diff --git a/bindgen-tests/tests/expectations/tests/derive-hash-and-blocklist.rs b/bindgen-tests/tests/expectations/tests/derive-hash-and-blocklist.rs index c677b15e49..a29c04fd04 100644 --- a/bindgen-tests/tests/expectations/tests/derive-hash-and-blocklist.rs +++ b/bindgen-tests/tests/expectations/tests/derive-hash-and-blocklist.rs @@ -1,12 +1,5 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub struct BlocklistMe(u8); - /// Because this type contains a blocklisted type, it should not derive Hash. #[repr(C)] pub struct ShouldNotDeriveHash { @@ -14,28 +7,20 @@ pub struct ShouldNotDeriveHash { } #[test] fn bindgen_test_layout_ShouldNotDeriveHash() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(ShouldNotDeriveHash)) + ::std::mem::size_of:: < ShouldNotDeriveHash > (), 1usize, concat!("Size of: ", + stringify!(ShouldNotDeriveHash)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < ShouldNotDeriveHash > (), 1usize, concat!("Alignment of ", stringify!(ShouldNotDeriveHash)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldNotDeriveHash), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(ShouldNotDeriveHash), "::", + stringify!(a)) ); } impl Default for ShouldNotDeriveHash { diff --git a/bindgen-tests/tests/expectations/tests/derive-hash-blocklisting.rs b/bindgen-tests/tests/expectations/tests/derive-hash-blocklisting.rs index 868bf9f2a9..4d733f3102 100644 --- a/bindgen-tests/tests/expectations/tests/derive-hash-blocklisting.rs +++ b/bindgen-tests/tests/expectations/tests/derive-hash-blocklisting.rs @@ -1,47 +1,31 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Hash, Copy, Clone, PartialEq, Eq)] pub struct Blocklisted { t: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } - -/// This would derive(Hash, Eq, PartialEq) if it didn't contain a blocklisted type, -/// causing us to conservatively avoid deriving hash/Eq/PartialEq for it. +/** This would derive(Hash, Eq, PartialEq) if it didn't contain a blocklisted type, + causing us to conservatively avoid deriving hash/Eq/PartialEq for it.*/ #[repr(C)] pub struct AllowlistedOne { pub a: Blocklisted<::std::os::raw::c_int>, } #[test] fn bindgen_test_layout_AllowlistedOne() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(AllowlistedOne)) + ::std::mem::size_of:: < AllowlistedOne > (), 4usize, concat!("Size of: ", + stringify!(AllowlistedOne)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(AllowlistedOne)) + ::std::mem::align_of:: < AllowlistedOne > (), 4usize, concat!("Alignment of ", + stringify!(AllowlistedOne)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AllowlistedOne), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(AllowlistedOne), "::", stringify!(a)) ); } impl Default for AllowlistedOne { @@ -60,28 +44,19 @@ pub struct AllowlistedTwo { } #[test] fn bindgen_test_layout_AllowlistedTwo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(AllowlistedTwo)) + ::std::mem::size_of:: < AllowlistedTwo > (), 4usize, concat!("Size of: ", + stringify!(AllowlistedTwo)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(AllowlistedTwo)) + ::std::mem::align_of:: < AllowlistedTwo > (), 4usize, concat!("Alignment of ", + stringify!(AllowlistedTwo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AllowlistedTwo), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(AllowlistedTwo), "::", stringify!(b)) ); } impl Default for AllowlistedTwo { diff --git a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs index 78c8449b58..5c7706c6df 100644 --- a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs +++ b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] /// A struct containing a struct containing a float that cannot derive Hash/Eq/Ord but can derive PartialEq/PartialOrd #[repr(C)] #[derive(Debug, Default, Copy, Clone, PartialOrd, PartialEq)] @@ -19,58 +13,38 @@ pub struct foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)) + ::std::mem::size_of:: < foo__bindgen_ty_1 > (), 8usize, concat!("Size of: ", + stringify!(foo__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) + ::std::mem::align_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", + stringify!(foo__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)) ); } #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of:: < foo > (), 8usize, concat!("Size of: ", stringify!(foo)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) + ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", + stringify!(foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); } diff --git a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-float-array.rs b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-float-array.rs index a3f6013b2a..b9ae54b058 100644 --- a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-float-array.rs +++ b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-float-array.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] /// A struct containing an array of floats that cannot derive Hash/Eq/Ord but can derive PartialEq/PartialOrd #[repr(C)] #[derive(Debug, Default, Copy, Clone, PartialOrd, PartialEq)] @@ -13,22 +7,17 @@ pub struct foo { } #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 12usize, - concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of:: < foo > (), 12usize, concat!("Size of: ", stringify!(foo)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) + ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", + stringify!(foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); } diff --git a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs index 06c8da1bad..93df00c148 100644 --- a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs +++ b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Default)] pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); @@ -43,36 +37,23 @@ pub struct test { } #[test] fn bindgen_test_layout_test() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(test)) + ::std::mem::size_of:: < test > (), 4usize, concat!("Size of: ", stringify!(test)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(test)) + ::std::mem::align_of:: < test > (), 4usize, concat!("Alignment of ", + stringify!(test)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(test), "::", stringify!(a)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(test), - "::", - stringify!(zero_length_array) - ) + unsafe { ::std::ptr::addr_of!((* ptr).zero_length_array) as usize - ptr as usize + }, 4usize, concat!("Offset of field: ", stringify!(test), "::", + stringify!(zero_length_array)) ); } #[repr(C)] @@ -84,14 +65,12 @@ pub struct test2 { #[test] fn bindgen_test_layout_test2() { assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(test2)) + ::std::mem::size_of:: < test2 > (), 4usize, concat!("Size of: ", + stringify!(test2)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(test2)) + ::std::mem::align_of:: < test2 > (), 4usize, concat!("Alignment of ", + stringify!(test2)) ); } #[repr(C)] @@ -104,13 +83,11 @@ pub struct test3 { #[test] fn bindgen_test_layout_test3() { assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(test3)) + ::std::mem::size_of:: < test3 > (), 4usize, concat!("Size of: ", + stringify!(test3)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(test3)) + ::std::mem::align_of:: < test3 > (), 4usize, concat!("Alignment of ", + stringify!(test3)) ); } diff --git a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-pointer.rs b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-pointer.rs index 3efd55c9d2..b66332318f 100644 --- a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-pointer.rs +++ b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-pointer.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] /// Pointers can derive Hash/PartialOrd/Ord/PartialEq/Eq #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] @@ -13,28 +7,19 @@ pub struct ConstPtrMutObj { } #[test] fn bindgen_test_layout_ConstPtrMutObj() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(ConstPtrMutObj)) + ::std::mem::size_of:: < ConstPtrMutObj > (), 8usize, concat!("Size of: ", + stringify!(ConstPtrMutObj)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(ConstPtrMutObj)) + ::std::mem::align_of:: < ConstPtrMutObj > (), 8usize, concat!("Alignment of ", + stringify!(ConstPtrMutObj)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ConstPtrMutObj), - "::", - stringify!(bar) - ) + unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(ConstPtrMutObj), "::", stringify!(bar)) ); } impl Default for ConstPtrMutObj { @@ -53,28 +38,19 @@ pub struct MutPtrMutObj { } #[test] fn bindgen_test_layout_MutPtrMutObj() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(MutPtrMutObj)) + ::std::mem::size_of:: < MutPtrMutObj > (), 8usize, concat!("Size of: ", + stringify!(MutPtrMutObj)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(MutPtrMutObj)) + ::std::mem::align_of:: < MutPtrMutObj > (), 8usize, concat!("Alignment of ", + stringify!(MutPtrMutObj)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(MutPtrMutObj), - "::", - stringify!(bar) - ) + unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(MutPtrMutObj), "::", stringify!(bar)) ); } impl Default for MutPtrMutObj { @@ -93,28 +69,19 @@ pub struct MutPtrConstObj { } #[test] fn bindgen_test_layout_MutPtrConstObj() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(MutPtrConstObj)) + ::std::mem::size_of:: < MutPtrConstObj > (), 8usize, concat!("Size of: ", + stringify!(MutPtrConstObj)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(MutPtrConstObj)) + ::std::mem::align_of:: < MutPtrConstObj > (), 8usize, concat!("Alignment of ", + stringify!(MutPtrConstObj)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(MutPtrConstObj), - "::", - stringify!(bar) - ) + unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(MutPtrConstObj), "::", stringify!(bar)) ); } impl Default for MutPtrConstObj { @@ -133,28 +100,19 @@ pub struct ConstPtrConstObj { } #[test] fn bindgen_test_layout_ConstPtrConstObj() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(ConstPtrConstObj)) + ::std::mem::size_of:: < ConstPtrConstObj > (), 8usize, concat!("Size of: ", + stringify!(ConstPtrConstObj)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(ConstPtrConstObj)) + ::std::mem::align_of:: < ConstPtrConstObj > (), 8usize, concat!("Alignment of ", + stringify!(ConstPtrConstObj)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ConstPtrConstObj), - "::", - stringify!(bar) - ) + unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(ConstPtrConstObj), "::", stringify!(bar)) ); } impl Default for ConstPtrConstObj { diff --git a/bindgen-tests/tests/expectations/tests/derive-hash-template-def-float.rs b/bindgen-tests/tests/expectations/tests/derive-hash-template-def-float.rs index 5e07a61115..cf251c4508 100644 --- a/bindgen-tests/tests/expectations/tests/derive-hash-template-def-float.rs +++ b/bindgen-tests/tests/expectations/tests/derive-hash-template-def-float.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] /// Template definition containing a float, which cannot derive Hash/Eq/Ord but can derive PartialEq/PartialOrd. #[repr(C)] #[derive(Debug, Copy, Clone, PartialOrd, PartialEq)] diff --git a/bindgen-tests/tests/expectations/tests/derive-hash-template-inst-float.rs b/bindgen-tests/tests/expectations/tests/derive-hash-template-inst-float.rs index b2e2d8d088..cdece306e0 100644 --- a/bindgen-tests/tests/expectations/tests/derive-hash-template-inst-float.rs +++ b/bindgen-tests/tests/expectations/tests/derive-hash-template-inst-float.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] /// Template definition that doesn't contain float can derive Hash/PartialOrd/Ord/PartialEq/Eq #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] @@ -29,22 +23,18 @@ pub struct IntStr { } #[test] fn bindgen_test_layout_IntStr() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(IntStr)) + ::std::mem::size_of:: < IntStr > (), 4usize, concat!("Size of: ", + stringify!(IntStr)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(IntStr)) + ::std::mem::align_of:: < IntStr > (), 4usize, concat!("Alignment of ", + stringify!(IntStr)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(IntStr), "::", stringify!(a)) ); } @@ -65,28 +55,19 @@ pub struct FloatStr { } #[test] fn bindgen_test_layout_FloatStr() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(FloatStr)) + ::std::mem::size_of:: < FloatStr > (), 4usize, concat!("Size of: ", + stringify!(FloatStr)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(FloatStr)) + ::std::mem::align_of:: < FloatStr > (), 4usize, concat!("Alignment of ", + stringify!(FloatStr)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(FloatStr), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(FloatStr), "::", stringify!(a)) ); } impl Default for FloatStr { @@ -101,35 +82,24 @@ impl Default for FloatStr { #[test] fn __bindgen_test_layout_foo_open0_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!( - "Size of template specialization: ", - stringify!(foo<::std::os::raw::c_int>) - ) + ::std::mem::size_of:: < foo < ::std::os::raw::c_int > > (), 4usize, + concat!("Size of template specialization: ", stringify!(foo < + ::std::os::raw::c_int >)) ); assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(foo<::std::os::raw::c_int>) - ) + ::std::mem::align_of:: < foo < ::std::os::raw::c_int > > (), 4usize, + concat!("Alignment of template specialization: ", stringify!(foo < + ::std::os::raw::c_int >)) ); } #[test] fn __bindgen_test_layout_foo_open0_float_close0_instantiation() { assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!("Size of template specialization: ", stringify!(foo)) + ::std::mem::size_of:: < foo < f32 > > (), 4usize, + concat!("Size of template specialization: ", stringify!(foo < f32 >)) ); assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(foo) - ) + ::std::mem::align_of:: < foo < f32 > > (), 4usize, + concat!("Alignment of template specialization: ", stringify!(foo < f32 >)) ); } diff --git a/bindgen-tests/tests/expectations/tests/derive-partialeq-and-blocklist.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-and-blocklist.rs index c772c0b90e..52552dd746 100644 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-and-blocklist.rs +++ b/bindgen-tests/tests/expectations/tests/derive-partialeq-and-blocklist.rs @@ -1,42 +1,27 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub struct BlocklistMe(u8); - -/// Because this type contains a blocklisted type, it should not derive -/// PartialEq. +/** Because this type contains a blocklisted type, it should not derive + PartialEq.*/ #[repr(C)] pub struct ShouldNotDerivePartialEq { pub a: BlocklistMe, } #[test] fn bindgen_test_layout_ShouldNotDerivePartialEq() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 1usize, + ::std::mem::size_of:: < ShouldNotDerivePartialEq > (), 1usize, concat!("Size of: ", stringify!(ShouldNotDerivePartialEq)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < ShouldNotDerivePartialEq > (), 1usize, concat!("Alignment of ", stringify!(ShouldNotDerivePartialEq)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldNotDerivePartialEq), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(ShouldNotDerivePartialEq), "::", + stringify!(a)) ); } impl Default for ShouldNotDerivePartialEq { diff --git a/bindgen-tests/tests/expectations/tests/derive-partialeq-anonfield.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-anonfield.rs index 16d4381f86..3dc27a0d30 100644 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-anonfield.rs +++ b/bindgen-tests/tests/expectations/tests/derive-partialeq-anonfield.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[repr(align(64))] #[derive(Copy, Clone)] @@ -20,13 +14,11 @@ pub struct rte_mbuf__bindgen_ty_1 { #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_1() { assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_1)) + ::std::mem::size_of:: < rte_mbuf__bindgen_ty_1 > (), 0usize, concat!("Size of: ", + stringify!(rte_mbuf__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < rte_mbuf__bindgen_ty_1 > (), 1usize, concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_1)) ); } @@ -42,14 +34,12 @@ impl Default for rte_mbuf__bindgen_ty_1 { #[test] fn bindgen_test_layout_rte_mbuf() { assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(rte_mbuf)) + ::std::mem::size_of:: < rte_mbuf > (), 0usize, concat!("Size of: ", + stringify!(rte_mbuf)) ); assert_eq!( - ::std::mem::align_of::(), - 64usize, - concat!("Alignment of ", stringify!(rte_mbuf)) + ::std::mem::align_of:: < rte_mbuf > (), 64usize, concat!("Alignment of ", + stringify!(rte_mbuf)) ); } impl Default for rte_mbuf { diff --git a/bindgen-tests/tests/expectations/tests/derive-partialeq-base.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-base.rs index 840720f28d..950e954bc3 100644 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-base.rs +++ b/bindgen-tests/tests/expectations/tests/derive-partialeq-base.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone)] pub struct Base { @@ -12,28 +6,19 @@ pub struct Base { } #[test] fn bindgen_test_layout_Base() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 132usize, - concat!("Size of: ", stringify!(Base)) + ::std::mem::size_of:: < Base > (), 132usize, concat!("Size of: ", + stringify!(Base)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Base)) + ::std::mem::align_of:: < Base > (), 4usize, concat!("Alignment of ", + stringify!(Base)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).large) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Base), - "::", - stringify!(large) - ) + unsafe { ::std::ptr::addr_of!((* ptr).large) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(Base), "::", stringify!(large)) ); } impl Default for Base { @@ -58,13 +43,11 @@ pub struct ShouldDerivePartialEq { #[test] fn bindgen_test_layout_ShouldDerivePartialEq() { assert_eq!( - ::std::mem::size_of::(), - 132usize, + ::std::mem::size_of:: < ShouldDerivePartialEq > (), 132usize, concat!("Size of: ", stringify!(ShouldDerivePartialEq)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < ShouldDerivePartialEq > (), 4usize, concat!("Alignment of ", stringify!(ShouldDerivePartialEq)) ); } diff --git a/bindgen-tests/tests/expectations/tests/derive-partialeq-bitfield.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-bitfield.rs index cb9781dea6..0bf1298af0 100644 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/derive-partialeq-bitfield.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -100,30 +92,18 @@ pub struct C { } #[test] fn bindgen_test_layout_C() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 204usize, - concat!("Size of: ", stringify!(C)) + ::std::mem::size_of:: < C > (), 204usize, concat!("Size of: ", stringify!(C)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C)) + ::std::mem::align_of:: < C > (), 4usize, concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(large_array) - ) + unsafe { ::std::ptr::addr_of!((* ptr).large_array) as usize - ptr as usize }, + 4usize, concat!("Offset of field: ", stringify!(C), "::", + stringify!(large_array)) ); } impl Default for C { @@ -137,17 +117,14 @@ 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[..] + self.a() == other.a() && self.b() == other.b() + && &self.large_array[..] == &other.large_array[..] } } impl C { #[inline] pub fn a(&self) -> bool { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) } } #[inline] pub fn set_a(&mut self, val: bool) { @@ -158,9 +135,7 @@ impl C { } #[inline] pub fn b(&self) -> bool { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(1usize, 7u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 7u8) as u8) } } #[inline] pub fn set_b(&mut self, val: bool) { @@ -170,20 +145,26 @@ impl C { } } #[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.set(0usize, 1u8, { - let a: u8 = unsafe { ::std::mem::transmute(a) }; - a as u64 - }); - __bindgen_bitfield_unit.set(1usize, 7u8, { - let b: u8 = unsafe { ::std::mem::transmute(b) }; - b as u64 - }); + 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 + .set( + 0usize, + 1u8, + { + let a: u8 = unsafe { ::std::mem::transmute(a) }; + a as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 1usize, + 7u8, + { + let b: u8 = unsafe { ::std::mem::transmute(b) }; + b as u64 + }, + ); __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 620b40faf9..e2d991a898 100644 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-core.rs +++ b/bindgen-tests/tests/expectations/tests/derive-partialeq-core.rs @@ -1,12 +1,5 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern crate core; - #[repr(C)] #[derive(Copy, Clone)] pub struct C { @@ -14,30 +7,18 @@ pub struct C { } #[test] fn bindgen_test_layout_C() { - const UNINIT: ::core::mem::MaybeUninit = - ::core::mem::MaybeUninit::uninit(); + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::core::mem::size_of::(), - 1680usize, - concat!("Size of: ", stringify!(C)) + ::core::mem::size_of:: < C > (), 1680usize, concat!("Size of: ", stringify!(C)) ); assert_eq!( - ::core::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C)) + ::core::mem::align_of:: < C > (), 4usize, concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { - ::core::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(large_array) - ) + unsafe { ::core::ptr::addr_of!((* ptr).large_array) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(C), "::", + stringify!(large_array)) ); } impl Default for C { diff --git a/bindgen-tests/tests/expectations/tests/derive-partialeq-pointer.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-pointer.rs index e0d3c0629e..3cd6c46b00 100644 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-pointer.rs +++ b/bindgen-tests/tests/expectations/tests/derive-partialeq-pointer.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Bar { @@ -12,22 +6,17 @@ pub struct Bar { } #[test] fn bindgen_test_layout_Bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Bar)) + ::std::mem::size_of:: < Bar > (), 8usize, concat!("Size of: ", stringify!(Bar)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Bar)) + ::std::mem::align_of:: < Bar > (), 8usize, concat!("Alignment of ", + stringify!(Bar)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(b)) ); } @@ -53,14 +42,12 @@ pub union c__bindgen_ty_1 { #[test] fn bindgen_test_layout_c__bindgen_ty_1() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(c__bindgen_ty_1)) + ::std::mem::size_of:: < c__bindgen_ty_1 > (), 1usize, concat!("Size of: ", + stringify!(c__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(c__bindgen_ty_1)) + ::std::mem::align_of:: < c__bindgen_ty_1 > (), 1usize, concat!("Alignment of ", + stringify!(c__bindgen_ty_1)) ); } impl Default for c__bindgen_ty_1 { @@ -75,14 +62,10 @@ impl Default for c__bindgen_ty_1 { #[test] fn bindgen_test_layout_c() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(c)) + ::std::mem::size_of:: < c > (), 1usize, concat!("Size of: ", stringify!(c)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(c)) + ::std::mem::align_of:: < c > (), 1usize, concat!("Alignment of ", stringify!(c)) ); } impl Default for c { @@ -101,22 +84,16 @@ pub struct a { } #[test] fn bindgen_test_layout_a() { - const UNINIT: ::std::mem::MaybeUninit
= - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(a)) + ::std::mem::size_of:: < a > (), 1usize, concat!("Size of: ", stringify!(a)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(a)) + ::std::mem::align_of:: < a > (), 1usize, concat!("Alignment of ", stringify!(a)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).d) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(a), "::", stringify!(d)) ); } diff --git a/bindgen-tests/tests/expectations/tests/derive-partialeq-union.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-union.rs index 5ffd0bcd3b..511e4b8891 100644 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-union.rs +++ b/bindgen-tests/tests/expectations/tests/derive-partialeq-union.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] /// Deriving PartialEq for rust unions is not supported. #[repr(C)] #[derive(Copy, Clone)] @@ -14,38 +8,25 @@ pub union ShouldNotDerivePartialEq { } #[test] fn bindgen_test_layout_ShouldNotDerivePartialEq() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, + ::std::mem::size_of:: < ShouldNotDerivePartialEq > (), 4usize, concat!("Size of: ", stringify!(ShouldNotDerivePartialEq)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < ShouldNotDerivePartialEq > (), 4usize, concat!("Alignment of ", stringify!(ShouldNotDerivePartialEq)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldNotDerivePartialEq), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(ShouldNotDerivePartialEq), "::", + stringify!(a)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldNotDerivePartialEq), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(ShouldNotDerivePartialEq), "::", + stringify!(b)) ); } impl Default for ShouldNotDerivePartialEq { diff --git a/bindgen-tests/tests/expectations/tests/derive-partialeq-union_1_0.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-union_1_0.rs index a53b9ba8e6..07b97b00de 100644 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/derive-partialeq-union_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -58,38 +52,25 @@ pub struct ShouldDerivePartialEq { } #[test] fn bindgen_test_layout_ShouldDerivePartialEq() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 152usize, + ::std::mem::size_of:: < ShouldDerivePartialEq > (), 152usize, concat!("Size of: ", stringify!(ShouldDerivePartialEq)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < ShouldDerivePartialEq > (), 4usize, concat!("Alignment of ", stringify!(ShouldDerivePartialEq)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldDerivePartialEq), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(ShouldDerivePartialEq), "::", + stringify!(a)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldDerivePartialEq), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(ShouldDerivePartialEq), "::", + stringify!(b)) ); } impl Clone for ShouldDerivePartialEq { diff --git a/bindgen-tests/tests/expectations/tests/disable-namespacing.rs b/bindgen-tests/tests/expectations/tests/disable-namespacing.rs index 626bb060c5..4d9b6a082d 100644 --- a/bindgen-tests/tests/expectations/tests/disable-namespacing.rs +++ b/bindgen-tests/tests/expectations/tests/disable-namespacing.rs @@ -1,8 +1,2 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type Baz = ::std::os::raw::c_int; diff --git a/bindgen-tests/tests/expectations/tests/disable-nested-struct-naming.rs b/bindgen-tests/tests/expectations/tests/disable-nested-struct-naming.rs index ce8a01ada3..d9e53cc773 100644 --- a/bindgen-tests/tests/expectations/tests/disable-nested-struct-naming.rs +++ b/bindgen-tests/tests/expectations/tests/disable-nested-struct-naming.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct foo { @@ -35,144 +29,100 @@ pub struct bar4 { } #[test] fn bindgen_test_layout_bar4() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(bar4)) + ::std::mem::size_of:: < bar4 > (), 4usize, concat!("Size of: ", stringify!(bar4)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(bar4)) + ::std::mem::align_of:: < bar4 > (), 4usize, concat!("Alignment of ", + stringify!(bar4)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x4) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).x4) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(bar4), "::", stringify!(x4)) ); } #[test] fn bindgen_test_layout_bar1__bindgen_ty_1__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, + ::std::mem::size_of:: < bar1__bindgen_ty_1__bindgen_ty_1 > (), 8usize, concat!("Size of: ", stringify!(bar1__bindgen_ty_1__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!( - "Alignment of ", - stringify!(bar1__bindgen_ty_1__bindgen_ty_1) - ) + ::std::mem::align_of:: < bar1__bindgen_ty_1__bindgen_ty_1 > (), 4usize, + concat!("Alignment of ", stringify!(bar1__bindgen_ty_1__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x3) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(bar1__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(x3) - ) + unsafe { ::std::ptr::addr_of!((* ptr).x3) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(bar1__bindgen_ty_1__bindgen_ty_1), "::", + stringify!(x3)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b4) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(bar1__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(b4) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b4) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(bar1__bindgen_ty_1__bindgen_ty_1), "::", + stringify!(b4)) ); } #[test] fn bindgen_test_layout_bar1__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 12usize, - concat!("Size of: ", stringify!(bar1__bindgen_ty_1)) + ::std::mem::size_of:: < bar1__bindgen_ty_1 > (), 12usize, concat!("Size of: ", + stringify!(bar1__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < bar1__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", stringify!(bar1__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x2) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(bar1__bindgen_ty_1), - "::", - stringify!(x2) - ) + unsafe { ::std::ptr::addr_of!((* ptr).x2) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(bar1__bindgen_ty_1), "::", + stringify!(x2)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b3) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(bar1__bindgen_ty_1), - "::", - stringify!(b3) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b3) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(bar1__bindgen_ty_1), "::", + stringify!(b3)) ); } #[test] fn bindgen_test_layout_bar1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(bar1)) + ::std::mem::size_of:: < bar1 > (), 16usize, concat!("Size of: ", + stringify!(bar1)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(bar1)) + ::std::mem::align_of:: < bar1 > (), 4usize, concat!("Alignment of ", + stringify!(bar1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x1) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).x1) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(bar1), "::", stringify!(x1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b2) as usize - ptr as usize }, - 4usize, + unsafe { ::std::ptr::addr_of!((* ptr).b2) as usize - ptr as usize }, 4usize, concat!("Offset of field: ", stringify!(bar1), "::", stringify!(b2)) ); } #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of:: < foo > (), 16usize, concat!("Size of: ", stringify!(foo)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) + ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", + stringify!(foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b1) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).b1) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(b1)) ); } @@ -193,75 +143,53 @@ pub struct baz { } #[test] fn bindgen_test_layout_baz() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(baz)) + ::std::mem::size_of:: < baz > (), 4usize, concat!("Size of: ", stringify!(baz)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(baz)) + ::std::mem::align_of:: < baz > (), 4usize, concat!("Alignment of ", + stringify!(baz)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).x) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(baz), "::", stringify!(x)) ); } #[test] fn bindgen_test_layout__bindgen_ty_1__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit<_bindgen_ty_1__bindgen_ty_1> = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit<_bindgen_ty_1__bindgen_ty_1> = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::<_bindgen_ty_1__bindgen_ty_1>(), - 4usize, + ::std::mem::size_of:: < _bindgen_ty_1__bindgen_ty_1 > (), 4usize, concat!("Size of: ", stringify!(_bindgen_ty_1__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::<_bindgen_ty_1__bindgen_ty_1>(), - 4usize, + ::std::mem::align_of:: < _bindgen_ty_1__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", stringify!(_bindgen_ty_1__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(_bindgen_ty_1__bindgen_ty_1), "::", + stringify!(b)) ); } #[test] fn bindgen_test_layout__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit<_bindgen_ty_1> = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit<_bindgen_ty_1> = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::<_bindgen_ty_1>(), - 4usize, - concat!("Size of: ", stringify!(_bindgen_ty_1)) + ::std::mem::size_of:: < _bindgen_ty_1 > (), 4usize, concat!("Size of: ", + stringify!(_bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::<_bindgen_ty_1>(), - 4usize, - concat!("Alignment of ", stringify!(_bindgen_ty_1)) + ::std::mem::align_of:: < _bindgen_ty_1 > (), 4usize, concat!("Alignment of ", + stringify!(_bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).anon2) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_bindgen_ty_1), - "::", - stringify!(anon2) - ) + unsafe { ::std::ptr::addr_of!((* ptr).anon2) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(_bindgen_ty_1), "::", stringify!(anon2)) ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/disable-untagged-union.rs b/bindgen-tests/tests/expectations/tests/disable-untagged-union.rs index 515f496b87..d2913f4802 100644 --- a/bindgen-tests/tests/expectations/tests/disable-untagged-union.rs +++ b/bindgen-tests/tests/expectations/tests/disable-untagged-union.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -57,27 +51,21 @@ pub struct Foo { } #[test] fn bindgen_test_layout_Foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of:: < Foo > (), 4usize, concat!("Size of: ", stringify!(Foo)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Foo)) + ::std::mem::align_of:: < Foo > (), 4usize, concat!("Alignment of ", + stringify!(Foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).baz) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(baz)) ); } diff --git a/bindgen-tests/tests/expectations/tests/divide-by-zero-in-struct-layout.rs b/bindgen-tests/tests/expectations/tests/divide-by-zero-in-struct-layout.rs index 721d71e259..18221499b2 100644 --- a/bindgen-tests/tests/expectations/tests/divide-by-zero-in-struct-layout.rs +++ b/bindgen-tests/tests/expectations/tests/divide-by-zero-in-struct-layout.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -101,8 +93,7 @@ pub struct WithBitfield { impl WithBitfield { #[inline] pub fn new_bitfield_1() -> __BindgenBitfieldUnit<[u8; 1usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = - Default::default(); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); __bindgen_bitfield_unit } } @@ -116,8 +107,7 @@ pub struct WithBitfieldAndAttrPacked { impl WithBitfieldAndAttrPacked { #[inline] pub fn new_bitfield_1() -> __BindgenBitfieldUnit<[u8; 1usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = - Default::default(); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); __bindgen_bitfield_unit } } @@ -131,8 +121,7 @@ pub struct WithBitfieldAndPacked { impl WithBitfieldAndPacked { #[inline] pub fn new_bitfield_1() -> __BindgenBitfieldUnit<[u8; 1usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = - Default::default(); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); __bindgen_bitfield_unit } } diff --git a/bindgen-tests/tests/expectations/tests/do-not-derive-copy.rs b/bindgen-tests/tests/expectations/tests/do-not-derive-copy.rs index 4f9081adf4..3fcfce4f1f 100644 --- a/bindgen-tests/tests/expectations/tests/do-not-derive-copy.rs +++ b/bindgen-tests/tests/expectations/tests/do-not-derive-copy.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default)] pub struct WouldBeCopyButWeAreNotDerivingCopy { @@ -12,30 +6,19 @@ pub struct WouldBeCopyButWeAreNotDerivingCopy { } #[test] fn bindgen_test_layout_WouldBeCopyButWeAreNotDerivingCopy() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, + ::std::mem::size_of:: < WouldBeCopyButWeAreNotDerivingCopy > (), 4usize, concat!("Size of: ", stringify!(WouldBeCopyButWeAreNotDerivingCopy)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!( - "Alignment of ", - stringify!(WouldBeCopyButWeAreNotDerivingCopy) - ) + ::std::mem::align_of:: < WouldBeCopyButWeAreNotDerivingCopy > (), 4usize, + concat!("Alignment of ", stringify!(WouldBeCopyButWeAreNotDerivingCopy)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WouldBeCopyButWeAreNotDerivingCopy), - "::", - stringify!(x) - ) + unsafe { ::std::ptr::addr_of!((* ptr).x) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(WouldBeCopyButWeAreNotDerivingCopy), + "::", stringify!(x)) ); } diff --git a/bindgen-tests/tests/expectations/tests/doggo-or-null.rs b/bindgen-tests/tests/expectations/tests/doggo-or-null.rs index 9028715958..3129bf99a3 100644 --- a/bindgen-tests/tests/expectations/tests/doggo-or-null.rs +++ b/bindgen-tests/tests/expectations/tests/doggo-or-null.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq)] pub struct Doggo { @@ -12,22 +6,18 @@ pub struct Doggo { } #[test] fn bindgen_test_layout_Doggo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Doggo)) + ::std::mem::size_of:: < Doggo > (), 4usize, concat!("Size of: ", + stringify!(Doggo)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Doggo)) + ::std::mem::align_of:: < Doggo > (), 4usize, concat!("Alignment of ", + stringify!(Doggo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).x) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Doggo), "::", stringify!(x)) ); } @@ -39,22 +29,19 @@ pub struct Null { #[test] fn bindgen_test_layout_Null() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Null)) + ::std::mem::size_of:: < Null > (), 1usize, concat!("Size of: ", stringify!(Null)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Null)) + ::std::mem::align_of:: < Null > (), 1usize, concat!("Alignment of ", + stringify!(Null)) ); } -/// This type is an opaque union. Unions can't derive anything interesting like -/// Debug or Default, even if their layout can, because it would require knowing -/// which variant is in use. Opaque unions still end up as a `union` in the Rust -/// bindings, but they just have one variant. Even so, can't derive. We should -/// probably emit an opaque struct for opaque unions... but until then, we have -/// this test to make sure that opaque unions don't derive and still compile. +/** This type is an opaque union. Unions can't derive anything interesting like + Debug or Default, even if their layout can, because it would require knowing + which variant is in use. Opaque unions still end up as a `union` in the Rust + bindings, but they just have one variant. Even so, can't derive. We should + probably emit an opaque struct for opaque unions... but until then, we have + this test to make sure that opaque unions don't derive and still compile.*/ #[repr(C)] #[repr(align(4))] #[derive(Copy, Clone)] @@ -64,14 +51,12 @@ pub union DoggoOrNull { #[test] fn bindgen_test_layout_DoggoOrNull() { assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(DoggoOrNull)) + ::std::mem::size_of:: < DoggoOrNull > (), 4usize, concat!("Size of: ", + stringify!(DoggoOrNull)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(DoggoOrNull)) + ::std::mem::align_of:: < DoggoOrNull > (), 4usize, concat!("Alignment of ", + stringify!(DoggoOrNull)) ); } impl Default for DoggoOrNull { diff --git a/bindgen-tests/tests/expectations/tests/dupe-enum-variant-in-namespace.rs b/bindgen-tests/tests/expectations/tests/dupe-enum-variant-in-namespace.rs index 85e4539253..d521bcc17b 100644 --- a/bindgen-tests/tests/expectations/tests/dupe-enum-variant-in-namespace.rs +++ b/bindgen-tests/tests/expectations/tests/dupe-enum-variant-in-namespace.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![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 { #[allow(unused_imports)] diff --git a/bindgen-tests/tests/expectations/tests/duplicated-definition-count.rs b/bindgen-tests/tests/expectations/tests/duplicated-definition-count.rs index 829022a279..3115d9cf9e 100644 --- a/bindgen-tests/tests/expectations/tests/duplicated-definition-count.rs +++ b/bindgen-tests/tests/expectations/tests/duplicated-definition-count.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct BitStream { @@ -13,14 +7,12 @@ pub struct BitStream { #[test] fn bindgen_test_layout_BitStream() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(BitStream)) + ::std::mem::size_of:: < BitStream > (), 1usize, concat!("Size of: ", + stringify!(BitStream)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(BitStream)) + ::std::mem::align_of:: < BitStream > (), 1usize, concat!("Alignment of ", + stringify!(BitStream)) ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/duplicated-namespaces-definitions.rs b/bindgen-tests/tests/expectations/tests/duplicated-namespaces-definitions.rs index 8e7c895bf0..a491547e36 100644 --- a/bindgen-tests/tests/expectations/tests/duplicated-namespaces-definitions.rs +++ b/bindgen-tests/tests/expectations/tests/duplicated-namespaces-definitions.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![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 { #[allow(unused_imports)] @@ -20,42 +14,25 @@ pub mod root { } #[test] fn bindgen_test_layout_Bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Bar)) + ::std::mem::size_of:: < Bar > (), 8usize, concat!("Size of: ", + stringify!(Bar)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Bar)) + ::std::mem::align_of:: < Bar > (), 4usize, concat!("Alignment of ", + stringify!(Bar)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(foo) - ) + unsafe { ::std::ptr::addr_of!((* ptr).foo) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(Bar), "::", + stringify!(foo)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(baz) - ) + unsafe { ::std::ptr::addr_of!((* ptr).baz) as usize - ptr as usize }, + 4usize, concat!("Offset of field: ", stringify!(Bar), "::", + stringify!(baz)) ); } } @@ -69,30 +46,20 @@ pub mod root { } #[test] fn bindgen_test_layout_Foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of:: < Foo > (), 8usize, concat!("Size of: ", + stringify!(Foo)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Foo)) + ::std::mem::align_of:: < Foo > (), 8usize, concat!("Alignment of ", + stringify!(Foo)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(ptr) - ) + unsafe { ::std::ptr::addr_of!((* ptr).ptr) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(Foo), "::", + stringify!(ptr)) ); } impl Default for Foo { diff --git a/bindgen-tests/tests/expectations/tests/duplicated-namespaces.rs b/bindgen-tests/tests/expectations/tests/duplicated-namespaces.rs index 0bbceac8e2..c652d151b8 100644 --- a/bindgen-tests/tests/expectations/tests/duplicated-namespaces.rs +++ b/bindgen-tests/tests/expectations/tests/duplicated-namespaces.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![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 { #[allow(unused_imports)] diff --git a/bindgen-tests/tests/expectations/tests/duplicated_constants_in_ns.rs b/bindgen-tests/tests/expectations/tests/duplicated_constants_in_ns.rs index 3b3405db5c..2f676374ae 100644 --- a/bindgen-tests/tests/expectations/tests/duplicated_constants_in_ns.rs +++ b/bindgen-tests/tests/expectations/tests/duplicated_constants_in_ns.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![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 { #[allow(unused_imports)] diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_attributes.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_attributes.rs index c834752e3c..7682884bbb 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_attributes.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_attributes.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern crate libloading; pub struct TestLib { __library: ::libloading::Library, @@ -22,27 +16,21 @@ impl TestLib { let library = ::libloading::Library::new(path)?; Self::from_library(library) } - pub unsafe fn from_library( - library: L, - ) -> Result + pub unsafe fn from_library(library: L) -> Result where L: Into<::libloading::Library>, { let __library = library.into(); let foo = __library.get(b"foo\0").map(|sym| *sym)?; let baz = __library.get(b"baz\0").map(|sym| *sym)?; - Ok(TestLib { - __library, - foo, - baz, - }) + Ok(TestLib { __library, foo, baz }) } #[must_use] - /// @brief A function - /// - /// @param x - /// @param y - /// @return int + /** @brief A function + + @param x + @param y + @return int*/ pub unsafe fn foo( &self, x: ::std::os::raw::c_int, diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_required.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_required.rs index e46ffd49e0..6fd97e4a46 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_required.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_required.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern crate libloading; pub struct TestLib { __library: ::libloading::Library, @@ -25,9 +19,7 @@ impl TestLib { let library = ::libloading::Library::new(path)?; Self::from_library(library) } - pub unsafe fn from_library( - library: L, - ) -> Result + pub unsafe fn from_library(library: L) -> Result where L: Into<::libloading::Library>, { @@ -49,10 +41,7 @@ impl TestLib { ) -> ::std::os::raw::c_int { (self.foo)(x, y) } - pub unsafe fn bar( - &self, - x: *mut ::std::os::raw::c_void, - ) -> ::std::os::raw::c_int { + pub unsafe fn bar(&self, x: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int { (self.bar)(x) } pub unsafe fn baz(&self) -> ::std::os::raw::c_int { diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_simple.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_simple.rs index cae5bd6937..cdacf3ab42 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_simple.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_simple.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern crate libloading; pub struct TestLib { __library: ::libloading::Library, @@ -16,9 +10,7 @@ pub struct TestLib { ::libloading::Error, >, pub bar: Result< - unsafe extern "C" fn( - x: *mut ::std::os::raw::c_void, - ) -> ::std::os::raw::c_int, + unsafe extern "C" fn(x: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int, ::libloading::Error, >, pub baz: Result< @@ -34,9 +26,7 @@ impl TestLib { let library = ::libloading::Library::new(path)?; Self::from_library(library) } - pub unsafe fn from_library( - library: L, - ) -> Result + pub unsafe fn from_library(library: L) -> Result where L: Into<::libloading::Library>, { @@ -58,10 +48,7 @@ impl TestLib { ) -> ::std::os::raw::c_int { (self.foo.as_ref().expect("Expected function, got error."))(x, y) } - pub unsafe fn bar( - &self, - x: *mut ::std::os::raw::c_void, - ) -> ::std::os::raw::c_int { + pub unsafe fn bar(&self, x: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int { (self.bar.as_ref().expect("Expected function, got error."))(x) } pub unsafe fn baz(&self) -> ::std::os::raw::c_int { diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_template.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_template.rs index 06e67ed791..65c36e4893 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_template.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_template.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern crate libloading; pub struct TestLib { __library: ::libloading::Library, @@ -22,25 +16,16 @@ impl TestLib { let library = ::libloading::Library::new(path)?; Self::from_library(library) } - pub unsafe fn from_library( - library: L, - ) -> Result + pub unsafe fn from_library(library: L) -> Result where L: Into<::libloading::Library>, { let __library = library.into(); let foo = __library.get(b"foo\0").map(|sym| *sym); let foo1 = __library.get(b"foo1\0").map(|sym| *sym); - Ok(TestLib { - __library, - foo, - foo1, - }) + Ok(TestLib { __library, foo, foo1 }) } - pub unsafe fn foo( - &self, - x: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int { + pub unsafe fn foo(&self, x: ::std::os::raw::c_int) -> ::std::os::raw::c_int { (self.foo.as_ref().expect("Expected function, got error."))(x) } pub unsafe fn foo1(&self, x: f32) -> f32 { diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_allowlist.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_allowlist.rs index 97bb67abdc..06fffc3d47 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_allowlist.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_allowlist.rs @@ -1,30 +1,17 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern crate libloading; pub struct TestLib { __library: ::libloading::Library, pub foo: Result< - unsafe extern "C" fn( - x: *mut ::std::os::raw::c_void, - ) -> ::std::os::raw::c_int, + unsafe extern "C" fn(x: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int, ::libloading::Error, >, pub baz: Result< - unsafe extern "C" fn( - x: *mut ::std::os::raw::c_void, - ) -> ::std::os::raw::c_int, + unsafe extern "C" fn(x: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int, ::libloading::Error, >, pub bazz: Result< - unsafe extern "C" fn( - arg1: ::std::os::raw::c_int, - ... - ) -> ::std::os::raw::c_int, + unsafe extern "C" fn(arg1: ::std::os::raw::c_int, ...) -> ::std::os::raw::c_int, ::libloading::Error, >, } @@ -36,9 +23,7 @@ impl TestLib { let library = ::libloading::Library::new(path)?; Self::from_library(library) } - pub unsafe fn from_library( - library: L, - ) -> Result + pub unsafe fn from_library(library: L) -> Result where L: Into<::libloading::Library>, { @@ -53,16 +38,10 @@ impl TestLib { bazz, }) } - pub unsafe fn foo( - &self, - x: *mut ::std::os::raw::c_void, - ) -> ::std::os::raw::c_int { + pub unsafe fn foo(&self, x: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int { (self.foo.as_ref().expect("Expected function, got error."))(x) } - pub unsafe fn baz( - &self, - x: *mut ::std::os::raw::c_void, - ) -> ::std::os::raw::c_int { + pub unsafe fn baz(&self, x: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int { (self.baz.as_ref().expect("Expected function, got error."))(x) } } diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_blocklist.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_blocklist.rs index af482ad938..59c3c4273d 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_blocklist.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_blocklist.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct X { @@ -12,22 +6,16 @@ pub struct X { } #[test] fn bindgen_test_layout_X() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(X)) + ::std::mem::size_of:: < X > (), 4usize, concat!("Size of: ", stringify!(X)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(X)) + ::std::mem::align_of:: < X > (), 4usize, concat!("Alignment of ", stringify!(X)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr)._x) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr)._x) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(X), "::", stringify!(_x)) ); } @@ -63,15 +51,11 @@ extern crate libloading; pub struct TestLib { __library: ::libloading::Library, pub foo: Result< - unsafe extern "C" fn( - x: *mut ::std::os::raw::c_void, - ) -> ::std::os::raw::c_int, + unsafe extern "C" fn(x: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int, ::libloading::Error, >, pub bar: Result< - unsafe extern "C" fn( - x: *mut ::std::os::raw::c_void, - ) -> ::std::os::raw::c_int, + unsafe extern "C" fn(x: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int, ::libloading::Error, >, } @@ -83,31 +67,19 @@ impl TestLib { let library = ::libloading::Library::new(path)?; Self::from_library(library) } - pub unsafe fn from_library( - library: L, - ) -> Result + pub unsafe fn from_library(library: L) -> Result where L: Into<::libloading::Library>, { let __library = library.into(); let foo = __library.get(b"foo\0").map(|sym| *sym); let bar = __library.get(b"bar\0").map(|sym| *sym); - Ok(TestLib { - __library, - foo, - bar, - }) + Ok(TestLib { __library, foo, bar }) } - pub unsafe fn foo( - &self, - x: *mut ::std::os::raw::c_void, - ) -> ::std::os::raw::c_int { + pub unsafe fn foo(&self, x: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int { (self.foo.as_ref().expect("Expected function, got error."))(x) } - pub unsafe fn bar( - &self, - x: *mut ::std::os::raw::c_void, - ) -> ::std::os::raw::c_int { + pub unsafe fn bar(&self, x: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int { (self.bar.as_ref().expect("Expected function, got error."))(x) } } diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs index 098ffa24ce..6c4cf9eec9 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct A { @@ -12,22 +6,16 @@ pub struct A { } #[test] fn bindgen_test_layout_A() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(A)) + ::std::mem::size_of:: < A > (), 4usize, concat!("Size of: ", stringify!(A)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(A)) + ::std::mem::align_of:: < A > (), 4usize, concat!("Alignment of ", stringify!(A)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr)._x) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr)._x) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(_x)) ); } @@ -63,9 +51,7 @@ extern crate libloading; pub struct TestLib { __library: ::libloading::Library, pub foo: Result< - unsafe extern "C" fn( - x: *mut ::std::os::raw::c_void, - ) -> ::std::os::raw::c_int, + unsafe extern "C" fn(x: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int, ::libloading::Error, >, pub bar: Result, @@ -78,25 +64,16 @@ impl TestLib { let library = ::libloading::Library::new(path)?; Self::from_library(library) } - pub unsafe fn from_library( - library: L, - ) -> Result + pub unsafe fn from_library(library: L) -> Result where L: Into<::libloading::Library>, { let __library = library.into(); let foo = __library.get(b"foo\0").map(|sym| *sym); let bar = __library.get(b"bar\0").map(|sym| *sym); - Ok(TestLib { - __library, - foo, - bar, - }) + Ok(TestLib { __library, foo, bar }) } - pub unsafe fn foo( - &self, - x: *mut ::std::os::raw::c_void, - ) -> ::std::os::raw::c_int { + pub unsafe fn foo(&self, x: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int { (self.foo.as_ref().expect("Expected function, got error."))(x) } pub unsafe fn bar(&self) { diff --git a/bindgen-tests/tests/expectations/tests/elaborated.rs b/bindgen-tests/tests/expectations/tests/elaborated.rs index 4741601640..80bf30f89a 100644 --- a/bindgen-tests/tests/expectations/tests/elaborated.rs +++ b/bindgen-tests/tests/expectations/tests/elaborated.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type whatever_whatever_t = ::std::os::raw::c_int; extern "C" { #[link_name = "\u{1}_Z9somethingPKi"] diff --git a/bindgen-tests/tests/expectations/tests/empty-enum.rs b/bindgen-tests/tests/expectations/tests/empty-enum.rs index fe188b3e3e..fda6f581df 100644 --- a/bindgen-tests/tests/expectations/tests/empty-enum.rs +++ b/bindgen-tests/tests/expectations/tests/empty-enum.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type EmptyConstified = ::std::os::raw::c_uint; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] diff --git a/bindgen-tests/tests/expectations/tests/empty-union.rs b/bindgen-tests/tests/expectations/tests/empty-union.rs index c21ae2f01f..de0f806eb5 100644 --- a/bindgen-tests/tests/expectations/tests/empty-union.rs +++ b/bindgen-tests/tests/expectations/tests/empty-union.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone)] pub union a__bindgen_ty_1 { diff --git a/bindgen-tests/tests/expectations/tests/empty_template_param_name.rs b/bindgen-tests/tests/expectations/tests/empty_template_param_name.rs index aa751f77e6..db5764ab25 100644 --- a/bindgen-tests/tests/expectations/tests/empty_template_param_name.rs +++ b/bindgen-tests/tests/expectations/tests/empty_template_param_name.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type __void_t = ::std::os::raw::c_void; #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] diff --git a/bindgen-tests/tests/expectations/tests/enum-default-bitfield.rs b/bindgen-tests/tests/expectations/tests/enum-default-bitfield.rs index 4c0757667e..16c92c5750 100644 --- a/bindgen-tests/tests/expectations/tests/enum-default-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/enum-default-bitfield.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct foo { @@ -43,28 +37,18 @@ impl ::std::ops::BitAndAssign for foo__bindgen_ty_1 { pub struct foo__bindgen_ty_1(pub ::std::os::raw::c_uint); #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of:: < foo > (), 4usize, concat!("Size of: ", stringify!(foo)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) + ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", + stringify!(foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(member) - ) + unsafe { ::std::ptr::addr_of!((* ptr).member) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(member)) ); } impl Default for foo { diff --git a/bindgen-tests/tests/expectations/tests/enum-default-consts.rs b/bindgen-tests/tests/expectations/tests/enum-default-consts.rs index ddce26c20a..70d4ad2acb 100644 --- a/bindgen-tests/tests/expectations/tests/enum-default-consts.rs +++ b/bindgen-tests/tests/expectations/tests/enum-default-consts.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct foo { @@ -15,28 +9,18 @@ pub const foo_FOO_B: foo__bindgen_ty_1 = 1; pub type foo__bindgen_ty_1 = ::std::os::raw::c_uint; #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of:: < foo > (), 4usize, concat!("Size of: ", stringify!(foo)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) + ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", + stringify!(foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(member) - ) + unsafe { ::std::ptr::addr_of!((* ptr).member) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(member)) ); } impl Default for foo { diff --git a/bindgen-tests/tests/expectations/tests/enum-default-module.rs b/bindgen-tests/tests/expectations/tests/enum-default-module.rs index ae026d8bca..6432af559a 100644 --- a/bindgen-tests/tests/expectations/tests/enum-default-module.rs +++ b/bindgen-tests/tests/expectations/tests/enum-default-module.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct foo { @@ -17,28 +11,18 @@ pub mod foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of:: < foo > (), 4usize, concat!("Size of: ", stringify!(foo)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) + ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", + stringify!(foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(member) - ) + unsafe { ::std::ptr::addr_of!((* ptr).member) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(member)) ); } impl Default for foo { diff --git a/bindgen-tests/tests/expectations/tests/enum-default-rust.rs b/bindgen-tests/tests/expectations/tests/enum-default-rust.rs index c3b728f826..45d48397d8 100644 --- a/bindgen-tests/tests/expectations/tests/enum-default-rust.rs +++ b/bindgen-tests/tests/expectations/tests/enum-default-rust.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct foo { @@ -20,28 +14,18 @@ pub enum foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of:: < foo > (), 4usize, concat!("Size of: ", stringify!(foo)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) + ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", + stringify!(foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(member) - ) + unsafe { ::std::ptr::addr_of!((* ptr).member) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(member)) ); } impl Default for foo { diff --git a/bindgen-tests/tests/expectations/tests/enum-doc-bitfield.rs b/bindgen-tests/tests/expectations/tests/enum-doc-bitfield.rs index 3be0438e5b..e6e9ffaa65 100644 --- a/bindgen-tests/tests/expectations/tests/enum-doc-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/enum-doc-bitfield.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] impl B { /// Document field with three slashes pub const VAR_A: B = B(0); @@ -26,10 +20,10 @@ impl B { pub const VAR_E: B = B(4); } impl B { - /// Document field with preceeding star, with a loong long multiline - /// comment. - /// - /// Very interesting documentation, definitely. + /** Document field with preceeding star, with a loong long multiline + comment. + + Very interesting documentation, definitely.*/ pub const VAR_F: B = B(5); } impl ::std::ops::BitOr for B { diff --git a/bindgen-tests/tests/expectations/tests/enum-doc-mod.rs b/bindgen-tests/tests/expectations/tests/enum-doc-mod.rs index 60d6b9f4d9..c54410e271 100644 --- a/bindgen-tests/tests/expectations/tests/enum-doc-mod.rs +++ b/bindgen-tests/tests/expectations/tests/enum-doc-mod.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod B { /// Document enum pub type Type = ::std::os::raw::c_uint; @@ -18,9 +12,9 @@ pub mod B { pub const VAR_D: Type = 3; ///< Document field with following exclamation pub const VAR_E: Type = 4; - /// Document field with preceeding star, with a loong long multiline - /// comment. - /// - /// Very interesting documentation, definitely. + /** Document field with preceeding star, with a loong long multiline + comment. + + Very interesting documentation, definitely.*/ pub const VAR_F: Type = 5; } diff --git a/bindgen-tests/tests/expectations/tests/enum-doc-rusty.rs b/bindgen-tests/tests/expectations/tests/enum-doc-rusty.rs index e7208a9db6..a83d2dc458 100644 --- a/bindgen-tests/tests/expectations/tests/enum-doc-rusty.rs +++ b/bindgen-tests/tests/expectations/tests/enum-doc-rusty.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(u32)] /// Document enum #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] @@ -19,9 +13,9 @@ pub enum B { VAR_D = 3, ///< Document field with following exclamation VAR_E = 4, - /// Document field with preceeding star, with a loong long multiline - /// comment. - /// - /// Very interesting documentation, definitely. + /** Document field with preceeding star, with a loong long multiline + comment. + + Very interesting documentation, definitely.*/ VAR_F = 5, } diff --git a/bindgen-tests/tests/expectations/tests/enum-doc.rs b/bindgen-tests/tests/expectations/tests/enum-doc.rs index b5d14b3cf0..ee0ca23bff 100644 --- a/bindgen-tests/tests/expectations/tests/enum-doc.rs +++ b/bindgen-tests/tests/expectations/tests/enum-doc.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] /// Document field with three slashes pub const B_VAR_A: B = 0; /// Document field with preceeding star @@ -15,10 +9,10 @@ pub const B_VAR_C: B = 2; pub const B_VAR_D: B = 3; ///< Document field with following exclamation pub const B_VAR_E: B = 4; -/// Document field with preceeding star, with a loong long multiline -/// comment. -/// -/// Very interesting documentation, definitely. +/** Document field with preceeding star, with a loong long multiline + comment. + + Very interesting documentation, definitely.*/ pub const B_VAR_F: B = 5; /// Document enum pub type B = ::std::os::raw::c_uint; diff --git a/bindgen-tests/tests/expectations/tests/enum-no-debug-rust.rs b/bindgen-tests/tests/expectations/tests/enum-no-debug-rust.rs index 33c7b5c7cc..9a52fd4d96 100644 --- a/bindgen-tests/tests/expectations/tests/enum-no-debug-rust.rs +++ b/bindgen-tests/tests/expectations/tests/enum-no-debug-rust.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone)] pub struct foo { @@ -20,28 +14,18 @@ pub enum foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of:: < foo > (), 4usize, concat!("Size of: ", stringify!(foo)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) + ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", + stringify!(foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(member) - ) + unsafe { ::std::ptr::addr_of!((* ptr).member) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(member)) ); } impl Default for foo { diff --git a/bindgen-tests/tests/expectations/tests/enum-translate-type.rs b/bindgen-tests/tests/expectations/tests/enum-translate-type.rs index 89e6003e44..2431e48d5b 100644 --- a/bindgen-tests/tests/expectations/tests/enum-translate-type.rs +++ b/bindgen-tests/tests/expectations/tests/enum-translate-type.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const my_enum1_A: my_enum1 = 0; pub type my_enum1 = u32; pub const my_enum2_B: my_enum2 = -1; diff --git a/bindgen-tests/tests/expectations/tests/enum-typedef.rs b/bindgen-tests/tests/expectations/tests/enum-typedef.rs index dc78eb11eb..772184b39f 100644 --- a/bindgen-tests/tests/expectations/tests/enum-typedef.rs +++ b/bindgen-tests/tests/expectations/tests/enum-typedef.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const Enum_Variant: Enum = 0; pub type Enum = i16; pub type TypedefFirst = i16; diff --git a/bindgen-tests/tests/expectations/tests/enum-undefault.rs b/bindgen-tests/tests/expectations/tests/enum-undefault.rs index e5618b9148..01a7aa3cea 100644 --- a/bindgen-tests/tests/expectations/tests/enum-undefault.rs +++ b/bindgen-tests/tests/expectations/tests/enum-undefault.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Foo { diff --git a/bindgen-tests/tests/expectations/tests/enum-variant-replaces.rs b/bindgen-tests/tests/expectations/tests/enum-variant-replaces.rs index d927657492..a661ca833b 100644 --- a/bindgen-tests/tests/expectations/tests/enum-variant-replaces.rs +++ b/bindgen-tests/tests/expectations/tests/enum-variant-replaces.rs @@ -1,17 +1,11 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +/**
-///
-/// -/// Should see PASS below. + Should see PASS below.*/ pub const OGRErr_PASS: OGRErr = 0; -///
-/// -/// Should see OGRERR_NONE instead of CUSTOM_OGRERR_NONE below. +/**
+ + Should see OGRERR_NONE instead of CUSTOM_OGRERR_NONE below.*/ pub const OGRErr_OGRERR_NONE: OGRErr = 1; ///
pub type OGRErr = ::std::os::raw::c_uint; diff --git a/bindgen-tests/tests/expectations/tests/enum.rs b/bindgen-tests/tests/expectations/tests/enum.rs index 65b734a325..6c5a5bf742 100644 --- a/bindgen-tests/tests/expectations/tests/enum.rs +++ b/bindgen-tests/tests/expectations/tests/enum.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct foo { @@ -15,28 +9,18 @@ pub const foo_FOO_B: foo__bindgen_ty_1 = 1; pub type foo__bindgen_ty_1 = ::std::os::raw::c_uint; #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of:: < foo > (), 4usize, concat!("Size of: ", stringify!(foo)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) + ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", + stringify!(foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(member) - ) + unsafe { ::std::ptr::addr_of!((* ptr).member) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(member)) ); } impl Default for foo { diff --git a/bindgen-tests/tests/expectations/tests/enum_alias.rs b/bindgen-tests/tests/expectations/tests/enum_alias.rs index ad62d16fa2..0d29768837 100644 --- a/bindgen-tests/tests/expectations/tests/enum_alias.rs +++ b/bindgen-tests/tests/expectations/tests/enum_alias.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(u8)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Bar { diff --git a/bindgen-tests/tests/expectations/tests/enum_and_vtable_mangling.rs b/bindgen-tests/tests/expectations/tests/enum_and_vtable_mangling.rs index f414812b82..f9f90e9bcc 100644 --- a/bindgen-tests/tests/expectations/tests/enum_and_vtable_mangling.rs +++ b/bindgen-tests/tests/expectations/tests/enum_and_vtable_mangling.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const match_: _bindgen_ty_1 = _bindgen_ty_1::match_; pub const whatever_else: _bindgen_ty_1 = _bindgen_ty_1::whatever_else; #[repr(u32)] @@ -25,22 +19,16 @@ pub struct C { } #[test] fn bindgen_test_layout_C() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(C)) + ::std::mem::size_of:: < C > (), 16usize, concat!("Size of: ", stringify!(C)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(C)) + ::std::mem::align_of:: < C > (), 8usize, concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, - 8usize, + unsafe { ::std::ptr::addr_of!((* ptr).i) as usize - ptr as usize }, 8usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(i)) ); } diff --git a/bindgen-tests/tests/expectations/tests/enum_dupe.rs b/bindgen-tests/tests/expectations/tests/enum_dupe.rs index 869375bbfd..3ee4c68cbd 100644 --- a/bindgen-tests/tests/expectations/tests/enum_dupe.rs +++ b/bindgen-tests/tests/expectations/tests/enum_dupe.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] impl Foo { pub const Dupe: Foo = Foo::Bar; } diff --git a/bindgen-tests/tests/expectations/tests/enum_explicit_type.rs b/bindgen-tests/tests/expectations/tests/enum_explicit_type.rs index 29bc5d8cfc..1f3dd36f96 100644 --- a/bindgen-tests/tests/expectations/tests/enum_explicit_type.rs +++ b/bindgen-tests/tests/expectations/tests/enum_explicit_type.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(u8)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Foo { @@ -49,10 +43,8 @@ pub type MyType = bool; pub enum BoolEnumsAreFun2 { Value2 = 1, } -pub const AnonymousVariantOne: _bindgen_ty_1 = - _bindgen_ty_1::AnonymousVariantOne; -pub const AnonymousVariantTwo: _bindgen_ty_1 = - _bindgen_ty_1::AnonymousVariantTwo; +pub const AnonymousVariantOne: _bindgen_ty_1 = _bindgen_ty_1::AnonymousVariantOne; +pub const AnonymousVariantTwo: _bindgen_ty_1 = _bindgen_ty_1::AnonymousVariantTwo; #[repr(u8)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum _bindgen_ty_1 { diff --git a/bindgen-tests/tests/expectations/tests/enum_explicit_type_constants.rs b/bindgen-tests/tests/expectations/tests/enum_explicit_type_constants.rs index 0c833b6640..8f310572b6 100644 --- a/bindgen-tests/tests/expectations/tests/enum_explicit_type_constants.rs +++ b/bindgen-tests/tests/expectations/tests/enum_explicit_type_constants.rs @@ -1,11 +1,5 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(not(target_os = "windows"))] - pub const Foo_Bar: Foo = 0; pub const Foo_Qux: Foo = 1; pub type Foo = ::std::os::raw::c_uchar; diff --git a/bindgen-tests/tests/expectations/tests/enum_in_template.rs b/bindgen-tests/tests/expectations/tests/enum_in_template.rs index c4c06a3733..e54a97b5f4 100644 --- a/bindgen-tests/tests/expectations/tests/enum_in_template.rs +++ b/bindgen-tests/tests/expectations/tests/enum_in_template.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { diff --git a/bindgen-tests/tests/expectations/tests/enum_in_template_with_typedef.rs b/bindgen-tests/tests/expectations/tests/enum_in_template_with_typedef.rs index 75dce30c0e..b71923e10f 100644 --- a/bindgen-tests/tests/expectations/tests/enum_in_template_with_typedef.rs +++ b/bindgen-tests/tests/expectations/tests/enum_in_template_with_typedef.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct std_fbstring_core { diff --git a/bindgen-tests/tests/expectations/tests/enum_negative.rs b/bindgen-tests/tests/expectations/tests/enum_negative.rs index 02b4baed59..f946e0f044 100644 --- a/bindgen-tests/tests/expectations/tests/enum_negative.rs +++ b/bindgen-tests/tests/expectations/tests/enum_negative.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(i32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Foo { diff --git a/bindgen-tests/tests/expectations/tests/enum_packed.rs b/bindgen-tests/tests/expectations/tests/enum_packed.rs index 89b0da461d..d4ec2192d1 100644 --- a/bindgen-tests/tests/expectations/tests/enum_packed.rs +++ b/bindgen-tests/tests/expectations/tests/enum_packed.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(u8)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Foo { diff --git a/bindgen-tests/tests/expectations/tests/eval-value-dependent.rs b/bindgen-tests/tests/expectations/tests/eval-value-dependent.rs index 3376bfc6b3..b9b2709cfa 100644 --- a/bindgen-tests/tests/expectations/tests/eval-value-dependent.rs +++ b/bindgen-tests/tests/expectations/tests/eval-value-dependent.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct e { diff --git a/bindgen-tests/tests/expectations/tests/eval-variadic-template-parameter.rs b/bindgen-tests/tests/expectations/tests/eval-variadic-template-parameter.rs index 576bb721c5..fccd2ad5d7 100644 --- a/bindgen-tests/tests/expectations/tests/eval-variadic-template-parameter.rs +++ b/bindgen-tests/tests/expectations/tests/eval-variadic-template-parameter.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct B { diff --git a/bindgen-tests/tests/expectations/tests/explicit-padding.rs b/bindgen-tests/tests/expectations/tests/explicit-padding.rs index a6ea767129..0cd40e9c5f 100644 --- a/bindgen-tests/tests/expectations/tests/explicit-padding.rs +++ b/bindgen-tests/tests/expectations/tests/explicit-padding.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct pad_me { @@ -16,48 +10,27 @@ pub struct pad_me { } #[test] fn bindgen_test_layout_pad_me() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 12usize, - concat!("Size of: ", stringify!(pad_me)) + ::std::mem::size_of:: < pad_me > (), 12usize, concat!("Size of: ", + stringify!(pad_me)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(pad_me)) + ::std::mem::align_of:: < pad_me > (), 4usize, concat!("Alignment of ", + stringify!(pad_me)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).first) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(pad_me), - "::", - stringify!(first) - ) + unsafe { ::std::ptr::addr_of!((* ptr).first) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(pad_me), "::", stringify!(first)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).second) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(pad_me), - "::", - stringify!(second) - ) + unsafe { ::std::ptr::addr_of!((* ptr).second) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(pad_me), "::", stringify!(second)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).third) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(pad_me), - "::", - stringify!(third) - ) + unsafe { ::std::ptr::addr_of!((* ptr).third) as usize - ptr as usize }, 8usize, + concat!("Offset of field: ", stringify!(pad_me), "::", stringify!(third)) ); } #[repr(C)] @@ -69,48 +42,27 @@ pub union dont_pad_me { } #[test] fn bindgen_test_layout_dont_pad_me() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(dont_pad_me)) + ::std::mem::size_of:: < dont_pad_me > (), 4usize, concat!("Size of: ", + stringify!(dont_pad_me)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(dont_pad_me)) + ::std::mem::align_of:: < dont_pad_me > (), 4usize, concat!("Alignment of ", + stringify!(dont_pad_me)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).first) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(dont_pad_me), - "::", - stringify!(first) - ) + unsafe { ::std::ptr::addr_of!((* ptr).first) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(dont_pad_me), "::", stringify!(first)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).second) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(dont_pad_me), - "::", - stringify!(second) - ) + unsafe { ::std::ptr::addr_of!((* ptr).second) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(dont_pad_me), "::", stringify!(second)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).third) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(dont_pad_me), - "::", - stringify!(third) - ) + unsafe { ::std::ptr::addr_of!((* ptr).third) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(dont_pad_me), "::", stringify!(third)) ); } impl Default for dont_pad_me { diff --git a/bindgen-tests/tests/expectations/tests/extern-const-struct.rs b/bindgen-tests/tests/expectations/tests/extern-const-struct.rs index 8060316a35..731291da8c 100644 --- a/bindgen-tests/tests/expectations/tests/extern-const-struct.rs +++ b/bindgen-tests/tests/expectations/tests/extern-const-struct.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone)] pub struct nsFoo { @@ -12,28 +6,19 @@ pub struct nsFoo { } #[test] fn bindgen_test_layout_nsFoo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 1600usize, - concat!("Size of: ", stringify!(nsFoo)) + ::std::mem::size_of:: < nsFoo > (), 1600usize, concat!("Size of: ", + stringify!(nsFoo)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(nsFoo)) + ::std::mem::align_of:: < nsFoo > (), 4usize, concat!("Alignment of ", + stringify!(nsFoo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).details) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsFoo), - "::", - stringify!(details) - ) + unsafe { ::std::ptr::addr_of!((* ptr).details) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(nsFoo), "::", stringify!(details)) ); } impl Default for nsFoo { diff --git a/bindgen-tests/tests/expectations/tests/extern.rs b/bindgen-tests/tests/expectations/tests/extern.rs index 7ded13f179..496f595a0d 100644 --- a/bindgen-tests/tests/expectations/tests/extern.rs +++ b/bindgen-tests/tests/expectations/tests/extern.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type foo = ::std::option::Option< unsafe extern "C" fn(bar: ::std::os::raw::c_int) -> ::std::os::raw::c_int, >; diff --git a/bindgen-tests/tests/expectations/tests/fit-macro-constant-types-signed.rs b/bindgen-tests/tests/expectations/tests/fit-macro-constant-types-signed.rs index ccb76b8507..0602f7714a 100644 --- a/bindgen-tests/tests/expectations/tests/fit-macro-constant-types-signed.rs +++ b/bindgen-tests/tests/expectations/tests/fit-macro-constant-types-signed.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const N0: i8 = 0; pub const N1: i8 = 1; pub const N2: i8 = 2; diff --git a/bindgen-tests/tests/expectations/tests/fit-macro-constant-types.rs b/bindgen-tests/tests/expectations/tests/fit-macro-constant-types.rs index d8d3f207c1..f5d2a56ff2 100644 --- a/bindgen-tests/tests/expectations/tests/fit-macro-constant-types.rs +++ b/bindgen-tests/tests/expectations/tests/fit-macro-constant-types.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const N0: u8 = 0; pub const N1: u8 = 1; pub const N2: u8 = 2; diff --git a/bindgen-tests/tests/expectations/tests/float128.rs b/bindgen-tests/tests/expectations/tests/float128.rs index 131dbdf39f..fe64295a68 100644 --- a/bindgen-tests/tests/expectations/tests/float128.rs +++ b/bindgen-tests/tests/expectations/tests/float128.rs @@ -1,6 +1 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] \ No newline at end of file diff --git a/bindgen-tests/tests/expectations/tests/forward-declaration-autoptr.rs b/bindgen-tests/tests/expectations/tests/forward-declaration-autoptr.rs index 9f4fdca0a6..67de3b4b99 100644 --- a/bindgen-tests/tests/expectations/tests/forward-declaration-autoptr.rs +++ b/bindgen-tests/tests/expectations/tests/forward-declaration-autoptr.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Foo { @@ -32,30 +26,18 @@ pub struct Bar { } #[test] fn bindgen_test_layout_Bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Bar)) + ::std::mem::size_of:: < Bar > (), 8usize, concat!("Size of: ", stringify!(Bar)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Bar)) + ::std::mem::align_of:: < Bar > (), 8usize, concat!("Alignment of ", + stringify!(Bar)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(m_member) - ) + unsafe { ::std::ptr::addr_of!((* ptr).m_member) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(m_member)) ); } impl Default for Bar { @@ -70,16 +52,11 @@ impl Default for Bar { #[test] fn __bindgen_test_layout_RefPtr_open0_Foo_close0_instantiation() { assert_eq!( - ::std::mem::size_of::>(), - 8usize, - concat!("Size of template specialization: ", stringify!(RefPtr)) + ::std::mem::size_of:: < RefPtr < Foo > > (), 8usize, + concat!("Size of template specialization: ", stringify!(RefPtr < Foo >)) ); assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(RefPtr) - ) + ::std::mem::align_of:: < RefPtr < Foo > > (), 8usize, + concat!("Alignment of template specialization: ", stringify!(RefPtr < Foo >)) ); } diff --git a/bindgen-tests/tests/expectations/tests/forward-enum-decl.rs b/bindgen-tests/tests/expectations/tests/forward-enum-decl.rs index 0ac550bcba..9949b39aae 100644 --- a/bindgen-tests/tests/expectations/tests/forward-enum-decl.rs +++ b/bindgen-tests/tests/expectations/tests/forward-enum-decl.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(i32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum CSSPseudoClassType { diff --git a/bindgen-tests/tests/expectations/tests/forward-inherit-struct-with-fields.rs b/bindgen-tests/tests/expectations/tests/forward-inherit-struct-with-fields.rs index 330d766b31..0e5bcd969f 100644 --- a/bindgen-tests/tests/expectations/tests/forward-inherit-struct-with-fields.rs +++ b/bindgen-tests/tests/expectations/tests/forward-inherit-struct-with-fields.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct js_RootedBase { diff --git a/bindgen-tests/tests/expectations/tests/forward-inherit-struct.rs b/bindgen-tests/tests/expectations/tests/forward-inherit-struct.rs index 2c4546eb41..52888c4626 100644 --- a/bindgen-tests/tests/expectations/tests/forward-inherit-struct.rs +++ b/bindgen-tests/tests/expectations/tests/forward-inherit-struct.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct js_RootedBase { diff --git a/bindgen-tests/tests/expectations/tests/forward_declared_complex_types.rs b/bindgen-tests/tests/expectations/tests/forward_declared_complex_types.rs index c1b1f23d2d..47c31cddd0 100644 --- a/bindgen-tests/tests/expectations/tests/forward_declared_complex_types.rs +++ b/bindgen-tests/tests/expectations/tests/forward_declared_complex_types.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo_empty { @@ -13,14 +7,12 @@ pub struct Foo_empty { #[test] fn bindgen_test_layout_Foo_empty() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo_empty)) + ::std::mem::size_of:: < Foo_empty > (), 1usize, concat!("Size of: ", + stringify!(Foo_empty)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo_empty)) + ::std::mem::align_of:: < Foo_empty > (), 1usize, concat!("Alignment of ", + stringify!(Foo_empty)) ); } #[repr(C)] @@ -35,22 +27,17 @@ pub struct Bar { } #[test] fn bindgen_test_layout_Bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Bar)) + ::std::mem::size_of:: < Bar > (), 8usize, concat!("Size of: ", stringify!(Bar)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Bar)) + ::std::mem::align_of:: < Bar > (), 8usize, concat!("Alignment of ", + stringify!(Bar)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).f) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(f)) ); } diff --git a/bindgen-tests/tests/expectations/tests/forward_declared_complex_types_1_0.rs b/bindgen-tests/tests/expectations/tests/forward_declared_complex_types_1_0.rs index ecdbe49da7..ba6a77af52 100644 --- a/bindgen-tests/tests/expectations/tests/forward_declared_complex_types_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/forward_declared_complex_types_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy)] pub struct Foo_empty { @@ -13,14 +7,12 @@ pub struct Foo_empty { #[test] fn bindgen_test_layout_Foo_empty() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo_empty)) + ::std::mem::size_of:: < Foo_empty > (), 1usize, concat!("Size of: ", + stringify!(Foo_empty)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo_empty)) + ::std::mem::align_of:: < Foo_empty > (), 1usize, concat!("Alignment of ", + stringify!(Foo_empty)) ); } impl Clone for Foo_empty { @@ -45,22 +37,17 @@ pub struct Bar { } #[test] fn bindgen_test_layout_Bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Bar)) + ::std::mem::size_of:: < Bar > (), 8usize, concat!("Size of: ", stringify!(Bar)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Bar)) + ::std::mem::align_of:: < Bar > (), 8usize, concat!("Alignment of ", + stringify!(Bar)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).f) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(f)) ); } diff --git a/bindgen-tests/tests/expectations/tests/forward_declared_opaque.rs b/bindgen-tests/tests/expectations/tests/forward_declared_opaque.rs index 58c02b4406..1f92194045 100644 --- a/bindgen-tests/tests/expectations/tests/forward_declared_opaque.rs +++ b/bindgen-tests/tests/expectations/tests/forward_declared_opaque.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone)] pub struct a { diff --git a/bindgen-tests/tests/expectations/tests/forward_declared_struct.rs b/bindgen-tests/tests/expectations/tests/forward_declared_struct.rs index f877666adc..bcbe3ac99a 100644 --- a/bindgen-tests/tests/expectations/tests/forward_declared_struct.rs +++ b/bindgen-tests/tests/expectations/tests/forward_declared_struct.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct a { @@ -12,22 +6,16 @@ pub struct a { } #[test] fn bindgen_test_layout_a() { - const UNINIT: ::std::mem::MaybeUninit
= - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(a)) + ::std::mem::size_of:: < a > (), 4usize, concat!("Size of: ", stringify!(a)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(a)) + ::std::mem::align_of:: < a > (), 4usize, concat!("Alignment of ", stringify!(a)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(a), "::", stringify!(b)) ); } @@ -38,22 +26,16 @@ pub struct c { } #[test] fn bindgen_test_layout_c() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(c)) + ::std::mem::size_of:: < c > (), 4usize, concat!("Size of: ", stringify!(c)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(c)) + ::std::mem::align_of:: < c > (), 4usize, concat!("Alignment of ", stringify!(c)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).d) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(c), "::", stringify!(d)) ); } diff --git a/bindgen-tests/tests/expectations/tests/func_proto.rs b/bindgen-tests/tests/expectations/tests/func_proto.rs index 7ded13f179..496f595a0d 100644 --- a/bindgen-tests/tests/expectations/tests/func_proto.rs +++ b/bindgen-tests/tests/expectations/tests/func_proto.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type foo = ::std::option::Option< unsafe extern "C" fn(bar: ::std::os::raw::c_int) -> ::std::os::raw::c_int, >; diff --git a/bindgen-tests/tests/expectations/tests/func_ptr.rs b/bindgen-tests/tests/expectations/tests/func_ptr.rs index 9c718f03ec..4e9c5b131d 100644 --- a/bindgen-tests/tests/expectations/tests/func_ptr.rs +++ b/bindgen-tests/tests/expectations/tests/func_ptr.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub static mut foo: ::std::option::Option< unsafe extern "C" fn( diff --git a/bindgen-tests/tests/expectations/tests/func_ptr_in_struct.rs b/bindgen-tests/tests/expectations/tests/func_ptr_in_struct.rs index 745720d998..f606d57289 100644 --- a/bindgen-tests/tests/expectations/tests/func_ptr_in_struct.rs +++ b/bindgen-tests/tests/expectations/tests/func_ptr_in_struct.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(i32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum baz { @@ -14,30 +8,22 @@ pub enum baz { #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct Foo { pub bar: ::std::option::Option< - unsafe extern "C" fn( - x: ::std::os::raw::c_int, - y: ::std::os::raw::c_int, - ) -> baz, + unsafe extern "C" fn(x: ::std::os::raw::c_int, y: ::std::os::raw::c_int) -> baz, >, } #[test] fn bindgen_test_layout_Foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of:: < Foo > (), 8usize, concat!("Size of: ", stringify!(Foo)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Foo)) + ::std::mem::align_of:: < Foo > (), 8usize, concat!("Alignment of ", + stringify!(Foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) ); } diff --git a/bindgen-tests/tests/expectations/tests/func_ptr_return_type.rs b/bindgen-tests/tests/expectations/tests/func_ptr_return_type.rs index 8f2da8efda..c1c890249f 100644 --- a/bindgen-tests/tests/expectations/tests/func_ptr_return_type.rs +++ b/bindgen-tests/tests/expectations/tests/func_ptr_return_type.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub fn func() -> ::std::option::Option< unsafe extern "C" fn( diff --git a/bindgen-tests/tests/expectations/tests/func_return_must_use.rs b/bindgen-tests/tests/expectations/tests/func_return_must_use.rs index 6ea6c704f0..2cfd163cac 100644 --- a/bindgen-tests/tests/expectations/tests/func_return_must_use.rs +++ b/bindgen-tests/tests/expectations/tests/func_return_must_use.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type MustUseInt = ::std::os::raw::c_int; extern "C" { #[must_use] @@ -37,14 +31,12 @@ pub struct AnnotatedStruct {} #[test] fn bindgen_test_layout_AnnotatedStruct() { assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(AnnotatedStruct)) + ::std::mem::size_of:: < AnnotatedStruct > (), 0usize, concat!("Size of: ", + stringify!(AnnotatedStruct)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(AnnotatedStruct)) + ::std::mem::align_of:: < AnnotatedStruct > (), 1usize, concat!("Alignment of ", + stringify!(AnnotatedStruct)) ); } extern "C" { @@ -57,14 +49,12 @@ pub struct PlainStruct {} #[test] fn bindgen_test_layout_PlainStruct() { assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(PlainStruct)) + ::std::mem::size_of:: < PlainStruct > (), 0usize, concat!("Size of: ", + stringify!(PlainStruct)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(PlainStruct)) + ::std::mem::align_of:: < PlainStruct > (), 1usize, concat!("Alignment of ", + stringify!(PlainStruct)) ); } ///
diff --git a/bindgen-tests/tests/expectations/tests/func_with_array_arg.rs b/bindgen-tests/tests/expectations/tests/func_with_array_arg.rs index f98192f8db..e41cb2ce44 100644 --- a/bindgen-tests/tests/expectations/tests/func_with_array_arg.rs +++ b/bindgen-tests/tests/expectations/tests/func_with_array_arg.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub fn f(x: *mut ::std::os::raw::c_int); } diff --git a/bindgen-tests/tests/expectations/tests/func_with_func_ptr_arg.rs b/bindgen-tests/tests/expectations/tests/func_with_func_ptr_arg.rs index fb06b88e68..af8a3fc68c 100644 --- a/bindgen-tests/tests/expectations/tests/func_with_func_ptr_arg.rs +++ b/bindgen-tests/tests/expectations/tests/func_with_func_ptr_arg.rs @@ -1,26 +1,14 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub fn foo(bar: ::std::option::Option); } extern "C" { pub fn bar( one: ::std::option::Option< - unsafe extern "C" fn( - a: ::std::os::raw::c_int, - b: ::std::os::raw::c_int, - ), + unsafe extern "C" fn(a: ::std::os::raw::c_int, b: ::std::os::raw::c_int), >, two: ::std::option::Option< - unsafe extern "C" fn( - c: ::std::os::raw::c_int, - d: ::std::os::raw::c_int, - ), + unsafe extern "C" fn(c: ::std::os::raw::c_int, d: ::std::os::raw::c_int), >, ); } diff --git a/bindgen-tests/tests/expectations/tests/function-typedef-stdcall.rs b/bindgen-tests/tests/expectations/tests/function-typedef-stdcall.rs index 11c9ef2072..3b08e0988c 100644 --- a/bindgen-tests/tests/expectations/tests/function-typedef-stdcall.rs +++ b/bindgen-tests/tests/expectations/tests/function-typedef-stdcall.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type PFN_VIGEM_X360_NOTIFICATION = ::std::option::Option< unsafe extern "C" fn( arg1: *mut ::std::os::raw::c_void, diff --git a/bindgen-tests/tests/expectations/tests/gen-constructors-neg.rs b/bindgen-tests/tests/expectations/tests/gen-constructors-neg.rs index f5ba025a25..d16596b591 100644 --- a/bindgen-tests/tests/expectations/tests/gen-constructors-neg.rs +++ b/bindgen-tests/tests/expectations/tests/gen-constructors-neg.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { @@ -13,13 +7,10 @@ pub struct Foo { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) + ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", + stringify!(Foo)) ); } diff --git a/bindgen-tests/tests/expectations/tests/gen-constructors.rs b/bindgen-tests/tests/expectations/tests/gen-constructors.rs index 89b8637954..ae882bfeba 100644 --- a/bindgen-tests/tests/expectations/tests/gen-constructors.rs +++ b/bindgen-tests/tests/expectations/tests/gen-constructors.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { @@ -13,14 +7,11 @@ pub struct Foo { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) + ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", + stringify!(Foo)) ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/gen-destructors-neg.rs b/bindgen-tests/tests/expectations/tests/gen-destructors-neg.rs index b87eb1d46c..0959bdfbd9 100644 --- a/bindgen-tests/tests/expectations/tests/gen-destructors-neg.rs +++ b/bindgen-tests/tests/expectations/tests/gen-destructors-neg.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default)] pub struct Foo { @@ -12,22 +6,17 @@ pub struct Foo { } #[test] fn bindgen_test_layout_Foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of:: < Foo > (), 4usize, concat!("Size of: ", stringify!(Foo)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Foo)) + ::std::mem::align_of:: < Foo > (), 4usize, concat!("Alignment of ", + stringify!(Foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) ); } diff --git a/bindgen-tests/tests/expectations/tests/gen-destructors.rs b/bindgen-tests/tests/expectations/tests/gen-destructors.rs index 1711f76d0c..43d122963e 100644 --- a/bindgen-tests/tests/expectations/tests/gen-destructors.rs +++ b/bindgen-tests/tests/expectations/tests/gen-destructors.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default)] pub struct Foo { @@ -12,22 +6,17 @@ pub struct Foo { } #[test] fn bindgen_test_layout_Foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of:: < Foo > (), 4usize, concat!("Size of: ", stringify!(Foo)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Foo)) + ::std::mem::align_of:: < Foo > (), 4usize, concat!("Alignment of ", + stringify!(Foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) ); } diff --git a/bindgen-tests/tests/expectations/tests/generate-inline.rs b/bindgen-tests/tests/expectations/tests/generate-inline.rs index 3cb865a4d7..6be11f5cc7 100644 --- a/bindgen-tests/tests/expectations/tests/generate-inline.rs +++ b/bindgen-tests/tests/expectations/tests/generate-inline.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { @@ -13,14 +7,11 @@ pub struct Foo { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) + ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", + stringify!(Foo)) ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/i128.rs b/bindgen-tests/tests/expectations/tests/i128.rs index dee57a6ded..a988562c6f 100644 --- a/bindgen-tests/tests/expectations/tests/i128.rs +++ b/bindgen-tests/tests/expectations/tests/i128.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[repr(align(16))] #[derive(Debug, Default, Copy, Clone)] @@ -14,41 +8,23 @@ pub struct foo { } #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 32usize, - concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of:: < foo > (), 32usize, concat!("Size of: ", stringify!(foo)) ); assert_eq!( - ::std::mem::align_of::(), - 16usize, - concat!("Alignment of ", stringify!(foo)) + ::std::mem::align_of:: < foo > (), 16usize, concat!("Alignment of ", + stringify!(foo)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).my_signed) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(my_signed) - ) + unsafe { ::std::ptr::addr_of!((* ptr).my_signed) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(foo), "::", + stringify!(my_signed)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).my_unsigned) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(my_unsigned) - ) + unsafe { ::std::ptr::addr_of!((* ptr).my_unsigned) as usize - ptr as usize }, + 16usize, concat!("Offset of field: ", stringify!(foo), "::", + stringify!(my_unsigned)) ); } diff --git a/bindgen-tests/tests/expectations/tests/in_class_typedef.rs b/bindgen-tests/tests/expectations/tests/in_class_typedef.rs index 7bb7d39182..ccb73520d7 100644 --- a/bindgen-tests/tests/expectations/tests/in_class_typedef.rs +++ b/bindgen-tests/tests/expectations/tests/in_class_typedef.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { diff --git a/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs b/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs index 18061ea12a..2c7966c371 100644 --- a/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs +++ b/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -131,14 +123,11 @@ pub struct foo { #[test] fn bindgen_test_layout_foo() { assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of:: < foo > (), 8usize, concat!("Size of: ", stringify!(foo)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(foo)) + ::std::mem::align_of:: < foo > (), 8usize, concat!("Alignment of ", + stringify!(foo)) ); } impl Default for foo { @@ -153,9 +142,7 @@ impl Default for foo { impl foo { #[inline] pub fn a(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) } } #[inline] pub fn set_a(&mut self, val: ::std::os::raw::c_char) { @@ -168,12 +155,16 @@ impl foo { pub fn new_bitfield_1( a: ::std::os::raw::c_char, ) -> __BindgenBitfieldUnit<[u8; 1usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 1u8, { - let a: u8 = unsafe { ::std::mem::transmute(a) }; - a as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let a: u8 = unsafe { ::std::mem::transmute(a) }; + a as u64 + }, + ); __bindgen_bitfield_unit } } diff --git a/bindgen-tests/tests/expectations/tests/infinite-macro.rs b/bindgen-tests/tests/expectations/tests/infinite-macro.rs index 081a0c296b..455a7ae5ed 100644 --- a/bindgen-tests/tests/expectations/tests/infinite-macro.rs +++ b/bindgen-tests/tests/expectations/tests/infinite-macro.rs @@ -1,9 +1,3 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const INFINITY: f64 = ::std::f64::INFINITY; pub const NAN: f64 = ::std::f64::NAN; diff --git a/bindgen-tests/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs b/bindgen-tests/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs index 0876878efc..1902b1b971 100644 --- a/bindgen-tests/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs +++ b/bindgen-tests/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct BaseWithVtable__bindgen_vtable {} /// This should have an explicit vtable. @@ -33,13 +27,11 @@ pub struct DerivedWithNoVirtualMethods { #[test] fn bindgen_test_layout_DerivedWithNoVirtualMethods() { assert_eq!( - ::std::mem::size_of::(), - 16usize, + ::std::mem::size_of:: < DerivedWithNoVirtualMethods > (), 16usize, concat!("Size of: ", stringify!(DerivedWithNoVirtualMethods)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, + ::std::mem::align_of:: < DerivedWithNoVirtualMethods > (), 8usize, concat!("Alignment of ", stringify!(DerivedWithNoVirtualMethods)) ); } @@ -61,13 +53,11 @@ pub struct DerivedWithVirtualMethods { #[test] fn bindgen_test_layout_DerivedWithVirtualMethods() { assert_eq!( - ::std::mem::size_of::(), - 16usize, + ::std::mem::size_of:: < DerivedWithVirtualMethods > (), 16usize, concat!("Size of: ", stringify!(DerivedWithVirtualMethods)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, + ::std::mem::align_of:: < DerivedWithVirtualMethods > (), 8usize, concat!("Alignment of ", stringify!(DerivedWithVirtualMethods)) ); } @@ -108,14 +98,12 @@ pub struct DerivedWithVtable { #[test] fn bindgen_test_layout_DerivedWithVtable() { assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(DerivedWithVtable)) + ::std::mem::size_of:: < DerivedWithVtable > (), 16usize, concat!("Size of: ", + stringify!(DerivedWithVtable)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(DerivedWithVtable)) + ::std::mem::align_of:: < DerivedWithVtable > (), 8usize, concat!("Alignment of ", + stringify!(DerivedWithVtable)) ); } impl Default for DerivedWithVtable { @@ -136,13 +124,11 @@ pub struct DerivedWithoutVtable { #[test] fn bindgen_test_layout_DerivedWithoutVtable() { assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(DerivedWithoutVtable)) + ::std::mem::size_of:: < DerivedWithoutVtable > (), 8usize, concat!("Size of: ", + stringify!(DerivedWithoutVtable)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, + ::std::mem::align_of:: < DerivedWithoutVtable > (), 8usize, concat!("Alignment of ", stringify!(DerivedWithoutVtable)) ); } @@ -158,81 +144,52 @@ impl Default for DerivedWithoutVtable { #[test] fn __bindgen_test_layout_BaseWithVtable_open0_ptr_char_close0_instantiation() { assert_eq!( - ::std::mem::size_of::>(), - 16usize, - concat!( - "Size of template specialization: ", - stringify!(BaseWithVtable<*mut ::std::os::raw::c_char>) - ) + ::std::mem::size_of:: < BaseWithVtable < * mut ::std::os::raw::c_char > > (), + 16usize, concat!("Size of template specialization: ", stringify!(BaseWithVtable < + * mut ::std::os::raw::c_char >)) ); assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(BaseWithVtable<*mut ::std::os::raw::c_char>) - ) + ::std::mem::align_of:: < BaseWithVtable < * mut ::std::os::raw::c_char > > (), + 8usize, concat!("Alignment of template specialization: ", + stringify!(BaseWithVtable < * mut ::std::os::raw::c_char >)) ); } #[test] -fn __bindgen_test_layout_BaseWithVtable_open0_ptr_char_close0_instantiation_1() -{ +fn __bindgen_test_layout_BaseWithVtable_open0_ptr_char_close0_instantiation_1() { assert_eq!( - ::std::mem::size_of::>(), - 16usize, - concat!( - "Size of template specialization: ", - stringify!(BaseWithVtable<*mut ::std::os::raw::c_char>) - ) + ::std::mem::size_of:: < BaseWithVtable < * mut ::std::os::raw::c_char > > (), + 16usize, concat!("Size of template specialization: ", stringify!(BaseWithVtable < + * mut ::std::os::raw::c_char >)) ); assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(BaseWithVtable<*mut ::std::os::raw::c_char>) - ) + ::std::mem::align_of:: < BaseWithVtable < * mut ::std::os::raw::c_char > > (), + 8usize, concat!("Alignment of template specialization: ", + stringify!(BaseWithVtable < * mut ::std::os::raw::c_char >)) ); } #[test] -fn __bindgen_test_layout_BaseWithoutVtable_open0_ptr_char_close0_instantiation() -{ +fn __bindgen_test_layout_BaseWithoutVtable_open0_ptr_char_close0_instantiation() { assert_eq!( - ::std::mem::size_of::>(), - 8usize, - concat!( - "Size of template specialization: ", - stringify!(BaseWithoutVtable<*mut ::std::os::raw::c_char>) - ) + ::std::mem::size_of:: < BaseWithoutVtable < * mut ::std::os::raw::c_char > > (), + 8usize, concat!("Size of template specialization: ", stringify!(BaseWithoutVtable + < * mut ::std::os::raw::c_char >)) ); assert_eq!( - ::std::mem::align_of::>( - ), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(BaseWithoutVtable<*mut ::std::os::raw::c_char>) - ) + ::std::mem::align_of:: < BaseWithoutVtable < * mut ::std::os::raw::c_char > > (), + 8usize, concat!("Alignment of template specialization: ", + stringify!(BaseWithoutVtable < * mut ::std::os::raw::c_char >)) ); } #[test] -fn __bindgen_test_layout_BaseWithoutVtable_open0_ptr_char_close0_instantiation_1( -) { - assert_eq!( - ::std::mem::size_of::>(), - 8usize, - concat!( - "Size of template specialization: ", - stringify!(BaseWithoutVtable<*mut ::std::os::raw::c_char>) - ) - ); - assert_eq!( - ::std::mem::align_of::>( - ), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(BaseWithoutVtable<*mut ::std::os::raw::c_char>) - ) +fn __bindgen_test_layout_BaseWithoutVtable_open0_ptr_char_close0_instantiation_1() { + assert_eq!( + ::std::mem::size_of:: < BaseWithoutVtable < * mut ::std::os::raw::c_char > > (), + 8usize, concat!("Size of template specialization: ", stringify!(BaseWithoutVtable + < * mut ::std::os::raw::c_char >)) + ); + assert_eq!( + ::std::mem::align_of:: < BaseWithoutVtable < * mut ::std::os::raw::c_char > > (), + 8usize, concat!("Alignment of template specialization: ", + stringify!(BaseWithoutVtable < * mut ::std::os::raw::c_char >)) ); } diff --git a/bindgen-tests/tests/expectations/tests/inherit-namespaced.rs b/bindgen-tests/tests/expectations/tests/inherit-namespaced.rs index 2c4546eb41..52888c4626 100644 --- a/bindgen-tests/tests/expectations/tests/inherit-namespaced.rs +++ b/bindgen-tests/tests/expectations/tests/inherit-namespaced.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct js_RootedBase { diff --git a/bindgen-tests/tests/expectations/tests/inherit_multiple_interfaces.rs b/bindgen-tests/tests/expectations/tests/inherit_multiple_interfaces.rs index 46aa15db77..dfb69e4d32 100644 --- a/bindgen-tests/tests/expectations/tests/inherit_multiple_interfaces.rs +++ b/bindgen-tests/tests/expectations/tests/inherit_multiple_interfaces.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct A__bindgen_vtable {} #[repr(C)] @@ -15,22 +9,16 @@ pub struct A { } #[test] fn bindgen_test_layout_A() { - const UNINIT: ::std::mem::MaybeUninit
= - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(A)) + ::std::mem::size_of:: < A > (), 16usize, concat!("Size of: ", stringify!(A)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(A)) + ::std::mem::align_of:: < A > (), 8usize, concat!("Alignment of ", stringify!(A)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, - 8usize, + unsafe { ::std::ptr::addr_of!((* ptr).member) as usize - ptr as usize }, 8usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(member)) ); } @@ -53,28 +41,17 @@ pub struct B { } #[test] fn bindgen_test_layout_B() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(B)) + ::std::mem::size_of:: < B > (), 16usize, concat!("Size of: ", stringify!(B)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(B)) + ::std::mem::align_of:: < B > (), 8usize, concat!("Alignment of ", stringify!(B)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member2) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(B), - "::", - stringify!(member2) - ) + unsafe { ::std::ptr::addr_of!((* ptr).member2) as usize - ptr as usize }, 8usize, + concat!("Offset of field: ", stringify!(B), "::", stringify!(member2)) ); } impl Default for B { @@ -95,28 +72,17 @@ pub struct C { } #[test] fn bindgen_test_layout_C() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 40usize, - concat!("Size of: ", stringify!(C)) + ::std::mem::size_of:: < C > (), 40usize, concat!("Size of: ", stringify!(C)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(C)) + ::std::mem::align_of:: < C > (), 8usize, concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member3) as usize - ptr as usize }, - 32usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(member3) - ) + unsafe { ::std::ptr::addr_of!((* ptr).member3) as usize - ptr as usize }, + 32usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(member3)) ); } impl Default for C { diff --git a/bindgen-tests/tests/expectations/tests/inherit_named.rs b/bindgen-tests/tests/expectations/tests/inherit_named.rs index a8eee20767..4b3bbd7d63 100644 --- a/bindgen-tests/tests/expectations/tests/inherit_named.rs +++ b/bindgen-tests/tests/expectations/tests/inherit_named.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Wohoo { diff --git a/bindgen-tests/tests/expectations/tests/inherit_typedef.rs b/bindgen-tests/tests/expectations/tests/inherit_typedef.rs index 285dd44f1c..bd4f358a08 100644 --- a/bindgen-tests/tests/expectations/tests/inherit_typedef.rs +++ b/bindgen-tests/tests/expectations/tests/inherit_typedef.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { @@ -13,14 +7,11 @@ pub struct Foo { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) + ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", + stringify!(Foo)) ); } pub type TypedefedFoo = Foo; @@ -32,13 +23,10 @@ pub struct Bar { #[test] fn bindgen_test_layout_Bar() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Bar)) + ::std::mem::size_of:: < Bar > (), 1usize, concat!("Size of: ", stringify!(Bar)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Bar)) + ::std::mem::align_of:: < Bar > (), 1usize, concat!("Alignment of ", + stringify!(Bar)) ); } diff --git a/bindgen-tests/tests/expectations/tests/inline-function.rs b/bindgen-tests/tests/expectations/tests/inline-function.rs index 131dbdf39f..fe64295a68 100644 --- a/bindgen-tests/tests/expectations/tests/inline-function.rs +++ b/bindgen-tests/tests/expectations/tests/inline-function.rs @@ -1,6 +1 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] \ No newline at end of file diff --git a/bindgen-tests/tests/expectations/tests/inline_namespace.rs b/bindgen-tests/tests/expectations/tests/inline_namespace.rs index c569bba688..2764065e29 100644 --- a/bindgen-tests/tests/expectations/tests/inline_namespace.rs +++ b/bindgen-tests/tests/expectations/tests/inline_namespace.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![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 { #[allow(unused_imports)] @@ -21,28 +15,19 @@ pub mod root { } #[test] fn bindgen_test_layout_Bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Bar)) + ::std::mem::size_of:: < Bar > (), 4usize, concat!("Size of: ", + stringify!(Bar)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Bar)) + ::std::mem::align_of:: < Bar > (), 4usize, concat!("Alignment of ", + stringify!(Bar)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(baz) - ) + unsafe { ::std::ptr::addr_of!((* ptr).baz) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz)) ); } } diff --git a/bindgen-tests/tests/expectations/tests/inline_namespace_allowlist.rs b/bindgen-tests/tests/expectations/tests/inline_namespace_allowlist.rs index 1f4bc686c1..915a40c654 100644 --- a/bindgen-tests/tests/expectations/tests/inline_namespace_allowlist.rs +++ b/bindgen-tests/tests/expectations/tests/inline_namespace_allowlist.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![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 { #[allow(unused_imports)] diff --git a/bindgen-tests/tests/expectations/tests/inline_namespace_conservative.rs b/bindgen-tests/tests/expectations/tests/inline_namespace_conservative.rs index 4ffafd46b7..510cfacc04 100644 --- a/bindgen-tests/tests/expectations/tests/inline_namespace_conservative.rs +++ b/bindgen-tests/tests/expectations/tests/inline_namespace_conservative.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![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 { #[allow(unused_imports)] @@ -26,28 +20,19 @@ pub mod root { } #[test] fn bindgen_test_layout_Bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Bar)) + ::std::mem::size_of:: < Bar > (), 4usize, concat!("Size of: ", + stringify!(Bar)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Bar)) + ::std::mem::align_of:: < Bar > (), 4usize, concat!("Alignment of ", + stringify!(Bar)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(baz) - ) + unsafe { ::std::ptr::addr_of!((* ptr).baz) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz)) ); } } diff --git a/bindgen-tests/tests/expectations/tests/inline_namespace_nested.rs b/bindgen-tests/tests/expectations/tests/inline_namespace_nested.rs index 29b5b35ffa..1474f47ba2 100644 --- a/bindgen-tests/tests/expectations/tests/inline_namespace_nested.rs +++ b/bindgen-tests/tests/expectations/tests/inline_namespace_nested.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![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 { #[allow(unused_imports)] diff --git a/bindgen-tests/tests/expectations/tests/inline_namespace_no_ns_enabled.rs b/bindgen-tests/tests/expectations/tests/inline_namespace_no_ns_enabled.rs index 7a0c993555..bc3a95d2a5 100644 --- a/bindgen-tests/tests/expectations/tests/inline_namespace_no_ns_enabled.rs +++ b/bindgen-tests/tests/expectations/tests/inline_namespace_no_ns_enabled.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug)] pub struct std_basic_string { diff --git a/bindgen-tests/tests/expectations/tests/inner-typedef-gh422.rs b/bindgen-tests/tests/expectations/tests/inner-typedef-gh422.rs index 1cfa549c32..0cc6880b44 100644 --- a/bindgen-tests/tests/expectations/tests/inner-typedef-gh422.rs +++ b/bindgen-tests/tests/expectations/tests/inner-typedef-gh422.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { diff --git a/bindgen-tests/tests/expectations/tests/inner_const.rs b/bindgen-tests/tests/expectations/tests/inner_const.rs index 69a7c39a69..78f178e0c6 100644 --- a/bindgen-tests/tests/expectations/tests/inner_const.rs +++ b/bindgen-tests/tests/expectations/tests/inner_const.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { @@ -20,22 +14,17 @@ extern "C" { } #[test] fn bindgen_test_layout_Foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of:: < Foo > (), 4usize, concat!("Size of: ", stringify!(Foo)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Foo)) + ::std::mem::align_of:: < Foo > (), 4usize, concat!("Alignment of ", + stringify!(Foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) ); } diff --git a/bindgen-tests/tests/expectations/tests/inner_template_self.rs b/bindgen-tests/tests/expectations/tests/inner_template_self.rs index 13d9ac1423..49de8a6319 100644 --- a/bindgen-tests/tests/expectations/tests/inner_template_self.rs +++ b/bindgen-tests/tests/expectations/tests/inner_template_self.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct LinkedList { @@ -27,28 +21,19 @@ pub struct InstantiateIt { } #[test] fn bindgen_test_layout_InstantiateIt() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(InstantiateIt)) + ::std::mem::size_of:: < InstantiateIt > (), 16usize, concat!("Size of: ", + stringify!(InstantiateIt)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(InstantiateIt)) + ::std::mem::align_of:: < InstantiateIt > (), 8usize, concat!("Alignment of ", + stringify!(InstantiateIt)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).m_list) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(InstantiateIt), - "::", - stringify!(m_list) - ) + unsafe { ::std::ptr::addr_of!((* ptr).m_list) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(InstantiateIt), "::", stringify!(m_list)) ); } impl Default for InstantiateIt { @@ -63,16 +48,11 @@ impl Default for InstantiateIt { #[test] fn __bindgen_test_layout_LinkedList_open0_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of::(), - 16usize, + ::std::mem::size_of:: < LinkedList > (), 16usize, concat!("Size of template specialization: ", stringify!(LinkedList)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(LinkedList) - ) + ::std::mem::align_of:: < LinkedList > (), 8usize, + concat!("Alignment of template specialization: ", stringify!(LinkedList)) ); } diff --git a/bindgen-tests/tests/expectations/tests/int128_t.rs b/bindgen-tests/tests/expectations/tests/int128_t.rs index 131dbdf39f..fe64295a68 100644 --- a/bindgen-tests/tests/expectations/tests/int128_t.rs +++ b/bindgen-tests/tests/expectations/tests/int128_t.rs @@ -1,6 +1 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] \ No newline at end of file diff --git a/bindgen-tests/tests/expectations/tests/issue-1025-unknown-enum-repr.rs b/bindgen-tests/tests/expectations/tests/issue-1025-unknown-enum-repr.rs index c42e167fba..6e27b94ca9 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1025-unknown-enum-repr.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1025-unknown-enum-repr.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct a { diff --git a/bindgen-tests/tests/expectations/tests/issue-1034.rs b/bindgen-tests/tests/expectations/tests/issue-1034.rs index 32f4310e49..f626f9cb84 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1034.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1034.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -100,21 +92,17 @@ pub struct S2 { #[test] fn bindgen_test_layout_S2() { assert_eq!( - ::std::mem::size_of::(), - 2usize, - concat!("Size of: ", stringify!(S2)) + ::std::mem::size_of:: < S2 > (), 2usize, concat!("Size of: ", stringify!(S2)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(S2)) + ::std::mem::align_of:: < S2 > (), 1usize, concat!("Alignment of ", + stringify!(S2)) ); } impl S2 { #[inline] pub fn new_bitfield_1() -> __BindgenBitfieldUnit<[u8; 2usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 2usize]> = - Default::default(); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 2usize]> = Default::default(); __bindgen_bitfield_unit } } diff --git a/bindgen-tests/tests/expectations/tests/issue-1040.rs b/bindgen-tests/tests/expectations/tests/issue-1040.rs index 8503e8d226..788c480424 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1040.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1040.rs @@ -1,8 +1,2 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const g_107: ::std::os::raw::c_ulonglong = 18446744073709551615; diff --git a/bindgen-tests/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs b/bindgen-tests/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs index d91dd8fa5c..5ece85654e 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -100,21 +92,17 @@ pub struct S1 { #[test] fn bindgen_test_layout_S1() { assert_eq!( - ::std::mem::size_of::(), - 3usize, - concat!("Size of: ", stringify!(S1)) + ::std::mem::size_of:: < S1 > (), 3usize, concat!("Size of: ", stringify!(S1)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(S1)) + ::std::mem::align_of:: < S1 > (), 1usize, concat!("Alignment of ", + stringify!(S1)) ); } impl S1 { #[inline] pub fn new_bitfield_1() -> __BindgenBitfieldUnit<[u8; 3usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 3usize]> = - Default::default(); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 3usize]> = Default::default(); __bindgen_bitfield_unit } } diff --git a/bindgen-tests/tests/expectations/tests/issue-1113-template-references.rs b/bindgen-tests/tests/expectations/tests/issue-1113-template-references.rs index c146583521..d42621beaf 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1113-template-references.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1113-template-references.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Entry { diff --git a/bindgen-tests/tests/expectations/tests/issue-1118-using-forward-decl.rs b/bindgen-tests/tests/expectations/tests/issue-1118-using-forward-decl.rs index e881c8c482..d602ff8835 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1118-using-forward-decl.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1118-using-forward-decl.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type c = nsTArray; #[repr(C)] #[derive(Debug, Copy, Clone)] @@ -13,28 +7,19 @@ pub struct nsTArray_base { } #[test] fn bindgen_test_layout_nsTArray_base() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(nsTArray_base)) + ::std::mem::size_of:: < nsTArray_base > (), 8usize, concat!("Size of: ", + stringify!(nsTArray_base)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(nsTArray_base)) + ::std::mem::align_of:: < nsTArray_base > (), 8usize, concat!("Alignment of ", + stringify!(nsTArray_base)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsTArray_base), - "::", - stringify!(d) - ) + unsafe { ::std::ptr::addr_of!((* ptr).d) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(nsTArray_base), "::", stringify!(d)) ); } impl Default for nsTArray_base { @@ -67,28 +52,19 @@ pub struct nsIContent { } #[test] fn bindgen_test_layout_nsIContent() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(nsIContent)) + ::std::mem::size_of:: < nsIContent > (), 8usize, concat!("Size of: ", + stringify!(nsIContent)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(nsIContent)) + ::std::mem::align_of:: < nsIContent > (), 8usize, concat!("Alignment of ", + stringify!(nsIContent)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsIContent), - "::", - stringify!(foo) - ) + unsafe { ::std::ptr::addr_of!((* ptr).foo) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(nsIContent), "::", stringify!(foo)) ); } impl Default for nsIContent { @@ -107,33 +83,22 @@ extern "C" { #[test] fn __bindgen_test_layout_nsTArray_open0_ptr_nsIContent_close0_instantiation() { assert_eq!( - ::std::mem::size_of::(), - 8usize, + ::std::mem::size_of:: < nsTArray > (), 8usize, concat!("Size of template specialization: ", stringify!(nsTArray)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(nsTArray) - ) + ::std::mem::align_of:: < nsTArray > (), 8usize, + concat!("Alignment of template specialization: ", stringify!(nsTArray)) ); } #[test] -fn __bindgen_test_layout_nsTArray_open0_ptr_nsIContent_close0_instantiation_1() -{ +fn __bindgen_test_layout_nsTArray_open0_ptr_nsIContent_close0_instantiation_1() { assert_eq!( - ::std::mem::size_of::(), - 8usize, + ::std::mem::size_of:: < nsTArray > (), 8usize, concat!("Size of template specialization: ", stringify!(nsTArray)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(nsTArray) - ) + ::std::mem::align_of:: < nsTArray > (), 8usize, + concat!("Alignment of template specialization: ", stringify!(nsTArray)) ); } diff --git a/bindgen-tests/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs b/bindgen-tests/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs index fd023363d7..83bb62df9e 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct Foo__bindgen_vtable(::std::os::raw::c_void); #[repr(C)] @@ -15,14 +9,11 @@ pub struct Foo { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of:: < Foo > (), 8usize, concat!("Size of: ", stringify!(Foo)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Foo)) + ::std::mem::align_of:: < Foo > (), 8usize, concat!("Alignment of ", + stringify!(Foo)) ); } impl Default for Foo { diff --git a/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-bitfield-enum.rs b/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-bitfield-enum.rs index ed9f7c9ba8..7bbcb0d50b 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-bitfield-enum.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-bitfield-enum.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] impl MyDupeEnum { pub const A: MyDupeEnum = MyDupeEnum(0); } diff --git a/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-const-mod-bitfield-enum.rs b/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-const-mod-bitfield-enum.rs index 81c74abbf0..76c1de0b1c 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-const-mod-bitfield-enum.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-const-mod-bitfield-enum.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod MyDupeEnum { pub type Type = ::std::os::raw::c_uint; pub const A: Type = 0; diff --git a/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-const-mod-enum.rs b/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-const-mod-enum.rs index 81c74abbf0..76c1de0b1c 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-const-mod-enum.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-const-mod-enum.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod MyDupeEnum { pub type Type = ::std::os::raw::c_uint; pub const A: Type = 0; diff --git a/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-enum.rs b/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-enum.rs index fda73a021f..f41d6e90ec 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-enum.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-enum.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] impl MyDupeEnum { pub const A_alias: MyDupeEnum = MyDupeEnum::A; } diff --git a/bindgen-tests/tests/expectations/tests/issue-1216-variadic-member.rs b/bindgen-tests/tests/expectations/tests/issue-1216-variadic-member.rs index bb57c8568a..7c4fb568c9 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1216-variadic-member.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1216-variadic-member.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub fn f(a: ::std::os::raw::c_int, ...); } @@ -22,22 +16,17 @@ pub struct Foo { } #[test] fn bindgen_test_layout_Foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of:: < Foo > (), 8usize, concat!("Size of: ", stringify!(Foo)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Foo)) + ::std::mem::align_of:: < Foo > (), 8usize, concat!("Alignment of ", + stringify!(Foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).f) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(f)) ); } diff --git a/bindgen-tests/tests/expectations/tests/issue-1238-fwd-no-copy.rs b/bindgen-tests/tests/expectations/tests/issue-1238-fwd-no-copy.rs index 006900cb6e..81e8fed5f3 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1238-fwd-no-copy.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1238-fwd-no-copy.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug)] pub struct MyType { diff --git a/bindgen-tests/tests/expectations/tests/issue-1281.rs b/bindgen-tests/tests/expectations/tests/issue-1281.rs index db99cbce99..61e2c3690a 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1281.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1281.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct bar { @@ -17,43 +11,33 @@ pub struct foo { } #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of:: < foo > (), 4usize, concat!("Size of: ", stringify!(foo)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) + ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", + stringify!(foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).foo) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(foo)) ); } #[test] fn bindgen_test_layout_bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(bar)) + ::std::mem::size_of:: < bar > (), 4usize, concat!("Size of: ", stringify!(bar)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(bar)) + ::std::mem::align_of:: < bar > (), 4usize, concat!("Alignment of ", + stringify!(bar)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).u) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(bar), "::", stringify!(u)) ); } @@ -65,22 +49,17 @@ pub struct baz { } #[test] fn bindgen_test_layout_baz() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(baz)) + ::std::mem::size_of:: < baz > (), 4usize, concat!("Size of: ", stringify!(baz)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(baz)) + ::std::mem::align_of:: < baz > (), 4usize, concat!("Alignment of ", + stringify!(baz)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).f) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(baz), "::", stringify!(f)) ); } diff --git a/bindgen-tests/tests/expectations/tests/issue-1285.rs b/bindgen-tests/tests/expectations/tests/issue-1285.rs index 08aab0a94c..322bcdd288 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1285.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1285.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone)] pub struct foo { @@ -18,38 +12,23 @@ pub union foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)) + ::std::mem::size_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Size of: ", + stringify!(foo__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) + ::std::mem::align_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", + stringify!(foo__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)) ); } impl Default for foo__bindgen_ty_1 { @@ -63,22 +42,17 @@ impl Default for foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of:: < foo > (), 4usize, concat!("Size of: ", stringify!(foo)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) + ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", + stringify!(foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); } diff --git a/bindgen-tests/tests/expectations/tests/issue-1291.rs b/bindgen-tests/tests/expectations/tests/issue-1291.rs index 25f4f1055d..c7bb3efdab 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1291.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1291.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[repr(align(16))] #[derive(Debug, Default, Copy, Clone)] @@ -27,157 +21,74 @@ pub struct RTCRay { } #[test] fn bindgen_test_layout_RTCRay() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 96usize, - concat!("Size of: ", stringify!(RTCRay)) - ); - assert_eq!( - ::std::mem::align_of::(), - 16usize, - concat!("Alignment of ", stringify!(RTCRay)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).org) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(org) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).align0) as usize - ptr as usize }, - 12usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(align0) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dir) as usize - ptr as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(dir) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).align1) as usize - ptr as usize }, - 28usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(align1) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).tnear) as usize - ptr as usize }, - 32usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(tnear) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).tfar) as usize - ptr as usize }, - 36usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(tfar) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).time) as usize - ptr as usize }, - 40usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(time) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize }, - 44usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(mask) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).Ng) as usize - ptr as usize }, - 48usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(Ng) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).align2) as usize - ptr as usize }, - 60usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(align2) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize }, - 64usize, + ::std::mem::size_of:: < RTCRay > (), 96usize, concat!("Size of: ", + stringify!(RTCRay)) + ); + assert_eq!( + ::std::mem::align_of:: < RTCRay > (), 16usize, concat!("Alignment of ", + stringify!(RTCRay)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).org) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(org)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).align0) as usize - ptr as usize }, 12usize, + concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(align0)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).dir) as usize - ptr as usize }, 16usize, + concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(dir)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).align1) as usize - ptr as usize }, 28usize, + concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(align1)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).tnear) as usize - ptr as usize }, 32usize, + concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(tnear)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).tfar) as usize - ptr as usize }, 36usize, + concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(tfar)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).time) as usize - ptr as usize }, 40usize, + concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(time)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).mask) as usize - ptr as usize }, 44usize, + concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(mask)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).Ng) as usize - ptr as usize }, 48usize, + concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(Ng)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).align2) as usize - ptr as usize }, 60usize, + concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(align2)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).u) as usize - ptr as usize }, 64usize, concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(u)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).v) as usize - ptr as usize }, - 68usize, + unsafe { ::std::ptr::addr_of!((* ptr).v) as usize - ptr as usize }, 68usize, concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(v)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).geomID) as usize - ptr as usize }, - 72usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(geomID) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).primID) as usize - ptr as usize }, - 76usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(primID) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).instID) as usize - ptr as usize }, - 80usize, - concat!( - "Offset of field: ", - stringify!(RTCRay), - "::", - stringify!(instID) - ) + unsafe { ::std::ptr::addr_of!((* ptr).geomID) as usize - ptr as usize }, 72usize, + concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(geomID)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).primID) as usize - ptr as usize }, 76usize, + concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(primID)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).instID) as usize - ptr as usize }, 80usize, + concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(instID)) ); } diff --git a/bindgen-tests/tests/expectations/tests/issue-1350-attribute-overloadable.rs b/bindgen-tests/tests/expectations/tests/issue-1350-attribute-overloadable.rs index 4deed06055..908ccfbc2e 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1350-attribute-overloadable.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1350-attribute-overloadable.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { #[link_name = "\u{1}_Z11my_functioni"] pub fn my_function(a: ::std::os::raw::c_int); diff --git a/bindgen-tests/tests/expectations/tests/issue-1375-prefixed-functions.rs b/bindgen-tests/tests/expectations/tests/issue-1375-prefixed-functions.rs index edcca46d8a..2e9a594a31 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1375-prefixed-functions.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1375-prefixed-functions.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { #[link_name = "\u{1}my_custom_prefix_var_const_name"] pub static var_const_name: ::std::os::raw::c_int; diff --git a/bindgen-tests/tests/expectations/tests/issue-1382-rust-primitive-types.rs b/bindgen-tests/tests/expectations/tests/issue-1382-rust-primitive-types.rs index b767d5e430..2c45a20d6e 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1382-rust-primitive-types.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1382-rust-primitive-types.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type i8_ = i8; pub type u8_ = u8; pub type i16_ = i16; @@ -33,107 +27,69 @@ pub struct Foo { } #[test] fn bindgen_test_layout_Foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 56usize, - concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of:: < Foo > (), 56usize, concat!("Size of: ", stringify!(Foo)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Foo)) + ::std::mem::align_of:: < Foo > (), 4usize, concat!("Alignment of ", + stringify!(Foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i8_) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).i8_) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i8_)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).u8_) as usize - ptr as usize }, - 4usize, + unsafe { ::std::ptr::addr_of!((* ptr).u8_) as usize - ptr as usize }, 4usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u8_)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i16_) as usize - ptr as usize }, - 8usize, + unsafe { ::std::ptr::addr_of!((* ptr).i16_) as usize - ptr as usize }, 8usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i16_)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).u16_) as usize - ptr as usize }, - 12usize, + unsafe { ::std::ptr::addr_of!((* ptr).u16_) as usize - ptr as usize }, 12usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u16_)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i32_) as usize - ptr as usize }, - 16usize, + unsafe { ::std::ptr::addr_of!((* ptr).i32_) as usize - ptr as usize }, 16usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i32_)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).u32_) as usize - ptr as usize }, - 20usize, + unsafe { ::std::ptr::addr_of!((* ptr).u32_) as usize - ptr as usize }, 20usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u32_)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i64_) as usize - ptr as usize }, - 24usize, + unsafe { ::std::ptr::addr_of!((* ptr).i64_) as usize - ptr as usize }, 24usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i64_)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).u64_) as usize - ptr as usize }, - 28usize, + unsafe { ::std::ptr::addr_of!((* ptr).u64_) as usize - ptr as usize }, 28usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u64_)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i128_) as usize - ptr as usize }, - 32usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(i128_) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).u128_) as usize - ptr as usize }, - 36usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(u128_) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).isize_) as usize - ptr as usize }, - 40usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(isize_) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).usize_) as usize - ptr as usize }, - 44usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(usize_) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).f32_) as usize - ptr as usize }, - 48usize, + unsafe { ::std::ptr::addr_of!((* ptr).i128_) as usize - ptr as usize }, 32usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i128_)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).u128_) as usize - ptr as usize }, 36usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u128_)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).isize_) as usize - ptr as usize }, 40usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(isize_)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).usize_) as usize - ptr as usize }, 44usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(usize_)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).f32_) as usize - ptr as usize }, 48usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(f32_)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).f64_) as usize - ptr as usize }, - 52usize, + unsafe { ::std::ptr::addr_of!((* ptr).f64_) as usize - ptr as usize }, 52usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(f64_)) ); } diff --git a/bindgen-tests/tests/expectations/tests/issue-1435.rs b/bindgen-tests/tests/expectations/tests/issue-1435.rs index 79ed7b294b..3040c1451e 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1435.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1435.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![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 { #[allow(unused_imports)] @@ -16,7 +10,7 @@ pub mod root { pub const AB_B: root::ns::AB = 1; pub type AB = ::std::os::raw::c_int; } - pub use self::super::root::ns::AB; + pub use self::super::root::ns::AB as AB; extern "C" { #[link_name = "\u{1}_ZL2kA"] pub static kA: root::AB; diff --git a/bindgen-tests/tests/expectations/tests/issue-1443.rs b/bindgen-tests/tests/expectations/tests/issue-1443.rs index 48cae79faa..32aae6c379 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1443.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1443.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Foo { @@ -18,27 +12,21 @@ pub struct Bar { } #[test] fn bindgen_test_layout_Bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(Bar)) + ::std::mem::size_of:: < Bar > (), 16usize, concat!("Size of: ", stringify!(Bar)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Bar)) + ::std::mem::align_of:: < Bar > (), 8usize, concat!("Alignment of ", + stringify!(Bar)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).f) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(f)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize }, - 8usize, + unsafe { ::std::ptr::addr_of!((* ptr).m) as usize - ptr as usize }, 8usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(m)) ); } @@ -59,27 +47,21 @@ pub struct Baz { } #[test] fn bindgen_test_layout_Baz() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(Baz)) + ::std::mem::size_of:: < Baz > (), 16usize, concat!("Size of: ", stringify!(Baz)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Baz)) + ::std::mem::align_of:: < Baz > (), 8usize, concat!("Alignment of ", + stringify!(Baz)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).f) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Baz), "::", stringify!(f)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize }, - 8usize, + unsafe { ::std::ptr::addr_of!((* ptr).m) as usize - ptr as usize }, 8usize, concat!("Offset of field: ", stringify!(Baz), "::", stringify!(m)) ); } @@ -100,27 +82,21 @@ pub struct Tar { } #[test] fn bindgen_test_layout_Tar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(Tar)) + ::std::mem::size_of:: < Tar > (), 16usize, concat!("Size of: ", stringify!(Tar)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Tar)) + ::std::mem::align_of:: < Tar > (), 8usize, concat!("Alignment of ", + stringify!(Tar)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).f) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Tar), "::", stringify!(f)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize }, - 8usize, + unsafe { ::std::ptr::addr_of!((* ptr).m) as usize - ptr as usize }, 8usize, concat!("Offset of field: ", stringify!(Tar), "::", stringify!(m)) ); } @@ -141,27 +117,21 @@ pub struct Taz { } #[test] fn bindgen_test_layout_Taz() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(Taz)) + ::std::mem::size_of:: < Taz > (), 16usize, concat!("Size of: ", stringify!(Taz)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Taz)) + ::std::mem::align_of:: < Taz > (), 8usize, concat!("Alignment of ", + stringify!(Taz)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).f) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Taz), "::", stringify!(f)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize }, - 8usize, + unsafe { ::std::ptr::addr_of!((* ptr).m) as usize - ptr as usize }, 8usize, concat!("Offset of field: ", stringify!(Taz), "::", stringify!(m)) ); } diff --git a/bindgen-tests/tests/expectations/tests/issue-1454.rs b/bindgen-tests/tests/expectations/tests/issue-1454.rs index 8da43cb090..188a2eb09f 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1454.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1454.rs @@ -1,14 +1,7 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug)] pub struct extern_type; - #[repr(C)] #[derive(Debug)] pub struct local_type { @@ -16,27 +9,18 @@ pub struct local_type { } #[test] fn bindgen_test_layout_local_type() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(local_type)) + ::std::mem::size_of:: < local_type > (), 0usize, concat!("Size of: ", + stringify!(local_type)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(local_type)) + ::std::mem::align_of:: < local_type > (), 1usize, concat!("Alignment of ", + stringify!(local_type)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).inner) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(local_type), - "::", - stringify!(inner) - ) + unsafe { ::std::ptr::addr_of!((* ptr).inner) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(local_type), "::", stringify!(inner)) ); } diff --git a/bindgen-tests/tests/expectations/tests/issue-1464.rs b/bindgen-tests/tests/expectations/tests/issue-1464.rs index 131dbdf39f..fe64295a68 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1464.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1464.rs @@ -1,6 +1 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] \ No newline at end of file diff --git a/bindgen-tests/tests/expectations/tests/issue-1488-enum-new-type.rs b/bindgen-tests/tests/expectations/tests/issue-1488-enum-new-type.rs index b762659a50..60882da2d5 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1488-enum-new-type.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1488-enum-new-type.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const Foo_A: Foo = 0; pub const Foo_B: Foo = 1; pub type Foo = ::std::os::raw::c_uint; diff --git a/bindgen-tests/tests/expectations/tests/issue-1488-options.rs b/bindgen-tests/tests/expectations/tests/issue-1488-options.rs index cf13b56284..0f6efb93d4 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1488-options.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1488-options.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type OSStatus = ::std::os::raw::c_int; #[repr(transparent)] #[derive(Debug, Copy, Clone)] diff --git a/bindgen-tests/tests/expectations/tests/issue-1488-template-alias-new-type.rs b/bindgen-tests/tests/expectations/tests/issue-1488-template-alias-new-type.rs index 1af0c5751d..de43753e9c 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1488-template-alias-new-type.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1488-template-alias-new-type.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(transparent)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Wrapped(pub T); diff --git a/bindgen-tests/tests/expectations/tests/issue-1498.rs b/bindgen-tests/tests/expectations/tests/issue-1498.rs index eb5e280457..bfbf3becf6 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1498.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1498.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C, packed)] #[derive(Copy, Clone)] pub struct rte_memseg { @@ -32,38 +26,25 @@ pub union rte_memseg__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_memseg__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, + ::std::mem::size_of:: < rte_memseg__bindgen_ty_1 > (), 8usize, concat!("Size of: ", stringify!(rte_memseg__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, + ::std::mem::align_of:: < rte_memseg__bindgen_ty_1 > (), 8usize, concat!("Alignment of ", stringify!(rte_memseg__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).addr) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_memseg__bindgen_ty_1), - "::", - stringify!(addr) - ) + unsafe { ::std::ptr::addr_of!((* ptr).addr) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_memseg__bindgen_ty_1), "::", + stringify!(addr)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).addr_64) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_memseg__bindgen_ty_1), - "::", - stringify!(addr_64) - ) + unsafe { ::std::ptr::addr_of!((* ptr).addr_64) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_memseg__bindgen_ty_1), "::", + stringify!(addr_64)) ); } impl Default for rte_memseg__bindgen_ty_1 { @@ -77,86 +58,43 @@ impl Default for rte_memseg__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_memseg() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 44usize, - concat!("Size of: ", stringify!(rte_memseg)) + ::std::mem::size_of:: < rte_memseg > (), 44usize, concat!("Size of: ", + stringify!(rte_memseg)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(rte_memseg)) + ::std::mem::align_of:: < rte_memseg > (), 1usize, concat!("Alignment of ", + stringify!(rte_memseg)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).phys_addr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_memseg), - "::", - stringify!(phys_addr) - ) + unsafe { ::std::ptr::addr_of!((* ptr).phys_addr) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_memseg), "::", + stringify!(phys_addr)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_memseg), - "::", - stringify!(len) - ) + unsafe { ::std::ptr::addr_of!((* ptr).len) as usize - ptr as usize }, 16usize, + concat!("Offset of field: ", stringify!(rte_memseg), "::", stringify!(len)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).hugepage_sz) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(rte_memseg), - "::", - stringify!(hugepage_sz) - ) + unsafe { ::std::ptr::addr_of!((* ptr).hugepage_sz) as usize - ptr as usize }, + 24usize, concat!("Offset of field: ", stringify!(rte_memseg), "::", + stringify!(hugepage_sz)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).socket_id) as usize - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(rte_memseg), - "::", - stringify!(socket_id) - ) + unsafe { ::std::ptr::addr_of!((* ptr).socket_id) as usize - ptr as usize }, + 32usize, concat!("Offset of field: ", stringify!(rte_memseg), "::", + stringify!(socket_id)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).nchannel) as usize - ptr as usize - }, - 36usize, - concat!( - "Offset of field: ", - stringify!(rte_memseg), - "::", - stringify!(nchannel) - ) + unsafe { ::std::ptr::addr_of!((* ptr).nchannel) as usize - ptr as usize }, + 36usize, concat!("Offset of field: ", stringify!(rte_memseg), "::", + stringify!(nchannel)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).nrank) as usize - ptr as usize }, - 40usize, - concat!( - "Offset of field: ", - stringify!(rte_memseg), - "::", - stringify!(nrank) - ) + unsafe { ::std::ptr::addr_of!((* ptr).nrank) as usize - ptr as usize }, 40usize, + concat!("Offset of field: ", stringify!(rte_memseg), "::", stringify!(nrank)) ); } impl Default for rte_memseg { diff --git a/bindgen-tests/tests/expectations/tests/issue-1514.rs b/bindgen-tests/tests/expectations/tests/issue-1514.rs index 31939ca588..a52272ef93 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1514.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1514.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Thing { diff --git a/bindgen-tests/tests/expectations/tests/issue-1554.rs b/bindgen-tests/tests/expectations/tests/issue-1554.rs index 7e7cddd610..7b1a2cd410 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1554.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1554.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(feature = "nightly")] #![feature(non_exhaustive)] - #[repr(u32)] #[non_exhaustive] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] diff --git a/bindgen-tests/tests/expectations/tests/issue-1599-opaque-typedef-to-enum.rs b/bindgen-tests/tests/expectations/tests/issue-1599-opaque-typedef-to-enum.rs index eacb34111c..325ee4adc4 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1599-opaque-typedef-to-enum.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1599-opaque-typedef-to-enum.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const a_b: a = 0; pub const a_c: a = 1; pub type a = ::std::os::raw::c_uint; diff --git a/bindgen-tests/tests/expectations/tests/issue-1676-macro-namespace-prefix.rs b/bindgen-tests/tests/expectations/tests/issue-1676-macro-namespace-prefix.rs index 131dbdf39f..fe64295a68 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1676-macro-namespace-prefix.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1676-macro-namespace-prefix.rs @@ -1,6 +1 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] \ No newline at end of file diff --git a/bindgen-tests/tests/expectations/tests/issue-1947.rs b/bindgen-tests/tests/expectations/tests/issue-1947.rs index e133ed85ba..de05e8bbe9 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1947.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1947.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -107,56 +99,33 @@ pub struct V56AMDY { } #[test] fn bindgen_test_layout_V56AMDY() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(V56AMDY)) + ::std::mem::size_of:: < V56AMDY > (), 8usize, concat!("Size of: ", + stringify!(V56AMDY)) ); assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(V56AMDY)) + ::std::mem::align_of:: < V56AMDY > (), 2usize, concat!("Alignment of ", + stringify!(V56AMDY)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).MADK) as usize - ptr as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(V56AMDY), - "::", - stringify!(MADK) - ) + unsafe { ::std::ptr::addr_of!((* ptr).MADK) as usize - ptr as usize }, 2usize, + concat!("Offset of field: ", stringify!(V56AMDY), "::", stringify!(MADK)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).MABR) as usize - ptr as usize }, - 3usize, - concat!( - "Offset of field: ", - stringify!(V56AMDY), - "::", - stringify!(MABR) - ) + unsafe { ::std::ptr::addr_of!((* ptr).MABR) as usize - ptr as usize }, 3usize, + concat!("Offset of field: ", stringify!(V56AMDY), "::", stringify!(MABR)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr)._rB_) as usize - ptr as usize }, - 7usize, - concat!( - "Offset of field: ", - stringify!(V56AMDY), - "::", - stringify!(_rB_) - ) + unsafe { ::std::ptr::addr_of!((* ptr)._rB_) as usize - ptr as usize }, 7usize, + concat!("Offset of field: ", stringify!(V56AMDY), "::", stringify!(_rB_)) ); } impl V56AMDY { #[inline] pub fn MADZ(&self) -> U16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 10u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 10u8) as u16) } } #[inline] pub fn set_MADZ(&mut self, val: U16) { @@ -167,9 +136,7 @@ impl V56AMDY { } #[inline] pub fn MAI0(&self) -> U16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(10usize, 2u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(10usize, 2u8) as u16) } } #[inline] pub fn set_MAI0(&mut self, val: U16) { @@ -180,9 +147,7 @@ impl V56AMDY { } #[inline] pub fn MAI1(&self) -> U16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(12usize, 2u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(12usize, 2u8) as u16) } } #[inline] pub fn set_MAI1(&mut self, val: U16) { @@ -193,9 +158,7 @@ impl V56AMDY { } #[inline] pub fn MAI2(&self) -> U16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(14usize, 2u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(14usize, 2u8) as u16) } } #[inline] pub fn set_MAI2(&mut self, val: U16) { @@ -211,31 +174,48 @@ impl V56AMDY { MAI1: U16, MAI2: U16, ) -> __BindgenBitfieldUnit<[u8; 2usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 2usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 10u8, { - let MADZ: u16 = unsafe { ::std::mem::transmute(MADZ) }; - MADZ as u64 - }); - __bindgen_bitfield_unit.set(10usize, 2u8, { - let MAI0: u16 = unsafe { ::std::mem::transmute(MAI0) }; - MAI0 as u64 - }); - __bindgen_bitfield_unit.set(12usize, 2u8, { - let MAI1: u16 = unsafe { ::std::mem::transmute(MAI1) }; - MAI1 as u64 - }); - __bindgen_bitfield_unit.set(14usize, 2u8, { - let MAI2: u16 = unsafe { ::std::mem::transmute(MAI2) }; - MAI2 as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 2usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 10u8, + { + let MADZ: u16 = unsafe { ::std::mem::transmute(MADZ) }; + MADZ as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 10usize, + 2u8, + { + let MAI0: u16 = unsafe { ::std::mem::transmute(MAI0) }; + MAI0 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 12usize, + 2u8, + { + let MAI1: u16 = unsafe { ::std::mem::transmute(MAI1) }; + MAI1 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 14usize, + 2u8, + { + let MAI2: u16 = unsafe { ::std::mem::transmute(MAI2) }; + MAI2 as u64 + }, + ); __bindgen_bitfield_unit } #[inline] pub fn MATH(&self) -> U16 { - unsafe { - ::std::mem::transmute(self._bitfield_2.get(0usize, 10u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_2.get(0usize, 10u8) as u16) } } #[inline] pub fn set_MATH(&mut self, val: U16) { @@ -246,9 +226,7 @@ impl V56AMDY { } #[inline] pub fn MATE(&self) -> U16 { - unsafe { - ::std::mem::transmute(self._bitfield_2.get(10usize, 4u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_2.get(10usize, 4u8) as u16) } } #[inline] pub fn set_MATE(&mut self, val: U16) { @@ -259,9 +237,7 @@ impl V56AMDY { } #[inline] pub fn MATW(&self) -> U16 { - unsafe { - ::std::mem::transmute(self._bitfield_2.get(14usize, 2u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_2.get(14usize, 2u8) as u16) } } #[inline] pub fn set_MATW(&mut self, val: U16) { @@ -272,9 +248,7 @@ impl V56AMDY { } #[inline] pub fn MASW(&self) -> U8 { - unsafe { - ::std::mem::transmute(self._bitfield_2.get(16usize, 4u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_2.get(16usize, 4u8) as u8) } } #[inline] pub fn set_MASW(&mut self, val: U8) { @@ -285,9 +259,7 @@ impl V56AMDY { } #[inline] pub fn MABW(&self) -> U8 { - unsafe { - ::std::mem::transmute(self._bitfield_2.get(20usize, 3u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_2.get(20usize, 3u8) as u8) } } #[inline] pub fn set_MABW(&mut self, val: U8) { @@ -298,9 +270,7 @@ impl V56AMDY { } #[inline] pub fn MAXN(&self) -> U8 { - unsafe { - ::std::mem::transmute(self._bitfield_2.get(23usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_2.get(23usize, 1u8) as u8) } } #[inline] pub fn set_MAXN(&mut self, val: U8) { @@ -318,32 +288,61 @@ impl V56AMDY { MABW: U8, MAXN: U8, ) -> __BindgenBitfieldUnit<[u8; 3usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 3usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 10u8, { - let MATH: u16 = unsafe { ::std::mem::transmute(MATH) }; - MATH as u64 - }); - __bindgen_bitfield_unit.set(10usize, 4u8, { - let MATE: u16 = unsafe { ::std::mem::transmute(MATE) }; - MATE as u64 - }); - __bindgen_bitfield_unit.set(14usize, 2u8, { - let MATW: u16 = unsafe { ::std::mem::transmute(MATW) }; - MATW as u64 - }); - __bindgen_bitfield_unit.set(16usize, 4u8, { - let MASW: u8 = unsafe { ::std::mem::transmute(MASW) }; - MASW as u64 - }); - __bindgen_bitfield_unit.set(20usize, 3u8, { - let MABW: u8 = unsafe { ::std::mem::transmute(MABW) }; - MABW as u64 - }); - __bindgen_bitfield_unit.set(23usize, 1u8, { - let MAXN: u8 = unsafe { ::std::mem::transmute(MAXN) }; - MAXN as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 3usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 10u8, + { + let MATH: u16 = unsafe { ::std::mem::transmute(MATH) }; + MATH as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 10usize, + 4u8, + { + let MATE: u16 = unsafe { ::std::mem::transmute(MATE) }; + MATE as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 14usize, + 2u8, + { + let MATW: u16 = unsafe { ::std::mem::transmute(MATW) }; + MATW as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 16usize, + 4u8, + { + let MASW: u8 = unsafe { ::std::mem::transmute(MASW) }; + MASW as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 20usize, + 3u8, + { + let MABW: u8 = unsafe { ::std::mem::transmute(MABW) }; + MABW as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 23usize, + 1u8, + { + let MAXN: u8 = unsafe { ::std::mem::transmute(MAXN) }; + MAXN as u64 + }, + ); __bindgen_bitfield_unit } } diff --git a/bindgen-tests/tests/expectations/tests/issue-1977-larger-arrays.rs b/bindgen-tests/tests/expectations/tests/issue-1977-larger-arrays.rs index 6375ea7e67..c7a0d74d0f 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1977-larger-arrays.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1977-larger-arrays.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct S { @@ -12,30 +6,18 @@ pub struct S { } #[test] fn bindgen_test_layout_S() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 33usize, - concat!("Size of: ", stringify!(S)) + ::std::mem::size_of:: < S > (), 33usize, concat!("Size of: ", stringify!(S)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(S)) + ::std::mem::align_of:: < S > (), 1usize, concat!("Alignment of ", stringify!(S)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(S), - "::", - stringify!(large_array) - ) + unsafe { ::std::ptr::addr_of!((* ptr).large_array) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(S), "::", + stringify!(large_array)) ); } impl Default for S { diff --git a/bindgen-tests/tests/expectations/tests/issue-1995.rs b/bindgen-tests/tests/expectations/tests/issue-1995.rs index 890479b5df..0035989e62 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1995.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1995.rs @@ -1,17 +1,11 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +/** This is a constant that has a docstring -/// This is a constant that has a docstring -/// -/// And expected to be found in generated bindings code too. + And expected to be found in generated bindings code too.*/ pub const FOO: ::std::os::raw::c_int = 1; -/// This is a constant that has a docstring -/// -/// And expected to be found in generated bindings code too. +/** This is a constant that has a docstring + + And expected to be found in generated bindings code too.*/ #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Bar { @@ -19,22 +13,17 @@ pub struct Bar { } #[test] fn bindgen_test_layout_Bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Bar)) + ::std::mem::size_of:: < Bar > (), 4usize, concat!("Size of: ", stringify!(Bar)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Bar)) + ::std::mem::align_of:: < Bar > (), 4usize, concat!("Alignment of ", + stringify!(Bar)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).baz) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz)) ); } diff --git a/bindgen-tests/tests/expectations/tests/issue-2019.rs b/bindgen-tests/tests/expectations/tests/issue-2019.rs index 294e9f0e83..3879af2a3c 100644 --- a/bindgen-tests/tests/expectations/tests/issue-2019.rs +++ b/bindgen-tests/tests/expectations/tests/issue-2019.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct A { @@ -12,22 +6,16 @@ pub struct A { } #[test] fn bindgen_test_layout_A() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(A)) + ::std::mem::size_of:: < A > (), 4usize, concat!("Size of: ", stringify!(A)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(A)) + ::std::mem::align_of:: < A > (), 4usize, concat!("Alignment of ", stringify!(A)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(a)) ); } @@ -48,22 +36,16 @@ pub struct B { } #[test] fn bindgen_test_layout_B() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(B)) + ::std::mem::size_of:: < B > (), 4usize, concat!("Size of: ", stringify!(B)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(B)) + ::std::mem::align_of:: < B > (), 4usize, concat!("Alignment of ", stringify!(B)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(B), "::", stringify!(b)) ); } diff --git a/bindgen-tests/tests/expectations/tests/issue-2239-template-dependent-bit-width.rs b/bindgen-tests/tests/expectations/tests/issue-2239-template-dependent-bit-width.rs index 75ec9e439e..6ff58b7559 100644 --- a/bindgen-tests/tests/expectations/tests/issue-2239-template-dependent-bit-width.rs +++ b/bindgen-tests/tests/expectations/tests/issue-2239-template-dependent-bit-width.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct b { diff --git a/bindgen-tests/tests/expectations/tests/issue-358.rs b/bindgen-tests/tests/expectations/tests/issue-358.rs index e9ee0f502f..ff915e9fba 100644 --- a/bindgen-tests/tests/expectations/tests/issue-358.rs +++ b/bindgen-tests/tests/expectations/tests/issue-358.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct JS_PersistentRooted { diff --git a/bindgen-tests/tests/expectations/tests/issue-372.rs b/bindgen-tests/tests/expectations/tests/issue-372.rs index e87fb4d108..1f4b81b83d 100644 --- a/bindgen-tests/tests/expectations/tests/issue-372.rs +++ b/bindgen-tests/tests/expectations/tests/issue-372.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![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 { #[allow(unused_imports)] @@ -18,32 +12,25 @@ pub mod root { } #[test] fn bindgen_test_layout_i() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 24usize, - concat!("Size of: ", stringify!(i)) + ::std::mem::size_of:: < i > (), 24usize, concat!("Size of: ", stringify!(i)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(i)) + ::std::mem::align_of:: < i > (), 8usize, concat!("Alignment of ", + stringify!(i)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).j) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).j) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(i), "::", stringify!(j)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).k) as usize - ptr as usize }, - 8usize, + unsafe { ::std::ptr::addr_of!((* ptr).k) as usize - ptr as usize }, 8usize, concat!("Offset of field: ", stringify!(i), "::", stringify!(k)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).l) as usize - ptr as usize }, - 16usize, + unsafe { ::std::ptr::addr_of!((* ptr).l) as usize - ptr as usize }, 16usize, concat!("Offset of field: ", stringify!(i), "::", stringify!(l)) ); } @@ -63,22 +50,17 @@ pub mod root { } #[test] fn bindgen_test_layout_d() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 24usize, - concat!("Size of: ", stringify!(d)) + ::std::mem::size_of:: < d > (), 24usize, concat!("Size of: ", stringify!(d)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(d)) + ::std::mem::align_of:: < d > (), 8usize, concat!("Alignment of ", + stringify!(d)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).m) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(d), "::", stringify!(m)) ); } @@ -113,22 +95,17 @@ pub mod root { } #[test] fn bindgen_test_layout_F() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 264usize, - concat!("Size of: ", stringify!(F)) + ::std::mem::size_of:: < F > (), 264usize, concat!("Size of: ", stringify!(F)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(F)) + ::std::mem::align_of:: < F > (), 8usize, concat!("Alignment of ", + stringify!(F)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).w) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).w) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(F), "::", stringify!(w)) ); } diff --git a/bindgen-tests/tests/expectations/tests/issue-410.rs b/bindgen-tests/tests/expectations/tests/issue-410.rs index ad7463c266..2b849fa240 100644 --- a/bindgen-tests/tests/expectations/tests/issue-410.rs +++ b/bindgen-tests/tests/expectations/tests/issue-410.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![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 { #[allow(unused_imports)] @@ -20,14 +14,12 @@ pub mod root { #[test] fn bindgen_test_layout_Value() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Value)) + ::std::mem::size_of:: < Value > (), 1usize, concat!("Size of: ", + stringify!(Value)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Value)) + ::std::mem::align_of:: < Value > (), 1usize, concat!("Alignment of ", + stringify!(Value)) ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/issue-446.rs b/bindgen-tests/tests/expectations/tests/issue-446.rs index db69f159c7..5d625cb311 100644 --- a/bindgen-tests/tests/expectations/tests/issue-446.rs +++ b/bindgen-tests/tests/expectations/tests/issue-446.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct List { diff --git a/bindgen-tests/tests/expectations/tests/issue-447.rs b/bindgen-tests/tests/expectations/tests/issue-447.rs index 949db73b79..ea5dc92bec 100644 --- a/bindgen-tests/tests/expectations/tests/issue-447.rs +++ b/bindgen-tests/tests/expectations/tests/issue-447.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![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 { #[allow(unused_imports)] @@ -23,13 +17,11 @@ pub mod root { #[test] fn bindgen_test_layout_GuardObjectNotifier() { assert_eq!( - ::std::mem::size_of::(), - 1usize, + ::std::mem::size_of:: < GuardObjectNotifier > (), 1usize, concat!("Size of: ", stringify!(GuardObjectNotifier)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < GuardObjectNotifier > (), 1usize, concat!("Alignment of ", stringify!(GuardObjectNotifier)) ); } @@ -43,13 +35,11 @@ pub mod root { #[test] fn bindgen_test_layout_JSAutoCompartment() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(JSAutoCompartment)) + ::std::mem::size_of:: < JSAutoCompartment > (), 1usize, concat!("Size of: ", + stringify!(JSAutoCompartment)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < JSAutoCompartment > (), 1usize, concat!("Alignment of ", stringify!(JSAutoCompartment)) ); } @@ -62,14 +52,9 @@ pub mod root { } impl JSAutoCompartment { #[inline] - pub unsafe fn new( - arg1: root::mozilla::detail::GuardObjectNotifier, - ) -> Self { + pub unsafe fn new(arg1: root::mozilla::detail::GuardObjectNotifier) -> Self { let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); - JSAutoCompartment_JSAutoCompartment( - __bindgen_tmp.as_mut_ptr(), - arg1, - ); + JSAutoCompartment_JSAutoCompartment(__bindgen_tmp.as_mut_ptr(), arg1); __bindgen_tmp.assume_init() } } diff --git a/bindgen-tests/tests/expectations/tests/issue-493.rs b/bindgen-tests/tests/expectations/tests/issue-493.rs index 61c7f7929e..16c5cc7e58 100644 --- a/bindgen-tests/tests/expectations/tests/issue-493.rs +++ b/bindgen-tests/tests/expectations/tests/issue-493.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -72,8 +66,7 @@ impl Default for basic_string___long { } } } -pub const basic_string___min_cap: basic_string__bindgen_ty_1 = - basic_string__bindgen_ty_1::__min_cap; +pub const basic_string___min_cap: basic_string__bindgen_ty_1 = basic_string__bindgen_ty_1::__min_cap; #[repr(i32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum basic_string__bindgen_ty_1 { @@ -123,8 +116,7 @@ impl Default for basic_string___ulx { } } } -pub const basic_string___n_words: basic_string__bindgen_ty_2 = - basic_string__bindgen_ty_2::__n_words; +pub const basic_string___n_words: basic_string__bindgen_ty_2 = basic_string__bindgen_ty_2::__n_words; #[repr(i32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum basic_string__bindgen_ty_2 { diff --git a/bindgen-tests/tests/expectations/tests/issue-493_1_0.rs b/bindgen-tests/tests/expectations/tests/issue-493_1_0.rs index 1a0131c327..0716802fe2 100644 --- a/bindgen-tests/tests/expectations/tests/issue-493_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/issue-493_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -72,8 +66,7 @@ impl Default for basic_string___long { } } } -pub const basic_string___min_cap: basic_string__bindgen_ty_1 = - basic_string__bindgen_ty_1::__min_cap; +pub const basic_string___min_cap: basic_string__bindgen_ty_1 = basic_string__bindgen_ty_1::__min_cap; #[repr(i32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum basic_string__bindgen_ty_1 { @@ -108,8 +101,7 @@ pub struct basic_string___ulx { pub __lxx: __BindgenUnionField, pub bindgen_union_field: [u8; 0usize], } -pub const basic_string___n_words: basic_string__bindgen_ty_2 = - basic_string__bindgen_ty_2::__n_words; +pub const basic_string___n_words: basic_string__bindgen_ty_2 = basic_string__bindgen_ty_2::__n_words; #[repr(i32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum basic_string__bindgen_ty_2 { diff --git a/bindgen-tests/tests/expectations/tests/issue-511.rs b/bindgen-tests/tests/expectations/tests/issue-511.rs index b7705ef2b1..e2bb991946 100644 --- a/bindgen-tests/tests/expectations/tests/issue-511.rs +++ b/bindgen-tests/tests/expectations/tests/issue-511.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub static mut a: *mut ::std::os::raw::c_char; } 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 b1e42ca72a..bf848673cb 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 @@ -1,13 +1,7 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(feature = "nightly")] - -/// This should not be opaque; we can see the attributes and can pack the -/// struct. +/** This should not be opaque; we can see the attributes and can pack the + struct.*/ #[repr(C, packed)] #[derive(Debug, Default, Copy, Clone)] pub struct AlignedToOne { @@ -15,28 +9,19 @@ pub struct AlignedToOne { } #[test] fn bindgen_test_layout_AlignedToOne() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(AlignedToOne)) + ::std::mem::size_of:: < AlignedToOne > (), 4usize, concat!("Size of: ", + stringify!(AlignedToOne)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(AlignedToOne)) + ::std::mem::align_of:: < AlignedToOne > (), 1usize, concat!("Alignment of ", + stringify!(AlignedToOne)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AlignedToOne), - "::", - stringify!(i) - ) + unsafe { ::std::ptr::addr_of!((* ptr).i) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(AlignedToOne), "::", stringify!(i)) ); } /// This should be be packed because Rust 1.33 has `#[repr(packed(N))]`. @@ -47,33 +32,24 @@ pub struct AlignedToTwo { } #[test] fn bindgen_test_layout_AlignedToTwo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(AlignedToTwo)) + ::std::mem::size_of:: < AlignedToTwo > (), 4usize, concat!("Size of: ", + stringify!(AlignedToTwo)) ); assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(AlignedToTwo)) + ::std::mem::align_of:: < AlignedToTwo > (), 2usize, concat!("Alignment of ", + stringify!(AlignedToTwo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AlignedToTwo), - "::", - stringify!(i) - ) + unsafe { ::std::ptr::addr_of!((* ptr).i) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(AlignedToTwo), "::", stringify!(i)) ); } -/// 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. +/** 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.*/ #[repr(C, packed)] #[derive(Debug, Default, Copy, Clone)] pub struct PackedToOne { @@ -82,38 +58,23 @@ pub struct PackedToOne { } #[test] fn bindgen_test_layout_PackedToOne() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(PackedToOne)) + ::std::mem::size_of:: < PackedToOne > (), 8usize, concat!("Size of: ", + stringify!(PackedToOne)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(PackedToOne)) + ::std::mem::align_of:: < PackedToOne > (), 1usize, concat!("Alignment of ", + stringify!(PackedToOne)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(PackedToOne), - "::", - stringify!(x) - ) + unsafe { ::std::ptr::addr_of!((* ptr).x) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(PackedToOne), "::", stringify!(x)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(PackedToOne), - "::", - stringify!(y) - ) + unsafe { ::std::ptr::addr_of!((* ptr).y) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(PackedToOne), "::", stringify!(y)) ); } /// This should be be packed because Rust 1.33 has `#[repr(packed(N))]`. @@ -125,37 +86,22 @@ pub struct PackedToTwo { } #[test] fn bindgen_test_layout_PackedToTwo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(PackedToTwo)) + ::std::mem::size_of:: < PackedToTwo > (), 8usize, concat!("Size of: ", + stringify!(PackedToTwo)) ); assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(PackedToTwo)) + ::std::mem::align_of:: < PackedToTwo > (), 2usize, concat!("Alignment of ", + stringify!(PackedToTwo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(PackedToTwo), - "::", - stringify!(x) - ) + unsafe { ::std::ptr::addr_of!((* ptr).x) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(PackedToTwo), "::", stringify!(x)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(PackedToTwo), - "::", - stringify!(y) - ) + unsafe { ::std::ptr::addr_of!((* ptr).y) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(PackedToTwo), "::", stringify!(y)) ); } diff --git a/bindgen-tests/tests/expectations/tests/issue-537.rs b/bindgen-tests/tests/expectations/tests/issue-537.rs index e2be9d63ba..a0387cd9d0 100644 --- a/bindgen-tests/tests/expectations/tests/issue-537.rs +++ b/bindgen-tests/tests/expectations/tests/issue-537.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -/// This should not be opaque; we can see the attributes and can pack the -/// struct. +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +/** This should not be opaque; we can see the attributes and can pack the + struct.*/ #[repr(C, packed)] #[derive(Debug, Default, Copy, Clone)] pub struct AlignedToOne { @@ -14,32 +8,23 @@ pub struct AlignedToOne { } #[test] fn bindgen_test_layout_AlignedToOne() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(AlignedToOne)) + ::std::mem::size_of:: < AlignedToOne > (), 4usize, concat!("Size of: ", + stringify!(AlignedToOne)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(AlignedToOne)) + ::std::mem::align_of:: < AlignedToOne > (), 1usize, concat!("Alignment of ", + stringify!(AlignedToOne)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AlignedToOne), - "::", - stringify!(i) - ) + unsafe { ::std::ptr::addr_of!((* ptr).i) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(AlignedToOne), "::", stringify!(i)) ); } -/// This should be opaque because although we can see the attributes, Rust before -/// 1.33 doesn't have `#[repr(packed(N))]`. +/** This should be opaque because although we can see the attributes, Rust before + 1.33 doesn't have `#[repr(packed(N))]`.*/ #[repr(C, packed(2))] #[derive(Debug, Default, Copy, Clone)] pub struct AlignedToTwo { @@ -47,33 +32,24 @@ pub struct AlignedToTwo { } #[test] fn bindgen_test_layout_AlignedToTwo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(AlignedToTwo)) + ::std::mem::size_of:: < AlignedToTwo > (), 4usize, concat!("Size of: ", + stringify!(AlignedToTwo)) ); assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(AlignedToTwo)) + ::std::mem::align_of:: < AlignedToTwo > (), 2usize, concat!("Alignment of ", + stringify!(AlignedToTwo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AlignedToTwo), - "::", - stringify!(i) - ) + unsafe { ::std::ptr::addr_of!((* ptr).i) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(AlignedToTwo), "::", stringify!(i)) ); } -/// 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. +/** 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.*/ #[repr(C, packed)] #[derive(Debug, Default, Copy, Clone)] pub struct PackedToOne { @@ -82,43 +58,28 @@ pub struct PackedToOne { } #[test] fn bindgen_test_layout_PackedToOne() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(PackedToOne)) + ::std::mem::size_of:: < PackedToOne > (), 8usize, concat!("Size of: ", + stringify!(PackedToOne)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(PackedToOne)) + ::std::mem::align_of:: < PackedToOne > (), 1usize, concat!("Alignment of ", + stringify!(PackedToOne)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(PackedToOne), - "::", - stringify!(x) - ) + unsafe { ::std::ptr::addr_of!((* ptr).x) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(PackedToOne), "::", stringify!(x)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(PackedToOne), - "::", - stringify!(y) - ) + unsafe { ::std::ptr::addr_of!((* ptr).y) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(PackedToOne), "::", stringify!(y)) ); } -/// In this case, even if we can detect the weird alignment triggered by -/// `#pragma pack(2)`, we can't do anything about it because Rust before 1.33 -/// doesn't have `#[repr(packed(N))]`. Therefore, we must make it opaque. +/** In this case, even if we can detect the weird alignment triggered by + `#pragma pack(2)`, we can't do anything about it because Rust before 1.33 + doesn't have `#[repr(packed(N))]`. Therefore, we must make it opaque.*/ #[repr(C, packed(2))] #[derive(Debug, Default, Copy, Clone)] pub struct PackedToTwo { @@ -127,37 +88,22 @@ pub struct PackedToTwo { } #[test] fn bindgen_test_layout_PackedToTwo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(PackedToTwo)) + ::std::mem::size_of:: < PackedToTwo > (), 8usize, concat!("Size of: ", + stringify!(PackedToTwo)) ); assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(PackedToTwo)) + ::std::mem::align_of:: < PackedToTwo > (), 2usize, concat!("Alignment of ", + stringify!(PackedToTwo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(PackedToTwo), - "::", - stringify!(x) - ) + unsafe { ::std::ptr::addr_of!((* ptr).x) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(PackedToTwo), "::", stringify!(x)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(PackedToTwo), - "::", - stringify!(y) - ) + unsafe { ::std::ptr::addr_of!((* ptr).y) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(PackedToTwo), "::", stringify!(y)) ); } diff --git a/bindgen-tests/tests/expectations/tests/issue-544-stylo-creduce-2.rs b/bindgen-tests/tests/expectations/tests/issue-544-stylo-creduce-2.rs index 6165419d65..835f029cb2 100644 --- a/bindgen-tests/tests/expectations/tests/issue-544-stylo-creduce-2.rs +++ b/bindgen-tests/tests/expectations/tests/issue-544-stylo-creduce-2.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct Foo { pub member: Foo_SecondAlias, diff --git a/bindgen-tests/tests/expectations/tests/issue-544-stylo-creduce.rs b/bindgen-tests/tests/expectations/tests/issue-544-stylo-creduce.rs index 1516c0a95e..b9c42ae12a 100644 --- a/bindgen-tests/tests/expectations/tests/issue-544-stylo-creduce.rs +++ b/bindgen-tests/tests/expectations/tests/issue-544-stylo-creduce.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct a { diff --git a/bindgen-tests/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs b/bindgen-tests/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs index 997a73112d..a1a2f1e52b 100644 --- a/bindgen-tests/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs +++ b/bindgen-tests/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const ENUM_VARIANT_1: _bindgen_ty_1 = _bindgen_ty_1::ENUM_VARIANT_1; pub const ENUM_VARIANT_2: _bindgen_ty_1 = _bindgen_ty_1::ENUM_VARIANT_2; #[repr(u32)] @@ -36,14 +30,12 @@ pub struct JS_AutoIdVector { #[test] fn bindgen_test_layout_JS_AutoIdVector() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(JS_AutoIdVector)) + ::std::mem::size_of:: < JS_AutoIdVector > (), 1usize, concat!("Size of: ", + stringify!(JS_AutoIdVector)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(JS_AutoIdVector)) + ::std::mem::align_of:: < JS_AutoIdVector > (), 1usize, concat!("Alignment of ", + stringify!(JS_AutoIdVector)) ); } impl Default for JS_AutoIdVector { @@ -58,16 +50,11 @@ impl Default for JS_AutoIdVector { #[test] fn __bindgen_test_layout_JS_Base_open0_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of::(), - 1usize, + ::std::mem::size_of:: < JS_Base > (), 1usize, concat!("Size of template specialization: ", stringify!(JS_Base)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!( - "Alignment of template specialization: ", - stringify!(JS_Base) - ) + ::std::mem::align_of:: < JS_Base > (), 1usize, + concat!("Alignment of template specialization: ", stringify!(JS_Base)) ); } diff --git a/bindgen-tests/tests/expectations/tests/issue-573-layout-test-failures.rs b/bindgen-tests/tests/expectations/tests/issue-573-layout-test-failures.rs index fbff136279..5b77a26a23 100644 --- a/bindgen-tests/tests/expectations/tests/issue-573-layout-test-failures.rs +++ b/bindgen-tests/tests/expectations/tests/issue-573-layout-test-failures.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Outer { @@ -17,40 +11,29 @@ pub struct AutoIdVector { } #[test] fn bindgen_test_layout_AutoIdVector() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(AutoIdVector)) + ::std::mem::size_of:: < AutoIdVector > (), 1usize, concat!("Size of: ", + stringify!(AutoIdVector)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(AutoIdVector)) + ::std::mem::align_of:: < AutoIdVector > (), 1usize, concat!("Alignment of ", + stringify!(AutoIdVector)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ar) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AutoIdVector), - "::", - stringify!(ar) - ) + unsafe { ::std::ptr::addr_of!((* ptr).ar) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(AutoIdVector), "::", stringify!(ar)) ); } #[test] fn __bindgen_test_layout_Outer_open0_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of::(), - 1usize, + ::std::mem::size_of:: < Outer > (), 1usize, concat!("Size of template specialization: ", stringify!(Outer)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < Outer > (), 1usize, concat!("Alignment of template specialization: ", stringify!(Outer)) ); } diff --git a/bindgen-tests/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs b/bindgen-tests/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs index 22aa9d16e6..2591c1aac5 100644 --- a/bindgen-tests/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs +++ b/bindgen-tests/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct a { @@ -17,28 +11,19 @@ pub struct _bindgen_ty_1 { } #[test] fn bindgen_test_layout__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit<_bindgen_ty_1> = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit<_bindgen_ty_1> = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::<_bindgen_ty_1>(), - 1usize, - concat!("Size of: ", stringify!(_bindgen_ty_1)) + ::std::mem::size_of:: < _bindgen_ty_1 > (), 1usize, concat!("Size of: ", + stringify!(_bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::<_bindgen_ty_1>(), - 1usize, - concat!("Alignment of ", stringify!(_bindgen_ty_1)) + ::std::mem::align_of:: < _bindgen_ty_1 > (), 1usize, concat!("Alignment of ", + stringify!(_bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ar) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_bindgen_ty_1), - "::", - stringify!(ar) - ) + unsafe { ::std::ptr::addr_of!((* ptr).ar) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(_bindgen_ty_1), "::", stringify!(ar)) ); } extern "C" { @@ -47,13 +32,11 @@ extern "C" { #[test] fn __bindgen_test_layout_a_open0_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of::(), - 1usize, + ::std::mem::size_of:: < a > (), 1usize, concat!("Size of template specialization: ", stringify!(a)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < a > (), 1usize, concat!("Alignment of template specialization: ", stringify!(a)) ); } diff --git a/bindgen-tests/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs b/bindgen-tests/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs index 3765315c43..96bbfe4c1b 100644 --- a/bindgen-tests/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs +++ b/bindgen-tests/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs @@ -1,12 +1,5 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type RefPtr = T; - #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct A { @@ -16,14 +9,10 @@ pub type A_a = b; #[test] fn bindgen_test_layout_A() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(A)) + ::std::mem::size_of:: < A > (), 1usize, concat!("Size of: ", stringify!(A)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(A)) + ::std::mem::align_of:: < A > (), 1usize, concat!("Alignment of ", stringify!(A)) ); } #[repr(C)] @@ -51,22 +40,16 @@ pub struct g { } #[test] fn bindgen_test_layout_g() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(g)) + ::std::mem::size_of:: < g > (), 1usize, concat!("Size of: ", stringify!(g)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(g)) + ::std::mem::align_of:: < g > (), 1usize, concat!("Alignment of ", stringify!(g)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).h) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).h) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(g), "::", stringify!(h)) ); } @@ -86,14 +69,10 @@ pub struct b { #[test] fn bindgen_test_layout_b() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(b)) + ::std::mem::size_of:: < b > (), 1usize, concat!("Size of: ", stringify!(b)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(b)) + ::std::mem::align_of:: < b > (), 1usize, concat!("Alignment of ", stringify!(b)) ); } impl Default for b { @@ -112,13 +91,11 @@ extern "C" { #[test] fn __bindgen_test_layout_f_open0_e_open1_int_close1_close0_instantiation() { assert_eq!( - ::std::mem::size_of::(), - 1usize, + ::std::mem::size_of:: < f > (), 1usize, concat!("Size of template specialization: ", stringify!(f)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < f > (), 1usize, concat!("Alignment of template specialization: ", stringify!(f)) ); } diff --git a/bindgen-tests/tests/expectations/tests/issue-638-stylo-cannot-find-T-in-this-scope.rs b/bindgen-tests/tests/expectations/tests/issue-638-stylo-cannot-find-T-in-this-scope.rs index ba886f361e..292fa2734f 100644 --- a/bindgen-tests/tests/expectations/tests/issue-638-stylo-cannot-find-T-in-this-scope.rs +++ b/bindgen-tests/tests/expectations/tests/issue-638-stylo-cannot-find-T-in-this-scope.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct RefPtr { diff --git a/bindgen-tests/tests/expectations/tests/issue-639-typedef-anon-field.rs b/bindgen-tests/tests/expectations/tests/issue-639-typedef-anon-field.rs index bac8a04c24..7e8bae67c7 100644 --- a/bindgen-tests/tests/expectations/tests/issue-639-typedef-anon-field.rs +++ b/bindgen-tests/tests/expectations/tests/issue-639-typedef-anon-field.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { @@ -17,48 +11,34 @@ pub struct Foo_Bar { } #[test] fn bindgen_test_layout_Foo_Bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Foo_Bar)) + ::std::mem::size_of:: < Foo_Bar > (), 4usize, concat!("Size of: ", + stringify!(Foo_Bar)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Foo_Bar)) + ::std::mem::align_of:: < Foo_Bar > (), 4usize, concat!("Alignment of ", + stringify!(Foo_Bar)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).abc) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Foo_Bar), - "::", - stringify!(abc) - ) + unsafe { ::std::ptr::addr_of!((* ptr).abc) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(Foo_Bar), "::", stringify!(abc)) ); } #[test] fn bindgen_test_layout_Foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of:: < Foo > (), 4usize, concat!("Size of: ", stringify!(Foo)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Foo)) + ::std::mem::align_of:: < Foo > (), 4usize, concat!("Alignment of ", + stringify!(Foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) ); } @@ -74,40 +54,28 @@ pub struct Baz_Bar { } #[test] fn bindgen_test_layout_Baz_Bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Baz_Bar)) + ::std::mem::size_of:: < Baz_Bar > (), 4usize, concat!("Size of: ", + stringify!(Baz_Bar)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Baz_Bar)) + ::std::mem::align_of:: < Baz_Bar > (), 4usize, concat!("Alignment of ", + stringify!(Baz_Bar)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).abc) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Baz_Bar), - "::", - stringify!(abc) - ) + unsafe { ::std::ptr::addr_of!((* ptr).abc) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(Baz_Bar), "::", stringify!(abc)) ); } #[test] fn bindgen_test_layout_Baz() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Baz)) + ::std::mem::size_of:: < Baz > (), 1usize, concat!("Size of: ", stringify!(Baz)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Baz)) + ::std::mem::align_of:: < Baz > (), 1usize, concat!("Alignment of ", + stringify!(Baz)) ); } diff --git a/bindgen-tests/tests/expectations/tests/issue-643-inner-struct.rs b/bindgen-tests/tests/expectations/tests/issue-643-inner-struct.rs index b69aa16ef3..103c0ce1ed 100644 --- a/bindgen-tests/tests/expectations/tests/issue-643-inner-struct.rs +++ b/bindgen-tests/tests/expectations/tests/issue-643-inner-struct.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Default)] pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); @@ -50,30 +44,20 @@ pub struct rte_ring_prod { } #[test] fn bindgen_test_layout_rte_ring_prod() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(rte_ring_prod)) + ::std::mem::size_of:: < rte_ring_prod > (), 4usize, concat!("Size of: ", + stringify!(rte_ring_prod)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(rte_ring_prod)) + ::std::mem::align_of:: < rte_ring_prod > (), 4usize, concat!("Alignment of ", + stringify!(rte_ring_prod)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).watermark) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ring_prod), - "::", - stringify!(watermark) - ) + unsafe { ::std::ptr::addr_of!((* ptr).watermark) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_ring_prod), "::", + stringify!(watermark)) ); } #[repr(C)] @@ -83,43 +67,31 @@ pub struct rte_ring_cons { } #[test] fn bindgen_test_layout_rte_ring_cons() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(rte_ring_cons)) + ::std::mem::size_of:: < rte_ring_cons > (), 4usize, concat!("Size of: ", + stringify!(rte_ring_cons)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(rte_ring_cons)) + ::std::mem::align_of:: < rte_ring_cons > (), 4usize, concat!("Alignment of ", + stringify!(rte_ring_cons)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).sc_dequeue) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ring_cons), - "::", - stringify!(sc_dequeue) - ) + unsafe { ::std::ptr::addr_of!((* ptr).sc_dequeue) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_ring_cons), "::", + stringify!(sc_dequeue)) ); } #[test] fn bindgen_test_layout_rte_ring() { assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(rte_ring)) + ::std::mem::size_of:: < rte_ring > (), 16usize, concat!("Size of: ", + stringify!(rte_ring)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(rte_ring)) + ::std::mem::align_of:: < rte_ring > (), 8usize, concat!("Alignment of ", + stringify!(rte_ring)) ); } impl Default for rte_ring { diff --git a/bindgen-tests/tests/expectations/tests/issue-645-cannot-find-type-T-in-this-scope.rs b/bindgen-tests/tests/expectations/tests/issue-645-cannot-find-type-T-in-this-scope.rs index 75d6581e2d..3e3e398006 100644 --- a/bindgen-tests/tests/expectations/tests/issue-645-cannot-find-type-T-in-this-scope.rs +++ b/bindgen-tests/tests/expectations/tests/issue-645-cannot-find-type-T-in-this-scope.rs @@ -1,13 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[derive(Clone, Copy, Debug)] pub struct RefPtr(T); - #[repr(C)] pub struct HasRefPtr { pub refptr_member: RefPtr>, 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 13cdf0c97b..0168c4e55a 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 @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -/// We emit a `[u8; 63usize]` padding field for this struct, which cannot derive -/// Debug/Hash because 63 is over the hard coded limit. +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +/** We emit a `[u8; 63usize]` padding field for this struct, which cannot derive + Debug/Hash because 63 is over the hard coded limit.*/ #[repr(C)] #[repr(align(64))] #[derive(Copy, Clone)] @@ -15,28 +9,19 @@ pub struct NoDebug { } #[test] fn bindgen_test_layout_NoDebug() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 64usize, - concat!("Size of: ", stringify!(NoDebug)) + ::std::mem::size_of:: < NoDebug > (), 64usize, concat!("Size of: ", + stringify!(NoDebug)) ); assert_eq!( - ::std::mem::align_of::(), - 64usize, - concat!("Alignment of ", stringify!(NoDebug)) + ::std::mem::align_of:: < NoDebug > (), 64usize, concat!("Alignment of ", + stringify!(NoDebug)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NoDebug), - "::", - stringify!(c) - ) + unsafe { ::std::ptr::addr_of!((* ptr).c) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(NoDebug), "::", stringify!(c)) ); } impl Default for NoDebug { @@ -53,10 +38,10 @@ impl ::std::cmp::PartialEq for NoDebug { 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. +/** 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)] @@ -66,38 +51,25 @@ pub struct ShouldDeriveDebugButDoesNot { } #[test] fn bindgen_test_layout_ShouldDeriveDebugButDoesNot() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 64usize, + ::std::mem::size_of:: < ShouldDeriveDebugButDoesNot > (), 64usize, concat!("Size of: ", stringify!(ShouldDeriveDebugButDoesNot)) ); assert_eq!( - ::std::mem::align_of::(), - 64usize, + ::std::mem::align_of:: < ShouldDeriveDebugButDoesNot > (), 64usize, concat!("Alignment of ", stringify!(ShouldDeriveDebugButDoesNot)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldDeriveDebugButDoesNot), - "::", - stringify!(c) - ) + unsafe { ::std::ptr::addr_of!((* ptr).c) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(ShouldDeriveDebugButDoesNot), "::", + stringify!(c)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 32usize, - concat!( - "Offset of field: ", - stringify!(ShouldDeriveDebugButDoesNot), - "::", - stringify!(d) - ) + unsafe { ::std::ptr::addr_of!((* ptr).d) as usize - ptr as usize }, 32usize, + concat!("Offset of field: ", stringify!(ShouldDeriveDebugButDoesNot), "::", + stringify!(d)) ); } impl Default for ShouldDeriveDebugButDoesNot { diff --git a/bindgen-tests/tests/expectations/tests/issue-654-struct-fn-collision.rs b/bindgen-tests/tests/expectations/tests/issue-654-struct-fn-collision.rs index 65d3a51636..289dac9a1c 100644 --- a/bindgen-tests/tests/expectations/tests/issue-654-struct-fn-collision.rs +++ b/bindgen-tests/tests/expectations/tests/issue-654-struct-fn-collision.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct foo { diff --git a/bindgen-tests/tests/expectations/tests/issue-662-cannot-find-T-in-this-scope.rs b/bindgen-tests/tests/expectations/tests/issue-662-cannot-find-T-in-this-scope.rs index 5636a977b4..5e6dd01298 100644 --- a/bindgen-tests/tests/expectations/tests/issue-662-cannot-find-T-in-this-scope.rs +++ b/bindgen-tests/tests/expectations/tests/issue-662-cannot-find-T-in-this-scope.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct RefPtr { diff --git a/bindgen-tests/tests/expectations/tests/issue-662-part-2.rs b/bindgen-tests/tests/expectations/tests/issue-662-part-2.rs index e8d14bfe89..75993a052d 100644 --- a/bindgen-tests/tests/expectations/tests/issue-662-part-2.rs +++ b/bindgen-tests/tests/expectations/tests/issue-662-part-2.rs @@ -1,13 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[derive(Clone, Copy, Debug)] pub struct RefPtr(T); - #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct nsMainThreadPtrHolder { diff --git a/bindgen-tests/tests/expectations/tests/issue-674-1.rs b/bindgen-tests/tests/expectations/tests/issue-674-1.rs index b37d7a27d7..e68a62b8fb 100644 --- a/bindgen-tests/tests/expectations/tests/issue-674-1.rs +++ b/bindgen-tests/tests/expectations/tests/issue-674-1.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![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 { #[allow(unused_imports)] @@ -26,28 +20,20 @@ pub mod root { } #[test] fn bindgen_test_layout_CapturingContentInfo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 1usize, + ::std::mem::size_of:: < CapturingContentInfo > (), 1usize, concat!("Size of: ", stringify!(CapturingContentInfo)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < CapturingContentInfo > (), 1usize, concat!("Alignment of ", stringify!(CapturingContentInfo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(CapturingContentInfo), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(CapturingContentInfo), "::", + stringify!(a)) ); } } diff --git a/bindgen-tests/tests/expectations/tests/issue-674-2.rs b/bindgen-tests/tests/expectations/tests/issue-674-2.rs index 12b2aa20a5..66b52dbc70 100644 --- a/bindgen-tests/tests/expectations/tests/issue-674-2.rs +++ b/bindgen-tests/tests/expectations/tests/issue-674-2.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![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 { #[allow(unused_imports)] @@ -26,22 +20,17 @@ pub mod root { } #[test] fn bindgen_test_layout_c() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(c)) + ::std::mem::size_of:: < c > (), 1usize, concat!("Size of: ", stringify!(c)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(c)) + ::std::mem::align_of:: < c > (), 1usize, concat!("Alignment of ", + stringify!(c)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(c), "::", stringify!(b)) ); } @@ -52,22 +41,17 @@ pub mod root { } #[test] fn bindgen_test_layout_B() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(B)) + ::std::mem::size_of:: < B > (), 1usize, concat!("Size of: ", stringify!(B)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(B)) + ::std::mem::align_of:: < B > (), 1usize, concat!("Alignment of ", + stringify!(B)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(B), "::", stringify!(a)) ); } @@ -79,20 +63,13 @@ pub mod root { #[test] fn __bindgen_test_layout_StaticRefPtr_open0_B_close0_instantiation() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!( - "Size of template specialization: ", - stringify!(root::StaticRefPtr) - ) + ::std::mem::size_of:: < root::StaticRefPtr > (), 1usize, + concat!("Size of template specialization: ", stringify!(root::StaticRefPtr)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!( - "Alignment of template specialization: ", - stringify!(root::StaticRefPtr) - ) + ::std::mem::align_of:: < root::StaticRefPtr > (), 1usize, + concat!("Alignment of template specialization: ", + stringify!(root::StaticRefPtr)) ); } } diff --git a/bindgen-tests/tests/expectations/tests/issue-674-3.rs b/bindgen-tests/tests/expectations/tests/issue-674-3.rs index e7af6b8dc0..72eda5dff0 100644 --- a/bindgen-tests/tests/expectations/tests/issue-674-3.rs +++ b/bindgen-tests/tests/expectations/tests/issue-674-3.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![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 { #[allow(unused_imports)] @@ -22,22 +16,17 @@ pub mod root { } #[test] fn bindgen_test_layout_a() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(a)) + ::std::mem::size_of:: < a > (), 1usize, concat!("Size of: ", stringify!(a)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(a)) + ::std::mem::align_of:: < a > (), 1usize, concat!("Alignment of ", + stringify!(a)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(a), "::", stringify!(b)) ); } @@ -48,28 +37,19 @@ pub mod root { } #[test] fn bindgen_test_layout_nsCSSValue() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(nsCSSValue)) + ::std::mem::size_of:: < nsCSSValue > (), 1usize, concat!("Size of: ", + stringify!(nsCSSValue)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(nsCSSValue)) + ::std::mem::align_of:: < nsCSSValue > (), 1usize, concat!("Alignment of ", + stringify!(nsCSSValue)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsCSSValue), - "::", - stringify!(c) - ) + unsafe { ::std::ptr::addr_of!((* ptr).c) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(nsCSSValue), "::", stringify!(c)) ); } } diff --git a/bindgen-tests/tests/expectations/tests/issue-677-nested-ns-specifier.rs b/bindgen-tests/tests/expectations/tests/issue-677-nested-ns-specifier.rs index 800f0dc84b..34ec99688a 100644 --- a/bindgen-tests/tests/expectations/tests/issue-677-nested-ns-specifier.rs +++ b/bindgen-tests/tests/expectations/tests/issue-677-nested-ns-specifier.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![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 { #[allow(unused_imports)] diff --git a/bindgen-tests/tests/expectations/tests/issue-691-template-parameter-virtual.rs b/bindgen-tests/tests/expectations/tests/issue-691-template-parameter-virtual.rs index e71b2aae91..0b659930a8 100644 --- a/bindgen-tests/tests/expectations/tests/issue-691-template-parameter-virtual.rs +++ b/bindgen-tests/tests/expectations/tests/issue-691-template-parameter-virtual.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct VirtualMethods__bindgen_vtable {} #[repr(C)] @@ -15,14 +9,12 @@ pub struct VirtualMethods { #[test] fn bindgen_test_layout_VirtualMethods() { assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(VirtualMethods)) + ::std::mem::size_of:: < VirtualMethods > (), 8usize, concat!("Size of: ", + stringify!(VirtualMethods)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(VirtualMethods)) + ::std::mem::align_of:: < VirtualMethods > (), 8usize, concat!("Alignment of ", + stringify!(VirtualMethods)) ); } impl Default for VirtualMethods { @@ -47,13 +39,11 @@ pub struct ServoElementSnapshotTable { #[test] fn bindgen_test_layout_ServoElementSnapshotTable() { assert_eq!( - ::std::mem::size_of::(), - 4usize, + ::std::mem::size_of:: < ServoElementSnapshotTable > (), 4usize, concat!("Size of: ", stringify!(ServoElementSnapshotTable)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < ServoElementSnapshotTable > (), 4usize, concat!("Alignment of ", stringify!(ServoElementSnapshotTable)) ); } @@ -69,13 +59,11 @@ impl Default for ServoElementSnapshotTable { #[test] fn __bindgen_test_layout_Set_open0_VirtualMethods_close0_instantiation() { assert_eq!( - ::std::mem::size_of::(), - 4usize, + ::std::mem::size_of:: < Set > (), 4usize, concat!("Size of template specialization: ", stringify!(Set)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < Set > (), 4usize, concat!("Alignment of template specialization: ", stringify!(Set)) ); } diff --git a/bindgen-tests/tests/expectations/tests/issue-710-must-use-type.rs b/bindgen-tests/tests/expectations/tests/issue-710-must-use-type.rs index 1d59824146..d7006dd011 100644 --- a/bindgen-tests/tests/expectations/tests/issue-710-must-use-type.rs +++ b/bindgen-tests/tests/expectations/tests/issue-710-must-use-type.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] #[must_use] diff --git a/bindgen-tests/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs b/bindgen-tests/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs index 1a633844f2..be1e01a66a 100644 --- a/bindgen-tests/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs @@ -1,11 +1,5 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(not(target_os = "windows"))] - #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -56,8 +50,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -77,8 +70,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -102,22 +94,17 @@ pub struct Foo { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of::(), - 32usize, - concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of:: < Foo > (), 32usize, concat!("Size of: ", stringify!(Foo)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Foo)) + ::std::mem::align_of:: < Foo > (), 8usize, concat!("Alignment of ", + stringify!(Foo)) ); } impl Foo { #[inline] pub fn m_bitfield(&self) -> ::std::os::raw::c_ulong { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 64u8) as u64) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 64u8) as u64) } } #[inline] pub fn set_m_bitfield(&mut self, val: ::std::os::raw::c_ulong) { @@ -128,9 +115,7 @@ impl Foo { } #[inline] pub fn m_bar(&self) -> ::std::os::raw::c_ulong { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(64usize, 64u8) as u64) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(64usize, 64u8) as u64) } } #[inline] pub fn set_m_bar(&mut self, val: ::std::os::raw::c_ulong) { @@ -141,9 +126,7 @@ impl Foo { } #[inline] pub fn foo(&self) -> ::std::os::raw::c_ulong { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(128usize, 1u8) as u64) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(128usize, 1u8) as u64) } } #[inline] pub fn set_foo(&mut self, val: ::std::os::raw::c_ulong) { @@ -154,9 +137,7 @@ impl Foo { } #[inline] pub fn bar(&self) -> ::std::os::raw::c_ulong { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(192usize, 64u8) as u64) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(192usize, 64u8) as u64) } } #[inline] pub fn set_bar(&mut self, val: ::std::os::raw::c_ulong) { @@ -172,24 +153,43 @@ impl Foo { foo: ::std::os::raw::c_ulong, bar: ::std::os::raw::c_ulong, ) -> __BindgenBitfieldUnit<[u8; 32usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 32usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 64u8, { - let m_bitfield: u64 = unsafe { ::std::mem::transmute(m_bitfield) }; - m_bitfield as u64 - }); - __bindgen_bitfield_unit.set(64usize, 64u8, { - let m_bar: u64 = unsafe { ::std::mem::transmute(m_bar) }; - m_bar as u64 - }); - __bindgen_bitfield_unit.set(128usize, 1u8, { - let foo: u64 = unsafe { ::std::mem::transmute(foo) }; - foo as u64 - }); - __bindgen_bitfield_unit.set(192usize, 64u8, { - let bar: u64 = unsafe { ::std::mem::transmute(bar) }; - bar as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 32usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 64u8, + { + let m_bitfield: u64 = unsafe { ::std::mem::transmute(m_bitfield) }; + m_bitfield as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 64usize, + 64u8, + { + let m_bar: u64 = unsafe { ::std::mem::transmute(m_bar) }; + m_bar as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 128usize, + 1u8, + { + let foo: u64 = unsafe { ::std::mem::transmute(foo) }; + foo as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 192usize, + 64u8, + { + let bar: u64 = unsafe { ::std::mem::transmute(bar) }; + bar as u64 + }, + ); __bindgen_bitfield_unit } } diff --git a/bindgen-tests/tests/expectations/tests/issue-801-opaque-sloppiness.rs b/bindgen-tests/tests/expectations/tests/issue-801-opaque-sloppiness.rs index b3192b7243..2883552895 100644 --- a/bindgen-tests/tests/expectations/tests/issue-801-opaque-sloppiness.rs +++ b/bindgen-tests/tests/expectations/tests/issue-801-opaque-sloppiness.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct A { @@ -19,14 +13,10 @@ pub struct B { #[test] fn bindgen_test_layout_B() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(B)) + ::std::mem::size_of:: < B > (), 1usize, concat!("Size of: ", stringify!(B)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(B)) + ::std::mem::align_of:: < B > (), 1usize, concat!("Alignment of ", stringify!(B)) ); } extern "C" { @@ -40,22 +30,16 @@ pub struct C { } #[test] fn bindgen_test_layout_C() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(C)) + ::std::mem::size_of:: < C > (), 1usize, concat!("Size of: ", stringify!(C)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(C)) + ::std::mem::align_of:: < C > (), 1usize, concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(b)) ); } diff --git a/bindgen-tests/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs b/bindgen-tests/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs index f886952822..f5c4852d23 100644 --- a/bindgen-tests/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs +++ b/bindgen-tests/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct Pupper { @@ -13,14 +7,12 @@ pub struct Pupper { #[test] fn bindgen_test_layout_Pupper() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Pupper)) + ::std::mem::size_of:: < Pupper > (), 1usize, concat!("Size of: ", + stringify!(Pupper)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Pupper)) + ::std::mem::align_of:: < Pupper > (), 1usize, concat!("Alignment of ", + stringify!(Pupper)) ); } #[repr(C)] @@ -31,14 +23,12 @@ pub struct Doggo { #[test] fn bindgen_test_layout_Doggo() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Doggo)) + ::std::mem::size_of:: < Doggo > (), 1usize, concat!("Size of: ", + stringify!(Doggo)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Doggo)) + ::std::mem::align_of:: < Doggo > (), 1usize, concat!("Alignment of ", + stringify!(Doggo)) ); } #[repr(C)] @@ -49,14 +39,12 @@ pub struct SuchWow { #[test] fn bindgen_test_layout_SuchWow() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(SuchWow)) + ::std::mem::size_of:: < SuchWow > (), 1usize, concat!("Size of: ", + stringify!(SuchWow)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(SuchWow)) + ::std::mem::align_of:: < SuchWow > (), 1usize, concat!("Alignment of ", + stringify!(SuchWow)) ); } #[repr(C)] @@ -68,14 +56,12 @@ pub struct Opaque { #[test] fn bindgen_test_layout_Opaque() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Opaque)) + ::std::mem::size_of:: < Opaque > (), 1usize, concat!("Size of: ", + stringify!(Opaque)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Opaque)) + ::std::mem::align_of:: < Opaque > (), 1usize, concat!("Alignment of ", + stringify!(Opaque)) ); } extern "C" { @@ -109,29 +95,19 @@ pub struct Allowlisted { } #[test] fn bindgen_test_layout_Allowlisted() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Allowlisted)) + ::std::mem::size_of:: < Allowlisted > (), 1usize, concat!("Size of: ", + stringify!(Allowlisted)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Allowlisted)) + ::std::mem::align_of:: < Allowlisted > (), 1usize, concat!("Alignment of ", + stringify!(Allowlisted)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).some_member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Allowlisted), - "::", - stringify!(some_member) - ) + unsafe { ::std::ptr::addr_of!((* ptr).some_member) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(Allowlisted), "::", + stringify!(some_member)) ); } diff --git a/bindgen-tests/tests/expectations/tests/issue-816.rs b/bindgen-tests/tests/expectations/tests/issue-816.rs index c7f94106f4..ac4c275070 100644 --- a/bindgen-tests/tests/expectations/tests/issue-816.rs +++ b/bindgen-tests/tests/expectations/tests/issue-816.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -101,22 +93,18 @@ pub struct capabilities { #[test] fn bindgen_test_layout_capabilities() { assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(capabilities)) + ::std::mem::size_of:: < capabilities > (), 16usize, concat!("Size of: ", + stringify!(capabilities)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(capabilities)) + ::std::mem::align_of:: < capabilities > (), 4usize, concat!("Alignment of ", + stringify!(capabilities)) ); } impl capabilities { #[inline] pub fn bit_1(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u32) } } #[inline] pub fn set_bit_1(&mut self, val: ::std::os::raw::c_uint) { @@ -127,9 +115,7 @@ impl capabilities { } #[inline] pub fn bit_2(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u32) } } #[inline] pub fn set_bit_2(&mut self, val: ::std::os::raw::c_uint) { @@ -140,9 +126,7 @@ impl capabilities { } #[inline] pub fn bit_3(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u32) } } #[inline] pub fn set_bit_3(&mut self, val: ::std::os::raw::c_uint) { @@ -153,9 +137,7 @@ impl capabilities { } #[inline] pub fn bit_4(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(3usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(3usize, 1u8) as u32) } } #[inline] pub fn set_bit_4(&mut self, val: ::std::os::raw::c_uint) { @@ -166,9 +148,7 @@ impl capabilities { } #[inline] pub fn bit_5(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(4usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(4usize, 1u8) as u32) } } #[inline] pub fn set_bit_5(&mut self, val: ::std::os::raw::c_uint) { @@ -179,9 +159,7 @@ impl capabilities { } #[inline] pub fn bit_6(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(5usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(5usize, 1u8) as u32) } } #[inline] pub fn set_bit_6(&mut self, val: ::std::os::raw::c_uint) { @@ -192,9 +170,7 @@ impl capabilities { } #[inline] pub fn bit_7(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(6usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(6usize, 1u8) as u32) } } #[inline] pub fn set_bit_7(&mut self, val: ::std::os::raw::c_uint) { @@ -205,9 +181,7 @@ impl capabilities { } #[inline] pub fn bit_8(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(7usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(7usize, 1u8) as u32) } } #[inline] pub fn set_bit_8(&mut self, val: ::std::os::raw::c_uint) { @@ -218,9 +192,7 @@ impl capabilities { } #[inline] pub fn bit_9(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(8usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(8usize, 1u8) as u32) } } #[inline] pub fn set_bit_9(&mut self, val: ::std::os::raw::c_uint) { @@ -231,9 +203,7 @@ impl capabilities { } #[inline] pub fn bit_10(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(9usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(9usize, 1u8) as u32) } } #[inline] pub fn set_bit_10(&mut self, val: ::std::os::raw::c_uint) { @@ -244,9 +214,7 @@ impl capabilities { } #[inline] pub fn bit_11(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(10usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(10usize, 1u8) as u32) } } #[inline] pub fn set_bit_11(&mut self, val: ::std::os::raw::c_uint) { @@ -257,9 +225,7 @@ impl capabilities { } #[inline] pub fn bit_12(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(11usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(11usize, 1u8) as u32) } } #[inline] pub fn set_bit_12(&mut self, val: ::std::os::raw::c_uint) { @@ -270,9 +236,7 @@ impl capabilities { } #[inline] pub fn bit_13(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(12usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(12usize, 1u8) as u32) } } #[inline] pub fn set_bit_13(&mut self, val: ::std::os::raw::c_uint) { @@ -283,9 +247,7 @@ impl capabilities { } #[inline] pub fn bit_14(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(13usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(13usize, 1u8) as u32) } } #[inline] pub fn set_bit_14(&mut self, val: ::std::os::raw::c_uint) { @@ -296,9 +258,7 @@ impl capabilities { } #[inline] pub fn bit_15(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(14usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(14usize, 1u8) as u32) } } #[inline] pub fn set_bit_15(&mut self, val: ::std::os::raw::c_uint) { @@ -309,9 +269,7 @@ impl capabilities { } #[inline] pub fn bit_16(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(15usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(15usize, 1u8) as u32) } } #[inline] pub fn set_bit_16(&mut self, val: ::std::os::raw::c_uint) { @@ -322,9 +280,7 @@ impl capabilities { } #[inline] pub fn bit_17(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(16usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(16usize, 1u8) as u32) } } #[inline] pub fn set_bit_17(&mut self, val: ::std::os::raw::c_uint) { @@ -335,9 +291,7 @@ impl capabilities { } #[inline] pub fn bit_18(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(17usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(17usize, 1u8) as u32) } } #[inline] pub fn set_bit_18(&mut self, val: ::std::os::raw::c_uint) { @@ -348,9 +302,7 @@ impl capabilities { } #[inline] pub fn bit_19(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(18usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(18usize, 1u8) as u32) } } #[inline] pub fn set_bit_19(&mut self, val: ::std::os::raw::c_uint) { @@ -361,9 +313,7 @@ impl capabilities { } #[inline] pub fn bit_20(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(19usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(19usize, 1u8) as u32) } } #[inline] pub fn set_bit_20(&mut self, val: ::std::os::raw::c_uint) { @@ -374,9 +324,7 @@ impl capabilities { } #[inline] pub fn bit_21(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(20usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(20usize, 1u8) as u32) } } #[inline] pub fn set_bit_21(&mut self, val: ::std::os::raw::c_uint) { @@ -387,9 +335,7 @@ impl capabilities { } #[inline] pub fn bit_22(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(21usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(21usize, 1u8) as u32) } } #[inline] pub fn set_bit_22(&mut self, val: ::std::os::raw::c_uint) { @@ -400,9 +346,7 @@ impl capabilities { } #[inline] pub fn bit_23(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(22usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(22usize, 1u8) as u32) } } #[inline] pub fn set_bit_23(&mut self, val: ::std::os::raw::c_uint) { @@ -413,9 +357,7 @@ impl capabilities { } #[inline] pub fn bit_24(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(23usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(23usize, 1u8) as u32) } } #[inline] pub fn set_bit_24(&mut self, val: ::std::os::raw::c_uint) { @@ -426,9 +368,7 @@ impl capabilities { } #[inline] pub fn bit_25(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(24usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(24usize, 1u8) as u32) } } #[inline] pub fn set_bit_25(&mut self, val: ::std::os::raw::c_uint) { @@ -439,9 +379,7 @@ impl capabilities { } #[inline] pub fn bit_26(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(25usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(25usize, 1u8) as u32) } } #[inline] pub fn set_bit_26(&mut self, val: ::std::os::raw::c_uint) { @@ -452,9 +390,7 @@ impl capabilities { } #[inline] pub fn bit_27(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(26usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(26usize, 1u8) as u32) } } #[inline] pub fn set_bit_27(&mut self, val: ::std::os::raw::c_uint) { @@ -465,9 +401,7 @@ impl capabilities { } #[inline] pub fn bit_28(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(27usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(27usize, 1u8) as u32) } } #[inline] pub fn set_bit_28(&mut self, val: ::std::os::raw::c_uint) { @@ -478,9 +412,7 @@ impl capabilities { } #[inline] pub fn bit_29(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(28usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(28usize, 1u8) as u32) } } #[inline] pub fn set_bit_29(&mut self, val: ::std::os::raw::c_uint) { @@ -491,9 +423,7 @@ impl capabilities { } #[inline] pub fn bit_30(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(29usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(29usize, 1u8) as u32) } } #[inline] pub fn set_bit_30(&mut self, val: ::std::os::raw::c_uint) { @@ -504,9 +434,7 @@ impl capabilities { } #[inline] pub fn bit_31(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(30usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(30usize, 1u8) as u32) } } #[inline] pub fn set_bit_31(&mut self, val: ::std::os::raw::c_uint) { @@ -517,9 +445,7 @@ impl capabilities { } #[inline] pub fn bit_32(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(31usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(31usize, 1u8) as u32) } } #[inline] pub fn set_bit_32(&mut self, val: ::std::os::raw::c_uint) { @@ -530,9 +456,7 @@ impl capabilities { } #[inline] pub fn bit_33(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(32usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(32usize, 1u8) as u32) } } #[inline] pub fn set_bit_33(&mut self, val: ::std::os::raw::c_uint) { @@ -543,9 +467,7 @@ impl capabilities { } #[inline] pub fn bit_34(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(33usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(33usize, 1u8) as u32) } } #[inline] pub fn set_bit_34(&mut self, val: ::std::os::raw::c_uint) { @@ -556,9 +478,7 @@ impl capabilities { } #[inline] pub fn bit_35(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(34usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(34usize, 1u8) as u32) } } #[inline] pub fn set_bit_35(&mut self, val: ::std::os::raw::c_uint) { @@ -569,9 +489,7 @@ impl capabilities { } #[inline] pub fn bit_36(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(35usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(35usize, 1u8) as u32) } } #[inline] pub fn set_bit_36(&mut self, val: ::std::os::raw::c_uint) { @@ -582,9 +500,7 @@ impl capabilities { } #[inline] pub fn bit_37(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(36usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(36usize, 1u8) as u32) } } #[inline] pub fn set_bit_37(&mut self, val: ::std::os::raw::c_uint) { @@ -595,9 +511,7 @@ impl capabilities { } #[inline] pub fn bit_38(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(37usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(37usize, 1u8) as u32) } } #[inline] pub fn set_bit_38(&mut self, val: ::std::os::raw::c_uint) { @@ -608,9 +522,7 @@ impl capabilities { } #[inline] pub fn bit_39(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(38usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(38usize, 1u8) as u32) } } #[inline] pub fn set_bit_39(&mut self, val: ::std::os::raw::c_uint) { @@ -621,9 +533,7 @@ impl capabilities { } #[inline] pub fn bit_40(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(39usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(39usize, 1u8) as u32) } } #[inline] pub fn set_bit_40(&mut self, val: ::std::os::raw::c_uint) { @@ -634,9 +544,7 @@ impl capabilities { } #[inline] pub fn bit_41(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(40usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(40usize, 1u8) as u32) } } #[inline] pub fn set_bit_41(&mut self, val: ::std::os::raw::c_uint) { @@ -689,172 +597,376 @@ impl capabilities { bit_40: ::std::os::raw::c_uint, bit_41: ::std::os::raw::c_uint, ) -> __BindgenBitfieldUnit<[u8; 16usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 16usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 1u8, { - let bit_1: u32 = unsafe { ::std::mem::transmute(bit_1) }; - bit_1 as u64 - }); - __bindgen_bitfield_unit.set(1usize, 1u8, { - let bit_2: u32 = unsafe { ::std::mem::transmute(bit_2) }; - bit_2 as u64 - }); - __bindgen_bitfield_unit.set(2usize, 1u8, { - let bit_3: u32 = unsafe { ::std::mem::transmute(bit_3) }; - bit_3 as u64 - }); - __bindgen_bitfield_unit.set(3usize, 1u8, { - let bit_4: u32 = unsafe { ::std::mem::transmute(bit_4) }; - bit_4 as u64 - }); - __bindgen_bitfield_unit.set(4usize, 1u8, { - let bit_5: u32 = unsafe { ::std::mem::transmute(bit_5) }; - bit_5 as u64 - }); - __bindgen_bitfield_unit.set(5usize, 1u8, { - let bit_6: u32 = unsafe { ::std::mem::transmute(bit_6) }; - bit_6 as u64 - }); - __bindgen_bitfield_unit.set(6usize, 1u8, { - let bit_7: u32 = unsafe { ::std::mem::transmute(bit_7) }; - bit_7 as u64 - }); - __bindgen_bitfield_unit.set(7usize, 1u8, { - let bit_8: u32 = unsafe { ::std::mem::transmute(bit_8) }; - bit_8 as u64 - }); - __bindgen_bitfield_unit.set(8usize, 1u8, { - let bit_9: u32 = unsafe { ::std::mem::transmute(bit_9) }; - bit_9 as u64 - }); - __bindgen_bitfield_unit.set(9usize, 1u8, { - let bit_10: u32 = unsafe { ::std::mem::transmute(bit_10) }; - bit_10 as u64 - }); - __bindgen_bitfield_unit.set(10usize, 1u8, { - let bit_11: u32 = unsafe { ::std::mem::transmute(bit_11) }; - bit_11 as u64 - }); - __bindgen_bitfield_unit.set(11usize, 1u8, { - let bit_12: u32 = unsafe { ::std::mem::transmute(bit_12) }; - bit_12 as u64 - }); - __bindgen_bitfield_unit.set(12usize, 1u8, { - let bit_13: u32 = unsafe { ::std::mem::transmute(bit_13) }; - bit_13 as u64 - }); - __bindgen_bitfield_unit.set(13usize, 1u8, { - let bit_14: u32 = unsafe { ::std::mem::transmute(bit_14) }; - bit_14 as u64 - }); - __bindgen_bitfield_unit.set(14usize, 1u8, { - let bit_15: u32 = unsafe { ::std::mem::transmute(bit_15) }; - bit_15 as u64 - }); - __bindgen_bitfield_unit.set(15usize, 1u8, { - let bit_16: u32 = unsafe { ::std::mem::transmute(bit_16) }; - bit_16 as u64 - }); - __bindgen_bitfield_unit.set(16usize, 1u8, { - let bit_17: u32 = unsafe { ::std::mem::transmute(bit_17) }; - bit_17 as u64 - }); - __bindgen_bitfield_unit.set(17usize, 1u8, { - let bit_18: u32 = unsafe { ::std::mem::transmute(bit_18) }; - bit_18 as u64 - }); - __bindgen_bitfield_unit.set(18usize, 1u8, { - let bit_19: u32 = unsafe { ::std::mem::transmute(bit_19) }; - bit_19 as u64 - }); - __bindgen_bitfield_unit.set(19usize, 1u8, { - let bit_20: u32 = unsafe { ::std::mem::transmute(bit_20) }; - bit_20 as u64 - }); - __bindgen_bitfield_unit.set(20usize, 1u8, { - let bit_21: u32 = unsafe { ::std::mem::transmute(bit_21) }; - bit_21 as u64 - }); - __bindgen_bitfield_unit.set(21usize, 1u8, { - let bit_22: u32 = unsafe { ::std::mem::transmute(bit_22) }; - bit_22 as u64 - }); - __bindgen_bitfield_unit.set(22usize, 1u8, { - let bit_23: u32 = unsafe { ::std::mem::transmute(bit_23) }; - bit_23 as u64 - }); - __bindgen_bitfield_unit.set(23usize, 1u8, { - let bit_24: u32 = unsafe { ::std::mem::transmute(bit_24) }; - bit_24 as u64 - }); - __bindgen_bitfield_unit.set(24usize, 1u8, { - let bit_25: u32 = unsafe { ::std::mem::transmute(bit_25) }; - bit_25 as u64 - }); - __bindgen_bitfield_unit.set(25usize, 1u8, { - let bit_26: u32 = unsafe { ::std::mem::transmute(bit_26) }; - bit_26 as u64 - }); - __bindgen_bitfield_unit.set(26usize, 1u8, { - let bit_27: u32 = unsafe { ::std::mem::transmute(bit_27) }; - bit_27 as u64 - }); - __bindgen_bitfield_unit.set(27usize, 1u8, { - let bit_28: u32 = unsafe { ::std::mem::transmute(bit_28) }; - bit_28 as u64 - }); - __bindgen_bitfield_unit.set(28usize, 1u8, { - let bit_29: u32 = unsafe { ::std::mem::transmute(bit_29) }; - bit_29 as u64 - }); - __bindgen_bitfield_unit.set(29usize, 1u8, { - let bit_30: u32 = unsafe { ::std::mem::transmute(bit_30) }; - bit_30 as u64 - }); - __bindgen_bitfield_unit.set(30usize, 1u8, { - let bit_31: u32 = unsafe { ::std::mem::transmute(bit_31) }; - bit_31 as u64 - }); - __bindgen_bitfield_unit.set(31usize, 1u8, { - let bit_32: u32 = unsafe { ::std::mem::transmute(bit_32) }; - bit_32 as u64 - }); - __bindgen_bitfield_unit.set(32usize, 1u8, { - let bit_33: u32 = unsafe { ::std::mem::transmute(bit_33) }; - bit_33 as u64 - }); - __bindgen_bitfield_unit.set(33usize, 1u8, { - let bit_34: u32 = unsafe { ::std::mem::transmute(bit_34) }; - bit_34 as u64 - }); - __bindgen_bitfield_unit.set(34usize, 1u8, { - let bit_35: u32 = unsafe { ::std::mem::transmute(bit_35) }; - bit_35 as u64 - }); - __bindgen_bitfield_unit.set(35usize, 1u8, { - let bit_36: u32 = unsafe { ::std::mem::transmute(bit_36) }; - bit_36 as u64 - }); - __bindgen_bitfield_unit.set(36usize, 1u8, { - let bit_37: u32 = unsafe { ::std::mem::transmute(bit_37) }; - bit_37 as u64 - }); - __bindgen_bitfield_unit.set(37usize, 1u8, { - let bit_38: u32 = unsafe { ::std::mem::transmute(bit_38) }; - bit_38 as u64 - }); - __bindgen_bitfield_unit.set(38usize, 1u8, { - let bit_39: u32 = unsafe { ::std::mem::transmute(bit_39) }; - bit_39 as u64 - }); - __bindgen_bitfield_unit.set(39usize, 1u8, { - let bit_40: u32 = unsafe { ::std::mem::transmute(bit_40) }; - bit_40 as u64 - }); - __bindgen_bitfield_unit.set(40usize, 1u8, { - let bit_41: u32 = unsafe { ::std::mem::transmute(bit_41) }; - bit_41 as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 16usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let bit_1: u32 = unsafe { ::std::mem::transmute(bit_1) }; + bit_1 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 1usize, + 1u8, + { + let bit_2: u32 = unsafe { ::std::mem::transmute(bit_2) }; + bit_2 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 2usize, + 1u8, + { + let bit_3: u32 = unsafe { ::std::mem::transmute(bit_3) }; + bit_3 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 3usize, + 1u8, + { + let bit_4: u32 = unsafe { ::std::mem::transmute(bit_4) }; + bit_4 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 4usize, + 1u8, + { + let bit_5: u32 = unsafe { ::std::mem::transmute(bit_5) }; + bit_5 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 5usize, + 1u8, + { + let bit_6: u32 = unsafe { ::std::mem::transmute(bit_6) }; + bit_6 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 6usize, + 1u8, + { + let bit_7: u32 = unsafe { ::std::mem::transmute(bit_7) }; + bit_7 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 7usize, + 1u8, + { + let bit_8: u32 = unsafe { ::std::mem::transmute(bit_8) }; + bit_8 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 8usize, + 1u8, + { + let bit_9: u32 = unsafe { ::std::mem::transmute(bit_9) }; + bit_9 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 9usize, + 1u8, + { + let bit_10: u32 = unsafe { ::std::mem::transmute(bit_10) }; + bit_10 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 10usize, + 1u8, + { + let bit_11: u32 = unsafe { ::std::mem::transmute(bit_11) }; + bit_11 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 11usize, + 1u8, + { + let bit_12: u32 = unsafe { ::std::mem::transmute(bit_12) }; + bit_12 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 12usize, + 1u8, + { + let bit_13: u32 = unsafe { ::std::mem::transmute(bit_13) }; + bit_13 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 13usize, + 1u8, + { + let bit_14: u32 = unsafe { ::std::mem::transmute(bit_14) }; + bit_14 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 14usize, + 1u8, + { + let bit_15: u32 = unsafe { ::std::mem::transmute(bit_15) }; + bit_15 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 15usize, + 1u8, + { + let bit_16: u32 = unsafe { ::std::mem::transmute(bit_16) }; + bit_16 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 16usize, + 1u8, + { + let bit_17: u32 = unsafe { ::std::mem::transmute(bit_17) }; + bit_17 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 17usize, + 1u8, + { + let bit_18: u32 = unsafe { ::std::mem::transmute(bit_18) }; + bit_18 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 18usize, + 1u8, + { + let bit_19: u32 = unsafe { ::std::mem::transmute(bit_19) }; + bit_19 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 19usize, + 1u8, + { + let bit_20: u32 = unsafe { ::std::mem::transmute(bit_20) }; + bit_20 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 20usize, + 1u8, + { + let bit_21: u32 = unsafe { ::std::mem::transmute(bit_21) }; + bit_21 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 21usize, + 1u8, + { + let bit_22: u32 = unsafe { ::std::mem::transmute(bit_22) }; + bit_22 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 22usize, + 1u8, + { + let bit_23: u32 = unsafe { ::std::mem::transmute(bit_23) }; + bit_23 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 23usize, + 1u8, + { + let bit_24: u32 = unsafe { ::std::mem::transmute(bit_24) }; + bit_24 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 24usize, + 1u8, + { + let bit_25: u32 = unsafe { ::std::mem::transmute(bit_25) }; + bit_25 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 25usize, + 1u8, + { + let bit_26: u32 = unsafe { ::std::mem::transmute(bit_26) }; + bit_26 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 26usize, + 1u8, + { + let bit_27: u32 = unsafe { ::std::mem::transmute(bit_27) }; + bit_27 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 27usize, + 1u8, + { + let bit_28: u32 = unsafe { ::std::mem::transmute(bit_28) }; + bit_28 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 28usize, + 1u8, + { + let bit_29: u32 = unsafe { ::std::mem::transmute(bit_29) }; + bit_29 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 29usize, + 1u8, + { + let bit_30: u32 = unsafe { ::std::mem::transmute(bit_30) }; + bit_30 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 30usize, + 1u8, + { + let bit_31: u32 = unsafe { ::std::mem::transmute(bit_31) }; + bit_31 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 31usize, + 1u8, + { + let bit_32: u32 = unsafe { ::std::mem::transmute(bit_32) }; + bit_32 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 32usize, + 1u8, + { + let bit_33: u32 = unsafe { ::std::mem::transmute(bit_33) }; + bit_33 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 33usize, + 1u8, + { + let bit_34: u32 = unsafe { ::std::mem::transmute(bit_34) }; + bit_34 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 34usize, + 1u8, + { + let bit_35: u32 = unsafe { ::std::mem::transmute(bit_35) }; + bit_35 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 35usize, + 1u8, + { + let bit_36: u32 = unsafe { ::std::mem::transmute(bit_36) }; + bit_36 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 36usize, + 1u8, + { + let bit_37: u32 = unsafe { ::std::mem::transmute(bit_37) }; + bit_37 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 37usize, + 1u8, + { + let bit_38: u32 = unsafe { ::std::mem::transmute(bit_38) }; + bit_38 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 38usize, + 1u8, + { + let bit_39: u32 = unsafe { ::std::mem::transmute(bit_39) }; + bit_39 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 39usize, + 1u8, + { + let bit_40: u32 = unsafe { ::std::mem::transmute(bit_40) }; + bit_40 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 40usize, + 1u8, + { + let bit_41: u32 = unsafe { ::std::mem::transmute(bit_41) }; + bit_41 as u64 + }, + ); __bindgen_bitfield_unit } } diff --git a/bindgen-tests/tests/expectations/tests/issue-820-unused-template-param-in-alias.rs b/bindgen-tests/tests/expectations/tests/issue-820-unused-template-param-in-alias.rs index cfe0078455..a367e2e0e1 100644 --- a/bindgen-tests/tests/expectations/tests/issue-820-unused-template-param-in-alias.rs +++ b/bindgen-tests/tests/expectations/tests/issue-820-unused-template-param-in-alias.rs @@ -1,8 +1,2 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type Foo_self_type = u8; diff --git a/bindgen-tests/tests/expectations/tests/issue-826-generating-methods-when-asked-not-to.rs b/bindgen-tests/tests/expectations/tests/issue-826-generating-methods-when-asked-not-to.rs index f5ba025a25..d16596b591 100644 --- a/bindgen-tests/tests/expectations/tests/issue-826-generating-methods-when-asked-not-to.rs +++ b/bindgen-tests/tests/expectations/tests/issue-826-generating-methods-when-asked-not-to.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { @@ -13,13 +7,10 @@ pub struct Foo { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) + ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", + stringify!(Foo)) ); } diff --git a/bindgen-tests/tests/expectations/tests/issue-833-1.rs b/bindgen-tests/tests/expectations/tests/issue-833-1.rs index f91266f634..b86a4e0df3 100644 --- a/bindgen-tests/tests/expectations/tests/issue-833-1.rs +++ b/bindgen-tests/tests/expectations/tests/issue-833-1.rs @@ -1,15 +1,8 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct nsTArray { pub hdr: *const (), } - extern "C" { pub fn func() -> *mut nsTArray; } diff --git a/bindgen-tests/tests/expectations/tests/issue-833-2.rs b/bindgen-tests/tests/expectations/tests/issue-833-2.rs index 1dfe1abda6..b8ef2f8554 100644 --- a/bindgen-tests/tests/expectations/tests/issue-833-2.rs +++ b/bindgen-tests/tests/expectations/tests/issue-833-2.rs @@ -1,12 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -// If the output of this changes, please ensure issue-833-1.hpp changes too - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct nsTArray { diff --git a/bindgen-tests/tests/expectations/tests/issue-833.rs b/bindgen-tests/tests/expectations/tests/issue-833.rs index a092fb7156..2a2d375e89 100644 --- a/bindgen-tests/tests/expectations/tests/issue-833.rs +++ b/bindgen-tests/tests/expectations/tests/issue-833.rs @@ -1,15 +1,8 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct nsTArray { pub hdr: *const T, } - extern "C" { pub fn func() -> *mut nsTArray<::std::os::raw::c_int>; } diff --git a/bindgen-tests/tests/expectations/tests/issue-834.rs b/bindgen-tests/tests/expectations/tests/issue-834.rs index 465341fb71..46ae37b5e5 100644 --- a/bindgen-tests/tests/expectations/tests/issue-834.rs +++ b/bindgen-tests/tests/expectations/tests/issue-834.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct U { @@ -13,13 +7,9 @@ pub struct U { #[test] fn bindgen_test_layout_U() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(U)) + ::std::mem::size_of:: < U > (), 1usize, concat!("Size of: ", stringify!(U)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(U)) + ::std::mem::align_of:: < U > (), 1usize, concat!("Alignment of ", stringify!(U)) ); } diff --git a/bindgen-tests/tests/expectations/tests/issue-848-replacement-system-include.rs b/bindgen-tests/tests/expectations/tests/issue-848-replacement-system-include.rs index 294df575da..d9d4fd9abc 100644 --- a/bindgen-tests/tests/expectations/tests/issue-848-replacement-system-include.rs +++ b/bindgen-tests/tests/expectations/tests/issue-848-replacement-system-include.rs @@ -1,16 +1,10 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +/** This is intended to replace another type, but won't if we treat this include + as a system include, because clang doesn't parse comments there. -/// This is intended to replace another type, but won't if we treat this include -/// as a system include, because clang doesn't parse comments there. -/// -/// See #848. -/// -///
+ See #848. + +
*/ #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct nsTArray { diff --git a/bindgen-tests/tests/expectations/tests/issue-888-enum-var-decl-jump.rs b/bindgen-tests/tests/expectations/tests/issue-888-enum-var-decl-jump.rs index 6ac308a74f..317a73ab16 100644 --- a/bindgen-tests/tests/expectations/tests/issue-888-enum-var-decl-jump.rs +++ b/bindgen-tests/tests/expectations/tests/issue-888-enum-var-decl-jump.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![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 { #[allow(unused_imports)] @@ -24,14 +18,12 @@ pub mod root { #[test] fn bindgen_test_layout_Type() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Type)) + ::std::mem::size_of:: < Type > (), 1usize, concat!("Size of: ", + stringify!(Type)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Type)) + ::std::mem::align_of:: < Type > (), 1usize, concat!("Alignment of ", + stringify!(Type)) ); } } diff --git a/bindgen-tests/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs b/bindgen-tests/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs index d9c365d828..60b8dddc09 100644 --- a/bindgen-tests/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs +++ b/bindgen-tests/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs @@ -1,12 +1,5 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub struct BlocklistMe(u8); - /// Because this type contains a blocklisted type, it should not derive Copy. #[repr(C)] pub struct ShouldNotBeCopy { @@ -14,28 +7,19 @@ pub struct ShouldNotBeCopy { } #[test] fn bindgen_test_layout_ShouldNotBeCopy() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(ShouldNotBeCopy)) + ::std::mem::size_of:: < ShouldNotBeCopy > (), 1usize, concat!("Size of: ", + stringify!(ShouldNotBeCopy)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(ShouldNotBeCopy)) + ::std::mem::align_of:: < ShouldNotBeCopy > (), 1usize, concat!("Alignment of ", + stringify!(ShouldNotBeCopy)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldNotBeCopy), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(ShouldNotBeCopy), "::", stringify!(a)) ); } impl Default for ShouldNotBeCopy { diff --git a/bindgen-tests/tests/expectations/tests/issue-946.rs b/bindgen-tests/tests/expectations/tests/issue-946.rs index 897700b325..9cd65e4aae 100644 --- a/bindgen-tests/tests/expectations/tests/issue-946.rs +++ b/bindgen-tests/tests/expectations/tests/issue-946.rs @@ -1,24 +1,15 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct foo {} #[test] fn bindgen_test_layout_foo() { assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of:: < foo > (), 0usize, concat!("Size of: ", stringify!(foo)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(foo)) + ::std::mem::align_of:: < foo > (), 1usize, concat!("Alignment of ", + stringify!(foo)) ); } pub type bar = foo; diff --git a/bindgen-tests/tests/expectations/tests/issue_311.rs b/bindgen-tests/tests/expectations/tests/issue_311.rs index 49e30d8407..f0cc889c9a 100644 --- a/bindgen-tests/tests/expectations/tests/issue_311.rs +++ b/bindgen-tests/tests/expectations/tests/issue_311.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![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 { #[allow(unused_imports)] @@ -22,27 +16,23 @@ pub mod root { #[test] fn bindgen_test_layout_jsval_layout__bindgen_ty_1() { assert_eq!( - ::std::mem::size_of::(), - 1usize, + ::std::mem::size_of:: < jsval_layout__bindgen_ty_1 > (), 1usize, concat!("Size of: ", stringify!(jsval_layout__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < jsval_layout__bindgen_ty_1 > (), 1usize, concat!("Alignment of ", stringify!(jsval_layout__bindgen_ty_1)) ); } #[test] fn bindgen_test_layout_jsval_layout() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(jsval_layout)) + ::std::mem::size_of:: < jsval_layout > (), 1usize, concat!("Size of: ", + stringify!(jsval_layout)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(jsval_layout)) + ::std::mem::align_of:: < jsval_layout > (), 1usize, concat!("Alignment of ", + stringify!(jsval_layout)) ); } } diff --git a/bindgen-tests/tests/expectations/tests/issue_315.rs b/bindgen-tests/tests/expectations/tests/issue_315.rs index 71ae1f2746..cecdccc2aa 100644 --- a/bindgen-tests/tests/expectations/tests/issue_315.rs +++ b/bindgen-tests/tests/expectations/tests/issue_315.rs @@ -1,9 +1,3 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] ///
pub type c
= a; diff --git a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs index a812e90560..cfbf2f61cc 100644 --- a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs +++ b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -198,13 +190,11 @@ pub struct jsval_layout__bindgen_ty_1 { #[test] fn bindgen_test_layout_jsval_layout__bindgen_ty_1() { assert_eq!( - ::std::mem::size_of::(), - 8usize, + ::std::mem::size_of:: < jsval_layout__bindgen_ty_1 > (), 8usize, concat!("Size of: ", stringify!(jsval_layout__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, + ::std::mem::align_of:: < jsval_layout__bindgen_ty_1 > (), 8usize, concat!("Alignment of ", stringify!(jsval_layout__bindgen_ty_1)) ); } @@ -220,9 +210,7 @@ impl Default for jsval_layout__bindgen_ty_1 { impl jsval_layout__bindgen_ty_1 { #[inline] pub fn payload47(&self) -> u64 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 47u8) as u64) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 47u8) as u64) } } #[inline] pub fn set_payload47(&mut self, val: u64) { @@ -233,9 +221,7 @@ impl jsval_layout__bindgen_ty_1 { } #[inline] pub fn tag(&self) -> JSValueTag { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(47usize, 17u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(47usize, 17u8) as u32) } } #[inline] pub fn set_tag(&mut self, val: JSValueTag) { @@ -249,16 +235,25 @@ impl jsval_layout__bindgen_ty_1 { payload47: u64, tag: JSValueTag, ) -> __BindgenBitfieldUnit<[u8; 8usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 8usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 47u8, { - let payload47: u64 = unsafe { ::std::mem::transmute(payload47) }; - payload47 as u64 - }); - __bindgen_bitfield_unit.set(47usize, 17u8, { - let tag: u32 = unsafe { ::std::mem::transmute(tag) }; - tag as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 8usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 47u8, + { + let payload47: u64 = unsafe { ::std::mem::transmute(payload47) }; + payload47 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 47usize, + 17u8, + { + let tag: u32 = unsafe { ::std::mem::transmute(tag) }; + tag as u64 + }, + ); __bindgen_bitfield_unit } } @@ -276,55 +271,30 @@ pub union jsval_layout__bindgen_ty_2__bindgen_ty_1 { } #[test] fn bindgen_test_layout_jsval_layout__bindgen_ty_2__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit< - jsval_layout__bindgen_ty_2__bindgen_ty_1, - > = ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!( - "Size of: ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1) - ) + ::std::mem::size_of:: < jsval_layout__bindgen_ty_2__bindgen_ty_1 > (), 4usize, + concat!("Size of: ", stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!( - "Alignment of ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1) - ) + ::std::mem::align_of:: < jsval_layout__bindgen_ty_2__bindgen_ty_1 > (), 4usize, + concat!("Alignment of ", stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i32_) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), - "::", - stringify!(i32_) - ) + unsafe { ::std::ptr::addr_of!((* ptr).i32_) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", + stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), "::", stringify!(i32_)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).u32_) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), - "::", - stringify!(u32_) - ) + unsafe { ::std::ptr::addr_of!((* ptr).u32_) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", + stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), "::", stringify!(u32_)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).why) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), - "::", - stringify!(why) - ) + unsafe { ::std::ptr::addr_of!((* ptr).why) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", + stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), "::", stringify!(why)) ); } impl Default for jsval_layout__bindgen_ty_2__bindgen_ty_1 { @@ -338,28 +308,20 @@ impl Default for jsval_layout__bindgen_ty_2__bindgen_ty_1 { } #[test] fn bindgen_test_layout_jsval_layout__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, + ::std::mem::size_of:: < jsval_layout__bindgen_ty_2 > (), 4usize, concat!("Size of: ", stringify!(jsval_layout__bindgen_ty_2)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < jsval_layout__bindgen_ty_2 > (), 4usize, concat!("Alignment of ", stringify!(jsval_layout__bindgen_ty_2)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).payload) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2), - "::", - stringify!(payload) - ) + unsafe { ::std::ptr::addr_of!((* ptr).payload) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(jsval_layout__bindgen_ty_2), "::", + stringify!(payload)) ); } impl Default for jsval_layout__bindgen_ty_2 { @@ -373,94 +335,46 @@ impl Default for jsval_layout__bindgen_ty_2 { } #[test] fn bindgen_test_layout_jsval_layout() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(jsval_layout)) + ::std::mem::size_of:: < jsval_layout > (), 8usize, concat!("Size of: ", + stringify!(jsval_layout)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(jsval_layout)) + ::std::mem::align_of:: < jsval_layout > (), 8usize, concat!("Alignment of ", + stringify!(jsval_layout)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).asBits) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asBits) - ) + unsafe { ::std::ptr::addr_of!((* ptr).asBits) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(jsval_layout), "::", stringify!(asBits)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).debugView) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(debugView) - ) + unsafe { ::std::ptr::addr_of!((* ptr).debugView) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(jsval_layout), "::", + stringify!(debugView)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).s) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(s) - ) + unsafe { ::std::ptr::addr_of!((* ptr).s) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(jsval_layout), "::", stringify!(s)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).asDouble) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asDouble) - ) + unsafe { ::std::ptr::addr_of!((* ptr).asDouble) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(jsval_layout), "::", + stringify!(asDouble)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).asPtr) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asPtr) - ) + unsafe { ::std::ptr::addr_of!((* ptr).asPtr) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(jsval_layout), "::", stringify!(asPtr)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).asWord) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asWord) - ) + unsafe { ::std::ptr::addr_of!((* ptr).asWord) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(jsval_layout), "::", stringify!(asWord)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).asUIntPtr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asUIntPtr) - ) + unsafe { ::std::ptr::addr_of!((* ptr).asUIntPtr) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(jsval_layout), "::", + stringify!(asUIntPtr)) ); } impl Default for jsval_layout { @@ -479,28 +393,19 @@ pub struct Value { } #[test] fn bindgen_test_layout_Value() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Value)) + ::std::mem::size_of:: < Value > (), 8usize, concat!("Size of: ", + stringify!(Value)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Value)) + ::std::mem::align_of:: < Value > (), 8usize, concat!("Alignment of ", + stringify!(Value)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Value), - "::", - stringify!(data) - ) + unsafe { ::std::ptr::addr_of!((* ptr).data) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(Value), "::", stringify!(data)) ); } impl Default for Value { diff --git a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs index b439499355..b97bbac96f 100644 --- a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -242,13 +234,11 @@ pub struct jsval_layout__bindgen_ty_1 { #[test] fn bindgen_test_layout_jsval_layout__bindgen_ty_1() { assert_eq!( - ::std::mem::size_of::(), - 8usize, + ::std::mem::size_of:: < jsval_layout__bindgen_ty_1 > (), 8usize, concat!("Size of: ", stringify!(jsval_layout__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, + ::std::mem::align_of:: < jsval_layout__bindgen_ty_1 > (), 8usize, concat!("Alignment of ", stringify!(jsval_layout__bindgen_ty_1)) ); } @@ -269,9 +259,7 @@ impl Default for jsval_layout__bindgen_ty_1 { impl jsval_layout__bindgen_ty_1 { #[inline] pub fn payload47(&self) -> u64 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 47u8) as u64) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 47u8) as u64) } } #[inline] pub fn set_payload47(&mut self, val: u64) { @@ -282,9 +270,7 @@ impl jsval_layout__bindgen_ty_1 { } #[inline] pub fn tag(&self) -> JSValueTag { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(47usize, 17u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(47usize, 17u8) as u32) } } #[inline] pub fn set_tag(&mut self, val: JSValueTag) { @@ -298,16 +284,25 @@ impl jsval_layout__bindgen_ty_1 { payload47: u64, tag: JSValueTag, ) -> __BindgenBitfieldUnit<[u8; 8usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 8usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 47u8, { - let payload47: u64 = unsafe { ::std::mem::transmute(payload47) }; - payload47 as u64 - }); - __bindgen_bitfield_unit.set(47usize, 17u8, { - let tag: u32 = unsafe { ::std::mem::transmute(tag) }; - tag as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 8usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 47u8, + { + let payload47: u64 = unsafe { ::std::mem::transmute(payload47) }; + payload47 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 47usize, + 17u8, + { + let tag: u32 = unsafe { ::std::mem::transmute(tag) }; + tag as u64 + }, + ); __bindgen_bitfield_unit } } @@ -326,55 +321,30 @@ pub struct jsval_layout__bindgen_ty_2__bindgen_ty_1 { } #[test] fn bindgen_test_layout_jsval_layout__bindgen_ty_2__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit< - jsval_layout__bindgen_ty_2__bindgen_ty_1, - > = ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!( - "Size of: ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1) - ) + ::std::mem::size_of:: < jsval_layout__bindgen_ty_2__bindgen_ty_1 > (), 4usize, + concat!("Size of: ", stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!( - "Alignment of ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1) - ) + ::std::mem::align_of:: < jsval_layout__bindgen_ty_2__bindgen_ty_1 > (), 4usize, + concat!("Alignment of ", stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i32_) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), - "::", - stringify!(i32_) - ) + unsafe { ::std::ptr::addr_of!((* ptr).i32_) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", + stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), "::", stringify!(i32_)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).u32_) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), - "::", - stringify!(u32_) - ) + unsafe { ::std::ptr::addr_of!((* ptr).u32_) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", + stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), "::", stringify!(u32_)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).why) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), - "::", - stringify!(why) - ) + unsafe { ::std::ptr::addr_of!((* ptr).why) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", + stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), "::", stringify!(why)) ); } impl Clone for jsval_layout__bindgen_ty_2__bindgen_ty_1 { @@ -384,28 +354,20 @@ impl Clone for jsval_layout__bindgen_ty_2__bindgen_ty_1 { } #[test] fn bindgen_test_layout_jsval_layout__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, + ::std::mem::size_of:: < jsval_layout__bindgen_ty_2 > (), 4usize, concat!("Size of: ", stringify!(jsval_layout__bindgen_ty_2)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < jsval_layout__bindgen_ty_2 > (), 4usize, concat!("Alignment of ", stringify!(jsval_layout__bindgen_ty_2)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).payload) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2), - "::", - stringify!(payload) - ) + unsafe { ::std::ptr::addr_of!((* ptr).payload) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(jsval_layout__bindgen_ty_2), "::", + stringify!(payload)) ); } impl Clone for jsval_layout__bindgen_ty_2 { @@ -415,94 +377,46 @@ impl Clone for jsval_layout__bindgen_ty_2 { } #[test] fn bindgen_test_layout_jsval_layout() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(jsval_layout)) + ::std::mem::size_of:: < jsval_layout > (), 8usize, concat!("Size of: ", + stringify!(jsval_layout)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(jsval_layout)) + ::std::mem::align_of:: < jsval_layout > (), 8usize, concat!("Alignment of ", + stringify!(jsval_layout)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).asBits) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asBits) - ) + unsafe { ::std::ptr::addr_of!((* ptr).asBits) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(jsval_layout), "::", stringify!(asBits)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).debugView) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(debugView) - ) + unsafe { ::std::ptr::addr_of!((* ptr).debugView) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(jsval_layout), "::", + stringify!(debugView)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).s) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(s) - ) + unsafe { ::std::ptr::addr_of!((* ptr).s) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(jsval_layout), "::", stringify!(s)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).asDouble) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asDouble) - ) + unsafe { ::std::ptr::addr_of!((* ptr).asDouble) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(jsval_layout), "::", + stringify!(asDouble)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).asPtr) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asPtr) - ) + unsafe { ::std::ptr::addr_of!((* ptr).asPtr) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(jsval_layout), "::", stringify!(asPtr)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).asWord) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asWord) - ) + unsafe { ::std::ptr::addr_of!((* ptr).asWord) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(jsval_layout), "::", stringify!(asWord)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).asUIntPtr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asUIntPtr) - ) + unsafe { ::std::ptr::addr_of!((* ptr).asUIntPtr) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(jsval_layout), "::", + stringify!(asUIntPtr)) ); } impl Clone for jsval_layout { @@ -517,28 +431,19 @@ pub struct Value { } #[test] fn bindgen_test_layout_Value() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Value)) + ::std::mem::size_of:: < Value > (), 8usize, concat!("Size of: ", + stringify!(Value)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Value)) + ::std::mem::align_of:: < Value > (), 8usize, concat!("Alignment of ", + stringify!(Value)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Value), - "::", - stringify!(data) - ) + unsafe { ::std::ptr::addr_of!((* ptr).data) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(Value), "::", stringify!(data)) ); } impl Clone for Value { diff --git a/bindgen-tests/tests/expectations/tests/keywords.rs b/bindgen-tests/tests/expectations/tests/keywords.rs index a1e7f877e1..d07f241376 100644 --- a/bindgen-tests/tests/expectations/tests/keywords.rs +++ b/bindgen-tests/tests/expectations/tests/keywords.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { #[link_name = "\u{1}u8"] pub static mut u8_: ::std::os::raw::c_int; diff --git a/bindgen-tests/tests/expectations/tests/layout.rs b/bindgen-tests/tests/expectations/tests/layout.rs index ae417259cd..79048d2917 100644 --- a/bindgen-tests/tests/expectations/tests/layout.rs +++ b/bindgen-tests/tests/expectations/tests/layout.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct header { pub _bindgen_opaque_blob: [u8; 16usize], @@ -12,9 +6,8 @@ pub struct header { #[test] fn bindgen_test_layout_header() { assert_eq!( - ::std::mem::size_of::
(), - 16usize, - concat!("Size of: ", stringify!(header)) + ::std::mem::size_of:: < header > (), 16usize, concat!("Size of: ", + stringify!(header)) ); } impl Default for header { diff --git a/bindgen-tests/tests/expectations/tests/layout_align.rs b/bindgen-tests/tests/expectations/tests/layout_align.rs index 466e76862c..7a8e0569a2 100644 --- a/bindgen-tests/tests/expectations/tests/layout_align.rs +++ b/bindgen-tests/tests/expectations/tests/layout_align.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -138,14 +130,12 @@ pub struct rte_kni_fifo { #[test] fn bindgen_test_layout_rte_kni_fifo() { assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(rte_kni_fifo)) + ::std::mem::size_of:: < rte_kni_fifo > (), 16usize, concat!("Size of: ", + stringify!(rte_kni_fifo)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(rte_kni_fifo)) + ::std::mem::align_of:: < rte_kni_fifo > (), 8usize, concat!("Alignment of ", + stringify!(rte_kni_fifo)) ); } impl Default for rte_kni_fifo { @@ -169,38 +159,26 @@ pub struct rte_eth_link { } #[test] fn bindgen_test_layout_rte_eth_link() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(rte_eth_link)) + ::std::mem::size_of:: < rte_eth_link > (), 8usize, concat!("Size of: ", + stringify!(rte_eth_link)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(rte_eth_link)) + ::std::mem::align_of:: < rte_eth_link > (), 8usize, concat!("Alignment of ", + stringify!(rte_eth_link)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).link_speed) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_link), - "::", - stringify!(link_speed) - ) + unsafe { ::std::ptr::addr_of!((* ptr).link_speed) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_eth_link), "::", + stringify!(link_speed)) ); } impl rte_eth_link { #[inline] pub fn link_duplex(&self) -> u16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u16) } } #[inline] pub fn set_link_duplex(&mut self, val: u16) { @@ -211,9 +189,7 @@ impl rte_eth_link { } #[inline] pub fn link_autoneg(&self) -> u16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u16) } } #[inline] pub fn set_link_autoneg(&mut self, val: u16) { @@ -224,9 +200,7 @@ impl rte_eth_link { } #[inline] pub fn link_status(&self) -> u16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u16) } } #[inline] pub fn set_link_status(&mut self, val: u16) { @@ -241,23 +215,36 @@ impl rte_eth_link { link_autoneg: u16, link_status: u16, ) -> __BindgenBitfieldUnit<[u8; 1usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 1u8, { - let link_duplex: u16 = - unsafe { ::std::mem::transmute(link_duplex) }; - link_duplex as u64 - }); - __bindgen_bitfield_unit.set(1usize, 1u8, { - let link_autoneg: u16 = - unsafe { ::std::mem::transmute(link_autoneg) }; - link_autoneg as u64 - }); - __bindgen_bitfield_unit.set(2usize, 1u8, { - let link_status: u16 = - unsafe { ::std::mem::transmute(link_status) }; - link_status as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let link_duplex: u16 = unsafe { ::std::mem::transmute(link_duplex) }; + link_duplex as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 1usize, + 1u8, + { + let link_autoneg: u16 = unsafe { + ::std::mem::transmute(link_autoneg) + }; + link_autoneg as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 2usize, + 1u8, + { + let link_status: u16 = unsafe { ::std::mem::transmute(link_status) }; + link_status as u64 + }, + ); __bindgen_bitfield_unit } } diff --git a/bindgen-tests/tests/expectations/tests/layout_arp.rs b/bindgen-tests/tests/expectations/tests/layout_arp.rs index 6852c23635..1ee045593f 100644 --- a/bindgen-tests/tests/expectations/tests/layout_arp.rs +++ b/bindgen-tests/tests/expectations/tests/layout_arp.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const ETHER_ADDR_LEN: u32 = 6; pub const ARP_HRD_ETHER: u32 = 1; pub const ARP_OP_REQUEST: u32 = 1; @@ -13,15 +7,15 @@ pub const ARP_OP_REVREQUEST: u32 = 3; pub const ARP_OP_REVREPLY: u32 = 4; pub const ARP_OP_INVREQUEST: u32 = 8; pub const ARP_OP_INVREPLY: u32 = 9; -/// Ethernet address: -/// A universally administered address is uniquely assigned to a device by its -/// manufacturer. The first three octets (in transmission order) contain the -/// Organizationally Unique Identifier (OUI). The following three (MAC-48 and -/// EUI-48) octets are assigned by that organization with the only constraint -/// of uniqueness. -/// A locally administered address is assigned to a device by a network -/// administrator and does not contain OUIs. -/// See http://standards.ieee.org/regauth/groupmac/tutorial.html +/** Ethernet address: + A universally administered address is uniquely assigned to a device by its + manufacturer. The first three octets (in transmission order) contain the + Organizationally Unique Identifier (OUI). The following three (MAC-48 and + EUI-48) octets are assigned by that organization with the only constraint + of uniqueness. + A locally administered address is assigned to a device by a network + administrator and does not contain OUIs. + See http://standards.ieee.org/regauth/groupmac/tutorial.html*/ #[repr(C, packed)] #[derive(Debug, Default, Copy, Clone)] pub struct ether_addr { @@ -30,30 +24,20 @@ pub struct ether_addr { } #[test] fn bindgen_test_layout_ether_addr() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 6usize, - concat!("Size of: ", stringify!(ether_addr)) + ::std::mem::size_of:: < ether_addr > (), 6usize, concat!("Size of: ", + stringify!(ether_addr)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(ether_addr)) + ::std::mem::align_of:: < ether_addr > (), 1usize, concat!("Alignment of ", + stringify!(ether_addr)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).addr_bytes) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ether_addr), - "::", - stringify!(addr_bytes) - ) + unsafe { ::std::ptr::addr_of!((* ptr).addr_bytes) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(ether_addr), "::", + stringify!(addr_bytes)) ); } /// ARP header IPv4 payload. @@ -71,58 +55,33 @@ pub struct arp_ipv4 { } #[test] fn bindgen_test_layout_arp_ipv4() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 20usize, - concat!("Size of: ", stringify!(arp_ipv4)) + ::std::mem::size_of:: < arp_ipv4 > (), 20usize, concat!("Size of: ", + stringify!(arp_ipv4)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(arp_ipv4)) + ::std::mem::align_of:: < arp_ipv4 > (), 1usize, concat!("Alignment of ", + stringify!(arp_ipv4)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).arp_sha) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(arp_ipv4), - "::", - stringify!(arp_sha) - ) + unsafe { ::std::ptr::addr_of!((* ptr).arp_sha) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(arp_ipv4), "::", stringify!(arp_sha)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).arp_sip) as usize - ptr as usize }, - 6usize, - concat!( - "Offset of field: ", - stringify!(arp_ipv4), - "::", - stringify!(arp_sip) - ) + unsafe { ::std::ptr::addr_of!((* ptr).arp_sip) as usize - ptr as usize }, 6usize, + concat!("Offset of field: ", stringify!(arp_ipv4), "::", stringify!(arp_sip)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).arp_tha) as usize - ptr as usize }, - 10usize, - concat!( - "Offset of field: ", - stringify!(arp_ipv4), - "::", - stringify!(arp_tha) - ) + unsafe { ::std::ptr::addr_of!((* ptr).arp_tha) as usize - ptr as usize }, + 10usize, concat!("Offset of field: ", stringify!(arp_ipv4), "::", + stringify!(arp_tha)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).arp_tip) as usize - ptr as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(arp_ipv4), - "::", - stringify!(arp_tip) - ) + unsafe { ::std::ptr::addr_of!((* ptr).arp_tip) as usize - ptr as usize }, + 16usize, concat!("Offset of field: ", stringify!(arp_ipv4), "::", + stringify!(arp_tip)) ); } /// ARP header. @@ -138,79 +97,39 @@ pub struct arp_hdr { } #[test] fn bindgen_test_layout_arp_hdr() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 28usize, - concat!("Size of: ", stringify!(arp_hdr)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(arp_hdr)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).arp_hrd) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(arp_hdr), - "::", - stringify!(arp_hrd) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).arp_pro) as usize - ptr as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(arp_hdr), - "::", - stringify!(arp_pro) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).arp_hln) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(arp_hdr), - "::", - stringify!(arp_hln) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).arp_pln) as usize - ptr as usize }, - 5usize, - concat!( - "Offset of field: ", - stringify!(arp_hdr), - "::", - stringify!(arp_pln) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).arp_op) as usize - ptr as usize }, - 6usize, - concat!( - "Offset of field: ", - stringify!(arp_hdr), - "::", - stringify!(arp_op) - ) - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).arp_data) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(arp_hdr), - "::", - stringify!(arp_data) - ) + ::std::mem::size_of:: < arp_hdr > (), 28usize, concat!("Size of: ", + stringify!(arp_hdr)) + ); + assert_eq!( + ::std::mem::align_of:: < arp_hdr > (), 1usize, concat!("Alignment of ", + stringify!(arp_hdr)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).arp_hrd) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(arp_hdr), "::", stringify!(arp_hrd)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).arp_pro) as usize - ptr as usize }, 2usize, + concat!("Offset of field: ", stringify!(arp_hdr), "::", stringify!(arp_pro)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).arp_hln) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(arp_hdr), "::", stringify!(arp_hln)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).arp_pln) as usize - ptr as usize }, 5usize, + concat!("Offset of field: ", stringify!(arp_hdr), "::", stringify!(arp_pln)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).arp_op) as usize - ptr as usize }, 6usize, + concat!("Offset of field: ", stringify!(arp_hdr), "::", stringify!(arp_op)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).arp_data) as usize - ptr as usize }, + 8usize, concat!("Offset of field: ", stringify!(arp_hdr), "::", + stringify!(arp_data)) ); } diff --git a/bindgen-tests/tests/expectations/tests/layout_array.rs b/bindgen-tests/tests/expectations/tests/layout_array.rs index daf0ad06fd..d9171be24b 100644 --- a/bindgen-tests/tests/expectations/tests/layout_array.rs +++ b/bindgen-tests/tests/expectations/tests/layout_array.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const RTE_CACHE_LINE_SIZE: u32 = 64; pub const RTE_MEMPOOL_OPS_NAMESIZE: u32 = 32; pub const RTE_MEMPOOL_MAX_OPS_IDX: u32 = 16; @@ -14,20 +8,21 @@ pub const RTE_HEAP_NUM_FREELISTS: u32 = 13; pub struct rte_mempool { _unused: [u8; 0], } -/// Prototype for implementation specific data provisioning function. -/// -/// The function should provide the implementation specific memory for -/// for use by the other mempool ops functions in a given mempool ops struct. -/// E.g. the default ops provides an instance of the rte_ring for this purpose. -/// it will most likely point to a different type of data structure, and -/// will be transparent to the application programmer. -/// This function should set mp->pool_data. +/** Prototype for implementation specific data provisioning function. + + The function should provide the implementation specific memory for + for use by the other mempool ops functions in a given mempool ops struct. + E.g. the default ops provides an instance of the rte_ring for this purpose. + it will most likely point to a different type of data structure, and + will be transparent to the application programmer. + This function should set mp->pool_data.*/ pub type rte_mempool_alloc_t = ::std::option::Option< unsafe extern "C" fn(mp: *mut rte_mempool) -> ::std::os::raw::c_int, >; /// Free the opaque private data pointed to by mp->pool_data pointer. -pub type rte_mempool_free_t = - ::std::option::Option; +pub type rte_mempool_free_t = ::std::option::Option< + unsafe extern "C" fn(mp: *mut rte_mempool), +>; /// Enqueue an object into the external pool. pub type rte_mempool_enqueue_t = ::std::option::Option< unsafe extern "C" fn( @@ -68,80 +63,43 @@ pub struct rte_mempool_ops { } #[test] fn bindgen_test_layout_rte_mempool_ops() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 128usize, - concat!("Size of: ", stringify!(rte_mempool_ops)) + ::std::mem::size_of:: < rte_mempool_ops > (), 128usize, concat!("Size of: ", + stringify!(rte_mempool_ops)) ); assert_eq!( - ::std::mem::align_of::(), - 64usize, - concat!("Alignment of ", stringify!(rte_mempool_ops)) + ::std::mem::align_of:: < rte_mempool_ops > (), 64usize, concat!("Alignment of ", + stringify!(rte_mempool_ops)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).name) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mempool_ops), - "::", - stringify!(name) - ) + unsafe { ::std::ptr::addr_of!((* ptr).name) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_mempool_ops), "::", stringify!(name)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).alloc) as usize - ptr as usize }, - 32usize, - concat!( - "Offset of field: ", - stringify!(rte_mempool_ops), - "::", - stringify!(alloc) - ) + unsafe { ::std::ptr::addr_of!((* ptr).alloc) as usize - ptr as usize }, 32usize, + concat!("Offset of field: ", stringify!(rte_mempool_ops), "::", + stringify!(alloc)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).free) as usize - ptr as usize }, - 40usize, - concat!( - "Offset of field: ", - stringify!(rte_mempool_ops), - "::", - stringify!(free) - ) + unsafe { ::std::ptr::addr_of!((* ptr).free) as usize - ptr as usize }, 40usize, + concat!("Offset of field: ", stringify!(rte_mempool_ops), "::", stringify!(free)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).enqueue) as usize - ptr as usize }, - 48usize, - concat!( - "Offset of field: ", - stringify!(rte_mempool_ops), - "::", - stringify!(enqueue) - ) + unsafe { ::std::ptr::addr_of!((* ptr).enqueue) as usize - ptr as usize }, + 48usize, concat!("Offset of field: ", stringify!(rte_mempool_ops), "::", + stringify!(enqueue)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dequeue) as usize - ptr as usize }, - 56usize, - concat!( - "Offset of field: ", - stringify!(rte_mempool_ops), - "::", - stringify!(dequeue) - ) + unsafe { ::std::ptr::addr_of!((* ptr).dequeue) as usize - ptr as usize }, + 56usize, concat!("Offset of field: ", stringify!(rte_mempool_ops), "::", + stringify!(dequeue)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).get_count) as usize - ptr as usize - }, - 64usize, - concat!( - "Offset of field: ", - stringify!(rte_mempool_ops), - "::", - stringify!(get_count) - ) + unsafe { ::std::ptr::addr_of!((* ptr).get_count) as usize - ptr as usize }, + 64usize, concat!("Offset of field: ", stringify!(rte_mempool_ops), "::", + stringify!(get_count)) ); } impl Default for rte_mempool_ops { @@ -155,12 +113,9 @@ 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 + 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. @@ -172,37 +127,29 @@ pub struct rte_spinlock_t { } #[test] fn bindgen_test_layout_rte_spinlock_t() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(rte_spinlock_t)) + ::std::mem::size_of:: < rte_spinlock_t > (), 4usize, concat!("Size of: ", + stringify!(rte_spinlock_t)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(rte_spinlock_t)) + ::std::mem::align_of:: < rte_spinlock_t > (), 4usize, concat!("Alignment of ", + stringify!(rte_spinlock_t)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).locked) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_spinlock_t), - "::", - stringify!(locked) - ) + unsafe { ::std::ptr::addr_of!((* ptr).locked) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_spinlock_t), "::", + stringify!(locked)) ); } -/// 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 -/// the mempools can be shared across primary and secondary processes. -/// The indices used to access the array are valid across processes, whereas -/// any function pointers stored directly in the mempool struct would not be. -/// This results in us simply having "ops_index" in the mempool struct. +/** 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 + the mempools can be shared across primary and secondary processes. + The indices used to access the array are valid across processes, whereas + any function pointers stored directly in the mempool struct would not be. + This results in us simply having "ops_index" in the mempool struct.*/ #[repr(C)] #[repr(align(64))] #[derive(Copy, Clone)] @@ -217,48 +164,30 @@ pub struct rte_mempool_ops_table { } #[test] fn bindgen_test_layout_rte_mempool_ops_table() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 2112usize, + ::std::mem::size_of:: < rte_mempool_ops_table > (), 2112usize, concat!("Size of: ", stringify!(rte_mempool_ops_table)) ); assert_eq!( - ::std::mem::align_of::(), - 64usize, + ::std::mem::align_of:: < rte_mempool_ops_table > (), 64usize, concat!("Alignment of ", stringify!(rte_mempool_ops_table)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).sl) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mempool_ops_table), - "::", - stringify!(sl) - ) + unsafe { ::std::ptr::addr_of!((* ptr).sl) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_mempool_ops_table), "::", + stringify!(sl)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).num_ops) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_mempool_ops_table), - "::", - stringify!(num_ops) - ) + unsafe { ::std::ptr::addr_of!((* ptr).num_ops) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(rte_mempool_ops_table), "::", + stringify!(num_ops)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ops) as usize - ptr as usize }, - 64usize, - concat!( - "Offset of field: ", - stringify!(rte_mempool_ops_table), - "::", - stringify!(ops) - ) + unsafe { ::std::ptr::addr_of!((* ptr).ops) as usize - ptr as usize }, 64usize, + concat!("Offset of field: ", stringify!(rte_mempool_ops_table), "::", + stringify!(ops)) ); } impl Default for rte_mempool_ops_table { @@ -287,30 +216,20 @@ pub struct malloc_heap__bindgen_ty_1 { } #[test] fn bindgen_test_layout_malloc_heap__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, + ::std::mem::size_of:: < malloc_heap__bindgen_ty_1 > (), 8usize, concat!("Size of: ", stringify!(malloc_heap__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, + ::std::mem::align_of:: < malloc_heap__bindgen_ty_1 > (), 8usize, concat!("Alignment of ", stringify!(malloc_heap__bindgen_ty_1)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).lh_first) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(malloc_heap__bindgen_ty_1), - "::", - stringify!(lh_first) - ) + unsafe { ::std::ptr::addr_of!((* ptr).lh_first) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(malloc_heap__bindgen_ty_1), "::", + stringify!(lh_first)) ); } impl Default for malloc_heap__bindgen_ty_1 { @@ -324,64 +243,34 @@ impl Default for malloc_heap__bindgen_ty_1 { } #[test] fn bindgen_test_layout_malloc_heap() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 128usize, - concat!("Size of: ", stringify!(malloc_heap)) + ::std::mem::size_of:: < malloc_heap > (), 128usize, concat!("Size of: ", + stringify!(malloc_heap)) ); assert_eq!( - ::std::mem::align_of::(), - 64usize, - concat!("Alignment of ", stringify!(malloc_heap)) + ::std::mem::align_of:: < malloc_heap > (), 64usize, concat!("Alignment of ", + stringify!(malloc_heap)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).lock) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(malloc_heap), - "::", - stringify!(lock) - ) + unsafe { ::std::ptr::addr_of!((* ptr).lock) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(malloc_heap), "::", stringify!(lock)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).free_head) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(malloc_heap), - "::", - stringify!(free_head) - ) + unsafe { ::std::ptr::addr_of!((* ptr).free_head) as usize - ptr as usize }, + 8usize, concat!("Offset of field: ", stringify!(malloc_heap), "::", + stringify!(free_head)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).alloc_count) as usize - ptr as usize - }, - 112usize, - concat!( - "Offset of field: ", - stringify!(malloc_heap), - "::", - stringify!(alloc_count) - ) + unsafe { ::std::ptr::addr_of!((* ptr).alloc_count) as usize - ptr as usize }, + 112usize, concat!("Offset of field: ", stringify!(malloc_heap), "::", + stringify!(alloc_count)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).total_size) as usize - ptr as usize - }, - 120usize, - concat!( - "Offset of field: ", - stringify!(malloc_heap), - "::", - stringify!(total_size) - ) + unsafe { ::std::ptr::addr_of!((* ptr).total_size) as usize - ptr as usize }, + 120usize, concat!("Offset of field: ", stringify!(malloc_heap), "::", + stringify!(total_size)) ); } impl Default for malloc_heap { @@ -395,10 +284,9 @@ 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 + self.lock == other.lock && self.free_head == other.free_head + && self.alloc_count == other.alloc_count + && self.total_size == other.total_size } } #[repr(C)] 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 56b3c021f5..2eb95b2d85 100644 --- a/bindgen-tests/tests/expectations/tests/layout_array_too_long.rs +++ b/bindgen-tests/tests/expectations/tests/layout_array_too_long.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const RTE_CACHE_LINE_SIZE: u32 = 64; pub const RTE_LIBRTE_IP_FRAG_MAX_FRAG: u32 = 4; pub const IP_LAST_FRAG_IDX: _bindgen_ty_1 = _bindgen_ty_1::IP_LAST_FRAG_IDX; @@ -35,48 +29,27 @@ pub struct ip_frag { } #[test] fn bindgen_test_layout_ip_frag() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(ip_frag)) + ::std::mem::size_of:: < ip_frag > (), 16usize, concat!("Size of: ", + stringify!(ip_frag)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(ip_frag)) + ::std::mem::align_of:: < ip_frag > (), 8usize, concat!("Alignment of ", + stringify!(ip_frag)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ofs) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ip_frag), - "::", - stringify!(ofs) - ) + unsafe { ::std::ptr::addr_of!((* ptr).ofs) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(ip_frag), "::", stringify!(ofs)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(ip_frag), - "::", - stringify!(len) - ) + unsafe { ::std::ptr::addr_of!((* ptr).len) as usize - ptr as usize }, 2usize, + concat!("Offset of field: ", stringify!(ip_frag), "::", stringify!(len)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mb) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(ip_frag), - "::", - stringify!(mb) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mb) as usize - ptr as usize }, 8usize, + concat!("Offset of field: ", stringify!(ip_frag), "::", stringify!(mb)) ); } impl Default for ip_frag { @@ -101,52 +74,32 @@ pub struct ip_frag_key { } #[test] fn bindgen_test_layout_ip_frag_key() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 40usize, - concat!("Size of: ", stringify!(ip_frag_key)) + ::std::mem::size_of:: < ip_frag_key > (), 40usize, concat!("Size of: ", + stringify!(ip_frag_key)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(ip_frag_key)) + ::std::mem::align_of:: < ip_frag_key > (), 8usize, concat!("Alignment of ", + stringify!(ip_frag_key)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).src_dst) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_key), - "::", - stringify!(src_dst) - ) + unsafe { ::std::ptr::addr_of!((* ptr).src_dst) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(ip_frag_key), "::", stringify!(src_dst)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).id) as usize - ptr as usize }, - 32usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_key), - "::", - stringify!(id) - ) + unsafe { ::std::ptr::addr_of!((* ptr).id) as usize - ptr as usize }, 32usize, + concat!("Offset of field: ", stringify!(ip_frag_key), "::", stringify!(id)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).key_len) as usize - ptr as usize }, - 36usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_key), - "::", - stringify!(key_len) - ) + unsafe { ::std::ptr::addr_of!((* ptr).key_len) as usize - ptr as usize }, + 36usize, concat!("Offset of field: ", stringify!(ip_frag_key), "::", + stringify!(key_len)) ); } -/// @internal Fragmented packet to reassemble. -/// First two entries in the frags[] array are for the last and first fragments. +/** @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)] @@ -174,42 +127,25 @@ pub struct ip_frag_pkt__bindgen_ty_1 { } #[test] fn bindgen_test_layout_ip_frag_pkt__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 16usize, + ::std::mem::size_of:: < ip_frag_pkt__bindgen_ty_1 > (), 16usize, concat!("Size of: ", stringify!(ip_frag_pkt__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, + ::std::mem::align_of:: < ip_frag_pkt__bindgen_ty_1 > (), 8usize, concat!("Alignment of ", stringify!(ip_frag_pkt__bindgen_ty_1)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).tqe_next) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt__bindgen_ty_1), - "::", - stringify!(tqe_next) - ) + unsafe { ::std::ptr::addr_of!((* ptr).tqe_next) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(ip_frag_pkt__bindgen_ty_1), "::", + stringify!(tqe_next)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).tqe_prev) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt__bindgen_ty_1), - "::", - stringify!(tqe_prev) - ) + unsafe { ::std::ptr::addr_of!((* ptr).tqe_prev) as usize - ptr as usize }, + 8usize, concat!("Offset of field: ", stringify!(ip_frag_pkt__bindgen_ty_1), "::", + stringify!(tqe_prev)) ); } impl Default for ip_frag_pkt__bindgen_ty_1 { @@ -223,94 +159,46 @@ 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(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 192usize, - concat!("Size of: ", stringify!(ip_frag_pkt)) + ::std::mem::size_of:: < ip_frag_pkt > (), 192usize, concat!("Size of: ", + stringify!(ip_frag_pkt)) ); assert_eq!( - ::std::mem::align_of::(), - 64usize, - concat!("Alignment of ", stringify!(ip_frag_pkt)) + ::std::mem::align_of:: < ip_frag_pkt > (), 64usize, concat!("Alignment of ", + stringify!(ip_frag_pkt)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).lru) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(lru) - ) + unsafe { ::std::ptr::addr_of!((* ptr).lru) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", stringify!(lru)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).key) as usize - ptr as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(key) - ) + unsafe { ::std::ptr::addr_of!((* ptr).key) as usize - ptr as usize }, 16usize, + concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", stringify!(key)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).start) as usize - ptr as usize }, - 56usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(start) - ) + unsafe { ::std::ptr::addr_of!((* ptr).start) as usize - ptr as usize }, 56usize, + concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", stringify!(start)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).total_size) as usize - ptr as usize - }, - 64usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(total_size) - ) + unsafe { ::std::ptr::addr_of!((* ptr).total_size) as usize - ptr as usize }, + 64usize, concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", + stringify!(total_size)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).frag_size) as usize - ptr as usize - }, - 68usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(frag_size) - ) + unsafe { ::std::ptr::addr_of!((* ptr).frag_size) as usize - ptr as usize }, + 68usize, concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", + stringify!(frag_size)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).last_idx) as usize - ptr as usize - }, - 72usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(last_idx) - ) + unsafe { ::std::ptr::addr_of!((* ptr).last_idx) as usize - ptr as usize }, + 72usize, concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", + stringify!(last_idx)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).frags) as usize - ptr as usize }, - 80usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(frags) - ) + unsafe { ::std::ptr::addr_of!((* ptr).frags) as usize - ptr as usize }, 80usize, + concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", stringify!(frags)) ); } impl Default for ip_frag_pkt { @@ -324,13 +212,9 @@ 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 + 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 diff --git a/bindgen-tests/tests/expectations/tests/layout_cmdline_token.rs b/bindgen-tests/tests/expectations/tests/layout_cmdline_token.rs index 899703bd04..af18e90d12 100644 --- a/bindgen-tests/tests/expectations/tests/layout_cmdline_token.rs +++ b/bindgen-tests/tests/expectations/tests/layout_cmdline_token.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -/// Stores a pointer to the ops struct, and the offset: the place to -/// write the parsed result in the destination structure. +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +/** Stores a pointer to the ops struct, and the offset: the place to + write the parsed result in the destination structure.*/ #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct cmdline_token_hdr { @@ -15,38 +9,25 @@ pub struct cmdline_token_hdr { } #[test] fn bindgen_test_layout_cmdline_token_hdr() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(cmdline_token_hdr)) + ::std::mem::size_of:: < cmdline_token_hdr > (), 16usize, concat!("Size of: ", + stringify!(cmdline_token_hdr)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(cmdline_token_hdr)) + ::std::mem::align_of:: < cmdline_token_hdr > (), 8usize, concat!("Alignment of ", + stringify!(cmdline_token_hdr)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ops) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(cmdline_token_hdr), - "::", - stringify!(ops) - ) + unsafe { ::std::ptr::addr_of!((* ptr).ops) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(cmdline_token_hdr), "::", + stringify!(ops)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).offset) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(cmdline_token_hdr), - "::", - stringify!(offset) - ) + unsafe { ::std::ptr::addr_of!((* ptr).offset) as usize - ptr as usize }, 8usize, + concat!("Offset of field: ", stringify!(cmdline_token_hdr), "::", + stringify!(offset)) ); } impl Default for cmdline_token_hdr { @@ -58,26 +39,26 @@ impl Default for cmdline_token_hdr { } } } -/// Stores a pointer to the ops struct, and the offset: the place to -/// write the parsed result in the destination structure. +/** Stores a pointer to the ops struct, and the offset: the place to + write the parsed result in the destination structure.*/ pub type cmdline_parse_token_hdr_t = cmdline_token_hdr; -/// A token is defined by this structure. -/// -/// parse() takes the token as first argument, then the source buffer -/// starting at the token we want to parse. The 3rd arg is a pointer -/// where we store the parsed data (as binary). It returns the number of -/// parsed chars on success and a negative value on error. -/// -/// complete_get_nb() returns the number of possible values for this -/// token if completion is possible. If it is NULL or if it returns 0, -/// no completion is possible. -/// -/// complete_get_elt() copy in dstbuf (the size is specified in the -/// parameter) the i-th possible completion for this token. returns 0 -/// on success or and a negative value on error. -/// -/// get_help() fills the dstbuf with the help for the token. It returns -/// -1 on error and 0 on success. +/** A token is defined by this structure. + + parse() takes the token as first argument, then the source buffer + starting at the token we want to parse. The 3rd arg is a pointer + where we store the parsed data (as binary). It returns the number of + parsed chars on success and a negative value on error. + + complete_get_nb() returns the number of possible values for this + token if completion is possible. If it is NULL or if it returns 0, + no completion is possible. + + complete_get_elt() copy in dstbuf (the size is specified in the + parameter) the i-th possible completion for this token. returns 0 + on success or and a negative value on error. + + get_help() fills the dstbuf with the help for the token. It returns + -1 on error and 0 on success.*/ #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct cmdline_token_ops { @@ -116,65 +97,35 @@ pub struct cmdline_token_ops { } #[test] fn bindgen_test_layout_cmdline_token_ops() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 32usize, - concat!("Size of: ", stringify!(cmdline_token_ops)) + ::std::mem::size_of:: < cmdline_token_ops > (), 32usize, concat!("Size of: ", + stringify!(cmdline_token_ops)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(cmdline_token_ops)) + ::std::mem::align_of:: < cmdline_token_ops > (), 8usize, concat!("Alignment of ", + stringify!(cmdline_token_ops)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).parse) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(cmdline_token_ops), - "::", - stringify!(parse) - ) + unsafe { ::std::ptr::addr_of!((* ptr).parse) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(cmdline_token_ops), "::", + stringify!(parse)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).complete_get_nb) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(cmdline_token_ops), - "::", - stringify!(complete_get_nb) - ) + unsafe { ::std::ptr::addr_of!((* ptr).complete_get_nb) as usize - ptr as usize }, + 8usize, concat!("Offset of field: ", stringify!(cmdline_token_ops), "::", + stringify!(complete_get_nb)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).complete_get_elt) as usize - - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(cmdline_token_ops), - "::", - stringify!(complete_get_elt) - ) + unsafe { ::std::ptr::addr_of!((* ptr).complete_get_elt) as usize - ptr as usize + }, 16usize, concat!("Offset of field: ", stringify!(cmdline_token_ops), "::", + stringify!(complete_get_elt)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).get_help) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(cmdline_token_ops), - "::", - stringify!(get_help) - ) + unsafe { ::std::ptr::addr_of!((* ptr).get_help) as usize - ptr as usize }, + 24usize, concat!("Offset of field: ", stringify!(cmdline_token_ops), "::", + stringify!(get_help)) ); } #[repr(u32)] @@ -196,28 +147,20 @@ pub struct cmdline_token_num_data { } #[test] fn bindgen_test_layout_cmdline_token_num_data() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(cmdline_token_num_data)) + ::std::mem::size_of:: < cmdline_token_num_data > (), 4usize, concat!("Size of: ", + stringify!(cmdline_token_num_data)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < cmdline_token_num_data > (), 4usize, concat!("Alignment of ", stringify!(cmdline_token_num_data)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(cmdline_token_num_data), - "::", - stringify!(type_) - ) + unsafe { ::std::ptr::addr_of!((* ptr).type_) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(cmdline_token_num_data), "::", + stringify!(type_)) ); } impl Default for cmdline_token_num_data { @@ -237,40 +180,25 @@ pub struct cmdline_token_num { } #[test] fn bindgen_test_layout_cmdline_token_num() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 24usize, - concat!("Size of: ", stringify!(cmdline_token_num)) + ::std::mem::size_of:: < cmdline_token_num > (), 24usize, concat!("Size of: ", + stringify!(cmdline_token_num)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(cmdline_token_num)) + ::std::mem::align_of:: < cmdline_token_num > (), 8usize, concat!("Alignment of ", + stringify!(cmdline_token_num)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).hdr) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(cmdline_token_num), - "::", - stringify!(hdr) - ) + unsafe { ::std::ptr::addr_of!((* ptr).hdr) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(cmdline_token_num), "::", + stringify!(hdr)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).num_data) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(cmdline_token_num), - "::", - stringify!(num_data) - ) + unsafe { ::std::ptr::addr_of!((* ptr).num_data) as usize - ptr as usize }, + 16usize, concat!("Offset of field: ", stringify!(cmdline_token_num), "::", + stringify!(num_data)) ); } impl Default for cmdline_token_num { diff --git a/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs b/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs index 7dd45b709e..1ec0744f0d 100644 --- a/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs +++ b/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -124,8 +116,8 @@ pub const RTE_ETH_FLOW_GENEVE: u32 = 20; pub const RTE_ETH_FLOW_NVGRE: u32 = 21; pub const RTE_ETH_FLOW_MAX: u32 = 22; #[repr(u32)] -/// A set of values to identify what method is to be used to route -/// packets to multiple queues. +/** A set of values to identify what method is to be used to route + packets to multiple queues.*/ #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum rte_eth_rx_mq_mode { /// None of DCB,RSS or VMDQ mode @@ -160,52 +152,30 @@ pub struct rte_eth_rxmode { } #[test] fn bindgen_test_layout_rte_eth_rxmode() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 12usize, - concat!("Size of: ", stringify!(rte_eth_rxmode)) + ::std::mem::size_of:: < rte_eth_rxmode > (), 12usize, concat!("Size of: ", + stringify!(rte_eth_rxmode)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(rte_eth_rxmode)) + ::std::mem::align_of:: < rte_eth_rxmode > (), 4usize, concat!("Alignment of ", + stringify!(rte_eth_rxmode)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mq_mode) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rxmode), - "::", - stringify!(mq_mode) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mq_mode) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_eth_rxmode), "::", + stringify!(mq_mode)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).max_rx_pkt_len) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rxmode), - "::", - stringify!(max_rx_pkt_len) - ) + unsafe { ::std::ptr::addr_of!((* ptr).max_rx_pkt_len) as usize - ptr as usize }, + 4usize, concat!("Offset of field: ", stringify!(rte_eth_rxmode), "::", + stringify!(max_rx_pkt_len)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).split_hdr_size) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rxmode), - "::", - stringify!(split_hdr_size) - ) + unsafe { ::std::ptr::addr_of!((* ptr).split_hdr_size) as usize - ptr as usize }, + 8usize, concat!("Offset of field: ", stringify!(rte_eth_rxmode), "::", + stringify!(split_hdr_size)) ); } impl Default for rte_eth_rxmode { @@ -220,9 +190,7 @@ impl Default for rte_eth_rxmode { impl rte_eth_rxmode { #[inline] pub fn header_split(&self) -> u16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u16) } } #[inline] pub fn set_header_split(&mut self, val: u16) { @@ -233,9 +201,7 @@ impl rte_eth_rxmode { } #[inline] pub fn hw_ip_checksum(&self) -> u16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u16) } } #[inline] pub fn set_hw_ip_checksum(&mut self, val: u16) { @@ -246,9 +212,7 @@ impl rte_eth_rxmode { } #[inline] pub fn hw_vlan_filter(&self) -> u16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u16) } } #[inline] pub fn set_hw_vlan_filter(&mut self, val: u16) { @@ -259,9 +223,7 @@ impl rte_eth_rxmode { } #[inline] pub fn hw_vlan_strip(&self) -> u16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(3usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(3usize, 1u8) as u16) } } #[inline] pub fn set_hw_vlan_strip(&mut self, val: u16) { @@ -272,9 +234,7 @@ impl rte_eth_rxmode { } #[inline] pub fn hw_vlan_extend(&self) -> u16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(4usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(4usize, 1u8) as u16) } } #[inline] pub fn set_hw_vlan_extend(&mut self, val: u16) { @@ -285,9 +245,7 @@ impl rte_eth_rxmode { } #[inline] pub fn jumbo_frame(&self) -> u16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(5usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(5usize, 1u8) as u16) } } #[inline] pub fn set_jumbo_frame(&mut self, val: u16) { @@ -298,9 +256,7 @@ impl rte_eth_rxmode { } #[inline] pub fn hw_strip_crc(&self) -> u16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(6usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(6usize, 1u8) as u16) } } #[inline] pub fn set_hw_strip_crc(&mut self, val: u16) { @@ -311,9 +267,7 @@ impl rte_eth_rxmode { } #[inline] pub fn enable_scatter(&self) -> u16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(7usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(7usize, 1u8) as u16) } } #[inline] pub fn set_enable_scatter(&mut self, val: u16) { @@ -324,9 +278,7 @@ impl rte_eth_rxmode { } #[inline] pub fn enable_lro(&self) -> u16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(8usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(8usize, 1u8) as u16) } } #[inline] pub fn set_enable_lro(&mut self, val: u16) { @@ -347,58 +299,108 @@ impl rte_eth_rxmode { enable_scatter: u16, enable_lro: u16, ) -> __BindgenBitfieldUnit<[u8; 2usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 2usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 1u8, { - let header_split: u16 = - unsafe { ::std::mem::transmute(header_split) }; - header_split as u64 - }); - __bindgen_bitfield_unit.set(1usize, 1u8, { - let hw_ip_checksum: u16 = - unsafe { ::std::mem::transmute(hw_ip_checksum) }; - hw_ip_checksum as u64 - }); - __bindgen_bitfield_unit.set(2usize, 1u8, { - let hw_vlan_filter: u16 = - unsafe { ::std::mem::transmute(hw_vlan_filter) }; - hw_vlan_filter as u64 - }); - __bindgen_bitfield_unit.set(3usize, 1u8, { - let hw_vlan_strip: u16 = - unsafe { ::std::mem::transmute(hw_vlan_strip) }; - hw_vlan_strip as u64 - }); - __bindgen_bitfield_unit.set(4usize, 1u8, { - let hw_vlan_extend: u16 = - unsafe { ::std::mem::transmute(hw_vlan_extend) }; - hw_vlan_extend as u64 - }); - __bindgen_bitfield_unit.set(5usize, 1u8, { - let jumbo_frame: u16 = - unsafe { ::std::mem::transmute(jumbo_frame) }; - jumbo_frame as u64 - }); - __bindgen_bitfield_unit.set(6usize, 1u8, { - let hw_strip_crc: u16 = - unsafe { ::std::mem::transmute(hw_strip_crc) }; - hw_strip_crc as u64 - }); - __bindgen_bitfield_unit.set(7usize, 1u8, { - let enable_scatter: u16 = - unsafe { ::std::mem::transmute(enable_scatter) }; - enable_scatter as u64 - }); - __bindgen_bitfield_unit.set(8usize, 1u8, { - let enable_lro: u16 = unsafe { ::std::mem::transmute(enable_lro) }; - enable_lro as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 2usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let header_split: u16 = unsafe { + ::std::mem::transmute(header_split) + }; + header_split as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 1usize, + 1u8, + { + let hw_ip_checksum: u16 = unsafe { + ::std::mem::transmute(hw_ip_checksum) + }; + hw_ip_checksum as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 2usize, + 1u8, + { + let hw_vlan_filter: u16 = unsafe { + ::std::mem::transmute(hw_vlan_filter) + }; + hw_vlan_filter as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 3usize, + 1u8, + { + let hw_vlan_strip: u16 = unsafe { + ::std::mem::transmute(hw_vlan_strip) + }; + hw_vlan_strip as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 4usize, + 1u8, + { + let hw_vlan_extend: u16 = unsafe { + ::std::mem::transmute(hw_vlan_extend) + }; + hw_vlan_extend as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 5usize, + 1u8, + { + let jumbo_frame: u16 = unsafe { ::std::mem::transmute(jumbo_frame) }; + jumbo_frame as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 6usize, + 1u8, + { + let hw_strip_crc: u16 = unsafe { + ::std::mem::transmute(hw_strip_crc) + }; + hw_strip_crc as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 7usize, + 1u8, + { + let enable_scatter: u16 = unsafe { + ::std::mem::transmute(enable_scatter) + }; + enable_scatter as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 8usize, + 1u8, + { + let enable_lro: u16 = unsafe { ::std::mem::transmute(enable_lro) }; + enable_lro as u64 + }, + ); __bindgen_bitfield_unit } } #[repr(u32)] -/// A set of values to identify what method is to be used to transmit -/// packets using multi-TCs. +/** A set of values to identify what method is to be used to transmit + packets using multi-TCs.*/ #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum rte_eth_tx_mq_mode { ///< It is in neither DCB nor VT mode. @@ -423,38 +425,24 @@ pub struct rte_eth_txmode { } #[test] fn bindgen_test_layout_rte_eth_txmode() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(rte_eth_txmode)) + ::std::mem::size_of:: < rte_eth_txmode > (), 8usize, concat!("Size of: ", + stringify!(rte_eth_txmode)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(rte_eth_txmode)) + ::std::mem::align_of:: < rte_eth_txmode > (), 4usize, concat!("Alignment of ", + stringify!(rte_eth_txmode)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mq_mode) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_txmode), - "::", - stringify!(mq_mode) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mq_mode) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_eth_txmode), "::", + stringify!(mq_mode)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).pvid) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_txmode), - "::", - stringify!(pvid) - ) + unsafe { ::std::ptr::addr_of!((* ptr).pvid) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(rte_eth_txmode), "::", stringify!(pvid)) ); } impl Default for rte_eth_txmode { @@ -469,9 +457,7 @@ impl Default for rte_eth_txmode { impl rte_eth_txmode { #[inline] pub fn hw_vlan_reject_tagged(&self) -> u8 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) } } #[inline] pub fn set_hw_vlan_reject_tagged(&mut self, val: u8) { @@ -482,9 +468,7 @@ impl rte_eth_txmode { } #[inline] pub fn hw_vlan_reject_untagged(&self) -> u8 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u8) } } #[inline] pub fn set_hw_vlan_reject_untagged(&mut self, val: u8) { @@ -495,9 +479,7 @@ impl rte_eth_txmode { } #[inline] pub fn hw_vlan_insert_pvid(&self) -> u8 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u8) } } #[inline] pub fn set_hw_vlan_insert_pvid(&mut self, val: u8) { @@ -512,41 +494,58 @@ impl rte_eth_txmode { hw_vlan_reject_untagged: u8, hw_vlan_insert_pvid: u8, ) -> __BindgenBitfieldUnit<[u8; 1usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 1u8, { - let hw_vlan_reject_tagged: u8 = - unsafe { ::std::mem::transmute(hw_vlan_reject_tagged) }; - hw_vlan_reject_tagged as u64 - }); - __bindgen_bitfield_unit.set(1usize, 1u8, { - let hw_vlan_reject_untagged: u8 = - unsafe { ::std::mem::transmute(hw_vlan_reject_untagged) }; - hw_vlan_reject_untagged as u64 - }); - __bindgen_bitfield_unit.set(2usize, 1u8, { - let hw_vlan_insert_pvid: u8 = - unsafe { ::std::mem::transmute(hw_vlan_insert_pvid) }; - hw_vlan_insert_pvid as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let hw_vlan_reject_tagged: u8 = unsafe { + ::std::mem::transmute(hw_vlan_reject_tagged) + }; + hw_vlan_reject_tagged as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 1usize, + 1u8, + { + let hw_vlan_reject_untagged: u8 = unsafe { + ::std::mem::transmute(hw_vlan_reject_untagged) + }; + hw_vlan_reject_untagged as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 2usize, + 1u8, + { + let hw_vlan_insert_pvid: u8 = unsafe { + ::std::mem::transmute(hw_vlan_insert_pvid) + }; + hw_vlan_insert_pvid as u64 + }, + ); __bindgen_bitfield_unit } } -/// A structure used to configure the Receive Side Scaling (RSS) feature -/// of an Ethernet port. -/// If not NULL, the *rss_key* pointer of the *rss_conf* structure points -/// to an array holding the RSS key to use for hashing specific header -/// fields of received packets. The length of this array should be indicated -/// by *rss_key_len* below. Otherwise, a default random hash key is used by -/// the device driver. -/// -/// The *rss_key_len* field of the *rss_conf* structure indicates the length -/// in bytes of the array pointed by *rss_key*. To be compatible, this length -/// will be checked in i40e only. Others assume 40 bytes to be used as before. -/// -/// The *rss_hf* field of the *rss_conf* structure indicates the different -/// types of IPv4/IPv6 packets to which the RSS hashing must be applied. -/// Supplying an *rss_hf* equal to zero disables the RSS feature. +/** A structure used to configure the Receive Side Scaling (RSS) feature + of an Ethernet port. + If not NULL, the *rss_key* pointer of the *rss_conf* structure points + to an array holding the RSS key to use for hashing specific header + fields of received packets. The length of this array should be indicated + by *rss_key_len* below. Otherwise, a default random hash key is used by + the device driver. + + The *rss_key_len* field of the *rss_conf* structure indicates the length + in bytes of the array pointed by *rss_key*. To be compatible, this length + will be checked in i40e only. Others assume 40 bytes to be used as before. + + The *rss_hf* field of the *rss_conf* structure indicates the different + types of IPv4/IPv6 packets to which the RSS hashing must be applied. + Supplying an *rss_hf* equal to zero disables the RSS feature.*/ #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_eth_rss_conf { @@ -559,50 +558,30 @@ pub struct rte_eth_rss_conf { } #[test] fn bindgen_test_layout_rte_eth_rss_conf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 24usize, - concat!("Size of: ", stringify!(rte_eth_rss_conf)) + ::std::mem::size_of:: < rte_eth_rss_conf > (), 24usize, concat!("Size of: ", + stringify!(rte_eth_rss_conf)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(rte_eth_rss_conf)) + ::std::mem::align_of:: < rte_eth_rss_conf > (), 8usize, concat!("Alignment of ", + stringify!(rte_eth_rss_conf)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).rss_key) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rss_conf), - "::", - stringify!(rss_key) - ) + unsafe { ::std::ptr::addr_of!((* ptr).rss_key) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_eth_rss_conf), "::", + stringify!(rss_key)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).rss_key_len) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rss_conf), - "::", - stringify!(rss_key_len) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).rss_hf) as usize - ptr as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rss_conf), - "::", - stringify!(rss_hf) - ) + unsafe { ::std::ptr::addr_of!((* ptr).rss_key_len) as usize - ptr as usize }, + 8usize, concat!("Offset of field: ", stringify!(rte_eth_rss_conf), "::", + stringify!(rss_key_len)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).rss_hf) as usize - ptr as usize }, 16usize, + concat!("Offset of field: ", stringify!(rte_eth_rss_conf), "::", + stringify!(rss_hf)) ); } impl Default for rte_eth_rss_conf { @@ -615,8 +594,8 @@ impl Default for rte_eth_rss_conf { } } #[repr(u32)] -/// This enum indicates the possible number of traffic classes -/// in DCB configratioins +/** This enum indicates the possible number of traffic classes + in DCB configratioins*/ #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum rte_eth_nb_tcs { ///< 4 TCs with DCB. @@ -625,8 +604,8 @@ pub enum rte_eth_nb_tcs { ETH_8_TCS = 8, } #[repr(u32)] -/// This enum indicates the possible number of queue pools -/// in VMDQ configurations. +/** This enum indicates the possible number of queue pools + in VMDQ configurations.*/ #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum rte_eth_nb_pools { ///< 8 VMDq pools. @@ -638,15 +617,15 @@ pub enum rte_eth_nb_pools { ///< 64 VMDq pools. ETH_64_POOLS = 64, } -/// A structure used to configure the VMDQ+DCB feature -/// of an Ethernet port. -/// -/// Using this feature, packets are routed to a pool of queues, based -/// on the vlan ID in the vlan tag, and then to a specific queue within -/// that pool, using the user priority vlan tag field. -/// -/// A default pool may be used, if desired, to route all traffic which -/// does not match the vlan filter rules. +/** A structure used to configure the VMDQ+DCB feature + of an Ethernet port. + + Using this feature, packets are routed to a pool of queues, based + on the vlan ID in the vlan tag, and then to a specific queue within + that pool, using the user priority vlan tag field. + + 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)] pub struct rte_eth_vmdq_dcb_conf { @@ -672,128 +651,68 @@ pub struct rte_eth_vmdq_dcb_conf__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_eth_vmdq_dcb_conf__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 16usize, + ::std::mem::size_of:: < rte_eth_vmdq_dcb_conf__bindgen_ty_1 > (), 16usize, concat!("Size of: ", stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!( - "Alignment of ", - stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1) - ) + ::std::mem::align_of:: < rte_eth_vmdq_dcb_conf__bindgen_ty_1 > (), 8usize, + concat!("Alignment of ", stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).vlan_id) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1), - "::", - stringify!(vlan_id) - ) + unsafe { ::std::ptr::addr_of!((* ptr).vlan_id) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1), + "::", stringify!(vlan_id)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).pools) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1), - "::", - stringify!(pools) - ) + unsafe { ::std::ptr::addr_of!((* ptr).pools) as usize - ptr as usize }, 8usize, + concat!("Offset of field: ", stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1), + "::", stringify!(pools)) ); } #[test] fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 1040usize, + ::std::mem::size_of:: < rte_eth_vmdq_dcb_conf > (), 1040usize, concat!("Size of: ", stringify!(rte_eth_vmdq_dcb_conf)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, + ::std::mem::align_of:: < rte_eth_vmdq_dcb_conf > (), 8usize, concat!("Alignment of ", stringify!(rte_eth_vmdq_dcb_conf)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(nb_queue_pools) - ) + unsafe { ::std::ptr::addr_of!((* ptr).nb_queue_pools) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_dcb_conf), "::", + stringify!(nb_queue_pools)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).enable_default_pool) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(enable_default_pool) - ) + unsafe { ::std::ptr::addr_of!((* ptr).enable_default_pool) as usize - ptr as + usize }, 4usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_dcb_conf), + "::", stringify!(enable_default_pool)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).default_pool) as usize - ptr as usize - }, - 5usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(default_pool) - ) + unsafe { ::std::ptr::addr_of!((* ptr).default_pool) as usize - ptr as usize }, + 5usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_dcb_conf), "::", + stringify!(default_pool)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).nb_pool_maps) as usize - ptr as usize - }, - 6usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(nb_pool_maps) - ) + unsafe { ::std::ptr::addr_of!((* ptr).nb_pool_maps) as usize - ptr as usize }, + 6usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_dcb_conf), "::", + stringify!(nb_pool_maps)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).pool_map) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(pool_map) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize }, - 1032usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(dcb_tc) - ) + unsafe { ::std::ptr::addr_of!((* ptr).pool_map) as usize - ptr as usize }, + 8usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_dcb_conf), "::", + stringify!(pool_map)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).dcb_tc) as usize - ptr as usize }, + 1032usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_dcb_conf), "::", + stringify!(dcb_tc)) ); } impl Default for rte_eth_vmdq_dcb_conf { @@ -815,38 +734,25 @@ pub struct rte_eth_dcb_rx_conf { } #[test] fn bindgen_test_layout_rte_eth_dcb_rx_conf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 12usize, - concat!("Size of: ", stringify!(rte_eth_dcb_rx_conf)) + ::std::mem::size_of:: < rte_eth_dcb_rx_conf > (), 12usize, concat!("Size of: ", + stringify!(rte_eth_dcb_rx_conf)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < rte_eth_dcb_rx_conf > (), 4usize, concat!("Alignment of ", stringify!(rte_eth_dcb_rx_conf)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_dcb_rx_conf), - "::", - stringify!(nb_tcs) - ) + unsafe { ::std::ptr::addr_of!((* ptr).nb_tcs) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_eth_dcb_rx_conf), "::", + stringify!(nb_tcs)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_dcb_rx_conf), - "::", - stringify!(dcb_tc) - ) + unsafe { ::std::ptr::addr_of!((* ptr).dcb_tc) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(rte_eth_dcb_rx_conf), "::", + stringify!(dcb_tc)) ); } impl Default for rte_eth_dcb_rx_conf { @@ -868,40 +774,25 @@ pub struct rte_eth_vmdq_dcb_tx_conf { } #[test] fn bindgen_test_layout_rte_eth_vmdq_dcb_tx_conf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 12usize, + ::std::mem::size_of:: < rte_eth_vmdq_dcb_tx_conf > (), 12usize, concat!("Size of: ", stringify!(rte_eth_vmdq_dcb_tx_conf)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < rte_eth_vmdq_dcb_tx_conf > (), 4usize, concat!("Alignment of ", stringify!(rte_eth_vmdq_dcb_tx_conf)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_tx_conf), - "::", - stringify!(nb_queue_pools) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_tx_conf), - "::", - stringify!(dcb_tc) - ) + unsafe { ::std::ptr::addr_of!((* ptr).nb_queue_pools) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_dcb_tx_conf), "::", + stringify!(nb_queue_pools)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).dcb_tc) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(rte_eth_vmdq_dcb_tx_conf), "::", + stringify!(dcb_tc)) ); } impl Default for rte_eth_vmdq_dcb_tx_conf { @@ -923,38 +814,25 @@ pub struct rte_eth_dcb_tx_conf { } #[test] fn bindgen_test_layout_rte_eth_dcb_tx_conf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 12usize, - concat!("Size of: ", stringify!(rte_eth_dcb_tx_conf)) + ::std::mem::size_of:: < rte_eth_dcb_tx_conf > (), 12usize, concat!("Size of: ", + stringify!(rte_eth_dcb_tx_conf)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < rte_eth_dcb_tx_conf > (), 4usize, concat!("Alignment of ", stringify!(rte_eth_dcb_tx_conf)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_dcb_tx_conf), - "::", - stringify!(nb_tcs) - ) + unsafe { ::std::ptr::addr_of!((* ptr).nb_tcs) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_eth_dcb_tx_conf), "::", + stringify!(nb_tcs)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_dcb_tx_conf), - "::", - stringify!(dcb_tc) - ) + unsafe { ::std::ptr::addr_of!((* ptr).dcb_tc) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(rte_eth_dcb_tx_conf), "::", + stringify!(dcb_tc)) ); } impl Default for rte_eth_dcb_tx_conf { @@ -974,30 +852,20 @@ pub struct rte_eth_vmdq_tx_conf { } #[test] fn bindgen_test_layout_rte_eth_vmdq_tx_conf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(rte_eth_vmdq_tx_conf)) + ::std::mem::size_of:: < rte_eth_vmdq_tx_conf > (), 4usize, concat!("Size of: ", + stringify!(rte_eth_vmdq_tx_conf)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < rte_eth_vmdq_tx_conf > (), 4usize, concat!("Alignment of ", stringify!(rte_eth_vmdq_tx_conf)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_tx_conf), - "::", - stringify!(nb_queue_pools) - ) + unsafe { ::std::ptr::addr_of!((* ptr).nb_queue_pools) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_tx_conf), "::", + stringify!(nb_queue_pools)) ); } impl Default for rte_eth_vmdq_tx_conf { @@ -1037,141 +905,73 @@ pub struct rte_eth_vmdq_rx_conf__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_eth_vmdq_rx_conf__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 16usize, + ::std::mem::size_of:: < rte_eth_vmdq_rx_conf__bindgen_ty_1 > (), 16usize, concat!("Size of: ", stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!( - "Alignment of ", - stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1) - ) + ::std::mem::align_of:: < rte_eth_vmdq_rx_conf__bindgen_ty_1 > (), 8usize, + concat!("Alignment of ", stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).vlan_id) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1), - "::", - stringify!(vlan_id) - ) + unsafe { ::std::ptr::addr_of!((* ptr).vlan_id) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1), + "::", stringify!(vlan_id)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).pools) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1), - "::", - stringify!(pools) - ) + unsafe { ::std::ptr::addr_of!((* ptr).pools) as usize - ptr as usize }, 8usize, + concat!("Offset of field: ", stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1), + "::", stringify!(pools)) ); } #[test] fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 1040usize, + ::std::mem::size_of:: < rte_eth_vmdq_rx_conf > (), 1040usize, concat!("Size of: ", stringify!(rte_eth_vmdq_rx_conf)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, + ::std::mem::align_of:: < rte_eth_vmdq_rx_conf > (), 8usize, concat!("Alignment of ", stringify!(rte_eth_vmdq_rx_conf)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(nb_queue_pools) - ) + unsafe { ::std::ptr::addr_of!((* ptr).nb_queue_pools) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_rx_conf), "::", + stringify!(nb_queue_pools)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).enable_default_pool) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(enable_default_pool) - ) + unsafe { ::std::ptr::addr_of!((* ptr).enable_default_pool) as usize - ptr as + usize }, 4usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_rx_conf), + "::", stringify!(enable_default_pool)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).default_pool) as usize - ptr as usize - }, - 5usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(default_pool) - ) + unsafe { ::std::ptr::addr_of!((* ptr).default_pool) as usize - ptr as usize }, + 5usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_rx_conf), "::", + stringify!(default_pool)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).enable_loop_back) as usize - - ptr as usize - }, - 6usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(enable_loop_back) - ) + unsafe { ::std::ptr::addr_of!((* ptr).enable_loop_back) as usize - ptr as usize + }, 6usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_rx_conf), "::", + stringify!(enable_loop_back)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).nb_pool_maps) as usize - ptr as usize - }, - 7usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(nb_pool_maps) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).rx_mode) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(rx_mode) - ) + unsafe { ::std::ptr::addr_of!((* ptr).nb_pool_maps) as usize - ptr as usize }, + 7usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_rx_conf), "::", + stringify!(nb_pool_maps)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).pool_map) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(pool_map) - ) + unsafe { ::std::ptr::addr_of!((* ptr).rx_mode) as usize - ptr as usize }, 8usize, + concat!("Offset of field: ", stringify!(rte_eth_vmdq_rx_conf), "::", + stringify!(rx_mode)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).pool_map) as usize - ptr as usize }, + 16usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_rx_conf), "::", + stringify!(pool_map)) ); } impl Default for rte_eth_vmdq_rx_conf { @@ -1199,8 +999,8 @@ pub enum rte_fdir_mode { RTE_FDIR_MODE_PERFECT_TUNNEL = 4, } #[repr(u32)] -/// Memory space that can be configured to store Flow Director filters -/// in the board memory. +/** Memory space that can be configured to store Flow Director filters + in the board memory.*/ #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum rte_fdir_pballoc_type { ///< 64k. @@ -1238,68 +1038,40 @@ pub struct rte_eth_ipv4_flow { } #[test] fn bindgen_test_layout_rte_eth_ipv4_flow() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 12usize, - concat!("Size of: ", stringify!(rte_eth_ipv4_flow)) + ::std::mem::size_of:: < rte_eth_ipv4_flow > (), 12usize, concat!("Size of: ", + stringify!(rte_eth_ipv4_flow)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(rte_eth_ipv4_flow)) + ::std::mem::align_of:: < rte_eth_ipv4_flow > (), 4usize, concat!("Alignment of ", + stringify!(rte_eth_ipv4_flow)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(src_ip) - ) + unsafe { ::std::ptr::addr_of!((* ptr).src_ip) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_eth_ipv4_flow), "::", + stringify!(src_ip)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dst_ip) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(dst_ip) - ) + unsafe { ::std::ptr::addr_of!((* ptr).dst_ip) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(rte_eth_ipv4_flow), "::", + stringify!(dst_ip)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).tos) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(tos) - ) + unsafe { ::std::ptr::addr_of!((* ptr).tos) as usize - ptr as usize }, 8usize, + concat!("Offset of field: ", stringify!(rte_eth_ipv4_flow), "::", + stringify!(tos)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ttl) as usize - ptr as usize }, - 9usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(ttl) - ) + unsafe { ::std::ptr::addr_of!((* ptr).ttl) as usize - ptr as usize }, 9usize, + concat!("Offset of field: ", stringify!(rte_eth_ipv4_flow), "::", + stringify!(ttl)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize }, - 10usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(proto) - ) + unsafe { ::std::ptr::addr_of!((* ptr).proto) as usize - ptr as usize }, 10usize, + concat!("Offset of field: ", stringify!(rte_eth_ipv4_flow), "::", + stringify!(proto)) ); } /// A structure used to define the input for IPV6 flow @@ -1319,74 +1091,43 @@ pub struct rte_eth_ipv6_flow { } #[test] fn bindgen_test_layout_rte_eth_ipv6_flow() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 36usize, - concat!("Size of: ", stringify!(rte_eth_ipv6_flow)) + ::std::mem::size_of:: < rte_eth_ipv6_flow > (), 36usize, concat!("Size of: ", + stringify!(rte_eth_ipv6_flow)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(rte_eth_ipv6_flow)) + ::std::mem::align_of:: < rte_eth_ipv6_flow > (), 4usize, concat!("Alignment of ", + stringify!(rte_eth_ipv6_flow)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(src_ip) - ) + unsafe { ::std::ptr::addr_of!((* ptr).src_ip) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_eth_ipv6_flow), "::", + stringify!(src_ip)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dst_ip) as usize - ptr as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(dst_ip) - ) + unsafe { ::std::ptr::addr_of!((* ptr).dst_ip) as usize - ptr as usize }, 16usize, + concat!("Offset of field: ", stringify!(rte_eth_ipv6_flow), "::", + stringify!(dst_ip)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).tc) as usize - ptr as usize }, - 32usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(tc) - ) + unsafe { ::std::ptr::addr_of!((* ptr).tc) as usize - ptr as usize }, 32usize, + concat!("Offset of field: ", stringify!(rte_eth_ipv6_flow), "::", stringify!(tc)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize }, - 33usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(proto) - ) + unsafe { ::std::ptr::addr_of!((* ptr).proto) as usize - ptr as usize }, 33usize, + concat!("Offset of field: ", stringify!(rte_eth_ipv6_flow), "::", + stringify!(proto)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).hop_limits) as usize - ptr as usize - }, - 34usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(hop_limits) - ) - ); -} -/// A structure used to configure FDIR masks that are used by the device -/// to match the various fields of RX packet headers. + unsafe { ::std::ptr::addr_of!((* ptr).hop_limits) as usize - ptr as usize }, + 34usize, concat!("Offset of field: ", stringify!(rte_eth_ipv6_flow), "::", + stringify!(hop_limits)) + ); +} +/** A structure used to configure FDIR masks that are used by the device + to match the various fields of RX packet headers.*/ #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_eth_fdir_masks { @@ -1400,127 +1141,66 @@ pub struct rte_eth_fdir_masks { pub src_port_mask: u16, /// Bit mask for L4 destination port in big endian. pub dst_port_mask: u16, - /// 6 bit mask for proper 6 bytes of Mac address, bit 0 matches the - ///first byte on the wire + /** 6 bit mask for proper 6 bytes of Mac address, bit 0 matches the +first byte on the wire*/ pub mac_addr_byte_mask: u8, /// Bit mask for tunnel ID in big endian. pub tunnel_id_mask: u32, - ///< 1 - Match tunnel type, - ///0 - Ignore tunnel type. + /**< 1 - Match tunnel type, +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(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 68usize, - concat!("Size of: ", stringify!(rte_eth_fdir_masks)) + ::std::mem::size_of:: < rte_eth_fdir_masks > (), 68usize, concat!("Size of: ", + stringify!(rte_eth_fdir_masks)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < rte_eth_fdir_masks > (), 4usize, concat!("Alignment of ", stringify!(rte_eth_fdir_masks)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).vlan_tci_mask) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(vlan_tci_mask) - ) + unsafe { ::std::ptr::addr_of!((* ptr).vlan_tci_mask) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_masks), "::", + stringify!(vlan_tci_mask)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).ipv4_mask) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(ipv4_mask) - ) + unsafe { ::std::ptr::addr_of!((* ptr).ipv4_mask) as usize - ptr as usize }, + 4usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_masks), "::", + stringify!(ipv4_mask)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).ipv6_mask) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(ipv6_mask) - ) + unsafe { ::std::ptr::addr_of!((* ptr).ipv6_mask) as usize - ptr as usize }, + 16usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_masks), "::", + stringify!(ipv6_mask)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).src_port_mask) as usize - ptr as usize - }, - 52usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(src_port_mask) - ) + unsafe { ::std::ptr::addr_of!((* ptr).src_port_mask) as usize - ptr as usize }, + 52usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_masks), "::", + stringify!(src_port_mask)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).dst_port_mask) as usize - ptr as usize - }, - 54usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(dst_port_mask) - ) + unsafe { ::std::ptr::addr_of!((* ptr).dst_port_mask) as usize - ptr as usize }, + 54usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_masks), "::", + stringify!(dst_port_mask)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mac_addr_byte_mask) as usize - - ptr as usize - }, - 56usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(mac_addr_byte_mask) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mac_addr_byte_mask) as usize - ptr as usize + }, 56usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_masks), "::", + stringify!(mac_addr_byte_mask)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).tunnel_id_mask) as usize - ptr as usize - }, - 60usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(tunnel_id_mask) - ) + unsafe { ::std::ptr::addr_of!((* ptr).tunnel_id_mask) as usize - ptr as usize }, + 60usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_masks), "::", + stringify!(tunnel_id_mask)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).tunnel_type_mask) as usize - - ptr as usize - }, - 64usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(tunnel_type_mask) - ) + unsafe { ::std::ptr::addr_of!((* ptr).tunnel_type_mask) as usize - ptr as usize + }, 64usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_masks), "::", + stringify!(tunnel_type_mask)) ); } #[repr(u32)] @@ -1534,8 +1214,8 @@ pub enum rte_eth_payload_type { RTE_ETH_L4_PAYLOAD = 4, RTE_ETH_PAYLOAD_MAX = 8, } -/// A structure used to select bytes extracted from the protocol layers to -/// flexible payload for filter +/** A structure used to select bytes extracted from the protocol layers to + flexible payload for filter*/ #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_eth_flex_payload_cfg { @@ -1545,40 +1225,25 @@ pub struct rte_eth_flex_payload_cfg { } #[test] fn bindgen_test_layout_rte_eth_flex_payload_cfg() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 36usize, + ::std::mem::size_of:: < rte_eth_flex_payload_cfg > (), 36usize, concat!("Size of: ", stringify!(rte_eth_flex_payload_cfg)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < rte_eth_flex_payload_cfg > (), 4usize, concat!("Alignment of ", stringify!(rte_eth_flex_payload_cfg)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_flex_payload_cfg), - "::", - stringify!(type_) - ) + unsafe { ::std::ptr::addr_of!((* ptr).type_) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_eth_flex_payload_cfg), "::", + stringify!(type_)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).src_offset) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_flex_payload_cfg), - "::", - stringify!(src_offset) - ) + unsafe { ::std::ptr::addr_of!((* ptr).src_offset) as usize - ptr as usize }, + 4usize, concat!("Offset of field: ", stringify!(rte_eth_flex_payload_cfg), "::", + stringify!(src_offset)) ); } impl Default for rte_eth_flex_payload_cfg { @@ -1590,8 +1255,8 @@ impl Default for rte_eth_flex_payload_cfg { } } } -/// A structure used to define FDIR masks for flexible payload -/// for each flow type +/** A structure used to define FDIR masks for flexible payload + for each flow type*/ #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_eth_fdir_flex_mask { @@ -1600,44 +1265,29 @@ pub struct rte_eth_fdir_flex_mask { } #[test] fn bindgen_test_layout_rte_eth_fdir_flex_mask() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 18usize, + ::std::mem::size_of:: < rte_eth_fdir_flex_mask > (), 18usize, concat!("Size of: ", stringify!(rte_eth_fdir_flex_mask)) ); assert_eq!( - ::std::mem::align_of::(), - 2usize, + ::std::mem::align_of:: < rte_eth_fdir_flex_mask > (), 2usize, concat!("Alignment of ", stringify!(rte_eth_fdir_flex_mask)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).flow_type) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_mask), - "::", - stringify!(flow_type) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_mask), - "::", - stringify!(mask) - ) - ); -} -/// A structure used to define all flexible payload related setting -/// include flex payload and flex mask + unsafe { ::std::ptr::addr_of!((* ptr).flow_type) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_flex_mask), "::", + stringify!(flow_type)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).mask) as usize - ptr as usize }, 2usize, + concat!("Offset of field: ", stringify!(rte_eth_fdir_flex_mask), "::", + stringify!(mask)) + ); +} +/** A structure used to define all flexible payload related setting + include flex payload and flex mask*/ #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_eth_fdir_flex_conf { @@ -1650,66 +1300,35 @@ pub struct rte_eth_fdir_flex_conf { } #[test] fn bindgen_test_layout_rte_eth_fdir_flex_conf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 688usize, + ::std::mem::size_of:: < rte_eth_fdir_flex_conf > (), 688usize, concat!("Size of: ", stringify!(rte_eth_fdir_flex_conf)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < rte_eth_fdir_flex_conf > (), 4usize, concat!("Alignment of ", stringify!(rte_eth_fdir_flex_conf)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).nb_payloads) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_conf), - "::", - stringify!(nb_payloads) - ) + unsafe { ::std::ptr::addr_of!((* ptr).nb_payloads) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_flex_conf), "::", + stringify!(nb_payloads)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).nb_flexmasks) as usize - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_conf), - "::", - stringify!(nb_flexmasks) - ) + unsafe { ::std::ptr::addr_of!((* ptr).nb_flexmasks) as usize - ptr as usize }, + 2usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_flex_conf), "::", + stringify!(nb_flexmasks)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).flex_set) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_conf), - "::", - stringify!(flex_set) - ) + unsafe { ::std::ptr::addr_of!((* ptr).flex_set) as usize - ptr as usize }, + 4usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_flex_conf), "::", + stringify!(flex_set)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).flex_mask) as usize - ptr as usize - }, - 292usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_conf), - "::", - stringify!(flex_mask) - ) + unsafe { ::std::ptr::addr_of!((* ptr).flex_mask) as usize - ptr as usize }, + 292usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_flex_conf), "::", + stringify!(flex_mask)) ); } impl Default for rte_eth_fdir_flex_conf { @@ -1721,10 +1340,10 @@ impl Default for rte_eth_fdir_flex_conf { } } } -/// A structure used to configure the Flow Director (FDIR) feature -/// of an Ethernet port. -/// -/// If mode is RTE_FDIR_DISABLE, the pballoc value is ignored. +/** A structure used to configure the Flow Director (FDIR) feature + of an Ethernet port. + + If mode is RTE_FDIR_DISABLE, the pballoc value is ignored.*/ #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_fdir_conf { @@ -1741,82 +1360,42 @@ pub struct rte_fdir_conf { } #[test] fn bindgen_test_layout_rte_fdir_conf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 772usize, - concat!("Size of: ", stringify!(rte_fdir_conf)) + ::std::mem::size_of:: < rte_fdir_conf > (), 772usize, concat!("Size of: ", + stringify!(rte_fdir_conf)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(rte_fdir_conf)) + ::std::mem::align_of:: < rte_fdir_conf > (), 4usize, concat!("Alignment of ", + stringify!(rte_fdir_conf)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mode) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(mode) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mode) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_fdir_conf), "::", stringify!(mode)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).pballoc) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(pballoc) - ) + unsafe { ::std::ptr::addr_of!((* ptr).pballoc) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(rte_fdir_conf), "::", + stringify!(pballoc)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).status) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(status) - ) + unsafe { ::std::ptr::addr_of!((* ptr).status) as usize - ptr as usize }, 8usize, + concat!("Offset of field: ", stringify!(rte_fdir_conf), "::", stringify!(status)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).drop_queue) as usize - ptr as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(drop_queue) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(mask) - ) + unsafe { ::std::ptr::addr_of!((* ptr).drop_queue) as usize - ptr as usize }, + 12usize, concat!("Offset of field: ", stringify!(rte_fdir_conf), "::", + stringify!(drop_queue)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).flex_conf) as usize - ptr as usize - }, - 84usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(flex_conf) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mask) as usize - ptr as usize }, 16usize, + concat!("Offset of field: ", stringify!(rte_fdir_conf), "::", stringify!(mask)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).flex_conf) as usize - ptr as usize }, + 84usize, concat!("Offset of field: ", stringify!(rte_fdir_conf), "::", + stringify!(flex_conf)) ); } impl Default for rte_fdir_conf { @@ -1839,70 +1418,55 @@ pub struct rte_intr_conf { } #[test] fn bindgen_test_layout_rte_intr_conf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(rte_intr_conf)) + ::std::mem::size_of:: < rte_intr_conf > (), 4usize, concat!("Size of: ", + stringify!(rte_intr_conf)) ); assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(rte_intr_conf)) + ::std::mem::align_of:: < rte_intr_conf > (), 2usize, concat!("Alignment of ", + stringify!(rte_intr_conf)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).lsc) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_intr_conf), - "::", - stringify!(lsc) - ) + unsafe { ::std::ptr::addr_of!((* ptr).lsc) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_intr_conf), "::", stringify!(lsc)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).rxq) as usize - ptr as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(rte_intr_conf), - "::", - stringify!(rxq) - ) + unsafe { ::std::ptr::addr_of!((* ptr).rxq) as usize - ptr as usize }, 2usize, + concat!("Offset of field: ", stringify!(rte_intr_conf), "::", stringify!(rxq)) ); } -/// A structure used to configure an Ethernet port. -/// Depending upon the RX multi-queue mode, extra advanced -/// configuration settings may be needed. +/** A structure used to configure an Ethernet port. + Depending upon the RX multi-queue mode, extra advanced + configuration settings may be needed.*/ #[repr(C)] #[derive(Copy, Clone)] pub struct rte_eth_conf { - ///< bitmap of ETH_LINK_SPEED_XXX of speeds to be - ///used. ETH_LINK_SPEED_FIXED disables link - ///autonegotiation, and a unique speed shall be - ///set. Otherwise, the bitmap defines the set of - ///speeds to be advertised. If the special value - ///ETH_LINK_SPEED_AUTONEG (0) is used, all speeds - ///supported are advertised. + /**< bitmap of ETH_LINK_SPEED_XXX of speeds to be +used. ETH_LINK_SPEED_FIXED disables link +autonegotiation, and a unique speed shall be +set. Otherwise, the bitmap defines the set of +speeds to be advertised. If the special value +ETH_LINK_SPEED_AUTONEG (0) is used, all speeds +supported are advertised.*/ pub link_speeds: u32, ///< Port RX configuration. pub rxmode: rte_eth_rxmode, ///< Port TX configuration. pub txmode: rte_eth_txmode, - ///< Loopback operation mode. By default the value - ///is 0, meaning the loopback mode is disabled. - ///Read the datasheet of given ethernet controller - ///for details. The possible values of this field - ///are defined in implementation of each driver. + /**< Loopback operation mode. By default the value +is 0, meaning the loopback mode is disabled. +Read the datasheet of given ethernet controller +for details. The possible values of this field +are defined in implementation of each driver.*/ pub lpbk_mode: u32, ///< Port RX filtering configuration (union). pub rx_adv_conf: rte_eth_conf__bindgen_ty_1, ///< Port TX DCB configuration (union). pub tx_adv_conf: rte_eth_conf__bindgen_ty_2, - /// Currently,Priority Flow Control(PFC) are supported,if DCB with PFC - ///is needed,and the variable must be set ETH_DCB_PFC_SUPPORT. + /** Currently,Priority Flow Control(PFC) are supported,if DCB with PFC +is needed,and the variable must be set ETH_DCB_PFC_SUPPORT.*/ pub dcb_capability_en: u32, ///< FDIR configuration. pub fdir_conf: rte_fdir_conf, @@ -1920,66 +1484,35 @@ pub struct rte_eth_conf__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_eth_conf__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 2120usize, + ::std::mem::size_of:: < rte_eth_conf__bindgen_ty_1 > (), 2120usize, concat!("Size of: ", stringify!(rte_eth_conf__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, + ::std::mem::align_of:: < rte_eth_conf__bindgen_ty_1 > (), 8usize, concat!("Alignment of ", stringify!(rte_eth_conf__bindgen_ty_1)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).rss_conf) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_1), - "::", - stringify!(rss_conf) - ) + unsafe { ::std::ptr::addr_of!((* ptr).rss_conf) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_eth_conf__bindgen_ty_1), + "::", stringify!(rss_conf)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).vmdq_dcb_conf) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_1), - "::", - stringify!(vmdq_dcb_conf) - ) + unsafe { ::std::ptr::addr_of!((* ptr).vmdq_dcb_conf) as usize - ptr as usize }, + 24usize, concat!("Offset of field: ", stringify!(rte_eth_conf__bindgen_ty_1), + "::", stringify!(vmdq_dcb_conf)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).dcb_rx_conf) as usize - ptr as usize - }, - 1064usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_1), - "::", - stringify!(dcb_rx_conf) - ) + unsafe { ::std::ptr::addr_of!((* ptr).dcb_rx_conf) as usize - ptr as usize }, + 1064usize, concat!("Offset of field: ", stringify!(rte_eth_conf__bindgen_ty_1), + "::", stringify!(dcb_rx_conf)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).vmdq_rx_conf) as usize - ptr as usize - }, - 1080usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_1), - "::", - stringify!(vmdq_rx_conf) - ) + unsafe { ::std::ptr::addr_of!((* ptr).vmdq_rx_conf) as usize - ptr as usize }, + 1080usize, concat!("Offset of field: ", stringify!(rte_eth_conf__bindgen_ty_1), + "::", stringify!(vmdq_rx_conf)) ); } impl Default for rte_eth_conf__bindgen_ty_1 { @@ -2000,55 +1533,30 @@ pub union rte_eth_conf__bindgen_ty_2 { } #[test] fn bindgen_test_layout_rte_eth_conf__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 12usize, + ::std::mem::size_of:: < rte_eth_conf__bindgen_ty_2 > (), 12usize, concat!("Size of: ", stringify!(rte_eth_conf__bindgen_ty_2)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < rte_eth_conf__bindgen_ty_2 > (), 4usize, concat!("Alignment of ", stringify!(rte_eth_conf__bindgen_ty_2)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).vmdq_dcb_tx_conf) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_2), - "::", - stringify!(vmdq_dcb_tx_conf) - ) + unsafe { ::std::ptr::addr_of!((* ptr).vmdq_dcb_tx_conf) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(rte_eth_conf__bindgen_ty_2), + "::", stringify!(vmdq_dcb_tx_conf)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).dcb_tx_conf) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_2), - "::", - stringify!(dcb_tx_conf) - ) + unsafe { ::std::ptr::addr_of!((* ptr).dcb_tx_conf) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_eth_conf__bindgen_ty_2), + "::", stringify!(dcb_tx_conf)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).vmdq_tx_conf) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_2), - "::", - stringify!(vmdq_tx_conf) - ) + unsafe { ::std::ptr::addr_of!((* ptr).vmdq_tx_conf) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_eth_conf__bindgen_ty_2), + "::", stringify!(vmdq_tx_conf)) ); } impl Default for rte_eth_conf__bindgen_ty_2 { @@ -2062,123 +1570,58 @@ 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(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 2944usize, - concat!("Size of: ", stringify!(rte_eth_conf)) + ::std::mem::size_of:: < rte_eth_conf > (), 2944usize, concat!("Size of: ", + stringify!(rte_eth_conf)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(rte_eth_conf)) + ::std::mem::align_of:: < rte_eth_conf > (), 8usize, concat!("Alignment of ", + stringify!(rte_eth_conf)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).link_speeds) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(link_speeds) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).rxmode) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(rxmode) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).txmode) as usize - ptr as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(txmode) - ) + unsafe { ::std::ptr::addr_of!((* ptr).link_speeds) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_eth_conf), "::", + stringify!(link_speeds)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).lpbk_mode) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(lpbk_mode) - ) + unsafe { ::std::ptr::addr_of!((* ptr).rxmode) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(rte_eth_conf), "::", stringify!(rxmode)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).rx_adv_conf) as usize - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(rx_adv_conf) - ) + unsafe { ::std::ptr::addr_of!((* ptr).txmode) as usize - ptr as usize }, 16usize, + concat!("Offset of field: ", stringify!(rte_eth_conf), "::", stringify!(txmode)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).tx_adv_conf) as usize - ptr as usize - }, - 2152usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(tx_adv_conf) - ) + unsafe { ::std::ptr::addr_of!((* ptr).lpbk_mode) as usize - ptr as usize }, + 24usize, concat!("Offset of field: ", stringify!(rte_eth_conf), "::", + stringify!(lpbk_mode)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).dcb_capability_en) as usize - - ptr as usize - }, - 2164usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(dcb_capability_en) - ) + unsafe { ::std::ptr::addr_of!((* ptr).rx_adv_conf) as usize - ptr as usize }, + 32usize, concat!("Offset of field: ", stringify!(rte_eth_conf), "::", + stringify!(rx_adv_conf)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).fdir_conf) as usize - ptr as usize - }, - 2168usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(fdir_conf) - ) + unsafe { ::std::ptr::addr_of!((* ptr).tx_adv_conf) as usize - ptr as usize }, + 2152usize, concat!("Offset of field: ", stringify!(rte_eth_conf), "::", + stringify!(tx_adv_conf)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).intr_conf) as usize - ptr as usize - }, - 2940usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(intr_conf) - ) + unsafe { ::std::ptr::addr_of!((* ptr).dcb_capability_en) as usize - ptr as usize + }, 2164usize, concat!("Offset of field: ", stringify!(rte_eth_conf), "::", + stringify!(dcb_capability_en)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).fdir_conf) as usize - ptr as usize }, + 2168usize, concat!("Offset of field: ", stringify!(rte_eth_conf), "::", + stringify!(fdir_conf)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).intr_conf) as usize - ptr as usize }, + 2940usize, concat!("Offset of field: ", stringify!(rte_eth_conf), "::", + stringify!(intr_conf)) ); } impl Default for rte_eth_conf { diff --git a/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs b/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs index 1ffb508d5d..086384c450 100644 --- a/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -167,8 +159,8 @@ pub const RTE_ETH_FLOW_GENEVE: u32 = 20; pub const RTE_ETH_FLOW_NVGRE: u32 = 21; pub const RTE_ETH_FLOW_MAX: u32 = 22; #[repr(u32)] -/// A set of values to identify what method is to be used to route -/// packets to multiple queues. +/** A set of values to identify what method is to be used to route + packets to multiple queues.*/ #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum rte_eth_rx_mq_mode { /// None of DCB,RSS or VMDQ mode @@ -203,52 +195,30 @@ pub struct rte_eth_rxmode { } #[test] fn bindgen_test_layout_rte_eth_rxmode() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 12usize, - concat!("Size of: ", stringify!(rte_eth_rxmode)) + ::std::mem::size_of:: < rte_eth_rxmode > (), 12usize, concat!("Size of: ", + stringify!(rte_eth_rxmode)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(rte_eth_rxmode)) + ::std::mem::align_of:: < rte_eth_rxmode > (), 4usize, concat!("Alignment of ", + stringify!(rte_eth_rxmode)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mq_mode) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rxmode), - "::", - stringify!(mq_mode) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mq_mode) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_eth_rxmode), "::", + stringify!(mq_mode)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).max_rx_pkt_len) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rxmode), - "::", - stringify!(max_rx_pkt_len) - ) + unsafe { ::std::ptr::addr_of!((* ptr).max_rx_pkt_len) as usize - ptr as usize }, + 4usize, concat!("Offset of field: ", stringify!(rte_eth_rxmode), "::", + stringify!(max_rx_pkt_len)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).split_hdr_size) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rxmode), - "::", - stringify!(split_hdr_size) - ) + unsafe { ::std::ptr::addr_of!((* ptr).split_hdr_size) as usize - ptr as usize }, + 8usize, concat!("Offset of field: ", stringify!(rte_eth_rxmode), "::", + stringify!(split_hdr_size)) ); } impl Clone for rte_eth_rxmode { @@ -268,9 +238,7 @@ impl Default for rte_eth_rxmode { impl rte_eth_rxmode { #[inline] pub fn header_split(&self) -> u16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u16) } } #[inline] pub fn set_header_split(&mut self, val: u16) { @@ -281,9 +249,7 @@ impl rte_eth_rxmode { } #[inline] pub fn hw_ip_checksum(&self) -> u16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u16) } } #[inline] pub fn set_hw_ip_checksum(&mut self, val: u16) { @@ -294,9 +260,7 @@ impl rte_eth_rxmode { } #[inline] pub fn hw_vlan_filter(&self) -> u16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u16) } } #[inline] pub fn set_hw_vlan_filter(&mut self, val: u16) { @@ -307,9 +271,7 @@ impl rte_eth_rxmode { } #[inline] pub fn hw_vlan_strip(&self) -> u16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(3usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(3usize, 1u8) as u16) } } #[inline] pub fn set_hw_vlan_strip(&mut self, val: u16) { @@ -320,9 +282,7 @@ impl rte_eth_rxmode { } #[inline] pub fn hw_vlan_extend(&self) -> u16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(4usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(4usize, 1u8) as u16) } } #[inline] pub fn set_hw_vlan_extend(&mut self, val: u16) { @@ -333,9 +293,7 @@ impl rte_eth_rxmode { } #[inline] pub fn jumbo_frame(&self) -> u16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(5usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(5usize, 1u8) as u16) } } #[inline] pub fn set_jumbo_frame(&mut self, val: u16) { @@ -346,9 +304,7 @@ impl rte_eth_rxmode { } #[inline] pub fn hw_strip_crc(&self) -> u16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(6usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(6usize, 1u8) as u16) } } #[inline] pub fn set_hw_strip_crc(&mut self, val: u16) { @@ -359,9 +315,7 @@ impl rte_eth_rxmode { } #[inline] pub fn enable_scatter(&self) -> u16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(7usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(7usize, 1u8) as u16) } } #[inline] pub fn set_enable_scatter(&mut self, val: u16) { @@ -372,9 +326,7 @@ impl rte_eth_rxmode { } #[inline] pub fn enable_lro(&self) -> u16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(8usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(8usize, 1u8) as u16) } } #[inline] pub fn set_enable_lro(&mut self, val: u16) { @@ -395,58 +347,108 @@ impl rte_eth_rxmode { enable_scatter: u16, enable_lro: u16, ) -> __BindgenBitfieldUnit<[u8; 2usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 2usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 1u8, { - let header_split: u16 = - unsafe { ::std::mem::transmute(header_split) }; - header_split as u64 - }); - __bindgen_bitfield_unit.set(1usize, 1u8, { - let hw_ip_checksum: u16 = - unsafe { ::std::mem::transmute(hw_ip_checksum) }; - hw_ip_checksum as u64 - }); - __bindgen_bitfield_unit.set(2usize, 1u8, { - let hw_vlan_filter: u16 = - unsafe { ::std::mem::transmute(hw_vlan_filter) }; - hw_vlan_filter as u64 - }); - __bindgen_bitfield_unit.set(3usize, 1u8, { - let hw_vlan_strip: u16 = - unsafe { ::std::mem::transmute(hw_vlan_strip) }; - hw_vlan_strip as u64 - }); - __bindgen_bitfield_unit.set(4usize, 1u8, { - let hw_vlan_extend: u16 = - unsafe { ::std::mem::transmute(hw_vlan_extend) }; - hw_vlan_extend as u64 - }); - __bindgen_bitfield_unit.set(5usize, 1u8, { - let jumbo_frame: u16 = - unsafe { ::std::mem::transmute(jumbo_frame) }; - jumbo_frame as u64 - }); - __bindgen_bitfield_unit.set(6usize, 1u8, { - let hw_strip_crc: u16 = - unsafe { ::std::mem::transmute(hw_strip_crc) }; - hw_strip_crc as u64 - }); - __bindgen_bitfield_unit.set(7usize, 1u8, { - let enable_scatter: u16 = - unsafe { ::std::mem::transmute(enable_scatter) }; - enable_scatter as u64 - }); - __bindgen_bitfield_unit.set(8usize, 1u8, { - let enable_lro: u16 = unsafe { ::std::mem::transmute(enable_lro) }; - enable_lro as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 2usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let header_split: u16 = unsafe { + ::std::mem::transmute(header_split) + }; + header_split as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 1usize, + 1u8, + { + let hw_ip_checksum: u16 = unsafe { + ::std::mem::transmute(hw_ip_checksum) + }; + hw_ip_checksum as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 2usize, + 1u8, + { + let hw_vlan_filter: u16 = unsafe { + ::std::mem::transmute(hw_vlan_filter) + }; + hw_vlan_filter as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 3usize, + 1u8, + { + let hw_vlan_strip: u16 = unsafe { + ::std::mem::transmute(hw_vlan_strip) + }; + hw_vlan_strip as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 4usize, + 1u8, + { + let hw_vlan_extend: u16 = unsafe { + ::std::mem::transmute(hw_vlan_extend) + }; + hw_vlan_extend as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 5usize, + 1u8, + { + let jumbo_frame: u16 = unsafe { ::std::mem::transmute(jumbo_frame) }; + jumbo_frame as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 6usize, + 1u8, + { + let hw_strip_crc: u16 = unsafe { + ::std::mem::transmute(hw_strip_crc) + }; + hw_strip_crc as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 7usize, + 1u8, + { + let enable_scatter: u16 = unsafe { + ::std::mem::transmute(enable_scatter) + }; + enable_scatter as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 8usize, + 1u8, + { + let enable_lro: u16 = unsafe { ::std::mem::transmute(enable_lro) }; + enable_lro as u64 + }, + ); __bindgen_bitfield_unit } } #[repr(u32)] -/// A set of values to identify what method is to be used to transmit -/// packets using multi-TCs. +/** A set of values to identify what method is to be used to transmit + packets using multi-TCs.*/ #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum rte_eth_tx_mq_mode { ///< It is in neither DCB nor VT mode. @@ -471,38 +473,24 @@ pub struct rte_eth_txmode { } #[test] fn bindgen_test_layout_rte_eth_txmode() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(rte_eth_txmode)) + ::std::mem::size_of:: < rte_eth_txmode > (), 8usize, concat!("Size of: ", + stringify!(rte_eth_txmode)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(rte_eth_txmode)) + ::std::mem::align_of:: < rte_eth_txmode > (), 4usize, concat!("Alignment of ", + stringify!(rte_eth_txmode)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mq_mode) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_txmode), - "::", - stringify!(mq_mode) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mq_mode) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_eth_txmode), "::", + stringify!(mq_mode)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).pvid) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_txmode), - "::", - stringify!(pvid) - ) + unsafe { ::std::ptr::addr_of!((* ptr).pvid) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(rte_eth_txmode), "::", stringify!(pvid)) ); } impl Clone for rte_eth_txmode { @@ -522,9 +510,7 @@ impl Default for rte_eth_txmode { impl rte_eth_txmode { #[inline] pub fn hw_vlan_reject_tagged(&self) -> u8 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) } } #[inline] pub fn set_hw_vlan_reject_tagged(&mut self, val: u8) { @@ -535,9 +521,7 @@ impl rte_eth_txmode { } #[inline] pub fn hw_vlan_reject_untagged(&self) -> u8 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u8) } } #[inline] pub fn set_hw_vlan_reject_untagged(&mut self, val: u8) { @@ -548,9 +532,7 @@ impl rte_eth_txmode { } #[inline] pub fn hw_vlan_insert_pvid(&self) -> u8 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u8) } } #[inline] pub fn set_hw_vlan_insert_pvid(&mut self, val: u8) { @@ -565,41 +547,58 @@ impl rte_eth_txmode { hw_vlan_reject_untagged: u8, hw_vlan_insert_pvid: u8, ) -> __BindgenBitfieldUnit<[u8; 1usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 1u8, { - let hw_vlan_reject_tagged: u8 = - unsafe { ::std::mem::transmute(hw_vlan_reject_tagged) }; - hw_vlan_reject_tagged as u64 - }); - __bindgen_bitfield_unit.set(1usize, 1u8, { - let hw_vlan_reject_untagged: u8 = - unsafe { ::std::mem::transmute(hw_vlan_reject_untagged) }; - hw_vlan_reject_untagged as u64 - }); - __bindgen_bitfield_unit.set(2usize, 1u8, { - let hw_vlan_insert_pvid: u8 = - unsafe { ::std::mem::transmute(hw_vlan_insert_pvid) }; - hw_vlan_insert_pvid as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let hw_vlan_reject_tagged: u8 = unsafe { + ::std::mem::transmute(hw_vlan_reject_tagged) + }; + hw_vlan_reject_tagged as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 1usize, + 1u8, + { + let hw_vlan_reject_untagged: u8 = unsafe { + ::std::mem::transmute(hw_vlan_reject_untagged) + }; + hw_vlan_reject_untagged as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 2usize, + 1u8, + { + let hw_vlan_insert_pvid: u8 = unsafe { + ::std::mem::transmute(hw_vlan_insert_pvid) + }; + hw_vlan_insert_pvid as u64 + }, + ); __bindgen_bitfield_unit } } -/// A structure used to configure the Receive Side Scaling (RSS) feature -/// of an Ethernet port. -/// If not NULL, the *rss_key* pointer of the *rss_conf* structure points -/// to an array holding the RSS key to use for hashing specific header -/// fields of received packets. The length of this array should be indicated -/// by *rss_key_len* below. Otherwise, a default random hash key is used by -/// the device driver. -/// -/// The *rss_key_len* field of the *rss_conf* structure indicates the length -/// in bytes of the array pointed by *rss_key*. To be compatible, this length -/// will be checked in i40e only. Others assume 40 bytes to be used as before. -/// -/// The *rss_hf* field of the *rss_conf* structure indicates the different -/// types of IPv4/IPv6 packets to which the RSS hashing must be applied. -/// Supplying an *rss_hf* equal to zero disables the RSS feature. +/** A structure used to configure the Receive Side Scaling (RSS) feature + of an Ethernet port. + If not NULL, the *rss_key* pointer of the *rss_conf* structure points + to an array holding the RSS key to use for hashing specific header + fields of received packets. The length of this array should be indicated + by *rss_key_len* below. Otherwise, a default random hash key is used by + the device driver. + + The *rss_key_len* field of the *rss_conf* structure indicates the length + in bytes of the array pointed by *rss_key*. To be compatible, this length + will be checked in i40e only. Others assume 40 bytes to be used as before. + + The *rss_hf* field of the *rss_conf* structure indicates the different + types of IPv4/IPv6 packets to which the RSS hashing must be applied. + Supplying an *rss_hf* equal to zero disables the RSS feature.*/ #[repr(C)] #[derive(Debug, Copy, Hash, PartialEq, Eq)] pub struct rte_eth_rss_conf { @@ -612,50 +611,30 @@ pub struct rte_eth_rss_conf { } #[test] fn bindgen_test_layout_rte_eth_rss_conf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 24usize, - concat!("Size of: ", stringify!(rte_eth_rss_conf)) + ::std::mem::size_of:: < rte_eth_rss_conf > (), 24usize, concat!("Size of: ", + stringify!(rte_eth_rss_conf)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(rte_eth_rss_conf)) + ::std::mem::align_of:: < rte_eth_rss_conf > (), 8usize, concat!("Alignment of ", + stringify!(rte_eth_rss_conf)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).rss_key) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rss_conf), - "::", - stringify!(rss_key) - ) + unsafe { ::std::ptr::addr_of!((* ptr).rss_key) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_eth_rss_conf), "::", + stringify!(rss_key)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).rss_key_len) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rss_conf), - "::", - stringify!(rss_key_len) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).rss_hf) as usize - ptr as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rss_conf), - "::", - stringify!(rss_hf) - ) + unsafe { ::std::ptr::addr_of!((* ptr).rss_key_len) as usize - ptr as usize }, + 8usize, concat!("Offset of field: ", stringify!(rte_eth_rss_conf), "::", + stringify!(rss_key_len)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).rss_hf) as usize - ptr as usize }, 16usize, + concat!("Offset of field: ", stringify!(rte_eth_rss_conf), "::", + stringify!(rss_hf)) ); } impl Clone for rte_eth_rss_conf { @@ -673,8 +652,8 @@ impl Default for rte_eth_rss_conf { } } #[repr(u32)] -/// This enum indicates the possible number of traffic classes -/// in DCB configratioins +/** This enum indicates the possible number of traffic classes + in DCB configratioins*/ #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum rte_eth_nb_tcs { ///< 4 TCs with DCB. @@ -683,8 +662,8 @@ pub enum rte_eth_nb_tcs { ETH_8_TCS = 8, } #[repr(u32)] -/// This enum indicates the possible number of queue pools -/// in VMDQ configurations. +/** This enum indicates the possible number of queue pools + in VMDQ configurations.*/ #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum rte_eth_nb_pools { ///< 8 VMDq pools. @@ -696,15 +675,15 @@ pub enum rte_eth_nb_pools { ///< 64 VMDq pools. ETH_64_POOLS = 64, } -/// A structure used to configure the VMDQ+DCB feature -/// of an Ethernet port. -/// -/// Using this feature, packets are routed to a pool of queues, based -/// on the vlan ID in the vlan tag, and then to a specific queue within -/// that pool, using the user priority vlan tag field. -/// -/// A default pool may be used, if desired, to route all traffic which -/// does not match the vlan filter rules. +/** A structure used to configure the VMDQ+DCB feature + of an Ethernet port. + + Using this feature, packets are routed to a pool of queues, based + on the vlan ID in the vlan tag, and then to a specific queue within + that pool, using the user priority vlan tag field. + + A default pool may be used, if desired, to route all traffic which + does not match the vlan filter rules.*/ #[repr(C)] #[derive(Copy)] pub struct rte_eth_vmdq_dcb_conf { @@ -730,41 +709,25 @@ pub struct rte_eth_vmdq_dcb_conf__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_eth_vmdq_dcb_conf__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 16usize, + ::std::mem::size_of:: < rte_eth_vmdq_dcb_conf__bindgen_ty_1 > (), 16usize, concat!("Size of: ", stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!( - "Alignment of ", - stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1) - ) + ::std::mem::align_of:: < rte_eth_vmdq_dcb_conf__bindgen_ty_1 > (), 8usize, + concat!("Alignment of ", stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).vlan_id) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1), - "::", - stringify!(vlan_id) - ) + unsafe { ::std::ptr::addr_of!((* ptr).vlan_id) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1), + "::", stringify!(vlan_id)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).pools) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1), - "::", - stringify!(pools) - ) + unsafe { ::std::ptr::addr_of!((* ptr).pools) as usize - ptr as usize }, 8usize, + concat!("Offset of field: ", stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1), + "::", stringify!(pools)) ); } impl Clone for rte_eth_vmdq_dcb_conf__bindgen_ty_1 { @@ -774,89 +737,45 @@ impl Clone for rte_eth_vmdq_dcb_conf__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 1040usize, + ::std::mem::size_of:: < rte_eth_vmdq_dcb_conf > (), 1040usize, concat!("Size of: ", stringify!(rte_eth_vmdq_dcb_conf)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, + ::std::mem::align_of:: < rte_eth_vmdq_dcb_conf > (), 8usize, concat!("Alignment of ", stringify!(rte_eth_vmdq_dcb_conf)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(nb_queue_pools) - ) + unsafe { ::std::ptr::addr_of!((* ptr).nb_queue_pools) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_dcb_conf), "::", + stringify!(nb_queue_pools)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).enable_default_pool) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(enable_default_pool) - ) + unsafe { ::std::ptr::addr_of!((* ptr).enable_default_pool) as usize - ptr as + usize }, 4usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_dcb_conf), + "::", stringify!(enable_default_pool)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).default_pool) as usize - ptr as usize - }, - 5usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(default_pool) - ) + unsafe { ::std::ptr::addr_of!((* ptr).default_pool) as usize - ptr as usize }, + 5usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_dcb_conf), "::", + stringify!(default_pool)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).nb_pool_maps) as usize - ptr as usize - }, - 6usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(nb_pool_maps) - ) + unsafe { ::std::ptr::addr_of!((* ptr).nb_pool_maps) as usize - ptr as usize }, + 6usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_dcb_conf), "::", + stringify!(nb_pool_maps)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).pool_map) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(pool_map) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize }, - 1032usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(dcb_tc) - ) + unsafe { ::std::ptr::addr_of!((* ptr).pool_map) as usize - ptr as usize }, + 8usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_dcb_conf), "::", + stringify!(pool_map)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).dcb_tc) as usize - ptr as usize }, + 1032usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_dcb_conf), "::", + stringify!(dcb_tc)) ); } impl Clone for rte_eth_vmdq_dcb_conf { @@ -883,38 +802,25 @@ pub struct rte_eth_dcb_rx_conf { } #[test] fn bindgen_test_layout_rte_eth_dcb_rx_conf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 12usize, - concat!("Size of: ", stringify!(rte_eth_dcb_rx_conf)) + ::std::mem::size_of:: < rte_eth_dcb_rx_conf > (), 12usize, concat!("Size of: ", + stringify!(rte_eth_dcb_rx_conf)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < rte_eth_dcb_rx_conf > (), 4usize, concat!("Alignment of ", stringify!(rte_eth_dcb_rx_conf)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_dcb_rx_conf), - "::", - stringify!(nb_tcs) - ) + unsafe { ::std::ptr::addr_of!((* ptr).nb_tcs) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_eth_dcb_rx_conf), "::", + stringify!(nb_tcs)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_dcb_rx_conf), - "::", - stringify!(dcb_tc) - ) + unsafe { ::std::ptr::addr_of!((* ptr).dcb_tc) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(rte_eth_dcb_rx_conf), "::", + stringify!(dcb_tc)) ); } impl Clone for rte_eth_dcb_rx_conf { @@ -941,40 +847,25 @@ pub struct rte_eth_vmdq_dcb_tx_conf { } #[test] fn bindgen_test_layout_rte_eth_vmdq_dcb_tx_conf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 12usize, + ::std::mem::size_of:: < rte_eth_vmdq_dcb_tx_conf > (), 12usize, concat!("Size of: ", stringify!(rte_eth_vmdq_dcb_tx_conf)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < rte_eth_vmdq_dcb_tx_conf > (), 4usize, concat!("Alignment of ", stringify!(rte_eth_vmdq_dcb_tx_conf)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_tx_conf), - "::", - stringify!(nb_queue_pools) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_tx_conf), - "::", - stringify!(dcb_tc) - ) + unsafe { ::std::ptr::addr_of!((* ptr).nb_queue_pools) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_dcb_tx_conf), "::", + stringify!(nb_queue_pools)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).dcb_tc) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(rte_eth_vmdq_dcb_tx_conf), "::", + stringify!(dcb_tc)) ); } impl Clone for rte_eth_vmdq_dcb_tx_conf { @@ -1001,38 +892,25 @@ pub struct rte_eth_dcb_tx_conf { } #[test] fn bindgen_test_layout_rte_eth_dcb_tx_conf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 12usize, - concat!("Size of: ", stringify!(rte_eth_dcb_tx_conf)) + ::std::mem::size_of:: < rte_eth_dcb_tx_conf > (), 12usize, concat!("Size of: ", + stringify!(rte_eth_dcb_tx_conf)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < rte_eth_dcb_tx_conf > (), 4usize, concat!("Alignment of ", stringify!(rte_eth_dcb_tx_conf)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_dcb_tx_conf), - "::", - stringify!(nb_tcs) - ) + unsafe { ::std::ptr::addr_of!((* ptr).nb_tcs) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_eth_dcb_tx_conf), "::", + stringify!(nb_tcs)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_dcb_tx_conf), - "::", - stringify!(dcb_tc) - ) + unsafe { ::std::ptr::addr_of!((* ptr).dcb_tc) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(rte_eth_dcb_tx_conf), "::", + stringify!(dcb_tc)) ); } impl Clone for rte_eth_dcb_tx_conf { @@ -1057,30 +935,20 @@ pub struct rte_eth_vmdq_tx_conf { } #[test] fn bindgen_test_layout_rte_eth_vmdq_tx_conf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(rte_eth_vmdq_tx_conf)) + ::std::mem::size_of:: < rte_eth_vmdq_tx_conf > (), 4usize, concat!("Size of: ", + stringify!(rte_eth_vmdq_tx_conf)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < rte_eth_vmdq_tx_conf > (), 4usize, concat!("Alignment of ", stringify!(rte_eth_vmdq_tx_conf)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_tx_conf), - "::", - stringify!(nb_queue_pools) - ) + unsafe { ::std::ptr::addr_of!((* ptr).nb_queue_pools) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_tx_conf), "::", + stringify!(nb_queue_pools)) ); } impl Clone for rte_eth_vmdq_tx_conf { @@ -1125,41 +993,25 @@ pub struct rte_eth_vmdq_rx_conf__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_eth_vmdq_rx_conf__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 16usize, + ::std::mem::size_of:: < rte_eth_vmdq_rx_conf__bindgen_ty_1 > (), 16usize, concat!("Size of: ", stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!( - "Alignment of ", - stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1) - ) + ::std::mem::align_of:: < rte_eth_vmdq_rx_conf__bindgen_ty_1 > (), 8usize, + concat!("Alignment of ", stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).vlan_id) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1), - "::", - stringify!(vlan_id) - ) + unsafe { ::std::ptr::addr_of!((* ptr).vlan_id) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1), + "::", stringify!(vlan_id)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).pools) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1), - "::", - stringify!(pools) - ) + unsafe { ::std::ptr::addr_of!((* ptr).pools) as usize - ptr as usize }, 8usize, + concat!("Offset of field: ", stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1), + "::", stringify!(pools)) ); } impl Clone for rte_eth_vmdq_rx_conf__bindgen_ty_1 { @@ -1169,102 +1021,50 @@ impl Clone for rte_eth_vmdq_rx_conf__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 1040usize, + ::std::mem::size_of:: < rte_eth_vmdq_rx_conf > (), 1040usize, concat!("Size of: ", stringify!(rte_eth_vmdq_rx_conf)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, + ::std::mem::align_of:: < rte_eth_vmdq_rx_conf > (), 8usize, concat!("Alignment of ", stringify!(rte_eth_vmdq_rx_conf)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(nb_queue_pools) - ) + unsafe { ::std::ptr::addr_of!((* ptr).nb_queue_pools) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_rx_conf), "::", + stringify!(nb_queue_pools)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).enable_default_pool) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(enable_default_pool) - ) + unsafe { ::std::ptr::addr_of!((* ptr).enable_default_pool) as usize - ptr as + usize }, 4usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_rx_conf), + "::", stringify!(enable_default_pool)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).default_pool) as usize - ptr as usize - }, - 5usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(default_pool) - ) + unsafe { ::std::ptr::addr_of!((* ptr).default_pool) as usize - ptr as usize }, + 5usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_rx_conf), "::", + stringify!(default_pool)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).enable_loop_back) as usize - - ptr as usize - }, - 6usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(enable_loop_back) - ) + unsafe { ::std::ptr::addr_of!((* ptr).enable_loop_back) as usize - ptr as usize + }, 6usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_rx_conf), "::", + stringify!(enable_loop_back)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).nb_pool_maps) as usize - ptr as usize - }, - 7usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(nb_pool_maps) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).rx_mode) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(rx_mode) - ) + unsafe { ::std::ptr::addr_of!((* ptr).nb_pool_maps) as usize - ptr as usize }, + 7usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_rx_conf), "::", + stringify!(nb_pool_maps)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).pool_map) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(pool_map) - ) + unsafe { ::std::ptr::addr_of!((* ptr).rx_mode) as usize - ptr as usize }, 8usize, + concat!("Offset of field: ", stringify!(rte_eth_vmdq_rx_conf), "::", + stringify!(rx_mode)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).pool_map) as usize - ptr as usize }, + 16usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_rx_conf), "::", + stringify!(pool_map)) ); } impl Clone for rte_eth_vmdq_rx_conf { @@ -1297,8 +1097,8 @@ pub enum rte_fdir_mode { RTE_FDIR_MODE_PERFECT_TUNNEL = 4, } #[repr(u32)] -/// Memory space that can be configured to store Flow Director filters -/// in the board memory. +/** Memory space that can be configured to store Flow Director filters + in the board memory.*/ #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum rte_fdir_pballoc_type { ///< 64k. @@ -1336,68 +1136,40 @@ pub struct rte_eth_ipv4_flow { } #[test] fn bindgen_test_layout_rte_eth_ipv4_flow() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 12usize, - concat!("Size of: ", stringify!(rte_eth_ipv4_flow)) + ::std::mem::size_of:: < rte_eth_ipv4_flow > (), 12usize, concat!("Size of: ", + stringify!(rte_eth_ipv4_flow)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(rte_eth_ipv4_flow)) + ::std::mem::align_of:: < rte_eth_ipv4_flow > (), 4usize, concat!("Alignment of ", + stringify!(rte_eth_ipv4_flow)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(src_ip) - ) + unsafe { ::std::ptr::addr_of!((* ptr).src_ip) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_eth_ipv4_flow), "::", + stringify!(src_ip)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dst_ip) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(dst_ip) - ) + unsafe { ::std::ptr::addr_of!((* ptr).dst_ip) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(rte_eth_ipv4_flow), "::", + stringify!(dst_ip)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).tos) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(tos) - ) + unsafe { ::std::ptr::addr_of!((* ptr).tos) as usize - ptr as usize }, 8usize, + concat!("Offset of field: ", stringify!(rte_eth_ipv4_flow), "::", + stringify!(tos)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ttl) as usize - ptr as usize }, - 9usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(ttl) - ) + unsafe { ::std::ptr::addr_of!((* ptr).ttl) as usize - ptr as usize }, 9usize, + concat!("Offset of field: ", stringify!(rte_eth_ipv4_flow), "::", + stringify!(ttl)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize }, - 10usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(proto) - ) + unsafe { ::std::ptr::addr_of!((* ptr).proto) as usize - ptr as usize }, 10usize, + concat!("Offset of field: ", stringify!(rte_eth_ipv4_flow), "::", + stringify!(proto)) ); } impl Clone for rte_eth_ipv4_flow { @@ -1422,70 +1194,39 @@ pub struct rte_eth_ipv6_flow { } #[test] fn bindgen_test_layout_rte_eth_ipv6_flow() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 36usize, - concat!("Size of: ", stringify!(rte_eth_ipv6_flow)) + ::std::mem::size_of:: < rte_eth_ipv6_flow > (), 36usize, concat!("Size of: ", + stringify!(rte_eth_ipv6_flow)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(rte_eth_ipv6_flow)) + ::std::mem::align_of:: < rte_eth_ipv6_flow > (), 4usize, concat!("Alignment of ", + stringify!(rte_eth_ipv6_flow)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(src_ip) - ) + unsafe { ::std::ptr::addr_of!((* ptr).src_ip) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_eth_ipv6_flow), "::", + stringify!(src_ip)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dst_ip) as usize - ptr as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(dst_ip) - ) + unsafe { ::std::ptr::addr_of!((* ptr).dst_ip) as usize - ptr as usize }, 16usize, + concat!("Offset of field: ", stringify!(rte_eth_ipv6_flow), "::", + stringify!(dst_ip)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).tc) as usize - ptr as usize }, - 32usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(tc) - ) + unsafe { ::std::ptr::addr_of!((* ptr).tc) as usize - ptr as usize }, 32usize, + concat!("Offset of field: ", stringify!(rte_eth_ipv6_flow), "::", stringify!(tc)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize }, - 33usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(proto) - ) + unsafe { ::std::ptr::addr_of!((* ptr).proto) as usize - ptr as usize }, 33usize, + concat!("Offset of field: ", stringify!(rte_eth_ipv6_flow), "::", + stringify!(proto)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).hop_limits) as usize - ptr as usize - }, - 34usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(hop_limits) - ) + unsafe { ::std::ptr::addr_of!((* ptr).hop_limits) as usize - ptr as usize }, + 34usize, concat!("Offset of field: ", stringify!(rte_eth_ipv6_flow), "::", + stringify!(hop_limits)) ); } impl Clone for rte_eth_ipv6_flow { @@ -1493,8 +1234,8 @@ impl Clone for rte_eth_ipv6_flow { *self } } -/// A structure used to configure FDIR masks that are used by the device -/// to match the various fields of RX packet headers. +/** A structure used to configure FDIR masks that are used by the device + to match the various fields of RX packet headers.*/ #[repr(C)] #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct rte_eth_fdir_masks { @@ -1508,127 +1249,66 @@ pub struct rte_eth_fdir_masks { pub src_port_mask: u16, /// Bit mask for L4 destination port in big endian. pub dst_port_mask: u16, - /// 6 bit mask for proper 6 bytes of Mac address, bit 0 matches the - ///first byte on the wire + /** 6 bit mask for proper 6 bytes of Mac address, bit 0 matches the +first byte on the wire*/ pub mac_addr_byte_mask: u8, /// Bit mask for tunnel ID in big endian. pub tunnel_id_mask: u32, - ///< 1 - Match tunnel type, - ///0 - Ignore tunnel type. + /**< 1 - Match tunnel type, +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(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 68usize, - concat!("Size of: ", stringify!(rte_eth_fdir_masks)) + ::std::mem::size_of:: < rte_eth_fdir_masks > (), 68usize, concat!("Size of: ", + stringify!(rte_eth_fdir_masks)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < rte_eth_fdir_masks > (), 4usize, concat!("Alignment of ", stringify!(rte_eth_fdir_masks)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).vlan_tci_mask) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(vlan_tci_mask) - ) + unsafe { ::std::ptr::addr_of!((* ptr).vlan_tci_mask) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_masks), "::", + stringify!(vlan_tci_mask)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).ipv4_mask) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(ipv4_mask) - ) + unsafe { ::std::ptr::addr_of!((* ptr).ipv4_mask) as usize - ptr as usize }, + 4usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_masks), "::", + stringify!(ipv4_mask)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).ipv6_mask) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(ipv6_mask) - ) + unsafe { ::std::ptr::addr_of!((* ptr).ipv6_mask) as usize - ptr as usize }, + 16usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_masks), "::", + stringify!(ipv6_mask)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).src_port_mask) as usize - ptr as usize - }, - 52usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(src_port_mask) - ) + unsafe { ::std::ptr::addr_of!((* ptr).src_port_mask) as usize - ptr as usize }, + 52usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_masks), "::", + stringify!(src_port_mask)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).dst_port_mask) as usize - ptr as usize - }, - 54usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(dst_port_mask) - ) + unsafe { ::std::ptr::addr_of!((* ptr).dst_port_mask) as usize - ptr as usize }, + 54usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_masks), "::", + stringify!(dst_port_mask)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mac_addr_byte_mask) as usize - - ptr as usize - }, - 56usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(mac_addr_byte_mask) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mac_addr_byte_mask) as usize - ptr as usize + }, 56usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_masks), "::", + stringify!(mac_addr_byte_mask)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).tunnel_id_mask) as usize - ptr as usize - }, - 60usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(tunnel_id_mask) - ) + unsafe { ::std::ptr::addr_of!((* ptr).tunnel_id_mask) as usize - ptr as usize }, + 60usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_masks), "::", + stringify!(tunnel_id_mask)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).tunnel_type_mask) as usize - - ptr as usize - }, - 64usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(tunnel_type_mask) - ) + unsafe { ::std::ptr::addr_of!((* ptr).tunnel_type_mask) as usize - ptr as usize + }, 64usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_masks), "::", + stringify!(tunnel_type_mask)) ); } impl Clone for rte_eth_fdir_masks { @@ -1647,8 +1327,8 @@ pub enum rte_eth_payload_type { RTE_ETH_L4_PAYLOAD = 4, RTE_ETH_PAYLOAD_MAX = 8, } -/// A structure used to select bytes extracted from the protocol layers to -/// flexible payload for filter +/** A structure used to select bytes extracted from the protocol layers to + flexible payload for filter*/ #[repr(C)] #[derive(Debug, Copy, Hash, PartialEq, Eq)] pub struct rte_eth_flex_payload_cfg { @@ -1658,40 +1338,25 @@ pub struct rte_eth_flex_payload_cfg { } #[test] fn bindgen_test_layout_rte_eth_flex_payload_cfg() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 36usize, + ::std::mem::size_of:: < rte_eth_flex_payload_cfg > (), 36usize, concat!("Size of: ", stringify!(rte_eth_flex_payload_cfg)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < rte_eth_flex_payload_cfg > (), 4usize, concat!("Alignment of ", stringify!(rte_eth_flex_payload_cfg)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_flex_payload_cfg), - "::", - stringify!(type_) - ) + unsafe { ::std::ptr::addr_of!((* ptr).type_) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_eth_flex_payload_cfg), "::", + stringify!(type_)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).src_offset) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_flex_payload_cfg), - "::", - stringify!(src_offset) - ) + unsafe { ::std::ptr::addr_of!((* ptr).src_offset) as usize - ptr as usize }, + 4usize, concat!("Offset of field: ", stringify!(rte_eth_flex_payload_cfg), "::", + stringify!(src_offset)) ); } impl Clone for rte_eth_flex_payload_cfg { @@ -1708,8 +1373,8 @@ impl Default for rte_eth_flex_payload_cfg { } } } -/// A structure used to define FDIR masks for flexible payload -/// for each flow type +/** A structure used to define FDIR masks for flexible payload + for each flow type*/ #[repr(C)] #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct rte_eth_fdir_flex_mask { @@ -1718,40 +1383,25 @@ pub struct rte_eth_fdir_flex_mask { } #[test] fn bindgen_test_layout_rte_eth_fdir_flex_mask() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 18usize, + ::std::mem::size_of:: < rte_eth_fdir_flex_mask > (), 18usize, concat!("Size of: ", stringify!(rte_eth_fdir_flex_mask)) ); assert_eq!( - ::std::mem::align_of::(), - 2usize, + ::std::mem::align_of:: < rte_eth_fdir_flex_mask > (), 2usize, concat!("Alignment of ", stringify!(rte_eth_fdir_flex_mask)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).flow_type) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_mask), - "::", - stringify!(flow_type) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_mask), - "::", - stringify!(mask) - ) + unsafe { ::std::ptr::addr_of!((* ptr).flow_type) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_flex_mask), "::", + stringify!(flow_type)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).mask) as usize - ptr as usize }, 2usize, + concat!("Offset of field: ", stringify!(rte_eth_fdir_flex_mask), "::", + stringify!(mask)) ); } impl Clone for rte_eth_fdir_flex_mask { @@ -1759,8 +1409,8 @@ impl Clone for rte_eth_fdir_flex_mask { *self } } -/// A structure used to define all flexible payload related setting -/// include flex payload and flex mask +/** A structure used to define all flexible payload related setting + include flex payload and flex mask*/ #[repr(C)] #[derive(Debug, Copy, Hash, PartialEq, Eq)] pub struct rte_eth_fdir_flex_conf { @@ -1773,66 +1423,35 @@ pub struct rte_eth_fdir_flex_conf { } #[test] fn bindgen_test_layout_rte_eth_fdir_flex_conf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 688usize, + ::std::mem::size_of:: < rte_eth_fdir_flex_conf > (), 688usize, concat!("Size of: ", stringify!(rte_eth_fdir_flex_conf)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < rte_eth_fdir_flex_conf > (), 4usize, concat!("Alignment of ", stringify!(rte_eth_fdir_flex_conf)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).nb_payloads) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_conf), - "::", - stringify!(nb_payloads) - ) + unsafe { ::std::ptr::addr_of!((* ptr).nb_payloads) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_flex_conf), "::", + stringify!(nb_payloads)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).nb_flexmasks) as usize - ptr as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_conf), - "::", - stringify!(nb_flexmasks) - ) + unsafe { ::std::ptr::addr_of!((* ptr).nb_flexmasks) as usize - ptr as usize }, + 2usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_flex_conf), "::", + stringify!(nb_flexmasks)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).flex_set) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_conf), - "::", - stringify!(flex_set) - ) + unsafe { ::std::ptr::addr_of!((* ptr).flex_set) as usize - ptr as usize }, + 4usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_flex_conf), "::", + stringify!(flex_set)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).flex_mask) as usize - ptr as usize - }, - 292usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_conf), - "::", - stringify!(flex_mask) - ) + unsafe { ::std::ptr::addr_of!((* ptr).flex_mask) as usize - ptr as usize }, + 292usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_flex_conf), "::", + stringify!(flex_mask)) ); } impl Clone for rte_eth_fdir_flex_conf { @@ -1849,10 +1468,10 @@ impl Default for rte_eth_fdir_flex_conf { } } } -/// A structure used to configure the Flow Director (FDIR) feature -/// of an Ethernet port. -/// -/// If mode is RTE_FDIR_DISABLE, the pballoc value is ignored. +/** A structure used to configure the Flow Director (FDIR) feature + of an Ethernet port. + + If mode is RTE_FDIR_DISABLE, the pballoc value is ignored.*/ #[repr(C)] #[derive(Debug, Copy, Hash, PartialEq, Eq)] pub struct rte_fdir_conf { @@ -1869,82 +1488,42 @@ pub struct rte_fdir_conf { } #[test] fn bindgen_test_layout_rte_fdir_conf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 772usize, - concat!("Size of: ", stringify!(rte_fdir_conf)) + ::std::mem::size_of:: < rte_fdir_conf > (), 772usize, concat!("Size of: ", + stringify!(rte_fdir_conf)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(rte_fdir_conf)) + ::std::mem::align_of:: < rte_fdir_conf > (), 4usize, concat!("Alignment of ", + stringify!(rte_fdir_conf)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mode) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(mode) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mode) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_fdir_conf), "::", stringify!(mode)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).pballoc) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(pballoc) - ) + unsafe { ::std::ptr::addr_of!((* ptr).pballoc) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(rte_fdir_conf), "::", + stringify!(pballoc)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).status) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(status) - ) + unsafe { ::std::ptr::addr_of!((* ptr).status) as usize - ptr as usize }, 8usize, + concat!("Offset of field: ", stringify!(rte_fdir_conf), "::", stringify!(status)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).drop_queue) as usize - ptr as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(drop_queue) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(mask) - ) + unsafe { ::std::ptr::addr_of!((* ptr).drop_queue) as usize - ptr as usize }, + 12usize, concat!("Offset of field: ", stringify!(rte_fdir_conf), "::", + stringify!(drop_queue)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).flex_conf) as usize - ptr as usize - }, - 84usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(flex_conf) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mask) as usize - ptr as usize }, 16usize, + concat!("Offset of field: ", stringify!(rte_fdir_conf), "::", stringify!(mask)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).flex_conf) as usize - ptr as usize }, + 84usize, concat!("Offset of field: ", stringify!(rte_fdir_conf), "::", + stringify!(flex_conf)) ); } impl Clone for rte_fdir_conf { @@ -1972,38 +1551,23 @@ pub struct rte_intr_conf { } #[test] fn bindgen_test_layout_rte_intr_conf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(rte_intr_conf)) + ::std::mem::size_of:: < rte_intr_conf > (), 4usize, concat!("Size of: ", + stringify!(rte_intr_conf)) ); assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(rte_intr_conf)) + ::std::mem::align_of:: < rte_intr_conf > (), 2usize, concat!("Alignment of ", + stringify!(rte_intr_conf)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).lsc) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_intr_conf), - "::", - stringify!(lsc) - ) + unsafe { ::std::ptr::addr_of!((* ptr).lsc) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_intr_conf), "::", stringify!(lsc)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).rxq) as usize - ptr as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(rte_intr_conf), - "::", - stringify!(rxq) - ) + unsafe { ::std::ptr::addr_of!((* ptr).rxq) as usize - ptr as usize }, 2usize, + concat!("Offset of field: ", stringify!(rte_intr_conf), "::", stringify!(rxq)) ); } impl Clone for rte_intr_conf { @@ -2011,36 +1575,36 @@ impl Clone for rte_intr_conf { *self } } -/// A structure used to configure an Ethernet port. -/// Depending upon the RX multi-queue mode, extra advanced -/// configuration settings may be needed. +/** A structure used to configure an Ethernet port. + Depending upon the RX multi-queue mode, extra advanced + configuration settings may be needed.*/ #[repr(C)] #[derive(Copy)] pub struct rte_eth_conf { - ///< bitmap of ETH_LINK_SPEED_XXX of speeds to be - ///used. ETH_LINK_SPEED_FIXED disables link - ///autonegotiation, and a unique speed shall be - ///set. Otherwise, the bitmap defines the set of - ///speeds to be advertised. If the special value - ///ETH_LINK_SPEED_AUTONEG (0) is used, all speeds - ///supported are advertised. + /**< bitmap of ETH_LINK_SPEED_XXX of speeds to be +used. ETH_LINK_SPEED_FIXED disables link +autonegotiation, and a unique speed shall be +set. Otherwise, the bitmap defines the set of +speeds to be advertised. If the special value +ETH_LINK_SPEED_AUTONEG (0) is used, all speeds +supported are advertised.*/ pub link_speeds: u32, ///< Port RX configuration. pub rxmode: rte_eth_rxmode, ///< Port TX configuration. pub txmode: rte_eth_txmode, - ///< Loopback operation mode. By default the value - ///is 0, meaning the loopback mode is disabled. - ///Read the datasheet of given ethernet controller - ///for details. The possible values of this field - ///are defined in implementation of each driver. + /**< Loopback operation mode. By default the value +is 0, meaning the loopback mode is disabled. +Read the datasheet of given ethernet controller +for details. The possible values of this field +are defined in implementation of each driver.*/ pub lpbk_mode: u32, ///< Port RX filtering configuration (union). pub rx_adv_conf: rte_eth_conf__bindgen_ty_1, ///< Port TX DCB configuration (union). pub tx_adv_conf: rte_eth_conf__bindgen_ty_2, - /// Currently,Priority Flow Control(PFC) are supported,if DCB with PFC - ///is needed,and the variable must be set ETH_DCB_PFC_SUPPORT. + /** Currently,Priority Flow Control(PFC) are supported,if DCB with PFC +is needed,and the variable must be set ETH_DCB_PFC_SUPPORT.*/ pub dcb_capability_en: u32, ///< FDIR configuration. pub fdir_conf: rte_fdir_conf, @@ -2058,66 +1622,35 @@ pub struct rte_eth_conf__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_eth_conf__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 2120usize, + ::std::mem::size_of:: < rte_eth_conf__bindgen_ty_1 > (), 2120usize, concat!("Size of: ", stringify!(rte_eth_conf__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, + ::std::mem::align_of:: < rte_eth_conf__bindgen_ty_1 > (), 8usize, concat!("Alignment of ", stringify!(rte_eth_conf__bindgen_ty_1)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).rss_conf) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_1), - "::", - stringify!(rss_conf) - ) + unsafe { ::std::ptr::addr_of!((* ptr).rss_conf) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_eth_conf__bindgen_ty_1), + "::", stringify!(rss_conf)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).vmdq_dcb_conf) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_1), - "::", - stringify!(vmdq_dcb_conf) - ) + unsafe { ::std::ptr::addr_of!((* ptr).vmdq_dcb_conf) as usize - ptr as usize }, + 24usize, concat!("Offset of field: ", stringify!(rte_eth_conf__bindgen_ty_1), + "::", stringify!(vmdq_dcb_conf)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).dcb_rx_conf) as usize - ptr as usize - }, - 1064usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_1), - "::", - stringify!(dcb_rx_conf) - ) + unsafe { ::std::ptr::addr_of!((* ptr).dcb_rx_conf) as usize - ptr as usize }, + 1064usize, concat!("Offset of field: ", stringify!(rte_eth_conf__bindgen_ty_1), + "::", stringify!(dcb_rx_conf)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).vmdq_rx_conf) as usize - ptr as usize - }, - 1080usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_1), - "::", - stringify!(vmdq_rx_conf) - ) + unsafe { ::std::ptr::addr_of!((* ptr).vmdq_rx_conf) as usize - ptr as usize }, + 1080usize, concat!("Offset of field: ", stringify!(rte_eth_conf__bindgen_ty_1), + "::", stringify!(vmdq_rx_conf)) ); } impl Clone for rte_eth_conf__bindgen_ty_1 { @@ -2144,55 +1677,30 @@ pub struct rte_eth_conf__bindgen_ty_2 { } #[test] fn bindgen_test_layout_rte_eth_conf__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 12usize, + ::std::mem::size_of:: < rte_eth_conf__bindgen_ty_2 > (), 12usize, concat!("Size of: ", stringify!(rte_eth_conf__bindgen_ty_2)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < rte_eth_conf__bindgen_ty_2 > (), 4usize, concat!("Alignment of ", stringify!(rte_eth_conf__bindgen_ty_2)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).vmdq_dcb_tx_conf) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_2), - "::", - stringify!(vmdq_dcb_tx_conf) - ) + unsafe { ::std::ptr::addr_of!((* ptr).vmdq_dcb_tx_conf) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", stringify!(rte_eth_conf__bindgen_ty_2), + "::", stringify!(vmdq_dcb_tx_conf)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).dcb_tx_conf) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_2), - "::", - stringify!(dcb_tx_conf) - ) + unsafe { ::std::ptr::addr_of!((* ptr).dcb_tx_conf) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_eth_conf__bindgen_ty_2), + "::", stringify!(dcb_tx_conf)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).vmdq_tx_conf) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_2), - "::", - stringify!(vmdq_tx_conf) - ) + unsafe { ::std::ptr::addr_of!((* ptr).vmdq_tx_conf) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_eth_conf__bindgen_ty_2), + "::", stringify!(vmdq_tx_conf)) ); } impl Clone for rte_eth_conf__bindgen_ty_2 { @@ -2202,123 +1710,58 @@ impl Clone for rte_eth_conf__bindgen_ty_2 { } #[test] fn bindgen_test_layout_rte_eth_conf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 2944usize, - concat!("Size of: ", stringify!(rte_eth_conf)) + ::std::mem::size_of:: < rte_eth_conf > (), 2944usize, concat!("Size of: ", + stringify!(rte_eth_conf)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(rte_eth_conf)) + ::std::mem::align_of:: < rte_eth_conf > (), 8usize, concat!("Alignment of ", + stringify!(rte_eth_conf)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).link_speeds) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(link_speeds) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).rxmode) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(rxmode) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).txmode) as usize - ptr as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(txmode) - ) + unsafe { ::std::ptr::addr_of!((* ptr).link_speeds) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_eth_conf), "::", + stringify!(link_speeds)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).lpbk_mode) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(lpbk_mode) - ) + unsafe { ::std::ptr::addr_of!((* ptr).rxmode) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(rte_eth_conf), "::", stringify!(rxmode)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).rx_adv_conf) as usize - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(rx_adv_conf) - ) + unsafe { ::std::ptr::addr_of!((* ptr).txmode) as usize - ptr as usize }, 16usize, + concat!("Offset of field: ", stringify!(rte_eth_conf), "::", stringify!(txmode)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).tx_adv_conf) as usize - ptr as usize - }, - 2152usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(tx_adv_conf) - ) + unsafe { ::std::ptr::addr_of!((* ptr).lpbk_mode) as usize - ptr as usize }, + 24usize, concat!("Offset of field: ", stringify!(rte_eth_conf), "::", + stringify!(lpbk_mode)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).dcb_capability_en) as usize - - ptr as usize - }, - 2164usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(dcb_capability_en) - ) + unsafe { ::std::ptr::addr_of!((* ptr).rx_adv_conf) as usize - ptr as usize }, + 32usize, concat!("Offset of field: ", stringify!(rte_eth_conf), "::", + stringify!(rx_adv_conf)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).fdir_conf) as usize - ptr as usize - }, - 2168usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(fdir_conf) - ) + unsafe { ::std::ptr::addr_of!((* ptr).tx_adv_conf) as usize - ptr as usize }, + 2152usize, concat!("Offset of field: ", stringify!(rte_eth_conf), "::", + stringify!(tx_adv_conf)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).intr_conf) as usize - ptr as usize - }, - 2940usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(intr_conf) - ) + unsafe { ::std::ptr::addr_of!((* ptr).dcb_capability_en) as usize - ptr as usize + }, 2164usize, concat!("Offset of field: ", stringify!(rte_eth_conf), "::", + stringify!(dcb_capability_en)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).fdir_conf) as usize - ptr as usize }, + 2168usize, concat!("Offset of field: ", stringify!(rte_eth_conf), "::", + stringify!(fdir_conf)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).intr_conf) as usize - ptr as usize }, + 2940usize, concat!("Offset of field: ", stringify!(rte_eth_conf), "::", + stringify!(intr_conf)) ); } impl Clone for rte_eth_conf { diff --git a/bindgen-tests/tests/expectations/tests/layout_kni_mbuf.rs b/bindgen-tests/tests/expectations/tests/layout_kni_mbuf.rs index be88d20fff..1167a7317f 100644 --- a/bindgen-tests/tests/expectations/tests/layout_kni_mbuf.rs +++ b/bindgen-tests/tests/expectations/tests/layout_kni_mbuf.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const RTE_CACHE_LINE_MIN_SIZE: u32 = 64; pub const RTE_CACHE_LINE_SIZE: u32 = 64; #[repr(C)] @@ -34,168 +28,78 @@ pub struct rte_kni_mbuf { } #[test] fn bindgen_test_layout_rte_kni_mbuf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 128usize, - concat!("Size of: ", stringify!(rte_kni_mbuf)) + ::std::mem::size_of:: < rte_kni_mbuf > (), 128usize, concat!("Size of: ", + stringify!(rte_kni_mbuf)) ); assert_eq!( - ::std::mem::align_of::(), - 64usize, - concat!("Alignment of ", stringify!(rte_kni_mbuf)) + ::std::mem::align_of:: < rte_kni_mbuf > (), 64usize, concat!("Alignment of ", + stringify!(rte_kni_mbuf)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).buf_addr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(buf_addr) - ) + unsafe { ::std::ptr::addr_of!((* ptr).buf_addr) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_kni_mbuf), "::", + stringify!(buf_addr)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).buf_physaddr) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(buf_physaddr) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).pad0) as usize - ptr as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(pad0) - ) + unsafe { ::std::ptr::addr_of!((* ptr).buf_physaddr) as usize - ptr as usize }, + 8usize, concat!("Offset of field: ", stringify!(rte_kni_mbuf), "::", + stringify!(buf_physaddr)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).data_off) as usize - ptr as usize - }, - 18usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(data_off) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).pad1) as usize - ptr as usize }, - 20usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(pad1) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).nb_segs) as usize - ptr as usize }, - 22usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(nb_segs) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).pad4) as usize - ptr as usize }, - 23usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(pad4) - ) + unsafe { ::std::ptr::addr_of!((* ptr).pad0) as usize - ptr as usize }, 16usize, + concat!("Offset of field: ", stringify!(rte_kni_mbuf), "::", stringify!(pad0)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).ol_flags) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(ol_flags) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).pad2) as usize - ptr as usize }, - 32usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(pad2) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).pkt_len) as usize - ptr as usize }, - 36usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(pkt_len) - ) + unsafe { ::std::ptr::addr_of!((* ptr).data_off) as usize - ptr as usize }, + 18usize, concat!("Offset of field: ", stringify!(rte_kni_mbuf), "::", + stringify!(data_off)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).data_len) as usize - ptr as usize - }, - 40usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(data_len) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).pad3) as usize - ptr as usize }, - 64usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(pad3) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).pool) as usize - ptr as usize }, - 72usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(pool) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize }, - 80usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(next) - ) + unsafe { ::std::ptr::addr_of!((* ptr).pad1) as usize - ptr as usize }, 20usize, + concat!("Offset of field: ", stringify!(rte_kni_mbuf), "::", stringify!(pad1)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).nb_segs) as usize - ptr as usize }, + 22usize, concat!("Offset of field: ", stringify!(rte_kni_mbuf), "::", + stringify!(nb_segs)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).pad4) as usize - ptr as usize }, 23usize, + concat!("Offset of field: ", stringify!(rte_kni_mbuf), "::", stringify!(pad4)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).ol_flags) as usize - ptr as usize }, + 24usize, concat!("Offset of field: ", stringify!(rte_kni_mbuf), "::", + stringify!(ol_flags)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).pad2) as usize - ptr as usize }, 32usize, + concat!("Offset of field: ", stringify!(rte_kni_mbuf), "::", stringify!(pad2)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).pkt_len) as usize - ptr as usize }, + 36usize, concat!("Offset of field: ", stringify!(rte_kni_mbuf), "::", + stringify!(pkt_len)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).data_len) as usize - ptr as usize }, + 40usize, concat!("Offset of field: ", stringify!(rte_kni_mbuf), "::", + stringify!(data_len)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).pad3) as usize - ptr as usize }, 64usize, + concat!("Offset of field: ", stringify!(rte_kni_mbuf), "::", stringify!(pad3)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).pool) as usize - ptr as usize }, 72usize, + concat!("Offset of field: ", stringify!(rte_kni_mbuf), "::", stringify!(pool)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).next) as usize - ptr as usize }, 80usize, + concat!("Offset of field: ", stringify!(rte_kni_mbuf), "::", stringify!(next)) ); } impl Default for rte_kni_mbuf { 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 075ef46ae4..d70e6237da 100644 --- a/bindgen-tests/tests/expectations/tests/layout_large_align_field.rs +++ b/bindgen-tests/tests/expectations/tests/layout_large_align_field.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Default)] pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); @@ -65,48 +59,27 @@ pub struct ip_frag { } #[test] fn bindgen_test_layout_ip_frag() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(ip_frag)) + ::std::mem::size_of:: < ip_frag > (), 16usize, concat!("Size of: ", + stringify!(ip_frag)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(ip_frag)) + ::std::mem::align_of:: < ip_frag > (), 8usize, concat!("Alignment of ", + stringify!(ip_frag)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ofs) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ip_frag), - "::", - stringify!(ofs) - ) + unsafe { ::std::ptr::addr_of!((* ptr).ofs) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(ip_frag), "::", stringify!(ofs)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(ip_frag), - "::", - stringify!(len) - ) + unsafe { ::std::ptr::addr_of!((* ptr).len) as usize - ptr as usize }, 2usize, + concat!("Offset of field: ", stringify!(ip_frag), "::", stringify!(len)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mb) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(ip_frag), - "::", - stringify!(mb) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mb) as usize - ptr as usize }, 8usize, + concat!("Offset of field: ", stringify!(ip_frag), "::", stringify!(mb)) ); } impl Default for ip_frag { @@ -131,52 +104,32 @@ pub struct ip_frag_key { } #[test] fn bindgen_test_layout_ip_frag_key() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 40usize, - concat!("Size of: ", stringify!(ip_frag_key)) + ::std::mem::size_of:: < ip_frag_key > (), 40usize, concat!("Size of: ", + stringify!(ip_frag_key)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(ip_frag_key)) + ::std::mem::align_of:: < ip_frag_key > (), 8usize, concat!("Alignment of ", + stringify!(ip_frag_key)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).src_dst) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_key), - "::", - stringify!(src_dst) - ) + unsafe { ::std::ptr::addr_of!((* ptr).src_dst) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(ip_frag_key), "::", stringify!(src_dst)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).id) as usize - ptr as usize }, - 32usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_key), - "::", - stringify!(id) - ) + unsafe { ::std::ptr::addr_of!((* ptr).id) as usize - ptr as usize }, 32usize, + concat!("Offset of field: ", stringify!(ip_frag_key), "::", stringify!(id)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).key_len) as usize - ptr as usize }, - 36usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_key), - "::", - stringify!(key_len) - ) + unsafe { ::std::ptr::addr_of!((* ptr).key_len) as usize - ptr as usize }, + 36usize, concat!("Offset of field: ", stringify!(ip_frag_key), "::", + stringify!(key_len)) ); } -/// @internal Fragmented packet to reassemble. -/// First two entries in the frags[] array are for the last and first fragments. +/** @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)] @@ -204,42 +157,25 @@ pub struct ip_frag_pkt__bindgen_ty_1 { } #[test] fn bindgen_test_layout_ip_frag_pkt__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 16usize, + ::std::mem::size_of:: < ip_frag_pkt__bindgen_ty_1 > (), 16usize, concat!("Size of: ", stringify!(ip_frag_pkt__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, + ::std::mem::align_of:: < ip_frag_pkt__bindgen_ty_1 > (), 8usize, concat!("Alignment of ", stringify!(ip_frag_pkt__bindgen_ty_1)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).tqe_next) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt__bindgen_ty_1), - "::", - stringify!(tqe_next) - ) + unsafe { ::std::ptr::addr_of!((* ptr).tqe_next) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(ip_frag_pkt__bindgen_ty_1), "::", + stringify!(tqe_next)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).tqe_prev) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt__bindgen_ty_1), - "::", - stringify!(tqe_prev) - ) + unsafe { ::std::ptr::addr_of!((* ptr).tqe_prev) as usize - ptr as usize }, + 8usize, concat!("Offset of field: ", stringify!(ip_frag_pkt__bindgen_ty_1), "::", + stringify!(tqe_prev)) ); } impl Default for ip_frag_pkt__bindgen_ty_1 { @@ -253,94 +189,46 @@ 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(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 192usize, - concat!("Size of: ", stringify!(ip_frag_pkt)) + ::std::mem::size_of:: < ip_frag_pkt > (), 192usize, concat!("Size of: ", + stringify!(ip_frag_pkt)) ); assert_eq!( - ::std::mem::align_of::(), - 64usize, - concat!("Alignment of ", stringify!(ip_frag_pkt)) + ::std::mem::align_of:: < ip_frag_pkt > (), 64usize, concat!("Alignment of ", + stringify!(ip_frag_pkt)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).lru) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(lru) - ) + unsafe { ::std::ptr::addr_of!((* ptr).lru) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", stringify!(lru)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).key) as usize - ptr as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(key) - ) + unsafe { ::std::ptr::addr_of!((* ptr).key) as usize - ptr as usize }, 16usize, + concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", stringify!(key)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).start) as usize - ptr as usize }, - 56usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(start) - ) + unsafe { ::std::ptr::addr_of!((* ptr).start) as usize - ptr as usize }, 56usize, + concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", stringify!(start)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).total_size) as usize - ptr as usize - }, - 64usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(total_size) - ) + unsafe { ::std::ptr::addr_of!((* ptr).total_size) as usize - ptr as usize }, + 64usize, concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", + stringify!(total_size)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).frag_size) as usize - ptr as usize - }, - 68usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(frag_size) - ) + unsafe { ::std::ptr::addr_of!((* ptr).frag_size) as usize - ptr as usize }, + 68usize, concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", + stringify!(frag_size)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).last_idx) as usize - ptr as usize - }, - 72usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(last_idx) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).frags) as usize - ptr as usize }, - 80usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(frags) - ) + unsafe { ::std::ptr::addr_of!((* ptr).last_idx) as usize - ptr as usize }, + 72usize, concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", + stringify!(last_idx)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).frags) as usize - ptr as usize }, 80usize, + concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", stringify!(frags)) ); } impl Default for ip_frag_pkt { @@ -360,42 +248,25 @@ pub struct ip_pkt_list { } #[test] fn bindgen_test_layout_ip_pkt_list() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(ip_pkt_list)) + ::std::mem::size_of:: < ip_pkt_list > (), 16usize, concat!("Size of: ", + stringify!(ip_pkt_list)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(ip_pkt_list)) + ::std::mem::align_of:: < ip_pkt_list > (), 8usize, concat!("Alignment of ", + stringify!(ip_pkt_list)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).tqh_first) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ip_pkt_list), - "::", - stringify!(tqh_first) - ) + unsafe { ::std::ptr::addr_of!((* ptr).tqh_first) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(ip_pkt_list), "::", + stringify!(tqh_first)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).tqh_last) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(ip_pkt_list), - "::", - stringify!(tqh_last) - ) + unsafe { ::std::ptr::addr_of!((* ptr).tqh_last) as usize - ptr as usize }, + 8usize, concat!("Offset of field: ", stringify!(ip_pkt_list), "::", + stringify!(tqh_last)) ); } impl Default for ip_pkt_list { @@ -427,86 +298,45 @@ pub struct ip_frag_tbl_stat { } #[test] fn bindgen_test_layout_ip_frag_tbl_stat() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 64usize, - concat!("Size of: ", stringify!(ip_frag_tbl_stat)) + ::std::mem::size_of:: < ip_frag_tbl_stat > (), 64usize, concat!("Size of: ", + stringify!(ip_frag_tbl_stat)) ); assert_eq!( - ::std::mem::align_of::(), - 64usize, - concat!("Alignment of ", stringify!(ip_frag_tbl_stat)) + ::std::mem::align_of:: < ip_frag_tbl_stat > (), 64usize, concat!("Alignment of ", + stringify!(ip_frag_tbl_stat)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).find_num) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_tbl_stat), - "::", - stringify!(find_num) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).add_num) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_tbl_stat), - "::", - stringify!(add_num) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).del_num) as usize - ptr as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_tbl_stat), - "::", - stringify!(del_num) - ) + unsafe { ::std::ptr::addr_of!((* ptr).find_num) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(ip_frag_tbl_stat), "::", + stringify!(find_num)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).reuse_num) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_tbl_stat), - "::", - stringify!(reuse_num) - ) + unsafe { ::std::ptr::addr_of!((* ptr).add_num) as usize - ptr as usize }, 8usize, + concat!("Offset of field: ", stringify!(ip_frag_tbl_stat), "::", + stringify!(add_num)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).fail_total) as usize - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_tbl_stat), - "::", - stringify!(fail_total) - ) + unsafe { ::std::ptr::addr_of!((* ptr).del_num) as usize - ptr as usize }, + 16usize, concat!("Offset of field: ", stringify!(ip_frag_tbl_stat), "::", + stringify!(del_num)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).fail_nospace) as usize - ptr as usize - }, - 40usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_tbl_stat), - "::", - stringify!(fail_nospace) - ) + unsafe { ::std::ptr::addr_of!((* ptr).reuse_num) as usize - ptr as usize }, + 24usize, concat!("Offset of field: ", stringify!(ip_frag_tbl_stat), "::", + stringify!(reuse_num)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).fail_total) as usize - ptr as usize }, + 32usize, concat!("Offset of field: ", stringify!(ip_frag_tbl_stat), "::", + stringify!(fail_total)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).fail_nospace) as usize - ptr as usize }, + 40usize, concat!("Offset of field: ", stringify!(ip_frag_tbl_stat), "::", + stringify!(fail_nospace)) ); } impl Default for ip_frag_tbl_stat { @@ -548,142 +378,66 @@ pub struct rte_ip_frag_tbl { } #[test] fn bindgen_test_layout_rte_ip_frag_tbl() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 128usize, - concat!("Size of: ", stringify!(rte_ip_frag_tbl)) + ::std::mem::size_of:: < rte_ip_frag_tbl > (), 128usize, concat!("Size of: ", + stringify!(rte_ip_frag_tbl)) ); assert_eq!( - ::std::mem::align_of::(), - 64usize, - concat!("Alignment of ", stringify!(rte_ip_frag_tbl)) + ::std::mem::align_of:: < rte_ip_frag_tbl > (), 64usize, concat!("Alignment of ", + stringify!(rte_ip_frag_tbl)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).max_cycles) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(max_cycles) - ) + unsafe { ::std::ptr::addr_of!((* ptr).max_cycles) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_ip_frag_tbl), "::", + stringify!(max_cycles)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).entry_mask) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(entry_mask) - ) + unsafe { ::std::ptr::addr_of!((* ptr).entry_mask) as usize - ptr as usize }, + 8usize, concat!("Offset of field: ", stringify!(rte_ip_frag_tbl), "::", + stringify!(entry_mask)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).max_entries) as usize - ptr as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(max_entries) - ) + unsafe { ::std::ptr::addr_of!((* ptr).max_entries) as usize - ptr as usize }, + 12usize, concat!("Offset of field: ", stringify!(rte_ip_frag_tbl), "::", + stringify!(max_entries)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).use_entries) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(use_entries) - ) + unsafe { ::std::ptr::addr_of!((* ptr).use_entries) as usize - ptr as usize }, + 16usize, concat!("Offset of field: ", stringify!(rte_ip_frag_tbl), "::", + stringify!(use_entries)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).bucket_entries) as usize - ptr as usize - }, - 20usize, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(bucket_entries) - ) + unsafe { ::std::ptr::addr_of!((* ptr).bucket_entries) as usize - ptr as usize }, + 20usize, concat!("Offset of field: ", stringify!(rte_ip_frag_tbl), "::", + stringify!(bucket_entries)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).nb_entries) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(nb_entries) - ) + unsafe { ::std::ptr::addr_of!((* ptr).nb_entries) as usize - ptr as usize }, + 24usize, concat!("Offset of field: ", stringify!(rte_ip_frag_tbl), "::", + stringify!(nb_entries)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).nb_buckets) as usize - ptr as usize - }, - 28usize, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(nb_buckets) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).last) as usize - ptr as usize }, - 32usize, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(last) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).lru) as usize - ptr as usize }, - 40usize, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(lru) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).stat) as usize - ptr as usize }, - 64usize, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(stat) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).pkt) as usize - ptr as usize }, - 128usize, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(pkt) - ) + unsafe { ::std::ptr::addr_of!((* ptr).nb_buckets) as usize - ptr as usize }, + 28usize, concat!("Offset of field: ", stringify!(rte_ip_frag_tbl), "::", + stringify!(nb_buckets)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).last) as usize - ptr as usize }, 32usize, + concat!("Offset of field: ", stringify!(rte_ip_frag_tbl), "::", stringify!(last)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).lru) as usize - ptr as usize }, 40usize, + concat!("Offset of field: ", stringify!(rte_ip_frag_tbl), "::", stringify!(lru)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).stat) as usize - ptr as usize }, 64usize, + concat!("Offset of field: ", stringify!(rte_ip_frag_tbl), "::", stringify!(stat)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).pkt) as usize - ptr as usize }, 128usize, + concat!("Offset of field: ", stringify!(rte_ip_frag_tbl), "::", stringify!(pkt)) ); } impl Default for rte_ip_frag_tbl { diff --git a/bindgen-tests/tests/expectations/tests/layout_mbuf.rs b/bindgen-tests/tests/expectations/tests/layout_mbuf.rs index 800a303be1..04e8a37efd 100644 --- a/bindgen-tests/tests/expectations/tests/layout_mbuf.rs +++ b/bindgen-tests/tests/expectations/tests/layout_mbuf.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -106,28 +98,19 @@ pub struct rte_atomic16_t { } #[test] fn bindgen_test_layout_rte_atomic16_t() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 2usize, - concat!("Size of: ", stringify!(rte_atomic16_t)) + ::std::mem::size_of:: < rte_atomic16_t > (), 2usize, concat!("Size of: ", + stringify!(rte_atomic16_t)) ); assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(rte_atomic16_t)) + ::std::mem::align_of:: < rte_atomic16_t > (), 2usize, concat!("Alignment of ", + stringify!(rte_atomic16_t)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).cnt) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_atomic16_t), - "::", - stringify!(cnt) - ) + unsafe { ::std::ptr::addr_of!((* ptr).cnt) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_atomic16_t), "::", stringify!(cnt)) ); } /// The generic rte_mbuf, containing a packet mbuf. @@ -171,18 +154,18 @@ pub struct rte_mbuf { ///< Next segment of scattered packet. pub next: *mut rte_mbuf, pub __bindgen_anon_4: rte_mbuf__bindgen_ty_5, - /// Size of the application private data. In case of an indirect - /// mbuf, it stores the direct mbuf private data size. + /** Size of the application private data. In case of an indirect + mbuf, it stores the direct mbuf private data size.*/ pub priv_size: u16, /// Timesync flags for use with IEEE1588. pub timesync: u16, } -/// 16-bit Reference counter. -/// It should only be accessed using the following functions: -/// rte_mbuf_refcnt_update(), rte_mbuf_refcnt_read(), and -/// rte_mbuf_refcnt_set(). The functionality of these functions (atomic, -/// or non-atomic) is controlled by the CONFIG_RTE_MBUF_REFCNT_ATOMIC -/// config option. +/** 16-bit Reference counter. + It should only be accessed using the following functions: + rte_mbuf_refcnt_update(), rte_mbuf_refcnt_read(), and + rte_mbuf_refcnt_set(). The functionality of these functions (atomic, + or non-atomic) is controlled by the CONFIG_RTE_MBUF_REFCNT_ATOMIC + config option.*/ #[repr(C)] #[derive(Copy, Clone)] pub union rte_mbuf__bindgen_ty_1 { @@ -193,40 +176,25 @@ pub union rte_mbuf__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 2usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_1)) + ::std::mem::size_of:: < rte_mbuf__bindgen_ty_1 > (), 2usize, concat!("Size of: ", + stringify!(rte_mbuf__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 2usize, + ::std::mem::align_of:: < rte_mbuf__bindgen_ty_1 > (), 2usize, concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_1)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).refcnt_atomic) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_1), - "::", - stringify!(refcnt_atomic) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).refcnt) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_1), - "::", - stringify!(refcnt) - ) + unsafe { ::std::ptr::addr_of!((* ptr).refcnt_atomic) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_1), "::", + stringify!(refcnt_atomic)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).refcnt) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_1), "::", + stringify!(refcnt)) ); } impl Default for rte_mbuf__bindgen_ty_1 { @@ -255,28 +223,18 @@ pub struct rte_mbuf__bindgen_ty_2__bindgen_ty_1 { #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_2__bindgen_ty_1() { assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!( - "Size of: ", - stringify!(rte_mbuf__bindgen_ty_2__bindgen_ty_1) - ) + ::std::mem::size_of:: < rte_mbuf__bindgen_ty_2__bindgen_ty_1 > (), 4usize, + concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_2__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!( - "Alignment of ", - stringify!(rte_mbuf__bindgen_ty_2__bindgen_ty_1) - ) + ::std::mem::align_of:: < rte_mbuf__bindgen_ty_2__bindgen_ty_1 > (), 4usize, + concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_2__bindgen_ty_1)) ); } impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { #[inline] pub fn l2_type(&self) -> u32 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 4u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 4u8) as u32) } } #[inline] pub fn set_l2_type(&mut self, val: u32) { @@ -287,9 +245,7 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } #[inline] pub fn l3_type(&self) -> u32 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(4usize, 4u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(4usize, 4u8) as u32) } } #[inline] pub fn set_l3_type(&mut self, val: u32) { @@ -300,9 +256,7 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } #[inline] pub fn l4_type(&self) -> u32 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(8usize, 4u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(8usize, 4u8) as u32) } } #[inline] pub fn set_l4_type(&mut self, val: u32) { @@ -313,9 +267,7 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } #[inline] pub fn tun_type(&self) -> u32 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(12usize, 4u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(12usize, 4u8) as u32) } } #[inline] pub fn set_tun_type(&mut self, val: u32) { @@ -326,9 +278,7 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } #[inline] pub fn inner_l2_type(&self) -> u32 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(16usize, 4u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(16usize, 4u8) as u32) } } #[inline] pub fn set_inner_l2_type(&mut self, val: u32) { @@ -339,9 +289,7 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } #[inline] pub fn inner_l3_type(&self) -> u32 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(20usize, 4u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(20usize, 4u8) as u32) } } #[inline] pub fn set_inner_l3_type(&mut self, val: u32) { @@ -352,9 +300,7 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } #[inline] pub fn inner_l4_type(&self) -> u32 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(24usize, 4u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(24usize, 4u8) as u32) } } #[inline] pub fn set_inner_l4_type(&mut self, val: u32) { @@ -373,68 +319,95 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { inner_l3_type: u32, inner_l4_type: u32, ) -> __BindgenBitfieldUnit<[u8; 4usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 4u8, { - let l2_type: u32 = unsafe { ::std::mem::transmute(l2_type) }; - l2_type as u64 - }); - __bindgen_bitfield_unit.set(4usize, 4u8, { - let l3_type: u32 = unsafe { ::std::mem::transmute(l3_type) }; - l3_type as u64 - }); - __bindgen_bitfield_unit.set(8usize, 4u8, { - let l4_type: u32 = unsafe { ::std::mem::transmute(l4_type) }; - l4_type as u64 - }); - __bindgen_bitfield_unit.set(12usize, 4u8, { - let tun_type: u32 = unsafe { ::std::mem::transmute(tun_type) }; - tun_type as u64 - }); - __bindgen_bitfield_unit.set(16usize, 4u8, { - let inner_l2_type: u32 = - unsafe { ::std::mem::transmute(inner_l2_type) }; - inner_l2_type as u64 - }); - __bindgen_bitfield_unit.set(20usize, 4u8, { - let inner_l3_type: u32 = - unsafe { ::std::mem::transmute(inner_l3_type) }; - inner_l3_type as u64 - }); - __bindgen_bitfield_unit.set(24usize, 4u8, { - let inner_l4_type: u32 = - unsafe { ::std::mem::transmute(inner_l4_type) }; - inner_l4_type as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 4u8, + { + let l2_type: u32 = unsafe { ::std::mem::transmute(l2_type) }; + l2_type as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 4usize, + 4u8, + { + let l3_type: u32 = unsafe { ::std::mem::transmute(l3_type) }; + l3_type as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 8usize, + 4u8, + { + let l4_type: u32 = unsafe { ::std::mem::transmute(l4_type) }; + l4_type as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 12usize, + 4u8, + { + let tun_type: u32 = unsafe { ::std::mem::transmute(tun_type) }; + tun_type as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 16usize, + 4u8, + { + let inner_l2_type: u32 = unsafe { + ::std::mem::transmute(inner_l2_type) + }; + inner_l2_type as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 20usize, + 4u8, + { + let inner_l3_type: u32 = unsafe { + ::std::mem::transmute(inner_l3_type) + }; + inner_l3_type as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 24usize, + 4u8, + { + let inner_l4_type: u32 = unsafe { + ::std::mem::transmute(inner_l4_type) + }; + inner_l4_type as u64 + }, + ); __bindgen_bitfield_unit } } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_2)) + ::std::mem::size_of:: < rte_mbuf__bindgen_ty_2 > (), 4usize, concat!("Size of: ", + stringify!(rte_mbuf__bindgen_ty_2)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < rte_mbuf__bindgen_ty_2 > (), 4usize, concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_2)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).packet_type) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_2), - "::", - stringify!(packet_type) - ) + unsafe { ::std::ptr::addr_of!((* ptr).packet_type) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_2), "::", + stringify!(packet_type)) ); } impl Default for rte_mbuf__bindgen_ty_2 { @@ -467,8 +440,7 @@ pub struct rte_mbuf__bindgen_ty_3__bindgen_ty_1 { #[repr(C)] #[derive(Copy, Clone)] pub union rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 { - pub __bindgen_anon_1: - rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1, + pub __bindgen_anon_1: rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1, pub lo: u32, } #[repr(C)] @@ -478,16 +450,35 @@ pub struct rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 { pub id: u16, } #[test] -fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1( -) { +fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit< rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1, > = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq ! (:: std :: mem :: size_of :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > () , 4usize , concat ! ("Size of: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1))); - assert_eq ! (:: std :: mem :: align_of :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > () , 2usize , concat ! ("Alignment of " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1))); - assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . hash) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (hash))); - assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . id) as usize - ptr as usize } , 2usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (id))); + assert_eq!( + ::std::mem::size_of:: < + rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > (), 4usize, + concat!("Size of: ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1)) + ); + assert_eq!( + ::std::mem::align_of:: < + rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > (), 2usize, + concat!("Alignment of ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).hash) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1), + "::", stringify!(hash)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).id) as usize - ptr as usize }, 2usize, + concat!("Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1), + "::", stringify!(id)) + ); } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1() { @@ -496,33 +487,20 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1() { > = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::( - ), - 4usize, - concat!( - "Size of: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1) - ) - ); - assert_eq!( - ::std::mem::align_of::< - rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1, - >(), - 4usize, - concat!( - "Alignment of ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).lo) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(lo) - ) + ::std::mem::size_of:: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 > (), + 4usize, concat!("Size of: ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1)) + ); + assert_eq!( + ::std::mem::align_of:: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 > (), + 4usize, concat!("Alignment of ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).lo) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1), "::", + stringify!(lo)) ); } impl Default for rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 { @@ -536,35 +514,20 @@ impl Default for rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit< - rte_mbuf__bindgen_ty_3__bindgen_ty_1, - > = ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!( - "Size of: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1) - ) + ::std::mem::size_of:: < rte_mbuf__bindgen_ty_3__bindgen_ty_1 > (), 8usize, + concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!( - "Alignment of ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1) - ) + ::std::mem::align_of:: < rte_mbuf__bindgen_ty_3__bindgen_ty_1 > (), 4usize, + concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).hi) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1), - "::", - stringify!(hi) - ) + unsafe { ::std::ptr::addr_of!((* ptr).hi) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1), + "::", stringify!(hi)) ); } impl Default for rte_mbuf__bindgen_ty_3__bindgen_ty_1 { @@ -584,101 +547,58 @@ pub struct rte_mbuf__bindgen_ty_3__bindgen_ty_2 { } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit< - rte_mbuf__bindgen_ty_3__bindgen_ty_2, - > = ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!( - "Size of: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2) - ) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!( - "Alignment of ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).lo) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2), - "::", - stringify!(lo) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).hi) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2), - "::", - stringify!(hi) - ) + ::std::mem::size_of:: < rte_mbuf__bindgen_ty_3__bindgen_ty_2 > (), 8usize, + concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2)) + ); + assert_eq!( + ::std::mem::align_of:: < rte_mbuf__bindgen_ty_3__bindgen_ty_2 > (), 4usize, + concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).lo) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2), + "::", stringify!(lo)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).hi) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2), + "::", stringify!(hi)) ); } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_3() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_3)) + ::std::mem::size_of:: < rte_mbuf__bindgen_ty_3 > (), 8usize, concat!("Size of: ", + stringify!(rte_mbuf__bindgen_ty_3)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < rte_mbuf__bindgen_ty_3 > (), 4usize, concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_3)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).rss) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(rss) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).fdir) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(fdir) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).sched) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(sched) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).usr) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(usr) - ) + unsafe { ::std::ptr::addr_of!((* ptr).rss) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_3), "::", + stringify!(rss)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).fdir) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_3), "::", + stringify!(fdir)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).sched) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_3), "::", + stringify!(sched)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).usr) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_3), "::", + stringify!(usr)) ); } impl Default for rte_mbuf__bindgen_ty_3 { @@ -700,40 +620,25 @@ pub union rte_mbuf__bindgen_ty_4 { } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_4() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_4)) + ::std::mem::size_of:: < rte_mbuf__bindgen_ty_4 > (), 8usize, concat!("Size of: ", + stringify!(rte_mbuf__bindgen_ty_4)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, + ::std::mem::align_of:: < rte_mbuf__bindgen_ty_4 > (), 8usize, concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_4)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).userdata) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_4), - "::", - stringify!(userdata) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).udata64) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_4), - "::", - stringify!(udata64) - ) + unsafe { ::std::ptr::addr_of!((* ptr).userdata) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_4), "::", + stringify!(userdata)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).udata64) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_4), "::", + stringify!(udata64)) ); } impl Default for rte_mbuf__bindgen_ty_4 { @@ -762,28 +667,18 @@ pub struct rte_mbuf__bindgen_ty_5__bindgen_ty_1 { #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_5__bindgen_ty_1() { assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!( - "Size of: ", - stringify!(rte_mbuf__bindgen_ty_5__bindgen_ty_1) - ) + ::std::mem::size_of:: < rte_mbuf__bindgen_ty_5__bindgen_ty_1 > (), 8usize, + concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_5__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!( - "Alignment of ", - stringify!(rte_mbuf__bindgen_ty_5__bindgen_ty_1) - ) + ::std::mem::align_of:: < rte_mbuf__bindgen_ty_5__bindgen_ty_1 > (), 8usize, + concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_5__bindgen_ty_1)) ); } impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { #[inline] pub fn l2_len(&self) -> u64 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 7u8) as u64) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 7u8) as u64) } } #[inline] pub fn set_l2_len(&mut self, val: u64) { @@ -794,9 +689,7 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { } #[inline] pub fn l3_len(&self) -> u64 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(7usize, 9u8) as u64) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(7usize, 9u8) as u64) } } #[inline] pub fn set_l3_len(&mut self, val: u64) { @@ -807,9 +700,7 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { } #[inline] pub fn l4_len(&self) -> u64 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(16usize, 8u8) as u64) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(16usize, 8u8) as u64) } } #[inline] pub fn set_l4_len(&mut self, val: u64) { @@ -820,9 +711,7 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { } #[inline] pub fn tso_segsz(&self) -> u64 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(24usize, 16u8) as u64) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(24usize, 16u8) as u64) } } #[inline] pub fn set_tso_segsz(&mut self, val: u64) { @@ -833,9 +722,7 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { } #[inline] pub fn outer_l3_len(&self) -> u64 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(40usize, 9u8) as u64) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(40usize, 9u8) as u64) } } #[inline] pub fn set_outer_l3_len(&mut self, val: u64) { @@ -846,9 +733,7 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { } #[inline] pub fn outer_l2_len(&self) -> u64 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(49usize, 7u8) as u64) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(49usize, 7u8) as u64) } } #[inline] pub fn set_outer_l2_len(&mut self, val: u64) { @@ -866,63 +751,84 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { outer_l3_len: u64, outer_l2_len: u64, ) -> __BindgenBitfieldUnit<[u8; 7usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 7usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 7u8, { - let l2_len: u64 = unsafe { ::std::mem::transmute(l2_len) }; - l2_len as u64 - }); - __bindgen_bitfield_unit.set(7usize, 9u8, { - let l3_len: u64 = unsafe { ::std::mem::transmute(l3_len) }; - l3_len as u64 - }); - __bindgen_bitfield_unit.set(16usize, 8u8, { - let l4_len: u64 = unsafe { ::std::mem::transmute(l4_len) }; - l4_len as u64 - }); - __bindgen_bitfield_unit.set(24usize, 16u8, { - let tso_segsz: u64 = unsafe { ::std::mem::transmute(tso_segsz) }; - tso_segsz as u64 - }); - __bindgen_bitfield_unit.set(40usize, 9u8, { - let outer_l3_len: u64 = - unsafe { ::std::mem::transmute(outer_l3_len) }; - outer_l3_len as u64 - }); - __bindgen_bitfield_unit.set(49usize, 7u8, { - let outer_l2_len: u64 = - unsafe { ::std::mem::transmute(outer_l2_len) }; - outer_l2_len as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 7usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 7u8, + { + let l2_len: u64 = unsafe { ::std::mem::transmute(l2_len) }; + l2_len as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 7usize, + 9u8, + { + let l3_len: u64 = unsafe { ::std::mem::transmute(l3_len) }; + l3_len as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 16usize, + 8u8, + { + let l4_len: u64 = unsafe { ::std::mem::transmute(l4_len) }; + l4_len as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 24usize, + 16u8, + { + let tso_segsz: u64 = unsafe { ::std::mem::transmute(tso_segsz) }; + tso_segsz as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 40usize, + 9u8, + { + let outer_l3_len: u64 = unsafe { + ::std::mem::transmute(outer_l3_len) + }; + outer_l3_len as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 49usize, + 7u8, + { + let outer_l2_len: u64 = unsafe { + ::std::mem::transmute(outer_l2_len) + }; + outer_l2_len as u64 + }, + ); __bindgen_bitfield_unit } } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_5() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_5)) + ::std::mem::size_of:: < rte_mbuf__bindgen_ty_5 > (), 8usize, concat!("Size of: ", + stringify!(rte_mbuf__bindgen_ty_5)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, + ::std::mem::align_of:: < rte_mbuf__bindgen_ty_5 > (), 8usize, concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_5)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).tx_offload) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_5), - "::", - stringify!(tx_offload) - ) + unsafe { ::std::ptr::addr_of!((* ptr).tx_offload) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_5), "::", + stringify!(tx_offload)) ); } impl Default for rte_mbuf__bindgen_ty_5 { @@ -936,255 +842,115 @@ impl Default for rte_mbuf__bindgen_ty_5 { } #[test] fn bindgen_test_layout_rte_mbuf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 128usize, - concat!("Size of: ", stringify!(rte_mbuf)) + ::std::mem::size_of:: < rte_mbuf > (), 128usize, concat!("Size of: ", + stringify!(rte_mbuf)) ); assert_eq!( - ::std::mem::align_of::(), - 64usize, - concat!("Alignment of ", stringify!(rte_mbuf)) + ::std::mem::align_of:: < rte_mbuf > (), 64usize, concat!("Alignment of ", + stringify!(rte_mbuf)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).cacheline0) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(cacheline0) - ) + unsafe { ::std::ptr::addr_of!((* ptr).cacheline0) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", + stringify!(cacheline0)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).buf_addr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(buf_addr) - ) + unsafe { ::std::ptr::addr_of!((* ptr).buf_addr) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", + stringify!(buf_addr)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).buf_physaddr) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(buf_physaddr) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).buf_len) as usize - ptr as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(buf_len) - ) + unsafe { ::std::ptr::addr_of!((* ptr).buf_physaddr) as usize - ptr as usize }, + 8usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", + stringify!(buf_physaddr)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).rearm_data) as usize - ptr as usize - }, - 18usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(rearm_data) - ) + unsafe { ::std::ptr::addr_of!((* ptr).buf_len) as usize - ptr as usize }, + 16usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", + stringify!(buf_len)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).data_off) as usize - ptr as usize - }, - 18usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(data_off) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).nb_segs) as usize - ptr as usize }, - 22usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(nb_segs) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).port) as usize - ptr as usize }, - 23usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(port) - ) + unsafe { ::std::ptr::addr_of!((* ptr).rearm_data) as usize - ptr as usize }, + 18usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", + stringify!(rearm_data)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).ol_flags) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(ol_flags) - ) + unsafe { ::std::ptr::addr_of!((* ptr).data_off) as usize - ptr as usize }, + 18usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", + stringify!(data_off)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).rx_descriptor_fields1) as usize - - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(rx_descriptor_fields1) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).pkt_len) as usize - ptr as usize }, - 36usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(pkt_len) - ) + unsafe { ::std::ptr::addr_of!((* ptr).nb_segs) as usize - ptr as usize }, + 22usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", + stringify!(nb_segs)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).data_len) as usize - ptr as usize - }, - 40usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(data_len) - ) + unsafe { ::std::ptr::addr_of!((* ptr).port) as usize - ptr as usize }, 23usize, + concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(port)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).vlan_tci) as usize - ptr as usize - }, - 42usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(vlan_tci) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).hash) as usize - ptr as usize }, - 44usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(hash) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).seqn) as usize - ptr as usize }, - 52usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(seqn) - ) + unsafe { ::std::ptr::addr_of!((* ptr).ol_flags) as usize - ptr as usize }, + 24usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", + stringify!(ol_flags)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).vlan_tci_outer) as usize - ptr as usize - }, - 56usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(vlan_tci_outer) - ) + unsafe { ::std::ptr::addr_of!((* ptr).rx_descriptor_fields1) as usize - ptr as + usize }, 32usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", + stringify!(rx_descriptor_fields1)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).cacheline1) as usize - ptr as usize - }, - 64usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(cacheline1) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).pool) as usize - ptr as usize }, - 72usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(pool) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize }, - 80usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(next) - ) + unsafe { ::std::ptr::addr_of!((* ptr).pkt_len) as usize - ptr as usize }, + 36usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", + stringify!(pkt_len)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).priv_size) as usize - ptr as usize - }, - 96usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(priv_size) - ) + unsafe { ::std::ptr::addr_of!((* ptr).data_len) as usize - ptr as usize }, + 40usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", + stringify!(data_len)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).timesync) as usize - ptr as usize - }, - 98usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(timesync) - ) + unsafe { ::std::ptr::addr_of!((* ptr).vlan_tci) as usize - ptr as usize }, + 42usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", + stringify!(vlan_tci)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).hash) as usize - ptr as usize }, 44usize, + concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(hash)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).seqn) as usize - ptr as usize }, 52usize, + concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(seqn)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).vlan_tci_outer) as usize - ptr as usize }, + 56usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", + stringify!(vlan_tci_outer)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).cacheline1) as usize - ptr as usize }, + 64usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", + stringify!(cacheline1)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).pool) as usize - ptr as usize }, 72usize, + concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(pool)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).next) as usize - ptr as usize }, 80usize, + concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(next)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).priv_size) as usize - ptr as usize }, + 96usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", + stringify!(priv_size)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).timesync) as usize - ptr as usize }, + 98usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", + stringify!(timesync)) ); } impl Default for rte_mbuf { diff --git a/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs b/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs index 90f7ed09b2..96f8cb176c 100644 --- a/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -149,28 +141,19 @@ pub struct rte_atomic16_t { } #[test] fn bindgen_test_layout_rte_atomic16_t() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 2usize, - concat!("Size of: ", stringify!(rte_atomic16_t)) + ::std::mem::size_of:: < rte_atomic16_t > (), 2usize, concat!("Size of: ", + stringify!(rte_atomic16_t)) ); assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(rte_atomic16_t)) + ::std::mem::align_of:: < rte_atomic16_t > (), 2usize, concat!("Alignment of ", + stringify!(rte_atomic16_t)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).cnt) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_atomic16_t), - "::", - stringify!(cnt) - ) + unsafe { ::std::ptr::addr_of!((* ptr).cnt) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_atomic16_t), "::", stringify!(cnt)) ); } impl Clone for rte_atomic16_t { @@ -218,19 +201,19 @@ pub struct rte_mbuf { ///< Next segment of scattered packet. pub next: *mut rte_mbuf, pub __bindgen_anon_4: rte_mbuf__bindgen_ty_5, - /// Size of the application private data. In case of an indirect - /// mbuf, it stores the direct mbuf private data size. + /** Size of the application private data. In case of an indirect + mbuf, it stores the direct mbuf private data size.*/ pub priv_size: u16, /// Timesync flags for use with IEEE1588. pub timesync: u16, pub __bindgen_padding_0: [u32; 7usize], } -/// 16-bit Reference counter. -/// It should only be accessed using the following functions: -/// rte_mbuf_refcnt_update(), rte_mbuf_refcnt_read(), and -/// rte_mbuf_refcnt_set(). The functionality of these functions (atomic, -/// or non-atomic) is controlled by the CONFIG_RTE_MBUF_REFCNT_ATOMIC -/// config option. +/** 16-bit Reference counter. + It should only be accessed using the following functions: + rte_mbuf_refcnt_update(), rte_mbuf_refcnt_read(), and + rte_mbuf_refcnt_set(). The functionality of these functions (atomic, + or non-atomic) is controlled by the CONFIG_RTE_MBUF_REFCNT_ATOMIC + config option.*/ #[repr(C)] #[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] pub struct rte_mbuf__bindgen_ty_1 { @@ -242,40 +225,25 @@ pub struct rte_mbuf__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 2usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_1)) + ::std::mem::size_of:: < rte_mbuf__bindgen_ty_1 > (), 2usize, concat!("Size of: ", + stringify!(rte_mbuf__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 2usize, + ::std::mem::align_of:: < rte_mbuf__bindgen_ty_1 > (), 2usize, concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_1)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).refcnt_atomic) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_1), - "::", - stringify!(refcnt_atomic) - ) + unsafe { ::std::ptr::addr_of!((* ptr).refcnt_atomic) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_1), "::", + stringify!(refcnt_atomic)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).refcnt) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_1), - "::", - stringify!(refcnt) - ) + unsafe { ::std::ptr::addr_of!((* ptr).refcnt) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_1), "::", + stringify!(refcnt)) ); } impl Clone for rte_mbuf__bindgen_ty_1 { @@ -288,8 +256,7 @@ impl Clone for rte_mbuf__bindgen_ty_1 { pub struct rte_mbuf__bindgen_ty_2 { ///< L2/L3/L4 and tunnel information. pub packet_type: __BindgenUnionField, - pub __bindgen_anon_1: - __BindgenUnionField, + pub __bindgen_anon_1: __BindgenUnionField, pub bindgen_union_field: u32, } #[repr(C)] @@ -302,20 +269,12 @@ pub struct rte_mbuf__bindgen_ty_2__bindgen_ty_1 { #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_2__bindgen_ty_1() { assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!( - "Size of: ", - stringify!(rte_mbuf__bindgen_ty_2__bindgen_ty_1) - ) + ::std::mem::size_of:: < rte_mbuf__bindgen_ty_2__bindgen_ty_1 > (), 4usize, + concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_2__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!( - "Alignment of ", - stringify!(rte_mbuf__bindgen_ty_2__bindgen_ty_1) - ) + ::std::mem::align_of:: < rte_mbuf__bindgen_ty_2__bindgen_ty_1 > (), 4usize, + concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_2__bindgen_ty_1)) ); } impl Clone for rte_mbuf__bindgen_ty_2__bindgen_ty_1 { @@ -326,9 +285,7 @@ impl Clone for rte_mbuf__bindgen_ty_2__bindgen_ty_1 { impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { #[inline] pub fn l2_type(&self) -> u32 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 4u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 4u8) as u32) } } #[inline] pub fn set_l2_type(&mut self, val: u32) { @@ -339,9 +296,7 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } #[inline] pub fn l3_type(&self) -> u32 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(4usize, 4u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(4usize, 4u8) as u32) } } #[inline] pub fn set_l3_type(&mut self, val: u32) { @@ -352,9 +307,7 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } #[inline] pub fn l4_type(&self) -> u32 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(8usize, 4u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(8usize, 4u8) as u32) } } #[inline] pub fn set_l4_type(&mut self, val: u32) { @@ -365,9 +318,7 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } #[inline] pub fn tun_type(&self) -> u32 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(12usize, 4u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(12usize, 4u8) as u32) } } #[inline] pub fn set_tun_type(&mut self, val: u32) { @@ -378,9 +329,7 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } #[inline] pub fn inner_l2_type(&self) -> u32 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(16usize, 4u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(16usize, 4u8) as u32) } } #[inline] pub fn set_inner_l2_type(&mut self, val: u32) { @@ -391,9 +340,7 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } #[inline] pub fn inner_l3_type(&self) -> u32 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(20usize, 4u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(20usize, 4u8) as u32) } } #[inline] pub fn set_inner_l3_type(&mut self, val: u32) { @@ -404,9 +351,7 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } #[inline] pub fn inner_l4_type(&self) -> u32 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(24usize, 4u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(24usize, 4u8) as u32) } } #[inline] pub fn set_inner_l4_type(&mut self, val: u32) { @@ -425,68 +370,95 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { inner_l3_type: u32, inner_l4_type: u32, ) -> __BindgenBitfieldUnit<[u8; 4usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 4u8, { - let l2_type: u32 = unsafe { ::std::mem::transmute(l2_type) }; - l2_type as u64 - }); - __bindgen_bitfield_unit.set(4usize, 4u8, { - let l3_type: u32 = unsafe { ::std::mem::transmute(l3_type) }; - l3_type as u64 - }); - __bindgen_bitfield_unit.set(8usize, 4u8, { - let l4_type: u32 = unsafe { ::std::mem::transmute(l4_type) }; - l4_type as u64 - }); - __bindgen_bitfield_unit.set(12usize, 4u8, { - let tun_type: u32 = unsafe { ::std::mem::transmute(tun_type) }; - tun_type as u64 - }); - __bindgen_bitfield_unit.set(16usize, 4u8, { - let inner_l2_type: u32 = - unsafe { ::std::mem::transmute(inner_l2_type) }; - inner_l2_type as u64 - }); - __bindgen_bitfield_unit.set(20usize, 4u8, { - let inner_l3_type: u32 = - unsafe { ::std::mem::transmute(inner_l3_type) }; - inner_l3_type as u64 - }); - __bindgen_bitfield_unit.set(24usize, 4u8, { - let inner_l4_type: u32 = - unsafe { ::std::mem::transmute(inner_l4_type) }; - inner_l4_type as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 4u8, + { + let l2_type: u32 = unsafe { ::std::mem::transmute(l2_type) }; + l2_type as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 4usize, + 4u8, + { + let l3_type: u32 = unsafe { ::std::mem::transmute(l3_type) }; + l3_type as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 8usize, + 4u8, + { + let l4_type: u32 = unsafe { ::std::mem::transmute(l4_type) }; + l4_type as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 12usize, + 4u8, + { + let tun_type: u32 = unsafe { ::std::mem::transmute(tun_type) }; + tun_type as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 16usize, + 4u8, + { + let inner_l2_type: u32 = unsafe { + ::std::mem::transmute(inner_l2_type) + }; + inner_l2_type as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 20usize, + 4u8, + { + let inner_l3_type: u32 = unsafe { + ::std::mem::transmute(inner_l3_type) + }; + inner_l3_type as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 24usize, + 4u8, + { + let inner_l4_type: u32 = unsafe { + ::std::mem::transmute(inner_l4_type) + }; + inner_l4_type as u64 + }, + ); __bindgen_bitfield_unit } } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_2)) + ::std::mem::size_of:: < rte_mbuf__bindgen_ty_2 > (), 4usize, concat!("Size of: ", + stringify!(rte_mbuf__bindgen_ty_2)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < rte_mbuf__bindgen_ty_2 > (), 4usize, concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_2)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).packet_type) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_2), - "::", - stringify!(packet_type) - ) + unsafe { ::std::ptr::addr_of!((* ptr).packet_type) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_2), "::", + stringify!(packet_type)) ); } impl Clone for rte_mbuf__bindgen_ty_2 { @@ -529,20 +501,37 @@ pub struct rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 { pub id: u16, } #[test] -fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1( -) { +fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit< rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1, > = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq ! (:: std :: mem :: size_of :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > () , 4usize , concat ! ("Size of: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1))); - assert_eq ! (:: std :: mem :: align_of :: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > () , 2usize , concat ! ("Alignment of " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1))); - assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . hash) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (hash))); - assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . id) as usize - ptr as usize } , 2usize , concat ! ("Offset of field: " , stringify ! (rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1) , "::" , stringify ! (id))); + assert_eq!( + ::std::mem::size_of:: < + rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > (), 4usize, + concat!("Size of: ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1)) + ); + assert_eq!( + ::std::mem::align_of:: < + rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > (), 2usize, + concat!("Alignment of ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).hash) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1), + "::", stringify!(hash)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).id) as usize - ptr as usize }, 2usize, + concat!("Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1), + "::", stringify!(id)) + ); } -impl Clone - for rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 -{ +impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 { fn clone(&self) -> Self { *self } @@ -554,33 +543,20 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1() { > = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::( - ), - 4usize, - concat!( - "Size of: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1) - ) + ::std::mem::size_of:: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 > (), + 4usize, concat!("Size of: ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::< - rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1, - >(), - 4usize, - concat!( - "Alignment of ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1) - ) + ::std::mem::align_of:: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 > (), + 4usize, concat!("Alignment of ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).lo) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(lo) - ) + unsafe { ::std::ptr::addr_of!((* ptr).lo) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1), "::", + stringify!(lo)) ); } impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 { @@ -590,35 +566,20 @@ impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 { } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit< - rte_mbuf__bindgen_ty_3__bindgen_ty_1, - > = ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!( - "Size of: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1) - ) + ::std::mem::size_of:: < rte_mbuf__bindgen_ty_3__bindgen_ty_1 > (), 8usize, + concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!( - "Alignment of ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1) - ) + ::std::mem::align_of:: < rte_mbuf__bindgen_ty_3__bindgen_ty_1 > (), 4usize, + concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).hi) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1), - "::", - stringify!(hi) - ) + unsafe { ::std::ptr::addr_of!((* ptr).hi) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1), + "::", stringify!(hi)) ); } impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_1 { @@ -634,45 +595,25 @@ pub struct rte_mbuf__bindgen_ty_3__bindgen_ty_2 { } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit< - rte_mbuf__bindgen_ty_3__bindgen_ty_2, - > = ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!( - "Size of: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2) - ) + ::std::mem::size_of:: < rte_mbuf__bindgen_ty_3__bindgen_ty_2 > (), 8usize, + concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!( - "Alignment of ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2) - ) + ::std::mem::align_of:: < rte_mbuf__bindgen_ty_3__bindgen_ty_2 > (), 4usize, + concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).lo) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2), - "::", - stringify!(lo) - ) + unsafe { ::std::ptr::addr_of!((* ptr).lo) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2), + "::", stringify!(lo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).hi) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2), - "::", - stringify!(hi) - ) + unsafe { ::std::ptr::addr_of!((* ptr).hi) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2), + "::", stringify!(hi)) ); } impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_2 { @@ -682,58 +623,35 @@ impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_2 { } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_3() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_3)) + ::std::mem::size_of:: < rte_mbuf__bindgen_ty_3 > (), 8usize, concat!("Size of: ", + stringify!(rte_mbuf__bindgen_ty_3)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < rte_mbuf__bindgen_ty_3 > (), 4usize, concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_3)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).rss) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(rss) - ) + unsafe { ::std::ptr::addr_of!((* ptr).rss) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_3), "::", + stringify!(rss)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).fdir) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(fdir) - ) + unsafe { ::std::ptr::addr_of!((* ptr).fdir) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_3), "::", + stringify!(fdir)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).sched) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(sched) - ) + unsafe { ::std::ptr::addr_of!((* ptr).sched) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_3), "::", + stringify!(sched)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).usr) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(usr) - ) + unsafe { ::std::ptr::addr_of!((* ptr).usr) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_3), "::", + stringify!(usr)) ); } impl Clone for rte_mbuf__bindgen_ty_3 { @@ -752,40 +670,25 @@ pub struct rte_mbuf__bindgen_ty_4 { } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_4() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_4)) + ::std::mem::size_of:: < rte_mbuf__bindgen_ty_4 > (), 8usize, concat!("Size of: ", + stringify!(rte_mbuf__bindgen_ty_4)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, + ::std::mem::align_of:: < rte_mbuf__bindgen_ty_4 > (), 8usize, concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_4)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).userdata) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_4), - "::", - stringify!(userdata) - ) + unsafe { ::std::ptr::addr_of!((* ptr).userdata) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_4), "::", + stringify!(userdata)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).udata64) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_4), - "::", - stringify!(udata64) - ) + unsafe { ::std::ptr::addr_of!((* ptr).udata64) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_4), "::", + stringify!(udata64)) ); } impl Clone for rte_mbuf__bindgen_ty_4 { @@ -798,8 +701,7 @@ impl Clone for rte_mbuf__bindgen_ty_4 { pub struct rte_mbuf__bindgen_ty_5 { ///< combined for easy fetch pub tx_offload: __BindgenUnionField, - pub __bindgen_anon_1: - __BindgenUnionField, + pub __bindgen_anon_1: __BindgenUnionField, pub bindgen_union_field: u64, } #[repr(C)] @@ -812,20 +714,12 @@ pub struct rte_mbuf__bindgen_ty_5__bindgen_ty_1 { #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_5__bindgen_ty_1() { assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!( - "Size of: ", - stringify!(rte_mbuf__bindgen_ty_5__bindgen_ty_1) - ) + ::std::mem::size_of:: < rte_mbuf__bindgen_ty_5__bindgen_ty_1 > (), 8usize, + concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_5__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!( - "Alignment of ", - stringify!(rte_mbuf__bindgen_ty_5__bindgen_ty_1) - ) + ::std::mem::align_of:: < rte_mbuf__bindgen_ty_5__bindgen_ty_1 > (), 8usize, + concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_5__bindgen_ty_1)) ); } impl Clone for rte_mbuf__bindgen_ty_5__bindgen_ty_1 { @@ -836,9 +730,7 @@ impl Clone for rte_mbuf__bindgen_ty_5__bindgen_ty_1 { impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { #[inline] pub fn l2_len(&self) -> u64 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 7u8) as u64) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 7u8) as u64) } } #[inline] pub fn set_l2_len(&mut self, val: u64) { @@ -849,9 +741,7 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { } #[inline] pub fn l3_len(&self) -> u64 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(7usize, 9u8) as u64) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(7usize, 9u8) as u64) } } #[inline] pub fn set_l3_len(&mut self, val: u64) { @@ -862,9 +752,7 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { } #[inline] pub fn l4_len(&self) -> u64 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(16usize, 8u8) as u64) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(16usize, 8u8) as u64) } } #[inline] pub fn set_l4_len(&mut self, val: u64) { @@ -875,9 +763,7 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { } #[inline] pub fn tso_segsz(&self) -> u64 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(24usize, 16u8) as u64) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(24usize, 16u8) as u64) } } #[inline] pub fn set_tso_segsz(&mut self, val: u64) { @@ -888,9 +774,7 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { } #[inline] pub fn outer_l3_len(&self) -> u64 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(40usize, 9u8) as u64) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(40usize, 9u8) as u64) } } #[inline] pub fn set_outer_l3_len(&mut self, val: u64) { @@ -901,9 +785,7 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { } #[inline] pub fn outer_l2_len(&self) -> u64 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(49usize, 7u8) as u64) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(49usize, 7u8) as u64) } } #[inline] pub fn set_outer_l2_len(&mut self, val: u64) { @@ -921,63 +803,84 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { outer_l3_len: u64, outer_l2_len: u64, ) -> __BindgenBitfieldUnit<[u8; 7usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 7usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 7u8, { - let l2_len: u64 = unsafe { ::std::mem::transmute(l2_len) }; - l2_len as u64 - }); - __bindgen_bitfield_unit.set(7usize, 9u8, { - let l3_len: u64 = unsafe { ::std::mem::transmute(l3_len) }; - l3_len as u64 - }); - __bindgen_bitfield_unit.set(16usize, 8u8, { - let l4_len: u64 = unsafe { ::std::mem::transmute(l4_len) }; - l4_len as u64 - }); - __bindgen_bitfield_unit.set(24usize, 16u8, { - let tso_segsz: u64 = unsafe { ::std::mem::transmute(tso_segsz) }; - tso_segsz as u64 - }); - __bindgen_bitfield_unit.set(40usize, 9u8, { - let outer_l3_len: u64 = - unsafe { ::std::mem::transmute(outer_l3_len) }; - outer_l3_len as u64 - }); - __bindgen_bitfield_unit.set(49usize, 7u8, { - let outer_l2_len: u64 = - unsafe { ::std::mem::transmute(outer_l2_len) }; - outer_l2_len as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 7usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 7u8, + { + let l2_len: u64 = unsafe { ::std::mem::transmute(l2_len) }; + l2_len as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 7usize, + 9u8, + { + let l3_len: u64 = unsafe { ::std::mem::transmute(l3_len) }; + l3_len as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 16usize, + 8u8, + { + let l4_len: u64 = unsafe { ::std::mem::transmute(l4_len) }; + l4_len as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 24usize, + 16u8, + { + let tso_segsz: u64 = unsafe { ::std::mem::transmute(tso_segsz) }; + tso_segsz as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 40usize, + 9u8, + { + let outer_l3_len: u64 = unsafe { + ::std::mem::transmute(outer_l3_len) + }; + outer_l3_len as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 49usize, + 7u8, + { + let outer_l2_len: u64 = unsafe { + ::std::mem::transmute(outer_l2_len) + }; + outer_l2_len as u64 + }, + ); __bindgen_bitfield_unit } } #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_5() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_5)) + ::std::mem::size_of:: < rte_mbuf__bindgen_ty_5 > (), 8usize, concat!("Size of: ", + stringify!(rte_mbuf__bindgen_ty_5)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, + ::std::mem::align_of:: < rte_mbuf__bindgen_ty_5 > (), 8usize, concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_5)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).tx_offload) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_5), - "::", - stringify!(tx_offload) - ) + unsafe { ::std::ptr::addr_of!((* ptr).tx_offload) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_5), "::", + stringify!(tx_offload)) ); } impl Clone for rte_mbuf__bindgen_ty_5 { @@ -987,250 +890,111 @@ impl Clone for rte_mbuf__bindgen_ty_5 { } #[test] fn bindgen_test_layout_rte_mbuf() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 128usize, - concat!("Size of: ", stringify!(rte_mbuf)) + ::std::mem::size_of:: < rte_mbuf > (), 128usize, concat!("Size of: ", + stringify!(rte_mbuf)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).cacheline0) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(cacheline0) - ) + unsafe { ::std::ptr::addr_of!((* ptr).cacheline0) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", + stringify!(cacheline0)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).buf_addr) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(buf_addr) - ) + unsafe { ::std::ptr::addr_of!((* ptr).buf_addr) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", + stringify!(buf_addr)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).buf_physaddr) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(buf_physaddr) - ) + unsafe { ::std::ptr::addr_of!((* ptr).buf_physaddr) as usize - ptr as usize }, + 8usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", + stringify!(buf_physaddr)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).buf_len) as usize - ptr as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(buf_len) - ) + unsafe { ::std::ptr::addr_of!((* ptr).buf_len) as usize - ptr as usize }, + 16usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", + stringify!(buf_len)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).rearm_data) as usize - ptr as usize - }, - 18usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(rearm_data) - ) + unsafe { ::std::ptr::addr_of!((* ptr).rearm_data) as usize - ptr as usize }, + 18usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", + stringify!(rearm_data)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).data_off) as usize - ptr as usize - }, - 18usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(data_off) - ) + unsafe { ::std::ptr::addr_of!((* ptr).data_off) as usize - ptr as usize }, + 18usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", + stringify!(data_off)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).nb_segs) as usize - ptr as usize }, - 22usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(nb_segs) - ) + unsafe { ::std::ptr::addr_of!((* ptr).nb_segs) as usize - ptr as usize }, + 22usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", + stringify!(nb_segs)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).port) as usize - ptr as usize }, - 23usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(port) - ) + unsafe { ::std::ptr::addr_of!((* ptr).port) as usize - ptr as usize }, 23usize, + concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(port)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).ol_flags) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(ol_flags) - ) + unsafe { ::std::ptr::addr_of!((* ptr).ol_flags) as usize - ptr as usize }, + 24usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", + stringify!(ol_flags)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).rx_descriptor_fields1) as usize - - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(rx_descriptor_fields1) - ) + unsafe { ::std::ptr::addr_of!((* ptr).rx_descriptor_fields1) as usize - ptr as + usize }, 32usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", + stringify!(rx_descriptor_fields1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).pkt_len) as usize - ptr as usize }, - 36usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(pkt_len) - ) + unsafe { ::std::ptr::addr_of!((* ptr).pkt_len) as usize - ptr as usize }, + 36usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", + stringify!(pkt_len)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).data_len) as usize - ptr as usize - }, - 40usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(data_len) - ) + unsafe { ::std::ptr::addr_of!((* ptr).data_len) as usize - ptr as usize }, + 40usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", + stringify!(data_len)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).vlan_tci) as usize - ptr as usize - }, - 42usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(vlan_tci) - ) + unsafe { ::std::ptr::addr_of!((* ptr).vlan_tci) as usize - ptr as usize }, + 42usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", + stringify!(vlan_tci)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).hash) as usize - ptr as usize }, - 44usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(hash) - ) + unsafe { ::std::ptr::addr_of!((* ptr).hash) as usize - ptr as usize }, 44usize, + concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(hash)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).seqn) as usize - ptr as usize }, - 52usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(seqn) - ) + unsafe { ::std::ptr::addr_of!((* ptr).seqn) as usize - ptr as usize }, 52usize, + concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(seqn)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).vlan_tci_outer) as usize - ptr as usize - }, - 56usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(vlan_tci_outer) - ) + unsafe { ::std::ptr::addr_of!((* ptr).vlan_tci_outer) as usize - ptr as usize }, + 56usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", + stringify!(vlan_tci_outer)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).cacheline1) as usize - ptr as usize - }, - 64usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(cacheline1) - ) + unsafe { ::std::ptr::addr_of!((* ptr).cacheline1) as usize - ptr as usize }, + 64usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", + stringify!(cacheline1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).pool) as usize - ptr as usize }, - 72usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(pool) - ) + unsafe { ::std::ptr::addr_of!((* ptr).pool) as usize - ptr as usize }, 72usize, + concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(pool)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize }, - 80usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(next) - ) + unsafe { ::std::ptr::addr_of!((* ptr).next) as usize - ptr as usize }, 80usize, + concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(next)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).priv_size) as usize - ptr as usize - }, - 96usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(priv_size) - ) + unsafe { ::std::ptr::addr_of!((* ptr).priv_size) as usize - ptr as usize }, + 96usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", + stringify!(priv_size)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).timesync) as usize - ptr as usize - }, - 98usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(timesync) - ) + unsafe { ::std::ptr::addr_of!((* ptr).timesync) as usize - ptr as usize }, + 98usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", + stringify!(timesync)) ); } impl Default for rte_mbuf { diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/abi_variadic_function.rs b/bindgen-tests/tests/expectations/tests/libclang-5/abi_variadic_function.rs index 6aeb16f2a7..3cb7248c93 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-5/abi_variadic_function.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-5/abi_variadic_function.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { #[link_name = "\u{1}_Z1bcz"] pub fn b(arg1: ::std::os::raw::c_char, ...) -> ::std::os::raw::c_char; diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/auto.rs b/bindgen-tests/tests/expectations/tests/libclang-5/auto.rs index 0b20b39eb6..acf81c26d6 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-5/auto.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-5/auto.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { @@ -14,14 +8,11 @@ pub const Foo_kFoo: bool = true; #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) + ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", + stringify!(Foo)) ); } #[repr(C)] diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/call-conv-field.rs b/bindgen-tests/tests/expectations/tests/libclang-5/call-conv-field.rs index 62b5ace2b0..8f99ebc3a4 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-5/call-conv-field.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-5/call-conv-field.rs @@ -1,11 +1,5 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(not(test))] - #[repr(C)] #[derive(Default, Copy, Clone)] pub struct JNINativeInterface_ { @@ -18,40 +12,25 @@ pub struct JNINativeInterface_ { } #[test] fn bindgen_test_layout_JNINativeInterface_() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(JNINativeInterface_)) + ::std::mem::size_of:: < JNINativeInterface_ > (), 16usize, concat!("Size of: ", + stringify!(JNINativeInterface_)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, + ::std::mem::align_of:: < JNINativeInterface_ > (), 8usize, concat!("Alignment of ", stringify!(JNINativeInterface_)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).GetVersion) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(JNINativeInterface_), - "::", - stringify!(GetVersion) - ) + unsafe { ::std::ptr::addr_of!((* ptr).GetVersion) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(JNINativeInterface_), "::", + stringify!(GetVersion)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).__hack) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(JNINativeInterface_), - "::", - stringify!(__hack) - ) + unsafe { ::std::ptr::addr_of!((* ptr).__hack) as usize - ptr as usize }, 8usize, + concat!("Offset of field: ", stringify!(JNINativeInterface_), "::", + stringify!(__hack)) ); } extern "stdcall" { diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/const_bool.rs b/bindgen-tests/tests/expectations/tests/libclang-5/const_bool.rs index 97e1d8dda4..d08e431607 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-5/const_bool.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-5/const_bool.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const k: bool = true; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -15,14 +9,10 @@ pub const A_k: bool = false; #[test] fn bindgen_test_layout_A() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(A)) + ::std::mem::size_of:: < A > (), 1usize, concat!("Size of: ", stringify!(A)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(A)) + ::std::mem::align_of:: < A > (), 1usize, concat!("Alignment of ", stringify!(A)) ); } pub type foo = bool; diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/constant-evaluate.rs b/bindgen-tests/tests/expectations/tests/libclang-5/constant-evaluate.rs index 6263faed6a..bbcf6d5450 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-5/constant-evaluate.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-5/constant-evaluate.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const foo: _bindgen_ty_1 = _bindgen_ty_1::foo; pub const bar: _bindgen_ty_1 = _bindgen_ty_1::bar; #[repr(u32)] diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/error-E0600-cannot-apply-unary-negation-to-u32.rs b/bindgen-tests/tests/expectations/tests/libclang-5/error-E0600-cannot-apply-unary-negation-to-u32.rs index 57878592d9..79004238fc 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-5/error-E0600-cannot-apply-unary-negation-to-u32.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-5/error-E0600-cannot-apply-unary-negation-to-u32.rs @@ -1,9 +1,3 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![allow(overflowing_literals)] - pub const a: u32 = 4294967291; diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/issue-769-bad-instantiation-test.rs b/bindgen-tests/tests/expectations/tests/libclang-5/issue-769-bad-instantiation-test.rs index 60857966ce..0acb9ad8b8 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-5/issue-769-bad-instantiation-test.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-5/issue-769-bad-instantiation-test.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![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 { #[allow(unused_imports)] @@ -28,40 +22,27 @@ pub mod root { #[test] fn __bindgen_test_layout_Rooted_open0_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!( - "Size of template specialization: ", - stringify!(root::Rooted<::std::os::raw::c_int>) - ) + ::std::mem::size_of:: < root::Rooted < ::std::os::raw::c_int > > (), 4usize, + concat!("Size of template specialization: ", stringify!(root::Rooted < + ::std::os::raw::c_int >)) ); assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(root::Rooted<::std::os::raw::c_int>) - ) + ::std::mem::align_of:: < root::Rooted < ::std::os::raw::c_int > > (), 4usize, + concat!("Alignment of template specialization: ", stringify!(root::Rooted < + ::std::os::raw::c_int >)) ); } #[test] - fn __bindgen_test_layout_Rooted_open0_AutoValueVector_Alias_close0_instantiation( - ) { + fn __bindgen_test_layout_Rooted_open0_AutoValueVector_Alias_close0_instantiation() { assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!( - "Size of template specialization: ", - stringify!(root::Rooted) - ) + ::std::mem::size_of:: < root::Rooted < root::AutoValueVector_Alias > > (), + 4usize, concat!("Size of template specialization: ", stringify!(root::Rooted + < root::AutoValueVector_Alias >)) ); assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(root::Rooted) - ) + ::std::mem::align_of:: < root::Rooted < root::AutoValueVector_Alias > > (), + 4usize, concat!("Alignment of template specialization: ", + stringify!(root::Rooted < root::AutoValueVector_Alias >)) ); } } diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/mangling-win32.rs b/bindgen-tests/tests/expectations/tests/libclang-5/mangling-win32.rs index 0aee327414..c3185060a4 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-5/mangling-win32.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-5/mangling-win32.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub fn foo(); } @@ -20,14 +14,11 @@ extern "C" { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) + ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", + stringify!(Foo)) ); } extern "fastcall" { diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/objc_inheritance.rs b/bindgen-tests/tests/expectations/tests/libclang-5/objc_inheritance.rs index f1c2a88cb0..6fb4e6b857 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-5/objc_inheritance.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-5/objc_inheritance.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] - -use objc::{self, class, msg_send, sel, sel_impl}; +use objc::{self, msg_send, sel, sel_impl, class}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] @@ -50,8 +44,7 @@ impl From for Foo { impl std::convert::TryFrom for Bar { type Error = &'static str; fn try_from(parent: Foo) -> Result { - let is_kind_of: bool = - unsafe { msg_send!(parent, isKindOfClass: class!(Bar)) }; + let is_kind_of: bool = unsafe { msg_send!(parent, isKindOfClass : class!(Bar)) }; if is_kind_of { Ok(Bar(parent.0)) } else { @@ -85,8 +78,7 @@ impl From for Bar { impl std::convert::TryFrom for Baz { type Error = &'static str; fn try_from(parent: Bar) -> Result { - let is_kind_of: bool = - unsafe { msg_send!(parent, isKindOfClass: class!(Baz)) }; + let is_kind_of: bool = unsafe { msg_send!(parent, isKindOfClass : class!(Baz)) }; if is_kind_of { Ok(Baz(parent.0)) } else { @@ -103,8 +95,7 @@ impl From for Foo { impl std::convert::TryFrom for Baz { type Error = &'static str; fn try_from(parent: Foo) -> Result { - let is_kind_of: bool = - unsafe { msg_send!(parent, isKindOfClass: class!(Baz)) }; + let is_kind_of: bool = unsafe { msg_send!(parent, isKindOfClass : class!(Baz)) }; if is_kind_of { Ok(Baz(parent.0)) } else { diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/objc_template.rs b/bindgen-tests/tests/expectations/tests/libclang-5/objc_template.rs index 53caa661c6..7ab3ac45ba 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-5/objc_template.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-5/objc_template.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] - -use objc::{self, class, msg_send, sel, sel_impl}; +use objc::{self, msg_send, sel, sel_impl, class}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] @@ -30,7 +24,7 @@ pub trait IFoo: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - msg_send!(*self, get) + msg_send!(* self, get) } } #[repr(transparent)] @@ -48,17 +42,16 @@ impl FooMultiGeneric { Self(unsafe { msg_send!(class!(FooMultiGeneric), alloc) }) } } -impl - IFooMultiGeneric for FooMultiGeneric -{ -} -pub trait IFooMultiGeneric: - Sized + std::ops::Deref -{ +impl IFooMultiGeneric +for FooMultiGeneric {} +pub trait IFooMultiGeneric< + KeyType: 'static, + ObjectType: 'static, +>: Sized + std::ops::Deref { unsafe fn objectForKey_(&self, key: *mut KeyType) -> *mut ObjectType where ::Target: objc::Message + Sized, { - msg_send!(*self, objectForKey: key) + msg_send!(* self, objectForKey : key) } } diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/partial-specialization-and-inheritance.rs b/bindgen-tests/tests/expectations/tests/libclang-5/partial-specialization-and-inheritance.rs index e62ea68172..b35befce18 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-5/partial-specialization-and-inheritance.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-5/partial-specialization-and-inheritance.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Base { @@ -27,13 +21,11 @@ extern "C" { #[test] fn bindgen_test_layout_Usage() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Usage)) + ::std::mem::size_of:: < Usage > (), 1usize, concat!("Size of: ", + stringify!(Usage)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Usage)) + ::std::mem::align_of:: < Usage > (), 1usize, concat!("Alignment of ", + stringify!(Usage)) ); } diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/type_alias_template_specialized.rs b/bindgen-tests/tests/expectations/tests/libclang-5/type_alias_template_specialized.rs index 19f8881db6..0483cdaf75 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-5/type_alias_template_specialized.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-5/type_alias_template_specialized.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Rooted { @@ -12,28 +6,19 @@ pub struct Rooted { } #[test] fn bindgen_test_layout_Rooted() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Rooted)) + ::std::mem::size_of:: < Rooted > (), 4usize, concat!("Size of: ", + stringify!(Rooted)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Rooted)) + ::std::mem::align_of:: < Rooted > (), 4usize, concat!("Alignment of ", + stringify!(Rooted)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Rooted), - "::", - stringify!(ptr) - ) + unsafe { ::std::ptr::addr_of!((* ptr).ptr) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(Rooted), "::", stringify!(ptr)) ); } impl Default for Rooted { @@ -50,19 +35,13 @@ pub type MaybeWrapped = a; #[test] fn __bindgen_test_layout_MaybeWrapped_open0_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!( - "Size of template specialization: ", - stringify!(MaybeWrapped<::std::os::raw::c_int>) - ) + ::std::mem::size_of:: < MaybeWrapped < ::std::os::raw::c_int > > (), 4usize, + concat!("Size of template specialization: ", stringify!(MaybeWrapped < + ::std::os::raw::c_int >)) ); assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(MaybeWrapped<::std::os::raw::c_int>) - ) + ::std::mem::align_of:: < MaybeWrapped < ::std::os::raw::c_int > > (), 4usize, + concat!("Alignment of template specialization: ", stringify!(MaybeWrapped < + ::std::os::raw::c_int >)) ); } diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/abi_variadic_function.rs b/bindgen-tests/tests/expectations/tests/libclang-9/abi_variadic_function.rs index 6aeb16f2a7..3cb7248c93 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/abi_variadic_function.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/abi_variadic_function.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { #[link_name = "\u{1}_Z1bcz"] pub fn b(arg1: ::std::os::raw::c_char, ...) -> ::std::os::raw::c_char; diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/auto.rs b/bindgen-tests/tests/expectations/tests/libclang-9/auto.rs index 0b20b39eb6..acf81c26d6 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/auto.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/auto.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { @@ -14,14 +8,11 @@ pub const Foo_kFoo: bool = true; #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) + ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", + stringify!(Foo)) ); } #[repr(C)] diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/call-conv-field.rs b/bindgen-tests/tests/expectations/tests/libclang-9/call-conv-field.rs index 62b5ace2b0..8f99ebc3a4 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/call-conv-field.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/call-conv-field.rs @@ -1,11 +1,5 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(not(test))] - #[repr(C)] #[derive(Default, Copy, Clone)] pub struct JNINativeInterface_ { @@ -18,40 +12,25 @@ pub struct JNINativeInterface_ { } #[test] fn bindgen_test_layout_JNINativeInterface_() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(JNINativeInterface_)) + ::std::mem::size_of:: < JNINativeInterface_ > (), 16usize, concat!("Size of: ", + stringify!(JNINativeInterface_)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, + ::std::mem::align_of:: < JNINativeInterface_ > (), 8usize, concat!("Alignment of ", stringify!(JNINativeInterface_)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).GetVersion) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(JNINativeInterface_), - "::", - stringify!(GetVersion) - ) + unsafe { ::std::ptr::addr_of!((* ptr).GetVersion) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(JNINativeInterface_), "::", + stringify!(GetVersion)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).__hack) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(JNINativeInterface_), - "::", - stringify!(__hack) - ) + unsafe { ::std::ptr::addr_of!((* ptr).__hack) as usize - ptr as usize }, 8usize, + concat!("Offset of field: ", stringify!(JNINativeInterface_), "::", + stringify!(__hack)) ); } extern "stdcall" { diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/class.rs b/bindgen-tests/tests/expectations/tests/libclang-9/class.rs index 0d64a9ffc8..d794141c06 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/class.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/class.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Default)] pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); @@ -43,35 +37,21 @@ pub struct C { } #[test] fn bindgen_test_layout_C() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 40usize, - concat!("Size of: ", stringify!(C)) + ::std::mem::size_of:: < C > (), 40usize, concat!("Size of: ", stringify!(C)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C)) + ::std::mem::align_of:: < C > (), 4usize, concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(a)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(big_array) - ) + unsafe { ::std::ptr::addr_of!((* ptr).big_array) as usize - ptr as usize }, + 4usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(big_array)) ); } impl Default for C { @@ -91,53 +71,30 @@ pub struct C_with_zero_length_array { } #[test] fn bindgen_test_layout_C_with_zero_length_array() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 40usize, + ::std::mem::size_of:: < C_with_zero_length_array > (), 40usize, concat!("Size of: ", stringify!(C_with_zero_length_array)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < C_with_zero_length_array > (), 4usize, concat!("Alignment of ", stringify!(C_with_zero_length_array)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(C_with_zero_length_array), "::", + stringify!(a)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(big_array) - ) + unsafe { ::std::ptr::addr_of!((* ptr).big_array) as usize - ptr as usize }, + 4usize, concat!("Offset of field: ", stringify!(C_with_zero_length_array), "::", + stringify!(big_array)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize - }, - 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(zero_length_array) - ) + unsafe { ::std::ptr::addr_of!((* ptr).zero_length_array) as usize - ptr as usize + }, 37usize, concat!("Offset of field: ", stringify!(C_with_zero_length_array), + "::", stringify!(zero_length_array)) ); } impl Default for C_with_zero_length_array { @@ -157,41 +114,25 @@ pub struct C_with_zero_length_array_2 { } #[test] fn bindgen_test_layout_C_with_zero_length_array_2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, + ::std::mem::size_of:: < C_with_zero_length_array_2 > (), 4usize, concat!("Size of: ", stringify!(C_with_zero_length_array_2)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < C_with_zero_length_array_2 > (), 4usize, concat!("Alignment of ", stringify!(C_with_zero_length_array_2)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_2), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(C_with_zero_length_array_2), "::", + stringify!(a)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_2), - "::", - stringify!(zero_length_array) - ) + unsafe { ::std::ptr::addr_of!((* ptr).zero_length_array) as usize - ptr as usize + }, 4usize, concat!("Offset of field: ", stringify!(C_with_zero_length_array_2), + "::", stringify!(zero_length_array)) ); } #[repr(C)] @@ -202,53 +143,30 @@ pub struct C_with_incomplete_array { } #[test] fn bindgen_test_layout_C_with_incomplete_array() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 40usize, + ::std::mem::size_of:: < C_with_incomplete_array > (), 40usize, concat!("Size of: ", stringify!(C_with_incomplete_array)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < C_with_incomplete_array > (), 4usize, concat!("Alignment of ", stringify!(C_with_incomplete_array)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(C_with_incomplete_array), "::", + stringify!(a)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array), - "::", - stringify!(big_array) - ) + unsafe { ::std::ptr::addr_of!((* ptr).big_array) as usize - ptr as usize }, + 4usize, concat!("Offset of field: ", stringify!(C_with_incomplete_array), "::", + stringify!(big_array)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - - ptr as usize - }, - 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array), - "::", - stringify!(incomplete_array) - ) + unsafe { ::std::ptr::addr_of!((* ptr).incomplete_array) as usize - ptr as usize + }, 37usize, concat!("Offset of field: ", stringify!(C_with_incomplete_array), + "::", stringify!(incomplete_array)) ); } impl Default for C_with_incomplete_array { @@ -268,41 +186,25 @@ pub struct C_with_incomplete_array_2 { } #[test] fn bindgen_test_layout_C_with_incomplete_array_2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, + ::std::mem::size_of:: < C_with_incomplete_array_2 > (), 4usize, concat!("Size of: ", stringify!(C_with_incomplete_array_2)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < C_with_incomplete_array_2 > (), 4usize, concat!("Alignment of ", stringify!(C_with_incomplete_array_2)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array_2), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(C_with_incomplete_array_2), "::", + stringify!(a)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array_2), - "::", - stringify!(incomplete_array) - ) + unsafe { ::std::ptr::addr_of!((* ptr).incomplete_array) as usize - ptr as usize + }, 4usize, concat!("Offset of field: ", stringify!(C_with_incomplete_array_2), + "::", stringify!(incomplete_array)) ); } #[repr(C)] @@ -319,68 +221,37 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { > = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 40usize, - concat!( - "Size of: ", - stringify!(C_with_zero_length_array_and_incomplete_array) - ) + ::std::mem::size_of:: < C_with_zero_length_array_and_incomplete_array > (), + 40usize, concat!("Size of: ", + stringify!(C_with_zero_length_array_and_incomplete_array)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!( - "Alignment of ", - stringify!(C_with_zero_length_array_and_incomplete_array) - ) + ::std::mem::align_of:: < C_with_zero_length_array_and_incomplete_array > (), + 4usize, concat!("Alignment of ", + stringify!(C_with_zero_length_array_and_incomplete_array)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), "::", stringify!(a)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(big_array) - ) + unsafe { ::std::ptr::addr_of!((* ptr).big_array) as usize - ptr as usize }, + 4usize, concat!("Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), "::", + stringify!(big_array)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize - }, - 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(zero_length_array) - ) + unsafe { ::std::ptr::addr_of!((* ptr).zero_length_array) as usize - ptr as usize + }, 37usize, concat!("Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), "::", + stringify!(zero_length_array)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - - ptr as usize - }, - 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(incomplete_array) - ) + unsafe { ::std::ptr::addr_of!((* ptr).incomplete_array) as usize - ptr as usize + }, 37usize, concat!("Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), "::", + stringify!(incomplete_array)) ); } impl Default for C_with_zero_length_array_and_incomplete_array { @@ -406,58 +277,31 @@ fn bindgen_test_layout_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, - concat!( - "Size of: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2) - ) + ::std::mem::size_of:: < C_with_zero_length_array_and_incomplete_array_2 > (), + 4usize, concat!("Size of: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2)) ); assert_eq!( - ::std::mem::align_of::( - ), - 4usize, - concat!( - "Alignment of ", - stringify!(C_with_zero_length_array_and_incomplete_array_2) - ) + ::std::mem::align_of:: < C_with_zero_length_array_and_incomplete_array_2 > (), + 4usize, concat!("Alignment of ", + stringify!(C_with_zero_length_array_and_incomplete_array_2)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), "::", stringify!(a)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), - "::", - stringify!(zero_length_array) - ) + unsafe { ::std::ptr::addr_of!((* ptr).zero_length_array) as usize - ptr as usize + }, 4usize, concat!("Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), "::", + stringify!(zero_length_array)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), - "::", - stringify!(incomplete_array) - ) + unsafe { ::std::ptr::addr_of!((* ptr).incomplete_array) as usize - ptr as usize + }, 4usize, concat!("Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), "::", + stringify!(incomplete_array)) ); } #[repr(C)] @@ -467,28 +311,19 @@ pub struct WithDtor { } #[test] fn bindgen_test_layout_WithDtor() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(WithDtor)) + ::std::mem::size_of:: < WithDtor > (), 4usize, concat!("Size of: ", + stringify!(WithDtor)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithDtor)) + ::std::mem::align_of:: < WithDtor > (), 4usize, concat!("Alignment of ", + stringify!(WithDtor)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithDtor), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(WithDtor), "::", stringify!(b)) ); } #[repr(C)] @@ -498,43 +333,25 @@ pub struct IncompleteArrayNonCopiable { } #[test] fn bindgen_test_layout_IncompleteArrayNonCopiable() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, + ::std::mem::size_of:: < IncompleteArrayNonCopiable > (), 8usize, concat!("Size of: ", stringify!(IncompleteArrayNonCopiable)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, + ::std::mem::align_of:: < IncompleteArrayNonCopiable > (), 8usize, concat!("Alignment of ", stringify!(IncompleteArrayNonCopiable)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).whatever) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(IncompleteArrayNonCopiable), - "::", - stringify!(whatever) - ) + unsafe { ::std::ptr::addr_of!((* ptr).whatever) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(IncompleteArrayNonCopiable), + "::", stringify!(whatever)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(IncompleteArrayNonCopiable), - "::", - stringify!(incomplete_array) - ) + unsafe { ::std::ptr::addr_of!((* ptr).incomplete_array) as usize - ptr as usize + }, 8usize, concat!("Offset of field: ", stringify!(IncompleteArrayNonCopiable), + "::", stringify!(incomplete_array)) ); } impl Default for IncompleteArrayNonCopiable { @@ -554,27 +371,22 @@ pub union Union { } #[test] fn bindgen_test_layout_Union() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Union)) + ::std::mem::size_of:: < Union > (), 4usize, concat!("Size of: ", + stringify!(Union)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Union)) + ::std::mem::align_of:: < Union > (), 4usize, concat!("Alignment of ", + stringify!(Union)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).d) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Union), "::", stringify!(d)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).i) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Union), "::", stringify!(i)) ); } @@ -594,28 +406,19 @@ pub struct WithUnion { } #[test] fn bindgen_test_layout_WithUnion() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(WithUnion)) + ::std::mem::size_of:: < WithUnion > (), 4usize, concat!("Size of: ", + stringify!(WithUnion)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithUnion)) + ::std::mem::align_of:: < WithUnion > (), 4usize, concat!("Alignment of ", + stringify!(WithUnion)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithUnion), - "::", - stringify!(data) - ) + unsafe { ::std::ptr::addr_of!((* ptr).data) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(WithUnion), "::", stringify!(data)) ); } impl Default for WithUnion { @@ -635,17 +438,12 @@ pub struct RealAbstractionWithTonsOfMethods { #[test] fn bindgen_test_layout_RealAbstractionWithTonsOfMethods() { assert_eq!( - ::std::mem::size_of::(), - 1usize, + ::std::mem::size_of:: < RealAbstractionWithTonsOfMethods > (), 1usize, concat!("Size of: ", stringify!(RealAbstractionWithTonsOfMethods)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!( - "Alignment of ", - stringify!(RealAbstractionWithTonsOfMethods) - ) + ::std::mem::align_of:: < RealAbstractionWithTonsOfMethods > (), 1usize, + concat!("Alignment of ", stringify!(RealAbstractionWithTonsOfMethods)) ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/class_1_0.rs b/bindgen-tests/tests/expectations/tests/libclang-9/class_1_0.rs index e8c2e07798..5ea68ca3fc 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/class_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/class_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Default)] pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); @@ -86,35 +80,21 @@ pub struct C { } #[test] fn bindgen_test_layout_C() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 40usize, - concat!("Size of: ", stringify!(C)) + ::std::mem::size_of:: < C > (), 40usize, concat!("Size of: ", stringify!(C)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C)) + ::std::mem::align_of:: < C > (), 4usize, concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(a)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(big_array) - ) + unsafe { ::std::ptr::addr_of!((* ptr).big_array) as usize - ptr as usize }, + 4usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(big_array)) ); } impl Clone for C { @@ -144,53 +124,30 @@ pub struct C_with_zero_length_array { } #[test] fn bindgen_test_layout_C_with_zero_length_array() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 40usize, + ::std::mem::size_of:: < C_with_zero_length_array > (), 40usize, concat!("Size of: ", stringify!(C_with_zero_length_array)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < C_with_zero_length_array > (), 4usize, concat!("Alignment of ", stringify!(C_with_zero_length_array)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(C_with_zero_length_array), "::", + stringify!(a)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(big_array) - ) + unsafe { ::std::ptr::addr_of!((* ptr).big_array) as usize - ptr as usize }, + 4usize, concat!("Offset of field: ", stringify!(C_with_zero_length_array), "::", + stringify!(big_array)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize - }, - 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(zero_length_array) - ) + unsafe { ::std::ptr::addr_of!((* ptr).zero_length_array) as usize - ptr as usize + }, 37usize, concat!("Offset of field: ", stringify!(C_with_zero_length_array), + "::", stringify!(zero_length_array)) ); } impl Default for C_with_zero_length_array { @@ -210,41 +167,25 @@ pub struct C_with_zero_length_array_2 { } #[test] fn bindgen_test_layout_C_with_zero_length_array_2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, + ::std::mem::size_of:: < C_with_zero_length_array_2 > (), 4usize, concat!("Size of: ", stringify!(C_with_zero_length_array_2)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < C_with_zero_length_array_2 > (), 4usize, concat!("Alignment of ", stringify!(C_with_zero_length_array_2)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_2), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(C_with_zero_length_array_2), "::", + stringify!(a)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_2), - "::", - stringify!(zero_length_array) - ) + unsafe { ::std::ptr::addr_of!((* ptr).zero_length_array) as usize - ptr as usize + }, 4usize, concat!("Offset of field: ", stringify!(C_with_zero_length_array_2), + "::", stringify!(zero_length_array)) ); } #[repr(C)] @@ -255,53 +196,30 @@ pub struct C_with_incomplete_array { } #[test] fn bindgen_test_layout_C_with_incomplete_array() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 40usize, + ::std::mem::size_of:: < C_with_incomplete_array > (), 40usize, concat!("Size of: ", stringify!(C_with_incomplete_array)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < C_with_incomplete_array > (), 4usize, concat!("Alignment of ", stringify!(C_with_incomplete_array)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(C_with_incomplete_array), "::", + stringify!(a)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array), - "::", - stringify!(big_array) - ) + unsafe { ::std::ptr::addr_of!((* ptr).big_array) as usize - ptr as usize }, + 4usize, concat!("Offset of field: ", stringify!(C_with_incomplete_array), "::", + stringify!(big_array)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - - ptr as usize - }, - 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array), - "::", - stringify!(incomplete_array) - ) + unsafe { ::std::ptr::addr_of!((* ptr).incomplete_array) as usize - ptr as usize + }, 37usize, concat!("Offset of field: ", stringify!(C_with_incomplete_array), + "::", stringify!(incomplete_array)) ); } impl Default for C_with_incomplete_array { @@ -321,41 +239,25 @@ pub struct C_with_incomplete_array_2 { } #[test] fn bindgen_test_layout_C_with_incomplete_array_2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, + ::std::mem::size_of:: < C_with_incomplete_array_2 > (), 4usize, concat!("Size of: ", stringify!(C_with_incomplete_array_2)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < C_with_incomplete_array_2 > (), 4usize, concat!("Alignment of ", stringify!(C_with_incomplete_array_2)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array_2), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(C_with_incomplete_array_2), "::", + stringify!(a)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array_2), - "::", - stringify!(incomplete_array) - ) + unsafe { ::std::ptr::addr_of!((* ptr).incomplete_array) as usize - ptr as usize + }, 4usize, concat!("Offset of field: ", stringify!(C_with_incomplete_array_2), + "::", stringify!(incomplete_array)) ); } #[repr(C)] @@ -372,68 +274,37 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { > = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 40usize, - concat!( - "Size of: ", - stringify!(C_with_zero_length_array_and_incomplete_array) - ) + ::std::mem::size_of:: < C_with_zero_length_array_and_incomplete_array > (), + 40usize, concat!("Size of: ", + stringify!(C_with_zero_length_array_and_incomplete_array)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!( - "Alignment of ", - stringify!(C_with_zero_length_array_and_incomplete_array) - ) + ::std::mem::align_of:: < C_with_zero_length_array_and_incomplete_array > (), + 4usize, concat!("Alignment of ", + stringify!(C_with_zero_length_array_and_incomplete_array)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), "::", stringify!(a)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(big_array) - ) + unsafe { ::std::ptr::addr_of!((* ptr).big_array) as usize - ptr as usize }, + 4usize, concat!("Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), "::", + stringify!(big_array)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize - }, - 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(zero_length_array) - ) + unsafe { ::std::ptr::addr_of!((* ptr).zero_length_array) as usize - ptr as usize + }, 37usize, concat!("Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), "::", + stringify!(zero_length_array)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - - ptr as usize - }, - 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(incomplete_array) - ) + unsafe { ::std::ptr::addr_of!((* ptr).incomplete_array) as usize - ptr as usize + }, 37usize, concat!("Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), "::", + stringify!(incomplete_array)) ); } impl Default for C_with_zero_length_array_and_incomplete_array { @@ -459,58 +330,31 @@ fn bindgen_test_layout_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, - concat!( - "Size of: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2) - ) + ::std::mem::size_of:: < C_with_zero_length_array_and_incomplete_array_2 > (), + 4usize, concat!("Size of: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2)) ); assert_eq!( - ::std::mem::align_of::( - ), - 4usize, - concat!( - "Alignment of ", - stringify!(C_with_zero_length_array_and_incomplete_array_2) - ) + ::std::mem::align_of:: < C_with_zero_length_array_and_incomplete_array_2 > (), + 4usize, concat!("Alignment of ", + stringify!(C_with_zero_length_array_and_incomplete_array_2)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), "::", stringify!(a)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), - "::", - stringify!(zero_length_array) - ) + unsafe { ::std::ptr::addr_of!((* ptr).zero_length_array) as usize - ptr as usize + }, 4usize, concat!("Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), "::", + stringify!(zero_length_array)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), - "::", - stringify!(incomplete_array) - ) + unsafe { ::std::ptr::addr_of!((* ptr).incomplete_array) as usize - ptr as usize + }, 4usize, concat!("Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), "::", + stringify!(incomplete_array)) ); } #[repr(C)] @@ -520,28 +364,19 @@ pub struct WithDtor { } #[test] fn bindgen_test_layout_WithDtor() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(WithDtor)) + ::std::mem::size_of:: < WithDtor > (), 4usize, concat!("Size of: ", + stringify!(WithDtor)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithDtor)) + ::std::mem::align_of:: < WithDtor > (), 4usize, concat!("Alignment of ", + stringify!(WithDtor)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithDtor), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(WithDtor), "::", stringify!(b)) ); } #[repr(C)] @@ -551,43 +386,25 @@ pub struct IncompleteArrayNonCopiable { } #[test] fn bindgen_test_layout_IncompleteArrayNonCopiable() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, + ::std::mem::size_of:: < IncompleteArrayNonCopiable > (), 8usize, concat!("Size of: ", stringify!(IncompleteArrayNonCopiable)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, + ::std::mem::align_of:: < IncompleteArrayNonCopiable > (), 8usize, concat!("Alignment of ", stringify!(IncompleteArrayNonCopiable)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).whatever) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(IncompleteArrayNonCopiable), - "::", - stringify!(whatever) - ) + unsafe { ::std::ptr::addr_of!((* ptr).whatever) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(IncompleteArrayNonCopiable), + "::", stringify!(whatever)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(IncompleteArrayNonCopiable), - "::", - stringify!(incomplete_array) - ) + unsafe { ::std::ptr::addr_of!((* ptr).incomplete_array) as usize - ptr as usize + }, 8usize, concat!("Offset of field: ", stringify!(IncompleteArrayNonCopiable), + "::", stringify!(incomplete_array)) ); } impl Default for IncompleteArrayNonCopiable { @@ -608,27 +425,22 @@ pub struct Union { } #[test] fn bindgen_test_layout_Union() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Union)) + ::std::mem::size_of:: < Union > (), 4usize, concat!("Size of: ", + stringify!(Union)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Union)) + ::std::mem::align_of:: < Union > (), 4usize, concat!("Alignment of ", + stringify!(Union)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).d) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Union), "::", stringify!(d)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).i) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Union), "::", stringify!(i)) ); } @@ -644,28 +456,19 @@ pub struct WithUnion { } #[test] fn bindgen_test_layout_WithUnion() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(WithUnion)) + ::std::mem::size_of:: < WithUnion > (), 4usize, concat!("Size of: ", + stringify!(WithUnion)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithUnion)) + ::std::mem::align_of:: < WithUnion > (), 4usize, concat!("Alignment of ", + stringify!(WithUnion)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithUnion), - "::", - stringify!(data) - ) + unsafe { ::std::ptr::addr_of!((* ptr).data) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(WithUnion), "::", stringify!(data)) ); } impl Clone for WithUnion { @@ -681,17 +484,12 @@ pub struct RealAbstractionWithTonsOfMethods { #[test] fn bindgen_test_layout_RealAbstractionWithTonsOfMethods() { assert_eq!( - ::std::mem::size_of::(), - 1usize, + ::std::mem::size_of:: < RealAbstractionWithTonsOfMethods > (), 1usize, concat!("Size of: ", stringify!(RealAbstractionWithTonsOfMethods)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!( - "Alignment of ", - stringify!(RealAbstractionWithTonsOfMethods) - ) + ::std::mem::align_of:: < RealAbstractionWithTonsOfMethods > (), 1usize, + concat!("Alignment of ", stringify!(RealAbstractionWithTonsOfMethods)) ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/const_bool.rs b/bindgen-tests/tests/expectations/tests/libclang-9/const_bool.rs index 97e1d8dda4..d08e431607 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/const_bool.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/const_bool.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const k: bool = true; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -15,14 +9,10 @@ pub const A_k: bool = false; #[test] fn bindgen_test_layout_A() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(A)) + ::std::mem::size_of:: < A > (), 1usize, concat!("Size of: ", stringify!(A)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(A)) + ::std::mem::align_of:: < A > (), 1usize, concat!("Alignment of ", stringify!(A)) ); } pub type foo = bool; diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/constant-evaluate.rs b/bindgen-tests/tests/expectations/tests/libclang-9/constant-evaluate.rs index 6263faed6a..bbcf6d5450 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/constant-evaluate.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/constant-evaluate.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const foo: _bindgen_ty_1 = _bindgen_ty_1::foo; pub const bar: _bindgen_ty_1 = _bindgen_ty_1::bar; #[repr(u32)] diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs b/bindgen-tests/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs index 2af22cc4c9..effbaf6e9c 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Default)] pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); @@ -43,36 +37,23 @@ pub struct test { } #[test] fn bindgen_test_layout_test() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(test)) + ::std::mem::size_of:: < test > (), 4usize, concat!("Size of: ", stringify!(test)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(test)) + ::std::mem::align_of:: < test > (), 4usize, concat!("Alignment of ", + stringify!(test)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(test), "::", stringify!(a)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(test), - "::", - stringify!(zero_length_array) - ) + unsafe { ::std::ptr::addr_of!((* ptr).zero_length_array) as usize - ptr as usize + }, 4usize, concat!("Offset of field: ", stringify!(test), "::", + stringify!(zero_length_array)) ); } #[repr(C)] @@ -83,36 +64,24 @@ pub struct test2 { } #[test] fn bindgen_test_layout_test2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(test2)) + ::std::mem::size_of:: < test2 > (), 4usize, concat!("Size of: ", + stringify!(test2)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(test2)) + ::std::mem::align_of:: < test2 > (), 4usize, concat!("Alignment of ", + stringify!(test2)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(test2), "::", stringify!(a)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(test2), - "::", - stringify!(incomplete_array) - ) + unsafe { ::std::ptr::addr_of!((* ptr).incomplete_array) as usize - ptr as usize + }, 4usize, concat!("Offset of field: ", stringify!(test2), "::", + stringify!(incomplete_array)) ); } #[repr(C)] @@ -124,48 +93,28 @@ pub struct test3 { } #[test] fn bindgen_test_layout_test3() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(test3)) + ::std::mem::size_of:: < test3 > (), 4usize, concat!("Size of: ", + stringify!(test3)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(test3)) + ::std::mem::align_of:: < test3 > (), 4usize, concat!("Alignment of ", + stringify!(test3)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(test3), "::", stringify!(a)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(test3), - "::", - stringify!(zero_length_array) - ) + unsafe { ::std::ptr::addr_of!((* ptr).zero_length_array) as usize - ptr as usize + }, 4usize, concat!("Offset of field: ", stringify!(test3), "::", + stringify!(zero_length_array)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(test3), - "::", - stringify!(incomplete_array) - ) + unsafe { ::std::ptr::addr_of!((* ptr).incomplete_array) as usize - ptr as usize + }, 4usize, concat!("Offset of field: ", stringify!(test3), "::", + stringify!(incomplete_array)) ); } diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/error-E0600-cannot-apply-unary-negation-to-u32.rs b/bindgen-tests/tests/expectations/tests/libclang-9/error-E0600-cannot-apply-unary-negation-to-u32.rs index 57878592d9..79004238fc 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/error-E0600-cannot-apply-unary-negation-to-u32.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/error-E0600-cannot-apply-unary-negation-to-u32.rs @@ -1,9 +1,3 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![allow(overflowing_literals)] - pub const a: u32 = 4294967291; diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/incomplete-array-padding.rs b/bindgen-tests/tests/expectations/tests/libclang-9/incomplete-array-padding.rs index 1de963bf0f..353f113e69 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/incomplete-array-padding.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/incomplete-array-padding.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -130,22 +122,17 @@ pub struct foo { } #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of:: < foo > (), 8usize, concat!("Size of: ", stringify!(foo)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(foo)) + ::std::mem::align_of:: < foo > (), 8usize, concat!("Alignment of ", + stringify!(foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 8usize, + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 8usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) ); } @@ -161,9 +148,7 @@ impl Default for foo { impl foo { #[inline] pub fn a(&self) -> ::std::os::raw::c_char { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) } } #[inline] pub fn set_a(&mut self, val: ::std::os::raw::c_char) { @@ -176,12 +161,16 @@ impl foo { pub fn new_bitfield_1( a: ::std::os::raw::c_char, ) -> __BindgenBitfieldUnit<[u8; 1usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 1u8, { - let a: u8 = unsafe { ::std::mem::transmute(a) }; - a as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let a: u8 = unsafe { ::std::mem::transmute(a) }; + a as u64 + }, + ); __bindgen_bitfield_unit } } diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs b/bindgen-tests/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs index ab402cfb7c..3571903358 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Default)] pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); @@ -50,30 +44,20 @@ pub struct rte_ring_prod { } #[test] fn bindgen_test_layout_rte_ring_prod() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(rte_ring_prod)) + ::std::mem::size_of:: < rte_ring_prod > (), 4usize, concat!("Size of: ", + stringify!(rte_ring_prod)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(rte_ring_prod)) + ::std::mem::align_of:: < rte_ring_prod > (), 4usize, concat!("Alignment of ", + stringify!(rte_ring_prod)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).watermark) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ring_prod), - "::", - stringify!(watermark) - ) + unsafe { ::std::ptr::addr_of!((* ptr).watermark) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_ring_prod), "::", + stringify!(watermark)) ); } #[repr(C)] @@ -83,86 +67,49 @@ pub struct rte_ring_cons { } #[test] fn bindgen_test_layout_rte_ring_cons() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(rte_ring_cons)) + ::std::mem::size_of:: < rte_ring_cons > (), 4usize, concat!("Size of: ", + stringify!(rte_ring_cons)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(rte_ring_cons)) + ::std::mem::align_of:: < rte_ring_cons > (), 4usize, concat!("Alignment of ", + stringify!(rte_ring_cons)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).sc_dequeue) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ring_cons), - "::", - stringify!(sc_dequeue) - ) + unsafe { ::std::ptr::addr_of!((* ptr).sc_dequeue) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_ring_cons), "::", + stringify!(sc_dequeue)) ); } #[test] fn bindgen_test_layout_rte_ring() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(rte_ring)) + ::std::mem::size_of:: < rte_ring > (), 16usize, concat!("Size of: ", + stringify!(rte_ring)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(rte_ring)) + ::std::mem::align_of:: < rte_ring > (), 8usize, concat!("Alignment of ", + stringify!(rte_ring)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).memzone) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ring), - "::", - stringify!(memzone) - ) + unsafe { ::std::ptr::addr_of!((* ptr).memzone) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_ring), "::", stringify!(memzone)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).prod) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_ring), - "::", - stringify!(prod) - ) + unsafe { ::std::ptr::addr_of!((* ptr).prod) as usize - ptr as usize }, 8usize, + concat!("Offset of field: ", stringify!(rte_ring), "::", stringify!(prod)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).cons) as usize - ptr as usize }, - 12usize, - concat!( - "Offset of field: ", - stringify!(rte_ring), - "::", - stringify!(cons) - ) + unsafe { ::std::ptr::addr_of!((* ptr).cons) as usize - ptr as usize }, 12usize, + concat!("Offset of field: ", stringify!(rte_ring), "::", stringify!(cons)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ring) as usize - ptr as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_ring), - "::", - stringify!(ring) - ) + unsafe { ::std::ptr::addr_of!((* ptr).ring) as usize - ptr as usize }, 16usize, + concat!("Offset of field: ", stringify!(rte_ring), "::", stringify!(ring)) ); } impl Default for rte_ring { diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/issue-769-bad-instantiation-test.rs b/bindgen-tests/tests/expectations/tests/libclang-9/issue-769-bad-instantiation-test.rs index 60857966ce..0acb9ad8b8 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/issue-769-bad-instantiation-test.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/issue-769-bad-instantiation-test.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![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 { #[allow(unused_imports)] @@ -28,40 +22,27 @@ pub mod root { #[test] fn __bindgen_test_layout_Rooted_open0_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!( - "Size of template specialization: ", - stringify!(root::Rooted<::std::os::raw::c_int>) - ) + ::std::mem::size_of:: < root::Rooted < ::std::os::raw::c_int > > (), 4usize, + concat!("Size of template specialization: ", stringify!(root::Rooted < + ::std::os::raw::c_int >)) ); assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(root::Rooted<::std::os::raw::c_int>) - ) + ::std::mem::align_of:: < root::Rooted < ::std::os::raw::c_int > > (), 4usize, + concat!("Alignment of template specialization: ", stringify!(root::Rooted < + ::std::os::raw::c_int >)) ); } #[test] - fn __bindgen_test_layout_Rooted_open0_AutoValueVector_Alias_close0_instantiation( - ) { + fn __bindgen_test_layout_Rooted_open0_AutoValueVector_Alias_close0_instantiation() { assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!( - "Size of template specialization: ", - stringify!(root::Rooted) - ) + ::std::mem::size_of:: < root::Rooted < root::AutoValueVector_Alias > > (), + 4usize, concat!("Size of template specialization: ", stringify!(root::Rooted + < root::AutoValueVector_Alias >)) ); assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(root::Rooted) - ) + ::std::mem::align_of:: < root::Rooted < root::AutoValueVector_Alias > > (), + 4usize, concat!("Alignment of template specialization: ", + stringify!(root::Rooted < root::AutoValueVector_Alias >)) ); } } diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/layout_align.rs b/bindgen-tests/tests/expectations/tests/libclang-9/layout_align.rs index f6a32704f1..adb5574fbb 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/layout_align.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/layout_align.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -137,70 +129,36 @@ pub struct rte_kni_fifo { } #[test] fn bindgen_test_layout_rte_kni_fifo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(rte_kni_fifo)) + ::std::mem::size_of:: < rte_kni_fifo > (), 16usize, concat!("Size of: ", + stringify!(rte_kni_fifo)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(rte_kni_fifo)) + ::std::mem::align_of:: < rte_kni_fifo > (), 8usize, concat!("Alignment of ", + stringify!(rte_kni_fifo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).write) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_fifo), - "::", - stringify!(write) - ) + unsafe { ::std::ptr::addr_of!((* ptr).write) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(rte_kni_fifo), "::", stringify!(write)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).read) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_fifo), - "::", - stringify!(read) - ) + unsafe { ::std::ptr::addr_of!((* ptr).read) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(rte_kni_fifo), "::", stringify!(read)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_fifo), - "::", - stringify!(len) - ) + unsafe { ::std::ptr::addr_of!((* ptr).len) as usize - ptr as usize }, 8usize, + concat!("Offset of field: ", stringify!(rte_kni_fifo), "::", stringify!(len)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).elem_size) as usize - ptr as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_fifo), - "::", - stringify!(elem_size) - ) + unsafe { ::std::ptr::addr_of!((* ptr).elem_size) as usize - ptr as usize }, + 12usize, concat!("Offset of field: ", stringify!(rte_kni_fifo), "::", + stringify!(elem_size)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).buffer) as usize - ptr as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_fifo), - "::", - stringify!(buffer) - ) + unsafe { ::std::ptr::addr_of!((* ptr).buffer) as usize - ptr as usize }, 16usize, + concat!("Offset of field: ", stringify!(rte_kni_fifo), "::", stringify!(buffer)) ); } impl Default for rte_kni_fifo { @@ -224,38 +182,26 @@ pub struct rte_eth_link { } #[test] fn bindgen_test_layout_rte_eth_link() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(rte_eth_link)) + ::std::mem::size_of:: < rte_eth_link > (), 8usize, concat!("Size of: ", + stringify!(rte_eth_link)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(rte_eth_link)) + ::std::mem::align_of:: < rte_eth_link > (), 8usize, concat!("Alignment of ", + stringify!(rte_eth_link)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).link_speed) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_link), - "::", - stringify!(link_speed) - ) + unsafe { ::std::ptr::addr_of!((* ptr).link_speed) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(rte_eth_link), "::", + stringify!(link_speed)) ); } impl rte_eth_link { #[inline] pub fn link_duplex(&self) -> u16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u16) } } #[inline] pub fn set_link_duplex(&mut self, val: u16) { @@ -266,9 +212,7 @@ impl rte_eth_link { } #[inline] pub fn link_autoneg(&self) -> u16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u16) } } #[inline] pub fn set_link_autoneg(&mut self, val: u16) { @@ -279,9 +223,7 @@ impl rte_eth_link { } #[inline] pub fn link_status(&self) -> u16 { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u16) } } #[inline] pub fn set_link_status(&mut self, val: u16) { @@ -296,23 +238,36 @@ impl rte_eth_link { link_autoneg: u16, link_status: u16, ) -> __BindgenBitfieldUnit<[u8; 1usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 1u8, { - let link_duplex: u16 = - unsafe { ::std::mem::transmute(link_duplex) }; - link_duplex as u64 - }); - __bindgen_bitfield_unit.set(1usize, 1u8, { - let link_autoneg: u16 = - unsafe { ::std::mem::transmute(link_autoneg) }; - link_autoneg as u64 - }); - __bindgen_bitfield_unit.set(2usize, 1u8, { - let link_status: u16 = - unsafe { ::std::mem::transmute(link_status) }; - link_status as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let link_duplex: u16 = unsafe { ::std::mem::transmute(link_duplex) }; + link_duplex as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 1usize, + 1u8, + { + let link_autoneg: u16 = unsafe { + ::std::mem::transmute(link_autoneg) + }; + link_autoneg as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 2usize, + 1u8, + { + let link_status: u16 = unsafe { ::std::mem::transmute(link_status) }; + link_status as u64 + }, + ); __bindgen_bitfield_unit } } diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/mangling-win32.rs b/bindgen-tests/tests/expectations/tests/libclang-9/mangling-win32.rs index 0aee327414..c3185060a4 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/mangling-win32.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/mangling-win32.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub fn foo(); } @@ -20,14 +14,11 @@ extern "C" { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) + ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", + stringify!(Foo)) ); } extern "fastcall" { diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/objc_inheritance.rs b/bindgen-tests/tests/expectations/tests/libclang-9/objc_inheritance.rs index f1c2a88cb0..6fb4e6b857 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/objc_inheritance.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/objc_inheritance.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] - -use objc::{self, class, msg_send, sel, sel_impl}; +use objc::{self, msg_send, sel, sel_impl, class}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] @@ -50,8 +44,7 @@ impl From for Foo { impl std::convert::TryFrom for Bar { type Error = &'static str; fn try_from(parent: Foo) -> Result { - let is_kind_of: bool = - unsafe { msg_send!(parent, isKindOfClass: class!(Bar)) }; + let is_kind_of: bool = unsafe { msg_send!(parent, isKindOfClass : class!(Bar)) }; if is_kind_of { Ok(Bar(parent.0)) } else { @@ -85,8 +78,7 @@ impl From for Bar { impl std::convert::TryFrom for Baz { type Error = &'static str; fn try_from(parent: Bar) -> Result { - let is_kind_of: bool = - unsafe { msg_send!(parent, isKindOfClass: class!(Baz)) }; + let is_kind_of: bool = unsafe { msg_send!(parent, isKindOfClass : class!(Baz)) }; if is_kind_of { Ok(Baz(parent.0)) } else { @@ -103,8 +95,7 @@ impl From for Foo { impl std::convert::TryFrom for Baz { type Error = &'static str; fn try_from(parent: Foo) -> Result { - let is_kind_of: bool = - unsafe { msg_send!(parent, isKindOfClass: class!(Baz)) }; + let is_kind_of: bool = unsafe { msg_send!(parent, isKindOfClass : class!(Baz)) }; if is_kind_of { Ok(Baz(parent.0)) } else { diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/objc_template.rs b/bindgen-tests/tests/expectations/tests/libclang-9/objc_template.rs index 3c615035ce..ee47f67d4c 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/objc_template.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/objc_template.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] - -use objc::{self, class, msg_send, sel, sel_impl}; +use objc::{self, msg_send, sel, sel_impl, class}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] @@ -30,7 +24,7 @@ pub trait IFoo: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - msg_send!(*self, get) + msg_send!(* self, get) } } #[repr(transparent)] @@ -48,17 +42,16 @@ impl FooMultiGeneric { Self(unsafe { msg_send!(class!(FooMultiGeneric), alloc) }) } } -impl - IFooMultiGeneric for FooMultiGeneric -{ -} -pub trait IFooMultiGeneric: - Sized + std::ops::Deref -{ +impl IFooMultiGeneric +for FooMultiGeneric {} +pub trait IFooMultiGeneric< + KeyType: 'static, + ObjectType: 'static, +>: Sized + std::ops::Deref { unsafe fn objectForKey_(&self, key: u64) -> u64 where ::Target: objc::Message + Sized, { - msg_send!(*self, objectForKey: key) + msg_send!(* self, objectForKey : key) } } diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/partial-specialization-and-inheritance.rs b/bindgen-tests/tests/expectations/tests/libclang-9/partial-specialization-and-inheritance.rs index e62ea68172..b35befce18 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/partial-specialization-and-inheritance.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/partial-specialization-and-inheritance.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Base { @@ -27,13 +21,11 @@ extern "C" { #[test] fn bindgen_test_layout_Usage() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Usage)) + ::std::mem::size_of:: < Usage > (), 1usize, concat!("Size of: ", + stringify!(Usage)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Usage)) + ::std::mem::align_of:: < Usage > (), 1usize, concat!("Alignment of ", + stringify!(Usage)) ); } diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/type_alias_template_specialized.rs b/bindgen-tests/tests/expectations/tests/libclang-9/type_alias_template_specialized.rs index 19f8881db6..0483cdaf75 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/type_alias_template_specialized.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/type_alias_template_specialized.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Rooted { @@ -12,28 +6,19 @@ pub struct Rooted { } #[test] fn bindgen_test_layout_Rooted() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Rooted)) + ::std::mem::size_of:: < Rooted > (), 4usize, concat!("Size of: ", + stringify!(Rooted)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Rooted)) + ::std::mem::align_of:: < Rooted > (), 4usize, concat!("Alignment of ", + stringify!(Rooted)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Rooted), - "::", - stringify!(ptr) - ) + unsafe { ::std::ptr::addr_of!((* ptr).ptr) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(Rooted), "::", stringify!(ptr)) ); } impl Default for Rooted { @@ -50,19 +35,13 @@ pub type MaybeWrapped = a; #[test] fn __bindgen_test_layout_MaybeWrapped_open0_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!( - "Size of template specialization: ", - stringify!(MaybeWrapped<::std::os::raw::c_int>) - ) + ::std::mem::size_of:: < MaybeWrapped < ::std::os::raw::c_int > > (), 4usize, + concat!("Size of template specialization: ", stringify!(MaybeWrapped < + ::std::os::raw::c_int >)) ); assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(MaybeWrapped<::std::os::raw::c_int>) - ) + ::std::mem::align_of:: < MaybeWrapped < ::std::os::raw::c_int > > (), 4usize, + concat!("Alignment of template specialization: ", stringify!(MaybeWrapped < + ::std::os::raw::c_int >)) ); } diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/zero-sized-array.rs b/bindgen-tests/tests/expectations/tests/libclang-9/zero-sized-array.rs index 3066fac40a..f6b8324f68 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/zero-sized-array.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/zero-sized-array.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Default)] pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); @@ -43,28 +37,19 @@ pub struct ZeroSizedArray { } #[test] fn bindgen_test_layout_ZeroSizedArray() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(ZeroSizedArray)) + ::std::mem::size_of:: < ZeroSizedArray > (), 0usize, concat!("Size of: ", + stringify!(ZeroSizedArray)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(ZeroSizedArray)) + ::std::mem::align_of:: < ZeroSizedArray > (), 1usize, concat!("Alignment of ", + stringify!(ZeroSizedArray)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ZeroSizedArray), - "::", - stringify!(arr) - ) + unsafe { ::std::ptr::addr_of!((* ptr).arr) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(ZeroSizedArray), "::", stringify!(arr)) ); } /// And nor should this get an `_address` field. @@ -75,32 +60,24 @@ pub struct ContainsZeroSizedArray { } #[test] fn bindgen_test_layout_ContainsZeroSizedArray() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(ContainsZeroSizedArray)) + ::std::mem::size_of:: < ContainsZeroSizedArray > (), 0usize, concat!("Size of: ", + stringify!(ContainsZeroSizedArray)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < ContainsZeroSizedArray > (), 1usize, concat!("Alignment of ", stringify!(ContainsZeroSizedArray)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).zsa) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContainsZeroSizedArray), - "::", - stringify!(zsa) - ) + unsafe { ::std::ptr::addr_of!((* ptr).zsa) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(ContainsZeroSizedArray), "::", + stringify!(zsa)) ); } -/// Inheriting from ZeroSizedArray shouldn't cause an `_address` to be inserted -/// either. +/** Inheriting from ZeroSizedArray shouldn't cause an `_address` to be inserted + either.*/ #[repr(C)] #[derive(Debug, Default)] pub struct InheritsZeroSizedArray { @@ -109,13 +86,11 @@ pub struct InheritsZeroSizedArray { #[test] fn bindgen_test_layout_InheritsZeroSizedArray() { assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(InheritsZeroSizedArray)) + ::std::mem::size_of:: < InheritsZeroSizedArray > (), 0usize, concat!("Size of: ", + stringify!(InheritsZeroSizedArray)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < InheritsZeroSizedArray > (), 1usize, concat!("Alignment of ", stringify!(InheritsZeroSizedArray)) ); } @@ -127,28 +102,20 @@ pub struct DynamicallySizedArray { } #[test] fn bindgen_test_layout_DynamicallySizedArray() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(DynamicallySizedArray)) + ::std::mem::size_of:: < DynamicallySizedArray > (), 0usize, concat!("Size of: ", + stringify!(DynamicallySizedArray)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < DynamicallySizedArray > (), 1usize, concat!("Alignment of ", stringify!(DynamicallySizedArray)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(DynamicallySizedArray), - "::", - stringify!(arr) - ) + unsafe { ::std::ptr::addr_of!((* ptr).arr) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(DynamicallySizedArray), "::", + stringify!(arr)) ); } /// No `_address` field here either. @@ -159,27 +126,19 @@ pub struct ContainsDynamicallySizedArray { } #[test] fn bindgen_test_layout_ContainsDynamicallySizedArray() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 0usize, + ::std::mem::size_of:: < ContainsDynamicallySizedArray > (), 0usize, concat!("Size of: ", stringify!(ContainsDynamicallySizedArray)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < ContainsDynamicallySizedArray > (), 1usize, concat!("Alignment of ", stringify!(ContainsDynamicallySizedArray)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dsa) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContainsDynamicallySizedArray), - "::", - stringify!(dsa) - ) + unsafe { ::std::ptr::addr_of!((* ptr).dsa) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(ContainsDynamicallySizedArray), "::", + stringify!(dsa)) ); } diff --git a/bindgen-tests/tests/expectations/tests/long_double.rs b/bindgen-tests/tests/expectations/tests/long_double.rs index 2c3b6c937f..c33f6ede45 100644 --- a/bindgen-tests/tests/expectations/tests/long_double.rs +++ b/bindgen-tests/tests/expectations/tests/long_double.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[repr(align(16))] #[derive(Debug, Default, Copy, Clone)] @@ -13,22 +7,17 @@ pub struct foo { } #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of:: < foo > (), 16usize, concat!("Size of: ", stringify!(foo)) ); assert_eq!( - ::std::mem::align_of::(), - 16usize, - concat!("Alignment of ", stringify!(foo)) + ::std::mem::align_of:: < foo > (), 16usize, concat!("Alignment of ", + stringify!(foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); } diff --git a/bindgen-tests/tests/expectations/tests/macro-expr-basic.rs b/bindgen-tests/tests/expectations/tests/macro-expr-basic.rs index 4eeb310c8f..21c81b317c 100644 --- a/bindgen-tests/tests/expectations/tests/macro-expr-basic.rs +++ b/bindgen-tests/tests/expectations/tests/macro-expr-basic.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const FOO: u32 = 1; pub const BAR: u32 = 4; pub const BAZ: u32 = 5; diff --git a/bindgen-tests/tests/expectations/tests/macro-expr-uncommon-token.rs b/bindgen-tests/tests/expectations/tests/macro-expr-uncommon-token.rs index b2f2ebd2e2..c905e5aa90 100644 --- a/bindgen-tests/tests/expectations/tests/macro-expr-uncommon-token.rs +++ b/bindgen-tests/tests/expectations/tests/macro-expr-uncommon-token.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const MODBUS_WOOT: u32 = 3; extern "C" { pub fn foo(); diff --git a/bindgen-tests/tests/expectations/tests/macro-redef.rs b/bindgen-tests/tests/expectations/tests/macro-redef.rs index ff5654f47b..12e3d3d587 100644 --- a/bindgen-tests/tests/expectations/tests/macro-redef.rs +++ b/bindgen-tests/tests/expectations/tests/macro-redef.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const FOO: u32 = 4; pub const BAR: u32 = 5; pub const BAZ: u32 = 6; diff --git a/bindgen-tests/tests/expectations/tests/macro_const.rs b/bindgen-tests/tests/expectations/tests/macro_const.rs index eecd8bd74e..e4e27dea52 100644 --- a/bindgen-tests/tests/expectations/tests/macro_const.rs +++ b/bindgen-tests/tests/expectations/tests/macro_const.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const foo: &[u8; 4] = b"bar\0"; pub const CHAR: u8 = 98u8; pub const CHARR: u8 = 0u8; diff --git a/bindgen-tests/tests/expectations/tests/macro_const_1_0.rs b/bindgen-tests/tests/expectations/tests/macro_const_1_0.rs index 8523a68af9..2f3e228d80 100644 --- a/bindgen-tests/tests/expectations/tests/macro_const_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/macro_const_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const foo: &'static [u8; 4] = b"bar\0"; pub const CHAR: u8 = 98u8; pub const CHARR: u8 = 0u8; diff --git a/bindgen-tests/tests/expectations/tests/maddness-is-avoidable.rs b/bindgen-tests/tests/expectations/tests/maddness-is-avoidable.rs index 12157f4b9d..0876aeb904 100644 --- a/bindgen-tests/tests/expectations/tests/maddness-is-avoidable.rs +++ b/bindgen-tests/tests/expectations/tests/maddness-is-avoidable.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct RefPtr { diff --git a/bindgen-tests/tests/expectations/tests/mangling-ios.rs b/bindgen-tests/tests/expectations/tests/mangling-ios.rs index 8a4ff6578e..05b7aecd3e 100644 --- a/bindgen-tests/tests/expectations/tests/mangling-ios.rs +++ b/bindgen-tests/tests/expectations/tests/mangling-ios.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub fn foo(); } diff --git a/bindgen-tests/tests/expectations/tests/mangling-linux32.rs b/bindgen-tests/tests/expectations/tests/mangling-linux32.rs index bddd761794..6b2a5e076d 100644 --- a/bindgen-tests/tests/expectations/tests/mangling-linux32.rs +++ b/bindgen-tests/tests/expectations/tests/mangling-linux32.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub fn foo(); } @@ -20,13 +14,10 @@ extern "C" { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) + ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", + stringify!(Foo)) ); } diff --git a/bindgen-tests/tests/expectations/tests/mangling-linux64.rs b/bindgen-tests/tests/expectations/tests/mangling-linux64.rs index bddd761794..6b2a5e076d 100644 --- a/bindgen-tests/tests/expectations/tests/mangling-linux64.rs +++ b/bindgen-tests/tests/expectations/tests/mangling-linux64.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub fn foo(); } @@ -20,13 +14,10 @@ extern "C" { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) + ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", + stringify!(Foo)) ); } diff --git a/bindgen-tests/tests/expectations/tests/mangling-macos.rs b/bindgen-tests/tests/expectations/tests/mangling-macos.rs index 9af36259fd..6f59e943f7 100644 --- a/bindgen-tests/tests/expectations/tests/mangling-macos.rs +++ b/bindgen-tests/tests/expectations/tests/mangling-macos.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub fn foo(); } @@ -20,13 +14,10 @@ extern "C" { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) + ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", + stringify!(Foo)) ); } diff --git a/bindgen-tests/tests/expectations/tests/mangling-win64.rs b/bindgen-tests/tests/expectations/tests/mangling-win64.rs index cb5f7103ad..232fe582a1 100644 --- a/bindgen-tests/tests/expectations/tests/mangling-win64.rs +++ b/bindgen-tests/tests/expectations/tests/mangling-win64.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub fn foo(); } @@ -20,13 +14,10 @@ extern "C" { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) + ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", + stringify!(Foo)) ); } diff --git a/bindgen-tests/tests/expectations/tests/merge-extern-blocks.rs b/bindgen-tests/tests/expectations/tests/merge-extern-blocks.rs index ae9799d275..cf1abdc789 100644 --- a/bindgen-tests/tests/expectations/tests/merge-extern-blocks.rs +++ b/bindgen-tests/tests/expectations/tests/merge-extern-blocks.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![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 { #[allow(unused_imports)] @@ -16,28 +10,19 @@ pub mod root { } #[test] fn bindgen_test_layout_Point() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Point)) + ::std::mem::size_of:: < Point > (), 4usize, concat!("Size of: ", + stringify!(Point)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Point)) + ::std::mem::align_of:: < Point > (), 4usize, concat!("Alignment of ", + stringify!(Point)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Point), - "::", - stringify!(x) - ) + unsafe { ::std::ptr::addr_of!((* ptr).x) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(Point), "::", stringify!(x)) ); } pub mod ns { @@ -50,30 +35,20 @@ pub mod root { } #[test] fn bindgen_test_layout_Point() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Point)) + ::std::mem::size_of:: < Point > (), 4usize, concat!("Size of: ", + stringify!(Point)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Point)) + ::std::mem::align_of:: < Point > (), 4usize, concat!("Alignment of ", + stringify!(Point)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Point), - "::", - stringify!(x) - ) + unsafe { ::std::ptr::addr_of!((* ptr).x) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(Point), "::", + stringify!(x)) ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/method-mangling.rs b/bindgen-tests/tests/expectations/tests/method-mangling.rs index e4627ac8a7..7586070c36 100644 --- a/bindgen-tests/tests/expectations/tests/method-mangling.rs +++ b/bindgen-tests/tests/expectations/tests/method-mangling.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { @@ -13,14 +7,11 @@ pub struct Foo { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) + ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", + stringify!(Foo)) ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/module-allowlisted.rs b/bindgen-tests/tests/expectations/tests/module-allowlisted.rs index 30cdb3580b..64e4045bcf 100644 --- a/bindgen-tests/tests/expectations/tests/module-allowlisted.rs +++ b/bindgen-tests/tests/expectations/tests/module-allowlisted.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![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 { #[allow(unused_imports)] @@ -17,14 +11,12 @@ pub mod root { #[test] fn bindgen_test_layout_Test() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Test)) + ::std::mem::size_of:: < Test > (), 1usize, concat!("Size of: ", + stringify!(Test)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Test)) + ::std::mem::align_of:: < Test > (), 1usize, concat!("Alignment of ", + stringify!(Test)) ); } } diff --git a/bindgen-tests/tests/expectations/tests/msvc-no-usr.rs b/bindgen-tests/tests/expectations/tests/msvc-no-usr.rs index 64db43a6b6..62b9e8c364 100644 --- a/bindgen-tests/tests/expectations/tests/msvc-no-usr.rs +++ b/bindgen-tests/tests/expectations/tests/msvc-no-usr.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct A { @@ -12,22 +6,16 @@ pub struct A { } #[test] fn bindgen_test_layout_A() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(A)) + ::std::mem::size_of:: < A > (), 8usize, concat!("Size of: ", stringify!(A)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(A)) + ::std::mem::align_of:: < A > (), 8usize, concat!("Alignment of ", stringify!(A)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).foo) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(foo)) ); } diff --git a/bindgen-tests/tests/expectations/tests/multiple-inherit-empty-correct-layout.rs b/bindgen-tests/tests/expectations/tests/multiple-inherit-empty-correct-layout.rs index 55b3d1e31b..27322ecd41 100644 --- a/bindgen-tests/tests/expectations/tests/multiple-inherit-empty-correct-layout.rs +++ b/bindgen-tests/tests/expectations/tests/multiple-inherit-empty-correct-layout.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { @@ -13,14 +7,11 @@ pub struct Foo { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) + ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", + stringify!(Foo)) ); } #[repr(C)] @@ -31,14 +22,11 @@ pub struct Bar { #[test] fn bindgen_test_layout_Bar() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Bar)) + ::std::mem::size_of:: < Bar > (), 1usize, concat!("Size of: ", stringify!(Bar)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Bar)) + ::std::mem::align_of:: < Bar > (), 1usize, concat!("Alignment of ", + stringify!(Bar)) ); } #[repr(C)] @@ -49,13 +37,10 @@ pub struct Baz { #[test] fn bindgen_test_layout_Baz() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Baz)) + ::std::mem::size_of:: < Baz > (), 1usize, concat!("Size of: ", stringify!(Baz)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Baz)) + ::std::mem::align_of:: < Baz > (), 1usize, concat!("Alignment of ", + stringify!(Baz)) ); } diff --git a/bindgen-tests/tests/expectations/tests/mutable.rs b/bindgen-tests/tests/expectations/tests/mutable.rs index 94c703266a..eed5848181 100644 --- a/bindgen-tests/tests/expectations/tests/mutable.rs +++ b/bindgen-tests/tests/expectations/tests/mutable.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct C { @@ -13,40 +7,21 @@ pub struct C { } #[test] fn bindgen_test_layout_C() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(C)) + ::std::mem::size_of:: < C > (), 8usize, concat!("Size of: ", stringify!(C)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C)) + ::std::mem::align_of:: < C > (), 4usize, concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(m_member) - ) + unsafe { ::std::ptr::addr_of!((* ptr).m_member) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(m_member)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).m_other) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(m_other) - ) + unsafe { ::std::ptr::addr_of!((* ptr).m_other) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(m_other)) ); } #[repr(C)] @@ -56,30 +31,20 @@ pub struct NonCopiable { } #[test] fn bindgen_test_layout_NonCopiable() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(NonCopiable)) + ::std::mem::size_of:: < NonCopiable > (), 4usize, concat!("Size of: ", + stringify!(NonCopiable)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(NonCopiable)) + ::std::mem::align_of:: < NonCopiable > (), 4usize, concat!("Alignment of ", + stringify!(NonCopiable)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NonCopiable), - "::", - stringify!(m_member) - ) + unsafe { ::std::ptr::addr_of!((* ptr).m_member) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(NonCopiable), "::", + stringify!(m_member)) ); } #[repr(C)] @@ -89,36 +54,19 @@ pub struct NonCopiableWithNonCopiableMutableMember { } #[test] fn bindgen_test_layout_NonCopiableWithNonCopiableMutableMember() { - const UNINIT: ::std::mem::MaybeUninit< - NonCopiableWithNonCopiableMutableMember, - > = ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!( - "Size of: ", - stringify!(NonCopiableWithNonCopiableMutableMember) - ) + ::std::mem::size_of:: < NonCopiableWithNonCopiableMutableMember > (), 4usize, + concat!("Size of: ", stringify!(NonCopiableWithNonCopiableMutableMember)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!( - "Alignment of ", - stringify!(NonCopiableWithNonCopiableMutableMember) - ) + ::std::mem::align_of:: < NonCopiableWithNonCopiableMutableMember > (), 4usize, + concat!("Alignment of ", stringify!(NonCopiableWithNonCopiableMutableMember)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NonCopiableWithNonCopiableMutableMember), - "::", - stringify!(m_member) - ) + unsafe { ::std::ptr::addr_of!((* ptr).m_member) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", + stringify!(NonCopiableWithNonCopiableMutableMember), "::", stringify!(m_member)) ); } diff --git a/bindgen-tests/tests/expectations/tests/namespace.rs b/bindgen-tests/tests/expectations/tests/namespace.rs index 49c8a7ef48..83543b851e 100644 --- a/bindgen-tests/tests/expectations/tests/namespace.rs +++ b/bindgen-tests/tests/expectations/tests/namespace.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![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 { #[allow(unused_imports)] @@ -33,30 +27,19 @@ pub mod root { } #[test] fn bindgen_test_layout_A() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(A)) + ::std::mem::size_of:: < A > (), 4usize, concat!("Size of: ", + stringify!(A)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(A)) + ::std::mem::align_of:: < A > (), 4usize, concat!("Alignment of ", + stringify!(A)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(A), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(b)) ); } } @@ -86,8 +69,7 @@ pub mod root { #[derive(Debug)] pub struct D { pub m_c: root::C, - pub _phantom_0: - ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } impl Default for D { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/nested-template-typedef.rs b/bindgen-tests/tests/expectations/tests/nested-template-typedef.rs index ab761d286f..4a4dd2ffe1 100644 --- a/bindgen-tests/tests/expectations/tests/nested-template-typedef.rs +++ b/bindgen-tests/tests/expectations/tests/nested-template-typedef.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { diff --git a/bindgen-tests/tests/expectations/tests/nested.rs b/bindgen-tests/tests/expectations/tests/nested.rs index 415a740561..373a04fa90 100644 --- a/bindgen-tests/tests/expectations/tests/nested.rs +++ b/bindgen-tests/tests/expectations/tests/nested.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Calc { @@ -12,22 +6,17 @@ pub struct Calc { } #[test] fn bindgen_test_layout_Calc() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Calc)) + ::std::mem::size_of:: < Calc > (), 4usize, concat!("Size of: ", stringify!(Calc)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Calc)) + ::std::mem::align_of:: < Calc > (), 4usize, concat!("Alignment of ", + stringify!(Calc)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).w) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).w) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Calc), "::", stringify!(w)) ); } @@ -50,62 +39,42 @@ pub struct Test_Size_Dimension { #[test] fn bindgen_test_layout_Test_Size_Dimension() { assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Test_Size_Dimension)) + ::std::mem::size_of:: < Test_Size_Dimension > (), 4usize, concat!("Size of: ", + stringify!(Test_Size_Dimension)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < Test_Size_Dimension > (), 4usize, concat!("Alignment of ", stringify!(Test_Size_Dimension)) ); } #[test] fn bindgen_test_layout_Test_Size() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Test_Size)) + ::std::mem::size_of:: < Test_Size > (), 8usize, concat!("Size of: ", + stringify!(Test_Size)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Test_Size)) + ::std::mem::align_of:: < Test_Size > (), 4usize, concat!("Alignment of ", + stringify!(Test_Size)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mWidth) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Test_Size), - "::", - stringify!(mWidth) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mWidth) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(Test_Size), "::", stringify!(mWidth)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mHeight) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(Test_Size), - "::", - stringify!(mHeight) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mHeight) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(Test_Size), "::", stringify!(mHeight)) ); } #[test] fn bindgen_test_layout_Test() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Test)) + ::std::mem::size_of:: < Test > (), 1usize, concat!("Size of: ", stringify!(Test)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Test)) + ::std::mem::align_of:: < Test > (), 1usize, concat!("Alignment of ", + stringify!(Test)) ); } diff --git a/bindgen-tests/tests/expectations/tests/nested_vtable.rs b/bindgen-tests/tests/expectations/tests/nested_vtable.rs index 7ee483044e..1470d673ff 100644 --- a/bindgen-tests/tests/expectations/tests/nested_vtable.rs +++ b/bindgen-tests/tests/expectations/tests/nested_vtable.rs @@ -1,14 +1,9 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct nsISupports__bindgen_vtable { - pub nsISupports_QueryInterface: - unsafe extern "C" fn(this: *mut nsISupports) -> *mut nsISupports, + pub nsISupports_QueryInterface: unsafe extern "C" fn( + this: *mut nsISupports, + ) -> *mut nsISupports, } #[repr(C)] #[derive(Debug, Copy, Clone)] @@ -18,14 +13,12 @@ pub struct nsISupports { #[test] fn bindgen_test_layout_nsISupports() { assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(nsISupports)) + ::std::mem::size_of:: < nsISupports > (), 8usize, concat!("Size of: ", + stringify!(nsISupports)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(nsISupports)) + ::std::mem::align_of:: < nsISupports > (), 8usize, concat!("Alignment of ", + stringify!(nsISupports)) ); } impl Default for nsISupports { @@ -51,14 +44,12 @@ pub struct nsIRunnable { #[test] fn bindgen_test_layout_nsIRunnable() { assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(nsIRunnable)) + ::std::mem::size_of:: < nsIRunnable > (), 8usize, concat!("Size of: ", + stringify!(nsIRunnable)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(nsIRunnable)) + ::std::mem::align_of:: < nsIRunnable > (), 8usize, concat!("Alignment of ", + stringify!(nsIRunnable)) ); } impl Default for nsIRunnable { @@ -78,14 +69,12 @@ pub struct Runnable { #[test] fn bindgen_test_layout_Runnable() { assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Runnable)) + ::std::mem::size_of:: < Runnable > (), 8usize, concat!("Size of: ", + stringify!(Runnable)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Runnable)) + ::std::mem::align_of:: < Runnable > (), 8usize, concat!("Alignment of ", + stringify!(Runnable)) ); } impl Default for Runnable { diff --git a/bindgen-tests/tests/expectations/tests/nested_within_namespace.rs b/bindgen-tests/tests/expectations/tests/nested_within_namespace.rs index 629c449a61..2131a5d86a 100644 --- a/bindgen-tests/tests/expectations/tests/nested_within_namespace.rs +++ b/bindgen-tests/tests/expectations/tests/nested_within_namespace.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![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 { #[allow(unused_imports)] @@ -24,58 +18,38 @@ pub mod root { } #[test] fn bindgen_test_layout_Bar_Baz() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Bar_Baz)) + ::std::mem::size_of:: < Bar_Baz > (), 4usize, concat!("Size of: ", + stringify!(Bar_Baz)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Bar_Baz)) + ::std::mem::align_of:: < Bar_Baz > (), 4usize, concat!("Alignment of ", + stringify!(Bar_Baz)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar_Baz), - "::", - stringify!(foo) - ) + unsafe { ::std::ptr::addr_of!((* ptr).foo) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(Bar_Baz), "::", + stringify!(foo)) ); } #[test] fn bindgen_test_layout_Bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Bar)) + ::std::mem::size_of:: < Bar > (), 4usize, concat!("Size of: ", + stringify!(Bar)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Bar)) + ::std::mem::align_of:: < Bar > (), 4usize, concat!("Alignment of ", + stringify!(Bar)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(foo) - ) + unsafe { ::std::ptr::addr_of!((* ptr).foo) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(Bar), "::", + stringify!(foo)) ); } #[repr(C)] @@ -85,30 +59,20 @@ pub mod root { } #[test] fn bindgen_test_layout_Baz() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Baz)) + ::std::mem::size_of:: < Baz > (), 4usize, concat!("Size of: ", + stringify!(Baz)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Baz)) + ::std::mem::align_of:: < Baz > (), 4usize, concat!("Alignment of ", + stringify!(Baz)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Baz), - "::", - stringify!(baz) - ) + unsafe { ::std::ptr::addr_of!((* ptr).baz) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(Baz), "::", + stringify!(baz)) ); } } diff --git a/bindgen-tests/tests/expectations/tests/newtype-enum.rs b/bindgen-tests/tests/expectations/tests/newtype-enum.rs index 26a4eb1fdf..ea25950de0 100644 --- a/bindgen-tests/tests/expectations/tests/newtype-enum.rs +++ b/bindgen-tests/tests/expectations/tests/newtype-enum.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] impl Foo { pub const Bar: Foo = Foo(2); } diff --git a/bindgen-tests/tests/expectations/tests/newtype-global-enum.rs b/bindgen-tests/tests/expectations/tests/newtype-global-enum.rs index cf23cca60b..29b87bff06 100644 --- a/bindgen-tests/tests/expectations/tests/newtype-global-enum.rs +++ b/bindgen-tests/tests/expectations/tests/newtype-global-enum.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const Foo_Bar: Foo = Foo(2); pub const Foo_Baz: Foo = Foo(4); pub const Foo_Duplicated: Foo = Foo(4); diff --git a/bindgen-tests/tests/expectations/tests/no-comments.rs b/bindgen-tests/tests/expectations/tests/no-comments.rs index a375d8ea69..626c5747e8 100644 --- a/bindgen-tests/tests/expectations/tests/no-comments.rs +++ b/bindgen-tests/tests/expectations/tests/no-comments.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { @@ -12,22 +6,17 @@ pub struct Foo { } #[test] fn bindgen_test_layout_Foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of:: < Foo > (), 4usize, concat!("Size of: ", stringify!(Foo)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Foo)) + ::std::mem::align_of:: < Foo > (), 4usize, concat!("Alignment of ", + stringify!(Foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).s) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).s) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(s)) ); } diff --git a/bindgen-tests/tests/expectations/tests/no-derive-debug.rs b/bindgen-tests/tests/expectations/tests/no-derive-debug.rs index c7a6d1843b..dff97781d0 100644 --- a/bindgen-tests/tests/expectations/tests/no-derive-debug.rs +++ b/bindgen-tests/tests/expectations/tests/no-derive-debug.rs @@ -1,19 +1,12 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Default)] pub struct foo { bar: ::std::os::raw::c_int, } - -/// bar should compile. It will normally derive debug, but our blocklist of foo -/// and replacement for another type that doesn't implement it would prevent it -/// from building if --no-derive-debug didn't work. +/** bar should compile. It will normally derive debug, but our blocklist of foo + and replacement for another type that doesn't implement it would prevent it + from building if --no-derive-debug didn't work.*/ #[repr(C)] pub struct bar { pub foo: foo, @@ -21,27 +14,21 @@ pub struct bar { } #[test] fn bindgen_test_layout_bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(bar)) + ::std::mem::size_of:: < bar > (), 8usize, concat!("Size of: ", stringify!(bar)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(bar)) + ::std::mem::align_of:: < bar > (), 4usize, concat!("Alignment of ", + stringify!(bar)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).foo) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(bar), "::", stringify!(foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 4usize, + unsafe { ::std::ptr::addr_of!((* ptr).baz) as usize - ptr as usize }, 4usize, concat!("Offset of field: ", stringify!(bar), "::", stringify!(baz)) ); } diff --git a/bindgen-tests/tests/expectations/tests/no-derive-default.rs b/bindgen-tests/tests/expectations/tests/no-derive-default.rs index 46b2cb4ee7..483520f0aa 100644 --- a/bindgen-tests/tests/expectations/tests/no-derive-default.rs +++ b/bindgen-tests/tests/expectations/tests/no-derive-default.rs @@ -1,19 +1,12 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug)] pub struct foo { bar: ::std::os::raw::c_int, } - -/// bar should compile. It will normally derive default, but our blocklist of foo -/// and replacement for another type that doesn't implement it would prevent it -/// from building if --no-derive-default didn't work. +/** bar should compile. It will normally derive default, but our blocklist of foo + and replacement for another type that doesn't implement it would prevent it + from building if --no-derive-default didn't work.*/ #[repr(C)] pub struct bar { pub foo: foo, @@ -21,27 +14,21 @@ pub struct bar { } #[test] fn bindgen_test_layout_bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(bar)) + ::std::mem::size_of:: < bar > (), 8usize, concat!("Size of: ", stringify!(bar)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(bar)) + ::std::mem::align_of:: < bar > (), 4usize, concat!("Alignment of ", + stringify!(bar)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).foo) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(bar), "::", stringify!(foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 4usize, + unsafe { ::std::ptr::addr_of!((* ptr).baz) as usize - ptr as usize }, 4usize, concat!("Offset of field: ", stringify!(bar), "::", stringify!(baz)) ); } diff --git a/bindgen-tests/tests/expectations/tests/no-hash-allowlisted.rs b/bindgen-tests/tests/expectations/tests/no-hash-allowlisted.rs index 549b72b53b..80aaf7eed8 100644 --- a/bindgen-tests/tests/expectations/tests/no-hash-allowlisted.rs +++ b/bindgen-tests/tests/expectations/tests/no-hash-allowlisted.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct NoHash { @@ -12,22 +6,18 @@ pub struct NoHash { } #[test] fn bindgen_test_layout_NoHash() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(NoHash)) + ::std::mem::size_of:: < NoHash > (), 4usize, concat!("Size of: ", + stringify!(NoHash)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(NoHash)) + ::std::mem::align_of:: < NoHash > (), 4usize, concat!("Alignment of ", + stringify!(NoHash)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).i) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(NoHash), "::", stringify!(i)) ); } diff --git a/bindgen-tests/tests/expectations/tests/no-hash-opaque.rs b/bindgen-tests/tests/expectations/tests/no-hash-opaque.rs index 49ff4daad7..67da7b6fe5 100644 --- a/bindgen-tests/tests/expectations/tests/no-hash-opaque.rs +++ b/bindgen-tests/tests/expectations/tests/no-hash-opaque.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[repr(align(4))] #[derive(Debug, Default, Copy, Clone)] @@ -14,13 +8,11 @@ pub struct NoHash { #[test] fn bindgen_test_layout_NoHash() { assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(NoHash)) + ::std::mem::size_of:: < NoHash > (), 4usize, concat!("Size of: ", + stringify!(NoHash)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(NoHash)) + ::std::mem::align_of:: < NoHash > (), 4usize, concat!("Alignment of ", + stringify!(NoHash)) ); } diff --git a/bindgen-tests/tests/expectations/tests/no-partialeq-allowlisted.rs b/bindgen-tests/tests/expectations/tests/no-partialeq-allowlisted.rs index c7895fe64b..11d7b37610 100644 --- a/bindgen-tests/tests/expectations/tests/no-partialeq-allowlisted.rs +++ b/bindgen-tests/tests/expectations/tests/no-partialeq-allowlisted.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct NoPartialEq { @@ -12,27 +6,18 @@ pub struct NoPartialEq { } #[test] fn bindgen_test_layout_NoPartialEq() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(NoPartialEq)) + ::std::mem::size_of:: < NoPartialEq > (), 4usize, concat!("Size of: ", + stringify!(NoPartialEq)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(NoPartialEq)) + ::std::mem::align_of:: < NoPartialEq > (), 4usize, concat!("Alignment of ", + stringify!(NoPartialEq)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NoPartialEq), - "::", - stringify!(i) - ) + unsafe { ::std::ptr::addr_of!((* ptr).i) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(NoPartialEq), "::", stringify!(i)) ); } diff --git a/bindgen-tests/tests/expectations/tests/no-partialeq-opaque.rs b/bindgen-tests/tests/expectations/tests/no-partialeq-opaque.rs index 423799a6b9..04f3a5c18c 100644 --- a/bindgen-tests/tests/expectations/tests/no-partialeq-opaque.rs +++ b/bindgen-tests/tests/expectations/tests/no-partialeq-opaque.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[repr(align(4))] #[derive(Debug, Default, Copy, Clone)] @@ -14,13 +8,11 @@ pub struct NoPartialEq { #[test] fn bindgen_test_layout_NoPartialEq() { assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(NoPartialEq)) + ::std::mem::size_of:: < NoPartialEq > (), 4usize, concat!("Size of: ", + stringify!(NoPartialEq)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(NoPartialEq)) + ::std::mem::align_of:: < NoPartialEq > (), 4usize, concat!("Alignment of ", + stringify!(NoPartialEq)) ); } diff --git a/bindgen-tests/tests/expectations/tests/no-recursive-allowlisting.rs b/bindgen-tests/tests/expectations/tests/no-recursive-allowlisting.rs index 6f1e19ba95..4e8e06e94f 100644 --- a/bindgen-tests/tests/expectations/tests/no-recursive-allowlisting.rs +++ b/bindgen-tests/tests/expectations/tests/no-recursive-allowlisting.rs @@ -1,12 +1,5 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub enum Bar {} - #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Foo { @@ -14,22 +7,17 @@ pub struct Foo { } #[test] fn bindgen_test_layout_Foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of:: < Foo > (), 8usize, concat!("Size of: ", stringify!(Foo)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Foo)) + ::std::mem::align_of:: < Foo > (), 8usize, concat!("Alignment of ", + stringify!(Foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).baz) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(baz)) ); } diff --git a/bindgen-tests/tests/expectations/tests/no-std.rs b/bindgen-tests/tests/expectations/tests/no-std.rs index 457242c2ba..9c70dd0027 100644 --- a/bindgen-tests/tests/expectations/tests/no-std.rs +++ b/bindgen-tests/tests/expectations/tests/no-std.rs @@ -1,15 +1,9 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![no_std] mod libc { pub type c_int = i32; pub enum c_void {} } - #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct foo { @@ -19,32 +13,25 @@ pub struct foo { } #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::core::mem::MaybeUninit = - ::core::mem::MaybeUninit::uninit(); + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::core::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(foo)) + ::core::mem::size_of:: < foo > (), 16usize, concat!("Size of: ", stringify!(foo)) ); assert_eq!( - ::core::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(foo)) + ::core::mem::align_of:: < foo > (), 8usize, concat!("Alignment of ", + stringify!(foo)) ); assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, + unsafe { ::core::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) ); assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 4usize, + unsafe { ::core::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 4usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) ); assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 8usize, + unsafe { ::core::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 8usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); } diff --git a/bindgen-tests/tests/expectations/tests/no_copy.rs b/bindgen-tests/tests/expectations/tests/no_copy.rs index daccf757ec..b92c542482 100644 --- a/bindgen-tests/tests/expectations/tests/no_copy.rs +++ b/bindgen-tests/tests/expectations/tests/no_copy.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] ///
#[repr(C)] #[derive(Debug, Default)] diff --git a/bindgen-tests/tests/expectations/tests/no_copy_allowlisted.rs b/bindgen-tests/tests/expectations/tests/no_copy_allowlisted.rs index 1c46de75f1..e427a55f1b 100644 --- a/bindgen-tests/tests/expectations/tests/no_copy_allowlisted.rs +++ b/bindgen-tests/tests/expectations/tests/no_copy_allowlisted.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default)] pub struct NoCopy { @@ -12,22 +6,18 @@ pub struct NoCopy { } #[test] fn bindgen_test_layout_NoCopy() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(NoCopy)) + ::std::mem::size_of:: < NoCopy > (), 4usize, concat!("Size of: ", + stringify!(NoCopy)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(NoCopy)) + ::std::mem::align_of:: < NoCopy > (), 4usize, concat!("Alignment of ", + stringify!(NoCopy)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).i) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(NoCopy), "::", stringify!(i)) ); } diff --git a/bindgen-tests/tests/expectations/tests/no_copy_opaque.rs b/bindgen-tests/tests/expectations/tests/no_copy_opaque.rs index 7fc3529f6e..83dcdf61d2 100644 --- a/bindgen-tests/tests/expectations/tests/no_copy_opaque.rs +++ b/bindgen-tests/tests/expectations/tests/no_copy_opaque.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[repr(align(4))] #[derive(Debug, Default)] @@ -14,13 +8,11 @@ pub struct NoCopy { #[test] fn bindgen_test_layout_NoCopy() { assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(NoCopy)) + ::std::mem::size_of:: < NoCopy > (), 4usize, concat!("Size of: ", + stringify!(NoCopy)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(NoCopy)) + ::std::mem::align_of:: < NoCopy > (), 4usize, concat!("Alignment of ", + stringify!(NoCopy)) ); } diff --git a/bindgen-tests/tests/expectations/tests/no_debug.rs b/bindgen-tests/tests/expectations/tests/no_debug.rs index 21850ecb15..9a162c6f70 100644 --- a/bindgen-tests/tests/expectations/tests/no_debug.rs +++ b/bindgen-tests/tests/expectations/tests/no_debug.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] ///
#[repr(C)] #[derive(Default, Copy, Clone)] diff --git a/bindgen-tests/tests/expectations/tests/no_debug_allowlisted.rs b/bindgen-tests/tests/expectations/tests/no_debug_allowlisted.rs index 859dad8cb3..00b213cbae 100644 --- a/bindgen-tests/tests/expectations/tests/no_debug_allowlisted.rs +++ b/bindgen-tests/tests/expectations/tests/no_debug_allowlisted.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Default, Copy, Clone)] pub struct NoDebug { @@ -12,27 +6,18 @@ pub struct NoDebug { } #[test] fn bindgen_test_layout_NoDebug() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(NoDebug)) + ::std::mem::size_of:: < NoDebug > (), 4usize, concat!("Size of: ", + stringify!(NoDebug)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(NoDebug)) + ::std::mem::align_of:: < NoDebug > (), 4usize, concat!("Alignment of ", + stringify!(NoDebug)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NoDebug), - "::", - stringify!(i) - ) + unsafe { ::std::ptr::addr_of!((* ptr).i) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(NoDebug), "::", stringify!(i)) ); } 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 334f39ddb0..7078a4c255 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,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct Generic { pub t: [T; 40usize], diff --git a/bindgen-tests/tests/expectations/tests/no_debug_opaque.rs b/bindgen-tests/tests/expectations/tests/no_debug_opaque.rs index 4b657481cd..62b5fcc289 100644 --- a/bindgen-tests/tests/expectations/tests/no_debug_opaque.rs +++ b/bindgen-tests/tests/expectations/tests/no_debug_opaque.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[repr(align(4))] #[derive(Default, Copy, Clone)] @@ -14,13 +8,11 @@ pub struct NoDebug { #[test] fn bindgen_test_layout_NoDebug() { assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(NoDebug)) + ::std::mem::size_of:: < NoDebug > (), 4usize, concat!("Size of: ", + stringify!(NoDebug)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(NoDebug)) + ::std::mem::align_of:: < NoDebug > (), 4usize, concat!("Alignment of ", + stringify!(NoDebug)) ); } diff --git a/bindgen-tests/tests/expectations/tests/no_default.rs b/bindgen-tests/tests/expectations/tests/no_default.rs index 22fdbf36e4..fd3d86e277 100644 --- a/bindgen-tests/tests/expectations/tests/no_default.rs +++ b/bindgen-tests/tests/expectations/tests/no_default.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] ///
#[repr(C)] #[derive(Debug, Copy, Clone)] diff --git a/bindgen-tests/tests/expectations/tests/no_default_allowlisted.rs b/bindgen-tests/tests/expectations/tests/no_default_allowlisted.rs index c4deceb4b0..f624c2aeaf 100644 --- a/bindgen-tests/tests/expectations/tests/no_default_allowlisted.rs +++ b/bindgen-tests/tests/expectations/tests/no_default_allowlisted.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct NoDefault { @@ -12,27 +6,18 @@ pub struct NoDefault { } #[test] fn bindgen_test_layout_NoDefault() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(NoDefault)) + ::std::mem::size_of:: < NoDefault > (), 4usize, concat!("Size of: ", + stringify!(NoDefault)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(NoDefault)) + ::std::mem::align_of:: < NoDefault > (), 4usize, concat!("Alignment of ", + stringify!(NoDefault)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NoDefault), - "::", - stringify!(i) - ) + unsafe { ::std::ptr::addr_of!((* ptr).i) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(NoDefault), "::", stringify!(i)) ); } 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 6c44a9dd28..f5b4322065 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,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct Generic { pub t: [T; 40usize], diff --git a/bindgen-tests/tests/expectations/tests/no_default_opaque.rs b/bindgen-tests/tests/expectations/tests/no_default_opaque.rs index 3c928551e6..4b8f0f464b 100644 --- a/bindgen-tests/tests/expectations/tests/no_default_opaque.rs +++ b/bindgen-tests/tests/expectations/tests/no_default_opaque.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[repr(align(4))] #[derive(Debug, Copy, Clone)] @@ -14,13 +8,11 @@ pub struct NoDefault { #[test] fn bindgen_test_layout_NoDefault() { assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(NoDefault)) + ::std::mem::size_of:: < NoDefault > (), 4usize, concat!("Size of: ", + stringify!(NoDefault)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(NoDefault)) + ::std::mem::align_of:: < NoDefault > (), 4usize, concat!("Alignment of ", + stringify!(NoDefault)) ); } diff --git a/bindgen-tests/tests/expectations/tests/no_size_t_is_usize.rs b/bindgen-tests/tests/expectations/tests/no_size_t_is_usize.rs index f399a66724..a9e4149d7e 100644 --- a/bindgen-tests/tests/expectations/tests/no_size_t_is_usize.rs +++ b/bindgen-tests/tests/expectations/tests/no_size_t_is_usize.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type size_t = ::std::os::raw::c_ulong; pub type ssize_t = ::std::os::raw::c_long; #[repr(C)] @@ -16,32 +10,24 @@ pub struct A { } #[test] fn bindgen_test_layout_A() { - const UNINIT: ::std::mem::MaybeUninit
= - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 24usize, - concat!("Size of: ", stringify!(A)) + ::std::mem::size_of:: < A > (), 24usize, concat!("Size of: ", stringify!(A)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(A)) + ::std::mem::align_of:: < A > (), 8usize, concat!("Alignment of ", stringify!(A)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).len) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(len)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).offset) as usize - ptr as usize }, - 8usize, + unsafe { ::std::ptr::addr_of!((* ptr).offset) as usize - ptr as usize }, 8usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(offset)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize }, - 16usize, + unsafe { ::std::ptr::addr_of!((* ptr).next) as usize - ptr as usize }, 16usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(next)) ); } diff --git a/bindgen-tests/tests/expectations/tests/non-type-params.rs b/bindgen-tests/tests/expectations/tests/non-type-params.rs index 2b38e21667..64e352a77d 100644 --- a/bindgen-tests/tests/expectations/tests/non-type-params.rs +++ b/bindgen-tests/tests/expectations/tests/non-type-params.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type Array16 = u8; pub type ArrayInt4 = [u32; 4usize]; #[repr(C)] @@ -16,53 +10,29 @@ pub struct UsesArray { } #[test] fn bindgen_test_layout_UsesArray() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 40usize, - concat!("Size of: ", stringify!(UsesArray)) + ::std::mem::size_of:: < UsesArray > (), 40usize, concat!("Size of: ", + stringify!(UsesArray)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(UsesArray)) + ::std::mem::align_of:: < UsesArray > (), 4usize, concat!("Alignment of ", + stringify!(UsesArray)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).array_char_16) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(UsesArray), - "::", - stringify!(array_char_16) - ) + unsafe { ::std::ptr::addr_of!((* ptr).array_char_16) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(UsesArray), "::", + stringify!(array_char_16)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).array_bool_8) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(UsesArray), - "::", - stringify!(array_bool_8) - ) + unsafe { ::std::ptr::addr_of!((* ptr).array_bool_8) as usize - ptr as usize }, + 16usize, concat!("Offset of field: ", stringify!(UsesArray), "::", + stringify!(array_bool_8)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).array_int_4) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(UsesArray), - "::", - stringify!(array_int_4) - ) + unsafe { ::std::ptr::addr_of!((* ptr).array_int_4) as usize - ptr as usize }, + 24usize, concat!("Offset of field: ", stringify!(UsesArray), "::", + stringify!(array_int_4)) ); } diff --git a/bindgen-tests/tests/expectations/tests/noreturn.rs b/bindgen-tests/tests/expectations/tests/noreturn.rs index a390578211..2b9b316b5d 100644 --- a/bindgen-tests/tests/expectations/tests/noreturn.rs +++ b/bindgen-tests/tests/expectations/tests/noreturn.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { #[link_name = "\u{1}_Z1fv"] pub fn f() -> !; diff --git a/bindgen-tests/tests/expectations/tests/nsBaseHashtable.rs b/bindgen-tests/tests/expectations/tests/nsBaseHashtable.rs index 26179b763e..f2f7eefb46 100644 --- a/bindgen-tests/tests/expectations/tests/nsBaseHashtable.rs +++ b/bindgen-tests/tests/expectations/tests/nsBaseHashtable.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct nsBaseHashtableET { diff --git a/bindgen-tests/tests/expectations/tests/nsStyleAutoArray.rs b/bindgen-tests/tests/expectations/tests/nsStyleAutoArray.rs index fab18c1cab..b475b1a9b1 100644 --- a/bindgen-tests/tests/expectations/tests/nsStyleAutoArray.rs +++ b/bindgen-tests/tests/expectations/tests/nsStyleAutoArray.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct nsTArray { diff --git a/bindgen-tests/tests/expectations/tests/objc_allowlist.rs b/bindgen-tests/tests/expectations/tests/objc_allowlist.rs index 370cab9332..7ccd4e3c04 100644 --- a/bindgen-tests/tests/expectations/tests/objc_allowlist.rs +++ b/bindgen-tests/tests/expectations/tests/objc_allowlist.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] - -use objc::{self, class, msg_send, sel, sel_impl}; +use objc::{self, msg_send, sel, sel_impl, class}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; pub trait PSomeProtocol: Sized + std::ops::Deref { @@ -14,7 +8,7 @@ pub trait PSomeProtocol: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - msg_send!(*self, protocolMethod) + msg_send!(* self, protocolMethod) } unsafe fn protocolClassMethod() where @@ -45,7 +39,7 @@ pub trait IAllowlistMe: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - msg_send!(*self, method) + msg_send!(* self, method) } unsafe fn classMethod() where diff --git a/bindgen-tests/tests/expectations/tests/objc_blocklist.rs b/bindgen-tests/tests/expectations/tests/objc_blocklist.rs index 7d5d19b083..e5c5d2bfd5 100644 --- a/bindgen-tests/tests/expectations/tests/objc_blocklist.rs +++ b/bindgen-tests/tests/expectations/tests/objc_blocklist.rs @@ -1,11 +1,5 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] - #[macro_use] extern crate objc; #[allow(non_camel_case_types)] @@ -31,12 +25,12 @@ pub trait ISomeClass: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - msg_send!(*self, ambiguouslyBlockedMethod) + msg_send!(* self, ambiguouslyBlockedMethod) } unsafe fn instanceMethod(&self) where ::Target: objc::Message + Sized, { - msg_send!(*self, instanceMethod) + msg_send!(* self, instanceMethod) } } diff --git a/bindgen-tests/tests/expectations/tests/objc_category.rs b/bindgen-tests/tests/expectations/tests/objc_category.rs index 9d60233bed..a1b1e3b1f1 100644 --- a/bindgen-tests/tests/expectations/tests/objc_category.rs +++ b/bindgen-tests/tests/expectations/tests/objc_category.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] - -use objc::{self, class, msg_send, sel, sel_impl}; +use objc::{self, msg_send, sel, sel_impl, class}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] @@ -30,7 +24,7 @@ pub trait IFoo: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - msg_send!(*self, method) + msg_send!(* self, method) } } impl Foo_BarCategory for Foo {} @@ -39,6 +33,6 @@ pub trait Foo_BarCategory: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - msg_send!(*self, categoryMethod) + msg_send!(* self, categoryMethod) } } diff --git a/bindgen-tests/tests/expectations/tests/objc_class.rs b/bindgen-tests/tests/expectations/tests/objc_class.rs index b322bddcb6..50bdea53ee 100644 --- a/bindgen-tests/tests/expectations/tests/objc_class.rs +++ b/bindgen-tests/tests/expectations/tests/objc_class.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] - -use objc::{self, class, msg_send, sel, sel_impl}; +use objc::{self, msg_send, sel, sel_impl, class}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; extern "C" { @@ -33,6 +27,6 @@ pub trait IFoo: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - msg_send!(*self, method) + msg_send!(* self, method) } } diff --git a/bindgen-tests/tests/expectations/tests/objc_class_method.rs b/bindgen-tests/tests/expectations/tests/objc_class_method.rs index 29e70256ff..6bc2621462 100644 --- a/bindgen-tests/tests/expectations/tests/objc_class_method.rs +++ b/bindgen-tests/tests/expectations/tests/objc_class_method.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] - -use objc::{self, class, msg_send, sel, sel_impl}; +use objc::{self, msg_send, sel, sel_impl, class}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] @@ -36,13 +30,13 @@ pub trait IFoo: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - msg_send!(class!(Foo), methodWithInt: foo) + msg_send!(class!(Foo), methodWithInt : foo) } unsafe fn methodWithFoo_(foo: Foo) where ::Target: objc::Message + Sized, { - msg_send!(class!(Foo), methodWithFoo: foo) + msg_send!(class!(Foo), methodWithFoo : foo) } unsafe fn methodReturningInt() -> ::std::os::raw::c_int where @@ -60,9 +54,12 @@ pub trait IFoo: Sized + std::ops::Deref { intvalue: ::std::os::raw::c_int, ptr: *mut ::std::os::raw::c_char, floatvalue: f32, - ) where + ) + where ::Target: objc::Message + Sized, { - msg_send ! (class ! (Foo) , methodWithArg1 : intvalue andArg2 : ptr andArg3 : floatvalue) + msg_send!( + class!(Foo), methodWithArg1 : intvalue andArg2 : ptr andArg3 : floatvalue + ) } } diff --git a/bindgen-tests/tests/expectations/tests/objc_escape.rs b/bindgen-tests/tests/expectations/tests/objc_escape.rs index c2f0ce313c..f0ddcc1545 100644 --- a/bindgen-tests/tests/expectations/tests/objc_escape.rs +++ b/bindgen-tests/tests/expectations/tests/objc_escape.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] - -use objc::{self, class, msg_send, sel, sel_impl}; +use objc::{self, msg_send, sel, sel_impl, class}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] @@ -26,13 +20,10 @@ impl A { } impl IA for A {} pub trait IA: Sized + std::ops::Deref { - unsafe fn f_as_( - &self, - arg1: ::std::os::raw::c_int, - arg2: ::std::os::raw::c_int, - ) where + unsafe fn f_as_(&self, arg1: ::std::os::raw::c_int, arg2: ::std::os::raw::c_int) + where ::Target: objc::Message + Sized, { - msg_send ! (* self , f : arg1 r#as : arg2) + msg_send!(* self, f : arg1 r#as : arg2) } } diff --git a/bindgen-tests/tests/expectations/tests/objc_interface.rs b/bindgen-tests/tests/expectations/tests/objc_interface.rs index 89e64d86b6..2cc602efd4 100644 --- a/bindgen-tests/tests/expectations/tests/objc_interface.rs +++ b/bindgen-tests/tests/expectations/tests/objc_interface.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] - -use objc::{self, class, msg_send, sel, sel_impl}; +use objc::{self, msg_send, sel, sel_impl, class}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] diff --git a/bindgen-tests/tests/expectations/tests/objc_interface_type.rs b/bindgen-tests/tests/expectations/tests/objc_interface_type.rs index 423ba910d4..2cf92ded84 100644 --- a/bindgen-tests/tests/expectations/tests/objc_interface_type.rs +++ b/bindgen-tests/tests/expectations/tests/objc_interface_type.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] - -use objc::{self, class, msg_send, sel, sel_impl}; +use objc::{self, msg_send, sel, sel_impl, class}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] @@ -33,28 +27,19 @@ pub struct FooStruct { } #[test] fn bindgen_test_layout_FooStruct() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(FooStruct)) + ::std::mem::size_of:: < FooStruct > (), 8usize, concat!("Size of: ", + stringify!(FooStruct)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(FooStruct)) + ::std::mem::align_of:: < FooStruct > (), 8usize, concat!("Alignment of ", + stringify!(FooStruct)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(FooStruct), - "::", - stringify!(foo) - ) + unsafe { ::std::ptr::addr_of!((* ptr).foo) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(FooStruct), "::", stringify!(foo)) ); } impl Default for FooStruct { diff --git a/bindgen-tests/tests/expectations/tests/objc_method.rs b/bindgen-tests/tests/expectations/tests/objc_method.rs index 593fd27738..7d9fd84cf2 100644 --- a/bindgen-tests/tests/expectations/tests/objc_method.rs +++ b/bindgen-tests/tests/expectations/tests/objc_method.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] - -use objc::{self, class, msg_send, sel, sel_impl}; +use objc::{self, msg_send, sel, sel_impl, class}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] @@ -30,41 +24,42 @@ pub trait IFoo: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - msg_send!(*self, method) + msg_send!(* self, method) } unsafe fn methodWithInt_(&self, foo: ::std::os::raw::c_int) where ::Target: objc::Message + Sized, { - msg_send!(*self, methodWithInt: foo) + msg_send!(* self, methodWithInt : foo) } unsafe fn methodWithFoo_(&self, foo: Foo) where ::Target: objc::Message + Sized, { - msg_send!(*self, methodWithFoo: foo) + msg_send!(* self, methodWithFoo : foo) } unsafe fn methodReturningInt(&self) -> ::std::os::raw::c_int where ::Target: objc::Message + Sized, { - msg_send!(*self, methodReturningInt) + msg_send!(* self, methodReturningInt) } unsafe fn methodReturningFoo(&self) -> Foo where ::Target: objc::Message + Sized, { - msg_send!(*self, methodReturningFoo) + msg_send!(* self, methodReturningFoo) } unsafe fn methodWithArg1_andArg2_andArg3_( &self, intvalue: ::std::os::raw::c_int, ptr: *mut ::std::os::raw::c_char, floatvalue: f32, - ) where + ) + where ::Target: objc::Message + Sized, { - msg_send ! (* self , methodWithArg1 : intvalue andArg2 : ptr andArg3 : floatvalue) + msg_send!(* self, methodWithArg1 : intvalue andArg2 : ptr andArg3 : floatvalue) } unsafe fn methodWithAndWithoutKeywords_arg2Name__arg4Name_( &self, @@ -76,7 +71,10 @@ pub trait IFoo: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - msg_send ! (* self , methodWithAndWithoutKeywords : arg1 arg2Name : arg2 arg3 : arg3 arg4Name : arg4) + msg_send!( + * self, methodWithAndWithoutKeywords : arg1 arg2Name : arg2 arg3 : arg3 + arg4Name : arg4 + ) } } pub type instancetype = id; diff --git a/bindgen-tests/tests/expectations/tests/objc_method_clash.rs b/bindgen-tests/tests/expectations/tests/objc_method_clash.rs index ac77cc19e3..4d35661f8c 100644 --- a/bindgen-tests/tests/expectations/tests/objc_method_clash.rs +++ b/bindgen-tests/tests/expectations/tests/objc_method_clash.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] - -use objc::{self, class, msg_send, sel, sel_impl}; +use objc::{self, msg_send, sel, sel_impl, class}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] @@ -30,7 +24,7 @@ pub trait IFoo: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - msg_send!(*self, foo) + msg_send!(* self, foo) } unsafe fn class_foo() where diff --git a/bindgen-tests/tests/expectations/tests/objc_pointer_return_types.rs b/bindgen-tests/tests/expectations/tests/objc_pointer_return_types.rs index 1ec8494d25..73c3d6e5c8 100644 --- a/bindgen-tests/tests/expectations/tests/objc_pointer_return_types.rs +++ b/bindgen-tests/tests/expectations/tests/objc_pointer_return_types.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] - -use objc::{self, class, msg_send, sel, sel_impl}; +use objc::{self, msg_send, sel, sel_impl, class}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] @@ -47,7 +41,7 @@ pub trait IFoo: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - msg_send!(*self, methodUsingBar: my_bar) + msg_send!(* self, methodUsingBar : my_bar) } unsafe fn methodReturningBar() -> Bar where diff --git a/bindgen-tests/tests/expectations/tests/objc_property_fnptr.rs b/bindgen-tests/tests/expectations/tests/objc_property_fnptr.rs index 9f3fabd272..e038edf7f1 100644 --- a/bindgen-tests/tests/expectations/tests/objc_property_fnptr.rs +++ b/bindgen-tests/tests/expectations/tests/objc_property_fnptr.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] - -use objc::{self, class, msg_send, sel, sel_impl}; +use objc::{self, msg_send, sel, sel_impl, class}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] @@ -38,7 +32,7 @@ pub trait IFoo: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - msg_send!(*self, func) + msg_send!(* self, func) } unsafe fn setFunc_( &self, @@ -49,9 +43,10 @@ pub trait IFoo: Sized + std::ops::Deref { arg3: f32, ) -> ::std::os::raw::c_int, >, - ) where + ) + where ::Target: objc::Message + Sized, { - msg_send!(*self, setFunc: func) + msg_send!(* self, setFunc : func) } } diff --git a/bindgen-tests/tests/expectations/tests/objc_protocol.rs b/bindgen-tests/tests/expectations/tests/objc_protocol.rs index 5bd7d433f4..533f5e2ef3 100644 --- a/bindgen-tests/tests/expectations/tests/objc_protocol.rs +++ b/bindgen-tests/tests/expectations/tests/objc_protocol.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] - -use objc::{self, class, msg_send, sel, sel_impl}; +use objc::{self, msg_send, sel, sel_impl, class}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; pub trait PFoo: Sized + std::ops::Deref {} diff --git a/bindgen-tests/tests/expectations/tests/objc_protocol_inheritance.rs b/bindgen-tests/tests/expectations/tests/objc_protocol_inheritance.rs index f5f80e2e30..8bb0ef6f62 100644 --- a/bindgen-tests/tests/expectations/tests/objc_protocol_inheritance.rs +++ b/bindgen-tests/tests/expectations/tests/objc_protocol_inheritance.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] - -use objc::{self, class, msg_send, sel, sel_impl}; +use objc::{self, msg_send, sel, sel_impl, class}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; pub trait PFoo: Sized + std::ops::Deref {} @@ -53,8 +47,7 @@ impl From for Foo { impl std::convert::TryFrom for Bar { type Error = &'static str; fn try_from(parent: Foo) -> Result { - let is_kind_of: bool = - unsafe { msg_send!(parent, isKindOfClass: class!(Bar)) }; + let is_kind_of: bool = unsafe { msg_send!(parent, isKindOfClass : class!(Bar)) }; if is_kind_of { Ok(Bar(parent.0)) } else { diff --git a/bindgen-tests/tests/expectations/tests/objc_sel_and_id.rs b/bindgen-tests/tests/expectations/tests/objc_sel_and_id.rs index 0017eab00d..25854d8488 100644 --- a/bindgen-tests/tests/expectations/tests/objc_sel_and_id.rs +++ b/bindgen-tests/tests/expectations/tests/objc_sel_and_id.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] - -use objc::{self, class, msg_send, sel, sel_impl}; +use objc::{self, msg_send, sel, sel_impl, class}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/only_bitfields.rs b/bindgen-tests/tests/expectations/tests/only_bitfields.rs index 2f063b5b38..e36f8235bb 100644 --- a/bindgen-tests/tests/expectations/tests/only_bitfields.rs +++ b/bindgen-tests/tests/expectations/tests/only_bitfields.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -100,22 +92,16 @@ pub struct C { #[test] fn bindgen_test_layout_C() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(C)) + ::std::mem::size_of:: < C > (), 1usize, concat!("Size of: ", stringify!(C)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(C)) + ::std::mem::align_of:: < C > (), 1usize, concat!("Alignment of ", stringify!(C)) ); } impl C { #[inline] pub fn a(&self) -> bool { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) } } #[inline] pub fn set_a(&mut self, val: bool) { @@ -126,9 +112,7 @@ impl C { } #[inline] pub fn b(&self) -> bool { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(1usize, 7u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 7u8) as u8) } } #[inline] pub fn set_b(&mut self, val: bool) { @@ -138,20 +122,26 @@ impl C { } } #[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.set(0usize, 1u8, { - let a: u8 = unsafe { ::std::mem::transmute(a) }; - a as u64 - }); - __bindgen_bitfield_unit.set(1usize, 7u8, { - let b: u8 = unsafe { ::std::mem::transmute(b) }; - b as u64 - }); + 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 + .set( + 0usize, + 1u8, + { + let a: u8 = unsafe { ::std::mem::transmute(a) }; + a as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 1usize, + 7u8, + { + let b: u8 = unsafe { ::std::mem::transmute(b) }; + b as u64 + }, + ); __bindgen_bitfield_unit } } diff --git a/bindgen-tests/tests/expectations/tests/opaque-template-inst-member-2.rs b/bindgen-tests/tests/expectations/tests/opaque-template-inst-member-2.rs index c28d935664..2fd9ed7c61 100644 --- a/bindgen-tests/tests/expectations/tests/opaque-template-inst-member-2.rs +++ b/bindgen-tests/tests/expectations/tests/opaque-template-inst-member-2.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -/// This is like `opaque-template-inst-member.hpp` except exercising the cases -/// where we are OK to derive Debug/Hash/PartialEq. +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +/** This is like `opaque-template-inst-member.hpp` except exercising the cases + where we are OK to derive Debug/Hash/PartialEq.*/ #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct OpaqueTemplate { @@ -21,38 +15,25 @@ pub struct ContainsOpaqueTemplate { } #[test] fn bindgen_test_layout_ContainsOpaqueTemplate() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(ContainsOpaqueTemplate)) + ::std::mem::size_of:: < ContainsOpaqueTemplate > (), 8usize, concat!("Size of: ", + stringify!(ContainsOpaqueTemplate)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < ContainsOpaqueTemplate > (), 4usize, concat!("Alignment of ", stringify!(ContainsOpaqueTemplate)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mBlah) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContainsOpaqueTemplate), - "::", - stringify!(mBlah) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mBlah) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(ContainsOpaqueTemplate), "::", + stringify!(mBlah)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mBaz) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(ContainsOpaqueTemplate), - "::", - stringify!(mBaz) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mBaz) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(ContainsOpaqueTemplate), "::", + stringify!(mBaz)) ); } /// Should also derive Debug/Hash/PartialEq. @@ -64,28 +45,20 @@ pub struct InheritsOpaqueTemplate { } #[test] fn bindgen_test_layout_InheritsOpaqueTemplate() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 16usize, + ::std::mem::size_of:: < InheritsOpaqueTemplate > (), 16usize, concat!("Size of: ", stringify!(InheritsOpaqueTemplate)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, + ::std::mem::align_of:: < InheritsOpaqueTemplate > (), 8usize, concat!("Alignment of ", stringify!(InheritsOpaqueTemplate)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).wow) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(InheritsOpaqueTemplate), - "::", - stringify!(wow) - ) + unsafe { ::std::ptr::addr_of!((* ptr).wow) as usize - ptr as usize }, 8usize, + concat!("Offset of field: ", stringify!(InheritsOpaqueTemplate), "::", + stringify!(wow)) ); } impl Default for InheritsOpaqueTemplate { 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 4ba85f660f..dc50471b8b 100644 --- a/bindgen-tests/tests/expectations/tests/opaque-template-inst-member.rs +++ b/bindgen-tests/tests/expectations/tests/opaque-template-inst-member.rs @@ -1,17 +1,11 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct OpaqueTemplate { pub _address: u8, } -/// This should not end up deriving Debug/Hash because its `mBlah` field cannot derive -/// Debug/Hash because the instantiation's definition cannot derive Debug/Hash. +/** This should not end up deriving Debug/Hash because its `mBlah` field cannot derive + Debug/Hash because the instantiation's definition cannot derive Debug/Hash.*/ #[repr(C)] pub struct ContainsOpaqueTemplate { pub mBlah: [u32; 101usize], @@ -19,38 +13,25 @@ pub struct ContainsOpaqueTemplate { } #[test] fn bindgen_test_layout_ContainsOpaqueTemplate() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 408usize, + ::std::mem::size_of:: < ContainsOpaqueTemplate > (), 408usize, concat!("Size of: ", stringify!(ContainsOpaqueTemplate)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < ContainsOpaqueTemplate > (), 4usize, concat!("Alignment of ", stringify!(ContainsOpaqueTemplate)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mBlah) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContainsOpaqueTemplate), - "::", - stringify!(mBlah) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mBlah) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(ContainsOpaqueTemplate), "::", + stringify!(mBlah)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mBaz) as usize - ptr as usize }, - 404usize, - concat!( - "Offset of field: ", - stringify!(ContainsOpaqueTemplate), - "::", - stringify!(mBaz) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mBaz) as usize - ptr as usize }, 404usize, + concat!("Offset of field: ", stringify!(ContainsOpaqueTemplate), "::", + stringify!(mBaz)) ); } impl Default for ContainsOpaqueTemplate { @@ -67,8 +48,8 @@ impl ::std::cmp::PartialEq for ContainsOpaqueTemplate { &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. +/** 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], @@ -76,28 +57,20 @@ pub struct InheritsOpaqueTemplate { } #[test] fn bindgen_test_layout_InheritsOpaqueTemplate() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 416usize, + ::std::mem::size_of:: < InheritsOpaqueTemplate > (), 416usize, concat!("Size of: ", stringify!(InheritsOpaqueTemplate)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, + ::std::mem::align_of:: < InheritsOpaqueTemplate > (), 8usize, concat!("Alignment of ", stringify!(InheritsOpaqueTemplate)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).wow) as usize - ptr as usize }, - 408usize, - concat!( - "Offset of field: ", - stringify!(InheritsOpaqueTemplate), - "::", - stringify!(wow) - ) + unsafe { ::std::ptr::addr_of!((* ptr).wow) as usize - ptr as usize }, 408usize, + concat!("Offset of field: ", stringify!(InheritsOpaqueTemplate), "::", + stringify!(wow)) ); } impl Default for InheritsOpaqueTemplate { diff --git a/bindgen-tests/tests/expectations/tests/opaque-template-instantiation-namespaced.rs b/bindgen-tests/tests/expectations/tests/opaque-template-instantiation-namespaced.rs index 3575216cb0..62701da3c1 100644 --- a/bindgen-tests/tests/expectations/tests/opaque-template-instantiation-namespaced.rs +++ b/bindgen-tests/tests/expectations/tests/opaque-template-instantiation-namespaced.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![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 { #[allow(unused_imports)] @@ -16,8 +10,7 @@ pub mod root { #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Template { pub member: T, - pub _phantom_0: - ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } impl Default for Template { fn default() -> Self { @@ -35,30 +28,20 @@ pub mod root { } #[test] fn bindgen_test_layout_Foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", + stringify!(Foo)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) + ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", + stringify!(Foo)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Foo), - "::", - stringify!(c) - ) + unsafe { ::std::ptr::addr_of!((* ptr).c) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(Foo), "::", + stringify!(c)) ); } #[repr(C)] @@ -68,30 +51,20 @@ pub mod root { } #[test] fn bindgen_test_layout_Bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Bar)) + ::std::mem::size_of:: < Bar > (), 4usize, concat!("Size of: ", + stringify!(Bar)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Bar)) + ::std::mem::align_of:: < Bar > (), 4usize, concat!("Alignment of ", + stringify!(Bar)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(i) - ) + unsafe { ::std::ptr::addr_of!((* ptr).i) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(Bar), "::", + stringify!(i)) ); } #[repr(C)] @@ -101,31 +74,20 @@ pub mod root { } #[test] fn bindgen_test_layout_ContainsInstantiation() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 1usize, + ::std::mem::size_of:: < ContainsInstantiation > (), 1usize, concat!("Size of: ", stringify!(ContainsInstantiation)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < ContainsInstantiation > (), 1usize, concat!("Alignment of ", stringify!(ContainsInstantiation)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).not_opaque) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContainsInstantiation), - "::", - stringify!(not_opaque) - ) + unsafe { ::std::ptr::addr_of!((* ptr).not_opaque) as usize - ptr as usize + }, 0usize, concat!("Offset of field: ", + stringify!(ContainsInstantiation), "::", stringify!(not_opaque)) ); } impl Default for ContainsInstantiation { @@ -144,55 +106,34 @@ pub mod root { } #[test] fn bindgen_test_layout_ContainsOpaqueInstantiation() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, + ::std::mem::size_of:: < ContainsOpaqueInstantiation > (), 4usize, concat!("Size of: ", stringify!(ContainsOpaqueInstantiation)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!( - "Alignment of ", - stringify!(ContainsOpaqueInstantiation) - ) + ::std::mem::align_of:: < ContainsOpaqueInstantiation > (), 4usize, + concat!("Alignment of ", stringify!(ContainsOpaqueInstantiation)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).opaque) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContainsOpaqueInstantiation), - "::", - stringify!(opaque) - ) + unsafe { ::std::ptr::addr_of!((* ptr).opaque) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", + stringify!(ContainsOpaqueInstantiation), "::", stringify!(opaque)) ); } } #[test] fn __bindgen_test_layout_Template_open0_Foo_close0_instantiation() { assert_eq!( - ::std::mem::size_of::>( - ), - 1usize, - concat!( - "Size of template specialization: ", - stringify!(root::zoidberg::Template) - ) + ::std::mem::size_of:: < root::zoidberg::Template < root::zoidberg::Foo > > + (), 1usize, concat!("Size of template specialization: ", + stringify!(root::zoidberg::Template < root::zoidberg::Foo >)) ); assert_eq!( - ::std::mem::align_of::>( - ), - 1usize, - concat!( - "Alignment of template specialization: ", - stringify!(root::zoidberg::Template) - ) + ::std::mem::align_of:: < root::zoidberg::Template < root::zoidberg::Foo > > + (), 1usize, concat!("Alignment of template specialization: ", + stringify!(root::zoidberg::Template < root::zoidberg::Foo >)) ); } } diff --git a/bindgen-tests/tests/expectations/tests/opaque-template-instantiation.rs b/bindgen-tests/tests/expectations/tests/opaque-template-instantiation.rs index 910c616fd8..f35915f64c 100644 --- a/bindgen-tests/tests/expectations/tests/opaque-template-instantiation.rs +++ b/bindgen-tests/tests/expectations/tests/opaque-template-instantiation.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Template { @@ -27,30 +21,20 @@ pub struct ContainsInstantiation { } #[test] fn bindgen_test_layout_ContainsInstantiation() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(ContainsInstantiation)) + ::std::mem::size_of:: < ContainsInstantiation > (), 1usize, concat!("Size of: ", + stringify!(ContainsInstantiation)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < ContainsInstantiation > (), 1usize, concat!("Alignment of ", stringify!(ContainsInstantiation)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).not_opaque) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContainsInstantiation), - "::", - stringify!(not_opaque) - ) + unsafe { ::std::ptr::addr_of!((* ptr).not_opaque) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(ContainsInstantiation), "::", + stringify!(not_opaque)) ); } impl Default for ContainsInstantiation { @@ -69,46 +53,32 @@ pub struct ContainsOpaqueInstantiation { } #[test] fn bindgen_test_layout_ContainsOpaqueInstantiation() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, + ::std::mem::size_of:: < ContainsOpaqueInstantiation > (), 4usize, concat!("Size of: ", stringify!(ContainsOpaqueInstantiation)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < ContainsOpaqueInstantiation > (), 4usize, concat!("Alignment of ", stringify!(ContainsOpaqueInstantiation)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).opaque) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContainsOpaqueInstantiation), - "::", - stringify!(opaque) - ) + unsafe { ::std::ptr::addr_of!((* ptr).opaque) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(ContainsOpaqueInstantiation), "::", + stringify!(opaque)) ); } #[test] fn __bindgen_test_layout_Template_open0_char_close0_instantiation() { assert_eq!( - ::std::mem::size_of::>(), - 1usize, - concat!( - "Size of template specialization: ", - stringify!(Template<::std::os::raw::c_char>) - ) + ::std::mem::size_of:: < Template < ::std::os::raw::c_char > > (), 1usize, + concat!("Size of template specialization: ", stringify!(Template < + ::std::os::raw::c_char >)) ); assert_eq!( - ::std::mem::align_of::>(), - 1usize, - concat!( - "Alignment of template specialization: ", - stringify!(Template<::std::os::raw::c_char>) - ) + ::std::mem::align_of:: < Template < ::std::os::raw::c_char > > (), 1usize, + concat!("Alignment of template specialization: ", stringify!(Template < + ::std::os::raw::c_char >)) ); } diff --git a/bindgen-tests/tests/expectations/tests/opaque-tracing.rs b/bindgen-tests/tests/expectations/tests/opaque-tracing.rs index 98c5417138..1c3a16ad5c 100644 --- a/bindgen-tests/tests/expectations/tests/opaque-tracing.rs +++ b/bindgen-tests/tests/expectations/tests/opaque-tracing.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { #[link_name = "\u{1}_Z3fooP9Container"] pub fn foo(c: *mut Container); @@ -18,13 +12,11 @@ pub struct Container { #[test] fn bindgen_test_layout_Container() { assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Container)) + ::std::mem::size_of:: < Container > (), 8usize, concat!("Size of: ", + stringify!(Container)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Container)) + ::std::mem::align_of:: < Container > (), 4usize, concat!("Alignment of ", + stringify!(Container)) ); } diff --git a/bindgen-tests/tests/expectations/tests/opaque_in_struct.rs b/bindgen-tests/tests/expectations/tests/opaque_in_struct.rs index 0d13b12106..1e6a58aa21 100644 --- a/bindgen-tests/tests/expectations/tests/opaque_in_struct.rs +++ b/bindgen-tests/tests/expectations/tests/opaque_in_struct.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] ///
#[repr(C)] #[repr(align(4))] @@ -15,14 +9,12 @@ pub struct opaque { #[test] fn bindgen_test_layout_opaque() { assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(opaque)) + ::std::mem::size_of:: < opaque > (), 4usize, concat!("Size of: ", + stringify!(opaque)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(opaque)) + ::std::mem::align_of:: < opaque > (), 4usize, concat!("Alignment of ", + stringify!(opaque)) ); } #[repr(C)] @@ -32,29 +24,19 @@ pub struct container { } #[test] fn bindgen_test_layout_container() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(container)) + ::std::mem::size_of:: < container > (), 4usize, concat!("Size of: ", + stringify!(container)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(container)) + ::std::mem::align_of:: < container > (), 4usize, concat!("Alignment of ", + stringify!(container)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).contained) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(container), - "::", - stringify!(contained) - ) + unsafe { ::std::ptr::addr_of!((* ptr).contained) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(container), "::", + stringify!(contained)) ); } diff --git a/bindgen-tests/tests/expectations/tests/opaque_pointer.rs b/bindgen-tests/tests/expectations/tests/opaque_pointer.rs index 13b8cc366c..cd06c9b4a3 100644 --- a/bindgen-tests/tests/expectations/tests/opaque_pointer.rs +++ b/bindgen-tests/tests/expectations/tests/opaque_pointer.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] ///
#[repr(C)] #[repr(align(4))] @@ -15,14 +9,12 @@ pub struct OtherOpaque { #[test] fn bindgen_test_layout_OtherOpaque() { assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(OtherOpaque)) + ::std::mem::size_of:: < OtherOpaque > (), 4usize, concat!("Size of: ", + stringify!(OtherOpaque)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(OtherOpaque)) + ::std::mem::align_of:: < OtherOpaque > (), 4usize, concat!("Alignment of ", + stringify!(OtherOpaque)) ); } ///
@@ -40,50 +32,28 @@ pub struct WithOpaquePtr { } #[test] fn bindgen_test_layout_WithOpaquePtr() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(WithOpaquePtr)) + ::std::mem::size_of:: < WithOpaquePtr > (), 16usize, concat!("Size of: ", + stringify!(WithOpaquePtr)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(WithOpaquePtr)) + ::std::mem::align_of:: < WithOpaquePtr > (), 8usize, concat!("Alignment of ", + stringify!(WithOpaquePtr)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).whatever) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithOpaquePtr), - "::", - stringify!(whatever) - ) + unsafe { ::std::ptr::addr_of!((* ptr).whatever) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(WithOpaquePtr), "::", + stringify!(whatever)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).other) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(WithOpaquePtr), - "::", - stringify!(other) - ) + unsafe { ::std::ptr::addr_of!((* ptr).other) as usize - ptr as usize }, 8usize, + concat!("Offset of field: ", stringify!(WithOpaquePtr), "::", stringify!(other)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).t) as usize - ptr as usize }, - 12usize, - concat!( - "Offset of field: ", - stringify!(WithOpaquePtr), - "::", - stringify!(t) - ) + unsafe { ::std::ptr::addr_of!((* ptr).t) as usize - ptr as usize }, 12usize, + concat!("Offset of field: ", stringify!(WithOpaquePtr), "::", stringify!(t)) ); } impl Default for WithOpaquePtr { diff --git a/bindgen-tests/tests/expectations/tests/opaque_typedef.rs b/bindgen-tests/tests/expectations/tests/opaque_typedef.rs index c61a294cf6..90c3b709e3 100644 --- a/bindgen-tests/tests/expectations/tests/opaque_typedef.rs +++ b/bindgen-tests/tests/expectations/tests/opaque_typedef.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct RandomTemplate { diff --git a/bindgen-tests/tests/expectations/tests/operator.rs b/bindgen-tests/tests/expectations/tests/operator.rs index 5128226dd8..fa018724fc 100644 --- a/bindgen-tests/tests/expectations/tests/operator.rs +++ b/bindgen-tests/tests/expectations/tests/operator.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { #[link_name = "\u{1}_Z20operator_informationv"] pub fn operator_information() -> ::std::os::raw::c_int; diff --git a/bindgen-tests/tests/expectations/tests/ord-enum.rs b/bindgen-tests/tests/expectations/tests/ord-enum.rs index a72fef8df6..aa2e67ab91 100644 --- a/bindgen-tests/tests/expectations/tests/ord-enum.rs +++ b/bindgen-tests/tests/expectations/tests/ord-enum.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(i32)] #[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] pub enum A { diff --git a/bindgen-tests/tests/expectations/tests/overflowed_enum.rs b/bindgen-tests/tests/expectations/tests/overflowed_enum.rs index 94e166addb..2c67ba6903 100644 --- a/bindgen-tests/tests/expectations/tests/overflowed_enum.rs +++ b/bindgen-tests/tests/expectations/tests/overflowed_enum.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Foo { diff --git a/bindgen-tests/tests/expectations/tests/overloading.rs b/bindgen-tests/tests/expectations/tests/overloading.rs index b43432eb0d..3e8fced8e7 100644 --- a/bindgen-tests/tests/expectations/tests/overloading.rs +++ b/bindgen-tests/tests/expectations/tests/overloading.rs @@ -1,20 +1,11 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { #[link_name = "\u{1}_Z8Evaluatec"] pub fn Evaluate(r: ::std::os::raw::c_char) -> bool; } extern "C" { #[link_name = "\u{1}_Z8Evaluateii"] - pub fn Evaluate1( - x: ::std::os::raw::c_int, - y: ::std::os::raw::c_int, - ) -> bool; + pub fn Evaluate1(x: ::std::os::raw::c_int, y: ::std::os::raw::c_int) -> bool; } extern "C" { #[link_name = "\u{1}_ZN3foo10MyFunctionEv"] diff --git a/bindgen-tests/tests/expectations/tests/packed-bitfield.rs b/bindgen-tests/tests/expectations/tests/packed-bitfield.rs index f90edb930b..a5b34d6e6d 100644 --- a/bindgen-tests/tests/expectations/tests/packed-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/packed-bitfield.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -100,22 +92,17 @@ pub struct Date { #[test] fn bindgen_test_layout_Date() { assert_eq!( - ::std::mem::size_of::(), - 3usize, - concat!("Size of: ", stringify!(Date)) + ::std::mem::size_of:: < Date > (), 3usize, concat!("Size of: ", stringify!(Date)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Date)) + ::std::mem::align_of:: < Date > (), 1usize, concat!("Alignment of ", + stringify!(Date)) ); } impl Date { #[inline] pub fn day(&self) -> ::std::os::raw::c_uchar { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 5u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 5u8) as u8) } } #[inline] pub fn set_day(&mut self, val: ::std::os::raw::c_uchar) { @@ -126,9 +113,7 @@ impl Date { } #[inline] pub fn month(&self) -> ::std::os::raw::c_uchar { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(5usize, 4u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(5usize, 4u8) as u8) } } #[inline] pub fn set_month(&mut self, val: ::std::os::raw::c_uchar) { @@ -139,9 +124,7 @@ impl Date { } #[inline] pub fn year(&self) -> ::std::os::raw::c_short { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(9usize, 15u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(9usize, 15u8) as u16) } } #[inline] pub fn set_year(&mut self, val: ::std::os::raw::c_short) { @@ -156,20 +139,34 @@ impl Date { month: ::std::os::raw::c_uchar, year: ::std::os::raw::c_short, ) -> __BindgenBitfieldUnit<[u8; 3usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 3usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 5u8, { - let day: u8 = unsafe { ::std::mem::transmute(day) }; - day as u64 - }); - __bindgen_bitfield_unit.set(5usize, 4u8, { - let month: u8 = unsafe { ::std::mem::transmute(month) }; - month as u64 - }); - __bindgen_bitfield_unit.set(9usize, 15u8, { - let year: u16 = unsafe { ::std::mem::transmute(year) }; - year as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 3usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 5u8, + { + let day: u8 = unsafe { ::std::mem::transmute(day) }; + day as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 5usize, + 4u8, + { + let month: u8 = unsafe { ::std::mem::transmute(month) }; + month as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 9usize, + 15u8, + { + let year: u16 = unsafe { ::std::mem::transmute(year) }; + year as u64 + }, + ); __bindgen_bitfield_unit } } diff --git a/bindgen-tests/tests/expectations/tests/packed-n-with-padding.rs b/bindgen-tests/tests/expectations/tests/packed-n-with-padding.rs index b171b1da70..739d08dbfa 100644 --- a/bindgen-tests/tests/expectations/tests/packed-n-with-padding.rs +++ b/bindgen-tests/tests/expectations/tests/packed-n-with-padding.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C, packed(2))] #[derive(Debug, Default, Copy, Clone)] pub struct Packed { @@ -15,37 +9,30 @@ pub struct Packed { } #[test] fn bindgen_test_layout_Packed() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 10usize, - concat!("Size of: ", stringify!(Packed)) + ::std::mem::size_of:: < Packed > (), 10usize, concat!("Size of: ", + stringify!(Packed)) ); assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(Packed)) + ::std::mem::align_of:: < Packed > (), 2usize, concat!("Alignment of ", + stringify!(Packed)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Packed), "::", stringify!(a)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 2usize, + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 2usize, concat!("Offset of field: ", stringify!(Packed), "::", stringify!(b)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, - 4usize, + unsafe { ::std::ptr::addr_of!((* ptr).c) as usize - ptr as usize }, 4usize, concat!("Offset of field: ", stringify!(Packed), "::", stringify!(c)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 6usize, + unsafe { ::std::ptr::addr_of!((* ptr).d) as usize - ptr as usize }, 6usize, concat!("Offset of field: ", stringify!(Packed), "::", stringify!(d)) ); } diff --git a/bindgen-tests/tests/expectations/tests/packed-vtable.rs b/bindgen-tests/tests/expectations/tests/packed-vtable.rs index 71688151f5..8ec42e3729 100644 --- a/bindgen-tests/tests/expectations/tests/packed-vtable.rs +++ b/bindgen-tests/tests/expectations/tests/packed-vtable.rs @@ -1,11 +1,5 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(feature = "nightly")] - #[repr(C)] pub struct PackedVtable__bindgen_vtable(::std::os::raw::c_void); #[repr(C, packed)] @@ -15,14 +9,12 @@ pub struct PackedVtable { #[test] fn bindgen_test_layout_PackedVtable() { assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(PackedVtable)) + ::std::mem::size_of:: < PackedVtable > (), 8usize, concat!("Size of: ", + stringify!(PackedVtable)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(PackedVtable)) + ::std::mem::align_of:: < PackedVtable > (), 1usize, concat!("Alignment of ", + stringify!(PackedVtable)) ); } impl Default for PackedVtable { diff --git a/bindgen-tests/tests/expectations/tests/parm-union.rs b/bindgen-tests/tests/expectations/tests/parm-union.rs index 9f7dd20ad9..f110f457d4 100644 --- a/bindgen-tests/tests/expectations/tests/parm-union.rs +++ b/bindgen-tests/tests/expectations/tests/parm-union.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Struct { @@ -13,14 +7,12 @@ pub struct Struct { #[test] fn bindgen_test_layout_Struct() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Struct)) + ::std::mem::size_of:: < Struct > (), 1usize, concat!("Size of: ", + stringify!(Struct)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Struct)) + ::std::mem::align_of:: < Struct > (), 1usize, concat!("Alignment of ", + stringify!(Struct)) ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/parsecb-anonymous-enum-variant-rename.rs b/bindgen-tests/tests/expectations/tests/parsecb-anonymous-enum-variant-rename.rs index 8ead5b8a60..98c10d7ec5 100644 --- a/bindgen-tests/tests/expectations/tests/parsecb-anonymous-enum-variant-rename.rs +++ b/bindgen-tests/tests/expectations/tests/parsecb-anonymous-enum-variant-rename.rs @@ -1,9 +1,3 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const RENAMED_MyVal: _bindgen_ty_1 = 0; pub type _bindgen_ty_1 = ::std::os::raw::c_uint; diff --git a/bindgen-tests/tests/expectations/tests/pointer-attr.rs b/bindgen-tests/tests/expectations/tests/pointer-attr.rs index 95fe9c5f0d..edb29dc499 100644 --- a/bindgen-tests/tests/expectations/tests/pointer-attr.rs +++ b/bindgen-tests/tests/expectations/tests/pointer-attr.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub fn a(arg1: *const ::std::os::raw::c_char); } diff --git a/bindgen-tests/tests/expectations/tests/prefix-link-name-c.rs b/bindgen-tests/tests/expectations/tests/prefix-link-name-c.rs index c363a7874b..e81a3b667d 100644 --- a/bindgen-tests/tests/expectations/tests/prefix-link-name-c.rs +++ b/bindgen-tests/tests/expectations/tests/prefix-link-name-c.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { #[link_name = "\u{1}foo_bar"] pub fn bar() -> ::std::os::raw::c_int; diff --git a/bindgen-tests/tests/expectations/tests/prefix-link-name-cpp.rs b/bindgen-tests/tests/expectations/tests/prefix-link-name-cpp.rs index 535fccbdb7..bf53473d88 100644 --- a/bindgen-tests/tests/expectations/tests/prefix-link-name-cpp.rs +++ b/bindgen-tests/tests/expectations/tests/prefix-link-name-cpp.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { #[link_name = "\u{1}foo_foo"] pub fn baz_foo() -> ::std::os::raw::c_int; diff --git a/bindgen-tests/tests/expectations/tests/prepend-enum-constified-variant.rs b/bindgen-tests/tests/expectations/tests/prepend-enum-constified-variant.rs index b2b094443b..ff49d684f1 100644 --- a/bindgen-tests/tests/expectations/tests/prepend-enum-constified-variant.rs +++ b/bindgen-tests/tests/expectations/tests/prepend-enum-constified-variant.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] impl AVCodecID { pub const AV_CODEC_ID_TTF: AVCodecID = AVCodecID::AV_CODEC_ID_FIRST_UNKNOWN; } diff --git a/bindgen-tests/tests/expectations/tests/prepend_enum_name.rs b/bindgen-tests/tests/expectations/tests/prepend_enum_name.rs index 31db41444c..b4201a8cd9 100644 --- a/bindgen-tests/tests/expectations/tests/prepend_enum_name.rs +++ b/bindgen-tests/tests/expectations/tests/prepend_enum_name.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const FOO_BAR: foo = 0; pub const FOO_BAZ: foo = 1; pub type foo = ::std::os::raw::c_uint; diff --git a/bindgen-tests/tests/expectations/tests/private.rs b/bindgen-tests/tests/expectations/tests/private.rs index ab57d37f3b..cd689979c7 100644 --- a/bindgen-tests/tests/expectations/tests/private.rs +++ b/bindgen-tests/tests/expectations/tests/private.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct HasPrivate { @@ -14,42 +8,25 @@ pub struct HasPrivate { } #[test] fn bindgen_test_layout_HasPrivate() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(HasPrivate)) + ::std::mem::size_of:: < HasPrivate > (), 8usize, concat!("Size of: ", + stringify!(HasPrivate)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(HasPrivate)) + ::std::mem::align_of:: < HasPrivate > (), 4usize, concat!("Alignment of ", + stringify!(HasPrivate)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mNotPrivate) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(HasPrivate), - "::", - stringify!(mNotPrivate) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mNotPrivate) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(HasPrivate), "::", + stringify!(mNotPrivate)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mIsPrivate) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(HasPrivate), - "::", - stringify!(mIsPrivate) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mIsPrivate) as usize - ptr as usize }, + 4usize, concat!("Offset of field: ", stringify!(HasPrivate), "::", + stringify!(mIsPrivate)) ); } ///
@@ -61,42 +38,25 @@ pub struct VeryPrivate { } #[test] fn bindgen_test_layout_VeryPrivate() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(VeryPrivate)) + ::std::mem::size_of:: < VeryPrivate > (), 8usize, concat!("Size of: ", + stringify!(VeryPrivate)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(VeryPrivate)) + ::std::mem::align_of:: < VeryPrivate > (), 4usize, concat!("Alignment of ", + stringify!(VeryPrivate)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mIsPrivate) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(VeryPrivate), - "::", - stringify!(mIsPrivate) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mIsPrivate) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(VeryPrivate), "::", + stringify!(mIsPrivate)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mIsAlsoPrivate) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(VeryPrivate), - "::", - stringify!(mIsAlsoPrivate) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mIsAlsoPrivate) as usize - ptr as usize }, + 4usize, concat!("Offset of field: ", stringify!(VeryPrivate), "::", + stringify!(mIsAlsoPrivate)) ); } ///
@@ -109,41 +69,24 @@ pub struct ContradictPrivate { } #[test] fn bindgen_test_layout_ContradictPrivate() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(ContradictPrivate)) + ::std::mem::size_of:: < ContradictPrivate > (), 8usize, concat!("Size of: ", + stringify!(ContradictPrivate)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(ContradictPrivate)) + ::std::mem::align_of:: < ContradictPrivate > (), 4usize, concat!("Alignment of ", + stringify!(ContradictPrivate)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mNotPrivate) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContradictPrivate), - "::", - stringify!(mNotPrivate) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mNotPrivate) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(ContradictPrivate), "::", + stringify!(mNotPrivate)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mIsPrivate) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(ContradictPrivate), - "::", - stringify!(mIsPrivate) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mIsPrivate) as usize - ptr as usize }, + 4usize, concat!("Offset of field: ", stringify!(ContradictPrivate), "::", + stringify!(mIsPrivate)) ); } diff --git a/bindgen-tests/tests/expectations/tests/private_fields.rs b/bindgen-tests/tests/expectations/tests/private_fields.rs index 8db332a5f3..3408a9a3aa 100644 --- a/bindgen-tests/tests/expectations/tests/private_fields.rs +++ b/bindgen-tests/tests/expectations/tests/private_fields.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -99,38 +91,23 @@ pub struct PubPriv { } #[test] fn bindgen_test_layout_PubPriv() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(PubPriv)) + ::std::mem::size_of:: < PubPriv > (), 8usize, concat!("Size of: ", + stringify!(PubPriv)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(PubPriv)) + ::std::mem::align_of:: < PubPriv > (), 4usize, concat!("Alignment of ", + stringify!(PubPriv)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(PubPriv), - "::", - stringify!(x) - ) + unsafe { ::std::ptr::addr_of!((* ptr).x) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(PubPriv), "::", stringify!(x)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(PubPriv), - "::", - stringify!(y) - ) + unsafe { ::std::ptr::addr_of!((* ptr).y) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(PubPriv), "::", stringify!(y)) ); } #[repr(C)] @@ -144,22 +121,18 @@ pub struct PrivateBitFields { #[test] fn bindgen_test_layout_PrivateBitFields() { assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(PrivateBitFields)) + ::std::mem::size_of:: < PrivateBitFields > (), 4usize, concat!("Size of: ", + stringify!(PrivateBitFields)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(PrivateBitFields)) + ::std::mem::align_of:: < PrivateBitFields > (), 4usize, concat!("Alignment of ", + stringify!(PrivateBitFields)) ); } impl PrivateBitFields { #[inline] fn a(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 4u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 4u8) as u32) } } #[inline] fn set_a(&mut self, val: ::std::os::raw::c_uint) { @@ -170,9 +143,7 @@ impl PrivateBitFields { } #[inline] fn b(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(4usize, 4u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(4usize, 4u8) as u32) } } #[inline] fn set_b(&mut self, val: ::std::os::raw::c_uint) { @@ -186,16 +157,25 @@ impl PrivateBitFields { a: ::std::os::raw::c_uint, b: ::std::os::raw::c_uint, ) -> __BindgenBitfieldUnit<[u8; 1usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 4u8, { - let a: u32 = unsafe { ::std::mem::transmute(a) }; - a as u64 - }); - __bindgen_bitfield_unit.set(4usize, 4u8, { - let b: u32 = unsafe { ::std::mem::transmute(b) }; - b as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 4u8, + { + let a: u32 = unsafe { ::std::mem::transmute(a) }; + a as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 4usize, + 4u8, + { + let b: u32 = unsafe { ::std::mem::transmute(b) }; + b as u64 + }, + ); __bindgen_bitfield_unit } } @@ -210,22 +190,18 @@ pub struct PublicBitFields { #[test] fn bindgen_test_layout_PublicBitFields() { assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(PublicBitFields)) + ::std::mem::size_of:: < PublicBitFields > (), 4usize, concat!("Size of: ", + stringify!(PublicBitFields)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(PublicBitFields)) + ::std::mem::align_of:: < PublicBitFields > (), 4usize, concat!("Alignment of ", + stringify!(PublicBitFields)) ); } impl PublicBitFields { #[inline] pub fn a(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 4u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 4u8) as u32) } } #[inline] pub fn set_a(&mut self, val: ::std::os::raw::c_uint) { @@ -236,9 +212,7 @@ impl PublicBitFields { } #[inline] pub fn b(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(4usize, 4u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(4usize, 4u8) as u32) } } #[inline] pub fn set_b(&mut self, val: ::std::os::raw::c_uint) { @@ -252,16 +226,25 @@ impl PublicBitFields { a: ::std::os::raw::c_uint, b: ::std::os::raw::c_uint, ) -> __BindgenBitfieldUnit<[u8; 1usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 4u8, { - let a: u32 = unsafe { ::std::mem::transmute(a) }; - a as u64 - }); - __bindgen_bitfield_unit.set(4usize, 4u8, { - let b: u32 = unsafe { ::std::mem::transmute(b) }; - b as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 4u8, + { + let a: u32 = unsafe { ::std::mem::transmute(a) }; + a as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 4usize, + 4u8, + { + let b: u32 = unsafe { ::std::mem::transmute(b) }; + b as u64 + }, + ); __bindgen_bitfield_unit } } @@ -276,22 +259,18 @@ pub struct MixedBitFields { #[test] fn bindgen_test_layout_MixedBitFields() { assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(MixedBitFields)) + ::std::mem::size_of:: < MixedBitFields > (), 4usize, concat!("Size of: ", + stringify!(MixedBitFields)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(MixedBitFields)) + ::std::mem::align_of:: < MixedBitFields > (), 4usize, concat!("Alignment of ", + stringify!(MixedBitFields)) ); } impl MixedBitFields { #[inline] fn a(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 4u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 4u8) as u32) } } #[inline] fn set_a(&mut self, val: ::std::os::raw::c_uint) { @@ -302,9 +281,7 @@ impl MixedBitFields { } #[inline] pub fn d(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(4usize, 4u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(4usize, 4u8) as u32) } } #[inline] pub fn set_d(&mut self, val: ::std::os::raw::c_uint) { @@ -318,16 +295,25 @@ impl MixedBitFields { a: ::std::os::raw::c_uint, d: ::std::os::raw::c_uint, ) -> __BindgenBitfieldUnit<[u8; 1usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 4u8, { - let a: u32 = unsafe { ::std::mem::transmute(a) }; - a as u64 - }); - __bindgen_bitfield_unit.set(4usize, 4u8, { - let d: u32 = unsafe { ::std::mem::transmute(d) }; - d as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 4u8, + { + let a: u32 = unsafe { ::std::mem::transmute(a) }; + a as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 4usize, + 4u8, + { + let d: u32 = unsafe { ::std::mem::transmute(d) }; + d as u64 + }, + ); __bindgen_bitfield_unit } } @@ -338,28 +324,18 @@ pub struct Base { } #[test] fn bindgen_test_layout_Base() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Base)) + ::std::mem::size_of:: < Base > (), 4usize, concat!("Size of: ", stringify!(Base)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Base)) + ::std::mem::align_of:: < Base > (), 4usize, concat!("Alignment of ", + stringify!(Base)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Base), - "::", - stringify!(member) - ) + unsafe { ::std::ptr::addr_of!((* ptr).member) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(Base), "::", stringify!(member)) ); } #[repr(C)] @@ -370,14 +346,12 @@ pub struct InheritsPrivately { #[test] fn bindgen_test_layout_InheritsPrivately() { assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(InheritsPrivately)) + ::std::mem::size_of:: < InheritsPrivately > (), 4usize, concat!("Size of: ", + stringify!(InheritsPrivately)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(InheritsPrivately)) + ::std::mem::align_of:: < InheritsPrivately > (), 4usize, concat!("Alignment of ", + stringify!(InheritsPrivately)) ); } #[repr(C)] @@ -388,13 +362,11 @@ pub struct InheritsPublically { #[test] fn bindgen_test_layout_InheritsPublically() { assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(InheritsPublically)) + ::std::mem::size_of:: < InheritsPublically > (), 4usize, concat!("Size of: ", + stringify!(InheritsPublically)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < InheritsPublically > (), 4usize, concat!("Alignment of ", stringify!(InheritsPublically)) ); } @@ -411,28 +383,20 @@ pub struct WithAnonStruct__bindgen_ty_1 { } #[test] fn bindgen_test_layout_WithAnonStruct__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, + ::std::mem::size_of:: < WithAnonStruct__bindgen_ty_1 > (), 4usize, concat!("Size of: ", stringify!(WithAnonStruct__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < WithAnonStruct__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", stringify!(WithAnonStruct__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithAnonStruct__bindgen_ty_1), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(WithAnonStruct__bindgen_ty_1), "::", + stringify!(a)) ); } #[repr(C)] @@ -442,41 +406,31 @@ pub struct WithAnonStruct__bindgen_ty_2 { } #[test] fn bindgen_test_layout_WithAnonStruct__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, + ::std::mem::size_of:: < WithAnonStruct__bindgen_ty_2 > (), 4usize, concat!("Size of: ", stringify!(WithAnonStruct__bindgen_ty_2)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < WithAnonStruct__bindgen_ty_2 > (), 4usize, concat!("Alignment of ", stringify!(WithAnonStruct__bindgen_ty_2)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithAnonStruct__bindgen_ty_2), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(WithAnonStruct__bindgen_ty_2), "::", + stringify!(b)) ); } #[test] fn bindgen_test_layout_WithAnonStruct() { assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(WithAnonStruct)) + ::std::mem::size_of:: < WithAnonStruct > (), 8usize, concat!("Size of: ", + stringify!(WithAnonStruct)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithAnonStruct)) + ::std::mem::align_of:: < WithAnonStruct > (), 4usize, concat!("Alignment of ", + stringify!(WithAnonStruct)) ); } #[repr(C)] @@ -492,13 +446,11 @@ pub union WithAnonUnion__bindgen_ty_1 { #[test] fn bindgen_test_layout_WithAnonUnion__bindgen_ty_1() { assert_eq!( - ::std::mem::size_of::(), - 1usize, + ::std::mem::size_of:: < WithAnonUnion__bindgen_ty_1 > (), 1usize, concat!("Size of: ", stringify!(WithAnonUnion__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < WithAnonUnion__bindgen_ty_1 > (), 1usize, concat!("Alignment of ", stringify!(WithAnonUnion__bindgen_ty_1)) ); } @@ -514,14 +466,12 @@ impl Default for WithAnonUnion__bindgen_ty_1 { #[test] fn bindgen_test_layout_WithAnonUnion() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(WithAnonUnion)) + ::std::mem::size_of:: < WithAnonUnion > (), 1usize, concat!("Size of: ", + stringify!(WithAnonUnion)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(WithAnonUnion)) + ::std::mem::align_of:: < WithAnonUnion > (), 1usize, concat!("Alignment of ", + stringify!(WithAnonUnion)) ); } impl Default for WithAnonUnion { diff --git a/bindgen-tests/tests/expectations/tests/public-dtor.rs b/bindgen-tests/tests/expectations/tests/public-dtor.rs index 979dd4b564..d125dc547a 100644 --- a/bindgen-tests/tests/expectations/tests/public-dtor.rs +++ b/bindgen-tests/tests/expectations/tests/public-dtor.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default)] pub struct cv_Foo { @@ -13,14 +7,12 @@ pub struct cv_Foo { #[test] fn bindgen_test_layout_cv_Foo() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(cv_Foo)) + ::std::mem::size_of:: < cv_Foo > (), 1usize, concat!("Size of: ", + stringify!(cv_Foo)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(cv_Foo)) + ::std::mem::align_of:: < cv_Foo > (), 1usize, concat!("Alignment of ", + stringify!(cv_Foo)) ); } extern "C" { @@ -41,13 +33,11 @@ pub struct cv_Bar { #[test] fn bindgen_test_layout_cv_Bar() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(cv_Bar)) + ::std::mem::size_of:: < cv_Bar > (), 1usize, concat!("Size of: ", + stringify!(cv_Bar)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(cv_Bar)) + ::std::mem::align_of:: < cv_Bar > (), 1usize, concat!("Alignment of ", + stringify!(cv_Bar)) ); } diff --git a/bindgen-tests/tests/expectations/tests/qualified-dependent-types.rs b/bindgen-tests/tests/expectations/tests/qualified-dependent-types.rs index f1b2c8459c..9bbbddd88d 100644 --- a/bindgen-tests/tests/expectations/tests/qualified-dependent-types.rs +++ b/bindgen-tests/tests/expectations/tests/qualified-dependent-types.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { diff --git a/bindgen-tests/tests/expectations/tests/redeclaration.rs b/bindgen-tests/tests/expectations/tests/redeclaration.rs index 8a4ff6578e..05b7aecd3e 100644 --- a/bindgen-tests/tests/expectations/tests/redeclaration.rs +++ b/bindgen-tests/tests/expectations/tests/redeclaration.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub fn foo(); } diff --git a/bindgen-tests/tests/expectations/tests/ref_argument_array.rs b/bindgen-tests/tests/expectations/tests/ref_argument_array.rs index 00a8e0ee35..518833f75e 100644 --- a/bindgen-tests/tests/expectations/tests/ref_argument_array.rs +++ b/bindgen-tests/tests/expectations/tests/ref_argument_array.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const NSID_LENGTH: u32 = 10; #[repr(C)] pub struct nsID__bindgen_vtable { @@ -21,14 +15,11 @@ pub struct nsID { #[test] fn bindgen_test_layout_nsID() { assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(nsID)) + ::std::mem::size_of:: < nsID > (), 8usize, concat!("Size of: ", stringify!(nsID)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(nsID)) + ::std::mem::align_of:: < nsID > (), 8usize, concat!("Alignment of ", + stringify!(nsID)) ); } impl Default for nsID { diff --git a/bindgen-tests/tests/expectations/tests/reparented_replacement.rs b/bindgen-tests/tests/expectations/tests/reparented_replacement.rs index d9d13c1a9d..4cab0e996b 100644 --- a/bindgen-tests/tests/expectations/tests/reparented_replacement.rs +++ b/bindgen-tests/tests/expectations/tests/reparented_replacement.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![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 { #[allow(unused_imports)] @@ -20,30 +14,20 @@ pub mod root { } #[test] fn bindgen_test_layout_Bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Bar)) + ::std::mem::size_of:: < Bar > (), 4usize, concat!("Size of: ", + stringify!(Bar)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Bar)) + ::std::mem::align_of:: < Bar > (), 4usize, concat!("Alignment of ", + stringify!(Bar)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).bazz) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(bazz) - ) + unsafe { ::std::ptr::addr_of!((* ptr).bazz) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(Bar), "::", + stringify!(bazz)) ); } } diff --git a/bindgen-tests/tests/expectations/tests/replace_template_alias.rs b/bindgen-tests/tests/expectations/tests/replace_template_alias.rs index 4f464129fe..6d656b2be6 100644 --- a/bindgen-tests/tests/expectations/tests/replace_template_alias.rs +++ b/bindgen-tests/tests/expectations/tests/replace_template_alias.rs @@ -1,13 +1,7 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +/** But the replacement type does use T! -/// But the replacement type does use T! -/// -///
+
*/ pub type JS_detail_MaybeWrapped = T; #[repr(C)] #[derive(Debug, Copy, Clone)] diff --git a/bindgen-tests/tests/expectations/tests/replace_use.rs b/bindgen-tests/tests/expectations/tests/replace_use.rs index d4228e126e..4a50938409 100644 --- a/bindgen-tests/tests/expectations/tests/replace_use.rs +++ b/bindgen-tests/tests/expectations/tests/replace_use.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] ///
#[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -18,38 +12,28 @@ pub struct Test { } #[test] fn bindgen_test_layout_Test() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Test)) + ::std::mem::size_of:: < Test > (), 4usize, concat!("Size of: ", stringify!(Test)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Test)) + ::std::mem::align_of:: < Test > (), 4usize, concat!("Alignment of ", + stringify!(Test)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Test), "::", stringify!(a)) ); } #[test] fn __bindgen_test_layout_nsTArray_open0_long_close0_instantiation() { assert_eq!( - ::std::mem::size_of::(), - 4usize, + ::std::mem::size_of:: < nsTArray > (), 4usize, concat!("Size of template specialization: ", stringify!(nsTArray)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(nsTArray) - ) + ::std::mem::align_of:: < nsTArray > (), 4usize, + concat!("Alignment of template specialization: ", stringify!(nsTArray)) ); } diff --git a/bindgen-tests/tests/expectations/tests/replaces_double.rs b/bindgen-tests/tests/expectations/tests/replaces_double.rs index 99de132090..30966355fe 100644 --- a/bindgen-tests/tests/expectations/tests/replaces_double.rs +++ b/bindgen-tests/tests/expectations/tests/replaces_double.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Wrapper_Wrapped { diff --git a/bindgen-tests/tests/expectations/tests/repr-align.rs b/bindgen-tests/tests/expectations/tests/repr-align.rs index c6fee20dbc..5da572f329 100644 --- a/bindgen-tests/tests/expectations/tests/repr-align.rs +++ b/bindgen-tests/tests/expectations/tests/repr-align.rs @@ -1,11 +1,5 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(feature = "nightly")] - #[repr(C)] #[repr(align(8))] #[derive(Debug, Default, Copy, Clone)] @@ -15,27 +9,20 @@ pub struct a { } #[test] fn bindgen_test_layout_a() { - const UNINIT: ::std::mem::MaybeUninit
= - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(a)) + ::std::mem::size_of:: < a > (), 8usize, concat!("Size of: ", stringify!(a)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(a)) + ::std::mem::align_of:: < a > (), 8usize, concat!("Alignment of ", stringify!(a)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(a), "::", stringify!(b)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, - 4usize, + unsafe { ::std::ptr::addr_of!((* ptr).c) as usize - ptr as usize }, 4usize, concat!("Offset of field: ", stringify!(a), "::", stringify!(c)) ); } @@ -48,27 +35,20 @@ pub struct b { } #[test] fn bindgen_test_layout_b() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(b)) + ::std::mem::size_of:: < b > (), 8usize, concat!("Size of: ", stringify!(b)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(b)) + ::std::mem::align_of:: < b > (), 8usize, concat!("Alignment of ", stringify!(b)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(b), "::", stringify!(b)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, - 4usize, + unsafe { ::std::ptr::addr_of!((* ptr).c) as usize - ptr as usize }, 4usize, concat!("Offset of field: ", stringify!(b), "::", stringify!(c)) ); } diff --git a/bindgen-tests/tests/expectations/tests/resolved_type_def_function.rs b/bindgen-tests/tests/expectations/tests/resolved_type_def_function.rs index 797976798f..8fe7eb7da2 100644 --- a/bindgen-tests/tests/expectations/tests/resolved_type_def_function.rs +++ b/bindgen-tests/tests/expectations/tests/resolved_type_def_function.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type FuncType = ::std::option::Option; extern "C" { pub fn Func(); diff --git a/bindgen-tests/tests/expectations/tests/same_struct_name_in_different_namespaces.rs b/bindgen-tests/tests/expectations/tests/same_struct_name_in_different_namespaces.rs index 8002476197..3f456b0a74 100644 --- a/bindgen-tests/tests/expectations/tests/same_struct_name_in_different_namespaces.rs +++ b/bindgen-tests/tests/expectations/tests/same_struct_name_in_different_namespaces.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct JS_Zone { @@ -18,37 +12,22 @@ pub struct JS_shadow_Zone { } #[test] fn bindgen_test_layout_JS_shadow_Zone() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(JS_shadow_Zone)) + ::std::mem::size_of:: < JS_shadow_Zone > (), 8usize, concat!("Size of: ", + stringify!(JS_shadow_Zone)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(JS_shadow_Zone)) + ::std::mem::align_of:: < JS_shadow_Zone > (), 4usize, concat!("Alignment of ", + stringify!(JS_shadow_Zone)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(JS_shadow_Zone), - "::", - stringify!(x) - ) + unsafe { ::std::ptr::addr_of!((* ptr).x) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(JS_shadow_Zone), "::", stringify!(x)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(JS_shadow_Zone), - "::", - stringify!(y) - ) + unsafe { ::std::ptr::addr_of!((* ptr).y) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(JS_shadow_Zone), "::", stringify!(y)) ); } diff --git a/bindgen-tests/tests/expectations/tests/sentry-defined-multiple-times.rs b/bindgen-tests/tests/expectations/tests/sentry-defined-multiple-times.rs index 48f8ca8133..7d287a9e90 100644 --- a/bindgen-tests/tests/expectations/tests/sentry-defined-multiple-times.rs +++ b/bindgen-tests/tests/expectations/tests/sentry-defined-multiple-times.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![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 { #[allow(unused_imports)] @@ -29,31 +23,20 @@ pub mod root { } #[test] fn bindgen_test_layout_sentry() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(sentry)) + ::std::mem::size_of:: < sentry > (), 1usize, concat!("Size of: ", + stringify!(sentry)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(sentry)) + ::std::mem::align_of:: < sentry > (), 1usize, concat!("Alignment of ", + stringify!(sentry)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).i_am_plain_sentry) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(sentry), - "::", - stringify!(i_am_plain_sentry) - ) + unsafe { ::std::ptr::addr_of!((* ptr).i_am_plain_sentry) as usize - ptr + as usize }, 0usize, concat!("Offset of field: ", stringify!(sentry), + "::", stringify!(i_am_plain_sentry)) ); } #[repr(C)] @@ -64,13 +47,11 @@ pub mod root { #[test] fn bindgen_test_layout_NotTemplateWrapper() { assert_eq!( - ::std::mem::size_of::(), - 1usize, + ::std::mem::size_of:: < NotTemplateWrapper > (), 1usize, concat!("Size of: ", stringify!(NotTemplateWrapper)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < NotTemplateWrapper > (), 1usize, concat!("Alignment of ", stringify!(NotTemplateWrapper)) ); } @@ -81,33 +62,21 @@ pub mod root { } #[test] fn bindgen_test_layout_NotTemplateWrapper_sentry() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 1usize, + ::std::mem::size_of:: < NotTemplateWrapper_sentry > (), 1usize, concat!("Size of: ", stringify!(NotTemplateWrapper_sentry)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < NotTemplateWrapper_sentry > (), 1usize, concat!("Alignment of ", stringify!(NotTemplateWrapper_sentry)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!( - (*ptr).i_am_not_template_wrapper_sentry - ) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NotTemplateWrapper_sentry), - "::", - stringify!(i_am_not_template_wrapper_sentry) - ) + unsafe { ::std::ptr::addr_of!((* ptr).i_am_not_template_wrapper_sentry) + as usize - ptr as usize }, 0usize, concat!("Offset of field: ", + stringify!(NotTemplateWrapper_sentry), "::", + stringify!(i_am_not_template_wrapper_sentry)) ); } #[repr(C)] @@ -122,52 +91,32 @@ pub mod root { } #[test] fn bindgen_test_layout_InlineNotTemplateWrapper_sentry() { - const UNINIT: ::std::mem::MaybeUninit< - InlineNotTemplateWrapper_sentry, - > = ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!( - "Size of: ", - stringify!(InlineNotTemplateWrapper_sentry) - ) + ::std::mem::size_of:: < InlineNotTemplateWrapper_sentry > (), 1usize, + concat!("Size of: ", stringify!(InlineNotTemplateWrapper_sentry)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!( - "Alignment of ", - stringify!(InlineNotTemplateWrapper_sentry) - ) + ::std::mem::align_of:: < InlineNotTemplateWrapper_sentry > (), 1usize, + concat!("Alignment of ", stringify!(InlineNotTemplateWrapper_sentry)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!( - (*ptr).i_am_inline_not_template_wrapper_sentry - ) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(InlineNotTemplateWrapper_sentry), - "::", - stringify!(i_am_inline_not_template_wrapper_sentry) - ) + unsafe { ::std::ptr::addr_of!((* ptr) + .i_am_inline_not_template_wrapper_sentry) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", + stringify!(InlineNotTemplateWrapper_sentry), "::", + stringify!(i_am_inline_not_template_wrapper_sentry)) ); } #[test] fn bindgen_test_layout_InlineNotTemplateWrapper() { assert_eq!( - ::std::mem::size_of::(), - 1usize, + ::std::mem::size_of:: < InlineNotTemplateWrapper > (), 1usize, concat!("Size of: ", stringify!(InlineNotTemplateWrapper)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < InlineNotTemplateWrapper > (), 1usize, concat!("Alignment of ", stringify!(InlineNotTemplateWrapper)) ); } @@ -194,32 +143,24 @@ pub mod root { #[test] fn bindgen_test_layout_OuterDoubleWrapper_InnerDoubleWrapper() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!( - "Size of: ", - stringify!(OuterDoubleWrapper_InnerDoubleWrapper) - ) + ::std::mem::size_of:: < OuterDoubleWrapper_InnerDoubleWrapper > (), + 1usize, concat!("Size of: ", + stringify!(OuterDoubleWrapper_InnerDoubleWrapper)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!( - "Alignment of ", - stringify!(OuterDoubleWrapper_InnerDoubleWrapper) - ) + ::std::mem::align_of:: < OuterDoubleWrapper_InnerDoubleWrapper > (), + 1usize, concat!("Alignment of ", + stringify!(OuterDoubleWrapper_InnerDoubleWrapper)) ); } #[test] fn bindgen_test_layout_OuterDoubleWrapper() { assert_eq!( - ::std::mem::size_of::(), - 1usize, + ::std::mem::size_of:: < OuterDoubleWrapper > (), 1usize, concat!("Size of: ", stringify!(OuterDoubleWrapper)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < OuterDoubleWrapper > (), 1usize, concat!("Alignment of ", stringify!(OuterDoubleWrapper)) ); } @@ -235,38 +176,20 @@ pub mod root { > = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::< - OuterDoubleWrapper_InnerDoubleWrapper_sentry, - >(), - 4usize, - concat!( - "Size of: ", - stringify!(OuterDoubleWrapper_InnerDoubleWrapper_sentry) - ) + ::std::mem::size_of:: < OuterDoubleWrapper_InnerDoubleWrapper_sentry > + (), 4usize, concat!("Size of: ", + stringify!(OuterDoubleWrapper_InnerDoubleWrapper_sentry)) ); assert_eq!( - ::std::mem::align_of::< - OuterDoubleWrapper_InnerDoubleWrapper_sentry, - >(), - 4usize, - concat!( - "Alignment of ", - stringify!(OuterDoubleWrapper_InnerDoubleWrapper_sentry) - ) + ::std::mem::align_of:: < OuterDoubleWrapper_InnerDoubleWrapper_sentry > + (), 4usize, concat!("Alignment of ", + stringify!(OuterDoubleWrapper_InnerDoubleWrapper_sentry)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).i_am_double_wrapper_sentry) - as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(OuterDoubleWrapper_InnerDoubleWrapper_sentry), - "::", - stringify!(i_am_double_wrapper_sentry) - ) + unsafe { ::std::ptr::addr_of!((* ptr).i_am_double_wrapper_sentry) as + usize - ptr as usize }, 0usize, concat!("Offset of field: ", + stringify!(OuterDoubleWrapper_InnerDoubleWrapper_sentry), "::", + stringify!(i_am_double_wrapper_sentry)) ); } #[repr(C)] @@ -285,54 +208,52 @@ pub mod root { pub i_am_double_wrapper_inline_sentry: ::std::os::raw::c_int, } #[test] - fn bindgen_test_layout_OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry( - ) { + fn bindgen_test_layout_OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry() { const UNINIT: ::std::mem::MaybeUninit< OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry, > = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq ! (:: std :: mem :: size_of :: < OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry > () , 4usize , concat ! ("Size of: " , stringify ! (OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry))); - assert_eq ! (:: std :: mem :: align_of :: < OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry > () , 4usize , concat ! ("Alignment of " , stringify ! (OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry))); - assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . i_am_double_wrapper_inline_sentry) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry) , "::" , stringify ! (i_am_double_wrapper_inline_sentry))); + assert_eq!( + ::std::mem::size_of:: < + OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry > (), 4usize, + concat!("Size of: ", + stringify!(OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry)) + ); + assert_eq!( + ::std::mem::align_of:: < + OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry > (), 4usize, + concat!("Alignment of ", + stringify!(OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).i_am_double_wrapper_inline_sentry) + as usize - ptr as usize }, 0usize, concat!("Offset of field: ", + stringify!(OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry), + "::", stringify!(i_am_double_wrapper_inline_sentry)) + ); } #[test] - fn bindgen_test_layout_OuterDoubleInlineWrapper_InnerDoubleInlineWrapper( - ) { + fn bindgen_test_layout_OuterDoubleInlineWrapper_InnerDoubleInlineWrapper() { assert_eq!( - ::std::mem::size_of::< - OuterDoubleInlineWrapper_InnerDoubleInlineWrapper, - >(), - 1usize, - concat!( - "Size of: ", - stringify!( - OuterDoubleInlineWrapper_InnerDoubleInlineWrapper - ) - ) + ::std::mem::size_of:: < OuterDoubleInlineWrapper_InnerDoubleInlineWrapper + > (), 1usize, concat!("Size of: ", + stringify!(OuterDoubleInlineWrapper_InnerDoubleInlineWrapper)) ); assert_eq!( - ::std::mem::align_of::< - OuterDoubleInlineWrapper_InnerDoubleInlineWrapper, - >(), - 1usize, - concat!( - "Alignment of ", - stringify!( - OuterDoubleInlineWrapper_InnerDoubleInlineWrapper - ) - ) + ::std::mem::align_of:: < + OuterDoubleInlineWrapper_InnerDoubleInlineWrapper > (), 1usize, + concat!("Alignment of ", + stringify!(OuterDoubleInlineWrapper_InnerDoubleInlineWrapper)) ); } #[test] fn bindgen_test_layout_OuterDoubleInlineWrapper() { assert_eq!( - ::std::mem::size_of::(), - 1usize, + ::std::mem::size_of:: < OuterDoubleInlineWrapper > (), 1usize, concat!("Size of: ", stringify!(OuterDoubleInlineWrapper)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < OuterDoubleInlineWrapper > (), 1usize, concat!("Alignment of ", stringify!(OuterDoubleInlineWrapper)) ); } @@ -354,32 +275,20 @@ pub mod root { } #[test] fn bindgen_test_layout_sentry() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(sentry)) + ::std::mem::size_of:: < sentry > (), 4usize, concat!("Size of: ", + stringify!(sentry)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(sentry)) + ::std::mem::align_of:: < sentry > (), 4usize, concat!("Alignment of ", + stringify!(sentry)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).i_am_outside_namespace_sentry) - as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(sentry), - "::", - stringify!(i_am_outside_namespace_sentry) - ) + unsafe { ::std::ptr::addr_of!((* ptr).i_am_outside_namespace_sentry) as usize + - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(sentry), + "::", stringify!(i_am_outside_namespace_sentry)) ); } } diff --git a/bindgen-tests/tests/expectations/tests/short-enums.rs b/bindgen-tests/tests/expectations/tests/short-enums.rs index a8a494eaa6..493bb5b419 100644 --- a/bindgen-tests/tests/expectations/tests/short-enums.rs +++ b/bindgen-tests/tests/expectations/tests/short-enums.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(u8)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum one_byte_t { diff --git a/bindgen-tests/tests/expectations/tests/size_t_template.rs b/bindgen-tests/tests/expectations/tests/size_t_template.rs index 1aa8b9acae..1ccc74c7ed 100644 --- a/bindgen-tests/tests/expectations/tests/size_t_template.rs +++ b/bindgen-tests/tests/expectations/tests/size_t_template.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct C { @@ -12,22 +6,16 @@ pub struct C { } #[test] fn bindgen_test_layout_C() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 12usize, - concat!("Size of: ", stringify!(C)) + ::std::mem::size_of:: < C > (), 12usize, concat!("Size of: ", stringify!(C)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C)) + ::std::mem::align_of:: < C > (), 4usize, concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).arr) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(arr)) ); } diff --git a/bindgen-tests/tests/expectations/tests/sorted_items.rs b/bindgen-tests/tests/expectations/tests/sorted_items.rs index e04e3b6090..9d4c451dab 100644 --- a/bindgen-tests/tests/expectations/tests/sorted_items.rs +++ b/bindgen-tests/tests/expectations/tests/sorted_items.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![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 { pub type number = ::std::os::raw::c_int; @@ -23,74 +17,44 @@ pub mod root { pub const NUMBER: root::number = 42; #[test] fn bindgen_test_layout_Point() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Point)) + ::std::mem::size_of:: < Point > (), 8usize, concat!("Size of: ", + stringify!(Point)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Point)) + ::std::mem::align_of:: < Point > (), 4usize, concat!("Alignment of ", + stringify!(Point)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Point), - "::", - stringify!(x) - ) + unsafe { ::std::ptr::addr_of!((* ptr).x) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(Point), "::", stringify!(x)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(Point), - "::", - stringify!(y) - ) + unsafe { ::std::ptr::addr_of!((* ptr).y) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(Point), "::", stringify!(y)) ); } #[test] fn bindgen_test_layout_Angle() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Angle)) + ::std::mem::size_of:: < Angle > (), 8usize, concat!("Size of: ", + stringify!(Angle)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Angle)) + ::std::mem::align_of:: < Angle > (), 4usize, concat!("Alignment of ", + stringify!(Angle)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Angle), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(Angle), "::", stringify!(a)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(Angle), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(Angle), "::", stringify!(b)) ); } pub mod ns { @@ -110,82 +74,48 @@ pub mod root { pub const NUMBER: root::ns::number = 42; #[test] fn bindgen_test_layout_Point() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Point)) + ::std::mem::size_of:: < Point > (), 8usize, concat!("Size of: ", + stringify!(Point)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Point)) + ::std::mem::align_of:: < Point > (), 4usize, concat!("Alignment of ", + stringify!(Point)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Point), - "::", - stringify!(x) - ) + unsafe { ::std::ptr::addr_of!((* ptr).x) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(Point), "::", + stringify!(x)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(Point), - "::", - stringify!(y) - ) + unsafe { ::std::ptr::addr_of!((* ptr).y) as usize - ptr as usize }, + 4usize, concat!("Offset of field: ", stringify!(Point), "::", + stringify!(y)) ); } #[test] fn bindgen_test_layout_Angle() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Angle)) + ::std::mem::size_of:: < Angle > (), 8usize, concat!("Size of: ", + stringify!(Angle)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Angle)) + ::std::mem::align_of:: < Angle > (), 4usize, concat!("Alignment of ", + stringify!(Angle)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Angle), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(Angle), "::", + stringify!(a)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(Angle), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, + 4usize, concat!("Offset of field: ", stringify!(Angle), "::", + stringify!(b)) ); } #[allow(unused_imports)] diff --git a/bindgen-tests/tests/expectations/tests/stdint_typedef.rs b/bindgen-tests/tests/expectations/tests/stdint_typedef.rs index a52db49691..31d3b5c5e7 100644 --- a/bindgen-tests/tests/expectations/tests/stdint_typedef.rs +++ b/bindgen-tests/tests/expectations/tests/stdint_typedef.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub fn fun() -> u64; } @@ -15,27 +9,18 @@ pub struct Struct { } #[test] fn bindgen_test_layout_Struct() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Struct)) + ::std::mem::size_of:: < Struct > (), 8usize, concat!("Size of: ", + stringify!(Struct)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Struct)) + ::std::mem::align_of:: < Struct > (), 8usize, concat!("Alignment of ", + stringify!(Struct)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).field) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Struct), - "::", - stringify!(field) - ) + unsafe { ::std::ptr::addr_of!((* ptr).field) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(Struct), "::", stringify!(field)) ); } diff --git a/bindgen-tests/tests/expectations/tests/strings_array.rs b/bindgen-tests/tests/expectations/tests/strings_array.rs index 76e8debd78..6f352b32ca 100644 --- a/bindgen-tests/tests/expectations/tests/strings_array.rs +++ b/bindgen-tests/tests/expectations/tests/strings_array.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const MY_STRING_UTF8: &'static [u8; 14] = b"Hello, world!\0"; pub const MY_STRING_INTERIOR_NULL: &'static [u8; 7] = b"Hello,\0"; pub const MY_STRING_NON_UTF8: &'static [u8; 7] = b"ABCDE\xFF\0"; diff --git a/bindgen-tests/tests/expectations/tests/strings_cstr.rs b/bindgen-tests/tests/expectations/tests/strings_cstr.rs index e7f275f32c..ca089cf130 100644 --- a/bindgen-tests/tests/expectations/tests/strings_cstr.rs +++ b/bindgen-tests/tests/expectations/tests/strings_cstr.rs @@ -1,17 +1,13 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[allow(unsafe_code)] pub const MY_STRING_UTF8: &::std::ffi::CStr = unsafe { ::std::ffi::CStr::from_bytes_with_nul_unchecked(b"Hello, world!\0") }; #[allow(unsafe_code)] -pub const MY_STRING_INTERIOR_NULL: &::std::ffi::CStr = - unsafe { ::std::ffi::CStr::from_bytes_with_nul_unchecked(b"Hello,\0") }; +pub const MY_STRING_INTERIOR_NULL: &::std::ffi::CStr = unsafe { + ::std::ffi::CStr::from_bytes_with_nul_unchecked(b"Hello,\0") +}; #[allow(unsafe_code)] -pub const MY_STRING_NON_UTF8: &::std::ffi::CStr = - unsafe { ::std::ffi::CStr::from_bytes_with_nul_unchecked(b"ABCDE\xFF\0") }; +pub const MY_STRING_NON_UTF8: &::std::ffi::CStr = unsafe { + ::std::ffi::CStr::from_bytes_with_nul_unchecked(b"ABCDE\xFF\0") +}; diff --git a/bindgen-tests/tests/expectations/tests/struct_containing_forward_declared_struct.rs b/bindgen-tests/tests/expectations/tests/struct_containing_forward_declared_struct.rs index 8279fe1f7d..e0ab49cdda 100644 --- a/bindgen-tests/tests/expectations/tests/struct_containing_forward_declared_struct.rs +++ b/bindgen-tests/tests/expectations/tests/struct_containing_forward_declared_struct.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct a { @@ -12,22 +6,16 @@ pub struct a { } #[test] fn bindgen_test_layout_a() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(a)) + ::std::mem::size_of:: < a > (), 8usize, concat!("Size of: ", stringify!(a)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(a)) + ::std::mem::align_of:: < a > (), 8usize, concat!("Alignment of ", stringify!(a)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).val_a) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).val_a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(a), "::", stringify!(val_a)) ); } @@ -47,22 +35,16 @@ pub struct b { } #[test] fn bindgen_test_layout_b() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(b)) + ::std::mem::size_of:: < b > (), 4usize, concat!("Size of: ", stringify!(b)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(b)) + ::std::mem::align_of:: < b > (), 4usize, concat!("Alignment of ", stringify!(b)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).val_b) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).val_b) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(b), "::", stringify!(val_b)) ); } diff --git a/bindgen-tests/tests/expectations/tests/struct_typedef.rs b/bindgen-tests/tests/expectations/tests/struct_typedef.rs index f9d7fedb25..4d39123e43 100644 --- a/bindgen-tests/tests/expectations/tests/struct_typedef.rs +++ b/bindgen-tests/tests/expectations/tests/struct_typedef.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct typedef_named_struct { @@ -12,30 +6,20 @@ pub struct typedef_named_struct { } #[test] fn bindgen_test_layout_typedef_named_struct() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(typedef_named_struct)) + ::std::mem::size_of:: < typedef_named_struct > (), 1usize, concat!("Size of: ", + stringify!(typedef_named_struct)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < typedef_named_struct > (), 1usize, concat!("Alignment of ", stringify!(typedef_named_struct)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).has_name) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(typedef_named_struct), - "::", - stringify!(has_name) - ) + unsafe { ::std::ptr::addr_of!((* ptr).has_name) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(typedef_named_struct), "::", + stringify!(has_name)) ); } #[repr(C)] @@ -45,28 +29,20 @@ pub struct _bindgen_ty_1 { } #[test] fn bindgen_test_layout__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit<_bindgen_ty_1> = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit<_bindgen_ty_1> = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::<_bindgen_ty_1>(), - 8usize, - concat!("Size of: ", stringify!(_bindgen_ty_1)) + ::std::mem::size_of:: < _bindgen_ty_1 > (), 8usize, concat!("Size of: ", + stringify!(_bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::<_bindgen_ty_1>(), - 8usize, - concat!("Alignment of ", stringify!(_bindgen_ty_1)) + ::std::mem::align_of:: < _bindgen_ty_1 > (), 8usize, concat!("Alignment of ", + stringify!(_bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).no_name) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_bindgen_ty_1), - "::", - stringify!(no_name) - ) + unsafe { ::std::ptr::addr_of!((* ptr).no_name) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(_bindgen_ty_1), "::", + stringify!(no_name)) ); } impl Default for _bindgen_ty_1 { diff --git a/bindgen-tests/tests/expectations/tests/struct_typedef_ns.rs b/bindgen-tests/tests/expectations/tests/struct_typedef_ns.rs index 2bad358aee..bf35121d99 100644 --- a/bindgen-tests/tests/expectations/tests/struct_typedef_ns.rs +++ b/bindgen-tests/tests/expectations/tests/struct_typedef_ns.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![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 { #[allow(unused_imports)] @@ -19,30 +13,20 @@ pub mod root { } #[test] fn bindgen_test_layout_typedef_struct() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(typedef_struct)) + ::std::mem::size_of:: < typedef_struct > (), 4usize, concat!("Size of: ", + stringify!(typedef_struct)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < typedef_struct > (), 4usize, concat!("Alignment of ", stringify!(typedef_struct)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(typedef_struct), - "::", - stringify!(foo) - ) + unsafe { ::std::ptr::addr_of!((* ptr).foo) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(typedef_struct), "::", + stringify!(foo)) ); } #[repr(u32)] @@ -61,35 +45,24 @@ pub mod root { } #[test] fn bindgen_test_layout__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit<_bindgen_ty_1> = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit<_bindgen_ty_1> = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::<_bindgen_ty_1>(), - 4usize, - concat!("Size of: ", stringify!(_bindgen_ty_1)) + ::std::mem::size_of:: < _bindgen_ty_1 > (), 4usize, concat!("Size of: ", + stringify!(_bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::<_bindgen_ty_1>(), - 4usize, + ::std::mem::align_of:: < _bindgen_ty_1 > (), 4usize, concat!("Alignment of ", stringify!(_bindgen_ty_1)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_bindgen_ty_1), - "::", - stringify!(foo) - ) + unsafe { ::std::ptr::addr_of!((* ptr).foo) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(_bindgen_ty_1), "::", + stringify!(foo)) ); } pub type typedef_struct = root::_bindgen_mod_id_12::_bindgen_ty_1; - pub const _bindgen_mod_id_12_BAR: - root::_bindgen_mod_id_12::_bindgen_ty_2 = _bindgen_ty_2::BAR; + pub const _bindgen_mod_id_12_BAR: root::_bindgen_mod_id_12::_bindgen_ty_2 = _bindgen_ty_2::BAR; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum _bindgen_ty_2 { diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_struct.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_struct.rs index 238400a17c..856fc60b25 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_struct.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_anon_struct.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct foo { @@ -18,58 +12,38 @@ pub struct foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)) + ::std::mem::size_of:: < foo__bindgen_ty_1 > (), 8usize, concat!("Size of: ", + stringify!(foo__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) + ::std::mem::align_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", + stringify!(foo__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)) ); } #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of:: < foo > (), 8usize, concat!("Size of: ", stringify!(foo)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) + ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", + stringify!(foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); } diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_struct_array.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_struct_array.rs index f3af6b60ff..3423aba181 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_struct_array.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_anon_struct_array.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct foo { @@ -19,38 +13,23 @@ pub struct foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)) + ::std::mem::size_of:: < foo__bindgen_ty_1 > (), 8usize, concat!("Size of: ", + stringify!(foo__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) + ::std::mem::align_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", + stringify!(foo__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)) ); } #[repr(C)] @@ -61,63 +40,42 @@ pub struct foo__bindgen_ty_2 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_2)) + ::std::mem::size_of:: < foo__bindgen_ty_2 > (), 8usize, concat!("Size of: ", + stringify!(foo__bindgen_ty_2)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_2)) + ::std::mem::align_of:: < foo__bindgen_ty_2 > (), 4usize, concat!("Alignment of ", + stringify!(foo__bindgen_ty_2)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_2), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_2), "::", stringify!(a)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_2), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_2), "::", stringify!(b)) ); } #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 208usize, - concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of:: < foo > (), 208usize, concat!("Size of: ", stringify!(foo)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) + ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", + stringify!(foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 16usize, + unsafe { ::std::ptr::addr_of!((* ptr).baz) as usize - ptr as usize }, 16usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(baz)) ); } diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_struct_pointer.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_struct_pointer.rs index 5bb10079a3..aeb5c10984 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_struct_pointer.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_anon_struct_pointer.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct foo { @@ -18,58 +12,38 @@ pub struct foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)) + ::std::mem::size_of:: < foo__bindgen_ty_1 > (), 8usize, concat!("Size of: ", + stringify!(foo__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) + ::std::mem::align_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", + stringify!(foo__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)) ); } #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of:: < foo > (), 8usize, concat!("Size of: ", stringify!(foo)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(foo)) + ::std::mem::align_of:: < foo > (), 8usize, concat!("Alignment of ", + stringify!(foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); } diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_union.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_union.rs index 08aab0a94c..322bcdd288 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_union.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_anon_union.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone)] pub struct foo { @@ -18,38 +12,23 @@ pub union foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)) + ::std::mem::size_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Size of: ", + stringify!(foo__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) + ::std::mem::align_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", + stringify!(foo__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)) ); } impl Default for foo__bindgen_ty_1 { @@ -63,22 +42,17 @@ impl Default for foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of:: < foo > (), 4usize, concat!("Size of: ", stringify!(foo)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) + ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", + stringify!(foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); } diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_union_1_0.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_union_1_0.rs index 8db33d113e..74d4139515 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_anon_union_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -62,38 +56,23 @@ pub struct foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)) + ::std::mem::size_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Size of: ", + stringify!(foo__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) + ::std::mem::align_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", + stringify!(foo__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)) ); } impl Clone for foo__bindgen_ty_1 { @@ -103,22 +82,17 @@ impl Clone for foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of:: < foo > (), 4usize, concat!("Size of: ", stringify!(foo)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) + ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", + stringify!(foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); } diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_struct.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_struct.rs index 5698106528..606f28e031 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_struct.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_struct.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct foo { @@ -18,50 +12,32 @@ pub struct foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)) + ::std::mem::size_of:: < foo__bindgen_ty_1 > (), 8usize, concat!("Size of: ", + stringify!(foo__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) + ::std::mem::align_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", + stringify!(foo__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)) ); } #[test] fn bindgen_test_layout_foo() { assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of:: < foo > (), 8usize, concat!("Size of: ", stringify!(foo)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) + ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", + stringify!(foo)) ); } diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union.rs index 499fc7a174..309622ab4b 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone)] pub struct foo { @@ -18,38 +12,23 @@ pub union foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)) + ::std::mem::size_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Size of: ", + stringify!(foo__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) + ::std::mem::align_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", + stringify!(foo__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)) ); } impl Default for foo__bindgen_ty_1 { @@ -64,14 +43,11 @@ impl Default for foo__bindgen_ty_1 { #[test] fn bindgen_test_layout_foo() { assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of:: < foo > (), 4usize, concat!("Size of: ", stringify!(foo)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) + ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", + stringify!(foo)) ); } impl Default for foo { diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs index 55432d47fc..b7e5b2c98e 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -62,38 +56,23 @@ pub struct foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)) + ::std::mem::size_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Size of: ", + stringify!(foo__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) + ::std::mem::align_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", + stringify!(foo__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)) ); } impl Clone for foo__bindgen_ty_1 { @@ -104,14 +83,11 @@ impl Clone for foo__bindgen_ty_1 { #[test] fn bindgen_test_layout_foo() { assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of:: < foo > (), 4usize, concat!("Size of: ", stringify!(foo)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) + ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", + stringify!(foo)) ); } impl Clone for foo { diff --git a/bindgen-tests/tests/expectations/tests/struct_with_bitfields.rs b/bindgen-tests/tests/expectations/tests/struct_with_bitfields.rs index a9be30069e..113d4b5441 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_bitfields.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_bitfields.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -102,36 +94,25 @@ pub struct bitfield { } #[test] fn bindgen_test_layout_bitfield() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(bitfield)) + ::std::mem::size_of:: < bitfield > (), 16usize, concat!("Size of: ", + stringify!(bitfield)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(bitfield)) + ::std::mem::align_of:: < bitfield > (), 4usize, concat!("Alignment of ", + stringify!(bitfield)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).e) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(bitfield), - "::", - stringify!(e) - ) + unsafe { ::std::ptr::addr_of!((* ptr).e) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(bitfield), "::", stringify!(e)) ); } impl bitfield { #[inline] pub fn a(&self) -> ::std::os::raw::c_ushort { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u16) } } #[inline] pub fn set_a(&mut self, val: ::std::os::raw::c_ushort) { @@ -142,9 +123,7 @@ impl bitfield { } #[inline] pub fn b(&self) -> ::std::os::raw::c_ushort { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u16) } } #[inline] pub fn set_b(&mut self, val: ::std::os::raw::c_ushort) { @@ -155,9 +134,7 @@ impl bitfield { } #[inline] pub fn c(&self) -> ::std::os::raw::c_ushort { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u16) } } #[inline] pub fn set_c(&mut self, val: ::std::os::raw::c_ushort) { @@ -168,9 +145,7 @@ impl bitfield { } #[inline] pub fn d(&self) -> ::std::os::raw::c_ushort { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(6usize, 2u8) as u16) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(6usize, 2u8) as u16) } } #[inline] pub fn set_d(&mut self, val: ::std::os::raw::c_ushort) { @@ -186,31 +161,48 @@ impl bitfield { c: ::std::os::raw::c_ushort, d: ::std::os::raw::c_ushort, ) -> __BindgenBitfieldUnit<[u8; 1usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 1u8, { - let a: u16 = unsafe { ::std::mem::transmute(a) }; - a as u64 - }); - __bindgen_bitfield_unit.set(1usize, 1u8, { - let b: u16 = unsafe { ::std::mem::transmute(b) }; - b as u64 - }); - __bindgen_bitfield_unit.set(2usize, 1u8, { - let c: u16 = unsafe { ::std::mem::transmute(c) }; - c as u64 - }); - __bindgen_bitfield_unit.set(6usize, 2u8, { - let d: u16 = unsafe { ::std::mem::transmute(d) }; - d as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let a: u16 = unsafe { ::std::mem::transmute(a) }; + a as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 1usize, + 1u8, + { + let b: u16 = unsafe { ::std::mem::transmute(b) }; + b as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 2usize, + 1u8, + { + let c: u16 = unsafe { ::std::mem::transmute(c) }; + c as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 6usize, + 2u8, + { + let d: u16 = unsafe { ::std::mem::transmute(d) }; + d as u64 + }, + ); __bindgen_bitfield_unit } #[inline] pub fn f(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_2.get(0usize, 2u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_2.get(0usize, 2u8) as u32) } } #[inline] pub fn set_f(&mut self, val: ::std::os::raw::c_uint) { @@ -221,9 +213,7 @@ impl bitfield { } #[inline] pub fn g(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_2.get(32usize, 32u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_2.get(32usize, 32u8) as u32) } } #[inline] pub fn set_g(&mut self, val: ::std::os::raw::c_uint) { @@ -237,16 +227,25 @@ impl bitfield { f: ::std::os::raw::c_uint, g: ::std::os::raw::c_uint, ) -> __BindgenBitfieldUnit<[u8; 8usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 8usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 2u8, { - let f: u32 = unsafe { ::std::mem::transmute(f) }; - f as u64 - }); - __bindgen_bitfield_unit.set(32usize, 32u8, { - let g: u32 = unsafe { ::std::mem::transmute(g) }; - g as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 8usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 2u8, + { + let f: u32 = unsafe { ::std::mem::transmute(f) }; + f as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 32usize, + 32u8, + { + let g: u32 = unsafe { ::std::mem::transmute(g) }; + g as u64 + }, + ); __bindgen_bitfield_unit } } 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 1bb7c77d26..90992689b5 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_derive_debug.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_derive_debug.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct LittleArray { @@ -12,28 +6,19 @@ pub struct LittleArray { } #[test] fn bindgen_test_layout_LittleArray() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 128usize, - concat!("Size of: ", stringify!(LittleArray)) + ::std::mem::size_of:: < LittleArray > (), 128usize, concat!("Size of: ", + stringify!(LittleArray)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(LittleArray)) + ::std::mem::align_of:: < LittleArray > (), 4usize, concat!("Alignment of ", + stringify!(LittleArray)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(LittleArray), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(LittleArray), "::", stringify!(a)) ); } #[repr(C)] @@ -43,28 +28,19 @@ pub struct BigArray { } #[test] fn bindgen_test_layout_BigArray() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 132usize, - concat!("Size of: ", stringify!(BigArray)) + ::std::mem::size_of:: < BigArray > (), 132usize, concat!("Size of: ", + stringify!(BigArray)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(BigArray)) + ::std::mem::align_of:: < BigArray > (), 4usize, concat!("Alignment of ", + stringify!(BigArray)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(BigArray), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(BigArray), "::", stringify!(a)) ); } impl Default for BigArray { @@ -83,28 +59,19 @@ pub struct WithLittleArray { } #[test] fn bindgen_test_layout_WithLittleArray() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 128usize, - concat!("Size of: ", stringify!(WithLittleArray)) + ::std::mem::size_of:: < WithLittleArray > (), 128usize, concat!("Size of: ", + stringify!(WithLittleArray)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithLittleArray)) + ::std::mem::align_of:: < WithLittleArray > (), 4usize, concat!("Alignment of ", + stringify!(WithLittleArray)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithLittleArray), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(WithLittleArray), "::", stringify!(a)) ); } #[repr(C)] @@ -114,28 +81,19 @@ pub struct WithBigArray { } #[test] fn bindgen_test_layout_WithBigArray() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 132usize, - concat!("Size of: ", stringify!(WithBigArray)) + ::std::mem::size_of:: < WithBigArray > (), 132usize, concat!("Size of: ", + stringify!(WithBigArray)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithBigArray)) + ::std::mem::align_of:: < WithBigArray > (), 4usize, concat!("Alignment of ", + stringify!(WithBigArray)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigArray), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(WithBigArray), "::", stringify!(a)) ); } impl Default for WithBigArray { 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 9f2c0ecc28..4cdf5bb055 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_large_array.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_large_array.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone)] pub struct S { @@ -12,30 +6,18 @@ pub struct S { } #[test] fn bindgen_test_layout_S() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 33usize, - concat!("Size of: ", stringify!(S)) + ::std::mem::size_of:: < S > (), 33usize, concat!("Size of: ", stringify!(S)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(S)) + ::std::mem::align_of:: < S > (), 1usize, concat!("Alignment of ", stringify!(S)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(S), - "::", - stringify!(large_array) - ) + unsafe { ::std::ptr::addr_of!((* ptr).large_array) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(S), "::", + stringify!(large_array)) ); } impl Default for S { diff --git a/bindgen-tests/tests/expectations/tests/struct_with_nesting.rs b/bindgen-tests/tests/expectations/tests/struct_with_nesting.rs index ff177ff131..1e92d7ecf1 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_nesting.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_nesting.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone)] pub struct foo { @@ -26,38 +20,25 @@ pub struct foo__bindgen_ty_1__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, + ::std::mem::size_of:: < foo__bindgen_ty_1__bindgen_ty_1 > (), 4usize, concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 2usize, + ::std::mem::align_of:: < foo__bindgen_ty_1__bindgen_ty_1 > (), 2usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c1) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(c1) - ) + unsafe { ::std::ptr::addr_of!((* ptr).c1) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1__bindgen_ty_1), "::", + stringify!(c1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c2) as usize - ptr as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(c2) - ) + unsafe { ::std::ptr::addr_of!((* ptr).c2) as usize - ptr as usize }, 2usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1__bindgen_ty_1), "::", + stringify!(c2)) ); } #[repr(C)] @@ -70,84 +51,52 @@ pub struct foo__bindgen_ty_1__bindgen_ty_2 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, + ::std::mem::size_of:: < foo__bindgen_ty_1__bindgen_ty_2 > (), 4usize, concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < foo__bindgen_ty_1__bindgen_ty_2 > (), 1usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d1) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(d1) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d2) as usize - ptr as usize }, - 1usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(d2) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d3) as usize - ptr as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(d3) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d4) as usize - ptr as usize }, - 3usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(d4) - ) + unsafe { ::std::ptr::addr_of!((* ptr).d1) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2), "::", + stringify!(d1)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).d2) as usize - ptr as usize }, 1usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2), "::", + stringify!(d2)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).d3) as usize - ptr as usize }, 2usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2), "::", + stringify!(d3)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).d4) as usize - ptr as usize }, 3usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2), "::", + stringify!(d4)) ); } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)) + ::std::mem::size_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Size of: ", + stringify!(foo__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) + ::std::mem::align_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", + stringify!(foo__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)) ); } impl Default for foo__bindgen_ty_1 { @@ -161,22 +110,17 @@ impl Default for foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of:: < foo > (), 8usize, concat!("Size of: ", stringify!(foo)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) + ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", + stringify!(foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) ); } diff --git a/bindgen-tests/tests/expectations/tests/struct_with_nesting_1_0.rs b/bindgen-tests/tests/expectations/tests/struct_with_nesting_1_0.rs index af795b6423..f6aacb7de1 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_nesting_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_nesting_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -70,38 +64,25 @@ pub struct foo__bindgen_ty_1__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, + ::std::mem::size_of:: < foo__bindgen_ty_1__bindgen_ty_1 > (), 4usize, concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 2usize, + ::std::mem::align_of:: < foo__bindgen_ty_1__bindgen_ty_1 > (), 2usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c1) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(c1) - ) + unsafe { ::std::ptr::addr_of!((* ptr).c1) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1__bindgen_ty_1), "::", + stringify!(c1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c2) as usize - ptr as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(c2) - ) + unsafe { ::std::ptr::addr_of!((* ptr).c2) as usize - ptr as usize }, 2usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1__bindgen_ty_1), "::", + stringify!(c2)) ); } impl Clone for foo__bindgen_ty_1__bindgen_ty_1 { @@ -119,58 +100,35 @@ pub struct foo__bindgen_ty_1__bindgen_ty_2 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, + ::std::mem::size_of:: < foo__bindgen_ty_1__bindgen_ty_2 > (), 4usize, concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < foo__bindgen_ty_1__bindgen_ty_2 > (), 1usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d1) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(d1) - ) + unsafe { ::std::ptr::addr_of!((* ptr).d1) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2), "::", + stringify!(d1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d2) as usize - ptr as usize }, - 1usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(d2) - ) + unsafe { ::std::ptr::addr_of!((* ptr).d2) as usize - ptr as usize }, 1usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2), "::", + stringify!(d2)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d3) as usize - ptr as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(d3) - ) + unsafe { ::std::ptr::addr_of!((* ptr).d3) as usize - ptr as usize }, 2usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2), "::", + stringify!(d3)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d4) as usize - ptr as usize }, - 3usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(d4) - ) + unsafe { ::std::ptr::addr_of!((* ptr).d4) as usize - ptr as usize }, 3usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2), "::", + stringify!(d4)) ); } impl Clone for foo__bindgen_ty_1__bindgen_ty_2 { @@ -180,28 +138,19 @@ impl Clone for foo__bindgen_ty_1__bindgen_ty_2 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)) + ::std::mem::size_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Size of: ", + stringify!(foo__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) + ::std::mem::align_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", + stringify!(foo__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)) ); } impl Clone for foo__bindgen_ty_1 { @@ -211,22 +160,17 @@ impl Clone for foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of:: < foo > (), 8usize, concat!("Size of: ", stringify!(foo)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) + ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", + stringify!(foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) ); } diff --git a/bindgen-tests/tests/expectations/tests/struct_with_packing.rs b/bindgen-tests/tests/expectations/tests/struct_with_packing.rs index b8ea17cd83..05cc10eb27 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_packing.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_packing.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C, packed)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct a { @@ -13,27 +7,20 @@ pub struct a { } #[test] fn bindgen_test_layout_a() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 3usize, - concat!("Size of: ", stringify!(a)) + ::std::mem::size_of:: < a > (), 3usize, concat!("Size of: ", stringify!(a)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(a)) + ::std::mem::align_of:: < a > (), 1usize, concat!("Alignment of ", stringify!(a)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(a), "::", stringify!(b)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, - 1usize, + unsafe { ::std::ptr::addr_of!((* ptr).c) as usize - ptr as usize }, 1usize, concat!("Offset of field: ", stringify!(a), "::", stringify!(c)) ); } diff --git a/bindgen-tests/tests/expectations/tests/struct_with_struct.rs b/bindgen-tests/tests/expectations/tests/struct_with_struct.rs index b1ee5db48b..1f56e71b83 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_struct.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_struct.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct foo { @@ -18,58 +12,38 @@ pub struct foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)) + ::std::mem::size_of:: < foo__bindgen_ty_1 > (), 8usize, concat!("Size of: ", + stringify!(foo__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) + ::std::mem::align_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", + stringify!(foo__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(x) - ) + unsafe { ::std::ptr::addr_of!((* ptr).x) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(x)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(y) - ) + unsafe { ::std::ptr::addr_of!((* ptr).y) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(y)) ); } #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of:: < foo > (), 8usize, concat!("Size of: ", stringify!(foo)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) + ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", + stringify!(foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); } diff --git a/bindgen-tests/tests/expectations/tests/struct_with_typedef_template_arg.rs b/bindgen-tests/tests/expectations/tests/struct_with_typedef_template_arg.rs index 49afe55906..2aaae12dcf 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_typedef_template_arg.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_typedef_template_arg.rs @@ -1,14 +1,7 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct Proxy { pub _address: u8, } -pub type Proxy_foo = - ::std::option::Option; +pub type Proxy_foo = ::std::option::Option; diff --git a/bindgen-tests/tests/expectations/tests/template-fun-ty.rs b/bindgen-tests/tests/expectations/tests/template-fun-ty.rs index a7132cf04c..5337af037a 100644 --- a/bindgen-tests/tests/expectations/tests/template-fun-ty.rs +++ b/bindgen-tests/tests/expectations/tests/template-fun-ty.rs @@ -1,17 +1,10 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct Foo { pub _address: u8, } -pub type Foo_FunctionPtr = - ::std::option::Option T>; +pub type Foo_FunctionPtr = ::std::option::Option T>; #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct RefPtr { @@ -22,6 +15,7 @@ pub struct RefPtr { pub struct RefPtr_Proxy { pub _address: u8, } -pub type RefPtr_Proxy_member_function = - ::std::option::Option R>; +pub type RefPtr_Proxy_member_function = ::std::option::Option< + unsafe extern "C" fn(arg1: Args) -> R, +>; pub type Returner = ::std::option::Option T>; diff --git a/bindgen-tests/tests/expectations/tests/template-param-usage-0.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-0.rs index 2acfb06926..6ca9b11ec6 100644 --- a/bindgen-tests/tests/expectations/tests/template-param-usage-0.rs +++ b/bindgen-tests/tests/expectations/tests/template-param-usage-0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct UsesTemplateParameter { diff --git a/bindgen-tests/tests/expectations/tests/template-param-usage-1.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-1.rs index 4fc227c914..7cbec9610d 100644 --- a/bindgen-tests/tests/expectations/tests/template-param-usage-1.rs +++ b/bindgen-tests/tests/expectations/tests/template-param-usage-1.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct DoesNotUseTemplateParameter { diff --git a/bindgen-tests/tests/expectations/tests/template-param-usage-10.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-10.rs index c6034fb8fe..778ac4a2a3 100644 --- a/bindgen-tests/tests/expectations/tests/template-param-usage-10.rs +++ b/bindgen-tests/tests/expectations/tests/template-param-usage-10.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct DoublyIndirectUsage { diff --git a/bindgen-tests/tests/expectations/tests/template-param-usage-11.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-11.rs index 63a31e234a..e914375875 100644 --- a/bindgen-tests/tests/expectations/tests/template-param-usage-11.rs +++ b/bindgen-tests/tests/expectations/tests/template-param-usage-11.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct DoesNotUseT { diff --git a/bindgen-tests/tests/expectations/tests/template-param-usage-12.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-12.rs index 626e451af4..d4d403f1da 100644 --- a/bindgen-tests/tests/expectations/tests/template-param-usage-12.rs +++ b/bindgen-tests/tests/expectations/tests/template-param-usage-12.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct BaseUsesT { diff --git a/bindgen-tests/tests/expectations/tests/template-param-usage-13.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-13.rs index 70c1778bd5..204bb1d965 100644 --- a/bindgen-tests/tests/expectations/tests/template-param-usage-13.rs +++ b/bindgen-tests/tests/expectations/tests/template-param-usage-13.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct BaseIgnoresT { diff --git a/bindgen-tests/tests/expectations/tests/template-param-usage-14.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-14.rs index 0e0fd0c9ef..b008bb5b8f 100644 --- a/bindgen-tests/tests/expectations/tests/template-param-usage-14.rs +++ b/bindgen-tests/tests/expectations/tests/template-param-usage-14.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct BaseIgnoresT { diff --git a/bindgen-tests/tests/expectations/tests/template-param-usage-15.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-15.rs index 941c607321..c6d7f71d17 100644 --- a/bindgen-tests/tests/expectations/tests/template-param-usage-15.rs +++ b/bindgen-tests/tests/expectations/tests/template-param-usage-15.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct BaseUsesT { diff --git a/bindgen-tests/tests/expectations/tests/template-param-usage-2.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-2.rs index 0ad5d7bb69..ea24b9ea82 100644 --- a/bindgen-tests/tests/expectations/tests/template-param-usage-2.rs +++ b/bindgen-tests/tests/expectations/tests/template-param-usage-2.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct UsesTemplateParameter { diff --git a/bindgen-tests/tests/expectations/tests/template-param-usage-3.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-3.rs index 414818d920..ab7121bca9 100644 --- a/bindgen-tests/tests/expectations/tests/template-param-usage-3.rs +++ b/bindgen-tests/tests/expectations/tests/template-param-usage-3.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct UsesTemplateParameter { @@ -19,9 +13,7 @@ pub struct UsesTemplateParameter_AlsoUsesTemplateParameterAndMore { pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub _phantom_1: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } -impl Default - for UsesTemplateParameter_AlsoUsesTemplateParameterAndMore -{ +impl Default for UsesTemplateParameter_AlsoUsesTemplateParameterAndMore { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); unsafe { diff --git a/bindgen-tests/tests/expectations/tests/template-param-usage-4.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-4.rs index afcba978de..0136af8b45 100644 --- a/bindgen-tests/tests/expectations/tests/template-param-usage-4.rs +++ b/bindgen-tests/tests/expectations/tests/template-param-usage-4.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct UsesTemplateParameter { diff --git a/bindgen-tests/tests/expectations/tests/template-param-usage-5.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-5.rs index 2cc8db6fe2..da363e8058 100644 --- a/bindgen-tests/tests/expectations/tests/template-param-usage-5.rs +++ b/bindgen-tests/tests/expectations/tests/template-param-usage-5.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct IndirectlyUsesTemplateParameter { diff --git a/bindgen-tests/tests/expectations/tests/template-param-usage-6.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-6.rs index 3c0e515264..0a08bc9da9 100644 --- a/bindgen-tests/tests/expectations/tests/template-param-usage-6.rs +++ b/bindgen-tests/tests/expectations/tests/template-param-usage-6.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct DoesNotUseTemplateParameter { diff --git a/bindgen-tests/tests/expectations/tests/template-param-usage-7.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-7.rs index 3ed7a45dfc..477fc5efe1 100644 --- a/bindgen-tests/tests/expectations/tests/template-param-usage-7.rs +++ b/bindgen-tests/tests/expectations/tests/template-param-usage-7.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct DoesNotUseU { diff --git a/bindgen-tests/tests/expectations/tests/template-param-usage-8.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-8.rs index f8ac671410..700f06c431 100644 --- a/bindgen-tests/tests/expectations/tests/template-param-usage-8.rs +++ b/bindgen-tests/tests/expectations/tests/template-param-usage-8.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct IndirectUsage { diff --git a/bindgen-tests/tests/expectations/tests/template-param-usage-9.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-9.rs index a50079a2ed..6e62dccd41 100644 --- a/bindgen-tests/tests/expectations/tests/template-param-usage-9.rs +++ b/bindgen-tests/tests/expectations/tests/template-param-usage-9.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct DoesNotUse { diff --git a/bindgen-tests/tests/expectations/tests/template-with-var.rs b/bindgen-tests/tests/expectations/tests/template-with-var.rs index 0476a256bf..cdc0b5b149 100644 --- a/bindgen-tests/tests/expectations/tests/template-with-var.rs +++ b/bindgen-tests/tests/expectations/tests/template-with-var.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct TemplateWithVar { diff --git a/bindgen-tests/tests/expectations/tests/template.rs b/bindgen-tests/tests/expectations/tests/template.rs index 7637295a92..4b9c99c31b 100644 --- a/bindgen-tests/tests/expectations/tests/template.rs +++ b/bindgen-tests/tests/expectations/tests/template.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Hash, PartialEq, Eq)] pub struct Foo { @@ -68,192 +62,86 @@ pub struct C { } #[test] fn bindgen_test_layout_C() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 104usize, - concat!("Size of: ", stringify!(C)) + ::std::mem::size_of:: < C > (), 104usize, concat!("Size of: ", stringify!(C)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(C)) + ::std::mem::align_of:: < C > (), 8usize, concat!("Alignment of ", stringify!(C)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mB) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).mB) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(mB)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mBConstPtr) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBConstPtr) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mBConstPtr) as usize - ptr as usize }, + 8usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(mBConstPtr)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mBConstStructPtr) as usize - - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBConstStructPtr) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mBConstStructPtr) as usize - ptr as usize + }, 16usize, concat!("Offset of field: ", stringify!(C), "::", + stringify!(mBConstStructPtr)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mBConstStructPtrArray) as usize - - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBConstStructPtrArray) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mBConst) as usize - ptr as usize }, - 32usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBConst) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mBConstStructPtrArray) as usize - ptr as + usize }, 24usize, concat!("Offset of field: ", stringify!(C), "::", + stringify!(mBConstStructPtrArray)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mBVolatile) as usize - ptr as usize - }, - 36usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBVolatile) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mBConst) as usize - ptr as usize }, + 32usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(mBConst)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mBConstBool) as usize - ptr as usize - }, - 40usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBConstBool) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mBVolatile) as usize - ptr as usize }, + 36usize, concat!("Offset of field: ", stringify!(C), "::", + stringify!(mBVolatile)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mBConstChar) as usize - ptr as usize - }, - 42usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBConstChar) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mBArray) as usize - ptr as usize }, - 44usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBArray) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mBConstBool) as usize - ptr as usize }, + 40usize, concat!("Offset of field: ", stringify!(C), "::", + stringify!(mBConstBool)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mBPtrArray) as usize - ptr as usize - }, - 48usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBPtrArray) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mBConstChar) as usize - ptr as usize }, + 42usize, concat!("Offset of field: ", stringify!(C), "::", + stringify!(mBConstChar)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mBArrayPtr) as usize - ptr as usize - }, - 56usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBArrayPtr) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mBRef) as usize - ptr as usize }, - 64usize, + unsafe { ::std::ptr::addr_of!((* ptr).mBArray) as usize - ptr as usize }, + 44usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(mBArray)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).mBPtrArray) as usize - ptr as usize }, + 48usize, concat!("Offset of field: ", stringify!(C), "::", + stringify!(mBPtrArray)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).mBArrayPtr) as usize - ptr as usize }, + 56usize, concat!("Offset of field: ", stringify!(C), "::", + stringify!(mBArrayPtr)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).mBRef) as usize - ptr as usize }, 64usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(mBRef)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mBConstRef) as usize - ptr as usize - }, - 72usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBConstRef) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mPtrRef) as usize - ptr as usize }, - 80usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mPtrRef) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mBConstRef) as usize - ptr as usize }, + 72usize, concat!("Offset of field: ", stringify!(C), "::", + stringify!(mBConstRef)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mArrayRef) as usize - ptr as usize - }, - 88usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mArrayRef) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mPtrRef) as usize - ptr as usize }, + 80usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(mPtrRef)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mBConstArray) as usize - ptr as usize - }, - 96usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBConstArray) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mArrayRef) as usize - ptr as usize }, + 88usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(mArrayRef)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).mBConstArray) as usize - ptr as usize }, + 96usize, concat!("Offset of field: ", stringify!(C), "::", + stringify!(mBConstArray)) ); } impl Default for C { @@ -320,28 +208,19 @@ pub struct RootedContainer { } #[test] fn bindgen_test_layout_RootedContainer() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 24usize, - concat!("Size of: ", stringify!(RootedContainer)) + ::std::mem::size_of:: < RootedContainer > (), 24usize, concat!("Size of: ", + stringify!(RootedContainer)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(RootedContainer)) + ::std::mem::align_of:: < RootedContainer > (), 8usize, concat!("Alignment of ", + stringify!(RootedContainer)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).root) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(RootedContainer), - "::", - stringify!(root) - ) + unsafe { ::std::ptr::addr_of!((* ptr).root) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(RootedContainer), "::", stringify!(root)) ); } impl Default for RootedContainer { @@ -376,28 +255,20 @@ pub struct PODButContainsDtor { } #[test] fn bindgen_test_layout_PODButContainsDtor() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(PODButContainsDtor)) + ::std::mem::size_of:: < PODButContainsDtor > (), 4usize, concat!("Size of: ", + stringify!(PODButContainsDtor)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < PODButContainsDtor > (), 4usize, concat!("Alignment of ", stringify!(PODButContainsDtor)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(PODButContainsDtor), - "::", - stringify!(member) - ) + unsafe { ::std::ptr::addr_of!((* ptr).member) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(PODButContainsDtor), "::", + stringify!(member)) ); } impl Default for PODButContainsDtor { @@ -422,30 +293,19 @@ pub struct POD { } #[test] fn bindgen_test_layout_POD() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(POD)) + ::std::mem::size_of:: < POD > (), 4usize, concat!("Size of: ", stringify!(POD)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(POD)) + ::std::mem::align_of:: < POD > (), 4usize, concat!("Alignment of ", + stringify!(POD)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).opaque_member) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(POD), - "::", - stringify!(opaque_member) - ) + unsafe { ::std::ptr::addr_of!((* ptr).opaque_member) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(POD), "::", + stringify!(opaque_member)) ); } ///
@@ -519,14 +379,12 @@ pub struct Untemplated { #[test] fn bindgen_test_layout_Untemplated() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Untemplated)) + ::std::mem::size_of:: < Untemplated > (), 1usize, concat!("Size of: ", + stringify!(Untemplated)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Untemplated)) + ::std::mem::align_of:: < Untemplated > (), 1usize, concat!("Alignment of ", + stringify!(Untemplated)) ); } #[repr(C)] @@ -534,10 +392,10 @@ fn bindgen_test_layout_Untemplated() { pub struct Templated { pub m_untemplated: Untemplated, } -/// If the replacement doesn't happen at the parse level the container would be -/// copy and the replacement wouldn't, so this wouldn't compile. -/// -///
+/** If the replacement doesn't happen at the parse level the container would be + copy and the replacement wouldn't, so this wouldn't compile. + +
*/ #[repr(C)] #[derive(Debug, Hash, PartialEq, Eq)] pub struct ReplacedWithoutDestructor { @@ -583,10 +441,10 @@ impl Default for ShouldNotBeCopiableAsWell { } } } -/// If the replacement doesn't happen at the parse level the container would be -/// copy and the replacement wouldn't, so this wouldn't compile. -/// -///
+/** If the replacement doesn't happen at the parse level the container would be + copy and the replacement wouldn't, so this wouldn't compile. + +
*/ #[repr(C)] #[derive(Debug, Hash, PartialEq, Eq)] pub struct ReplacedWithoutDestructorFwd { @@ -605,391 +463,269 @@ impl Default for ReplacedWithoutDestructorFwd { #[test] fn __bindgen_test_layout_Foo_open0_int_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of::>(), - 24usize, - concat!( - "Size of template specialization: ", - stringify!(Foo<::std::os::raw::c_int>) - ) + ::std::mem::size_of:: < Foo < ::std::os::raw::c_int > > (), 24usize, + concat!("Size of template specialization: ", stringify!(Foo < + ::std::os::raw::c_int >)) ); assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(Foo<::std::os::raw::c_int>) - ) + ::std::mem::align_of:: < Foo < ::std::os::raw::c_int > > (), 8usize, + concat!("Alignment of template specialization: ", stringify!(Foo < + ::std::os::raw::c_int >)) ); } #[test] fn __bindgen_test_layout_B_open0_unsigned_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!( - "Size of template specialization: ", - stringify!(B<::std::os::raw::c_uint>) - ) + ::std::mem::size_of:: < B < ::std::os::raw::c_uint > > (), 4usize, + concat!("Size of template specialization: ", stringify!(B < + ::std::os::raw::c_uint >)) ); assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(B<::std::os::raw::c_uint>) - ) + ::std::mem::align_of:: < B < ::std::os::raw::c_uint > > (), 4usize, + concat!("Alignment of template specialization: ", stringify!(B < + ::std::os::raw::c_uint >)) ); } #[test] fn __bindgen_test_layout_B_open0_ptr_const_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of::>(), - 8usize, - concat!( - "Size of template specialization: ", - stringify!(B<*const ::std::os::raw::c_int>) - ) + ::std::mem::size_of:: < B < * const ::std::os::raw::c_int > > (), 8usize, + concat!("Size of template specialization: ", stringify!(B < * const + ::std::os::raw::c_int >)) ); assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(B<*const ::std::os::raw::c_int>) - ) + ::std::mem::align_of:: < B < * const ::std::os::raw::c_int > > (), 8usize, + concat!("Alignment of template specialization: ", stringify!(B < * const + ::std::os::raw::c_int >)) ); } #[test] fn __bindgen_test_layout_B_open0_ptr_const_mozilla__Foo_close0_instantiation() { assert_eq!( - ::std::mem::size_of::>(), - 8usize, - concat!( - "Size of template specialization: ", - stringify!(B<*const mozilla_Foo>) - ) + ::std::mem::size_of:: < B < * const mozilla_Foo > > (), 8usize, + concat!("Size of template specialization: ", stringify!(B < * const mozilla_Foo + >)) ); assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(B<*const mozilla_Foo>) - ) + ::std::mem::align_of:: < B < * const mozilla_Foo > > (), 8usize, + concat!("Alignment of template specialization: ", stringify!(B < * const + mozilla_Foo >)) ); } #[test] -fn __bindgen_test_layout_B_open0_array1_ptr_const_mozilla__Foo_close0_instantiation( -) { +fn __bindgen_test_layout_B_open0_array1_ptr_const_mozilla__Foo_close0_instantiation() { assert_eq!( - ::std::mem::size_of::>(), - 8usize, - concat!( - "Size of template specialization: ", - stringify!(B<[*const mozilla_Foo; 1usize]>) - ) + ::std::mem::size_of:: < B < [* const mozilla_Foo; 1usize] > > (), 8usize, + concat!("Size of template specialization: ", stringify!(B < [* const mozilla_Foo; + 1usize] >)) ); assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(B<[*const mozilla_Foo; 1usize]>) - ) + ::std::mem::align_of:: < B < [* const mozilla_Foo; 1usize] > > (), 8usize, + concat!("Alignment of template specialization: ", stringify!(B < [* const + mozilla_Foo; 1usize] >)) ); } #[test] fn __bindgen_test_layout_B_open0_const_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!( - "Size of template specialization: ", - stringify!(B<::std::os::raw::c_int>) - ) + ::std::mem::size_of:: < B < ::std::os::raw::c_int > > (), 4usize, + concat!("Size of template specialization: ", stringify!(B < ::std::os::raw::c_int + >)) ); assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(B<::std::os::raw::c_int>) - ) + ::std::mem::align_of:: < B < ::std::os::raw::c_int > > (), 4usize, + concat!("Alignment of template specialization: ", stringify!(B < + ::std::os::raw::c_int >)) ); } #[test] fn __bindgen_test_layout_B_open0_volatile_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!( - "Size of template specialization: ", - stringify!(B<::std::os::raw::c_int>) - ) + ::std::mem::size_of:: < B < ::std::os::raw::c_int > > (), 4usize, + concat!("Size of template specialization: ", stringify!(B < ::std::os::raw::c_int + >)) ); assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(B<::std::os::raw::c_int>) - ) + ::std::mem::align_of:: < B < ::std::os::raw::c_int > > (), 4usize, + concat!("Alignment of template specialization: ", stringify!(B < + ::std::os::raw::c_int >)) ); } #[test] fn __bindgen_test_layout_B_open0_const_bool_close0_instantiation() { assert_eq!( - ::std::mem::size_of::>(), - 1usize, - concat!("Size of template specialization: ", stringify!(B)) + ::std::mem::size_of:: < B < bool > > (), 1usize, + concat!("Size of template specialization: ", stringify!(B < bool >)) ); assert_eq!( - ::std::mem::align_of::>(), - 1usize, - concat!( - "Alignment of template specialization: ", - stringify!(B) - ) + ::std::mem::align_of:: < B < bool > > (), 1usize, + concat!("Alignment of template specialization: ", stringify!(B < bool >)) ); } #[test] fn __bindgen_test_layout_B_open0_const_char16_t_close0_instantiation() { assert_eq!( - ::std::mem::size_of::>(), - 2usize, - concat!("Size of template specialization: ", stringify!(B)) + ::std::mem::size_of:: < B < u16 > > (), 2usize, + concat!("Size of template specialization: ", stringify!(B < u16 >)) ); assert_eq!( - ::std::mem::align_of::>(), - 2usize, - concat!("Alignment of template specialization: ", stringify!(B)) + ::std::mem::align_of:: < B < u16 > > (), 2usize, + concat!("Alignment of template specialization: ", stringify!(B < u16 >)) ); } #[test] fn __bindgen_test_layout_B_open0_array1_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!( - "Size of template specialization: ", - stringify!(B<[::std::os::raw::c_int; 1usize]>) - ) + ::std::mem::size_of:: < B < [::std::os::raw::c_int; 1usize] > > (), 4usize, + concat!("Size of template specialization: ", stringify!(B < + [::std::os::raw::c_int; 1usize] >)) ); assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(B<[::std::os::raw::c_int; 1usize]>) - ) + ::std::mem::align_of:: < B < [::std::os::raw::c_int; 1usize] > > (), 4usize, + concat!("Alignment of template specialization: ", stringify!(B < + [::std::os::raw::c_int; 1usize] >)) ); } #[test] fn __bindgen_test_layout_B_open0_array1_ptr_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of::>(), - 8usize, - concat!( - "Size of template specialization: ", - stringify!(B<[*mut ::std::os::raw::c_int; 1usize]>) - ) + ::std::mem::size_of:: < B < [* mut ::std::os::raw::c_int; 1usize] > > (), 8usize, + concat!("Size of template specialization: ", stringify!(B < [* mut + ::std::os::raw::c_int; 1usize] >)) ); assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(B<[*mut ::std::os::raw::c_int; 1usize]>) - ) + ::std::mem::align_of:: < B < [* mut ::std::os::raw::c_int; 1usize] > > (), + 8usize, concat!("Alignment of template specialization: ", stringify!(B < [* mut + ::std::os::raw::c_int; 1usize] >)) ); } #[test] fn __bindgen_test_layout_B_open0_ptr_array1_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of::>(), - 8usize, - concat!( - "Size of template specialization: ", - stringify!(B<*mut [::std::os::raw::c_int; 1usize]>) - ) + ::std::mem::size_of:: < B < * mut [::std::os::raw::c_int; 1usize] > > (), 8usize, + concat!("Size of template specialization: ", stringify!(B < * mut + [::std::os::raw::c_int; 1usize] >)) ); assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(B<*mut [::std::os::raw::c_int; 1usize]>) - ) + ::std::mem::align_of:: < B < * mut [::std::os::raw::c_int; 1usize] > > (), + 8usize, concat!("Alignment of template specialization: ", stringify!(B < * mut + [::std::os::raw::c_int; 1usize] >)) ); } #[test] fn __bindgen_test_layout_B_open0_ref_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of::>(), - 8usize, - concat!( - "Size of template specialization: ", - stringify!(B<*mut ::std::os::raw::c_int>) - ) + ::std::mem::size_of:: < B < * mut ::std::os::raw::c_int > > (), 8usize, + concat!("Size of template specialization: ", stringify!(B < * mut + ::std::os::raw::c_int >)) ); assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(B<*mut ::std::os::raw::c_int>) - ) + ::std::mem::align_of:: < B < * mut ::std::os::raw::c_int > > (), 8usize, + concat!("Alignment of template specialization: ", stringify!(B < * mut + ::std::os::raw::c_int >)) ); } #[test] fn __bindgen_test_layout_B_open0_ref_const_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of::>(), - 8usize, - concat!( - "Size of template specialization: ", - stringify!(B<*const ::std::os::raw::c_int>) - ) + ::std::mem::size_of:: < B < * const ::std::os::raw::c_int > > (), 8usize, + concat!("Size of template specialization: ", stringify!(B < * const + ::std::os::raw::c_int >)) ); assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(B<*const ::std::os::raw::c_int>) - ) + ::std::mem::align_of:: < B < * const ::std::os::raw::c_int > > (), 8usize, + concat!("Alignment of template specialization: ", stringify!(B < * const + ::std::os::raw::c_int >)) ); } #[test] fn __bindgen_test_layout_B_open0_ref_ptr_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of::>(), - 8usize, - concat!( - "Size of template specialization: ", - stringify!(B<*mut *mut ::std::os::raw::c_int>) - ) + ::std::mem::size_of:: < B < * mut * mut ::std::os::raw::c_int > > (), 8usize, + concat!("Size of template specialization: ", stringify!(B < * mut * mut + ::std::os::raw::c_int >)) ); assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(B<*mut *mut ::std::os::raw::c_int>) - ) + ::std::mem::align_of:: < B < * mut * mut ::std::os::raw::c_int > > (), 8usize, + concat!("Alignment of template specialization: ", stringify!(B < * mut * mut + ::std::os::raw::c_int >)) ); } #[test] fn __bindgen_test_layout_B_open0_ref_array1_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of::>(), - 8usize, - concat!( - "Size of template specialization: ", - stringify!(B<*mut [::std::os::raw::c_int; 1usize]>) - ) + ::std::mem::size_of:: < B < * mut [::std::os::raw::c_int; 1usize] > > (), 8usize, + concat!("Size of template specialization: ", stringify!(B < * mut + [::std::os::raw::c_int; 1usize] >)) ); assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(B<*mut [::std::os::raw::c_int; 1usize]>) - ) + ::std::mem::align_of:: < B < * mut [::std::os::raw::c_int; 1usize] > > (), + 8usize, concat!("Alignment of template specialization: ", stringify!(B < * mut + [::std::os::raw::c_int; 1usize] >)) ); } #[test] fn __bindgen_test_layout_B_open0_array1_const_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!( - "Size of template specialization: ", - stringify!(B<[::std::os::raw::c_int; 1usize]>) - ) + ::std::mem::size_of:: < B < [::std::os::raw::c_int; 1usize] > > (), 4usize, + concat!("Size of template specialization: ", stringify!(B < + [::std::os::raw::c_int; 1usize] >)) ); assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(B<[::std::os::raw::c_int; 1usize]>) - ) + ::std::mem::align_of:: < B < [::std::os::raw::c_int; 1usize] > > (), 4usize, + concat!("Alignment of template specialization: ", stringify!(B < + [::std::os::raw::c_int; 1usize] >)) ); } #[test] fn __bindgen_test_layout_Foo_open0_int_int_close0_instantiation_1() { assert_eq!( - ::std::mem::size_of::>(), - 24usize, - concat!( - "Size of template specialization: ", - stringify!(Foo<::std::os::raw::c_int>) - ) + ::std::mem::size_of:: < Foo < ::std::os::raw::c_int > > (), 24usize, + concat!("Size of template specialization: ", stringify!(Foo < + ::std::os::raw::c_int >)) ); assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(Foo<::std::os::raw::c_int>) - ) + ::std::mem::align_of:: < Foo < ::std::os::raw::c_int > > (), 8usize, + concat!("Alignment of template specialization: ", stringify!(Foo < + ::std::os::raw::c_int >)) ); } #[test] fn __bindgen_test_layout_Rooted_open0_ptr_void_close0_instantiation() { assert_eq!( - ::std::mem::size_of::>(), - 24usize, - concat!( - "Size of template specialization: ", - stringify!(Rooted<*mut ::std::os::raw::c_void>) - ) + ::std::mem::size_of:: < Rooted < * mut ::std::os::raw::c_void > > (), 24usize, + concat!("Size of template specialization: ", stringify!(Rooted < * mut + ::std::os::raw::c_void >)) ); assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(Rooted<*mut ::std::os::raw::c_void>) - ) + ::std::mem::align_of:: < Rooted < * mut ::std::os::raw::c_void > > (), 8usize, + concat!("Alignment of template specialization: ", stringify!(Rooted < * mut + ::std::os::raw::c_void >)) ); } #[test] fn __bindgen_test_layout_Rooted_open0_ptr_void_close0_instantiation_1() { assert_eq!( - ::std::mem::size_of::>(), - 24usize, - concat!( - "Size of template specialization: ", - stringify!(Rooted<*mut ::std::os::raw::c_void>) - ) + ::std::mem::size_of:: < Rooted < * mut ::std::os::raw::c_void > > (), 24usize, + concat!("Size of template specialization: ", stringify!(Rooted < * mut + ::std::os::raw::c_void >)) ); assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(Rooted<*mut ::std::os::raw::c_void>) - ) + ::std::mem::align_of:: < Rooted < * mut ::std::os::raw::c_void > > (), 8usize, + concat!("Alignment of template specialization: ", stringify!(Rooted < * mut + ::std::os::raw::c_void >)) ); } #[test] fn __bindgen_test_layout_WithDtor_open0_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!( - "Size of template specialization: ", - stringify!(WithDtor<::std::os::raw::c_int>) - ) + ::std::mem::size_of:: < WithDtor < ::std::os::raw::c_int > > (), 4usize, + concat!("Size of template specialization: ", stringify!(WithDtor < + ::std::os::raw::c_int >)) ); assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(WithDtor<::std::os::raw::c_int>) - ) + ::std::mem::align_of:: < WithDtor < ::std::os::raw::c_int > > (), 4usize, + concat!("Alignment of template specialization: ", stringify!(WithDtor < + ::std::os::raw::c_int >)) ); } diff --git a/bindgen-tests/tests/expectations/tests/template_alias.rs b/bindgen-tests/tests/expectations/tests/template_alias.rs index 7e0af20d78..d286cca3c6 100644 --- a/bindgen-tests/tests/expectations/tests/template_alias.rs +++ b/bindgen-tests/tests/expectations/tests/template_alias.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type JS_detail_Wrapped = T; #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] diff --git a/bindgen-tests/tests/expectations/tests/template_alias_basic.rs b/bindgen-tests/tests/expectations/tests/template_alias_basic.rs index e06ffadab3..d0f8f104c7 100644 --- a/bindgen-tests/tests/expectations/tests/template_alias_basic.rs +++ b/bindgen-tests/tests/expectations/tests/template_alias_basic.rs @@ -1,8 +1,2 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type Wrapped = T; diff --git a/bindgen-tests/tests/expectations/tests/template_alias_namespace.rs b/bindgen-tests/tests/expectations/tests/template_alias_namespace.rs index 7196b532f6..d0dfa78596 100644 --- a/bindgen-tests/tests/expectations/tests/template_alias_namespace.rs +++ b/bindgen-tests/tests/expectations/tests/template_alias_namespace.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![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 { #[allow(unused_imports)] @@ -21,8 +15,7 @@ pub mod root { #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Rooted { pub ptr: root::JS::detail::Wrapped, - pub _phantom_0: - ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } impl Default for Rooted { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/template_fun.rs b/bindgen-tests/tests/expectations/tests/template_fun.rs index 131dbdf39f..fe64295a68 100644 --- a/bindgen-tests/tests/expectations/tests/template_fun.rs +++ b/bindgen-tests/tests/expectations/tests/template_fun.rs @@ -1,6 +1 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] \ No newline at end of file diff --git a/bindgen-tests/tests/expectations/tests/template_instantiation_with_fn_local_type.rs b/bindgen-tests/tests/expectations/tests/template_instantiation_with_fn_local_type.rs index d968e71bae..ab87b4160b 100644 --- a/bindgen-tests/tests/expectations/tests/template_instantiation_with_fn_local_type.rs +++ b/bindgen-tests/tests/expectations/tests/template_instantiation_with_fn_local_type.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { @@ -17,13 +11,11 @@ extern "C" { #[test] fn __bindgen_test_layout_Foo_open0_Bar_close0_instantiation() { assert_eq!( - ::std::mem::size_of::(), - 1usize, + ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of template specialization: ", stringify!(Foo)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of template specialization: ", stringify!(Foo)) ); } @@ -35,26 +27,21 @@ pub struct Baz { #[test] fn bindgen_test_layout_Baz() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Baz)) + ::std::mem::size_of:: < Baz > (), 1usize, concat!("Size of: ", stringify!(Baz)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Baz)) + ::std::mem::align_of:: < Baz > (), 1usize, concat!("Alignment of ", + stringify!(Baz)) ); } #[test] fn __bindgen_test_layout_Foo_open0_Boo_close0_instantiation() { assert_eq!( - ::std::mem::size_of::(), - 1usize, + ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of template specialization: ", stringify!(Foo)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of template specialization: ", stringify!(Foo)) ); } @@ -66,14 +53,11 @@ pub struct Bar { #[test] fn bindgen_test_layout_Bar() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Bar)) + ::std::mem::size_of:: < Bar > (), 1usize, concat!("Size of: ", stringify!(Bar)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Bar)) + ::std::mem::align_of:: < Bar > (), 1usize, concat!("Alignment of ", + stringify!(Bar)) ); } #[repr(C)] @@ -84,13 +68,10 @@ pub struct Boo { #[test] fn bindgen_test_layout_Boo() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Boo)) + ::std::mem::size_of:: < Boo > (), 1usize, concat!("Size of: ", stringify!(Boo)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Boo)) + ::std::mem::align_of:: < Boo > (), 1usize, concat!("Alignment of ", + stringify!(Boo)) ); } diff --git a/bindgen-tests/tests/expectations/tests/template_partial_specification.rs b/bindgen-tests/tests/expectations/tests/template_partial_specification.rs index 131dbdf39f..fe64295a68 100644 --- a/bindgen-tests/tests/expectations/tests/template_partial_specification.rs +++ b/bindgen-tests/tests/expectations/tests/template_partial_specification.rs @@ -1,6 +1 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] \ No newline at end of file diff --git a/bindgen-tests/tests/expectations/tests/template_typedef_transitive_param.rs b/bindgen-tests/tests/expectations/tests/template_typedef_transitive_param.rs index 68ca126ac9..019f085c60 100644 --- a/bindgen-tests/tests/expectations/tests/template_typedef_transitive_param.rs +++ b/bindgen-tests/tests/expectations/tests/template_typedef_transitive_param.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct Wrapper { diff --git a/bindgen-tests/tests/expectations/tests/template_typedefs.rs b/bindgen-tests/tests/expectations/tests/template_typedefs.rs index 3883879d28..71f0732a63 100644 --- a/bindgen-tests/tests/expectations/tests/template_typedefs.rs +++ b/bindgen-tests/tests/expectations/tests/template_typedefs.rs @@ -1,12 +1,5 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -pub type foo = - ::std::option::Option; +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub type foo = ::std::option::Option; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { @@ -15,8 +8,5 @@ pub struct Foo { pub type Foo_Char = T; pub type Foo_FooPtrTypedef = *mut Foo_Char; pub type Foo_nsCOMArrayEnumFunc = ::std::option::Option< - unsafe extern "C" fn( - aElement: *mut T, - aData: *mut ::std::os::raw::c_void, - ) -> bool, + unsafe extern "C" fn(aElement: *mut T, aData: *mut ::std::os::raw::c_void) -> bool, >; diff --git a/bindgen-tests/tests/expectations/tests/templateref_opaque.rs b/bindgen-tests/tests/expectations/tests/templateref_opaque.rs index 70cef86717..8f73e86c31 100644 --- a/bindgen-tests/tests/expectations/tests/templateref_opaque.rs +++ b/bindgen-tests/tests/expectations/tests/templateref_opaque.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct detail_PointerType { diff --git a/bindgen-tests/tests/expectations/tests/templatized-bitfield.rs b/bindgen-tests/tests/expectations/tests/templatized-bitfield.rs index 5657a65540..1b3e712361 100644 --- a/bindgen-tests/tests/expectations/tests/templatized-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/templatized-bitfield.rs @@ -1,13 +1,7 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - -/// We don't get a layout for this bitfield, since we don't know what `T` will -/// be, so we cannot allocate bitfield units. The best thing we can do is make -/// the struct opaque. +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +/** We don't get a layout for this bitfield, since we don't know what `T` will + be, so we cannot allocate bitfield units. The best thing we can do is make + the struct opaque.*/ #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct TemplatizedBitfield { diff --git a/bindgen-tests/tests/expectations/tests/timex.rs b/bindgen-tests/tests/expectations/tests/timex.rs index dfcebdd29c..025dce91ff 100644 --- a/bindgen-tests/tests/expectations/tests/timex.rs +++ b/bindgen-tests/tests/expectations/tests/timex.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -100,28 +92,19 @@ pub struct timex { } #[test] fn bindgen_test_layout_timex() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 48usize, - concat!("Size of: ", stringify!(timex)) + ::std::mem::size_of:: < timex > (), 48usize, concat!("Size of: ", + stringify!(timex)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(timex)) + ::std::mem::align_of:: < timex > (), 4usize, concat!("Alignment of ", + stringify!(timex)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).tai) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(timex), - "::", - stringify!(tai) - ) + unsafe { ::std::ptr::addr_of!((* ptr).tai) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(timex), "::", stringify!(tai)) ); } impl Default for timex { @@ -142,28 +125,19 @@ pub struct timex_named { } #[test] fn bindgen_test_layout_timex_named() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 48usize, - concat!("Size of: ", stringify!(timex_named)) + ::std::mem::size_of:: < timex_named > (), 48usize, concat!("Size of: ", + stringify!(timex_named)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(timex_named)) + ::std::mem::align_of:: < timex_named > (), 4usize, concat!("Alignment of ", + stringify!(timex_named)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).tai) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(timex_named), - "::", - stringify!(tai) - ) + unsafe { ::std::ptr::addr_of!((* ptr).tai) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(timex_named), "::", stringify!(tai)) ); } impl Default for timex_named { @@ -178,9 +152,7 @@ impl Default for timex_named { impl timex_named { #[inline] pub fn a(&self) -> ::std::os::raw::c_int { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 32u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 32u8) as u32) } } #[inline] pub fn set_a(&mut self, val: ::std::os::raw::c_int) { @@ -191,9 +163,7 @@ impl timex_named { } #[inline] pub fn b(&self) -> ::std::os::raw::c_int { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(32usize, 32u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(32usize, 32u8) as u32) } } #[inline] pub fn set_b(&mut self, val: ::std::os::raw::c_int) { @@ -204,9 +174,7 @@ impl timex_named { } #[inline] pub fn c(&self) -> ::std::os::raw::c_int { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(64usize, 32u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(64usize, 32u8) as u32) } } #[inline] pub fn set_c(&mut self, val: ::std::os::raw::c_int) { @@ -217,9 +185,7 @@ impl timex_named { } #[inline] pub fn d(&self) -> ::std::os::raw::c_int { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(96usize, 32u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(96usize, 32u8) as u32) } } #[inline] pub fn set_d(&mut self, val: ::std::os::raw::c_int) { @@ -230,9 +196,7 @@ impl timex_named { } #[inline] pub fn e(&self) -> ::std::os::raw::c_int { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(128usize, 32u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(128usize, 32u8) as u32) } } #[inline] pub fn set_e(&mut self, val: ::std::os::raw::c_int) { @@ -243,9 +207,7 @@ impl timex_named { } #[inline] pub fn f(&self) -> ::std::os::raw::c_int { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(160usize, 32u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(160usize, 32u8) as u32) } } #[inline] pub fn set_f(&mut self, val: ::std::os::raw::c_int) { @@ -256,9 +218,7 @@ impl timex_named { } #[inline] pub fn g(&self) -> ::std::os::raw::c_int { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(192usize, 32u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(192usize, 32u8) as u32) } } #[inline] pub fn set_g(&mut self, val: ::std::os::raw::c_int) { @@ -269,9 +229,7 @@ impl timex_named { } #[inline] pub fn h(&self) -> ::std::os::raw::c_int { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(224usize, 32u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(224usize, 32u8) as u32) } } #[inline] pub fn set_h(&mut self, val: ::std::os::raw::c_int) { @@ -282,9 +240,7 @@ impl timex_named { } #[inline] pub fn i(&self) -> ::std::os::raw::c_int { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(256usize, 32u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(256usize, 32u8) as u32) } } #[inline] pub fn set_i(&mut self, val: ::std::os::raw::c_int) { @@ -295,9 +251,7 @@ impl timex_named { } #[inline] pub fn j(&self) -> ::std::os::raw::c_int { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(288usize, 32u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(288usize, 32u8) as u32) } } #[inline] pub fn set_j(&mut self, val: ::std::os::raw::c_int) { @@ -308,9 +262,7 @@ impl timex_named { } #[inline] pub fn k(&self) -> ::std::os::raw::c_int { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(320usize, 32u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(320usize, 32u8) as u32) } } #[inline] pub fn set_k(&mut self, val: ::std::os::raw::c_int) { diff --git a/bindgen-tests/tests/expectations/tests/transform-op.rs b/bindgen-tests/tests/expectations/tests/transform-op.rs index 84a9460362..3e7730bcea 100644 --- a/bindgen-tests/tests/expectations/tests/transform-op.rs +++ b/bindgen-tests/tests/expectations/tests/transform-op.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -223,38 +217,22 @@ impl Default for StyleBar { #[test] fn __bindgen_test_layout_StylePoint_open0_float_close0_instantiation() { assert_eq!( - ::std::mem::size_of::>(), - 8usize, - concat!( - "Size of template specialization: ", - stringify!(StylePoint) - ) + ::std::mem::size_of:: < StylePoint < f32 > > (), 8usize, + concat!("Size of template specialization: ", stringify!(StylePoint < f32 >)) ); assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(StylePoint) - ) + ::std::mem::align_of:: < StylePoint < f32 > > (), 4usize, + concat!("Alignment of template specialization: ", stringify!(StylePoint < f32 >)) ); } #[test] fn __bindgen_test_layout_StylePoint_open0_float_close0_instantiation_1() { assert_eq!( - ::std::mem::size_of::>(), - 8usize, - concat!( - "Size of template specialization: ", - stringify!(StylePoint) - ) + ::std::mem::size_of:: < StylePoint < f32 > > (), 8usize, + concat!("Size of template specialization: ", stringify!(StylePoint < f32 >)) ); assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(StylePoint) - ) + ::std::mem::align_of:: < StylePoint < f32 > > (), 4usize, + concat!("Alignment of template specialization: ", stringify!(StylePoint < f32 >)) ); } diff --git a/bindgen-tests/tests/expectations/tests/type-referenced-by-allowlisted-function.rs b/bindgen-tests/tests/expectations/tests/type-referenced-by-allowlisted-function.rs index 7ae042bc9c..bc16ba496e 100644 --- a/bindgen-tests/tests/expectations/tests/type-referenced-by-allowlisted-function.rs +++ b/bindgen-tests/tests/expectations/tests/type-referenced-by-allowlisted-function.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct dl_phdr_info { @@ -12,28 +6,19 @@ pub struct dl_phdr_info { } #[test] fn bindgen_test_layout_dl_phdr_info() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(dl_phdr_info)) + ::std::mem::size_of:: < dl_phdr_info > (), 4usize, concat!("Size of: ", + stringify!(dl_phdr_info)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(dl_phdr_info)) + ::std::mem::align_of:: < dl_phdr_info > (), 4usize, concat!("Alignment of ", + stringify!(dl_phdr_info)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(dl_phdr_info), - "::", - stringify!(x) - ) + unsafe { ::std::ptr::addr_of!((* ptr).x) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(dl_phdr_info), "::", stringify!(x)) ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/type_alias_empty.rs b/bindgen-tests/tests/expectations/tests/type_alias_empty.rs index cb871a33a2..2cbeb75570 100644 --- a/bindgen-tests/tests/expectations/tests/type_alias_empty.rs +++ b/bindgen-tests/tests/expectations/tests/type_alias_empty.rs @@ -1,8 +1,2 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type bool_constant = u8; diff --git a/bindgen-tests/tests/expectations/tests/type_alias_partial_template_especialization.rs b/bindgen-tests/tests/expectations/tests/type_alias_partial_template_especialization.rs index 44449f20d1..48c388d6f9 100644 --- a/bindgen-tests/tests/expectations/tests/type_alias_partial_template_especialization.rs +++ b/bindgen-tests/tests/expectations/tests/type_alias_partial_template_especialization.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type MaybeWrapped
= A; #[repr(C)] #[derive(Debug, Copy, Clone)] diff --git a/bindgen-tests/tests/expectations/tests/typedef-pointer-overlap.rs b/bindgen-tests/tests/expectations/tests/typedef-pointer-overlap.rs index 2d5c5aae8c..fed13bbd42 100644 --- a/bindgen-tests/tests/expectations/tests/typedef-pointer-overlap.rs +++ b/bindgen-tests/tests/expectations/tests/typedef-pointer-overlap.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct foo { @@ -12,28 +6,18 @@ pub struct foo { } #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of:: < foo > (), 1usize, concat!("Size of: ", stringify!(foo)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(foo)) + ::std::mem::align_of:: < foo > (), 1usize, concat!("Alignment of ", + stringify!(foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).inner) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(inner) - ) + unsafe { ::std::ptr::addr_of!((* ptr).inner) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(inner)) ); } pub type foo_ptr = *const foo; @@ -44,28 +28,18 @@ pub struct bar { } #[test] fn bindgen_test_layout_bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(bar)) + ::std::mem::size_of:: < bar > (), 1usize, concat!("Size of: ", stringify!(bar)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(bar)) + ::std::mem::align_of:: < bar > (), 1usize, concat!("Alignment of ", + stringify!(bar)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).inner) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(inner) - ) + unsafe { ::std::ptr::addr_of!((* ptr).inner) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(bar), "::", stringify!(inner)) ); } pub type bar_ptr = *mut bar; @@ -82,30 +56,19 @@ pub union cat { } #[test] fn bindgen_test_layout_cat() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(cat)) + ::std::mem::size_of:: < cat > (), 4usize, concat!("Size of: ", stringify!(cat)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(cat)) + ::std::mem::align_of:: < cat > (), 4usize, concat!("Alignment of ", + stringify!(cat)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).standard_issue) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(cat), - "::", - stringify!(standard_issue) - ) + unsafe { ::std::ptr::addr_of!((* ptr).standard_issue) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(cat), "::", + stringify!(standard_issue)) ); } impl Default for cat { diff --git a/bindgen-tests/tests/expectations/tests/typedefd-array-as-function-arg.rs b/bindgen-tests/tests/expectations/tests/typedefd-array-as-function-arg.rs index 330499b8ab..792b243a7a 100644 --- a/bindgen-tests/tests/expectations/tests/typedefd-array-as-function-arg.rs +++ b/bindgen-tests/tests/expectations/tests/typedefd-array-as-function-arg.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type myVector3 = [f32; 3usize]; extern "C" { pub fn modifyVectorFunc(v: *mut f32); diff --git a/bindgen-tests/tests/expectations/tests/typeref.rs b/bindgen-tests/tests/expectations/tests/typeref.rs index a3a31dafa7..1a19ba6c8f 100644 --- a/bindgen-tests/tests/expectations/tests/typeref.rs +++ b/bindgen-tests/tests/expectations/tests/typeref.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct mozilla_FragmentOrURL { @@ -12,30 +6,20 @@ pub struct mozilla_FragmentOrURL { } #[test] fn bindgen_test_layout_mozilla_FragmentOrURL() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(mozilla_FragmentOrURL)) + ::std::mem::size_of:: < mozilla_FragmentOrURL > (), 1usize, concat!("Size of: ", + stringify!(mozilla_FragmentOrURL)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < mozilla_FragmentOrURL > (), 1usize, concat!("Alignment of ", stringify!(mozilla_FragmentOrURL)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mIsLocalRef) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(mozilla_FragmentOrURL), - "::", - stringify!(mIsLocalRef) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mIsLocalRef) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(mozilla_FragmentOrURL), "::", + stringify!(mIsLocalRef)) ); } #[repr(C)] @@ -46,14 +30,12 @@ pub struct mozilla_Position { #[test] fn bindgen_test_layout_mozilla_Position() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(mozilla_Position)) + ::std::mem::size_of:: < mozilla_Position > (), 1usize, concat!("Size of: ", + stringify!(mozilla_Position)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(mozilla_Position)) + ::std::mem::align_of:: < mozilla_Position > (), 1usize, concat!("Alignment of ", + stringify!(mozilla_Position)) ); } #[repr(C)] @@ -90,22 +72,17 @@ pub struct Bar { } #[test] fn bindgen_test_layout_Bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Bar)) + ::std::mem::size_of:: < Bar > (), 8usize, concat!("Size of: ", stringify!(Bar)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Bar)) + ::std::mem::align_of:: < Bar > (), 8usize, concat!("Alignment of ", + stringify!(Bar)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mFoo) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).mFoo) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(mFoo)) ); } @@ -124,28 +101,19 @@ pub struct nsFoo { } #[test] fn bindgen_test_layout_nsFoo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(nsFoo)) + ::std::mem::size_of:: < nsFoo > (), 8usize, concat!("Size of: ", + stringify!(nsFoo)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(nsFoo)) + ::std::mem::align_of:: < nsFoo > (), 8usize, concat!("Alignment of ", + stringify!(nsFoo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mBar) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsFoo), - "::", - stringify!(mBar) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mBar) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(nsFoo), "::", stringify!(mBar)) ); } impl Default for nsFoo { @@ -158,22 +126,15 @@ impl Default for nsFoo { } } #[test] -fn __bindgen_test_layout_mozilla_StyleShapeSource_open0_int_close0_instantiation( -) { +fn __bindgen_test_layout_mozilla_StyleShapeSource_open0_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!( - "Size of template specialization: ", - stringify!(mozilla_StyleShapeSource) - ) + ::std::mem::size_of:: < mozilla_StyleShapeSource > (), 8usize, + concat!("Size of template specialization: ", + stringify!(mozilla_StyleShapeSource)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(mozilla_StyleShapeSource) - ) + ::std::mem::align_of:: < mozilla_StyleShapeSource > (), 8usize, + concat!("Alignment of template specialization: ", + stringify!(mozilla_StyleShapeSource)) ); } diff --git a/bindgen-tests/tests/expectations/tests/typeref_1_0.rs b/bindgen-tests/tests/expectations/tests/typeref_1_0.rs index 8e4143c082..f552d13a07 100644 --- a/bindgen-tests/tests/expectations/tests/typeref_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/typeref_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -55,30 +49,20 @@ pub struct mozilla_FragmentOrURL { } #[test] fn bindgen_test_layout_mozilla_FragmentOrURL() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(mozilla_FragmentOrURL)) + ::std::mem::size_of:: < mozilla_FragmentOrURL > (), 1usize, concat!("Size of: ", + stringify!(mozilla_FragmentOrURL)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < mozilla_FragmentOrURL > (), 1usize, concat!("Alignment of ", stringify!(mozilla_FragmentOrURL)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mIsLocalRef) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(mozilla_FragmentOrURL), - "::", - stringify!(mIsLocalRef) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mIsLocalRef) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(mozilla_FragmentOrURL), "::", + stringify!(mIsLocalRef)) ); } impl Clone for mozilla_FragmentOrURL { @@ -94,14 +78,12 @@ pub struct mozilla_Position { #[test] fn bindgen_test_layout_mozilla_Position() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(mozilla_Position)) + ::std::mem::size_of:: < mozilla_Position > (), 1usize, concat!("Size of: ", + stringify!(mozilla_Position)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(mozilla_Position)) + ::std::mem::align_of:: < mozilla_Position > (), 1usize, concat!("Alignment of ", + stringify!(mozilla_Position)) ); } impl Clone for mozilla_Position { @@ -128,22 +110,17 @@ pub struct Bar { } #[test] fn bindgen_test_layout_Bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Bar)) + ::std::mem::size_of:: < Bar > (), 8usize, concat!("Size of: ", stringify!(Bar)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Bar)) + ::std::mem::align_of:: < Bar > (), 8usize, concat!("Alignment of ", + stringify!(Bar)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mFoo) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).mFoo) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(mFoo)) ); } @@ -168,28 +145,19 @@ pub struct nsFoo { } #[test] fn bindgen_test_layout_nsFoo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(nsFoo)) + ::std::mem::size_of:: < nsFoo > (), 8usize, concat!("Size of: ", + stringify!(nsFoo)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(nsFoo)) + ::std::mem::align_of:: < nsFoo > (), 8usize, concat!("Alignment of ", + stringify!(nsFoo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mBar) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsFoo), - "::", - stringify!(mBar) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mBar) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(nsFoo), "::", stringify!(mBar)) ); } impl Clone for nsFoo { @@ -198,22 +166,15 @@ impl Clone for nsFoo { } } #[test] -fn __bindgen_test_layout_mozilla_StyleShapeSource_open0_int_close0_instantiation( -) { +fn __bindgen_test_layout_mozilla_StyleShapeSource_open0_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!( - "Size of template specialization: ", - stringify!(mozilla_StyleShapeSource) - ) + ::std::mem::size_of:: < mozilla_StyleShapeSource > (), 8usize, + concat!("Size of template specialization: ", + stringify!(mozilla_StyleShapeSource)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(mozilla_StyleShapeSource) - ) + ::std::mem::align_of:: < mozilla_StyleShapeSource > (), 8usize, + concat!("Alignment of template specialization: ", + stringify!(mozilla_StyleShapeSource)) ); } diff --git a/bindgen-tests/tests/expectations/tests/underscore.rs b/bindgen-tests/tests/expectations/tests/underscore.rs index bfc05ac17a..c547cedef0 100644 --- a/bindgen-tests/tests/expectations/tests/underscore.rs +++ b/bindgen-tests/tests/expectations/tests/underscore.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const __: ::std::os::raw::c_int = 10; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -13,22 +7,18 @@ pub struct ptr_t { } #[test] fn bindgen_test_layout_ptr_t() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(ptr_t)) + ::std::mem::size_of:: < ptr_t > (), 8usize, concat!("Size of: ", + stringify!(ptr_t)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(ptr_t)) + ::std::mem::align_of:: < ptr_t > (), 1usize, concat!("Alignment of ", + stringify!(ptr_t)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).__) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).__) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(ptr_t), "::", stringify!(__)) ); } diff --git a/bindgen-tests/tests/expectations/tests/union-align.rs b/bindgen-tests/tests/expectations/tests/union-align.rs index 062ea97a86..7f74d16463 100644 --- a/bindgen-tests/tests/expectations/tests/union-align.rs +++ b/bindgen-tests/tests/expectations/tests/union-align.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[repr(align(16))] #[derive(Copy, Clone)] @@ -13,22 +7,17 @@ pub union Bar { } #[test] fn bindgen_test_layout_Bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(Bar)) + ::std::mem::size_of:: < Bar > (), 16usize, concat!("Size of: ", stringify!(Bar)) ); assert_eq!( - ::std::mem::align_of::(), - 16usize, - concat!("Alignment of ", stringify!(Bar)) + ::std::mem::align_of:: < Bar > (), 16usize, concat!("Alignment of ", + stringify!(Bar)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).foo) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(foo)) ); } @@ -49,22 +38,17 @@ pub union Baz { } #[test] fn bindgen_test_layout_Baz() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(Baz)) + ::std::mem::size_of:: < Baz > (), 16usize, concat!("Size of: ", stringify!(Baz)) ); assert_eq!( - ::std::mem::align_of::(), - 16usize, - concat!("Alignment of ", stringify!(Baz)) + ::std::mem::align_of:: < Baz > (), 16usize, concat!("Alignment of ", + stringify!(Baz)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Baz), "::", stringify!(bar)) ); } diff --git a/bindgen-tests/tests/expectations/tests/union-in-ns.rs b/bindgen-tests/tests/expectations/tests/union-in-ns.rs index 65f3f8f288..4d92466e66 100644 --- a/bindgen-tests/tests/expectations/tests/union-in-ns.rs +++ b/bindgen-tests/tests/expectations/tests/union-in-ns.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![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 { #[allow(unused_imports)] @@ -16,28 +10,19 @@ pub mod root { } #[test] fn bindgen_test_layout_bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(bar)) + ::std::mem::size_of:: < bar > (), 4usize, concat!("Size of: ", + stringify!(bar)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(bar)) + ::std::mem::align_of:: < bar > (), 4usize, concat!("Alignment of ", + stringify!(bar)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(baz) - ) + unsafe { ::std::ptr::addr_of!((* ptr).baz) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(bar), "::", stringify!(baz)) ); } impl Default for bar { diff --git a/bindgen-tests/tests/expectations/tests/union-in-ns_1_0.rs b/bindgen-tests/tests/expectations/tests/union-in-ns_1_0.rs index a057cc348a..27c148f353 100644 --- a/bindgen-tests/tests/expectations/tests/union-in-ns_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union-in-ns_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![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 { #[repr(C)] @@ -37,10 +31,7 @@ pub mod root { } impl ::std::marker::Copy for __BindgenUnionField {} impl ::std::fmt::Debug for __BindgenUnionField { - fn fmt( - &self, - fmt: &mut ::std::fmt::Formatter<'_>, - ) -> ::std::fmt::Result { + fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { fmt.write_str("__BindgenUnionField") } } @@ -63,28 +54,19 @@ pub mod root { } #[test] fn bindgen_test_layout_bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(bar)) + ::std::mem::size_of:: < bar > (), 4usize, concat!("Size of: ", + stringify!(bar)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(bar)) + ::std::mem::align_of:: < bar > (), 4usize, concat!("Alignment of ", + stringify!(bar)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(baz) - ) + unsafe { ::std::ptr::addr_of!((* ptr).baz) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(bar), "::", stringify!(baz)) ); } impl Clone for bar { diff --git a/bindgen-tests/tests/expectations/tests/union_bitfield.rs b/bindgen-tests/tests/expectations/tests/union_bitfield.rs index 9e07a1dfcd..a38fb325ce 100644 --- a/bindgen-tests/tests/expectations/tests/union_bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/union_bitfield.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -101,14 +93,11 @@ pub union U4 { #[test] fn bindgen_test_layout_U4() { assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(U4)) + ::std::mem::size_of:: < U4 > (), 4usize, concat!("Size of: ", stringify!(U4)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(U4)) + ::std::mem::align_of:: < U4 > (), 4usize, concat!("Alignment of ", + stringify!(U4)) ); } impl Default for U4 { @@ -123,9 +112,7 @@ impl Default for U4 { impl U4 { #[inline] pub fn derp(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u32) } } #[inline] pub fn set_derp(&mut self, val: ::std::os::raw::c_uint) { @@ -138,12 +125,16 @@ impl U4 { pub fn new_bitfield_1( derp: ::std::os::raw::c_uint, ) -> __BindgenBitfieldUnit<[u8; 1usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 1u8, { - let derp: u32 = unsafe { ::std::mem::transmute(derp) }; - derp as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let derp: u32 = unsafe { ::std::mem::transmute(derp) }; + derp as u64 + }, + ); __bindgen_bitfield_unit } } @@ -157,14 +148,10 @@ pub union B { #[test] fn bindgen_test_layout_B() { assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(B)) + ::std::mem::size_of:: < B > (), 4usize, concat!("Size of: ", stringify!(B)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(B)) + ::std::mem::align_of:: < B > (), 4usize, concat!("Alignment of ", stringify!(B)) ); } impl Default for B { @@ -179,9 +166,7 @@ impl Default for B { impl B { #[inline] pub fn foo(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 31u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 31u8) as u32) } } #[inline] pub fn set_foo(&mut self, val: ::std::os::raw::c_uint) { @@ -192,9 +177,7 @@ impl B { } #[inline] pub fn bar(&self) -> ::std::os::raw::c_uchar { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(31usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(31usize, 1u8) as u8) } } #[inline] pub fn set_bar(&mut self, val: ::std::os::raw::c_uchar) { @@ -208,16 +191,25 @@ impl B { foo: ::std::os::raw::c_uint, bar: ::std::os::raw::c_uchar, ) -> __BindgenBitfieldUnit<[u8; 4usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 31u8, { - let foo: u32 = unsafe { ::std::mem::transmute(foo) }; - foo as u64 - }); - __bindgen_bitfield_unit.set(31usize, 1u8, { - let bar: u8 = unsafe { ::std::mem::transmute(bar) }; - bar as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 31u8, + { + let foo: u32 = unsafe { ::std::mem::transmute(foo) }; + foo as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 31usize, + 1u8, + { + let bar: u8 = unsafe { ::std::mem::transmute(bar) }; + bar as u64 + }, + ); __bindgen_bitfield_unit } } diff --git a/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs b/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs index 2227746849..f67b6a87ac 100644 --- a/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -144,14 +136,11 @@ pub struct U4 { #[test] fn bindgen_test_layout_U4() { assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(U4)) + ::std::mem::size_of:: < U4 > (), 4usize, concat!("Size of: ", stringify!(U4)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(U4)) + ::std::mem::align_of:: < U4 > (), 4usize, concat!("Alignment of ", + stringify!(U4)) ); } impl Clone for U4 { @@ -163,9 +152,7 @@ impl U4 { #[inline] pub fn derp(&self) -> ::std::os::raw::c_uint { unsafe { - ::std::mem::transmute( - self._bitfield_1.as_ref().get(0usize, 1u8) as u32 - ) + ::std::mem::transmute(self._bitfield_1.as_ref().get(0usize, 1u8) as u32) } } #[inline] @@ -179,12 +166,16 @@ impl U4 { pub fn new_bitfield_1( derp: ::std::os::raw::c_uint, ) -> __BindgenBitfieldUnit<[u8; 1usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 1u8, { - let derp: u32 = unsafe { ::std::mem::transmute(derp) }; - derp as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let derp: u32 = unsafe { ::std::mem::transmute(derp) }; + derp as u64 + }, + ); __bindgen_bitfield_unit } } @@ -198,14 +189,10 @@ pub struct B { #[test] fn bindgen_test_layout_B() { assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(B)) + ::std::mem::size_of:: < B > (), 4usize, concat!("Size of: ", stringify!(B)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(B)) + ::std::mem::align_of:: < B > (), 4usize, concat!("Alignment of ", stringify!(B)) ); } impl Clone for B { @@ -217,9 +204,7 @@ impl B { #[inline] pub fn foo(&self) -> ::std::os::raw::c_uint { unsafe { - ::std::mem::transmute( - self._bitfield_1.as_ref().get(0usize, 31u8) as u32 - ) + ::std::mem::transmute(self._bitfield_1.as_ref().get(0usize, 31u8) as u32) } } #[inline] @@ -232,9 +217,7 @@ impl B { #[inline] pub fn bar(&self) -> ::std::os::raw::c_uchar { unsafe { - ::std::mem::transmute( - self._bitfield_1.as_ref().get(31usize, 1u8) as u8 - ) + ::std::mem::transmute(self._bitfield_1.as_ref().get(31usize, 1u8) as u8) } } #[inline] @@ -249,16 +232,25 @@ impl B { foo: ::std::os::raw::c_uint, bar: ::std::os::raw::c_uchar, ) -> __BindgenBitfieldUnit<[u8; 4usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 31u8, { - let foo: u32 = unsafe { ::std::mem::transmute(foo) }; - foo as u64 - }); - __bindgen_bitfield_unit.set(31usize, 1u8, { - let bar: u8 = unsafe { ::std::mem::transmute(bar) }; - bar as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 31u8, + { + let foo: u32 = unsafe { ::std::mem::transmute(foo) }; + foo as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 31usize, + 1u8, + { + let bar: u8 = unsafe { ::std::mem::transmute(bar) }; + bar as u64 + }, + ); __bindgen_bitfield_unit } } @@ -272,9 +264,8 @@ pub struct HasBigBitfield { #[test] fn bindgen_test_layout_HasBigBitfield() { assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(HasBigBitfield)) + ::std::mem::size_of:: < HasBigBitfield > (), 16usize, concat!("Size of: ", + stringify!(HasBigBitfield)) ); } impl Clone for HasBigBitfield { diff --git a/bindgen-tests/tests/expectations/tests/union_dtor.rs b/bindgen-tests/tests/expectations/tests/union_dtor.rs index 085e5ca30a..b37891017c 100644 --- a/bindgen-tests/tests/expectations/tests/union_dtor.rs +++ b/bindgen-tests/tests/expectations/tests/union_dtor.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub union UnionWithDtor { pub mFoo: ::std::os::raw::c_int, @@ -12,38 +6,23 @@ pub union UnionWithDtor { } #[test] fn bindgen_test_layout_UnionWithDtor() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(UnionWithDtor)) + ::std::mem::size_of:: < UnionWithDtor > (), 8usize, concat!("Size of: ", + stringify!(UnionWithDtor)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(UnionWithDtor)) + ::std::mem::align_of:: < UnionWithDtor > (), 8usize, concat!("Alignment of ", + stringify!(UnionWithDtor)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mFoo) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(UnionWithDtor), - "::", - stringify!(mFoo) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mFoo) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(UnionWithDtor), "::", stringify!(mFoo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mBar) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(UnionWithDtor), - "::", - stringify!(mBar) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mBar) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(UnionWithDtor), "::", stringify!(mBar)) ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/union_dtor_1_0.rs b/bindgen-tests/tests/expectations/tests/union_dtor_1_0.rs index 67455aa8b8..5039947a4f 100644 --- a/bindgen-tests/tests/expectations/tests/union_dtor_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_dtor_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -57,38 +51,23 @@ pub struct UnionWithDtor { } #[test] fn bindgen_test_layout_UnionWithDtor() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(UnionWithDtor)) + ::std::mem::size_of:: < UnionWithDtor > (), 8usize, concat!("Size of: ", + stringify!(UnionWithDtor)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(UnionWithDtor)) + ::std::mem::align_of:: < UnionWithDtor > (), 8usize, concat!("Alignment of ", + stringify!(UnionWithDtor)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mFoo) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(UnionWithDtor), - "::", - stringify!(mFoo) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mFoo) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(UnionWithDtor), "::", stringify!(mFoo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mBar) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(UnionWithDtor), - "::", - stringify!(mBar) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mBar) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(UnionWithDtor), "::", stringify!(mBar)) ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/union_fields.rs b/bindgen-tests/tests/expectations/tests/union_fields.rs index 9135ca3c6c..ab0b9bff40 100644 --- a/bindgen-tests/tests/expectations/tests/union_fields.rs +++ b/bindgen-tests/tests/expectations/tests/union_fields.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone)] pub union nsStyleUnion { @@ -14,50 +8,28 @@ pub union nsStyleUnion { } #[test] fn bindgen_test_layout_nsStyleUnion() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(nsStyleUnion)) + ::std::mem::size_of:: < nsStyleUnion > (), 8usize, concat!("Size of: ", + stringify!(nsStyleUnion)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(nsStyleUnion)) + ::std::mem::align_of:: < nsStyleUnion > (), 8usize, concat!("Alignment of ", + stringify!(nsStyleUnion)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mInt) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsStyleUnion), - "::", - stringify!(mInt) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mInt) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(nsStyleUnion), "::", stringify!(mInt)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mFloat) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsStyleUnion), - "::", - stringify!(mFloat) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mFloat) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(nsStyleUnion), "::", stringify!(mFloat)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mPointer) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsStyleUnion), - "::", - stringify!(mPointer) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mPointer) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(nsStyleUnion), "::", + stringify!(mPointer)) ); } impl Default for nsStyleUnion { diff --git a/bindgen-tests/tests/expectations/tests/union_fields_1_0.rs b/bindgen-tests/tests/expectations/tests/union_fields_1_0.rs index b5f94bcd05..2e41c103e8 100644 --- a/bindgen-tests/tests/expectations/tests/union_fields_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_fields_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -58,50 +52,28 @@ pub struct nsStyleUnion { } #[test] fn bindgen_test_layout_nsStyleUnion() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(nsStyleUnion)) + ::std::mem::size_of:: < nsStyleUnion > (), 8usize, concat!("Size of: ", + stringify!(nsStyleUnion)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(nsStyleUnion)) + ::std::mem::align_of:: < nsStyleUnion > (), 8usize, concat!("Alignment of ", + stringify!(nsStyleUnion)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mInt) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsStyleUnion), - "::", - stringify!(mInt) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mInt) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(nsStyleUnion), "::", stringify!(mInt)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mFloat) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsStyleUnion), - "::", - stringify!(mFloat) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mFloat) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(nsStyleUnion), "::", stringify!(mFloat)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mPointer) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsStyleUnion), - "::", - stringify!(mPointer) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mPointer) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(nsStyleUnion), "::", + stringify!(mPointer)) ); } impl Clone for nsStyleUnion { diff --git a/bindgen-tests/tests/expectations/tests/union_template.rs b/bindgen-tests/tests/expectations/tests/union_template.rs index 9c3d7a07eb..62019e6dd7 100644 --- a/bindgen-tests/tests/expectations/tests/union_template.rs +++ b/bindgen-tests/tests/expectations/tests/union_template.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct NastyStruct { pub mIsSome: bool, diff --git a/bindgen-tests/tests/expectations/tests/union_template_1_0.rs b/bindgen-tests/tests/expectations/tests/union_template_1_0.rs index 487579f7e5..3d8d90b8cb 100644 --- a/bindgen-tests/tests/expectations/tests/union_template_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_template_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_struct.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_struct.rs index 35b5829beb..ef03a830fe 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_struct.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_struct.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone)] pub union foo { @@ -18,58 +12,38 @@ pub struct foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)) + ::std::mem::size_of:: < foo__bindgen_ty_1 > (), 8usize, concat!("Size of: ", + stringify!(foo__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) + ::std::mem::align_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", + stringify!(foo__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)) ); } #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of:: < foo > (), 8usize, concat!("Size of: ", stringify!(foo)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) + ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", + stringify!(foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); } diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_1_0.rs index 8b11e75796..a4beed5199 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -62,38 +56,23 @@ pub struct foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)) + ::std::mem::size_of:: < foo__bindgen_ty_1 > (), 8usize, concat!("Size of: ", + stringify!(foo__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) + ::std::mem::align_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", + stringify!(foo__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)) ); } impl Clone for foo__bindgen_ty_1 { @@ -103,22 +82,17 @@ impl Clone for foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of:: < foo > (), 8usize, concat!("Size of: ", stringify!(foo)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) + ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", + stringify!(foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); } diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield.rs index e81b3bef50..649fdfc2cb 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -107,22 +99,18 @@ pub struct foo__bindgen_ty_1 { #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)) + ::std::mem::size_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Size of: ", + stringify!(foo__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) + ::std::mem::align_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", + stringify!(foo__bindgen_ty_1)) ); } impl foo__bindgen_ty_1 { #[inline] pub fn b(&self) -> ::std::os::raw::c_int { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 7u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 7u8) as u32) } } #[inline] pub fn set_b(&mut self, val: ::std::os::raw::c_int) { @@ -133,9 +121,7 @@ impl foo__bindgen_ty_1 { } #[inline] pub fn c(&self) -> ::std::os::raw::c_int { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(7usize, 25u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(7usize, 25u8) as u32) } } #[inline] pub fn set_c(&mut self, val: ::std::os::raw::c_int) { @@ -149,37 +135,41 @@ impl foo__bindgen_ty_1 { b: ::std::os::raw::c_int, c: ::std::os::raw::c_int, ) -> __BindgenBitfieldUnit<[u8; 4usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 7u8, { - let b: u32 = unsafe { ::std::mem::transmute(b) }; - b as u64 - }); - __bindgen_bitfield_unit.set(7usize, 25u8, { - let c: u32 = unsafe { ::std::mem::transmute(c) }; - c as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 7u8, + { + let b: u32 = unsafe { ::std::mem::transmute(b) }; + b as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 7usize, + 25u8, + { + let c: u32 = unsafe { ::std::mem::transmute(c) }; + c as u64 + }, + ); __bindgen_bitfield_unit } } #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of:: < foo > (), 4usize, concat!("Size of: ", stringify!(foo)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) + ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", + stringify!(foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) ); } diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs index 6ce6ed2282..02df95b5e8 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -151,14 +143,12 @@ pub struct foo__bindgen_ty_1 { #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)) + ::std::mem::size_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Size of: ", + stringify!(foo__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) + ::std::mem::align_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", + stringify!(foo__bindgen_ty_1)) ); } impl Clone for foo__bindgen_ty_1 { @@ -169,9 +159,7 @@ impl Clone for foo__bindgen_ty_1 { impl foo__bindgen_ty_1 { #[inline] pub fn b(&self) -> ::std::os::raw::c_int { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 7u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 7u8) as u32) } } #[inline] pub fn set_b(&mut self, val: ::std::os::raw::c_int) { @@ -182,9 +170,7 @@ impl foo__bindgen_ty_1 { } #[inline] pub fn c(&self) -> ::std::os::raw::c_int { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(7usize, 25u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(7usize, 25u8) as u32) } } #[inline] pub fn set_c(&mut self, val: ::std::os::raw::c_int) { @@ -198,37 +184,41 @@ impl foo__bindgen_ty_1 { b: ::std::os::raw::c_int, c: ::std::os::raw::c_int, ) -> __BindgenBitfieldUnit<[u8; 4usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 7u8, { - let b: u32 = unsafe { ::std::mem::transmute(b) }; - b as u64 - }); - __bindgen_bitfield_unit.set(7usize, 25u8, { - let c: u32 = unsafe { ::std::mem::transmute(c) }; - c as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 7u8, + { + let b: u32 = unsafe { ::std::mem::transmute(b) }; + b as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 7usize, + 25u8, + { + let c: u32 = unsafe { ::std::mem::transmute(c) }; + c as u64 + }, + ); __bindgen_bitfield_unit } } #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of:: < foo > (), 4usize, concat!("Size of: ", stringify!(foo)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) + ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", + stringify!(foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) ); } diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_union.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_union.rs index 487650bfe4..ce74a6f03d 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_union.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_union.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone)] pub union foo { @@ -18,38 +12,23 @@ pub union foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)) + ::std::mem::size_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Size of: ", + stringify!(foo__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) + ::std::mem::align_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", + stringify!(foo__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)) ); } impl Default for foo__bindgen_ty_1 { @@ -63,22 +42,17 @@ impl Default for foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of:: < foo > (), 4usize, concat!("Size of: ", stringify!(foo)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) + ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", + stringify!(foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); } diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_union_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_union_1_0.rs index f3e4b84003..1cafbe7144 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_union_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -63,38 +57,23 @@ pub struct foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)) + ::std::mem::size_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Size of: ", + stringify!(foo__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) + ::std::mem::align_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", + stringify!(foo__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)) ); } impl Clone for foo__bindgen_ty_1 { @@ -104,22 +83,17 @@ impl Clone for foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of:: < foo > (), 4usize, concat!("Size of: ", stringify!(foo)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) + ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", + stringify!(foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); } diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct.rs index cff5df0472..bd158c8793 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone)] pub union pixel { @@ -21,84 +15,52 @@ pub struct pixel__bindgen_ty_1 { } #[test] fn bindgen_test_layout_pixel__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(pixel__bindgen_ty_1)) + ::std::mem::size_of:: < pixel__bindgen_ty_1 > (), 4usize, concat!("Size of: ", + stringify!(pixel__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < pixel__bindgen_ty_1 > (), 1usize, concat!("Alignment of ", stringify!(pixel__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).r) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(pixel__bindgen_ty_1), - "::", - stringify!(r) - ) + unsafe { ::std::ptr::addr_of!((* ptr).r) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(pixel__bindgen_ty_1), "::", + stringify!(r)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).g) as usize - ptr as usize }, - 1usize, - concat!( - "Offset of field: ", - stringify!(pixel__bindgen_ty_1), - "::", - stringify!(g) - ) + unsafe { ::std::ptr::addr_of!((* ptr).g) as usize - ptr as usize }, 1usize, + concat!("Offset of field: ", stringify!(pixel__bindgen_ty_1), "::", + stringify!(g)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(pixel__bindgen_ty_1), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 2usize, + concat!("Offset of field: ", stringify!(pixel__bindgen_ty_1), "::", + stringify!(b)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 3usize, - concat!( - "Offset of field: ", - stringify!(pixel__bindgen_ty_1), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 3usize, + concat!("Offset of field: ", stringify!(pixel__bindgen_ty_1), "::", + stringify!(a)) ); } #[test] fn bindgen_test_layout_pixel() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(pixel)) + ::std::mem::size_of:: < pixel > (), 4usize, concat!("Size of: ", + stringify!(pixel)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(pixel)) + ::std::mem::align_of:: < pixel > (), 4usize, concat!("Alignment of ", + stringify!(pixel)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).rgba) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(pixel), - "::", - stringify!(rgba) - ) + unsafe { ::std::ptr::addr_of!((* ptr).rgba) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(pixel), "::", stringify!(rgba)) ); } impl Default for pixel { diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs index 1562a8c971..80c38abde1 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -65,58 +59,35 @@ pub struct pixel__bindgen_ty_1 { } #[test] fn bindgen_test_layout_pixel__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(pixel__bindgen_ty_1)) + ::std::mem::size_of:: < pixel__bindgen_ty_1 > (), 4usize, concat!("Size of: ", + stringify!(pixel__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < pixel__bindgen_ty_1 > (), 1usize, concat!("Alignment of ", stringify!(pixel__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).r) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(pixel__bindgen_ty_1), - "::", - stringify!(r) - ) + unsafe { ::std::ptr::addr_of!((* ptr).r) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(pixel__bindgen_ty_1), "::", + stringify!(r)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).g) as usize - ptr as usize }, - 1usize, - concat!( - "Offset of field: ", - stringify!(pixel__bindgen_ty_1), - "::", - stringify!(g) - ) + unsafe { ::std::ptr::addr_of!((* ptr).g) as usize - ptr as usize }, 1usize, + concat!("Offset of field: ", stringify!(pixel__bindgen_ty_1), "::", + stringify!(g)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(pixel__bindgen_ty_1), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 2usize, + concat!("Offset of field: ", stringify!(pixel__bindgen_ty_1), "::", + stringify!(b)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 3usize, - concat!( - "Offset of field: ", - stringify!(pixel__bindgen_ty_1), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 3usize, + concat!("Offset of field: ", stringify!(pixel__bindgen_ty_1), "::", + stringify!(a)) ); } impl Clone for pixel__bindgen_ty_1 { @@ -126,28 +97,19 @@ impl Clone for pixel__bindgen_ty_1 { } #[test] fn bindgen_test_layout_pixel() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(pixel)) + ::std::mem::size_of:: < pixel > (), 4usize, concat!("Size of: ", + stringify!(pixel)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(pixel)) + ::std::mem::align_of:: < pixel > (), 4usize, concat!("Alignment of ", + stringify!(pixel)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).rgba) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(pixel), - "::", - stringify!(rgba) - ) + unsafe { ::std::ptr::addr_of!((* ptr).rgba) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(pixel), "::", stringify!(rgba)) ); } impl Clone for pixel { diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union.rs index f1abfc5a25..a3b0f72e6c 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone)] pub union foo { @@ -19,38 +13,23 @@ pub union foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 2usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)) + ::std::mem::size_of:: < foo__bindgen_ty_1 > (), 2usize, concat!("Size of: ", + stringify!(foo__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) + ::std::mem::align_of:: < foo__bindgen_ty_1 > (), 2usize, concat!("Alignment of ", + stringify!(foo__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(c) - ) + unsafe { ::std::ptr::addr_of!((* ptr).c) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(c)) ); } impl Default for foo__bindgen_ty_1 { @@ -64,22 +43,17 @@ impl Default for foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of:: < foo > (), 4usize, concat!("Size of: ", stringify!(foo)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) + ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", + stringify!(foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) ); } diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs index 197a6bbfbc..59887dc900 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -64,38 +58,23 @@ pub struct foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 2usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)) + ::std::mem::size_of:: < foo__bindgen_ty_1 > (), 2usize, concat!("Size of: ", + stringify!(foo__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) + ::std::mem::align_of:: < foo__bindgen_ty_1 > (), 2usize, concat!("Alignment of ", + stringify!(foo__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1), - "::", - stringify!(c) - ) + unsafe { ::std::ptr::addr_of!((* ptr).c) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(c)) ); } impl Clone for foo__bindgen_ty_1 { @@ -105,22 +84,17 @@ impl Clone for foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of:: < foo > (), 4usize, concat!("Size of: ", stringify!(foo)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) + ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", + stringify!(foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) ); } diff --git a/bindgen-tests/tests/expectations/tests/union_with_big_member.rs b/bindgen-tests/tests/expectations/tests/union_with_big_member.rs index 7110257bc7..4d5461809d 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_big_member.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_big_member.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone)] pub union WithBigArray { @@ -13,38 +7,23 @@ pub union WithBigArray { } #[test] fn bindgen_test_layout_WithBigArray() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 132usize, - concat!("Size of: ", stringify!(WithBigArray)) + ::std::mem::size_of:: < WithBigArray > (), 132usize, concat!("Size of: ", + stringify!(WithBigArray)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithBigArray)) + ::std::mem::align_of:: < WithBigArray > (), 4usize, concat!("Alignment of ", + stringify!(WithBigArray)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigArray), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(WithBigArray), "::", stringify!(a)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigArray), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(WithBigArray), "::", stringify!(b)) ); } impl Default for WithBigArray { @@ -64,38 +43,23 @@ pub union WithBigArray2 { } #[test] fn bindgen_test_layout_WithBigArray2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 36usize, - concat!("Size of: ", stringify!(WithBigArray2)) + ::std::mem::size_of:: < WithBigArray2 > (), 36usize, concat!("Size of: ", + stringify!(WithBigArray2)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithBigArray2)) + ::std::mem::align_of:: < WithBigArray2 > (), 4usize, concat!("Alignment of ", + stringify!(WithBigArray2)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigArray2), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(WithBigArray2), "::", stringify!(a)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigArray2), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(WithBigArray2), "::", stringify!(b)) ); } impl Default for WithBigArray2 { @@ -115,38 +79,23 @@ pub union WithBigMember { } #[test] fn bindgen_test_layout_WithBigMember() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 132usize, - concat!("Size of: ", stringify!(WithBigMember)) + ::std::mem::size_of:: < WithBigMember > (), 132usize, concat!("Size of: ", + stringify!(WithBigMember)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithBigMember)) + ::std::mem::align_of:: < WithBigMember > (), 4usize, concat!("Alignment of ", + stringify!(WithBigMember)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigMember), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(WithBigMember), "::", stringify!(a)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigMember), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(WithBigMember), "::", stringify!(b)) ); } impl Default for WithBigMember { diff --git a/bindgen-tests/tests/expectations/tests/union_with_big_member_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_big_member_1_0.rs index 63b43baa82..0e192d4898 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_big_member_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_big_member_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -57,38 +51,23 @@ pub struct WithBigArray { } #[test] fn bindgen_test_layout_WithBigArray() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 132usize, - concat!("Size of: ", stringify!(WithBigArray)) + ::std::mem::size_of:: < WithBigArray > (), 132usize, concat!("Size of: ", + stringify!(WithBigArray)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithBigArray)) + ::std::mem::align_of:: < WithBigArray > (), 4usize, concat!("Alignment of ", + stringify!(WithBigArray)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigArray), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(WithBigArray), "::", stringify!(a)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigArray), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(WithBigArray), "::", stringify!(b)) ); } impl Clone for WithBigArray { @@ -114,38 +93,23 @@ pub struct WithBigArray2 { } #[test] fn bindgen_test_layout_WithBigArray2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 36usize, - concat!("Size of: ", stringify!(WithBigArray2)) + ::std::mem::size_of:: < WithBigArray2 > (), 36usize, concat!("Size of: ", + stringify!(WithBigArray2)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithBigArray2)) + ::std::mem::align_of:: < WithBigArray2 > (), 4usize, concat!("Alignment of ", + stringify!(WithBigArray2)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigArray2), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(WithBigArray2), "::", stringify!(a)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigArray2), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(WithBigArray2), "::", stringify!(b)) ); } impl Clone for WithBigArray2 { @@ -162,38 +126,23 @@ pub struct WithBigMember { } #[test] fn bindgen_test_layout_WithBigMember() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 132usize, - concat!("Size of: ", stringify!(WithBigMember)) + ::std::mem::size_of:: < WithBigMember > (), 132usize, concat!("Size of: ", + stringify!(WithBigMember)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithBigMember)) + ::std::mem::align_of:: < WithBigMember > (), 4usize, concat!("Alignment of ", + stringify!(WithBigMember)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigMember), - "::", - stringify!(a) - ) + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(WithBigMember), "::", stringify!(a)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBigMember), - "::", - stringify!(b) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(WithBigMember), "::", stringify!(b)) ); } impl Clone for WithBigMember { diff --git a/bindgen-tests/tests/expectations/tests/union_with_nesting.rs b/bindgen-tests/tests/expectations/tests/union_with_nesting.rs index ec9c148011..1feafebe73 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_nesting.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_nesting.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone)] pub union foo { @@ -25,38 +19,25 @@ pub union foo__bindgen_ty_1__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 2usize, + ::std::mem::size_of:: < foo__bindgen_ty_1__bindgen_ty_1 > (), 2usize, concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 2usize, + ::std::mem::align_of:: < foo__bindgen_ty_1__bindgen_ty_1 > (), 2usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b1) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(b1) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b1) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1__bindgen_ty_1), "::", + stringify!(b1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b2) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(b2) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b2) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1__bindgen_ty_1), "::", + stringify!(b2)) ); } impl Default for foo__bindgen_ty_1__bindgen_ty_1 { @@ -76,38 +57,25 @@ pub union foo__bindgen_ty_1__bindgen_ty_2 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 2usize, + ::std::mem::size_of:: < foo__bindgen_ty_1__bindgen_ty_2 > (), 2usize, concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)) ); assert_eq!( - ::std::mem::align_of::(), - 2usize, + ::std::mem::align_of:: < foo__bindgen_ty_1__bindgen_ty_2 > (), 2usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c1) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(c1) - ) + unsafe { ::std::ptr::addr_of!((* ptr).c1) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2), "::", + stringify!(c1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c2) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(c2) - ) + unsafe { ::std::ptr::addr_of!((* ptr).c2) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2), "::", + stringify!(c2)) ); } impl Default for foo__bindgen_ty_1__bindgen_ty_2 { @@ -122,14 +90,12 @@ impl Default for foo__bindgen_ty_1__bindgen_ty_2 { #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)) + ::std::mem::size_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Size of: ", + stringify!(foo__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) + ::std::mem::align_of:: < foo__bindgen_ty_1 > (), 2usize, concat!("Alignment of ", + stringify!(foo__bindgen_ty_1)) ); } impl Default for foo__bindgen_ty_1 { @@ -143,22 +109,17 @@ impl Default for foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of:: < foo > (), 4usize, concat!("Size of: ", stringify!(foo)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) + ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", + stringify!(foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) ); } diff --git a/bindgen-tests/tests/expectations/tests/union_with_nesting_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_nesting_1_0.rs index a1e452fe03..9dc42f3eaa 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_nesting_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_nesting_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -70,38 +64,25 @@ pub struct foo__bindgen_ty_1__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 2usize, + ::std::mem::size_of:: < foo__bindgen_ty_1__bindgen_ty_1 > (), 2usize, concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 2usize, + ::std::mem::align_of:: < foo__bindgen_ty_1__bindgen_ty_1 > (), 2usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b1) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(b1) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b1) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1__bindgen_ty_1), "::", + stringify!(b1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b2) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(b2) - ) + unsafe { ::std::ptr::addr_of!((* ptr).b2) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1__bindgen_ty_1), "::", + stringify!(b2)) ); } impl Clone for foo__bindgen_ty_1__bindgen_ty_1 { @@ -118,38 +99,25 @@ pub struct foo__bindgen_ty_1__bindgen_ty_2 { } #[test] fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 2usize, + ::std::mem::size_of:: < foo__bindgen_ty_1__bindgen_ty_2 > (), 2usize, concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)) ); assert_eq!( - ::std::mem::align_of::(), - 2usize, + ::std::mem::align_of:: < foo__bindgen_ty_1__bindgen_ty_2 > (), 2usize, concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c1) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(c1) - ) + unsafe { ::std::ptr::addr_of!((* ptr).c1) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2), "::", + stringify!(c1)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c2) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(c2) - ) + unsafe { ::std::ptr::addr_of!((* ptr).c2) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2), "::", + stringify!(c2)) ); } impl Clone for foo__bindgen_ty_1__bindgen_ty_2 { @@ -160,14 +128,12 @@ impl Clone for foo__bindgen_ty_1__bindgen_ty_2 { #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)) + ::std::mem::size_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Size of: ", + stringify!(foo__bindgen_ty_1)) ); assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)) + ::std::mem::align_of:: < foo__bindgen_ty_1 > (), 2usize, concat!("Alignment of ", + stringify!(foo__bindgen_ty_1)) ); } impl Clone for foo__bindgen_ty_1 { @@ -177,22 +143,17 @@ impl Clone for foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of:: < foo > (), 4usize, concat!("Size of: ", stringify!(foo)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)) + ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", + stringify!(foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) ); } diff --git a/bindgen-tests/tests/expectations/tests/union_with_non_copy_member.rs b/bindgen-tests/tests/expectations/tests/union_with_non_copy_member.rs index 3c500b2106..2c7789128e 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_non_copy_member.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_non_copy_member.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -55,28 +49,19 @@ pub struct NonCopyType { } #[test] fn bindgen_test_layout_NonCopyType() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(NonCopyType)) + ::std::mem::size_of:: < NonCopyType > (), 4usize, concat!("Size of: ", + stringify!(NonCopyType)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(NonCopyType)) + ::std::mem::align_of:: < NonCopyType > (), 4usize, concat!("Alignment of ", + stringify!(NonCopyType)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NonCopyType), - "::", - stringify!(foo) - ) + unsafe { ::std::ptr::addr_of!((* ptr).foo) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(NonCopyType), "::", stringify!(foo)) ); } #[repr(C)] @@ -87,40 +72,25 @@ pub struct WithBindgenGeneratedWrapper { } #[test] fn bindgen_test_layout_WithBindgenGeneratedWrapper() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, + ::std::mem::size_of:: < WithBindgenGeneratedWrapper > (), 4usize, concat!("Size of: ", stringify!(WithBindgenGeneratedWrapper)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < WithBindgenGeneratedWrapper > (), 4usize, concat!("Alignment of ", stringify!(WithBindgenGeneratedWrapper)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).non_copy_type) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBindgenGeneratedWrapper), - "::", - stringify!(non_copy_type) - ) + unsafe { ::std::ptr::addr_of!((* ptr).non_copy_type) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(WithBindgenGeneratedWrapper), + "::", stringify!(non_copy_type)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBindgenGeneratedWrapper), - "::", - stringify!(bar) - ) + unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(WithBindgenGeneratedWrapper), "::", + stringify!(bar)) ); } impl Default for WithBindgenGeneratedWrapper { @@ -139,40 +109,24 @@ pub union WithManuallyDrop { } #[test] fn bindgen_test_layout_WithManuallyDrop() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(WithManuallyDrop)) + ::std::mem::size_of:: < WithManuallyDrop > (), 4usize, concat!("Size of: ", + stringify!(WithManuallyDrop)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithManuallyDrop)) + ::std::mem::align_of:: < WithManuallyDrop > (), 4usize, concat!("Alignment of ", + stringify!(WithManuallyDrop)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).non_copy_type) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithManuallyDrop), - "::", - stringify!(non_copy_type) - ) + unsafe { ::std::ptr::addr_of!((* ptr).non_copy_type) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(WithManuallyDrop), "::", + stringify!(non_copy_type)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithManuallyDrop), - "::", - stringify!(bar) - ) + unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(WithManuallyDrop), "::", stringify!(bar)) ); } impl Default for WithManuallyDrop { @@ -192,40 +146,25 @@ pub struct WithDefaultWrapper { } #[test] fn bindgen_test_layout_WithDefaultWrapper() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(WithDefaultWrapper)) + ::std::mem::size_of:: < WithDefaultWrapper > (), 4usize, concat!("Size of: ", + stringify!(WithDefaultWrapper)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, + ::std::mem::align_of:: < WithDefaultWrapper > (), 4usize, concat!("Alignment of ", stringify!(WithDefaultWrapper)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).non_copy_type) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithDefaultWrapper), - "::", - stringify!(non_copy_type) - ) + unsafe { ::std::ptr::addr_of!((* ptr).non_copy_type) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(WithDefaultWrapper), "::", + stringify!(non_copy_type)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithDefaultWrapper), - "::", - stringify!(bar) - ) + unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(WithDefaultWrapper), "::", + stringify!(bar)) ); } impl Default for WithDefaultWrapper { diff --git a/bindgen-tests/tests/expectations/tests/unknown_attr.rs b/bindgen-tests/tests/expectations/tests/unknown_attr.rs index c790f009c9..3233800101 100644 --- a/bindgen-tests/tests/expectations/tests/unknown_attr.rs +++ b/bindgen-tests/tests/expectations/tests/unknown_attr.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[repr(align(16))] #[derive(Debug, Default, Copy, Clone)] @@ -15,43 +9,24 @@ pub struct max_align_t { } #[test] fn bindgen_test_layout_max_align_t() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 32usize, - concat!("Size of: ", stringify!(max_align_t)) + ::std::mem::size_of:: < max_align_t > (), 32usize, concat!("Size of: ", + stringify!(max_align_t)) ); assert_eq!( - ::std::mem::align_of::(), - 16usize, - concat!("Alignment of ", stringify!(max_align_t)) + ::std::mem::align_of:: < max_align_t > (), 16usize, concat!("Alignment of ", + stringify!(max_align_t)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).__clang_max_align_nonce1) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(max_align_t), - "::", - stringify!(__clang_max_align_nonce1) - ) + unsafe { ::std::ptr::addr_of!((* ptr).__clang_max_align_nonce1) as usize - ptr as + usize }, 0usize, concat!("Offset of field: ", stringify!(max_align_t), "::", + stringify!(__clang_max_align_nonce1)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).__clang_max_align_nonce2) as usize - - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(max_align_t), - "::", - stringify!(__clang_max_align_nonce2) - ) + unsafe { ::std::ptr::addr_of!((* ptr).__clang_max_align_nonce2) as usize - ptr as + usize }, 16usize, concat!("Offset of field: ", stringify!(max_align_t), "::", + stringify!(__clang_max_align_nonce2)) ); } diff --git a/bindgen-tests/tests/expectations/tests/unsorted-items.rs b/bindgen-tests/tests/expectations/tests/unsorted-items.rs index ce0c5f3f66..0ba9d89491 100644 --- a/bindgen-tests/tests/expectations/tests/unsorted-items.rs +++ b/bindgen-tests/tests/expectations/tests/unsorted-items.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub fn foo() -> ::std::os::raw::c_int; } @@ -20,27 +14,22 @@ pub struct Point { } #[test] fn bindgen_test_layout_Point() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Point)) + ::std::mem::size_of:: < Point > (), 8usize, concat!("Size of: ", + stringify!(Point)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Point)) + ::std::mem::align_of:: < Point > (), 4usize, concat!("Alignment of ", + stringify!(Point)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).x) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Point), "::", stringify!(x)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, - 4usize, + unsafe { ::std::ptr::addr_of!((* ptr).y) as usize - ptr as usize }, 4usize, concat!("Offset of field: ", stringify!(Point), "::", stringify!(y)) ); } @@ -52,27 +41,22 @@ pub struct Angle { } #[test] fn bindgen_test_layout_Angle() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Angle)) + ::std::mem::size_of:: < Angle > (), 8usize, concat!("Size of: ", + stringify!(Angle)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Angle)) + ::std::mem::align_of:: < Angle > (), 4usize, concat!("Alignment of ", + stringify!(Angle)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(Angle), "::", stringify!(a)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 4usize, + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 4usize, concat!("Offset of field: ", stringify!(Angle), "::", stringify!(b)) ); } diff --git a/bindgen-tests/tests/expectations/tests/use-core.rs b/bindgen-tests/tests/expectations/tests/use-core.rs index 569e8d2470..f7865e58d1 100644 --- a/bindgen-tests/tests/expectations/tests/use-core.rs +++ b/bindgen-tests/tests/expectations/tests/use-core.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(not(target_os = "windows"))] extern crate core; - #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct foo { @@ -16,32 +10,25 @@ pub struct foo { } #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::core::mem::MaybeUninit = - ::core::mem::MaybeUninit::uninit(); + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::core::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(foo)) + ::core::mem::size_of:: < foo > (), 16usize, concat!("Size of: ", stringify!(foo)) ); assert_eq!( - ::core::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(foo)) + ::core::mem::align_of:: < foo > (), 8usize, concat!("Alignment of ", + stringify!(foo)) ); assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, + unsafe { ::core::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) ); assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 4usize, + unsafe { ::core::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 4usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) ); assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 8usize, + unsafe { ::core::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 8usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); } @@ -62,38 +49,23 @@ pub union _bindgen_ty_1 { } #[test] fn bindgen_test_layout__bindgen_ty_1() { - const UNINIT: ::core::mem::MaybeUninit<_bindgen_ty_1> = - ::core::mem::MaybeUninit::uninit(); + const UNINIT: ::core::mem::MaybeUninit<_bindgen_ty_1> = ::core::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::core::mem::size_of::<_bindgen_ty_1>(), - 8usize, - concat!("Size of: ", stringify!(_bindgen_ty_1)) + ::core::mem::size_of:: < _bindgen_ty_1 > (), 8usize, concat!("Size of: ", + stringify!(_bindgen_ty_1)) ); assert_eq!( - ::core::mem::align_of::<_bindgen_ty_1>(), - 8usize, - concat!("Alignment of ", stringify!(_bindgen_ty_1)) + ::core::mem::align_of:: < _bindgen_ty_1 > (), 8usize, concat!("Alignment of ", + stringify!(_bindgen_ty_1)) ); assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_bindgen_ty_1), - "::", - stringify!(bar) - ) + unsafe { ::core::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(_bindgen_ty_1), "::", stringify!(bar)) ); assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_bindgen_ty_1), - "::", - stringify!(baz) - ) + unsafe { ::core::ptr::addr_of!((* ptr).baz) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(_bindgen_ty_1), "::", stringify!(baz)) ); } impl Default for _bindgen_ty_1 { @@ -108,5 +80,6 @@ impl Default for _bindgen_ty_1 { extern "C" { pub static mut bazz: _bindgen_ty_1; } -pub type fooFunction = - ::core::option::Option; +pub type fooFunction = ::core::option::Option< + unsafe extern "C" fn(bar: ::core::ffi::c_int), +>; diff --git a/bindgen-tests/tests/expectations/tests/use-core_1_0.rs b/bindgen-tests/tests/expectations/tests/use-core_1_0.rs index 8c6d0fd272..80fd7b0556 100644 --- a/bindgen-tests/tests/expectations/tests/use-core_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/use-core_1_0.rs @@ -1,12 +1,5 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern crate core; - #[repr(C)] pub struct __BindgenUnionField(::core::marker::PhantomData); impl __BindgenUnionField { @@ -59,32 +52,25 @@ pub struct foo { } #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::core::mem::MaybeUninit = - ::core::mem::MaybeUninit::uninit(); + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::core::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(foo)) + ::core::mem::size_of:: < foo > (), 16usize, concat!("Size of: ", stringify!(foo)) ); assert_eq!( - ::core::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(foo)) + ::core::mem::align_of:: < foo > (), 8usize, concat!("Alignment of ", + stringify!(foo)) ); assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, + unsafe { ::core::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) ); assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 4usize, + unsafe { ::core::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 4usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) ); assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 8usize, + unsafe { ::core::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 8usize, concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) ); } @@ -111,38 +97,23 @@ pub struct _bindgen_ty_1 { } #[test] fn bindgen_test_layout__bindgen_ty_1() { - const UNINIT: ::core::mem::MaybeUninit<_bindgen_ty_1> = - ::core::mem::MaybeUninit::uninit(); + const UNINIT: ::core::mem::MaybeUninit<_bindgen_ty_1> = ::core::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::core::mem::size_of::<_bindgen_ty_1>(), - 8usize, - concat!("Size of: ", stringify!(_bindgen_ty_1)) + ::core::mem::size_of:: < _bindgen_ty_1 > (), 8usize, concat!("Size of: ", + stringify!(_bindgen_ty_1)) ); assert_eq!( - ::core::mem::align_of::<_bindgen_ty_1>(), - 8usize, - concat!("Alignment of ", stringify!(_bindgen_ty_1)) + ::core::mem::align_of:: < _bindgen_ty_1 > (), 8usize, concat!("Alignment of ", + stringify!(_bindgen_ty_1)) ); assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_bindgen_ty_1), - "::", - stringify!(bar) - ) + unsafe { ::core::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(_bindgen_ty_1), "::", stringify!(bar)) ); assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_bindgen_ty_1), - "::", - stringify!(baz) - ) + unsafe { ::core::ptr::addr_of!((* ptr).baz) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(_bindgen_ty_1), "::", stringify!(baz)) ); } impl Clone for _bindgen_ty_1 { @@ -153,5 +124,6 @@ impl Clone for _bindgen_ty_1 { extern "C" { pub static mut bazz: _bindgen_ty_1; } -pub type fooFunction = - ::core::option::Option; +pub type fooFunction = ::core::option::Option< + unsafe extern "C" fn(bar: ::std::os::raw::c_int), +>; diff --git a/bindgen-tests/tests/expectations/tests/using.rs b/bindgen-tests/tests/expectations/tests/using.rs index 4749ed5552..97d00cb5b8 100644 --- a/bindgen-tests/tests/expectations/tests/using.rs +++ b/bindgen-tests/tests/expectations/tests/using.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Point { diff --git a/bindgen-tests/tests/expectations/tests/var-tracing.rs b/bindgen-tests/tests/expectations/tests/var-tracing.rs index 37fdd95105..c6a06ef4b1 100644 --- a/bindgen-tests/tests/expectations/tests/var-tracing.rs +++ b/bindgen-tests/tests/expectations/tests/var-tracing.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Bar { @@ -12,28 +6,18 @@ pub struct Bar { } #[test] fn bindgen_test_layout_Bar() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Bar)) + ::std::mem::size_of:: < Bar > (), 4usize, concat!("Size of: ", stringify!(Bar)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Bar)) + ::std::mem::align_of:: < Bar > (), 4usize, concat!("Alignment of ", + stringify!(Bar)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).m_baz) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Bar), - "::", - stringify!(m_baz) - ) + unsafe { ::std::ptr::addr_of!((* ptr).m_baz) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(m_baz)) ); } extern "C" { @@ -60,13 +44,10 @@ extern "C" { #[test] fn bindgen_test_layout_Baz() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Baz)) + ::std::mem::size_of:: < Baz > (), 1usize, concat!("Size of: ", stringify!(Baz)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Baz)) + ::std::mem::align_of:: < Baz > (), 1usize, concat!("Alignment of ", + stringify!(Baz)) ); } diff --git a/bindgen-tests/tests/expectations/tests/variadic-method.rs b/bindgen-tests/tests/expectations/tests/variadic-method.rs index be93dda70b..ebf454335c 100644 --- a/bindgen-tests/tests/expectations/tests/variadic-method.rs +++ b/bindgen-tests/tests/expectations/tests/variadic-method.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { #[link_name = "\u{1}_Z3fooPKcz"] pub fn foo(fmt: *const ::std::os::raw::c_char, ...); @@ -17,14 +11,11 @@ pub struct Bar { #[test] fn bindgen_test_layout_Bar() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Bar)) + ::std::mem::size_of:: < Bar > (), 1usize, concat!("Size of: ", stringify!(Bar)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Bar)) + ::std::mem::align_of:: < Bar > (), 1usize, concat!("Alignment of ", + stringify!(Bar)) ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/variadic_template_function.rs b/bindgen-tests/tests/expectations/tests/variadic_template_function.rs index 8f67136ac8..ee945f2599 100644 --- a/bindgen-tests/tests/expectations/tests/variadic_template_function.rs +++ b/bindgen-tests/tests/expectations/tests/variadic_template_function.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct VariadicFunctionObject { diff --git a/bindgen-tests/tests/expectations/tests/vector.rs b/bindgen-tests/tests/expectations/tests/vector.rs index 12d2e1b1f7..d397d5b8c8 100644 --- a/bindgen-tests/tests/expectations/tests/vector.rs +++ b/bindgen-tests/tests/expectations/tests/vector.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct foo { @@ -12,28 +6,18 @@ pub struct foo { } #[test] fn bindgen_test_layout_foo() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of:: < foo > (), 8usize, concat!("Size of: ", stringify!(foo)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(foo)) + ::std::mem::align_of:: < foo > (), 8usize, concat!("Alignment of ", + stringify!(foo)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo), - "::", - stringify!(mMember) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mMember) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(mMember)) ); } pub type __m128 = [f32; 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/virtual_dtor.rs b/bindgen-tests/tests/expectations/tests/virtual_dtor.rs index c3c66e91d8..271f959dfb 100644 --- a/bindgen-tests/tests/expectations/tests/virtual_dtor.rs +++ b/bindgen-tests/tests/expectations/tests/virtual_dtor.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct nsSlots__bindgen_vtable(::std::os::raw::c_void); #[repr(C)] @@ -15,14 +9,12 @@ pub struct nsSlots { #[test] fn bindgen_test_layout_nsSlots() { assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(nsSlots)) + ::std::mem::size_of:: < nsSlots > (), 8usize, concat!("Size of: ", + stringify!(nsSlots)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(nsSlots)) + ::std::mem::align_of:: < nsSlots > (), 8usize, concat!("Alignment of ", + stringify!(nsSlots)) ); } impl Default for nsSlots { diff --git a/bindgen-tests/tests/expectations/tests/virtual_inheritance.rs b/bindgen-tests/tests/expectations/tests/virtual_inheritance.rs index 07b94ec89c..6b5a855fae 100644 --- a/bindgen-tests/tests/expectations/tests/virtual_inheritance.rs +++ b/bindgen-tests/tests/expectations/tests/virtual_inheritance.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct A { diff --git a/bindgen-tests/tests/expectations/tests/virtual_interface.rs b/bindgen-tests/tests/expectations/tests/virtual_interface.rs index be94f23205..50ac61efc8 100644 --- a/bindgen-tests/tests/expectations/tests/virtual_interface.rs +++ b/bindgen-tests/tests/expectations/tests/virtual_interface.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct PureVirtualIFace__bindgen_vtable { pub PureVirtualIFace_Foo: unsafe extern "C" fn(this: *mut PureVirtualIFace), @@ -21,14 +15,12 @@ pub struct PureVirtualIFace { #[test] fn bindgen_test_layout_PureVirtualIFace() { assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(PureVirtualIFace)) + ::std::mem::size_of:: < PureVirtualIFace > (), 8usize, concat!("Size of: ", + stringify!(PureVirtualIFace)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(PureVirtualIFace)) + ::std::mem::align_of:: < PureVirtualIFace > (), 8usize, concat!("Alignment of ", + stringify!(PureVirtualIFace)) ); } impl Default for PureVirtualIFace { @@ -52,14 +44,12 @@ pub struct AnotherInterface { #[test] fn bindgen_test_layout_AnotherInterface() { assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(AnotherInterface)) + ::std::mem::size_of:: < AnotherInterface > (), 8usize, concat!("Size of: ", + stringify!(AnotherInterface)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(AnotherInterface)) + ::std::mem::align_of:: < AnotherInterface > (), 8usize, concat!("Alignment of ", + stringify!(AnotherInterface)) ); } impl Default for AnotherInterface { @@ -79,14 +69,12 @@ pub struct Implementation { #[test] fn bindgen_test_layout_Implementation() { assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Implementation)) + ::std::mem::size_of:: < Implementation > (), 8usize, concat!("Size of: ", + stringify!(Implementation)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Implementation)) + ::std::mem::align_of:: < Implementation > (), 8usize, concat!("Alignment of ", + stringify!(Implementation)) ); } impl Default for Implementation { @@ -107,14 +95,12 @@ pub struct DoubleImpl { #[test] fn bindgen_test_layout_DoubleImpl() { assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(DoubleImpl)) + ::std::mem::size_of:: < DoubleImpl > (), 16usize, concat!("Size of: ", + stringify!(DoubleImpl)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(DoubleImpl)) + ::std::mem::align_of:: < DoubleImpl > (), 8usize, concat!("Alignment of ", + stringify!(DoubleImpl)) ); } impl Default for DoubleImpl { diff --git a/bindgen-tests/tests/expectations/tests/virtual_overloaded.rs b/bindgen-tests/tests/expectations/tests/virtual_overloaded.rs index c117d9ef6c..9d33bc336a 100644 --- a/bindgen-tests/tests/expectations/tests/virtual_overloaded.rs +++ b/bindgen-tests/tests/expectations/tests/virtual_overloaded.rs @@ -1,16 +1,8 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct C__bindgen_vtable { - pub C_do_thing: - unsafe extern "C" fn(this: *mut C, arg1: ::std::os::raw::c_char), - pub C_do_thing1: - unsafe extern "C" fn(this: *mut C, arg1: ::std::os::raw::c_int), + pub C_do_thing: unsafe extern "C" fn(this: *mut C, arg1: ::std::os::raw::c_char), + pub C_do_thing1: unsafe extern "C" fn(this: *mut C, arg1: ::std::os::raw::c_int), } #[repr(C)] #[derive(Debug, Copy, Clone)] @@ -20,14 +12,10 @@ pub struct C { #[test] fn bindgen_test_layout_C() { assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(C)) + ::std::mem::size_of:: < C > (), 8usize, concat!("Size of: ", stringify!(C)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(C)) + ::std::mem::align_of:: < C > (), 8usize, concat!("Alignment of ", stringify!(C)) ); } impl Default for C { @@ -41,15 +29,9 @@ impl Default for C { } extern "C" { #[link_name = "\u{1}_ZN1C8do_thingEc"] - pub fn C_do_thing( - this: *mut ::std::os::raw::c_void, - arg1: ::std::os::raw::c_char, - ); + pub fn C_do_thing(this: *mut ::std::os::raw::c_void, arg1: ::std::os::raw::c_char); } extern "C" { #[link_name = "\u{1}_ZN1C8do_thingEi"] - pub fn C_do_thing1( - this: *mut ::std::os::raw::c_void, - arg1: ::std::os::raw::c_int, - ); + pub fn C_do_thing1(this: *mut ::std::os::raw::c_void, arg1: ::std::os::raw::c_int); } diff --git a/bindgen-tests/tests/expectations/tests/void_typedef.rs b/bindgen-tests/tests/expectations/tests/void_typedef.rs index 7e148e7238..6c3b45dcc7 100644 --- a/bindgen-tests/tests/expectations/tests/void_typedef.rs +++ b/bindgen-tests/tests/expectations/tests/void_typedef.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type VOID = ::std::os::raw::c_void; pub type ALSO_VOID = VOID; extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/vtable_recursive_sig.rs b/bindgen-tests/tests/expectations/tests/vtable_recursive_sig.rs index 74e1dc7914..d16557d371 100644 --- a/bindgen-tests/tests/expectations/tests/vtable_recursive_sig.rs +++ b/bindgen-tests/tests/expectations/tests/vtable_recursive_sig.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct Base__bindgen_vtable { pub Base_AsDerived: unsafe extern "C" fn(this: *mut Base) -> *mut Derived, @@ -17,14 +11,11 @@ pub struct Base { #[test] fn bindgen_test_layout_Base() { assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Base)) + ::std::mem::size_of:: < Base > (), 8usize, concat!("Size of: ", stringify!(Base)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Base)) + ::std::mem::align_of:: < Base > (), 8usize, concat!("Alignment of ", + stringify!(Base)) ); } impl Default for Base { @@ -48,14 +39,12 @@ pub struct Derived { #[test] fn bindgen_test_layout_Derived() { assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Derived)) + ::std::mem::size_of:: < Derived > (), 8usize, concat!("Size of: ", + stringify!(Derived)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Derived)) + ::std::mem::align_of:: < Derived > (), 8usize, concat!("Alignment of ", + stringify!(Derived)) ); } impl Default for Derived { diff --git a/bindgen-tests/tests/expectations/tests/wasm-constructor-returns.rs b/bindgen-tests/tests/expectations/tests/wasm-constructor-returns.rs index 6d15c51f9d..73a5500db9 100644 --- a/bindgen-tests/tests/expectations/tests/wasm-constructor-returns.rs +++ b/bindgen-tests/tests/expectations/tests/wasm-constructor-returns.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { @@ -13,14 +7,11 @@ pub struct Foo { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) + ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", + stringify!(Foo)) ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/wasm-import-module.rs b/bindgen-tests/tests/expectations/tests/wasm-import-module.rs index e334a7b734..9725195e0e 100644 --- a/bindgen-tests/tests/expectations/tests/wasm-import-module.rs +++ b/bindgen-tests/tests/expectations/tests/wasm-import-module.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[link(wasm_import_module = "test-module")] extern "C" { pub fn test_function(); diff --git a/bindgen-tests/tests/expectations/tests/weird_bitfields.rs b/bindgen-tests/tests/expectations/tests/weird_bitfields.rs index 9383bada44..0337786cdd 100644 --- a/bindgen-tests/tests/expectations/tests/weird_bitfields.rs +++ b/bindgen-tests/tests/expectations/tests/weird_bitfields.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct __BindgenBitfieldUnit { @@ -55,8 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -76,8 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len() ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -121,165 +113,75 @@ pub struct Weird { } #[test] fn bindgen_test_layout_Weird() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 24usize, - concat!("Size of: ", stringify!(Weird)) + ::std::mem::size_of:: < Weird > (), 24usize, concat!("Size of: ", + stringify!(Weird)) ); assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Weird)) + ::std::mem::align_of:: < Weird > (), 4usize, concat!("Alignment of ", + stringify!(Weird)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mStrokeDasharrayLength) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mStrokeDasharrayLength) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mStrokeDasharrayLength) as usize - ptr as + usize }, 0usize, concat!("Offset of field: ", stringify!(Weird), "::", + stringify!(mStrokeDasharrayLength)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mClipRule) as usize - ptr as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mClipRule) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mClipRule) as usize - ptr as usize }, + 8usize, concat!("Offset of field: ", stringify!(Weird), "::", + stringify!(mClipRule)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mColorInterpolation) as usize - - ptr as usize - }, - 9usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mColorInterpolation) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mColorInterpolation) as usize - ptr as + usize }, 9usize, concat!("Offset of field: ", stringify!(Weird), "::", + stringify!(mColorInterpolation)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mColorInterpolationFilters) as usize - - ptr as usize - }, - 10usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mColorInterpolationFilters) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mColorInterpolationFilters) as usize - ptr + as usize }, 10usize, concat!("Offset of field: ", stringify!(Weird), "::", + stringify!(mColorInterpolationFilters)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mFillRule) as usize - ptr as usize - }, - 11usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mFillRule) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mFillRule) as usize - ptr as usize }, + 11usize, concat!("Offset of field: ", stringify!(Weird), "::", + stringify!(mFillRule)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mImageRendering) as usize - ptr as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mImageRendering) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mImageRendering) as usize - ptr as usize }, + 12usize, concat!("Offset of field: ", stringify!(Weird), "::", + stringify!(mImageRendering)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mPaintOrder) as usize - ptr as usize - }, - 13usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mPaintOrder) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mPaintOrder) as usize - ptr as usize }, + 13usize, concat!("Offset of field: ", stringify!(Weird), "::", + stringify!(mPaintOrder)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mShapeRendering) as usize - ptr as usize - }, - 14usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mShapeRendering) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mShapeRendering) as usize - ptr as usize }, + 14usize, concat!("Offset of field: ", stringify!(Weird), "::", + stringify!(mShapeRendering)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mStrokeLinecap) as usize - ptr as usize - }, - 15usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mStrokeLinecap) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mStrokeLinecap) as usize - ptr as usize }, + 15usize, concat!("Offset of field: ", stringify!(Weird), "::", + stringify!(mStrokeLinecap)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mStrokeLinejoin) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mStrokeLinejoin) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mStrokeLinejoin) as usize - ptr as usize }, + 16usize, concat!("Offset of field: ", stringify!(Weird), "::", + stringify!(mStrokeLinejoin)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mTextAnchor) as usize - ptr as usize - }, - 17usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mTextAnchor) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mTextAnchor) as usize - ptr as usize }, + 17usize, concat!("Offset of field: ", stringify!(Weird), "::", + stringify!(mTextAnchor)) ); assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mTextRendering) as usize - ptr as usize - }, - 18usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mTextRendering) - ) + unsafe { ::std::ptr::addr_of!((* ptr).mTextRendering) as usize - ptr as usize }, + 18usize, concat!("Offset of field: ", stringify!(Weird), "::", + stringify!(mTextRendering)) ); } impl Default for Weird { @@ -294,9 +196,7 @@ impl Default for Weird { impl Weird { #[inline] pub fn bitTest(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(0usize, 16u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 16u8) as u32) } } #[inline] pub fn set_bitTest(&mut self, val: ::std::os::raw::c_uint) { @@ -307,9 +207,7 @@ impl Weird { } #[inline] pub fn bitTest2(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.get(16usize, 15u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_1.get(16usize, 15u8) as u32) } } #[inline] pub fn set_bitTest2(&mut self, val: ::std::os::raw::c_uint) { @@ -323,23 +221,30 @@ impl Weird { bitTest: ::std::os::raw::c_uint, bitTest2: ::std::os::raw::c_uint, ) -> __BindgenBitfieldUnit<[u8; 4usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 16u8, { - let bitTest: u32 = unsafe { ::std::mem::transmute(bitTest) }; - bitTest as u64 - }); - __bindgen_bitfield_unit.set(16usize, 15u8, { - let bitTest2: u32 = unsafe { ::std::mem::transmute(bitTest2) }; - bitTest2 as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 16u8, + { + let bitTest: u32 = unsafe { ::std::mem::transmute(bitTest) }; + bitTest as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 16usize, + 15u8, + { + let bitTest2: u32 = unsafe { ::std::mem::transmute(bitTest2) }; + bitTest2 as u64 + }, + ); __bindgen_bitfield_unit } #[inline] pub fn mFillOpacitySource(&self) -> nsStyleSVGOpacitySource { - unsafe { - ::std::mem::transmute(self._bitfield_2.get(0usize, 3u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_2.get(0usize, 3u8) as u32) } } #[inline] pub fn set_mFillOpacitySource(&mut self, val: nsStyleSVGOpacitySource) { @@ -350,9 +255,7 @@ impl Weird { } #[inline] pub fn mStrokeOpacitySource(&self) -> nsStyleSVGOpacitySource { - unsafe { - ::std::mem::transmute(self._bitfield_2.get(3usize, 3u8) as u32) - } + unsafe { ::std::mem::transmute(self._bitfield_2.get(3usize, 3u8) as u32) } } #[inline] pub fn set_mStrokeOpacitySource(&mut self, val: nsStyleSVGOpacitySource) { @@ -363,9 +266,7 @@ impl Weird { } #[inline] pub fn mStrokeDasharrayFromObject(&self) -> bool { - unsafe { - ::std::mem::transmute(self._bitfield_2.get(6usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_2.get(6usize, 1u8) as u8) } } #[inline] pub fn set_mStrokeDasharrayFromObject(&mut self, val: bool) { @@ -376,9 +277,7 @@ impl Weird { } #[inline] pub fn mStrokeDashoffsetFromObject(&self) -> bool { - unsafe { - ::std::mem::transmute(self._bitfield_2.get(7usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_2.get(7usize, 1u8) as u8) } } #[inline] pub fn set_mStrokeDashoffsetFromObject(&mut self, val: bool) { @@ -389,9 +288,7 @@ impl Weird { } #[inline] pub fn mStrokeWidthFromObject(&self) -> bool { - unsafe { - ::std::mem::transmute(self._bitfield_2.get(8usize, 1u8) as u8) - } + unsafe { ::std::mem::transmute(self._bitfield_2.get(8usize, 1u8) as u8) } } #[inline] pub fn set_mStrokeWidthFromObject(&mut self, val: bool) { @@ -408,33 +305,62 @@ impl Weird { mStrokeDashoffsetFromObject: bool, mStrokeWidthFromObject: bool, ) -> __BindgenBitfieldUnit<[u8; 2usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 2usize]> = - Default::default(); - __bindgen_bitfield_unit.set(0usize, 3u8, { - let mFillOpacitySource: u32 = - unsafe { ::std::mem::transmute(mFillOpacitySource) }; - mFillOpacitySource as u64 - }); - __bindgen_bitfield_unit.set(3usize, 3u8, { - let mStrokeOpacitySource: u32 = - unsafe { ::std::mem::transmute(mStrokeOpacitySource) }; - mStrokeOpacitySource as u64 - }); - __bindgen_bitfield_unit.set(6usize, 1u8, { - let mStrokeDasharrayFromObject: u8 = - unsafe { ::std::mem::transmute(mStrokeDasharrayFromObject) }; - mStrokeDasharrayFromObject as u64 - }); - __bindgen_bitfield_unit.set(7usize, 1u8, { - let mStrokeDashoffsetFromObject: u8 = - unsafe { ::std::mem::transmute(mStrokeDashoffsetFromObject) }; - mStrokeDashoffsetFromObject as u64 - }); - __bindgen_bitfield_unit.set(8usize, 1u8, { - let mStrokeWidthFromObject: u8 = - unsafe { ::std::mem::transmute(mStrokeWidthFromObject) }; - mStrokeWidthFromObject as u64 - }); + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 2usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 3u8, + { + let mFillOpacitySource: u32 = unsafe { + ::std::mem::transmute(mFillOpacitySource) + }; + mFillOpacitySource as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 3usize, + 3u8, + { + let mStrokeOpacitySource: u32 = unsafe { + ::std::mem::transmute(mStrokeOpacitySource) + }; + mStrokeOpacitySource as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 6usize, + 1u8, + { + let mStrokeDasharrayFromObject: u8 = unsafe { + ::std::mem::transmute(mStrokeDasharrayFromObject) + }; + mStrokeDasharrayFromObject as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 7usize, + 1u8, + { + let mStrokeDashoffsetFromObject: u8 = unsafe { + ::std::mem::transmute(mStrokeDashoffsetFromObject) + }; + mStrokeDashoffsetFromObject as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 8usize, + 1u8, + { + let mStrokeWidthFromObject: u8 = unsafe { + ::std::mem::transmute(mStrokeWidthFromObject) + }; + mStrokeWidthFromObject as u64 + }, + ); __bindgen_bitfield_unit } } diff --git a/bindgen-tests/tests/expectations/tests/what_is_going_on.rs b/bindgen-tests/tests/expectations/tests/what_is_going_on.rs index b4f42791db..4ba2c56683 100644 --- a/bindgen-tests/tests/expectations/tests/what_is_going_on.rs +++ b/bindgen-tests/tests/expectations/tests/what_is_going_on.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct UnknownUnits { @@ -13,14 +7,12 @@ pub struct UnknownUnits { #[test] fn bindgen_test_layout_UnknownUnits() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(UnknownUnits)) + ::std::mem::size_of:: < UnknownUnits > (), 1usize, concat!("Size of: ", + stringify!(UnknownUnits)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(UnknownUnits)) + ::std::mem::align_of:: < UnknownUnits > (), 1usize, concat!("Alignment of ", + stringify!(UnknownUnits)) ); } pub type Float = f32; diff --git a/bindgen-tests/tests/expectations/tests/win32-thiscall_1_0.rs b/bindgen-tests/tests/expectations/tests/win32-thiscall_1_0.rs index 502e12fe44..2cd4d0aa25 100644 --- a/bindgen-tests/tests/expectations/tests/win32-thiscall_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/win32-thiscall_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Debug, Default, Copy)] pub struct Foo { @@ -13,14 +7,11 @@ pub struct Foo { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) + ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", + stringify!(Foo)) ); } impl Clone for Foo { diff --git a/bindgen-tests/tests/expectations/tests/win32-thiscall_nightly.rs b/bindgen-tests/tests/expectations/tests/win32-thiscall_nightly.rs index 92bb13cc61..93c75b9388 100644 --- a/bindgen-tests/tests/expectations/tests/win32-thiscall_nightly.rs +++ b/bindgen-tests/tests/expectations/tests/win32-thiscall_nightly.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(feature = "nightly")] #![feature(abi_thiscall)] - #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { @@ -15,14 +9,11 @@ pub struct Foo { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)) + ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", + stringify!(Foo)) ); } extern "thiscall" { @@ -42,10 +33,7 @@ impl Foo { Foo_test(self) } #[inline] - pub unsafe fn test2( - &mut self, - var: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int { + 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/win32-vectorcall-1_0.rs b/bindgen-tests/tests/expectations/tests/win32-vectorcall-1_0.rs index 131dbdf39f..fe64295a68 100644 --- a/bindgen-tests/tests/expectations/tests/win32-vectorcall-1_0.rs +++ b/bindgen-tests/tests/expectations/tests/win32-vectorcall-1_0.rs @@ -1,6 +1 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] \ No newline at end of file diff --git a/bindgen-tests/tests/expectations/tests/win32-vectorcall-nightly.rs b/bindgen-tests/tests/expectations/tests/win32-vectorcall-nightly.rs index 163741df62..a262b78c59 100644 --- a/bindgen-tests/tests/expectations/tests/win32-vectorcall-nightly.rs +++ b/bindgen-tests/tests/expectations/tests/win32-vectorcall-nightly.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(feature = "nightly")] #![feature(abi_vectorcall)] - extern "vectorcall" { #[link_name = "\u{1}test_vectorcall@@16"] pub fn test_vectorcall( diff --git a/bindgen-tests/tests/expectations/tests/with_array_pointers_arguments.rs b/bindgen-tests/tests/expectations/tests/with_array_pointers_arguments.rs index 2a7d18025d..cc82fd4daf 100644 --- a/bindgen-tests/tests/expectations/tests/with_array_pointers_arguments.rs +++ b/bindgen-tests/tests/expectations/tests/with_array_pointers_arguments.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { pub fn test_fn( a: f32, diff --git a/bindgen-tests/tests/expectations/tests/without_array_pointers_arguments.rs b/bindgen-tests/tests/expectations/tests/without_array_pointers_arguments.rs index c4acdb3e91..f48e5f7f5c 100644 --- a/bindgen-tests/tests/expectations/tests/without_array_pointers_arguments.rs +++ b/bindgen-tests/tests/expectations/tests/without_array_pointers_arguments.rs @@ -1,25 +1,14 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { - pub fn test_fn( - a: f32, - arr: *mut ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int; + pub fn test_fn(a: f32, arr: *mut ::std::os::raw::c_int) -> ::std::os::raw::c_int; } extern "C" { - pub fn test_fn2( - arr: *const f32, - b: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int; + pub fn test_fn2(arr: *const f32, b: ::std::os::raw::c_int) -> ::std::os::raw::c_int; } pub type defArr = [::std::os::raw::c_char; 20usize]; -pub type foo = - ::std::option::Option; +pub type foo = ::std::option::Option< + unsafe extern "C" fn(a: *mut ::std::os::raw::c_char), +>; extern "C" { pub fn bar(a: *mut ::std::os::raw::c_char); } diff --git a/bindgen-tests/tests/expectations/tests/wrap-static-fns.rs b/bindgen-tests/tests/expectations/tests/wrap-static-fns.rs index 2800d7034d..122f4c9cc8 100644 --- a/bindgen-tests/tests/expectations/tests/wrap-static-fns.rs +++ b/bindgen-tests/tests/expectations/tests/wrap-static-fns.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern "C" { #[link_name = "foo__extern"] pub fn foo() -> ::std::os::raw::c_int; @@ -21,9 +15,7 @@ extern "C" { #[link_name = "takes_fn_ptr__extern"] pub fn takes_fn_ptr( f: ::std::option::Option< - unsafe extern "C" fn( - arg1: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int, + unsafe extern "C" fn(arg1: ::std::os::raw::c_int) -> ::std::os::raw::c_int, >, ) -> ::std::os::raw::c_int; } @@ -31,9 +23,7 @@ extern "C" { #[link_name = "takes_fn__extern"] pub fn takes_fn( f: ::std::option::Option< - unsafe extern "C" fn( - arg1: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int, + unsafe extern "C" fn(arg1: ::std::os::raw::c_int) -> ::std::os::raw::c_int, >, ) -> ::std::os::raw::c_int; } diff --git a/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_anon_union_1_0.rs b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_anon_union_1_0.rs index 0eef6d2e78..fdee0709d4 100644 --- a/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_anon_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_anon_union_1_0.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { @@ -73,8 +67,7 @@ pub struct TErrorResult_DOMExceptionInfo { #[derive(Debug, Default, Copy, Clone)] pub struct TErrorResult__bindgen_ty_1 { pub mMessage: __BindgenUnionField<*mut TErrorResult_Message>, - pub mDOMExceptionInfo: - __BindgenUnionField<*mut TErrorResult_DOMExceptionInfo>, + pub mDOMExceptionInfo: __BindgenUnionField<*mut TErrorResult_DOMExceptionInfo>, pub bindgen_union_field: u64, } impl Default for TErrorResult { diff --git a/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_class.rs b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_class.rs index d621b450a2..5f64396f6b 100644 --- a/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_class.rs +++ b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_class.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Default)] pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); diff --git a/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_dynamic_loading_simple.rs b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_dynamic_loading_simple.rs index 5864ba0a8d..968f10f6e5 100644 --- a/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_dynamic_loading_simple.rs +++ b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_dynamic_loading_simple.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] extern crate libloading; pub struct TestLib { __library: ::libloading::Library, @@ -16,9 +10,7 @@ pub struct TestLib { ::libloading::Error, >, pub bar: Result< - unsafe extern "C" fn( - x: *mut ::std::os::raw::c_void, - ) -> ::std::os::raw::c_int, + unsafe extern "C" fn(x: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int, ::libloading::Error, >, pub baz: Result< @@ -34,9 +26,7 @@ impl TestLib { let library = ::libloading::Library::new(path)?; unsafe { Self::from_library(library) } } - pub unsafe fn from_library( - library: L, - ) -> Result + pub unsafe fn from_library(library: L) -> Result where L: Into<::libloading::Library>, { @@ -56,17 +46,10 @@ impl TestLib { x: ::std::os::raw::c_int, y: ::std::os::raw::c_int, ) -> ::std::os::raw::c_int { - unsafe { - (self.foo.as_ref().expect("Expected function, got error."))(x, y) - } + unsafe { (self.foo.as_ref().expect("Expected function, got error."))(x, y) } } - pub unsafe fn bar( - &self, - x: *mut ::std::os::raw::c_void, - ) -> ::std::os::raw::c_int { - unsafe { - (self.bar.as_ref().expect("Expected function, got error."))(x) - } + pub unsafe fn bar(&self, x: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int { + unsafe { (self.bar.as_ref().expect("Expected function, got error."))(x) } } pub unsafe fn baz(&self) -> ::std::os::raw::c_int { unsafe { (self.baz.as_ref().expect("Expected function, got error."))() } diff --git a/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_objc_class.rs b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_objc_class.rs index 0fe8e254c3..c8f7241fcf 100644 --- a/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_objc_class.rs +++ b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_objc_class.rs @@ -1,12 +1,6 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] - -use objc::{self, class, msg_send, sel, sel_impl}; +use objc::{self, msg_send, sel, sel_impl, class}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; extern "C" { @@ -33,6 +27,6 @@ pub trait IFoo: Sized + std::ops::Deref { where ::Target: objc::Message + Sized, { - unsafe { msg_send!(*self, method) } + unsafe { msg_send!(* self, method) } } } diff --git a/bindgen-tests/tests/expectations/tests/zero-size-array-align.rs b/bindgen-tests/tests/expectations/tests/zero-size-array-align.rs index d7d0f6613d..a0f65d8b2a 100644 --- a/bindgen-tests/tests/expectations/tests/zero-size-array-align.rs +++ b/bindgen-tests/tests/expectations/tests/zero-size-array-align.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Default)] pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); @@ -44,47 +38,26 @@ pub struct dm_deps { } #[test] fn bindgen_test_layout_dm_deps() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(dm_deps)) + ::std::mem::size_of:: < dm_deps > (), 8usize, concat!("Size of: ", + stringify!(dm_deps)) ); assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(dm_deps)) + ::std::mem::align_of:: < dm_deps > (), 8usize, concat!("Alignment of ", + stringify!(dm_deps)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).count) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(dm_deps), - "::", - stringify!(count) - ) + unsafe { ::std::ptr::addr_of!((* ptr).count) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(dm_deps), "::", stringify!(count)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).filler) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(dm_deps), - "::", - stringify!(filler) - ) + unsafe { ::std::ptr::addr_of!((* ptr).filler) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(dm_deps), "::", stringify!(filler)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).device) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(dm_deps), - "::", - stringify!(device) - ) + unsafe { ::std::ptr::addr_of!((* ptr).device) as usize - ptr as usize }, 8usize, + concat!("Offset of field: ", stringify!(dm_deps), "::", stringify!(device)) ); } diff --git a/bindgen-tests/tests/expectations/tests/zero-sized-array.rs b/bindgen-tests/tests/expectations/tests/zero-sized-array.rs index 4ba52498c4..477702a24e 100644 --- a/bindgen-tests/tests/expectations/tests/zero-sized-array.rs +++ b/bindgen-tests/tests/expectations/tests/zero-sized-array.rs @@ -1,10 +1,4 @@ -#![allow( - dead_code, - non_snake_case, - non_camel_case_types, - non_upper_case_globals -)] - +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] #[derive(Default)] pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); @@ -43,28 +37,19 @@ pub struct ZeroSizedArray { } #[test] fn bindgen_test_layout_ZeroSizedArray() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(ZeroSizedArray)) + ::std::mem::size_of:: < ZeroSizedArray > (), 0usize, concat!("Size of: ", + stringify!(ZeroSizedArray)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(ZeroSizedArray)) + ::std::mem::align_of:: < ZeroSizedArray > (), 1usize, concat!("Alignment of ", + stringify!(ZeroSizedArray)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ZeroSizedArray), - "::", - stringify!(arr) - ) + unsafe { ::std::ptr::addr_of!((* ptr).arr) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(ZeroSizedArray), "::", stringify!(arr)) ); } /// And nor should this get an `_address` field. @@ -75,32 +60,24 @@ pub struct ContainsZeroSizedArray { } #[test] fn bindgen_test_layout_ContainsZeroSizedArray() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(ContainsZeroSizedArray)) + ::std::mem::size_of:: < ContainsZeroSizedArray > (), 0usize, concat!("Size of: ", + stringify!(ContainsZeroSizedArray)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < ContainsZeroSizedArray > (), 1usize, concat!("Alignment of ", stringify!(ContainsZeroSizedArray)) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).zsa) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContainsZeroSizedArray), - "::", - stringify!(zsa) - ) + unsafe { ::std::ptr::addr_of!((* ptr).zsa) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(ContainsZeroSizedArray), "::", + stringify!(zsa)) ); } -/// Inheriting from ZeroSizedArray shouldn't cause an `_address` to be inserted -/// either. +/** Inheriting from ZeroSizedArray shouldn't cause an `_address` to be inserted + either.*/ #[repr(C)] #[derive(Debug, Default)] pub struct InheritsZeroSizedArray { @@ -109,13 +86,11 @@ pub struct InheritsZeroSizedArray { #[test] fn bindgen_test_layout_InheritsZeroSizedArray() { assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(InheritsZeroSizedArray)) + ::std::mem::size_of:: < InheritsZeroSizedArray > (), 0usize, concat!("Size of: ", + stringify!(InheritsZeroSizedArray)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < InheritsZeroSizedArray > (), 1usize, concat!("Alignment of ", stringify!(InheritsZeroSizedArray)) ); } @@ -128,13 +103,11 @@ pub struct DynamicallySizedArray { #[test] fn bindgen_test_layout_DynamicallySizedArray() { assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(DynamicallySizedArray)) + ::std::mem::size_of:: < DynamicallySizedArray > (), 0usize, concat!("Size of: ", + stringify!(DynamicallySizedArray)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < DynamicallySizedArray > (), 1usize, concat!("Alignment of ", stringify!(DynamicallySizedArray)) ); } @@ -147,13 +120,11 @@ pub struct ContainsDynamicallySizedArray { #[test] fn bindgen_test_layout_ContainsDynamicallySizedArray() { assert_eq!( - ::std::mem::size_of::(), - 0usize, + ::std::mem::size_of:: < ContainsDynamicallySizedArray > (), 0usize, concat!("Size of: ", stringify!(ContainsDynamicallySizedArray)) ); assert_eq!( - ::std::mem::align_of::(), - 1usize, + ::std::mem::align_of:: < ContainsDynamicallySizedArray > (), 1usize, concat!("Alignment of ", stringify!(ContainsDynamicallySizedArray)) ); } diff --git a/bindgen-tests/tests/tests.rs b/bindgen-tests/tests/tests.rs index e1c35faa41..f83c1a7a8d 100644 --- a/bindgen-tests/tests/tests.rs +++ b/bindgen-tests/tests/tests.rs @@ -8,10 +8,8 @@ extern crate shlex; use bindgen::{clang_version, Builder}; use std::env; use std::fs; -use std::io::{self, BufRead, BufReader, Error, ErrorKind, Read, Write}; +use std::io::{BufRead, BufReader, Error, ErrorKind, Read, Write}; use std::path::{Path, PathBuf}; -use std::process; -use std::sync::Once; use crate::options::builder_from_flags; @@ -20,100 +18,14 @@ mod options; mod parse_callbacks; -// Run `rustfmt` on the given source string and return a tuple of the formatted -// bindings, and rustfmt's stderr. -fn rustfmt(source: String) -> (String, String) { - static CHECK_RUSTFMT: Once = Once::new(); +// Format the given source string. It can fail if the source string does not contain syntactically +// valid Rust. +fn format_code>(source: S) -> syn::Result { + use prettyplease::unparse; + use syn::{parse_str, File}; - CHECK_RUSTFMT.call_once(|| { - if env::var_os("RUSTFMT").is_some() { - return; - } - - let mut rustfmt = { - let mut p = process::Command::new("rustup"); - p.args(["run", "nightly", "rustfmt", "--version"]); - p - }; - - let have_working_rustfmt = rustfmt - .stdout(process::Stdio::null()) - .stderr(process::Stdio::null()) - .status() - .ok() - .map_or(false, |status| status.success()); - - if !have_working_rustfmt { - panic!( - " -The latest `rustfmt` is required to run the `bindgen` test suite. Install -`rustfmt` with: - - $ rustup update nightly - $ rustup component add rustfmt --toolchain nightly -" - ); - } - }); - - let mut child = match env::var_os("RUSTFMT") { - Some(r) => process::Command::new(r), - None => { - let mut p = process::Command::new("rustup"); - p.args(["run", "nightly", "rustfmt"]); - p - } - }; - - let mut child = child - .args([ - "--config-path", - concat!(env!("CARGO_MANIFEST_DIR"), "/tests/rustfmt.toml"), - ]) - .stdin(process::Stdio::piped()) - .stdout(process::Stdio::piped()) - .stderr(process::Stdio::piped()) - .spawn() - .expect("should spawn `rustup run nightly rustfmt`"); - - let mut stdin = child.stdin.take().unwrap(); - let mut stdout = child.stdout.take().unwrap(); - let mut stderr = child.stderr.take().unwrap(); - - // Write to stdin in a new thread, so that we can read from stdout on this - // thread. This keeps the child from blocking on writing to its stdout which - // might block us from writing to its stdin. - let stdin_handle = - ::std::thread::spawn(move || stdin.write_all(source.as_bytes())); - - // Read stderr on a new thread for similar reasons. - let stderr_handle = ::std::thread::spawn(move || { - let mut output = vec![]; - io::copy(&mut stderr, &mut output) - .map(|_| String::from_utf8_lossy(&output).to_string()) - }); - - let mut output = vec![]; - io::copy(&mut stdout, &mut output).expect("Should copy stdout into vec OK"); - - // Ignore actual rustfmt status because it is often non-zero for trivial - // things. - let _ = child.wait().expect("should wait on rustfmt child OK"); - - stdin_handle - .join() - .expect("writer thread should not have panicked") - .expect("should have written to child rustfmt's stdin OK"); - - let bindings = String::from_utf8(output) - .expect("rustfmt should only emit valid utf-8"); - - let stderr = stderr_handle - .join() - .expect("stderr reader thread should not have panicked") - .expect("should have read child rustfmt's stderr OK"); - - (bindings, stderr) + let file = parse_str::(source.as_ref())?; + Ok(unparse(&file)) } fn should_overwrite_expected() -> bool { @@ -247,17 +159,15 @@ fn compare_generated_header( let (builder, roundtrip_builder) = builder.into_builder(check_roundtrip)?; // We skip the generate() error here so we get a full diff below - let (actual, rustfmt_stderr) = match builder.generate() { - Ok(bindings) => { - let actual = bindings.to_string(); - rustfmt(actual) - } - Err(_) => ("/* error generating bindings */\n".into(), "".to_string()), + let actual = match builder.generate() { + Ok(bindings) => format_code(bindings.to_string()).map_err(|err| { + Error::new( + ErrorKind::Other, + format!("Cannot parse the generated bindings: {}", err), + ) + })?, + Err(_) => "/* error generating bindings */\n".into(), }; - println!("{}", rustfmt_stderr); - - let (expected, rustfmt_stderr) = rustfmt(expected); - println!("{}", rustfmt_stderr); if actual.is_empty() { return Err(Error::new( @@ -265,9 +175,7 @@ fn compare_generated_header( "Something's gone really wrong!", )); } - if actual != expected { - println!("{}", rustfmt_stderr); return error_diff_mismatch( &actual, &expected, @@ -451,19 +359,18 @@ fn test_clang_env_args() { .unwrap() .to_string(); - let (actual, stderr) = rustfmt(actual); - println!("{}", stderr); + let actual = format_code(actual).unwrap(); - let (expected, _) = rustfmt( + let expected = format_code( "extern \"C\" { pub static x: [::std::os::raw::c_int; 1usize]; } extern \"C\" { pub static y: [::std::os::raw::c_int; 1usize]; } -" - .to_string(), - ); +", + ) + .unwrap(); assert_eq!(expected, actual); } @@ -478,16 +385,15 @@ fn test_header_contents() { .unwrap() .to_string(); - let (actual, stderr) = rustfmt(actual); - println!("{}", stderr); + let actual = format_code(actual).unwrap(); - let (expected, _) = rustfmt( + let expected = format_code( "extern \"C\" { pub fn foo(a: *const ::std::os::raw::c_char) -> ::std::os::raw::c_int; } -" - .to_string(), - ); +", + ) + .unwrap(); assert_eq!(expected, actual); } @@ -505,8 +411,7 @@ fn test_multiple_header_calls_in_builder() { .unwrap() .to_string(); - let (actual, stderr) = rustfmt(actual); - println!("{}", stderr); + let actual = format_code(actual).unwrap(); let expected_filename = concat!( env!("CARGO_MANIFEST_DIR"), @@ -516,7 +421,7 @@ fn test_multiple_header_calls_in_builder() { env!("CARGO_MANIFEST_DIR"), "/tests/expectations/tests/test_multiple_header_calls_in_builder.rs" )); - let (expected, _) = rustfmt(expected.to_string()); + let expected = format_code(expected).unwrap(); if actual != expected { println!("Generated bindings differ from expected!"); @@ -540,19 +445,18 @@ fn test_multiple_header_contents() { .unwrap() .to_string(); - let (actual, stderr) = rustfmt(actual); - println!("{}", stderr); + let actual = format_code(actual).unwrap(); - let (expected, _) = rustfmt( + let expected = format_code( "extern \"C\" { pub fn foo2(b: *const ::std::os::raw::c_char) -> f32; } extern \"C\" { pub fn foo(a: *const ::std::os::raw::c_char) -> ::std::os::raw::c_int; } -" - .to_string(), - ); +", + ) + .unwrap(); assert_eq!(expected, actual); } @@ -572,8 +476,7 @@ fn test_mixed_header_and_header_contents() { .unwrap() .to_string(); - let (actual, stderr) = rustfmt(actual); - println!("{}", stderr); + let actual = format_code(actual).unwrap(); let expected_filename = concat!( env!("CARGO_MANIFEST_DIR"), @@ -583,7 +486,7 @@ fn test_mixed_header_and_header_contents() { env!("CARGO_MANIFEST_DIR"), "/tests/expectations/tests/test_mixed_header_and_header_contents.rs" )); - let (expected, _) = rustfmt(expected.to_string()); + let expected = format_code(expected).unwrap(); if expected != actual { error_diff_mismatch( &actual, diff --git a/ci/test.sh b/ci/test.sh index 33d0f7c690..c0c8bec59b 100755 --- a/ci/test.sh +++ b/ci/test.sh @@ -75,14 +75,6 @@ set_llvm_env() { fi } -# Need rustfmt to compare the test expectations. -set_rustfmt_env() { - local toolchain="nightly-$(curl https://rust-lang.github.io/rustup-components-history/$(rustup target list --installed | tail -1)/rustfmt)" - rustup update "$toolchain" - rustup component add rustfmt --toolchain "$toolchain" - export RUSTFMT="$(rustup which --toolchain "$toolchain" rustfmt)" -} - assert_no_diff() { git add -u git diff @ @@ -90,7 +82,6 @@ assert_no_diff() { } set_llvm_env -set_rustfmt_env get_cargo_args() { local args="" From 133103f91f95c324a206638782d754e13d8cde1e Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Fri, 2 Jun 2023 22:14:50 +0200 Subject: [PATCH 513/942] allow quick-edit (#2527) --- book/book.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/book/book.toml b/book/book.toml index 340134a32e..371c7aa5b5 100644 --- a/book/book.toml +++ b/book/book.toml @@ -2,3 +2,7 @@ title = "The `bindgen` User Guide" author = "The Servo project developers" description = "`bindgen` automatically generates Rust FFI bindings to C and C++ libraries." + +[output.html] +git-repository-url = "https://github.com/rust-lang/rust-bindgen" +edit-url-template = "https://github.com/rust-lang/rust-bindgen/edit/main/book/{path}" From e5b839a5c224ccb34f10de9e5da0677611e4a54c Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Fri, 2 Jun 2023 22:16:03 +0200 Subject: [PATCH 514/942] backticks are not pretty when not rendered (#2529) These ones are particularly uncomfortable due to being of large font, in addition to being visible on all pages of the book. --- book/book.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/book.toml b/book/book.toml index 371c7aa5b5..78809c2176 100644 --- a/book/book.toml +++ b/book/book.toml @@ -1,5 +1,5 @@ [book] -title = "The `bindgen` User Guide" +title = "The bindgen User Guide" author = "The Servo project developers" description = "`bindgen` automatically generates Rust FFI bindings to C and C++ libraries." From 12b59bb2e57ad4a7a4b5de230a129daa6cda0433 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Fri, 2 Jun 2023 22:17:01 +0200 Subject: [PATCH 515/942] not needed since 2018 edition (#2531) --- book/src/tutorial-3.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/book/src/tutorial-3.md b/book/src/tutorial-3.md index dcd67c5ca8..7a42bf16ee 100644 --- a/book/src/tutorial-3.md +++ b/book/src/tutorial-3.md @@ -10,8 +10,6 @@ like `./target/debug/build/bindgen-tutorial-bzip2-sys-afc7747d7eafd720/out/`. Note that the associated shared object to `bz2` is `libbz2.so`. In general, a `lib.so` should be referenced in the build file by ``. ```rust,ignore -extern crate bindgen; - use std::env; use std::path::PathBuf; From df984e2dfc0ae5088a00afdd82916dd50f82ec60 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Fri, 2 Jun 2023 22:17:24 +0200 Subject: [PATCH 516/942] replace inappropriate markup (#2532) --- book/src/non-system-libraries.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/book/src/non-system-libraries.md b/book/src/non-system-libraries.md index c724a2fc77..7d6e4e3d45 100644 --- a/book/src/non-system-libraries.md +++ b/book/src/non-system-libraries.md @@ -1,17 +1,18 @@ Now let's suppose we want to generate bindings for a non-system library. We will be the same crate setup as the previous tutorial. First let's create a new -directory `hello` with two files inside it. A `c` source file `hello.c` +directory `hello` with two files inside it. A C source file `hello.c` containing ```c int hello() { return 42; } ``` -and a `c` header file `hello.h` containing +and a C header file `hello.h` containing ```c int hello(); ``` -given that the library has not been compiled yet, we need to modify the + +Given that the library has not been compiled yet, we need to modify the `build.rs` build script to compile the `hello.c` source file into a static libary: @@ -103,4 +104,3 @@ fn main() { .expect("Couldn't write bindings!"); } ``` - From 26d672e18dbcfc6500a20fbd5ee0765bf639ce91 Mon Sep 17 00:00:00 2001 From: Ryan Lopopolo Date: Fri, 2 Jun 2023 13:17:55 -0700 Subject: [PATCH 517/942] Restore prettyplease feature gate to bindgen library crate (#2537) This is a partial revert of these two PRs: - https://github.com/rust-lang/rust-bindgen/pull/2491 - https://github.com/rust-lang/rust-bindgen/pull/2505 Allow formatting of generated bindings and the inclusion of the `prettyplease` dependency to be optional when depending on bindgen as a library. `prettyplease` remains required and enabled by bindgen-cli. In a project I maintain, `bindgen` is used in a build script to generate bindings for a native C library. Those bindings are written to `OUT_DIR` and are `include!`'d into the crate sources; these bindings don't need to be formatted. See for additional context: - https://github.com/rust-lang/rust-bindgen/pull/2491#issuecomment-1558266335 - https://github.com/rust-lang/rust-bindgen/pull/2491#issuecomment-1559699924 - https://github.com/rust-lang/rust-bindgen/pull/2491#issuecomment-1562248014 I tested all of the following locally: ```shell cd bindgen cargo check cargo check --no-default-features cargo check --no-default-features --features prettyplease ``` The CI steps added in rust-lang/rust-bindgen#2506 should be sufficient for maintaining the correctness of these conditional compilation features. --- CHANGELOG.md | 4 +++- bindgen/Cargo.toml | 4 ++-- bindgen/lib.rs | 4 ++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a611ea4080..aac313e76a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -184,7 +184,9 @@ them. To make the escaping clear and consistent, backslashes are also escaped. * Updated `bitflags` dependency to 2.2.1. This changes the API of `CodegenConfig`. - +* Prettyplease formatting is gated by an optional, enabled by default Cargo + feature when depending on `bindgen` as a library. + ## Removed ## Fixed diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index fd20049e78..eeaccf84ee 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -35,7 +35,7 @@ quote = { version = "1", default-features = false } syn = { version = "2.0", features = ["full", "extra-traits", "visit-mut"]} regex = { version = "1.5", default-features = false , features = ["std", "unicode"] } which = { version = "4.2.1", optional = true, default-features = false } -prettyplease = { version = "0.2.0" } +prettyplease = { version = "0.2.0", optional = true } annotate-snippets = { version = "0.9.1", features = ["color"], optional = true } shlex = "1" rustc-hash = "1.0.1" @@ -43,7 +43,7 @@ proc-macro2 = { version = "1", default-features = false } log = { version = "0.4", optional = true } [features] -default = ["logging", "runtime", "which-rustfmt"] +default = ["logging", "prettyplease", "runtime", "which-rustfmt"] logging = ["log"] static = ["clang-sys/static"] runtime = ["clang-sys/runtime"] diff --git a/bindgen/lib.rs b/bindgen/lib.rs index e4b71b0496..2eb4486dac 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -172,6 +172,7 @@ pub enum Formatter { None, /// Use `rustfmt` to format the bindings. Rustfmt, + #[cfg(feature = "prettyplease")] /// Use `prettyplease` to format the bindings. Prettyplease, } @@ -189,6 +190,7 @@ impl FromStr for Formatter { match s { "none" => Ok(Self::None), "rustfmt" => Ok(Self::Rustfmt), + #[cfg(feature = "prettyplease")] "prettyplease" => Ok(Self::Prettyplease), _ => Err(format!("`{}` is not a valid formatter", s)), } @@ -200,6 +202,7 @@ impl std::fmt::Display for Formatter { let s = match self { Self::None => "none", Self::Rustfmt => "rustfmt", + #[cfg(feature = "prettyplease")] Self::Prettyplease => "prettyplease", }; @@ -964,6 +967,7 @@ impl Bindings { match self.options.formatter { Formatter::None => return Ok(tokens.to_string()), + #[cfg(feature = "prettyplease")] Formatter::Prettyplease => { return Ok(prettyplease::unparse(&syn::parse_quote!(#tokens))); } From 05ebcace15a8784e5a5b1001a3b755b866fac901 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Fri, 2 Jun 2023 22:20:59 +0200 Subject: [PATCH 518/942] remove obsolete comment (#2538) See #2176 --- .github/workflows/bindgen.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 8ab00dcef2..72a34fa06c 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -111,8 +111,6 @@ jobs: runs-on: ${{matrix.os}} strategy: matrix: - # TODO(#1954): These should be run on mac too, but turns out they're - # broken. os: [ubuntu-latest, macos-latest] steps: - uses: actions/checkout@v3 From 4faa3662c6999efc7b4d91e81e166e52f3e717bf Mon Sep 17 00:00:00 2001 From: jethrogb Date: Mon, 5 Jun 2023 21:58:47 +0200 Subject: [PATCH 519/942] Field visibility callback (#2525) * Add test for respect-cxx-access-specs and visibility annotations * Use default visibility for padding fields * Compute visibility of bitfield unit based on actual field visibility * Add callback to override field visibility --------- Co-authored-by: Jethro Beekman --- ...bility_private_respects_cxx_access_spec.rs | 4 +- .../tests/field-visibility-callback.rs | 166 ++++++++++++++++ .../expectations/tests/field-visibility.rs | 179 ++++++++++++++++++ .../expectations/tests/private_fields.rs | 110 +++++++++++ .../tests/headers/field-visibility-callback.h | 9 + .../tests/headers/field-visibility.h | 10 + .../tests/headers/private_fields.hpp | 21 +- bindgen-tests/tests/parse_callbacks/mod.rs | 61 +++++- bindgen/callbacks.rs | 22 +++ bindgen/codegen/mod.rs | 135 ++++++++----- bindgen/codegen/struct_layout.rs | 8 +- bindgen/ir/annotations.rs | 2 +- 12 files changed, 662 insertions(+), 65 deletions(-) create mode 100644 bindgen-tests/tests/expectations/tests/field-visibility-callback.rs create mode 100644 bindgen-tests/tests/expectations/tests/field-visibility.rs create mode 100644 bindgen-tests/tests/headers/field-visibility-callback.h create mode 100644 bindgen-tests/tests/headers/field-visibility.h diff --git a/bindgen-tests/tests/expectations/tests/default_visibility_private_respects_cxx_access_spec.rs b/bindgen-tests/tests/expectations/tests/default_visibility_private_respects_cxx_access_spec.rs index d38790f384..453a3054ae 100644 --- a/bindgen-tests/tests/expectations/tests/default_visibility_private_respects_cxx_access_spec.rs +++ b/bindgen-tests/tests/expectations/tests/default_visibility_private_respects_cxx_access_spec.rs @@ -93,7 +93,7 @@ pub struct Point { #[derive(Debug, Default, Copy, Clone)] pub struct Color { _bitfield_align_1: [u8; 0], - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, + _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, } impl Color { #[inline] @@ -130,7 +130,7 @@ impl Color { } } #[inline] - pub fn new_bitfield_1( + fn new_bitfield_1( r: ::std::os::raw::c_char, g: ::std::os::raw::c_char, b: ::std::os::raw::c_char, diff --git a/bindgen-tests/tests/expectations/tests/field-visibility-callback.rs b/bindgen-tests/tests/expectations/tests/field-visibility-callback.rs new file mode 100644 index 0000000000..9411ccc7a6 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/field-visibility-callback.rs @@ -0,0 +1,166 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[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] + 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]; + 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 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]; + 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 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 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); + } + } +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct my_struct { + pub a: ::std::os::raw::c_int, + private_b: ::std::os::raw::c_int, + _bitfield_align_1: [u8; 0], + _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, + __bindgen_padding_0: [u8; 3usize], +} +#[test] +fn bindgen_test_layout_my_struct() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of:: < my_struct > (), 12usize, concat!("Size of: ", + stringify!(my_struct)) + ); + assert_eq!( + ::std::mem::align_of:: < my_struct > (), 4usize, concat!("Alignment of ", + stringify!(my_struct)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(my_struct), "::", stringify!(a)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).private_b) as usize - ptr as usize }, + 4usize, concat!("Offset of field: ", stringify!(my_struct), "::", + stringify!(private_b)) + ); +} +impl my_struct { + #[inline] + pub fn c(&self) -> ::std::os::raw::c_int { + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u32) } + } + #[inline] + pub fn set_c(&mut self, val: ::std::os::raw::c_int) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + self._bitfield_1.set(0usize, 1u8, val as u64) + } + } + #[inline] + fn private_d(&self) -> ::std::os::raw::c_int { + unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u32) } + } + #[inline] + fn set_private_d(&mut self, val: ::std::os::raw::c_int) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + self._bitfield_1.set(1usize, 1u8, val as u64) + } + } + #[inline] + fn new_bitfield_1( + c: ::std::os::raw::c_int, + private_d: ::std::os::raw::c_int, + ) -> __BindgenBitfieldUnit<[u8; 1usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let c: u32 = unsafe { ::std::mem::transmute(c) }; + c as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 1usize, + 1u8, + { + let private_d: u32 = unsafe { ::std::mem::transmute(private_d) }; + private_d as u64 + }, + ); + __bindgen_bitfield_unit + } +} diff --git a/bindgen-tests/tests/expectations/tests/field-visibility.rs b/bindgen-tests/tests/expectations/tests/field-visibility.rs new file mode 100644 index 0000000000..b4e0620867 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/field-visibility.rs @@ -0,0 +1,179 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[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] + 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]; + 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 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]; + 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 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 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); + } + } +} +#[repr(C)] +#[repr(align(4))] +#[derive(Debug, Default, Copy, Clone)] +pub struct my_struct1 { + _bitfield_align_1: [u8; 0], + _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, + __bindgen_padding_0: [u8; 3usize], +} +#[test] +fn bindgen_test_layout_my_struct1() { + assert_eq!( + ::std::mem::size_of:: < my_struct1 > (), 4usize, concat!("Size of: ", + stringify!(my_struct1)) + ); + assert_eq!( + ::std::mem::align_of:: < my_struct1 > (), 4usize, concat!("Alignment of ", + stringify!(my_struct1)) + ); +} +impl my_struct1 { + #[inline] + fn a(&self) -> ::std::os::raw::c_int { + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u32) } + } + #[inline] + fn set_a(&mut self, val: ::std::os::raw::c_int) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + self._bitfield_1.set(0usize, 1u8, val as u64) + } + } + #[inline] + fn new_bitfield_1(a: ::std::os::raw::c_int) -> __BindgenBitfieldUnit<[u8; 1usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let a: u32 = unsafe { ::std::mem::transmute(a) }; + a as u64 + }, + ); + __bindgen_bitfield_unit + } +} +#[repr(C)] +#[repr(align(4))] +#[derive(Debug, Default, Copy, Clone)] +pub struct my_struct2 { + pub _bitfield_align_1: [u8; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, + pub __bindgen_padding_0: [u8; 3usize], +} +#[test] +fn bindgen_test_layout_my_struct2() { + assert_eq!( + ::std::mem::size_of:: < my_struct2 > (), 4usize, concat!("Size of: ", + stringify!(my_struct2)) + ); + assert_eq!( + ::std::mem::align_of:: < my_struct2 > (), 4usize, concat!("Alignment of ", + stringify!(my_struct2)) + ); +} +impl my_struct2 { + #[inline] + pub fn a(&self) -> ::std::os::raw::c_int { + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u32) } + } + #[inline] + pub fn set_a(&mut self, val: ::std::os::raw::c_int) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + self._bitfield_1.set(0usize, 1u8, val as u64) + } + } + #[inline] + pub fn new_bitfield_1( + a: ::std::os::raw::c_int, + ) -> __BindgenBitfieldUnit<[u8; 1usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let a: u32 = unsafe { ::std::mem::transmute(a) }; + a as u64 + }, + ); + __bindgen_bitfield_unit + } +} diff --git a/bindgen-tests/tests/expectations/tests/private_fields.rs b/bindgen-tests/tests/expectations/tests/private_fields.rs index 3408a9a3aa..120ed85803 100644 --- a/bindgen-tests/tests/expectations/tests/private_fields.rs +++ b/bindgen-tests/tests/expectations/tests/private_fields.rs @@ -483,3 +483,113 @@ impl Default for WithAnonUnion { } } } +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Override { + pub a: ::std::os::raw::c_uint, + ///
+ b: ::std::os::raw::c_uint, + private_c: ::std::os::raw::c_uint, + pub _bitfield_align_1: [u8; 0], + _bitfield_1: __BindgenBitfieldUnit<[u8; 2usize]>, + pub __bindgen_padding_0: u16, +} +#[test] +fn bindgen_test_layout_Override() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of:: < Override > (), 16usize, concat!("Size of: ", + stringify!(Override)) + ); + assert_eq!( + ::std::mem::align_of:: < Override > (), 4usize, concat!("Alignment of ", + stringify!(Override)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, + concat!("Offset of field: ", stringify!(Override), "::", stringify!(a)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 4usize, + concat!("Offset of field: ", stringify!(Override), "::", stringify!(b)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).private_c) as usize - ptr as usize }, + 8usize, concat!("Offset of field: ", stringify!(Override), "::", + stringify!(private_c)) + ); +} +impl Override { + #[inline] + pub fn bf_a(&self) -> ::std::os::raw::c_uint { + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 4u8) as u32) } + } + #[inline] + pub fn set_bf_a(&mut self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + self._bitfield_1.set(0usize, 4u8, val as u64) + } + } + #[inline] + fn bf_b(&self) -> ::std::os::raw::c_uint { + unsafe { ::std::mem::transmute(self._bitfield_1.get(4usize, 4u8) as u32) } + } + #[inline] + fn set_bf_b(&mut self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + self._bitfield_1.set(4usize, 4u8, val as u64) + } + } + #[inline] + fn private_bf_c(&self) -> ::std::os::raw::c_uint { + unsafe { ::std::mem::transmute(self._bitfield_1.get(8usize, 4u8) as u32) } + } + #[inline] + fn set_private_bf_c(&mut self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + self._bitfield_1.set(8usize, 4u8, val as u64) + } + } + #[inline] + fn new_bitfield_1( + bf_a: ::std::os::raw::c_uint, + bf_b: ::std::os::raw::c_uint, + private_bf_c: ::std::os::raw::c_uint, + ) -> __BindgenBitfieldUnit<[u8; 2usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 2usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 4u8, + { + let bf_a: u32 = unsafe { ::std::mem::transmute(bf_a) }; + bf_a as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 4usize, + 4u8, + { + let bf_b: u32 = unsafe { ::std::mem::transmute(bf_b) }; + bf_b as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 8usize, + 4u8, + { + let private_bf_c: u32 = unsafe { + ::std::mem::transmute(private_bf_c) + }; + private_bf_c as u64 + }, + ); + __bindgen_bitfield_unit + } +} diff --git a/bindgen-tests/tests/headers/field-visibility-callback.h b/bindgen-tests/tests/headers/field-visibility-callback.h new file mode 100644 index 0000000000..d2fe3ace80 --- /dev/null +++ b/bindgen-tests/tests/headers/field-visibility-callback.h @@ -0,0 +1,9 @@ +// bindgen-flags: --default-visibility private +// bindgen-parse-callbacks: field-visibility-default-private + +struct my_struct { + int a; + int private_b; + int c: 1; + int private_d: 1; +}; diff --git a/bindgen-tests/tests/headers/field-visibility.h b/bindgen-tests/tests/headers/field-visibility.h new file mode 100644 index 0000000000..adb73159c2 --- /dev/null +++ b/bindgen-tests/tests/headers/field-visibility.h @@ -0,0 +1,10 @@ +// bindgen-flags: --default-visibility private --no-doc-comments + +struct my_struct1 { + int a: 1; +}; + +/**
*/ +struct my_struct2 { + int a: 1; +}; diff --git a/bindgen-tests/tests/headers/private_fields.hpp b/bindgen-tests/tests/headers/private_fields.hpp index 9d55ebcac8..965acde9e8 100644 --- a/bindgen-tests/tests/headers/private_fields.hpp +++ b/bindgen-tests/tests/headers/private_fields.hpp @@ -1,4 +1,6 @@ // bindgen-flags: --respect-cxx-access-specs +// bindgen-parse-callbacks: field-visibility-default-public + class PubPriv { public: int x; @@ -41,4 +43,21 @@ class WithAnonStruct { class WithAnonUnion { union {}; -}; \ No newline at end of file +}; + +class Override { + public: + unsigned int a; + // override with annotation + /**
*/ + unsigned int b; + // override with callback + unsigned int private_c; + + unsigned int bf_a : 4; + // override with annotation + /**
*/ + unsigned int bf_b : 4; + // override with callback + unsigned int private_bf_c : 4; +}; diff --git a/bindgen-tests/tests/parse_callbacks/mod.rs b/bindgen-tests/tests/parse_callbacks/mod.rs index 85082b63f7..fe4c4e5cf2 100644 --- a/bindgen-tests/tests/parse_callbacks/mod.rs +++ b/bindgen-tests/tests/parse_callbacks/mod.rs @@ -1,4 +1,5 @@ use bindgen::callbacks::*; +use bindgen::FieldVisibilityKind; #[derive(Debug)] pub struct RemovePrefixParseCallback { @@ -86,25 +87,65 @@ impl ParseCallbacks for BlocklistedTypeImplementsTrait { } } +#[derive(Debug)] +struct FieldVisibility { + default: FieldVisibilityKind, +} + +/// Implements the `field_visibility` function of the trait by checking if the +/// field name starts with `private_`. If it does it makes it private, if it +/// doesn't it makes it public, taking into account the default visibility. +impl ParseCallbacks for FieldVisibility { + fn field_visibility( + &self, + FieldInfo { field_name, .. }: FieldInfo, + ) -> Option { + match (self.default, field_name.starts_with("private_")) { + (FieldVisibilityKind::Private, false) => { + Some(FieldVisibilityKind::Public) + } + (FieldVisibilityKind::Public, true) => { + Some(FieldVisibilityKind::Private) + } + (FieldVisibilityKind::PublicCrate, _) => unimplemented!(), + _ => None, + } + } +} + pub fn lookup(cb: &str) -> Box { + fn try_strip_prefix<'a>(s: &'a str, prefix: &str) -> Option<&'a str> { + if s.starts_with(prefix) { + Some(&s[prefix.len()..]) + } else { + None + } + } + match cb { "enum-variant-rename" => Box::new(EnumVariantRename), "blocklisted-type-implements-trait" => { Box::new(BlocklistedTypeImplementsTrait) } call_back => { - if call_back.starts_with("remove-function-prefix-") { - let prefix = call_back - .split("remove-function-prefix-") - .last() - .to_owned(); - let lnopc = RemovePrefixParseCallback::new(prefix.unwrap()); + if let Some(prefix) = + try_strip_prefix(call_back, "remove-function-prefix-") + { + let lnopc = RemovePrefixParseCallback::new(prefix); Box::new(lnopc) - } else if call_back.starts_with("prefix-link-name-") { - let prefix = - call_back.split("prefix-link-name-").last().to_owned(); - let plnpc = PrefixLinkNameParseCallback::new(prefix.unwrap()); + } else if let Some(prefix) = + try_strip_prefix(call_back, "prefix-link-name-") + { + let plnpc = PrefixLinkNameParseCallback::new(prefix); Box::new(plnpc) + } else if let Some(default) = + try_strip_prefix(call_back, "field-visibility-default-") + { + Box::new(FieldVisibility { + default: default.parse().expect( + "unable to parse field-visibility-default callback", + ), + }) } else { panic!("Couldn't find name ParseCallbacks: {}", cb) } diff --git a/bindgen/callbacks.rs b/bindgen/callbacks.rs index 582446687c..96c1b19834 100644 --- a/bindgen/callbacks.rs +++ b/bindgen/callbacks.rs @@ -135,6 +135,17 @@ pub trait ParseCallbacks: fmt::Debug { fn process_comment(&self, _comment: &str) -> Option { None } + + /// Potentially override the visibility of a composite type field. + /// + /// Caution: This allows overriding standard C++ visibility inferred by + /// `respect_cxx_access_specs`. + fn field_visibility( + &self, + _info: FieldInfo<'_>, + ) -> Option { + None + } } /// Relevant information about a type to which new derive attributes will be added using @@ -176,3 +187,14 @@ pub enum ItemKind { /// A Variable Var, } + +/// Relevant information about a field for which visibility can be determined using +/// [`ParseCallbacks::field_visibility`]. +#[derive(Debug)] +#[non_exhaustive] +pub struct FieldInfo<'a> { + /// The name of the type. + pub type_name: &'a str, + /// The name of the field. + pub field_name: &'a str, +} diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 47f23193cb..c9cad86bb6 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -19,7 +19,7 @@ use self::struct_layout::StructLayoutTracker; use super::BindgenOptions; -use crate::callbacks::{DeriveInfo, TypeKind as DeriveTypeKind}; +use crate::callbacks::{DeriveInfo, FieldInfo, TypeKind as DeriveTypeKind}; use crate::ir::analysis::{HasVtable, Sizedness}; use crate::ir::annotations::{ Annotations, FieldAccessorKind, FieldVisibilityKind, @@ -1291,6 +1291,7 @@ trait FieldCodegen<'a> { visibility_kind: FieldVisibilityKind, accessor_kind: FieldAccessorKind, parent: &CompInfo, + parent_item: &Item, result: &mut CodegenResult, struct_layout: &mut StructLayoutTracker, fields: &mut F, @@ -1310,6 +1311,7 @@ impl<'a> FieldCodegen<'a> for Field { visibility_kind: FieldVisibilityKind, accessor_kind: FieldAccessorKind, parent: &CompInfo, + parent_item: &Item, result: &mut CodegenResult, struct_layout: &mut StructLayoutTracker, fields: &mut F, @@ -1326,6 +1328,7 @@ impl<'a> FieldCodegen<'a> for Field { visibility_kind, accessor_kind, parent, + parent_item, result, struct_layout, fields, @@ -1339,6 +1342,7 @@ impl<'a> FieldCodegen<'a> for Field { visibility_kind, accessor_kind, parent, + parent_item, result, struct_layout, fields, @@ -1388,6 +1392,7 @@ impl<'a> FieldCodegen<'a> for FieldData { parent_visibility_kind: FieldVisibilityKind, accessor_kind: FieldAccessorKind, parent: &CompInfo, + parent_item: &Item, result: &mut CodegenResult, struct_layout: &mut StructLayoutTracker, fields: &mut F, @@ -1440,10 +1445,11 @@ impl<'a> FieldCodegen<'a> for FieldData { .name() .map(|name| ctx.rust_mangle(name).into_owned()) .expect("Each field should have a name in codegen!"); - let field_ident = ctx.rust_ident_raw(field_name.as_str()); + let field_name = field_name.as_str(); + let field_ident = ctx.rust_ident_raw(field_name); if let Some(padding_field) = - struct_layout.saw_field(&field_name, field_ty, self.offset()) + struct_layout.saw_field(field_name, field_ty, self.offset()) { fields.extend(Some(padding_field)); } @@ -1451,7 +1457,13 @@ impl<'a> FieldCodegen<'a> for FieldData { let visibility = compute_visibility( ctx, self.is_public(), - Some(self.annotations()), + ctx.options().last_callback(|cb| { + cb.field_visibility(FieldInfo { + type_name: &parent_item.canonical_name(ctx), + field_name, + }) + }), + self.annotations(), parent_visibility_kind, ); let accessor_kind = @@ -1485,7 +1497,6 @@ impl<'a> FieldCodegen<'a> for FieldData { let getter_name = ctx.rust_ident_raw(format!("get_{}", field_name)); let mutable_getter_name = ctx.rust_ident_raw(format!("get_{}_mut", field_name)); - let field_name = ctx.rust_ident_raw(field_name); methods.extend(Some(match accessor_kind { FieldAccessorKind::None => unreachable!(), @@ -1493,12 +1504,12 @@ impl<'a> FieldCodegen<'a> for FieldData { quote! { #[inline] pub fn #getter_name(&self) -> & #ty { - &self.#field_name + &self.#field_ident } #[inline] pub fn #mutable_getter_name(&mut self) -> &mut #ty { - &mut self.#field_name + &mut self.#field_ident } } } @@ -1506,12 +1517,12 @@ impl<'a> FieldCodegen<'a> for FieldData { quote! { #[inline] pub unsafe fn #getter_name(&self) -> & #ty { - &self.#field_name + &self.#field_ident } #[inline] pub unsafe fn #mutable_getter_name(&mut self) -> &mut #ty { - &mut self.#field_name + &mut self.#field_ident } } } @@ -1519,7 +1530,7 @@ impl<'a> FieldCodegen<'a> for FieldData { quote! { #[inline] pub fn #getter_name(&self) -> & #ty { - &self.#field_name + &self.#field_ident } } } @@ -1604,27 +1615,28 @@ fn access_specifier( fn compute_visibility( ctx: &BindgenContext, is_declared_public: bool, - annotations: Option<&Annotations>, + callback_override: Option, + annotations: &Annotations, default_kind: FieldVisibilityKind, ) -> FieldVisibilityKind { - match ( - is_declared_public, - ctx.options().respect_cxx_access_specs, - annotations.and_then(|e| e.visibility_kind()), - ) { - (true, true, annotated_visibility) => { - // declared as public, cxx specs are respected - annotated_visibility.unwrap_or(FieldVisibilityKind::Public) - } - (false, true, annotated_visibility) => { - // declared as private, cxx specs are respected - annotated_visibility.unwrap_or(FieldVisibilityKind::Private) - } - (_, false, annotated_visibility) => { - // cxx specs are not respected, declaration does not matter. - annotated_visibility.unwrap_or(default_kind) - } - } + callback_override + .or_else(|| annotations.visibility_kind()) + .unwrap_or_else(|| { + match (is_declared_public, ctx.options().respect_cxx_access_specs) { + (true, true) => { + // declared as public, cxx specs are respected + FieldVisibilityKind::Public + } + (false, true) => { + // declared as private, cxx specs are respected + FieldVisibilityKind::Private + } + (_, false) => { + // cxx specs are not respected, declaration does not matter. + default_kind + } + } + }) } impl<'a> FieldCodegen<'a> for BitfieldUnit { @@ -1636,6 +1648,7 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit { visibility_kind: FieldVisibilityKind, accessor_kind: FieldAccessorKind, parent: &CompInfo, + parent_item: &Item, result: &mut CodegenResult, struct_layout: &mut StructLayoutTracker, fields: &mut F, @@ -1695,7 +1708,7 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit { // the 32 items limitation. let mut generate_ctor = layout.size <= RUST_DERIVE_IN_ARRAY_LIMIT; - let mut all_fields_declared_as_public = true; + let mut unit_visibility = visibility_kind; for bf in self.bitfields() { // Codegen not allowed for anonymous bitfields if bf.name().is_none() { @@ -1708,19 +1721,27 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit { continue; } - all_fields_declared_as_public &= bf.is_public(); let mut bitfield_representable_as_int = true; + let mut bitfield_visibility = visibility_kind; bf.codegen( ctx, visibility_kind, accessor_kind, parent, + parent_item, result, struct_layout, fields, methods, - (&unit_field_name, &mut bitfield_representable_as_int), + ( + &unit_field_name, + &mut bitfield_representable_as_int, + &mut bitfield_visibility, + ), ); + if bitfield_visibility < unit_visibility { + unit_visibility = bitfield_visibility; + } // Generating a constructor requires the bitfield to be representable as an integer. if !bitfield_representable_as_int { @@ -1740,13 +1761,7 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit { ctor_impl = bf.extend_ctor_impl(ctx, param_name, ctor_impl); } - let visibility_kind = compute_visibility( - ctx, - all_fields_declared_as_public, - None, - visibility_kind, - ); - let access_spec = access_specifier(visibility_kind); + let access_spec = access_specifier(unit_visibility); let field = quote! { #access_spec #unit_field_ident : #field_ty , @@ -1787,7 +1802,7 @@ fn bitfield_setter_name( } impl<'a> FieldCodegen<'a> for Bitfield { - type Extra = (&'a str, &'a mut bool); + type Extra = (&'a str, &'a mut bool, &'a mut FieldVisibilityKind); fn codegen( &self, @@ -1795,11 +1810,16 @@ impl<'a> FieldCodegen<'a> for Bitfield { visibility_kind: FieldVisibilityKind, _accessor_kind: FieldAccessorKind, parent: &CompInfo, + parent_item: &Item, _result: &mut CodegenResult, struct_layout: &mut StructLayoutTracker, _fields: &mut F, methods: &mut M, - (unit_field_name, bitfield_representable_as_int): (&'a str, &mut bool), + (unit_field_name, bitfield_representable_as_int, bitfield_visibility): ( + &'a str, + &mut bool, + &'a mut FieldVisibilityKind, + ), ) where F: Extend, M: Extend, @@ -1833,13 +1853,22 @@ impl<'a> FieldCodegen<'a> for Bitfield { let offset = self.offset_into_unit(); let width = self.width() as u8; - let visibility_kind = compute_visibility( + let override_visibility = self.name().and_then(|field_name| { + ctx.options().last_callback(|cb| { + cb.field_visibility(FieldInfo { + type_name: &parent_item.canonical_name(ctx), + field_name, + }) + }) + }); + *bitfield_visibility = compute_visibility( ctx, self.is_public(), - Some(self.annotations()), + override_visibility, + self.annotations(), visibility_kind, ); - let access_spec = access_specifier(visibility_kind); + let access_spec = access_specifier(*bitfield_visibility); if parent.is_union() && !struct_layout.is_rust_union() { methods.extend(Some(quote! { @@ -1933,8 +1962,17 @@ impl CodeGenerator for CompInfo { // the parent too. let is_opaque = item.is_opaque(ctx, &()); let mut fields = vec![]; - let mut struct_layout = - StructLayoutTracker::new(ctx, self, ty, &canonical_name); + let visibility = item + .annotations() + .visibility_kind() + .unwrap_or(ctx.options().default_visibility); + let mut struct_layout = StructLayoutTracker::new( + ctx, + self, + ty, + &canonical_name, + visibility, + ); if !is_opaque { if item.has_vtable_ptr(ctx) { @@ -1983,10 +2021,6 @@ impl CodeGenerator for CompInfo { let mut methods = vec![]; if !is_opaque { - let visibility = item - .annotations() - .visibility_kind() - .unwrap_or(ctx.options().default_visibility); let struct_accessor_kind = item .annotations() .accessor_kind() @@ -1997,6 +2031,7 @@ impl CodeGenerator for CompInfo { visibility, struct_accessor_kind, self, + item, result, &mut struct_layout, &mut fields, diff --git a/bindgen/codegen/struct_layout.rs b/bindgen/codegen/struct_layout.rs index cca4a59b73..5673060361 100644 --- a/bindgen/codegen/struct_layout.rs +++ b/bindgen/codegen/struct_layout.rs @@ -6,6 +6,7 @@ use crate::ir::comp::CompInfo; use crate::ir::context::BindgenContext; use crate::ir::layout::Layout; use crate::ir::ty::{Type, TypeKind}; +use crate::FieldVisibilityKind; use proc_macro2::{self, Ident, Span}; use std::cmp; @@ -26,6 +27,7 @@ pub(crate) struct StructLayoutTracker<'a> { latest_field_layout: Option, max_field_align: usize, last_field_was_bitfield: bool, + visibility: FieldVisibilityKind, } /// Returns a size aligned to a given value. @@ -88,6 +90,7 @@ impl<'a> StructLayoutTracker<'a> { comp: &'a CompInfo, ty: &'a Type, name: &'a str, + visibility: FieldVisibilityKind, ) -> Self { let known_type_layout = ty.layout(ctx); let is_packed = comp.is_packed(ctx, known_type_layout.as_ref()); @@ -97,6 +100,7 @@ impl<'a> StructLayoutTracker<'a> { name, ctx, comp, + visibility, is_packed, known_type_layout, is_rust_union, @@ -397,8 +401,10 @@ impl<'a> StructLayoutTracker<'a> { self.max_field_align = cmp::max(self.max_field_align, layout.align); + let vis = super::access_specifier(self.visibility); + quote! { - pub #padding_field_name : #ty , + #vis #padding_field_name : #ty , } } diff --git a/bindgen/ir/annotations.rs b/bindgen/ir/annotations.rs index 423f6c4b60..d085f5c574 100644 --- a/bindgen/ir/annotations.rs +++ b/bindgen/ir/annotations.rs @@ -9,7 +9,7 @@ use std::str::FromStr; use crate::clang; /// What kind of visibility modifer should be used for a struct or field? -#[derive(Copy, PartialEq, Eq, Clone, Debug)] +#[derive(Copy, PartialEq, Eq, PartialOrd, Ord, Clone, Debug)] pub enum FieldVisibilityKind { /// Fields are marked as private, i.e., struct Foo {bar: bool} Private, From bfc5b7faeb6498a8bed02ba89f2f45400d320b5a Mon Sep 17 00:00:00 2001 From: Urgau <3616612+Urgau@users.noreply.github.com> Date: Mon, 5 Jun 2023 23:49:10 +0200 Subject: [PATCH 520/942] Wrap `va_list` function as variadic function (#2502) * Add more generic version of fnsig_arguments based on iterator * Wrap va_list function as variadic function * Add tests for wrapped va_list fn as variadic * Add tests for wrapped va_list in bindgen-integration * Make an exception for including stdarg.h in the tests * Add wrap_as_variadic_fn in the CHANGELOG.md --- CHANGELOG.md | 2 + bindgen-integration/build.rs | 12 ++ bindgen-integration/src/lib.rs | 8 + .../tests/generated/wrap_static_fns.c | 18 +++ .../expectations/tests/wrap-static-fns.rs | 33 ++++ bindgen-tests/tests/headers/wrap-static-fns.h | 32 ++++ bindgen-tests/tests/parse_callbacks/mod.rs | 10 ++ bindgen-tests/tests/tests.rs | 1 + bindgen/callbacks.rs | 10 ++ bindgen/codegen/mod.rs | 151 +++++++++++++++--- bindgen/codegen/serialize.rs | 116 ++++++++++---- ci/no-includes.sh | 6 +- 12 files changed, 351 insertions(+), 48 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aac313e76a..93072cb4e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -170,6 +170,8 @@ instead of `&[u8]`. (Requires Rust 1.59 or higher.) * Added the `--generate-shell-completions` CLI flag to generate completions for different shells. +* The `--wrap-static-fns` option can now wrap `va_list` functions as variadic functions + with the experimental `wrap_as_variadic_fn` callback. ## Changed diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs index e03f7f9a79..ce4a3200af 100644 --- a/bindgen-integration/build.rs +++ b/bindgen-integration/build.rs @@ -149,6 +149,15 @@ impl Drop for MacroCallback { } } +#[derive(Debug)] +struct WrappedVaListCallback; + +impl ParseCallbacks for WrappedVaListCallback { + fn wrap_as_variadic_fn(&self, name: &str) -> Option { + Some(name.to_owned() + "_wrapped") + } +} + fn setup_macro_test() { cc::Build::new() .cpp(true) @@ -223,10 +232,12 @@ fn setup_wrap_static_fns_test() { let bindings = Builder::default() .header(input_header_file_path_str) .parse_callbacks(Box::new(CargoCallbacks)) + .parse_callbacks(Box::new(WrappedVaListCallback)) .wrap_static_fns(true) .wrap_static_fns_path( out_path.join("wrap_static_fns").display().to_string(), ) + .clang_arg("-DUSE_VA_HEADER") .generate() .expect("Unable to generate bindings"); @@ -242,6 +253,7 @@ fn setup_wrap_static_fns_test() { .arg("-o") .arg(&obj_path) .arg(out_path.join("wrap_static_fns.c")) + .arg("-DUSE_VA_HEADER") .output() .expect("`clang` command error"); if !clang_output.status.success() { diff --git a/bindgen-integration/src/lib.rs b/bindgen-integration/src/lib.rs index e89351c3b3..04f6a5c9de 100755 --- a/bindgen-integration/src/lib.rs +++ b/bindgen-integration/src/lib.rs @@ -320,5 +320,13 @@ fn test_wrap_static_fns() { let tq = extern_bindings::takes_qualified(&(&5 as *const _) as *const _); assert_eq!(5, tq); + + let wv1 = extern_bindings::wrap_as_variadic_fn1_wrapped(0); + assert_eq!(0, wv1); + + let wv1 = extern_bindings::wrap_as_variadic_fn1_wrapped(2, 5, 3); + assert_eq!(8, wv1); + + extern_bindings::wrap_as_variadic_fn2_wrapped(1, 2); } } diff --git a/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c b/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c index 8d6e97aad1..cf1106ec76 100644 --- a/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c +++ b/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c @@ -11,3 +11,21 @@ int takes_alias__extern(func f) { return takes_alias(f); } int takes_qualified__extern(const int *const *arg) { return takes_qualified(arg); } enum foo takes_enum__extern(const enum foo f) { return takes_enum(f); } void nevermore__extern(void) { nevermore(); } +void no_extra_argument__extern(__builtin_va_list va) { no_extra_argument(va); } +int many_va_list__extern(int i, __builtin_va_list va1, __builtin_va_list va2) { return many_va_list(i, va1, va2); } +int wrap_as_variadic_fn1__extern(int i, ...) { + int ret; + va_list ap; + + va_start(ap, i); + ret = wrap_as_variadic_fn1(i, ap); + va_end(ap); + return ret; +} +void wrap_as_variadic_fn2__extern(int i, ...) { + va_list ap; + + va_start(ap, i); + wrap_as_variadic_fn2(i, ap); + va_end(ap); +} diff --git a/bindgen-tests/tests/expectations/tests/wrap-static-fns.rs b/bindgen-tests/tests/expectations/tests/wrap-static-fns.rs index 122f4c9cc8..03f3907ed2 100644 --- a/bindgen-tests/tests/expectations/tests/wrap-static-fns.rs +++ b/bindgen-tests/tests/expectations/tests/wrap-static-fns.rs @@ -50,3 +50,36 @@ extern "C" { #[link_name = "nevermore__extern"] pub fn nevermore(); } +extern "C" { + #[link_name = "no_extra_argument__extern"] + pub fn no_extra_argument(va: *mut __va_list_tag); +} +extern "C" { + #[link_name = "many_va_list__extern"] + pub fn many_va_list( + i: ::std::os::raw::c_int, + va1: *mut __va_list_tag, + va2: *mut __va_list_tag, + ) -> ::std::os::raw::c_int; +} +extern "C" { + #[link_name = "wrap_as_variadic_fn1__extern"] + pub fn wrap_as_variadic_fn1_wrapped( + i: ::std::os::raw::c_int, + ... + ) -> ::std::os::raw::c_int; +} +extern "C" { + #[link_name = "wrap_as_variadic_fn2__extern"] + pub fn wrap_as_variadic_fn2_wrapped(i: ::std::os::raw::c_int, ...); +} +pub type __builtin_va_list = [__va_list_tag; 1usize]; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct __va_list_tag { + pub gp_offset: ::std::os::raw::c_uint, + pub fp_offset: ::std::os::raw::c_uint, + pub overflow_arg_area: *mut ::std::os::raw::c_void, + pub reg_save_area: *mut ::std::os::raw::c_void, + _unused: [u8; 0], +} diff --git a/bindgen-tests/tests/headers/wrap-static-fns.h b/bindgen-tests/tests/headers/wrap-static-fns.h index 85dfeac2af..8dcabe7b30 100644 --- a/bindgen-tests/tests/headers/wrap-static-fns.h +++ b/bindgen-tests/tests/headers/wrap-static-fns.h @@ -1,4 +1,11 @@ // bindgen-flags: --experimental --wrap-static-fns +// bindgen-parse-callbacks: wrap-as-variadic-fn + +// to avoid poluting theexpectation tests we put the stdarg.h behind a conditional +// variable only used in bindgen-integration +#ifdef USE_VA_HEADER +#include +#endif static inline int foo() { return 11; @@ -48,3 +55,28 @@ static inline void nevermore() { static inline int variadic(int x, ...) { return x; } + +static inline void no_extra_argument(__builtin_va_list va) {} + +static inline int many_va_list(int i, __builtin_va_list va1, __builtin_va_list va2) { + return i; +} + +#ifndef USE_VA_HEADER +static inline int wrap_as_variadic_fn1(int i, __builtin_va_list va) { + return i; +} + +static inline void wrap_as_variadic_fn2(int i, __builtin_va_list va) {} +#else +static inline int wrap_as_variadic_fn1(int i, va_list va) { + int res = 0; + + for (int j = 0; j < i; j++) + res += (int) va_arg(va, int); + + return res; +} + +static inline void wrap_as_variadic_fn2(int i, va_list va) {} +#endif diff --git a/bindgen-tests/tests/parse_callbacks/mod.rs b/bindgen-tests/tests/parse_callbacks/mod.rs index fe4c4e5cf2..820432baa8 100644 --- a/bindgen-tests/tests/parse_callbacks/mod.rs +++ b/bindgen-tests/tests/parse_callbacks/mod.rs @@ -113,6 +113,15 @@ impl ParseCallbacks for FieldVisibility { } } +#[derive(Debug)] +pub(super) struct WrapAsVariadicFn; + +impl ParseCallbacks for WrapAsVariadicFn { + fn wrap_as_variadic_fn(&self, name: &str) -> Option { + Some(name.to_owned() + "_wrapped") + } +} + pub fn lookup(cb: &str) -> Box { fn try_strip_prefix<'a>(s: &'a str, prefix: &str) -> Option<&'a str> { if s.starts_with(prefix) { @@ -127,6 +136,7 @@ pub fn lookup(cb: &str) -> Box { "blocklisted-type-implements-trait" => { Box::new(BlocklistedTypeImplementsTrait) } + "wrap-as-variadic-fn" => Box::new(WrapAsVariadicFn), call_back => { if let Some(prefix) = try_strip_prefix(call_back, "remove-function-prefix-") diff --git a/bindgen-tests/tests/tests.rs b/bindgen-tests/tests/tests.rs index f83c1a7a8d..895e1cac2c 100644 --- a/bindgen-tests/tests/tests.rs +++ b/bindgen-tests/tests/tests.rs @@ -618,6 +618,7 @@ fn test_wrap_static_fns() { .header("tests/headers/wrap-static-fns.h") .wrap_static_fns(true) .wrap_static_fns_path(generated_path.display().to_string()) + .parse_callbacks(Box::new(parse_callbacks::WrapAsVariadicFn)) .generate() .expect("Failed to generate bindings"); diff --git a/bindgen/callbacks.rs b/bindgen/callbacks.rs index 96c1b19834..a9d315dca7 100644 --- a/bindgen/callbacks.rs +++ b/bindgen/callbacks.rs @@ -146,6 +146,16 @@ pub trait ParseCallbacks: fmt::Debug { ) -> Option { None } + + /// Process a function name that as exactly one `va_list` argument + /// to be wrapped as a variadic function with the wrapped static function + /// feature. + /// + /// The returned string is new function name. + #[cfg(feature = "experimental")] + fn wrap_as_variadic_fn(&self, _name: &str) -> Option { + None + } } /// Relevant information about a type to which new derive attributes will be added using diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index c9cad86bb6..c381f57cb8 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -221,6 +221,11 @@ impl From for Vec<&'static str> { } } +struct WrapAsVariadic { + new_name: String, + idx_of_va_list_arg: usize, +} + struct CodegenResult<'a> { items: Vec, dynamic_items: DynamicItems, @@ -269,7 +274,9 @@ struct CodegenResult<'a> { /// that name. This lets us give each overload a unique suffix. overload_counters: HashMap, - items_to_serialize: Vec, + /// List of items to serialize. With optionally the argument for the wrap as + /// variadic transformation to be applied. + items_to_serialize: Vec<(ItemId, Option)>, } impl<'a> CodegenResult<'a> { @@ -4246,9 +4253,6 @@ impl CodeGenerator for Function { result.saw_function(seen_symbol_name); } - let args = utils::fnsig_arguments(ctx, signature); - let ret = utils::fnsig_return_ty(ctx, signature); - let mut attributes = vec![]; if ctx.options().rust_features().must_use_function { @@ -4333,10 +4337,6 @@ impl CodeGenerator for Function { abi => abi, }; - if is_internal && ctx.options().wrap_static_fns { - result.items_to_serialize.push(item.id()); - } - // Handle overloaded functions by giving each overload its own unique // suffix. let times_seen = result.overload_number(&canonical_name); @@ -4370,12 +4370,49 @@ impl CodeGenerator for Function { quote! { #[link(wasm_import_module = #name)] } }); - if is_internal && ctx.options().wrap_static_fns && !has_link_name_attr { + let should_wrap = + is_internal && ctx.options().wrap_static_fns && !has_link_name_attr; + + if should_wrap { let name = canonical_name.clone() + ctx.wrap_static_fns_suffix(); attributes.push(attributes::link_name::(&name)); } - let ident = ctx.rust_ident(canonical_name); + let wrap_as_variadic = if should_wrap && !signature.is_variadic() { + utils::wrap_as_variadic_fn(ctx, signature, name) + } else { + None + }; + + let (ident, args) = if let Some(WrapAsVariadic { + idx_of_va_list_arg, + new_name, + }) = &wrap_as_variadic + { + ( + new_name, + utils::fnsig_arguments_iter( + ctx, + // Prune argument at index (idx_of_va_list_arg) + signature.argument_types().iter().enumerate().filter_map( + |(idx, t)| { + if idx == *idx_of_va_list_arg { + None + } else { + Some(t) + } + }, + ), + // and replace it by a `...` (variadic symbol and the end of the signature) + true, + ), + ) + } else { + (&canonical_name, utils::fnsig_arguments(ctx, signature)) + }; + let ret = utils::fnsig_return_ty(ctx, signature); + + let ident = ctx.rust_ident(ident); let tokens = quote! { #wasm_link_attribute extern #abi { @@ -4384,6 +4421,13 @@ impl CodeGenerator for Function { } }; + // Add the item to the serialization list if necessary + if should_wrap { + result + .items_to_serialize + .push((item.id(), wrap_as_variadic)); + } + // If we're doing dynamic binding generation, add to the dynamic items. if is_dynamic_function { let args_identifiers = @@ -4886,9 +4930,9 @@ pub(crate) mod utils { writeln!(code, "// Static wrappers\n")?; - for &id in &result.items_to_serialize { - let item = context.resolve_item(id); - item.serialize(context, (), &mut vec![], &mut code)?; + for (id, wrap_as_variadic) in &result.items_to_serialize { + let item = context.resolve_item(*id); + item.serialize(context, wrap_as_variadic, &mut vec![], &mut code)?; } std::fs::write(source_path, code)?; @@ -4896,6 +4940,62 @@ pub(crate) mod utils { Ok(()) } + pub(super) fn wrap_as_variadic_fn( + ctx: &BindgenContext, + signature: &FunctionSig, + name: &str, + ) -> Option { + // Fast path, exclude because: + // - with 0 args: no va_list possible, so no point searching for one + // - with 1 args: cannot have a `va_list` and another arg (required by va_start) + if signature.argument_types().len() <= 1 { + return None; + } + + let mut it = signature.argument_types().iter().enumerate().filter_map( + |(idx, (_name, mut type_id))| { + // Hand rolled visitor that checks for the presence of `va_list` + loop { + let ty = ctx.resolve_type(type_id); + if Some("__builtin_va_list") == ty.name() { + return Some(idx); + } + match ty.kind() { + TypeKind::Alias(type_id_alias) => { + type_id = *type_id_alias + } + TypeKind::ResolvedTypeRef(type_id_typedef) => { + type_id = *type_id_typedef + } + _ => break, + } + } + None + }, + ); + + // Return THE idx (by checking that there is no idx after) + // This is done since we cannot handle multiple `va_list` + it.next().filter(|_| it.next().is_none()).and_then(|idx| { + // Call the `wrap_as_variadic_fn` callback + #[cfg(feature = "experimental")] + { + ctx.options() + .last_callback(|c| c.wrap_as_variadic_fn(name)) + .map(|new_name| super::WrapAsVariadic { + new_name, + idx_of_va_list_arg: idx, + }) + } + #[cfg(not(feature = "experimental"))] + { + let _ = name; + let _ = idx; + None + } + }) + } + pub(crate) fn prepend_bitfield_unit_type( ctx: &BindgenContext, result: &mut Vec, @@ -5260,16 +5360,18 @@ pub(crate) mod utils { fnsig_return_ty_internal(ctx, sig, /* include_arrow = */ true) } - pub(crate) fn fnsig_arguments( + pub(crate) fn fnsig_arguments_iter< + 'a, + I: Iterator, crate::ir::context::TypeId)>, + >( ctx: &BindgenContext, - sig: &FunctionSig, + args_iter: I, + is_variadic: bool, ) -> Vec { use super::ToPtr; let mut unnamed_arguments = 0; - let mut args = sig - .argument_types() - .iter() + let mut args = args_iter .map(|&(ref name, ty)| { let arg_item = ctx.resolve_item(ty); let arg_ty = arg_item.kind().expect_type(); @@ -5326,13 +5428,24 @@ pub(crate) mod utils { }) .collect::>(); - if sig.is_variadic() { + if is_variadic { args.push(quote! { ... }) } args } + pub(crate) fn fnsig_arguments( + ctx: &BindgenContext, + sig: &FunctionSig, + ) -> Vec { + fnsig_arguments_iter( + ctx, + sig.argument_types().iter(), + sig.is_variadic(), + ) + } + pub(crate) fn fnsig_argument_identifiers( ctx: &BindgenContext, sig: &FunctionSig, diff --git a/bindgen/codegen/serialize.rs b/bindgen/codegen/serialize.rs index 1136234e05..58e0882faf 100644 --- a/bindgen/codegen/serialize.rs +++ b/bindgen/codegen/serialize.rs @@ -10,7 +10,7 @@ use crate::ir::item::ItemCanonicalName; use crate::ir::item_kind::ItemKind; use crate::ir::ty::{FloatKind, Type, TypeKind}; -use super::CodegenError; +use super::{CodegenError, WrapAsVariadic}; fn get_loc(item: &Item) -> String { item.location() @@ -18,7 +18,7 @@ fn get_loc(item: &Item) -> String { .unwrap_or_else(|| "unknown".to_owned()) } -pub(crate) trait CSerialize<'a> { +pub(super) trait CSerialize<'a> { type Extra; fn serialize( @@ -31,18 +31,18 @@ pub(crate) trait CSerialize<'a> { } impl<'a> CSerialize<'a> for Item { - type Extra = (); + type Extra = &'a Option; fn serialize( &self, ctx: &BindgenContext, - (): Self::Extra, + extra: Self::Extra, stack: &mut Vec, writer: &mut W, ) -> Result<(), CodegenError> { match self.kind() { ItemKind::Function(func) => { - func.serialize(ctx, self, stack, writer) + func.serialize(ctx, (self, extra), stack, writer) } kind => Err(CodegenError::Serialize { msg: format!("Cannot serialize item kind {:?}", kind), @@ -53,12 +53,12 @@ impl<'a> CSerialize<'a> for Item { } impl<'a> CSerialize<'a> for Function { - type Extra = &'a Item; + type Extra = (&'a Item, &'a Option); fn serialize( &self, ctx: &BindgenContext, - item: Self::Extra, + (item, wrap_as_variadic): Self::Extra, stack: &mut Vec, writer: &mut W, ) -> Result<(), CodegenError> { @@ -85,19 +85,30 @@ impl<'a> CSerialize<'a> for Function { let args = { let mut count = 0; + let idx_to_prune = wrap_as_variadic.as_ref().map( + |WrapAsVariadic { + idx_of_va_list_arg, .. + }| *idx_of_va_list_arg, + ); + signature .argument_types() .iter() .cloned() - .map(|(opt_name, type_id)| { - ( - opt_name.unwrap_or_else(|| { - let name = format!("arg_{}", count); - count += 1; - name - }), - type_id, - ) + .enumerate() + .filter_map(|(idx, (opt_name, type_id))| { + if Some(idx) == idx_to_prune { + None + } else { + Some(( + opt_name.unwrap_or_else(|| { + let name = format!("arg_{}", count); + count += 1; + name + }), + type_id, + )) + } }) .collect::>() }; @@ -106,33 +117,82 @@ impl<'a> CSerialize<'a> for Function { let wrap_name = format!("{}{}", name, ctx.wrap_static_fns_suffix()); // The function's return type - let ret_ty = { + let (ret_item, ret_ty) = { let type_id = signature.return_type(); - let item = ctx.resolve_item(type_id); - let ret_ty = item.expect_type(); + let ret_item = ctx.resolve_item(type_id); + let ret_ty = ret_item.expect_type(); // Write `ret_ty`. - ret_ty.serialize(ctx, item, stack, writer)?; + ret_ty.serialize(ctx, ret_item, stack, writer)?; - ret_ty + (ret_item, ret_ty) }; + const INDENT: &str = " "; + // Write `wrap_name(args`. write!(writer, " {}(", wrap_name)?; serialize_args(&args, ctx, writer)?; - // Write `) { name(` if the function returns void and `) { return name(` if it does not. - if ret_ty.is_void() { - write!(writer, ") {{ {}(", name)?; + if wrap_as_variadic.is_none() { + // Write `) { name(` if the function returns void and `) { return name(` if it does not. + if ret_ty.is_void() { + write!(writer, ") {{ {}(", name)?; + } else { + write!(writer, ") {{ return {}(", name)?; + } } else { - write!(writer, ") {{ return {}(", name)?; + // Write `, ...) {` + writeln!(writer, ", ...) {{")?; + + // Declare the return type `RET_TY ret;` if their is a need to do so + if !ret_ty.is_void() { + write!(writer, "{INDENT}")?; + ret_ty.serialize(ctx, ret_item, stack, writer)?; + writeln!(writer, " ret;")?; + } + + // Setup va_list + writeln!(writer, "{INDENT}va_list ap;\n")?; + writeln!( + writer, + "{INDENT}va_start(ap, {});", + args.last().unwrap().0 + )?; + + write!(writer, "{INDENT}")?; + // Write `ret = name(` or `name(` depending if the function returns something + if !ret_ty.is_void() { + write!(writer, "ret = ")?; + } + write!(writer, "{}(", name)?; } - // Write `arg_names); }`. - serialize_sep(", ", args.iter(), ctx, writer, |(name, _), _, buf| { + // Get the arguments names and insert at the right place if necessary `ap` + let mut args: Vec<_> = args.into_iter().map(|(name, _)| name).collect(); + if let Some(WrapAsVariadic { + idx_of_va_list_arg, .. + }) = wrap_as_variadic + { + args.insert(*idx_of_va_list_arg, "ap".to_owned()); + } + + // Write `arg_names);`. + serialize_sep(", ", args.iter(), ctx, writer, |name, _, buf| { write!(buf, "{}", name).map_err(From::from) })?; - writeln!(writer, "); }}")?; + #[rustfmt::skip] + write!(writer, ");{}", if wrap_as_variadic.is_none() { " " } else { "\n" })?; + + if wrap_as_variadic.is_some() { + // End va_list and return the result if their is one + writeln!(writer, "{INDENT}va_end(ap);")?; + if !ret_ty.is_void() { + writeln!(writer, "{INDENT}return ret;")?; + } + } + + writeln!(writer, "}}")?; Ok(()) } diff --git a/ci/no-includes.sh b/ci/no-includes.sh index 97966cb090..32c20059e0 100755 --- a/ci/no-includes.sh +++ b/ci/no-includes.sh @@ -1,13 +1,17 @@ #!/usr/bin/env bash # Don't allow any system include directives in tests. +# +# We make an exception for stdarg.h which is used for +# the wrapped va_list feature. stdarg.h is available since C89 +# therefor not having this header is a sign of a bigger issue. set -eu cd "$(dirname "$0")/.." echo "Checking for #include directives of system headers..." -grep -rn '#include\s*<.*>' bindgen-tests/tests/headers || { +grep -rn '#include\s*<(?!stdarg).*>' bindgen-tests/tests/headers || { echo "Found none; OK!" exit 0 } From 83f729f44819459665832459cb86b68b4fc3739f Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 9 Jun 2023 13:57:05 +0200 Subject: [PATCH 521/942] Parse code by source order. (#2543) --- CHANGELOG.md | 2 + .../expectations/tests/allowlist-file.rs | 2 +- .../expectations/tests/jsval_layout_opaque.rs | 4 +- .../tests/jsval_layout_opaque_1_0.rs | 4 +- .../tests/expectations/tests/layout_arp.rs | 14 +-- .../tests/expectations/tests/layout_array.rs | 14 +-- .../expectations/tests/layout_eth_conf.rs | 50 +++++----- .../expectations/tests/layout_eth_conf_1_0.rs | 50 +++++----- .../tests/expectations/tests/namespace.rs | 4 +- ...mplate_instantiation_with_fn_local_type.rs | 30 +++--- bindgen/clang.rs | 97 +++++++++++++++++++ bindgen/deps.rs | 2 +- bindgen/ir/context.rs | 38 ++++++-- bindgen/ir/item.rs | 8 +- bindgen/ir/module.rs | 5 +- bindgen/lib.rs | 7 +- 16 files changed, 231 insertions(+), 100 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 93072cb4e7..610c2cfcca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -188,6 +188,8 @@ * Updated `bitflags` dependency to 2.2.1. This changes the API of `CodegenConfig`. * Prettyplease formatting is gated by an optional, enabled by default Cargo feature when depending on `bindgen` as a library. +* Items are now parsed in the order they appear in source files. This may result in + auto-generated `_bindgen_*` names having a different index. ## Removed diff --git a/bindgen-tests/tests/expectations/tests/allowlist-file.rs b/bindgen-tests/tests/expectations/tests/allowlist-file.rs index 1ee7a192ed..63953ccb67 100644 --- a/bindgen-tests/tests/expectations/tests/allowlist-file.rs +++ b/bindgen-tests/tests/expectations/tests/allowlist-file.rs @@ -1,5 +1,4 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -pub const SOME_DEFUN: u32 = 123; extern "C" { #[link_name = "\u{1}_Z12SomeFunctionv"] pub fn SomeFunction(); @@ -7,6 +6,7 @@ extern "C" { extern "C" { pub static mut someVar: ::std::os::raw::c_int; } +pub const SOME_DEFUN: u32 = 123; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct someClass { diff --git a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs index cfbf2f61cc..4ec58e7825 100644 --- a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs +++ b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs @@ -84,8 +84,6 @@ where } } pub const JSVAL_TAG_SHIFT: u32 = 47; -pub const JSVAL_PAYLOAD_MASK: u64 = 140737488355327; -pub const JSVAL_TAG_MASK: i64 = -140737488355328; #[repr(u8)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum JSValueType { @@ -127,6 +125,8 @@ pub enum JSValueShiftedTag { JSVAL_SHIFTED_TAG_NULL = 18445477436314353664, JSVAL_SHIFTED_TAG_OBJECT = 18445618173802708992, } +pub const JSVAL_PAYLOAD_MASK: u64 = 140737488355327; +pub const JSVAL_TAG_MASK: i64 = -140737488355328; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum JSWhyMagic { diff --git a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs index b97bbac96f..fa55d5c1ce 100644 --- a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs @@ -127,8 +127,6 @@ impl ::std::cmp::PartialEq for __BindgenUnionField { } impl ::std::cmp::Eq for __BindgenUnionField {} pub const JSVAL_TAG_SHIFT: u32 = 47; -pub const JSVAL_PAYLOAD_MASK: u64 = 140737488355327; -pub const JSVAL_TAG_MASK: i64 = -140737488355328; #[repr(u8)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum JSValueType { @@ -170,6 +168,8 @@ pub enum JSValueShiftedTag { JSVAL_SHIFTED_TAG_NULL = 18445477436314353664, JSVAL_SHIFTED_TAG_OBJECT = 18445618173802708992, } +pub const JSVAL_PAYLOAD_MASK: u64 = 140737488355327; +pub const JSVAL_TAG_MASK: i64 = -140737488355328; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum JSWhyMagic { diff --git a/bindgen-tests/tests/expectations/tests/layout_arp.rs b/bindgen-tests/tests/expectations/tests/layout_arp.rs index 1ee045593f..ee6bdf01a8 100644 --- a/bindgen-tests/tests/expectations/tests/layout_arp.rs +++ b/bindgen-tests/tests/expectations/tests/layout_arp.rs @@ -1,12 +1,5 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const ETHER_ADDR_LEN: u32 = 6; -pub const ARP_HRD_ETHER: u32 = 1; -pub const ARP_OP_REQUEST: u32 = 1; -pub const ARP_OP_REPLY: u32 = 2; -pub const ARP_OP_REVREQUEST: u32 = 3; -pub const ARP_OP_REVREPLY: u32 = 4; -pub const ARP_OP_INVREQUEST: u32 = 8; -pub const ARP_OP_INVREPLY: u32 = 9; /** Ethernet address: A universally administered address is uniquely assigned to a device by its manufacturer. The first three octets (in transmission order) contain the @@ -133,3 +126,10 @@ fn bindgen_test_layout_arp_hdr() { stringify!(arp_data)) ); } +pub const ARP_HRD_ETHER: u32 = 1; +pub const ARP_OP_REQUEST: u32 = 1; +pub const ARP_OP_REPLY: u32 = 2; +pub const ARP_OP_REVREQUEST: u32 = 3; +pub const ARP_OP_REVREPLY: u32 = 4; +pub const ARP_OP_INVREQUEST: u32 = 8; +pub const ARP_OP_INVREPLY: u32 = 9; diff --git a/bindgen-tests/tests/expectations/tests/layout_array.rs b/bindgen-tests/tests/expectations/tests/layout_array.rs index d9171be24b..3654c62c7c 100644 --- a/bindgen-tests/tests/expectations/tests/layout_array.rs +++ b/bindgen-tests/tests/expectations/tests/layout_array.rs @@ -1,13 +1,6 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const RTE_CACHE_LINE_SIZE: u32 = 64; pub const RTE_MEMPOOL_OPS_NAMESIZE: u32 = 32; -pub const RTE_MEMPOOL_MAX_OPS_IDX: u32 = 16; -pub const RTE_HEAP_NUM_FREELISTS: u32 = 13; -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct rte_mempool { - _unused: [u8; 0], -} /** Prototype for implementation specific data provisioning function. The function should provide the implementation specific memory for @@ -19,6 +12,11 @@ pub struct rte_mempool { pub type rte_mempool_alloc_t = ::std::option::Option< unsafe extern "C" fn(mp: *mut rte_mempool) -> ::std::os::raw::c_int, >; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct rte_mempool { + _unused: [u8; 0], +} /// Free the opaque private data pointed to by mp->pool_data pointer. pub type rte_mempool_free_t = ::std::option::Option< unsafe extern "C" fn(mp: *mut rte_mempool), @@ -118,6 +116,7 @@ impl ::std::cmp::PartialEq for rte_mempool_ops { && self.get_count == other.get_count } } +pub const RTE_MEMPOOL_MAX_OPS_IDX: u32 = 16; /// The rte_spinlock_t type. #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] @@ -199,6 +198,7 @@ impl Default for rte_mempool_ops_table { } } } +pub const RTE_HEAP_NUM_FREELISTS: u32 = 13; /// Structure to hold malloc heap #[repr(C)] #[repr(align(64))] diff --git a/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs b/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs index 1ec0744f0d..0916a16b85 100644 --- a/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs +++ b/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs @@ -90,31 +90,6 @@ pub const ETH_VMDQ_MAX_VLAN_FILTERS: u32 = 64; pub const ETH_DCB_NUM_USER_PRIORITIES: u32 = 8; pub const ETH_VMDQ_DCB_NUM_QUEUES: u32 = 128; pub const ETH_DCB_NUM_QUEUES: u32 = 128; -pub const RTE_ETH_FDIR_MAX_FLEXLEN: u32 = 16; -pub const RTE_ETH_INSET_SIZE_MAX: u32 = 128; -pub const RTE_ETH_FLOW_UNKNOWN: u32 = 0; -pub const RTE_ETH_FLOW_RAW: u32 = 1; -pub const RTE_ETH_FLOW_IPV4: u32 = 2; -pub const RTE_ETH_FLOW_FRAG_IPV4: u32 = 3; -pub const RTE_ETH_FLOW_NONFRAG_IPV4_TCP: u32 = 4; -pub const RTE_ETH_FLOW_NONFRAG_IPV4_UDP: u32 = 5; -pub const RTE_ETH_FLOW_NONFRAG_IPV4_SCTP: u32 = 6; -pub const RTE_ETH_FLOW_NONFRAG_IPV4_OTHER: u32 = 7; -pub const RTE_ETH_FLOW_IPV6: u32 = 8; -pub const RTE_ETH_FLOW_FRAG_IPV6: u32 = 9; -pub const RTE_ETH_FLOW_NONFRAG_IPV6_TCP: u32 = 10; -pub const RTE_ETH_FLOW_NONFRAG_IPV6_UDP: u32 = 11; -pub const RTE_ETH_FLOW_NONFRAG_IPV6_SCTP: u32 = 12; -pub const RTE_ETH_FLOW_NONFRAG_IPV6_OTHER: u32 = 13; -pub const RTE_ETH_FLOW_L2_PAYLOAD: u32 = 14; -pub const RTE_ETH_FLOW_IPV6_EX: u32 = 15; -pub const RTE_ETH_FLOW_IPV6_TCP_EX: u32 = 16; -pub const RTE_ETH_FLOW_IPV6_UDP_EX: u32 = 17; -pub const RTE_ETH_FLOW_PORT: u32 = 18; -pub const RTE_ETH_FLOW_VXLAN: u32 = 19; -pub const RTE_ETH_FLOW_GENEVE: u32 = 20; -pub const RTE_ETH_FLOW_NVGRE: u32 = 21; -pub const RTE_ETH_FLOW_MAX: u32 = 22; #[repr(u32)] /** A set of values to identify what method is to be used to route packets to multiple queues.*/ @@ -1214,6 +1189,8 @@ pub enum rte_eth_payload_type { RTE_ETH_L4_PAYLOAD = 4, RTE_ETH_PAYLOAD_MAX = 8, } +pub const RTE_ETH_FDIR_MAX_FLEXLEN: u32 = 16; +pub const RTE_ETH_INSET_SIZE_MAX: u32 = 128; /** A structure used to select bytes extracted from the protocol layers to flexible payload for filter*/ #[repr(C)] @@ -1286,6 +1263,29 @@ fn bindgen_test_layout_rte_eth_fdir_flex_mask() { stringify!(mask)) ); } +pub const RTE_ETH_FLOW_UNKNOWN: u32 = 0; +pub const RTE_ETH_FLOW_RAW: u32 = 1; +pub const RTE_ETH_FLOW_IPV4: u32 = 2; +pub const RTE_ETH_FLOW_FRAG_IPV4: u32 = 3; +pub const RTE_ETH_FLOW_NONFRAG_IPV4_TCP: u32 = 4; +pub const RTE_ETH_FLOW_NONFRAG_IPV4_UDP: u32 = 5; +pub const RTE_ETH_FLOW_NONFRAG_IPV4_SCTP: u32 = 6; +pub const RTE_ETH_FLOW_NONFRAG_IPV4_OTHER: u32 = 7; +pub const RTE_ETH_FLOW_IPV6: u32 = 8; +pub const RTE_ETH_FLOW_FRAG_IPV6: u32 = 9; +pub const RTE_ETH_FLOW_NONFRAG_IPV6_TCP: u32 = 10; +pub const RTE_ETH_FLOW_NONFRAG_IPV6_UDP: u32 = 11; +pub const RTE_ETH_FLOW_NONFRAG_IPV6_SCTP: u32 = 12; +pub const RTE_ETH_FLOW_NONFRAG_IPV6_OTHER: u32 = 13; +pub const RTE_ETH_FLOW_L2_PAYLOAD: u32 = 14; +pub const RTE_ETH_FLOW_IPV6_EX: u32 = 15; +pub const RTE_ETH_FLOW_IPV6_TCP_EX: u32 = 16; +pub const RTE_ETH_FLOW_IPV6_UDP_EX: u32 = 17; +pub const RTE_ETH_FLOW_PORT: u32 = 18; +pub const RTE_ETH_FLOW_VXLAN: u32 = 19; +pub const RTE_ETH_FLOW_GENEVE: u32 = 20; +pub const RTE_ETH_FLOW_NVGRE: u32 = 21; +pub const RTE_ETH_FLOW_MAX: u32 = 22; /** A structure used to define all flexible payload related setting include flex payload and flex mask*/ #[repr(C)] diff --git a/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs b/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs index 086384c450..c20732c604 100644 --- a/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs @@ -133,31 +133,6 @@ pub const ETH_VMDQ_MAX_VLAN_FILTERS: u32 = 64; pub const ETH_DCB_NUM_USER_PRIORITIES: u32 = 8; pub const ETH_VMDQ_DCB_NUM_QUEUES: u32 = 128; pub const ETH_DCB_NUM_QUEUES: u32 = 128; -pub const RTE_ETH_FDIR_MAX_FLEXLEN: u32 = 16; -pub const RTE_ETH_INSET_SIZE_MAX: u32 = 128; -pub const RTE_ETH_FLOW_UNKNOWN: u32 = 0; -pub const RTE_ETH_FLOW_RAW: u32 = 1; -pub const RTE_ETH_FLOW_IPV4: u32 = 2; -pub const RTE_ETH_FLOW_FRAG_IPV4: u32 = 3; -pub const RTE_ETH_FLOW_NONFRAG_IPV4_TCP: u32 = 4; -pub const RTE_ETH_FLOW_NONFRAG_IPV4_UDP: u32 = 5; -pub const RTE_ETH_FLOW_NONFRAG_IPV4_SCTP: u32 = 6; -pub const RTE_ETH_FLOW_NONFRAG_IPV4_OTHER: u32 = 7; -pub const RTE_ETH_FLOW_IPV6: u32 = 8; -pub const RTE_ETH_FLOW_FRAG_IPV6: u32 = 9; -pub const RTE_ETH_FLOW_NONFRAG_IPV6_TCP: u32 = 10; -pub const RTE_ETH_FLOW_NONFRAG_IPV6_UDP: u32 = 11; -pub const RTE_ETH_FLOW_NONFRAG_IPV6_SCTP: u32 = 12; -pub const RTE_ETH_FLOW_NONFRAG_IPV6_OTHER: u32 = 13; -pub const RTE_ETH_FLOW_L2_PAYLOAD: u32 = 14; -pub const RTE_ETH_FLOW_IPV6_EX: u32 = 15; -pub const RTE_ETH_FLOW_IPV6_TCP_EX: u32 = 16; -pub const RTE_ETH_FLOW_IPV6_UDP_EX: u32 = 17; -pub const RTE_ETH_FLOW_PORT: u32 = 18; -pub const RTE_ETH_FLOW_VXLAN: u32 = 19; -pub const RTE_ETH_FLOW_GENEVE: u32 = 20; -pub const RTE_ETH_FLOW_NVGRE: u32 = 21; -pub const RTE_ETH_FLOW_MAX: u32 = 22; #[repr(u32)] /** A set of values to identify what method is to be used to route packets to multiple queues.*/ @@ -1327,6 +1302,8 @@ pub enum rte_eth_payload_type { RTE_ETH_L4_PAYLOAD = 4, RTE_ETH_PAYLOAD_MAX = 8, } +pub const RTE_ETH_FDIR_MAX_FLEXLEN: u32 = 16; +pub const RTE_ETH_INSET_SIZE_MAX: u32 = 128; /** A structure used to select bytes extracted from the protocol layers to flexible payload for filter*/ #[repr(C)] @@ -1409,6 +1386,29 @@ impl Clone for rte_eth_fdir_flex_mask { *self } } +pub const RTE_ETH_FLOW_UNKNOWN: u32 = 0; +pub const RTE_ETH_FLOW_RAW: u32 = 1; +pub const RTE_ETH_FLOW_IPV4: u32 = 2; +pub const RTE_ETH_FLOW_FRAG_IPV4: u32 = 3; +pub const RTE_ETH_FLOW_NONFRAG_IPV4_TCP: u32 = 4; +pub const RTE_ETH_FLOW_NONFRAG_IPV4_UDP: u32 = 5; +pub const RTE_ETH_FLOW_NONFRAG_IPV4_SCTP: u32 = 6; +pub const RTE_ETH_FLOW_NONFRAG_IPV4_OTHER: u32 = 7; +pub const RTE_ETH_FLOW_IPV6: u32 = 8; +pub const RTE_ETH_FLOW_FRAG_IPV6: u32 = 9; +pub const RTE_ETH_FLOW_NONFRAG_IPV6_TCP: u32 = 10; +pub const RTE_ETH_FLOW_NONFRAG_IPV6_UDP: u32 = 11; +pub const RTE_ETH_FLOW_NONFRAG_IPV6_SCTP: u32 = 12; +pub const RTE_ETH_FLOW_NONFRAG_IPV6_OTHER: u32 = 13; +pub const RTE_ETH_FLOW_L2_PAYLOAD: u32 = 14; +pub const RTE_ETH_FLOW_IPV6_EX: u32 = 15; +pub const RTE_ETH_FLOW_IPV6_TCP_EX: u32 = 16; +pub const RTE_ETH_FLOW_IPV6_UDP_EX: u32 = 17; +pub const RTE_ETH_FLOW_PORT: u32 = 18; +pub const RTE_ETH_FLOW_VXLAN: u32 = 19; +pub const RTE_ETH_FLOW_GENEVE: u32 = 20; +pub const RTE_ETH_FLOW_NVGRE: u32 = 21; +pub const RTE_ETH_FLOW_MAX: u32 = 22; /** A structure used to define all flexible payload related setting include flex payload and flex mask*/ #[repr(C)] diff --git a/bindgen-tests/tests/expectations/tests/namespace.rs b/bindgen-tests/tests/expectations/tests/namespace.rs index 83543b851e..a99711b277 100644 --- a/bindgen-tests/tests/expectations/tests/namespace.rs +++ b/bindgen-tests/tests/expectations/tests/namespace.rs @@ -17,7 +17,7 @@ pub mod root { pub fn in_whatever(); } } - pub mod _bindgen_mod_id_17 { + pub mod _bindgen_mod_id_13 { #[allow(unused_imports)] use self::super::super::root; #[repr(C)] @@ -46,7 +46,7 @@ pub mod root { #[repr(C)] #[derive(Debug)] pub struct C { - pub _base: root::_bindgen_mod_id_17::A, + pub _base: root::_bindgen_mod_id_13::A, pub m_c: T, pub m_c_ptr: *mut T, pub m_c_arr: [T; 10usize], diff --git a/bindgen-tests/tests/expectations/tests/template_instantiation_with_fn_local_type.rs b/bindgen-tests/tests/expectations/tests/template_instantiation_with_fn_local_type.rs index ab87b4160b..5816a6c5e9 100644 --- a/bindgen-tests/tests/expectations/tests/template_instantiation_with_fn_local_type.rs +++ b/bindgen-tests/tests/expectations/tests/template_instantiation_with_fn_local_type.rs @@ -4,10 +4,6 @@ pub struct Foo { pub _address: u8, } -extern "C" { - #[link_name = "\u{1}_Z1fv"] - pub fn f(); -} #[test] fn __bindgen_test_layout_Foo_open0_Bar_close0_instantiation() { assert_eq!( @@ -19,6 +15,21 @@ fn __bindgen_test_layout_Foo_open0_Bar_close0_instantiation() { concat!("Alignment of template specialization: ", stringify!(Foo)) ); } +#[test] +fn __bindgen_test_layout_Foo_open0_Boo_close0_instantiation() { + assert_eq!( + ::std::mem::size_of:: < Foo > (), 1usize, + concat!("Size of template specialization: ", stringify!(Foo)) + ); + assert_eq!( + ::std::mem::align_of:: < Foo > (), 1usize, + concat!("Alignment of template specialization: ", stringify!(Foo)) + ); +} +extern "C" { + #[link_name = "\u{1}_Z1fv"] + pub fn f(); +} #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Baz { @@ -34,17 +45,6 @@ fn bindgen_test_layout_Baz() { stringify!(Baz)) ); } -#[test] -fn __bindgen_test_layout_Foo_open0_Boo_close0_instantiation() { - assert_eq!( - ::std::mem::size_of:: < Foo > (), 1usize, - concat!("Size of template specialization: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of:: < Foo > (), 1usize, - concat!("Alignment of template specialization: ", stringify!(Foo)) - ); -} #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Bar { diff --git a/bindgen/clang.rs b/bindgen/clang.rs index 0060213336..0559faf464 100644 --- a/bindgen/clang.rs +++ b/bindgen/clang.rs @@ -6,6 +6,8 @@ use crate::ir::context::BindgenContext; use clang_sys::*; +use std::cmp; + use std::ffi::{CStr, CString}; use std::fmt; use std::hash::Hash; @@ -496,6 +498,44 @@ impl Cursor { } } + /// Traverse this curser's children, sorted by where they appear in source code. + /// + /// Call the given function on each AST node traversed. + pub(crate) fn visit_sorted( + &self, + ctx: &mut BindgenContext, + mut visitor: Visitor, + ) where + Visitor: FnMut(&mut BindgenContext, Cursor) -> CXChildVisitResult, + { + let mut children = self.collect_children(); + + for child in &children { + if child.kind() == CXCursor_InclusionDirective { + if let Some(included_file) = child.get_included_file_name() { + let location = child.location(); + + let (source_file, _, _, offset) = location.location(); + + if let Some(source_file) = source_file.name() { + ctx.add_include(source_file, included_file, offset); + } + } + } + } + + children.sort_by(|child1, child2| { + child1 + .location() + .partial_cmp_with_context(&child2.location(), ctx) + .unwrap_or(std::cmp::Ordering::Equal) + }); + + for child in children { + visitor(ctx, child); + } + } + /// Collect all of this cursor's children into a vec and return them. pub(crate) fn collect_children(&self) -> Vec { let mut children = vec![]; @@ -1524,6 +1564,63 @@ impl SourceLocation { } } +impl SourceLocation { + /// Compare source locations, also considering `#include` directives. + /// + /// Built-in items provided by the compiler (which don't have a source file), + /// are sorted first. Remaining files are sorted by their position in the source file. + /// If the items' source files differ, they are sorted by the position of the first + /// `#include` for their source file. If no source files are included, `None` is returned. + pub(crate) fn partial_cmp_with_context( + &self, + other: &Self, + ctx: &BindgenContext, + ) -> Option { + let (file, _, _, offset) = self.location(); + let (other_file, _, _, other_offset) = other.location(); + + match (file.name(), other_file.name()) { + (Some(file), Some(other_file)) => { + if file == other_file { + return offset.partial_cmp(&other_offset); + } + + let include_location = ctx.included_file_location(&file); + let other_include_location = + ctx.included_file_location(&other_file); + + match (include_location, other_include_location) { + (Some((file2, offset2)), _) if file2 == other_file => { + offset2.partial_cmp(&other_offset) + } + (Some(_), None) => Some(cmp::Ordering::Greater), + (_, Some((other_file2, other_offset2))) + if file == other_file2 => + { + offset.partial_cmp(&other_offset2) + } + (None, Some(_)) => Some(cmp::Ordering::Less), + ( + Some((file2, offset2)), + Some((other_file2, other_offset2)), + ) => { + if file2 == other_file2 { + offset2.partial_cmp(&other_offset2) + } else { + None + } + } + (None, None) => Some(cmp::Ordering::Equal), + } + } + // Built-in definitions should come first. + (Some(_), None) => Some(cmp::Ordering::Greater), + (None, Some(_)) => Some(cmp::Ordering::Less), + (None, None) => Some(cmp::Ordering::Equal), + } + } +} + impl fmt::Display for SourceLocation { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let (file, line, col, _) = self.location(); diff --git a/bindgen/deps.rs b/bindgen/deps.rs index 2edeaa8886..e348fa1303 100644 --- a/bindgen/deps.rs +++ b/bindgen/deps.rs @@ -9,7 +9,7 @@ pub(crate) struct DepfileSpec { impl DepfileSpec { pub fn write(&self, deps: &BTreeSet) -> std::io::Result<()> { - std::fs::write(&self.depfile_path, &self.to_string(deps)) + std::fs::write(&self.depfile_path, self.to_string(deps)) } fn to_string(&self, deps: &BTreeSet) -> String { diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index ee07625430..bc9e59c3f0 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -356,6 +356,14 @@ pub(crate) struct BindgenContext { /// This needs to be an std::HashMap because the cexpr API requires it. parsed_macros: StdHashMap, cexpr::expr::EvalResult>, + /// A map with all include locations. + /// + /// This is needed so that items are created in the order they are defined in. + /// + /// The key is the included file, the value is a pair of the source file and + /// the position of the `#include` directive in the source file. + includes: StdHashMap, + /// A set of all the included filenames. deps: BTreeSet, @@ -560,6 +568,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" BindgenContext { items: vec![Some(root_module)], + includes: Default::default(), deps, types: Default::default(), type_params: Default::default(), @@ -634,12 +643,29 @@ If you encounter an error missing from this list, please file an issue or a PR!" ) } - /// Add another path to the set of included files. - pub(crate) fn include_file(&mut self, filename: String) { - for cb in &self.options().parse_callbacks { - cb.include_file(&filename); - } - self.deps.insert(filename); + /// Add the location of the `#include` directive for the `included_file`. + pub(crate) fn add_include( + &mut self, + source_file: String, + included_file: String, + offset: usize, + ) { + self.includes + .entry(included_file) + .or_insert((source_file, offset)); + } + + /// Get the location of the first `#include` directive for the `included_file`. + pub(crate) fn included_file_location( + &self, + included_file: &str, + ) -> Option<(String, usize)> { + self.includes.get(included_file).cloned() + } + + /// Add an included file. + pub(crate) fn add_dep(&mut self, dep: String) { + self.deps.insert(dep); } /// Get any included files. diff --git a/bindgen/ir/item.rs b/bindgen/ir/item.rs index f4dce45d83..1b9d7694b2 100644 --- a/bindgen/ir/item.rs +++ b/bindgen/ir/item.rs @@ -1460,8 +1460,12 @@ impl Item { cursor ); } - Some(filename) => { - ctx.include_file(filename); + Some(included_file) => { + for cb in &ctx.options().parse_callbacks { + cb.include_file(&included_file); + } + + ctx.add_dep(included_file); } } } diff --git a/bindgen/ir/module.rs b/bindgen/ir/module.rs index f25ef40f77..5ec55e9048 100644 --- a/bindgen/ir/module.rs +++ b/bindgen/ir/module.rs @@ -6,6 +6,7 @@ use super::item::ItemSet; use crate::clang; use crate::parse::{ClangSubItemParser, ParseError, ParseResult}; use crate::parse_one; + use std::io; /// Whether this module is inline or not. @@ -82,8 +83,8 @@ impl ClangSubItemParser for Module { CXCursor_Namespace => { let module_id = ctx.module(cursor); ctx.with_module(module_id, |ctx| { - cursor.visit(|cursor| { - parse_one(ctx, cursor, Some(module_id.into())) + cursor.visit_sorted(ctx, |ctx, child| { + parse_one(ctx, child, Some(module_id.into())) }) }); diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 2eb4486dac..be0cd8266a 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -1085,7 +1085,8 @@ fn parse_one( Ok(..) => {} Err(ParseError::Continue) => {} Err(ParseError::Recurse) => { - cursor.visit(|child| parse_one(ctx, child, parent)); + cursor + .visit_sorted(ctx, |ctx, child| parse_one(ctx, child, parent)); } } CXChildVisit_Continue @@ -1126,8 +1127,8 @@ fn parse(context: &mut BindgenContext) -> Result<(), BindgenError> { } let root = context.root_module(); - context.with_module(root, |context| { - cursor.visit(|cursor| parse_one(context, cursor, None)) + context.with_module(root, |ctx| { + cursor.visit_sorted(ctx, |ctx, child| parse_one(ctx, child, None)) }); assert!( From 2261681f735c735c9a7c0d8e36fdab0ca39c211d Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Sat, 10 Jun 2023 06:36:03 +0200 Subject: [PATCH 522/942] avoid implicit Cargo features (#2539) * avoid implicit Cargo features * cargo sort --- CHANGELOG.md | 6 ++++++ bindgen-cli/Cargo.toml | 4 ++-- bindgen-tests/Cargo.toml | 4 ++-- bindgen-tests/tests/expectations/Cargo.toml | 2 +- bindgen/Cargo.toml | 24 ++++++++++----------- 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 610c2cfcca..2a78cb26c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -190,6 +190,12 @@ feature when depending on `bindgen` as a library. * Items are now parsed in the order they appear in source files. This may result in auto-generated `_bindgen_*` names having a different index. +* Remove redundant Cargo features, which were all implicit: + - bindgen-cli: `env_logger` and `log` removed in favor of `logging` + - bindgen (lib): + + `log` removed in favor of `logging` + + `which` removed in favor of `which-logging` + + `annotate-snippets` removed in favor of `experimental` ## Removed diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index 523a01b767..90e8cc62a4 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -21,15 +21,15 @@ name = "bindgen" [dependencies] bindgen = { path = "../bindgen", version = "=0.65.1", features = ["__cli", "experimental"] } -shlex = "1" clap = { version = "4", features = ["derive"] } clap_complete = "4" env_logger = { version = "0.10.0", optional = true } log = { version = "0.4", optional = true } +shlex = "1" [features] default = ["logging", "runtime", "which-rustfmt"] -logging = ["bindgen/logging", "env_logger", "log"] +logging = ["bindgen/logging", "dep:env_logger", "dep:log"] static = ["bindgen/static"] runtime = ["bindgen/runtime"] # Dynamically discover a `rustfmt` binary using the `which` crate diff --git a/bindgen-tests/Cargo.toml b/bindgen-tests/Cargo.toml index ab53660a0a..eb7e1b1742 100644 --- a/bindgen-tests/Cargo.toml +++ b/bindgen-tests/Cargo.toml @@ -6,10 +6,10 @@ publish = false [dev-dependencies] bindgen = { path = "../bindgen", features = ["__cli", "experimental"] } -diff = "0.1" -shlex = "1" clap = { version = "4", features = ["derive"] } clap_complete = "4" +diff = "0.1" +shlex = "1" prettyplease = { version = "0.2.0" } syn = { version = "2.0" } tempfile = "3" diff --git a/bindgen-tests/tests/expectations/Cargo.toml b/bindgen-tests/tests/expectations/Cargo.toml index 086d0e8c31..bf7da25349 100644 --- a/bindgen-tests/tests/expectations/Cargo.toml +++ b/bindgen-tests/tests/expectations/Cargo.toml @@ -10,6 +10,6 @@ authors = [ edition = "2018" [dependencies] -objc = "0.2" block = "0.1" libloading = "0.7" +objc = "0.2" diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index eeaccf84ee..054c841f9f 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -25,31 +25,31 @@ name = "bindgen" path = "lib.rs" [dependencies] +annotate-snippets = { version = "0.9.1", features = ["color"], optional = true } bitflags = "2.2.1" cexpr = "0.6" clang-sys = { version = "1", features = ["clang_6_0"] } -lazycell = "1" lazy_static = "1" +lazycell = "1" +log = { version = "0.4", optional = true } peeking_take_while = "0.1.2" -quote = { version = "1", default-features = false } -syn = { version = "2.0", features = ["full", "extra-traits", "visit-mut"]} -regex = { version = "1.5", default-features = false , features = ["std", "unicode"] } -which = { version = "4.2.1", optional = true, default-features = false } prettyplease = { version = "0.2.0", optional = true } -annotate-snippets = { version = "0.9.1", features = ["color"], optional = true } -shlex = "1" -rustc-hash = "1.0.1" proc-macro2 = { version = "1", default-features = false } -log = { version = "0.4", optional = true } +quote = { version = "1", default-features = false } +regex = { version = "1.5", default-features = false, features = ["std", "unicode"] } +rustc-hash = "1.0.1" +shlex = "1" +syn = { version = "2.0", features = ["full", "extra-traits", "visit-mut"] } +which = { version = "4.2.1", optional = true, default-features = false } [features] default = ["logging", "prettyplease", "runtime", "which-rustfmt"] -logging = ["log"] +logging = ["dep:log"] static = ["clang-sys/static"] runtime = ["clang-sys/runtime"] # Dynamically discover a `rustfmt` binary using the `which` crate -which-rustfmt = ["which"] -experimental = ["annotate-snippets"] +which-rustfmt = ["dep:which"] +experimental = ["dep:annotate-snippets"] ## The following features are for internal use and they shouldn't be used if ## you're not hacking on bindgen From d56f53d2ad0c9293980ccaccf86a1aa66f2e2539 Mon Sep 17 00:00:00 2001 From: Conner <59540839+TheConner@users.noreply.github.com> Date: Sat, 10 Jun 2023 13:32:49 -0400 Subject: [PATCH 523/942] Add target mappings for riscv32imc and riscv32imac (#2551) Similar problem as the one mentioned in #2136, just continuing by adding the 32 bit risc tuple mappings. Tuples like riscv32imc- and riscv32imac- should map to the clang riscv32- tuple. Fixed by adding mappings and tests for the mappings. Projects that now failed to build the "riscv32imac-unknown-none-elf" target tuple now build without issue. --- CHANGELOG.md | 1 + bindgen/lib.rs | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a78cb26c9..650d055cd6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -196,6 +196,7 @@ + `log` removed in favor of `logging` + `which` removed in favor of `which-logging` + `annotate-snippets` removed in favor of `experimental` +* Add target mappings for riscv32imc and riscv32imac. ## Removed diff --git a/bindgen/lib.rs b/bindgen/lib.rs index be0cd8266a..9d1ebb4599 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -686,6 +686,15 @@ fn rust_to_clang_target(rust_target: &str) -> String { clang_target.strip_prefix("riscv32imc-").unwrap(); } return clang_target; + } else if rust_target.starts_with("riscv32imc-") { + let mut clang_target = "riscv32-".to_owned(); + clang_target.push_str(rust_target.strip_prefix("riscv32imc-").unwrap()); + return clang_target; + } else if rust_target.starts_with("riscv32imac-") { + let mut clang_target = "riscv32-".to_owned(); + clang_target + .push_str(rust_target.strip_prefix("riscv32imac-").unwrap()); + return clang_target; } rust_target.to_owned() } @@ -1285,7 +1294,15 @@ fn test_rust_to_clang_target_riscv() { assert_eq!( rust_to_clang_target("riscv64gc-unknown-linux-gnu"), "riscv64-unknown-linux-gnu" - ) + ); + assert_eq!( + rust_to_clang_target("riscv32imc-unknown-none-elf"), + "riscv32-unknown-none-elf" + ); + assert_eq!( + rust_to_clang_target("riscv32imac-unknown-none-elf"), + "riscv32-unknown-none-elf" + ); } #[test] From 81b3ce74dfbcf0656965c3ece3bb4fb7266c95d1 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Sat, 10 Jun 2023 19:34:18 +0200 Subject: [PATCH 524/942] it's a redirect (#2530) --- book/src/tutorial-3.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/book/src/tutorial-3.md b/book/src/tutorial-3.md index 7a42bf16ee..599ece2708 100644 --- a/book/src/tutorial-3.md +++ b/book/src/tutorial-3.md @@ -50,6 +50,6 @@ fn main() { Now, when we run `cargo build`, our bindings to `bzip2` are generated on the fly! -[There's more info about `build.rs` files in the crates.io documentation.][build-rs] +[There's more info about `build.rs` files in the Cargo documentation.][build-rs] -[build-rs]: http://doc.crates.io/build-script.html +[build-rs]: https://doc.rust-lang.org/cargo/reference/build-scripts.html From df439e94047970cbae7d2b534d2d20143420ced9 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Sat, 10 Jun 2023 19:34:45 +0200 Subject: [PATCH 525/942] fix and simplify language (#2528) --- book/src/tutorial-1.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/book/src/tutorial-1.md b/book/src/tutorial-1.md index 182a777fe7..464b6b9d71 100644 --- a/book/src/tutorial-1.md +++ b/book/src/tutorial-1.md @@ -3,15 +3,14 @@ First we need to declare a build-time dependency on `bindgen` by adding it to the `[build-dependencies]` section of our crate's `Cargo.toml` file. -Please always use the latest version of `bindgen`, it has the most fixes and -best compatibility. At the time of writing the latest bindgen is `0.53.1`, but -you can always check [the bindgen page of -crates.io](https://crates.io/crates/bindgen) to verify the latest version if -you're unsure. +Please always use the latest version of `bindgen`, as it has the most fixes and +best compatibility. +You can always check the latest version at +[the bindgen page in crates.io](https://crates.io/crates/bindgen). ```toml [build-dependencies] -bindgen = "0.53.1" +bindgen = "0.65.1" ``` > ⚠ **Warning** From 9042f42b2e58e1997b8957a762cab552a8708b96 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Wed, 14 Jun 2023 18:42:37 +0200 Subject: [PATCH 526/942] rustfmt cleanup (#2553) Closes #2540 * test-one: use prettyplease to format generated code * contributing: note the prettyplease change, state that it is an optional dependency of bindgen, not bindgen-cli --- CONTRIBUTING.md | 17 ++++++++++------- bindgen-tests/tests/test-one.sh | 7 ++----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 429962ae00..c9e749d1c7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -104,18 +104,18 @@ There are also some integration tests in the `./bindgen-integration` crate, whic generate bindings to some C++ code, and then uses the bindings, asserting that values are what we expect them to be, both on the Rust and C++ side. -The generated and expected bindings are run through `rustfmt` before they are -compared. Make sure you have `rustfmt` up to date: - -``` -$ rustup update nightly -$ rustup component add rustfmt --toolchain nightly -``` +The generated and expected bindings are formatted with [prettyplease] before they are +compared. It is a default (but optional) dependency of `bindgen`, +so be sure to keep that in mind +(if you built `bindgen` with the `--no-default-features` option of Cargo). +Note also that `rustfmt` formatting is disabled for the `bindgen-tests/tests/expectations/` +directory tree, which helps avoid failing ui tests. Note: running `cargo test` from the root directory of `bindgen`'s repository does not automatically test the generated bindings or run the integration tests. These steps must be performed manually when needed. + ### Testing Bindings Generation To regenerate bindings from the corpus of test headers in `bindgen-tests/tests/headers` and @@ -576,3 +576,6 @@ $ git push --tags upstream # To publish the tag ### Create a new release on Github See [Releasing projects on Github](https://docs.github.com/en/repositories/releasing-projects-on-github) + + +[prettyplease]: https://github.com/dtolnay/prettyplease diff --git a/bindgen-tests/tests/test-one.sh b/bindgen-tests/tests/test-one.sh index 163d23a200..5ab6e9a468 100755 --- a/bindgen-tests/tests/test-one.sh +++ b/bindgen-tests/tests/test-one.sh @@ -45,7 +45,7 @@ TEST_BINDINGS_BINARY=$(mktemp -t bindings.XXXXXX) FLAGS="$(grep "// bindgen-flags: " "$TEST" || echo)" FLAGS="${FLAGS/\/\/ bindgen\-flags:/}" # Prepend the default flags added in test.rs's `create_bindgen_builder`. -FLAGS="--rustfmt-bindings --with-derive-default --raw-line '' --raw-line '#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]' --raw-line '' $FLAGS" +FLAGS="--with-derive-default --raw-line '' --raw-line '#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]' --raw-line '' $FLAGS" eval ../target/debug/bindgen \ @@ -53,11 +53,10 @@ eval ../target/debug/bindgen \ --emit-ir \ --emit-ir-graphviz ir.dot \ --emit-clang-ast \ + --formatter prettyplease \ -o "\"$BINDINGS\"" \ $FLAGS -rustup run nightly rustfmt "$BINDINGS" || true - dot -Tpng ir.dot -o ir.png echo @@ -80,8 +79,6 @@ EXPECTED=${TEST/headers/expectations\/tests} EXPECTED=${EXPECTED/.hpp/.rs} EXPECTED=${EXPECTED/.h/.rs} -rustup run nightly rustfmt "$EXPECTED" || true - # Don't exit early if there is a diff. diff -U8 "$EXPECTED" "$BINDINGS" || true From 38a2c93d9445366a0ac7ef5bbdd3aa964d484faf Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Wed, 14 Jun 2023 18:43:23 +0200 Subject: [PATCH 527/942] some doc fixes (#2552) --- CONTRIBUTING.md | 4 ++-- bindgen-cli/options.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c9e749d1c7..4ec1a4c834 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -161,10 +161,10 @@ $ cargo test ### Testing a Single Header's Bindings Generation and Compiling its Bindings -Note: You will to need to install [Graphviz](https://graphviz.org/) since that +Note: You will need to install [Graphviz](https://graphviz.org/) since that is a dependency for running `test-one.sh`. -Sometimes its useful to work with one test header from start (generating +Sometimes it's useful to work with one test header from start (generating bindings for it) to finish (compiling the bindings and running their layout tests). This can be done with the `bindgen-tests/tests/test-one.sh` script. It supports fuzzy searching for test headers. For example, to test diff --git a/bindgen-cli/options.rs b/bindgen-cli/options.rs index 5ddf9ad306..8031a138f9 100644 --- a/bindgen-cli/options.rs +++ b/bindgen-cli/options.rs @@ -872,7 +872,7 @@ where if !path.is_absolute() { return Err(Error::new( ErrorKind::Other, - "--rustfmt-configuration--file needs to be an absolute path!", + "--rustfmt-configuration-file needs to be an absolute path!", )); } From bbeddb657fd33b49d269c9b3a71cb85c7a6c952b Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Wed, 14 Jun 2023 18:48:12 +0200 Subject: [PATCH 528/942] Use `syn::Type` instead of raw `TokenStream`. (#2549) --- bindgen/codegen/error.rs | 15 +- bindgen/codegen/helpers.rs | 140 +++++---- bindgen/codegen/mod.rs | 592 ++++++++++++++----------------------- bindgen/ir/function.rs | 36 ++- bindgen/ir/layout.rs | 16 +- bindgen/ir/ty.rs | 3 +- 6 files changed, 370 insertions(+), 432 deletions(-) diff --git a/bindgen/codegen/error.rs b/bindgen/codegen/error.rs index ead34965ba..2c9bf97680 100644 --- a/bindgen/codegen/error.rs +++ b/bindgen/codegen/error.rs @@ -11,17 +11,26 @@ pub(crate) enum Error { /// definition that is too difficult for us to understand (like a partial /// template specialization). InstantiationOfOpaqueType, + + /// Function ABI is not supported. + UnsupportedAbi(&'static str), } impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.write_str(match *self { Error::NoLayoutForOpaqueBlob => { - "Tried to generate an opaque blob, but had no layout" + "Tried to generate an opaque blob, but had no layout." } Error::InstantiationOfOpaqueType => { - "Instantiation of opaque template type or partial template \ - specialization" + "Instantiation of opaque template type or partial template specialization." + } + Error::UnsupportedAbi(abi) => { + return write!( + f, + "{} ABI is not supported by the configured Rust target.", + abi + ) } }) } diff --git a/bindgen/codegen/helpers.rs b/bindgen/codegen/helpers.rs index 8231e07c11..7ef44fe099 100644 --- a/bindgen/codegen/helpers.rs +++ b/bindgen/codegen/helpers.rs @@ -2,8 +2,6 @@ use crate::ir::context::BindgenContext; use crate::ir::layout::Layout; -use proc_macro2::{Ident, Span, TokenStream}; -use quote::TokenStreamExt; pub(crate) mod attributes { use proc_macro2::{Ident, Span, TokenStream}; @@ -79,33 +77,27 @@ pub(crate) mod attributes { /// Generates a proper type for a field or type with a given `Layout`, that is, /// a type with the correct size and alignment restrictions. -pub(crate) fn blob(ctx: &BindgenContext, layout: Layout) -> TokenStream { +pub(crate) fn blob(ctx: &BindgenContext, layout: Layout) -> syn::Type { let opaque = layout.opaque(); // FIXME(emilio, #412): We fall back to byte alignment, but there are // some things that legitimately are more than 8-byte aligned. // // Eventually we should be able to `unwrap` here, but... - let ty_name = match opaque.known_rust_type_for_array(ctx) { + let ty = match opaque.known_rust_type_for_array(ctx) { Some(ty) => ty, None => { warn!("Found unknown alignment on code generation!"); - "u8" + syn::parse_quote! { u8 } } }; - let ty_name = Ident::new(ty_name, Span::call_site()); - let data_len = opaque.array_size(ctx).unwrap_or(layout.size); if data_len == 1 { - quote! { - #ty_name - } + ty } else { - quote! { - [ #ty_name ; #data_len ] - } + syn::parse_quote! { [ #ty ; #data_len ] } } } @@ -113,80 +105,118 @@ pub(crate) fn blob(ctx: &BindgenContext, layout: Layout) -> TokenStream { pub(crate) fn integer_type( ctx: &BindgenContext, layout: Layout, -) -> Option { - let name = Layout::known_type_for_size(ctx, layout.size)?; - let name = Ident::new(name, Span::call_site()); - Some(quote! { #name }) +) -> Option { + Layout::known_type_for_size(ctx, layout.size) } /// Generates a bitfield allocation unit type for a type with the given `Layout`. -pub(crate) fn bitfield_unit( - ctx: &BindgenContext, - layout: Layout, -) -> TokenStream { - let mut tokens = quote! {}; +pub(crate) fn bitfield_unit(ctx: &BindgenContext, layout: Layout) -> syn::Type { + let size = layout.size; + let ty = syn::parse_quote! { __BindgenBitfieldUnit<[u8; #size]> }; if ctx.options().enable_cxx_namespaces { - tokens.append_all(quote! { root:: }); + return syn::parse_quote! { root::#ty }; } - let size = layout.size; - tokens.append_all(quote! { - __BindgenBitfieldUnit<[u8; #size]> - }); - - tokens + ty } pub(crate) mod ast_ty { use crate::ir::context::BindgenContext; use crate::ir::function::FunctionSig; use crate::ir::layout::Layout; - use crate::ir::ty::FloatKind; + use crate::ir::ty::{FloatKind, IntKind}; use proc_macro2::{self, TokenStream}; use std::str::FromStr; - pub(crate) fn c_void(ctx: &BindgenContext) -> TokenStream { + pub(crate) fn c_void(ctx: &BindgenContext) -> syn::Type { // ctypes_prefix takes precedence match ctx.options().ctypes_prefix { Some(ref prefix) => { let prefix = TokenStream::from_str(prefix.as_str()).unwrap(); - quote! { - #prefix::c_void - } + syn::parse_quote! { #prefix::c_void } } None => { if ctx.options().use_core && ctx.options().rust_features.core_ffi_c_void { - quote! { ::core::ffi::c_void } + syn::parse_quote! { ::core::ffi::c_void } } else { - quote! { ::std::os::raw::c_void } + syn::parse_quote! { ::std::os::raw::c_void } } } } } - pub(crate) fn raw_type(ctx: &BindgenContext, name: &str) -> TokenStream { + pub(crate) fn raw_type(ctx: &BindgenContext, name: &str) -> syn::Type { let ident = ctx.rust_ident_raw(name); match ctx.options().ctypes_prefix { Some(ref prefix) => { let prefix = TokenStream::from_str(prefix.as_str()).unwrap(); - quote! { - #prefix::#ident - } + syn::parse_quote! { #prefix::#ident } } None => { if ctx.options().use_core && ctx.options().rust_features().core_ffi_c { - quote! { - ::core::ffi::#ident - } + syn::parse_quote! { ::core::ffi::#ident } } else { - quote! { - ::std::os::raw::#ident - } + syn::parse_quote! { ::std::os::raw::#ident } + } + } + } + } + + pub(crate) fn int_kind_rust_type( + ctx: &BindgenContext, + ik: IntKind, + layout: Option, + ) -> syn::Type { + match ik { + IntKind::Bool => syn::parse_quote! { bool }, + IntKind::Char { .. } => raw_type(ctx, "c_char"), + IntKind::SChar => raw_type(ctx, "c_schar"), + IntKind::UChar => raw_type(ctx, "c_uchar"), + IntKind::Short => raw_type(ctx, "c_short"), + IntKind::UShort => raw_type(ctx, "c_ushort"), + IntKind::Int => raw_type(ctx, "c_int"), + IntKind::UInt => raw_type(ctx, "c_uint"), + IntKind::Long => raw_type(ctx, "c_long"), + IntKind::ULong => raw_type(ctx, "c_ulong"), + IntKind::LongLong => raw_type(ctx, "c_longlong"), + IntKind::ULongLong => raw_type(ctx, "c_ulonglong"), + IntKind::WChar => { + let layout = + layout.expect("Couldn't compute wchar_t's layout?"); + Layout::known_type_for_size(ctx, layout.size) + .expect("Non-representable wchar_t?") + } + + IntKind::I8 => syn::parse_quote! { i8 }, + IntKind::U8 => syn::parse_quote! { u8 }, + IntKind::I16 => syn::parse_quote! { i16 }, + IntKind::U16 => syn::parse_quote! { u16 }, + IntKind::I32 => syn::parse_quote! { i32 }, + IntKind::U32 => syn::parse_quote! { u32 }, + IntKind::I64 => syn::parse_quote! { i64 }, + IntKind::U64 => syn::parse_quote! { u64 }, + IntKind::Custom { name, .. } => { + syn::parse_str(name).expect("Invalid integer type.") + } + IntKind::U128 => { + if ctx.options().rust_features.i128_and_u128 { + syn::parse_quote! { u128 } + } else { + // Best effort thing, but wrong alignment + // unfortunately. + syn::parse_quote! { [u64; 2] } + } + } + IntKind::I128 => { + if ctx.options().rust_features.i128_and_u128 { + syn::parse_quote! { i128 } + } else { + syn::parse_quote! { [u64; 2] } } } } @@ -196,26 +226,26 @@ pub(crate) mod ast_ty { ctx: &BindgenContext, fk: FloatKind, layout: Option, - ) -> TokenStream { + ) -> syn::Type { // TODO: we probably should take the type layout into account more // often? // // Also, maybe this one shouldn't be the default? match (fk, ctx.options().convert_floats) { - (FloatKind::Float, true) => quote! { f32 }, - (FloatKind::Double, true) => quote! { f64 }, + (FloatKind::Float, true) => syn::parse_quote! { f32 }, + (FloatKind::Double, true) => syn::parse_quote! { f64 }, (FloatKind::Float, false) => raw_type(ctx, "c_float"), (FloatKind::Double, false) => raw_type(ctx, "c_double"), (FloatKind::LongDouble, _) => { match layout { Some(layout) => { match layout.size { - 4 => quote! { f32 }, - 8 => quote! { f64 }, + 4 => syn::parse_quote! { f32 }, + 8 => syn::parse_quote! { f64 }, // TODO(emilio): If rust ever gains f128 we should // use it here and below. _ => super::integer_type(ctx, layout) - .unwrap_or(quote! { f64 }), + .unwrap_or(syn::parse_quote! { f64 }), } } None => { @@ -223,15 +253,15 @@ pub(crate) mod ast_ty { false, "How didn't we know the layout for a primitive type?" ); - quote! { f64 } + syn::parse_quote! { f64 } } } } (FloatKind::Float128, _) => { if ctx.options().rust_features.i128_and_u128 { - quote! { u128 } + syn::parse_quote! { u128 } } else { - quote! { [u64; 2] } + syn::parse_quote! { [u64; 2] } } } } diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index c381f57cb8..11425e02a4 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -1,5 +1,6 @@ mod dyngen; -mod error; +pub(crate) mod error; + mod helpers; mod impl_debug; mod impl_partialeq; @@ -36,7 +37,7 @@ use crate::ir::derive::{ use crate::ir::dot; use crate::ir::enum_ty::{Enum, EnumVariant, EnumVariantValue}; use crate::ir::function::{ - Abi, ClangAbi, Function, FunctionKind, FunctionSig, Linkage, + ClangAbi, Function, FunctionKind, FunctionSig, Linkage, }; use crate::ir::int::IntKind; use crate::ir::item::{IsOpaque, Item, ItemCanonicalName, ItemCanonicalPath}; @@ -391,45 +392,44 @@ impl<'a> ops::DerefMut for CodegenResult<'a> { /// A trait to convert a rust type into a pointer, optionally const, to the same /// type. trait ToPtr { - fn to_ptr(self, is_const: bool) -> proc_macro2::TokenStream; + fn to_ptr(self, is_const: bool) -> syn::Type; } -impl ToPtr for proc_macro2::TokenStream { - fn to_ptr(self, is_const: bool) -> proc_macro2::TokenStream { +impl ToPtr for syn::Type { + fn to_ptr(self, is_const: bool) -> syn::Type { if is_const { - quote! { *const #self } + syn::parse_quote! { *const #self } } else { - quote! { *mut #self } + syn::parse_quote! { *mut #self } } } } -/// An extension trait for `proc_macro2::TokenStream` that lets us append any implicit +/// An extension trait for `syn::Type` that lets us append any implicit /// template parameters that exist for some type, if necessary. -trait AppendImplicitTemplateParams { - fn append_implicit_template_params( - &mut self, +trait WithImplicitTemplateParams { + fn with_implicit_template_params( + self, ctx: &BindgenContext, item: &Item, - ); + ) -> Self; } -impl AppendImplicitTemplateParams for proc_macro2::TokenStream { - fn append_implicit_template_params( - &mut self, +impl WithImplicitTemplateParams for syn::Type { + fn with_implicit_template_params( + self, ctx: &BindgenContext, item: &Item, - ) { + ) -> Self { let item = item.id().into_resolver().through_type_refs().resolve(ctx); - match *item.expect_type().kind() { + let params = match *item.expect_type().kind() { TypeKind::UnresolvedTypeRef(..) => { unreachable!("already resolved unresolved type refs") } TypeKind::ResolvedTypeRef(..) => { unreachable!("we resolved item through type refs") } - // None of these types ever have implicit template parameters. TypeKind::Void | TypeKind::NullPtr | @@ -445,22 +445,25 @@ impl AppendImplicitTemplateParams for proc_macro2::TokenStream { TypeKind::Enum(..) | TypeKind::ObjCId | TypeKind::ObjCSel | - TypeKind::TemplateInstantiation(..) => return, - _ => {} - } + TypeKind::TemplateInstantiation(..) => None, + _ => { + let params = item.used_template_params(ctx); + if params.is_empty() { + None + } else { + Some(params.into_iter().map(|p| { + p.try_to_rust_ty(ctx, &()).expect( + "template params cannot fail to be a rust type", + ) + })) + } + } + }; - let params: Vec<_> = item - .used_template_params(ctx) - .iter() - .map(|p| { - p.try_to_rust_ty(ctx, &()) - .expect("template params cannot fail to be a rust type") - }) - .collect(); - if !params.is_empty() { - self.append_all(quote! { - < #( #params ),* > - }); + if let Some(params) = params { + syn::parse_quote! { #self<#(#params),*> } + } else { + self } } } @@ -670,7 +673,8 @@ impl CodeGenerator for Var { attrs.push(attributes::doc(comment)); } - let ty = self.ty().to_rust_ty_or_opaque(ctx, &()); + let var_ty = self.ty(); + let ty = var_ty.to_rust_ty_or_opaque(ctx, &()); if let Some(val) = self.val() { match *val { @@ -681,8 +685,7 @@ impl CodeGenerator for Var { }); } VarType::Int(val) => { - let int_kind = self - .ty() + let int_kind = var_ty .into_resolver() .through_type_aliases() .through_type_refs() @@ -929,11 +932,10 @@ impl CodeGenerator for Type { // Its possible that we have better layout information than // the inner type does, so fall back to an opaque blob based // on our layout if converting the inner item fails. - let mut inner_ty = inner_item + inner_item .try_to_rust_ty_or_opaque(ctx, &()) - .unwrap_or_else(|_| self.to_opaque(ctx, item)); - inner_ty.append_implicit_template_params(ctx, inner_item); - inner_ty + .unwrap_or_else(|_| self.to_opaque(ctx, item)) + .with_implicit_template_params(ctx, inner_item) }; { @@ -979,9 +981,8 @@ impl CodeGenerator for Type { // We prefer using `pub use` over `pub type` because of: // https://github.com/rust-lang/rust/issues/26264 - // These are the only characters allowed in simple - // paths, eg `good::dogs::Bront`. - if inner_rust_type.to_string().chars().all(|c| matches!(c, 'A'..='Z' | 'a'..='z' | '0'..='9' | ':' | '_' | ' ')) && outer_params.is_empty() && + if matches!(inner_rust_type, syn::Type::Path(_)) && + outer_params.is_empty() && !is_opaque && alias_style == AliasVariation::TypeAlias && inner_item.expect_type().canonical_type(ctx).is_enum() @@ -1208,11 +1209,9 @@ impl<'a> TryToRustTy for Vtable<'a> { &self, ctx: &BindgenContext, _: &(), - ) -> error::Result { + ) -> error::Result { let name = ctx.rust_ident(self.canonical_name(ctx)); - Ok(quote! { - #name - }) + Ok(syn::parse_quote! { #name }) } } @@ -1364,28 +1363,22 @@ impl<'a> FieldCodegen<'a> for Field { fn wrap_union_field_if_needed( ctx: &BindgenContext, struct_layout: &StructLayoutTracker, - ty: proc_macro2::TokenStream, + ty: syn::Type, result: &mut CodegenResult, -) -> proc_macro2::TokenStream { +) -> syn::Type { if struct_layout.is_rust_union() { if struct_layout.can_copy_union_fields() { ty } else { let prefix = ctx.trait_prefix(); - quote! { - ::#prefix::mem::ManuallyDrop<#ty> - } + syn::parse_quote! { ::#prefix::mem::ManuallyDrop<#ty> } } } else { result.saw_bindgen_union(); if ctx.options().enable_cxx_namespaces { - quote! { - root::__BindgenUnionField<#ty> - } + syn::parse_quote! { root::__BindgenUnionField<#ty> } } else { - quote! { - __BindgenUnionField<#ty> - } + syn::parse_quote! { __BindgenUnionField<#ty> } } } } @@ -1416,8 +1409,10 @@ impl<'a> FieldCodegen<'a> for FieldData { let field_item = self.ty().into_resolver().through_type_refs().resolve(ctx); let field_ty = field_item.expect_type(); - let mut ty = self.ty().to_rust_ty_or_opaque(ctx, &()); - ty.append_implicit_template_params(ctx, field_item); + let ty = self + .ty() + .to_rust_ty_or_opaque(ctx, &()) + .with_implicit_template_params(ctx, field_item); // NB: If supported, we use proper `union` types. let ty = if parent.is_union() { @@ -1428,13 +1423,9 @@ impl<'a> FieldCodegen<'a> for FieldData { let inner = item.to_rust_ty_or_opaque(ctx, &()); if ctx.options().enable_cxx_namespaces { - quote! { - root::__IncompleteArrayField<#inner> - } + syn::parse_quote! { root::__IncompleteArrayField<#inner> } } else { - quote! { - __IncompleteArrayField<#inner> - } + syn::parse_quote! { __IncompleteArrayField<#inner> } } } else { ty @@ -2004,8 +1995,9 @@ impl CodeGenerator for CompInfo { } let inner_item = ctx.resolve_item(base.ty); - let mut inner = inner_item.to_rust_ty_or_opaque(ctx, &()); - inner.append_implicit_template_params(ctx, inner_item); + let inner = inner_item + .to_rust_ty_or_opaque(ctx, &()) + .with_implicit_template_params(ctx, inner_item); let field_name = ctx.rust_ident(&base.field_name); struct_layout.saw_base(inner_item.expect_type()); @@ -2607,22 +2599,7 @@ impl Method { _ => panic!("How in the world?"), }; - let supported_abi = match signature.abi(ctx, Some(&*name)) { - ClangAbi::Known(Abi::ThisCall) => { - ctx.options().rust_features().thiscall_abi - } - ClangAbi::Known(Abi::Vectorcall) => { - ctx.options().rust_features().vectorcall_abi - } - ClangAbi::Known(Abi::CUnwind) => { - ctx.options().rust_features().c_unwind_abi - } - ClangAbi::Known(Abi::EfiApi) => { - ctx.options().rust_features().abi_efiapi - } - _ => true, - }; - + let supported_abi = signature.abi(ctx, Some(&*name)).is_ok(); if !supported_abi { return; } @@ -2891,7 +2868,7 @@ impl<'a> EnumBuilder<'a> { fn new( name: &'a str, mut attrs: Vec, - repr: proc_macro2::TokenStream, + repr: syn::Type, enum_variation: EnumVariation, has_typedef: bool, ) -> Self { @@ -2960,7 +2937,7 @@ impl<'a> EnumBuilder<'a> { ctx: &BindgenContext, variant: &EnumVariant, mangling_prefix: Option<&str>, - rust_ty: proc_macro2::TokenStream, + rust_ty: syn::Type, result: &mut CodegenResult<'_>, is_ty_named: bool, ) -> Self { @@ -3075,7 +3052,7 @@ impl<'a> EnumBuilder<'a> { fn build( self, ctx: &BindgenContext, - rust_ty: proc_macro2::TokenStream, + rust_ty: syn::Type, result: &mut CodegenResult<'_>, ) -> proc_macro2::TokenStream { match self { @@ -3326,7 +3303,7 @@ impl CodeGenerator for Enum { // value. variant_name: &Ident, referenced_name: &Ident, - enum_rust_ty: proc_macro2::TokenStream, + enum_rust_ty: syn::Type, result: &mut CodegenResult<'_>, ) { let constant_name = if enum_.name().is_some() { @@ -3641,7 +3618,7 @@ impl std::str::FromStr for NonCopyUnionStyle { /// Implementors of this trait should provide the `try_get_layout` method to /// fallibly get this thing's layout, which the provided `try_to_opaque` trait /// method will use to convert the `Layout` into an opaque blob Rust type. -trait TryToOpaque { +pub(crate) trait TryToOpaque { type Extra; /// Get the layout for this thing, if one is available. @@ -3656,7 +3633,7 @@ trait TryToOpaque { &self, ctx: &BindgenContext, extra: &Self::Extra, - ) -> error::Result { + ) -> error::Result { self.try_get_layout(ctx, extra) .map(|layout| helpers::blob(ctx, layout)) } @@ -3672,7 +3649,7 @@ trait TryToOpaque { /// /// Don't implement this directly. Instead implement `TryToOpaque`, and then /// leverage the blanket impl for this trait. -trait ToOpaque: TryToOpaque { +pub(crate) trait ToOpaque: TryToOpaque { fn get_layout(&self, ctx: &BindgenContext, extra: &Self::Extra) -> Layout { self.try_get_layout(ctx, extra) .unwrap_or_else(|_| Layout::for_size(ctx, 1)) @@ -3682,7 +3659,7 @@ trait ToOpaque: TryToOpaque { &self, ctx: &BindgenContext, extra: &Self::Extra, - ) -> proc_macro2::TokenStream { + ) -> syn::Type { let layout = self.get_layout(ctx, extra); helpers::blob(ctx, layout) } @@ -3697,14 +3674,14 @@ impl ToOpaque for T where T: TryToOpaque {} /// const-value generic parameters) then the impl should return an `Err`. It /// should *not* attempt to return an opaque blob with the correct size and /// alignment. That is the responsibility of the `TryToOpaque` trait. -trait TryToRustTy { +pub(crate) trait TryToRustTy { type Extra; fn try_to_rust_ty( &self, ctx: &BindgenContext, extra: &Self::Extra, - ) -> error::Result; + ) -> error::Result; } /// Fallible conversion to a Rust type or an opaque blob with the correct size @@ -3712,14 +3689,14 @@ trait TryToRustTy { /// /// Don't implement this directly. Instead implement `TryToRustTy` and /// `TryToOpaque`, and then leverage the blanket impl for this trait below. -trait TryToRustTyOrOpaque: TryToRustTy + TryToOpaque { +pub(crate) trait TryToRustTyOrOpaque: TryToRustTy + TryToOpaque { type Extra; fn try_to_rust_ty_or_opaque( &self, ctx: &BindgenContext, extra: &::Extra, - ) -> error::Result; + ) -> error::Result; } impl TryToRustTyOrOpaque for T @@ -3732,7 +3709,7 @@ where &self, ctx: &BindgenContext, extra: &E, - ) -> error::Result { + ) -> error::Result { self.try_to_rust_ty(ctx, extra).or_else(|_| { if let Ok(layout) = self.try_get_layout(ctx, extra) { Ok(helpers::blob(ctx, layout)) @@ -3760,14 +3737,14 @@ where /// `ToRustTyOrOpaque`. The further out we push error recovery, the more likely /// we are to get a usable `Layout` even if we can't generate an equivalent Rust /// type for a C++ construct. -trait ToRustTyOrOpaque: TryToRustTy + ToOpaque { +pub(crate) trait ToRustTyOrOpaque: TryToRustTy + ToOpaque { type Extra; fn to_rust_ty_or_opaque( &self, ctx: &BindgenContext, extra: &::Extra, - ) -> proc_macro2::TokenStream; + ) -> syn::Type; } impl ToRustTyOrOpaque for T @@ -3780,7 +3757,7 @@ where &self, ctx: &BindgenContext, extra: &E, - ) -> proc_macro2::TokenStream { + ) -> syn::Type { self.try_to_rust_ty(ctx, extra) .unwrap_or_else(|_| self.to_opaque(ctx, extra)) } @@ -3811,7 +3788,7 @@ where &self, ctx: &BindgenContext, _: &(), - ) -> error::Result { + ) -> error::Result { ctx.resolve_item((*self).into()).try_to_rust_ty(ctx, &()) } } @@ -3835,7 +3812,7 @@ impl TryToRustTy for Item { &self, ctx: &BindgenContext, _: &(), - ) -> error::Result { + ) -> error::Result { self.kind().expect_type().try_to_rust_ty(ctx, self) } } @@ -3859,7 +3836,7 @@ impl TryToRustTy for Type { &self, ctx: &BindgenContext, item: &Item, - ) -> error::Result { + ) -> error::Result { use self::helpers::ast_ty::*; match *self.kind() { @@ -3868,57 +3845,7 @@ impl TryToRustTy for Type { // c_void is enough? TypeKind::NullPtr => Ok(c_void(ctx).to_ptr(true)), TypeKind::Int(ik) => { - match ik { - IntKind::Bool => Ok(quote! { bool }), - IntKind::Char { .. } => Ok(raw_type(ctx, "c_char")), - IntKind::SChar => Ok(raw_type(ctx, "c_schar")), - IntKind::UChar => Ok(raw_type(ctx, "c_uchar")), - IntKind::Short => Ok(raw_type(ctx, "c_short")), - IntKind::UShort => Ok(raw_type(ctx, "c_ushort")), - IntKind::Int => Ok(raw_type(ctx, "c_int")), - IntKind::UInt => Ok(raw_type(ctx, "c_uint")), - IntKind::Long => Ok(raw_type(ctx, "c_long")), - IntKind::ULong => Ok(raw_type(ctx, "c_ulong")), - IntKind::LongLong => Ok(raw_type(ctx, "c_longlong")), - IntKind::ULongLong => Ok(raw_type(ctx, "c_ulonglong")), - IntKind::WChar => { - let layout = self - .layout(ctx) - .expect("Couldn't compute wchar_t's layout?"); - let ty = Layout::known_type_for_size(ctx, layout.size) - .expect("Non-representable wchar_t?"); - let ident = ctx.rust_ident_raw(ty); - Ok(quote! { #ident }) - } - - IntKind::I8 => Ok(quote! { i8 }), - IntKind::U8 => Ok(quote! { u8 }), - IntKind::I16 => Ok(quote! { i16 }), - IntKind::U16 => Ok(quote! { u16 }), - IntKind::I32 => Ok(quote! { i32 }), - IntKind::U32 => Ok(quote! { u32 }), - IntKind::I64 => Ok(quote! { i64 }), - IntKind::U64 => Ok(quote! { u64 }), - IntKind::Custom { name, .. } => { - Ok(proc_macro2::TokenStream::from_str(name).unwrap()) - } - IntKind::U128 => { - Ok(if ctx.options().rust_features.i128_and_u128 { - quote! { u128 } - } else { - // Best effort thing, but wrong alignment - // unfortunately. - quote! { [u64; 2] } - }) - } - IntKind::I128 => { - Ok(if ctx.options().rust_features.i128_and_u128 { - quote! { i128 } - } else { - quote! { [u64; 2] } - }) - } - } + Ok(int_kind_rust_type(ctx, ik, self.layout(ctx))) } TypeKind::Float(fk) => { Ok(float_kind_rust_type(ctx, fk, self.layout(ctx))) @@ -3929,38 +3856,30 @@ impl TryToRustTy for Type { ctx.generated_bindgen_complex(); Ok(if ctx.options().enable_cxx_namespaces { - quote! { - root::__BindgenComplex<#float_path> - } + syn::parse_quote! { root::__BindgenComplex<#float_path> } } else { - quote! { - __BindgenComplex<#float_path> - } + syn::parse_quote! { __BindgenComplex<#float_path> } }) } - TypeKind::Function(ref fs) => { + TypeKind::Function(ref signature) => { // We can't rely on the sizeof(Option>) == // sizeof(NonZero<_>) optimization with opaque blobs (because // they aren't NonZero), so don't *ever* use an or_opaque // variant here. - let ty = fs.try_to_rust_ty(ctx, &())?; + let ty = signature.try_to_rust_ty(ctx, item)?; let prefix = ctx.trait_prefix(); - Ok(quote! { - ::#prefix::option::Option<#ty> - }) + Ok(syn::parse_quote! { ::#prefix::option::Option<#ty> }) } TypeKind::Array(item, len) | TypeKind::Vector(item, len) => { let ty = item.try_to_rust_ty(ctx, &())?; - Ok(quote! { - [ #ty ; #len ] - }) + Ok(syn::parse_quote! { [ #ty ; #len ] }) } TypeKind::Enum(..) => { let path = item.namespace_aware_canonical_path(ctx); let path = proc_macro2::TokenStream::from_str(&path.join("::")) .unwrap(); - Ok(quote!(#path)) + Ok(syn::parse_quote!(#path)) } TypeKind::TemplateInstantiation(ref inst) => { inst.try_to_rust_ty(ctx, item) @@ -4013,8 +3932,9 @@ impl TryToRustTy for Type { // Regardless if we can properly represent the inner type, we // should always generate a proper pointer here, so use // infallible conversion of the inner type. - let mut ty = inner.to_rust_ty_or_opaque(ctx, &()); - ty.append_implicit_template_params(ctx, inner); + let ty = inner + .to_rust_ty_or_opaque(ctx, &()) + .with_implicit_template_params(ctx, inner); // Avoid the first function pointer level, since it's already // represented in Rust. @@ -4028,21 +3948,13 @@ impl TryToRustTy for Type { TypeKind::TypeParam => { let name = item.canonical_name(ctx); let ident = ctx.rust_ident(name); - Ok(quote! { - #ident - }) + Ok(syn::parse_quote! { #ident }) } - TypeKind::ObjCSel => Ok(quote! { - objc::runtime::Sel - }), - TypeKind::ObjCId => Ok(quote! { - id - }), + TypeKind::ObjCSel => Ok(syn::parse_quote! { objc::runtime::Sel }), + TypeKind::ObjCId => Ok(syn::parse_quote! { id }), TypeKind::ObjCInterface(ref interface) => { let name = ctx.rust_ident(interface.name()); - Ok(quote! { - #name - }) + Ok(syn::parse_quote! { #name }) } ref u @ TypeKind::UnresolvedTypeRef(..) => { unreachable!("Should have been resolved after parsing {:?}!", u) @@ -4072,7 +3984,7 @@ impl TryToRustTy for TemplateInstantiation { &self, ctx: &BindgenContext, item: &Item, - ) -> error::Result { + ) -> error::Result { if self.is_opaque(ctx, item) { return Err(error::Error::InstantiationOfOpaqueType); } @@ -4116,62 +4028,50 @@ impl TryToRustTy for TemplateInstantiation { .filter(|&(_, param)| ctx.uses_template_parameter(def.id(), *param)) .map(|(arg, _)| { let arg = arg.into_resolver().through_type_refs().resolve(ctx); - let mut ty = arg.try_to_rust_ty(ctx, &())?; - ty.append_implicit_template_params(ctx, arg); + let ty = arg + .try_to_rust_ty(ctx, &())? + .with_implicit_template_params(ctx, arg); Ok(ty) }) .collect::>>()?; - if template_args.is_empty() { - return Ok(ty); - } - - Ok(quote! { - #ty < #( #template_args ),* > + Ok(if template_args.is_empty() { + syn::parse_quote! { #ty } + } else { + syn::parse_quote! { #ty<#(#template_args),*> } }) } } impl TryToRustTy for FunctionSig { - type Extra = (); + type Extra = Item; fn try_to_rust_ty( &self, ctx: &BindgenContext, - _: &(), - ) -> error::Result { + item: &Item, + ) -> error::Result { // TODO: we might want to consider ignoring the reference return value. let ret = utils::fnsig_return_ty(ctx, self); let arguments = utils::fnsig_arguments(ctx, self); match self.abi(ctx, None) { - ClangAbi::Known(Abi::ThisCall) - if !ctx.options().rust_features().thiscall_abi => - { - warn!("Skipping function with thiscall ABI that isn't supported by the configured Rust target"); - Ok(proc_macro2::TokenStream::new()) - } - ClangAbi::Known(Abi::Vectorcall) - if !ctx.options().rust_features().vectorcall_abi => - { - warn!("Skipping function with vectorcall ABI that isn't supported by the configured Rust target"); - Ok(proc_macro2::TokenStream::new()) - } - ClangAbi::Known(Abi::CUnwind) - if !ctx.options().rust_features().c_unwind_abi => - { - warn!("Skipping function with C-unwind ABI that isn't supported by the configured Rust target"); - Ok(proc_macro2::TokenStream::new()) - } - ClangAbi::Known(Abi::EfiApi) - if !ctx.options().rust_features().abi_efiapi => - { - warn!("Skipping function with efiapi ABI that isn't supported by the configured Rust target"); - Ok(proc_macro2::TokenStream::new()) + Ok(abi) => Ok( + syn::parse_quote! { unsafe extern #abi fn ( #( #arguments ),* ) #ret }, + ), + Err(err) => { + if matches!(err, error::Error::UnsupportedAbi(_)) { + unsupported_abi_diagnostic( + self.name(), + self.is_variadic(), + item.location(), + ctx, + &err, + ); + } + + Err(err) } - abi => Ok(quote! { - unsafe extern #abi fn ( #( #arguments ),* ) #ret - }), } } } @@ -4275,66 +4175,26 @@ impl CodeGenerator for Function { } let abi = match signature.abi(ctx, Some(name)) { - ClangAbi::Known(Abi::ThisCall) - if !ctx.options().rust_features().thiscall_abi => - { - unsupported_abi_diagnostic::( - name, - item.location(), - "thiscall", - ctx, - ); - return None; - } - ClangAbi::Known(Abi::Vectorcall) - if !ctx.options().rust_features().vectorcall_abi => - { - unsupported_abi_diagnostic::( - name, - item.location(), - "vectorcall", - ctx, - ); - return None; - } - ClangAbi::Known(Abi::CUnwind) - if !ctx.options().rust_features().c_unwind_abi => - { - unsupported_abi_diagnostic::( - name, - item.location(), - "C-unwind", - ctx, - ); - return None; - } - ClangAbi::Known(Abi::EfiApi) - if !ctx.options().rust_features().abi_efiapi => - { - unsupported_abi_diagnostic::( - name, - item.location(), - "efiapi", - ctx, - ); - return None; - } - ClangAbi::Known(Abi::Win64) if signature.is_variadic() => { - unsupported_abi_diagnostic::( - name, - item.location(), - "Win64", - ctx, - ); + Err(err) => { + if matches!(err, error::Error::UnsupportedAbi(_)) { + unsupported_abi_diagnostic( + name, + signature.is_variadic(), + item.location(), + ctx, + &err, + ); + } + return None; } - ClangAbi::Unknown(unknown_abi) => { + Ok(ClangAbi::Unknown(unknown_abi)) => { panic!( "Invalid or unknown abi {:?} for function {:?} ({:?})", unknown_abi, canonical_name, self ); } - abi => abi, + Ok(abi) => abi, }; // Handle overloaded functions by giving each overload its own unique @@ -4452,34 +4312,48 @@ impl CodeGenerator for Function { } } -fn unsupported_abi_diagnostic( +#[cfg_attr(not(feature = "experimental"), allow(unused_variables))] +fn unsupported_abi_diagnostic( fn_name: &str, - _location: Option<&crate::clang::SourceLocation>, - abi: &str, - _ctx: &BindgenContext, + variadic: bool, + location: Option<&crate::clang::SourceLocation>, + ctx: &BindgenContext, + error: &error::Error, ) { warn!( - "Skipping {}function `{}` with the {} ABI that isn't supported by the configured Rust target", - if VARIADIC { "variadic " } else { "" }, + "Skipping {}function `{}` because the {}", + if variadic { "variadic " } else { "" }, fn_name, - abi + error ); #[cfg(feature = "experimental")] - if _ctx.options().emit_diagnostics { + if ctx.options().emit_diagnostics { use crate::diagnostics::{get_line, Diagnostic, Level, Slice}; let mut diag = Diagnostic::default(); - diag - .with_title(format!( - "The `{}` {}function uses the {} ABI which is not supported by the configured Rust target.", + diag.with_title( + format!( + "Skipping {}function `{}` because the {}", + if variadic { "variadic " } else { "" }, fn_name, - if VARIADIC { "variadic " } else { "" }, - abi), Level::Warn) - .add_annotation("No code will be generated for this function.", Level::Warn) - .add_annotation(format!("The configured Rust version is {}.", String::from(_ctx.options().rust_target)), Level::Note); + error + ), + Level::Warn, + ) + .add_annotation( + "No code will be generated for this function.", + Level::Warn, + ) + .add_annotation( + format!( + "The configured Rust version is {}.", + String::from(ctx.options().rust_target) + ), + Level::Note, + ); - if let Some(loc) = _location { + if let Some(loc) = location { let (file, line, col, _) = loc.location(); if let Some(filename) = file.name() { @@ -4868,6 +4742,7 @@ pub(crate) mod utils { use super::serialize::CSerialize; use super::{error, CodegenError, CodegenResult, ToRustTyOrOpaque}; use crate::ir::context::BindgenContext; + use crate::ir::context::TypeId; use crate::ir::function::{Abi, ClangAbi, FunctionSig}; use crate::ir::item::{Item, ItemCanonicalPath}; use crate::ir::ty::TypeKind; @@ -5267,28 +5142,23 @@ pub(crate) mod utils { pub(crate) fn build_path( item: &Item, ctx: &BindgenContext, - ) -> error::Result { + ) -> error::Result { let path = item.namespace_aware_canonical_path(ctx); let tokens = proc_macro2::TokenStream::from_str(&path.join("::")).unwrap(); - Ok(tokens) + Ok(syn::parse_quote! { #tokens }) } - fn primitive_ty( - ctx: &BindgenContext, - name: &str, - ) -> proc_macro2::TokenStream { + fn primitive_ty(ctx: &BindgenContext, name: &str) -> syn::Type { let ident = ctx.rust_ident_raw(name); - quote! { - #ident - } + syn::parse_quote! { #ident } } pub(crate) fn type_from_named( ctx: &BindgenContext, name: &str, - ) -> Option { + ) -> Option { // FIXME: We could use the inner item to check this is really a // primitive type but, who the heck overrides these anyway? Some(match name { @@ -5317,14 +5187,9 @@ pub(crate) mod utils { fn fnsig_return_ty_internal( ctx: &BindgenContext, sig: &FunctionSig, - include_arrow: bool, - ) -> proc_macro2::TokenStream { + ) -> syn::Type { if sig.is_divergent() { - return if include_arrow { - quote! { -> ! } - } else { - quote! { ! } - }; + return syn::parse_quote! { ! }; } let canonical_type_kind = sig @@ -5337,19 +5202,9 @@ pub(crate) mod utils { .expect_type() .kind(); - if let TypeKind::Void = canonical_type_kind { - return if include_arrow { - quote! {} - } else { - quote! { () } - }; - } - - let ret_ty = sig.return_type().to_rust_ty_or_opaque(ctx, &()); - if include_arrow { - quote! { -> #ret_ty } - } else { - ret_ty + match canonical_type_kind { + TypeKind::Void => syn::parse_quote! { () }, + _ => sig.return_type().to_rust_ty_or_opaque(ctx, &()), } } @@ -5357,7 +5212,56 @@ pub(crate) mod utils { ctx: &BindgenContext, sig: &FunctionSig, ) -> proc_macro2::TokenStream { - fnsig_return_ty_internal(ctx, sig, /* include_arrow = */ true) + match fnsig_return_ty_internal(ctx, sig) { + syn::Type::Tuple(syn::TypeTuple { elems, .. }) + if elems.is_empty() => + { + quote! {} + } + ty => quote! { -> #ty }, + } + } + + pub(crate) fn fnsig_argument_type( + ctx: &BindgenContext, + ty: &TypeId, + ) -> syn::Type { + use super::ToPtr; + + let arg_item = ctx.resolve_item(ty); + let arg_ty = arg_item.kind().expect_type(); + + // From the C90 standard[1]: + // + // A declaration of a parameter as "array of type" shall be + // adjusted to "qualified pointer to type", where the type + // qualifiers (if any) are those specified within the [ and ] of + // the array type derivation. + // + // [1]: http://c0x.coding-guidelines.com/6.7.5.3.html + match *arg_ty.canonical_type(ctx).kind() { + TypeKind::Array(t, _) => { + let stream = if ctx.options().array_pointers_in_arguments { + arg_ty.to_rust_ty_or_opaque(ctx, arg_item) + } else { + t.to_rust_ty_or_opaque(ctx, &()) + }; + stream.to_ptr(ctx.resolve_type(t).is_const()) + } + TypeKind::Pointer(inner) => { + let inner = ctx.resolve_item(inner); + let inner_ty = inner.expect_type(); + if let TypeKind::ObjCInterface(ref interface) = + *inner_ty.canonical_type(ctx).kind() + { + let name = ctx.rust_ident(interface.name()); + syn::parse_quote! { #name } + } else { + arg_item.to_rust_ty_or_opaque(ctx, &()) + } + } + _ => arg_item.to_rust_ty_or_opaque(ctx, &()), + } } pub(crate) fn fnsig_arguments_iter< @@ -5368,48 +5272,10 @@ pub(crate) mod utils { args_iter: I, is_variadic: bool, ) -> Vec { - use super::ToPtr; - let mut unnamed_arguments = 0; let mut args = args_iter - .map(|&(ref name, ty)| { - let arg_item = ctx.resolve_item(ty); - let arg_ty = arg_item.kind().expect_type(); - - // From the C90 standard[1]: - // - // A declaration of a parameter as "array of type" shall be - // adjusted to "qualified pointer to type", where the type - // qualifiers (if any) are those specified within the [ and ] of - // the array type derivation. - // - // [1]: http://c0x.coding-guidelines.com/6.7.5.3.html - let arg_ty = match *arg_ty.canonical_type(ctx).kind() { - TypeKind::Array(t, _) => { - let stream = - if ctx.options().array_pointers_in_arguments { - arg_ty.to_rust_ty_or_opaque(ctx, arg_item) - } else { - t.to_rust_ty_or_opaque(ctx, &()) - }; - stream.to_ptr(ctx.resolve_type(t).is_const()) - } - TypeKind::Pointer(inner) => { - let inner = ctx.resolve_item(inner); - let inner_ty = inner.expect_type(); - if let TypeKind::ObjCInterface(ref interface) = - *inner_ty.canonical_type(ctx).kind() - { - let name = ctx.rust_ident(interface.name()); - quote! { - #name - } - } else { - arg_item.to_rust_ty_or_opaque(ctx, &()) - } - } - _ => arg_item.to_rust_ty_or_opaque(ctx, &()), - }; + .map(|(name, ty)| { + let arg_ty = fnsig_argument_type(ctx, ty); let arg_name = match *name { Some(ref name) => ctx.rust_mangle(name).into_owned(), @@ -5485,9 +5351,7 @@ pub(crate) mod utils { arg_item.to_rust_ty_or_opaque(ctx, &()) }); - let ret_ty = fnsig_return_ty_internal( - ctx, sig, /* include_arrow = */ false, - ); + let ret_ty = fnsig_return_ty_internal(ctx, sig); quote! { *const ::block::Block<(#(#args,)*), #ret_ty> } diff --git a/bindgen/ir/function.rs b/bindgen/ir/function.rs index fab380e45f..a0781a3cda 100644 --- a/bindgen/ir/function.rs +++ b/bindgen/ir/function.rs @@ -405,6 +405,11 @@ fn args_from_ty_and_cursor( } impl FunctionSig { + /// Get the function name. + pub(crate) fn name(&self) -> &str { + &self.name + } + /// Construct a new function signature from the given Clang type. pub(crate) fn from_ty( ty: &clang::Type, @@ -605,10 +610,10 @@ impl FunctionSig { &self, ctx: &BindgenContext, name: Option<&str>, - ) -> ClangAbi { + ) -> crate::codegen::error::Result { // FIXME (pvdrz): Try to do this check lazily instead. Maybe store the ABI inside `ctx` // instead?. - if let Some(name) = name { + let abi = if let Some(name) = name { if let Some((abi, _)) = ctx .options() .abi_overrides @@ -628,6 +633,33 @@ impl FunctionSig { ClangAbi::Known(*abi) } else { self.abi + }; + + match abi { + ClangAbi::Known(Abi::ThisCall) + if !ctx.options().rust_features().thiscall_abi => + { + Err(crate::codegen::error::Error::UnsupportedAbi("thiscall")) + } + ClangAbi::Known(Abi::Vectorcall) + if !ctx.options().rust_features().vectorcall_abi => + { + Err(crate::codegen::error::Error::UnsupportedAbi("vectorcall")) + } + ClangAbi::Known(Abi::CUnwind) + if !ctx.options().rust_features().c_unwind_abi => + { + Err(crate::codegen::error::Error::UnsupportedAbi("C-unwind")) + } + ClangAbi::Known(Abi::EfiApi) + if !ctx.options().rust_features().abi_efiapi => + { + Err(crate::codegen::error::Error::UnsupportedAbi("efiapi")) + } + ClangAbi::Known(Abi::Win64) if self.is_variadic() => { + Err(crate::codegen::error::Error::UnsupportedAbi("Win64")) + } + abi => Ok(abi), } } diff --git a/bindgen/ir/layout.rs b/bindgen/ir/layout.rs index ba944b06bc..85a553da31 100644 --- a/bindgen/ir/layout.rs +++ b/bindgen/ir/layout.rs @@ -37,13 +37,15 @@ impl Layout { pub(crate) fn known_type_for_size( ctx: &BindgenContext, size: usize, - ) -> Option<&'static str> { + ) -> Option { Some(match size { - 16 if ctx.options().rust_features.i128_and_u128 => "u128", - 8 => "u64", - 4 => "u32", - 2 => "u16", - 1 => "u8", + 16 if ctx.options().rust_features.i128_and_u128 => { + syn::parse_quote! { u128 } + } + 8 => syn::parse_quote! { u64 }, + 4 => syn::parse_quote! { u32 }, + 2 => syn::parse_quote! { u16 }, + 1 => syn::parse_quote! { u8 }, _ => return None, }) } @@ -103,7 +105,7 @@ impl Opaque { pub(crate) fn known_rust_type_for_array( &self, ctx: &BindgenContext, - ) -> Option<&'static str> { + ) -> Option { Layout::known_type_for_size(ctx, self.0.align) } diff --git a/bindgen/ir/ty.rs b/bindgen/ir/ty.rs index 572d7de451..32bea702c1 100644 --- a/bindgen/ir/ty.rs +++ b/bindgen/ir/ty.rs @@ -5,7 +5,6 @@ use super::context::{BindgenContext, ItemId, TypeId}; use super::dot::DotAttributes; use super::enum_ty::Enum; use super::function::FunctionSig; -use super::int::IntKind; use super::item::{IsOpaque, Item}; use super::layout::{Layout, Opaque}; use super::objc::ObjCInterface; @@ -18,6 +17,8 @@ use crate::parse::{ParseError, ParseResult}; use std::borrow::Cow; use std::io; +pub use super::int::IntKind; + /// The base representation of a type in bindgen. /// /// A type has an optional name, which if present cannot be empty, a `layout` From 2665f1c9d02552ebdc9e5b001e134343644482bd Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Wed, 14 Jun 2023 19:34:45 +0200 Subject: [PATCH 529/942] Improve the `blocklist_*` and `allowlist_*` documentation. (#2554) * Explicitly mention that `blocklist` methods are not recursive * Mention that `blocklist_file` and `allowlist_file` match the whole path of the file --- bindgen/options/mod.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/bindgen/options/mod.rs b/bindgen/options/mod.rs index 83674e0e31..cda04ee8c7 100644 --- a/bindgen/options/mod.rs +++ b/bindgen/options/mod.rs @@ -158,6 +158,9 @@ options! { methods: { regex_option! { /// Do not generate any bindings for the given type. + /// + /// This option is not recursive, meaning that it will only block types whose names + /// explicitly match the argument of this method. pub fn blocklist_type>(mut self, arg: T) -> Builder { self.options.blocklisted_types.insert(arg); self @@ -171,6 +174,9 @@ options! { methods: { regex_option! { /// Do not generate any bindings for the given function. + /// + /// This option is not recursive, meaning that it will only block functions whose + /// names explicitly match the argument of this method. pub fn blocklist_function>(mut self, arg: T) -> Builder { self.options.blocklisted_functions.insert(arg); self @@ -185,6 +191,9 @@ options! { regex_option! { /// Do not generate any bindings for the given item, regardless of whether it is a /// type, function, module, etc. + /// + /// This option is not recursive, meaning that it will only block items whose names + /// explicitly match the argument of this method. pub fn blocklist_item>(mut self, arg: T) -> Builder { self.options.blocklisted_items.insert(arg); self @@ -199,6 +208,12 @@ options! { regex_option! { /// Do not generate any bindings for the contents of the given file, regardless of /// whether the contents of the file are types, functions, modules, etc. + /// + /// This option is not recursive, meaning that it will only block files whose names + /// explicitly match the argument of this method. + /// + /// This method will use the argument to match the complete path of the file + /// instead of a section of it. pub fn blocklist_file>(mut self, arg: T) -> Builder { self.options.blocklisted_files.insert(arg); self @@ -319,6 +334,9 @@ options! { /// /// This option is transitive by default. Check the documentation of the /// [`Builder::allowlist_recursively`] method for further information. + /// + /// This method will use the argument to match the complete path of the file + /// instead of a section of it. pub fn allowlist_file>(mut self, arg: T) -> Builder { self.options.allowlisted_files.insert(arg); self From 264075a6362f951e90240a976428f0225652d27c Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Wed, 14 Jun 2023 20:08:52 +0200 Subject: [PATCH 530/942] 0.66.0 release preparation (#2555) * Update changelog * Bump versions --- CHANGELOG.md | 163 ++++++++++++++++++++++------------------- Cargo.lock | 4 +- bindgen-cli/Cargo.toml | 4 +- bindgen/Cargo.toml | 2 +- 4 files changed, 94 insertions(+), 79 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 650d055cd6..c81900bdf6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,129 +7,133 @@ - [Removed](#removed) - [Fixed](#fixed) - [Security](#security) -- [0.65.1](#0651) - - [Fixed](#fixed-1) -- [0.65.0](#0650) +- [0.66.0](#0660) - [Added](#added-1) - [Changed](#changed-1) - [Removed](#removed-1) -- [0.64.0](#0640) +- [0.65.1](#0651) + - [Fixed](#fixed-1) +- [0.65.0](#0650) - [Added](#added-2) - [Changed](#changed-2) -- [0.63.0](#0630) + - [Removed](#removed-2) +- [0.64.0](#0640) - [Added](#added-3) - [Changed](#changed-3) - - [Removed](#removed-2) -- [0.62.0](#0620) +- [0.63.0](#0630) - [Added](#added-4) - [Changed](#changed-4) - - [Fixed](#fixed-2) -- [0.61.0](#0610) + - [Removed](#removed-3) +- [0.62.0](#0620) - [Added](#added-5) - [Changed](#changed-5) + - [Fixed](#fixed-2) +- [0.61.0](#0610) + - [Added](#added-6) + - [Changed](#changed-6) - [Fixed](#fixed-3) - [0.60.1](#0601) - [Fixed](#fixed-4) - [0.60.0](#0600) - - [Added](#added-6) + - [Added](#added-7) - [Fixed](#fixed-5) - - [Changed](#changed-6) - - [Removed](#removed-3) + - [Changed](#changed-7) + - [Removed](#removed-4) - [0.59.2](#0592) - [0.59.1](#0591) - [Fixed](#fixed-6) - [0.59.0](#0590) - - [Added](#added-7) + - [Added](#added-8) - [Fixed](#fixed-7) - - [Changed](#changed-7) + - [Changed](#changed-8) - [0.58.1](#0581) - - [Added](#added-8) -- [0.58.0](#0580) - [Added](#added-9) +- [0.58.0](#0580) + - [Added](#added-10) - [Fixed](#fixed-8) - - [Changed](#changed-8) + - [Changed](#changed-9) - [Deprecated](#deprecated) - - [Removed](#removed-4) + - [Removed](#removed-5) - [Fixed](#fixed-9) - [Security](#security-1) - [0.57.0](#0570) - - [Added](#added-10) + - [Added](#added-11) - [Fixed](#fixed-10) - [0.56.0](#0560) - - [Added](#added-11) - - [Changed](#changed-9) + - [Added](#added-12) + - [Changed](#changed-10) - [Fixed](#fixed-11) - [0.55.1](#0551) - [Fixed](#fixed-12) - [0.55.0](#0550) - - [Removed](#removed-5) - - [Added](#added-12) - - [Changed](#changed-10) - - [Fixed](#fixed-13) -- [0.54.1](#0541) + - [Removed](#removed-6) - [Added](#added-13) - [Changed](#changed-11) - - [Fixed](#fixed-14) -- [0.54.0](#0540) + - [Fixed](#fixed-13) +- [0.54.1](#0541) - [Added](#added-14) - [Changed](#changed-12) + - [Fixed](#fixed-14) +- [0.54.0](#0540) + - [Added](#added-15) + - [Changed](#changed-13) - [Fixed](#fixed-15) - [0.53.3](#0533) - - [Added](#added-15) + - [Added](#added-16) - [Fixed](#fixed-16) - [0.53.2](#0532) - - [Changed](#changed-13) + - [Changed](#changed-14) - [0.53.1](#0531) - - [Added](#added-16) -- [0.53.0](#0530) - [Added](#added-17) - - [Changed](#changed-14) - - [Fixed](#fixed-17) -- [0.52.0](#0520) +- [0.53.0](#0530) - [Added](#added-18) - [Changed](#changed-15) + - [Fixed](#fixed-17) +- [0.52.0](#0520) + - [Added](#added-19) + - [Changed](#changed-16) - [Fixed](#fixed-18) - [0.51.1](#0511) - [Fixed](#fixed-19) - - [Changed](#changed-16) + - [Changed](#changed-17) - [0.51.0](#0510) - [Fixed](#fixed-20) - - [Changed](#changed-17) - - [Added](#added-19) -- [0.50.0](#0500) + - [Changed](#changed-18) - [Added](#added-20) -- [0.49.3](#0493) +- [0.50.0](#0500) - [Added](#added-21) +- [0.49.3](#0493) + - [Added](#added-22) - [0.49.2](#0492) - - [Changed](#changed-18) + - [Changed](#changed-19) - [0.49.1](#0491) - [Fixed](#fixed-21) - - [Changed](#changed-19) + - [Changed](#changed-20) - [0.49.0](#0490) - - [Added](#added-22) + - [Added](#added-23) - [Fixed](#fixed-22) - - [Changed](#changed-20) + - [Changed](#changed-21) - [0.48.1](#0481) - [Fixed](#fixed-23) - [0.48.0](#0480) - - [Changed](#changed-21) + - [Changed](#changed-22) - [Fixed](#fixed-24) - [0.47.4](#0474) - - [Added](#added-23) + - [Added](#added-24) - [0.47.3](#0473) - - [Changed](#changed-22) + - [Changed](#changed-23) - [0.47.2](#0472) - [Fixed](#fixed-25) - [0.47.1](#0471) - - [Changed](#changed-23) + - [Changed](#changed-24) - [Fixed](#fixed-26) - [0.47.0](#0470) - - [Changed](#changed-24) + - [Changed](#changed-25) - [Fixed](#fixed-27) - [0.33.1 .. 0.46.0](#0331--0460) - - [Added](#added-24) - - [Removed](#removed-6) - - [Changed](#changed-25) + - [Added](#added-25) + - [Removed](#removed-7) + - [Changed](#changed-26) - [Fixed](#fixed-28) - [0.33.1](#0331) - [Fixed](#fixed-29) @@ -139,30 +143,38 @@ - [0.32.1](#0321) - [Fixed](#fixed-31) - [0.32.0](#0320) - - [Added](#added-25) - - [Changed](#changed-26) - - [Fixed](#fixed-32) -- [0.31.0](#0310) - [Added](#added-26) - [Changed](#changed-27) + - [Fixed](#fixed-32) +- [0.31.0](#0310) + - [Added](#added-27) + - [Changed](#changed-28) - [Deprecated](#deprecated-1) - - [Removed](#removed-7) + - [Removed](#removed-8) - [Fixed](#fixed-33) - [0.30.0](#0300) - - [Added](#added-27) - - [Changed](#changed-28) + - [Added](#added-28) + - [Changed](#changed-29) - [Deprecated](#deprecated-2) - [Fixed](#fixed-34) - [0.29.0](#0290) - - [Added](#added-28) - - [Changed](#changed-29) + - [Added](#added-29) + - [Changed](#changed-30) - [Fixed](#fixed-35) -------------------------------------------------------------------------------- -# Unreleased +# Unreleased + +## Added +## Changed +## Removed +## Fixed +## Security + +# 0.66.0 ## Added @@ -171,7 +183,9 @@ * Added the `--generate-shell-completions` CLI flag to generate completions for different shells. * The `--wrap-static-fns` option can now wrap `va_list` functions as variadic functions - with the experimental `wrap_as_variadic_fn` callback. + with the experimental `ParseCallbacks::wrap_as_variadic_fn` method. +* Add target mappings for riscv32imc and riscv32imac. +* Add the `ParseCallbacks::field_visibility` method to modify field visibility. ## Changed @@ -181,31 +195,32 @@ statement and only call the static function instead. * The `--wrap-static-fns` option no longer emits wrappers for static variadic functions. -* Depfiles generated with `--depfile` or `Builder::depfile` will now be - properly generate module names and paths that include spaces by escaping - them. To make the escaping clear and consistent, backslashes are also - escaped. +* Depfiles generated with `--depfile` or `Builder::depfile` will now properly + generate module names and paths that include spaces by escaping them. To make + the escaping clear and consistent, backslashes are also escaped. * Updated `bitflags` dependency to 2.2.1. This changes the API of `CodegenConfig`. * Prettyplease formatting is gated by an optional, enabled by default Cargo feature when depending on `bindgen` as a library. * Items are now parsed in the order they appear in source files. This may result in auto-generated `_bindgen_*` names having a different index. +* Use default visibility for padding fields: Previously, padding fields were + always public. Now, they follow the default visibility for the type they are + in. +* Compute visibility of bitfield unit based on actual field visibility: A + bitfield unit field and its related functions now have their visibility + determined based on the most private between the default visibility and the + actual visibility of the bitfields within the unit. + +## Removed * Remove redundant Cargo features, which were all implicit: - bindgen-cli: `env_logger` and `log` removed in favor of `logging` - bindgen (lib): + `log` removed in favor of `logging` + `which` removed in favor of `which-logging` + `annotate-snippets` removed in favor of `experimental` -* Add target mappings for riscv32imc and riscv32imac. - -## Removed - -## Fixed * Prettyplease is available as a `Formatter` variant now. -## Security - # 0.65.1 ## Fixed diff --git a/Cargo.lock b/Cargo.lock index 923cb84818..a6a1fe3e48 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -23,7 +23,7 @@ dependencies = [ [[package]] name = "bindgen" -version = "0.65.1" +version = "0.66.0" dependencies = [ "annotate-snippets", "bitflags 2.2.1", @@ -45,7 +45,7 @@ dependencies = [ [[package]] name = "bindgen-cli" -version = "0.65.1" +version = "0.66.0" dependencies = [ "bindgen", "clap", diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index 90e8cc62a4..abe0298fe0 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -11,7 +11,7 @@ readme = "../README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.65.1" +version = "0.66.0" edition = "2018" rust-version = "1.64.0" @@ -20,7 +20,7 @@ path = "main.rs" name = "bindgen" [dependencies] -bindgen = { path = "../bindgen", version = "=0.65.1", features = ["__cli", "experimental"] } +bindgen = { path = "../bindgen", version = "=0.66.0", features = ["__cli", "experimental"] } clap = { version = "4", features = ["derive"] } clap_complete = "4" env_logger = { version = "0.10.0", optional = true } diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index 054c841f9f..831eb7be85 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -14,7 +14,7 @@ readme = "../README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.65.1" +version = "0.66.0" edition = "2018" build = "build.rs" # If you change this, also update README.md and msrv in .github/workflows/bindgen.yml From adba49ec410d22836e9f4ebd7679c50ae6a06d7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 15 Jun 2023 22:05:55 +0200 Subject: [PATCH 531/942] clang: Clean up source order sorting. (#2557) This doesn't change behavior but is easier to debug and reason about (because you have the relevant cursors there). --- bindgen/clang.rs | 122 ++++++++++++++++++++--------------------------- bindgen/lib.rs | 6 +-- 2 files changed, 55 insertions(+), 73 deletions(-) diff --git a/bindgen/clang.rs b/bindgen/clang.rs index 0559faf464..35aafc0f58 100644 --- a/bindgen/clang.rs +++ b/bindgen/clang.rs @@ -498,7 +498,7 @@ impl Cursor { } } - /// Traverse this curser's children, sorted by where they appear in source code. + /// Traverse all of this cursor's children, sorted by where they appear in source code. /// /// Call the given function on each AST node traversed. pub(crate) fn visit_sorted( @@ -506,15 +506,13 @@ impl Cursor { ctx: &mut BindgenContext, mut visitor: Visitor, ) where - Visitor: FnMut(&mut BindgenContext, Cursor) -> CXChildVisitResult, + Visitor: FnMut(&mut BindgenContext, Cursor), { let mut children = self.collect_children(); - for child in &children { if child.kind() == CXCursor_InclusionDirective { if let Some(included_file) = child.get_included_file_name() { let location = child.location(); - let (source_file, _, _, offset) = location.location(); if let Some(source_file) = source_file.name() { @@ -523,19 +521,62 @@ impl Cursor { } } } - - children.sort_by(|child1, child2| { - child1 - .location() - .partial_cmp_with_context(&child2.location(), ctx) - .unwrap_or(std::cmp::Ordering::Equal) - }); - + children + .sort_by(|child1, child2| child1.cmp_by_source_order(child2, ctx)); for child in children { visitor(ctx, child); } } + /// Compare source order of two cursors, considering `#include` directives. + /// + /// Built-in items provided by the compiler (which don't have a source file), + /// are sorted first. Remaining files are sorted by their position in the source file. + /// If the items' source files differ, they are sorted by the position of the first + /// `#include` for their source file. If no source files are included, `None` is returned. + fn cmp_by_source_order( + &self, + other: &Self, + ctx: &BindgenContext, + ) -> cmp::Ordering { + let (file, _, _, offset) = self.location().location(); + let (other_file, _, _, other_offset) = other.location().location(); + + let (file, other_file) = match (file.name(), other_file.name()) { + (Some(file), Some(other_file)) => (file, other_file), + // Built-in definitions should come first. + (Some(_), None) => return cmp::Ordering::Greater, + (None, Some(_)) => return cmp::Ordering::Less, + (None, None) => return cmp::Ordering::Equal, + }; + + if file == other_file { + // Both items are in the same source file, compare by byte offset. + return offset.cmp(&other_offset); + } + + let include_location = ctx.included_file_location(&file); + let other_include_location = ctx.included_file_location(&other_file); + match (include_location, other_include_location) { + (Some((file2, offset2)), _) if file2 == other_file => { + offset2.cmp(&other_offset) + } + (Some(_), None) => cmp::Ordering::Greater, + (_, Some((other_file2, other_offset2))) if file == other_file2 => { + offset.cmp(&other_offset2) + } + (None, Some(_)) => cmp::Ordering::Less, + (Some((file2, offset2)), Some((other_file2, other_offset2))) => { + if file2 == other_file2 { + offset2.cmp(&other_offset2) + } else { + cmp::Ordering::Equal + } + } + (None, None) => cmp::Ordering::Equal, + } + } + /// Collect all of this cursor's children into a vec and return them. pub(crate) fn collect_children(&self) -> Vec { let mut children = vec![]; @@ -1564,63 +1605,6 @@ impl SourceLocation { } } -impl SourceLocation { - /// Compare source locations, also considering `#include` directives. - /// - /// Built-in items provided by the compiler (which don't have a source file), - /// are sorted first. Remaining files are sorted by their position in the source file. - /// If the items' source files differ, they are sorted by the position of the first - /// `#include` for their source file. If no source files are included, `None` is returned. - pub(crate) fn partial_cmp_with_context( - &self, - other: &Self, - ctx: &BindgenContext, - ) -> Option { - let (file, _, _, offset) = self.location(); - let (other_file, _, _, other_offset) = other.location(); - - match (file.name(), other_file.name()) { - (Some(file), Some(other_file)) => { - if file == other_file { - return offset.partial_cmp(&other_offset); - } - - let include_location = ctx.included_file_location(&file); - let other_include_location = - ctx.included_file_location(&other_file); - - match (include_location, other_include_location) { - (Some((file2, offset2)), _) if file2 == other_file => { - offset2.partial_cmp(&other_offset) - } - (Some(_), None) => Some(cmp::Ordering::Greater), - (_, Some((other_file2, other_offset2))) - if file == other_file2 => - { - offset.partial_cmp(&other_offset2) - } - (None, Some(_)) => Some(cmp::Ordering::Less), - ( - Some((file2, offset2)), - Some((other_file2, other_offset2)), - ) => { - if file2 == other_file2 { - offset2.partial_cmp(&other_offset2) - } else { - None - } - } - (None, None) => Some(cmp::Ordering::Equal), - } - } - // Built-in definitions should come first. - (Some(_), None) => Some(cmp::Ordering::Greater), - (None, Some(_)) => Some(cmp::Ordering::Less), - (None, None) => Some(cmp::Ordering::Equal), - } - } -} - impl fmt::Display for SourceLocation { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let (file, line, col, _) = self.location(); diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 9d1ebb4599..49b42574e1 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -1084,12 +1084,11 @@ fn parse_one( ctx: &mut BindgenContext, cursor: clang::Cursor, parent: Option, -) -> clang_sys::CXChildVisitResult { +) { if !filter_builtins(ctx, &cursor) { - return CXChildVisit_Continue; + return; } - use clang_sys::CXChildVisit_Continue; match Item::parse(cursor, parent, ctx) { Ok(..) => {} Err(ParseError::Continue) => {} @@ -1098,7 +1097,6 @@ fn parse_one( .visit_sorted(ctx, |ctx, child| parse_one(ctx, child, parent)); } } - CXChildVisit_Continue } /// Parse the Clang AST into our `Item` internal representation. From c14e53ea4bddef686f899c10b9df65ebc99cb8fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 15 Jun 2023 22:20:56 +0200 Subject: [PATCH 532/942] clang: Disable source order sorting for now. (#2558) * clang: Clean up source order sorting. This doesn't change behavior but is easier to debug and reason about (because you have the relevant cursors there). * clang: Disable source order sorting for now. This disables (hopefully temporarily) source order sorting, for causing correctness regressions like #2556. Fixes #2556. * tests: Add a test for #2556 * Remove merge artifact * Update clang.rs --------- Co-authored-by: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> --- .../expectations/tests/allowlist-file.rs | 2 +- .../tests/expectations/tests/issue-2556.rs | 43 ++++++++++++++++ .../expectations/tests/jsval_layout_opaque.rs | 4 +- .../tests/jsval_layout_opaque_1_0.rs | 4 +- .../tests/expectations/tests/layout_arp.rs | 14 +++--- .../tests/expectations/tests/layout_array.rs | 14 +++--- .../expectations/tests/layout_eth_conf.rs | 50 +++++++++---------- .../expectations/tests/layout_eth_conf_1_0.rs | 50 +++++++++---------- .../tests/expectations/tests/namespace.rs | 4 +- ...mplate_instantiation_with_fn_local_type.rs | 30 +++++------ bindgen-tests/tests/headers/issue-2556.h | 4 ++ .../headers/issue-2556/LayoutConstants.h | 7 +++ .../tests/headers/issue-2556/nsSize.h | 6 +++ .../tests/headers/issue-2556/nsStyleStruct.h | 3 ++ bindgen/clang.rs | 11 ++++ 15 files changed, 160 insertions(+), 86 deletions(-) create mode 100644 bindgen-tests/tests/expectations/tests/issue-2556.rs create mode 100644 bindgen-tests/tests/headers/issue-2556.h create mode 100644 bindgen-tests/tests/headers/issue-2556/LayoutConstants.h create mode 100644 bindgen-tests/tests/headers/issue-2556/nsSize.h create mode 100644 bindgen-tests/tests/headers/issue-2556/nsStyleStruct.h diff --git a/bindgen-tests/tests/expectations/tests/allowlist-file.rs b/bindgen-tests/tests/expectations/tests/allowlist-file.rs index 63953ccb67..1ee7a192ed 100644 --- a/bindgen-tests/tests/expectations/tests/allowlist-file.rs +++ b/bindgen-tests/tests/expectations/tests/allowlist-file.rs @@ -1,4 +1,5 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub const SOME_DEFUN: u32 = 123; extern "C" { #[link_name = "\u{1}_Z12SomeFunctionv"] pub fn SomeFunction(); @@ -6,7 +7,6 @@ extern "C" { extern "C" { pub static mut someVar: ::std::os::raw::c_int; } -pub const SOME_DEFUN: u32 = 123; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct someClass { diff --git a/bindgen-tests/tests/expectations/tests/issue-2556.rs b/bindgen-tests/tests/expectations/tests/issue-2556.rs new file mode 100644 index 0000000000..7722b851e2 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/issue-2556.rs @@ -0,0 +1,43 @@ +#![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 { + #[allow(unused_imports)] + use self::super::root; + #[repr(C)] + #[derive(Debug, Default, Copy, Clone)] + pub struct nsSize { + pub width: ::std::os::raw::c_int, + pub height: ::std::os::raw::c_int, + } + #[test] + fn bindgen_test_layout_nsSize() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of:: < nsSize > (), 8usize, concat!("Size of: ", + stringify!(nsSize)) + ); + assert_eq!( + ::std::mem::align_of:: < nsSize > (), 4usize, concat!("Alignment of ", + stringify!(nsSize)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).width) as usize - ptr as usize }, + 0usize, concat!("Offset of field: ", stringify!(nsSize), "::", + stringify!(width)) + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((* ptr).height) as usize - ptr as usize }, + 4usize, concat!("Offset of field: ", stringify!(nsSize), "::", + stringify!(height)) + ); + } + pub mod foo { + #[allow(unused_imports)] + use self::super::super::root; + extern "C" { + #[link_name = "\u{1}_ZN3fooL22kFallbackIntrinsicSizeE"] + pub static kFallbackIntrinsicSize: root::nsSize; + } + } +} diff --git a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs index 4ec58e7825..cfbf2f61cc 100644 --- a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs +++ b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs @@ -84,6 +84,8 @@ where } } pub const JSVAL_TAG_SHIFT: u32 = 47; +pub const JSVAL_PAYLOAD_MASK: u64 = 140737488355327; +pub const JSVAL_TAG_MASK: i64 = -140737488355328; #[repr(u8)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum JSValueType { @@ -125,8 +127,6 @@ pub enum JSValueShiftedTag { JSVAL_SHIFTED_TAG_NULL = 18445477436314353664, JSVAL_SHIFTED_TAG_OBJECT = 18445618173802708992, } -pub const JSVAL_PAYLOAD_MASK: u64 = 140737488355327; -pub const JSVAL_TAG_MASK: i64 = -140737488355328; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum JSWhyMagic { diff --git a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs index fa55d5c1ce..b97bbac96f 100644 --- a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs @@ -127,6 +127,8 @@ impl ::std::cmp::PartialEq for __BindgenUnionField { } impl ::std::cmp::Eq for __BindgenUnionField {} pub const JSVAL_TAG_SHIFT: u32 = 47; +pub const JSVAL_PAYLOAD_MASK: u64 = 140737488355327; +pub const JSVAL_TAG_MASK: i64 = -140737488355328; #[repr(u8)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum JSValueType { @@ -168,8 +170,6 @@ pub enum JSValueShiftedTag { JSVAL_SHIFTED_TAG_NULL = 18445477436314353664, JSVAL_SHIFTED_TAG_OBJECT = 18445618173802708992, } -pub const JSVAL_PAYLOAD_MASK: u64 = 140737488355327; -pub const JSVAL_TAG_MASK: i64 = -140737488355328; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum JSWhyMagic { diff --git a/bindgen-tests/tests/expectations/tests/layout_arp.rs b/bindgen-tests/tests/expectations/tests/layout_arp.rs index ee6bdf01a8..1ee045593f 100644 --- a/bindgen-tests/tests/expectations/tests/layout_arp.rs +++ b/bindgen-tests/tests/expectations/tests/layout_arp.rs @@ -1,5 +1,12 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const ETHER_ADDR_LEN: u32 = 6; +pub const ARP_HRD_ETHER: u32 = 1; +pub const ARP_OP_REQUEST: u32 = 1; +pub const ARP_OP_REPLY: u32 = 2; +pub const ARP_OP_REVREQUEST: u32 = 3; +pub const ARP_OP_REVREPLY: u32 = 4; +pub const ARP_OP_INVREQUEST: u32 = 8; +pub const ARP_OP_INVREPLY: u32 = 9; /** Ethernet address: A universally administered address is uniquely assigned to a device by its manufacturer. The first three octets (in transmission order) contain the @@ -126,10 +133,3 @@ fn bindgen_test_layout_arp_hdr() { stringify!(arp_data)) ); } -pub const ARP_HRD_ETHER: u32 = 1; -pub const ARP_OP_REQUEST: u32 = 1; -pub const ARP_OP_REPLY: u32 = 2; -pub const ARP_OP_REVREQUEST: u32 = 3; -pub const ARP_OP_REVREPLY: u32 = 4; -pub const ARP_OP_INVREQUEST: u32 = 8; -pub const ARP_OP_INVREPLY: u32 = 9; diff --git a/bindgen-tests/tests/expectations/tests/layout_array.rs b/bindgen-tests/tests/expectations/tests/layout_array.rs index 3654c62c7c..d9171be24b 100644 --- a/bindgen-tests/tests/expectations/tests/layout_array.rs +++ b/bindgen-tests/tests/expectations/tests/layout_array.rs @@ -1,6 +1,13 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const RTE_CACHE_LINE_SIZE: u32 = 64; pub const RTE_MEMPOOL_OPS_NAMESIZE: u32 = 32; +pub const RTE_MEMPOOL_MAX_OPS_IDX: u32 = 16; +pub const RTE_HEAP_NUM_FREELISTS: u32 = 13; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct rte_mempool { + _unused: [u8; 0], +} /** Prototype for implementation specific data provisioning function. The function should provide the implementation specific memory for @@ -12,11 +19,6 @@ pub const RTE_MEMPOOL_OPS_NAMESIZE: u32 = 32; pub type rte_mempool_alloc_t = ::std::option::Option< unsafe extern "C" fn(mp: *mut rte_mempool) -> ::std::os::raw::c_int, >; -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct rte_mempool { - _unused: [u8; 0], -} /// Free the opaque private data pointed to by mp->pool_data pointer. pub type rte_mempool_free_t = ::std::option::Option< unsafe extern "C" fn(mp: *mut rte_mempool), @@ -116,7 +118,6 @@ impl ::std::cmp::PartialEq for rte_mempool_ops { && self.get_count == other.get_count } } -pub const RTE_MEMPOOL_MAX_OPS_IDX: u32 = 16; /// The rte_spinlock_t type. #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] @@ -198,7 +199,6 @@ impl Default for rte_mempool_ops_table { } } } -pub const RTE_HEAP_NUM_FREELISTS: u32 = 13; /// Structure to hold malloc heap #[repr(C)] #[repr(align(64))] diff --git a/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs b/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs index 0916a16b85..1ec0744f0d 100644 --- a/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs +++ b/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs @@ -90,6 +90,31 @@ pub const ETH_VMDQ_MAX_VLAN_FILTERS: u32 = 64; pub const ETH_DCB_NUM_USER_PRIORITIES: u32 = 8; pub const ETH_VMDQ_DCB_NUM_QUEUES: u32 = 128; pub const ETH_DCB_NUM_QUEUES: u32 = 128; +pub const RTE_ETH_FDIR_MAX_FLEXLEN: u32 = 16; +pub const RTE_ETH_INSET_SIZE_MAX: u32 = 128; +pub const RTE_ETH_FLOW_UNKNOWN: u32 = 0; +pub const RTE_ETH_FLOW_RAW: u32 = 1; +pub const RTE_ETH_FLOW_IPV4: u32 = 2; +pub const RTE_ETH_FLOW_FRAG_IPV4: u32 = 3; +pub const RTE_ETH_FLOW_NONFRAG_IPV4_TCP: u32 = 4; +pub const RTE_ETH_FLOW_NONFRAG_IPV4_UDP: u32 = 5; +pub const RTE_ETH_FLOW_NONFRAG_IPV4_SCTP: u32 = 6; +pub const RTE_ETH_FLOW_NONFRAG_IPV4_OTHER: u32 = 7; +pub const RTE_ETH_FLOW_IPV6: u32 = 8; +pub const RTE_ETH_FLOW_FRAG_IPV6: u32 = 9; +pub const RTE_ETH_FLOW_NONFRAG_IPV6_TCP: u32 = 10; +pub const RTE_ETH_FLOW_NONFRAG_IPV6_UDP: u32 = 11; +pub const RTE_ETH_FLOW_NONFRAG_IPV6_SCTP: u32 = 12; +pub const RTE_ETH_FLOW_NONFRAG_IPV6_OTHER: u32 = 13; +pub const RTE_ETH_FLOW_L2_PAYLOAD: u32 = 14; +pub const RTE_ETH_FLOW_IPV6_EX: u32 = 15; +pub const RTE_ETH_FLOW_IPV6_TCP_EX: u32 = 16; +pub const RTE_ETH_FLOW_IPV6_UDP_EX: u32 = 17; +pub const RTE_ETH_FLOW_PORT: u32 = 18; +pub const RTE_ETH_FLOW_VXLAN: u32 = 19; +pub const RTE_ETH_FLOW_GENEVE: u32 = 20; +pub const RTE_ETH_FLOW_NVGRE: u32 = 21; +pub const RTE_ETH_FLOW_MAX: u32 = 22; #[repr(u32)] /** A set of values to identify what method is to be used to route packets to multiple queues.*/ @@ -1189,8 +1214,6 @@ pub enum rte_eth_payload_type { RTE_ETH_L4_PAYLOAD = 4, RTE_ETH_PAYLOAD_MAX = 8, } -pub const RTE_ETH_FDIR_MAX_FLEXLEN: u32 = 16; -pub const RTE_ETH_INSET_SIZE_MAX: u32 = 128; /** A structure used to select bytes extracted from the protocol layers to flexible payload for filter*/ #[repr(C)] @@ -1263,29 +1286,6 @@ fn bindgen_test_layout_rte_eth_fdir_flex_mask() { stringify!(mask)) ); } -pub const RTE_ETH_FLOW_UNKNOWN: u32 = 0; -pub const RTE_ETH_FLOW_RAW: u32 = 1; -pub const RTE_ETH_FLOW_IPV4: u32 = 2; -pub const RTE_ETH_FLOW_FRAG_IPV4: u32 = 3; -pub const RTE_ETH_FLOW_NONFRAG_IPV4_TCP: u32 = 4; -pub const RTE_ETH_FLOW_NONFRAG_IPV4_UDP: u32 = 5; -pub const RTE_ETH_FLOW_NONFRAG_IPV4_SCTP: u32 = 6; -pub const RTE_ETH_FLOW_NONFRAG_IPV4_OTHER: u32 = 7; -pub const RTE_ETH_FLOW_IPV6: u32 = 8; -pub const RTE_ETH_FLOW_FRAG_IPV6: u32 = 9; -pub const RTE_ETH_FLOW_NONFRAG_IPV6_TCP: u32 = 10; -pub const RTE_ETH_FLOW_NONFRAG_IPV6_UDP: u32 = 11; -pub const RTE_ETH_FLOW_NONFRAG_IPV6_SCTP: u32 = 12; -pub const RTE_ETH_FLOW_NONFRAG_IPV6_OTHER: u32 = 13; -pub const RTE_ETH_FLOW_L2_PAYLOAD: u32 = 14; -pub const RTE_ETH_FLOW_IPV6_EX: u32 = 15; -pub const RTE_ETH_FLOW_IPV6_TCP_EX: u32 = 16; -pub const RTE_ETH_FLOW_IPV6_UDP_EX: u32 = 17; -pub const RTE_ETH_FLOW_PORT: u32 = 18; -pub const RTE_ETH_FLOW_VXLAN: u32 = 19; -pub const RTE_ETH_FLOW_GENEVE: u32 = 20; -pub const RTE_ETH_FLOW_NVGRE: u32 = 21; -pub const RTE_ETH_FLOW_MAX: u32 = 22; /** A structure used to define all flexible payload related setting include flex payload and flex mask*/ #[repr(C)] diff --git a/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs b/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs index c20732c604..086384c450 100644 --- a/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs @@ -133,6 +133,31 @@ pub const ETH_VMDQ_MAX_VLAN_FILTERS: u32 = 64; pub const ETH_DCB_NUM_USER_PRIORITIES: u32 = 8; pub const ETH_VMDQ_DCB_NUM_QUEUES: u32 = 128; pub const ETH_DCB_NUM_QUEUES: u32 = 128; +pub const RTE_ETH_FDIR_MAX_FLEXLEN: u32 = 16; +pub const RTE_ETH_INSET_SIZE_MAX: u32 = 128; +pub const RTE_ETH_FLOW_UNKNOWN: u32 = 0; +pub const RTE_ETH_FLOW_RAW: u32 = 1; +pub const RTE_ETH_FLOW_IPV4: u32 = 2; +pub const RTE_ETH_FLOW_FRAG_IPV4: u32 = 3; +pub const RTE_ETH_FLOW_NONFRAG_IPV4_TCP: u32 = 4; +pub const RTE_ETH_FLOW_NONFRAG_IPV4_UDP: u32 = 5; +pub const RTE_ETH_FLOW_NONFRAG_IPV4_SCTP: u32 = 6; +pub const RTE_ETH_FLOW_NONFRAG_IPV4_OTHER: u32 = 7; +pub const RTE_ETH_FLOW_IPV6: u32 = 8; +pub const RTE_ETH_FLOW_FRAG_IPV6: u32 = 9; +pub const RTE_ETH_FLOW_NONFRAG_IPV6_TCP: u32 = 10; +pub const RTE_ETH_FLOW_NONFRAG_IPV6_UDP: u32 = 11; +pub const RTE_ETH_FLOW_NONFRAG_IPV6_SCTP: u32 = 12; +pub const RTE_ETH_FLOW_NONFRAG_IPV6_OTHER: u32 = 13; +pub const RTE_ETH_FLOW_L2_PAYLOAD: u32 = 14; +pub const RTE_ETH_FLOW_IPV6_EX: u32 = 15; +pub const RTE_ETH_FLOW_IPV6_TCP_EX: u32 = 16; +pub const RTE_ETH_FLOW_IPV6_UDP_EX: u32 = 17; +pub const RTE_ETH_FLOW_PORT: u32 = 18; +pub const RTE_ETH_FLOW_VXLAN: u32 = 19; +pub const RTE_ETH_FLOW_GENEVE: u32 = 20; +pub const RTE_ETH_FLOW_NVGRE: u32 = 21; +pub const RTE_ETH_FLOW_MAX: u32 = 22; #[repr(u32)] /** A set of values to identify what method is to be used to route packets to multiple queues.*/ @@ -1302,8 +1327,6 @@ pub enum rte_eth_payload_type { RTE_ETH_L4_PAYLOAD = 4, RTE_ETH_PAYLOAD_MAX = 8, } -pub const RTE_ETH_FDIR_MAX_FLEXLEN: u32 = 16; -pub const RTE_ETH_INSET_SIZE_MAX: u32 = 128; /** A structure used to select bytes extracted from the protocol layers to flexible payload for filter*/ #[repr(C)] @@ -1386,29 +1409,6 @@ impl Clone for rte_eth_fdir_flex_mask { *self } } -pub const RTE_ETH_FLOW_UNKNOWN: u32 = 0; -pub const RTE_ETH_FLOW_RAW: u32 = 1; -pub const RTE_ETH_FLOW_IPV4: u32 = 2; -pub const RTE_ETH_FLOW_FRAG_IPV4: u32 = 3; -pub const RTE_ETH_FLOW_NONFRAG_IPV4_TCP: u32 = 4; -pub const RTE_ETH_FLOW_NONFRAG_IPV4_UDP: u32 = 5; -pub const RTE_ETH_FLOW_NONFRAG_IPV4_SCTP: u32 = 6; -pub const RTE_ETH_FLOW_NONFRAG_IPV4_OTHER: u32 = 7; -pub const RTE_ETH_FLOW_IPV6: u32 = 8; -pub const RTE_ETH_FLOW_FRAG_IPV6: u32 = 9; -pub const RTE_ETH_FLOW_NONFRAG_IPV6_TCP: u32 = 10; -pub const RTE_ETH_FLOW_NONFRAG_IPV6_UDP: u32 = 11; -pub const RTE_ETH_FLOW_NONFRAG_IPV6_SCTP: u32 = 12; -pub const RTE_ETH_FLOW_NONFRAG_IPV6_OTHER: u32 = 13; -pub const RTE_ETH_FLOW_L2_PAYLOAD: u32 = 14; -pub const RTE_ETH_FLOW_IPV6_EX: u32 = 15; -pub const RTE_ETH_FLOW_IPV6_TCP_EX: u32 = 16; -pub const RTE_ETH_FLOW_IPV6_UDP_EX: u32 = 17; -pub const RTE_ETH_FLOW_PORT: u32 = 18; -pub const RTE_ETH_FLOW_VXLAN: u32 = 19; -pub const RTE_ETH_FLOW_GENEVE: u32 = 20; -pub const RTE_ETH_FLOW_NVGRE: u32 = 21; -pub const RTE_ETH_FLOW_MAX: u32 = 22; /** A structure used to define all flexible payload related setting include flex payload and flex mask*/ #[repr(C)] diff --git a/bindgen-tests/tests/expectations/tests/namespace.rs b/bindgen-tests/tests/expectations/tests/namespace.rs index a99711b277..83543b851e 100644 --- a/bindgen-tests/tests/expectations/tests/namespace.rs +++ b/bindgen-tests/tests/expectations/tests/namespace.rs @@ -17,7 +17,7 @@ pub mod root { pub fn in_whatever(); } } - pub mod _bindgen_mod_id_13 { + pub mod _bindgen_mod_id_17 { #[allow(unused_imports)] use self::super::super::root; #[repr(C)] @@ -46,7 +46,7 @@ pub mod root { #[repr(C)] #[derive(Debug)] pub struct C { - pub _base: root::_bindgen_mod_id_13::A, + pub _base: root::_bindgen_mod_id_17::A, pub m_c: T, pub m_c_ptr: *mut T, pub m_c_arr: [T; 10usize], diff --git a/bindgen-tests/tests/expectations/tests/template_instantiation_with_fn_local_type.rs b/bindgen-tests/tests/expectations/tests/template_instantiation_with_fn_local_type.rs index 5816a6c5e9..ab87b4160b 100644 --- a/bindgen-tests/tests/expectations/tests/template_instantiation_with_fn_local_type.rs +++ b/bindgen-tests/tests/expectations/tests/template_instantiation_with_fn_local_type.rs @@ -4,19 +4,12 @@ pub struct Foo { pub _address: u8, } -#[test] -fn __bindgen_test_layout_Foo_open0_Bar_close0_instantiation() { - assert_eq!( - ::std::mem::size_of:: < Foo > (), 1usize, - concat!("Size of template specialization: ", stringify!(Foo)) - ); - assert_eq!( - ::std::mem::align_of:: < Foo > (), 1usize, - concat!("Alignment of template specialization: ", stringify!(Foo)) - ); +extern "C" { + #[link_name = "\u{1}_Z1fv"] + pub fn f(); } #[test] -fn __bindgen_test_layout_Foo_open0_Boo_close0_instantiation() { +fn __bindgen_test_layout_Foo_open0_Bar_close0_instantiation() { assert_eq!( ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of template specialization: ", stringify!(Foo)) @@ -26,10 +19,6 @@ fn __bindgen_test_layout_Foo_open0_Boo_close0_instantiation() { concat!("Alignment of template specialization: ", stringify!(Foo)) ); } -extern "C" { - #[link_name = "\u{1}_Z1fv"] - pub fn f(); -} #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Baz { @@ -45,6 +34,17 @@ fn bindgen_test_layout_Baz() { stringify!(Baz)) ); } +#[test] +fn __bindgen_test_layout_Foo_open0_Boo_close0_instantiation() { + assert_eq!( + ::std::mem::size_of:: < Foo > (), 1usize, + concat!("Size of template specialization: ", stringify!(Foo)) + ); + assert_eq!( + ::std::mem::align_of:: < Foo > (), 1usize, + concat!("Alignment of template specialization: ", stringify!(Foo)) + ); +} #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Bar { diff --git a/bindgen-tests/tests/headers/issue-2556.h b/bindgen-tests/tests/headers/issue-2556.h new file mode 100644 index 0000000000..bbb1b874ec --- /dev/null +++ b/bindgen-tests/tests/headers/issue-2556.h @@ -0,0 +1,4 @@ +// bindgen-flags: --enable-cxx-namespaces -- -x c++ -Itests/headers -include tests/headers/issue-2556/nsStyleStruct.h -include tests/headers/issue-2556/LayoutConstants.h + +#include "issue-2556/nsSize.h" +#include "issue-2556/nsStyleStruct.h" diff --git a/bindgen-tests/tests/headers/issue-2556/LayoutConstants.h b/bindgen-tests/tests/headers/issue-2556/LayoutConstants.h new file mode 100644 index 0000000000..2ed1c864b2 --- /dev/null +++ b/bindgen-tests/tests/headers/issue-2556/LayoutConstants.h @@ -0,0 +1,7 @@ +#include "nsSize.h" + +namespace foo { + +static constexpr nsSize kFallbackIntrinsicSize(0, 0); + +} diff --git a/bindgen-tests/tests/headers/issue-2556/nsSize.h b/bindgen-tests/tests/headers/issue-2556/nsSize.h new file mode 100644 index 0000000000..8fe8b95023 --- /dev/null +++ b/bindgen-tests/tests/headers/issue-2556/nsSize.h @@ -0,0 +1,6 @@ +#pragma once + +struct nsSize { + int width, height; + constexpr nsSize(int aWidth, int aHeight) : width(aWidth), height(aHeight) {} +}; diff --git a/bindgen-tests/tests/headers/issue-2556/nsStyleStruct.h b/bindgen-tests/tests/headers/issue-2556/nsStyleStruct.h new file mode 100644 index 0000000000..4c6eedfb9a --- /dev/null +++ b/bindgen-tests/tests/headers/issue-2556/nsStyleStruct.h @@ -0,0 +1,3 @@ +#pragma once + +#include "nsSize.h" diff --git a/bindgen/clang.rs b/bindgen/clang.rs index 35aafc0f58..51064a558f 100644 --- a/bindgen/clang.rs +++ b/bindgen/clang.rs @@ -508,6 +508,17 @@ impl Cursor { ) where Visitor: FnMut(&mut BindgenContext, Cursor), { + // FIXME(#2556): The current source order stuff doesn't account well for different levels + // of includes, or includes that show up at the same byte offset because they are passed in + // via CLI. + const SOURCE_ORDER_ENABLED: bool = false; + if !SOURCE_ORDER_ENABLED { + return self.visit(|c| { + visitor(ctx, c); + CXChildVisit_Continue + }); + } + let mut children = self.collect_children(); for child in &children { if child.kind() == CXCursor_InclusionDirective { From 7ac500ca70bb4acb523281e775c184ceba60e0a1 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Thu, 15 Jun 2023 16:47:59 -0500 Subject: [PATCH 533/942] Fix expectation tests for clang 5 --- bindgen-tests/tests/expectations/tests/libclang-5/issue-2556.rs | 1 + 1 file changed, 1 insertion(+) create mode 100644 bindgen-tests/tests/expectations/tests/libclang-5/issue-2556.rs diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/issue-2556.rs b/bindgen-tests/tests/expectations/tests/libclang-5/issue-2556.rs new file mode 100644 index 0000000000..996b877e50 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/libclang-5/issue-2556.rs @@ -0,0 +1 @@ +/* error generating bindings */ From 167c0d643e49b7cb9aa9ad45ca24f90f542b200c Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Thu, 15 Jun 2023 15:35:31 -0500 Subject: [PATCH 534/942] Update CHANGELOG.md --- CHANGELOG.md | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c81900bdf6..e8477daaa8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,23 +7,25 @@ - [Removed](#removed) - [Fixed](#fixed) - [Security](#security) +- [0.66.1](#0661) + - [Removed](#removed-1) - [0.66.0](#0660) - [Added](#added-1) - [Changed](#changed-1) - - [Removed](#removed-1) + - [Removed](#removed-2) - [0.65.1](#0651) - [Fixed](#fixed-1) - [0.65.0](#0650) - [Added](#added-2) - [Changed](#changed-2) - - [Removed](#removed-2) + - [Removed](#removed-3) - [0.64.0](#0640) - [Added](#added-3) - [Changed](#changed-3) - [0.63.0](#0630) - [Added](#added-4) - [Changed](#changed-4) - - [Removed](#removed-3) + - [Removed](#removed-4) - [0.62.0](#0620) - [Added](#added-5) - [Changed](#changed-5) @@ -38,7 +40,7 @@ - [Added](#added-7) - [Fixed](#fixed-5) - [Changed](#changed-7) - - [Removed](#removed-4) + - [Removed](#removed-5) - [0.59.2](#0592) - [0.59.1](#0591) - [Fixed](#fixed-6) @@ -53,7 +55,7 @@ - [Fixed](#fixed-8) - [Changed](#changed-9) - [Deprecated](#deprecated) - - [Removed](#removed-5) + - [Removed](#removed-6) - [Fixed](#fixed-9) - [Security](#security-1) - [0.57.0](#0570) @@ -66,7 +68,7 @@ - [0.55.1](#0551) - [Fixed](#fixed-12) - [0.55.0](#0550) - - [Removed](#removed-6) + - [Removed](#removed-7) - [Added](#added-13) - [Changed](#changed-11) - [Fixed](#fixed-13) @@ -132,7 +134,7 @@ - [Fixed](#fixed-27) - [0.33.1 .. 0.46.0](#0331--0460) - [Added](#added-25) - - [Removed](#removed-7) + - [Removed](#removed-8) - [Changed](#changed-26) - [Fixed](#fixed-28) - [0.33.1](#0331) @@ -150,7 +152,7 @@ - [Added](#added-27) - [Changed](#changed-28) - [Deprecated](#deprecated-1) - - [Removed](#removed-8) + - [Removed](#removed-9) - [Fixed](#fixed-33) - [0.30.0](#0300) - [Added](#added-28) @@ -166,7 +168,7 @@ -------------------------------------------------------------------------------- -# Unreleased +# Unreleased ## Added ## Changed @@ -174,6 +176,11 @@ ## Fixed ## Security +# 0.66.1 + +## Removed +* Revert source order sorting (#2543) due to correctness regressions #2558. + # 0.66.0 ## Added From 38a779c61734c134429dfb99da3499173a848c17 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Thu, 15 Jun 2023 15:36:31 -0500 Subject: [PATCH 535/942] Bump versions --- Cargo.lock | 4 ++-- bindgen-cli/Cargo.toml | 4 ++-- bindgen/Cargo.toml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a6a1fe3e48..9195feb4ee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -23,7 +23,7 @@ dependencies = [ [[package]] name = "bindgen" -version = "0.66.0" +version = "0.66.1" dependencies = [ "annotate-snippets", "bitflags 2.2.1", @@ -45,7 +45,7 @@ dependencies = [ [[package]] name = "bindgen-cli" -version = "0.66.0" +version = "0.66.1" dependencies = [ "bindgen", "clap", diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index abe0298fe0..5db34395d1 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -11,7 +11,7 @@ readme = "../README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.66.0" +version = "0.66.1" edition = "2018" rust-version = "1.64.0" @@ -20,7 +20,7 @@ path = "main.rs" name = "bindgen" [dependencies] -bindgen = { path = "../bindgen", version = "=0.66.0", features = ["__cli", "experimental"] } +bindgen = { path = "../bindgen", version = "=0.66.1", features = ["__cli", "experimental"] } clap = { version = "4", features = ["derive"] } clap_complete = "4" env_logger = { version = "0.10.0", optional = true } diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index 831eb7be85..8e1b99dc80 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -14,7 +14,7 @@ readme = "../README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.66.0" +version = "0.66.1" edition = "2018" build = "build.rs" # If you change this, also update README.md and msrv in .github/workflows/bindgen.yml From ee980e1afeedc2afadafa6d8bdface54b5027e2d Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 16 Jun 2023 16:54:07 -0700 Subject: [PATCH 536/942] Update prettyplease to format macros better --- Cargo.lock | 22 +- bindgen-tests/Cargo.toml | 2 +- .../expectations/tests/16-byte-alignment.rs | 190 ++- .../tests/16-byte-alignment_1_0.rs | 185 ++- .../tests/expectations/tests/accessors.rs | 212 ++- .../expectations/tests/allowlist-file.rs | 67 +- .../tests/allowlist-namespaces-basic.rs | 10 +- .../tests/allowlist-namespaces.rs | 26 +- .../allowlisted-item-references-no-hash.rs | 25 +- ...llowlisted-item-references-no-partialeq.rs | 25 +- .../allowlisted_item_references_no_copy.rs | 25 +- .../expectations/tests/annotation_hide.rs | 23 +- .../expectations/tests/anon-fields-prefix.rs | 101 +- .../tests/expectations/tests/anon_enum.rs | 19 +- .../expectations/tests/anon_enum_trait.rs | 9 +- .../tests/anon_struct_in_union.rs | 55 +- .../tests/anon_struct_in_union_1_0.rs | 55 +- .../tests/expectations/tests/anon_union.rs | 20 +- .../expectations/tests/anon_union_1_0.rs | 20 +- .../tests/array-of-zero-sized-types.rs | 31 +- .../tests/attribute_warn_unused_result.rs | 9 +- ...rn_unused_result_no_attribute_detection.rs | 9 +- .../attribute_warn_unused_result_pre_1_27.rs | 9 +- .../expectations/tests/base-to-derived.rs | 10 +- .../tests/bindgen-union-inside-namespace.rs | 22 +- .../tests/bitfield-32bit-overflow.rs | 14 +- .../expectations/tests/bitfield-enum-basic.rs | 10 +- .../expectations/tests/bitfield-large.rs | 24 +- .../expectations/tests/bitfield-linux-32.rs | 19 +- .../tests/bitfield-method-same-name.rs | 13 +- .../expectations/tests/bitfield_align.rs | 83 +- .../expectations/tests/bitfield_align_2.rs | 14 +- .../tests/bitfield_large_overflow.rs | 10 +- .../tests/bitfield_method_mangling.rs | 14 +- .../tests/bitfield_pragma_packed.rs | 14 +- .../tests/blocklist-and-impl-debug.rs | 21 +- .../expectations/tests/blocklist-file.rs | 46 +- .../expectations/tests/blocklist-function.rs | 9 +- .../expectations/tests/blocklist-methods.rs | 9 +- .../expectations/tests/blocks-signature.rs | 32 +- .../tests/expectations/tests/blocks.rs | 32 +- .../tests/expectations/tests/bug-1529681.rs | 10 +- .../expectations/tests/c-empty-layout.rs | 9 +- .../tests/expectations/tests/c_naming.rs | 35 +- .../expectations/tests/canonical-types.rs | 85 +- .../canonical_path_without_namespacing.rs | 9 +- .../tests/expectations/tests/char.rs | 70 +- .../tests/expectations/tests/class.rs | 217 ++-- .../tests/expectations/tests/class_1_0.rs | 217 ++-- .../tests/expectations/tests/class_nested.rs | 72 +- .../expectations/tests/class_no_members.rs | 41 +- .../tests/expectations/tests/class_static.rs | 10 +- .../expectations/tests/class_static_const.rs | 8 +- .../tests/expectations/tests/class_use_as.rs | 31 +- .../expectations/tests/class_with_dtor.rs | 39 +- .../tests/class_with_inner_struct.rs | 242 ++-- .../tests/class_with_inner_struct_1_0.rs | 242 ++-- .../expectations/tests/class_with_typedef.rs | 46 +- .../expectations/tests/comment-indent.rs | 56 +- .../tests/expectations/tests/complex.rs | 66 +- .../expectations/tests/const-const-mut-ptr.rs | 14 +- .../expectations/tests/const_enum_unnamed.rs | 9 +- .../tests/constified-enum-module-overflow.rs | 23 +- .../expectations/tests/constify-all-enums.rs | 15 +- .../tests/constify-module-enums-basic.rs | 15 +- .../tests/constify-module-enums-namespace.rs | 24 +- .../constify-module-enums-shadow-name.rs | 14 +- .../constify-module-enums-simple-alias.rs | 53 +- ...onstify-module-enums-simple-nonamespace.rs | 19 +- .../tests/constify-module-enums-types.rs | 88 +- .../expectations/tests/constructor-tp.rs | 9 +- .../tests/expectations/tests/constructors.rs | 20 +- .../expectations/tests/constructors_1_33.rs | 20 +- .../tests/contains-vs-inherits-zero-sized.rs | 45 +- .../expectations/tests/convert-floats.rs | 41 +- .../expectations/tests/cpp-empty-layout.rs | 9 +- .../tests/expectations/tests/crtp.rs | 40 +- .../expectations/tests/ctypes-prefix-path.rs | 24 +- .../tests/default-template-parameter.rs | 18 +- .../tests/default_visibility_crate.rs | 4 +- .../tests/default_visibility_private.rs | 4 +- ...bility_private_respects_cxx_access_spec.rs | 4 +- .../expectations/tests/deleted-function.rs | 24 +- .../tests/derive-bitfield-method-same-name.rs | 30 +- .../tests/expectations/tests/derive-clone.rs | 21 +- .../expectations/tests/derive-clone_1_0.rs | 21 +- .../expectations/tests/derive-custom-cli.rs | 50 +- .../tests/derive-debug-bitfield-core.rs | 18 +- .../tests/derive-debug-bitfield.rs | 31 +- .../tests/derive-debug-function-pointer.rs | 33 +- .../tests/derive-debug-mangle-name.rs | 65 +- ...ive-debug-opaque-template-instantiation.rs | 15 +- .../expectations/tests/derive-debug-opaque.rs | 25 +- .../tests/derive-default-and-blocklist.rs | 21 +- .../tests/expectations/tests/derive-fn-ptr.rs | 28 +- .../tests/derive-hash-and-blocklist.rs | 21 +- .../tests/derive-hash-blocklisting.rs | 30 +- ...rive-hash-struct-with-anon-struct-float.rs | 34 +- .../derive-hash-struct-with-float-array.rs | 14 +- ...erive-hash-struct-with-incomplete-array.rs | 47 +- .../tests/derive-hash-struct-with-pointer.rs | 60 +- .../tests/derive-hash-template-inst-float.rs | 58 +- .../tests/derive-partialeq-and-blocklist.rs | 21 +- .../tests/derive-partialeq-anonfield.rs | 20 +- .../tests/derive-partialeq-base.rs | 25 +- .../tests/derive-partialeq-bitfield.rs | 18 +- .../tests/derive-partialeq-core.rs | 14 +- .../tests/derive-partialeq-pointer.rs | 45 +- .../tests/derive-partialeq-union.rs | 32 +- .../tests/derive-partialeq-union_1_0.rs | 32 +- .../tests/disable-nested-struct-naming.rs | 162 ++- .../tests/disable-untagged-union.rs | 19 +- .../tests/divide-by-zero-in-struct-layout.rs | 4 +- .../expectations/tests/do-not-derive-copy.rs | 21 +- .../tests/expectations/tests/doggo-or-null.rs | 34 +- .../tests/duplicated-definition-count.rs | 10 +- .../duplicated-namespaces-definitions.rs | 38 +- .../tests/dynamic_loading_with_blocklist.rs | 13 +- .../tests/dynamic_loading_with_class.rs | 13 +- .../tests/enum-default-bitfield.rs | 14 +- .../expectations/tests/enum-default-consts.rs | 14 +- .../expectations/tests/enum-default-module.rs | 14 +- .../expectations/tests/enum-default-rust.rs | 14 +- .../expectations/tests/enum-no-debug-rust.rs | 14 +- .../tests/expectations/tests/enum.rs | 14 +- .../tests/enum_and_vtable_mangling.rs | 13 +- .../expectations/tests/explicit-padding.rs | 50 +- .../expectations/tests/extern-const-struct.rs | 15 +- .../tests/field-visibility-callback.rs | 25 +- .../expectations/tests/field-visibility.rs | 24 +- .../tests/forward-declaration-autoptr.rs | 24 +- .../tests/forward_declared_complex_types.rs | 24 +- .../forward_declared_complex_types_1_0.rs | 24 +- .../tests/forward_declared_struct.rs | 26 +- .../expectations/tests/func_ptr_in_struct.rs | 14 +- .../tests/func_return_must_use.rs | 20 +- .../tests/gen-constructors-neg.rs | 9 +- .../expectations/tests/gen-constructors.rs | 9 +- .../expectations/tests/gen-destructors-neg.rs | 14 +- .../expectations/tests/gen-destructors.rs | 14 +- .../expectations/tests/generate-inline.rs | 9 +- .../tests/expectations/tests/i128.rs | 21 +- .../tests/incomplete-array-padding.rs | 13 +- ...from-template-instantiation-with-vtable.rs | 112 +- .../tests/inherit_multiple_interfaces.rs | 39 +- .../expectations/tests/inherit_typedef.rs | 18 +- .../expectations/tests/inline_namespace.rs | 15 +- .../tests/inline_namespace_conservative.rs | 15 +- .../tests/expectations/tests/inner_const.rs | 14 +- .../expectations/tests/inner_template_self.rs | 25 +- .../tests/expectations/tests/issue-1034.rs | 13 +- .../issue-1076-unnamed-bitfield-alignment.rs | 13 +- .../tests/issue-1118-using-forward-decl.rs | 50 +- .../tests/issue-1197-pure-virtual-stuff.rs | 9 +- .../tests/issue-1216-variadic-member.rs | 14 +- .../tests/expectations/tests/issue-1281.rs | 42 +- .../tests/expectations/tests/issue-1285.rs | 34 +- .../tests/expectations/tests/issue-1291.rs | 85 +- .../tests/issue-1382-rust-primitive-types.rs | 79 +- .../tests/expectations/tests/issue-1443.rs | 76 +- .../tests/expectations/tests/issue-1454.rs | 15 +- .../tests/expectations/tests/issue-1498.rs | 81 +- .../tests/expectations/tests/issue-1947.rs | 29 +- .../tests/issue-1977-larger-arrays.rs | 14 +- .../tests/expectations/tests/issue-1995.rs | 14 +- .../tests/expectations/tests/issue-2019.rs | 26 +- .../tests/expectations/tests/issue-2556.rs | 22 +- .../tests/expectations/tests/issue-372.rs | 52 +- .../tests/expectations/tests/issue-410.rs | 10 +- .../tests/expectations/tests/issue-447.rs | 20 +- .../tests/issue-537-repr-packed-n.rs | 70 +- .../tests/expectations/tests/issue-537.rs | 70 +- ...ate-params-causing-layout-test-failures.rs | 20 +- .../tests/issue-573-layout-test-failures.rs | 25 +- .../issue-574-assertion-failure-in-codegen.rs | 25 +- ...issue-584-stylo-template-analysis-panic.rs | 39 +- .../tests/issue-639-typedef-anon-field.rs | 53 +- .../tests/issue-643-inner-struct.rs | 52 +- .../issue-648-derive-debug-with-padding.rs | 47 +- .../tests/expectations/tests/issue-674-1.rs | 21 +- .../tests/expectations/tests/issue-674-2.rs | 42 +- .../tests/expectations/tests/issue-674-3.rs | 29 +- .../issue-691-template-parameter-virtual.rs | 30 +- .../tests/issue-739-pointer-wide-bitfield.rs | 13 +- .../tests/issue-801-opaque-sloppiness.rs | 21 +- ...07-opaque-types-methods-being-generated.rs | 61 +- .../tests/expectations/tests/issue-816.rs | 14 +- ...26-generating-methods-when-asked-not-to.rs | 9 +- .../tests/expectations/tests/issue-834.rs | 8 +- .../tests/issue-888-enum-var-decl-jump.rs | 10 +- .../issue-944-derive-copy-and-blocklisting.rs | 15 +- .../tests/expectations/tests/issue-946.rs | 9 +- .../tests/expectations/tests/issue_311.rs | 20 +- .../expectations/tests/jsval_layout_opaque.rs | 156 ++- .../tests/jsval_layout_opaque_1_0.rs | 156 ++- .../tests/expectations/tests/layout.rs | 5 +- .../tests/expectations/tests/layout_align.rs | 35 +- .../tests/expectations/tests/layout_arp.rs | 94 +- .../tests/expectations/tests/layout_array.rs | 197 ++- .../tests/layout_array_too_long.rs | 141 +- .../tests/layout_cmdline_token.rs | 139 +- .../expectations/tests/layout_eth_conf.rs | 1132 ++++++++++++----- .../expectations/tests/layout_eth_conf_1_0.rs | 1132 ++++++++++++----- .../expectations/tests/layout_kni_mbuf.rs | 112 +- .../tests/layout_large_align_field.rs | 379 ++++-- .../tests/expectations/tests/layout_mbuf.rs | 490 ++++--- .../expectations/tests/layout_mbuf_1_0.rs | 473 ++++--- .../expectations/tests/libclang-5/auto.rs | 9 +- .../tests/libclang-5/call-conv-field.rs | 32 +- .../tests/libclang-5/const_bool.rs | 8 +- .../issue-769-bad-instantiation-test.rs | 36 +- .../tests/libclang-5/mangling-win32.rs | 9 +- .../partial-specialization-and-inheritance.rs | 10 +- .../type_alias_template_specialized.rs | 33 +- .../expectations/tests/libclang-9/auto.rs | 9 +- .../tests/libclang-9/call-conv-field.rs | 32 +- .../expectations/tests/libclang-9/class.rs | 388 ++++-- .../tests/libclang-9/class_1_0.rs | 388 ++++-- .../tests/libclang-9/const_bool.rs | 8 +- ...erive-hash-struct-with-incomplete-array.rs | 92 +- .../libclang-9/incomplete-array-padding.rs | 18 +- .../libclang-9/issue-643-inner-struct.rs | 72 +- .../issue-769-bad-instantiation-test.rs | 36 +- .../tests/libclang-9/layout_align.rs | 66 +- .../tests/libclang-9/mangling-win32.rs | 9 +- .../partial-specialization-and-inheritance.rs | 10 +- .../type_alias_template_specialized.rs | 33 +- .../tests/libclang-9/zero-sized-array.rs | 88 +- .../tests/expectations/tests/long_double.rs | 14 +- .../expectations/tests/mangling-linux32.rs | 9 +- .../expectations/tests/mangling-linux64.rs | 9 +- .../expectations/tests/mangling-macos.rs | 9 +- .../expectations/tests/mangling-win64.rs | 9 +- .../expectations/tests/merge-extern-blocks.rs | 31 +- .../expectations/tests/method-mangling.rs | 9 +- .../expectations/tests/module-allowlisted.rs | 10 +- .../tests/expectations/tests/msvc-no-usr.rs | 13 +- .../multiple-inherit-empty-correct-layout.rs | 27 +- .../tests/expectations/tests/mutable.rs | 55 +- .../tests/expectations/tests/namespace.rs | 15 +- .../tests/expectations/tests/nested.rs | 53 +- .../tests/expectations/tests/nested_vtable.rs | 30 +- .../tests/nested_within_namespace.rs | 48 +- .../tests/expectations/tests/no-comments.rs | 14 +- .../expectations/tests/no-derive-debug.rs | 19 +- .../expectations/tests/no-derive-default.rs | 19 +- .../expectations/tests/no-hash-allowlisted.rs | 15 +- .../expectations/tests/no-hash-opaque.rs | 10 +- .../tests/no-partialeq-allowlisted.rs | 15 +- .../expectations/tests/no-partialeq-opaque.rs | 10 +- .../tests/no-recursive-allowlisting.rs | 14 +- .../tests/expectations/tests/no-std.rs | 24 +- .../expectations/tests/no_copy_allowlisted.rs | 15 +- .../expectations/tests/no_copy_opaque.rs | 10 +- .../tests/no_debug_allowlisted.rs | 15 +- .../expectations/tests/no_debug_opaque.rs | 10 +- .../tests/no_default_allowlisted.rs | 15 +- .../expectations/tests/no_default_opaque.rs | 10 +- .../expectations/tests/no_size_t_is_usize.rs | 23 +- .../expectations/tests/non-type-params.rs | 43 +- .../expectations/tests/objc_interface_type.rs | 15 +- .../expectations/tests/only_bitfields.rs | 12 +- .../tests/opaque-template-inst-member-2.rs | 53 +- .../tests/opaque-template-inst-member.rs | 53 +- ...paque-template-instantiation-namespaced.rs | 94 +- .../tests/opaque-template-instantiation.rs | 60 +- .../expectations/tests/opaque-tracing.rs | 10 +- .../expectations/tests/opaque_in_struct.rs | 26 +- .../expectations/tests/opaque_pointer.rs | 41 +- .../expectations/tests/packed-bitfield.rs | 13 +- .../tests/packed-n-with-padding.rs | 30 +- .../tests/expectations/tests/packed-vtable.rs | 10 +- .../tests/expectations/tests/parm-union.rs | 10 +- .../tests/expectations/tests/private.rs | 96 +- .../expectations/tests/private_fields.rs | 186 +-- .../tests/expectations/tests/public-dtor.rs | 20 +- .../expectations/tests/ref_argument_array.rs | 9 +- .../tests/reparented_replacement.rs | 16 +- .../tests/expectations/tests/replace_use.rs | 24 +- .../tests/expectations/tests/repr-align.rs | 36 +- ...ame_struct_name_in_different_namespaces.rs | 20 +- .../tests/sentry-defined-multiple-times.rs | 249 ++-- .../expectations/tests/size_t_template.rs | 13 +- .../tests/expectations/tests/sorted_items.rs | 84 +- .../expectations/tests/stdint_typedef.rs | 15 +- ...ruct_containing_forward_declared_struct.rs | 26 +- .../expectations/tests/struct_typedef.rs | 42 +- .../expectations/tests/struct_typedef_ns.rs | 42 +- .../tests/struct_with_anon_struct.rs | 34 +- .../tests/struct_with_anon_struct_array.rs | 59 +- .../tests/struct_with_anon_struct_pointer.rs | 34 +- .../tests/struct_with_anon_union.rs | 34 +- .../tests/struct_with_anon_union_1_0.rs | 34 +- .../tests/struct_with_anon_unnamed_struct.rs | 29 +- .../tests/struct_with_anon_unnamed_union.rs | 29 +- .../struct_with_anon_unnamed_union_1_0.rs | 29 +- .../tests/struct_with_bitfields.rs | 19 +- .../tests/struct_with_derive_debug.rs | 60 +- .../tests/struct_with_large_array.rs | 14 +- .../expectations/tests/struct_with_nesting.rs | 115 +- .../tests/struct_with_nesting_1_0.rs | 115 +- .../expectations/tests/struct_with_packing.rs | 18 +- .../expectations/tests/struct_with_struct.rs | 34 +- .../tests/expectations/tests/template.rs | 527 +++++--- ...mplate_instantiation_with_fn_local_type.rs | 47 +- .../tests/expectations/tests/timex.rs | 34 +- .../tests/expectations/tests/transform-op.rs | 20 +- ...type-referenced-by-allowlisted-function.rs | 15 +- .../tests/typedef-pointer-overlap.rs | 43 +- .../tests/expectations/tests/typeref.rs | 78 +- .../tests/expectations/tests/typeref_1_0.rs | 78 +- .../tests/expectations/tests/underscore.rs | 15 +- .../tests/expectations/tests/union-align.rs | 28 +- .../tests/expectations/tests/union-in-ns.rs | 15 +- .../expectations/tests/union-in-ns_1_0.rs | 15 +- .../expectations/tests/union_bitfield.rs | 21 +- .../expectations/tests/union_bitfield_1_0.rs | 26 +- .../tests/expectations/tests/union_dtor.rs | 20 +- .../expectations/tests/union_dtor_1_0.rs | 20 +- .../tests/expectations/tests/union_fields.rs | 31 +- .../expectations/tests/union_fields_1_0.rs | 31 +- .../tests/union_with_anon_struct.rs | 34 +- .../tests/union_with_anon_struct_1_0.rs | 34 +- .../tests/union_with_anon_struct_bitfield.rs | 28 +- .../union_with_anon_struct_bitfield_1_0.rs | 28 +- .../tests/union_with_anon_union.rs | 34 +- .../tests/union_with_anon_union_1_0.rs | 34 +- .../tests/union_with_anon_unnamed_struct.rs | 69 +- .../union_with_anon_unnamed_struct_1_0.rs | 69 +- .../tests/union_with_anon_unnamed_union.rs | 34 +- .../union_with_anon_unnamed_union_1_0.rs | 34 +- .../tests/union_with_big_member.rs | 60 +- .../tests/union_with_big_member_1_0.rs | 60 +- .../expectations/tests/union_with_nesting.rs | 88 +- .../tests/union_with_nesting_1_0.rs | 88 +- .../tests/union_with_non_copy_member.rs | 105 +- .../tests/expectations/tests/unknown_attr.rs | 36 +- .../expectations/tests/unsorted-items.rs | 40 +- .../tests/expectations/tests/use-core.rs | 44 +- .../tests/expectations/tests/use-core_1_0.rs | 44 +- .../tests/expectations/tests/var-tracing.rs | 23 +- .../expectations/tests/variadic-method.rs | 9 +- .../tests/expectations/tests/vector.rs | 14 +- .../tests/expectations/tests/virtual_dtor.rs | 10 +- .../expectations/tests/virtual_interface.rs | 40 +- .../expectations/tests/virtual_overloaded.rs | 8 +- .../tests/vtable_recursive_sig.rs | 19 +- .../tests/wasm-constructor-returns.rs | 9 +- .../expectations/tests/weird_bitfields.rs | 123 +- .../expectations/tests/what_is_going_on.rs | 10 +- .../expectations/tests/win32-thiscall_1_0.rs | 9 +- .../tests/win32-thiscall_nightly.rs | 9 +- .../tests/zero-size-array-align.rs | 25 +- .../expectations/tests/zero-sized-array.rs | 66 +- bindgen/Cargo.toml | 2 +- 355 files changed, 11413 insertions(+), 6401 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9195feb4ee..538a5bd624 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -39,7 +39,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.7", + "syn 2.0.18", "which", ] @@ -73,7 +73,7 @@ dependencies = [ "diff", "prettyplease", "shlex", - "syn 2.0.7", + "syn 2.0.18", "tempfile", ] @@ -410,12 +410,12 @@ checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" [[package]] name = "prettyplease" -version = "0.2.0" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4508c0eff4d1e708551034de4bddd61bf8bda8c7b5ae72bd844cf68ea21117ac" +checksum = "43ded2b5b204571f065ab8540367d738dfe1b3606ab9eb669dcfb5e7a3a07501" dependencies = [ "proc-macro2", - "syn 2.0.7", + "syn 2.0.18", ] [[package]] @@ -444,9 +444,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.52" +version = "1.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d0e1ae9e836cc3beddd63db0df682593d7e2d3d891ae8c9083d2113e1744224" +checksum = "dec2b086b7a862cf4de201096214fa870344cf922b2b30c167badb3af3195406" dependencies = [ "unicode-ident", ] @@ -474,9 +474,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.26" +version = "1.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" +checksum = "1b9ab9c7eadfd8df19006f1cf1a4aed13540ed5cbc047010ece5826e10825488" dependencies = [ "proc-macro2", ] @@ -570,9 +570,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.7" +version = "2.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a9a90d19f27bb60792270bb90225f96d97fc5705395134b2ca1dcbb3acc27f4" +checksum = "32d41677bcbe24c20c52e7c70b0d8db04134c5d1066bf98662e2871ad200ea3e" dependencies = [ "proc-macro2", "quote", diff --git a/bindgen-tests/Cargo.toml b/bindgen-tests/Cargo.toml index eb7e1b1742..5bf8ac635e 100644 --- a/bindgen-tests/Cargo.toml +++ b/bindgen-tests/Cargo.toml @@ -10,7 +10,7 @@ clap = { version = "4", features = ["derive"] } clap_complete = "4" diff = "0.1" shlex = "1" -prettyplease = { version = "0.2.0" } +prettyplease = { version = "0.2.7", features = ["verbatim"] } syn = { version = "2.0" } tempfile = "3" diff --git a/bindgen-tests/tests/expectations/tests/16-byte-alignment.rs b/bindgen-tests/tests/expectations/tests/16-byte-alignment.rs index b280f2f5be..b93cae0465 100644 --- a/bindgen-tests/tests/expectations/tests/16-byte-alignment.rs +++ b/bindgen-tests/tests/expectations/tests/16-byte-alignment.rs @@ -23,22 +23,34 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 > (), 4usize, - concat!("Size of: ", stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 > (), 2usize, - concat!("Alignment of ", stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1)) + ::std::mem::align_of::(), + 2usize, + concat!("Alignment of ", stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).dport) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", - stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1), "::", stringify!(dport)) + unsafe { ::std::ptr::addr_of!((*ptr).dport) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(dport), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).sport) as usize - ptr as usize }, 2usize, - concat!("Offset of field: ", - stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1), "::", stringify!(sport)) + unsafe { ::std::ptr::addr_of!((*ptr).sport) as usize - ptr as usize }, + 2usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(sport), + ), ); } #[test] @@ -46,17 +58,24 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < rte_ipv4_tuple__bindgen_ty_1 > (), 4usize, - concat!("Size of: ", stringify!(rte_ipv4_tuple__bindgen_ty_1)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(rte_ipv4_tuple__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < rte_ipv4_tuple__bindgen_ty_1 > (), 4usize, - concat!("Alignment of ", stringify!(rte_ipv4_tuple__bindgen_ty_1)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_ipv4_tuple__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).sctp_tag) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_ipv4_tuple__bindgen_ty_1), - "::", stringify!(sctp_tag)) + unsafe { ::std::ptr::addr_of!((*ptr).sctp_tag) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv4_tuple__bindgen_ty_1), + "::", + stringify!(sctp_tag), + ), ); } impl Default for rte_ipv4_tuple__bindgen_ty_1 { @@ -73,22 +92,34 @@ fn bindgen_test_layout_rte_ipv4_tuple() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < rte_ipv4_tuple > (), 12usize, concat!("Size of: ", - stringify!(rte_ipv4_tuple)) + ::std::mem::size_of::(), + 12usize, + concat!("Size of: ", stringify!(rte_ipv4_tuple)), ); assert_eq!( - ::std::mem::align_of:: < rte_ipv4_tuple > (), 4usize, concat!("Alignment of ", - stringify!(rte_ipv4_tuple)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_ipv4_tuple)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).src_addr) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_ipv4_tuple), "::", - stringify!(src_addr)) + unsafe { ::std::ptr::addr_of!((*ptr).src_addr) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv4_tuple), + "::", + stringify!(src_addr), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).dst_addr) as usize - ptr as usize }, - 4usize, concat!("Offset of field: ", stringify!(rte_ipv4_tuple), "::", - stringify!(dst_addr)) + unsafe { ::std::ptr::addr_of!((*ptr).dst_addr) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv4_tuple), + "::", + stringify!(dst_addr), + ), ); } impl Default for rte_ipv4_tuple { @@ -124,22 +155,34 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 > (), 4usize, - concat!("Size of: ", stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 > (), 2usize, - concat!("Alignment of ", stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1)) + ::std::mem::align_of::(), + 2usize, + concat!("Alignment of ", stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).dport) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", - stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1), "::", stringify!(dport)) + unsafe { ::std::ptr::addr_of!((*ptr).dport) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(dport), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).sport) as usize - ptr as usize }, 2usize, - concat!("Offset of field: ", - stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1), "::", stringify!(sport)) + unsafe { ::std::ptr::addr_of!((*ptr).sport) as usize - ptr as usize }, + 2usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(sport), + ), ); } #[test] @@ -147,17 +190,24 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < rte_ipv6_tuple__bindgen_ty_1 > (), 4usize, - concat!("Size of: ", stringify!(rte_ipv6_tuple__bindgen_ty_1)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(rte_ipv6_tuple__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < rte_ipv6_tuple__bindgen_ty_1 > (), 4usize, - concat!("Alignment of ", stringify!(rte_ipv6_tuple__bindgen_ty_1)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_ipv6_tuple__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).sctp_tag) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_ipv6_tuple__bindgen_ty_1), - "::", stringify!(sctp_tag)) + unsafe { ::std::ptr::addr_of!((*ptr).sctp_tag) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv6_tuple__bindgen_ty_1), + "::", + stringify!(sctp_tag), + ), ); } impl Default for rte_ipv6_tuple__bindgen_ty_1 { @@ -174,22 +224,34 @@ fn bindgen_test_layout_rte_ipv6_tuple() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < rte_ipv6_tuple > (), 36usize, concat!("Size of: ", - stringify!(rte_ipv6_tuple)) + ::std::mem::size_of::(), + 36usize, + concat!("Size of: ", stringify!(rte_ipv6_tuple)), ); assert_eq!( - ::std::mem::align_of:: < rte_ipv6_tuple > (), 4usize, concat!("Alignment of ", - stringify!(rte_ipv6_tuple)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_ipv6_tuple)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).src_addr) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_ipv6_tuple), "::", - stringify!(src_addr)) + unsafe { ::std::ptr::addr_of!((*ptr).src_addr) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv6_tuple), + "::", + stringify!(src_addr), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).dst_addr) as usize - ptr as usize }, - 16usize, concat!("Offset of field: ", stringify!(rte_ipv6_tuple), "::", - stringify!(dst_addr)) + unsafe { ::std::ptr::addr_of!((*ptr).dst_addr) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv6_tuple), + "::", + stringify!(dst_addr), + ), ); } impl Default for rte_ipv6_tuple { @@ -213,20 +275,24 @@ fn bindgen_test_layout_rte_thash_tuple() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < rte_thash_tuple > (), 48usize, concat!("Size of: ", - stringify!(rte_thash_tuple)) + ::std::mem::size_of::(), + 48usize, + concat!("Size of: ", stringify!(rte_thash_tuple)), ); assert_eq!( - ::std::mem::align_of:: < rte_thash_tuple > (), 16usize, concat!("Alignment of ", - stringify!(rte_thash_tuple)) + ::std::mem::align_of::(), + 16usize, + concat!("Alignment of ", stringify!(rte_thash_tuple)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).v4) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_thash_tuple), "::", stringify!(v4)) + unsafe { ::std::ptr::addr_of!((*ptr).v4) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(rte_thash_tuple), "::", stringify!(v4)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).v6) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_thash_tuple), "::", stringify!(v6)) + unsafe { ::std::ptr::addr_of!((*ptr).v6) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(rte_thash_tuple), "::", stringify!(v6)), ); } impl Default for rte_thash_tuple { diff --git a/bindgen-tests/tests/expectations/tests/16-byte-alignment_1_0.rs b/bindgen-tests/tests/expectations/tests/16-byte-alignment_1_0.rs index 906d9a121b..758675dace 100644 --- a/bindgen-tests/tests/expectations/tests/16-byte-alignment_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/16-byte-alignment_1_0.rs @@ -69,22 +69,34 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 > (), 4usize, - concat!("Size of: ", stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 > (), 2usize, - concat!("Alignment of ", stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1)) + ::std::mem::align_of::(), + 2usize, + concat!("Alignment of ", stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).dport) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", - stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1), "::", stringify!(dport)) + unsafe { ::std::ptr::addr_of!((*ptr).dport) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(dport), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).sport) as usize - ptr as usize }, 2usize, - concat!("Offset of field: ", - stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1), "::", stringify!(sport)) + unsafe { ::std::ptr::addr_of!((*ptr).sport) as usize - ptr as usize }, + 2usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(sport), + ), ); } impl Clone for rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 { @@ -97,17 +109,24 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < rte_ipv4_tuple__bindgen_ty_1 > (), 4usize, - concat!("Size of: ", stringify!(rte_ipv4_tuple__bindgen_ty_1)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(rte_ipv4_tuple__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < rte_ipv4_tuple__bindgen_ty_1 > (), 4usize, - concat!("Alignment of ", stringify!(rte_ipv4_tuple__bindgen_ty_1)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_ipv4_tuple__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).sctp_tag) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_ipv4_tuple__bindgen_ty_1), - "::", stringify!(sctp_tag)) + unsafe { ::std::ptr::addr_of!((*ptr).sctp_tag) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv4_tuple__bindgen_ty_1), + "::", + stringify!(sctp_tag), + ), ); } impl Clone for rte_ipv4_tuple__bindgen_ty_1 { @@ -120,22 +139,34 @@ fn bindgen_test_layout_rte_ipv4_tuple() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < rte_ipv4_tuple > (), 12usize, concat!("Size of: ", - stringify!(rte_ipv4_tuple)) + ::std::mem::size_of::(), + 12usize, + concat!("Size of: ", stringify!(rte_ipv4_tuple)), ); assert_eq!( - ::std::mem::align_of:: < rte_ipv4_tuple > (), 4usize, concat!("Alignment of ", - stringify!(rte_ipv4_tuple)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_ipv4_tuple)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).src_addr) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_ipv4_tuple), "::", - stringify!(src_addr)) + unsafe { ::std::ptr::addr_of!((*ptr).src_addr) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv4_tuple), + "::", + stringify!(src_addr), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).dst_addr) as usize - ptr as usize }, - 4usize, concat!("Offset of field: ", stringify!(rte_ipv4_tuple), "::", - stringify!(dst_addr)) + unsafe { ::std::ptr::addr_of!((*ptr).dst_addr) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv4_tuple), + "::", + stringify!(dst_addr), + ), ); } impl Clone for rte_ipv4_tuple { @@ -170,22 +201,34 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 > (), 4usize, - concat!("Size of: ", stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 > (), 2usize, - concat!("Alignment of ", stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1)) + ::std::mem::align_of::(), + 2usize, + concat!("Alignment of ", stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).dport) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", - stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1), "::", stringify!(dport)) + unsafe { ::std::ptr::addr_of!((*ptr).dport) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(dport), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).sport) as usize - ptr as usize }, 2usize, - concat!("Offset of field: ", - stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1), "::", stringify!(sport)) + unsafe { ::std::ptr::addr_of!((*ptr).sport) as usize - ptr as usize }, + 2usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(sport), + ), ); } impl Clone for rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 { @@ -198,17 +241,24 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < rte_ipv6_tuple__bindgen_ty_1 > (), 4usize, - concat!("Size of: ", stringify!(rte_ipv6_tuple__bindgen_ty_1)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(rte_ipv6_tuple__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < rte_ipv6_tuple__bindgen_ty_1 > (), 4usize, - concat!("Alignment of ", stringify!(rte_ipv6_tuple__bindgen_ty_1)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_ipv6_tuple__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).sctp_tag) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_ipv6_tuple__bindgen_ty_1), - "::", stringify!(sctp_tag)) + unsafe { ::std::ptr::addr_of!((*ptr).sctp_tag) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv6_tuple__bindgen_ty_1), + "::", + stringify!(sctp_tag), + ), ); } impl Clone for rte_ipv6_tuple__bindgen_ty_1 { @@ -221,22 +271,34 @@ fn bindgen_test_layout_rte_ipv6_tuple() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < rte_ipv6_tuple > (), 36usize, concat!("Size of: ", - stringify!(rte_ipv6_tuple)) + ::std::mem::size_of::(), + 36usize, + concat!("Size of: ", stringify!(rte_ipv6_tuple)), ); assert_eq!( - ::std::mem::align_of:: < rte_ipv6_tuple > (), 4usize, concat!("Alignment of ", - stringify!(rte_ipv6_tuple)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_ipv6_tuple)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).src_addr) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_ipv6_tuple), "::", - stringify!(src_addr)) + unsafe { ::std::ptr::addr_of!((*ptr).src_addr) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv6_tuple), + "::", + stringify!(src_addr), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).dst_addr) as usize - ptr as usize }, - 16usize, concat!("Offset of field: ", stringify!(rte_ipv6_tuple), "::", - stringify!(dst_addr)) + unsafe { ::std::ptr::addr_of!((*ptr).dst_addr) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_ipv6_tuple), + "::", + stringify!(dst_addr), + ), ); } impl Clone for rte_ipv6_tuple { @@ -256,16 +318,19 @@ fn bindgen_test_layout_rte_thash_tuple() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < rte_thash_tuple > (), 48usize, concat!("Size of: ", - stringify!(rte_thash_tuple)) + ::std::mem::size_of::(), + 48usize, + concat!("Size of: ", stringify!(rte_thash_tuple)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).v4) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_thash_tuple), "::", stringify!(v4)) + unsafe { ::std::ptr::addr_of!((*ptr).v4) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(rte_thash_tuple), "::", stringify!(v4)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).v6) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_thash_tuple), "::", stringify!(v6)) + unsafe { ::std::ptr::addr_of!((*ptr).v6) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(rte_thash_tuple), "::", stringify!(v6)), ); } impl Clone for rte_thash_tuple { diff --git a/bindgen-tests/tests/expectations/tests/accessors.rs b/bindgen-tests/tests/expectations/tests/accessors.rs index f9a3e23aa8..9aa33d65b5 100644 --- a/bindgen-tests/tests/expectations/tests/accessors.rs +++ b/bindgen-tests/tests/expectations/tests/accessors.rs @@ -15,32 +15,56 @@ fn bindgen_test_layout_SomeAccessors() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < SomeAccessors > (), 16usize, concat!("Size of: ", - stringify!(SomeAccessors)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(SomeAccessors)), ); assert_eq!( - ::std::mem::align_of:: < SomeAccessors > (), 4usize, concat!("Alignment of ", - stringify!(SomeAccessors)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(SomeAccessors)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mNoAccessor) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(SomeAccessors), "::", - stringify!(mNoAccessor)) + unsafe { ::std::ptr::addr_of!((*ptr).mNoAccessor) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(SomeAccessors), + "::", + stringify!(mNoAccessor), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mBothAccessors) as usize - ptr as usize }, - 4usize, concat!("Offset of field: ", stringify!(SomeAccessors), "::", - stringify!(mBothAccessors)) + unsafe { ::std::ptr::addr_of!((*ptr).mBothAccessors) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(SomeAccessors), + "::", + stringify!(mBothAccessors), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mUnsafeAccessors) as usize - ptr as usize - }, 8usize, concat!("Offset of field: ", stringify!(SomeAccessors), "::", - stringify!(mUnsafeAccessors)) + unsafe { ::std::ptr::addr_of!((*ptr).mUnsafeAccessors) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(SomeAccessors), + "::", + stringify!(mUnsafeAccessors), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mImmutableAccessor) as usize - ptr as usize - }, 12usize, concat!("Offset of field: ", stringify!(SomeAccessors), "::", - stringify!(mImmutableAccessor)) + unsafe { + ::std::ptr::addr_of!((*ptr).mImmutableAccessor) as usize - ptr as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(SomeAccessors), + "::", + stringify!(mImmutableAccessor), + ), ); } impl SomeAccessors { @@ -77,22 +101,36 @@ fn bindgen_test_layout_AllAccessors() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < AllAccessors > (), 8usize, concat!("Size of: ", - stringify!(AllAccessors)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(AllAccessors)), ); assert_eq!( - ::std::mem::align_of:: < AllAccessors > (), 4usize, concat!("Alignment of ", - stringify!(AllAccessors)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(AllAccessors)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mBothAccessors) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(AllAccessors), "::", - stringify!(mBothAccessors)) + unsafe { ::std::ptr::addr_of!((*ptr).mBothAccessors) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(AllAccessors), + "::", + stringify!(mBothAccessors), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mAlsoBothAccessors) as usize - ptr as usize - }, 4usize, concat!("Offset of field: ", stringify!(AllAccessors), "::", - stringify!(mAlsoBothAccessors)) + unsafe { + ::std::ptr::addr_of!((*ptr).mAlsoBothAccessors) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(AllAccessors), + "::", + stringify!(mAlsoBothAccessors), + ), ); } impl AllAccessors { @@ -125,22 +163,36 @@ fn bindgen_test_layout_AllUnsafeAccessors() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < AllUnsafeAccessors > (), 8usize, concat!("Size of: ", - stringify!(AllUnsafeAccessors)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(AllUnsafeAccessors)), ); assert_eq!( - ::std::mem::align_of:: < AllUnsafeAccessors > (), 4usize, - concat!("Alignment of ", stringify!(AllUnsafeAccessors)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(AllUnsafeAccessors)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mBothAccessors) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(AllUnsafeAccessors), "::", - stringify!(mBothAccessors)) + unsafe { ::std::ptr::addr_of!((*ptr).mBothAccessors) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(AllUnsafeAccessors), + "::", + stringify!(mBothAccessors), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mAlsoBothAccessors) as usize - ptr as usize - }, 4usize, concat!("Offset of field: ", stringify!(AllUnsafeAccessors), "::", - stringify!(mAlsoBothAccessors)) + unsafe { + ::std::ptr::addr_of!((*ptr).mAlsoBothAccessors) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(AllUnsafeAccessors), + "::", + stringify!(mAlsoBothAccessors), + ), ); } impl AllUnsafeAccessors { @@ -178,32 +230,56 @@ fn bindgen_test_layout_ContradictAccessors() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < ContradictAccessors > (), 16usize, concat!("Size of: ", - stringify!(ContradictAccessors)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(ContradictAccessors)), ); assert_eq!( - ::std::mem::align_of:: < ContradictAccessors > (), 4usize, - concat!("Alignment of ", stringify!(ContradictAccessors)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(ContradictAccessors)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mBothAccessors) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(ContradictAccessors), "::", - stringify!(mBothAccessors)) + unsafe { ::std::ptr::addr_of!((*ptr).mBothAccessors) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ContradictAccessors), + "::", + stringify!(mBothAccessors), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mNoAccessors) as usize - ptr as usize }, - 4usize, concat!("Offset of field: ", stringify!(ContradictAccessors), "::", - stringify!(mNoAccessors)) + unsafe { ::std::ptr::addr_of!((*ptr).mNoAccessors) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(ContradictAccessors), + "::", + stringify!(mNoAccessors), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mUnsafeAccessors) as usize - ptr as usize - }, 8usize, concat!("Offset of field: ", stringify!(ContradictAccessors), "::", - stringify!(mUnsafeAccessors)) + unsafe { ::std::ptr::addr_of!((*ptr).mUnsafeAccessors) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(ContradictAccessors), + "::", + stringify!(mUnsafeAccessors), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mImmutableAccessor) as usize - ptr as usize - }, 12usize, concat!("Offset of field: ", stringify!(ContradictAccessors), "::", - stringify!(mImmutableAccessor)) + unsafe { + ::std::ptr::addr_of!((*ptr).mImmutableAccessor) as usize - ptr as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(ContradictAccessors), + "::", + stringify!(mImmutableAccessor), + ), ); } impl ContradictAccessors { @@ -239,17 +315,19 @@ fn bindgen_test_layout_Replaced() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < Replaced > (), 4usize, concat!("Size of: ", - stringify!(Replaced)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Replaced)), ); assert_eq!( - ::std::mem::align_of:: < Replaced > (), 4usize, concat!("Alignment of ", - stringify!(Replaced)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Replaced)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mAccessor) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(Replaced), "::", - stringify!(mAccessor)) + unsafe { ::std::ptr::addr_of!((*ptr).mAccessor) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Replaced), "::", stringify!(mAccessor)), ); } impl Replaced { @@ -273,17 +351,19 @@ fn bindgen_test_layout_Wrapper() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < Wrapper > (), 4usize, concat!("Size of: ", - stringify!(Wrapper)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Wrapper)), ); assert_eq!( - ::std::mem::align_of:: < Wrapper > (), 4usize, concat!("Alignment of ", - stringify!(Wrapper)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Wrapper)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mReplaced) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(Wrapper), "::", - stringify!(mReplaced)) + unsafe { ::std::ptr::addr_of!((*ptr).mReplaced) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Wrapper), "::", stringify!(mReplaced)), ); } impl Wrapper { diff --git a/bindgen-tests/tests/expectations/tests/allowlist-file.rs b/bindgen-tests/tests/expectations/tests/allowlist-file.rs index 1ee7a192ed..ce591f59d3 100644 --- a/bindgen-tests/tests/expectations/tests/allowlist-file.rs +++ b/bindgen-tests/tests/expectations/tests/allowlist-file.rs @@ -15,12 +15,14 @@ pub struct someClass { #[test] fn bindgen_test_layout_someClass() { assert_eq!( - ::std::mem::size_of:: < someClass > (), 1usize, concat!("Size of: ", - stringify!(someClass)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(someClass)), ); assert_eq!( - ::std::mem::align_of:: < someClass > (), 1usize, concat!("Alignment of ", - stringify!(someClass)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(someClass)), ); } extern "C" { @@ -50,17 +52,24 @@ fn bindgen_test_layout_StructWithAllowlistedDefinition() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < StructWithAllowlistedDefinition > (), 8usize, - concat!("Size of: ", stringify!(StructWithAllowlistedDefinition)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(StructWithAllowlistedDefinition)), ); assert_eq!( - ::std::mem::align_of:: < StructWithAllowlistedDefinition > (), 8usize, - concat!("Alignment of ", stringify!(StructWithAllowlistedDefinition)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(StructWithAllowlistedDefinition)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).other) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(StructWithAllowlistedDefinition), "::", - stringify!(other)) + unsafe { ::std::ptr::addr_of!((*ptr).other) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(StructWithAllowlistedDefinition), + "::", + stringify!(other), + ), ); } impl Default for StructWithAllowlistedDefinition { @@ -82,17 +91,24 @@ fn bindgen_test_layout_StructWithAllowlistedFwdDecl() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < StructWithAllowlistedFwdDecl > (), 4usize, - concat!("Size of: ", stringify!(StructWithAllowlistedFwdDecl)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(StructWithAllowlistedFwdDecl)), ); assert_eq!( - ::std::mem::align_of:: < StructWithAllowlistedFwdDecl > (), 4usize, - concat!("Alignment of ", stringify!(StructWithAllowlistedFwdDecl)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(StructWithAllowlistedFwdDecl)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(StructWithAllowlistedFwdDecl), "::", - stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(StructWithAllowlistedFwdDecl), + "::", + stringify!(b), + ), ); } #[repr(C)] @@ -105,15 +121,18 @@ fn bindgen_test_layout_AllowlistMe() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < AllowlistMe > (), 4usize, concat!("Size of: ", - stringify!(AllowlistMe)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(AllowlistMe)), ); assert_eq!( - ::std::mem::align_of:: < AllowlistMe > (), 4usize, concat!("Alignment of ", - stringify!(AllowlistMe)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(AllowlistMe)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).foo) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(AllowlistMe), "::", stringify!(foo)) + unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(AllowlistMe), "::", stringify!(foo)), ); } diff --git a/bindgen-tests/tests/expectations/tests/allowlist-namespaces-basic.rs b/bindgen-tests/tests/expectations/tests/allowlist-namespaces-basic.rs index 38b15d0ef4..726a596953 100644 --- a/bindgen-tests/tests/expectations/tests/allowlist-namespaces-basic.rs +++ b/bindgen-tests/tests/expectations/tests/allowlist-namespaces-basic.rs @@ -17,12 +17,14 @@ pub mod root { #[test] fn bindgen_test_layout_Helper() { assert_eq!( - ::std::mem::size_of:: < Helper > (), 1usize, concat!("Size of: ", - stringify!(Helper)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Helper)), ); assert_eq!( - ::std::mem::align_of:: < Helper > (), 1usize, - concat!("Alignment of ", stringify!(Helper)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Helper)), ); } } diff --git a/bindgen-tests/tests/expectations/tests/allowlist-namespaces.rs b/bindgen-tests/tests/expectations/tests/allowlist-namespaces.rs index 0c760b7d1b..1445bf73a2 100644 --- a/bindgen-tests/tests/expectations/tests/allowlist-namespaces.rs +++ b/bindgen-tests/tests/expectations/tests/allowlist-namespaces.rs @@ -17,12 +17,14 @@ pub mod root { #[test] fn bindgen_test_layout_Helper() { assert_eq!( - ::std::mem::size_of:: < Helper > (), 1usize, concat!("Size of: ", - stringify!(Helper)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Helper)), ); assert_eq!( - ::std::mem::align_of:: < Helper > (), 1usize, - concat!("Alignment of ", stringify!(Helper)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Helper)), ); } } @@ -36,17 +38,19 @@ pub mod root { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < Test > (), 1usize, concat!("Size of: ", - stringify!(Test)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Test)), ); assert_eq!( - ::std::mem::align_of:: < Test > (), 1usize, concat!("Alignment of ", - stringify!(Test)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Test)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).helper) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(Test), "::", - stringify!(helper)) + unsafe { ::std::ptr::addr_of!((*ptr).helper) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(helper)), ); } } diff --git a/bindgen-tests/tests/expectations/tests/allowlisted-item-references-no-hash.rs b/bindgen-tests/tests/expectations/tests/allowlisted-item-references-no-hash.rs index 3c542aaefd..b9a3fb5c16 100644 --- a/bindgen-tests/tests/expectations/tests/allowlisted-item-references-no-hash.rs +++ b/bindgen-tests/tests/expectations/tests/allowlisted-item-references-no-hash.rs @@ -7,12 +7,14 @@ pub struct NoHash { #[test] fn bindgen_test_layout_NoHash() { assert_eq!( - ::std::mem::size_of:: < NoHash > (), 1usize, concat!("Size of: ", - stringify!(NoHash)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(NoHash)), ); assert_eq!( - ::std::mem::align_of:: < NoHash > (), 1usize, concat!("Alignment of ", - stringify!(NoHash)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(NoHash)), ); } #[repr(C)] @@ -25,15 +27,18 @@ fn bindgen_test_layout_AllowlistMe() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < AllowlistMe > (), 1usize, concat!("Size of: ", - stringify!(AllowlistMe)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(AllowlistMe)), ); assert_eq!( - ::std::mem::align_of:: < AllowlistMe > (), 1usize, concat!("Alignment of ", - stringify!(AllowlistMe)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(AllowlistMe)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(AllowlistMe), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(AllowlistMe), "::", stringify!(a)), ); } diff --git a/bindgen-tests/tests/expectations/tests/allowlisted-item-references-no-partialeq.rs b/bindgen-tests/tests/expectations/tests/allowlisted-item-references-no-partialeq.rs index a582414c10..1e763880e1 100644 --- a/bindgen-tests/tests/expectations/tests/allowlisted-item-references-no-partialeq.rs +++ b/bindgen-tests/tests/expectations/tests/allowlisted-item-references-no-partialeq.rs @@ -7,12 +7,14 @@ pub struct NoPartialEq { #[test] fn bindgen_test_layout_NoPartialEq() { assert_eq!( - ::std::mem::size_of:: < NoPartialEq > (), 1usize, concat!("Size of: ", - stringify!(NoPartialEq)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(NoPartialEq)), ); assert_eq!( - ::std::mem::align_of:: < NoPartialEq > (), 1usize, concat!("Alignment of ", - stringify!(NoPartialEq)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(NoPartialEq)), ); } #[repr(C)] @@ -25,15 +27,18 @@ fn bindgen_test_layout_AllowlistMe() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < AllowlistMe > (), 1usize, concat!("Size of: ", - stringify!(AllowlistMe)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(AllowlistMe)), ); assert_eq!( - ::std::mem::align_of:: < AllowlistMe > (), 1usize, concat!("Alignment of ", - stringify!(AllowlistMe)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(AllowlistMe)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(AllowlistMe), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(AllowlistMe), "::", stringify!(a)), ); } diff --git a/bindgen-tests/tests/expectations/tests/allowlisted_item_references_no_copy.rs b/bindgen-tests/tests/expectations/tests/allowlisted_item_references_no_copy.rs index e2b8ac9343..0058371966 100644 --- a/bindgen-tests/tests/expectations/tests/allowlisted_item_references_no_copy.rs +++ b/bindgen-tests/tests/expectations/tests/allowlisted_item_references_no_copy.rs @@ -7,12 +7,14 @@ pub struct NoCopy { #[test] fn bindgen_test_layout_NoCopy() { assert_eq!( - ::std::mem::size_of:: < NoCopy > (), 1usize, concat!("Size of: ", - stringify!(NoCopy)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(NoCopy)), ); assert_eq!( - ::std::mem::align_of:: < NoCopy > (), 1usize, concat!("Alignment of ", - stringify!(NoCopy)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(NoCopy)), ); } #[repr(C)] @@ -25,15 +27,18 @@ fn bindgen_test_layout_AllowlistMe() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < AllowlistMe > (), 1usize, concat!("Size of: ", - stringify!(AllowlistMe)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(AllowlistMe)), ); assert_eq!( - ::std::mem::align_of:: < AllowlistMe > (), 1usize, concat!("Alignment of ", - stringify!(AllowlistMe)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(AllowlistMe)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(AllowlistMe), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(AllowlistMe), "::", stringify!(a)), ); } diff --git a/bindgen-tests/tests/expectations/tests/annotation_hide.rs b/bindgen-tests/tests/expectations/tests/annotation_hide.rs index ce74ca123c..1ec81ba6e2 100644 --- a/bindgen-tests/tests/expectations/tests/annotation_hide.rs +++ b/bindgen-tests/tests/expectations/tests/annotation_hide.rs @@ -8,11 +8,11 @@ pub struct D { } #[test] fn bindgen_test_layout_D() { + assert_eq!(::std::mem::size_of::(), 4usize, concat!("Size of: ", stringify!(D))); assert_eq!( - ::std::mem::size_of:: < D > (), 4usize, concat!("Size of: ", stringify!(D)) - ); - assert_eq!( - ::std::mem::align_of:: < D > (), 4usize, concat!("Alignment of ", stringify!(D)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(D)), ); } #[repr(C)] @@ -25,15 +25,18 @@ fn bindgen_test_layout_NotAnnotated() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < NotAnnotated > (), 4usize, concat!("Size of: ", - stringify!(NotAnnotated)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(NotAnnotated)), ); assert_eq!( - ::std::mem::align_of:: < NotAnnotated > (), 4usize, concat!("Alignment of ", - stringify!(NotAnnotated)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(NotAnnotated)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).f) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(NotAnnotated), "::", stringify!(f)) + unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(NotAnnotated), "::", stringify!(f)), ); } diff --git a/bindgen-tests/tests/expectations/tests/anon-fields-prefix.rs b/bindgen-tests/tests/expectations/tests/anon-fields-prefix.rs index 4cd2724dcf..813bde9e55 100644 --- a/bindgen-tests/tests/expectations/tests/anon-fields-prefix.rs +++ b/bindgen-tests/tests/expectations/tests/anon-fields-prefix.rs @@ -18,27 +18,44 @@ fn bindgen_test_layout_color__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < color__bindgen_ty_1 > (), 3usize, concat!("Size of: ", - stringify!(color__bindgen_ty_1)) + ::std::mem::size_of::(), + 3usize, + concat!("Size of: ", stringify!(color__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < color__bindgen_ty_1 > (), 1usize, - concat!("Alignment of ", stringify!(color__bindgen_ty_1)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(color__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).r) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(color__bindgen_ty_1), "::", - stringify!(r)) + unsafe { ::std::ptr::addr_of!((*ptr).r) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(color__bindgen_ty_1), + "::", + stringify!(r), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).g) as usize - ptr as usize }, 1usize, - concat!("Offset of field: ", stringify!(color__bindgen_ty_1), "::", - stringify!(g)) + unsafe { ::std::ptr::addr_of!((*ptr).g) as usize - ptr as usize }, + 1usize, + concat!( + "Offset of field: ", + stringify!(color__bindgen_ty_1), + "::", + stringify!(g), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 2usize, - concat!("Offset of field: ", stringify!(color__bindgen_ty_1), "::", - stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 2usize, + concat!( + "Offset of field: ", + stringify!(color__bindgen_ty_1), + "::", + stringify!(b), + ), ); } #[repr(C)] @@ -53,27 +70,44 @@ fn bindgen_test_layout_color__bindgen_ty_2() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < color__bindgen_ty_2 > (), 3usize, concat!("Size of: ", - stringify!(color__bindgen_ty_2)) + ::std::mem::size_of::(), + 3usize, + concat!("Size of: ", stringify!(color__bindgen_ty_2)), ); assert_eq!( - ::std::mem::align_of:: < color__bindgen_ty_2 > (), 1usize, - concat!("Alignment of ", stringify!(color__bindgen_ty_2)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(color__bindgen_ty_2)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).y) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(color__bindgen_ty_2), "::", - stringify!(y)) + unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(color__bindgen_ty_2), + "::", + stringify!(y), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).u) as usize - ptr as usize }, 1usize, - concat!("Offset of field: ", stringify!(color__bindgen_ty_2), "::", - stringify!(u)) + unsafe { ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize }, + 1usize, + concat!( + "Offset of field: ", + stringify!(color__bindgen_ty_2), + "::", + stringify!(u), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).v) as usize - ptr as usize }, 2usize, - concat!("Offset of field: ", stringify!(color__bindgen_ty_2), "::", - stringify!(v)) + unsafe { ::std::ptr::addr_of!((*ptr).v) as usize - ptr as usize }, + 2usize, + concat!( + "Offset of field: ", + stringify!(color__bindgen_ty_2), + "::", + stringify!(v), + ), ); } #[test] @@ -81,16 +115,19 @@ fn bindgen_test_layout_color() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < color > (), 3usize, concat!("Size of: ", - stringify!(color)) + ::std::mem::size_of::(), + 3usize, + concat!("Size of: ", stringify!(color)), ); assert_eq!( - ::std::mem::align_of:: < color > (), 1usize, concat!("Alignment of ", - stringify!(color)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(color)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).v3) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(color), "::", stringify!(v3)) + unsafe { ::std::ptr::addr_of!((*ptr).v3) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(color), "::", stringify!(v3)), ); } impl Default for color { diff --git a/bindgen-tests/tests/expectations/tests/anon_enum.rs b/bindgen-tests/tests/expectations/tests/anon_enum.rs index b8a18dd63e..a3ad1db9f0 100644 --- a/bindgen-tests/tests/expectations/tests/anon_enum.rs +++ b/bindgen-tests/tests/expectations/tests/anon_enum.rs @@ -16,19 +16,24 @@ fn bindgen_test_layout_Test() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < Test > (), 8usize, concat!("Size of: ", stringify!(Test)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Test)), ); assert_eq!( - ::std::mem::align_of:: < Test > (), 4usize, concat!("Alignment of ", - stringify!(Test)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Test)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).foo) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(foo)) + unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(bar)) + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(bar)), ); } #[repr(u32)] diff --git a/bindgen-tests/tests/expectations/tests/anon_enum_trait.rs b/bindgen-tests/tests/expectations/tests/anon_enum_trait.rs index 06fc3faba9..37fe6d810c 100644 --- a/bindgen-tests/tests/expectations/tests/anon_enum_trait.rs +++ b/bindgen-tests/tests/expectations/tests/anon_enum_trait.rs @@ -33,10 +33,13 @@ pub enum Foo__bindgen_ty_1 { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo)), ); assert_eq!( - ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", - stringify!(Foo)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)), ); } diff --git a/bindgen-tests/tests/expectations/tests/anon_struct_in_union.rs b/bindgen-tests/tests/expectations/tests/anon_struct_in_union.rs index b4e30c1a86..a012f1692e 100644 --- a/bindgen-tests/tests/expectations/tests/anon_struct_in_union.rs +++ b/bindgen-tests/tests/expectations/tests/anon_struct_in_union.rs @@ -19,17 +19,24 @@ fn bindgen_test_layout_s__bindgen_ty_1_inner() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < s__bindgen_ty_1_inner > (), 4usize, concat!("Size of: ", - stringify!(s__bindgen_ty_1_inner)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(s__bindgen_ty_1_inner)), ); assert_eq!( - ::std::mem::align_of:: < s__bindgen_ty_1_inner > (), 4usize, - concat!("Alignment of ", stringify!(s__bindgen_ty_1_inner)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(s__bindgen_ty_1_inner)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(s__bindgen_ty_1_inner), "::", - stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(s__bindgen_ty_1_inner), + "::", + stringify!(b), + ), ); } #[test] @@ -37,17 +44,24 @@ fn bindgen_test_layout_s__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < s__bindgen_ty_1 > (), 4usize, concat!("Size of: ", - stringify!(s__bindgen_ty_1)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(s__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < s__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", - stringify!(s__bindgen_ty_1)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(s__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).field) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(s__bindgen_ty_1), "::", - stringify!(field)) + unsafe { ::std::ptr::addr_of!((*ptr).field) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(s__bindgen_ty_1), + "::", + stringify!(field), + ), ); } impl Default for s__bindgen_ty_1 { @@ -63,15 +77,16 @@ impl Default for s__bindgen_ty_1 { 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::(), 4usize, concat!("Size of: ", stringify!(s))); assert_eq!( - ::std::mem::size_of:: < s > (), 4usize, concat!("Size of: ", stringify!(s)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(s)), ); assert_eq!( - ::std::mem::align_of:: < s > (), 4usize, concat!("Alignment of ", stringify!(s)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).u) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(s), "::", stringify!(u)) + unsafe { ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(s), "::", stringify!(u)), ); } impl Default for s { diff --git a/bindgen-tests/tests/expectations/tests/anon_struct_in_union_1_0.rs b/bindgen-tests/tests/expectations/tests/anon_struct_in_union_1_0.rs index 43d495eb0c..5de1669a21 100644 --- a/bindgen-tests/tests/expectations/tests/anon_struct_in_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/anon_struct_in_union_1_0.rs @@ -63,17 +63,24 @@ fn bindgen_test_layout_s__bindgen_ty_1_inner() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < s__bindgen_ty_1_inner > (), 4usize, concat!("Size of: ", - stringify!(s__bindgen_ty_1_inner)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(s__bindgen_ty_1_inner)), ); assert_eq!( - ::std::mem::align_of:: < s__bindgen_ty_1_inner > (), 4usize, - concat!("Alignment of ", stringify!(s__bindgen_ty_1_inner)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(s__bindgen_ty_1_inner)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(s__bindgen_ty_1_inner), "::", - stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(s__bindgen_ty_1_inner), + "::", + stringify!(b), + ), ); } impl Clone for s__bindgen_ty_1_inner { @@ -86,17 +93,24 @@ fn bindgen_test_layout_s__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < s__bindgen_ty_1 > (), 4usize, concat!("Size of: ", - stringify!(s__bindgen_ty_1)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(s__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < s__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", - stringify!(s__bindgen_ty_1)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(s__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).field) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(s__bindgen_ty_1), "::", - stringify!(field)) + unsafe { ::std::ptr::addr_of!((*ptr).field) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(s__bindgen_ty_1), + "::", + stringify!(field), + ), ); } impl Clone for s__bindgen_ty_1 { @@ -108,15 +122,16 @@ impl Clone for s__bindgen_ty_1 { 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::(), 4usize, concat!("Size of: ", stringify!(s))); assert_eq!( - ::std::mem::size_of:: < s > (), 4usize, concat!("Size of: ", stringify!(s)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(s)), ); assert_eq!( - ::std::mem::align_of:: < s > (), 4usize, concat!("Alignment of ", stringify!(s)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).u) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(s), "::", stringify!(u)) + unsafe { ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(s), "::", stringify!(u)), ); } impl Clone for s { diff --git a/bindgen-tests/tests/expectations/tests/anon_union.rs b/bindgen-tests/tests/expectations/tests/anon_union.rs index b8e43f3df5..d77658df83 100644 --- a/bindgen-tests/tests/expectations/tests/anon_union.rs +++ b/bindgen-tests/tests/expectations/tests/anon_union.rs @@ -54,12 +54,14 @@ pub struct ErrorResult { #[test] fn bindgen_test_layout_ErrorResult() { assert_eq!( - ::std::mem::size_of:: < ErrorResult > (), 24usize, concat!("Size of: ", - stringify!(ErrorResult)) + ::std::mem::size_of::(), + 24usize, + concat!("Size of: ", stringify!(ErrorResult)), ); assert_eq!( - ::std::mem::align_of:: < ErrorResult > (), 8usize, concat!("Alignment of ", - stringify!(ErrorResult)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(ErrorResult)), ); } impl Default for ErrorResult { @@ -74,11 +76,13 @@ impl Default for ErrorResult { #[test] fn __bindgen_test_layout_TErrorResult_open0_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < TErrorResult > (), 24usize, - concat!("Size of template specialization: ", stringify!(TErrorResult)) + ::std::mem::size_of::(), + 24usize, + concat!("Size of template specialization: ", stringify!(TErrorResult)), ); assert_eq!( - ::std::mem::align_of:: < TErrorResult > (), 8usize, - concat!("Alignment of template specialization: ", stringify!(TErrorResult)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of template specialization: ", stringify!(TErrorResult)), ); } diff --git a/bindgen-tests/tests/expectations/tests/anon_union_1_0.rs b/bindgen-tests/tests/expectations/tests/anon_union_1_0.rs index 90094777ed..90a2e00d0b 100644 --- a/bindgen-tests/tests/expectations/tests/anon_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/anon_union_1_0.rs @@ -90,12 +90,14 @@ pub struct ErrorResult { #[test] fn bindgen_test_layout_ErrorResult() { assert_eq!( - ::std::mem::size_of:: < ErrorResult > (), 24usize, concat!("Size of: ", - stringify!(ErrorResult)) + ::std::mem::size_of::(), + 24usize, + concat!("Size of: ", stringify!(ErrorResult)), ); assert_eq!( - ::std::mem::align_of:: < ErrorResult > (), 8usize, concat!("Alignment of ", - stringify!(ErrorResult)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(ErrorResult)), ); } impl Clone for ErrorResult { @@ -115,11 +117,13 @@ impl Default for ErrorResult { #[test] fn __bindgen_test_layout_TErrorResult_open0_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < TErrorResult > (), 24usize, - concat!("Size of template specialization: ", stringify!(TErrorResult)) + ::std::mem::size_of::(), + 24usize, + concat!("Size of template specialization: ", stringify!(TErrorResult)), ); assert_eq!( - ::std::mem::align_of:: < TErrorResult > (), 8usize, - concat!("Alignment of template specialization: ", stringify!(TErrorResult)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of template specialization: ", stringify!(TErrorResult)), ); } diff --git a/bindgen-tests/tests/expectations/tests/array-of-zero-sized-types.rs b/bindgen-tests/tests/expectations/tests/array-of-zero-sized-types.rs index fd6b658ccd..9eb483cc6a 100644 --- a/bindgen-tests/tests/expectations/tests/array-of-zero-sized-types.rs +++ b/bindgen-tests/tests/expectations/tests/array-of-zero-sized-types.rs @@ -8,12 +8,14 @@ pub struct Empty { #[test] fn bindgen_test_layout_Empty() { assert_eq!( - ::std::mem::size_of:: < Empty > (), 1usize, concat!("Size of: ", - stringify!(Empty)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Empty)), ); assert_eq!( - ::std::mem::align_of:: < Empty > (), 1usize, concat!("Alignment of ", - stringify!(Empty)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Empty)), ); } /** This should not get an `_address` byte, since each `Empty` gets one, meaning @@ -28,16 +30,23 @@ fn bindgen_test_layout_HasArrayOfEmpty() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < HasArrayOfEmpty > (), 10usize, concat!("Size of: ", - stringify!(HasArrayOfEmpty)) + ::std::mem::size_of::(), + 10usize, + concat!("Size of: ", stringify!(HasArrayOfEmpty)), ); assert_eq!( - ::std::mem::align_of:: < HasArrayOfEmpty > (), 1usize, concat!("Alignment of ", - stringify!(HasArrayOfEmpty)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(HasArrayOfEmpty)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).empties) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(HasArrayOfEmpty), "::", - stringify!(empties)) + unsafe { ::std::ptr::addr_of!((*ptr).empties) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(HasArrayOfEmpty), + "::", + stringify!(empties), + ), ); } 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 b6c5c3cb2b..b3ded6636e 100644 --- a/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result.rs +++ b/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result.rs @@ -7,11 +7,14 @@ pub struct Foo { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo)), ); assert_eq!( - ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", - stringify!(Foo)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)), ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_no_attribute_detection.rs b/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_no_attribute_detection.rs index 9d13c2b6e6..15cfef051f 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 @@ -7,11 +7,14 @@ pub struct Foo { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo)), ); assert_eq!( - ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", - stringify!(Foo)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)), ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_pre_1_27.rs b/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_pre_1_27.rs index 9d13c2b6e6..15cfef051f 100644 --- a/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_pre_1_27.rs +++ b/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_pre_1_27.rs @@ -7,11 +7,14 @@ pub struct Foo { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo)), ); assert_eq!( - ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", - stringify!(Foo)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)), ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/base-to-derived.rs b/bindgen-tests/tests/expectations/tests/base-to-derived.rs index ebe7ffe6f1..1d6643219c 100644 --- a/bindgen-tests/tests/expectations/tests/base-to-derived.rs +++ b/bindgen-tests/tests/expectations/tests/base-to-derived.rs @@ -7,11 +7,13 @@ pub struct false_type { #[test] fn bindgen_test_layout_false_type() { assert_eq!( - ::std::mem::size_of:: < false_type > (), 1usize, concat!("Size of: ", - stringify!(false_type)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(false_type)), ); assert_eq!( - ::std::mem::align_of:: < false_type > (), 1usize, concat!("Alignment of ", - stringify!(false_type)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(false_type)), ); } 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 5bb19af498..93e2b8e750 100644 --- a/bindgen-tests/tests/expectations/tests/bindgen-union-inside-namespace.rs +++ b/bindgen-tests/tests/expectations/tests/bindgen-union-inside-namespace.rs @@ -61,22 +61,24 @@ pub mod root { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < Bar > (), 4usize, concat!("Size of: ", - stringify!(Bar)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Bar)), ); assert_eq!( - ::std::mem::align_of:: < Bar > (), 4usize, concat!("Alignment of ", - stringify!(Bar)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Bar)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).foo) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(Bar), "::", - stringify!(foo)) + unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(Bar), "::", - stringify!(bar)) + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(bar)), ); } impl Clone for Bar { diff --git a/bindgen-tests/tests/expectations/tests/bitfield-32bit-overflow.rs b/bindgen-tests/tests/expectations/tests/bitfield-32bit-overflow.rs index 64d5456a6c..cf04543654 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-32bit-overflow.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-32bit-overflow.rs @@ -49,7 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -69,7 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -92,12 +92,14 @@ pub struct MuchBitfield { #[test] fn bindgen_test_layout_MuchBitfield() { assert_eq!( - ::std::mem::size_of:: < MuchBitfield > (), 5usize, concat!("Size of: ", - stringify!(MuchBitfield)) + ::std::mem::size_of::(), + 5usize, + concat!("Size of: ", stringify!(MuchBitfield)), ); assert_eq!( - ::std::mem::align_of:: < MuchBitfield > (), 1usize, concat!("Alignment of ", - stringify!(MuchBitfield)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(MuchBitfield)), ); } impl MuchBitfield { diff --git a/bindgen-tests/tests/expectations/tests/bitfield-enum-basic.rs b/bindgen-tests/tests/expectations/tests/bitfield-enum-basic.rs index 6a07c8be69..ab6a923201 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-enum-basic.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-enum-basic.rs @@ -151,11 +151,13 @@ pub struct Dummy__bindgen_ty_1(pub ::std::os::raw::c_uint); #[test] fn bindgen_test_layout_Dummy() { assert_eq!( - ::std::mem::size_of:: < Dummy > (), 1usize, concat!("Size of: ", - stringify!(Dummy)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Dummy)), ); assert_eq!( - ::std::mem::align_of:: < Dummy > (), 1usize, concat!("Alignment of ", - stringify!(Dummy)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Dummy)), ); } diff --git a/bindgen-tests/tests/expectations/tests/bitfield-large.rs b/bindgen-tests/tests/expectations/tests/bitfield-large.rs index d7d37c12fc..f5b337cf45 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-large.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-large.rs @@ -49,7 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -69,7 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -93,12 +93,14 @@ pub struct HasBigBitfield { #[test] fn bindgen_test_layout_HasBigBitfield() { assert_eq!( - ::std::mem::size_of:: < HasBigBitfield > (), 16usize, concat!("Size of: ", - stringify!(HasBigBitfield)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(HasBigBitfield)), ); assert_eq!( - ::std::mem::align_of:: < HasBigBitfield > (), 16usize, concat!("Alignment of ", - stringify!(HasBigBitfield)) + ::std::mem::align_of::(), + 16usize, + concat!("Alignment of ", stringify!(HasBigBitfield)), ); } impl HasBigBitfield { @@ -138,12 +140,14 @@ pub struct HasTwoBigBitfields { #[test] fn bindgen_test_layout_HasTwoBigBitfields() { assert_eq!( - ::std::mem::size_of:: < HasTwoBigBitfields > (), 16usize, concat!("Size of: ", - stringify!(HasTwoBigBitfields)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(HasTwoBigBitfields)), ); assert_eq!( - ::std::mem::align_of:: < HasTwoBigBitfields > (), 16usize, - concat!("Alignment of ", stringify!(HasTwoBigBitfields)) + ::std::mem::align_of::(), + 16usize, + concat!("Alignment of ", stringify!(HasTwoBigBitfields)), ); } impl HasTwoBigBitfields { diff --git a/bindgen-tests/tests/expectations/tests/bitfield-linux-32.rs b/bindgen-tests/tests/expectations/tests/bitfield-linux-32.rs index e76aab6df7..4500be292f 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-linux-32.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-linux-32.rs @@ -49,7 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -69,7 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -95,16 +95,19 @@ fn bindgen_test_layout_Test() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < Test > (), 16usize, concat!("Size of: ", - stringify!(Test)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(Test)), ); assert_eq!( - ::std::mem::align_of:: < Test > (), 4usize, concat!("Alignment of ", - stringify!(Test)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Test)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).foo) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(foo)) + unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(foo)), ); } impl Test { diff --git a/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs b/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs index 48bcf0583d..8cd1997a93 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs @@ -49,7 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -69,7 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -92,11 +92,14 @@ pub struct Foo { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo)), ); assert_eq!( - ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", - stringify!(Foo)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)), ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/bitfield_align.rs b/bindgen-tests/tests/expectations/tests/bitfield_align.rs index 5c54d92623..559038ed3e 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_align.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_align.rs @@ -49,7 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -69,7 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -96,19 +96,21 @@ pub struct A { 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::(), 4usize, concat!("Size of: ", stringify!(A))); assert_eq!( - ::std::mem::size_of:: < A > (), 4usize, concat!("Size of: ", stringify!(A)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(A)), ); assert_eq!( - ::std::mem::align_of:: < A > (), 4usize, concat!("Alignment of ", stringify!(A)) + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(A), "::", stringify!(x)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).x) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(x)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).y) as usize - ptr as usize }, 3usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(y)) + unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, + 3usize, + concat!("Offset of field: ", stringify!(A), "::", stringify!(y)), ); } impl A { @@ -338,11 +340,11 @@ pub struct B { } #[test] fn bindgen_test_layout_B() { + assert_eq!(::std::mem::size_of::(), 4usize, concat!("Size of: ", stringify!(B))); assert_eq!( - ::std::mem::size_of:: < B > (), 4usize, concat!("Size of: ", stringify!(B)) - ); - assert_eq!( - ::std::mem::align_of:: < B > (), 4usize, concat!("Alignment of ", stringify!(B)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(B)), ); } impl B { @@ -407,19 +409,21 @@ pub struct C { 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::(), 8usize, concat!("Size of: ", stringify!(C))); assert_eq!( - ::std::mem::size_of:: < C > (), 8usize, concat!("Size of: ", stringify!(C)) - ); - assert_eq!( - ::std::mem::align_of:: < C > (), 4usize, concat!("Alignment of ", stringify!(C)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(C)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).x) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(x)) + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(x)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).baz) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(baz)) + unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(baz)), ); } impl C { @@ -483,12 +487,14 @@ pub struct Date1 { #[test] fn bindgen_test_layout_Date1() { assert_eq!( - ::std::mem::size_of:: < Date1 > (), 4usize, concat!("Size of: ", - stringify!(Date1)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Date1)), ); assert_eq!( - ::std::mem::align_of:: < Date1 > (), 2usize, concat!("Alignment of ", - stringify!(Date1)) + ::std::mem::align_of::(), + 2usize, + concat!("Alignment of ", stringify!(Date1)), ); } impl Date1 { @@ -593,12 +599,14 @@ pub struct Date2 { #[test] fn bindgen_test_layout_Date2() { assert_eq!( - ::std::mem::size_of:: < Date2 > (), 4usize, concat!("Size of: ", - stringify!(Date2)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Date2)), ); assert_eq!( - ::std::mem::align_of:: < Date2 > (), 2usize, concat!("Alignment of ", - stringify!(Date2)) + ::std::mem::align_of::(), + 2usize, + concat!("Alignment of ", stringify!(Date2)), ); } impl Date2 { @@ -727,16 +735,19 @@ fn bindgen_test_layout_Date3() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < Date3 > (), 4usize, concat!("Size of: ", - stringify!(Date3)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Date3)), ); assert_eq!( - ::std::mem::align_of:: < Date3 > (), 2usize, concat!("Alignment of ", - stringify!(Date3)) + ::std::mem::align_of::(), + 2usize, + concat!("Alignment of ", stringify!(Date3)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).byte) as usize - ptr as usize }, 3usize, - concat!("Offset of field: ", stringify!(Date3), "::", stringify!(byte)) + unsafe { ::std::ptr::addr_of!((*ptr).byte) as usize - ptr as usize }, + 3usize, + concat!("Offset of field: ", stringify!(Date3), "::", stringify!(byte)), ); } impl Date3 { diff --git a/bindgen-tests/tests/expectations/tests/bitfield_align_2.rs b/bindgen-tests/tests/expectations/tests/bitfield_align_2.rs index e50930d5af..dc49137e9b 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_align_2.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_align_2.rs @@ -50,7 +50,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -70,7 +70,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -102,12 +102,14 @@ pub struct TaggedPtr { #[test] fn bindgen_test_layout_TaggedPtr() { assert_eq!( - ::std::mem::size_of:: < TaggedPtr > (), 8usize, concat!("Size of: ", - stringify!(TaggedPtr)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(TaggedPtr)), ); assert_eq!( - ::std::mem::align_of:: < TaggedPtr > (), 8usize, concat!("Alignment of ", - stringify!(TaggedPtr)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(TaggedPtr)), ); } impl Default for TaggedPtr { diff --git a/bindgen-tests/tests/expectations/tests/bitfield_large_overflow.rs b/bindgen-tests/tests/expectations/tests/bitfield_large_overflow.rs index 725edd2b6a..54f09f6229 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_large_overflow.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_large_overflow.rs @@ -8,12 +8,14 @@ pub struct _bindgen_ty_1 { #[test] fn bindgen_test_layout__bindgen_ty_1() { assert_eq!( - ::std::mem::size_of:: < _bindgen_ty_1 > (), 80usize, concat!("Size of: ", - stringify!(_bindgen_ty_1)) + ::std::mem::size_of::<_bindgen_ty_1>(), + 80usize, + concat!("Size of: ", stringify!(_bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < _bindgen_ty_1 > (), 8usize, concat!("Alignment of ", - stringify!(_bindgen_ty_1)) + ::std::mem::align_of::<_bindgen_ty_1>(), + 8usize, + concat!("Alignment of ", stringify!(_bindgen_ty_1)), ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/bitfield_method_mangling.rs b/bindgen-tests/tests/expectations/tests/bitfield_method_mangling.rs index 9938ca15d2..ea1502eb61 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_method_mangling.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_method_mangling.rs @@ -49,7 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -69,7 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -93,12 +93,14 @@ pub struct mach_msg_type_descriptor_t { #[test] fn bindgen_test_layout_mach_msg_type_descriptor_t() { assert_eq!( - ::std::mem::size_of:: < mach_msg_type_descriptor_t > (), 4usize, - concat!("Size of: ", stringify!(mach_msg_type_descriptor_t)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(mach_msg_type_descriptor_t)), ); assert_eq!( - ::std::mem::align_of:: < mach_msg_type_descriptor_t > (), 4usize, - concat!("Alignment of ", stringify!(mach_msg_type_descriptor_t)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(mach_msg_type_descriptor_t)), ); } impl mach_msg_type_descriptor_t { diff --git a/bindgen-tests/tests/expectations/tests/bitfield_pragma_packed.rs b/bindgen-tests/tests/expectations/tests/bitfield_pragma_packed.rs index 44bf30e71a..c37b42f2fd 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_pragma_packed.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_pragma_packed.rs @@ -49,7 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -69,7 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -92,12 +92,14 @@ pub struct Struct { #[test] fn bindgen_test_layout_Struct() { assert_eq!( - ::std::mem::size_of:: < Struct > (), 4usize, concat!("Size of: ", - stringify!(Struct)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Struct)), ); assert_eq!( - ::std::mem::align_of:: < Struct > (), 1usize, concat!("Alignment of ", - stringify!(Struct)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Struct)), ); } impl Struct { diff --git a/bindgen-tests/tests/expectations/tests/blocklist-and-impl-debug.rs b/bindgen-tests/tests/expectations/tests/blocklist-and-impl-debug.rs index a0bccaff0c..c09ff915b7 100644 --- a/bindgen-tests/tests/expectations/tests/blocklist-and-impl-debug.rs +++ b/bindgen-tests/tests/expectations/tests/blocklist-and-impl-debug.rs @@ -10,17 +10,24 @@ fn bindgen_test_layout_ShouldManuallyImplDebug() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < ShouldManuallyImplDebug > (), 1usize, - concat!("Size of: ", stringify!(ShouldManuallyImplDebug)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(ShouldManuallyImplDebug)), ); assert_eq!( - ::std::mem::align_of:: < ShouldManuallyImplDebug > (), 1usize, - concat!("Alignment of ", stringify!(ShouldManuallyImplDebug)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(ShouldManuallyImplDebug)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(ShouldManuallyImplDebug), "::", - stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ShouldManuallyImplDebug), + "::", + stringify!(a), + ), ); } impl Default for ShouldManuallyImplDebug { diff --git a/bindgen-tests/tests/expectations/tests/blocklist-file.rs b/bindgen-tests/tests/expectations/tests/blocklist-file.rs index de8deabade..99f81f9e50 100644 --- a/bindgen-tests/tests/expectations/tests/blocklist-file.rs +++ b/bindgen-tests/tests/expectations/tests/blocklist-file.rs @@ -11,24 +11,29 @@ fn bindgen_test_layout_SizedIntegers() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < SizedIntegers > (), 8usize, concat!("Size of: ", - stringify!(SizedIntegers)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(SizedIntegers)), ); assert_eq!( - ::std::mem::align_of:: < SizedIntegers > (), 4usize, concat!("Alignment of ", - stringify!(SizedIntegers)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(SizedIntegers)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).x) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(SizedIntegers), "::", stringify!(x)) + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(SizedIntegers), "::", stringify!(x)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).y) as usize - ptr as usize }, 2usize, - concat!("Offset of field: ", stringify!(SizedIntegers), "::", stringify!(y)) + unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, + 2usize, + concat!("Offset of field: ", stringify!(SizedIntegers), "::", stringify!(y)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).z) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(SizedIntegers), "::", stringify!(z)) + unsafe { ::std::ptr::addr_of!((*ptr).z) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(SizedIntegers), "::", stringify!(z)), ); } #[repr(C)] @@ -41,16 +46,23 @@ fn bindgen_test_layout_StructWithBlocklistedFwdDecl() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < StructWithBlocklistedFwdDecl > (), 1usize, - concat!("Size of: ", stringify!(StructWithBlocklistedFwdDecl)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(StructWithBlocklistedFwdDecl)), ); assert_eq!( - ::std::mem::align_of:: < StructWithBlocklistedFwdDecl > (), 1usize, - concat!("Alignment of ", stringify!(StructWithBlocklistedFwdDecl)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(StructWithBlocklistedFwdDecl)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(StructWithBlocklistedFwdDecl), "::", - stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(StructWithBlocklistedFwdDecl), + "::", + stringify!(b), + ), ); } diff --git a/bindgen-tests/tests/expectations/tests/blocklist-function.rs b/bindgen-tests/tests/expectations/tests/blocklist-function.rs index 002752bc6f..531ba2e6d8 100644 --- a/bindgen-tests/tests/expectations/tests/blocklist-function.rs +++ b/bindgen-tests/tests/expectations/tests/blocklist-function.rs @@ -23,11 +23,14 @@ pub mod root { #[test] fn bindgen_test_layout_C() { assert_eq!( - ::std::mem::size_of:: < C > (), 1usize, concat!("Size of: ", stringify!(C)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(C)), ); assert_eq!( - ::std::mem::align_of:: < C > (), 1usize, concat!("Alignment of ", - stringify!(C)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(C)), ); } } diff --git a/bindgen-tests/tests/expectations/tests/blocklist-methods.rs b/bindgen-tests/tests/expectations/tests/blocklist-methods.rs index dee53c0b81..583beabeed 100644 --- a/bindgen-tests/tests/expectations/tests/blocklist-methods.rs +++ b/bindgen-tests/tests/expectations/tests/blocklist-methods.rs @@ -7,11 +7,14 @@ pub struct Foo { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo)), ); assert_eq!( - ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", - stringify!(Foo)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)), ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/blocks-signature.rs b/bindgen-tests/tests/expectations/tests/blocks-signature.rs index 6a5b873b94..3f4fa289b0 100644 --- a/bindgen-tests/tests/expectations/tests/blocks-signature.rs +++ b/bindgen-tests/tests/expectations/tests/blocks-signature.rs @@ -33,22 +33,34 @@ fn bindgen_test_layout_contains_block_pointers() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < contains_block_pointers > (), 16usize, - concat!("Size of: ", stringify!(contains_block_pointers)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(contains_block_pointers)), ); assert_eq!( - ::std::mem::align_of:: < contains_block_pointers > (), 8usize, - concat!("Alignment of ", stringify!(contains_block_pointers)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(contains_block_pointers)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).val) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(contains_block_pointers), "::", - stringify!(val)) + unsafe { ::std::ptr::addr_of!((*ptr).val) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(contains_block_pointers), + "::", + stringify!(val), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).ptr_val) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(contains_block_pointers), "::", - stringify!(ptr_val)) + unsafe { ::std::ptr::addr_of!((*ptr).ptr_val) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(contains_block_pointers), + "::", + stringify!(ptr_val), + ), ); } impl Default for contains_block_pointers { diff --git a/bindgen-tests/tests/expectations/tests/blocks.rs b/bindgen-tests/tests/expectations/tests/blocks.rs index 9bbfdaaddd..0d43e65fc4 100644 --- a/bindgen-tests/tests/expectations/tests/blocks.rs +++ b/bindgen-tests/tests/expectations/tests/blocks.rs @@ -32,22 +32,34 @@ fn bindgen_test_layout_contains_block_pointers() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < contains_block_pointers > (), 16usize, - concat!("Size of: ", stringify!(contains_block_pointers)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(contains_block_pointers)), ); assert_eq!( - ::std::mem::align_of:: < contains_block_pointers > (), 8usize, - concat!("Alignment of ", stringify!(contains_block_pointers)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(contains_block_pointers)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).val) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(contains_block_pointers), "::", - stringify!(val)) + unsafe { ::std::ptr::addr_of!((*ptr).val) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(contains_block_pointers), + "::", + stringify!(val), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).ptr_val) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(contains_block_pointers), "::", - stringify!(ptr_val)) + unsafe { ::std::ptr::addr_of!((*ptr).ptr_val) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(contains_block_pointers), + "::", + stringify!(ptr_val), + ), ); } impl Default for contains_block_pointers { diff --git a/bindgen-tests/tests/expectations/tests/bug-1529681.rs b/bindgen-tests/tests/expectations/tests/bug-1529681.rs index b4d84ea4f1..50d48d438c 100644 --- a/bindgen-tests/tests/expectations/tests/bug-1529681.rs +++ b/bindgen-tests/tests/expectations/tests/bug-1529681.rs @@ -7,11 +7,13 @@ pub struct BrowsingContext { #[test] fn bindgen_test_layout_BrowsingContext() { assert_eq!( - ::std::mem::size_of:: < BrowsingContext > (), 1usize, concat!("Size of: ", - stringify!(BrowsingContext)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(BrowsingContext)), ); assert_eq!( - ::std::mem::align_of:: < BrowsingContext > (), 1usize, concat!("Alignment of ", - stringify!(BrowsingContext)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(BrowsingContext)), ); } diff --git a/bindgen-tests/tests/expectations/tests/c-empty-layout.rs b/bindgen-tests/tests/expectations/tests/c-empty-layout.rs index 72ccd3f405..7d59cadcca 100644 --- a/bindgen-tests/tests/expectations/tests/c-empty-layout.rs +++ b/bindgen-tests/tests/expectations/tests/c-empty-layout.rs @@ -5,10 +5,13 @@ pub struct Foo {} #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of:: < Foo > (), 0usize, concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of::(), + 0usize, + concat!("Size of: ", stringify!(Foo)), ); assert_eq!( - ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", - stringify!(Foo)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)), ); } diff --git a/bindgen-tests/tests/expectations/tests/c_naming.rs b/bindgen-tests/tests/expectations/tests/c_naming.rs index c60f4f5980..a88f1b3572 100644 --- a/bindgen-tests/tests/expectations/tests/c_naming.rs +++ b/bindgen-tests/tests/expectations/tests/c_naming.rs @@ -9,16 +9,19 @@ fn bindgen_test_layout_struct_a() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < struct_a > (), 4usize, concat!("Size of: ", - stringify!(struct_a)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(struct_a)), ); assert_eq!( - ::std::mem::align_of:: < struct_a > (), 4usize, concat!("Alignment of ", - stringify!(struct_a)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(struct_a)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(struct_a), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(struct_a), "::", stringify!(a)), ); } pub type a = *const struct_a; @@ -33,20 +36,24 @@ fn bindgen_test_layout_union_b() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < union_b > (), 4usize, concat!("Size of: ", - stringify!(union_b)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(union_b)), ); assert_eq!( - ::std::mem::align_of:: < union_b > (), 4usize, concat!("Alignment of ", - stringify!(union_b)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(union_b)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(union_b), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(union_b), "::", stringify!(a)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(union_b), "::", stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(union_b), "::", stringify!(b)), ); } impl Default for union_b { diff --git a/bindgen-tests/tests/expectations/tests/canonical-types.rs b/bindgen-tests/tests/expectations/tests/canonical-types.rs index 61faef16b0..d19ced3b43 100644 --- a/bindgen-tests/tests/expectations/tests/canonical-types.rs +++ b/bindgen-tests/tests/expectations/tests/canonical-types.rs @@ -79,12 +79,14 @@ pub struct ClassD { #[test] fn bindgen_test_layout_ClassD() { assert_eq!( - ::std::mem::size_of:: < ClassD > (), 1usize, concat!("Size of: ", - stringify!(ClassD)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(ClassD)), ); assert_eq!( - ::std::mem::align_of:: < ClassD > (), 1usize, concat!("Alignment of ", - stringify!(ClassD)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(ClassD)), ); } impl Default for ClassD { @@ -99,12 +101,14 @@ impl Default for ClassD { #[test] fn __bindgen_test_layout_ClassB_open0_ClassD_ClassCInnerCRTP_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < ClassB > (), 1usize, - concat!("Size of template specialization: ", stringify!(ClassB)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of template specialization: ", stringify!(ClassB)), ); assert_eq!( - ::std::mem::align_of:: < ClassB > (), 1usize, - concat!("Alignment of template specialization: ", stringify!(ClassB)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of template specialization: ", stringify!(ClassB)), ); } #[repr(C)] @@ -115,12 +119,14 @@ pub struct ClassCInnerCRTP { #[test] fn bindgen_test_layout_ClassCInnerCRTP() { assert_eq!( - ::std::mem::size_of:: < ClassCInnerCRTP > (), 1usize, concat!("Size of: ", - stringify!(ClassCInnerCRTP)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(ClassCInnerCRTP)), ); assert_eq!( - ::std::mem::align_of:: < ClassCInnerCRTP > (), 1usize, concat!("Alignment of ", - stringify!(ClassCInnerCRTP)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(ClassCInnerCRTP)), ); } impl Default for ClassCInnerCRTP { @@ -135,12 +141,14 @@ impl Default for ClassCInnerCRTP { #[test] fn __bindgen_test_layout_ClassB_open0_ClassCInnerCRTP_ClassAInner_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < ClassB > (), 1usize, - concat!("Size of template specialization: ", stringify!(ClassB)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of template specialization: ", stringify!(ClassB)), ); assert_eq!( - ::std::mem::align_of:: < ClassB > (), 1usize, - concat!("Alignment of template specialization: ", stringify!(ClassB)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of template specialization: ", stringify!(ClassB)), ); } #[repr(C)] @@ -153,16 +161,19 @@ fn bindgen_test_layout_ClassAInner() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < ClassAInner > (), 8usize, concat!("Size of: ", - stringify!(ClassAInner)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(ClassAInner)), ); assert_eq!( - ::std::mem::align_of:: < ClassAInner > (), 8usize, concat!("Alignment of ", - stringify!(ClassAInner)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(ClassAInner)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).x) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(ClassAInner), "::", stringify!(x)) + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(ClassAInner), "::", stringify!(x)), ); } impl Default for ClassAInner { @@ -184,16 +195,19 @@ fn bindgen_test_layout_ClassCInnerA() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < ClassCInnerA > (), 8usize, concat!("Size of: ", - stringify!(ClassCInnerA)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(ClassCInnerA)), ); assert_eq!( - ::std::mem::align_of:: < ClassCInnerA > (), 8usize, concat!("Alignment of ", - stringify!(ClassCInnerA)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(ClassCInnerA)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).member) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(ClassCInnerA), "::", stringify!(member)) + unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(ClassCInnerA), "::", stringify!(member)), ); } impl Default for ClassCInnerA { @@ -215,16 +229,19 @@ fn bindgen_test_layout_ClassCInnerB() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < ClassCInnerB > (), 8usize, concat!("Size of: ", - stringify!(ClassCInnerB)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(ClassCInnerB)), ); assert_eq!( - ::std::mem::align_of:: < ClassCInnerB > (), 8usize, concat!("Alignment of ", - stringify!(ClassCInnerB)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(ClassCInnerB)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).cache) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(ClassCInnerB), "::", stringify!(cache)) + unsafe { ::std::ptr::addr_of!((*ptr).cache) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(ClassCInnerB), "::", stringify!(cache)), ); } impl Default for ClassCInnerB { diff --git a/bindgen-tests/tests/expectations/tests/canonical_path_without_namespacing.rs b/bindgen-tests/tests/expectations/tests/canonical_path_without_namespacing.rs index 3b9db4be47..11ae02814e 100644 --- a/bindgen-tests/tests/expectations/tests/canonical_path_without_namespacing.rs +++ b/bindgen-tests/tests/expectations/tests/canonical_path_without_namespacing.rs @@ -7,11 +7,14 @@ pub struct Bar { #[test] fn bindgen_test_layout_Bar() { assert_eq!( - ::std::mem::size_of:: < Bar > (), 1usize, concat!("Size of: ", stringify!(Bar)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Bar)), ); assert_eq!( - ::std::mem::align_of:: < Bar > (), 1usize, concat!("Alignment of ", - stringify!(Bar)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Bar)), ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/char.rs b/bindgen-tests/tests/expectations/tests/char.rs index 9e1e3177d2..f3acf04e0c 100644 --- a/bindgen-tests/tests/expectations/tests/char.rs +++ b/bindgen-tests/tests/expectations/tests/char.rs @@ -23,59 +23,73 @@ fn bindgen_test_layout_Test() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < Test > (), 12usize, concat!("Size of: ", - stringify!(Test)) + ::std::mem::size_of::(), + 12usize, + concat!("Size of: ", stringify!(Test)), ); assert_eq!( - ::std::mem::align_of:: < Test > (), 1usize, concat!("Alignment of ", - stringify!(Test)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Test)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).ch) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(ch)) + unsafe { ::std::ptr::addr_of!((*ptr).ch) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(ch)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).u) as usize - ptr as usize }, 1usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(u)) + unsafe { ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize }, + 1usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(u)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).d) as usize - ptr as usize }, 2usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(d)) + unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, + 2usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(d)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).cch) as usize - ptr as usize }, 3usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(cch)) + unsafe { ::std::ptr::addr_of!((*ptr).cch) as usize - ptr as usize }, + 3usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(cch)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).cu) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(cu)) + unsafe { ::std::ptr::addr_of!((*ptr).cu) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(cu)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).cd) as usize - ptr as usize }, 5usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(cd)) + unsafe { ::std::ptr::addr_of!((*ptr).cd) as usize - ptr as usize }, + 5usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(cd)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).Cch) as usize - ptr as usize }, 6usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cch)) + unsafe { ::std::ptr::addr_of!((*ptr).Cch) as usize - ptr as usize }, + 6usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cch)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).Cu) as usize - ptr as usize }, 7usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cu)) + unsafe { ::std::ptr::addr_of!((*ptr).Cu) as usize - ptr as usize }, + 7usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cu)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).Cd) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cd)) + unsafe { ::std::ptr::addr_of!((*ptr).Cd) as usize - ptr as usize }, + 8usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cd)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).Ccch) as usize - ptr as usize }, 9usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccch)) + unsafe { ::std::ptr::addr_of!((*ptr).Ccch) as usize - ptr as usize }, + 9usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccch)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).Ccu) as usize - ptr as usize }, 10usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccu)) + unsafe { ::std::ptr::addr_of!((*ptr).Ccu) as usize - ptr as usize }, + 10usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccu)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).Ccd) as usize - ptr as usize }, 11usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccd)) + unsafe { ::std::ptr::addr_of!((*ptr).Ccd) as usize - ptr as usize }, + 11usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccd)), ); } diff --git a/bindgen-tests/tests/expectations/tests/class.rs b/bindgen-tests/tests/expectations/tests/class.rs index 34051571bf..ce43204d73 100644 --- a/bindgen-tests/tests/expectations/tests/class.rs +++ b/bindgen-tests/tests/expectations/tests/class.rs @@ -39,19 +39,21 @@ pub struct C { 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, concat!("Size of: ", stringify!(C))); assert_eq!( - ::std::mem::size_of:: < C > (), 40usize, concat!("Size of: ", stringify!(C)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(C)), ); assert_eq!( - ::std::mem::align_of:: < C > (), 4usize, concat!("Alignment of ", stringify!(C)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(a)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(a)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).big_array) as usize - ptr as usize }, - 4usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(big_array)) + unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(big_array)), ); } impl Default for C { @@ -74,27 +76,46 @@ 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:: < C_with_zero_length_array > (), 40usize, - concat!("Size of: ", stringify!(C_with_zero_length_array)) + ::std::mem::size_of::(), + 40usize, + concat!("Size of: ", stringify!(C_with_zero_length_array)), ); assert_eq!( - ::std::mem::align_of:: < C_with_zero_length_array > (), 4usize, - concat!("Alignment of ", stringify!(C_with_zero_length_array)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(C_with_zero_length_array)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(C_with_zero_length_array), "::", - stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array), + "::", + stringify!(a), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).big_array) as usize - ptr as usize }, - 4usize, concat!("Offset of field: ", stringify!(C_with_zero_length_array), "::", - stringify!(big_array)) + unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array), + "::", + stringify!(big_array), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).zero_length_array) as usize - ptr as usize - }, 37usize, concat!("Offset of field: ", stringify!(C_with_zero_length_array), - "::", stringify!(zero_length_array)) + unsafe { + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize + }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array), + "::", + stringify!(zero_length_array), + ), ); } impl Default for C_with_zero_length_array { @@ -117,22 +138,36 @@ 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:: < C_with_zero_length_array_2 > (), 4usize, - concat!("Size of: ", stringify!(C_with_zero_length_array_2)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(C_with_zero_length_array_2)), ); assert_eq!( - ::std::mem::align_of:: < C_with_zero_length_array_2 > (), 4usize, - concat!("Alignment of ", stringify!(C_with_zero_length_array_2)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(C_with_zero_length_array_2)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(C_with_zero_length_array_2), "::", - stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_2), + "::", + stringify!(a), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).zero_length_array) as usize - ptr as usize - }, 4usize, concat!("Offset of field: ", stringify!(C_with_zero_length_array_2), - "::", stringify!(zero_length_array)) + unsafe { + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_2), + "::", + stringify!(zero_length_array), + ), ); } #[repr(C)] @@ -144,12 +179,14 @@ pub struct C_with_incomplete_array { #[test] fn bindgen_test_layout_C_with_incomplete_array() { assert_eq!( - ::std::mem::size_of:: < C_with_incomplete_array > (), 40usize, - concat!("Size of: ", stringify!(C_with_incomplete_array)) + ::std::mem::size_of::(), + 40usize, + concat!("Size of: ", stringify!(C_with_incomplete_array)), ); assert_eq!( - ::std::mem::align_of:: < C_with_incomplete_array > (), 4usize, - concat!("Alignment of ", stringify!(C_with_incomplete_array)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(C_with_incomplete_array)), ); } impl Default for C_with_incomplete_array { @@ -170,12 +207,14 @@ pub struct C_with_incomplete_array_2 { #[test] fn bindgen_test_layout_C_with_incomplete_array_2() { assert_eq!( - ::std::mem::size_of:: < C_with_incomplete_array_2 > (), 4usize, - concat!("Size of: ", stringify!(C_with_incomplete_array_2)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(C_with_incomplete_array_2)), ); assert_eq!( - ::std::mem::align_of:: < C_with_incomplete_array_2 > (), 4usize, - concat!("Alignment of ", stringify!(C_with_incomplete_array_2)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(C_with_incomplete_array_2)), ); } #[repr(C)] @@ -188,14 +227,17 @@ pub struct C_with_zero_length_array_and_incomplete_array { #[test] fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { assert_eq!( - ::std::mem::size_of:: < C_with_zero_length_array_and_incomplete_array > (), - 40usize, concat!("Size of: ", - stringify!(C_with_zero_length_array_and_incomplete_array)) + ::std::mem::size_of::(), + 40usize, + concat!("Size of: ", stringify!(C_with_zero_length_array_and_incomplete_array)), ); assert_eq!( - ::std::mem::align_of:: < C_with_zero_length_array_and_incomplete_array > (), - 4usize, concat!("Alignment of ", - stringify!(C_with_zero_length_array_and_incomplete_array)) + ::std::mem::align_of::(), + 4usize, + concat!( + "Alignment of ", + stringify!(C_with_zero_length_array_and_incomplete_array), + ), ); } impl Default for C_with_zero_length_array_and_incomplete_array { @@ -217,14 +259,17 @@ pub struct C_with_zero_length_array_and_incomplete_array_2 { #[test] fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { assert_eq!( - ::std::mem::size_of:: < C_with_zero_length_array_and_incomplete_array_2 > (), - 4usize, concat!("Size of: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(C_with_zero_length_array_and_incomplete_array_2)), ); assert_eq!( - ::std::mem::align_of:: < C_with_zero_length_array_and_incomplete_array_2 > (), - 4usize, concat!("Alignment of ", - stringify!(C_with_zero_length_array_and_incomplete_array_2)) + ::std::mem::align_of::(), + 4usize, + concat!( + "Alignment of ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), + ), ); } #[repr(C)] @@ -237,16 +282,19 @@ 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:: < WithDtor > (), 4usize, concat!("Size of: ", - stringify!(WithDtor)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(WithDtor)), ); assert_eq!( - ::std::mem::align_of:: < WithDtor > (), 4usize, concat!("Alignment of ", - stringify!(WithDtor)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(WithDtor)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(WithDtor), "::", stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(WithDtor), "::", stringify!(b)), ); } #[repr(C)] @@ -257,12 +305,14 @@ pub struct IncompleteArrayNonCopiable { #[test] fn bindgen_test_layout_IncompleteArrayNonCopiable() { assert_eq!( - ::std::mem::size_of:: < IncompleteArrayNonCopiable > (), 8usize, - concat!("Size of: ", stringify!(IncompleteArrayNonCopiable)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(IncompleteArrayNonCopiable)), ); assert_eq!( - ::std::mem::align_of:: < IncompleteArrayNonCopiable > (), 8usize, - concat!("Alignment of ", stringify!(IncompleteArrayNonCopiable)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(IncompleteArrayNonCopiable)), ); } impl Default for IncompleteArrayNonCopiable { @@ -285,20 +335,24 @@ 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:: < Union > (), 4usize, concat!("Size of: ", - stringify!(Union)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Union)), ); assert_eq!( - ::std::mem::align_of:: < Union > (), 4usize, concat!("Alignment of ", - stringify!(Union)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Union)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).d) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Union), "::", stringify!(d)) + unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Union), "::", stringify!(d)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).i) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Union), "::", stringify!(i)) + unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Union), "::", stringify!(i)), ); } impl Default for Union { @@ -320,16 +374,19 @@ 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:: < WithUnion > (), 4usize, concat!("Size of: ", - stringify!(WithUnion)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(WithUnion)), ); assert_eq!( - ::std::mem::align_of:: < WithUnion > (), 4usize, concat!("Alignment of ", - stringify!(WithUnion)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(WithUnion)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).data) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(WithUnion), "::", stringify!(data)) + unsafe { ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(WithUnion), "::", stringify!(data)), ); } impl Default for WithUnion { @@ -349,12 +406,14 @@ pub struct RealAbstractionWithTonsOfMethods { #[test] fn bindgen_test_layout_RealAbstractionWithTonsOfMethods() { assert_eq!( - ::std::mem::size_of:: < RealAbstractionWithTonsOfMethods > (), 1usize, - concat!("Size of: ", stringify!(RealAbstractionWithTonsOfMethods)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(RealAbstractionWithTonsOfMethods)), ); assert_eq!( - ::std::mem::align_of:: < RealAbstractionWithTonsOfMethods > (), 1usize, - concat!("Alignment of ", stringify!(RealAbstractionWithTonsOfMethods)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(RealAbstractionWithTonsOfMethods)), ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/class_1_0.rs b/bindgen-tests/tests/expectations/tests/class_1_0.rs index e36fd2fa5d..5d66e2122b 100644 --- a/bindgen-tests/tests/expectations/tests/class_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/class_1_0.rs @@ -82,19 +82,21 @@ pub struct C { 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, concat!("Size of: ", stringify!(C))); assert_eq!( - ::std::mem::size_of:: < C > (), 40usize, concat!("Size of: ", stringify!(C)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(C)), ); assert_eq!( - ::std::mem::align_of:: < C > (), 4usize, concat!("Alignment of ", stringify!(C)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(a)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(a)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).big_array) as usize - ptr as usize }, - 4usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(big_array)) + unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(big_array)), ); } impl Clone for C { @@ -127,27 +129,46 @@ 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:: < C_with_zero_length_array > (), 40usize, - concat!("Size of: ", stringify!(C_with_zero_length_array)) + ::std::mem::size_of::(), + 40usize, + concat!("Size of: ", stringify!(C_with_zero_length_array)), ); assert_eq!( - ::std::mem::align_of:: < C_with_zero_length_array > (), 4usize, - concat!("Alignment of ", stringify!(C_with_zero_length_array)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(C_with_zero_length_array)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(C_with_zero_length_array), "::", - stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array), + "::", + stringify!(a), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).big_array) as usize - ptr as usize }, - 4usize, concat!("Offset of field: ", stringify!(C_with_zero_length_array), "::", - stringify!(big_array)) + unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array), + "::", + stringify!(big_array), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).zero_length_array) as usize - ptr as usize - }, 37usize, concat!("Offset of field: ", stringify!(C_with_zero_length_array), - "::", stringify!(zero_length_array)) + unsafe { + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize + }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array), + "::", + stringify!(zero_length_array), + ), ); } impl Default for C_with_zero_length_array { @@ -170,22 +191,36 @@ 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:: < C_with_zero_length_array_2 > (), 4usize, - concat!("Size of: ", stringify!(C_with_zero_length_array_2)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(C_with_zero_length_array_2)), ); assert_eq!( - ::std::mem::align_of:: < C_with_zero_length_array_2 > (), 4usize, - concat!("Alignment of ", stringify!(C_with_zero_length_array_2)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(C_with_zero_length_array_2)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(C_with_zero_length_array_2), "::", - stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_2), + "::", + stringify!(a), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).zero_length_array) as usize - ptr as usize - }, 4usize, concat!("Offset of field: ", stringify!(C_with_zero_length_array_2), - "::", stringify!(zero_length_array)) + unsafe { + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_2), + "::", + stringify!(zero_length_array), + ), ); } #[repr(C)] @@ -197,12 +232,14 @@ pub struct C_with_incomplete_array { #[test] fn bindgen_test_layout_C_with_incomplete_array() { assert_eq!( - ::std::mem::size_of:: < C_with_incomplete_array > (), 40usize, - concat!("Size of: ", stringify!(C_with_incomplete_array)) + ::std::mem::size_of::(), + 40usize, + concat!("Size of: ", stringify!(C_with_incomplete_array)), ); assert_eq!( - ::std::mem::align_of:: < C_with_incomplete_array > (), 4usize, - concat!("Alignment of ", stringify!(C_with_incomplete_array)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(C_with_incomplete_array)), ); } impl Default for C_with_incomplete_array { @@ -223,12 +260,14 @@ pub struct C_with_incomplete_array_2 { #[test] fn bindgen_test_layout_C_with_incomplete_array_2() { assert_eq!( - ::std::mem::size_of:: < C_with_incomplete_array_2 > (), 4usize, - concat!("Size of: ", stringify!(C_with_incomplete_array_2)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(C_with_incomplete_array_2)), ); assert_eq!( - ::std::mem::align_of:: < C_with_incomplete_array_2 > (), 4usize, - concat!("Alignment of ", stringify!(C_with_incomplete_array_2)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(C_with_incomplete_array_2)), ); } #[repr(C)] @@ -241,14 +280,17 @@ pub struct C_with_zero_length_array_and_incomplete_array { #[test] fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { assert_eq!( - ::std::mem::size_of:: < C_with_zero_length_array_and_incomplete_array > (), - 40usize, concat!("Size of: ", - stringify!(C_with_zero_length_array_and_incomplete_array)) + ::std::mem::size_of::(), + 40usize, + concat!("Size of: ", stringify!(C_with_zero_length_array_and_incomplete_array)), ); assert_eq!( - ::std::mem::align_of:: < C_with_zero_length_array_and_incomplete_array > (), - 4usize, concat!("Alignment of ", - stringify!(C_with_zero_length_array_and_incomplete_array)) + ::std::mem::align_of::(), + 4usize, + concat!( + "Alignment of ", + stringify!(C_with_zero_length_array_and_incomplete_array), + ), ); } impl Default for C_with_zero_length_array_and_incomplete_array { @@ -270,14 +312,17 @@ pub struct C_with_zero_length_array_and_incomplete_array_2 { #[test] fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { assert_eq!( - ::std::mem::size_of:: < C_with_zero_length_array_and_incomplete_array_2 > (), - 4usize, concat!("Size of: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(C_with_zero_length_array_and_incomplete_array_2)), ); assert_eq!( - ::std::mem::align_of:: < C_with_zero_length_array_and_incomplete_array_2 > (), - 4usize, concat!("Alignment of ", - stringify!(C_with_zero_length_array_and_incomplete_array_2)) + ::std::mem::align_of::(), + 4usize, + concat!( + "Alignment of ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), + ), ); } #[repr(C)] @@ -290,16 +335,19 @@ 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:: < WithDtor > (), 4usize, concat!("Size of: ", - stringify!(WithDtor)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(WithDtor)), ); assert_eq!( - ::std::mem::align_of:: < WithDtor > (), 4usize, concat!("Alignment of ", - stringify!(WithDtor)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(WithDtor)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(WithDtor), "::", stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(WithDtor), "::", stringify!(b)), ); } #[repr(C)] @@ -310,12 +358,14 @@ pub struct IncompleteArrayNonCopiable { #[test] fn bindgen_test_layout_IncompleteArrayNonCopiable() { assert_eq!( - ::std::mem::size_of:: < IncompleteArrayNonCopiable > (), 8usize, - concat!("Size of: ", stringify!(IncompleteArrayNonCopiable)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(IncompleteArrayNonCopiable)), ); assert_eq!( - ::std::mem::align_of:: < IncompleteArrayNonCopiable > (), 8usize, - concat!("Alignment of ", stringify!(IncompleteArrayNonCopiable)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(IncompleteArrayNonCopiable)), ); } impl Default for IncompleteArrayNonCopiable { @@ -339,20 +389,24 @@ 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:: < Union > (), 4usize, concat!("Size of: ", - stringify!(Union)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Union)), ); assert_eq!( - ::std::mem::align_of:: < Union > (), 4usize, concat!("Alignment of ", - stringify!(Union)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Union)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).d) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Union), "::", stringify!(d)) + unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Union), "::", stringify!(d)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).i) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Union), "::", stringify!(i)) + unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Union), "::", stringify!(i)), ); } impl Clone for Union { @@ -370,16 +424,19 @@ 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:: < WithUnion > (), 4usize, concat!("Size of: ", - stringify!(WithUnion)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(WithUnion)), ); assert_eq!( - ::std::mem::align_of:: < WithUnion > (), 4usize, concat!("Alignment of ", - stringify!(WithUnion)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(WithUnion)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).data) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(WithUnion), "::", stringify!(data)) + unsafe { ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(WithUnion), "::", stringify!(data)), ); } impl Clone for WithUnion { @@ -395,12 +452,14 @@ pub struct RealAbstractionWithTonsOfMethods { #[test] fn bindgen_test_layout_RealAbstractionWithTonsOfMethods() { assert_eq!( - ::std::mem::size_of:: < RealAbstractionWithTonsOfMethods > (), 1usize, - concat!("Size of: ", stringify!(RealAbstractionWithTonsOfMethods)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(RealAbstractionWithTonsOfMethods)), ); assert_eq!( - ::std::mem::align_of:: < RealAbstractionWithTonsOfMethods > (), 1usize, - concat!("Alignment of ", stringify!(RealAbstractionWithTonsOfMethods)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(RealAbstractionWithTonsOfMethods)), ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/class_nested.rs b/bindgen-tests/tests/expectations/tests/class_nested.rs index 66700efc09..38db451b8b 100644 --- a/bindgen-tests/tests/expectations/tests/class_nested.rs +++ b/bindgen-tests/tests/expectations/tests/class_nested.rs @@ -14,15 +14,19 @@ fn bindgen_test_layout_A_B() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < A_B > (), 4usize, concat!("Size of: ", stringify!(A_B)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(A_B)), ); assert_eq!( - ::std::mem::align_of:: < A_B > (), 4usize, concat!("Alignment of ", - stringify!(A_B)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(A_B)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).member_b) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(A_B), "::", stringify!(member_b)) + unsafe { ::std::ptr::addr_of!((*ptr).member_b) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(A_B), "::", stringify!(member_b)), ); } #[repr(C)] @@ -44,15 +48,16 @@ impl Default for A_D { 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::(), 4usize, concat!("Size of: ", stringify!(A))); assert_eq!( - ::std::mem::size_of:: < A > (), 4usize, concat!("Size of: ", stringify!(A)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(A)), ); assert_eq!( - ::std::mem::align_of:: < A > (), 4usize, concat!("Alignment of ", stringify!(A)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).member_a) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(member_a)) + unsafe { ::std::ptr::addr_of!((*ptr).member_a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(A), "::", stringify!(member_a)), ); } #[repr(C)] @@ -65,15 +70,19 @@ fn bindgen_test_layout_A_C() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < A_C > (), 4usize, concat!("Size of: ", stringify!(A_C)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(A_C)), ); assert_eq!( - ::std::mem::align_of:: < A_C > (), 4usize, concat!("Alignment of ", - stringify!(A_C)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(A_C)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).baz) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(A_C), "::", stringify!(baz)) + unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(A_C), "::", stringify!(baz)), ); } extern "C" { @@ -82,14 +91,20 @@ extern "C" { #[test] fn __bindgen_test_layout_A_D_open0_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < A_D < ::std::os::raw::c_int > > (), 4usize, - concat!("Size of template specialization: ", stringify!(A_D < - ::std::os::raw::c_int >)) + ::std::mem::size_of::>(), + 4usize, + concat!( + "Size of template specialization: ", + stringify!(A_D < ::std::os::raw::c_int >), + ), ); assert_eq!( - ::std::mem::align_of:: < A_D < ::std::os::raw::c_int > > (), 4usize, - concat!("Alignment of template specialization: ", stringify!(A_D < - ::std::os::raw::c_int >)) + ::std::mem::align_of::>(), + 4usize, + concat!( + "Alignment of template specialization: ", + stringify!(A_D < ::std::os::raw::c_int >), + ), ); } extern "C" { @@ -104,15 +119,16 @@ pub struct D { 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::(), 4usize, concat!("Size of: ", stringify!(D))); assert_eq!( - ::std::mem::size_of:: < D > (), 4usize, concat!("Size of: ", stringify!(D)) - ); - assert_eq!( - ::std::mem::align_of:: < D > (), 4usize, concat!("Alignment of ", stringify!(D)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(D)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).member) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(D), "::", stringify!(member)) + unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(D), "::", stringify!(member)), ); } #[repr(C)] diff --git a/bindgen-tests/tests/expectations/tests/class_no_members.rs b/bindgen-tests/tests/expectations/tests/class_no_members.rs index 32750cfbff..d8c67ca52d 100644 --- a/bindgen-tests/tests/expectations/tests/class_no_members.rs +++ b/bindgen-tests/tests/expectations/tests/class_no_members.rs @@ -7,12 +7,14 @@ pub struct whatever { #[test] fn bindgen_test_layout_whatever() { assert_eq!( - ::std::mem::size_of:: < whatever > (), 1usize, concat!("Size of: ", - stringify!(whatever)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(whatever)), ); assert_eq!( - ::std::mem::align_of:: < whatever > (), 1usize, concat!("Alignment of ", - stringify!(whatever)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(whatever)), ); } #[repr(C)] @@ -23,12 +25,14 @@ pub struct whatever_child { #[test] fn bindgen_test_layout_whatever_child() { assert_eq!( - ::std::mem::size_of:: < whatever_child > (), 1usize, concat!("Size of: ", - stringify!(whatever_child)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(whatever_child)), ); assert_eq!( - ::std::mem::align_of:: < whatever_child > (), 1usize, concat!("Alignment of ", - stringify!(whatever_child)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(whatever_child)), ); } #[repr(C)] @@ -41,16 +45,23 @@ fn bindgen_test_layout_whatever_child_with_member() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < whatever_child_with_member > (), 4usize, - concat!("Size of: ", stringify!(whatever_child_with_member)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(whatever_child_with_member)), ); assert_eq!( - ::std::mem::align_of:: < whatever_child_with_member > (), 4usize, - concat!("Alignment of ", stringify!(whatever_child_with_member)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(whatever_child_with_member)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).m_member) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(whatever_child_with_member), - "::", stringify!(m_member)) + unsafe { ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(whatever_child_with_member), + "::", + stringify!(m_member), + ), ); } diff --git a/bindgen-tests/tests/expectations/tests/class_static.rs b/bindgen-tests/tests/expectations/tests/class_static.rs index 9ddc19c1ab..f6f8a3b175 100644 --- a/bindgen-tests/tests/expectations/tests/class_static.rs +++ b/bindgen-tests/tests/expectations/tests/class_static.rs @@ -15,12 +15,14 @@ extern "C" { #[test] fn bindgen_test_layout_MyClass() { assert_eq!( - ::std::mem::size_of:: < MyClass > (), 1usize, concat!("Size of: ", - stringify!(MyClass)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(MyClass)), ); assert_eq!( - ::std::mem::align_of:: < MyClass > (), 1usize, concat!("Alignment of ", - stringify!(MyClass)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(MyClass)), ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/class_static_const.rs b/bindgen-tests/tests/expectations/tests/class_static_const.rs index 0f7635e640..c2cd5b3e9f 100644 --- a/bindgen-tests/tests/expectations/tests/class_static_const.rs +++ b/bindgen-tests/tests/expectations/tests/class_static_const.rs @@ -9,10 +9,10 @@ pub const A_b: i32 = 63; pub const A_c: u32 = 255; #[test] fn bindgen_test_layout_A() { + assert_eq!(::std::mem::size_of::(), 1usize, concat!("Size of: ", stringify!(A))); assert_eq!( - ::std::mem::size_of:: < A > (), 1usize, concat!("Size of: ", stringify!(A)) - ); - assert_eq!( - ::std::mem::align_of:: < A > (), 1usize, concat!("Alignment of ", stringify!(A)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(A)), ); } diff --git a/bindgen-tests/tests/expectations/tests/class_use_as.rs b/bindgen-tests/tests/expectations/tests/class_use_as.rs index 46a0acff66..f01e8acb1b 100644 --- a/bindgen-tests/tests/expectations/tests/class_use_as.rs +++ b/bindgen-tests/tests/expectations/tests/class_use_as.rs @@ -10,17 +10,19 @@ fn bindgen_test_layout_whatever() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < whatever > (), 4usize, concat!("Size of: ", - stringify!(whatever)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(whatever)), ); assert_eq!( - ::std::mem::align_of:: < whatever > (), 4usize, concat!("Alignment of ", - stringify!(whatever)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(whatever)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).replacement) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(whatever), "::", - stringify!(replacement)) + unsafe { ::std::ptr::addr_of!((*ptr).replacement) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(whatever), "::", stringify!(replacement)), ); } #[repr(C)] @@ -33,15 +35,18 @@ fn bindgen_test_layout_container() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < container > (), 4usize, concat!("Size of: ", - stringify!(container)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(container)), ); assert_eq!( - ::std::mem::align_of:: < container > (), 4usize, concat!("Alignment of ", - stringify!(container)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(container)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).c) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(container), "::", stringify!(c)) + unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(container), "::", stringify!(c)), ); } diff --git a/bindgen-tests/tests/expectations/tests/class_with_dtor.rs b/bindgen-tests/tests/expectations/tests/class_with_dtor.rs index 4060cf5398..75585e6351 100644 --- a/bindgen-tests/tests/expectations/tests/class_with_dtor.rs +++ b/bindgen-tests/tests/expectations/tests/class_with_dtor.rs @@ -25,17 +25,24 @@ fn bindgen_test_layout_WithoutDtor() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < WithoutDtor > (), 8usize, concat!("Size of: ", - stringify!(WithoutDtor)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(WithoutDtor)), ); assert_eq!( - ::std::mem::align_of:: < WithoutDtor > (), 8usize, concat!("Alignment of ", - stringify!(WithoutDtor)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(WithoutDtor)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).shouldBeWithDtor) as usize - ptr as usize - }, 0usize, concat!("Offset of field: ", stringify!(WithoutDtor), "::", - stringify!(shouldBeWithDtor)) + unsafe { ::std::ptr::addr_of!((*ptr).shouldBeWithDtor) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithoutDtor), + "::", + stringify!(shouldBeWithDtor), + ), ); } impl Default for WithoutDtor { @@ -50,13 +57,19 @@ impl Default for WithoutDtor { #[test] fn __bindgen_test_layout_HandleWithDtor_open0_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < HandleWithDtor < ::std::os::raw::c_int > > (), 8usize, - concat!("Size of template specialization: ", stringify!(HandleWithDtor < - ::std::os::raw::c_int >)) + ::std::mem::size_of::>(), + 8usize, + concat!( + "Size of template specialization: ", + stringify!(HandleWithDtor < ::std::os::raw::c_int >), + ), ); assert_eq!( - ::std::mem::align_of:: < HandleWithDtor < ::std::os::raw::c_int > > (), 8usize, - concat!("Alignment of template specialization: ", stringify!(HandleWithDtor < - ::std::os::raw::c_int >)) + ::std::mem::align_of::>(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(HandleWithDtor < ::std::os::raw::c_int >), + ), ); } diff --git a/bindgen-tests/tests/expectations/tests/class_with_inner_struct.rs b/bindgen-tests/tests/expectations/tests/class_with_inner_struct.rs index 68e749b1d8..1b0f511230 100644 --- a/bindgen-tests/tests/expectations/tests/class_with_inner_struct.rs +++ b/bindgen-tests/tests/expectations/tests/class_with_inner_struct.rs @@ -17,20 +17,24 @@ fn bindgen_test_layout_A_Segment() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < A_Segment > (), 8usize, concat!("Size of: ", - stringify!(A_Segment)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(A_Segment)), ); assert_eq!( - ::std::mem::align_of:: < A_Segment > (), 4usize, concat!("Alignment of ", - stringify!(A_Segment)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(A_Segment)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).begin) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(A_Segment), "::", stringify!(begin)) + unsafe { ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(A_Segment), "::", stringify!(begin)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).end) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(A_Segment), "::", stringify!(end)) + unsafe { ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(A_Segment), "::", stringify!(end)), ); } #[repr(C)] @@ -43,16 +47,19 @@ fn bindgen_test_layout_A__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < A__bindgen_ty_1 > (), 4usize, concat!("Size of: ", - stringify!(A__bindgen_ty_1)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(A__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < A__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", - stringify!(A__bindgen_ty_1)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(A__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).f) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(A__bindgen_ty_1), "::", stringify!(f)) + unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(A__bindgen_ty_1), "::", stringify!(f)), ); } impl Default for A__bindgen_ty_1 { @@ -74,16 +81,19 @@ fn bindgen_test_layout_A__bindgen_ty_2() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < A__bindgen_ty_2 > (), 4usize, concat!("Size of: ", - stringify!(A__bindgen_ty_2)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(A__bindgen_ty_2)), ); assert_eq!( - ::std::mem::align_of:: < A__bindgen_ty_2 > (), 4usize, concat!("Alignment of ", - stringify!(A__bindgen_ty_2)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(A__bindgen_ty_2)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).d) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(A__bindgen_ty_2), "::", stringify!(d)) + unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(A__bindgen_ty_2), "::", stringify!(d)), ); } impl Default for A__bindgen_ty_2 { @@ -99,20 +109,21 @@ impl Default for A__bindgen_ty_2 { 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::(), 12usize, concat!("Size of: ", stringify!(A))); assert_eq!( - ::std::mem::size_of:: < A > (), 12usize, concat!("Size of: ", stringify!(A)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(A)), ); assert_eq!( - ::std::mem::align_of:: < A > (), 4usize, concat!("Alignment of ", stringify!(A)) + unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(A), "::", stringify!(c)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).c) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(c)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).named_union) as usize - ptr as usize }, - 4usize, concat!("Offset of field: ", stringify!(A), "::", - stringify!(named_union)) + unsafe { ::std::ptr::addr_of!((*ptr).named_union) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(A), "::", stringify!(named_union)), ); } impl Default for A { @@ -140,35 +151,40 @@ fn bindgen_test_layout_B_Segment() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < B_Segment > (), 8usize, concat!("Size of: ", - stringify!(B_Segment)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(B_Segment)), ); assert_eq!( - ::std::mem::align_of:: < B_Segment > (), 4usize, concat!("Alignment of ", - stringify!(B_Segment)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(B_Segment)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).begin) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(B_Segment), "::", stringify!(begin)) + unsafe { ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(B_Segment), "::", stringify!(begin)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).end) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(B_Segment), "::", stringify!(end)) + unsafe { ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(B_Segment), "::", stringify!(end)), ); } #[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::(), 4usize, concat!("Size of: ", stringify!(B))); assert_eq!( - ::std::mem::size_of:: < B > (), 4usize, concat!("Size of: ", stringify!(B)) - ); - assert_eq!( - ::std::mem::align_of:: < B > (), 4usize, concat!("Alignment of ", stringify!(B)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(B)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).d) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(B), "::", stringify!(d)) + unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(B), "::", stringify!(d)), ); } #[repr(i32)] @@ -204,32 +220,54 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < C__bindgen_ty_1__bindgen_ty_1 > (), 16usize, - concat!("Size of: ", stringify!(C__bindgen_ty_1__bindgen_ty_1)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(C__bindgen_ty_1__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < C__bindgen_ty_1__bindgen_ty_1 > (), 4usize, - concat!("Alignment of ", stringify!(C__bindgen_ty_1__bindgen_ty_1)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(C__bindgen_ty_1__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mX1) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(C__bindgen_ty_1__bindgen_ty_1), "::", - stringify!(mX1)) + unsafe { ::std::ptr::addr_of!((*ptr).mX1) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(mX1), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mY1) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(C__bindgen_ty_1__bindgen_ty_1), "::", - stringify!(mY1)) + unsafe { ::std::ptr::addr_of!((*ptr).mY1) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(mY1), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mX2) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(C__bindgen_ty_1__bindgen_ty_1), "::", - stringify!(mX2)) + unsafe { ::std::ptr::addr_of!((*ptr).mX2) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(C__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(mX2), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mY2) as usize - ptr as usize }, 12usize, - concat!("Offset of field: ", stringify!(C__bindgen_ty_1__bindgen_ty_1), "::", - stringify!(mY2)) + unsafe { ::std::ptr::addr_of!((*ptr).mY2) as usize - ptr as usize }, + 12usize, + concat!( + "Offset of field: ", + stringify!(C__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(mY2), + ), ); } #[repr(C)] @@ -243,22 +281,34 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_2() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < C__bindgen_ty_1__bindgen_ty_2 > (), 8usize, - concat!("Size of: ", stringify!(C__bindgen_ty_1__bindgen_ty_2)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(C__bindgen_ty_1__bindgen_ty_2)), ); assert_eq!( - ::std::mem::align_of:: < C__bindgen_ty_1__bindgen_ty_2 > (), 4usize, - concat!("Alignment of ", stringify!(C__bindgen_ty_1__bindgen_ty_2)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(C__bindgen_ty_1__bindgen_ty_2)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mStepSyntax) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(C__bindgen_ty_1__bindgen_ty_2), - "::", stringify!(mStepSyntax)) + unsafe { ::std::ptr::addr_of!((*ptr).mStepSyntax) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(mStepSyntax), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mSteps) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(C__bindgen_ty_1__bindgen_ty_2), "::", - stringify!(mSteps)) + unsafe { ::std::ptr::addr_of!((*ptr).mSteps) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(mSteps), + ), ); } impl Default for C__bindgen_ty_1__bindgen_ty_2 { @@ -275,17 +325,24 @@ fn bindgen_test_layout_C__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < C__bindgen_ty_1 > (), 16usize, concat!("Size of: ", - stringify!(C__bindgen_ty_1)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(C__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < C__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", - stringify!(C__bindgen_ty_1)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(C__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mFunc) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(C__bindgen_ty_1), "::", - stringify!(mFunc)) + unsafe { ::std::ptr::addr_of!((*ptr).mFunc) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C__bindgen_ty_1), + "::", + stringify!(mFunc), + ), ); } impl Default for C__bindgen_ty_1 { @@ -308,35 +365,40 @@ fn bindgen_test_layout_C_Segment() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < C_Segment > (), 8usize, concat!("Size of: ", - stringify!(C_Segment)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(C_Segment)), ); assert_eq!( - ::std::mem::align_of:: < C_Segment > (), 4usize, concat!("Alignment of ", - stringify!(C_Segment)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(C_Segment)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).begin) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(C_Segment), "::", stringify!(begin)) + unsafe { ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(C_Segment), "::", stringify!(begin)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).end) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(C_Segment), "::", stringify!(end)) + unsafe { ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(C_Segment), "::", stringify!(end)), ); } #[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::(), 20usize, concat!("Size of: ", stringify!(C))); assert_eq!( - ::std::mem::size_of:: < C > (), 20usize, concat!("Size of: ", stringify!(C)) - ); - assert_eq!( - ::std::mem::align_of:: < C > (), 4usize, concat!("Alignment of ", stringify!(C)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(C)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).d) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(d)) + unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(d)), ); } impl Default for C { diff --git a/bindgen-tests/tests/expectations/tests/class_with_inner_struct_1_0.rs b/bindgen-tests/tests/expectations/tests/class_with_inner_struct_1_0.rs index c1600618ba..1f0ea9abdc 100644 --- a/bindgen-tests/tests/expectations/tests/class_with_inner_struct_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/class_with_inner_struct_1_0.rs @@ -60,20 +60,24 @@ fn bindgen_test_layout_A_Segment() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < A_Segment > (), 8usize, concat!("Size of: ", - stringify!(A_Segment)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(A_Segment)), ); assert_eq!( - ::std::mem::align_of:: < A_Segment > (), 4usize, concat!("Alignment of ", - stringify!(A_Segment)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(A_Segment)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).begin) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(A_Segment), "::", stringify!(begin)) + unsafe { ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(A_Segment), "::", stringify!(begin)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).end) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(A_Segment), "::", stringify!(end)) + unsafe { ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(A_Segment), "::", stringify!(end)), ); } impl Clone for A_Segment { @@ -92,16 +96,19 @@ fn bindgen_test_layout_A__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < A__bindgen_ty_1 > (), 4usize, concat!("Size of: ", - stringify!(A__bindgen_ty_1)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(A__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < A__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", - stringify!(A__bindgen_ty_1)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(A__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).f) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(A__bindgen_ty_1), "::", stringify!(f)) + unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(A__bindgen_ty_1), "::", stringify!(f)), ); } impl Clone for A__bindgen_ty_1 { @@ -120,16 +127,19 @@ fn bindgen_test_layout_A__bindgen_ty_2() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < A__bindgen_ty_2 > (), 4usize, concat!("Size of: ", - stringify!(A__bindgen_ty_2)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(A__bindgen_ty_2)), ); assert_eq!( - ::std::mem::align_of:: < A__bindgen_ty_2 > (), 4usize, concat!("Alignment of ", - stringify!(A__bindgen_ty_2)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(A__bindgen_ty_2)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).d) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(A__bindgen_ty_2), "::", stringify!(d)) + unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(A__bindgen_ty_2), "::", stringify!(d)), ); } impl Clone for A__bindgen_ty_2 { @@ -141,20 +151,21 @@ impl Clone for A__bindgen_ty_2 { 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::(), 12usize, concat!("Size of: ", stringify!(A))); assert_eq!( - ::std::mem::size_of:: < A > (), 12usize, concat!("Size of: ", stringify!(A)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(A)), ); assert_eq!( - ::std::mem::align_of:: < A > (), 4usize, concat!("Alignment of ", stringify!(A)) + unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(A), "::", stringify!(c)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).c) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(c)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).named_union) as usize - ptr as usize }, - 4usize, concat!("Offset of field: ", stringify!(A), "::", - stringify!(named_union)) + unsafe { ::std::ptr::addr_of!((*ptr).named_union) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(A), "::", stringify!(named_union)), ); } impl Clone for A { @@ -178,20 +189,24 @@ fn bindgen_test_layout_B_Segment() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < B_Segment > (), 8usize, concat!("Size of: ", - stringify!(B_Segment)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(B_Segment)), ); assert_eq!( - ::std::mem::align_of:: < B_Segment > (), 4usize, concat!("Alignment of ", - stringify!(B_Segment)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(B_Segment)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).begin) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(B_Segment), "::", stringify!(begin)) + unsafe { ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(B_Segment), "::", stringify!(begin)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).end) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(B_Segment), "::", stringify!(end)) + unsafe { ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(B_Segment), "::", stringify!(end)), ); } impl Clone for B_Segment { @@ -203,15 +218,16 @@ impl Clone for B_Segment { 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::(), 4usize, concat!("Size of: ", stringify!(B))); assert_eq!( - ::std::mem::size_of:: < B > (), 4usize, concat!("Size of: ", stringify!(B)) - ); - assert_eq!( - ::std::mem::align_of:: < B > (), 4usize, concat!("Alignment of ", stringify!(B)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(B)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).d) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(B), "::", stringify!(d)) + unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(B), "::", stringify!(d)), ); } impl Clone for B { @@ -253,32 +269,54 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < C__bindgen_ty_1__bindgen_ty_1 > (), 16usize, - concat!("Size of: ", stringify!(C__bindgen_ty_1__bindgen_ty_1)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(C__bindgen_ty_1__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < C__bindgen_ty_1__bindgen_ty_1 > (), 4usize, - concat!("Alignment of ", stringify!(C__bindgen_ty_1__bindgen_ty_1)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(C__bindgen_ty_1__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mX1) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(C__bindgen_ty_1__bindgen_ty_1), "::", - stringify!(mX1)) + unsafe { ::std::ptr::addr_of!((*ptr).mX1) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(mX1), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mY1) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(C__bindgen_ty_1__bindgen_ty_1), "::", - stringify!(mY1)) + unsafe { ::std::ptr::addr_of!((*ptr).mY1) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(mY1), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mX2) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(C__bindgen_ty_1__bindgen_ty_1), "::", - stringify!(mX2)) + unsafe { ::std::ptr::addr_of!((*ptr).mX2) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(C__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(mX2), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mY2) as usize - ptr as usize }, 12usize, - concat!("Offset of field: ", stringify!(C__bindgen_ty_1__bindgen_ty_1), "::", - stringify!(mY2)) + unsafe { ::std::ptr::addr_of!((*ptr).mY2) as usize - ptr as usize }, + 12usize, + concat!( + "Offset of field: ", + stringify!(C__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(mY2), + ), ); } impl Clone for C__bindgen_ty_1__bindgen_ty_1 { @@ -297,22 +335,34 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_2() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < C__bindgen_ty_1__bindgen_ty_2 > (), 8usize, - concat!("Size of: ", stringify!(C__bindgen_ty_1__bindgen_ty_2)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(C__bindgen_ty_1__bindgen_ty_2)), ); assert_eq!( - ::std::mem::align_of:: < C__bindgen_ty_1__bindgen_ty_2 > (), 4usize, - concat!("Alignment of ", stringify!(C__bindgen_ty_1__bindgen_ty_2)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(C__bindgen_ty_1__bindgen_ty_2)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mStepSyntax) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(C__bindgen_ty_1__bindgen_ty_2), - "::", stringify!(mStepSyntax)) + unsafe { ::std::ptr::addr_of!((*ptr).mStepSyntax) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(mStepSyntax), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mSteps) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(C__bindgen_ty_1__bindgen_ty_2), "::", - stringify!(mSteps)) + unsafe { ::std::ptr::addr_of!((*ptr).mSteps) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(mSteps), + ), ); } impl Clone for C__bindgen_ty_1__bindgen_ty_2 { @@ -334,17 +384,24 @@ fn bindgen_test_layout_C__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < C__bindgen_ty_1 > (), 16usize, concat!("Size of: ", - stringify!(C__bindgen_ty_1)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(C__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < C__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", - stringify!(C__bindgen_ty_1)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(C__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mFunc) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(C__bindgen_ty_1), "::", - stringify!(mFunc)) + unsafe { ::std::ptr::addr_of!((*ptr).mFunc) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C__bindgen_ty_1), + "::", + stringify!(mFunc), + ), ); } impl Clone for C__bindgen_ty_1 { @@ -363,20 +420,24 @@ fn bindgen_test_layout_C_Segment() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < C_Segment > (), 8usize, concat!("Size of: ", - stringify!(C_Segment)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(C_Segment)), ); assert_eq!( - ::std::mem::align_of:: < C_Segment > (), 4usize, concat!("Alignment of ", - stringify!(C_Segment)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(C_Segment)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).begin) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(C_Segment), "::", stringify!(begin)) + unsafe { ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(C_Segment), "::", stringify!(begin)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).end) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(C_Segment), "::", stringify!(end)) + unsafe { ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(C_Segment), "::", stringify!(end)), ); } impl Clone for C_Segment { @@ -388,15 +449,16 @@ impl Clone for C_Segment { 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::(), 20usize, concat!("Size of: ", stringify!(C))); assert_eq!( - ::std::mem::size_of:: < C > (), 20usize, concat!("Size of: ", stringify!(C)) - ); - assert_eq!( - ::std::mem::align_of:: < C > (), 4usize, concat!("Alignment of ", stringify!(C)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(C)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).d) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(d)) + unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(d)), ); } impl Clone for C { diff --git a/bindgen-tests/tests/expectations/tests/class_with_typedef.rs b/bindgen-tests/tests/expectations/tests/class_with_typedef.rs index e2e8d9e99e..ca9ea56ec4 100644 --- a/bindgen-tests/tests/expectations/tests/class_with_typedef.rs +++ b/bindgen-tests/tests/expectations/tests/class_with_typedef.rs @@ -15,31 +15,36 @@ pub type C_Lookup = *const ::std::os::raw::c_char; 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::(), 72usize, concat!("Size of: ", stringify!(C))); assert_eq!( - ::std::mem::size_of:: < C > (), 72usize, concat!("Size of: ", stringify!(C)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(C)), ); assert_eq!( - ::std::mem::align_of:: < C > (), 8usize, concat!("Alignment of ", stringify!(C)) + unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(c)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).c) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(c)) + unsafe { ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize }, + 8usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(ptr)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).ptr) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(ptr)) + unsafe { ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize }, + 16usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(arr)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).arr) as usize - ptr as usize }, 16usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(arr)) + unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, + 56usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(d)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).d) as usize - ptr as usize }, 56usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(d)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).other_ptr) as usize - ptr as usize }, - 64usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(other_ptr)) + unsafe { ::std::ptr::addr_of!((*ptr).other_ptr) as usize - ptr as usize }, + 64usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(other_ptr)), ); } extern "C" { @@ -95,15 +100,16 @@ pub struct D { 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::(), 80usize, concat!("Size of: ", stringify!(D))); assert_eq!( - ::std::mem::size_of:: < D > (), 80usize, concat!("Size of: ", stringify!(D)) - ); - assert_eq!( - ::std::mem::align_of:: < D > (), 8usize, concat!("Alignment of ", stringify!(D)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(D)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).ptr) as usize - ptr as usize }, 72usize, - concat!("Offset of field: ", stringify!(D), "::", stringify!(ptr)) + unsafe { ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize }, + 72usize, + concat!("Offset of field: ", stringify!(D), "::", stringify!(ptr)), ); } impl Default for D { diff --git a/bindgen-tests/tests/expectations/tests/comment-indent.rs b/bindgen-tests/tests/expectations/tests/comment-indent.rs index a99269fcf2..95fe892768 100644 --- a/bindgen-tests/tests/expectations/tests/comment-indent.rs +++ b/bindgen-tests/tests/expectations/tests/comment-indent.rs @@ -22,23 +22,27 @@ pub mod root { #[test] fn bindgen_test_layout_Foo_Bar() { assert_eq!( - ::std::mem::size_of:: < Foo_Bar > (), 1usize, concat!("Size of: ", - stringify!(Foo_Bar)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo_Bar)), ); assert_eq!( - ::std::mem::align_of:: < Foo_Bar > (), 1usize, concat!("Alignment of ", - stringify!(Foo_Bar)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo_Bar)), ); } #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", - stringify!(Foo)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo)), ); assert_eq!( - ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", - stringify!(Foo)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)), ); } pub mod test { @@ -63,17 +67,19 @@ pub mod root { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < Baz > (), 4usize, concat!("Size of: ", - stringify!(Baz)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Baz)), ); assert_eq!( - ::std::mem::align_of:: < Baz > (), 4usize, concat!("Alignment of ", - stringify!(Baz)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Baz)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).member) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(Baz), "::", - stringify!(member)) + unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Baz), "::", stringify!(member)), ); } /** I'm in an inline namespace, and as such I shouldn't get generated inside @@ -87,12 +93,14 @@ pub mod root { #[test] fn bindgen_test_layout_InInlineNS() { assert_eq!( - ::std::mem::size_of:: < InInlineNS > (), 1usize, concat!("Size of: ", - stringify!(InInlineNS)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(InInlineNS)), ); assert_eq!( - ::std::mem::align_of:: < InInlineNS > (), 1usize, - concat!("Alignment of ", stringify!(InInlineNS)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(InInlineNS)), ); } #[repr(C)] @@ -103,12 +111,14 @@ pub mod root { #[test] fn bindgen_test_layout_Bazz() { assert_eq!( - ::std::mem::size_of:: < Bazz > (), 1usize, concat!("Size of: ", - stringify!(Bazz)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Bazz)), ); assert_eq!( - ::std::mem::align_of:: < Bazz > (), 1usize, concat!("Alignment of ", - stringify!(Bazz)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Bazz)), ); } } diff --git a/bindgen-tests/tests/expectations/tests/complex.rs b/bindgen-tests/tests/expectations/tests/complex.rs index 4bf0280da6..7bcc1b9e04 100644 --- a/bindgen-tests/tests/expectations/tests/complex.rs +++ b/bindgen-tests/tests/expectations/tests/complex.rs @@ -15,16 +15,19 @@ fn bindgen_test_layout_TestDouble() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < TestDouble > (), 16usize, concat!("Size of: ", - stringify!(TestDouble)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(TestDouble)), ); assert_eq!( - ::std::mem::align_of:: < TestDouble > (), 8usize, concat!("Alignment of ", - stringify!(TestDouble)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(TestDouble)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mMember) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(TestDouble), "::", stringify!(mMember)) + unsafe { ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(TestDouble), "::", stringify!(mMember)), ); } #[repr(C)] @@ -37,17 +40,24 @@ fn bindgen_test_layout_TestDoublePtr() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < TestDoublePtr > (), 8usize, concat!("Size of: ", - stringify!(TestDoublePtr)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(TestDoublePtr)), ); assert_eq!( - ::std::mem::align_of:: < TestDoublePtr > (), 8usize, concat!("Alignment of ", - stringify!(TestDoublePtr)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(TestDoublePtr)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mMember) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(TestDoublePtr), "::", - stringify!(mMember)) + unsafe { ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(TestDoublePtr), + "::", + stringify!(mMember), + ), ); } impl Default for TestDoublePtr { @@ -69,16 +79,19 @@ fn bindgen_test_layout_TestFloat() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < TestFloat > (), 8usize, concat!("Size of: ", - stringify!(TestFloat)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(TestFloat)), ); assert_eq!( - ::std::mem::align_of:: < TestFloat > (), 4usize, concat!("Alignment of ", - stringify!(TestFloat)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(TestFloat)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mMember) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(TestFloat), "::", stringify!(mMember)) + unsafe { ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(TestFloat), "::", stringify!(mMember)), ); } #[repr(C)] @@ -91,16 +104,19 @@ fn bindgen_test_layout_TestFloatPtr() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < TestFloatPtr > (), 8usize, concat!("Size of: ", - stringify!(TestFloatPtr)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(TestFloatPtr)), ); assert_eq!( - ::std::mem::align_of:: < TestFloatPtr > (), 8usize, concat!("Alignment of ", - stringify!(TestFloatPtr)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(TestFloatPtr)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mMember) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(TestFloatPtr), "::", stringify!(mMember)) + unsafe { ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(TestFloatPtr), "::", stringify!(mMember)), ); } impl Default for TestFloatPtr { diff --git a/bindgen-tests/tests/expectations/tests/const-const-mut-ptr.rs b/bindgen-tests/tests/expectations/tests/const-const-mut-ptr.rs index 374b5194ae..e165b8de9b 100644 --- a/bindgen-tests/tests/expectations/tests/const-const-mut-ptr.rs +++ b/bindgen-tests/tests/expectations/tests/const-const-mut-ptr.rs @@ -9,15 +9,19 @@ 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:: < foo > (), 8usize, concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(foo)), ); assert_eq!( - ::std::mem::align_of:: < foo > (), 8usize, concat!("Alignment of ", - stringify!(foo)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)), ); } impl Default for foo { diff --git a/bindgen-tests/tests/expectations/tests/const_enum_unnamed.rs b/bindgen-tests/tests/expectations/tests/const_enum_unnamed.rs index 0c3462dc47..3648a48e28 100644 --- a/bindgen-tests/tests/expectations/tests/const_enum_unnamed.rs +++ b/bindgen-tests/tests/expectations/tests/const_enum_unnamed.rs @@ -21,10 +21,13 @@ pub enum Foo__bindgen_ty_1 { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo)), ); assert_eq!( - ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", - stringify!(Foo)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)), ); } diff --git a/bindgen-tests/tests/expectations/tests/constified-enum-module-overflow.rs b/bindgen-tests/tests/expectations/tests/constified-enum-module-overflow.rs index 67c8fa9746..49498deaa5 100644 --- a/bindgen-tests/tests/expectations/tests/constified-enum-module-overflow.rs +++ b/bindgen-tests/tests/expectations/tests/constified-enum-module-overflow.rs @@ -19,25 +19,28 @@ pub struct A { 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::(), 1usize, concat!("Size of: ", stringify!(A))); assert_eq!( - ::std::mem::size_of:: < A > (), 1usize, concat!("Size of: ", stringify!(A)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(A)), ); assert_eq!( - ::std::mem::align_of:: < A > (), 1usize, concat!("Alignment of ", stringify!(A)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).u) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(u)) + unsafe { ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(A), "::", stringify!(u)), ); } #[test] fn __bindgen_test_layout_C_open0_A_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < C > (), 1usize, - concat!("Size of template specialization: ", stringify!(C)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of template specialization: ", stringify!(C)), ); assert_eq!( - ::std::mem::align_of:: < C > (), 1usize, - concat!("Alignment of template specialization: ", stringify!(C)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of template specialization: ", stringify!(C)), ); } diff --git a/bindgen-tests/tests/expectations/tests/constify-all-enums.rs b/bindgen-tests/tests/expectations/tests/constify-all-enums.rs index 6e2a1963c6..de5d949283 100644 --- a/bindgen-tests/tests/expectations/tests/constify-all-enums.rs +++ b/bindgen-tests/tests/expectations/tests/constify-all-enums.rs @@ -13,16 +13,19 @@ 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:: < bar > (), 4usize, concat!("Size of: ", stringify!(bar)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(bar)), ); assert_eq!( - ::std::mem::align_of:: < bar > (), 4usize, concat!("Alignment of ", - stringify!(bar)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(bar)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).this_should_work) as usize - ptr as usize - }, 0usize, concat!("Offset of field: ", stringify!(bar), "::", - stringify!(this_should_work)) + unsafe { ::std::ptr::addr_of!((*ptr).this_should_work) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(bar), "::", stringify!(this_should_work)), ); } impl Default for bar { diff --git a/bindgen-tests/tests/expectations/tests/constify-module-enums-basic.rs b/bindgen-tests/tests/expectations/tests/constify-module-enums-basic.rs index cce1da523b..7f0ea58101 100644 --- a/bindgen-tests/tests/expectations/tests/constify-module-enums-basic.rs +++ b/bindgen-tests/tests/expectations/tests/constify-module-enums-basic.rs @@ -17,16 +17,19 @@ 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:: < bar > (), 4usize, concat!("Size of: ", stringify!(bar)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(bar)), ); assert_eq!( - ::std::mem::align_of:: < bar > (), 4usize, concat!("Alignment of ", - stringify!(bar)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(bar)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).this_should_work) as usize - ptr as usize - }, 0usize, concat!("Offset of field: ", stringify!(bar), "::", - stringify!(this_should_work)) + unsafe { ::std::ptr::addr_of!((*ptr).this_should_work) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(bar), "::", stringify!(this_should_work)), ); } impl Default for bar { diff --git a/bindgen-tests/tests/expectations/tests/constify-module-enums-namespace.rs b/bindgen-tests/tests/expectations/tests/constify-module-enums-namespace.rs index e2634dbf22..d8faac4fa3 100644 --- a/bindgen-tests/tests/expectations/tests/constify-module-enums-namespace.rs +++ b/bindgen-tests/tests/expectations/tests/constify-module-enums-namespace.rs @@ -29,17 +29,27 @@ pub mod root { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < bar > (), 4usize, concat!("Size of: ", - stringify!(bar)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(bar)), ); assert_eq!( - ::std::mem::align_of:: < bar > (), 4usize, concat!("Alignment of ", - stringify!(bar)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(bar)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).this_should_work) as usize - - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(bar), - "::", stringify!(this_should_work)) + unsafe { + ::std::ptr::addr_of!((*ptr).this_should_work) as usize + - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(bar), + "::", + stringify!(this_should_work), + ), ); } impl Default for bar { diff --git a/bindgen-tests/tests/expectations/tests/constify-module-enums-shadow-name.rs b/bindgen-tests/tests/expectations/tests/constify-module-enums-shadow-name.rs index 464a2d0631..4780df6841 100644 --- a/bindgen-tests/tests/expectations/tests/constify-module-enums-shadow-name.rs +++ b/bindgen-tests/tests/expectations/tests/constify-module-enums-shadow-name.rs @@ -16,15 +16,19 @@ 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:: < bar > (), 4usize, concat!("Size of: ", stringify!(bar)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(bar)), ); assert_eq!( - ::std::mem::align_of:: < bar > (), 4usize, concat!("Alignment of ", - stringify!(bar)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(bar)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).member) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(bar), "::", stringify!(member)) + unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(bar), "::", stringify!(member)), ); } impl Default for bar { diff --git a/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-alias.rs b/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-alias.rs index 38feeb651c..791f2b3054 100644 --- a/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-alias.rs +++ b/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-alias.rs @@ -25,47 +25,54 @@ 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:: < Bar > (), 48usize, concat!("Size of: ", stringify!(Bar)) + ::std::mem::size_of::(), + 48usize, + concat!("Size of: ", stringify!(Bar)), ); assert_eq!( - ::std::mem::align_of:: < Bar > (), 8usize, concat!("Alignment of ", - stringify!(Bar)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Bar)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).baz1) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz1)) + unsafe { ::std::ptr::addr_of!((*ptr).baz1) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).baz2) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz2)) + unsafe { ::std::ptr::addr_of!((*ptr).baz2) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz2)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).baz3) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz3)) + unsafe { ::std::ptr::addr_of!((*ptr).baz3) as usize - ptr as usize }, + 8usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz3)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).baz4) as usize - ptr as usize }, 12usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz4)) + unsafe { ::std::ptr::addr_of!((*ptr).baz4) as usize - ptr as usize }, + 12usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz4)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).baz_ptr1) as usize - ptr as usize }, - 16usize, concat!("Offset of field: ", stringify!(Bar), "::", - stringify!(baz_ptr1)) + unsafe { ::std::ptr::addr_of!((*ptr).baz_ptr1) as usize - ptr as usize }, + 16usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz_ptr1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).baz_ptr2) as usize - ptr as usize }, - 24usize, concat!("Offset of field: ", stringify!(Bar), "::", - stringify!(baz_ptr2)) + unsafe { ::std::ptr::addr_of!((*ptr).baz_ptr2) as usize - ptr as usize }, + 24usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz_ptr2)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).baz_ptr3) as usize - ptr as usize }, - 32usize, concat!("Offset of field: ", stringify!(Bar), "::", - stringify!(baz_ptr3)) + unsafe { ::std::ptr::addr_of!((*ptr).baz_ptr3) as usize - ptr as usize }, + 32usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz_ptr3)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).baz_ptr4) as usize - ptr as usize }, - 40usize, concat!("Offset of field: ", stringify!(Bar), "::", - stringify!(baz_ptr4)) + unsafe { ::std::ptr::addr_of!((*ptr).baz_ptr4) as usize - ptr as usize }, + 40usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz_ptr4)), ); } impl Default for Bar { diff --git a/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs b/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs index fd629d86fd..363768a0d0 100644 --- a/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs +++ b/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs @@ -15,19 +15,24 @@ 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:: < Bar > (), 16usize, concat!("Size of: ", stringify!(Bar)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(Bar)), ); assert_eq!( - ::std::mem::align_of:: < Bar > (), 8usize, concat!("Alignment of ", - stringify!(Bar)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Bar)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).baz1) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz1)) + unsafe { ::std::ptr::addr_of!((*ptr).baz1) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).baz2) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz2)) + unsafe { ::std::ptr::addr_of!((*ptr).baz2) as usize - ptr as usize }, + 8usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz2)), ); } impl Default for Bar { diff --git a/bindgen-tests/tests/expectations/tests/constify-module-enums-types.rs b/bindgen-tests/tests/expectations/tests/constify-module-enums-types.rs index 610024b358..687deb45c1 100644 --- a/bindgen-tests/tests/expectations/tests/constify-module-enums-types.rs +++ b/bindgen-tests/tests/expectations/tests/constify-module-enums-types.rs @@ -50,52 +50,64 @@ 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:: < bar > (), 48usize, concat!("Size of: ", stringify!(bar)) + ::std::mem::size_of::(), + 48usize, + concat!("Size of: ", stringify!(bar)), ); assert_eq!( - ::std::mem::align_of:: < bar > (), 8usize, concat!("Alignment of ", - stringify!(bar)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(bar)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).member1) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(bar), "::", stringify!(member1)) + unsafe { ::std::ptr::addr_of!((*ptr).member1) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(bar), "::", stringify!(member1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).member2) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(bar), "::", stringify!(member2)) + unsafe { ::std::ptr::addr_of!((*ptr).member2) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(bar), "::", stringify!(member2)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).member3) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(bar), "::", stringify!(member3)) + unsafe { ::std::ptr::addr_of!((*ptr).member3) as usize - ptr as usize }, + 8usize, + concat!("Offset of field: ", stringify!(bar), "::", stringify!(member3)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).member4) as usize - ptr as usize }, - 12usize, concat!("Offset of field: ", stringify!(bar), "::", stringify!(member4)) + unsafe { ::std::ptr::addr_of!((*ptr).member4) as usize - ptr as usize }, + 12usize, + concat!("Offset of field: ", stringify!(bar), "::", stringify!(member4)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).member5) as usize - ptr as usize }, - 16usize, concat!("Offset of field: ", stringify!(bar), "::", stringify!(member5)) + unsafe { ::std::ptr::addr_of!((*ptr).member5) as usize - ptr as usize }, + 16usize, + concat!("Offset of field: ", stringify!(bar), "::", stringify!(member5)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).member6) as usize - ptr as usize }, - 24usize, concat!("Offset of field: ", stringify!(bar), "::", stringify!(member6)) + unsafe { ::std::ptr::addr_of!((*ptr).member6) as usize - ptr as usize }, + 24usize, + concat!("Offset of field: ", stringify!(bar), "::", stringify!(member6)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).member7) as usize - ptr as usize }, - 32usize, concat!("Offset of field: ", stringify!(bar), "::", stringify!(member7)) + unsafe { ::std::ptr::addr_of!((*ptr).member7) as usize - ptr as usize }, + 32usize, + concat!("Offset of field: ", stringify!(bar), "::", stringify!(member7)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).member8) as usize - ptr as usize }, - 36usize, concat!("Offset of field: ", stringify!(bar), "::", stringify!(member8)) + unsafe { ::std::ptr::addr_of!((*ptr).member8) as usize - ptr as usize }, + 36usize, + concat!("Offset of field: ", stringify!(bar), "::", stringify!(member8)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).member9) as usize - ptr as usize }, - 40usize, concat!("Offset of field: ", stringify!(bar), "::", stringify!(member9)) + unsafe { ::std::ptr::addr_of!((*ptr).member9) as usize - ptr as usize }, + 40usize, + concat!("Offset of field: ", stringify!(bar), "::", stringify!(member9)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).member10) as usize - ptr as usize }, - 44usize, concat!("Offset of field: ", stringify!(bar), "::", - stringify!(member10)) + unsafe { ::std::ptr::addr_of!((*ptr).member10) as usize - ptr as usize }, + 44usize, + concat!("Offset of field: ", stringify!(bar), "::", stringify!(member10)), ); } impl Default for bar { @@ -117,15 +129,19 @@ 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:: < Baz > (), 4usize, concat!("Size of: ", stringify!(Baz)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Baz)), ); assert_eq!( - ::std::mem::align_of:: < Baz > (), 4usize, concat!("Alignment of ", - stringify!(Baz)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Baz)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).member1) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Baz), "::", stringify!(member1)) + unsafe { ::std::ptr::addr_of!((*ptr).member1) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Baz), "::", stringify!(member1)), ); } impl Default for Baz { @@ -152,15 +168,19 @@ 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:: < Bar > (), 8usize, concat!("Size of: ", stringify!(Bar)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Bar)), ); assert_eq!( - ::std::mem::align_of:: < Bar > (), 8usize, concat!("Alignment of ", - stringify!(Bar)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Bar)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).baz) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz)) + unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz)), ); } impl Default for Bar { diff --git a/bindgen-tests/tests/expectations/tests/constructor-tp.rs b/bindgen-tests/tests/expectations/tests/constructor-tp.rs index 1275aa2087..5f3be0b4d9 100644 --- a/bindgen-tests/tests/expectations/tests/constructor-tp.rs +++ b/bindgen-tests/tests/expectations/tests/constructor-tp.rs @@ -12,11 +12,14 @@ pub struct Bar { #[test] fn bindgen_test_layout_Bar() { assert_eq!( - ::std::mem::size_of:: < Bar > (), 1usize, concat!("Size of: ", stringify!(Bar)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Bar)), ); assert_eq!( - ::std::mem::align_of:: < Bar > (), 1usize, concat!("Alignment of ", - stringify!(Bar)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Bar)), ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/constructors.rs b/bindgen-tests/tests/expectations/tests/constructors.rs index 56041394df..75c05d3050 100644 --- a/bindgen-tests/tests/expectations/tests/constructors.rs +++ b/bindgen-tests/tests/expectations/tests/constructors.rs @@ -7,12 +7,14 @@ pub struct TestOverload { #[test] fn bindgen_test_layout_TestOverload() { assert_eq!( - ::std::mem::size_of:: < TestOverload > (), 1usize, concat!("Size of: ", - stringify!(TestOverload)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(TestOverload)), ); assert_eq!( - ::std::mem::align_of:: < TestOverload > (), 1usize, concat!("Alignment of ", - stringify!(TestOverload)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(TestOverload)), ); } extern "C" { @@ -48,12 +50,14 @@ pub struct TestPublicNoArgs { #[test] fn bindgen_test_layout_TestPublicNoArgs() { assert_eq!( - ::std::mem::size_of:: < TestPublicNoArgs > (), 1usize, concat!("Size of: ", - stringify!(TestPublicNoArgs)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(TestPublicNoArgs)), ); assert_eq!( - ::std::mem::align_of:: < TestPublicNoArgs > (), 1usize, concat!("Alignment of ", - stringify!(TestPublicNoArgs)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(TestPublicNoArgs)), ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/constructors_1_33.rs b/bindgen-tests/tests/expectations/tests/constructors_1_33.rs index 36b9b1a357..5d523e848e 100644 --- a/bindgen-tests/tests/expectations/tests/constructors_1_33.rs +++ b/bindgen-tests/tests/expectations/tests/constructors_1_33.rs @@ -7,12 +7,14 @@ pub struct TestOverload { #[test] fn bindgen_test_layout_TestOverload() { assert_eq!( - ::std::mem::size_of:: < TestOverload > (), 1usize, concat!("Size of: ", - stringify!(TestOverload)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(TestOverload)), ); assert_eq!( - ::std::mem::align_of:: < TestOverload > (), 1usize, concat!("Alignment of ", - stringify!(TestOverload)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(TestOverload)), ); } extern "C" { @@ -50,12 +52,14 @@ pub struct TestPublicNoArgs { #[test] fn bindgen_test_layout_TestPublicNoArgs() { assert_eq!( - ::std::mem::size_of:: < TestPublicNoArgs > (), 1usize, concat!("Size of: ", - stringify!(TestPublicNoArgs)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(TestPublicNoArgs)), ); assert_eq!( - ::std::mem::align_of:: < TestPublicNoArgs > (), 1usize, concat!("Alignment of ", - stringify!(TestPublicNoArgs)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(TestPublicNoArgs)), ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/contains-vs-inherits-zero-sized.rs b/bindgen-tests/tests/expectations/tests/contains-vs-inherits-zero-sized.rs index 30da3eb3b5..70a4180757 100644 --- a/bindgen-tests/tests/expectations/tests/contains-vs-inherits-zero-sized.rs +++ b/bindgen-tests/tests/expectations/tests/contains-vs-inherits-zero-sized.rs @@ -8,12 +8,14 @@ pub struct Empty { #[test] fn bindgen_test_layout_Empty() { assert_eq!( - ::std::mem::size_of:: < Empty > (), 1usize, concat!("Size of: ", - stringify!(Empty)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Empty)), ); assert_eq!( - ::std::mem::align_of:: < Empty > (), 1usize, concat!("Alignment of ", - stringify!(Empty)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Empty)), ); } /** This should not get an `_address` byte, so `sizeof(Inherits)` should be @@ -28,16 +30,19 @@ fn bindgen_test_layout_Inherits() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < Inherits > (), 1usize, concat!("Size of: ", - stringify!(Inherits)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Inherits)), ); assert_eq!( - ::std::mem::align_of:: < Inherits > (), 1usize, concat!("Alignment of ", - stringify!(Inherits)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Inherits)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Inherits), "::", stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Inherits), "::", stringify!(b)), ); } /** This should not get an `_address` byte, but contains `Empty` which *does* get @@ -53,19 +58,23 @@ fn bindgen_test_layout_Contains() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < Contains > (), 2usize, concat!("Size of: ", - stringify!(Contains)) + ::std::mem::size_of::(), + 2usize, + concat!("Size of: ", stringify!(Contains)), ); assert_eq!( - ::std::mem::align_of:: < Contains > (), 1usize, concat!("Alignment of ", - stringify!(Contains)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Contains)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).empty) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Contains), "::", stringify!(empty)) + unsafe { ::std::ptr::addr_of!((*ptr).empty) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Contains), "::", stringify!(empty)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 1usize, - concat!("Offset of field: ", stringify!(Contains), "::", stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 1usize, + concat!("Offset of field: ", stringify!(Contains), "::", stringify!(b)), ); } diff --git a/bindgen-tests/tests/expectations/tests/convert-floats.rs b/bindgen-tests/tests/expectations/tests/convert-floats.rs index 63f3e755d9..3f45f76f5d 100644 --- a/bindgen-tests/tests/expectations/tests/convert-floats.rs +++ b/bindgen-tests/tests/expectations/tests/convert-floats.rs @@ -20,37 +20,44 @@ 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:: < foo > (), 48usize, concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of::(), + 48usize, + concat!("Size of: ", stringify!(foo)), ); assert_eq!( - ::std::mem::align_of:: < foo > (), 8usize, concat!("Alignment of ", - stringify!(foo)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).baz) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(baz)) + unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(baz)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).bazz) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bazz)) + unsafe { ::std::ptr::addr_of!((*ptr).bazz) as usize - ptr as usize }, + 8usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(bazz)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).bazzz) as usize - ptr as usize }, 16usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bazzz)) + unsafe { ::std::ptr::addr_of!((*ptr).bazzz) as usize - ptr as usize }, + 16usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(bazzz)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).complexFloat) as usize - ptr as usize }, - 24usize, concat!("Offset of field: ", stringify!(foo), "::", - stringify!(complexFloat)) + unsafe { ::std::ptr::addr_of!((*ptr).complexFloat) as usize - ptr as usize }, + 24usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(complexFloat)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).complexDouble) as usize - ptr as usize }, - 32usize, concat!("Offset of field: ", stringify!(foo), "::", - stringify!(complexDouble)) + unsafe { ::std::ptr::addr_of!((*ptr).complexDouble) as usize - ptr as usize }, + 32usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(complexDouble)), ); } impl Default for foo { diff --git a/bindgen-tests/tests/expectations/tests/cpp-empty-layout.rs b/bindgen-tests/tests/expectations/tests/cpp-empty-layout.rs index d16596b591..d51ccfa80c 100644 --- a/bindgen-tests/tests/expectations/tests/cpp-empty-layout.rs +++ b/bindgen-tests/tests/expectations/tests/cpp-empty-layout.rs @@ -7,10 +7,13 @@ pub struct Foo { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo)), ); assert_eq!( - ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", - stringify!(Foo)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)), ); } diff --git a/bindgen-tests/tests/expectations/tests/crtp.rs b/bindgen-tests/tests/expectations/tests/crtp.rs index 08931f8893..6a953d7704 100644 --- a/bindgen-tests/tests/expectations/tests/crtp.rs +++ b/bindgen-tests/tests/expectations/tests/crtp.rs @@ -12,12 +12,14 @@ pub struct Derived { #[test] fn bindgen_test_layout_Derived() { assert_eq!( - ::std::mem::size_of:: < Derived > (), 1usize, concat!("Size of: ", - stringify!(Derived)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Derived)), ); assert_eq!( - ::std::mem::align_of:: < Derived > (), 1usize, concat!("Alignment of ", - stringify!(Derived)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Derived)), ); } #[repr(C)] @@ -33,33 +35,39 @@ pub struct DerivedFromBaseWithDestructor { #[test] fn bindgen_test_layout_DerivedFromBaseWithDestructor() { assert_eq!( - ::std::mem::size_of:: < DerivedFromBaseWithDestructor > (), 1usize, - concat!("Size of: ", stringify!(DerivedFromBaseWithDestructor)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(DerivedFromBaseWithDestructor)), ); assert_eq!( - ::std::mem::align_of:: < DerivedFromBaseWithDestructor > (), 1usize, - concat!("Alignment of ", stringify!(DerivedFromBaseWithDestructor)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(DerivedFromBaseWithDestructor)), ); } #[test] fn __bindgen_test_layout_Base_open0_Derived_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < Base > (), 1usize, - concat!("Size of template specialization: ", stringify!(Base)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of template specialization: ", stringify!(Base)), ); assert_eq!( - ::std::mem::align_of:: < Base > (), 1usize, - concat!("Alignment of template specialization: ", stringify!(Base)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of template specialization: ", stringify!(Base)), ); } #[test] fn __bindgen_test_layout_BaseWithDestructor_open0_DerivedFromBaseWithDestructor_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < BaseWithDestructor > (), 1usize, - concat!("Size of template specialization: ", stringify!(BaseWithDestructor)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of template specialization: ", stringify!(BaseWithDestructor)), ); assert_eq!( - ::std::mem::align_of:: < BaseWithDestructor > (), 1usize, - concat!("Alignment of template specialization: ", stringify!(BaseWithDestructor)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of template specialization: ", stringify!(BaseWithDestructor)), ); } diff --git a/bindgen-tests/tests/expectations/tests/ctypes-prefix-path.rs b/bindgen-tests/tests/expectations/tests/ctypes-prefix-path.rs index 834bc77504..c2da364afa 100644 --- a/bindgen-tests/tests/expectations/tests/ctypes-prefix-path.rs +++ b/bindgen-tests/tests/expectations/tests/ctypes-prefix-path.rs @@ -18,23 +18,29 @@ fn bindgen_test_layout_foo() { const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::core::mem::size_of:: < foo > (), 16usize, concat!("Size of: ", stringify!(foo)) + ::core::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(foo)), ); assert_eq!( - ::core::mem::align_of:: < foo > (), 8usize, concat!("Alignment of ", - stringify!(foo)) + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(foo)), ); assert_eq!( - unsafe { ::core::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) + unsafe { ::core::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)), ); assert_eq!( - unsafe { ::core::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) + unsafe { ::core::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)), ); assert_eq!( - unsafe { ::core::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) + unsafe { ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, + 8usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)), ); } impl Default for foo { diff --git a/bindgen-tests/tests/expectations/tests/default-template-parameter.rs b/bindgen-tests/tests/expectations/tests/default-template-parameter.rs index 4ed8c18bdc..dc279e3d90 100644 --- a/bindgen-tests/tests/expectations/tests/default-template-parameter.rs +++ b/bindgen-tests/tests/expectations/tests/default-template-parameter.rs @@ -19,14 +19,20 @@ impl Default for Foo { #[test] fn __bindgen_test_layout_Foo_open0_bool__int_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < Foo < bool, ::std::os::raw::c_int > > (), 8usize, - concat!("Size of template specialization: ", stringify!(Foo < bool, - ::std::os::raw::c_int >)) + ::std::mem::size_of::>(), + 8usize, + concat!( + "Size of template specialization: ", + stringify!(Foo < bool, ::std::os::raw::c_int >), + ), ); assert_eq!( - ::std::mem::align_of:: < Foo < bool, ::std::os::raw::c_int > > (), 4usize, - concat!("Alignment of template specialization: ", stringify!(Foo < bool, - ::std::os::raw::c_int >)) + ::std::mem::align_of::>(), + 4usize, + concat!( + "Alignment of template specialization: ", + stringify!(Foo < bool, ::std::os::raw::c_int >), + ), ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/default_visibility_crate.rs b/bindgen-tests/tests/expectations/tests/default_visibility_crate.rs index a3131a1bae..f75a06e984 100644 --- a/bindgen-tests/tests/expectations/tests/default_visibility_crate.rs +++ b/bindgen-tests/tests/expectations/tests/default_visibility_crate.rs @@ -49,7 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -69,7 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; diff --git a/bindgen-tests/tests/expectations/tests/default_visibility_private.rs b/bindgen-tests/tests/expectations/tests/default_visibility_private.rs index 280b6b69d9..9bd6409f4f 100644 --- a/bindgen-tests/tests/expectations/tests/default_visibility_private.rs +++ b/bindgen-tests/tests/expectations/tests/default_visibility_private.rs @@ -49,7 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -69,7 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; diff --git a/bindgen-tests/tests/expectations/tests/default_visibility_private_respects_cxx_access_spec.rs b/bindgen-tests/tests/expectations/tests/default_visibility_private_respects_cxx_access_spec.rs index 453a3054ae..a8b0d29733 100644 --- a/bindgen-tests/tests/expectations/tests/default_visibility_private_respects_cxx_access_spec.rs +++ b/bindgen-tests/tests/expectations/tests/default_visibility_private_respects_cxx_access_spec.rs @@ -49,7 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -69,7 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; diff --git a/bindgen-tests/tests/expectations/tests/deleted-function.rs b/bindgen-tests/tests/expectations/tests/deleted-function.rs index 03d5a8f0f1..3d29bd872c 100644 --- a/bindgen-tests/tests/expectations/tests/deleted-function.rs +++ b/bindgen-tests/tests/expectations/tests/deleted-function.rs @@ -6,11 +6,11 @@ pub struct A { } #[test] fn bindgen_test_layout_A() { + assert_eq!(::std::mem::size_of::(), 1usize, concat!("Size of: ", stringify!(A))); assert_eq!( - ::std::mem::size_of:: < A > (), 1usize, concat!("Size of: ", stringify!(A)) - ); - assert_eq!( - ::std::mem::align_of:: < A > (), 1usize, concat!("Alignment of ", stringify!(A)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(A)), ); } extern "C" { @@ -38,11 +38,11 @@ pub struct B { } #[test] fn bindgen_test_layout_B() { + assert_eq!(::std::mem::size_of::(), 1usize, concat!("Size of: ", stringify!(B))); assert_eq!( - ::std::mem::size_of:: < B > (), 1usize, concat!("Size of: ", stringify!(B)) - ); - assert_eq!( - ::std::mem::align_of:: < B > (), 1usize, concat!("Alignment of ", stringify!(B)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(B)), ); } #[repr(C)] @@ -52,11 +52,11 @@ pub struct C { } #[test] fn bindgen_test_layout_C() { + assert_eq!(::std::mem::size_of::(), 1usize, concat!("Size of: ", stringify!(C))); assert_eq!( - ::std::mem::size_of:: < C > (), 1usize, concat!("Size of: ", stringify!(C)) - ); - assert_eq!( - ::std::mem::align_of:: < C > (), 1usize, concat!("Alignment of ", stringify!(C)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(C)), ); } extern "C" { 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 ec68b474d3..e3236f58fe 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 @@ -49,7 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -69,7 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -99,15 +99,19 @@ 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:: < Foo > (), 136usize, concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of::(), + 136usize, + concat!("Size of: ", stringify!(Foo)), ); assert_eq!( - ::std::mem::align_of:: < Foo > (), 4usize, concat!("Alignment of ", - stringify!(Foo)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).large) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(large)) + unsafe { ::std::ptr::addr_of!((*ptr).large) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(large)), ); } extern "C" { @@ -134,9 +138,15 @@ 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_ : {:?}, }}", self.large.iter().enumerate() - .map(| (i, v) | format!("{}{:?}", if i > 0 { ", " } else { "" }, v)) - .collect:: < String > (), self.type__bindgen_bitfield() + f, + "Foo {{ large: [{}], type_ : {:?}, }}", + self + .large + .iter() + .enumerate() + .map(|(i, v)| format!("{}{:?}", if i > 0 { ", " } else { "" }, v)) + .collect::(), + self.type__bindgen_bitfield(), ) } } diff --git a/bindgen-tests/tests/expectations/tests/derive-clone.rs b/bindgen-tests/tests/expectations/tests/derive-clone.rs index ecb9ebadc0..b11287453c 100644 --- a/bindgen-tests/tests/expectations/tests/derive-clone.rs +++ b/bindgen-tests/tests/expectations/tests/derive-clone.rs @@ -10,17 +10,24 @@ 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:: < ShouldDeriveClone > (), 132usize, concat!("Size of: ", - stringify!(ShouldDeriveClone)) + ::std::mem::size_of::(), + 132usize, + concat!("Size of: ", stringify!(ShouldDeriveClone)), ); assert_eq!( - ::std::mem::align_of:: < ShouldDeriveClone > (), 4usize, concat!("Alignment of ", - stringify!(ShouldDeriveClone)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(ShouldDeriveClone)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).large) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(ShouldDeriveClone), "::", - stringify!(large)) + unsafe { ::std::ptr::addr_of!((*ptr).large) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ShouldDeriveClone), + "::", + stringify!(large), + ), ); } impl Default for ShouldDeriveClone { diff --git a/bindgen-tests/tests/expectations/tests/derive-clone_1_0.rs b/bindgen-tests/tests/expectations/tests/derive-clone_1_0.rs index 59b26c9922..2702c94793 100644 --- a/bindgen-tests/tests/expectations/tests/derive-clone_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/derive-clone_1_0.rs @@ -11,17 +11,24 @@ fn bindgen_test_layout_ShouldImplClone() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < ShouldImplClone > (), 132usize, concat!("Size of: ", - stringify!(ShouldImplClone)) + ::std::mem::size_of::(), + 132usize, + concat!("Size of: ", stringify!(ShouldImplClone)), ); assert_eq!( - ::std::mem::align_of:: < ShouldImplClone > (), 4usize, concat!("Alignment of ", - stringify!(ShouldImplClone)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(ShouldImplClone)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).large) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(ShouldImplClone), "::", - stringify!(large)) + unsafe { ::std::ptr::addr_of!((*ptr).large) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ShouldImplClone), + "::", + stringify!(large), + ), ); } impl Clone for ShouldImplClone { diff --git a/bindgen-tests/tests/expectations/tests/derive-custom-cli.rs b/bindgen-tests/tests/expectations/tests/derive-custom-cli.rs index 710dc6890f..5784684556 100644 --- a/bindgen-tests/tests/expectations/tests/derive-custom-cli.rs +++ b/bindgen-tests/tests/expectations/tests/derive-custom-cli.rs @@ -9,16 +9,19 @@ fn bindgen_test_layout_foo_struct() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < foo_struct > (), 4usize, concat!("Size of: ", - stringify!(foo_struct)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo_struct)), ); assert_eq!( - ::std::mem::align_of:: < foo_struct > (), 4usize, concat!("Alignment of ", - stringify!(foo_struct)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo_struct)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).inner) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo_struct), "::", stringify!(inner)) + unsafe { ::std::ptr::addr_of!((*ptr).inner) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo_struct), "::", stringify!(inner)), ); } #[repr(u32)] @@ -37,20 +40,24 @@ fn bindgen_test_layout_foo_union() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < foo_union > (), 4usize, concat!("Size of: ", - stringify!(foo_union)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo_union)), ); assert_eq!( - ::std::mem::align_of:: < foo_union > (), 4usize, concat!("Alignment of ", - stringify!(foo_union)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo_union)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).fst) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo_union), "::", stringify!(fst)) + unsafe { ::std::ptr::addr_of!((*ptr).fst) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo_union), "::", stringify!(fst)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).snd) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo_union), "::", stringify!(snd)) + unsafe { ::std::ptr::addr_of!((*ptr).snd) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo_union), "::", stringify!(snd)), ); } #[repr(C)] @@ -62,15 +69,18 @@ fn bindgen_test_layout_non_matching() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < non_matching > (), 4usize, concat!("Size of: ", - stringify!(non_matching)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(non_matching)), ); assert_eq!( - ::std::mem::align_of:: < non_matching > (), 4usize, concat!("Alignment of ", - stringify!(non_matching)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(non_matching)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).inner) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(non_matching), "::", stringify!(inner)) + unsafe { ::std::ptr::addr_of!((*ptr).inner) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(non_matching), "::", stringify!(inner)), ); } 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 17a2d4d582..54b44b33d2 100644 --- a/bindgen-tests/tests/expectations/tests/derive-debug-bitfield-core.rs +++ b/bindgen-tests/tests/expectations/tests/derive-debug-bitfield-core.rs @@ -50,7 +50,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -70,7 +70,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -96,15 +96,19 @@ 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:: < C > (), 204usize, concat!("Size of: ", stringify!(C)) + ::core::mem::size_of::(), + 204usize, + concat!("Size of: ", stringify!(C)), ); assert_eq!( - ::core::mem::align_of:: < C > (), 4usize, concat!("Alignment of ", stringify!(C)) + ::core::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(C)), ); assert_eq!( - unsafe { ::core::ptr::addr_of!((* ptr).large_array) as usize - ptr as usize }, - 4usize, concat!("Offset of field: ", stringify!(C), "::", - stringify!(large_array)) + unsafe { ::core::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(large_array)), ); } impl Default for C { diff --git a/bindgen-tests/tests/expectations/tests/derive-debug-bitfield.rs b/bindgen-tests/tests/expectations/tests/derive-debug-bitfield.rs index 2e10b245ed..828383af4e 100644 --- a/bindgen-tests/tests/expectations/tests/derive-debug-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/derive-debug-bitfield.rs @@ -49,7 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -69,7 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -95,15 +95,19 @@ 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:: < C > (), 204usize, concat!("Size of: ", stringify!(C)) + ::std::mem::size_of::(), + 204usize, + concat!("Size of: ", stringify!(C)), ); assert_eq!( - ::std::mem::align_of:: < C > (), 4usize, concat!("Alignment of ", stringify!(C)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(C)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).large_array) as usize - ptr as usize }, - 4usize, concat!("Offset of field: ", stringify!(C), "::", - stringify!(large_array)) + unsafe { ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(large_array)), ); } impl Default for C { @@ -118,9 +122,16 @@ 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(), self - .large_array.iter().enumerate().map(| (i, v) | format!("{}{:?}", if i > 0 { - ", " } else { "" }, v)).collect:: < String > () + f, + "C {{ a : {:?}, b : {:?}, large_array: [{}] }}", + self.a(), + self.b(), + self + .large_array + .iter() + .enumerate() + .map(|(i, v)| format!("{}{:?}", if i > 0 { ", " } else { "" }, v)) + .collect::(), ) } } 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 085dd95a1f..2ca5a839ed 100644 --- a/bindgen-tests/tests/expectations/tests/derive-debug-function-pointer.rs +++ b/bindgen-tests/tests/expectations/tests/derive-debug-function-pointer.rs @@ -13,21 +13,24 @@ 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:: < Nice > (), 144usize, concat!("Size of: ", - stringify!(Nice)) + ::std::mem::size_of::(), + 144usize, + concat!("Size of: ", stringify!(Nice)), ); assert_eq!( - ::std::mem::align_of:: < Nice > (), 8usize, concat!("Alignment of ", - stringify!(Nice)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Nice)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).pointer) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Nice), "::", stringify!(pointer)) + unsafe { ::std::ptr::addr_of!((*ptr).pointer) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Nice), "::", stringify!(pointer)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).large_array) as usize - ptr as usize }, - 8usize, concat!("Offset of field: ", stringify!(Nice), "::", - stringify!(large_array)) + unsafe { ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize }, + 8usize, + concat!("Offset of field: ", stringify!(Nice), "::", stringify!(large_array)), ); } impl Default for Nice { @@ -42,9 +45,15 @@ 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, self - .large_array.iter().enumerate().map(| (i, v) | format!("{}{:?}", if i > 0 { - ", " } else { "" }, v)).collect:: < String > () + f, + "Nice {{ pointer: {:?}, large_array: [{}] }}", + self.pointer, + self + .large_array + .iter() + .enumerate() + .map(|(i, v)| format!("{}{:?}", if i > 0 { ", " } else { "" }, v)) + .collect::(), ) } } diff --git a/bindgen-tests/tests/expectations/tests/derive-debug-mangle-name.rs b/bindgen-tests/tests/expectations/tests/derive-debug-mangle-name.rs index d97721166e..b93a425af6 100644 --- a/bindgen-tests/tests/expectations/tests/derive-debug-mangle-name.rs +++ b/bindgen-tests/tests/expectations/tests/derive-debug-mangle-name.rs @@ -17,22 +17,34 @@ fn bindgen_test_layout_perf_event_attr__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < perf_event_attr__bindgen_ty_1 > (), 4usize, - concat!("Size of: ", stringify!(perf_event_attr__bindgen_ty_1)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(perf_event_attr__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < perf_event_attr__bindgen_ty_1 > (), 4usize, - concat!("Alignment of ", stringify!(perf_event_attr__bindgen_ty_1)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(perf_event_attr__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(perf_event_attr__bindgen_ty_1), "::", - stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(perf_event_attr__bindgen_ty_1), + "::", + stringify!(b), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).c) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(perf_event_attr__bindgen_ty_1), "::", - stringify!(c)) + unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(perf_event_attr__bindgen_ty_1), + "::", + stringify!(c), + ), ); } impl Default for perf_event_attr__bindgen_ty_1 { @@ -54,21 +66,29 @@ fn bindgen_test_layout_perf_event_attr() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < perf_event_attr > (), 12usize, concat!("Size of: ", - stringify!(perf_event_attr)) + ::std::mem::size_of::(), + 12usize, + concat!("Size of: ", stringify!(perf_event_attr)), ); assert_eq!( - ::std::mem::align_of:: < perf_event_attr > (), 4usize, concat!("Alignment of ", - stringify!(perf_event_attr)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(perf_event_attr)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).type_) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(perf_event_attr), "::", - stringify!(type_)) + unsafe { ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(perf_event_attr), + "::", + stringify!(type_), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(perf_event_attr), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(perf_event_attr), "::", stringify!(a)), ); } impl Default for perf_event_attr { @@ -83,8 +103,11 @@ impl Default for perf_event_attr { impl ::std::fmt::Debug for perf_event_attr { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { write!( - f, "perf_event_attr {{ type: {:?}, a: {:?}, __bindgen_anon_1: {:?} }}", self - .type_, self.a, self.__bindgen_anon_1 + f, + "perf_event_attr {{ type: {:?}, a: {:?}, __bindgen_anon_1: {:?} }}", + self.type_, + self.a, + self.__bindgen_anon_1, ) } } 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 3d49764cd8..812bf0283f 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 @@ -8,16 +8,19 @@ 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:: < Instance > (), 200usize, concat!("Size of: ", - stringify!(Instance)) + ::std::mem::size_of::(), + 200usize, + concat!("Size of: ", stringify!(Instance)), ); assert_eq!( - ::std::mem::align_of:: < Instance > (), 4usize, concat!("Alignment of ", - stringify!(Instance)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Instance)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).val) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Instance), "::", stringify!(val)) + unsafe { ::std::ptr::addr_of!((*ptr).val) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Instance), "::", stringify!(val)), ); } impl Default for Instance { diff --git a/bindgen-tests/tests/expectations/tests/derive-debug-opaque.rs b/bindgen-tests/tests/expectations/tests/derive-debug-opaque.rs index 07123e496e..b214562c0f 100644 --- a/bindgen-tests/tests/expectations/tests/derive-debug-opaque.rs +++ b/bindgen-tests/tests/expectations/tests/derive-debug-opaque.rs @@ -7,12 +7,14 @@ pub struct Opaque { #[test] fn bindgen_test_layout_Opaque() { assert_eq!( - ::std::mem::size_of:: < Opaque > (), 164usize, concat!("Size of: ", - stringify!(Opaque)) + ::std::mem::size_of::(), + 164usize, + concat!("Size of: ", stringify!(Opaque)), ); assert_eq!( - ::std::mem::align_of:: < Opaque > (), 4usize, concat!("Alignment of ", - stringify!(Opaque)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Opaque)), ); } impl Default for Opaque { @@ -38,16 +40,19 @@ 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:: < OpaqueUser > (), 164usize, concat!("Size of: ", - stringify!(OpaqueUser)) + ::std::mem::size_of::(), + 164usize, + concat!("Size of: ", stringify!(OpaqueUser)), ); assert_eq!( - ::std::mem::align_of:: < OpaqueUser > (), 4usize, concat!("Alignment of ", - stringify!(OpaqueUser)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(OpaqueUser)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).opaque) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(OpaqueUser), "::", stringify!(opaque)) + unsafe { ::std::ptr::addr_of!((*ptr).opaque) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(OpaqueUser), "::", stringify!(opaque)), ); } impl Default for OpaqueUser { diff --git a/bindgen-tests/tests/expectations/tests/derive-default-and-blocklist.rs b/bindgen-tests/tests/expectations/tests/derive-default-and-blocklist.rs index d769c01459..131df71c22 100644 --- a/bindgen-tests/tests/expectations/tests/derive-default-and-blocklist.rs +++ b/bindgen-tests/tests/expectations/tests/derive-default-and-blocklist.rs @@ -11,17 +11,24 @@ fn bindgen_test_layout_ShouldNotDeriveDefault() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < ShouldNotDeriveDefault > (), 1usize, concat!("Size of: ", - stringify!(ShouldNotDeriveDefault)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(ShouldNotDeriveDefault)), ); assert_eq!( - ::std::mem::align_of:: < ShouldNotDeriveDefault > (), 1usize, - concat!("Alignment of ", stringify!(ShouldNotDeriveDefault)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(ShouldNotDeriveDefault)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(ShouldNotDeriveDefault), "::", - stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ShouldNotDeriveDefault), + "::", + stringify!(a), + ), ); } impl Default for ShouldNotDeriveDefault { diff --git a/bindgen-tests/tests/expectations/tests/derive-fn-ptr.rs b/bindgen-tests/tests/expectations/tests/derive-fn-ptr.rs index d5944eee9d..395e31c5b5 100644 --- a/bindgen-tests/tests/expectations/tests/derive-fn-ptr.rs +++ b/bindgen-tests/tests/expectations/tests/derive-fn-ptr.rs @@ -29,15 +29,19 @@ 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:: < Foo > (), 8usize, concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Foo)), ); assert_eq!( - ::std::mem::align_of:: < Foo > (), 8usize, concat!("Alignment of ", - stringify!(Foo)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).callback) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(Foo), "::", stringify!(callback)) + unsafe { ::std::ptr::addr_of!((*ptr).callback) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(callback)), ); } pub type my_fun2_t = ::std::option::Option< @@ -66,14 +70,18 @@ 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:: < Bar > (), 8usize, concat!("Size of: ", stringify!(Bar)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Bar)), ); assert_eq!( - ::std::mem::align_of:: < Bar > (), 8usize, concat!("Alignment of ", - stringify!(Bar)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Bar)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).callback) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(callback)) + unsafe { ::std::ptr::addr_of!((*ptr).callback) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(callback)), ); } diff --git a/bindgen-tests/tests/expectations/tests/derive-hash-and-blocklist.rs b/bindgen-tests/tests/expectations/tests/derive-hash-and-blocklist.rs index a29c04fd04..98b3a11f85 100644 --- a/bindgen-tests/tests/expectations/tests/derive-hash-and-blocklist.rs +++ b/bindgen-tests/tests/expectations/tests/derive-hash-and-blocklist.rs @@ -10,17 +10,24 @@ fn bindgen_test_layout_ShouldNotDeriveHash() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < ShouldNotDeriveHash > (), 1usize, concat!("Size of: ", - stringify!(ShouldNotDeriveHash)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(ShouldNotDeriveHash)), ); assert_eq!( - ::std::mem::align_of:: < ShouldNotDeriveHash > (), 1usize, - concat!("Alignment of ", stringify!(ShouldNotDeriveHash)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(ShouldNotDeriveHash)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(ShouldNotDeriveHash), "::", - stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ShouldNotDeriveHash), + "::", + stringify!(a), + ), ); } impl Default for ShouldNotDeriveHash { diff --git a/bindgen-tests/tests/expectations/tests/derive-hash-blocklisting.rs b/bindgen-tests/tests/expectations/tests/derive-hash-blocklisting.rs index 4d733f3102..dd6f3e26b7 100644 --- a/bindgen-tests/tests/expectations/tests/derive-hash-blocklisting.rs +++ b/bindgen-tests/tests/expectations/tests/derive-hash-blocklisting.rs @@ -16,16 +16,19 @@ fn bindgen_test_layout_AllowlistedOne() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < AllowlistedOne > (), 4usize, concat!("Size of: ", - stringify!(AllowlistedOne)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(AllowlistedOne)), ); assert_eq!( - ::std::mem::align_of:: < AllowlistedOne > (), 4usize, concat!("Alignment of ", - stringify!(AllowlistedOne)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(AllowlistedOne)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(AllowlistedOne), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(AllowlistedOne), "::", stringify!(a)), ); } impl Default for AllowlistedOne { @@ -47,16 +50,19 @@ fn bindgen_test_layout_AllowlistedTwo() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < AllowlistedTwo > (), 4usize, concat!("Size of: ", - stringify!(AllowlistedTwo)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(AllowlistedTwo)), ); assert_eq!( - ::std::mem::align_of:: < AllowlistedTwo > (), 4usize, concat!("Alignment of ", - stringify!(AllowlistedTwo)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(AllowlistedTwo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(AllowlistedTwo), "::", stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(AllowlistedTwo), "::", stringify!(b)), ); } impl Default for AllowlistedTwo { diff --git a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs index 5c7706c6df..25b2ad6b6f 100644 --- a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs +++ b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs @@ -16,20 +16,24 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < foo__bindgen_ty_1 > (), 8usize, concat!("Size of: ", - stringify!(foo__bindgen_ty_1)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", - stringify!(foo__bindgen_ty_1)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)), ); } #[test] @@ -37,14 +41,18 @@ 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:: < foo > (), 8usize, concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(foo)), ); assert_eq!( - ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", - stringify!(foo)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)), ); } diff --git a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-float-array.rs b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-float-array.rs index b9ae54b058..aa990eceb4 100644 --- a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-float-array.rs +++ b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-float-array.rs @@ -10,14 +10,18 @@ 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:: < foo > (), 12usize, concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of::(), + 12usize, + concat!("Size of: ", stringify!(foo)), ); assert_eq!( - ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", - stringify!(foo)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)), ); } diff --git a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs index 93df00c148..2a1090e130 100644 --- a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs +++ b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs @@ -40,20 +40,31 @@ fn bindgen_test_layout_test() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < test > (), 4usize, concat!("Size of: ", stringify!(test)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(test)), ); assert_eq!( - ::std::mem::align_of:: < test > (), 4usize, concat!("Alignment of ", - stringify!(test)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(test)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(test), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(test), "::", stringify!(a)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).zero_length_array) as usize - ptr as usize - }, 4usize, concat!("Offset of field: ", stringify!(test), "::", - stringify!(zero_length_array)) + unsafe { + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(test), + "::", + stringify!(zero_length_array), + ), ); } #[repr(C)] @@ -65,12 +76,14 @@ pub struct test2 { #[test] fn bindgen_test_layout_test2() { assert_eq!( - ::std::mem::size_of:: < test2 > (), 4usize, concat!("Size of: ", - stringify!(test2)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(test2)), ); assert_eq!( - ::std::mem::align_of:: < test2 > (), 4usize, concat!("Alignment of ", - stringify!(test2)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(test2)), ); } #[repr(C)] @@ -83,11 +96,13 @@ pub struct test3 { #[test] fn bindgen_test_layout_test3() { assert_eq!( - ::std::mem::size_of:: < test3 > (), 4usize, concat!("Size of: ", - stringify!(test3)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(test3)), ); assert_eq!( - ::std::mem::align_of:: < test3 > (), 4usize, concat!("Alignment of ", - stringify!(test3)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(test3)), ); } diff --git a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-pointer.rs b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-pointer.rs index b66332318f..616a046f5e 100644 --- a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-pointer.rs +++ b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-pointer.rs @@ -10,16 +10,19 @@ fn bindgen_test_layout_ConstPtrMutObj() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < ConstPtrMutObj > (), 8usize, concat!("Size of: ", - stringify!(ConstPtrMutObj)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(ConstPtrMutObj)), ); assert_eq!( - ::std::mem::align_of:: < ConstPtrMutObj > (), 8usize, concat!("Alignment of ", - stringify!(ConstPtrMutObj)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(ConstPtrMutObj)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(ConstPtrMutObj), "::", stringify!(bar)) + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(ConstPtrMutObj), "::", stringify!(bar)), ); } impl Default for ConstPtrMutObj { @@ -41,16 +44,19 @@ fn bindgen_test_layout_MutPtrMutObj() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < MutPtrMutObj > (), 8usize, concat!("Size of: ", - stringify!(MutPtrMutObj)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(MutPtrMutObj)), ); assert_eq!( - ::std::mem::align_of:: < MutPtrMutObj > (), 8usize, concat!("Alignment of ", - stringify!(MutPtrMutObj)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(MutPtrMutObj)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(MutPtrMutObj), "::", stringify!(bar)) + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(MutPtrMutObj), "::", stringify!(bar)), ); } impl Default for MutPtrMutObj { @@ -72,16 +78,19 @@ fn bindgen_test_layout_MutPtrConstObj() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < MutPtrConstObj > (), 8usize, concat!("Size of: ", - stringify!(MutPtrConstObj)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(MutPtrConstObj)), ); assert_eq!( - ::std::mem::align_of:: < MutPtrConstObj > (), 8usize, concat!("Alignment of ", - stringify!(MutPtrConstObj)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(MutPtrConstObj)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(MutPtrConstObj), "::", stringify!(bar)) + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(MutPtrConstObj), "::", stringify!(bar)), ); } impl Default for MutPtrConstObj { @@ -103,16 +112,19 @@ fn bindgen_test_layout_ConstPtrConstObj() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < ConstPtrConstObj > (), 8usize, concat!("Size of: ", - stringify!(ConstPtrConstObj)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(ConstPtrConstObj)), ); assert_eq!( - ::std::mem::align_of:: < ConstPtrConstObj > (), 8usize, concat!("Alignment of ", - stringify!(ConstPtrConstObj)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(ConstPtrConstObj)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(ConstPtrConstObj), "::", stringify!(bar)) + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(ConstPtrConstObj), "::", stringify!(bar)), ); } impl Default for ConstPtrConstObj { diff --git a/bindgen-tests/tests/expectations/tests/derive-hash-template-inst-float.rs b/bindgen-tests/tests/expectations/tests/derive-hash-template-inst-float.rs index cdece306e0..57a716fa58 100644 --- a/bindgen-tests/tests/expectations/tests/derive-hash-template-inst-float.rs +++ b/bindgen-tests/tests/expectations/tests/derive-hash-template-inst-float.rs @@ -26,16 +26,19 @@ fn bindgen_test_layout_IntStr() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < IntStr > (), 4usize, concat!("Size of: ", - stringify!(IntStr)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(IntStr)), ); assert_eq!( - ::std::mem::align_of:: < IntStr > (), 4usize, concat!("Alignment of ", - stringify!(IntStr)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(IntStr)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(IntStr), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(IntStr), "::", stringify!(a)), ); } impl Default for IntStr { @@ -58,16 +61,19 @@ fn bindgen_test_layout_FloatStr() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < FloatStr > (), 4usize, concat!("Size of: ", - stringify!(FloatStr)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(FloatStr)), ); assert_eq!( - ::std::mem::align_of:: < FloatStr > (), 4usize, concat!("Alignment of ", - stringify!(FloatStr)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(FloatStr)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(FloatStr), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(FloatStr), "::", stringify!(a)), ); } impl Default for FloatStr { @@ -82,24 +88,32 @@ impl Default for FloatStr { #[test] fn __bindgen_test_layout_foo_open0_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < foo < ::std::os::raw::c_int > > (), 4usize, - concat!("Size of template specialization: ", stringify!(foo < - ::std::os::raw::c_int >)) + ::std::mem::size_of::>(), + 4usize, + concat!( + "Size of template specialization: ", + stringify!(foo < ::std::os::raw::c_int >), + ), ); assert_eq!( - ::std::mem::align_of:: < foo < ::std::os::raw::c_int > > (), 4usize, - concat!("Alignment of template specialization: ", stringify!(foo < - ::std::os::raw::c_int >)) + ::std::mem::align_of::>(), + 4usize, + concat!( + "Alignment of template specialization: ", + stringify!(foo < ::std::os::raw::c_int >), + ), ); } #[test] fn __bindgen_test_layout_foo_open0_float_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < foo < f32 > > (), 4usize, - concat!("Size of template specialization: ", stringify!(foo < f32 >)) + ::std::mem::size_of::>(), + 4usize, + concat!("Size of template specialization: ", stringify!(foo < f32 >)), ); assert_eq!( - ::std::mem::align_of:: < foo < f32 > > (), 4usize, - concat!("Alignment of template specialization: ", stringify!(foo < f32 >)) + ::std::mem::align_of::>(), + 4usize, + concat!("Alignment of template specialization: ", stringify!(foo < f32 >)), ); } diff --git a/bindgen-tests/tests/expectations/tests/derive-partialeq-and-blocklist.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-and-blocklist.rs index 52552dd746..614d0e674f 100644 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-and-blocklist.rs +++ b/bindgen-tests/tests/expectations/tests/derive-partialeq-and-blocklist.rs @@ -11,17 +11,24 @@ fn bindgen_test_layout_ShouldNotDerivePartialEq() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < ShouldNotDerivePartialEq > (), 1usize, - concat!("Size of: ", stringify!(ShouldNotDerivePartialEq)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(ShouldNotDerivePartialEq)), ); assert_eq!( - ::std::mem::align_of:: < ShouldNotDerivePartialEq > (), 1usize, - concat!("Alignment of ", stringify!(ShouldNotDerivePartialEq)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(ShouldNotDerivePartialEq)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(ShouldNotDerivePartialEq), "::", - stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ShouldNotDerivePartialEq), + "::", + stringify!(a), + ), ); } impl Default for ShouldNotDerivePartialEq { diff --git a/bindgen-tests/tests/expectations/tests/derive-partialeq-anonfield.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-anonfield.rs index 3dc27a0d30..b7be202924 100644 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-anonfield.rs +++ b/bindgen-tests/tests/expectations/tests/derive-partialeq-anonfield.rs @@ -14,12 +14,14 @@ pub struct rte_mbuf__bindgen_ty_1 { #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_1() { assert_eq!( - ::std::mem::size_of:: < rte_mbuf__bindgen_ty_1 > (), 0usize, concat!("Size of: ", - stringify!(rte_mbuf__bindgen_ty_1)) + ::std::mem::size_of::(), + 0usize, + concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < rte_mbuf__bindgen_ty_1 > (), 1usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_1)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_1)), ); } impl Default for rte_mbuf__bindgen_ty_1 { @@ -34,12 +36,14 @@ impl Default for rte_mbuf__bindgen_ty_1 { #[test] fn bindgen_test_layout_rte_mbuf() { assert_eq!( - ::std::mem::size_of:: < rte_mbuf > (), 0usize, concat!("Size of: ", - stringify!(rte_mbuf)) + ::std::mem::size_of::(), + 0usize, + concat!("Size of: ", stringify!(rte_mbuf)), ); assert_eq!( - ::std::mem::align_of:: < rte_mbuf > (), 64usize, concat!("Alignment of ", - stringify!(rte_mbuf)) + ::std::mem::align_of::(), + 64usize, + concat!("Alignment of ", stringify!(rte_mbuf)), ); } impl Default for rte_mbuf { diff --git a/bindgen-tests/tests/expectations/tests/derive-partialeq-base.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-base.rs index 950e954bc3..785bcbe0b1 100644 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-base.rs +++ b/bindgen-tests/tests/expectations/tests/derive-partialeq-base.rs @@ -9,16 +9,19 @@ 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:: < Base > (), 132usize, concat!("Size of: ", - stringify!(Base)) + ::std::mem::size_of::(), + 132usize, + concat!("Size of: ", stringify!(Base)), ); assert_eq!( - ::std::mem::align_of:: < Base > (), 4usize, concat!("Alignment of ", - stringify!(Base)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Base)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).large) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Base), "::", stringify!(large)) + unsafe { ::std::ptr::addr_of!((*ptr).large) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Base), "::", stringify!(large)), ); } impl Default for Base { @@ -43,12 +46,14 @@ pub struct ShouldDerivePartialEq { #[test] fn bindgen_test_layout_ShouldDerivePartialEq() { assert_eq!( - ::std::mem::size_of:: < ShouldDerivePartialEq > (), 132usize, - concat!("Size of: ", stringify!(ShouldDerivePartialEq)) + ::std::mem::size_of::(), + 132usize, + concat!("Size of: ", stringify!(ShouldDerivePartialEq)), ); assert_eq!( - ::std::mem::align_of:: < ShouldDerivePartialEq > (), 4usize, - concat!("Alignment of ", stringify!(ShouldDerivePartialEq)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(ShouldDerivePartialEq)), ); } impl Default for ShouldDerivePartialEq { diff --git a/bindgen-tests/tests/expectations/tests/derive-partialeq-bitfield.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-bitfield.rs index 0bf1298af0..6f474165ad 100644 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/derive-partialeq-bitfield.rs @@ -49,7 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -69,7 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -95,15 +95,19 @@ 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:: < C > (), 204usize, concat!("Size of: ", stringify!(C)) + ::std::mem::size_of::(), + 204usize, + concat!("Size of: ", stringify!(C)), ); assert_eq!( - ::std::mem::align_of:: < C > (), 4usize, concat!("Alignment of ", stringify!(C)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(C)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).large_array) as usize - ptr as usize }, - 4usize, concat!("Offset of field: ", stringify!(C), "::", - stringify!(large_array)) + unsafe { ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(large_array)), ); } impl Default for C { diff --git a/bindgen-tests/tests/expectations/tests/derive-partialeq-core.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-core.rs index e2d991a898..b535256cec 100644 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-core.rs +++ b/bindgen-tests/tests/expectations/tests/derive-partialeq-core.rs @@ -10,15 +10,19 @@ 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:: < C > (), 1680usize, concat!("Size of: ", stringify!(C)) + ::core::mem::size_of::(), + 1680usize, + concat!("Size of: ", stringify!(C)), ); assert_eq!( - ::core::mem::align_of:: < C > (), 4usize, concat!("Alignment of ", stringify!(C)) + ::core::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(C)), ); assert_eq!( - unsafe { ::core::ptr::addr_of!((* ptr).large_array) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(C), "::", - stringify!(large_array)) + unsafe { ::core::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(large_array)), ); } impl Default for C { diff --git a/bindgen-tests/tests/expectations/tests/derive-partialeq-pointer.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-pointer.rs index 3cd6c46b00..3baa2daaad 100644 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-pointer.rs +++ b/bindgen-tests/tests/expectations/tests/derive-partialeq-pointer.rs @@ -9,15 +9,19 @@ 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:: < Bar > (), 8usize, concat!("Size of: ", stringify!(Bar)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Bar)), ); assert_eq!( - ::std::mem::align_of:: < Bar > (), 8usize, concat!("Alignment of ", - stringify!(Bar)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Bar)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(b)), ); } impl Default for Bar { @@ -42,12 +46,14 @@ pub union c__bindgen_ty_1 { #[test] fn bindgen_test_layout_c__bindgen_ty_1() { assert_eq!( - ::std::mem::size_of:: < c__bindgen_ty_1 > (), 1usize, concat!("Size of: ", - stringify!(c__bindgen_ty_1)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(c__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < c__bindgen_ty_1 > (), 1usize, concat!("Alignment of ", - stringify!(c__bindgen_ty_1)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(c__bindgen_ty_1)), ); } impl Default for c__bindgen_ty_1 { @@ -61,11 +67,11 @@ impl Default for c__bindgen_ty_1 { } #[test] fn bindgen_test_layout_c() { + assert_eq!(::std::mem::size_of::(), 1usize, concat!("Size of: ", stringify!(c))); assert_eq!( - ::std::mem::size_of:: < c > (), 1usize, concat!("Size of: ", stringify!(c)) - ); - assert_eq!( - ::std::mem::align_of:: < c > (), 1usize, concat!("Alignment of ", stringify!(c)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(c)), ); } impl Default for c { @@ -86,15 +92,16 @@ pub struct a { 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::(), 1usize, concat!("Size of: ", stringify!(a))); assert_eq!( - ::std::mem::size_of:: < a > (), 1usize, concat!("Size of: ", stringify!(a)) - ); - assert_eq!( - ::std::mem::align_of:: < a > (), 1usize, concat!("Alignment of ", stringify!(a)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(a)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).d) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(a), "::", stringify!(d)) + unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(a), "::", stringify!(d)), ); } impl Default for a { diff --git a/bindgen-tests/tests/expectations/tests/derive-partialeq-union.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-union.rs index 511e4b8891..61b1a4b1b5 100644 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-union.rs +++ b/bindgen-tests/tests/expectations/tests/derive-partialeq-union.rs @@ -11,22 +11,34 @@ fn bindgen_test_layout_ShouldNotDerivePartialEq() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < ShouldNotDerivePartialEq > (), 4usize, - concat!("Size of: ", stringify!(ShouldNotDerivePartialEq)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(ShouldNotDerivePartialEq)), ); assert_eq!( - ::std::mem::align_of:: < ShouldNotDerivePartialEq > (), 4usize, - concat!("Alignment of ", stringify!(ShouldNotDerivePartialEq)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(ShouldNotDerivePartialEq)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(ShouldNotDerivePartialEq), "::", - stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ShouldNotDerivePartialEq), + "::", + stringify!(a), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(ShouldNotDerivePartialEq), "::", - stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ShouldNotDerivePartialEq), + "::", + stringify!(b), + ), ); } impl Default for ShouldNotDerivePartialEq { diff --git a/bindgen-tests/tests/expectations/tests/derive-partialeq-union_1_0.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-union_1_0.rs index 07b97b00de..3429b72b49 100644 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/derive-partialeq-union_1_0.rs @@ -55,22 +55,34 @@ fn bindgen_test_layout_ShouldDerivePartialEq() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < ShouldDerivePartialEq > (), 152usize, - concat!("Size of: ", stringify!(ShouldDerivePartialEq)) + ::std::mem::size_of::(), + 152usize, + concat!("Size of: ", stringify!(ShouldDerivePartialEq)), ); assert_eq!( - ::std::mem::align_of:: < ShouldDerivePartialEq > (), 4usize, - concat!("Alignment of ", stringify!(ShouldDerivePartialEq)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(ShouldDerivePartialEq)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(ShouldDerivePartialEq), "::", - stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ShouldDerivePartialEq), + "::", + stringify!(a), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(ShouldDerivePartialEq), "::", - stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ShouldDerivePartialEq), + "::", + stringify!(b), + ), ); } impl Clone for ShouldDerivePartialEq { diff --git a/bindgen-tests/tests/expectations/tests/disable-nested-struct-naming.rs b/bindgen-tests/tests/expectations/tests/disable-nested-struct-naming.rs index d9e53cc773..db942db300 100644 --- a/bindgen-tests/tests/expectations/tests/disable-nested-struct-naming.rs +++ b/bindgen-tests/tests/expectations/tests/disable-nested-struct-naming.rs @@ -32,15 +32,19 @@ fn bindgen_test_layout_bar4() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < bar4 > (), 4usize, concat!("Size of: ", stringify!(bar4)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(bar4)), ); assert_eq!( - ::std::mem::align_of:: < bar4 > (), 4usize, concat!("Alignment of ", - stringify!(bar4)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(bar4)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).x4) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(bar4), "::", stringify!(x4)) + unsafe { ::std::ptr::addr_of!((*ptr).x4) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(bar4), "::", stringify!(x4)), ); } #[test] @@ -48,22 +52,34 @@ fn bindgen_test_layout_bar1__bindgen_ty_1__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < bar1__bindgen_ty_1__bindgen_ty_1 > (), 8usize, - concat!("Size of: ", stringify!(bar1__bindgen_ty_1__bindgen_ty_1)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(bar1__bindgen_ty_1__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < bar1__bindgen_ty_1__bindgen_ty_1 > (), 4usize, - concat!("Alignment of ", stringify!(bar1__bindgen_ty_1__bindgen_ty_1)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(bar1__bindgen_ty_1__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).x3) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(bar1__bindgen_ty_1__bindgen_ty_1), "::", - stringify!(x3)) + unsafe { ::std::ptr::addr_of!((*ptr).x3) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(bar1__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(x3), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b4) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(bar1__bindgen_ty_1__bindgen_ty_1), "::", - stringify!(b4)) + unsafe { ::std::ptr::addr_of!((*ptr).b4) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(bar1__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(b4), + ), ); } #[test] @@ -71,22 +87,34 @@ fn bindgen_test_layout_bar1__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < bar1__bindgen_ty_1 > (), 12usize, concat!("Size of: ", - stringify!(bar1__bindgen_ty_1)) + ::std::mem::size_of::(), + 12usize, + concat!("Size of: ", stringify!(bar1__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < bar1__bindgen_ty_1 > (), 4usize, - concat!("Alignment of ", stringify!(bar1__bindgen_ty_1)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(bar1__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).x2) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(bar1__bindgen_ty_1), "::", - stringify!(x2)) + unsafe { ::std::ptr::addr_of!((*ptr).x2) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(bar1__bindgen_ty_1), + "::", + stringify!(x2), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b3) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(bar1__bindgen_ty_1), "::", - stringify!(b3)) + unsafe { ::std::ptr::addr_of!((*ptr).b3) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(bar1__bindgen_ty_1), + "::", + stringify!(b3), + ), ); } #[test] @@ -94,20 +122,24 @@ fn bindgen_test_layout_bar1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < bar1 > (), 16usize, concat!("Size of: ", - stringify!(bar1)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(bar1)), ); assert_eq!( - ::std::mem::align_of:: < bar1 > (), 4usize, concat!("Alignment of ", - stringify!(bar1)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(bar1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).x1) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(bar1), "::", stringify!(x1)) + unsafe { ::std::ptr::addr_of!((*ptr).x1) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(bar1), "::", stringify!(x1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b2) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(bar1), "::", stringify!(b2)) + unsafe { ::std::ptr::addr_of!((*ptr).b2) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(bar1), "::", stringify!(b2)), ); } #[test] @@ -115,15 +147,19 @@ 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:: < foo > (), 16usize, concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(foo)), ); assert_eq!( - ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", - stringify!(foo)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b1) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(b1)) + unsafe { ::std::ptr::addr_of!((*ptr).b1) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(b1)), ); } #[repr(C)] @@ -146,15 +182,19 @@ 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:: < baz > (), 4usize, concat!("Size of: ", stringify!(baz)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(baz)), ); assert_eq!( - ::std::mem::align_of:: < baz > (), 4usize, concat!("Alignment of ", - stringify!(baz)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(baz)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).x) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(baz), "::", stringify!(x)) + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(baz), "::", stringify!(x)), ); } #[test] @@ -162,17 +202,24 @@ fn bindgen_test_layout__bindgen_ty_1__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit<_bindgen_ty_1__bindgen_ty_1> = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < _bindgen_ty_1__bindgen_ty_1 > (), 4usize, - concat!("Size of: ", stringify!(_bindgen_ty_1__bindgen_ty_1)) + ::std::mem::size_of::<_bindgen_ty_1__bindgen_ty_1>(), + 4usize, + concat!("Size of: ", stringify!(_bindgen_ty_1__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < _bindgen_ty_1__bindgen_ty_1 > (), 4usize, - concat!("Alignment of ", stringify!(_bindgen_ty_1__bindgen_ty_1)) + ::std::mem::align_of::<_bindgen_ty_1__bindgen_ty_1>(), + 4usize, + concat!("Alignment of ", stringify!(_bindgen_ty_1__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(_bindgen_ty_1__bindgen_ty_1), "::", - stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(b), + ), ); } #[test] @@ -180,16 +227,19 @@ fn bindgen_test_layout__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit<_bindgen_ty_1> = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < _bindgen_ty_1 > (), 4usize, concat!("Size of: ", - stringify!(_bindgen_ty_1)) + ::std::mem::size_of::<_bindgen_ty_1>(), + 4usize, + concat!("Size of: ", stringify!(_bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < _bindgen_ty_1 > (), 4usize, concat!("Alignment of ", - stringify!(_bindgen_ty_1)) + ::std::mem::align_of::<_bindgen_ty_1>(), + 4usize, + concat!("Alignment of ", stringify!(_bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).anon2) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(_bindgen_ty_1), "::", stringify!(anon2)) + unsafe { ::std::ptr::addr_of!((*ptr).anon2) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(_bindgen_ty_1), "::", stringify!(anon2)), ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/disable-untagged-union.rs b/bindgen-tests/tests/expectations/tests/disable-untagged-union.rs index d2913f4802..7322552a76 100644 --- a/bindgen-tests/tests/expectations/tests/disable-untagged-union.rs +++ b/bindgen-tests/tests/expectations/tests/disable-untagged-union.rs @@ -54,18 +54,23 @@ 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:: < Foo > (), 4usize, concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Foo)), ); assert_eq!( - ::std::mem::align_of:: < Foo > (), 4usize, concat!("Alignment of ", - stringify!(Foo)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).baz) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(baz)) + unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(baz)), ); } diff --git a/bindgen-tests/tests/expectations/tests/divide-by-zero-in-struct-layout.rs b/bindgen-tests/tests/expectations/tests/divide-by-zero-in-struct-layout.rs index 18221499b2..707c2d56bc 100644 --- a/bindgen-tests/tests/expectations/tests/divide-by-zero-in-struct-layout.rs +++ b/bindgen-tests/tests/expectations/tests/divide-by-zero-in-struct-layout.rs @@ -49,7 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -69,7 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; diff --git a/bindgen-tests/tests/expectations/tests/do-not-derive-copy.rs b/bindgen-tests/tests/expectations/tests/do-not-derive-copy.rs index 3fcfce4f1f..5d1cf1c547 100644 --- a/bindgen-tests/tests/expectations/tests/do-not-derive-copy.rs +++ b/bindgen-tests/tests/expectations/tests/do-not-derive-copy.rs @@ -9,16 +9,23 @@ fn bindgen_test_layout_WouldBeCopyButWeAreNotDerivingCopy() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < WouldBeCopyButWeAreNotDerivingCopy > (), 4usize, - concat!("Size of: ", stringify!(WouldBeCopyButWeAreNotDerivingCopy)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(WouldBeCopyButWeAreNotDerivingCopy)), ); assert_eq!( - ::std::mem::align_of:: < WouldBeCopyButWeAreNotDerivingCopy > (), 4usize, - concat!("Alignment of ", stringify!(WouldBeCopyButWeAreNotDerivingCopy)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(WouldBeCopyButWeAreNotDerivingCopy)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).x) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(WouldBeCopyButWeAreNotDerivingCopy), - "::", stringify!(x)) + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WouldBeCopyButWeAreNotDerivingCopy), + "::", + stringify!(x), + ), ); } diff --git a/bindgen-tests/tests/expectations/tests/doggo-or-null.rs b/bindgen-tests/tests/expectations/tests/doggo-or-null.rs index 3129bf99a3..395c02043e 100644 --- a/bindgen-tests/tests/expectations/tests/doggo-or-null.rs +++ b/bindgen-tests/tests/expectations/tests/doggo-or-null.rs @@ -9,16 +9,19 @@ fn bindgen_test_layout_Doggo() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < Doggo > (), 4usize, concat!("Size of: ", - stringify!(Doggo)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Doggo)), ); assert_eq!( - ::std::mem::align_of:: < Doggo > (), 4usize, concat!("Alignment of ", - stringify!(Doggo)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Doggo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).x) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Doggo), "::", stringify!(x)) + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Doggo), "::", stringify!(x)), ); } #[repr(C)] @@ -29,11 +32,14 @@ pub struct Null { #[test] fn bindgen_test_layout_Null() { assert_eq!( - ::std::mem::size_of:: < Null > (), 1usize, concat!("Size of: ", stringify!(Null)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Null)), ); assert_eq!( - ::std::mem::align_of:: < Null > (), 1usize, concat!("Alignment of ", - stringify!(Null)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Null)), ); } /** This type is an opaque union. Unions can't derive anything interesting like @@ -51,12 +57,14 @@ pub union DoggoOrNull { #[test] fn bindgen_test_layout_DoggoOrNull() { assert_eq!( - ::std::mem::size_of:: < DoggoOrNull > (), 4usize, concat!("Size of: ", - stringify!(DoggoOrNull)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(DoggoOrNull)), ); assert_eq!( - ::std::mem::align_of:: < DoggoOrNull > (), 4usize, concat!("Alignment of ", - stringify!(DoggoOrNull)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(DoggoOrNull)), ); } impl Default for DoggoOrNull { diff --git a/bindgen-tests/tests/expectations/tests/duplicated-definition-count.rs b/bindgen-tests/tests/expectations/tests/duplicated-definition-count.rs index 3115d9cf9e..186d32d1f9 100644 --- a/bindgen-tests/tests/expectations/tests/duplicated-definition-count.rs +++ b/bindgen-tests/tests/expectations/tests/duplicated-definition-count.rs @@ -7,12 +7,14 @@ pub struct BitStream { #[test] fn bindgen_test_layout_BitStream() { assert_eq!( - ::std::mem::size_of:: < BitStream > (), 1usize, concat!("Size of: ", - stringify!(BitStream)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(BitStream)), ); assert_eq!( - ::std::mem::align_of:: < BitStream > (), 1usize, concat!("Alignment of ", - stringify!(BitStream)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(BitStream)), ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/duplicated-namespaces-definitions.rs b/bindgen-tests/tests/expectations/tests/duplicated-namespaces-definitions.rs index a491547e36..afb649d769 100644 --- a/bindgen-tests/tests/expectations/tests/duplicated-namespaces-definitions.rs +++ b/bindgen-tests/tests/expectations/tests/duplicated-namespaces-definitions.rs @@ -17,22 +17,24 @@ pub mod root { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < Bar > (), 8usize, concat!("Size of: ", - stringify!(Bar)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Bar)), ); assert_eq!( - ::std::mem::align_of:: < Bar > (), 4usize, concat!("Alignment of ", - stringify!(Bar)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Bar)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).foo) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(Bar), "::", - stringify!(foo)) + unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).baz) as usize - ptr as usize }, - 4usize, concat!("Offset of field: ", stringify!(Bar), "::", - stringify!(baz)) + unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz)), ); } } @@ -49,17 +51,19 @@ pub mod root { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < Foo > (), 8usize, concat!("Size of: ", - stringify!(Foo)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Foo)), ); assert_eq!( - ::std::mem::align_of:: < Foo > (), 8usize, concat!("Alignment of ", - stringify!(Foo)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).ptr) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(Foo), "::", - stringify!(ptr)) + unsafe { ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(ptr)), ); } impl Default for Foo { diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_blocklist.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_blocklist.rs index 59c3c4273d..4a523db856 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_blocklist.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_blocklist.rs @@ -8,15 +8,16 @@ pub struct X { fn bindgen_test_layout_X() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); + assert_eq!(::std::mem::size_of::(), 4usize, concat!("Size of: ", stringify!(X))); assert_eq!( - ::std::mem::size_of:: < X > (), 4usize, concat!("Size of: ", stringify!(X)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(X)), ); assert_eq!( - ::std::mem::align_of:: < X > (), 4usize, concat!("Alignment of ", stringify!(X)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr)._x) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(X), "::", stringify!(_x)) + unsafe { ::std::ptr::addr_of!((*ptr)._x) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(X), "::", stringify!(_x)), ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs index 6c4cf9eec9..2d17952408 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs @@ -8,15 +8,16 @@ pub struct A { 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::(), 4usize, concat!("Size of: ", stringify!(A))); assert_eq!( - ::std::mem::size_of:: < A > (), 4usize, concat!("Size of: ", stringify!(A)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(A)), ); assert_eq!( - ::std::mem::align_of:: < A > (), 4usize, concat!("Alignment of ", stringify!(A)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr)._x) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(_x)) + unsafe { ::std::ptr::addr_of!((*ptr)._x) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(A), "::", stringify!(_x)), ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/enum-default-bitfield.rs b/bindgen-tests/tests/expectations/tests/enum-default-bitfield.rs index 16c92c5750..0d3829de20 100644 --- a/bindgen-tests/tests/expectations/tests/enum-default-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/enum-default-bitfield.rs @@ -40,15 +40,19 @@ 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:: < foo > (), 4usize, concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo)), ); assert_eq!( - ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", - stringify!(foo)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).member) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(member)) + unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(member)), ); } impl Default for foo { diff --git a/bindgen-tests/tests/expectations/tests/enum-default-consts.rs b/bindgen-tests/tests/expectations/tests/enum-default-consts.rs index 70d4ad2acb..a63be965bf 100644 --- a/bindgen-tests/tests/expectations/tests/enum-default-consts.rs +++ b/bindgen-tests/tests/expectations/tests/enum-default-consts.rs @@ -12,15 +12,19 @@ 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:: < foo > (), 4usize, concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo)), ); assert_eq!( - ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", - stringify!(foo)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).member) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(member)) + unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(member)), ); } impl Default for foo { diff --git a/bindgen-tests/tests/expectations/tests/enum-default-module.rs b/bindgen-tests/tests/expectations/tests/enum-default-module.rs index 6432af559a..9774135d5c 100644 --- a/bindgen-tests/tests/expectations/tests/enum-default-module.rs +++ b/bindgen-tests/tests/expectations/tests/enum-default-module.rs @@ -14,15 +14,19 @@ 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:: < foo > (), 4usize, concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo)), ); assert_eq!( - ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", - stringify!(foo)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).member) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(member)) + unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(member)), ); } impl Default for foo { diff --git a/bindgen-tests/tests/expectations/tests/enum-default-rust.rs b/bindgen-tests/tests/expectations/tests/enum-default-rust.rs index 45d48397d8..27ea5a1694 100644 --- a/bindgen-tests/tests/expectations/tests/enum-default-rust.rs +++ b/bindgen-tests/tests/expectations/tests/enum-default-rust.rs @@ -17,15 +17,19 @@ 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:: < foo > (), 4usize, concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo)), ); assert_eq!( - ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", - stringify!(foo)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).member) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(member)) + unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(member)), ); } impl Default for foo { diff --git a/bindgen-tests/tests/expectations/tests/enum-no-debug-rust.rs b/bindgen-tests/tests/expectations/tests/enum-no-debug-rust.rs index 9a52fd4d96..6050d25ad3 100644 --- a/bindgen-tests/tests/expectations/tests/enum-no-debug-rust.rs +++ b/bindgen-tests/tests/expectations/tests/enum-no-debug-rust.rs @@ -17,15 +17,19 @@ 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:: < foo > (), 4usize, concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo)), ); assert_eq!( - ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", - stringify!(foo)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).member) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(member)) + unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(member)), ); } impl Default for foo { diff --git a/bindgen-tests/tests/expectations/tests/enum.rs b/bindgen-tests/tests/expectations/tests/enum.rs index 6c5a5bf742..69422fb34b 100644 --- a/bindgen-tests/tests/expectations/tests/enum.rs +++ b/bindgen-tests/tests/expectations/tests/enum.rs @@ -12,15 +12,19 @@ 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:: < foo > (), 4usize, concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo)), ); assert_eq!( - ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", - stringify!(foo)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).member) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(member)) + unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(member)), ); } impl Default for foo { diff --git a/bindgen-tests/tests/expectations/tests/enum_and_vtable_mangling.rs b/bindgen-tests/tests/expectations/tests/enum_and_vtable_mangling.rs index f9f90e9bcc..c450c7b2d9 100644 --- a/bindgen-tests/tests/expectations/tests/enum_and_vtable_mangling.rs +++ b/bindgen-tests/tests/expectations/tests/enum_and_vtable_mangling.rs @@ -21,15 +21,16 @@ pub struct C { 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::(), 16usize, concat!("Size of: ", stringify!(C))); assert_eq!( - ::std::mem::size_of:: < C > (), 16usize, concat!("Size of: ", stringify!(C)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(C)), ); assert_eq!( - ::std::mem::align_of:: < C > (), 8usize, concat!("Alignment of ", stringify!(C)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).i) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(i)) + unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, + 8usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(i)), ); } impl Default for C { diff --git a/bindgen-tests/tests/expectations/tests/explicit-padding.rs b/bindgen-tests/tests/expectations/tests/explicit-padding.rs index 0cd40e9c5f..14d46c8120 100644 --- a/bindgen-tests/tests/expectations/tests/explicit-padding.rs +++ b/bindgen-tests/tests/expectations/tests/explicit-padding.rs @@ -13,24 +13,29 @@ fn bindgen_test_layout_pad_me() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < pad_me > (), 12usize, concat!("Size of: ", - stringify!(pad_me)) + ::std::mem::size_of::(), + 12usize, + concat!("Size of: ", stringify!(pad_me)), ); assert_eq!( - ::std::mem::align_of:: < pad_me > (), 4usize, concat!("Alignment of ", - stringify!(pad_me)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(pad_me)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).first) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(pad_me), "::", stringify!(first)) + unsafe { ::std::ptr::addr_of!((*ptr).first) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(pad_me), "::", stringify!(first)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).second) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(pad_me), "::", stringify!(second)) + unsafe { ::std::ptr::addr_of!((*ptr).second) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(pad_me), "::", stringify!(second)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).third) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(pad_me), "::", stringify!(third)) + unsafe { ::std::ptr::addr_of!((*ptr).third) as usize - ptr as usize }, + 8usize, + concat!("Offset of field: ", stringify!(pad_me), "::", stringify!(third)), ); } #[repr(C)] @@ -45,24 +50,29 @@ fn bindgen_test_layout_dont_pad_me() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < dont_pad_me > (), 4usize, concat!("Size of: ", - stringify!(dont_pad_me)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(dont_pad_me)), ); assert_eq!( - ::std::mem::align_of:: < dont_pad_me > (), 4usize, concat!("Alignment of ", - stringify!(dont_pad_me)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(dont_pad_me)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).first) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(dont_pad_me), "::", stringify!(first)) + unsafe { ::std::ptr::addr_of!((*ptr).first) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(dont_pad_me), "::", stringify!(first)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).second) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(dont_pad_me), "::", stringify!(second)) + unsafe { ::std::ptr::addr_of!((*ptr).second) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(dont_pad_me), "::", stringify!(second)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).third) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(dont_pad_me), "::", stringify!(third)) + unsafe { ::std::ptr::addr_of!((*ptr).third) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(dont_pad_me), "::", stringify!(third)), ); } impl Default for dont_pad_me { diff --git a/bindgen-tests/tests/expectations/tests/extern-const-struct.rs b/bindgen-tests/tests/expectations/tests/extern-const-struct.rs index 731291da8c..db62de1460 100644 --- a/bindgen-tests/tests/expectations/tests/extern-const-struct.rs +++ b/bindgen-tests/tests/expectations/tests/extern-const-struct.rs @@ -9,16 +9,19 @@ 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:: < nsFoo > (), 1600usize, concat!("Size of: ", - stringify!(nsFoo)) + ::std::mem::size_of::(), + 1600usize, + concat!("Size of: ", stringify!(nsFoo)), ); assert_eq!( - ::std::mem::align_of:: < nsFoo > (), 4usize, concat!("Alignment of ", - stringify!(nsFoo)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(nsFoo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).details) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(nsFoo), "::", stringify!(details)) + unsafe { ::std::ptr::addr_of!((*ptr).details) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(nsFoo), "::", stringify!(details)), ); } impl Default for nsFoo { diff --git a/bindgen-tests/tests/expectations/tests/field-visibility-callback.rs b/bindgen-tests/tests/expectations/tests/field-visibility-callback.rs index 9411ccc7a6..31d6335700 100644 --- a/bindgen-tests/tests/expectations/tests/field-visibility-callback.rs +++ b/bindgen-tests/tests/expectations/tests/field-visibility-callback.rs @@ -49,7 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -69,7 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -97,21 +97,24 @@ fn bindgen_test_layout_my_struct() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < my_struct > (), 12usize, concat!("Size of: ", - stringify!(my_struct)) + ::std::mem::size_of::(), + 12usize, + concat!("Size of: ", stringify!(my_struct)), ); assert_eq!( - ::std::mem::align_of:: < my_struct > (), 4usize, concat!("Alignment of ", - stringify!(my_struct)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(my_struct)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(my_struct), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(my_struct), "::", stringify!(a)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).private_b) as usize - ptr as usize }, - 4usize, concat!("Offset of field: ", stringify!(my_struct), "::", - stringify!(private_b)) + unsafe { ::std::ptr::addr_of!((*ptr).private_b) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(my_struct), "::", stringify!(private_b)), ); } impl my_struct { diff --git a/bindgen-tests/tests/expectations/tests/field-visibility.rs b/bindgen-tests/tests/expectations/tests/field-visibility.rs index b4e0620867..c898d60b75 100644 --- a/bindgen-tests/tests/expectations/tests/field-visibility.rs +++ b/bindgen-tests/tests/expectations/tests/field-visibility.rs @@ -49,7 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -69,7 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -94,12 +94,14 @@ pub struct my_struct1 { #[test] fn bindgen_test_layout_my_struct1() { assert_eq!( - ::std::mem::size_of:: < my_struct1 > (), 4usize, concat!("Size of: ", - stringify!(my_struct1)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(my_struct1)), ); assert_eq!( - ::std::mem::align_of:: < my_struct1 > (), 4usize, concat!("Alignment of ", - stringify!(my_struct1)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(my_struct1)), ); } impl my_struct1 { @@ -140,12 +142,14 @@ pub struct my_struct2 { #[test] fn bindgen_test_layout_my_struct2() { assert_eq!( - ::std::mem::size_of:: < my_struct2 > (), 4usize, concat!("Size of: ", - stringify!(my_struct2)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(my_struct2)), ); assert_eq!( - ::std::mem::align_of:: < my_struct2 > (), 4usize, concat!("Alignment of ", - stringify!(my_struct2)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(my_struct2)), ); } impl my_struct2 { diff --git a/bindgen-tests/tests/expectations/tests/forward-declaration-autoptr.rs b/bindgen-tests/tests/expectations/tests/forward-declaration-autoptr.rs index 67de3b4b99..7c483638eb 100644 --- a/bindgen-tests/tests/expectations/tests/forward-declaration-autoptr.rs +++ b/bindgen-tests/tests/expectations/tests/forward-declaration-autoptr.rs @@ -29,15 +29,19 @@ 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:: < Bar > (), 8usize, concat!("Size of: ", stringify!(Bar)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Bar)), ); assert_eq!( - ::std::mem::align_of:: < Bar > (), 8usize, concat!("Alignment of ", - stringify!(Bar)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Bar)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).m_member) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(Bar), "::", stringify!(m_member)) + unsafe { ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(m_member)), ); } impl Default for Bar { @@ -52,11 +56,13 @@ impl Default for Bar { #[test] fn __bindgen_test_layout_RefPtr_open0_Foo_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < RefPtr < Foo > > (), 8usize, - concat!("Size of template specialization: ", stringify!(RefPtr < Foo >)) + ::std::mem::size_of::>(), + 8usize, + concat!("Size of template specialization: ", stringify!(RefPtr < Foo >)), ); assert_eq!( - ::std::mem::align_of:: < RefPtr < Foo > > (), 8usize, - concat!("Alignment of template specialization: ", stringify!(RefPtr < Foo >)) + ::std::mem::align_of::>(), + 8usize, + concat!("Alignment of template specialization: ", stringify!(RefPtr < Foo >)), ); } diff --git a/bindgen-tests/tests/expectations/tests/forward_declared_complex_types.rs b/bindgen-tests/tests/expectations/tests/forward_declared_complex_types.rs index 47c31cddd0..5a8d5aebaf 100644 --- a/bindgen-tests/tests/expectations/tests/forward_declared_complex_types.rs +++ b/bindgen-tests/tests/expectations/tests/forward_declared_complex_types.rs @@ -7,12 +7,14 @@ pub struct Foo_empty { #[test] fn bindgen_test_layout_Foo_empty() { assert_eq!( - ::std::mem::size_of:: < Foo_empty > (), 1usize, concat!("Size of: ", - stringify!(Foo_empty)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo_empty)), ); assert_eq!( - ::std::mem::align_of:: < Foo_empty > (), 1usize, concat!("Alignment of ", - stringify!(Foo_empty)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo_empty)), ); } #[repr(C)] @@ -30,15 +32,19 @@ 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:: < Bar > (), 8usize, concat!("Size of: ", stringify!(Bar)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Bar)), ); assert_eq!( - ::std::mem::align_of:: < Bar > (), 8usize, concat!("Alignment of ", - stringify!(Bar)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Bar)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).f) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(f)) + unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(f)), ); } impl Default for Bar { diff --git a/bindgen-tests/tests/expectations/tests/forward_declared_complex_types_1_0.rs b/bindgen-tests/tests/expectations/tests/forward_declared_complex_types_1_0.rs index ba6a77af52..e03884bfe6 100644 --- a/bindgen-tests/tests/expectations/tests/forward_declared_complex_types_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/forward_declared_complex_types_1_0.rs @@ -7,12 +7,14 @@ pub struct Foo_empty { #[test] fn bindgen_test_layout_Foo_empty() { assert_eq!( - ::std::mem::size_of:: < Foo_empty > (), 1usize, concat!("Size of: ", - stringify!(Foo_empty)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo_empty)), ); assert_eq!( - ::std::mem::align_of:: < Foo_empty > (), 1usize, concat!("Alignment of ", - stringify!(Foo_empty)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo_empty)), ); } impl Clone for Foo_empty { @@ -40,15 +42,19 @@ 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:: < Bar > (), 8usize, concat!("Size of: ", stringify!(Bar)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Bar)), ); assert_eq!( - ::std::mem::align_of:: < Bar > (), 8usize, concat!("Alignment of ", - stringify!(Bar)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Bar)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).f) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(f)) + unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(f)), ); } impl Clone for Bar { diff --git a/bindgen-tests/tests/expectations/tests/forward_declared_struct.rs b/bindgen-tests/tests/expectations/tests/forward_declared_struct.rs index bcbe3ac99a..8960ff11b3 100644 --- a/bindgen-tests/tests/expectations/tests/forward_declared_struct.rs +++ b/bindgen-tests/tests/expectations/tests/forward_declared_struct.rs @@ -8,15 +8,16 @@ pub struct a { 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::(), 4usize, concat!("Size of: ", stringify!(a))); assert_eq!( - ::std::mem::size_of:: < a > (), 4usize, concat!("Size of: ", stringify!(a)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(a)), ); assert_eq!( - ::std::mem::align_of:: < a > (), 4usize, concat!("Alignment of ", stringify!(a)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(a), "::", stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(a), "::", stringify!(b)), ); } #[repr(C)] @@ -28,14 +29,15 @@ pub struct c { 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::(), 4usize, concat!("Size of: ", stringify!(c))); assert_eq!( - ::std::mem::size_of:: < c > (), 4usize, concat!("Size of: ", stringify!(c)) - ); - assert_eq!( - ::std::mem::align_of:: < c > (), 4usize, concat!("Alignment of ", stringify!(c)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(c)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).d) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(c), "::", stringify!(d)) + unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(c), "::", stringify!(d)), ); } diff --git a/bindgen-tests/tests/expectations/tests/func_ptr_in_struct.rs b/bindgen-tests/tests/expectations/tests/func_ptr_in_struct.rs index f606d57289..d0ba38ad3a 100644 --- a/bindgen-tests/tests/expectations/tests/func_ptr_in_struct.rs +++ b/bindgen-tests/tests/expectations/tests/func_ptr_in_struct.rs @@ -16,14 +16,18 @@ 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:: < Foo > (), 8usize, concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Foo)), ); assert_eq!( - ::std::mem::align_of:: < Foo > (), 8usize, concat!("Alignment of ", - stringify!(Foo)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)), ); } diff --git a/bindgen-tests/tests/expectations/tests/func_return_must_use.rs b/bindgen-tests/tests/expectations/tests/func_return_must_use.rs index 2cfd163cac..e12c433c22 100644 --- a/bindgen-tests/tests/expectations/tests/func_return_must_use.rs +++ b/bindgen-tests/tests/expectations/tests/func_return_must_use.rs @@ -31,12 +31,14 @@ pub struct AnnotatedStruct {} #[test] fn bindgen_test_layout_AnnotatedStruct() { assert_eq!( - ::std::mem::size_of:: < AnnotatedStruct > (), 0usize, concat!("Size of: ", - stringify!(AnnotatedStruct)) + ::std::mem::size_of::(), + 0usize, + concat!("Size of: ", stringify!(AnnotatedStruct)), ); assert_eq!( - ::std::mem::align_of:: < AnnotatedStruct > (), 1usize, concat!("Alignment of ", - stringify!(AnnotatedStruct)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(AnnotatedStruct)), ); } extern "C" { @@ -49,12 +51,14 @@ pub struct PlainStruct {} #[test] fn bindgen_test_layout_PlainStruct() { assert_eq!( - ::std::mem::size_of:: < PlainStruct > (), 0usize, concat!("Size of: ", - stringify!(PlainStruct)) + ::std::mem::size_of::(), + 0usize, + concat!("Size of: ", stringify!(PlainStruct)), ); assert_eq!( - ::std::mem::align_of:: < PlainStruct > (), 1usize, concat!("Alignment of ", - stringify!(PlainStruct)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(PlainStruct)), ); } ///
diff --git a/bindgen-tests/tests/expectations/tests/gen-constructors-neg.rs b/bindgen-tests/tests/expectations/tests/gen-constructors-neg.rs index d16596b591..d51ccfa80c 100644 --- a/bindgen-tests/tests/expectations/tests/gen-constructors-neg.rs +++ b/bindgen-tests/tests/expectations/tests/gen-constructors-neg.rs @@ -7,10 +7,13 @@ pub struct Foo { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo)), ); assert_eq!( - ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", - stringify!(Foo)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)), ); } diff --git a/bindgen-tests/tests/expectations/tests/gen-constructors.rs b/bindgen-tests/tests/expectations/tests/gen-constructors.rs index ae882bfeba..b46ee61a16 100644 --- a/bindgen-tests/tests/expectations/tests/gen-constructors.rs +++ b/bindgen-tests/tests/expectations/tests/gen-constructors.rs @@ -7,11 +7,14 @@ pub struct Foo { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo)), ); assert_eq!( - ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", - stringify!(Foo)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)), ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/gen-destructors-neg.rs b/bindgen-tests/tests/expectations/tests/gen-destructors-neg.rs index 0959bdfbd9..67f00f79ee 100644 --- a/bindgen-tests/tests/expectations/tests/gen-destructors-neg.rs +++ b/bindgen-tests/tests/expectations/tests/gen-destructors-neg.rs @@ -9,14 +9,18 @@ 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:: < Foo > (), 4usize, concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Foo)), ); assert_eq!( - ::std::mem::align_of:: < Foo > (), 4usize, concat!("Alignment of ", - stringify!(Foo)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)), ); } diff --git a/bindgen-tests/tests/expectations/tests/gen-destructors.rs b/bindgen-tests/tests/expectations/tests/gen-destructors.rs index 43d122963e..47adf19cce 100644 --- a/bindgen-tests/tests/expectations/tests/gen-destructors.rs +++ b/bindgen-tests/tests/expectations/tests/gen-destructors.rs @@ -9,15 +9,19 @@ 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:: < Foo > (), 4usize, concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Foo)), ); assert_eq!( - ::std::mem::align_of:: < Foo > (), 4usize, concat!("Alignment of ", - stringify!(Foo)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)), ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/generate-inline.rs b/bindgen-tests/tests/expectations/tests/generate-inline.rs index 6be11f5cc7..ce34c1ec17 100644 --- a/bindgen-tests/tests/expectations/tests/generate-inline.rs +++ b/bindgen-tests/tests/expectations/tests/generate-inline.rs @@ -7,11 +7,14 @@ pub struct Foo { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo)), ); assert_eq!( - ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", - stringify!(Foo)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)), ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/i128.rs b/bindgen-tests/tests/expectations/tests/i128.rs index a988562c6f..0c7c5e0223 100644 --- a/bindgen-tests/tests/expectations/tests/i128.rs +++ b/bindgen-tests/tests/expectations/tests/i128.rs @@ -11,20 +11,23 @@ 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:: < foo > (), 32usize, concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of::(), + 32usize, + concat!("Size of: ", stringify!(foo)), ); assert_eq!( - ::std::mem::align_of:: < foo > (), 16usize, concat!("Alignment of ", - stringify!(foo)) + ::std::mem::align_of::(), + 16usize, + concat!("Alignment of ", stringify!(foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).my_signed) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(foo), "::", - stringify!(my_signed)) + unsafe { ::std::ptr::addr_of!((*ptr).my_signed) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(my_signed)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).my_unsigned) as usize - ptr as usize }, - 16usize, concat!("Offset of field: ", stringify!(foo), "::", - stringify!(my_unsigned)) + unsafe { ::std::ptr::addr_of!((*ptr).my_unsigned) as usize - ptr as usize }, + 16usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(my_unsigned)), ); } diff --git a/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs b/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs index 2c7966c371..4a14802d88 100644 --- a/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs +++ b/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs @@ -49,7 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -69,7 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -123,11 +123,14 @@ pub struct foo { #[test] fn bindgen_test_layout_foo() { assert_eq!( - ::std::mem::size_of:: < foo > (), 8usize, concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(foo)), ); assert_eq!( - ::std::mem::align_of:: < foo > (), 8usize, concat!("Alignment of ", - stringify!(foo)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(foo)), ); } impl Default for foo { diff --git a/bindgen-tests/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs b/bindgen-tests/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs index 1902b1b971..08f186d92b 100644 --- a/bindgen-tests/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs +++ b/bindgen-tests/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs @@ -27,12 +27,14 @@ pub struct DerivedWithNoVirtualMethods { #[test] fn bindgen_test_layout_DerivedWithNoVirtualMethods() { assert_eq!( - ::std::mem::size_of:: < DerivedWithNoVirtualMethods > (), 16usize, - concat!("Size of: ", stringify!(DerivedWithNoVirtualMethods)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(DerivedWithNoVirtualMethods)), ); assert_eq!( - ::std::mem::align_of:: < DerivedWithNoVirtualMethods > (), 8usize, - concat!("Alignment of ", stringify!(DerivedWithNoVirtualMethods)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(DerivedWithNoVirtualMethods)), ); } impl Default for DerivedWithNoVirtualMethods { @@ -53,12 +55,14 @@ pub struct DerivedWithVirtualMethods { #[test] fn bindgen_test_layout_DerivedWithVirtualMethods() { assert_eq!( - ::std::mem::size_of:: < DerivedWithVirtualMethods > (), 16usize, - concat!("Size of: ", stringify!(DerivedWithVirtualMethods)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(DerivedWithVirtualMethods)), ); assert_eq!( - ::std::mem::align_of:: < DerivedWithVirtualMethods > (), 8usize, - concat!("Alignment of ", stringify!(DerivedWithVirtualMethods)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(DerivedWithVirtualMethods)), ); } impl Default for DerivedWithVirtualMethods { @@ -98,12 +102,14 @@ pub struct DerivedWithVtable { #[test] fn bindgen_test_layout_DerivedWithVtable() { assert_eq!( - ::std::mem::size_of:: < DerivedWithVtable > (), 16usize, concat!("Size of: ", - stringify!(DerivedWithVtable)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(DerivedWithVtable)), ); assert_eq!( - ::std::mem::align_of:: < DerivedWithVtable > (), 8usize, concat!("Alignment of ", - stringify!(DerivedWithVtable)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(DerivedWithVtable)), ); } impl Default for DerivedWithVtable { @@ -124,12 +130,14 @@ pub struct DerivedWithoutVtable { #[test] fn bindgen_test_layout_DerivedWithoutVtable() { assert_eq!( - ::std::mem::size_of:: < DerivedWithoutVtable > (), 8usize, concat!("Size of: ", - stringify!(DerivedWithoutVtable)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(DerivedWithoutVtable)), ); assert_eq!( - ::std::mem::align_of:: < DerivedWithoutVtable > (), 8usize, - concat!("Alignment of ", stringify!(DerivedWithoutVtable)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(DerivedWithoutVtable)), ); } impl Default for DerivedWithoutVtable { @@ -144,52 +152,76 @@ impl Default for DerivedWithoutVtable { #[test] fn __bindgen_test_layout_BaseWithVtable_open0_ptr_char_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < BaseWithVtable < * mut ::std::os::raw::c_char > > (), - 16usize, concat!("Size of template specialization: ", stringify!(BaseWithVtable < - * mut ::std::os::raw::c_char >)) + ::std::mem::size_of::>(), + 16usize, + concat!( + "Size of template specialization: ", + stringify!(BaseWithVtable < * mut ::std::os::raw::c_char >), + ), ); assert_eq!( - ::std::mem::align_of:: < BaseWithVtable < * mut ::std::os::raw::c_char > > (), - 8usize, concat!("Alignment of template specialization: ", - stringify!(BaseWithVtable < * mut ::std::os::raw::c_char >)) + ::std::mem::align_of::>(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(BaseWithVtable < * mut ::std::os::raw::c_char >), + ), ); } #[test] fn __bindgen_test_layout_BaseWithVtable_open0_ptr_char_close0_instantiation_1() { assert_eq!( - ::std::mem::size_of:: < BaseWithVtable < * mut ::std::os::raw::c_char > > (), - 16usize, concat!("Size of template specialization: ", stringify!(BaseWithVtable < - * mut ::std::os::raw::c_char >)) + ::std::mem::size_of::>(), + 16usize, + concat!( + "Size of template specialization: ", + stringify!(BaseWithVtable < * mut ::std::os::raw::c_char >), + ), ); assert_eq!( - ::std::mem::align_of:: < BaseWithVtable < * mut ::std::os::raw::c_char > > (), - 8usize, concat!("Alignment of template specialization: ", - stringify!(BaseWithVtable < * mut ::std::os::raw::c_char >)) + ::std::mem::align_of::>(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(BaseWithVtable < * mut ::std::os::raw::c_char >), + ), ); } #[test] fn __bindgen_test_layout_BaseWithoutVtable_open0_ptr_char_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < BaseWithoutVtable < * mut ::std::os::raw::c_char > > (), - 8usize, concat!("Size of template specialization: ", stringify!(BaseWithoutVtable - < * mut ::std::os::raw::c_char >)) + ::std::mem::size_of::>(), + 8usize, + concat!( + "Size of template specialization: ", + stringify!(BaseWithoutVtable < * mut ::std::os::raw::c_char >), + ), ); assert_eq!( - ::std::mem::align_of:: < BaseWithoutVtable < * mut ::std::os::raw::c_char > > (), - 8usize, concat!("Alignment of template specialization: ", - stringify!(BaseWithoutVtable < * mut ::std::os::raw::c_char >)) + ::std::mem::align_of::>(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(BaseWithoutVtable < * mut ::std::os::raw::c_char >), + ), ); } #[test] fn __bindgen_test_layout_BaseWithoutVtable_open0_ptr_char_close0_instantiation_1() { assert_eq!( - ::std::mem::size_of:: < BaseWithoutVtable < * mut ::std::os::raw::c_char > > (), - 8usize, concat!("Size of template specialization: ", stringify!(BaseWithoutVtable - < * mut ::std::os::raw::c_char >)) + ::std::mem::size_of::>(), + 8usize, + concat!( + "Size of template specialization: ", + stringify!(BaseWithoutVtable < * mut ::std::os::raw::c_char >), + ), ); assert_eq!( - ::std::mem::align_of:: < BaseWithoutVtable < * mut ::std::os::raw::c_char > > (), - 8usize, concat!("Alignment of template specialization: ", - stringify!(BaseWithoutVtable < * mut ::std::os::raw::c_char >)) + ::std::mem::align_of::>(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(BaseWithoutVtable < * mut ::std::os::raw::c_char >), + ), ); } diff --git a/bindgen-tests/tests/expectations/tests/inherit_multiple_interfaces.rs b/bindgen-tests/tests/expectations/tests/inherit_multiple_interfaces.rs index dfb69e4d32..76b2e3bd09 100644 --- a/bindgen-tests/tests/expectations/tests/inherit_multiple_interfaces.rs +++ b/bindgen-tests/tests/expectations/tests/inherit_multiple_interfaces.rs @@ -11,15 +11,16 @@ pub struct A { 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::(), 16usize, concat!("Size of: ", stringify!(A))); assert_eq!( - ::std::mem::size_of:: < A > (), 16usize, concat!("Size of: ", stringify!(A)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(A)), ); assert_eq!( - ::std::mem::align_of:: < A > (), 8usize, concat!("Alignment of ", stringify!(A)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).member) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(member)) + unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, + 8usize, + concat!("Offset of field: ", stringify!(A), "::", stringify!(member)), ); } impl Default for A { @@ -43,15 +44,16 @@ pub struct B { 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::(), 16usize, concat!("Size of: ", stringify!(B))); assert_eq!( - ::std::mem::size_of:: < B > (), 16usize, concat!("Size of: ", stringify!(B)) - ); - assert_eq!( - ::std::mem::align_of:: < B > (), 8usize, concat!("Alignment of ", stringify!(B)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(B)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).member2) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(B), "::", stringify!(member2)) + unsafe { ::std::ptr::addr_of!((*ptr).member2) as usize - ptr as usize }, + 8usize, + concat!("Offset of field: ", stringify!(B), "::", stringify!(member2)), ); } impl Default for B { @@ -74,15 +76,16 @@ pub struct C { 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, concat!("Size of: ", stringify!(C))); assert_eq!( - ::std::mem::size_of:: < C > (), 40usize, concat!("Size of: ", stringify!(C)) - ); - assert_eq!( - ::std::mem::align_of:: < C > (), 8usize, concat!("Alignment of ", stringify!(C)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(C)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).member3) as usize - ptr as usize }, - 32usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(member3)) + unsafe { ::std::ptr::addr_of!((*ptr).member3) as usize - ptr as usize }, + 32usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(member3)), ); } impl Default for C { diff --git a/bindgen-tests/tests/expectations/tests/inherit_typedef.rs b/bindgen-tests/tests/expectations/tests/inherit_typedef.rs index bd4f358a08..1d48635962 100644 --- a/bindgen-tests/tests/expectations/tests/inherit_typedef.rs +++ b/bindgen-tests/tests/expectations/tests/inherit_typedef.rs @@ -7,11 +7,14 @@ pub struct Foo { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo)), ); assert_eq!( - ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", - stringify!(Foo)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)), ); } pub type TypedefedFoo = Foo; @@ -23,10 +26,13 @@ pub struct Bar { #[test] fn bindgen_test_layout_Bar() { assert_eq!( - ::std::mem::size_of:: < Bar > (), 1usize, concat!("Size of: ", stringify!(Bar)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Bar)), ); assert_eq!( - ::std::mem::align_of:: < Bar > (), 1usize, concat!("Alignment of ", - stringify!(Bar)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Bar)), ); } diff --git a/bindgen-tests/tests/expectations/tests/inline_namespace.rs b/bindgen-tests/tests/expectations/tests/inline_namespace.rs index 2764065e29..124542ba75 100644 --- a/bindgen-tests/tests/expectations/tests/inline_namespace.rs +++ b/bindgen-tests/tests/expectations/tests/inline_namespace.rs @@ -18,16 +18,19 @@ pub mod root { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < Bar > (), 4usize, concat!("Size of: ", - stringify!(Bar)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Bar)), ); assert_eq!( - ::std::mem::align_of:: < Bar > (), 4usize, concat!("Alignment of ", - stringify!(Bar)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Bar)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).baz) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz)) + unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz)), ); } } diff --git a/bindgen-tests/tests/expectations/tests/inline_namespace_conservative.rs b/bindgen-tests/tests/expectations/tests/inline_namespace_conservative.rs index 510cfacc04..957d7e880a 100644 --- a/bindgen-tests/tests/expectations/tests/inline_namespace_conservative.rs +++ b/bindgen-tests/tests/expectations/tests/inline_namespace_conservative.rs @@ -23,16 +23,19 @@ pub mod root { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < Bar > (), 4usize, concat!("Size of: ", - stringify!(Bar)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Bar)), ); assert_eq!( - ::std::mem::align_of:: < Bar > (), 4usize, concat!("Alignment of ", - stringify!(Bar)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Bar)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).baz) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz)) + unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz)), ); } } diff --git a/bindgen-tests/tests/expectations/tests/inner_const.rs b/bindgen-tests/tests/expectations/tests/inner_const.rs index 78f178e0c6..6afa16bbac 100644 --- a/bindgen-tests/tests/expectations/tests/inner_const.rs +++ b/bindgen-tests/tests/expectations/tests/inner_const.rs @@ -17,14 +17,18 @@ 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:: < Foo > (), 4usize, concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Foo)), ); assert_eq!( - ::std::mem::align_of:: < Foo > (), 4usize, concat!("Alignment of ", - stringify!(Foo)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)), ); } diff --git a/bindgen-tests/tests/expectations/tests/inner_template_self.rs b/bindgen-tests/tests/expectations/tests/inner_template_self.rs index 49de8a6319..ecfe079d66 100644 --- a/bindgen-tests/tests/expectations/tests/inner_template_self.rs +++ b/bindgen-tests/tests/expectations/tests/inner_template_self.rs @@ -24,16 +24,19 @@ fn bindgen_test_layout_InstantiateIt() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < InstantiateIt > (), 16usize, concat!("Size of: ", - stringify!(InstantiateIt)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(InstantiateIt)), ); assert_eq!( - ::std::mem::align_of:: < InstantiateIt > (), 8usize, concat!("Alignment of ", - stringify!(InstantiateIt)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(InstantiateIt)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).m_list) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(InstantiateIt), "::", stringify!(m_list)) + unsafe { ::std::ptr::addr_of!((*ptr).m_list) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(InstantiateIt), "::", stringify!(m_list)), ); } impl Default for InstantiateIt { @@ -48,11 +51,13 @@ impl Default for InstantiateIt { #[test] fn __bindgen_test_layout_LinkedList_open0_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < LinkedList > (), 16usize, - concat!("Size of template specialization: ", stringify!(LinkedList)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of template specialization: ", stringify!(LinkedList)), ); assert_eq!( - ::std::mem::align_of:: < LinkedList > (), 8usize, - concat!("Alignment of template specialization: ", stringify!(LinkedList)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of template specialization: ", stringify!(LinkedList)), ); } diff --git a/bindgen-tests/tests/expectations/tests/issue-1034.rs b/bindgen-tests/tests/expectations/tests/issue-1034.rs index f626f9cb84..0bd7647aa0 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1034.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1034.rs @@ -49,7 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -69,7 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -92,11 +92,14 @@ pub struct S2 { #[test] fn bindgen_test_layout_S2() { assert_eq!( - ::std::mem::size_of:: < S2 > (), 2usize, concat!("Size of: ", stringify!(S2)) + ::std::mem::size_of::(), + 2usize, + concat!("Size of: ", stringify!(S2)), ); assert_eq!( - ::std::mem::align_of:: < S2 > (), 1usize, concat!("Alignment of ", - stringify!(S2)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(S2)), ); } impl S2 { diff --git a/bindgen-tests/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs b/bindgen-tests/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs index 5ece85654e..d88806954f 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs @@ -49,7 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -69,7 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -92,11 +92,14 @@ pub struct S1 { #[test] fn bindgen_test_layout_S1() { assert_eq!( - ::std::mem::size_of:: < S1 > (), 3usize, concat!("Size of: ", stringify!(S1)) + ::std::mem::size_of::(), + 3usize, + concat!("Size of: ", stringify!(S1)), ); assert_eq!( - ::std::mem::align_of:: < S1 > (), 1usize, concat!("Alignment of ", - stringify!(S1)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(S1)), ); } impl S1 { diff --git a/bindgen-tests/tests/expectations/tests/issue-1118-using-forward-decl.rs b/bindgen-tests/tests/expectations/tests/issue-1118-using-forward-decl.rs index d602ff8835..2c60226142 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1118-using-forward-decl.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1118-using-forward-decl.rs @@ -10,16 +10,19 @@ fn bindgen_test_layout_nsTArray_base() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < nsTArray_base > (), 8usize, concat!("Size of: ", - stringify!(nsTArray_base)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(nsTArray_base)), ); assert_eq!( - ::std::mem::align_of:: < nsTArray_base > (), 8usize, concat!("Alignment of ", - stringify!(nsTArray_base)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(nsTArray_base)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).d) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(nsTArray_base), "::", stringify!(d)) + unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(nsTArray_base), "::", stringify!(d)), ); } impl Default for nsTArray_base { @@ -55,16 +58,19 @@ fn bindgen_test_layout_nsIContent() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < nsIContent > (), 8usize, concat!("Size of: ", - stringify!(nsIContent)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(nsIContent)), ); assert_eq!( - ::std::mem::align_of:: < nsIContent > (), 8usize, concat!("Alignment of ", - stringify!(nsIContent)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(nsIContent)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).foo) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(nsIContent), "::", stringify!(foo)) + unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(nsIContent), "::", stringify!(foo)), ); } impl Default for nsIContent { @@ -83,22 +89,26 @@ extern "C" { #[test] fn __bindgen_test_layout_nsTArray_open0_ptr_nsIContent_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < nsTArray > (), 8usize, - concat!("Size of template specialization: ", stringify!(nsTArray)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of template specialization: ", stringify!(nsTArray)), ); assert_eq!( - ::std::mem::align_of:: < nsTArray > (), 8usize, - concat!("Alignment of template specialization: ", stringify!(nsTArray)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of template specialization: ", stringify!(nsTArray)), ); } #[test] fn __bindgen_test_layout_nsTArray_open0_ptr_nsIContent_close0_instantiation_1() { assert_eq!( - ::std::mem::size_of:: < nsTArray > (), 8usize, - concat!("Size of template specialization: ", stringify!(nsTArray)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of template specialization: ", stringify!(nsTArray)), ); assert_eq!( - ::std::mem::align_of:: < nsTArray > (), 8usize, - concat!("Alignment of template specialization: ", stringify!(nsTArray)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of template specialization: ", stringify!(nsTArray)), ); } diff --git a/bindgen-tests/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs b/bindgen-tests/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs index 83bb62df9e..45ffb3d8b3 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs @@ -9,11 +9,14 @@ pub struct Foo { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of:: < Foo > (), 8usize, concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Foo)), ); assert_eq!( - ::std::mem::align_of:: < Foo > (), 8usize, concat!("Alignment of ", - stringify!(Foo)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Foo)), ); } impl Default for Foo { diff --git a/bindgen-tests/tests/expectations/tests/issue-1216-variadic-member.rs b/bindgen-tests/tests/expectations/tests/issue-1216-variadic-member.rs index 7c4fb568c9..f7bbeba92b 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1216-variadic-member.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1216-variadic-member.rs @@ -19,14 +19,18 @@ 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:: < Foo > (), 8usize, concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Foo)), ); assert_eq!( - ::std::mem::align_of:: < Foo > (), 8usize, concat!("Alignment of ", - stringify!(Foo)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).f) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(f)) + unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(f)), ); } diff --git a/bindgen-tests/tests/expectations/tests/issue-1281.rs b/bindgen-tests/tests/expectations/tests/issue-1281.rs index 61e2c3690a..8e0096c904 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1281.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1281.rs @@ -14,15 +14,19 @@ 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:: < foo > (), 4usize, concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo)), ); assert_eq!( - ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", - stringify!(foo)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).foo) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(foo)) + unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(foo)), ); } #[test] @@ -30,15 +34,19 @@ 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:: < bar > (), 4usize, concat!("Size of: ", stringify!(bar)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(bar)), ); assert_eq!( - ::std::mem::align_of:: < bar > (), 4usize, concat!("Alignment of ", - stringify!(bar)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(bar)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).u) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(bar), "::", stringify!(u)) + unsafe { ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(bar), "::", stringify!(u)), ); } pub type bar_t = bar; @@ -52,14 +60,18 @@ 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:: < baz > (), 4usize, concat!("Size of: ", stringify!(baz)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(baz)), ); assert_eq!( - ::std::mem::align_of:: < baz > (), 4usize, concat!("Alignment of ", - stringify!(baz)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(baz)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).f) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(baz), "::", stringify!(f)) + unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(baz), "::", stringify!(f)), ); } diff --git a/bindgen-tests/tests/expectations/tests/issue-1285.rs b/bindgen-tests/tests/expectations/tests/issue-1285.rs index 322bcdd288..506b6a8819 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1285.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1285.rs @@ -15,20 +15,24 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Size of: ", - stringify!(foo__bindgen_ty_1)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", - stringify!(foo__bindgen_ty_1)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)), ); } impl Default for foo__bindgen_ty_1 { @@ -45,15 +49,19 @@ 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:: < foo > (), 4usize, concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo)), ); assert_eq!( - ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", - stringify!(foo)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)), ); } impl Default for foo { diff --git a/bindgen-tests/tests/expectations/tests/issue-1291.rs b/bindgen-tests/tests/expectations/tests/issue-1291.rs index c7bb3efdab..1a9e14518b 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1291.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1291.rs @@ -24,71 +24,88 @@ 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:: < RTCRay > (), 96usize, concat!("Size of: ", - stringify!(RTCRay)) + ::std::mem::size_of::(), + 96usize, + concat!("Size of: ", stringify!(RTCRay)), ); assert_eq!( - ::std::mem::align_of:: < RTCRay > (), 16usize, concat!("Alignment of ", - stringify!(RTCRay)) + ::std::mem::align_of::(), + 16usize, + concat!("Alignment of ", stringify!(RTCRay)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).org) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(org)) + unsafe { ::std::ptr::addr_of!((*ptr).org) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(org)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).align0) as usize - ptr as usize }, 12usize, - concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(align0)) + unsafe { ::std::ptr::addr_of!((*ptr).align0) as usize - ptr as usize }, + 12usize, + concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(align0)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).dir) as usize - ptr as usize }, 16usize, - concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(dir)) + unsafe { ::std::ptr::addr_of!((*ptr).dir) as usize - ptr as usize }, + 16usize, + concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(dir)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).align1) as usize - ptr as usize }, 28usize, - concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(align1)) + unsafe { ::std::ptr::addr_of!((*ptr).align1) as usize - ptr as usize }, + 28usize, + concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(align1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).tnear) as usize - ptr as usize }, 32usize, - concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(tnear)) + unsafe { ::std::ptr::addr_of!((*ptr).tnear) as usize - ptr as usize }, + 32usize, + concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(tnear)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).tfar) as usize - ptr as usize }, 36usize, - concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(tfar)) + unsafe { ::std::ptr::addr_of!((*ptr).tfar) as usize - ptr as usize }, + 36usize, + concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(tfar)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).time) as usize - ptr as usize }, 40usize, - concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(time)) + unsafe { ::std::ptr::addr_of!((*ptr).time) as usize - ptr as usize }, + 40usize, + concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(time)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mask) as usize - ptr as usize }, 44usize, - concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(mask)) + unsafe { ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize }, + 44usize, + concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(mask)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).Ng) as usize - ptr as usize }, 48usize, - concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(Ng)) + unsafe { ::std::ptr::addr_of!((*ptr).Ng) as usize - ptr as usize }, + 48usize, + concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(Ng)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).align2) as usize - ptr as usize }, 60usize, - concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(align2)) + unsafe { ::std::ptr::addr_of!((*ptr).align2) as usize - ptr as usize }, + 60usize, + concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(align2)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).u) as usize - ptr as usize }, 64usize, - concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(u)) + unsafe { ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize }, + 64usize, + concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(u)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).v) as usize - ptr as usize }, 68usize, - concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(v)) + unsafe { ::std::ptr::addr_of!((*ptr).v) as usize - ptr as usize }, + 68usize, + concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(v)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).geomID) as usize - ptr as usize }, 72usize, - concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(geomID)) + unsafe { ::std::ptr::addr_of!((*ptr).geomID) as usize - ptr as usize }, + 72usize, + concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(geomID)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).primID) as usize - ptr as usize }, 76usize, - concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(primID)) + unsafe { ::std::ptr::addr_of!((*ptr).primID) as usize - ptr as usize }, + 76usize, + concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(primID)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).instID) as usize - ptr as usize }, 80usize, - concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(instID)) + unsafe { ::std::ptr::addr_of!((*ptr).instID) as usize - ptr as usize }, + 80usize, + concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(instID)), ); } diff --git a/bindgen-tests/tests/expectations/tests/issue-1382-rust-primitive-types.rs b/bindgen-tests/tests/expectations/tests/issue-1382-rust-primitive-types.rs index 2c45a20d6e..8dbed446af 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1382-rust-primitive-types.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1382-rust-primitive-types.rs @@ -30,66 +30,83 @@ 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:: < Foo > (), 56usize, concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of::(), + 56usize, + concat!("Size of: ", stringify!(Foo)), ); assert_eq!( - ::std::mem::align_of:: < Foo > (), 4usize, concat!("Alignment of ", - stringify!(Foo)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).i8_) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i8_)) + unsafe { ::std::ptr::addr_of!((*ptr).i8_) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i8_)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).u8_) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u8_)) + unsafe { ::std::ptr::addr_of!((*ptr).u8_) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u8_)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).i16_) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i16_)) + unsafe { ::std::ptr::addr_of!((*ptr).i16_) as usize - ptr as usize }, + 8usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i16_)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).u16_) as usize - ptr as usize }, 12usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u16_)) + unsafe { ::std::ptr::addr_of!((*ptr).u16_) as usize - ptr as usize }, + 12usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u16_)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).i32_) as usize - ptr as usize }, 16usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i32_)) + unsafe { ::std::ptr::addr_of!((*ptr).i32_) as usize - ptr as usize }, + 16usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i32_)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).u32_) as usize - ptr as usize }, 20usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u32_)) + unsafe { ::std::ptr::addr_of!((*ptr).u32_) as usize - ptr as usize }, + 20usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u32_)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).i64_) as usize - ptr as usize }, 24usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i64_)) + unsafe { ::std::ptr::addr_of!((*ptr).i64_) as usize - ptr as usize }, + 24usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i64_)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).u64_) as usize - ptr as usize }, 28usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u64_)) + unsafe { ::std::ptr::addr_of!((*ptr).u64_) as usize - ptr as usize }, + 28usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u64_)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).i128_) as usize - ptr as usize }, 32usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i128_)) + unsafe { ::std::ptr::addr_of!((*ptr).i128_) as usize - ptr as usize }, + 32usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i128_)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).u128_) as usize - ptr as usize }, 36usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u128_)) + unsafe { ::std::ptr::addr_of!((*ptr).u128_) as usize - ptr as usize }, + 36usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u128_)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).isize_) as usize - ptr as usize }, 40usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(isize_)) + unsafe { ::std::ptr::addr_of!((*ptr).isize_) as usize - ptr as usize }, + 40usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(isize_)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).usize_) as usize - ptr as usize }, 44usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(usize_)) + unsafe { ::std::ptr::addr_of!((*ptr).usize_) as usize - ptr as usize }, + 44usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(usize_)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).f32_) as usize - ptr as usize }, 48usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(f32_)) + unsafe { ::std::ptr::addr_of!((*ptr).f32_) as usize - ptr as usize }, + 48usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(f32_)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).f64_) as usize - ptr as usize }, 52usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(f64_)) + unsafe { ::std::ptr::addr_of!((*ptr).f64_) as usize - ptr as usize }, + 52usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(f64_)), ); } diff --git a/bindgen-tests/tests/expectations/tests/issue-1443.rs b/bindgen-tests/tests/expectations/tests/issue-1443.rs index 32aae6c379..16ad2ca437 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1443.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1443.rs @@ -15,19 +15,24 @@ 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:: < Bar > (), 16usize, concat!("Size of: ", stringify!(Bar)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(Bar)), ); assert_eq!( - ::std::mem::align_of:: < Bar > (), 8usize, concat!("Alignment of ", - stringify!(Bar)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Bar)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).f) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(f)) + unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(f)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).m) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(m)) + unsafe { ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize }, + 8usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(m)), ); } impl Default for Bar { @@ -50,19 +55,24 @@ 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:: < Baz > (), 16usize, concat!("Size of: ", stringify!(Baz)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(Baz)), ); assert_eq!( - ::std::mem::align_of:: < Baz > (), 8usize, concat!("Alignment of ", - stringify!(Baz)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Baz)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).f) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Baz), "::", stringify!(f)) + unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Baz), "::", stringify!(f)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).m) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(Baz), "::", stringify!(m)) + unsafe { ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize }, + 8usize, + concat!("Offset of field: ", stringify!(Baz), "::", stringify!(m)), ); } impl Default for Baz { @@ -85,19 +95,24 @@ fn bindgen_test_layout_Tar() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < Tar > (), 16usize, concat!("Size of: ", stringify!(Tar)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(Tar)), ); assert_eq!( - ::std::mem::align_of:: < Tar > (), 8usize, concat!("Alignment of ", - stringify!(Tar)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Tar)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).f) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Tar), "::", stringify!(f)) + unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Tar), "::", stringify!(f)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).m) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(Tar), "::", stringify!(m)) + unsafe { ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize }, + 8usize, + concat!("Offset of field: ", stringify!(Tar), "::", stringify!(m)), ); } impl Default for Tar { @@ -120,19 +135,24 @@ fn bindgen_test_layout_Taz() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < Taz > (), 16usize, concat!("Size of: ", stringify!(Taz)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(Taz)), ); assert_eq!( - ::std::mem::align_of:: < Taz > (), 8usize, concat!("Alignment of ", - stringify!(Taz)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Taz)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).f) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Taz), "::", stringify!(f)) + unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Taz), "::", stringify!(f)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).m) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(Taz), "::", stringify!(m)) + unsafe { ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize }, + 8usize, + concat!("Offset of field: ", stringify!(Taz), "::", stringify!(m)), ); } impl Default for Taz { diff --git a/bindgen-tests/tests/expectations/tests/issue-1454.rs b/bindgen-tests/tests/expectations/tests/issue-1454.rs index 188a2eb09f..9a6052c9ea 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1454.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1454.rs @@ -12,15 +12,18 @@ fn bindgen_test_layout_local_type() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < local_type > (), 0usize, concat!("Size of: ", - stringify!(local_type)) + ::std::mem::size_of::(), + 0usize, + concat!("Size of: ", stringify!(local_type)), ); assert_eq!( - ::std::mem::align_of:: < local_type > (), 1usize, concat!("Alignment of ", - stringify!(local_type)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(local_type)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).inner) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(local_type), "::", stringify!(inner)) + unsafe { ::std::ptr::addr_of!((*ptr).inner) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(local_type), "::", stringify!(inner)), ); } diff --git a/bindgen-tests/tests/expectations/tests/issue-1498.rs b/bindgen-tests/tests/expectations/tests/issue-1498.rs index bfbf3becf6..342fcc0869 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1498.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1498.rs @@ -29,22 +29,34 @@ fn bindgen_test_layout_rte_memseg__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < rte_memseg__bindgen_ty_1 > (), 8usize, - concat!("Size of: ", stringify!(rte_memseg__bindgen_ty_1)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(rte_memseg__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < rte_memseg__bindgen_ty_1 > (), 8usize, - concat!("Alignment of ", stringify!(rte_memseg__bindgen_ty_1)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(rte_memseg__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).addr) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_memseg__bindgen_ty_1), "::", - stringify!(addr)) + unsafe { ::std::ptr::addr_of!((*ptr).addr) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_memseg__bindgen_ty_1), + "::", + stringify!(addr), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).addr_64) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_memseg__bindgen_ty_1), "::", - stringify!(addr_64)) + unsafe { ::std::ptr::addr_of!((*ptr).addr_64) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_memseg__bindgen_ty_1), + "::", + stringify!(addr_64), + ), ); } impl Default for rte_memseg__bindgen_ty_1 { @@ -61,40 +73,49 @@ fn bindgen_test_layout_rte_memseg() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < rte_memseg > (), 44usize, concat!("Size of: ", - stringify!(rte_memseg)) + ::std::mem::size_of::(), + 44usize, + concat!("Size of: ", stringify!(rte_memseg)), ); assert_eq!( - ::std::mem::align_of:: < rte_memseg > (), 1usize, concat!("Alignment of ", - stringify!(rte_memseg)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(rte_memseg)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).phys_addr) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_memseg), "::", - stringify!(phys_addr)) + unsafe { ::std::ptr::addr_of!((*ptr).phys_addr) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(rte_memseg), "::", stringify!(phys_addr)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).len) as usize - ptr as usize }, 16usize, - concat!("Offset of field: ", stringify!(rte_memseg), "::", stringify!(len)) + unsafe { ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize }, + 16usize, + concat!("Offset of field: ", stringify!(rte_memseg), "::", stringify!(len)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).hugepage_sz) as usize - ptr as usize }, - 24usize, concat!("Offset of field: ", stringify!(rte_memseg), "::", - stringify!(hugepage_sz)) + unsafe { ::std::ptr::addr_of!((*ptr).hugepage_sz) as usize - ptr as usize }, + 24usize, + concat!( + "Offset of field: ", + stringify!(rte_memseg), + "::", + stringify!(hugepage_sz), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).socket_id) as usize - ptr as usize }, - 32usize, concat!("Offset of field: ", stringify!(rte_memseg), "::", - stringify!(socket_id)) + unsafe { ::std::ptr::addr_of!((*ptr).socket_id) as usize - ptr as usize }, + 32usize, + concat!("Offset of field: ", stringify!(rte_memseg), "::", stringify!(socket_id)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).nchannel) as usize - ptr as usize }, - 36usize, concat!("Offset of field: ", stringify!(rte_memseg), "::", - stringify!(nchannel)) + unsafe { ::std::ptr::addr_of!((*ptr).nchannel) as usize - ptr as usize }, + 36usize, + concat!("Offset of field: ", stringify!(rte_memseg), "::", stringify!(nchannel)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).nrank) as usize - ptr as usize }, 40usize, - concat!("Offset of field: ", stringify!(rte_memseg), "::", stringify!(nrank)) + unsafe { ::std::ptr::addr_of!((*ptr).nrank) as usize - ptr as usize }, + 40usize, + concat!("Offset of field: ", stringify!(rte_memseg), "::", stringify!(nrank)), ); } impl Default for rte_memseg { diff --git a/bindgen-tests/tests/expectations/tests/issue-1947.rs b/bindgen-tests/tests/expectations/tests/issue-1947.rs index de05e8bbe9..24aa354814 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1947.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1947.rs @@ -49,7 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -69,7 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -102,24 +102,29 @@ fn bindgen_test_layout_V56AMDY() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < V56AMDY > (), 8usize, concat!("Size of: ", - stringify!(V56AMDY)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(V56AMDY)), ); assert_eq!( - ::std::mem::align_of:: < V56AMDY > (), 2usize, concat!("Alignment of ", - stringify!(V56AMDY)) + ::std::mem::align_of::(), + 2usize, + concat!("Alignment of ", stringify!(V56AMDY)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).MADK) as usize - ptr as usize }, 2usize, - concat!("Offset of field: ", stringify!(V56AMDY), "::", stringify!(MADK)) + unsafe { ::std::ptr::addr_of!((*ptr).MADK) as usize - ptr as usize }, + 2usize, + concat!("Offset of field: ", stringify!(V56AMDY), "::", stringify!(MADK)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).MABR) as usize - ptr as usize }, 3usize, - concat!("Offset of field: ", stringify!(V56AMDY), "::", stringify!(MABR)) + unsafe { ::std::ptr::addr_of!((*ptr).MABR) as usize - ptr as usize }, + 3usize, + concat!("Offset of field: ", stringify!(V56AMDY), "::", stringify!(MABR)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr)._rB_) as usize - ptr as usize }, 7usize, - concat!("Offset of field: ", stringify!(V56AMDY), "::", stringify!(_rB_)) + unsafe { ::std::ptr::addr_of!((*ptr)._rB_) as usize - ptr as usize }, + 7usize, + concat!("Offset of field: ", stringify!(V56AMDY), "::", stringify!(_rB_)), ); } impl V56AMDY { diff --git a/bindgen-tests/tests/expectations/tests/issue-1977-larger-arrays.rs b/bindgen-tests/tests/expectations/tests/issue-1977-larger-arrays.rs index c7a0d74d0f..f60e10cdff 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1977-larger-arrays.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1977-larger-arrays.rs @@ -8,16 +8,16 @@ pub struct S { 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, concat!("Size of: ", stringify!(S))); assert_eq!( - ::std::mem::size_of:: < S > (), 33usize, concat!("Size of: ", stringify!(S)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(S)), ); assert_eq!( - ::std::mem::align_of:: < S > (), 1usize, concat!("Alignment of ", stringify!(S)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).large_array) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(S), "::", - stringify!(large_array)) + unsafe { ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(S), "::", stringify!(large_array)), ); } impl Default for S { diff --git a/bindgen-tests/tests/expectations/tests/issue-1995.rs b/bindgen-tests/tests/expectations/tests/issue-1995.rs index 0035989e62..c0964371e9 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1995.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1995.rs @@ -16,14 +16,18 @@ 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:: < Bar > (), 4usize, concat!("Size of: ", stringify!(Bar)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Bar)), ); assert_eq!( - ::std::mem::align_of:: < Bar > (), 4usize, concat!("Alignment of ", - stringify!(Bar)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Bar)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).baz) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz)) + unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz)), ); } diff --git a/bindgen-tests/tests/expectations/tests/issue-2019.rs b/bindgen-tests/tests/expectations/tests/issue-2019.rs index 3879af2a3c..6dbbc3b0c8 100644 --- a/bindgen-tests/tests/expectations/tests/issue-2019.rs +++ b/bindgen-tests/tests/expectations/tests/issue-2019.rs @@ -8,15 +8,16 @@ pub struct A { 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::(), 4usize, concat!("Size of: ", stringify!(A))); assert_eq!( - ::std::mem::size_of:: < A > (), 4usize, concat!("Size of: ", stringify!(A)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(A)), ); assert_eq!( - ::std::mem::align_of:: < A > (), 4usize, concat!("Alignment of ", stringify!(A)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(A), "::", stringify!(a)), ); } extern "C" { @@ -38,15 +39,16 @@ pub struct B { 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::(), 4usize, concat!("Size of: ", stringify!(B))); assert_eq!( - ::std::mem::size_of:: < B > (), 4usize, concat!("Size of: ", stringify!(B)) - ); - assert_eq!( - ::std::mem::align_of:: < B > (), 4usize, concat!("Alignment of ", stringify!(B)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(B)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(B), "::", stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(B), "::", stringify!(b)), ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/issue-2556.rs b/bindgen-tests/tests/expectations/tests/issue-2556.rs index 7722b851e2..54b0b5ec54 100644 --- a/bindgen-tests/tests/expectations/tests/issue-2556.rs +++ b/bindgen-tests/tests/expectations/tests/issue-2556.rs @@ -14,22 +14,24 @@ pub mod root { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < nsSize > (), 8usize, concat!("Size of: ", - stringify!(nsSize)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(nsSize)), ); assert_eq!( - ::std::mem::align_of:: < nsSize > (), 4usize, concat!("Alignment of ", - stringify!(nsSize)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(nsSize)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).width) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(nsSize), "::", - stringify!(width)) + unsafe { ::std::ptr::addr_of!((*ptr).width) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(nsSize), "::", stringify!(width)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).height) as usize - ptr as usize }, - 4usize, concat!("Offset of field: ", stringify!(nsSize), "::", - stringify!(height)) + unsafe { ::std::ptr::addr_of!((*ptr).height) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(nsSize), "::", stringify!(height)), ); } pub mod foo { diff --git a/bindgen-tests/tests/expectations/tests/issue-372.rs b/bindgen-tests/tests/expectations/tests/issue-372.rs index 1f4b81b83d..3155676176 100644 --- a/bindgen-tests/tests/expectations/tests/issue-372.rs +++ b/bindgen-tests/tests/expectations/tests/issue-372.rs @@ -15,23 +15,29 @@ pub mod root { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < i > (), 24usize, concat!("Size of: ", stringify!(i)) + ::std::mem::size_of::(), + 24usize, + concat!("Size of: ", stringify!(i)), ); assert_eq!( - ::std::mem::align_of:: < i > (), 8usize, concat!("Alignment of ", - stringify!(i)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(i)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).j) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(i), "::", stringify!(j)) + unsafe { ::std::ptr::addr_of!((*ptr).j) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(i), "::", stringify!(j)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).k) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(i), "::", stringify!(k)) + unsafe { ::std::ptr::addr_of!((*ptr).k) as usize - ptr as usize }, + 8usize, + concat!("Offset of field: ", stringify!(i), "::", stringify!(k)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).l) as usize - ptr as usize }, 16usize, - concat!("Offset of field: ", stringify!(i), "::", stringify!(l)) + unsafe { ::std::ptr::addr_of!((*ptr).l) as usize - ptr as usize }, + 16usize, + concat!("Offset of field: ", stringify!(i), "::", stringify!(l)), ); } impl Default for i { @@ -53,15 +59,19 @@ pub mod root { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < d > (), 24usize, concat!("Size of: ", stringify!(d)) + ::std::mem::size_of::(), + 24usize, + concat!("Size of: ", stringify!(d)), ); assert_eq!( - ::std::mem::align_of:: < d > (), 8usize, concat!("Alignment of ", - stringify!(d)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(d)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).m) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(d), "::", stringify!(m)) + unsafe { ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(d), "::", stringify!(m)), ); } impl Default for d { @@ -98,15 +108,19 @@ pub mod root { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < F > (), 264usize, concat!("Size of: ", stringify!(F)) + ::std::mem::size_of::(), + 264usize, + concat!("Size of: ", stringify!(F)), ); assert_eq!( - ::std::mem::align_of:: < F > (), 8usize, concat!("Alignment of ", - stringify!(F)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(F)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).w) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(F), "::", stringify!(w)) + unsafe { ::std::ptr::addr_of!((*ptr).w) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(F), "::", stringify!(w)), ); } impl Default for F { diff --git a/bindgen-tests/tests/expectations/tests/issue-410.rs b/bindgen-tests/tests/expectations/tests/issue-410.rs index 2b849fa240..d04cafe8df 100644 --- a/bindgen-tests/tests/expectations/tests/issue-410.rs +++ b/bindgen-tests/tests/expectations/tests/issue-410.rs @@ -14,12 +14,14 @@ pub mod root { #[test] fn bindgen_test_layout_Value() { assert_eq!( - ::std::mem::size_of:: < Value > (), 1usize, concat!("Size of: ", - stringify!(Value)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Value)), ); assert_eq!( - ::std::mem::align_of:: < Value > (), 1usize, concat!("Alignment of ", - stringify!(Value)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Value)), ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/issue-447.rs b/bindgen-tests/tests/expectations/tests/issue-447.rs index ea5dc92bec..1f1e376b5c 100644 --- a/bindgen-tests/tests/expectations/tests/issue-447.rs +++ b/bindgen-tests/tests/expectations/tests/issue-447.rs @@ -17,12 +17,14 @@ pub mod root { #[test] fn bindgen_test_layout_GuardObjectNotifier() { assert_eq!( - ::std::mem::size_of:: < GuardObjectNotifier > (), 1usize, - concat!("Size of: ", stringify!(GuardObjectNotifier)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(GuardObjectNotifier)), ); assert_eq!( - ::std::mem::align_of:: < GuardObjectNotifier > (), 1usize, - concat!("Alignment of ", stringify!(GuardObjectNotifier)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(GuardObjectNotifier)), ); } } @@ -35,12 +37,14 @@ pub mod root { #[test] fn bindgen_test_layout_JSAutoCompartment() { assert_eq!( - ::std::mem::size_of:: < JSAutoCompartment > (), 1usize, concat!("Size of: ", - stringify!(JSAutoCompartment)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(JSAutoCompartment)), ); assert_eq!( - ::std::mem::align_of:: < JSAutoCompartment > (), 1usize, - concat!("Alignment of ", stringify!(JSAutoCompartment)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(JSAutoCompartment)), ); } extern "C" { 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 bf848673cb..387082d0c8 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 @@ -12,16 +12,19 @@ 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:: < AlignedToOne > (), 4usize, concat!("Size of: ", - stringify!(AlignedToOne)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(AlignedToOne)), ); assert_eq!( - ::std::mem::align_of:: < AlignedToOne > (), 1usize, concat!("Alignment of ", - stringify!(AlignedToOne)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(AlignedToOne)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).i) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(AlignedToOne), "::", stringify!(i)) + unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(AlignedToOne), "::", stringify!(i)), ); } /// This should be be packed because Rust 1.33 has `#[repr(packed(N))]`. @@ -35,16 +38,19 @@ 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:: < AlignedToTwo > (), 4usize, concat!("Size of: ", - stringify!(AlignedToTwo)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(AlignedToTwo)), ); assert_eq!( - ::std::mem::align_of:: < AlignedToTwo > (), 2usize, concat!("Alignment of ", - stringify!(AlignedToTwo)) + ::std::mem::align_of::(), + 2usize, + concat!("Alignment of ", stringify!(AlignedToTwo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).i) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(AlignedToTwo), "::", stringify!(i)) + unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(AlignedToTwo), "::", stringify!(i)), ); } /** This should not be opaque because although `libclang` doesn't give us the @@ -61,20 +67,24 @@ 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:: < PackedToOne > (), 8usize, concat!("Size of: ", - stringify!(PackedToOne)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(PackedToOne)), ); assert_eq!( - ::std::mem::align_of:: < PackedToOne > (), 1usize, concat!("Alignment of ", - stringify!(PackedToOne)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(PackedToOne)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).x) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(PackedToOne), "::", stringify!(x)) + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(PackedToOne), "::", stringify!(x)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).y) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(PackedToOne), "::", stringify!(y)) + unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(PackedToOne), "::", stringify!(y)), ); } /// This should be be packed because Rust 1.33 has `#[repr(packed(N))]`. @@ -89,19 +99,23 @@ 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:: < PackedToTwo > (), 8usize, concat!("Size of: ", - stringify!(PackedToTwo)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(PackedToTwo)), ); assert_eq!( - ::std::mem::align_of:: < PackedToTwo > (), 2usize, concat!("Alignment of ", - stringify!(PackedToTwo)) + ::std::mem::align_of::(), + 2usize, + concat!("Alignment of ", stringify!(PackedToTwo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).x) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(PackedToTwo), "::", stringify!(x)) + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(PackedToTwo), "::", stringify!(x)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).y) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(PackedToTwo), "::", stringify!(y)) + unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(PackedToTwo), "::", stringify!(y)), ); } diff --git a/bindgen-tests/tests/expectations/tests/issue-537.rs b/bindgen-tests/tests/expectations/tests/issue-537.rs index a0387cd9d0..c9ce3fb035 100644 --- a/bindgen-tests/tests/expectations/tests/issue-537.rs +++ b/bindgen-tests/tests/expectations/tests/issue-537.rs @@ -11,16 +11,19 @@ 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:: < AlignedToOne > (), 4usize, concat!("Size of: ", - stringify!(AlignedToOne)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(AlignedToOne)), ); assert_eq!( - ::std::mem::align_of:: < AlignedToOne > (), 1usize, concat!("Alignment of ", - stringify!(AlignedToOne)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(AlignedToOne)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).i) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(AlignedToOne), "::", stringify!(i)) + unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(AlignedToOne), "::", stringify!(i)), ); } /** This should be opaque because although we can see the attributes, Rust before @@ -35,16 +38,19 @@ 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:: < AlignedToTwo > (), 4usize, concat!("Size of: ", - stringify!(AlignedToTwo)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(AlignedToTwo)), ); assert_eq!( - ::std::mem::align_of:: < AlignedToTwo > (), 2usize, concat!("Alignment of ", - stringify!(AlignedToTwo)) + ::std::mem::align_of::(), + 2usize, + concat!("Alignment of ", stringify!(AlignedToTwo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).i) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(AlignedToTwo), "::", stringify!(i)) + unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(AlignedToTwo), "::", stringify!(i)), ); } /** This should not be opaque because although `libclang` doesn't give us the @@ -61,20 +67,24 @@ 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:: < PackedToOne > (), 8usize, concat!("Size of: ", - stringify!(PackedToOne)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(PackedToOne)), ); assert_eq!( - ::std::mem::align_of:: < PackedToOne > (), 1usize, concat!("Alignment of ", - stringify!(PackedToOne)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(PackedToOne)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).x) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(PackedToOne), "::", stringify!(x)) + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(PackedToOne), "::", stringify!(x)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).y) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(PackedToOne), "::", stringify!(y)) + unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(PackedToOne), "::", stringify!(y)), ); } /** In this case, even if we can detect the weird alignment triggered by @@ -91,19 +101,23 @@ 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:: < PackedToTwo > (), 8usize, concat!("Size of: ", - stringify!(PackedToTwo)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(PackedToTwo)), ); assert_eq!( - ::std::mem::align_of:: < PackedToTwo > (), 2usize, concat!("Alignment of ", - stringify!(PackedToTwo)) + ::std::mem::align_of::(), + 2usize, + concat!("Alignment of ", stringify!(PackedToTwo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).x) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(PackedToTwo), "::", stringify!(x)) + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(PackedToTwo), "::", stringify!(x)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).y) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(PackedToTwo), "::", stringify!(y)) + unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(PackedToTwo), "::", stringify!(y)), ); } diff --git a/bindgen-tests/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs b/bindgen-tests/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs index a1a2f1e52b..59590ec8fe 100644 --- a/bindgen-tests/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs +++ b/bindgen-tests/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs @@ -30,12 +30,14 @@ pub struct JS_AutoIdVector { #[test] fn bindgen_test_layout_JS_AutoIdVector() { assert_eq!( - ::std::mem::size_of:: < JS_AutoIdVector > (), 1usize, concat!("Size of: ", - stringify!(JS_AutoIdVector)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(JS_AutoIdVector)), ); assert_eq!( - ::std::mem::align_of:: < JS_AutoIdVector > (), 1usize, concat!("Alignment of ", - stringify!(JS_AutoIdVector)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(JS_AutoIdVector)), ); } impl Default for JS_AutoIdVector { @@ -50,11 +52,13 @@ impl Default for JS_AutoIdVector { #[test] fn __bindgen_test_layout_JS_Base_open0_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < JS_Base > (), 1usize, - concat!("Size of template specialization: ", stringify!(JS_Base)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of template specialization: ", stringify!(JS_Base)), ); assert_eq!( - ::std::mem::align_of:: < JS_Base > (), 1usize, - concat!("Alignment of template specialization: ", stringify!(JS_Base)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of template specialization: ", stringify!(JS_Base)), ); } diff --git a/bindgen-tests/tests/expectations/tests/issue-573-layout-test-failures.rs b/bindgen-tests/tests/expectations/tests/issue-573-layout-test-failures.rs index 5b77a26a23..ab51dc8943 100644 --- a/bindgen-tests/tests/expectations/tests/issue-573-layout-test-failures.rs +++ b/bindgen-tests/tests/expectations/tests/issue-573-layout-test-failures.rs @@ -14,26 +14,31 @@ fn bindgen_test_layout_AutoIdVector() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < AutoIdVector > (), 1usize, concat!("Size of: ", - stringify!(AutoIdVector)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(AutoIdVector)), ); assert_eq!( - ::std::mem::align_of:: < AutoIdVector > (), 1usize, concat!("Alignment of ", - stringify!(AutoIdVector)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(AutoIdVector)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).ar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(AutoIdVector), "::", stringify!(ar)) + unsafe { ::std::ptr::addr_of!((*ptr).ar) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(AutoIdVector), "::", stringify!(ar)), ); } #[test] fn __bindgen_test_layout_Outer_open0_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < Outer > (), 1usize, - concat!("Size of template specialization: ", stringify!(Outer)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of template specialization: ", stringify!(Outer)), ); assert_eq!( - ::std::mem::align_of:: < Outer > (), 1usize, - concat!("Alignment of template specialization: ", stringify!(Outer)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of template specialization: ", stringify!(Outer)), ); } diff --git a/bindgen-tests/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs b/bindgen-tests/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs index 2591c1aac5..d3c0cee41c 100644 --- a/bindgen-tests/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs +++ b/bindgen-tests/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs @@ -14,16 +14,19 @@ fn bindgen_test_layout__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit<_bindgen_ty_1> = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < _bindgen_ty_1 > (), 1usize, concat!("Size of: ", - stringify!(_bindgen_ty_1)) + ::std::mem::size_of::<_bindgen_ty_1>(), + 1usize, + concat!("Size of: ", stringify!(_bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < _bindgen_ty_1 > (), 1usize, concat!("Alignment of ", - stringify!(_bindgen_ty_1)) + ::std::mem::align_of::<_bindgen_ty_1>(), + 1usize, + concat!("Alignment of ", stringify!(_bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).ar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(_bindgen_ty_1), "::", stringify!(ar)) + unsafe { ::std::ptr::addr_of!((*ptr).ar) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(_bindgen_ty_1), "::", stringify!(ar)), ); } extern "C" { @@ -32,11 +35,13 @@ extern "C" { #[test] fn __bindgen_test_layout_a_open0_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < a > (), 1usize, - concat!("Size of template specialization: ", stringify!(a)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of template specialization: ", stringify!(a)), ); assert_eq!( - ::std::mem::align_of:: < a > (), 1usize, - concat!("Alignment of template specialization: ", stringify!(a)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of template specialization: ", stringify!(a)), ); } diff --git a/bindgen-tests/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs b/bindgen-tests/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs index 96bbfe4c1b..060db1636d 100644 --- a/bindgen-tests/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs +++ b/bindgen-tests/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs @@ -8,11 +8,11 @@ pub struct A { pub type A_a = b; #[test] fn bindgen_test_layout_A() { + assert_eq!(::std::mem::size_of::(), 1usize, concat!("Size of: ", stringify!(A))); assert_eq!( - ::std::mem::size_of:: < A > (), 1usize, concat!("Size of: ", stringify!(A)) - ); - assert_eq!( - ::std::mem::align_of:: < A > (), 1usize, concat!("Alignment of ", stringify!(A)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(A)), ); } #[repr(C)] @@ -42,15 +42,16 @@ pub struct g { fn bindgen_test_layout_g() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); + assert_eq!(::std::mem::size_of::(), 1usize, concat!("Size of: ", stringify!(g))); assert_eq!( - ::std::mem::size_of:: < g > (), 1usize, concat!("Size of: ", stringify!(g)) - ); - assert_eq!( - ::std::mem::align_of:: < g > (), 1usize, concat!("Alignment of ", stringify!(g)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(g)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).h) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(g), "::", stringify!(h)) + unsafe { ::std::ptr::addr_of!((*ptr).h) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(g), "::", stringify!(h)), ); } impl Default for g { @@ -68,11 +69,11 @@ pub struct b { } #[test] fn bindgen_test_layout_b() { + assert_eq!(::std::mem::size_of::(), 1usize, concat!("Size of: ", stringify!(b))); assert_eq!( - ::std::mem::size_of:: < b > (), 1usize, concat!("Size of: ", stringify!(b)) - ); - assert_eq!( - ::std::mem::align_of:: < b > (), 1usize, concat!("Alignment of ", stringify!(b)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(b)), ); } impl Default for b { @@ -91,11 +92,13 @@ extern "C" { #[test] fn __bindgen_test_layout_f_open0_e_open1_int_close1_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < f > (), 1usize, - concat!("Size of template specialization: ", stringify!(f)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of template specialization: ", stringify!(f)), ); assert_eq!( - ::std::mem::align_of:: < f > (), 1usize, - concat!("Alignment of template specialization: ", stringify!(f)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of template specialization: ", stringify!(f)), ); } diff --git a/bindgen-tests/tests/expectations/tests/issue-639-typedef-anon-field.rs b/bindgen-tests/tests/expectations/tests/issue-639-typedef-anon-field.rs index 7e8bae67c7..2495b458e4 100644 --- a/bindgen-tests/tests/expectations/tests/issue-639-typedef-anon-field.rs +++ b/bindgen-tests/tests/expectations/tests/issue-639-typedef-anon-field.rs @@ -14,16 +14,19 @@ fn bindgen_test_layout_Foo_Bar() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < Foo_Bar > (), 4usize, concat!("Size of: ", - stringify!(Foo_Bar)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Foo_Bar)), ); assert_eq!( - ::std::mem::align_of:: < Foo_Bar > (), 4usize, concat!("Alignment of ", - stringify!(Foo_Bar)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Foo_Bar)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).abc) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Foo_Bar), "::", stringify!(abc)) + unsafe { ::std::ptr::addr_of!((*ptr).abc) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Foo_Bar), "::", stringify!(abc)), ); } #[test] @@ -31,15 +34,19 @@ 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:: < Foo > (), 4usize, concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Foo)), ); assert_eq!( - ::std::mem::align_of:: < Foo > (), 4usize, concat!("Alignment of ", - stringify!(Foo)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)) + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)), ); } #[repr(C)] @@ -57,25 +64,31 @@ fn bindgen_test_layout_Baz_Bar() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < Baz_Bar > (), 4usize, concat!("Size of: ", - stringify!(Baz_Bar)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Baz_Bar)), ); assert_eq!( - ::std::mem::align_of:: < Baz_Bar > (), 4usize, concat!("Alignment of ", - stringify!(Baz_Bar)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Baz_Bar)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).abc) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Baz_Bar), "::", stringify!(abc)) + unsafe { ::std::ptr::addr_of!((*ptr).abc) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Baz_Bar), "::", stringify!(abc)), ); } #[test] fn bindgen_test_layout_Baz() { assert_eq!( - ::std::mem::size_of:: < Baz > (), 1usize, concat!("Size of: ", stringify!(Baz)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Baz)), ); assert_eq!( - ::std::mem::align_of:: < Baz > (), 1usize, concat!("Alignment of ", - stringify!(Baz)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Baz)), ); } diff --git a/bindgen-tests/tests/expectations/tests/issue-643-inner-struct.rs b/bindgen-tests/tests/expectations/tests/issue-643-inner-struct.rs index 103c0ce1ed..673221e385 100644 --- a/bindgen-tests/tests/expectations/tests/issue-643-inner-struct.rs +++ b/bindgen-tests/tests/expectations/tests/issue-643-inner-struct.rs @@ -47,17 +47,24 @@ fn bindgen_test_layout_rte_ring_prod() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < rte_ring_prod > (), 4usize, concat!("Size of: ", - stringify!(rte_ring_prod)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(rte_ring_prod)), ); assert_eq!( - ::std::mem::align_of:: < rte_ring_prod > (), 4usize, concat!("Alignment of ", - stringify!(rte_ring_prod)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_ring_prod)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).watermark) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_ring_prod), "::", - stringify!(watermark)) + unsafe { ::std::ptr::addr_of!((*ptr).watermark) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ring_prod), + "::", + stringify!(watermark), + ), ); } #[repr(C)] @@ -70,28 +77,37 @@ fn bindgen_test_layout_rte_ring_cons() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < rte_ring_cons > (), 4usize, concat!("Size of: ", - stringify!(rte_ring_cons)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(rte_ring_cons)), ); assert_eq!( - ::std::mem::align_of:: < rte_ring_cons > (), 4usize, concat!("Alignment of ", - stringify!(rte_ring_cons)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_ring_cons)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).sc_dequeue) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_ring_cons), "::", - stringify!(sc_dequeue)) + unsafe { ::std::ptr::addr_of!((*ptr).sc_dequeue) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ring_cons), + "::", + stringify!(sc_dequeue), + ), ); } #[test] fn bindgen_test_layout_rte_ring() { assert_eq!( - ::std::mem::size_of:: < rte_ring > (), 16usize, concat!("Size of: ", - stringify!(rte_ring)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(rte_ring)), ); assert_eq!( - ::std::mem::align_of:: < rte_ring > (), 8usize, concat!("Alignment of ", - stringify!(rte_ring)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(rte_ring)), ); } impl Default for rte_ring { 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 0168c4e55a..6015618d48 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 @@ -12,16 +12,19 @@ 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:: < NoDebug > (), 64usize, concat!("Size of: ", - stringify!(NoDebug)) + ::std::mem::size_of::(), + 64usize, + concat!("Size of: ", stringify!(NoDebug)), ); assert_eq!( - ::std::mem::align_of:: < NoDebug > (), 64usize, concat!("Alignment of ", - stringify!(NoDebug)) + ::std::mem::align_of::(), + 64usize, + concat!("Alignment of ", stringify!(NoDebug)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).c) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(NoDebug), "::", stringify!(c)) + unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(NoDebug), "::", stringify!(c)), ); } impl Default for NoDebug { @@ -54,22 +57,34 @@ 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:: < ShouldDeriveDebugButDoesNot > (), 64usize, - concat!("Size of: ", stringify!(ShouldDeriveDebugButDoesNot)) + ::std::mem::size_of::(), + 64usize, + concat!("Size of: ", stringify!(ShouldDeriveDebugButDoesNot)), ); assert_eq!( - ::std::mem::align_of:: < ShouldDeriveDebugButDoesNot > (), 64usize, - concat!("Alignment of ", stringify!(ShouldDeriveDebugButDoesNot)) + ::std::mem::align_of::(), + 64usize, + concat!("Alignment of ", stringify!(ShouldDeriveDebugButDoesNot)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).c) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(ShouldDeriveDebugButDoesNot), "::", - stringify!(c)) + unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ShouldDeriveDebugButDoesNot), + "::", + stringify!(c), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).d) as usize - ptr as usize }, 32usize, - concat!("Offset of field: ", stringify!(ShouldDeriveDebugButDoesNot), "::", - stringify!(d)) + unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, + 32usize, + concat!( + "Offset of field: ", + stringify!(ShouldDeriveDebugButDoesNot), + "::", + stringify!(d), + ), ); } impl Default for ShouldDeriveDebugButDoesNot { diff --git a/bindgen-tests/tests/expectations/tests/issue-674-1.rs b/bindgen-tests/tests/expectations/tests/issue-674-1.rs index e68a62b8fb..2173924c3c 100644 --- a/bindgen-tests/tests/expectations/tests/issue-674-1.rs +++ b/bindgen-tests/tests/expectations/tests/issue-674-1.rs @@ -23,17 +23,24 @@ pub mod root { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < CapturingContentInfo > (), 1usize, - concat!("Size of: ", stringify!(CapturingContentInfo)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(CapturingContentInfo)), ); assert_eq!( - ::std::mem::align_of:: < CapturingContentInfo > (), 1usize, - concat!("Alignment of ", stringify!(CapturingContentInfo)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(CapturingContentInfo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(CapturingContentInfo), "::", - stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(CapturingContentInfo), + "::", + stringify!(a), + ), ); } } diff --git a/bindgen-tests/tests/expectations/tests/issue-674-2.rs b/bindgen-tests/tests/expectations/tests/issue-674-2.rs index 66b52dbc70..01f54798d7 100644 --- a/bindgen-tests/tests/expectations/tests/issue-674-2.rs +++ b/bindgen-tests/tests/expectations/tests/issue-674-2.rs @@ -23,15 +23,19 @@ pub mod root { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < c > (), 1usize, concat!("Size of: ", stringify!(c)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(c)), ); assert_eq!( - ::std::mem::align_of:: < c > (), 1usize, concat!("Alignment of ", - stringify!(c)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(c)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(c), "::", stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(c), "::", stringify!(b)), ); } #[repr(C)] @@ -44,15 +48,19 @@ pub mod root { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < B > (), 1usize, concat!("Size of: ", stringify!(B)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(B)), ); assert_eq!( - ::std::mem::align_of:: < B > (), 1usize, concat!("Alignment of ", - stringify!(B)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(B)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(B), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(B), "::", stringify!(a)), ); } #[repr(C)] @@ -63,13 +71,17 @@ pub mod root { #[test] fn __bindgen_test_layout_StaticRefPtr_open0_B_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < root::StaticRefPtr > (), 1usize, - concat!("Size of template specialization: ", stringify!(root::StaticRefPtr)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of template specialization: ", stringify!(root::StaticRefPtr)), ); assert_eq!( - ::std::mem::align_of:: < root::StaticRefPtr > (), 1usize, - concat!("Alignment of template specialization: ", - stringify!(root::StaticRefPtr)) + ::std::mem::align_of::(), + 1usize, + concat!( + "Alignment of template specialization: ", + stringify!(root::StaticRefPtr), + ), ); } } diff --git a/bindgen-tests/tests/expectations/tests/issue-674-3.rs b/bindgen-tests/tests/expectations/tests/issue-674-3.rs index 72eda5dff0..bba2f38b43 100644 --- a/bindgen-tests/tests/expectations/tests/issue-674-3.rs +++ b/bindgen-tests/tests/expectations/tests/issue-674-3.rs @@ -19,15 +19,19 @@ pub mod root { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < a > (), 1usize, concat!("Size of: ", stringify!(a)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(a)), ); assert_eq!( - ::std::mem::align_of:: < a > (), 1usize, concat!("Alignment of ", - stringify!(a)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(a)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(a), "::", stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(a), "::", stringify!(b)), ); } #[repr(C)] @@ -40,16 +44,19 @@ pub mod root { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < nsCSSValue > (), 1usize, concat!("Size of: ", - stringify!(nsCSSValue)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(nsCSSValue)), ); assert_eq!( - ::std::mem::align_of:: < nsCSSValue > (), 1usize, concat!("Alignment of ", - stringify!(nsCSSValue)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(nsCSSValue)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).c) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(nsCSSValue), "::", stringify!(c)) + unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(nsCSSValue), "::", stringify!(c)), ); } } diff --git a/bindgen-tests/tests/expectations/tests/issue-691-template-parameter-virtual.rs b/bindgen-tests/tests/expectations/tests/issue-691-template-parameter-virtual.rs index 0b659930a8..7080f2048b 100644 --- a/bindgen-tests/tests/expectations/tests/issue-691-template-parameter-virtual.rs +++ b/bindgen-tests/tests/expectations/tests/issue-691-template-parameter-virtual.rs @@ -9,12 +9,14 @@ pub struct VirtualMethods { #[test] fn bindgen_test_layout_VirtualMethods() { assert_eq!( - ::std::mem::size_of:: < VirtualMethods > (), 8usize, concat!("Size of: ", - stringify!(VirtualMethods)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(VirtualMethods)), ); assert_eq!( - ::std::mem::align_of:: < VirtualMethods > (), 8usize, concat!("Alignment of ", - stringify!(VirtualMethods)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(VirtualMethods)), ); } impl Default for VirtualMethods { @@ -39,12 +41,14 @@ pub struct ServoElementSnapshotTable { #[test] fn bindgen_test_layout_ServoElementSnapshotTable() { assert_eq!( - ::std::mem::size_of:: < ServoElementSnapshotTable > (), 4usize, - concat!("Size of: ", stringify!(ServoElementSnapshotTable)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(ServoElementSnapshotTable)), ); assert_eq!( - ::std::mem::align_of:: < ServoElementSnapshotTable > (), 4usize, - concat!("Alignment of ", stringify!(ServoElementSnapshotTable)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(ServoElementSnapshotTable)), ); } impl Default for ServoElementSnapshotTable { @@ -59,11 +63,13 @@ impl Default for ServoElementSnapshotTable { #[test] fn __bindgen_test_layout_Set_open0_VirtualMethods_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < Set > (), 4usize, - concat!("Size of template specialization: ", stringify!(Set)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of template specialization: ", stringify!(Set)), ); assert_eq!( - ::std::mem::align_of:: < Set > (), 4usize, - concat!("Alignment of template specialization: ", stringify!(Set)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of template specialization: ", stringify!(Set)), ); } diff --git a/bindgen-tests/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs b/bindgen-tests/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs index be1e01a66a..adea1cbe56 100644 --- a/bindgen-tests/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs @@ -50,7 +50,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -70,7 +70,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -94,11 +94,14 @@ pub struct Foo { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of:: < Foo > (), 32usize, concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of::(), + 32usize, + concat!("Size of: ", stringify!(Foo)), ); assert_eq!( - ::std::mem::align_of:: < Foo > (), 8usize, concat!("Alignment of ", - stringify!(Foo)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Foo)), ); } impl Foo { diff --git a/bindgen-tests/tests/expectations/tests/issue-801-opaque-sloppiness.rs b/bindgen-tests/tests/expectations/tests/issue-801-opaque-sloppiness.rs index 2883552895..cf68821f18 100644 --- a/bindgen-tests/tests/expectations/tests/issue-801-opaque-sloppiness.rs +++ b/bindgen-tests/tests/expectations/tests/issue-801-opaque-sloppiness.rs @@ -12,11 +12,11 @@ pub struct B { } #[test] fn bindgen_test_layout_B() { + assert_eq!(::std::mem::size_of::(), 1usize, concat!("Size of: ", stringify!(B))); assert_eq!( - ::std::mem::size_of:: < B > (), 1usize, concat!("Size of: ", stringify!(B)) - ); - assert_eq!( - ::std::mem::align_of:: < B > (), 1usize, concat!("Alignment of ", stringify!(B)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(B)), ); } extern "C" { @@ -32,14 +32,15 @@ pub struct C { 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::(), 1usize, concat!("Size of: ", stringify!(C))); assert_eq!( - ::std::mem::size_of:: < C > (), 1usize, concat!("Size of: ", stringify!(C)) - ); - assert_eq!( - ::std::mem::align_of:: < C > (), 1usize, concat!("Alignment of ", stringify!(C)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(C)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(b)), ); } diff --git a/bindgen-tests/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs b/bindgen-tests/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs index f5c4852d23..ab807045be 100644 --- a/bindgen-tests/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs +++ b/bindgen-tests/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs @@ -7,12 +7,14 @@ pub struct Pupper { #[test] fn bindgen_test_layout_Pupper() { assert_eq!( - ::std::mem::size_of:: < Pupper > (), 1usize, concat!("Size of: ", - stringify!(Pupper)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Pupper)), ); assert_eq!( - ::std::mem::align_of:: < Pupper > (), 1usize, concat!("Alignment of ", - stringify!(Pupper)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Pupper)), ); } #[repr(C)] @@ -23,12 +25,14 @@ pub struct Doggo { #[test] fn bindgen_test_layout_Doggo() { assert_eq!( - ::std::mem::size_of:: < Doggo > (), 1usize, concat!("Size of: ", - stringify!(Doggo)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Doggo)), ); assert_eq!( - ::std::mem::align_of:: < Doggo > (), 1usize, concat!("Alignment of ", - stringify!(Doggo)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Doggo)), ); } #[repr(C)] @@ -39,12 +43,14 @@ pub struct SuchWow { #[test] fn bindgen_test_layout_SuchWow() { assert_eq!( - ::std::mem::size_of:: < SuchWow > (), 1usize, concat!("Size of: ", - stringify!(SuchWow)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(SuchWow)), ); assert_eq!( - ::std::mem::align_of:: < SuchWow > (), 1usize, concat!("Alignment of ", - stringify!(SuchWow)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(SuchWow)), ); } #[repr(C)] @@ -56,12 +62,14 @@ pub struct Opaque { #[test] fn bindgen_test_layout_Opaque() { assert_eq!( - ::std::mem::size_of:: < Opaque > (), 1usize, concat!("Size of: ", - stringify!(Opaque)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Opaque)), ); assert_eq!( - ::std::mem::align_of:: < Opaque > (), 1usize, concat!("Alignment of ", - stringify!(Opaque)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Opaque)), ); } extern "C" { @@ -98,16 +106,23 @@ fn bindgen_test_layout_Allowlisted() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < Allowlisted > (), 1usize, concat!("Size of: ", - stringify!(Allowlisted)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Allowlisted)), ); assert_eq!( - ::std::mem::align_of:: < Allowlisted > (), 1usize, concat!("Alignment of ", - stringify!(Allowlisted)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Allowlisted)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).some_member) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(Allowlisted), "::", - stringify!(some_member)) + unsafe { ::std::ptr::addr_of!((*ptr).some_member) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Allowlisted), + "::", + stringify!(some_member), + ), ); } diff --git a/bindgen-tests/tests/expectations/tests/issue-816.rs b/bindgen-tests/tests/expectations/tests/issue-816.rs index ac4c275070..206e6ffd17 100644 --- a/bindgen-tests/tests/expectations/tests/issue-816.rs +++ b/bindgen-tests/tests/expectations/tests/issue-816.rs @@ -49,7 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -69,7 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -93,12 +93,14 @@ pub struct capabilities { #[test] fn bindgen_test_layout_capabilities() { assert_eq!( - ::std::mem::size_of:: < capabilities > (), 16usize, concat!("Size of: ", - stringify!(capabilities)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(capabilities)), ); assert_eq!( - ::std::mem::align_of:: < capabilities > (), 4usize, concat!("Alignment of ", - stringify!(capabilities)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(capabilities)), ); } impl capabilities { diff --git a/bindgen-tests/tests/expectations/tests/issue-826-generating-methods-when-asked-not-to.rs b/bindgen-tests/tests/expectations/tests/issue-826-generating-methods-when-asked-not-to.rs index d16596b591..d51ccfa80c 100644 --- a/bindgen-tests/tests/expectations/tests/issue-826-generating-methods-when-asked-not-to.rs +++ b/bindgen-tests/tests/expectations/tests/issue-826-generating-methods-when-asked-not-to.rs @@ -7,10 +7,13 @@ pub struct Foo { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo)), ); assert_eq!( - ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", - stringify!(Foo)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)), ); } diff --git a/bindgen-tests/tests/expectations/tests/issue-834.rs b/bindgen-tests/tests/expectations/tests/issue-834.rs index 46ae37b5e5..24c18c2be7 100644 --- a/bindgen-tests/tests/expectations/tests/issue-834.rs +++ b/bindgen-tests/tests/expectations/tests/issue-834.rs @@ -6,10 +6,10 @@ pub struct U { } #[test] fn bindgen_test_layout_U() { + assert_eq!(::std::mem::size_of::(), 1usize, concat!("Size of: ", stringify!(U))); assert_eq!( - ::std::mem::size_of:: < U > (), 1usize, concat!("Size of: ", stringify!(U)) - ); - assert_eq!( - ::std::mem::align_of:: < U > (), 1usize, concat!("Alignment of ", stringify!(U)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(U)), ); } diff --git a/bindgen-tests/tests/expectations/tests/issue-888-enum-var-decl-jump.rs b/bindgen-tests/tests/expectations/tests/issue-888-enum-var-decl-jump.rs index 317a73ab16..974e191401 100644 --- a/bindgen-tests/tests/expectations/tests/issue-888-enum-var-decl-jump.rs +++ b/bindgen-tests/tests/expectations/tests/issue-888-enum-var-decl-jump.rs @@ -18,12 +18,14 @@ pub mod root { #[test] fn bindgen_test_layout_Type() { assert_eq!( - ::std::mem::size_of:: < Type > (), 1usize, concat!("Size of: ", - stringify!(Type)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Type)), ); assert_eq!( - ::std::mem::align_of:: < Type > (), 1usize, concat!("Alignment of ", - stringify!(Type)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Type)), ); } } diff --git a/bindgen-tests/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs b/bindgen-tests/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs index 60b8dddc09..a5cd116cfd 100644 --- a/bindgen-tests/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs +++ b/bindgen-tests/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs @@ -10,16 +10,19 @@ fn bindgen_test_layout_ShouldNotBeCopy() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < ShouldNotBeCopy > (), 1usize, concat!("Size of: ", - stringify!(ShouldNotBeCopy)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(ShouldNotBeCopy)), ); assert_eq!( - ::std::mem::align_of:: < ShouldNotBeCopy > (), 1usize, concat!("Alignment of ", - stringify!(ShouldNotBeCopy)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(ShouldNotBeCopy)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(ShouldNotBeCopy), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(ShouldNotBeCopy), "::", stringify!(a)), ); } impl Default for ShouldNotBeCopy { diff --git a/bindgen-tests/tests/expectations/tests/issue-946.rs b/bindgen-tests/tests/expectations/tests/issue-946.rs index 9cd65e4aae..a1bf320f1a 100644 --- a/bindgen-tests/tests/expectations/tests/issue-946.rs +++ b/bindgen-tests/tests/expectations/tests/issue-946.rs @@ -5,11 +5,14 @@ pub struct foo {} #[test] fn bindgen_test_layout_foo() { assert_eq!( - ::std::mem::size_of:: < foo > (), 0usize, concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of::(), + 0usize, + concat!("Size of: ", stringify!(foo)), ); assert_eq!( - ::std::mem::align_of:: < foo > (), 1usize, concat!("Alignment of ", - stringify!(foo)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(foo)), ); } pub type bar = foo; diff --git a/bindgen-tests/tests/expectations/tests/issue_311.rs b/bindgen-tests/tests/expectations/tests/issue_311.rs index f0cc889c9a..8822aece04 100644 --- a/bindgen-tests/tests/expectations/tests/issue_311.rs +++ b/bindgen-tests/tests/expectations/tests/issue_311.rs @@ -16,23 +16,27 @@ pub mod root { #[test] fn bindgen_test_layout_jsval_layout__bindgen_ty_1() { assert_eq!( - ::std::mem::size_of:: < jsval_layout__bindgen_ty_1 > (), 1usize, - concat!("Size of: ", stringify!(jsval_layout__bindgen_ty_1)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(jsval_layout__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < jsval_layout__bindgen_ty_1 > (), 1usize, - concat!("Alignment of ", stringify!(jsval_layout__bindgen_ty_1)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(jsval_layout__bindgen_ty_1)), ); } #[test] fn bindgen_test_layout_jsval_layout() { assert_eq!( - ::std::mem::size_of:: < jsval_layout > (), 1usize, concat!("Size of: ", - stringify!(jsval_layout)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(jsval_layout)), ); assert_eq!( - ::std::mem::align_of:: < jsval_layout > (), 1usize, concat!("Alignment of ", - stringify!(jsval_layout)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(jsval_layout)), ); } } diff --git a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs index cfbf2f61cc..735cebfb25 100644 --- a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs +++ b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs @@ -49,7 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -69,7 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -190,12 +190,14 @@ pub struct jsval_layout__bindgen_ty_1 { #[test] fn bindgen_test_layout_jsval_layout__bindgen_ty_1() { assert_eq!( - ::std::mem::size_of:: < jsval_layout__bindgen_ty_1 > (), 8usize, - concat!("Size of: ", stringify!(jsval_layout__bindgen_ty_1)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(jsval_layout__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < jsval_layout__bindgen_ty_1 > (), 8usize, - concat!("Alignment of ", stringify!(jsval_layout__bindgen_ty_1)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(jsval_layout__bindgen_ty_1)), ); } impl Default for jsval_layout__bindgen_ty_1 { @@ -274,27 +276,44 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < jsval_layout__bindgen_ty_2__bindgen_ty_1 > (), 4usize, - concat!("Size of: ", stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < jsval_layout__bindgen_ty_2__bindgen_ty_1 > (), 4usize, - concat!("Alignment of ", stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).i32_) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), "::", stringify!(i32_)) + unsafe { ::std::ptr::addr_of!((*ptr).i32_) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), + "::", + stringify!(i32_), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).u32_) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), "::", stringify!(u32_)) + unsafe { ::std::ptr::addr_of!((*ptr).u32_) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), + "::", + stringify!(u32_), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).why) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), "::", stringify!(why)) + unsafe { ::std::ptr::addr_of!((*ptr).why) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), + "::", + stringify!(why), + ), ); } impl Default for jsval_layout__bindgen_ty_2__bindgen_ty_1 { @@ -311,17 +330,24 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < jsval_layout__bindgen_ty_2 > (), 4usize, - concat!("Size of: ", stringify!(jsval_layout__bindgen_ty_2)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(jsval_layout__bindgen_ty_2)), ); assert_eq!( - ::std::mem::align_of:: < jsval_layout__bindgen_ty_2 > (), 4usize, - concat!("Alignment of ", stringify!(jsval_layout__bindgen_ty_2)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(jsval_layout__bindgen_ty_2)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).payload) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(jsval_layout__bindgen_ty_2), "::", - stringify!(payload)) + unsafe { ::std::ptr::addr_of!((*ptr).payload) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout__bindgen_ty_2), + "::", + stringify!(payload), + ), ); } impl Default for jsval_layout__bindgen_ty_2 { @@ -338,43 +364,64 @@ fn bindgen_test_layout_jsval_layout() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < jsval_layout > (), 8usize, concat!("Size of: ", - stringify!(jsval_layout)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(jsval_layout)), ); assert_eq!( - ::std::mem::align_of:: < jsval_layout > (), 8usize, concat!("Alignment of ", - stringify!(jsval_layout)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(jsval_layout)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).asBits) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(jsval_layout), "::", stringify!(asBits)) + unsafe { ::std::ptr::addr_of!((*ptr).asBits) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(jsval_layout), "::", stringify!(asBits)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).debugView) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(jsval_layout), "::", - stringify!(debugView)) + unsafe { ::std::ptr::addr_of!((*ptr).debugView) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout), + "::", + stringify!(debugView), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).s) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(jsval_layout), "::", stringify!(s)) + unsafe { ::std::ptr::addr_of!((*ptr).s) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(jsval_layout), "::", stringify!(s)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).asDouble) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(jsval_layout), "::", - stringify!(asDouble)) + unsafe { ::std::ptr::addr_of!((*ptr).asDouble) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout), + "::", + stringify!(asDouble), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).asPtr) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(jsval_layout), "::", stringify!(asPtr)) + unsafe { ::std::ptr::addr_of!((*ptr).asPtr) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(jsval_layout), "::", stringify!(asPtr)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).asWord) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(jsval_layout), "::", stringify!(asWord)) + unsafe { ::std::ptr::addr_of!((*ptr).asWord) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(jsval_layout), "::", stringify!(asWord)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).asUIntPtr) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(jsval_layout), "::", - stringify!(asUIntPtr)) + unsafe { ::std::ptr::addr_of!((*ptr).asUIntPtr) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout), + "::", + stringify!(asUIntPtr), + ), ); } impl Default for jsval_layout { @@ -396,16 +443,19 @@ fn bindgen_test_layout_Value() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < Value > (), 8usize, concat!("Size of: ", - stringify!(Value)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Value)), ); assert_eq!( - ::std::mem::align_of:: < Value > (), 8usize, concat!("Alignment of ", - stringify!(Value)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Value)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).data) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Value), "::", stringify!(data)) + unsafe { ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Value), "::", stringify!(data)), ); } impl Default for Value { diff --git a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs index b97bbac96f..7c691a9720 100644 --- a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs @@ -49,7 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -69,7 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -234,12 +234,14 @@ pub struct jsval_layout__bindgen_ty_1 { #[test] fn bindgen_test_layout_jsval_layout__bindgen_ty_1() { assert_eq!( - ::std::mem::size_of:: < jsval_layout__bindgen_ty_1 > (), 8usize, - concat!("Size of: ", stringify!(jsval_layout__bindgen_ty_1)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(jsval_layout__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < jsval_layout__bindgen_ty_1 > (), 8usize, - concat!("Alignment of ", stringify!(jsval_layout__bindgen_ty_1)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(jsval_layout__bindgen_ty_1)), ); } impl Clone for jsval_layout__bindgen_ty_1 { @@ -324,27 +326,44 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < jsval_layout__bindgen_ty_2__bindgen_ty_1 > (), 4usize, - concat!("Size of: ", stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < jsval_layout__bindgen_ty_2__bindgen_ty_1 > (), 4usize, - concat!("Alignment of ", stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).i32_) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), "::", stringify!(i32_)) + unsafe { ::std::ptr::addr_of!((*ptr).i32_) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), + "::", + stringify!(i32_), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).u32_) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), "::", stringify!(u32_)) + unsafe { ::std::ptr::addr_of!((*ptr).u32_) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), + "::", + stringify!(u32_), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).why) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), "::", stringify!(why)) + unsafe { ::std::ptr::addr_of!((*ptr).why) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), + "::", + stringify!(why), + ), ); } impl Clone for jsval_layout__bindgen_ty_2__bindgen_ty_1 { @@ -357,17 +376,24 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < jsval_layout__bindgen_ty_2 > (), 4usize, - concat!("Size of: ", stringify!(jsval_layout__bindgen_ty_2)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(jsval_layout__bindgen_ty_2)), ); assert_eq!( - ::std::mem::align_of:: < jsval_layout__bindgen_ty_2 > (), 4usize, - concat!("Alignment of ", stringify!(jsval_layout__bindgen_ty_2)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(jsval_layout__bindgen_ty_2)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).payload) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(jsval_layout__bindgen_ty_2), "::", - stringify!(payload)) + unsafe { ::std::ptr::addr_of!((*ptr).payload) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout__bindgen_ty_2), + "::", + stringify!(payload), + ), ); } impl Clone for jsval_layout__bindgen_ty_2 { @@ -380,43 +406,64 @@ fn bindgen_test_layout_jsval_layout() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < jsval_layout > (), 8usize, concat!("Size of: ", - stringify!(jsval_layout)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(jsval_layout)), ); assert_eq!( - ::std::mem::align_of:: < jsval_layout > (), 8usize, concat!("Alignment of ", - stringify!(jsval_layout)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(jsval_layout)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).asBits) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(jsval_layout), "::", stringify!(asBits)) + unsafe { ::std::ptr::addr_of!((*ptr).asBits) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(jsval_layout), "::", stringify!(asBits)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).debugView) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(jsval_layout), "::", - stringify!(debugView)) + unsafe { ::std::ptr::addr_of!((*ptr).debugView) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout), + "::", + stringify!(debugView), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).s) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(jsval_layout), "::", stringify!(s)) + unsafe { ::std::ptr::addr_of!((*ptr).s) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(jsval_layout), "::", stringify!(s)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).asDouble) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(jsval_layout), "::", - stringify!(asDouble)) + unsafe { ::std::ptr::addr_of!((*ptr).asDouble) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout), + "::", + stringify!(asDouble), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).asPtr) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(jsval_layout), "::", stringify!(asPtr)) + unsafe { ::std::ptr::addr_of!((*ptr).asPtr) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(jsval_layout), "::", stringify!(asPtr)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).asWord) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(jsval_layout), "::", stringify!(asWord)) + unsafe { ::std::ptr::addr_of!((*ptr).asWord) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(jsval_layout), "::", stringify!(asWord)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).asUIntPtr) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(jsval_layout), "::", - stringify!(asUIntPtr)) + unsafe { ::std::ptr::addr_of!((*ptr).asUIntPtr) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(jsval_layout), + "::", + stringify!(asUIntPtr), + ), ); } impl Clone for jsval_layout { @@ -434,16 +481,19 @@ fn bindgen_test_layout_Value() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < Value > (), 8usize, concat!("Size of: ", - stringify!(Value)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Value)), ); assert_eq!( - ::std::mem::align_of:: < Value > (), 8usize, concat!("Alignment of ", - stringify!(Value)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Value)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).data) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Value), "::", stringify!(data)) + unsafe { ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Value), "::", stringify!(data)), ); } impl Clone for Value { diff --git a/bindgen-tests/tests/expectations/tests/layout.rs b/bindgen-tests/tests/expectations/tests/layout.rs index 79048d2917..2c7dc047ba 100644 --- a/bindgen-tests/tests/expectations/tests/layout.rs +++ b/bindgen-tests/tests/expectations/tests/layout.rs @@ -6,8 +6,9 @@ pub struct header { #[test] fn bindgen_test_layout_header() { assert_eq!( - ::std::mem::size_of:: < header > (), 16usize, concat!("Size of: ", - stringify!(header)) + ::std::mem::size_of::
(), + 16usize, + concat!("Size of: ", stringify!(header)), ); } impl Default for header { diff --git a/bindgen-tests/tests/expectations/tests/layout_align.rs b/bindgen-tests/tests/expectations/tests/layout_align.rs index 7a8e0569a2..81fc8359d9 100644 --- a/bindgen-tests/tests/expectations/tests/layout_align.rs +++ b/bindgen-tests/tests/expectations/tests/layout_align.rs @@ -49,7 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -69,7 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -130,12 +130,14 @@ pub struct rte_kni_fifo { #[test] fn bindgen_test_layout_rte_kni_fifo() { assert_eq!( - ::std::mem::size_of:: < rte_kni_fifo > (), 16usize, concat!("Size of: ", - stringify!(rte_kni_fifo)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(rte_kni_fifo)), ); assert_eq!( - ::std::mem::align_of:: < rte_kni_fifo > (), 8usize, concat!("Alignment of ", - stringify!(rte_kni_fifo)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(rte_kni_fifo)), ); } impl Default for rte_kni_fifo { @@ -162,17 +164,24 @@ fn bindgen_test_layout_rte_eth_link() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < rte_eth_link > (), 8usize, concat!("Size of: ", - stringify!(rte_eth_link)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(rte_eth_link)), ); assert_eq!( - ::std::mem::align_of:: < rte_eth_link > (), 8usize, concat!("Alignment of ", - stringify!(rte_eth_link)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(rte_eth_link)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).link_speed) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_eth_link), "::", - stringify!(link_speed)) + unsafe { ::std::ptr::addr_of!((*ptr).link_speed) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_link), + "::", + stringify!(link_speed), + ), ); } impl rte_eth_link { diff --git a/bindgen-tests/tests/expectations/tests/layout_arp.rs b/bindgen-tests/tests/expectations/tests/layout_arp.rs index 1ee045593f..45e0156f68 100644 --- a/bindgen-tests/tests/expectations/tests/layout_arp.rs +++ b/bindgen-tests/tests/expectations/tests/layout_arp.rs @@ -27,17 +27,24 @@ fn bindgen_test_layout_ether_addr() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < ether_addr > (), 6usize, concat!("Size of: ", - stringify!(ether_addr)) + ::std::mem::size_of::(), + 6usize, + concat!("Size of: ", stringify!(ether_addr)), ); assert_eq!( - ::std::mem::align_of:: < ether_addr > (), 1usize, concat!("Alignment of ", - stringify!(ether_addr)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(ether_addr)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).addr_bytes) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(ether_addr), "::", - stringify!(addr_bytes)) + unsafe { ::std::ptr::addr_of!((*ptr).addr_bytes) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ether_addr), + "::", + stringify!(addr_bytes), + ), ); } /// ARP header IPv4 payload. @@ -58,30 +65,34 @@ fn bindgen_test_layout_arp_ipv4() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < arp_ipv4 > (), 20usize, concat!("Size of: ", - stringify!(arp_ipv4)) + ::std::mem::size_of::(), + 20usize, + concat!("Size of: ", stringify!(arp_ipv4)), ); assert_eq!( - ::std::mem::align_of:: < arp_ipv4 > (), 1usize, concat!("Alignment of ", - stringify!(arp_ipv4)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(arp_ipv4)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).arp_sha) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(arp_ipv4), "::", stringify!(arp_sha)) + unsafe { ::std::ptr::addr_of!((*ptr).arp_sha) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(arp_ipv4), "::", stringify!(arp_sha)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).arp_sip) as usize - ptr as usize }, 6usize, - concat!("Offset of field: ", stringify!(arp_ipv4), "::", stringify!(arp_sip)) + unsafe { ::std::ptr::addr_of!((*ptr).arp_sip) as usize - ptr as usize }, + 6usize, + concat!("Offset of field: ", stringify!(arp_ipv4), "::", stringify!(arp_sip)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).arp_tha) as usize - ptr as usize }, - 10usize, concat!("Offset of field: ", stringify!(arp_ipv4), "::", - stringify!(arp_tha)) + unsafe { ::std::ptr::addr_of!((*ptr).arp_tha) as usize - ptr as usize }, + 10usize, + concat!("Offset of field: ", stringify!(arp_ipv4), "::", stringify!(arp_tha)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).arp_tip) as usize - ptr as usize }, - 16usize, concat!("Offset of field: ", stringify!(arp_ipv4), "::", - stringify!(arp_tip)) + unsafe { ::std::ptr::addr_of!((*ptr).arp_tip) as usize - ptr as usize }, + 16usize, + concat!("Offset of field: ", stringify!(arp_ipv4), "::", stringify!(arp_tip)), ); } /// ARP header. @@ -100,36 +111,43 @@ fn bindgen_test_layout_arp_hdr() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < arp_hdr > (), 28usize, concat!("Size of: ", - stringify!(arp_hdr)) + ::std::mem::size_of::(), + 28usize, + concat!("Size of: ", stringify!(arp_hdr)), ); assert_eq!( - ::std::mem::align_of:: < arp_hdr > (), 1usize, concat!("Alignment of ", - stringify!(arp_hdr)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(arp_hdr)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).arp_hrd) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(arp_hdr), "::", stringify!(arp_hrd)) + unsafe { ::std::ptr::addr_of!((*ptr).arp_hrd) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(arp_hdr), "::", stringify!(arp_hrd)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).arp_pro) as usize - ptr as usize }, 2usize, - concat!("Offset of field: ", stringify!(arp_hdr), "::", stringify!(arp_pro)) + unsafe { ::std::ptr::addr_of!((*ptr).arp_pro) as usize - ptr as usize }, + 2usize, + concat!("Offset of field: ", stringify!(arp_hdr), "::", stringify!(arp_pro)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).arp_hln) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(arp_hdr), "::", stringify!(arp_hln)) + unsafe { ::std::ptr::addr_of!((*ptr).arp_hln) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(arp_hdr), "::", stringify!(arp_hln)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).arp_pln) as usize - ptr as usize }, 5usize, - concat!("Offset of field: ", stringify!(arp_hdr), "::", stringify!(arp_pln)) + unsafe { ::std::ptr::addr_of!((*ptr).arp_pln) as usize - ptr as usize }, + 5usize, + concat!("Offset of field: ", stringify!(arp_hdr), "::", stringify!(arp_pln)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).arp_op) as usize - ptr as usize }, 6usize, - concat!("Offset of field: ", stringify!(arp_hdr), "::", stringify!(arp_op)) + unsafe { ::std::ptr::addr_of!((*ptr).arp_op) as usize - ptr as usize }, + 6usize, + concat!("Offset of field: ", stringify!(arp_hdr), "::", stringify!(arp_op)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).arp_data) as usize - ptr as usize }, - 8usize, concat!("Offset of field: ", stringify!(arp_hdr), "::", - stringify!(arp_data)) + unsafe { ::std::ptr::addr_of!((*ptr).arp_data) as usize - ptr as usize }, + 8usize, + concat!("Offset of field: ", stringify!(arp_hdr), "::", stringify!(arp_data)), ); } diff --git a/bindgen-tests/tests/expectations/tests/layout_array.rs b/bindgen-tests/tests/expectations/tests/layout_array.rs index d9171be24b..dcf6f17b5c 100644 --- a/bindgen-tests/tests/expectations/tests/layout_array.rs +++ b/bindgen-tests/tests/expectations/tests/layout_array.rs @@ -66,40 +66,64 @@ 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:: < rte_mempool_ops > (), 128usize, concat!("Size of: ", - stringify!(rte_mempool_ops)) + ::std::mem::size_of::(), + 128usize, + concat!("Size of: ", stringify!(rte_mempool_ops)), ); assert_eq!( - ::std::mem::align_of:: < rte_mempool_ops > (), 64usize, concat!("Alignment of ", - stringify!(rte_mempool_ops)) + ::std::mem::align_of::(), + 64usize, + concat!("Alignment of ", stringify!(rte_mempool_ops)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).name) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_mempool_ops), "::", stringify!(name)) + unsafe { ::std::ptr::addr_of!((*ptr).name) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(rte_mempool_ops), "::", stringify!(name)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).alloc) as usize - ptr as usize }, 32usize, - concat!("Offset of field: ", stringify!(rte_mempool_ops), "::", - stringify!(alloc)) + unsafe { ::std::ptr::addr_of!((*ptr).alloc) as usize - ptr as usize }, + 32usize, + concat!( + "Offset of field: ", + stringify!(rte_mempool_ops), + "::", + stringify!(alloc), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).free) as usize - ptr as usize }, 40usize, - concat!("Offset of field: ", stringify!(rte_mempool_ops), "::", stringify!(free)) + unsafe { ::std::ptr::addr_of!((*ptr).free) as usize - ptr as usize }, + 40usize, + concat!("Offset of field: ", stringify!(rte_mempool_ops), "::", stringify!(free)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).enqueue) as usize - ptr as usize }, - 48usize, concat!("Offset of field: ", stringify!(rte_mempool_ops), "::", - stringify!(enqueue)) + unsafe { ::std::ptr::addr_of!((*ptr).enqueue) as usize - ptr as usize }, + 48usize, + concat!( + "Offset of field: ", + stringify!(rte_mempool_ops), + "::", + stringify!(enqueue), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).dequeue) as usize - ptr as usize }, - 56usize, concat!("Offset of field: ", stringify!(rte_mempool_ops), "::", - stringify!(dequeue)) + unsafe { ::std::ptr::addr_of!((*ptr).dequeue) as usize - ptr as usize }, + 56usize, + concat!( + "Offset of field: ", + stringify!(rte_mempool_ops), + "::", + stringify!(dequeue), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).get_count) as usize - ptr as usize }, - 64usize, concat!("Offset of field: ", stringify!(rte_mempool_ops), "::", - stringify!(get_count)) + unsafe { ::std::ptr::addr_of!((*ptr).get_count) as usize - ptr as usize }, + 64usize, + concat!( + "Offset of field: ", + stringify!(rte_mempool_ops), + "::", + stringify!(get_count), + ), ); } impl Default for rte_mempool_ops { @@ -130,17 +154,24 @@ 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:: < rte_spinlock_t > (), 4usize, concat!("Size of: ", - stringify!(rte_spinlock_t)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(rte_spinlock_t)), ); assert_eq!( - ::std::mem::align_of:: < rte_spinlock_t > (), 4usize, concat!("Alignment of ", - stringify!(rte_spinlock_t)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_spinlock_t)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).locked) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_spinlock_t), "::", - stringify!(locked)) + unsafe { ::std::ptr::addr_of!((*ptr).locked) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_spinlock_t), + "::", + stringify!(locked), + ), ); } /** Structure storing the table of registered ops structs, each of which contain @@ -167,27 +198,44 @@ 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:: < rte_mempool_ops_table > (), 2112usize, - concat!("Size of: ", stringify!(rte_mempool_ops_table)) + ::std::mem::size_of::(), + 2112usize, + concat!("Size of: ", stringify!(rte_mempool_ops_table)), ); assert_eq!( - ::std::mem::align_of:: < rte_mempool_ops_table > (), 64usize, - concat!("Alignment of ", stringify!(rte_mempool_ops_table)) + ::std::mem::align_of::(), + 64usize, + concat!("Alignment of ", stringify!(rte_mempool_ops_table)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).sl) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_mempool_ops_table), "::", - stringify!(sl)) + unsafe { ::std::ptr::addr_of!((*ptr).sl) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mempool_ops_table), + "::", + stringify!(sl), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).num_ops) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(rte_mempool_ops_table), "::", - stringify!(num_ops)) + unsafe { ::std::ptr::addr_of!((*ptr).num_ops) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_mempool_ops_table), + "::", + stringify!(num_ops), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).ops) as usize - ptr as usize }, 64usize, - concat!("Offset of field: ", stringify!(rte_mempool_ops_table), "::", - stringify!(ops)) + unsafe { ::std::ptr::addr_of!((*ptr).ops) as usize - ptr as usize }, + 64usize, + concat!( + "Offset of field: ", + stringify!(rte_mempool_ops_table), + "::", + stringify!(ops), + ), ); } impl Default for rte_mempool_ops_table { @@ -219,17 +267,24 @@ 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:: < malloc_heap__bindgen_ty_1 > (), 8usize, - concat!("Size of: ", stringify!(malloc_heap__bindgen_ty_1)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(malloc_heap__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < malloc_heap__bindgen_ty_1 > (), 8usize, - concat!("Alignment of ", stringify!(malloc_heap__bindgen_ty_1)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(malloc_heap__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).lh_first) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(malloc_heap__bindgen_ty_1), "::", - stringify!(lh_first)) + unsafe { ::std::ptr::addr_of!((*ptr).lh_first) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(malloc_heap__bindgen_ty_1), + "::", + stringify!(lh_first), + ), ); } impl Default for malloc_heap__bindgen_ty_1 { @@ -246,31 +301,49 @@ 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:: < malloc_heap > (), 128usize, concat!("Size of: ", - stringify!(malloc_heap)) + ::std::mem::size_of::(), + 128usize, + concat!("Size of: ", stringify!(malloc_heap)), ); assert_eq!( - ::std::mem::align_of:: < malloc_heap > (), 64usize, concat!("Alignment of ", - stringify!(malloc_heap)) + ::std::mem::align_of::(), + 64usize, + concat!("Alignment of ", stringify!(malloc_heap)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).lock) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(malloc_heap), "::", stringify!(lock)) + unsafe { ::std::ptr::addr_of!((*ptr).lock) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(malloc_heap), "::", stringify!(lock)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).free_head) as usize - ptr as usize }, - 8usize, concat!("Offset of field: ", stringify!(malloc_heap), "::", - stringify!(free_head)) + unsafe { ::std::ptr::addr_of!((*ptr).free_head) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(malloc_heap), + "::", + stringify!(free_head), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).alloc_count) as usize - ptr as usize }, - 112usize, concat!("Offset of field: ", stringify!(malloc_heap), "::", - stringify!(alloc_count)) + unsafe { ::std::ptr::addr_of!((*ptr).alloc_count) as usize - ptr as usize }, + 112usize, + concat!( + "Offset of field: ", + stringify!(malloc_heap), + "::", + stringify!(alloc_count), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).total_size) as usize - ptr as usize }, - 120usize, concat!("Offset of field: ", stringify!(malloc_heap), "::", - stringify!(total_size)) + unsafe { ::std::ptr::addr_of!((*ptr).total_size) as usize - ptr as usize }, + 120usize, + concat!( + "Offset of field: ", + stringify!(malloc_heap), + "::", + stringify!(total_size), + ), ); } impl Default for malloc_heap { 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 2eb95b2d85..52e7532ba2 100644 --- a/bindgen-tests/tests/expectations/tests/layout_array_too_long.rs +++ b/bindgen-tests/tests/expectations/tests/layout_array_too_long.rs @@ -32,24 +32,29 @@ 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:: < ip_frag > (), 16usize, concat!("Size of: ", - stringify!(ip_frag)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(ip_frag)), ); assert_eq!( - ::std::mem::align_of:: < ip_frag > (), 8usize, concat!("Alignment of ", - stringify!(ip_frag)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(ip_frag)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).ofs) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(ip_frag), "::", stringify!(ofs)) + unsafe { ::std::ptr::addr_of!((*ptr).ofs) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(ip_frag), "::", stringify!(ofs)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).len) as usize - ptr as usize }, 2usize, - concat!("Offset of field: ", stringify!(ip_frag), "::", stringify!(len)) + unsafe { ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize }, + 2usize, + concat!("Offset of field: ", stringify!(ip_frag), "::", stringify!(len)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mb) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(ip_frag), "::", stringify!(mb)) + unsafe { ::std::ptr::addr_of!((*ptr).mb) as usize - ptr as usize }, + 8usize, + concat!("Offset of field: ", stringify!(ip_frag), "::", stringify!(mb)), ); } impl Default for ip_frag { @@ -77,25 +82,29 @@ 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:: < ip_frag_key > (), 40usize, concat!("Size of: ", - stringify!(ip_frag_key)) + ::std::mem::size_of::(), + 40usize, + concat!("Size of: ", stringify!(ip_frag_key)), ); assert_eq!( - ::std::mem::align_of:: < ip_frag_key > (), 8usize, concat!("Alignment of ", - stringify!(ip_frag_key)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(ip_frag_key)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).src_dst) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(ip_frag_key), "::", stringify!(src_dst)) + unsafe { ::std::ptr::addr_of!((*ptr).src_dst) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(ip_frag_key), "::", stringify!(src_dst)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).id) as usize - ptr as usize }, 32usize, - concat!("Offset of field: ", stringify!(ip_frag_key), "::", stringify!(id)) + unsafe { ::std::ptr::addr_of!((*ptr).id) as usize - ptr as usize }, + 32usize, + concat!("Offset of field: ", stringify!(ip_frag_key), "::", stringify!(id)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).key_len) as usize - ptr as usize }, - 36usize, concat!("Offset of field: ", stringify!(ip_frag_key), "::", - stringify!(key_len)) + unsafe { ::std::ptr::addr_of!((*ptr).key_len) as usize - ptr as usize }, + 36usize, + concat!("Offset of field: ", stringify!(ip_frag_key), "::", stringify!(key_len)), ); } /** @internal Fragmented packet to reassemble. @@ -130,22 +139,34 @@ 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:: < ip_frag_pkt__bindgen_ty_1 > (), 16usize, - concat!("Size of: ", stringify!(ip_frag_pkt__bindgen_ty_1)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(ip_frag_pkt__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < ip_frag_pkt__bindgen_ty_1 > (), 8usize, - concat!("Alignment of ", stringify!(ip_frag_pkt__bindgen_ty_1)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(ip_frag_pkt__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).tqe_next) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(ip_frag_pkt__bindgen_ty_1), "::", - stringify!(tqe_next)) + unsafe { ::std::ptr::addr_of!((*ptr).tqe_next) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_pkt__bindgen_ty_1), + "::", + stringify!(tqe_next), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).tqe_prev) as usize - ptr as usize }, - 8usize, concat!("Offset of field: ", stringify!(ip_frag_pkt__bindgen_ty_1), "::", - stringify!(tqe_prev)) + unsafe { ::std::ptr::addr_of!((*ptr).tqe_prev) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_pkt__bindgen_ty_1), + "::", + stringify!(tqe_prev), + ), ); } impl Default for ip_frag_pkt__bindgen_ty_1 { @@ -162,43 +183,59 @@ 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:: < ip_frag_pkt > (), 192usize, concat!("Size of: ", - stringify!(ip_frag_pkt)) + ::std::mem::size_of::(), + 192usize, + concat!("Size of: ", stringify!(ip_frag_pkt)), ); assert_eq!( - ::std::mem::align_of:: < ip_frag_pkt > (), 64usize, concat!("Alignment of ", - stringify!(ip_frag_pkt)) + ::std::mem::align_of::(), + 64usize, + concat!("Alignment of ", stringify!(ip_frag_pkt)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).lru) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", stringify!(lru)) + unsafe { ::std::ptr::addr_of!((*ptr).lru) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", stringify!(lru)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).key) as usize - ptr as usize }, 16usize, - concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", stringify!(key)) + unsafe { ::std::ptr::addr_of!((*ptr).key) as usize - ptr as usize }, + 16usize, + concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", stringify!(key)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).start) as usize - ptr as usize }, 56usize, - concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", stringify!(start)) + unsafe { ::std::ptr::addr_of!((*ptr).start) as usize - ptr as usize }, + 56usize, + concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", stringify!(start)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).total_size) as usize - ptr as usize }, - 64usize, concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", - stringify!(total_size)) + unsafe { ::std::ptr::addr_of!((*ptr).total_size) as usize - ptr as usize }, + 64usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_pkt), + "::", + stringify!(total_size), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).frag_size) as usize - ptr as usize }, - 68usize, concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", - stringify!(frag_size)) + unsafe { ::std::ptr::addr_of!((*ptr).frag_size) as usize - ptr as usize }, + 68usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_pkt), + "::", + stringify!(frag_size), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).last_idx) as usize - ptr as usize }, - 72usize, concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", - stringify!(last_idx)) + unsafe { ::std::ptr::addr_of!((*ptr).last_idx) as usize - ptr as usize }, + 72usize, + concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", stringify!(last_idx)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).frags) as usize - ptr as usize }, 80usize, - concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", stringify!(frags)) + unsafe { ::std::ptr::addr_of!((*ptr).frags) as usize - ptr as usize }, + 80usize, + concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", stringify!(frags)), ); } impl Default for ip_frag_pkt { diff --git a/bindgen-tests/tests/expectations/tests/layout_cmdline_token.rs b/bindgen-tests/tests/expectations/tests/layout_cmdline_token.rs index af18e90d12..6141ab8f67 100644 --- a/bindgen-tests/tests/expectations/tests/layout_cmdline_token.rs +++ b/bindgen-tests/tests/expectations/tests/layout_cmdline_token.rs @@ -12,22 +12,34 @@ fn bindgen_test_layout_cmdline_token_hdr() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < cmdline_token_hdr > (), 16usize, concat!("Size of: ", - stringify!(cmdline_token_hdr)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(cmdline_token_hdr)), ); assert_eq!( - ::std::mem::align_of:: < cmdline_token_hdr > (), 8usize, concat!("Alignment of ", - stringify!(cmdline_token_hdr)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(cmdline_token_hdr)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).ops) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(cmdline_token_hdr), "::", - stringify!(ops)) + unsafe { ::std::ptr::addr_of!((*ptr).ops) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(cmdline_token_hdr), + "::", + stringify!(ops), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).offset) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(cmdline_token_hdr), "::", - stringify!(offset)) + unsafe { ::std::ptr::addr_of!((*ptr).offset) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(cmdline_token_hdr), + "::", + stringify!(offset), + ), ); } impl Default for cmdline_token_hdr { @@ -100,32 +112,54 @@ fn bindgen_test_layout_cmdline_token_ops() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < cmdline_token_ops > (), 32usize, concat!("Size of: ", - stringify!(cmdline_token_ops)) + ::std::mem::size_of::(), + 32usize, + concat!("Size of: ", stringify!(cmdline_token_ops)), ); assert_eq!( - ::std::mem::align_of:: < cmdline_token_ops > (), 8usize, concat!("Alignment of ", - stringify!(cmdline_token_ops)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(cmdline_token_ops)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).parse) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(cmdline_token_ops), "::", - stringify!(parse)) + unsafe { ::std::ptr::addr_of!((*ptr).parse) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(cmdline_token_ops), + "::", + stringify!(parse), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).complete_get_nb) as usize - ptr as usize }, - 8usize, concat!("Offset of field: ", stringify!(cmdline_token_ops), "::", - stringify!(complete_get_nb)) + unsafe { ::std::ptr::addr_of!((*ptr).complete_get_nb) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(cmdline_token_ops), + "::", + stringify!(complete_get_nb), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).complete_get_elt) as usize - ptr as usize - }, 16usize, concat!("Offset of field: ", stringify!(cmdline_token_ops), "::", - stringify!(complete_get_elt)) + unsafe { ::std::ptr::addr_of!((*ptr).complete_get_elt) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(cmdline_token_ops), + "::", + stringify!(complete_get_elt), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).get_help) as usize - ptr as usize }, - 24usize, concat!("Offset of field: ", stringify!(cmdline_token_ops), "::", - stringify!(get_help)) + unsafe { ::std::ptr::addr_of!((*ptr).get_help) as usize - ptr as usize }, + 24usize, + concat!( + "Offset of field: ", + stringify!(cmdline_token_ops), + "::", + stringify!(get_help), + ), ); } #[repr(u32)] @@ -150,17 +184,24 @@ fn bindgen_test_layout_cmdline_token_num_data() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < cmdline_token_num_data > (), 4usize, concat!("Size of: ", - stringify!(cmdline_token_num_data)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(cmdline_token_num_data)), ); assert_eq!( - ::std::mem::align_of:: < cmdline_token_num_data > (), 4usize, - concat!("Alignment of ", stringify!(cmdline_token_num_data)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(cmdline_token_num_data)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).type_) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(cmdline_token_num_data), "::", - stringify!(type_)) + unsafe { ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(cmdline_token_num_data), + "::", + stringify!(type_), + ), ); } impl Default for cmdline_token_num_data { @@ -183,22 +224,34 @@ fn bindgen_test_layout_cmdline_token_num() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < cmdline_token_num > (), 24usize, concat!("Size of: ", - stringify!(cmdline_token_num)) + ::std::mem::size_of::(), + 24usize, + concat!("Size of: ", stringify!(cmdline_token_num)), ); assert_eq!( - ::std::mem::align_of:: < cmdline_token_num > (), 8usize, concat!("Alignment of ", - stringify!(cmdline_token_num)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(cmdline_token_num)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).hdr) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(cmdline_token_num), "::", - stringify!(hdr)) + unsafe { ::std::ptr::addr_of!((*ptr).hdr) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(cmdline_token_num), + "::", + stringify!(hdr), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).num_data) as usize - ptr as usize }, - 16usize, concat!("Offset of field: ", stringify!(cmdline_token_num), "::", - stringify!(num_data)) + unsafe { ::std::ptr::addr_of!((*ptr).num_data) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(cmdline_token_num), + "::", + stringify!(num_data), + ), ); } impl Default for cmdline_token_num { diff --git a/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs b/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs index 1ec0744f0d..84af546c8c 100644 --- a/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs +++ b/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs @@ -49,7 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -69,7 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -155,27 +155,44 @@ 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:: < rte_eth_rxmode > (), 12usize, concat!("Size of: ", - stringify!(rte_eth_rxmode)) + ::std::mem::size_of::(), + 12usize, + concat!("Size of: ", stringify!(rte_eth_rxmode)), ); assert_eq!( - ::std::mem::align_of:: < rte_eth_rxmode > (), 4usize, concat!("Alignment of ", - stringify!(rte_eth_rxmode)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_eth_rxmode)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mq_mode) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_eth_rxmode), "::", - stringify!(mq_mode)) + unsafe { ::std::ptr::addr_of!((*ptr).mq_mode) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_rxmode), + "::", + stringify!(mq_mode), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).max_rx_pkt_len) as usize - ptr as usize }, - 4usize, concat!("Offset of field: ", stringify!(rte_eth_rxmode), "::", - stringify!(max_rx_pkt_len)) + unsafe { ::std::ptr::addr_of!((*ptr).max_rx_pkt_len) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_rxmode), + "::", + stringify!(max_rx_pkt_len), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).split_hdr_size) as usize - ptr as usize }, - 8usize, concat!("Offset of field: ", stringify!(rte_eth_rxmode), "::", - stringify!(split_hdr_size)) + unsafe { ::std::ptr::addr_of!((*ptr).split_hdr_size) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_rxmode), + "::", + stringify!(split_hdr_size), + ), ); } impl Default for rte_eth_rxmode { @@ -428,21 +445,29 @@ 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:: < rte_eth_txmode > (), 8usize, concat!("Size of: ", - stringify!(rte_eth_txmode)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(rte_eth_txmode)), ); assert_eq!( - ::std::mem::align_of:: < rte_eth_txmode > (), 4usize, concat!("Alignment of ", - stringify!(rte_eth_txmode)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_eth_txmode)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mq_mode) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_eth_txmode), "::", - stringify!(mq_mode)) + unsafe { ::std::ptr::addr_of!((*ptr).mq_mode) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_txmode), + "::", + stringify!(mq_mode), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).pvid) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(rte_eth_txmode), "::", stringify!(pvid)) + unsafe { ::std::ptr::addr_of!((*ptr).pvid) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(rte_eth_txmode), "::", stringify!(pvid)), ); } impl Default for rte_eth_txmode { @@ -561,27 +586,44 @@ 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:: < rte_eth_rss_conf > (), 24usize, concat!("Size of: ", - stringify!(rte_eth_rss_conf)) + ::std::mem::size_of::(), + 24usize, + concat!("Size of: ", stringify!(rte_eth_rss_conf)), ); assert_eq!( - ::std::mem::align_of:: < rte_eth_rss_conf > (), 8usize, concat!("Alignment of ", - stringify!(rte_eth_rss_conf)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(rte_eth_rss_conf)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).rss_key) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_eth_rss_conf), "::", - stringify!(rss_key)) + unsafe { ::std::ptr::addr_of!((*ptr).rss_key) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_rss_conf), + "::", + stringify!(rss_key), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).rss_key_len) as usize - ptr as usize }, - 8usize, concat!("Offset of field: ", stringify!(rte_eth_rss_conf), "::", - stringify!(rss_key_len)) + unsafe { ::std::ptr::addr_of!((*ptr).rss_key_len) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_rss_conf), + "::", + stringify!(rss_key_len), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).rss_hf) as usize - ptr as usize }, 16usize, - concat!("Offset of field: ", stringify!(rte_eth_rss_conf), "::", - stringify!(rss_hf)) + unsafe { ::std::ptr::addr_of!((*ptr).rss_hf) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_rss_conf), + "::", + stringify!(rss_hf), + ), ); } impl Default for rte_eth_rss_conf { @@ -654,22 +696,34 @@ 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:: < rte_eth_vmdq_dcb_conf__bindgen_ty_1 > (), 16usize, - concat!("Size of: ", stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < rte_eth_vmdq_dcb_conf__bindgen_ty_1 > (), 8usize, - concat!("Alignment of ", stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).vlan_id) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1), - "::", stringify!(vlan_id)) + unsafe { ::std::ptr::addr_of!((*ptr).vlan_id) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1), + "::", + stringify!(vlan_id), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).pools) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1), - "::", stringify!(pools)) + unsafe { ::std::ptr::addr_of!((*ptr).pools) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1), + "::", + stringify!(pools), + ), ); } #[test] @@ -677,42 +731,76 @@ 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:: < rte_eth_vmdq_dcb_conf > (), 1040usize, - concat!("Size of: ", stringify!(rte_eth_vmdq_dcb_conf)) + ::std::mem::size_of::(), + 1040usize, + concat!("Size of: ", stringify!(rte_eth_vmdq_dcb_conf)), ); assert_eq!( - ::std::mem::align_of:: < rte_eth_vmdq_dcb_conf > (), 8usize, - concat!("Alignment of ", stringify!(rte_eth_vmdq_dcb_conf)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(rte_eth_vmdq_dcb_conf)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).nb_queue_pools) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_dcb_conf), "::", - stringify!(nb_queue_pools)) + unsafe { ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf), + "::", + stringify!(nb_queue_pools), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).enable_default_pool) as usize - ptr as - usize }, 4usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_dcb_conf), - "::", stringify!(enable_default_pool)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).default_pool) as usize - ptr as usize }, - 5usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_dcb_conf), "::", - stringify!(default_pool)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).nb_pool_maps) as usize - ptr as usize }, - 6usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_dcb_conf), "::", - stringify!(nb_pool_maps)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).pool_map) as usize - ptr as usize }, - 8usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_dcb_conf), "::", - stringify!(pool_map)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).dcb_tc) as usize - ptr as usize }, - 1032usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_dcb_conf), "::", - stringify!(dcb_tc)) + unsafe { + ::std::ptr::addr_of!((*ptr).enable_default_pool) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf), + "::", + stringify!(enable_default_pool), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).default_pool) as usize - ptr as usize }, + 5usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf), + "::", + stringify!(default_pool), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).nb_pool_maps) as usize - ptr as usize }, + 6usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf), + "::", + stringify!(nb_pool_maps), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).pool_map) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf), + "::", + stringify!(pool_map), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize }, + 1032usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf), + "::", + stringify!(dcb_tc), + ), ); } impl Default for rte_eth_vmdq_dcb_conf { @@ -737,22 +825,34 @@ 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:: < rte_eth_dcb_rx_conf > (), 12usize, concat!("Size of: ", - stringify!(rte_eth_dcb_rx_conf)) + ::std::mem::size_of::(), + 12usize, + concat!("Size of: ", stringify!(rte_eth_dcb_rx_conf)), ); assert_eq!( - ::std::mem::align_of:: < rte_eth_dcb_rx_conf > (), 4usize, - concat!("Alignment of ", stringify!(rte_eth_dcb_rx_conf)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_eth_dcb_rx_conf)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).nb_tcs) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_eth_dcb_rx_conf), "::", - stringify!(nb_tcs)) + unsafe { ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_dcb_rx_conf), + "::", + stringify!(nb_tcs), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).dcb_tc) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(rte_eth_dcb_rx_conf), "::", - stringify!(dcb_tc)) + unsafe { ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_dcb_rx_conf), + "::", + stringify!(dcb_tc), + ), ); } impl Default for rte_eth_dcb_rx_conf { @@ -777,22 +877,34 @@ 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:: < rte_eth_vmdq_dcb_tx_conf > (), 12usize, - concat!("Size of: ", stringify!(rte_eth_vmdq_dcb_tx_conf)) + ::std::mem::size_of::(), + 12usize, + concat!("Size of: ", stringify!(rte_eth_vmdq_dcb_tx_conf)), ); assert_eq!( - ::std::mem::align_of:: < rte_eth_vmdq_dcb_tx_conf > (), 4usize, - concat!("Alignment of ", stringify!(rte_eth_vmdq_dcb_tx_conf)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_eth_vmdq_dcb_tx_conf)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).nb_queue_pools) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_dcb_tx_conf), "::", - stringify!(nb_queue_pools)) + unsafe { ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_tx_conf), + "::", + stringify!(nb_queue_pools), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).dcb_tc) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(rte_eth_vmdq_dcb_tx_conf), "::", - stringify!(dcb_tc)) + unsafe { ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_tx_conf), + "::", + stringify!(dcb_tc), + ), ); } impl Default for rte_eth_vmdq_dcb_tx_conf { @@ -817,22 +929,34 @@ 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:: < rte_eth_dcb_tx_conf > (), 12usize, concat!("Size of: ", - stringify!(rte_eth_dcb_tx_conf)) + ::std::mem::size_of::(), + 12usize, + concat!("Size of: ", stringify!(rte_eth_dcb_tx_conf)), ); assert_eq!( - ::std::mem::align_of:: < rte_eth_dcb_tx_conf > (), 4usize, - concat!("Alignment of ", stringify!(rte_eth_dcb_tx_conf)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_eth_dcb_tx_conf)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).nb_tcs) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_eth_dcb_tx_conf), "::", - stringify!(nb_tcs)) + unsafe { ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_dcb_tx_conf), + "::", + stringify!(nb_tcs), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).dcb_tc) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(rte_eth_dcb_tx_conf), "::", - stringify!(dcb_tc)) + unsafe { ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_dcb_tx_conf), + "::", + stringify!(dcb_tc), + ), ); } impl Default for rte_eth_dcb_tx_conf { @@ -855,17 +979,24 @@ 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:: < rte_eth_vmdq_tx_conf > (), 4usize, concat!("Size of: ", - stringify!(rte_eth_vmdq_tx_conf)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(rte_eth_vmdq_tx_conf)), ); assert_eq!( - ::std::mem::align_of:: < rte_eth_vmdq_tx_conf > (), 4usize, - concat!("Alignment of ", stringify!(rte_eth_vmdq_tx_conf)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_eth_vmdq_tx_conf)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).nb_queue_pools) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_tx_conf), "::", - stringify!(nb_queue_pools)) + unsafe { ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_tx_conf), + "::", + stringify!(nb_queue_pools), + ), ); } impl Default for rte_eth_vmdq_tx_conf { @@ -908,22 +1039,34 @@ 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:: < rte_eth_vmdq_rx_conf__bindgen_ty_1 > (), 16usize, - concat!("Size of: ", stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < rte_eth_vmdq_rx_conf__bindgen_ty_1 > (), 8usize, - concat!("Alignment of ", stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).vlan_id) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1), - "::", stringify!(vlan_id)) + unsafe { ::std::ptr::addr_of!((*ptr).vlan_id) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1), + "::", + stringify!(vlan_id), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).pools) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1), - "::", stringify!(pools)) + unsafe { ::std::ptr::addr_of!((*ptr).pools) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1), + "::", + stringify!(pools), + ), ); } #[test] @@ -931,47 +1074,86 @@ 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:: < rte_eth_vmdq_rx_conf > (), 1040usize, - concat!("Size of: ", stringify!(rte_eth_vmdq_rx_conf)) - ); - assert_eq!( - ::std::mem::align_of:: < rte_eth_vmdq_rx_conf > (), 8usize, - concat!("Alignment of ", stringify!(rte_eth_vmdq_rx_conf)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).nb_queue_pools) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_rx_conf), "::", - stringify!(nb_queue_pools)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).enable_default_pool) as usize - ptr as - usize }, 4usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_rx_conf), - "::", stringify!(enable_default_pool)) + ::std::mem::size_of::(), + 1040usize, + concat!("Size of: ", stringify!(rte_eth_vmdq_rx_conf)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).default_pool) as usize - ptr as usize }, - 5usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_rx_conf), "::", - stringify!(default_pool)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(rte_eth_vmdq_rx_conf)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).enable_loop_back) as usize - ptr as usize - }, 6usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_rx_conf), "::", - stringify!(enable_loop_back)) + unsafe { ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf), + "::", + stringify!(nb_queue_pools), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).nb_pool_maps) as usize - ptr as usize }, - 7usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_rx_conf), "::", - stringify!(nb_pool_maps)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).rx_mode) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(rte_eth_vmdq_rx_conf), "::", - stringify!(rx_mode)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).pool_map) as usize - ptr as usize }, - 16usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_rx_conf), "::", - stringify!(pool_map)) + unsafe { + ::std::ptr::addr_of!((*ptr).enable_default_pool) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf), + "::", + stringify!(enable_default_pool), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).default_pool) as usize - ptr as usize }, + 5usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf), + "::", + stringify!(default_pool), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).enable_loop_back) as usize - ptr as usize }, + 6usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf), + "::", + stringify!(enable_loop_back), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).nb_pool_maps) as usize - ptr as usize }, + 7usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf), + "::", + stringify!(nb_pool_maps), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).rx_mode) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf), + "::", + stringify!(rx_mode), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).pool_map) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf), + "::", + stringify!(pool_map), + ), ); } impl Default for rte_eth_vmdq_rx_conf { @@ -1041,37 +1223,64 @@ 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:: < rte_eth_ipv4_flow > (), 12usize, concat!("Size of: ", - stringify!(rte_eth_ipv4_flow)) + ::std::mem::size_of::(), + 12usize, + concat!("Size of: ", stringify!(rte_eth_ipv4_flow)), ); assert_eq!( - ::std::mem::align_of:: < rte_eth_ipv4_flow > (), 4usize, concat!("Alignment of ", - stringify!(rte_eth_ipv4_flow)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_eth_ipv4_flow)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).src_ip) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_eth_ipv4_flow), "::", - stringify!(src_ip)) + unsafe { ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv4_flow), + "::", + stringify!(src_ip), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).dst_ip) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(rte_eth_ipv4_flow), "::", - stringify!(dst_ip)) + unsafe { ::std::ptr::addr_of!((*ptr).dst_ip) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv4_flow), + "::", + stringify!(dst_ip), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).tos) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(rte_eth_ipv4_flow), "::", - stringify!(tos)) + unsafe { ::std::ptr::addr_of!((*ptr).tos) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv4_flow), + "::", + stringify!(tos), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).ttl) as usize - ptr as usize }, 9usize, - concat!("Offset of field: ", stringify!(rte_eth_ipv4_flow), "::", - stringify!(ttl)) + unsafe { ::std::ptr::addr_of!((*ptr).ttl) as usize - ptr as usize }, + 9usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv4_flow), + "::", + stringify!(ttl), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).proto) as usize - ptr as usize }, 10usize, - concat!("Offset of field: ", stringify!(rte_eth_ipv4_flow), "::", - stringify!(proto)) + unsafe { ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize }, + 10usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv4_flow), + "::", + stringify!(proto), + ), ); } /// A structure used to define the input for IPV6 flow @@ -1094,36 +1303,59 @@ 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:: < rte_eth_ipv6_flow > (), 36usize, concat!("Size of: ", - stringify!(rte_eth_ipv6_flow)) + ::std::mem::size_of::(), + 36usize, + concat!("Size of: ", stringify!(rte_eth_ipv6_flow)), ); assert_eq!( - ::std::mem::align_of:: < rte_eth_ipv6_flow > (), 4usize, concat!("Alignment of ", - stringify!(rte_eth_ipv6_flow)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_eth_ipv6_flow)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).src_ip) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_eth_ipv6_flow), "::", - stringify!(src_ip)) + unsafe { ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv6_flow), + "::", + stringify!(src_ip), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).dst_ip) as usize - ptr as usize }, 16usize, - concat!("Offset of field: ", stringify!(rte_eth_ipv6_flow), "::", - stringify!(dst_ip)) + unsafe { ::std::ptr::addr_of!((*ptr).dst_ip) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv6_flow), + "::", + stringify!(dst_ip), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).tc) as usize - ptr as usize }, 32usize, - concat!("Offset of field: ", stringify!(rte_eth_ipv6_flow), "::", stringify!(tc)) + unsafe { ::std::ptr::addr_of!((*ptr).tc) as usize - ptr as usize }, + 32usize, + concat!("Offset of field: ", stringify!(rte_eth_ipv6_flow), "::", stringify!(tc)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).proto) as usize - ptr as usize }, 33usize, - concat!("Offset of field: ", stringify!(rte_eth_ipv6_flow), "::", - stringify!(proto)) + unsafe { ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize }, + 33usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv6_flow), + "::", + stringify!(proto), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).hop_limits) as usize - ptr as usize }, - 34usize, concat!("Offset of field: ", stringify!(rte_eth_ipv6_flow), "::", - stringify!(hop_limits)) + unsafe { ::std::ptr::addr_of!((*ptr).hop_limits) as usize - ptr as usize }, + 34usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv6_flow), + "::", + stringify!(hop_limits), + ), ); } /** A structure used to configure FDIR masks that are used by the device @@ -1155,52 +1387,96 @@ 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:: < rte_eth_fdir_masks > (), 68usize, concat!("Size of: ", - stringify!(rte_eth_fdir_masks)) - ); - assert_eq!( - ::std::mem::align_of:: < rte_eth_fdir_masks > (), 4usize, - concat!("Alignment of ", stringify!(rte_eth_fdir_masks)) + ::std::mem::size_of::(), + 68usize, + concat!("Size of: ", stringify!(rte_eth_fdir_masks)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).vlan_tci_mask) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_masks), "::", - stringify!(vlan_tci_mask)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_eth_fdir_masks)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).ipv4_mask) as usize - ptr as usize }, - 4usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_masks), "::", - stringify!(ipv4_mask)) + unsafe { ::std::ptr::addr_of!((*ptr).vlan_tci_mask) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(vlan_tci_mask), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).ipv6_mask) as usize - ptr as usize }, - 16usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_masks), "::", - stringify!(ipv6_mask)) + unsafe { ::std::ptr::addr_of!((*ptr).ipv4_mask) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(ipv4_mask), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).src_port_mask) as usize - ptr as usize }, - 52usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_masks), "::", - stringify!(src_port_mask)) + unsafe { ::std::ptr::addr_of!((*ptr).ipv6_mask) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(ipv6_mask), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).dst_port_mask) as usize - ptr as usize }, - 54usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_masks), "::", - stringify!(dst_port_mask)) + unsafe { ::std::ptr::addr_of!((*ptr).src_port_mask) as usize - ptr as usize }, + 52usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(src_port_mask), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mac_addr_byte_mask) as usize - ptr as usize - }, 56usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_masks), "::", - stringify!(mac_addr_byte_mask)) + unsafe { ::std::ptr::addr_of!((*ptr).dst_port_mask) as usize - ptr as usize }, + 54usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(dst_port_mask), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).tunnel_id_mask) as usize - ptr as usize }, - 60usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_masks), "::", - stringify!(tunnel_id_mask)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).tunnel_type_mask) as usize - ptr as usize - }, 64usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_masks), "::", - stringify!(tunnel_type_mask)) + unsafe { + ::std::ptr::addr_of!((*ptr).mac_addr_byte_mask) as usize - ptr as usize + }, + 56usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(mac_addr_byte_mask), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).tunnel_id_mask) as usize - ptr as usize }, + 60usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(tunnel_id_mask), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).tunnel_type_mask) as usize - ptr as usize }, + 64usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(tunnel_type_mask), + ), ); } #[repr(u32)] @@ -1228,22 +1504,34 @@ 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:: < rte_eth_flex_payload_cfg > (), 36usize, - concat!("Size of: ", stringify!(rte_eth_flex_payload_cfg)) + ::std::mem::size_of::(), + 36usize, + concat!("Size of: ", stringify!(rte_eth_flex_payload_cfg)), ); assert_eq!( - ::std::mem::align_of:: < rte_eth_flex_payload_cfg > (), 4usize, - concat!("Alignment of ", stringify!(rte_eth_flex_payload_cfg)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_eth_flex_payload_cfg)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).type_) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_eth_flex_payload_cfg), "::", - stringify!(type_)) + unsafe { ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_flex_payload_cfg), + "::", + stringify!(type_), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).src_offset) as usize - ptr as usize }, - 4usize, concat!("Offset of field: ", stringify!(rte_eth_flex_payload_cfg), "::", - stringify!(src_offset)) + unsafe { ::std::ptr::addr_of!((*ptr).src_offset) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_flex_payload_cfg), + "::", + stringify!(src_offset), + ), ); } impl Default for rte_eth_flex_payload_cfg { @@ -1268,22 +1556,34 @@ 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:: < rte_eth_fdir_flex_mask > (), 18usize, - concat!("Size of: ", stringify!(rte_eth_fdir_flex_mask)) + ::std::mem::size_of::(), + 18usize, + concat!("Size of: ", stringify!(rte_eth_fdir_flex_mask)), ); assert_eq!( - ::std::mem::align_of:: < rte_eth_fdir_flex_mask > (), 2usize, - concat!("Alignment of ", stringify!(rte_eth_fdir_flex_mask)) + ::std::mem::align_of::(), + 2usize, + concat!("Alignment of ", stringify!(rte_eth_fdir_flex_mask)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).flow_type) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_flex_mask), "::", - stringify!(flow_type)) + unsafe { ::std::ptr::addr_of!((*ptr).flow_type) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_flex_mask), + "::", + stringify!(flow_type), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mask) as usize - ptr as usize }, 2usize, - concat!("Offset of field: ", stringify!(rte_eth_fdir_flex_mask), "::", - stringify!(mask)) + unsafe { ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize }, + 2usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_flex_mask), + "::", + stringify!(mask), + ), ); } /** A structure used to define all flexible payload related setting @@ -1303,32 +1603,54 @@ 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:: < rte_eth_fdir_flex_conf > (), 688usize, - concat!("Size of: ", stringify!(rte_eth_fdir_flex_conf)) + ::std::mem::size_of::(), + 688usize, + concat!("Size of: ", stringify!(rte_eth_fdir_flex_conf)), ); assert_eq!( - ::std::mem::align_of:: < rte_eth_fdir_flex_conf > (), 4usize, - concat!("Alignment of ", stringify!(rte_eth_fdir_flex_conf)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_eth_fdir_flex_conf)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).nb_payloads) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_flex_conf), "::", - stringify!(nb_payloads)) + unsafe { ::std::ptr::addr_of!((*ptr).nb_payloads) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_flex_conf), + "::", + stringify!(nb_payloads), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).nb_flexmasks) as usize - ptr as usize }, - 2usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_flex_conf), "::", - stringify!(nb_flexmasks)) + unsafe { ::std::ptr::addr_of!((*ptr).nb_flexmasks) as usize - ptr as usize }, + 2usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_flex_conf), + "::", + stringify!(nb_flexmasks), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).flex_set) as usize - ptr as usize }, - 4usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_flex_conf), "::", - stringify!(flex_set)) + unsafe { ::std::ptr::addr_of!((*ptr).flex_set) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_flex_conf), + "::", + stringify!(flex_set), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).flex_mask) as usize - ptr as usize }, - 292usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_flex_conf), "::", - stringify!(flex_mask)) + unsafe { ::std::ptr::addr_of!((*ptr).flex_mask) as usize - ptr as usize }, + 292usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_flex_conf), + "::", + stringify!(flex_mask), + ), ); } impl Default for rte_eth_fdir_flex_conf { @@ -1363,39 +1685,59 @@ 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:: < rte_fdir_conf > (), 772usize, concat!("Size of: ", - stringify!(rte_fdir_conf)) + ::std::mem::size_of::(), + 772usize, + concat!("Size of: ", stringify!(rte_fdir_conf)), ); assert_eq!( - ::std::mem::align_of:: < rte_fdir_conf > (), 4usize, concat!("Alignment of ", - stringify!(rte_fdir_conf)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_fdir_conf)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mode) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_fdir_conf), "::", stringify!(mode)) + unsafe { ::std::ptr::addr_of!((*ptr).mode) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(rte_fdir_conf), "::", stringify!(mode)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).pballoc) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(rte_fdir_conf), "::", - stringify!(pballoc)) + unsafe { ::std::ptr::addr_of!((*ptr).pballoc) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_fdir_conf), + "::", + stringify!(pballoc), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).status) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(rte_fdir_conf), "::", stringify!(status)) + unsafe { ::std::ptr::addr_of!((*ptr).status) as usize - ptr as usize }, + 8usize, + concat!("Offset of field: ", stringify!(rte_fdir_conf), "::", stringify!(status)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).drop_queue) as usize - ptr as usize }, - 12usize, concat!("Offset of field: ", stringify!(rte_fdir_conf), "::", - stringify!(drop_queue)) + unsafe { ::std::ptr::addr_of!((*ptr).drop_queue) as usize - ptr as usize }, + 12usize, + concat!( + "Offset of field: ", + stringify!(rte_fdir_conf), + "::", + stringify!(drop_queue), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mask) as usize - ptr as usize }, 16usize, - concat!("Offset of field: ", stringify!(rte_fdir_conf), "::", stringify!(mask)) + unsafe { ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize }, + 16usize, + concat!("Offset of field: ", stringify!(rte_fdir_conf), "::", stringify!(mask)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).flex_conf) as usize - ptr as usize }, - 84usize, concat!("Offset of field: ", stringify!(rte_fdir_conf), "::", - stringify!(flex_conf)) + unsafe { ::std::ptr::addr_of!((*ptr).flex_conf) as usize - ptr as usize }, + 84usize, + concat!( + "Offset of field: ", + stringify!(rte_fdir_conf), + "::", + stringify!(flex_conf), + ), ); } impl Default for rte_fdir_conf { @@ -1421,20 +1763,24 @@ 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:: < rte_intr_conf > (), 4usize, concat!("Size of: ", - stringify!(rte_intr_conf)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(rte_intr_conf)), ); assert_eq!( - ::std::mem::align_of:: < rte_intr_conf > (), 2usize, concat!("Alignment of ", - stringify!(rte_intr_conf)) + ::std::mem::align_of::(), + 2usize, + concat!("Alignment of ", stringify!(rte_intr_conf)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).lsc) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_intr_conf), "::", stringify!(lsc)) + unsafe { ::std::ptr::addr_of!((*ptr).lsc) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(rte_intr_conf), "::", stringify!(lsc)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).rxq) as usize - ptr as usize }, 2usize, - concat!("Offset of field: ", stringify!(rte_intr_conf), "::", stringify!(rxq)) + unsafe { ::std::ptr::addr_of!((*ptr).rxq) as usize - ptr as usize }, + 2usize, + concat!("Offset of field: ", stringify!(rte_intr_conf), "::", stringify!(rxq)), ); } /** A structure used to configure an Ethernet port. @@ -1487,32 +1833,54 @@ 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:: < rte_eth_conf__bindgen_ty_1 > (), 2120usize, - concat!("Size of: ", stringify!(rte_eth_conf__bindgen_ty_1)) + ::std::mem::size_of::(), + 2120usize, + concat!("Size of: ", stringify!(rte_eth_conf__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < rte_eth_conf__bindgen_ty_1 > (), 8usize, - concat!("Alignment of ", stringify!(rte_eth_conf__bindgen_ty_1)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(rte_eth_conf__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).rss_conf) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_eth_conf__bindgen_ty_1), - "::", stringify!(rss_conf)) + unsafe { ::std::ptr::addr_of!((*ptr).rss_conf) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf__bindgen_ty_1), + "::", + stringify!(rss_conf), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).vmdq_dcb_conf) as usize - ptr as usize }, - 24usize, concat!("Offset of field: ", stringify!(rte_eth_conf__bindgen_ty_1), - "::", stringify!(vmdq_dcb_conf)) + unsafe { ::std::ptr::addr_of!((*ptr).vmdq_dcb_conf) as usize - ptr as usize }, + 24usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf__bindgen_ty_1), + "::", + stringify!(vmdq_dcb_conf), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).dcb_rx_conf) as usize - ptr as usize }, - 1064usize, concat!("Offset of field: ", stringify!(rte_eth_conf__bindgen_ty_1), - "::", stringify!(dcb_rx_conf)) + unsafe { ::std::ptr::addr_of!((*ptr).dcb_rx_conf) as usize - ptr as usize }, + 1064usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf__bindgen_ty_1), + "::", + stringify!(dcb_rx_conf), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).vmdq_rx_conf) as usize - ptr as usize }, - 1080usize, concat!("Offset of field: ", stringify!(rte_eth_conf__bindgen_ty_1), - "::", stringify!(vmdq_rx_conf)) + unsafe { ::std::ptr::addr_of!((*ptr).vmdq_rx_conf) as usize - ptr as usize }, + 1080usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf__bindgen_ty_1), + "::", + stringify!(vmdq_rx_conf), + ), ); } impl Default for rte_eth_conf__bindgen_ty_1 { @@ -1536,27 +1904,44 @@ 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:: < rte_eth_conf__bindgen_ty_2 > (), 12usize, - concat!("Size of: ", stringify!(rte_eth_conf__bindgen_ty_2)) + ::std::mem::size_of::(), + 12usize, + concat!("Size of: ", stringify!(rte_eth_conf__bindgen_ty_2)), ); assert_eq!( - ::std::mem::align_of:: < rte_eth_conf__bindgen_ty_2 > (), 4usize, - concat!("Alignment of ", stringify!(rte_eth_conf__bindgen_ty_2)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_eth_conf__bindgen_ty_2)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).vmdq_dcb_tx_conf) as usize - ptr as usize - }, 0usize, concat!("Offset of field: ", stringify!(rte_eth_conf__bindgen_ty_2), - "::", stringify!(vmdq_dcb_tx_conf)) + unsafe { ::std::ptr::addr_of!((*ptr).vmdq_dcb_tx_conf) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf__bindgen_ty_2), + "::", + stringify!(vmdq_dcb_tx_conf), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).dcb_tx_conf) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_eth_conf__bindgen_ty_2), - "::", stringify!(dcb_tx_conf)) + unsafe { ::std::ptr::addr_of!((*ptr).dcb_tx_conf) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf__bindgen_ty_2), + "::", + stringify!(dcb_tx_conf), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).vmdq_tx_conf) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_eth_conf__bindgen_ty_2), - "::", stringify!(vmdq_tx_conf)) + unsafe { ::std::ptr::addr_of!((*ptr).vmdq_tx_conf) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf__bindgen_ty_2), + "::", + stringify!(vmdq_tx_conf), + ), ); } impl Default for rte_eth_conf__bindgen_ty_2 { @@ -1573,55 +1958,96 @@ 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:: < rte_eth_conf > (), 2944usize, concat!("Size of: ", - stringify!(rte_eth_conf)) - ); - assert_eq!( - ::std::mem::align_of:: < rte_eth_conf > (), 8usize, concat!("Alignment of ", - stringify!(rte_eth_conf)) + ::std::mem::size_of::(), + 2944usize, + concat!("Size of: ", stringify!(rte_eth_conf)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).link_speeds) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_eth_conf), "::", - stringify!(link_speeds)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(rte_eth_conf)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).rxmode) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(rte_eth_conf), "::", stringify!(rxmode)) + unsafe { ::std::ptr::addr_of!((*ptr).link_speeds) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(link_speeds), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).txmode) as usize - ptr as usize }, 16usize, - concat!("Offset of field: ", stringify!(rte_eth_conf), "::", stringify!(txmode)) + unsafe { ::std::ptr::addr_of!((*ptr).rxmode) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(rte_eth_conf), "::", stringify!(rxmode)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).lpbk_mode) as usize - ptr as usize }, - 24usize, concat!("Offset of field: ", stringify!(rte_eth_conf), "::", - stringify!(lpbk_mode)) + unsafe { ::std::ptr::addr_of!((*ptr).txmode) as usize - ptr as usize }, + 16usize, + concat!("Offset of field: ", stringify!(rte_eth_conf), "::", stringify!(txmode)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).rx_adv_conf) as usize - ptr as usize }, - 32usize, concat!("Offset of field: ", stringify!(rte_eth_conf), "::", - stringify!(rx_adv_conf)) + unsafe { ::std::ptr::addr_of!((*ptr).lpbk_mode) as usize - ptr as usize }, + 24usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(lpbk_mode), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).tx_adv_conf) as usize - ptr as usize }, - 2152usize, concat!("Offset of field: ", stringify!(rte_eth_conf), "::", - stringify!(tx_adv_conf)) + unsafe { ::std::ptr::addr_of!((*ptr).rx_adv_conf) as usize - ptr as usize }, + 32usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(rx_adv_conf), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).dcb_capability_en) as usize - ptr as usize - }, 2164usize, concat!("Offset of field: ", stringify!(rte_eth_conf), "::", - stringify!(dcb_capability_en)) + unsafe { ::std::ptr::addr_of!((*ptr).tx_adv_conf) as usize - ptr as usize }, + 2152usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(tx_adv_conf), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).fdir_conf) as usize - ptr as usize }, - 2168usize, concat!("Offset of field: ", stringify!(rte_eth_conf), "::", - stringify!(fdir_conf)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).intr_conf) as usize - ptr as usize }, - 2940usize, concat!("Offset of field: ", stringify!(rte_eth_conf), "::", - stringify!(intr_conf)) + unsafe { + ::std::ptr::addr_of!((*ptr).dcb_capability_en) as usize - ptr as usize + }, + 2164usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(dcb_capability_en), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).fdir_conf) as usize - ptr as usize }, + 2168usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(fdir_conf), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).intr_conf) as usize - ptr as usize }, + 2940usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(intr_conf), + ), ); } impl Default for rte_eth_conf { diff --git a/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs b/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs index 086384c450..b9ad64374b 100644 --- a/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs @@ -49,7 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -69,7 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -198,27 +198,44 @@ 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:: < rte_eth_rxmode > (), 12usize, concat!("Size of: ", - stringify!(rte_eth_rxmode)) + ::std::mem::size_of::(), + 12usize, + concat!("Size of: ", stringify!(rte_eth_rxmode)), ); assert_eq!( - ::std::mem::align_of:: < rte_eth_rxmode > (), 4usize, concat!("Alignment of ", - stringify!(rte_eth_rxmode)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_eth_rxmode)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mq_mode) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_eth_rxmode), "::", - stringify!(mq_mode)) + unsafe { ::std::ptr::addr_of!((*ptr).mq_mode) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_rxmode), + "::", + stringify!(mq_mode), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).max_rx_pkt_len) as usize - ptr as usize }, - 4usize, concat!("Offset of field: ", stringify!(rte_eth_rxmode), "::", - stringify!(max_rx_pkt_len)) + unsafe { ::std::ptr::addr_of!((*ptr).max_rx_pkt_len) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_rxmode), + "::", + stringify!(max_rx_pkt_len), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).split_hdr_size) as usize - ptr as usize }, - 8usize, concat!("Offset of field: ", stringify!(rte_eth_rxmode), "::", - stringify!(split_hdr_size)) + unsafe { ::std::ptr::addr_of!((*ptr).split_hdr_size) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_rxmode), + "::", + stringify!(split_hdr_size), + ), ); } impl Clone for rte_eth_rxmode { @@ -476,21 +493,29 @@ 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:: < rte_eth_txmode > (), 8usize, concat!("Size of: ", - stringify!(rte_eth_txmode)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(rte_eth_txmode)), ); assert_eq!( - ::std::mem::align_of:: < rte_eth_txmode > (), 4usize, concat!("Alignment of ", - stringify!(rte_eth_txmode)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_eth_txmode)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mq_mode) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_eth_txmode), "::", - stringify!(mq_mode)) + unsafe { ::std::ptr::addr_of!((*ptr).mq_mode) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_txmode), + "::", + stringify!(mq_mode), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).pvid) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(rte_eth_txmode), "::", stringify!(pvid)) + unsafe { ::std::ptr::addr_of!((*ptr).pvid) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(rte_eth_txmode), "::", stringify!(pvid)), ); } impl Clone for rte_eth_txmode { @@ -614,27 +639,44 @@ 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:: < rte_eth_rss_conf > (), 24usize, concat!("Size of: ", - stringify!(rte_eth_rss_conf)) + ::std::mem::size_of::(), + 24usize, + concat!("Size of: ", stringify!(rte_eth_rss_conf)), ); assert_eq!( - ::std::mem::align_of:: < rte_eth_rss_conf > (), 8usize, concat!("Alignment of ", - stringify!(rte_eth_rss_conf)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(rte_eth_rss_conf)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).rss_key) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_eth_rss_conf), "::", - stringify!(rss_key)) + unsafe { ::std::ptr::addr_of!((*ptr).rss_key) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_rss_conf), + "::", + stringify!(rss_key), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).rss_key_len) as usize - ptr as usize }, - 8usize, concat!("Offset of field: ", stringify!(rte_eth_rss_conf), "::", - stringify!(rss_key_len)) + unsafe { ::std::ptr::addr_of!((*ptr).rss_key_len) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_rss_conf), + "::", + stringify!(rss_key_len), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).rss_hf) as usize - ptr as usize }, 16usize, - concat!("Offset of field: ", stringify!(rte_eth_rss_conf), "::", - stringify!(rss_hf)) + unsafe { ::std::ptr::addr_of!((*ptr).rss_hf) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_rss_conf), + "::", + stringify!(rss_hf), + ), ); } impl Clone for rte_eth_rss_conf { @@ -712,22 +754,34 @@ 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:: < rte_eth_vmdq_dcb_conf__bindgen_ty_1 > (), 16usize, - concat!("Size of: ", stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < rte_eth_vmdq_dcb_conf__bindgen_ty_1 > (), 8usize, - concat!("Alignment of ", stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).vlan_id) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1), - "::", stringify!(vlan_id)) + unsafe { ::std::ptr::addr_of!((*ptr).vlan_id) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1), + "::", + stringify!(vlan_id), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).pools) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1), - "::", stringify!(pools)) + unsafe { ::std::ptr::addr_of!((*ptr).pools) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1), + "::", + stringify!(pools), + ), ); } impl Clone for rte_eth_vmdq_dcb_conf__bindgen_ty_1 { @@ -740,42 +794,76 @@ 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:: < rte_eth_vmdq_dcb_conf > (), 1040usize, - concat!("Size of: ", stringify!(rte_eth_vmdq_dcb_conf)) + ::std::mem::size_of::(), + 1040usize, + concat!("Size of: ", stringify!(rte_eth_vmdq_dcb_conf)), ); assert_eq!( - ::std::mem::align_of:: < rte_eth_vmdq_dcb_conf > (), 8usize, - concat!("Alignment of ", stringify!(rte_eth_vmdq_dcb_conf)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(rte_eth_vmdq_dcb_conf)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).nb_queue_pools) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_dcb_conf), "::", - stringify!(nb_queue_pools)) + unsafe { ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf), + "::", + stringify!(nb_queue_pools), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).enable_default_pool) as usize - ptr as - usize }, 4usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_dcb_conf), - "::", stringify!(enable_default_pool)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).default_pool) as usize - ptr as usize }, - 5usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_dcb_conf), "::", - stringify!(default_pool)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).nb_pool_maps) as usize - ptr as usize }, - 6usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_dcb_conf), "::", - stringify!(nb_pool_maps)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).pool_map) as usize - ptr as usize }, - 8usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_dcb_conf), "::", - stringify!(pool_map)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).dcb_tc) as usize - ptr as usize }, - 1032usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_dcb_conf), "::", - stringify!(dcb_tc)) + unsafe { + ::std::ptr::addr_of!((*ptr).enable_default_pool) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf), + "::", + stringify!(enable_default_pool), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).default_pool) as usize - ptr as usize }, + 5usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf), + "::", + stringify!(default_pool), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).nb_pool_maps) as usize - ptr as usize }, + 6usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf), + "::", + stringify!(nb_pool_maps), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).pool_map) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf), + "::", + stringify!(pool_map), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize }, + 1032usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_conf), + "::", + stringify!(dcb_tc), + ), ); } impl Clone for rte_eth_vmdq_dcb_conf { @@ -805,22 +893,34 @@ 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:: < rte_eth_dcb_rx_conf > (), 12usize, concat!("Size of: ", - stringify!(rte_eth_dcb_rx_conf)) + ::std::mem::size_of::(), + 12usize, + concat!("Size of: ", stringify!(rte_eth_dcb_rx_conf)), ); assert_eq!( - ::std::mem::align_of:: < rte_eth_dcb_rx_conf > (), 4usize, - concat!("Alignment of ", stringify!(rte_eth_dcb_rx_conf)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_eth_dcb_rx_conf)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).nb_tcs) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_eth_dcb_rx_conf), "::", - stringify!(nb_tcs)) + unsafe { ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_dcb_rx_conf), + "::", + stringify!(nb_tcs), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).dcb_tc) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(rte_eth_dcb_rx_conf), "::", - stringify!(dcb_tc)) + unsafe { ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_dcb_rx_conf), + "::", + stringify!(dcb_tc), + ), ); } impl Clone for rte_eth_dcb_rx_conf { @@ -850,22 +950,34 @@ 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:: < rte_eth_vmdq_dcb_tx_conf > (), 12usize, - concat!("Size of: ", stringify!(rte_eth_vmdq_dcb_tx_conf)) + ::std::mem::size_of::(), + 12usize, + concat!("Size of: ", stringify!(rte_eth_vmdq_dcb_tx_conf)), ); assert_eq!( - ::std::mem::align_of:: < rte_eth_vmdq_dcb_tx_conf > (), 4usize, - concat!("Alignment of ", stringify!(rte_eth_vmdq_dcb_tx_conf)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_eth_vmdq_dcb_tx_conf)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).nb_queue_pools) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_dcb_tx_conf), "::", - stringify!(nb_queue_pools)) + unsafe { ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_tx_conf), + "::", + stringify!(nb_queue_pools), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).dcb_tc) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(rte_eth_vmdq_dcb_tx_conf), "::", - stringify!(dcb_tc)) + unsafe { ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_dcb_tx_conf), + "::", + stringify!(dcb_tc), + ), ); } impl Clone for rte_eth_vmdq_dcb_tx_conf { @@ -895,22 +1007,34 @@ 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:: < rte_eth_dcb_tx_conf > (), 12usize, concat!("Size of: ", - stringify!(rte_eth_dcb_tx_conf)) + ::std::mem::size_of::(), + 12usize, + concat!("Size of: ", stringify!(rte_eth_dcb_tx_conf)), ); assert_eq!( - ::std::mem::align_of:: < rte_eth_dcb_tx_conf > (), 4usize, - concat!("Alignment of ", stringify!(rte_eth_dcb_tx_conf)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_eth_dcb_tx_conf)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).nb_tcs) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_eth_dcb_tx_conf), "::", - stringify!(nb_tcs)) + unsafe { ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_dcb_tx_conf), + "::", + stringify!(nb_tcs), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).dcb_tc) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(rte_eth_dcb_tx_conf), "::", - stringify!(dcb_tc)) + unsafe { ::std::ptr::addr_of!((*ptr).dcb_tc) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_dcb_tx_conf), + "::", + stringify!(dcb_tc), + ), ); } impl Clone for rte_eth_dcb_tx_conf { @@ -938,17 +1062,24 @@ 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:: < rte_eth_vmdq_tx_conf > (), 4usize, concat!("Size of: ", - stringify!(rte_eth_vmdq_tx_conf)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(rte_eth_vmdq_tx_conf)), ); assert_eq!( - ::std::mem::align_of:: < rte_eth_vmdq_tx_conf > (), 4usize, - concat!("Alignment of ", stringify!(rte_eth_vmdq_tx_conf)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_eth_vmdq_tx_conf)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).nb_queue_pools) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_tx_conf), "::", - stringify!(nb_queue_pools)) + unsafe { ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_tx_conf), + "::", + stringify!(nb_queue_pools), + ), ); } impl Clone for rte_eth_vmdq_tx_conf { @@ -996,22 +1127,34 @@ 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:: < rte_eth_vmdq_rx_conf__bindgen_ty_1 > (), 16usize, - concat!("Size of: ", stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < rte_eth_vmdq_rx_conf__bindgen_ty_1 > (), 8usize, - concat!("Alignment of ", stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).vlan_id) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1), - "::", stringify!(vlan_id)) + unsafe { ::std::ptr::addr_of!((*ptr).vlan_id) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1), + "::", + stringify!(vlan_id), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).pools) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1), - "::", stringify!(pools)) + unsafe { ::std::ptr::addr_of!((*ptr).pools) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1), + "::", + stringify!(pools), + ), ); } impl Clone for rte_eth_vmdq_rx_conf__bindgen_ty_1 { @@ -1024,47 +1167,86 @@ 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:: < rte_eth_vmdq_rx_conf > (), 1040usize, - concat!("Size of: ", stringify!(rte_eth_vmdq_rx_conf)) - ); - assert_eq!( - ::std::mem::align_of:: < rte_eth_vmdq_rx_conf > (), 8usize, - concat!("Alignment of ", stringify!(rte_eth_vmdq_rx_conf)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).nb_queue_pools) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_rx_conf), "::", - stringify!(nb_queue_pools)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).enable_default_pool) as usize - ptr as - usize }, 4usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_rx_conf), - "::", stringify!(enable_default_pool)) + ::std::mem::size_of::(), + 1040usize, + concat!("Size of: ", stringify!(rte_eth_vmdq_rx_conf)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).default_pool) as usize - ptr as usize }, - 5usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_rx_conf), "::", - stringify!(default_pool)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(rte_eth_vmdq_rx_conf)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).enable_loop_back) as usize - ptr as usize - }, 6usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_rx_conf), "::", - stringify!(enable_loop_back)) + unsafe { ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf), + "::", + stringify!(nb_queue_pools), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).nb_pool_maps) as usize - ptr as usize }, - 7usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_rx_conf), "::", - stringify!(nb_pool_maps)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).rx_mode) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(rte_eth_vmdq_rx_conf), "::", - stringify!(rx_mode)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).pool_map) as usize - ptr as usize }, - 16usize, concat!("Offset of field: ", stringify!(rte_eth_vmdq_rx_conf), "::", - stringify!(pool_map)) + unsafe { + ::std::ptr::addr_of!((*ptr).enable_default_pool) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf), + "::", + stringify!(enable_default_pool), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).default_pool) as usize - ptr as usize }, + 5usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf), + "::", + stringify!(default_pool), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).enable_loop_back) as usize - ptr as usize }, + 6usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf), + "::", + stringify!(enable_loop_back), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).nb_pool_maps) as usize - ptr as usize }, + 7usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf), + "::", + stringify!(nb_pool_maps), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).rx_mode) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf), + "::", + stringify!(rx_mode), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).pool_map) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_vmdq_rx_conf), + "::", + stringify!(pool_map), + ), ); } impl Clone for rte_eth_vmdq_rx_conf { @@ -1139,37 +1321,64 @@ 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:: < rte_eth_ipv4_flow > (), 12usize, concat!("Size of: ", - stringify!(rte_eth_ipv4_flow)) + ::std::mem::size_of::(), + 12usize, + concat!("Size of: ", stringify!(rte_eth_ipv4_flow)), ); assert_eq!( - ::std::mem::align_of:: < rte_eth_ipv4_flow > (), 4usize, concat!("Alignment of ", - stringify!(rte_eth_ipv4_flow)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_eth_ipv4_flow)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).src_ip) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_eth_ipv4_flow), "::", - stringify!(src_ip)) + unsafe { ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv4_flow), + "::", + stringify!(src_ip), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).dst_ip) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(rte_eth_ipv4_flow), "::", - stringify!(dst_ip)) + unsafe { ::std::ptr::addr_of!((*ptr).dst_ip) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv4_flow), + "::", + stringify!(dst_ip), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).tos) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(rte_eth_ipv4_flow), "::", - stringify!(tos)) + unsafe { ::std::ptr::addr_of!((*ptr).tos) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv4_flow), + "::", + stringify!(tos), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).ttl) as usize - ptr as usize }, 9usize, - concat!("Offset of field: ", stringify!(rte_eth_ipv4_flow), "::", - stringify!(ttl)) + unsafe { ::std::ptr::addr_of!((*ptr).ttl) as usize - ptr as usize }, + 9usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv4_flow), + "::", + stringify!(ttl), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).proto) as usize - ptr as usize }, 10usize, - concat!("Offset of field: ", stringify!(rte_eth_ipv4_flow), "::", - stringify!(proto)) + unsafe { ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize }, + 10usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv4_flow), + "::", + stringify!(proto), + ), ); } impl Clone for rte_eth_ipv4_flow { @@ -1197,36 +1406,59 @@ 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:: < rte_eth_ipv6_flow > (), 36usize, concat!("Size of: ", - stringify!(rte_eth_ipv6_flow)) + ::std::mem::size_of::(), + 36usize, + concat!("Size of: ", stringify!(rte_eth_ipv6_flow)), ); assert_eq!( - ::std::mem::align_of:: < rte_eth_ipv6_flow > (), 4usize, concat!("Alignment of ", - stringify!(rte_eth_ipv6_flow)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_eth_ipv6_flow)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).src_ip) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_eth_ipv6_flow), "::", - stringify!(src_ip)) + unsafe { ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv6_flow), + "::", + stringify!(src_ip), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).dst_ip) as usize - ptr as usize }, 16usize, - concat!("Offset of field: ", stringify!(rte_eth_ipv6_flow), "::", - stringify!(dst_ip)) + unsafe { ::std::ptr::addr_of!((*ptr).dst_ip) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv6_flow), + "::", + stringify!(dst_ip), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).tc) as usize - ptr as usize }, 32usize, - concat!("Offset of field: ", stringify!(rte_eth_ipv6_flow), "::", stringify!(tc)) + unsafe { ::std::ptr::addr_of!((*ptr).tc) as usize - ptr as usize }, + 32usize, + concat!("Offset of field: ", stringify!(rte_eth_ipv6_flow), "::", stringify!(tc)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).proto) as usize - ptr as usize }, 33usize, - concat!("Offset of field: ", stringify!(rte_eth_ipv6_flow), "::", - stringify!(proto)) + unsafe { ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize }, + 33usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv6_flow), + "::", + stringify!(proto), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).hop_limits) as usize - ptr as usize }, - 34usize, concat!("Offset of field: ", stringify!(rte_eth_ipv6_flow), "::", - stringify!(hop_limits)) + unsafe { ::std::ptr::addr_of!((*ptr).hop_limits) as usize - ptr as usize }, + 34usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_ipv6_flow), + "::", + stringify!(hop_limits), + ), ); } impl Clone for rte_eth_ipv6_flow { @@ -1263,52 +1495,96 @@ 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:: < rte_eth_fdir_masks > (), 68usize, concat!("Size of: ", - stringify!(rte_eth_fdir_masks)) - ); - assert_eq!( - ::std::mem::align_of:: < rte_eth_fdir_masks > (), 4usize, - concat!("Alignment of ", stringify!(rte_eth_fdir_masks)) + ::std::mem::size_of::(), + 68usize, + concat!("Size of: ", stringify!(rte_eth_fdir_masks)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).vlan_tci_mask) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_masks), "::", - stringify!(vlan_tci_mask)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_eth_fdir_masks)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).ipv4_mask) as usize - ptr as usize }, - 4usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_masks), "::", - stringify!(ipv4_mask)) + unsafe { ::std::ptr::addr_of!((*ptr).vlan_tci_mask) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(vlan_tci_mask), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).ipv6_mask) as usize - ptr as usize }, - 16usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_masks), "::", - stringify!(ipv6_mask)) + unsafe { ::std::ptr::addr_of!((*ptr).ipv4_mask) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(ipv4_mask), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).src_port_mask) as usize - ptr as usize }, - 52usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_masks), "::", - stringify!(src_port_mask)) + unsafe { ::std::ptr::addr_of!((*ptr).ipv6_mask) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(ipv6_mask), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).dst_port_mask) as usize - ptr as usize }, - 54usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_masks), "::", - stringify!(dst_port_mask)) + unsafe { ::std::ptr::addr_of!((*ptr).src_port_mask) as usize - ptr as usize }, + 52usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(src_port_mask), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mac_addr_byte_mask) as usize - ptr as usize - }, 56usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_masks), "::", - stringify!(mac_addr_byte_mask)) + unsafe { ::std::ptr::addr_of!((*ptr).dst_port_mask) as usize - ptr as usize }, + 54usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(dst_port_mask), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).tunnel_id_mask) as usize - ptr as usize }, - 60usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_masks), "::", - stringify!(tunnel_id_mask)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).tunnel_type_mask) as usize - ptr as usize - }, 64usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_masks), "::", - stringify!(tunnel_type_mask)) + unsafe { + ::std::ptr::addr_of!((*ptr).mac_addr_byte_mask) as usize - ptr as usize + }, + 56usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(mac_addr_byte_mask), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).tunnel_id_mask) as usize - ptr as usize }, + 60usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(tunnel_id_mask), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).tunnel_type_mask) as usize - ptr as usize }, + 64usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_masks), + "::", + stringify!(tunnel_type_mask), + ), ); } impl Clone for rte_eth_fdir_masks { @@ -1341,22 +1617,34 @@ 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:: < rte_eth_flex_payload_cfg > (), 36usize, - concat!("Size of: ", stringify!(rte_eth_flex_payload_cfg)) + ::std::mem::size_of::(), + 36usize, + concat!("Size of: ", stringify!(rte_eth_flex_payload_cfg)), ); assert_eq!( - ::std::mem::align_of:: < rte_eth_flex_payload_cfg > (), 4usize, - concat!("Alignment of ", stringify!(rte_eth_flex_payload_cfg)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_eth_flex_payload_cfg)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).type_) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_eth_flex_payload_cfg), "::", - stringify!(type_)) + unsafe { ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_flex_payload_cfg), + "::", + stringify!(type_), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).src_offset) as usize - ptr as usize }, - 4usize, concat!("Offset of field: ", stringify!(rte_eth_flex_payload_cfg), "::", - stringify!(src_offset)) + unsafe { ::std::ptr::addr_of!((*ptr).src_offset) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_flex_payload_cfg), + "::", + stringify!(src_offset), + ), ); } impl Clone for rte_eth_flex_payload_cfg { @@ -1386,22 +1674,34 @@ 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:: < rte_eth_fdir_flex_mask > (), 18usize, - concat!("Size of: ", stringify!(rte_eth_fdir_flex_mask)) + ::std::mem::size_of::(), + 18usize, + concat!("Size of: ", stringify!(rte_eth_fdir_flex_mask)), ); assert_eq!( - ::std::mem::align_of:: < rte_eth_fdir_flex_mask > (), 2usize, - concat!("Alignment of ", stringify!(rte_eth_fdir_flex_mask)) + ::std::mem::align_of::(), + 2usize, + concat!("Alignment of ", stringify!(rte_eth_fdir_flex_mask)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).flow_type) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_flex_mask), "::", - stringify!(flow_type)) + unsafe { ::std::ptr::addr_of!((*ptr).flow_type) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_flex_mask), + "::", + stringify!(flow_type), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mask) as usize - ptr as usize }, 2usize, - concat!("Offset of field: ", stringify!(rte_eth_fdir_flex_mask), "::", - stringify!(mask)) + unsafe { ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize }, + 2usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_flex_mask), + "::", + stringify!(mask), + ), ); } impl Clone for rte_eth_fdir_flex_mask { @@ -1426,32 +1726,54 @@ 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:: < rte_eth_fdir_flex_conf > (), 688usize, - concat!("Size of: ", stringify!(rte_eth_fdir_flex_conf)) + ::std::mem::size_of::(), + 688usize, + concat!("Size of: ", stringify!(rte_eth_fdir_flex_conf)), ); assert_eq!( - ::std::mem::align_of:: < rte_eth_fdir_flex_conf > (), 4usize, - concat!("Alignment of ", stringify!(rte_eth_fdir_flex_conf)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_eth_fdir_flex_conf)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).nb_payloads) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_flex_conf), "::", - stringify!(nb_payloads)) + unsafe { ::std::ptr::addr_of!((*ptr).nb_payloads) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_flex_conf), + "::", + stringify!(nb_payloads), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).nb_flexmasks) as usize - ptr as usize }, - 2usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_flex_conf), "::", - stringify!(nb_flexmasks)) + unsafe { ::std::ptr::addr_of!((*ptr).nb_flexmasks) as usize - ptr as usize }, + 2usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_flex_conf), + "::", + stringify!(nb_flexmasks), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).flex_set) as usize - ptr as usize }, - 4usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_flex_conf), "::", - stringify!(flex_set)) + unsafe { ::std::ptr::addr_of!((*ptr).flex_set) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_flex_conf), + "::", + stringify!(flex_set), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).flex_mask) as usize - ptr as usize }, - 292usize, concat!("Offset of field: ", stringify!(rte_eth_fdir_flex_conf), "::", - stringify!(flex_mask)) + unsafe { ::std::ptr::addr_of!((*ptr).flex_mask) as usize - ptr as usize }, + 292usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_fdir_flex_conf), + "::", + stringify!(flex_mask), + ), ); } impl Clone for rte_eth_fdir_flex_conf { @@ -1491,39 +1813,59 @@ 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:: < rte_fdir_conf > (), 772usize, concat!("Size of: ", - stringify!(rte_fdir_conf)) + ::std::mem::size_of::(), + 772usize, + concat!("Size of: ", stringify!(rte_fdir_conf)), ); assert_eq!( - ::std::mem::align_of:: < rte_fdir_conf > (), 4usize, concat!("Alignment of ", - stringify!(rte_fdir_conf)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_fdir_conf)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mode) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_fdir_conf), "::", stringify!(mode)) + unsafe { ::std::ptr::addr_of!((*ptr).mode) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(rte_fdir_conf), "::", stringify!(mode)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).pballoc) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(rte_fdir_conf), "::", - stringify!(pballoc)) + unsafe { ::std::ptr::addr_of!((*ptr).pballoc) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_fdir_conf), + "::", + stringify!(pballoc), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).status) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(rte_fdir_conf), "::", stringify!(status)) + unsafe { ::std::ptr::addr_of!((*ptr).status) as usize - ptr as usize }, + 8usize, + concat!("Offset of field: ", stringify!(rte_fdir_conf), "::", stringify!(status)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).drop_queue) as usize - ptr as usize }, - 12usize, concat!("Offset of field: ", stringify!(rte_fdir_conf), "::", - stringify!(drop_queue)) + unsafe { ::std::ptr::addr_of!((*ptr).drop_queue) as usize - ptr as usize }, + 12usize, + concat!( + "Offset of field: ", + stringify!(rte_fdir_conf), + "::", + stringify!(drop_queue), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mask) as usize - ptr as usize }, 16usize, - concat!("Offset of field: ", stringify!(rte_fdir_conf), "::", stringify!(mask)) + unsafe { ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize }, + 16usize, + concat!("Offset of field: ", stringify!(rte_fdir_conf), "::", stringify!(mask)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).flex_conf) as usize - ptr as usize }, - 84usize, concat!("Offset of field: ", stringify!(rte_fdir_conf), "::", - stringify!(flex_conf)) + unsafe { ::std::ptr::addr_of!((*ptr).flex_conf) as usize - ptr as usize }, + 84usize, + concat!( + "Offset of field: ", + stringify!(rte_fdir_conf), + "::", + stringify!(flex_conf), + ), ); } impl Clone for rte_fdir_conf { @@ -1554,20 +1896,24 @@ 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:: < rte_intr_conf > (), 4usize, concat!("Size of: ", - stringify!(rte_intr_conf)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(rte_intr_conf)), ); assert_eq!( - ::std::mem::align_of:: < rte_intr_conf > (), 2usize, concat!("Alignment of ", - stringify!(rte_intr_conf)) + ::std::mem::align_of::(), + 2usize, + concat!("Alignment of ", stringify!(rte_intr_conf)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).lsc) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_intr_conf), "::", stringify!(lsc)) + unsafe { ::std::ptr::addr_of!((*ptr).lsc) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(rte_intr_conf), "::", stringify!(lsc)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).rxq) as usize - ptr as usize }, 2usize, - concat!("Offset of field: ", stringify!(rte_intr_conf), "::", stringify!(rxq)) + unsafe { ::std::ptr::addr_of!((*ptr).rxq) as usize - ptr as usize }, + 2usize, + concat!("Offset of field: ", stringify!(rte_intr_conf), "::", stringify!(rxq)), ); } impl Clone for rte_intr_conf { @@ -1625,32 +1971,54 @@ 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:: < rte_eth_conf__bindgen_ty_1 > (), 2120usize, - concat!("Size of: ", stringify!(rte_eth_conf__bindgen_ty_1)) + ::std::mem::size_of::(), + 2120usize, + concat!("Size of: ", stringify!(rte_eth_conf__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < rte_eth_conf__bindgen_ty_1 > (), 8usize, - concat!("Alignment of ", stringify!(rte_eth_conf__bindgen_ty_1)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(rte_eth_conf__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).rss_conf) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_eth_conf__bindgen_ty_1), - "::", stringify!(rss_conf)) + unsafe { ::std::ptr::addr_of!((*ptr).rss_conf) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf__bindgen_ty_1), + "::", + stringify!(rss_conf), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).vmdq_dcb_conf) as usize - ptr as usize }, - 24usize, concat!("Offset of field: ", stringify!(rte_eth_conf__bindgen_ty_1), - "::", stringify!(vmdq_dcb_conf)) + unsafe { ::std::ptr::addr_of!((*ptr).vmdq_dcb_conf) as usize - ptr as usize }, + 24usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf__bindgen_ty_1), + "::", + stringify!(vmdq_dcb_conf), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).dcb_rx_conf) as usize - ptr as usize }, - 1064usize, concat!("Offset of field: ", stringify!(rte_eth_conf__bindgen_ty_1), - "::", stringify!(dcb_rx_conf)) + unsafe { ::std::ptr::addr_of!((*ptr).dcb_rx_conf) as usize - ptr as usize }, + 1064usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf__bindgen_ty_1), + "::", + stringify!(dcb_rx_conf), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).vmdq_rx_conf) as usize - ptr as usize }, - 1080usize, concat!("Offset of field: ", stringify!(rte_eth_conf__bindgen_ty_1), - "::", stringify!(vmdq_rx_conf)) + unsafe { ::std::ptr::addr_of!((*ptr).vmdq_rx_conf) as usize - ptr as usize }, + 1080usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf__bindgen_ty_1), + "::", + stringify!(vmdq_rx_conf), + ), ); } impl Clone for rte_eth_conf__bindgen_ty_1 { @@ -1680,27 +2048,44 @@ 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:: < rte_eth_conf__bindgen_ty_2 > (), 12usize, - concat!("Size of: ", stringify!(rte_eth_conf__bindgen_ty_2)) + ::std::mem::size_of::(), + 12usize, + concat!("Size of: ", stringify!(rte_eth_conf__bindgen_ty_2)), ); assert_eq!( - ::std::mem::align_of:: < rte_eth_conf__bindgen_ty_2 > (), 4usize, - concat!("Alignment of ", stringify!(rte_eth_conf__bindgen_ty_2)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_eth_conf__bindgen_ty_2)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).vmdq_dcb_tx_conf) as usize - ptr as usize - }, 0usize, concat!("Offset of field: ", stringify!(rte_eth_conf__bindgen_ty_2), - "::", stringify!(vmdq_dcb_tx_conf)) + unsafe { ::std::ptr::addr_of!((*ptr).vmdq_dcb_tx_conf) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf__bindgen_ty_2), + "::", + stringify!(vmdq_dcb_tx_conf), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).dcb_tx_conf) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_eth_conf__bindgen_ty_2), - "::", stringify!(dcb_tx_conf)) + unsafe { ::std::ptr::addr_of!((*ptr).dcb_tx_conf) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf__bindgen_ty_2), + "::", + stringify!(dcb_tx_conf), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).vmdq_tx_conf) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_eth_conf__bindgen_ty_2), - "::", stringify!(vmdq_tx_conf)) + unsafe { ::std::ptr::addr_of!((*ptr).vmdq_tx_conf) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf__bindgen_ty_2), + "::", + stringify!(vmdq_tx_conf), + ), ); } impl Clone for rte_eth_conf__bindgen_ty_2 { @@ -1713,55 +2098,96 @@ 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:: < rte_eth_conf > (), 2944usize, concat!("Size of: ", - stringify!(rte_eth_conf)) - ); - assert_eq!( - ::std::mem::align_of:: < rte_eth_conf > (), 8usize, concat!("Alignment of ", - stringify!(rte_eth_conf)) + ::std::mem::size_of::(), + 2944usize, + concat!("Size of: ", stringify!(rte_eth_conf)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).link_speeds) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_eth_conf), "::", - stringify!(link_speeds)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(rte_eth_conf)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).rxmode) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(rte_eth_conf), "::", stringify!(rxmode)) + unsafe { ::std::ptr::addr_of!((*ptr).link_speeds) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(link_speeds), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).txmode) as usize - ptr as usize }, 16usize, - concat!("Offset of field: ", stringify!(rte_eth_conf), "::", stringify!(txmode)) + unsafe { ::std::ptr::addr_of!((*ptr).rxmode) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(rte_eth_conf), "::", stringify!(rxmode)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).lpbk_mode) as usize - ptr as usize }, - 24usize, concat!("Offset of field: ", stringify!(rte_eth_conf), "::", - stringify!(lpbk_mode)) + unsafe { ::std::ptr::addr_of!((*ptr).txmode) as usize - ptr as usize }, + 16usize, + concat!("Offset of field: ", stringify!(rte_eth_conf), "::", stringify!(txmode)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).rx_adv_conf) as usize - ptr as usize }, - 32usize, concat!("Offset of field: ", stringify!(rte_eth_conf), "::", - stringify!(rx_adv_conf)) + unsafe { ::std::ptr::addr_of!((*ptr).lpbk_mode) as usize - ptr as usize }, + 24usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(lpbk_mode), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).tx_adv_conf) as usize - ptr as usize }, - 2152usize, concat!("Offset of field: ", stringify!(rte_eth_conf), "::", - stringify!(tx_adv_conf)) + unsafe { ::std::ptr::addr_of!((*ptr).rx_adv_conf) as usize - ptr as usize }, + 32usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(rx_adv_conf), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).dcb_capability_en) as usize - ptr as usize - }, 2164usize, concat!("Offset of field: ", stringify!(rte_eth_conf), "::", - stringify!(dcb_capability_en)) + unsafe { ::std::ptr::addr_of!((*ptr).tx_adv_conf) as usize - ptr as usize }, + 2152usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(tx_adv_conf), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).fdir_conf) as usize - ptr as usize }, - 2168usize, concat!("Offset of field: ", stringify!(rte_eth_conf), "::", - stringify!(fdir_conf)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).intr_conf) as usize - ptr as usize }, - 2940usize, concat!("Offset of field: ", stringify!(rte_eth_conf), "::", - stringify!(intr_conf)) + unsafe { + ::std::ptr::addr_of!((*ptr).dcb_capability_en) as usize - ptr as usize + }, + 2164usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(dcb_capability_en), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).fdir_conf) as usize - ptr as usize }, + 2168usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(fdir_conf), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).intr_conf) as usize - ptr as usize }, + 2940usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_conf), + "::", + stringify!(intr_conf), + ), ); } impl Clone for rte_eth_conf { diff --git a/bindgen-tests/tests/expectations/tests/layout_kni_mbuf.rs b/bindgen-tests/tests/expectations/tests/layout_kni_mbuf.rs index 1167a7317f..258ac0d3dc 100644 --- a/bindgen-tests/tests/expectations/tests/layout_kni_mbuf.rs +++ b/bindgen-tests/tests/expectations/tests/layout_kni_mbuf.rs @@ -31,75 +31,109 @@ 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:: < rte_kni_mbuf > (), 128usize, concat!("Size of: ", - stringify!(rte_kni_mbuf)) + ::std::mem::size_of::(), + 128usize, + concat!("Size of: ", stringify!(rte_kni_mbuf)), ); assert_eq!( - ::std::mem::align_of:: < rte_kni_mbuf > (), 64usize, concat!("Alignment of ", - stringify!(rte_kni_mbuf)) + ::std::mem::align_of::(), + 64usize, + concat!("Alignment of ", stringify!(rte_kni_mbuf)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).buf_addr) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_kni_mbuf), "::", - stringify!(buf_addr)) + unsafe { ::std::ptr::addr_of!((*ptr).buf_addr) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_mbuf), + "::", + stringify!(buf_addr), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).buf_physaddr) as usize - ptr as usize }, - 8usize, concat!("Offset of field: ", stringify!(rte_kni_mbuf), "::", - stringify!(buf_physaddr)) + unsafe { ::std::ptr::addr_of!((*ptr).buf_physaddr) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_mbuf), + "::", + stringify!(buf_physaddr), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).pad0) as usize - ptr as usize }, 16usize, - concat!("Offset of field: ", stringify!(rte_kni_mbuf), "::", stringify!(pad0)) + unsafe { ::std::ptr::addr_of!((*ptr).pad0) as usize - ptr as usize }, + 16usize, + concat!("Offset of field: ", stringify!(rte_kni_mbuf), "::", stringify!(pad0)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).data_off) as usize - ptr as usize }, - 18usize, concat!("Offset of field: ", stringify!(rte_kni_mbuf), "::", - stringify!(data_off)) + unsafe { ::std::ptr::addr_of!((*ptr).data_off) as usize - ptr as usize }, + 18usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_mbuf), + "::", + stringify!(data_off), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).pad1) as usize - ptr as usize }, 20usize, - concat!("Offset of field: ", stringify!(rte_kni_mbuf), "::", stringify!(pad1)) + unsafe { ::std::ptr::addr_of!((*ptr).pad1) as usize - ptr as usize }, + 20usize, + concat!("Offset of field: ", stringify!(rte_kni_mbuf), "::", stringify!(pad1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).nb_segs) as usize - ptr as usize }, - 22usize, concat!("Offset of field: ", stringify!(rte_kni_mbuf), "::", - stringify!(nb_segs)) + unsafe { ::std::ptr::addr_of!((*ptr).nb_segs) as usize - ptr as usize }, + 22usize, + concat!("Offset of field: ", stringify!(rte_kni_mbuf), "::", stringify!(nb_segs)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).pad4) as usize - ptr as usize }, 23usize, - concat!("Offset of field: ", stringify!(rte_kni_mbuf), "::", stringify!(pad4)) + unsafe { ::std::ptr::addr_of!((*ptr).pad4) as usize - ptr as usize }, + 23usize, + concat!("Offset of field: ", stringify!(rte_kni_mbuf), "::", stringify!(pad4)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).ol_flags) as usize - ptr as usize }, - 24usize, concat!("Offset of field: ", stringify!(rte_kni_mbuf), "::", - stringify!(ol_flags)) + unsafe { ::std::ptr::addr_of!((*ptr).ol_flags) as usize - ptr as usize }, + 24usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_mbuf), + "::", + stringify!(ol_flags), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).pad2) as usize - ptr as usize }, 32usize, - concat!("Offset of field: ", stringify!(rte_kni_mbuf), "::", stringify!(pad2)) + unsafe { ::std::ptr::addr_of!((*ptr).pad2) as usize - ptr as usize }, + 32usize, + concat!("Offset of field: ", stringify!(rte_kni_mbuf), "::", stringify!(pad2)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).pkt_len) as usize - ptr as usize }, - 36usize, concat!("Offset of field: ", stringify!(rte_kni_mbuf), "::", - stringify!(pkt_len)) + unsafe { ::std::ptr::addr_of!((*ptr).pkt_len) as usize - ptr as usize }, + 36usize, + concat!("Offset of field: ", stringify!(rte_kni_mbuf), "::", stringify!(pkt_len)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).data_len) as usize - ptr as usize }, - 40usize, concat!("Offset of field: ", stringify!(rte_kni_mbuf), "::", - stringify!(data_len)) + unsafe { ::std::ptr::addr_of!((*ptr).data_len) as usize - ptr as usize }, + 40usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_mbuf), + "::", + stringify!(data_len), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).pad3) as usize - ptr as usize }, 64usize, - concat!("Offset of field: ", stringify!(rte_kni_mbuf), "::", stringify!(pad3)) + unsafe { ::std::ptr::addr_of!((*ptr).pad3) as usize - ptr as usize }, + 64usize, + concat!("Offset of field: ", stringify!(rte_kni_mbuf), "::", stringify!(pad3)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).pool) as usize - ptr as usize }, 72usize, - concat!("Offset of field: ", stringify!(rte_kni_mbuf), "::", stringify!(pool)) + unsafe { ::std::ptr::addr_of!((*ptr).pool) as usize - ptr as usize }, + 72usize, + concat!("Offset of field: ", stringify!(rte_kni_mbuf), "::", stringify!(pool)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).next) as usize - ptr as usize }, 80usize, - concat!("Offset of field: ", stringify!(rte_kni_mbuf), "::", stringify!(next)) + unsafe { ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize }, + 80usize, + concat!("Offset of field: ", stringify!(rte_kni_mbuf), "::", stringify!(next)), ); } impl Default for rte_kni_mbuf { 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 d70e6237da..05a9784356 100644 --- a/bindgen-tests/tests/expectations/tests/layout_large_align_field.rs +++ b/bindgen-tests/tests/expectations/tests/layout_large_align_field.rs @@ -62,24 +62,29 @@ 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:: < ip_frag > (), 16usize, concat!("Size of: ", - stringify!(ip_frag)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(ip_frag)), ); assert_eq!( - ::std::mem::align_of:: < ip_frag > (), 8usize, concat!("Alignment of ", - stringify!(ip_frag)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(ip_frag)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).ofs) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(ip_frag), "::", stringify!(ofs)) + unsafe { ::std::ptr::addr_of!((*ptr).ofs) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(ip_frag), "::", stringify!(ofs)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).len) as usize - ptr as usize }, 2usize, - concat!("Offset of field: ", stringify!(ip_frag), "::", stringify!(len)) + unsafe { ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize }, + 2usize, + concat!("Offset of field: ", stringify!(ip_frag), "::", stringify!(len)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mb) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(ip_frag), "::", stringify!(mb)) + unsafe { ::std::ptr::addr_of!((*ptr).mb) as usize - ptr as usize }, + 8usize, + concat!("Offset of field: ", stringify!(ip_frag), "::", stringify!(mb)), ); } impl Default for ip_frag { @@ -107,25 +112,29 @@ 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:: < ip_frag_key > (), 40usize, concat!("Size of: ", - stringify!(ip_frag_key)) + ::std::mem::size_of::(), + 40usize, + concat!("Size of: ", stringify!(ip_frag_key)), ); assert_eq!( - ::std::mem::align_of:: < ip_frag_key > (), 8usize, concat!("Alignment of ", - stringify!(ip_frag_key)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(ip_frag_key)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).src_dst) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(ip_frag_key), "::", stringify!(src_dst)) + unsafe { ::std::ptr::addr_of!((*ptr).src_dst) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(ip_frag_key), "::", stringify!(src_dst)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).id) as usize - ptr as usize }, 32usize, - concat!("Offset of field: ", stringify!(ip_frag_key), "::", stringify!(id)) + unsafe { ::std::ptr::addr_of!((*ptr).id) as usize - ptr as usize }, + 32usize, + concat!("Offset of field: ", stringify!(ip_frag_key), "::", stringify!(id)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).key_len) as usize - ptr as usize }, - 36usize, concat!("Offset of field: ", stringify!(ip_frag_key), "::", - stringify!(key_len)) + unsafe { ::std::ptr::addr_of!((*ptr).key_len) as usize - ptr as usize }, + 36usize, + concat!("Offset of field: ", stringify!(ip_frag_key), "::", stringify!(key_len)), ); } /** @internal Fragmented packet to reassemble. @@ -160,22 +169,34 @@ 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:: < ip_frag_pkt__bindgen_ty_1 > (), 16usize, - concat!("Size of: ", stringify!(ip_frag_pkt__bindgen_ty_1)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(ip_frag_pkt__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < ip_frag_pkt__bindgen_ty_1 > (), 8usize, - concat!("Alignment of ", stringify!(ip_frag_pkt__bindgen_ty_1)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(ip_frag_pkt__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).tqe_next) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(ip_frag_pkt__bindgen_ty_1), "::", - stringify!(tqe_next)) + unsafe { ::std::ptr::addr_of!((*ptr).tqe_next) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_pkt__bindgen_ty_1), + "::", + stringify!(tqe_next), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).tqe_prev) as usize - ptr as usize }, - 8usize, concat!("Offset of field: ", stringify!(ip_frag_pkt__bindgen_ty_1), "::", - stringify!(tqe_prev)) + unsafe { ::std::ptr::addr_of!((*ptr).tqe_prev) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_pkt__bindgen_ty_1), + "::", + stringify!(tqe_prev), + ), ); } impl Default for ip_frag_pkt__bindgen_ty_1 { @@ -192,43 +213,59 @@ 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:: < ip_frag_pkt > (), 192usize, concat!("Size of: ", - stringify!(ip_frag_pkt)) + ::std::mem::size_of::(), + 192usize, + concat!("Size of: ", stringify!(ip_frag_pkt)), ); assert_eq!( - ::std::mem::align_of:: < ip_frag_pkt > (), 64usize, concat!("Alignment of ", - stringify!(ip_frag_pkt)) + ::std::mem::align_of::(), + 64usize, + concat!("Alignment of ", stringify!(ip_frag_pkt)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).lru) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", stringify!(lru)) + unsafe { ::std::ptr::addr_of!((*ptr).lru) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", stringify!(lru)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).key) as usize - ptr as usize }, 16usize, - concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", stringify!(key)) + unsafe { ::std::ptr::addr_of!((*ptr).key) as usize - ptr as usize }, + 16usize, + concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", stringify!(key)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).start) as usize - ptr as usize }, 56usize, - concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", stringify!(start)) + unsafe { ::std::ptr::addr_of!((*ptr).start) as usize - ptr as usize }, + 56usize, + concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", stringify!(start)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).total_size) as usize - ptr as usize }, - 64usize, concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", - stringify!(total_size)) + unsafe { ::std::ptr::addr_of!((*ptr).total_size) as usize - ptr as usize }, + 64usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_pkt), + "::", + stringify!(total_size), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).frag_size) as usize - ptr as usize }, - 68usize, concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", - stringify!(frag_size)) + unsafe { ::std::ptr::addr_of!((*ptr).frag_size) as usize - ptr as usize }, + 68usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_pkt), + "::", + stringify!(frag_size), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).last_idx) as usize - ptr as usize }, - 72usize, concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", - stringify!(last_idx)) + unsafe { ::std::ptr::addr_of!((*ptr).last_idx) as usize - ptr as usize }, + 72usize, + concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", stringify!(last_idx)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).frags) as usize - ptr as usize }, 80usize, - concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", stringify!(frags)) + unsafe { ::std::ptr::addr_of!((*ptr).frags) as usize - ptr as usize }, + 80usize, + concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", stringify!(frags)), ); } impl Default for ip_frag_pkt { @@ -251,22 +288,29 @@ 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:: < ip_pkt_list > (), 16usize, concat!("Size of: ", - stringify!(ip_pkt_list)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(ip_pkt_list)), ); assert_eq!( - ::std::mem::align_of:: < ip_pkt_list > (), 8usize, concat!("Alignment of ", - stringify!(ip_pkt_list)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(ip_pkt_list)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).tqh_first) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(ip_pkt_list), "::", - stringify!(tqh_first)) + unsafe { ::std::ptr::addr_of!((*ptr).tqh_first) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ip_pkt_list), + "::", + stringify!(tqh_first), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).tqh_last) as usize - ptr as usize }, - 8usize, concat!("Offset of field: ", stringify!(ip_pkt_list), "::", - stringify!(tqh_last)) + unsafe { ::std::ptr::addr_of!((*ptr).tqh_last) as usize - ptr as usize }, + 8usize, + concat!("Offset of field: ", stringify!(ip_pkt_list), "::", stringify!(tqh_last)), ); } impl Default for ip_pkt_list { @@ -301,42 +345,74 @@ 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:: < ip_frag_tbl_stat > (), 64usize, concat!("Size of: ", - stringify!(ip_frag_tbl_stat)) - ); - assert_eq!( - ::std::mem::align_of:: < ip_frag_tbl_stat > (), 64usize, concat!("Alignment of ", - stringify!(ip_frag_tbl_stat)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).find_num) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(ip_frag_tbl_stat), "::", - stringify!(find_num)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).add_num) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(ip_frag_tbl_stat), "::", - stringify!(add_num)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).del_num) as usize - ptr as usize }, - 16usize, concat!("Offset of field: ", stringify!(ip_frag_tbl_stat), "::", - stringify!(del_num)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).reuse_num) as usize - ptr as usize }, - 24usize, concat!("Offset of field: ", stringify!(ip_frag_tbl_stat), "::", - stringify!(reuse_num)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).fail_total) as usize - ptr as usize }, - 32usize, concat!("Offset of field: ", stringify!(ip_frag_tbl_stat), "::", - stringify!(fail_total)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).fail_nospace) as usize - ptr as usize }, - 40usize, concat!("Offset of field: ", stringify!(ip_frag_tbl_stat), "::", - stringify!(fail_nospace)) + ::std::mem::size_of::(), + 64usize, + concat!("Size of: ", stringify!(ip_frag_tbl_stat)), + ); + assert_eq!( + ::std::mem::align_of::(), + 64usize, + concat!("Alignment of ", stringify!(ip_frag_tbl_stat)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).find_num) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_tbl_stat), + "::", + stringify!(find_num), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).add_num) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_tbl_stat), + "::", + stringify!(add_num), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).del_num) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_tbl_stat), + "::", + stringify!(del_num), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).reuse_num) as usize - ptr as usize }, + 24usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_tbl_stat), + "::", + stringify!(reuse_num), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).fail_total) as usize - ptr as usize }, + 32usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_tbl_stat), + "::", + stringify!(fail_total), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).fail_nospace) as usize - ptr as usize }, + 40usize, + concat!( + "Offset of field: ", + stringify!(ip_frag_tbl_stat), + "::", + stringify!(fail_nospace), + ), ); } impl Default for ip_frag_tbl_stat { @@ -381,63 +457,104 @@ 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:: < rte_ip_frag_tbl > (), 128usize, concat!("Size of: ", - stringify!(rte_ip_frag_tbl)) + ::std::mem::size_of::(), + 128usize, + concat!("Size of: ", stringify!(rte_ip_frag_tbl)), ); assert_eq!( - ::std::mem::align_of:: < rte_ip_frag_tbl > (), 64usize, concat!("Alignment of ", - stringify!(rte_ip_frag_tbl)) + ::std::mem::align_of::(), + 64usize, + concat!("Alignment of ", stringify!(rte_ip_frag_tbl)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).max_cycles) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_ip_frag_tbl), "::", - stringify!(max_cycles)) + unsafe { ::std::ptr::addr_of!((*ptr).max_cycles) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ip_frag_tbl), + "::", + stringify!(max_cycles), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).entry_mask) as usize - ptr as usize }, - 8usize, concat!("Offset of field: ", stringify!(rte_ip_frag_tbl), "::", - stringify!(entry_mask)) + unsafe { ::std::ptr::addr_of!((*ptr).entry_mask) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_ip_frag_tbl), + "::", + stringify!(entry_mask), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).max_entries) as usize - ptr as usize }, - 12usize, concat!("Offset of field: ", stringify!(rte_ip_frag_tbl), "::", - stringify!(max_entries)) + unsafe { ::std::ptr::addr_of!((*ptr).max_entries) as usize - ptr as usize }, + 12usize, + concat!( + "Offset of field: ", + stringify!(rte_ip_frag_tbl), + "::", + stringify!(max_entries), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).use_entries) as usize - ptr as usize }, - 16usize, concat!("Offset of field: ", stringify!(rte_ip_frag_tbl), "::", - stringify!(use_entries)) + unsafe { ::std::ptr::addr_of!((*ptr).use_entries) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(rte_ip_frag_tbl), + "::", + stringify!(use_entries), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).bucket_entries) as usize - ptr as usize }, - 20usize, concat!("Offset of field: ", stringify!(rte_ip_frag_tbl), "::", - stringify!(bucket_entries)) + unsafe { ::std::ptr::addr_of!((*ptr).bucket_entries) as usize - ptr as usize }, + 20usize, + concat!( + "Offset of field: ", + stringify!(rte_ip_frag_tbl), + "::", + stringify!(bucket_entries), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).nb_entries) as usize - ptr as usize }, - 24usize, concat!("Offset of field: ", stringify!(rte_ip_frag_tbl), "::", - stringify!(nb_entries)) + unsafe { ::std::ptr::addr_of!((*ptr).nb_entries) as usize - ptr as usize }, + 24usize, + concat!( + "Offset of field: ", + stringify!(rte_ip_frag_tbl), + "::", + stringify!(nb_entries), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).nb_buckets) as usize - ptr as usize }, - 28usize, concat!("Offset of field: ", stringify!(rte_ip_frag_tbl), "::", - stringify!(nb_buckets)) + unsafe { ::std::ptr::addr_of!((*ptr).nb_buckets) as usize - ptr as usize }, + 28usize, + concat!( + "Offset of field: ", + stringify!(rte_ip_frag_tbl), + "::", + stringify!(nb_buckets), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).last) as usize - ptr as usize }, 32usize, - concat!("Offset of field: ", stringify!(rte_ip_frag_tbl), "::", stringify!(last)) + unsafe { ::std::ptr::addr_of!((*ptr).last) as usize - ptr as usize }, + 32usize, + concat!("Offset of field: ", stringify!(rte_ip_frag_tbl), "::", stringify!(last)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).lru) as usize - ptr as usize }, 40usize, - concat!("Offset of field: ", stringify!(rte_ip_frag_tbl), "::", stringify!(lru)) + unsafe { ::std::ptr::addr_of!((*ptr).lru) as usize - ptr as usize }, + 40usize, + concat!("Offset of field: ", stringify!(rte_ip_frag_tbl), "::", stringify!(lru)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).stat) as usize - ptr as usize }, 64usize, - concat!("Offset of field: ", stringify!(rte_ip_frag_tbl), "::", stringify!(stat)) + unsafe { ::std::ptr::addr_of!((*ptr).stat) as usize - ptr as usize }, + 64usize, + concat!("Offset of field: ", stringify!(rte_ip_frag_tbl), "::", stringify!(stat)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).pkt) as usize - ptr as usize }, 128usize, - concat!("Offset of field: ", stringify!(rte_ip_frag_tbl), "::", stringify!(pkt)) + unsafe { ::std::ptr::addr_of!((*ptr).pkt) as usize - ptr as usize }, + 128usize, + concat!("Offset of field: ", stringify!(rte_ip_frag_tbl), "::", stringify!(pkt)), ); } impl Default for rte_ip_frag_tbl { diff --git a/bindgen-tests/tests/expectations/tests/layout_mbuf.rs b/bindgen-tests/tests/expectations/tests/layout_mbuf.rs index 04e8a37efd..a04f0274d1 100644 --- a/bindgen-tests/tests/expectations/tests/layout_mbuf.rs +++ b/bindgen-tests/tests/expectations/tests/layout_mbuf.rs @@ -49,7 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -69,7 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -101,16 +101,19 @@ fn bindgen_test_layout_rte_atomic16_t() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < rte_atomic16_t > (), 2usize, concat!("Size of: ", - stringify!(rte_atomic16_t)) + ::std::mem::size_of::(), + 2usize, + concat!("Size of: ", stringify!(rte_atomic16_t)), ); assert_eq!( - ::std::mem::align_of:: < rte_atomic16_t > (), 2usize, concat!("Alignment of ", - stringify!(rte_atomic16_t)) + ::std::mem::align_of::(), + 2usize, + concat!("Alignment of ", stringify!(rte_atomic16_t)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).cnt) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_atomic16_t), "::", stringify!(cnt)) + unsafe { ::std::ptr::addr_of!((*ptr).cnt) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(rte_atomic16_t), "::", stringify!(cnt)), ); } /// The generic rte_mbuf, containing a packet mbuf. @@ -179,22 +182,34 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < rte_mbuf__bindgen_ty_1 > (), 2usize, concat!("Size of: ", - stringify!(rte_mbuf__bindgen_ty_1)) + ::std::mem::size_of::(), + 2usize, + concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < rte_mbuf__bindgen_ty_1 > (), 2usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_1)) + ::std::mem::align_of::(), + 2usize, + concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).refcnt_atomic) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_1), "::", - stringify!(refcnt_atomic)) + unsafe { ::std::ptr::addr_of!((*ptr).refcnt_atomic) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_1), + "::", + stringify!(refcnt_atomic), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).refcnt) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_1), "::", - stringify!(refcnt)) + unsafe { ::std::ptr::addr_of!((*ptr).refcnt) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_1), + "::", + stringify!(refcnt), + ), ); } impl Default for rte_mbuf__bindgen_ty_1 { @@ -223,12 +238,14 @@ pub struct rte_mbuf__bindgen_ty_2__bindgen_ty_1 { #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_2__bindgen_ty_1() { assert_eq!( - ::std::mem::size_of:: < rte_mbuf__bindgen_ty_2__bindgen_ty_1 > (), 4usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_2__bindgen_ty_1)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_2__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < rte_mbuf__bindgen_ty_2__bindgen_ty_1 > (), 4usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_2__bindgen_ty_1)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_2__bindgen_ty_1)), ); } impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { @@ -397,17 +414,24 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_2() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < rte_mbuf__bindgen_ty_2 > (), 4usize, concat!("Size of: ", - stringify!(rte_mbuf__bindgen_ty_2)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_2)), ); assert_eq!( - ::std::mem::align_of:: < rte_mbuf__bindgen_ty_2 > (), 4usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_2)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_2)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).packet_type) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_2), "::", - stringify!(packet_type)) + unsafe { ::std::ptr::addr_of!((*ptr).packet_type) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_2), + "::", + stringify!(packet_type), + ), ); } impl Default for rte_mbuf__bindgen_ty_2 { @@ -456,28 +480,44 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindg > = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < - rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > (), 4usize, - concat!("Size of: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1)) - ); - assert_eq!( - ::std::mem::align_of:: < - rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > (), 2usize, - concat!("Alignment of ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).hash) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1), - "::", stringify!(hash)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).id) as usize - ptr as usize }, 2usize, - concat!("Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1), - "::", stringify!(id)) + ::std::mem::size_of::< + rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1, + >(), + 4usize, + concat!( + "Size of: ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1), + ), + ); + assert_eq!( + ::std::mem::align_of::< + rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1, + >(), + 2usize, + concat!( + "Alignment of ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).hash) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(hash), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).id) as usize - ptr as usize }, + 2usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(id), + ), ); } #[test] @@ -487,20 +527,30 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1() { > = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 > (), - 4usize, concat!("Size of: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1)) + ::std::mem::size_of::(), + 4usize, + concat!( + "Size of: ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1), + ), ); assert_eq!( - ::std::mem::align_of:: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 > (), - 4usize, concat!("Alignment of ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1)) + ::std::mem::align_of::(), + 4usize, + concat!( + "Alignment of ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).lo) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1), "::", - stringify!(lo)) + unsafe { ::std::ptr::addr_of!((*ptr).lo) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(lo), + ), ); } impl Default for rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 { @@ -517,17 +567,24 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < rte_mbuf__bindgen_ty_3__bindgen_ty_1 > (), 8usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < rte_mbuf__bindgen_ty_3__bindgen_ty_1 > (), 4usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).hi) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1), - "::", stringify!(hi)) + unsafe { ::std::ptr::addr_of!((*ptr).hi) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1), + "::", + stringify!(hi), + ), ); } impl Default for rte_mbuf__bindgen_ty_3__bindgen_ty_1 { @@ -550,22 +607,34 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_2() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < rte_mbuf__bindgen_ty_3__bindgen_ty_2 > (), 8usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2)), ); assert_eq!( - ::std::mem::align_of:: < rte_mbuf__bindgen_ty_3__bindgen_ty_2 > (), 4usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).lo) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2), - "::", stringify!(lo)) + unsafe { ::std::ptr::addr_of!((*ptr).lo) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2), + "::", + stringify!(lo), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).hi) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2), - "::", stringify!(hi)) + unsafe { ::std::ptr::addr_of!((*ptr).hi) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2), + "::", + stringify!(hi), + ), ); } #[test] @@ -573,32 +642,54 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < rte_mbuf__bindgen_ty_3 > (), 8usize, concat!("Size of: ", - stringify!(rte_mbuf__bindgen_ty_3)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_3)), ); assert_eq!( - ::std::mem::align_of:: < rte_mbuf__bindgen_ty_3 > (), 4usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_3)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_3)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).rss) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_3), "::", - stringify!(rss)) + unsafe { ::std::ptr::addr_of!((*ptr).rss) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3), + "::", + stringify!(rss), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).fdir) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_3), "::", - stringify!(fdir)) + unsafe { ::std::ptr::addr_of!((*ptr).fdir) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3), + "::", + stringify!(fdir), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).sched) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_3), "::", - stringify!(sched)) + unsafe { ::std::ptr::addr_of!((*ptr).sched) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3), + "::", + stringify!(sched), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).usr) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_3), "::", - stringify!(usr)) + unsafe { ::std::ptr::addr_of!((*ptr).usr) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3), + "::", + stringify!(usr), + ), ); } impl Default for rte_mbuf__bindgen_ty_3 { @@ -623,22 +714,34 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_4() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < rte_mbuf__bindgen_ty_4 > (), 8usize, concat!("Size of: ", - stringify!(rte_mbuf__bindgen_ty_4)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_4)), ); assert_eq!( - ::std::mem::align_of:: < rte_mbuf__bindgen_ty_4 > (), 8usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_4)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_4)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).userdata) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_4), "::", - stringify!(userdata)) + unsafe { ::std::ptr::addr_of!((*ptr).userdata) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_4), + "::", + stringify!(userdata), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).udata64) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_4), "::", - stringify!(udata64)) + unsafe { ::std::ptr::addr_of!((*ptr).udata64) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_4), + "::", + stringify!(udata64), + ), ); } impl Default for rte_mbuf__bindgen_ty_4 { @@ -667,12 +770,14 @@ pub struct rte_mbuf__bindgen_ty_5__bindgen_ty_1 { #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_5__bindgen_ty_1() { assert_eq!( - ::std::mem::size_of:: < rte_mbuf__bindgen_ty_5__bindgen_ty_1 > (), 8usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_5__bindgen_ty_1)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_5__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < rte_mbuf__bindgen_ty_5__bindgen_ty_1 > (), 8usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_5__bindgen_ty_1)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_5__bindgen_ty_1)), ); } impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { @@ -818,17 +923,24 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_5() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < rte_mbuf__bindgen_ty_5 > (), 8usize, concat!("Size of: ", - stringify!(rte_mbuf__bindgen_ty_5)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_5)), ); assert_eq!( - ::std::mem::align_of:: < rte_mbuf__bindgen_ty_5 > (), 8usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_5)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_5)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).tx_offload) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_5), "::", - stringify!(tx_offload)) + unsafe { ::std::ptr::addr_of!((*ptr).tx_offload) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_5), + "::", + stringify!(tx_offload), + ), ); } impl Default for rte_mbuf__bindgen_ty_5 { @@ -845,112 +957,136 @@ fn bindgen_test_layout_rte_mbuf() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < rte_mbuf > (), 128usize, concat!("Size of: ", - stringify!(rte_mbuf)) + ::std::mem::size_of::(), + 128usize, + concat!("Size of: ", stringify!(rte_mbuf)), ); assert_eq!( - ::std::mem::align_of:: < rte_mbuf > (), 64usize, concat!("Alignment of ", - stringify!(rte_mbuf)) + ::std::mem::align_of::(), + 64usize, + concat!("Alignment of ", stringify!(rte_mbuf)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).cacheline0) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", - stringify!(cacheline0)) + unsafe { ::std::ptr::addr_of!((*ptr).cacheline0) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(cacheline0)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).buf_addr) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", - stringify!(buf_addr)) + unsafe { ::std::ptr::addr_of!((*ptr).buf_addr) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(buf_addr)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).buf_physaddr) as usize - ptr as usize }, - 8usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", - stringify!(buf_physaddr)) + unsafe { ::std::ptr::addr_of!((*ptr).buf_physaddr) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(buf_physaddr), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).buf_len) as usize - ptr as usize }, - 16usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", - stringify!(buf_len)) + unsafe { ::std::ptr::addr_of!((*ptr).buf_len) as usize - ptr as usize }, + 16usize, + concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(buf_len)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).rearm_data) as usize - ptr as usize }, - 18usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", - stringify!(rearm_data)) + unsafe { ::std::ptr::addr_of!((*ptr).rearm_data) as usize - ptr as usize }, + 18usize, + concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(rearm_data)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).data_off) as usize - ptr as usize }, - 18usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", - stringify!(data_off)) + unsafe { ::std::ptr::addr_of!((*ptr).data_off) as usize - ptr as usize }, + 18usize, + concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(data_off)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).nb_segs) as usize - ptr as usize }, - 22usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", - stringify!(nb_segs)) + unsafe { ::std::ptr::addr_of!((*ptr).nb_segs) as usize - ptr as usize }, + 22usize, + concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(nb_segs)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).port) as usize - ptr as usize }, 23usize, - concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(port)) + unsafe { ::std::ptr::addr_of!((*ptr).port) as usize - ptr as usize }, + 23usize, + concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(port)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).ol_flags) as usize - ptr as usize }, - 24usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", - stringify!(ol_flags)) + unsafe { ::std::ptr::addr_of!((*ptr).ol_flags) as usize - ptr as usize }, + 24usize, + concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(ol_flags)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).rx_descriptor_fields1) as usize - ptr as - usize }, 32usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", - stringify!(rx_descriptor_fields1)) + unsafe { + ::std::ptr::addr_of!((*ptr).rx_descriptor_fields1) as usize - ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(rx_descriptor_fields1), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).pkt_len) as usize - ptr as usize }, - 36usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", - stringify!(pkt_len)) + unsafe { ::std::ptr::addr_of!((*ptr).pkt_len) as usize - ptr as usize }, + 36usize, + concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(pkt_len)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).data_len) as usize - ptr as usize }, - 40usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", - stringify!(data_len)) + unsafe { ::std::ptr::addr_of!((*ptr).data_len) as usize - ptr as usize }, + 40usize, + concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(data_len)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).vlan_tci) as usize - ptr as usize }, - 42usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", - stringify!(vlan_tci)) + unsafe { ::std::ptr::addr_of!((*ptr).vlan_tci) as usize - ptr as usize }, + 42usize, + concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(vlan_tci)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).hash) as usize - ptr as usize }, 44usize, - concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(hash)) + unsafe { ::std::ptr::addr_of!((*ptr).hash) as usize - ptr as usize }, + 44usize, + concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(hash)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).seqn) as usize - ptr as usize }, 52usize, - concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(seqn)) + unsafe { ::std::ptr::addr_of!((*ptr).seqn) as usize - ptr as usize }, + 52usize, + concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(seqn)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).vlan_tci_outer) as usize - ptr as usize }, - 56usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", - stringify!(vlan_tci_outer)) + unsafe { ::std::ptr::addr_of!((*ptr).vlan_tci_outer) as usize - ptr as usize }, + 56usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(vlan_tci_outer), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).cacheline1) as usize - ptr as usize }, - 64usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", - stringify!(cacheline1)) + unsafe { ::std::ptr::addr_of!((*ptr).cacheline1) as usize - ptr as usize }, + 64usize, + concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(cacheline1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).pool) as usize - ptr as usize }, 72usize, - concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(pool)) + unsafe { ::std::ptr::addr_of!((*ptr).pool) as usize - ptr as usize }, + 72usize, + concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(pool)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).next) as usize - ptr as usize }, 80usize, - concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(next)) + unsafe { ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize }, + 80usize, + concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(next)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).priv_size) as usize - ptr as usize }, - 96usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", - stringify!(priv_size)) + unsafe { ::std::ptr::addr_of!((*ptr).priv_size) as usize - ptr as usize }, + 96usize, + concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(priv_size)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).timesync) as usize - ptr as usize }, - 98usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", - stringify!(timesync)) + unsafe { ::std::ptr::addr_of!((*ptr).timesync) as usize - ptr as usize }, + 98usize, + concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(timesync)), ); } impl Default for rte_mbuf { diff --git a/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs b/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs index 96f8cb176c..eb8d4b5d30 100644 --- a/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs @@ -49,7 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -69,7 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -144,16 +144,19 @@ fn bindgen_test_layout_rte_atomic16_t() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < rte_atomic16_t > (), 2usize, concat!("Size of: ", - stringify!(rte_atomic16_t)) + ::std::mem::size_of::(), + 2usize, + concat!("Size of: ", stringify!(rte_atomic16_t)), ); assert_eq!( - ::std::mem::align_of:: < rte_atomic16_t > (), 2usize, concat!("Alignment of ", - stringify!(rte_atomic16_t)) + ::std::mem::align_of::(), + 2usize, + concat!("Alignment of ", stringify!(rte_atomic16_t)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).cnt) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_atomic16_t), "::", stringify!(cnt)) + unsafe { ::std::ptr::addr_of!((*ptr).cnt) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(rte_atomic16_t), "::", stringify!(cnt)), ); } impl Clone for rte_atomic16_t { @@ -228,22 +231,34 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < rte_mbuf__bindgen_ty_1 > (), 2usize, concat!("Size of: ", - stringify!(rte_mbuf__bindgen_ty_1)) + ::std::mem::size_of::(), + 2usize, + concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < rte_mbuf__bindgen_ty_1 > (), 2usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_1)) + ::std::mem::align_of::(), + 2usize, + concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).refcnt_atomic) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_1), "::", - stringify!(refcnt_atomic)) + unsafe { ::std::ptr::addr_of!((*ptr).refcnt_atomic) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_1), + "::", + stringify!(refcnt_atomic), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).refcnt) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_1), "::", - stringify!(refcnt)) + unsafe { ::std::ptr::addr_of!((*ptr).refcnt) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_1), + "::", + stringify!(refcnt), + ), ); } impl Clone for rte_mbuf__bindgen_ty_1 { @@ -269,12 +284,14 @@ pub struct rte_mbuf__bindgen_ty_2__bindgen_ty_1 { #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_2__bindgen_ty_1() { assert_eq!( - ::std::mem::size_of:: < rte_mbuf__bindgen_ty_2__bindgen_ty_1 > (), 4usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_2__bindgen_ty_1)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_2__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < rte_mbuf__bindgen_ty_2__bindgen_ty_1 > (), 4usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_2__bindgen_ty_1)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_2__bindgen_ty_1)), ); } impl Clone for rte_mbuf__bindgen_ty_2__bindgen_ty_1 { @@ -448,17 +465,24 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_2() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < rte_mbuf__bindgen_ty_2 > (), 4usize, concat!("Size of: ", - stringify!(rte_mbuf__bindgen_ty_2)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_2)), ); assert_eq!( - ::std::mem::align_of:: < rte_mbuf__bindgen_ty_2 > (), 4usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_2)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_2)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).packet_type) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_2), "::", - stringify!(packet_type)) + unsafe { ::std::ptr::addr_of!((*ptr).packet_type) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_2), + "::", + stringify!(packet_type), + ), ); } impl Clone for rte_mbuf__bindgen_ty_2 { @@ -507,28 +531,44 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindg > = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < - rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > (), 4usize, - concat!("Size of: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1)) + ::std::mem::size_of::< + rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1, + >(), + 4usize, + concat!( + "Size of: ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1), + ), ); assert_eq!( - ::std::mem::align_of:: < - rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 > (), 2usize, - concat!("Alignment of ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1)) + ::std::mem::align_of::< + rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1, + >(), + 2usize, + concat!( + "Alignment of ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).hash) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1), - "::", stringify!(hash)) + unsafe { ::std::ptr::addr_of!((*ptr).hash) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(hash), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).id) as usize - ptr as usize }, 2usize, - concat!("Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1), - "::", stringify!(id)) + unsafe { ::std::ptr::addr_of!((*ptr).id) as usize - ptr as usize }, + 2usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(id), + ), ); } impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 { @@ -543,20 +583,30 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1() { > = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 > (), - 4usize, concat!("Size of: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1)) + ::std::mem::size_of::(), + 4usize, + concat!( + "Size of: ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1), + ), ); assert_eq!( - ::std::mem::align_of:: < rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 > (), - 4usize, concat!("Alignment of ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1)) + ::std::mem::align_of::(), + 4usize, + concat!( + "Alignment of ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).lo) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1), "::", - stringify!(lo)) + unsafe { ::std::ptr::addr_of!((*ptr).lo) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(lo), + ), ); } impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 { @@ -569,17 +619,24 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < rte_mbuf__bindgen_ty_3__bindgen_ty_1 > (), 8usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < rte_mbuf__bindgen_ty_3__bindgen_ty_1 > (), 4usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).hi) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1), - "::", stringify!(hi)) + unsafe { ::std::ptr::addr_of!((*ptr).hi) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1), + "::", + stringify!(hi), + ), ); } impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_1 { @@ -598,22 +655,34 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_2() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < rte_mbuf__bindgen_ty_3__bindgen_ty_2 > (), 8usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2)), ); assert_eq!( - ::std::mem::align_of:: < rte_mbuf__bindgen_ty_3__bindgen_ty_2 > (), 4usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).lo) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2), - "::", stringify!(lo)) + unsafe { ::std::ptr::addr_of!((*ptr).lo) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2), + "::", + stringify!(lo), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).hi) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2), - "::", stringify!(hi)) + unsafe { ::std::ptr::addr_of!((*ptr).hi) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2), + "::", + stringify!(hi), + ), ); } impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_2 { @@ -626,32 +695,54 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < rte_mbuf__bindgen_ty_3 > (), 8usize, concat!("Size of: ", - stringify!(rte_mbuf__bindgen_ty_3)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_3)), ); assert_eq!( - ::std::mem::align_of:: < rte_mbuf__bindgen_ty_3 > (), 4usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_3)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_3)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).rss) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_3), "::", - stringify!(rss)) + unsafe { ::std::ptr::addr_of!((*ptr).rss) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3), + "::", + stringify!(rss), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).fdir) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_3), "::", - stringify!(fdir)) + unsafe { ::std::ptr::addr_of!((*ptr).fdir) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3), + "::", + stringify!(fdir), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).sched) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_3), "::", - stringify!(sched)) + unsafe { ::std::ptr::addr_of!((*ptr).sched) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3), + "::", + stringify!(sched), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).usr) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_3), "::", - stringify!(usr)) + unsafe { ::std::ptr::addr_of!((*ptr).usr) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_3), + "::", + stringify!(usr), + ), ); } impl Clone for rte_mbuf__bindgen_ty_3 { @@ -673,22 +764,34 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_4() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < rte_mbuf__bindgen_ty_4 > (), 8usize, concat!("Size of: ", - stringify!(rte_mbuf__bindgen_ty_4)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_4)), ); assert_eq!( - ::std::mem::align_of:: < rte_mbuf__bindgen_ty_4 > (), 8usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_4)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_4)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).userdata) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_4), "::", - stringify!(userdata)) + unsafe { ::std::ptr::addr_of!((*ptr).userdata) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_4), + "::", + stringify!(userdata), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).udata64) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_4), "::", - stringify!(udata64)) + unsafe { ::std::ptr::addr_of!((*ptr).udata64) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_4), + "::", + stringify!(udata64), + ), ); } impl Clone for rte_mbuf__bindgen_ty_4 { @@ -714,12 +817,14 @@ pub struct rte_mbuf__bindgen_ty_5__bindgen_ty_1 { #[test] fn bindgen_test_layout_rte_mbuf__bindgen_ty_5__bindgen_ty_1() { assert_eq!( - ::std::mem::size_of:: < rte_mbuf__bindgen_ty_5__bindgen_ty_1 > (), 8usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_5__bindgen_ty_1)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_5__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < rte_mbuf__bindgen_ty_5__bindgen_ty_1 > (), 8usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_5__bindgen_ty_1)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_5__bindgen_ty_1)), ); } impl Clone for rte_mbuf__bindgen_ty_5__bindgen_ty_1 { @@ -870,17 +975,24 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_5() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < rte_mbuf__bindgen_ty_5 > (), 8usize, concat!("Size of: ", - stringify!(rte_mbuf__bindgen_ty_5)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_5)), ); assert_eq!( - ::std::mem::align_of:: < rte_mbuf__bindgen_ty_5 > (), 8usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_5)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_5)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).tx_offload) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_mbuf__bindgen_ty_5), "::", - stringify!(tx_offload)) + unsafe { ::std::ptr::addr_of!((*ptr).tx_offload) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf__bindgen_ty_5), + "::", + stringify!(tx_offload), + ), ); } impl Clone for rte_mbuf__bindgen_ty_5 { @@ -893,108 +1005,131 @@ fn bindgen_test_layout_rte_mbuf() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < rte_mbuf > (), 128usize, concat!("Size of: ", - stringify!(rte_mbuf)) + ::std::mem::size_of::(), + 128usize, + concat!("Size of: ", stringify!(rte_mbuf)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).cacheline0) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", - stringify!(cacheline0)) + unsafe { ::std::ptr::addr_of!((*ptr).cacheline0) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(cacheline0)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).buf_addr) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", - stringify!(buf_addr)) + unsafe { ::std::ptr::addr_of!((*ptr).buf_addr) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(buf_addr)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).buf_physaddr) as usize - ptr as usize }, - 8usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", - stringify!(buf_physaddr)) + unsafe { ::std::ptr::addr_of!((*ptr).buf_physaddr) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(buf_physaddr), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).buf_len) as usize - ptr as usize }, - 16usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", - stringify!(buf_len)) + unsafe { ::std::ptr::addr_of!((*ptr).buf_len) as usize - ptr as usize }, + 16usize, + concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(buf_len)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).rearm_data) as usize - ptr as usize }, - 18usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", - stringify!(rearm_data)) + unsafe { ::std::ptr::addr_of!((*ptr).rearm_data) as usize - ptr as usize }, + 18usize, + concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(rearm_data)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).data_off) as usize - ptr as usize }, - 18usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", - stringify!(data_off)) + unsafe { ::std::ptr::addr_of!((*ptr).data_off) as usize - ptr as usize }, + 18usize, + concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(data_off)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).nb_segs) as usize - ptr as usize }, - 22usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", - stringify!(nb_segs)) + unsafe { ::std::ptr::addr_of!((*ptr).nb_segs) as usize - ptr as usize }, + 22usize, + concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(nb_segs)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).port) as usize - ptr as usize }, 23usize, - concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(port)) + unsafe { ::std::ptr::addr_of!((*ptr).port) as usize - ptr as usize }, + 23usize, + concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(port)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).ol_flags) as usize - ptr as usize }, - 24usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", - stringify!(ol_flags)) + unsafe { ::std::ptr::addr_of!((*ptr).ol_flags) as usize - ptr as usize }, + 24usize, + concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(ol_flags)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).rx_descriptor_fields1) as usize - ptr as - usize }, 32usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", - stringify!(rx_descriptor_fields1)) + unsafe { + ::std::ptr::addr_of!((*ptr).rx_descriptor_fields1) as usize - ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(rx_descriptor_fields1), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).pkt_len) as usize - ptr as usize }, - 36usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", - stringify!(pkt_len)) + unsafe { ::std::ptr::addr_of!((*ptr).pkt_len) as usize - ptr as usize }, + 36usize, + concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(pkt_len)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).data_len) as usize - ptr as usize }, - 40usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", - stringify!(data_len)) + unsafe { ::std::ptr::addr_of!((*ptr).data_len) as usize - ptr as usize }, + 40usize, + concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(data_len)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).vlan_tci) as usize - ptr as usize }, - 42usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", - stringify!(vlan_tci)) + unsafe { ::std::ptr::addr_of!((*ptr).vlan_tci) as usize - ptr as usize }, + 42usize, + concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(vlan_tci)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).hash) as usize - ptr as usize }, 44usize, - concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(hash)) + unsafe { ::std::ptr::addr_of!((*ptr).hash) as usize - ptr as usize }, + 44usize, + concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(hash)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).seqn) as usize - ptr as usize }, 52usize, - concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(seqn)) + unsafe { ::std::ptr::addr_of!((*ptr).seqn) as usize - ptr as usize }, + 52usize, + concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(seqn)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).vlan_tci_outer) as usize - ptr as usize }, - 56usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", - stringify!(vlan_tci_outer)) + unsafe { ::std::ptr::addr_of!((*ptr).vlan_tci_outer) as usize - ptr as usize }, + 56usize, + concat!( + "Offset of field: ", + stringify!(rte_mbuf), + "::", + stringify!(vlan_tci_outer), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).cacheline1) as usize - ptr as usize }, - 64usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", - stringify!(cacheline1)) + unsafe { ::std::ptr::addr_of!((*ptr).cacheline1) as usize - ptr as usize }, + 64usize, + concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(cacheline1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).pool) as usize - ptr as usize }, 72usize, - concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(pool)) + unsafe { ::std::ptr::addr_of!((*ptr).pool) as usize - ptr as usize }, + 72usize, + concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(pool)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).next) as usize - ptr as usize }, 80usize, - concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(next)) + unsafe { ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize }, + 80usize, + concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(next)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).priv_size) as usize - ptr as usize }, - 96usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", - stringify!(priv_size)) + unsafe { ::std::ptr::addr_of!((*ptr).priv_size) as usize - ptr as usize }, + 96usize, + concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(priv_size)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).timesync) as usize - ptr as usize }, - 98usize, concat!("Offset of field: ", stringify!(rte_mbuf), "::", - stringify!(timesync)) + unsafe { ::std::ptr::addr_of!((*ptr).timesync) as usize - ptr as usize }, + 98usize, + concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(timesync)), ); } impl Default for rte_mbuf { diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/auto.rs b/bindgen-tests/tests/expectations/tests/libclang-5/auto.rs index acf81c26d6..340bc670dc 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-5/auto.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-5/auto.rs @@ -8,11 +8,14 @@ pub const Foo_kFoo: bool = true; #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo)), ); assert_eq!( - ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", - stringify!(Foo)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)), ); } #[repr(C)] diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/call-conv-field.rs b/bindgen-tests/tests/expectations/tests/libclang-5/call-conv-field.rs index 8f99ebc3a4..e3179543fc 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-5/call-conv-field.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-5/call-conv-field.rs @@ -15,22 +15,34 @@ fn bindgen_test_layout_JNINativeInterface_() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < JNINativeInterface_ > (), 16usize, concat!("Size of: ", - stringify!(JNINativeInterface_)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(JNINativeInterface_)), ); assert_eq!( - ::std::mem::align_of:: < JNINativeInterface_ > (), 8usize, - concat!("Alignment of ", stringify!(JNINativeInterface_)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(JNINativeInterface_)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).GetVersion) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(JNINativeInterface_), "::", - stringify!(GetVersion)) + unsafe { ::std::ptr::addr_of!((*ptr).GetVersion) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(JNINativeInterface_), + "::", + stringify!(GetVersion), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).__hack) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(JNINativeInterface_), "::", - stringify!(__hack)) + unsafe { ::std::ptr::addr_of!((*ptr).__hack) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(JNINativeInterface_), + "::", + stringify!(__hack), + ), ); } extern "stdcall" { diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/const_bool.rs b/bindgen-tests/tests/expectations/tests/libclang-5/const_bool.rs index d08e431607..97cb7ec691 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-5/const_bool.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-5/const_bool.rs @@ -8,11 +8,11 @@ pub struct A { pub const A_k: bool = false; #[test] fn bindgen_test_layout_A() { + assert_eq!(::std::mem::size_of::(), 1usize, concat!("Size of: ", stringify!(A))); assert_eq!( - ::std::mem::size_of:: < A > (), 1usize, concat!("Size of: ", stringify!(A)) - ); - assert_eq!( - ::std::mem::align_of:: < A > (), 1usize, concat!("Alignment of ", stringify!(A)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(A)), ); } pub type foo = bool; diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/issue-769-bad-instantiation-test.rs b/bindgen-tests/tests/expectations/tests/libclang-5/issue-769-bad-instantiation-test.rs index 0acb9ad8b8..ef830ca69e 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-5/issue-769-bad-instantiation-test.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-5/issue-769-bad-instantiation-test.rs @@ -22,27 +22,39 @@ pub mod root { #[test] fn __bindgen_test_layout_Rooted_open0_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < root::Rooted < ::std::os::raw::c_int > > (), 4usize, - concat!("Size of template specialization: ", stringify!(root::Rooted < - ::std::os::raw::c_int >)) + ::std::mem::size_of::>(), + 4usize, + concat!( + "Size of template specialization: ", + stringify!(root::Rooted < ::std::os::raw::c_int >), + ), ); assert_eq!( - ::std::mem::align_of:: < root::Rooted < ::std::os::raw::c_int > > (), 4usize, - concat!("Alignment of template specialization: ", stringify!(root::Rooted < - ::std::os::raw::c_int >)) + ::std::mem::align_of::>(), + 4usize, + concat!( + "Alignment of template specialization: ", + stringify!(root::Rooted < ::std::os::raw::c_int >), + ), ); } #[test] fn __bindgen_test_layout_Rooted_open0_AutoValueVector_Alias_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < root::Rooted < root::AutoValueVector_Alias > > (), - 4usize, concat!("Size of template specialization: ", stringify!(root::Rooted - < root::AutoValueVector_Alias >)) + ::std::mem::size_of::>(), + 4usize, + concat!( + "Size of template specialization: ", + stringify!(root::Rooted < root::AutoValueVector_Alias >), + ), ); assert_eq!( - ::std::mem::align_of:: < root::Rooted < root::AutoValueVector_Alias > > (), - 4usize, concat!("Alignment of template specialization: ", - stringify!(root::Rooted < root::AutoValueVector_Alias >)) + ::std::mem::align_of::>(), + 4usize, + concat!( + "Alignment of template specialization: ", + stringify!(root::Rooted < root::AutoValueVector_Alias >), + ), ); } } diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/mangling-win32.rs b/bindgen-tests/tests/expectations/tests/libclang-5/mangling-win32.rs index c3185060a4..34efb92461 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-5/mangling-win32.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-5/mangling-win32.rs @@ -14,11 +14,14 @@ extern "C" { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo)), ); assert_eq!( - ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", - stringify!(Foo)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)), ); } extern "fastcall" { diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/partial-specialization-and-inheritance.rs b/bindgen-tests/tests/expectations/tests/libclang-5/partial-specialization-and-inheritance.rs index b35befce18..3ba3a82aa3 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-5/partial-specialization-and-inheritance.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-5/partial-specialization-and-inheritance.rs @@ -21,11 +21,13 @@ extern "C" { #[test] fn bindgen_test_layout_Usage() { assert_eq!( - ::std::mem::size_of:: < Usage > (), 1usize, concat!("Size of: ", - stringify!(Usage)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Usage)), ); assert_eq!( - ::std::mem::align_of:: < Usage > (), 1usize, concat!("Alignment of ", - stringify!(Usage)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Usage)), ); } diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/type_alias_template_specialized.rs b/bindgen-tests/tests/expectations/tests/libclang-5/type_alias_template_specialized.rs index 0483cdaf75..d585a857d9 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-5/type_alias_template_specialized.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-5/type_alias_template_specialized.rs @@ -9,16 +9,19 @@ fn bindgen_test_layout_Rooted() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < Rooted > (), 4usize, concat!("Size of: ", - stringify!(Rooted)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Rooted)), ); assert_eq!( - ::std::mem::align_of:: < Rooted > (), 4usize, concat!("Alignment of ", - stringify!(Rooted)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Rooted)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).ptr) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Rooted), "::", stringify!(ptr)) + unsafe { ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Rooted), "::", stringify!(ptr)), ); } impl Default for Rooted { @@ -35,13 +38,19 @@ pub type MaybeWrapped = a; #[test] fn __bindgen_test_layout_MaybeWrapped_open0_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < MaybeWrapped < ::std::os::raw::c_int > > (), 4usize, - concat!("Size of template specialization: ", stringify!(MaybeWrapped < - ::std::os::raw::c_int >)) + ::std::mem::size_of::>(), + 4usize, + concat!( + "Size of template specialization: ", + stringify!(MaybeWrapped < ::std::os::raw::c_int >), + ), ); assert_eq!( - ::std::mem::align_of:: < MaybeWrapped < ::std::os::raw::c_int > > (), 4usize, - concat!("Alignment of template specialization: ", stringify!(MaybeWrapped < - ::std::os::raw::c_int >)) + ::std::mem::align_of::>(), + 4usize, + concat!( + "Alignment of template specialization: ", + stringify!(MaybeWrapped < ::std::os::raw::c_int >), + ), ); } diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/auto.rs b/bindgen-tests/tests/expectations/tests/libclang-9/auto.rs index acf81c26d6..340bc670dc 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/auto.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/auto.rs @@ -8,11 +8,14 @@ pub const Foo_kFoo: bool = true; #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo)), ); assert_eq!( - ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", - stringify!(Foo)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)), ); } #[repr(C)] diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/call-conv-field.rs b/bindgen-tests/tests/expectations/tests/libclang-9/call-conv-field.rs index 8f99ebc3a4..e3179543fc 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/call-conv-field.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/call-conv-field.rs @@ -15,22 +15,34 @@ fn bindgen_test_layout_JNINativeInterface_() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < JNINativeInterface_ > (), 16usize, concat!("Size of: ", - stringify!(JNINativeInterface_)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(JNINativeInterface_)), ); assert_eq!( - ::std::mem::align_of:: < JNINativeInterface_ > (), 8usize, - concat!("Alignment of ", stringify!(JNINativeInterface_)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(JNINativeInterface_)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).GetVersion) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(JNINativeInterface_), "::", - stringify!(GetVersion)) + unsafe { ::std::ptr::addr_of!((*ptr).GetVersion) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(JNINativeInterface_), + "::", + stringify!(GetVersion), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).__hack) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(JNINativeInterface_), "::", - stringify!(__hack)) + unsafe { ::std::ptr::addr_of!((*ptr).__hack) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(JNINativeInterface_), + "::", + stringify!(__hack), + ), ); } extern "stdcall" { diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/class.rs b/bindgen-tests/tests/expectations/tests/libclang-9/class.rs index d794141c06..19668a73dd 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/class.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/class.rs @@ -39,19 +39,21 @@ pub struct C { 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, concat!("Size of: ", stringify!(C))); assert_eq!( - ::std::mem::size_of:: < C > (), 40usize, concat!("Size of: ", stringify!(C)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(C)), ); assert_eq!( - ::std::mem::align_of:: < C > (), 4usize, concat!("Alignment of ", stringify!(C)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(a)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(a)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).big_array) as usize - ptr as usize }, - 4usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(big_array)) + unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(big_array)), ); } impl Default for C { @@ -74,27 +76,46 @@ 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:: < C_with_zero_length_array > (), 40usize, - concat!("Size of: ", stringify!(C_with_zero_length_array)) + ::std::mem::size_of::(), + 40usize, + concat!("Size of: ", stringify!(C_with_zero_length_array)), ); assert_eq!( - ::std::mem::align_of:: < C_with_zero_length_array > (), 4usize, - concat!("Alignment of ", stringify!(C_with_zero_length_array)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(C_with_zero_length_array)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(C_with_zero_length_array), "::", - stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array), + "::", + stringify!(a), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).big_array) as usize - ptr as usize }, - 4usize, concat!("Offset of field: ", stringify!(C_with_zero_length_array), "::", - stringify!(big_array)) + unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array), + "::", + stringify!(big_array), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).zero_length_array) as usize - ptr as usize - }, 37usize, concat!("Offset of field: ", stringify!(C_with_zero_length_array), - "::", stringify!(zero_length_array)) + unsafe { + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize + }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array), + "::", + stringify!(zero_length_array), + ), ); } impl Default for C_with_zero_length_array { @@ -117,22 +138,36 @@ 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:: < C_with_zero_length_array_2 > (), 4usize, - concat!("Size of: ", stringify!(C_with_zero_length_array_2)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(C_with_zero_length_array_2)), ); assert_eq!( - ::std::mem::align_of:: < C_with_zero_length_array_2 > (), 4usize, - concat!("Alignment of ", stringify!(C_with_zero_length_array_2)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(C_with_zero_length_array_2)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(C_with_zero_length_array_2), "::", - stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_2), + "::", + stringify!(a), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).zero_length_array) as usize - ptr as usize - }, 4usize, concat!("Offset of field: ", stringify!(C_with_zero_length_array_2), - "::", stringify!(zero_length_array)) + unsafe { + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_2), + "::", + stringify!(zero_length_array), + ), ); } #[repr(C)] @@ -146,27 +181,44 @@ 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:: < C_with_incomplete_array > (), 40usize, - concat!("Size of: ", stringify!(C_with_incomplete_array)) + ::std::mem::size_of::(), + 40usize, + concat!("Size of: ", stringify!(C_with_incomplete_array)), ); assert_eq!( - ::std::mem::align_of:: < C_with_incomplete_array > (), 4usize, - concat!("Alignment of ", stringify!(C_with_incomplete_array)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(C_with_incomplete_array)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(C_with_incomplete_array), "::", - stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array), + "::", + stringify!(a), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).big_array) as usize - ptr as usize }, - 4usize, concat!("Offset of field: ", stringify!(C_with_incomplete_array), "::", - stringify!(big_array)) + unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array), + "::", + stringify!(big_array), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).incomplete_array) as usize - ptr as usize - }, 37usize, concat!("Offset of field: ", stringify!(C_with_incomplete_array), - "::", stringify!(incomplete_array)) + unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array), + "::", + stringify!(incomplete_array), + ), ); } impl Default for C_with_incomplete_array { @@ -189,22 +241,34 @@ 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:: < C_with_incomplete_array_2 > (), 4usize, - concat!("Size of: ", stringify!(C_with_incomplete_array_2)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(C_with_incomplete_array_2)), ); assert_eq!( - ::std::mem::align_of:: < C_with_incomplete_array_2 > (), 4usize, - concat!("Alignment of ", stringify!(C_with_incomplete_array_2)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(C_with_incomplete_array_2)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(C_with_incomplete_array_2), "::", - stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array_2), + "::", + stringify!(a), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).incomplete_array) as usize - ptr as usize - }, 4usize, concat!("Offset of field: ", stringify!(C_with_incomplete_array_2), - "::", stringify!(incomplete_array)) + unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array_2), + "::", + stringify!(incomplete_array), + ), ); } #[repr(C)] @@ -221,37 +285,59 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { > = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < C_with_zero_length_array_and_incomplete_array > (), - 40usize, concat!("Size of: ", - stringify!(C_with_zero_length_array_and_incomplete_array)) - ); - assert_eq!( - ::std::mem::align_of:: < C_with_zero_length_array_and_incomplete_array > (), - 4usize, concat!("Alignment of ", - stringify!(C_with_zero_length_array_and_incomplete_array)) + ::std::mem::size_of::(), + 40usize, + concat!("Size of: ", stringify!(C_with_zero_length_array_and_incomplete_array)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), "::", stringify!(a)) + ::std::mem::align_of::(), + 4usize, + concat!( + "Alignment of ", + stringify!(C_with_zero_length_array_and_incomplete_array), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).big_array) as usize - ptr as usize }, - 4usize, concat!("Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), "::", - stringify!(big_array)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(a), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).zero_length_array) as usize - ptr as usize - }, 37usize, concat!("Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), "::", - stringify!(zero_length_array)) + unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(big_array), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).incomplete_array) as usize - ptr as usize - }, 37usize, concat!("Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), "::", - stringify!(incomplete_array)) + unsafe { + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize + }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(zero_length_array), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(incomplete_array), + ), ); } impl Default for C_with_zero_length_array_and_incomplete_array { @@ -277,31 +363,49 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { > = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < C_with_zero_length_array_and_incomplete_array_2 > (), - 4usize, concat!("Size of: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(C_with_zero_length_array_and_incomplete_array_2)), ); assert_eq!( - ::std::mem::align_of:: < C_with_zero_length_array_and_incomplete_array_2 > (), - 4usize, concat!("Alignment of ", - stringify!(C_with_zero_length_array_and_incomplete_array_2)) + ::std::mem::align_of::(), + 4usize, + concat!( + "Alignment of ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), + "::", + stringify!(a), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).zero_length_array) as usize - ptr as usize - }, 4usize, concat!("Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), "::", - stringify!(zero_length_array)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).incomplete_array) as usize - ptr as usize - }, 4usize, concat!("Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), "::", - stringify!(incomplete_array)) + unsafe { + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), + "::", + stringify!(zero_length_array), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), + "::", + stringify!(incomplete_array), + ), ); } #[repr(C)] @@ -314,16 +418,19 @@ 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:: < WithDtor > (), 4usize, concat!("Size of: ", - stringify!(WithDtor)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(WithDtor)), ); assert_eq!( - ::std::mem::align_of:: < WithDtor > (), 4usize, concat!("Alignment of ", - stringify!(WithDtor)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(WithDtor)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(WithDtor), "::", stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(WithDtor), "::", stringify!(b)), ); } #[repr(C)] @@ -336,22 +443,34 @@ 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:: < IncompleteArrayNonCopiable > (), 8usize, - concat!("Size of: ", stringify!(IncompleteArrayNonCopiable)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(IncompleteArrayNonCopiable)), ); assert_eq!( - ::std::mem::align_of:: < IncompleteArrayNonCopiable > (), 8usize, - concat!("Alignment of ", stringify!(IncompleteArrayNonCopiable)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(IncompleteArrayNonCopiable)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).whatever) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(IncompleteArrayNonCopiable), - "::", stringify!(whatever)) + unsafe { ::std::ptr::addr_of!((*ptr).whatever) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(IncompleteArrayNonCopiable), + "::", + stringify!(whatever), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).incomplete_array) as usize - ptr as usize - }, 8usize, concat!("Offset of field: ", stringify!(IncompleteArrayNonCopiable), - "::", stringify!(incomplete_array)) + unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(IncompleteArrayNonCopiable), + "::", + stringify!(incomplete_array), + ), ); } impl Default for IncompleteArrayNonCopiable { @@ -374,20 +493,24 @@ 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:: < Union > (), 4usize, concat!("Size of: ", - stringify!(Union)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Union)), ); assert_eq!( - ::std::mem::align_of:: < Union > (), 4usize, concat!("Alignment of ", - stringify!(Union)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Union)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).d) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Union), "::", stringify!(d)) + unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Union), "::", stringify!(d)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).i) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Union), "::", stringify!(i)) + unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Union), "::", stringify!(i)), ); } impl Default for Union { @@ -409,16 +532,19 @@ 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:: < WithUnion > (), 4usize, concat!("Size of: ", - stringify!(WithUnion)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(WithUnion)), ); assert_eq!( - ::std::mem::align_of:: < WithUnion > (), 4usize, concat!("Alignment of ", - stringify!(WithUnion)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(WithUnion)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).data) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(WithUnion), "::", stringify!(data)) + unsafe { ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(WithUnion), "::", stringify!(data)), ); } impl Default for WithUnion { @@ -438,12 +564,14 @@ pub struct RealAbstractionWithTonsOfMethods { #[test] fn bindgen_test_layout_RealAbstractionWithTonsOfMethods() { assert_eq!( - ::std::mem::size_of:: < RealAbstractionWithTonsOfMethods > (), 1usize, - concat!("Size of: ", stringify!(RealAbstractionWithTonsOfMethods)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(RealAbstractionWithTonsOfMethods)), ); assert_eq!( - ::std::mem::align_of:: < RealAbstractionWithTonsOfMethods > (), 1usize, - concat!("Alignment of ", stringify!(RealAbstractionWithTonsOfMethods)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(RealAbstractionWithTonsOfMethods)), ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/class_1_0.rs b/bindgen-tests/tests/expectations/tests/libclang-9/class_1_0.rs index 5ea68ca3fc..9796b592d4 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/class_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/class_1_0.rs @@ -82,19 +82,21 @@ pub struct C { 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, concat!("Size of: ", stringify!(C))); assert_eq!( - ::std::mem::size_of:: < C > (), 40usize, concat!("Size of: ", stringify!(C)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(C)), ); assert_eq!( - ::std::mem::align_of:: < C > (), 4usize, concat!("Alignment of ", stringify!(C)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(a)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(a)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).big_array) as usize - ptr as usize }, - 4usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(big_array)) + unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(big_array)), ); } impl Clone for C { @@ -127,27 +129,46 @@ 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:: < C_with_zero_length_array > (), 40usize, - concat!("Size of: ", stringify!(C_with_zero_length_array)) + ::std::mem::size_of::(), + 40usize, + concat!("Size of: ", stringify!(C_with_zero_length_array)), ); assert_eq!( - ::std::mem::align_of:: < C_with_zero_length_array > (), 4usize, - concat!("Alignment of ", stringify!(C_with_zero_length_array)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(C_with_zero_length_array)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(C_with_zero_length_array), "::", - stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array), + "::", + stringify!(a), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).big_array) as usize - ptr as usize }, - 4usize, concat!("Offset of field: ", stringify!(C_with_zero_length_array), "::", - stringify!(big_array)) + unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array), + "::", + stringify!(big_array), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).zero_length_array) as usize - ptr as usize - }, 37usize, concat!("Offset of field: ", stringify!(C_with_zero_length_array), - "::", stringify!(zero_length_array)) + unsafe { + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize + }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array), + "::", + stringify!(zero_length_array), + ), ); } impl Default for C_with_zero_length_array { @@ -170,22 +191,36 @@ 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:: < C_with_zero_length_array_2 > (), 4usize, - concat!("Size of: ", stringify!(C_with_zero_length_array_2)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(C_with_zero_length_array_2)), ); assert_eq!( - ::std::mem::align_of:: < C_with_zero_length_array_2 > (), 4usize, - concat!("Alignment of ", stringify!(C_with_zero_length_array_2)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(C_with_zero_length_array_2)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(C_with_zero_length_array_2), "::", - stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_2), + "::", + stringify!(a), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).zero_length_array) as usize - ptr as usize - }, 4usize, concat!("Offset of field: ", stringify!(C_with_zero_length_array_2), - "::", stringify!(zero_length_array)) + unsafe { + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_2), + "::", + stringify!(zero_length_array), + ), ); } #[repr(C)] @@ -199,27 +234,44 @@ 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:: < C_with_incomplete_array > (), 40usize, - concat!("Size of: ", stringify!(C_with_incomplete_array)) + ::std::mem::size_of::(), + 40usize, + concat!("Size of: ", stringify!(C_with_incomplete_array)), ); assert_eq!( - ::std::mem::align_of:: < C_with_incomplete_array > (), 4usize, - concat!("Alignment of ", stringify!(C_with_incomplete_array)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(C_with_incomplete_array)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(C_with_incomplete_array), "::", - stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array), + "::", + stringify!(a), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).big_array) as usize - ptr as usize }, - 4usize, concat!("Offset of field: ", stringify!(C_with_incomplete_array), "::", - stringify!(big_array)) + unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array), + "::", + stringify!(big_array), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).incomplete_array) as usize - ptr as usize - }, 37usize, concat!("Offset of field: ", stringify!(C_with_incomplete_array), - "::", stringify!(incomplete_array)) + unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array), + "::", + stringify!(incomplete_array), + ), ); } impl Default for C_with_incomplete_array { @@ -242,22 +294,34 @@ 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:: < C_with_incomplete_array_2 > (), 4usize, - concat!("Size of: ", stringify!(C_with_incomplete_array_2)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(C_with_incomplete_array_2)), ); assert_eq!( - ::std::mem::align_of:: < C_with_incomplete_array_2 > (), 4usize, - concat!("Alignment of ", stringify!(C_with_incomplete_array_2)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(C_with_incomplete_array_2)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(C_with_incomplete_array_2), "::", - stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array_2), + "::", + stringify!(a), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).incomplete_array) as usize - ptr as usize - }, 4usize, concat!("Offset of field: ", stringify!(C_with_incomplete_array_2), - "::", stringify!(incomplete_array)) + unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array_2), + "::", + stringify!(incomplete_array), + ), ); } #[repr(C)] @@ -274,37 +338,59 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { > = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < C_with_zero_length_array_and_incomplete_array > (), - 40usize, concat!("Size of: ", - stringify!(C_with_zero_length_array_and_incomplete_array)) - ); - assert_eq!( - ::std::mem::align_of:: < C_with_zero_length_array_and_incomplete_array > (), - 4usize, concat!("Alignment of ", - stringify!(C_with_zero_length_array_and_incomplete_array)) + ::std::mem::size_of::(), + 40usize, + concat!("Size of: ", stringify!(C_with_zero_length_array_and_incomplete_array)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), "::", stringify!(a)) + ::std::mem::align_of::(), + 4usize, + concat!( + "Alignment of ", + stringify!(C_with_zero_length_array_and_incomplete_array), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).big_array) as usize - ptr as usize }, - 4usize, concat!("Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), "::", - stringify!(big_array)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(a), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).zero_length_array) as usize - ptr as usize - }, 37usize, concat!("Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), "::", - stringify!(zero_length_array)) + unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(big_array), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).incomplete_array) as usize - ptr as usize - }, 37usize, concat!("Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), "::", - stringify!(incomplete_array)) + unsafe { + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize + }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(zero_length_array), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(incomplete_array), + ), ); } impl Default for C_with_zero_length_array_and_incomplete_array { @@ -330,31 +416,49 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { > = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < C_with_zero_length_array_and_incomplete_array_2 > (), - 4usize, concat!("Size of: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(C_with_zero_length_array_and_incomplete_array_2)), ); assert_eq!( - ::std::mem::align_of:: < C_with_zero_length_array_and_incomplete_array_2 > (), - 4usize, concat!("Alignment of ", - stringify!(C_with_zero_length_array_and_incomplete_array_2)) + ::std::mem::align_of::(), + 4usize, + concat!( + "Alignment of ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), + "::", + stringify!(a), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).zero_length_array) as usize - ptr as usize - }, 4usize, concat!("Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), "::", - stringify!(zero_length_array)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).incomplete_array) as usize - ptr as usize - }, 4usize, concat!("Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), "::", - stringify!(incomplete_array)) + unsafe { + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), + "::", + stringify!(zero_length_array), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), + "::", + stringify!(incomplete_array), + ), ); } #[repr(C)] @@ -367,16 +471,19 @@ 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:: < WithDtor > (), 4usize, concat!("Size of: ", - stringify!(WithDtor)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(WithDtor)), ); assert_eq!( - ::std::mem::align_of:: < WithDtor > (), 4usize, concat!("Alignment of ", - stringify!(WithDtor)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(WithDtor)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(WithDtor), "::", stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(WithDtor), "::", stringify!(b)), ); } #[repr(C)] @@ -389,22 +496,34 @@ 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:: < IncompleteArrayNonCopiable > (), 8usize, - concat!("Size of: ", stringify!(IncompleteArrayNonCopiable)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(IncompleteArrayNonCopiable)), ); assert_eq!( - ::std::mem::align_of:: < IncompleteArrayNonCopiable > (), 8usize, - concat!("Alignment of ", stringify!(IncompleteArrayNonCopiable)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(IncompleteArrayNonCopiable)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).whatever) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(IncompleteArrayNonCopiable), - "::", stringify!(whatever)) + unsafe { ::std::ptr::addr_of!((*ptr).whatever) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(IncompleteArrayNonCopiable), + "::", + stringify!(whatever), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).incomplete_array) as usize - ptr as usize - }, 8usize, concat!("Offset of field: ", stringify!(IncompleteArrayNonCopiable), - "::", stringify!(incomplete_array)) + unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(IncompleteArrayNonCopiable), + "::", + stringify!(incomplete_array), + ), ); } impl Default for IncompleteArrayNonCopiable { @@ -428,20 +547,24 @@ 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:: < Union > (), 4usize, concat!("Size of: ", - stringify!(Union)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Union)), ); assert_eq!( - ::std::mem::align_of:: < Union > (), 4usize, concat!("Alignment of ", - stringify!(Union)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Union)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).d) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Union), "::", stringify!(d)) + unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Union), "::", stringify!(d)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).i) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Union), "::", stringify!(i)) + unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Union), "::", stringify!(i)), ); } impl Clone for Union { @@ -459,16 +582,19 @@ 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:: < WithUnion > (), 4usize, concat!("Size of: ", - stringify!(WithUnion)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(WithUnion)), ); assert_eq!( - ::std::mem::align_of:: < WithUnion > (), 4usize, concat!("Alignment of ", - stringify!(WithUnion)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(WithUnion)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).data) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(WithUnion), "::", stringify!(data)) + unsafe { ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(WithUnion), "::", stringify!(data)), ); } impl Clone for WithUnion { @@ -484,12 +610,14 @@ pub struct RealAbstractionWithTonsOfMethods { #[test] fn bindgen_test_layout_RealAbstractionWithTonsOfMethods() { assert_eq!( - ::std::mem::size_of:: < RealAbstractionWithTonsOfMethods > (), 1usize, - concat!("Size of: ", stringify!(RealAbstractionWithTonsOfMethods)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(RealAbstractionWithTonsOfMethods)), ); assert_eq!( - ::std::mem::align_of:: < RealAbstractionWithTonsOfMethods > (), 1usize, - concat!("Alignment of ", stringify!(RealAbstractionWithTonsOfMethods)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(RealAbstractionWithTonsOfMethods)), ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/const_bool.rs b/bindgen-tests/tests/expectations/tests/libclang-9/const_bool.rs index d08e431607..97cb7ec691 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/const_bool.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/const_bool.rs @@ -8,11 +8,11 @@ pub struct A { pub const A_k: bool = false; #[test] fn bindgen_test_layout_A() { + assert_eq!(::std::mem::size_of::(), 1usize, concat!("Size of: ", stringify!(A))); assert_eq!( - ::std::mem::size_of:: < A > (), 1usize, concat!("Size of: ", stringify!(A)) - ); - assert_eq!( - ::std::mem::align_of:: < A > (), 1usize, concat!("Alignment of ", stringify!(A)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(A)), ); } pub type foo = bool; diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs b/bindgen-tests/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs index effbaf6e9c..d1b4c9004a 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs @@ -40,20 +40,31 @@ fn bindgen_test_layout_test() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < test > (), 4usize, concat!("Size of: ", stringify!(test)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(test)), ); assert_eq!( - ::std::mem::align_of:: < test > (), 4usize, concat!("Alignment of ", - stringify!(test)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(test)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(test), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(test), "::", stringify!(a)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).zero_length_array) as usize - ptr as usize - }, 4usize, concat!("Offset of field: ", stringify!(test), "::", - stringify!(zero_length_array)) + unsafe { + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(test), + "::", + stringify!(zero_length_array), + ), ); } #[repr(C)] @@ -67,21 +78,29 @@ fn bindgen_test_layout_test2() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < test2 > (), 4usize, concat!("Size of: ", - stringify!(test2)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(test2)), ); assert_eq!( - ::std::mem::align_of:: < test2 > (), 4usize, concat!("Alignment of ", - stringify!(test2)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(test2)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(test2), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(test2), "::", stringify!(a)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).incomplete_array) as usize - ptr as usize - }, 4usize, concat!("Offset of field: ", stringify!(test2), "::", - stringify!(incomplete_array)) + unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(test2), + "::", + stringify!(incomplete_array), + ), ); } #[repr(C)] @@ -96,25 +115,40 @@ fn bindgen_test_layout_test3() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < test3 > (), 4usize, concat!("Size of: ", - stringify!(test3)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(test3)), ); assert_eq!( - ::std::mem::align_of:: < test3 > (), 4usize, concat!("Alignment of ", - stringify!(test3)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(test3)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(test3), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(test3), "::", stringify!(a)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).zero_length_array) as usize - ptr as usize - }, 4usize, concat!("Offset of field: ", stringify!(test3), "::", - stringify!(zero_length_array)) + unsafe { + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(test3), + "::", + stringify!(zero_length_array), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).incomplete_array) as usize - ptr as usize - }, 4usize, concat!("Offset of field: ", stringify!(test3), "::", - stringify!(incomplete_array)) + unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(test3), + "::", + stringify!(incomplete_array), + ), ); } diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/incomplete-array-padding.rs b/bindgen-tests/tests/expectations/tests/libclang-9/incomplete-array-padding.rs index 353f113e69..c8038e1f40 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/incomplete-array-padding.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/incomplete-array-padding.rs @@ -49,7 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -69,7 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -125,15 +125,19 @@ 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:: < foo > (), 8usize, concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(foo)), ); assert_eq!( - ::std::mem::align_of:: < foo > (), 8usize, concat!("Alignment of ", - stringify!(foo)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 8usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)), ); } impl Default for foo { diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs b/bindgen-tests/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs index 3571903358..520b3b0ecd 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs @@ -47,17 +47,24 @@ fn bindgen_test_layout_rte_ring_prod() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < rte_ring_prod > (), 4usize, concat!("Size of: ", - stringify!(rte_ring_prod)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(rte_ring_prod)), ); assert_eq!( - ::std::mem::align_of:: < rte_ring_prod > (), 4usize, concat!("Alignment of ", - stringify!(rte_ring_prod)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_ring_prod)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).watermark) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_ring_prod), "::", - stringify!(watermark)) + unsafe { ::std::ptr::addr_of!((*ptr).watermark) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ring_prod), + "::", + stringify!(watermark), + ), ); } #[repr(C)] @@ -70,17 +77,24 @@ fn bindgen_test_layout_rte_ring_cons() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < rte_ring_cons > (), 4usize, concat!("Size of: ", - stringify!(rte_ring_cons)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(rte_ring_cons)), ); assert_eq!( - ::std::mem::align_of:: < rte_ring_cons > (), 4usize, concat!("Alignment of ", - stringify!(rte_ring_cons)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(rte_ring_cons)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).sc_dequeue) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_ring_cons), "::", - stringify!(sc_dequeue)) + unsafe { ::std::ptr::addr_of!((*ptr).sc_dequeue) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_ring_cons), + "::", + stringify!(sc_dequeue), + ), ); } #[test] @@ -88,28 +102,34 @@ fn bindgen_test_layout_rte_ring() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < rte_ring > (), 16usize, concat!("Size of: ", - stringify!(rte_ring)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(rte_ring)), ); assert_eq!( - ::std::mem::align_of:: < rte_ring > (), 8usize, concat!("Alignment of ", - stringify!(rte_ring)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(rte_ring)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).memzone) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_ring), "::", stringify!(memzone)) + unsafe { ::std::ptr::addr_of!((*ptr).memzone) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(rte_ring), "::", stringify!(memzone)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).prod) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(rte_ring), "::", stringify!(prod)) + unsafe { ::std::ptr::addr_of!((*ptr).prod) as usize - ptr as usize }, + 8usize, + concat!("Offset of field: ", stringify!(rte_ring), "::", stringify!(prod)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).cons) as usize - ptr as usize }, 12usize, - concat!("Offset of field: ", stringify!(rte_ring), "::", stringify!(cons)) + unsafe { ::std::ptr::addr_of!((*ptr).cons) as usize - ptr as usize }, + 12usize, + concat!("Offset of field: ", stringify!(rte_ring), "::", stringify!(cons)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).ring) as usize - ptr as usize }, 16usize, - concat!("Offset of field: ", stringify!(rte_ring), "::", stringify!(ring)) + unsafe { ::std::ptr::addr_of!((*ptr).ring) as usize - ptr as usize }, + 16usize, + concat!("Offset of field: ", stringify!(rte_ring), "::", stringify!(ring)), ); } impl Default for rte_ring { diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/issue-769-bad-instantiation-test.rs b/bindgen-tests/tests/expectations/tests/libclang-9/issue-769-bad-instantiation-test.rs index 0acb9ad8b8..ef830ca69e 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/issue-769-bad-instantiation-test.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/issue-769-bad-instantiation-test.rs @@ -22,27 +22,39 @@ pub mod root { #[test] fn __bindgen_test_layout_Rooted_open0_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < root::Rooted < ::std::os::raw::c_int > > (), 4usize, - concat!("Size of template specialization: ", stringify!(root::Rooted < - ::std::os::raw::c_int >)) + ::std::mem::size_of::>(), + 4usize, + concat!( + "Size of template specialization: ", + stringify!(root::Rooted < ::std::os::raw::c_int >), + ), ); assert_eq!( - ::std::mem::align_of:: < root::Rooted < ::std::os::raw::c_int > > (), 4usize, - concat!("Alignment of template specialization: ", stringify!(root::Rooted < - ::std::os::raw::c_int >)) + ::std::mem::align_of::>(), + 4usize, + concat!( + "Alignment of template specialization: ", + stringify!(root::Rooted < ::std::os::raw::c_int >), + ), ); } #[test] fn __bindgen_test_layout_Rooted_open0_AutoValueVector_Alias_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < root::Rooted < root::AutoValueVector_Alias > > (), - 4usize, concat!("Size of template specialization: ", stringify!(root::Rooted - < root::AutoValueVector_Alias >)) + ::std::mem::size_of::>(), + 4usize, + concat!( + "Size of template specialization: ", + stringify!(root::Rooted < root::AutoValueVector_Alias >), + ), ); assert_eq!( - ::std::mem::align_of:: < root::Rooted < root::AutoValueVector_Alias > > (), - 4usize, concat!("Alignment of template specialization: ", - stringify!(root::Rooted < root::AutoValueVector_Alias >)) + ::std::mem::align_of::>(), + 4usize, + concat!( + "Alignment of template specialization: ", + stringify!(root::Rooted < root::AutoValueVector_Alias >), + ), ); } } diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/layout_align.rs b/bindgen-tests/tests/expectations/tests/libclang-9/layout_align.rs index adb5574fbb..be77dc75d4 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/layout_align.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/layout_align.rs @@ -49,7 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -69,7 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -132,33 +132,44 @@ fn bindgen_test_layout_rte_kni_fifo() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < rte_kni_fifo > (), 16usize, concat!("Size of: ", - stringify!(rte_kni_fifo)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(rte_kni_fifo)), ); assert_eq!( - ::std::mem::align_of:: < rte_kni_fifo > (), 8usize, concat!("Alignment of ", - stringify!(rte_kni_fifo)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(rte_kni_fifo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).write) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_kni_fifo), "::", stringify!(write)) + unsafe { ::std::ptr::addr_of!((*ptr).write) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(rte_kni_fifo), "::", stringify!(write)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).read) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(rte_kni_fifo), "::", stringify!(read)) + unsafe { ::std::ptr::addr_of!((*ptr).read) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(rte_kni_fifo), "::", stringify!(read)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).len) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(rte_kni_fifo), "::", stringify!(len)) + unsafe { ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize }, + 8usize, + concat!("Offset of field: ", stringify!(rte_kni_fifo), "::", stringify!(len)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).elem_size) as usize - ptr as usize }, - 12usize, concat!("Offset of field: ", stringify!(rte_kni_fifo), "::", - stringify!(elem_size)) + unsafe { ::std::ptr::addr_of!((*ptr).elem_size) as usize - ptr as usize }, + 12usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_fifo), + "::", + stringify!(elem_size), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).buffer) as usize - ptr as usize }, 16usize, - concat!("Offset of field: ", stringify!(rte_kni_fifo), "::", stringify!(buffer)) + unsafe { ::std::ptr::addr_of!((*ptr).buffer) as usize - ptr as usize }, + 16usize, + concat!("Offset of field: ", stringify!(rte_kni_fifo), "::", stringify!(buffer)), ); } impl Default for rte_kni_fifo { @@ -185,17 +196,24 @@ fn bindgen_test_layout_rte_eth_link() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < rte_eth_link > (), 8usize, concat!("Size of: ", - stringify!(rte_eth_link)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(rte_eth_link)), ); assert_eq!( - ::std::mem::align_of:: < rte_eth_link > (), 8usize, concat!("Alignment of ", - stringify!(rte_eth_link)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(rte_eth_link)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).link_speed) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(rte_eth_link), "::", - stringify!(link_speed)) + unsafe { ::std::ptr::addr_of!((*ptr).link_speed) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(rte_eth_link), + "::", + stringify!(link_speed), + ), ); } impl rte_eth_link { diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/mangling-win32.rs b/bindgen-tests/tests/expectations/tests/libclang-9/mangling-win32.rs index c3185060a4..34efb92461 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/mangling-win32.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/mangling-win32.rs @@ -14,11 +14,14 @@ extern "C" { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo)), ); assert_eq!( - ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", - stringify!(Foo)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)), ); } extern "fastcall" { diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/partial-specialization-and-inheritance.rs b/bindgen-tests/tests/expectations/tests/libclang-9/partial-specialization-and-inheritance.rs index b35befce18..3ba3a82aa3 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/partial-specialization-and-inheritance.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/partial-specialization-and-inheritance.rs @@ -21,11 +21,13 @@ extern "C" { #[test] fn bindgen_test_layout_Usage() { assert_eq!( - ::std::mem::size_of:: < Usage > (), 1usize, concat!("Size of: ", - stringify!(Usage)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Usage)), ); assert_eq!( - ::std::mem::align_of:: < Usage > (), 1usize, concat!("Alignment of ", - stringify!(Usage)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Usage)), ); } diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/type_alias_template_specialized.rs b/bindgen-tests/tests/expectations/tests/libclang-9/type_alias_template_specialized.rs index 0483cdaf75..d585a857d9 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/type_alias_template_specialized.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/type_alias_template_specialized.rs @@ -9,16 +9,19 @@ fn bindgen_test_layout_Rooted() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < Rooted > (), 4usize, concat!("Size of: ", - stringify!(Rooted)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Rooted)), ); assert_eq!( - ::std::mem::align_of:: < Rooted > (), 4usize, concat!("Alignment of ", - stringify!(Rooted)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Rooted)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).ptr) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Rooted), "::", stringify!(ptr)) + unsafe { ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Rooted), "::", stringify!(ptr)), ); } impl Default for Rooted { @@ -35,13 +38,19 @@ pub type MaybeWrapped = a; #[test] fn __bindgen_test_layout_MaybeWrapped_open0_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < MaybeWrapped < ::std::os::raw::c_int > > (), 4usize, - concat!("Size of template specialization: ", stringify!(MaybeWrapped < - ::std::os::raw::c_int >)) + ::std::mem::size_of::>(), + 4usize, + concat!( + "Size of template specialization: ", + stringify!(MaybeWrapped < ::std::os::raw::c_int >), + ), ); assert_eq!( - ::std::mem::align_of:: < MaybeWrapped < ::std::os::raw::c_int > > (), 4usize, - concat!("Alignment of template specialization: ", stringify!(MaybeWrapped < - ::std::os::raw::c_int >)) + ::std::mem::align_of::>(), + 4usize, + concat!( + "Alignment of template specialization: ", + stringify!(MaybeWrapped < ::std::os::raw::c_int >), + ), ); } diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/zero-sized-array.rs b/bindgen-tests/tests/expectations/tests/libclang-9/zero-sized-array.rs index f6b8324f68..bc4b660029 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/zero-sized-array.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/zero-sized-array.rs @@ -40,16 +40,19 @@ fn bindgen_test_layout_ZeroSizedArray() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < ZeroSizedArray > (), 0usize, concat!("Size of: ", - stringify!(ZeroSizedArray)) + ::std::mem::size_of::(), + 0usize, + concat!("Size of: ", stringify!(ZeroSizedArray)), ); assert_eq!( - ::std::mem::align_of:: < ZeroSizedArray > (), 1usize, concat!("Alignment of ", - stringify!(ZeroSizedArray)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(ZeroSizedArray)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).arr) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(ZeroSizedArray), "::", stringify!(arr)) + unsafe { ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(ZeroSizedArray), "::", stringify!(arr)), ); } /// And nor should this get an `_address` field. @@ -63,17 +66,24 @@ fn bindgen_test_layout_ContainsZeroSizedArray() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < ContainsZeroSizedArray > (), 0usize, concat!("Size of: ", - stringify!(ContainsZeroSizedArray)) + ::std::mem::size_of::(), + 0usize, + concat!("Size of: ", stringify!(ContainsZeroSizedArray)), ); assert_eq!( - ::std::mem::align_of:: < ContainsZeroSizedArray > (), 1usize, - concat!("Alignment of ", stringify!(ContainsZeroSizedArray)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(ContainsZeroSizedArray)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).zsa) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(ContainsZeroSizedArray), "::", - stringify!(zsa)) + unsafe { ::std::ptr::addr_of!((*ptr).zsa) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ContainsZeroSizedArray), + "::", + stringify!(zsa), + ), ); } /** Inheriting from ZeroSizedArray shouldn't cause an `_address` to be inserted @@ -86,12 +96,14 @@ pub struct InheritsZeroSizedArray { #[test] fn bindgen_test_layout_InheritsZeroSizedArray() { assert_eq!( - ::std::mem::size_of:: < InheritsZeroSizedArray > (), 0usize, concat!("Size of: ", - stringify!(InheritsZeroSizedArray)) + ::std::mem::size_of::(), + 0usize, + concat!("Size of: ", stringify!(InheritsZeroSizedArray)), ); assert_eq!( - ::std::mem::align_of:: < InheritsZeroSizedArray > (), 1usize, - concat!("Alignment of ", stringify!(InheritsZeroSizedArray)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(InheritsZeroSizedArray)), ); } /// And this should not get an `_address` field either. @@ -105,17 +117,24 @@ fn bindgen_test_layout_DynamicallySizedArray() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < DynamicallySizedArray > (), 0usize, concat!("Size of: ", - stringify!(DynamicallySizedArray)) + ::std::mem::size_of::(), + 0usize, + concat!("Size of: ", stringify!(DynamicallySizedArray)), ); assert_eq!( - ::std::mem::align_of:: < DynamicallySizedArray > (), 1usize, - concat!("Alignment of ", stringify!(DynamicallySizedArray)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(DynamicallySizedArray)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).arr) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(DynamicallySizedArray), "::", - stringify!(arr)) + unsafe { ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(DynamicallySizedArray), + "::", + stringify!(arr), + ), ); } /// No `_address` field here either. @@ -129,16 +148,23 @@ fn bindgen_test_layout_ContainsDynamicallySizedArray() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < ContainsDynamicallySizedArray > (), 0usize, - concat!("Size of: ", stringify!(ContainsDynamicallySizedArray)) + ::std::mem::size_of::(), + 0usize, + concat!("Size of: ", stringify!(ContainsDynamicallySizedArray)), ); assert_eq!( - ::std::mem::align_of:: < ContainsDynamicallySizedArray > (), 1usize, - concat!("Alignment of ", stringify!(ContainsDynamicallySizedArray)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(ContainsDynamicallySizedArray)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).dsa) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(ContainsDynamicallySizedArray), "::", - stringify!(dsa)) + unsafe { ::std::ptr::addr_of!((*ptr).dsa) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ContainsDynamicallySizedArray), + "::", + stringify!(dsa), + ), ); } diff --git a/bindgen-tests/tests/expectations/tests/long_double.rs b/bindgen-tests/tests/expectations/tests/long_double.rs index c33f6ede45..b362787f9a 100644 --- a/bindgen-tests/tests/expectations/tests/long_double.rs +++ b/bindgen-tests/tests/expectations/tests/long_double.rs @@ -10,14 +10,18 @@ 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:: < foo > (), 16usize, concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(foo)), ); assert_eq!( - ::std::mem::align_of:: < foo > (), 16usize, concat!("Alignment of ", - stringify!(foo)) + ::std::mem::align_of::(), + 16usize, + concat!("Alignment of ", stringify!(foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)), ); } diff --git a/bindgen-tests/tests/expectations/tests/mangling-linux32.rs b/bindgen-tests/tests/expectations/tests/mangling-linux32.rs index 6b2a5e076d..1672f2cf65 100644 --- a/bindgen-tests/tests/expectations/tests/mangling-linux32.rs +++ b/bindgen-tests/tests/expectations/tests/mangling-linux32.rs @@ -14,10 +14,13 @@ extern "C" { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo)), ); assert_eq!( - ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", - stringify!(Foo)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)), ); } diff --git a/bindgen-tests/tests/expectations/tests/mangling-linux64.rs b/bindgen-tests/tests/expectations/tests/mangling-linux64.rs index 6b2a5e076d..1672f2cf65 100644 --- a/bindgen-tests/tests/expectations/tests/mangling-linux64.rs +++ b/bindgen-tests/tests/expectations/tests/mangling-linux64.rs @@ -14,10 +14,13 @@ extern "C" { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo)), ); assert_eq!( - ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", - stringify!(Foo)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)), ); } diff --git a/bindgen-tests/tests/expectations/tests/mangling-macos.rs b/bindgen-tests/tests/expectations/tests/mangling-macos.rs index 6f59e943f7..b3c236bb0b 100644 --- a/bindgen-tests/tests/expectations/tests/mangling-macos.rs +++ b/bindgen-tests/tests/expectations/tests/mangling-macos.rs @@ -14,10 +14,13 @@ extern "C" { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo)), ); assert_eq!( - ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", - stringify!(Foo)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)), ); } diff --git a/bindgen-tests/tests/expectations/tests/mangling-win64.rs b/bindgen-tests/tests/expectations/tests/mangling-win64.rs index 232fe582a1..99224e54dc 100644 --- a/bindgen-tests/tests/expectations/tests/mangling-win64.rs +++ b/bindgen-tests/tests/expectations/tests/mangling-win64.rs @@ -14,10 +14,13 @@ extern "C" { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo)), ); assert_eq!( - ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", - stringify!(Foo)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)), ); } diff --git a/bindgen-tests/tests/expectations/tests/merge-extern-blocks.rs b/bindgen-tests/tests/expectations/tests/merge-extern-blocks.rs index cf1abdc789..5c4b8e02ae 100644 --- a/bindgen-tests/tests/expectations/tests/merge-extern-blocks.rs +++ b/bindgen-tests/tests/expectations/tests/merge-extern-blocks.rs @@ -13,16 +13,19 @@ pub mod root { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < Point > (), 4usize, concat!("Size of: ", - stringify!(Point)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Point)), ); assert_eq!( - ::std::mem::align_of:: < Point > (), 4usize, concat!("Alignment of ", - stringify!(Point)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Point)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).x) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Point), "::", stringify!(x)) + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Point), "::", stringify!(x)), ); } pub mod ns { @@ -38,17 +41,19 @@ pub mod root { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < Point > (), 4usize, concat!("Size of: ", - stringify!(Point)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Point)), ); assert_eq!( - ::std::mem::align_of:: < Point > (), 4usize, concat!("Alignment of ", - stringify!(Point)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Point)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).x) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(Point), "::", - stringify!(x)) + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Point), "::", stringify!(x)), ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/method-mangling.rs b/bindgen-tests/tests/expectations/tests/method-mangling.rs index 7586070c36..f241f43525 100644 --- a/bindgen-tests/tests/expectations/tests/method-mangling.rs +++ b/bindgen-tests/tests/expectations/tests/method-mangling.rs @@ -7,11 +7,14 @@ pub struct Foo { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo)), ); assert_eq!( - ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", - stringify!(Foo)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)), ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/module-allowlisted.rs b/bindgen-tests/tests/expectations/tests/module-allowlisted.rs index 64e4045bcf..945bccac2d 100644 --- a/bindgen-tests/tests/expectations/tests/module-allowlisted.rs +++ b/bindgen-tests/tests/expectations/tests/module-allowlisted.rs @@ -11,12 +11,14 @@ pub mod root { #[test] fn bindgen_test_layout_Test() { assert_eq!( - ::std::mem::size_of:: < Test > (), 1usize, concat!("Size of: ", - stringify!(Test)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Test)), ); assert_eq!( - ::std::mem::align_of:: < Test > (), 1usize, concat!("Alignment of ", - stringify!(Test)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Test)), ); } } diff --git a/bindgen-tests/tests/expectations/tests/msvc-no-usr.rs b/bindgen-tests/tests/expectations/tests/msvc-no-usr.rs index 62b9e8c364..2afd183321 100644 --- a/bindgen-tests/tests/expectations/tests/msvc-no-usr.rs +++ b/bindgen-tests/tests/expectations/tests/msvc-no-usr.rs @@ -8,14 +8,15 @@ pub struct A { 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, concat!("Size of: ", stringify!(A))); assert_eq!( - ::std::mem::size_of:: < A > (), 8usize, concat!("Size of: ", stringify!(A)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(A)), ); assert_eq!( - ::std::mem::align_of:: < A > (), 8usize, concat!("Alignment of ", stringify!(A)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).foo) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(foo)) + unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(A), "::", stringify!(foo)), ); } diff --git a/bindgen-tests/tests/expectations/tests/multiple-inherit-empty-correct-layout.rs b/bindgen-tests/tests/expectations/tests/multiple-inherit-empty-correct-layout.rs index 27322ecd41..81b5e7f1d8 100644 --- a/bindgen-tests/tests/expectations/tests/multiple-inherit-empty-correct-layout.rs +++ b/bindgen-tests/tests/expectations/tests/multiple-inherit-empty-correct-layout.rs @@ -7,11 +7,14 @@ pub struct Foo { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo)), ); assert_eq!( - ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", - stringify!(Foo)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)), ); } #[repr(C)] @@ -22,11 +25,14 @@ pub struct Bar { #[test] fn bindgen_test_layout_Bar() { assert_eq!( - ::std::mem::size_of:: < Bar > (), 1usize, concat!("Size of: ", stringify!(Bar)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Bar)), ); assert_eq!( - ::std::mem::align_of:: < Bar > (), 1usize, concat!("Alignment of ", - stringify!(Bar)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Bar)), ); } #[repr(C)] @@ -37,10 +43,13 @@ pub struct Baz { #[test] fn bindgen_test_layout_Baz() { assert_eq!( - ::std::mem::size_of:: < Baz > (), 1usize, concat!("Size of: ", stringify!(Baz)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Baz)), ); assert_eq!( - ::std::mem::align_of:: < Baz > (), 1usize, concat!("Alignment of ", - stringify!(Baz)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Baz)), ); } diff --git a/bindgen-tests/tests/expectations/tests/mutable.rs b/bindgen-tests/tests/expectations/tests/mutable.rs index eed5848181..ddf49aaeee 100644 --- a/bindgen-tests/tests/expectations/tests/mutable.rs +++ b/bindgen-tests/tests/expectations/tests/mutable.rs @@ -9,19 +9,21 @@ pub struct C { 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::(), 8usize, concat!("Size of: ", stringify!(C))); assert_eq!( - ::std::mem::size_of:: < C > (), 8usize, concat!("Size of: ", stringify!(C)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(C)), ); assert_eq!( - ::std::mem::align_of:: < C > (), 4usize, concat!("Alignment of ", stringify!(C)) + unsafe { ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(m_member)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).m_member) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(m_member)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).m_other) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(m_other)) + unsafe { ::std::ptr::addr_of!((*ptr).m_other) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(m_other)), ); } #[repr(C)] @@ -34,17 +36,19 @@ fn bindgen_test_layout_NonCopiable() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < NonCopiable > (), 4usize, concat!("Size of: ", - stringify!(NonCopiable)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(NonCopiable)), ); assert_eq!( - ::std::mem::align_of:: < NonCopiable > (), 4usize, concat!("Alignment of ", - stringify!(NonCopiable)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(NonCopiable)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).m_member) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(NonCopiable), "::", - stringify!(m_member)) + unsafe { ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(NonCopiable), "::", stringify!(m_member)), ); } #[repr(C)] @@ -57,16 +61,23 @@ fn bindgen_test_layout_NonCopiableWithNonCopiableMutableMember() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < NonCopiableWithNonCopiableMutableMember > (), 4usize, - concat!("Size of: ", stringify!(NonCopiableWithNonCopiableMutableMember)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(NonCopiableWithNonCopiableMutableMember)), ); assert_eq!( - ::std::mem::align_of:: < NonCopiableWithNonCopiableMutableMember > (), 4usize, - concat!("Alignment of ", stringify!(NonCopiableWithNonCopiableMutableMember)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(NonCopiableWithNonCopiableMutableMember)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).m_member) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", - stringify!(NonCopiableWithNonCopiableMutableMember), "::", stringify!(m_member)) + unsafe { ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(NonCopiableWithNonCopiableMutableMember), + "::", + stringify!(m_member), + ), ); } diff --git a/bindgen-tests/tests/expectations/tests/namespace.rs b/bindgen-tests/tests/expectations/tests/namespace.rs index 83543b851e..ebeccb1344 100644 --- a/bindgen-tests/tests/expectations/tests/namespace.rs +++ b/bindgen-tests/tests/expectations/tests/namespace.rs @@ -30,16 +30,19 @@ pub mod root { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < A > (), 4usize, concat!("Size of: ", - stringify!(A)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(A)), ); assert_eq!( - ::std::mem::align_of:: < A > (), 4usize, concat!("Alignment of ", - stringify!(A)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(A)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(A), "::", stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(A), "::", stringify!(b)), ); } } diff --git a/bindgen-tests/tests/expectations/tests/nested.rs b/bindgen-tests/tests/expectations/tests/nested.rs index 373a04fa90..71d3a4c28a 100644 --- a/bindgen-tests/tests/expectations/tests/nested.rs +++ b/bindgen-tests/tests/expectations/tests/nested.rs @@ -9,15 +9,19 @@ fn bindgen_test_layout_Calc() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < Calc > (), 4usize, concat!("Size of: ", stringify!(Calc)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Calc)), ); assert_eq!( - ::std::mem::align_of:: < Calc > (), 4usize, concat!("Alignment of ", - stringify!(Calc)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Calc)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).w) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Calc), "::", stringify!(w)) + unsafe { ::std::ptr::addr_of!((*ptr).w) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Calc), "::", stringify!(w)), ); } #[repr(C)] @@ -39,12 +43,14 @@ pub struct Test_Size_Dimension { #[test] fn bindgen_test_layout_Test_Size_Dimension() { assert_eq!( - ::std::mem::size_of:: < Test_Size_Dimension > (), 4usize, concat!("Size of: ", - stringify!(Test_Size_Dimension)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Test_Size_Dimension)), ); assert_eq!( - ::std::mem::align_of:: < Test_Size_Dimension > (), 4usize, - concat!("Alignment of ", stringify!(Test_Size_Dimension)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Test_Size_Dimension)), ); } #[test] @@ -52,29 +58,36 @@ fn bindgen_test_layout_Test_Size() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < Test_Size > (), 8usize, concat!("Size of: ", - stringify!(Test_Size)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Test_Size)), ); assert_eq!( - ::std::mem::align_of:: < Test_Size > (), 4usize, concat!("Alignment of ", - stringify!(Test_Size)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Test_Size)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mWidth) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Test_Size), "::", stringify!(mWidth)) + unsafe { ::std::ptr::addr_of!((*ptr).mWidth) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Test_Size), "::", stringify!(mWidth)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mHeight) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(Test_Size), "::", stringify!(mHeight)) + unsafe { ::std::ptr::addr_of!((*ptr).mHeight) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(Test_Size), "::", stringify!(mHeight)), ); } #[test] fn bindgen_test_layout_Test() { assert_eq!( - ::std::mem::size_of:: < Test > (), 1usize, concat!("Size of: ", stringify!(Test)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Test)), ); assert_eq!( - ::std::mem::align_of:: < Test > (), 1usize, concat!("Alignment of ", - stringify!(Test)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Test)), ); } diff --git a/bindgen-tests/tests/expectations/tests/nested_vtable.rs b/bindgen-tests/tests/expectations/tests/nested_vtable.rs index 1470d673ff..bcedd777e8 100644 --- a/bindgen-tests/tests/expectations/tests/nested_vtable.rs +++ b/bindgen-tests/tests/expectations/tests/nested_vtable.rs @@ -13,12 +13,14 @@ pub struct nsISupports { #[test] fn bindgen_test_layout_nsISupports() { assert_eq!( - ::std::mem::size_of:: < nsISupports > (), 8usize, concat!("Size of: ", - stringify!(nsISupports)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(nsISupports)), ); assert_eq!( - ::std::mem::align_of:: < nsISupports > (), 8usize, concat!("Alignment of ", - stringify!(nsISupports)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(nsISupports)), ); } impl Default for nsISupports { @@ -44,12 +46,14 @@ pub struct nsIRunnable { #[test] fn bindgen_test_layout_nsIRunnable() { assert_eq!( - ::std::mem::size_of:: < nsIRunnable > (), 8usize, concat!("Size of: ", - stringify!(nsIRunnable)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(nsIRunnable)), ); assert_eq!( - ::std::mem::align_of:: < nsIRunnable > (), 8usize, concat!("Alignment of ", - stringify!(nsIRunnable)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(nsIRunnable)), ); } impl Default for nsIRunnable { @@ -69,12 +73,14 @@ pub struct Runnable { #[test] fn bindgen_test_layout_Runnable() { assert_eq!( - ::std::mem::size_of:: < Runnable > (), 8usize, concat!("Size of: ", - stringify!(Runnable)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Runnable)), ); assert_eq!( - ::std::mem::align_of:: < Runnable > (), 8usize, concat!("Alignment of ", - stringify!(Runnable)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Runnable)), ); } impl Default for Runnable { diff --git a/bindgen-tests/tests/expectations/tests/nested_within_namespace.rs b/bindgen-tests/tests/expectations/tests/nested_within_namespace.rs index 2131a5d86a..c9b00d5add 100644 --- a/bindgen-tests/tests/expectations/tests/nested_within_namespace.rs +++ b/bindgen-tests/tests/expectations/tests/nested_within_namespace.rs @@ -21,17 +21,19 @@ pub mod root { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < Bar_Baz > (), 4usize, concat!("Size of: ", - stringify!(Bar_Baz)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Bar_Baz)), ); assert_eq!( - ::std::mem::align_of:: < Bar_Baz > (), 4usize, concat!("Alignment of ", - stringify!(Bar_Baz)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Bar_Baz)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).foo) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(Bar_Baz), "::", - stringify!(foo)) + unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Bar_Baz), "::", stringify!(foo)), ); } #[test] @@ -39,17 +41,19 @@ pub mod root { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < Bar > (), 4usize, concat!("Size of: ", - stringify!(Bar)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Bar)), ); assert_eq!( - ::std::mem::align_of:: < Bar > (), 4usize, concat!("Alignment of ", - stringify!(Bar)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Bar)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).foo) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(Bar), "::", - stringify!(foo)) + unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(foo)), ); } #[repr(C)] @@ -62,17 +66,19 @@ pub mod root { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < Baz > (), 4usize, concat!("Size of: ", - stringify!(Baz)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Baz)), ); assert_eq!( - ::std::mem::align_of:: < Baz > (), 4usize, concat!("Alignment of ", - stringify!(Baz)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Baz)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).baz) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(Baz), "::", - stringify!(baz)) + unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Baz), "::", stringify!(baz)), ); } } diff --git a/bindgen-tests/tests/expectations/tests/no-comments.rs b/bindgen-tests/tests/expectations/tests/no-comments.rs index 626c5747e8..712580c9fd 100644 --- a/bindgen-tests/tests/expectations/tests/no-comments.rs +++ b/bindgen-tests/tests/expectations/tests/no-comments.rs @@ -9,14 +9,18 @@ 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:: < Foo > (), 4usize, concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Foo)), ); assert_eq!( - ::std::mem::align_of:: < Foo > (), 4usize, concat!("Alignment of ", - stringify!(Foo)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).s) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(s)) + unsafe { ::std::ptr::addr_of!((*ptr).s) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(s)), ); } diff --git a/bindgen-tests/tests/expectations/tests/no-derive-debug.rs b/bindgen-tests/tests/expectations/tests/no-derive-debug.rs index dff97781d0..6a8c4d8aa7 100644 --- a/bindgen-tests/tests/expectations/tests/no-derive-debug.rs +++ b/bindgen-tests/tests/expectations/tests/no-derive-debug.rs @@ -17,19 +17,24 @@ 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:: < bar > (), 8usize, concat!("Size of: ", stringify!(bar)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(bar)), ); assert_eq!( - ::std::mem::align_of:: < bar > (), 4usize, concat!("Alignment of ", - stringify!(bar)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(bar)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).foo) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(bar), "::", stringify!(foo)) + unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(bar), "::", stringify!(foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).baz) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(bar), "::", stringify!(baz)) + unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(bar), "::", stringify!(baz)), ); } impl Default for bar { diff --git a/bindgen-tests/tests/expectations/tests/no-derive-default.rs b/bindgen-tests/tests/expectations/tests/no-derive-default.rs index 483520f0aa..fea25bec1e 100644 --- a/bindgen-tests/tests/expectations/tests/no-derive-default.rs +++ b/bindgen-tests/tests/expectations/tests/no-derive-default.rs @@ -17,18 +17,23 @@ 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:: < bar > (), 8usize, concat!("Size of: ", stringify!(bar)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(bar)), ); assert_eq!( - ::std::mem::align_of:: < bar > (), 4usize, concat!("Alignment of ", - stringify!(bar)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(bar)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).foo) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(bar), "::", stringify!(foo)) + unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(bar), "::", stringify!(foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).baz) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(bar), "::", stringify!(baz)) + unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(bar), "::", stringify!(baz)), ); } diff --git a/bindgen-tests/tests/expectations/tests/no-hash-allowlisted.rs b/bindgen-tests/tests/expectations/tests/no-hash-allowlisted.rs index 80aaf7eed8..ab94a578d8 100644 --- a/bindgen-tests/tests/expectations/tests/no-hash-allowlisted.rs +++ b/bindgen-tests/tests/expectations/tests/no-hash-allowlisted.rs @@ -9,15 +9,18 @@ fn bindgen_test_layout_NoHash() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < NoHash > (), 4usize, concat!("Size of: ", - stringify!(NoHash)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(NoHash)), ); assert_eq!( - ::std::mem::align_of:: < NoHash > (), 4usize, concat!("Alignment of ", - stringify!(NoHash)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(NoHash)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).i) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(NoHash), "::", stringify!(i)) + unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(NoHash), "::", stringify!(i)), ); } diff --git a/bindgen-tests/tests/expectations/tests/no-hash-opaque.rs b/bindgen-tests/tests/expectations/tests/no-hash-opaque.rs index 67da7b6fe5..9f25d948a5 100644 --- a/bindgen-tests/tests/expectations/tests/no-hash-opaque.rs +++ b/bindgen-tests/tests/expectations/tests/no-hash-opaque.rs @@ -8,11 +8,13 @@ pub struct NoHash { #[test] fn bindgen_test_layout_NoHash() { assert_eq!( - ::std::mem::size_of:: < NoHash > (), 4usize, concat!("Size of: ", - stringify!(NoHash)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(NoHash)), ); assert_eq!( - ::std::mem::align_of:: < NoHash > (), 4usize, concat!("Alignment of ", - stringify!(NoHash)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(NoHash)), ); } diff --git a/bindgen-tests/tests/expectations/tests/no-partialeq-allowlisted.rs b/bindgen-tests/tests/expectations/tests/no-partialeq-allowlisted.rs index 11d7b37610..d07f16b944 100644 --- a/bindgen-tests/tests/expectations/tests/no-partialeq-allowlisted.rs +++ b/bindgen-tests/tests/expectations/tests/no-partialeq-allowlisted.rs @@ -9,15 +9,18 @@ fn bindgen_test_layout_NoPartialEq() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < NoPartialEq > (), 4usize, concat!("Size of: ", - stringify!(NoPartialEq)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(NoPartialEq)), ); assert_eq!( - ::std::mem::align_of:: < NoPartialEq > (), 4usize, concat!("Alignment of ", - stringify!(NoPartialEq)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(NoPartialEq)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).i) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(NoPartialEq), "::", stringify!(i)) + unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(NoPartialEq), "::", stringify!(i)), ); } diff --git a/bindgen-tests/tests/expectations/tests/no-partialeq-opaque.rs b/bindgen-tests/tests/expectations/tests/no-partialeq-opaque.rs index 04f3a5c18c..cf775ccd47 100644 --- a/bindgen-tests/tests/expectations/tests/no-partialeq-opaque.rs +++ b/bindgen-tests/tests/expectations/tests/no-partialeq-opaque.rs @@ -8,11 +8,13 @@ pub struct NoPartialEq { #[test] fn bindgen_test_layout_NoPartialEq() { assert_eq!( - ::std::mem::size_of:: < NoPartialEq > (), 4usize, concat!("Size of: ", - stringify!(NoPartialEq)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(NoPartialEq)), ); assert_eq!( - ::std::mem::align_of:: < NoPartialEq > (), 4usize, concat!("Alignment of ", - stringify!(NoPartialEq)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(NoPartialEq)), ); } diff --git a/bindgen-tests/tests/expectations/tests/no-recursive-allowlisting.rs b/bindgen-tests/tests/expectations/tests/no-recursive-allowlisting.rs index 4e8e06e94f..6dd354df35 100644 --- a/bindgen-tests/tests/expectations/tests/no-recursive-allowlisting.rs +++ b/bindgen-tests/tests/expectations/tests/no-recursive-allowlisting.rs @@ -10,15 +10,19 @@ 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:: < Foo > (), 8usize, concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Foo)), ); assert_eq!( - ::std::mem::align_of:: < Foo > (), 8usize, concat!("Alignment of ", - stringify!(Foo)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).baz) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(baz)) + unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(baz)), ); } impl Default for Foo { diff --git a/bindgen-tests/tests/expectations/tests/no-std.rs b/bindgen-tests/tests/expectations/tests/no-std.rs index 9c70dd0027..a41bef8939 100644 --- a/bindgen-tests/tests/expectations/tests/no-std.rs +++ b/bindgen-tests/tests/expectations/tests/no-std.rs @@ -16,23 +16,29 @@ fn bindgen_test_layout_foo() { const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::core::mem::size_of:: < foo > (), 16usize, concat!("Size of: ", stringify!(foo)) + ::core::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(foo)), ); assert_eq!( - ::core::mem::align_of:: < foo > (), 8usize, concat!("Alignment of ", - stringify!(foo)) + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(foo)), ); assert_eq!( - unsafe { ::core::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) + unsafe { ::core::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)), ); assert_eq!( - unsafe { ::core::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) + unsafe { ::core::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)), ); assert_eq!( - unsafe { ::core::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) + unsafe { ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, + 8usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)), ); } impl Default for foo { diff --git a/bindgen-tests/tests/expectations/tests/no_copy_allowlisted.rs b/bindgen-tests/tests/expectations/tests/no_copy_allowlisted.rs index e427a55f1b..b0c9bc026e 100644 --- a/bindgen-tests/tests/expectations/tests/no_copy_allowlisted.rs +++ b/bindgen-tests/tests/expectations/tests/no_copy_allowlisted.rs @@ -9,15 +9,18 @@ fn bindgen_test_layout_NoCopy() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < NoCopy > (), 4usize, concat!("Size of: ", - stringify!(NoCopy)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(NoCopy)), ); assert_eq!( - ::std::mem::align_of:: < NoCopy > (), 4usize, concat!("Alignment of ", - stringify!(NoCopy)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(NoCopy)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).i) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(NoCopy), "::", stringify!(i)) + unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(NoCopy), "::", stringify!(i)), ); } diff --git a/bindgen-tests/tests/expectations/tests/no_copy_opaque.rs b/bindgen-tests/tests/expectations/tests/no_copy_opaque.rs index 83dcdf61d2..3a8f84784d 100644 --- a/bindgen-tests/tests/expectations/tests/no_copy_opaque.rs +++ b/bindgen-tests/tests/expectations/tests/no_copy_opaque.rs @@ -8,11 +8,13 @@ pub struct NoCopy { #[test] fn bindgen_test_layout_NoCopy() { assert_eq!( - ::std::mem::size_of:: < NoCopy > (), 4usize, concat!("Size of: ", - stringify!(NoCopy)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(NoCopy)), ); assert_eq!( - ::std::mem::align_of:: < NoCopy > (), 4usize, concat!("Alignment of ", - stringify!(NoCopy)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(NoCopy)), ); } diff --git a/bindgen-tests/tests/expectations/tests/no_debug_allowlisted.rs b/bindgen-tests/tests/expectations/tests/no_debug_allowlisted.rs index 00b213cbae..e58f9bf85a 100644 --- a/bindgen-tests/tests/expectations/tests/no_debug_allowlisted.rs +++ b/bindgen-tests/tests/expectations/tests/no_debug_allowlisted.rs @@ -9,15 +9,18 @@ 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:: < NoDebug > (), 4usize, concat!("Size of: ", - stringify!(NoDebug)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(NoDebug)), ); assert_eq!( - ::std::mem::align_of:: < NoDebug > (), 4usize, concat!("Alignment of ", - stringify!(NoDebug)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(NoDebug)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).i) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(NoDebug), "::", stringify!(i)) + unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(NoDebug), "::", stringify!(i)), ); } diff --git a/bindgen-tests/tests/expectations/tests/no_debug_opaque.rs b/bindgen-tests/tests/expectations/tests/no_debug_opaque.rs index 62b5fcc289..527d370103 100644 --- a/bindgen-tests/tests/expectations/tests/no_debug_opaque.rs +++ b/bindgen-tests/tests/expectations/tests/no_debug_opaque.rs @@ -8,11 +8,13 @@ pub struct NoDebug { #[test] fn bindgen_test_layout_NoDebug() { assert_eq!( - ::std::mem::size_of:: < NoDebug > (), 4usize, concat!("Size of: ", - stringify!(NoDebug)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(NoDebug)), ); assert_eq!( - ::std::mem::align_of:: < NoDebug > (), 4usize, concat!("Alignment of ", - stringify!(NoDebug)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(NoDebug)), ); } diff --git a/bindgen-tests/tests/expectations/tests/no_default_allowlisted.rs b/bindgen-tests/tests/expectations/tests/no_default_allowlisted.rs index f624c2aeaf..55501ebd2b 100644 --- a/bindgen-tests/tests/expectations/tests/no_default_allowlisted.rs +++ b/bindgen-tests/tests/expectations/tests/no_default_allowlisted.rs @@ -9,15 +9,18 @@ fn bindgen_test_layout_NoDefault() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < NoDefault > (), 4usize, concat!("Size of: ", - stringify!(NoDefault)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(NoDefault)), ); assert_eq!( - ::std::mem::align_of:: < NoDefault > (), 4usize, concat!("Alignment of ", - stringify!(NoDefault)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(NoDefault)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).i) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(NoDefault), "::", stringify!(i)) + unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(NoDefault), "::", stringify!(i)), ); } diff --git a/bindgen-tests/tests/expectations/tests/no_default_opaque.rs b/bindgen-tests/tests/expectations/tests/no_default_opaque.rs index 4b8f0f464b..b7dd4d41e1 100644 --- a/bindgen-tests/tests/expectations/tests/no_default_opaque.rs +++ b/bindgen-tests/tests/expectations/tests/no_default_opaque.rs @@ -8,11 +8,13 @@ pub struct NoDefault { #[test] fn bindgen_test_layout_NoDefault() { assert_eq!( - ::std::mem::size_of:: < NoDefault > (), 4usize, concat!("Size of: ", - stringify!(NoDefault)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(NoDefault)), ); assert_eq!( - ::std::mem::align_of:: < NoDefault > (), 4usize, concat!("Alignment of ", - stringify!(NoDefault)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(NoDefault)), ); } diff --git a/bindgen-tests/tests/expectations/tests/no_size_t_is_usize.rs b/bindgen-tests/tests/expectations/tests/no_size_t_is_usize.rs index a9e4149d7e..99d13449c7 100644 --- a/bindgen-tests/tests/expectations/tests/no_size_t_is_usize.rs +++ b/bindgen-tests/tests/expectations/tests/no_size_t_is_usize.rs @@ -12,23 +12,26 @@ pub struct A { 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::(), 24usize, concat!("Size of: ", stringify!(A))); assert_eq!( - ::std::mem::size_of:: < A > (), 24usize, concat!("Size of: ", stringify!(A)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(A)), ); assert_eq!( - ::std::mem::align_of:: < A > (), 8usize, concat!("Alignment of ", stringify!(A)) + unsafe { ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(A), "::", stringify!(len)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).len) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(len)) + unsafe { ::std::ptr::addr_of!((*ptr).offset) as usize - ptr as usize }, + 8usize, + concat!("Offset of field: ", stringify!(A), "::", stringify!(offset)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).offset) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(offset)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).next) as usize - ptr as usize }, 16usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(next)) + unsafe { ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize }, + 16usize, + concat!("Offset of field: ", stringify!(A), "::", stringify!(next)), ); } impl Default for A { diff --git a/bindgen-tests/tests/expectations/tests/non-type-params.rs b/bindgen-tests/tests/expectations/tests/non-type-params.rs index 64e352a77d..e83ee74de6 100644 --- a/bindgen-tests/tests/expectations/tests/non-type-params.rs +++ b/bindgen-tests/tests/expectations/tests/non-type-params.rs @@ -13,26 +13,43 @@ fn bindgen_test_layout_UsesArray() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < UsesArray > (), 40usize, concat!("Size of: ", - stringify!(UsesArray)) + ::std::mem::size_of::(), + 40usize, + concat!("Size of: ", stringify!(UsesArray)), ); assert_eq!( - ::std::mem::align_of:: < UsesArray > (), 4usize, concat!("Alignment of ", - stringify!(UsesArray)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(UsesArray)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).array_char_16) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(UsesArray), "::", - stringify!(array_char_16)) + unsafe { ::std::ptr::addr_of!((*ptr).array_char_16) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(UsesArray), + "::", + stringify!(array_char_16), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).array_bool_8) as usize - ptr as usize }, - 16usize, concat!("Offset of field: ", stringify!(UsesArray), "::", - stringify!(array_bool_8)) + unsafe { ::std::ptr::addr_of!((*ptr).array_bool_8) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(UsesArray), + "::", + stringify!(array_bool_8), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).array_int_4) as usize - ptr as usize }, - 24usize, concat!("Offset of field: ", stringify!(UsesArray), "::", - stringify!(array_int_4)) + unsafe { ::std::ptr::addr_of!((*ptr).array_int_4) as usize - ptr as usize }, + 24usize, + concat!( + "Offset of field: ", + stringify!(UsesArray), + "::", + stringify!(array_int_4), + ), ); } diff --git a/bindgen-tests/tests/expectations/tests/objc_interface_type.rs b/bindgen-tests/tests/expectations/tests/objc_interface_type.rs index 2cf92ded84..a49f9229a0 100644 --- a/bindgen-tests/tests/expectations/tests/objc_interface_type.rs +++ b/bindgen-tests/tests/expectations/tests/objc_interface_type.rs @@ -30,16 +30,19 @@ fn bindgen_test_layout_FooStruct() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < FooStruct > (), 8usize, concat!("Size of: ", - stringify!(FooStruct)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(FooStruct)), ); assert_eq!( - ::std::mem::align_of:: < FooStruct > (), 8usize, concat!("Alignment of ", - stringify!(FooStruct)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(FooStruct)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).foo) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(FooStruct), "::", stringify!(foo)) + unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(FooStruct), "::", stringify!(foo)), ); } impl Default for FooStruct { diff --git a/bindgen-tests/tests/expectations/tests/only_bitfields.rs b/bindgen-tests/tests/expectations/tests/only_bitfields.rs index e36f8235bb..42ea60f1aa 100644 --- a/bindgen-tests/tests/expectations/tests/only_bitfields.rs +++ b/bindgen-tests/tests/expectations/tests/only_bitfields.rs @@ -49,7 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -69,7 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -91,11 +91,11 @@ pub struct C { } #[test] fn bindgen_test_layout_C() { + assert_eq!(::std::mem::size_of::(), 1usize, concat!("Size of: ", stringify!(C))); assert_eq!( - ::std::mem::size_of:: < C > (), 1usize, concat!("Size of: ", stringify!(C)) - ); - assert_eq!( - ::std::mem::align_of:: < C > (), 1usize, concat!("Alignment of ", stringify!(C)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(C)), ); } impl C { diff --git a/bindgen-tests/tests/expectations/tests/opaque-template-inst-member-2.rs b/bindgen-tests/tests/expectations/tests/opaque-template-inst-member-2.rs index 2fd9ed7c61..3dd89d0a5d 100644 --- a/bindgen-tests/tests/expectations/tests/opaque-template-inst-member-2.rs +++ b/bindgen-tests/tests/expectations/tests/opaque-template-inst-member-2.rs @@ -18,22 +18,34 @@ 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:: < ContainsOpaqueTemplate > (), 8usize, concat!("Size of: ", - stringify!(ContainsOpaqueTemplate)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(ContainsOpaqueTemplate)), ); assert_eq!( - ::std::mem::align_of:: < ContainsOpaqueTemplate > (), 4usize, - concat!("Alignment of ", stringify!(ContainsOpaqueTemplate)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(ContainsOpaqueTemplate)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mBlah) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(ContainsOpaqueTemplate), "::", - stringify!(mBlah)) + unsafe { ::std::ptr::addr_of!((*ptr).mBlah) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ContainsOpaqueTemplate), + "::", + stringify!(mBlah), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mBaz) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(ContainsOpaqueTemplate), "::", - stringify!(mBaz)) + unsafe { ::std::ptr::addr_of!((*ptr).mBaz) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(ContainsOpaqueTemplate), + "::", + stringify!(mBaz), + ), ); } /// Should also derive Debug/Hash/PartialEq. @@ -48,17 +60,24 @@ 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:: < InheritsOpaqueTemplate > (), 16usize, - concat!("Size of: ", stringify!(InheritsOpaqueTemplate)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(InheritsOpaqueTemplate)), ); assert_eq!( - ::std::mem::align_of:: < InheritsOpaqueTemplate > (), 8usize, - concat!("Alignment of ", stringify!(InheritsOpaqueTemplate)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(InheritsOpaqueTemplate)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).wow) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(InheritsOpaqueTemplate), "::", - stringify!(wow)) + unsafe { ::std::ptr::addr_of!((*ptr).wow) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(InheritsOpaqueTemplate), + "::", + stringify!(wow), + ), ); } impl Default for InheritsOpaqueTemplate { 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 dc50471b8b..4f3f4b5724 100644 --- a/bindgen-tests/tests/expectations/tests/opaque-template-inst-member.rs +++ b/bindgen-tests/tests/expectations/tests/opaque-template-inst-member.rs @@ -16,22 +16,34 @@ 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:: < ContainsOpaqueTemplate > (), 408usize, - concat!("Size of: ", stringify!(ContainsOpaqueTemplate)) + ::std::mem::size_of::(), + 408usize, + concat!("Size of: ", stringify!(ContainsOpaqueTemplate)), ); assert_eq!( - ::std::mem::align_of:: < ContainsOpaqueTemplate > (), 4usize, - concat!("Alignment of ", stringify!(ContainsOpaqueTemplate)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(ContainsOpaqueTemplate)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mBlah) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(ContainsOpaqueTemplate), "::", - stringify!(mBlah)) + unsafe { ::std::ptr::addr_of!((*ptr).mBlah) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ContainsOpaqueTemplate), + "::", + stringify!(mBlah), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mBaz) as usize - ptr as usize }, 404usize, - concat!("Offset of field: ", stringify!(ContainsOpaqueTemplate), "::", - stringify!(mBaz)) + unsafe { ::std::ptr::addr_of!((*ptr).mBaz) as usize - ptr as usize }, + 404usize, + concat!( + "Offset of field: ", + stringify!(ContainsOpaqueTemplate), + "::", + stringify!(mBaz), + ), ); } impl Default for ContainsOpaqueTemplate { @@ -60,17 +72,24 @@ 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:: < InheritsOpaqueTemplate > (), 416usize, - concat!("Size of: ", stringify!(InheritsOpaqueTemplate)) + ::std::mem::size_of::(), + 416usize, + concat!("Size of: ", stringify!(InheritsOpaqueTemplate)), ); assert_eq!( - ::std::mem::align_of:: < InheritsOpaqueTemplate > (), 8usize, - concat!("Alignment of ", stringify!(InheritsOpaqueTemplate)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(InheritsOpaqueTemplate)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).wow) as usize - ptr as usize }, 408usize, - concat!("Offset of field: ", stringify!(InheritsOpaqueTemplate), "::", - stringify!(wow)) + unsafe { ::std::ptr::addr_of!((*ptr).wow) as usize - ptr as usize }, + 408usize, + concat!( + "Offset of field: ", + stringify!(InheritsOpaqueTemplate), + "::", + stringify!(wow), + ), ); } impl Default for InheritsOpaqueTemplate { diff --git a/bindgen-tests/tests/expectations/tests/opaque-template-instantiation-namespaced.rs b/bindgen-tests/tests/expectations/tests/opaque-template-instantiation-namespaced.rs index 62701da3c1..57b20c78a9 100644 --- a/bindgen-tests/tests/expectations/tests/opaque-template-instantiation-namespaced.rs +++ b/bindgen-tests/tests/expectations/tests/opaque-template-instantiation-namespaced.rs @@ -31,17 +31,19 @@ pub mod root { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", - stringify!(Foo)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo)), ); assert_eq!( - ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", - stringify!(Foo)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).c) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(Foo), "::", - stringify!(c)) + unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(c)), ); } #[repr(C)] @@ -54,17 +56,19 @@ pub mod root { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < Bar > (), 4usize, concat!("Size of: ", - stringify!(Bar)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Bar)), ); assert_eq!( - ::std::mem::align_of:: < Bar > (), 4usize, concat!("Alignment of ", - stringify!(Bar)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Bar)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).i) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(Bar), "::", - stringify!(i)) + unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(i)), ); } #[repr(C)] @@ -77,17 +81,26 @@ pub mod root { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < ContainsInstantiation > (), 1usize, - concat!("Size of: ", stringify!(ContainsInstantiation)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(ContainsInstantiation)), ); assert_eq!( - ::std::mem::align_of:: < ContainsInstantiation > (), 1usize, - concat!("Alignment of ", stringify!(ContainsInstantiation)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(ContainsInstantiation)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).not_opaque) as usize - ptr as usize - }, 0usize, concat!("Offset of field: ", - stringify!(ContainsInstantiation), "::", stringify!(not_opaque)) + unsafe { + ::std::ptr::addr_of!((*ptr).not_opaque) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ContainsInstantiation), + "::", + stringify!(not_opaque), + ), ); } impl Default for ContainsInstantiation { @@ -109,31 +122,44 @@ pub mod root { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < ContainsOpaqueInstantiation > (), 4usize, - concat!("Size of: ", stringify!(ContainsOpaqueInstantiation)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(ContainsOpaqueInstantiation)), ); assert_eq!( - ::std::mem::align_of:: < ContainsOpaqueInstantiation > (), 4usize, - concat!("Alignment of ", stringify!(ContainsOpaqueInstantiation)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(ContainsOpaqueInstantiation)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).opaque) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", - stringify!(ContainsOpaqueInstantiation), "::", stringify!(opaque)) + unsafe { ::std::ptr::addr_of!((*ptr).opaque) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ContainsOpaqueInstantiation), + "::", + stringify!(opaque), + ), ); } } #[test] fn __bindgen_test_layout_Template_open0_Foo_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < root::zoidberg::Template < root::zoidberg::Foo > > - (), 1usize, concat!("Size of template specialization: ", - stringify!(root::zoidberg::Template < root::zoidberg::Foo >)) + ::std::mem::size_of::>(), + 1usize, + concat!( + "Size of template specialization: ", + stringify!(root::zoidberg::Template < root::zoidberg::Foo >), + ), ); assert_eq!( - ::std::mem::align_of:: < root::zoidberg::Template < root::zoidberg::Foo > > - (), 1usize, concat!("Alignment of template specialization: ", - stringify!(root::zoidberg::Template < root::zoidberg::Foo >)) + ::std::mem::align_of::>(), + 1usize, + concat!( + "Alignment of template specialization: ", + stringify!(root::zoidberg::Template < root::zoidberg::Foo >), + ), ); } } diff --git a/bindgen-tests/tests/expectations/tests/opaque-template-instantiation.rs b/bindgen-tests/tests/expectations/tests/opaque-template-instantiation.rs index f35915f64c..a1cdbcc977 100644 --- a/bindgen-tests/tests/expectations/tests/opaque-template-instantiation.rs +++ b/bindgen-tests/tests/expectations/tests/opaque-template-instantiation.rs @@ -24,17 +24,24 @@ fn bindgen_test_layout_ContainsInstantiation() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < ContainsInstantiation > (), 1usize, concat!("Size of: ", - stringify!(ContainsInstantiation)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(ContainsInstantiation)), ); assert_eq!( - ::std::mem::align_of:: < ContainsInstantiation > (), 1usize, - concat!("Alignment of ", stringify!(ContainsInstantiation)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(ContainsInstantiation)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).not_opaque) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(ContainsInstantiation), "::", - stringify!(not_opaque)) + unsafe { ::std::ptr::addr_of!((*ptr).not_opaque) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ContainsInstantiation), + "::", + stringify!(not_opaque), + ), ); } impl Default for ContainsInstantiation { @@ -56,29 +63,42 @@ fn bindgen_test_layout_ContainsOpaqueInstantiation() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < ContainsOpaqueInstantiation > (), 4usize, - concat!("Size of: ", stringify!(ContainsOpaqueInstantiation)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(ContainsOpaqueInstantiation)), ); assert_eq!( - ::std::mem::align_of:: < ContainsOpaqueInstantiation > (), 4usize, - concat!("Alignment of ", stringify!(ContainsOpaqueInstantiation)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(ContainsOpaqueInstantiation)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).opaque) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(ContainsOpaqueInstantiation), "::", - stringify!(opaque)) + unsafe { ::std::ptr::addr_of!((*ptr).opaque) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ContainsOpaqueInstantiation), + "::", + stringify!(opaque), + ), ); } #[test] fn __bindgen_test_layout_Template_open0_char_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < Template < ::std::os::raw::c_char > > (), 1usize, - concat!("Size of template specialization: ", stringify!(Template < - ::std::os::raw::c_char >)) + ::std::mem::size_of::>(), + 1usize, + concat!( + "Size of template specialization: ", + stringify!(Template < ::std::os::raw::c_char >), + ), ); assert_eq!( - ::std::mem::align_of:: < Template < ::std::os::raw::c_char > > (), 1usize, - concat!("Alignment of template specialization: ", stringify!(Template < - ::std::os::raw::c_char >)) + ::std::mem::align_of::>(), + 1usize, + concat!( + "Alignment of template specialization: ", + stringify!(Template < ::std::os::raw::c_char >), + ), ); } diff --git a/bindgen-tests/tests/expectations/tests/opaque-tracing.rs b/bindgen-tests/tests/expectations/tests/opaque-tracing.rs index 1c3a16ad5c..3bc54c5ed8 100644 --- a/bindgen-tests/tests/expectations/tests/opaque-tracing.rs +++ b/bindgen-tests/tests/expectations/tests/opaque-tracing.rs @@ -12,11 +12,13 @@ pub struct Container { #[test] fn bindgen_test_layout_Container() { assert_eq!( - ::std::mem::size_of:: < Container > (), 8usize, concat!("Size of: ", - stringify!(Container)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Container)), ); assert_eq!( - ::std::mem::align_of:: < Container > (), 4usize, concat!("Alignment of ", - stringify!(Container)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Container)), ); } diff --git a/bindgen-tests/tests/expectations/tests/opaque_in_struct.rs b/bindgen-tests/tests/expectations/tests/opaque_in_struct.rs index 1e6a58aa21..5a267a194b 100644 --- a/bindgen-tests/tests/expectations/tests/opaque_in_struct.rs +++ b/bindgen-tests/tests/expectations/tests/opaque_in_struct.rs @@ -9,12 +9,14 @@ pub struct opaque { #[test] fn bindgen_test_layout_opaque() { assert_eq!( - ::std::mem::size_of:: < opaque > (), 4usize, concat!("Size of: ", - stringify!(opaque)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(opaque)), ); assert_eq!( - ::std::mem::align_of:: < opaque > (), 4usize, concat!("Alignment of ", - stringify!(opaque)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(opaque)), ); } #[repr(C)] @@ -27,16 +29,18 @@ fn bindgen_test_layout_container() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < container > (), 4usize, concat!("Size of: ", - stringify!(container)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(container)), ); assert_eq!( - ::std::mem::align_of:: < container > (), 4usize, concat!("Alignment of ", - stringify!(container)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(container)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).contained) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(container), "::", - stringify!(contained)) + unsafe { ::std::ptr::addr_of!((*ptr).contained) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(container), "::", stringify!(contained)), ); } diff --git a/bindgen-tests/tests/expectations/tests/opaque_pointer.rs b/bindgen-tests/tests/expectations/tests/opaque_pointer.rs index cd06c9b4a3..36a120536e 100644 --- a/bindgen-tests/tests/expectations/tests/opaque_pointer.rs +++ b/bindgen-tests/tests/expectations/tests/opaque_pointer.rs @@ -9,12 +9,14 @@ pub struct OtherOpaque { #[test] fn bindgen_test_layout_OtherOpaque() { assert_eq!( - ::std::mem::size_of:: < OtherOpaque > (), 4usize, concat!("Size of: ", - stringify!(OtherOpaque)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(OtherOpaque)), ); assert_eq!( - ::std::mem::align_of:: < OtherOpaque > (), 4usize, concat!("Alignment of ", - stringify!(OtherOpaque)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(OtherOpaque)), ); } ///
@@ -35,25 +37,34 @@ fn bindgen_test_layout_WithOpaquePtr() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < WithOpaquePtr > (), 16usize, concat!("Size of: ", - stringify!(WithOpaquePtr)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(WithOpaquePtr)), ); assert_eq!( - ::std::mem::align_of:: < WithOpaquePtr > (), 8usize, concat!("Alignment of ", - stringify!(WithOpaquePtr)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(WithOpaquePtr)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).whatever) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(WithOpaquePtr), "::", - stringify!(whatever)) + unsafe { ::std::ptr::addr_of!((*ptr).whatever) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithOpaquePtr), + "::", + stringify!(whatever), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).other) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(WithOpaquePtr), "::", stringify!(other)) + unsafe { ::std::ptr::addr_of!((*ptr).other) as usize - ptr as usize }, + 8usize, + concat!("Offset of field: ", stringify!(WithOpaquePtr), "::", stringify!(other)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).t) as usize - ptr as usize }, 12usize, - concat!("Offset of field: ", stringify!(WithOpaquePtr), "::", stringify!(t)) + unsafe { ::std::ptr::addr_of!((*ptr).t) as usize - ptr as usize }, + 12usize, + concat!("Offset of field: ", stringify!(WithOpaquePtr), "::", stringify!(t)), ); } impl Default for WithOpaquePtr { diff --git a/bindgen-tests/tests/expectations/tests/packed-bitfield.rs b/bindgen-tests/tests/expectations/tests/packed-bitfield.rs index a5b34d6e6d..8d4b87453f 100644 --- a/bindgen-tests/tests/expectations/tests/packed-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/packed-bitfield.rs @@ -49,7 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -69,7 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -92,11 +92,14 @@ pub struct Date { #[test] fn bindgen_test_layout_Date() { assert_eq!( - ::std::mem::size_of:: < Date > (), 3usize, concat!("Size of: ", stringify!(Date)) + ::std::mem::size_of::(), + 3usize, + concat!("Size of: ", stringify!(Date)), ); assert_eq!( - ::std::mem::align_of:: < Date > (), 1usize, concat!("Alignment of ", - stringify!(Date)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Date)), ); } impl Date { diff --git a/bindgen-tests/tests/expectations/tests/packed-n-with-padding.rs b/bindgen-tests/tests/expectations/tests/packed-n-with-padding.rs index 739d08dbfa..3a24767eeb 100644 --- a/bindgen-tests/tests/expectations/tests/packed-n-with-padding.rs +++ b/bindgen-tests/tests/expectations/tests/packed-n-with-padding.rs @@ -12,27 +12,33 @@ fn bindgen_test_layout_Packed() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < Packed > (), 10usize, concat!("Size of: ", - stringify!(Packed)) + ::std::mem::size_of::(), + 10usize, + concat!("Size of: ", stringify!(Packed)), ); assert_eq!( - ::std::mem::align_of:: < Packed > (), 2usize, concat!("Alignment of ", - stringify!(Packed)) + ::std::mem::align_of::(), + 2usize, + concat!("Alignment of ", stringify!(Packed)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Packed), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Packed), "::", stringify!(a)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 2usize, - concat!("Offset of field: ", stringify!(Packed), "::", stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 2usize, + concat!("Offset of field: ", stringify!(Packed), "::", stringify!(b)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).c) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(Packed), "::", stringify!(c)) + unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(Packed), "::", stringify!(c)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).d) as usize - ptr as usize }, 6usize, - concat!("Offset of field: ", stringify!(Packed), "::", stringify!(d)) + unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, + 6usize, + concat!("Offset of field: ", stringify!(Packed), "::", stringify!(d)), ); } diff --git a/bindgen-tests/tests/expectations/tests/packed-vtable.rs b/bindgen-tests/tests/expectations/tests/packed-vtable.rs index 8ec42e3729..b85143250f 100644 --- a/bindgen-tests/tests/expectations/tests/packed-vtable.rs +++ b/bindgen-tests/tests/expectations/tests/packed-vtable.rs @@ -9,12 +9,14 @@ pub struct PackedVtable { #[test] fn bindgen_test_layout_PackedVtable() { assert_eq!( - ::std::mem::size_of:: < PackedVtable > (), 8usize, concat!("Size of: ", - stringify!(PackedVtable)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(PackedVtable)), ); assert_eq!( - ::std::mem::align_of:: < PackedVtable > (), 1usize, concat!("Alignment of ", - stringify!(PackedVtable)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(PackedVtable)), ); } impl Default for PackedVtable { diff --git a/bindgen-tests/tests/expectations/tests/parm-union.rs b/bindgen-tests/tests/expectations/tests/parm-union.rs index f110f457d4..92a3c19576 100644 --- a/bindgen-tests/tests/expectations/tests/parm-union.rs +++ b/bindgen-tests/tests/expectations/tests/parm-union.rs @@ -7,12 +7,14 @@ pub struct Struct { #[test] fn bindgen_test_layout_Struct() { assert_eq!( - ::std::mem::size_of:: < Struct > (), 1usize, concat!("Size of: ", - stringify!(Struct)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Struct)), ); assert_eq!( - ::std::mem::align_of:: < Struct > (), 1usize, concat!("Alignment of ", - stringify!(Struct)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Struct)), ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/private.rs b/bindgen-tests/tests/expectations/tests/private.rs index cd689979c7..2d37e95e35 100644 --- a/bindgen-tests/tests/expectations/tests/private.rs +++ b/bindgen-tests/tests/expectations/tests/private.rs @@ -11,22 +11,34 @@ fn bindgen_test_layout_HasPrivate() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < HasPrivate > (), 8usize, concat!("Size of: ", - stringify!(HasPrivate)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(HasPrivate)), ); assert_eq!( - ::std::mem::align_of:: < HasPrivate > (), 4usize, concat!("Alignment of ", - stringify!(HasPrivate)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(HasPrivate)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mNotPrivate) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(HasPrivate), "::", - stringify!(mNotPrivate)) + unsafe { ::std::ptr::addr_of!((*ptr).mNotPrivate) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(HasPrivate), + "::", + stringify!(mNotPrivate), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mIsPrivate) as usize - ptr as usize }, - 4usize, concat!("Offset of field: ", stringify!(HasPrivate), "::", - stringify!(mIsPrivate)) + unsafe { ::std::ptr::addr_of!((*ptr).mIsPrivate) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(HasPrivate), + "::", + stringify!(mIsPrivate), + ), ); } ///
@@ -41,22 +53,34 @@ fn bindgen_test_layout_VeryPrivate() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < VeryPrivate > (), 8usize, concat!("Size of: ", - stringify!(VeryPrivate)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(VeryPrivate)), ); assert_eq!( - ::std::mem::align_of:: < VeryPrivate > (), 4usize, concat!("Alignment of ", - stringify!(VeryPrivate)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(VeryPrivate)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mIsPrivate) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(VeryPrivate), "::", - stringify!(mIsPrivate)) + unsafe { ::std::ptr::addr_of!((*ptr).mIsPrivate) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(VeryPrivate), + "::", + stringify!(mIsPrivate), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mIsAlsoPrivate) as usize - ptr as usize }, - 4usize, concat!("Offset of field: ", stringify!(VeryPrivate), "::", - stringify!(mIsAlsoPrivate)) + unsafe { ::std::ptr::addr_of!((*ptr).mIsAlsoPrivate) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(VeryPrivate), + "::", + stringify!(mIsAlsoPrivate), + ), ); } ///
@@ -72,21 +96,33 @@ fn bindgen_test_layout_ContradictPrivate() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < ContradictPrivate > (), 8usize, concat!("Size of: ", - stringify!(ContradictPrivate)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(ContradictPrivate)), ); assert_eq!( - ::std::mem::align_of:: < ContradictPrivate > (), 4usize, concat!("Alignment of ", - stringify!(ContradictPrivate)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(ContradictPrivate)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mNotPrivate) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(ContradictPrivate), "::", - stringify!(mNotPrivate)) + unsafe { ::std::ptr::addr_of!((*ptr).mNotPrivate) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ContradictPrivate), + "::", + stringify!(mNotPrivate), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mIsPrivate) as usize - ptr as usize }, - 4usize, concat!("Offset of field: ", stringify!(ContradictPrivate), "::", - stringify!(mIsPrivate)) + unsafe { ::std::ptr::addr_of!((*ptr).mIsPrivate) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(ContradictPrivate), + "::", + stringify!(mIsPrivate), + ), ); } diff --git a/bindgen-tests/tests/expectations/tests/private_fields.rs b/bindgen-tests/tests/expectations/tests/private_fields.rs index 120ed85803..cc54f2856f 100644 --- a/bindgen-tests/tests/expectations/tests/private_fields.rs +++ b/bindgen-tests/tests/expectations/tests/private_fields.rs @@ -49,7 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -69,7 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -94,20 +94,24 @@ fn bindgen_test_layout_PubPriv() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < PubPriv > (), 8usize, concat!("Size of: ", - stringify!(PubPriv)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(PubPriv)), ); assert_eq!( - ::std::mem::align_of:: < PubPriv > (), 4usize, concat!("Alignment of ", - stringify!(PubPriv)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(PubPriv)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).x) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(PubPriv), "::", stringify!(x)) + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(PubPriv), "::", stringify!(x)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).y) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(PubPriv), "::", stringify!(y)) + unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(PubPriv), "::", stringify!(y)), ); } #[repr(C)] @@ -121,12 +125,14 @@ pub struct PrivateBitFields { #[test] fn bindgen_test_layout_PrivateBitFields() { assert_eq!( - ::std::mem::size_of:: < PrivateBitFields > (), 4usize, concat!("Size of: ", - stringify!(PrivateBitFields)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(PrivateBitFields)), ); assert_eq!( - ::std::mem::align_of:: < PrivateBitFields > (), 4usize, concat!("Alignment of ", - stringify!(PrivateBitFields)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(PrivateBitFields)), ); } impl PrivateBitFields { @@ -190,12 +196,14 @@ pub struct PublicBitFields { #[test] fn bindgen_test_layout_PublicBitFields() { assert_eq!( - ::std::mem::size_of:: < PublicBitFields > (), 4usize, concat!("Size of: ", - stringify!(PublicBitFields)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(PublicBitFields)), ); assert_eq!( - ::std::mem::align_of:: < PublicBitFields > (), 4usize, concat!("Alignment of ", - stringify!(PublicBitFields)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(PublicBitFields)), ); } impl PublicBitFields { @@ -259,12 +267,14 @@ pub struct MixedBitFields { #[test] fn bindgen_test_layout_MixedBitFields() { assert_eq!( - ::std::mem::size_of:: < MixedBitFields > (), 4usize, concat!("Size of: ", - stringify!(MixedBitFields)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(MixedBitFields)), ); assert_eq!( - ::std::mem::align_of:: < MixedBitFields > (), 4usize, concat!("Alignment of ", - stringify!(MixedBitFields)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(MixedBitFields)), ); } impl MixedBitFields { @@ -327,15 +337,19 @@ 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:: < Base > (), 4usize, concat!("Size of: ", stringify!(Base)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Base)), ); assert_eq!( - ::std::mem::align_of:: < Base > (), 4usize, concat!("Alignment of ", - stringify!(Base)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Base)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).member) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Base), "::", stringify!(member)) + unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Base), "::", stringify!(member)), ); } #[repr(C)] @@ -346,12 +360,14 @@ pub struct InheritsPrivately { #[test] fn bindgen_test_layout_InheritsPrivately() { assert_eq!( - ::std::mem::size_of:: < InheritsPrivately > (), 4usize, concat!("Size of: ", - stringify!(InheritsPrivately)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(InheritsPrivately)), ); assert_eq!( - ::std::mem::align_of:: < InheritsPrivately > (), 4usize, concat!("Alignment of ", - stringify!(InheritsPrivately)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(InheritsPrivately)), ); } #[repr(C)] @@ -362,12 +378,14 @@ pub struct InheritsPublically { #[test] fn bindgen_test_layout_InheritsPublically() { assert_eq!( - ::std::mem::size_of:: < InheritsPublically > (), 4usize, concat!("Size of: ", - stringify!(InheritsPublically)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(InheritsPublically)), ); assert_eq!( - ::std::mem::align_of:: < InheritsPublically > (), 4usize, - concat!("Alignment of ", stringify!(InheritsPublically)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(InheritsPublically)), ); } #[repr(C)] @@ -386,17 +404,24 @@ fn bindgen_test_layout_WithAnonStruct__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < WithAnonStruct__bindgen_ty_1 > (), 4usize, - concat!("Size of: ", stringify!(WithAnonStruct__bindgen_ty_1)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(WithAnonStruct__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < WithAnonStruct__bindgen_ty_1 > (), 4usize, - concat!("Alignment of ", stringify!(WithAnonStruct__bindgen_ty_1)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(WithAnonStruct__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(WithAnonStruct__bindgen_ty_1), "::", - stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithAnonStruct__bindgen_ty_1), + "::", + stringify!(a), + ), ); } #[repr(C)] @@ -409,28 +434,37 @@ fn bindgen_test_layout_WithAnonStruct__bindgen_ty_2() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < WithAnonStruct__bindgen_ty_2 > (), 4usize, - concat!("Size of: ", stringify!(WithAnonStruct__bindgen_ty_2)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(WithAnonStruct__bindgen_ty_2)), ); assert_eq!( - ::std::mem::align_of:: < WithAnonStruct__bindgen_ty_2 > (), 4usize, - concat!("Alignment of ", stringify!(WithAnonStruct__bindgen_ty_2)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(WithAnonStruct__bindgen_ty_2)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(WithAnonStruct__bindgen_ty_2), "::", - stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithAnonStruct__bindgen_ty_2), + "::", + stringify!(b), + ), ); } #[test] fn bindgen_test_layout_WithAnonStruct() { assert_eq!( - ::std::mem::size_of:: < WithAnonStruct > (), 8usize, concat!("Size of: ", - stringify!(WithAnonStruct)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(WithAnonStruct)), ); assert_eq!( - ::std::mem::align_of:: < WithAnonStruct > (), 4usize, concat!("Alignment of ", - stringify!(WithAnonStruct)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(WithAnonStruct)), ); } #[repr(C)] @@ -446,12 +480,14 @@ pub union WithAnonUnion__bindgen_ty_1 { #[test] fn bindgen_test_layout_WithAnonUnion__bindgen_ty_1() { assert_eq!( - ::std::mem::size_of:: < WithAnonUnion__bindgen_ty_1 > (), 1usize, - concat!("Size of: ", stringify!(WithAnonUnion__bindgen_ty_1)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(WithAnonUnion__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < WithAnonUnion__bindgen_ty_1 > (), 1usize, - concat!("Alignment of ", stringify!(WithAnonUnion__bindgen_ty_1)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(WithAnonUnion__bindgen_ty_1)), ); } impl Default for WithAnonUnion__bindgen_ty_1 { @@ -466,12 +502,14 @@ impl Default for WithAnonUnion__bindgen_ty_1 { #[test] fn bindgen_test_layout_WithAnonUnion() { assert_eq!( - ::std::mem::size_of:: < WithAnonUnion > (), 1usize, concat!("Size of: ", - stringify!(WithAnonUnion)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(WithAnonUnion)), ); assert_eq!( - ::std::mem::align_of:: < WithAnonUnion > (), 1usize, concat!("Alignment of ", - stringify!(WithAnonUnion)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(WithAnonUnion)), ); } impl Default for WithAnonUnion { @@ -499,25 +537,29 @@ fn bindgen_test_layout_Override() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < Override > (), 16usize, concat!("Size of: ", - stringify!(Override)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(Override)), ); assert_eq!( - ::std::mem::align_of:: < Override > (), 4usize, concat!("Alignment of ", - stringify!(Override)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Override)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Override), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Override), "::", stringify!(a)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(Override), "::", stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(Override), "::", stringify!(b)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).private_c) as usize - ptr as usize }, - 8usize, concat!("Offset of field: ", stringify!(Override), "::", - stringify!(private_c)) + unsafe { ::std::ptr::addr_of!((*ptr).private_c) as usize - ptr as usize }, + 8usize, + concat!("Offset of field: ", stringify!(Override), "::", stringify!(private_c)), ); } impl Override { diff --git a/bindgen-tests/tests/expectations/tests/public-dtor.rs b/bindgen-tests/tests/expectations/tests/public-dtor.rs index d125dc547a..ad0ae6d919 100644 --- a/bindgen-tests/tests/expectations/tests/public-dtor.rs +++ b/bindgen-tests/tests/expectations/tests/public-dtor.rs @@ -7,12 +7,14 @@ pub struct cv_Foo { #[test] fn bindgen_test_layout_cv_Foo() { assert_eq!( - ::std::mem::size_of:: < cv_Foo > (), 1usize, concat!("Size of: ", - stringify!(cv_Foo)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(cv_Foo)), ); assert_eq!( - ::std::mem::align_of:: < cv_Foo > (), 1usize, concat!("Alignment of ", - stringify!(cv_Foo)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(cv_Foo)), ); } extern "C" { @@ -33,11 +35,13 @@ pub struct cv_Bar { #[test] fn bindgen_test_layout_cv_Bar() { assert_eq!( - ::std::mem::size_of:: < cv_Bar > (), 1usize, concat!("Size of: ", - stringify!(cv_Bar)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(cv_Bar)), ); assert_eq!( - ::std::mem::align_of:: < cv_Bar > (), 1usize, concat!("Alignment of ", - stringify!(cv_Bar)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(cv_Bar)), ); } diff --git a/bindgen-tests/tests/expectations/tests/ref_argument_array.rs b/bindgen-tests/tests/expectations/tests/ref_argument_array.rs index 518833f75e..0ca31312fe 100644 --- a/bindgen-tests/tests/expectations/tests/ref_argument_array.rs +++ b/bindgen-tests/tests/expectations/tests/ref_argument_array.rs @@ -15,11 +15,14 @@ pub struct nsID { #[test] fn bindgen_test_layout_nsID() { assert_eq!( - ::std::mem::size_of:: < nsID > (), 8usize, concat!("Size of: ", stringify!(nsID)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(nsID)), ); assert_eq!( - ::std::mem::align_of:: < nsID > (), 8usize, concat!("Alignment of ", - stringify!(nsID)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(nsID)), ); } impl Default for nsID { diff --git a/bindgen-tests/tests/expectations/tests/reparented_replacement.rs b/bindgen-tests/tests/expectations/tests/reparented_replacement.rs index 4cab0e996b..f2f70482eb 100644 --- a/bindgen-tests/tests/expectations/tests/reparented_replacement.rs +++ b/bindgen-tests/tests/expectations/tests/reparented_replacement.rs @@ -17,17 +17,19 @@ pub mod root { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < Bar > (), 4usize, concat!("Size of: ", - stringify!(Bar)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Bar)), ); assert_eq!( - ::std::mem::align_of:: < Bar > (), 4usize, concat!("Alignment of ", - stringify!(Bar)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Bar)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).bazz) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(Bar), "::", - stringify!(bazz)) + unsafe { ::std::ptr::addr_of!((*ptr).bazz) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(bazz)), ); } } diff --git a/bindgen-tests/tests/expectations/tests/replace_use.rs b/bindgen-tests/tests/expectations/tests/replace_use.rs index 4a50938409..b21fd03cac 100644 --- a/bindgen-tests/tests/expectations/tests/replace_use.rs +++ b/bindgen-tests/tests/expectations/tests/replace_use.rs @@ -15,25 +15,31 @@ fn bindgen_test_layout_Test() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < Test > (), 4usize, concat!("Size of: ", stringify!(Test)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Test)), ); assert_eq!( - ::std::mem::align_of:: < Test > (), 4usize, concat!("Alignment of ", - stringify!(Test)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Test)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(a)), ); } #[test] fn __bindgen_test_layout_nsTArray_open0_long_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < nsTArray > (), 4usize, - concat!("Size of template specialization: ", stringify!(nsTArray)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of template specialization: ", stringify!(nsTArray)), ); assert_eq!( - ::std::mem::align_of:: < nsTArray > (), 4usize, - concat!("Alignment of template specialization: ", stringify!(nsTArray)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of template specialization: ", stringify!(nsTArray)), ); } diff --git a/bindgen-tests/tests/expectations/tests/repr-align.rs b/bindgen-tests/tests/expectations/tests/repr-align.rs index 5da572f329..b8a7f1e6ea 100644 --- a/bindgen-tests/tests/expectations/tests/repr-align.rs +++ b/bindgen-tests/tests/expectations/tests/repr-align.rs @@ -11,19 +11,21 @@ pub struct a { 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, concat!("Size of: ", stringify!(a))); assert_eq!( - ::std::mem::size_of:: < a > (), 8usize, concat!("Size of: ", stringify!(a)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(a)), ); assert_eq!( - ::std::mem::align_of:: < a > (), 8usize, concat!("Alignment of ", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(a), "::", stringify!(b)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(a), "::", stringify!(b)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).c) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(a), "::", stringify!(c)) + unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(a), "::", stringify!(c)), ); } #[repr(C)] @@ -37,18 +39,20 @@ pub struct b { 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, concat!("Size of: ", stringify!(b))); assert_eq!( - ::std::mem::size_of:: < b > (), 8usize, concat!("Size of: ", stringify!(b)) - ); - assert_eq!( - ::std::mem::align_of:: < b > (), 8usize, concat!("Alignment of ", stringify!(b)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(b)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(b), "::", stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(b), "::", stringify!(b)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).c) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(b), "::", stringify!(c)) + unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(b), "::", stringify!(c)), ); } diff --git a/bindgen-tests/tests/expectations/tests/same_struct_name_in_different_namespaces.rs b/bindgen-tests/tests/expectations/tests/same_struct_name_in_different_namespaces.rs index 3f456b0a74..cbdea272aa 100644 --- a/bindgen-tests/tests/expectations/tests/same_struct_name_in_different_namespaces.rs +++ b/bindgen-tests/tests/expectations/tests/same_struct_name_in_different_namespaces.rs @@ -15,19 +15,23 @@ fn bindgen_test_layout_JS_shadow_Zone() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < JS_shadow_Zone > (), 8usize, concat!("Size of: ", - stringify!(JS_shadow_Zone)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(JS_shadow_Zone)), ); assert_eq!( - ::std::mem::align_of:: < JS_shadow_Zone > (), 4usize, concat!("Alignment of ", - stringify!(JS_shadow_Zone)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(JS_shadow_Zone)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).x) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(JS_shadow_Zone), "::", stringify!(x)) + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(JS_shadow_Zone), "::", stringify!(x)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).y) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(JS_shadow_Zone), "::", stringify!(y)) + unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(JS_shadow_Zone), "::", stringify!(y)), ); } diff --git a/bindgen-tests/tests/expectations/tests/sentry-defined-multiple-times.rs b/bindgen-tests/tests/expectations/tests/sentry-defined-multiple-times.rs index 7d287a9e90..b881d72dfd 100644 --- a/bindgen-tests/tests/expectations/tests/sentry-defined-multiple-times.rs +++ b/bindgen-tests/tests/expectations/tests/sentry-defined-multiple-times.rs @@ -26,17 +26,27 @@ pub mod root { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < sentry > (), 1usize, concat!("Size of: ", - stringify!(sentry)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(sentry)), ); assert_eq!( - ::std::mem::align_of:: < sentry > (), 1usize, concat!("Alignment of ", - stringify!(sentry)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(sentry)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).i_am_plain_sentry) as usize - ptr - as usize }, 0usize, concat!("Offset of field: ", stringify!(sentry), - "::", stringify!(i_am_plain_sentry)) + unsafe { + ::std::ptr::addr_of!((*ptr).i_am_plain_sentry) as usize + - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(sentry), + "::", + stringify!(i_am_plain_sentry), + ), ); } #[repr(C)] @@ -47,12 +57,14 @@ pub mod root { #[test] fn bindgen_test_layout_NotTemplateWrapper() { assert_eq!( - ::std::mem::size_of:: < NotTemplateWrapper > (), 1usize, - concat!("Size of: ", stringify!(NotTemplateWrapper)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(NotTemplateWrapper)), ); assert_eq!( - ::std::mem::align_of:: < NotTemplateWrapper > (), 1usize, - concat!("Alignment of ", stringify!(NotTemplateWrapper)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(NotTemplateWrapper)), ); } #[repr(C)] @@ -65,18 +77,27 @@ pub mod root { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < NotTemplateWrapper_sentry > (), 1usize, - concat!("Size of: ", stringify!(NotTemplateWrapper_sentry)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(NotTemplateWrapper_sentry)), ); assert_eq!( - ::std::mem::align_of:: < NotTemplateWrapper_sentry > (), 1usize, - concat!("Alignment of ", stringify!(NotTemplateWrapper_sentry)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(NotTemplateWrapper_sentry)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).i_am_not_template_wrapper_sentry) - as usize - ptr as usize }, 0usize, concat!("Offset of field: ", - stringify!(NotTemplateWrapper_sentry), "::", - stringify!(i_am_not_template_wrapper_sentry)) + unsafe { + ::std::ptr::addr_of!((*ptr).i_am_not_template_wrapper_sentry) + as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(NotTemplateWrapper_sentry), + "::", + stringify!(i_am_not_template_wrapper_sentry), + ), ); } #[repr(C)] @@ -94,30 +115,40 @@ pub mod root { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < InlineNotTemplateWrapper_sentry > (), 1usize, - concat!("Size of: ", stringify!(InlineNotTemplateWrapper_sentry)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(InlineNotTemplateWrapper_sentry)), ); assert_eq!( - ::std::mem::align_of:: < InlineNotTemplateWrapper_sentry > (), 1usize, - concat!("Alignment of ", stringify!(InlineNotTemplateWrapper_sentry)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(InlineNotTemplateWrapper_sentry)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr) - .i_am_inline_not_template_wrapper_sentry) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", - stringify!(InlineNotTemplateWrapper_sentry), "::", - stringify!(i_am_inline_not_template_wrapper_sentry)) + unsafe { + ::std::ptr::addr_of!((*ptr).i_am_inline_not_template_wrapper_sentry) + as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(InlineNotTemplateWrapper_sentry), + "::", + stringify!(i_am_inline_not_template_wrapper_sentry), + ), ); } #[test] fn bindgen_test_layout_InlineNotTemplateWrapper() { assert_eq!( - ::std::mem::size_of:: < InlineNotTemplateWrapper > (), 1usize, - concat!("Size of: ", stringify!(InlineNotTemplateWrapper)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(InlineNotTemplateWrapper)), ); assert_eq!( - ::std::mem::align_of:: < InlineNotTemplateWrapper > (), 1usize, - concat!("Alignment of ", stringify!(InlineNotTemplateWrapper)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(InlineNotTemplateWrapper)), ); } #[repr(C)] @@ -143,25 +174,30 @@ pub mod root { #[test] fn bindgen_test_layout_OuterDoubleWrapper_InnerDoubleWrapper() { assert_eq!( - ::std::mem::size_of:: < OuterDoubleWrapper_InnerDoubleWrapper > (), - 1usize, concat!("Size of: ", - stringify!(OuterDoubleWrapper_InnerDoubleWrapper)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(OuterDoubleWrapper_InnerDoubleWrapper)), ); assert_eq!( - ::std::mem::align_of:: < OuterDoubleWrapper_InnerDoubleWrapper > (), - 1usize, concat!("Alignment of ", - stringify!(OuterDoubleWrapper_InnerDoubleWrapper)) + ::std::mem::align_of::(), + 1usize, + concat!( + "Alignment of ", + stringify!(OuterDoubleWrapper_InnerDoubleWrapper), + ), ); } #[test] fn bindgen_test_layout_OuterDoubleWrapper() { assert_eq!( - ::std::mem::size_of:: < OuterDoubleWrapper > (), 1usize, - concat!("Size of: ", stringify!(OuterDoubleWrapper)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(OuterDoubleWrapper)), ); assert_eq!( - ::std::mem::align_of:: < OuterDoubleWrapper > (), 1usize, - concat!("Alignment of ", stringify!(OuterDoubleWrapper)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(OuterDoubleWrapper)), ); } #[repr(C)] @@ -176,20 +212,33 @@ pub mod root { > = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < OuterDoubleWrapper_InnerDoubleWrapper_sentry > - (), 4usize, concat!("Size of: ", - stringify!(OuterDoubleWrapper_InnerDoubleWrapper_sentry)) + ::std::mem::size_of::(), + 4usize, + concat!( + "Size of: ", + stringify!(OuterDoubleWrapper_InnerDoubleWrapper_sentry), + ), ); assert_eq!( - ::std::mem::align_of:: < OuterDoubleWrapper_InnerDoubleWrapper_sentry > - (), 4usize, concat!("Alignment of ", - stringify!(OuterDoubleWrapper_InnerDoubleWrapper_sentry)) + ::std::mem::align_of::(), + 4usize, + concat!( + "Alignment of ", + stringify!(OuterDoubleWrapper_InnerDoubleWrapper_sentry), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).i_am_double_wrapper_sentry) as - usize - ptr as usize }, 0usize, concat!("Offset of field: ", - stringify!(OuterDoubleWrapper_InnerDoubleWrapper_sentry), "::", - stringify!(i_am_double_wrapper_sentry)) + unsafe { + ::std::ptr::addr_of!((*ptr).i_am_double_wrapper_sentry) as usize + - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(OuterDoubleWrapper_InnerDoubleWrapper_sentry), + "::", + stringify!(i_am_double_wrapper_sentry), + ), ); } #[repr(C)] @@ -214,47 +263,73 @@ pub mod root { > = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < - OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry > (), 4usize, - concat!("Size of: ", - stringify!(OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry)) + ::std::mem::size_of::< + OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry, + >(), + 4usize, + concat!( + "Size of: ", + stringify!(OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry), + ), ); assert_eq!( - ::std::mem::align_of:: < - OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry > (), 4usize, - concat!("Alignment of ", - stringify!(OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry)) + ::std::mem::align_of::< + OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry, + >(), + 4usize, + concat!( + "Alignment of ", + stringify!(OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).i_am_double_wrapper_inline_sentry) - as usize - ptr as usize }, 0usize, concat!("Offset of field: ", - stringify!(OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry), - "::", stringify!(i_am_double_wrapper_inline_sentry)) + unsafe { + ::std::ptr::addr_of!((*ptr).i_am_double_wrapper_inline_sentry) + as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry), + "::", + stringify!(i_am_double_wrapper_inline_sentry), + ), ); } #[test] fn bindgen_test_layout_OuterDoubleInlineWrapper_InnerDoubleInlineWrapper() { assert_eq!( - ::std::mem::size_of:: < OuterDoubleInlineWrapper_InnerDoubleInlineWrapper - > (), 1usize, concat!("Size of: ", - stringify!(OuterDoubleInlineWrapper_InnerDoubleInlineWrapper)) + ::std::mem::size_of::< + OuterDoubleInlineWrapper_InnerDoubleInlineWrapper, + >(), + 1usize, + concat!( + "Size of: ", + stringify!(OuterDoubleInlineWrapper_InnerDoubleInlineWrapper), + ), ); assert_eq!( - ::std::mem::align_of:: < - OuterDoubleInlineWrapper_InnerDoubleInlineWrapper > (), 1usize, - concat!("Alignment of ", - stringify!(OuterDoubleInlineWrapper_InnerDoubleInlineWrapper)) + ::std::mem::align_of::< + OuterDoubleInlineWrapper_InnerDoubleInlineWrapper, + >(), + 1usize, + concat!( + "Alignment of ", + stringify!(OuterDoubleInlineWrapper_InnerDoubleInlineWrapper), + ), ); } #[test] fn bindgen_test_layout_OuterDoubleInlineWrapper() { assert_eq!( - ::std::mem::size_of:: < OuterDoubleInlineWrapper > (), 1usize, - concat!("Size of: ", stringify!(OuterDoubleInlineWrapper)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(OuterDoubleInlineWrapper)), ); assert_eq!( - ::std::mem::align_of:: < OuterDoubleInlineWrapper > (), 1usize, - concat!("Alignment of ", stringify!(OuterDoubleInlineWrapper)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(OuterDoubleInlineWrapper)), ); } } @@ -278,17 +353,27 @@ pub mod root { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < sentry > (), 4usize, concat!("Size of: ", - stringify!(sentry)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(sentry)), ); assert_eq!( - ::std::mem::align_of:: < sentry > (), 4usize, concat!("Alignment of ", - stringify!(sentry)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(sentry)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).i_am_outside_namespace_sentry) as usize - - ptr as usize }, 0usize, concat!("Offset of field: ", stringify!(sentry), - "::", stringify!(i_am_outside_namespace_sentry)) + unsafe { + ::std::ptr::addr_of!((*ptr).i_am_outside_namespace_sentry) as usize + - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(sentry), + "::", + stringify!(i_am_outside_namespace_sentry), + ), ); } } diff --git a/bindgen-tests/tests/expectations/tests/size_t_template.rs b/bindgen-tests/tests/expectations/tests/size_t_template.rs index 1ccc74c7ed..3e37508b6a 100644 --- a/bindgen-tests/tests/expectations/tests/size_t_template.rs +++ b/bindgen-tests/tests/expectations/tests/size_t_template.rs @@ -8,14 +8,15 @@ pub struct C { 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::(), 12usize, concat!("Size of: ", stringify!(C))); assert_eq!( - ::std::mem::size_of:: < C > (), 12usize, concat!("Size of: ", stringify!(C)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(C)), ); assert_eq!( - ::std::mem::align_of:: < C > (), 4usize, concat!("Alignment of ", stringify!(C)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).arr) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(arr)) + unsafe { ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(arr)), ); } diff --git a/bindgen-tests/tests/expectations/tests/sorted_items.rs b/bindgen-tests/tests/expectations/tests/sorted_items.rs index 9d4c451dab..e7da5e67fd 100644 --- a/bindgen-tests/tests/expectations/tests/sorted_items.rs +++ b/bindgen-tests/tests/expectations/tests/sorted_items.rs @@ -20,20 +20,24 @@ pub mod root { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < Point > (), 8usize, concat!("Size of: ", - stringify!(Point)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Point)), ); assert_eq!( - ::std::mem::align_of:: < Point > (), 4usize, concat!("Alignment of ", - stringify!(Point)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Point)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).x) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Point), "::", stringify!(x)) + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Point), "::", stringify!(x)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).y) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(Point), "::", stringify!(y)) + unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(Point), "::", stringify!(y)), ); } #[test] @@ -41,20 +45,24 @@ pub mod root { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < Angle > (), 8usize, concat!("Size of: ", - stringify!(Angle)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Angle)), ); assert_eq!( - ::std::mem::align_of:: < Angle > (), 4usize, concat!("Alignment of ", - stringify!(Angle)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Angle)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Angle), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Angle), "::", stringify!(a)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(Angle), "::", stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(Angle), "::", stringify!(b)), ); } pub mod ns { @@ -77,22 +85,24 @@ pub mod root { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < Point > (), 8usize, concat!("Size of: ", - stringify!(Point)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Point)), ); assert_eq!( - ::std::mem::align_of:: < Point > (), 4usize, concat!("Alignment of ", - stringify!(Point)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Point)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).x) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(Point), "::", - stringify!(x)) + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Point), "::", stringify!(x)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).y) as usize - ptr as usize }, - 4usize, concat!("Offset of field: ", stringify!(Point), "::", - stringify!(y)) + unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(Point), "::", stringify!(y)), ); } #[test] @@ -100,22 +110,24 @@ pub mod root { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < Angle > (), 8usize, concat!("Size of: ", - stringify!(Angle)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Angle)), ); assert_eq!( - ::std::mem::align_of:: < Angle > (), 4usize, concat!("Alignment of ", - stringify!(Angle)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Angle)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(Angle), "::", - stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Angle), "::", stringify!(a)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, - 4usize, concat!("Offset of field: ", stringify!(Angle), "::", - stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(Angle), "::", stringify!(b)), ); } #[allow(unused_imports)] diff --git a/bindgen-tests/tests/expectations/tests/stdint_typedef.rs b/bindgen-tests/tests/expectations/tests/stdint_typedef.rs index 31d3b5c5e7..34c71831da 100644 --- a/bindgen-tests/tests/expectations/tests/stdint_typedef.rs +++ b/bindgen-tests/tests/expectations/tests/stdint_typedef.rs @@ -12,15 +12,18 @@ fn bindgen_test_layout_Struct() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < Struct > (), 8usize, concat!("Size of: ", - stringify!(Struct)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Struct)), ); assert_eq!( - ::std::mem::align_of:: < Struct > (), 8usize, concat!("Alignment of ", - stringify!(Struct)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Struct)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).field) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Struct), "::", stringify!(field)) + unsafe { ::std::ptr::addr_of!((*ptr).field) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Struct), "::", stringify!(field)), ); } diff --git a/bindgen-tests/tests/expectations/tests/struct_containing_forward_declared_struct.rs b/bindgen-tests/tests/expectations/tests/struct_containing_forward_declared_struct.rs index e0ab49cdda..60c093c79a 100644 --- a/bindgen-tests/tests/expectations/tests/struct_containing_forward_declared_struct.rs +++ b/bindgen-tests/tests/expectations/tests/struct_containing_forward_declared_struct.rs @@ -8,15 +8,16 @@ pub struct a { 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, concat!("Size of: ", stringify!(a))); assert_eq!( - ::std::mem::size_of:: < a > (), 8usize, concat!("Size of: ", stringify!(a)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(a)), ); assert_eq!( - ::std::mem::align_of:: < a > (), 8usize, concat!("Alignment of ", stringify!(a)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).val_a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(a), "::", stringify!(val_a)) + unsafe { ::std::ptr::addr_of!((*ptr).val_a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(a), "::", stringify!(val_a)), ); } impl Default for a { @@ -37,14 +38,15 @@ pub struct b { 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::(), 4usize, concat!("Size of: ", stringify!(b))); assert_eq!( - ::std::mem::size_of:: < b > (), 4usize, concat!("Size of: ", stringify!(b)) - ); - assert_eq!( - ::std::mem::align_of:: < b > (), 4usize, concat!("Alignment of ", stringify!(b)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(b)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).val_b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(b), "::", stringify!(val_b)) + unsafe { ::std::ptr::addr_of!((*ptr).val_b) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(b), "::", stringify!(val_b)), ); } diff --git a/bindgen-tests/tests/expectations/tests/struct_typedef.rs b/bindgen-tests/tests/expectations/tests/struct_typedef.rs index 4d39123e43..2c0039e3f0 100644 --- a/bindgen-tests/tests/expectations/tests/struct_typedef.rs +++ b/bindgen-tests/tests/expectations/tests/struct_typedef.rs @@ -9,17 +9,24 @@ fn bindgen_test_layout_typedef_named_struct() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < typedef_named_struct > (), 1usize, concat!("Size of: ", - stringify!(typedef_named_struct)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(typedef_named_struct)), ); assert_eq!( - ::std::mem::align_of:: < typedef_named_struct > (), 1usize, - concat!("Alignment of ", stringify!(typedef_named_struct)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(typedef_named_struct)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).has_name) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(typedef_named_struct), "::", - stringify!(has_name)) + unsafe { ::std::ptr::addr_of!((*ptr).has_name) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(typedef_named_struct), + "::", + stringify!(has_name), + ), ); } #[repr(C)] @@ -32,17 +39,24 @@ fn bindgen_test_layout__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit<_bindgen_ty_1> = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < _bindgen_ty_1 > (), 8usize, concat!("Size of: ", - stringify!(_bindgen_ty_1)) + ::std::mem::size_of::<_bindgen_ty_1>(), + 8usize, + concat!("Size of: ", stringify!(_bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < _bindgen_ty_1 > (), 8usize, concat!("Alignment of ", - stringify!(_bindgen_ty_1)) + ::std::mem::align_of::<_bindgen_ty_1>(), + 8usize, + concat!("Alignment of ", stringify!(_bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).no_name) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(_bindgen_ty_1), "::", - stringify!(no_name)) + unsafe { ::std::ptr::addr_of!((*ptr).no_name) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_bindgen_ty_1), + "::", + stringify!(no_name), + ), ); } impl Default for _bindgen_ty_1 { diff --git a/bindgen-tests/tests/expectations/tests/struct_typedef_ns.rs b/bindgen-tests/tests/expectations/tests/struct_typedef_ns.rs index bf35121d99..44afa4822a 100644 --- a/bindgen-tests/tests/expectations/tests/struct_typedef_ns.rs +++ b/bindgen-tests/tests/expectations/tests/struct_typedef_ns.rs @@ -16,17 +16,24 @@ pub mod root { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < typedef_struct > (), 4usize, concat!("Size of: ", - stringify!(typedef_struct)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(typedef_struct)), ); assert_eq!( - ::std::mem::align_of:: < typedef_struct > (), 4usize, - concat!("Alignment of ", stringify!(typedef_struct)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(typedef_struct)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).foo) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(typedef_struct), "::", - stringify!(foo)) + unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(typedef_struct), + "::", + stringify!(foo), + ), ); } #[repr(u32)] @@ -48,17 +55,24 @@ pub mod root { const UNINIT: ::std::mem::MaybeUninit<_bindgen_ty_1> = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < _bindgen_ty_1 > (), 4usize, concat!("Size of: ", - stringify!(_bindgen_ty_1)) + ::std::mem::size_of::<_bindgen_ty_1>(), + 4usize, + concat!("Size of: ", stringify!(_bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < _bindgen_ty_1 > (), 4usize, - concat!("Alignment of ", stringify!(_bindgen_ty_1)) + ::std::mem::align_of::<_bindgen_ty_1>(), + 4usize, + concat!("Alignment of ", stringify!(_bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).foo) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(_bindgen_ty_1), "::", - stringify!(foo)) + unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_bindgen_ty_1), + "::", + stringify!(foo), + ), ); } pub type typedef_struct = root::_bindgen_mod_id_12::_bindgen_ty_1; diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_struct.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_struct.rs index 856fc60b25..d5ea2224b4 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_struct.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_anon_struct.rs @@ -15,20 +15,24 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < foo__bindgen_ty_1 > (), 8usize, concat!("Size of: ", - stringify!(foo__bindgen_ty_1)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", - stringify!(foo__bindgen_ty_1)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)), ); } #[test] @@ -36,14 +40,18 @@ 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:: < foo > (), 8usize, concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(foo)), ); assert_eq!( - ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", - stringify!(foo)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)), ); } diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_struct_array.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_struct_array.rs index 3423aba181..ba3f82a86f 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_struct_array.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_anon_struct_array.rs @@ -16,20 +16,24 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < foo__bindgen_ty_1 > (), 8usize, concat!("Size of: ", - stringify!(foo__bindgen_ty_1)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", - stringify!(foo__bindgen_ty_1)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)), ); } #[repr(C)] @@ -43,20 +47,24 @@ fn bindgen_test_layout_foo__bindgen_ty_2() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < foo__bindgen_ty_2 > (), 8usize, concat!("Size of: ", - stringify!(foo__bindgen_ty_2)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_2)), ); assert_eq!( - ::std::mem::align_of:: < foo__bindgen_ty_2 > (), 4usize, concat!("Alignment of ", - stringify!(foo__bindgen_ty_2)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo__bindgen_ty_2)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_2), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_2), "::", stringify!(a)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_2), "::", stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_2), "::", stringify!(b)), ); } #[test] @@ -64,18 +72,23 @@ 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:: < foo > (), 208usize, concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of::(), + 208usize, + concat!("Size of: ", stringify!(foo)), ); assert_eq!( - ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", - stringify!(foo)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).baz) as usize - ptr as usize }, 16usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(baz)) + unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, + 16usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(baz)), ); } diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_struct_pointer.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_struct_pointer.rs index aeb5c10984..77a89934b0 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_struct_pointer.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_anon_struct_pointer.rs @@ -15,20 +15,24 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < foo__bindgen_ty_1 > (), 8usize, concat!("Size of: ", - stringify!(foo__bindgen_ty_1)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", - stringify!(foo__bindgen_ty_1)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)), ); } #[test] @@ -36,15 +40,19 @@ 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:: < foo > (), 8usize, concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(foo)), ); assert_eq!( - ::std::mem::align_of:: < foo > (), 8usize, concat!("Alignment of ", - stringify!(foo)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)), ); } impl Default for foo { diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_union.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_union.rs index 322bcdd288..506b6a8819 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_union.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_anon_union.rs @@ -15,20 +15,24 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Size of: ", - stringify!(foo__bindgen_ty_1)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", - stringify!(foo__bindgen_ty_1)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)), ); } impl Default for foo__bindgen_ty_1 { @@ -45,15 +49,19 @@ 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:: < foo > (), 4usize, concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo)), ); assert_eq!( - ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", - stringify!(foo)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)), ); } impl Default for foo { diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_union_1_0.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_union_1_0.rs index 74d4139515..9831363dc8 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_anon_union_1_0.rs @@ -59,20 +59,24 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Size of: ", - stringify!(foo__bindgen_ty_1)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", - stringify!(foo__bindgen_ty_1)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)), ); } impl Clone for foo__bindgen_ty_1 { @@ -85,15 +89,19 @@ 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:: < foo > (), 4usize, concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo)), ); assert_eq!( - ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", - stringify!(foo)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)), ); } impl Clone for foo { diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_struct.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_struct.rs index 606f28e031..981dd648be 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_struct.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_struct.rs @@ -15,29 +15,36 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < foo__bindgen_ty_1 > (), 8usize, concat!("Size of: ", - stringify!(foo__bindgen_ty_1)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", - stringify!(foo__bindgen_ty_1)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)), ); } #[test] fn bindgen_test_layout_foo() { assert_eq!( - ::std::mem::size_of:: < foo > (), 8usize, concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(foo)), ); assert_eq!( - ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", - stringify!(foo)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo)), ); } diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union.rs index 309622ab4b..3d0175354f 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union.rs @@ -15,20 +15,24 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Size of: ", - stringify!(foo__bindgen_ty_1)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", - stringify!(foo__bindgen_ty_1)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)), ); } impl Default for foo__bindgen_ty_1 { @@ -43,11 +47,14 @@ impl Default for foo__bindgen_ty_1 { #[test] fn bindgen_test_layout_foo() { assert_eq!( - ::std::mem::size_of:: < foo > (), 4usize, concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo)), ); assert_eq!( - ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", - stringify!(foo)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo)), ); } impl Default for foo { diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs index b7e5b2c98e..291526fd58 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs @@ -59,20 +59,24 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Size of: ", - stringify!(foo__bindgen_ty_1)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", - stringify!(foo__bindgen_ty_1)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)), ); } impl Clone for foo__bindgen_ty_1 { @@ -83,11 +87,14 @@ impl Clone for foo__bindgen_ty_1 { #[test] fn bindgen_test_layout_foo() { assert_eq!( - ::std::mem::size_of:: < foo > (), 4usize, concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo)), ); assert_eq!( - ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", - stringify!(foo)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo)), ); } impl Clone for foo { diff --git a/bindgen-tests/tests/expectations/tests/struct_with_bitfields.rs b/bindgen-tests/tests/expectations/tests/struct_with_bitfields.rs index 113d4b5441..6a6b17e341 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_bitfields.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_bitfields.rs @@ -49,7 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -69,7 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -97,16 +97,19 @@ fn bindgen_test_layout_bitfield() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < bitfield > (), 16usize, concat!("Size of: ", - stringify!(bitfield)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(bitfield)), ); assert_eq!( - ::std::mem::align_of:: < bitfield > (), 4usize, concat!("Alignment of ", - stringify!(bitfield)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(bitfield)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).e) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(bitfield), "::", stringify!(e)) + unsafe { ::std::ptr::addr_of!((*ptr).e) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(bitfield), "::", stringify!(e)), ); } impl bitfield { 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 90992689b5..b84fa7b2c0 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_derive_debug.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_derive_debug.rs @@ -9,16 +9,19 @@ 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:: < LittleArray > (), 128usize, concat!("Size of: ", - stringify!(LittleArray)) + ::std::mem::size_of::(), + 128usize, + concat!("Size of: ", stringify!(LittleArray)), ); assert_eq!( - ::std::mem::align_of:: < LittleArray > (), 4usize, concat!("Alignment of ", - stringify!(LittleArray)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(LittleArray)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(LittleArray), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(LittleArray), "::", stringify!(a)), ); } #[repr(C)] @@ -31,16 +34,19 @@ 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:: < BigArray > (), 132usize, concat!("Size of: ", - stringify!(BigArray)) + ::std::mem::size_of::(), + 132usize, + concat!("Size of: ", stringify!(BigArray)), ); assert_eq!( - ::std::mem::align_of:: < BigArray > (), 4usize, concat!("Alignment of ", - stringify!(BigArray)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(BigArray)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(BigArray), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(BigArray), "::", stringify!(a)), ); } impl Default for BigArray { @@ -62,16 +68,19 @@ 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:: < WithLittleArray > (), 128usize, concat!("Size of: ", - stringify!(WithLittleArray)) + ::std::mem::size_of::(), + 128usize, + concat!("Size of: ", stringify!(WithLittleArray)), ); assert_eq!( - ::std::mem::align_of:: < WithLittleArray > (), 4usize, concat!("Alignment of ", - stringify!(WithLittleArray)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(WithLittleArray)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(WithLittleArray), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(WithLittleArray), "::", stringify!(a)), ); } #[repr(C)] @@ -84,16 +93,19 @@ 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:: < WithBigArray > (), 132usize, concat!("Size of: ", - stringify!(WithBigArray)) + ::std::mem::size_of::(), + 132usize, + concat!("Size of: ", stringify!(WithBigArray)), ); assert_eq!( - ::std::mem::align_of:: < WithBigArray > (), 4usize, concat!("Alignment of ", - stringify!(WithBigArray)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(WithBigArray)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(WithBigArray), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(WithBigArray), "::", stringify!(a)), ); } impl Default for WithBigArray { 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 4cdf5bb055..74b409235d 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_large_array.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_large_array.rs @@ -8,16 +8,16 @@ pub struct S { 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, concat!("Size of: ", stringify!(S))); assert_eq!( - ::std::mem::size_of:: < S > (), 33usize, concat!("Size of: ", stringify!(S)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(S)), ); assert_eq!( - ::std::mem::align_of:: < S > (), 1usize, concat!("Alignment of ", stringify!(S)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).large_array) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(S), "::", - stringify!(large_array)) + unsafe { ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(S), "::", stringify!(large_array)), ); } impl Default for S { diff --git a/bindgen-tests/tests/expectations/tests/struct_with_nesting.rs b/bindgen-tests/tests/expectations/tests/struct_with_nesting.rs index 1e92d7ecf1..1bcba5a154 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_nesting.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_nesting.rs @@ -23,22 +23,34 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < foo__bindgen_ty_1__bindgen_ty_1 > (), 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < foo__bindgen_ty_1__bindgen_ty_1 > (), 2usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)) + ::std::mem::align_of::(), + 2usize, + concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).c1) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1__bindgen_ty_1), "::", - stringify!(c1)) + unsafe { ::std::ptr::addr_of!((*ptr).c1) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(c1), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).c2) as usize - ptr as usize }, 2usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1__bindgen_ty_1), "::", - stringify!(c2)) + unsafe { ::std::ptr::addr_of!((*ptr).c2) as usize - ptr as usize }, + 2usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(c2), + ), ); } #[repr(C)] @@ -54,32 +66,54 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < foo__bindgen_ty_1__bindgen_ty_2 > (), 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)), ); assert_eq!( - ::std::mem::align_of:: < foo__bindgen_ty_1__bindgen_ty_2 > (), 1usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).d1) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2), "::", - stringify!(d1)) + unsafe { ::std::ptr::addr_of!((*ptr).d1) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(d1), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).d2) as usize - ptr as usize }, 1usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2), "::", - stringify!(d2)) + unsafe { ::std::ptr::addr_of!((*ptr).d2) as usize - ptr as usize }, + 1usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(d2), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).d3) as usize - ptr as usize }, 2usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2), "::", - stringify!(d3)) + unsafe { ::std::ptr::addr_of!((*ptr).d3) as usize - ptr as usize }, + 2usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(d3), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).d4) as usize - ptr as usize }, 3usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2), "::", - stringify!(d4)) + unsafe { ::std::ptr::addr_of!((*ptr).d4) as usize - ptr as usize }, + 3usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(d4), + ), ); } #[test] @@ -87,16 +121,19 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Size of: ", - stringify!(foo__bindgen_ty_1)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", - stringify!(foo__bindgen_ty_1)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)), ); } impl Default for foo__bindgen_ty_1 { @@ -113,15 +150,19 @@ 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:: < foo > (), 8usize, concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(foo)), ); assert_eq!( - ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", - stringify!(foo)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)), ); } impl Default for foo { diff --git a/bindgen-tests/tests/expectations/tests/struct_with_nesting_1_0.rs b/bindgen-tests/tests/expectations/tests/struct_with_nesting_1_0.rs index f6aacb7de1..f44a319470 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_nesting_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_nesting_1_0.rs @@ -67,22 +67,34 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < foo__bindgen_ty_1__bindgen_ty_1 > (), 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < foo__bindgen_ty_1__bindgen_ty_1 > (), 2usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)) + ::std::mem::align_of::(), + 2usize, + concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).c1) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1__bindgen_ty_1), "::", - stringify!(c1)) + unsafe { ::std::ptr::addr_of!((*ptr).c1) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(c1), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).c2) as usize - ptr as usize }, 2usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1__bindgen_ty_1), "::", - stringify!(c2)) + unsafe { ::std::ptr::addr_of!((*ptr).c2) as usize - ptr as usize }, + 2usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(c2), + ), ); } impl Clone for foo__bindgen_ty_1__bindgen_ty_1 { @@ -103,32 +115,54 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < foo__bindgen_ty_1__bindgen_ty_2 > (), 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)), ); assert_eq!( - ::std::mem::align_of:: < foo__bindgen_ty_1__bindgen_ty_2 > (), 1usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).d1) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2), "::", - stringify!(d1)) + unsafe { ::std::ptr::addr_of!((*ptr).d1) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(d1), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).d2) as usize - ptr as usize }, 1usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2), "::", - stringify!(d2)) + unsafe { ::std::ptr::addr_of!((*ptr).d2) as usize - ptr as usize }, + 1usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(d2), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).d3) as usize - ptr as usize }, 2usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2), "::", - stringify!(d3)) + unsafe { ::std::ptr::addr_of!((*ptr).d3) as usize - ptr as usize }, + 2usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(d3), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).d4) as usize - ptr as usize }, 3usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2), "::", - stringify!(d4)) + unsafe { ::std::ptr::addr_of!((*ptr).d4) as usize - ptr as usize }, + 3usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(d4), + ), ); } impl Clone for foo__bindgen_ty_1__bindgen_ty_2 { @@ -141,16 +175,19 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Size of: ", - stringify!(foo__bindgen_ty_1)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", - stringify!(foo__bindgen_ty_1)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)), ); } impl Clone for foo__bindgen_ty_1 { @@ -163,15 +200,19 @@ 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:: < foo > (), 8usize, concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(foo)), ); assert_eq!( - ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", - stringify!(foo)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)), ); } impl Clone for foo { diff --git a/bindgen-tests/tests/expectations/tests/struct_with_packing.rs b/bindgen-tests/tests/expectations/tests/struct_with_packing.rs index 05cc10eb27..252756e86c 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_packing.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_packing.rs @@ -9,18 +9,20 @@ pub struct a { 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::(), 3usize, concat!("Size of: ", stringify!(a))); assert_eq!( - ::std::mem::size_of:: < a > (), 3usize, concat!("Size of: ", stringify!(a)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(a)), ); assert_eq!( - ::std::mem::align_of:: < a > (), 1usize, concat!("Alignment of ", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(a), "::", stringify!(b)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(a), "::", stringify!(b)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).c) as usize - ptr as usize }, 1usize, - concat!("Offset of field: ", stringify!(a), "::", stringify!(c)) + unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, + 1usize, + concat!("Offset of field: ", stringify!(a), "::", stringify!(c)), ); } diff --git a/bindgen-tests/tests/expectations/tests/struct_with_struct.rs b/bindgen-tests/tests/expectations/tests/struct_with_struct.rs index 1f56e71b83..db6f32a57e 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_struct.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_struct.rs @@ -15,20 +15,24 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < foo__bindgen_ty_1 > (), 8usize, concat!("Size of: ", - stringify!(foo__bindgen_ty_1)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", - stringify!(foo__bindgen_ty_1)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).x) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(x)) + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(x)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).y) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(y)) + unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(y)), ); } #[test] @@ -36,14 +40,18 @@ 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:: < foo > (), 8usize, concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(foo)), ); assert_eq!( - ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", - stringify!(foo)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)), ); } diff --git a/bindgen-tests/tests/expectations/tests/template.rs b/bindgen-tests/tests/expectations/tests/template.rs index 4b9c99c31b..d43d4dd1a8 100644 --- a/bindgen-tests/tests/expectations/tests/template.rs +++ b/bindgen-tests/tests/expectations/tests/template.rs @@ -65,83 +65,101 @@ 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:: < C > (), 104usize, concat!("Size of: ", stringify!(C)) + ::std::mem::size_of::(), + 104usize, + concat!("Size of: ", stringify!(C)), ); assert_eq!( - ::std::mem::align_of:: < C > (), 8usize, concat!("Alignment of ", stringify!(C)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(C)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mB) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(mB)) + unsafe { ::std::ptr::addr_of!((*ptr).mB) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(mB)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mBConstPtr) as usize - ptr as usize }, - 8usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(mBConstPtr)) + unsafe { ::std::ptr::addr_of!((*ptr).mBConstPtr) as usize - ptr as usize }, + 8usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(mBConstPtr)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mBConstStructPtr) as usize - ptr as usize - }, 16usize, concat!("Offset of field: ", stringify!(C), "::", - stringify!(mBConstStructPtr)) + unsafe { ::std::ptr::addr_of!((*ptr).mBConstStructPtr) as usize - ptr as usize }, + 16usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(mBConstStructPtr)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mBConstStructPtrArray) as usize - ptr as - usize }, 24usize, concat!("Offset of field: ", stringify!(C), "::", - stringify!(mBConstStructPtrArray)) + unsafe { + ::std::ptr::addr_of!((*ptr).mBConstStructPtrArray) as usize - ptr as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(C), + "::", + stringify!(mBConstStructPtrArray), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mBConst) as usize - ptr as usize }, - 32usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(mBConst)) + unsafe { ::std::ptr::addr_of!((*ptr).mBConst) as usize - ptr as usize }, + 32usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(mBConst)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mBVolatile) as usize - ptr as usize }, - 36usize, concat!("Offset of field: ", stringify!(C), "::", - stringify!(mBVolatile)) + unsafe { ::std::ptr::addr_of!((*ptr).mBVolatile) as usize - ptr as usize }, + 36usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(mBVolatile)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mBConstBool) as usize - ptr as usize }, - 40usize, concat!("Offset of field: ", stringify!(C), "::", - stringify!(mBConstBool)) + unsafe { ::std::ptr::addr_of!((*ptr).mBConstBool) as usize - ptr as usize }, + 40usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(mBConstBool)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mBConstChar) as usize - ptr as usize }, - 42usize, concat!("Offset of field: ", stringify!(C), "::", - stringify!(mBConstChar)) + unsafe { ::std::ptr::addr_of!((*ptr).mBConstChar) as usize - ptr as usize }, + 42usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(mBConstChar)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mBArray) as usize - ptr as usize }, - 44usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(mBArray)) + unsafe { ::std::ptr::addr_of!((*ptr).mBArray) as usize - ptr as usize }, + 44usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(mBArray)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mBPtrArray) as usize - ptr as usize }, - 48usize, concat!("Offset of field: ", stringify!(C), "::", - stringify!(mBPtrArray)) + unsafe { ::std::ptr::addr_of!((*ptr).mBPtrArray) as usize - ptr as usize }, + 48usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(mBPtrArray)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mBArrayPtr) as usize - ptr as usize }, - 56usize, concat!("Offset of field: ", stringify!(C), "::", - stringify!(mBArrayPtr)) + unsafe { ::std::ptr::addr_of!((*ptr).mBArrayPtr) as usize - ptr as usize }, + 56usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(mBArrayPtr)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mBRef) as usize - ptr as usize }, 64usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(mBRef)) + unsafe { ::std::ptr::addr_of!((*ptr).mBRef) as usize - ptr as usize }, + 64usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(mBRef)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mBConstRef) as usize - ptr as usize }, - 72usize, concat!("Offset of field: ", stringify!(C), "::", - stringify!(mBConstRef)) + unsafe { ::std::ptr::addr_of!((*ptr).mBConstRef) as usize - ptr as usize }, + 72usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(mBConstRef)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mPtrRef) as usize - ptr as usize }, - 80usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(mPtrRef)) + unsafe { ::std::ptr::addr_of!((*ptr).mPtrRef) as usize - ptr as usize }, + 80usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(mPtrRef)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mArrayRef) as usize - ptr as usize }, - 88usize, concat!("Offset of field: ", stringify!(C), "::", stringify!(mArrayRef)) + unsafe { ::std::ptr::addr_of!((*ptr).mArrayRef) as usize - ptr as usize }, + 88usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(mArrayRef)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mBConstArray) as usize - ptr as usize }, - 96usize, concat!("Offset of field: ", stringify!(C), "::", - stringify!(mBConstArray)) + unsafe { ::std::ptr::addr_of!((*ptr).mBConstArray) as usize - ptr as usize }, + 96usize, + concat!("Offset of field: ", stringify!(C), "::", stringify!(mBConstArray)), ); } impl Default for C { @@ -211,16 +229,19 @@ fn bindgen_test_layout_RootedContainer() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < RootedContainer > (), 24usize, concat!("Size of: ", - stringify!(RootedContainer)) + ::std::mem::size_of::(), + 24usize, + concat!("Size of: ", stringify!(RootedContainer)), ); assert_eq!( - ::std::mem::align_of:: < RootedContainer > (), 8usize, concat!("Alignment of ", - stringify!(RootedContainer)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(RootedContainer)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).root) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(RootedContainer), "::", stringify!(root)) + unsafe { ::std::ptr::addr_of!((*ptr).root) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(RootedContainer), "::", stringify!(root)), ); } impl Default for RootedContainer { @@ -258,17 +279,24 @@ fn bindgen_test_layout_PODButContainsDtor() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < PODButContainsDtor > (), 4usize, concat!("Size of: ", - stringify!(PODButContainsDtor)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(PODButContainsDtor)), ); assert_eq!( - ::std::mem::align_of:: < PODButContainsDtor > (), 4usize, - concat!("Alignment of ", stringify!(PODButContainsDtor)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(PODButContainsDtor)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).member) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(PODButContainsDtor), "::", - stringify!(member)) + unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(PODButContainsDtor), + "::", + stringify!(member), + ), ); } impl Default for PODButContainsDtor { @@ -296,16 +324,19 @@ fn bindgen_test_layout_POD() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < POD > (), 4usize, concat!("Size of: ", stringify!(POD)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(POD)), ); assert_eq!( - ::std::mem::align_of:: < POD > (), 4usize, concat!("Alignment of ", - stringify!(POD)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(POD)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).opaque_member) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(POD), "::", - stringify!(opaque_member)) + unsafe { ::std::ptr::addr_of!((*ptr).opaque_member) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(POD), "::", stringify!(opaque_member)), ); } ///
@@ -379,12 +410,14 @@ pub struct Untemplated { #[test] fn bindgen_test_layout_Untemplated() { assert_eq!( - ::std::mem::size_of:: < Untemplated > (), 1usize, concat!("Size of: ", - stringify!(Untemplated)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Untemplated)), ); assert_eq!( - ::std::mem::align_of:: < Untemplated > (), 1usize, concat!("Alignment of ", - stringify!(Untemplated)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Untemplated)), ); } #[repr(C)] @@ -463,269 +496,387 @@ impl Default for ReplacedWithoutDestructorFwd { #[test] fn __bindgen_test_layout_Foo_open0_int_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < Foo < ::std::os::raw::c_int > > (), 24usize, - concat!("Size of template specialization: ", stringify!(Foo < - ::std::os::raw::c_int >)) + ::std::mem::size_of::>(), + 24usize, + concat!( + "Size of template specialization: ", + stringify!(Foo < ::std::os::raw::c_int >), + ), ); assert_eq!( - ::std::mem::align_of:: < Foo < ::std::os::raw::c_int > > (), 8usize, - concat!("Alignment of template specialization: ", stringify!(Foo < - ::std::os::raw::c_int >)) + ::std::mem::align_of::>(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(Foo < ::std::os::raw::c_int >), + ), ); } #[test] fn __bindgen_test_layout_B_open0_unsigned_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < B < ::std::os::raw::c_uint > > (), 4usize, - concat!("Size of template specialization: ", stringify!(B < - ::std::os::raw::c_uint >)) + ::std::mem::size_of::>(), + 4usize, + concat!( + "Size of template specialization: ", + stringify!(B < ::std::os::raw::c_uint >), + ), ); assert_eq!( - ::std::mem::align_of:: < B < ::std::os::raw::c_uint > > (), 4usize, - concat!("Alignment of template specialization: ", stringify!(B < - ::std::os::raw::c_uint >)) + ::std::mem::align_of::>(), + 4usize, + concat!( + "Alignment of template specialization: ", + stringify!(B < ::std::os::raw::c_uint >), + ), ); } #[test] fn __bindgen_test_layout_B_open0_ptr_const_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < B < * const ::std::os::raw::c_int > > (), 8usize, - concat!("Size of template specialization: ", stringify!(B < * const - ::std::os::raw::c_int >)) + ::std::mem::size_of::>(), + 8usize, + concat!( + "Size of template specialization: ", + stringify!(B < * const ::std::os::raw::c_int >), + ), ); assert_eq!( - ::std::mem::align_of:: < B < * const ::std::os::raw::c_int > > (), 8usize, - concat!("Alignment of template specialization: ", stringify!(B < * const - ::std::os::raw::c_int >)) + ::std::mem::align_of::>(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(B < * const ::std::os::raw::c_int >), + ), ); } #[test] fn __bindgen_test_layout_B_open0_ptr_const_mozilla__Foo_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < B < * const mozilla_Foo > > (), 8usize, - concat!("Size of template specialization: ", stringify!(B < * const mozilla_Foo - >)) + ::std::mem::size_of::>(), + 8usize, + concat!( + "Size of template specialization: ", + stringify!(B < * const mozilla_Foo >), + ), ); assert_eq!( - ::std::mem::align_of:: < B < * const mozilla_Foo > > (), 8usize, - concat!("Alignment of template specialization: ", stringify!(B < * const - mozilla_Foo >)) + ::std::mem::align_of::>(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(B < * const mozilla_Foo >), + ), ); } #[test] fn __bindgen_test_layout_B_open0_array1_ptr_const_mozilla__Foo_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < B < [* const mozilla_Foo; 1usize] > > (), 8usize, - concat!("Size of template specialization: ", stringify!(B < [* const mozilla_Foo; - 1usize] >)) + ::std::mem::size_of::>(), + 8usize, + concat!( + "Size of template specialization: ", + stringify!(B < [* const mozilla_Foo; 1usize] >), + ), ); assert_eq!( - ::std::mem::align_of:: < B < [* const mozilla_Foo; 1usize] > > (), 8usize, - concat!("Alignment of template specialization: ", stringify!(B < [* const - mozilla_Foo; 1usize] >)) + ::std::mem::align_of::>(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(B < [* const mozilla_Foo; 1usize] >), + ), ); } #[test] fn __bindgen_test_layout_B_open0_const_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < B < ::std::os::raw::c_int > > (), 4usize, - concat!("Size of template specialization: ", stringify!(B < ::std::os::raw::c_int - >)) + ::std::mem::size_of::>(), + 4usize, + concat!( + "Size of template specialization: ", + stringify!(B < ::std::os::raw::c_int >), + ), ); assert_eq!( - ::std::mem::align_of:: < B < ::std::os::raw::c_int > > (), 4usize, - concat!("Alignment of template specialization: ", stringify!(B < - ::std::os::raw::c_int >)) + ::std::mem::align_of::>(), + 4usize, + concat!( + "Alignment of template specialization: ", + stringify!(B < ::std::os::raw::c_int >), + ), ); } #[test] fn __bindgen_test_layout_B_open0_volatile_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < B < ::std::os::raw::c_int > > (), 4usize, - concat!("Size of template specialization: ", stringify!(B < ::std::os::raw::c_int - >)) + ::std::mem::size_of::>(), + 4usize, + concat!( + "Size of template specialization: ", + stringify!(B < ::std::os::raw::c_int >), + ), ); assert_eq!( - ::std::mem::align_of:: < B < ::std::os::raw::c_int > > (), 4usize, - concat!("Alignment of template specialization: ", stringify!(B < - ::std::os::raw::c_int >)) + ::std::mem::align_of::>(), + 4usize, + concat!( + "Alignment of template specialization: ", + stringify!(B < ::std::os::raw::c_int >), + ), ); } #[test] fn __bindgen_test_layout_B_open0_const_bool_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < B < bool > > (), 1usize, - concat!("Size of template specialization: ", stringify!(B < bool >)) + ::std::mem::size_of::>(), + 1usize, + concat!("Size of template specialization: ", stringify!(B < bool >)), ); assert_eq!( - ::std::mem::align_of:: < B < bool > > (), 1usize, - concat!("Alignment of template specialization: ", stringify!(B < bool >)) + ::std::mem::align_of::>(), + 1usize, + concat!("Alignment of template specialization: ", stringify!(B < bool >)), ); } #[test] fn __bindgen_test_layout_B_open0_const_char16_t_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < B < u16 > > (), 2usize, - concat!("Size of template specialization: ", stringify!(B < u16 >)) + ::std::mem::size_of::>(), + 2usize, + concat!("Size of template specialization: ", stringify!(B < u16 >)), ); assert_eq!( - ::std::mem::align_of:: < B < u16 > > (), 2usize, - concat!("Alignment of template specialization: ", stringify!(B < u16 >)) + ::std::mem::align_of::>(), + 2usize, + concat!("Alignment of template specialization: ", stringify!(B < u16 >)), ); } #[test] fn __bindgen_test_layout_B_open0_array1_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < B < [::std::os::raw::c_int; 1usize] > > (), 4usize, - concat!("Size of template specialization: ", stringify!(B < - [::std::os::raw::c_int; 1usize] >)) + ::std::mem::size_of::>(), + 4usize, + concat!( + "Size of template specialization: ", + stringify!(B < [::std::os::raw::c_int; 1usize] >), + ), ); assert_eq!( - ::std::mem::align_of:: < B < [::std::os::raw::c_int; 1usize] > > (), 4usize, - concat!("Alignment of template specialization: ", stringify!(B < - [::std::os::raw::c_int; 1usize] >)) + ::std::mem::align_of::>(), + 4usize, + concat!( + "Alignment of template specialization: ", + stringify!(B < [::std::os::raw::c_int; 1usize] >), + ), ); } #[test] fn __bindgen_test_layout_B_open0_array1_ptr_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < B < [* mut ::std::os::raw::c_int; 1usize] > > (), 8usize, - concat!("Size of template specialization: ", stringify!(B < [* mut - ::std::os::raw::c_int; 1usize] >)) + ::std::mem::size_of::>(), + 8usize, + concat!( + "Size of template specialization: ", + stringify!(B < [* mut ::std::os::raw::c_int; 1usize] >), + ), ); assert_eq!( - ::std::mem::align_of:: < B < [* mut ::std::os::raw::c_int; 1usize] > > (), - 8usize, concat!("Alignment of template specialization: ", stringify!(B < [* mut - ::std::os::raw::c_int; 1usize] >)) + ::std::mem::align_of::>(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(B < [* mut ::std::os::raw::c_int; 1usize] >), + ), ); } #[test] fn __bindgen_test_layout_B_open0_ptr_array1_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < B < * mut [::std::os::raw::c_int; 1usize] > > (), 8usize, - concat!("Size of template specialization: ", stringify!(B < * mut - [::std::os::raw::c_int; 1usize] >)) + ::std::mem::size_of::>(), + 8usize, + concat!( + "Size of template specialization: ", + stringify!(B < * mut [::std::os::raw::c_int; 1usize] >), + ), ); assert_eq!( - ::std::mem::align_of:: < B < * mut [::std::os::raw::c_int; 1usize] > > (), - 8usize, concat!("Alignment of template specialization: ", stringify!(B < * mut - [::std::os::raw::c_int; 1usize] >)) + ::std::mem::align_of::>(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(B < * mut [::std::os::raw::c_int; 1usize] >), + ), ); } #[test] fn __bindgen_test_layout_B_open0_ref_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < B < * mut ::std::os::raw::c_int > > (), 8usize, - concat!("Size of template specialization: ", stringify!(B < * mut - ::std::os::raw::c_int >)) + ::std::mem::size_of::>(), + 8usize, + concat!( + "Size of template specialization: ", + stringify!(B < * mut ::std::os::raw::c_int >), + ), ); assert_eq!( - ::std::mem::align_of:: < B < * mut ::std::os::raw::c_int > > (), 8usize, - concat!("Alignment of template specialization: ", stringify!(B < * mut - ::std::os::raw::c_int >)) + ::std::mem::align_of::>(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(B < * mut ::std::os::raw::c_int >), + ), ); } #[test] fn __bindgen_test_layout_B_open0_ref_const_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < B < * const ::std::os::raw::c_int > > (), 8usize, - concat!("Size of template specialization: ", stringify!(B < * const - ::std::os::raw::c_int >)) + ::std::mem::size_of::>(), + 8usize, + concat!( + "Size of template specialization: ", + stringify!(B < * const ::std::os::raw::c_int >), + ), ); assert_eq!( - ::std::mem::align_of:: < B < * const ::std::os::raw::c_int > > (), 8usize, - concat!("Alignment of template specialization: ", stringify!(B < * const - ::std::os::raw::c_int >)) + ::std::mem::align_of::>(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(B < * const ::std::os::raw::c_int >), + ), ); } #[test] fn __bindgen_test_layout_B_open0_ref_ptr_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < B < * mut * mut ::std::os::raw::c_int > > (), 8usize, - concat!("Size of template specialization: ", stringify!(B < * mut * mut - ::std::os::raw::c_int >)) + ::std::mem::size_of::>(), + 8usize, + concat!( + "Size of template specialization: ", + stringify!(B < * mut * mut ::std::os::raw::c_int >), + ), ); assert_eq!( - ::std::mem::align_of:: < B < * mut * mut ::std::os::raw::c_int > > (), 8usize, - concat!("Alignment of template specialization: ", stringify!(B < * mut * mut - ::std::os::raw::c_int >)) + ::std::mem::align_of::>(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(B < * mut * mut ::std::os::raw::c_int >), + ), ); } #[test] fn __bindgen_test_layout_B_open0_ref_array1_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < B < * mut [::std::os::raw::c_int; 1usize] > > (), 8usize, - concat!("Size of template specialization: ", stringify!(B < * mut - [::std::os::raw::c_int; 1usize] >)) + ::std::mem::size_of::>(), + 8usize, + concat!( + "Size of template specialization: ", + stringify!(B < * mut [::std::os::raw::c_int; 1usize] >), + ), ); assert_eq!( - ::std::mem::align_of:: < B < * mut [::std::os::raw::c_int; 1usize] > > (), - 8usize, concat!("Alignment of template specialization: ", stringify!(B < * mut - [::std::os::raw::c_int; 1usize] >)) + ::std::mem::align_of::>(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(B < * mut [::std::os::raw::c_int; 1usize] >), + ), ); } #[test] fn __bindgen_test_layout_B_open0_array1_const_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < B < [::std::os::raw::c_int; 1usize] > > (), 4usize, - concat!("Size of template specialization: ", stringify!(B < - [::std::os::raw::c_int; 1usize] >)) + ::std::mem::size_of::>(), + 4usize, + concat!( + "Size of template specialization: ", + stringify!(B < [::std::os::raw::c_int; 1usize] >), + ), ); assert_eq!( - ::std::mem::align_of:: < B < [::std::os::raw::c_int; 1usize] > > (), 4usize, - concat!("Alignment of template specialization: ", stringify!(B < - [::std::os::raw::c_int; 1usize] >)) + ::std::mem::align_of::>(), + 4usize, + concat!( + "Alignment of template specialization: ", + stringify!(B < [::std::os::raw::c_int; 1usize] >), + ), ); } #[test] fn __bindgen_test_layout_Foo_open0_int_int_close0_instantiation_1() { assert_eq!( - ::std::mem::size_of:: < Foo < ::std::os::raw::c_int > > (), 24usize, - concat!("Size of template specialization: ", stringify!(Foo < - ::std::os::raw::c_int >)) + ::std::mem::size_of::>(), + 24usize, + concat!( + "Size of template specialization: ", + stringify!(Foo < ::std::os::raw::c_int >), + ), ); assert_eq!( - ::std::mem::align_of:: < Foo < ::std::os::raw::c_int > > (), 8usize, - concat!("Alignment of template specialization: ", stringify!(Foo < - ::std::os::raw::c_int >)) + ::std::mem::align_of::>(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(Foo < ::std::os::raw::c_int >), + ), ); } #[test] fn __bindgen_test_layout_Rooted_open0_ptr_void_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < Rooted < * mut ::std::os::raw::c_void > > (), 24usize, - concat!("Size of template specialization: ", stringify!(Rooted < * mut - ::std::os::raw::c_void >)) + ::std::mem::size_of::>(), + 24usize, + concat!( + "Size of template specialization: ", + stringify!(Rooted < * mut ::std::os::raw::c_void >), + ), ); assert_eq!( - ::std::mem::align_of:: < Rooted < * mut ::std::os::raw::c_void > > (), 8usize, - concat!("Alignment of template specialization: ", stringify!(Rooted < * mut - ::std::os::raw::c_void >)) + ::std::mem::align_of::>(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(Rooted < * mut ::std::os::raw::c_void >), + ), ); } #[test] fn __bindgen_test_layout_Rooted_open0_ptr_void_close0_instantiation_1() { assert_eq!( - ::std::mem::size_of:: < Rooted < * mut ::std::os::raw::c_void > > (), 24usize, - concat!("Size of template specialization: ", stringify!(Rooted < * mut - ::std::os::raw::c_void >)) + ::std::mem::size_of::>(), + 24usize, + concat!( + "Size of template specialization: ", + stringify!(Rooted < * mut ::std::os::raw::c_void >), + ), ); assert_eq!( - ::std::mem::align_of:: < Rooted < * mut ::std::os::raw::c_void > > (), 8usize, - concat!("Alignment of template specialization: ", stringify!(Rooted < * mut - ::std::os::raw::c_void >)) + ::std::mem::align_of::>(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(Rooted < * mut ::std::os::raw::c_void >), + ), ); } #[test] fn __bindgen_test_layout_WithDtor_open0_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < WithDtor < ::std::os::raw::c_int > > (), 4usize, - concat!("Size of template specialization: ", stringify!(WithDtor < - ::std::os::raw::c_int >)) + ::std::mem::size_of::>(), + 4usize, + concat!( + "Size of template specialization: ", + stringify!(WithDtor < ::std::os::raw::c_int >), + ), ); assert_eq!( - ::std::mem::align_of:: < WithDtor < ::std::os::raw::c_int > > (), 4usize, - concat!("Alignment of template specialization: ", stringify!(WithDtor < - ::std::os::raw::c_int >)) + ::std::mem::align_of::>(), + 4usize, + concat!( + "Alignment of template specialization: ", + stringify!(WithDtor < ::std::os::raw::c_int >), + ), ); } diff --git a/bindgen-tests/tests/expectations/tests/template_instantiation_with_fn_local_type.rs b/bindgen-tests/tests/expectations/tests/template_instantiation_with_fn_local_type.rs index ab87b4160b..c6da8c26c7 100644 --- a/bindgen-tests/tests/expectations/tests/template_instantiation_with_fn_local_type.rs +++ b/bindgen-tests/tests/expectations/tests/template_instantiation_with_fn_local_type.rs @@ -11,12 +11,14 @@ extern "C" { #[test] fn __bindgen_test_layout_Foo_open0_Bar_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < Foo > (), 1usize, - concat!("Size of template specialization: ", stringify!(Foo)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of template specialization: ", stringify!(Foo)), ); assert_eq!( - ::std::mem::align_of:: < Foo > (), 1usize, - concat!("Alignment of template specialization: ", stringify!(Foo)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of template specialization: ", stringify!(Foo)), ); } #[repr(C)] @@ -27,22 +29,27 @@ pub struct Baz { #[test] fn bindgen_test_layout_Baz() { assert_eq!( - ::std::mem::size_of:: < Baz > (), 1usize, concat!("Size of: ", stringify!(Baz)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Baz)), ); assert_eq!( - ::std::mem::align_of:: < Baz > (), 1usize, concat!("Alignment of ", - stringify!(Baz)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Baz)), ); } #[test] fn __bindgen_test_layout_Foo_open0_Boo_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < Foo > (), 1usize, - concat!("Size of template specialization: ", stringify!(Foo)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of template specialization: ", stringify!(Foo)), ); assert_eq!( - ::std::mem::align_of:: < Foo > (), 1usize, - concat!("Alignment of template specialization: ", stringify!(Foo)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of template specialization: ", stringify!(Foo)), ); } #[repr(C)] @@ -53,11 +60,14 @@ pub struct Bar { #[test] fn bindgen_test_layout_Bar() { assert_eq!( - ::std::mem::size_of:: < Bar > (), 1usize, concat!("Size of: ", stringify!(Bar)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Bar)), ); assert_eq!( - ::std::mem::align_of:: < Bar > (), 1usize, concat!("Alignment of ", - stringify!(Bar)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Bar)), ); } #[repr(C)] @@ -68,10 +78,13 @@ pub struct Boo { #[test] fn bindgen_test_layout_Boo() { assert_eq!( - ::std::mem::size_of:: < Boo > (), 1usize, concat!("Size of: ", stringify!(Boo)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Boo)), ); assert_eq!( - ::std::mem::align_of:: < Boo > (), 1usize, concat!("Alignment of ", - stringify!(Boo)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Boo)), ); } diff --git a/bindgen-tests/tests/expectations/tests/timex.rs b/bindgen-tests/tests/expectations/tests/timex.rs index 025dce91ff..16bbae7607 100644 --- a/bindgen-tests/tests/expectations/tests/timex.rs +++ b/bindgen-tests/tests/expectations/tests/timex.rs @@ -49,7 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -69,7 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -95,16 +95,19 @@ fn bindgen_test_layout_timex() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < timex > (), 48usize, concat!("Size of: ", - stringify!(timex)) + ::std::mem::size_of::(), + 48usize, + concat!("Size of: ", stringify!(timex)), ); assert_eq!( - ::std::mem::align_of:: < timex > (), 4usize, concat!("Alignment of ", - stringify!(timex)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(timex)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).tai) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(timex), "::", stringify!(tai)) + unsafe { ::std::ptr::addr_of!((*ptr).tai) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(timex), "::", stringify!(tai)), ); } impl Default for timex { @@ -128,16 +131,19 @@ fn bindgen_test_layout_timex_named() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < timex_named > (), 48usize, concat!("Size of: ", - stringify!(timex_named)) + ::std::mem::size_of::(), + 48usize, + concat!("Size of: ", stringify!(timex_named)), ); assert_eq!( - ::std::mem::align_of:: < timex_named > (), 4usize, concat!("Alignment of ", - stringify!(timex_named)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(timex_named)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).tai) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(timex_named), "::", stringify!(tai)) + unsafe { ::std::ptr::addr_of!((*ptr).tai) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(timex_named), "::", stringify!(tai)), ); } impl Default for timex_named { diff --git a/bindgen-tests/tests/expectations/tests/transform-op.rs b/bindgen-tests/tests/expectations/tests/transform-op.rs index 3e7730bcea..57b22ca2e4 100644 --- a/bindgen-tests/tests/expectations/tests/transform-op.rs +++ b/bindgen-tests/tests/expectations/tests/transform-op.rs @@ -217,22 +217,26 @@ impl Default for StyleBar { #[test] fn __bindgen_test_layout_StylePoint_open0_float_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < StylePoint < f32 > > (), 8usize, - concat!("Size of template specialization: ", stringify!(StylePoint < f32 >)) + ::std::mem::size_of::>(), + 8usize, + concat!("Size of template specialization: ", stringify!(StylePoint < f32 >)), ); assert_eq!( - ::std::mem::align_of:: < StylePoint < f32 > > (), 4usize, - concat!("Alignment of template specialization: ", stringify!(StylePoint < f32 >)) + ::std::mem::align_of::>(), + 4usize, + concat!("Alignment of template specialization: ", stringify!(StylePoint < f32 >)), ); } #[test] fn __bindgen_test_layout_StylePoint_open0_float_close0_instantiation_1() { assert_eq!( - ::std::mem::size_of:: < StylePoint < f32 > > (), 8usize, - concat!("Size of template specialization: ", stringify!(StylePoint < f32 >)) + ::std::mem::size_of::>(), + 8usize, + concat!("Size of template specialization: ", stringify!(StylePoint < f32 >)), ); assert_eq!( - ::std::mem::align_of:: < StylePoint < f32 > > (), 4usize, - concat!("Alignment of template specialization: ", stringify!(StylePoint < f32 >)) + ::std::mem::align_of::>(), + 4usize, + concat!("Alignment of template specialization: ", stringify!(StylePoint < f32 >)), ); } diff --git a/bindgen-tests/tests/expectations/tests/type-referenced-by-allowlisted-function.rs b/bindgen-tests/tests/expectations/tests/type-referenced-by-allowlisted-function.rs index bc16ba496e..62ebce73fb 100644 --- a/bindgen-tests/tests/expectations/tests/type-referenced-by-allowlisted-function.rs +++ b/bindgen-tests/tests/expectations/tests/type-referenced-by-allowlisted-function.rs @@ -9,16 +9,19 @@ fn bindgen_test_layout_dl_phdr_info() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < dl_phdr_info > (), 4usize, concat!("Size of: ", - stringify!(dl_phdr_info)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(dl_phdr_info)), ); assert_eq!( - ::std::mem::align_of:: < dl_phdr_info > (), 4usize, concat!("Alignment of ", - stringify!(dl_phdr_info)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(dl_phdr_info)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).x) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(dl_phdr_info), "::", stringify!(x)) + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(dl_phdr_info), "::", stringify!(x)), ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/typedef-pointer-overlap.rs b/bindgen-tests/tests/expectations/tests/typedef-pointer-overlap.rs index fed13bbd42..3e04de9185 100644 --- a/bindgen-tests/tests/expectations/tests/typedef-pointer-overlap.rs +++ b/bindgen-tests/tests/expectations/tests/typedef-pointer-overlap.rs @@ -9,15 +9,19 @@ 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:: < foo > (), 1usize, concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(foo)), ); assert_eq!( - ::std::mem::align_of:: < foo > (), 1usize, concat!("Alignment of ", - stringify!(foo)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).inner) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(inner)) + unsafe { ::std::ptr::addr_of!((*ptr).inner) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(inner)), ); } pub type foo_ptr = *const foo; @@ -31,15 +35,19 @@ 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:: < bar > (), 1usize, concat!("Size of: ", stringify!(bar)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(bar)), ); assert_eq!( - ::std::mem::align_of:: < bar > (), 1usize, concat!("Alignment of ", - stringify!(bar)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(bar)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).inner) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(bar), "::", stringify!(inner)) + unsafe { ::std::ptr::addr_of!((*ptr).inner) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(bar), "::", stringify!(inner)), ); } pub type bar_ptr = *mut bar; @@ -59,16 +67,19 @@ fn bindgen_test_layout_cat() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < cat > (), 4usize, concat!("Size of: ", stringify!(cat)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(cat)), ); assert_eq!( - ::std::mem::align_of:: < cat > (), 4usize, concat!("Alignment of ", - stringify!(cat)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(cat)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).standard_issue) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(cat), "::", - stringify!(standard_issue)) + unsafe { ::std::ptr::addr_of!((*ptr).standard_issue) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(cat), "::", stringify!(standard_issue)), ); } impl Default for cat { diff --git a/bindgen-tests/tests/expectations/tests/typeref.rs b/bindgen-tests/tests/expectations/tests/typeref.rs index 1a19ba6c8f..31f9d2c697 100644 --- a/bindgen-tests/tests/expectations/tests/typeref.rs +++ b/bindgen-tests/tests/expectations/tests/typeref.rs @@ -9,17 +9,24 @@ fn bindgen_test_layout_mozilla_FragmentOrURL() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < mozilla_FragmentOrURL > (), 1usize, concat!("Size of: ", - stringify!(mozilla_FragmentOrURL)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(mozilla_FragmentOrURL)), ); assert_eq!( - ::std::mem::align_of:: < mozilla_FragmentOrURL > (), 1usize, - concat!("Alignment of ", stringify!(mozilla_FragmentOrURL)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(mozilla_FragmentOrURL)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mIsLocalRef) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(mozilla_FragmentOrURL), "::", - stringify!(mIsLocalRef)) + unsafe { ::std::ptr::addr_of!((*ptr).mIsLocalRef) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(mozilla_FragmentOrURL), + "::", + stringify!(mIsLocalRef), + ), ); } #[repr(C)] @@ -30,12 +37,14 @@ pub struct mozilla_Position { #[test] fn bindgen_test_layout_mozilla_Position() { assert_eq!( - ::std::mem::size_of:: < mozilla_Position > (), 1usize, concat!("Size of: ", - stringify!(mozilla_Position)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(mozilla_Position)), ); assert_eq!( - ::std::mem::align_of:: < mozilla_Position > (), 1usize, concat!("Alignment of ", - stringify!(mozilla_Position)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(mozilla_Position)), ); } #[repr(C)] @@ -75,15 +84,19 @@ 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:: < Bar > (), 8usize, concat!("Size of: ", stringify!(Bar)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Bar)), ); assert_eq!( - ::std::mem::align_of:: < Bar > (), 8usize, concat!("Alignment of ", - stringify!(Bar)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Bar)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mFoo) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(mFoo)) + unsafe { ::std::ptr::addr_of!((*ptr).mFoo) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(mFoo)), ); } impl Default for Bar { @@ -104,16 +117,19 @@ 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:: < nsFoo > (), 8usize, concat!("Size of: ", - stringify!(nsFoo)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(nsFoo)), ); assert_eq!( - ::std::mem::align_of:: < nsFoo > (), 8usize, concat!("Alignment of ", - stringify!(nsFoo)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(nsFoo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mBar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(nsFoo), "::", stringify!(mBar)) + unsafe { ::std::ptr::addr_of!((*ptr).mBar) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(nsFoo), "::", stringify!(mBar)), ); } impl Default for nsFoo { @@ -128,13 +144,19 @@ impl Default for nsFoo { #[test] fn __bindgen_test_layout_mozilla_StyleShapeSource_open0_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < mozilla_StyleShapeSource > (), 8usize, - concat!("Size of template specialization: ", - stringify!(mozilla_StyleShapeSource)) + ::std::mem::size_of::(), + 8usize, + concat!( + "Size of template specialization: ", + stringify!(mozilla_StyleShapeSource), + ), ); assert_eq!( - ::std::mem::align_of:: < mozilla_StyleShapeSource > (), 8usize, - concat!("Alignment of template specialization: ", - stringify!(mozilla_StyleShapeSource)) + ::std::mem::align_of::(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(mozilla_StyleShapeSource), + ), ); } diff --git a/bindgen-tests/tests/expectations/tests/typeref_1_0.rs b/bindgen-tests/tests/expectations/tests/typeref_1_0.rs index f552d13a07..e6c60c7f1a 100644 --- a/bindgen-tests/tests/expectations/tests/typeref_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/typeref_1_0.rs @@ -52,17 +52,24 @@ fn bindgen_test_layout_mozilla_FragmentOrURL() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < mozilla_FragmentOrURL > (), 1usize, concat!("Size of: ", - stringify!(mozilla_FragmentOrURL)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(mozilla_FragmentOrURL)), ); assert_eq!( - ::std::mem::align_of:: < mozilla_FragmentOrURL > (), 1usize, - concat!("Alignment of ", stringify!(mozilla_FragmentOrURL)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(mozilla_FragmentOrURL)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mIsLocalRef) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(mozilla_FragmentOrURL), "::", - stringify!(mIsLocalRef)) + unsafe { ::std::ptr::addr_of!((*ptr).mIsLocalRef) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(mozilla_FragmentOrURL), + "::", + stringify!(mIsLocalRef), + ), ); } impl Clone for mozilla_FragmentOrURL { @@ -78,12 +85,14 @@ pub struct mozilla_Position { #[test] fn bindgen_test_layout_mozilla_Position() { assert_eq!( - ::std::mem::size_of:: < mozilla_Position > (), 1usize, concat!("Size of: ", - stringify!(mozilla_Position)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(mozilla_Position)), ); assert_eq!( - ::std::mem::align_of:: < mozilla_Position > (), 1usize, concat!("Alignment of ", - stringify!(mozilla_Position)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(mozilla_Position)), ); } impl Clone for mozilla_Position { @@ -113,15 +122,19 @@ 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:: < Bar > (), 8usize, concat!("Size of: ", stringify!(Bar)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Bar)), ); assert_eq!( - ::std::mem::align_of:: < Bar > (), 8usize, concat!("Alignment of ", - stringify!(Bar)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Bar)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mFoo) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(mFoo)) + unsafe { ::std::ptr::addr_of!((*ptr).mFoo) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(mFoo)), ); } impl Clone for Bar { @@ -148,16 +161,19 @@ 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:: < nsFoo > (), 8usize, concat!("Size of: ", - stringify!(nsFoo)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(nsFoo)), ); assert_eq!( - ::std::mem::align_of:: < nsFoo > (), 8usize, concat!("Alignment of ", - stringify!(nsFoo)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(nsFoo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mBar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(nsFoo), "::", stringify!(mBar)) + unsafe { ::std::ptr::addr_of!((*ptr).mBar) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(nsFoo), "::", stringify!(mBar)), ); } impl Clone for nsFoo { @@ -168,13 +184,19 @@ impl Clone for nsFoo { #[test] fn __bindgen_test_layout_mozilla_StyleShapeSource_open0_int_close0_instantiation() { assert_eq!( - ::std::mem::size_of:: < mozilla_StyleShapeSource > (), 8usize, - concat!("Size of template specialization: ", - stringify!(mozilla_StyleShapeSource)) + ::std::mem::size_of::(), + 8usize, + concat!( + "Size of template specialization: ", + stringify!(mozilla_StyleShapeSource), + ), ); assert_eq!( - ::std::mem::align_of:: < mozilla_StyleShapeSource > (), 8usize, - concat!("Alignment of template specialization: ", - stringify!(mozilla_StyleShapeSource)) + ::std::mem::align_of::(), + 8usize, + concat!( + "Alignment of template specialization: ", + stringify!(mozilla_StyleShapeSource), + ), ); } diff --git a/bindgen-tests/tests/expectations/tests/underscore.rs b/bindgen-tests/tests/expectations/tests/underscore.rs index c547cedef0..59897e41fd 100644 --- a/bindgen-tests/tests/expectations/tests/underscore.rs +++ b/bindgen-tests/tests/expectations/tests/underscore.rs @@ -10,15 +10,18 @@ fn bindgen_test_layout_ptr_t() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < ptr_t > (), 8usize, concat!("Size of: ", - stringify!(ptr_t)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(ptr_t)), ); assert_eq!( - ::std::mem::align_of:: < ptr_t > (), 1usize, concat!("Alignment of ", - stringify!(ptr_t)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(ptr_t)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).__) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(ptr_t), "::", stringify!(__)) + unsafe { ::std::ptr::addr_of!((*ptr).__) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(ptr_t), "::", stringify!(__)), ); } diff --git a/bindgen-tests/tests/expectations/tests/union-align.rs b/bindgen-tests/tests/expectations/tests/union-align.rs index 7f74d16463..0047834f81 100644 --- a/bindgen-tests/tests/expectations/tests/union-align.rs +++ b/bindgen-tests/tests/expectations/tests/union-align.rs @@ -10,15 +10,19 @@ 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:: < Bar > (), 16usize, concat!("Size of: ", stringify!(Bar)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(Bar)), ); assert_eq!( - ::std::mem::align_of:: < Bar > (), 16usize, concat!("Alignment of ", - stringify!(Bar)) + ::std::mem::align_of::(), + 16usize, + concat!("Alignment of ", stringify!(Bar)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).foo) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(foo)) + unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(foo)), ); } impl Default for Bar { @@ -41,15 +45,19 @@ 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:: < Baz > (), 16usize, concat!("Size of: ", stringify!(Baz)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(Baz)), ); assert_eq!( - ::std::mem::align_of:: < Baz > (), 16usize, concat!("Alignment of ", - stringify!(Baz)) + ::std::mem::align_of::(), + 16usize, + concat!("Alignment of ", stringify!(Baz)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Baz), "::", stringify!(bar)) + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Baz), "::", stringify!(bar)), ); } impl Default for Baz { diff --git a/bindgen-tests/tests/expectations/tests/union-in-ns.rs b/bindgen-tests/tests/expectations/tests/union-in-ns.rs index 4d92466e66..58160c65a9 100644 --- a/bindgen-tests/tests/expectations/tests/union-in-ns.rs +++ b/bindgen-tests/tests/expectations/tests/union-in-ns.rs @@ -13,16 +13,19 @@ pub mod root { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < bar > (), 4usize, concat!("Size of: ", - stringify!(bar)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(bar)), ); assert_eq!( - ::std::mem::align_of:: < bar > (), 4usize, concat!("Alignment of ", - stringify!(bar)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(bar)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).baz) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(bar), "::", stringify!(baz)) + unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(bar), "::", stringify!(baz)), ); } impl Default for bar { diff --git a/bindgen-tests/tests/expectations/tests/union-in-ns_1_0.rs b/bindgen-tests/tests/expectations/tests/union-in-ns_1_0.rs index 27c148f353..c1982df14a 100644 --- a/bindgen-tests/tests/expectations/tests/union-in-ns_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union-in-ns_1_0.rs @@ -57,16 +57,19 @@ pub mod root { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < bar > (), 4usize, concat!("Size of: ", - stringify!(bar)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(bar)), ); assert_eq!( - ::std::mem::align_of:: < bar > (), 4usize, concat!("Alignment of ", - stringify!(bar)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(bar)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).baz) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(bar), "::", stringify!(baz)) + unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(bar), "::", stringify!(baz)), ); } impl Clone for bar { diff --git a/bindgen-tests/tests/expectations/tests/union_bitfield.rs b/bindgen-tests/tests/expectations/tests/union_bitfield.rs index a38fb325ce..096c0371a6 100644 --- a/bindgen-tests/tests/expectations/tests/union_bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/union_bitfield.rs @@ -49,7 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -69,7 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -93,11 +93,14 @@ pub union U4 { #[test] fn bindgen_test_layout_U4() { assert_eq!( - ::std::mem::size_of:: < U4 > (), 4usize, concat!("Size of: ", stringify!(U4)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(U4)), ); assert_eq!( - ::std::mem::align_of:: < U4 > (), 4usize, concat!("Alignment of ", - stringify!(U4)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(U4)), ); } impl Default for U4 { @@ -147,11 +150,11 @@ pub union B { } #[test] fn bindgen_test_layout_B() { + assert_eq!(::std::mem::size_of::(), 4usize, concat!("Size of: ", stringify!(B))); assert_eq!( - ::std::mem::size_of:: < B > (), 4usize, concat!("Size of: ", stringify!(B)) - ); - assert_eq!( - ::std::mem::align_of:: < B > (), 4usize, concat!("Alignment of ", stringify!(B)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(B)), ); } impl Default for B { diff --git a/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs b/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs index f67b6a87ac..fa7a0d8f82 100644 --- a/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs @@ -49,7 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -69,7 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -136,11 +136,14 @@ pub struct U4 { #[test] fn bindgen_test_layout_U4() { assert_eq!( - ::std::mem::size_of:: < U4 > (), 4usize, concat!("Size of: ", stringify!(U4)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(U4)), ); assert_eq!( - ::std::mem::align_of:: < U4 > (), 4usize, concat!("Alignment of ", - stringify!(U4)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(U4)), ); } impl Clone for U4 { @@ -188,11 +191,11 @@ pub struct B { } #[test] fn bindgen_test_layout_B() { + assert_eq!(::std::mem::size_of::(), 4usize, concat!("Size of: ", stringify!(B))); assert_eq!( - ::std::mem::size_of:: < B > (), 4usize, concat!("Size of: ", stringify!(B)) - ); - assert_eq!( - ::std::mem::align_of:: < B > (), 4usize, concat!("Alignment of ", stringify!(B)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(B)), ); } impl Clone for B { @@ -264,8 +267,9 @@ pub struct HasBigBitfield { #[test] fn bindgen_test_layout_HasBigBitfield() { assert_eq!( - ::std::mem::size_of:: < HasBigBitfield > (), 16usize, concat!("Size of: ", - stringify!(HasBigBitfield)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(HasBigBitfield)), ); } impl Clone for HasBigBitfield { diff --git a/bindgen-tests/tests/expectations/tests/union_dtor.rs b/bindgen-tests/tests/expectations/tests/union_dtor.rs index b37891017c..5eea0cacda 100644 --- a/bindgen-tests/tests/expectations/tests/union_dtor.rs +++ b/bindgen-tests/tests/expectations/tests/union_dtor.rs @@ -9,20 +9,24 @@ fn bindgen_test_layout_UnionWithDtor() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < UnionWithDtor > (), 8usize, concat!("Size of: ", - stringify!(UnionWithDtor)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(UnionWithDtor)), ); assert_eq!( - ::std::mem::align_of:: < UnionWithDtor > (), 8usize, concat!("Alignment of ", - stringify!(UnionWithDtor)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(UnionWithDtor)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mFoo) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(UnionWithDtor), "::", stringify!(mFoo)) + unsafe { ::std::ptr::addr_of!((*ptr).mFoo) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(UnionWithDtor), "::", stringify!(mFoo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mBar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(UnionWithDtor), "::", stringify!(mBar)) + unsafe { ::std::ptr::addr_of!((*ptr).mBar) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(UnionWithDtor), "::", stringify!(mBar)), ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/union_dtor_1_0.rs b/bindgen-tests/tests/expectations/tests/union_dtor_1_0.rs index 5039947a4f..9c60ca47ef 100644 --- a/bindgen-tests/tests/expectations/tests/union_dtor_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_dtor_1_0.rs @@ -54,20 +54,24 @@ fn bindgen_test_layout_UnionWithDtor() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < UnionWithDtor > (), 8usize, concat!("Size of: ", - stringify!(UnionWithDtor)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(UnionWithDtor)), ); assert_eq!( - ::std::mem::align_of:: < UnionWithDtor > (), 8usize, concat!("Alignment of ", - stringify!(UnionWithDtor)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(UnionWithDtor)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mFoo) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(UnionWithDtor), "::", stringify!(mFoo)) + unsafe { ::std::ptr::addr_of!((*ptr).mFoo) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(UnionWithDtor), "::", stringify!(mFoo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mBar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(UnionWithDtor), "::", stringify!(mBar)) + unsafe { ::std::ptr::addr_of!((*ptr).mBar) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(UnionWithDtor), "::", stringify!(mBar)), ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/union_fields.rs b/bindgen-tests/tests/expectations/tests/union_fields.rs index ab0b9bff40..30f130c3c1 100644 --- a/bindgen-tests/tests/expectations/tests/union_fields.rs +++ b/bindgen-tests/tests/expectations/tests/union_fields.rs @@ -11,25 +11,34 @@ fn bindgen_test_layout_nsStyleUnion() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < nsStyleUnion > (), 8usize, concat!("Size of: ", - stringify!(nsStyleUnion)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(nsStyleUnion)), ); assert_eq!( - ::std::mem::align_of:: < nsStyleUnion > (), 8usize, concat!("Alignment of ", - stringify!(nsStyleUnion)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(nsStyleUnion)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mInt) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(nsStyleUnion), "::", stringify!(mInt)) + unsafe { ::std::ptr::addr_of!((*ptr).mInt) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(nsStyleUnion), "::", stringify!(mInt)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mFloat) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(nsStyleUnion), "::", stringify!(mFloat)) + unsafe { ::std::ptr::addr_of!((*ptr).mFloat) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(nsStyleUnion), "::", stringify!(mFloat)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mPointer) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(nsStyleUnion), "::", - stringify!(mPointer)) + unsafe { ::std::ptr::addr_of!((*ptr).mPointer) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(nsStyleUnion), + "::", + stringify!(mPointer), + ), ); } impl Default for nsStyleUnion { diff --git a/bindgen-tests/tests/expectations/tests/union_fields_1_0.rs b/bindgen-tests/tests/expectations/tests/union_fields_1_0.rs index 2e41c103e8..f59295c089 100644 --- a/bindgen-tests/tests/expectations/tests/union_fields_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_fields_1_0.rs @@ -55,25 +55,34 @@ fn bindgen_test_layout_nsStyleUnion() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < nsStyleUnion > (), 8usize, concat!("Size of: ", - stringify!(nsStyleUnion)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(nsStyleUnion)), ); assert_eq!( - ::std::mem::align_of:: < nsStyleUnion > (), 8usize, concat!("Alignment of ", - stringify!(nsStyleUnion)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(nsStyleUnion)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mInt) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(nsStyleUnion), "::", stringify!(mInt)) + unsafe { ::std::ptr::addr_of!((*ptr).mInt) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(nsStyleUnion), "::", stringify!(mInt)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mFloat) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(nsStyleUnion), "::", stringify!(mFloat)) + unsafe { ::std::ptr::addr_of!((*ptr).mFloat) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(nsStyleUnion), "::", stringify!(mFloat)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mPointer) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(nsStyleUnion), "::", - stringify!(mPointer)) + unsafe { ::std::ptr::addr_of!((*ptr).mPointer) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(nsStyleUnion), + "::", + stringify!(mPointer), + ), ); } impl Clone for nsStyleUnion { diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_struct.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_struct.rs index ef03a830fe..16f04b383e 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_struct.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_struct.rs @@ -15,20 +15,24 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < foo__bindgen_ty_1 > (), 8usize, concat!("Size of: ", - stringify!(foo__bindgen_ty_1)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", - stringify!(foo__bindgen_ty_1)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)), ); } #[test] @@ -36,15 +40,19 @@ 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:: < foo > (), 8usize, concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(foo)), ); assert_eq!( - ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", - stringify!(foo)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)), ); } impl Default for foo { diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_1_0.rs index a4beed5199..269a10aa1c 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_1_0.rs @@ -59,20 +59,24 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < foo__bindgen_ty_1 > (), 8usize, concat!("Size of: ", - stringify!(foo__bindgen_ty_1)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", - stringify!(foo__bindgen_ty_1)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)), ); } impl Clone for foo__bindgen_ty_1 { @@ -85,15 +89,19 @@ 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:: < foo > (), 8usize, concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(foo)), ); assert_eq!( - ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", - stringify!(foo)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)), ); } impl Clone for foo { diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield.rs index 649fdfc2cb..2f99027158 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield.rs @@ -49,7 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -69,7 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -99,12 +99,14 @@ pub struct foo__bindgen_ty_1 { #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { assert_eq!( - ::std::mem::size_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Size of: ", - stringify!(foo__bindgen_ty_1)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", - stringify!(foo__bindgen_ty_1)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo__bindgen_ty_1)), ); } impl foo__bindgen_ty_1 { @@ -162,15 +164,19 @@ 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:: < foo > (), 4usize, concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo)), ); assert_eq!( - ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", - stringify!(foo)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)), ); } impl Default for foo { diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs index 02df95b5e8..90bb27437e 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs @@ -49,7 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -69,7 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -143,12 +143,14 @@ pub struct foo__bindgen_ty_1 { #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { assert_eq!( - ::std::mem::size_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Size of: ", - stringify!(foo__bindgen_ty_1)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", - stringify!(foo__bindgen_ty_1)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo__bindgen_ty_1)), ); } impl Clone for foo__bindgen_ty_1 { @@ -211,15 +213,19 @@ 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:: < foo > (), 4usize, concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo)), ); assert_eq!( - ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", - stringify!(foo)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)), ); } impl Clone for foo { diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_union.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_union.rs index ce74a6f03d..cbdeca49c0 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_union.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_union.rs @@ -15,20 +15,24 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Size of: ", - stringify!(foo__bindgen_ty_1)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", - stringify!(foo__bindgen_ty_1)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)), ); } impl Default for foo__bindgen_ty_1 { @@ -45,15 +49,19 @@ 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:: < foo > (), 4usize, concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo)), ); assert_eq!( - ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", - stringify!(foo)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)), ); } impl Default for foo { diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_union_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_union_1_0.rs index 1cafbe7144..176c9ec0de 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_union_1_0.rs @@ -60,20 +60,24 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Size of: ", - stringify!(foo__bindgen_ty_1)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Alignment of ", - stringify!(foo__bindgen_ty_1)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)), ); } impl Clone for foo__bindgen_ty_1 { @@ -86,15 +90,19 @@ 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:: < foo > (), 4usize, concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo)), ); assert_eq!( - ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", - stringify!(foo)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)), ); } impl Clone for foo { diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct.rs index bd158c8793..4f8aa8ff8a 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct.rs @@ -18,32 +18,54 @@ fn bindgen_test_layout_pixel__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < pixel__bindgen_ty_1 > (), 4usize, concat!("Size of: ", - stringify!(pixel__bindgen_ty_1)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(pixel__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < pixel__bindgen_ty_1 > (), 1usize, - concat!("Alignment of ", stringify!(pixel__bindgen_ty_1)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(pixel__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).r) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(pixel__bindgen_ty_1), "::", - stringify!(r)) + unsafe { ::std::ptr::addr_of!((*ptr).r) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(pixel__bindgen_ty_1), + "::", + stringify!(r), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).g) as usize - ptr as usize }, 1usize, - concat!("Offset of field: ", stringify!(pixel__bindgen_ty_1), "::", - stringify!(g)) + unsafe { ::std::ptr::addr_of!((*ptr).g) as usize - ptr as usize }, + 1usize, + concat!( + "Offset of field: ", + stringify!(pixel__bindgen_ty_1), + "::", + stringify!(g), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 2usize, - concat!("Offset of field: ", stringify!(pixel__bindgen_ty_1), "::", - stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 2usize, + concat!( + "Offset of field: ", + stringify!(pixel__bindgen_ty_1), + "::", + stringify!(b), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 3usize, - concat!("Offset of field: ", stringify!(pixel__bindgen_ty_1), "::", - stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 3usize, + concat!( + "Offset of field: ", + stringify!(pixel__bindgen_ty_1), + "::", + stringify!(a), + ), ); } #[test] @@ -51,16 +73,19 @@ fn bindgen_test_layout_pixel() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < pixel > (), 4usize, concat!("Size of: ", - stringify!(pixel)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(pixel)), ); assert_eq!( - ::std::mem::align_of:: < pixel > (), 4usize, concat!("Alignment of ", - stringify!(pixel)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(pixel)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).rgba) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(pixel), "::", stringify!(rgba)) + unsafe { ::std::ptr::addr_of!((*ptr).rgba) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(pixel), "::", stringify!(rgba)), ); } impl Default for pixel { diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs index 80c38abde1..446044d8d2 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs @@ -62,32 +62,54 @@ fn bindgen_test_layout_pixel__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < pixel__bindgen_ty_1 > (), 4usize, concat!("Size of: ", - stringify!(pixel__bindgen_ty_1)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(pixel__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < pixel__bindgen_ty_1 > (), 1usize, - concat!("Alignment of ", stringify!(pixel__bindgen_ty_1)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(pixel__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).r) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(pixel__bindgen_ty_1), "::", - stringify!(r)) + unsafe { ::std::ptr::addr_of!((*ptr).r) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(pixel__bindgen_ty_1), + "::", + stringify!(r), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).g) as usize - ptr as usize }, 1usize, - concat!("Offset of field: ", stringify!(pixel__bindgen_ty_1), "::", - stringify!(g)) + unsafe { ::std::ptr::addr_of!((*ptr).g) as usize - ptr as usize }, + 1usize, + concat!( + "Offset of field: ", + stringify!(pixel__bindgen_ty_1), + "::", + stringify!(g), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 2usize, - concat!("Offset of field: ", stringify!(pixel__bindgen_ty_1), "::", - stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 2usize, + concat!( + "Offset of field: ", + stringify!(pixel__bindgen_ty_1), + "::", + stringify!(b), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 3usize, - concat!("Offset of field: ", stringify!(pixel__bindgen_ty_1), "::", - stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 3usize, + concat!( + "Offset of field: ", + stringify!(pixel__bindgen_ty_1), + "::", + stringify!(a), + ), ); } impl Clone for pixel__bindgen_ty_1 { @@ -100,16 +122,19 @@ fn bindgen_test_layout_pixel() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < pixel > (), 4usize, concat!("Size of: ", - stringify!(pixel)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(pixel)), ); assert_eq!( - ::std::mem::align_of:: < pixel > (), 4usize, concat!("Alignment of ", - stringify!(pixel)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(pixel)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).rgba) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(pixel), "::", stringify!(rgba)) + unsafe { ::std::ptr::addr_of!((*ptr).rgba) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(pixel), "::", stringify!(rgba)), ); } impl Clone for pixel { diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union.rs index a3b0f72e6c..d9d22e323e 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union.rs @@ -16,20 +16,24 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < foo__bindgen_ty_1 > (), 2usize, concat!("Size of: ", - stringify!(foo__bindgen_ty_1)) + ::std::mem::size_of::(), + 2usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < foo__bindgen_ty_1 > (), 2usize, concat!("Alignment of ", - stringify!(foo__bindgen_ty_1)) + ::std::mem::align_of::(), + 2usize, + concat!("Alignment of ", stringify!(foo__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).c) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(c)) + unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(c)), ); } impl Default for foo__bindgen_ty_1 { @@ -46,15 +50,19 @@ 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:: < foo > (), 4usize, concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo)), ); assert_eq!( - ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", - stringify!(foo)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)), ); } impl Default for foo { diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs index 59887dc900..57916a89f6 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs @@ -61,20 +61,24 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < foo__bindgen_ty_1 > (), 2usize, concat!("Size of: ", - stringify!(foo__bindgen_ty_1)) + ::std::mem::size_of::(), + 2usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < foo__bindgen_ty_1 > (), 2usize, concat!("Alignment of ", - stringify!(foo__bindgen_ty_1)) + ::std::mem::align_of::(), + 2usize, + concat!("Alignment of ", stringify!(foo__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).c) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(c)) + unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(c)), ); } impl Clone for foo__bindgen_ty_1 { @@ -87,15 +91,19 @@ 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:: < foo > (), 4usize, concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo)), ); assert_eq!( - ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", - stringify!(foo)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)), ); } impl Clone for foo { diff --git a/bindgen-tests/tests/expectations/tests/union_with_big_member.rs b/bindgen-tests/tests/expectations/tests/union_with_big_member.rs index 4d5461809d..955e57a0a0 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_big_member.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_big_member.rs @@ -10,20 +10,24 @@ 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:: < WithBigArray > (), 132usize, concat!("Size of: ", - stringify!(WithBigArray)) + ::std::mem::size_of::(), + 132usize, + concat!("Size of: ", stringify!(WithBigArray)), ); assert_eq!( - ::std::mem::align_of:: < WithBigArray > (), 4usize, concat!("Alignment of ", - stringify!(WithBigArray)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(WithBigArray)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(WithBigArray), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(WithBigArray), "::", stringify!(a)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(WithBigArray), "::", stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(WithBigArray), "::", stringify!(b)), ); } impl Default for WithBigArray { @@ -46,20 +50,24 @@ fn bindgen_test_layout_WithBigArray2() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < WithBigArray2 > (), 36usize, concat!("Size of: ", - stringify!(WithBigArray2)) + ::std::mem::size_of::(), + 36usize, + concat!("Size of: ", stringify!(WithBigArray2)), ); assert_eq!( - ::std::mem::align_of:: < WithBigArray2 > (), 4usize, concat!("Alignment of ", - stringify!(WithBigArray2)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(WithBigArray2)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(WithBigArray2), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(WithBigArray2), "::", stringify!(a)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(WithBigArray2), "::", stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(WithBigArray2), "::", stringify!(b)), ); } impl Default for WithBigArray2 { @@ -82,20 +90,24 @@ fn bindgen_test_layout_WithBigMember() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < WithBigMember > (), 132usize, concat!("Size of: ", - stringify!(WithBigMember)) + ::std::mem::size_of::(), + 132usize, + concat!("Size of: ", stringify!(WithBigMember)), ); assert_eq!( - ::std::mem::align_of:: < WithBigMember > (), 4usize, concat!("Alignment of ", - stringify!(WithBigMember)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(WithBigMember)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(WithBigMember), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(WithBigMember), "::", stringify!(a)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(WithBigMember), "::", stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(WithBigMember), "::", stringify!(b)), ); } impl Default for WithBigMember { diff --git a/bindgen-tests/tests/expectations/tests/union_with_big_member_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_big_member_1_0.rs index 0e192d4898..adda6a0d7e 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_big_member_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_big_member_1_0.rs @@ -54,20 +54,24 @@ 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:: < WithBigArray > (), 132usize, concat!("Size of: ", - stringify!(WithBigArray)) + ::std::mem::size_of::(), + 132usize, + concat!("Size of: ", stringify!(WithBigArray)), ); assert_eq!( - ::std::mem::align_of:: < WithBigArray > (), 4usize, concat!("Alignment of ", - stringify!(WithBigArray)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(WithBigArray)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(WithBigArray), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(WithBigArray), "::", stringify!(a)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(WithBigArray), "::", stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(WithBigArray), "::", stringify!(b)), ); } impl Clone for WithBigArray { @@ -96,20 +100,24 @@ fn bindgen_test_layout_WithBigArray2() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < WithBigArray2 > (), 36usize, concat!("Size of: ", - stringify!(WithBigArray2)) + ::std::mem::size_of::(), + 36usize, + concat!("Size of: ", stringify!(WithBigArray2)), ); assert_eq!( - ::std::mem::align_of:: < WithBigArray2 > (), 4usize, concat!("Alignment of ", - stringify!(WithBigArray2)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(WithBigArray2)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(WithBigArray2), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(WithBigArray2), "::", stringify!(a)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(WithBigArray2), "::", stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(WithBigArray2), "::", stringify!(b)), ); } impl Clone for WithBigArray2 { @@ -129,20 +137,24 @@ fn bindgen_test_layout_WithBigMember() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < WithBigMember > (), 132usize, concat!("Size of: ", - stringify!(WithBigMember)) + ::std::mem::size_of::(), + 132usize, + concat!("Size of: ", stringify!(WithBigMember)), ); assert_eq!( - ::std::mem::align_of:: < WithBigMember > (), 4usize, concat!("Alignment of ", - stringify!(WithBigMember)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(WithBigMember)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(WithBigMember), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(WithBigMember), "::", stringify!(a)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(WithBigMember), "::", stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(WithBigMember), "::", stringify!(b)), ); } impl Clone for WithBigMember { diff --git a/bindgen-tests/tests/expectations/tests/union_with_nesting.rs b/bindgen-tests/tests/expectations/tests/union_with_nesting.rs index 1feafebe73..929484d12c 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_nesting.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_nesting.rs @@ -22,22 +22,34 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < foo__bindgen_ty_1__bindgen_ty_1 > (), 2usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)) + ::std::mem::size_of::(), + 2usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < foo__bindgen_ty_1__bindgen_ty_1 > (), 2usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)) + ::std::mem::align_of::(), + 2usize, + concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b1) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1__bindgen_ty_1), "::", - stringify!(b1)) + unsafe { ::std::ptr::addr_of!((*ptr).b1) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(b1), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b2) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1__bindgen_ty_1), "::", - stringify!(b2)) + unsafe { ::std::ptr::addr_of!((*ptr).b2) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(b2), + ), ); } impl Default for foo__bindgen_ty_1__bindgen_ty_1 { @@ -60,22 +72,34 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < foo__bindgen_ty_1__bindgen_ty_2 > (), 2usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)) + ::std::mem::size_of::(), + 2usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)), ); assert_eq!( - ::std::mem::align_of:: < foo__bindgen_ty_1__bindgen_ty_2 > (), 2usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)) + ::std::mem::align_of::(), + 2usize, + concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).c1) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2), "::", - stringify!(c1)) + unsafe { ::std::ptr::addr_of!((*ptr).c1) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(c1), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).c2) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2), "::", - stringify!(c2)) + unsafe { ::std::ptr::addr_of!((*ptr).c2) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(c2), + ), ); } impl Default for foo__bindgen_ty_1__bindgen_ty_2 { @@ -90,12 +114,14 @@ impl Default for foo__bindgen_ty_1__bindgen_ty_2 { #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { assert_eq!( - ::std::mem::size_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Size of: ", - stringify!(foo__bindgen_ty_1)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < foo__bindgen_ty_1 > (), 2usize, concat!("Alignment of ", - stringify!(foo__bindgen_ty_1)) + ::std::mem::align_of::(), + 2usize, + concat!("Alignment of ", stringify!(foo__bindgen_ty_1)), ); } impl Default for foo__bindgen_ty_1 { @@ -112,15 +138,19 @@ 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:: < foo > (), 4usize, concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo)), ); assert_eq!( - ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", - stringify!(foo)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)), ); } impl Default for foo { diff --git a/bindgen-tests/tests/expectations/tests/union_with_nesting_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_nesting_1_0.rs index 9dc42f3eaa..94fab65192 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_nesting_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_nesting_1_0.rs @@ -67,22 +67,34 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < foo__bindgen_ty_1__bindgen_ty_1 > (), 2usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)) + ::std::mem::size_of::(), + 2usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < foo__bindgen_ty_1__bindgen_ty_1 > (), 2usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)) + ::std::mem::align_of::(), + 2usize, + concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b1) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1__bindgen_ty_1), "::", - stringify!(b1)) + unsafe { ::std::ptr::addr_of!((*ptr).b1) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(b1), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b2) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1__bindgen_ty_1), "::", - stringify!(b2)) + unsafe { ::std::ptr::addr_of!((*ptr).b2) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(b2), + ), ); } impl Clone for foo__bindgen_ty_1__bindgen_ty_1 { @@ -102,22 +114,34 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < foo__bindgen_ty_1__bindgen_ty_2 > (), 2usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)) + ::std::mem::size_of::(), + 2usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)), ); assert_eq!( - ::std::mem::align_of:: < foo__bindgen_ty_1__bindgen_ty_2 > (), 2usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)) + ::std::mem::align_of::(), + 2usize, + concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).c1) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2), "::", - stringify!(c1)) + unsafe { ::std::ptr::addr_of!((*ptr).c1) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(c1), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).c2) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2), "::", - stringify!(c2)) + unsafe { ::std::ptr::addr_of!((*ptr).c2) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(foo__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(c2), + ), ); } impl Clone for foo__bindgen_ty_1__bindgen_ty_2 { @@ -128,12 +152,14 @@ impl Clone for foo__bindgen_ty_1__bindgen_ty_2 { #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { assert_eq!( - ::std::mem::size_of:: < foo__bindgen_ty_1 > (), 4usize, concat!("Size of: ", - stringify!(foo__bindgen_ty_1)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo__bindgen_ty_1)), ); assert_eq!( - ::std::mem::align_of:: < foo__bindgen_ty_1 > (), 2usize, concat!("Alignment of ", - stringify!(foo__bindgen_ty_1)) + ::std::mem::align_of::(), + 2usize, + concat!("Alignment of ", stringify!(foo__bindgen_ty_1)), ); } impl Clone for foo__bindgen_ty_1 { @@ -146,15 +172,19 @@ 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:: < foo > (), 4usize, concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(foo)), ); assert_eq!( - ::std::mem::align_of:: < foo > (), 4usize, concat!("Alignment of ", - stringify!(foo)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)), ); } impl Clone for foo { diff --git a/bindgen-tests/tests/expectations/tests/union_with_non_copy_member.rs b/bindgen-tests/tests/expectations/tests/union_with_non_copy_member.rs index 2c7789128e..580826f4c0 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_non_copy_member.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_non_copy_member.rs @@ -52,16 +52,19 @@ fn bindgen_test_layout_NonCopyType() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < NonCopyType > (), 4usize, concat!("Size of: ", - stringify!(NonCopyType)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(NonCopyType)), ); assert_eq!( - ::std::mem::align_of:: < NonCopyType > (), 4usize, concat!("Alignment of ", - stringify!(NonCopyType)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(NonCopyType)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).foo) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(NonCopyType), "::", stringify!(foo)) + unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(NonCopyType), "::", stringify!(foo)), ); } #[repr(C)] @@ -75,22 +78,34 @@ fn bindgen_test_layout_WithBindgenGeneratedWrapper() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < WithBindgenGeneratedWrapper > (), 4usize, - concat!("Size of: ", stringify!(WithBindgenGeneratedWrapper)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(WithBindgenGeneratedWrapper)), ); assert_eq!( - ::std::mem::align_of:: < WithBindgenGeneratedWrapper > (), 4usize, - concat!("Alignment of ", stringify!(WithBindgenGeneratedWrapper)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(WithBindgenGeneratedWrapper)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).non_copy_type) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(WithBindgenGeneratedWrapper), - "::", stringify!(non_copy_type)) + unsafe { ::std::ptr::addr_of!((*ptr).non_copy_type) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithBindgenGeneratedWrapper), + "::", + stringify!(non_copy_type), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(WithBindgenGeneratedWrapper), "::", - stringify!(bar)) + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithBindgenGeneratedWrapper), + "::", + stringify!(bar), + ), ); } impl Default for WithBindgenGeneratedWrapper { @@ -112,21 +127,29 @@ fn bindgen_test_layout_WithManuallyDrop() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < WithManuallyDrop > (), 4usize, concat!("Size of: ", - stringify!(WithManuallyDrop)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(WithManuallyDrop)), ); assert_eq!( - ::std::mem::align_of:: < WithManuallyDrop > (), 4usize, concat!("Alignment of ", - stringify!(WithManuallyDrop)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(WithManuallyDrop)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).non_copy_type) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(WithManuallyDrop), "::", - stringify!(non_copy_type)) + unsafe { ::std::ptr::addr_of!((*ptr).non_copy_type) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithManuallyDrop), + "::", + stringify!(non_copy_type), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(WithManuallyDrop), "::", stringify!(bar)) + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(WithManuallyDrop), "::", stringify!(bar)), ); } impl Default for WithManuallyDrop { @@ -149,22 +172,34 @@ fn bindgen_test_layout_WithDefaultWrapper() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < WithDefaultWrapper > (), 4usize, concat!("Size of: ", - stringify!(WithDefaultWrapper)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(WithDefaultWrapper)), ); assert_eq!( - ::std::mem::align_of:: < WithDefaultWrapper > (), 4usize, - concat!("Alignment of ", stringify!(WithDefaultWrapper)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(WithDefaultWrapper)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).non_copy_type) as usize - ptr as usize }, - 0usize, concat!("Offset of field: ", stringify!(WithDefaultWrapper), "::", - stringify!(non_copy_type)) + unsafe { ::std::ptr::addr_of!((*ptr).non_copy_type) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithDefaultWrapper), + "::", + stringify!(non_copy_type), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(WithDefaultWrapper), "::", - stringify!(bar)) + unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(WithDefaultWrapper), + "::", + stringify!(bar), + ), ); } impl Default for WithDefaultWrapper { diff --git a/bindgen-tests/tests/expectations/tests/unknown_attr.rs b/bindgen-tests/tests/expectations/tests/unknown_attr.rs index 3233800101..7b21595d9f 100644 --- a/bindgen-tests/tests/expectations/tests/unknown_attr.rs +++ b/bindgen-tests/tests/expectations/tests/unknown_attr.rs @@ -12,21 +12,37 @@ fn bindgen_test_layout_max_align_t() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < max_align_t > (), 32usize, concat!("Size of: ", - stringify!(max_align_t)) + ::std::mem::size_of::(), + 32usize, + concat!("Size of: ", stringify!(max_align_t)), ); assert_eq!( - ::std::mem::align_of:: < max_align_t > (), 16usize, concat!("Alignment of ", - stringify!(max_align_t)) + ::std::mem::align_of::(), + 16usize, + concat!("Alignment of ", stringify!(max_align_t)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).__clang_max_align_nonce1) as usize - ptr as - usize }, 0usize, concat!("Offset of field: ", stringify!(max_align_t), "::", - stringify!(__clang_max_align_nonce1)) + unsafe { + ::std::ptr::addr_of!((*ptr).__clang_max_align_nonce1) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(max_align_t), + "::", + stringify!(__clang_max_align_nonce1), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).__clang_max_align_nonce2) as usize - ptr as - usize }, 16usize, concat!("Offset of field: ", stringify!(max_align_t), "::", - stringify!(__clang_max_align_nonce2)) + unsafe { + ::std::ptr::addr_of!((*ptr).__clang_max_align_nonce2) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(max_align_t), + "::", + stringify!(__clang_max_align_nonce2), + ), ); } diff --git a/bindgen-tests/tests/expectations/tests/unsorted-items.rs b/bindgen-tests/tests/expectations/tests/unsorted-items.rs index 0ba9d89491..745ddd92e2 100644 --- a/bindgen-tests/tests/expectations/tests/unsorted-items.rs +++ b/bindgen-tests/tests/expectations/tests/unsorted-items.rs @@ -17,20 +17,24 @@ fn bindgen_test_layout_Point() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < Point > (), 8usize, concat!("Size of: ", - stringify!(Point)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Point)), ); assert_eq!( - ::std::mem::align_of:: < Point > (), 4usize, concat!("Alignment of ", - stringify!(Point)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Point)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).x) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Point), "::", stringify!(x)) + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Point), "::", stringify!(x)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).y) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(Point), "::", stringify!(y)) + unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(Point), "::", stringify!(y)), ); } #[repr(C)] @@ -44,20 +48,24 @@ fn bindgen_test_layout_Angle() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < Angle > (), 8usize, concat!("Size of: ", - stringify!(Angle)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Angle)), ); assert_eq!( - ::std::mem::align_of:: < Angle > (), 4usize, concat!("Alignment of ", - stringify!(Angle)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Angle)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Angle), "::", stringify!(a)) + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Angle), "::", stringify!(a)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(Angle), "::", stringify!(b)) + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(Angle), "::", stringify!(b)), ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/use-core.rs b/bindgen-tests/tests/expectations/tests/use-core.rs index f7865e58d1..2b6e93bfc4 100644 --- a/bindgen-tests/tests/expectations/tests/use-core.rs +++ b/bindgen-tests/tests/expectations/tests/use-core.rs @@ -13,23 +13,29 @@ fn bindgen_test_layout_foo() { const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::core::mem::size_of:: < foo > (), 16usize, concat!("Size of: ", stringify!(foo)) + ::core::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(foo)), ); assert_eq!( - ::core::mem::align_of:: < foo > (), 8usize, concat!("Alignment of ", - stringify!(foo)) + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(foo)), ); assert_eq!( - unsafe { ::core::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) + unsafe { ::core::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)), ); assert_eq!( - unsafe { ::core::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) + unsafe { ::core::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)), ); assert_eq!( - unsafe { ::core::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) + unsafe { ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, + 8usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)), ); } impl Default for foo { @@ -52,20 +58,24 @@ fn bindgen_test_layout__bindgen_ty_1() { const UNINIT: ::core::mem::MaybeUninit<_bindgen_ty_1> = ::core::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::core::mem::size_of:: < _bindgen_ty_1 > (), 8usize, concat!("Size of: ", - stringify!(_bindgen_ty_1)) + ::core::mem::size_of::<_bindgen_ty_1>(), + 8usize, + concat!("Size of: ", stringify!(_bindgen_ty_1)), ); assert_eq!( - ::core::mem::align_of:: < _bindgen_ty_1 > (), 8usize, concat!("Alignment of ", - stringify!(_bindgen_ty_1)) + ::core::mem::align_of::<_bindgen_ty_1>(), + 8usize, + concat!("Alignment of ", stringify!(_bindgen_ty_1)), ); assert_eq!( - unsafe { ::core::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(_bindgen_ty_1), "::", stringify!(bar)) + unsafe { ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(_bindgen_ty_1), "::", stringify!(bar)), ); assert_eq!( - unsafe { ::core::ptr::addr_of!((* ptr).baz) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(_bindgen_ty_1), "::", stringify!(baz)) + unsafe { ::core::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(_bindgen_ty_1), "::", stringify!(baz)), ); } impl Default for _bindgen_ty_1 { diff --git a/bindgen-tests/tests/expectations/tests/use-core_1_0.rs b/bindgen-tests/tests/expectations/tests/use-core_1_0.rs index 80fd7b0556..a11ea28659 100644 --- a/bindgen-tests/tests/expectations/tests/use-core_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/use-core_1_0.rs @@ -55,23 +55,29 @@ fn bindgen_test_layout_foo() { const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::core::mem::size_of:: < foo > (), 16usize, concat!("Size of: ", stringify!(foo)) + ::core::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(foo)), ); assert_eq!( - ::core::mem::align_of:: < foo > (), 8usize, concat!("Alignment of ", - stringify!(foo)) + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(foo)), ); assert_eq!( - unsafe { ::core::ptr::addr_of!((* ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)) + unsafe { ::core::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)), ); assert_eq!( - unsafe { ::core::ptr::addr_of!((* ptr).b) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)) + unsafe { ::core::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)), ); assert_eq!( - unsafe { ::core::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)) + unsafe { ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, + 8usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)), ); } impl Clone for foo { @@ -100,20 +106,24 @@ fn bindgen_test_layout__bindgen_ty_1() { const UNINIT: ::core::mem::MaybeUninit<_bindgen_ty_1> = ::core::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::core::mem::size_of:: < _bindgen_ty_1 > (), 8usize, concat!("Size of: ", - stringify!(_bindgen_ty_1)) + ::core::mem::size_of::<_bindgen_ty_1>(), + 8usize, + concat!("Size of: ", stringify!(_bindgen_ty_1)), ); assert_eq!( - ::core::mem::align_of:: < _bindgen_ty_1 > (), 8usize, concat!("Alignment of ", - stringify!(_bindgen_ty_1)) + ::core::mem::align_of::<_bindgen_ty_1>(), + 8usize, + concat!("Alignment of ", stringify!(_bindgen_ty_1)), ); assert_eq!( - unsafe { ::core::ptr::addr_of!((* ptr).bar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(_bindgen_ty_1), "::", stringify!(bar)) + unsafe { ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(_bindgen_ty_1), "::", stringify!(bar)), ); assert_eq!( - unsafe { ::core::ptr::addr_of!((* ptr).baz) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(_bindgen_ty_1), "::", stringify!(baz)) + unsafe { ::core::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(_bindgen_ty_1), "::", stringify!(baz)), ); } impl Clone for _bindgen_ty_1 { diff --git a/bindgen-tests/tests/expectations/tests/var-tracing.rs b/bindgen-tests/tests/expectations/tests/var-tracing.rs index c6a06ef4b1..fcd5d59471 100644 --- a/bindgen-tests/tests/expectations/tests/var-tracing.rs +++ b/bindgen-tests/tests/expectations/tests/var-tracing.rs @@ -9,15 +9,19 @@ 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:: < Bar > (), 4usize, concat!("Size of: ", stringify!(Bar)) + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Bar)), ); assert_eq!( - ::std::mem::align_of:: < Bar > (), 4usize, concat!("Alignment of ", - stringify!(Bar)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Bar)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).m_baz) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(m_baz)) + unsafe { ::std::ptr::addr_of!((*ptr).m_baz) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Bar), "::", stringify!(m_baz)), ); } extern "C" { @@ -44,10 +48,13 @@ extern "C" { #[test] fn bindgen_test_layout_Baz() { assert_eq!( - ::std::mem::size_of:: < Baz > (), 1usize, concat!("Size of: ", stringify!(Baz)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Baz)), ); assert_eq!( - ::std::mem::align_of:: < Baz > (), 1usize, concat!("Alignment of ", - stringify!(Baz)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Baz)), ); } diff --git a/bindgen-tests/tests/expectations/tests/variadic-method.rs b/bindgen-tests/tests/expectations/tests/variadic-method.rs index ebf454335c..c9b4e87bf9 100644 --- a/bindgen-tests/tests/expectations/tests/variadic-method.rs +++ b/bindgen-tests/tests/expectations/tests/variadic-method.rs @@ -11,11 +11,14 @@ pub struct Bar { #[test] fn bindgen_test_layout_Bar() { assert_eq!( - ::std::mem::size_of:: < Bar > (), 1usize, concat!("Size of: ", stringify!(Bar)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Bar)), ); assert_eq!( - ::std::mem::align_of:: < Bar > (), 1usize, concat!("Alignment of ", - stringify!(Bar)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Bar)), ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/vector.rs b/bindgen-tests/tests/expectations/tests/vector.rs index d397d5b8c8..fc400acebf 100644 --- a/bindgen-tests/tests/expectations/tests/vector.rs +++ b/bindgen-tests/tests/expectations/tests/vector.rs @@ -9,15 +9,19 @@ 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:: < foo > (), 8usize, concat!("Size of: ", stringify!(foo)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(foo)), ); assert_eq!( - ::std::mem::align_of:: < foo > (), 8usize, concat!("Alignment of ", - stringify!(foo)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(foo)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mMember) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(mMember)) + unsafe { ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(mMember)), ); } pub type __m128 = [f32; 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/virtual_dtor.rs b/bindgen-tests/tests/expectations/tests/virtual_dtor.rs index 271f959dfb..cff0bc1205 100644 --- a/bindgen-tests/tests/expectations/tests/virtual_dtor.rs +++ b/bindgen-tests/tests/expectations/tests/virtual_dtor.rs @@ -9,12 +9,14 @@ pub struct nsSlots { #[test] fn bindgen_test_layout_nsSlots() { assert_eq!( - ::std::mem::size_of:: < nsSlots > (), 8usize, concat!("Size of: ", - stringify!(nsSlots)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(nsSlots)), ); assert_eq!( - ::std::mem::align_of:: < nsSlots > (), 8usize, concat!("Alignment of ", - stringify!(nsSlots)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(nsSlots)), ); } impl Default for nsSlots { diff --git a/bindgen-tests/tests/expectations/tests/virtual_interface.rs b/bindgen-tests/tests/expectations/tests/virtual_interface.rs index 50ac61efc8..e3440567b4 100644 --- a/bindgen-tests/tests/expectations/tests/virtual_interface.rs +++ b/bindgen-tests/tests/expectations/tests/virtual_interface.rs @@ -15,12 +15,14 @@ pub struct PureVirtualIFace { #[test] fn bindgen_test_layout_PureVirtualIFace() { assert_eq!( - ::std::mem::size_of:: < PureVirtualIFace > (), 8usize, concat!("Size of: ", - stringify!(PureVirtualIFace)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(PureVirtualIFace)), ); assert_eq!( - ::std::mem::align_of:: < PureVirtualIFace > (), 8usize, concat!("Alignment of ", - stringify!(PureVirtualIFace)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(PureVirtualIFace)), ); } impl Default for PureVirtualIFace { @@ -44,12 +46,14 @@ pub struct AnotherInterface { #[test] fn bindgen_test_layout_AnotherInterface() { assert_eq!( - ::std::mem::size_of:: < AnotherInterface > (), 8usize, concat!("Size of: ", - stringify!(AnotherInterface)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(AnotherInterface)), ); assert_eq!( - ::std::mem::align_of:: < AnotherInterface > (), 8usize, concat!("Alignment of ", - stringify!(AnotherInterface)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(AnotherInterface)), ); } impl Default for AnotherInterface { @@ -69,12 +73,14 @@ pub struct Implementation { #[test] fn bindgen_test_layout_Implementation() { assert_eq!( - ::std::mem::size_of:: < Implementation > (), 8usize, concat!("Size of: ", - stringify!(Implementation)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Implementation)), ); assert_eq!( - ::std::mem::align_of:: < Implementation > (), 8usize, concat!("Alignment of ", - stringify!(Implementation)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Implementation)), ); } impl Default for Implementation { @@ -95,12 +101,14 @@ pub struct DoubleImpl { #[test] fn bindgen_test_layout_DoubleImpl() { assert_eq!( - ::std::mem::size_of:: < DoubleImpl > (), 16usize, concat!("Size of: ", - stringify!(DoubleImpl)) + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(DoubleImpl)), ); assert_eq!( - ::std::mem::align_of:: < DoubleImpl > (), 8usize, concat!("Alignment of ", - stringify!(DoubleImpl)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(DoubleImpl)), ); } impl Default for DoubleImpl { diff --git a/bindgen-tests/tests/expectations/tests/virtual_overloaded.rs b/bindgen-tests/tests/expectations/tests/virtual_overloaded.rs index 9d33bc336a..28a873c458 100644 --- a/bindgen-tests/tests/expectations/tests/virtual_overloaded.rs +++ b/bindgen-tests/tests/expectations/tests/virtual_overloaded.rs @@ -11,11 +11,11 @@ pub struct C { } #[test] fn bindgen_test_layout_C() { + assert_eq!(::std::mem::size_of::(), 8usize, concat!("Size of: ", stringify!(C))); assert_eq!( - ::std::mem::size_of:: < C > (), 8usize, concat!("Size of: ", stringify!(C)) - ); - assert_eq!( - ::std::mem::align_of:: < C > (), 8usize, concat!("Alignment of ", stringify!(C)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(C)), ); } impl Default for C { diff --git a/bindgen-tests/tests/expectations/tests/vtable_recursive_sig.rs b/bindgen-tests/tests/expectations/tests/vtable_recursive_sig.rs index d16557d371..a37ecf2669 100644 --- a/bindgen-tests/tests/expectations/tests/vtable_recursive_sig.rs +++ b/bindgen-tests/tests/expectations/tests/vtable_recursive_sig.rs @@ -11,11 +11,14 @@ pub struct Base { #[test] fn bindgen_test_layout_Base() { assert_eq!( - ::std::mem::size_of:: < Base > (), 8usize, concat!("Size of: ", stringify!(Base)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Base)), ); assert_eq!( - ::std::mem::align_of:: < Base > (), 8usize, concat!("Alignment of ", - stringify!(Base)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Base)), ); } impl Default for Base { @@ -39,12 +42,14 @@ pub struct Derived { #[test] fn bindgen_test_layout_Derived() { assert_eq!( - ::std::mem::size_of:: < Derived > (), 8usize, concat!("Size of: ", - stringify!(Derived)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Derived)), ); assert_eq!( - ::std::mem::align_of:: < Derived > (), 8usize, concat!("Alignment of ", - stringify!(Derived)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Derived)), ); } impl Default for Derived { diff --git a/bindgen-tests/tests/expectations/tests/wasm-constructor-returns.rs b/bindgen-tests/tests/expectations/tests/wasm-constructor-returns.rs index 73a5500db9..7c47a43c20 100644 --- a/bindgen-tests/tests/expectations/tests/wasm-constructor-returns.rs +++ b/bindgen-tests/tests/expectations/tests/wasm-constructor-returns.rs @@ -7,11 +7,14 @@ pub struct Foo { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo)), ); assert_eq!( - ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", - stringify!(Foo)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)), ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/weird_bitfields.rs b/bindgen-tests/tests/expectations/tests/weird_bitfields.rs index 0337786cdd..49579967fe 100644 --- a/bindgen-tests/tests/expectations/tests/weird_bitfields.rs +++ b/bindgen-tests/tests/expectations/tests/weird_bitfields.rs @@ -49,7 +49,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); let mut val = 0; for i in 0..(bit_width as usize) { @@ -69,7 +69,7 @@ where 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() + (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), ); for i in 0..(bit_width as usize) { let mask = 1 << i; @@ -116,72 +116,111 @@ fn bindgen_test_layout_Weird() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < Weird > (), 24usize, concat!("Size of: ", - stringify!(Weird)) + ::std::mem::size_of::(), + 24usize, + concat!("Size of: ", stringify!(Weird)), ); assert_eq!( - ::std::mem::align_of:: < Weird > (), 4usize, concat!("Alignment of ", - stringify!(Weird)) + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Weird)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mStrokeDasharrayLength) as usize - ptr as - usize }, 0usize, concat!("Offset of field: ", stringify!(Weird), "::", - stringify!(mStrokeDasharrayLength)) + unsafe { + ::std::ptr::addr_of!((*ptr).mStrokeDasharrayLength) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(Weird), + "::", + stringify!(mStrokeDasharrayLength), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mClipRule) as usize - ptr as usize }, - 8usize, concat!("Offset of field: ", stringify!(Weird), "::", - stringify!(mClipRule)) + unsafe { ::std::ptr::addr_of!((*ptr).mClipRule) as usize - ptr as usize }, + 8usize, + concat!("Offset of field: ", stringify!(Weird), "::", stringify!(mClipRule)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mColorInterpolation) as usize - ptr as - usize }, 9usize, concat!("Offset of field: ", stringify!(Weird), "::", - stringify!(mColorInterpolation)) + unsafe { + ::std::ptr::addr_of!((*ptr).mColorInterpolation) as usize - ptr as usize + }, + 9usize, + concat!( + "Offset of field: ", + stringify!(Weird), + "::", + stringify!(mColorInterpolation), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mColorInterpolationFilters) as usize - ptr - as usize }, 10usize, concat!("Offset of field: ", stringify!(Weird), "::", - stringify!(mColorInterpolationFilters)) + unsafe { + ::std::ptr::addr_of!((*ptr).mColorInterpolationFilters) as usize + - ptr as usize + }, + 10usize, + concat!( + "Offset of field: ", + stringify!(Weird), + "::", + stringify!(mColorInterpolationFilters), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mFillRule) as usize - ptr as usize }, - 11usize, concat!("Offset of field: ", stringify!(Weird), "::", - stringify!(mFillRule)) + unsafe { ::std::ptr::addr_of!((*ptr).mFillRule) as usize - ptr as usize }, + 11usize, + concat!("Offset of field: ", stringify!(Weird), "::", stringify!(mFillRule)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mImageRendering) as usize - ptr as usize }, - 12usize, concat!("Offset of field: ", stringify!(Weird), "::", - stringify!(mImageRendering)) + unsafe { ::std::ptr::addr_of!((*ptr).mImageRendering) as usize - ptr as usize }, + 12usize, + concat!( + "Offset of field: ", + stringify!(Weird), + "::", + stringify!(mImageRendering), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mPaintOrder) as usize - ptr as usize }, - 13usize, concat!("Offset of field: ", stringify!(Weird), "::", - stringify!(mPaintOrder)) + unsafe { ::std::ptr::addr_of!((*ptr).mPaintOrder) as usize - ptr as usize }, + 13usize, + concat!("Offset of field: ", stringify!(Weird), "::", stringify!(mPaintOrder)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mShapeRendering) as usize - ptr as usize }, - 14usize, concat!("Offset of field: ", stringify!(Weird), "::", - stringify!(mShapeRendering)) + unsafe { ::std::ptr::addr_of!((*ptr).mShapeRendering) as usize - ptr as usize }, + 14usize, + concat!( + "Offset of field: ", + stringify!(Weird), + "::", + stringify!(mShapeRendering), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mStrokeLinecap) as usize - ptr as usize }, - 15usize, concat!("Offset of field: ", stringify!(Weird), "::", - stringify!(mStrokeLinecap)) + unsafe { ::std::ptr::addr_of!((*ptr).mStrokeLinecap) as usize - ptr as usize }, + 15usize, + concat!("Offset of field: ", stringify!(Weird), "::", stringify!(mStrokeLinecap)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mStrokeLinejoin) as usize - ptr as usize }, - 16usize, concat!("Offset of field: ", stringify!(Weird), "::", - stringify!(mStrokeLinejoin)) + unsafe { ::std::ptr::addr_of!((*ptr).mStrokeLinejoin) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(Weird), + "::", + stringify!(mStrokeLinejoin), + ), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mTextAnchor) as usize - ptr as usize }, - 17usize, concat!("Offset of field: ", stringify!(Weird), "::", - stringify!(mTextAnchor)) + unsafe { ::std::ptr::addr_of!((*ptr).mTextAnchor) as usize - ptr as usize }, + 17usize, + concat!("Offset of field: ", stringify!(Weird), "::", stringify!(mTextAnchor)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).mTextRendering) as usize - ptr as usize }, - 18usize, concat!("Offset of field: ", stringify!(Weird), "::", - stringify!(mTextRendering)) + unsafe { ::std::ptr::addr_of!((*ptr).mTextRendering) as usize - ptr as usize }, + 18usize, + concat!("Offset of field: ", stringify!(Weird), "::", stringify!(mTextRendering)), ); } impl Default for Weird { diff --git a/bindgen-tests/tests/expectations/tests/what_is_going_on.rs b/bindgen-tests/tests/expectations/tests/what_is_going_on.rs index 4ba2c56683..596636a961 100644 --- a/bindgen-tests/tests/expectations/tests/what_is_going_on.rs +++ b/bindgen-tests/tests/expectations/tests/what_is_going_on.rs @@ -7,12 +7,14 @@ pub struct UnknownUnits { #[test] fn bindgen_test_layout_UnknownUnits() { assert_eq!( - ::std::mem::size_of:: < UnknownUnits > (), 1usize, concat!("Size of: ", - stringify!(UnknownUnits)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(UnknownUnits)), ); assert_eq!( - ::std::mem::align_of:: < UnknownUnits > (), 1usize, concat!("Alignment of ", - stringify!(UnknownUnits)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(UnknownUnits)), ); } pub type Float = f32; diff --git a/bindgen-tests/tests/expectations/tests/win32-thiscall_1_0.rs b/bindgen-tests/tests/expectations/tests/win32-thiscall_1_0.rs index 2cd4d0aa25..dc19e05dde 100644 --- a/bindgen-tests/tests/expectations/tests/win32-thiscall_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/win32-thiscall_1_0.rs @@ -7,11 +7,14 @@ pub struct Foo { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo)), ); assert_eq!( - ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", - stringify!(Foo)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)), ); } impl Clone for Foo { diff --git a/bindgen-tests/tests/expectations/tests/win32-thiscall_nightly.rs b/bindgen-tests/tests/expectations/tests/win32-thiscall_nightly.rs index 93c75b9388..ba861131b9 100644 --- a/bindgen-tests/tests/expectations/tests/win32-thiscall_nightly.rs +++ b/bindgen-tests/tests/expectations/tests/win32-thiscall_nightly.rs @@ -9,11 +9,14 @@ pub struct Foo { #[test] fn bindgen_test_layout_Foo() { assert_eq!( - ::std::mem::size_of:: < Foo > (), 1usize, concat!("Size of: ", stringify!(Foo)) + ::std::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(Foo)), ); assert_eq!( - ::std::mem::align_of:: < Foo > (), 1usize, concat!("Alignment of ", - stringify!(Foo)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)), ); } extern "thiscall" { diff --git a/bindgen-tests/tests/expectations/tests/zero-size-array-align.rs b/bindgen-tests/tests/expectations/tests/zero-size-array-align.rs index a0f65d8b2a..be373d7ae8 100644 --- a/bindgen-tests/tests/expectations/tests/zero-size-array-align.rs +++ b/bindgen-tests/tests/expectations/tests/zero-size-array-align.rs @@ -41,23 +41,28 @@ fn bindgen_test_layout_dm_deps() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < dm_deps > (), 8usize, concat!("Size of: ", - stringify!(dm_deps)) + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(dm_deps)), ); assert_eq!( - ::std::mem::align_of:: < dm_deps > (), 8usize, concat!("Alignment of ", - stringify!(dm_deps)) + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(dm_deps)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).count) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(dm_deps), "::", stringify!(count)) + unsafe { ::std::ptr::addr_of!((*ptr).count) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(dm_deps), "::", stringify!(count)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).filler) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(dm_deps), "::", stringify!(filler)) + unsafe { ::std::ptr::addr_of!((*ptr).filler) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(dm_deps), "::", stringify!(filler)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).device) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(dm_deps), "::", stringify!(device)) + unsafe { ::std::ptr::addr_of!((*ptr).device) as usize - ptr as usize }, + 8usize, + concat!("Offset of field: ", stringify!(dm_deps), "::", stringify!(device)), ); } diff --git a/bindgen-tests/tests/expectations/tests/zero-sized-array.rs b/bindgen-tests/tests/expectations/tests/zero-sized-array.rs index 477702a24e..b0a1d3e538 100644 --- a/bindgen-tests/tests/expectations/tests/zero-sized-array.rs +++ b/bindgen-tests/tests/expectations/tests/zero-sized-array.rs @@ -40,16 +40,19 @@ fn bindgen_test_layout_ZeroSizedArray() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < ZeroSizedArray > (), 0usize, concat!("Size of: ", - stringify!(ZeroSizedArray)) + ::std::mem::size_of::(), + 0usize, + concat!("Size of: ", stringify!(ZeroSizedArray)), ); assert_eq!( - ::std::mem::align_of:: < ZeroSizedArray > (), 1usize, concat!("Alignment of ", - stringify!(ZeroSizedArray)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(ZeroSizedArray)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).arr) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(ZeroSizedArray), "::", stringify!(arr)) + unsafe { ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(ZeroSizedArray), "::", stringify!(arr)), ); } /// And nor should this get an `_address` field. @@ -63,17 +66,24 @@ fn bindgen_test_layout_ContainsZeroSizedArray() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of:: < ContainsZeroSizedArray > (), 0usize, concat!("Size of: ", - stringify!(ContainsZeroSizedArray)) + ::std::mem::size_of::(), + 0usize, + concat!("Size of: ", stringify!(ContainsZeroSizedArray)), ); assert_eq!( - ::std::mem::align_of:: < ContainsZeroSizedArray > (), 1usize, - concat!("Alignment of ", stringify!(ContainsZeroSizedArray)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(ContainsZeroSizedArray)), ); assert_eq!( - unsafe { ::std::ptr::addr_of!((* ptr).zsa) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(ContainsZeroSizedArray), "::", - stringify!(zsa)) + unsafe { ::std::ptr::addr_of!((*ptr).zsa) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ContainsZeroSizedArray), + "::", + stringify!(zsa), + ), ); } /** Inheriting from ZeroSizedArray shouldn't cause an `_address` to be inserted @@ -86,12 +96,14 @@ pub struct InheritsZeroSizedArray { #[test] fn bindgen_test_layout_InheritsZeroSizedArray() { assert_eq!( - ::std::mem::size_of:: < InheritsZeroSizedArray > (), 0usize, concat!("Size of: ", - stringify!(InheritsZeroSizedArray)) + ::std::mem::size_of::(), + 0usize, + concat!("Size of: ", stringify!(InheritsZeroSizedArray)), ); assert_eq!( - ::std::mem::align_of:: < InheritsZeroSizedArray > (), 1usize, - concat!("Alignment of ", stringify!(InheritsZeroSizedArray)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(InheritsZeroSizedArray)), ); } /// And this should not get an `_address` field either. @@ -103,12 +115,14 @@ pub struct DynamicallySizedArray { #[test] fn bindgen_test_layout_DynamicallySizedArray() { assert_eq!( - ::std::mem::size_of:: < DynamicallySizedArray > (), 0usize, concat!("Size of: ", - stringify!(DynamicallySizedArray)) + ::std::mem::size_of::(), + 0usize, + concat!("Size of: ", stringify!(DynamicallySizedArray)), ); assert_eq!( - ::std::mem::align_of:: < DynamicallySizedArray > (), 1usize, - concat!("Alignment of ", stringify!(DynamicallySizedArray)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(DynamicallySizedArray)), ); } /// No `_address` field here either. @@ -120,11 +134,13 @@ pub struct ContainsDynamicallySizedArray { #[test] fn bindgen_test_layout_ContainsDynamicallySizedArray() { assert_eq!( - ::std::mem::size_of:: < ContainsDynamicallySizedArray > (), 0usize, - concat!("Size of: ", stringify!(ContainsDynamicallySizedArray)) + ::std::mem::size_of::(), + 0usize, + concat!("Size of: ", stringify!(ContainsDynamicallySizedArray)), ); assert_eq!( - ::std::mem::align_of:: < ContainsDynamicallySizedArray > (), 1usize, - concat!("Alignment of ", stringify!(ContainsDynamicallySizedArray)) + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(ContainsDynamicallySizedArray)), ); } diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index 8e1b99dc80..1c938bed29 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -33,7 +33,7 @@ lazy_static = "1" lazycell = "1" log = { version = "0.4", optional = true } peeking_take_while = "0.1.2" -prettyplease = { version = "0.2.0", optional = true } +prettyplease = { version = "0.2.7", optional = true, features = ["verbatim"] } proc-macro2 = { version = "1", default-features = false } quote = { version = "1", default-features = false } regex = { version = "1.5", default-features = false, features = ["std", "unicode"] } From 441bc7b2856b4628e9e3bcacce9c867980744689 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 26 Jun 2023 09:53:57 +0200 Subject: [PATCH 537/942] codegen: Generate CStr only if possible. And fix a crash when strings have interior nulls. Fixes #2566 --- .../tests/expectations/tests/issue-2566-cstr.rs | 2 ++ bindgen-tests/tests/expectations/tests/issue-2566.rs | 2 ++ bindgen-tests/tests/headers/issue-2566-cstr.h | 4 ++++ bindgen-tests/tests/headers/issue-2566.h | 1 + bindgen/codegen/mod.rs | 10 +++++----- 5 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 bindgen-tests/tests/expectations/tests/issue-2566-cstr.rs create mode 100644 bindgen-tests/tests/expectations/tests/issue-2566.rs create mode 100644 bindgen-tests/tests/headers/issue-2566-cstr.h create mode 100644 bindgen-tests/tests/headers/issue-2566.h diff --git a/bindgen-tests/tests/expectations/tests/issue-2566-cstr.rs b/bindgen-tests/tests/expectations/tests/issue-2566-cstr.rs new file mode 100644 index 0000000000..4227cf2956 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/issue-2566-cstr.rs @@ -0,0 +1,2 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub const FOO: &[u8; 4] = b"a\0b\0"; diff --git a/bindgen-tests/tests/expectations/tests/issue-2566.rs b/bindgen-tests/tests/expectations/tests/issue-2566.rs new file mode 100644 index 0000000000..4227cf2956 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/issue-2566.rs @@ -0,0 +1,2 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub const FOO: &[u8; 4] = b"a\0b\0"; diff --git a/bindgen-tests/tests/headers/issue-2566-cstr.h b/bindgen-tests/tests/headers/issue-2566-cstr.h new file mode 100644 index 0000000000..674b894024 --- /dev/null +++ b/bindgen-tests/tests/headers/issue-2566-cstr.h @@ -0,0 +1,4 @@ +// bindgen-flags: --generate-cstr + +/// We should _not_ generate a cstr for this because cstr shouldn't have interior nulls. +#define FOO "a\0b" diff --git a/bindgen-tests/tests/headers/issue-2566.h b/bindgen-tests/tests/headers/issue-2566.h new file mode 100644 index 0000000000..6e15ec1979 --- /dev/null +++ b/bindgen-tests/tests/headers/issue-2566.h @@ -0,0 +1 @@ +#define FOO "a\0b" diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 11425e02a4..3d99fa02c8 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -714,18 +714,18 @@ impl CodeGenerator for Var { let len = proc_macro2::Literal::usize_unsuffixed( cstr_bytes.len(), ); - let cstr = CStr::from_bytes_with_nul(&cstr_bytes).unwrap(); // TODO: Here we ignore the type we just made up, probably // we should refactor how the variable type and ty ID work. let array_ty = quote! { [u8; #len] }; let cstr_ty = quote! { ::#prefix::ffi::CStr }; - let bytes = proc_macro2::Literal::byte_string( - cstr.to_bytes_with_nul(), - ); + let bytes = proc_macro2::Literal::byte_string(&cstr_bytes); - if rust_features.const_cstr && options.generate_cstr { + if options.generate_cstr && + rust_features.const_cstr && + CStr::from_bytes_with_nul(&cstr_bytes).is_ok() + { result.push(quote! { #(#attrs)* #[allow(unsafe_code)] From 5e9513028aa350a9e4d234c9a7f3c485383f7519 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Wed, 28 Jun 2023 16:54:49 +0200 Subject: [PATCH 538/942] please clippy (#2570) --- bindgen-tests/tests/parse_callbacks/mod.rs | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/bindgen-tests/tests/parse_callbacks/mod.rs b/bindgen-tests/tests/parse_callbacks/mod.rs index 820432baa8..ee31d56e49 100644 --- a/bindgen-tests/tests/parse_callbacks/mod.rs +++ b/bindgen-tests/tests/parse_callbacks/mod.rs @@ -123,14 +123,6 @@ impl ParseCallbacks for WrapAsVariadicFn { } pub fn lookup(cb: &str) -> Box { - fn try_strip_prefix<'a>(s: &'a str, prefix: &str) -> Option<&'a str> { - if s.starts_with(prefix) { - Some(&s[prefix.len()..]) - } else { - None - } - } - match cb { "enum-variant-rename" => Box::new(EnumVariantRename), "blocklisted-type-implements-trait" => { @@ -139,17 +131,17 @@ pub fn lookup(cb: &str) -> Box { "wrap-as-variadic-fn" => Box::new(WrapAsVariadicFn), call_back => { if let Some(prefix) = - try_strip_prefix(call_back, "remove-function-prefix-") + call_back.strip_prefix("remove-function-prefix-") { let lnopc = RemovePrefixParseCallback::new(prefix); Box::new(lnopc) } else if let Some(prefix) = - try_strip_prefix(call_back, "prefix-link-name-") + call_back.strip_prefix("prefix-link-name-") { let plnpc = PrefixLinkNameParseCallback::new(prefix); Box::new(plnpc) } else if let Some(default) = - try_strip_prefix(call_back, "field-visibility-default-") + call_back.strip_prefix("field-visibility-default-") { Box::new(FieldVisibility { default: default.parse().expect( From 43741d239bcd04019b0c369dbacd7f1d5f6894fe Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Wed, 5 Jul 2023 14:40:21 +0200 Subject: [PATCH 539/942] please clippy (#2573) --- bindgen-tests/tests/tests.rs | 7 ++----- bindgen/codegen/mod.rs | 10 +++++----- bindgen/lib.rs | 10 +++++----- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/bindgen-tests/tests/tests.rs b/bindgen-tests/tests/tests.rs index 895e1cac2c..b92a457be3 100644 --- a/bindgen-tests/tests/tests.rs +++ b/bindgen-tests/tests/tests.rs @@ -254,7 +254,7 @@ fn create_bindgen_builder(header: &Path) -> Result { .last() .and_then(shlex::split) .unwrap(); - flags.extend(extra_flags.into_iter()); + flags.extend(extra_flags); } else if line.contains("bindgen-osx-only") { let prepend_flags = ["--raw-line", "#![cfg(target_os=\"macos\")]"]; flags = prepend_flags @@ -304,10 +304,7 @@ fn create_bindgen_builder(header: &Path) -> Result { "", ]; - let args = prepend - .iter() - .map(ToString::to_string) - .chain(flags.into_iter()); + let args = prepend.iter().map(ToString::to_string).chain(flags); let mut builder = builder_from_flags(args)?.0; if let Some(ref parse_cb) = parse_callbacks { diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 3d99fa02c8..9280b7b91e 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -4912,7 +4912,7 @@ pub(crate) mod utils { let items = vec![use_objc, id_type]; let old_items = mem::replace(result, items); - result.extend(old_items.into_iter()); + result.extend(old_items); } pub(crate) fn prepend_block_header( @@ -4931,7 +4931,7 @@ pub(crate) mod utils { let items = vec![use_block]; let old_items = mem::replace(result, items); - result.extend(old_items.into_iter()); + result.extend(old_items); } pub(crate) fn prepend_union_types( @@ -5043,7 +5043,7 @@ pub(crate) mod utils { ]; let old_items = mem::replace(result, items); - result.extend(old_items.into_iter()); + result.extend(old_items); } pub(crate) fn prepend_incomplete_array_types( @@ -5119,7 +5119,7 @@ pub(crate) mod utils { ]; let old_items = mem::replace(result, items); - result.extend(old_items.into_iter()); + result.extend(old_items); } pub(crate) fn prepend_complex_type( @@ -5136,7 +5136,7 @@ pub(crate) mod utils { let items = vec![complex_type]; let old_items = mem::replace(result, items); - result.extend(old_items.into_iter()); + result.extend(old_items); } pub(crate) fn build_path( diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 49b42574e1..c806d14806 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -912,10 +912,10 @@ impl Bindings { /// Write these bindings as source text to the given `Write`able. pub fn write<'a>(&self, mut writer: Box) -> io::Result<()> { if !self.options.disable_header_comment { - let version = option_env!("CARGO_PKG_VERSION"); + let version = + option_env!("CARGO_PKG_VERSION").unwrap_or("(unknown version)"); let header = format!( - "/* automatically generated by rust-bindgen {} */\n\n", - version.unwrap_or("(unknown version)") + "/* automatically generated by rust-bindgen {version} */\n\n", ); writer.write_all(header.as_bytes())?; } @@ -1244,7 +1244,7 @@ fn commandline_flag_unit_test_function() { let bindings = crate::builder(); let command_line_flags = bindings.command_line_flags(); - let test_cases = vec![ + let test_cases = [ "--rust-target", "--no-derive-default", "--generate", @@ -1263,7 +1263,7 @@ fn commandline_flag_unit_test_function() { .allowlist_function("safe_function"); let command_line_flags = bindings.command_line_flags(); - let test_cases = vec![ + let test_cases = [ "--rust-target", "input_header", "--no-derive-default", From ec6a0c7c41e1600a0c5d416ef586e9a26fce1412 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Wed, 5 Jul 2023 14:41:08 +0200 Subject: [PATCH 540/942] quickchecking crate cleanup (#2572) --- Cargo.lock | 2 +- bindgen-tests/tests/quickchecking/Cargo.toml | 6 ++++-- bindgen-tests/tests/quickchecking/README.md | 5 +++-- bindgen-tests/tests/quickchecking/src/lib.rs | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 538a5bd624..a1e3556b27 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -464,7 +464,7 @@ dependencies = [ [[package]] name = "quickchecking" -version = "0.1.0" +version = "0.0.0" dependencies = [ "clap", "lazy_static", diff --git a/bindgen-tests/tests/quickchecking/Cargo.toml b/bindgen-tests/tests/quickchecking/Cargo.toml index 3b87704f27..294961baf9 100644 --- a/bindgen-tests/tests/quickchecking/Cargo.toml +++ b/bindgen-tests/tests/quickchecking/Cargo.toml @@ -1,8 +1,10 @@ [package] name = "quickchecking" description = "Bindgen property tests with quickcheck. Generate random valid C code and pass it to the csmith/predicate.py script" -version = "0.1.0" -authors = ["Shea Newton "] +version = "0.0.0" +publish = false +rust-version = "1.64" +edition = "2018" [lib] name = "quickchecking" diff --git a/bindgen-tests/tests/quickchecking/README.md b/bindgen-tests/tests/quickchecking/README.md index d3cfe17071..03aa0f2313 100644 --- a/bindgen-tests/tests/quickchecking/README.md +++ b/bindgen-tests/tests/quickchecking/README.md @@ -1,7 +1,7 @@ # Property tests for `bindgen` with `quickchecking` `quickchecking` generates random C headers to test `bindgen` -using the [`quickcheck`][quickcheck] property testing crate. When testing +using the [`quickcheck`] property testing crate. When testing `bindgen` with `quickchecking`, the generated header files are passed to `bindgen`'s `csmith-fuzzing/predicate.py` script. If that script fails, `quickchecking` panics, and you can report an issue containing the test case! @@ -36,4 +36,5 @@ Run `quickchecking` binary to generate and test fuzzed C headers with ``` $ cargo run --bin=quickchecking -- -h ``` -[quickcheck]: https://github.com/BurntSushi/quickcheck + +[`quickcheck`]: https://github.com/BurntSushi/quickcheck diff --git a/bindgen-tests/tests/quickchecking/src/lib.rs b/bindgen-tests/tests/quickchecking/src/lib.rs index 348ecaa687..631c1c679e 100644 --- a/bindgen-tests/tests/quickchecking/src/lib.rs +++ b/bindgen-tests/tests/quickchecking/src/lib.rs @@ -82,7 +82,7 @@ fn run_predicate_script( .output()?; } - Ok(Command::new(&predicate_script_path_string) + Ok(Command::new(predicate_script_path_string) .arg(&header_path_string) .output()?) } From f44a66578dfcc74da290b9707e0cbb290b5ceeb4 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Mon, 10 Jul 2023 22:52:26 +0200 Subject: [PATCH 541/942] make expected-tests diff more pretty (#2577) * make expected-tests diff more pretty * use owo-colors, which is more pleasant --- Cargo.lock | 211 ++++++++++++++++++++++++++++------- bindgen-tests/Cargo.toml | 3 +- bindgen-tests/tests/tests.rs | 58 ++++++++-- 3 files changed, 220 insertions(+), 52 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a1e3556b27..b44aab8eb9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -70,9 +70,10 @@ dependencies = [ "bindgen", "clap", "clap_complete", - "diff", + "owo-colors", "prettyplease", "shlex", + "similar", "syn 2.0.18", "tempfile", ] @@ -173,12 +174,6 @@ dependencies = [ "os_str_bytes", ] -[[package]] -name = "diff" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" - [[package]] name = "either" version = "1.8.1" @@ -219,6 +214,17 @@ dependencies = [ "winapi", ] +[[package]] +name = "errno" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a" +dependencies = [ + "errno-dragonfly", + "libc", + "windows-sys 0.48.0", +] + [[package]] name = "errno-dragonfly" version = "0.1.2" @@ -263,12 +269,9 @@ checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" [[package]] name = "hermit-abi" -version = "0.2.6" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" -dependencies = [ - "libc", -] +checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" [[package]] name = "humantime" @@ -292,19 +295,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e7d6c6f8c91b4b9ed43484ad1a938e393caf35960fce7f82a040497207bd8e9e" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] name = "is-terminal" -version = "0.4.2" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28dfb6c8100ccc63462345b67d1bbc3679177c75ee4bf59bf29c8b1d110b8189" +checksum = "adcf93614601c8129ddf72e2d5633df827ba6551541c6d8c59520a371475be1f" dependencies = [ "hermit-abi", "io-lifetimes", - "rustix", - "windows-sys", + "rustix 0.37.3", + "windows-sys 0.48.0", ] [[package]] @@ -341,6 +344,12 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" +[[package]] +name = "linux-raw-sys" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" + [[package]] name = "log" version = "0.4.17" @@ -402,6 +411,12 @@ version = "6.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee" +[[package]] +name = "owo-colors" +version = "3.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" + [[package]] name = "peeking_take_while" version = "0.1.2" @@ -538,11 +553,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4fdebc4b395b7fbb9ab11e462e20ed9051e7b16e42d24042c776eca0ac81b03" dependencies = [ "bitflags 1.3.2", - "errno", + "errno 0.2.8", "io-lifetimes", "libc", - "linux-raw-sys", - "windows-sys", + "linux-raw-sys 0.1.4", + "windows-sys 0.42.0", +] + +[[package]] +name = "rustix" +version = "0.37.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b24138615de35e32031d041a09032ef3487a616d901ca4db224e7d557efae2" +dependencies = [ + "bitflags 1.3.2", + "errno 0.3.1", + "io-lifetimes", + "libc", + "linux-raw-sys 0.3.8", + "windows-sys 0.45.0", ] [[package]] @@ -551,6 +580,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" +[[package]] +name = "similar" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "420acb44afdae038210c99e69aae24109f32f15500aa708e81d46c9f29d55fcf" + [[package]] name = "strsim" version = "0.10.0" @@ -588,8 +623,8 @@ dependencies = [ "cfg-if", "fastrand", "redox_syscall", - "rustix", - "windows-sys", + "rustix 0.36.7", + "windows-sys 0.42.0", ] [[package]] @@ -682,56 +717,146 @@ version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets 0.42.2", ] +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.1", +] + +[[package]] +name = "windows-targets" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +dependencies = [ + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + +[[package]] +name = "windows-targets" +version = "0.48.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f" +dependencies = [ + "windows_aarch64_gnullvm 0.48.0", + "windows_aarch64_msvc 0.48.0", + "windows_i686_gnu 0.48.0", + "windows_i686_msvc 0.48.0", + "windows_x86_64_gnu 0.48.0", + "windows_x86_64_gnullvm 0.48.0", + "windows_x86_64_msvc 0.48.0", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" + [[package]] name = "windows_aarch64_gnullvm" -version = "0.42.1" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608" +checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" [[package]] name = "windows_aarch64_msvc" -version = "0.42.1" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" + +[[package]] +name = "windows_i686_gnu" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7" +checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" [[package]] name = "windows_i686_gnu" -version = "0.42.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640" +checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" [[package]] name = "windows_i686_msvc" -version = "0.42.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605" +checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" [[package]] name = "windows_x86_64_gnu" -version = "0.42.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45" +checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" [[package]] name = "windows_x86_64_gnullvm" -version = "0.42.1" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463" +checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" [[package]] name = "windows_x86_64_msvc" -version = "0.42.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" +checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" [[package]] name = "yansi-term" diff --git a/bindgen-tests/Cargo.toml b/bindgen-tests/Cargo.toml index 5bf8ac635e..d3907c3619 100644 --- a/bindgen-tests/Cargo.toml +++ b/bindgen-tests/Cargo.toml @@ -8,11 +8,12 @@ publish = false bindgen = { path = "../bindgen", features = ["__cli", "experimental"] } clap = { version = "4", features = ["derive"] } clap_complete = "4" -diff = "0.1" shlex = "1" prettyplease = { version = "0.2.7", features = ["verbatim"] } syn = { version = "2.0" } tempfile = "3" +similar = { version = "2.2.1", features = ["inline"] } +owo-colors = "3.5.0" [features] logging = ["bindgen/logging"] diff --git a/bindgen-tests/tests/tests.rs b/bindgen-tests/tests/tests.rs index b92a457be3..1913b874f0 100644 --- a/bindgen-tests/tests/tests.rs +++ b/bindgen-tests/tests/tests.rs @@ -1,12 +1,14 @@ extern crate bindgen; extern crate clap; -extern crate diff; #[cfg(feature = "logging")] extern crate env_logger; extern crate shlex; use bindgen::{clang_version, Builder}; +use owo_colors::{OwoColorize, Style}; +use similar::{ChangeTag, TextDiff}; use std::env; +use std::fmt; use std::fs; use std::io::{BufRead, BufReader, Error, ErrorKind, Read, Write}; use std::path::{Path, PathBuf}; @@ -52,13 +54,7 @@ fn error_diff_mismatch( println!("+++ generated from: {:?}", header); } - for diff in diff::lines(expected, actual) { - match diff { - diff::Result::Left(l) => println!("-{}", l), - diff::Result::Both(l, _) => println!(" {}", l), - diff::Result::Right(r) => println!("+{}", r), - } - } + show_diff(expected, actual); if should_overwrite_expected() { // Overwrite the expectation with actual output. @@ -84,6 +80,52 @@ fn error_diff_mismatch( Err(Error::new(ErrorKind::Other, "Header and binding differ! Run with BINDGEN_OVERWRITE_EXPECTED=1 in the environment to automatically overwrite the expectation or with BINDGEN_TESTS_DIFFTOOL=meld to do this manually.")) } +struct Line(Option); + +impl fmt::Display for Line { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self.0 { + None => write!(f, " "), + Some(idx) => write!(f, "{:<4}", idx + 1), + } + } +} + +fn show_diff(old: &str, new: &str) { + let diff = TextDiff::from_lines(old, new); + for (count, group) in diff.grouped_ops(3).iter().enumerate() { + if count > 0 { + let message = format!("(chunk {count}/n)"); + println!("{}", message.cyan().dimmed()); + } + for diff_op in group { + for change in diff.iter_inline_changes(diff_op) { + let (sign, color) = match change.tag() { + ChangeTag::Delete => ("-", Style::new().red()), + ChangeTag::Insert => ("+", Style::new().green()), + ChangeTag::Equal => (" ", Style::new()), + }; + print!( + "{}{}| {}", + Line(change.old_index()).style(color).dimmed(), + Line(change.new_index()).style(color).dimmed(), + sign.style(color).bold(), + ); + for (emphasized, text) in change.iter_strings_lossy() { + if emphasized { + print!("{}", text.style(color).underline()); + } else { + print!("{}", text.style(color)); + } + } + if change.missing_newline() { + println!(); + } + } + } + } +} + fn compare_generated_header( header: &Path, builder: BuilderState, From 251dec94c8c7c6413bdaec0c40ff2acecc42e660 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Fri, 14 Jul 2023 16:52:56 -0500 Subject: [PATCH 542/942] Fix `Clone` implementation for `__BindgenUnionField` (#2583) * Fix `Clone` implementation for `__BindgenUnionField` * Fix clang 5 tests * Update changelog --- CHANGELOG.md | 2 ++ bindgen-tests/tests/expectations/tests/16-byte-alignment_1_0.rs | 2 +- .../tests/expectations/tests/anon_struct_in_union_1_0.rs | 2 +- bindgen-tests/tests/expectations/tests/anon_union_1_0.rs | 2 +- .../tests/expectations/tests/bindgen-union-inside-namespace.rs | 2 +- bindgen-tests/tests/expectations/tests/class_1_0.rs | 2 +- .../tests/expectations/tests/class_with_inner_struct_1_0.rs | 2 +- .../tests/expectations/tests/derive-partialeq-union_1_0.rs | 2 +- .../tests/expectations/tests/disable-untagged-union.rs | 2 +- bindgen-tests/tests/expectations/tests/issue-493.rs | 2 +- bindgen-tests/tests/expectations/tests/issue-493_1_0.rs | 2 +- .../tests/expectations/tests/jsval_layout_opaque_1_0.rs | 2 +- bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs | 2 +- bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs | 2 +- bindgen-tests/tests/expectations/tests/libclang-9/class_1_0.rs | 2 +- .../tests/expectations/tests/struct_with_anon_union_1_0.rs | 2 +- .../expectations/tests/struct_with_anon_unnamed_union_1_0.rs | 2 +- .../tests/expectations/tests/struct_with_nesting_1_0.rs | 2 +- bindgen-tests/tests/expectations/tests/transform-op.rs | 2 +- bindgen-tests/tests/expectations/tests/typeref_1_0.rs | 2 +- bindgen-tests/tests/expectations/tests/union-in-ns_1_0.rs | 2 +- bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs | 2 +- bindgen-tests/tests/expectations/tests/union_dtor_1_0.rs | 2 +- bindgen-tests/tests/expectations/tests/union_fields_1_0.rs | 2 +- bindgen-tests/tests/expectations/tests/union_template_1_0.rs | 2 +- .../tests/expectations/tests/union_with_anon_struct_1_0.rs | 2 +- .../expectations/tests/union_with_anon_struct_bitfield_1_0.rs | 2 +- .../tests/expectations/tests/union_with_anon_union_1_0.rs | 2 +- .../expectations/tests/union_with_anon_unnamed_struct_1_0.rs | 2 +- .../expectations/tests/union_with_anon_unnamed_union_1_0.rs | 2 +- .../tests/expectations/tests/union_with_big_member_1_0.rs | 2 +- .../tests/expectations/tests/union_with_nesting_1_0.rs | 2 +- .../tests/expectations/tests/union_with_non_copy_member.rs | 2 +- bindgen-tests/tests/expectations/tests/use-core_1_0.rs | 2 +- .../tests/expectations/tests/wrap_unsafe_ops_anon_union_1_0.rs | 2 +- bindgen/codegen/mod.rs | 2 +- 36 files changed, 37 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e8477daaa8..1317f8fe79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -172,6 +172,8 @@ ## Added ## Changed +- The `Clone` implementation for `_BindgenUnionField` has been changed to pass + the `incorrect_clone_impl_on_copy_type` Clippy lint. ## Removed ## Fixed ## Security diff --git a/bindgen-tests/tests/expectations/tests/16-byte-alignment_1_0.rs b/bindgen-tests/tests/expectations/tests/16-byte-alignment_1_0.rs index 758675dace..a7d7518a34 100644 --- a/bindgen-tests/tests/expectations/tests/16-byte-alignment_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/16-byte-alignment_1_0.rs @@ -24,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} diff --git a/bindgen-tests/tests/expectations/tests/anon_struct_in_union_1_0.rs b/bindgen-tests/tests/expectations/tests/anon_struct_in_union_1_0.rs index 5de1669a21..c3b11f63e8 100644 --- a/bindgen-tests/tests/expectations/tests/anon_struct_in_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/anon_struct_in_union_1_0.rs @@ -24,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} diff --git a/bindgen-tests/tests/expectations/tests/anon_union_1_0.rs b/bindgen-tests/tests/expectations/tests/anon_union_1_0.rs index 90a2e00d0b..c7e24da1c7 100644 --- a/bindgen-tests/tests/expectations/tests/anon_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/anon_union_1_0.rs @@ -24,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} 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 93e2b8e750..2a73a439d1 100644 --- a/bindgen-tests/tests/expectations/tests/bindgen-union-inside-namespace.rs +++ b/bindgen-tests/tests/expectations/tests/bindgen-union-inside-namespace.rs @@ -26,7 +26,7 @@ pub mod root { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} diff --git a/bindgen-tests/tests/expectations/tests/class_1_0.rs b/bindgen-tests/tests/expectations/tests/class_1_0.rs index 5d66e2122b..17cf118242 100644 --- a/bindgen-tests/tests/expectations/tests/class_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/class_1_0.rs @@ -54,7 +54,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} diff --git a/bindgen-tests/tests/expectations/tests/class_with_inner_struct_1_0.rs b/bindgen-tests/tests/expectations/tests/class_with_inner_struct_1_0.rs index 1f0ea9abdc..b36faa6cf1 100644 --- a/bindgen-tests/tests/expectations/tests/class_with_inner_struct_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/class_with_inner_struct_1_0.rs @@ -24,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} diff --git a/bindgen-tests/tests/expectations/tests/derive-partialeq-union_1_0.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-union_1_0.rs index 3429b72b49..308b6a650b 100644 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/derive-partialeq-union_1_0.rs @@ -24,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} diff --git a/bindgen-tests/tests/expectations/tests/disable-untagged-union.rs b/bindgen-tests/tests/expectations/tests/disable-untagged-union.rs index 7322552a76..d507c70a3a 100644 --- a/bindgen-tests/tests/expectations/tests/disable-untagged-union.rs +++ b/bindgen-tests/tests/expectations/tests/disable-untagged-union.rs @@ -24,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} diff --git a/bindgen-tests/tests/expectations/tests/issue-493.rs b/bindgen-tests/tests/expectations/tests/issue-493.rs index 16c5cc7e58..d2e4ea5375 100644 --- a/bindgen-tests/tests/expectations/tests/issue-493.rs +++ b/bindgen-tests/tests/expectations/tests/issue-493.rs @@ -24,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} diff --git a/bindgen-tests/tests/expectations/tests/issue-493_1_0.rs b/bindgen-tests/tests/expectations/tests/issue-493_1_0.rs index 0716802fe2..ff0c93428b 100644 --- a/bindgen-tests/tests/expectations/tests/issue-493_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/issue-493_1_0.rs @@ -24,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} diff --git a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs index 7c691a9720..2e64796b5f 100644 --- a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs @@ -108,7 +108,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} diff --git a/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs b/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs index b9ad64374b..e2ae2b0c17 100644 --- a/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs @@ -108,7 +108,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} diff --git a/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs b/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs index eb8d4b5d30..129300790b 100644 --- a/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs @@ -108,7 +108,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/class_1_0.rs b/bindgen-tests/tests/expectations/tests/libclang-9/class_1_0.rs index 9796b592d4..b6544212cf 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/class_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/class_1_0.rs @@ -54,7 +54,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_union_1_0.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_union_1_0.rs index 9831363dc8..8bab61e3b7 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_anon_union_1_0.rs @@ -24,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs index 291526fd58..ae2ff33377 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs @@ -24,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} diff --git a/bindgen-tests/tests/expectations/tests/struct_with_nesting_1_0.rs b/bindgen-tests/tests/expectations/tests/struct_with_nesting_1_0.rs index f44a319470..6d8a5b97ae 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_nesting_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_nesting_1_0.rs @@ -24,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} diff --git a/bindgen-tests/tests/expectations/tests/transform-op.rs b/bindgen-tests/tests/expectations/tests/transform-op.rs index 57b22ca2e4..85c34985c3 100644 --- a/bindgen-tests/tests/expectations/tests/transform-op.rs +++ b/bindgen-tests/tests/expectations/tests/transform-op.rs @@ -24,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} diff --git a/bindgen-tests/tests/expectations/tests/typeref_1_0.rs b/bindgen-tests/tests/expectations/tests/typeref_1_0.rs index e6c60c7f1a..16bb52c19c 100644 --- a/bindgen-tests/tests/expectations/tests/typeref_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/typeref_1_0.rs @@ -24,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} diff --git a/bindgen-tests/tests/expectations/tests/union-in-ns_1_0.rs b/bindgen-tests/tests/expectations/tests/union-in-ns_1_0.rs index c1982df14a..f80cff753b 100644 --- a/bindgen-tests/tests/expectations/tests/union-in-ns_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union-in-ns_1_0.rs @@ -26,7 +26,7 @@ pub mod root { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} diff --git a/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs b/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs index fa7a0d8f82..e3b65e5011 100644 --- a/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs @@ -108,7 +108,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} diff --git a/bindgen-tests/tests/expectations/tests/union_dtor_1_0.rs b/bindgen-tests/tests/expectations/tests/union_dtor_1_0.rs index 9c60ca47ef..a37109ab08 100644 --- a/bindgen-tests/tests/expectations/tests/union_dtor_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_dtor_1_0.rs @@ -24,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} diff --git a/bindgen-tests/tests/expectations/tests/union_fields_1_0.rs b/bindgen-tests/tests/expectations/tests/union_fields_1_0.rs index f59295c089..8fbade8c25 100644 --- a/bindgen-tests/tests/expectations/tests/union_fields_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_fields_1_0.rs @@ -24,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} diff --git a/bindgen-tests/tests/expectations/tests/union_template_1_0.rs b/bindgen-tests/tests/expectations/tests/union_template_1_0.rs index 3d8d90b8cb..4ebad2a2e2 100644 --- a/bindgen-tests/tests/expectations/tests/union_template_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_template_1_0.rs @@ -24,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_1_0.rs index 269a10aa1c..4bc131bd3d 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_1_0.rs @@ -24,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs index 90bb27437e..dec7fc29ea 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs @@ -108,7 +108,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_union_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_union_1_0.rs index 176c9ec0de..d0158ce178 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_union_1_0.rs @@ -24,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs index 446044d8d2..23b1887b5a 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs @@ -24,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs index 57916a89f6..179a87c92c 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs @@ -24,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} diff --git a/bindgen-tests/tests/expectations/tests/union_with_big_member_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_big_member_1_0.rs index adda6a0d7e..2b50d4e754 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_big_member_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_big_member_1_0.rs @@ -24,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} diff --git a/bindgen-tests/tests/expectations/tests/union_with_nesting_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_nesting_1_0.rs index 94fab65192..4305d58f91 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_nesting_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_nesting_1_0.rs @@ -24,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} diff --git a/bindgen-tests/tests/expectations/tests/union_with_non_copy_member.rs b/bindgen-tests/tests/expectations/tests/union_with_non_copy_member.rs index 580826f4c0..d9eaeacdf1 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_non_copy_member.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_non_copy_member.rs @@ -24,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} diff --git a/bindgen-tests/tests/expectations/tests/use-core_1_0.rs b/bindgen-tests/tests/expectations/tests/use-core_1_0.rs index a11ea28659..6c56e43eea 100644 --- a/bindgen-tests/tests/expectations/tests/use-core_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/use-core_1_0.rs @@ -25,7 +25,7 @@ impl ::core::default::Default for __BindgenUnionField { impl ::core::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::core::marker::Copy for __BindgenUnionField {} diff --git a/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_anon_union_1_0.rs b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_anon_union_1_0.rs index fdee0709d4..dfe2213ed4 100644 --- a/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_anon_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_anon_union_1_0.rs @@ -24,7 +24,7 @@ impl ::std::default::Default for __BindgenUnionField { impl ::std::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } impl ::std::marker::Copy for __BindgenUnionField {} diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 9280b7b91e..31a4b23a2e 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -4990,7 +4990,7 @@ pub(crate) mod utils { impl ::#prefix::clone::Clone for __BindgenUnionField { #[inline] fn clone(&self) -> Self { - Self::new() + *self } } }; From 2df02c2668f41d35616c8385ed61ada896a4bf4c Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Tue, 18 Jul 2023 18:08:35 +0200 Subject: [PATCH 543/942] docs: fix/improve readability of regex args explanation (#2585) * docs: fix/improve readability of regex args explanation * extraneous word --- bindgen/lib.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bindgen/lib.rs b/bindgen/lib.rs index c806d14806..59496823c8 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -263,9 +263,9 @@ impl std::fmt::Display for Formatter { /// /// # Regular expression arguments /// -/// Some [`Builder`] methods such as the `allowlist_*` and `blocklist_*` methods allow regular +/// Some [`Builder`] methods, such as `allowlist_*` and `blocklist_*`, allow regular /// expressions as arguments. These regular expressions will be enclosed in parentheses and -/// anchored with `^` and `$`. So if the argument passed is ``, the regular expression to be +/// anchored with `^` and `$`. So, if the argument passed is ``, the regular expression to be /// stored will be `^()$`. /// /// As a consequence, regular expressions passed to `bindgen` will try to match the whole name of @@ -273,16 +273,16 @@ impl std::fmt::Display for Formatter { /// `prefix`, the `prefix.*` regular expression must be used. /// /// Certain methods, like [`Builder::allowlist_function`], use regular expressions over function -/// names. To match C++ methods, prefix the name of the type where they belong followed by an -/// underscore. So if the type `Foo` has a method `bar`, it can be matched with the `Foo_bar` +/// names. To match C++ methods, prefix the name of the type where they belong, followed by an +/// underscore. So, if the type `Foo` has a method `bar`, it can be matched with the `Foo_bar` /// regular expression. /// /// Additionally, Objective-C interfaces can be matched by prefixing the regular expression with -/// `I`. For example, the `IFoo` regular expression matches the `Foo` interface and the `IFoo_foo` +/// `I`. For example, the `IFoo` regular expression matches the `Foo` interface, and the `IFoo_foo` /// regular expression matches the `foo` method of the `Foo` interface. /// /// Releases of `bindgen` with a version lesser or equal to `0.62.0` used to accept the wildcard -/// pattern `*` as a valid regular expression. This behavior has been deprecated and the `.*` +/// pattern `*` as a valid regular expression. This behavior has been deprecated, and the `.*` /// regular expression must be used instead. #[derive(Debug, Default, Clone)] pub struct Builder { From 97e29b49bebaba4d067d4f5f2270748c7d28a557 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Tue, 18 Jul 2023 15:29:12 -0500 Subject: [PATCH 544/942] Fix escaping for objective-C identifiers (#2587) * Escape keywords that cannot be raw identifiers * Update tests * Update changelog --- CHANGELOG.md | 3 +++ .../tests/expectations/tests/objc_escape.rs | 6 ++++++ bindgen-tests/tests/headers/objc_escape.h | 1 + bindgen/ir/objc.rs | 12 +++++++++--- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1317f8fe79..46872f6fe7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -176,6 +176,9 @@ the `incorrect_clone_impl_on_copy_type` Clippy lint. ## Removed ## Fixed +- Bindgen no longer panics when parsing an objective-C header that includes a + Rust keyword that cannot be a raw identifier, such as: `self`, `crate`, + `super` or `Self`. ## Security # 0.66.1 diff --git a/bindgen-tests/tests/expectations/tests/objc_escape.rs b/bindgen-tests/tests/expectations/tests/objc_escape.rs index f0ddcc1545..abf8df602d 100644 --- a/bindgen-tests/tests/expectations/tests/objc_escape.rs +++ b/bindgen-tests/tests/expectations/tests/objc_escape.rs @@ -26,4 +26,10 @@ pub trait IA: Sized + std::ops::Deref { { msg_send!(* self, f : arg1 r#as : arg2) } + unsafe fn crate_(&self, self_: ::std::os::raw::c_int) + where + ::Target: objc::Message + Sized, + { + msg_send!(* self, crate_ : self_) + } } diff --git a/bindgen-tests/tests/headers/objc_escape.h b/bindgen-tests/tests/headers/objc_escape.h index 184d1da8b1..6b52e745be 100644 --- a/bindgen-tests/tests/headers/objc_escape.h +++ b/bindgen-tests/tests/headers/objc_escape.h @@ -3,4 +3,5 @@ @interface A -(void)f:(int)arg1 as:(int)arg2; +-(void)crate:(int)self; @end diff --git a/bindgen/ir/objc.rs b/bindgen/ir/objc.rs index eaf3b8a545..2ebf38b8ca 100644 --- a/bindgen/ir/objc.rs +++ b/bindgen/ir/objc.rs @@ -257,15 +257,21 @@ impl ObjCMethod { if name.is_empty() { None } else { - // Try to parse the current name as an identifier. This might fail if the - // name is a keyword so we try to prepend "r#" to it and parse again. If - // this also fails, we panic with the first error. + // Try to parse the current name as an identifier. This might fail if the name + // is a keyword, so we try to "r#" to it and parse again, this could also fail + // if the name is `crate`, `self`, `super` or `Self`, so we try to add the `_` + // suffix to it and parse again. If this also fails, we panic with the first + // error. Some( syn::parse_str::(name) .or_else(|err| { syn::parse_str::(&format!("r#{}", name)) .map_err(|_| err) }) + .or_else(|err| { + syn::parse_str::(&format!("{}_", name)) + .map_err(|_| err) + }) .expect("Invalid identifier"), ) } From 1d2b579d1c3180e93089ffb1379ee11fac0cccc0 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Wed, 19 Jul 2023 20:57:20 +0200 Subject: [PATCH 545/942] account for system abi (#2586) * account for system abi Closes #2576 * add test for system abi * Update changelog --------- Co-authored-by: Christian Poveda --- CHANGELOG.md | 1 + bindgen-tests/tests/expectations/tests/abi-override.rs | 3 +++ bindgen-tests/tests/headers/abi-override.h | 3 ++- bindgen/ir/function.rs | 4 ++++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46872f6fe7..7727787abb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -171,6 +171,7 @@ # Unreleased ## Added +- The `system` ABI is now supported as an option for the `--override-abi` flag. ## Changed - The `Clone` implementation for `_BindgenUnionField` has been changed to pass the `incorrect_clone_impl_on_copy_type` Clippy lint. diff --git a/bindgen-tests/tests/expectations/tests/abi-override.rs b/bindgen-tests/tests/expectations/tests/abi-override.rs index 7853efbbe4..13132f9c45 100644 --- a/bindgen-tests/tests/expectations/tests/abi-override.rs +++ b/bindgen-tests/tests/expectations/tests/abi-override.rs @@ -8,5 +8,8 @@ extern "stdcall" { extern "C" { pub fn baz(); } +extern "system" { + pub fn qux(); +} pub type boo = ::std::option::Option; pub type foobar = ::std::option::Option; diff --git a/bindgen-tests/tests/headers/abi-override.h b/bindgen-tests/tests/headers/abi-override.h index bbfe82c2f9..578659733e 100644 --- a/bindgen-tests/tests/headers/abi-override.h +++ b/bindgen-tests/tests/headers/abi-override.h @@ -1,8 +1,9 @@ -// bindgen-flags: --override-abi=foo=fastcall --override-abi=bar=stdcall --override-abi=boo=efiapi --override-abi=foobar=efiapi +// bindgen-flags: --override-abi=foo=fastcall --override-abi=bar=stdcall --override-abi=boo=efiapi --override-abi=foobar=efiapi --override-abi qux=system void foo(); void bar(); void baz(); +void qux(); typedef void (*boo)(); typedef void (*foobar)(boo boo); diff --git a/bindgen/ir/function.rs b/bindgen/ir/function.rs index a0781a3cda..5bfb70eff1 100644 --- a/bindgen/ir/function.rs +++ b/bindgen/ir/function.rs @@ -190,6 +190,8 @@ pub enum Abi { Win64, /// The "C-unwind" ABI. CUnwind, + /// The "system" ABI. + System, } impl FromStr for Abi { @@ -206,6 +208,7 @@ impl FromStr for Abi { "aapcs" => Ok(Self::Aapcs), "win64" => Ok(Self::Win64), "C-unwind" => Ok(Self::CUnwind), + "system" => Ok(Self::System), _ => Err(format!("Invalid or unknown ABI {:?}", s)), } } @@ -223,6 +226,7 @@ impl std::fmt::Display for Abi { Self::Aapcs => "aapcs", Self::Win64 => "win64", Self::CUnwind => "C-unwind", + Abi::System => "system", }; s.fmt(f) From d2c188e0c38f7c980cc1faa25fe60dcbb2cce57a Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Thu, 27 Jul 2023 05:37:35 +0200 Subject: [PATCH 546/942] C unwind is stable (#2591) * c_unwind stabilised in Rust 1.71 * update changelog * adjust test to indicate it not longer requires nightly * rename tests to indicate new reality * improve changelog entry * add unit test --- CHANGELOG.md | 3 +++ ...de-nightly.rs => c-unwind-abi-override.rs} | 2 -- .../headers/c-unwind-abi-override-nightly.h | 5 ----- .../tests/headers/c-unwind-abi-override.h | 5 +++++ bindgen/features.rs | 20 ++++++++++++++----- 5 files changed, 23 insertions(+), 12 deletions(-) rename bindgen-tests/tests/expectations/tests/{c-unwind-abi-override-nightly.rs => c-unwind-abi-override.rs} (78%) delete mode 100644 bindgen-tests/tests/headers/c-unwind-abi-override-nightly.h create mode 100644 bindgen-tests/tests/headers/c-unwind-abi-override.h diff --git a/CHANGELOG.md b/CHANGELOG.md index 7727787abb..8befcb7aed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -175,6 +175,9 @@ ## Changed - The `Clone` implementation for `_BindgenUnionField` has been changed to pass the `incorrect_clone_impl_on_copy_type` Clippy lint. +- The `c_unwind` ABI can be used without a feature gate for any Rust target version + equal to or greater than 1.71. + This comes as a result of the ABI being stabilised (in Rust 1.71). ## Removed ## Fixed - Bindgen no longer panics when parsing an objective-C header that includes a diff --git a/bindgen-tests/tests/expectations/tests/c-unwind-abi-override-nightly.rs b/bindgen-tests/tests/expectations/tests/c-unwind-abi-override.rs similarity index 78% rename from bindgen-tests/tests/expectations/tests/c-unwind-abi-override-nightly.rs rename to bindgen-tests/tests/expectations/tests/c-unwind-abi-override.rs index 8511b30f5f..25fd333cea 100644 --- a/bindgen-tests/tests/expectations/tests/c-unwind-abi-override-nightly.rs +++ b/bindgen-tests/tests/expectations/tests/c-unwind-abi-override.rs @@ -1,6 +1,4 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#![cfg(feature = "nightly")] -#![feature(abi_thiscall)] extern "C-unwind" { pub fn foo(); } diff --git a/bindgen-tests/tests/headers/c-unwind-abi-override-nightly.h b/bindgen-tests/tests/headers/c-unwind-abi-override-nightly.h deleted file mode 100644 index ac79a420c0..0000000000 --- a/bindgen-tests/tests/headers/c-unwind-abi-override-nightly.h +++ /dev/null @@ -1,5 +0,0 @@ -// bindgen-flags: --override-abi="foo|bar=C-unwind" --rust-target=nightly --raw-line '#![cfg(feature = "nightly")]' --raw-line '#![feature(abi_thiscall)]' - -void foo(); -void bar(); -void baz(); diff --git a/bindgen-tests/tests/headers/c-unwind-abi-override.h b/bindgen-tests/tests/headers/c-unwind-abi-override.h new file mode 100644 index 0000000000..591f4b84ff --- /dev/null +++ b/bindgen-tests/tests/headers/c-unwind-abi-override.h @@ -0,0 +1,5 @@ +// bindgen-flags: --override-abi="foo|bar=C-unwind" + +void foo(); +void bar(); +void baz(); diff --git a/bindgen/features.rs b/bindgen/features.rs index bee0e859b9..12e78db44e 100644 --- a/bindgen/features.rs +++ b/bindgen/features.rs @@ -137,10 +137,12 @@ macro_rules! rust_target_base { /// Rust stable 1.68 /// * `abi_efiapi` calling convention ([Tracking issue](https://github.com/rust-lang/rust/issues/65815)) => Stable_1_68 => 1.68; + /// Rust stable 1.71 + /// * `c_unwind` calling convention ([Tracking issue](https://github.com/rust-lang/rust/issues/74990)) + => Stable_1_71 => 1.71; /// Nightly rust /// * `thiscall` calling convention ([Tracking issue](https://github.com/rust-lang/rust/issues/42202)) /// * `vectorcall` calling convention (no tracking issue) - /// * `c_unwind` calling convention ([Tracking issue](https://github.com/rust-lang/rust/issues/74990)) => Nightly => nightly; ); } @@ -150,7 +152,7 @@ rust_target_base!(rust_target_def); rust_target_base!(rust_target_values_def); /// Latest stable release of Rust -pub const LATEST_STABLE_RUST: RustTarget = RustTarget::Stable_1_68; +pub const LATEST_STABLE_RUST: RustTarget = RustTarget::Stable_1_71; /// Create RustFeatures struct definition, new(), and a getter for each field macro_rules! rust_feature_def { @@ -253,10 +255,12 @@ rust_feature_def!( Stable_1_68 { => abi_efiapi; } + Stable_1_71 { + => c_unwind_abi; + } Nightly { => thiscall_abi; => vectorcall_abi; - => c_unwind_abi; } ); @@ -296,6 +300,12 @@ mod test { !f_1_21.thiscall_abi && !f_1_21.vectorcall_abi ); + let features = RustFeatures::from(RustTarget::Stable_1_71); + assert!( + features.c_unwind_abi && + features.abi_efiapi && + !features.thiscall_abi + ); let f_nightly = RustFeatures::from(RustTarget::Nightly); assert!( f_nightly.static_lifetime_elision && @@ -306,8 +316,7 @@ mod test { f_nightly.maybe_uninit && f_nightly.repr_align && f_nightly.thiscall_abi && - f_nightly.vectorcall_abi && - f_nightly.c_unwind_abi + f_nightly.vectorcall_abi ); } @@ -324,6 +333,7 @@ mod test { test_target("1.19", RustTarget::Stable_1_19); test_target("1.21", RustTarget::Stable_1_21); test_target("1.25", RustTarget::Stable_1_25); + test_target("1.71", RustTarget::Stable_1_71); test_target("nightly", RustTarget::Nightly); } } From bf5e79bb2274c4515a04d18c5d82d62f172e46ed Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Fri, 28 Jul 2023 12:20:01 -0500 Subject: [PATCH 547/942] Refactor the `features` module (#2592) * Refactor the `features` module Co-authored-by: Tshepang Mbambo --- bindgen-cli/options.rs | 4 +- bindgen/codegen/mod.rs | 2 +- bindgen/features.rs | 395 ++++++++++++++++++----------------------- bindgen/lib.rs | 7 +- bindgen/options/mod.rs | 2 +- 5 files changed, 184 insertions(+), 226 deletions(-) diff --git a/bindgen-cli/options.rs b/bindgen-cli/options.rs index 8031a138f9..66f068e474 100644 --- a/bindgen-cli/options.rs +++ b/bindgen-cli/options.rs @@ -12,9 +12,9 @@ use std::process::exit; fn rust_target_help() -> String { format!( - "Version of the Rust compiler to target. Valid options are: {:?}. Defaults to {:?}.", + "Version of the Rust compiler to target. Valid options are: {:?}. Defaults to {}.", RUST_TARGET_STRINGS, - String::from(RustTarget::default()) + RustTarget::default() ) } diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 31a4b23a2e..d207d5a98f 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -4348,7 +4348,7 @@ fn unsupported_abi_diagnostic( .add_annotation( format!( "The configured Rust version is {}.", - String::from(ctx.options().rust_target) + ctx.options().rust_target ), Level::Note, ); diff --git a/bindgen/features.rs b/bindgen/features.rs index 12e78db44e..67c6fb4565 100644 --- a/bindgen/features.rs +++ b/bindgen/features.rs @@ -4,270 +4,227 @@ #![deny(clippy::missing_docs_in_private_items)] #![allow(deprecated)] +use std::cmp::Ordering; use std::io; use std::str::FromStr; -/// Define RustTarget struct definition, Default impl, and conversions -/// between RustTarget and String. -macro_rules! rust_target_def { - ( $( $( #[$attr:meta] )* => $release:ident => $value:expr; )* ) => { +/// This macro defines the [`RustTarget`] and [`RustFeatures`] types. +macro_rules! define_rust_targets { + ( + Nightly => {$($nightly_feature:ident $(: #$issue:literal)?),* $(,)?} $(,)? + $( + $(#[$attrs:meta])* + $variant:ident($minor:literal) => {$($feature:ident $(: #$pull:literal)?),* $(,)?}, + )* + $(,)? + ) => { /// Represents the version of the Rust language to target. /// /// To support a beta release, use the corresponding stable release. /// /// This enum will have more variants added as necessary. - #[derive(Debug, Copy, Clone, Eq, PartialEq, PartialOrd, Hash)] #[allow(non_camel_case_types)] + #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub enum RustTarget { + /// Rust Nightly + $(#[doc = concat!( + "- [`", stringify!($nightly_feature), "`]", + "(", $("https://github.com/rust-lang/rust/pull/", stringify!($issue),)* ")", + )])* + Nightly, $( - $( - #[$attr] - )* - $release, + #[doc = concat!("Rust 1.", stringify!($minor))] + $(#[doc = concat!( + "- [`", stringify!($feature), "`]", + "(", $("https://github.com/rust-lang/rust/pull/", stringify!($pull),)* ")", + )])* + $(#[$attrs])* + $variant, )* } - impl Default for RustTarget { - /// Gives the latest stable Rust version - fn default() -> RustTarget { - LATEST_STABLE_RUST + impl RustTarget { + fn minor(self) -> Option { + match self { + $( Self::$variant => Some($minor),)* + Self::Nightly => None + } + } + + const fn stable_releases() -> [(Self, u64); [$($minor,)*].len()] { + [$((Self::$variant, $minor),)*] } } - impl FromStr for RustTarget { - type Err = io::Error; + #[cfg(feature = "__cli")] + /// Strings of allowed `RustTarget` values + pub const RUST_TARGET_STRINGS: &[&str] = &[$(concat!("1.", stringify!($minor)),)*]; - /// Create a `RustTarget` from a string. - /// - /// * The stable/beta versions of Rust are of the form "1.0", - /// "1.19", etc. - /// * The nightly version should be specified with "nightly". - fn from_str(s: &str) -> Result { - match s.as_ref() { - $( - stringify!($value) => Ok(RustTarget::$release), - )* - _ => Err( - io::Error::new( - io::ErrorKind::InvalidInput, - concat!( - "Got an invalid rust target. Accepted values ", - "are of the form ", - "\"1.0\" or \"nightly\"."))), - } - } + #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] + pub(crate) struct RustFeatures { + $($(pub(crate) $feature: bool,)*)* + $(pub(crate) $nightly_feature: bool,)* } - impl From for String { + impl From for RustFeatures { fn from(target: RustTarget) -> Self { - match target { - $( - RustTarget::$release => stringify!($value), - )* - }.into() + if target == RustTarget::Nightly { + return Self { + $($($feature: true,)*)* + $($nightly_feature: true,)* + }; + } + + let mut features = Self { + $($($feature: false,)*)* + $($nightly_feature: false,)* + }; + + $(if target >= RustTarget::$variant { + $(features.$feature = true;)* + })* + + features } } - } + }; } -/// Defines an array slice with all RustTarget values -macro_rules! rust_target_values_def { - ( $( $( #[$attr:meta] )* => $release:ident => $value:expr; )* ) => { - /// Strings of allowed `RustTarget` values - pub static RUST_TARGET_STRINGS: &'static [&str] = &[ - $( - stringify!($value), - )* - ]; +// NOTE: When adding or removing features here, make sure to add the stabilization PR +// number for the feature if it has been stabilized or the tracking issue number if the feature is +// not stable. +define_rust_targets! { + Nightly => { + thiscall_abi: #42202, + vectorcall_abi, + }, + 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_59(59) => { const_cstr: #54745 }, + Stable_1_47(47) => { larger_arrays: #74060 }, + Stable_1_40(40) => { non_exhaustive: #44109 }, + Stable_1_36(36) => { maybe_uninit: #60445 }, + Stable_1_33(33) => { repr_packed_n: #57049 }, + #[deprecated] + Stable_1_30(30) => { + core_ffi_c_void: #53910, + min_const_fn: #54835, + }, + #[deprecated] + Stable_1_28(28) => { repr_transparent: #51562 }, + #[deprecated] + Stable_1_27(27) => { must_use_function: #48925 }, + #[deprecated] + Stable_1_26(26) => { i128_and_u128: #49101 }, + #[deprecated] + Stable_1_25(25) => { repr_align: #47006 }, + #[deprecated] + Stable_1_21(21) => { builtin_clone_impls: #43690 }, + #[deprecated] + Stable_1_20(20) => { associated_const: #42809 }, + #[deprecated] + Stable_1_19(19) => { untagged_union: #42068 }, + #[deprecated] + Stable_1_17(17) => { static_lifetime_elision: #39265 }, + #[deprecated] + Stable_1_0(0) => {}, +} + +/// Latest stable release of Rust +pub const LATEST_STABLE_RUST: RustTarget = { + // FIXME: replace all this code by + // ``` + // RustTarget::stable_releases() + // .into_iter() + // .max_by_key(|(_, m)| m) + // .map(|(t, _)| t) + // .unwrap_or(RustTarget::Nightly) + // ``` + // once those operations can be used in constants. + let targets = RustTarget::stable_releases(); + + let mut i = 0; + let mut latest_target = None; + let mut latest_minor = 0; + + while i < targets.len() { + let (target, minor) = targets[i]; + + if latest_minor < minor { + latest_minor = minor; + latest_target = Some(target); + } + + i += 1; + } + + match latest_target { + Some(target) => target, + None => unreachable!(), + } +}; + +impl Default for RustTarget { + fn default() -> Self { + LATEST_STABLE_RUST } } -/// Defines macro which takes a macro -macro_rules! rust_target_base { - ( $x_macro:ident ) => { - $x_macro!( - /// Rust stable 1.0 - #[deprecated = "This rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues"] => Stable_1_0 => 1.0; - /// Rust stable 1.17 - /// * Static lifetime elision ([RFC 1623](https://github.com/rust-lang/rfcs/blob/master/text/1623-static.md)) - #[deprecated = "This rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues"] => Stable_1_17 => 1.17; - /// Rust stable 1.19 - /// * Untagged unions ([RFC 1444](https://github.com/rust-lang/rfcs/blob/master/text/1444-union.md)) - #[deprecated = "This rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues"] => Stable_1_19 => 1.19; - /// Rust stable 1.20 - /// * Associated constants ([PR](https://github.com/rust-lang/rust/pull/42809)) - #[deprecated = "This rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues"] => Stable_1_20 => 1.20; - /// Rust stable 1.21 - /// * Builtin impls for `Clone` ([PR](https://github.com/rust-lang/rust/pull/43690)) - #[deprecated = "This rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues"] => Stable_1_21 => 1.21; - /// Rust stable 1.25 - /// * `repr(align)` ([PR](https://github.com/rust-lang/rust/pull/47006)) - #[deprecated = "This rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues"] => Stable_1_25 => 1.25; - /// Rust stable 1.26 - /// * [i128 / u128 support](https://doc.rust-lang.org/std/primitive.i128.html) - #[deprecated = "This rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues"] => Stable_1_26 => 1.26; - /// Rust stable 1.27 - /// * `must_use` attribute on functions ([PR](https://github.com/rust-lang/rust/pull/48925)) - #[deprecated = "This rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues"] => Stable_1_27 => 1.27; - /// Rust stable 1.28 - /// * `repr(transparent)` ([PR](https://github.com/rust-lang/rust/pull/51562)) - #[deprecated = "This rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues"] => Stable_1_28 => 1.28; - /// Rust stable 1.30 - /// * `const fn` support for limited cases ([PR](https://github.com/rust-lang/rust/pull/54835/) - /// * [c_void available in core](https://doc.rust-lang.org/core/ffi/enum.c_void.html) - #[deprecated = "This rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues"] => Stable_1_30 => 1.30; - /// Rust stable 1.33 - /// * repr(packed(N)) ([PR](https://github.com/rust-lang/rust/pull/57049)) - => Stable_1_33 => 1.33; - /// Rust stable 1.36 - /// * `MaybeUninit` instead of `mem::uninitialized()` ([PR](https://github.com/rust-lang/rust/pull/60445)) - => Stable_1_36 => 1.36; - /// Rust stable 1.40 - /// * `non_exhaustive` enums/structs ([Tracking issue](https://github.com/rust-lang/rust/issues/44109)) - => Stable_1_40 => 1.40; - /// Rust stable 1.47 - /// * `larger_arrays` ([Tracking issue](https://github.com/rust-lang/rust/pull/74060)) - => Stable_1_47 => 1.47; - /// Rust stable 1.59 - /// * `CStr::from_bytes_with_nul_unchecked` in `const` contexts ([PR](https://github.com/rust-lang/rust/pull/54745)) - => Stable_1_59 => 1.59; - /// Rust stable 1.64 - /// * `core_ffi_c` ([Tracking issue](https://github.com/rust-lang/rust/issues/94501)) - => Stable_1_64 => 1.64; - /// Rust stable 1.68 - /// * `abi_efiapi` calling convention ([Tracking issue](https://github.com/rust-lang/rust/issues/65815)) - => Stable_1_68 => 1.68; - /// Rust stable 1.71 - /// * `c_unwind` calling convention ([Tracking issue](https://github.com/rust-lang/rust/issues/74990)) - => Stable_1_71 => 1.71; - /// Nightly rust - /// * `thiscall` calling convention ([Tracking issue](https://github.com/rust-lang/rust/issues/42202)) - /// * `vectorcall` calling convention (no tracking issue) - => Nightly => nightly; - ); +impl PartialOrd for RustTarget { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) } } -rust_target_base!(rust_target_def); -rust_target_base!(rust_target_values_def); +impl Ord for RustTarget { + fn cmp(&self, other: &Self) -> Ordering { + match (self.minor(), other.minor()) { + (Some(a), Some(b)) => a.cmp(&b), + (Some(_), None) => Ordering::Less, + (None, Some(_)) => Ordering::Greater, + (None, None) => Ordering::Equal, + } + } +} -/// Latest stable release of Rust -pub const LATEST_STABLE_RUST: RustTarget = RustTarget::Stable_1_71; +impl FromStr for RustTarget { + type Err = io::Error; -/// Create RustFeatures struct definition, new(), and a getter for each field -macro_rules! rust_feature_def { - ( - $( $rust_target:ident { - $( $( #[$attr:meta] )* => $feature:ident; )* - } )* - ) => { - /// Features supported by a rust target - #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] - #[allow(missing_docs)] // Documentation should go into the relevant variants. - pub(crate) struct RustFeatures { - $( $( - $( - #[$attr] - )* - pub $feature: bool, - )* )* + fn from_str(s: &str) -> Result { + if s == "nightly" { + return Ok(Self::Nightly); } - impl RustFeatures { - /// Gives a RustFeatures struct with all features disabled - fn new() -> Self { - RustFeatures { - $( $( - $feature: false, - )* )* + if let Some(("1", str_minor)) = s.split_once('.') { + if let Ok(minor) = str_minor.parse::() { + for (target, target_minor) in Self::stable_releases() { + if minor == target_minor { + return Ok(target); + } } } } - impl From for RustFeatures { - fn from(rust_target: RustTarget) -> Self { - let mut features = RustFeatures::new(); - - $( - if rust_target >= RustTarget::$rust_target { - $( - features.$feature = true; - )* - } - )* - - features - } - } + Err(io::Error::new( + io::ErrorKind::InvalidInput, + "Got an invalid Rust target. Accepted values are of the form \"1.71\" or \"nightly\"." + )) } } -// NOTE(emilio): When adding or removing features here, make sure to update the -// documentation for the relevant variant in the rust_target_base macro -// definition. -rust_feature_def!( - Stable_1_17 { - => static_lifetime_elision; - } - Stable_1_19 { - => untagged_union; - } - Stable_1_20 { - => associated_const; - } - Stable_1_21 { - => builtin_clone_impls; - } - Stable_1_25 { - => repr_align; - } - Stable_1_26 { - => i128_and_u128; - } - Stable_1_27 { - => must_use_function; - } - Stable_1_28 { - => repr_transparent; - } - Stable_1_30 { - => min_const_fn; - => core_ffi_c_void; - } - Stable_1_33 { - => repr_packed_n; - } - Stable_1_36 { - => maybe_uninit; - } - Stable_1_40 { - => non_exhaustive; - } - Stable_1_47 { - => larger_arrays; - } - Stable_1_59 { - => const_cstr; - } - Stable_1_64 { - => core_ffi_c; - } - Stable_1_68 { - => abi_efiapi; - } - Stable_1_71 { - => c_unwind_abi; - } - Nightly { - => thiscall_abi; - => vectorcall_abi; +impl std::fmt::Display for RustTarget { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self.minor() { + Some(minor) => write!(f, "1.{}", minor), + None => "nightly".fmt(f), + } } -); +} impl Default for RustFeatures { fn default() -> Self { - let default_rust_target: RustTarget = Default::default(); - Self::from(default_rust_target) + RustTarget::default().into() } } @@ -321,7 +278,7 @@ mod test { } fn test_target(target_str: &str, target: RustTarget) { - let target_string: String = target.into(); + let target_string = target.to_string(); assert_eq!(target_str, target_string); assert_eq!(target, RustTarget::from_str(target_str).unwrap()); } diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 59496823c8..a6c929f4c7 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -52,7 +52,9 @@ mod regex_set; pub use codegen::{ AliasVariation, EnumVariation, MacroTypeVariation, NonCopyUnionStyle, }; -pub use features::{RustTarget, LATEST_STABLE_RUST, RUST_TARGET_STRINGS}; +#[cfg(feature = "__cli")] +pub use features::RUST_TARGET_STRINGS; +pub use features::{RustTarget, LATEST_STABLE_RUST}; pub use ir::annotations::FieldVisibilityKind; pub use ir::function::Abi; pub use regex_set::RegexSet; @@ -568,8 +570,7 @@ impl BindgenOptions { } fn deprecated_target_diagnostic(target: RustTarget, _options: &BindgenOptions) { - let target = String::from(target); - warn!("The {} Rust target is deprecated. If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues", target,); + warn!("The {} Rust target is deprecated. If you have a need to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues", target); #[cfg(feature = "experimental")] if _options.emit_diagnostics { diff --git a/bindgen/options/mod.rs b/bindgen/options/mod.rs index cda04ee8c7..91620ce0d6 100644 --- a/bindgen/options/mod.rs +++ b/bindgen/options/mod.rs @@ -1543,7 +1543,7 @@ options! { }, as_args: |rust_target, args| { args.push("--rust-target".to_owned()); - args.push((*rust_target).into()); + args.push(rust_target.to_string()); }, }, /// Features to be enabled. They are derived from `rust_target`. From 6a9a0897fdd113f0f2560e10055fe0cf77a7db9a Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Tue, 8 Aug 2023 12:41:19 -0500 Subject: [PATCH 548/942] Turn collections of `String` into collections of `Box` (#2594) * Change `String` by `Box` inside `RegexSet` * Turn `raw_lines` into a `Box` * Turn keys and values of `module_lines` into `Box`s * Turn `input_headers` into a `Vec>` * Turn `clang_args` into a `Vec>` * Turn keys and values of `input_header_contents` into `Box`s * Add suggestions * Run rustfmt --- bindgen/clang.rs | 10 ++--- bindgen/codegen/mod.rs | 5 ++- bindgen/deps.rs | 20 ++++----- bindgen/ir/context.rs | 6 +-- bindgen/ir/item.rs | 2 +- bindgen/lib.rs | 83 +++++++++++++++++++++----------------- bindgen/options/as_args.rs | 2 +- bindgen/options/mod.rs | 36 ++++++++--------- bindgen/regex_set.rs | 14 +++---- 9 files changed, 94 insertions(+), 84 deletions(-) diff --git a/bindgen/clang.rs b/bindgen/clang.rs index 51064a558f..db239ebc77 100644 --- a/bindgen/clang.rs +++ b/bindgen/clang.rs @@ -1813,14 +1813,14 @@ impl TranslationUnit { pub(crate) fn parse( ix: &Index, file: &str, - cmd_args: &[String], + cmd_args: &[Box], unsaved: &[UnsavedFile], opts: CXTranslationUnit_Flags, ) -> Option { let fname = CString::new(file).unwrap(); let _c_args: Vec = cmd_args .iter() - .map(|s| CString::new(s.clone()).unwrap()) + .map(|s| CString::new(s.clone().into_boxed_bytes()).unwrap()) .collect(); let c_args: Vec<*const c_char> = _c_args.iter().map(|s| s.as_ptr()).collect(); @@ -1923,9 +1923,9 @@ pub(crate) struct UnsavedFile { impl UnsavedFile { /// Construct a new unsaved file with the given `name` and `contents`. - pub(crate) fn new(name: String, contents: String) -> UnsavedFile { - let name = CString::new(name).unwrap(); - let contents = CString::new(contents).unwrap(); + pub(crate) fn new(name: &str, contents: &str) -> UnsavedFile { + let name = CString::new(name.as_bytes()).unwrap(); + let contents = CString::new(contents.as_bytes()).unwrap(); let x = CXUnsavedFile { Filename: name.as_ptr(), Contents: contents.as_ptr(), diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index d207d5a98f..bc8e3ec711 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -601,7 +601,10 @@ impl CodeGenerator for Module { let inner_items = result.inner(|result| { result.push(root_import(ctx, item)); - let path = item.namespace_aware_canonical_path(ctx).join("::"); + let path = item + .namespace_aware_canonical_path(ctx) + .join("::") + .into_boxed_str(); if let Some(raw_lines) = ctx.options().module_lines.get(&path) { for raw_line in raw_lines { found_any = true; diff --git a/bindgen/deps.rs b/bindgen/deps.rs index e348fa1303..be31f92896 100644 --- a/bindgen/deps.rs +++ b/bindgen/deps.rs @@ -8,11 +8,11 @@ pub(crate) struct DepfileSpec { } impl DepfileSpec { - pub fn write(&self, deps: &BTreeSet) -> std::io::Result<()> { + pub fn write(&self, deps: &BTreeSet>) -> std::io::Result<()> { std::fs::write(&self.depfile_path, self.to_string(deps)) } - fn to_string(&self, deps: &BTreeSet) -> String { + fn to_string(&self, deps: &BTreeSet>) -> String { // Transforms a string by escaping spaces and backslashes. let escape = |s: &str| s.replace('\\', "\\\\").replace(' ', "\\ "); @@ -35,14 +35,14 @@ mod tests { depfile_path: PathBuf::new(), }; - let deps: BTreeSet = vec![ - r"/absolute/path".to_owned(), - r"C:\win\absolute\path".to_owned(), - r"../relative/path".to_owned(), - r"..\win\relative\path".to_owned(), - r"../path/with spaces/in/it".to_owned(), - r"..\win\path\with spaces\in\it".to_owned(), - r"path\with/mixed\separators".to_owned(), + let deps: BTreeSet<_> = vec![ + r"/absolute/path".into(), + r"C:\win\absolute\path".into(), + r"../relative/path".into(), + r"..\win\relative\path".into(), + r"../path/with spaces/in/it".into(), + r"..\win\path\with spaces\in\it".into(), + r"path\with/mixed\separators".into(), ] .into_iter() .collect(); diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index bc9e59c3f0..1b26c2c3a2 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -365,7 +365,7 @@ pub(crate) struct BindgenContext { includes: StdHashMap, /// A set of all the included filenames. - deps: BTreeSet, + deps: BTreeSet>, /// The active replacements collected from replaces="xxx" annotations. replacements: HashMap, ItemId>, @@ -664,12 +664,12 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Add an included file. - pub(crate) fn add_dep(&mut self, dep: String) { + pub(crate) fn add_dep(&mut self, dep: Box) { self.deps.insert(dep); } /// Get any included files. - pub(crate) fn deps(&self) -> &BTreeSet { + pub(crate) fn deps(&self) -> &BTreeSet> { &self.deps } diff --git a/bindgen/ir/item.rs b/bindgen/ir/item.rs index 1b9d7694b2..4abca5c49b 100644 --- a/bindgen/ir/item.rs +++ b/bindgen/ir/item.rs @@ -1465,7 +1465,7 @@ impl Item { cb.include_file(&included_file); } - ctx.add_dep(included_file); + ctx.add_dep(included_file.into_boxed_str()); } } } diff --git a/bindgen/lib.rs b/bindgen/lib.rs index a6c929f4c7..4e5d445f3a 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -94,15 +94,15 @@ fn file_is_cpp(name_file: &str) -> bool { name_file.ends_with(".h++") } -fn args_are_cpp(clang_args: &[String]) -> bool { +fn args_are_cpp(clang_args: &[Box]) -> bool { for w in clang_args.windows(2) { - if w[0] == "-xc++" || w[1] == "-xc++" { + if w[0].as_ref() == "-xc++" || w[1].as_ref() == "-xc++" { return true; } - if w[0] == "-x" && w[1] == "c++" { + if w[0].as_ref() == "-x" && w[1].as_ref() == "c++" { return true; } - if w[0] == "-include" && file_is_cpp(&w[1]) { + if w[0].as_ref() == "-include" && file_is_cpp(w[1].as_ref()) { return true; } } @@ -319,22 +319,26 @@ impl Builder { /// Generate the Rust bindings using the options built up thus far. pub fn generate(mut self) -> Result { // Add any extra arguments from the environment to the clang command line. - self.options - .clang_args - .extend(get_extra_clang_args(&self.options.parse_callbacks)); + self.options.clang_args.extend( + get_extra_clang_args(&self.options.parse_callbacks) + .into_iter() + .map(String::into_boxed_str), + ); // Transform input headers to arguments on the clang command line. self.options.clang_args.extend( self.options.input_headers [..self.options.input_headers.len().saturating_sub(1)] .iter() - .flat_map(|header| ["-include".into(), header.to_string()]), + .flat_map(|header| ["-include".into(), header.clone()]), ); let input_unsaved_files = std::mem::take(&mut self.options.input_header_contents) .into_iter() - .map(|(name, contents)| clang::UnsavedFile::new(name, contents)) + .map(|(name, contents)| { + clang::UnsavedFile::new(name.as_ref(), contents.as_ref()) + }) .collect::>(); Bindings::generate(self.options, input_unsaved_files) @@ -401,7 +405,7 @@ impl Builder { .stdout(Stdio::piped()); for a in &self.options.clang_args { - cmd.arg(a); + cmd.arg(a.as_ref()); } for a in get_extra_clang_args(&self.options.parse_callbacks) { @@ -668,16 +672,16 @@ pub(crate) const HOST_TARGET: &str = // Some architecture triplets are different between rust and libclang, see #1211 // and duplicates. -fn rust_to_clang_target(rust_target: &str) -> String { +fn rust_to_clang_target(rust_target: &str) -> Box { if rust_target.starts_with("aarch64-apple-") { let mut clang_target = "arm64-apple-".to_owned(); clang_target .push_str(rust_target.strip_prefix("aarch64-apple-").unwrap()); - return clang_target; + return clang_target.into(); } else if rust_target.starts_with("riscv64gc-") { let mut clang_target = "riscv64-".to_owned(); clang_target.push_str(rust_target.strip_prefix("riscv64gc-").unwrap()); - return clang_target; + return clang_target.into(); } else if rust_target.ends_with("-espidf") { let mut clang_target = rust_target.strip_suffix("-espidf").unwrap().to_owned(); @@ -686,32 +690,32 @@ fn rust_to_clang_target(rust_target: &str) -> String { clang_target = "riscv32-".to_owned() + clang_target.strip_prefix("riscv32imc-").unwrap(); } - return clang_target; + return clang_target.into(); } else if rust_target.starts_with("riscv32imc-") { let mut clang_target = "riscv32-".to_owned(); clang_target.push_str(rust_target.strip_prefix("riscv32imc-").unwrap()); - return clang_target; + return clang_target.into(); } else if rust_target.starts_with("riscv32imac-") { let mut clang_target = "riscv32-".to_owned(); clang_target .push_str(rust_target.strip_prefix("riscv32imac-").unwrap()); - return clang_target; + return clang_target.into(); } - rust_target.to_owned() + rust_target.into() } /// Returns the effective target, and whether it was explicitly specified on the /// clang flags. -fn find_effective_target(clang_args: &[String]) -> (String, bool) { +fn find_effective_target(clang_args: &[Box]) -> (Box, bool) { let mut args = clang_args.iter(); while let Some(opt) = args.next() { if opt.starts_with("--target=") { let mut split = opt.split('='); split.next(); - return (split.next().unwrap().to_owned(), true); + return (split.next().unwrap().into(), true); } - if opt == "-target" { + if opt.as_ref() == "-target" { if let Some(target) = args.next() { return (target.clone(), true); } @@ -756,9 +760,10 @@ impl Bindings { // opening libclang.so, it has to be the same architecture and thus the // check is fine. if !explicit_target && !is_host_build { - options - .clang_args - .insert(0, format!("--target={}", effective_target)); + options.clang_args.insert( + 0, + format!("--target={}", effective_target).into_boxed_str(), + ); }; fn detect_include_paths(options: &mut BindgenOptions) { @@ -779,7 +784,7 @@ impl Bindings { return false; } - let arg = &**arg; + let arg = arg.as_ref(); // https://clang.llvm.org/docs/ClangCommandLineReference.html // -isystem and -isystem-after are harmless. @@ -796,7 +801,7 @@ impl Bindings { true }) - .cloned() + .map(|arg| arg.clone().into()) .collect::>() }; @@ -828,8 +833,8 @@ impl Bindings { if let Some(search_paths) = search_paths { for path in search_paths.into_iter() { if let Ok(path) = path.into_os_string().into_string() { - options.clang_args.push("-isystem".to_owned()); - options.clang_args.push(path); + options.clang_args.push("-isystem".into()); + options.clang_args.push(path.into_boxed_str()); } } } @@ -849,7 +854,7 @@ impl Bindings { } if let Some(h) = options.input_headers.last() { - let path = Path::new(h); + let path = Path::new(h.as_ref()); if let Ok(md) = std::fs::metadata(path) { if md.is_dir() { return Err(BindgenError::FolderAsHeader(path.into())); @@ -859,8 +864,7 @@ impl Bindings { path.into(), )); } - let h = h.clone(); - options.clang_args.push(h); + options.clang_args.push(h.clone()); } else { return Err(BindgenError::NotExist(path.into())); } @@ -868,9 +872,9 @@ impl Bindings { for (idx, f) in input_unsaved_files.iter().enumerate() { if idx != 0 || !options.input_headers.is_empty() { - options.clang_args.push("-include".to_owned()); + options.clang_args.push("-include".into()); } - options.clang_args.push(f.name.to_str().unwrap().to_owned()) + options.clang_args.push(f.name.to_str().unwrap().into()) } debug!("Fixed-up options: {:?}", options); @@ -1285,21 +1289,24 @@ fn commandline_flag_unit_test_function() { #[test] fn test_rust_to_clang_target() { - assert_eq!(rust_to_clang_target("aarch64-apple-ios"), "arm64-apple-ios"); + assert_eq!( + rust_to_clang_target("aarch64-apple-ios").as_ref(), + "arm64-apple-ios" + ); } #[test] fn test_rust_to_clang_target_riscv() { assert_eq!( - rust_to_clang_target("riscv64gc-unknown-linux-gnu"), + rust_to_clang_target("riscv64gc-unknown-linux-gnu").as_ref(), "riscv64-unknown-linux-gnu" ); assert_eq!( - rust_to_clang_target("riscv32imc-unknown-none-elf"), + rust_to_clang_target("riscv32imc-unknown-none-elf").as_ref(), "riscv32-unknown-none-elf" ); assert_eq!( - rust_to_clang_target("riscv32imac-unknown-none-elf"), + rust_to_clang_target("riscv32imac-unknown-none-elf").as_ref(), "riscv32-unknown-none-elf" ); } @@ -1307,11 +1314,11 @@ fn test_rust_to_clang_target_riscv() { #[test] fn test_rust_to_clang_target_espidf() { assert_eq!( - rust_to_clang_target("riscv32imc-esp-espidf"), + rust_to_clang_target("riscv32imc-esp-espidf").as_ref(), "riscv32-esp-elf" ); assert_eq!( - rust_to_clang_target("xtensa-esp32-espidf"), + rust_to_clang_target("xtensa-esp32-espidf").as_ref(), "xtensa-esp32-elf" ); } diff --git a/bindgen/options/as_args.rs b/bindgen/options/as_args.rs index 13439c45f8..6918ad9fec 100644 --- a/bindgen/options/as_args.rs +++ b/bindgen/options/as_args.rs @@ -24,7 +24,7 @@ impl AsArgs for bool { impl AsArgs for RegexSet { fn as_args(&self, args: &mut Vec, flag: &str) { for item in self.get_items() { - args.extend_from_slice(&[flag.to_owned(), item.clone()]); + args.extend_from_slice(&[flag.to_owned(), item.clone().into()]); } } } diff --git a/bindgen/options/mod.rs b/bindgen/options/mod.rs index 91620ce0d6..925dcbaea1 100644 --- a/bindgen/options/mod.rs +++ b/bindgen/options/mod.rs @@ -114,7 +114,7 @@ macro_rules! options { let headers = match self.options.input_headers.split_last() { Some((header, headers)) => { // The last input header is passed as an argument in the first position. - args.push(header.clone()); + args.push(header.clone().into()); headers }, None => &[] @@ -135,13 +135,13 @@ macro_rules! options { args.push("--".to_owned()); if !self.options.clang_args.is_empty() { - args.extend_from_slice(&self.options.clang_args); + args.extend(self.options.clang_args.iter().map(|s| s.clone().into())); } // We need to pass all but the last header via the `-include` clang argument. for header in headers { args.push("-include".to_owned()); - args.push(header.clone()); + args.push(header.clone().into()); } args @@ -1072,24 +1072,24 @@ options! { as_args: |value, args| (!value).as_args(args, "--no-convert-floats"), }, /// The set of raw lines to be prepended to the top-level module of the generated Rust code. - raw_lines: Vec { + raw_lines: Vec> { methods: { /// Add a line of Rust code at the beginning of the generated bindings. The string is /// passed through without any modification. pub fn raw_line>(mut self, arg: T) -> Self { - self.options.raw_lines.push(arg.into()); + self.options.raw_lines.push(arg.into().into_boxed_str()); self } }, as_args: |raw_lines, args| { for line in raw_lines { args.push("--raw-line".to_owned()); - args.push(line.clone()); + args.push(line.clone().into()); } }, }, /// The set of raw lines to prepend to different modules. - module_lines: HashMap> { + module_lines: HashMap, Vec>> { methods: { /// Add a given line to the beginning of a given module. /// @@ -1102,9 +1102,9 @@ options! { { self.options .module_lines - .entry(module.into()) + .entry(module.into().into_boxed_str()) .or_insert_with(Vec::new) - .push(line.into()); + .push(line.into().into_boxed_str()); self } }, @@ -1112,14 +1112,14 @@ options! { for (module, lines) in module_lines { for line in lines.iter() { args.push("--module-raw-line".to_owned()); - args.push(module.clone()); - args.push(line.clone()); + args.push(module.clone().into()); + args.push(line.clone().into()); } } }, }, /// The input header files. - input_headers: Vec { + input_headers: Vec> { methods: { /// Add an input C/C++ header to generate bindings for. /// @@ -1143,7 +1143,7 @@ options! { /// .unwrap(); /// ``` pub fn header>(mut self, header: T) -> Builder { - self.options.input_headers.push(header.into()); + self.options.input_headers.push(header.into().into_boxed_str()); self } }, @@ -1151,11 +1151,11 @@ options! { as_args: ignore, }, /// The set of arguments to be passed straight through to Clang. - clang_args: Vec { + clang_args: Vec> { methods: { /// Add an argument to be passed straight through to Clang. pub fn clang_arg>(self, arg: T) -> Builder { - self.clang_args([arg.into()]) + self.clang_args([arg.into().into_boxed_str()]) } /// Add several arguments to be passed straight through to Clang. @@ -1164,7 +1164,7 @@ options! { I::Item: AsRef, { for arg in args { - self.options.clang_args.push(arg.as_ref().to_owned()); + self.options.clang_args.push(arg.as_ref().to_owned().into_boxed_str()); } self } @@ -1173,7 +1173,7 @@ options! { as_args: ignore, }, /// Tuples of unsaved file contents of the form (name, contents). - input_header_contents: Vec<(String, String)> { + input_header_contents: Vec<(Box, Box)> { methods: { /// Add `contents` as an input C/C++ header named `name`. /// @@ -1187,7 +1187,7 @@ options! { .join(name) .to_str() .expect("Cannot convert current directory name to string") - .to_owned(); + .into(); self.options .input_header_contents .push((absolute_path, contents.into())); diff --git a/bindgen/regex_set.rs b/bindgen/regex_set.rs index 1d5cad2fc8..b78424aae1 100644 --- a/bindgen/regex_set.rs +++ b/bindgen/regex_set.rs @@ -7,7 +7,7 @@ use std::cell::Cell; /// A dynamic set of regular expressions. #[derive(Clone, Debug, Default)] pub struct RegexSet { - items: Vec, + items: Vec>, /// Whether any of the items in the set was ever matched. The length of this /// vector is exactly the length of `items`. matched: Vec>, @@ -32,25 +32,25 @@ impl RegexSet { where S: AsRef, { - self.items.push(string.as_ref().to_owned()); + self.items.push(string.as_ref().to_owned().into_boxed_str()); self.matched.push(Cell::new(false)); self.set = None; } /// Returns slice of String from its field 'items' - pub fn get_items(&self) -> &[String] { - &self.items[..] + pub fn get_items(&self) -> &[Box] { + &self.items } /// Returns an iterator over regexes in the set which didn't match any /// strings yet. - pub fn unmatched_items(&self) -> impl Iterator { + pub fn unmatched_items(&self) -> impl Iterator { self.items.iter().enumerate().filter_map(move |(i, item)| { if !self.record_matches || self.matched[i].get() { return None; } - Some(item) + Some(item.as_ref()) }) } @@ -197,7 +197,7 @@ fn invalid_regex_warning( Level::Note, ); - if set.items.iter().any(|item| item == "*") { + if set.items.iter().any(|item| item.as_ref() == "*") { diagnostic.add_annotation("Wildcard patterns \"*\" are no longer considered valid. Use \".*\" instead.", Level::Help); } diagnostic.display(); From 871699415ec975e3e5a61ca147052daf290e160f Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Wed, 9 Aug 2023 16:42:17 -0500 Subject: [PATCH 549/942] Make clippy happy (#2602) --- bindgen/ir/ty.rs | 7 ++++--- bindgen/options/mod.rs | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/bindgen/ir/ty.rs b/bindgen/ir/ty.rs index 32bea702c1..1aee065970 100644 --- a/bindgen/ir/ty.rs +++ b/bindgen/ir/ty.rs @@ -210,9 +210,10 @@ impl Type { self.layout.or_else(|| { match self.kind { TypeKind::Comp(ref ci) => ci.layout(ctx), - TypeKind::Array(inner, length) if length == 0 => Some( - Layout::new(0, ctx.resolve_type(inner).layout(ctx)?.align), - ), + TypeKind::Array(inner, 0) => Some(Layout::new( + 0, + ctx.resolve_type(inner).layout(ctx)?.align, + )), // FIXME(emilio): This is a hack for anonymous union templates. // Use the actual pointer size! TypeKind::Pointer(..) => Some(Layout::new( diff --git a/bindgen/options/mod.rs b/bindgen/options/mod.rs index 925dcbaea1..856b7f8c70 100644 --- a/bindgen/options/mod.rs +++ b/bindgen/options/mod.rs @@ -1103,7 +1103,7 @@ options! { self.options .module_lines .entry(module.into().into_boxed_str()) - .or_insert_with(Vec::new) + .or_default() .push(line.into().into_boxed_str()); self } From 9f57c67775abb49b0f945acc1ab5d0f72de3745c Mon Sep 17 00:00:00 2001 From: CGMossa Date: Mon, 14 Aug 2023 21:52:26 +0200 Subject: [PATCH 550/942] Add "experimental" features to docs.rs (#2605) * Add "experimental" features to docs.rs docs.rs/bindgen doesn't contain the documentation for things under the `"experimental"` feature. This means that no-one can see the `emit_diagnostics` replacement for `emit_warnings`. * Update Cargo.toml Maybe we just need `all-features = true`? --- bindgen/Cargo.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index 1c938bed29..4c736e0d97 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -59,3 +59,6 @@ __cli = [] __testing_only_extra_assertions = [] __testing_only_libclang_9 = [] __testing_only_libclang_5 = [] + +[package.metadata.docs.rs] +features = ["experimental"] From 4dd9afa0fd343650b99cc0c4906eb48fbb3c39b7 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Mon, 14 Aug 2023 15:25:11 -0500 Subject: [PATCH 551/942] Avoid exporting `extra_assert` macros (#2606) --- CHANGELOG.md | 1 + bindgen/extra_assertions.rs | 17 ----------------- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8befcb7aed..3c508178f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -179,6 +179,7 @@ equal to or greater than 1.71. This comes as a result of the ABI being stabilised (in Rust 1.71). ## Removed +- The `extra_assert` and `extra_assert_eq` macros are no longer exported. ## Fixed - Bindgen no longer panics when parsing an objective-C header that includes a Rust keyword that cannot be a raw identifier, such as: `self`, `crate`, diff --git a/bindgen/extra_assertions.rs b/bindgen/extra_assertions.rs index 19e47636d2..fbddad7825 100644 --- a/bindgen/extra_assertions.rs +++ b/bindgen/extra_assertions.rs @@ -3,7 +3,6 @@ /// Simple macro that forwards to assert! when using /// __testing_only_extra_assertions. -#[macro_export] macro_rules! extra_assert { ( $cond:expr ) => { if cfg!(feature = "__testing_only_extra_assertions") { @@ -16,19 +15,3 @@ macro_rules! extra_assert { } }; } - -/// Simple macro that forwards to assert_eq! when using -/// __testing_only_extra_assertions. -#[macro_export] -macro_rules! extra_assert_eq { - ( $lhs:expr , $rhs:expr ) => { - if cfg!(feature = "__testing_only_extra_assertions") { - assert_eq!($lhs, $rhs); - } - }; - ( $lhs:expr , $rhs:expr , $( $arg:tt )+ ) => { - if cfg!(feature = "__testing_only_extra_assertions") { - assert!($lhs, $rhs, $( $arg )* ); - } - }; -} From bb8db7e8e497a45a8fe6f1c0d38479871d180401 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Mon, 14 Aug 2023 15:40:49 -0500 Subject: [PATCH 552/942] Document non-generation of `size_t` definition (#2607) * Document non-generation of `size_t` definition * Run rustfmt --- bindgen/options/mod.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bindgen/options/mod.rs b/bindgen/options/mod.rs index 856b7f8c70..3c7bf7c2eb 100644 --- a/bindgen/options/mod.rs +++ b/bindgen/options/mod.rs @@ -1589,6 +1589,9 @@ options! { methods: { /// Set whether `size_t` should be translated to `usize`. /// + /// If `size_t` is translated to `usize`, type definitions for `size_t` will not be + /// emitted. + /// /// `size_t` is translated to `usize` by default. pub fn size_t_is_usize(mut self, is: bool) -> Self { self.options.size_t_is_usize = is; From 820ca42982fe77d5504f7a0534a3de6db6a1d703 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Tue, 15 Aug 2023 13:01:02 -0500 Subject: [PATCH 553/942] Add `--allowlist-item` (#2601) * Add `allowlist_item` method and flag * Add `allowlist_item` basic functionality * Add test * Update changelog --- CHANGELOG.md | 2 ++ bindgen-cli/options.rs | 8 +++++ .../expectations/tests/allowlist_item.rs | 30 +++++++++++++++++++ bindgen-tests/tests/headers/allowlist_item.h | 17 +++++++++++ bindgen/ir/context.rs | 12 +++++++- bindgen/lib.rs | 12 ++++---- bindgen/options/mod.rs | 17 +++++++++++ 7 files changed, 92 insertions(+), 6 deletions(-) create mode 100644 bindgen-tests/tests/expectations/tests/allowlist_item.rs create mode 100644 bindgen-tests/tests/headers/allowlist_item.h diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c508178f4..ef6468290c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -172,6 +172,8 @@ ## Added - The `system` ABI is now supported as an option for the `--override-abi` flag. +- The `allowlist_item` method and the `--allowlist-item` flag have been + included to filter items regardless or their kind. ## Changed - The `Clone` implementation for `_BindgenUnionField` has been changed to pass the `incorrect_clone_impl_on_copy_type` Clippy lint. diff --git a/bindgen-cli/options.rs b/bindgen-cli/options.rs index 66f068e474..b6ff059da2 100644 --- a/bindgen-cli/options.rs +++ b/bindgen-cli/options.rs @@ -258,6 +258,9 @@ struct BindgenCommand { /// Allowlist all contents of PATH. #[arg(long, value_name = "PATH")] allowlist_file: Vec, + /// Allowlist all items matching REGEX. Other non-allowlisted items will not be generated. + #[arg(long, value_name = "REGEX")] + allowlist_item: Vec, /// Print verbose error messages. #[arg(long)] verbose: bool, @@ -471,6 +474,7 @@ where allowlist_type, allowlist_var, allowlist_file, + allowlist_item, verbose, dump_preprocessed_input, no_record_matches, @@ -829,6 +833,10 @@ where builder = builder.allowlist_file(file); } + for item in allowlist_item { + builder = builder.allowlist_item(item); + } + for arg in clang_args { builder = builder.clang_arg(arg); } diff --git a/bindgen-tests/tests/expectations/tests/allowlist_item.rs b/bindgen-tests/tests/expectations/tests/allowlist_item.rs new file mode 100644 index 0000000000..eaca8aec22 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/allowlist_item.rs @@ -0,0 +1,30 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub const FooDefault: u32 = 0; +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Foo { + pub field: ::std::os::raw::c_int, +} +#[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::(), + 4usize, + concat!("Size of: ", stringify!(Foo)), + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(Foo)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).field) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Foo), "::", stringify!(field)), + ); +} +extern "C" { + pub fn FooNew(value: ::std::os::raw::c_int) -> Foo; +} diff --git a/bindgen-tests/tests/headers/allowlist_item.h b/bindgen-tests/tests/headers/allowlist_item.h new file mode 100644 index 0000000000..7e5e00d0e3 --- /dev/null +++ b/bindgen-tests/tests/headers/allowlist_item.h @@ -0,0 +1,17 @@ +// bindgen-flags: --allowlist-item 'Foo.*' + +struct Foo { + int field; +}; + +struct Foo FooNew(int value); + +#define FooDefault 0 + +struct Bar { + int field; +}; + +struct Foo BarNew(int value); + +#define BarDefault 0 diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index 1b26c2c3a2..c5e2832cc9 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -2343,7 +2343,8 @@ If you encounter an error missing from this list, please file an issue or a PR!" if self.options().allowlisted_types.is_empty() && self.options().allowlisted_functions.is_empty() && self.options().allowlisted_vars.is_empty() && - self.options().allowlisted_files.is_empty() + self.options().allowlisted_files.is_empty() && + self.options().allowlisted_items.is_empty() { return true; } @@ -2373,6 +2374,11 @@ If you encounter an error missing from this list, please file an issue or a PR!" let name = item.path_for_allowlisting(self)[1..].join("::"); debug!("allowlisted_items: testing {:?}", name); + + if self.options().allowlisted_items.matches(&name) { + return true; + } + match *item.kind() { ItemKind::Module(..) => true, ItemKind::Function(_) => { @@ -2496,6 +2502,10 @@ If you encounter an error missing from this list, please file an issue or a PR!" for item in self.options().allowlisted_types.unmatched_items() { unused_regex_diagnostic(item, "--allowlist-type", self); } + + for item in self.options().allowlisted_items.unmatched_items() { + unused_regex_diagnostic(item, "--allowlist-items", self); + } } /// Convenient method for getting the prefix to use for most traits in diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 4e5d445f3a..05f95bf8f5 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -435,18 +435,19 @@ impl Builder { impl BindgenOptions { fn build(&mut self) { - const REGEX_SETS_LEN: usize = 27; + const REGEX_SETS_LEN: usize = 28; let regex_sets: [_; REGEX_SETS_LEN] = [ - &mut self.allowlisted_vars, - &mut self.allowlisted_types, - &mut self.allowlisted_functions, - &mut self.allowlisted_files, &mut self.blocklisted_types, &mut self.blocklisted_functions, &mut self.blocklisted_items, &mut self.blocklisted_files, &mut self.opaque_types, + &mut self.allowlisted_vars, + &mut self.allowlisted_types, + &mut self.allowlisted_functions, + &mut self.allowlisted_files, + &mut self.allowlisted_items, &mut self.bitfield_enums, &mut self.constified_enums, &mut self.constified_enum_modules, @@ -482,6 +483,7 @@ impl BindgenOptions { "--allowlist-function", "--allowlist-var", "--allowlist-file", + "--allowlist-item", "--bitfield-enum", "--newtype-enum", "--newtype-global-enum", diff --git a/bindgen/options/mod.rs b/bindgen/options/mod.rs index 3c7bf7c2eb..558f5343a2 100644 --- a/bindgen/options/mod.rs +++ b/bindgen/options/mod.rs @@ -345,6 +345,23 @@ options! { }, as_args: "--allowlist-file", }, + /// Items that have been allowlisted and should appear in the generated code. + allowlisted_items: RegexSet { + methods: { + regex_option! { + /// Generate bindings for the given item, regardless of whether it is a type, + /// function, module, etc. + /// + /// This option is transitive by default. Check the documentation of the + /// [`Builder::allowlist_recursively`] method for further information. + pub fn allowlist_item>(mut self, arg: T) -> Builder { + self.options.allowlisted_items.insert(arg); + self + } + } + }, + as_args: "--allowlist-item", + }, /// The default style of for generated `enum`s. default_enum_style: EnumVariation { methods: { From 5c9f516612150362aaa82daacc34e38a291dc4cb Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Tue, 5 Sep 2023 18:52:19 +0200 Subject: [PATCH 554/942] cargo-dist (and cargo-release) (#2609) * wow shiny new cargo-dist CI! * cargo-dist: include installers * tests_expectations is not to be published Makes it play well with cargo-release, where we would get the following: error: tests_expectations is missing the following fields: license || license-file documentation || homepage || repository * add config for cargo-release * too long to fit easy * add some docs * fix docs * fix docs * doc clarification * bump cargo-dist --- .github/workflows/release.yml | 180 ++++++++++++++++++++ CONTRIBUTING.md | 35 +++- Cargo.lock | 2 +- Cargo.toml | 26 +++ bindgen-tests/tests/expectations/Cargo.toml | 3 +- 5 files changed, 240 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000000..e0631ca88a --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,180 @@ +# Copyright 2022-2023, axodotdev +# SPDX-License-Identifier: MIT or Apache-2.0 +# +# CI that: +# +# * checks for a Git Tag that looks like a release +# * creates a draft Github Release™ and fills in its text +# * builds artifacts with cargo-dist (executable-zips, installers, hashes) +# * uploads those artifacts to the Github Release™ +# * undrafts the Github Release™ on success +# +# Note that the Github Release™ will be created before the artifacts, +# so there will be a few minutes where the release has no artifacts +# and then they will slowly trickle in, possibly failing. To make +# this more pleasant we mark the release as a "draft" until all +# artifacts have been successfully uploaded. This allows you to +# choose what to do with partial successes and avoids spamming +# anyone with notifications before the release is actually ready. +name: Release + +permissions: + contents: write + +# This task will run whenever you push a git tag that looks like a version +# like "1.0.0", "v0.1.0-prerelease.1", "my-app/0.1.0", "releases/v1.0.0", etc. +# Various formats will be parsed into a VERSION and an optional PACKAGE_NAME, where +# PACKAGE_NAME must be the name of a Cargo package in your workspace, and VERSION +# must be a Cargo-style SemVer Version (must have at least major.minor.patch). +# +# If PACKAGE_NAME is specified, then the release will be for that +# package (erroring out if it doesn't have the given version or isn't cargo-dist-able). +# +# If PACKAGE_NAME isn't specified, then the release will be for all +# (cargo-dist-able) packages in the workspace with that version (this mode is +# intended for workspaces with only one dist-able package, or with all dist-able +# packages versioned/released in lockstep). +# +# If you push multiple tags at once, separate instances of this workflow will +# spin up, creating an independent Github Release™ for each one. However Github +# will hard limit this to 3 tags per commit, as it will assume more tags is a +# mistake. +# +# If there's a prerelease-style suffix to the version, then the Github Release™ +# will be marked as a prerelease. +on: + push: + tags: + - '**[0-9]+.[0-9]+.[0-9]+*' + +jobs: + # Run 'cargo dist plan' to determine what tasks we need to do + # and create a draft github release with the computed title/body + plan: + runs-on: ubuntu-latest + outputs: + has-releases: ${{ steps.plan.outputs.has-releases }} + releases: ${{ steps.plan.outputs.releases }} + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + - name: Install cargo-dist + run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.2.0/cargo-dist-installer.sh | sh" + - id: plan + run: | + cargo dist plan --tag=${{ github.ref_name }} --output-format=json > dist-manifest.json + echo "dist plan ran successfully" + cat dist-manifest.json + + # Create the Github Release™ based on what cargo-dist thinks it should be + ANNOUNCEMENT_TITLE=$(jq --raw-output ".announcement_title" dist-manifest.json) + IS_PRERELEASE=$(jq --raw-output ".announcement_is_prerelease" dist-manifest.json) + jq --raw-output ".announcement_github_body" dist-manifest.json > new_dist_announcement.md + gh release create ${{ github.ref_name }} --draft --prerelease="$IS_PRERELEASE" --title="$ANNOUNCEMENT_TITLE" --notes-file=new_dist_announcement.md + echo "created announcement!" + + # Upload the manifest to the Github Release™ + gh release upload ${{ github.ref_name }} dist-manifest.json + echo "uploaded manifest!" + + # Disable all the upload-artifacts tasks if we have no actual releases + HAS_RELEASES=$(jq --raw-output ".releases != null" dist-manifest.json) + echo "has-releases=$HAS_RELEASES" >> "$GITHUB_OUTPUT" + echo "releases=$(jq --compact-output ".releases" dist-manifest.json)" >> "$GITHUB_OUTPUT" + + # Build and packages all the platform-specific things + upload-local-artifacts: + # Let the initial task tell us to not run (currently very blunt) + needs: plan + if: ${{ needs.plan.outputs.has-releases == 'true' }} + strategy: + fail-fast: false + matrix: + # For these target platforms + include: + - os: "macos-11" + dist-args: "--artifacts=local --target=aarch64-apple-darwin" + install-dist: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.2.0/cargo-dist-installer.sh | sh" + - os: "macos-11" + dist-args: "--artifacts=local --target=x86_64-apple-darwin" + install-dist: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.2.0/cargo-dist-installer.sh | sh" + - os: "windows-2019" + dist-args: "--artifacts=local --target=x86_64-pc-windows-msvc" + install-dist: "irm https://github.com/axodotdev/cargo-dist/releases/download/v0.2.0/cargo-dist-installer.ps1 | iex" + - os: "ubuntu-20.04" + dist-args: "--artifacts=local --target=x86_64-unknown-linux-gnu" + install-dist: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.2.0/cargo-dist-installer.sh | sh" + runs-on: ${{ matrix.os }} + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + - name: Install cargo-dist + run: ${{ matrix.install-dist }} + - name: Run cargo-dist + # This logic is a bit janky because it's trying to be a polyglot between + # powershell and bash since this will run on windows, macos, and linux! + # The two platforms don't agree on how to talk about env vars but they + # do agree on 'cat' and '$()' so we use that to marshal values between commands. + run: | + # Actually do builds and make zips and whatnot + cargo dist build --tag=${{ github.ref_name }} --output-format=json ${{ matrix.dist-args }} > dist-manifest.json + echo "dist ran successfully" + cat dist-manifest.json + + # Parse out what we just built and upload it to the Github Release™ + jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json > uploads.txt + echo "uploading..." + cat uploads.txt + gh release upload ${{ github.ref_name }} $(cat uploads.txt) + echo "uploaded!" + + # Build and package all the platform-agnostic(ish) things + upload-global-artifacts: + needs: upload-local-artifacts + runs-on: "ubuntu-20.04" + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + - name: Install cargo-dist + run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.2.0/cargo-dist-installer.sh | sh" + # Get all the local artifacts for the global tasks to use (for e.g. checksums) + - name: Fetch local artifacts + run: | + gh release download ${{ github.ref_name }} --dir target/distrib/ + - name: Run cargo-dist + run: | + cargo dist build --tag=${{ github.ref_name }} --output-format=json "--artifacts=global" > dist-manifest.json + echo "dist ran successfully" + cat dist-manifest.json + + # Parse out what we just built and upload it to the Github Release™ + jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json > uploads.txt + echo "uploading..." + cat uploads.txt + gh release upload ${{ github.ref_name }} $(cat uploads.txt) + echo "uploaded!" + + # Mark the Github Release™ as a non-draft now that everything has succeeded! + publish-release: + # Only run after all the other tasks, but it's ok if upload-artifacts was skipped + needs: [plan, upload-local-artifacts, upload-global-artifacts] + if: ${{ always() && needs.plan.result == 'success' && (needs.upload-local-artifacts.result == 'skipped' || needs.upload-local-artifacts.result == 'success') && (needs.upload-global-artifacts.result == 'skipped' || needs.upload-global-artifacts.result == 'success') }} + runs-on: ubuntu-latest + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + - name: mark release as non-draft + run: | + gh release edit ${{ github.ref_name }} --draft=false diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4ec1a4c834..e6439e1262 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -552,10 +552,14 @@ $ npm install doctoc $ ./node_modules/doctoc/doctoc.js CHANGELOG.md ``` -### Bumping the version numbers. +### Bumping the version numbers -Bump version numbers as needed. Run tests just to ensure everything is working -as expected. +Use `cargo release` (from `cargo install cargo-release`) to automate things: + +- For a feature release, `cargo release minor --execute` (will bump v0.62.1 to v0.63.0) +- For a patch release, `cargo release patch --execute` (will bump v0.63.0 to v0.63.1) + +Run tests just to ensure everything is working as expected. ### Merge to `main` @@ -567,15 +571,38 @@ important fix) you can skip this. Once you're in the right commit, do: +``` +cargo release [patch|minor] --execute +cargo release --execute +``` +This does the equivalent of the following: + ``` $ git tag -a v0.62.1 # With the right version of course $ pushd bindgen && cargo publish && popd $ pushd bindgen-cli && cargo publish && popd $ git push --tags upstream # To publish the tag ``` + ### Create a new release on Github -See [Releasing projects on Github](https://docs.github.com/en/repositories/releasing-projects-on-github) +The release will be automated with the help of `.github/workflows/release.yml`, +and will only be created when all tests succeed. +While the tests are still running, +a draft GitHub release will be created, +to avoid notifying watchers of the repo should a CI step fail. + +If everything succeeds, +bindgen cli installers for Linux/MacOS and Windows will be created, +as well as tarballs. +See `[workspace.metadata.dist]` section in Cargo.toml for the configuration. + +To update the release configuration, +when a new cargo-dist is available: +``` +cargo dist init # from "cargo install cargo-dist" +cargo dist generate-ci # to update .github/workflows/release.yml +``` [prettyplease]: https://github.com/dtolnay/prettyplease diff --git a/Cargo.lock b/Cargo.lock index b44aab8eb9..5cf46b2214 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -638,7 +638,7 @@ dependencies = [ [[package]] name = "tests_expectations" -version = "0.1.0" +version = "0.0.0" dependencies = [ "block", "libloading", diff --git a/Cargo.toml b/Cargo.toml index a9d9d41ee6..359501dc67 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,3 +13,29 @@ default-members = [ "bindgen-cli", "bindgen-tests", ] + +# Config for 'cargo dist' +[workspace.metadata.dist] +# The preferred cargo-dist version to use in CI (Cargo.toml SemVer syntax) +cargo-dist-version = "0.2.0" +# CI backends to support (see 'cargo dist generate-ci') +ci = ["github"] +# The installers to generate for each app +installers = ["shell", "powershell"] +# Target platforms to build apps for (Rust target-triple syntax) +targets = [ + "x86_64-unknown-linux-gnu", + "x86_64-apple-darwin", + "x86_64-pc-windows-msvc", + "aarch64-apple-darwin", +] + +# Config for 'cargo release' +[workspace.metadata.release] +shared-version = true # ensures published packages share the same version +tag-name = "v{{version}}" + +# The profile that 'cargo dist' will build with +[profile.dist] +inherits = "release" +lto = "thin" diff --git a/bindgen-tests/tests/expectations/Cargo.toml b/bindgen-tests/tests/expectations/Cargo.toml index bf7da25349..adb95d56d2 100644 --- a/bindgen-tests/tests/expectations/Cargo.toml +++ b/bindgen-tests/tests/expectations/Cargo.toml @@ -1,13 +1,14 @@ [package] name = "tests_expectations" description = "bindgen results when ran on ../headers/*" -version = "0.1.0" +version = "0.0.0" authors = [ "Jyun-Yan You ", "Emilio Cobos Álvarez ", "The Servo project developers", ] edition = "2018" +publish = false [dependencies] block = "0.1" From 81bba696a0473db17ed9efcda862364d012f2a45 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Tue, 5 Sep 2023 18:58:31 +0200 Subject: [PATCH 555/942] we stopped building mdbook from source (#2614) Should of been part of 922655f33646b7a126f4c39fb7df60a122d7eb1b as we no longer need a rust toolchain to compile mdbook --- .github/workflows/bindgen.yml | 7 ------- .github/workflows/deploy-book.yml | 7 ------- 2 files changed, 14 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 72a34fa06c..0bf33d199f 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -237,13 +237,6 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Install stable - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - # NOTE(emilio): Change deploy-book as well if you change this. - name: Test book run: | diff --git a/.github/workflows/deploy-book.yml b/.github/workflows/deploy-book.yml index a0d87a2094..9bb1e1b852 100644 --- a/.github/workflows/deploy-book.yml +++ b/.github/workflows/deploy-book.yml @@ -13,13 +13,6 @@ jobs: with: persist-credentials: false - - name: Install stable - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - name: Test book run: | curl -L https://github.com/rust-lang/mdBook/releases/download/v0.4.5/mdbook-v0.4.5-x86_64-unknown-linux-gnu.tar.gz | tar xz From ea3f8a75b3f38fb3d8201e5401783754ca4733a6 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Tue, 5 Sep 2023 18:59:33 +0200 Subject: [PATCH 556/942] there been editors not affilicated with Servo (#2615) --- book/book.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/book/book.toml b/book/book.toml index 78809c2176..d007c1ee49 100644 --- a/book/book.toml +++ b/book/book.toml @@ -1,6 +1,5 @@ [book] title = "The bindgen User Guide" -author = "The Servo project developers" description = "`bindgen` automatically generates Rust FFI bindings to C and C++ libraries." [output.html] From ef2fb793e9894afae7423796200293d06661c1a4 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Tue, 5 Sep 2023 19:00:53 +0200 Subject: [PATCH 557/942] make search less surprising (#2613) This is so it matches common search engines and you get more precise search results --- book/book.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/book/book.toml b/book/book.toml index d007c1ee49..3f55b78377 100644 --- a/book/book.toml +++ b/book/book.toml @@ -5,3 +5,4 @@ description = "`bindgen` automatically generates Rust FFI bindings to C and C++ [output.html] git-repository-url = "https://github.com/rust-lang/rust-bindgen" edit-url-template = "https://github.com/rust-lang/rust-bindgen/edit/main/book/{path}" +search.use-boolean-and = true From 1d74af3a12f0a6718339069ec084050dc134e306 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Tue, 5 Sep 2023 12:35:06 -0500 Subject: [PATCH 558/942] Don't delete the lockfile on the msrv workflow (#2621) --- .github/workflows/bindgen.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 0bf33d199f..3d7b5aa7a8 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -52,7 +52,7 @@ jobs: override: true - name: Build with msrv - run: rm Cargo.lock && cargo +1.60.0 build --lib + run: cargo +1.60.0 build --lib minimal: runs-on: ubuntu-latest From b52377ab5148b54aa6ac63fab1fd4f352c044da0 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Tue, 5 Sep 2023 13:11:34 -0500 Subject: [PATCH 559/942] Update CHANGELOG.md (#2622) --- CHANGELOG.md | 174 ++++++++++++++++++++++++++++----------------------- 1 file changed, 95 insertions(+), 79 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef6468290c..8ab4bd440d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,186 +7,202 @@ - [Removed](#removed) - [Fixed](#fixed) - [Security](#security) -- [0.66.1](#0661) - - [Removed](#removed-1) -- [0.66.0](#0660) +- [0.67.0](#0670) - [Added](#added-1) - [Changed](#changed-1) - - [Removed](#removed-2) -- [0.65.1](#0651) + - [Removed](#removed-1) - [Fixed](#fixed-1) -- [0.65.0](#0650) +- [0.66.1](#0661) + - [Removed](#removed-2) +- [0.66.0](#0660) - [Added](#added-2) - [Changed](#changed-2) - [Removed](#removed-3) -- [0.64.0](#0640) +- [0.65.1](#0651) + - [Fixed](#fixed-2) +- [0.65.0](#0650) - [Added](#added-3) - [Changed](#changed-3) -- [0.63.0](#0630) + - [Removed](#removed-4) +- [0.64.0](#0640) - [Added](#added-4) - [Changed](#changed-4) - - [Removed](#removed-4) -- [0.62.0](#0620) +- [0.63.0](#0630) - [Added](#added-5) - [Changed](#changed-5) - - [Fixed](#fixed-2) -- [0.61.0](#0610) + - [Removed](#removed-5) +- [0.62.0](#0620) - [Added](#added-6) - [Changed](#changed-6) - [Fixed](#fixed-3) -- [0.60.1](#0601) - - [Fixed](#fixed-4) -- [0.60.0](#0600) +- [0.61.0](#0610) - [Added](#added-7) - - [Fixed](#fixed-5) - [Changed](#changed-7) - - [Removed](#removed-5) + - [Fixed](#fixed-4) +- [0.60.1](#0601) + - [Fixed](#fixed-5) +- [0.60.0](#0600) + - [Added](#added-8) + - [Fixed](#fixed-6) + - [Changed](#changed-8) + - [Removed](#removed-6) - [0.59.2](#0592) - [0.59.1](#0591) - - [Fixed](#fixed-6) -- [0.59.0](#0590) - - [Added](#added-8) - [Fixed](#fixed-7) - - [Changed](#changed-8) -- [0.58.1](#0581) +- [0.59.0](#0590) - [Added](#added-9) -- [0.58.0](#0580) - - [Added](#added-10) - [Fixed](#fixed-8) - [Changed](#changed-9) - - [Deprecated](#deprecated) - - [Removed](#removed-6) +- [0.58.1](#0581) + - [Added](#added-10) +- [0.58.0](#0580) + - [Added](#added-11) - [Fixed](#fixed-9) + - [Changed](#changed-10) + - [Deprecated](#deprecated) + - [Removed](#removed-7) + - [Fixed](#fixed-10) - [Security](#security-1) - [0.57.0](#0570) - - [Added](#added-11) - - [Fixed](#fixed-10) -- [0.56.0](#0560) - [Added](#added-12) - - [Changed](#changed-10) - [Fixed](#fixed-11) -- [0.55.1](#0551) - - [Fixed](#fixed-12) -- [0.55.0](#0550) - - [Removed](#removed-7) +- [0.56.0](#0560) - [Added](#added-13) - [Changed](#changed-11) + - [Fixed](#fixed-12) +- [0.55.1](#0551) - [Fixed](#fixed-13) -- [0.54.1](#0541) +- [0.55.0](#0550) + - [Removed](#removed-8) - [Added](#added-14) - [Changed](#changed-12) - [Fixed](#fixed-14) -- [0.54.0](#0540) +- [0.54.1](#0541) - [Added](#added-15) - [Changed](#changed-13) - [Fixed](#fixed-15) -- [0.53.3](#0533) +- [0.54.0](#0540) - [Added](#added-16) + - [Changed](#changed-14) - [Fixed](#fixed-16) +- [0.53.3](#0533) + - [Added](#added-17) + - [Fixed](#fixed-17) - [0.53.2](#0532) - - [Changed](#changed-14) + - [Changed](#changed-15) - [0.53.1](#0531) - - [Added](#added-17) -- [0.53.0](#0530) - [Added](#added-18) - - [Changed](#changed-15) - - [Fixed](#fixed-17) -- [0.52.0](#0520) +- [0.53.0](#0530) - [Added](#added-19) - [Changed](#changed-16) - [Fixed](#fixed-18) -- [0.51.1](#0511) - - [Fixed](#fixed-19) +- [0.52.0](#0520) + - [Added](#added-20) - [Changed](#changed-17) -- [0.51.0](#0510) + - [Fixed](#fixed-19) +- [0.51.1](#0511) - [Fixed](#fixed-20) - [Changed](#changed-18) - - [Added](#added-20) -- [0.50.0](#0500) +- [0.51.0](#0510) + - [Fixed](#fixed-21) + - [Changed](#changed-19) - [Added](#added-21) -- [0.49.3](#0493) +- [0.50.0](#0500) - [Added](#added-22) +- [0.49.3](#0493) + - [Added](#added-23) - [0.49.2](#0492) - - [Changed](#changed-19) -- [0.49.1](#0491) - - [Fixed](#fixed-21) - [Changed](#changed-20) -- [0.49.0](#0490) - - [Added](#added-23) +- [0.49.1](#0491) - [Fixed](#fixed-22) - [Changed](#changed-21) -- [0.48.1](#0481) +- [0.49.0](#0490) + - [Added](#added-24) - [Fixed](#fixed-23) -- [0.48.0](#0480) - [Changed](#changed-22) +- [0.48.1](#0481) - [Fixed](#fixed-24) -- [0.47.4](#0474) - - [Added](#added-24) -- [0.47.3](#0473) +- [0.48.0](#0480) - [Changed](#changed-23) -- [0.47.2](#0472) - [Fixed](#fixed-25) -- [0.47.1](#0471) +- [0.47.4](#0474) + - [Added](#added-25) +- [0.47.3](#0473) - [Changed](#changed-24) +- [0.47.2](#0472) - [Fixed](#fixed-26) -- [0.47.0](#0470) +- [0.47.1](#0471) - [Changed](#changed-25) - [Fixed](#fixed-27) -- [0.33.1 .. 0.46.0](#0331--0460) - - [Added](#added-25) - - [Removed](#removed-8) +- [0.47.0](#0470) - [Changed](#changed-26) - [Fixed](#fixed-28) -- [0.33.1](#0331) +- [0.33.1 .. 0.46.0](#0331--0460) + - [Added](#added-26) + - [Removed](#removed-9) + - [Changed](#changed-27) - [Fixed](#fixed-29) +- [0.33.1](#0331) + - [Fixed](#fixed-30) - [0.33.0](#0330) - [0.32.2](#0322) - - [Fixed](#fixed-30) -- [0.32.1](#0321) - [Fixed](#fixed-31) -- [0.32.0](#0320) - - [Added](#added-26) - - [Changed](#changed-27) +- [0.32.1](#0321) - [Fixed](#fixed-32) -- [0.31.0](#0310) +- [0.32.0](#0320) - [Added](#added-27) - [Changed](#changed-28) - - [Deprecated](#deprecated-1) - - [Removed](#removed-9) - [Fixed](#fixed-33) -- [0.30.0](#0300) +- [0.31.0](#0310) - [Added](#added-28) - [Changed](#changed-29) - - [Deprecated](#deprecated-2) + - [Deprecated](#deprecated-1) + - [Removed](#removed-10) - [Fixed](#fixed-34) -- [0.29.0](#0290) +- [0.30.0](#0300) - [Added](#added-29) - [Changed](#changed-30) + - [Deprecated](#deprecated-2) - [Fixed](#fixed-35) +- [0.29.0](#0290) + - [Added](#added-30) + - [Changed](#changed-31) + - [Fixed](#fixed-36) -------------------------------------------------------------------------------- - # Unreleased +## Added +## Changed +## Removed +## Fixed +## Security + +# 0.67.0 + ## Added - The `system` ABI is now supported as an option for the `--override-abi` flag. - The `allowlist_item` method and the `--allowlist-item` flag have been included to filter items regardless or their kind. +- Include installers as release artifacts on Github. ## Changed - The `Clone` implementation for `_BindgenUnionField` has been changed to pass the `incorrect_clone_impl_on_copy_type` Clippy lint. - The `c_unwind` ABI can be used without a feature gate for any Rust target version equal to or greater than 1.71. This comes as a result of the ABI being stabilised (in Rust 1.71). +- Formatting changes when using prettyplease as a formatter due to a new + prettyplease version. +- Avoid generating invalid `CStr` constants when using the `--generate-cstr` + option. ## Removed - The `extra_assert` and `extra_assert_eq` macros are no longer exported. ## Fixed - Bindgen no longer panics when parsing an objective-C header that includes a Rust keyword that cannot be a raw identifier, such as: `self`, `crate`, `super` or `Self`. -## Security # 0.66.1 From 073fa628ac66f7a96f5bb184505046341d105a16 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Wed, 6 Sep 2023 18:48:13 +0200 Subject: [PATCH 560/942] test cli and lib msrv separately (#2625) * ci: test lib too * ci: a more accurate title * ci: use a maintained Action * ci: test cli msrv --- .github/workflows/bindgen.yml | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 3d7b5aa7a8..c7c37bbc17 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -42,17 +42,25 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Install msrv - uses: actions-rs/toolchain@v1 + - name: Install msrv for lib + uses: dtolnay/rust-toolchain@master with: - profile: minimal # MSRV below is documented in Cargo.toml and README.md, please update those if you # change this. toolchain: 1.60.0 - override: true - - name: Build with msrv - run: cargo +1.60.0 build --lib + - name: Test lib with msrv + run: cargo +1.60.0 test --package bindgen + + - name: Install msrv for cli + uses: dtolnay/rust-toolchain@master + with: + # MSRV below is documented in Cargo.toml and README.md, please update those if you + # change this. + toolchain: 1.64.0 + + - name: Test cli with msrv + run: cargo +1.64.0 build --package bindgen-cli minimal: runs-on: ubuntu-latest From f623bfb5c35d8100fe20cbf35529d3fd2e9ea060 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Wed, 6 Sep 2023 11:48:42 -0500 Subject: [PATCH 561/942] Don't release anything by default (#2623) This PR marks the whole workspace with `release = false` so `cargo release` doesn't release any packages and then marks `bindgen` and `bindgen-cli` with `release = true` so they are the only packages being released. --- Cargo.toml | 1 + bindgen-cli/Cargo.toml | 3 +++ bindgen/Cargo.toml | 3 +++ 3 files changed, 7 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 359501dc67..ea6da9aada 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,6 +34,7 @@ targets = [ [workspace.metadata.release] shared-version = true # ensures published packages share the same version tag-name = "v{{version}}" +release = false # The profile that 'cargo dist' will build with [profile.dist] diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index 5db34395d1..6126f4034f 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -41,3 +41,6 @@ which-rustfmt = ["bindgen/which-rustfmt"] __testing_only_extra_assertions = ["bindgen/__testing_only_extra_assertions"] __testing_only_libclang_9 = ["bindgen/__testing_only_libclang_9"] __testing_only_libclang_5 = ["bindgen/__testing_only_libclang_5"] + +[package.metadata.release] +release = true diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index 4c736e0d97..09a841ad47 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -62,3 +62,6 @@ __testing_only_libclang_5 = [] [package.metadata.docs.rs] features = ["experimental"] + +[package.metadata.release] +release = true From 59102e9b531d55ccee5f652cb63295f621971df7 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Wed, 6 Sep 2023 11:59:29 -0500 Subject: [PATCH 562/942] chore: Release --- Cargo.lock | 4 ++-- bindgen-cli/Cargo.toml | 4 ++-- bindgen/Cargo.toml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5cf46b2214..fbecd9b982 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -23,7 +23,7 @@ dependencies = [ [[package]] name = "bindgen" -version = "0.66.1" +version = "0.67.0" dependencies = [ "annotate-snippets", "bitflags 2.2.1", @@ -45,7 +45,7 @@ dependencies = [ [[package]] name = "bindgen-cli" -version = "0.66.1" +version = "0.67.0" dependencies = [ "bindgen", "clap", diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index 6126f4034f..30f99aa7bd 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -11,7 +11,7 @@ readme = "../README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.66.1" +version = "0.67.0" edition = "2018" rust-version = "1.64.0" @@ -20,7 +20,7 @@ path = "main.rs" name = "bindgen" [dependencies] -bindgen = { path = "../bindgen", version = "=0.66.1", features = ["__cli", "experimental"] } +bindgen = { path = "../bindgen", version = "=0.67.0", features = ["__cli", "experimental"] } clap = { version = "4", features = ["derive"] } clap_complete = "4" env_logger = { version = "0.10.0", optional = true } diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index 09a841ad47..87c2a4b317 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -14,7 +14,7 @@ readme = "../README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.66.1" +version = "0.67.0" edition = "2018" build = "build.rs" # If you change this, also update README.md and msrv in .github/workflows/bindgen.yml From ebcf0bcc8bba113d82d0f1e0cbede40ccffc6e8f Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Wed, 6 Sep 2023 12:00:41 -0500 Subject: [PATCH 563/942] chore: Release --- Cargo.lock | 4 ++-- bindgen-cli/Cargo.toml | 4 ++-- bindgen/Cargo.toml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fbecd9b982..6d32325240 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -23,7 +23,7 @@ dependencies = [ [[package]] name = "bindgen" -version = "0.67.0" +version = "0.68.0" dependencies = [ "annotate-snippets", "bitflags 2.2.1", @@ -45,7 +45,7 @@ dependencies = [ [[package]] name = "bindgen-cli" -version = "0.67.0" +version = "0.68.0" dependencies = [ "bindgen", "clap", diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index 30f99aa7bd..070a1f0ad7 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -11,7 +11,7 @@ readme = "../README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.67.0" +version = "0.68.0" edition = "2018" rust-version = "1.64.0" @@ -20,7 +20,7 @@ path = "main.rs" name = "bindgen" [dependencies] -bindgen = { path = "../bindgen", version = "=0.67.0", features = ["__cli", "experimental"] } +bindgen = { path = "../bindgen", version = "=0.68.0", features = ["__cli", "experimental"] } clap = { version = "4", features = ["derive"] } clap_complete = "4" env_logger = { version = "0.10.0", optional = true } diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index 87c2a4b317..336081148c 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -14,7 +14,7 @@ readme = "../README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.67.0" +version = "0.68.0" edition = "2018" build = "build.rs" # If you change this, also update README.md and msrv in .github/workflows/bindgen.yml From a21e60b5087edfe50d94093255122baae5697aea Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Wed, 6 Sep 2023 12:46:37 -0500 Subject: [PATCH 564/942] Release preparation for v0.68.1 (#2627) * Don't try to build anything that's not `bindgen-cli` with `cargo dist` * Update CHANGELOG.md * Remove duplicated table from manifest --- CHANGELOG.md | 88 ++++++++++++++++++++++++------------------ Cargo.toml | 3 ++ bindgen-cli/Cargo.toml | 3 ++ 3 files changed, 56 insertions(+), 38 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ab4bd440d..fa5af68580 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,11 +7,14 @@ - [Removed](#removed) - [Fixed](#fixed) - [Security](#security) -- [0.67.0](#0670) +- [0.68.1](#0681) + - [Fixed](#fixed-1) +- [0.68.0](#0680) - [Added](#added-1) - [Changed](#changed-1) - [Removed](#removed-1) - - [Fixed](#fixed-1) + - [Fixed](#fixed-2) +- [0.67.0](#0670) - [0.66.1](#0661) - [Removed](#removed-2) - [0.66.0](#0660) @@ -19,7 +22,7 @@ - [Changed](#changed-2) - [Removed](#removed-3) - [0.65.1](#0651) - - [Fixed](#fixed-2) + - [Fixed](#fixed-3) - [0.65.0](#0650) - [Added](#added-3) - [Changed](#changed-3) @@ -34,60 +37,60 @@ - [0.62.0](#0620) - [Added](#added-6) - [Changed](#changed-6) - - [Fixed](#fixed-3) + - [Fixed](#fixed-4) - [0.61.0](#0610) - [Added](#added-7) - [Changed](#changed-7) - - [Fixed](#fixed-4) -- [0.60.1](#0601) - [Fixed](#fixed-5) +- [0.60.1](#0601) + - [Fixed](#fixed-6) - [0.60.0](#0600) - [Added](#added-8) - - [Fixed](#fixed-6) + - [Fixed](#fixed-7) - [Changed](#changed-8) - [Removed](#removed-6) - [0.59.2](#0592) - [0.59.1](#0591) - - [Fixed](#fixed-7) + - [Fixed](#fixed-8) - [0.59.0](#0590) - [Added](#added-9) - - [Fixed](#fixed-8) + - [Fixed](#fixed-9) - [Changed](#changed-9) - [0.58.1](#0581) - [Added](#added-10) - [0.58.0](#0580) - [Added](#added-11) - - [Fixed](#fixed-9) + - [Fixed](#fixed-10) - [Changed](#changed-10) - [Deprecated](#deprecated) - [Removed](#removed-7) - - [Fixed](#fixed-10) + - [Fixed](#fixed-11) - [Security](#security-1) - [0.57.0](#0570) - [Added](#added-12) - - [Fixed](#fixed-11) + - [Fixed](#fixed-12) - [0.56.0](#0560) - [Added](#added-13) - [Changed](#changed-11) - - [Fixed](#fixed-12) -- [0.55.1](#0551) - [Fixed](#fixed-13) +- [0.55.1](#0551) + - [Fixed](#fixed-14) - [0.55.0](#0550) - [Removed](#removed-8) - [Added](#added-14) - [Changed](#changed-12) - - [Fixed](#fixed-14) + - [Fixed](#fixed-15) - [0.54.1](#0541) - [Added](#added-15) - [Changed](#changed-13) - - [Fixed](#fixed-15) + - [Fixed](#fixed-16) - [0.54.0](#0540) - [Added](#added-16) - [Changed](#changed-14) - - [Fixed](#fixed-16) + - [Fixed](#fixed-17) - [0.53.3](#0533) - [Added](#added-17) - - [Fixed](#fixed-17) + - [Fixed](#fixed-18) - [0.53.2](#0532) - [Changed](#changed-15) - [0.53.1](#0531) @@ -95,16 +98,16 @@ - [0.53.0](#0530) - [Added](#added-19) - [Changed](#changed-16) - - [Fixed](#fixed-18) + - [Fixed](#fixed-19) - [0.52.0](#0520) - [Added](#added-20) - [Changed](#changed-17) - - [Fixed](#fixed-19) -- [0.51.1](#0511) - [Fixed](#fixed-20) +- [0.51.1](#0511) + - [Fixed](#fixed-21) - [Changed](#changed-18) - [0.51.0](#0510) - - [Fixed](#fixed-21) + - [Fixed](#fixed-22) - [Changed](#changed-19) - [Added](#added-21) - [0.50.0](#0500) @@ -114,60 +117,60 @@ - [0.49.2](#0492) - [Changed](#changed-20) - [0.49.1](#0491) - - [Fixed](#fixed-22) + - [Fixed](#fixed-23) - [Changed](#changed-21) - [0.49.0](#0490) - [Added](#added-24) - - [Fixed](#fixed-23) + - [Fixed](#fixed-24) - [Changed](#changed-22) - [0.48.1](#0481) - - [Fixed](#fixed-24) + - [Fixed](#fixed-25) - [0.48.0](#0480) - [Changed](#changed-23) - - [Fixed](#fixed-25) + - [Fixed](#fixed-26) - [0.47.4](#0474) - [Added](#added-25) - [0.47.3](#0473) - [Changed](#changed-24) - [0.47.2](#0472) - - [Fixed](#fixed-26) + - [Fixed](#fixed-27) - [0.47.1](#0471) - [Changed](#changed-25) - - [Fixed](#fixed-27) + - [Fixed](#fixed-28) - [0.47.0](#0470) - [Changed](#changed-26) - - [Fixed](#fixed-28) + - [Fixed](#fixed-29) - [0.33.1 .. 0.46.0](#0331--0460) - [Added](#added-26) - [Removed](#removed-9) - [Changed](#changed-27) - - [Fixed](#fixed-29) -- [0.33.1](#0331) - [Fixed](#fixed-30) +- [0.33.1](#0331) + - [Fixed](#fixed-31) - [0.33.0](#0330) - [0.32.2](#0322) - - [Fixed](#fixed-31) -- [0.32.1](#0321) - [Fixed](#fixed-32) +- [0.32.1](#0321) + - [Fixed](#fixed-33) - [0.32.0](#0320) - [Added](#added-27) - [Changed](#changed-28) - - [Fixed](#fixed-33) + - [Fixed](#fixed-34) - [0.31.0](#0310) - [Added](#added-28) - [Changed](#changed-29) - [Deprecated](#deprecated-1) - [Removed](#removed-10) - - [Fixed](#fixed-34) + - [Fixed](#fixed-35) - [0.30.0](#0300) - [Added](#added-29) - [Changed](#changed-30) - [Deprecated](#deprecated-2) - - [Fixed](#fixed-35) + - [Fixed](#fixed-36) - [0.29.0](#0290) - [Added](#added-30) - [Changed](#changed-31) - - [Fixed](#fixed-36) + - [Fixed](#fixed-37) @@ -180,7 +183,12 @@ ## Fixed ## Security -# 0.67.0 +# 0.68.1 + +## Fixed +- Fixed errors on the windows artifact build process. + +# 0.68.0 ## Added - The `system` ABI is now supported as an option for the `--override-abi` flag. @@ -204,6 +212,10 @@ Rust keyword that cannot be a raw identifier, such as: `self`, `crate`, `super` or `Self`. +# 0.67.0 + +This version was skipped due to some problems on the release workflow. + # 0.66.1 ## Removed diff --git a/Cargo.toml b/Cargo.toml index ea6da9aada..0c581d663d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,11 +29,14 @@ targets = [ "x86_64-pc-windows-msvc", "aarch64-apple-darwin", ] +# Don't compile any crate while building artifacts unless the crate's manifest has `dist = true` +dist = false # Config for 'cargo release' [workspace.metadata.release] shared-version = true # ensures published packages share the same version tag-name = "v{{version}}" +# Don't release any crate unless its manifest has `release = true` release = false # The profile that 'cargo dist' will build with diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index 070a1f0ad7..2a80aca05b 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -44,3 +44,6 @@ __testing_only_libclang_5 = ["bindgen/__testing_only_libclang_5"] [package.metadata.release] release = true + +[package.metadata.dist] +dist = true From 8d75a02bbb5c64e85e6ce62b57d52b7df9c61c79 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Wed, 6 Sep 2023 12:48:20 -0500 Subject: [PATCH 565/942] chore: Release --- Cargo.lock | 4 ++-- bindgen-cli/Cargo.toml | 4 ++-- bindgen/Cargo.toml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6d32325240..40cb0777cb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -23,7 +23,7 @@ dependencies = [ [[package]] name = "bindgen" -version = "0.68.0" +version = "0.68.1" dependencies = [ "annotate-snippets", "bitflags 2.2.1", @@ -45,7 +45,7 @@ dependencies = [ [[package]] name = "bindgen-cli" -version = "0.68.0" +version = "0.68.1" dependencies = [ "bindgen", "clap", diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index 2a80aca05b..72e231cf02 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -11,7 +11,7 @@ readme = "../README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.68.0" +version = "0.68.1" edition = "2018" rust-version = "1.64.0" @@ -20,7 +20,7 @@ path = "main.rs" name = "bindgen" [dependencies] -bindgen = { path = "../bindgen", version = "=0.68.0", features = ["__cli", "experimental"] } +bindgen = { path = "../bindgen", version = "=0.68.1", features = ["__cli", "experimental"] } clap = { version = "4", features = ["derive"] } clap_complete = "4" env_logger = { version = "0.10.0", optional = true } diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index 336081148c..d7b6df9f05 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -14,7 +14,7 @@ readme = "../README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.68.0" +version = "0.68.1" edition = "2018" build = "build.rs" # If you change this, also update README.md and msrv in .github/workflows/bindgen.yml From f7e120bb6d4a5fb941cfe96065a8d1d3d2bebda5 Mon Sep 17 00:00:00 2001 From: XXIV <13811862+thechampagne@users.noreply.github.com> Date: Thu, 7 Sep 2023 05:25:38 +0300 Subject: [PATCH 566/942] remove unnecessary heap allocation (#2628) --- bindgen/clang.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindgen/clang.rs b/bindgen/clang.rs index db239ebc77..3438bfa2c4 100644 --- a/bindgen/clang.rs +++ b/bindgen/clang.rs @@ -1820,7 +1820,7 @@ impl TranslationUnit { let fname = CString::new(file).unwrap(); let _c_args: Vec = cmd_args .iter() - .map(|s| CString::new(s.clone().into_boxed_bytes()).unwrap()) + .map(|s| CString::new(s.as_bytes()).unwrap()) .collect(); let c_args: Vec<*const c_char> = _c_args.iter().map(|s| s.as_ptr()).collect(); From e4c29ad09b21c87c07812f7a57c4f321e213e8cc Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Wed, 6 Sep 2023 21:43:28 -0500 Subject: [PATCH 567/942] Fix typo in cfg attribute (#2629) --- bindgen/options/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindgen/options/mod.rs b/bindgen/options/mod.rs index 558f5343a2..3a82bcf397 100644 --- a/bindgen/options/mod.rs +++ b/bindgen/options/mod.rs @@ -1374,7 +1374,7 @@ options! { /// or `-fno-inline-functions` if you are responsible of compiling the library to make /// them callable. #[cfg_attr( - features = "experimental", + feature = "experimental", doc = "\nCheck the [`Builder::wrap_static_fns`] method for an alternative." )] pub fn generate_inline_functions(mut self, doit: bool) -> Self { From 53c01d222b9e7e7a914898ef12247515247dff83 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Mon, 11 Sep 2023 23:41:28 +0200 Subject: [PATCH 568/942] changelog: automatically populate version and date when releasing (#2635) --- Cargo.toml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 0c581d663d..370828da55 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,6 +39,12 @@ tag-name = "v{{version}}" # Don't release any crate unless its manifest has `release = true` release = false +# Add version and date to changelog file +[[workspace.metadata.release.pre-release-replacements]] +file = "CHANGELOG.md" +search = "# Unreleased" +replace = "# {{version}} ({{date}})" + # The profile that 'cargo dist' will build with [profile.dist] inherits = "release" From 1a09f450c874d57883f56a7a0c298be5db183569 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Mon, 11 Sep 2023 16:48:04 -0500 Subject: [PATCH 569/942] Use void in parameterless functions (#2633) * Use void for parameterless function arguments * Update tests * Update CHANGELOG.md --- CHANGELOG.md | 2 ++ .../tests/generated/wrap_static_fns.c | 1 + .../expectations/tests/wrap-static-fns.rs | 6 ++++ bindgen-tests/tests/headers/wrap-static-fns.h | 4 +++ bindgen/codegen/serialize.rs | 35 +++++++++++-------- 5 files changed, 33 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fa5af68580..9b536800fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -179,6 +179,8 @@ ## Added ## Changed +- The `--wrap-static-fns` feature was updated so function types that has no + argument use `void` as its sole argument. ## Removed ## Fixed ## Security diff --git a/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c b/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c index cf1106ec76..a8fd5045d2 100644 --- a/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c +++ b/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c @@ -11,6 +11,7 @@ int takes_alias__extern(func f) { return takes_alias(f); } int takes_qualified__extern(const int *const *arg) { return takes_qualified(arg); } enum foo takes_enum__extern(const enum foo f) { return takes_enum(f); } void nevermore__extern(void) { nevermore(); } +int takes_fn_with_no_args__extern(int (f) (void)) { return takes_fn_with_no_args(f); } void no_extra_argument__extern(__builtin_va_list va) { no_extra_argument(va); } int many_va_list__extern(int i, __builtin_va_list va1, __builtin_va_list va2) { return many_va_list(i, va1, va2); } int wrap_as_variadic_fn1__extern(int i, ...) { diff --git a/bindgen-tests/tests/expectations/tests/wrap-static-fns.rs b/bindgen-tests/tests/expectations/tests/wrap-static-fns.rs index 03f3907ed2..46b369b2f4 100644 --- a/bindgen-tests/tests/expectations/tests/wrap-static-fns.rs +++ b/bindgen-tests/tests/expectations/tests/wrap-static-fns.rs @@ -50,6 +50,12 @@ extern "C" { #[link_name = "nevermore__extern"] pub fn nevermore(); } +extern "C" { + #[link_name = "takes_fn_with_no_args__extern"] + pub fn takes_fn_with_no_args( + f: ::std::option::Option ::std::os::raw::c_int>, + ) -> ::std::os::raw::c_int; +} extern "C" { #[link_name = "no_extra_argument__extern"] pub fn no_extra_argument(va: *mut __va_list_tag); diff --git a/bindgen-tests/tests/headers/wrap-static-fns.h b/bindgen-tests/tests/headers/wrap-static-fns.h index 8dcabe7b30..131b7ab15f 100644 --- a/bindgen-tests/tests/headers/wrap-static-fns.h +++ b/bindgen-tests/tests/headers/wrap-static-fns.h @@ -52,6 +52,10 @@ static inline void nevermore() { while (1) { } } +static inline int takes_fn_with_no_args(int(f)(void)) { + return f(); +} + static inline int variadic(int x, ...) { return x; } diff --git a/bindgen/codegen/serialize.rs b/bindgen/codegen/serialize.rs index 58e0882faf..02c4680263 100644 --- a/bindgen/codegen/serialize.rs +++ b/bindgen/codegen/serialize.rs @@ -322,21 +322,26 @@ impl<'a> CSerialize<'a> for Type { } write!(writer, ")")?; - write!(writer, " (")?; - serialize_sep( - ", ", - signature.argument_types().iter(), - ctx, - writer, - |(name, type_id), ctx, buf| { - let mut stack = vec![]; - if let Some(name) = name { - stack.push(name.clone()); - } - type_id.serialize(ctx, (), &mut stack, buf) - }, - )?; - write!(writer, ")")? + let args = signature.argument_types(); + if args.is_empty() { + write!(writer, " (void)")?; + } else { + write!(writer, " (")?; + serialize_sep( + ", ", + args.iter(), + ctx, + writer, + |(name, type_id), ctx, buf| { + let mut stack = vec![]; + if let Some(name) = name { + stack.push(name.clone()); + } + type_id.serialize(ctx, (), &mut stack, buf) + }, + )?; + write!(writer, ")")? + } } TypeKind::ResolvedTypeRef(type_id) => { if self.is_const() { From 35924dac31b489f09153565442e06a6d859fc20d Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Tue, 12 Sep 2023 22:32:29 +0200 Subject: [PATCH 570/942] make some improvements to contribution guide (#2634) * creating a release requires just 1 command * improve release documentation * update toc * fix anchor link * fix grammar * we should not need nightly r-a anymore * typo * has since moved to github actions * mention active maintainer * Revert "we should not need nightly r-a anymore" This reverts commit a812e77f9853add6aff4305cfa7544149d37e7aa. I missed that this is r-a setting requiring a nightly rustfmt, not r-a itself needing to be nightly. --- CONTRIBUTING.md | 53 +++++++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e6439e1262..25cad1e9bd 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -35,9 +35,9 @@ and introduce yourself. - [Writing a Predicate Script](#writing-a-predicate-script) - [Cutting a new bindgen release](#cutting-a-new-bindgen-release) - [Updating the changelog](#updating-the-changelog) - - [Bumping the version numbers.](#bumping-the-version-numbers) - [Merge to `main`](#merge-to-main) - - [Publish and add a git tag for the right commit](#publish-and-add-a-git-tag-for-the-right-commit) + - [Tag and publish](#tag-and-publish) + - [Create a new release on GitHub](create-a-new-relese-on-github) @@ -56,7 +56,7 @@ issue, provide us with: * The `bindgen` flags used to reproduce the issue with the header file * The expected `bindgen` output * The actual `bindgen` output -* The [debugging logs](#logs) generated when running `bindgen` on this testcase +* The [debugging logs](#debug-logging) generated when running `bindgen` on this testcase ## Looking to Start Contributing to `bindgen`? @@ -69,7 +69,8 @@ issue, provide us with: ### `rustfmt` / `cargo fmt` -We use `nightly` channel for `rustfmt` so please set the appropriate setting your editor/IDE for that. +We use `nightly` channel for `rustfmt`, +so please set the appropriate setting in your editor/IDE for that. For rust-analyzer, you can set `rustfmt.extraArgs = ['+nightly']`. @@ -212,8 +213,8 @@ add each of: If you need to update the test expectations for a test file that generates different bindings for different `libclang` versions, you *don't* need to have -many version of `libclang` installed locally. Just make a work-in-progress pull -request, and then when Travis CI fails, it will log a diff of the +many versions of `libclang` installed locally. Just make a work-in-progress pull +request, and then when CI fails, it will log a diff of the expectations. Use the diff to patch the appropriate expectation file locally and then update your pull request. @@ -355,7 +356,7 @@ changes should be squashed into the original commit. Unsure who to ask for review? Ask any of: * `@emilio` -* `@fitzgen` +* `@pvdrz` More resources: @@ -552,42 +553,38 @@ $ npm install doctoc $ ./node_modules/doctoc/doctoc.js CHANGELOG.md ``` -### Bumping the version numbers - -Use `cargo release` (from `cargo install cargo-release`) to automate things: - -- For a feature release, `cargo release minor --execute` (will bump v0.62.1 to v0.63.0) -- For a patch release, `cargo release patch --execute` (will bump v0.63.0 to v0.63.1) - -Run tests just to ensure everything is working as expected. - ### Merge to `main` For regular releases, the changes above should end up in `main` before publishing. For dot-releases of an old version (e.g., cherry-picking an important fix) you can skip this. -### Publish and add a git tag for the right commit +### Tag and publish -Once you're in the right commit, do: +Once you're in the right branch, do: ``` cargo release [patch|minor] --execute -cargo release --execute ``` -This does the equivalent of the following: +This does the following: -``` -$ git tag -a v0.62.1 # With the right version of course -$ pushd bindgen && cargo publish && popd -$ pushd bindgen-cli && cargo publish && popd -$ git push --tags upstream # To publish the tag -``` +- Tag (`git tag`) the HEAD commit +- Publish (`cargo publish`) bindgen and bindgen-cli +- Push (`git push`) to GitHub + +The `patch` and `minor` refer to semver concepts: + +- `patch` would bump __v0.68.1__ to __v0.68.2__ +- `feature` would bump __v0.68.2__ to __v0.69.0__ ### Create a new release on Github -The release will be automated with the help of `.github/workflows/release.yml`, -and will only be created when all tests succeed. +The release is automated with the help of `.github/workflows/release.yml`, +and will only be created... + +- when a Git tag is pushed +- when all tests succeed + While the tests are still running, a draft GitHub release will be created, to avoid notifying watchers of the repo should a CI step fail. From b43ab103baf4cbb24b20604d5abd7123ea52e207 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Tue, 12 Sep 2023 22:32:45 +0200 Subject: [PATCH 571/942] please clippy (#2639) * please clippy * fmt --- bindgen/ir/analysis/mod.rs | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/bindgen/ir/analysis/mod.rs b/bindgen/ir/analysis/mod.rs index 0263088a99..443384a487 100644 --- a/bindgen/ir/analysis/mod.rs +++ b/bindgen/ir/analysis/mod.rs @@ -334,20 +334,13 @@ mod tests { // Yes, what follows is a **terribly** inefficient set union // implementation. Don't copy this code outside of this test! - let original_size = self - .reachable - .entry(node) - .or_insert_with(HashSet::default) - .len(); + let original_size = self.reachable.entry(node).or_default().len(); for sub_node in self.graph.0[&node].iter() { self.reachable.get_mut(&node).unwrap().insert(*sub_node); - let sub_reachable = self - .reachable - .entry(*sub_node) - .or_insert_with(HashSet::default) - .clone(); + let sub_reachable = + self.reachable.entry(*sub_node).or_default().clone(); for transitive in sub_reachable { self.reachable.get_mut(&node).unwrap().insert(transitive); From a960d9767b58c535f2e447feffcad0adc000207e Mon Sep 17 00:00:00 2001 From: baul Date: Wed, 20 Sep 2023 01:27:30 +0800 Subject: [PATCH 572/942] Fix bindgen-cli support link static libclang (#2644) * Fix bindgen-cli support link static libclang * Update CHANGELOG.md --------- Co-authored-by: Christian Poveda --- CHANGELOG.md | 1 + bindgen-cli/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b536800fe..c4d8294afe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -183,6 +183,7 @@ argument use `void` as its sole argument. ## Removed ## Fixed +- Allow compiling `bindgen-cli` with a static libclang. ## Security # 0.68.1 diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index 72e231cf02..07e7786113 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -20,7 +20,7 @@ path = "main.rs" name = "bindgen" [dependencies] -bindgen = { path = "../bindgen", version = "=0.68.1", features = ["__cli", "experimental"] } +bindgen = { path = "../bindgen", version = "=0.68.1", default-features = false, features = ["__cli", "experimental"] } clap = { version = "4", features = ["derive"] } clap_complete = "4" env_logger = { version = "0.10.0", optional = true } From 4f8709f8653b54c481653e5fbff213cae0dde53f Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Tue, 19 Sep 2023 12:46:24 -0500 Subject: [PATCH 573/942] Check pointer size and emit opaque type if required (#2637) * Check size of pointer types * Test that `__ptr32` is emitted as `u32` * Update CHANGELOG.md * Add expectation with raw pointer for clang 5 * Add expectation with raw pointer for clang 9 * Remove extra line --- CHANGELOG.md | 2 + .../libclang-5/ptr32-has-different-size.rs | 41 +++++++++++++++++++ .../libclang-9/ptr32-has-different-size.rs | 41 +++++++++++++++++++ .../tests/ptr32-has-different-size.rs | 41 +++++++++++++++++++ .../tests/headers/ptr32-has-different-size.h | 4 ++ bindgen/codegen/error.rs | 19 +++++++-- bindgen/codegen/mod.rs | 11 +++++ 7 files changed, 155 insertions(+), 4 deletions(-) create mode 100644 bindgen-tests/tests/expectations/tests/libclang-5/ptr32-has-different-size.rs create mode 100644 bindgen-tests/tests/expectations/tests/libclang-9/ptr32-has-different-size.rs create mode 100644 bindgen-tests/tests/expectations/tests/ptr32-has-different-size.rs create mode 100644 bindgen-tests/tests/headers/ptr32-has-different-size.h diff --git a/CHANGELOG.md b/CHANGELOG.md index c4d8294afe..2071cc2370 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -184,6 +184,8 @@ ## Removed ## Fixed - Allow compiling `bindgen-cli` with a static libclang. +- Emit an opaque integer type for pointer types that don't have the same size + as the target's pointer size. ## Security # 0.68.1 diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/ptr32-has-different-size.rs b/bindgen-tests/tests/expectations/tests/libclang-5/ptr32-has-different-size.rs new file mode 100644 index 0000000000..0d677052ea --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/libclang-5/ptr32-has-different-size.rs @@ -0,0 +1,41 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct TEST_STRUCT { + pub ptr_32bit: *mut ::std::os::raw::c_void, +} +#[test] +fn bindgen_test_layout_TEST_STRUCT() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(TEST_STRUCT)), + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(TEST_STRUCT)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).ptr_32bit) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(TEST_STRUCT), + "::", + stringify!(ptr_32bit), + ), + ); +} +impl Default for TEST_STRUCT { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +pub type TEST = TEST_STRUCT; diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/ptr32-has-different-size.rs b/bindgen-tests/tests/expectations/tests/libclang-9/ptr32-has-different-size.rs new file mode 100644 index 0000000000..0d677052ea --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/libclang-9/ptr32-has-different-size.rs @@ -0,0 +1,41 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct TEST_STRUCT { + pub ptr_32bit: *mut ::std::os::raw::c_void, +} +#[test] +fn bindgen_test_layout_TEST_STRUCT() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(TEST_STRUCT)), + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(TEST_STRUCT)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).ptr_32bit) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(TEST_STRUCT), + "::", + stringify!(ptr_32bit), + ), + ); +} +impl Default for TEST_STRUCT { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +pub type TEST = TEST_STRUCT; diff --git a/bindgen-tests/tests/expectations/tests/ptr32-has-different-size.rs b/bindgen-tests/tests/expectations/tests/ptr32-has-different-size.rs new file mode 100644 index 0000000000..bdcc170af7 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/ptr32-has-different-size.rs @@ -0,0 +1,41 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct TEST_STRUCT { + pub ptr_32bit: u32, +} +#[test] +fn bindgen_test_layout_TEST_STRUCT() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(TEST_STRUCT)), + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(TEST_STRUCT)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).ptr_32bit) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(TEST_STRUCT), + "::", + stringify!(ptr_32bit), + ), + ); +} +impl Default for TEST_STRUCT { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +pub type TEST = TEST_STRUCT; diff --git a/bindgen-tests/tests/headers/ptr32-has-different-size.h b/bindgen-tests/tests/headers/ptr32-has-different-size.h new file mode 100644 index 0000000000..8cda702c53 --- /dev/null +++ b/bindgen-tests/tests/headers/ptr32-has-different-size.h @@ -0,0 +1,4 @@ +// bindgen-flags: -- -fms-extensions +typedef struct TEST_STRUCT { + void* __ptr32 ptr_32bit; +} TEST; diff --git a/bindgen/codegen/error.rs b/bindgen/codegen/error.rs index 2c9bf97680..82e921d771 100644 --- a/bindgen/codegen/error.rs +++ b/bindgen/codegen/error.rs @@ -14,25 +14,36 @@ pub(crate) enum Error { /// Function ABI is not supported. UnsupportedAbi(&'static str), + + /// The pointer type size does not match the target's pointer size. + InvalidPointerSize { + ty_name: String, + ty_size: usize, + ptr_size: usize, + }, } impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.write_str(match *self { + match self { Error::NoLayoutForOpaqueBlob => { - "Tried to generate an opaque blob, but had no layout." + "Tried to generate an opaque blob, but had no layout.".fmt(f) } Error::InstantiationOfOpaqueType => { "Instantiation of opaque template type or partial template specialization." + .fmt(f) } Error::UnsupportedAbi(abi) => { - return write!( + write!( f, "{} ABI is not supported by the configured Rust target.", abi ) } - }) + Error::InvalidPointerSize { ty_name, ty_size, ptr_size } => { + write!(f, "The {} pointer type has size {} but the current target's pointer size is {}.", ty_name, ty_size, ptr_size) + } + } } } diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index bc8e3ec711..8e13606345 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -21,6 +21,7 @@ use self::struct_layout::StructLayoutTracker; use super::BindgenOptions; use crate::callbacks::{DeriveInfo, FieldInfo, TypeKind as DeriveTypeKind}; +use crate::codegen::error::Error; use crate::ir::analysis::{HasVtable, Sizedness}; use crate::ir::annotations::{ Annotations, FieldAccessorKind, FieldVisibilityKind, @@ -3923,6 +3924,16 @@ impl TryToRustTy for Type { } TypeKind::Opaque => self.try_to_opaque(ctx, item), TypeKind::Pointer(inner) | TypeKind::Reference(inner) => { + // Check that this type has the same size as the target's pointer type. + let size = self.get_layout(ctx, item).size; + if size != ctx.target_pointer_size() { + return Err(Error::InvalidPointerSize { + ty_name: self.name().unwrap_or("unknown").into(), + ty_size: size, + ptr_size: ctx.target_pointer_size(), + }); + } + let is_const = ctx.resolve_type(inner).is_const(); let inner = From 8b884ea63e55ec3e90ae6b905bbbf180d5a2691d Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Wed, 27 Sep 2023 11:23:23 -0500 Subject: [PATCH 574/942] Don't escape objective-c method names (#2648) * Don't escape objective-c method names * Still escape `crate`, `self`, and the like * Don't escape keywords if they are method names * Update tests * Update CHANGELOG.md --- CHANGELOG.md | 2 ++ .../tests/expectations/tests/objc_escape.rs | 30 +++++++++++++++++++ bindgen-tests/tests/headers/objc_escape.h | 6 ++++ bindgen/ir/objc.rs | 17 +++++++++-- 4 files changed, 53 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2071cc2370..3a43bd966f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -186,6 +186,8 @@ - Allow compiling `bindgen-cli` with a static libclang. - Emit an opaque integer type for pointer types that don't have the same size as the target's pointer size. +- Avoid escaping Objective-C method names unless they are `Self`, `self`, + `crate` or `super`. ## Security # 0.68.1 diff --git a/bindgen-tests/tests/expectations/tests/objc_escape.rs b/bindgen-tests/tests/expectations/tests/objc_escape.rs index abf8df602d..1351231d62 100644 --- a/bindgen-tests/tests/expectations/tests/objc_escape.rs +++ b/bindgen-tests/tests/expectations/tests/objc_escape.rs @@ -33,3 +33,33 @@ pub trait IA: Sized + std::ops::Deref { msg_send!(* self, crate_ : self_) } } +#[repr(transparent)] +#[derive(Debug, Copy, Clone)] +pub struct B(pub id); +impl std::ops::Deref for B { + type Target = objc::runtime::Object; + fn deref(&self) -> &Self::Target { + unsafe { &*self.0 } + } +} +unsafe impl objc::Message for B {} +impl B { + pub fn alloc() -> Self { + Self(unsafe { msg_send!(class!(B), alloc) }) + } +} +impl IB for B {} +pub trait IB: Sized + std::ops::Deref { + unsafe fn type_(&self) -> id + where + ::Target: objc::Message + Sized, + { + msg_send!(* self, type) + } + unsafe fn setType_(&self, type_: id) + where + ::Target: objc::Message + Sized, + { + msg_send!(* self, setType : type_) + } +} diff --git a/bindgen-tests/tests/headers/objc_escape.h b/bindgen-tests/tests/headers/objc_escape.h index 6b52e745be..2d21bd5481 100644 --- a/bindgen-tests/tests/headers/objc_escape.h +++ b/bindgen-tests/tests/headers/objc_escape.h @@ -5,3 +5,9 @@ -(void)f:(int)arg1 as:(int)arg2; -(void)crate:(int)self; @end + +@interface B + +@property(nonatomic, retain) id type; + +@end diff --git a/bindgen/ir/objc.rs b/bindgen/ir/objc.rs index 2ebf38b8ca..93d8b3bfdf 100644 --- a/bindgen/ir/objc.rs +++ b/bindgen/ir/objc.rs @@ -253,11 +253,24 @@ impl ObjCMethod { let split_name: Vec> = self .name .split(':') - .map(|name| { + .enumerate() + .map(|(idx, name)| { if name.is_empty() { None + } else if idx == 0 { + // Try to parse the method name as an identifier. Having a keyword is ok + // unless it is `crate`, `self`, `super` or `Self`, so we try to add the `_` + // suffix to it and parse it. + if ["crate", "self", "super", "Self"].contains(&name) { + Some(Ident::new( + &format!("{}_", name), + Span::call_site(), + )) + } else { + Some(Ident::new(name, Span::call_site())) + } } else { - // Try to parse the current name as an identifier. This might fail if the name + // Try to parse the current joining name as an identifier. This might fail if the name // is a keyword, so we try to "r#" to it and parse again, this could also fail // if the name is `crate`, `self`, `super` or `Self`, so we try to add the `_` // suffix to it and parse again. If this also fails, we panic with the first From b72bf154e5c3f7c2abbbe06d48c59f4e4dd175d7 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Mon, 2 Oct 2023 15:09:25 -0500 Subject: [PATCH 575/942] Remove windows binary from releases (#2655) --- .github/workflows/release.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e0631ca88a..5bcdd7b458 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -101,9 +101,6 @@ jobs: - os: "macos-11" dist-args: "--artifacts=local --target=x86_64-apple-darwin" install-dist: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.2.0/cargo-dist-installer.sh | sh" - - os: "windows-2019" - dist-args: "--artifacts=local --target=x86_64-pc-windows-msvc" - install-dist: "irm https://github.com/axodotdev/cargo-dist/releases/download/v0.2.0/cargo-dist-installer.ps1 | iex" - os: "ubuntu-20.04" dist-args: "--artifacts=local --target=x86_64-unknown-linux-gnu" install-dist: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.2.0/cargo-dist-installer.sh | sh" From 795d900ed659c07518e2c456006893713fc1ee2b Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Mon, 2 Oct 2023 15:23:53 -0500 Subject: [PATCH 576/942] Introduce `ParseCallbacks::header_file` (#2653) * Add `ParseCallbacks::input_file` * Make `CargoCallbacks` configurable * Use the `input_file` callback with every header * Fix docs * Rename callback to `header_file` for clarity * Update CHANGELOG.md * Run rustfmt --- CHANGELOG.md | 10 +++++++++ bindgen/callbacks.rs | 3 +++ bindgen/lib.rs | 52 +++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a43bd966f..9149d45d40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -178,9 +178,19 @@ # Unreleased ## Added +- Added the `ParseCallbacks::header_file` callback which runs on every filename passed to `Builder::header`. +- Added the `CargoCallbacks::new` constructor which emits a cargo-rerun line + for every input header file by default. +- Added the `CargoCallbacks::rerun_on_header_files` method to configure whether + a cargo-rerun line should be emitted for every input header file. ## Changed - The `--wrap-static-fns` feature was updated so function types that has no argument use `void` as its sole argument. +- `CargoCallbacks` is no longer a [unit-like + struct](https://doc.rust-lang.org/reference/items/structs.html) and the + `CargoCallbacks` constant was added to mitigate the breaking nature of this + change. This constant has been marked as deprecated and users will have to + use the new `CargoCallbacks::new` method in the future. ## Removed ## Fixed - Allow compiling `bindgen-cli` with a static libclang. diff --git a/bindgen/callbacks.rs b/bindgen/callbacks.rs index a9d315dca7..c22ba975dd 100644 --- a/bindgen/callbacks.rs +++ b/bindgen/callbacks.rs @@ -99,6 +99,9 @@ pub trait ParseCallbacks: fmt::Debug { None } + /// This will be called on every header filename passed to (`Builder::header`)[`crate::Builder::header`]. + fn header_file(&self, _filename: &str) {} + /// This will be called on every file inclusion, with the full path of the included file. fn include_file(&self, _filename: &str) {} diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 05f95bf8f5..54348e2232 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -325,6 +325,11 @@ impl Builder { .map(String::into_boxed_str), ); + for header in &self.options.input_headers { + self.options + .for_each_callback(|cb| cb.header_file(header.as_ref())); + } + // Transform input headers to arguments on the clang command line. self.options.clang_args.extend( self.options.input_headers @@ -566,6 +571,10 @@ impl BindgenOptions { .collect() } + fn for_each_callback(&self, f: impl Fn(&dyn callbacks::ParseCallbacks)) { + self.parse_callbacks.iter().for_each(|cb| f(cb.as_ref())); + } + fn process_comment(&self, comment: &str) -> String { let comment = comment::preprocess(comment); self.parse_callbacks @@ -1232,9 +1241,50 @@ fn get_target_dependent_env_var( /// .generate(); /// ``` #[derive(Debug)] -pub struct CargoCallbacks; +pub struct CargoCallbacks { + rerun_on_header_files: bool, +} + +/// Create a new `CargoCallbacks` value with [`CargoCallbacks::rerun_on_header_files`] disabled. +/// +/// This constructor has been deprecated in favor of [`CargoCallbacks::new`] where +/// [`CargoCallbacks::rerun_on_header_files`] is enabled by default. +#[deprecated = "Use `CargoCallbacks::new()` instead. Please, check the documentation for further information."] +pub const CargoCallbacks: CargoCallbacks = CargoCallbacks { + rerun_on_header_files: false, +}; + +impl CargoCallbacks { + /// Create a new `CargoCallbacks` value. + pub fn new() -> Self { + Self { + rerun_on_header_files: true, + } + } + + /// Whether Cargo should re-run the build script if any of the input header files has changed. + /// + /// This option is enabled by default unless the deprecated [`const@CargoCallbacks`] + /// constructor is used. + pub fn rerun_on_header_files(mut self, doit: bool) -> Self { + self.rerun_on_header_files = doit; + self + } +} + +impl Default for CargoCallbacks { + fn default() -> Self { + Self::new() + } +} impl callbacks::ParseCallbacks for CargoCallbacks { + fn header_file(&self, filename: &str) { + if self.rerun_on_header_files { + println!("cargo:rerun-if-changed={}", filename); + } + } + fn include_file(&self, filename: &str) { println!("cargo:rerun-if-changed={}", filename); } From 7b9567394e2ba7d76341746db36133da31e3b682 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Tue, 3 Oct 2023 16:06:41 -0500 Subject: [PATCH 577/942] Let clap handle all CLI parsing errors (#2656) This PR removes some ad-hoc error propagation that the CLI parser had for more sophisticated arguments and just uses `clap::Error` for everything. --- bindgen-cli/options.rs | 168 ++++++++++++++++++++++------------------- 1 file changed, 92 insertions(+), 76 deletions(-) diff --git a/bindgen-cli/options.rs b/bindgen-cli/options.rs index b6ff059da2..d52ccb8e89 100644 --- a/bindgen-cli/options.rs +++ b/bindgen-cli/options.rs @@ -1,13 +1,14 @@ use bindgen::callbacks::TypeKind; use bindgen::{ - builder, AliasVariation, Builder, CodegenConfig, EnumVariation, + builder, Abi, AliasVariation, Builder, CodegenConfig, EnumVariation, FieldVisibilityKind, Formatter, MacroTypeVariation, NonCopyUnionStyle, RegexSet, RustTarget, DEFAULT_ANON_FIELDS_PREFIX, RUST_TARGET_STRINGS, }; +use clap::error::{Error, ErrorKind}; use clap::{CommandFactory, Parser}; use std::fs::File; -use std::io::{self, Error, ErrorKind}; -use std::path::PathBuf; +use std::io; +use std::path::{Path, PathBuf}; use std::process::exit; fn rust_target_help() -> String { @@ -18,7 +19,9 @@ fn rust_target_help() -> String { ) } -fn parse_codegen_config(what_to_generate: &str) -> io::Result { +fn parse_codegen_config( + what_to_generate: &str, +) -> Result { let mut config = CodegenConfig::empty(); for what in what_to_generate.split(',') { match what { @@ -29,9 +32,9 @@ fn parse_codegen_config(what_to_generate: &str) -> io::Result { "constructors" => config.insert(CodegenConfig::CONSTRUCTORS), "destructors" => config.insert(CodegenConfig::DESTRUCTORS), otherwise => { - return Err(Error::new( - ErrorKind::Other, - format!("Unknown generate item: {}", otherwise), + return Err(Error::raw( + ErrorKind::InvalidValue, + format!("Unknown codegen item kind: {}", otherwise), )); } } @@ -40,20 +43,64 @@ fn parse_codegen_config(what_to_generate: &str) -> io::Result { Ok(config) } +fn parse_rustfmt_config_path(path_str: &str) -> Result { + let path = Path::new(path_str); + + if !path.is_absolute() { + return Err(Error::raw( + ErrorKind::InvalidValue, + "--rustfmt-configuration-file needs to be an absolute path!", + )); + } + + if path.to_str().is_none() { + return Err(Error::raw( + ErrorKind::InvalidUtf8, + "--rustfmt-configuration-file contains non-valid UTF8 characters.", + )); + } + + Ok(path.to_path_buf()) +} + +fn parse_abi_override(abi_override: &str) -> Result<(Abi, String), Error> { + let (regex, abi_str) = abi_override + .rsplit_once('=') + .ok_or_else(|| Error::raw(ErrorKind::InvalidValue, "Missing `=`"))?; + + let abi = abi_str + .parse() + .map_err(|err| Error::raw(ErrorKind::InvalidValue, err))?; + + Ok((abi, regex.to_owned())) +} + +fn parse_custom_derive( + custom_derive: &str, +) -> Result<(Vec, String), Error> { + let (regex, derives) = custom_derive + .rsplit_once('=') + .ok_or_else(|| Error::raw(ErrorKind::InvalidValue, "Missing `=`"))?; + + let derives = derives.split(',').map(|s| s.to_owned()).collect(); + + Ok((derives, regex.to_owned())) +} + #[derive(Parser, Debug)] #[clap( about = "Generates Rust bindings from C/C++ headers.", - override_usage = "bindgen [FLAGS] [OPTIONS] [HEADER] -- [CLANG_ARGS]...", + override_usage = "bindgen
-- ...", trailing_var_arg = true )] struct BindgenCommand { /// C or C++ header file. - header: Option, + header: String, /// Path to write depfile to. #[arg(long)] depfile: Option, - /// The default style of code used to generate enums. - #[arg(long, value_name = "VARIANT")] + /// The default STYLE of code used to generate enums. + #[arg(long, value_name = "STYLE")] default_enum_style: Option, /// Mark any enum whose name matches REGEX as a set of bitfield flags. #[arg(long, value_name = "REGEX")] @@ -73,11 +120,11 @@ struct BindgenCommand { /// Mark any enum whose name matches REGEX as a module of constants. #[arg(long, value_name = "REGEX")] constified_enum_module: Vec, - /// The default signed/unsigned type for C macro constants. - #[arg(long, value_name = "VARIANT")] + /// The default signed/unsigned TYPE for C macro constants. + #[arg(long, value_name = "TYPE")] default_macro_constant_type: Option, - /// The default style of code used to generate typedefs. - #[arg(long, value_name = "VARIANT")] + /// The default STYLE of code used to generate typedefs. + #[arg(long, value_name = "STYLE")] default_alias_style: Option, /// Mark any typedef alias whose name matches REGEX to use normal type aliasing. #[arg(long, value_name = "REGEX")] @@ -88,7 +135,7 @@ struct BindgenCommand { /// Mark any typedef alias whose name matches REGEX to have a new type with Deref and DerefMut to the inner type. #[arg(long, value_name = "REGEX")] new_type_alias_deref: Vec, - /// The default style of code used to generate unions with non-Copy members. Note that ManuallyDrop was first stabilized in Rust 1.20.0. + /// The default STYLE of code used to generate unions with non-Copy members. Note that ManuallyDrop was first stabilized in Rust 1.20.0. #[arg(long, value_name = "STYLE")] default_non_copy_union_style: Option, /// Mark any union whose name matches REGEX and who has a non-Copy member to use a bindgen-generated wrapper for fields. @@ -169,10 +216,10 @@ struct BindgenCommand { /// Output bindings for builtin definitions, e.g. __builtin_va_list. #[arg(long)] builtins: bool, - /// Use the given prefix before raw types instead of ::std::os::raw. + /// Use the given PREFIX before raw types instead of ::std::os::raw. #[arg(long, value_name = "PREFIX")] ctypes_prefix: Option, - /// Use the given prefix for anonymous fields. + /// Use the given PREFIX for anonymous fields. #[arg(long, default_value = DEFAULT_ANON_FIELDS_PREFIX, value_name = "PREFIX")] anon_fields_prefix: String, /// Time the different bindgen phases and print to stderr @@ -184,7 +231,7 @@ struct BindgenCommand { /// Output our internal IR for debugging purposes. #[arg(long)] emit_ir: bool, - /// Dump graphviz dot file. + /// Dump a graphviz dot file to PATH. #[arg(long, value_name = "PATH")] emit_ir_graphviz: Option, /// Enable support for C++ namespaces. @@ -232,8 +279,8 @@ struct BindgenCommand { /// Add a raw line of Rust code at the beginning of output. #[arg(long)] raw_line: Vec, - /// Add a raw line of Rust code to a given module. - #[arg(long, number_of_values = 2, value_names = ["MODULE-NAME", "RAW-LINE"])] + /// Add a RAW_LINE of Rust code to a given module with name MODULE_NAME. + #[arg(long, number_of_values = 2, value_names = ["MODULE_NAME", "RAW_LINE"])] module_raw_line: Vec, #[arg(long, help = rust_target_help())] rust_target: Option, @@ -277,16 +324,16 @@ struct BindgenCommand { /// `--formatter=none` instead. #[arg(long)] no_rustfmt_bindings: bool, - /// Which tool should be used to format the bindings + /// Which FORMATTER should be used for the bindings #[arg( long, value_name = "FORMATTER", conflicts_with = "no_rustfmt_bindings" )] formatter: Option, - /// The absolute path to the rustfmt configuration file. The configuration file will be used for formatting the bindings. This parameter sets `formatter` to `rustfmt`. - #[arg(long, value_name = "PATH", conflicts_with = "no_rustfmt_bindings")] - rustfmt_configuration_file: Option, + /// The absolute PATH to the rustfmt configuration file. The configuration file will be used for formatting the bindings. This parameter sets `formatter` to `rustfmt`. + #[arg(long, value_name = "PATH", conflicts_with = "no_rustfmt_bindings", value_parser=parse_rustfmt_config_path)] + rustfmt_configuration_file: Option, /// Avoid deriving PartialEq for types matching REGEX. #[arg(long, value_name = "REGEX")] no_partialeq: Vec, @@ -311,10 +358,10 @@ struct BindgenCommand { /// Use `*const [T; size]` instead of `*const T` for C arrays #[arg(long)] use_array_pointers_in_arguments: bool, - /// The name to be used in a #[link(wasm_import_module = ...)] statement + /// The NAME to be used in a #[link(wasm_import_module = ...)] statement #[arg(long, value_name = "NAME")] wasm_import_module_name: Option, - /// Use dynamic loading mode with the given library name. + /// Use dynamic loading mode with the given library NAME. #[arg(long, value_name = "NAME")] dynamic_loading: Option, /// Require successful linkage to all functions in the library. @@ -344,36 +391,36 @@ struct BindgenCommand { /// Deduplicates extern blocks. #[arg(long)] merge_extern_blocks: bool, - /// Overrides the ABI of functions matching REGEX. The OVERRIDE value must be of the shape REGEX=ABI where ABI can be one of C, stdcall, efiapi, fastcall, thiscall, aapcs, win64 or C-unwind. - #[arg(long, value_name = "OVERRIDE")] - override_abi: Vec, + /// Overrides the ABI of functions matching REGEX. The OVERRIDE value must be of the shape REGEX=ABI where ABI can be one of C, stdcall, efiapi, fastcall, thiscall, aapcs, win64 or C-unwind<.> + #[arg(long, value_name = "OVERRIDE", value_parser = parse_abi_override)] + override_abi: Vec<(Abi, String)>, /// Wrap unsafe operations in unsafe blocks. #[arg(long)] wrap_unsafe_ops: bool, /// Derive custom traits on any kind of type. The CUSTOM value must be of the shape REGEX=DERIVE where DERIVE is a coma-separated list of derive macros. - #[arg(long, value_name = "CUSTOM")] - with_derive_custom: Vec, + #[arg(long, value_name = "CUSTOM", value_parser = parse_custom_derive)] + with_derive_custom: Vec<(Vec, String)>, /// Derive custom traits on a `struct`. The CUSTOM value must be of the shape REGEX=DERIVE where DERIVE is a coma-separated list of derive macros. - #[arg(long, value_name = "CUSTOM")] - with_derive_custom_struct: Vec, + #[arg(long, value_name = "CUSTOM", value_parser = parse_custom_derive)] + with_derive_custom_struct: Vec<(Vec, String)>, /// Derive custom traits on an `enum. The CUSTOM value must be of the shape REGEX=DERIVE where DERIVE is a coma-separated list of derive macros. - #[arg(long, value_name = "CUSTOM")] - with_derive_custom_enum: Vec, + #[arg(long, value_name = "CUSTOM", value_parser = parse_custom_derive)] + with_derive_custom_enum: Vec<(Vec, String)>, /// Derive custom traits on a `union`. The CUSTOM value must be of the shape REGEX=DERIVE where DERIVE is a coma-separated list of derive macros. - #[arg(long, value_name = "CUSTOM")] - with_derive_custom_union: Vec, + #[arg(long, value_name = "CUSTOM", value_parser = parse_custom_derive)] + with_derive_custom_union: Vec<(Vec, String)>, /// Generate wrappers for `static` and `static inline` functions. #[arg(long, requires = "experimental")] wrap_static_fns: bool, - /// Sets the path for the source file that must be created due to the presence of `static` and + /// Sets the PATH for the source file that must be created due to the presence of `static` and /// `static inline` functions. #[arg(long, requires = "experimental", value_name = "PATH")] wrap_static_fns_path: Option, - /// Sets the suffix added to the extern wrapper functions generated for `static` and `static + /// Sets the SUFFIX added to the extern wrapper functions generated for `static` and `static /// inline` functions. #[arg(long, requires = "experimental", value_name = "SUFFIX")] wrap_static_fns_suffix: Option, - /// Set the default visibility of fields, including bitfields and accessor methods for + /// Set the default VISIBILITY of fields, including bitfields and accessor methods for /// bitfields. This flag is ignored if the `--respect-cxx-access-specs` flag is used. #[arg(long, value_name = "VISIBILITY")] default_visibility: Option, @@ -542,11 +589,7 @@ where let mut builder = builder(); - if let Some(header) = header { - builder = builder.header(header); - } else { - return Err(Error::new(ErrorKind::Other, "Header not found")); - } + builder = builder.header(header); if let Some(rust_target) = rust_target { builder = builder.rust_target(rust_target); @@ -874,23 +917,7 @@ where builder = builder.formatter(formatter); } - if let Some(path_str) = rustfmt_configuration_file { - let path = PathBuf::from(path_str); - - if !path.is_absolute() { - return Err(Error::new( - ErrorKind::Other, - "--rustfmt-configuration-file needs to be an absolute path!", - )); - } - - if path.to_str().is_none() { - return Err(Error::new( - ErrorKind::Other, - "--rustfmt-configuration-file contains non-valid UTF8 characters.", - )); - } - + if let Some(path) = rustfmt_configuration_file { builder = builder.rustfmt_configuration_file(Some(path)); } @@ -976,13 +1003,7 @@ where builder = builder.merge_extern_blocks(true); } - for abi_override in override_abi { - let (regex, abi_str) = abi_override - .rsplit_once('=') - .expect("Invalid ABI override: Missing `=`"); - let abi = abi_str - .parse() - .unwrap_or_else(|err| panic!("Invalid ABI override: {}", err)); + for (abi, regex) in override_abi { builder = builder.override_abi(abi, regex); } @@ -1052,12 +1073,7 @@ where ), ] { let name = emit_diagnostics.then_some(name); - for custom_derive in custom_derives { - let (regex, derives) = custom_derive - .rsplit_once('=') - .expect("Invalid custom derive argument: Missing `=`"); - let derives = derives.split(',').map(|s| s.to_owned()).collect(); - + for (derives, regex) in custom_derives { let mut regex_set = RegexSet::new(); regex_set.insert(regex); regex_set.build_with_diagnostics(false, name); From 100ab4c6c86a0dfa2a3d075457c5b50e5feb80e7 Mon Sep 17 00:00:00 2001 From: Xing Guo Date: Mon, 9 Oct 2023 21:38:05 +0800 Subject: [PATCH 578/942] [Doc] Add missing entry for allowlist-item. (#2659) While playing with bindgen, I noticed that the entry for allowlist-item is missing from the official doc. This patch helps add it. I've checked that the doc for allowlist_* and blocklist_* are correct. --- book/src/allowlisting.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/book/src/allowlisting.md b/book/src/allowlisting.md index edf93df0ef..99dd169865 100644 --- a/book/src/allowlisting.md +++ b/book/src/allowlisting.md @@ -20,6 +20,7 @@ transitively used by a definition that matches them. * [`bindgen::Builder::allowlist_function`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.allowlist_function) * [`bindgen::Builder::allowlist_var`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.allowlist_var) * [`bindgen::Builder::allowlist_file`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.allowlist_file) +* [`bindgen::Builder::allowlist_item`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.allowlist_item) ### Command Line @@ -27,6 +28,7 @@ transitively used by a definition that matches them. * `--allowlist-function ` * `--allowlist-var ` * `--allowlist-file ` +* `--allowlist-item ` ### Annotations From e41f9dcd31cc3ac6bf79ccfe477055b19c190e47 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Tue, 17 Oct 2023 17:41:59 +0200 Subject: [PATCH 579/942] bump cargo dist, and disable trying to create windows releases (#2660) * use latest cargo-dist * windows executables fail to build --- .github/workflows/release.yml | 186 ++++++++++++++++++---------------- Cargo.toml | 15 ++- 2 files changed, 106 insertions(+), 95 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5bcdd7b458..7997a9c1b7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,18 +4,12 @@ # CI that: # # * checks for a Git Tag that looks like a release -# * creates a draft Github Release™ and fills in its text -# * builds artifacts with cargo-dist (executable-zips, installers, hashes) -# * uploads those artifacts to the Github Release™ -# * undrafts the Github Release™ on success +# * builds artifacts with cargo-dist (archives, installers, hashes) +# * uploads those artifacts to temporary workflow zip +# * on success, uploads the artifacts to a Github Release™ # -# Note that the Github Release™ will be created before the artifacts, -# so there will be a few minutes where the release has no artifacts -# and then they will slowly trickle in, possibly failing. To make -# this more pleasant we mark the release as a "draft" until all -# artifacts have been successfully uploaded. This allows you to -# choose what to do with partial successes and avoids spamming -# anyone with notifications before the release is actually ready. +# Note that the Github Release™ will be created with a generated +# title/body based on your changelogs. name: Release permissions: @@ -46,132 +40,152 @@ on: push: tags: - '**[0-9]+.[0-9]+.[0-9]+*' + pull_request: jobs: # Run 'cargo dist plan' to determine what tasks we need to do - # and create a draft github release with the computed title/body plan: runs-on: ubuntu-latest outputs: - has-releases: ${{ steps.plan.outputs.has-releases }} - releases: ${{ steps.plan.outputs.releases }} + val: ${{ steps.plan.outputs.manifest }} + tag: ${{ !github.event.pull_request && github.ref_name || '' }} + tag-flag: ${{ !github.event.pull_request && format('--tag={0}', github.ref_name) || '' }} + publishing: ${{ !github.event.pull_request }} env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: recursive - name: Install cargo-dist - run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.2.0/cargo-dist-installer.sh | sh" + run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.3.1/cargo-dist-installer.sh | sh" - id: plan run: | - cargo dist plan --tag=${{ github.ref_name }} --output-format=json > dist-manifest.json - echo "dist plan ran successfully" + cargo dist plan ${{ !github.event.pull_request && format('--tag={0}', github.ref_name) || '' }} --output-format=json > dist-manifest.json + echo "cargo dist plan ran successfully" cat dist-manifest.json - - # Create the Github Release™ based on what cargo-dist thinks it should be - ANNOUNCEMENT_TITLE=$(jq --raw-output ".announcement_title" dist-manifest.json) - IS_PRERELEASE=$(jq --raw-output ".announcement_is_prerelease" dist-manifest.json) - jq --raw-output ".announcement_github_body" dist-manifest.json > new_dist_announcement.md - gh release create ${{ github.ref_name }} --draft --prerelease="$IS_PRERELEASE" --title="$ANNOUNCEMENT_TITLE" --notes-file=new_dist_announcement.md - echo "created announcement!" - - # Upload the manifest to the Github Release™ - gh release upload ${{ github.ref_name }} dist-manifest.json - echo "uploaded manifest!" - - # Disable all the upload-artifacts tasks if we have no actual releases - HAS_RELEASES=$(jq --raw-output ".releases != null" dist-manifest.json) - echo "has-releases=$HAS_RELEASES" >> "$GITHUB_OUTPUT" - echo "releases=$(jq --compact-output ".releases" dist-manifest.json)" >> "$GITHUB_OUTPUT" + echo "manifest=$(jq -c "." dist-manifest.json)" >> "$GITHUB_OUTPUT" + - name: "Upload dist-manifest.json" + uses: actions/upload-artifact@v3 + with: + name: artifacts + path: dist-manifest.json # Build and packages all the platform-specific things upload-local-artifacts: # Let the initial task tell us to not run (currently very blunt) needs: plan - if: ${{ needs.plan.outputs.has-releases == 'true' }} + if: ${{ fromJson(needs.plan.outputs.val).releases != null && (needs.plan.outputs.publishing == 'true' || fromJson(needs.plan.outputs.val).ci.github.pr_run_mode == 'upload') }} strategy: fail-fast: false - matrix: - # For these target platforms - include: - - os: "macos-11" - dist-args: "--artifacts=local --target=aarch64-apple-darwin" - install-dist: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.2.0/cargo-dist-installer.sh | sh" - - os: "macos-11" - dist-args: "--artifacts=local --target=x86_64-apple-darwin" - install-dist: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.2.0/cargo-dist-installer.sh | sh" - - os: "ubuntu-20.04" - dist-args: "--artifacts=local --target=x86_64-unknown-linux-gnu" - install-dist: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.2.0/cargo-dist-installer.sh | sh" - runs-on: ${{ matrix.os }} + # Target platforms/runners are computed by cargo-dist in create-release. + # Each member of the matrix has the following arguments: + # + # - runner: the github runner + # - dist-args: cli flags to pass to cargo dist + # - install-dist: expression to run to install cargo-dist on the runner + # + # Typically there will be: + # - 1 "global" task that builds universal installers + # - N "local" tasks that build each platform's binaries and platform-specific installers + matrix: ${{ fromJson(needs.plan.outputs.val).ci.github.artifacts_matrix }} + runs-on: ${{ matrix.runner }} env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: recursive + - uses: swatinem/rust-cache@v2 - name: Install cargo-dist - run: ${{ matrix.install-dist }} - - name: Run cargo-dist - # This logic is a bit janky because it's trying to be a polyglot between - # powershell and bash since this will run on windows, macos, and linux! - # The two platforms don't agree on how to talk about env vars but they - # do agree on 'cat' and '$()' so we use that to marshal values between commands. + run: ${{ matrix.install_dist }} + - name: Build artifacts run: | # Actually do builds and make zips and whatnot - cargo dist build --tag=${{ github.ref_name }} --output-format=json ${{ matrix.dist-args }} > dist-manifest.json - echo "dist ran successfully" - cat dist-manifest.json - + cargo dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json ${{ matrix.dist_args }} > dist-manifest.json + echo "cargo dist ran successfully" + - id: cargo-dist + name: Post-build + # We force bash here just because github makes it really hard to get values up + # to "real" actions without writing to env-vars, and writing to env-vars has + # inconsistent syntax between shell and powershell. + shell: bash + run: | # Parse out what we just built and upload it to the Github Release™ - jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json > uploads.txt - echo "uploading..." - cat uploads.txt - gh release upload ${{ github.ref_name }} $(cat uploads.txt) - echo "uploaded!" + echo "paths<> "$GITHUB_OUTPUT" + jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json >> "$GITHUB_OUTPUT" + echo "EOF" >> "$GITHUB_OUTPUT" + - name: "Upload artifacts" + uses: actions/upload-artifact@v3 + with: + name: artifacts + path: ${{ steps.cargo-dist.outputs.paths }} # Build and package all the platform-agnostic(ish) things upload-global-artifacts: - needs: upload-local-artifacts + needs: [plan, upload-local-artifacts] runs-on: "ubuntu-20.04" env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: recursive - name: Install cargo-dist - run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.2.0/cargo-dist-installer.sh | sh" + run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.3.1/cargo-dist-installer.sh | sh" # Get all the local artifacts for the global tasks to use (for e.g. checksums) - name: Fetch local artifacts + uses: actions/download-artifact@v3 + with: + name: artifacts + path: target/distrib/ + - id: cargo-dist + shell: bash run: | - gh release download ${{ github.ref_name }} --dir target/distrib/ - - name: Run cargo-dist - run: | - cargo dist build --tag=${{ github.ref_name }} --output-format=json "--artifacts=global" > dist-manifest.json - echo "dist ran successfully" - cat dist-manifest.json + cargo dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json "--artifacts=global" > dist-manifest.json + echo "cargo dist ran successfully" # Parse out what we just built and upload it to the Github Release™ - jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json > uploads.txt - echo "uploading..." - cat uploads.txt - gh release upload ${{ github.ref_name }} $(cat uploads.txt) - echo "uploaded!" + echo "paths<> "$GITHUB_OUTPUT" + jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json >> "$GITHUB_OUTPUT" + echo "EOF" >> "$GITHUB_OUTPUT" + - name: "Upload artifacts" + uses: actions/upload-artifact@v3 + with: + name: artifacts + path: ${{ steps.cargo-dist.outputs.paths }} - # Mark the Github Release™ as a non-draft now that everything has succeeded! + should-publish: + needs: + - plan + - upload-local-artifacts + - upload-global-artifacts + if: ${{ needs.plan.outputs.publishing == 'true' }} + runs-on: ubuntu-latest + steps: + - name: print tag + run: echo "ok we're publishing!" + + # Create a Github Release with all the results once everything is done, publish-release: - # Only run after all the other tasks, but it's ok if upload-artifacts was skipped - needs: [plan, upload-local-artifacts, upload-global-artifacts] - if: ${{ always() && needs.plan.result == 'success' && (needs.upload-local-artifacts.result == 'skipped' || needs.upload-local-artifacts.result == 'success') && (needs.upload-global-artifacts.result == 'skipped' || needs.upload-global-artifacts.result == 'success') }} + needs: [plan, should-publish] runs-on: ubuntu-latest env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: recursive - - name: mark release as non-draft - run: | - gh release edit ${{ github.ref_name }} --draft=false + - name: "Download artifacts" + uses: actions/download-artifact@v3 + with: + name: artifacts + path: artifacts + - name: Create Release + uses: ncipollo/release-action@v1 + with: + tag: ${{ needs.plan.outputs.tag }} + name: ${{ fromJson(needs.plan.outputs.val).announcement_title }} + body: ${{ fromJson(needs.plan.outputs.val).announcement_github_body }} + prerelease: ${{ fromJson(needs.plan.outputs.val).announcement_is_prerelease }} + artifacts: "artifacts/*" diff --git a/Cargo.toml b/Cargo.toml index 370828da55..3f674e6973 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,20 +17,17 @@ default-members = [ # Config for 'cargo dist' [workspace.metadata.dist] # The preferred cargo-dist version to use in CI (Cargo.toml SemVer syntax) -cargo-dist-version = "0.2.0" -# CI backends to support (see 'cargo dist generate-ci') +cargo-dist-version = "0.3.1" +# CI backends to support ci = ["github"] # The installers to generate for each app installers = ["shell", "powershell"] # Target platforms to build apps for (Rust target-triple syntax) -targets = [ - "x86_64-unknown-linux-gnu", - "x86_64-apple-darwin", - "x86_64-pc-windows-msvc", - "aarch64-apple-darwin", -] -# Don't compile any crate while building artifacts unless the crate's manifest has `dist = true` +targets = ["x86_64-unknown-linux-gnu", "aarch64-apple-darwin", "x86_64-apple-darwin"] +# Whether to consider the binaries in a package for distribution (defaults true) dist = false +# Publish jobs to run in CI +pr-run-mode = "plan" # Config for 'cargo release' [workspace.metadata.release] From 89a84f6c251c3894397d04f75d2bf2219e806c3c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 1 Nov 2023 09:43:57 -0500 Subject: [PATCH 580/942] Bump rustix from 0.36.7 to 0.36.16 (#2666) Bumps [rustix](https://github.com/bytecodealliance/rustix) from 0.36.7 to 0.36.16. - [Release notes](https://github.com/bytecodealliance/rustix/releases) - [Commits](https://github.com/bytecodealliance/rustix/compare/v0.36.7...v0.36.16) --- updated-dependencies: - dependency-name: rustix dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Cargo.lock | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 40cb0777cb..04423fce97 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -203,17 +203,6 @@ dependencies = [ "termcolor", ] -[[package]] -name = "errno" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" -dependencies = [ - "errno-dragonfly", - "libc", - "winapi", -] - [[package]] name = "errno" version = "0.3.1" @@ -548,16 +537,16 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" [[package]] name = "rustix" -version = "0.36.7" +version = "0.36.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4fdebc4b395b7fbb9ab11e462e20ed9051e7b16e42d24042c776eca0ac81b03" +checksum = "6da3636faa25820d8648e0e31c5d519bbb01f72fdf57131f0f5f7da5fed36eab" dependencies = [ "bitflags 1.3.2", - "errno 0.2.8", + "errno", "io-lifetimes", "libc", "linux-raw-sys 0.1.4", - "windows-sys 0.42.0", + "windows-sys 0.45.0", ] [[package]] @@ -567,7 +556,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "62b24138615de35e32031d041a09032ef3487a616d901ca4db224e7d557efae2" dependencies = [ "bitflags 1.3.2", - "errno 0.3.1", + "errno", "io-lifetimes", "libc", "linux-raw-sys 0.3.8", @@ -623,7 +612,7 @@ dependencies = [ "cfg-if", "fastrand", "redox_syscall", - "rustix 0.36.7", + "rustix 0.36.16", "windows-sys 0.42.0", ] From 5d1a25447fd5d8f7f0a0b18487721099e71064f7 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Wed, 1 Nov 2023 09:46:58 -0500 Subject: [PATCH 581/942] Fix the `check-cfg` workflow (#2676) * Fix unused cfg attributes * Fix check-cfg workflow --- .github/workflows/bindgen.yml | 2 +- bindgen/ir/item.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index c7c37bbc17..3f85cd862a 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -238,7 +238,7 @@ jobs: override: true - name: Check cfg - run: cargo check -Z unstable-options -Z check-cfg=features + run: cargo check -Z unstable-options -Z check-cfg test-book: runs-on: ubuntu-latest diff --git a/bindgen/ir/item.rs b/bindgen/ir/item.rs index 4abca5c49b..0556452bfa 100644 --- a/bindgen/ir/item.rs +++ b/bindgen/ir/item.rs @@ -98,13 +98,13 @@ pub(crate) trait ItemAncestors { fn ancestors<'a>(&self, ctx: &'a BindgenContext) -> ItemAncestorsIter<'a>; } -#[cfg(__testing_only_extra_assertions)] +#[cfg(feature = "__testing_only_extra_assertions")] type DebugOnlyItemSet = ItemSet; -#[cfg(not(__testing_only_extra_assertions))] +#[cfg(not(feature = "__testing_only_extra_assertions"))] struct DebugOnlyItemSet; -#[cfg(not(__testing_only_extra_assertions))] +#[cfg(not(feature = "__testing_only_extra_assertions"))] impl DebugOnlyItemSet { fn new() -> Self { DebugOnlyItemSet From 04fa3930f45bbff050f97e6d45e0ddcbb98bde85 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Wed, 1 Nov 2023 16:47:15 +0200 Subject: [PATCH 582/942] publish from GitHub release page (#2645) * space to breath * publish from GitHub Releases * Apply suggestions from code review --- .github/workflows/publish.yml | 21 +++++++++++++++++++++ CONTRIBUTING.md | 3 ++- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000000..5aa52860f4 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,21 @@ +# To trigger this: +# - go to Actions > Publish +# - click the Run Workflow dropdown in the top-right +name: Publish +on: workflow_dispatch +env: + CRATES_TOKEN: ${{ secrets.CRATES_TOKEN }} +jobs: + cargo-publish: + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v3 + - name: Install stable toolchain + uses: dtolnay/rust-toolchain@master + with: + toolchain: stable + - name: Publish bindgen (lib) + run: cargo publish --package bindgen --token ${CRATES_TOKEN} + - name: Publish bindgen-cli + run: cargo publish --package bindgen-cli --token ${CRATES_TOKEN} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 25cad1e9bd..58d47a41e9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -564,8 +564,9 @@ important fix) you can skip this. Once you're in the right branch, do: ``` -cargo release [patch|minor] --execute +cargo release [patch|minor] --no-publish --execute ``` + This does the following: - Tag (`git tag`) the HEAD commit From 7ed33dde6311f425cfef06c8b48a025f9c0064e7 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Wed, 1 Nov 2023 12:00:28 -0500 Subject: [PATCH 583/942] Update the changelog using cargo release --- .gitignore | 5 +++++ Cargo.toml | 6 ------ bindgen/Cargo.toml | 7 +++++++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index a924030cc9..a610640e5e 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,8 @@ csmith-fuzzing/platform.info # Backups of test cases from C-Reduce **/*.orig + +# node.js files +node_modules +package-lock.json +package.json diff --git a/Cargo.toml b/Cargo.toml index 3f674e6973..0730e061b4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,12 +36,6 @@ tag-name = "v{{version}}" # Don't release any crate unless its manifest has `release = true` release = false -# Add version and date to changelog file -[[workspace.metadata.release.pre-release-replacements]] -file = "CHANGELOG.md" -search = "# Unreleased" -replace = "# {{version}} ({{date}})" - # The profile that 'cargo dist' will build with [profile.dist] inherits = "release" diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index d7b6df9f05..bda6397876 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -65,3 +65,10 @@ features = ["experimental"] [package.metadata.release] release = true +pre-release-hook = ["../node_modules/doctoc/doctoc.js", "../CHANGELOG.md"] + +# Add version and date to changelog file +[[package.metadata.release.pre-release-replacements]] +file = "../CHANGELOG.md" +search = "# Unreleased" +replace = "# Unreleased\n## Added\n## Changed\n## Removed\n## Fixed\n## Security\n\n# {{version}} ({{date}})" From d1cc3c2432ce4e7e8bf7b0462e54d61731f72118 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Wed, 1 Nov 2023 12:43:57 -0500 Subject: [PATCH 584/942] Update release instructions --- CONTRIBUTING.md | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 58d47a41e9..1fdacaaf6c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -544,15 +544,6 @@ like the following is a useful way to check what has landed: Also worth checking the [next-release tag](https://github.com/rust-lang/rust-bindgen/pulls?q=is%3Apr+label%3Anext-release). -Once that's done and the changelog is up-to-date, run `doctoc` on it. - -If needed, install it locally by running: - -``` -$ npm install doctoc -$ ./node_modules/doctoc/doctoc.js CHANGELOG.md -``` - ### Merge to `main` For regular releases, the changes above should end up in `main` before @@ -561,14 +552,21 @@ important fix) you can skip this. ### Tag and publish -Once you're in the right branch, do: +Once you're in `main`. Remember to install `doctoc` by running: +``` +npm install doctoc +``` +And then run: ``` cargo release [patch|minor] --no-publish --execute ``` This does the following: +- Bump the version. +- Turn the `Unreleased` section of the changelog into the section for the version being published. +- Update the table of contents of the changelog using `doctoc`. - Tag (`git tag`) the HEAD commit - Publish (`cargo publish`) bindgen and bindgen-cli - Push (`git push`) to GitHub From 1279a11dfb9560554fbfaecc427d3fc8753942dd Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Wed, 1 Nov 2023 12:45:09 -0500 Subject: [PATCH 585/942] chore: Release --- CHANGELOG.md | 177 ++++++++++++++++++++++------------------- Cargo.lock | 4 +- bindgen-cli/Cargo.toml | 4 +- bindgen/Cargo.toml | 2 +- 4 files changed, 100 insertions(+), 87 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9149d45d40..65d015a190 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,175 +7,188 @@ - [Removed](#removed) - [Fixed](#fixed) - [Security](#security) -- [0.68.1](#0681) - - [Fixed](#fixed-1) -- [0.68.0](#0680) +- [0.69.0 (2023-11-01)](#0690-2023-11-01) - [Added](#added-1) - [Changed](#changed-1) - [Removed](#removed-1) + - [Fixed](#fixed-1) + - [Security](#security-1) +- [0.68.1](#0681) - [Fixed](#fixed-2) -- [0.67.0](#0670) -- [0.66.1](#0661) - - [Removed](#removed-2) -- [0.66.0](#0660) +- [0.68.0](#0680) - [Added](#added-2) - [Changed](#changed-2) - - [Removed](#removed-3) -- [0.65.1](#0651) + - [Removed](#removed-2) - [Fixed](#fixed-3) -- [0.65.0](#0650) +- [0.67.0](#0670) +- [0.66.1](#0661) + - [Removed](#removed-3) +- [0.66.0](#0660) - [Added](#added-3) - [Changed](#changed-3) - [Removed](#removed-4) -- [0.64.0](#0640) +- [0.65.1](#0651) + - [Fixed](#fixed-4) +- [0.65.0](#0650) - [Added](#added-4) - [Changed](#changed-4) -- [0.63.0](#0630) + - [Removed](#removed-5) +- [0.64.0](#0640) - [Added](#added-5) - [Changed](#changed-5) - - [Removed](#removed-5) -- [0.62.0](#0620) +- [0.63.0](#0630) - [Added](#added-6) - [Changed](#changed-6) - - [Fixed](#fixed-4) -- [0.61.0](#0610) + - [Removed](#removed-6) +- [0.62.0](#0620) - [Added](#added-7) - [Changed](#changed-7) - [Fixed](#fixed-5) -- [0.60.1](#0601) - - [Fixed](#fixed-6) -- [0.60.0](#0600) +- [0.61.0](#0610) - [Added](#added-8) - - [Fixed](#fixed-7) - [Changed](#changed-8) - - [Removed](#removed-6) + - [Fixed](#fixed-6) +- [0.60.1](#0601) + - [Fixed](#fixed-7) +- [0.60.0](#0600) + - [Added](#added-9) + - [Fixed](#fixed-8) + - [Changed](#changed-9) + - [Removed](#removed-7) - [0.59.2](#0592) - [0.59.1](#0591) - - [Fixed](#fixed-8) -- [0.59.0](#0590) - - [Added](#added-9) - [Fixed](#fixed-9) - - [Changed](#changed-9) -- [0.58.1](#0581) +- [0.59.0](#0590) - [Added](#added-10) -- [0.58.0](#0580) - - [Added](#added-11) - [Fixed](#fixed-10) - [Changed](#changed-10) - - [Deprecated](#deprecated) - - [Removed](#removed-7) - - [Fixed](#fixed-11) - - [Security](#security-1) -- [0.57.0](#0570) +- [0.58.1](#0581) + - [Added](#added-11) +- [0.58.0](#0580) - [Added](#added-12) + - [Fixed](#fixed-11) + - [Changed](#changed-11) + - [Deprecated](#deprecated) + - [Removed](#removed-8) - [Fixed](#fixed-12) -- [0.56.0](#0560) + - [Security](#security-2) +- [0.57.0](#0570) - [Added](#added-13) - - [Changed](#changed-11) - [Fixed](#fixed-13) -- [0.55.1](#0551) - - [Fixed](#fixed-14) -- [0.55.0](#0550) - - [Removed](#removed-8) +- [0.56.0](#0560) - [Added](#added-14) - [Changed](#changed-12) + - [Fixed](#fixed-14) +- [0.55.1](#0551) - [Fixed](#fixed-15) -- [0.54.1](#0541) +- [0.55.0](#0550) + - [Removed](#removed-9) - [Added](#added-15) - [Changed](#changed-13) - [Fixed](#fixed-16) -- [0.54.0](#0540) +- [0.54.1](#0541) - [Added](#added-16) - [Changed](#changed-14) - [Fixed](#fixed-17) -- [0.53.3](#0533) +- [0.54.0](#0540) - [Added](#added-17) + - [Changed](#changed-15) - [Fixed](#fixed-18) +- [0.53.3](#0533) + - [Added](#added-18) + - [Fixed](#fixed-19) - [0.53.2](#0532) - - [Changed](#changed-15) + - [Changed](#changed-16) - [0.53.1](#0531) - - [Added](#added-18) -- [0.53.0](#0530) - [Added](#added-19) - - [Changed](#changed-16) - - [Fixed](#fixed-19) -- [0.52.0](#0520) +- [0.53.0](#0530) - [Added](#added-20) - [Changed](#changed-17) - [Fixed](#fixed-20) -- [0.51.1](#0511) - - [Fixed](#fixed-21) +- [0.52.0](#0520) + - [Added](#added-21) - [Changed](#changed-18) -- [0.51.0](#0510) + - [Fixed](#fixed-21) +- [0.51.1](#0511) - [Fixed](#fixed-22) - [Changed](#changed-19) - - [Added](#added-21) -- [0.50.0](#0500) +- [0.51.0](#0510) + - [Fixed](#fixed-23) + - [Changed](#changed-20) - [Added](#added-22) -- [0.49.3](#0493) +- [0.50.0](#0500) - [Added](#added-23) +- [0.49.3](#0493) + - [Added](#added-24) - [0.49.2](#0492) - - [Changed](#changed-20) -- [0.49.1](#0491) - - [Fixed](#fixed-23) - [Changed](#changed-21) -- [0.49.0](#0490) - - [Added](#added-24) +- [0.49.1](#0491) - [Fixed](#fixed-24) - [Changed](#changed-22) -- [0.48.1](#0481) +- [0.49.0](#0490) + - [Added](#added-25) - [Fixed](#fixed-25) -- [0.48.0](#0480) - [Changed](#changed-23) +- [0.48.1](#0481) - [Fixed](#fixed-26) -- [0.47.4](#0474) - - [Added](#added-25) -- [0.47.3](#0473) +- [0.48.0](#0480) - [Changed](#changed-24) -- [0.47.2](#0472) - [Fixed](#fixed-27) -- [0.47.1](#0471) +- [0.47.4](#0474) + - [Added](#added-26) +- [0.47.3](#0473) - [Changed](#changed-25) +- [0.47.2](#0472) - [Fixed](#fixed-28) -- [0.47.0](#0470) +- [0.47.1](#0471) - [Changed](#changed-26) - [Fixed](#fixed-29) -- [0.33.1 .. 0.46.0](#0331--0460) - - [Added](#added-26) - - [Removed](#removed-9) +- [0.47.0](#0470) - [Changed](#changed-27) - [Fixed](#fixed-30) -- [0.33.1](#0331) +- [0.33.1 .. 0.46.0](#0331--0460) + - [Added](#added-27) + - [Removed](#removed-10) + - [Changed](#changed-28) - [Fixed](#fixed-31) +- [0.33.1](#0331) + - [Fixed](#fixed-32) - [0.33.0](#0330) - [0.32.2](#0322) - - [Fixed](#fixed-32) -- [0.32.1](#0321) - [Fixed](#fixed-33) -- [0.32.0](#0320) - - [Added](#added-27) - - [Changed](#changed-28) +- [0.32.1](#0321) - [Fixed](#fixed-34) -- [0.31.0](#0310) +- [0.32.0](#0320) - [Added](#added-28) - [Changed](#changed-29) - - [Deprecated](#deprecated-1) - - [Removed](#removed-10) - [Fixed](#fixed-35) -- [0.30.0](#0300) +- [0.31.0](#0310) - [Added](#added-29) - [Changed](#changed-30) - - [Deprecated](#deprecated-2) + - [Deprecated](#deprecated-1) + - [Removed](#removed-11) - [Fixed](#fixed-36) -- [0.29.0](#0290) +- [0.30.0](#0300) - [Added](#added-30) - [Changed](#changed-31) + - [Deprecated](#deprecated-2) - [Fixed](#fixed-37) +- [0.29.0](#0290) + - [Added](#added-31) + - [Changed](#changed-32) + - [Fixed](#fixed-38) -------------------------------------------------------------------------------- # Unreleased +## Added +## Changed +## Removed +## Fixed +## Security + +# 0.69.0 (2023-11-01) ## Added - Added the `ParseCallbacks::header_file` callback which runs on every filename passed to `Builder::header`. diff --git a/Cargo.lock b/Cargo.lock index 04423fce97..cb3f87c287 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -23,7 +23,7 @@ dependencies = [ [[package]] name = "bindgen" -version = "0.68.1" +version = "0.69.0" dependencies = [ "annotate-snippets", "bitflags 2.2.1", @@ -45,7 +45,7 @@ dependencies = [ [[package]] name = "bindgen-cli" -version = "0.68.1" +version = "0.69.0" dependencies = [ "bindgen", "clap", diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index 07e7786113..2de54e7c7d 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -11,7 +11,7 @@ readme = "../README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.68.1" +version = "0.69.0" edition = "2018" rust-version = "1.64.0" @@ -20,7 +20,7 @@ path = "main.rs" name = "bindgen" [dependencies] -bindgen = { path = "../bindgen", version = "=0.68.1", default-features = false, features = ["__cli", "experimental"] } +bindgen = { path = "../bindgen", version = "=0.69.0", default-features = false, features = ["__cli", "experimental"] } clap = { version = "4", features = ["derive"] } clap_complete = "4" env_logger = { version = "0.10.0", optional = true } diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index bda6397876..396bf6068e 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -14,7 +14,7 @@ readme = "../README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.68.1" +version = "0.69.0" edition = "2018" build = "build.rs" # If you change this, also update README.md and msrv in .github/workflows/bindgen.yml From c73990cc0f714ce79e444039f09eaf1f769d7e6a Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Wed, 1 Nov 2023 12:55:44 -0500 Subject: [PATCH 586/942] Rename secret for crates.io token --- .github/workflows/publish.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 5aa52860f4..f79ce1036b 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -4,7 +4,7 @@ name: Publish on: workflow_dispatch env: - CRATES_TOKEN: ${{ secrets.CRATES_TOKEN }} + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} jobs: cargo-publish: runs-on: ubuntu-latest @@ -16,6 +16,6 @@ jobs: with: toolchain: stable - name: Publish bindgen (lib) - run: cargo publish --package bindgen --token ${CRATES_TOKEN} + run: cargo publish --package bindgen --token ${CARGO_REGISTRY_TOKEN} - name: Publish bindgen-cli - run: cargo publish --package bindgen-cli --token ${CRATES_TOKEN} + run: cargo publish --package bindgen-cli --token ${CARGO_REGISTRY_TOKEN} From 6666724a2a399a68efb53717608f6b6fd9b52f85 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Wed, 1 Nov 2023 13:10:07 -0500 Subject: [PATCH 587/942] Update release instructions --- CONTRIBUTING.md | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1fdacaaf6c..7e5cdc53eb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -542,7 +542,11 @@ like the following is a useful way to check what has landed: $ git log --oneline v0.62.0..HEAD ``` -Also worth checking the [next-release tag](https://github.com/rust-lang/rust-bindgen/pulls?q=is%3Apr+label%3Anext-release). +Also worth checking the [next-release +tag](https://github.com/rust-lang/rust-bindgen/pulls?q=is%3Apr+label%3Anext-release). +It is very important that you do not rename the `Unreleased` section of the +changelog as this will be done automatically using `cargo release` on a further +step. ### Merge to `main` @@ -601,4 +605,20 @@ cargo dist init # from "cargo install cargo-dist" cargo dist generate-ci # to update .github/workflows/release.yml ``` +### What to do if a Github release fails + +If the release process failed after you run `cargo release` you can manually +delete the tag and release from Github. Also remember to delete the tag locally +by running `git tag -d`. Once all the extra changes are in the `main` branch +you can trigger a release by creating a new tag using `git tag` and push it +using `git push --tag`. + +### Create a new crates.io release + +Go to [the Publish +workflow](https://github.com/rust-lang/rust-bindgen/actions/workflows/publish.yml) +and run a new workflow using the "Run Workflow" button. + +Remember that crates.io releases cannot be deleted! + [prettyplease]: https://github.com/dtolnay/prettyplease From d85878f49d05742f9b338a01af027d9b4033b077 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Orhun=20Parmaks=C4=B1z?= Date: Thu, 2 Nov 2023 18:40:17 +0100 Subject: [PATCH 588/942] fix(args): make header argument optional (#2678) * fix(args): make header argument optional fixes #2677 * refactor(args): avoid using type aliases --- bindgen-cli/options.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bindgen-cli/options.rs b/bindgen-cli/options.rs index d52ccb8e89..f82d391901 100644 --- a/bindgen-cli/options.rs +++ b/bindgen-cli/options.rs @@ -95,7 +95,7 @@ fn parse_custom_derive( )] struct BindgenCommand { /// C or C++ header file. - header: String, + header: Option, /// Path to write depfile to. #[arg(long)] depfile: Option, @@ -589,7 +589,11 @@ where let mut builder = builder(); - builder = builder.header(header); + if let Some(header) = header { + builder = builder.header(header); + } else { + return Err(io::Error::new(io::ErrorKind::Other, "Header not found")); + } if let Some(rust_target) = rust_target { builder = builder.rust_target(rust_target); From fc4e67bb17a7dc34a137fef8201ceb3633809006 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Thu, 2 Nov 2023 12:46:39 -0500 Subject: [PATCH 589/942] Update changelog --- CHANGELOG.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 65d015a190..468dfdd597 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -182,11 +182,9 @@ -------------------------------------------------------------------------------- # Unreleased -## Added -## Changed -## Removed + ## Fixed -## Security +- Allow to run `bindgen -v` without an input header argument. # 0.69.0 (2023-11-01) From f3f3d326c7e9e6fa55562fec6a8676ae8eab7588 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Thu, 2 Nov 2023 12:47:49 -0500 Subject: [PATCH 590/942] chore: Release --- CHANGELOG.md | 85 +++++++++++++++++++++++------------------- Cargo.lock | 4 +- bindgen-cli/Cargo.toml | 4 +- bindgen/Cargo.toml | 2 +- 4 files changed, 52 insertions(+), 43 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 468dfdd597..e3f2c9e98a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,19 +7,21 @@ - [Removed](#removed) - [Fixed](#fixed) - [Security](#security) +- [0.69.1 (2023-11-02)](#0691-2023-11-02) + - [Fixed](#fixed-1) - [0.69.0 (2023-11-01)](#0690-2023-11-01) - [Added](#added-1) - [Changed](#changed-1) - [Removed](#removed-1) - - [Fixed](#fixed-1) + - [Fixed](#fixed-2) - [Security](#security-1) - [0.68.1](#0681) - - [Fixed](#fixed-2) + - [Fixed](#fixed-3) - [0.68.0](#0680) - [Added](#added-2) - [Changed](#changed-2) - [Removed](#removed-2) - - [Fixed](#fixed-3) + - [Fixed](#fixed-4) - [0.67.0](#0670) - [0.66.1](#0661) - [Removed](#removed-3) @@ -28,7 +30,7 @@ - [Changed](#changed-3) - [Removed](#removed-4) - [0.65.1](#0651) - - [Fixed](#fixed-4) + - [Fixed](#fixed-5) - [0.65.0](#0650) - [Added](#added-4) - [Changed](#changed-4) @@ -43,60 +45,60 @@ - [0.62.0](#0620) - [Added](#added-7) - [Changed](#changed-7) - - [Fixed](#fixed-5) + - [Fixed](#fixed-6) - [0.61.0](#0610) - [Added](#added-8) - [Changed](#changed-8) - - [Fixed](#fixed-6) -- [0.60.1](#0601) - [Fixed](#fixed-7) +- [0.60.1](#0601) + - [Fixed](#fixed-8) - [0.60.0](#0600) - [Added](#added-9) - - [Fixed](#fixed-8) + - [Fixed](#fixed-9) - [Changed](#changed-9) - [Removed](#removed-7) - [0.59.2](#0592) - [0.59.1](#0591) - - [Fixed](#fixed-9) + - [Fixed](#fixed-10) - [0.59.0](#0590) - [Added](#added-10) - - [Fixed](#fixed-10) + - [Fixed](#fixed-11) - [Changed](#changed-10) - [0.58.1](#0581) - [Added](#added-11) - [0.58.0](#0580) - [Added](#added-12) - - [Fixed](#fixed-11) + - [Fixed](#fixed-12) - [Changed](#changed-11) - [Deprecated](#deprecated) - [Removed](#removed-8) - - [Fixed](#fixed-12) + - [Fixed](#fixed-13) - [Security](#security-2) - [0.57.0](#0570) - [Added](#added-13) - - [Fixed](#fixed-13) + - [Fixed](#fixed-14) - [0.56.0](#0560) - [Added](#added-14) - [Changed](#changed-12) - - [Fixed](#fixed-14) -- [0.55.1](#0551) - [Fixed](#fixed-15) +- [0.55.1](#0551) + - [Fixed](#fixed-16) - [0.55.0](#0550) - [Removed](#removed-9) - [Added](#added-15) - [Changed](#changed-13) - - [Fixed](#fixed-16) + - [Fixed](#fixed-17) - [0.54.1](#0541) - [Added](#added-16) - [Changed](#changed-14) - - [Fixed](#fixed-17) + - [Fixed](#fixed-18) - [0.54.0](#0540) - [Added](#added-17) - [Changed](#changed-15) - - [Fixed](#fixed-18) + - [Fixed](#fixed-19) - [0.53.3](#0533) - [Added](#added-18) - - [Fixed](#fixed-19) + - [Fixed](#fixed-20) - [0.53.2](#0532) - [Changed](#changed-16) - [0.53.1](#0531) @@ -104,16 +106,16 @@ - [0.53.0](#0530) - [Added](#added-20) - [Changed](#changed-17) - - [Fixed](#fixed-20) + - [Fixed](#fixed-21) - [0.52.0](#0520) - [Added](#added-21) - [Changed](#changed-18) - - [Fixed](#fixed-21) -- [0.51.1](#0511) - [Fixed](#fixed-22) +- [0.51.1](#0511) + - [Fixed](#fixed-23) - [Changed](#changed-19) - [0.51.0](#0510) - - [Fixed](#fixed-23) + - [Fixed](#fixed-24) - [Changed](#changed-20) - [Added](#added-22) - [0.50.0](#0500) @@ -123,65 +125,72 @@ - [0.49.2](#0492) - [Changed](#changed-21) - [0.49.1](#0491) - - [Fixed](#fixed-24) + - [Fixed](#fixed-25) - [Changed](#changed-22) - [0.49.0](#0490) - [Added](#added-25) - - [Fixed](#fixed-25) + - [Fixed](#fixed-26) - [Changed](#changed-23) - [0.48.1](#0481) - - [Fixed](#fixed-26) + - [Fixed](#fixed-27) - [0.48.0](#0480) - [Changed](#changed-24) - - [Fixed](#fixed-27) + - [Fixed](#fixed-28) - [0.47.4](#0474) - [Added](#added-26) - [0.47.3](#0473) - [Changed](#changed-25) - [0.47.2](#0472) - - [Fixed](#fixed-28) + - [Fixed](#fixed-29) - [0.47.1](#0471) - [Changed](#changed-26) - - [Fixed](#fixed-29) + - [Fixed](#fixed-30) - [0.47.0](#0470) - [Changed](#changed-27) - - [Fixed](#fixed-30) + - [Fixed](#fixed-31) - [0.33.1 .. 0.46.0](#0331--0460) - [Added](#added-27) - [Removed](#removed-10) - [Changed](#changed-28) - - [Fixed](#fixed-31) -- [0.33.1](#0331) - [Fixed](#fixed-32) +- [0.33.1](#0331) + - [Fixed](#fixed-33) - [0.33.0](#0330) - [0.32.2](#0322) - - [Fixed](#fixed-33) -- [0.32.1](#0321) - [Fixed](#fixed-34) +- [0.32.1](#0321) + - [Fixed](#fixed-35) - [0.32.0](#0320) - [Added](#added-28) - [Changed](#changed-29) - - [Fixed](#fixed-35) + - [Fixed](#fixed-36) - [0.31.0](#0310) - [Added](#added-29) - [Changed](#changed-30) - [Deprecated](#deprecated-1) - [Removed](#removed-11) - - [Fixed](#fixed-36) + - [Fixed](#fixed-37) - [0.30.0](#0300) - [Added](#added-30) - [Changed](#changed-31) - [Deprecated](#deprecated-2) - - [Fixed](#fixed-37) + - [Fixed](#fixed-38) - [0.29.0](#0290) - [Added](#added-31) - [Changed](#changed-32) - - [Fixed](#fixed-38) + - [Fixed](#fixed-39) -------------------------------------------------------------------------------- # Unreleased +## Added +## Changed +## Removed +## Fixed +## Security + +# 0.69.1 (2023-11-02) ## Fixed - Allow to run `bindgen -v` without an input header argument. diff --git a/Cargo.lock b/Cargo.lock index cb3f87c287..a4d120a864 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -23,7 +23,7 @@ dependencies = [ [[package]] name = "bindgen" -version = "0.69.0" +version = "0.69.1" dependencies = [ "annotate-snippets", "bitflags 2.2.1", @@ -45,7 +45,7 @@ dependencies = [ [[package]] name = "bindgen-cli" -version = "0.69.0" +version = "0.69.1" dependencies = [ "bindgen", "clap", diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index 2de54e7c7d..2738952803 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -11,7 +11,7 @@ readme = "../README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.69.0" +version = "0.69.1" edition = "2018" rust-version = "1.64.0" @@ -20,7 +20,7 @@ path = "main.rs" name = "bindgen" [dependencies] -bindgen = { path = "../bindgen", version = "=0.69.0", default-features = false, features = ["__cli", "experimental"] } +bindgen = { path = "../bindgen", version = "=0.69.1", default-features = false, features = ["__cli", "experimental"] } clap = { version = "4", features = ["derive"] } clap_complete = "4" env_logger = { version = "0.10.0", optional = true } diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index 396bf6068e..18f43c0431 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -14,7 +14,7 @@ readme = "../README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.69.0" +version = "0.69.1" edition = "2018" build = "build.rs" # If you change this, also update README.md and msrv in .github/workflows/bindgen.yml From 4f9fa49ca907b831fdc3aecdfaec36b16d03c8d8 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Thu, 2 Nov 2023 12:51:25 -0500 Subject: [PATCH 591/942] Avoid syncing `master` with `main` --- .github/workflows/sync-master-from-main.yml | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 .github/workflows/sync-master-from-main.yml diff --git a/.github/workflows/sync-master-from-main.yml b/.github/workflows/sync-master-from-main.yml deleted file mode 100644 index 56142450ca..0000000000 --- a/.github/workflows/sync-master-from-main.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: sync master from main - -on: - push: - branches: - - main - -jobs: - sync-branches: - runs-on: ubuntu-latest - name: Keep master and main in sync until master is done - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Merge master <- main - uses: devmasx/merge-branch@master - with: - type: now - from_branch: main - target_branch: master - github_token: ${{ secrets.GITHUB_TOKEN }} From c006d5e501927b0b5afe10ab98504374af289cfd Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Tue, 28 Nov 2023 11:18:39 -0800 Subject: [PATCH 592/942] Flatten cursor.kind() matching in Item::parse down to one match --- bindgen/ir/item.rs | 84 ++++++++++++++++++++++------------------------ 1 file changed, 41 insertions(+), 43 deletions(-) diff --git a/bindgen/ir/item.rs b/bindgen/ir/item.rs index 0556452bfa..4f2d361e51 100644 --- a/bindgen/ir/item.rs +++ b/bindgen/ir/item.rs @@ -1432,57 +1432,55 @@ impl Item { } } - // Guess how does clang treat extern "C" blocks? - if cursor.kind() == CXCursor_UnexposedDecl { - Err(ParseError::Recurse) - } else { + match cursor.kind() { + // Guess how does clang treat extern "C" blocks? + CXCursor_UnexposedDecl => Err(ParseError::Recurse), + // We allowlist cursors here known to be unhandled, to prevent being // too noisy about this. - match cursor.kind() { - CXCursor_MacroDefinition | - CXCursor_MacroExpansion | - CXCursor_UsingDeclaration | - CXCursor_UsingDirective | - CXCursor_StaticAssert | - CXCursor_FunctionTemplate => { - debug!( - "Unhandled cursor kind {:?}: {:?}", - cursor.kind(), - cursor - ); - } - CXCursor_InclusionDirective => { - let file = cursor.get_included_file_name(); - match file { - None => { - warn!( - "Inclusion of a nameless file in {:?}", - cursor - ); - } - Some(included_file) => { - for cb in &ctx.options().parse_callbacks { - cb.include_file(&included_file); - } + CXCursor_MacroDefinition | + CXCursor_MacroExpansion | + CXCursor_UsingDeclaration | + CXCursor_UsingDirective | + CXCursor_StaticAssert | + CXCursor_FunctionTemplate => { + debug!( + "Unhandled cursor kind {:?}: {:?}", + cursor.kind(), + cursor + ); + Err(ParseError::Continue) + } - ctx.add_dep(included_file.into_boxed_str()); - } + CXCursor_InclusionDirective => { + let file = cursor.get_included_file_name(); + match file { + None => { + warn!("Inclusion of a nameless file in {:?}", cursor); } - } - _ => { - // ignore toplevel operator overloads - let spelling = cursor.spelling(); - if !spelling.starts_with("operator") { - warn!( - "Unhandled cursor kind {:?}: {:?}", - cursor.kind(), - cursor - ); + Some(included_file) => { + for cb in &ctx.options().parse_callbacks { + cb.include_file(&included_file); + } + + ctx.add_dep(included_file.into_boxed_str()); } } + Err(ParseError::Continue) } - Err(ParseError::Continue) + _ => { + // ignore toplevel operator overloads + let spelling = cursor.spelling(); + if !spelling.starts_with("operator") { + warn!( + "Unhandled cursor kind {:?}: {:?}", + cursor.kind(), + cursor + ); + } + Err(ParseError::Continue) + } } } From 86f3dbe846020e2ba573d6eb38d1434d0cbcbb40 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Tue, 28 Nov 2023 11:21:18 -0800 Subject: [PATCH 593/942] Handle CXCursor_LinkageSpec in Clang 18+ --- bindgen/ir/item.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bindgen/ir/item.rs b/bindgen/ir/item.rs index 4f2d361e51..dd587b088b 100644 --- a/bindgen/ir/item.rs +++ b/bindgen/ir/item.rs @@ -1433,8 +1433,11 @@ impl Item { } match cursor.kind() { - // Guess how does clang treat extern "C" blocks? - CXCursor_UnexposedDecl => Err(ParseError::Recurse), + // On Clang 18+, extern "C" is reported accurately as a LinkageSpec. + // Older LLVM treat it as UnexposedDecl. + CXCursor_LinkageSpec | CXCursor_UnexposedDecl => { + Err(ParseError::Recurse) + } // We allowlist cursors here known to be unhandled, to prevent being // too noisy about this. From b6ff60930a0a670f4feda5688d2b156f3775e434 Mon Sep 17 00:00:00 2001 From: usamoi Date: Mon, 11 Dec 2023 21:11:43 +0800 Subject: [PATCH 594/942] prevent panic when compiling aarch64 vectorcall functions --- bindgen/ir/function.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/bindgen/ir/function.rs b/bindgen/ir/function.rs index 5bfb70eff1..6342758f9f 100644 --- a/bindgen/ir/function.rs +++ b/bindgen/ir/function.rs @@ -303,6 +303,7 @@ fn get_abi(cc: CXCallingConv) -> ClangAbi { CXCallingConv_X86VectorCall => ClangAbi::Known(Abi::Vectorcall), CXCallingConv_AAPCS => ClangAbi::Known(Abi::Aapcs), CXCallingConv_X86_64Win64 => ClangAbi::Known(Abi::Win64), + CXCallingConv_AArch64VectorCall => ClangAbi::Known(Abi::Vectorcall), other => ClangAbi::Unknown(other), } } From be197f333275671b37a230d7338b8b68b0c4c18d Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Mon, 11 Dec 2023 16:19:05 +0000 Subject: [PATCH 595/942] Consider alignment contribution from bitfields (#2680) --- .../tests/bitfield-32bit-overflow.rs | 2 +- .../tests/bitfield-method-same-name.rs | 2 +- .../expectations/tests/bitfield_align.rs | 1 - .../expectations/tests/bitfield_align_2.rs | 1 - .../tests/bitfield_method_mangling.rs | 1 - .../tests/bitfield_pragma_packed.rs | 96 ++++++++++++++++++- .../tests/default_visibility_crate.rs | 2 +- .../tests/default_visibility_private.rs | 2 +- ...bility_private_respects_cxx_access_spec.rs | 2 +- .../tests/expectations/tests/issue-1034.rs | 2 +- .../issue-1076-unnamed-bitfield-alignment.rs | 2 +- .../tests/expectations/tests/issue-1947.rs | 1 - .../tests/issue-739-pointer-wide-bitfield.rs | 1 - .../expectations/tests/jsval_layout_opaque.rs | 1 - .../tests/jsval_layout_opaque_1_0.rs | 1 - .../expectations/tests/only_bitfields.rs | 2 +- .../expectations/tests/union_bitfield.rs | 1 - .../tests/union_with_anon_struct_bitfield.rs | 1 - .../union_with_anon_struct_bitfield_1_0.rs | 1 - .../tests/headers/bitfield_pragma_packed.h | 11 +++ bindgen/codegen/struct_layout.rs | 4 +- 21 files changed, 115 insertions(+), 22 deletions(-) diff --git a/bindgen-tests/tests/expectations/tests/bitfield-32bit-overflow.rs b/bindgen-tests/tests/expectations/tests/bitfield-32bit-overflow.rs index cf04543654..ea126bbbc1 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-32bit-overflow.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-32bit-overflow.rs @@ -83,7 +83,7 @@ where } } } -#[repr(C, packed)] +#[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct MuchBitfield { pub _bitfield_align_1: [u8; 0], diff --git a/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs b/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs index 8cd1997a93..ce3ea41e75 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs @@ -83,7 +83,7 @@ where } } } -#[repr(C, packed)] +#[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { pub _bitfield_align_1: [u8; 0], diff --git a/bindgen-tests/tests/expectations/tests/bitfield_align.rs b/bindgen-tests/tests/expectations/tests/bitfield_align.rs index 559038ed3e..8002327981 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_align.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_align.rs @@ -332,7 +332,6 @@ impl A { } } #[repr(C)] -#[repr(align(4))] #[derive(Debug, Default, Copy, Clone)] pub struct B { pub _bitfield_align_1: [u32; 0], diff --git a/bindgen-tests/tests/expectations/tests/bitfield_align_2.rs b/bindgen-tests/tests/expectations/tests/bitfield_align_2.rs index dc49137e9b..963d86f9be 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_align_2.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_align_2.rs @@ -93,7 +93,6 @@ pub enum MyEnum { FOUR = 3, } #[repr(C)] -#[repr(align(8))] #[derive(Debug, Copy, Clone)] pub struct TaggedPtr { pub _bitfield_align_1: [u64; 0], diff --git a/bindgen-tests/tests/expectations/tests/bitfield_method_mangling.rs b/bindgen-tests/tests/expectations/tests/bitfield_method_mangling.rs index ea1502eb61..7104682ea8 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_method_mangling.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_method_mangling.rs @@ -84,7 +84,6 @@ where } } #[repr(C)] -#[repr(align(4))] #[derive(Debug, Default, Copy, Clone)] pub struct mach_msg_type_descriptor_t { pub _bitfield_align_1: [u32; 0], diff --git a/bindgen-tests/tests/expectations/tests/bitfield_pragma_packed.rs b/bindgen-tests/tests/expectations/tests/bitfield_pragma_packed.rs index c37b42f2fd..e3168f51ea 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_pragma_packed.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_pragma_packed.rs @@ -83,7 +83,7 @@ where } } } -#[repr(C, packed)] +#[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Struct { pub _bitfield_align_1: [u8; 0], @@ -215,3 +215,97 @@ impl Struct { __bindgen_bitfield_unit } } +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Inner { + pub _bitfield_align_1: [u16; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, +} +#[test] +fn bindgen_test_layout_Inner() { + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Inner)), + ); + assert_eq!( + ::std::mem::align_of::(), + 2usize, + concat!("Alignment of ", stringify!(Inner)), + ); +} +impl Inner { + #[inline] + pub fn a(&self) -> ::std::os::raw::c_ushort { + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 16u8) as u16) } + } + #[inline] + pub fn set_a(&mut self, val: ::std::os::raw::c_ushort) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + self._bitfield_1.set(0usize, 16u8, val as u64) + } + } + #[inline] + pub fn b(&self) -> ::std::os::raw::c_ushort { + unsafe { ::std::mem::transmute(self._bitfield_1.get(16usize, 16u8) as u16) } + } + #[inline] + pub fn set_b(&mut self, val: ::std::os::raw::c_ushort) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + self._bitfield_1.set(16usize, 16u8, val as u64) + } + } + #[inline] + pub fn new_bitfield_1( + a: ::std::os::raw::c_ushort, + b: ::std::os::raw::c_ushort, + ) -> __BindgenBitfieldUnit<[u8; 4usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 16u8, + { + let a: u16 = unsafe { ::std::mem::transmute(a) }; + a as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 16usize, + 16u8, + { + let b: u16 = unsafe { ::std::mem::transmute(b) }; + b as u64 + }, + ); + __bindgen_bitfield_unit + } +} +#[repr(C, packed)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Outer { + pub inner: Inner, +} +#[test] +fn bindgen_test_layout_Outer() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(Outer)), + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Outer)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).inner) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Outer), "::", stringify!(inner)), + ); +} diff --git a/bindgen-tests/tests/expectations/tests/default_visibility_crate.rs b/bindgen-tests/tests/expectations/tests/default_visibility_crate.rs index f75a06e984..aef1a61a08 100644 --- a/bindgen-tests/tests/expectations/tests/default_visibility_crate.rs +++ b/bindgen-tests/tests/expectations/tests/default_visibility_crate.rs @@ -89,7 +89,7 @@ pub struct Point { pub(crate) x: ::std::os::raw::c_int, pub(crate) y: ::std::os::raw::c_int, } -#[repr(C, packed)] +#[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Color { pub(crate) _bitfield_align_1: [u8; 0], diff --git a/bindgen-tests/tests/expectations/tests/default_visibility_private.rs b/bindgen-tests/tests/expectations/tests/default_visibility_private.rs index 9bd6409f4f..8b3099c0d8 100644 --- a/bindgen-tests/tests/expectations/tests/default_visibility_private.rs +++ b/bindgen-tests/tests/expectations/tests/default_visibility_private.rs @@ -89,7 +89,7 @@ pub struct Point { x: ::std::os::raw::c_int, y: ::std::os::raw::c_int, } -#[repr(C, packed)] +#[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Color { _bitfield_align_1: [u8; 0], diff --git a/bindgen-tests/tests/expectations/tests/default_visibility_private_respects_cxx_access_spec.rs b/bindgen-tests/tests/expectations/tests/default_visibility_private_respects_cxx_access_spec.rs index a8b0d29733..29fbb3a893 100644 --- a/bindgen-tests/tests/expectations/tests/default_visibility_private_respects_cxx_access_spec.rs +++ b/bindgen-tests/tests/expectations/tests/default_visibility_private_respects_cxx_access_spec.rs @@ -89,7 +89,7 @@ pub struct Point { pub x: ::std::os::raw::c_int, pub y: ::std::os::raw::c_int, } -#[repr(C, packed)] +#[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Color { _bitfield_align_1: [u8; 0], diff --git a/bindgen-tests/tests/expectations/tests/issue-1034.rs b/bindgen-tests/tests/expectations/tests/issue-1034.rs index 0bd7647aa0..7848090fba 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1034.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1034.rs @@ -83,7 +83,7 @@ where } } } -#[repr(C, packed)] +#[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct S2 { pub _bitfield_align_1: [u8; 0], diff --git a/bindgen-tests/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs b/bindgen-tests/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs index d88806954f..89c09cc62f 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs @@ -83,7 +83,7 @@ where } } } -#[repr(C, packed)] +#[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct S1 { pub _bitfield_align_1: [u8; 0], diff --git a/bindgen-tests/tests/expectations/tests/issue-1947.rs b/bindgen-tests/tests/expectations/tests/issue-1947.rs index 24aa354814..be623357d0 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1947.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1947.rs @@ -86,7 +86,6 @@ where pub type U8 = ::std::os::raw::c_uchar; pub type U16 = ::std::os::raw::c_ushort; #[repr(C)] -#[repr(align(2))] #[derive(Debug, Default, Copy, Clone)] pub struct V56AMDY { pub _bitfield_align_1: [u16; 0], diff --git a/bindgen-tests/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs b/bindgen-tests/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs index adea1cbe56..7bc9933697 100644 --- a/bindgen-tests/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs @@ -85,7 +85,6 @@ where } } #[repr(C)] -#[repr(align(8))] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { pub _bitfield_align_1: [u64; 0], diff --git a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs index 735cebfb25..576f57586a 100644 --- a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs +++ b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs @@ -181,7 +181,6 @@ pub union jsval_layout { pub asUIntPtr: usize, } #[repr(C)] -#[repr(align(8))] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct jsval_layout__bindgen_ty_1 { pub _bitfield_align_1: [u64; 0], diff --git a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs index 2e64796b5f..0889b65232 100644 --- a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs @@ -229,7 +229,6 @@ pub struct jsval_layout { pub struct jsval_layout__bindgen_ty_1 { pub _bitfield_align_1: [u64; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 8usize]>, - pub __bindgen_align: [u64; 0usize], } #[test] fn bindgen_test_layout_jsval_layout__bindgen_ty_1() { diff --git a/bindgen-tests/tests/expectations/tests/only_bitfields.rs b/bindgen-tests/tests/expectations/tests/only_bitfields.rs index 42ea60f1aa..fe216f4b56 100644 --- a/bindgen-tests/tests/expectations/tests/only_bitfields.rs +++ b/bindgen-tests/tests/expectations/tests/only_bitfields.rs @@ -83,7 +83,7 @@ where } } } -#[repr(C, packed)] +#[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct C { pub _bitfield_align_1: [u8; 0], diff --git a/bindgen-tests/tests/expectations/tests/union_bitfield.rs b/bindgen-tests/tests/expectations/tests/union_bitfield.rs index 096c0371a6..7f4bd37f35 100644 --- a/bindgen-tests/tests/expectations/tests/union_bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/union_bitfield.rs @@ -142,7 +142,6 @@ impl U4 { } } #[repr(C)] -#[repr(align(4))] #[derive(Copy, Clone)] pub union B { pub _bitfield_align_1: [u32; 0], diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield.rs index 2f99027158..48a1bda9dc 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield.rs @@ -90,7 +90,6 @@ pub union foo { pub __bindgen_anon_1: foo__bindgen_ty_1, } #[repr(C)] -#[repr(align(4))] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct foo__bindgen_ty_1 { pub _bitfield_align_1: [u32; 0], diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs index dec7fc29ea..530cb7ea6a 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs @@ -138,7 +138,6 @@ pub struct foo { pub struct foo__bindgen_ty_1 { pub _bitfield_align_1: [u32; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, - pub __bindgen_align: [u32; 0usize], } #[test] fn bindgen_test_layout_foo__bindgen_ty_1() { diff --git a/bindgen-tests/tests/headers/bitfield_pragma_packed.h b/bindgen-tests/tests/headers/bitfield_pragma_packed.h index b4011ca844..c18b80ddfc 100644 --- a/bindgen-tests/tests/headers/bitfield_pragma_packed.h +++ b/bindgen-tests/tests/headers/bitfield_pragma_packed.h @@ -7,3 +7,14 @@ struct Struct { unsigned char e : 8; }; #pragma pack(pop) + +struct Inner { + unsigned short a: 16; + unsigned short b: 16; +}; + +#pragma pack(push, 1) +struct Outer { + struct Inner inner; +}; +#pragma pop diff --git a/bindgen/codegen/struct_layout.rs b/bindgen/codegen/struct_layout.rs index 5673060361..83d7836118 100644 --- a/bindgen/codegen/struct_layout.rs +++ b/bindgen/codegen/struct_layout.rs @@ -156,9 +156,7 @@ impl<'a> StructLayoutTracker<'a> { self.latest_field_layout = Some(layout); self.last_field_was_bitfield = true; - // NB: We intentionally don't update the max_field_align here, since our - // bitfields code doesn't necessarily guarantee it, so we need to - // actually generate the dummy alignment. + self.max_field_align = cmp::max(self.max_field_align, layout.align); } /// Returns a padding field if necessary for a given new field _before_ From d77e53ed8398743bf68831d25063719fa0f4f136 Mon Sep 17 00:00:00 2001 From: sagudev <16504129+sagudev@users.noreply.github.com> Date: Fri, 20 Oct 2023 18:50:54 +0200 Subject: [PATCH 596/942] Support float16 --- .../tests/expectations/tests/float16.rs | 66 +++++++++++++++++++ bindgen-tests/tests/headers/float16.h | 36 ++++++++++ bindgen/codegen/helpers.rs | 9 +++ bindgen/codegen/mod.rs | 17 +++++ bindgen/codegen/serialize.rs | 2 + bindgen/ir/context.rs | 16 +++++ bindgen/ir/ty.rs | 2 + 7 files changed, 148 insertions(+) create mode 100644 bindgen-tests/tests/expectations/tests/float16.rs create mode 100644 bindgen-tests/tests/headers/float16.h diff --git a/bindgen-tests/tests/expectations/tests/float16.rs b/bindgen-tests/tests/expectations/tests/float16.rs new file mode 100644 index 0000000000..b5471b1efa --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/float16.rs @@ -0,0 +1,66 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[derive(PartialEq, Copy, Clone, Hash, Debug, Default)] +#[repr(transparent)] +pub struct __BindgenFloat16(pub u16); +extern "C" { + pub static mut global: __BindgenFloat16; +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone, PartialEq)] +pub struct Test__Float16 { + pub f: __BindgenFloat16, +} +#[test] +fn bindgen_test_layout_Test__Float16() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 2usize, + concat!("Size of: ", stringify!(Test__Float16)), + ); + assert_eq!( + ::std::mem::align_of::(), + 2usize, + concat!("Alignment of ", stringify!(Test__Float16)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Test__Float16), "::", stringify!(f)), + ); +} +#[repr(C)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +pub struct Test__Float16Ref { + pub f: *mut __BindgenFloat16, +} +#[test] +fn bindgen_test_layout_Test__Float16Ref() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(Test__Float16Ref)), + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(Test__Float16Ref)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Test__Float16Ref), "::", stringify!(f)), + ); +} +impl Default for Test__Float16Ref { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} diff --git a/bindgen-tests/tests/headers/float16.h b/bindgen-tests/tests/headers/float16.h new file mode 100644 index 0000000000..3b1058591d --- /dev/null +++ b/bindgen-tests/tests/headers/float16.h @@ -0,0 +1,36 @@ +// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq + +static __fp16 global; + +struct Test__Float16 +{ + __fp16 f; +}; + +struct Test__Float16Ref +{ + __fp16 *f; +}; + +/* +// This options are currently supported only on specific targets (eg. x86 with sse2) +_Float16 returns_f16(); + +void gets_f16(_Float16 arg); + +struct Test__Float16_Complex +{ + _Float16 _Complex mMember; +}; + +struct Test__Float16_ComplexPtr +{ + _Float16 _Complex *mMember; +}; + +_Float16 _Complex globalValueHalf; + +_Float16 _Complex returns_f16_complex(); + +void gets_f16_complex(_Float16 _Complex arg); +*/ \ No newline at end of file diff --git a/bindgen/codegen/helpers.rs b/bindgen/codegen/helpers.rs index 7ef44fe099..48bfe56dde 100644 --- a/bindgen/codegen/helpers.rs +++ b/bindgen/codegen/helpers.rs @@ -232,6 +232,15 @@ pub(crate) mod ast_ty { // // Also, maybe this one shouldn't be the default? match (fk, ctx.options().convert_floats) { + (FloatKind::Float16, _) => { + // TODO: do f16 when rust lands it + ctx.generated_bindgen_float16(); + if ctx.options().enable_cxx_namespaces { + syn::parse_quote! { root::__BindgenFloat16 } + } else { + syn::parse_quote! { __BindgenFloat16 } + } + } (FloatKind::Float, true) => syn::parse_quote! { f32 }, (FloatKind::Double, true) => syn::parse_quote! { f64 }, (FloatKind::Float, false) => raw_type(ctx, "c_float"), diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 8e13606345..c84320ce5b 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -578,6 +578,9 @@ impl CodeGenerator for Module { if result.saw_incomplete_array { utils::prepend_incomplete_array_types(ctx, &mut *result); } + if ctx.need_bindgen_float16_type() { + utils::prepend_float16_type(&mut *result); + } if ctx.need_bindgen_complex_type() { utils::prepend_complex_type(&mut *result); } @@ -5136,6 +5139,20 @@ pub(crate) mod utils { result.extend(old_items); } + pub(crate) fn prepend_float16_type( + result: &mut Vec, + ) { + let float16_type = quote! { + #[derive(PartialEq, Copy, Clone, Hash, Debug, Default)] + #[repr(transparent)] + pub struct __BindgenFloat16(pub u16); + }; + + let items = vec![float16_type]; + let old_items = mem::replace(result, items); + result.extend(old_items); + } + pub(crate) fn prepend_complex_type( result: &mut Vec, ) { diff --git a/bindgen/codegen/serialize.rs b/bindgen/codegen/serialize.rs index 02c4680263..9765a8bdf2 100644 --- a/bindgen/codegen/serialize.rs +++ b/bindgen/codegen/serialize.rs @@ -270,6 +270,7 @@ impl<'a> CSerialize<'a> for Type { write!(writer, "const ")?; } match float_kind { + FloatKind::Float16 => write!(writer, "_Float16")?, FloatKind::Float => write!(writer, "float")?, FloatKind::Double => write!(writer, "double")?, FloatKind::LongDouble => write!(writer, "long double")?, @@ -281,6 +282,7 @@ impl<'a> CSerialize<'a> for Type { write!(writer, "const ")?; } match float_kind { + FloatKind::Float16 => write!(writer, "_Float16 complex")?, FloatKind::Float => write!(writer, "float complex")?, FloatKind::Double => write!(writer, "double complex")?, FloatKind::LongDouble => { diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index c5e2832cc9..11048b70c8 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -386,6 +386,9 @@ pub(crate) struct BindgenContext { /// Whether a bindgen complex was generated generated_bindgen_complex: Cell, + /// Whether a bindgen float16 was generated + generated_bindgen_float16: Cell, + /// The set of `ItemId`s that are allowlisted. This the very first thing /// computed after parsing our IR, and before running any of our analyses. allowlisted: Option, @@ -585,6 +588,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" target_info, options, generated_bindgen_complex: Cell::new(false), + generated_bindgen_float16: Cell::new(false), allowlisted: None, blocklisted_types_implement_traits: Default::default(), codegen_items: None, @@ -2005,6 +2009,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" CXType_ULongLong => TypeKind::Int(IntKind::ULongLong), CXType_Int128 => TypeKind::Int(IntKind::I128), CXType_UInt128 => TypeKind::Int(IntKind::U128), + CXType_Float16 | CXType_Half => TypeKind::Float(FloatKind::Float16), CXType_Float => TypeKind::Float(FloatKind::Float), CXType_Double => TypeKind::Float(FloatKind::Double), CXType_LongDouble => TypeKind::Float(FloatKind::LongDouble), @@ -2013,6 +2018,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" let float_type = ty.elem_type().expect("Not able to resolve complex type?"); let float_kind = match float_type.kind() { + CXType_Float16 | CXType_Half => FloatKind::Float16, CXType_Float => FloatKind::Float, CXType_Double => FloatKind::Double, CXType_LongDouble => FloatKind::LongDouble, @@ -2528,6 +2534,16 @@ If you encounter an error missing from this list, please file an issue or a PR!" self.generated_bindgen_complex.get() } + /// Call if a bindgen float16 is generated + pub(crate) fn generated_bindgen_float16(&self) { + self.generated_bindgen_float16.set(true) + } + + /// Whether we need to generate the bindgen float16 type + pub(crate) fn need_bindgen_float16_type(&self) -> bool { + self.generated_bindgen_float16.get() + } + /// Compute which `enum`s have an associated `typedef` definition. fn compute_enum_typedef_combos(&mut self) { let _t = self.timer("compute_enum_typedef_combos"); diff --git a/bindgen/ir/ty.rs b/bindgen/ir/ty.rs index 1aee065970..b7a429323e 100644 --- a/bindgen/ir/ty.rs +++ b/bindgen/ir/ty.rs @@ -558,6 +558,8 @@ impl TemplateParameters for TypeKind { /// The kind of float this type represents. #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub(crate) enum FloatKind { + /// A half (`_Float16` or `__fp16`) + Float16, /// A `float`. Float, /// A `double`. From 4f1125cd67c936ccc7fab22f6d3ca3059ee286b5 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Thu, 14 Dec 2023 21:05:24 +0100 Subject: [PATCH 597/942] Use `\r\n` on windows (#2698) --- bindgen/lib.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 54348e2232..70aa67149f 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -927,22 +927,24 @@ impl Bindings { /// Write these bindings as source text to the given `Write`able. pub fn write<'a>(&self, mut writer: Box) -> io::Result<()> { + const NL: &str = if cfg!(windows) { "\r\n" } else { "\n" }; + if !self.options.disable_header_comment { let version = option_env!("CARGO_PKG_VERSION").unwrap_or("(unknown version)"); - let header = format!( - "/* automatically generated by rust-bindgen {version} */\n\n", - ); - writer.write_all(header.as_bytes())?; + writeln!( + writer, + "/* automatically generated by rust-bindgen {version} */{NL}", + )?; } for line in self.options.raw_lines.iter() { writer.write_all(line.as_bytes())?; - writer.write_all("\n".as_bytes())?; + writer.write_all(NL.as_bytes())?; } if !self.options.raw_lines.is_empty() { - writer.write_all("\n".as_bytes())?; + writer.write_all(NL.as_bytes())?; } match self.format_tokens(&self.module) { From 138cdae857508326e1fcfdc8c3bccd29d88da149 Mon Sep 17 00:00:00 2001 From: Andrei Damian Date: Wed, 18 Oct 2023 21:24:32 +0300 Subject: [PATCH 598/942] better working destructors on windows --- bindgen/clang.rs | 19 +++++++++++++++++++ bindgen/ir/context.rs | 7 ++++++- bindgen/ir/function.rs | 7 ++++--- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/bindgen/clang.rs b/bindgen/clang.rs index 3438bfa2c4..4a4ed89d69 100644 --- a/bindgen/clang.rs +++ b/bindgen/clang.rs @@ -2297,6 +2297,15 @@ impl Drop for EvalResult { unsafe { clang_EvalResult_dispose(self.x) }; } } +/// ABI kinds as defined in +/// +#[derive(Debug, Eq, PartialEq, Copy, Clone)] +pub(crate) enum ABIKind { + /// All the regular targets like Linux, Mac, WASM, etc. implement the Itanium ABI + GenericItanium, + /// The ABI used when compiling for the MSVC target + Microsoft, +} /// Target information obtained from libclang. #[derive(Debug)] @@ -2305,6 +2314,8 @@ pub(crate) struct TargetInfo { pub(crate) triple: String, /// The width of the pointer _in bits_. pub(crate) pointer_width: usize, + /// The ABI of the target + pub(crate) abi: ABIKind, } impl TargetInfo { @@ -2320,9 +2331,17 @@ impl TargetInfo { } assert!(pointer_width > 0); assert_eq!(pointer_width % 8, 0); + + let abi = if triple.contains("msvc") { + ABIKind::Microsoft + } else { + ABIKind::GenericItanium + }; + TargetInfo { triple, pointer_width: pointer_width as usize, + abi, } } } diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index 11048b70c8..517d3365b6 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -19,7 +19,7 @@ use super::module::{Module, ModuleKind}; use super::template::{TemplateInstantiation, TemplateParameters}; use super::traversal::{self, Edge, ItemTraversal}; use super::ty::{FloatKind, Type, TypeKind}; -use crate::clang::{self, Cursor}; +use crate::clang::{self, ABIKind, Cursor}; use crate::codegen::CodegenError; use crate::BindgenOptions; use crate::{Entry, HashMap, HashSet}; @@ -626,6 +626,11 @@ If you encounter an error missing from this list, please file an issue or a PR!" self.target_info.pointer_width / 8 } + /// Returns the ABI, which is mostly useful for determining the mangling kind. + pub(crate) fn abi_kind(&self) -> ABIKind { + self.target_info.abi + } + /// Get the stack of partially parsed types that we are in the middle of /// parsing. pub(crate) fn currently_parsed_types(&self) -> &[PartialType] { diff --git a/bindgen/ir/function.rs b/bindgen/ir/function.rs index 6342758f9f..6679a3d509 100644 --- a/bindgen/ir/function.rs +++ b/bindgen/ir/function.rs @@ -7,7 +7,7 @@ use super::item::Item; use super::traversal::{EdgeKind, Trace, Tracer}; use super::ty::TypeKind; use crate::callbacks::{ItemInfo, ItemKind}; -use crate::clang::{self, Attribute}; +use crate::clang::{self, ABIKind, Attribute}; use crate::parse::{ClangSubItemParser, ParseError, ParseResult}; use clang_sys::{self, CXCallingConv}; @@ -324,11 +324,12 @@ pub(crate) fn cursor_mangling( return None; } + let is_itanium_abi = ctx.abi_kind() == ABIKind::GenericItanium; let is_destructor = cursor.kind() == clang_sys::CXCursor_Destructor; if let Ok(mut manglings) = cursor.cxx_manglings() { while let Some(m) = manglings.pop() { // Only generate the destructor group 1, see below. - if is_destructor && !m.ends_with("D1Ev") { + if is_itanium_abi && is_destructor && !m.ends_with("D1Ev") { continue; } @@ -341,7 +342,7 @@ pub(crate) fn cursor_mangling( return None; } - if is_destructor { + if is_itanium_abi && is_destructor { // With old (3.8-) libclang versions, and the Itanium ABI, clang returns // the "destructor group 0" symbol, which means that it'll try to free // memory, which definitely isn't what we want. From 5ff913ab3349db1905cfbbf44a9121cbc223249d Mon Sep 17 00:00:00 2001 From: Andrei Damian Date: Sun, 17 Dec 2023 20:22:34 +0200 Subject: [PATCH 599/942] win destructor test --- .../tests/expectations/tests/win32-dtors.rs | 201 ++++++++++++++++++ bindgen-tests/tests/headers/win32-dtors.hpp | 29 +++ 2 files changed, 230 insertions(+) create mode 100644 bindgen-tests/tests/expectations/tests/win32-dtors.rs create mode 100644 bindgen-tests/tests/headers/win32-dtors.hpp diff --git a/bindgen-tests/tests/expectations/tests/win32-dtors.rs b/bindgen-tests/tests/expectations/tests/win32-dtors.rs new file mode 100644 index 0000000000..8739ef4be8 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/win32-dtors.rs @@ -0,0 +1,201 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[repr(C)] +#[derive(Debug, Default)] +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, + concat!("Size of: ", stringify!(CppObj)), + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(CppObj)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(CppObj), "::", stringify!(x)), + ); +} +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" { + #[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 + } + #[inline] + pub unsafe fn destruct(&mut self) { + CppObj_CppObj_destructor(self) + } +} +#[repr(C)] +pub struct CppObj2__bindgen_vtable(::std::os::raw::c_void); +#[repr(C)] +#[derive(Debug)] +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, + concat!("Size of: ", stringify!(CppObj2)), + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(CppObj2)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, + 8usize, + concat!("Offset of field: ", stringify!(CppObj2), "::", stringify!(x)), + ); +} +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 { + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } + } +} +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 + } +} +extern "C" { + #[link_name = "\u{1}??1CppObj2@@UEAA@XZ"] + pub fn CppObj2_CppObj2_destructor(this: *mut CppObj2); +} +#[repr(C)] +#[derive(Debug)] +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, + concat!("Size of: ", stringify!(CppObj3)), + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(CppObj3)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, + 16usize, + concat!("Offset of field: ", stringify!(CppObj3), "::", stringify!(x)), + ); +} +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 { + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } + } +} +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 + } +} +extern "C" { + #[link_name = "\u{1}??1CppObj3@@UEAA@XZ"] + pub fn CppObj3_CppObj3_destructor(this: *mut CppObj3); +} +#[repr(C)] +#[derive(Debug)] +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, + concat!("Size of: ", stringify!(CppObj4)), + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(CppObj4)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, + 16usize, + concat!("Offset of field: ", stringify!(CppObj4), "::", stringify!(x)), + ); +} +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 { + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } + } +} +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 + } +} +extern "C" { + #[link_name = "\u{1}??1CppObj4@@UEAA@XZ"] + pub fn CppObj4_CppObj4_destructor(this: *mut CppObj4); +} diff --git a/bindgen-tests/tests/headers/win32-dtors.hpp b/bindgen-tests/tests/headers/win32-dtors.hpp new file mode 100644 index 0000000000..dc9b0fdc6e --- /dev/null +++ b/bindgen-tests/tests/headers/win32-dtors.hpp @@ -0,0 +1,29 @@ +// bindgen-flags: --rust-target 1.0 -- --target=x86_64-pc-windows-msvc + +struct CppObj { + int x; + + CppObj(int x); + ~CppObj(); +}; + +struct CppObj2 { + int x; + + CppObj2(int x); + virtual ~CppObj2(); +}; + +struct CppObj3 : CppObj2 { + int x; + + CppObj3(int x); + virtual ~CppObj3(); +}; + +struct CppObj4 : CppObj2 { + int x; + + CppObj4(int x); + ~CppObj4(); +}; \ No newline at end of file From d0c2b1e3de54860cebb649af6fee2abca8410506 Mon Sep 17 00:00:00 2001 From: Ryan Lopopolo Date: Wed, 27 Dec 2023 10:36:35 -0500 Subject: [PATCH 600/942] Deactivate many `regex` Unicode crate features rust-lang/rust-bindgen#1643 disabled many deafault features of the `regex` crate but left the `unicode` meta feature enabled. With the `unicode` feature enabled and `bindgen` as a build dependency, `regex-syntax` (a direct dependency of the `regex` crate) takes 7 seconds to compile as a build dependency in my application. The `unicode` feature includes support for many Unicode character class lookups which I find unlikely that bindgen uses. From https://docs.rs/regex/latest/regex/#unicode-features: > - unicode-age - Provide the data for the Unicode Age property. This > makes it possible to use classes like `\p{Age:6.0}` to refer to all > codepoints first introduced in Unicode 6.0 > - unicode-bool - Provide the data for numerous Unicode boolean > properties. The full list is not included here, but contains > properties like `Alphabetic`, `Emoji`, `Lowercase`, `Math`, > `Uppercase` and `White_Space`. > - unicode-case - Provide the data for case insensitive matching using > Unicode's "simple loose matches" specification. > - unicode-gencat - Provide the data for Unicode general categories. > This includes, but is not limited to, `Decimal_Number`, `Letter`, > `Math_Symbol`, `Number` and `Punctuation`. > - unicode-script - Provide the data for Unicode scripts and script > extensions. This includes, but is not limited to, `Arabic`, `Cyrillic`, > `Hebrew`, `Latin` and `Thai`. > - unicode-segment - Provide the data necessary to provide the > properties used to implement the Unicode text segmentation > algorithms. This enables using classes like `\p{gcb=Extend}`, > `\p{wb=Katakana}` and `\p{sb=ATerm}`. I have retained the `unicode-perl` feature, which gives support for `\w`, `\s` and `\d`, because these character classes were required to get tests to pass. Removing support for these character classes removes the need to compile many data tables, which should significantly reduce compile times. --- bindgen/Cargo.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index 18f43c0431..2a01c6ca99 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -36,7 +36,7 @@ peeking_take_while = "0.1.2" prettyplease = { version = "0.2.7", optional = true, features = ["verbatim"] } proc-macro2 = { version = "1", default-features = false } quote = { version = "1", default-features = false } -regex = { version = "1.5", default-features = false, features = ["std", "unicode"] } +regex = { version = "1.5", default-features = false, features = ["std", "unicode-perl"] } rustc-hash = "1.0.1" shlex = "1" syn = { version = "2.0", features = ["full", "extra-traits", "visit-mut"] } @@ -53,9 +53,9 @@ experimental = ["dep:annotate-snippets"] ## The following features are for internal use and they shouldn't be used if ## you're not hacking on bindgen -# Features used by `bindgen-cli` +# Features used by `bindgen-cli` __cli = [] -# Features used for CI testing +# Features used for CI testing __testing_only_extra_assertions = [] __testing_only_libclang_9 = [] __testing_only_libclang_5 = [] From 11aeae4875af5d078db77106fcd3caf4a59c4227 Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Wed, 10 Jan 2024 18:09:03 +0100 Subject: [PATCH 601/942] Use at least `regex 1.5.1` to avoid build build failures without `perf-literal` feature When building a crate that depends on `bindgen` with `-Zminimal-features`, `cargo` ends up selecting `regex 1.5.0` which fails to compile when its `perf-literal` feature wasn't enabled. This was aptly fixed in `1.5.1`, albeit without yanking the `1.5.0` release. https://github.com/rust-lang/regex/issues/931 --- bindgen/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index 2a01c6ca99..7dd4d01d29 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -36,7 +36,7 @@ peeking_take_while = "0.1.2" prettyplease = { version = "0.2.7", optional = true, features = ["verbatim"] } proc-macro2 = { version = "1", default-features = false } quote = { version = "1", default-features = false } -regex = { version = "1.5", default-features = false, features = ["std", "unicode-perl"] } +regex = { version = "1.5.1", default-features = false, features = ["std", "unicode-perl"] } rustc-hash = "1.0.1" shlex = "1" syn = { version = "2.0", features = ["full", "extra-traits", "visit-mut"] } From 8fffbf85e98e75f38e438002d74988b97afde7ee Mon Sep 17 00:00:00 2001 From: Nathan Ringo Date: Thu, 11 Jan 2024 20:04:13 -0600 Subject: [PATCH 602/942] Fixes #2715. --- .../tests/expectations/tests/noreturn.rs | 8 +++++++ bindgen-tests/tests/headers/noreturn.hpp | 2 ++ bindgen/ir/function.rs | 22 +++++++++++++++---- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/bindgen-tests/tests/expectations/tests/noreturn.rs b/bindgen-tests/tests/expectations/tests/noreturn.rs index 2b9b316b5d..2081d3d44b 100644 --- a/bindgen-tests/tests/expectations/tests/noreturn.rs +++ b/bindgen-tests/tests/expectations/tests/noreturn.rs @@ -11,3 +11,11 @@ extern "C" { #[link_name = "\u{1}_Z1hv"] pub fn h() -> !; } +extern "C" { + #[link_name = "\u{1}_Z1iPFvvE"] + pub fn i(arg: ::std::option::Option !>); +} +extern "C" { + #[link_name = "\u{1}_Z1jPFvvE"] + pub fn j(arg: ::std::option::Option !>) -> !; +} diff --git a/bindgen-tests/tests/headers/noreturn.hpp b/bindgen-tests/tests/headers/noreturn.hpp index 4ce1e11e3f..bf9d58c7fa 100644 --- a/bindgen-tests/tests/headers/noreturn.hpp +++ b/bindgen-tests/tests/headers/noreturn.hpp @@ -2,3 +2,5 @@ _Noreturn void f(void); __attribute__((noreturn)) void g(void); [[noreturn]] void h(void); +void i(__attribute__((noreturn)) void (*arg)(void)); +__attribute__((noreturn)) void j(__attribute__((noreturn)) void (*arg)(void)); diff --git a/bindgen/ir/function.rs b/bindgen/ir/function.rs index 6679a3d509..448bcd22ea 100644 --- a/bindgen/ir/function.rs +++ b/bindgen/ir/function.rs @@ -505,10 +505,24 @@ impl FunctionSig { Default::default() }; - // This looks easy to break but the clang parser keeps the type spelling clean even if - // other attributes are added. - is_divergent = - is_divergent || ty.spelling().contains("__attribute__((noreturn))"); + // Check if the type contains __attribute__((noreturn)) outside of parentheses. This is + // somewhat fragile, but it seems to be the only way to get at this information as of + // libclang 9. + let ty_spelling = ty.spelling(); + let has_attribute_noreturn = ty_spelling + .match_indices("__attribute__((noreturn))") + .any(|(i, _)| { + let depth = ty_spelling[..i] + .bytes() + .filter_map(|ch| match ch { + b'(' => Some(1), + b')' => Some(-1), + _ => None, + }) + .sum::(); + depth == 0 + }); + is_divergent = is_divergent || has_attribute_noreturn; let is_method = kind == CXCursor_CXXMethod; let is_constructor = kind == CXCursor_Constructor; From 5ac0381f8a7365c34b83a7434dcbe279bc4a99cb Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Tue, 12 Dec 2023 17:28:00 +0000 Subject: [PATCH 603/942] Use field align if it's smaller than pack align Fixes #2695 --- bindgen/codegen/struct_layout.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bindgen/codegen/struct_layout.rs b/bindgen/codegen/struct_layout.rs index 83d7836118..a62da69534 100644 --- a/bindgen/codegen/struct_layout.rs +++ b/bindgen/codegen/struct_layout.rs @@ -212,7 +212,10 @@ impl<'a> StructLayoutTracker<'a> { 0 } else if !self.is_packed { self.padding_bytes(field_layout) - } else if let Some(l) = self.known_type_layout { + } else if let Some(mut l) = self.known_type_layout { + if field_layout.align < l.align { + l.align = field_layout.align; + } self.padding_bytes(l) } else { 0 From 5dd7648811c236810fad3bdfa71f86f999789672 Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Fri, 12 Jan 2024 23:32:49 +0000 Subject: [PATCH 604/942] add a test case for issue #2695 --- .../tests/expectations/tests/issue-2695.rs | 45 +++++++++++++++++++ bindgen-tests/tests/headers/issue-2695.h | 10 +++++ 2 files changed, 55 insertions(+) create mode 100644 bindgen-tests/tests/expectations/tests/issue-2695.rs create mode 100644 bindgen-tests/tests/headers/issue-2695.h diff --git a/bindgen-tests/tests/expectations/tests/issue-2695.rs b/bindgen-tests/tests/expectations/tests/issue-2695.rs new file mode 100644 index 0000000000..ed559fb606 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/issue-2695.rs @@ -0,0 +1,45 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[repr(C, packed(2))] +#[derive(Debug, Default, Copy, Clone)] +pub struct Test { + pub x: ::std::os::raw::c_ulong, + pub a: ::std::os::raw::c_char, + pub b: ::std::os::raw::c_char, + pub c: ::std::os::raw::c_char, + pub __bindgen_padding_0: u8, +} +#[test] +fn bindgen_test_layout_Test() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 12usize, + concat!("Size of: ", stringify!(Test)), + ); + assert_eq!( + ::std::mem::align_of::(), + 2usize, + concat!("Alignment of ", stringify!(Test)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(x)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 8usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(a)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 9usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(b)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, + 10usize, + concat!("Offset of field: ", stringify!(Test), "::", stringify!(c)), + ); +} diff --git a/bindgen-tests/tests/headers/issue-2695.h b/bindgen-tests/tests/headers/issue-2695.h new file mode 100644 index 0000000000..4fbcc39bf8 --- /dev/null +++ b/bindgen-tests/tests/headers/issue-2695.h @@ -0,0 +1,10 @@ +// bindgen-flags: --explicit-padding + +#pragma pack(2) + +struct Test { + unsigned long x; + char a; + char b; + char c; +}; From 588a75c1acb95300fae7dafd39891d4efba617be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sat, 13 Jan 2024 01:10:37 +0100 Subject: [PATCH 605/942] Document v0.69.2 release. This is just 0.69.1 with the llvm 18 fix. --- CHANGELOG.md | 186 +++++++++++++++++++++++++++------------------------ 1 file changed, 100 insertions(+), 86 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e3f2c9e98a..5f39caa1c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,178 +7,184 @@ - [Removed](#removed) - [Fixed](#fixed) - [Security](#security) -- [0.69.1 (2023-11-02)](#0691-2023-11-02) - - [Fixed](#fixed-1) -- [0.69.0 (2023-11-01)](#0690-2023-11-01) +- [0.69.2 (2024-01-13)](#0692-2024-01-13) - [Added](#added-1) - [Changed](#changed-1) - [Removed](#removed-1) - - [Fixed](#fixed-2) + - [Fixed](#fixed-1) - [Security](#security-1) -- [0.68.1](#0681) - - [Fixed](#fixed-3) -- [0.68.0](#0680) +- [0.69.1 (2023-11-02)](#0691-2023-11-02) + - [Fixed](#fixed-2) +- [0.69.0 (2023-11-01)](#0690-2023-11-01) - [Added](#added-2) - [Changed](#changed-2) - [Removed](#removed-2) + - [Fixed](#fixed-3) + - [Security](#security-2) +- [0.68.1](#0681) - [Fixed](#fixed-4) -- [0.67.0](#0670) -- [0.66.1](#0661) - - [Removed](#removed-3) -- [0.66.0](#0660) +- [0.68.0](#0680) - [Added](#added-3) - [Changed](#changed-3) - - [Removed](#removed-4) -- [0.65.1](#0651) + - [Removed](#removed-3) - [Fixed](#fixed-5) -- [0.65.0](#0650) +- [0.67.0](#0670) +- [0.66.1](#0661) + - [Removed](#removed-4) +- [0.66.0](#0660) - [Added](#added-4) - [Changed](#changed-4) - [Removed](#removed-5) -- [0.64.0](#0640) +- [0.65.1](#0651) + - [Fixed](#fixed-6) +- [0.65.0](#0650) - [Added](#added-5) - [Changed](#changed-5) -- [0.63.0](#0630) + - [Removed](#removed-6) +- [0.64.0](#0640) - [Added](#added-6) - [Changed](#changed-6) - - [Removed](#removed-6) -- [0.62.0](#0620) +- [0.63.0](#0630) - [Added](#added-7) - [Changed](#changed-7) - - [Fixed](#fixed-6) -- [0.61.0](#0610) + - [Removed](#removed-7) +- [0.62.0](#0620) - [Added](#added-8) - [Changed](#changed-8) - [Fixed](#fixed-7) -- [0.60.1](#0601) - - [Fixed](#fixed-8) -- [0.60.0](#0600) +- [0.61.0](#0610) - [Added](#added-9) - - [Fixed](#fixed-9) - [Changed](#changed-9) - - [Removed](#removed-7) + - [Fixed](#fixed-8) +- [0.60.1](#0601) + - [Fixed](#fixed-9) +- [0.60.0](#0600) + - [Added](#added-10) + - [Fixed](#fixed-10) + - [Changed](#changed-10) + - [Removed](#removed-8) - [0.59.2](#0592) - [0.59.1](#0591) - - [Fixed](#fixed-10) -- [0.59.0](#0590) - - [Added](#added-10) - [Fixed](#fixed-11) - - [Changed](#changed-10) -- [0.58.1](#0581) +- [0.59.0](#0590) - [Added](#added-11) -- [0.58.0](#0580) - - [Added](#added-12) - [Fixed](#fixed-12) - [Changed](#changed-11) - - [Deprecated](#deprecated) - - [Removed](#removed-8) - - [Fixed](#fixed-13) - - [Security](#security-2) -- [0.57.0](#0570) +- [0.58.1](#0581) + - [Added](#added-12) +- [0.58.0](#0580) - [Added](#added-13) + - [Fixed](#fixed-13) + - [Changed](#changed-12) + - [Deprecated](#deprecated) + - [Removed](#removed-9) - [Fixed](#fixed-14) -- [0.56.0](#0560) + - [Security](#security-3) +- [0.57.0](#0570) - [Added](#added-14) - - [Changed](#changed-12) - [Fixed](#fixed-15) -- [0.55.1](#0551) - - [Fixed](#fixed-16) -- [0.55.0](#0550) - - [Removed](#removed-9) +- [0.56.0](#0560) - [Added](#added-15) - [Changed](#changed-13) + - [Fixed](#fixed-16) +- [0.55.1](#0551) - [Fixed](#fixed-17) -- [0.54.1](#0541) +- [0.55.0](#0550) + - [Removed](#removed-10) - [Added](#added-16) - [Changed](#changed-14) - [Fixed](#fixed-18) -- [0.54.0](#0540) +- [0.54.1](#0541) - [Added](#added-17) - [Changed](#changed-15) - [Fixed](#fixed-19) -- [0.53.3](#0533) +- [0.54.0](#0540) - [Added](#added-18) + - [Changed](#changed-16) - [Fixed](#fixed-20) +- [0.53.3](#0533) + - [Added](#added-19) + - [Fixed](#fixed-21) - [0.53.2](#0532) - - [Changed](#changed-16) + - [Changed](#changed-17) - [0.53.1](#0531) - - [Added](#added-19) -- [0.53.0](#0530) - [Added](#added-20) - - [Changed](#changed-17) - - [Fixed](#fixed-21) -- [0.52.0](#0520) +- [0.53.0](#0530) - [Added](#added-21) - [Changed](#changed-18) - [Fixed](#fixed-22) -- [0.51.1](#0511) - - [Fixed](#fixed-23) +- [0.52.0](#0520) + - [Added](#added-22) - [Changed](#changed-19) -- [0.51.0](#0510) + - [Fixed](#fixed-23) +- [0.51.1](#0511) - [Fixed](#fixed-24) - [Changed](#changed-20) - - [Added](#added-22) -- [0.50.0](#0500) +- [0.51.0](#0510) + - [Fixed](#fixed-25) + - [Changed](#changed-21) - [Added](#added-23) -- [0.49.3](#0493) +- [0.50.0](#0500) - [Added](#added-24) +- [0.49.3](#0493) + - [Added](#added-25) - [0.49.2](#0492) - - [Changed](#changed-21) -- [0.49.1](#0491) - - [Fixed](#fixed-25) - [Changed](#changed-22) -- [0.49.0](#0490) - - [Added](#added-25) +- [0.49.1](#0491) - [Fixed](#fixed-26) - [Changed](#changed-23) -- [0.48.1](#0481) +- [0.49.0](#0490) + - [Added](#added-26) - [Fixed](#fixed-27) -- [0.48.0](#0480) - [Changed](#changed-24) +- [0.48.1](#0481) - [Fixed](#fixed-28) -- [0.47.4](#0474) - - [Added](#added-26) -- [0.47.3](#0473) +- [0.48.0](#0480) - [Changed](#changed-25) -- [0.47.2](#0472) - [Fixed](#fixed-29) -- [0.47.1](#0471) +- [0.47.4](#0474) + - [Added](#added-27) +- [0.47.3](#0473) - [Changed](#changed-26) +- [0.47.2](#0472) - [Fixed](#fixed-30) -- [0.47.0](#0470) +- [0.47.1](#0471) - [Changed](#changed-27) - [Fixed](#fixed-31) -- [0.33.1 .. 0.46.0](#0331--0460) - - [Added](#added-27) - - [Removed](#removed-10) +- [0.47.0](#0470) - [Changed](#changed-28) - [Fixed](#fixed-32) -- [0.33.1](#0331) +- [0.33.1 .. 0.46.0](#0331--0460) + - [Added](#added-28) + - [Removed](#removed-11) + - [Changed](#changed-29) - [Fixed](#fixed-33) +- [0.33.1](#0331) + - [Fixed](#fixed-34) - [0.33.0](#0330) - [0.32.2](#0322) - - [Fixed](#fixed-34) -- [0.32.1](#0321) - [Fixed](#fixed-35) -- [0.32.0](#0320) - - [Added](#added-28) - - [Changed](#changed-29) +- [0.32.1](#0321) - [Fixed](#fixed-36) -- [0.31.0](#0310) +- [0.32.0](#0320) - [Added](#added-29) - [Changed](#changed-30) - - [Deprecated](#deprecated-1) - - [Removed](#removed-11) - [Fixed](#fixed-37) -- [0.30.0](#0300) +- [0.31.0](#0310) - [Added](#added-30) - [Changed](#changed-31) - - [Deprecated](#deprecated-2) + - [Deprecated](#deprecated-1) + - [Removed](#removed-12) - [Fixed](#fixed-38) -- [0.29.0](#0290) +- [0.30.0](#0300) - [Added](#added-31) - [Changed](#changed-32) + - [Deprecated](#deprecated-2) - [Fixed](#fixed-39) +- [0.29.0](#0290) + - [Added](#added-32) + - [Changed](#changed-33) + - [Fixed](#fixed-40) @@ -190,6 +196,14 @@ ## Fixed ## Security +# 0.69.2 (2024-01-13) +## Added +## Changed +## Removed +## Fixed +- Fixed generation of extern "C" blocks with llvm 18+. See #2689. +## Security + # 0.69.1 (2023-11-02) ## Fixed From 308fe4bfc687983a43be3bdcf358b026fb767357 Mon Sep 17 00:00:00 2001 From: Rodrigo Rivas Costa Date: Wed, 11 Oct 2023 17:27:04 +0200 Subject: [PATCH 606/942] Add thiscall_abi to stable version Rust 1.73. 1.73 Changelog: - https://github.com/rust-lang/rust/releases/tag/1.73.0 Stabilization issue: - https://github.com/rust-lang/rust/pull/114562/ --- bindgen/features.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindgen/features.rs b/bindgen/features.rs index 67c6fb4565..e5e2068053 100644 --- a/bindgen/features.rs +++ b/bindgen/features.rs @@ -95,9 +95,9 @@ macro_rules! define_rust_targets { // not stable. define_rust_targets! { Nightly => { - thiscall_abi: #42202, vectorcall_abi, }, + Stable_1_73(73) => { thiscall_abi: #42202 }, Stable_1_71(71) => { c_unwind_abi: #106075 }, Stable_1_68(68) => { abi_efiapi: #105795 }, Stable_1_64(64) => { core_ffi_c: #94503 }, From 2ded089f793d99e642bbf9eb12d3bf1dbf6747f7 Mon Sep 17 00:00:00 2001 From: Rodrigo Rivas Costa Date: Wed, 18 Oct 2023 16:43:54 +0200 Subject: [PATCH 607/942] Add a thiscall_abi test for stable Rust 1.73. --- .../expectations/tests/win32-thiscall_1_73.rs | 41 +++++++++++++++++++ .../tests/headers/win32-thiscall_1_73.hpp | 7 ++++ 2 files changed, 48 insertions(+) create mode 100644 bindgen-tests/tests/expectations/tests/win32-thiscall_1_73.rs create mode 100644 bindgen-tests/tests/headers/win32-thiscall_1_73.hpp diff --git a/bindgen-tests/tests/expectations/tests/win32-thiscall_1_73.rs b/bindgen-tests/tests/expectations/tests/win32-thiscall_1_73.rs new file mode 100644 index 0000000000..2faedf1814 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/win32-thiscall_1_73.rs @@ -0,0 +1,41 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#![cfg(target = "i686-pc-windows-msvc")] +#[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, + concat!("Size of: ", stringify!(Foo)), + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(Foo)), + ); +} +extern "thiscall" { + #[link_name = "\u{1}?test@Foo@@QAEXXZ"] + pub fn Foo_test(this: *mut Foo); +} +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/headers/win32-thiscall_1_73.hpp b/bindgen-tests/tests/headers/win32-thiscall_1_73.hpp new file mode 100644 index 0000000000..8c240055b2 --- /dev/null +++ b/bindgen-tests/tests/headers/win32-thiscall_1_73.hpp @@ -0,0 +1,7 @@ +// bindgen-flags: --rust-target=1.73 --raw-line '#![cfg(target = "i686-pc-windows-msvc")]' -- --target=i686-pc-windows-msvc + +class Foo { + public: + void test(); + int test2(int var); +}; From b82746d15d6466a911217ac2edd458f8e41ed0f0 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 12 Jan 2024 21:38:30 -0500 Subject: [PATCH 608/942] Add a triagebot.toml file This allows non-maintainers to set labels with `@rustbot`. --- triagebot.toml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 triagebot.toml diff --git a/triagebot.toml b/triagebot.toml new file mode 100644 index 0000000000..c196fb3d4d --- /dev/null +++ b/triagebot.toml @@ -0,0 +1,28 @@ +[relabel] +allow-unauthenticated = [ + "A-*", + "C-*", + "E-*", + "I-*", + "S-*", + "bug", + "dependencies", + "enhancement", + "good first issue", + "hacktoberfest", + "help wanted", + "invalid", + "meta", + "msvc", + "next-release", + "question", + "This Week In Servo (TWiS)", + "windows", +] + +[autolabel."A-C++"] +trigger_files = [ + "**/*.cpp", + "**/*.cc", + "**/*.hpp", +] \ No newline at end of file From 9c59ac9ceb04a40b4b7a57397791fe334fb513ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sat, 13 Jan 2024 01:29:52 +0100 Subject: [PATCH 609/942] ci: Remove llvm 5, introduce llvm 16 LLVM 5 is ancient. --- .github/workflows/bindgen.yml | 19 +- CONTRIBUTING.md | 8 +- appveyor.yml | 12 +- bindgen-cli/Cargo.toml | 2 +- bindgen-cli/main.rs | 6 +- bindgen-integration/Cargo.toml | 2 +- bindgen-tests/Cargo.toml | 2 +- bindgen-tests/tests/expectations/build.rs | 2 +- .../{libclang-5 => }/abi_variadic_function.rs | 0 .../tests/{libclang-5 => }/auto.rs | 0 .../tests/{libclang-5 => }/call-conv-field.rs | 0 .../tests/expectations/tests/class.rs | 158 +++++ .../tests/expectations/tests/class_1_0.rs | 158 +++++ .../tests/{libclang-5 => }/const_bool.rs | 0 .../{libclang-5 => }/constant-evaluate.rs | 0 .../tests/constified-enum-module-overflow.rs | 15 +- ...erive-hash-struct-with-incomplete-array.rs | 46 ++ ...0600-cannot-apply-unary-negation-to-u32.rs | 0 .../tests/incomplete-array-padding.rs | 7 + .../tests/issue-544-stylo-creduce-2.rs | 5 +- .../tests/issue-643-inner-struct.rs | 22 + .../issue-769-bad-instantiation-test.rs | 0 .../tests/expectations/tests/layout_align.rs | 32 + .../libclang-5/inline_namespace_nested.rs | 1 - .../tests/libclang-5/issue-2556.rs | 1 - .../tests/libclang-5/objc_template.rs | 57 -- .../libclang-5/ptr32-has-different-size.rs | 41 -- .../tests/libclang-9/abi_variadic_function.rs | 5 - .../expectations/tests/libclang-9/auto.rs | 29 - .../tests/libclang-9/call-conv-field.rs | 50 -- .../expectations/tests/libclang-9/class.rs | 617 ---------------- .../tests/libclang-9/class_1_0.rs | 668 ------------------ .../tests/libclang-9/const_bool.rs | 19 - .../tests/libclang-9/constant-evaluate.rs | 19 - .../constified-enum-module-overflow.rs | 46 ++ ...erive-hash-struct-with-incomplete-array.rs | 154 ---- ...0600-cannot-apply-unary-negation-to-u32.rs | 3 - .../libclang-9/incomplete-array-padding.rs | 180 ----- .../libclang-9/issue-544-stylo-creduce-2.rs | 17 + .../libclang-9/issue-643-inner-struct.rs | 148 ---- .../issue-769-bad-instantiation-test.rs | 60 -- .../tests/libclang-9/layout_align.rs | 291 -------- .../tests/libclang-9/mangling-win32.rs | 46 -- .../tests/libclang-9/objc_inheritance.rs | 107 --- .../partial-specialization-and-inheritance.rs | 33 - .../tests/libclang-9/struct_typedef_ns.rs | 87 +++ .../type_alias_template_specialized.rs | 56 -- .../tests/libclang-9/zero-sized-array.rs | 170 ----- .../tests/{libclang-5 => }/mangling-win32.rs | 0 .../{libclang-5 => }/objc_inheritance.rs | 0 .../tests/{libclang-9 => }/objc_template.rs | 0 .../partial-specialization-and-inheritance.rs | 0 .../expectations/tests/struct_typedef_ns.rs | 21 +- .../type_alias_template_specialized.rs | 0 .../expectations/tests/zero-sized-array.rs | 24 + .../headers/issue-544-stylo-creduce-2.hpp | 7 + bindgen-tests/tests/stylo_sanity.rs | 4 +- bindgen-tests/tests/tests.rs | 16 +- bindgen/Cargo.toml | 2 +- ci/test.sh | 23 +- 60 files changed, 673 insertions(+), 2825 deletions(-) rename bindgen-tests/tests/expectations/tests/{libclang-5 => }/abi_variadic_function.rs (100%) rename bindgen-tests/tests/expectations/tests/{libclang-5 => }/auto.rs (100%) rename bindgen-tests/tests/expectations/tests/{libclang-5 => }/call-conv-field.rs (100%) rename bindgen-tests/tests/expectations/tests/{libclang-5 => }/const_bool.rs (100%) rename bindgen-tests/tests/expectations/tests/{libclang-5 => }/constant-evaluate.rs (100%) rename bindgen-tests/tests/expectations/tests/{libclang-5 => }/error-E0600-cannot-apply-unary-negation-to-u32.rs (100%) rename bindgen-tests/tests/expectations/tests/{libclang-5 => }/issue-769-bad-instantiation-test.rs (100%) delete mode 100644 bindgen-tests/tests/expectations/tests/libclang-5/inline_namespace_nested.rs delete mode 100644 bindgen-tests/tests/expectations/tests/libclang-5/issue-2556.rs delete mode 100644 bindgen-tests/tests/expectations/tests/libclang-5/objc_template.rs delete mode 100644 bindgen-tests/tests/expectations/tests/libclang-5/ptr32-has-different-size.rs delete mode 100644 bindgen-tests/tests/expectations/tests/libclang-9/abi_variadic_function.rs delete mode 100644 bindgen-tests/tests/expectations/tests/libclang-9/auto.rs delete mode 100644 bindgen-tests/tests/expectations/tests/libclang-9/call-conv-field.rs delete mode 100644 bindgen-tests/tests/expectations/tests/libclang-9/class.rs delete mode 100644 bindgen-tests/tests/expectations/tests/libclang-9/class_1_0.rs delete mode 100644 bindgen-tests/tests/expectations/tests/libclang-9/const_bool.rs delete mode 100644 bindgen-tests/tests/expectations/tests/libclang-9/constant-evaluate.rs create mode 100644 bindgen-tests/tests/expectations/tests/libclang-9/constified-enum-module-overflow.rs delete mode 100644 bindgen-tests/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs delete mode 100644 bindgen-tests/tests/expectations/tests/libclang-9/error-E0600-cannot-apply-unary-negation-to-u32.rs delete mode 100644 bindgen-tests/tests/expectations/tests/libclang-9/incomplete-array-padding.rs create mode 100644 bindgen-tests/tests/expectations/tests/libclang-9/issue-544-stylo-creduce-2.rs delete mode 100644 bindgen-tests/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs delete mode 100644 bindgen-tests/tests/expectations/tests/libclang-9/issue-769-bad-instantiation-test.rs delete mode 100644 bindgen-tests/tests/expectations/tests/libclang-9/layout_align.rs delete mode 100644 bindgen-tests/tests/expectations/tests/libclang-9/mangling-win32.rs delete mode 100644 bindgen-tests/tests/expectations/tests/libclang-9/objc_inheritance.rs delete mode 100644 bindgen-tests/tests/expectations/tests/libclang-9/partial-specialization-and-inheritance.rs create mode 100644 bindgen-tests/tests/expectations/tests/libclang-9/struct_typedef_ns.rs delete mode 100644 bindgen-tests/tests/expectations/tests/libclang-9/type_alias_template_specialized.rs delete mode 100644 bindgen-tests/tests/expectations/tests/libclang-9/zero-sized-array.rs rename bindgen-tests/tests/expectations/tests/{libclang-5 => }/mangling-win32.rs (100%) rename bindgen-tests/tests/expectations/tests/{libclang-5 => }/objc_inheritance.rs (100%) rename bindgen-tests/tests/expectations/tests/{libclang-9 => }/objc_template.rs (100%) rename bindgen-tests/tests/expectations/tests/{libclang-5 => }/partial-specialization-and-inheritance.rs (100%) rename bindgen-tests/tests/expectations/tests/{libclang-5 => }/type_alias_template_specialized.rs (100%) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 3f85cd862a..883fb46b5c 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -142,7 +142,7 @@ jobs: - debian: null cross: null rust: null - llvm_version: ["5.0", "9.0"] + llvm_version: ["9.0", "16.0"] main_tests: [1] release_build: [0, 1] no_default_features: [0, 1] @@ -155,7 +155,7 @@ jobs: # Test with extra asserts + docs just with latest llvm versions to # prevent explosion - os: ubuntu-latest - llvm_version: "9.0" + llvm_version: "16.0" release_build: 0 no_default_features: 0 feature_extra_asserts: 1 @@ -169,17 +169,20 @@ jobs: # debian: arm64 # cross: aarch64-linux-gnu # rust: aarch64-unknown-linux-gnu - # llvm_version: "9.0" + # llvm_version: "16.0" # main_tests: 0 # release_build: 0 # feature_extra_asserts: 0 # Ensure stuff works on macos too - - os: macos-latest - llvm_version: "9.0" - release_build: 0 - no_default_features: 0 - feature_extra_asserts: 0 + # Disabled for now because llvm doesn't provide releases for x86-64 + # macOS which is what the runner uses. + # + # - os: macos-latest + # llvm_version: "16.0" + # release_build: 0 + # no_default_features: 0 + # feature_extra_asserts: 0 steps: - uses: actions/checkout@v3 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7e5cdc53eb..62cf80742e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -208,8 +208,8 @@ can add multiple test expectations, one for each supported `libclang` version. Instead of having a single `bindgen-tests/tests/expectations/tests/my_test.rs` file, add each of: +* `bindgen-tests/tests/expectations/tests/libclang-16/my_test.rs` * `bindgen-tests/tests/expectations/tests/libclang-9/my_test.rs` -* `bindgen-tests/tests/expectations/tests/libclang-5/my_test.rs` If you need to update the test expectations for a test file that generates different bindings for different `libclang` versions, you *don't* need to have @@ -226,12 +226,6 @@ to check the bindings against with a cargo feature: $ cargo test --features __testing_only_libclang_$VERSION ``` -Where `$VERSION` is one of: - -* `4` -* `3_9` -* `3_8` - depending on which version of `libclang` you have installed. ### Integration Tests diff --git a/appveyor.yml b/appveyor.yml index 973b4cdf07..ffb74eedc6 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,18 +2,18 @@ environment: RUST_BACKTRACE: 1 RUST_CHANNEL: "%Configuration%" matrix: - - TARGET: gnu - LLVM_VERSION: 5.0.0-1 - BINDGEN_FEATURES: __testing_only_libclang_5 - TARGET: gnu LLVM_VERSION: 9.0.0-1 BINDGEN_FEATURES: __testing_only_libclang_9 - - TARGET: msvc - LLVM_VERSION: 5.0.0 - BINDGEN_FEATURES: __testing_only_libclang_5 + - TARGET: gnu + LLVM_VERSION: 16.0.4 + BINDGEN_FEATURES: __testing_only_libclang_16 - TARGET: msvc LLVM_VERSION: 9.0.0 BINDGEN_FEATURES: __testing_only_libclang_9 + - TARGET: msvc + LLVM_VERSION: 16.0.4 + BINDGEN_FEATURES: __testing_only_libclang_16 configuration: - stable diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index 2738952803..5e04cb0d80 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -40,7 +40,7 @@ which-rustfmt = ["bindgen/which-rustfmt"] # Features used for CI testing __testing_only_extra_assertions = ["bindgen/__testing_only_extra_assertions"] __testing_only_libclang_9 = ["bindgen/__testing_only_libclang_9"] -__testing_only_libclang_5 = ["bindgen/__testing_only_libclang_5"] +__testing_only_libclang_16 = ["bindgen/__testing_only_libclang_16"] [package.metadata.release] release = true diff --git a/bindgen-cli/main.rs b/bindgen-cli/main.rs index a3407232de..4b1bfad282 100644 --- a/bindgen-cli/main.rs +++ b/bindgen-cli/main.rs @@ -13,10 +13,10 @@ use crate::options::builder_from_flags; #[cfg(feature = "logging")] fn clang_version_check() { let version = bindgen::clang_version(); - let expected_version = if cfg!(feature = "__testing_only_libclang_9") { + let expected_version = if cfg!(feature = "__testing_only_libclang_16") { + Some((16, 0)) + } else if cfg!(feature = "__testing_only_libclang_9") { Some((9, 0)) - } else if cfg!(feature = "__testing_only_libclang_5") { - Some((5, 0)) } else { None }; diff --git a/bindgen-integration/Cargo.toml b/bindgen-integration/Cargo.toml index 6c9508ab93..ccdd1467df 100644 --- a/bindgen-integration/Cargo.toml +++ b/bindgen-integration/Cargo.toml @@ -16,4 +16,4 @@ runtime = ["bindgen/runtime"] __testing_only_extra_assertions = ["bindgen/__testing_only_extra_assertions"] __testing_only_libclang_9 = ["bindgen/__testing_only_libclang_9"] -__testing_only_libclang_5 = ["bindgen/__testing_only_libclang_5"] +__testing_only_libclang_16 = ["bindgen/__testing_only_libclang_16"] diff --git a/bindgen-tests/Cargo.toml b/bindgen-tests/Cargo.toml index d3907c3619..1c06c3f10d 100644 --- a/bindgen-tests/Cargo.toml +++ b/bindgen-tests/Cargo.toml @@ -23,4 +23,4 @@ which-rustfmt = ["bindgen/which-rustfmt"] __testing_only_extra_assertions = ["bindgen/__testing_only_extra_assertions"] __testing_only_libclang_9 = ["bindgen/__testing_only_libclang_9"] -__testing_only_libclang_5 = ["bindgen/__testing_only_libclang_5"] +__testing_only_libclang_16 = ["bindgen/__testing_only_libclang_16"] diff --git a/bindgen-tests/tests/expectations/build.rs b/bindgen-tests/tests/expectations/build.rs index 2111185384..6136823e21 100644 --- a/bindgen-tests/tests/expectations/build.rs +++ b/bindgen-tests/tests/expectations/build.rs @@ -8,7 +8,7 @@ use std::fs; use std::io::Write; use std::path::Path; -const LIBCLANG_VERSION_DIRS: &[&str] = &["libclang-5", "libclang-9"]; +const LIBCLANG_VERSION_DIRS: &[&str] = &["libclang-9"]; fn main() { println!("cargo:rerun-if-changed=build.rs"); diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/abi_variadic_function.rs b/bindgen-tests/tests/expectations/tests/abi_variadic_function.rs similarity index 100% rename from bindgen-tests/tests/expectations/tests/libclang-5/abi_variadic_function.rs rename to bindgen-tests/tests/expectations/tests/abi_variadic_function.rs diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/auto.rs b/bindgen-tests/tests/expectations/tests/auto.rs similarity index 100% rename from bindgen-tests/tests/expectations/tests/libclang-5/auto.rs rename to bindgen-tests/tests/expectations/tests/auto.rs diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/call-conv-field.rs b/bindgen-tests/tests/expectations/tests/call-conv-field.rs similarity index 100% rename from bindgen-tests/tests/expectations/tests/libclang-5/call-conv-field.rs rename to bindgen-tests/tests/expectations/tests/call-conv-field.rs diff --git a/bindgen-tests/tests/expectations/tests/class.rs b/bindgen-tests/tests/expectations/tests/class.rs index ce43204d73..19668a73dd 100644 --- a/bindgen-tests/tests/expectations/tests/class.rs +++ b/bindgen-tests/tests/expectations/tests/class.rs @@ -178,6 +178,8 @@ pub struct C_with_incomplete_array { } #[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, @@ -188,6 +190,36 @@ fn bindgen_test_layout_C_with_incomplete_array() { 4usize, concat!("Alignment of ", stringify!(C_with_incomplete_array)), ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array), + "::", + stringify!(a), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array), + "::", + stringify!(big_array), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array), + "::", + stringify!(incomplete_array), + ), + ); } impl Default for C_with_incomplete_array { fn default() -> Self { @@ -206,6 +238,8 @@ pub struct C_with_incomplete_array_2 { } #[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, @@ -216,6 +250,26 @@ fn bindgen_test_layout_C_with_incomplete_array_2() { 4usize, concat!("Alignment of ", stringify!(C_with_incomplete_array_2)), ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array_2), + "::", + stringify!(a), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array_2), + "::", + stringify!(incomplete_array), + ), + ); } #[repr(C)] pub struct C_with_zero_length_array_and_incomplete_array { @@ -226,6 +280,10 @@ pub struct C_with_zero_length_array_and_incomplete_array { } #[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, @@ -239,6 +297,48 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { stringify!(C_with_zero_length_array_and_incomplete_array), ), ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(a), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(big_array), + ), + ); + assert_eq!( + unsafe { + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize + }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(zero_length_array), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(incomplete_array), + ), + ); } impl Default for C_with_zero_length_array_and_incomplete_array { fn default() -> Self { @@ -258,6 +358,10 @@ pub struct C_with_zero_length_array_and_incomplete_array_2 { } #[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, @@ -271,6 +375,38 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { stringify!(C_with_zero_length_array_and_incomplete_array_2), ), ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), + "::", + stringify!(a), + ), + ); + assert_eq!( + unsafe { + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), + "::", + stringify!(zero_length_array), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), + "::", + stringify!(incomplete_array), + ), + ); } #[repr(C)] #[derive(Debug, Default, Hash, PartialOrd, Ord, PartialEq, Eq)] @@ -304,6 +440,8 @@ pub struct IncompleteArrayNonCopiable { } #[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, @@ -314,6 +452,26 @@ fn bindgen_test_layout_IncompleteArrayNonCopiable() { 8usize, concat!("Alignment of ", stringify!(IncompleteArrayNonCopiable)), ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).whatever) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(IncompleteArrayNonCopiable), + "::", + stringify!(whatever), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(IncompleteArrayNonCopiable), + "::", + stringify!(incomplete_array), + ), + ); } impl Default for IncompleteArrayNonCopiable { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/class_1_0.rs b/bindgen-tests/tests/expectations/tests/class_1_0.rs index 17cf118242..b6544212cf 100644 --- a/bindgen-tests/tests/expectations/tests/class_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/class_1_0.rs @@ -231,6 +231,8 @@ pub struct C_with_incomplete_array { } #[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, @@ -241,6 +243,36 @@ fn bindgen_test_layout_C_with_incomplete_array() { 4usize, concat!("Alignment of ", stringify!(C_with_incomplete_array)), ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array), + "::", + stringify!(a), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array), + "::", + stringify!(big_array), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array), + "::", + stringify!(incomplete_array), + ), + ); } impl Default for C_with_incomplete_array { fn default() -> Self { @@ -259,6 +291,8 @@ pub struct C_with_incomplete_array_2 { } #[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, @@ -269,6 +303,26 @@ fn bindgen_test_layout_C_with_incomplete_array_2() { 4usize, concat!("Alignment of ", stringify!(C_with_incomplete_array_2)), ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array_2), + "::", + stringify!(a), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_incomplete_array_2), + "::", + stringify!(incomplete_array), + ), + ); } #[repr(C)] pub struct C_with_zero_length_array_and_incomplete_array { @@ -279,6 +333,10 @@ pub struct C_with_zero_length_array_and_incomplete_array { } #[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, @@ -292,6 +350,48 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { stringify!(C_with_zero_length_array_and_incomplete_array), ), ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(a), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(big_array), + ), + ); + assert_eq!( + unsafe { + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize + }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(zero_length_array), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, + 37usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array), + "::", + stringify!(incomplete_array), + ), + ); } impl Default for C_with_zero_length_array_and_incomplete_array { fn default() -> Self { @@ -311,6 +411,10 @@ pub struct C_with_zero_length_array_and_incomplete_array_2 { } #[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, @@ -324,6 +428,38 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { stringify!(C_with_zero_length_array_and_incomplete_array_2), ), ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), + "::", + stringify!(a), + ), + ); + assert_eq!( + unsafe { + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), + "::", + stringify!(zero_length_array), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(C_with_zero_length_array_and_incomplete_array_2), + "::", + stringify!(incomplete_array), + ), + ); } #[repr(C)] #[derive(Debug, Default, Hash, PartialEq, Eq)] @@ -357,6 +493,8 @@ pub struct IncompleteArrayNonCopiable { } #[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, @@ -367,6 +505,26 @@ fn bindgen_test_layout_IncompleteArrayNonCopiable() { 8usize, concat!("Alignment of ", stringify!(IncompleteArrayNonCopiable)), ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).whatever) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(IncompleteArrayNonCopiable), + "::", + stringify!(whatever), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(IncompleteArrayNonCopiable), + "::", + stringify!(incomplete_array), + ), + ); } impl Default for IncompleteArrayNonCopiable { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/const_bool.rs b/bindgen-tests/tests/expectations/tests/const_bool.rs similarity index 100% rename from bindgen-tests/tests/expectations/tests/libclang-5/const_bool.rs rename to bindgen-tests/tests/expectations/tests/const_bool.rs diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/constant-evaluate.rs b/bindgen-tests/tests/expectations/tests/constant-evaluate.rs similarity index 100% rename from bindgen-tests/tests/expectations/tests/libclang-5/constant-evaluate.rs rename to bindgen-tests/tests/expectations/tests/constant-evaluate.rs diff --git a/bindgen-tests/tests/expectations/tests/constified-enum-module-overflow.rs b/bindgen-tests/tests/expectations/tests/constified-enum-module-overflow.rs index 49498deaa5..61e666d2a0 100644 --- a/bindgen-tests/tests/expectations/tests/constified-enum-module-overflow.rs +++ b/bindgen-tests/tests/expectations/tests/constified-enum-module-overflow.rs @@ -13,7 +13,7 @@ pub type C_U = B; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct A { - pub u: u8, + pub u: B, } #[test] fn bindgen_test_layout_A() { @@ -44,3 +44,16 @@ fn __bindgen_test_layout_C_open0_A_close0_instantiation() { concat!("Alignment of template specialization: ", stringify!(C)), ); } +#[test] +fn __bindgen_test_layout_B_open0_A_close0_instantiation() { + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of template specialization: ", stringify!(B)), + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of template specialization: ", stringify!(B)), + ); +} diff --git a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs index 2a1090e130..d1b4c9004a 100644 --- a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs +++ b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs @@ -75,6 +75,8 @@ pub struct test2 { } #[test] fn bindgen_test_layout_test2() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -85,6 +87,21 @@ fn bindgen_test_layout_test2() { 4usize, concat!("Alignment of ", stringify!(test2)), ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(test2), "::", stringify!(a)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(test2), + "::", + stringify!(incomplete_array), + ), + ); } #[repr(C)] #[derive(Debug, Default)] @@ -95,6 +112,8 @@ pub struct test3 { } #[test] fn bindgen_test_layout_test3() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 4usize, @@ -105,4 +124,31 @@ fn bindgen_test_layout_test3() { 4usize, concat!("Alignment of ", stringify!(test3)), ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(test3), "::", stringify!(a)), + ); + assert_eq!( + unsafe { + ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(test3), + "::", + stringify!(zero_length_array), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(test3), + "::", + stringify!(incomplete_array), + ), + ); } diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/error-E0600-cannot-apply-unary-negation-to-u32.rs b/bindgen-tests/tests/expectations/tests/error-E0600-cannot-apply-unary-negation-to-u32.rs similarity index 100% rename from bindgen-tests/tests/expectations/tests/libclang-5/error-E0600-cannot-apply-unary-negation-to-u32.rs rename to bindgen-tests/tests/expectations/tests/error-E0600-cannot-apply-unary-negation-to-u32.rs diff --git a/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs b/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs index 4a14802d88..c8038e1f40 100644 --- a/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs +++ b/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs @@ -122,6 +122,8 @@ pub struct foo { } #[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::(), 8usize, @@ -132,6 +134,11 @@ fn bindgen_test_layout_foo() { 8usize, concat!("Alignment of ", stringify!(foo)), ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 8usize, + concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)), + ); } impl Default for foo { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/issue-544-stylo-creduce-2.rs b/bindgen-tests/tests/expectations/tests/issue-544-stylo-creduce-2.rs index 835f029cb2..c81b672956 100644 --- a/bindgen-tests/tests/expectations/tests/issue-544-stylo-creduce-2.rs +++ b/bindgen-tests/tests/expectations/tests/issue-544-stylo-creduce-2.rs @@ -1,10 +1,11 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] +#[derive(Debug, Copy, Clone)] pub struct Foo { - pub member: Foo_SecondAlias, + pub member: *mut Foo_SecondAlias, } pub type Foo_FirstAlias = [u8; 0usize]; -pub type Foo_SecondAlias = [u8; 0usize]; +pub type Foo_SecondAlias = Foo; impl Default for Foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/issue-643-inner-struct.rs b/bindgen-tests/tests/expectations/tests/issue-643-inner-struct.rs index 673221e385..520b3b0ecd 100644 --- a/bindgen-tests/tests/expectations/tests/issue-643-inner-struct.rs +++ b/bindgen-tests/tests/expectations/tests/issue-643-inner-struct.rs @@ -99,6 +99,8 @@ fn bindgen_test_layout_rte_ring_cons() { } #[test] fn bindgen_test_layout_rte_ring() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -109,6 +111,26 @@ fn bindgen_test_layout_rte_ring() { 8usize, concat!("Alignment of ", stringify!(rte_ring)), ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).memzone) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(rte_ring), "::", stringify!(memzone)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).prod) as usize - ptr as usize }, + 8usize, + concat!("Offset of field: ", stringify!(rte_ring), "::", stringify!(prod)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).cons) as usize - ptr as usize }, + 12usize, + concat!("Offset of field: ", stringify!(rte_ring), "::", stringify!(cons)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).ring) as usize - ptr as usize }, + 16usize, + concat!("Offset of field: ", stringify!(rte_ring), "::", stringify!(ring)), + ); } impl Default for rte_ring { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/issue-769-bad-instantiation-test.rs b/bindgen-tests/tests/expectations/tests/issue-769-bad-instantiation-test.rs similarity index 100% rename from bindgen-tests/tests/expectations/tests/libclang-5/issue-769-bad-instantiation-test.rs rename to bindgen-tests/tests/expectations/tests/issue-769-bad-instantiation-test.rs diff --git a/bindgen-tests/tests/expectations/tests/layout_align.rs b/bindgen-tests/tests/expectations/tests/layout_align.rs index 81fc8359d9..be77dc75d4 100644 --- a/bindgen-tests/tests/expectations/tests/layout_align.rs +++ b/bindgen-tests/tests/expectations/tests/layout_align.rs @@ -129,6 +129,8 @@ pub struct rte_kni_fifo { } #[test] fn bindgen_test_layout_rte_kni_fifo() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 16usize, @@ -139,6 +141,36 @@ fn bindgen_test_layout_rte_kni_fifo() { 8usize, concat!("Alignment of ", stringify!(rte_kni_fifo)), ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).write) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(rte_kni_fifo), "::", stringify!(write)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).read) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(rte_kni_fifo), "::", stringify!(read)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize }, + 8usize, + concat!("Offset of field: ", stringify!(rte_kni_fifo), "::", stringify!(len)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).elem_size) as usize - ptr as usize }, + 12usize, + concat!( + "Offset of field: ", + stringify!(rte_kni_fifo), + "::", + stringify!(elem_size), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).buffer) as usize - ptr as usize }, + 16usize, + concat!("Offset of field: ", stringify!(rte_kni_fifo), "::", stringify!(buffer)), + ); } impl Default for rte_kni_fifo { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/inline_namespace_nested.rs b/bindgen-tests/tests/expectations/tests/libclang-5/inline_namespace_nested.rs deleted file mode 100644 index 996b877e50..0000000000 --- a/bindgen-tests/tests/expectations/tests/libclang-5/inline_namespace_nested.rs +++ /dev/null @@ -1 +0,0 @@ -/* error generating bindings */ diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/issue-2556.rs b/bindgen-tests/tests/expectations/tests/libclang-5/issue-2556.rs deleted file mode 100644 index 996b877e50..0000000000 --- a/bindgen-tests/tests/expectations/tests/libclang-5/issue-2556.rs +++ /dev/null @@ -1 +0,0 @@ -/* error generating bindings */ diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/objc_template.rs b/bindgen-tests/tests/expectations/tests/libclang-5/objc_template.rs deleted file mode 100644 index 7ab3ac45ba..0000000000 --- a/bindgen-tests/tests/expectations/tests/libclang-5/objc_template.rs +++ /dev/null @@ -1,57 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#![cfg(target_os = "macos")] -use objc::{self, msg_send, sel, sel_impl, class}; -#[allow(non_camel_case_types)] -pub type id = *mut objc::runtime::Object; -#[repr(transparent)] -#[derive(Debug, Copy, Clone)] -pub struct Foo(pub id); -impl std::ops::Deref for Foo { - type Target = objc::runtime::Object; - fn deref(&self) -> &Self::Target { - unsafe { &*self.0 } - } -} -unsafe impl objc::Message for Foo {} -impl Foo { - pub fn alloc() -> Self { - Self(unsafe { msg_send!(class!(Foo), alloc) }) - } -} -impl IFoo for Foo {} -pub trait IFoo: Sized + std::ops::Deref { - unsafe fn get(&self) -> *mut ObjectType - where - ::Target: objc::Message + Sized, - { - msg_send!(* self, get) - } -} -#[repr(transparent)] -#[derive(Debug, Copy, Clone)] -pub struct FooMultiGeneric(pub id); -impl std::ops::Deref for FooMultiGeneric { - type Target = objc::runtime::Object; - fn deref(&self) -> &Self::Target { - unsafe { &*self.0 } - } -} -unsafe impl objc::Message for FooMultiGeneric {} -impl FooMultiGeneric { - pub fn alloc() -> Self { - Self(unsafe { msg_send!(class!(FooMultiGeneric), alloc) }) - } -} -impl IFooMultiGeneric -for FooMultiGeneric {} -pub trait IFooMultiGeneric< - KeyType: 'static, - ObjectType: 'static, ->: Sized + std::ops::Deref { - unsafe fn objectForKey_(&self, key: *mut KeyType) -> *mut ObjectType - where - ::Target: objc::Message + Sized, - { - msg_send!(* self, objectForKey : key) - } -} diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/ptr32-has-different-size.rs b/bindgen-tests/tests/expectations/tests/libclang-5/ptr32-has-different-size.rs deleted file mode 100644 index 0d677052ea..0000000000 --- a/bindgen-tests/tests/expectations/tests/libclang-5/ptr32-has-different-size.rs +++ /dev/null @@ -1,41 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct TEST_STRUCT { - pub ptr_32bit: *mut ::std::os::raw::c_void, -} -#[test] -fn bindgen_test_layout_TEST_STRUCT() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(TEST_STRUCT)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(TEST_STRUCT)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ptr_32bit) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(TEST_STRUCT), - "::", - stringify!(ptr_32bit), - ), - ); -} -impl Default for TEST_STRUCT { - fn default() -> Self { - let mut s = ::std::mem::MaybeUninit::::uninit(); - unsafe { - ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); - s.assume_init() - } - } -} -pub type TEST = TEST_STRUCT; diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/abi_variadic_function.rs b/bindgen-tests/tests/expectations/tests/libclang-9/abi_variadic_function.rs deleted file mode 100644 index 3cb7248c93..0000000000 --- a/bindgen-tests/tests/expectations/tests/libclang-9/abi_variadic_function.rs +++ /dev/null @@ -1,5 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern "C" { - #[link_name = "\u{1}_Z1bcz"] - pub fn b(arg1: ::std::os::raw::c_char, ...) -> ::std::os::raw::c_char; -} diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/auto.rs b/bindgen-tests/tests/expectations/tests/libclang-9/auto.rs deleted file mode 100644 index 340bc670dc..0000000000 --- a/bindgen-tests/tests/expectations/tests/libclang-9/auto.rs +++ /dev/null @@ -1,29 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct Foo { - pub _address: u8, -} -pub const Foo_kFoo: bool = true; -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)), - ); -} -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct Bar { - pub _address: u8, -} -extern "C" { - #[link_name = "\u{1}_Z5Test2v"] - pub fn Test2() -> ::std::os::raw::c_uint; -} diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/call-conv-field.rs b/bindgen-tests/tests/expectations/tests/libclang-9/call-conv-field.rs deleted file mode 100644 index e3179543fc..0000000000 --- a/bindgen-tests/tests/expectations/tests/libclang-9/call-conv-field.rs +++ /dev/null @@ -1,50 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#![cfg(not(test))] -#[repr(C)] -#[derive(Default, Copy, Clone)] -pub struct JNINativeInterface_ { - pub GetVersion: ::std::option::Option< - unsafe extern "stdcall" fn( - env: *mut ::std::os::raw::c_void, - ) -> ::std::os::raw::c_int, - >, - pub __hack: ::std::os::raw::c_ulonglong, -} -#[test] -fn bindgen_test_layout_JNINativeInterface_() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(JNINativeInterface_)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(JNINativeInterface_)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).GetVersion) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(JNINativeInterface_), - "::", - stringify!(GetVersion), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).__hack) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(JNINativeInterface_), - "::", - stringify!(__hack), - ), - ); -} -extern "stdcall" { - pub fn bar(); -} diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/class.rs b/bindgen-tests/tests/expectations/tests/libclang-9/class.rs deleted file mode 100644 index 19668a73dd..0000000000 --- a/bindgen-tests/tests/expectations/tests/libclang-9/class.rs +++ /dev/null @@ -1,617 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -#[derive(Default)] -pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); -impl __IncompleteArrayField { - #[inline] - pub const fn new() -> Self { - __IncompleteArrayField(::std::marker::PhantomData, []) - } - #[inline] - pub fn as_ptr(&self) -> *const T { - self as *const _ as *const T - } - #[inline] - pub fn as_mut_ptr(&mut self) -> *mut T { - self as *mut _ as *mut T - } - #[inline] - pub unsafe fn as_slice(&self, len: usize) -> &[T] { - ::std::slice::from_raw_parts(self.as_ptr(), len) - } - #[inline] - pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) - } -} -impl ::std::fmt::Debug for __IncompleteArrayField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__IncompleteArrayField") - } -} -#[repr(C)] -#[derive(Copy, Clone)] -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, concat!("Size of: ", stringify!(C))); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(a)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(big_array)), - ); -} -impl Default for C { - fn default() -> Self { - let mut s = ::std::mem::MaybeUninit::::uninit(); - unsafe { - ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); - s.assume_init() - } - } -} -#[repr(C)] -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, - concat!("Size of: ", stringify!(C_with_zero_length_array)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C_with_zero_length_array)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(a), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(big_array), - ), - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize - }, - 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(zero_length_array), - ), - ); -} -impl Default for C_with_zero_length_array { - fn default() -> Self { - let mut s = ::std::mem::MaybeUninit::::uninit(); - unsafe { - ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); - s.assume_init() - } - } -} -#[repr(C)] -#[derive(Debug, Default)] -pub struct C_with_zero_length_array_2 { - pub a: ::std::os::raw::c_int, - pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, -} -#[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, - concat!("Size of: ", stringify!(C_with_zero_length_array_2)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C_with_zero_length_array_2)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_2), - "::", - stringify!(a), - ), - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_2), - "::", - stringify!(zero_length_array), - ), - ); -} -#[repr(C)] -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, - concat!("Size of: ", stringify!(C_with_incomplete_array)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C_with_incomplete_array)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array), - "::", - stringify!(a), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array), - "::", - stringify!(big_array), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, - 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array), - "::", - stringify!(incomplete_array), - ), - ); -} -impl Default for C_with_incomplete_array { - fn default() -> Self { - let mut s = ::std::mem::MaybeUninit::::uninit(); - unsafe { - ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); - s.assume_init() - } - } -} -#[repr(C)] -#[derive(Debug, Default)] -pub struct C_with_incomplete_array_2 { - pub a: ::std::os::raw::c_int, - pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, -} -#[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, - concat!("Size of: ", stringify!(C_with_incomplete_array_2)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C_with_incomplete_array_2)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array_2), - "::", - stringify!(a), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array_2), - "::", - stringify!(incomplete_array), - ), - ); -} -#[repr(C)] -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, - concat!("Size of: ", stringify!(C_with_zero_length_array_and_incomplete_array)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!( - "Alignment of ", - stringify!(C_with_zero_length_array_and_incomplete_array), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(a), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(big_array), - ), - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize - }, - 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(zero_length_array), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, - 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(incomplete_array), - ), - ); -} -impl Default for C_with_zero_length_array_and_incomplete_array { - fn default() -> Self { - let mut s = ::std::mem::MaybeUninit::::uninit(); - unsafe { - ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); - s.assume_init() - } - } -} -#[repr(C)] -#[derive(Debug, Default)] -pub struct C_with_zero_length_array_and_incomplete_array_2 { - pub a: ::std::os::raw::c_int, - pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, - pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, -} -#[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, - concat!("Size of: ", stringify!(C_with_zero_length_array_and_incomplete_array_2)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!( - "Alignment of ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), - "::", - stringify!(a), - ), - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), - "::", - stringify!(zero_length_array), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), - "::", - stringify!(incomplete_array), - ), - ); -} -#[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, - concat!("Size of: ", stringify!(WithDtor)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithDtor)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(WithDtor), "::", stringify!(b)), - ); -} -#[repr(C)] -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, - concat!("Size of: ", stringify!(IncompleteArrayNonCopiable)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(IncompleteArrayNonCopiable)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).whatever) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(IncompleteArrayNonCopiable), - "::", - stringify!(whatever), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(IncompleteArrayNonCopiable), - "::", - stringify!(incomplete_array), - ), - ); -} -impl Default for IncompleteArrayNonCopiable { - fn default() -> Self { - let mut s = ::std::mem::MaybeUninit::::uninit(); - unsafe { - ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); - s.assume_init() - } - } -} -#[repr(C)] -#[derive(Copy, Clone)] -pub union Union { - pub d: f32, - pub i: ::std::os::raw::c_int, -} -#[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, - concat!("Size of: ", stringify!(Union)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Union)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Union), "::", stringify!(d)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Union), "::", stringify!(i)), - ); -} -impl Default for Union { - fn default() -> Self { - let mut s = ::std::mem::MaybeUninit::::uninit(); - unsafe { - ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); - s.assume_init() - } - } -} -#[repr(C)] -#[derive(Copy, Clone)] -pub struct WithUnion { - pub data: Union, -} -#[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, - concat!("Size of: ", stringify!(WithUnion)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithUnion)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(WithUnion), "::", stringify!(data)), - ); -} -impl Default for WithUnion { - fn default() -> Self { - let mut s = ::std::mem::MaybeUninit::::uninit(); - unsafe { - ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); - s.assume_init() - } - } -} -#[repr(C)] -#[derive(Debug, Default, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] -pub struct RealAbstractionWithTonsOfMethods { - pub _address: u8, -} -#[test] -fn bindgen_test_layout_RealAbstractionWithTonsOfMethods() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(RealAbstractionWithTonsOfMethods)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(RealAbstractionWithTonsOfMethods)), - ); -} -extern "C" { - #[link_name = "\u{1}_ZNK32RealAbstractionWithTonsOfMethods3barEv"] - pub fn RealAbstractionWithTonsOfMethods_bar( - this: *const RealAbstractionWithTonsOfMethods, - ); -} -extern "C" { - #[link_name = "\u{1}_ZN32RealAbstractionWithTonsOfMethods3barEv"] - pub fn RealAbstractionWithTonsOfMethods_bar1( - this: *mut RealAbstractionWithTonsOfMethods, - ); -} -extern "C" { - #[link_name = "\u{1}_ZN32RealAbstractionWithTonsOfMethods3barEi"] - pub fn RealAbstractionWithTonsOfMethods_bar2( - this: *mut RealAbstractionWithTonsOfMethods, - foo: ::std::os::raw::c_int, - ); -} -extern "C" { - #[link_name = "\u{1}_ZN32RealAbstractionWithTonsOfMethods3staEv"] - pub fn RealAbstractionWithTonsOfMethods_sta(); -} -impl RealAbstractionWithTonsOfMethods { - #[inline] - pub unsafe fn bar(&self) { - RealAbstractionWithTonsOfMethods_bar(self) - } - #[inline] - pub unsafe fn bar1(&mut self) { - RealAbstractionWithTonsOfMethods_bar1(self) - } - #[inline] - pub unsafe fn bar2(&mut self, foo: ::std::os::raw::c_int) { - RealAbstractionWithTonsOfMethods_bar2(self, foo) - } - #[inline] - pub unsafe fn sta() { - RealAbstractionWithTonsOfMethods_sta() - } -} diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/class_1_0.rs b/bindgen-tests/tests/expectations/tests/libclang-9/class_1_0.rs deleted file mode 100644 index b6544212cf..0000000000 --- a/bindgen-tests/tests/expectations/tests/libclang-9/class_1_0.rs +++ /dev/null @@ -1,668 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -#[derive(Default)] -pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); -impl __IncompleteArrayField { - #[inline] - pub fn new() -> Self { - __IncompleteArrayField(::std::marker::PhantomData, []) - } - #[inline] - pub fn as_ptr(&self) -> *const T { - self as *const _ as *const T - } - #[inline] - pub fn as_mut_ptr(&mut self) -> *mut T { - self as *mut _ as *mut T - } - #[inline] - pub unsafe fn as_slice(&self, len: usize) -> &[T] { - ::std::slice::from_raw_parts(self.as_ptr(), len) - } - #[inline] - pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) - } -} -impl ::std::fmt::Debug for __IncompleteArrayField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__IncompleteArrayField") - } -} -#[repr(C)] -pub struct __BindgenUnionField(::std::marker::PhantomData); -impl __BindgenUnionField { - #[inline] - pub fn new() -> Self { - __BindgenUnionField(::std::marker::PhantomData) - } - #[inline] - pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) - } - #[inline] - pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) - } -} -impl ::std::default::Default for __BindgenUnionField { - #[inline] - fn default() -> Self { - Self::new() - } -} -impl ::std::clone::Clone for __BindgenUnionField { - #[inline] - fn clone(&self) -> Self { - *self - } -} -impl ::std::marker::Copy for __BindgenUnionField {} -impl ::std::fmt::Debug for __BindgenUnionField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__BindgenUnionField") - } -} -impl ::std::hash::Hash for __BindgenUnionField { - fn hash(&self, _state: &mut H) {} -} -impl ::std::cmp::PartialEq for __BindgenUnionField { - fn eq(&self, _other: &__BindgenUnionField) -> bool { - true - } -} -impl ::std::cmp::Eq for __BindgenUnionField {} -#[repr(C)] -#[derive(Copy)] -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, concat!("Size of: ", stringify!(C))); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(a)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(big_array)), - ); -} -impl Clone for C { - fn clone(&self) -> Self { - *self - } -} -impl Default for C { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} -impl ::std::cmp::PartialEq for C { - fn eq(&self, other: &C) -> bool { - self.a == other.a && &self.big_array[..] == &other.big_array[..] - } -} -#[repr(C)] -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, - concat!("Size of: ", stringify!(C_with_zero_length_array)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C_with_zero_length_array)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(a), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(big_array), - ), - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize - }, - 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(zero_length_array), - ), - ); -} -impl Default for C_with_zero_length_array { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} -#[repr(C)] -#[derive(Debug, Default)] -pub struct C_with_zero_length_array_2 { - pub a: ::std::os::raw::c_int, - pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, -} -#[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, - concat!("Size of: ", stringify!(C_with_zero_length_array_2)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C_with_zero_length_array_2)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_2), - "::", - stringify!(a), - ), - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_2), - "::", - stringify!(zero_length_array), - ), - ); -} -#[repr(C)] -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, - concat!("Size of: ", stringify!(C_with_incomplete_array)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C_with_incomplete_array)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array), - "::", - stringify!(a), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array), - "::", - stringify!(big_array), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, - 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array), - "::", - stringify!(incomplete_array), - ), - ); -} -impl Default for C_with_incomplete_array { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} -#[repr(C)] -#[derive(Debug, Default)] -pub struct C_with_incomplete_array_2 { - pub a: ::std::os::raw::c_int, - pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, -} -#[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, - concat!("Size of: ", stringify!(C_with_incomplete_array_2)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C_with_incomplete_array_2)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array_2), - "::", - stringify!(a), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array_2), - "::", - stringify!(incomplete_array), - ), - ); -} -#[repr(C)] -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, - concat!("Size of: ", stringify!(C_with_zero_length_array_and_incomplete_array)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!( - "Alignment of ", - stringify!(C_with_zero_length_array_and_incomplete_array), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(a), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(big_array), - ), - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize - }, - 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(zero_length_array), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, - 37usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(incomplete_array), - ), - ); -} -impl Default for C_with_zero_length_array_and_incomplete_array { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} -#[repr(C)] -#[derive(Debug, Default)] -pub struct C_with_zero_length_array_and_incomplete_array_2 { - pub a: ::std::os::raw::c_int, - pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, - pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, -} -#[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, - concat!("Size of: ", stringify!(C_with_zero_length_array_and_incomplete_array_2)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!( - "Alignment of ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), - "::", - stringify!(a), - ), - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), - "::", - stringify!(zero_length_array), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), - "::", - stringify!(incomplete_array), - ), - ); -} -#[repr(C)] -#[derive(Debug, Default, Hash, 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, - concat!("Size of: ", stringify!(WithDtor)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithDtor)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(WithDtor), "::", stringify!(b)), - ); -} -#[repr(C)] -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, - concat!("Size of: ", stringify!(IncompleteArrayNonCopiable)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(IncompleteArrayNonCopiable)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).whatever) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(IncompleteArrayNonCopiable), - "::", - stringify!(whatever), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(IncompleteArrayNonCopiable), - "::", - stringify!(incomplete_array), - ), - ); -} -impl Default for IncompleteArrayNonCopiable { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq)] -pub struct Union { - pub d: __BindgenUnionField, - pub i: __BindgenUnionField<::std::os::raw::c_int>, - pub bindgen_union_field: u32, -} -#[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, - concat!("Size of: ", stringify!(Union)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Union)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Union), "::", stringify!(d)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Union), "::", stringify!(i)), - ); -} -impl Clone for Union { - fn clone(&self) -> Self { - *self - } -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq)] -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, - concat!("Size of: ", stringify!(WithUnion)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithUnion)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(WithUnion), "::", stringify!(data)), - ); -} -impl Clone for WithUnion { - fn clone(&self) -> Self { - *self - } -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct RealAbstractionWithTonsOfMethods { - pub _address: u8, -} -#[test] -fn bindgen_test_layout_RealAbstractionWithTonsOfMethods() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(RealAbstractionWithTonsOfMethods)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(RealAbstractionWithTonsOfMethods)), - ); -} -extern "C" { - #[link_name = "\u{1}_ZNK32RealAbstractionWithTonsOfMethods3barEv"] - pub fn RealAbstractionWithTonsOfMethods_bar( - this: *const RealAbstractionWithTonsOfMethods, - ); -} -extern "C" { - #[link_name = "\u{1}_ZN32RealAbstractionWithTonsOfMethods3barEv"] - pub fn RealAbstractionWithTonsOfMethods_bar1( - this: *mut RealAbstractionWithTonsOfMethods, - ); -} -extern "C" { - #[link_name = "\u{1}_ZN32RealAbstractionWithTonsOfMethods3barEi"] - pub fn RealAbstractionWithTonsOfMethods_bar2( - this: *mut RealAbstractionWithTonsOfMethods, - foo: ::std::os::raw::c_int, - ); -} -extern "C" { - #[link_name = "\u{1}_ZN32RealAbstractionWithTonsOfMethods3staEv"] - pub fn RealAbstractionWithTonsOfMethods_sta(); -} -impl Clone for RealAbstractionWithTonsOfMethods { - fn clone(&self) -> Self { - *self - } -} -impl RealAbstractionWithTonsOfMethods { - #[inline] - pub unsafe fn bar(&self) { - RealAbstractionWithTonsOfMethods_bar(self) - } - #[inline] - pub unsafe fn bar1(&mut self) { - RealAbstractionWithTonsOfMethods_bar1(self) - } - #[inline] - pub unsafe fn bar2(&mut self, foo: ::std::os::raw::c_int) { - RealAbstractionWithTonsOfMethods_bar2(self, foo) - } - #[inline] - pub unsafe fn sta() { - RealAbstractionWithTonsOfMethods_sta() - } -} diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/const_bool.rs b/bindgen-tests/tests/expectations/tests/libclang-9/const_bool.rs deleted file mode 100644 index 97cb7ec691..0000000000 --- a/bindgen-tests/tests/expectations/tests/libclang-9/const_bool.rs +++ /dev/null @@ -1,19 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -pub const k: bool = true; -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct A { - pub _address: u8, -} -pub const A_k: bool = false; -#[test] -fn bindgen_test_layout_A() { - assert_eq!(::std::mem::size_of::(), 1usize, concat!("Size of: ", stringify!(A))); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(A)), - ); -} -pub type foo = bool; -pub const k2: foo = true; diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/constant-evaluate.rs b/bindgen-tests/tests/expectations/tests/libclang-9/constant-evaluate.rs deleted file mode 100644 index bbcf6d5450..0000000000 --- a/bindgen-tests/tests/expectations/tests/libclang-9/constant-evaluate.rs +++ /dev/null @@ -1,19 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -pub const foo: _bindgen_ty_1 = _bindgen_ty_1::foo; -pub const bar: _bindgen_ty_1 = _bindgen_ty_1::bar; -#[repr(u32)] -#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] -pub enum _bindgen_ty_1 { - foo = 4, - bar = 8, -} -pub type EasyToOverflow = ::std::os::raw::c_ulonglong; -pub const k: EasyToOverflow = 2147483648; -pub const k_expr: EasyToOverflow = 1152921504606846976; -pub const wow: EasyToOverflow = 2147483648; -pub const BAZ: ::std::os::raw::c_longlong = 24; -pub const fuzz: f64 = 51.0; -pub const BAZZ: ::std::os::raw::c_char = 53; -pub const WAT: ::std::os::raw::c_char = 0; -pub const bytestring: &[u8; 4] = b"Foo\0"; -pub const NOT_UTF8: &[u8; 5] = b"\xF0(\x8C(\0"; diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/constified-enum-module-overflow.rs b/bindgen-tests/tests/expectations/tests/libclang-9/constified-enum-module-overflow.rs new file mode 100644 index 0000000000..49498deaa5 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/libclang-9/constified-enum-module-overflow.rs @@ -0,0 +1,46 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct B { + pub _address: u8, +} +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct C { + pub _address: u8, +} +pub type C_U = B; +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct A { + pub u: u8, +} +#[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::(), 1usize, concat!("Size of: ", stringify!(A))); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(A)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(A), "::", stringify!(u)), + ); +} +#[test] +fn __bindgen_test_layout_C_open0_A_close0_instantiation() { + assert_eq!( + ::std::mem::size_of::(), + 1usize, + concat!("Size of template specialization: ", stringify!(C)), + ); + assert_eq!( + ::std::mem::align_of::(), + 1usize, + concat!("Alignment of template specialization: ", stringify!(C)), + ); +} diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs b/bindgen-tests/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs deleted file mode 100644 index d1b4c9004a..0000000000 --- a/bindgen-tests/tests/expectations/tests/libclang-9/derive-hash-struct-with-incomplete-array.rs +++ /dev/null @@ -1,154 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -#[derive(Default)] -pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); -impl __IncompleteArrayField { - #[inline] - pub const fn new() -> Self { - __IncompleteArrayField(::std::marker::PhantomData, []) - } - #[inline] - pub fn as_ptr(&self) -> *const T { - self as *const _ as *const T - } - #[inline] - pub fn as_mut_ptr(&mut self) -> *mut T { - self as *mut _ as *mut T - } - #[inline] - pub unsafe fn as_slice(&self, len: usize) -> &[T] { - ::std::slice::from_raw_parts(self.as_ptr(), len) - } - #[inline] - pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) - } -} -impl ::std::fmt::Debug for __IncompleteArrayField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__IncompleteArrayField") - } -} -#[repr(C)] -#[derive(Debug, Default)] -pub struct test { - pub a: ::std::os::raw::c_int, - pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, -} -#[test] -fn bindgen_test_layout_test() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(test)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(test)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(test), "::", stringify!(a)), - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(test), - "::", - stringify!(zero_length_array), - ), - ); -} -#[repr(C)] -#[derive(Debug, Default)] -pub struct test2 { - pub a: ::std::os::raw::c_int, - pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, -} -#[test] -fn bindgen_test_layout_test2() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(test2)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(test2)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(test2), "::", stringify!(a)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(test2), - "::", - stringify!(incomplete_array), - ), - ); -} -#[repr(C)] -#[derive(Debug, Default)] -pub struct test3 { - pub a: ::std::os::raw::c_int, - pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, - pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, -} -#[test] -fn bindgen_test_layout_test3() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(test3)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(test3)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(test3), "::", stringify!(a)), - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(test3), - "::", - stringify!(zero_length_array), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(test3), - "::", - stringify!(incomplete_array), - ), - ); -} diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/error-E0600-cannot-apply-unary-negation-to-u32.rs b/bindgen-tests/tests/expectations/tests/libclang-9/error-E0600-cannot-apply-unary-negation-to-u32.rs deleted file mode 100644 index 79004238fc..0000000000 --- a/bindgen-tests/tests/expectations/tests/libclang-9/error-E0600-cannot-apply-unary-negation-to-u32.rs +++ /dev/null @@ -1,3 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#![allow(overflowing_literals)] -pub const a: u32 = 4294967291; diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/incomplete-array-padding.rs b/bindgen-tests/tests/expectations/tests/libclang-9/incomplete-array-padding.rs deleted file mode 100644 index c8038e1f40..0000000000 --- a/bindgen-tests/tests/expectations/tests/libclang-9/incomplete-array-padding.rs +++ /dev/null @@ -1,180 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[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] - 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]; - 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 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]; - 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 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 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); - } - } -} -#[repr(C)] -#[derive(Default)] -pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); -impl __IncompleteArrayField { - #[inline] - pub const fn new() -> Self { - __IncompleteArrayField(::std::marker::PhantomData, []) - } - #[inline] - pub fn as_ptr(&self) -> *const T { - self as *const _ as *const T - } - #[inline] - pub fn as_mut_ptr(&mut self) -> *mut T { - self as *mut _ as *mut T - } - #[inline] - pub unsafe fn as_slice(&self, len: usize) -> &[T] { - ::std::slice::from_raw_parts(self.as_ptr(), len) - } - #[inline] - pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) - } -} -impl ::std::fmt::Debug for __IncompleteArrayField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__IncompleteArrayField") - } -} -#[repr(C)] -#[derive(Debug)] -pub struct foo { - pub _bitfield_align_1: [u8; 0], - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, - pub b: __IncompleteArrayField<*mut ::std::os::raw::c_void>, -} -#[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::(), - 8usize, - concat!("Size of: ", stringify!(foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(foo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)), - ); -} -impl Default for foo { - fn default() -> Self { - let mut s = ::std::mem::MaybeUninit::::uninit(); - unsafe { - ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); - s.assume_init() - } - } -} -impl foo { - #[inline] - pub fn a(&self) -> ::std::os::raw::c_char { - unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) } - } - #[inline] - pub fn set_a(&mut self, val: ::std::os::raw::c_char) { - unsafe { - let val: u8 = ::std::mem::transmute(val); - self._bitfield_1.set(0usize, 1u8, val as u64) - } - } - #[inline] - pub fn new_bitfield_1( - a: ::std::os::raw::c_char, - ) -> __BindgenBitfieldUnit<[u8; 1usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); - __bindgen_bitfield_unit - .set( - 0usize, - 1u8, - { - let a: u8 = unsafe { ::std::mem::transmute(a) }; - a as u64 - }, - ); - __bindgen_bitfield_unit - } -} diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/issue-544-stylo-creduce-2.rs b/bindgen-tests/tests/expectations/tests/libclang-9/issue-544-stylo-creduce-2.rs new file mode 100644 index 0000000000..5c5ad156e3 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/libclang-9/issue-544-stylo-creduce-2.rs @@ -0,0 +1,17 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct Foo { + pub member: *mut [u8; 0usize], +} +pub type Foo_FirstAlias = [u8; 0usize]; +pub type Foo_SecondAlias = [u8; 0usize]; +impl Default for Foo { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs b/bindgen-tests/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs deleted file mode 100644 index 520b3b0ecd..0000000000 --- a/bindgen-tests/tests/expectations/tests/libclang-9/issue-643-inner-struct.rs +++ /dev/null @@ -1,148 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -#[derive(Default)] -pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); -impl __IncompleteArrayField { - #[inline] - pub const fn new() -> Self { - __IncompleteArrayField(::std::marker::PhantomData, []) - } - #[inline] - pub fn as_ptr(&self) -> *const T { - self as *const _ as *const T - } - #[inline] - pub fn as_mut_ptr(&mut self) -> *mut T { - self as *mut _ as *mut T - } - #[inline] - pub unsafe fn as_slice(&self, len: usize) -> &[T] { - ::std::slice::from_raw_parts(self.as_ptr(), len) - } - #[inline] - pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) - } -} -impl ::std::fmt::Debug for __IncompleteArrayField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__IncompleteArrayField") - } -} -#[repr(C)] -#[derive(Debug)] -pub struct rte_ring { - pub memzone: *mut rte_memzone, - pub prod: rte_ring_prod, - pub cons: rte_ring_cons, - pub ring: __IncompleteArrayField<*mut ::std::os::raw::c_void>, -} -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct rte_ring_prod { - pub watermark: ::std::os::raw::c_uint, -} -#[test] -fn bindgen_test_layout_rte_ring_prod() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(rte_ring_prod)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(rte_ring_prod)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).watermark) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ring_prod), - "::", - stringify!(watermark), - ), - ); -} -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct rte_ring_cons { - pub sc_dequeue: ::std::os::raw::c_uint, -} -#[test] -fn bindgen_test_layout_rte_ring_cons() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(rte_ring_cons)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(rte_ring_cons)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).sc_dequeue) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ring_cons), - "::", - stringify!(sc_dequeue), - ), - ); -} -#[test] -fn bindgen_test_layout_rte_ring() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(rte_ring)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(rte_ring)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).memzone) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(rte_ring), "::", stringify!(memzone)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).prod) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(rte_ring), "::", stringify!(prod)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).cons) as usize - ptr as usize }, - 12usize, - concat!("Offset of field: ", stringify!(rte_ring), "::", stringify!(cons)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ring) as usize - ptr as usize }, - 16usize, - concat!("Offset of field: ", stringify!(rte_ring), "::", stringify!(ring)), - ); -} -impl Default for rte_ring { - fn default() -> Self { - let mut s = ::std::mem::MaybeUninit::::uninit(); - unsafe { - ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); - s.assume_init() - } - } -} -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct rte_memzone { - pub _address: u8, -} diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/issue-769-bad-instantiation-test.rs b/bindgen-tests/tests/expectations/tests/libclang-9/issue-769-bad-instantiation-test.rs deleted file mode 100644 index ef830ca69e..0000000000 --- a/bindgen-tests/tests/expectations/tests/libclang-9/issue-769-bad-instantiation-test.rs +++ /dev/null @@ -1,60 +0,0 @@ -#![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 { - #[allow(unused_imports)] - use self::super::root; - #[repr(C)] - #[derive(Debug, Copy, Clone)] - pub struct Rooted { - pub member: T, - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, - } - impl Default for Rooted { - fn default() -> Self { - let mut s = ::std::mem::MaybeUninit::::uninit(); - unsafe { - ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); - s.assume_init() - } - } - } - pub type AutoValueVector_Alias = ::std::os::raw::c_int; - #[test] - fn __bindgen_test_layout_Rooted_open0_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!( - "Size of template specialization: ", - stringify!(root::Rooted < ::std::os::raw::c_int >), - ), - ); - assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(root::Rooted < ::std::os::raw::c_int >), - ), - ); - } - #[test] - fn __bindgen_test_layout_Rooted_open0_AutoValueVector_Alias_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!( - "Size of template specialization: ", - stringify!(root::Rooted < root::AutoValueVector_Alias >), - ), - ); - assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(root::Rooted < root::AutoValueVector_Alias >), - ), - ); - } -} diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/layout_align.rs b/bindgen-tests/tests/expectations/tests/libclang-9/layout_align.rs deleted file mode 100644 index be77dc75d4..0000000000 --- a/bindgen-tests/tests/expectations/tests/libclang-9/layout_align.rs +++ /dev/null @@ -1,291 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[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] - 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]; - 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 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]; - 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 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 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); - } - } -} -#[repr(C)] -#[derive(Default)] -pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); -impl __IncompleteArrayField { - #[inline] - pub const fn new() -> Self { - __IncompleteArrayField(::std::marker::PhantomData, []) - } - #[inline] - pub fn as_ptr(&self) -> *const T { - self as *const _ as *const T - } - #[inline] - pub fn as_mut_ptr(&mut self) -> *mut T { - self as *mut _ as *mut T - } - #[inline] - pub unsafe fn as_slice(&self, len: usize) -> &[T] { - ::std::slice::from_raw_parts(self.as_ptr(), len) - } - #[inline] - pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) - } -} -impl ::std::fmt::Debug for __IncompleteArrayField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__IncompleteArrayField") - } -} -#[repr(C)] -#[derive(Debug)] -pub struct rte_kni_fifo { - ///< Next position to be written - pub write: ::std::os::raw::c_uint, - ///< Next position to be read - pub read: ::std::os::raw::c_uint, - ///< Circular buffer length - pub len: ::std::os::raw::c_uint, - ///< Pointer size - for 32/64 bit OS - pub elem_size: ::std::os::raw::c_uint, - ///< The buffer contains mbuf pointers - pub buffer: __IncompleteArrayField<*mut ::std::os::raw::c_void>, -} -#[test] -fn bindgen_test_layout_rte_kni_fifo() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(rte_kni_fifo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(rte_kni_fifo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).write) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(rte_kni_fifo), "::", stringify!(write)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).read) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(rte_kni_fifo), "::", stringify!(read)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(rte_kni_fifo), "::", stringify!(len)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).elem_size) as usize - ptr as usize }, - 12usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_fifo), - "::", - stringify!(elem_size), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).buffer) as usize - ptr as usize }, - 16usize, - concat!("Offset of field: ", stringify!(rte_kni_fifo), "::", stringify!(buffer)), - ); -} -impl Default for rte_kni_fifo { - fn default() -> Self { - let mut s = ::std::mem::MaybeUninit::::uninit(); - unsafe { - ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); - s.assume_init() - } - } -} -#[repr(C)] -#[repr(align(8))] -#[derive(Debug, Default, Copy, Clone)] -pub struct rte_eth_link { - ///< ETH_SPEED_NUM_ - pub link_speed: u32, - pub _bitfield_align_1: [u8; 0], - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, - pub __bindgen_padding_0: [u8; 3usize], -} -#[test] -fn bindgen_test_layout_rte_eth_link() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(rte_eth_link)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(rte_eth_link)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).link_speed) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_link), - "::", - stringify!(link_speed), - ), - ); -} -impl rte_eth_link { - #[inline] - pub fn link_duplex(&self) -> u16 { - unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u16) } - } - #[inline] - pub fn set_link_duplex(&mut self, val: u16) { - unsafe { - let val: u16 = ::std::mem::transmute(val); - self._bitfield_1.set(0usize, 1u8, val as u64) - } - } - #[inline] - pub fn link_autoneg(&self) -> u16 { - unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u16) } - } - #[inline] - pub fn set_link_autoneg(&mut self, val: u16) { - unsafe { - let val: u16 = ::std::mem::transmute(val); - self._bitfield_1.set(1usize, 1u8, val as u64) - } - } - #[inline] - pub fn link_status(&self) -> u16 { - unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u16) } - } - #[inline] - pub fn set_link_status(&mut self, val: u16) { - unsafe { - let val: u16 = ::std::mem::transmute(val); - self._bitfield_1.set(2usize, 1u8, val as u64) - } - } - #[inline] - pub fn new_bitfield_1( - link_duplex: u16, - link_autoneg: u16, - link_status: u16, - ) -> __BindgenBitfieldUnit<[u8; 1usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); - __bindgen_bitfield_unit - .set( - 0usize, - 1u8, - { - let link_duplex: u16 = unsafe { ::std::mem::transmute(link_duplex) }; - link_duplex as u64 - }, - ); - __bindgen_bitfield_unit - .set( - 1usize, - 1u8, - { - let link_autoneg: u16 = unsafe { - ::std::mem::transmute(link_autoneg) - }; - link_autoneg as u64 - }, - ); - __bindgen_bitfield_unit - .set( - 2usize, - 1u8, - { - let link_status: u16 = unsafe { ::std::mem::transmute(link_status) }; - link_status as u64 - }, - ); - __bindgen_bitfield_unit - } -} diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/mangling-win32.rs b/bindgen-tests/tests/expectations/tests/libclang-9/mangling-win32.rs deleted file mode 100644 index 34efb92461..0000000000 --- a/bindgen-tests/tests/expectations/tests/libclang-9/mangling-win32.rs +++ /dev/null @@ -1,46 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern "C" { - pub fn foo(); -} -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct Foo { - pub _address: u8, -} -extern "C" { - #[link_name = "\u{1}?sBar@Foo@@2_NA"] - pub static mut Foo_sBar: bool; -} -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)), - ); -} -extern "fastcall" { - pub fn fast_call_func_no_args() -> ::std::os::raw::c_int; -} -extern "fastcall" { - pub fn fast_call_func_many_args( - arg1: ::std::os::raw::c_int, - arg2: ::std::os::raw::c_int, - arg3: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int; -} -extern "stdcall" { - pub fn std_call_func_no_args() -> ::std::os::raw::c_int; -} -extern "stdcall" { - pub fn std_call_func_many_args( - arg1: ::std::os::raw::c_int, - arg2: ::std::os::raw::c_int, - arg3: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int; -} diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/objc_inheritance.rs b/bindgen-tests/tests/expectations/tests/libclang-9/objc_inheritance.rs deleted file mode 100644 index 6fb4e6b857..0000000000 --- a/bindgen-tests/tests/expectations/tests/libclang-9/objc_inheritance.rs +++ /dev/null @@ -1,107 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#![cfg(target_os = "macos")] -use objc::{self, msg_send, sel, sel_impl, class}; -#[allow(non_camel_case_types)] -pub type id = *mut objc::runtime::Object; -#[repr(transparent)] -#[derive(Debug, Copy, Clone)] -pub struct Foo(pub id); -impl std::ops::Deref for Foo { - type Target = objc::runtime::Object; - fn deref(&self) -> &Self::Target { - unsafe { &*self.0 } - } -} -unsafe impl objc::Message for Foo {} -impl Foo { - pub fn alloc() -> Self { - Self(unsafe { msg_send!(class!(Foo), alloc) }) - } -} -impl IFoo for Foo {} -pub trait IFoo: Sized + std::ops::Deref {} -#[repr(transparent)] -#[derive(Debug, Copy, Clone)] -pub struct Bar(pub id); -impl std::ops::Deref for Bar { - type Target = objc::runtime::Object; - fn deref(&self) -> &Self::Target { - unsafe { &*self.0 } - } -} -unsafe impl objc::Message for Bar {} -impl Bar { - pub fn alloc() -> Self { - Self(unsafe { msg_send!(class!(Bar), alloc) }) - } -} -impl IFoo for Bar {} -impl From for Foo { - fn from(child: Bar) -> Foo { - Foo(child.0) - } -} -impl std::convert::TryFrom for Bar { - type Error = &'static str; - fn try_from(parent: Foo) -> Result { - let is_kind_of: bool = unsafe { msg_send!(parent, isKindOfClass : class!(Bar)) }; - if is_kind_of { - Ok(Bar(parent.0)) - } else { - Err("This Foo cannot be downcasted to Bar") - } - } -} -impl IBar for Bar {} -pub trait IBar: Sized + std::ops::Deref {} -#[repr(transparent)] -#[derive(Debug, Copy, Clone)] -pub struct Baz(pub id); -impl std::ops::Deref for Baz { - type Target = objc::runtime::Object; - fn deref(&self) -> &Self::Target { - unsafe { &*self.0 } - } -} -unsafe impl objc::Message for Baz {} -impl Baz { - pub fn alloc() -> Self { - Self(unsafe { msg_send!(class!(Baz), alloc) }) - } -} -impl IBar for Baz {} -impl From for Bar { - fn from(child: Baz) -> Bar { - Bar(child.0) - } -} -impl std::convert::TryFrom for Baz { - type Error = &'static str; - fn try_from(parent: Bar) -> Result { - let is_kind_of: bool = unsafe { msg_send!(parent, isKindOfClass : class!(Baz)) }; - if is_kind_of { - Ok(Baz(parent.0)) - } else { - Err("This Bar cannot be downcasted to Baz") - } - } -} -impl IFoo for Baz {} -impl From for Foo { - fn from(child: Baz) -> Foo { - Foo(child.0) - } -} -impl std::convert::TryFrom for Baz { - type Error = &'static str; - fn try_from(parent: Foo) -> Result { - let is_kind_of: bool = unsafe { msg_send!(parent, isKindOfClass : class!(Baz)) }; - if is_kind_of { - Ok(Baz(parent.0)) - } else { - Err("This Foo cannot be downcasted to Baz") - } - } -} -impl IBaz for Baz {} -pub trait IBaz: Sized + std::ops::Deref {} diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/partial-specialization-and-inheritance.rs b/bindgen-tests/tests/expectations/tests/libclang-9/partial-specialization-and-inheritance.rs deleted file mode 100644 index 3ba3a82aa3..0000000000 --- a/bindgen-tests/tests/expectations/tests/libclang-9/partial-specialization-and-inheritance.rs +++ /dev/null @@ -1,33 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct Base { - pub _address: u8, -} -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct Derived { - pub b: bool, -} -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct Usage { - pub _address: u8, -} -extern "C" { - #[link_name = "\u{1}_ZN5Usage13static_memberE"] - pub static mut Usage_static_member: [u32; 2usize]; -} -#[test] -fn bindgen_test_layout_Usage() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Usage)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Usage)), - ); -} diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/struct_typedef_ns.rs b/bindgen-tests/tests/expectations/tests/libclang-9/struct_typedef_ns.rs new file mode 100644 index 0000000000..44afa4822a --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/libclang-9/struct_typedef_ns.rs @@ -0,0 +1,87 @@ +#![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 { + #[allow(unused_imports)] + use self::super::root; + pub mod whatever { + #[allow(unused_imports)] + use self::super::super::root; + #[repr(C)] + #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] + pub struct typedef_struct { + pub foo: ::std::os::raw::c_int, + } + #[test] + fn bindgen_test_layout_typedef_struct() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(typedef_struct)), + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(typedef_struct)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(typedef_struct), + "::", + stringify!(foo), + ), + ); + } + #[repr(u32)] + #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] + pub enum typedef_enum { + BAR = 1, + } + } + pub mod _bindgen_mod_id_12 { + #[allow(unused_imports)] + use self::super::super::root; + #[repr(C)] + #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] + pub struct _bindgen_ty_1 { + pub foo: ::std::os::raw::c_int, + } + #[test] + fn bindgen_test_layout__bindgen_ty_1() { + const UNINIT: ::std::mem::MaybeUninit<_bindgen_ty_1> = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::<_bindgen_ty_1>(), + 4usize, + concat!("Size of: ", stringify!(_bindgen_ty_1)), + ); + assert_eq!( + ::std::mem::align_of::<_bindgen_ty_1>(), + 4usize, + concat!("Alignment of ", stringify!(_bindgen_ty_1)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(_bindgen_ty_1), + "::", + stringify!(foo), + ), + ); + } + pub type typedef_struct = root::_bindgen_mod_id_12::_bindgen_ty_1; + pub const _bindgen_mod_id_12_BAR: root::_bindgen_mod_id_12::_bindgen_ty_2 = _bindgen_ty_2::BAR; + #[repr(u32)] + #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] + pub enum _bindgen_ty_2 { + BAR = 1, + } + pub use self::super::super::root::_bindgen_mod_id_12::_bindgen_ty_2 as typedef_enum; + } +} diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/type_alias_template_specialized.rs b/bindgen-tests/tests/expectations/tests/libclang-9/type_alias_template_specialized.rs deleted file mode 100644 index d585a857d9..0000000000 --- a/bindgen-tests/tests/expectations/tests/libclang-9/type_alias_template_specialized.rs +++ /dev/null @@ -1,56 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct Rooted { - pub ptr: MaybeWrapped<::std::os::raw::c_int>, -} -#[test] -fn bindgen_test_layout_Rooted() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Rooted)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Rooted)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Rooted), "::", stringify!(ptr)), - ); -} -impl Default for Rooted { - fn default() -> Self { - let mut s = ::std::mem::MaybeUninit::::uninit(); - unsafe { - ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); - s.assume_init() - } - } -} -///
-pub type MaybeWrapped
= a; -#[test] -fn __bindgen_test_layout_MaybeWrapped_open0_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!( - "Size of template specialization: ", - stringify!(MaybeWrapped < ::std::os::raw::c_int >), - ), - ); - assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(MaybeWrapped < ::std::os::raw::c_int >), - ), - ); -} diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/zero-sized-array.rs b/bindgen-tests/tests/expectations/tests/libclang-9/zero-sized-array.rs deleted file mode 100644 index bc4b660029..0000000000 --- a/bindgen-tests/tests/expectations/tests/libclang-9/zero-sized-array.rs +++ /dev/null @@ -1,170 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -#[derive(Default)] -pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); -impl __IncompleteArrayField { - #[inline] - pub const fn new() -> Self { - __IncompleteArrayField(::std::marker::PhantomData, []) - } - #[inline] - pub fn as_ptr(&self) -> *const T { - self as *const _ as *const T - } - #[inline] - pub fn as_mut_ptr(&mut self) -> *mut T { - self as *mut _ as *mut T - } - #[inline] - pub unsafe fn as_slice(&self, len: usize) -> &[T] { - ::std::slice::from_raw_parts(self.as_ptr(), len) - } - #[inline] - pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) - } -} -impl ::std::fmt::Debug for __IncompleteArrayField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__IncompleteArrayField") - } -} -/// Bizarrely enough, this should *not* get an `_address` field. -#[repr(C)] -#[derive(Debug, Default)] -pub struct ZeroSizedArray { - pub arr: __IncompleteArrayField<::std::os::raw::c_char>, -} -#[test] -fn bindgen_test_layout_ZeroSizedArray() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(ZeroSizedArray)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(ZeroSizedArray)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(ZeroSizedArray), "::", stringify!(arr)), - ); -} -/// And nor should this get an `_address` field. -#[repr(C)] -#[derive(Debug, Default)] -pub struct ContainsZeroSizedArray { - pub zsa: ZeroSizedArray, -} -#[test] -fn bindgen_test_layout_ContainsZeroSizedArray() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(ContainsZeroSizedArray)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(ContainsZeroSizedArray)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).zsa) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContainsZeroSizedArray), - "::", - stringify!(zsa), - ), - ); -} -/** Inheriting from ZeroSizedArray shouldn't cause an `_address` to be inserted - either.*/ -#[repr(C)] -#[derive(Debug, Default)] -pub struct InheritsZeroSizedArray { - pub _base: ZeroSizedArray, -} -#[test] -fn bindgen_test_layout_InheritsZeroSizedArray() { - assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(InheritsZeroSizedArray)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(InheritsZeroSizedArray)), - ); -} -/// And this should not get an `_address` field either. -#[repr(C)] -#[derive(Debug, Default)] -pub struct DynamicallySizedArray { - pub arr: __IncompleteArrayField<::std::os::raw::c_char>, -} -#[test] -fn bindgen_test_layout_DynamicallySizedArray() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(DynamicallySizedArray)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(DynamicallySizedArray)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(DynamicallySizedArray), - "::", - stringify!(arr), - ), - ); -} -/// No `_address` field here either. -#[repr(C)] -#[derive(Debug, Default)] -pub struct ContainsDynamicallySizedArray { - pub dsa: DynamicallySizedArray, -} -#[test] -fn bindgen_test_layout_ContainsDynamicallySizedArray() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(ContainsDynamicallySizedArray)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(ContainsDynamicallySizedArray)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dsa) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContainsDynamicallySizedArray), - "::", - stringify!(dsa), - ), - ); -} diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/mangling-win32.rs b/bindgen-tests/tests/expectations/tests/mangling-win32.rs similarity index 100% rename from bindgen-tests/tests/expectations/tests/libclang-5/mangling-win32.rs rename to bindgen-tests/tests/expectations/tests/mangling-win32.rs diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/objc_inheritance.rs b/bindgen-tests/tests/expectations/tests/objc_inheritance.rs similarity index 100% rename from bindgen-tests/tests/expectations/tests/libclang-5/objc_inheritance.rs rename to bindgen-tests/tests/expectations/tests/objc_inheritance.rs diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/objc_template.rs b/bindgen-tests/tests/expectations/tests/objc_template.rs similarity index 100% rename from bindgen-tests/tests/expectations/tests/libclang-9/objc_template.rs rename to bindgen-tests/tests/expectations/tests/objc_template.rs diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/partial-specialization-and-inheritance.rs b/bindgen-tests/tests/expectations/tests/partial-specialization-and-inheritance.rs similarity index 100% rename from bindgen-tests/tests/expectations/tests/libclang-5/partial-specialization-and-inheritance.rs rename to bindgen-tests/tests/expectations/tests/partial-specialization-and-inheritance.rs diff --git a/bindgen-tests/tests/expectations/tests/struct_typedef_ns.rs b/bindgen-tests/tests/expectations/tests/struct_typedef_ns.rs index 44afa4822a..aabe23b18e 100644 --- a/bindgen-tests/tests/expectations/tests/struct_typedef_ns.rs +++ b/bindgen-tests/tests/expectations/tests/struct_typedef_ns.rs @@ -47,41 +47,38 @@ pub mod root { use self::super::super::root; #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] - pub struct _bindgen_ty_1 { + pub struct typedef_struct { pub foo: ::std::os::raw::c_int, } #[test] - fn bindgen_test_layout__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit<_bindgen_ty_1> = ::std::mem::MaybeUninit::uninit(); + fn bindgen_test_layout_typedef_struct() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); assert_eq!( - ::std::mem::size_of::<_bindgen_ty_1>(), + ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(_bindgen_ty_1)), + concat!("Size of: ", stringify!(typedef_struct)), ); assert_eq!( - ::std::mem::align_of::<_bindgen_ty_1>(), + ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(_bindgen_ty_1)), + concat!("Alignment of ", stringify!(typedef_struct)), ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, 0usize, concat!( "Offset of field: ", - stringify!(_bindgen_ty_1), + stringify!(typedef_struct), "::", stringify!(foo), ), ); } - pub type typedef_struct = root::_bindgen_mod_id_12::_bindgen_ty_1; - pub const _bindgen_mod_id_12_BAR: root::_bindgen_mod_id_12::_bindgen_ty_2 = _bindgen_ty_2::BAR; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] - pub enum _bindgen_ty_2 { + pub enum typedef_enum { BAR = 1, } - pub use self::super::super::root::_bindgen_mod_id_12::_bindgen_ty_2 as typedef_enum; } } diff --git a/bindgen-tests/tests/expectations/tests/libclang-5/type_alias_template_specialized.rs b/bindgen-tests/tests/expectations/tests/type_alias_template_specialized.rs similarity index 100% rename from bindgen-tests/tests/expectations/tests/libclang-5/type_alias_template_specialized.rs rename to bindgen-tests/tests/expectations/tests/type_alias_template_specialized.rs diff --git a/bindgen-tests/tests/expectations/tests/zero-sized-array.rs b/bindgen-tests/tests/expectations/tests/zero-sized-array.rs index b0a1d3e538..bc4b660029 100644 --- a/bindgen-tests/tests/expectations/tests/zero-sized-array.rs +++ b/bindgen-tests/tests/expectations/tests/zero-sized-array.rs @@ -114,6 +114,8 @@ pub struct DynamicallySizedArray { } #[test] fn bindgen_test_layout_DynamicallySizedArray() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 0usize, @@ -124,6 +126,16 @@ fn bindgen_test_layout_DynamicallySizedArray() { 1usize, concat!("Alignment of ", stringify!(DynamicallySizedArray)), ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(DynamicallySizedArray), + "::", + stringify!(arr), + ), + ); } /// No `_address` field here either. #[repr(C)] @@ -133,6 +145,8 @@ pub struct ContainsDynamicallySizedArray { } #[test] fn bindgen_test_layout_ContainsDynamicallySizedArray() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), 0usize, @@ -143,4 +157,14 @@ fn bindgen_test_layout_ContainsDynamicallySizedArray() { 1usize, concat!("Alignment of ", stringify!(ContainsDynamicallySizedArray)), ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).dsa) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ContainsDynamicallySizedArray), + "::", + stringify!(dsa), + ), + ); } diff --git a/bindgen-tests/tests/headers/issue-544-stylo-creduce-2.hpp b/bindgen-tests/tests/headers/issue-544-stylo-creduce-2.hpp index f3467f4528..b41b422d1e 100644 --- a/bindgen-tests/tests/headers/issue-544-stylo-creduce-2.hpp +++ b/bindgen-tests/tests/headers/issue-544-stylo-creduce-2.hpp @@ -4,5 +4,12 @@ template struct Foo { template using FirstAlias = typename T::Associated; template using SecondAlias = Foo>; + +#if 0 + // FIXME: This regressed sometime between libclang 9 and 16, though it + // never quite worked properly so... SecondAlias member; +#else + SecondAlias* member; +#endif }; diff --git a/bindgen-tests/tests/stylo_sanity.rs b/bindgen-tests/tests/stylo_sanity.rs index e1ad86b04d..e9ec69bcb8 100755 --- a/bindgen-tests/tests/stylo_sanity.rs +++ b/bindgen-tests/tests/stylo_sanity.rs @@ -19,8 +19,8 @@ extern crate bindgen; feature = "__testing_only_extra_assertions", )))] #[cfg(any( - feature = "__testing_only_libclang_5", - feature = "__testing_only_libclang_9" + feature = "__testing_only_libclang_9", + feature = "__testing_only_libclang_16" ))] fn sanity_check_can_generate_stylo_bindings() { use std::time::Instant; diff --git a/bindgen-tests/tests/tests.rs b/bindgen-tests/tests/tests.rs index 1913b874f0..bcc02b8dfe 100644 --- a/bindgen-tests/tests/tests.rs +++ b/bindgen-tests/tests/tests.rs @@ -148,21 +148,19 @@ fn compare_generated_header( { let mut expectation = expectation.clone(); - if cfg!(feature = "__testing_only_libclang_9") { + if cfg!(feature = "__testing_only_libclang_16") { + expectation.push("libclang-16"); + } else if cfg!(feature = "__testing_only_libclang_9") { expectation.push("libclang-9"); - } else if cfg!(feature = "__testing_only_libclang_5") { - expectation.push("libclang-5"); } else { match clang_version().parsed { - None => expectation.push("libclang-9"), + None => expectation.push("libclang-16"), Some(version) => { let (maj, min) = version; - let version_str = if maj >= 9 { + let version_str = if maj >= 16 { + "16".to_owned() + } else if maj >= 9 { "9".to_owned() - } else if maj >= 5 { - "5".to_owned() - } else if maj >= 4 { - "4".to_owned() } else { format!("{}.{}", maj, min) }; diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index 7dd4d01d29..733679a603 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -58,7 +58,7 @@ __cli = [] # Features used for CI testing __testing_only_extra_assertions = [] __testing_only_libclang_9 = [] -__testing_only_libclang_5 = [] +__testing_only_libclang_16 = [] [package.metadata.docs.rs] features = ["experimental"] diff --git a/ci/test.sh b/ci/test.sh index c0c8bec59b..11e091f49f 100755 --- a/ci/test.sh +++ b/ci/test.sh @@ -9,20 +9,22 @@ set -x set -o pipefail function llvm_linux_target_triple() { - echo "x86_64-linux-gnu-ubuntu-16.04" + case "$1" in + 9.0.1) echo "x86_64-linux-gnu-ubuntu-16.04" ;; + *) echo "x86_64-linux-gnu-ubuntu-18.04" ;; + esac } function llvm_macos_target_triple() { case "$1" in - [0-8].* | 9.0.0) echo "x86_64-darwin-apple" ;; - # Starting with 9.0.1, triple swapped ordering - *) echo "x86_64-apple-darwin" ;; + 9.0.1) echo "x86_64-apple-darwin" ;; + *) echo "arm64-apple-darwin22.0" ;; esac } function llvm_version_triple() { case "$1" in - 5.0) echo "5.0.1" ;; + 9.0) echo "9.0.1" ;; # By default, take the .0 patch release *) echo "$1.0" ;; esac @@ -30,16 +32,7 @@ function llvm_version_triple() { function llvm_base_url() { local llvm_version_triple=$1 - - case "$llvm_version_triple" in - [0-8].* | 9.0.0) - echo "http://releases.llvm.org/$llvm_version_triple" - ;; - # Starting with 9.0.1, releases are hosted on github - *) - echo "https://github.com/llvm/llvm-project/releases/download/llvmorg-$llvm_version_triple" - ;; - esac + echo "https://github.com/llvm/llvm-project/releases/download/llvmorg-$llvm_version_triple" } function llvm_download() { From 46c06e5ef11c01680edd9ca250ed0c32b6cdc9e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sat, 13 Jan 2024 02:21:05 +0100 Subject: [PATCH 610/942] ci: Try to keep mac CI on 9.0 --- .github/workflows/bindgen.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 883fb46b5c..ebf70dce09 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -175,14 +175,14 @@ jobs: # feature_extra_asserts: 0 # Ensure stuff works on macos too - # Disabled for now because llvm doesn't provide releases for x86-64 - # macOS which is what the runner uses. + # FIXME: Ideally should use the latest llvm version, but llvm doesn't + # provide releases for x86-64 macOS anymore which is what the runner uses. # - # - os: macos-latest - # llvm_version: "16.0" - # release_build: 0 - # no_default_features: 0 - # feature_extra_asserts: 0 + - os: macos-latest + llvm_version: "9.0" + release_build: 0 + no_default_features: 0 + feature_extra_asserts: 0 steps: - uses: actions/checkout@v3 From 3239e69ddb0f7af694d6a889c5b589131ddd3001 Mon Sep 17 00:00:00 2001 From: Simon Paitrault Date: Mon, 22 Jan 2024 16:17:12 +0100 Subject: [PATCH 611/942] chore: updating shlex regarding RUSTSEC-2024-0006 Signed-off-by: Simon Paitrault --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a4d120a864..d64377809c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -565,9 +565,9 @@ dependencies = [ [[package]] name = "shlex" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "similar" From 3370a3cd7e30a434c9d5b003433273b48ef2e4d4 Mon Sep 17 00:00:00 2001 From: Moritz Hedtke Date: Sat, 20 Jan 2024 23:46:40 +0100 Subject: [PATCH 612/942] Replace peeking_take_while by itertools --- Cargo.lock | 17 ++++++++++------- bindgen/Cargo.toml | 2 +- bindgen/ir/comp.rs | 3 ++- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d64377809c..33a2e1b7d0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -29,10 +29,10 @@ dependencies = [ "bitflags 2.2.1", "cexpr", "clang-sys", + "itertools", "lazy_static", "lazycell", "log", - "peeking_take_while", "prettyplease", "proc-macro2", "quote", @@ -299,6 +299,15 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "itertools" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25db6b064527c5d482d0423354fcd07a89a2dfe07b67892e62411946db7f07b0" +dependencies = [ + "either", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -406,12 +415,6 @@ version = "3.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" -[[package]] -name = "peeking_take_while" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" - [[package]] name = "prettyplease" version = "0.2.7" diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index 733679a603..eafa2ce35d 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -29,10 +29,10 @@ annotate-snippets = { version = "0.9.1", features = ["color"], optional = true } bitflags = "2.2.1" cexpr = "0.6" clang-sys = { version = "1", features = ["clang_6_0"] } +itertools = { version = "0.12.0", default-features = false } lazy_static = "1" lazycell = "1" log = { version = "0.4", optional = true } -peeking_take_while = "0.1.2" prettyplease = { version = "0.2.7", optional = true, features = ["verbatim"] } proc-macro2 = { version = "1", default-features = false } quote = { version = "1", default-features = false } diff --git a/bindgen/ir/comp.rs b/bindgen/ir/comp.rs index 89e77e160f..a5d06fa556 100644 --- a/bindgen/ir/comp.rs +++ b/bindgen/ir/comp.rs @@ -1,5 +1,7 @@ //! Compound types (unions and structs) in our intermediate representation. +use itertools::Itertools; + use super::analysis::Sizedness; use super::annotations::Annotations; use super::context::{BindgenContext, FunctionId, ItemId, TypeId, VarId}; @@ -15,7 +17,6 @@ use crate::ir::derive::CanDeriveCopy; use crate::parse::ParseError; use crate::HashMap; use crate::NonCopyUnionStyle; -use peeking_take_while::PeekableExt; use std::cmp; use std::io; use std::mem; From c0ebd68669557ce290dbc24c9cc5fd5ab2168aaf Mon Sep 17 00:00:00 2001 From: Matthys Strydom Date: Fri, 26 Jan 2024 14:39:34 -0800 Subject: [PATCH 613/942] Update Rust Code of Conduct link in Contribution guide The contribution guide seems to be pointing at a dead link. This commit updates the link to a working version. --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 62cf80742e..491e233147 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -45,7 +45,7 @@ and introduce yourself. We abide by the [Rust Code of Conduct][coc] and ask that you do as well. -[coc]: https://www.rust-lang.org/en-US/conduct.html +[coc]: https://www.rust-lang.org/policies/code-of-conduct ## Filing an Issue From a8fa94280a93d608ccc8c770a6966639924b0a5a Mon Sep 17 00:00:00 2001 From: LuncyBloont Date: Sat, 27 Jan 2024 17:38:45 +0800 Subject: [PATCH 614/942] Use `CargoCallbacks::new()` instead of `bindgen::CargoCallbacks` in the example code --- book/src/tutorial-3.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/src/tutorial-3.md b/book/src/tutorial-3.md index 599ece2708..a8b825ecc8 100644 --- a/book/src/tutorial-3.md +++ b/book/src/tutorial-3.md @@ -33,7 +33,7 @@ fn main() { .header("wrapper.h") // Tell cargo to invalidate the built crate whenever any of the // included header files changed. - .parse_callbacks(Box::new(bindgen::CargoCallbacks)) + .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) // Finish the builder and generate the bindings. .generate() // Unwrap the Result and panic on failure. From 6e133bad2c4265b9de7c53e8b73a8a5a8b6cfd0f Mon Sep 17 00:00:00 2001 From: George Hopkins Date: Thu, 18 Jan 2024 11:35:47 +0100 Subject: [PATCH 615/942] Use CargoCallbacks::new() in documentation --- bindgen/lib.rs | 2 +- book/src/non-system-libraries.md | 5 +---- book/src/tutorial-3.md | 3 --- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 70aa67149f..11c2fa2c4e 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -1239,7 +1239,7 @@ fn get_target_dependent_env_var( /// use bindgen::builder; /// let bindings = builder() /// .header("path/to/input/header") -/// .parse_callbacks(Box::new(bindgen::CargoCallbacks)) +/// .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) /// .generate(); /// ``` #[derive(Debug)] diff --git a/book/src/non-system-libraries.md b/book/src/non-system-libraries.md index 7d6e4e3d45..1bb19e4d0b 100644 --- a/book/src/non-system-libraries.md +++ b/book/src/non-system-libraries.md @@ -48,9 +48,6 @@ fn main() { // automatically know it must look for a `libhello.a` file. println!("cargo:rustc-link-lib=hello"); - // Tell cargo to invalidate the built crate whenever the header changes. - println!("cargo:rerun-if-changed={}", headers_path_str); - // Run `clang` to compile the `hello.c` file into a `hello.o` object file. // Unwrap if it is not possible to spawn the process. if !std::process::Command::new("clang") @@ -91,7 +88,7 @@ fn main() { .header(headers_path_str) // Tell cargo to invalidate the built crate whenever any of the // included header files changed. - .parse_callbacks(Box::new(CargoCallbacks)) + .parse_callbacks(Box::new(CargoCallbacks::new())) // Finish the builder and generate the bindings. .generate() // Unwrap the Result and panic on failure. diff --git a/book/src/tutorial-3.md b/book/src/tutorial-3.md index a8b825ecc8..3248f2847f 100644 --- a/book/src/tutorial-3.md +++ b/book/src/tutorial-3.md @@ -21,9 +21,6 @@ fn main() { // shared library. println!("cargo:rustc-link-lib=bz2"); - // Tell cargo to invalidate the built crate whenever the wrapper changes - println!("cargo:rerun-if-changed=wrapper.h"); - // The bindgen::Builder is the main entry point // to bindgen, and lets you build up options for // the resulting bindings. From 199bee441ad0fb81b4b054e0c1e2ffb51f4e4a6d Mon Sep 17 00:00:00 2001 From: Thomas Bertschinger Date: Tue, 23 Jan 2024 21:41:14 -0700 Subject: [PATCH 616/942] try to avoid `#[repr(packed)]` when `align` is needed Currently rustc forbids compound types from having both a `packed` and `align` attribute. When a source type has both attributes, this may mean it cannot be represented with the current rustc. Often, though, one or both of these attributes is redundant and can be safely removed from the generated Rust code. Previously, bindgen avoided placing the `align` attribute when it is not needed. However, it would always place the `packed` attribute if the source type has it, even when it is redundant because the source type is "naturally packed". With this change, bindgen avoids placing `packed` on a type if the `packed` is redundant and the type needs an `align` attribute. If the type does not have an "align" attribute, then bindgen will still place `packed` so as to avoid changing existing working behavior. This commit also takes out an extraneous `is_packed()` call from `StructLayoutTracker::new()` since the value can be passed in from the caller; this avoids duplicating work in some cases. --- .../tests/redundant-packed-and-align.rs | 369 ++++++++++++++++++ .../headers/redundant-packed-and-align.h | 42 ++ bindgen/codegen/mod.rs | 10 +- bindgen/codegen/struct_layout.rs | 2 +- bindgen/ir/comp.rs | 20 + 5 files changed, 441 insertions(+), 2 deletions(-) create mode 100644 bindgen-tests/tests/expectations/tests/redundant-packed-and-align.rs create mode 100644 bindgen-tests/tests/headers/redundant-packed-and-align.h diff --git a/bindgen-tests/tests/expectations/tests/redundant-packed-and-align.rs b/bindgen-tests/tests/expectations/tests/redundant-packed-and-align.rs new file mode 100644 index 0000000000..b5feaa140a --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/redundant-packed-and-align.rs @@ -0,0 +1,369 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[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] + 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]; + 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 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]; + 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 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 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); + } + } +} +#[repr(C)] +#[repr(align(8))] +#[derive(Debug, Default, Copy, Clone)] +pub struct redundant_packed { + pub a: u32, + pub b: u32, +} +#[test] +fn bindgen_test_layout_redundant_packed() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(redundant_packed)), + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(redundant_packed)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(redundant_packed), "::", stringify!(a)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(redundant_packed), "::", stringify!(b)), + ); +} +#[repr(C)] +#[repr(align(8))] +#[derive(Debug, Default, Copy, Clone)] +pub struct redundant_packed_bitfield { + pub a: [u8; 3usize], + pub _bitfield_align_1: [u8; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, + pub c: u32, +} +#[test] +fn bindgen_test_layout_redundant_packed_bitfield() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(redundant_packed_bitfield)), + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(redundant_packed_bitfield)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(redundant_packed_bitfield), + "::", + stringify!(a), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(redundant_packed_bitfield), + "::", + stringify!(c), + ), + ); +} +impl redundant_packed_bitfield { + #[inline] + pub fn b0(&self) -> u8 { + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) } + } + #[inline] + pub fn set_b0(&mut self, val: u8) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + self._bitfield_1.set(0usize, 1u8, val as u64) + } + } + #[inline] + pub fn b1(&self) -> u8 { + unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u8) } + } + #[inline] + pub fn set_b1(&mut self, val: u8) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + self._bitfield_1.set(1usize, 1u8, val as u64) + } + } + #[inline] + pub fn new_bitfield_1(b0: u8, b1: u8) -> __BindgenBitfieldUnit<[u8; 1usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let b0: u8 = unsafe { ::std::mem::transmute(b0) }; + b0 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 1usize, + 1u8, + { + let b1: u8 = unsafe { ::std::mem::transmute(b1) }; + b1 as u64 + }, + ); + __bindgen_bitfield_unit + } +} +#[repr(C)] +#[repr(align(16))] +#[derive(Copy, Clone)] +pub union redundant_packed_union { + pub a: u64, + pub b: u32, +} +#[test] +fn bindgen_test_layout_redundant_packed_union() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(redundant_packed_union)), + ); + assert_eq!( + ::std::mem::align_of::(), + 16usize, + concat!("Alignment of ", stringify!(redundant_packed_union)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(redundant_packed_union), + "::", + stringify!(a), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(redundant_packed_union), + "::", + stringify!(b), + ), + ); +} +impl Default for redundant_packed_union { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] +#[repr(align(2))] +#[derive(Debug, Default, Copy, Clone)] +pub struct inner { + pub a: u8, +} +#[test] +fn bindgen_test_layout_inner() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 2usize, + concat!("Size of: ", stringify!(inner)), + ); + assert_eq!( + ::std::mem::align_of::(), + 2usize, + concat!("Alignment of ", stringify!(inner)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(inner), "::", stringify!(a)), + ); +} +#[repr(C)] +#[repr(align(8))] +#[derive(Debug, Default, Copy, Clone)] +pub struct outer_redundant_packed { + pub a: [inner; 2usize], + pub b: u32, +} +#[test] +fn bindgen_test_layout_outer_redundant_packed() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(outer_redundant_packed)), + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(outer_redundant_packed)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(outer_redundant_packed), + "::", + stringify!(a), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(outer_redundant_packed), + "::", + stringify!(b), + ), + ); +} +#[repr(C)] +#[repr(align(4))] +#[derive(Debug, Default, Copy, Clone)] +pub struct redundant_pragma_packed { + pub a: u8, + pub b: u16, +} +#[test] +fn bindgen_test_layout_redundant_pragma_packed() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(redundant_pragma_packed)), + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(redundant_pragma_packed)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(redundant_pragma_packed), + "::", + stringify!(a), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, + 2usize, + concat!( + "Offset of field: ", + stringify!(redundant_pragma_packed), + "::", + stringify!(b), + ), + ); +} diff --git a/bindgen-tests/tests/headers/redundant-packed-and-align.h b/bindgen-tests/tests/headers/redundant-packed-and-align.h new file mode 100644 index 0000000000..75e15e4139 --- /dev/null +++ b/bindgen-tests/tests/headers/redundant-packed-and-align.h @@ -0,0 +1,42 @@ +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; +typedef unsigned long long uint64_t; + +struct redundant_packed { + uint32_t a; + uint32_t b; +} __attribute__((packed, aligned(8))); + +struct redundant_packed_bitfield { + uint8_t a[3]; + uint8_t b0:1; + uint8_t b1:1; + uint32_t c; +} __attribute__((packed, aligned(8))); + + +union redundant_packed_union { + uint64_t a; + uint32_t b; +} __attribute__((packed, aligned(16))); + + +struct inner { + uint8_t a; +} __attribute__((packed, aligned(2))); + +struct outer_redundant_packed { + struct inner a[2]; + uint32_t b; +} __attribute__((packed, aligned(8))); + + +#pragma pack(2) + +struct redundant_pragma_packed { + uint8_t a; + uint16_t b; +} __attribute__((aligned(4))); + +#pragma pack() diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index c84320ce5b..b2f0f15173 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -1977,6 +1977,7 @@ impl CodeGenerator for CompInfo { ty, &canonical_name, visibility, + packed, ); if !is_opaque { @@ -2196,7 +2197,14 @@ impl CodeGenerator for CompInfo { if let Some(comment) = item.comment(ctx) { attributes.push(attributes::doc(comment)); } - if packed && !is_opaque { + + // if a type has both a "packed" attribute and an "align(N)" attribute, then check if the + // "packed" attr is redundant, and do not include it if so. + if packed && + !is_opaque && + !(explicit_align.is_some() && + self.already_packed(ctx).map_or(false, |t| t)) + { 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 { diff --git a/bindgen/codegen/struct_layout.rs b/bindgen/codegen/struct_layout.rs index a62da69534..f4596a1992 100644 --- a/bindgen/codegen/struct_layout.rs +++ b/bindgen/codegen/struct_layout.rs @@ -91,9 +91,9 @@ impl<'a> StructLayoutTracker<'a> { ty: &'a Type, name: &'a str, visibility: FieldVisibilityKind, + is_packed: bool, ) -> Self { let known_type_layout = ty.layout(ctx); - let is_packed = comp.is_packed(ctx, known_type_layout.as_ref()); let (is_rust_union, can_copy_union_fields) = comp.is_rust_union(ctx, known_type_layout.as_ref(), name); StructLayoutTracker { diff --git a/bindgen/ir/comp.rs b/bindgen/ir/comp.rs index a5d06fa556..fed6ba8ac8 100644 --- a/bindgen/ir/comp.rs +++ b/bindgen/ir/comp.rs @@ -1642,6 +1642,26 @@ impl CompInfo { false } + /// Return true if a compound type is "naturally packed". This means we can exclude the + /// "packed" attribute without changing the layout. + /// This is useful for types that need an "align(N)" attribute since rustc won't compile + /// structs that have both of those attributes. + pub(crate) fn already_packed(&self, ctx: &BindgenContext) -> Option { + let mut total_size: usize = 0; + + for field in self.fields().iter() { + let layout = field.layout(ctx)?; + + if layout.align != 0 && total_size % layout.align != 0 { + return Some(false); + } + + total_size += layout.size; + } + + Some(true) + } + /// Returns true if compound type has been forward declared pub(crate) fn is_forward_declaration(&self) -> bool { self.is_forward_declaration From 66328b237e93556bb4007156d26219d060dbb39e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 31 Jan 2024 19:56:34 +0100 Subject: [PATCH 617/942] codegen: Fix a nit I commented on #2734. --- bindgen/codegen/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index b2f0f15173..dd1486df74 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -2203,7 +2203,7 @@ impl CodeGenerator for CompInfo { if packed && !is_opaque && !(explicit_align.is_some() && - self.already_packed(ctx).map_or(false, |t| t)) + 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); From ee94c43554407f6b57c5dc44aa8914835f4760c0 Mon Sep 17 00:00:00 2001 From: Axel Viala Date: Mon, 22 Jan 2024 17:54:54 +0100 Subject: [PATCH 618/942] Add test for quoted Env variables passed with BINDGEN_EXTRA_CLANG_ARGS. Before the test was too broad and just tested for the definition of the variable. With this test we can ensure that quoting was indeed managed. Signed-off-by: Axel Viala --- bindgen-tests/tests/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindgen-tests/tests/tests.rs b/bindgen-tests/tests/tests.rs index bcc02b8dfe..9df45c3b07 100644 --- a/bindgen-tests/tests/tests.rs +++ b/bindgen-tests/tests/tests.rs @@ -390,7 +390,7 @@ fn test_clang_env_args() { "test.hpp", "#ifdef _ENV_ONE\nextern const int x[] = { 42 };\n#endif\n\ #ifdef _ENV_TWO\nextern const int y[] = { 42 };\n#endif\n\ - #ifdef NOT_THREE\nextern const int z[] = { 42 };\n#endif\n", + #if defined NOT_THREE && NOT_THREE == 1\nextern const int z[] = { 42 };\n#endif\n", ) .generate() .unwrap() From b7de6ee766fdb3b2f2acdba6e31cd7eea0a62bbb Mon Sep 17 00:00:00 2001 From: Dhruvin Gandhi Date: Tue, 23 Jan 2024 13:22:45 +0530 Subject: [PATCH 619/942] feat: add blocklist_var --- bindgen-cli/options.rs | 8 ++++++++ .../tests/expectations/tests/blocklist-var.rs | 1 + bindgen-tests/tests/headers/blocklist-var.hpp | 3 +++ bindgen/ir/item.rs | 7 +++++-- bindgen/lib.rs | 4 +++- bindgen/options/mod.rs | 16 ++++++++++++++++ book/src/blocklisting.md | 2 ++ 7 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 bindgen-tests/tests/expectations/tests/blocklist-var.rs create mode 100644 bindgen-tests/tests/headers/blocklist-var.hpp diff --git a/bindgen-cli/options.rs b/bindgen-cli/options.rs index f82d391901..66bb3f1439 100644 --- a/bindgen-cli/options.rs +++ b/bindgen-cli/options.rs @@ -156,6 +156,9 @@ struct BindgenCommand { /// Mark FILE as hidden. #[arg(long, value_name = "FILE")] blocklist_file: Vec, + /// Mark VAR as hidden. + #[arg(long, value_name = "VAR")] + blocklist_var: Vec, /// Avoid generating layout tests for any type. #[arg(long)] no_layout_tests: bool, @@ -471,6 +474,7 @@ where blocklist_function, blocklist_item, blocklist_file, + blocklist_var, no_layout_tests, no_derive_copy, no_derive_debug, @@ -676,6 +680,10 @@ where builder = builder.blocklist_file(file); } + for var in blocklist_var { + builder = builder.blocklist_var(var); + } + if builtins { builder = builder.emit_builtins(); } diff --git a/bindgen-tests/tests/expectations/tests/blocklist-var.rs b/bindgen-tests/tests/expectations/tests/blocklist-var.rs new file mode 100644 index 0000000000..fe64295a68 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/blocklist-var.rs @@ -0,0 +1 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] \ No newline at end of file diff --git a/bindgen-tests/tests/headers/blocklist-var.hpp b/bindgen-tests/tests/headers/blocklist-var.hpp new file mode 100644 index 0000000000..3c70e6f032 --- /dev/null +++ b/bindgen-tests/tests/headers/blocklist-var.hpp @@ -0,0 +1,3 @@ +// bindgen-flags: --blocklist-var should_be_blocked + +extern int should_be_blocked; diff --git a/bindgen/ir/item.rs b/bindgen/ir/item.rs index dd587b088b..2941eb81e2 100644 --- a/bindgen/ir/item.rs +++ b/bindgen/ir/item.rs @@ -668,8 +668,11 @@ impl Item { ItemKind::Function(..) => { ctx.options().blocklisted_functions.matches(&name) } - // TODO: Add constant / namespace blocklisting? - ItemKind::Var(..) | ItemKind::Module(..) => false, + ItemKind::Var(..) => { + ctx.options().blocklisted_vars.matches(&name) + } + // TODO: Add namespace blocklisting? + ItemKind::Module(..) => false, } } diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 11c2fa2c4e..c4ab11486c 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -440,13 +440,14 @@ impl Builder { impl BindgenOptions { fn build(&mut self) { - const REGEX_SETS_LEN: usize = 28; + const REGEX_SETS_LEN: usize = 29; let regex_sets: [_; REGEX_SETS_LEN] = [ &mut self.blocklisted_types, &mut self.blocklisted_functions, &mut self.blocklisted_items, &mut self.blocklisted_files, + &mut self.blocklisted_vars, &mut self.opaque_types, &mut self.allowlisted_vars, &mut self.allowlisted_types, @@ -483,6 +484,7 @@ impl BindgenOptions { "--blocklist-function", "--blocklist-item", "--blocklist-file", + "--blocklist-var", "--opaque-type", "--allowlist-type", "--allowlist-function", diff --git a/bindgen/options/mod.rs b/bindgen/options/mod.rs index 3a82bcf397..1fc2241615 100644 --- a/bindgen/options/mod.rs +++ b/bindgen/options/mod.rs @@ -222,6 +222,22 @@ options! { }, as_args: "--blocklist-file", }, + /// Variables that have been blocklisted and should not appear in the generated code. + blocklisted_vars: RegexSet { + methods: { + regex_option! { + /// Do not generate any bindings for the given variable. + /// + /// This option is not recursive, meaning that it will only block variables whose + /// names explicitly match the argument of this method. + pub fn blocklist_var>(mut self, arg: T) -> Builder { + self.options.blocklisted_vars.insert(arg); + self + } + } + }, + as_args: "--blocklist-var", + }, /// Types that should be treated as opaque structures in the generated code. opaque_types: RegexSet { methods: { diff --git a/book/src/blocklisting.md b/book/src/blocklisting.md index 6eb5786328..535a08c8d5 100644 --- a/book/src/blocklisting.md +++ b/book/src/blocklisting.md @@ -22,6 +22,7 @@ that are transitively included. * [`bindgen::Builder::blocklist_function`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.blocklist_function) * [`bindgen::Builder::blocklist_item`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.blocklist_item) * [`bindgen::Builder::blocklist_type`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.blocklist_type) +* [`bindgen::Builder::blocklist_var`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.blocklist_var) ### Command Line @@ -29,6 +30,7 @@ that are transitively included. * `--blocklist-function ` * `--blocklist-item ` * `--blocklist-type ` +* `--blocklist-var ` ### Annotations From 84c0612608c949d46575a581cdda7855053d13d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 4 Feb 2024 12:29:08 +0100 Subject: [PATCH 620/942] changelog: Prepare for 0.69.3 release. --- CHANGELOG.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f39caa1c1..e2af0ea870 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -191,11 +191,28 @@ -------------------------------------------------------------------------------- # Unreleased ## Added + +- Added blocklist_var (#2731) +- Stabilized thiscall_abi (#2661) + ## Changed + +- Use CR consistently on windows (#2698) +- Replaced peeking_take_while by itertools (#2724) + ## Removed ## Fixed + +- Try to avoid repr(packed) for explicitly aligned types when not needed (#2734) +- Improved destructor handling on Windows (#2663) +- Support Float16 (#2667) +- Fix alignment contribution from bitfields (#2680) +- Fixed msrv build. + ## Security +- Updated shlex dependency (RUSTSEC-2024-0006) + # 0.69.2 (2024-01-13) ## Added ## Changed From 00f0273a90c776fd125e29474fc7b1c19cec5dfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 4 Feb 2024 12:41:45 +0100 Subject: [PATCH 621/942] chore: Release --- CHANGELOG.md | 187 ++++++++++++++++++++++------------------- Cargo.lock | 4 +- bindgen-cli/Cargo.toml | 4 +- bindgen/Cargo.toml | 2 +- 4 files changed, 105 insertions(+), 92 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e2af0ea870..2eae1291d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,190 +7,203 @@ - [Removed](#removed) - [Fixed](#fixed) - [Security](#security) -- [0.69.2 (2024-01-13)](#0692-2024-01-13) +- [0.69.3 (2024-02-04)](#0693-2024-02-04) - [Added](#added-1) - [Changed](#changed-1) - [Removed](#removed-1) - [Fixed](#fixed-1) - [Security](#security-1) -- [0.69.1 (2023-11-02)](#0691-2023-11-02) - - [Fixed](#fixed-2) -- [0.69.0 (2023-11-01)](#0690-2023-11-01) +- [0.69.2 (2024-01-13)](#0692-2024-01-13) - [Added](#added-2) - [Changed](#changed-2) - [Removed](#removed-2) - - [Fixed](#fixed-3) + - [Fixed](#fixed-2) - [Security](#security-2) -- [0.68.1](#0681) - - [Fixed](#fixed-4) -- [0.68.0](#0680) +- [0.69.1 (2023-11-02)](#0691-2023-11-02) + - [Fixed](#fixed-3) +- [0.69.0 (2023-11-01)](#0690-2023-11-01) - [Added](#added-3) - [Changed](#changed-3) - [Removed](#removed-3) + - [Fixed](#fixed-4) + - [Security](#security-3) +- [0.68.1](#0681) - [Fixed](#fixed-5) -- [0.67.0](#0670) -- [0.66.1](#0661) - - [Removed](#removed-4) -- [0.66.0](#0660) +- [0.68.0](#0680) - [Added](#added-4) - [Changed](#changed-4) - - [Removed](#removed-5) -- [0.65.1](#0651) + - [Removed](#removed-4) - [Fixed](#fixed-6) -- [0.65.0](#0650) +- [0.67.0](#0670) +- [0.66.1](#0661) + - [Removed](#removed-5) +- [0.66.0](#0660) - [Added](#added-5) - [Changed](#changed-5) - [Removed](#removed-6) -- [0.64.0](#0640) +- [0.65.1](#0651) + - [Fixed](#fixed-7) +- [0.65.0](#0650) - [Added](#added-6) - [Changed](#changed-6) -- [0.63.0](#0630) + - [Removed](#removed-7) +- [0.64.0](#0640) - [Added](#added-7) - [Changed](#changed-7) - - [Removed](#removed-7) -- [0.62.0](#0620) +- [0.63.0](#0630) - [Added](#added-8) - [Changed](#changed-8) - - [Fixed](#fixed-7) -- [0.61.0](#0610) + - [Removed](#removed-8) +- [0.62.0](#0620) - [Added](#added-9) - [Changed](#changed-9) - [Fixed](#fixed-8) -- [0.60.1](#0601) - - [Fixed](#fixed-9) -- [0.60.0](#0600) +- [0.61.0](#0610) - [Added](#added-10) - - [Fixed](#fixed-10) - [Changed](#changed-10) - - [Removed](#removed-8) + - [Fixed](#fixed-9) +- [0.60.1](#0601) + - [Fixed](#fixed-10) +- [0.60.0](#0600) + - [Added](#added-11) + - [Fixed](#fixed-11) + - [Changed](#changed-11) + - [Removed](#removed-9) - [0.59.2](#0592) - [0.59.1](#0591) - - [Fixed](#fixed-11) -- [0.59.0](#0590) - - [Added](#added-11) - [Fixed](#fixed-12) - - [Changed](#changed-11) -- [0.58.1](#0581) +- [0.59.0](#0590) - [Added](#added-12) -- [0.58.0](#0580) - - [Added](#added-13) - [Fixed](#fixed-13) - [Changed](#changed-12) - - [Deprecated](#deprecated) - - [Removed](#removed-9) - - [Fixed](#fixed-14) - - [Security](#security-3) -- [0.57.0](#0570) +- [0.58.1](#0581) + - [Added](#added-13) +- [0.58.0](#0580) - [Added](#added-14) + - [Fixed](#fixed-14) + - [Changed](#changed-13) + - [Deprecated](#deprecated) + - [Removed](#removed-10) - [Fixed](#fixed-15) -- [0.56.0](#0560) + - [Security](#security-4) +- [0.57.0](#0570) - [Added](#added-15) - - [Changed](#changed-13) - [Fixed](#fixed-16) -- [0.55.1](#0551) - - [Fixed](#fixed-17) -- [0.55.0](#0550) - - [Removed](#removed-10) +- [0.56.0](#0560) - [Added](#added-16) - [Changed](#changed-14) + - [Fixed](#fixed-17) +- [0.55.1](#0551) - [Fixed](#fixed-18) -- [0.54.1](#0541) +- [0.55.0](#0550) + - [Removed](#removed-11) - [Added](#added-17) - [Changed](#changed-15) - [Fixed](#fixed-19) -- [0.54.0](#0540) +- [0.54.1](#0541) - [Added](#added-18) - [Changed](#changed-16) - [Fixed](#fixed-20) -- [0.53.3](#0533) +- [0.54.0](#0540) - [Added](#added-19) + - [Changed](#changed-17) - [Fixed](#fixed-21) +- [0.53.3](#0533) + - [Added](#added-20) + - [Fixed](#fixed-22) - [0.53.2](#0532) - - [Changed](#changed-17) + - [Changed](#changed-18) - [0.53.1](#0531) - - [Added](#added-20) -- [0.53.0](#0530) - [Added](#added-21) - - [Changed](#changed-18) - - [Fixed](#fixed-22) -- [0.52.0](#0520) +- [0.53.0](#0530) - [Added](#added-22) - [Changed](#changed-19) - [Fixed](#fixed-23) -- [0.51.1](#0511) - - [Fixed](#fixed-24) +- [0.52.0](#0520) + - [Added](#added-23) - [Changed](#changed-20) -- [0.51.0](#0510) + - [Fixed](#fixed-24) +- [0.51.1](#0511) - [Fixed](#fixed-25) - [Changed](#changed-21) - - [Added](#added-23) -- [0.50.0](#0500) +- [0.51.0](#0510) + - [Fixed](#fixed-26) + - [Changed](#changed-22) - [Added](#added-24) -- [0.49.3](#0493) +- [0.50.0](#0500) - [Added](#added-25) +- [0.49.3](#0493) + - [Added](#added-26) - [0.49.2](#0492) - - [Changed](#changed-22) -- [0.49.1](#0491) - - [Fixed](#fixed-26) - [Changed](#changed-23) -- [0.49.0](#0490) - - [Added](#added-26) +- [0.49.1](#0491) - [Fixed](#fixed-27) - [Changed](#changed-24) -- [0.48.1](#0481) +- [0.49.0](#0490) + - [Added](#added-27) - [Fixed](#fixed-28) -- [0.48.0](#0480) - [Changed](#changed-25) +- [0.48.1](#0481) - [Fixed](#fixed-29) -- [0.47.4](#0474) - - [Added](#added-27) -- [0.47.3](#0473) +- [0.48.0](#0480) - [Changed](#changed-26) -- [0.47.2](#0472) - [Fixed](#fixed-30) -- [0.47.1](#0471) +- [0.47.4](#0474) + - [Added](#added-28) +- [0.47.3](#0473) - [Changed](#changed-27) +- [0.47.2](#0472) - [Fixed](#fixed-31) -- [0.47.0](#0470) +- [0.47.1](#0471) - [Changed](#changed-28) - [Fixed](#fixed-32) -- [0.33.1 .. 0.46.0](#0331--0460) - - [Added](#added-28) - - [Removed](#removed-11) +- [0.47.0](#0470) - [Changed](#changed-29) - [Fixed](#fixed-33) -- [0.33.1](#0331) +- [0.33.1 .. 0.46.0](#0331--0460) + - [Added](#added-29) + - [Removed](#removed-12) + - [Changed](#changed-30) - [Fixed](#fixed-34) +- [0.33.1](#0331) + - [Fixed](#fixed-35) - [0.33.0](#0330) - [0.32.2](#0322) - - [Fixed](#fixed-35) -- [0.32.1](#0321) - [Fixed](#fixed-36) -- [0.32.0](#0320) - - [Added](#added-29) - - [Changed](#changed-30) +- [0.32.1](#0321) - [Fixed](#fixed-37) -- [0.31.0](#0310) +- [0.32.0](#0320) - [Added](#added-30) - [Changed](#changed-31) - - [Deprecated](#deprecated-1) - - [Removed](#removed-12) - [Fixed](#fixed-38) -- [0.30.0](#0300) +- [0.31.0](#0310) - [Added](#added-31) - [Changed](#changed-32) - - [Deprecated](#deprecated-2) + - [Deprecated](#deprecated-1) + - [Removed](#removed-13) - [Fixed](#fixed-39) -- [0.29.0](#0290) +- [0.30.0](#0300) - [Added](#added-32) - [Changed](#changed-33) + - [Deprecated](#deprecated-2) - [Fixed](#fixed-40) +- [0.29.0](#0290) + - [Added](#added-33) + - [Changed](#changed-34) + - [Fixed](#fixed-41) -------------------------------------------------------------------------------- # Unreleased ## Added +## Changed +## Removed +## Fixed +## Security + +# 0.69.3 (2024-02-04) +## Added - Added blocklist_var (#2731) - Stabilized thiscall_abi (#2661) diff --git a/Cargo.lock b/Cargo.lock index 33a2e1b7d0..5fe0edb14e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -23,7 +23,7 @@ dependencies = [ [[package]] name = "bindgen" -version = "0.69.1" +version = "0.69.3" dependencies = [ "annotate-snippets", "bitflags 2.2.1", @@ -45,7 +45,7 @@ dependencies = [ [[package]] name = "bindgen-cli" -version = "0.69.1" +version = "0.69.3" dependencies = [ "bindgen", "clap", diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index 5e04cb0d80..3c1fb1fc99 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -11,7 +11,7 @@ readme = "../README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.69.1" +version = "0.69.3" edition = "2018" rust-version = "1.64.0" @@ -20,7 +20,7 @@ path = "main.rs" name = "bindgen" [dependencies] -bindgen = { path = "../bindgen", version = "=0.69.1", default-features = false, features = ["__cli", "experimental"] } +bindgen = { path = "../bindgen", version = "=0.69.3", default-features = false, features = ["__cli", "experimental"] } clap = { version = "4", features = ["derive"] } clap_complete = "4" env_logger = { version = "0.10.0", optional = true } diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index eafa2ce35d..0958c74950 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -14,7 +14,7 @@ readme = "../README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.69.1" +version = "0.69.3" edition = "2018" build = "build.rs" # If you change this, also update README.md and msrv in .github/workflows/bindgen.yml From 44ec8b36dcc9d14fb00dbdf77716f303935d20db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 4 Feb 2024 13:41:15 +0100 Subject: [PATCH 622/942] Update itertools and allow itertools 0.10 too. This can help avoid duplicate dependencies when using bindgen as a library. --- CHANGELOG.md | 1 + Cargo.lock | 4 ++-- bindgen/Cargo.toml | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2eae1291d4..720e04bdc6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -198,6 +198,7 @@ # Unreleased ## Added ## Changed +- Allow older itertools. (#2745) ## Removed ## Fixed ## Security diff --git a/Cargo.lock b/Cargo.lock index 5fe0edb14e..7cf861ebde 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -301,9 +301,9 @@ dependencies = [ [[package]] name = "itertools" -version = "0.12.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25db6b064527c5d482d0423354fcd07a89a2dfe07b67892e62411946db7f07b0" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" dependencies = [ "either", ] diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index 0958c74950..4578d88669 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -29,7 +29,7 @@ annotate-snippets = { version = "0.9.1", features = ["color"], optional = true } bitflags = "2.2.1" cexpr = "0.6" clang-sys = { version = "1", features = ["clang_6_0"] } -itertools = { version = "0.12.0", default-features = false } +itertools = { version = ">=0.10,<0.13", default-features = false } lazy_static = "1" lazycell = "1" log = { version = "0.4", optional = true } From 7c6858deab9cdd6812822e9e1060d44df674455b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 4 Feb 2024 13:50:31 +0100 Subject: [PATCH 623/942] chore: Release --- CHANGELOG.md | 189 ++++++++++++++++++++++------------------- Cargo.lock | 4 +- bindgen-cli/Cargo.toml | 4 +- bindgen/Cargo.toml | 2 +- 4 files changed, 106 insertions(+), 93 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 720e04bdc6..94b19f56ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,190 +7,196 @@ - [Removed](#removed) - [Fixed](#fixed) - [Security](#security) -- [0.69.3 (2024-02-04)](#0693-2024-02-04) +- [0.69.4 (2024-02-04)](#0694-2024-02-04) - [Added](#added-1) - [Changed](#changed-1) - [Removed](#removed-1) - [Fixed](#fixed-1) - [Security](#security-1) -- [0.69.2 (2024-01-13)](#0692-2024-01-13) +- [0.69.3 (2024-02-04)](#0693-2024-02-04) - [Added](#added-2) - [Changed](#changed-2) - [Removed](#removed-2) - [Fixed](#fixed-2) - [Security](#security-2) -- [0.69.1 (2023-11-02)](#0691-2023-11-02) - - [Fixed](#fixed-3) -- [0.69.0 (2023-11-01)](#0690-2023-11-01) +- [0.69.2 (2024-01-13)](#0692-2024-01-13) - [Added](#added-3) - [Changed](#changed-3) - [Removed](#removed-3) - - [Fixed](#fixed-4) + - [Fixed](#fixed-3) - [Security](#security-3) -- [0.68.1](#0681) - - [Fixed](#fixed-5) -- [0.68.0](#0680) +- [0.69.1 (2023-11-02)](#0691-2023-11-02) + - [Fixed](#fixed-4) +- [0.69.0 (2023-11-01)](#0690-2023-11-01) - [Added](#added-4) - [Changed](#changed-4) - [Removed](#removed-4) + - [Fixed](#fixed-5) + - [Security](#security-4) +- [0.68.1](#0681) - [Fixed](#fixed-6) -- [0.67.0](#0670) -- [0.66.1](#0661) - - [Removed](#removed-5) -- [0.66.0](#0660) +- [0.68.0](#0680) - [Added](#added-5) - [Changed](#changed-5) - - [Removed](#removed-6) -- [0.65.1](#0651) + - [Removed](#removed-5) - [Fixed](#fixed-7) -- [0.65.0](#0650) +- [0.67.0](#0670) +- [0.66.1](#0661) + - [Removed](#removed-6) +- [0.66.0](#0660) - [Added](#added-6) - [Changed](#changed-6) - [Removed](#removed-7) -- [0.64.0](#0640) +- [0.65.1](#0651) + - [Fixed](#fixed-8) +- [0.65.0](#0650) - [Added](#added-7) - [Changed](#changed-7) -- [0.63.0](#0630) + - [Removed](#removed-8) +- [0.64.0](#0640) - [Added](#added-8) - [Changed](#changed-8) - - [Removed](#removed-8) -- [0.62.0](#0620) +- [0.63.0](#0630) - [Added](#added-9) - [Changed](#changed-9) - - [Fixed](#fixed-8) -- [0.61.0](#0610) + - [Removed](#removed-9) +- [0.62.0](#0620) - [Added](#added-10) - [Changed](#changed-10) - [Fixed](#fixed-9) -- [0.60.1](#0601) - - [Fixed](#fixed-10) -- [0.60.0](#0600) +- [0.61.0](#0610) - [Added](#added-11) - - [Fixed](#fixed-11) - [Changed](#changed-11) - - [Removed](#removed-9) + - [Fixed](#fixed-10) +- [0.60.1](#0601) + - [Fixed](#fixed-11) +- [0.60.0](#0600) + - [Added](#added-12) + - [Fixed](#fixed-12) + - [Changed](#changed-12) + - [Removed](#removed-10) - [0.59.2](#0592) - [0.59.1](#0591) - - [Fixed](#fixed-12) -- [0.59.0](#0590) - - [Added](#added-12) - [Fixed](#fixed-13) - - [Changed](#changed-12) -- [0.58.1](#0581) +- [0.59.0](#0590) - [Added](#added-13) -- [0.58.0](#0580) - - [Added](#added-14) - [Fixed](#fixed-14) - [Changed](#changed-13) - - [Deprecated](#deprecated) - - [Removed](#removed-10) - - [Fixed](#fixed-15) - - [Security](#security-4) -- [0.57.0](#0570) +- [0.58.1](#0581) + - [Added](#added-14) +- [0.58.0](#0580) - [Added](#added-15) + - [Fixed](#fixed-15) + - [Changed](#changed-14) + - [Deprecated](#deprecated) + - [Removed](#removed-11) - [Fixed](#fixed-16) -- [0.56.0](#0560) + - [Security](#security-5) +- [0.57.0](#0570) - [Added](#added-16) - - [Changed](#changed-14) - [Fixed](#fixed-17) -- [0.55.1](#0551) - - [Fixed](#fixed-18) -- [0.55.0](#0550) - - [Removed](#removed-11) +- [0.56.0](#0560) - [Added](#added-17) - [Changed](#changed-15) + - [Fixed](#fixed-18) +- [0.55.1](#0551) - [Fixed](#fixed-19) -- [0.54.1](#0541) +- [0.55.0](#0550) + - [Removed](#removed-12) - [Added](#added-18) - [Changed](#changed-16) - [Fixed](#fixed-20) -- [0.54.0](#0540) +- [0.54.1](#0541) - [Added](#added-19) - [Changed](#changed-17) - [Fixed](#fixed-21) -- [0.53.3](#0533) +- [0.54.0](#0540) - [Added](#added-20) + - [Changed](#changed-18) - [Fixed](#fixed-22) +- [0.53.3](#0533) + - [Added](#added-21) + - [Fixed](#fixed-23) - [0.53.2](#0532) - - [Changed](#changed-18) + - [Changed](#changed-19) - [0.53.1](#0531) - - [Added](#added-21) -- [0.53.0](#0530) - [Added](#added-22) - - [Changed](#changed-19) - - [Fixed](#fixed-23) -- [0.52.0](#0520) +- [0.53.0](#0530) - [Added](#added-23) - [Changed](#changed-20) - [Fixed](#fixed-24) -- [0.51.1](#0511) - - [Fixed](#fixed-25) +- [0.52.0](#0520) + - [Added](#added-24) - [Changed](#changed-21) -- [0.51.0](#0510) + - [Fixed](#fixed-25) +- [0.51.1](#0511) - [Fixed](#fixed-26) - [Changed](#changed-22) - - [Added](#added-24) -- [0.50.0](#0500) +- [0.51.0](#0510) + - [Fixed](#fixed-27) + - [Changed](#changed-23) - [Added](#added-25) -- [0.49.3](#0493) +- [0.50.0](#0500) - [Added](#added-26) +- [0.49.3](#0493) + - [Added](#added-27) - [0.49.2](#0492) - - [Changed](#changed-23) -- [0.49.1](#0491) - - [Fixed](#fixed-27) - [Changed](#changed-24) -- [0.49.0](#0490) - - [Added](#added-27) +- [0.49.1](#0491) - [Fixed](#fixed-28) - [Changed](#changed-25) -- [0.48.1](#0481) +- [0.49.0](#0490) + - [Added](#added-28) - [Fixed](#fixed-29) -- [0.48.0](#0480) - [Changed](#changed-26) +- [0.48.1](#0481) - [Fixed](#fixed-30) -- [0.47.4](#0474) - - [Added](#added-28) -- [0.47.3](#0473) +- [0.48.0](#0480) - [Changed](#changed-27) -- [0.47.2](#0472) - [Fixed](#fixed-31) -- [0.47.1](#0471) +- [0.47.4](#0474) + - [Added](#added-29) +- [0.47.3](#0473) - [Changed](#changed-28) +- [0.47.2](#0472) - [Fixed](#fixed-32) -- [0.47.0](#0470) +- [0.47.1](#0471) - [Changed](#changed-29) - [Fixed](#fixed-33) -- [0.33.1 .. 0.46.0](#0331--0460) - - [Added](#added-29) - - [Removed](#removed-12) +- [0.47.0](#0470) - [Changed](#changed-30) - [Fixed](#fixed-34) -- [0.33.1](#0331) +- [0.33.1 .. 0.46.0](#0331--0460) + - [Added](#added-30) + - [Removed](#removed-13) + - [Changed](#changed-31) - [Fixed](#fixed-35) +- [0.33.1](#0331) + - [Fixed](#fixed-36) - [0.33.0](#0330) - [0.32.2](#0322) - - [Fixed](#fixed-36) -- [0.32.1](#0321) - [Fixed](#fixed-37) -- [0.32.0](#0320) - - [Added](#added-30) - - [Changed](#changed-31) +- [0.32.1](#0321) - [Fixed](#fixed-38) -- [0.31.0](#0310) +- [0.32.0](#0320) - [Added](#added-31) - [Changed](#changed-32) - - [Deprecated](#deprecated-1) - - [Removed](#removed-13) - [Fixed](#fixed-39) -- [0.30.0](#0300) +- [0.31.0](#0310) - [Added](#added-32) - [Changed](#changed-33) - - [Deprecated](#deprecated-2) + - [Deprecated](#deprecated-1) + - [Removed](#removed-14) - [Fixed](#fixed-40) -- [0.29.0](#0290) +- [0.30.0](#0300) - [Added](#added-33) - [Changed](#changed-34) + - [Deprecated](#deprecated-2) - [Fixed](#fixed-41) +- [0.29.0](#0290) + - [Added](#added-34) + - [Changed](#changed-35) + - [Fixed](#fixed-42) @@ -198,6 +204,13 @@ # Unreleased ## Added ## Changed +## Removed +## Fixed +## Security + +# 0.69.4 (2024-02-04) +## Added +## Changed - Allow older itertools. (#2745) ## Removed ## Fixed diff --git a/Cargo.lock b/Cargo.lock index 7cf861ebde..4fa9dbcf51 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -23,7 +23,7 @@ dependencies = [ [[package]] name = "bindgen" -version = "0.69.3" +version = "0.69.4" dependencies = [ "annotate-snippets", "bitflags 2.2.1", @@ -45,7 +45,7 @@ dependencies = [ [[package]] name = "bindgen-cli" -version = "0.69.3" +version = "0.69.4" dependencies = [ "bindgen", "clap", diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index 3c1fb1fc99..e642790014 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -11,7 +11,7 @@ readme = "../README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.69.3" +version = "0.69.4" edition = "2018" rust-version = "1.64.0" @@ -20,7 +20,7 @@ path = "main.rs" name = "bindgen" [dependencies] -bindgen = { path = "../bindgen", version = "=0.69.3", default-features = false, features = ["__cli", "experimental"] } +bindgen = { path = "../bindgen", version = "=0.69.4", default-features = false, features = ["__cli", "experimental"] } clap = { version = "4", features = ["derive"] } clap_complete = "4" env_logger = { version = "0.10.0", optional = true } diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index 4578d88669..a231efcc2c 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -14,7 +14,7 @@ readme = "../README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.69.3" +version = "0.69.4" edition = "2018" build = "build.rs" # If you change this, also update README.md and msrv in .github/workflows/bindgen.yml From 9e004e983898aa2147f38e19185cbe97f02c61a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 4 Feb 2024 21:50:30 +0100 Subject: [PATCH 624/942] ci: Try to enable merge queue. --- .github/workflows/bindgen.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index ebf70dce09..21f96aed27 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -7,6 +7,9 @@ on: pull_request: branches: - main + merge_group: + branches: + - main jobs: rustfmt-clippy: @@ -254,3 +257,18 @@ jobs: curl -L https://github.com/rust-lang/mdBook/releases/download/v0.4.5/mdbook-v0.4.5-x86_64-unknown-linux-gnu.tar.gz | tar xz ./mdbook build book ./mdbook test book + + # One job that "summarizes" the success state of this pipeline. This can then + # be added to branch protection, rather than having to add each job + # separately. + success: + runs-on: ubuntu-latest + needs: [rustfmt-clippy, msrv, minimal, docs, quickchecking, test-expectations, test, check-cfg, test-book] + # GitHub branch protection is exceedingly silly and treats "jobs skipped + # because a dependency failed" as success. So we have to do some + # contortions to ensure the job fails if any of its dependencies fails. + if: always() # make sure this is never "skipped" + steps: + # Manually check the status of all dependencies. `if: failure()` does not work. + - name: check if any dependency failed + run: jq --exit-status 'all(.result == "success")' <<< '${{ toJson(needs) }}' From 4dd4523dad0cf27acf84832e7147f69b9ff39ece Mon Sep 17 00:00:00 2001 From: Christian Heussy Date: Fri, 2 Feb 2024 04:31:18 +0000 Subject: [PATCH 625/942] feat: add `headers` option Problem: It's cumbersome to define multiple input headers using the existing `header` API. It's difficult for the user to configure the `Builder` with a list of input headers. Solution: Add `headers` method that permits adding multiple headers via an iterable of Strings. Testing: Added `test_headers_call_in_builder`. Ran `cargo test` in `bindgen-tests/tests/expectations`. Issue: https://github.com/rust-lang/rust-bindgen/issues/2738 --- bindgen-tests/tests/tests.rs | 36 ++++++++++++++++++++++++++++++++++++ bindgen/options/mod.rs | 29 +++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/bindgen-tests/tests/tests.rs b/bindgen-tests/tests/tests.rs index 9df45c3b07..0e15155d92 100644 --- a/bindgen-tests/tests/tests.rs +++ b/bindgen-tests/tests/tests.rs @@ -472,6 +472,42 @@ fn test_multiple_header_calls_in_builder() { } } +#[test] +fn test_headers_call_in_builder() { + let actual = builder() + .headers([ + concat!(env!("CARGO_MANIFEST_DIR"), "/tests/headers/func_ptr.h"), + concat!(env!("CARGO_MANIFEST_DIR"), "/tests/headers/char.h"), + ]) + .clang_arg("--target=x86_64-unknown-linux") + .generate() + .unwrap() + .to_string(); + + let actual = format_code(actual).unwrap(); + + let expected_filename = concat!( + env!("CARGO_MANIFEST_DIR"), + "/tests/expectations/tests/test_multiple_header_calls_in_builder.rs" + ); + let expected = include_str!(concat!( + env!("CARGO_MANIFEST_DIR"), + "/tests/expectations/tests/test_multiple_header_calls_in_builder.rs" + )); + let expected = format_code(expected).unwrap(); + + if actual != expected { + println!("Generated bindings differ from expected!"); + error_diff_mismatch( + &actual, + &expected, + None, + Path::new(expected_filename), + ) + .unwrap(); + } +} + #[test] fn test_multiple_header_contents() { let actual = builder() diff --git a/bindgen/options/mod.rs b/bindgen/options/mod.rs index 1fc2241615..d6e7ad5131 100644 --- a/bindgen/options/mod.rs +++ b/bindgen/options/mod.rs @@ -1179,6 +1179,35 @@ options! { self.options.input_headers.push(header.into().into_boxed_str()); self } + + /// Add input C/C++ header(s) to generate bindings for. + /// + /// This can be used to generate bindings for a single header: + /// + /// ```ignore + /// let bindings = bindgen::Builder::default() + /// .headers(["input.h"]) + /// .generate() + /// .unwrap(); + /// ``` + /// + /// Or for multiple headers: + /// + /// ```ignore + /// let bindings = bindgen::Builder::default() + /// .headers(["first.h", "second.h", "third.h"]) + /// .generate() + /// .unwrap(); + /// ``` + pub fn headers(mut self, headers: I) -> Builder + where + I::Item: Into, + { + self.options + .input_headers + .extend(headers.into_iter().map(Into::into).map(Into::into)); + self + } }, // This field is handled specially inside the macro. as_args: ignore, From aa63496ff0be337dfdb25963d6b006b7d2aa0a5a Mon Sep 17 00:00:00 2001 From: Nick Spinale Date: Wed, 7 Feb 2024 10:21:05 +0000 Subject: [PATCH 626/942] Add target mappings for riscv64imac and riscv32imafc Similar change to #2551. Just filling in more mappings. --- CHANGELOG.md | 1 + bindgen/lib.rs | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94b19f56ef..95b7ac2966 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -204,6 +204,7 @@ # Unreleased ## Added ## Changed +- Add target mappings for riscv64imac and riscv32imafc. ## Removed ## Fixed ## Security diff --git a/bindgen/lib.rs b/bindgen/lib.rs index c4ab11486c..f672f3ff93 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -695,6 +695,11 @@ fn rust_to_clang_target(rust_target: &str) -> Box { let mut clang_target = "riscv64-".to_owned(); clang_target.push_str(rust_target.strip_prefix("riscv64gc-").unwrap()); return clang_target.into(); + } else if rust_target.starts_with("riscv64imac-") { + let mut clang_target = "riscv64-".to_owned(); + clang_target + .push_str(rust_target.strip_prefix("riscv64imac-").unwrap()); + return clang_target.into(); } else if rust_target.ends_with("-espidf") { let mut clang_target = rust_target.strip_suffix("-espidf").unwrap().to_owned(); @@ -713,6 +718,11 @@ fn rust_to_clang_target(rust_target: &str) -> Box { clang_target .push_str(rust_target.strip_prefix("riscv32imac-").unwrap()); return clang_target.into(); + } else if rust_target.starts_with("riscv32imafc-") { + let mut clang_target = "riscv32-".to_owned(); + clang_target + .push_str(rust_target.strip_prefix("riscv32imafc-").unwrap()); + return clang_target.into(); } rust_target.into() } @@ -1357,6 +1367,10 @@ fn test_rust_to_clang_target_riscv() { rust_to_clang_target("riscv64gc-unknown-linux-gnu").as_ref(), "riscv64-unknown-linux-gnu" ); + assert_eq!( + rust_to_clang_target("riscv64imac-unknown-none-elf").as_ref(), + "riscv64-unknown-none-elf" + ); assert_eq!( rust_to_clang_target("riscv32imc-unknown-none-elf").as_ref(), "riscv32-unknown-none-elf" @@ -1365,6 +1379,10 @@ fn test_rust_to_clang_target_riscv() { rust_to_clang_target("riscv32imac-unknown-none-elf").as_ref(), "riscv32-unknown-none-elf" ); + assert_eq!( + rust_to_clang_target("riscv32imafc-unknown-none-elf").as_ref(), + "riscv32-unknown-none-elf" + ); } #[test] From a152f280ce72c40e034987afab0f49caa54926bc Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Mon, 5 Feb 2024 14:35:17 -0600 Subject: [PATCH 627/942] Fix several typos --- bindgen-integration/build.rs | 2 +- bindgen/clang.rs | 2 +- bindgen/codegen/serialize.rs | 2 +- bindgen/ir/annotations.rs | 2 +- bindgen/ir/comp.rs | 2 +- bindgen/ir/context.rs | 2 +- bindgen/ir/item_kind.rs | 14 +++++++------- bindgen/ir/objc.rs | 4 ++-- bindgen/ir/ty.rs | 6 +++--- bindgen/lib.rs | 2 +- bindgen/options/mod.rs | 6 +++--- book/src/cpp.md | 2 +- book/src/non-system-libraries.md | 2 +- book/src/objc.md | 2 +- 14 files changed, 25 insertions(+), 25 deletions(-) diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs index ce4a3200af..7021f865d7 100644 --- a/bindgen-integration/build.rs +++ b/bindgen-integration/build.rs @@ -279,7 +279,7 @@ fn setup_wrap_static_fns_test() { bindings .write_to_file(out_rust_file) - .expect("Cound not write bindings to the Rust file"); + .expect("Could not write bindings to the Rust file"); } fn main() { diff --git a/bindgen/clang.rs b/bindgen/clang.rs index 4a4ed89d69..a9a0ec814f 100644 --- a/bindgen/clang.rs +++ b/bindgen/clang.rs @@ -874,7 +874,7 @@ impl Cursor { unsafe { clang_getCXXAccessSpecifier(self.x) } } - /// Is the cursor's referrent publically accessible in C++? + /// Is the cursor's referent publically accessible in C++? /// /// Returns true if self.access_specifier() is `CX_CXXPublic` or /// `CX_CXXInvalidAccessSpecifier`. diff --git a/bindgen/codegen/serialize.rs b/bindgen/codegen/serialize.rs index 9765a8bdf2..7f00f809f4 100644 --- a/bindgen/codegen/serialize.rs +++ b/bindgen/codegen/serialize.rs @@ -81,7 +81,7 @@ impl<'a> CSerialize<'a> for Function { let name = self.name(); - // Function argoments stored as `(name, type_id)` tuples. + // Function arguments stored as `(name, type_id)` tuples. let args = { let mut count = 0; diff --git a/bindgen/ir/annotations.rs b/bindgen/ir/annotations.rs index d085f5c574..9165f3d39a 100644 --- a/bindgen/ir/annotations.rs +++ b/bindgen/ir/annotations.rs @@ -8,7 +8,7 @@ use std::str::FromStr; use crate::clang; -/// What kind of visibility modifer should be used for a struct or field? +/// What kind of visibility modifier should be used for a struct or field? #[derive(Copy, PartialEq, Eq, PartialOrd, Ord, Clone, Debug)] pub enum FieldVisibilityKind { /// Fields are marked as private, i.e., struct Foo {bar: bool} diff --git a/bindgen/ir/comp.rs b/bindgen/ir/comp.rs index fed6ba8ac8..bd4d016261 100644 --- a/bindgen/ir/comp.rs +++ b/bindgen/ir/comp.rs @@ -147,7 +147,7 @@ pub(crate) trait FieldMethods { /// If this is a bitfield, how many bits does it need? fn bitfield_width(&self) -> Option; - /// Is this feild declared public? + /// Is this field declared public? fn is_public(&self) -> bool; /// Get the annotations for this field. diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index 517d3365b6..f13f34abcd 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -36,7 +36,7 @@ use std::mem; #[derive(Debug, Copy, Clone, Eq, PartialOrd, Ord, Hash)] pub(crate) struct ItemId(usize); -/// Declare a newtype around `ItemId` with convesion methods. +/// Declare a newtype around `ItemId` with conversion methods. macro_rules! item_id_newtype { ( $( #[$attr:meta] )* diff --git a/bindgen/ir/item_kind.rs b/bindgen/ir/item_kind.rs index e8618498ad..9221b50579 100644 --- a/bindgen/ir/item_kind.rs +++ b/bindgen/ir/item_kind.rs @@ -26,7 +26,7 @@ pub(crate) enum ItemKind { } impl ItemKind { - /// Get a reference to this `ItemKind`'s underying `Module`, or `None` if it + /// Get a reference to this `ItemKind`'s underlying `Module`, or `None` if it /// is some other kind. pub(crate) fn as_module(&self) -> Option<&Module> { match *self { @@ -50,7 +50,7 @@ impl ItemKind { self.as_module().is_some() } - /// Get a reference to this `ItemKind`'s underying `Function`, or `None` if + /// Get a reference to this `ItemKind`'s underlying `Function`, or `None` if /// it is some other kind. pub(crate) fn as_function(&self) -> Option<&Function> { match *self { @@ -64,13 +64,13 @@ impl ItemKind { self.as_function().is_some() } - /// Get a reference to this `ItemKind`'s underying `Function`, or panic if + /// Get a reference to this `ItemKind`'s underlying `Function`, or panic if /// it is some other kind. pub(crate) fn expect_function(&self) -> &Function { self.as_function().expect("Not a function") } - /// Get a reference to this `ItemKind`'s underying `Type`, or `None` if + /// Get a reference to this `ItemKind`'s underlying `Type`, or `None` if /// it is some other kind. pub(crate) fn as_type(&self) -> Option<&Type> { match *self { @@ -79,7 +79,7 @@ impl ItemKind { } } - /// Get a mutable reference to this `ItemKind`'s underying `Type`, or `None` + /// Get a mutable reference to this `ItemKind`'s underlying `Type`, or `None` /// if it is some other kind. pub(crate) fn as_type_mut(&mut self) -> Option<&mut Type> { match *self { @@ -93,13 +93,13 @@ impl ItemKind { self.as_type().is_some() } - /// Get a reference to this `ItemKind`'s underying `Type`, or panic if it is + /// Get a reference to this `ItemKind`'s underlying `Type`, or panic if it is /// some other kind. pub(crate) fn expect_type(&self) -> &Type { self.as_type().expect("Not a type") } - /// Get a reference to this `ItemKind`'s underying `Var`, or `None` if it is + /// Get a reference to this `ItemKind`'s underlying `Var`, or `None` if it is /// some other kind. pub(crate) fn as_var(&self) -> Option<&Var> { match *self { diff --git a/bindgen/ir/objc.rs b/bindgen/ir/objc.rs index 93d8b3bfdf..d7f7cc65a6 100644 --- a/bindgen/ir/objc.rs +++ b/bindgen/ir/objc.rs @@ -39,7 +39,7 @@ pub(crate) struct ObjCInterface { /// The direct parent for this interface. pub(crate) parent_class: Option, - /// List of the methods defined in this interfae + /// List of the methods defined in this interface methods: Vec, class_methods: Vec, @@ -137,7 +137,7 @@ impl ObjCInterface { CXCursor_ObjCClassRef => { if cursor.kind() == CXCursor_ObjCCategoryDecl { // We are actually a category extension, and we found the reference - // to the original interface, so name this interface approriately + // to the original interface, so name this interface appropriately interface.name = c.spelling(); interface.category = Some(cursor.spelling()); } diff --git a/bindgen/ir/ty.rs b/bindgen/ir/ty.rs index b7a429323e..2a24dd0291 100644 --- a/bindgen/ir/ty.rs +++ b/bindgen/ir/ty.rs @@ -252,7 +252,7 @@ impl Type { Cow::Owned(name) } - /// Get this type's santizied name. + /// Get this type's sanitized name. pub(crate) fn sanitized_name<'a>( &'a self, ctx: &BindgenContext, @@ -498,7 +498,7 @@ fn is_invalid_type_param_invalid_start() { } #[test] -fn is_invalid_type_param_invalid_remaing() { +fn is_invalid_type_param_invalid_remaining() { let ty = Type::new(Some("foo-".into()), None, TypeKind::TypeParam, false); assert!(ty.is_invalid_type_param()) } @@ -1092,7 +1092,7 @@ impl Type { Item::from_ty_or_ref(inner, location, None, ctx); if inner_id == potential_id { warn!( - "Generating oqaque type instead of self-referential \ + "Generating opaque type instead of self-referential \ typedef"); // This can happen if we bail out of recursive situations // within the clang parsing. diff --git a/bindgen/lib.rs b/bindgen/lib.rs index f672f3ff93..c2df8a8a1f 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -144,7 +144,7 @@ impl CodegenConfig { self.contains(CodegenConfig::VARS) } - /// Returns true if methds should be generated. + /// Returns true if methods should be generated. pub fn methods(self) -> bool { self.contains(CodegenConfig::METHODS) } diff --git a/bindgen/options/mod.rs b/bindgen/options/mod.rs index d6e7ad5131..6b5b4d8cbc 100644 --- a/bindgen/options/mod.rs +++ b/bindgen/options/mod.rs @@ -508,7 +508,7 @@ options! { constified_enums: RegexSet { methods: { regex_option! { - /// Mark the given `enum` as a set o integer constants. + /// Mark the given `enum` as a set of integer constants. /// /// This is similar to the [`Builder::constified_enum_module`] style, but the /// constants are generated in the current module instead of in a new module. @@ -1843,7 +1843,7 @@ options! { }, as_args: "--dynamic-loading", }, - /// Whether to equire successful linkage for all routines in a shared library. + /// Whether to require successful linkage for all routines in a shared library. dynamic_link_require_all: bool { methods: { /// Set whether to require successful linkage for all routines in a shared library. @@ -1908,7 +1908,7 @@ options! { }, as_args: "--c-naming", }, - /// Wether to always emit explicit padding fields. + /// Whether to always emit explicit padding fields. force_explicit_padding: bool { methods: { /// Set whether to always emit explicit padding fields. diff --git a/book/src/cpp.md b/book/src/cpp.md index f5091b355e..9b451b9d35 100644 --- a/book/src/cpp.md +++ b/book/src/cpp.md @@ -74,7 +74,7 @@ cannot translate into Rust: * Many C++ specific aspects of calling conventions. For example in the Itanium abi types that are "[non trivial for the purposes of calls](https://itanium-cxx-abi.github.io/cxx-abi/abi.html#non-trivial)" - should be passed by pointer, even if they are otherwise eligable to be passed in a register. + should be passed by pointer, even if they are otherwise eligible to be passed in a register. Similarly in both the Itanium and MSVC ABIs such types are returned by "hidden parameter", much like large structs in C that would not fit into a register. This also applies to types with any base classes in the MSVC ABI (see [x64 calling convention](https://learn.microsoft.com/en-us/cpp/build/x64-calling-convention?view=msvc-170#return-values)). diff --git a/book/src/non-system-libraries.md b/book/src/non-system-libraries.md index 1bb19e4d0b..d5d288d101 100644 --- a/book/src/non-system-libraries.md +++ b/book/src/non-system-libraries.md @@ -14,7 +14,7 @@ int hello(); Given that the library has not been compiled yet, we need to modify the `build.rs` build script to compile the `hello.c` source file into a static -libary: +library: ```rust,ignore extern crate bindgen; diff --git a/book/src/objc.md b/book/src/objc.md index ce6d756761..ed6f2cb881 100644 --- a/book/src/objc.md +++ b/book/src/objc.md @@ -18,7 +18,7 @@ objc::runtime::Object` (the pointer to the objective-c instance). The trait `IFoo` is needed to allow for the generated inheritance. Functions that use or return objective-c pointers of instance `Foo` will return -`Foo`. The reason this works is beacuse `Foo` represented as `transparent`. +`Foo`. The reason this works is because `Foo` represented as `transparent`. This will be helpful for a lot of objective-c frameworks however there are some cases where functions return `instancetype` which is a type alias for `id` so an occasional `foo.0` may be required. An example of this would in the UIKit From 8b1f971b2e1ccf09eee0bd8cc9bf8a37c15a4825 Mon Sep 17 00:00:00 2001 From: Shintaro Kawamura Date: Fri, 12 Jan 2024 13:05:17 +0900 Subject: [PATCH 628/942] Update minimum regex version to fix compile error regex 1.5.3 solves the compile error with unicode-perl feature. https://github.com/rust-lang/regex/blob/master/CHANGELOG.md#153-2021-05-01 Specifing wrong version as the minimum version can cause compile errors on products which depend on bindgen. Minimum versions can be checked with this cargo command. ``` cargo +nightly update -Z minimal-versions ``` --- bindgen/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index a231efcc2c..95293daf61 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -36,7 +36,7 @@ log = { version = "0.4", optional = true } prettyplease = { version = "0.2.7", optional = true, features = ["verbatim"] } proc-macro2 = { version = "1", default-features = false } quote = { version = "1", default-features = false } -regex = { version = "1.5.1", default-features = false, features = ["std", "unicode-perl"] } +regex = { version = "1.5.3", default-features = false, features = ["std", "unicode-perl"] } rustc-hash = "1.0.1" shlex = "1" syn = { version = "2.0", features = ["full", "extra-traits", "visit-mut"] } From 78a6799f12a7a7b3f81a929f987ab5963118a9e3 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 10 Feb 2024 01:33:13 +0100 Subject: [PATCH 629/942] Remove unused `HasFloat` trait. --- bindgen/ir/item.rs | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/bindgen/ir/item.rs b/bindgen/ir/item.rs index 2941eb81e2..4eb9ef8bf4 100644 --- a/bindgen/ir/item.rs +++ b/bindgen/ir/item.rs @@ -85,12 +85,6 @@ pub(crate) trait HasTypeParamInArray { fn has_type_param_in_array(&self, ctx: &BindgenContext) -> bool; } -/// A trait for determining if some IR thing has float or not. -pub(crate) trait HasFloat { - /// Returns `true` if the thing has float, and `false` otherwise. - fn has_float(&self, ctx: &BindgenContext) -> bool; -} - /// A trait for iterating over an item and its parents and up its ancestor chain /// up to (but not including) the implicit root module. pub(crate) trait ItemAncestors { @@ -1203,29 +1197,6 @@ impl HasTypeParamInArray for Item { } } -impl HasFloat for T -where - T: Copy + Into, -{ - fn has_float(&self, ctx: &BindgenContext) -> bool { - debug_assert!( - ctx.in_codegen_phase(), - "You're not supposed to call this yet" - ); - ctx.lookup_has_float(*self) - } -} - -impl HasFloat for Item { - fn has_float(&self, ctx: &BindgenContext) -> bool { - debug_assert!( - ctx.in_codegen_phase(), - "You're not supposed to call this yet" - ); - ctx.lookup_has_float(self.id()) - } -} - /// A set of items. pub(crate) type ItemSet = BTreeSet; From 454ec8420490ac4fd7fec3f5099b3e225ce0c957 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 10 Feb 2024 01:33:26 +0100 Subject: [PATCH 630/942] Don't use deprecated `shlex::quote`. --- bindgen-tests/tests/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindgen-tests/tests/tests.rs b/bindgen-tests/tests/tests.rs index 0e15155d92..c096b2e81e 100644 --- a/bindgen-tests/tests/tests.rs +++ b/bindgen-tests/tests/tests.rs @@ -654,7 +654,7 @@ fn build_flags_output_helper(builder: &bindgen::Builder) { let flags_quoted: Vec = command_line_flags .iter() - .map(|x| format!("{}", shlex::quote(x))) + .map(|x| format!("{}", shlex::try_quote(x).unwrap())) .collect(); let flags_str = flags_quoted.join(" "); println!("{}", flags_str); From 285eb56cf5a02ee778880b8e1b7bb2e8118a5a88 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Sun, 18 Feb 2024 22:39:08 -0500 Subject: [PATCH 631/942] Fix 'unused_imports' warnings that started appearing in CI recently --- bindgen/codegen/helpers.rs | 2 +- bindgen/codegen/mod.rs | 2 +- bindgen/codegen/struct_layout.rs | 2 +- bindgen/ir/context.rs | 1 - bindgen/ir/function.rs | 2 +- 5 files changed, 4 insertions(+), 5 deletions(-) diff --git a/bindgen/codegen/helpers.rs b/bindgen/codegen/helpers.rs index 48bfe56dde..fa1dde8786 100644 --- a/bindgen/codegen/helpers.rs +++ b/bindgen/codegen/helpers.rs @@ -126,7 +126,7 @@ pub(crate) mod ast_ty { use crate::ir::function::FunctionSig; use crate::ir::layout::Layout; use crate::ir::ty::{FloatKind, IntKind}; - use proc_macro2::{self, TokenStream}; + use proc_macro2::TokenStream; use std::str::FromStr; pub(crate) fn c_void(ctx: &BindgenContext) -> syn::Type { diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index dd1486df74..339c2fe59b 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -52,7 +52,7 @@ use crate::ir::template::{ use crate::ir::ty::{Type, TypeKind}; use crate::ir::var::Var; -use proc_macro2::{self, Ident, Span}; +use proc_macro2::{Ident, Span}; use quote::TokenStreamExt; use crate::{Entry, HashMap, HashSet}; diff --git a/bindgen/codegen/struct_layout.rs b/bindgen/codegen/struct_layout.rs index f4596a1992..7349669871 100644 --- a/bindgen/codegen/struct_layout.rs +++ b/bindgen/codegen/struct_layout.rs @@ -7,7 +7,7 @@ use crate::ir::context::BindgenContext; use crate::ir::layout::Layout; use crate::ir::ty::{Type, TypeKind}; use crate::FieldVisibilityKind; -use proc_macro2::{self, Ident, Span}; +use proc_macro2::{Ident, Span}; use std::cmp; const MAX_GUARANTEED_ALIGN: usize = 8; diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index f13f34abcd..26247cdcc5 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -29,7 +29,6 @@ use quote::ToTokens; use std::borrow::Cow; use std::cell::{Cell, RefCell}; use std::collections::{BTreeSet, HashMap as StdHashMap}; -use std::iter::IntoIterator; use std::mem; /// An identifier for some kind of IR item. diff --git a/bindgen/ir/function.rs b/bindgen/ir/function.rs index 448bcd22ea..1557843d03 100644 --- a/bindgen/ir/function.rs +++ b/bindgen/ir/function.rs @@ -9,7 +9,7 @@ use super::ty::TypeKind; use crate::callbacks::{ItemInfo, ItemKind}; use crate::clang::{self, ABIKind, Attribute}; use crate::parse::{ClangSubItemParser, ParseError, ParseResult}; -use clang_sys::{self, CXCallingConv}; +use clang_sys::CXCallingConv; use quote::TokenStreamExt; use std::io; From 41faf8ee4c27116291e8ecceae24b029dae259bf Mon Sep 17 00:00:00 2001 From: Robert Sammelson Date: Wed, 15 Nov 2023 12:17:02 -0500 Subject: [PATCH 632/942] Fix const array issue --- bindgen/codegen/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 339c2fe59b..b126a847b4 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -5285,7 +5285,8 @@ pub(crate) mod utils { } else { t.to_rust_ty_or_opaque(ctx, &()) }; - stream.to_ptr(ctx.resolve_type(t).is_const()) + stream + .to_ptr(ctx.resolve_type(t).is_const() || arg_ty.is_const()) } TypeKind::Pointer(inner) => { let inner = ctx.resolve_item(inner); From b5a6813c9a6feaeda38d7c672a1ed155f9e27266 Mon Sep 17 00:00:00 2001 From: Robert Sammelson Date: Sun, 18 Feb 2024 22:20:49 -0500 Subject: [PATCH 633/942] Add test for constant array typedef --- .../expectations/tests/const_array_typedef.rs | 42 +++++++++++++++++++ .../tests/headers/const_array_typedef.h | 13 ++++++ 2 files changed, 55 insertions(+) create mode 100644 bindgen-tests/tests/expectations/tests/const_array_typedef.rs create mode 100644 bindgen-tests/tests/headers/const_array_typedef.h diff --git a/bindgen-tests/tests/expectations/tests/const_array_typedef.rs b/bindgen-tests/tests/expectations/tests/const_array_typedef.rs new file mode 100644 index 0000000000..9222e52596 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/const_array_typedef.rs @@ -0,0 +1,42 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct strct { + pub field: ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout_strct() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(strct)), + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(strct)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).field) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(strct), "::", stringify!(field)), + ); +} +pub type typ = [strct; 1usize]; +extern "C" { + pub static mut w: typ; +} +extern "C" { + pub static mut x: *mut strct; +} +extern "C" { + pub static y: typ; +} +extern "C" { + pub static mut z: *const strct; +} +extern "C" { + pub fn function(a: *const strct, b: *const strct); +} diff --git a/bindgen-tests/tests/headers/const_array_typedef.h b/bindgen-tests/tests/headers/const_array_typedef.h new file mode 100644 index 0000000000..e5379c97ba --- /dev/null +++ b/bindgen-tests/tests/headers/const_array_typedef.h @@ -0,0 +1,13 @@ +typedef struct { + int field; +} strct; + +typedef strct typ[1]; + +extern typ w; +extern strct *x; + +extern const typ y; +extern const strct *z; + +void function(const typ a, const strct *b); From 9aa584dce6798ae455aa26c900acfceffa214223 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Mon, 18 Mar 2024 14:53:30 +0200 Subject: [PATCH 634/942] registry publish happens in a separate step --- CONTRIBUTING.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 491e233147..8a240d27e4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -566,7 +566,6 @@ This does the following: - Turn the `Unreleased` section of the changelog into the section for the version being published. - Update the table of contents of the changelog using `doctoc`. - Tag (`git tag`) the HEAD commit -- Publish (`cargo publish`) bindgen and bindgen-cli - Push (`git push`) to GitHub The `patch` and `minor` refer to semver concepts: From c0e09cf07d20b1eec1b268e06087ac1ef4eed6ed Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Mon, 18 Mar 2024 14:55:46 +0200 Subject: [PATCH 635/942] fix name --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8a240d27e4..8d0b4576b9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -571,7 +571,7 @@ This does the following: The `patch` and `minor` refer to semver concepts: - `patch` would bump __v0.68.1__ to __v0.68.2__ -- `feature` would bump __v0.68.2__ to __v0.69.0__ +- `minor` would bump __v0.68.2__ to __v0.69.0__ ### Create a new release on Github From 3dd9d08db258277b6f8b7c8042be649428a24bf2 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Mon, 18 Mar 2024 15:00:36 +0200 Subject: [PATCH 636/942] fix and update what platforms get tarballs generated for --- CONTRIBUTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8d0b4576b9..a86cef3e10 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -586,8 +586,8 @@ a draft GitHub release will be created, to avoid notifying watchers of the repo should a CI step fail. If everything succeeds, -bindgen cli installers for Linux/MacOS and Windows will be created, -as well as tarballs. +tarballs containing bindgen cli executables for Linux and MacOS +(both for x86 and Arm) will be created. See `[workspace.metadata.dist]` section in Cargo.toml for the configuration. To update the release configuration, From d1a2504960b78988462565ab4ea1928f82183336 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Mon, 18 Mar 2024 15:01:29 +0200 Subject: [PATCH 637/942] fix grammar --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a86cef3e10..449b37f51a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -600,7 +600,7 @@ cargo dist generate-ci # to update .github/workflows/release.yml ### What to do if a Github release fails -If the release process failed after you run `cargo release` you can manually +If the release process fails after you run `cargo release` you can manually delete the tag and release from Github. Also remember to delete the tag locally by running `git tag -d`. Once all the extra changes are in the `main` branch you can trigger a release by creating a new tag using `git tag` and push it From c78f6650b43000566cfd22b8d31b853abb485da7 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Mon, 18 Mar 2024 15:01:43 +0200 Subject: [PATCH 638/942] add a pause --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 449b37f51a..b10fd6c336 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -600,7 +600,7 @@ cargo dist generate-ci # to update .github/workflows/release.yml ### What to do if a Github release fails -If the release process fails after you run `cargo release` you can manually +If the release process fails after you run `cargo release`, you can manually delete the tag and release from Github. Also remember to delete the tag locally by running `git tag -d`. Once all the extra changes are in the `main` branch you can trigger a release by creating a new tag using `git tag` and push it From f1589818203160c641506aef6bcea5314387b264 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Mon, 18 Mar 2024 15:02:12 +0200 Subject: [PATCH 639/942] add a pause --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b10fd6c336..6ba1044c7a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -602,7 +602,7 @@ cargo dist generate-ci # to update .github/workflows/release.yml If the release process fails after you run `cargo release`, you can manually delete the tag and release from Github. Also remember to delete the tag locally -by running `git tag -d`. Once all the extra changes are in the `main` branch +by running `git tag -d`. Once all the extra changes are in the `main` branch, you can trigger a release by creating a new tag using `git tag` and push it using `git push --tag`. From 67115d961b1e4a1a02a946e110c05e4c5d37b1eb Mon Sep 17 00:00:00 2001 From: arctic-alpaca <67190338+arctic-alpaca@users.noreply.github.com> Date: Wed, 13 Mar 2024 10:02:56 +0100 Subject: [PATCH 640/942] Allow custom derives on new-type alias --- bindgen-integration/build.rs | 3 +++ bindgen-integration/cpp/Test.h | 3 +++ bindgen-integration/src/lib.rs | 7 +++++++ bindgen/codegen/mod.rs | 18 ++++++++++++++---- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs index 7021f865d7..2a0763b0b7 100644 --- a/bindgen-integration/build.rs +++ b/bindgen-integration/build.rs @@ -128,6 +128,8 @@ impl ParseCallbacks for MacroCallback { vec!["PartialEq".into()] } else if info.name == "MyOrderedEnum" { vec!["std::cmp::PartialOrd".into()] + } else if info.name == "TestDeriveOnAlias" { + vec!["std::cmp::PartialEq".into(), "std::cmp::PartialOrd".into()] } else { vec![] } @@ -193,6 +195,7 @@ fn setup_macro_test() { .blocklist_function("my_prefixed_function_to_remove") .constified_enum("my_prefixed_enum_to_be_constified") .opaque_type("my_prefixed_templated_foo") + .new_type_alias("TestDeriveOnAlias") .depfile(out_rust_file_relative.display().to_string(), &out_dep_file) .generate() .expect("Unable to generate bindings"); diff --git a/bindgen-integration/cpp/Test.h b/bindgen-integration/cpp/Test.h index eee1974cbc..81a921b5f8 100644 --- a/bindgen-integration/cpp/Test.h +++ b/bindgen-integration/cpp/Test.h @@ -241,3 +241,6 @@ enum MyOrderedEnum { METER, LIGHTYEAR, }; + +// Used to test custom derives on new-type alias. See `test_custom_derive`. +typedef int TestDeriveOnAlias; diff --git a/bindgen-integration/src/lib.rs b/bindgen-integration/src/lib.rs index 04f6a5c9de..e234477080 100755 --- a/bindgen-integration/src/lib.rs +++ b/bindgen-integration/src/lib.rs @@ -289,6 +289,13 @@ fn test_custom_derive() { assert!(meter < lightyear); assert!(meter > micron); + + // The `add_derives` callback should have added `#[derive(PartialEq, PartialOrd)]` + // to the `TestDeriveOnAlias` new-type alias. If it didn't, this will fail to compile. + let test1 = unsafe { bindings::TestDeriveOnAlias(5) }; + let test2 = unsafe { bindings::TestDeriveOnAlias(6) }; + assert!(test1 < test2); + assert!(!(test1 > test2)); } #[test] diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index b126a847b4..902e49a4e4 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -1022,10 +1022,20 @@ impl CodeGenerator for Type { let packed = false; // Types can't be packed in Rust. let derivable_traits = derives_of_item(item, ctx, packed); - if !derivable_traits.is_empty() { - let derives: Vec<_> = derivable_traits.into(); - attributes.push(attributes::derives(&derives)) - } + let mut derives: Vec<_> = derivable_traits.into(); + // The custom derives callback may return a list of derive attributes; + // add them to the end of the list. + let custom_derives = + ctx.options().all_callbacks(|cb| { + cb.add_derives(&DeriveInfo { + name: &name, + kind: DeriveTypeKind::Struct, + }) + }); + // In most cases this will be a no-op, since custom_derives will be empty. + derives + .extend(custom_derives.iter().map(|s| s.as_str())); + attributes.push(attributes::derives(&derives)); quote! { #( #attributes )* From c9ba3363e327c0a9d45167d91601fdfc359c6396 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Wed, 6 Mar 2024 14:45:05 -0500 Subject: [PATCH 641/942] Make `CargoCallbacks` more discoverable --- bindgen/options/mod.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bindgen/options/mod.rs b/bindgen/options/mod.rs index 6b5b4d8cbc..3b3224caf0 100644 --- a/bindgen/options/mod.rs +++ b/bindgen/options/mod.rs @@ -1263,6 +1263,9 @@ options! { parse_callbacks: Vec> { methods: { /// Add a new [`ParseCallbacks`] instance to configure types in different situations. + /// + /// This can also be used with [`CargoCallbacks`](struct@crate::CargoCallbacks) to emit + /// `cargo:rerun-if-changed=...` for all `#include`d header files. pub fn parse_callbacks(mut self, cb: Box) -> Self { self.options.parse_callbacks.push(Rc::from(cb)); self From 5bd9771d87c3f7829aaa7657051e56148eaefaf8 Mon Sep 17 00:00:00 2001 From: Jeremy Fitzhardinge Date: Sun, 3 Mar 2024 00:31:40 -0500 Subject: [PATCH 642/942] Move phantom fields to start of struct to avoid interfering with flexible array members. Flex array members must always be last. This changed a bunch of tests, but only in a trivial way. --- .../expectations/tests/allowlist_basic.rs | 4 +- .../tests/anonymous-template-types.rs | 4 +- .../expectations/tests/canonical-types.rs | 2 +- .../tests/expectations/tests/class_nested.rs | 6 +-- .../expectations/tests/class_with_dtor.rs | 2 +- .../tests/expectations/tests/const_tparam.rs | 2 +- .../tests/constify-module-enums-types.rs | 2 +- .../tests/default-template-parameter.rs | 4 +- .../tests/derive-debug-generic.rs | 2 +- .../tests/derive-hash-template-def-float.rs | 2 +- .../tests/derive-hash-template-inst-float.rs | 2 +- .../tests/forward-declaration-autoptr.rs | 2 +- .../forward-inherit-struct-with-fields.rs | 4 +- ...from-template-instantiation-with-vtable.rs | 4 +- .../tests/expectations/tests/inherit_named.rs | 2 +- .../tests/inline_namespace_no_ns_enabled.rs | 4 +- .../expectations/tests/inner-typedef-gh422.rs | 2 +- .../tests/issue-1113-template-references.rs | 8 ++-- .../tests/expectations/tests/issue-1514.rs | 4 +- .../tests/issue-1977-larger-arrays.rs | 2 +- ...issue-584-stylo-template-analysis-panic.rs | 2 +- ...e-638-stylo-cannot-find-T-in-this-scope.rs | 4 +- ...ue-645-cannot-find-type-T-in-this-scope.rs | 2 +- .../issue-662-cannot-find-T-in-this-scope.rs | 6 +-- .../expectations/tests/issue-662-part-2.rs | 4 +- .../tests/issue-769-bad-instantiation-test.rs | 2 +- .../issue-848-replacement-system-include.rs | 2 +- .../tests/expectations/tests/namespace.rs | 4 +- .../tests/no_debug_bypass_impl_debug.rs | 4 +- .../tests/no_default_bypass_derive_default.rs | 4 +- .../expectations/tests/nsStyleAutoArray.rs | 4 +- ...paque-template-instantiation-namespaced.rs | 2 +- .../tests/opaque-template-instantiation.rs | 2 +- .../tests/replace_template_alias.rs | 2 +- .../expectations/tests/replaces_double.rs | 4 +- .../tests/struct_with_large_array.rs | 2 +- .../tests/template-param-usage-0.rs | 2 +- .../tests/template-param-usage-10.rs | 6 +-- .../tests/template-param-usage-12.rs | 4 +- .../tests/template-param-usage-13.rs | 2 +- .../tests/template-param-usage-15.rs | 2 +- .../tests/template-param-usage-2.rs | 4 +- .../tests/template-param-usage-3.rs | 6 +-- .../tests/template-param-usage-4.rs | 2 +- .../tests/template-param-usage-5.rs | 2 +- .../tests/template-param-usage-7.rs | 4 +- .../tests/template-param-usage-8.rs | 4 +- .../tests/template-param-usage-9.rs | 4 +- .../tests/expectations/tests/template.rs | 26 ++++++------ .../expectations/tests/template_alias.rs | 2 +- .../tests/template_alias_namespace.rs | 2 +- .../template_typedef_transitive_param.rs | 2 +- .../tests/expectations/tests/transform-op.rs | 20 +++++----- ..._alias_partial_template_especialization.rs | 2 +- .../tests/expectations/tests/using.rs | 2 +- .../expectations/tests/what_is_going_on.rs | 2 +- bindgen/codegen/mod.rs | 40 +++++++++---------- 57 files changed, 127 insertions(+), 127 deletions(-) diff --git a/bindgen-tests/tests/expectations/tests/allowlist_basic.rs b/bindgen-tests/tests/expectations/tests/allowlist_basic.rs index 902c6ba503..a1c6919739 100644 --- a/bindgen-tests/tests/expectations/tests/allowlist_basic.rs +++ b/bindgen-tests/tests/expectations/tests/allowlist_basic.rs @@ -2,15 +2,15 @@ #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct AllowlistMe { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub foo: ::std::os::raw::c_int, pub bar: AllowlistMe_Inner, - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct AllowlistMe_Inner { - pub bar: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub bar: T, } impl Default for AllowlistMe_Inner { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/anonymous-template-types.rs b/bindgen-tests/tests/expectations/tests/anonymous-template-types.rs index 9009b0d7c2..f6c894d8b5 100644 --- a/bindgen-tests/tests/expectations/tests/anonymous-template-types.rs +++ b/bindgen-tests/tests/expectations/tests/anonymous-template-types.rs @@ -2,8 +2,8 @@ #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Foo { - pub t_member: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub t_member: T, } impl Default for Foo { fn default() -> Self { @@ -22,8 +22,8 @@ pub struct Bar { #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Quux { - pub v_member: V, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub v_member: V, } impl Default for Quux { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/canonical-types.rs b/bindgen-tests/tests/expectations/tests/canonical-types.rs index d19ced3b43..49795c7db7 100644 --- a/bindgen-tests/tests/expectations/tests/canonical-types.rs +++ b/bindgen-tests/tests/expectations/tests/canonical-types.rs @@ -7,8 +7,8 @@ pub struct ClassA { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct ClassA_ClassAInner { - pub x: *mut T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub x: *mut T, } impl Default for ClassA_ClassAInner { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/class_nested.rs b/bindgen-tests/tests/expectations/tests/class_nested.rs index 38db451b8b..bfda0cc281 100644 --- a/bindgen-tests/tests/expectations/tests/class_nested.rs +++ b/bindgen-tests/tests/expectations/tests/class_nested.rs @@ -32,8 +32,8 @@ fn bindgen_test_layout_A_B() { #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct A_D { - pub foo: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub foo: T, } impl Default for A_D { fn default() -> Self { @@ -134,14 +134,14 @@ fn bindgen_test_layout_D() { #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Templated { - pub member: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub member: T, } #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Templated_Templated_inner { - pub member_ptr: *mut T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub member_ptr: *mut T, } impl Default for Templated_Templated_inner { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/class_with_dtor.rs b/bindgen-tests/tests/expectations/tests/class_with_dtor.rs index 75585e6351..0fadc50671 100644 --- a/bindgen-tests/tests/expectations/tests/class_with_dtor.rs +++ b/bindgen-tests/tests/expectations/tests/class_with_dtor.rs @@ -2,8 +2,8 @@ #[repr(C)] #[derive(Debug, Hash, PartialEq, Eq)] pub struct HandleWithDtor { - pub ptr: *mut T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub ptr: *mut T, } impl Default for HandleWithDtor { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/const_tparam.rs b/bindgen-tests/tests/expectations/tests/const_tparam.rs index 12c0c2e509..c6b16a8959 100644 --- a/bindgen-tests/tests/expectations/tests/const_tparam.rs +++ b/bindgen-tests/tests/expectations/tests/const_tparam.rs @@ -2,9 +2,9 @@ #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct C { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub foo: *const T, pub bar: *const T, - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } impl Default for C { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/constify-module-enums-types.rs b/bindgen-tests/tests/expectations/tests/constify-module-enums-types.rs index 687deb45c1..e34624c5cb 100644 --- a/bindgen-tests/tests/expectations/tests/constify-module-enums-types.rs +++ b/bindgen-tests/tests/expectations/tests/constify-module-enums-types.rs @@ -211,8 +211,8 @@ extern "C" { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Thing { - pub thing: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub thing: T, } impl Default for Thing { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/default-template-parameter.rs b/bindgen-tests/tests/expectations/tests/default-template-parameter.rs index dc279e3d90..3371bad292 100644 --- a/bindgen-tests/tests/expectations/tests/default-template-parameter.rs +++ b/bindgen-tests/tests/expectations/tests/default-template-parameter.rs @@ -2,10 +2,10 @@ #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Foo { - pub t: T, - pub u: U, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub _phantom_1: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub t: T, + pub u: U, } impl Default for Foo { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/derive-debug-generic.rs b/bindgen-tests/tests/expectations/tests/derive-debug-generic.rs index f35b28b3e5..de6ce385ac 100644 --- a/bindgen-tests/tests/expectations/tests/derive-debug-generic.rs +++ b/bindgen-tests/tests/expectations/tests/derive-debug-generic.rs @@ -1,8 +1,8 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct Generic { - pub t: [T; 40usize], pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub t: [T; 40usize], } impl Default for Generic { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/derive-hash-template-def-float.rs b/bindgen-tests/tests/expectations/tests/derive-hash-template-def-float.rs index cf251c4508..af09533cca 100644 --- a/bindgen-tests/tests/expectations/tests/derive-hash-template-def-float.rs +++ b/bindgen-tests/tests/expectations/tests/derive-hash-template-def-float.rs @@ -3,9 +3,9 @@ #[repr(C)] #[derive(Debug, Copy, Clone, PartialOrd, PartialEq)] pub struct foo { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub data: T, pub b: f32, - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } impl Default for foo { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/derive-hash-template-inst-float.rs b/bindgen-tests/tests/expectations/tests/derive-hash-template-inst-float.rs index 57a716fa58..848dba6e7d 100644 --- a/bindgen-tests/tests/expectations/tests/derive-hash-template-inst-float.rs +++ b/bindgen-tests/tests/expectations/tests/derive-hash-template-inst-float.rs @@ -3,8 +3,8 @@ #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] pub struct foo { - pub data: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub data: T, } impl Default for foo { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/forward-declaration-autoptr.rs b/bindgen-tests/tests/expectations/tests/forward-declaration-autoptr.rs index 7c483638eb..6898f69d8e 100644 --- a/bindgen-tests/tests/expectations/tests/forward-declaration-autoptr.rs +++ b/bindgen-tests/tests/expectations/tests/forward-declaration-autoptr.rs @@ -7,8 +7,8 @@ pub struct Foo { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct RefPtr { - pub m_inner: *mut T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub m_inner: *mut T, } impl Default for RefPtr { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/forward-inherit-struct-with-fields.rs b/bindgen-tests/tests/expectations/tests/forward-inherit-struct-with-fields.rs index 0e5bcd969f..069c76fead 100644 --- a/bindgen-tests/tests/expectations/tests/forward-inherit-struct-with-fields.rs +++ b/bindgen-tests/tests/expectations/tests/forward-inherit-struct-with-fields.rs @@ -2,9 +2,9 @@ #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct js_RootedBase { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub foo: *mut T, pub next: *mut Rooted, - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } impl Default for js_RootedBase { fn default() -> Self { @@ -18,8 +18,8 @@ impl Default for js_RootedBase { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Rooted { - pub _base: js_RootedBase, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub _base: js_RootedBase, } impl Default for Rooted { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs b/bindgen-tests/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs index 08f186d92b..95f673921b 100644 --- a/bindgen-tests/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs +++ b/bindgen-tests/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs @@ -5,9 +5,9 @@ pub struct BaseWithVtable__bindgen_vtable {} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct BaseWithVtable { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub vtable_: *const BaseWithVtable__bindgen_vtable, pub t: T, - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } impl Default for BaseWithVtable { fn default() -> Self { @@ -78,8 +78,8 @@ impl Default for DerivedWithVirtualMethods { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct BaseWithoutVtable { - pub u: U, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub u: U, } impl Default for BaseWithoutVtable { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/inherit_named.rs b/bindgen-tests/tests/expectations/tests/inherit_named.rs index 4b3bbd7d63..a371249ab0 100644 --- a/bindgen-tests/tests/expectations/tests/inherit_named.rs +++ b/bindgen-tests/tests/expectations/tests/inherit_named.rs @@ -7,8 +7,8 @@ pub struct Wohoo { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Weeee { - pub _base: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub _base: T, } impl Default for Weeee { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/inline_namespace_no_ns_enabled.rs b/bindgen-tests/tests/expectations/tests/inline_namespace_no_ns_enabled.rs index bc3a95d2a5..66359bd51b 100644 --- a/bindgen-tests/tests/expectations/tests/inline_namespace_no_ns_enabled.rs +++ b/bindgen-tests/tests/expectations/tests/inline_namespace_no_ns_enabled.rs @@ -2,10 +2,10 @@ #[repr(C)] #[derive(Debug)] pub struct std_basic_string { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub hider: std_basic_string_Alloc_hider, pub length: ::std::os::raw::c_ulong, pub __bindgen_anon_1: std_basic_string__bindgen_ty_1, - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } #[repr(C)] #[derive(Debug, Copy, Clone)] @@ -24,8 +24,8 @@ impl Default for std_basic_string_Alloc_hider { #[repr(C)] #[derive(Debug)] pub struct std_basic_string__bindgen_ty_1 { - pub inline_storage: [CharT; 4usize], pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub inline_storage: [CharT; 4usize], } impl Default for std_basic_string__bindgen_ty_1 { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/inner-typedef-gh422.rs b/bindgen-tests/tests/expectations/tests/inner-typedef-gh422.rs index 0cc6880b44..69d2151bbb 100644 --- a/bindgen-tests/tests/expectations/tests/inner-typedef-gh422.rs +++ b/bindgen-tests/tests/expectations/tests/inner-typedef-gh422.rs @@ -7,8 +7,8 @@ pub struct Foo { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Foo_InnerType { - pub t: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub t: T, } impl Default for Foo_InnerType { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/issue-1113-template-references.rs b/bindgen-tests/tests/expectations/tests/issue-1113-template-references.rs index d42621beaf..c0e76d8047 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1113-template-references.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1113-template-references.rs @@ -2,10 +2,10 @@ #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Entry { - pub _base: K, - pub mData: V, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub _phantom_1: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub _base: K, + pub mData: V, } impl Default for Entry { fn default() -> Self { @@ -25,10 +25,10 @@ pub type nsBaseHashtable_EntryType = Entry; #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct nsBaseHashtable_EntryPtr { - pub mEntry: *mut nsBaseHashtable_EntryType, - pub mExistingEntry: bool, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub _phantom_1: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub mEntry: *mut nsBaseHashtable_EntryType, + pub mExistingEntry: bool, } impl Default for nsBaseHashtable_EntryPtr { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/issue-1514.rs b/bindgen-tests/tests/expectations/tests/issue-1514.rs index a52272ef93..aef63037ae 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1514.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1514.rs @@ -7,8 +7,8 @@ pub struct Thing { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Thing_Inner { - pub ptr: *mut T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub ptr: *mut T, } impl Default for Thing_Inner { fn default() -> Self { @@ -22,8 +22,8 @@ impl Default for Thing_Inner { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Thing_AnotherInner { - pub _base: Thing_Inner, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub _base: Thing_Inner, } impl Default for Thing_AnotherInner { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/issue-1977-larger-arrays.rs b/bindgen-tests/tests/expectations/tests/issue-1977-larger-arrays.rs index f60e10cdff..a64d7a2d46 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1977-larger-arrays.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1977-larger-arrays.rs @@ -32,8 +32,8 @@ impl Default for S { #[repr(C)] #[derive(Debug, Hash, PartialEq, Eq)] pub struct ST { - pub large_array: [T; 33usize], pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub large_array: [T; 33usize], } impl Default for ST { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs b/bindgen-tests/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs index 060db1636d..c9c5dbc7f1 100644 --- a/bindgen-tests/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs +++ b/bindgen-tests/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs @@ -17,8 +17,8 @@ fn bindgen_test_layout_A() { } #[repr(C)] pub struct e { - pub d: RefPtr, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub d: RefPtr, } impl Default for e { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/issue-638-stylo-cannot-find-T-in-this-scope.rs b/bindgen-tests/tests/expectations/tests/issue-638-stylo-cannot-find-T-in-this-scope.rs index 292fa2734f..db94687737 100644 --- a/bindgen-tests/tests/expectations/tests/issue-638-stylo-cannot-find-T-in-this-scope.rs +++ b/bindgen-tests/tests/expectations/tests/issue-638-stylo-cannot-find-T-in-this-scope.rs @@ -2,8 +2,8 @@ #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct RefPtr { - pub use_of_t: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub use_of_t: T, } impl Default for RefPtr { fn default() -> Self { @@ -17,8 +17,8 @@ impl Default for RefPtr { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct UsesRefPtrWithAliasedTypeParam { - pub member: RefPtr>, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub member: RefPtr>, } pub type UsesRefPtrWithAliasedTypeParam_V = U; impl Default for UsesRefPtrWithAliasedTypeParam { diff --git a/bindgen-tests/tests/expectations/tests/issue-645-cannot-find-type-T-in-this-scope.rs b/bindgen-tests/tests/expectations/tests/issue-645-cannot-find-type-T-in-this-scope.rs index 3e3e398006..82e2ab4c42 100644 --- a/bindgen-tests/tests/expectations/tests/issue-645-cannot-find-type-T-in-this-scope.rs +++ b/bindgen-tests/tests/expectations/tests/issue-645-cannot-find-type-T-in-this-scope.rs @@ -3,8 +3,8 @@ pub struct RefPtr(T); #[repr(C)] pub struct HasRefPtr { - pub refptr_member: RefPtr>, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub refptr_member: RefPtr>, } pub type HasRefPtr_TypedefOfT = T; impl Default for HasRefPtr { diff --git a/bindgen-tests/tests/expectations/tests/issue-662-cannot-find-T-in-this-scope.rs b/bindgen-tests/tests/expectations/tests/issue-662-cannot-find-T-in-this-scope.rs index 5e6dd01298..2e68628323 100644 --- a/bindgen-tests/tests/expectations/tests/issue-662-cannot-find-T-in-this-scope.rs +++ b/bindgen-tests/tests/expectations/tests/issue-662-cannot-find-T-in-this-scope.rs @@ -2,8 +2,8 @@ #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct RefPtr { - pub a: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub a: T, } impl Default for RefPtr { fn default() -> Self { @@ -17,8 +17,8 @@ impl Default for RefPtr { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct nsMainThreadPtrHolder { - pub a: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub a: T, } impl Default for nsMainThreadPtrHolder { fn default() -> Self { @@ -32,8 +32,8 @@ impl Default for nsMainThreadPtrHolder { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct nsMainThreadPtrHandle { - pub mPtr: RefPtr>, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub mPtr: RefPtr>, } impl Default for nsMainThreadPtrHandle { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/issue-662-part-2.rs b/bindgen-tests/tests/expectations/tests/issue-662-part-2.rs index 75993a052d..9ddcdc5e8d 100644 --- a/bindgen-tests/tests/expectations/tests/issue-662-part-2.rs +++ b/bindgen-tests/tests/expectations/tests/issue-662-part-2.rs @@ -4,8 +4,8 @@ pub struct RefPtr(T); #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct nsMainThreadPtrHolder { - pub a: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub a: T, } impl Default for nsMainThreadPtrHolder { fn default() -> Self { @@ -18,8 +18,8 @@ impl Default for nsMainThreadPtrHolder { } #[repr(C)] pub struct nsMainThreadPtrHandle { - pub mPtr: RefPtr>, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub mPtr: RefPtr>, } impl Default for nsMainThreadPtrHandle { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/issue-769-bad-instantiation-test.rs b/bindgen-tests/tests/expectations/tests/issue-769-bad-instantiation-test.rs index ef830ca69e..172c3193d2 100644 --- a/bindgen-tests/tests/expectations/tests/issue-769-bad-instantiation-test.rs +++ b/bindgen-tests/tests/expectations/tests/issue-769-bad-instantiation-test.rs @@ -6,8 +6,8 @@ pub mod root { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Rooted { - pub member: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub member: T, } impl Default for Rooted { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/issue-848-replacement-system-include.rs b/bindgen-tests/tests/expectations/tests/issue-848-replacement-system-include.rs index d9d4fd9abc..d224612ba9 100644 --- a/bindgen-tests/tests/expectations/tests/issue-848-replacement-system-include.rs +++ b/bindgen-tests/tests/expectations/tests/issue-848-replacement-system-include.rs @@ -8,8 +8,8 @@ #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct nsTArray { - pub m: *mut T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub m: *mut T, } impl Default for nsTArray { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/namespace.rs b/bindgen-tests/tests/expectations/tests/namespace.rs index ebeccb1344..ab3a613840 100644 --- a/bindgen-tests/tests/expectations/tests/namespace.rs +++ b/bindgen-tests/tests/expectations/tests/namespace.rs @@ -49,11 +49,11 @@ pub mod root { #[repr(C)] #[derive(Debug)] pub struct C { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub _base: root::_bindgen_mod_id_17::A, pub m_c: T, pub m_c_ptr: *mut T, pub m_c_arr: [T; 10usize], - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } impl Default for C { fn default() -> Self { @@ -71,8 +71,8 @@ pub mod root { #[repr(C)] #[derive(Debug)] pub struct D { - pub m_c: root::C, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub m_c: root::C, } impl Default for D { fn default() -> Self { 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 7078a4c255..d972c74376 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,8 +1,8 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct Generic { - pub t: [T; 40usize], pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub t: [T; 40usize], } impl Default for Generic { fn default() -> Self { @@ -20,8 +20,8 @@ impl ::std::fmt::Debug for Generic { } #[repr(C)] pub struct NoDebug { - pub t: [T; 40usize], pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub t: [T; 40usize], } impl Default for NoDebug { fn default() -> Self { 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 f5b4322065..58f3684ac9 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,8 +1,8 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] pub struct Generic { - pub t: [T; 40usize], pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub t: [T; 40usize], } impl Default for Generic { fn default() -> Self { @@ -15,6 +15,6 @@ impl Default for Generic { } #[repr(C)] pub struct NoDefault { - pub t: [T; 40usize], pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub t: [T; 40usize], } diff --git a/bindgen-tests/tests/expectations/tests/nsStyleAutoArray.rs b/bindgen-tests/tests/expectations/tests/nsStyleAutoArray.rs index b475b1a9b1..3d8edcfdc1 100644 --- a/bindgen-tests/tests/expectations/tests/nsStyleAutoArray.rs +++ b/bindgen-tests/tests/expectations/tests/nsStyleAutoArray.rs @@ -2,8 +2,8 @@ #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct nsTArray { - pub mBuff: *mut T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub mBuff: *mut T, } impl Default for nsTArray { fn default() -> Self { @@ -17,9 +17,9 @@ impl Default for nsTArray { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct nsStyleAutoArray { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub mFirstElement: T, pub mOtherElements: nsTArray, - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } #[repr(i32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] diff --git a/bindgen-tests/tests/expectations/tests/opaque-template-instantiation-namespaced.rs b/bindgen-tests/tests/expectations/tests/opaque-template-instantiation-namespaced.rs index 57b20c78a9..07190df7f9 100644 --- a/bindgen-tests/tests/expectations/tests/opaque-template-instantiation-namespaced.rs +++ b/bindgen-tests/tests/expectations/tests/opaque-template-instantiation-namespaced.rs @@ -9,8 +9,8 @@ pub mod root { #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Template { - pub member: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub member: T, } impl Default for Template { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/opaque-template-instantiation.rs b/bindgen-tests/tests/expectations/tests/opaque-template-instantiation.rs index a1cdbcc977..7431f69024 100644 --- a/bindgen-tests/tests/expectations/tests/opaque-template-instantiation.rs +++ b/bindgen-tests/tests/expectations/tests/opaque-template-instantiation.rs @@ -2,8 +2,8 @@ #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Template { - pub member: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub member: T, } impl Default for Template { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/replace_template_alias.rs b/bindgen-tests/tests/expectations/tests/replace_template_alias.rs index 6d656b2be6..2efa164ddf 100644 --- a/bindgen-tests/tests/expectations/tests/replace_template_alias.rs +++ b/bindgen-tests/tests/expectations/tests/replace_template_alias.rs @@ -6,8 +6,8 @@ pub type JS_detail_MaybeWrapped = T; #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct JS_Rooted { - pub ptr: JS_detail_MaybeWrapped, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub ptr: JS_detail_MaybeWrapped, } impl Default for JS_Rooted { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/replaces_double.rs b/bindgen-tests/tests/expectations/tests/replaces_double.rs index 30966355fe..e764113f21 100644 --- a/bindgen-tests/tests/expectations/tests/replaces_double.rs +++ b/bindgen-tests/tests/expectations/tests/replaces_double.rs @@ -2,8 +2,8 @@ #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Wrapper_Wrapped { - pub t: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub t: T, } impl Default for Wrapper_Wrapped { fn default() -> Self { @@ -18,8 +18,8 @@ pub type Wrapper_Type = Wrapper_Wrapped; #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Rooted { - pub ptr: Rooted_MaybeWrapped, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub ptr: Rooted_MaybeWrapped, } ///
pub type Rooted_MaybeWrapped = T; 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 74b409235d..a0d8cf0268 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_large_array.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_large_array.rs @@ -31,8 +31,8 @@ impl Default for S { } #[repr(C)] pub struct ST { - pub large_array: [T; 33usize], pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub large_array: [T; 33usize], } impl Default for ST { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/template-param-usage-0.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-0.rs index 6ca9b11ec6..ba8980be00 100644 --- a/bindgen-tests/tests/expectations/tests/template-param-usage-0.rs +++ b/bindgen-tests/tests/expectations/tests/template-param-usage-0.rs @@ -2,8 +2,8 @@ #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct UsesTemplateParameter { - pub t: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub t: T, } impl Default for UsesTemplateParameter { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/template-param-usage-10.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-10.rs index 778ac4a2a3..a4e5d0ce82 100644 --- a/bindgen-tests/tests/expectations/tests/template-param-usage-10.rs +++ b/bindgen-tests/tests/expectations/tests/template-param-usage-10.rs @@ -2,19 +2,19 @@ #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct DoublyIndirectUsage { - pub doubly_indirect: DoublyIndirectUsage_IndirectUsage, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub _phantom_1: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub doubly_indirect: DoublyIndirectUsage_IndirectUsage, } pub type DoublyIndirectUsage_Aliased = T; pub type DoublyIndirectUsage_Typedefed = U; #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct DoublyIndirectUsage_IndirectUsage { - pub member: DoublyIndirectUsage_Aliased, - pub another: DoublyIndirectUsage_Typedefed, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub _phantom_1: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub member: DoublyIndirectUsage_Aliased, + pub another: DoublyIndirectUsage_Typedefed, } impl Default for DoublyIndirectUsage_IndirectUsage { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/template-param-usage-12.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-12.rs index d4d403f1da..7f3a306b6b 100644 --- a/bindgen-tests/tests/expectations/tests/template-param-usage-12.rs +++ b/bindgen-tests/tests/expectations/tests/template-param-usage-12.rs @@ -2,8 +2,8 @@ #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct BaseUsesT { - pub t: *mut T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub t: *mut T, } impl Default for BaseUsesT { fn default() -> Self { @@ -17,9 +17,9 @@ impl Default for BaseUsesT { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct CrtpUsesU { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub _base: BaseUsesT>, pub usage: U, - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } impl Default for CrtpUsesU { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/template-param-usage-13.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-13.rs index 204bb1d965..185f16be11 100644 --- a/bindgen-tests/tests/expectations/tests/template-param-usage-13.rs +++ b/bindgen-tests/tests/expectations/tests/template-param-usage-13.rs @@ -7,9 +7,9 @@ pub struct BaseIgnoresT { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct CrtpUsesU { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub _base: BaseIgnoresT, pub usage: U, - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } impl Default for CrtpUsesU { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/template-param-usage-15.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-15.rs index c6d7f71d17..fced6dc58c 100644 --- a/bindgen-tests/tests/expectations/tests/template-param-usage-15.rs +++ b/bindgen-tests/tests/expectations/tests/template-param-usage-15.rs @@ -2,8 +2,8 @@ #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct BaseUsesT { - pub usage: *mut T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub usage: *mut T, } impl Default for BaseUsesT { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/template-param-usage-2.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-2.rs index ea24b9ea82..4c671ce2ab 100644 --- a/bindgen-tests/tests/expectations/tests/template-param-usage-2.rs +++ b/bindgen-tests/tests/expectations/tests/template-param-usage-2.rs @@ -2,14 +2,14 @@ #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct UsesTemplateParameter { - pub t: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub t: T, } #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct UsesTemplateParameter_AlsoUsesTemplateParameter { - pub also: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub also: T, } impl Default for UsesTemplateParameter_AlsoUsesTemplateParameter { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/template-param-usage-3.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-3.rs index ab7121bca9..511365e656 100644 --- a/bindgen-tests/tests/expectations/tests/template-param-usage-3.rs +++ b/bindgen-tests/tests/expectations/tests/template-param-usage-3.rs @@ -2,16 +2,16 @@ #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct UsesTemplateParameter { - pub t: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub t: T, } #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct UsesTemplateParameter_AlsoUsesTemplateParameterAndMore { - pub also: T, - pub more: U, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub _phantom_1: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub also: T, + pub more: U, } impl Default for UsesTemplateParameter_AlsoUsesTemplateParameterAndMore { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/template-param-usage-4.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-4.rs index 0136af8b45..5655a6d260 100644 --- a/bindgen-tests/tests/expectations/tests/template-param-usage-4.rs +++ b/bindgen-tests/tests/expectations/tests/template-param-usage-4.rs @@ -2,8 +2,8 @@ #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct UsesTemplateParameter { - pub t: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub t: T, } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] diff --git a/bindgen-tests/tests/expectations/tests/template-param-usage-5.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-5.rs index da363e8058..5049559b33 100644 --- a/bindgen-tests/tests/expectations/tests/template-param-usage-5.rs +++ b/bindgen-tests/tests/expectations/tests/template-param-usage-5.rs @@ -2,8 +2,8 @@ #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct IndirectlyUsesTemplateParameter { - pub aliased: IndirectlyUsesTemplateParameter_Aliased, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub aliased: IndirectlyUsesTemplateParameter_Aliased, } pub type IndirectlyUsesTemplateParameter_Aliased = T; impl Default for IndirectlyUsesTemplateParameter { diff --git a/bindgen-tests/tests/expectations/tests/template-param-usage-7.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-7.rs index 477fc5efe1..1552ae852f 100644 --- a/bindgen-tests/tests/expectations/tests/template-param-usage-7.rs +++ b/bindgen-tests/tests/expectations/tests/template-param-usage-7.rs @@ -2,10 +2,10 @@ #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct DoesNotUseU { - pub t: T, - pub v: V, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub _phantom_1: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub t: T, + pub v: V, } impl Default for DoesNotUseU { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/template-param-usage-8.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-8.rs index 700f06c431..61de18a833 100644 --- a/bindgen-tests/tests/expectations/tests/template-param-usage-8.rs +++ b/bindgen-tests/tests/expectations/tests/template-param-usage-8.rs @@ -2,10 +2,10 @@ #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct IndirectUsage { - pub member1: IndirectUsage_Typedefed, - pub member2: IndirectUsage_Aliased, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub _phantom_1: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub member1: IndirectUsage_Typedefed, + pub member2: IndirectUsage_Aliased, } pub type IndirectUsage_Typedefed = T; pub type IndirectUsage_Aliased = U; diff --git a/bindgen-tests/tests/expectations/tests/template-param-usage-9.rs b/bindgen-tests/tests/expectations/tests/template-param-usage-9.rs index 6e62dccd41..ff0eedc8ae 100644 --- a/bindgen-tests/tests/expectations/tests/template-param-usage-9.rs +++ b/bindgen-tests/tests/expectations/tests/template-param-usage-9.rs @@ -9,10 +9,10 @@ pub type DoesNotUse_Typedefed = U; #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct DoesNotUse_IndirectUsage { - pub member: DoesNotUse_Aliased, - pub another: DoesNotUse_Typedefed, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub _phantom_1: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub member: DoesNotUse_Aliased, + pub another: DoesNotUse_Typedefed, } impl Default for DoesNotUse_IndirectUsage { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/template.rs b/bindgen-tests/tests/expectations/tests/template.rs index d43d4dd1a8..6b8bd11e2b 100644 --- a/bindgen-tests/tests/expectations/tests/template.rs +++ b/bindgen-tests/tests/expectations/tests/template.rs @@ -2,10 +2,10 @@ #[repr(C)] #[derive(Debug, Hash, PartialEq, Eq)] pub struct Foo { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub m_member: T, pub m_member_ptr: *mut T, pub m_member_arr: [T; 1usize], - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } impl Default for Foo { fn default() -> Self { @@ -19,8 +19,8 @@ impl Default for Foo { #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct B { - pub m_member: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub m_member: T, } impl Default for B { fn default() -> Self { @@ -180,9 +180,9 @@ pub type D_MyFoo = Foo<::std::os::raw::c_int>; #[repr(C)] #[derive(Debug, Hash, PartialEq, Eq)] pub struct D_U { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub m_nested_foo: D_MyFoo, pub m_baz: Z, - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } impl Default for D_U { fn default() -> Self { @@ -205,10 +205,10 @@ impl Default for D { #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Rooted { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub prev: *mut T, pub next: *mut Rooted<*mut ::std::os::raw::c_void>, pub ptr: T, - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } impl Default for Rooted { fn default() -> Self { @@ -257,8 +257,8 @@ pub type WithDtorIntFwd = WithDtor<::std::os::raw::c_int>; #[repr(C)] #[derive(Debug, Hash, PartialEq, Eq)] pub struct WithDtor { - pub member: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub member: T, } impl Default for WithDtor { fn default() -> Self { @@ -343,8 +343,8 @@ fn bindgen_test_layout_POD() { #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct NestedReplaced { - pub buff: *mut T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub buff: *mut T, } impl Default for NestedReplaced { fn default() -> Self { @@ -358,8 +358,8 @@ impl Default for NestedReplaced { #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct NestedBase { - pub buff: *mut T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub buff: *mut T, } impl Default for NestedBase { fn default() -> Self { @@ -373,10 +373,10 @@ impl Default for NestedBase { #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct NestedContainer { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub c: T, pub nested: NestedReplaced, pub inc: Incomplete, - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } impl Default for NestedContainer { fn default() -> Self { @@ -390,8 +390,8 @@ impl Default for NestedContainer { #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Incomplete { - pub d: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub d: T, } impl Default for Incomplete { fn default() -> Self { @@ -432,8 +432,8 @@ pub struct Templated { #[repr(C)] #[derive(Debug, Hash, PartialEq, Eq)] pub struct ReplacedWithoutDestructor { - pub buff: *mut T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub buff: *mut T, } impl Default for ReplacedWithoutDestructor { fn default() -> Self { @@ -447,8 +447,8 @@ impl Default for ReplacedWithoutDestructor { #[repr(C)] #[derive(Debug, Hash, PartialEq, Eq)] pub struct ShouldNotBeCopiable { - pub m_member: ReplacedWithoutDestructor, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub m_member: ReplacedWithoutDestructor, } impl Default for ShouldNotBeCopiable { fn default() -> Self { @@ -462,8 +462,8 @@ impl Default for ShouldNotBeCopiable { #[repr(C)] #[derive(Debug, Hash, PartialEq, Eq)] pub struct ShouldNotBeCopiableAsWell { - pub m_member: ReplacedWithoutDestructorFwd, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub m_member: ReplacedWithoutDestructorFwd, } impl Default for ShouldNotBeCopiableAsWell { fn default() -> Self { @@ -481,8 +481,8 @@ impl Default for ShouldNotBeCopiableAsWell { #[repr(C)] #[derive(Debug, Hash, PartialEq, Eq)] pub struct ReplacedWithoutDestructorFwd { - pub buff: *mut T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub buff: *mut T, } impl Default for ReplacedWithoutDestructorFwd { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/template_alias.rs b/bindgen-tests/tests/expectations/tests/template_alias.rs index d286cca3c6..b270c9f3a4 100644 --- a/bindgen-tests/tests/expectations/tests/template_alias.rs +++ b/bindgen-tests/tests/expectations/tests/template_alias.rs @@ -3,8 +3,8 @@ pub type JS_detail_Wrapped = T; #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct JS_Rooted { - pub ptr: JS_detail_Wrapped, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub ptr: JS_detail_Wrapped, } impl Default for JS_Rooted { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/template_alias_namespace.rs b/bindgen-tests/tests/expectations/tests/template_alias_namespace.rs index d0dfa78596..0aa5fc679a 100644 --- a/bindgen-tests/tests/expectations/tests/template_alias_namespace.rs +++ b/bindgen-tests/tests/expectations/tests/template_alias_namespace.rs @@ -14,8 +14,8 @@ pub mod root { #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Rooted { - pub ptr: root::JS::detail::Wrapped, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub ptr: root::JS::detail::Wrapped, } impl Default for Rooted { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/template_typedef_transitive_param.rs b/bindgen-tests/tests/expectations/tests/template_typedef_transitive_param.rs index 019f085c60..2efdde944e 100644 --- a/bindgen-tests/tests/expectations/tests/template_typedef_transitive_param.rs +++ b/bindgen-tests/tests/expectations/tests/template_typedef_transitive_param.rs @@ -7,8 +7,8 @@ pub struct Wrapper { #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Wrapper_Wrapped { - pub t: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub t: T, } impl Default for Wrapper_Wrapped { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/transform-op.rs b/bindgen-tests/tests/expectations/tests/transform-op.rs index 85c34985c3..bd70711f47 100644 --- a/bindgen-tests/tests/expectations/tests/transform-op.rs +++ b/bindgen-tests/tests/expectations/tests/transform-op.rs @@ -45,9 +45,9 @@ impl ::std::cmp::Eq for __BindgenUnionField {} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct StylePoint { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub x: T, pub y: T, - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } impl Default for StylePoint { fn default() -> Self { @@ -61,12 +61,12 @@ impl Default for StylePoint { #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct StyleFoo { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub __bindgen_anon_1: __BindgenUnionField, pub foo: __BindgenUnionField>, pub bar: __BindgenUnionField>, pub baz: __BindgenUnionField>, pub bindgen_union_field: [u8; 0usize], - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } pub const StyleFoo_Tag_Foo: StyleFoo_Tag = 0; pub const StyleFoo_Tag_Bar: StyleFoo_Tag = 0; @@ -76,11 +76,11 @@ pub type StyleFoo_Tag = u8; #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct StyleFoo_Foo_Body { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub tag: StyleFoo_Tag, pub x: i32, pub y: StylePoint, pub z: StylePoint, - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } impl Default for StyleFoo_Foo_Body { fn default() -> Self { @@ -94,9 +94,9 @@ impl Default for StyleFoo_Foo_Body { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct StyleFoo_Bar_Body { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub tag: StyleFoo_Tag, pub _0: T, - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } impl Default for StyleFoo_Bar_Body { fn default() -> Self { @@ -110,9 +110,9 @@ impl Default for StyleFoo_Bar_Body { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct StyleFoo_Baz_Body { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub tag: StyleFoo_Tag, pub _0: StylePoint, - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } impl Default for StyleFoo_Baz_Body { fn default() -> Self { @@ -140,9 +140,9 @@ impl Default for StyleFoo__bindgen_ty_1 { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct StyleBar { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub tag: StyleBar_Tag, pub __bindgen_anon_1: StyleBar__bindgen_ty_1, - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } pub const StyleBar_Tag_Bar1: StyleBar_Tag = 0; pub const StyleBar_Tag_Bar2: StyleBar_Tag = 0; @@ -152,10 +152,10 @@ pub type StyleBar_Tag = ::std::os::raw::c_int; #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct StyleBar_StyleBar1_Body { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub x: i32, pub y: StylePoint, pub z: StylePoint, - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } impl Default for StyleBar_StyleBar1_Body { fn default() -> Self { @@ -169,8 +169,8 @@ impl Default for StyleBar_StyleBar1_Body { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct StyleBar_StyleBar2_Body { - pub _0: T, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub _0: T, } impl Default for StyleBar_StyleBar2_Body { fn default() -> Self { @@ -184,8 +184,8 @@ impl Default for StyleBar_StyleBar2_Body { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct StyleBar_StyleBar3_Body { - pub _0: StylePoint, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub _0: StylePoint, } impl Default for StyleBar_StyleBar3_Body { fn default() -> Self { @@ -199,11 +199,11 @@ impl Default for StyleBar_StyleBar3_Body { #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct StyleBar__bindgen_ty_1 { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub bar1: __BindgenUnionField>, pub bar2: __BindgenUnionField>, pub bar3: __BindgenUnionField>, pub bindgen_union_field: [u8; 0usize], - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } impl Default for StyleBar { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/type_alias_partial_template_especialization.rs b/bindgen-tests/tests/expectations/tests/type_alias_partial_template_especialization.rs index 48c388d6f9..29df017a9b 100644 --- a/bindgen-tests/tests/expectations/tests/type_alias_partial_template_especialization.rs +++ b/bindgen-tests/tests/expectations/tests/type_alias_partial_template_especialization.rs @@ -3,8 +3,8 @@ pub type MaybeWrapped
= A; #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Rooted { - pub ptr: MaybeWrapped, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub ptr: MaybeWrapped, } impl Default for Rooted { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/using.rs b/bindgen-tests/tests/expectations/tests/using.rs index 97d00cb5b8..9737fef0a5 100644 --- a/bindgen-tests/tests/expectations/tests/using.rs +++ b/bindgen-tests/tests/expectations/tests/using.rs @@ -2,9 +2,9 @@ #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Point { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub x: T, pub y: T, - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } impl Default for Point { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/what_is_going_on.rs b/bindgen-tests/tests/expectations/tests/what_is_going_on.rs index 596636a961..2bd4d2b33b 100644 --- a/bindgen-tests/tests/expectations/tests/what_is_going_on.rs +++ b/bindgen-tests/tests/expectations/tests/what_is_going_on.rs @@ -21,9 +21,9 @@ pub type Float = f32; #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct PointTyped { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub x: F, pub y: F, - pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, } impl Default for PointTyped { fn default() -> Self { diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 902e49a4e4..6e342ce8f1 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -1990,6 +1990,23 @@ impl CodeGenerator for CompInfo { packed, ); + let mut generic_param_names = vec![]; + + for (idx, ty) in item.used_template_params(ctx).iter().enumerate() { + let param = ctx.resolve_type(*ty); + let name = param.name().unwrap(); + let ident = ctx.rust_ident(name); + generic_param_names.push(ident.clone()); + + let prefix = ctx.trait_prefix(); + let field_name = ctx.rust_ident(format!("_phantom_{}", idx)); + fields.push(quote! { + pub #field_name : ::#prefix::marker::PhantomData< + ::#prefix::cell::UnsafeCell<#ident> + > , + }); + } + if !is_opaque { if item.has_vtable_ptr(ctx) { let vtable = Vtable::new(item.id(), self); @@ -2173,32 +2190,15 @@ impl CodeGenerator for CompInfo { }); } - let mut generic_param_names = vec![]; - - for (idx, ty) in item.used_template_params(ctx).iter().enumerate() { - let param = ctx.resolve_type(*ty); - let name = param.name().unwrap(); - let ident = ctx.rust_ident(name); - generic_param_names.push(ident.clone()); - - let prefix = ctx.trait_prefix(); - let field_name = ctx.rust_ident(format!("_phantom_{}", idx)); - fields.push(quote! { - pub #field_name : ::#prefix::marker::PhantomData< - ::#prefix::cell::UnsafeCell<#ident> - > , - }); - } - let generics = if !generic_param_names.is_empty() { let generic_param_names = generic_param_names.clone(); quote! { < #( #generic_param_names ),* > - } + } } else { - quote! {} + quote !{} }; - + let mut attributes = vec![]; let mut needs_clone_impl = false; let mut needs_default_impl = false; From 3b5ce9c5861cd2e97e9789f5b686238656abd2d6 Mon Sep 17 00:00:00 2001 From: Jeremy Fitzhardinge Date: Tue, 19 Mar 2024 14:52:17 -0700 Subject: [PATCH 643/942] formatting fixes --- bindgen/codegen/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 6e342ce8f1..73ae0c4f61 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -2194,11 +2194,11 @@ impl CodeGenerator for CompInfo { let generic_param_names = generic_param_names.clone(); quote! { < #( #generic_param_names ),* > - } + } } else { - quote !{} + quote! {} }; - + let mut attributes = vec![]; let mut needs_clone_impl = false; let mut needs_default_impl = false; From 740ec66fbf84f1b65a2154f98c65027649412541 Mon Sep 17 00:00:00 2001 From: Jonathan Schwender <55576758+jschwe@users.noreply.github.com> Date: Wed, 27 Mar 2024 07:30:30 +0100 Subject: [PATCH 644/942] Add prettyplease feature to bindgen-cli (#2789) * Add prettyplease feature to bindgen-cli The bindgen documentation explictly mentions being able to use `--formatter=prettyplease`, but currently the prettyplease feature has no way to be enabled. Enable it by default, since the documentation also doesn't mention needing to cargo install with a feature. Documentation: https://rust-lang.github.io/rust-bindgen/code-formatting.html * Add Changelog entry for bindgen-cli prettyplease fix --- CHANGELOG.md | 2 ++ bindgen-cli/Cargo.toml | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 95b7ac2966..390660f2ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -207,6 +207,8 @@ - Add target mappings for riscv64imac and riscv32imafc. ## Removed ## Fixed +- Fix `--formatter=prettyplease` not working in `bindgen-cli` by adding `prettyplease` feature and + enabling it by default for `bindgen-cli` (#2789) . ## Security # 0.69.4 (2024-02-04) diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index e642790014..24066c4c34 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -20,7 +20,7 @@ path = "main.rs" name = "bindgen" [dependencies] -bindgen = { path = "../bindgen", version = "=0.69.4", default-features = false, features = ["__cli", "experimental"] } +bindgen = { path = "../bindgen", version = "=0.69.4", default-features = false, features = ["__cli", "experimental", "prettyplease"] } clap = { version = "4", features = ["derive"] } clap_complete = "4" env_logger = { version = "0.10.0", optional = true } @@ -34,6 +34,7 @@ static = ["bindgen/static"] runtime = ["bindgen/runtime"] # Dynamically discover a `rustfmt` binary using the `which` crate which-rustfmt = ["bindgen/which-rustfmt"] +prettyplease = ["bindgen/prettyplease"] ## The following features are for internal use and they shouldn't be used if ## you're not hacking on bindgen From ea3b4a026ed1f9d719e965e35f9eb751c0b826a1 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Wed, 27 Mar 2024 20:12:24 +0200 Subject: [PATCH 645/942] book: fix typo --- book/src/code-formatting.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/src/code-formatting.md b/book/src/code-formatting.md index 2972a48b4f..9c82e83a32 100644 --- a/book/src/code-formatting.md +++ b/book/src/code-formatting.md @@ -73,7 +73,7 @@ These two methods also apply to any other toolchain available in your system. The [`prettyplease`](https://github.com/dtolnay/prettyplease) crate is a minimal formatter for generated code. To format bindings using `prettyplease` you have to invoke `bindgen` with either the `--formatter=prettyplease` flag or -the the `bindgen::Builder::formatter(bindgen::Formatter::Prettyplease)`. One of +the `bindgen::Builder::formatter(bindgen::Formatter::Prettyplease)`. One of its advantages is that `prettyplease` can be used in minimal environments where the Rust toolchain is not installed. From 738644fb4f34ce55bfaa57e755e71f2d2045b665 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Wed, 27 Mar 2024 20:46:55 +0200 Subject: [PATCH 646/942] bump cargo-dist (#2790) --- .github/workflows/release.yml | 177 ++++++++++++++++++++++++---------- CONTRIBUTING.md | 1 - Cargo.toml | 6 +- 3 files changed, 130 insertions(+), 54 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7997a9c1b7..502a5ff8da 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -6,10 +6,11 @@ # * checks for a Git Tag that looks like a release # * builds artifacts with cargo-dist (archives, installers, hashes) # * uploads those artifacts to temporary workflow zip -# * on success, uploads the artifacts to a Github Release™ +# * on success, uploads the artifacts to a Github Release # -# Note that the Github Release™ will be created with a generated +# Note that the Github Release will be created with a generated # title/body based on your changelogs. + name: Release permissions: @@ -21,20 +22,20 @@ permissions: # PACKAGE_NAME must be the name of a Cargo package in your workspace, and VERSION # must be a Cargo-style SemVer Version (must have at least major.minor.patch). # -# If PACKAGE_NAME is specified, then the release will be for that +# If PACKAGE_NAME is specified, then the announcement will be for that # package (erroring out if it doesn't have the given version or isn't cargo-dist-able). # -# If PACKAGE_NAME isn't specified, then the release will be for all +# If PACKAGE_NAME isn't specified, then the announcement will be for all # (cargo-dist-able) packages in the workspace with that version (this mode is # intended for workspaces with only one dist-able package, or with all dist-able # packages versioned/released in lockstep). # # If you push multiple tags at once, separate instances of this workflow will -# spin up, creating an independent Github Release™ for each one. However Github +# spin up, creating an independent announcement for each one. However Github # will hard limit this to 3 tags per commit, as it will assume more tags is a # mistake. # -# If there's a prerelease-style suffix to the version, then the Github Release™ +# If there's a prerelease-style suffix to the version, then the release(s) # will be marked as a prerelease. on: push: @@ -43,7 +44,7 @@ on: pull_request: jobs: - # Run 'cargo dist plan' to determine what tasks we need to do + # Run 'cargo dist plan' (or host) to determine what tasks we need to do plan: runs-on: ubuntu-latest outputs: @@ -58,24 +59,34 @@ jobs: with: submodules: recursive - name: Install cargo-dist - run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.3.1/cargo-dist-installer.sh | sh" + # we specify bash to get pipefail; it guards against the `curl` command + # failing. otherwise `sh` won't catch that `curl` returned non-0 + shell: bash + run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.12.0/cargo-dist-installer.sh | sh" + # sure would be cool if github gave us proper conditionals... + # so here's a doubly-nested ternary-via-truthiness to try to provide the best possible + # functionality based on whether this is a pull_request, and whether it's from a fork. + # (PRs run on the *source* but secrets are usually on the *target* -- that's *good* + # but also really annoying to build CI around when it needs secrets to work right.) - id: plan run: | - cargo dist plan ${{ !github.event.pull_request && format('--tag={0}', github.ref_name) || '' }} --output-format=json > dist-manifest.json - echo "cargo dist plan ran successfully" - cat dist-manifest.json - echo "manifest=$(jq -c "." dist-manifest.json)" >> "$GITHUB_OUTPUT" + cargo dist ${{ (!github.event.pull_request && format('host --steps=create --tag={0}', github.ref_name)) || 'plan' }} --output-format=json > plan-dist-manifest.json + echo "cargo dist ran successfully" + cat plan-dist-manifest.json + echo "manifest=$(jq -c "." plan-dist-manifest.json)" >> "$GITHUB_OUTPUT" - name: "Upload dist-manifest.json" - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: - name: artifacts - path: dist-manifest.json + name: artifacts-plan-dist-manifest + path: plan-dist-manifest.json # Build and packages all the platform-specific things - upload-local-artifacts: + build-local-artifacts: + name: build-local-artifacts (${{ join(matrix.targets, ', ') }}) # Let the initial task tell us to not run (currently very blunt) - needs: plan - if: ${{ fromJson(needs.plan.outputs.val).releases != null && (needs.plan.outputs.publishing == 'true' || fromJson(needs.plan.outputs.val).ci.github.pr_run_mode == 'upload') }} + needs: + - plan + if: ${{ fromJson(needs.plan.outputs.val).ci.github.artifacts_matrix.include != null && (needs.plan.outputs.publishing == 'true' || fromJson(needs.plan.outputs.val).ci.github.pr_run_mode == 'upload') }} strategy: fail-fast: false # Target platforms/runners are computed by cargo-dist in create-release. @@ -92,6 +103,7 @@ jobs: runs-on: ${{ matrix.runner }} env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + BUILD_MANIFEST_NAME: target/distrib/${{ join(matrix.targets, '-') }}-dist-manifest.json steps: - uses: actions/checkout@v4 with: @@ -99,10 +111,20 @@ jobs: - uses: swatinem/rust-cache@v2 - name: Install cargo-dist run: ${{ matrix.install_dist }} + # Get the dist-manifest + - name: Fetch local artifacts + uses: actions/download-artifact@v4 + with: + pattern: artifacts-* + path: target/distrib/ + merge-multiple: true + - name: Install dependencies + run: | + ${{ matrix.packages_install }} - name: Build artifacts run: | # Actually do builds and make zips and whatnot - cargo dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json ${{ matrix.dist_args }} > dist-manifest.json + cargo dist build ${{ needs.plan.outputs.tag-flag }} --print=linkage --output-format=json ${{ matrix.dist_args }} > dist-manifest.json echo "cargo dist ran successfully" - id: cargo-dist name: Post-build @@ -111,81 +133,134 @@ jobs: # inconsistent syntax between shell and powershell. shell: bash run: | - # Parse out what we just built and upload it to the Github Release™ + # Parse out what we just built and upload it to scratch storage echo "paths<> "$GITHUB_OUTPUT" jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json >> "$GITHUB_OUTPUT" echo "EOF" >> "$GITHUB_OUTPUT" + + cp dist-manifest.json "$BUILD_MANIFEST_NAME" - name: "Upload artifacts" - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: - name: artifacts - path: ${{ steps.cargo-dist.outputs.paths }} + name: artifacts-build-local-${{ join(matrix.targets, '_') }} + path: | + ${{ steps.cargo-dist.outputs.paths }} + ${{ env.BUILD_MANIFEST_NAME }} # Build and package all the platform-agnostic(ish) things - upload-global-artifacts: - needs: [plan, upload-local-artifacts] + build-global-artifacts: + needs: + - plan + - build-local-artifacts runs-on: "ubuntu-20.04" env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + BUILD_MANIFEST_NAME: target/distrib/global-dist-manifest.json steps: - uses: actions/checkout@v4 with: submodules: recursive - name: Install cargo-dist - run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.3.1/cargo-dist-installer.sh | sh" + shell: bash + run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.12.0/cargo-dist-installer.sh | sh" # Get all the local artifacts for the global tasks to use (for e.g. checksums) - name: Fetch local artifacts - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: - name: artifacts + pattern: artifacts-* path: target/distrib/ + merge-multiple: true - id: cargo-dist shell: bash run: | cargo dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json "--artifacts=global" > dist-manifest.json echo "cargo dist ran successfully" - # Parse out what we just built and upload it to the Github Release™ + # Parse out what we just built and upload it to scratch storage echo "paths<> "$GITHUB_OUTPUT" jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json >> "$GITHUB_OUTPUT" echo "EOF" >> "$GITHUB_OUTPUT" + + cp dist-manifest.json "$BUILD_MANIFEST_NAME" - name: "Upload artifacts" - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: - name: artifacts - path: ${{ steps.cargo-dist.outputs.paths }} - - should-publish: + name: artifacts-build-global + path: | + ${{ steps.cargo-dist.outputs.paths }} + ${{ env.BUILD_MANIFEST_NAME }} + # Determines if we should publish/announce + host: needs: - plan - - upload-local-artifacts - - upload-global-artifacts - if: ${{ needs.plan.outputs.publishing == 'true' }} - runs-on: ubuntu-latest + - build-local-artifacts + - build-global-artifacts + # Only run if we're "publishing", and only if local and global didn't fail (skipped is fine) + if: ${{ always() && needs.plan.outputs.publishing == 'true' && (needs.build-global-artifacts.result == 'skipped' || needs.build-global-artifacts.result == 'success') && (needs.build-local-artifacts.result == 'skipped' || needs.build-local-artifacts.result == 'success') }} + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + runs-on: "ubuntu-20.04" + outputs: + val: ${{ steps.host.outputs.manifest }} steps: - - name: print tag - run: echo "ok we're publishing!" + - uses: actions/checkout@v4 + with: + submodules: recursive + - name: Install cargo-dist + run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.12.0/cargo-dist-installer.sh | sh" + # Fetch artifacts from scratch-storage + - name: Fetch artifacts + uses: actions/download-artifact@v4 + with: + pattern: artifacts-* + path: target/distrib/ + merge-multiple: true + # This is a harmless no-op for Github Releases, hosting for that happens in "announce" + - id: host + shell: bash + run: | + cargo dist host ${{ needs.plan.outputs.tag-flag }} --steps=upload --steps=release --output-format=json > dist-manifest.json + echo "artifacts uploaded and released successfully" + cat dist-manifest.json + echo "manifest=$(jq -c "." dist-manifest.json)" >> "$GITHUB_OUTPUT" + - name: "Upload dist-manifest.json" + uses: actions/upload-artifact@v4 + with: + # Overwrite the previous copy + name: artifacts-dist-manifest + path: dist-manifest.json - # Create a Github Release with all the results once everything is done, - publish-release: - needs: [plan, should-publish] - runs-on: ubuntu-latest + # Create a Github Release while uploading all files to it + announce: + needs: + - plan + - host + # use "always() && ..." to allow us to wait for all publish jobs while + # still allowing individual publish jobs to skip themselves (for prereleases). + # "host" however must run to completion, no skipping allowed! + if: ${{ always() && needs.host.result == 'success' }} + runs-on: "ubuntu-20.04" env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@v4 with: submodules: recursive - - name: "Download artifacts" - uses: actions/download-artifact@v3 + - name: "Download Github Artifacts" + uses: actions/download-artifact@v4 with: - name: artifacts + pattern: artifacts-* path: artifacts - - name: Create Release + merge-multiple: true + - name: Cleanup + run: | + # Remove the granular manifests + rm -f artifacts/*-dist-manifest.json + - name: Create Github Release uses: ncipollo/release-action@v1 with: tag: ${{ needs.plan.outputs.tag }} - name: ${{ fromJson(needs.plan.outputs.val).announcement_title }} - body: ${{ fromJson(needs.plan.outputs.val).announcement_github_body }} - prerelease: ${{ fromJson(needs.plan.outputs.val).announcement_is_prerelease }} + name: ${{ fromJson(needs.host.outputs.val).announcement_title }} + body: ${{ fromJson(needs.host.outputs.val).announcement_github_body }} + prerelease: ${{ fromJson(needs.host.outputs.val).announcement_is_prerelease }} artifacts: "artifacts/*" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6ba1044c7a..67e913455a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -595,7 +595,6 @@ when a new cargo-dist is available: ``` cargo dist init # from "cargo install cargo-dist" -cargo dist generate-ci # to update .github/workflows/release.yml ``` ### What to do if a Github release fails diff --git a/Cargo.toml b/Cargo.toml index 0730e061b4..bc9a80555d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,17 +17,19 @@ default-members = [ # Config for 'cargo dist' [workspace.metadata.dist] # The preferred cargo-dist version to use in CI (Cargo.toml SemVer syntax) -cargo-dist-version = "0.3.1" +cargo-dist-version = "0.12.0" # CI backends to support ci = ["github"] # The installers to generate for each app installers = ["shell", "powershell"] # Target platforms to build apps for (Rust target-triple syntax) -targets = ["x86_64-unknown-linux-gnu", "aarch64-apple-darwin", "x86_64-apple-darwin"] +targets = ["aarch64-apple-darwin", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu"] # Whether to consider the binaries in a package for distribution (defaults true) dist = false # Publish jobs to run in CI pr-run-mode = "plan" +# Whether to install an updater program +install-updater = false # Config for 'cargo release' [workspace.metadata.release] From ec0e7f9e160f13ddfa4defa8a24571f5a1f0191d Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Wed, 27 Mar 2024 21:24:29 +0200 Subject: [PATCH 647/942] needless declarations --- bindgen-cli/main.rs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/bindgen-cli/main.rs b/bindgen-cli/main.rs index 4b1bfad282..a3a011fcc7 100644 --- a/bindgen-cli/main.rs +++ b/bindgen-cli/main.rs @@ -1,10 +1,3 @@ -extern crate bindgen; -extern crate clap; -#[cfg(feature = "logging")] -extern crate env_logger; -#[cfg(feature = "logging")] -extern crate log; - use std::env; mod options; From 4f78afa67a574383123fe306b0927eb17bd40bf6 Mon Sep 17 00:00:00 2001 From: George Bateman Date: Sun, 24 Mar 2024 11:36:36 +0000 Subject: [PATCH 648/942] Compile time layout tests --- .../expectations/tests/16-byte-alignment.rs | 301 ++----- .../tests/16-byte-alignment_1_0.rs | 100 +-- .../tests/expectations/tests/accessors.rs | 300 ++----- .../expectations/tests/allowlist-file.rs | 116 +-- .../tests/allowlist-namespaces-basic.rs | 17 +- .../tests/allowlist-namespaces.rs | 44 +- .../expectations/tests/allowlist_item.rs | 25 +- .../allowlisted-item-references-no-hash.rs | 42 +- ...llowlisted-item-references-no-partialeq.rs | 42 +- .../allowlisted_item_references_no_copy.rs | 42 +- .../expectations/tests/annotation_hide.rs | 40 +- .../expectations/tests/anon-fields-prefix.rs | 149 +--- .../tests/expectations/tests/anon_enum.rs | 31 +- .../expectations/tests/anon_enum_trait.rs | 17 +- .../tests/anon_struct_in_union.rs | 89 +- .../tests/anon_struct_in_union_1_0.rs | 32 +- .../tests/expectations/tests/anon_union.rs | 38 +- .../expectations/tests/anon_union_1_0.rs | 12 +- .../tests/array-of-zero-sized-types.rs | 49 +- .../tests/attribute_warn_unused_result.rs | 12 +- ...rn_unused_result_no_attribute_detection.rs | 12 +- .../attribute_warn_unused_result_pre_1_27.rs | 17 +- .../tests/expectations/tests/auto.rs | 17 +- .../expectations/tests/base-to-derived.rs | 17 +- .../tests/bindgen-union-inside-namespace.rs | 16 +- .../tests/bitfield-32bit-overflow.rs | 17 +- .../expectations/tests/bitfield-enum-basic.rs | 17 +- .../expectations/tests/bitfield-large.rs | 38 +- .../expectations/tests/bitfield-linux-32.rs | 25 +- .../tests/bitfield-method-same-name.rs | 17 +- .../expectations/tests/bitfield_align.rs | 126 +-- .../expectations/tests/bitfield_align_2.rs | 17 +- .../tests/bitfield_large_overflow.rs | 17 +- .../tests/bitfield_method_mangling.rs | 21 +- .../tests/bitfield_pragma_packed.rs | 59 +- .../tests/blocklist-and-impl-debug.rs | 36 +- .../expectations/tests/blocklist-file.rs | 79 +- .../expectations/tests/blocklist-function.rs | 17 +- .../expectations/tests/blocklist-methods.rs | 17 +- .../expectations/tests/blocks-signature.rs | 49 +- .../tests/expectations/tests/blocks.rs | 49 +- .../tests/expectations/tests/bug-1529681.rs | 17 +- .../expectations/tests/c-empty-layout.rs | 17 +- .../tests/expectations/tests/c_naming.rs | 56 +- .../expectations/tests/call-conv-field.rs | 49 +- .../expectations/tests/canonical-types.rs | 155 +--- .../canonical_path_without_namespacing.rs | 17 +- .../tests/expectations/tests/char.rs | 91 +- .../tests/expectations/tests/class.rs | 227 ++--- .../tests/expectations/tests/class_1_0.rs | 227 ++--- .../tests/expectations/tests/class_nested.rs | 119 +-- .../expectations/tests/class_no_members.rs | 70 +- .../tests/expectations/tests/class_static.rs | 17 +- .../expectations/tests/class_static_const.rs | 13 +- .../tests/expectations/tests/class_use_as.rs | 52 +- .../expectations/tests/class_with_dtor.rs | 59 +- .../tests/class_with_inner_struct.rs | 378 +++------ .../tests/class_with_inner_struct_1_0.rs | 153 +--- .../expectations/tests/class_with_typedef.rs | 66 +- .../expectations/tests/comment-indent.rs | 95 +-- .../tests/expectations/tests/complex.rs | 113 +-- .../expectations/tests/const-const-mut-ptr.rs | 25 +- .../expectations/tests/const_array_typedef.rs | 25 +- .../tests/expectations/tests/const_bool.rs | 13 +- .../expectations/tests/const_enum_unnamed.rs | 17 +- .../tests/constified-enum-module-overflow.rs | 63 +- .../expectations/tests/constify-all-enums.rs | 27 +- .../tests/constify-module-enums-basic.rs | 27 +- .../tests/constify-module-enums-namespace.rs | 35 +- .../constify-module-enums-shadow-name.rs | 25 +- .../constify-module-enums-simple-alias.rs | 67 +- ...onstify-module-enums-simple-nonamespace.rs | 31 +- .../tests/constify-module-enums-types.rs | 129 +-- .../expectations/tests/constructor-tp.rs | 17 +- .../tests/expectations/tests/constructors.rs | 36 +- .../expectations/tests/constructors_1_33.rs | 12 +- .../tests/contains-vs-inherits-zero-sized.rs | 75 +- .../expectations/tests/convert-floats.rs | 59 +- .../expectations/tests/cpp-empty-layout.rs | 17 +- .../tests/expectations/tests/crtp.rs | 80 +- .../expectations/tests/ctypes-prefix-path.rs | 37 +- .../tests/default-template-parameter.rs | 27 +- .../expectations/tests/deleted-function.rs | 39 +- .../tests/derive-bitfield-method-same-name.rs | 14 +- .../tests/expectations/tests/derive-clone.rs | 11 +- .../expectations/tests/derive-clone_1_0.rs | 11 +- .../expectations/tests/derive-custom-cli.rs | 85 +- .../tests/derive-debug-bitfield-core.rs | 14 +- .../tests/derive-debug-bitfield.rs | 14 +- .../tests/derive-debug-function-pointer.rs | 16 +- .../tests/derive-debug-mangle-name.rs | 89 +- ...ive-debug-opaque-template-instantiation.rs | 14 +- .../expectations/tests/derive-debug-opaque.rs | 26 +- .../tests/derive-default-and-blocklist.rs | 36 +- .../tests/expectations/tests/derive-fn-ptr.rs | 50 +- .../tests/derive-hash-and-blocklist.rs | 36 +- .../tests/derive-hash-blocklisting.rs | 54 +- ...rive-hash-struct-with-anon-struct-float.rs | 62 +- .../derive-hash-struct-with-float-array.rs | 25 +- ...erive-hash-struct-with-incomplete-array.rs | 131 +-- .../tests/derive-hash-struct-with-pointer.rs | 110 +-- .../tests/derive-hash-template-inst-float.rs | 98 +-- .../tests/derive-partialeq-and-blocklist.rs | 36 +- .../tests/derive-partialeq-anonfield.rs | 38 +- .../tests/derive-partialeq-base.rs | 18 +- .../tests/derive-partialeq-bitfield.rs | 14 +- .../tests/derive-partialeq-core.rs | 14 +- .../tests/derive-partialeq-pointer.rs | 76 +- .../tests/derive-partialeq-union.rs | 49 +- .../tests/derive-partialeq-union_1_0.rs | 18 +- .../tests/disable-nested-struct-naming.rs | 267 ++---- .../tests/disable-untagged-union.rs | 31 +- .../expectations/tests/do-not-derive-copy.rs | 36 +- .../tests/expectations/tests/doggo-or-null.rs | 59 +- .../tests/duplicated-definition-count.rs | 17 +- .../duplicated-namespaces-definitions.rs | 56 +- .../tests/dynamic_loading_with_blocklist.rs | 21 +- .../tests/dynamic_loading_with_class.rs | 21 +- .../tests/enum-default-bitfield.rs | 25 +- .../expectations/tests/enum-default-consts.rs | 25 +- .../expectations/tests/enum-default-module.rs | 25 +- .../expectations/tests/enum-default-rust.rs | 25 +- .../expectations/tests/enum-no-debug-rust.rs | 25 +- .../tests/expectations/tests/enum.rs | 25 +- .../tests/enum_and_vtable_mangling.rs | 21 +- .../expectations/tests/explicit-padding.rs | 80 +- .../expectations/tests/extern-const-struct.rs | 14 +- .../tests/field-visibility-callback.rs | 33 +- .../expectations/tests/field-visibility.rs | 34 +- .../tests/expectations/tests/float16.rs | 56 +- .../tests/forward-declaration-autoptr.rs | 46 +- .../tests/forward_declared_complex_types.rs | 42 +- .../forward_declared_complex_types_1_0.rs | 26 +- .../tests/forward_declared_struct.rs | 42 +- .../expectations/tests/func_ptr_in_struct.rs | 25 +- .../tests/func_return_must_use.rs | 34 +- .../tests/gen-constructors-neg.rs | 17 +- .../expectations/tests/gen-constructors.rs | 17 +- .../expectations/tests/gen-destructors-neg.rs | 25 +- .../expectations/tests/gen-destructors.rs | 25 +- .../expectations/tests/generate-inline.rs | 17 +- .../tests/expectations/tests/i128.rs | 16 +- .../tests/incomplete-array-padding.rs | 25 +- ...from-template-instantiation-with-vtable.rs | 190 ++--- .../tests/inherit_multiple_interfaces.rs | 63 +- .../expectations/tests/inherit_typedef.rs | 34 +- .../expectations/tests/inline_namespace.rs | 25 +- .../tests/inline_namespace_conservative.rs | 25 +- .../tests/expectations/tests/inner_const.rs | 25 +- .../expectations/tests/inner_template_self.rs | 48 +- .../tests/expectations/tests/issue-1034.rs | 17 +- .../issue-1076-unnamed-bitfield-alignment.rs | 17 +- .../tests/issue-1118-using-forward-decl.rs | 96 +-- .../tests/issue-1197-pure-virtual-stuff.rs | 17 +- .../tests/issue-1216-variadic-member.rs | 25 +- .../tests/expectations/tests/issue-1281.rs | 75 +- .../tests/expectations/tests/issue-1285.rs | 62 +- .../tests/expectations/tests/issue-1291.rs | 42 +- .../tests/issue-1382-rust-primitive-types.rs | 103 +-- .../tests/expectations/tests/issue-1443.rs | 124 +-- .../tests/expectations/tests/issue-1454.rs | 27 +- .../tests/expectations/tests/issue-1498.rs | 121 +-- .../tests/expectations/tests/issue-1947.rs | 37 +- .../tests/issue-1977-larger-arrays.rs | 21 +- .../tests/expectations/tests/issue-1995.rs | 25 +- .../tests/expectations/tests/issue-2019.rs | 42 +- .../tests/expectations/tests/issue-2556.rs | 35 +- .../tests/expectations/tests/issue-2695.rs | 43 +- .../tests/expectations/tests/issue-372.rs | 46 +- .../tests/expectations/tests/issue-410.rs | 17 +- .../tests/expectations/tests/issue-447.rs | 42 +- .../tests/issue-537-repr-packed-n.rs | 44 +- .../tests/expectations/tests/issue-537.rs | 116 +-- ...ate-params-causing-layout-test-failures.rs | 38 +- .../tests/issue-573-layout-test-failures.rs | 48 +- .../issue-574-assertion-failure-in-codegen.rs | 48 +- ...issue-584-stylo-template-analysis-panic.rs | 68 +- .../tests/issue-639-typedef-anon-field.rs | 92 +- .../tests/issue-643-inner-struct.rs | 113 +-- .../issue-648-derive-debug-with-padding.rs | 32 +- .../tests/expectations/tests/issue-674-1.rs | 36 +- .../tests/expectations/tests/issue-674-2.rs | 74 +- .../tests/expectations/tests/issue-674-3.rs | 52 +- .../issue-691-template-parameter-virtual.rs | 59 +- .../tests/issue-739-pointer-wide-bitfield.rs | 17 +- .../tests/issue-769-bad-instantiation-test.rs | 54 +- .../tests/issue-801-opaque-sloppiness.rs | 34 +- ...07-opaque-types-methods-being-generated.rs | 100 +-- .../tests/expectations/tests/issue-816.rs | 17 +- ...26-generating-methods-when-asked-not-to.rs | 17 +- .../tests/expectations/tests/issue-834.rs | 13 +- .../tests/issue-888-enum-var-decl-jump.rs | 17 +- .../issue-944-derive-copy-and-blocklisting.rs | 27 +- .../tests/expectations/tests/issue-946.rs | 17 +- .../tests/expectations/tests/issue_311.rs | 38 +- .../expectations/tests/jsval_layout_opaque.rs | 234 ++---- .../tests/jsval_layout_opaque_1_0.rs | 91 +- .../tests/expectations/tests/layout.rs | 6 +- .../tests/expectations/tests/layout_align.rs | 96 +-- .../tests/expectations/tests/layout_arp.rs | 150 +--- .../tests/expectations/tests/layout_array.rs | 114 +-- .../tests/layout_array_too_long.rs | 82 +- .../tests/layout_cmdline_token.rs | 203 ++--- .../expectations/tests/layout_eth_conf.rs | 625 +++----------- .../expectations/tests/layout_eth_conf_1_0.rs | 625 +++----------- .../expectations/tests/layout_kni_mbuf.rs | 61 +- .../tests/layout_large_align_field.rs | 206 ++--- .../tests/expectations/tests/layout_mbuf.rs | 717 +++++----------- .../expectations/tests/layout_mbuf_1_0.rs | 237 ++---- .../constified-enum-module-overflow.rs | 42 +- .../libclang-9/ptr32-has-different-size.rs | 32 +- .../tests/libclang-9/struct_typedef_ns.rs | 68 +- .../tests/expectations/tests/long_double.rs | 14 +- .../expectations/tests/mangling-linux32.rs | 17 +- .../expectations/tests/mangling-linux64.rs | 17 +- .../expectations/tests/mangling-macos.rs | 17 +- .../expectations/tests/mangling-win32.rs | 17 +- .../expectations/tests/mangling-win64.rs | 17 +- .../expectations/tests/merge-extern-blocks.rs | 50 +- .../expectations/tests/method-mangling.rs | 17 +- .../expectations/tests/module-allowlisted.rs | 17 +- .../tests/expectations/tests/msvc-no-usr.rs | 21 +- .../multiple-inherit-empty-correct-layout.rs | 51 +- .../tests/expectations/tests/mutable.rs | 91 +- .../tests/expectations/tests/namespace.rs | 25 +- .../tests/expectations/tests/nested.rs | 98 +-- .../tests/expectations/tests/nested_vtable.rs | 51 +- .../tests/nested_within_namespace.rs | 77 +- .../tests/expectations/tests/no-comments.rs | 25 +- .../expectations/tests/no-derive-debug.rs | 31 +- .../expectations/tests/no-derive-default.rs | 31 +- .../expectations/tests/no-hash-allowlisted.rs | 25 +- .../expectations/tests/no-hash-opaque.rs | 17 +- .../tests/no-partialeq-allowlisted.rs | 25 +- .../expectations/tests/no-partialeq-opaque.rs | 17 +- .../tests/no-recursive-allowlisting.rs | 25 +- .../tests/expectations/tests/no-std.rs | 37 +- .../expectations/tests/no_copy_allowlisted.rs | 25 +- .../expectations/tests/no_copy_opaque.rs | 17 +- .../tests/no_debug_allowlisted.rs | 25 +- .../expectations/tests/no_debug_opaque.rs | 17 +- .../tests/no_default_allowlisted.rs | 25 +- .../expectations/tests/no_default_opaque.rs | 17 +- .../expectations/tests/no_size_t_is_usize.rs | 33 +- .../expectations/tests/non-type-params.rs | 58 +- .../expectations/tests/objc_interface_type.rs | 25 +- .../expectations/tests/only_bitfields.rs | 13 +- .../tests/opaque-template-inst-member-2.rs | 85 +- .../tests/opaque-template-inst-member.rs | 29 +- ...paque-template-instantiation-namespaced.rs | 153 +--- .../tests/opaque-template-instantiation.rs | 99 +-- .../expectations/tests/opaque-tracing.rs | 17 +- .../expectations/tests/opaque_in_struct.rs | 44 +- .../expectations/tests/opaque_pointer.rs | 65 +- .../expectations/tests/packed-bitfield.rs | 17 +- .../tests/packed-n-with-padding.rs | 43 +- .../tests/expectations/tests/packed-vtable.rs | 8 +- .../tests/expectations/tests/parm-union.rs | 17 +- .../partial-specialization-and-inheritance.rs | 17 +- .../tests/expectations/tests/private.rs | 137 +-- .../expectations/tests/private_fields.rs | 313 ++----- .../tests/ptr32-has-different-size.rs | 32 +- .../tests/expectations/tests/public-dtor.rs | 34 +- .../tests/redundant-packed-and-align.rs | 258 ++---- .../expectations/tests/ref_argument_array.rs | 17 +- .../tests/reparented_replacement.rs | 25 +- .../tests/expectations/tests/replace_use.rs | 46 +- .../tests/expectations/tests/repr-align.rs | 24 +- ...ame_struct_name_in_different_namespaces.rs | 35 +- .../tests/sentry-defined-multiple-times.rs | 400 +++------ .../expectations/tests/size_t_template.rs | 21 +- .../tests/expectations/tests/sorted_items.rs | 124 +-- .../expectations/tests/stdint_typedef.rs | 25 +- ...ruct_containing_forward_declared_struct.rs | 42 +- .../expectations/tests/struct_typedef.rs | 68 +- .../expectations/tests/struct_typedef_ns.rs | 68 +- .../tests/struct_with_anon_struct.rs | 62 +- .../tests/struct_with_anon_struct_array.rs | 105 +-- .../tests/struct_with_anon_struct_pointer.rs | 62 +- .../tests/struct_with_anon_union.rs | 62 +- .../tests/struct_with_anon_union_1_0.rs | 22 +- .../tests/struct_with_anon_unnamed_struct.rs | 54 +- .../tests/struct_with_anon_unnamed_union.rs | 54 +- .../struct_with_anon_unnamed_union_1_0.rs | 20 +- .../tests/struct_with_bitfields.rs | 25 +- .../tests/struct_with_derive_debug.rs | 40 +- .../tests/struct_with_large_array.rs | 10 +- .../expectations/tests/struct_with_nesting.rs | 178 ++-- .../tests/struct_with_nesting_1_0.rs | 70 +- .../expectations/tests/struct_with_packing.rs | 27 +- .../expectations/tests/struct_with_struct.rs | 62 +- .../tests/expectations/tests/template.rs | 792 +++++------------- ...mplate_instantiation_with_fn_local_type.rs | 93 +- .../test_mixed_header_and_header_contents.rs | 97 +-- .../test_multiple_header_calls_in_builder.rs | 97 +-- .../tests/expectations/tests/timex.rs | 52 +- .../tests/expectations/tests/transform-op.rs | 8 +- ...type-referenced-by-allowlisted-function.rs | 27 +- .../tests/type_alias_template_specialized.rs | 52 +- .../tests/typedef-pointer-overlap.rs | 77 +- .../tests/expectations/tests/typeref.rs | 132 +-- .../tests/expectations/tests/typeref_1_0.rs | 53 +- .../tests/expectations/tests/underscore.rs | 25 +- .../tests/expectations/tests/union-align.rs | 28 +- .../tests/expectations/tests/union-in-ns.rs | 25 +- .../expectations/tests/union-in-ns_1_0.rs | 14 +- .../expectations/tests/union_bitfield.rs | 30 +- .../expectations/tests/union_bitfield_1_0.rs | 22 +- .../tests/expectations/tests/union_dtor.rs | 35 +- .../expectations/tests/union_dtor_1_0.rs | 12 +- .../tests/expectations/tests/union_fields.rs | 48 +- .../expectations/tests/union_fields_1_0.rs | 19 +- .../tests/union_with_anon_struct.rs | 62 +- .../tests/union_with_anon_struct_1_0.rs | 22 +- .../tests/union_with_anon_struct_bitfield.rs | 44 +- .../union_with_anon_struct_bitfield_1_0.rs | 18 +- .../tests/union_with_anon_union.rs | 62 +- .../tests/union_with_anon_union_1_0.rs | 22 +- .../tests/union_with_anon_unnamed_struct.rs | 100 +-- .../union_with_anon_unnamed_struct_1_0.rs | 46 +- .../tests/union_with_anon_unnamed_union.rs | 62 +- .../union_with_anon_unnamed_union_1_0.rs | 22 +- .../tests/union_with_big_member.rs | 105 +-- .../tests/union_with_big_member_1_0.rs | 32 +- .../expectations/tests/union_with_nesting.rs | 142 +--- .../tests/union_with_nesting_1_0.rs | 54 +- .../tests/union_with_non_copy_member.rs | 165 +--- .../tests/expectations/tests/unknown_attr.rs | 49 +- .../expectations/tests/unsorted-items.rs | 62 +- .../tests/expectations/tests/use-core.rs | 72 +- .../tests/expectations/tests/use-core_1_0.rs | 30 +- .../tests/expectations/tests/var-tracing.rs | 42 +- .../expectations/tests/variadic-method.rs | 17 +- .../tests/expectations/tests/vector.rs | 25 +- .../tests/expectations/tests/virtual_dtor.rs | 17 +- .../expectations/tests/virtual_interface.rs | 72 +- .../expectations/tests/virtual_overloaded.rs | 13 +- .../tests/vtable_recursive_sig.rs | 34 +- .../tests/wasm-constructor-returns.rs | 17 +- .../expectations/tests/weird_bitfields.rs | 152 +--- .../expectations/tests/what_is_going_on.rs | 17 +- .../tests/expectations/tests/win32-dtors.rs | 56 +- .../expectations/tests/win32-thiscall_1_0.rs | 12 +- .../expectations/tests/win32-thiscall_1_73.rs | 12 +- .../tests/win32-thiscall_nightly.rs | 17 +- .../tests/zero-size-array-align.rs | 41 +- .../expectations/tests/zero-sized-array.rs | 156 ++-- bindgen/codegen/mod.rs | 149 ++-- bindgen/features.rs | 1 + 349 files changed, 5538 insertions(+), 16090 deletions(-) diff --git a/bindgen-tests/tests/expectations/tests/16-byte-alignment.rs b/bindgen-tests/tests/expectations/tests/16-byte-alignment.rs index b93cae0465..8eb78eaf6c 100644 --- a/bindgen-tests/tests/expectations/tests/16-byte-alignment.rs +++ b/bindgen-tests/tests/expectations/tests/16-byte-alignment.rs @@ -18,66 +18,33 @@ pub struct rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 { pub dport: u16, pub sport: u16, } -#[test] -fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dport) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(dport), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).sport) as usize - ptr as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(sport), - ), - ); -} -#[test] -fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(rte_ipv4_tuple__bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(rte_ipv4_tuple__bindgen_ty_1)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).sctp_tag) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple__bindgen_ty_1), - "::", - stringify!(sctp_tag), - ), - ); -} +const _: () = { + [ + "Size of rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1", + ][::std::mem::align_of::() - 2usize]; + [ + "Offset of field: rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1::dport", + ][::std::mem::offset_of!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1, dport) + - 0usize]; + [ + "Offset of field: rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1::sport", + ][::std::mem::offset_of!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1, sport) + - 2usize]; +}; +const _: () = { + [ + "Size of rte_ipv4_tuple__bindgen_ty_1", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of rte_ipv4_tuple__bindgen_ty_1", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: rte_ipv4_tuple__bindgen_ty_1::sctp_tag", + ][::std::mem::offset_of!(rte_ipv4_tuple__bindgen_ty_1, sctp_tag) - 0usize]; +}; impl Default for rte_ipv4_tuple__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -87,41 +54,16 @@ impl Default for rte_ipv4_tuple__bindgen_ty_1 { } } } -#[test] -fn bindgen_test_layout_rte_ipv4_tuple() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 12usize, - concat!("Size of: ", stringify!(rte_ipv4_tuple)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(rte_ipv4_tuple)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).src_addr) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple), - "::", - stringify!(src_addr), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dst_addr) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple), - "::", - stringify!(dst_addr), - ), - ); -} +const _: () = { + ["Size of rte_ipv4_tuple"][::std::mem::size_of::() - 12usize]; + ["Alignment of rte_ipv4_tuple"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: rte_ipv4_tuple::src_addr", + ][::std::mem::offset_of!(rte_ipv4_tuple, src_addr) - 0usize]; + [ + "Offset of field: rte_ipv4_tuple::dst_addr", + ][::std::mem::offset_of!(rte_ipv4_tuple, dst_addr) - 4usize]; +}; impl Default for rte_ipv4_tuple { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -150,66 +92,33 @@ pub struct rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 { pub dport: u16, pub sport: u16, } -#[test] -fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dport) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(dport), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).sport) as usize - ptr as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(sport), - ), - ); -} -#[test] -fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(rte_ipv6_tuple__bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(rte_ipv6_tuple__bindgen_ty_1)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).sctp_tag) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple__bindgen_ty_1), - "::", - stringify!(sctp_tag), - ), - ); -} +const _: () = { + [ + "Size of rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1", + ][::std::mem::align_of::() - 2usize]; + [ + "Offset of field: rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1::dport", + ][::std::mem::offset_of!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1, dport) + - 0usize]; + [ + "Offset of field: rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1::sport", + ][::std::mem::offset_of!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1, sport) + - 2usize]; +}; +const _: () = { + [ + "Size of rte_ipv6_tuple__bindgen_ty_1", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of rte_ipv6_tuple__bindgen_ty_1", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: rte_ipv6_tuple__bindgen_ty_1::sctp_tag", + ][::std::mem::offset_of!(rte_ipv6_tuple__bindgen_ty_1, sctp_tag) - 0usize]; +}; impl Default for rte_ipv6_tuple__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -219,41 +128,16 @@ impl Default for rte_ipv6_tuple__bindgen_ty_1 { } } } -#[test] -fn bindgen_test_layout_rte_ipv6_tuple() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 36usize, - concat!("Size of: ", stringify!(rte_ipv6_tuple)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(rte_ipv6_tuple)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).src_addr) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple), - "::", - stringify!(src_addr), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dst_addr) as usize - ptr as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple), - "::", - stringify!(dst_addr), - ), - ); -} +const _: () = { + ["Size of rte_ipv6_tuple"][::std::mem::size_of::() - 36usize]; + ["Alignment of rte_ipv6_tuple"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: rte_ipv6_tuple::src_addr", + ][::std::mem::offset_of!(rte_ipv6_tuple, src_addr) - 0usize]; + [ + "Offset of field: rte_ipv6_tuple::dst_addr", + ][::std::mem::offset_of!(rte_ipv6_tuple, dst_addr) - 16usize]; +}; impl Default for rte_ipv6_tuple { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -270,31 +154,18 @@ pub union rte_thash_tuple { pub v4: rte_ipv4_tuple, pub v6: rte_ipv6_tuple, } -#[test] -fn bindgen_test_layout_rte_thash_tuple() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 48usize, - concat!("Size of: ", stringify!(rte_thash_tuple)), - ); - assert_eq!( - ::std::mem::align_of::(), - 16usize, - concat!("Alignment of ", stringify!(rte_thash_tuple)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).v4) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(rte_thash_tuple), "::", stringify!(v4)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).v6) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(rte_thash_tuple), "::", stringify!(v6)), - ); -} +const _: () = { + ["Size of rte_thash_tuple"][::std::mem::size_of::() - 48usize]; + [ + "Alignment of rte_thash_tuple", + ][::std::mem::align_of::() - 16usize]; + [ + "Offset of field: rte_thash_tuple::v4", + ][::std::mem::offset_of!(rte_thash_tuple, v4) - 0usize]; + [ + "Offset of field: rte_thash_tuple::v6", + ][::std::mem::offset_of!(rte_thash_tuple, v6) - 0usize]; +}; impl Default for rte_thash_tuple { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/16-byte-alignment_1_0.rs b/bindgen-tests/tests/expectations/tests/16-byte-alignment_1_0.rs index a7d7518a34..06d008982c 100644 --- a/bindgen-tests/tests/expectations/tests/16-byte-alignment_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/16-byte-alignment_1_0.rs @@ -71,32 +71,22 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1() { assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1)), + "Size of rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 2usize, - concat!("Alignment of ", stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1)), + "Alignment of rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).dport) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(dport), - ), + "Offset of field: rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1::dport", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).sport) as usize - ptr as usize }, 2usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(sport), - ), + "Offset of field: rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1::sport", ); } impl Clone for rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 { @@ -111,22 +101,17 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1() { assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(rte_ipv4_tuple__bindgen_ty_1)), + "Size of rte_ipv4_tuple__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_ipv4_tuple__bindgen_ty_1)), + "Alignment of rte_ipv4_tuple__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).sctp_tag) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple__bindgen_ty_1), - "::", - stringify!(sctp_tag), - ), + "Offset of field: rte_ipv4_tuple__bindgen_ty_1::sctp_tag", ); } impl Clone for rte_ipv4_tuple__bindgen_ty_1 { @@ -141,32 +126,22 @@ fn bindgen_test_layout_rte_ipv4_tuple() { assert_eq!( ::std::mem::size_of::(), 12usize, - concat!("Size of: ", stringify!(rte_ipv4_tuple)), + "Size of rte_ipv4_tuple", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_ipv4_tuple)), + "Alignment of rte_ipv4_tuple", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).src_addr) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple), - "::", - stringify!(src_addr), - ), + "Offset of field: rte_ipv4_tuple::src_addr", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).dst_addr) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv4_tuple), - "::", - stringify!(dst_addr), - ), + "Offset of field: rte_ipv4_tuple::dst_addr", ); } impl Clone for rte_ipv4_tuple { @@ -203,32 +178,22 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1() { assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1)), + "Size of rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 2usize, - concat!("Alignment of ", stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1)), + "Alignment of rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).dport) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(dport), - ), + "Offset of field: rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1::dport", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).sport) as usize - ptr as usize }, 2usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(sport), - ), + "Offset of field: rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1::sport", ); } impl Clone for rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 { @@ -243,22 +208,17 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1() { assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(rte_ipv6_tuple__bindgen_ty_1)), + "Size of rte_ipv6_tuple__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_ipv6_tuple__bindgen_ty_1)), + "Alignment of rte_ipv6_tuple__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).sctp_tag) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple__bindgen_ty_1), - "::", - stringify!(sctp_tag), - ), + "Offset of field: rte_ipv6_tuple__bindgen_ty_1::sctp_tag", ); } impl Clone for rte_ipv6_tuple__bindgen_ty_1 { @@ -273,32 +233,22 @@ fn bindgen_test_layout_rte_ipv6_tuple() { assert_eq!( ::std::mem::size_of::(), 36usize, - concat!("Size of: ", stringify!(rte_ipv6_tuple)), + "Size of rte_ipv6_tuple", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_ipv6_tuple)), + "Alignment of rte_ipv6_tuple", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).src_addr) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple), - "::", - stringify!(src_addr), - ), + "Offset of field: rte_ipv6_tuple::src_addr", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).dst_addr) as usize - ptr as usize }, 16usize, - concat!( - "Offset of field: ", - stringify!(rte_ipv6_tuple), - "::", - stringify!(dst_addr), - ), + "Offset of field: rte_ipv6_tuple::dst_addr", ); } impl Clone for rte_ipv6_tuple { @@ -320,17 +270,17 @@ fn bindgen_test_layout_rte_thash_tuple() { assert_eq!( ::std::mem::size_of::(), 48usize, - concat!("Size of: ", stringify!(rte_thash_tuple)), + "Size of rte_thash_tuple", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).v4) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_thash_tuple), "::", stringify!(v4)), + "Offset of field: rte_thash_tuple::v4", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).v6) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_thash_tuple), "::", stringify!(v6)), + "Offset of field: rte_thash_tuple::v6", ); } impl Clone for rte_thash_tuple { diff --git a/bindgen-tests/tests/expectations/tests/accessors.rs b/bindgen-tests/tests/expectations/tests/accessors.rs index 9aa33d65b5..0bd4d8169d 100644 --- a/bindgen-tests/tests/expectations/tests/accessors.rs +++ b/bindgen-tests/tests/expectations/tests/accessors.rs @@ -10,63 +10,22 @@ pub struct SomeAccessors { ///
pub mImmutableAccessor: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_SomeAccessors() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(SomeAccessors)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(SomeAccessors)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mNoAccessor) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(SomeAccessors), - "::", - stringify!(mNoAccessor), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mBothAccessors) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(SomeAccessors), - "::", - stringify!(mBothAccessors), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mUnsafeAccessors) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(SomeAccessors), - "::", - stringify!(mUnsafeAccessors), - ), - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mImmutableAccessor) as usize - ptr as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(SomeAccessors), - "::", - stringify!(mImmutableAccessor), - ), - ); -} +const _: () = { + ["Size of SomeAccessors"][::std::mem::size_of::() - 16usize]; + ["Alignment of SomeAccessors"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: SomeAccessors::mNoAccessor", + ][::std::mem::offset_of!(SomeAccessors, mNoAccessor) - 0usize]; + [ + "Offset of field: SomeAccessors::mBothAccessors", + ][::std::mem::offset_of!(SomeAccessors, mBothAccessors) - 4usize]; + [ + "Offset of field: SomeAccessors::mUnsafeAccessors", + ][::std::mem::offset_of!(SomeAccessors, mUnsafeAccessors) - 8usize]; + [ + "Offset of field: SomeAccessors::mImmutableAccessor", + ][::std::mem::offset_of!(SomeAccessors, mImmutableAccessor) - 12usize]; +}; impl SomeAccessors { #[inline] pub fn get_mBothAccessors(&self) -> &::std::os::raw::c_int { @@ -96,43 +55,16 @@ pub struct AllAccessors { pub mBothAccessors: ::std::os::raw::c_int, pub mAlsoBothAccessors: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_AllAccessors() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(AllAccessors)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(AllAccessors)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mBothAccessors) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AllAccessors), - "::", - stringify!(mBothAccessors), - ), - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mAlsoBothAccessors) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(AllAccessors), - "::", - stringify!(mAlsoBothAccessors), - ), - ); -} +const _: () = { + ["Size of AllAccessors"][::std::mem::size_of::() - 8usize]; + ["Alignment of AllAccessors"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: AllAccessors::mBothAccessors", + ][::std::mem::offset_of!(AllAccessors, mBothAccessors) - 0usize]; + [ + "Offset of field: AllAccessors::mAlsoBothAccessors", + ][::std::mem::offset_of!(AllAccessors, mAlsoBothAccessors) - 4usize]; +}; impl AllAccessors { #[inline] pub fn get_mBothAccessors(&self) -> &::std::os::raw::c_int { @@ -158,43 +90,18 @@ pub struct AllUnsafeAccessors { pub mBothAccessors: ::std::os::raw::c_int, pub mAlsoBothAccessors: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_AllUnsafeAccessors() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(AllUnsafeAccessors)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(AllUnsafeAccessors)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mBothAccessors) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(AllUnsafeAccessors), - "::", - stringify!(mBothAccessors), - ), - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mAlsoBothAccessors) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(AllUnsafeAccessors), - "::", - stringify!(mAlsoBothAccessors), - ), - ); -} +const _: () = { + ["Size of AllUnsafeAccessors"][::std::mem::size_of::() - 8usize]; + [ + "Alignment of AllUnsafeAccessors", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: AllUnsafeAccessors::mBothAccessors", + ][::std::mem::offset_of!(AllUnsafeAccessors, mBothAccessors) - 0usize]; + [ + "Offset of field: AllUnsafeAccessors::mAlsoBothAccessors", + ][::std::mem::offset_of!(AllUnsafeAccessors, mAlsoBothAccessors) - 4usize]; +}; impl AllUnsafeAccessors { #[inline] pub unsafe fn get_mBothAccessors(&self) -> &::std::os::raw::c_int { @@ -225,63 +132,26 @@ pub struct ContradictAccessors { ///
pub mImmutableAccessor: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_ContradictAccessors() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(ContradictAccessors)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(ContradictAccessors)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mBothAccessors) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContradictAccessors), - "::", - stringify!(mBothAccessors), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mNoAccessors) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(ContradictAccessors), - "::", - stringify!(mNoAccessors), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mUnsafeAccessors) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(ContradictAccessors), - "::", - stringify!(mUnsafeAccessors), - ), - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mImmutableAccessor) as usize - ptr as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(ContradictAccessors), - "::", - stringify!(mImmutableAccessor), - ), - ); -} +const _: () = { + [ + "Size of ContradictAccessors", + ][::std::mem::size_of::() - 16usize]; + [ + "Alignment of ContradictAccessors", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: ContradictAccessors::mBothAccessors", + ][::std::mem::offset_of!(ContradictAccessors, mBothAccessors) - 0usize]; + [ + "Offset of field: ContradictAccessors::mNoAccessors", + ][::std::mem::offset_of!(ContradictAccessors, mNoAccessors) - 4usize]; + [ + "Offset of field: ContradictAccessors::mUnsafeAccessors", + ][::std::mem::offset_of!(ContradictAccessors, mUnsafeAccessors) - 8usize]; + [ + "Offset of field: ContradictAccessors::mImmutableAccessor", + ][::std::mem::offset_of!(ContradictAccessors, mImmutableAccessor) - 12usize]; +}; impl ContradictAccessors { #[inline] pub fn get_mBothAccessors(&self) -> &::std::os::raw::c_int { @@ -310,26 +180,13 @@ impl ContradictAccessors { pub struct Replaced { pub mAccessor: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_Replaced() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Replaced)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Replaced)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mAccessor) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Replaced), "::", stringify!(mAccessor)), - ); -} +const _: () = { + ["Size of Replaced"][::std::mem::size_of::() - 4usize]; + ["Alignment of Replaced"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: Replaced::mAccessor", + ][::std::mem::offset_of!(Replaced, mAccessor) - 0usize]; +}; impl Replaced { #[inline] pub fn get_mAccessor(&self) -> &::std::os::raw::c_int { @@ -346,26 +203,13 @@ impl Replaced { pub struct Wrapper { pub mReplaced: Replaced, } -#[test] -fn bindgen_test_layout_Wrapper() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Wrapper)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Wrapper)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mReplaced) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Wrapper), "::", stringify!(mReplaced)), - ); -} +const _: () = { + ["Size of Wrapper"][::std::mem::size_of::() - 4usize]; + ["Alignment of Wrapper"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: Wrapper::mReplaced", + ][::std::mem::offset_of!(Wrapper, mReplaced) - 0usize]; +}; impl Wrapper { #[inline] pub fn get_mReplaced(&self) -> &Replaced { diff --git a/bindgen-tests/tests/expectations/tests/allowlist-file.rs b/bindgen-tests/tests/expectations/tests/allowlist-file.rs index ce591f59d3..cb2aa01c59 100644 --- a/bindgen-tests/tests/expectations/tests/allowlist-file.rs +++ b/bindgen-tests/tests/expectations/tests/allowlist-file.rs @@ -12,19 +12,10 @@ extern "C" { pub struct someClass { pub _address: u8, } -#[test] -fn bindgen_test_layout_someClass() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(someClass)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(someClass)), - ); -} +const _: () = { + ["Size of someClass"][::std::mem::size_of::() - 1usize]; + ["Alignment of someClass"][::std::mem::align_of::() - 1usize]; +}; extern "C" { #[link_name = "\u{1}_ZN9someClass16somePublicMethodEi"] pub fn someClass_somePublicMethod(this: *mut someClass, foo: ::std::os::raw::c_int); @@ -47,31 +38,17 @@ extern "C" { pub struct StructWithAllowlistedDefinition { pub other: *mut StructWithAllowlistedFwdDecl, } -#[test] -fn bindgen_test_layout_StructWithAllowlistedDefinition() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(StructWithAllowlistedDefinition)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(StructWithAllowlistedDefinition)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).other) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(StructWithAllowlistedDefinition), - "::", - stringify!(other), - ), - ); -} +const _: () = { + [ + "Size of StructWithAllowlistedDefinition", + ][::std::mem::size_of::() - 8usize]; + [ + "Alignment of StructWithAllowlistedDefinition", + ][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: StructWithAllowlistedDefinition::other", + ][::std::mem::offset_of!(StructWithAllowlistedDefinition, other) - 0usize]; +}; impl Default for StructWithAllowlistedDefinition { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -86,53 +63,26 @@ impl Default for StructWithAllowlistedDefinition { pub struct StructWithAllowlistedFwdDecl { pub b: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_StructWithAllowlistedFwdDecl() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(StructWithAllowlistedFwdDecl)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(StructWithAllowlistedFwdDecl)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(StructWithAllowlistedFwdDecl), - "::", - stringify!(b), - ), - ); -} +const _: () = { + [ + "Size of StructWithAllowlistedFwdDecl", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of StructWithAllowlistedFwdDecl", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: StructWithAllowlistedFwdDecl::b", + ][::std::mem::offset_of!(StructWithAllowlistedFwdDecl, b) - 0usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct AllowlistMe { pub foo: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_AllowlistMe() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(AllowlistMe)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(AllowlistMe)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(AllowlistMe), "::", stringify!(foo)), - ); -} +const _: () = { + ["Size of AllowlistMe"][::std::mem::size_of::() - 4usize]; + ["Alignment of AllowlistMe"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: AllowlistMe::foo", + ][::std::mem::offset_of!(AllowlistMe, foo) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/allowlist-namespaces-basic.rs b/bindgen-tests/tests/expectations/tests/allowlist-namespaces-basic.rs index 726a596953..be6fac2117 100644 --- a/bindgen-tests/tests/expectations/tests/allowlist-namespaces-basic.rs +++ b/bindgen-tests/tests/expectations/tests/allowlist-namespaces-basic.rs @@ -14,19 +14,10 @@ pub mod root { pub struct Helper { pub _address: u8, } - #[test] - fn bindgen_test_layout_Helper() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Helper)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Helper)), - ); - } + const _: () = { + ["Size of Helper"][::std::mem::size_of::() - 1usize]; + ["Alignment of Helper"][::std::mem::align_of::() - 1usize]; + }; } } } diff --git a/bindgen-tests/tests/expectations/tests/allowlist-namespaces.rs b/bindgen-tests/tests/expectations/tests/allowlist-namespaces.rs index 1445bf73a2..1c7078504f 100644 --- a/bindgen-tests/tests/expectations/tests/allowlist-namespaces.rs +++ b/bindgen-tests/tests/expectations/tests/allowlist-namespaces.rs @@ -14,44 +14,22 @@ pub mod root { pub struct Helper { pub _address: u8, } - #[test] - fn bindgen_test_layout_Helper() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Helper)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Helper)), - ); - } + const _: () = { + ["Size of Helper"][::std::mem::size_of::() - 1usize]; + ["Alignment of Helper"][::std::mem::align_of::() - 1usize]; + }; } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Test { pub helper: root::outer::inner::Helper, } - #[test] - fn bindgen_test_layout_Test() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Test)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Test)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).helper) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(helper)), - ); - } + const _: () = { + ["Size of Test"][::std::mem::size_of::() - 1usize]; + ["Alignment of Test"][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: Test::helper", + ][::std::mem::offset_of!(Test, helper) - 0usize]; + }; } } diff --git a/bindgen-tests/tests/expectations/tests/allowlist_item.rs b/bindgen-tests/tests/expectations/tests/allowlist_item.rs index eaca8aec22..f816f5170b 100644 --- a/bindgen-tests/tests/expectations/tests/allowlist_item.rs +++ b/bindgen-tests/tests/expectations/tests/allowlist_item.rs @@ -5,26 +5,11 @@ pub const FooDefault: u32 = 0; pub struct Foo { pub field: ::std::os::raw::c_int, } -#[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::(), - 4usize, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Foo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).field) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(field)), - ); -} +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 4usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Foo::field"][::std::mem::offset_of!(Foo, field) - 0usize]; +}; extern "C" { pub fn FooNew(value: ::std::os::raw::c_int) -> Foo; } diff --git a/bindgen-tests/tests/expectations/tests/allowlisted-item-references-no-hash.rs b/bindgen-tests/tests/expectations/tests/allowlisted-item-references-no-hash.rs index b9a3fb5c16..ce1d463f57 100644 --- a/bindgen-tests/tests/expectations/tests/allowlisted-item-references-no-hash.rs +++ b/bindgen-tests/tests/expectations/tests/allowlisted-item-references-no-hash.rs @@ -4,41 +4,17 @@ pub struct NoHash { pub _address: u8, } -#[test] -fn bindgen_test_layout_NoHash() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(NoHash)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(NoHash)), - ); -} +const _: () = { + ["Size of NoHash"][::std::mem::size_of::() - 1usize]; + ["Alignment of NoHash"][::std::mem::align_of::() - 1usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct AllowlistMe { pub a: NoHash, } -#[test] -fn bindgen_test_layout_AllowlistMe() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(AllowlistMe)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(AllowlistMe)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(AllowlistMe), "::", stringify!(a)), - ); -} +const _: () = { + ["Size of AllowlistMe"][::std::mem::size_of::() - 1usize]; + ["Alignment of AllowlistMe"][::std::mem::align_of::() - 1usize]; + ["Offset of field: AllowlistMe::a"][::std::mem::offset_of!(AllowlistMe, a) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/allowlisted-item-references-no-partialeq.rs b/bindgen-tests/tests/expectations/tests/allowlisted-item-references-no-partialeq.rs index 1e763880e1..2b699f61db 100644 --- a/bindgen-tests/tests/expectations/tests/allowlisted-item-references-no-partialeq.rs +++ b/bindgen-tests/tests/expectations/tests/allowlisted-item-references-no-partialeq.rs @@ -4,41 +4,17 @@ pub struct NoPartialEq { pub _address: u8, } -#[test] -fn bindgen_test_layout_NoPartialEq() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(NoPartialEq)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(NoPartialEq)), - ); -} +const _: () = { + ["Size of NoPartialEq"][::std::mem::size_of::() - 1usize]; + ["Alignment of NoPartialEq"][::std::mem::align_of::() - 1usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct AllowlistMe { pub a: NoPartialEq, } -#[test] -fn bindgen_test_layout_AllowlistMe() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(AllowlistMe)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(AllowlistMe)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(AllowlistMe), "::", stringify!(a)), - ); -} +const _: () = { + ["Size of AllowlistMe"][::std::mem::size_of::() - 1usize]; + ["Alignment of AllowlistMe"][::std::mem::align_of::() - 1usize]; + ["Offset of field: AllowlistMe::a"][::std::mem::offset_of!(AllowlistMe, a) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/allowlisted_item_references_no_copy.rs b/bindgen-tests/tests/expectations/tests/allowlisted_item_references_no_copy.rs index 0058371966..cbcce1ef44 100644 --- a/bindgen-tests/tests/expectations/tests/allowlisted_item_references_no_copy.rs +++ b/bindgen-tests/tests/expectations/tests/allowlisted_item_references_no_copy.rs @@ -4,41 +4,17 @@ pub struct NoCopy { pub _address: u8, } -#[test] -fn bindgen_test_layout_NoCopy() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(NoCopy)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(NoCopy)), - ); -} +const _: () = { + ["Size of NoCopy"][::std::mem::size_of::() - 1usize]; + ["Alignment of NoCopy"][::std::mem::align_of::() - 1usize]; +}; #[repr(C)] #[derive(Debug, Default)] pub struct AllowlistMe { pub a: NoCopy, } -#[test] -fn bindgen_test_layout_AllowlistMe() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(AllowlistMe)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(AllowlistMe)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(AllowlistMe), "::", stringify!(a)), - ); -} +const _: () = { + ["Size of AllowlistMe"][::std::mem::size_of::() - 1usize]; + ["Alignment of AllowlistMe"][::std::mem::align_of::() - 1usize]; + ["Offset of field: AllowlistMe::a"][::std::mem::offset_of!(AllowlistMe, a) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/annotation_hide.rs b/bindgen-tests/tests/expectations/tests/annotation_hide.rs index 1ec81ba6e2..0343c92272 100644 --- a/bindgen-tests/tests/expectations/tests/annotation_hide.rs +++ b/bindgen-tests/tests/expectations/tests/annotation_hide.rs @@ -6,37 +6,19 @@ pub struct D { pub _bindgen_opaque_blob: u32, } -#[test] -fn bindgen_test_layout_D() { - assert_eq!(::std::mem::size_of::(), 4usize, concat!("Size of: ", stringify!(D))); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(D)), - ); -} +const _: () = { + ["Size of D"][::std::mem::size_of::() - 4usize]; + ["Alignment of D"][::std::mem::align_of::() - 4usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct NotAnnotated { pub f: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_NotAnnotated() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(NotAnnotated)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(NotAnnotated)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(NotAnnotated), "::", stringify!(f)), - ); -} +const _: () = { + ["Size of NotAnnotated"][::std::mem::size_of::() - 4usize]; + ["Alignment of NotAnnotated"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: NotAnnotated::f", + ][::std::mem::offset_of!(NotAnnotated, f) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/anon-fields-prefix.rs b/bindgen-tests/tests/expectations/tests/anon-fields-prefix.rs index 813bde9e55..c408a08b0c 100644 --- a/bindgen-tests/tests/expectations/tests/anon-fields-prefix.rs +++ b/bindgen-tests/tests/expectations/tests/anon-fields-prefix.rs @@ -13,51 +13,23 @@ pub struct color__bindgen_ty_1 { pub g: ::std::os::raw::c_uchar, pub b: ::std::os::raw::c_uchar, } -#[test] -fn bindgen_test_layout_color__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 3usize, - concat!("Size of: ", stringify!(color__bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(color__bindgen_ty_1)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).r) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(color__bindgen_ty_1), - "::", - stringify!(r), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).g) as usize - ptr as usize }, - 1usize, - concat!( - "Offset of field: ", - stringify!(color__bindgen_ty_1), - "::", - stringify!(g), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(color__bindgen_ty_1), - "::", - stringify!(b), - ), - ); -} +const _: () = { + [ + "Size of color__bindgen_ty_1", + ][::std::mem::size_of::() - 3usize]; + [ + "Alignment of color__bindgen_ty_1", + ][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: color__bindgen_ty_1::r", + ][::std::mem::offset_of!(color__bindgen_ty_1, r) - 0usize]; + [ + "Offset of field: color__bindgen_ty_1::g", + ][::std::mem::offset_of!(color__bindgen_ty_1, g) - 1usize]; + [ + "Offset of field: color__bindgen_ty_1::b", + ][::std::mem::offset_of!(color__bindgen_ty_1, b) - 2usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct color__bindgen_ty_2 { @@ -65,71 +37,28 @@ pub struct color__bindgen_ty_2 { pub u: ::std::os::raw::c_uchar, pub v: ::std::os::raw::c_uchar, } -#[test] -fn bindgen_test_layout_color__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 3usize, - concat!("Size of: ", stringify!(color__bindgen_ty_2)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(color__bindgen_ty_2)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(color__bindgen_ty_2), - "::", - stringify!(y), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize }, - 1usize, - concat!( - "Offset of field: ", - stringify!(color__bindgen_ty_2), - "::", - stringify!(u), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).v) as usize - ptr as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(color__bindgen_ty_2), - "::", - stringify!(v), - ), - ); -} -#[test] -fn bindgen_test_layout_color() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 3usize, - concat!("Size of: ", stringify!(color)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(color)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).v3) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(color), "::", stringify!(v3)), - ); -} +const _: () = { + [ + "Size of color__bindgen_ty_2", + ][::std::mem::size_of::() - 3usize]; + [ + "Alignment of color__bindgen_ty_2", + ][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: color__bindgen_ty_2::y", + ][::std::mem::offset_of!(color__bindgen_ty_2, y) - 0usize]; + [ + "Offset of field: color__bindgen_ty_2::u", + ][::std::mem::offset_of!(color__bindgen_ty_2, u) - 1usize]; + [ + "Offset of field: color__bindgen_ty_2::v", + ][::std::mem::offset_of!(color__bindgen_ty_2, v) - 2usize]; +}; +const _: () = { + ["Size of color"][::std::mem::size_of::() - 3usize]; + ["Alignment of color"][::std::mem::align_of::() - 1usize]; + ["Offset of field: color::v3"][::std::mem::offset_of!(color, v3) - 0usize]; +}; impl Default for color { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/anon_enum.rs b/bindgen-tests/tests/expectations/tests/anon_enum.rs index a3ad1db9f0..5324e499e4 100644 --- a/bindgen-tests/tests/expectations/tests/anon_enum.rs +++ b/bindgen-tests/tests/expectations/tests/anon_enum.rs @@ -11,31 +11,12 @@ pub const Test_T_NONE: Test__bindgen_ty_1 = Test__bindgen_ty_1::T_NONE; pub enum Test__bindgen_ty_1 { T_NONE = 0, } -#[test] -fn bindgen_test_layout_Test() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Test)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Test)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(foo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(bar)), - ); -} +const _: () = { + ["Size of Test"][::std::mem::size_of::() - 8usize]; + ["Alignment of Test"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Test::foo"][::std::mem::offset_of!(Test, foo) - 0usize]; + ["Offset of field: Test::bar"][::std::mem::offset_of!(Test, bar) - 4usize]; +}; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Baz { diff --git a/bindgen-tests/tests/expectations/tests/anon_enum_trait.rs b/bindgen-tests/tests/expectations/tests/anon_enum_trait.rs index 37fe6d810c..97d97d6afd 100644 --- a/bindgen-tests/tests/expectations/tests/anon_enum_trait.rs +++ b/bindgen-tests/tests/expectations/tests/anon_enum_trait.rs @@ -30,16 +30,7 @@ pub const Foo_Baz: Foo__bindgen_ty_1 = Foo__bindgen_ty_1::Bar; pub enum Foo__bindgen_ty_1 { Bar = 0, } -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)), - ); -} +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/anon_struct_in_union.rs b/bindgen-tests/tests/expectations/tests/anon_struct_in_union.rs index a012f1692e..dc61f38911 100644 --- a/bindgen-tests/tests/expectations/tests/anon_struct_in_union.rs +++ b/bindgen-tests/tests/expectations/tests/anon_struct_in_union.rs @@ -14,56 +14,24 @@ pub union s__bindgen_ty_1 { pub struct s__bindgen_ty_1_inner { pub b: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_s__bindgen_ty_1_inner() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(s__bindgen_ty_1_inner)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(s__bindgen_ty_1_inner)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(s__bindgen_ty_1_inner), - "::", - stringify!(b), - ), - ); -} -#[test] -fn bindgen_test_layout_s__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(s__bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(s__bindgen_ty_1)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).field) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(s__bindgen_ty_1), - "::", - stringify!(field), - ), - ); -} +const _: () = { + [ + "Size of s__bindgen_ty_1_inner", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of s__bindgen_ty_1_inner", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: s__bindgen_ty_1_inner::b", + ][::std::mem::offset_of!(s__bindgen_ty_1_inner, b) - 0usize]; +}; +const _: () = { + ["Size of s__bindgen_ty_1"][::std::mem::size_of::() - 4usize]; + ["Alignment of s__bindgen_ty_1"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: s__bindgen_ty_1::field", + ][::std::mem::offset_of!(s__bindgen_ty_1, field) - 0usize]; +}; impl Default for s__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -73,22 +41,11 @@ impl Default for s__bindgen_ty_1 { } } } -#[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::(), 4usize, concat!("Size of: ", stringify!(s))); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(s)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(s), "::", stringify!(u)), - ); -} +const _: () = { + ["Size of s"][::std::mem::size_of::() - 4usize]; + ["Alignment of s"][::std::mem::align_of::() - 4usize]; + ["Offset of field: s::u"][::std::mem::offset_of!(s, u) - 0usize]; +}; impl Default for s { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/anon_struct_in_union_1_0.rs b/bindgen-tests/tests/expectations/tests/anon_struct_in_union_1_0.rs index c3b11f63e8..5a6e3ca477 100644 --- a/bindgen-tests/tests/expectations/tests/anon_struct_in_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/anon_struct_in_union_1_0.rs @@ -65,22 +65,17 @@ fn bindgen_test_layout_s__bindgen_ty_1_inner() { assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(s__bindgen_ty_1_inner)), + "Size of s__bindgen_ty_1_inner", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(s__bindgen_ty_1_inner)), + "Alignment of s__bindgen_ty_1_inner", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(s__bindgen_ty_1_inner), - "::", - stringify!(b), - ), + "Offset of field: s__bindgen_ty_1_inner::b", ); } impl Clone for s__bindgen_ty_1_inner { @@ -95,22 +90,17 @@ fn bindgen_test_layout_s__bindgen_ty_1() { assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(s__bindgen_ty_1)), + "Size of s__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(s__bindgen_ty_1)), + "Alignment of s__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).field) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(s__bindgen_ty_1), - "::", - stringify!(field), - ), + "Offset of field: s__bindgen_ty_1::field", ); } impl Clone for s__bindgen_ty_1 { @@ -122,16 +112,12 @@ impl Clone for s__bindgen_ty_1 { 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::(), 4usize, concat!("Size of: ", stringify!(s))); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(s)), - ); + assert_eq!(::std::mem::size_of::(), 4usize, "Size of s"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of s"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(s), "::", stringify!(u)), + "Offset of field: s::u", ); } impl Clone for s { diff --git a/bindgen-tests/tests/expectations/tests/anon_union.rs b/bindgen-tests/tests/expectations/tests/anon_union.rs index d77658df83..caf5f93ece 100644 --- a/bindgen-tests/tests/expectations/tests/anon_union.rs +++ b/bindgen-tests/tests/expectations/tests/anon_union.rs @@ -51,19 +51,10 @@ impl Default for TErrorResult { pub struct ErrorResult { pub _base: TErrorResult, } -#[test] -fn bindgen_test_layout_ErrorResult() { - assert_eq!( - ::std::mem::size_of::(), - 24usize, - concat!("Size of: ", stringify!(ErrorResult)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(ErrorResult)), - ); -} +const _: () = { + ["Size of ErrorResult"][::std::mem::size_of::() - 24usize]; + ["Alignment of ErrorResult"][::std::mem::align_of::() - 8usize]; +}; impl Default for ErrorResult { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -73,16 +64,11 @@ impl Default for ErrorResult { } } } -#[test] -fn __bindgen_test_layout_TErrorResult_open0_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::(), - 24usize, - concat!("Size of template specialization: ", stringify!(TErrorResult)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of template specialization: ", stringify!(TErrorResult)), - ); -} +const _: () = { + [ + "Size of template specialization: TErrorResult_open0_int_close0", + ][::std::mem::size_of::() - 24usize]; + [ + "Align of template specialization: TErrorResult_open0_int_close0", + ][::std::mem::align_of::() - 8usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/anon_union_1_0.rs b/bindgen-tests/tests/expectations/tests/anon_union_1_0.rs index c7e24da1c7..29b13d010d 100644 --- a/bindgen-tests/tests/expectations/tests/anon_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/anon_union_1_0.rs @@ -89,15 +89,11 @@ pub struct ErrorResult { } #[test] fn bindgen_test_layout_ErrorResult() { - assert_eq!( - ::std::mem::size_of::(), - 24usize, - concat!("Size of: ", stringify!(ErrorResult)), - ); + assert_eq!(::std::mem::size_of::(), 24usize, "Size of ErrorResult"); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(ErrorResult)), + "Alignment of ErrorResult", ); } impl Clone for ErrorResult { @@ -119,11 +115,11 @@ fn __bindgen_test_layout_TErrorResult_open0_int_close0_instantiation() { assert_eq!( ::std::mem::size_of::(), 24usize, - concat!("Size of template specialization: ", stringify!(TErrorResult)), + "Size of template specialization: TErrorResult_open0_int_close0", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of template specialization: ", stringify!(TErrorResult)), + "Align of template specialization: TErrorResult_open0_int_close0", ); } diff --git a/bindgen-tests/tests/expectations/tests/array-of-zero-sized-types.rs b/bindgen-tests/tests/expectations/tests/array-of-zero-sized-types.rs index 9eb483cc6a..3477e83dc2 100644 --- a/bindgen-tests/tests/expectations/tests/array-of-zero-sized-types.rs +++ b/bindgen-tests/tests/expectations/tests/array-of-zero-sized-types.rs @@ -5,19 +5,10 @@ pub struct Empty { pub _address: u8, } -#[test] -fn bindgen_test_layout_Empty() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Empty)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Empty)), - ); -} +const _: () = { + ["Size of Empty"][::std::mem::size_of::() - 1usize]; + ["Alignment of Empty"][::std::mem::align_of::() - 1usize]; +}; /** This should not get an `_address` byte, since each `Empty` gets one, meaning that this object is addressable.*/ #[repr(C)] @@ -25,28 +16,10 @@ fn bindgen_test_layout_Empty() { pub struct HasArrayOfEmpty { pub empties: [Empty; 10usize], } -#[test] -fn bindgen_test_layout_HasArrayOfEmpty() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 10usize, - concat!("Size of: ", stringify!(HasArrayOfEmpty)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(HasArrayOfEmpty)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).empties) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(HasArrayOfEmpty), - "::", - stringify!(empties), - ), - ); -} +const _: () = { + ["Size of HasArrayOfEmpty"][::std::mem::size_of::() - 10usize]; + ["Alignment of HasArrayOfEmpty"][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: HasArrayOfEmpty::empties", + ][::std::mem::offset_of!(HasArrayOfEmpty, empties) - 0usize]; +}; 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 b3ded6636e..07eb7a80f6 100644 --- a/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result.rs +++ b/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result.rs @@ -6,16 +6,8 @@ pub struct Foo { } #[test] fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)), - ); + assert_eq!(::std::mem::size_of::(), 1usize, "Size of Foo"); + assert_eq!(::std::mem::align_of::(), 1usize, "Alignment of Foo"); } extern "C" { #[must_use] 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 15cfef051f..aa01540b0e 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 @@ -6,16 +6,8 @@ pub struct Foo { } #[test] fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)), - ); + assert_eq!(::std::mem::size_of::(), 1usize, "Size of Foo"); + assert_eq!(::std::mem::align_of::(), 1usize, "Alignment of Foo"); } extern "C" { #[link_name = "\u{1}_ZN3Foo3fooEi"] diff --git a/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_pre_1_27.rs b/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_pre_1_27.rs index 15cfef051f..92f6eaf97d 100644 --- a/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_pre_1_27.rs +++ b/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_pre_1_27.rs @@ -4,19 +4,10 @@ pub struct Foo { pub _address: u8, } -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)), - ); -} +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; +}; 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; diff --git a/bindgen-tests/tests/expectations/tests/auto.rs b/bindgen-tests/tests/expectations/tests/auto.rs index 340bc670dc..2ee0ebbaff 100644 --- a/bindgen-tests/tests/expectations/tests/auto.rs +++ b/bindgen-tests/tests/expectations/tests/auto.rs @@ -5,19 +5,10 @@ pub struct Foo { pub _address: u8, } pub const Foo_kFoo: bool = true; -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)), - ); -} +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Bar { diff --git a/bindgen-tests/tests/expectations/tests/base-to-derived.rs b/bindgen-tests/tests/expectations/tests/base-to-derived.rs index 1d6643219c..26d8d799ba 100644 --- a/bindgen-tests/tests/expectations/tests/base-to-derived.rs +++ b/bindgen-tests/tests/expectations/tests/base-to-derived.rs @@ -4,16 +4,7 @@ pub struct false_type { pub _address: u8, } -#[test] -fn bindgen_test_layout_false_type() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(false_type)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(false_type)), - ); -} +const _: () = { + ["Size of false_type"][::std::mem::size_of::() - 1usize]; + ["Alignment of false_type"][::std::mem::align_of::() - 1usize]; +}; 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 2a73a439d1..70f9216a68 100644 --- a/bindgen-tests/tests/expectations/tests/bindgen-union-inside-namespace.rs +++ b/bindgen-tests/tests/expectations/tests/bindgen-union-inside-namespace.rs @@ -60,25 +60,17 @@ pub mod root { 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, - concat!("Size of: ", stringify!(Bar)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Bar)), - ); + 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, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(foo)), + "Offset of field: Bar::foo", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(bar)), + "Offset of field: Bar::bar", ); } impl Clone for Bar { diff --git a/bindgen-tests/tests/expectations/tests/bitfield-32bit-overflow.rs b/bindgen-tests/tests/expectations/tests/bitfield-32bit-overflow.rs index ea126bbbc1..9e365e48ef 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-32bit-overflow.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-32bit-overflow.rs @@ -89,19 +89,10 @@ pub struct MuchBitfield { pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 5usize]>, } -#[test] -fn bindgen_test_layout_MuchBitfield() { - assert_eq!( - ::std::mem::size_of::(), - 5usize, - concat!("Size of: ", stringify!(MuchBitfield)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(MuchBitfield)), - ); -} +const _: () = { + ["Size of MuchBitfield"][::std::mem::size_of::() - 5usize]; + ["Alignment of MuchBitfield"][::std::mem::align_of::() - 1usize]; +}; impl MuchBitfield { #[inline] pub fn m0(&self) -> ::std::os::raw::c_char { diff --git a/bindgen-tests/tests/expectations/tests/bitfield-enum-basic.rs b/bindgen-tests/tests/expectations/tests/bitfield-enum-basic.rs index ab6a923201..9775f07c60 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-enum-basic.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-enum-basic.rs @@ -148,16 +148,7 @@ impl ::std::ops::BitAndAssign for Dummy__bindgen_ty_1 { #[repr(transparent)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Dummy__bindgen_ty_1(pub ::std::os::raw::c_uint); -#[test] -fn bindgen_test_layout_Dummy() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Dummy)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Dummy)), - ); -} +const _: () = { + ["Size of Dummy"][::std::mem::size_of::() - 1usize]; + ["Alignment of Dummy"][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/bitfield-large.rs b/bindgen-tests/tests/expectations/tests/bitfield-large.rs index f5b337cf45..44f9e5b765 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-large.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-large.rs @@ -90,19 +90,10 @@ pub struct HasBigBitfield { pub _bitfield_align_1: [u64; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 16usize]>, } -#[test] -fn bindgen_test_layout_HasBigBitfield() { - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(HasBigBitfield)), - ); - assert_eq!( - ::std::mem::align_of::(), - 16usize, - concat!("Alignment of ", stringify!(HasBigBitfield)), - ); -} +const _: () = { + ["Size of HasBigBitfield"][::std::mem::size_of::() - 16usize]; + ["Alignment of HasBigBitfield"][::std::mem::align_of::() - 16usize]; +}; impl HasBigBitfield { #[inline] pub fn x(&self) -> i128 { @@ -137,19 +128,14 @@ pub struct HasTwoBigBitfields { pub _bitfield_align_1: [u64; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 16usize]>, } -#[test] -fn bindgen_test_layout_HasTwoBigBitfields() { - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(HasTwoBigBitfields)), - ); - assert_eq!( - ::std::mem::align_of::(), - 16usize, - concat!("Alignment of ", stringify!(HasTwoBigBitfields)), - ); -} +const _: () = { + [ + "Size of HasTwoBigBitfields", + ][::std::mem::size_of::() - 16usize]; + [ + "Alignment of HasTwoBigBitfields", + ][::std::mem::align_of::() - 16usize]; +}; impl HasTwoBigBitfields { #[inline] pub fn x(&self) -> i128 { diff --git a/bindgen-tests/tests/expectations/tests/bitfield-linux-32.rs b/bindgen-tests/tests/expectations/tests/bitfield-linux-32.rs index 4500be292f..ffd5e61cb5 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-linux-32.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-linux-32.rs @@ -90,26 +90,11 @@ pub struct Test { pub _bitfield_align_1: [u64; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 8usize]>, } -#[test] -fn bindgen_test_layout_Test() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(Test)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Test)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(foo)), - ); -} +const _: () = { + ["Size of Test"][::std::mem::size_of::() - 16usize]; + ["Alignment of Test"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Test::foo"][::std::mem::offset_of!(Test, foo) - 0usize]; +}; impl Test { #[inline] pub fn x(&self) -> u64 { diff --git a/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs b/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs index ce3ea41e75..ea8618280f 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs @@ -89,19 +89,10 @@ pub struct Foo { pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, } -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)), - ); -} +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; +}; extern "C" { #[link_name = "\u{1}_ZN3Foo4typeEv"] pub fn Foo_type(this: *mut Foo) -> ::std::os::raw::c_char; diff --git a/bindgen-tests/tests/expectations/tests/bitfield_align.rs b/bindgen-tests/tests/expectations/tests/bitfield_align.rs index 8002327981..dc0cc52183 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_align.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_align.rs @@ -92,27 +92,12 @@ pub struct A { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 2usize]>, pub y: ::std::os::raw::c_uchar, } -#[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::(), 4usize, concat!("Size of: ", stringify!(A))); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(A)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(x)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, - 3usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(y)), - ); -} +const _: () = { + ["Size of A"][::std::mem::size_of::() - 4usize]; + ["Alignment of A"][::std::mem::align_of::() - 4usize]; + ["Offset of field: A::x"][::std::mem::offset_of!(A, x) - 0usize]; + ["Offset of field: A::y"][::std::mem::offset_of!(A, y) - 3usize]; +}; impl A { #[inline] pub fn b1(&self) -> ::std::os::raw::c_uint { @@ -337,15 +322,10 @@ pub struct B { pub _bitfield_align_1: [u32; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, } -#[test] -fn bindgen_test_layout_B() { - assert_eq!(::std::mem::size_of::(), 4usize, concat!("Size of: ", stringify!(B))); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(B)), - ); -} +const _: () = { + ["Size of B"][::std::mem::size_of::() - 4usize]; + ["Alignment of B"][::std::mem::align_of::() - 4usize]; +}; impl B { #[inline] pub fn foo(&self) -> ::std::os::raw::c_uint { @@ -404,27 +384,12 @@ pub struct C { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub baz: ::std::os::raw::c_uint, } -#[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::(), 8usize, concat!("Size of: ", stringify!(C))); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(x)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(baz)), - ); -} +const _: () = { + ["Size of C"][::std::mem::size_of::() - 8usize]; + ["Alignment of C"][::std::mem::align_of::() - 4usize]; + ["Offset of field: C::x"][::std::mem::offset_of!(C, x) - 0usize]; + ["Offset of field: C::baz"][::std::mem::offset_of!(C, baz) - 4usize]; +}; impl C { #[inline] pub fn b1(&self) -> ::std::os::raw::c_uint { @@ -483,19 +448,10 @@ pub struct Date1 { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 3usize]>, pub __bindgen_padding_0: u8, } -#[test] -fn bindgen_test_layout_Date1() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Date1)), - ); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(Date1)), - ); -} +const _: () = { + ["Size of Date1"][::std::mem::size_of::() - 4usize]; + ["Alignment of Date1"][::std::mem::align_of::() - 2usize]; +}; impl Date1 { #[inline] pub fn nWeekDay(&self) -> ::std::os::raw::c_ushort { @@ -595,19 +551,10 @@ pub struct Date2 { pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, } -#[test] -fn bindgen_test_layout_Date2() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Date2)), - ); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(Date2)), - ); -} +const _: () = { + ["Size of Date2"][::std::mem::size_of::() - 4usize]; + ["Alignment of Date2"][::std::mem::align_of::() - 2usize]; +}; impl Date2 { #[inline] pub fn nWeekDay(&self) -> ::std::os::raw::c_ushort { @@ -729,26 +676,11 @@ pub struct Date3 { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 3usize]>, pub byte: ::std::os::raw::c_uchar, } -#[test] -fn bindgen_test_layout_Date3() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Date3)), - ); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(Date3)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).byte) as usize - ptr as usize }, - 3usize, - concat!("Offset of field: ", stringify!(Date3), "::", stringify!(byte)), - ); -} +const _: () = { + ["Size of Date3"][::std::mem::size_of::() - 4usize]; + ["Alignment of Date3"][::std::mem::align_of::() - 2usize]; + ["Offset of field: Date3::byte"][::std::mem::offset_of!(Date3, byte) - 3usize]; +}; impl Date3 { #[inline] pub fn nWeekDay(&self) -> ::std::os::raw::c_ushort { diff --git a/bindgen-tests/tests/expectations/tests/bitfield_align_2.rs b/bindgen-tests/tests/expectations/tests/bitfield_align_2.rs index 963d86f9be..4cb0aaa48c 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_align_2.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_align_2.rs @@ -98,19 +98,10 @@ pub struct TaggedPtr { pub _bitfield_align_1: [u64; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 8usize]>, } -#[test] -fn bindgen_test_layout_TaggedPtr() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(TaggedPtr)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(TaggedPtr)), - ); -} +const _: () = { + ["Size of TaggedPtr"][::std::mem::size_of::() - 8usize]; + ["Alignment of TaggedPtr"][::std::mem::align_of::() - 8usize]; +}; impl Default for TaggedPtr { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/bitfield_large_overflow.rs b/bindgen-tests/tests/expectations/tests/bitfield_large_overflow.rs index 54f09f6229..3040e3e47c 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_large_overflow.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_large_overflow.rs @@ -5,19 +5,10 @@ pub struct _bindgen_ty_1 { pub _bindgen_opaque_blob: [u64; 10usize], } -#[test] -fn bindgen_test_layout__bindgen_ty_1() { - assert_eq!( - ::std::mem::size_of::<_bindgen_ty_1>(), - 80usize, - concat!("Size of: ", stringify!(_bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::<_bindgen_ty_1>(), - 8usize, - concat!("Alignment of ", stringify!(_bindgen_ty_1)), - ); -} +const _: () = { + ["Size of _bindgen_ty_1"][::std::mem::size_of::<_bindgen_ty_1>() - 80usize]; + ["Alignment of _bindgen_ty_1"][::std::mem::align_of::<_bindgen_ty_1>() - 8usize]; +}; extern "C" { pub static mut a: _bindgen_ty_1; } diff --git a/bindgen-tests/tests/expectations/tests/bitfield_method_mangling.rs b/bindgen-tests/tests/expectations/tests/bitfield_method_mangling.rs index 7104682ea8..19e415e2c6 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_method_mangling.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_method_mangling.rs @@ -89,19 +89,14 @@ pub struct mach_msg_type_descriptor_t { pub _bitfield_align_1: [u32; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, } -#[test] -fn bindgen_test_layout_mach_msg_type_descriptor_t() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(mach_msg_type_descriptor_t)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(mach_msg_type_descriptor_t)), - ); -} +const _: () = { + [ + "Size of mach_msg_type_descriptor_t", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of mach_msg_type_descriptor_t", + ][::std::mem::align_of::() - 4usize]; +}; impl mach_msg_type_descriptor_t { #[inline] pub fn pad3(&self) -> ::std::os::raw::c_uint { diff --git a/bindgen-tests/tests/expectations/tests/bitfield_pragma_packed.rs b/bindgen-tests/tests/expectations/tests/bitfield_pragma_packed.rs index e3168f51ea..54cf2ff1d0 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_pragma_packed.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_pragma_packed.rs @@ -89,19 +89,10 @@ pub struct Struct { pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, } -#[test] -fn bindgen_test_layout_Struct() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Struct)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Struct)), - ); -} +const _: () = { + ["Size of Struct"][::std::mem::size_of::() - 4usize]; + ["Alignment of Struct"][::std::mem::align_of::() - 1usize]; +}; impl Struct { #[inline] pub fn a(&self) -> ::std::os::raw::c_uchar { @@ -221,19 +212,10 @@ pub struct Inner { pub _bitfield_align_1: [u16; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, } -#[test] -fn bindgen_test_layout_Inner() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Inner)), - ); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(Inner)), - ); -} +const _: () = { + ["Size of Inner"][::std::mem::size_of::() - 4usize]; + ["Alignment of Inner"][::std::mem::align_of::() - 2usize]; +}; impl Inner { #[inline] pub fn a(&self) -> ::std::os::raw::c_ushort { @@ -289,23 +271,8 @@ impl Inner { pub struct Outer { pub inner: Inner, } -#[test] -fn bindgen_test_layout_Outer() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Outer)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Outer)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).inner) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Outer), "::", stringify!(inner)), - ); -} +const _: () = { + ["Size of Outer"][::std::mem::size_of::() - 4usize]; + ["Alignment of Outer"][::std::mem::align_of::() - 1usize]; + ["Offset of field: Outer::inner"][::std::mem::offset_of!(Outer, inner) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/blocklist-and-impl-debug.rs b/bindgen-tests/tests/expectations/tests/blocklist-and-impl-debug.rs index c09ff915b7..e77967c930 100644 --- a/bindgen-tests/tests/expectations/tests/blocklist-and-impl-debug.rs +++ b/bindgen-tests/tests/expectations/tests/blocklist-and-impl-debug.rs @@ -5,31 +5,17 @@ pub struct BlocklistMe(u8); pub struct ShouldManuallyImplDebug { pub a: BlocklistMe, } -#[test] -fn bindgen_test_layout_ShouldManuallyImplDebug() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(ShouldManuallyImplDebug)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(ShouldManuallyImplDebug)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldManuallyImplDebug), - "::", - stringify!(a), - ), - ); -} +const _: () = { + [ + "Size of ShouldManuallyImplDebug", + ][::std::mem::size_of::() - 1usize]; + [ + "Alignment of ShouldManuallyImplDebug", + ][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: ShouldManuallyImplDebug::a", + ][::std::mem::offset_of!(ShouldManuallyImplDebug, a) - 0usize]; +}; impl Default for ShouldManuallyImplDebug { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/blocklist-file.rs b/bindgen-tests/tests/expectations/tests/blocklist-file.rs index 99f81f9e50..834db1834d 100644 --- a/bindgen-tests/tests/expectations/tests/blocklist-file.rs +++ b/bindgen-tests/tests/expectations/tests/blocklist-file.rs @@ -6,63 +6,32 @@ pub struct SizedIntegers { pub y: u16, pub z: u32, } -#[test] -fn bindgen_test_layout_SizedIntegers() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(SizedIntegers)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(SizedIntegers)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(SizedIntegers), "::", stringify!(x)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, - 2usize, - concat!("Offset of field: ", stringify!(SizedIntegers), "::", stringify!(y)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).z) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(SizedIntegers), "::", stringify!(z)), - ); -} +const _: () = { + ["Size of SizedIntegers"][::std::mem::size_of::() - 8usize]; + ["Alignment of SizedIntegers"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: SizedIntegers::x", + ][::std::mem::offset_of!(SizedIntegers, x) - 0usize]; + [ + "Offset of field: SizedIntegers::y", + ][::std::mem::offset_of!(SizedIntegers, y) - 2usize]; + [ + "Offset of field: SizedIntegers::z", + ][::std::mem::offset_of!(SizedIntegers, z) - 4usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct StructWithBlocklistedFwdDecl { pub b: u8, } -#[test] -fn bindgen_test_layout_StructWithBlocklistedFwdDecl() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(StructWithBlocklistedFwdDecl)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(StructWithBlocklistedFwdDecl)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(StructWithBlocklistedFwdDecl), - "::", - stringify!(b), - ), - ); -} +const _: () = { + [ + "Size of StructWithBlocklistedFwdDecl", + ][::std::mem::size_of::() - 1usize]; + [ + "Alignment of StructWithBlocklistedFwdDecl", + ][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: StructWithBlocklistedFwdDecl::b", + ][::std::mem::offset_of!(StructWithBlocklistedFwdDecl, b) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/blocklist-function.rs b/bindgen-tests/tests/expectations/tests/blocklist-function.rs index 531ba2e6d8..2d0ab9d573 100644 --- a/bindgen-tests/tests/expectations/tests/blocklist-function.rs +++ b/bindgen-tests/tests/expectations/tests/blocklist-function.rs @@ -20,17 +20,8 @@ pub mod root { pub struct C { pub _address: u8, } - #[test] - fn bindgen_test_layout_C() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(C)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(C)), - ); - } + const _: () = { + ["Size of C"][::std::mem::size_of::() - 1usize]; + ["Alignment of C"][::std::mem::align_of::() - 1usize]; + }; } diff --git a/bindgen-tests/tests/expectations/tests/blocklist-methods.rs b/bindgen-tests/tests/expectations/tests/blocklist-methods.rs index 583beabeed..835b1fd385 100644 --- a/bindgen-tests/tests/expectations/tests/blocklist-methods.rs +++ b/bindgen-tests/tests/expectations/tests/blocklist-methods.rs @@ -4,19 +4,10 @@ pub struct Foo { pub _address: u8, } -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)), - ); -} +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; +}; extern "C" { #[link_name = "\u{1}_ZN3Foo3fooEv"] pub fn Foo_foo(this: *mut Foo) -> ::std::os::raw::c_int; diff --git a/bindgen-tests/tests/expectations/tests/blocks-signature.rs b/bindgen-tests/tests/expectations/tests/blocks-signature.rs index 3f4fa289b0..be5eed7d19 100644 --- a/bindgen-tests/tests/expectations/tests/blocks-signature.rs +++ b/bindgen-tests/tests/expectations/tests/blocks-signature.rs @@ -28,41 +28,20 @@ pub struct contains_block_pointers { pub val: contains_block_pointers__bindgen_ty_id_61, pub ptr_val: *mut _bindgen_ty_id_68, } -#[test] -fn bindgen_test_layout_contains_block_pointers() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(contains_block_pointers)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(contains_block_pointers)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).val) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(contains_block_pointers), - "::", - stringify!(val), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ptr_val) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(contains_block_pointers), - "::", - stringify!(ptr_val), - ), - ); -} +const _: () = { + [ + "Size of contains_block_pointers", + ][::std::mem::size_of::() - 16usize]; + [ + "Alignment of contains_block_pointers", + ][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: contains_block_pointers::val", + ][::std::mem::offset_of!(contains_block_pointers, val) - 0usize]; + [ + "Offset of field: contains_block_pointers::ptr_val", + ][::std::mem::offset_of!(contains_block_pointers, ptr_val) - 8usize]; +}; impl Default for contains_block_pointers { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/blocks.rs b/bindgen-tests/tests/expectations/tests/blocks.rs index 0d43e65fc4..1d79678292 100644 --- a/bindgen-tests/tests/expectations/tests/blocks.rs +++ b/bindgen-tests/tests/expectations/tests/blocks.rs @@ -27,41 +27,20 @@ pub struct contains_block_pointers { pub val: *mut ::std::os::raw::c_void, pub ptr_val: *mut *mut ::std::os::raw::c_void, } -#[test] -fn bindgen_test_layout_contains_block_pointers() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(contains_block_pointers)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(contains_block_pointers)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).val) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(contains_block_pointers), - "::", - stringify!(val), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ptr_val) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(contains_block_pointers), - "::", - stringify!(ptr_val), - ), - ); -} +const _: () = { + [ + "Size of contains_block_pointers", + ][::std::mem::size_of::() - 16usize]; + [ + "Alignment of contains_block_pointers", + ][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: contains_block_pointers::val", + ][::std::mem::offset_of!(contains_block_pointers, val) - 0usize]; + [ + "Offset of field: contains_block_pointers::ptr_val", + ][::std::mem::offset_of!(contains_block_pointers, ptr_val) - 8usize]; +}; impl Default for contains_block_pointers { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/bug-1529681.rs b/bindgen-tests/tests/expectations/tests/bug-1529681.rs index 50d48d438c..2681c36faf 100644 --- a/bindgen-tests/tests/expectations/tests/bug-1529681.rs +++ b/bindgen-tests/tests/expectations/tests/bug-1529681.rs @@ -4,16 +4,7 @@ pub struct BrowsingContext { pub _address: u8, } -#[test] -fn bindgen_test_layout_BrowsingContext() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(BrowsingContext)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(BrowsingContext)), - ); -} +const _: () = { + ["Size of BrowsingContext"][::std::mem::size_of::() - 1usize]; + ["Alignment of BrowsingContext"][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/c-empty-layout.rs b/bindgen-tests/tests/expectations/tests/c-empty-layout.rs index 7d59cadcca..e82d70cea1 100644 --- a/bindgen-tests/tests/expectations/tests/c-empty-layout.rs +++ b/bindgen-tests/tests/expectations/tests/c-empty-layout.rs @@ -2,16 +2,7 @@ #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo {} -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)), - ); -} +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 0usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/c_naming.rs b/bindgen-tests/tests/expectations/tests/c_naming.rs index a88f1b3572..83ccbeadcf 100644 --- a/bindgen-tests/tests/expectations/tests/c_naming.rs +++ b/bindgen-tests/tests/expectations/tests/c_naming.rs @@ -4,26 +4,11 @@ pub struct struct_a { pub a: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_struct_a() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(struct_a)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(struct_a)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(struct_a), "::", stringify!(a)), - ); -} +const _: () = { + ["Size of struct_a"][::std::mem::size_of::() - 4usize]; + ["Alignment of struct_a"][::std::mem::align_of::() - 4usize]; + ["Offset of field: struct_a::a"][::std::mem::offset_of!(struct_a, a) - 0usize]; +}; pub type a = *const struct_a; #[repr(C)] #[derive(Copy, Clone)] @@ -31,31 +16,12 @@ pub union union_b { pub a: ::std::os::raw::c_int, pub b: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_union_b() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(union_b)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(union_b)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(union_b), "::", stringify!(a)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(union_b), "::", stringify!(b)), - ); -} +const _: () = { + ["Size of union_b"][::std::mem::size_of::() - 4usize]; + ["Alignment of union_b"][::std::mem::align_of::() - 4usize]; + ["Offset of field: union_b::a"][::std::mem::offset_of!(union_b, a) - 0usize]; + ["Offset of field: union_b::b"][::std::mem::offset_of!(union_b, b) - 0usize]; +}; impl Default for union_b { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/call-conv-field.rs b/bindgen-tests/tests/expectations/tests/call-conv-field.rs index e3179543fc..73fc76e208 100644 --- a/bindgen-tests/tests/expectations/tests/call-conv-field.rs +++ b/bindgen-tests/tests/expectations/tests/call-conv-field.rs @@ -10,41 +10,20 @@ pub struct JNINativeInterface_ { >, pub __hack: ::std::os::raw::c_ulonglong, } -#[test] -fn bindgen_test_layout_JNINativeInterface_() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(JNINativeInterface_)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(JNINativeInterface_)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).GetVersion) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(JNINativeInterface_), - "::", - stringify!(GetVersion), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).__hack) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(JNINativeInterface_), - "::", - stringify!(__hack), - ), - ); -} +const _: () = { + [ + "Size of JNINativeInterface_", + ][::std::mem::size_of::() - 16usize]; + [ + "Alignment of JNINativeInterface_", + ][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: JNINativeInterface_::GetVersion", + ][::std::mem::offset_of!(JNINativeInterface_, GetVersion) - 0usize]; + [ + "Offset of field: JNINativeInterface_::__hack", + ][::std::mem::offset_of!(JNINativeInterface_, __hack) - 8usize]; +}; extern "stdcall" { pub fn bar(); } diff --git a/bindgen-tests/tests/expectations/tests/canonical-types.rs b/bindgen-tests/tests/expectations/tests/canonical-types.rs index 49795c7db7..a6e22c7788 100644 --- a/bindgen-tests/tests/expectations/tests/canonical-types.rs +++ b/bindgen-tests/tests/expectations/tests/canonical-types.rs @@ -76,19 +76,10 @@ impl Default for ClassC_ClassCInnerCRTP { pub struct ClassD { pub _address: u8, } -#[test] -fn bindgen_test_layout_ClassD() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(ClassD)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(ClassD)), - ); -} +const _: () = { + ["Size of ClassD"][::std::mem::size_of::() - 1usize]; + ["Alignment of ClassD"][::std::mem::align_of::() - 1usize]; +}; impl Default for ClassD { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -98,37 +89,23 @@ impl Default for ClassD { } } } -#[test] -fn __bindgen_test_layout_ClassB_open0_ClassD_ClassCInnerCRTP_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of template specialization: ", stringify!(ClassB)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of template specialization: ", stringify!(ClassB)), - ); -} +const _: () = { + [ + "Size of template specialization: ClassB_open0_ClassD_ClassCInnerCRTP_close0", + ][::std::mem::size_of::() - 1usize]; + [ + "Align of template specialization: ClassB_open0_ClassD_ClassCInnerCRTP_close0", + ][::std::mem::align_of::() - 1usize]; +}; #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct ClassCInnerCRTP { pub _address: u8, } -#[test] -fn bindgen_test_layout_ClassCInnerCRTP() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(ClassCInnerCRTP)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(ClassCInnerCRTP)), - ); -} +const _: () = { + ["Size of ClassCInnerCRTP"][::std::mem::size_of::() - 1usize]; + ["Alignment of ClassCInnerCRTP"][::std::mem::align_of::() - 1usize]; +}; impl Default for ClassCInnerCRTP { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -138,44 +115,24 @@ impl Default for ClassCInnerCRTP { } } } -#[test] -fn __bindgen_test_layout_ClassB_open0_ClassCInnerCRTP_ClassAInner_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of template specialization: ", stringify!(ClassB)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of template specialization: ", stringify!(ClassB)), - ); -} +const _: () = { + [ + "Size of template specialization: ClassB_open0_ClassCInnerCRTP_ClassAInner_close0", + ][::std::mem::size_of::() - 1usize]; + [ + "Align of template specialization: ClassB_open0_ClassCInnerCRTP_ClassAInner_close0", + ][::std::mem::align_of::() - 1usize]; +}; #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct ClassAInner { pub x: *mut ClassCInnerA, } -#[test] -fn bindgen_test_layout_ClassAInner() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(ClassAInner)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(ClassAInner)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(ClassAInner), "::", stringify!(x)), - ); -} +const _: () = { + ["Size of ClassAInner"][::std::mem::size_of::() - 8usize]; + ["Alignment of ClassAInner"][::std::mem::align_of::() - 8usize]; + ["Offset of field: ClassAInner::x"][::std::mem::offset_of!(ClassAInner, x) - 0usize]; +}; impl Default for ClassAInner { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -190,26 +147,13 @@ impl Default for ClassAInner { pub struct ClassCInnerA { pub member: *mut ClassCInnerB, } -#[test] -fn bindgen_test_layout_ClassCInnerA() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(ClassCInnerA)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(ClassCInnerA)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(ClassCInnerA), "::", stringify!(member)), - ); -} +const _: () = { + ["Size of ClassCInnerA"][::std::mem::size_of::() - 8usize]; + ["Alignment of ClassCInnerA"][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: ClassCInnerA::member", + ][::std::mem::offset_of!(ClassCInnerA, member) - 0usize]; +}; impl Default for ClassCInnerA { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -224,26 +168,13 @@ impl Default for ClassCInnerA { pub struct ClassCInnerB { pub cache: *mut ClassCInnerA, } -#[test] -fn bindgen_test_layout_ClassCInnerB() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(ClassCInnerB)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(ClassCInnerB)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).cache) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(ClassCInnerB), "::", stringify!(cache)), - ); -} +const _: () = { + ["Size of ClassCInnerB"][::std::mem::size_of::() - 8usize]; + ["Alignment of ClassCInnerB"][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: ClassCInnerB::cache", + ][::std::mem::offset_of!(ClassCInnerB, cache) - 0usize]; +}; impl Default for ClassCInnerB { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/canonical_path_without_namespacing.rs b/bindgen-tests/tests/expectations/tests/canonical_path_without_namespacing.rs index 11ae02814e..6882c57fa4 100644 --- a/bindgen-tests/tests/expectations/tests/canonical_path_without_namespacing.rs +++ b/bindgen-tests/tests/expectations/tests/canonical_path_without_namespacing.rs @@ -4,19 +4,10 @@ pub struct Bar { pub _address: u8, } -#[test] -fn bindgen_test_layout_Bar() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Bar)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Bar)), - ); -} +const _: () = { + ["Size of Bar"][::std::mem::size_of::() - 1usize]; + ["Alignment of Bar"][::std::mem::align_of::() - 1usize]; +}; extern "C" { #[link_name = "\u{1}_Z3bazPN3foo3BarE"] pub fn baz(arg1: *mut Bar); diff --git a/bindgen-tests/tests/expectations/tests/char.rs b/bindgen-tests/tests/expectations/tests/char.rs index f3acf04e0c..531c70213b 100644 --- a/bindgen-tests/tests/expectations/tests/char.rs +++ b/bindgen-tests/tests/expectations/tests/char.rs @@ -18,78 +18,19 @@ pub struct Test { pub Ccu: UChar, pub Ccd: SChar, } -#[test] -fn bindgen_test_layout_Test() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 12usize, - concat!("Size of: ", stringify!(Test)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Test)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ch) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(ch)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize }, - 1usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(u)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 2usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(d)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).cch) as usize - ptr as usize }, - 3usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(cch)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).cu) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(cu)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).cd) as usize - ptr as usize }, - 5usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(cd)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).Cch) as usize - ptr as usize }, - 6usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cch)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).Cu) as usize - ptr as usize }, - 7usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cu)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).Cd) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cd)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).Ccch) as usize - ptr as usize }, - 9usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccch)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).Ccu) as usize - ptr as usize }, - 10usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccu)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).Ccd) as usize - ptr as usize }, - 11usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccd)), - ); -} +const _: () = { + ["Size of Test"][::std::mem::size_of::() - 12usize]; + ["Alignment of Test"][::std::mem::align_of::() - 1usize]; + ["Offset of field: Test::ch"][::std::mem::offset_of!(Test, ch) - 0usize]; + ["Offset of field: Test::u"][::std::mem::offset_of!(Test, u) - 1usize]; + ["Offset of field: Test::d"][::std::mem::offset_of!(Test, d) - 2usize]; + ["Offset of field: Test::cch"][::std::mem::offset_of!(Test, cch) - 3usize]; + ["Offset of field: Test::cu"][::std::mem::offset_of!(Test, cu) - 4usize]; + ["Offset of field: Test::cd"][::std::mem::offset_of!(Test, cd) - 5usize]; + ["Offset of field: Test::Cch"][::std::mem::offset_of!(Test, Cch) - 6usize]; + ["Offset of field: Test::Cu"][::std::mem::offset_of!(Test, Cu) - 7usize]; + ["Offset of field: Test::Cd"][::std::mem::offset_of!(Test, Cd) - 8usize]; + ["Offset of field: Test::Ccch"][::std::mem::offset_of!(Test, Ccch) - 9usize]; + ["Offset of field: Test::Ccu"][::std::mem::offset_of!(Test, Ccu) - 10usize]; + ["Offset of field: Test::Ccd"][::std::mem::offset_of!(Test, Ccd) - 11usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/class.rs b/bindgen-tests/tests/expectations/tests/class.rs index 19668a73dd..69591d1bce 100644 --- a/bindgen-tests/tests/expectations/tests/class.rs +++ b/bindgen-tests/tests/expectations/tests/class.rs @@ -39,21 +39,17 @@ pub struct C { 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, concat!("Size of: ", stringify!(C))); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C)), - ); + 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, - concat!("Offset of field: ", stringify!(C), "::", stringify!(a)), + "Offset of field: C::a", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(big_array)), + "Offset of field: C::big_array", ); } impl Default for C { @@ -78,44 +74,29 @@ fn bindgen_test_layout_C_with_zero_length_array() { assert_eq!( ::std::mem::size_of::(), 40usize, - concat!("Size of: ", stringify!(C_with_zero_length_array)), + "Size of C_with_zero_length_array", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(C_with_zero_length_array)), + "Alignment of C_with_zero_length_array", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(a), - ), + "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, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(big_array), - ), + "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, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(zero_length_array), - ), + "Offset of field: C_with_zero_length_array::zero_length_array", ); } impl Default for C_with_zero_length_array { @@ -140,34 +121,24 @@ fn bindgen_test_layout_C_with_zero_length_array_2() { assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(C_with_zero_length_array_2)), + "Size of C_with_zero_length_array_2", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(C_with_zero_length_array_2)), + "Alignment of C_with_zero_length_array_2", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_2), - "::", - stringify!(a), - ), + "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, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_2), - "::", - stringify!(zero_length_array), - ), + "Offset of field: C_with_zero_length_array_2::zero_length_array", ); } #[repr(C)] @@ -183,42 +154,27 @@ fn bindgen_test_layout_C_with_incomplete_array() { assert_eq!( ::std::mem::size_of::(), 40usize, - concat!("Size of: ", stringify!(C_with_incomplete_array)), + "Size of C_with_incomplete_array", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(C_with_incomplete_array)), + "Alignment of C_with_incomplete_array", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array), - "::", - stringify!(a), - ), + "Offset of field: C_with_incomplete_array::a", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array), - "::", - stringify!(big_array), - ), + "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, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array), - "::", - stringify!(incomplete_array), - ), + "Offset of field: C_with_incomplete_array::incomplete_array", ); } impl Default for C_with_incomplete_array { @@ -243,32 +199,22 @@ fn bindgen_test_layout_C_with_incomplete_array_2() { assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(C_with_incomplete_array_2)), + "Size of C_with_incomplete_array_2", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(C_with_incomplete_array_2)), + "Alignment of C_with_incomplete_array_2", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array_2), - "::", - stringify!(a), - ), + "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, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array_2), - "::", - stringify!(incomplete_array), - ), + "Offset of field: C_with_incomplete_array_2::incomplete_array", ); } #[repr(C)] @@ -287,57 +233,34 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { assert_eq!( ::std::mem::size_of::(), 40usize, - concat!("Size of: ", stringify!(C_with_zero_length_array_and_incomplete_array)), + "Size of C_with_zero_length_array_and_incomplete_array", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!( - "Alignment of ", - stringify!(C_with_zero_length_array_and_incomplete_array), - ), + "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, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(a), - ), + "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, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(big_array), - ), + "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, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(zero_length_array), - ), + "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, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(incomplete_array), - ), + "Offset of field: C_with_zero_length_array_and_incomplete_array::incomplete_array", ); } impl Default for C_with_zero_length_array_and_incomplete_array { @@ -365,47 +288,29 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(C_with_zero_length_array_and_incomplete_array_2)), + "Size of C_with_zero_length_array_and_incomplete_array_2", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!( - "Alignment of ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), - ), + "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, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), - "::", - stringify!(a), - ), + "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, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), - "::", - stringify!(zero_length_array), - ), + "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, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), - "::", - stringify!(incomplete_array), - ), + "Offset of field: C_with_zero_length_array_and_incomplete_array_2::incomplete_array", ); } #[repr(C)] @@ -417,20 +322,12 @@ pub struct WithDtor { 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, - concat!("Size of: ", stringify!(WithDtor)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithDtor)), - ); + 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, - concat!("Offset of field: ", stringify!(WithDtor), "::", stringify!(b)), + "Offset of field: WithDtor::b", ); } #[repr(C)] @@ -445,32 +342,22 @@ fn bindgen_test_layout_IncompleteArrayNonCopiable() { assert_eq!( ::std::mem::size_of::(), 8usize, - concat!("Size of: ", stringify!(IncompleteArrayNonCopiable)), + "Size of IncompleteArrayNonCopiable", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(IncompleteArrayNonCopiable)), + "Alignment of IncompleteArrayNonCopiable", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).whatever) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(IncompleteArrayNonCopiable), - "::", - stringify!(whatever), - ), + "Offset of field: IncompleteArrayNonCopiable::whatever", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, 8usize, - concat!( - "Offset of field: ", - stringify!(IncompleteArrayNonCopiable), - "::", - stringify!(incomplete_array), - ), + "Offset of field: IncompleteArrayNonCopiable::incomplete_array", ); } impl Default for IncompleteArrayNonCopiable { @@ -492,25 +379,17 @@ pub union Union { 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, - concat!("Size of: ", stringify!(Union)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Union)), - ); + 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, - concat!("Offset of field: ", stringify!(Union), "::", stringify!(d)), + "Offset of field: Union::d", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Union), "::", stringify!(i)), + "Offset of field: Union::i", ); } impl Default for Union { @@ -531,20 +410,12 @@ pub struct WithUnion { 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, - concat!("Size of: ", stringify!(WithUnion)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithUnion)), - ); + 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, - concat!("Offset of field: ", stringify!(WithUnion), "::", stringify!(data)), + "Offset of field: WithUnion::data", ); } impl Default for WithUnion { @@ -566,12 +437,12 @@ fn bindgen_test_layout_RealAbstractionWithTonsOfMethods() { assert_eq!( ::std::mem::size_of::(), 1usize, - concat!("Size of: ", stringify!(RealAbstractionWithTonsOfMethods)), + "Size of RealAbstractionWithTonsOfMethods", ); assert_eq!( ::std::mem::align_of::(), 1usize, - concat!("Alignment of ", stringify!(RealAbstractionWithTonsOfMethods)), + "Alignment of RealAbstractionWithTonsOfMethods", ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/class_1_0.rs b/bindgen-tests/tests/expectations/tests/class_1_0.rs index b6544212cf..9db5b3a338 100644 --- a/bindgen-tests/tests/expectations/tests/class_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/class_1_0.rs @@ -82,21 +82,17 @@ pub struct C { 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, concat!("Size of: ", stringify!(C))); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C)), - ); + 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, - concat!("Offset of field: ", stringify!(C), "::", stringify!(a)), + "Offset of field: C::a", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(big_array)), + "Offset of field: C::big_array", ); } impl Clone for C { @@ -131,44 +127,29 @@ fn bindgen_test_layout_C_with_zero_length_array() { assert_eq!( ::std::mem::size_of::(), 40usize, - concat!("Size of: ", stringify!(C_with_zero_length_array)), + "Size of C_with_zero_length_array", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(C_with_zero_length_array)), + "Alignment of C_with_zero_length_array", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(a), - ), + "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, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(big_array), - ), + "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, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array), - "::", - stringify!(zero_length_array), - ), + "Offset of field: C_with_zero_length_array::zero_length_array", ); } impl Default for C_with_zero_length_array { @@ -193,34 +174,24 @@ fn bindgen_test_layout_C_with_zero_length_array_2() { assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(C_with_zero_length_array_2)), + "Size of C_with_zero_length_array_2", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(C_with_zero_length_array_2)), + "Alignment of C_with_zero_length_array_2", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_2), - "::", - stringify!(a), - ), + "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, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_2), - "::", - stringify!(zero_length_array), - ), + "Offset of field: C_with_zero_length_array_2::zero_length_array", ); } #[repr(C)] @@ -236,42 +207,27 @@ fn bindgen_test_layout_C_with_incomplete_array() { assert_eq!( ::std::mem::size_of::(), 40usize, - concat!("Size of: ", stringify!(C_with_incomplete_array)), + "Size of C_with_incomplete_array", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(C_with_incomplete_array)), + "Alignment of C_with_incomplete_array", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array), - "::", - stringify!(a), - ), + "Offset of field: C_with_incomplete_array::a", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array), - "::", - stringify!(big_array), - ), + "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, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array), - "::", - stringify!(incomplete_array), - ), + "Offset of field: C_with_incomplete_array::incomplete_array", ); } impl Default for C_with_incomplete_array { @@ -296,32 +252,22 @@ fn bindgen_test_layout_C_with_incomplete_array_2() { assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(C_with_incomplete_array_2)), + "Size of C_with_incomplete_array_2", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(C_with_incomplete_array_2)), + "Alignment of C_with_incomplete_array_2", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array_2), - "::", - stringify!(a), - ), + "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, - concat!( - "Offset of field: ", - stringify!(C_with_incomplete_array_2), - "::", - stringify!(incomplete_array), - ), + "Offset of field: C_with_incomplete_array_2::incomplete_array", ); } #[repr(C)] @@ -340,57 +286,34 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { assert_eq!( ::std::mem::size_of::(), 40usize, - concat!("Size of: ", stringify!(C_with_zero_length_array_and_incomplete_array)), + "Size of C_with_zero_length_array_and_incomplete_array", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!( - "Alignment of ", - stringify!(C_with_zero_length_array_and_incomplete_array), - ), + "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, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(a), - ), + "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, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(big_array), - ), + "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, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(zero_length_array), - ), + "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, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array), - "::", - stringify!(incomplete_array), - ), + "Offset of field: C_with_zero_length_array_and_incomplete_array::incomplete_array", ); } impl Default for C_with_zero_length_array_and_incomplete_array { @@ -418,47 +341,29 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(C_with_zero_length_array_and_incomplete_array_2)), + "Size of C_with_zero_length_array_and_incomplete_array_2", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!( - "Alignment of ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), - ), + "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, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), - "::", - stringify!(a), - ), + "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, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), - "::", - stringify!(zero_length_array), - ), + "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, - concat!( - "Offset of field: ", - stringify!(C_with_zero_length_array_and_incomplete_array_2), - "::", - stringify!(incomplete_array), - ), + "Offset of field: C_with_zero_length_array_and_incomplete_array_2::incomplete_array", ); } #[repr(C)] @@ -470,20 +375,12 @@ pub struct WithDtor { 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, - concat!("Size of: ", stringify!(WithDtor)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithDtor)), - ); + 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, - concat!("Offset of field: ", stringify!(WithDtor), "::", stringify!(b)), + "Offset of field: WithDtor::b", ); } #[repr(C)] @@ -498,32 +395,22 @@ fn bindgen_test_layout_IncompleteArrayNonCopiable() { assert_eq!( ::std::mem::size_of::(), 8usize, - concat!("Size of: ", stringify!(IncompleteArrayNonCopiable)), + "Size of IncompleteArrayNonCopiable", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(IncompleteArrayNonCopiable)), + "Alignment of IncompleteArrayNonCopiable", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).whatever) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(IncompleteArrayNonCopiable), - "::", - stringify!(whatever), - ), + "Offset of field: IncompleteArrayNonCopiable::whatever", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, 8usize, - concat!( - "Offset of field: ", - stringify!(IncompleteArrayNonCopiable), - "::", - stringify!(incomplete_array), - ), + "Offset of field: IncompleteArrayNonCopiable::incomplete_array", ); } impl Default for IncompleteArrayNonCopiable { @@ -546,25 +433,17 @@ pub struct Union { 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, - concat!("Size of: ", stringify!(Union)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Union)), - ); + 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, - concat!("Offset of field: ", stringify!(Union), "::", stringify!(d)), + "Offset of field: Union::d", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Union), "::", stringify!(i)), + "Offset of field: Union::i", ); } impl Clone for Union { @@ -581,20 +460,12 @@ pub struct WithUnion { 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, - concat!("Size of: ", stringify!(WithUnion)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithUnion)), - ); + 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, - concat!("Offset of field: ", stringify!(WithUnion), "::", stringify!(data)), + "Offset of field: WithUnion::data", ); } impl Clone for WithUnion { @@ -612,12 +483,12 @@ fn bindgen_test_layout_RealAbstractionWithTonsOfMethods() { assert_eq!( ::std::mem::size_of::(), 1usize, - concat!("Size of: ", stringify!(RealAbstractionWithTonsOfMethods)), + "Size of RealAbstractionWithTonsOfMethods", ); assert_eq!( ::std::mem::align_of::(), 1usize, - concat!("Alignment of ", stringify!(RealAbstractionWithTonsOfMethods)), + "Alignment of RealAbstractionWithTonsOfMethods", ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/class_nested.rs b/bindgen-tests/tests/expectations/tests/class_nested.rs index bfda0cc281..e3d4c2e65e 100644 --- a/bindgen-tests/tests/expectations/tests/class_nested.rs +++ b/bindgen-tests/tests/expectations/tests/class_nested.rs @@ -9,26 +9,11 @@ pub struct A { pub struct A_B { pub member_b: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_A_B() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(A_B)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(A_B)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member_b) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(A_B), "::", stringify!(member_b)), - ); -} +const _: () = { + ["Size of A_B"][::std::mem::size_of::() - 4usize]; + ["Alignment of A_B"][::std::mem::align_of::() - 4usize]; + ["Offset of field: A_B::member_b"][::std::mem::offset_of!(A_B, member_b) - 0usize]; +}; #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct A_D { @@ -44,69 +29,32 @@ impl Default for A_D { } } } -#[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::(), 4usize, concat!("Size of: ", stringify!(A))); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(A)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member_a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(member_a)), - ); -} +const _: () = { + ["Size of A"][::std::mem::size_of::() - 4usize]; + ["Alignment of A"][::std::mem::align_of::() - 4usize]; + ["Offset of field: A::member_a"][::std::mem::offset_of!(A, member_a) - 0usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct A_C { pub baz: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_A_C() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(A_C)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(A_C)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(A_C), "::", stringify!(baz)), - ); -} +const _: () = { + ["Size of A_C"][::std::mem::size_of::() - 4usize]; + ["Alignment of A_C"][::std::mem::align_of::() - 4usize]; + ["Offset of field: A_C::baz"][::std::mem::offset_of!(A_C, baz) - 0usize]; +}; extern "C" { pub static mut var: A_B; } -#[test] -fn __bindgen_test_layout_A_D_open0_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!( - "Size of template specialization: ", - stringify!(A_D < ::std::os::raw::c_int >), - ), - ); - assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(A_D < ::std::os::raw::c_int >), - ), - ); -} +const _: () = { + [ + "Size of template specialization: A_D_open0_int_close0", + ][::std::mem::size_of::>() - 4usize]; + [ + "Align of template specialization: A_D_open0_int_close0", + ][::std::mem::align_of::>() - 4usize]; +}; extern "C" { pub static mut baz: A_D<::std::os::raw::c_int>; } @@ -115,22 +63,11 @@ extern "C" { pub struct D { pub member: A_B, } -#[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::(), 4usize, concat!("Size of: ", stringify!(D))); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(D)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(D), "::", stringify!(member)), - ); -} +const _: () = { + ["Size of D"][::std::mem::size_of::() - 4usize]; + ["Alignment of D"][::std::mem::align_of::() - 4usize]; + ["Offset of field: D::member"][::std::mem::offset_of!(D, member) - 0usize]; +}; #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Templated { diff --git a/bindgen-tests/tests/expectations/tests/class_no_members.rs b/bindgen-tests/tests/expectations/tests/class_no_members.rs index d8c67ca52d..13e6410c3d 100644 --- a/bindgen-tests/tests/expectations/tests/class_no_members.rs +++ b/bindgen-tests/tests/expectations/tests/class_no_members.rs @@ -4,64 +4,32 @@ pub struct whatever { pub _address: u8, } -#[test] -fn bindgen_test_layout_whatever() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(whatever)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(whatever)), - ); -} +const _: () = { + ["Size of whatever"][::std::mem::size_of::() - 1usize]; + ["Alignment of whatever"][::std::mem::align_of::() - 1usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct whatever_child { pub _address: u8, } -#[test] -fn bindgen_test_layout_whatever_child() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(whatever_child)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(whatever_child)), - ); -} +const _: () = { + ["Size of whatever_child"][::std::mem::size_of::() - 1usize]; + ["Alignment of whatever_child"][::std::mem::align_of::() - 1usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct whatever_child_with_member { pub m_member: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_whatever_child_with_member() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(whatever_child_with_member)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(whatever_child_with_member)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(whatever_child_with_member), - "::", - stringify!(m_member), - ), - ); -} +const _: () = { + [ + "Size of whatever_child_with_member", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of whatever_child_with_member", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: whatever_child_with_member::m_member", + ][::std::mem::offset_of!(whatever_child_with_member, m_member) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/class_static.rs b/bindgen-tests/tests/expectations/tests/class_static.rs index f6f8a3b175..a1ded6bf35 100644 --- a/bindgen-tests/tests/expectations/tests/class_static.rs +++ b/bindgen-tests/tests/expectations/tests/class_static.rs @@ -12,19 +12,10 @@ extern "C" { #[link_name = "\u{1}_ZN7MyClass26example_check_no_collisionE"] pub static mut MyClass_example_check_no_collision: *const ::std::os::raw::c_int; } -#[test] -fn bindgen_test_layout_MyClass() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(MyClass)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(MyClass)), - ); -} +const _: () = { + ["Size of MyClass"][::std::mem::size_of::() - 1usize]; + ["Alignment of MyClass"][::std::mem::align_of::() - 1usize]; +}; extern "C" { #[link_name = "\u{1}_ZL26example_check_no_collision"] pub static mut example_check_no_collision: *const ::std::os::raw::c_int; diff --git a/bindgen-tests/tests/expectations/tests/class_static_const.rs b/bindgen-tests/tests/expectations/tests/class_static_const.rs index c2cd5b3e9f..68b2a8a45c 100644 --- a/bindgen-tests/tests/expectations/tests/class_static_const.rs +++ b/bindgen-tests/tests/expectations/tests/class_static_const.rs @@ -7,12 +7,7 @@ pub struct A { pub const A_a: ::std::os::raw::c_int = 0; pub const A_b: i32 = 63; pub const A_c: u32 = 255; -#[test] -fn bindgen_test_layout_A() { - assert_eq!(::std::mem::size_of::(), 1usize, concat!("Size of: ", stringify!(A))); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(A)), - ); -} +const _: () = { + ["Size of A"][::std::mem::size_of::() - 1usize]; + ["Alignment of A"][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/class_use_as.rs b/bindgen-tests/tests/expectations/tests/class_use_as.rs index f01e8acb1b..b91c32c723 100644 --- a/bindgen-tests/tests/expectations/tests/class_use_as.rs +++ b/bindgen-tests/tests/expectations/tests/class_use_as.rs @@ -5,48 +5,20 @@ pub struct whatever { pub replacement: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_whatever() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(whatever)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(whatever)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).replacement) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(whatever), "::", stringify!(replacement)), - ); -} +const _: () = { + ["Size of whatever"][::std::mem::size_of::() - 4usize]; + ["Alignment of whatever"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: whatever::replacement", + ][::std::mem::offset_of!(whatever, replacement) - 0usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct container { pub c: whatever, } -#[test] -fn bindgen_test_layout_container() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(container)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(container)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(container), "::", stringify!(c)), - ); -} +const _: () = { + ["Size of container"][::std::mem::size_of::() - 4usize]; + ["Alignment of container"][::std::mem::align_of::() - 4usize]; + ["Offset of field: container::c"][::std::mem::offset_of!(container, c) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/class_with_dtor.rs b/bindgen-tests/tests/expectations/tests/class_with_dtor.rs index 0fadc50671..01d7399e59 100644 --- a/bindgen-tests/tests/expectations/tests/class_with_dtor.rs +++ b/bindgen-tests/tests/expectations/tests/class_with_dtor.rs @@ -20,31 +20,13 @@ pub type HandleValue = HandleWithDtor<::std::os::raw::c_int>; pub struct WithoutDtor { pub shouldBeWithDtor: HandleValue, } -#[test] -fn bindgen_test_layout_WithoutDtor() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(WithoutDtor)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(WithoutDtor)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).shouldBeWithDtor) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithoutDtor), - "::", - stringify!(shouldBeWithDtor), - ), - ); -} +const _: () = { + ["Size of WithoutDtor"][::std::mem::size_of::() - 8usize]; + ["Alignment of WithoutDtor"][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: WithoutDtor::shouldBeWithDtor", + ][::std::mem::offset_of!(WithoutDtor, shouldBeWithDtor) - 0usize]; +}; impl Default for WithoutDtor { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -54,22 +36,11 @@ impl Default for WithoutDtor { } } } -#[test] -fn __bindgen_test_layout_HandleWithDtor_open0_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 8usize, - concat!( - "Size of template specialization: ", - stringify!(HandleWithDtor < ::std::os::raw::c_int >), - ), - ); - assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(HandleWithDtor < ::std::os::raw::c_int >), - ), - ); -} +const _: () = { + [ + "Size of template specialization: HandleWithDtor_open0_int_close0", + ][::std::mem::size_of::>() - 8usize]; + [ + "Align of template specialization: HandleWithDtor_open0_int_close0", + ][::std::mem::align_of::>() - 8usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/class_with_inner_struct.rs b/bindgen-tests/tests/expectations/tests/class_with_inner_struct.rs index 1b0f511230..e7483370b4 100644 --- a/bindgen-tests/tests/expectations/tests/class_with_inner_struct.rs +++ b/bindgen-tests/tests/expectations/tests/class_with_inner_struct.rs @@ -12,56 +12,26 @@ pub struct A_Segment { pub begin: ::std::os::raw::c_int, pub end: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_A_Segment() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(A_Segment)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(A_Segment)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(A_Segment), "::", stringify!(begin)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(A_Segment), "::", stringify!(end)), - ); -} +const _: () = { + ["Size of A_Segment"][::std::mem::size_of::() - 8usize]; + ["Alignment of A_Segment"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: A_Segment::begin", + ][::std::mem::offset_of!(A_Segment, begin) - 0usize]; + ["Offset of field: A_Segment::end"][::std::mem::offset_of!(A_Segment, end) - 4usize]; +}; #[repr(C)] #[derive(Copy, Clone)] pub union A__bindgen_ty_1 { pub f: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_A__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(A__bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(A__bindgen_ty_1)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(A__bindgen_ty_1), "::", stringify!(f)), - ); -} +const _: () = { + ["Size of A__bindgen_ty_1"][::std::mem::size_of::() - 4usize]; + ["Alignment of A__bindgen_ty_1"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: A__bindgen_ty_1::f", + ][::std::mem::offset_of!(A__bindgen_ty_1, f) - 0usize]; +}; impl Default for A__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -76,26 +46,13 @@ impl Default for A__bindgen_ty_1 { pub union A__bindgen_ty_2 { pub d: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_A__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(A__bindgen_ty_2)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(A__bindgen_ty_2)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(A__bindgen_ty_2), "::", stringify!(d)), - ); -} +const _: () = { + ["Size of A__bindgen_ty_2"][::std::mem::size_of::() - 4usize]; + ["Alignment of A__bindgen_ty_2"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: A__bindgen_ty_2::d", + ][::std::mem::offset_of!(A__bindgen_ty_2, d) - 0usize]; +}; impl Default for A__bindgen_ty_2 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -105,27 +62,12 @@ impl Default for A__bindgen_ty_2 { } } } -#[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::(), 12usize, concat!("Size of: ", stringify!(A))); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(A)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(c)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).named_union) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(named_union)), - ); -} +const _: () = { + ["Size of A"][::std::mem::size_of::() - 12usize]; + ["Alignment of A"][::std::mem::align_of::() - 4usize]; + ["Offset of field: A::c"][::std::mem::offset_of!(A, c) - 0usize]; + ["Offset of field: A::named_union"][::std::mem::offset_of!(A, named_union) - 4usize]; +}; impl Default for A { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -146,47 +88,19 @@ pub struct B_Segment { pub begin: ::std::os::raw::c_int, pub end: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_B_Segment() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(B_Segment)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(B_Segment)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(B_Segment), "::", stringify!(begin)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(B_Segment), "::", stringify!(end)), - ); -} -#[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::(), 4usize, concat!("Size of: ", stringify!(B))); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(B)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(B), "::", stringify!(d)), - ); -} +const _: () = { + ["Size of B_Segment"][::std::mem::size_of::() - 8usize]; + ["Alignment of B_Segment"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: B_Segment::begin", + ][::std::mem::offset_of!(B_Segment, begin) - 0usize]; + ["Offset of field: B_Segment::end"][::std::mem::offset_of!(B_Segment, end) - 4usize]; +}; +const _: () = { + ["Size of B"][::std::mem::size_of::() - 4usize]; + ["Alignment of B"][::std::mem::align_of::() - 4usize]; + ["Offset of field: B::d"][::std::mem::offset_of!(B, d) - 0usize]; +}; #[repr(i32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum StepSyntax { @@ -215,102 +129,46 @@ pub struct C__bindgen_ty_1__bindgen_ty_1 { pub mX2: f32, pub mY2: f32, } -#[test] -fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(C__bindgen_ty_1__bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C__bindgen_ty_1__bindgen_ty_1)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mX1) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(mX1), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mY1) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(mY1), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mX2) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(mX2), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mY2) as usize - ptr as usize }, - 12usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(mY2), - ), - ); -} +const _: () = { + [ + "Size of C__bindgen_ty_1__bindgen_ty_1", + ][::std::mem::size_of::() - 16usize]; + [ + "Alignment of C__bindgen_ty_1__bindgen_ty_1", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: C__bindgen_ty_1__bindgen_ty_1::mX1", + ][::std::mem::offset_of!(C__bindgen_ty_1__bindgen_ty_1, mX1) - 0usize]; + [ + "Offset of field: C__bindgen_ty_1__bindgen_ty_1::mY1", + ][::std::mem::offset_of!(C__bindgen_ty_1__bindgen_ty_1, mY1) - 4usize]; + [ + "Offset of field: C__bindgen_ty_1__bindgen_ty_1::mX2", + ][::std::mem::offset_of!(C__bindgen_ty_1__bindgen_ty_1, mX2) - 8usize]; + [ + "Offset of field: C__bindgen_ty_1__bindgen_ty_1::mY2", + ][::std::mem::offset_of!(C__bindgen_ty_1__bindgen_ty_1, mY2) - 12usize]; +}; #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct C__bindgen_ty_1__bindgen_ty_2 { pub mStepSyntax: StepSyntax, pub mSteps: ::std::os::raw::c_uint, } -#[test] -fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(C__bindgen_ty_1__bindgen_ty_2)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C__bindgen_ty_1__bindgen_ty_2)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mStepSyntax) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(mStepSyntax), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mSteps) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(mSteps), - ), - ); -} +const _: () = { + [ + "Size of C__bindgen_ty_1__bindgen_ty_2", + ][::std::mem::size_of::() - 8usize]; + [ + "Alignment of C__bindgen_ty_1__bindgen_ty_2", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: C__bindgen_ty_1__bindgen_ty_2::mStepSyntax", + ][::std::mem::offset_of!(C__bindgen_ty_1__bindgen_ty_2, mStepSyntax) - 0usize]; + [ + "Offset of field: C__bindgen_ty_1__bindgen_ty_2::mSteps", + ][::std::mem::offset_of!(C__bindgen_ty_1__bindgen_ty_2, mSteps) - 4usize]; +}; impl Default for C__bindgen_ty_1__bindgen_ty_2 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -320,31 +178,13 @@ impl Default for C__bindgen_ty_1__bindgen_ty_2 { } } } -#[test] -fn bindgen_test_layout_C__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(C__bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C__bindgen_ty_1)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mFunc) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1), - "::", - stringify!(mFunc), - ), - ); -} +const _: () = { + ["Size of C__bindgen_ty_1"][::std::mem::size_of::() - 16usize]; + ["Alignment of C__bindgen_ty_1"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: C__bindgen_ty_1::mFunc", + ][::std::mem::offset_of!(C__bindgen_ty_1, mFunc) - 0usize]; +}; impl Default for C__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -360,47 +200,19 @@ pub struct C_Segment { pub begin: ::std::os::raw::c_int, pub end: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_C_Segment() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(C_Segment)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C_Segment)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(C_Segment), "::", stringify!(begin)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(C_Segment), "::", stringify!(end)), - ); -} -#[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::(), 20usize, concat!("Size of: ", stringify!(C))); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(d)), - ); -} +const _: () = { + ["Size of C_Segment"][::std::mem::size_of::() - 8usize]; + ["Alignment of C_Segment"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: C_Segment::begin", + ][::std::mem::offset_of!(C_Segment, begin) - 0usize]; + ["Offset of field: C_Segment::end"][::std::mem::offset_of!(C_Segment, end) - 4usize]; +}; +const _: () = { + ["Size of C"][::std::mem::size_of::() - 20usize]; + ["Alignment of C"][::std::mem::align_of::() - 4usize]; + ["Offset of field: C::d"][::std::mem::offset_of!(C, d) - 0usize]; +}; impl Default for C { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/class_with_inner_struct_1_0.rs b/bindgen-tests/tests/expectations/tests/class_with_inner_struct_1_0.rs index b36faa6cf1..23afad6319 100644 --- a/bindgen-tests/tests/expectations/tests/class_with_inner_struct_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/class_with_inner_struct_1_0.rs @@ -59,25 +59,17 @@ pub struct A_Segment { fn bindgen_test_layout_A_Segment() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(A_Segment)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(A_Segment)), - ); + assert_eq!(::std::mem::size_of::(), 8usize, "Size of A_Segment"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of A_Segment"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(A_Segment), "::", stringify!(begin)), + "Offset of field: A_Segment::begin", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(A_Segment), "::", stringify!(end)), + "Offset of field: A_Segment::end", ); } impl Clone for A_Segment { @@ -98,17 +90,17 @@ fn bindgen_test_layout_A__bindgen_ty_1() { assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(A__bindgen_ty_1)), + "Size of A__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(A__bindgen_ty_1)), + "Alignment of A__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(A__bindgen_ty_1), "::", stringify!(f)), + "Offset of field: A__bindgen_ty_1::f", ); } impl Clone for A__bindgen_ty_1 { @@ -129,17 +121,17 @@ fn bindgen_test_layout_A__bindgen_ty_2() { assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(A__bindgen_ty_2)), + "Size of A__bindgen_ty_2", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(A__bindgen_ty_2)), + "Alignment of A__bindgen_ty_2", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(A__bindgen_ty_2), "::", stringify!(d)), + "Offset of field: A__bindgen_ty_2::d", ); } impl Clone for A__bindgen_ty_2 { @@ -151,21 +143,17 @@ impl Clone for A__bindgen_ty_2 { 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::(), 12usize, concat!("Size of: ", stringify!(A))); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(A)), - ); + assert_eq!(::std::mem::size_of::(), 12usize, "Size of A"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of A"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(c)), + "Offset of field: A::c", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).named_union) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(named_union)), + "Offset of field: A::named_union", ); } impl Clone for A { @@ -188,25 +176,17 @@ pub struct B_Segment { fn bindgen_test_layout_B_Segment() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(B_Segment)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(B_Segment)), - ); + assert_eq!(::std::mem::size_of::(), 8usize, "Size of B_Segment"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of B_Segment"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(B_Segment), "::", stringify!(begin)), + "Offset of field: B_Segment::begin", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(B_Segment), "::", stringify!(end)), + "Offset of field: B_Segment::end", ); } impl Clone for B_Segment { @@ -218,16 +198,12 @@ impl Clone for B_Segment { 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::(), 4usize, concat!("Size of: ", stringify!(B))); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(B)), - ); + assert_eq!(::std::mem::size_of::(), 4usize, "Size of B"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of B"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(B), "::", stringify!(d)), + "Offset of field: B::d", ); } impl Clone for B { @@ -271,52 +247,32 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_1() { assert_eq!( ::std::mem::size_of::(), 16usize, - concat!("Size of: ", stringify!(C__bindgen_ty_1__bindgen_ty_1)), + "Size of C__bindgen_ty_1__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(C__bindgen_ty_1__bindgen_ty_1)), + "Alignment of C__bindgen_ty_1__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mX1) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(mX1), - ), + "Offset of field: C__bindgen_ty_1__bindgen_ty_1::mX1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mY1) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(mY1), - ), + "Offset of field: C__bindgen_ty_1__bindgen_ty_1::mY1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mX2) as usize - ptr as usize }, 8usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(mX2), - ), + "Offset of field: C__bindgen_ty_1__bindgen_ty_1::mX2", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mY2) as usize - ptr as usize }, 12usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(mY2), - ), + "Offset of field: C__bindgen_ty_1__bindgen_ty_1::mY2", ); } impl Clone for C__bindgen_ty_1__bindgen_ty_1 { @@ -337,32 +293,22 @@ fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_2() { assert_eq!( ::std::mem::size_of::(), 8usize, - concat!("Size of: ", stringify!(C__bindgen_ty_1__bindgen_ty_2)), + "Size of C__bindgen_ty_1__bindgen_ty_2", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(C__bindgen_ty_1__bindgen_ty_2)), + "Alignment of C__bindgen_ty_1__bindgen_ty_2", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mStepSyntax) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(mStepSyntax), - ), + "Offset of field: C__bindgen_ty_1__bindgen_ty_2::mStepSyntax", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mSteps) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(mSteps), - ), + "Offset of field: C__bindgen_ty_1__bindgen_ty_2::mSteps", ); } impl Clone for C__bindgen_ty_1__bindgen_ty_2 { @@ -386,22 +332,17 @@ fn bindgen_test_layout_C__bindgen_ty_1() { assert_eq!( ::std::mem::size_of::(), 16usize, - concat!("Size of: ", stringify!(C__bindgen_ty_1)), + "Size of C__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(C__bindgen_ty_1)), + "Alignment of C__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mFunc) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(C__bindgen_ty_1), - "::", - stringify!(mFunc), - ), + "Offset of field: C__bindgen_ty_1::mFunc", ); } impl Clone for C__bindgen_ty_1 { @@ -419,25 +360,17 @@ pub struct C_Segment { fn bindgen_test_layout_C_Segment() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(C_Segment)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C_Segment)), - ); + assert_eq!(::std::mem::size_of::(), 8usize, "Size of C_Segment"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of C_Segment"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(C_Segment), "::", stringify!(begin)), + "Offset of field: C_Segment::begin", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(C_Segment), "::", stringify!(end)), + "Offset of field: C_Segment::end", ); } impl Clone for C_Segment { @@ -449,16 +382,12 @@ impl Clone for C_Segment { 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::(), 20usize, concat!("Size of: ", stringify!(C))); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C)), - ); + assert_eq!(::std::mem::size_of::(), 20usize, "Size of C"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of C"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(d)), + "Offset of field: C::d", ); } impl Clone for C { diff --git a/bindgen-tests/tests/expectations/tests/class_with_typedef.rs b/bindgen-tests/tests/expectations/tests/class_with_typedef.rs index ca9ea56ec4..2d078541bf 100644 --- a/bindgen-tests/tests/expectations/tests/class_with_typedef.rs +++ b/bindgen-tests/tests/expectations/tests/class_with_typedef.rs @@ -11,42 +11,15 @@ pub struct C { } pub type C_MyInt = ::std::os::raw::c_int; pub type C_Lookup = *const ::std::os::raw::c_char; -#[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::(), 72usize, concat!("Size of: ", stringify!(C))); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(C)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(c)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(ptr)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize }, - 16usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(arr)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 56usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(d)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).other_ptr) as usize - ptr as usize }, - 64usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(other_ptr)), - ); -} +const _: () = { + ["Size of C"][::std::mem::size_of::() - 72usize]; + ["Alignment of C"][::std::mem::align_of::() - 8usize]; + ["Offset of field: C::c"][::std::mem::offset_of!(C, c) - 0usize]; + ["Offset of field: C::ptr"][::std::mem::offset_of!(C, ptr) - 8usize]; + ["Offset of field: C::arr"][::std::mem::offset_of!(C, arr) - 16usize]; + ["Offset of field: C::d"][::std::mem::offset_of!(C, d) - 56usize]; + ["Offset of field: C::other_ptr"][::std::mem::offset_of!(C, other_ptr) - 64usize]; +}; extern "C" { #[link_name = "\u{1}_ZN1C6methodEi"] pub fn C_method(this: *mut C, c: C_MyInt); @@ -96,22 +69,11 @@ pub struct D { pub _base: C, pub ptr: *mut C_MyInt, } -#[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::(), 80usize, concat!("Size of: ", stringify!(D))); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(D)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize }, - 72usize, - concat!("Offset of field: ", stringify!(D), "::", stringify!(ptr)), - ); -} +const _: () = { + ["Size of D"][::std::mem::size_of::() - 80usize]; + ["Alignment of D"][::std::mem::align_of::() - 8usize]; + ["Offset of field: D::ptr"][::std::mem::offset_of!(D, ptr) - 72usize]; +}; impl Default for D { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/comment-indent.rs b/bindgen-tests/tests/expectations/tests/comment-indent.rs index 95fe892768..47e6ebb185 100644 --- a/bindgen-tests/tests/expectations/tests/comment-indent.rs +++ b/bindgen-tests/tests/expectations/tests/comment-indent.rs @@ -19,32 +19,14 @@ pub mod root { pub struct Foo_Bar { pub _address: u8, } - #[test] - fn bindgen_test_layout_Foo_Bar() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo_Bar)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo_Bar)), - ); - } - #[test] - fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)), - ); - } + const _: () = { + ["Size of Foo_Bar"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo_Bar"][::std::mem::align_of::() - 1usize]; + }; + const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; + }; pub mod test { #[allow(unused_imports)] use self::super::super::root; @@ -62,26 +44,13 @@ pub mod root { +------+ +-------+*/ pub member: ::std::os::raw::c_int, } - #[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::(), - 4usize, - concat!("Size of: ", stringify!(Baz)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Baz)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Baz), "::", stringify!(member)), - ); - } + const _: () = { + ["Size of Baz"][::std::mem::size_of::() - 4usize]; + ["Alignment of Baz"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: Baz::member", + ][::std::mem::offset_of!(Baz, member) - 0usize]; + }; /** I'm in an inline namespace, and as such I shouldn't get generated inside a rust module, except when the relevant option is specified. Also, this comment shouldn't be misaligned.*/ @@ -90,36 +59,18 @@ pub mod root { pub struct InInlineNS { pub _address: u8, } - #[test] - fn bindgen_test_layout_InInlineNS() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(InInlineNS)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(InInlineNS)), - ); - } + const _: () = { + ["Size of InInlineNS"][::std::mem::size_of::() - 1usize]; + ["Alignment of InInlineNS"][::std::mem::align_of::() - 1usize]; + }; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Bazz { pub _address: u8, } - #[test] - fn bindgen_test_layout_Bazz() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Bazz)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Bazz)), - ); - } + const _: () = { + ["Size of Bazz"][::std::mem::size_of::() - 1usize]; + ["Alignment of Bazz"][::std::mem::align_of::() - 1usize]; + }; } } diff --git a/bindgen-tests/tests/expectations/tests/complex.rs b/bindgen-tests/tests/expectations/tests/complex.rs index 7bcc1b9e04..b3e165ae0e 100644 --- a/bindgen-tests/tests/expectations/tests/complex.rs +++ b/bindgen-tests/tests/expectations/tests/complex.rs @@ -10,56 +10,25 @@ pub struct __BindgenComplex { pub struct TestDouble { pub mMember: __BindgenComplex, } -#[test] -fn bindgen_test_layout_TestDouble() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(TestDouble)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(TestDouble)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(TestDouble), "::", stringify!(mMember)), - ); -} +const _: () = { + ["Size of TestDouble"][::std::mem::size_of::() - 16usize]; + ["Alignment of TestDouble"][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: TestDouble::mMember", + ][::std::mem::offset_of!(TestDouble, mMember) - 0usize]; +}; #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct TestDoublePtr { pub mMember: *mut __BindgenComplex, } -#[test] -fn bindgen_test_layout_TestDoublePtr() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(TestDoublePtr)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(TestDoublePtr)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(TestDoublePtr), - "::", - stringify!(mMember), - ), - ); -} +const _: () = { + ["Size of TestDoublePtr"][::std::mem::size_of::() - 8usize]; + ["Alignment of TestDoublePtr"][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: TestDoublePtr::mMember", + ][::std::mem::offset_of!(TestDoublePtr, mMember) - 0usize]; +}; impl Default for TestDoublePtr { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -74,51 +43,25 @@ impl Default for TestDoublePtr { pub struct TestFloat { pub mMember: __BindgenComplex, } -#[test] -fn bindgen_test_layout_TestFloat() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(TestFloat)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(TestFloat)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(TestFloat), "::", stringify!(mMember)), - ); -} +const _: () = { + ["Size of TestFloat"][::std::mem::size_of::() - 8usize]; + ["Alignment of TestFloat"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: TestFloat::mMember", + ][::std::mem::offset_of!(TestFloat, mMember) - 0usize]; +}; #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct TestFloatPtr { pub mMember: *mut __BindgenComplex, } -#[test] -fn bindgen_test_layout_TestFloatPtr() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(TestFloatPtr)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(TestFloatPtr)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(TestFloatPtr), "::", stringify!(mMember)), - ); -} +const _: () = { + ["Size of TestFloatPtr"][::std::mem::size_of::() - 8usize]; + ["Alignment of TestFloatPtr"][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: TestFloatPtr::mMember", + ][::std::mem::offset_of!(TestFloatPtr, mMember) - 0usize]; +}; impl Default for TestFloatPtr { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/const-const-mut-ptr.rs b/bindgen-tests/tests/expectations/tests/const-const-mut-ptr.rs index e165b8de9b..e3bf776898 100644 --- a/bindgen-tests/tests/expectations/tests/const-const-mut-ptr.rs +++ b/bindgen-tests/tests/expectations/tests/const-const-mut-ptr.rs @@ -4,26 +4,11 @@ pub struct foo { pub bar: *const *const *mut *const ::std::os::raw::c_int, } -#[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::(), - 8usize, - concat!("Size of: ", stringify!(foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(foo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)), - ); -} +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 8usize]; + ["Alignment of foo"][::std::mem::align_of::() - 8usize]; + ["Offset of field: foo::bar"][::std::mem::offset_of!(foo, bar) - 0usize]; +}; impl Default for foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/const_array_typedef.rs b/bindgen-tests/tests/expectations/tests/const_array_typedef.rs index 9222e52596..115c934813 100644 --- a/bindgen-tests/tests/expectations/tests/const_array_typedef.rs +++ b/bindgen-tests/tests/expectations/tests/const_array_typedef.rs @@ -4,26 +4,11 @@ pub struct strct { pub field: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_strct() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(strct)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(strct)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).field) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(strct), "::", stringify!(field)), - ); -} +const _: () = { + ["Size of strct"][::std::mem::size_of::() - 4usize]; + ["Alignment of strct"][::std::mem::align_of::() - 4usize]; + ["Offset of field: strct::field"][::std::mem::offset_of!(strct, field) - 0usize]; +}; pub type typ = [strct; 1usize]; extern "C" { pub static mut w: typ; diff --git a/bindgen-tests/tests/expectations/tests/const_bool.rs b/bindgen-tests/tests/expectations/tests/const_bool.rs index 97cb7ec691..1625454a9f 100644 --- a/bindgen-tests/tests/expectations/tests/const_bool.rs +++ b/bindgen-tests/tests/expectations/tests/const_bool.rs @@ -6,14 +6,9 @@ pub struct A { pub _address: u8, } pub const A_k: bool = false; -#[test] -fn bindgen_test_layout_A() { - assert_eq!(::std::mem::size_of::(), 1usize, concat!("Size of: ", stringify!(A))); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(A)), - ); -} +const _: () = { + ["Size of A"][::std::mem::size_of::() - 1usize]; + ["Alignment of A"][::std::mem::align_of::() - 1usize]; +}; pub type foo = bool; pub const k2: foo = true; diff --git a/bindgen-tests/tests/expectations/tests/const_enum_unnamed.rs b/bindgen-tests/tests/expectations/tests/const_enum_unnamed.rs index 3648a48e28..e3484479db 100644 --- a/bindgen-tests/tests/expectations/tests/const_enum_unnamed.rs +++ b/bindgen-tests/tests/expectations/tests/const_enum_unnamed.rs @@ -18,16 +18,7 @@ pub const Foo_FOO_BAR: Foo__bindgen_ty_1 = Foo__bindgen_ty_1::FOO_BAR; pub enum Foo__bindgen_ty_1 { FOO_BAR = 10, } -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)), - ); -} +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/constified-enum-module-overflow.rs b/bindgen-tests/tests/expectations/tests/constified-enum-module-overflow.rs index 61e666d2a0..c72ecf57dd 100644 --- a/bindgen-tests/tests/expectations/tests/constified-enum-module-overflow.rs +++ b/bindgen-tests/tests/expectations/tests/constified-enum-module-overflow.rs @@ -15,45 +15,24 @@ pub type C_U = B; pub struct A { pub u: B, } -#[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::(), 1usize, concat!("Size of: ", stringify!(A))); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(A)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(u)), - ); -} -#[test] -fn __bindgen_test_layout_C_open0_A_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of template specialization: ", stringify!(C)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of template specialization: ", stringify!(C)), - ); -} -#[test] -fn __bindgen_test_layout_B_open0_A_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of template specialization: ", stringify!(B)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of template specialization: ", stringify!(B)), - ); -} +const _: () = { + ["Size of A"][::std::mem::size_of::() - 1usize]; + ["Alignment of A"][::std::mem::align_of::() - 1usize]; + ["Offset of field: A::u"][::std::mem::offset_of!(A, u) - 0usize]; +}; +const _: () = { + [ + "Size of template specialization: C_open0_A_close0", + ][::std::mem::size_of::() - 1usize]; + [ + "Align of template specialization: C_open0_A_close0", + ][::std::mem::align_of::() - 1usize]; +}; +const _: () = { + [ + "Size of template specialization: B_open0_A_close0", + ][::std::mem::size_of::() - 1usize]; + [ + "Align of template specialization: B_open0_A_close0", + ][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/constify-all-enums.rs b/bindgen-tests/tests/expectations/tests/constify-all-enums.rs index de5d949283..0447a147ff 100644 --- a/bindgen-tests/tests/expectations/tests/constify-all-enums.rs +++ b/bindgen-tests/tests/expectations/tests/constify-all-enums.rs @@ -8,26 +8,13 @@ pub type foo = ::std::os::raw::c_uint; pub struct bar { pub this_should_work: foo, } -#[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, - concat!("Size of: ", stringify!(bar)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(bar)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).this_should_work) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(bar), "::", stringify!(this_should_work)), - ); -} +const _: () = { + ["Size of bar"][::std::mem::size_of::() - 4usize]; + ["Alignment of bar"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: bar::this_should_work", + ][::std::mem::offset_of!(bar, this_should_work) - 0usize]; +}; impl Default for bar { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/constify-module-enums-basic.rs b/bindgen-tests/tests/expectations/tests/constify-module-enums-basic.rs index 7f0ea58101..6bbcda650d 100644 --- a/bindgen-tests/tests/expectations/tests/constify-module-enums-basic.rs +++ b/bindgen-tests/tests/expectations/tests/constify-module-enums-basic.rs @@ -12,26 +12,13 @@ pub use self::foo_alias1 as foo_alias2; pub struct bar { pub this_should_work: foo::Type, } -#[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, - concat!("Size of: ", stringify!(bar)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(bar)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).this_should_work) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(bar), "::", stringify!(this_should_work)), - ); -} +const _: () = { + ["Size of bar"][::std::mem::size_of::() - 4usize]; + ["Alignment of bar"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: bar::this_should_work", + ][::std::mem::offset_of!(bar, this_should_work) - 0usize]; +}; impl Default for bar { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/constify-module-enums-namespace.rs b/bindgen-tests/tests/expectations/tests/constify-module-enums-namespace.rs index d8faac4fa3..1f96f8aacc 100644 --- a/bindgen-tests/tests/expectations/tests/constify-module-enums-namespace.rs +++ b/bindgen-tests/tests/expectations/tests/constify-module-enums-namespace.rs @@ -24,34 +24,13 @@ pub mod root { pub struct bar { pub this_should_work: root::ns1::ns2::foo::Type, } - #[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, - concat!("Size of: ", stringify!(bar)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(bar)), - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).this_should_work) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(bar), - "::", - stringify!(this_should_work), - ), - ); - } + const _: () = { + ["Size of bar"][::std::mem::size_of::() - 4usize]; + ["Alignment of bar"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: bar::this_should_work", + ][::std::mem::offset_of!(bar, this_should_work) - 0usize]; + }; impl Default for bar { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/constify-module-enums-shadow-name.rs b/bindgen-tests/tests/expectations/tests/constify-module-enums-shadow-name.rs index 4780df6841..d65bcd81b7 100644 --- a/bindgen-tests/tests/expectations/tests/constify-module-enums-shadow-name.rs +++ b/bindgen-tests/tests/expectations/tests/constify-module-enums-shadow-name.rs @@ -11,26 +11,11 @@ pub mod foo { pub struct bar { pub member: foo::Type, } -#[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, - concat!("Size of: ", stringify!(bar)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(bar)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(bar), "::", stringify!(member)), - ); -} +const _: () = { + ["Size of bar"][::std::mem::size_of::() - 4usize]; + ["Alignment of bar"][::std::mem::align_of::() - 4usize]; + ["Offset of field: bar::member"][::std::mem::offset_of!(bar, member) - 0usize]; +}; impl Default for bar { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-alias.rs b/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-alias.rs index 791f2b3054..0aa58bb9a1 100644 --- a/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-alias.rs +++ b/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-alias.rs @@ -20,61 +20,18 @@ pub struct Bar { pub baz_ptr3: *mut Foo_alias2, pub baz_ptr4: *mut Foo_alias3, } -#[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::(), - 48usize, - concat!("Size of: ", stringify!(Bar)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Bar)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz1) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz1)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz2) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz2)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz3) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz3)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz4) as usize - ptr as usize }, - 12usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz4)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz_ptr1) as usize - ptr as usize }, - 16usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz_ptr1)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz_ptr2) as usize - ptr as usize }, - 24usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz_ptr2)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz_ptr3) as usize - ptr as usize }, - 32usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz_ptr3)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz_ptr4) as usize - ptr as usize }, - 40usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz_ptr4)), - ); -} +const _: () = { + ["Size of Bar"][::std::mem::size_of::() - 48usize]; + ["Alignment of Bar"][::std::mem::align_of::() - 8usize]; + ["Offset of field: Bar::baz1"][::std::mem::offset_of!(Bar, baz1) - 0usize]; + ["Offset of field: Bar::baz2"][::std::mem::offset_of!(Bar, baz2) - 4usize]; + ["Offset of field: Bar::baz3"][::std::mem::offset_of!(Bar, baz3) - 8usize]; + ["Offset of field: Bar::baz4"][::std::mem::offset_of!(Bar, baz4) - 12usize]; + ["Offset of field: Bar::baz_ptr1"][::std::mem::offset_of!(Bar, baz_ptr1) - 16usize]; + ["Offset of field: Bar::baz_ptr2"][::std::mem::offset_of!(Bar, baz_ptr2) - 24usize]; + ["Offset of field: Bar::baz_ptr3"][::std::mem::offset_of!(Bar, baz_ptr3) - 32usize]; + ["Offset of field: Bar::baz_ptr4"][::std::mem::offset_of!(Bar, baz_ptr4) - 40usize]; +}; impl Default for Bar { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs b/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs index 363768a0d0..b12bfab49e 100644 --- a/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs +++ b/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs @@ -10,31 +10,12 @@ pub struct Bar { pub baz1: one_Foo::Type, pub baz2: *mut one_Foo::Type, } -#[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, - concat!("Size of: ", stringify!(Bar)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Bar)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz1) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz1)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz2) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz2)), - ); -} +const _: () = { + ["Size of Bar"][::std::mem::size_of::() - 16usize]; + ["Alignment of Bar"][::std::mem::align_of::() - 8usize]; + ["Offset of field: Bar::baz1"][::std::mem::offset_of!(Bar, baz1) - 0usize]; + ["Offset of field: Bar::baz2"][::std::mem::offset_of!(Bar, baz2) - 8usize]; +}; impl Default for Bar { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/constify-module-enums-types.rs b/bindgen-tests/tests/expectations/tests/constify-module-enums-types.rs index e34624c5cb..24b6b21fa5 100644 --- a/bindgen-tests/tests/expectations/tests/constify-module-enums-types.rs +++ b/bindgen-tests/tests/expectations/tests/constify-module-enums-types.rs @@ -45,71 +45,20 @@ pub struct bar { pub member9: anon_enum_alias2, pub member10: anon_enum_alias3, } -#[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::(), - 48usize, - concat!("Size of: ", stringify!(bar)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(bar)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member1) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(bar), "::", stringify!(member1)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member2) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(bar), "::", stringify!(member2)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member3) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(bar), "::", stringify!(member3)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member4) as usize - ptr as usize }, - 12usize, - concat!("Offset of field: ", stringify!(bar), "::", stringify!(member4)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member5) as usize - ptr as usize }, - 16usize, - concat!("Offset of field: ", stringify!(bar), "::", stringify!(member5)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member6) as usize - ptr as usize }, - 24usize, - concat!("Offset of field: ", stringify!(bar), "::", stringify!(member6)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member7) as usize - ptr as usize }, - 32usize, - concat!("Offset of field: ", stringify!(bar), "::", stringify!(member7)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member8) as usize - ptr as usize }, - 36usize, - concat!("Offset of field: ", stringify!(bar), "::", stringify!(member8)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member9) as usize - ptr as usize }, - 40usize, - concat!("Offset of field: ", stringify!(bar), "::", stringify!(member9)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member10) as usize - ptr as usize }, - 44usize, - concat!("Offset of field: ", stringify!(bar), "::", stringify!(member10)), - ); -} +const _: () = { + ["Size of bar"][::std::mem::size_of::() - 48usize]; + ["Alignment of bar"][::std::mem::align_of::() - 8usize]; + ["Offset of field: bar::member1"][::std::mem::offset_of!(bar, member1) - 0usize]; + ["Offset of field: bar::member2"][::std::mem::offset_of!(bar, member2) - 4usize]; + ["Offset of field: bar::member3"][::std::mem::offset_of!(bar, member3) - 8usize]; + ["Offset of field: bar::member4"][::std::mem::offset_of!(bar, member4) - 12usize]; + ["Offset of field: bar::member5"][::std::mem::offset_of!(bar, member5) - 16usize]; + ["Offset of field: bar::member6"][::std::mem::offset_of!(bar, member6) - 24usize]; + ["Offset of field: bar::member7"][::std::mem::offset_of!(bar, member7) - 32usize]; + ["Offset of field: bar::member8"][::std::mem::offset_of!(bar, member8) - 36usize]; + ["Offset of field: bar::member9"][::std::mem::offset_of!(bar, member9) - 40usize]; + ["Offset of field: bar::member10"][::std::mem::offset_of!(bar, member10) - 44usize]; +}; impl Default for bar { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -124,26 +73,11 @@ impl Default for bar { pub struct Baz { pub member1: ns2_Foo::Type, } -#[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::(), - 4usize, - concat!("Size of: ", stringify!(Baz)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Baz)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member1) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Baz), "::", stringify!(member1)), - ); -} +const _: () = { + ["Size of Baz"][::std::mem::size_of::() - 4usize]; + ["Alignment of Baz"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Baz::member1"][::std::mem::offset_of!(Baz, member1) - 0usize]; +}; impl Default for Baz { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -163,26 +97,11 @@ pub mod one_Foo { pub struct Bar { pub baz: *mut one_Foo::Type, } -#[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::(), - 8usize, - concat!("Size of: ", stringify!(Bar)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Bar)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz)), - ); -} +const _: () = { + ["Size of Bar"][::std::mem::size_of::() - 8usize]; + ["Alignment of Bar"][::std::mem::align_of::() - 8usize]; + ["Offset of field: Bar::baz"][::std::mem::offset_of!(Bar, baz) - 0usize]; +}; impl Default for Bar { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/constructor-tp.rs b/bindgen-tests/tests/expectations/tests/constructor-tp.rs index 5f3be0b4d9..30cbd86c18 100644 --- a/bindgen-tests/tests/expectations/tests/constructor-tp.rs +++ b/bindgen-tests/tests/expectations/tests/constructor-tp.rs @@ -9,19 +9,10 @@ pub struct Foo { pub struct Bar { pub _address: u8, } -#[test] -fn bindgen_test_layout_Bar() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Bar)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Bar)), - ); -} +const _: () = { + ["Size of Bar"][::std::mem::size_of::() - 1usize]; + ["Alignment of Bar"][::std::mem::align_of::() - 1usize]; +}; extern "C" { #[link_name = "\u{1}_ZN3BarC1Ev"] pub fn Bar_Bar(this: *mut Bar); diff --git a/bindgen-tests/tests/expectations/tests/constructors.rs b/bindgen-tests/tests/expectations/tests/constructors.rs index 75c05d3050..aa54ae4c4a 100644 --- a/bindgen-tests/tests/expectations/tests/constructors.rs +++ b/bindgen-tests/tests/expectations/tests/constructors.rs @@ -4,19 +4,10 @@ pub struct TestOverload { pub _address: u8, } -#[test] -fn bindgen_test_layout_TestOverload() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(TestOverload)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(TestOverload)), - ); -} +const _: () = { + ["Size of TestOverload"][::std::mem::size_of::() - 1usize]; + ["Alignment of TestOverload"][::std::mem::align_of::() - 1usize]; +}; extern "C" { #[link_name = "\u{1}_ZN12TestOverloadC1Ei"] pub fn TestOverload_TestOverload( @@ -47,19 +38,12 @@ impl TestOverload { pub struct TestPublicNoArgs { pub _address: u8, } -#[test] -fn bindgen_test_layout_TestPublicNoArgs() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(TestPublicNoArgs)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(TestPublicNoArgs)), - ); -} +const _: () = { + ["Size of TestPublicNoArgs"][::std::mem::size_of::() - 1usize]; + [ + "Alignment of TestPublicNoArgs", + ][::std::mem::align_of::() - 1usize]; +}; extern "C" { #[link_name = "\u{1}_ZN16TestPublicNoArgsC1Ev"] pub fn TestPublicNoArgs_TestPublicNoArgs(this: *mut TestPublicNoArgs); diff --git a/bindgen-tests/tests/expectations/tests/constructors_1_33.rs b/bindgen-tests/tests/expectations/tests/constructors_1_33.rs index 5d523e848e..0563b4e65d 100644 --- a/bindgen-tests/tests/expectations/tests/constructors_1_33.rs +++ b/bindgen-tests/tests/expectations/tests/constructors_1_33.rs @@ -6,15 +6,11 @@ pub struct TestOverload { } #[test] fn bindgen_test_layout_TestOverload() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(TestOverload)), - ); + assert_eq!(::std::mem::size_of::(), 1usize, "Size of TestOverload"); assert_eq!( ::std::mem::align_of::(), 1usize, - concat!("Alignment of ", stringify!(TestOverload)), + "Alignment of TestOverload", ); } extern "C" { @@ -54,12 +50,12 @@ fn bindgen_test_layout_TestPublicNoArgs() { assert_eq!( ::std::mem::size_of::(), 1usize, - concat!("Size of: ", stringify!(TestPublicNoArgs)), + "Size of TestPublicNoArgs", ); assert_eq!( ::std::mem::align_of::(), 1usize, - concat!("Alignment of ", stringify!(TestPublicNoArgs)), + "Alignment of TestPublicNoArgs", ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/contains-vs-inherits-zero-sized.rs b/bindgen-tests/tests/expectations/tests/contains-vs-inherits-zero-sized.rs index 70a4180757..8cec58751c 100644 --- a/bindgen-tests/tests/expectations/tests/contains-vs-inherits-zero-sized.rs +++ b/bindgen-tests/tests/expectations/tests/contains-vs-inherits-zero-sized.rs @@ -5,19 +5,10 @@ pub struct Empty { pub _address: u8, } -#[test] -fn bindgen_test_layout_Empty() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Empty)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Empty)), - ); -} +const _: () = { + ["Size of Empty"][::std::mem::size_of::() - 1usize]; + ["Alignment of Empty"][::std::mem::align_of::() - 1usize]; +}; /** This should not get an `_address` byte, so `sizeof(Inherits)` should be `1`.*/ #[repr(C)] @@ -25,26 +16,11 @@ fn bindgen_test_layout_Empty() { pub struct Inherits { pub b: bool, } -#[test] -fn bindgen_test_layout_Inherits() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Inherits)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Inherits)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Inherits), "::", stringify!(b)), - ); -} +const _: () = { + ["Size of Inherits"][::std::mem::size_of::() - 1usize]; + ["Alignment of Inherits"][::std::mem::align_of::() - 1usize]; + ["Offset of field: Inherits::b"][::std::mem::offset_of!(Inherits, b) - 0usize]; +}; /** This should not get an `_address` byte, but contains `Empty` which *does* get one, so `sizeof(Contains)` should be `1 + 1`.*/ #[repr(C)] @@ -53,28 +29,11 @@ pub struct Contains { pub empty: Empty, pub b: bool, } -#[test] -fn bindgen_test_layout_Contains() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 2usize, - concat!("Size of: ", stringify!(Contains)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Contains)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).empty) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Contains), "::", stringify!(empty)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 1usize, - concat!("Offset of field: ", stringify!(Contains), "::", stringify!(b)), - ); -} +const _: () = { + ["Size of Contains"][::std::mem::size_of::() - 2usize]; + ["Alignment of Contains"][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: Contains::empty", + ][::std::mem::offset_of!(Contains, empty) - 0usize]; + ["Offset of field: Contains::b"][::std::mem::offset_of!(Contains, b) - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/convert-floats.rs b/bindgen-tests/tests/expectations/tests/convert-floats.rs index 3f45f76f5d..bef0f6e5b7 100644 --- a/bindgen-tests/tests/expectations/tests/convert-floats.rs +++ b/bindgen-tests/tests/expectations/tests/convert-floats.rs @@ -15,51 +15,20 @@ pub struct foo { pub complexFloat: __BindgenComplex<::std::os::raw::c_float>, pub complexDouble: __BindgenComplex<::std::os::raw::c_double>, } -#[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::(), - 48usize, - concat!("Size of: ", stringify!(foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(foo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(baz)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bazz) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bazz)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bazzz) as usize - ptr as usize }, - 16usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bazzz)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).complexFloat) as usize - ptr as usize }, - 24usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(complexFloat)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).complexDouble) as usize - ptr as usize }, - 32usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(complexDouble)), - ); -} +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 48usize]; + ["Alignment of foo"][::std::mem::align_of::() - 8usize]; + ["Offset of field: foo::bar"][::std::mem::offset_of!(foo, bar) - 0usize]; + ["Offset of field: foo::baz"][::std::mem::offset_of!(foo, baz) - 4usize]; + ["Offset of field: foo::bazz"][::std::mem::offset_of!(foo, bazz) - 8usize]; + ["Offset of field: foo::bazzz"][::std::mem::offset_of!(foo, bazzz) - 16usize]; + [ + "Offset of field: foo::complexFloat", + ][::std::mem::offset_of!(foo, complexFloat) - 24usize]; + [ + "Offset of field: foo::complexDouble", + ][::std::mem::offset_of!(foo, complexDouble) - 32usize]; +}; impl Default for foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/cpp-empty-layout.rs b/bindgen-tests/tests/expectations/tests/cpp-empty-layout.rs index d51ccfa80c..30de3dce72 100644 --- a/bindgen-tests/tests/expectations/tests/cpp-empty-layout.rs +++ b/bindgen-tests/tests/expectations/tests/cpp-empty-layout.rs @@ -4,16 +4,7 @@ pub struct Foo { pub _address: u8, } -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)), - ); -} +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/crtp.rs b/bindgen-tests/tests/expectations/tests/crtp.rs index 6a953d7704..0685411bf8 100644 --- a/bindgen-tests/tests/expectations/tests/crtp.rs +++ b/bindgen-tests/tests/expectations/tests/crtp.rs @@ -9,19 +9,10 @@ pub struct Base { pub struct Derived { pub _address: u8, } -#[test] -fn bindgen_test_layout_Derived() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Derived)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Derived)), - ); -} +const _: () = { + ["Size of Derived"][::std::mem::size_of::() - 1usize]; + ["Alignment of Derived"][::std::mem::align_of::() - 1usize]; +}; #[repr(C)] #[derive(Debug, Default)] pub struct BaseWithDestructor { @@ -32,42 +23,27 @@ pub struct BaseWithDestructor { pub struct DerivedFromBaseWithDestructor { pub _address: u8, } -#[test] -fn bindgen_test_layout_DerivedFromBaseWithDestructor() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(DerivedFromBaseWithDestructor)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(DerivedFromBaseWithDestructor)), - ); -} -#[test] -fn __bindgen_test_layout_Base_open0_Derived_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of template specialization: ", stringify!(Base)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of template specialization: ", stringify!(Base)), - ); -} -#[test] -fn __bindgen_test_layout_BaseWithDestructor_open0_DerivedFromBaseWithDestructor_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of template specialization: ", stringify!(BaseWithDestructor)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of template specialization: ", stringify!(BaseWithDestructor)), - ); -} +const _: () = { + [ + "Size of DerivedFromBaseWithDestructor", + ][::std::mem::size_of::() - 1usize]; + [ + "Alignment of DerivedFromBaseWithDestructor", + ][::std::mem::align_of::() - 1usize]; +}; +const _: () = { + [ + "Size of template specialization: Base_open0_Derived_close0", + ][::std::mem::size_of::() - 1usize]; + [ + "Align of template specialization: Base_open0_Derived_close0", + ][::std::mem::align_of::() - 1usize]; +}; +const _: () = { + [ + "Size of template specialization: BaseWithDestructor_open0_DerivedFromBaseWithDestructor_close0", + ][::std::mem::size_of::() - 1usize]; + [ + "Align of template specialization: BaseWithDestructor_open0_DerivedFromBaseWithDestructor_close0", + ][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/ctypes-prefix-path.rs b/bindgen-tests/tests/expectations/tests/ctypes-prefix-path.rs index c2da364afa..14b4917f0b 100644 --- a/bindgen-tests/tests/expectations/tests/ctypes-prefix-path.rs +++ b/bindgen-tests/tests/expectations/tests/ctypes-prefix-path.rs @@ -13,36 +13,13 @@ pub struct foo { pub b: libc::foo::c_int, pub bar: *mut libc::foo::c_void, } -#[test] -fn bindgen_test_layout_foo() { - const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::core::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(foo)), - ); - assert_eq!( - ::core::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(foo)), - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)), - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)), - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)), - ); -} +const _: () = { + ["Size of foo"][::core::mem::size_of::() - 16usize]; + ["Alignment of foo"][::core::mem::align_of::() - 8usize]; + ["Offset of field: foo::a"][::core::mem::offset_of!(foo, a) - 0usize]; + ["Offset of field: foo::b"][::core::mem::offset_of!(foo, b) - 4usize]; + ["Offset of field: foo::bar"][::core::mem::offset_of!(foo, bar) - 8usize]; +}; impl Default for foo { fn default() -> Self { let mut s = ::core::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/default-template-parameter.rs b/bindgen-tests/tests/expectations/tests/default-template-parameter.rs index 3371bad292..a1fdcf9016 100644 --- a/bindgen-tests/tests/expectations/tests/default-template-parameter.rs +++ b/bindgen-tests/tests/expectations/tests/default-template-parameter.rs @@ -16,25 +16,14 @@ impl Default for Foo { } } } -#[test] -fn __bindgen_test_layout_Foo_open0_bool__int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 8usize, - concat!( - "Size of template specialization: ", - stringify!(Foo < bool, ::std::os::raw::c_int >), - ), - ); - assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(Foo < bool, ::std::os::raw::c_int >), - ), - ); -} +const _: () = { + [ + "Size of template specialization: Foo_open0_bool__int_close0", + ][::std::mem::size_of::>() - 8usize]; + [ + "Align of template specialization: Foo_open0_bool__int_close0", + ][::std::mem::align_of::>() - 4usize]; +}; extern "C" { #[link_name = "\u{1}_ZL3bar"] pub static mut bar: Foo; diff --git a/bindgen-tests/tests/expectations/tests/deleted-function.rs b/bindgen-tests/tests/expectations/tests/deleted-function.rs index 3d29bd872c..3abcf618cf 100644 --- a/bindgen-tests/tests/expectations/tests/deleted-function.rs +++ b/bindgen-tests/tests/expectations/tests/deleted-function.rs @@ -4,15 +4,10 @@ pub struct A { pub _address: u8, } -#[test] -fn bindgen_test_layout_A() { - assert_eq!(::std::mem::size_of::(), 1usize, concat!("Size of: ", stringify!(A))); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(A)), - ); -} +const _: () = { + ["Size of A"][::std::mem::size_of::() - 1usize]; + ["Alignment of A"][::std::mem::align_of::() - 1usize]; +}; extern "C" { #[link_name = "\u{1}_ZN1A17inline_definitionEv"] pub fn A_inline_definition(this: *mut A); @@ -36,29 +31,19 @@ impl A { pub struct B { pub _address: u8, } -#[test] -fn bindgen_test_layout_B() { - assert_eq!(::std::mem::size_of::(), 1usize, concat!("Size of: ", stringify!(B))); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(B)), - ); -} +const _: () = { + ["Size of B"][::std::mem::size_of::() - 1usize]; + ["Alignment of B"][::std::mem::align_of::() - 1usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct C { pub _address: u8, } -#[test] -fn bindgen_test_layout_C() { - assert_eq!(::std::mem::size_of::(), 1usize, concat!("Size of: ", stringify!(C))); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(C)), - ); -} +const _: () = { + ["Size of C"][::std::mem::size_of::() - 1usize]; + ["Alignment of C"][::std::mem::align_of::() - 1usize]; +}; extern "C" { #[link_name = "\u{1}_ZN1CC1ERS_"] pub fn C_C(this: *mut C, arg1: *mut C); 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 e3236f58fe..feded416f7 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 @@ -98,20 +98,12 @@ pub struct Foo { 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, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Foo)), - ); + 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, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(large)), + "Offset of field: Foo::large", ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/derive-clone.rs b/bindgen-tests/tests/expectations/tests/derive-clone.rs index b11287453c..d903afa06f 100644 --- a/bindgen-tests/tests/expectations/tests/derive-clone.rs +++ b/bindgen-tests/tests/expectations/tests/derive-clone.rs @@ -12,22 +12,17 @@ fn bindgen_test_layout_ShouldDeriveClone() { assert_eq!( ::std::mem::size_of::(), 132usize, - concat!("Size of: ", stringify!(ShouldDeriveClone)), + "Size of ShouldDeriveClone", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(ShouldDeriveClone)), + "Alignment of ShouldDeriveClone", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).large) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldDeriveClone), - "::", - stringify!(large), - ), + "Offset of field: ShouldDeriveClone::large", ); } impl Default for ShouldDeriveClone { diff --git a/bindgen-tests/tests/expectations/tests/derive-clone_1_0.rs b/bindgen-tests/tests/expectations/tests/derive-clone_1_0.rs index 2702c94793..7b3a00738c 100644 --- a/bindgen-tests/tests/expectations/tests/derive-clone_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/derive-clone_1_0.rs @@ -13,22 +13,17 @@ fn bindgen_test_layout_ShouldImplClone() { assert_eq!( ::std::mem::size_of::(), 132usize, - concat!("Size of: ", stringify!(ShouldImplClone)), + "Size of ShouldImplClone", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(ShouldImplClone)), + "Alignment of ShouldImplClone", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).large) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldImplClone), - "::", - stringify!(large), - ), + "Offset of field: ShouldImplClone::large", ); } impl Clone for ShouldImplClone { diff --git a/bindgen-tests/tests/expectations/tests/derive-custom-cli.rs b/bindgen-tests/tests/expectations/tests/derive-custom-cli.rs index 5784684556..48dbede146 100644 --- a/bindgen-tests/tests/expectations/tests/derive-custom-cli.rs +++ b/bindgen-tests/tests/expectations/tests/derive-custom-cli.rs @@ -4,26 +4,13 @@ pub struct foo_struct { pub inner: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_foo_struct() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo_struct)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo_struct)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).inner) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo_struct), "::", stringify!(inner)), - ); -} +const _: () = { + ["Size of foo_struct"][::std::mem::size_of::() - 4usize]; + ["Alignment of foo_struct"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: foo_struct::inner", + ][::std::mem::offset_of!(foo_struct, inner) - 0usize]; +}; #[repr(u32)] #[derive(Clone, Hash, PartialEq, Eq, Copy)] pub enum foo_enum { @@ -35,52 +22,20 @@ pub union foo_union { pub fst: ::std::mem::ManuallyDrop<::std::os::raw::c_int>, pub snd: ::std::mem::ManuallyDrop, } -#[test] -fn bindgen_test_layout_foo_union() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo_union)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo_union)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).fst) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo_union), "::", stringify!(fst)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).snd) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo_union), "::", stringify!(snd)), - ); -} +const _: () = { + ["Size of foo_union"][::std::mem::size_of::() - 4usize]; + ["Alignment of foo_union"][::std::mem::align_of::() - 4usize]; + ["Offset of field: foo_union::fst"][::std::mem::offset_of!(foo_union, fst) - 0usize]; + ["Offset of field: foo_union::snd"][::std::mem::offset_of!(foo_union, snd) - 0usize]; +}; #[repr(C)] pub struct non_matching { pub inner: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_non_matching() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(non_matching)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(non_matching)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).inner) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(non_matching), "::", stringify!(inner)), - ); -} +const _: () = { + ["Size of non_matching"][::std::mem::size_of::() - 4usize]; + ["Alignment of non_matching"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: non_matching::inner", + ][::std::mem::offset_of!(non_matching, inner) - 0usize]; +}; 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 54b44b33d2..64c20f91ba 100644 --- a/bindgen-tests/tests/expectations/tests/derive-debug-bitfield-core.rs +++ b/bindgen-tests/tests/expectations/tests/derive-debug-bitfield-core.rs @@ -95,20 +95,12 @@ pub struct C { 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, - concat!("Size of: ", stringify!(C)), - ); - assert_eq!( - ::core::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C)), - ); + 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, - concat!("Offset of field: ", stringify!(C), "::", stringify!(large_array)), + "Offset of field: C::large_array", ); } impl Default for C { diff --git a/bindgen-tests/tests/expectations/tests/derive-debug-bitfield.rs b/bindgen-tests/tests/expectations/tests/derive-debug-bitfield.rs index 828383af4e..0471b48bfa 100644 --- a/bindgen-tests/tests/expectations/tests/derive-debug-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/derive-debug-bitfield.rs @@ -94,20 +94,12 @@ pub struct C { 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, - concat!("Size of: ", stringify!(C)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C)), - ); + 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, - concat!("Offset of field: ", stringify!(C), "::", stringify!(large_array)), + "Offset of field: C::large_array", ); } impl Default for C { 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 2ca5a839ed..9077201a77 100644 --- a/bindgen-tests/tests/expectations/tests/derive-debug-function-pointer.rs +++ b/bindgen-tests/tests/expectations/tests/derive-debug-function-pointer.rs @@ -12,25 +12,17 @@ pub type Nice_Function = ::std::option::Option< 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, - concat!("Size of: ", stringify!(Nice)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Nice)), - ); + 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, - concat!("Offset of field: ", stringify!(Nice), "::", stringify!(pointer)), + "Offset of field: Nice::pointer", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(Nice), "::", stringify!(large_array)), + "Offset of field: Nice::large_array", ); } impl Default for Nice { diff --git a/bindgen-tests/tests/expectations/tests/derive-debug-mangle-name.rs b/bindgen-tests/tests/expectations/tests/derive-debug-mangle-name.rs index b93a425af6..c61fb0149a 100644 --- a/bindgen-tests/tests/expectations/tests/derive-debug-mangle-name.rs +++ b/bindgen-tests/tests/expectations/tests/derive-debug-mangle-name.rs @@ -12,41 +12,20 @@ pub union perf_event_attr__bindgen_ty_1 { pub b: ::std::os::raw::c_int, pub c: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_perf_event_attr__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(perf_event_attr__bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(perf_event_attr__bindgen_ty_1)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(perf_event_attr__bindgen_ty_1), - "::", - stringify!(b), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(perf_event_attr__bindgen_ty_1), - "::", - stringify!(c), - ), - ); -} +const _: () = { + [ + "Size of perf_event_attr__bindgen_ty_1", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of perf_event_attr__bindgen_ty_1", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: perf_event_attr__bindgen_ty_1::b", + ][::std::mem::offset_of!(perf_event_attr__bindgen_ty_1, b) - 0usize]; + [ + "Offset of field: perf_event_attr__bindgen_ty_1::c", + ][::std::mem::offset_of!(perf_event_attr__bindgen_ty_1, c) - 0usize]; +}; impl Default for perf_event_attr__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -61,36 +40,16 @@ impl ::std::fmt::Debug for perf_event_attr__bindgen_ty_1 { write!(f, "perf_event_attr__bindgen_ty_1 {{ union }}") } } -#[test] -fn bindgen_test_layout_perf_event_attr() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 12usize, - concat!("Size of: ", stringify!(perf_event_attr)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(perf_event_attr)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(perf_event_attr), - "::", - stringify!(type_), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(perf_event_attr), "::", stringify!(a)), - ); -} +const _: () = { + ["Size of perf_event_attr"][::std::mem::size_of::() - 12usize]; + ["Alignment of perf_event_attr"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: perf_event_attr::type_", + ][::std::mem::offset_of!(perf_event_attr, type_) - 0usize]; + [ + "Offset of field: perf_event_attr::a", + ][::std::mem::offset_of!(perf_event_attr, a) - 4usize]; +}; impl Default for perf_event_attr { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); 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 812bf0283f..d586278614 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 @@ -7,20 +7,12 @@ pub struct Instance { 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, - concat!("Size of: ", stringify!(Instance)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Instance)), - ); + 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, - concat!("Offset of field: ", stringify!(Instance), "::", stringify!(val)), + "Offset of field: Instance::val", ); } impl Default for Instance { diff --git a/bindgen-tests/tests/expectations/tests/derive-debug-opaque.rs b/bindgen-tests/tests/expectations/tests/derive-debug-opaque.rs index b214562c0f..13ddfd5ada 100644 --- a/bindgen-tests/tests/expectations/tests/derive-debug-opaque.rs +++ b/bindgen-tests/tests/expectations/tests/derive-debug-opaque.rs @@ -6,16 +6,8 @@ pub struct Opaque { } #[test] fn bindgen_test_layout_Opaque() { - assert_eq!( - ::std::mem::size_of::(), - 164usize, - concat!("Size of: ", stringify!(Opaque)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Opaque)), - ); + assert_eq!(::std::mem::size_of::(), 164usize, "Size of Opaque"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of Opaque"); } impl Default for Opaque { fn default() -> Self { @@ -39,20 +31,12 @@ pub struct OpaqueUser { 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, - concat!("Size of: ", stringify!(OpaqueUser)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(OpaqueUser)), - ); + 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, - concat!("Offset of field: ", stringify!(OpaqueUser), "::", stringify!(opaque)), + "Offset of field: OpaqueUser::opaque", ); } impl Default for OpaqueUser { diff --git a/bindgen-tests/tests/expectations/tests/derive-default-and-blocklist.rs b/bindgen-tests/tests/expectations/tests/derive-default-and-blocklist.rs index 131df71c22..75404fcc0b 100644 --- a/bindgen-tests/tests/expectations/tests/derive-default-and-blocklist.rs +++ b/bindgen-tests/tests/expectations/tests/derive-default-and-blocklist.rs @@ -6,31 +6,17 @@ pub struct BlocklistMe(u8); pub struct ShouldNotDeriveDefault { pub a: BlocklistMe, } -#[test] -fn bindgen_test_layout_ShouldNotDeriveDefault() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(ShouldNotDeriveDefault)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(ShouldNotDeriveDefault)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldNotDeriveDefault), - "::", - stringify!(a), - ), - ); -} +const _: () = { + [ + "Size of ShouldNotDeriveDefault", + ][::std::mem::size_of::() - 1usize]; + [ + "Alignment of ShouldNotDeriveDefault", + ][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: ShouldNotDeriveDefault::a", + ][::std::mem::offset_of!(ShouldNotDeriveDefault, a) - 0usize]; +}; impl Default for ShouldNotDeriveDefault { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/derive-fn-ptr.rs b/bindgen-tests/tests/expectations/tests/derive-fn-ptr.rs index 395e31c5b5..3e0b984bbc 100644 --- a/bindgen-tests/tests/expectations/tests/derive-fn-ptr.rs +++ b/bindgen-tests/tests/expectations/tests/derive-fn-ptr.rs @@ -24,26 +24,11 @@ pub type my_fun_t = ::std::option::Option< pub struct Foo { pub callback: my_fun_t, } -#[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::(), - 8usize, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Foo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).callback) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(callback)), - ); -} +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 8usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 8usize]; + ["Offset of field: Foo::callback"][::std::mem::offset_of!(Foo, callback) - 0usize]; +}; pub type my_fun2_t = ::std::option::Option< unsafe extern "C" fn( arg1: ::std::os::raw::c_int, @@ -65,23 +50,8 @@ pub type my_fun2_t = ::std::option::Option< pub struct Bar { pub callback: my_fun2_t, } -#[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::(), - 8usize, - concat!("Size of: ", stringify!(Bar)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Bar)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).callback) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(callback)), - ); -} +const _: () = { + ["Size of Bar"][::std::mem::size_of::() - 8usize]; + ["Alignment of Bar"][::std::mem::align_of::() - 8usize]; + ["Offset of field: Bar::callback"][::std::mem::offset_of!(Bar, callback) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/derive-hash-and-blocklist.rs b/bindgen-tests/tests/expectations/tests/derive-hash-and-blocklist.rs index 98b3a11f85..092244d5ba 100644 --- a/bindgen-tests/tests/expectations/tests/derive-hash-and-blocklist.rs +++ b/bindgen-tests/tests/expectations/tests/derive-hash-and-blocklist.rs @@ -5,31 +5,17 @@ pub struct BlocklistMe(u8); pub struct ShouldNotDeriveHash { pub a: BlocklistMe, } -#[test] -fn bindgen_test_layout_ShouldNotDeriveHash() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(ShouldNotDeriveHash)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(ShouldNotDeriveHash)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldNotDeriveHash), - "::", - stringify!(a), - ), - ); -} +const _: () = { + [ + "Size of ShouldNotDeriveHash", + ][::std::mem::size_of::() - 1usize]; + [ + "Alignment of ShouldNotDeriveHash", + ][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: ShouldNotDeriveHash::a", + ][::std::mem::offset_of!(ShouldNotDeriveHash, a) - 0usize]; +}; impl Default for ShouldNotDeriveHash { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/derive-hash-blocklisting.rs b/bindgen-tests/tests/expectations/tests/derive-hash-blocklisting.rs index dd6f3e26b7..d8b65e8e09 100644 --- a/bindgen-tests/tests/expectations/tests/derive-hash-blocklisting.rs +++ b/bindgen-tests/tests/expectations/tests/derive-hash-blocklisting.rs @@ -11,26 +11,13 @@ pub struct Blocklisted { pub struct AllowlistedOne { pub a: Blocklisted<::std::os::raw::c_int>, } -#[test] -fn bindgen_test_layout_AllowlistedOne() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(AllowlistedOne)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(AllowlistedOne)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(AllowlistedOne), "::", stringify!(a)), - ); -} +const _: () = { + ["Size of AllowlistedOne"][::std::mem::size_of::() - 4usize]; + ["Alignment of AllowlistedOne"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: AllowlistedOne::a", + ][::std::mem::offset_of!(AllowlistedOne, a) - 0usize]; +}; impl Default for AllowlistedOne { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -45,26 +32,13 @@ impl Default for AllowlistedOne { pub struct AllowlistedTwo { pub b: Blocklisted, } -#[test] -fn bindgen_test_layout_AllowlistedTwo() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(AllowlistedTwo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(AllowlistedTwo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(AllowlistedTwo), "::", stringify!(b)), - ); -} +const _: () = { + ["Size of AllowlistedTwo"][::std::mem::size_of::() - 4usize]; + ["Alignment of AllowlistedTwo"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: AllowlistedTwo::b", + ][::std::mem::offset_of!(AllowlistedTwo, b) - 0usize]; +}; impl Default for AllowlistedTwo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs index 25b2ad6b6f..ea434ae83b 100644 --- a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs +++ b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs @@ -11,48 +11,20 @@ pub struct foo__bindgen_ty_1 { pub a: f32, pub b: f32, } -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)), - ); -} -#[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::(), - 8usize, - concat!("Size of: ", stringify!(foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)), - ); -} +const _: () = { + ["Size of foo__bindgen_ty_1"][::std::mem::size_of::() - 8usize]; + [ + "Alignment of foo__bindgen_ty_1", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: foo__bindgen_ty_1::a", + ][::std::mem::offset_of!(foo__bindgen_ty_1, a) - 0usize]; + [ + "Offset of field: foo__bindgen_ty_1::b", + ][::std::mem::offset_of!(foo__bindgen_ty_1, b) - 4usize]; +}; +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 8usize]; + ["Alignment of foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: foo::bar"][::std::mem::offset_of!(foo, bar) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-float-array.rs b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-float-array.rs index aa990eceb4..b22ce29e48 100644 --- a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-float-array.rs +++ b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-float-array.rs @@ -5,23 +5,8 @@ pub struct foo { pub bar: [f32; 3usize], } -#[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::(), - 12usize, - concat!("Size of: ", stringify!(foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)), - ); -} +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 12usize]; + ["Alignment of foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: foo::bar"][::std::mem::offset_of!(foo, bar) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs index d1b4c9004a..657f72ece4 100644 --- a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs +++ b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs @@ -35,74 +35,28 @@ pub struct test { pub a: ::std::os::raw::c_int, pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, } -#[test] -fn bindgen_test_layout_test() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(test)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(test)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(test), "::", stringify!(a)), - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(test), - "::", - stringify!(zero_length_array), - ), - ); -} +const _: () = { + ["Size of test"][::std::mem::size_of::() - 4usize]; + ["Alignment of test"][::std::mem::align_of::() - 4usize]; + ["Offset of field: test::a"][::std::mem::offset_of!(test, a) - 0usize]; + [ + "Offset of field: test::zero_length_array", + ][::std::mem::offset_of!(test, zero_length_array) - 4usize]; +}; #[repr(C)] #[derive(Debug, Default)] pub struct test2 { pub a: ::std::os::raw::c_int, pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, } -#[test] -fn bindgen_test_layout_test2() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(test2)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(test2)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(test2), "::", stringify!(a)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(test2), - "::", - stringify!(incomplete_array), - ), - ); -} +const _: () = { + ["Size of test2"][::std::mem::size_of::() - 4usize]; + ["Alignment of test2"][::std::mem::align_of::() - 4usize]; + ["Offset of field: test2::a"][::std::mem::offset_of!(test2, a) - 0usize]; + [ + "Offset of field: test2::incomplete_array", + ][::std::mem::offset_of!(test2, incomplete_array) - 4usize]; +}; #[repr(C)] #[derive(Debug, Default)] pub struct test3 { @@ -110,45 +64,14 @@ pub struct test3 { pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, } -#[test] -fn bindgen_test_layout_test3() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(test3)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(test3)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(test3), "::", stringify!(a)), - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).zero_length_array) as usize - ptr as usize - }, - 4usize, - concat!( - "Offset of field: ", - stringify!(test3), - "::", - stringify!(zero_length_array), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(test3), - "::", - stringify!(incomplete_array), - ), - ); -} +const _: () = { + ["Size of test3"][::std::mem::size_of::() - 4usize]; + ["Alignment of test3"][::std::mem::align_of::() - 4usize]; + ["Offset of field: test3::a"][::std::mem::offset_of!(test3, a) - 0usize]; + [ + "Offset of field: test3::zero_length_array", + ][::std::mem::offset_of!(test3, zero_length_array) - 4usize]; + [ + "Offset of field: test3::incomplete_array", + ][::std::mem::offset_of!(test3, incomplete_array) - 4usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-pointer.rs b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-pointer.rs index 616a046f5e..b27091fa69 100644 --- a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-pointer.rs +++ b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-pointer.rs @@ -5,26 +5,13 @@ pub struct ConstPtrMutObj { pub bar: *mut ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_ConstPtrMutObj() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(ConstPtrMutObj)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(ConstPtrMutObj)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(ConstPtrMutObj), "::", stringify!(bar)), - ); -} +const _: () = { + ["Size of ConstPtrMutObj"][::std::mem::size_of::() - 8usize]; + ["Alignment of ConstPtrMutObj"][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: ConstPtrMutObj::bar", + ][::std::mem::offset_of!(ConstPtrMutObj, bar) - 0usize]; +}; impl Default for ConstPtrMutObj { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -39,26 +26,13 @@ impl Default for ConstPtrMutObj { pub struct MutPtrMutObj { pub bar: *mut ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_MutPtrMutObj() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(MutPtrMutObj)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(MutPtrMutObj)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(MutPtrMutObj), "::", stringify!(bar)), - ); -} +const _: () = { + ["Size of MutPtrMutObj"][::std::mem::size_of::() - 8usize]; + ["Alignment of MutPtrMutObj"][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: MutPtrMutObj::bar", + ][::std::mem::offset_of!(MutPtrMutObj, bar) - 0usize]; +}; impl Default for MutPtrMutObj { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -73,26 +47,13 @@ impl Default for MutPtrMutObj { pub struct MutPtrConstObj { pub bar: *const ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_MutPtrConstObj() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(MutPtrConstObj)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(MutPtrConstObj)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(MutPtrConstObj), "::", stringify!(bar)), - ); -} +const _: () = { + ["Size of MutPtrConstObj"][::std::mem::size_of::() - 8usize]; + ["Alignment of MutPtrConstObj"][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: MutPtrConstObj::bar", + ][::std::mem::offset_of!(MutPtrConstObj, bar) - 0usize]; +}; impl Default for MutPtrConstObj { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -107,26 +68,15 @@ impl Default for MutPtrConstObj { pub struct ConstPtrConstObj { pub bar: *const ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_ConstPtrConstObj() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(ConstPtrConstObj)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(ConstPtrConstObj)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(ConstPtrConstObj), "::", stringify!(bar)), - ); -} +const _: () = { + ["Size of ConstPtrConstObj"][::std::mem::size_of::() - 8usize]; + [ + "Alignment of ConstPtrConstObj", + ][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: ConstPtrConstObj::bar", + ][::std::mem::offset_of!(ConstPtrConstObj, bar) - 0usize]; +}; impl Default for ConstPtrConstObj { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/derive-hash-template-inst-float.rs b/bindgen-tests/tests/expectations/tests/derive-hash-template-inst-float.rs index 848dba6e7d..03a8b22cbb 100644 --- a/bindgen-tests/tests/expectations/tests/derive-hash-template-inst-float.rs +++ b/bindgen-tests/tests/expectations/tests/derive-hash-template-inst-float.rs @@ -21,26 +21,11 @@ impl Default for foo { pub struct IntStr { pub a: foo<::std::os::raw::c_int>, } -#[test] -fn bindgen_test_layout_IntStr() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(IntStr)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(IntStr)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(IntStr), "::", stringify!(a)), - ); -} +const _: () = { + ["Size of IntStr"][::std::mem::size_of::() - 4usize]; + ["Alignment of IntStr"][::std::mem::align_of::() - 4usize]; + ["Offset of field: IntStr::a"][::std::mem::offset_of!(IntStr, a) - 0usize]; +}; impl Default for IntStr { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -56,26 +41,11 @@ impl Default for IntStr { pub struct FloatStr { pub a: foo, } -#[test] -fn bindgen_test_layout_FloatStr() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(FloatStr)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(FloatStr)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(FloatStr), "::", stringify!(a)), - ); -} +const _: () = { + ["Size of FloatStr"][::std::mem::size_of::() - 4usize]; + ["Alignment of FloatStr"][::std::mem::align_of::() - 4usize]; + ["Offset of field: FloatStr::a"][::std::mem::offset_of!(FloatStr, a) - 0usize]; +}; impl Default for FloatStr { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -85,35 +55,19 @@ impl Default for FloatStr { } } } -#[test] -fn __bindgen_test_layout_foo_open0_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!( - "Size of template specialization: ", - stringify!(foo < ::std::os::raw::c_int >), - ), - ); - assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(foo < ::std::os::raw::c_int >), - ), - ); -} -#[test] -fn __bindgen_test_layout_foo_open0_float_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!("Size of template specialization: ", stringify!(foo < f32 >)), - ); - assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!("Alignment of template specialization: ", stringify!(foo < f32 >)), - ); -} +const _: () = { + [ + "Size of template specialization: foo_open0_int_close0", + ][::std::mem::size_of::>() - 4usize]; + [ + "Align of template specialization: foo_open0_int_close0", + ][::std::mem::align_of::>() - 4usize]; +}; +const _: () = { + [ + "Size of template specialization: foo_open0_float_close0", + ][::std::mem::size_of::>() - 4usize]; + [ + "Align of template specialization: foo_open0_float_close0", + ][::std::mem::align_of::>() - 4usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/derive-partialeq-and-blocklist.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-and-blocklist.rs index 614d0e674f..558fc86a44 100644 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-and-blocklist.rs +++ b/bindgen-tests/tests/expectations/tests/derive-partialeq-and-blocklist.rs @@ -6,31 +6,17 @@ pub struct BlocklistMe(u8); pub struct ShouldNotDerivePartialEq { pub a: BlocklistMe, } -#[test] -fn bindgen_test_layout_ShouldNotDerivePartialEq() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(ShouldNotDerivePartialEq)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(ShouldNotDerivePartialEq)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldNotDerivePartialEq), - "::", - stringify!(a), - ), - ); -} +const _: () = { + [ + "Size of ShouldNotDerivePartialEq", + ][::std::mem::size_of::() - 1usize]; + [ + "Alignment of ShouldNotDerivePartialEq", + ][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: ShouldNotDerivePartialEq::a", + ][::std::mem::offset_of!(ShouldNotDerivePartialEq, a) - 0usize]; +}; impl Default for ShouldNotDerivePartialEq { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/derive-partialeq-anonfield.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-anonfield.rs index b7be202924..02fa0e7303 100644 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-anonfield.rs +++ b/bindgen-tests/tests/expectations/tests/derive-partialeq-anonfield.rs @@ -11,19 +11,14 @@ pub struct rte_mbuf { pub struct rte_mbuf__bindgen_ty_1 { pub bindgen_union_field: [u8; 0usize], } -#[test] -fn bindgen_test_layout_rte_mbuf__bindgen_ty_1() { - assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_1)), - ); -} +const _: () = { + [ + "Size of rte_mbuf__bindgen_ty_1", + ][::std::mem::size_of::() - 0usize]; + [ + "Alignment of rte_mbuf__bindgen_ty_1", + ][::std::mem::align_of::() - 1usize]; +}; impl Default for rte_mbuf__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -33,19 +28,10 @@ impl Default for rte_mbuf__bindgen_ty_1 { } } } -#[test] -fn bindgen_test_layout_rte_mbuf() { - assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(rte_mbuf)), - ); - assert_eq!( - ::std::mem::align_of::(), - 64usize, - concat!("Alignment of ", stringify!(rte_mbuf)), - ); -} +const _: () = { + ["Size of rte_mbuf"][::std::mem::size_of::() - 0usize]; + ["Alignment of rte_mbuf"][::std::mem::align_of::() - 64usize]; +}; impl Default for rte_mbuf { 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 785bcbe0b1..d0768416ec 100644 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-base.rs +++ b/bindgen-tests/tests/expectations/tests/derive-partialeq-base.rs @@ -8,20 +8,12 @@ pub struct Base { 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, - concat!("Size of: ", stringify!(Base)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Base)), - ); + 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, - concat!("Offset of field: ", stringify!(Base), "::", stringify!(large)), + "Offset of field: Base::large", ); } impl Default for Base { @@ -48,12 +40,12 @@ fn bindgen_test_layout_ShouldDerivePartialEq() { assert_eq!( ::std::mem::size_of::(), 132usize, - concat!("Size of: ", stringify!(ShouldDerivePartialEq)), + "Size of ShouldDerivePartialEq", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(ShouldDerivePartialEq)), + "Alignment of ShouldDerivePartialEq", ); } impl Default for ShouldDerivePartialEq { diff --git a/bindgen-tests/tests/expectations/tests/derive-partialeq-bitfield.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-bitfield.rs index 6f474165ad..7c325620cf 100644 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/derive-partialeq-bitfield.rs @@ -94,20 +94,12 @@ pub struct C { 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, - concat!("Size of: ", stringify!(C)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C)), - ); + 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, - concat!("Offset of field: ", stringify!(C), "::", stringify!(large_array)), + "Offset of field: C::large_array", ); } impl Default for C { diff --git a/bindgen-tests/tests/expectations/tests/derive-partialeq-core.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-core.rs index b535256cec..3a7639f9de 100644 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-core.rs +++ b/bindgen-tests/tests/expectations/tests/derive-partialeq-core.rs @@ -9,20 +9,12 @@ pub struct C { 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, - concat!("Size of: ", stringify!(C)), - ); - assert_eq!( - ::core::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C)), - ); + 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, - concat!("Offset of field: ", stringify!(C), "::", stringify!(large_array)), + "Offset of field: C::large_array", ); } impl Default for C { diff --git a/bindgen-tests/tests/expectations/tests/derive-partialeq-pointer.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-pointer.rs index 3baa2daaad..fde2269b3b 100644 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-pointer.rs +++ b/bindgen-tests/tests/expectations/tests/derive-partialeq-pointer.rs @@ -4,26 +4,11 @@ pub struct Bar { pub b: *mut a, } -#[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::(), - 8usize, - concat!("Size of: ", stringify!(Bar)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Bar)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(b)), - ); -} +const _: () = { + ["Size of Bar"][::std::mem::size_of::() - 8usize]; + ["Alignment of Bar"][::std::mem::align_of::() - 8usize]; + ["Offset of field: Bar::b"][::std::mem::offset_of!(Bar, b) - 0usize]; +}; impl Default for Bar { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -43,19 +28,10 @@ pub struct c { pub union c__bindgen_ty_1 { pub _address: u8, } -#[test] -fn bindgen_test_layout_c__bindgen_ty_1() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(c__bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(c__bindgen_ty_1)), - ); -} +const _: () = { + ["Size of c__bindgen_ty_1"][::std::mem::size_of::() - 1usize]; + ["Alignment of c__bindgen_ty_1"][::std::mem::align_of::() - 1usize]; +}; impl Default for c__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -65,15 +41,10 @@ impl Default for c__bindgen_ty_1 { } } } -#[test] -fn bindgen_test_layout_c() { - assert_eq!(::std::mem::size_of::(), 1usize, concat!("Size of: ", stringify!(c))); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(c)), - ); -} +const _: () = { + ["Size of c"][::std::mem::size_of::() - 1usize]; + ["Alignment of c"][::std::mem::align_of::() - 1usize]; +}; impl Default for c { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -88,22 +59,11 @@ impl Default for c { pub struct a { pub d: c, } -#[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::(), 1usize, concat!("Size of: ", stringify!(a))); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(a)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(a), "::", stringify!(d)), - ); -} +const _: () = { + ["Size of a"][::std::mem::size_of::() - 1usize]; + ["Alignment of a"][::std::mem::align_of::() - 1usize]; + ["Offset of field: a::d"][::std::mem::offset_of!(a, d) - 0usize]; +}; impl Default for a { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/derive-partialeq-union.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-union.rs index 61b1a4b1b5..9dd183d073 100644 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-union.rs +++ b/bindgen-tests/tests/expectations/tests/derive-partialeq-union.rs @@ -6,41 +6,20 @@ pub union ShouldNotDerivePartialEq { pub a: ::std::os::raw::c_char, pub b: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_ShouldNotDerivePartialEq() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(ShouldNotDerivePartialEq)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(ShouldNotDerivePartialEq)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldNotDerivePartialEq), - "::", - stringify!(a), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldNotDerivePartialEq), - "::", - stringify!(b), - ), - ); -} +const _: () = { + [ + "Size of ShouldNotDerivePartialEq", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of ShouldNotDerivePartialEq", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: ShouldNotDerivePartialEq::a", + ][::std::mem::offset_of!(ShouldNotDerivePartialEq, a) - 0usize]; + [ + "Offset of field: ShouldNotDerivePartialEq::b", + ][::std::mem::offset_of!(ShouldNotDerivePartialEq, b) - 0usize]; +}; impl Default for ShouldNotDerivePartialEq { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/derive-partialeq-union_1_0.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-union_1_0.rs index 308b6a650b..f120f4fc12 100644 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/derive-partialeq-union_1_0.rs @@ -57,32 +57,22 @@ fn bindgen_test_layout_ShouldDerivePartialEq() { assert_eq!( ::std::mem::size_of::(), 152usize, - concat!("Size of: ", stringify!(ShouldDerivePartialEq)), + "Size of ShouldDerivePartialEq", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(ShouldDerivePartialEq)), + "Alignment of ShouldDerivePartialEq", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldDerivePartialEq), - "::", - stringify!(a), - ), + "Offset of field: ShouldDerivePartialEq::a", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldDerivePartialEq), - "::", - stringify!(b), - ), + "Offset of field: ShouldDerivePartialEq::b", ); } impl Clone for ShouldDerivePartialEq { diff --git a/bindgen-tests/tests/expectations/tests/disable-nested-struct-naming.rs b/bindgen-tests/tests/expectations/tests/disable-nested-struct-naming.rs index db942db300..cd020d2763 100644 --- a/bindgen-tests/tests/expectations/tests/disable-nested-struct-naming.rs +++ b/bindgen-tests/tests/expectations/tests/disable-nested-struct-naming.rs @@ -27,141 +27,50 @@ pub struct bar1__bindgen_ty_1__bindgen_ty_1 { pub struct bar4 { pub x4: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_bar4() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(bar4)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(bar4)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x4) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(bar4), "::", stringify!(x4)), - ); -} -#[test] -fn bindgen_test_layout_bar1__bindgen_ty_1__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(bar1__bindgen_ty_1__bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(bar1__bindgen_ty_1__bindgen_ty_1)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x3) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(bar1__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(x3), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b4) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(bar1__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(b4), - ), - ); -} -#[test] -fn bindgen_test_layout_bar1__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 12usize, - concat!("Size of: ", stringify!(bar1__bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(bar1__bindgen_ty_1)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x2) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(bar1__bindgen_ty_1), - "::", - stringify!(x2), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b3) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(bar1__bindgen_ty_1), - "::", - stringify!(b3), - ), - ); -} -#[test] -fn bindgen_test_layout_bar1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(bar1)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(bar1)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x1) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(bar1), "::", stringify!(x1)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b2) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(bar1), "::", stringify!(b2)), - ); -} -#[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, - concat!("Size of: ", stringify!(foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b1) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(b1)), - ); -} +const _: () = { + ["Size of bar4"][::std::mem::size_of::() - 4usize]; + ["Alignment of bar4"][::std::mem::align_of::() - 4usize]; + ["Offset of field: bar4::x4"][::std::mem::offset_of!(bar4, x4) - 0usize]; +}; +const _: () = { + [ + "Size of bar1__bindgen_ty_1__bindgen_ty_1", + ][::std::mem::size_of::() - 8usize]; + [ + "Alignment of bar1__bindgen_ty_1__bindgen_ty_1", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: bar1__bindgen_ty_1__bindgen_ty_1::x3", + ][::std::mem::offset_of!(bar1__bindgen_ty_1__bindgen_ty_1, x3) - 0usize]; + [ + "Offset of field: bar1__bindgen_ty_1__bindgen_ty_1::b4", + ][::std::mem::offset_of!(bar1__bindgen_ty_1__bindgen_ty_1, b4) - 4usize]; +}; +const _: () = { + [ + "Size of bar1__bindgen_ty_1", + ][::std::mem::size_of::() - 12usize]; + [ + "Alignment of bar1__bindgen_ty_1", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: bar1__bindgen_ty_1::x2", + ][::std::mem::offset_of!(bar1__bindgen_ty_1, x2) - 0usize]; + [ + "Offset of field: bar1__bindgen_ty_1::b3", + ][::std::mem::offset_of!(bar1__bindgen_ty_1, b3) - 4usize]; +}; +const _: () = { + ["Size of bar1"][::std::mem::size_of::() - 16usize]; + ["Alignment of bar1"][::std::mem::align_of::() - 4usize]; + ["Offset of field: bar1::x1"][::std::mem::offset_of!(bar1, x1) - 0usize]; + ["Offset of field: bar1::b2"][::std::mem::offset_of!(bar1, b2) - 4usize]; +}; +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 16usize]; + ["Alignment of foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: foo::b1"][::std::mem::offset_of!(foo, b1) - 0usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct _bindgen_ty_1 { @@ -177,71 +86,29 @@ pub struct _bindgen_ty_1__bindgen_ty_1 { pub struct baz { pub x: ::std::os::raw::c_int, } -#[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::(), - 4usize, - concat!("Size of: ", stringify!(baz)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(baz)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(baz), "::", stringify!(x)), - ); -} -#[test] -fn bindgen_test_layout__bindgen_ty_1__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit<_bindgen_ty_1__bindgen_ty_1> = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::<_bindgen_ty_1__bindgen_ty_1>(), - 4usize, - concat!("Size of: ", stringify!(_bindgen_ty_1__bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::<_bindgen_ty_1__bindgen_ty_1>(), - 4usize, - concat!("Alignment of ", stringify!(_bindgen_ty_1__bindgen_ty_1)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(b), - ), - ); -} -#[test] -fn bindgen_test_layout__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit<_bindgen_ty_1> = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::<_bindgen_ty_1>(), - 4usize, - concat!("Size of: ", stringify!(_bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::<_bindgen_ty_1>(), - 4usize, - concat!("Alignment of ", stringify!(_bindgen_ty_1)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).anon2) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(_bindgen_ty_1), "::", stringify!(anon2)), - ); -} +const _: () = { + ["Size of baz"][::std::mem::size_of::() - 4usize]; + ["Alignment of baz"][::std::mem::align_of::() - 4usize]; + ["Offset of field: baz::x"][::std::mem::offset_of!(baz, x) - 0usize]; +}; +const _: () = { + [ + "Size of _bindgen_ty_1__bindgen_ty_1", + ][::std::mem::size_of::<_bindgen_ty_1__bindgen_ty_1>() - 4usize]; + [ + "Alignment of _bindgen_ty_1__bindgen_ty_1", + ][::std::mem::align_of::<_bindgen_ty_1__bindgen_ty_1>() - 4usize]; + [ + "Offset of field: _bindgen_ty_1__bindgen_ty_1::b", + ][::std::mem::offset_of!(_bindgen_ty_1__bindgen_ty_1, b) - 0usize]; +}; +const _: () = { + ["Size of _bindgen_ty_1"][::std::mem::size_of::<_bindgen_ty_1>() - 4usize]; + ["Alignment of _bindgen_ty_1"][::std::mem::align_of::<_bindgen_ty_1>() - 4usize]; + [ + "Offset of field: _bindgen_ty_1::anon2", + ][::std::mem::offset_of!(_bindgen_ty_1, anon2) - 0usize]; +}; extern "C" { pub static mut anon1: _bindgen_ty_1; } diff --git a/bindgen-tests/tests/expectations/tests/disable-untagged-union.rs b/bindgen-tests/tests/expectations/tests/disable-untagged-union.rs index d507c70a3a..3e45778f08 100644 --- a/bindgen-tests/tests/expectations/tests/disable-untagged-union.rs +++ b/bindgen-tests/tests/expectations/tests/disable-untagged-union.rs @@ -49,28 +49,9 @@ pub struct Foo { pub baz: __BindgenUnionField<::std::os::raw::c_uint>, pub bindgen_union_field: u32, } -#[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::(), - 4usize, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Foo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(baz)), - ); -} +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 4usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Foo::bar"][::std::mem::offset_of!(Foo, bar) - 0usize]; + ["Offset of field: Foo::baz"][::std::mem::offset_of!(Foo, baz) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/do-not-derive-copy.rs b/bindgen-tests/tests/expectations/tests/do-not-derive-copy.rs index 5d1cf1c547..894bc93971 100644 --- a/bindgen-tests/tests/expectations/tests/do-not-derive-copy.rs +++ b/bindgen-tests/tests/expectations/tests/do-not-derive-copy.rs @@ -4,28 +4,14 @@ pub struct WouldBeCopyButWeAreNotDerivingCopy { pub x: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_WouldBeCopyButWeAreNotDerivingCopy() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(WouldBeCopyButWeAreNotDerivingCopy)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WouldBeCopyButWeAreNotDerivingCopy)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WouldBeCopyButWeAreNotDerivingCopy), - "::", - stringify!(x), - ), - ); -} +const _: () = { + [ + "Size of WouldBeCopyButWeAreNotDerivingCopy", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of WouldBeCopyButWeAreNotDerivingCopy", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: WouldBeCopyButWeAreNotDerivingCopy::x", + ][::std::mem::offset_of!(WouldBeCopyButWeAreNotDerivingCopy, x) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/doggo-or-null.rs b/bindgen-tests/tests/expectations/tests/doggo-or-null.rs index 395c02043e..d9169b7ecd 100644 --- a/bindgen-tests/tests/expectations/tests/doggo-or-null.rs +++ b/bindgen-tests/tests/expectations/tests/doggo-or-null.rs @@ -4,44 +4,20 @@ pub struct Doggo { pub x: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_Doggo() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Doggo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Doggo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Doggo), "::", stringify!(x)), - ); -} +const _: () = { + ["Size of Doggo"][::std::mem::size_of::() - 4usize]; + ["Alignment of Doggo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Doggo::x"][::std::mem::offset_of!(Doggo, x) - 0usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq)] pub struct Null { pub _address: u8, } -#[test] -fn bindgen_test_layout_Null() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Null)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Null)), - ); -} +const _: () = { + ["Size of Null"][::std::mem::size_of::() - 1usize]; + ["Alignment of Null"][::std::mem::align_of::() - 1usize]; +}; /** This type is an opaque union. Unions can't derive anything interesting like Debug or Default, even if their layout can, because it would require knowing which variant is in use. Opaque unions still end up as a `union` in the Rust @@ -54,19 +30,10 @@ fn bindgen_test_layout_Null() { pub union DoggoOrNull { pub _bindgen_opaque_blob: u32, } -#[test] -fn bindgen_test_layout_DoggoOrNull() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(DoggoOrNull)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(DoggoOrNull)), - ); -} +const _: () = { + ["Size of DoggoOrNull"][::std::mem::size_of::() - 4usize]; + ["Alignment of DoggoOrNull"][::std::mem::align_of::() - 4usize]; +}; impl Default for DoggoOrNull { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/duplicated-definition-count.rs b/bindgen-tests/tests/expectations/tests/duplicated-definition-count.rs index 186d32d1f9..f757029c2b 100644 --- a/bindgen-tests/tests/expectations/tests/duplicated-definition-count.rs +++ b/bindgen-tests/tests/expectations/tests/duplicated-definition-count.rs @@ -4,19 +4,10 @@ pub struct BitStream { pub _address: u8, } -#[test] -fn bindgen_test_layout_BitStream() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(BitStream)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(BitStream)), - ); -} +const _: () = { + ["Size of BitStream"][::std::mem::size_of::() - 1usize]; + ["Alignment of BitStream"][::std::mem::align_of::() - 1usize]; +}; extern "C" { #[link_name = "\u{1}_ZN9BitStream5WriteEPKcj"] pub fn BitStream_Write( diff --git a/bindgen-tests/tests/expectations/tests/duplicated-namespaces-definitions.rs b/bindgen-tests/tests/expectations/tests/duplicated-namespaces-definitions.rs index afb649d769..de1b5ae94d 100644 --- a/bindgen-tests/tests/expectations/tests/duplicated-namespaces-definitions.rs +++ b/bindgen-tests/tests/expectations/tests/duplicated-namespaces-definitions.rs @@ -12,31 +12,12 @@ pub mod root { pub foo: ::std::os::raw::c_int, pub baz: bool, } - #[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::(), - 8usize, - concat!("Size of: ", stringify!(Bar)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Bar)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(foo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz)), - ); - } + const _: () = { + ["Size of Bar"][::std::mem::size_of::() - 8usize]; + ["Alignment of Bar"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Bar::foo"][::std::mem::offset_of!(Bar, foo) - 0usize]; + ["Offset of field: Bar::baz"][::std::mem::offset_of!(Bar, baz) - 4usize]; + }; } pub mod bar { #[allow(unused_imports)] @@ -46,26 +27,11 @@ pub mod root { pub struct Foo { pub ptr: *mut root::foo::Bar, } - #[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::(), - 8usize, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Foo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(ptr)), - ); - } + const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 8usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 8usize]; + ["Offset of field: Foo::ptr"][::std::mem::offset_of!(Foo, ptr) - 0usize]; + }; impl Default for Foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_blocklist.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_blocklist.rs index 4a523db856..9273583a5f 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_blocklist.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_blocklist.rs @@ -4,22 +4,11 @@ pub struct X { pub _x: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_X() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 4usize, concat!("Size of: ", stringify!(X))); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(X)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr)._x) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(X), "::", stringify!(_x)), - ); -} +const _: () = { + ["Size of X"][::std::mem::size_of::() - 4usize]; + ["Alignment of X"][::std::mem::align_of::() - 4usize]; + ["Offset of field: X::_x"][::std::mem::offset_of!(X, _x) - 0usize]; +}; extern "C" { #[link_name = "\u{1}_ZN1X13some_functionEv"] pub fn X_some_function(this: *mut X); diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs index 2d17952408..dd0544b050 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs @@ -4,22 +4,11 @@ pub struct A { pub _x: ::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::(), 4usize, concat!("Size of: ", stringify!(A))); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(A)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr)._x) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(_x)), - ); -} +const _: () = { + ["Size of A"][::std::mem::size_of::() - 4usize]; + ["Alignment of A"][::std::mem::align_of::() - 4usize]; + ["Offset of field: A::_x"][::std::mem::offset_of!(A, _x) - 0usize]; +}; extern "C" { #[link_name = "\u{1}_ZN1A13some_functionEv"] pub fn A_some_function(this: *mut A); diff --git a/bindgen-tests/tests/expectations/tests/enum-default-bitfield.rs b/bindgen-tests/tests/expectations/tests/enum-default-bitfield.rs index 0d3829de20..56d30ae3a0 100644 --- a/bindgen-tests/tests/expectations/tests/enum-default-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/enum-default-bitfield.rs @@ -35,26 +35,11 @@ impl ::std::ops::BitAndAssign for foo__bindgen_ty_1 { #[repr(transparent)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct foo__bindgen_ty_1(pub ::std::os::raw::c_uint); -#[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::(), - 4usize, - concat!("Size of: ", stringify!(foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(member)), - ); -} +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 4usize]; + ["Alignment of foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: foo::member"][::std::mem::offset_of!(foo, member) - 0usize]; +}; impl Default for foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/enum-default-consts.rs b/bindgen-tests/tests/expectations/tests/enum-default-consts.rs index a63be965bf..9c409690cf 100644 --- a/bindgen-tests/tests/expectations/tests/enum-default-consts.rs +++ b/bindgen-tests/tests/expectations/tests/enum-default-consts.rs @@ -7,26 +7,11 @@ pub struct foo { pub const foo_FOO_A: foo__bindgen_ty_1 = 0; pub const foo_FOO_B: foo__bindgen_ty_1 = 1; pub type foo__bindgen_ty_1 = ::std::os::raw::c_uint; -#[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::(), - 4usize, - concat!("Size of: ", stringify!(foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(member)), - ); -} +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 4usize]; + ["Alignment of foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: foo::member"][::std::mem::offset_of!(foo, member) - 0usize]; +}; impl Default for foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/enum-default-module.rs b/bindgen-tests/tests/expectations/tests/enum-default-module.rs index 9774135d5c..9e5d408d66 100644 --- a/bindgen-tests/tests/expectations/tests/enum-default-module.rs +++ b/bindgen-tests/tests/expectations/tests/enum-default-module.rs @@ -9,26 +9,11 @@ pub mod foo__bindgen_ty_1 { pub const FOO_A: Type = 0; pub const FOO_B: Type = 1; } -#[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::(), - 4usize, - concat!("Size of: ", stringify!(foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(member)), - ); -} +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 4usize]; + ["Alignment of foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: foo::member"][::std::mem::offset_of!(foo, member) - 0usize]; +}; impl Default for foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/enum-default-rust.rs b/bindgen-tests/tests/expectations/tests/enum-default-rust.rs index 27ea5a1694..d2ca40eeb7 100644 --- a/bindgen-tests/tests/expectations/tests/enum-default-rust.rs +++ b/bindgen-tests/tests/expectations/tests/enum-default-rust.rs @@ -12,26 +12,11 @@ pub enum foo__bindgen_ty_1 { FOO_A = 0, FOO_B = 1, } -#[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::(), - 4usize, - concat!("Size of: ", stringify!(foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(member)), - ); -} +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 4usize]; + ["Alignment of foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: foo::member"][::std::mem::offset_of!(foo, member) - 0usize]; +}; impl Default for foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/enum-no-debug-rust.rs b/bindgen-tests/tests/expectations/tests/enum-no-debug-rust.rs index 6050d25ad3..26bd668292 100644 --- a/bindgen-tests/tests/expectations/tests/enum-no-debug-rust.rs +++ b/bindgen-tests/tests/expectations/tests/enum-no-debug-rust.rs @@ -12,26 +12,11 @@ pub enum foo__bindgen_ty_1 { FOO_A = 0, FOO_B = 1, } -#[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::(), - 4usize, - concat!("Size of: ", stringify!(foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(member)), - ); -} +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 4usize]; + ["Alignment of foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: foo::member"][::std::mem::offset_of!(foo, member) - 0usize]; +}; impl Default for foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/enum.rs b/bindgen-tests/tests/expectations/tests/enum.rs index 69422fb34b..f542ad0bef 100644 --- a/bindgen-tests/tests/expectations/tests/enum.rs +++ b/bindgen-tests/tests/expectations/tests/enum.rs @@ -7,26 +7,11 @@ pub struct foo { pub const foo_FOO_A: foo__bindgen_ty_1 = 0; pub const foo_FOO_B: foo__bindgen_ty_1 = 1; pub type foo__bindgen_ty_1 = ::std::os::raw::c_uint; -#[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::(), - 4usize, - concat!("Size of: ", stringify!(foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(member)), - ); -} +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 4usize]; + ["Alignment of foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: foo::member"][::std::mem::offset_of!(foo, member) - 0usize]; +}; impl Default for foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/enum_and_vtable_mangling.rs b/bindgen-tests/tests/expectations/tests/enum_and_vtable_mangling.rs index c450c7b2d9..4ee86d9251 100644 --- a/bindgen-tests/tests/expectations/tests/enum_and_vtable_mangling.rs +++ b/bindgen-tests/tests/expectations/tests/enum_and_vtable_mangling.rs @@ -17,22 +17,11 @@ pub struct C { pub vtable_: *const C__bindgen_vtable, pub i: ::std::os::raw::c_int, } -#[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::(), 16usize, concat!("Size of: ", stringify!(C))); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(C)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(i)), - ); -} +const _: () = { + ["Size of C"][::std::mem::size_of::() - 16usize]; + ["Alignment of C"][::std::mem::align_of::() - 8usize]; + ["Offset of field: C::i"][::std::mem::offset_of!(C, i) - 8usize]; +}; impl Default for C { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/explicit-padding.rs b/bindgen-tests/tests/expectations/tests/explicit-padding.rs index 14d46c8120..847c8ed492 100644 --- a/bindgen-tests/tests/expectations/tests/explicit-padding.rs +++ b/bindgen-tests/tests/expectations/tests/explicit-padding.rs @@ -8,36 +8,13 @@ pub struct pad_me { pub third: u16, pub __bindgen_padding_1: [u8; 2usize], } -#[test] -fn bindgen_test_layout_pad_me() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 12usize, - concat!("Size of: ", stringify!(pad_me)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(pad_me)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).first) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(pad_me), "::", stringify!(first)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).second) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(pad_me), "::", stringify!(second)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).third) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(pad_me), "::", stringify!(third)), - ); -} +const _: () = { + ["Size of pad_me"][::std::mem::size_of::() - 12usize]; + ["Alignment of pad_me"][::std::mem::align_of::() - 4usize]; + ["Offset of field: pad_me::first"][::std::mem::offset_of!(pad_me, first) - 0usize]; + ["Offset of field: pad_me::second"][::std::mem::offset_of!(pad_me, second) - 4usize]; + ["Offset of field: pad_me::third"][::std::mem::offset_of!(pad_me, third) - 8usize]; +}; #[repr(C)] #[derive(Copy, Clone)] pub union dont_pad_me { @@ -45,36 +22,19 @@ pub union dont_pad_me { pub second: u32, pub third: u16, } -#[test] -fn bindgen_test_layout_dont_pad_me() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(dont_pad_me)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(dont_pad_me)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).first) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(dont_pad_me), "::", stringify!(first)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).second) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(dont_pad_me), "::", stringify!(second)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).third) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(dont_pad_me), "::", stringify!(third)), - ); -} +const _: () = { + ["Size of dont_pad_me"][::std::mem::size_of::() - 4usize]; + ["Alignment of dont_pad_me"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: dont_pad_me::first", + ][::std::mem::offset_of!(dont_pad_me, first) - 0usize]; + [ + "Offset of field: dont_pad_me::second", + ][::std::mem::offset_of!(dont_pad_me, second) - 0usize]; + [ + "Offset of field: dont_pad_me::third", + ][::std::mem::offset_of!(dont_pad_me, third) - 0usize]; +}; impl Default for dont_pad_me { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/extern-const-struct.rs b/bindgen-tests/tests/expectations/tests/extern-const-struct.rs index db62de1460..c449e1a019 100644 --- a/bindgen-tests/tests/expectations/tests/extern-const-struct.rs +++ b/bindgen-tests/tests/expectations/tests/extern-const-struct.rs @@ -8,20 +8,12 @@ pub struct nsFoo { 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, - concat!("Size of: ", stringify!(nsFoo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(nsFoo)), - ); + 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, - concat!("Offset of field: ", stringify!(nsFoo), "::", stringify!(details)), + "Offset of field: nsFoo::details", ); } impl Default for nsFoo { diff --git a/bindgen-tests/tests/expectations/tests/field-visibility-callback.rs b/bindgen-tests/tests/expectations/tests/field-visibility-callback.rs index 31d6335700..2599c3ef9f 100644 --- a/bindgen-tests/tests/expectations/tests/field-visibility-callback.rs +++ b/bindgen-tests/tests/expectations/tests/field-visibility-callback.rs @@ -92,31 +92,14 @@ pub struct my_struct { _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, __bindgen_padding_0: [u8; 3usize], } -#[test] -fn bindgen_test_layout_my_struct() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 12usize, - concat!("Size of: ", stringify!(my_struct)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(my_struct)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(my_struct), "::", stringify!(a)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).private_b) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(my_struct), "::", stringify!(private_b)), - ); -} +const _: () = { + ["Size of my_struct"][::std::mem::size_of::() - 12usize]; + ["Alignment of my_struct"][::std::mem::align_of::() - 4usize]; + ["Offset of field: my_struct::a"][::std::mem::offset_of!(my_struct, a) - 0usize]; + [ + "Offset of field: my_struct::private_b", + ][::std::mem::offset_of!(my_struct, private_b) - 4usize]; +}; impl my_struct { #[inline] pub fn c(&self) -> ::std::os::raw::c_int { diff --git a/bindgen-tests/tests/expectations/tests/field-visibility.rs b/bindgen-tests/tests/expectations/tests/field-visibility.rs index c898d60b75..af74644c93 100644 --- a/bindgen-tests/tests/expectations/tests/field-visibility.rs +++ b/bindgen-tests/tests/expectations/tests/field-visibility.rs @@ -91,19 +91,10 @@ pub struct my_struct1 { _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, __bindgen_padding_0: [u8; 3usize], } -#[test] -fn bindgen_test_layout_my_struct1() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(my_struct1)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(my_struct1)), - ); -} +const _: () = { + ["Size of my_struct1"][::std::mem::size_of::() - 4usize]; + ["Alignment of my_struct1"][::std::mem::align_of::() - 4usize]; +}; impl my_struct1 { #[inline] fn a(&self) -> ::std::os::raw::c_int { @@ -139,19 +130,10 @@ pub struct my_struct2 { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub __bindgen_padding_0: [u8; 3usize], } -#[test] -fn bindgen_test_layout_my_struct2() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(my_struct2)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(my_struct2)), - ); -} +const _: () = { + ["Size of my_struct2"][::std::mem::size_of::() - 4usize]; + ["Alignment of my_struct2"][::std::mem::align_of::() - 4usize]; +}; impl my_struct2 { #[inline] pub fn a(&self) -> ::std::os::raw::c_int { diff --git a/bindgen-tests/tests/expectations/tests/float16.rs b/bindgen-tests/tests/expectations/tests/float16.rs index b5471b1efa..f218df495d 100644 --- a/bindgen-tests/tests/expectations/tests/float16.rs +++ b/bindgen-tests/tests/expectations/tests/float16.rs @@ -10,51 +10,27 @@ extern "C" { pub struct Test__Float16 { pub f: __BindgenFloat16, } -#[test] -fn bindgen_test_layout_Test__Float16() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 2usize, - concat!("Size of: ", stringify!(Test__Float16)), - ); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(Test__Float16)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Test__Float16), "::", stringify!(f)), - ); -} +const _: () = { + ["Size of Test__Float16"][::std::mem::size_of::() - 2usize]; + ["Alignment of Test__Float16"][::std::mem::align_of::() - 2usize]; + [ + "Offset of field: Test__Float16::f", + ][::std::mem::offset_of!(Test__Float16, f) - 0usize]; +}; #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Test__Float16Ref { pub f: *mut __BindgenFloat16, } -#[test] -fn bindgen_test_layout_Test__Float16Ref() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Test__Float16Ref)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Test__Float16Ref)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Test__Float16Ref), "::", stringify!(f)), - ); -} +const _: () = { + ["Size of Test__Float16Ref"][::std::mem::size_of::() - 8usize]; + [ + "Alignment of Test__Float16Ref", + ][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: Test__Float16Ref::f", + ][::std::mem::offset_of!(Test__Float16Ref, f) - 0usize]; +}; impl Default for Test__Float16Ref { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/forward-declaration-autoptr.rs b/bindgen-tests/tests/expectations/tests/forward-declaration-autoptr.rs index 6898f69d8e..162c4b6004 100644 --- a/bindgen-tests/tests/expectations/tests/forward-declaration-autoptr.rs +++ b/bindgen-tests/tests/expectations/tests/forward-declaration-autoptr.rs @@ -24,26 +24,11 @@ impl Default for RefPtr { pub struct Bar { pub m_member: RefPtr, } -#[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::(), - 8usize, - concat!("Size of: ", stringify!(Bar)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Bar)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(m_member)), - ); -} +const _: () = { + ["Size of Bar"][::std::mem::size_of::() - 8usize]; + ["Alignment of Bar"][::std::mem::align_of::() - 8usize]; + ["Offset of field: Bar::m_member"][::std::mem::offset_of!(Bar, m_member) - 0usize]; +}; impl Default for Bar { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -53,16 +38,11 @@ impl Default for Bar { } } } -#[test] -fn __bindgen_test_layout_RefPtr_open0_Foo_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 8usize, - concat!("Size of template specialization: ", stringify!(RefPtr < Foo >)), - ); - assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!("Alignment of template specialization: ", stringify!(RefPtr < Foo >)), - ); -} +const _: () = { + [ + "Size of template specialization: RefPtr_open0_Foo_close0", + ][::std::mem::size_of::>() - 8usize]; + [ + "Align of template specialization: RefPtr_open0_Foo_close0", + ][::std::mem::align_of::>() - 8usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/forward_declared_complex_types.rs b/bindgen-tests/tests/expectations/tests/forward_declared_complex_types.rs index 5a8d5aebaf..17dd065a85 100644 --- a/bindgen-tests/tests/expectations/tests/forward_declared_complex_types.rs +++ b/bindgen-tests/tests/expectations/tests/forward_declared_complex_types.rs @@ -4,19 +4,10 @@ pub struct Foo_empty { pub _address: u8, } -#[test] -fn bindgen_test_layout_Foo_empty() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo_empty)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo_empty)), - ); -} +const _: () = { + ["Size of Foo_empty"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo_empty"][::std::mem::align_of::() - 1usize]; +}; #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Foo { @@ -27,26 +18,11 @@ pub struct Foo { pub struct Bar { pub f: *mut Foo, } -#[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::(), - 8usize, - concat!("Size of: ", stringify!(Bar)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Bar)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(f)), - ); -} +const _: () = { + ["Size of Bar"][::std::mem::size_of::() - 8usize]; + ["Alignment of Bar"][::std::mem::align_of::() - 8usize]; + ["Offset of field: Bar::f"][::std::mem::offset_of!(Bar, f) - 0usize]; +}; impl Default for Bar { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/forward_declared_complex_types_1_0.rs b/bindgen-tests/tests/expectations/tests/forward_declared_complex_types_1_0.rs index e03884bfe6..e891a6b01b 100644 --- a/bindgen-tests/tests/expectations/tests/forward_declared_complex_types_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/forward_declared_complex_types_1_0.rs @@ -6,16 +6,8 @@ pub struct Foo_empty { } #[test] fn bindgen_test_layout_Foo_empty() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo_empty)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo_empty)), - ); + assert_eq!(::std::mem::size_of::(), 1usize, "Size of Foo_empty"); + assert_eq!(::std::mem::align_of::(), 1usize, "Alignment of Foo_empty"); } impl Clone for Foo_empty { fn clone(&self) -> Self { @@ -41,20 +33,12 @@ pub struct Bar { 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::(), - 8usize, - concat!("Size of: ", stringify!(Bar)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Bar)), - ); + assert_eq!(::std::mem::size_of::(), 8usize, "Size of Bar"); + assert_eq!(::std::mem::align_of::(), 8usize, "Alignment of Bar"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(f)), + "Offset of field: Bar::f", ); } impl Clone for Bar { diff --git a/bindgen-tests/tests/expectations/tests/forward_declared_struct.rs b/bindgen-tests/tests/expectations/tests/forward_declared_struct.rs index 8960ff11b3..20ae5c2e4f 100644 --- a/bindgen-tests/tests/expectations/tests/forward_declared_struct.rs +++ b/bindgen-tests/tests/expectations/tests/forward_declared_struct.rs @@ -4,40 +4,18 @@ pub struct a { pub b: ::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::(), 4usize, concat!("Size of: ", stringify!(a))); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(a)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(a), "::", stringify!(b)), - ); -} +const _: () = { + ["Size of a"][::std::mem::size_of::() - 4usize]; + ["Alignment of a"][::std::mem::align_of::() - 4usize]; + ["Offset of field: a::b"][::std::mem::offset_of!(a, b) - 0usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct c { pub d: ::std::os::raw::c_int, } -#[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::(), 4usize, concat!("Size of: ", stringify!(c))); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(c)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(c), "::", stringify!(d)), - ); -} +const _: () = { + ["Size of c"][::std::mem::size_of::() - 4usize]; + ["Alignment of c"][::std::mem::align_of::() - 4usize]; + ["Offset of field: c::d"][::std::mem::offset_of!(c, d) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/func_ptr_in_struct.rs b/bindgen-tests/tests/expectations/tests/func_ptr_in_struct.rs index d0ba38ad3a..c09ba012a3 100644 --- a/bindgen-tests/tests/expectations/tests/func_ptr_in_struct.rs +++ b/bindgen-tests/tests/expectations/tests/func_ptr_in_struct.rs @@ -11,23 +11,8 @@ pub struct Foo { unsafe extern "C" fn(x: ::std::os::raw::c_int, y: ::std::os::raw::c_int) -> baz, >, } -#[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::(), - 8usize, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Foo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)), - ); -} +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 8usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 8usize]; + ["Offset of field: Foo::bar"][::std::mem::offset_of!(Foo, bar) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/func_return_must_use.rs b/bindgen-tests/tests/expectations/tests/func_return_must_use.rs index e12c433c22..08c3e28443 100644 --- a/bindgen-tests/tests/expectations/tests/func_return_must_use.rs +++ b/bindgen-tests/tests/expectations/tests/func_return_must_use.rs @@ -28,19 +28,10 @@ extern "C" { #[derive(Debug, Default, Copy, Clone)] #[must_use] pub struct AnnotatedStruct {} -#[test] -fn bindgen_test_layout_AnnotatedStruct() { - assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(AnnotatedStruct)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(AnnotatedStruct)), - ); -} +const _: () = { + ["Size of AnnotatedStruct"][::std::mem::size_of::() - 0usize]; + ["Alignment of AnnotatedStruct"][::std::mem::align_of::() - 1usize]; +}; extern "C" { #[must_use] pub fn return_annotated_struct() -> AnnotatedStruct; @@ -48,19 +39,10 @@ extern "C" { #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct PlainStruct {} -#[test] -fn bindgen_test_layout_PlainStruct() { - assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(PlainStruct)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(PlainStruct)), - ); -} +const _: () = { + ["Size of PlainStruct"][::std::mem::size_of::() - 0usize]; + ["Alignment of PlainStruct"][::std::mem::align_of::() - 1usize]; +}; ///
pub type TypedefPlainStruct = PlainStruct; extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/gen-constructors-neg.rs b/bindgen-tests/tests/expectations/tests/gen-constructors-neg.rs index d51ccfa80c..30de3dce72 100644 --- a/bindgen-tests/tests/expectations/tests/gen-constructors-neg.rs +++ b/bindgen-tests/tests/expectations/tests/gen-constructors-neg.rs @@ -4,16 +4,7 @@ pub struct Foo { pub _address: u8, } -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)), - ); -} +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/gen-constructors.rs b/bindgen-tests/tests/expectations/tests/gen-constructors.rs index b46ee61a16..870e645493 100644 --- a/bindgen-tests/tests/expectations/tests/gen-constructors.rs +++ b/bindgen-tests/tests/expectations/tests/gen-constructors.rs @@ -4,19 +4,10 @@ pub struct Foo { pub _address: u8, } -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)), - ); -} +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; +}; extern "C" { #[link_name = "\u{1}_ZN3FooC1Ei"] pub fn Foo_Foo(this: *mut Foo, a: ::std::os::raw::c_int); diff --git a/bindgen-tests/tests/expectations/tests/gen-destructors-neg.rs b/bindgen-tests/tests/expectations/tests/gen-destructors-neg.rs index 67f00f79ee..95eeb8a508 100644 --- a/bindgen-tests/tests/expectations/tests/gen-destructors-neg.rs +++ b/bindgen-tests/tests/expectations/tests/gen-destructors-neg.rs @@ -4,23 +4,8 @@ pub struct Foo { pub bar: ::std::os::raw::c_int, } -#[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::(), - 4usize, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Foo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)), - ); -} +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 4usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Foo::bar"][::std::mem::offset_of!(Foo, bar) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/gen-destructors.rs b/bindgen-tests/tests/expectations/tests/gen-destructors.rs index 47adf19cce..35af32923b 100644 --- a/bindgen-tests/tests/expectations/tests/gen-destructors.rs +++ b/bindgen-tests/tests/expectations/tests/gen-destructors.rs @@ -4,26 +4,11 @@ pub struct Foo { pub bar: ::std::os::raw::c_int, } -#[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::(), - 4usize, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Foo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)), - ); -} +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 4usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Foo::bar"][::std::mem::offset_of!(Foo, bar) - 0usize]; +}; extern "C" { #[link_name = "\u{1}_ZN3FooD1Ev"] pub fn Foo_Foo_destructor(this: *mut Foo); diff --git a/bindgen-tests/tests/expectations/tests/generate-inline.rs b/bindgen-tests/tests/expectations/tests/generate-inline.rs index ce34c1ec17..e63ae1862c 100644 --- a/bindgen-tests/tests/expectations/tests/generate-inline.rs +++ b/bindgen-tests/tests/expectations/tests/generate-inline.rs @@ -4,19 +4,10 @@ pub struct Foo { pub _address: u8, } -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)), - ); -} +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; +}; extern "C" { #[link_name = "\u{1}_ZN3Foo3barEv"] pub fn Foo_bar() -> ::std::os::raw::c_int; diff --git a/bindgen-tests/tests/expectations/tests/i128.rs b/bindgen-tests/tests/expectations/tests/i128.rs index 0c7c5e0223..87459b5e75 100644 --- a/bindgen-tests/tests/expectations/tests/i128.rs +++ b/bindgen-tests/tests/expectations/tests/i128.rs @@ -10,24 +10,16 @@ pub struct foo { 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, - concat!("Size of: ", stringify!(foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 16usize, - concat!("Alignment of ", stringify!(foo)), - ); + 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, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(my_signed)), + "Offset of field: foo::my_signed", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).my_unsigned) as usize - ptr as usize }, 16usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(my_unsigned)), + "Offset of field: foo::my_unsigned", ); } diff --git a/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs b/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs index c8038e1f40..214667a23a 100644 --- a/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs +++ b/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs @@ -120,26 +120,11 @@ pub struct foo { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub b: __IncompleteArrayField<*mut ::std::os::raw::c_void>, } -#[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::(), - 8usize, - concat!("Size of: ", stringify!(foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(foo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)), - ); -} +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 8usize]; + ["Alignment of foo"][::std::mem::align_of::() - 8usize]; + ["Offset of field: foo::b"][::std::mem::offset_of!(foo, b) - 8usize]; +}; impl Default for foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs b/bindgen-tests/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs index 95f673921b..11b1df8703 100644 --- a/bindgen-tests/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs +++ b/bindgen-tests/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs @@ -24,19 +24,14 @@ impl Default for BaseWithVtable { pub struct DerivedWithNoVirtualMethods { pub _base: BaseWithVtable<*mut ::std::os::raw::c_char>, } -#[test] -fn bindgen_test_layout_DerivedWithNoVirtualMethods() { - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(DerivedWithNoVirtualMethods)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(DerivedWithNoVirtualMethods)), - ); -} +const _: () = { + [ + "Size of DerivedWithNoVirtualMethods", + ][::std::mem::size_of::() - 16usize]; + [ + "Alignment of DerivedWithNoVirtualMethods", + ][::std::mem::align_of::() - 8usize]; +}; impl Default for DerivedWithNoVirtualMethods { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -52,19 +47,14 @@ impl Default for DerivedWithNoVirtualMethods { pub struct DerivedWithVirtualMethods { pub _base: BaseWithVtable<*mut ::std::os::raw::c_char>, } -#[test] -fn bindgen_test_layout_DerivedWithVirtualMethods() { - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(DerivedWithVirtualMethods)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(DerivedWithVirtualMethods)), - ); -} +const _: () = { + [ + "Size of DerivedWithVirtualMethods", + ][::std::mem::size_of::() - 16usize]; + [ + "Alignment of DerivedWithVirtualMethods", + ][::std::mem::align_of::() - 8usize]; +}; impl Default for DerivedWithVirtualMethods { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -99,19 +89,12 @@ pub struct DerivedWithVtable { pub vtable_: *const DerivedWithVtable__bindgen_vtable, pub _base: BaseWithoutVtable<*mut ::std::os::raw::c_char>, } -#[test] -fn bindgen_test_layout_DerivedWithVtable() { - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(DerivedWithVtable)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(DerivedWithVtable)), - ); -} +const _: () = { + ["Size of DerivedWithVtable"][::std::mem::size_of::() - 16usize]; + [ + "Alignment of DerivedWithVtable", + ][::std::mem::align_of::() - 8usize]; +}; impl Default for DerivedWithVtable { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -127,19 +110,14 @@ impl Default for DerivedWithVtable { pub struct DerivedWithoutVtable { pub _base: BaseWithoutVtable<*mut ::std::os::raw::c_char>, } -#[test] -fn bindgen_test_layout_DerivedWithoutVtable() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(DerivedWithoutVtable)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(DerivedWithoutVtable)), - ); -} +const _: () = { + [ + "Size of DerivedWithoutVtable", + ][::std::mem::size_of::() - 8usize]; + [ + "Alignment of DerivedWithoutVtable", + ][::std::mem::align_of::() - 8usize]; +}; impl Default for DerivedWithoutVtable { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -149,79 +127,35 @@ impl Default for DerivedWithoutVtable { } } } -#[test] -fn __bindgen_test_layout_BaseWithVtable_open0_ptr_char_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 16usize, - concat!( - "Size of template specialization: ", - stringify!(BaseWithVtable < * mut ::std::os::raw::c_char >), - ), - ); - assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(BaseWithVtable < * mut ::std::os::raw::c_char >), - ), - ); -} -#[test] -fn __bindgen_test_layout_BaseWithVtable_open0_ptr_char_close0_instantiation_1() { - assert_eq!( - ::std::mem::size_of::>(), - 16usize, - concat!( - "Size of template specialization: ", - stringify!(BaseWithVtable < * mut ::std::os::raw::c_char >), - ), - ); - assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(BaseWithVtable < * mut ::std::os::raw::c_char >), - ), - ); -} -#[test] -fn __bindgen_test_layout_BaseWithoutVtable_open0_ptr_char_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 8usize, - concat!( - "Size of template specialization: ", - stringify!(BaseWithoutVtable < * mut ::std::os::raw::c_char >), - ), - ); - assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(BaseWithoutVtable < * mut ::std::os::raw::c_char >), - ), - ); -} -#[test] -fn __bindgen_test_layout_BaseWithoutVtable_open0_ptr_char_close0_instantiation_1() { - assert_eq!( - ::std::mem::size_of::>(), - 8usize, - concat!( - "Size of template specialization: ", - stringify!(BaseWithoutVtable < * mut ::std::os::raw::c_char >), - ), - ); - assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(BaseWithoutVtable < * mut ::std::os::raw::c_char >), - ), - ); -} +const _: () = { + [ + "Size of template specialization: BaseWithVtable_open0_ptr_char_close0", + ][::std::mem::size_of::>() - 16usize]; + [ + "Align of template specialization: BaseWithVtable_open0_ptr_char_close0", + ][::std::mem::align_of::>() - 8usize]; +}; +const _: () = { + [ + "Size of template specialization: BaseWithVtable_open0_ptr_char_close0", + ][::std::mem::size_of::>() - 16usize]; + [ + "Align of template specialization: BaseWithVtable_open0_ptr_char_close0", + ][::std::mem::align_of::>() - 8usize]; +}; +const _: () = { + [ + "Size of template specialization: BaseWithoutVtable_open0_ptr_char_close0", + ][::std::mem::size_of::>() - 8usize]; + [ + "Align of template specialization: BaseWithoutVtable_open0_ptr_char_close0", + ][::std::mem::align_of::>() - 8usize]; +}; +const _: () = { + [ + "Size of template specialization: BaseWithoutVtable_open0_ptr_char_close0", + ][::std::mem::size_of::>() - 8usize]; + [ + "Align of template specialization: BaseWithoutVtable_open0_ptr_char_close0", + ][::std::mem::align_of::>() - 8usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/inherit_multiple_interfaces.rs b/bindgen-tests/tests/expectations/tests/inherit_multiple_interfaces.rs index 76b2e3bd09..a4b0d2a867 100644 --- a/bindgen-tests/tests/expectations/tests/inherit_multiple_interfaces.rs +++ b/bindgen-tests/tests/expectations/tests/inherit_multiple_interfaces.rs @@ -7,22 +7,11 @@ pub struct A { pub vtable_: *const A__bindgen_vtable, pub member: ::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::(), 16usize, concat!("Size of: ", stringify!(A))); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(A)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(member)), - ); -} +const _: () = { + ["Size of A"][::std::mem::size_of::() - 16usize]; + ["Alignment of A"][::std::mem::align_of::() - 8usize]; + ["Offset of field: A::member"][::std::mem::offset_of!(A, member) - 8usize]; +}; impl Default for A { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -40,22 +29,11 @@ pub struct B { pub vtable_: *const B__bindgen_vtable, pub member2: *mut ::std::os::raw::c_void, } -#[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::(), 16usize, concat!("Size of: ", stringify!(B))); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(B)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member2) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(B), "::", stringify!(member2)), - ); -} +const _: () = { + ["Size of B"][::std::mem::size_of::() - 16usize]; + ["Alignment of B"][::std::mem::align_of::() - 8usize]; + ["Offset of field: B::member2"][::std::mem::offset_of!(B, member2) - 8usize]; +}; impl Default for B { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -72,22 +50,11 @@ pub struct C { pub _base_1: B, pub member3: f32, } -#[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, concat!("Size of: ", stringify!(C))); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(C)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member3) as usize - ptr as usize }, - 32usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(member3)), - ); -} +const _: () = { + ["Size of C"][::std::mem::size_of::() - 40usize]; + ["Alignment of C"][::std::mem::align_of::() - 8usize]; + ["Offset of field: C::member3"][::std::mem::offset_of!(C, member3) - 32usize]; +}; impl Default for C { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/inherit_typedef.rs b/bindgen-tests/tests/expectations/tests/inherit_typedef.rs index 1d48635962..e82fc06ce9 100644 --- a/bindgen-tests/tests/expectations/tests/inherit_typedef.rs +++ b/bindgen-tests/tests/expectations/tests/inherit_typedef.rs @@ -4,35 +4,17 @@ pub struct Foo { pub _address: u8, } -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)), - ); -} +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; +}; pub type TypedefedFoo = Foo; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Bar { pub _address: u8, } -#[test] -fn bindgen_test_layout_Bar() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Bar)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Bar)), - ); -} +const _: () = { + ["Size of Bar"][::std::mem::size_of::() - 1usize]; + ["Alignment of Bar"][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/inline_namespace.rs b/bindgen-tests/tests/expectations/tests/inline_namespace.rs index 124542ba75..72839492c1 100644 --- a/bindgen-tests/tests/expectations/tests/inline_namespace.rs +++ b/bindgen-tests/tests/expectations/tests/inline_namespace.rs @@ -13,24 +13,9 @@ pub mod root { pub struct Bar { pub baz: root::foo::Ty, } - #[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, - concat!("Size of: ", stringify!(Bar)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Bar)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz)), - ); - } + const _: () = { + ["Size of Bar"][::std::mem::size_of::() - 4usize]; + ["Alignment of Bar"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Bar::baz"][::std::mem::offset_of!(Bar, baz) - 0usize]; + }; } diff --git a/bindgen-tests/tests/expectations/tests/inline_namespace_conservative.rs b/bindgen-tests/tests/expectations/tests/inline_namespace_conservative.rs index 957d7e880a..6ac6cb7d6c 100644 --- a/bindgen-tests/tests/expectations/tests/inline_namespace_conservative.rs +++ b/bindgen-tests/tests/expectations/tests/inline_namespace_conservative.rs @@ -18,24 +18,9 @@ pub mod root { pub struct Bar { pub baz: root::foo::bar::Ty, } - #[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, - concat!("Size of: ", stringify!(Bar)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Bar)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz)), - ); - } + const _: () = { + ["Size of Bar"][::std::mem::size_of::() - 4usize]; + ["Alignment of Bar"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Bar::baz"][::std::mem::offset_of!(Bar, baz) - 0usize]; + }; } diff --git a/bindgen-tests/tests/expectations/tests/inner_const.rs b/bindgen-tests/tests/expectations/tests/inner_const.rs index 6afa16bbac..157ccce994 100644 --- a/bindgen-tests/tests/expectations/tests/inner_const.rs +++ b/bindgen-tests/tests/expectations/tests/inner_const.rs @@ -12,23 +12,8 @@ extern "C" { #[link_name = "\u{1}_ZN3Foo8whateverE"] pub static mut Foo_whatever: Foo; } -#[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::(), - 4usize, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Foo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)), - ); -} +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 4usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Foo::bar"][::std::mem::offset_of!(Foo, bar) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/inner_template_self.rs b/bindgen-tests/tests/expectations/tests/inner_template_self.rs index ecfe079d66..1c42ebea43 100644 --- a/bindgen-tests/tests/expectations/tests/inner_template_self.rs +++ b/bindgen-tests/tests/expectations/tests/inner_template_self.rs @@ -19,26 +19,13 @@ impl Default for LinkedList { pub struct InstantiateIt { pub m_list: LinkedList, } -#[test] -fn bindgen_test_layout_InstantiateIt() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(InstantiateIt)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(InstantiateIt)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).m_list) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(InstantiateIt), "::", stringify!(m_list)), - ); -} +const _: () = { + ["Size of InstantiateIt"][::std::mem::size_of::() - 16usize]; + ["Alignment of InstantiateIt"][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: InstantiateIt::m_list", + ][::std::mem::offset_of!(InstantiateIt, m_list) - 0usize]; +}; impl Default for InstantiateIt { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -48,16 +35,11 @@ impl Default for InstantiateIt { } } } -#[test] -fn __bindgen_test_layout_LinkedList_open0_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of template specialization: ", stringify!(LinkedList)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of template specialization: ", stringify!(LinkedList)), - ); -} +const _: () = { + [ + "Size of template specialization: LinkedList_open0_int_close0", + ][::std::mem::size_of::() - 16usize]; + [ + "Align of template specialization: LinkedList_open0_int_close0", + ][::std::mem::align_of::() - 8usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/issue-1034.rs b/bindgen-tests/tests/expectations/tests/issue-1034.rs index 7848090fba..fff0e13ef9 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1034.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1034.rs @@ -89,19 +89,10 @@ pub struct S2 { pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 2usize]>, } -#[test] -fn bindgen_test_layout_S2() { - assert_eq!( - ::std::mem::size_of::(), - 2usize, - concat!("Size of: ", stringify!(S2)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(S2)), - ); -} +const _: () = { + ["Size of S2"][::std::mem::size_of::() - 2usize]; + ["Alignment of S2"][::std::mem::align_of::() - 1usize]; +}; impl S2 { #[inline] pub fn new_bitfield_1() -> __BindgenBitfieldUnit<[u8; 2usize]> { diff --git a/bindgen-tests/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs b/bindgen-tests/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs index 89c09cc62f..8f9c0489ed 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs @@ -89,19 +89,10 @@ pub struct S1 { pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 3usize]>, } -#[test] -fn bindgen_test_layout_S1() { - assert_eq!( - ::std::mem::size_of::(), - 3usize, - concat!("Size of: ", stringify!(S1)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(S1)), - ); -} +const _: () = { + ["Size of S1"][::std::mem::size_of::() - 3usize]; + ["Alignment of S1"][::std::mem::align_of::() - 1usize]; +}; impl S1 { #[inline] pub fn new_bitfield_1() -> __BindgenBitfieldUnit<[u8; 3usize]> { diff --git a/bindgen-tests/tests/expectations/tests/issue-1118-using-forward-decl.rs b/bindgen-tests/tests/expectations/tests/issue-1118-using-forward-decl.rs index 2c60226142..13350e2b5c 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1118-using-forward-decl.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1118-using-forward-decl.rs @@ -5,26 +5,13 @@ pub type c = nsTArray; pub struct nsTArray_base { pub d: *mut ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_nsTArray_base() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(nsTArray_base)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(nsTArray_base)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(nsTArray_base), "::", stringify!(d)), - ); -} +const _: () = { + ["Size of nsTArray_base"][::std::mem::size_of::() - 8usize]; + ["Alignment of nsTArray_base"][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: nsTArray_base::d", + ][::std::mem::offset_of!(nsTArray_base, d) - 0usize]; +}; impl Default for nsTArray_base { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -53,26 +40,13 @@ impl Default for nsTArray { pub struct nsIContent { pub foo: nsTArray, } -#[test] -fn bindgen_test_layout_nsIContent() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(nsIContent)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(nsIContent)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(nsIContent), "::", stringify!(foo)), - ); -} +const _: () = { + ["Size of nsIContent"][::std::mem::size_of::() - 8usize]; + ["Alignment of nsIContent"][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: nsIContent::foo", + ][::std::mem::offset_of!(nsIContent, foo) - 0usize]; +}; impl Default for nsIContent { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -86,29 +60,19 @@ extern "C" { #[link_name = "\u{1}_Z35Gecko_GetAnonymousContentForElementv"] pub fn Gecko_GetAnonymousContentForElement() -> *mut nsTArray; } -#[test] -fn __bindgen_test_layout_nsTArray_open0_ptr_nsIContent_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of template specialization: ", stringify!(nsTArray)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of template specialization: ", stringify!(nsTArray)), - ); -} -#[test] -fn __bindgen_test_layout_nsTArray_open0_ptr_nsIContent_close0_instantiation_1() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of template specialization: ", stringify!(nsTArray)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of template specialization: ", stringify!(nsTArray)), - ); -} +const _: () = { + [ + "Size of template specialization: nsTArray_open0_ptr_nsIContent_close0", + ][::std::mem::size_of::() - 8usize]; + [ + "Align of template specialization: nsTArray_open0_ptr_nsIContent_close0", + ][::std::mem::align_of::() - 8usize]; +}; +const _: () = { + [ + "Size of template specialization: nsTArray_open0_ptr_nsIContent_close0", + ][::std::mem::size_of::() - 8usize]; + [ + "Align of template specialization: nsTArray_open0_ptr_nsIContent_close0", + ][::std::mem::align_of::() - 8usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs b/bindgen-tests/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs index 45ffb3d8b3..eef11c24c3 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs @@ -6,19 +6,10 @@ pub struct Foo__bindgen_vtable(::std::os::raw::c_void); pub struct Foo { pub vtable_: *const Foo__bindgen_vtable, } -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Foo)), - ); -} +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 8usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 8usize]; +}; impl Default for Foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/issue-1216-variadic-member.rs b/bindgen-tests/tests/expectations/tests/issue-1216-variadic-member.rs index f7bbeba92b..25fba1d1f1 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1216-variadic-member.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1216-variadic-member.rs @@ -14,23 +14,8 @@ pub struct Foo { ), >, } -#[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::(), - 8usize, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Foo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(f)), - ); -} +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 8usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 8usize]; + ["Offset of field: Foo::f"][::std::mem::offset_of!(Foo, f) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/issue-1281.rs b/bindgen-tests/tests/expectations/tests/issue-1281.rs index 8e0096c904..e5f82313e6 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1281.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1281.rs @@ -9,69 +9,24 @@ pub struct bar { pub struct foo { pub foo: ::std::os::raw::c_int, } -#[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::(), - 4usize, - concat!("Size of: ", stringify!(foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(foo)), - ); -} -#[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, - concat!("Size of: ", stringify!(bar)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(bar)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(bar), "::", stringify!(u)), - ); -} +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 4usize]; + ["Alignment of foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: foo::foo"][::std::mem::offset_of!(foo, foo) - 0usize]; +}; +const _: () = { + ["Size of bar"][::std::mem::size_of::() - 4usize]; + ["Alignment of bar"][::std::mem::align_of::() - 4usize]; + ["Offset of field: bar::u"][::std::mem::offset_of!(bar, u) - 0usize]; +}; pub type bar_t = bar; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct baz { pub f: foo, } -#[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::(), - 4usize, - concat!("Size of: ", stringify!(baz)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(baz)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(baz), "::", stringify!(f)), - ); -} +const _: () = { + ["Size of baz"][::std::mem::size_of::() - 4usize]; + ["Alignment of baz"][::std::mem::align_of::() - 4usize]; + ["Offset of field: baz::f"][::std::mem::offset_of!(baz, f) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/issue-1285.rs b/bindgen-tests/tests/expectations/tests/issue-1285.rs index 506b6a8819..5cd95f777f 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1285.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1285.rs @@ -10,31 +10,18 @@ pub union foo__bindgen_ty_1 { pub a: ::std::os::raw::c_uint, pub b: ::std::os::raw::c_ushort, } -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)), - ); -} +const _: () = { + ["Size of foo__bindgen_ty_1"][::std::mem::size_of::() - 4usize]; + [ + "Alignment of foo__bindgen_ty_1", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: foo__bindgen_ty_1::a", + ][::std::mem::offset_of!(foo__bindgen_ty_1, a) - 0usize]; + [ + "Offset of field: foo__bindgen_ty_1::b", + ][::std::mem::offset_of!(foo__bindgen_ty_1, b) - 0usize]; +}; impl Default for foo__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -44,26 +31,11 @@ impl Default for foo__bindgen_ty_1 { } } } -#[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::(), - 4usize, - concat!("Size of: ", stringify!(foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)), - ); -} +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 4usize]; + ["Alignment of foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: foo::bar"][::std::mem::offset_of!(foo, bar) - 0usize]; +}; impl Default for foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/issue-1291.rs b/bindgen-tests/tests/expectations/tests/issue-1291.rs index 1a9e14518b..190e899d7f 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1291.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1291.rs @@ -23,89 +23,81 @@ pub struct RTCRay { 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, - concat!("Size of: ", stringify!(RTCRay)), - ); - assert_eq!( - ::std::mem::align_of::(), - 16usize, - concat!("Alignment of ", stringify!(RTCRay)), - ); + 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, - concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(org)), + "Offset of field: RTCRay::org", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).align0) as usize - ptr as usize }, 12usize, - concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(align0)), + "Offset of field: RTCRay::align0", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).dir) as usize - ptr as usize }, 16usize, - concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(dir)), + "Offset of field: RTCRay::dir", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).align1) as usize - ptr as usize }, 28usize, - concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(align1)), + "Offset of field: RTCRay::align1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).tnear) as usize - ptr as usize }, 32usize, - concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(tnear)), + "Offset of field: RTCRay::tnear", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).tfar) as usize - ptr as usize }, 36usize, - concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(tfar)), + "Offset of field: RTCRay::tfar", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).time) as usize - ptr as usize }, 40usize, - concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(time)), + "Offset of field: RTCRay::time", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize }, 44usize, - concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(mask)), + "Offset of field: RTCRay::mask", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).Ng) as usize - ptr as usize }, 48usize, - concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(Ng)), + "Offset of field: RTCRay::Ng", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).align2) as usize - ptr as usize }, 60usize, - concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(align2)), + "Offset of field: RTCRay::align2", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize }, 64usize, - concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(u)), + "Offset of field: RTCRay::u", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).v) as usize - ptr as usize }, 68usize, - concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(v)), + "Offset of field: RTCRay::v", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).geomID) as usize - ptr as usize }, 72usize, - concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(geomID)), + "Offset of field: RTCRay::geomID", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).primID) as usize - ptr as usize }, 76usize, - concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(primID)), + "Offset of field: RTCRay::primID", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).instID) as usize - ptr as usize }, 80usize, - concat!("Offset of field: ", stringify!(RTCRay), "::", stringify!(instID)), + "Offset of field: RTCRay::instID", ); } diff --git a/bindgen-tests/tests/expectations/tests/issue-1382-rust-primitive-types.rs b/bindgen-tests/tests/expectations/tests/issue-1382-rust-primitive-types.rs index 8dbed446af..094a6d2c94 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1382-rust-primitive-types.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1382-rust-primitive-types.rs @@ -25,88 +25,21 @@ pub struct Foo { pub f32_: ::std::os::raw::c_int, pub f64_: ::std::os::raw::c_int, } -#[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::(), - 56usize, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Foo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i8_) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i8_)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).u8_) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u8_)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i16_) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i16_)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).u16_) as usize - ptr as usize }, - 12usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u16_)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i32_) as usize - ptr as usize }, - 16usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i32_)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).u32_) as usize - ptr as usize }, - 20usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u32_)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i64_) as usize - ptr as usize }, - 24usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i64_)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).u64_) as usize - ptr as usize }, - 28usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u64_)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i128_) as usize - ptr as usize }, - 32usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(i128_)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).u128_) as usize - ptr as usize }, - 36usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(u128_)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).isize_) as usize - ptr as usize }, - 40usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(isize_)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).usize_) as usize - ptr as usize }, - 44usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(usize_)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).f32_) as usize - ptr as usize }, - 48usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(f32_)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).f64_) as usize - ptr as usize }, - 52usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(f64_)), - ); -} +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 56usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Foo::i8_"][::std::mem::offset_of!(Foo, i8_) - 0usize]; + ["Offset of field: Foo::u8_"][::std::mem::offset_of!(Foo, u8_) - 4usize]; + ["Offset of field: Foo::i16_"][::std::mem::offset_of!(Foo, i16_) - 8usize]; + ["Offset of field: Foo::u16_"][::std::mem::offset_of!(Foo, u16_) - 12usize]; + ["Offset of field: Foo::i32_"][::std::mem::offset_of!(Foo, i32_) - 16usize]; + ["Offset of field: Foo::u32_"][::std::mem::offset_of!(Foo, u32_) - 20usize]; + ["Offset of field: Foo::i64_"][::std::mem::offset_of!(Foo, i64_) - 24usize]; + ["Offset of field: Foo::u64_"][::std::mem::offset_of!(Foo, u64_) - 28usize]; + ["Offset of field: Foo::i128_"][::std::mem::offset_of!(Foo, i128_) - 32usize]; + ["Offset of field: Foo::u128_"][::std::mem::offset_of!(Foo, u128_) - 36usize]; + ["Offset of field: Foo::isize_"][::std::mem::offset_of!(Foo, isize_) - 40usize]; + ["Offset of field: Foo::usize_"][::std::mem::offset_of!(Foo, usize_) - 44usize]; + ["Offset of field: Foo::f32_"][::std::mem::offset_of!(Foo, f32_) - 48usize]; + ["Offset of field: Foo::f64_"][::std::mem::offset_of!(Foo, f64_) - 52usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/issue-1443.rs b/bindgen-tests/tests/expectations/tests/issue-1443.rs index 16ad2ca437..9412d58f5d 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1443.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1443.rs @@ -10,31 +10,12 @@ pub struct Bar { pub f: *const Foo, pub m: ::std::os::raw::c_uint, } -#[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, - concat!("Size of: ", stringify!(Bar)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Bar)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(f)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(m)), - ); -} +const _: () = { + ["Size of Bar"][::std::mem::size_of::() - 16usize]; + ["Alignment of Bar"][::std::mem::align_of::() - 8usize]; + ["Offset of field: Bar::f"][::std::mem::offset_of!(Bar, f) - 0usize]; + ["Offset of field: Bar::m"][::std::mem::offset_of!(Bar, m) - 8usize]; +}; impl Default for Bar { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -50,31 +31,12 @@ pub struct Baz { pub f: *mut Foo, pub m: ::std::os::raw::c_uint, } -#[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, - concat!("Size of: ", stringify!(Baz)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Baz)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Baz), "::", stringify!(f)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(Baz), "::", stringify!(m)), - ); -} +const _: () = { + ["Size of Baz"][::std::mem::size_of::() - 16usize]; + ["Alignment of Baz"][::std::mem::align_of::() - 8usize]; + ["Offset of field: Baz::f"][::std::mem::offset_of!(Baz, f) - 0usize]; + ["Offset of field: Baz::m"][::std::mem::offset_of!(Baz, m) - 8usize]; +}; impl Default for Baz { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -90,31 +52,12 @@ pub struct Tar { pub f: *const Foo, pub m: ::std::os::raw::c_uint, } -#[test] -fn bindgen_test_layout_Tar() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(Tar)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Tar)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Tar), "::", stringify!(f)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(Tar), "::", stringify!(m)), - ); -} +const _: () = { + ["Size of Tar"][::std::mem::size_of::() - 16usize]; + ["Alignment of Tar"][::std::mem::align_of::() - 8usize]; + ["Offset of field: Tar::f"][::std::mem::offset_of!(Tar, f) - 0usize]; + ["Offset of field: Tar::m"][::std::mem::offset_of!(Tar, m) - 8usize]; +}; impl Default for Tar { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -130,31 +73,12 @@ pub struct Taz { pub f: *mut Foo, pub m: ::std::os::raw::c_uint, } -#[test] -fn bindgen_test_layout_Taz() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(Taz)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Taz)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Taz), "::", stringify!(f)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).m) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(Taz), "::", stringify!(m)), - ); -} +const _: () = { + ["Size of Taz"][::std::mem::size_of::() - 16usize]; + ["Alignment of Taz"][::std::mem::align_of::() - 8usize]; + ["Offset of field: Taz::f"][::std::mem::offset_of!(Taz, f) - 0usize]; + ["Offset of field: Taz::m"][::std::mem::offset_of!(Taz, m) - 8usize]; +}; impl Default for Taz { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/issue-1454.rs b/bindgen-tests/tests/expectations/tests/issue-1454.rs index 9a6052c9ea..caa0339662 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1454.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1454.rs @@ -7,23 +7,10 @@ pub struct extern_type; pub struct local_type { pub inner: extern_type, } -#[test] -fn bindgen_test_layout_local_type() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(local_type)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(local_type)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).inner) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(local_type), "::", stringify!(inner)), - ); -} +const _: () = { + ["Size of local_type"][::std::mem::size_of::() - 0usize]; + ["Alignment of local_type"][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: local_type::inner", + ][::std::mem::offset_of!(local_type, inner) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/issue-1498.rs b/bindgen-tests/tests/expectations/tests/issue-1498.rs index 342fcc0869..993777da46 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1498.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1498.rs @@ -24,41 +24,20 @@ pub union rte_memseg__bindgen_ty_1 { ///< Makes sure addr is always 64 bits pub addr_64: u64, } -#[test] -fn bindgen_test_layout_rte_memseg__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(rte_memseg__bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(rte_memseg__bindgen_ty_1)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).addr) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_memseg__bindgen_ty_1), - "::", - stringify!(addr), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).addr_64) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_memseg__bindgen_ty_1), - "::", - stringify!(addr_64), - ), - ); -} +const _: () = { + [ + "Size of rte_memseg__bindgen_ty_1", + ][::std::mem::size_of::() - 8usize]; + [ + "Alignment of rte_memseg__bindgen_ty_1", + ][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: rte_memseg__bindgen_ty_1::addr", + ][::std::mem::offset_of!(rte_memseg__bindgen_ty_1, addr) - 0usize]; + [ + "Offset of field: rte_memseg__bindgen_ty_1::addr_64", + ][::std::mem::offset_of!(rte_memseg__bindgen_ty_1, addr_64) - 0usize]; +}; impl Default for rte_memseg__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -68,56 +47,28 @@ impl Default for rte_memseg__bindgen_ty_1 { } } } -#[test] -fn bindgen_test_layout_rte_memseg() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 44usize, - concat!("Size of: ", stringify!(rte_memseg)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(rte_memseg)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).phys_addr) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(rte_memseg), "::", stringify!(phys_addr)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize }, - 16usize, - concat!("Offset of field: ", stringify!(rte_memseg), "::", stringify!(len)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).hugepage_sz) as usize - ptr as usize }, - 24usize, - concat!( - "Offset of field: ", - stringify!(rte_memseg), - "::", - stringify!(hugepage_sz), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).socket_id) as usize - ptr as usize }, - 32usize, - concat!("Offset of field: ", stringify!(rte_memseg), "::", stringify!(socket_id)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).nchannel) as usize - ptr as usize }, - 36usize, - concat!("Offset of field: ", stringify!(rte_memseg), "::", stringify!(nchannel)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).nrank) as usize - ptr as usize }, - 40usize, - concat!("Offset of field: ", stringify!(rte_memseg), "::", stringify!(nrank)), - ); -} +const _: () = { + ["Size of rte_memseg"][::std::mem::size_of::() - 44usize]; + ["Alignment of rte_memseg"][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: rte_memseg::phys_addr", + ][::std::mem::offset_of!(rte_memseg, phys_addr) - 0usize]; + [ + "Offset of field: rte_memseg::len", + ][::std::mem::offset_of!(rte_memseg, len) - 16usize]; + [ + "Offset of field: rte_memseg::hugepage_sz", + ][::std::mem::offset_of!(rte_memseg, hugepage_sz) - 24usize]; + [ + "Offset of field: rte_memseg::socket_id", + ][::std::mem::offset_of!(rte_memseg, socket_id) - 32usize]; + [ + "Offset of field: rte_memseg::nchannel", + ][::std::mem::offset_of!(rte_memseg, nchannel) - 36usize]; + [ + "Offset of field: rte_memseg::nrank", + ][::std::mem::offset_of!(rte_memseg, nrank) - 40usize]; +}; impl Default for rte_memseg { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/issue-1947.rs b/bindgen-tests/tests/expectations/tests/issue-1947.rs index be623357d0..46925bc19e 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1947.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1947.rs @@ -96,36 +96,13 @@ pub struct V56AMDY { pub _bitfield_2: __BindgenBitfieldUnit<[u8; 3usize]>, pub _rB_: U8, } -#[test] -fn bindgen_test_layout_V56AMDY() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(V56AMDY)), - ); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(V56AMDY)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).MADK) as usize - ptr as usize }, - 2usize, - concat!("Offset of field: ", stringify!(V56AMDY), "::", stringify!(MADK)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).MABR) as usize - ptr as usize }, - 3usize, - concat!("Offset of field: ", stringify!(V56AMDY), "::", stringify!(MABR)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr)._rB_) as usize - ptr as usize }, - 7usize, - concat!("Offset of field: ", stringify!(V56AMDY), "::", stringify!(_rB_)), - ); -} +const _: () = { + ["Size of V56AMDY"][::std::mem::size_of::() - 8usize]; + ["Alignment of V56AMDY"][::std::mem::align_of::() - 2usize]; + ["Offset of field: V56AMDY::MADK"][::std::mem::offset_of!(V56AMDY, MADK) - 2usize]; + ["Offset of field: V56AMDY::MABR"][::std::mem::offset_of!(V56AMDY, MABR) - 3usize]; + ["Offset of field: V56AMDY::_rB_"][::std::mem::offset_of!(V56AMDY, _rB_) - 7usize]; +}; impl V56AMDY { #[inline] pub fn MADZ(&self) -> U16 { diff --git a/bindgen-tests/tests/expectations/tests/issue-1977-larger-arrays.rs b/bindgen-tests/tests/expectations/tests/issue-1977-larger-arrays.rs index a64d7a2d46..077d2a5ccb 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1977-larger-arrays.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1977-larger-arrays.rs @@ -4,22 +4,11 @@ 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, concat!("Size of: ", stringify!(S))); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(S)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).large_array) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(S), "::", stringify!(large_array)), - ); -} +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(); diff --git a/bindgen-tests/tests/expectations/tests/issue-1995.rs b/bindgen-tests/tests/expectations/tests/issue-1995.rs index c0964371e9..a598f71b86 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1995.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1995.rs @@ -11,23 +11,8 @@ pub const FOO: ::std::os::raw::c_int = 1; pub struct Bar { pub baz: ::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, - concat!("Size of: ", stringify!(Bar)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Bar)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(baz)), - ); -} +const _: () = { + ["Size of Bar"][::std::mem::size_of::() - 4usize]; + ["Alignment of Bar"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Bar::baz"][::std::mem::offset_of!(Bar, baz) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/issue-2019.rs b/bindgen-tests/tests/expectations/tests/issue-2019.rs index 6dbbc3b0c8..72fe8bf1b9 100644 --- a/bindgen-tests/tests/expectations/tests/issue-2019.rs +++ b/bindgen-tests/tests/expectations/tests/issue-2019.rs @@ -4,22 +4,11 @@ pub struct A { pub a: ::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::(), 4usize, concat!("Size of: ", stringify!(A))); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(A)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(a)), - ); -} +const _: () = { + ["Size of A"][::std::mem::size_of::() - 4usize]; + ["Alignment of A"][::std::mem::align_of::() - 4usize]; + ["Offset of field: A::a"][::std::mem::offset_of!(A, a) - 0usize]; +}; extern "C" { #[link_name = "\u{1}_ZN1A4makeEv"] pub fn make() -> A; @@ -35,22 +24,11 @@ impl A { pub struct B { pub b: ::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::(), 4usize, concat!("Size of: ", stringify!(B))); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(B)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(B), "::", stringify!(b)), - ); -} +const _: () = { + ["Size of B"][::std::mem::size_of::() - 4usize]; + ["Alignment of B"][::std::mem::align_of::() - 4usize]; + ["Offset of field: B::b"][::std::mem::offset_of!(B, b) - 0usize]; +}; extern "C" { #[link_name = "\u{1}_ZN1B4makeEv"] pub fn make1() -> B; diff --git a/bindgen-tests/tests/expectations/tests/issue-2556.rs b/bindgen-tests/tests/expectations/tests/issue-2556.rs index 54b0b5ec54..b78fa4237d 100644 --- a/bindgen-tests/tests/expectations/tests/issue-2556.rs +++ b/bindgen-tests/tests/expectations/tests/issue-2556.rs @@ -9,31 +9,16 @@ pub mod root { pub width: ::std::os::raw::c_int, pub height: ::std::os::raw::c_int, } - #[test] - fn bindgen_test_layout_nsSize() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(nsSize)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(nsSize)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).width) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(nsSize), "::", stringify!(width)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).height) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(nsSize), "::", stringify!(height)), - ); - } + const _: () = { + ["Size of nsSize"][::std::mem::size_of::() - 8usize]; + ["Alignment of nsSize"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: nsSize::width", + ][::std::mem::offset_of!(nsSize, width) - 0usize]; + [ + "Offset of field: nsSize::height", + ][::std::mem::offset_of!(nsSize, height) - 4usize]; + }; pub mod foo { #[allow(unused_imports)] use self::super::super::root; diff --git a/bindgen-tests/tests/expectations/tests/issue-2695.rs b/bindgen-tests/tests/expectations/tests/issue-2695.rs index ed559fb606..daf218356a 100644 --- a/bindgen-tests/tests/expectations/tests/issue-2695.rs +++ b/bindgen-tests/tests/expectations/tests/issue-2695.rs @@ -8,38 +8,11 @@ pub struct Test { pub c: ::std::os::raw::c_char, pub __bindgen_padding_0: u8, } -#[test] -fn bindgen_test_layout_Test() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 12usize, - concat!("Size of: ", stringify!(Test)), - ); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(Test)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(x)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(a)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 9usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(b)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, - 10usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(c)), - ); -} +const _: () = { + ["Size of Test"][::std::mem::size_of::() - 12usize]; + ["Alignment of Test"][::std::mem::align_of::() - 2usize]; + ["Offset of field: Test::x"][::std::mem::offset_of!(Test, x) - 0usize]; + ["Offset of field: Test::a"][::std::mem::offset_of!(Test, a) - 8usize]; + ["Offset of field: Test::b"][::std::mem::offset_of!(Test, b) - 9usize]; + ["Offset of field: Test::c"][::std::mem::offset_of!(Test, c) - 10usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/issue-372.rs b/bindgen-tests/tests/expectations/tests/issue-372.rs index 3155676176..80b8cbe8b6 100644 --- a/bindgen-tests/tests/expectations/tests/issue-372.rs +++ b/bindgen-tests/tests/expectations/tests/issue-372.rs @@ -14,30 +14,22 @@ pub mod root { 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, - concat!("Size of: ", stringify!(i)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(i)), - ); + 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, - concat!("Offset of field: ", stringify!(i), "::", stringify!(j)), + "Offset of field: i::j", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).k) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(i), "::", stringify!(k)), + "Offset of field: i::k", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).l) as usize - ptr as usize }, 16usize, - concat!("Offset of field: ", stringify!(i), "::", stringify!(l)), + "Offset of field: i::l", ); } impl Default for i { @@ -58,20 +50,12 @@ pub mod root { 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, - concat!("Size of: ", stringify!(d)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(d)), - ); + 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, - concat!("Offset of field: ", stringify!(d), "::", stringify!(m)), + "Offset of field: d::m", ); } impl Default for d { @@ -107,20 +91,12 @@ pub mod root { 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, - concat!("Size of: ", stringify!(F)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(F)), - ); + 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, - concat!("Offset of field: ", stringify!(F), "::", stringify!(w)), + "Offset of field: F::w", ); } impl Default for F { diff --git a/bindgen-tests/tests/expectations/tests/issue-410.rs b/bindgen-tests/tests/expectations/tests/issue-410.rs index d04cafe8df..28a2893035 100644 --- a/bindgen-tests/tests/expectations/tests/issue-410.rs +++ b/bindgen-tests/tests/expectations/tests/issue-410.rs @@ -11,19 +11,10 @@ pub mod root { pub struct Value { pub _address: u8, } - #[test] - fn bindgen_test_layout_Value() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Value)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Value)), - ); - } + const _: () = { + ["Size of Value"][::std::mem::size_of::() - 1usize]; + ["Alignment of Value"][::std::mem::align_of::() - 1usize]; + }; extern "C" { #[link_name = "\u{1}_ZN2JS5Value1aE10JSWhyMagic"] pub fn Value_a(this: *mut root::JS::Value, arg1: root::JSWhyMagic); diff --git a/bindgen-tests/tests/expectations/tests/issue-447.rs b/bindgen-tests/tests/expectations/tests/issue-447.rs index 1f1e376b5c..0231b40aa8 100644 --- a/bindgen-tests/tests/expectations/tests/issue-447.rs +++ b/bindgen-tests/tests/expectations/tests/issue-447.rs @@ -14,19 +14,14 @@ pub mod root { pub struct GuardObjectNotifier { pub _address: u8, } - #[test] - fn bindgen_test_layout_GuardObjectNotifier() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(GuardObjectNotifier)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(GuardObjectNotifier)), - ); - } + const _: () = { + [ + "Size of GuardObjectNotifier", + ][::std::mem::size_of::() - 1usize]; + [ + "Alignment of GuardObjectNotifier", + ][::std::mem::align_of::() - 1usize]; + }; } } #[repr(C)] @@ -34,19 +29,14 @@ pub mod root { pub struct JSAutoCompartment { pub _address: u8, } - #[test] - fn bindgen_test_layout_JSAutoCompartment() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(JSAutoCompartment)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(JSAutoCompartment)), - ); - } + const _: () = { + [ + "Size of JSAutoCompartment", + ][::std::mem::size_of::() - 1usize]; + [ + "Alignment of JSAutoCompartment", + ][::std::mem::align_of::() - 1usize]; + }; extern "C" { #[link_name = "\u{1}_ZN17JSAutoCompartmentC1EN7mozilla6detail19GuardObjectNotifierE"] pub fn JSAutoCompartment_JSAutoCompartment( 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 387082d0c8..3042551585 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 @@ -11,20 +11,16 @@ pub struct AlignedToOne { 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, - concat!("Size of: ", stringify!(AlignedToOne)), - ); + assert_eq!(::std::mem::size_of::(), 4usize, "Size of AlignedToOne"); assert_eq!( ::std::mem::align_of::(), 1usize, - concat!("Alignment of ", stringify!(AlignedToOne)), + "Alignment of AlignedToOne", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(AlignedToOne), "::", stringify!(i)), + "Offset of field: AlignedToOne::i", ); } /// This should be be packed because Rust 1.33 has `#[repr(packed(N))]`. @@ -37,20 +33,16 @@ pub struct AlignedToTwo { 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, - concat!("Size of: ", stringify!(AlignedToTwo)), - ); + assert_eq!(::std::mem::size_of::(), 4usize, "Size of AlignedToTwo"); assert_eq!( ::std::mem::align_of::(), 2usize, - concat!("Alignment of ", stringify!(AlignedToTwo)), + "Alignment of AlignedToTwo", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(AlignedToTwo), "::", stringify!(i)), + "Offset of field: AlignedToTwo::i", ); } /** This should not be opaque because although `libclang` doesn't give us the @@ -66,25 +58,21 @@ pub struct PackedToOne { 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, - concat!("Size of: ", stringify!(PackedToOne)), - ); + assert_eq!(::std::mem::size_of::(), 8usize, "Size of PackedToOne"); assert_eq!( ::std::mem::align_of::(), 1usize, - concat!("Alignment of ", stringify!(PackedToOne)), + "Alignment of PackedToOne", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(PackedToOne), "::", stringify!(x)), + "Offset of field: PackedToOne::x", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(PackedToOne), "::", stringify!(y)), + "Offset of field: PackedToOne::y", ); } /// This should be be packed because Rust 1.33 has `#[repr(packed(N))]`. @@ -98,24 +86,20 @@ pub struct PackedToTwo { 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, - concat!("Size of: ", stringify!(PackedToTwo)), - ); + assert_eq!(::std::mem::size_of::(), 8usize, "Size of PackedToTwo"); assert_eq!( ::std::mem::align_of::(), 2usize, - concat!("Alignment of ", stringify!(PackedToTwo)), + "Alignment of PackedToTwo", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(PackedToTwo), "::", stringify!(x)), + "Offset of field: PackedToTwo::x", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(PackedToTwo), "::", stringify!(y)), + "Offset of field: PackedToTwo::y", ); } diff --git a/bindgen-tests/tests/expectations/tests/issue-537.rs b/bindgen-tests/tests/expectations/tests/issue-537.rs index c9ce3fb035..6a7bc3edfd 100644 --- a/bindgen-tests/tests/expectations/tests/issue-537.rs +++ b/bindgen-tests/tests/expectations/tests/issue-537.rs @@ -6,26 +6,13 @@ 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, - concat!("Size of: ", stringify!(AlignedToOne)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(AlignedToOne)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(AlignedToOne), "::", stringify!(i)), - ); -} +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 opaque because although we can see the attributes, Rust before 1.33 doesn't have `#[repr(packed(N))]`.*/ #[repr(C, packed(2))] @@ -33,26 +20,13 @@ fn bindgen_test_layout_AlignedToOne() { 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, - concat!("Size of: ", stringify!(AlignedToTwo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(AlignedToTwo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(AlignedToTwo), "::", stringify!(i)), - ); -} +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.*/ @@ -62,31 +36,12 @@ 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, - concat!("Size of: ", stringify!(PackedToOne)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(PackedToOne)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(PackedToOne), "::", stringify!(x)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(PackedToOne), "::", stringify!(y)), - ); -} +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]; +}; /** In this case, even if we can detect the weird alignment triggered by `#pragma pack(2)`, we can't do anything about it because Rust before 1.33 doesn't have `#[repr(packed(N))]`. Therefore, we must make it opaque.*/ @@ -96,28 +51,9 @@ 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, - concat!("Size of: ", stringify!(PackedToTwo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(PackedToTwo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(PackedToTwo), "::", stringify!(x)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(PackedToTwo), "::", stringify!(y)), - ); -} +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-569-non-type-template-params-causing-layout-test-failures.rs b/bindgen-tests/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs index 59590ec8fe..ffbbe792ca 100644 --- a/bindgen-tests/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs +++ b/bindgen-tests/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs @@ -27,19 +27,10 @@ impl Default for JS_Base { pub struct JS_AutoIdVector { pub _base: JS_Base, } -#[test] -fn bindgen_test_layout_JS_AutoIdVector() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(JS_AutoIdVector)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(JS_AutoIdVector)), - ); -} +const _: () = { + ["Size of JS_AutoIdVector"][::std::mem::size_of::() - 1usize]; + ["Alignment of JS_AutoIdVector"][::std::mem::align_of::() - 1usize]; +}; impl Default for JS_AutoIdVector { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -49,16 +40,11 @@ impl Default for JS_AutoIdVector { } } } -#[test] -fn __bindgen_test_layout_JS_Base_open0_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of template specialization: ", stringify!(JS_Base)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of template specialization: ", stringify!(JS_Base)), - ); -} +const _: () = { + [ + "Size of template specialization: JS_Base_open0_int_close0", + ][::std::mem::size_of::() - 1usize]; + [ + "Align of template specialization: JS_Base_open0_int_close0", + ][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/issue-573-layout-test-failures.rs b/bindgen-tests/tests/expectations/tests/issue-573-layout-test-failures.rs index ab51dc8943..2c5936e761 100644 --- a/bindgen-tests/tests/expectations/tests/issue-573-layout-test-failures.rs +++ b/bindgen-tests/tests/expectations/tests/issue-573-layout-test-failures.rs @@ -9,36 +9,18 @@ pub struct Outer { pub struct AutoIdVector { pub ar: Outer, } -#[test] -fn bindgen_test_layout_AutoIdVector() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(AutoIdVector)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(AutoIdVector)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ar) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(AutoIdVector), "::", stringify!(ar)), - ); -} -#[test] -fn __bindgen_test_layout_Outer_open0_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of template specialization: ", stringify!(Outer)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of template specialization: ", stringify!(Outer)), - ); -} +const _: () = { + ["Size of AutoIdVector"][::std::mem::size_of::() - 1usize]; + ["Alignment of AutoIdVector"][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: AutoIdVector::ar", + ][::std::mem::offset_of!(AutoIdVector, ar) - 0usize]; +}; +const _: () = { + [ + "Size of template specialization: Outer_open0_int_close0", + ][::std::mem::size_of::() - 1usize]; + [ + "Align of template specialization: Outer_open0_int_close0", + ][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs b/bindgen-tests/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs index d3c0cee41c..bcc8ecdb75 100644 --- a/bindgen-tests/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs +++ b/bindgen-tests/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs @@ -9,39 +9,21 @@ pub struct a { pub struct _bindgen_ty_1 { pub ar: a, } -#[test] -fn bindgen_test_layout__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit<_bindgen_ty_1> = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::<_bindgen_ty_1>(), - 1usize, - concat!("Size of: ", stringify!(_bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::<_bindgen_ty_1>(), - 1usize, - concat!("Alignment of ", stringify!(_bindgen_ty_1)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ar) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(_bindgen_ty_1), "::", stringify!(ar)), - ); -} +const _: () = { + ["Size of _bindgen_ty_1"][::std::mem::size_of::<_bindgen_ty_1>() - 1usize]; + ["Alignment of _bindgen_ty_1"][::std::mem::align_of::<_bindgen_ty_1>() - 1usize]; + [ + "Offset of field: _bindgen_ty_1::ar", + ][::std::mem::offset_of!(_bindgen_ty_1, ar) - 0usize]; +}; extern "C" { pub static mut AutoIdVector: _bindgen_ty_1; } -#[test] -fn __bindgen_test_layout_a_open0_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of template specialization: ", stringify!(a)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of template specialization: ", stringify!(a)), - ); -} +const _: () = { + [ + "Size of template specialization: a_open0_int_close0", + ][::std::mem::size_of::() - 1usize]; + [ + "Align of template specialization: a_open0_int_close0", + ][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs b/bindgen-tests/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs index c9c5dbc7f1..cfa6a195e2 100644 --- a/bindgen-tests/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs +++ b/bindgen-tests/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs @@ -6,15 +6,10 @@ pub struct A { pub _address: u8, } pub type A_a = b; -#[test] -fn bindgen_test_layout_A() { - assert_eq!(::std::mem::size_of::(), 1usize, concat!("Size of: ", stringify!(A))); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(A)), - ); -} +const _: () = { + ["Size of A"][::std::mem::size_of::() - 1usize]; + ["Alignment of A"][::std::mem::align_of::() - 1usize]; +}; #[repr(C)] pub struct e { pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, @@ -38,22 +33,11 @@ pub struct f { pub struct g { pub h: f, } -#[test] -fn bindgen_test_layout_g() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 1usize, concat!("Size of: ", stringify!(g))); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(g)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).h) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(g), "::", stringify!(h)), - ); -} +const _: () = { + ["Size of g"][::std::mem::size_of::() - 1usize]; + ["Alignment of g"][::std::mem::align_of::() - 1usize]; + ["Offset of field: g::h"][::std::mem::offset_of!(g, h) - 0usize]; +}; impl Default for g { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -67,15 +51,10 @@ impl Default for g { pub struct b { pub _base: g, } -#[test] -fn bindgen_test_layout_b() { - assert_eq!(::std::mem::size_of::(), 1usize, concat!("Size of: ", stringify!(b))); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(b)), - ); -} +const _: () = { + ["Size of b"][::std::mem::size_of::() - 1usize]; + ["Alignment of b"][::std::mem::align_of::() - 1usize]; +}; impl Default for b { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -89,16 +68,11 @@ extern "C" { #[link_name = "\u{1}_Z25Servo_Element_GetSnapshotv"] pub fn Servo_Element_GetSnapshot() -> A; } -#[test] -fn __bindgen_test_layout_f_open0_e_open1_int_close1_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of template specialization: ", stringify!(f)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of template specialization: ", stringify!(f)), - ); -} +const _: () = { + [ + "Size of template specialization: f_open0_e_open1_int_close1_close0", + ][::std::mem::size_of::() - 1usize]; + [ + "Align of template specialization: f_open0_e_open1_int_close1_close0", + ][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/issue-639-typedef-anon-field.rs b/bindgen-tests/tests/expectations/tests/issue-639-typedef-anon-field.rs index 2495b458e4..3909ce4e2f 100644 --- a/bindgen-tests/tests/expectations/tests/issue-639-typedef-anon-field.rs +++ b/bindgen-tests/tests/expectations/tests/issue-639-typedef-anon-field.rs @@ -9,46 +9,16 @@ pub struct Foo { pub struct Foo_Bar { pub abc: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_Foo_Bar() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Foo_Bar)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Foo_Bar)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).abc) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Foo_Bar), "::", stringify!(abc)), - ); -} -#[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::(), - 4usize, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Foo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(bar)), - ); -} +const _: () = { + ["Size of Foo_Bar"][::std::mem::size_of::() - 4usize]; + ["Alignment of Foo_Bar"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Foo_Bar::abc"][::std::mem::offset_of!(Foo_Bar, abc) - 0usize]; +}; +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 4usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Foo::bar"][::std::mem::offset_of!(Foo, bar) - 0usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Baz { @@ -59,36 +29,12 @@ pub struct Baz { pub struct Baz_Bar { pub abc: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_Baz_Bar() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Baz_Bar)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Baz_Bar)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).abc) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Baz_Bar), "::", stringify!(abc)), - ); -} -#[test] -fn bindgen_test_layout_Baz() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Baz)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Baz)), - ); -} +const _: () = { + ["Size of Baz_Bar"][::std::mem::size_of::() - 4usize]; + ["Alignment of Baz_Bar"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Baz_Bar::abc"][::std::mem::offset_of!(Baz_Bar, abc) - 0usize]; +}; +const _: () = { + ["Size of Baz"][::std::mem::size_of::() - 1usize]; + ["Alignment of Baz"][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/issue-643-inner-struct.rs b/bindgen-tests/tests/expectations/tests/issue-643-inner-struct.rs index 520b3b0ecd..3e3f2ada59 100644 --- a/bindgen-tests/tests/expectations/tests/issue-643-inner-struct.rs +++ b/bindgen-tests/tests/expectations/tests/issue-643-inner-struct.rs @@ -42,96 +42,39 @@ pub struct rte_ring { pub struct rte_ring_prod { pub watermark: ::std::os::raw::c_uint, } -#[test] -fn bindgen_test_layout_rte_ring_prod() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(rte_ring_prod)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(rte_ring_prod)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).watermark) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ring_prod), - "::", - stringify!(watermark), - ), - ); -} +const _: () = { + ["Size of rte_ring_prod"][::std::mem::size_of::() - 4usize]; + ["Alignment of rte_ring_prod"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: rte_ring_prod::watermark", + ][::std::mem::offset_of!(rte_ring_prod, watermark) - 0usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct rte_ring_cons { pub sc_dequeue: ::std::os::raw::c_uint, } -#[test] -fn bindgen_test_layout_rte_ring_cons() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(rte_ring_cons)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(rte_ring_cons)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).sc_dequeue) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ring_cons), - "::", - stringify!(sc_dequeue), - ), - ); -} -#[test] -fn bindgen_test_layout_rte_ring() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(rte_ring)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(rte_ring)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).memzone) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(rte_ring), "::", stringify!(memzone)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).prod) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(rte_ring), "::", stringify!(prod)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).cons) as usize - ptr as usize }, - 12usize, - concat!("Offset of field: ", stringify!(rte_ring), "::", stringify!(cons)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ring) as usize - ptr as usize }, - 16usize, - concat!("Offset of field: ", stringify!(rte_ring), "::", stringify!(ring)), - ); -} +const _: () = { + ["Size of rte_ring_cons"][::std::mem::size_of::() - 4usize]; + ["Alignment of rte_ring_cons"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: rte_ring_cons::sc_dequeue", + ][::std::mem::offset_of!(rte_ring_cons, sc_dequeue) - 0usize]; +}; +const _: () = { + ["Size of rte_ring"][::std::mem::size_of::() - 16usize]; + ["Alignment of rte_ring"][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: rte_ring::memzone", + ][::std::mem::offset_of!(rte_ring, memzone) - 0usize]; + ["Offset of field: rte_ring::prod"][::std::mem::offset_of!(rte_ring, prod) - 8usize]; + [ + "Offset of field: rte_ring::cons", + ][::std::mem::offset_of!(rte_ring, cons) - 12usize]; + [ + "Offset of field: rte_ring::ring", + ][::std::mem::offset_of!(rte_ring, ring) - 16usize]; +}; impl Default for rte_ring { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); 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 6015618d48..08e47bc2c6 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 @@ -11,20 +11,12 @@ pub struct NoDebug { 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, - concat!("Size of: ", stringify!(NoDebug)), - ); - assert_eq!( - ::std::mem::align_of::(), - 64usize, - concat!("Alignment of ", stringify!(NoDebug)), - ); + 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, - concat!("Offset of field: ", stringify!(NoDebug), "::", stringify!(c)), + "Offset of field: NoDebug::c", ); } impl Default for NoDebug { @@ -59,32 +51,22 @@ fn bindgen_test_layout_ShouldDeriveDebugButDoesNot() { assert_eq!( ::std::mem::size_of::(), 64usize, - concat!("Size of: ", stringify!(ShouldDeriveDebugButDoesNot)), + "Size of ShouldDeriveDebugButDoesNot", ); assert_eq!( ::std::mem::align_of::(), 64usize, - concat!("Alignment of ", stringify!(ShouldDeriveDebugButDoesNot)), + "Alignment of ShouldDeriveDebugButDoesNot", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(ShouldDeriveDebugButDoesNot), - "::", - stringify!(c), - ), + "Offset of field: ShouldDeriveDebugButDoesNot::c", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, 32usize, - concat!( - "Offset of field: ", - stringify!(ShouldDeriveDebugButDoesNot), - "::", - stringify!(d), - ), + "Offset of field: ShouldDeriveDebugButDoesNot::d", ); } impl Default for ShouldDeriveDebugButDoesNot { diff --git a/bindgen-tests/tests/expectations/tests/issue-674-1.rs b/bindgen-tests/tests/expectations/tests/issue-674-1.rs index 2173924c3c..0c45f11f52 100644 --- a/bindgen-tests/tests/expectations/tests/issue-674-1.rs +++ b/bindgen-tests/tests/expectations/tests/issue-674-1.rs @@ -18,29 +18,15 @@ pub mod root { pub struct CapturingContentInfo { pub a: u8, } - #[test] - fn bindgen_test_layout_CapturingContentInfo() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(CapturingContentInfo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(CapturingContentInfo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(CapturingContentInfo), - "::", - stringify!(a), - ), - ); - } + const _: () = { + [ + "Size of CapturingContentInfo", + ][::std::mem::size_of::() - 1usize]; + [ + "Alignment of CapturingContentInfo", + ][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: CapturingContentInfo::a", + ][::std::mem::offset_of!(CapturingContentInfo, a) - 0usize]; + }; } diff --git a/bindgen-tests/tests/expectations/tests/issue-674-2.rs b/bindgen-tests/tests/expectations/tests/issue-674-2.rs index 01f54798d7..7a42d02584 100644 --- a/bindgen-tests/tests/expectations/tests/issue-674-2.rs +++ b/bindgen-tests/tests/expectations/tests/issue-674-2.rs @@ -18,70 +18,32 @@ pub mod root { pub struct c { pub b: u8, } - #[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::(), - 1usize, - concat!("Size of: ", stringify!(c)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(c)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(c), "::", stringify!(b)), - ); - } + const _: () = { + ["Size of c"][::std::mem::size_of::() - 1usize]; + ["Alignment of c"][::std::mem::align_of::() - 1usize]; + ["Offset of field: c::b"][::std::mem::offset_of!(c, b) - 0usize]; + }; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct B { pub a: root::c, } - #[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::(), - 1usize, - concat!("Size of: ", stringify!(B)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(B)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(B), "::", stringify!(a)), - ); - } + const _: () = { + ["Size of B"][::std::mem::size_of::() - 1usize]; + ["Alignment of B"][::std::mem::align_of::() - 1usize]; + ["Offset of field: B::a"][::std::mem::offset_of!(B, a) - 0usize]; + }; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct StaticRefPtr { pub _address: u8, } - #[test] - fn __bindgen_test_layout_StaticRefPtr_open0_B_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of template specialization: ", stringify!(root::StaticRefPtr)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!( - "Alignment of template specialization: ", - stringify!(root::StaticRefPtr), - ), - ); - } + const _: () = { + [ + "Size of template specialization: StaticRefPtr_open0_B_close0", + ][::std::mem::size_of::() - 1usize]; + [ + "Align of template specialization: StaticRefPtr_open0_B_close0", + ][::std::mem::align_of::() - 1usize]; + }; } diff --git a/bindgen-tests/tests/expectations/tests/issue-674-3.rs b/bindgen-tests/tests/expectations/tests/issue-674-3.rs index bba2f38b43..8b9f2705bc 100644 --- a/bindgen-tests/tests/expectations/tests/issue-674-3.rs +++ b/bindgen-tests/tests/expectations/tests/issue-674-3.rs @@ -14,49 +14,21 @@ pub mod root { pub struct a { pub b: u8, } - #[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::(), - 1usize, - concat!("Size of: ", stringify!(a)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(a)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(a), "::", stringify!(b)), - ); - } + const _: () = { + ["Size of a"][::std::mem::size_of::() - 1usize]; + ["Alignment of a"][::std::mem::align_of::() - 1usize]; + ["Offset of field: a::b"][::std::mem::offset_of!(a, b) - 0usize]; + }; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct nsCSSValue { pub c: root::a, } - #[test] - fn bindgen_test_layout_nsCSSValue() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(nsCSSValue)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(nsCSSValue)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(nsCSSValue), "::", stringify!(c)), - ); - } + const _: () = { + ["Size of nsCSSValue"][::std::mem::size_of::() - 1usize]; + ["Alignment of nsCSSValue"][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: nsCSSValue::c", + ][::std::mem::offset_of!(nsCSSValue, c) - 0usize]; + }; } diff --git a/bindgen-tests/tests/expectations/tests/issue-691-template-parameter-virtual.rs b/bindgen-tests/tests/expectations/tests/issue-691-template-parameter-virtual.rs index 7080f2048b..9c3b00d163 100644 --- a/bindgen-tests/tests/expectations/tests/issue-691-template-parameter-virtual.rs +++ b/bindgen-tests/tests/expectations/tests/issue-691-template-parameter-virtual.rs @@ -6,19 +6,10 @@ pub struct VirtualMethods__bindgen_vtable {} pub struct VirtualMethods { pub vtable_: *const VirtualMethods__bindgen_vtable, } -#[test] -fn bindgen_test_layout_VirtualMethods() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(VirtualMethods)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(VirtualMethods)), - ); -} +const _: () = { + ["Size of VirtualMethods"][::std::mem::size_of::() - 8usize]; + ["Alignment of VirtualMethods"][::std::mem::align_of::() - 8usize]; +}; impl Default for VirtualMethods { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -38,19 +29,14 @@ pub struct Set { pub struct ServoElementSnapshotTable { pub _base: Set, } -#[test] -fn bindgen_test_layout_ServoElementSnapshotTable() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(ServoElementSnapshotTable)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(ServoElementSnapshotTable)), - ); -} +const _: () = { + [ + "Size of ServoElementSnapshotTable", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of ServoElementSnapshotTable", + ][::std::mem::align_of::() - 4usize]; +}; impl Default for ServoElementSnapshotTable { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -60,16 +46,11 @@ impl Default for ServoElementSnapshotTable { } } } -#[test] -fn __bindgen_test_layout_Set_open0_VirtualMethods_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of template specialization: ", stringify!(Set)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of template specialization: ", stringify!(Set)), - ); -} +const _: () = { + [ + "Size of template specialization: Set_open0_VirtualMethods_close0", + ][::std::mem::size_of::() - 4usize]; + [ + "Align of template specialization: Set_open0_VirtualMethods_close0", + ][::std::mem::align_of::() - 4usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs b/bindgen-tests/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs index 7bc9933697..be1eeee425 100644 --- a/bindgen-tests/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs @@ -90,19 +90,10 @@ pub struct Foo { pub _bitfield_align_1: [u64; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 32usize]>, } -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 32usize, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Foo)), - ); -} +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 32usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 8usize]; +}; impl Foo { #[inline] pub fn m_bitfield(&self) -> ::std::os::raw::c_ulong { diff --git a/bindgen-tests/tests/expectations/tests/issue-769-bad-instantiation-test.rs b/bindgen-tests/tests/expectations/tests/issue-769-bad-instantiation-test.rs index 172c3193d2..cdfe5f652a 100644 --- a/bindgen-tests/tests/expectations/tests/issue-769-bad-instantiation-test.rs +++ b/bindgen-tests/tests/expectations/tests/issue-769-bad-instantiation-test.rs @@ -19,42 +19,20 @@ pub mod root { } } pub type AutoValueVector_Alias = ::std::os::raw::c_int; - #[test] - fn __bindgen_test_layout_Rooted_open0_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!( - "Size of template specialization: ", - stringify!(root::Rooted < ::std::os::raw::c_int >), - ), - ); - assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(root::Rooted < ::std::os::raw::c_int >), - ), - ); - } - #[test] - fn __bindgen_test_layout_Rooted_open0_AutoValueVector_Alias_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!( - "Size of template specialization: ", - stringify!(root::Rooted < root::AutoValueVector_Alias >), - ), - ); - assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(root::Rooted < root::AutoValueVector_Alias >), - ), - ); - } + const _: () = { + [ + "Size of template specialization: Rooted_open0_int_close0", + ][::std::mem::size_of::>() - 4usize]; + [ + "Align of template specialization: Rooted_open0_int_close0", + ][::std::mem::align_of::>() - 4usize]; + }; + const _: () = { + [ + "Size of template specialization: Rooted_open0_AutoValueVector_Alias_close0", + ][::std::mem::size_of::>() - 4usize]; + [ + "Align of template specialization: Rooted_open0_AutoValueVector_Alias_close0", + ][::std::mem::align_of::>() - 4usize]; + }; } diff --git a/bindgen-tests/tests/expectations/tests/issue-801-opaque-sloppiness.rs b/bindgen-tests/tests/expectations/tests/issue-801-opaque-sloppiness.rs index cf68821f18..3d39c6642b 100644 --- a/bindgen-tests/tests/expectations/tests/issue-801-opaque-sloppiness.rs +++ b/bindgen-tests/tests/expectations/tests/issue-801-opaque-sloppiness.rs @@ -10,15 +10,10 @@ pub struct A { pub struct B { pub _bindgen_opaque_blob: u8, } -#[test] -fn bindgen_test_layout_B() { - assert_eq!(::std::mem::size_of::(), 1usize, concat!("Size of: ", stringify!(B))); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(B)), - ); -} +const _: () = { + ["Size of B"][::std::mem::size_of::() - 1usize]; + ["Alignment of B"][::std::mem::align_of::() - 1usize]; +}; extern "C" { #[link_name = "\u{1}_ZN1B1aE"] pub static mut B_a: A; @@ -28,19 +23,8 @@ extern "C" { pub struct C { pub b: B, } -#[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::(), 1usize, concat!("Size of: ", stringify!(C))); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(C)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(b)), - ); -} +const _: () = { + ["Size of C"][::std::mem::size_of::() - 1usize]; + ["Alignment of C"][::std::mem::align_of::() - 1usize]; + ["Offset of field: C::b"][::std::mem::offset_of!(C, b) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs b/bindgen-tests/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs index ab807045be..c268b0cbad 100644 --- a/bindgen-tests/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs +++ b/bindgen-tests/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs @@ -4,74 +4,38 @@ pub struct Pupper { pub _address: u8, } -#[test] -fn bindgen_test_layout_Pupper() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Pupper)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Pupper)), - ); -} +const _: () = { + ["Size of Pupper"][::std::mem::size_of::() - 1usize]; + ["Alignment of Pupper"][::std::mem::align_of::() - 1usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct Doggo { pub _address: u8, } -#[test] -fn bindgen_test_layout_Doggo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Doggo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Doggo)), - ); -} +const _: () = { + ["Size of Doggo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Doggo"][::std::mem::align_of::() - 1usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct SuchWow { pub _address: u8, } -#[test] -fn bindgen_test_layout_SuchWow() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(SuchWow)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(SuchWow)), - ); -} +const _: () = { + ["Size of SuchWow"][::std::mem::size_of::() - 1usize]; + ["Alignment of SuchWow"][::std::mem::align_of::() - 1usize]; +}; #[repr(C)] #[repr(align(1))] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct Opaque { pub _bindgen_opaque_blob: u8, } -#[test] -fn bindgen_test_layout_Opaque() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Opaque)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Opaque)), - ); -} +const _: () = { + ["Size of Opaque"][::std::mem::size_of::() - 1usize]; + ["Alignment of Opaque"][::std::mem::align_of::() - 1usize]; +}; extern "C" { #[link_name = "\u{1}_ZN6Opaque17eleven_out_of_tenEv"] pub fn Opaque_eleven_out_of_ten(this: *mut Opaque) -> SuchWow; @@ -101,28 +65,10 @@ extern "C" { pub struct Allowlisted { pub some_member: Opaque, } -#[test] -fn bindgen_test_layout_Allowlisted() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Allowlisted)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Allowlisted)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).some_member) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Allowlisted), - "::", - stringify!(some_member), - ), - ); -} +const _: () = { + ["Size of Allowlisted"][::std::mem::size_of::() - 1usize]; + ["Alignment of Allowlisted"][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: Allowlisted::some_member", + ][::std::mem::offset_of!(Allowlisted, some_member) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/issue-816.rs b/bindgen-tests/tests/expectations/tests/issue-816.rs index 206e6ffd17..219bd3c89e 100644 --- a/bindgen-tests/tests/expectations/tests/issue-816.rs +++ b/bindgen-tests/tests/expectations/tests/issue-816.rs @@ -90,19 +90,10 @@ pub struct capabilities { pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 16usize]>, } -#[test] -fn bindgen_test_layout_capabilities() { - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(capabilities)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(capabilities)), - ); -} +const _: () = { + ["Size of capabilities"][::std::mem::size_of::() - 16usize]; + ["Alignment of capabilities"][::std::mem::align_of::() - 4usize]; +}; impl capabilities { #[inline] pub fn bit_1(&self) -> ::std::os::raw::c_uint { diff --git a/bindgen-tests/tests/expectations/tests/issue-826-generating-methods-when-asked-not-to.rs b/bindgen-tests/tests/expectations/tests/issue-826-generating-methods-when-asked-not-to.rs index d51ccfa80c..30de3dce72 100644 --- a/bindgen-tests/tests/expectations/tests/issue-826-generating-methods-when-asked-not-to.rs +++ b/bindgen-tests/tests/expectations/tests/issue-826-generating-methods-when-asked-not-to.rs @@ -4,16 +4,7 @@ pub struct Foo { pub _address: u8, } -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)), - ); -} +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/issue-834.rs b/bindgen-tests/tests/expectations/tests/issue-834.rs index 24c18c2be7..b8cbd24714 100644 --- a/bindgen-tests/tests/expectations/tests/issue-834.rs +++ b/bindgen-tests/tests/expectations/tests/issue-834.rs @@ -4,12 +4,7 @@ pub struct U { pub _address: u8, } -#[test] -fn bindgen_test_layout_U() { - assert_eq!(::std::mem::size_of::(), 1usize, concat!("Size of: ", stringify!(U))); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(U)), - ); -} +const _: () = { + ["Size of U"][::std::mem::size_of::() - 1usize]; + ["Alignment of U"][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/issue-888-enum-var-decl-jump.rs b/bindgen-tests/tests/expectations/tests/issue-888-enum-var-decl-jump.rs index 974e191401..66a72aa845 100644 --- a/bindgen-tests/tests/expectations/tests/issue-888-enum-var-decl-jump.rs +++ b/bindgen-tests/tests/expectations/tests/issue-888-enum-var-decl-jump.rs @@ -15,19 +15,10 @@ pub mod root { #[link_name = "\u{1}_ZN6Halide4Type1bE"] pub static mut Type_b: root::a; } - #[test] - fn bindgen_test_layout_Type() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Type)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Type)), - ); - } + const _: () = { + ["Size of Type"][::std::mem::size_of::() - 1usize]; + ["Alignment of Type"][::std::mem::align_of::() - 1usize]; + }; } #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] diff --git a/bindgen-tests/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs b/bindgen-tests/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs index a5cd116cfd..778b9514a0 100644 --- a/bindgen-tests/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs +++ b/bindgen-tests/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs @@ -5,26 +5,13 @@ pub struct BlocklistMe(u8); pub struct ShouldNotBeCopy { pub a: BlocklistMe, } -#[test] -fn bindgen_test_layout_ShouldNotBeCopy() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(ShouldNotBeCopy)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(ShouldNotBeCopy)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(ShouldNotBeCopy), "::", stringify!(a)), - ); -} +const _: () = { + ["Size of ShouldNotBeCopy"][::std::mem::size_of::() - 1usize]; + ["Alignment of ShouldNotBeCopy"][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: ShouldNotBeCopy::a", + ][::std::mem::offset_of!(ShouldNotBeCopy, a) - 0usize]; +}; impl Default for ShouldNotBeCopy { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/issue-946.rs b/bindgen-tests/tests/expectations/tests/issue-946.rs index a1bf320f1a..042feccbc1 100644 --- a/bindgen-tests/tests/expectations/tests/issue-946.rs +++ b/bindgen-tests/tests/expectations/tests/issue-946.rs @@ -2,17 +2,8 @@ #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct foo {} -#[test] -fn bindgen_test_layout_foo() { - assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(foo)), - ); -} +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 0usize]; + ["Alignment of foo"][::std::mem::align_of::() - 1usize]; +}; pub type bar = foo; diff --git a/bindgen-tests/tests/expectations/tests/issue_311.rs b/bindgen-tests/tests/expectations/tests/issue_311.rs index 8822aece04..fd2e6e80fb 100644 --- a/bindgen-tests/tests/expectations/tests/issue_311.rs +++ b/bindgen-tests/tests/expectations/tests/issue_311.rs @@ -13,30 +13,16 @@ pub mod root { pub struct jsval_layout__bindgen_ty_1 { pub _address: u8, } - #[test] - fn bindgen_test_layout_jsval_layout__bindgen_ty_1() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(jsval_layout__bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(jsval_layout__bindgen_ty_1)), - ); - } - #[test] - fn bindgen_test_layout_jsval_layout() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(jsval_layout)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(jsval_layout)), - ); - } + const _: () = { + [ + "Size of jsval_layout__bindgen_ty_1", + ][::std::mem::size_of::() - 1usize]; + [ + "Alignment of jsval_layout__bindgen_ty_1", + ][::std::mem::align_of::() - 1usize]; + }; + const _: () = { + ["Size of jsval_layout"][::std::mem::size_of::() - 1usize]; + ["Alignment of jsval_layout"][::std::mem::align_of::() - 1usize]; + }; } diff --git a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs index 576f57586a..93fcc92b48 100644 --- a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs +++ b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs @@ -186,19 +186,14 @@ pub struct jsval_layout__bindgen_ty_1 { pub _bitfield_align_1: [u64; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 8usize]>, } -#[test] -fn bindgen_test_layout_jsval_layout__bindgen_ty_1() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(jsval_layout__bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(jsval_layout__bindgen_ty_1)), - ); -} +const _: () = { + [ + "Size of jsval_layout__bindgen_ty_1", + ][::std::mem::size_of::() - 8usize]; + [ + "Alignment of jsval_layout__bindgen_ty_1", + ][::std::mem::align_of::() - 8usize]; +}; impl Default for jsval_layout__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -270,51 +265,23 @@ pub union jsval_layout__bindgen_ty_2__bindgen_ty_1 { pub u32_: u32, pub why: JSWhyMagic, } -#[test] -fn bindgen_test_layout_jsval_layout__bindgen_ty_2__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i32_) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), - "::", - stringify!(i32_), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).u32_) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), - "::", - stringify!(u32_), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).why) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), - "::", - stringify!(why), - ), - ); -} +const _: () = { + [ + "Size of jsval_layout__bindgen_ty_2__bindgen_ty_1", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of jsval_layout__bindgen_ty_2__bindgen_ty_1", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: jsval_layout__bindgen_ty_2__bindgen_ty_1::i32_", + ][::std::mem::offset_of!(jsval_layout__bindgen_ty_2__bindgen_ty_1, i32_) - 0usize]; + [ + "Offset of field: jsval_layout__bindgen_ty_2__bindgen_ty_1::u32_", + ][::std::mem::offset_of!(jsval_layout__bindgen_ty_2__bindgen_ty_1, u32_) - 0usize]; + [ + "Offset of field: jsval_layout__bindgen_ty_2__bindgen_ty_1::why", + ][::std::mem::offset_of!(jsval_layout__bindgen_ty_2__bindgen_ty_1, why) - 0usize]; +}; impl Default for jsval_layout__bindgen_ty_2__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -324,31 +291,17 @@ impl Default for jsval_layout__bindgen_ty_2__bindgen_ty_1 { } } } -#[test] -fn bindgen_test_layout_jsval_layout__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(jsval_layout__bindgen_ty_2)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(jsval_layout__bindgen_ty_2)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).payload) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2), - "::", - stringify!(payload), - ), - ); -} +const _: () = { + [ + "Size of jsval_layout__bindgen_ty_2", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of jsval_layout__bindgen_ty_2", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: jsval_layout__bindgen_ty_2::payload", + ][::std::mem::offset_of!(jsval_layout__bindgen_ty_2, payload) - 0usize]; +}; impl Default for jsval_layout__bindgen_ty_2 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -358,71 +311,31 @@ impl Default for jsval_layout__bindgen_ty_2 { } } } -#[test] -fn bindgen_test_layout_jsval_layout() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(jsval_layout)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(jsval_layout)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).asBits) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(jsval_layout), "::", stringify!(asBits)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).debugView) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(debugView), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).s) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(jsval_layout), "::", stringify!(s)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).asDouble) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asDouble), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).asPtr) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(jsval_layout), "::", stringify!(asPtr)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).asWord) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(jsval_layout), "::", stringify!(asWord)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).asUIntPtr) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asUIntPtr), - ), - ); -} +const _: () = { + ["Size of jsval_layout"][::std::mem::size_of::() - 8usize]; + ["Alignment of jsval_layout"][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: jsval_layout::asBits", + ][::std::mem::offset_of!(jsval_layout, asBits) - 0usize]; + [ + "Offset of field: jsval_layout::debugView", + ][::std::mem::offset_of!(jsval_layout, debugView) - 0usize]; + [ + "Offset of field: jsval_layout::s", + ][::std::mem::offset_of!(jsval_layout, s) - 0usize]; + [ + "Offset of field: jsval_layout::asDouble", + ][::std::mem::offset_of!(jsval_layout, asDouble) - 0usize]; + [ + "Offset of field: jsval_layout::asPtr", + ][::std::mem::offset_of!(jsval_layout, asPtr) - 0usize]; + [ + "Offset of field: jsval_layout::asWord", + ][::std::mem::offset_of!(jsval_layout, asWord) - 0usize]; + [ + "Offset of field: jsval_layout::asUIntPtr", + ][::std::mem::offset_of!(jsval_layout, asUIntPtr) - 0usize]; +}; impl Default for jsval_layout { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -437,26 +350,11 @@ impl Default for jsval_layout { pub struct Value { pub data: jsval_layout, } -#[test] -fn bindgen_test_layout_Value() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Value)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Value)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Value), "::", stringify!(data)), - ); -} +const _: () = { + ["Size of Value"][::std::mem::size_of::() - 8usize]; + ["Alignment of Value"][::std::mem::align_of::() - 8usize]; + ["Offset of field: Value::data"][::std::mem::offset_of!(Value, data) - 0usize]; +}; impl Default for Value { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs index 0889b65232..7ae53bc40f 100644 --- a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs @@ -235,12 +235,12 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_1() { assert_eq!( ::std::mem::size_of::(), 8usize, - concat!("Size of: ", stringify!(jsval_layout__bindgen_ty_1)), + "Size of jsval_layout__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(jsval_layout__bindgen_ty_1)), + "Alignment of jsval_layout__bindgen_ty_1", ); } impl Clone for jsval_layout__bindgen_ty_1 { @@ -327,42 +327,27 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2__bindgen_ty_1() { assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1)), + "Size of jsval_layout__bindgen_ty_2__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1)), + "Alignment of jsval_layout__bindgen_ty_2__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).i32_) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), - "::", - stringify!(i32_), - ), + "Offset of field: jsval_layout__bindgen_ty_2__bindgen_ty_1::i32_", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).u32_) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), - "::", - stringify!(u32_), - ), + "Offset of field: jsval_layout__bindgen_ty_2__bindgen_ty_1::u32_", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).why) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2__bindgen_ty_1), - "::", - stringify!(why), - ), + "Offset of field: jsval_layout__bindgen_ty_2__bindgen_ty_1::why", ); } impl Clone for jsval_layout__bindgen_ty_2__bindgen_ty_1 { @@ -377,22 +362,17 @@ fn bindgen_test_layout_jsval_layout__bindgen_ty_2() { assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(jsval_layout__bindgen_ty_2)), + "Size of jsval_layout__bindgen_ty_2", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(jsval_layout__bindgen_ty_2)), + "Alignment of jsval_layout__bindgen_ty_2", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).payload) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout__bindgen_ty_2), - "::", - stringify!(payload), - ), + "Offset of field: jsval_layout__bindgen_ty_2::payload", ); } impl Clone for jsval_layout__bindgen_ty_2 { @@ -404,65 +384,46 @@ impl Clone for jsval_layout__bindgen_ty_2 { fn bindgen_test_layout_jsval_layout() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(jsval_layout)), - ); + assert_eq!(::std::mem::size_of::(), 8usize, "Size of jsval_layout"); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(jsval_layout)), + "Alignment of jsval_layout", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).asBits) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(jsval_layout), "::", stringify!(asBits)), + "Offset of field: jsval_layout::asBits", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).debugView) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(debugView), - ), + "Offset of field: jsval_layout::debugView", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).s) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(jsval_layout), "::", stringify!(s)), + "Offset of field: jsval_layout::s", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).asDouble) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asDouble), - ), + "Offset of field: jsval_layout::asDouble", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).asPtr) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(jsval_layout), "::", stringify!(asPtr)), + "Offset of field: jsval_layout::asPtr", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).asWord) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(jsval_layout), "::", stringify!(asWord)), + "Offset of field: jsval_layout::asWord", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).asUIntPtr) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(jsval_layout), - "::", - stringify!(asUIntPtr), - ), + "Offset of field: jsval_layout::asUIntPtr", ); } impl Clone for jsval_layout { @@ -479,20 +440,12 @@ pub struct Value { fn bindgen_test_layout_Value() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Value)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Value)), - ); + assert_eq!(::std::mem::size_of::(), 8usize, "Size of Value"); + assert_eq!(::std::mem::align_of::(), 8usize, "Alignment of Value"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Value), "::", stringify!(data)), + "Offset of field: Value::data", ); } impl Clone for Value { diff --git a/bindgen-tests/tests/expectations/tests/layout.rs b/bindgen-tests/tests/expectations/tests/layout.rs index 2c7dc047ba..8c4819f543 100644 --- a/bindgen-tests/tests/expectations/tests/layout.rs +++ b/bindgen-tests/tests/expectations/tests/layout.rs @@ -5,11 +5,7 @@ pub struct header { } #[test] fn bindgen_test_layout_header() { - assert_eq!( - ::std::mem::size_of::
(), - 16usize, - concat!("Size of: ", stringify!(header)), - ); + assert_eq!(::std::mem::size_of::
(), 16usize, "Size of header"); } impl Default for header { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/layout_align.rs b/bindgen-tests/tests/expectations/tests/layout_align.rs index be77dc75d4..f7f22120ad 100644 --- a/bindgen-tests/tests/expectations/tests/layout_align.rs +++ b/bindgen-tests/tests/expectations/tests/layout_align.rs @@ -127,51 +127,25 @@ pub struct rte_kni_fifo { ///< The buffer contains mbuf pointers pub buffer: __IncompleteArrayField<*mut ::std::os::raw::c_void>, } -#[test] -fn bindgen_test_layout_rte_kni_fifo() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(rte_kni_fifo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(rte_kni_fifo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).write) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(rte_kni_fifo), "::", stringify!(write)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).read) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(rte_kni_fifo), "::", stringify!(read)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(rte_kni_fifo), "::", stringify!(len)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).elem_size) as usize - ptr as usize }, - 12usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_fifo), - "::", - stringify!(elem_size), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).buffer) as usize - ptr as usize }, - 16usize, - concat!("Offset of field: ", stringify!(rte_kni_fifo), "::", stringify!(buffer)), - ); -} +const _: () = { + ["Size of rte_kni_fifo"][::std::mem::size_of::() - 16usize]; + ["Alignment of rte_kni_fifo"][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: rte_kni_fifo::write", + ][::std::mem::offset_of!(rte_kni_fifo, write) - 0usize]; + [ + "Offset of field: rte_kni_fifo::read", + ][::std::mem::offset_of!(rte_kni_fifo, read) - 4usize]; + [ + "Offset of field: rte_kni_fifo::len", + ][::std::mem::offset_of!(rte_kni_fifo, len) - 8usize]; + [ + "Offset of field: rte_kni_fifo::elem_size", + ][::std::mem::offset_of!(rte_kni_fifo, elem_size) - 12usize]; + [ + "Offset of field: rte_kni_fifo::buffer", + ][::std::mem::offset_of!(rte_kni_fifo, buffer) - 16usize]; +}; impl Default for rte_kni_fifo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -191,31 +165,13 @@ pub struct rte_eth_link { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub __bindgen_padding_0: [u8; 3usize], } -#[test] -fn bindgen_test_layout_rte_eth_link() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(rte_eth_link)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(rte_eth_link)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).link_speed) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_link), - "::", - stringify!(link_speed), - ), - ); -} +const _: () = { + ["Size of rte_eth_link"][::std::mem::size_of::() - 8usize]; + ["Alignment of rte_eth_link"][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: rte_eth_link::link_speed", + ][::std::mem::offset_of!(rte_eth_link, link_speed) - 0usize]; +}; impl rte_eth_link { #[inline] pub fn link_duplex(&self) -> u16 { diff --git a/bindgen-tests/tests/expectations/tests/layout_arp.rs b/bindgen-tests/tests/expectations/tests/layout_arp.rs index 45e0156f68..c48fd0e24e 100644 --- a/bindgen-tests/tests/expectations/tests/layout_arp.rs +++ b/bindgen-tests/tests/expectations/tests/layout_arp.rs @@ -22,31 +22,13 @@ pub struct ether_addr { ///< Addr bytes in tx order pub addr_bytes: [u8; 6usize], } -#[test] -fn bindgen_test_layout_ether_addr() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 6usize, - concat!("Size of: ", stringify!(ether_addr)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(ether_addr)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).addr_bytes) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ether_addr), - "::", - stringify!(addr_bytes), - ), - ); -} +const _: () = { + ["Size of ether_addr"][::std::mem::size_of::() - 6usize]; + ["Alignment of ether_addr"][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: ether_addr::addr_bytes", + ][::std::mem::offset_of!(ether_addr, addr_bytes) - 0usize]; +}; /// ARP header IPv4 payload. #[repr(C, packed)] #[derive(Debug, Default, Copy, Clone)] @@ -60,41 +42,22 @@ pub struct arp_ipv4 { ///< target IP address pub arp_tip: u32, } -#[test] -fn bindgen_test_layout_arp_ipv4() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 20usize, - concat!("Size of: ", stringify!(arp_ipv4)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(arp_ipv4)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).arp_sha) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(arp_ipv4), "::", stringify!(arp_sha)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).arp_sip) as usize - ptr as usize }, - 6usize, - concat!("Offset of field: ", stringify!(arp_ipv4), "::", stringify!(arp_sip)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).arp_tha) as usize - ptr as usize }, - 10usize, - concat!("Offset of field: ", stringify!(arp_ipv4), "::", stringify!(arp_tha)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).arp_tip) as usize - ptr as usize }, - 16usize, - concat!("Offset of field: ", stringify!(arp_ipv4), "::", stringify!(arp_tip)), - ); -} +const _: () = { + ["Size of arp_ipv4"][::std::mem::size_of::() - 20usize]; + ["Alignment of arp_ipv4"][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: arp_ipv4::arp_sha", + ][::std::mem::offset_of!(arp_ipv4, arp_sha) - 0usize]; + [ + "Offset of field: arp_ipv4::arp_sip", + ][::std::mem::offset_of!(arp_ipv4, arp_sip) - 6usize]; + [ + "Offset of field: arp_ipv4::arp_tha", + ][::std::mem::offset_of!(arp_ipv4, arp_tha) - 10usize]; + [ + "Offset of field: arp_ipv4::arp_tip", + ][::std::mem::offset_of!(arp_ipv4, arp_tip) - 16usize]; +}; /// ARP header. #[repr(C, packed)] #[derive(Debug, Default, Copy, Clone)] @@ -106,48 +69,25 @@ pub struct arp_hdr { pub arp_op: u16, pub arp_data: arp_ipv4, } -#[test] -fn bindgen_test_layout_arp_hdr() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 28usize, - concat!("Size of: ", stringify!(arp_hdr)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(arp_hdr)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).arp_hrd) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(arp_hdr), "::", stringify!(arp_hrd)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).arp_pro) as usize - ptr as usize }, - 2usize, - concat!("Offset of field: ", stringify!(arp_hdr), "::", stringify!(arp_pro)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).arp_hln) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(arp_hdr), "::", stringify!(arp_hln)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).arp_pln) as usize - ptr as usize }, - 5usize, - concat!("Offset of field: ", stringify!(arp_hdr), "::", stringify!(arp_pln)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).arp_op) as usize - ptr as usize }, - 6usize, - concat!("Offset of field: ", stringify!(arp_hdr), "::", stringify!(arp_op)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).arp_data) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(arp_hdr), "::", stringify!(arp_data)), - ); -} +const _: () = { + ["Size of arp_hdr"][::std::mem::size_of::() - 28usize]; + ["Alignment of arp_hdr"][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: arp_hdr::arp_hrd", + ][::std::mem::offset_of!(arp_hdr, arp_hrd) - 0usize]; + [ + "Offset of field: arp_hdr::arp_pro", + ][::std::mem::offset_of!(arp_hdr, arp_pro) - 2usize]; + [ + "Offset of field: arp_hdr::arp_hln", + ][::std::mem::offset_of!(arp_hdr, arp_hln) - 4usize]; + [ + "Offset of field: arp_hdr::arp_pln", + ][::std::mem::offset_of!(arp_hdr, arp_pln) - 5usize]; + [ + "Offset of field: arp_hdr::arp_op", + ][::std::mem::offset_of!(arp_hdr, arp_op) - 6usize]; + [ + "Offset of field: arp_hdr::arp_data", + ][::std::mem::offset_of!(arp_hdr, arp_data) - 8usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/layout_array.rs b/bindgen-tests/tests/expectations/tests/layout_array.rs index dcf6f17b5c..b910159beb 100644 --- a/bindgen-tests/tests/expectations/tests/layout_array.rs +++ b/bindgen-tests/tests/expectations/tests/layout_array.rs @@ -68,62 +68,42 @@ fn bindgen_test_layout_rte_mempool_ops() { assert_eq!( ::std::mem::size_of::(), 128usize, - concat!("Size of: ", stringify!(rte_mempool_ops)), + "Size of rte_mempool_ops", ); assert_eq!( ::std::mem::align_of::(), 64usize, - concat!("Alignment of ", stringify!(rte_mempool_ops)), + "Alignment of rte_mempool_ops", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).name) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_mempool_ops), "::", stringify!(name)), + "Offset of field: rte_mempool_ops::name", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).alloc) as usize - ptr as usize }, 32usize, - concat!( - "Offset of field: ", - stringify!(rte_mempool_ops), - "::", - stringify!(alloc), - ), + "Offset of field: rte_mempool_ops::alloc", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).free) as usize - ptr as usize }, 40usize, - concat!("Offset of field: ", stringify!(rte_mempool_ops), "::", stringify!(free)), + "Offset of field: rte_mempool_ops::free", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).enqueue) as usize - ptr as usize }, 48usize, - concat!( - "Offset of field: ", - stringify!(rte_mempool_ops), - "::", - stringify!(enqueue), - ), + "Offset of field: rte_mempool_ops::enqueue", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).dequeue) as usize - ptr as usize }, 56usize, - concat!( - "Offset of field: ", - stringify!(rte_mempool_ops), - "::", - stringify!(dequeue), - ), + "Offset of field: rte_mempool_ops::dequeue", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).get_count) as usize - ptr as usize }, 64usize, - concat!( - "Offset of field: ", - stringify!(rte_mempool_ops), - "::", - stringify!(get_count), - ), + "Offset of field: rte_mempool_ops::get_count", ); } impl Default for rte_mempool_ops { @@ -156,22 +136,17 @@ fn bindgen_test_layout_rte_spinlock_t() { assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(rte_spinlock_t)), + "Size of rte_spinlock_t", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_spinlock_t)), + "Alignment of rte_spinlock_t", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).locked) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_spinlock_t), - "::", - stringify!(locked), - ), + "Offset of field: rte_spinlock_t::locked", ); } /** Structure storing the table of registered ops structs, each of which contain @@ -200,42 +175,27 @@ fn bindgen_test_layout_rte_mempool_ops_table() { assert_eq!( ::std::mem::size_of::(), 2112usize, - concat!("Size of: ", stringify!(rte_mempool_ops_table)), + "Size of rte_mempool_ops_table", ); assert_eq!( ::std::mem::align_of::(), 64usize, - concat!("Alignment of ", stringify!(rte_mempool_ops_table)), + "Alignment of rte_mempool_ops_table", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).sl) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mempool_ops_table), - "::", - stringify!(sl), - ), + "Offset of field: rte_mempool_ops_table::sl", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).num_ops) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(rte_mempool_ops_table), - "::", - stringify!(num_ops), - ), + "Offset of field: rte_mempool_ops_table::num_ops", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).ops) as usize - ptr as usize }, 64usize, - concat!( - "Offset of field: ", - stringify!(rte_mempool_ops_table), - "::", - stringify!(ops), - ), + "Offset of field: rte_mempool_ops_table::ops", ); } impl Default for rte_mempool_ops_table { @@ -269,22 +229,17 @@ fn bindgen_test_layout_malloc_heap__bindgen_ty_1() { assert_eq!( ::std::mem::size_of::(), 8usize, - concat!("Size of: ", stringify!(malloc_heap__bindgen_ty_1)), + "Size of malloc_heap__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(malloc_heap__bindgen_ty_1)), + "Alignment of malloc_heap__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).lh_first) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(malloc_heap__bindgen_ty_1), - "::", - stringify!(lh_first), - ), + "Offset of field: malloc_heap__bindgen_ty_1::lh_first", ); } impl Default for malloc_heap__bindgen_ty_1 { @@ -300,50 +255,31 @@ impl Default for malloc_heap__bindgen_ty_1 { 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, - concat!("Size of: ", stringify!(malloc_heap)), - ); + assert_eq!(::std::mem::size_of::(), 128usize, "Size of malloc_heap"); assert_eq!( ::std::mem::align_of::(), 64usize, - concat!("Alignment of ", stringify!(malloc_heap)), + "Alignment of malloc_heap", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).lock) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(malloc_heap), "::", stringify!(lock)), + "Offset of field: malloc_heap::lock", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).free_head) as usize - ptr as usize }, 8usize, - concat!( - "Offset of field: ", - stringify!(malloc_heap), - "::", - stringify!(free_head), - ), + "Offset of field: malloc_heap::free_head", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).alloc_count) as usize - ptr as usize }, 112usize, - concat!( - "Offset of field: ", - stringify!(malloc_heap), - "::", - stringify!(alloc_count), - ), + "Offset of field: malloc_heap::alloc_count", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).total_size) as usize - ptr as usize }, 120usize, - concat!( - "Offset of field: ", - stringify!(malloc_heap), - "::", - stringify!(total_size), - ), + "Offset of field: malloc_heap::total_size", ); } impl Default for malloc_heap { 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 52e7532ba2..d6ce2883d7 100644 --- a/bindgen-tests/tests/expectations/tests/layout_array_too_long.rs +++ b/bindgen-tests/tests/expectations/tests/layout_array_too_long.rs @@ -31,30 +31,22 @@ pub struct ip_frag { 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, - concat!("Size of: ", stringify!(ip_frag)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(ip_frag)), - ); + 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, - concat!("Offset of field: ", stringify!(ip_frag), "::", stringify!(ofs)), + "Offset of field: ip_frag::ofs", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize }, 2usize, - concat!("Offset of field: ", stringify!(ip_frag), "::", stringify!(len)), + "Offset of field: ip_frag::len", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mb) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(ip_frag), "::", stringify!(mb)), + "Offset of field: ip_frag::mb", ); } impl Default for ip_frag { @@ -81,30 +73,26 @@ pub struct ip_frag_key { 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, - concat!("Size of: ", stringify!(ip_frag_key)), - ); + assert_eq!(::std::mem::size_of::(), 40usize, "Size of ip_frag_key"); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(ip_frag_key)), + "Alignment of ip_frag_key", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).src_dst) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(ip_frag_key), "::", stringify!(src_dst)), + "Offset of field: ip_frag_key::src_dst", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).id) as usize - ptr as usize }, 32usize, - concat!("Offset of field: ", stringify!(ip_frag_key), "::", stringify!(id)), + "Offset of field: ip_frag_key::id", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).key_len) as usize - ptr as usize }, 36usize, - concat!("Offset of field: ", stringify!(ip_frag_key), "::", stringify!(key_len)), + "Offset of field: ip_frag_key::key_len", ); } /** @internal Fragmented packet to reassemble. @@ -141,32 +129,22 @@ fn bindgen_test_layout_ip_frag_pkt__bindgen_ty_1() { assert_eq!( ::std::mem::size_of::(), 16usize, - concat!("Size of: ", stringify!(ip_frag_pkt__bindgen_ty_1)), + "Size of ip_frag_pkt__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(ip_frag_pkt__bindgen_ty_1)), + "Alignment of ip_frag_pkt__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).tqe_next) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt__bindgen_ty_1), - "::", - stringify!(tqe_next), - ), + "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, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt__bindgen_ty_1), - "::", - stringify!(tqe_prev), - ), + "Offset of field: ip_frag_pkt__bindgen_ty_1::tqe_prev", ); } impl Default for ip_frag_pkt__bindgen_ty_1 { @@ -182,60 +160,46 @@ impl Default for ip_frag_pkt__bindgen_ty_1 { 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, - concat!("Size of: ", stringify!(ip_frag_pkt)), - ); + assert_eq!(::std::mem::size_of::(), 192usize, "Size of ip_frag_pkt"); assert_eq!( ::std::mem::align_of::(), 64usize, - concat!("Alignment of ", stringify!(ip_frag_pkt)), + "Alignment of ip_frag_pkt", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).lru) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", stringify!(lru)), + "Offset of field: ip_frag_pkt::lru", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).key) as usize - ptr as usize }, 16usize, - concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", stringify!(key)), + "Offset of field: ip_frag_pkt::key", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).start) as usize - ptr as usize }, 56usize, - concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", stringify!(start)), + "Offset of field: ip_frag_pkt::start", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).total_size) as usize - ptr as usize }, 64usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(total_size), - ), + "Offset of field: ip_frag_pkt::total_size", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).frag_size) as usize - ptr as usize }, 68usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(frag_size), - ), + "Offset of field: ip_frag_pkt::frag_size", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).last_idx) as usize - ptr as usize }, 72usize, - concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", stringify!(last_idx)), + "Offset of field: ip_frag_pkt::last_idx", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).frags) as usize - ptr as usize }, 80usize, - concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", stringify!(frags)), + "Offset of field: ip_frag_pkt::frags", ); } impl Default for ip_frag_pkt { diff --git a/bindgen-tests/tests/expectations/tests/layout_cmdline_token.rs b/bindgen-tests/tests/expectations/tests/layout_cmdline_token.rs index 6141ab8f67..e187a4a7f6 100644 --- a/bindgen-tests/tests/expectations/tests/layout_cmdline_token.rs +++ b/bindgen-tests/tests/expectations/tests/layout_cmdline_token.rs @@ -7,41 +7,18 @@ pub struct cmdline_token_hdr { pub ops: *mut cmdline_token_ops, pub offset: ::std::os::raw::c_uint, } -#[test] -fn bindgen_test_layout_cmdline_token_hdr() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(cmdline_token_hdr)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(cmdline_token_hdr)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ops) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(cmdline_token_hdr), - "::", - stringify!(ops), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).offset) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(cmdline_token_hdr), - "::", - stringify!(offset), - ), - ); -} +const _: () = { + ["Size of cmdline_token_hdr"][::std::mem::size_of::() - 16usize]; + [ + "Alignment of cmdline_token_hdr", + ][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: cmdline_token_hdr::ops", + ][::std::mem::offset_of!(cmdline_token_hdr, ops) - 0usize]; + [ + "Offset of field: cmdline_token_hdr::offset", + ][::std::mem::offset_of!(cmdline_token_hdr, offset) - 8usize]; +}; impl Default for cmdline_token_hdr { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -107,61 +84,24 @@ pub struct cmdline_token_ops { ) -> ::std::os::raw::c_int, >, } -#[test] -fn bindgen_test_layout_cmdline_token_ops() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 32usize, - concat!("Size of: ", stringify!(cmdline_token_ops)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(cmdline_token_ops)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).parse) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(cmdline_token_ops), - "::", - stringify!(parse), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).complete_get_nb) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(cmdline_token_ops), - "::", - stringify!(complete_get_nb), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).complete_get_elt) as usize - ptr as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(cmdline_token_ops), - "::", - stringify!(complete_get_elt), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).get_help) as usize - ptr as usize }, - 24usize, - concat!( - "Offset of field: ", - stringify!(cmdline_token_ops), - "::", - stringify!(get_help), - ), - ); -} +const _: () = { + ["Size of cmdline_token_ops"][::std::mem::size_of::() - 32usize]; + [ + "Alignment of cmdline_token_ops", + ][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: cmdline_token_ops::parse", + ][::std::mem::offset_of!(cmdline_token_ops, parse) - 0usize]; + [ + "Offset of field: cmdline_token_ops::complete_get_nb", + ][::std::mem::offset_of!(cmdline_token_ops, complete_get_nb) - 8usize]; + [ + "Offset of field: cmdline_token_ops::complete_get_elt", + ][::std::mem::offset_of!(cmdline_token_ops, complete_get_elt) - 16usize]; + [ + "Offset of field: cmdline_token_ops::get_help", + ][::std::mem::offset_of!(cmdline_token_ops, get_help) - 24usize]; +}; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum cmdline_numtype { @@ -179,31 +119,17 @@ pub enum cmdline_numtype { pub struct cmdline_token_num_data { pub type_: cmdline_numtype, } -#[test] -fn bindgen_test_layout_cmdline_token_num_data() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(cmdline_token_num_data)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(cmdline_token_num_data)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(cmdline_token_num_data), - "::", - stringify!(type_), - ), - ); -} +const _: () = { + [ + "Size of cmdline_token_num_data", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of cmdline_token_num_data", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: cmdline_token_num_data::type_", + ][::std::mem::offset_of!(cmdline_token_num_data, type_) - 0usize]; +}; impl Default for cmdline_token_num_data { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -219,41 +145,18 @@ pub struct cmdline_token_num { pub hdr: cmdline_token_hdr, pub num_data: cmdline_token_num_data, } -#[test] -fn bindgen_test_layout_cmdline_token_num() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 24usize, - concat!("Size of: ", stringify!(cmdline_token_num)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(cmdline_token_num)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).hdr) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(cmdline_token_num), - "::", - stringify!(hdr), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).num_data) as usize - ptr as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(cmdline_token_num), - "::", - stringify!(num_data), - ), - ); -} +const _: () = { + ["Size of cmdline_token_num"][::std::mem::size_of::() - 24usize]; + [ + "Alignment of cmdline_token_num", + ][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: cmdline_token_num::hdr", + ][::std::mem::offset_of!(cmdline_token_num, hdr) - 0usize]; + [ + "Offset of field: cmdline_token_num::num_data", + ][::std::mem::offset_of!(cmdline_token_num, num_data) - 16usize]; +}; impl Default for cmdline_token_num { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs b/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs index 84af546c8c..9b98bac376 100644 --- a/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs +++ b/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs @@ -157,42 +157,27 @@ fn bindgen_test_layout_rte_eth_rxmode() { assert_eq!( ::std::mem::size_of::(), 12usize, - concat!("Size of: ", stringify!(rte_eth_rxmode)), + "Size of rte_eth_rxmode", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_rxmode)), + "Alignment of rte_eth_rxmode", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mq_mode) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rxmode), - "::", - stringify!(mq_mode), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_rxmode), - "::", - stringify!(max_rx_pkt_len), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_rxmode), - "::", - stringify!(split_hdr_size), - ), + "Offset of field: rte_eth_rxmode::split_hdr_size", ); } impl Default for rte_eth_rxmode { @@ -447,27 +432,22 @@ fn bindgen_test_layout_rte_eth_txmode() { assert_eq!( ::std::mem::size_of::(), 8usize, - concat!("Size of: ", stringify!(rte_eth_txmode)), + "Size of rte_eth_txmode", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_txmode)), + "Alignment of rte_eth_txmode", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mq_mode) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_txmode), - "::", - stringify!(mq_mode), - ), + "Offset of field: rte_eth_txmode::mq_mode", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).pvid) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(rte_eth_txmode), "::", stringify!(pvid)), + "Offset of field: rte_eth_txmode::pvid", ); } impl Default for rte_eth_txmode { @@ -588,42 +568,27 @@ fn bindgen_test_layout_rte_eth_rss_conf() { assert_eq!( ::std::mem::size_of::(), 24usize, - concat!("Size of: ", stringify!(rte_eth_rss_conf)), + "Size of rte_eth_rss_conf", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(rte_eth_rss_conf)), + "Alignment of rte_eth_rss_conf", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).rss_key) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rss_conf), - "::", - stringify!(rss_key), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_rss_conf), - "::", - stringify!(rss_key_len), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_rss_conf), - "::", - stringify!(rss_hf), - ), + "Offset of field: rte_eth_rss_conf::rss_hf", ); } impl Default for rte_eth_rss_conf { @@ -698,32 +663,22 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf__bindgen_ty_1() { assert_eq!( ::std::mem::size_of::(), 16usize, - concat!("Size of: ", stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1)), + "Size of rte_eth_vmdq_dcb_conf__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1)), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1), - "::", - stringify!(vlan_id), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1), - "::", - stringify!(pools), - ), + "Offset of field: rte_eth_vmdq_dcb_conf__bindgen_ty_1::pools", ); } #[test] @@ -733,74 +688,44 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { assert_eq!( ::std::mem::size_of::(), 1040usize, - concat!("Size of: ", stringify!(rte_eth_vmdq_dcb_conf)), + "Size of rte_eth_vmdq_dcb_conf", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(rte_eth_vmdq_dcb_conf)), + "Alignment of rte_eth_vmdq_dcb_conf", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(nb_queue_pools), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(enable_default_pool), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(default_pool), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(nb_pool_maps), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(pool_map), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(dcb_tc), - ), + "Offset of field: rte_eth_vmdq_dcb_conf::dcb_tc", ); } impl Default for rte_eth_vmdq_dcb_conf { @@ -827,32 +752,22 @@ fn bindgen_test_layout_rte_eth_dcb_rx_conf() { assert_eq!( ::std::mem::size_of::(), 12usize, - concat!("Size of: ", stringify!(rte_eth_dcb_rx_conf)), + "Size of rte_eth_dcb_rx_conf", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_dcb_rx_conf)), + "Alignment of rte_eth_dcb_rx_conf", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_dcb_rx_conf), - "::", - stringify!(nb_tcs), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_dcb_rx_conf), - "::", - stringify!(dcb_tc), - ), + "Offset of field: rte_eth_dcb_rx_conf::dcb_tc", ); } impl Default for rte_eth_dcb_rx_conf { @@ -879,32 +794,22 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_tx_conf() { assert_eq!( ::std::mem::size_of::(), 12usize, - concat!("Size of: ", stringify!(rte_eth_vmdq_dcb_tx_conf)), + "Size of rte_eth_vmdq_dcb_tx_conf", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_vmdq_dcb_tx_conf)), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_tx_conf), - "::", - stringify!(nb_queue_pools), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_tx_conf), - "::", - stringify!(dcb_tc), - ), + "Offset of field: rte_eth_vmdq_dcb_tx_conf::dcb_tc", ); } impl Default for rte_eth_vmdq_dcb_tx_conf { @@ -931,32 +836,22 @@ fn bindgen_test_layout_rte_eth_dcb_tx_conf() { assert_eq!( ::std::mem::size_of::(), 12usize, - concat!("Size of: ", stringify!(rte_eth_dcb_tx_conf)), + "Size of rte_eth_dcb_tx_conf", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_dcb_tx_conf)), + "Alignment of rte_eth_dcb_tx_conf", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_dcb_tx_conf), - "::", - stringify!(nb_tcs), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_dcb_tx_conf), - "::", - stringify!(dcb_tc), - ), + "Offset of field: rte_eth_dcb_tx_conf::dcb_tc", ); } impl Default for rte_eth_dcb_tx_conf { @@ -981,22 +876,17 @@ fn bindgen_test_layout_rte_eth_vmdq_tx_conf() { assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(rte_eth_vmdq_tx_conf)), + "Size of rte_eth_vmdq_tx_conf", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_vmdq_tx_conf)), + "Alignment of rte_eth_vmdq_tx_conf", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_tx_conf), - "::", - stringify!(nb_queue_pools), - ), + "Offset of field: rte_eth_vmdq_tx_conf::nb_queue_pools", ); } impl Default for rte_eth_vmdq_tx_conf { @@ -1041,32 +931,22 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf__bindgen_ty_1() { assert_eq!( ::std::mem::size_of::(), 16usize, - concat!("Size of: ", stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1)), + "Size of rte_eth_vmdq_rx_conf__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1)), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1), - "::", - stringify!(vlan_id), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1), - "::", - stringify!(pools), - ), + "Offset of field: rte_eth_vmdq_rx_conf__bindgen_ty_1::pools", ); } #[test] @@ -1076,84 +956,49 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { assert_eq!( ::std::mem::size_of::(), 1040usize, - concat!("Size of: ", stringify!(rte_eth_vmdq_rx_conf)), + "Size of rte_eth_vmdq_rx_conf", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(rte_eth_vmdq_rx_conf)), + "Alignment of rte_eth_vmdq_rx_conf", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(nb_queue_pools), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(enable_default_pool), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(default_pool), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(enable_loop_back), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(nb_pool_maps), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(rx_mode), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(pool_map), - ), + "Offset of field: rte_eth_vmdq_rx_conf::pool_map", ); } impl Default for rte_eth_vmdq_rx_conf { @@ -1225,62 +1070,37 @@ fn bindgen_test_layout_rte_eth_ipv4_flow() { assert_eq!( ::std::mem::size_of::(), 12usize, - concat!("Size of: ", stringify!(rte_eth_ipv4_flow)), + "Size of rte_eth_ipv4_flow", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_ipv4_flow)), + "Alignment of rte_eth_ipv4_flow", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(src_ip), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(dst_ip), - ), + "Offset of field: rte_eth_ipv4_flow::dst_ip", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).tos) as usize - ptr as usize }, 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(tos), - ), + "Offset of field: rte_eth_ipv4_flow::tos", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).ttl) as usize - ptr as usize }, 9usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(ttl), - ), + "Offset of field: rte_eth_ipv4_flow::ttl", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize }, 10usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(proto), - ), + "Offset of field: rte_eth_ipv4_flow::proto", ); } /// A structure used to define the input for IPV6 flow @@ -1305,57 +1125,37 @@ fn bindgen_test_layout_rte_eth_ipv6_flow() { assert_eq!( ::std::mem::size_of::(), 36usize, - concat!("Size of: ", stringify!(rte_eth_ipv6_flow)), + "Size of rte_eth_ipv6_flow", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_ipv6_flow)), + "Alignment of rte_eth_ipv6_flow", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(src_ip), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(dst_ip), - ), + "Offset of field: rte_eth_ipv6_flow::dst_ip", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).tc) as usize - ptr as usize }, 32usize, - concat!("Offset of field: ", stringify!(rte_eth_ipv6_flow), "::", stringify!(tc)), + "Offset of field: rte_eth_ipv6_flow::tc", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize }, 33usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(proto), - ), + "Offset of field: rte_eth_ipv6_flow::proto", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).hop_limits) as usize - ptr as usize }, 34usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(hop_limits), - ), + "Offset of field: rte_eth_ipv6_flow::hop_limits", ); } /** A structure used to configure FDIR masks that are used by the device @@ -1389,94 +1189,54 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { assert_eq!( ::std::mem::size_of::(), 68usize, - concat!("Size of: ", stringify!(rte_eth_fdir_masks)), + "Size of rte_eth_fdir_masks", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_fdir_masks)), + "Alignment of rte_eth_fdir_masks", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).vlan_tci_mask) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(vlan_tci_mask), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(ipv4_mask), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(ipv6_mask), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(src_port_mask), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(dst_port_mask), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(mac_addr_byte_mask), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(tunnel_id_mask), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(tunnel_type_mask), - ), + "Offset of field: rte_eth_fdir_masks::tunnel_type_mask", ); } #[repr(u32)] @@ -1506,32 +1266,22 @@ fn bindgen_test_layout_rte_eth_flex_payload_cfg() { assert_eq!( ::std::mem::size_of::(), 36usize, - concat!("Size of: ", stringify!(rte_eth_flex_payload_cfg)), + "Size of rte_eth_flex_payload_cfg", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_flex_payload_cfg)), + "Alignment of rte_eth_flex_payload_cfg", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_flex_payload_cfg), - "::", - stringify!(type_), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_flex_payload_cfg), - "::", - stringify!(src_offset), - ), + "Offset of field: rte_eth_flex_payload_cfg::src_offset", ); } impl Default for rte_eth_flex_payload_cfg { @@ -1558,32 +1308,22 @@ fn bindgen_test_layout_rte_eth_fdir_flex_mask() { assert_eq!( ::std::mem::size_of::(), 18usize, - concat!("Size of: ", stringify!(rte_eth_fdir_flex_mask)), + "Size of rte_eth_fdir_flex_mask", ); assert_eq!( ::std::mem::align_of::(), 2usize, - concat!("Alignment of ", stringify!(rte_eth_fdir_flex_mask)), + "Alignment of rte_eth_fdir_flex_mask", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).flow_type) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_mask), - "::", - stringify!(flow_type), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_mask), - "::", - stringify!(mask), - ), + "Offset of field: rte_eth_fdir_flex_mask::mask", ); } /** A structure used to define all flexible payload related setting @@ -1605,52 +1345,32 @@ fn bindgen_test_layout_rte_eth_fdir_flex_conf() { assert_eq!( ::std::mem::size_of::(), 688usize, - concat!("Size of: ", stringify!(rte_eth_fdir_flex_conf)), + "Size of rte_eth_fdir_flex_conf", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_fdir_flex_conf)), + "Alignment of rte_eth_fdir_flex_conf", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).nb_payloads) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_conf), - "::", - stringify!(nb_payloads), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_conf), - "::", - stringify!(nb_flexmasks), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_conf), - "::", - stringify!(flex_set), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_conf), - "::", - stringify!(flex_mask), - ), + "Offset of field: rte_eth_fdir_flex_conf::flex_mask", ); } impl Default for rte_eth_fdir_flex_conf { @@ -1687,57 +1407,42 @@ fn bindgen_test_layout_rte_fdir_conf() { assert_eq!( ::std::mem::size_of::(), 772usize, - concat!("Size of: ", stringify!(rte_fdir_conf)), + "Size of rte_fdir_conf", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_fdir_conf)), + "Alignment of rte_fdir_conf", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mode) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_fdir_conf), "::", stringify!(mode)), + "Offset of field: rte_fdir_conf::mode", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).pballoc) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(pballoc), - ), + "Offset of field: rte_fdir_conf::pballoc", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).status) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(rte_fdir_conf), "::", stringify!(status)), + "Offset of field: rte_fdir_conf::status", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).drop_queue) as usize - ptr as usize }, 12usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(drop_queue), - ), + "Offset of field: rte_fdir_conf::drop_queue", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize }, 16usize, - concat!("Offset of field: ", stringify!(rte_fdir_conf), "::", stringify!(mask)), + "Offset of field: rte_fdir_conf::mask", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).flex_conf) as usize - ptr as usize }, 84usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(flex_conf), - ), + "Offset of field: rte_fdir_conf::flex_conf", ); } impl Default for rte_fdir_conf { @@ -1762,25 +1467,21 @@ pub struct rte_intr_conf { 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, - concat!("Size of: ", stringify!(rte_intr_conf)), - ); + assert_eq!(::std::mem::size_of::(), 4usize, "Size of rte_intr_conf"); assert_eq!( ::std::mem::align_of::(), 2usize, - concat!("Alignment of ", stringify!(rte_intr_conf)), + "Alignment of rte_intr_conf", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).lsc) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_intr_conf), "::", stringify!(lsc)), + "Offset of field: rte_intr_conf::lsc", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).rxq) as usize - ptr as usize }, 2usize, - concat!("Offset of field: ", stringify!(rte_intr_conf), "::", stringify!(rxq)), + "Offset of field: rte_intr_conf::rxq", ); } /** A structure used to configure an Ethernet port. @@ -1835,52 +1536,32 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_1() { assert_eq!( ::std::mem::size_of::(), 2120usize, - concat!("Size of: ", stringify!(rte_eth_conf__bindgen_ty_1)), + "Size of rte_eth_conf__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(rte_eth_conf__bindgen_ty_1)), + "Alignment of rte_eth_conf__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).rss_conf) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_1), - "::", - stringify!(rss_conf), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_1), - "::", - stringify!(vmdq_dcb_conf), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_1), - "::", - stringify!(dcb_rx_conf), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_1), - "::", - stringify!(vmdq_rx_conf), - ), + "Offset of field: rte_eth_conf__bindgen_ty_1::vmdq_rx_conf", ); } impl Default for rte_eth_conf__bindgen_ty_1 { @@ -1906,42 +1587,27 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_2() { assert_eq!( ::std::mem::size_of::(), 12usize, - concat!("Size of: ", stringify!(rte_eth_conf__bindgen_ty_2)), + "Size of rte_eth_conf__bindgen_ty_2", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_conf__bindgen_ty_2)), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_2), - "::", - stringify!(vmdq_dcb_tx_conf), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_2), - "::", - stringify!(dcb_tx_conf), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_2), - "::", - stringify!(vmdq_tx_conf), - ), + "Offset of field: rte_eth_conf__bindgen_ty_2::vmdq_tx_conf", ); } impl Default for rte_eth_conf__bindgen_ty_2 { @@ -1957,97 +1623,58 @@ impl Default for rte_eth_conf__bindgen_ty_2 { 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, - concat!("Size of: ", stringify!(rte_eth_conf)), - ); + assert_eq!(::std::mem::size_of::(), 2944usize, "Size of rte_eth_conf"); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(rte_eth_conf)), + "Alignment of rte_eth_conf", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).link_speeds) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(link_speeds), - ), + "Offset of field: rte_eth_conf::link_speeds", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).rxmode) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(rte_eth_conf), "::", stringify!(rxmode)), + "Offset of field: rte_eth_conf::rxmode", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).txmode) as usize - ptr as usize }, 16usize, - concat!("Offset of field: ", stringify!(rte_eth_conf), "::", stringify!(txmode)), + "Offset of field: rte_eth_conf::txmode", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).lpbk_mode) as usize - ptr as usize }, 24usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(lpbk_mode), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(rx_adv_conf), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(tx_adv_conf), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(dcb_capability_en), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(fdir_conf), - ), + "Offset of field: rte_eth_conf::fdir_conf", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).intr_conf) as usize - ptr as usize }, 2940usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(intr_conf), - ), + "Offset of field: rte_eth_conf::intr_conf", ); } impl Default for rte_eth_conf { diff --git a/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs b/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs index e2ae2b0c17..34688b20b3 100644 --- a/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs @@ -200,42 +200,27 @@ fn bindgen_test_layout_rte_eth_rxmode() { assert_eq!( ::std::mem::size_of::(), 12usize, - concat!("Size of: ", stringify!(rte_eth_rxmode)), + "Size of rte_eth_rxmode", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_rxmode)), + "Alignment of rte_eth_rxmode", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mq_mode) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rxmode), - "::", - stringify!(mq_mode), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_rxmode), - "::", - stringify!(max_rx_pkt_len), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_rxmode), - "::", - stringify!(split_hdr_size), - ), + "Offset of field: rte_eth_rxmode::split_hdr_size", ); } impl Clone for rte_eth_rxmode { @@ -495,27 +480,22 @@ fn bindgen_test_layout_rte_eth_txmode() { assert_eq!( ::std::mem::size_of::(), 8usize, - concat!("Size of: ", stringify!(rte_eth_txmode)), + "Size of rte_eth_txmode", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_txmode)), + "Alignment of rte_eth_txmode", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mq_mode) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_txmode), - "::", - stringify!(mq_mode), - ), + "Offset of field: rte_eth_txmode::mq_mode", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).pvid) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(rte_eth_txmode), "::", stringify!(pvid)), + "Offset of field: rte_eth_txmode::pvid", ); } impl Clone for rte_eth_txmode { @@ -641,42 +621,27 @@ fn bindgen_test_layout_rte_eth_rss_conf() { assert_eq!( ::std::mem::size_of::(), 24usize, - concat!("Size of: ", stringify!(rte_eth_rss_conf)), + "Size of rte_eth_rss_conf", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(rte_eth_rss_conf)), + "Alignment of rte_eth_rss_conf", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).rss_key) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_rss_conf), - "::", - stringify!(rss_key), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_rss_conf), - "::", - stringify!(rss_key_len), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_rss_conf), - "::", - stringify!(rss_hf), - ), + "Offset of field: rte_eth_rss_conf::rss_hf", ); } impl Clone for rte_eth_rss_conf { @@ -756,32 +721,22 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf__bindgen_ty_1() { assert_eq!( ::std::mem::size_of::(), 16usize, - concat!("Size of: ", stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1)), + "Size of rte_eth_vmdq_dcb_conf__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1)), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1), - "::", - stringify!(vlan_id), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf__bindgen_ty_1), - "::", - stringify!(pools), - ), + "Offset of field: rte_eth_vmdq_dcb_conf__bindgen_ty_1::pools", ); } impl Clone for rte_eth_vmdq_dcb_conf__bindgen_ty_1 { @@ -796,74 +751,44 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_conf() { assert_eq!( ::std::mem::size_of::(), 1040usize, - concat!("Size of: ", stringify!(rte_eth_vmdq_dcb_conf)), + "Size of rte_eth_vmdq_dcb_conf", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(rte_eth_vmdq_dcb_conf)), + "Alignment of rte_eth_vmdq_dcb_conf", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(nb_queue_pools), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(enable_default_pool), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(default_pool), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(nb_pool_maps), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(pool_map), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_conf), - "::", - stringify!(dcb_tc), - ), + "Offset of field: rte_eth_vmdq_dcb_conf::dcb_tc", ); } impl Clone for rte_eth_vmdq_dcb_conf { @@ -895,32 +820,22 @@ fn bindgen_test_layout_rte_eth_dcb_rx_conf() { assert_eq!( ::std::mem::size_of::(), 12usize, - concat!("Size of: ", stringify!(rte_eth_dcb_rx_conf)), + "Size of rte_eth_dcb_rx_conf", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_dcb_rx_conf)), + "Alignment of rte_eth_dcb_rx_conf", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_dcb_rx_conf), - "::", - stringify!(nb_tcs), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_dcb_rx_conf), - "::", - stringify!(dcb_tc), - ), + "Offset of field: rte_eth_dcb_rx_conf::dcb_tc", ); } impl Clone for rte_eth_dcb_rx_conf { @@ -952,32 +867,22 @@ fn bindgen_test_layout_rte_eth_vmdq_dcb_tx_conf() { assert_eq!( ::std::mem::size_of::(), 12usize, - concat!("Size of: ", stringify!(rte_eth_vmdq_dcb_tx_conf)), + "Size of rte_eth_vmdq_dcb_tx_conf", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_vmdq_dcb_tx_conf)), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_tx_conf), - "::", - stringify!(nb_queue_pools), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_dcb_tx_conf), - "::", - stringify!(dcb_tc), - ), + "Offset of field: rte_eth_vmdq_dcb_tx_conf::dcb_tc", ); } impl Clone for rte_eth_vmdq_dcb_tx_conf { @@ -1009,32 +914,22 @@ fn bindgen_test_layout_rte_eth_dcb_tx_conf() { assert_eq!( ::std::mem::size_of::(), 12usize, - concat!("Size of: ", stringify!(rte_eth_dcb_tx_conf)), + "Size of rte_eth_dcb_tx_conf", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_dcb_tx_conf)), + "Alignment of rte_eth_dcb_tx_conf", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_dcb_tx_conf), - "::", - stringify!(nb_tcs), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_dcb_tx_conf), - "::", - stringify!(dcb_tc), - ), + "Offset of field: rte_eth_dcb_tx_conf::dcb_tc", ); } impl Clone for rte_eth_dcb_tx_conf { @@ -1064,22 +959,17 @@ fn bindgen_test_layout_rte_eth_vmdq_tx_conf() { assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(rte_eth_vmdq_tx_conf)), + "Size of rte_eth_vmdq_tx_conf", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_vmdq_tx_conf)), + "Alignment of rte_eth_vmdq_tx_conf", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_tx_conf), - "::", - stringify!(nb_queue_pools), - ), + "Offset of field: rte_eth_vmdq_tx_conf::nb_queue_pools", ); } impl Clone for rte_eth_vmdq_tx_conf { @@ -1129,32 +1019,22 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf__bindgen_ty_1() { assert_eq!( ::std::mem::size_of::(), 16usize, - concat!("Size of: ", stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1)), + "Size of rte_eth_vmdq_rx_conf__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1)), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1), - "::", - stringify!(vlan_id), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf__bindgen_ty_1), - "::", - stringify!(pools), - ), + "Offset of field: rte_eth_vmdq_rx_conf__bindgen_ty_1::pools", ); } impl Clone for rte_eth_vmdq_rx_conf__bindgen_ty_1 { @@ -1169,84 +1049,49 @@ fn bindgen_test_layout_rte_eth_vmdq_rx_conf() { assert_eq!( ::std::mem::size_of::(), 1040usize, - concat!("Size of: ", stringify!(rte_eth_vmdq_rx_conf)), + "Size of rte_eth_vmdq_rx_conf", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(rte_eth_vmdq_rx_conf)), + "Alignment of rte_eth_vmdq_rx_conf", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(nb_queue_pools), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(enable_default_pool), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(default_pool), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(enable_loop_back), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(nb_pool_maps), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(rx_mode), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_vmdq_rx_conf), - "::", - stringify!(pool_map), - ), + "Offset of field: rte_eth_vmdq_rx_conf::pool_map", ); } impl Clone for rte_eth_vmdq_rx_conf { @@ -1323,62 +1168,37 @@ fn bindgen_test_layout_rte_eth_ipv4_flow() { assert_eq!( ::std::mem::size_of::(), 12usize, - concat!("Size of: ", stringify!(rte_eth_ipv4_flow)), + "Size of rte_eth_ipv4_flow", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_ipv4_flow)), + "Alignment of rte_eth_ipv4_flow", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(src_ip), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(dst_ip), - ), + "Offset of field: rte_eth_ipv4_flow::dst_ip", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).tos) as usize - ptr as usize }, 8usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(tos), - ), + "Offset of field: rte_eth_ipv4_flow::tos", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).ttl) as usize - ptr as usize }, 9usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(ttl), - ), + "Offset of field: rte_eth_ipv4_flow::ttl", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize }, 10usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv4_flow), - "::", - stringify!(proto), - ), + "Offset of field: rte_eth_ipv4_flow::proto", ); } impl Clone for rte_eth_ipv4_flow { @@ -1408,57 +1228,37 @@ fn bindgen_test_layout_rte_eth_ipv6_flow() { assert_eq!( ::std::mem::size_of::(), 36usize, - concat!("Size of: ", stringify!(rte_eth_ipv6_flow)), + "Size of rte_eth_ipv6_flow", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_ipv6_flow)), + "Alignment of rte_eth_ipv6_flow", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(src_ip), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(dst_ip), - ), + "Offset of field: rte_eth_ipv6_flow::dst_ip", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).tc) as usize - ptr as usize }, 32usize, - concat!("Offset of field: ", stringify!(rte_eth_ipv6_flow), "::", stringify!(tc)), + "Offset of field: rte_eth_ipv6_flow::tc", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize }, 33usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(proto), - ), + "Offset of field: rte_eth_ipv6_flow::proto", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).hop_limits) as usize - ptr as usize }, 34usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_ipv6_flow), - "::", - stringify!(hop_limits), - ), + "Offset of field: rte_eth_ipv6_flow::hop_limits", ); } impl Clone for rte_eth_ipv6_flow { @@ -1497,94 +1297,54 @@ fn bindgen_test_layout_rte_eth_fdir_masks() { assert_eq!( ::std::mem::size_of::(), 68usize, - concat!("Size of: ", stringify!(rte_eth_fdir_masks)), + "Size of rte_eth_fdir_masks", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_fdir_masks)), + "Alignment of rte_eth_fdir_masks", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).vlan_tci_mask) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(vlan_tci_mask), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(ipv4_mask), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(ipv6_mask), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(src_port_mask), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(dst_port_mask), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(mac_addr_byte_mask), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(tunnel_id_mask), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_masks), - "::", - stringify!(tunnel_type_mask), - ), + "Offset of field: rte_eth_fdir_masks::tunnel_type_mask", ); } impl Clone for rte_eth_fdir_masks { @@ -1619,32 +1379,22 @@ fn bindgen_test_layout_rte_eth_flex_payload_cfg() { assert_eq!( ::std::mem::size_of::(), 36usize, - concat!("Size of: ", stringify!(rte_eth_flex_payload_cfg)), + "Size of rte_eth_flex_payload_cfg", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_flex_payload_cfg)), + "Alignment of rte_eth_flex_payload_cfg", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_flex_payload_cfg), - "::", - stringify!(type_), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_flex_payload_cfg), - "::", - stringify!(src_offset), - ), + "Offset of field: rte_eth_flex_payload_cfg::src_offset", ); } impl Clone for rte_eth_flex_payload_cfg { @@ -1676,32 +1426,22 @@ fn bindgen_test_layout_rte_eth_fdir_flex_mask() { assert_eq!( ::std::mem::size_of::(), 18usize, - concat!("Size of: ", stringify!(rte_eth_fdir_flex_mask)), + "Size of rte_eth_fdir_flex_mask", ); assert_eq!( ::std::mem::align_of::(), 2usize, - concat!("Alignment of ", stringify!(rte_eth_fdir_flex_mask)), + "Alignment of rte_eth_fdir_flex_mask", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).flow_type) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_mask), - "::", - stringify!(flow_type), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_mask), - "::", - stringify!(mask), - ), + "Offset of field: rte_eth_fdir_flex_mask::mask", ); } impl Clone for rte_eth_fdir_flex_mask { @@ -1728,52 +1468,32 @@ fn bindgen_test_layout_rte_eth_fdir_flex_conf() { assert_eq!( ::std::mem::size_of::(), 688usize, - concat!("Size of: ", stringify!(rte_eth_fdir_flex_conf)), + "Size of rte_eth_fdir_flex_conf", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_fdir_flex_conf)), + "Alignment of rte_eth_fdir_flex_conf", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).nb_payloads) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_conf), - "::", - stringify!(nb_payloads), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_conf), - "::", - stringify!(nb_flexmasks), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_conf), - "::", - stringify!(flex_set), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_fdir_flex_conf), - "::", - stringify!(flex_mask), - ), + "Offset of field: rte_eth_fdir_flex_conf::flex_mask", ); } impl Clone for rte_eth_fdir_flex_conf { @@ -1815,57 +1535,42 @@ fn bindgen_test_layout_rte_fdir_conf() { assert_eq!( ::std::mem::size_of::(), 772usize, - concat!("Size of: ", stringify!(rte_fdir_conf)), + "Size of rte_fdir_conf", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_fdir_conf)), + "Alignment of rte_fdir_conf", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mode) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_fdir_conf), "::", stringify!(mode)), + "Offset of field: rte_fdir_conf::mode", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).pballoc) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(pballoc), - ), + "Offset of field: rte_fdir_conf::pballoc", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).status) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(rte_fdir_conf), "::", stringify!(status)), + "Offset of field: rte_fdir_conf::status", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).drop_queue) as usize - ptr as usize }, 12usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(drop_queue), - ), + "Offset of field: rte_fdir_conf::drop_queue", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize }, 16usize, - concat!("Offset of field: ", stringify!(rte_fdir_conf), "::", stringify!(mask)), + "Offset of field: rte_fdir_conf::mask", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).flex_conf) as usize - ptr as usize }, 84usize, - concat!( - "Offset of field: ", - stringify!(rte_fdir_conf), - "::", - stringify!(flex_conf), - ), + "Offset of field: rte_fdir_conf::flex_conf", ); } impl Clone for rte_fdir_conf { @@ -1895,25 +1600,21 @@ pub struct rte_intr_conf { 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, - concat!("Size of: ", stringify!(rte_intr_conf)), - ); + assert_eq!(::std::mem::size_of::(), 4usize, "Size of rte_intr_conf"); assert_eq!( ::std::mem::align_of::(), 2usize, - concat!("Alignment of ", stringify!(rte_intr_conf)), + "Alignment of rte_intr_conf", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).lsc) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_intr_conf), "::", stringify!(lsc)), + "Offset of field: rte_intr_conf::lsc", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).rxq) as usize - ptr as usize }, 2usize, - concat!("Offset of field: ", stringify!(rte_intr_conf), "::", stringify!(rxq)), + "Offset of field: rte_intr_conf::rxq", ); } impl Clone for rte_intr_conf { @@ -1973,52 +1674,32 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_1() { assert_eq!( ::std::mem::size_of::(), 2120usize, - concat!("Size of: ", stringify!(rte_eth_conf__bindgen_ty_1)), + "Size of rte_eth_conf__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(rte_eth_conf__bindgen_ty_1)), + "Alignment of rte_eth_conf__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).rss_conf) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_1), - "::", - stringify!(rss_conf), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_1), - "::", - stringify!(vmdq_dcb_conf), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_1), - "::", - stringify!(dcb_rx_conf), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_1), - "::", - stringify!(vmdq_rx_conf), - ), + "Offset of field: rte_eth_conf__bindgen_ty_1::vmdq_rx_conf", ); } impl Clone for rte_eth_conf__bindgen_ty_1 { @@ -2050,42 +1731,27 @@ fn bindgen_test_layout_rte_eth_conf__bindgen_ty_2() { assert_eq!( ::std::mem::size_of::(), 12usize, - concat!("Size of: ", stringify!(rte_eth_conf__bindgen_ty_2)), + "Size of rte_eth_conf__bindgen_ty_2", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_eth_conf__bindgen_ty_2)), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_2), - "::", - stringify!(vmdq_dcb_tx_conf), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_2), - "::", - stringify!(dcb_tx_conf), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf__bindgen_ty_2), - "::", - stringify!(vmdq_tx_conf), - ), + "Offset of field: rte_eth_conf__bindgen_ty_2::vmdq_tx_conf", ); } impl Clone for rte_eth_conf__bindgen_ty_2 { @@ -2097,97 +1763,58 @@ impl Clone for rte_eth_conf__bindgen_ty_2 { 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, - concat!("Size of: ", stringify!(rte_eth_conf)), - ); + assert_eq!(::std::mem::size_of::(), 2944usize, "Size of rte_eth_conf"); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(rte_eth_conf)), + "Alignment of rte_eth_conf", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).link_speeds) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(link_speeds), - ), + "Offset of field: rte_eth_conf::link_speeds", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).rxmode) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(rte_eth_conf), "::", stringify!(rxmode)), + "Offset of field: rte_eth_conf::rxmode", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).txmode) as usize - ptr as usize }, 16usize, - concat!("Offset of field: ", stringify!(rte_eth_conf), "::", stringify!(txmode)), + "Offset of field: rte_eth_conf::txmode", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).lpbk_mode) as usize - ptr as usize }, 24usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(lpbk_mode), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(rx_adv_conf), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(tx_adv_conf), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(dcb_capability_en), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(fdir_conf), - ), + "Offset of field: rte_eth_conf::fdir_conf", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).intr_conf) as usize - ptr as usize }, 2940usize, - concat!( - "Offset of field: ", - stringify!(rte_eth_conf), - "::", - stringify!(intr_conf), - ), + "Offset of field: rte_eth_conf::intr_conf", ); } impl Clone for rte_eth_conf { diff --git a/bindgen-tests/tests/expectations/tests/layout_kni_mbuf.rs b/bindgen-tests/tests/expectations/tests/layout_kni_mbuf.rs index 258ac0d3dc..a9d779e9a1 100644 --- a/bindgen-tests/tests/expectations/tests/layout_kni_mbuf.rs +++ b/bindgen-tests/tests/expectations/tests/layout_kni_mbuf.rs @@ -30,110 +30,81 @@ pub struct rte_kni_mbuf { 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, - concat!("Size of: ", stringify!(rte_kni_mbuf)), - ); + assert_eq!(::std::mem::size_of::(), 128usize, "Size of rte_kni_mbuf"); assert_eq!( ::std::mem::align_of::(), 64usize, - concat!("Alignment of ", stringify!(rte_kni_mbuf)), + "Alignment of rte_kni_mbuf", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).buf_addr) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(buf_addr), - ), + "Offset of field: rte_kni_mbuf::buf_addr", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).buf_physaddr) as usize - ptr as usize }, 8usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(buf_physaddr), - ), + "Offset of field: rte_kni_mbuf::buf_physaddr", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).pad0) as usize - ptr as usize }, 16usize, - concat!("Offset of field: ", stringify!(rte_kni_mbuf), "::", stringify!(pad0)), + "Offset of field: rte_kni_mbuf::pad0", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).data_off) as usize - ptr as usize }, 18usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(data_off), - ), + "Offset of field: rte_kni_mbuf::data_off", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).pad1) as usize - ptr as usize }, 20usize, - concat!("Offset of field: ", stringify!(rte_kni_mbuf), "::", stringify!(pad1)), + "Offset of field: rte_kni_mbuf::pad1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).nb_segs) as usize - ptr as usize }, 22usize, - concat!("Offset of field: ", stringify!(rte_kni_mbuf), "::", stringify!(nb_segs)), + "Offset of field: rte_kni_mbuf::nb_segs", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).pad4) as usize - ptr as usize }, 23usize, - concat!("Offset of field: ", stringify!(rte_kni_mbuf), "::", stringify!(pad4)), + "Offset of field: rte_kni_mbuf::pad4", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).ol_flags) as usize - ptr as usize }, 24usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(ol_flags), - ), + "Offset of field: rte_kni_mbuf::ol_flags", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).pad2) as usize - ptr as usize }, 32usize, - concat!("Offset of field: ", stringify!(rte_kni_mbuf), "::", stringify!(pad2)), + "Offset of field: rte_kni_mbuf::pad2", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).pkt_len) as usize - ptr as usize }, 36usize, - concat!("Offset of field: ", stringify!(rte_kni_mbuf), "::", stringify!(pkt_len)), + "Offset of field: rte_kni_mbuf::pkt_len", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).data_len) as usize - ptr as usize }, 40usize, - concat!( - "Offset of field: ", - stringify!(rte_kni_mbuf), - "::", - stringify!(data_len), - ), + "Offset of field: rte_kni_mbuf::data_len", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).pad3) as usize - ptr as usize }, 64usize, - concat!("Offset of field: ", stringify!(rte_kni_mbuf), "::", stringify!(pad3)), + "Offset of field: rte_kni_mbuf::pad3", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).pool) as usize - ptr as usize }, 72usize, - concat!("Offset of field: ", stringify!(rte_kni_mbuf), "::", stringify!(pool)), + "Offset of field: rte_kni_mbuf::pool", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize }, 80usize, - concat!("Offset of field: ", stringify!(rte_kni_mbuf), "::", stringify!(next)), + "Offset of field: rte_kni_mbuf::next", ); } impl Default for rte_kni_mbuf { 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 05a9784356..b72c221dca 100644 --- a/bindgen-tests/tests/expectations/tests/layout_large_align_field.rs +++ b/bindgen-tests/tests/expectations/tests/layout_large_align_field.rs @@ -61,30 +61,22 @@ pub struct ip_frag { 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, - concat!("Size of: ", stringify!(ip_frag)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(ip_frag)), - ); + 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, - concat!("Offset of field: ", stringify!(ip_frag), "::", stringify!(ofs)), + "Offset of field: ip_frag::ofs", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize }, 2usize, - concat!("Offset of field: ", stringify!(ip_frag), "::", stringify!(len)), + "Offset of field: ip_frag::len", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mb) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(ip_frag), "::", stringify!(mb)), + "Offset of field: ip_frag::mb", ); } impl Default for ip_frag { @@ -111,30 +103,26 @@ pub struct ip_frag_key { 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, - concat!("Size of: ", stringify!(ip_frag_key)), - ); + assert_eq!(::std::mem::size_of::(), 40usize, "Size of ip_frag_key"); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(ip_frag_key)), + "Alignment of ip_frag_key", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).src_dst) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(ip_frag_key), "::", stringify!(src_dst)), + "Offset of field: ip_frag_key::src_dst", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).id) as usize - ptr as usize }, 32usize, - concat!("Offset of field: ", stringify!(ip_frag_key), "::", stringify!(id)), + "Offset of field: ip_frag_key::id", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).key_len) as usize - ptr as usize }, 36usize, - concat!("Offset of field: ", stringify!(ip_frag_key), "::", stringify!(key_len)), + "Offset of field: ip_frag_key::key_len", ); } /** @internal Fragmented packet to reassemble. @@ -171,32 +159,22 @@ fn bindgen_test_layout_ip_frag_pkt__bindgen_ty_1() { assert_eq!( ::std::mem::size_of::(), 16usize, - concat!("Size of: ", stringify!(ip_frag_pkt__bindgen_ty_1)), + "Size of ip_frag_pkt__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(ip_frag_pkt__bindgen_ty_1)), + "Alignment of ip_frag_pkt__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).tqe_next) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt__bindgen_ty_1), - "::", - stringify!(tqe_next), - ), + "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, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt__bindgen_ty_1), - "::", - stringify!(tqe_prev), - ), + "Offset of field: ip_frag_pkt__bindgen_ty_1::tqe_prev", ); } impl Default for ip_frag_pkt__bindgen_ty_1 { @@ -212,60 +190,46 @@ impl Default for ip_frag_pkt__bindgen_ty_1 { 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, - concat!("Size of: ", stringify!(ip_frag_pkt)), - ); + assert_eq!(::std::mem::size_of::(), 192usize, "Size of ip_frag_pkt"); assert_eq!( ::std::mem::align_of::(), 64usize, - concat!("Alignment of ", stringify!(ip_frag_pkt)), + "Alignment of ip_frag_pkt", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).lru) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", stringify!(lru)), + "Offset of field: ip_frag_pkt::lru", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).key) as usize - ptr as usize }, 16usize, - concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", stringify!(key)), + "Offset of field: ip_frag_pkt::key", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).start) as usize - ptr as usize }, 56usize, - concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", stringify!(start)), + "Offset of field: ip_frag_pkt::start", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).total_size) as usize - ptr as usize }, 64usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(total_size), - ), + "Offset of field: ip_frag_pkt::total_size", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).frag_size) as usize - ptr as usize }, 68usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_pkt), - "::", - stringify!(frag_size), - ), + "Offset of field: ip_frag_pkt::frag_size", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).last_idx) as usize - ptr as usize }, 72usize, - concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", stringify!(last_idx)), + "Offset of field: ip_frag_pkt::last_idx", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).frags) as usize - ptr as usize }, 80usize, - concat!("Offset of field: ", stringify!(ip_frag_pkt), "::", stringify!(frags)), + "Offset of field: ip_frag_pkt::frags", ); } impl Default for ip_frag_pkt { @@ -287,30 +251,21 @@ pub struct ip_pkt_list { 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, - concat!("Size of: ", stringify!(ip_pkt_list)), - ); + assert_eq!(::std::mem::size_of::(), 16usize, "Size of ip_pkt_list"); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(ip_pkt_list)), + "Alignment of ip_pkt_list", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).tqh_first) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(ip_pkt_list), - "::", - stringify!(tqh_first), - ), + "Offset of field: ip_pkt_list::tqh_first", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).tqh_last) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(ip_pkt_list), "::", stringify!(tqh_last)), + "Offset of field: ip_pkt_list::tqh_last", ); } impl Default for ip_pkt_list { @@ -347,72 +302,42 @@ fn bindgen_test_layout_ip_frag_tbl_stat() { assert_eq!( ::std::mem::size_of::(), 64usize, - concat!("Size of: ", stringify!(ip_frag_tbl_stat)), + "Size of ip_frag_tbl_stat", ); assert_eq!( ::std::mem::align_of::(), 64usize, - concat!("Alignment of ", stringify!(ip_frag_tbl_stat)), + "Alignment of ip_frag_tbl_stat", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).find_num) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(ip_frag_tbl_stat), - "::", - stringify!(find_num), - ), + "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, - concat!( - "Offset of field: ", - stringify!(ip_frag_tbl_stat), - "::", - stringify!(add_num), - ), + "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, - concat!( - "Offset of field: ", - stringify!(ip_frag_tbl_stat), - "::", - stringify!(del_num), - ), + "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, - concat!( - "Offset of field: ", - stringify!(ip_frag_tbl_stat), - "::", - stringify!(reuse_num), - ), + "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, - concat!( - "Offset of field: ", - stringify!(ip_frag_tbl_stat), - "::", - stringify!(fail_total), - ), + "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, - concat!( - "Offset of field: ", - stringify!(ip_frag_tbl_stat), - "::", - stringify!(fail_nospace), - ), + "Offset of field: ip_frag_tbl_stat::fail_nospace", ); } impl Default for ip_frag_tbl_stat { @@ -459,102 +384,67 @@ fn bindgen_test_layout_rte_ip_frag_tbl() { assert_eq!( ::std::mem::size_of::(), 128usize, - concat!("Size of: ", stringify!(rte_ip_frag_tbl)), + "Size of rte_ip_frag_tbl", ); assert_eq!( ::std::mem::align_of::(), 64usize, - concat!("Alignment of ", stringify!(rte_ip_frag_tbl)), + "Alignment of rte_ip_frag_tbl", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).max_cycles) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(max_cycles), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(entry_mask), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(max_entries), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(use_entries), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(bucket_entries), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(nb_entries), - ), + "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, - concat!( - "Offset of field: ", - stringify!(rte_ip_frag_tbl), - "::", - stringify!(nb_buckets), - ), + "Offset of field: rte_ip_frag_tbl::nb_buckets", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).last) as usize - ptr as usize }, 32usize, - concat!("Offset of field: ", stringify!(rte_ip_frag_tbl), "::", stringify!(last)), + "Offset of field: rte_ip_frag_tbl::last", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).lru) as usize - ptr as usize }, 40usize, - concat!("Offset of field: ", stringify!(rte_ip_frag_tbl), "::", stringify!(lru)), + "Offset of field: rte_ip_frag_tbl::lru", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).stat) as usize - ptr as usize }, 64usize, - concat!("Offset of field: ", stringify!(rte_ip_frag_tbl), "::", stringify!(stat)), + "Offset of field: rte_ip_frag_tbl::stat", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).pkt) as usize - ptr as usize }, 128usize, - concat!("Offset of field: ", stringify!(rte_ip_frag_tbl), "::", stringify!(pkt)), + "Offset of field: rte_ip_frag_tbl::pkt", ); } impl Default for rte_ip_frag_tbl { diff --git a/bindgen-tests/tests/expectations/tests/layout_mbuf.rs b/bindgen-tests/tests/expectations/tests/layout_mbuf.rs index a04f0274d1..c512ad33a2 100644 --- a/bindgen-tests/tests/expectations/tests/layout_mbuf.rs +++ b/bindgen-tests/tests/expectations/tests/layout_mbuf.rs @@ -96,26 +96,13 @@ pub struct rte_atomic16_t { ///< An internal counter value. pub cnt: i16, } -#[test] -fn bindgen_test_layout_rte_atomic16_t() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 2usize, - concat!("Size of: ", stringify!(rte_atomic16_t)), - ); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(rte_atomic16_t)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).cnt) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(rte_atomic16_t), "::", stringify!(cnt)), - ); -} +const _: () = { + ["Size of rte_atomic16_t"][::std::mem::size_of::() - 2usize]; + ["Alignment of rte_atomic16_t"][::std::mem::align_of::() - 2usize]; + [ + "Offset of field: rte_atomic16_t::cnt", + ][::std::mem::offset_of!(rte_atomic16_t, cnt) - 0usize]; +}; /// The generic rte_mbuf, containing a packet mbuf. #[repr(C)] #[repr(align(64))] @@ -177,41 +164,20 @@ pub union rte_mbuf__bindgen_ty_1 { ///< Non-atomically accessed refcnt pub refcnt: u16, } -#[test] -fn bindgen_test_layout_rte_mbuf__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 2usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_1)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).refcnt_atomic) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_1), - "::", - stringify!(refcnt_atomic), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).refcnt) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_1), - "::", - stringify!(refcnt), - ), - ); -} +const _: () = { + [ + "Size of rte_mbuf__bindgen_ty_1", + ][::std::mem::size_of::() - 2usize]; + [ + "Alignment of rte_mbuf__bindgen_ty_1", + ][::std::mem::align_of::() - 2usize]; + [ + "Offset of field: rte_mbuf__bindgen_ty_1::refcnt_atomic", + ][::std::mem::offset_of!(rte_mbuf__bindgen_ty_1, refcnt_atomic) - 0usize]; + [ + "Offset of field: rte_mbuf__bindgen_ty_1::refcnt", + ][::std::mem::offset_of!(rte_mbuf__bindgen_ty_1, refcnt) - 0usize]; +}; impl Default for rte_mbuf__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -235,19 +201,14 @@ pub struct rte_mbuf__bindgen_ty_2__bindgen_ty_1 { pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, } -#[test] -fn bindgen_test_layout_rte_mbuf__bindgen_ty_2__bindgen_ty_1() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_2__bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_2__bindgen_ty_1)), - ); -} +const _: () = { + [ + "Size of rte_mbuf__bindgen_ty_2__bindgen_ty_1", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of rte_mbuf__bindgen_ty_2__bindgen_ty_1", + ][::std::mem::align_of::() - 4usize]; +}; impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { #[inline] pub fn l2_type(&self) -> u32 { @@ -409,31 +370,17 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { __bindgen_bitfield_unit } } -#[test] -fn bindgen_test_layout_rte_mbuf__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_2)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_2)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).packet_type) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_2), - "::", - stringify!(packet_type), - ), - ); -} +const _: () = { + [ + "Size of rte_mbuf__bindgen_ty_2", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of rte_mbuf__bindgen_ty_2", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: rte_mbuf__bindgen_ty_2::packet_type", + ][::std::mem::offset_of!(rte_mbuf__bindgen_ty_2, packet_type) - 0usize]; +}; impl Default for rte_mbuf__bindgen_ty_2 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -473,86 +420,42 @@ pub struct rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 { pub hash: u16, pub id: u16, } -#[test] -fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit< +const _: () = { + [ + "Size of rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1", + ][::std::mem::size_of::< rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1, - > = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::< - rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1, - >(), - 4usize, - concat!( - "Size of: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1), - ), - ); - assert_eq!( - ::std::mem::align_of::< - rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1, - >(), - 2usize, - concat!( - "Alignment of ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).hash) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(hash), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).id) as usize - ptr as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(id), - ), - ); -} -#[test] -fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit< - rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1, - > = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!( - "Size of: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1), - ), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!( - "Alignment of ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).lo) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(lo), - ), - ); -} + >() - 4usize]; + [ + "Alignment of rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1", + ][::std::mem::align_of::< + rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1, + >() - 2usize]; + [ + "Offset of field: rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1::hash", + ][::std::mem::offset_of!( + rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1, hash + ) - 0usize]; + [ + "Offset of field: rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1::id", + ][::std::mem::offset_of!( + rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1, id + ) - 2usize]; +}; +const _: () = { + [ + "Size of rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1", + ][::std::mem::size_of::() + - 4usize]; + [ + "Alignment of rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1", + ][::std::mem::align_of::() + - 4usize]; + [ + "Offset of field: rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1::lo", + ][::std::mem::offset_of!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1, lo) + - 0usize]; +}; impl Default for rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -562,31 +465,17 @@ impl Default for rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 { } } } -#[test] -fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).hi) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1), - "::", - stringify!(hi), - ), - ); -} +const _: () = { + [ + "Size of rte_mbuf__bindgen_ty_3__bindgen_ty_1", + ][::std::mem::size_of::() - 8usize]; + [ + "Alignment of rte_mbuf__bindgen_ty_3__bindgen_ty_1", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: rte_mbuf__bindgen_ty_3__bindgen_ty_1::hi", + ][::std::mem::offset_of!(rte_mbuf__bindgen_ty_3__bindgen_ty_1, hi) - 4usize]; +}; impl Default for rte_mbuf__bindgen_ty_3__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -602,96 +491,40 @@ pub struct rte_mbuf__bindgen_ty_3__bindgen_ty_2 { pub lo: u32, pub hi: u32, } -#[test] -fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).lo) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2), - "::", - stringify!(lo), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).hi) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2), - "::", - stringify!(hi), - ), - ); -} -#[test] -fn bindgen_test_layout_rte_mbuf__bindgen_ty_3() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_3)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_3)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).rss) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(rss), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).fdir) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(fdir), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).sched) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(sched), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).usr) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(usr), - ), - ); -} +const _: () = { + [ + "Size of rte_mbuf__bindgen_ty_3__bindgen_ty_2", + ][::std::mem::size_of::() - 8usize]; + [ + "Alignment of rte_mbuf__bindgen_ty_3__bindgen_ty_2", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: rte_mbuf__bindgen_ty_3__bindgen_ty_2::lo", + ][::std::mem::offset_of!(rte_mbuf__bindgen_ty_3__bindgen_ty_2, lo) - 0usize]; + [ + "Offset of field: rte_mbuf__bindgen_ty_3__bindgen_ty_2::hi", + ][::std::mem::offset_of!(rte_mbuf__bindgen_ty_3__bindgen_ty_2, hi) - 4usize]; +}; +const _: () = { + [ + "Size of rte_mbuf__bindgen_ty_3", + ][::std::mem::size_of::() - 8usize]; + [ + "Alignment of rte_mbuf__bindgen_ty_3", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: rte_mbuf__bindgen_ty_3::rss", + ][::std::mem::offset_of!(rte_mbuf__bindgen_ty_3, rss) - 0usize]; + [ + "Offset of field: rte_mbuf__bindgen_ty_3::fdir", + ][::std::mem::offset_of!(rte_mbuf__bindgen_ty_3, fdir) - 0usize]; + [ + "Offset of field: rte_mbuf__bindgen_ty_3::sched", + ][::std::mem::offset_of!(rte_mbuf__bindgen_ty_3, sched) - 0usize]; + [ + "Offset of field: rte_mbuf__bindgen_ty_3::usr", + ][::std::mem::offset_of!(rte_mbuf__bindgen_ty_3, usr) - 0usize]; +}; impl Default for rte_mbuf__bindgen_ty_3 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -709,41 +542,20 @@ pub union rte_mbuf__bindgen_ty_4 { ///< Allow 8-byte userdata on 32-bit pub udata64: u64, } -#[test] -fn bindgen_test_layout_rte_mbuf__bindgen_ty_4() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_4)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_4)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).userdata) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_4), - "::", - stringify!(userdata), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).udata64) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_4), - "::", - stringify!(udata64), - ), - ); -} +const _: () = { + [ + "Size of rte_mbuf__bindgen_ty_4", + ][::std::mem::size_of::() - 8usize]; + [ + "Alignment of rte_mbuf__bindgen_ty_4", + ][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: rte_mbuf__bindgen_ty_4::userdata", + ][::std::mem::offset_of!(rte_mbuf__bindgen_ty_4, userdata) - 0usize]; + [ + "Offset of field: rte_mbuf__bindgen_ty_4::udata64", + ][::std::mem::offset_of!(rte_mbuf__bindgen_ty_4, udata64) - 0usize]; +}; impl Default for rte_mbuf__bindgen_ty_4 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -767,19 +579,14 @@ pub struct rte_mbuf__bindgen_ty_5__bindgen_ty_1 { pub _bitfield_align_1: [u16; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 7usize]>, } -#[test] -fn bindgen_test_layout_rte_mbuf__bindgen_ty_5__bindgen_ty_1() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_5__bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_5__bindgen_ty_1)), - ); -} +const _: () = { + [ + "Size of rte_mbuf__bindgen_ty_5__bindgen_ty_1", + ][::std::mem::size_of::() - 8usize]; + [ + "Alignment of rte_mbuf__bindgen_ty_5__bindgen_ty_1", + ][::std::mem::align_of::() - 8usize]; +}; impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { #[inline] pub fn l2_len(&self) -> u64 { @@ -918,31 +725,17 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { __bindgen_bitfield_unit } } -#[test] -fn bindgen_test_layout_rte_mbuf__bindgen_ty_5() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_5)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_5)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).tx_offload) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_5), - "::", - stringify!(tx_offload), - ), - ); -} +const _: () = { + [ + "Size of rte_mbuf__bindgen_ty_5", + ][::std::mem::size_of::() - 8usize]; + [ + "Alignment of rte_mbuf__bindgen_ty_5", + ][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: rte_mbuf__bindgen_ty_5::tx_offload", + ][::std::mem::offset_of!(rte_mbuf__bindgen_ty_5, tx_offload) - 0usize]; +}; impl Default for rte_mbuf__bindgen_ty_5 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -952,143 +745,73 @@ impl Default for rte_mbuf__bindgen_ty_5 { } } } -#[test] -fn bindgen_test_layout_rte_mbuf() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 128usize, - concat!("Size of: ", stringify!(rte_mbuf)), - ); - assert_eq!( - ::std::mem::align_of::(), - 64usize, - concat!("Alignment of ", stringify!(rte_mbuf)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).cacheline0) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(cacheline0)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).buf_addr) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(buf_addr)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).buf_physaddr) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(buf_physaddr), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).buf_len) as usize - ptr as usize }, - 16usize, - concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(buf_len)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).rearm_data) as usize - ptr as usize }, - 18usize, - concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(rearm_data)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).data_off) as usize - ptr as usize }, - 18usize, - concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(data_off)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).nb_segs) as usize - ptr as usize }, - 22usize, - concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(nb_segs)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).port) as usize - ptr as usize }, - 23usize, - concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(port)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ol_flags) as usize - ptr as usize }, - 24usize, - concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(ol_flags)), - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).rx_descriptor_fields1) as usize - ptr as usize - }, - 32usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(rx_descriptor_fields1), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).pkt_len) as usize - ptr as usize }, - 36usize, - concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(pkt_len)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).data_len) as usize - ptr as usize }, - 40usize, - concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(data_len)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).vlan_tci) as usize - ptr as usize }, - 42usize, - concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(vlan_tci)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).hash) as usize - ptr as usize }, - 44usize, - concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(hash)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).seqn) as usize - ptr as usize }, - 52usize, - concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(seqn)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).vlan_tci_outer) as usize - ptr as usize }, - 56usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(vlan_tci_outer), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).cacheline1) as usize - ptr as usize }, - 64usize, - concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(cacheline1)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).pool) as usize - ptr as usize }, - 72usize, - concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(pool)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize }, - 80usize, - concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(next)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).priv_size) as usize - ptr as usize }, - 96usize, - concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(priv_size)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).timesync) as usize - ptr as usize }, - 98usize, - concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(timesync)), - ); -} +const _: () = { + ["Size of rte_mbuf"][::std::mem::size_of::() - 128usize]; + ["Alignment of rte_mbuf"][::std::mem::align_of::() - 64usize]; + [ + "Offset of field: rte_mbuf::cacheline0", + ][::std::mem::offset_of!(rte_mbuf, cacheline0) - 0usize]; + [ + "Offset of field: rte_mbuf::buf_addr", + ][::std::mem::offset_of!(rte_mbuf, buf_addr) - 0usize]; + [ + "Offset of field: rte_mbuf::buf_physaddr", + ][::std::mem::offset_of!(rte_mbuf, buf_physaddr) - 8usize]; + [ + "Offset of field: rte_mbuf::buf_len", + ][::std::mem::offset_of!(rte_mbuf, buf_len) - 16usize]; + [ + "Offset of field: rte_mbuf::rearm_data", + ][::std::mem::offset_of!(rte_mbuf, rearm_data) - 18usize]; + [ + "Offset of field: rte_mbuf::data_off", + ][::std::mem::offset_of!(rte_mbuf, data_off) - 18usize]; + [ + "Offset of field: rte_mbuf::nb_segs", + ][::std::mem::offset_of!(rte_mbuf, nb_segs) - 22usize]; + [ + "Offset of field: rte_mbuf::port", + ][::std::mem::offset_of!(rte_mbuf, port) - 23usize]; + [ + "Offset of field: rte_mbuf::ol_flags", + ][::std::mem::offset_of!(rte_mbuf, ol_flags) - 24usize]; + [ + "Offset of field: rte_mbuf::rx_descriptor_fields1", + ][::std::mem::offset_of!(rte_mbuf, rx_descriptor_fields1) - 32usize]; + [ + "Offset of field: rte_mbuf::pkt_len", + ][::std::mem::offset_of!(rte_mbuf, pkt_len) - 36usize]; + [ + "Offset of field: rte_mbuf::data_len", + ][::std::mem::offset_of!(rte_mbuf, data_len) - 40usize]; + [ + "Offset of field: rte_mbuf::vlan_tci", + ][::std::mem::offset_of!(rte_mbuf, vlan_tci) - 42usize]; + [ + "Offset of field: rte_mbuf::hash", + ][::std::mem::offset_of!(rte_mbuf, hash) - 44usize]; + [ + "Offset of field: rte_mbuf::seqn", + ][::std::mem::offset_of!(rte_mbuf, seqn) - 52usize]; + [ + "Offset of field: rte_mbuf::vlan_tci_outer", + ][::std::mem::offset_of!(rte_mbuf, vlan_tci_outer) - 56usize]; + [ + "Offset of field: rte_mbuf::cacheline1", + ][::std::mem::offset_of!(rte_mbuf, cacheline1) - 64usize]; + [ + "Offset of field: rte_mbuf::pool", + ][::std::mem::offset_of!(rte_mbuf, pool) - 72usize]; + [ + "Offset of field: rte_mbuf::next", + ][::std::mem::offset_of!(rte_mbuf, next) - 80usize]; + [ + "Offset of field: rte_mbuf::priv_size", + ][::std::mem::offset_of!(rte_mbuf, priv_size) - 96usize]; + [ + "Offset of field: rte_mbuf::timesync", + ][::std::mem::offset_of!(rte_mbuf, timesync) - 98usize]; +}; impl Default for rte_mbuf { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs b/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs index 129300790b..19394d271f 100644 --- a/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs @@ -146,17 +146,17 @@ fn bindgen_test_layout_rte_atomic16_t() { assert_eq!( ::std::mem::size_of::(), 2usize, - concat!("Size of: ", stringify!(rte_atomic16_t)), + "Size of rte_atomic16_t", ); assert_eq!( ::std::mem::align_of::(), 2usize, - concat!("Alignment of ", stringify!(rte_atomic16_t)), + "Alignment of rte_atomic16_t", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).cnt) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_atomic16_t), "::", stringify!(cnt)), + "Offset of field: rte_atomic16_t::cnt", ); } impl Clone for rte_atomic16_t { @@ -233,32 +233,22 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_1() { assert_eq!( ::std::mem::size_of::(), 2usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_1)), + "Size of rte_mbuf__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 2usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_1)), + "Alignment of rte_mbuf__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).refcnt_atomic) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_1), - "::", - stringify!(refcnt_atomic), - ), + "Offset of field: rte_mbuf__bindgen_ty_1::refcnt_atomic", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).refcnt) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_1), - "::", - stringify!(refcnt), - ), + "Offset of field: rte_mbuf__bindgen_ty_1::refcnt", ); } impl Clone for rte_mbuf__bindgen_ty_1 { @@ -286,12 +276,12 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_2__bindgen_ty_1() { assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_2__bindgen_ty_1)), + "Size of rte_mbuf__bindgen_ty_2__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_2__bindgen_ty_1)), + "Alignment of rte_mbuf__bindgen_ty_2__bindgen_ty_1", ); } impl Clone for rte_mbuf__bindgen_ty_2__bindgen_ty_1 { @@ -467,22 +457,17 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_2() { assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_2)), + "Size of rte_mbuf__bindgen_ty_2", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_2)), + "Alignment of rte_mbuf__bindgen_ty_2", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).packet_type) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_2), - "::", - stringify!(packet_type), - ), + "Offset of field: rte_mbuf__bindgen_ty_2::packet_type", ); } impl Clone for rte_mbuf__bindgen_ty_2 { @@ -535,40 +520,24 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindg rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1, >(), 4usize, - concat!( - "Size of: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1), - ), + "Size of rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::< rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1, >(), 2usize, - concat!( - "Alignment of ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1), - ), + "Alignment of rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).hash) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(hash), - ), + "Offset of field: rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1::hash", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).id) as usize - ptr as usize }, 2usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(id), - ), + "Offset of field: rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1::id", ); } impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 { @@ -585,28 +554,17 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1() { assert_eq!( ::std::mem::size_of::(), 4usize, - concat!( - "Size of: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1), - ), + "Size of rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!( - "Alignment of ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1), - ), + "Alignment of rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).lo) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(lo), - ), + "Offset of field: rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1::lo", ); } impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 { @@ -621,22 +579,17 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1() { assert_eq!( ::std::mem::size_of::(), 8usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1)), + "Size of rte_mbuf__bindgen_ty_3__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1)), + "Alignment of rte_mbuf__bindgen_ty_3__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).hi) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_1), - "::", - stringify!(hi), - ), + "Offset of field: rte_mbuf__bindgen_ty_3__bindgen_ty_1::hi", ); } impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_1 { @@ -657,32 +610,22 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_2() { assert_eq!( ::std::mem::size_of::(), 8usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2)), + "Size of rte_mbuf__bindgen_ty_3__bindgen_ty_2", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2)), + "Alignment of rte_mbuf__bindgen_ty_3__bindgen_ty_2", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).lo) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2), - "::", - stringify!(lo), - ), + "Offset of field: rte_mbuf__bindgen_ty_3__bindgen_ty_2::lo", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).hi) as usize - ptr as usize }, 4usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3__bindgen_ty_2), - "::", - stringify!(hi), - ), + "Offset of field: rte_mbuf__bindgen_ty_3__bindgen_ty_2::hi", ); } impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_2 { @@ -697,52 +640,32 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_3() { assert_eq!( ::std::mem::size_of::(), 8usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_3)), + "Size of rte_mbuf__bindgen_ty_3", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_3)), + "Alignment of rte_mbuf__bindgen_ty_3", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).rss) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(rss), - ), + "Offset of field: rte_mbuf__bindgen_ty_3::rss", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).fdir) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(fdir), - ), + "Offset of field: rte_mbuf__bindgen_ty_3::fdir", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).sched) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(sched), - ), + "Offset of field: rte_mbuf__bindgen_ty_3::sched", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).usr) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_3), - "::", - stringify!(usr), - ), + "Offset of field: rte_mbuf__bindgen_ty_3::usr", ); } impl Clone for rte_mbuf__bindgen_ty_3 { @@ -766,32 +689,22 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_4() { assert_eq!( ::std::mem::size_of::(), 8usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_4)), + "Size of rte_mbuf__bindgen_ty_4", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_4)), + "Alignment of rte_mbuf__bindgen_ty_4", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).userdata) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_4), - "::", - stringify!(userdata), - ), + "Offset of field: rte_mbuf__bindgen_ty_4::userdata", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).udata64) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_4), - "::", - stringify!(udata64), - ), + "Offset of field: rte_mbuf__bindgen_ty_4::udata64", ); } impl Clone for rte_mbuf__bindgen_ty_4 { @@ -819,12 +732,12 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_5__bindgen_ty_1() { assert_eq!( ::std::mem::size_of::(), 8usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_5__bindgen_ty_1)), + "Size of rte_mbuf__bindgen_ty_5__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_5__bindgen_ty_1)), + "Alignment of rte_mbuf__bindgen_ty_5__bindgen_ty_1", ); } impl Clone for rte_mbuf__bindgen_ty_5__bindgen_ty_1 { @@ -977,22 +890,17 @@ fn bindgen_test_layout_rte_mbuf__bindgen_ty_5() { assert_eq!( ::std::mem::size_of::(), 8usize, - concat!("Size of: ", stringify!(rte_mbuf__bindgen_ty_5)), + "Size of rte_mbuf__bindgen_ty_5", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(rte_mbuf__bindgen_ty_5)), + "Alignment of rte_mbuf__bindgen_ty_5", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).tx_offload) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf__bindgen_ty_5), - "::", - stringify!(tx_offload), - ), + "Offset of field: rte_mbuf__bindgen_ty_5::tx_offload", ); } impl Clone for rte_mbuf__bindgen_ty_5 { @@ -1004,132 +912,113 @@ impl Clone for rte_mbuf__bindgen_ty_5 { fn bindgen_test_layout_rte_mbuf() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 128usize, - concat!("Size of: ", stringify!(rte_mbuf)), - ); + assert_eq!(::std::mem::size_of::(), 128usize, "Size of rte_mbuf"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).cacheline0) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(cacheline0)), + "Offset of field: rte_mbuf::cacheline0", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).buf_addr) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(buf_addr)), + "Offset of field: rte_mbuf::buf_addr", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).buf_physaddr) as usize - ptr as usize }, 8usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(buf_physaddr), - ), + "Offset of field: rte_mbuf::buf_physaddr", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).buf_len) as usize - ptr as usize }, 16usize, - concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(buf_len)), + "Offset of field: rte_mbuf::buf_len", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).rearm_data) as usize - ptr as usize }, 18usize, - concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(rearm_data)), + "Offset of field: rte_mbuf::rearm_data", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).data_off) as usize - ptr as usize }, 18usize, - concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(data_off)), + "Offset of field: rte_mbuf::data_off", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).nb_segs) as usize - ptr as usize }, 22usize, - concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(nb_segs)), + "Offset of field: rte_mbuf::nb_segs", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).port) as usize - ptr as usize }, 23usize, - concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(port)), + "Offset of field: rte_mbuf::port", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).ol_flags) as usize - ptr as usize }, 24usize, - concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(ol_flags)), + "Offset of field: rte_mbuf::ol_flags", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).rx_descriptor_fields1) as usize - ptr as usize }, 32usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(rx_descriptor_fields1), - ), + "Offset of field: rte_mbuf::rx_descriptor_fields1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).pkt_len) as usize - ptr as usize }, 36usize, - concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(pkt_len)), + "Offset of field: rte_mbuf::pkt_len", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).data_len) as usize - ptr as usize }, 40usize, - concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(data_len)), + "Offset of field: rte_mbuf::data_len", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).vlan_tci) as usize - ptr as usize }, 42usize, - concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(vlan_tci)), + "Offset of field: rte_mbuf::vlan_tci", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).hash) as usize - ptr as usize }, 44usize, - concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(hash)), + "Offset of field: rte_mbuf::hash", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).seqn) as usize - ptr as usize }, 52usize, - concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(seqn)), + "Offset of field: rte_mbuf::seqn", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).vlan_tci_outer) as usize - ptr as usize }, 56usize, - concat!( - "Offset of field: ", - stringify!(rte_mbuf), - "::", - stringify!(vlan_tci_outer), - ), + "Offset of field: rte_mbuf::vlan_tci_outer", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).cacheline1) as usize - ptr as usize }, 64usize, - concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(cacheline1)), + "Offset of field: rte_mbuf::cacheline1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).pool) as usize - ptr as usize }, 72usize, - concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(pool)), + "Offset of field: rte_mbuf::pool", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize }, 80usize, - concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(next)), + "Offset of field: rte_mbuf::next", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).priv_size) as usize - ptr as usize }, 96usize, - concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(priv_size)), + "Offset of field: rte_mbuf::priv_size", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).timesync) as usize - ptr as usize }, 98usize, - concat!("Offset of field: ", stringify!(rte_mbuf), "::", stringify!(timesync)), + "Offset of field: rte_mbuf::timesync", ); } impl Default for rte_mbuf { diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/constified-enum-module-overflow.rs b/bindgen-tests/tests/expectations/tests/libclang-9/constified-enum-module-overflow.rs index 49498deaa5..a4bdacf3a7 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/constified-enum-module-overflow.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/constified-enum-module-overflow.rs @@ -15,32 +15,16 @@ pub type C_U = B; pub struct A { pub u: u8, } -#[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::(), 1usize, concat!("Size of: ", stringify!(A))); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(A)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(u)), - ); -} -#[test] -fn __bindgen_test_layout_C_open0_A_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of template specialization: ", stringify!(C)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of template specialization: ", stringify!(C)), - ); -} +const _: () = { + ["Size of A"][::std::mem::size_of::() - 1usize]; + ["Alignment of A"][::std::mem::align_of::() - 1usize]; + ["Offset of field: A::u"][::std::mem::offset_of!(A, u) - 0usize]; +}; +const _: () = { + [ + "Size of template specialization: C_open0_A_close0", + ][::std::mem::size_of::() - 1usize]; + [ + "Align of template specialization: C_open0_A_close0", + ][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/ptr32-has-different-size.rs b/bindgen-tests/tests/expectations/tests/libclang-9/ptr32-has-different-size.rs index 0d677052ea..1ffc5249bc 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/ptr32-has-different-size.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/ptr32-has-different-size.rs @@ -4,31 +4,13 @@ pub struct TEST_STRUCT { pub ptr_32bit: *mut ::std::os::raw::c_void, } -#[test] -fn bindgen_test_layout_TEST_STRUCT() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(TEST_STRUCT)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(TEST_STRUCT)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ptr_32bit) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(TEST_STRUCT), - "::", - stringify!(ptr_32bit), - ), - ); -} +const _: () = { + ["Size of TEST_STRUCT"][::std::mem::size_of::() - 8usize]; + ["Alignment of TEST_STRUCT"][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: TEST_STRUCT::ptr_32bit", + ][::std::mem::offset_of!(TEST_STRUCT, ptr_32bit) - 0usize]; +}; impl Default for TEST_STRUCT { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/struct_typedef_ns.rs b/bindgen-tests/tests/expectations/tests/libclang-9/struct_typedef_ns.rs index 44afa4822a..34e44b7417 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/struct_typedef_ns.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/struct_typedef_ns.rs @@ -11,31 +11,15 @@ pub mod root { pub struct typedef_struct { pub foo: ::std::os::raw::c_int, } - #[test] - fn bindgen_test_layout_typedef_struct() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(typedef_struct)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(typedef_struct)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(typedef_struct), - "::", - stringify!(foo), - ), - ); - } + const _: () = { + ["Size of typedef_struct"][::std::mem::size_of::() - 4usize]; + [ + "Alignment of typedef_struct", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: typedef_struct::foo", + ][::std::mem::offset_of!(typedef_struct, foo) - 0usize]; + }; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum typedef_enum { @@ -50,31 +34,15 @@ pub mod root { pub struct _bindgen_ty_1 { pub foo: ::std::os::raw::c_int, } - #[test] - fn bindgen_test_layout__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit<_bindgen_ty_1> = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::<_bindgen_ty_1>(), - 4usize, - concat!("Size of: ", stringify!(_bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::<_bindgen_ty_1>(), - 4usize, - concat!("Alignment of ", stringify!(_bindgen_ty_1)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_bindgen_ty_1), - "::", - stringify!(foo), - ), - ); - } + const _: () = { + ["Size of _bindgen_ty_1"][::std::mem::size_of::<_bindgen_ty_1>() - 4usize]; + [ + "Alignment of _bindgen_ty_1", + ][::std::mem::align_of::<_bindgen_ty_1>() - 4usize]; + [ + "Offset of field: _bindgen_ty_1::foo", + ][::std::mem::offset_of!(_bindgen_ty_1, foo) - 0usize]; + }; pub type typedef_struct = root::_bindgen_mod_id_12::_bindgen_ty_1; pub const _bindgen_mod_id_12_BAR: root::_bindgen_mod_id_12::_bindgen_ty_2 = _bindgen_ty_2::BAR; #[repr(u32)] diff --git a/bindgen-tests/tests/expectations/tests/long_double.rs b/bindgen-tests/tests/expectations/tests/long_double.rs index b362787f9a..aa3109ca43 100644 --- a/bindgen-tests/tests/expectations/tests/long_double.rs +++ b/bindgen-tests/tests/expectations/tests/long_double.rs @@ -9,19 +9,11 @@ pub struct foo { 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, - concat!("Size of: ", stringify!(foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 16usize, - concat!("Alignment of ", stringify!(foo)), - ); + 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, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)), + "Offset of field: foo::bar", ); } diff --git a/bindgen-tests/tests/expectations/tests/mangling-linux32.rs b/bindgen-tests/tests/expectations/tests/mangling-linux32.rs index 1672f2cf65..dd34ac92f7 100644 --- a/bindgen-tests/tests/expectations/tests/mangling-linux32.rs +++ b/bindgen-tests/tests/expectations/tests/mangling-linux32.rs @@ -11,16 +11,7 @@ extern "C" { #[link_name = "\u{1}_ZN3Foo4sBarE"] pub static mut Foo_sBar: bool; } -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)), - ); -} +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/mangling-linux64.rs b/bindgen-tests/tests/expectations/tests/mangling-linux64.rs index 1672f2cf65..dd34ac92f7 100644 --- a/bindgen-tests/tests/expectations/tests/mangling-linux64.rs +++ b/bindgen-tests/tests/expectations/tests/mangling-linux64.rs @@ -11,16 +11,7 @@ extern "C" { #[link_name = "\u{1}_ZN3Foo4sBarE"] pub static mut Foo_sBar: bool; } -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)), - ); -} +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/mangling-macos.rs b/bindgen-tests/tests/expectations/tests/mangling-macos.rs index b3c236bb0b..8a95f99249 100644 --- a/bindgen-tests/tests/expectations/tests/mangling-macos.rs +++ b/bindgen-tests/tests/expectations/tests/mangling-macos.rs @@ -11,16 +11,7 @@ extern "C" { #[link_name = "\u{1}__ZN3Foo4sBarE"] pub static mut Foo_sBar: bool; } -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)), - ); -} +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/mangling-win32.rs b/bindgen-tests/tests/expectations/tests/mangling-win32.rs index 34efb92461..dddbde0bc7 100644 --- a/bindgen-tests/tests/expectations/tests/mangling-win32.rs +++ b/bindgen-tests/tests/expectations/tests/mangling-win32.rs @@ -11,19 +11,10 @@ extern "C" { #[link_name = "\u{1}?sBar@Foo@@2_NA"] pub static mut Foo_sBar: bool; } -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)), - ); -} +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; +}; extern "fastcall" { pub fn fast_call_func_no_args() -> ::std::os::raw::c_int; } diff --git a/bindgen-tests/tests/expectations/tests/mangling-win64.rs b/bindgen-tests/tests/expectations/tests/mangling-win64.rs index 99224e54dc..655992271d 100644 --- a/bindgen-tests/tests/expectations/tests/mangling-win64.rs +++ b/bindgen-tests/tests/expectations/tests/mangling-win64.rs @@ -11,16 +11,7 @@ extern "C" { #[link_name = "\u{1}?sBar@Foo@@2_NA"] pub static mut Foo_sBar: bool; } -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)), - ); -} +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/merge-extern-blocks.rs b/bindgen-tests/tests/expectations/tests/merge-extern-blocks.rs index 5c4b8e02ae..0b2eb59af9 100644 --- a/bindgen-tests/tests/expectations/tests/merge-extern-blocks.rs +++ b/bindgen-tests/tests/expectations/tests/merge-extern-blocks.rs @@ -8,26 +8,11 @@ pub mod root { pub struct Point { pub x: ::std::os::raw::c_int, } - #[test] - fn bindgen_test_layout_Point() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Point)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Point)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Point), "::", stringify!(x)), - ); - } + const _: () = { + ["Size of Point"][::std::mem::size_of::() - 4usize]; + ["Alignment of Point"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Point::x"][::std::mem::offset_of!(Point, x) - 0usize]; + }; pub mod ns { #[allow(unused_imports)] use self::super::super::root; @@ -36,26 +21,11 @@ pub mod root { pub struct Point { pub x: ::std::os::raw::c_int, } - #[test] - fn bindgen_test_layout_Point() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Point)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Point)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Point), "::", stringify!(x)), - ); - } + const _: () = { + ["Size of Point"][::std::mem::size_of::() - 4usize]; + ["Alignment of Point"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Point::x"][::std::mem::offset_of!(Point, x) - 0usize]; + }; extern "C" { #[link_name = "\u{1}_ZN2ns3fooEv"] pub fn foo() -> ::std::os::raw::c_int; diff --git a/bindgen-tests/tests/expectations/tests/method-mangling.rs b/bindgen-tests/tests/expectations/tests/method-mangling.rs index f241f43525..e7127376cd 100644 --- a/bindgen-tests/tests/expectations/tests/method-mangling.rs +++ b/bindgen-tests/tests/expectations/tests/method-mangling.rs @@ -4,19 +4,10 @@ pub struct Foo { pub _address: u8, } -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)), - ); -} +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; +}; extern "C" { #[link_name = "\u{1}_ZN3Foo4typeEv"] pub fn Foo_type(this: *mut Foo) -> ::std::os::raw::c_int; diff --git a/bindgen-tests/tests/expectations/tests/module-allowlisted.rs b/bindgen-tests/tests/expectations/tests/module-allowlisted.rs index 945bccac2d..257da9fb31 100644 --- a/bindgen-tests/tests/expectations/tests/module-allowlisted.rs +++ b/bindgen-tests/tests/expectations/tests/module-allowlisted.rs @@ -8,17 +8,8 @@ pub mod root { pub struct Test { pub _address: u8, } - #[test] - fn bindgen_test_layout_Test() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Test)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Test)), - ); - } + const _: () = { + ["Size of Test"][::std::mem::size_of::() - 1usize]; + ["Alignment of Test"][::std::mem::align_of::() - 1usize]; + }; } diff --git a/bindgen-tests/tests/expectations/tests/msvc-no-usr.rs b/bindgen-tests/tests/expectations/tests/msvc-no-usr.rs index 2afd183321..29363b07f7 100644 --- a/bindgen-tests/tests/expectations/tests/msvc-no-usr.rs +++ b/bindgen-tests/tests/expectations/tests/msvc-no-usr.rs @@ -4,19 +4,8 @@ pub struct A { pub foo: usize, } -#[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, concat!("Size of: ", stringify!(A))); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(A)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(foo)), - ); -} +const _: () = { + ["Size of A"][::std::mem::size_of::() - 8usize]; + ["Alignment of A"][::std::mem::align_of::() - 8usize]; + ["Offset of field: A::foo"][::std::mem::offset_of!(A, foo) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/multiple-inherit-empty-correct-layout.rs b/bindgen-tests/tests/expectations/tests/multiple-inherit-empty-correct-layout.rs index 81b5e7f1d8..b8963d6499 100644 --- a/bindgen-tests/tests/expectations/tests/multiple-inherit-empty-correct-layout.rs +++ b/bindgen-tests/tests/expectations/tests/multiple-inherit-empty-correct-layout.rs @@ -4,52 +4,25 @@ pub struct Foo { pub _address: u8, } -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)), - ); -} +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Bar { pub _address: u8, } -#[test] -fn bindgen_test_layout_Bar() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Bar)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Bar)), - ); -} +const _: () = { + ["Size of Bar"][::std::mem::size_of::() - 1usize]; + ["Alignment of Bar"][::std::mem::align_of::() - 1usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Baz { pub _address: u8, } -#[test] -fn bindgen_test_layout_Baz() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Baz)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Baz)), - ); -} +const _: () = { + ["Size of Baz"][::std::mem::size_of::() - 1usize]; + ["Alignment of Baz"][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/mutable.rs b/bindgen-tests/tests/expectations/tests/mutable.rs index ddf49aaeee..ca59bd15cc 100644 --- a/bindgen-tests/tests/expectations/tests/mutable.rs +++ b/bindgen-tests/tests/expectations/tests/mutable.rs @@ -5,79 +5,38 @@ pub struct C { pub m_member: ::std::os::raw::c_int, pub m_other: ::std::os::raw::c_int, } -#[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::(), 8usize, concat!("Size of: ", stringify!(C))); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(m_member)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).m_other) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(m_other)), - ); -} +const _: () = { + ["Size of C"][::std::mem::size_of::() - 8usize]; + ["Alignment of C"][::std::mem::align_of::() - 4usize]; + ["Offset of field: C::m_member"][::std::mem::offset_of!(C, m_member) - 0usize]; + ["Offset of field: C::m_other"][::std::mem::offset_of!(C, m_other) - 4usize]; +}; #[repr(C)] #[derive(Debug, Default)] pub struct NonCopiable { pub m_member: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_NonCopiable() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(NonCopiable)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(NonCopiable)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(NonCopiable), "::", stringify!(m_member)), - ); -} +const _: () = { + ["Size of NonCopiable"][::std::mem::size_of::() - 4usize]; + ["Alignment of NonCopiable"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: NonCopiable::m_member", + ][::std::mem::offset_of!(NonCopiable, m_member) - 0usize]; +}; #[repr(C)] #[derive(Debug, Default)] pub struct NonCopiableWithNonCopiableMutableMember { pub m_member: NonCopiable, } -#[test] -fn bindgen_test_layout_NonCopiableWithNonCopiableMutableMember() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(NonCopiableWithNonCopiableMutableMember)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(NonCopiableWithNonCopiableMutableMember)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).m_member) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NonCopiableWithNonCopiableMutableMember), - "::", - stringify!(m_member), - ), - ); -} +const _: () = { + [ + "Size of NonCopiableWithNonCopiableMutableMember", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of NonCopiableWithNonCopiableMutableMember", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: NonCopiableWithNonCopiableMutableMember::m_member", + ][::std::mem::offset_of!(NonCopiableWithNonCopiableMutableMember, m_member) + - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/namespace.rs b/bindgen-tests/tests/expectations/tests/namespace.rs index ab3a613840..93e201d329 100644 --- a/bindgen-tests/tests/expectations/tests/namespace.rs +++ b/bindgen-tests/tests/expectations/tests/namespace.rs @@ -25,26 +25,11 @@ pub mod root { pub struct A { pub b: root::whatever::whatever_int_t, } - #[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::(), - 4usize, - concat!("Size of: ", stringify!(A)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(A)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(b)), - ); - } + const _: () = { + ["Size of A"][::std::mem::size_of::() - 4usize]; + ["Alignment of A"][::std::mem::align_of::() - 4usize]; + ["Offset of field: A::b"][::std::mem::offset_of!(A, b) - 0usize]; + }; } #[repr(C)] #[derive(Debug)] diff --git a/bindgen-tests/tests/expectations/tests/nested.rs b/bindgen-tests/tests/expectations/tests/nested.rs index 71d3a4c28a..a083b7b341 100644 --- a/bindgen-tests/tests/expectations/tests/nested.rs +++ b/bindgen-tests/tests/expectations/tests/nested.rs @@ -4,26 +4,11 @@ pub struct Calc { pub w: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_Calc() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Calc)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Calc)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).w) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Calc), "::", stringify!(w)), - ); -} +const _: () = { + ["Size of Calc"][::std::mem::size_of::() - 4usize]; + ["Alignment of Calc"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Calc::w"][::std::mem::offset_of!(Calc, w) - 0usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Test { @@ -40,54 +25,25 @@ pub struct Test_Size { pub struct Test_Size_Dimension { pub _base: Calc, } -#[test] -fn bindgen_test_layout_Test_Size_Dimension() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Test_Size_Dimension)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Test_Size_Dimension)), - ); -} -#[test] -fn bindgen_test_layout_Test_Size() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Test_Size)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Test_Size)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mWidth) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Test_Size), "::", stringify!(mWidth)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mHeight) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(Test_Size), "::", stringify!(mHeight)), - ); -} -#[test] -fn bindgen_test_layout_Test() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Test)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Test)), - ); -} +const _: () = { + [ + "Size of Test_Size_Dimension", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of Test_Size_Dimension", + ][::std::mem::align_of::() - 4usize]; +}; +const _: () = { + ["Size of Test_Size"][::std::mem::size_of::() - 8usize]; + ["Alignment of Test_Size"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: Test_Size::mWidth", + ][::std::mem::offset_of!(Test_Size, mWidth) - 0usize]; + [ + "Offset of field: Test_Size::mHeight", + ][::std::mem::offset_of!(Test_Size, mHeight) - 4usize]; +}; +const _: () = { + ["Size of Test"][::std::mem::size_of::() - 1usize]; + ["Alignment of Test"][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/nested_vtable.rs b/bindgen-tests/tests/expectations/tests/nested_vtable.rs index bcedd777e8..7c4fd14f4f 100644 --- a/bindgen-tests/tests/expectations/tests/nested_vtable.rs +++ b/bindgen-tests/tests/expectations/tests/nested_vtable.rs @@ -10,19 +10,10 @@ pub struct nsISupports__bindgen_vtable { pub struct nsISupports { pub vtable_: *const nsISupports__bindgen_vtable, } -#[test] -fn bindgen_test_layout_nsISupports() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(nsISupports)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(nsISupports)), - ); -} +const _: () = { + ["Size of nsISupports"][::std::mem::size_of::() - 8usize]; + ["Alignment of nsISupports"][::std::mem::align_of::() - 8usize]; +}; impl Default for nsISupports { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -43,19 +34,10 @@ extern "C" { pub struct nsIRunnable { pub _base: nsISupports, } -#[test] -fn bindgen_test_layout_nsIRunnable() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(nsIRunnable)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(nsIRunnable)), - ); -} +const _: () = { + ["Size of nsIRunnable"][::std::mem::size_of::() - 8usize]; + ["Alignment of nsIRunnable"][::std::mem::align_of::() - 8usize]; +}; impl Default for nsIRunnable { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -70,19 +52,10 @@ impl Default for nsIRunnable { pub struct Runnable { pub _base: nsIRunnable, } -#[test] -fn bindgen_test_layout_Runnable() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Runnable)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Runnable)), - ); -} +const _: () = { + ["Size of Runnable"][::std::mem::size_of::() - 8usize]; + ["Alignment of Runnable"][::std::mem::align_of::() - 8usize]; +}; impl Default for Runnable { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/nested_within_namespace.rs b/bindgen-tests/tests/expectations/tests/nested_within_namespace.rs index c9b00d5add..1cc81efed9 100644 --- a/bindgen-tests/tests/expectations/tests/nested_within_namespace.rs +++ b/bindgen-tests/tests/expectations/tests/nested_within_namespace.rs @@ -16,70 +16,27 @@ pub mod root { pub struct Bar_Baz { pub foo: ::std::os::raw::c_int, } - #[test] - fn bindgen_test_layout_Bar_Baz() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Bar_Baz)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Bar_Baz)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Bar_Baz), "::", stringify!(foo)), - ); - } - #[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, - concat!("Size of: ", stringify!(Bar)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Bar)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(foo)), - ); - } + const _: () = { + ["Size of Bar_Baz"][::std::mem::size_of::() - 4usize]; + ["Alignment of Bar_Baz"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: Bar_Baz::foo", + ][::std::mem::offset_of!(Bar_Baz, foo) - 0usize]; + }; + 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]; + }; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Baz { pub baz: ::std::os::raw::c_int, } - #[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::(), - 4usize, - concat!("Size of: ", stringify!(Baz)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Baz)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Baz), "::", stringify!(baz)), - ); - } + const _: () = { + ["Size of Baz"][::std::mem::size_of::() - 4usize]; + ["Alignment of Baz"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Baz::baz"][::std::mem::offset_of!(Baz, baz) - 0usize]; + }; } } diff --git a/bindgen-tests/tests/expectations/tests/no-comments.rs b/bindgen-tests/tests/expectations/tests/no-comments.rs index 712580c9fd..20fa648a47 100644 --- a/bindgen-tests/tests/expectations/tests/no-comments.rs +++ b/bindgen-tests/tests/expectations/tests/no-comments.rs @@ -4,23 +4,8 @@ pub struct Foo { pub s: ::std::os::raw::c_int, } -#[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::(), - 4usize, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Foo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).s) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(s)), - ); -} +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 4usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Foo::s"][::std::mem::offset_of!(Foo, s) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/no-derive-debug.rs b/bindgen-tests/tests/expectations/tests/no-derive-debug.rs index 6a8c4d8aa7..9c58b9855b 100644 --- a/bindgen-tests/tests/expectations/tests/no-derive-debug.rs +++ b/bindgen-tests/tests/expectations/tests/no-derive-debug.rs @@ -12,31 +12,12 @@ pub struct bar { pub foo: foo, pub baz: ::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::(), - 8usize, - concat!("Size of: ", stringify!(bar)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(bar)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(bar), "::", stringify!(foo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(bar), "::", stringify!(baz)), - ); -} +const _: () = { + ["Size of bar"][::std::mem::size_of::() - 8usize]; + ["Alignment of bar"][::std::mem::align_of::() - 4usize]; + ["Offset of field: bar::foo"][::std::mem::offset_of!(bar, foo) - 0usize]; + ["Offset of field: bar::baz"][::std::mem::offset_of!(bar, baz) - 4usize]; +}; impl Default for bar { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/no-derive-default.rs b/bindgen-tests/tests/expectations/tests/no-derive-default.rs index fea25bec1e..3b2ebcc807 100644 --- a/bindgen-tests/tests/expectations/tests/no-derive-default.rs +++ b/bindgen-tests/tests/expectations/tests/no-derive-default.rs @@ -12,28 +12,9 @@ pub struct bar { pub foo: foo, pub baz: ::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::(), - 8usize, - concat!("Size of: ", stringify!(bar)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(bar)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(bar), "::", stringify!(foo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(bar), "::", stringify!(baz)), - ); -} +const _: () = { + ["Size of bar"][::std::mem::size_of::() - 8usize]; + ["Alignment of bar"][::std::mem::align_of::() - 4usize]; + ["Offset of field: bar::foo"][::std::mem::offset_of!(bar, foo) - 0usize]; + ["Offset of field: bar::baz"][::std::mem::offset_of!(bar, baz) - 4usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/no-hash-allowlisted.rs b/bindgen-tests/tests/expectations/tests/no-hash-allowlisted.rs index ab94a578d8..538d2109d5 100644 --- a/bindgen-tests/tests/expectations/tests/no-hash-allowlisted.rs +++ b/bindgen-tests/tests/expectations/tests/no-hash-allowlisted.rs @@ -4,23 +4,8 @@ pub struct NoHash { pub i: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_NoHash() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(NoHash)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(NoHash)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(NoHash), "::", stringify!(i)), - ); -} +const _: () = { + ["Size of NoHash"][::std::mem::size_of::() - 4usize]; + ["Alignment of NoHash"][::std::mem::align_of::() - 4usize]; + ["Offset of field: NoHash::i"][::std::mem::offset_of!(NoHash, i) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/no-hash-opaque.rs b/bindgen-tests/tests/expectations/tests/no-hash-opaque.rs index 9f25d948a5..b8869924b5 100644 --- a/bindgen-tests/tests/expectations/tests/no-hash-opaque.rs +++ b/bindgen-tests/tests/expectations/tests/no-hash-opaque.rs @@ -5,16 +5,7 @@ pub struct NoHash { pub _bindgen_opaque_blob: u32, } -#[test] -fn bindgen_test_layout_NoHash() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(NoHash)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(NoHash)), - ); -} +const _: () = { + ["Size of NoHash"][::std::mem::size_of::() - 4usize]; + ["Alignment of NoHash"][::std::mem::align_of::() - 4usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/no-partialeq-allowlisted.rs b/bindgen-tests/tests/expectations/tests/no-partialeq-allowlisted.rs index d07f16b944..ad09f91cc9 100644 --- a/bindgen-tests/tests/expectations/tests/no-partialeq-allowlisted.rs +++ b/bindgen-tests/tests/expectations/tests/no-partialeq-allowlisted.rs @@ -4,23 +4,8 @@ pub struct NoPartialEq { pub i: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_NoPartialEq() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(NoPartialEq)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(NoPartialEq)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(NoPartialEq), "::", stringify!(i)), - ); -} +const _: () = { + ["Size of NoPartialEq"][::std::mem::size_of::() - 4usize]; + ["Alignment of NoPartialEq"][::std::mem::align_of::() - 4usize]; + ["Offset of field: NoPartialEq::i"][::std::mem::offset_of!(NoPartialEq, i) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/no-partialeq-opaque.rs b/bindgen-tests/tests/expectations/tests/no-partialeq-opaque.rs index cf775ccd47..f16b92f5d4 100644 --- a/bindgen-tests/tests/expectations/tests/no-partialeq-opaque.rs +++ b/bindgen-tests/tests/expectations/tests/no-partialeq-opaque.rs @@ -5,16 +5,7 @@ pub struct NoPartialEq { pub _bindgen_opaque_blob: u32, } -#[test] -fn bindgen_test_layout_NoPartialEq() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(NoPartialEq)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(NoPartialEq)), - ); -} +const _: () = { + ["Size of NoPartialEq"][::std::mem::size_of::() - 4usize]; + ["Alignment of NoPartialEq"][::std::mem::align_of::() - 4usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/no-recursive-allowlisting.rs b/bindgen-tests/tests/expectations/tests/no-recursive-allowlisting.rs index 6dd354df35..0fc566bc2a 100644 --- a/bindgen-tests/tests/expectations/tests/no-recursive-allowlisting.rs +++ b/bindgen-tests/tests/expectations/tests/no-recursive-allowlisting.rs @@ -5,26 +5,11 @@ pub enum Bar {} pub struct Foo { pub baz: *mut Bar, } -#[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::(), - 8usize, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Foo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(baz)), - ); -} +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 8usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 8usize]; + ["Offset of field: Foo::baz"][::std::mem::offset_of!(Foo, baz) - 0usize]; +}; impl Default for Foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/no-std.rs b/bindgen-tests/tests/expectations/tests/no-std.rs index a41bef8939..32defdf1f5 100644 --- a/bindgen-tests/tests/expectations/tests/no-std.rs +++ b/bindgen-tests/tests/expectations/tests/no-std.rs @@ -11,36 +11,13 @@ pub struct foo { pub b: libc::c_int, pub bar: *mut libc::c_void, } -#[test] -fn bindgen_test_layout_foo() { - const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::core::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(foo)), - ); - assert_eq!( - ::core::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(foo)), - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)), - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)), - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)), - ); -} +const _: () = { + ["Size of foo"][::core::mem::size_of::() - 16usize]; + ["Alignment of foo"][::core::mem::align_of::() - 8usize]; + ["Offset of field: foo::a"][::core::mem::offset_of!(foo, a) - 0usize]; + ["Offset of field: foo::b"][::core::mem::offset_of!(foo, b) - 4usize]; + ["Offset of field: foo::bar"][::core::mem::offset_of!(foo, bar) - 8usize]; +}; impl Default for foo { fn default() -> Self { let mut s = ::core::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/no_copy_allowlisted.rs b/bindgen-tests/tests/expectations/tests/no_copy_allowlisted.rs index b0c9bc026e..409dd56784 100644 --- a/bindgen-tests/tests/expectations/tests/no_copy_allowlisted.rs +++ b/bindgen-tests/tests/expectations/tests/no_copy_allowlisted.rs @@ -4,23 +4,8 @@ pub struct NoCopy { pub i: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_NoCopy() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(NoCopy)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(NoCopy)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(NoCopy), "::", stringify!(i)), - ); -} +const _: () = { + ["Size of NoCopy"][::std::mem::size_of::() - 4usize]; + ["Alignment of NoCopy"][::std::mem::align_of::() - 4usize]; + ["Offset of field: NoCopy::i"][::std::mem::offset_of!(NoCopy, i) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/no_copy_opaque.rs b/bindgen-tests/tests/expectations/tests/no_copy_opaque.rs index 3a8f84784d..5cf9a9f65f 100644 --- a/bindgen-tests/tests/expectations/tests/no_copy_opaque.rs +++ b/bindgen-tests/tests/expectations/tests/no_copy_opaque.rs @@ -5,16 +5,7 @@ pub struct NoCopy { pub _bindgen_opaque_blob: u32, } -#[test] -fn bindgen_test_layout_NoCopy() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(NoCopy)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(NoCopy)), - ); -} +const _: () = { + ["Size of NoCopy"][::std::mem::size_of::() - 4usize]; + ["Alignment of NoCopy"][::std::mem::align_of::() - 4usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/no_debug_allowlisted.rs b/bindgen-tests/tests/expectations/tests/no_debug_allowlisted.rs index e58f9bf85a..042a3f00ad 100644 --- a/bindgen-tests/tests/expectations/tests/no_debug_allowlisted.rs +++ b/bindgen-tests/tests/expectations/tests/no_debug_allowlisted.rs @@ -4,23 +4,8 @@ pub struct NoDebug { pub i: ::std::os::raw::c_int, } -#[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::(), - 4usize, - concat!("Size of: ", stringify!(NoDebug)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(NoDebug)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(NoDebug), "::", stringify!(i)), - ); -} +const _: () = { + ["Size of NoDebug"][::std::mem::size_of::() - 4usize]; + ["Alignment of NoDebug"][::std::mem::align_of::() - 4usize]; + ["Offset of field: NoDebug::i"][::std::mem::offset_of!(NoDebug, i) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/no_debug_opaque.rs b/bindgen-tests/tests/expectations/tests/no_debug_opaque.rs index 527d370103..ca486739e0 100644 --- a/bindgen-tests/tests/expectations/tests/no_debug_opaque.rs +++ b/bindgen-tests/tests/expectations/tests/no_debug_opaque.rs @@ -5,16 +5,7 @@ pub struct NoDebug { pub _bindgen_opaque_blob: u32, } -#[test] -fn bindgen_test_layout_NoDebug() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(NoDebug)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(NoDebug)), - ); -} +const _: () = { + ["Size of NoDebug"][::std::mem::size_of::() - 4usize]; + ["Alignment of NoDebug"][::std::mem::align_of::() - 4usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/no_default_allowlisted.rs b/bindgen-tests/tests/expectations/tests/no_default_allowlisted.rs index 55501ebd2b..379596a065 100644 --- a/bindgen-tests/tests/expectations/tests/no_default_allowlisted.rs +++ b/bindgen-tests/tests/expectations/tests/no_default_allowlisted.rs @@ -4,23 +4,8 @@ pub struct NoDefault { pub i: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_NoDefault() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(NoDefault)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(NoDefault)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(NoDefault), "::", stringify!(i)), - ); -} +const _: () = { + ["Size of NoDefault"][::std::mem::size_of::() - 4usize]; + ["Alignment of NoDefault"][::std::mem::align_of::() - 4usize]; + ["Offset of field: NoDefault::i"][::std::mem::offset_of!(NoDefault, i) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/no_default_opaque.rs b/bindgen-tests/tests/expectations/tests/no_default_opaque.rs index b7dd4d41e1..28cd7b8cb5 100644 --- a/bindgen-tests/tests/expectations/tests/no_default_opaque.rs +++ b/bindgen-tests/tests/expectations/tests/no_default_opaque.rs @@ -5,16 +5,7 @@ pub struct NoDefault { pub _bindgen_opaque_blob: u32, } -#[test] -fn bindgen_test_layout_NoDefault() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(NoDefault)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(NoDefault)), - ); -} +const _: () = { + ["Size of NoDefault"][::std::mem::size_of::() - 4usize]; + ["Alignment of NoDefault"][::std::mem::align_of::() - 4usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/no_size_t_is_usize.rs b/bindgen-tests/tests/expectations/tests/no_size_t_is_usize.rs index 99d13449c7..326f0730a8 100644 --- a/bindgen-tests/tests/expectations/tests/no_size_t_is_usize.rs +++ b/bindgen-tests/tests/expectations/tests/no_size_t_is_usize.rs @@ -8,32 +8,13 @@ pub struct A { pub offset: ssize_t, pub next: *mut A, } -#[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::(), 24usize, concat!("Size of: ", stringify!(A))); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(A)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(len)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).offset) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(offset)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize }, - 16usize, - concat!("Offset of field: ", stringify!(A), "::", stringify!(next)), - ); -} +const _: () = { + ["Size of A"][::std::mem::size_of::() - 24usize]; + ["Alignment of A"][::std::mem::align_of::() - 8usize]; + ["Offset of field: A::len"][::std::mem::offset_of!(A, len) - 0usize]; + ["Offset of field: A::offset"][::std::mem::offset_of!(A, offset) - 8usize]; + ["Offset of field: A::next"][::std::mem::offset_of!(A, next) - 16usize]; +}; impl Default for A { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/non-type-params.rs b/bindgen-tests/tests/expectations/tests/non-type-params.rs index e83ee74de6..6fa250455c 100644 --- a/bindgen-tests/tests/expectations/tests/non-type-params.rs +++ b/bindgen-tests/tests/expectations/tests/non-type-params.rs @@ -8,48 +8,16 @@ pub struct UsesArray { pub array_bool_8: [u8; 8usize], pub array_int_4: ArrayInt4, } -#[test] -fn bindgen_test_layout_UsesArray() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 40usize, - concat!("Size of: ", stringify!(UsesArray)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(UsesArray)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).array_char_16) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(UsesArray), - "::", - stringify!(array_char_16), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).array_bool_8) as usize - ptr as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(UsesArray), - "::", - stringify!(array_bool_8), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).array_int_4) as usize - ptr as usize }, - 24usize, - concat!( - "Offset of field: ", - stringify!(UsesArray), - "::", - stringify!(array_int_4), - ), - ); -} +const _: () = { + ["Size of UsesArray"][::std::mem::size_of::() - 40usize]; + ["Alignment of UsesArray"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: UsesArray::array_char_16", + ][::std::mem::offset_of!(UsesArray, array_char_16) - 0usize]; + [ + "Offset of field: UsesArray::array_bool_8", + ][::std::mem::offset_of!(UsesArray, array_bool_8) - 16usize]; + [ + "Offset of field: UsesArray::array_int_4", + ][::std::mem::offset_of!(UsesArray, array_int_4) - 24usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/objc_interface_type.rs b/bindgen-tests/tests/expectations/tests/objc_interface_type.rs index a49f9229a0..53c7101e7d 100644 --- a/bindgen-tests/tests/expectations/tests/objc_interface_type.rs +++ b/bindgen-tests/tests/expectations/tests/objc_interface_type.rs @@ -25,26 +25,11 @@ pub trait IFoo: Sized + std::ops::Deref {} pub struct FooStruct { pub foo: Foo, } -#[test] -fn bindgen_test_layout_FooStruct() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(FooStruct)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(FooStruct)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(FooStruct), "::", stringify!(foo)), - ); -} +const _: () = { + ["Size of FooStruct"][::std::mem::size_of::() - 8usize]; + ["Alignment of FooStruct"][::std::mem::align_of::() - 8usize]; + ["Offset of field: FooStruct::foo"][::std::mem::offset_of!(FooStruct, foo) - 0usize]; +}; impl Default for FooStruct { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/only_bitfields.rs b/bindgen-tests/tests/expectations/tests/only_bitfields.rs index fe216f4b56..f3c9658762 100644 --- a/bindgen-tests/tests/expectations/tests/only_bitfields.rs +++ b/bindgen-tests/tests/expectations/tests/only_bitfields.rs @@ -89,15 +89,10 @@ pub struct C { pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, } -#[test] -fn bindgen_test_layout_C() { - assert_eq!(::std::mem::size_of::(), 1usize, concat!("Size of: ", stringify!(C))); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(C)), - ); -} +const _: () = { + ["Size of C"][::std::mem::size_of::() - 1usize]; + ["Alignment of C"][::std::mem::align_of::() - 1usize]; +}; impl C { #[inline] pub fn a(&self) -> bool { diff --git a/bindgen-tests/tests/expectations/tests/opaque-template-inst-member-2.rs b/bindgen-tests/tests/expectations/tests/opaque-template-inst-member-2.rs index 3dd89d0a5d..58b5004a4c 100644 --- a/bindgen-tests/tests/expectations/tests/opaque-template-inst-member-2.rs +++ b/bindgen-tests/tests/expectations/tests/opaque-template-inst-member-2.rs @@ -13,41 +13,20 @@ pub struct ContainsOpaqueTemplate { pub mBlah: u32, 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::(), - 8usize, - concat!("Size of: ", stringify!(ContainsOpaqueTemplate)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(ContainsOpaqueTemplate)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mBlah) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContainsOpaqueTemplate), - "::", - stringify!(mBlah), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mBaz) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(ContainsOpaqueTemplate), - "::", - stringify!(mBaz), - ), - ); -} +const _: () = { + [ + "Size of ContainsOpaqueTemplate", + ][::std::mem::size_of::() - 8usize]; + [ + "Alignment of ContainsOpaqueTemplate", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: ContainsOpaqueTemplate::mBlah", + ][::std::mem::offset_of!(ContainsOpaqueTemplate, mBlah) - 0usize]; + [ + "Offset of field: ContainsOpaqueTemplate::mBaz", + ][::std::mem::offset_of!(ContainsOpaqueTemplate, mBaz) - 4usize]; +}; /// Should also derive Debug/Hash/PartialEq. #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] @@ -55,31 +34,17 @@ pub struct InheritsOpaqueTemplate { pub _base: u8, 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::(), - 16usize, - concat!("Size of: ", stringify!(InheritsOpaqueTemplate)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(InheritsOpaqueTemplate)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).wow) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(InheritsOpaqueTemplate), - "::", - stringify!(wow), - ), - ); -} +const _: () = { + [ + "Size of InheritsOpaqueTemplate", + ][::std::mem::size_of::() - 16usize]; + [ + "Alignment of InheritsOpaqueTemplate", + ][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: InheritsOpaqueTemplate::wow", + ][::std::mem::offset_of!(InheritsOpaqueTemplate, wow) - 8usize]; +}; impl Default for InheritsOpaqueTemplate { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); 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 4f3f4b5724..4b070fa697 100644 --- a/bindgen-tests/tests/expectations/tests/opaque-template-inst-member.rs +++ b/bindgen-tests/tests/expectations/tests/opaque-template-inst-member.rs @@ -18,32 +18,22 @@ fn bindgen_test_layout_ContainsOpaqueTemplate() { assert_eq!( ::std::mem::size_of::(), 408usize, - concat!("Size of: ", stringify!(ContainsOpaqueTemplate)), + "Size of ContainsOpaqueTemplate", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(ContainsOpaqueTemplate)), + "Alignment of ContainsOpaqueTemplate", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mBlah) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(ContainsOpaqueTemplate), - "::", - stringify!(mBlah), - ), + "Offset of field: ContainsOpaqueTemplate::mBlah", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mBaz) as usize - ptr as usize }, 404usize, - concat!( - "Offset of field: ", - stringify!(ContainsOpaqueTemplate), - "::", - stringify!(mBaz), - ), + "Offset of field: ContainsOpaqueTemplate::mBaz", ); } impl Default for ContainsOpaqueTemplate { @@ -74,22 +64,17 @@ fn bindgen_test_layout_InheritsOpaqueTemplate() { assert_eq!( ::std::mem::size_of::(), 416usize, - concat!("Size of: ", stringify!(InheritsOpaqueTemplate)), + "Size of InheritsOpaqueTemplate", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(InheritsOpaqueTemplate)), + "Alignment of InheritsOpaqueTemplate", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).wow) as usize - ptr as usize }, 408usize, - concat!( - "Offset of field: ", - stringify!(InheritsOpaqueTemplate), - "::", - stringify!(wow), - ), + "Offset of field: InheritsOpaqueTemplate::wow", ); } impl Default for InheritsOpaqueTemplate { diff --git a/bindgen-tests/tests/expectations/tests/opaque-template-instantiation-namespaced.rs b/bindgen-tests/tests/expectations/tests/opaque-template-instantiation-namespaced.rs index 07190df7f9..2199785d9b 100644 --- a/bindgen-tests/tests/expectations/tests/opaque-template-instantiation-namespaced.rs +++ b/bindgen-tests/tests/expectations/tests/opaque-template-instantiation-namespaced.rs @@ -26,83 +26,37 @@ pub mod root { pub struct Foo { pub c: ::std::os::raw::c_char, } - #[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::(), - 1usize, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Foo), "::", stringify!(c)), - ); - } + const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; + ["Offset of field: Foo::c"][::std::mem::offset_of!(Foo, c) - 0usize]; + }; #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct Bar { pub i: ::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, - concat!("Size of: ", stringify!(Bar)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Bar)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(i)), - ); - } + const _: () = { + ["Size of Bar"][::std::mem::size_of::() - 4usize]; + ["Alignment of Bar"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Bar::i"][::std::mem::offset_of!(Bar, i) - 0usize]; + }; #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct ContainsInstantiation { pub not_opaque: root::zoidberg::Template, } - #[test] - fn bindgen_test_layout_ContainsInstantiation() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(ContainsInstantiation)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(ContainsInstantiation)), - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).not_opaque) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContainsInstantiation), - "::", - stringify!(not_opaque), - ), - ); - } + const _: () = { + [ + "Size of ContainsInstantiation", + ][::std::mem::size_of::() - 1usize]; + [ + "Alignment of ContainsInstantiation", + ][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: ContainsInstantiation::not_opaque", + ][::std::mem::offset_of!(ContainsInstantiation, not_opaque) - 0usize]; + }; impl Default for ContainsInstantiation { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -117,49 +71,26 @@ pub mod root { pub struct ContainsOpaqueInstantiation { pub opaque: u32, } - #[test] - fn bindgen_test_layout_ContainsOpaqueInstantiation() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(ContainsOpaqueInstantiation)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(ContainsOpaqueInstantiation)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).opaque) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContainsOpaqueInstantiation), - "::", - stringify!(opaque), - ), - ); - } - } - #[test] - fn __bindgen_test_layout_Template_open0_Foo_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 1usize, - concat!( - "Size of template specialization: ", - stringify!(root::zoidberg::Template < root::zoidberg::Foo >), - ), - ); - assert_eq!( - ::std::mem::align_of::>(), - 1usize, - concat!( - "Alignment of template specialization: ", - stringify!(root::zoidberg::Template < root::zoidberg::Foo >), - ), - ); + const _: () = { + [ + "Size of ContainsOpaqueInstantiation", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of ContainsOpaqueInstantiation", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: ContainsOpaqueInstantiation::opaque", + ][::std::mem::offset_of!(ContainsOpaqueInstantiation, opaque) - 0usize]; + }; } + const _: () = { + [ + "Size of template specialization: Template_open0_Foo_close0", + ][::std::mem::size_of::>() + - 1usize]; + [ + "Align of template specialization: Template_open0_Foo_close0", + ][::std::mem::align_of::>() + - 1usize]; + }; } diff --git a/bindgen-tests/tests/expectations/tests/opaque-template-instantiation.rs b/bindgen-tests/tests/expectations/tests/opaque-template-instantiation.rs index 7431f69024..83b4e08063 100644 --- a/bindgen-tests/tests/expectations/tests/opaque-template-instantiation.rs +++ b/bindgen-tests/tests/expectations/tests/opaque-template-instantiation.rs @@ -19,31 +19,17 @@ impl Default for Template { pub struct ContainsInstantiation { pub not_opaque: Template<::std::os::raw::c_char>, } -#[test] -fn bindgen_test_layout_ContainsInstantiation() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(ContainsInstantiation)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(ContainsInstantiation)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).not_opaque) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContainsInstantiation), - "::", - stringify!(not_opaque), - ), - ); -} +const _: () = { + [ + "Size of ContainsInstantiation", + ][::std::mem::size_of::() - 1usize]; + [ + "Alignment of ContainsInstantiation", + ][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: ContainsInstantiation::not_opaque", + ][::std::mem::offset_of!(ContainsInstantiation, not_opaque) - 0usize]; +}; impl Default for ContainsInstantiation { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -58,47 +44,22 @@ impl Default for ContainsInstantiation { pub struct ContainsOpaqueInstantiation { pub opaque: u32, } -#[test] -fn bindgen_test_layout_ContainsOpaqueInstantiation() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(ContainsOpaqueInstantiation)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(ContainsOpaqueInstantiation)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).opaque) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContainsOpaqueInstantiation), - "::", - stringify!(opaque), - ), - ); -} -#[test] -fn __bindgen_test_layout_Template_open0_char_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 1usize, - concat!( - "Size of template specialization: ", - stringify!(Template < ::std::os::raw::c_char >), - ), - ); - assert_eq!( - ::std::mem::align_of::>(), - 1usize, - concat!( - "Alignment of template specialization: ", - stringify!(Template < ::std::os::raw::c_char >), - ), - ); -} +const _: () = { + [ + "Size of ContainsOpaqueInstantiation", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of ContainsOpaqueInstantiation", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: ContainsOpaqueInstantiation::opaque", + ][::std::mem::offset_of!(ContainsOpaqueInstantiation, opaque) - 0usize]; +}; +const _: () = { + [ + "Size of template specialization: Template_open0_char_close0", + ][::std::mem::size_of::>() - 1usize]; + [ + "Align of template specialization: Template_open0_char_close0", + ][::std::mem::align_of::>() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/opaque-tracing.rs b/bindgen-tests/tests/expectations/tests/opaque-tracing.rs index 3bc54c5ed8..59afbf8ad9 100644 --- a/bindgen-tests/tests/expectations/tests/opaque-tracing.rs +++ b/bindgen-tests/tests/expectations/tests/opaque-tracing.rs @@ -9,16 +9,7 @@ extern "C" { pub struct Container { pub _bindgen_opaque_blob: [u32; 2usize], } -#[test] -fn bindgen_test_layout_Container() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Container)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Container)), - ); -} +const _: () = { + ["Size of Container"][::std::mem::size_of::() - 8usize]; + ["Alignment of Container"][::std::mem::align_of::() - 4usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/opaque_in_struct.rs b/bindgen-tests/tests/expectations/tests/opaque_in_struct.rs index 5a267a194b..1fb26f8406 100644 --- a/bindgen-tests/tests/expectations/tests/opaque_in_struct.rs +++ b/bindgen-tests/tests/expectations/tests/opaque_in_struct.rs @@ -6,41 +6,19 @@ pub struct opaque { pub _bindgen_opaque_blob: u32, } -#[test] -fn bindgen_test_layout_opaque() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(opaque)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(opaque)), - ); -} +const _: () = { + ["Size of opaque"][::std::mem::size_of::() - 4usize]; + ["Alignment of opaque"][::std::mem::align_of::() - 4usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct container { pub contained: opaque, } -#[test] -fn bindgen_test_layout_container() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(container)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(container)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).contained) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(container), "::", stringify!(contained)), - ); -} +const _: () = { + ["Size of container"][::std::mem::size_of::() - 4usize]; + ["Alignment of container"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: container::contained", + ][::std::mem::offset_of!(container, contained) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/opaque_pointer.rs b/bindgen-tests/tests/expectations/tests/opaque_pointer.rs index 36a120536e..9835e7f46e 100644 --- a/bindgen-tests/tests/expectations/tests/opaque_pointer.rs +++ b/bindgen-tests/tests/expectations/tests/opaque_pointer.rs @@ -6,19 +6,10 @@ pub struct OtherOpaque { pub _bindgen_opaque_blob: u32, } -#[test] -fn bindgen_test_layout_OtherOpaque() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(OtherOpaque)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(OtherOpaque)), - ); -} +const _: () = { + ["Size of OtherOpaque"][::std::mem::size_of::() - 4usize]; + ["Alignment of OtherOpaque"][::std::mem::align_of::() - 4usize]; +}; ///
#[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] @@ -32,41 +23,19 @@ pub struct WithOpaquePtr { pub other: u32, pub t: OtherOpaque, } -#[test] -fn bindgen_test_layout_WithOpaquePtr() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(WithOpaquePtr)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(WithOpaquePtr)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).whatever) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithOpaquePtr), - "::", - stringify!(whatever), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).other) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(WithOpaquePtr), "::", stringify!(other)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).t) as usize - ptr as usize }, - 12usize, - concat!("Offset of field: ", stringify!(WithOpaquePtr), "::", stringify!(t)), - ); -} +const _: () = { + ["Size of WithOpaquePtr"][::std::mem::size_of::() - 16usize]; + ["Alignment of WithOpaquePtr"][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: WithOpaquePtr::whatever", + ][::std::mem::offset_of!(WithOpaquePtr, whatever) - 0usize]; + [ + "Offset of field: WithOpaquePtr::other", + ][::std::mem::offset_of!(WithOpaquePtr, other) - 8usize]; + [ + "Offset of field: WithOpaquePtr::t", + ][::std::mem::offset_of!(WithOpaquePtr, t) - 12usize]; +}; impl Default for WithOpaquePtr { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/packed-bitfield.rs b/bindgen-tests/tests/expectations/tests/packed-bitfield.rs index 8d4b87453f..d788a4d5d4 100644 --- a/bindgen-tests/tests/expectations/tests/packed-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/packed-bitfield.rs @@ -89,19 +89,10 @@ pub struct Date { pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 3usize]>, } -#[test] -fn bindgen_test_layout_Date() { - assert_eq!( - ::std::mem::size_of::(), - 3usize, - concat!("Size of: ", stringify!(Date)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Date)), - ); -} +const _: () = { + ["Size of Date"][::std::mem::size_of::() - 3usize]; + ["Alignment of Date"][::std::mem::align_of::() - 1usize]; +}; impl Date { #[inline] pub fn day(&self) -> ::std::os::raw::c_uchar { diff --git a/bindgen-tests/tests/expectations/tests/packed-n-with-padding.rs b/bindgen-tests/tests/expectations/tests/packed-n-with-padding.rs index 3a24767eeb..cfb3bbec9b 100644 --- a/bindgen-tests/tests/expectations/tests/packed-n-with-padding.rs +++ b/bindgen-tests/tests/expectations/tests/packed-n-with-padding.rs @@ -7,38 +7,11 @@ pub struct Packed { pub c: ::std::os::raw::c_char, pub d: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_Packed() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 10usize, - concat!("Size of: ", stringify!(Packed)), - ); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(Packed)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Packed), "::", stringify!(a)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 2usize, - concat!("Offset of field: ", stringify!(Packed), "::", stringify!(b)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(Packed), "::", stringify!(c)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 6usize, - concat!("Offset of field: ", stringify!(Packed), "::", stringify!(d)), - ); -} +const _: () = { + ["Size of Packed"][::std::mem::size_of::() - 10usize]; + ["Alignment of Packed"][::std::mem::align_of::() - 2usize]; + ["Offset of field: Packed::a"][::std::mem::offset_of!(Packed, a) - 0usize]; + ["Offset of field: Packed::b"][::std::mem::offset_of!(Packed, b) - 2usize]; + ["Offset of field: Packed::c"][::std::mem::offset_of!(Packed, c) - 4usize]; + ["Offset of field: Packed::d"][::std::mem::offset_of!(Packed, d) - 6usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/packed-vtable.rs b/bindgen-tests/tests/expectations/tests/packed-vtable.rs index b85143250f..362017a233 100644 --- a/bindgen-tests/tests/expectations/tests/packed-vtable.rs +++ b/bindgen-tests/tests/expectations/tests/packed-vtable.rs @@ -8,15 +8,11 @@ pub struct PackedVtable { } #[test] fn bindgen_test_layout_PackedVtable() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(PackedVtable)), - ); + assert_eq!(::std::mem::size_of::(), 8usize, "Size of PackedVtable"); assert_eq!( ::std::mem::align_of::(), 1usize, - concat!("Alignment of ", stringify!(PackedVtable)), + "Alignment of PackedVtable", ); } impl Default for PackedVtable { diff --git a/bindgen-tests/tests/expectations/tests/parm-union.rs b/bindgen-tests/tests/expectations/tests/parm-union.rs index 92a3c19576..85c4718aa2 100644 --- a/bindgen-tests/tests/expectations/tests/parm-union.rs +++ b/bindgen-tests/tests/expectations/tests/parm-union.rs @@ -4,19 +4,10 @@ pub struct Struct { pub _address: u8, } -#[test] -fn bindgen_test_layout_Struct() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Struct)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Struct)), - ); -} +const _: () = { + ["Size of Struct"][::std::mem::size_of::() - 1usize]; + ["Alignment of Struct"][::std::mem::align_of::() - 1usize]; +}; extern "C" { #[link_name = "\u{1}_ZN6Struct8FunctionER5Union"] pub fn Struct_Function(this: *mut Struct, arg1: *mut Union); diff --git a/bindgen-tests/tests/expectations/tests/partial-specialization-and-inheritance.rs b/bindgen-tests/tests/expectations/tests/partial-specialization-and-inheritance.rs index 3ba3a82aa3..bb28bffcae 100644 --- a/bindgen-tests/tests/expectations/tests/partial-specialization-and-inheritance.rs +++ b/bindgen-tests/tests/expectations/tests/partial-specialization-and-inheritance.rs @@ -18,16 +18,7 @@ extern "C" { #[link_name = "\u{1}_ZN5Usage13static_memberE"] pub static mut Usage_static_member: [u32; 2usize]; } -#[test] -fn bindgen_test_layout_Usage() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Usage)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Usage)), - ); -} +const _: () = { + ["Size of Usage"][::std::mem::size_of::() - 1usize]; + ["Alignment of Usage"][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/private.rs b/bindgen-tests/tests/expectations/tests/private.rs index 2d37e95e35..86d0120e04 100644 --- a/bindgen-tests/tests/expectations/tests/private.rs +++ b/bindgen-tests/tests/expectations/tests/private.rs @@ -6,41 +6,16 @@ pub struct HasPrivate { ///
mIsPrivate: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_HasPrivate() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(HasPrivate)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(HasPrivate)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mNotPrivate) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(HasPrivate), - "::", - stringify!(mNotPrivate), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mIsPrivate) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(HasPrivate), - "::", - stringify!(mIsPrivate), - ), - ); -} +const _: () = { + ["Size of HasPrivate"][::std::mem::size_of::() - 8usize]; + ["Alignment of HasPrivate"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: HasPrivate::mNotPrivate", + ][::std::mem::offset_of!(HasPrivate, mNotPrivate) - 0usize]; + [ + "Offset of field: HasPrivate::mIsPrivate", + ][::std::mem::offset_of!(HasPrivate, mIsPrivate) - 4usize]; +}; ///
#[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -48,41 +23,16 @@ pub struct VeryPrivate { mIsPrivate: ::std::os::raw::c_int, mIsAlsoPrivate: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_VeryPrivate() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(VeryPrivate)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(VeryPrivate)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mIsPrivate) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(VeryPrivate), - "::", - stringify!(mIsPrivate), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mIsAlsoPrivate) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(VeryPrivate), - "::", - stringify!(mIsAlsoPrivate), - ), - ); -} +const _: () = { + ["Size of VeryPrivate"][::std::mem::size_of::() - 8usize]; + ["Alignment of VeryPrivate"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: VeryPrivate::mIsPrivate", + ][::std::mem::offset_of!(VeryPrivate, mIsPrivate) - 0usize]; + [ + "Offset of field: VeryPrivate::mIsAlsoPrivate", + ][::std::mem::offset_of!(VeryPrivate, mIsAlsoPrivate) - 4usize]; +}; ///
#[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -91,38 +41,15 @@ pub struct ContradictPrivate { pub mNotPrivate: ::std::os::raw::c_int, mIsPrivate: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_ContradictPrivate() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(ContradictPrivate)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(ContradictPrivate)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mNotPrivate) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContradictPrivate), - "::", - stringify!(mNotPrivate), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mIsPrivate) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(ContradictPrivate), - "::", - stringify!(mIsPrivate), - ), - ); -} +const _: () = { + ["Size of ContradictPrivate"][::std::mem::size_of::() - 8usize]; + [ + "Alignment of ContradictPrivate", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: ContradictPrivate::mNotPrivate", + ][::std::mem::offset_of!(ContradictPrivate, mNotPrivate) - 0usize]; + [ + "Offset of field: ContradictPrivate::mIsPrivate", + ][::std::mem::offset_of!(ContradictPrivate, mIsPrivate) - 4usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/private_fields.rs b/bindgen-tests/tests/expectations/tests/private_fields.rs index cc54f2856f..88e4797c73 100644 --- a/bindgen-tests/tests/expectations/tests/private_fields.rs +++ b/bindgen-tests/tests/expectations/tests/private_fields.rs @@ -89,31 +89,12 @@ pub struct PubPriv { pub x: ::std::os::raw::c_int, y: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_PubPriv() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(PubPriv)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(PubPriv)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(PubPriv), "::", stringify!(x)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(PubPriv), "::", stringify!(y)), - ); -} +const _: () = { + ["Size of PubPriv"][::std::mem::size_of::() - 8usize]; + ["Alignment of PubPriv"][::std::mem::align_of::() - 4usize]; + ["Offset of field: PubPriv::x"][::std::mem::offset_of!(PubPriv, x) - 0usize]; + ["Offset of field: PubPriv::y"][::std::mem::offset_of!(PubPriv, y) - 4usize]; +}; #[repr(C)] #[repr(align(4))] #[derive(Debug, Default, Copy, Clone)] @@ -122,19 +103,12 @@ pub struct PrivateBitFields { _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub __bindgen_padding_0: [u8; 3usize], } -#[test] -fn bindgen_test_layout_PrivateBitFields() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(PrivateBitFields)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(PrivateBitFields)), - ); -} +const _: () = { + ["Size of PrivateBitFields"][::std::mem::size_of::() - 4usize]; + [ + "Alignment of PrivateBitFields", + ][::std::mem::align_of::() - 4usize]; +}; impl PrivateBitFields { #[inline] fn a(&self) -> ::std::os::raw::c_uint { @@ -193,19 +167,10 @@ pub struct PublicBitFields { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub __bindgen_padding_0: [u8; 3usize], } -#[test] -fn bindgen_test_layout_PublicBitFields() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(PublicBitFields)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(PublicBitFields)), - ); -} +const _: () = { + ["Size of PublicBitFields"][::std::mem::size_of::() - 4usize]; + ["Alignment of PublicBitFields"][::std::mem::align_of::() - 4usize]; +}; impl PublicBitFields { #[inline] pub fn a(&self) -> ::std::os::raw::c_uint { @@ -264,19 +229,10 @@ pub struct MixedBitFields { _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub __bindgen_padding_0: [u8; 3usize], } -#[test] -fn bindgen_test_layout_MixedBitFields() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(MixedBitFields)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(MixedBitFields)), - ); -} +const _: () = { + ["Size of MixedBitFields"][::std::mem::size_of::() - 4usize]; + ["Alignment of MixedBitFields"][::std::mem::align_of::() - 4usize]; +}; impl MixedBitFields { #[inline] fn a(&self) -> ::std::os::raw::c_uint { @@ -332,62 +288,33 @@ impl MixedBitFields { pub struct Base { pub member: ::std::os::raw::c_int, } -#[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::(), - 4usize, - concat!("Size of: ", stringify!(Base)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Base)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Base), "::", stringify!(member)), - ); -} +const _: () = { + ["Size of Base"][::std::mem::size_of::() - 4usize]; + ["Alignment of Base"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Base::member"][::std::mem::offset_of!(Base, member) - 0usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct InheritsPrivately { _base: Base, } -#[test] -fn bindgen_test_layout_InheritsPrivately() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(InheritsPrivately)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(InheritsPrivately)), - ); -} +const _: () = { + ["Size of InheritsPrivately"][::std::mem::size_of::() - 4usize]; + [ + "Alignment of InheritsPrivately", + ][::std::mem::align_of::() - 4usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct InheritsPublically { pub _base: Base, } -#[test] -fn bindgen_test_layout_InheritsPublically() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(InheritsPublically)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(InheritsPublically)), - ); -} +const _: () = { + ["Size of InheritsPublically"][::std::mem::size_of::() - 4usize]; + [ + "Alignment of InheritsPublically", + ][::std::mem::align_of::() - 4usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct WithAnonStruct { @@ -399,74 +326,37 @@ pub struct WithAnonStruct { pub struct WithAnonStruct__bindgen_ty_1 { pub a: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_WithAnonStruct__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(WithAnonStruct__bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithAnonStruct__bindgen_ty_1)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithAnonStruct__bindgen_ty_1), - "::", - stringify!(a), - ), - ); -} +const _: () = { + [ + "Size of WithAnonStruct__bindgen_ty_1", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of WithAnonStruct__bindgen_ty_1", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: WithAnonStruct__bindgen_ty_1::a", + ][::std::mem::offset_of!(WithAnonStruct__bindgen_ty_1, a) - 0usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct WithAnonStruct__bindgen_ty_2 { pub b: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_WithAnonStruct__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(WithAnonStruct__bindgen_ty_2)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithAnonStruct__bindgen_ty_2)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithAnonStruct__bindgen_ty_2), - "::", - stringify!(b), - ), - ); -} -#[test] -fn bindgen_test_layout_WithAnonStruct() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(WithAnonStruct)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithAnonStruct)), - ); -} +const _: () = { + [ + "Size of WithAnonStruct__bindgen_ty_2", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of WithAnonStruct__bindgen_ty_2", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: WithAnonStruct__bindgen_ty_2::b", + ][::std::mem::offset_of!(WithAnonStruct__bindgen_ty_2, b) - 0usize]; +}; +const _: () = { + ["Size of WithAnonStruct"][::std::mem::size_of::() - 8usize]; + ["Alignment of WithAnonStruct"][::std::mem::align_of::() - 4usize]; +}; #[repr(C)] #[derive(Copy, Clone)] pub struct WithAnonUnion { @@ -477,19 +367,14 @@ pub struct WithAnonUnion { pub union WithAnonUnion__bindgen_ty_1 { pub _address: u8, } -#[test] -fn bindgen_test_layout_WithAnonUnion__bindgen_ty_1() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(WithAnonUnion__bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(WithAnonUnion__bindgen_ty_1)), - ); -} +const _: () = { + [ + "Size of WithAnonUnion__bindgen_ty_1", + ][::std::mem::size_of::() - 1usize]; + [ + "Alignment of WithAnonUnion__bindgen_ty_1", + ][::std::mem::align_of::() - 1usize]; +}; impl Default for WithAnonUnion__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -499,19 +384,10 @@ impl Default for WithAnonUnion__bindgen_ty_1 { } } } -#[test] -fn bindgen_test_layout_WithAnonUnion() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(WithAnonUnion)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(WithAnonUnion)), - ); -} +const _: () = { + ["Size of WithAnonUnion"][::std::mem::size_of::() - 1usize]; + ["Alignment of WithAnonUnion"][::std::mem::align_of::() - 1usize]; +}; impl Default for WithAnonUnion { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -532,36 +408,15 @@ pub struct Override { _bitfield_1: __BindgenBitfieldUnit<[u8; 2usize]>, pub __bindgen_padding_0: u16, } -#[test] -fn bindgen_test_layout_Override() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(Override)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Override)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Override), "::", stringify!(a)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(Override), "::", stringify!(b)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).private_c) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(Override), "::", stringify!(private_c)), - ); -} +const _: () = { + ["Size of Override"][::std::mem::size_of::() - 16usize]; + ["Alignment of Override"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Override::a"][::std::mem::offset_of!(Override, a) - 0usize]; + ["Offset of field: Override::b"][::std::mem::offset_of!(Override, b) - 4usize]; + [ + "Offset of field: Override::private_c", + ][::std::mem::offset_of!(Override, private_c) - 8usize]; +}; impl Override { #[inline] pub fn bf_a(&self) -> ::std::os::raw::c_uint { diff --git a/bindgen-tests/tests/expectations/tests/ptr32-has-different-size.rs b/bindgen-tests/tests/expectations/tests/ptr32-has-different-size.rs index bdcc170af7..d03d66f1a4 100644 --- a/bindgen-tests/tests/expectations/tests/ptr32-has-different-size.rs +++ b/bindgen-tests/tests/expectations/tests/ptr32-has-different-size.rs @@ -4,31 +4,13 @@ pub struct TEST_STRUCT { pub ptr_32bit: u32, } -#[test] -fn bindgen_test_layout_TEST_STRUCT() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(TEST_STRUCT)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(TEST_STRUCT)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ptr_32bit) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(TEST_STRUCT), - "::", - stringify!(ptr_32bit), - ), - ); -} +const _: () = { + ["Size of TEST_STRUCT"][::std::mem::size_of::() - 4usize]; + ["Alignment of TEST_STRUCT"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: TEST_STRUCT::ptr_32bit", + ][::std::mem::offset_of!(TEST_STRUCT, ptr_32bit) - 0usize]; +}; impl Default for TEST_STRUCT { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/public-dtor.rs b/bindgen-tests/tests/expectations/tests/public-dtor.rs index ad0ae6d919..fc9e85ced0 100644 --- a/bindgen-tests/tests/expectations/tests/public-dtor.rs +++ b/bindgen-tests/tests/expectations/tests/public-dtor.rs @@ -4,19 +4,10 @@ pub struct cv_Foo { pub _address: u8, } -#[test] -fn bindgen_test_layout_cv_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(cv_Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(cv_Foo)), - ); -} +const _: () = { + ["Size of cv_Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of cv_Foo"][::std::mem::align_of::() - 1usize]; +}; extern "C" { #[link_name = "\u{1}_ZN2cv3FooD1Ev"] pub fn cv_Foo_Foo_destructor(this: *mut cv_Foo); @@ -32,16 +23,7 @@ impl cv_Foo { pub struct cv_Bar { pub _address: u8, } -#[test] -fn bindgen_test_layout_cv_Bar() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(cv_Bar)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(cv_Bar)), - ); -} +const _: () = { + ["Size of cv_Bar"][::std::mem::size_of::() - 1usize]; + ["Alignment of cv_Bar"][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/redundant-packed-and-align.rs b/bindgen-tests/tests/expectations/tests/redundant-packed-and-align.rs index b5feaa140a..f4f2b95408 100644 --- a/bindgen-tests/tests/expectations/tests/redundant-packed-and-align.rs +++ b/bindgen-tests/tests/expectations/tests/redundant-packed-and-align.rs @@ -90,31 +90,18 @@ pub struct redundant_packed { pub a: u32, pub b: u32, } -#[test] -fn bindgen_test_layout_redundant_packed() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(redundant_packed)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(redundant_packed)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(redundant_packed), "::", stringify!(a)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(redundant_packed), "::", stringify!(b)), - ); -} +const _: () = { + ["Size of redundant_packed"][::std::mem::size_of::() - 8usize]; + [ + "Alignment of redundant_packed", + ][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: redundant_packed::a", + ][::std::mem::offset_of!(redundant_packed, a) - 0usize]; + [ + "Offset of field: redundant_packed::b", + ][::std::mem::offset_of!(redundant_packed, b) - 4usize]; +}; #[repr(C)] #[repr(align(8))] #[derive(Debug, Default, Copy, Clone)] @@ -124,41 +111,20 @@ pub struct redundant_packed_bitfield { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub c: u32, } -#[test] -fn bindgen_test_layout_redundant_packed_bitfield() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(redundant_packed_bitfield)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(redundant_packed_bitfield)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(redundant_packed_bitfield), - "::", - stringify!(a), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(redundant_packed_bitfield), - "::", - stringify!(c), - ), - ); -} +const _: () = { + [ + "Size of redundant_packed_bitfield", + ][::std::mem::size_of::() - 8usize]; + [ + "Alignment of redundant_packed_bitfield", + ][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: redundant_packed_bitfield::a", + ][::std::mem::offset_of!(redundant_packed_bitfield, a) - 0usize]; + [ + "Offset of field: redundant_packed_bitfield::c", + ][::std::mem::offset_of!(redundant_packed_bitfield, c) - 4usize]; +}; impl redundant_packed_bitfield { #[inline] pub fn b0(&self) -> u8 { @@ -213,41 +179,20 @@ pub union redundant_packed_union { pub a: u64, pub b: u32, } -#[test] -fn bindgen_test_layout_redundant_packed_union() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(redundant_packed_union)), - ); - assert_eq!( - ::std::mem::align_of::(), - 16usize, - concat!("Alignment of ", stringify!(redundant_packed_union)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(redundant_packed_union), - "::", - stringify!(a), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(redundant_packed_union), - "::", - stringify!(b), - ), - ); -} +const _: () = { + [ + "Size of redundant_packed_union", + ][::std::mem::size_of::() - 16usize]; + [ + "Alignment of redundant_packed_union", + ][::std::mem::align_of::() - 16usize]; + [ + "Offset of field: redundant_packed_union::a", + ][::std::mem::offset_of!(redundant_packed_union, a) - 0usize]; + [ + "Offset of field: redundant_packed_union::b", + ][::std::mem::offset_of!(redundant_packed_union, b) - 0usize]; +}; impl Default for redundant_packed_union { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -263,26 +208,11 @@ impl Default for redundant_packed_union { pub struct inner { pub a: u8, } -#[test] -fn bindgen_test_layout_inner() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 2usize, - concat!("Size of: ", stringify!(inner)), - ); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(inner)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(inner), "::", stringify!(a)), - ); -} +const _: () = { + ["Size of inner"][::std::mem::size_of::() - 2usize]; + ["Alignment of inner"][::std::mem::align_of::() - 2usize]; + ["Offset of field: inner::a"][::std::mem::offset_of!(inner, a) - 0usize]; +}; #[repr(C)] #[repr(align(8))] #[derive(Debug, Default, Copy, Clone)] @@ -290,41 +220,20 @@ pub struct outer_redundant_packed { pub a: [inner; 2usize], pub b: u32, } -#[test] -fn bindgen_test_layout_outer_redundant_packed() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(outer_redundant_packed)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(outer_redundant_packed)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(outer_redundant_packed), - "::", - stringify!(a), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(outer_redundant_packed), - "::", - stringify!(b), - ), - ); -} +const _: () = { + [ + "Size of outer_redundant_packed", + ][::std::mem::size_of::() - 8usize]; + [ + "Alignment of outer_redundant_packed", + ][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: outer_redundant_packed::a", + ][::std::mem::offset_of!(outer_redundant_packed, a) - 0usize]; + [ + "Offset of field: outer_redundant_packed::b", + ][::std::mem::offset_of!(outer_redundant_packed, b) - 4usize]; +}; #[repr(C)] #[repr(align(4))] #[derive(Debug, Default, Copy, Clone)] @@ -332,38 +241,17 @@ pub struct redundant_pragma_packed { pub a: u8, pub b: u16, } -#[test] -fn bindgen_test_layout_redundant_pragma_packed() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(redundant_pragma_packed)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(redundant_pragma_packed)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(redundant_pragma_packed), - "::", - stringify!(a), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(redundant_pragma_packed), - "::", - stringify!(b), - ), - ); -} +const _: () = { + [ + "Size of redundant_pragma_packed", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of redundant_pragma_packed", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: redundant_pragma_packed::a", + ][::std::mem::offset_of!(redundant_pragma_packed, a) - 0usize]; + [ + "Offset of field: redundant_pragma_packed::b", + ][::std::mem::offset_of!(redundant_pragma_packed, b) - 2usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/ref_argument_array.rs b/bindgen-tests/tests/expectations/tests/ref_argument_array.rs index 0ca31312fe..855fdec6ed 100644 --- a/bindgen-tests/tests/expectations/tests/ref_argument_array.rs +++ b/bindgen-tests/tests/expectations/tests/ref_argument_array.rs @@ -12,19 +12,10 @@ pub struct nsID__bindgen_vtable { pub struct nsID { pub vtable_: *const nsID__bindgen_vtable, } -#[test] -fn bindgen_test_layout_nsID() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(nsID)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(nsID)), - ); -} +const _: () = { + ["Size of nsID"][::std::mem::size_of::() - 8usize]; + ["Alignment of nsID"][::std::mem::align_of::() - 8usize]; +}; impl Default for nsID { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/reparented_replacement.rs b/bindgen-tests/tests/expectations/tests/reparented_replacement.rs index f2f70482eb..48ad6f3f5b 100644 --- a/bindgen-tests/tests/expectations/tests/reparented_replacement.rs +++ b/bindgen-tests/tests/expectations/tests/reparented_replacement.rs @@ -12,26 +12,11 @@ pub mod root { pub struct Bar { pub bazz: ::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, - concat!("Size of: ", stringify!(Bar)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Bar)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bazz) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(bazz)), - ); - } + const _: () = { + ["Size of Bar"][::std::mem::size_of::() - 4usize]; + ["Alignment of Bar"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Bar::bazz"][::std::mem::offset_of!(Bar, bazz) - 0usize]; + }; } pub type ReferencesBar = root::foo::Bar; } diff --git a/bindgen-tests/tests/expectations/tests/replace_use.rs b/bindgen-tests/tests/expectations/tests/replace_use.rs index b21fd03cac..d7d4e33536 100644 --- a/bindgen-tests/tests/expectations/tests/replace_use.rs +++ b/bindgen-tests/tests/expectations/tests/replace_use.rs @@ -10,36 +10,16 @@ pub struct nsTArray { pub struct Test { pub a: nsTArray, } -#[test] -fn bindgen_test_layout_Test() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Test)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Test)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(a)), - ); -} -#[test] -fn __bindgen_test_layout_nsTArray_open0_long_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of template specialization: ", stringify!(nsTArray)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of template specialization: ", stringify!(nsTArray)), - ); -} +const _: () = { + ["Size of Test"][::std::mem::size_of::() - 4usize]; + ["Alignment of Test"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Test::a"][::std::mem::offset_of!(Test, a) - 0usize]; +}; +const _: () = { + [ + "Size of template specialization: nsTArray_open0_long_close0", + ][::std::mem::size_of::() - 4usize]; + [ + "Align of template specialization: nsTArray_open0_long_close0", + ][::std::mem::align_of::() - 4usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/repr-align.rs b/bindgen-tests/tests/expectations/tests/repr-align.rs index b8a7f1e6ea..6afc0ba859 100644 --- a/bindgen-tests/tests/expectations/tests/repr-align.rs +++ b/bindgen-tests/tests/expectations/tests/repr-align.rs @@ -11,21 +11,17 @@ pub struct a { 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, concat!("Size of: ", stringify!(a))); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(a)), - ); + 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, - concat!("Offset of field: ", stringify!(a), "::", stringify!(b)), + "Offset of field: a::b", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(a), "::", stringify!(c)), + "Offset of field: a::c", ); } #[repr(C)] @@ -39,20 +35,16 @@ pub struct b { 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, concat!("Size of: ", stringify!(b))); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(b)), - ); + 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, - concat!("Offset of field: ", stringify!(b), "::", stringify!(b)), + "Offset of field: b::b", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(b), "::", stringify!(c)), + "Offset of field: b::c", ); } diff --git a/bindgen-tests/tests/expectations/tests/same_struct_name_in_different_namespaces.rs b/bindgen-tests/tests/expectations/tests/same_struct_name_in_different_namespaces.rs index cbdea272aa..9fb546fc0c 100644 --- a/bindgen-tests/tests/expectations/tests/same_struct_name_in_different_namespaces.rs +++ b/bindgen-tests/tests/expectations/tests/same_struct_name_in_different_namespaces.rs @@ -10,28 +10,13 @@ pub struct JS_shadow_Zone { pub x: ::std::os::raw::c_int, pub y: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_JS_shadow_Zone() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(JS_shadow_Zone)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(JS_shadow_Zone)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(JS_shadow_Zone), "::", stringify!(x)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(JS_shadow_Zone), "::", stringify!(y)), - ); -} +const _: () = { + ["Size of JS_shadow_Zone"][::std::mem::size_of::() - 8usize]; + ["Alignment of JS_shadow_Zone"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: JS_shadow_Zone::x", + ][::std::mem::offset_of!(JS_shadow_Zone, x) - 0usize]; + [ + "Offset of field: JS_shadow_Zone::y", + ][::std::mem::offset_of!(JS_shadow_Zone, y) - 4usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/sentry-defined-multiple-times.rs b/bindgen-tests/tests/expectations/tests/sentry-defined-multiple-times.rs index b881d72dfd..0d9d3a47ef 100644 --- a/bindgen-tests/tests/expectations/tests/sentry-defined-multiple-times.rs +++ b/bindgen-tests/tests/expectations/tests/sentry-defined-multiple-times.rs @@ -21,85 +21,44 @@ pub mod root { pub struct sentry { pub i_am_plain_sentry: bool, } - #[test] - fn bindgen_test_layout_sentry() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(sentry)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(sentry)), - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).i_am_plain_sentry) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(sentry), - "::", - stringify!(i_am_plain_sentry), - ), - ); - } + const _: () = { + ["Size of sentry"][::std::mem::size_of::() - 1usize]; + ["Alignment of sentry"][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: sentry::i_am_plain_sentry", + ][::std::mem::offset_of!(sentry, i_am_plain_sentry) - 0usize]; + }; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct NotTemplateWrapper { pub _address: u8, } - #[test] - fn bindgen_test_layout_NotTemplateWrapper() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(NotTemplateWrapper)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(NotTemplateWrapper)), - ); - } + const _: () = { + [ + "Size of NotTemplateWrapper", + ][::std::mem::size_of::() - 1usize]; + [ + "Alignment of NotTemplateWrapper", + ][::std::mem::align_of::() - 1usize]; + }; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct NotTemplateWrapper_sentry { pub i_am_not_template_wrapper_sentry: ::std::os::raw::c_char, } - #[test] - fn bindgen_test_layout_NotTemplateWrapper_sentry() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(NotTemplateWrapper_sentry)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(NotTemplateWrapper_sentry)), - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).i_am_not_template_wrapper_sentry) - as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(NotTemplateWrapper_sentry), - "::", - stringify!(i_am_not_template_wrapper_sentry), - ), - ); - } + const _: () = { + [ + "Size of NotTemplateWrapper_sentry", + ][::std::mem::size_of::() - 1usize]; + [ + "Alignment of NotTemplateWrapper_sentry", + ][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: NotTemplateWrapper_sentry::i_am_not_template_wrapper_sentry", + ][::std::mem::offset_of!( + NotTemplateWrapper_sentry, i_am_not_template_wrapper_sentry + ) - 0usize]; + }; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct InlineNotTemplateWrapper { @@ -110,47 +69,27 @@ pub mod root { pub struct InlineNotTemplateWrapper_sentry { pub i_am_inline_not_template_wrapper_sentry: bool, } - #[test] - fn bindgen_test_layout_InlineNotTemplateWrapper_sentry() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(InlineNotTemplateWrapper_sentry)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(InlineNotTemplateWrapper_sentry)), - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).i_am_inline_not_template_wrapper_sentry) - as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(InlineNotTemplateWrapper_sentry), - "::", - stringify!(i_am_inline_not_template_wrapper_sentry), - ), - ); - } - #[test] - fn bindgen_test_layout_InlineNotTemplateWrapper() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(InlineNotTemplateWrapper)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(InlineNotTemplateWrapper)), - ); - } + const _: () = { + [ + "Size of InlineNotTemplateWrapper_sentry", + ][::std::mem::size_of::() - 1usize]; + [ + "Alignment of InlineNotTemplateWrapper_sentry", + ][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: InlineNotTemplateWrapper_sentry::i_am_inline_not_template_wrapper_sentry", + ][::std::mem::offset_of!( + InlineNotTemplateWrapper_sentry, i_am_inline_not_template_wrapper_sentry + ) - 0usize]; + }; + const _: () = { + [ + "Size of InlineNotTemplateWrapper", + ][::std::mem::size_of::() - 1usize]; + [ + "Alignment of InlineNotTemplateWrapper", + ][::std::mem::align_of::() - 1usize]; + }; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct InlineTemplateWrapper { @@ -171,76 +110,42 @@ pub mod root { pub struct OuterDoubleWrapper_InnerDoubleWrapper { pub _address: u8, } - #[test] - fn bindgen_test_layout_OuterDoubleWrapper_InnerDoubleWrapper() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(OuterDoubleWrapper_InnerDoubleWrapper)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!( - "Alignment of ", - stringify!(OuterDoubleWrapper_InnerDoubleWrapper), - ), - ); - } - #[test] - fn bindgen_test_layout_OuterDoubleWrapper() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(OuterDoubleWrapper)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(OuterDoubleWrapper)), - ); - } + const _: () = { + [ + "Size of OuterDoubleWrapper_InnerDoubleWrapper", + ][::std::mem::size_of::() - 1usize]; + [ + "Alignment of OuterDoubleWrapper_InnerDoubleWrapper", + ][::std::mem::align_of::() - 1usize]; + }; + const _: () = { + [ + "Size of OuterDoubleWrapper", + ][::std::mem::size_of::() - 1usize]; + [ + "Alignment of OuterDoubleWrapper", + ][::std::mem::align_of::() - 1usize]; + }; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct OuterDoubleWrapper_InnerDoubleWrapper_sentry { pub i_am_double_wrapper_sentry: ::std::os::raw::c_int, } - #[test] - fn bindgen_test_layout_OuterDoubleWrapper_InnerDoubleWrapper_sentry() { - const UNINIT: ::std::mem::MaybeUninit< - OuterDoubleWrapper_InnerDoubleWrapper_sentry, - > = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!( - "Size of: ", - stringify!(OuterDoubleWrapper_InnerDoubleWrapper_sentry), - ), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!( - "Alignment of ", - stringify!(OuterDoubleWrapper_InnerDoubleWrapper_sentry), - ), - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).i_am_double_wrapper_sentry) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(OuterDoubleWrapper_InnerDoubleWrapper_sentry), - "::", - stringify!(i_am_double_wrapper_sentry), - ), - ); - } + const _: () = { + [ + "Size of OuterDoubleWrapper_InnerDoubleWrapper_sentry", + ][::std::mem::size_of::() + - 4usize]; + [ + "Alignment of OuterDoubleWrapper_InnerDoubleWrapper_sentry", + ][::std::mem::align_of::() + - 4usize]; + [ + "Offset of field: OuterDoubleWrapper_InnerDoubleWrapper_sentry::i_am_double_wrapper_sentry", + ][::std::mem::offset_of!( + OuterDoubleWrapper_InnerDoubleWrapper_sentry, i_am_double_wrapper_sentry + ) - 0usize]; + }; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct OuterDoubleInlineWrapper { @@ -256,82 +161,42 @@ pub mod root { pub struct OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry { pub i_am_double_wrapper_inline_sentry: ::std::os::raw::c_int, } - #[test] - fn bindgen_test_layout_OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry() { - const UNINIT: ::std::mem::MaybeUninit< + const _: () = { + [ + "Size of OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry", + ][::std::mem::size_of::< OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry, - > = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::< - OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry, - >(), - 4usize, - concat!( - "Size of: ", - stringify!(OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry), - ), - ); - assert_eq!( - ::std::mem::align_of::< - OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry, - >(), - 4usize, - concat!( - "Alignment of ", - stringify!(OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry), - ), - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).i_am_double_wrapper_inline_sentry) - as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry), - "::", - stringify!(i_am_double_wrapper_inline_sentry), - ), - ); - } - #[test] - fn bindgen_test_layout_OuterDoubleInlineWrapper_InnerDoubleInlineWrapper() { - assert_eq!( - ::std::mem::size_of::< - OuterDoubleInlineWrapper_InnerDoubleInlineWrapper, - >(), - 1usize, - concat!( - "Size of: ", - stringify!(OuterDoubleInlineWrapper_InnerDoubleInlineWrapper), - ), - ); - assert_eq!( - ::std::mem::align_of::< - OuterDoubleInlineWrapper_InnerDoubleInlineWrapper, - >(), - 1usize, - concat!( - "Alignment of ", - stringify!(OuterDoubleInlineWrapper_InnerDoubleInlineWrapper), - ), - ); - } - #[test] - fn bindgen_test_layout_OuterDoubleInlineWrapper() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(OuterDoubleInlineWrapper)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(OuterDoubleInlineWrapper)), - ); - } + >() - 4usize]; + [ + "Alignment of OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry", + ][::std::mem::align_of::< + OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry, + >() - 4usize]; + [ + "Offset of field: OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry::i_am_double_wrapper_inline_sentry", + ][::std::mem::offset_of!( + OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry, + i_am_double_wrapper_inline_sentry + ) - 0usize]; + }; + const _: () = { + [ + "Size of OuterDoubleInlineWrapper_InnerDoubleInlineWrapper", + ][::std::mem::size_of::() + - 1usize]; + [ + "Alignment of OuterDoubleInlineWrapper_InnerDoubleInlineWrapper", + ][::std::mem::align_of::() + - 1usize]; + }; + const _: () = { + [ + "Size of OuterDoubleInlineWrapper", + ][::std::mem::size_of::() - 1usize]; + [ + "Alignment of OuterDoubleInlineWrapper", + ][::std::mem::align_of::() - 1usize]; + }; } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -348,32 +213,11 @@ pub mod root { pub struct sentry { pub i_am_outside_namespace_sentry: ::std::os::raw::c_int, } - #[test] - fn bindgen_test_layout_sentry() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(sentry)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(sentry)), - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).i_am_outside_namespace_sentry) as usize - - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(sentry), - "::", - stringify!(i_am_outside_namespace_sentry), - ), - ); - } + const _: () = { + ["Size of sentry"][::std::mem::size_of::() - 4usize]; + ["Alignment of sentry"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: sentry::i_am_outside_namespace_sentry", + ][::std::mem::offset_of!(sentry, i_am_outside_namespace_sentry) - 0usize]; + }; } diff --git a/bindgen-tests/tests/expectations/tests/size_t_template.rs b/bindgen-tests/tests/expectations/tests/size_t_template.rs index 3e37508b6a..7ca85c2ca1 100644 --- a/bindgen-tests/tests/expectations/tests/size_t_template.rs +++ b/bindgen-tests/tests/expectations/tests/size_t_template.rs @@ -4,19 +4,8 @@ pub struct C { pub arr: [u32; 3usize], } -#[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::(), 12usize, concat!("Size of: ", stringify!(C))); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(C)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(arr)), - ); -} +const _: () = { + ["Size of C"][::std::mem::size_of::() - 12usize]; + ["Alignment of C"][::std::mem::align_of::() - 4usize]; + ["Offset of field: C::arr"][::std::mem::offset_of!(C, arr) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/sorted_items.rs b/bindgen-tests/tests/expectations/tests/sorted_items.rs index e7da5e67fd..ab2a6dc27a 100644 --- a/bindgen-tests/tests/expectations/tests/sorted_items.rs +++ b/bindgen-tests/tests/expectations/tests/sorted_items.rs @@ -14,57 +14,19 @@ pub mod root { pub a: root::number, pub b: root::number, } + const _: () = { + ["Size of Point"][::std::mem::size_of::() - 8usize]; + ["Alignment of Point"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Point::x"][::std::mem::offset_of!(Point, x) - 0usize]; + ["Offset of field: Point::y"][::std::mem::offset_of!(Point, y) - 4usize]; + }; + const _: () = { + ["Size of Angle"][::std::mem::size_of::() - 8usize]; + ["Alignment of Angle"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Angle::a"][::std::mem::offset_of!(Angle, a) - 0usize]; + ["Offset of field: Angle::b"][::std::mem::offset_of!(Angle, b) - 4usize]; + }; pub const NUMBER: root::number = 42; - #[test] - fn bindgen_test_layout_Point() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Point)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Point)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Point), "::", stringify!(x)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(Point), "::", stringify!(y)), - ); - } - #[test] - fn bindgen_test_layout_Angle() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Angle)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Angle)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Angle), "::", stringify!(a)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(Angle), "::", stringify!(b)), - ); - } pub mod ns { pub type number = ::std::os::raw::c_int; #[repr(C)] @@ -79,57 +41,19 @@ pub mod root { pub a: root::ns::number, pub b: root::ns::number, } + const _: () = { + ["Size of Point"][::std::mem::size_of::() - 8usize]; + ["Alignment of Point"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Point::x"][::std::mem::offset_of!(Point, x) - 0usize]; + ["Offset of field: Point::y"][::std::mem::offset_of!(Point, y) - 4usize]; + }; + const _: () = { + ["Size of Angle"][::std::mem::size_of::() - 8usize]; + ["Alignment of Angle"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Angle::a"][::std::mem::offset_of!(Angle, a) - 0usize]; + ["Offset of field: Angle::b"][::std::mem::offset_of!(Angle, b) - 4usize]; + }; pub const NUMBER: root::ns::number = 42; - #[test] - fn bindgen_test_layout_Point() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Point)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Point)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Point), "::", stringify!(x)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(Point), "::", stringify!(y)), - ); - } - #[test] - fn bindgen_test_layout_Angle() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Angle)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Angle)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Angle), "::", stringify!(a)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(Angle), "::", stringify!(b)), - ); - } #[allow(unused_imports)] use self::super::super::root; extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/stdint_typedef.rs b/bindgen-tests/tests/expectations/tests/stdint_typedef.rs index 34c71831da..67c0ea5685 100644 --- a/bindgen-tests/tests/expectations/tests/stdint_typedef.rs +++ b/bindgen-tests/tests/expectations/tests/stdint_typedef.rs @@ -7,23 +7,8 @@ extern "C" { pub struct Struct { pub field: u64, } -#[test] -fn bindgen_test_layout_Struct() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Struct)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Struct)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).field) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Struct), "::", stringify!(field)), - ); -} +const _: () = { + ["Size of Struct"][::std::mem::size_of::() - 8usize]; + ["Alignment of Struct"][::std::mem::align_of::() - 8usize]; + ["Offset of field: Struct::field"][::std::mem::offset_of!(Struct, field) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/struct_containing_forward_declared_struct.rs b/bindgen-tests/tests/expectations/tests/struct_containing_forward_declared_struct.rs index 60c093c79a..39880f2f5a 100644 --- a/bindgen-tests/tests/expectations/tests/struct_containing_forward_declared_struct.rs +++ b/bindgen-tests/tests/expectations/tests/struct_containing_forward_declared_struct.rs @@ -4,22 +4,11 @@ pub struct a { pub val_a: *mut b, } -#[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, concat!("Size of: ", stringify!(a))); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(a)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).val_a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(a), "::", stringify!(val_a)), - ); -} +const _: () = { + ["Size of a"][::std::mem::size_of::() - 8usize]; + ["Alignment of a"][::std::mem::align_of::() - 8usize]; + ["Offset of field: a::val_a"][::std::mem::offset_of!(a, val_a) - 0usize]; +}; impl Default for a { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -34,19 +23,8 @@ impl Default for a { pub struct b { pub val_b: ::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::(), 4usize, concat!("Size of: ", stringify!(b))); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(b)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).val_b) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(b), "::", stringify!(val_b)), - ); -} +const _: () = { + ["Size of b"][::std::mem::size_of::() - 4usize]; + ["Alignment of b"][::std::mem::align_of::() - 4usize]; + ["Offset of field: b::val_b"][::std::mem::offset_of!(b, val_b) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/struct_typedef.rs b/bindgen-tests/tests/expectations/tests/struct_typedef.rs index 2c0039e3f0..efcea67c39 100644 --- a/bindgen-tests/tests/expectations/tests/struct_typedef.rs +++ b/bindgen-tests/tests/expectations/tests/struct_typedef.rs @@ -4,61 +4,29 @@ pub struct typedef_named_struct { pub has_name: bool, } -#[test] -fn bindgen_test_layout_typedef_named_struct() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(typedef_named_struct)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(typedef_named_struct)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).has_name) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(typedef_named_struct), - "::", - stringify!(has_name), - ), - ); -} +const _: () = { + [ + "Size of typedef_named_struct", + ][::std::mem::size_of::() - 1usize]; + [ + "Alignment of typedef_named_struct", + ][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: typedef_named_struct::has_name", + ][::std::mem::offset_of!(typedef_named_struct, has_name) - 0usize]; +}; #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct _bindgen_ty_1 { pub no_name: *mut ::std::os::raw::c_void, } -#[test] -fn bindgen_test_layout__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit<_bindgen_ty_1> = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::<_bindgen_ty_1>(), - 8usize, - concat!("Size of: ", stringify!(_bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::<_bindgen_ty_1>(), - 8usize, - concat!("Alignment of ", stringify!(_bindgen_ty_1)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).no_name) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(_bindgen_ty_1), - "::", - stringify!(no_name), - ), - ); -} +const _: () = { + ["Size of _bindgen_ty_1"][::std::mem::size_of::<_bindgen_ty_1>() - 8usize]; + ["Alignment of _bindgen_ty_1"][::std::mem::align_of::<_bindgen_ty_1>() - 8usize]; + [ + "Offset of field: _bindgen_ty_1::no_name", + ][::std::mem::offset_of!(_bindgen_ty_1, no_name) - 0usize]; +}; impl Default for _bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/struct_typedef_ns.rs b/bindgen-tests/tests/expectations/tests/struct_typedef_ns.rs index aabe23b18e..14091c9dc6 100644 --- a/bindgen-tests/tests/expectations/tests/struct_typedef_ns.rs +++ b/bindgen-tests/tests/expectations/tests/struct_typedef_ns.rs @@ -11,31 +11,15 @@ pub mod root { pub struct typedef_struct { pub foo: ::std::os::raw::c_int, } - #[test] - fn bindgen_test_layout_typedef_struct() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(typedef_struct)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(typedef_struct)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(typedef_struct), - "::", - stringify!(foo), - ), - ); - } + const _: () = { + ["Size of typedef_struct"][::std::mem::size_of::() - 4usize]; + [ + "Alignment of typedef_struct", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: typedef_struct::foo", + ][::std::mem::offset_of!(typedef_struct, foo) - 0usize]; + }; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum typedef_enum { @@ -50,31 +34,15 @@ pub mod root { pub struct typedef_struct { pub foo: ::std::os::raw::c_int, } - #[test] - fn bindgen_test_layout_typedef_struct() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(typedef_struct)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(typedef_struct)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(typedef_struct), - "::", - stringify!(foo), - ), - ); - } + const _: () = { + ["Size of typedef_struct"][::std::mem::size_of::() - 4usize]; + [ + "Alignment of typedef_struct", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: typedef_struct::foo", + ][::std::mem::offset_of!(typedef_struct, foo) - 0usize]; + }; #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum typedef_enum { diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_struct.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_struct.rs index d5ea2224b4..f279a61378 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_struct.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_anon_struct.rs @@ -10,48 +10,20 @@ pub struct foo__bindgen_ty_1 { pub a: ::std::os::raw::c_int, pub b: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)), - ); -} -#[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::(), - 8usize, - concat!("Size of: ", stringify!(foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)), - ); -} +const _: () = { + ["Size of foo__bindgen_ty_1"][::std::mem::size_of::() - 8usize]; + [ + "Alignment of foo__bindgen_ty_1", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: foo__bindgen_ty_1::a", + ][::std::mem::offset_of!(foo__bindgen_ty_1, a) - 0usize]; + [ + "Offset of field: foo__bindgen_ty_1::b", + ][::std::mem::offset_of!(foo__bindgen_ty_1, b) - 4usize]; +}; +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 8usize]; + ["Alignment of foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: foo::bar"][::std::mem::offset_of!(foo, bar) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_struct_array.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_struct_array.rs index ba3f82a86f..48fb6ac03e 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_struct_array.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_anon_struct_array.rs @@ -11,84 +11,39 @@ pub struct foo__bindgen_ty_1 { pub a: ::std::os::raw::c_int, pub b: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)), - ); -} +const _: () = { + ["Size of foo__bindgen_ty_1"][::std::mem::size_of::() - 8usize]; + [ + "Alignment of foo__bindgen_ty_1", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: foo__bindgen_ty_1::a", + ][::std::mem::offset_of!(foo__bindgen_ty_1, a) - 0usize]; + [ + "Offset of field: foo__bindgen_ty_1::b", + ][::std::mem::offset_of!(foo__bindgen_ty_1, b) - 4usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct foo__bindgen_ty_2 { pub a: ::std::os::raw::c_int, pub b: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_foo__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_2)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_2)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_2), "::", stringify!(a)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_2), "::", stringify!(b)), - ); -} -#[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::(), - 208usize, - concat!("Size of: ", stringify!(foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 16usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(baz)), - ); -} +const _: () = { + ["Size of foo__bindgen_ty_2"][::std::mem::size_of::() - 8usize]; + [ + "Alignment of foo__bindgen_ty_2", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: foo__bindgen_ty_2::a", + ][::std::mem::offset_of!(foo__bindgen_ty_2, a) - 0usize]; + [ + "Offset of field: foo__bindgen_ty_2::b", + ][::std::mem::offset_of!(foo__bindgen_ty_2, b) - 4usize]; +}; +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 208usize]; + ["Alignment of foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: foo::bar"][::std::mem::offset_of!(foo, bar) - 0usize]; + ["Offset of field: foo::baz"][::std::mem::offset_of!(foo, baz) - 16usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_struct_pointer.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_struct_pointer.rs index 77a89934b0..04b78064aa 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_struct_pointer.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_anon_struct_pointer.rs @@ -10,51 +10,23 @@ pub struct foo__bindgen_ty_1 { pub a: ::std::os::raw::c_int, pub b: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)), - ); -} -#[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::(), - 8usize, - concat!("Size of: ", stringify!(foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(foo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)), - ); -} +const _: () = { + ["Size of foo__bindgen_ty_1"][::std::mem::size_of::() - 8usize]; + [ + "Alignment of foo__bindgen_ty_1", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: foo__bindgen_ty_1::a", + ][::std::mem::offset_of!(foo__bindgen_ty_1, a) - 0usize]; + [ + "Offset of field: foo__bindgen_ty_1::b", + ][::std::mem::offset_of!(foo__bindgen_ty_1, b) - 4usize]; +}; +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 8usize]; + ["Alignment of foo"][::std::mem::align_of::() - 8usize]; + ["Offset of field: foo::bar"][::std::mem::offset_of!(foo, bar) - 0usize]; +}; impl Default for foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_union.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_union.rs index 506b6a8819..5cd95f777f 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_union.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_anon_union.rs @@ -10,31 +10,18 @@ pub union foo__bindgen_ty_1 { pub a: ::std::os::raw::c_uint, pub b: ::std::os::raw::c_ushort, } -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)), - ); -} +const _: () = { + ["Size of foo__bindgen_ty_1"][::std::mem::size_of::() - 4usize]; + [ + "Alignment of foo__bindgen_ty_1", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: foo__bindgen_ty_1::a", + ][::std::mem::offset_of!(foo__bindgen_ty_1, a) - 0usize]; + [ + "Offset of field: foo__bindgen_ty_1::b", + ][::std::mem::offset_of!(foo__bindgen_ty_1, b) - 0usize]; +}; impl Default for foo__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -44,26 +31,11 @@ impl Default for foo__bindgen_ty_1 { } } } -#[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::(), - 4usize, - concat!("Size of: ", stringify!(foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)), - ); -} +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 4usize]; + ["Alignment of foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: foo::bar"][::std::mem::offset_of!(foo, bar) - 0usize]; +}; impl Default for foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_union_1_0.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_union_1_0.rs index 8bab61e3b7..dda2d06eb8 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_anon_union_1_0.rs @@ -61,22 +61,22 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)), + "Size of foo__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)), + "Alignment of foo__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)), + "Offset of field: foo__bindgen_ty_1::a", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)), + "Offset of field: foo__bindgen_ty_1::b", ); } impl Clone for foo__bindgen_ty_1 { @@ -88,20 +88,12 @@ impl Clone for foo__bindgen_ty_1 { 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::(), - 4usize, - concat!("Size of: ", stringify!(foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)), - ); + assert_eq!(::std::mem::size_of::(), 4usize, "Size of foo"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of foo"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)), + "Offset of field: foo::bar", ); } impl Clone for foo { diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_struct.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_struct.rs index 981dd648be..4e4a3f2d74 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_struct.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_struct.rs @@ -10,41 +10,19 @@ pub struct foo__bindgen_ty_1 { pub a: ::std::os::raw::c_uint, pub b: ::std::os::raw::c_uint, } -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)), - ); -} -#[test] -fn bindgen_test_layout_foo() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)), - ); -} +const _: () = { + ["Size of foo__bindgen_ty_1"][::std::mem::size_of::() - 8usize]; + [ + "Alignment of foo__bindgen_ty_1", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: foo__bindgen_ty_1::a", + ][::std::mem::offset_of!(foo__bindgen_ty_1, a) - 0usize]; + [ + "Offset of field: foo__bindgen_ty_1::b", + ][::std::mem::offset_of!(foo__bindgen_ty_1, b) - 4usize]; +}; +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 8usize]; + ["Alignment of foo"][::std::mem::align_of::() - 4usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union.rs index 3d0175354f..325aa820bf 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union.rs @@ -10,31 +10,18 @@ pub union foo__bindgen_ty_1 { pub a: ::std::os::raw::c_uint, pub b: ::std::os::raw::c_ushort, } -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)), - ); -} +const _: () = { + ["Size of foo__bindgen_ty_1"][::std::mem::size_of::() - 4usize]; + [ + "Alignment of foo__bindgen_ty_1", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: foo__bindgen_ty_1::a", + ][::std::mem::offset_of!(foo__bindgen_ty_1, a) - 0usize]; + [ + "Offset of field: foo__bindgen_ty_1::b", + ][::std::mem::offset_of!(foo__bindgen_ty_1, b) - 0usize]; +}; impl Default for foo__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -44,19 +31,10 @@ impl Default for foo__bindgen_ty_1 { } } } -#[test] -fn bindgen_test_layout_foo() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)), - ); -} +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 4usize]; + ["Alignment of foo"][::std::mem::align_of::() - 4usize]; +}; impl Default for foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs index ae2ff33377..b9977c688b 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs @@ -61,22 +61,22 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)), + "Size of foo__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)), + "Alignment of foo__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)), + "Offset of field: foo__bindgen_ty_1::a", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)), + "Offset of field: foo__bindgen_ty_1::b", ); } impl Clone for foo__bindgen_ty_1 { @@ -86,16 +86,8 @@ impl Clone for foo__bindgen_ty_1 { } #[test] fn bindgen_test_layout_foo() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)), - ); + assert_eq!(::std::mem::size_of::(), 4usize, "Size of foo"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of foo"); } impl Clone for foo { fn clone(&self) -> Self { diff --git a/bindgen-tests/tests/expectations/tests/struct_with_bitfields.rs b/bindgen-tests/tests/expectations/tests/struct_with_bitfields.rs index 6a6b17e341..9ec90061b3 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_bitfields.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_bitfields.rs @@ -92,26 +92,11 @@ pub struct bitfield { pub _bitfield_align_2: [u32; 0], pub _bitfield_2: __BindgenBitfieldUnit<[u8; 8usize]>, } -#[test] -fn bindgen_test_layout_bitfield() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(bitfield)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(bitfield)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).e) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(bitfield), "::", stringify!(e)), - ); -} +const _: () = { + ["Size of bitfield"][::std::mem::size_of::() - 16usize]; + ["Alignment of bitfield"][::std::mem::align_of::() - 4usize]; + ["Offset of field: bitfield::e"][::std::mem::offset_of!(bitfield, e) - 4usize]; +}; impl bitfield { #[inline] pub fn a(&self) -> ::std::os::raw::c_ushort { 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 b84fa7b2c0..b472666081 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_derive_debug.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_derive_debug.rs @@ -8,20 +8,16 @@ pub struct LittleArray { 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, - concat!("Size of: ", stringify!(LittleArray)), - ); + assert_eq!(::std::mem::size_of::(), 128usize, "Size of LittleArray"); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(LittleArray)), + "Alignment of LittleArray", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(LittleArray), "::", stringify!(a)), + "Offset of field: LittleArray::a", ); } #[repr(C)] @@ -33,20 +29,12 @@ pub struct BigArray { 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, - concat!("Size of: ", stringify!(BigArray)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(BigArray)), - ); + 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, - concat!("Offset of field: ", stringify!(BigArray), "::", stringify!(a)), + "Offset of field: BigArray::a", ); } impl Default for BigArray { @@ -70,17 +58,17 @@ fn bindgen_test_layout_WithLittleArray() { assert_eq!( ::std::mem::size_of::(), 128usize, - concat!("Size of: ", stringify!(WithLittleArray)), + "Size of WithLittleArray", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(WithLittleArray)), + "Alignment of WithLittleArray", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(WithLittleArray), "::", stringify!(a)), + "Offset of field: WithLittleArray::a", ); } #[repr(C)] @@ -92,20 +80,16 @@ pub struct WithBigArray { 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, - concat!("Size of: ", stringify!(WithBigArray)), - ); + assert_eq!(::std::mem::size_of::(), 132usize, "Size of WithBigArray"); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(WithBigArray)), + "Alignment of WithBigArray", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(WithBigArray), "::", stringify!(a)), + "Offset of field: WithBigArray::a", ); } impl Default for WithBigArray { 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 a0d8cf0268..eda7cadb46 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_large_array.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_large_array.rs @@ -8,16 +8,12 @@ pub struct S { 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, concat!("Size of: ", stringify!(S))); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(S)), - ); + 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, - concat!("Offset of field: ", stringify!(S), "::", stringify!(large_array)), + "Offset of field: S::large_array", ); } impl Default for S { diff --git a/bindgen-tests/tests/expectations/tests/struct_with_nesting.rs b/bindgen-tests/tests/expectations/tests/struct_with_nesting.rs index 1bcba5a154..ec3a07f613 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_nesting.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_nesting.rs @@ -18,41 +18,20 @@ pub struct foo__bindgen_ty_1__bindgen_ty_1 { pub c1: ::std::os::raw::c_ushort, pub c2: ::std::os::raw::c_ushort, } -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c1) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(c1), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c2) as usize - ptr as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(c2), - ), - ); -} +const _: () = { + [ + "Size of foo__bindgen_ty_1__bindgen_ty_1", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of foo__bindgen_ty_1__bindgen_ty_1", + ][::std::mem::align_of::() - 2usize]; + [ + "Offset of field: foo__bindgen_ty_1__bindgen_ty_1::c1", + ][::std::mem::offset_of!(foo__bindgen_ty_1__bindgen_ty_1, c1) - 0usize]; + [ + "Offset of field: foo__bindgen_ty_1__bindgen_ty_1::c2", + ][::std::mem::offset_of!(foo__bindgen_ty_1__bindgen_ty_1, c2) - 2usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct foo__bindgen_ty_1__bindgen_ty_2 { @@ -61,81 +40,35 @@ pub struct foo__bindgen_ty_1__bindgen_ty_2 { pub d3: ::std::os::raw::c_uchar, pub d4: ::std::os::raw::c_uchar, } -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d1) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(d1), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d2) as usize - ptr as usize }, - 1usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(d2), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d3) as usize - ptr as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(d3), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d4) as usize - ptr as usize }, - 3usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(d4), - ), - ); -} -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)), - ); -} +const _: () = { + [ + "Size of foo__bindgen_ty_1__bindgen_ty_2", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of foo__bindgen_ty_1__bindgen_ty_2", + ][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: foo__bindgen_ty_1__bindgen_ty_2::d1", + ][::std::mem::offset_of!(foo__bindgen_ty_1__bindgen_ty_2, d1) - 0usize]; + [ + "Offset of field: foo__bindgen_ty_1__bindgen_ty_2::d2", + ][::std::mem::offset_of!(foo__bindgen_ty_1__bindgen_ty_2, d2) - 1usize]; + [ + "Offset of field: foo__bindgen_ty_1__bindgen_ty_2::d3", + ][::std::mem::offset_of!(foo__bindgen_ty_1__bindgen_ty_2, d3) - 2usize]; + [ + "Offset of field: foo__bindgen_ty_1__bindgen_ty_2::d4", + ][::std::mem::offset_of!(foo__bindgen_ty_1__bindgen_ty_2, d4) - 3usize]; +}; +const _: () = { + ["Size of foo__bindgen_ty_1"][::std::mem::size_of::() - 4usize]; + [ + "Alignment of foo__bindgen_ty_1", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: foo__bindgen_ty_1::b", + ][::std::mem::offset_of!(foo__bindgen_ty_1, b) - 0usize]; +}; impl Default for foo__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -145,26 +78,11 @@ impl Default for foo__bindgen_ty_1 { } } } -#[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::(), - 8usize, - concat!("Size of: ", stringify!(foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)), - ); -} +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 8usize]; + ["Alignment of foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: foo::a"][::std::mem::offset_of!(foo, a) - 0usize]; +}; impl Default for foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/struct_with_nesting_1_0.rs b/bindgen-tests/tests/expectations/tests/struct_with_nesting_1_0.rs index 6d8a5b97ae..0753326174 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_nesting_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_nesting_1_0.rs @@ -69,32 +69,22 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)), + "Size of foo__bindgen_ty_1__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 2usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)), + "Alignment of foo__bindgen_ty_1__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).c1) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(c1), - ), + "Offset of field: foo__bindgen_ty_1__bindgen_ty_1::c1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).c2) as usize - ptr as usize }, 2usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(c2), - ), + "Offset of field: foo__bindgen_ty_1__bindgen_ty_1::c2", ); } impl Clone for foo__bindgen_ty_1__bindgen_ty_1 { @@ -117,52 +107,32 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)), + "Size of foo__bindgen_ty_1__bindgen_ty_2", ); assert_eq!( ::std::mem::align_of::(), 1usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)), + "Alignment of foo__bindgen_ty_1__bindgen_ty_2", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).d1) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(d1), - ), + "Offset of field: foo__bindgen_ty_1__bindgen_ty_2::d1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).d2) as usize - ptr as usize }, 1usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(d2), - ), + "Offset of field: foo__bindgen_ty_1__bindgen_ty_2::d2", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).d3) as usize - ptr as usize }, 2usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(d3), - ), + "Offset of field: foo__bindgen_ty_1__bindgen_ty_2::d3", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).d4) as usize - ptr as usize }, 3usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(d4), - ), + "Offset of field: foo__bindgen_ty_1__bindgen_ty_2::d4", ); } impl Clone for foo__bindgen_ty_1__bindgen_ty_2 { @@ -177,17 +147,17 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)), + "Size of foo__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)), + "Alignment of foo__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)), + "Offset of field: foo__bindgen_ty_1::b", ); } impl Clone for foo__bindgen_ty_1 { @@ -199,20 +169,12 @@ impl Clone for foo__bindgen_ty_1 { 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::(), - 8usize, - concat!("Size of: ", stringify!(foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)), - ); + assert_eq!(::std::mem::size_of::(), 8usize, "Size of foo"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of foo"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)), + "Offset of field: foo::a", ); } impl Clone for foo { diff --git a/bindgen-tests/tests/expectations/tests/struct_with_packing.rs b/bindgen-tests/tests/expectations/tests/struct_with_packing.rs index 252756e86c..2d041a4678 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_packing.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_packing.rs @@ -5,24 +5,9 @@ pub struct a { pub b: ::std::os::raw::c_char, pub c: ::std::os::raw::c_short, } -#[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::(), 3usize, concat!("Size of: ", stringify!(a))); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(a)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(a), "::", stringify!(b)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, - 1usize, - concat!("Offset of field: ", stringify!(a), "::", stringify!(c)), - ); -} +const _: () = { + ["Size of a"][::std::mem::size_of::() - 3usize]; + ["Alignment of a"][::std::mem::align_of::() - 1usize]; + ["Offset of field: a::b"][::std::mem::offset_of!(a, b) - 0usize]; + ["Offset of field: a::c"][::std::mem::offset_of!(a, c) - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/struct_with_struct.rs b/bindgen-tests/tests/expectations/tests/struct_with_struct.rs index db6f32a57e..13bd782e87 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_struct.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_struct.rs @@ -10,48 +10,20 @@ pub struct foo__bindgen_ty_1 { pub x: ::std::os::raw::c_uint, pub y: ::std::os::raw::c_uint, } -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(x)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(y)), - ); -} -#[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::(), - 8usize, - concat!("Size of: ", stringify!(foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)), - ); -} +const _: () = { + ["Size of foo__bindgen_ty_1"][::std::mem::size_of::() - 8usize]; + [ + "Alignment of foo__bindgen_ty_1", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: foo__bindgen_ty_1::x", + ][::std::mem::offset_of!(foo__bindgen_ty_1, x) - 0usize]; + [ + "Offset of field: foo__bindgen_ty_1::y", + ][::std::mem::offset_of!(foo__bindgen_ty_1, y) - 4usize]; +}; +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 8usize]; + ["Alignment of foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: foo::bar"][::std::mem::offset_of!(foo, bar) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/template.rs b/bindgen-tests/tests/expectations/tests/template.rs index 6b8bd11e2b..13c9f0066e 100644 --- a/bindgen-tests/tests/expectations/tests/template.rs +++ b/bindgen-tests/tests/expectations/tests/template.rs @@ -60,108 +60,36 @@ pub struct C { pub mArrayRef: B<*mut [::std::os::raw::c_int; 1usize]>, pub mBConstArray: B<[::std::os::raw::c_int; 1usize]>, } -#[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::(), - 104usize, - concat!("Size of: ", stringify!(C)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(C)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mB) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(mB)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mBConstPtr) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(mBConstPtr)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mBConstStructPtr) as usize - ptr as usize }, - 16usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(mBConstStructPtr)), - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mBConstStructPtrArray) as usize - ptr as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(C), - "::", - stringify!(mBConstStructPtrArray), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mBConst) as usize - ptr as usize }, - 32usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(mBConst)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mBVolatile) as usize - ptr as usize }, - 36usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(mBVolatile)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mBConstBool) as usize - ptr as usize }, - 40usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(mBConstBool)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mBConstChar) as usize - ptr as usize }, - 42usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(mBConstChar)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mBArray) as usize - ptr as usize }, - 44usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(mBArray)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mBPtrArray) as usize - ptr as usize }, - 48usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(mBPtrArray)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mBArrayPtr) as usize - ptr as usize }, - 56usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(mBArrayPtr)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mBRef) as usize - ptr as usize }, - 64usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(mBRef)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mBConstRef) as usize - ptr as usize }, - 72usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(mBConstRef)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mPtrRef) as usize - ptr as usize }, - 80usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(mPtrRef)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mArrayRef) as usize - ptr as usize }, - 88usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(mArrayRef)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mBConstArray) as usize - ptr as usize }, - 96usize, - concat!("Offset of field: ", stringify!(C), "::", stringify!(mBConstArray)), - ); -} +const _: () = { + ["Size of C"][::std::mem::size_of::() - 104usize]; + ["Alignment of C"][::std::mem::align_of::() - 8usize]; + ["Offset of field: C::mB"][::std::mem::offset_of!(C, mB) - 0usize]; + ["Offset of field: C::mBConstPtr"][::std::mem::offset_of!(C, mBConstPtr) - 8usize]; + [ + "Offset of field: C::mBConstStructPtr", + ][::std::mem::offset_of!(C, mBConstStructPtr) - 16usize]; + [ + "Offset of field: C::mBConstStructPtrArray", + ][::std::mem::offset_of!(C, mBConstStructPtrArray) - 24usize]; + ["Offset of field: C::mBConst"][::std::mem::offset_of!(C, mBConst) - 32usize]; + ["Offset of field: C::mBVolatile"][::std::mem::offset_of!(C, mBVolatile) - 36usize]; + [ + "Offset of field: C::mBConstBool", + ][::std::mem::offset_of!(C, mBConstBool) - 40usize]; + [ + "Offset of field: C::mBConstChar", + ][::std::mem::offset_of!(C, mBConstChar) - 42usize]; + ["Offset of field: C::mBArray"][::std::mem::offset_of!(C, mBArray) - 44usize]; + ["Offset of field: C::mBPtrArray"][::std::mem::offset_of!(C, mBPtrArray) - 48usize]; + ["Offset of field: C::mBArrayPtr"][::std::mem::offset_of!(C, mBArrayPtr) - 56usize]; + ["Offset of field: C::mBRef"][::std::mem::offset_of!(C, mBRef) - 64usize]; + ["Offset of field: C::mBConstRef"][::std::mem::offset_of!(C, mBConstRef) - 72usize]; + ["Offset of field: C::mPtrRef"][::std::mem::offset_of!(C, mPtrRef) - 80usize]; + ["Offset of field: C::mArrayRef"][::std::mem::offset_of!(C, mArrayRef) - 88usize]; + [ + "Offset of field: C::mBConstArray", + ][::std::mem::offset_of!(C, mBConstArray) - 96usize]; +}; impl Default for C { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -224,26 +152,13 @@ impl Default for Rooted { pub struct RootedContainer { pub root: Rooted<*mut ::std::os::raw::c_void>, } -#[test] -fn bindgen_test_layout_RootedContainer() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 24usize, - concat!("Size of: ", stringify!(RootedContainer)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(RootedContainer)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).root) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(RootedContainer), "::", stringify!(root)), - ); -} +const _: () = { + ["Size of RootedContainer"][::std::mem::size_of::() - 24usize]; + ["Alignment of RootedContainer"][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: RootedContainer::root", + ][::std::mem::offset_of!(RootedContainer, root) - 0usize]; +}; impl Default for RootedContainer { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -274,31 +189,15 @@ impl Default for WithDtor { pub struct PODButContainsDtor { pub member: WithDtorIntFwd, } -#[test] -fn bindgen_test_layout_PODButContainsDtor() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(PODButContainsDtor)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(PODButContainsDtor)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).member) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(PODButContainsDtor), - "::", - stringify!(member), - ), - ); -} +const _: () = { + ["Size of PODButContainsDtor"][::std::mem::size_of::() - 4usize]; + [ + "Alignment of PODButContainsDtor", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: PODButContainsDtor::member", + ][::std::mem::offset_of!(PODButContainsDtor, member) - 0usize]; +}; impl Default for PODButContainsDtor { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -319,26 +218,13 @@ pub struct Opaque { pub struct POD { pub opaque_member: u32, } -#[test] -fn bindgen_test_layout_POD() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(POD)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(POD)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).opaque_member) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(POD), "::", stringify!(opaque_member)), - ); -} +const _: () = { + ["Size of POD"][::std::mem::size_of::() - 4usize]; + ["Alignment of POD"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: POD::opaque_member", + ][::std::mem::offset_of!(POD, opaque_member) - 0usize]; +}; ///
#[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] @@ -407,19 +293,10 @@ impl Default for Incomplete { pub struct Untemplated { pub _address: u8, } -#[test] -fn bindgen_test_layout_Untemplated() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Untemplated)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Untemplated)), - ); -} +const _: () = { + ["Size of Untemplated"][::std::mem::size_of::() - 1usize]; + ["Alignment of Untemplated"][::std::mem::align_of::() - 1usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct Templated { @@ -493,390 +370,171 @@ impl Default for ReplacedWithoutDestructorFwd { } } } -#[test] -fn __bindgen_test_layout_Foo_open0_int_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 24usize, - concat!( - "Size of template specialization: ", - stringify!(Foo < ::std::os::raw::c_int >), - ), - ); - assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(Foo < ::std::os::raw::c_int >), - ), - ); -} -#[test] -fn __bindgen_test_layout_B_open0_unsigned_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!( - "Size of template specialization: ", - stringify!(B < ::std::os::raw::c_uint >), - ), - ); - assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(B < ::std::os::raw::c_uint >), - ), - ); -} -#[test] -fn __bindgen_test_layout_B_open0_ptr_const_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 8usize, - concat!( - "Size of template specialization: ", - stringify!(B < * const ::std::os::raw::c_int >), - ), - ); - assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(B < * const ::std::os::raw::c_int >), - ), - ); -} -#[test] -fn __bindgen_test_layout_B_open0_ptr_const_mozilla__Foo_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 8usize, - concat!( - "Size of template specialization: ", - stringify!(B < * const mozilla_Foo >), - ), - ); - assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(B < * const mozilla_Foo >), - ), - ); -} -#[test] -fn __bindgen_test_layout_B_open0_array1_ptr_const_mozilla__Foo_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 8usize, - concat!( - "Size of template specialization: ", - stringify!(B < [* const mozilla_Foo; 1usize] >), - ), - ); - assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(B < [* const mozilla_Foo; 1usize] >), - ), - ); -} -#[test] -fn __bindgen_test_layout_B_open0_const_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!( - "Size of template specialization: ", - stringify!(B < ::std::os::raw::c_int >), - ), - ); - assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(B < ::std::os::raw::c_int >), - ), - ); -} -#[test] -fn __bindgen_test_layout_B_open0_volatile_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!( - "Size of template specialization: ", - stringify!(B < ::std::os::raw::c_int >), - ), - ); - assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(B < ::std::os::raw::c_int >), - ), - ); -} -#[test] -fn __bindgen_test_layout_B_open0_const_bool_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 1usize, - concat!("Size of template specialization: ", stringify!(B < bool >)), - ); - assert_eq!( - ::std::mem::align_of::>(), - 1usize, - concat!("Alignment of template specialization: ", stringify!(B < bool >)), - ); -} -#[test] -fn __bindgen_test_layout_B_open0_const_char16_t_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 2usize, - concat!("Size of template specialization: ", stringify!(B < u16 >)), - ); - assert_eq!( - ::std::mem::align_of::>(), - 2usize, - concat!("Alignment of template specialization: ", stringify!(B < u16 >)), - ); -} -#[test] -fn __bindgen_test_layout_B_open0_array1_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!( - "Size of template specialization: ", - stringify!(B < [::std::os::raw::c_int; 1usize] >), - ), - ); - assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(B < [::std::os::raw::c_int; 1usize] >), - ), - ); -} -#[test] -fn __bindgen_test_layout_B_open0_array1_ptr_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 8usize, - concat!( - "Size of template specialization: ", - stringify!(B < [* mut ::std::os::raw::c_int; 1usize] >), - ), - ); - assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(B < [* mut ::std::os::raw::c_int; 1usize] >), - ), - ); -} -#[test] -fn __bindgen_test_layout_B_open0_ptr_array1_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 8usize, - concat!( - "Size of template specialization: ", - stringify!(B < * mut [::std::os::raw::c_int; 1usize] >), - ), - ); - assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(B < * mut [::std::os::raw::c_int; 1usize] >), - ), - ); -} -#[test] -fn __bindgen_test_layout_B_open0_ref_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 8usize, - concat!( - "Size of template specialization: ", - stringify!(B < * mut ::std::os::raw::c_int >), - ), - ); - assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(B < * mut ::std::os::raw::c_int >), - ), - ); -} -#[test] -fn __bindgen_test_layout_B_open0_ref_const_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 8usize, - concat!( - "Size of template specialization: ", - stringify!(B < * const ::std::os::raw::c_int >), - ), - ); - assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(B < * const ::std::os::raw::c_int >), - ), - ); -} -#[test] -fn __bindgen_test_layout_B_open0_ref_ptr_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 8usize, - concat!( - "Size of template specialization: ", - stringify!(B < * mut * mut ::std::os::raw::c_int >), - ), - ); - assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(B < * mut * mut ::std::os::raw::c_int >), - ), - ); -} -#[test] -fn __bindgen_test_layout_B_open0_ref_array1_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 8usize, - concat!( - "Size of template specialization: ", - stringify!(B < * mut [::std::os::raw::c_int; 1usize] >), - ), - ); - assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(B < * mut [::std::os::raw::c_int; 1usize] >), - ), - ); -} -#[test] -fn __bindgen_test_layout_B_open0_array1_const_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!( - "Size of template specialization: ", - stringify!(B < [::std::os::raw::c_int; 1usize] >), - ), - ); - assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(B < [::std::os::raw::c_int; 1usize] >), - ), - ); -} -#[test] -fn __bindgen_test_layout_Foo_open0_int_int_close0_instantiation_1() { - assert_eq!( - ::std::mem::size_of::>(), - 24usize, - concat!( - "Size of template specialization: ", - stringify!(Foo < ::std::os::raw::c_int >), - ), - ); - assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(Foo < ::std::os::raw::c_int >), - ), - ); -} -#[test] -fn __bindgen_test_layout_Rooted_open0_ptr_void_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 24usize, - concat!( - "Size of template specialization: ", - stringify!(Rooted < * mut ::std::os::raw::c_void >), - ), - ); - assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(Rooted < * mut ::std::os::raw::c_void >), - ), - ); -} -#[test] -fn __bindgen_test_layout_Rooted_open0_ptr_void_close0_instantiation_1() { - assert_eq!( - ::std::mem::size_of::>(), - 24usize, - concat!( - "Size of template specialization: ", - stringify!(Rooted < * mut ::std::os::raw::c_void >), - ), - ); - assert_eq!( - ::std::mem::align_of::>(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(Rooted < * mut ::std::os::raw::c_void >), - ), - ); -} -#[test] -fn __bindgen_test_layout_WithDtor_open0_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!( - "Size of template specialization: ", - stringify!(WithDtor < ::std::os::raw::c_int >), - ), - ); - assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(WithDtor < ::std::os::raw::c_int >), - ), - ); -} +const _: () = { + [ + "Size of template specialization: Foo_open0_int_int_close0", + ][::std::mem::size_of::>() - 24usize]; + [ + "Align of template specialization: Foo_open0_int_int_close0", + ][::std::mem::align_of::>() - 8usize]; +}; +const _: () = { + [ + "Size of template specialization: B_open0_unsigned_int_close0", + ][::std::mem::size_of::>() - 4usize]; + [ + "Align of template specialization: B_open0_unsigned_int_close0", + ][::std::mem::align_of::>() - 4usize]; +}; +const _: () = { + [ + "Size of template specialization: B_open0_ptr_const_int_close0", + ][::std::mem::size_of::>() - 8usize]; + [ + "Align of template specialization: B_open0_ptr_const_int_close0", + ][::std::mem::align_of::>() - 8usize]; +}; +const _: () = { + [ + "Size of template specialization: B_open0_ptr_const_mozilla__Foo_close0", + ][::std::mem::size_of::>() - 8usize]; + [ + "Align of template specialization: B_open0_ptr_const_mozilla__Foo_close0", + ][::std::mem::align_of::>() - 8usize]; +}; +const _: () = { + [ + "Size of template specialization: B_open0_array1_ptr_const_mozilla__Foo_close0", + ][::std::mem::size_of::>() - 8usize]; + [ + "Align of template specialization: B_open0_array1_ptr_const_mozilla__Foo_close0", + ][::std::mem::align_of::>() - 8usize]; +}; +const _: () = { + [ + "Size of template specialization: B_open0_const_int_close0", + ][::std::mem::size_of::>() - 4usize]; + [ + "Align of template specialization: B_open0_const_int_close0", + ][::std::mem::align_of::>() - 4usize]; +}; +const _: () = { + [ + "Size of template specialization: B_open0_volatile_int_close0", + ][::std::mem::size_of::>() - 4usize]; + [ + "Align of template specialization: B_open0_volatile_int_close0", + ][::std::mem::align_of::>() - 4usize]; +}; +const _: () = { + [ + "Size of template specialization: B_open0_const_bool_close0", + ][::std::mem::size_of::>() - 1usize]; + [ + "Align of template specialization: B_open0_const_bool_close0", + ][::std::mem::align_of::>() - 1usize]; +}; +const _: () = { + [ + "Size of template specialization: B_open0_const_char16_t_close0", + ][::std::mem::size_of::>() - 2usize]; + [ + "Align of template specialization: B_open0_const_char16_t_close0", + ][::std::mem::align_of::>() - 2usize]; +}; +const _: () = { + [ + "Size of template specialization: B_open0_array1_int_close0", + ][::std::mem::size_of::>() - 4usize]; + [ + "Align of template specialization: B_open0_array1_int_close0", + ][::std::mem::align_of::>() - 4usize]; +}; +const _: () = { + [ + "Size of template specialization: B_open0_array1_ptr_int_close0", + ][::std::mem::size_of::>() - 8usize]; + [ + "Align of template specialization: B_open0_array1_ptr_int_close0", + ][::std::mem::align_of::>() - 8usize]; +}; +const _: () = { + [ + "Size of template specialization: B_open0_ptr_array1_int_close0", + ][::std::mem::size_of::>() - 8usize]; + [ + "Align of template specialization: B_open0_ptr_array1_int_close0", + ][::std::mem::align_of::>() - 8usize]; +}; +const _: () = { + [ + "Size of template specialization: B_open0_ref_int_close0", + ][::std::mem::size_of::>() - 8usize]; + [ + "Align of template specialization: B_open0_ref_int_close0", + ][::std::mem::align_of::>() - 8usize]; +}; +const _: () = { + [ + "Size of template specialization: B_open0_ref_const_int_close0", + ][::std::mem::size_of::>() - 8usize]; + [ + "Align of template specialization: B_open0_ref_const_int_close0", + ][::std::mem::align_of::>() - 8usize]; +}; +const _: () = { + [ + "Size of template specialization: B_open0_ref_ptr_int_close0", + ][::std::mem::size_of::>() - 8usize]; + [ + "Align of template specialization: B_open0_ref_ptr_int_close0", + ][::std::mem::align_of::>() - 8usize]; +}; +const _: () = { + [ + "Size of template specialization: B_open0_ref_array1_int_close0", + ][::std::mem::size_of::>() - 8usize]; + [ + "Align of template specialization: B_open0_ref_array1_int_close0", + ][::std::mem::align_of::>() - 8usize]; +}; +const _: () = { + [ + "Size of template specialization: B_open0_array1_const_int_close0", + ][::std::mem::size_of::>() - 4usize]; + [ + "Align of template specialization: B_open0_array1_const_int_close0", + ][::std::mem::align_of::>() - 4usize]; +}; +const _: () = { + [ + "Size of template specialization: Foo_open0_int_int_close0", + ][::std::mem::size_of::>() - 24usize]; + [ + "Align of template specialization: Foo_open0_int_int_close0", + ][::std::mem::align_of::>() - 8usize]; +}; +const _: () = { + [ + "Size of template specialization: Rooted_open0_ptr_void_close0", + ][::std::mem::size_of::>() - 24usize]; + [ + "Align of template specialization: Rooted_open0_ptr_void_close0", + ][::std::mem::align_of::>() - 8usize]; +}; +const _: () = { + [ + "Size of template specialization: Rooted_open0_ptr_void_close0", + ][::std::mem::size_of::>() - 24usize]; + [ + "Align of template specialization: Rooted_open0_ptr_void_close0", + ][::std::mem::align_of::>() - 8usize]; +}; +const _: () = { + [ + "Size of template specialization: WithDtor_open0_int_close0", + ][::std::mem::size_of::>() - 4usize]; + [ + "Align of template specialization: WithDtor_open0_int_close0", + ][::std::mem::align_of::>() - 4usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/template_instantiation_with_fn_local_type.rs b/bindgen-tests/tests/expectations/tests/template_instantiation_with_fn_local_type.rs index c6da8c26c7..f152f1ae8e 100644 --- a/bindgen-tests/tests/expectations/tests/template_instantiation_with_fn_local_type.rs +++ b/bindgen-tests/tests/expectations/tests/template_instantiation_with_fn_local_type.rs @@ -8,83 +8,46 @@ extern "C" { #[link_name = "\u{1}_Z1fv"] pub fn f(); } -#[test] -fn __bindgen_test_layout_Foo_open0_Bar_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of template specialization: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of template specialization: ", stringify!(Foo)), - ); -} +const _: () = { + [ + "Size of template specialization: Foo_open0_Bar_close0", + ][::std::mem::size_of::() - 1usize]; + [ + "Align of template specialization: Foo_open0_Bar_close0", + ][::std::mem::align_of::() - 1usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Baz { pub _address: u8, } -#[test] -fn bindgen_test_layout_Baz() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Baz)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Baz)), - ); -} -#[test] -fn __bindgen_test_layout_Foo_open0_Boo_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of template specialization: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of template specialization: ", stringify!(Foo)), - ); -} +const _: () = { + ["Size of Baz"][::std::mem::size_of::() - 1usize]; + ["Alignment of Baz"][::std::mem::align_of::() - 1usize]; +}; +const _: () = { + [ + "Size of template specialization: Foo_open0_Boo_close0", + ][::std::mem::size_of::() - 1usize]; + [ + "Align of template specialization: Foo_open0_Boo_close0", + ][::std::mem::align_of::() - 1usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Bar { pub _address: u8, } -#[test] -fn bindgen_test_layout_Bar() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Bar)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Bar)), - ); -} +const _: () = { + ["Size of Bar"][::std::mem::size_of::() - 1usize]; + ["Alignment of Bar"][::std::mem::align_of::() - 1usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Boo { pub _address: u8, } -#[test] -fn bindgen_test_layout_Boo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Boo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Boo)), - ); -} +const _: () = { + ["Size of Boo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Boo"][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/test_mixed_header_and_header_contents.rs b/bindgen-tests/tests/expectations/tests/test_mixed_header_and_header_contents.rs index 5f8da2affb..fe346d112f 100644 --- a/bindgen-tests/tests/expectations/tests/test_mixed_header_and_header_contents.rs +++ b/bindgen-tests/tests/expectations/tests/test_mixed_header_and_header_contents.rs @@ -31,84 +31,19 @@ pub struct Test { pub Ccu: UChar, pub Ccd: SChar, } -#[test] -fn bindgen_test_layout_Test() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 12usize, - concat!("Size of: ", stringify!(Test)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Test)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ch) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(ch)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize }, - 1usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(u)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 2usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(d)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).cch) as usize - ptr as usize }, - 3usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(cch)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).cu) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(cu)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).cd) as usize - ptr as usize }, - 5usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(cd)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).Cch) as usize - ptr as usize }, - 6usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cch)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).Cu) as usize - ptr as usize }, - 7usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cu)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).Cd) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cd)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).Ccch) as usize - ptr as usize }, - 9usize, - concat!( - "Offset of field: ", - stringify!(Test), - "::", - stringify!(Ccch) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).Ccu) as usize - ptr as usize }, - 10usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccu)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).Ccd) as usize - ptr as usize }, - 11usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccd)) - ); -} +const _: () = { + ["Size of Test"][::std::mem::size_of::() - 12usize]; + ["Alignment of Test"][::std::mem::align_of::() - 1usize]; + ["Offset of field: Test::ch"][::std::mem::offset_of!(Test, ch) - 0usize]; + ["Offset of field: Test::u"][::std::mem::offset_of!(Test, u) - 1usize]; + ["Offset of field: Test::d"][::std::mem::offset_of!(Test, d) - 2usize]; + ["Offset of field: Test::cch"][::std::mem::offset_of!(Test, cch) - 3usize]; + ["Offset of field: Test::cu"][::std::mem::offset_of!(Test, cu) - 4usize]; + ["Offset of field: Test::cd"][::std::mem::offset_of!(Test, cd) - 5usize]; + ["Offset of field: Test::Cch"][::std::mem::offset_of!(Test, Cch) - 6usize]; + ["Offset of field: Test::Cu"][::std::mem::offset_of!(Test, Cu) - 7usize]; + ["Offset of field: Test::Cd"][::std::mem::offset_of!(Test, Cd) - 8usize]; + ["Offset of field: Test::Ccch"][::std::mem::offset_of!(Test, Ccch) - 9usize]; + ["Offset of field: Test::Ccu"][::std::mem::offset_of!(Test, Ccu) - 10usize]; + ["Offset of field: Test::Ccd"][::std::mem::offset_of!(Test, Ccd) - 11usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/test_multiple_header_calls_in_builder.rs b/bindgen-tests/tests/expectations/tests/test_multiple_header_calls_in_builder.rs index b594d70c93..92122d1714 100644 --- a/bindgen-tests/tests/expectations/tests/test_multiple_header_calls_in_builder.rs +++ b/bindgen-tests/tests/expectations/tests/test_multiple_header_calls_in_builder.rs @@ -25,84 +25,19 @@ pub struct Test { pub Ccu: UChar, pub Ccd: SChar, } -#[test] -fn bindgen_test_layout_Test() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 12usize, - concat!("Size of: ", stringify!(Test)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Test)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ch) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(ch)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize }, - 1usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(u)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 2usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(d)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).cch) as usize - ptr as usize }, - 3usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(cch)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).cu) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(cu)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).cd) as usize - ptr as usize }, - 5usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(cd)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).Cch) as usize - ptr as usize }, - 6usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cch)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).Cu) as usize - ptr as usize }, - 7usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cu)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).Cd) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Cd)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).Ccch) as usize - ptr as usize }, - 9usize, - concat!( - "Offset of field: ", - stringify!(Test), - "::", - stringify!(Ccch) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).Ccu) as usize - ptr as usize }, - 10usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccu)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).Ccd) as usize - ptr as usize }, - 11usize, - concat!("Offset of field: ", stringify!(Test), "::", stringify!(Ccd)) - ); -} +const _: () = { + ["Size of Test"][::std::mem::size_of::() - 12usize]; + ["Alignment of Test"][::std::mem::align_of::() - 1usize]; + ["Offset of field: Test::ch"][::std::mem::offset_of!(Test, ch) - 0usize]; + ["Offset of field: Test::u"][::std::mem::offset_of!(Test, u) - 1usize]; + ["Offset of field: Test::d"][::std::mem::offset_of!(Test, d) - 2usize]; + ["Offset of field: Test::cch"][::std::mem::offset_of!(Test, cch) - 3usize]; + ["Offset of field: Test::cu"][::std::mem::offset_of!(Test, cu) - 4usize]; + ["Offset of field: Test::cd"][::std::mem::offset_of!(Test, cd) - 5usize]; + ["Offset of field: Test::Cch"][::std::mem::offset_of!(Test, Cch) - 6usize]; + ["Offset of field: Test::Cu"][::std::mem::offset_of!(Test, Cu) - 7usize]; + ["Offset of field: Test::Cd"][::std::mem::offset_of!(Test, Cd) - 8usize]; + ["Offset of field: Test::Ccch"][::std::mem::offset_of!(Test, Ccch) - 9usize]; + ["Offset of field: Test::Ccu"][::std::mem::offset_of!(Test, Ccu) - 10usize]; + ["Offset of field: Test::Ccd"][::std::mem::offset_of!(Test, Ccd) - 11usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/timex.rs b/bindgen-tests/tests/expectations/tests/timex.rs index 16bbae7607..cece8f099d 100644 --- a/bindgen-tests/tests/expectations/tests/timex.rs +++ b/bindgen-tests/tests/expectations/tests/timex.rs @@ -90,26 +90,11 @@ pub struct timex { pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 44usize]>, } -#[test] -fn bindgen_test_layout_timex() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 48usize, - concat!("Size of: ", stringify!(timex)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(timex)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).tai) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(timex), "::", stringify!(tai)), - ); -} +const _: () = { + ["Size of timex"][::std::mem::size_of::() - 48usize]; + ["Alignment of timex"][::std::mem::align_of::() - 4usize]; + ["Offset of field: timex::tai"][::std::mem::offset_of!(timex, tai) - 0usize]; +}; impl Default for timex { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -126,26 +111,13 @@ pub struct timex_named { pub _bitfield_align_1: [u32; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 44usize]>, } -#[test] -fn bindgen_test_layout_timex_named() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 48usize, - concat!("Size of: ", stringify!(timex_named)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(timex_named)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).tai) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(timex_named), "::", stringify!(tai)), - ); -} +const _: () = { + ["Size of timex_named"][::std::mem::size_of::() - 48usize]; + ["Alignment of timex_named"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: timex_named::tai", + ][::std::mem::offset_of!(timex_named, tai) - 0usize]; +}; impl Default for timex_named { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/transform-op.rs b/bindgen-tests/tests/expectations/tests/transform-op.rs index bd70711f47..b53cea166a 100644 --- a/bindgen-tests/tests/expectations/tests/transform-op.rs +++ b/bindgen-tests/tests/expectations/tests/transform-op.rs @@ -219,12 +219,12 @@ fn __bindgen_test_layout_StylePoint_open0_float_close0_instantiation() { assert_eq!( ::std::mem::size_of::>(), 8usize, - concat!("Size of template specialization: ", stringify!(StylePoint < f32 >)), + "Size of template specialization: StylePoint_open0_float_close0", ); assert_eq!( ::std::mem::align_of::>(), 4usize, - concat!("Alignment of template specialization: ", stringify!(StylePoint < f32 >)), + "Align of template specialization: StylePoint_open0_float_close0", ); } #[test] @@ -232,11 +232,11 @@ fn __bindgen_test_layout_StylePoint_open0_float_close0_instantiation_1() { assert_eq!( ::std::mem::size_of::>(), 8usize, - concat!("Size of template specialization: ", stringify!(StylePoint < f32 >)), + "Size of template specialization: StylePoint_open0_float_close0", ); assert_eq!( ::std::mem::align_of::>(), 4usize, - concat!("Alignment of template specialization: ", stringify!(StylePoint < f32 >)), + "Align of template specialization: StylePoint_open0_float_close0", ); } diff --git a/bindgen-tests/tests/expectations/tests/type-referenced-by-allowlisted-function.rs b/bindgen-tests/tests/expectations/tests/type-referenced-by-allowlisted-function.rs index 62ebce73fb..7d0973f994 100644 --- a/bindgen-tests/tests/expectations/tests/type-referenced-by-allowlisted-function.rs +++ b/bindgen-tests/tests/expectations/tests/type-referenced-by-allowlisted-function.rs @@ -4,26 +4,13 @@ pub struct dl_phdr_info { pub x: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_dl_phdr_info() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(dl_phdr_info)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(dl_phdr_info)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(dl_phdr_info), "::", stringify!(x)), - ); -} +const _: () = { + ["Size of dl_phdr_info"][::std::mem::size_of::() - 4usize]; + ["Alignment of dl_phdr_info"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: dl_phdr_info::x", + ][::std::mem::offset_of!(dl_phdr_info, x) - 0usize]; +}; extern "C" { pub fn dl_iterate_phdr(arg1: *mut dl_phdr_info) -> ::std::os::raw::c_int; } diff --git a/bindgen-tests/tests/expectations/tests/type_alias_template_specialized.rs b/bindgen-tests/tests/expectations/tests/type_alias_template_specialized.rs index d585a857d9..bcd6c43af7 100644 --- a/bindgen-tests/tests/expectations/tests/type_alias_template_specialized.rs +++ b/bindgen-tests/tests/expectations/tests/type_alias_template_specialized.rs @@ -4,26 +4,11 @@ pub struct Rooted { pub ptr: MaybeWrapped<::std::os::raw::c_int>, } -#[test] -fn bindgen_test_layout_Rooted() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(Rooted)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Rooted)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Rooted), "::", stringify!(ptr)), - ); -} +const _: () = { + ["Size of Rooted"][::std::mem::size_of::() - 4usize]; + ["Alignment of Rooted"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Rooted::ptr"][::std::mem::offset_of!(Rooted, ptr) - 0usize]; +}; impl Default for Rooted { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -35,22 +20,11 @@ impl Default for Rooted { } ///
pub type MaybeWrapped
= a; -#[test] -fn __bindgen_test_layout_MaybeWrapped_open0_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::>(), - 4usize, - concat!( - "Size of template specialization: ", - stringify!(MaybeWrapped < ::std::os::raw::c_int >), - ), - ); - assert_eq!( - ::std::mem::align_of::>(), - 4usize, - concat!( - "Alignment of template specialization: ", - stringify!(MaybeWrapped < ::std::os::raw::c_int >), - ), - ); -} +const _: () = { + [ + "Size of template specialization: MaybeWrapped_open0_int_close0", + ][::std::mem::size_of::>() - 4usize]; + [ + "Align of template specialization: MaybeWrapped_open0_int_close0", + ][::std::mem::align_of::>() - 4usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/typedef-pointer-overlap.rs b/bindgen-tests/tests/expectations/tests/typedef-pointer-overlap.rs index 3e04de9185..e25c19394e 100644 --- a/bindgen-tests/tests/expectations/tests/typedef-pointer-overlap.rs +++ b/bindgen-tests/tests/expectations/tests/typedef-pointer-overlap.rs @@ -4,52 +4,22 @@ pub struct foo { pub inner: ::std::os::raw::c_char, } -#[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::(), - 1usize, - concat!("Size of: ", stringify!(foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(foo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).inner) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(inner)), - ); -} +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of foo"][::std::mem::align_of::() - 1usize]; + ["Offset of field: foo::inner"][::std::mem::offset_of!(foo, inner) - 0usize]; +}; pub type foo_ptr = *const foo; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct bar { pub inner: ::std::os::raw::c_char, } -#[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::(), - 1usize, - concat!("Size of: ", stringify!(bar)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(bar)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).inner) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(bar), "::", stringify!(inner)), - ); -} +const _: () = { + ["Size of bar"][::std::mem::size_of::() - 1usize]; + ["Alignment of bar"][::std::mem::align_of::() - 1usize]; + ["Offset of field: bar::inner"][::std::mem::offset_of!(bar, inner) - 0usize]; +}; pub type bar_ptr = *mut bar; #[repr(C)] #[derive(Debug, Copy, Clone)] @@ -62,26 +32,13 @@ pub type baz_ptr = *mut baz; pub union cat { pub standard_issue: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_cat() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(cat)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(cat)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).standard_issue) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(cat), "::", stringify!(standard_issue)), - ); -} +const _: () = { + ["Size of cat"][::std::mem::size_of::() - 4usize]; + ["Alignment of cat"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: cat::standard_issue", + ][::std::mem::offset_of!(cat, standard_issue) - 0usize]; +}; impl Default for cat { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/typeref.rs b/bindgen-tests/tests/expectations/tests/typeref.rs index 31f9d2c697..3ef184578d 100644 --- a/bindgen-tests/tests/expectations/tests/typeref.rs +++ b/bindgen-tests/tests/expectations/tests/typeref.rs @@ -4,49 +4,28 @@ pub struct mozilla_FragmentOrURL { pub mIsLocalRef: bool, } -#[test] -fn bindgen_test_layout_mozilla_FragmentOrURL() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(mozilla_FragmentOrURL)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(mozilla_FragmentOrURL)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mIsLocalRef) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(mozilla_FragmentOrURL), - "::", - stringify!(mIsLocalRef), - ), - ); -} +const _: () = { + [ + "Size of mozilla_FragmentOrURL", + ][::std::mem::size_of::() - 1usize]; + [ + "Alignment of mozilla_FragmentOrURL", + ][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: mozilla_FragmentOrURL::mIsLocalRef", + ][::std::mem::offset_of!(mozilla_FragmentOrURL, mIsLocalRef) - 0usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct mozilla_Position { pub _address: u8, } -#[test] -fn bindgen_test_layout_mozilla_Position() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(mozilla_Position)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(mozilla_Position)), - ); -} +const _: () = { + ["Size of mozilla_Position"][::std::mem::size_of::() - 1usize]; + [ + "Alignment of mozilla_Position", + ][::std::mem::align_of::() - 1usize]; +}; #[repr(C)] pub struct mozilla_StyleShapeSource { pub __bindgen_anon_1: mozilla_StyleShapeSource__bindgen_ty_1, @@ -79,26 +58,11 @@ impl Default for mozilla_StyleShapeSource { pub struct Bar { pub mFoo: *mut nsFoo, } -#[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::(), - 8usize, - concat!("Size of: ", stringify!(Bar)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Bar)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mFoo) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(mFoo)), - ); -} +const _: () = { + ["Size of Bar"][::std::mem::size_of::() - 8usize]; + ["Alignment of Bar"][::std::mem::align_of::() - 8usize]; + ["Offset of field: Bar::mFoo"][::std::mem::offset_of!(Bar, mFoo) - 0usize]; +}; impl Default for Bar { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -112,26 +76,11 @@ impl Default for Bar { pub struct nsFoo { pub mBar: mozilla_StyleShapeSource, } -#[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::(), - 8usize, - concat!("Size of: ", stringify!(nsFoo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(nsFoo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mBar) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(nsFoo), "::", stringify!(mBar)), - ); -} +const _: () = { + ["Size of nsFoo"][::std::mem::size_of::() - 8usize]; + ["Alignment of nsFoo"][::std::mem::align_of::() - 8usize]; + ["Offset of field: nsFoo::mBar"][::std::mem::offset_of!(nsFoo, mBar) - 0usize]; +}; impl Default for nsFoo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -141,22 +90,11 @@ impl Default for nsFoo { } } } -#[test] -fn __bindgen_test_layout_mozilla_StyleShapeSource_open0_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!( - "Size of template specialization: ", - stringify!(mozilla_StyleShapeSource), - ), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(mozilla_StyleShapeSource), - ), - ); -} +const _: () = { + [ + "Size of template specialization: mozilla_StyleShapeSource_open0_int_close0", + ][::std::mem::size_of::() - 8usize]; + [ + "Align of template specialization: mozilla_StyleShapeSource_open0_int_close0", + ][::std::mem::align_of::() - 8usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/typeref_1_0.rs b/bindgen-tests/tests/expectations/tests/typeref_1_0.rs index 16bb52c19c..2cf1633a61 100644 --- a/bindgen-tests/tests/expectations/tests/typeref_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/typeref_1_0.rs @@ -54,22 +54,17 @@ fn bindgen_test_layout_mozilla_FragmentOrURL() { assert_eq!( ::std::mem::size_of::(), 1usize, - concat!("Size of: ", stringify!(mozilla_FragmentOrURL)), + "Size of mozilla_FragmentOrURL", ); assert_eq!( ::std::mem::align_of::(), 1usize, - concat!("Alignment of ", stringify!(mozilla_FragmentOrURL)), + "Alignment of mozilla_FragmentOrURL", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mIsLocalRef) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(mozilla_FragmentOrURL), - "::", - stringify!(mIsLocalRef), - ), + "Offset of field: mozilla_FragmentOrURL::mIsLocalRef", ); } impl Clone for mozilla_FragmentOrURL { @@ -87,12 +82,12 @@ fn bindgen_test_layout_mozilla_Position() { assert_eq!( ::std::mem::size_of::(), 1usize, - concat!("Size of: ", stringify!(mozilla_Position)), + "Size of mozilla_Position", ); assert_eq!( ::std::mem::align_of::(), 1usize, - concat!("Alignment of ", stringify!(mozilla_Position)), + "Alignment of mozilla_Position", ); } impl Clone for mozilla_Position { @@ -121,20 +116,12 @@ pub struct Bar { 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::(), - 8usize, - concat!("Size of: ", stringify!(Bar)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Bar)), - ); + assert_eq!(::std::mem::size_of::(), 8usize, "Size of Bar"); + assert_eq!(::std::mem::align_of::(), 8usize, "Alignment of Bar"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mFoo) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(mFoo)), + "Offset of field: Bar::mFoo", ); } impl Clone for Bar { @@ -160,20 +147,12 @@ pub struct nsFoo { 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::(), - 8usize, - concat!("Size of: ", stringify!(nsFoo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(nsFoo)), - ); + assert_eq!(::std::mem::size_of::(), 8usize, "Size of nsFoo"); + assert_eq!(::std::mem::align_of::(), 8usize, "Alignment of nsFoo"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mBar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(nsFoo), "::", stringify!(mBar)), + "Offset of field: nsFoo::mBar", ); } impl Clone for nsFoo { @@ -186,17 +165,11 @@ fn __bindgen_test_layout_mozilla_StyleShapeSource_open0_int_close0_instantiation assert_eq!( ::std::mem::size_of::(), 8usize, - concat!( - "Size of template specialization: ", - stringify!(mozilla_StyleShapeSource), - ), + "Size of template specialization: mozilla_StyleShapeSource_open0_int_close0", ); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!( - "Alignment of template specialization: ", - stringify!(mozilla_StyleShapeSource), - ), + "Align of template specialization: mozilla_StyleShapeSource_open0_int_close0", ); } diff --git a/bindgen-tests/tests/expectations/tests/underscore.rs b/bindgen-tests/tests/expectations/tests/underscore.rs index 59897e41fd..65482d7b14 100644 --- a/bindgen-tests/tests/expectations/tests/underscore.rs +++ b/bindgen-tests/tests/expectations/tests/underscore.rs @@ -5,23 +5,8 @@ pub const __: ::std::os::raw::c_int = 10; pub struct ptr_t { pub __: [::std::os::raw::c_uchar; 8usize], } -#[test] -fn bindgen_test_layout_ptr_t() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(ptr_t)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(ptr_t)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).__) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(ptr_t), "::", stringify!(__)), - ); -} +const _: () = { + ["Size of ptr_t"][::std::mem::size_of::() - 8usize]; + ["Alignment of ptr_t"][::std::mem::align_of::() - 1usize]; + ["Offset of field: ptr_t::__"][::std::mem::offset_of!(ptr_t, __) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/union-align.rs b/bindgen-tests/tests/expectations/tests/union-align.rs index 0047834f81..2838ef34c3 100644 --- a/bindgen-tests/tests/expectations/tests/union-align.rs +++ b/bindgen-tests/tests/expectations/tests/union-align.rs @@ -9,20 +9,12 @@ pub union Bar { 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, - concat!("Size of: ", stringify!(Bar)), - ); - assert_eq!( - ::std::mem::align_of::(), - 16usize, - concat!("Alignment of ", stringify!(Bar)), - ); + 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, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(foo)), + "Offset of field: Bar::foo", ); } impl Default for Bar { @@ -44,20 +36,12 @@ pub union Baz { 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, - concat!("Size of: ", stringify!(Baz)), - ); - assert_eq!( - ::std::mem::align_of::(), - 16usize, - concat!("Alignment of ", stringify!(Baz)), - ); + 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, - concat!("Offset of field: ", stringify!(Baz), "::", stringify!(bar)), + "Offset of field: Baz::bar", ); } impl Default for Baz { diff --git a/bindgen-tests/tests/expectations/tests/union-in-ns.rs b/bindgen-tests/tests/expectations/tests/union-in-ns.rs index 58160c65a9..e1925d82cc 100644 --- a/bindgen-tests/tests/expectations/tests/union-in-ns.rs +++ b/bindgen-tests/tests/expectations/tests/union-in-ns.rs @@ -8,26 +8,11 @@ pub mod root { pub union bar { pub baz: ::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, - concat!("Size of: ", stringify!(bar)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(bar)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(bar), "::", stringify!(baz)), - ); - } + const _: () = { + ["Size of bar"][::std::mem::size_of::() - 4usize]; + ["Alignment of bar"][::std::mem::align_of::() - 4usize]; + ["Offset of field: bar::baz"][::std::mem::offset_of!(bar, baz) - 0usize]; + }; impl Default for bar { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/union-in-ns_1_0.rs b/bindgen-tests/tests/expectations/tests/union-in-ns_1_0.rs index f80cff753b..eac1df1a13 100644 --- a/bindgen-tests/tests/expectations/tests/union-in-ns_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union-in-ns_1_0.rs @@ -56,20 +56,12 @@ pub mod root { 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, - concat!("Size of: ", stringify!(bar)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(bar)), - ); + 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).baz) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(bar), "::", stringify!(baz)), + "Offset of field: bar::baz", ); } impl Clone for bar { diff --git a/bindgen-tests/tests/expectations/tests/union_bitfield.rs b/bindgen-tests/tests/expectations/tests/union_bitfield.rs index 7f4bd37f35..fea7dd00d9 100644 --- a/bindgen-tests/tests/expectations/tests/union_bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/union_bitfield.rs @@ -90,19 +90,10 @@ pub union U4 { pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, } -#[test] -fn bindgen_test_layout_U4() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(U4)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(U4)), - ); -} +const _: () = { + ["Size of U4"][::std::mem::size_of::() - 4usize]; + ["Alignment of U4"][::std::mem::align_of::() - 4usize]; +}; impl Default for U4 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -147,15 +138,10 @@ pub union B { pub _bitfield_align_1: [u32; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, } -#[test] -fn bindgen_test_layout_B() { - assert_eq!(::std::mem::size_of::(), 4usize, concat!("Size of: ", stringify!(B))); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(B)), - ); -} +const _: () = { + ["Size of B"][::std::mem::size_of::() - 4usize]; + ["Alignment of B"][::std::mem::align_of::() - 4usize]; +}; impl Default for B { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs b/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs index e3b65e5011..c2c7173bfe 100644 --- a/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs @@ -135,16 +135,8 @@ pub struct U4 { } #[test] fn bindgen_test_layout_U4() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(U4)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(U4)), - ); + assert_eq!(::std::mem::size_of::(), 4usize, "Size of U4"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of U4"); } impl Clone for U4 { fn clone(&self) -> Self { @@ -191,12 +183,8 @@ pub struct B { } #[test] fn bindgen_test_layout_B() { - assert_eq!(::std::mem::size_of::(), 4usize, concat!("Size of: ", stringify!(B))); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(B)), - ); + assert_eq!(::std::mem::size_of::(), 4usize, "Size of B"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of B"); } impl Clone for B { fn clone(&self) -> Self { @@ -269,7 +257,7 @@ fn bindgen_test_layout_HasBigBitfield() { assert_eq!( ::std::mem::size_of::(), 16usize, - concat!("Size of: ", stringify!(HasBigBitfield)), + "Size of HasBigBitfield", ); } impl Clone for HasBigBitfield { diff --git a/bindgen-tests/tests/expectations/tests/union_dtor.rs b/bindgen-tests/tests/expectations/tests/union_dtor.rs index 5eea0cacda..9f12f8e84f 100644 --- a/bindgen-tests/tests/expectations/tests/union_dtor.rs +++ b/bindgen-tests/tests/expectations/tests/union_dtor.rs @@ -4,31 +4,16 @@ pub union UnionWithDtor { pub mFoo: ::std::os::raw::c_int, pub mBar: *mut ::std::os::raw::c_void, } -#[test] -fn bindgen_test_layout_UnionWithDtor() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(UnionWithDtor)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(UnionWithDtor)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mFoo) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(UnionWithDtor), "::", stringify!(mFoo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mBar) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(UnionWithDtor), "::", stringify!(mBar)), - ); -} +const _: () = { + ["Size of UnionWithDtor"][::std::mem::size_of::() - 8usize]; + ["Alignment of UnionWithDtor"][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: UnionWithDtor::mFoo", + ][::std::mem::offset_of!(UnionWithDtor, mFoo) - 0usize]; + [ + "Offset of field: UnionWithDtor::mBar", + ][::std::mem::offset_of!(UnionWithDtor, mBar) - 0usize]; +}; extern "C" { #[link_name = "\u{1}_ZN13UnionWithDtorD1Ev"] pub fn UnionWithDtor_UnionWithDtor_destructor(this: *mut UnionWithDtor); diff --git a/bindgen-tests/tests/expectations/tests/union_dtor_1_0.rs b/bindgen-tests/tests/expectations/tests/union_dtor_1_0.rs index a37109ab08..e9c777df94 100644 --- a/bindgen-tests/tests/expectations/tests/union_dtor_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_dtor_1_0.rs @@ -53,25 +53,21 @@ pub struct UnionWithDtor { fn bindgen_test_layout_UnionWithDtor() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(UnionWithDtor)), - ); + assert_eq!(::std::mem::size_of::(), 8usize, "Size of UnionWithDtor"); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(UnionWithDtor)), + "Alignment of UnionWithDtor", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mFoo) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(UnionWithDtor), "::", stringify!(mFoo)), + "Offset of field: UnionWithDtor::mFoo", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mBar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(UnionWithDtor), "::", stringify!(mBar)), + "Offset of field: UnionWithDtor::mBar", ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/union_fields.rs b/bindgen-tests/tests/expectations/tests/union_fields.rs index 30f130c3c1..cc68bce506 100644 --- a/bindgen-tests/tests/expectations/tests/union_fields.rs +++ b/bindgen-tests/tests/expectations/tests/union_fields.rs @@ -6,41 +6,19 @@ pub union nsStyleUnion { pub mFloat: f32, pub mPointer: *mut ::std::os::raw::c_void, } -#[test] -fn bindgen_test_layout_nsStyleUnion() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(nsStyleUnion)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(nsStyleUnion)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mInt) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(nsStyleUnion), "::", stringify!(mInt)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mFloat) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(nsStyleUnion), "::", stringify!(mFloat)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mPointer) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(nsStyleUnion), - "::", - stringify!(mPointer), - ), - ); -} +const _: () = { + ["Size of nsStyleUnion"][::std::mem::size_of::() - 8usize]; + ["Alignment of nsStyleUnion"][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: nsStyleUnion::mInt", + ][::std::mem::offset_of!(nsStyleUnion, mInt) - 0usize]; + [ + "Offset of field: nsStyleUnion::mFloat", + ][::std::mem::offset_of!(nsStyleUnion, mFloat) - 0usize]; + [ + "Offset of field: nsStyleUnion::mPointer", + ][::std::mem::offset_of!(nsStyleUnion, mPointer) - 0usize]; +}; impl Default for nsStyleUnion { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/union_fields_1_0.rs b/bindgen-tests/tests/expectations/tests/union_fields_1_0.rs index 8fbade8c25..9cf2f09832 100644 --- a/bindgen-tests/tests/expectations/tests/union_fields_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_fields_1_0.rs @@ -54,35 +54,26 @@ pub struct nsStyleUnion { fn bindgen_test_layout_nsStyleUnion() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(nsStyleUnion)), - ); + assert_eq!(::std::mem::size_of::(), 8usize, "Size of nsStyleUnion"); assert_eq!( ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(nsStyleUnion)), + "Alignment of nsStyleUnion", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mInt) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(nsStyleUnion), "::", stringify!(mInt)), + "Offset of field: nsStyleUnion::mInt", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mFloat) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(nsStyleUnion), "::", stringify!(mFloat)), + "Offset of field: nsStyleUnion::mFloat", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).mPointer) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(nsStyleUnion), - "::", - stringify!(mPointer), - ), + "Offset of field: nsStyleUnion::mPointer", ); } impl Clone for nsStyleUnion { diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_struct.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_struct.rs index 16f04b383e..c01c6d516b 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_struct.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_struct.rs @@ -10,51 +10,23 @@ pub struct foo__bindgen_ty_1 { pub a: ::std::os::raw::c_uint, pub b: ::std::os::raw::c_uint, } -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)), - ); -} -#[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::(), - 8usize, - concat!("Size of: ", stringify!(foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)), - ); -} +const _: () = { + ["Size of foo__bindgen_ty_1"][::std::mem::size_of::() - 8usize]; + [ + "Alignment of foo__bindgen_ty_1", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: foo__bindgen_ty_1::a", + ][::std::mem::offset_of!(foo__bindgen_ty_1, a) - 0usize]; + [ + "Offset of field: foo__bindgen_ty_1::b", + ][::std::mem::offset_of!(foo__bindgen_ty_1, b) - 4usize]; +}; +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 8usize]; + ["Alignment of foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: foo::bar"][::std::mem::offset_of!(foo, bar) - 0usize]; +}; impl Default for foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_1_0.rs index 4bc131bd3d..7ea38b8bae 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_1_0.rs @@ -61,22 +61,22 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { assert_eq!( ::std::mem::size_of::(), 8usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)), + "Size of foo__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)), + "Alignment of foo__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)), + "Offset of field: foo__bindgen_ty_1::a", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)), + "Offset of field: foo__bindgen_ty_1::b", ); } impl Clone for foo__bindgen_ty_1 { @@ -88,20 +88,12 @@ impl Clone for foo__bindgen_ty_1 { 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::(), - 8usize, - concat!("Size of: ", stringify!(foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)), - ); + assert_eq!(::std::mem::size_of::(), 8usize, "Size of foo"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of foo"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)), + "Offset of field: foo::bar", ); } impl Clone for foo { diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield.rs index 48a1bda9dc..737ec715d3 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield.rs @@ -95,19 +95,12 @@ pub struct foo__bindgen_ty_1 { pub _bitfield_align_1: [u32; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, } -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)), - ); -} +const _: () = { + ["Size of foo__bindgen_ty_1"][::std::mem::size_of::() - 4usize]; + [ + "Alignment of foo__bindgen_ty_1", + ][::std::mem::align_of::() - 4usize]; +}; impl foo__bindgen_ty_1 { #[inline] pub fn b(&self) -> ::std::os::raw::c_int { @@ -158,26 +151,11 @@ impl foo__bindgen_ty_1 { __bindgen_bitfield_unit } } -#[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::(), - 4usize, - concat!("Size of: ", stringify!(foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)), - ); -} +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 4usize]; + ["Alignment of foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: foo::a"][::std::mem::offset_of!(foo, a) - 0usize]; +}; impl Default for foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs index 530cb7ea6a..ce81f8a04e 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs @@ -144,12 +144,12 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)), + "Size of foo__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)), + "Alignment of foo__bindgen_ty_1", ); } impl Clone for foo__bindgen_ty_1 { @@ -211,20 +211,12 @@ impl foo__bindgen_ty_1 { 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::(), - 4usize, - concat!("Size of: ", stringify!(foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)), - ); + assert_eq!(::std::mem::size_of::(), 4usize, "Size of foo"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of foo"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)), + "Offset of field: foo::a", ); } impl Clone for foo { diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_union.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_union.rs index cbdeca49c0..f32fe6973f 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_union.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_union.rs @@ -10,31 +10,18 @@ pub union foo__bindgen_ty_1 { pub a: ::std::os::raw::c_uint, pub b: ::std::os::raw::c_ushort, } -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)), - ); -} +const _: () = { + ["Size of foo__bindgen_ty_1"][::std::mem::size_of::() - 4usize]; + [ + "Alignment of foo__bindgen_ty_1", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: foo__bindgen_ty_1::a", + ][::std::mem::offset_of!(foo__bindgen_ty_1, a) - 0usize]; + [ + "Offset of field: foo__bindgen_ty_1::b", + ][::std::mem::offset_of!(foo__bindgen_ty_1, b) - 0usize]; +}; impl Default for foo__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -44,26 +31,11 @@ impl Default for foo__bindgen_ty_1 { } } } -#[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::(), - 4usize, - concat!("Size of: ", stringify!(foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)), - ); -} +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 4usize]; + ["Alignment of foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: foo::bar"][::std::mem::offset_of!(foo, bar) - 0usize]; +}; impl Default for foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_union_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_union_1_0.rs index d0158ce178..ad6d9c7e16 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_union_1_0.rs @@ -62,22 +62,22 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)), + "Size of foo__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)), + "Alignment of foo__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(a)), + "Offset of field: foo__bindgen_ty_1::a", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)), + "Offset of field: foo__bindgen_ty_1::b", ); } impl Clone for foo__bindgen_ty_1 { @@ -89,20 +89,12 @@ impl Clone for foo__bindgen_ty_1 { 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::(), - 4usize, - concat!("Size of: ", stringify!(foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)), - ); + assert_eq!(::std::mem::size_of::(), 4usize, "Size of foo"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of foo"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)), + "Offset of field: foo::bar", ); } impl Clone for foo { diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct.rs index 4f8aa8ff8a..7579dd1dcf 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct.rs @@ -13,81 +13,31 @@ pub struct pixel__bindgen_ty_1 { pub b: ::std::os::raw::c_uchar, pub a: ::std::os::raw::c_uchar, } -#[test] -fn bindgen_test_layout_pixel__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(pixel__bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(pixel__bindgen_ty_1)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).r) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(pixel__bindgen_ty_1), - "::", - stringify!(r), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).g) as usize - ptr as usize }, - 1usize, - concat!( - "Offset of field: ", - stringify!(pixel__bindgen_ty_1), - "::", - stringify!(g), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(pixel__bindgen_ty_1), - "::", - stringify!(b), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 3usize, - concat!( - "Offset of field: ", - stringify!(pixel__bindgen_ty_1), - "::", - stringify!(a), - ), - ); -} -#[test] -fn bindgen_test_layout_pixel() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(pixel)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(pixel)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).rgba) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(pixel), "::", stringify!(rgba)), - ); -} +const _: () = { + [ + "Size of pixel__bindgen_ty_1", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of pixel__bindgen_ty_1", + ][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: pixel__bindgen_ty_1::r", + ][::std::mem::offset_of!(pixel__bindgen_ty_1, r) - 0usize]; + [ + "Offset of field: pixel__bindgen_ty_1::g", + ][::std::mem::offset_of!(pixel__bindgen_ty_1, g) - 1usize]; + [ + "Offset of field: pixel__bindgen_ty_1::b", + ][::std::mem::offset_of!(pixel__bindgen_ty_1, b) - 2usize]; + [ + "Offset of field: pixel__bindgen_ty_1::a", + ][::std::mem::offset_of!(pixel__bindgen_ty_1, a) - 3usize]; +}; +const _: () = { + ["Size of pixel"][::std::mem::size_of::() - 4usize]; + ["Alignment of pixel"][::std::mem::align_of::() - 4usize]; + ["Offset of field: pixel::rgba"][::std::mem::offset_of!(pixel, rgba) - 0usize]; +}; impl Default for pixel { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs index 23b1887b5a..20ceaee90c 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs @@ -64,52 +64,32 @@ fn bindgen_test_layout_pixel__bindgen_ty_1() { assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(pixel__bindgen_ty_1)), + "Size of pixel__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 1usize, - concat!("Alignment of ", stringify!(pixel__bindgen_ty_1)), + "Alignment of pixel__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).r) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(pixel__bindgen_ty_1), - "::", - stringify!(r), - ), + "Offset of field: pixel__bindgen_ty_1::r", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).g) as usize - ptr as usize }, 1usize, - concat!( - "Offset of field: ", - stringify!(pixel__bindgen_ty_1), - "::", - stringify!(g), - ), + "Offset of field: pixel__bindgen_ty_1::g", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 2usize, - concat!( - "Offset of field: ", - stringify!(pixel__bindgen_ty_1), - "::", - stringify!(b), - ), + "Offset of field: pixel__bindgen_ty_1::b", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 3usize, - concat!( - "Offset of field: ", - stringify!(pixel__bindgen_ty_1), - "::", - stringify!(a), - ), + "Offset of field: pixel__bindgen_ty_1::a", ); } impl Clone for pixel__bindgen_ty_1 { @@ -121,20 +101,12 @@ impl Clone for pixel__bindgen_ty_1 { fn bindgen_test_layout_pixel() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(pixel)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(pixel)), - ); + assert_eq!(::std::mem::size_of::(), 4usize, "Size of pixel"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of pixel"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).rgba) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(pixel), "::", stringify!(rgba)), + "Offset of field: pixel::rgba", ); } impl Clone for pixel { diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union.rs index d9d22e323e..bd24400324 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union.rs @@ -11,31 +11,18 @@ pub union foo__bindgen_ty_1 { pub b: ::std::os::raw::c_ushort, pub c: ::std::os::raw::c_uchar, } -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 2usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(c)), - ); -} +const _: () = { + ["Size of foo__bindgen_ty_1"][::std::mem::size_of::() - 2usize]; + [ + "Alignment of foo__bindgen_ty_1", + ][::std::mem::align_of::() - 2usize]; + [ + "Offset of field: foo__bindgen_ty_1::b", + ][::std::mem::offset_of!(foo__bindgen_ty_1, b) - 0usize]; + [ + "Offset of field: foo__bindgen_ty_1::c", + ][::std::mem::offset_of!(foo__bindgen_ty_1, c) - 0usize]; +}; impl Default for foo__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -45,26 +32,11 @@ impl Default for foo__bindgen_ty_1 { } } } -#[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::(), - 4usize, - concat!("Size of: ", stringify!(foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)), - ); -} +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 4usize]; + ["Alignment of foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: foo::a"][::std::mem::offset_of!(foo, a) - 0usize]; +}; impl Default for foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs index 179a87c92c..561c7f8071 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs @@ -63,22 +63,22 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { assert_eq!( ::std::mem::size_of::(), 2usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)), + "Size of foo__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 2usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)), + "Alignment of foo__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(b)), + "Offset of field: foo__bindgen_ty_1::b", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo__bindgen_ty_1), "::", stringify!(c)), + "Offset of field: foo__bindgen_ty_1::c", ); } impl Clone for foo__bindgen_ty_1 { @@ -90,20 +90,12 @@ impl Clone for foo__bindgen_ty_1 { 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::(), - 4usize, - concat!("Size of: ", stringify!(foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)), - ); + assert_eq!(::std::mem::size_of::(), 4usize, "Size of foo"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of foo"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)), + "Offset of field: foo::a", ); } impl Clone for foo { diff --git a/bindgen-tests/tests/expectations/tests/union_with_big_member.rs b/bindgen-tests/tests/expectations/tests/union_with_big_member.rs index 955e57a0a0..b6b2bc25d7 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_big_member.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_big_member.rs @@ -5,31 +5,16 @@ pub union WithBigArray { pub a: ::std::os::raw::c_int, pub b: [::std::os::raw::c_int; 33usize], } -#[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, - concat!("Size of: ", stringify!(WithBigArray)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithBigArray)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(WithBigArray), "::", stringify!(a)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(WithBigArray), "::", stringify!(b)), - ); -} +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]; + [ + "Offset of field: WithBigArray::b", + ][::std::mem::offset_of!(WithBigArray, b) - 0usize]; +}; impl Default for WithBigArray { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -45,31 +30,16 @@ pub union WithBigArray2 { pub a: ::std::os::raw::c_int, pub b: [::std::os::raw::c_char; 33usize], } -#[test] -fn bindgen_test_layout_WithBigArray2() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 36usize, - concat!("Size of: ", stringify!(WithBigArray2)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithBigArray2)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(WithBigArray2), "::", stringify!(a)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(WithBigArray2), "::", stringify!(b)), - ); -} +const _: () = { + ["Size of WithBigArray2"][::std::mem::size_of::() - 36usize]; + ["Alignment of WithBigArray2"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: WithBigArray2::a", + ][::std::mem::offset_of!(WithBigArray2, a) - 0usize]; + [ + "Offset of field: WithBigArray2::b", + ][::std::mem::offset_of!(WithBigArray2, b) - 0usize]; +}; impl Default for WithBigArray2 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -85,31 +55,16 @@ pub union WithBigMember { pub a: ::std::os::raw::c_int, pub b: WithBigArray, } -#[test] -fn bindgen_test_layout_WithBigMember() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 132usize, - concat!("Size of: ", stringify!(WithBigMember)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithBigMember)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(WithBigMember), "::", stringify!(a)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(WithBigMember), "::", stringify!(b)), - ); -} +const _: () = { + ["Size of WithBigMember"][::std::mem::size_of::() - 132usize]; + ["Alignment of WithBigMember"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: WithBigMember::a", + ][::std::mem::offset_of!(WithBigMember, a) - 0usize]; + [ + "Offset of field: WithBigMember::b", + ][::std::mem::offset_of!(WithBigMember, b) - 0usize]; +}; impl Default for WithBigMember { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/union_with_big_member_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_big_member_1_0.rs index 2b50d4e754..14a68fc0bf 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_big_member_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_big_member_1_0.rs @@ -53,25 +53,21 @@ pub struct WithBigArray { 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, - concat!("Size of: ", stringify!(WithBigArray)), - ); + assert_eq!(::std::mem::size_of::(), 132usize, "Size of WithBigArray"); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(WithBigArray)), + "Alignment of WithBigArray", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(WithBigArray), "::", stringify!(a)), + "Offset of field: WithBigArray::a", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(WithBigArray), "::", stringify!(b)), + "Offset of field: WithBigArray::b", ); } impl Clone for WithBigArray { @@ -99,25 +95,21 @@ pub struct WithBigArray2 { fn bindgen_test_layout_WithBigArray2() { const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 36usize, - concat!("Size of: ", stringify!(WithBigArray2)), - ); + assert_eq!(::std::mem::size_of::(), 36usize, "Size of WithBigArray2"); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(WithBigArray2)), + "Alignment of WithBigArray2", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(WithBigArray2), "::", stringify!(a)), + "Offset of field: WithBigArray2::a", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(WithBigArray2), "::", stringify!(b)), + "Offset of field: WithBigArray2::b", ); } impl Clone for WithBigArray2 { @@ -139,22 +131,22 @@ fn bindgen_test_layout_WithBigMember() { assert_eq!( ::std::mem::size_of::(), 132usize, - concat!("Size of: ", stringify!(WithBigMember)), + "Size of WithBigMember", ); assert_eq!( ::std::mem::align_of::(), 4usize, - concat!("Alignment of ", stringify!(WithBigMember)), + "Alignment of WithBigMember", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(WithBigMember), "::", stringify!(a)), + "Offset of field: WithBigMember::a", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(WithBigMember), "::", stringify!(b)), + "Offset of field: WithBigMember::b", ); } impl Clone for WithBigMember { diff --git a/bindgen-tests/tests/expectations/tests/union_with_nesting.rs b/bindgen-tests/tests/expectations/tests/union_with_nesting.rs index 929484d12c..774a410231 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_nesting.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_nesting.rs @@ -17,41 +17,20 @@ pub union foo__bindgen_ty_1__bindgen_ty_1 { pub b1: ::std::os::raw::c_ushort, pub b2: ::std::os::raw::c_ushort, } -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 2usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b1) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(b1), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b2) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(b2), - ), - ); -} +const _: () = { + [ + "Size of foo__bindgen_ty_1__bindgen_ty_1", + ][::std::mem::size_of::() - 2usize]; + [ + "Alignment of foo__bindgen_ty_1__bindgen_ty_1", + ][::std::mem::align_of::() - 2usize]; + [ + "Offset of field: foo__bindgen_ty_1__bindgen_ty_1::b1", + ][::std::mem::offset_of!(foo__bindgen_ty_1__bindgen_ty_1, b1) - 0usize]; + [ + "Offset of field: foo__bindgen_ty_1__bindgen_ty_1::b2", + ][::std::mem::offset_of!(foo__bindgen_ty_1__bindgen_ty_1, b2) - 0usize]; +}; impl Default for foo__bindgen_ty_1__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -67,41 +46,20 @@ pub union foo__bindgen_ty_1__bindgen_ty_2 { pub c1: ::std::os::raw::c_ushort, pub c2: ::std::os::raw::c_ushort, } -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 2usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)), - ); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c1) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(c1), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c2) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(c2), - ), - ); -} +const _: () = { + [ + "Size of foo__bindgen_ty_1__bindgen_ty_2", + ][::std::mem::size_of::() - 2usize]; + [ + "Alignment of foo__bindgen_ty_1__bindgen_ty_2", + ][::std::mem::align_of::() - 2usize]; + [ + "Offset of field: foo__bindgen_ty_1__bindgen_ty_2::c1", + ][::std::mem::offset_of!(foo__bindgen_ty_1__bindgen_ty_2, c1) - 0usize]; + [ + "Offset of field: foo__bindgen_ty_1__bindgen_ty_2::c2", + ][::std::mem::offset_of!(foo__bindgen_ty_1__bindgen_ty_2, c2) - 0usize]; +}; impl Default for foo__bindgen_ty_1__bindgen_ty_2 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -111,19 +69,12 @@ impl Default for foo__bindgen_ty_1__bindgen_ty_2 { } } } -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)), - ); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)), - ); -} +const _: () = { + ["Size of foo__bindgen_ty_1"][::std::mem::size_of::() - 4usize]; + [ + "Alignment of foo__bindgen_ty_1", + ][::std::mem::align_of::() - 2usize]; +}; impl Default for foo__bindgen_ty_1 { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -133,26 +84,11 @@ impl Default for foo__bindgen_ty_1 { } } } -#[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::(), - 4usize, - concat!("Size of: ", stringify!(foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)), - ); -} +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 4usize]; + ["Alignment of foo"][::std::mem::align_of::() - 4usize]; + ["Offset of field: foo::a"][::std::mem::offset_of!(foo, a) - 0usize]; +}; impl Default for foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/union_with_nesting_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_nesting_1_0.rs index 4305d58f91..22b902d82c 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_nesting_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_nesting_1_0.rs @@ -69,32 +69,22 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { assert_eq!( ::std::mem::size_of::(), 2usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)), + "Size of foo__bindgen_ty_1__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 2usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_1)), + "Alignment of foo__bindgen_ty_1__bindgen_ty_1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).b1) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(b1), - ), + "Offset of field: foo__bindgen_ty_1__bindgen_ty_1::b1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).b2) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_1), - "::", - stringify!(b2), - ), + "Offset of field: foo__bindgen_ty_1__bindgen_ty_1::b2", ); } impl Clone for foo__bindgen_ty_1__bindgen_ty_1 { @@ -116,32 +106,22 @@ fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { assert_eq!( ::std::mem::size_of::(), 2usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)), + "Size of foo__bindgen_ty_1__bindgen_ty_2", ); assert_eq!( ::std::mem::align_of::(), 2usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1__bindgen_ty_2)), + "Alignment of foo__bindgen_ty_1__bindgen_ty_2", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).c1) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(c1), - ), + "Offset of field: foo__bindgen_ty_1__bindgen_ty_2::c1", ); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).c2) as usize - ptr as usize }, 0usize, - concat!( - "Offset of field: ", - stringify!(foo__bindgen_ty_1__bindgen_ty_2), - "::", - stringify!(c2), - ), + "Offset of field: foo__bindgen_ty_1__bindgen_ty_2::c2", ); } impl Clone for foo__bindgen_ty_1__bindgen_ty_2 { @@ -154,12 +134,12 @@ fn bindgen_test_layout_foo__bindgen_ty_1() { assert_eq!( ::std::mem::size_of::(), 4usize, - concat!("Size of: ", stringify!(foo__bindgen_ty_1)), + "Size of foo__bindgen_ty_1", ); assert_eq!( ::std::mem::align_of::(), 2usize, - concat!("Alignment of ", stringify!(foo__bindgen_ty_1)), + "Alignment of foo__bindgen_ty_1", ); } impl Clone for foo__bindgen_ty_1 { @@ -171,20 +151,12 @@ impl Clone for foo__bindgen_ty_1 { 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::(), - 4usize, - concat!("Size of: ", stringify!(foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(foo)), - ); + assert_eq!(::std::mem::size_of::(), 4usize, "Size of foo"); + assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of foo"); assert_eq!( unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)), + "Offset of field: foo::a", ); } impl Clone for foo { diff --git a/bindgen-tests/tests/expectations/tests/union_with_non_copy_member.rs b/bindgen-tests/tests/expectations/tests/union_with_non_copy_member.rs index d9eaeacdf1..fb00e14d4a 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_non_copy_member.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_non_copy_member.rs @@ -47,67 +47,33 @@ impl ::std::cmp::Eq for __BindgenUnionField {} pub struct NonCopyType { pub foo: ::std::os::raw::c_int, } -#[test] -fn bindgen_test_layout_NonCopyType() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(NonCopyType)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(NonCopyType)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).foo) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(NonCopyType), "::", stringify!(foo)), - ); -} +const _: () = { + ["Size of NonCopyType"][::std::mem::size_of::() - 4usize]; + ["Alignment of NonCopyType"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: NonCopyType::foo", + ][::std::mem::offset_of!(NonCopyType, foo) - 0usize]; +}; #[repr(C)] pub struct WithBindgenGeneratedWrapper { pub non_copy_type: __BindgenUnionField, pub bar: __BindgenUnionField<::std::os::raw::c_int>, pub bindgen_union_field: u32, } -#[test] -fn bindgen_test_layout_WithBindgenGeneratedWrapper() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(WithBindgenGeneratedWrapper)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithBindgenGeneratedWrapper)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).non_copy_type) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBindgenGeneratedWrapper), - "::", - stringify!(non_copy_type), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithBindgenGeneratedWrapper), - "::", - stringify!(bar), - ), - ); -} +const _: () = { + [ + "Size of WithBindgenGeneratedWrapper", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of WithBindgenGeneratedWrapper", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: WithBindgenGeneratedWrapper::non_copy_type", + ][::std::mem::offset_of!(WithBindgenGeneratedWrapper, non_copy_type) - 0usize]; + [ + "Offset of field: WithBindgenGeneratedWrapper::bar", + ][::std::mem::offset_of!(WithBindgenGeneratedWrapper, bar) - 0usize]; +}; impl Default for WithBindgenGeneratedWrapper { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -122,36 +88,18 @@ pub union WithManuallyDrop { pub non_copy_type: ::std::mem::ManuallyDrop, pub bar: ::std::mem::ManuallyDrop<::std::os::raw::c_int>, } -#[test] -fn bindgen_test_layout_WithManuallyDrop() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(WithManuallyDrop)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithManuallyDrop)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).non_copy_type) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithManuallyDrop), - "::", - stringify!(non_copy_type), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(WithManuallyDrop), "::", stringify!(bar)), - ); -} +const _: () = { + ["Size of WithManuallyDrop"][::std::mem::size_of::() - 4usize]; + [ + "Alignment of WithManuallyDrop", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: WithManuallyDrop::non_copy_type", + ][::std::mem::offset_of!(WithManuallyDrop, non_copy_type) - 0usize]; + [ + "Offset of field: WithManuallyDrop::bar", + ][::std::mem::offset_of!(WithManuallyDrop, bar) - 0usize]; +}; impl Default for WithManuallyDrop { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -167,41 +115,18 @@ pub struct WithDefaultWrapper { pub bar: __BindgenUnionField<::std::os::raw::c_int>, pub bindgen_union_field: u32, } -#[test] -fn bindgen_test_layout_WithDefaultWrapper() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(WithDefaultWrapper)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(WithDefaultWrapper)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).non_copy_type) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithDefaultWrapper), - "::", - stringify!(non_copy_type), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(WithDefaultWrapper), - "::", - stringify!(bar), - ), - ); -} +const _: () = { + ["Size of WithDefaultWrapper"][::std::mem::size_of::() - 4usize]; + [ + "Alignment of WithDefaultWrapper", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: WithDefaultWrapper::non_copy_type", + ][::std::mem::offset_of!(WithDefaultWrapper, non_copy_type) - 0usize]; + [ + "Offset of field: WithDefaultWrapper::bar", + ][::std::mem::offset_of!(WithDefaultWrapper, bar) - 0usize]; +}; impl Default for WithDefaultWrapper { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/unknown_attr.rs b/bindgen-tests/tests/expectations/tests/unknown_attr.rs index 7b21595d9f..58c64f7fdb 100644 --- a/bindgen-tests/tests/expectations/tests/unknown_attr.rs +++ b/bindgen-tests/tests/expectations/tests/unknown_attr.rs @@ -7,42 +7,13 @@ pub struct max_align_t { pub __bindgen_padding_0: u64, pub __clang_max_align_nonce2: ::std::os::raw::c_longlong, } -#[test] -fn bindgen_test_layout_max_align_t() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 32usize, - concat!("Size of: ", stringify!(max_align_t)), - ); - assert_eq!( - ::std::mem::align_of::(), - 16usize, - concat!("Alignment of ", stringify!(max_align_t)), - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).__clang_max_align_nonce1) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(max_align_t), - "::", - stringify!(__clang_max_align_nonce1), - ), - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).__clang_max_align_nonce2) as usize - ptr as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(max_align_t), - "::", - stringify!(__clang_max_align_nonce2), - ), - ); -} +const _: () = { + ["Size of max_align_t"][::std::mem::size_of::() - 32usize]; + ["Alignment of max_align_t"][::std::mem::align_of::() - 16usize]; + [ + "Offset of field: max_align_t::__clang_max_align_nonce1", + ][::std::mem::offset_of!(max_align_t, __clang_max_align_nonce1) - 0usize]; + [ + "Offset of field: max_align_t::__clang_max_align_nonce2", + ][::std::mem::offset_of!(max_align_t, __clang_max_align_nonce2) - 16usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/unsorted-items.rs b/bindgen-tests/tests/expectations/tests/unsorted-items.rs index 745ddd92e2..c73ae5124c 100644 --- a/bindgen-tests/tests/expectations/tests/unsorted-items.rs +++ b/bindgen-tests/tests/expectations/tests/unsorted-items.rs @@ -12,62 +12,24 @@ pub struct Point { pub x: number, pub y: number, } -#[test] -fn bindgen_test_layout_Point() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Point)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Point)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).x) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Point), "::", stringify!(x)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).y) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(Point), "::", stringify!(y)), - ); -} +const _: () = { + ["Size of Point"][::std::mem::size_of::() - 8usize]; + ["Alignment of Point"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Point::x"][::std::mem::offset_of!(Point, x) - 0usize]; + ["Offset of field: Point::y"][::std::mem::offset_of!(Point, y) - 4usize]; +}; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Angle { pub a: number, pub b: number, } -#[test] -fn bindgen_test_layout_Angle() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Angle)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Angle)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Angle), "::", stringify!(a)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(Angle), "::", stringify!(b)), - ); -} +const _: () = { + ["Size of Angle"][::std::mem::size_of::() - 8usize]; + ["Alignment of Angle"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Angle::a"][::std::mem::offset_of!(Angle, a) - 0usize]; + ["Offset of field: Angle::b"][::std::mem::offset_of!(Angle, b) - 4usize]; +}; extern "C" { pub fn baz(point: Point) -> ::std::os::raw::c_int; } diff --git a/bindgen-tests/tests/expectations/tests/use-core.rs b/bindgen-tests/tests/expectations/tests/use-core.rs index 2b6e93bfc4..20272bc5fb 100644 --- a/bindgen-tests/tests/expectations/tests/use-core.rs +++ b/bindgen-tests/tests/expectations/tests/use-core.rs @@ -8,36 +8,13 @@ pub struct foo { pub b: ::core::ffi::c_int, pub bar: *mut ::core::ffi::c_void, } -#[test] -fn bindgen_test_layout_foo() { - const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::core::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(foo)), - ); - assert_eq!( - ::core::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(foo)), - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)), - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)), - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)), - ); -} +const _: () = { + ["Size of foo"][::core::mem::size_of::() - 16usize]; + ["Alignment of foo"][::core::mem::align_of::() - 8usize]; + ["Offset of field: foo::a"][::core::mem::offset_of!(foo, a) - 0usize]; + ["Offset of field: foo::b"][::core::mem::offset_of!(foo, b) - 4usize]; + ["Offset of field: foo::bar"][::core::mem::offset_of!(foo, bar) - 8usize]; +}; impl Default for foo { fn default() -> Self { let mut s = ::core::mem::MaybeUninit::::uninit(); @@ -53,31 +30,16 @@ pub union _bindgen_ty_1 { pub bar: ::core::ffi::c_int, pub baz: ::core::ffi::c_long, } -#[test] -fn bindgen_test_layout__bindgen_ty_1() { - const UNINIT: ::core::mem::MaybeUninit<_bindgen_ty_1> = ::core::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::core::mem::size_of::<_bindgen_ty_1>(), - 8usize, - concat!("Size of: ", stringify!(_bindgen_ty_1)), - ); - assert_eq!( - ::core::mem::align_of::<_bindgen_ty_1>(), - 8usize, - concat!("Alignment of ", stringify!(_bindgen_ty_1)), - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(_bindgen_ty_1), "::", stringify!(bar)), - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(_bindgen_ty_1), "::", stringify!(baz)), - ); -} +const _: () = { + ["Size of _bindgen_ty_1"][::core::mem::size_of::<_bindgen_ty_1>() - 8usize]; + ["Alignment of _bindgen_ty_1"][::core::mem::align_of::<_bindgen_ty_1>() - 8usize]; + [ + "Offset of field: _bindgen_ty_1::bar", + ][::core::mem::offset_of!(_bindgen_ty_1, bar) - 0usize]; + [ + "Offset of field: _bindgen_ty_1::baz", + ][::core::mem::offset_of!(_bindgen_ty_1, baz) - 0usize]; +}; impl Default for _bindgen_ty_1 { fn default() -> Self { let mut s = ::core::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/use-core_1_0.rs b/bindgen-tests/tests/expectations/tests/use-core_1_0.rs index 6c56e43eea..707ca3d962 100644 --- a/bindgen-tests/tests/expectations/tests/use-core_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/use-core_1_0.rs @@ -54,30 +54,22 @@ pub struct foo { fn bindgen_test_layout_foo() { const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::core::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(foo)), - ); - assert_eq!( - ::core::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(foo)), - ); + assert_eq!(::core::mem::size_of::(), 16usize, "Size of foo"); + assert_eq!(::core::mem::align_of::(), 8usize, "Alignment of foo"); assert_eq!( unsafe { ::core::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(a)), + "Offset of field: foo::a", ); assert_eq!( unsafe { ::core::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, 4usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(b)), + "Offset of field: foo::b", ); assert_eq!( unsafe { ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 8usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(bar)), + "Offset of field: foo::bar", ); } impl Clone for foo { @@ -105,25 +97,21 @@ pub struct _bindgen_ty_1 { fn bindgen_test_layout__bindgen_ty_1() { const UNINIT: ::core::mem::MaybeUninit<_bindgen_ty_1> = ::core::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); - assert_eq!( - ::core::mem::size_of::<_bindgen_ty_1>(), - 8usize, - concat!("Size of: ", stringify!(_bindgen_ty_1)), - ); + assert_eq!(::core::mem::size_of::<_bindgen_ty_1>(), 8usize, "Size of _bindgen_ty_1"); assert_eq!( ::core::mem::align_of::<_bindgen_ty_1>(), 8usize, - concat!("Alignment of ", stringify!(_bindgen_ty_1)), + "Alignment of _bindgen_ty_1", ); assert_eq!( unsafe { ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(_bindgen_ty_1), "::", stringify!(bar)), + "Offset of field: _bindgen_ty_1::bar", ); assert_eq!( unsafe { ::core::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, 0usize, - concat!("Offset of field: ", stringify!(_bindgen_ty_1), "::", stringify!(baz)), + "Offset of field: _bindgen_ty_1::baz", ); } impl Clone for _bindgen_ty_1 { diff --git a/bindgen-tests/tests/expectations/tests/var-tracing.rs b/bindgen-tests/tests/expectations/tests/var-tracing.rs index fcd5d59471..8c61ee9d39 100644 --- a/bindgen-tests/tests/expectations/tests/var-tracing.rs +++ b/bindgen-tests/tests/expectations/tests/var-tracing.rs @@ -4,26 +4,11 @@ pub struct Bar { pub m_baz: ::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, - concat!("Size of: ", stringify!(Bar)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Bar)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).m_baz) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(Bar), "::", stringify!(m_baz)), - ); -} +const _: () = { + ["Size of Bar"][::std::mem::size_of::() - 4usize]; + ["Alignment of Bar"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Bar::m_baz"][::std::mem::offset_of!(Bar, m_baz) - 0usize]; +}; extern "C" { #[link_name = "\u{1}_ZN3BarC1Ei"] pub fn Bar_Bar(this: *mut Bar, baz: ::std::os::raw::c_int); @@ -45,16 +30,7 @@ extern "C" { #[link_name = "\u{1}_ZN3Baz3FOOE"] pub static Baz_FOO: [Bar; 0usize]; } -#[test] -fn bindgen_test_layout_Baz() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Baz)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Baz)), - ); -} +const _: () = { + ["Size of Baz"][::std::mem::size_of::() - 1usize]; + ["Alignment of Baz"][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/variadic-method.rs b/bindgen-tests/tests/expectations/tests/variadic-method.rs index c9b4e87bf9..8abf4343cf 100644 --- a/bindgen-tests/tests/expectations/tests/variadic-method.rs +++ b/bindgen-tests/tests/expectations/tests/variadic-method.rs @@ -8,19 +8,10 @@ extern "C" { pub struct Bar { pub _address: u8, } -#[test] -fn bindgen_test_layout_Bar() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Bar)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Bar)), - ); -} +const _: () = { + ["Size of Bar"][::std::mem::size_of::() - 1usize]; + ["Alignment of Bar"][::std::mem::align_of::() - 1usize]; +}; extern "C" { #[link_name = "\u{1}_ZN3Bar3fooEPKcz"] pub fn Bar_foo(this: *mut Bar, fmt: *const ::std::os::raw::c_char, ...); diff --git a/bindgen-tests/tests/expectations/tests/vector.rs b/bindgen-tests/tests/expectations/tests/vector.rs index fc400acebf..d4aed8a235 100644 --- a/bindgen-tests/tests/expectations/tests/vector.rs +++ b/bindgen-tests/tests/expectations/tests/vector.rs @@ -4,26 +4,11 @@ pub struct foo { pub mMember: [::std::os::raw::c_longlong; 1usize], } -#[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::(), - 8usize, - concat!("Size of: ", stringify!(foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(foo)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mMember) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(foo), "::", stringify!(mMember)), - ); -} +const _: () = { + ["Size of foo"][::std::mem::size_of::() - 8usize]; + ["Alignment of foo"][::std::mem::align_of::() - 8usize]; + ["Offset of field: foo::mMember"][::std::mem::offset_of!(foo, mMember) - 0usize]; +}; pub type __m128 = [f32; 4usize]; pub type __m128d = [f64; 2usize]; pub type __m128i = [::std::os::raw::c_longlong; 2usize]; diff --git a/bindgen-tests/tests/expectations/tests/virtual_dtor.rs b/bindgen-tests/tests/expectations/tests/virtual_dtor.rs index cff0bc1205..26198a1b4d 100644 --- a/bindgen-tests/tests/expectations/tests/virtual_dtor.rs +++ b/bindgen-tests/tests/expectations/tests/virtual_dtor.rs @@ -6,19 +6,10 @@ pub struct nsSlots__bindgen_vtable(::std::os::raw::c_void); pub struct nsSlots { pub vtable_: *const nsSlots__bindgen_vtable, } -#[test] -fn bindgen_test_layout_nsSlots() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(nsSlots)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(nsSlots)), - ); -} +const _: () = { + ["Size of nsSlots"][::std::mem::size_of::() - 8usize]; + ["Alignment of nsSlots"][::std::mem::align_of::() - 8usize]; +}; impl Default for nsSlots { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/virtual_interface.rs b/bindgen-tests/tests/expectations/tests/virtual_interface.rs index e3440567b4..ef46cbe6c4 100644 --- a/bindgen-tests/tests/expectations/tests/virtual_interface.rs +++ b/bindgen-tests/tests/expectations/tests/virtual_interface.rs @@ -12,19 +12,12 @@ pub struct PureVirtualIFace__bindgen_vtable { pub struct PureVirtualIFace { pub vtable_: *const PureVirtualIFace__bindgen_vtable, } -#[test] -fn bindgen_test_layout_PureVirtualIFace() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(PureVirtualIFace)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(PureVirtualIFace)), - ); -} +const _: () = { + ["Size of PureVirtualIFace"][::std::mem::size_of::() - 8usize]; + [ + "Alignment of PureVirtualIFace", + ][::std::mem::align_of::() - 8usize]; +}; impl Default for PureVirtualIFace { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -43,19 +36,12 @@ pub struct AnotherInterface__bindgen_vtable { pub struct AnotherInterface { pub vtable_: *const AnotherInterface__bindgen_vtable, } -#[test] -fn bindgen_test_layout_AnotherInterface() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(AnotherInterface)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(AnotherInterface)), - ); -} +const _: () = { + ["Size of AnotherInterface"][::std::mem::size_of::() - 8usize]; + [ + "Alignment of AnotherInterface", + ][::std::mem::align_of::() - 8usize]; +}; impl Default for AnotherInterface { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -70,19 +56,10 @@ impl Default for AnotherInterface { pub struct Implementation { pub _base: PureVirtualIFace, } -#[test] -fn bindgen_test_layout_Implementation() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Implementation)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Implementation)), - ); -} +const _: () = { + ["Size of Implementation"][::std::mem::size_of::() - 8usize]; + ["Alignment of Implementation"][::std::mem::align_of::() - 8usize]; +}; impl Default for Implementation { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -98,19 +75,10 @@ pub struct DoubleImpl { pub _base: PureVirtualIFace, pub _base_1: AnotherInterface, } -#[test] -fn bindgen_test_layout_DoubleImpl() { - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(DoubleImpl)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(DoubleImpl)), - ); -} +const _: () = { + ["Size of DoubleImpl"][::std::mem::size_of::() - 16usize]; + ["Alignment of DoubleImpl"][::std::mem::align_of::() - 8usize]; +}; impl Default for DoubleImpl { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/virtual_overloaded.rs b/bindgen-tests/tests/expectations/tests/virtual_overloaded.rs index 28a873c458..ab2df5f191 100644 --- a/bindgen-tests/tests/expectations/tests/virtual_overloaded.rs +++ b/bindgen-tests/tests/expectations/tests/virtual_overloaded.rs @@ -9,15 +9,10 @@ pub struct C__bindgen_vtable { pub struct C { pub vtable_: *const C__bindgen_vtable, } -#[test] -fn bindgen_test_layout_C() { - assert_eq!(::std::mem::size_of::(), 8usize, concat!("Size of: ", stringify!(C))); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(C)), - ); -} +const _: () = { + ["Size of C"][::std::mem::size_of::() - 8usize]; + ["Alignment of C"][::std::mem::align_of::() - 8usize]; +}; impl Default for C { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/vtable_recursive_sig.rs b/bindgen-tests/tests/expectations/tests/vtable_recursive_sig.rs index a37ecf2669..78b240ba09 100644 --- a/bindgen-tests/tests/expectations/tests/vtable_recursive_sig.rs +++ b/bindgen-tests/tests/expectations/tests/vtable_recursive_sig.rs @@ -8,19 +8,10 @@ pub struct Base__bindgen_vtable { pub struct Base { pub vtable_: *const Base__bindgen_vtable, } -#[test] -fn bindgen_test_layout_Base() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Base)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Base)), - ); -} +const _: () = { + ["Size of Base"][::std::mem::size_of::() - 8usize]; + ["Alignment of Base"][::std::mem::align_of::() - 8usize]; +}; impl Default for Base { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -39,19 +30,10 @@ extern "C" { pub struct Derived { pub _base: Base, } -#[test] -fn bindgen_test_layout_Derived() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(Derived)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(Derived)), - ); -} +const _: () = { + ["Size of Derived"][::std::mem::size_of::() - 8usize]; + ["Alignment of Derived"][::std::mem::align_of::() - 8usize]; +}; impl Default for Derived { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/wasm-constructor-returns.rs b/bindgen-tests/tests/expectations/tests/wasm-constructor-returns.rs index 7c47a43c20..00db5776c6 100644 --- a/bindgen-tests/tests/expectations/tests/wasm-constructor-returns.rs +++ b/bindgen-tests/tests/expectations/tests/wasm-constructor-returns.rs @@ -4,19 +4,10 @@ pub struct Foo { pub _address: u8, } -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)), - ); -} +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; +}; extern "C" { #[link_name = "\u{1}_ZN3FooC1Ei"] pub fn Foo_Foo( diff --git a/bindgen-tests/tests/expectations/tests/weird_bitfields.rs b/bindgen-tests/tests/expectations/tests/weird_bitfields.rs index 49579967fe..c6ab6fb7c4 100644 --- a/bindgen-tests/tests/expectations/tests/weird_bitfields.rs +++ b/bindgen-tests/tests/expectations/tests/weird_bitfields.rs @@ -111,118 +111,46 @@ pub struct Weird { pub _bitfield_2: __BindgenBitfieldUnit<[u8; 2usize]>, pub __bindgen_padding_0: [u8; 3usize], } -#[test] -fn bindgen_test_layout_Weird() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 24usize, - concat!("Size of: ", stringify!(Weird)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(Weird)), - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mStrokeDasharrayLength) as usize - ptr as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mStrokeDasharrayLength), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mClipRule) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(Weird), "::", stringify!(mClipRule)), - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mColorInterpolation) as usize - ptr as usize - }, - 9usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mColorInterpolation), - ), - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).mColorInterpolationFilters) as usize - - ptr as usize - }, - 10usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mColorInterpolationFilters), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mFillRule) as usize - ptr as usize }, - 11usize, - concat!("Offset of field: ", stringify!(Weird), "::", stringify!(mFillRule)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mImageRendering) as usize - ptr as usize }, - 12usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mImageRendering), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mPaintOrder) as usize - ptr as usize }, - 13usize, - concat!("Offset of field: ", stringify!(Weird), "::", stringify!(mPaintOrder)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mShapeRendering) as usize - ptr as usize }, - 14usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mShapeRendering), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mStrokeLinecap) as usize - ptr as usize }, - 15usize, - concat!("Offset of field: ", stringify!(Weird), "::", stringify!(mStrokeLinecap)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mStrokeLinejoin) as usize - ptr as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(Weird), - "::", - stringify!(mStrokeLinejoin), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mTextAnchor) as usize - ptr as usize }, - 17usize, - concat!("Offset of field: ", stringify!(Weird), "::", stringify!(mTextAnchor)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mTextRendering) as usize - ptr as usize }, - 18usize, - concat!("Offset of field: ", stringify!(Weird), "::", stringify!(mTextRendering)), - ); -} +const _: () = { + ["Size of Weird"][::std::mem::size_of::() - 24usize]; + ["Alignment of Weird"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: Weird::mStrokeDasharrayLength", + ][::std::mem::offset_of!(Weird, mStrokeDasharrayLength) - 0usize]; + [ + "Offset of field: Weird::mClipRule", + ][::std::mem::offset_of!(Weird, mClipRule) - 8usize]; + [ + "Offset of field: Weird::mColorInterpolation", + ][::std::mem::offset_of!(Weird, mColorInterpolation) - 9usize]; + [ + "Offset of field: Weird::mColorInterpolationFilters", + ][::std::mem::offset_of!(Weird, mColorInterpolationFilters) - 10usize]; + [ + "Offset of field: Weird::mFillRule", + ][::std::mem::offset_of!(Weird, mFillRule) - 11usize]; + [ + "Offset of field: Weird::mImageRendering", + ][::std::mem::offset_of!(Weird, mImageRendering) - 12usize]; + [ + "Offset of field: Weird::mPaintOrder", + ][::std::mem::offset_of!(Weird, mPaintOrder) - 13usize]; + [ + "Offset of field: Weird::mShapeRendering", + ][::std::mem::offset_of!(Weird, mShapeRendering) - 14usize]; + [ + "Offset of field: Weird::mStrokeLinecap", + ][::std::mem::offset_of!(Weird, mStrokeLinecap) - 15usize]; + [ + "Offset of field: Weird::mStrokeLinejoin", + ][::std::mem::offset_of!(Weird, mStrokeLinejoin) - 16usize]; + [ + "Offset of field: Weird::mTextAnchor", + ][::std::mem::offset_of!(Weird, mTextAnchor) - 17usize]; + [ + "Offset of field: Weird::mTextRendering", + ][::std::mem::offset_of!(Weird, mTextRendering) - 18usize]; +}; impl Default for Weird { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/what_is_going_on.rs b/bindgen-tests/tests/expectations/tests/what_is_going_on.rs index 2bd4d2b33b..bfc26f3950 100644 --- a/bindgen-tests/tests/expectations/tests/what_is_going_on.rs +++ b/bindgen-tests/tests/expectations/tests/what_is_going_on.rs @@ -4,19 +4,10 @@ pub struct UnknownUnits { pub _address: u8, } -#[test] -fn bindgen_test_layout_UnknownUnits() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(UnknownUnits)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(UnknownUnits)), - ); -} +const _: () = { + ["Size of UnknownUnits"][::std::mem::size_of::() - 1usize]; + ["Alignment of UnknownUnits"][::std::mem::align_of::() - 1usize]; +}; pub type Float = f32; #[repr(C)] #[derive(Debug, Copy, Clone)] diff --git a/bindgen-tests/tests/expectations/tests/win32-dtors.rs b/bindgen-tests/tests/expectations/tests/win32-dtors.rs index 8739ef4be8..042aa8cece 100644 --- a/bindgen-tests/tests/expectations/tests/win32-dtors.rs +++ b/bindgen-tests/tests/expectations/tests/win32-dtors.rs @@ -8,20 +8,12 @@ pub struct CppObj { 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, - concat!("Size of: ", stringify!(CppObj)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(CppObj)), - ); + 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, - concat!("Offset of field: ", stringify!(CppObj), "::", stringify!(x)), + "Offset of field: CppObj::x", ); } extern "C" { @@ -56,20 +48,12 @@ pub struct CppObj2 { 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, - concat!("Size of: ", stringify!(CppObj2)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(CppObj2)), - ); + 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, - concat!("Offset of field: ", stringify!(CppObj2), "::", stringify!(x)), + "Offset of field: CppObj2::x", ); } extern "C" { @@ -107,20 +91,12 @@ pub struct CppObj3 { 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, - concat!("Size of: ", stringify!(CppObj3)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(CppObj3)), - ); + 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, - concat!("Offset of field: ", stringify!(CppObj3), "::", stringify!(x)), + "Offset of field: CppObj3::x", ); } extern "C" { @@ -158,20 +134,12 @@ pub struct CppObj4 { 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, - concat!("Size of: ", stringify!(CppObj4)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(CppObj4)), - ); + 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, - concat!("Offset of field: ", stringify!(CppObj4), "::", stringify!(x)), + "Offset of field: CppObj4::x", ); } extern "C" { diff --git a/bindgen-tests/tests/expectations/tests/win32-thiscall_1_0.rs b/bindgen-tests/tests/expectations/tests/win32-thiscall_1_0.rs index dc19e05dde..185b935808 100644 --- a/bindgen-tests/tests/expectations/tests/win32-thiscall_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/win32-thiscall_1_0.rs @@ -6,16 +6,8 @@ pub struct Foo { } #[test] fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)), - ); + assert_eq!(::std::mem::size_of::(), 1usize, "Size of Foo"); + assert_eq!(::std::mem::align_of::(), 1usize, "Alignment of Foo"); } impl Clone for Foo { fn clone(&self) -> Self { diff --git a/bindgen-tests/tests/expectations/tests/win32-thiscall_1_73.rs b/bindgen-tests/tests/expectations/tests/win32-thiscall_1_73.rs index 2faedf1814..4741f029ff 100644 --- a/bindgen-tests/tests/expectations/tests/win32-thiscall_1_73.rs +++ b/bindgen-tests/tests/expectations/tests/win32-thiscall_1_73.rs @@ -7,16 +7,8 @@ pub struct Foo { } #[test] fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)), - ); + assert_eq!(::std::mem::size_of::(), 1usize, "Size of Foo"); + assert_eq!(::std::mem::align_of::(), 1usize, "Alignment of Foo"); } extern "thiscall" { #[link_name = "\u{1}?test@Foo@@QAEXXZ"] diff --git a/bindgen-tests/tests/expectations/tests/win32-thiscall_nightly.rs b/bindgen-tests/tests/expectations/tests/win32-thiscall_nightly.rs index ba861131b9..187fa75ee4 100644 --- a/bindgen-tests/tests/expectations/tests/win32-thiscall_nightly.rs +++ b/bindgen-tests/tests/expectations/tests/win32-thiscall_nightly.rs @@ -6,19 +6,10 @@ pub struct Foo { pub _address: u8, } -#[test] -fn bindgen_test_layout_Foo() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - concat!("Size of: ", stringify!(Foo)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(Foo)), - ); -} +const _: () = { + ["Size of Foo"][::std::mem::size_of::() - 1usize]; + ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; +}; extern "thiscall" { #[link_name = "\u{1}?test@Foo@@QAEXXZ"] pub fn Foo_test(this: *mut Foo); diff --git a/bindgen-tests/tests/expectations/tests/zero-size-array-align.rs b/bindgen-tests/tests/expectations/tests/zero-size-array-align.rs index be373d7ae8..f1e18874a4 100644 --- a/bindgen-tests/tests/expectations/tests/zero-size-array-align.rs +++ b/bindgen-tests/tests/expectations/tests/zero-size-array-align.rs @@ -36,33 +36,14 @@ pub struct dm_deps { pub filler: ::std::os::raw::c_uint, pub device: __IncompleteArrayField<::std::os::raw::c_ulonglong>, } -#[test] -fn bindgen_test_layout_dm_deps() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(dm_deps)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(dm_deps)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).count) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(dm_deps), "::", stringify!(count)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).filler) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(dm_deps), "::", stringify!(filler)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).device) as usize - ptr as usize }, - 8usize, - concat!("Offset of field: ", stringify!(dm_deps), "::", stringify!(device)), - ); -} +const _: () = { + ["Size of dm_deps"][::std::mem::size_of::() - 8usize]; + ["Alignment of dm_deps"][::std::mem::align_of::() - 8usize]; + ["Offset of field: dm_deps::count"][::std::mem::offset_of!(dm_deps, count) - 0usize]; + [ + "Offset of field: dm_deps::filler", + ][::std::mem::offset_of!(dm_deps, filler) - 4usize]; + [ + "Offset of field: dm_deps::device", + ][::std::mem::offset_of!(dm_deps, device) - 8usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/zero-sized-array.rs b/bindgen-tests/tests/expectations/tests/zero-sized-array.rs index bc4b660029..ba8310b747 100644 --- a/bindgen-tests/tests/expectations/tests/zero-sized-array.rs +++ b/bindgen-tests/tests/expectations/tests/zero-sized-array.rs @@ -35,57 +35,30 @@ impl ::std::fmt::Debug for __IncompleteArrayField { pub struct ZeroSizedArray { pub arr: __IncompleteArrayField<::std::os::raw::c_char>, } -#[test] -fn bindgen_test_layout_ZeroSizedArray() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(ZeroSizedArray)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(ZeroSizedArray)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(ZeroSizedArray), "::", stringify!(arr)), - ); -} +const _: () = { + ["Size of ZeroSizedArray"][::std::mem::size_of::() - 0usize]; + ["Alignment of ZeroSizedArray"][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: ZeroSizedArray::arr", + ][::std::mem::offset_of!(ZeroSizedArray, arr) - 0usize]; +}; /// And nor should this get an `_address` field. #[repr(C)] #[derive(Debug, Default)] pub struct ContainsZeroSizedArray { pub zsa: ZeroSizedArray, } -#[test] -fn bindgen_test_layout_ContainsZeroSizedArray() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(ContainsZeroSizedArray)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(ContainsZeroSizedArray)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).zsa) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContainsZeroSizedArray), - "::", - stringify!(zsa), - ), - ); -} +const _: () = { + [ + "Size of ContainsZeroSizedArray", + ][::std::mem::size_of::() - 0usize]; + [ + "Alignment of ContainsZeroSizedArray", + ][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: ContainsZeroSizedArray::zsa", + ][::std::mem::offset_of!(ContainsZeroSizedArray, zsa) - 0usize]; +}; /** Inheriting from ZeroSizedArray shouldn't cause an `_address` to be inserted either.*/ #[repr(C)] @@ -93,78 +66,45 @@ fn bindgen_test_layout_ContainsZeroSizedArray() { pub struct InheritsZeroSizedArray { pub _base: ZeroSizedArray, } -#[test] -fn bindgen_test_layout_InheritsZeroSizedArray() { - assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(InheritsZeroSizedArray)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(InheritsZeroSizedArray)), - ); -} +const _: () = { + [ + "Size of InheritsZeroSizedArray", + ][::std::mem::size_of::() - 0usize]; + [ + "Alignment of InheritsZeroSizedArray", + ][::std::mem::align_of::() - 1usize]; +}; /// And this should not get an `_address` field either. #[repr(C)] #[derive(Debug, Default)] pub struct DynamicallySizedArray { pub arr: __IncompleteArrayField<::std::os::raw::c_char>, } -#[test] -fn bindgen_test_layout_DynamicallySizedArray() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(DynamicallySizedArray)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(DynamicallySizedArray)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(DynamicallySizedArray), - "::", - stringify!(arr), - ), - ); -} +const _: () = { + [ + "Size of DynamicallySizedArray", + ][::std::mem::size_of::() - 0usize]; + [ + "Alignment of DynamicallySizedArray", + ][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: DynamicallySizedArray::arr", + ][::std::mem::offset_of!(DynamicallySizedArray, arr) - 0usize]; +}; /// No `_address` field here either. #[repr(C)] #[derive(Debug, Default)] pub struct ContainsDynamicallySizedArray { pub dsa: DynamicallySizedArray, } -#[test] -fn bindgen_test_layout_ContainsDynamicallySizedArray() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 0usize, - concat!("Size of: ", stringify!(ContainsDynamicallySizedArray)), - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(ContainsDynamicallySizedArray)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dsa) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ContainsDynamicallySizedArray), - "::", - stringify!(dsa), - ), - ); -} +const _: () = { + [ + "Size of ContainsDynamicallySizedArray", + ][::std::mem::size_of::() - 0usize]; + [ + "Alignment of ContainsDynamicallySizedArray", + ][::std::mem::align_of::() - 1usize]; + [ + "Offset of field: ContainsDynamicallySizedArray::dsa", + ][::std::mem::offset_of!(ContainsDynamicallySizedArray, dsa) - 0usize]; +}; diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 73ae0c4f61..4e1bf1b6fc 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -1254,6 +1254,9 @@ impl CodeGenerator for TemplateInstantiation { return; } + // For consistency with other layout tests, gate this on offset_of. + let compile_time = ctx.options().rust_features().offset_of; + // If there are any unbound type parameters, then we can't generate a // layout test because we aren't dealing with a concrete type with a // concrete size and alignment. @@ -1268,14 +1271,17 @@ impl CodeGenerator for TemplateInstantiation { let align = layout.align; let name = item.full_disambiguated_name(ctx); - let mut fn_name = - format!("__bindgen_test_layout_{}_instantiation", name); - let times_seen = result.overload_number(&fn_name); - if times_seen > 0 { - write!(&mut fn_name, "_{}", times_seen).unwrap(); - } - - let fn_name = ctx.rust_ident_raw(fn_name); + let fn_name = if compile_time { + None + } else { + let mut fn_name = + format!("__bindgen_test_layout_{name}_instantiation"); + let times_seen = result.overload_number(&fn_name); + if times_seen > 0 { + write!(&mut fn_name, "_{times_seen}").unwrap(); + } + Some(ctx.rust_ident_raw(fn_name)) + }; let prefix = ctx.trait_prefix(); let ident = item.to_rust_ty_or_opaque(ctx, &()); @@ -1285,20 +1291,32 @@ impl CodeGenerator for TemplateInstantiation { let align_of_expr = quote! { ::#prefix::mem::align_of::<#ident>() }; - - let item = quote! { - #[test] - fn #fn_name() { - assert_eq!(#size_of_expr, #size, - concat!("Size of template specialization: ", - stringify!(#ident))); - assert_eq!(#align_of_expr, #align, - concat!("Alignment of template specialization: ", - stringify!(#ident))); - } - }; - - result.push(item); + let size_of_err = + format!("Size of template specialization: {name}"); + let align_of_err = + format!("Align of template specialization: {name}"); + + if compile_time { + // In an ideal world this would be assert_eq!, but that is not + // supported in const fn due to the need for string formatting. + // If #size_of_expr > #size, this will index OOB, and if + // #size_of_expr < #size, the subtraction will overflow, both + // of which print enough information to see what has gone wrong. + result.push(quote! { + const _: () = { + [#size_of_err][#size_of_expr - #size]; + [#align_of_err][#align_of_expr - #align]; + }; + }); + } else { + result.push(quote! { + #[test] + fn #fn_name() { + assert_eq!(#size_of_expr, #size, #size_of_err); + assert_eq!(#align_of_expr, #align, #align_of_err); + } + }); + } } } } @@ -2344,9 +2362,14 @@ impl CodeGenerator for CompInfo { if ctx.options().layout_tests && !self.is_forward_declaration() { if let Some(layout) = layout { - let fn_name = - format!("bindgen_test_layout_{}", canonical_ident); - let fn_name = ctx.rust_ident_raw(fn_name); + let compile_time = ctx.options().rust_features().offset_of; + let fn_name = if compile_time { + None + } else { + let fn_name = + format!("bindgen_test_layout_{canonical_ident}"); + Some(ctx.rust_ident_raw(fn_name)) + }; let prefix = ctx.trait_prefix(); let size_of_expr = quote! { ::#prefix::mem::size_of::<#canonical_ident>() @@ -2356,18 +2379,22 @@ impl CodeGenerator for CompInfo { }; let size = layout.size; let align = layout.align; + let size_of_err = format!("Size of {canonical_ident}"); + let align_of_err = + format!("Alignment of {canonical_ident}"); let check_struct_align = if align > ctx.target_pointer_size() && !ctx.options().rust_features().repr_align { None + } else if compile_time { + Some(quote! { + [#align_of_err][#align_of_expr - #align]; + }) } else { Some(quote! { - assert_eq!(#align_of_expr, - #align, - concat!("Alignment of ", stringify!(#canonical_ident))); - + assert_eq!(#align_of_expr, #align, #align_of_err); }) }; @@ -2388,21 +2415,34 @@ impl CodeGenerator for CompInfo { field.offset().map(|offset| { let field_offset = offset / 8; let field_name = ctx.rust_ident(name); - quote! { - assert_eq!( - unsafe { - ::#prefix::ptr::addr_of!((*ptr).#field_name) as usize - ptr as usize - }, - #field_offset, - concat!("Offset of field: ", stringify!(#canonical_ident), "::", stringify!(#field_name)) - ); + let offset_of_err = format!("Offset of field: {canonical_ident}::{field_name}"); + if compile_time { + quote! { + [#offset_of_err][ + ::#prefix::mem::offset_of!(#canonical_ident, #field_name) - #field_offset + ]; + } + } else { + quote! { + assert_eq!( + unsafe { + ::#prefix::ptr::addr_of!((*ptr).#field_name) as usize - ptr as usize + }, + #field_offset, + #offset_of_err + ); + } } }) }) .collect() }; - let uninit_decl = if !check_field_offset.is_empty() { + let uninit_decl = if check_field_offset.is_empty() || + compile_time + { + None + } else { // FIXME: When MSRV >= 1.59.0, we can use // > const PTR: *const #canonical_ident = ::#prefix::mem::MaybeUninit::uninit().as_ptr(); Some(quote! { @@ -2412,22 +2452,27 @@ impl CodeGenerator for CompInfo { const UNINIT: ::#prefix::mem::MaybeUninit<#canonical_ident> = ::#prefix::mem::MaybeUninit::uninit(); let ptr = UNINIT.as_ptr(); }) - } else { - None }; - let item = quote! { - #[test] - fn #fn_name() { - #uninit_decl - assert_eq!(#size_of_expr, - #size, - concat!("Size of: ", stringify!(#canonical_ident))); - #check_struct_align - #( #check_field_offset )* - } - }; - result.push(item); + if compile_time { + result.push(quote! { + const _: () = { + [#size_of_err][#size_of_expr - #size]; + #check_struct_align + #( #check_field_offset )* + }; + }); + } else { + result.push(quote! { + #[test] + fn #fn_name() { + #uninit_decl + assert_eq!(#size_of_expr, #size, #size_of_err); + #check_struct_align + #( #check_field_offset )* + } + }); + } } } diff --git a/bindgen/features.rs b/bindgen/features.rs index e5e2068053..fa3f20d717 100644 --- a/bindgen/features.rs +++ b/bindgen/features.rs @@ -97,6 +97,7 @@ define_rust_targets! { Nightly => { vectorcall_abi, }, + Stable_1_77(77) => { offset_of: #106655 }, Stable_1_73(73) => { thiscall_abi: #42202 }, Stable_1_71(71) => { c_unwind_abi: #106075 }, Stable_1_68(68) => { abi_efiapi: #105795 }, From 2d293e65f1b68b695a89a37b949a3e8992e68416 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Thu, 28 Mar 2024 14:28:25 +0200 Subject: [PATCH 649/942] stop using deprecated type --- bindgen-integration/build.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs index 2a0763b0b7..b5afeba92f 100644 --- a/bindgen-integration/build.rs +++ b/bindgen-integration/build.rs @@ -4,7 +4,7 @@ extern crate cc; use bindgen::callbacks::{ DeriveInfo, IntKind, MacroParsingBehavior, ParseCallbacks, }; -use bindgen::{Builder, CargoCallbacks, EnumVariation, Formatter}; +use bindgen::{Builder, EnumVariation, Formatter}; use std::collections::HashSet; use std::env; use std::path::PathBuf; @@ -234,7 +234,9 @@ fn setup_wrap_static_fns_test() { // generate external bindings with the external .c and .h files let bindings = Builder::default() .header(input_header_file_path_str) - .parse_callbacks(Box::new(CargoCallbacks)) + .parse_callbacks(Box::new( + bindgen::CargoCallbacks::new().rerun_on_header_files(true), + )) .parse_callbacks(Box::new(WrappedVaListCallback)) .wrap_static_fns(true) .wrap_static_fns_path( From adb5d034ddf3bb3127ed6a18274da1f385edeff0 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Mon, 1 Apr 2024 22:12:56 +0200 Subject: [PATCH 650/942] needless declarations (#2794) * needless declarations * fix build * needless annotations --- bindgen-integration/build.rs | 1 - bindgen-integration/src/lib.rs | 1 - .../tests/expectations/tests/dynamic_loading_attributes.rs | 1 - .../tests/expectations/tests/dynamic_loading_required.rs | 1 - .../tests/expectations/tests/dynamic_loading_simple.rs | 1 - .../tests/expectations/tests/dynamic_loading_template.rs | 1 - .../expectations/tests/dynamic_loading_with_allowlist.rs | 1 - .../expectations/tests/dynamic_loading_with_blocklist.rs | 1 - .../tests/expectations/tests/dynamic_loading_with_class.rs | 1 - .../tests/wrap_unsafe_ops_dynamic_loading_simple.rs | 1 - bindgen-tests/tests/quickchecking/src/bin.rs | 2 -- bindgen-tests/tests/quickchecking/src/lib.rs | 4 ---- bindgen-tests/tests/quickchecking/tests/fuzzed-c-headers.rs | 3 --- bindgen-tests/tests/stylo_sanity.rs | 4 ---- bindgen-tests/tests/tests.rs | 6 ------ bindgen/codegen/dyngen.rs | 2 -- bindgen/features.rs | 1 - book/src/non-system-libraries.md | 2 -- 18 files changed, 34 deletions(-) diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs index b5afeba92f..6b06c91bc3 100644 --- a/bindgen-integration/build.rs +++ b/bindgen-integration/build.rs @@ -1,5 +1,4 @@ extern crate bindgen; -extern crate cc; use bindgen::callbacks::{ DeriveInfo, IntKind, MacroParsingBehavior, ParseCallbacks, diff --git a/bindgen-integration/src/lib.rs b/bindgen-integration/src/lib.rs index e234477080..c37055ee7d 100755 --- a/bindgen-integration/src/lib.rs +++ b/bindgen-integration/src/lib.rs @@ -12,7 +12,6 @@ use std::ffi::CStr; use std::mem; use std::os::raw::c_int; -#[allow(unused)] use bindings::testing::Bar; // This type is generated from module_raw_line. type MacroInteger = isize; diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_attributes.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_attributes.rs index 7682884bbb..a1fb1b0cc1 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_attributes.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_attributes.rs @@ -1,5 +1,4 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern crate libloading; pub struct TestLib { __library: ::libloading::Library, pub foo: unsafe extern "C" fn( diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_required.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_required.rs index 6fd97e4a46..5c929ffc3d 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_required.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_required.rs @@ -1,5 +1,4 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern crate libloading; pub struct TestLib { __library: ::libloading::Library, pub foo: unsafe extern "C" fn( diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_simple.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_simple.rs index cdacf3ab42..9a4cfaf570 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_simple.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_simple.rs @@ -1,5 +1,4 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern crate libloading; pub struct TestLib { __library: ::libloading::Library, pub foo: Result< diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_template.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_template.rs index 65c36e4893..65f079bede 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_template.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_template.rs @@ -1,5 +1,4 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern crate libloading; pub struct TestLib { __library: ::libloading::Library, pub foo: Result< diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_allowlist.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_allowlist.rs index 06fffc3d47..e65176b863 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_allowlist.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_allowlist.rs @@ -1,5 +1,4 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern crate libloading; pub struct TestLib { __library: ::libloading::Library, pub foo: Result< diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_blocklist.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_blocklist.rs index 9273583a5f..4908159826 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_blocklist.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_blocklist.rs @@ -37,7 +37,6 @@ impl X { __bindgen_tmp.assume_init() } } -extern crate libloading; pub struct TestLib { __library: ::libloading::Library, pub foo: Result< diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs index dd0544b050..694d7e4ad5 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs @@ -37,7 +37,6 @@ impl A { __bindgen_tmp.assume_init() } } -extern crate libloading; pub struct TestLib { __library: ::libloading::Library, pub foo: Result< diff --git a/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_dynamic_loading_simple.rs b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_dynamic_loading_simple.rs index 968f10f6e5..2f5b4cc5ba 100644 --- a/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_dynamic_loading_simple.rs +++ b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_dynamic_loading_simple.rs @@ -1,5 +1,4 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern crate libloading; pub struct TestLib { __library: ::libloading::Library, pub foo: Result< diff --git a/bindgen-tests/tests/quickchecking/src/bin.rs b/bindgen-tests/tests/quickchecking/src/bin.rs index 7f1307e15f..fcd56652be 100644 --- a/bindgen-tests/tests/quickchecking/src/bin.rs +++ b/bindgen-tests/tests/quickchecking/src/bin.rs @@ -14,8 +14,6 @@ //! ``` //! #![deny(missing_docs)] -extern crate clap; -extern crate quickchecking; use clap::{Arg, ArgAction, Command}; use std::path::PathBuf; diff --git a/bindgen-tests/tests/quickchecking/src/lib.rs b/bindgen-tests/tests/quickchecking/src/lib.rs index 631c1c679e..38da62f6ee 100644 --- a/bindgen-tests/tests/quickchecking/src/lib.rs +++ b/bindgen-tests/tests/quickchecking/src/lib.rs @@ -3,8 +3,6 @@ //! ## Example //! //! ```rust -//! extern crate quickcheck; -//! extern crate quickchecking; //! use quickcheck::{Arbitrary, Gen}; //! use quickchecking::fuzzers; //! @@ -20,8 +18,6 @@ #![deny(missing_docs)] #[macro_use] extern crate lazy_static; -extern crate quickcheck; -extern crate tempfile; use quickcheck::{Gen, QuickCheck, TestResult}; use std::error::Error; diff --git a/bindgen-tests/tests/quickchecking/tests/fuzzed-c-headers.rs b/bindgen-tests/tests/quickchecking/tests/fuzzed-c-headers.rs index e394efe387..0735a70c47 100644 --- a/bindgen-tests/tests/quickchecking/tests/fuzzed-c-headers.rs +++ b/bindgen-tests/tests/quickchecking/tests/fuzzed-c-headers.rs @@ -1,6 +1,3 @@ -extern crate quickcheck; -extern crate quickchecking; - use quickcheck::{Arbitrary, Gen}; use quickchecking::fuzzers::{ ArrayDimensionC, BaseTypeC, BasicTypeDeclarationC, DeclarationC, diff --git a/bindgen-tests/tests/stylo_sanity.rs b/bindgen-tests/tests/stylo_sanity.rs index e9ec69bcb8..7b94e2989e 100755 --- a/bindgen-tests/tests/stylo_sanity.rs +++ b/bindgen-tests/tests/stylo_sanity.rs @@ -1,7 +1,3 @@ -// Don't want to copy that nasty `cfg` below... -#[allow(unused_extern_crates)] -extern crate bindgen; - /// A sanity test that we can generate bindings for Stylo. /// /// We don't assert on expected output because its just too big. The output will diff --git a/bindgen-tests/tests/tests.rs b/bindgen-tests/tests/tests.rs index c096b2e81e..e6c038a064 100644 --- a/bindgen-tests/tests/tests.rs +++ b/bindgen-tests/tests/tests.rs @@ -1,9 +1,3 @@ -extern crate bindgen; -extern crate clap; -#[cfg(feature = "logging")] -extern crate env_logger; -extern crate shlex; - use bindgen::{clang_version, Builder}; use owo_colors::{OwoColorize, Style}; use similar::{ChangeTag, TextDiff}; diff --git a/bindgen/codegen/dyngen.rs b/bindgen/codegen/dyngen.rs index c067fada0e..b26c0b1817 100644 --- a/bindgen/codegen/dyngen.rs +++ b/bindgen/codegen/dyngen.rs @@ -90,8 +90,6 @@ impl DynamicItems { }; quote! { - extern crate libloading; - pub struct #lib_ident { __library: ::libloading::Library, #(#struct_members)* diff --git a/bindgen/features.rs b/bindgen/features.rs index fa3f20d717..6ac1d6a16d 100644 --- a/bindgen/features.rs +++ b/bindgen/features.rs @@ -231,7 +231,6 @@ impl Default for RustFeatures { #[cfg(test)] mod test { - #![allow(unused_imports)] use super::*; #[test] diff --git a/book/src/non-system-libraries.md b/book/src/non-system-libraries.md index d5d288d101..b080db80d7 100644 --- a/book/src/non-system-libraries.md +++ b/book/src/non-system-libraries.md @@ -17,8 +17,6 @@ Given that the library has not been compiled yet, we need to modify the library: ```rust,ignore -extern crate bindgen; - use std::env; use std::path::PathBuf; From 6e42ccff1590f732c6c57fdaf9f69df2ede84a88 Mon Sep 17 00:00:00 2001 From: John Baublitz Date: Mon, 1 Apr 2024 16:32:25 -0400 Subject: [PATCH 651/942] Workaround for expansion of function-like macros (#2779) This commit resolves an issue where macros that evaluate to a constant but have a function like macro in the macro body would not be properly expanded by cexpr. This adds an opt-in option to use Clang on intermediary files to evaluate the macros one by one. This is opt-in largely because of the compile time implications. --- bindgen-cli/options.rs | 16 +++ .../tests/expectations/tests/issue-753.rs | 4 + .../tests/libclang-9/issue-753.rs | 1 + bindgen-tests/tests/headers/issue-753.h | 7 ++ bindgen/clang.rs | 105 ++++++++++++++++++ bindgen/ir/context.rs | 76 +++++++++++++ bindgen/ir/var.rs | 46 +++++++- bindgen/options/mod.rs | 37 +++++- 8 files changed, 287 insertions(+), 5 deletions(-) create mode 100644 bindgen-tests/tests/expectations/tests/issue-753.rs create mode 100644 bindgen-tests/tests/expectations/tests/libclang-9/issue-753.rs create mode 100644 bindgen-tests/tests/headers/issue-753.h diff --git a/bindgen-cli/options.rs b/bindgen-cli/options.rs index 66bb3f1439..815a28f42a 100644 --- a/bindgen-cli/options.rs +++ b/bindgen-cli/options.rs @@ -400,6 +400,12 @@ struct BindgenCommand { /// Wrap unsafe operations in unsafe blocks. #[arg(long)] wrap_unsafe_ops: bool, + /// Enable fallback for clang macro parsing. + #[arg(long)] + clang_macro_fallback: bool, + /// Set path for temporary files generated by fallback for clang macro parsing. + #[arg(long)] + clang_macro_fallback_build_dir: Option, /// Derive custom traits on any kind of type. The CUSTOM value must be of the shape REGEX=DERIVE where DERIVE is a coma-separated list of derive macros. #[arg(long, value_name = "CUSTOM", value_parser = parse_custom_derive)] with_derive_custom: Vec<(Vec, String)>, @@ -554,6 +560,8 @@ where merge_extern_blocks, override_abi, wrap_unsafe_ops, + clang_macro_fallback, + clang_macro_fallback_build_dir, with_derive_custom, with_derive_custom_struct, with_derive_custom_enum, @@ -1023,6 +1031,14 @@ where builder = builder.wrap_unsafe_ops(true); } + if clang_macro_fallback { + builder = builder.clang_macro_fallback(); + } + + if let Some(path) = clang_macro_fallback_build_dir { + builder = builder.clang_macro_fallback_build_dir(path); + } + #[derive(Debug)] struct CustomDeriveCallback { derives: Vec, diff --git a/bindgen-tests/tests/expectations/tests/issue-753.rs b/bindgen-tests/tests/expectations/tests/issue-753.rs new file mode 100644 index 0000000000..3119ec569e --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/issue-753.rs @@ -0,0 +1,4 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub const CONST: u32 = 5; +pub const OTHER_CONST: u32 = 6; +pub const LARGE_CONST: u32 = 1536; diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/issue-753.rs b/bindgen-tests/tests/expectations/tests/libclang-9/issue-753.rs new file mode 100644 index 0000000000..fe64295a68 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/libclang-9/issue-753.rs @@ -0,0 +1 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] \ No newline at end of file diff --git a/bindgen-tests/tests/headers/issue-753.h b/bindgen-tests/tests/headers/issue-753.h new file mode 100644 index 0000000000..94bb8e1c31 --- /dev/null +++ b/bindgen-tests/tests/headers/issue-753.h @@ -0,0 +1,7 @@ +// bindgen-flags: --clang-macro-fallback + +#define UINT32_C(c) c ## U + +#define CONST UINT32_C(5) +#define OTHER_CONST UINT32_C(6) +#define LARGE_CONST UINT32_C(6 << 8) diff --git a/bindgen/clang.rs b/bindgen/clang.rs index a9a0ec814f..04465b6be9 100644 --- a/bindgen/clang.rs +++ b/bindgen/clang.rs @@ -10,6 +10,7 @@ use std::cmp; use std::ffi::{CStr, CString}; use std::fmt; +use std::fs::OpenOptions; use std::hash::Hash; use std::hash::Hasher; use std::os::raw::{c_char, c_int, c_longlong, c_uint, c_ulong, c_ulonglong}; @@ -1868,6 +1869,27 @@ impl TranslationUnit { } } + /// Save a translation unit to the given file. + pub(crate) fn save(&mut self, file: &str) -> Result<(), CXSaveError> { + let file = if let Ok(cstring) = CString::new(file) { + cstring + } else { + return Err(CXSaveError_Unknown); + }; + let ret = unsafe { + clang_saveTranslationUnit( + self.x, + file.as_ptr(), + clang_defaultSaveOptions(self.x), + ) + }; + if ret != 0 { + Err(ret) + } else { + Ok(()) + } + } + /// Is this the null translation unit? pub(crate) fn is_null(&self) -> bool { self.x.is_null() @@ -1882,6 +1904,89 @@ impl Drop for TranslationUnit { } } +/// Translation unit used for macro fallback parsing +pub(crate) struct FallbackTranslationUnit { + file_path: String, + pch_paths: Vec, + idx: Box, + tu: TranslationUnit, +} + +impl fmt::Debug for FallbackTranslationUnit { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + write!(fmt, "FallbackTranslationUnit {{ }}") + } +} + +impl FallbackTranslationUnit { + /// Create a new fallback translation unit + pub(crate) fn new( + file: String, + pch_paths: Vec, + c_args: &[Box], + ) -> Option { + // Create empty file + OpenOptions::new() + .write(true) + .create(true) + .truncate(true) + .open(&file) + .ok()?; + + let f_index = Box::new(Index::new(true, false)); + let f_translation_unit = TranslationUnit::parse( + &f_index, + &file, + c_args, + &[], + CXTranslationUnit_None, + )?; + Some(FallbackTranslationUnit { + file_path: file, + pch_paths, + tu: f_translation_unit, + idx: f_index, + }) + } + + /// Get reference to underlying translation unit. + pub(crate) fn translation_unit(&self) -> &TranslationUnit { + &self.tu + } + + /// Reparse a translation unit. + pub(crate) fn reparse( + &mut self, + unsaved_contents: &str, + ) -> Result<(), CXErrorCode> { + let unsaved = &[UnsavedFile::new(&self.file_path, unsaved_contents)]; + let mut c_unsaved: Vec = + unsaved.iter().map(|f| f.x).collect(); + let ret = unsafe { + clang_reparseTranslationUnit( + self.tu.x, + unsaved.len() as c_uint, + c_unsaved.as_mut_ptr(), + clang_defaultReparseOptions(self.tu.x), + ) + }; + if ret != 0 { + Err(ret) + } else { + Ok(()) + } + } +} + +impl Drop for FallbackTranslationUnit { + fn drop(&mut self) { + let _ = std::fs::remove_file(&self.file_path); + for pch in self.pch_paths.iter() { + let _ = std::fs::remove_file(pch); + } + } +} + /// A diagnostic message generated while parsing a translation unit. pub(crate) struct Diagnostic { x: CXDiagnostic, diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index 26247cdcc5..c4465df9ec 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -30,6 +30,7 @@ use std::borrow::Cow; use std::cell::{Cell, RefCell}; use std::collections::{BTreeSet, HashMap as StdHashMap}; use std::mem; +use std::path::Path; /// An identifier for some kind of IR item. #[derive(Debug, Copy, Clone, Eq, PartialOrd, Ord, Hash)] @@ -376,6 +377,9 @@ pub(crate) struct BindgenContext { /// The translation unit for parsing. translation_unit: clang::TranslationUnit, + /// The translation unit for macro fallback parsing. + fallback_tu: Option, + /// Target information that can be useful for some stuff. target_info: clang::TargetInfo, @@ -584,6 +588,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" collected_typerefs: false, in_codegen: false, translation_unit, + fallback_tu: None, target_info, options, generated_bindgen_complex: Cell::new(false), @@ -2060,6 +2065,77 @@ If you encounter an error missing from this list, please file an issue or a PR!" &self.translation_unit } + /// Initialize fallback translation unit if it does not exist and + /// then return a mutable reference to the fallback translation unit. + pub(crate) fn try_ensure_fallback_translation_unit( + &mut self, + ) -> Option<&mut clang::FallbackTranslationUnit> { + if self.fallback_tu.is_none() { + let file = format!( + "{}/.macro_eval.c", + match self.options().clang_macro_fallback_build_dir { + Some(ref path) => path.as_os_str().to_str()?, + None => ".", + } + ); + + let index = clang::Index::new(false, false); + + let mut c_args = Vec::new(); + let mut pch_paths = Vec::new(); + for input_header in self.options().input_headers.iter() { + let path = Path::new(input_header.as_ref()); + let header_name = path + .file_name() + .and_then(|hn| hn.to_str()) + .map(|s| s.to_owned()); + let header_path = path + .parent() + .and_then(|hp| hp.to_str()) + .map(|s| s.to_owned()); + + let (header, pch) = if let (Some(ref hp), Some(hn)) = + (header_path, header_name) + { + let header_path = if hp.is_empty() { "." } else { hp }; + let header = format!("{header_path}/{hn}"); + let pch_path = if let Some(ref path) = + self.options().clang_macro_fallback_build_dir + { + path.as_os_str().to_str()? + } else { + header_path + }; + (header, format!("{pch_path}/{hn}.pch")) + } else { + return None; + }; + + let mut tu = clang::TranslationUnit::parse( + &index, + &header, + &[ + "-x".to_owned().into_boxed_str(), + "c-header".to_owned().into_boxed_str(), + ], + &[], + clang_sys::CXTranslationUnit_ForSerialization, + )?; + tu.save(&pch).ok()?; + + c_args.push("-include-pch".to_string().into_boxed_str()); + c_args.push(pch.clone().into_boxed_str()); + pch_paths.push(pch); + } + + self.fallback_tu = Some(clang::FallbackTranslationUnit::new( + file, pch_paths, &c_args, + )?); + } + + self.fallback_tu.as_mut() + } + /// Have we parsed the macro named `macro_name` already? pub(crate) fn parsed_macro(&self, macro_name: &[u8]) -> bool { self.parsed_macros.contains_key(macro_name) diff --git a/bindgen/ir/var.rs b/bindgen/ir/var.rs index a548ec881b..a970cf1588 100644 --- a/bindgen/ir/var.rs +++ b/bindgen/ir/var.rs @@ -389,9 +389,51 @@ impl ClangSubItemParser for Var { } } +/// This function uses a [`FallbackTranslationUnit`][clang::FallbackTranslationUnit] to parse each +/// macro that cannot be parsed by the normal bindgen process for `#define`s. +/// +/// To construct the [`FallbackTranslationUnit`][clang::FallbackTranslationUnit], first precompiled +/// headers are generated for all input headers. An empty temporary `.c` file is generated to pass +/// to the translation unit. On the evaluation of each macro, a [`String`] is generated with the +/// new contents of the empty file and passed in for reparsing. The precompiled headers and +/// preservation of the [`FallbackTranslationUnit`][clang::FallbackTranslationUnit] across macro +/// evaluations are both optimizations that have significantly improved the performance. +fn parse_macro_clang_fallback( + ctx: &mut BindgenContext, + cursor: &clang::Cursor, +) -> Option<(Vec, cexpr::expr::EvalResult)> { + if !ctx.options().clang_macro_fallback { + return None; + } + + let ftu = ctx.try_ensure_fallback_translation_unit()?; + let contents = format!("int main() {{ {}; }}", cursor.spelling(),); + ftu.reparse(&contents).ok()?; + // Children of root node of AST + let root_children = ftu.translation_unit().cursor().collect_children(); + // Last child in root is function declaration + // Should be FunctionDecl + let main_func = root_children.last()?; + // Children should all be statements in function declaration + let all_stmts = main_func.collect_children(); + // First child in all_stmts should be the statement containing the macro to evaluate + // Should be CompoundStmt + let macro_stmt = all_stmts.first()?; + // Children should all be expressions from the compound statement + let paren_exprs = macro_stmt.collect_children(); + // First child in all_exprs is the expression utilizing the given macro to be evaluated + // Should be ParenExpr + let paren = paren_exprs.first()?; + + Some(( + cursor.spelling().into_bytes(), + cexpr::expr::EvalResult::Int(Wrapping(paren.evaluate()?.as_int()?)), + )) +} + /// Try and parse a macro using all the macros parsed until now. fn parse_macro( - ctx: &BindgenContext, + ctx: &mut BindgenContext, cursor: &clang::Cursor, ) -> Option<(Vec, cexpr::expr::EvalResult)> { use cexpr::expr; @@ -402,7 +444,7 @@ fn parse_macro( match parser.macro_definition(&cexpr_tokens) { Ok((_, (id, val))) => Some((id.into(), val)), - _ => None, + _ => parse_macro_clang_fallback(ctx, cursor), } } diff --git a/bindgen/options/mod.rs b/bindgen/options/mod.rs index 3b3224caf0..dc453b13aa 100644 --- a/bindgen/options/mod.rs +++ b/bindgen/options/mod.rs @@ -21,9 +21,7 @@ use crate::HashMap; use crate::DEFAULT_ANON_FIELDS_PREFIX; use std::env; -#[cfg(feature = "experimental")] -use std::path::Path; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use std::rc::Rc; use as_args::AsArgs; @@ -2107,5 +2105,38 @@ options! { } }, as_args: "--emit-diagnostics", + }, + /// Whether to use Clang evaluation on temporary files as a fallback for macros that fail to + /// parse. + clang_macro_fallback: bool { + methods: { + /// Use Clang as a fallback for macros that fail to parse using `CExpr`. + /// + /// This uses a workaround to evaluate each macro in a temporary file. Because this + /// results in slower compilation, this option is opt-in. + pub fn clang_macro_fallback(mut self) -> Self { + self.options.clang_macro_fallback = true; + self + } + }, + as_args: "--clang-macro-fallback", + } + /// Path to use for temporary files created by clang macro fallback code like precompiled + /// headers. + clang_macro_fallback_build_dir: Option { + methods: { + /// Set a path to a directory to which `.c` and `.h.pch` files should be written for the + /// purpose of using clang to evaluate macros that can't be easily parsed. + /// + /// The default location for `.h.pch` files is the directory that the corresponding + /// `.h` file is located in. The default for the temporary `.c` file used for clang + /// parsing is the current working directory. Both of these defaults are overridden + /// by this option. + pub fn clang_macro_fallback_build_dir>(mut self, path: P) -> Self { + self.options.clang_macro_fallback_build_dir = Some(path.as_ref().to_owned()); + self + } + }, + as_args: "--clang-macro-fallback-build-dir", } } From 0c32f2ef2f989e25c65b2ed40cdbe252d1112b7d Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Mon, 1 Apr 2024 22:32:36 +0200 Subject: [PATCH 652/942] more release automation (#2796) * automatically publish after cli release is created * a more accurate term * explain --no-publish --- .github/workflows/publish.yml | 13 ++++++++----- CONTRIBUTING.md | 6 +++++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index f79ce1036b..1fbc15049d 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,13 +1,16 @@ -# To trigger this: -# - go to Actions > Publish -# - click the Run Workflow dropdown in the top-right -name: Publish -on: workflow_dispatch +# This is triggered after the Release workflow successfully completes its run +on: + workflow_run: + workflows: + - Release + types: + - completed env: CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} jobs: cargo-publish: runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'success' }} steps: - name: Checkout sources uses: actions/checkout@v3 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 67e913455a..af069be2da 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -563,7 +563,7 @@ cargo release [patch|minor] --no-publish --execute This does the following: - Bump the version. -- Turn the `Unreleased` section of the changelog into the section for the version being published. +- Turn the `Unreleased` section of the changelog into the section for the version being released. - Update the table of contents of the changelog using `doctoc`. - Tag (`git tag`) the HEAD commit - Push (`git push`) to GitHub @@ -573,6 +573,10 @@ The `patch` and `minor` refer to semver concepts: - `patch` would bump __v0.68.1__ to __v0.68.2__ - `minor` would bump __v0.68.2__ to __v0.69.0__ +> NOTE: +> We use the `--no-publish` so that the crates are only published after the release is complete. +> This is automatic, provided the release CI job is successful. + ### Create a new release on Github The release is automated with the help of `.github/workflows/release.yml`, From fb39a30a052bbc3c4e7afe78c5c1655622094d9d Mon Sep 17 00:00:00 2001 From: Sun Bin <165283125+shandongbinzhou@users.noreply.github.com> Date: Tue, 2 Apr 2024 04:32:52 +0800 Subject: [PATCH 653/942] chore: fix some comments (#2798) Signed-off-by: shandongbinzhou Co-authored-by: shandongbinzhou --- bindgen-tests/tests/expectations/tests/enum-doc-bitfield.rs | 6 +++--- bindgen-tests/tests/expectations/tests/enum-doc-mod.rs | 6 +++--- bindgen-tests/tests/expectations/tests/enum-doc-rusty.rs | 6 +++--- bindgen-tests/tests/expectations/tests/enum-doc.rs | 6 +++--- .../tests/expectations/tests/issue-537-repr-packed-n.rs | 4 ++-- bindgen-tests/tests/headers/enum-doc.h | 6 +++--- bindgen-tests/tests/headers/issue-537-repr-packed-n.h | 4 ++-- bindgen-tests/tests/headers/template-param-usage-7.hpp | 2 +- bindgen-tests/tests/headers/wrap-static-fns.h | 2 +- bindgen/codegen/mod.rs | 2 +- bindgen/ir/analysis/has_type_param_in_array.rs | 2 +- bindgen/options/mod.rs | 2 +- book/src/cpp.md | 2 +- book/src/using-unions.md | 4 ++-- 14 files changed, 27 insertions(+), 27 deletions(-) diff --git a/bindgen-tests/tests/expectations/tests/enum-doc-bitfield.rs b/bindgen-tests/tests/expectations/tests/enum-doc-bitfield.rs index e6e9ffaa65..ba73a8ea3e 100644 --- a/bindgen-tests/tests/expectations/tests/enum-doc-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/enum-doc-bitfield.rs @@ -4,11 +4,11 @@ impl B { pub const VAR_A: B = B(0); } impl B { - /// Document field with preceeding star + /// Document field with preceding star pub const VAR_B: B = B(1); } impl B { - /// Document field with preceeding exclamation + /// Document field with preceding exclamation pub const VAR_C: B = B(2); } impl B { @@ -20,7 +20,7 @@ impl B { pub const VAR_E: B = B(4); } impl B { - /** Document field with preceeding star, with a loong long multiline + /** Document field with preceding star, with a loong long multiline comment. Very interesting documentation, definitely.*/ diff --git a/bindgen-tests/tests/expectations/tests/enum-doc-mod.rs b/bindgen-tests/tests/expectations/tests/enum-doc-mod.rs index c54410e271..2b18b35df0 100644 --- a/bindgen-tests/tests/expectations/tests/enum-doc-mod.rs +++ b/bindgen-tests/tests/expectations/tests/enum-doc-mod.rs @@ -4,15 +4,15 @@ pub mod B { pub type Type = ::std::os::raw::c_uint; /// Document field with three slashes pub const VAR_A: Type = 0; - /// Document field with preceeding star + /// Document field with preceding star pub const VAR_B: Type = 1; - /// Document field with preceeding exclamation + /// Document field with preceding exclamation pub const VAR_C: Type = 2; ///< Document field with following star pub const VAR_D: Type = 3; ///< Document field with following exclamation pub const VAR_E: Type = 4; - /** Document field with preceeding star, with a loong long multiline + /** Document field with preceding star, with a loong long multiline comment. Very interesting documentation, definitely.*/ diff --git a/bindgen-tests/tests/expectations/tests/enum-doc-rusty.rs b/bindgen-tests/tests/expectations/tests/enum-doc-rusty.rs index a83d2dc458..3eec0759c5 100644 --- a/bindgen-tests/tests/expectations/tests/enum-doc-rusty.rs +++ b/bindgen-tests/tests/expectations/tests/enum-doc-rusty.rs @@ -5,15 +5,15 @@ pub enum B { /// Document field with three slashes VAR_A = 0, - /// Document field with preceeding star + /// Document field with preceding star VAR_B = 1, - /// Document field with preceeding exclamation + /// Document field with preceding exclamation VAR_C = 2, ///< Document field with following star VAR_D = 3, ///< Document field with following exclamation VAR_E = 4, - /** Document field with preceeding star, with a loong long multiline + /** Document field with preceding star, with a loong long multiline comment. Very interesting documentation, definitely.*/ diff --git a/bindgen-tests/tests/expectations/tests/enum-doc.rs b/bindgen-tests/tests/expectations/tests/enum-doc.rs index ee0ca23bff..98a7eed8f8 100644 --- a/bindgen-tests/tests/expectations/tests/enum-doc.rs +++ b/bindgen-tests/tests/expectations/tests/enum-doc.rs @@ -1,15 +1,15 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] /// Document field with three slashes pub const B_VAR_A: B = 0; -/// Document field with preceeding star +/// Document field with preceding star pub const B_VAR_B: B = 1; -/// Document field with preceeding exclamation +/// Document field with preceding exclamation pub const B_VAR_C: B = 2; ///< Document field with following star pub const B_VAR_D: B = 3; ///< Document field with following exclamation pub const B_VAR_E: B = 4; -/** Document field with preceeding star, with a loong long multiline +/** Document field with preceding star, with a loong long multiline comment. Very interesting documentation, definitely.*/ 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 3042551585..0142673f3e 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 @@ -23,7 +23,7 @@ fn bindgen_test_layout_AlignedToOne() { "Offset of field: AlignedToOne::i", ); } -/// This should be be packed because Rust 1.33 has `#[repr(packed(N))]`. +/// This should be packed because Rust 1.33 has `#[repr(packed(N))]`. #[repr(C, packed(2))] #[derive(Debug, Default, Copy, Clone)] pub struct AlignedToTwo { @@ -75,7 +75,7 @@ fn bindgen_test_layout_PackedToOne() { "Offset of field: PackedToOne::y", ); } -/// This should be be packed because Rust 1.33 has `#[repr(packed(N))]`. +/// This should be packed because Rust 1.33 has `#[repr(packed(N))]`. #[repr(C, packed(2))] #[derive(Debug, Default, Copy, Clone)] pub struct PackedToTwo { diff --git a/bindgen-tests/tests/headers/enum-doc.h b/bindgen-tests/tests/headers/enum-doc.h index 58e2c69e13..7a2f425cda 100644 --- a/bindgen-tests/tests/headers/enum-doc.h +++ b/bindgen-tests/tests/headers/enum-doc.h @@ -2,14 +2,14 @@ enum B { /// Document field with three slashes VAR_A = 0, - /** Document field with preceeding star */ + /** Document field with preceding star */ VAR_B = 1, - /*! Document field with preceeding exclamation */ + /*! Document field with preceding exclamation */ VAR_C = 2, VAR_D = 3, /**< Document field with following star */ VAR_E = 4, /*!< Document field with following exclamation */ /** - * Document field with preceeding star, with a loong long multiline + * Document field with preceding star, with a loong long multiline * comment. * * Very interesting documentation, definitely. 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 f4c0070a4a..7beaf88383 100644 --- a/bindgen-tests/tests/headers/issue-537-repr-packed-n.h +++ b/bindgen-tests/tests/headers/issue-537-repr-packed-n.h @@ -6,7 +6,7 @@ struct AlignedToOne { int i; } __attribute__ ((packed,aligned(1))); -/// This should be be packed because Rust 1.33 has `#[repr(packed(N))]`. +/// This should be packed because Rust 1.33 has `#[repr(packed(N))]`. struct AlignedToTwo { int i; } __attribute__ ((packed,aligned(2))); @@ -25,7 +25,7 @@ struct PackedToOne { #pragma pack(2) -/// This should be be packed because Rust 1.33 has `#[repr(packed(N))]`. +/// This should be packed because Rust 1.33 has `#[repr(packed(N))]`. struct PackedToTwo { int x; int y; diff --git a/bindgen-tests/tests/headers/template-param-usage-7.hpp b/bindgen-tests/tests/headers/template-param-usage-7.hpp index 99d4cc71b4..3d70cee145 100644 --- a/bindgen-tests/tests/headers/template-param-usage-7.hpp +++ b/bindgen-tests/tests/headers/template-param-usage-7.hpp @@ -6,5 +6,5 @@ class DoesNotUseU { V v; }; -// The bool should go away becuase U is not used. +// The bool should go away because U is not used. using Alias = DoesNotUseU; diff --git a/bindgen-tests/tests/headers/wrap-static-fns.h b/bindgen-tests/tests/headers/wrap-static-fns.h index 131b7ab15f..2be7bd93d9 100644 --- a/bindgen-tests/tests/headers/wrap-static-fns.h +++ b/bindgen-tests/tests/headers/wrap-static-fns.h @@ -1,7 +1,7 @@ // bindgen-flags: --experimental --wrap-static-fns // bindgen-parse-callbacks: wrap-as-variadic-fn -// to avoid poluting theexpectation tests we put the stdarg.h behind a conditional +// to avoid polluting the expectation tests we put the stdarg.h behind a conditional // variable only used in bindgen-integration #ifdef USE_VA_HEADER #include diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 4e1bf1b6fc..b6f915a833 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -2557,7 +2557,7 @@ impl CodeGenerator for CompInfo { }; // Note we use `ptr::write_bytes()` instead of `mem::zeroed()` because the latter does // not necessarily ensure padding bytes are zeroed. Some C libraries are sensitive to - // non-zero padding bytes, especially when forwards/backwards compatability is + // non-zero padding bytes, especially when forwards/backwards compatibility is // involved. result.push(quote! { impl #generics Default for #ty_for_impl { diff --git a/bindgen/ir/analysis/has_type_param_in_array.rs b/bindgen/ir/analysis/has_type_param_in_array.rs index 088c08f542..6665547ca6 100644 --- a/bindgen/ir/analysis/has_type_param_in_array.rs +++ b/bindgen/ir/analysis/has_type_param_in_array.rs @@ -17,7 +17,7 @@ use crate::{HashMap, HashSet}; /// * If T is a type alias, a templated alias or an indirection to another type, /// it has type parameter in array if the type T refers to has. /// * If T is a compound type, it has array if any of base memter or field -/// has type paramter in array. +/// has type parameter in array. /// * If T is an instantiation of an abstract template definition, T has /// type parameter in array if any of the template arguments or template definition /// has. diff --git a/bindgen/options/mod.rs b/bindgen/options/mod.rs index dc453b13aa..f374d20732 100644 --- a/bindgen/options/mod.rs +++ b/bindgen/options/mod.rs @@ -1981,7 +1981,7 @@ options! { }, as_args: "--wrap-unsafe-ops", }, - /// Patterns for functions whose ABI should be overriden. + /// Patterns for functions whose ABI should be overridden. abi_overrides: HashMap { methods: { regex_option! { diff --git a/book/src/cpp.md b/book/src/cpp.md index 9b451b9d35..db368f6787 100644 --- a/book/src/cpp.md +++ b/book/src/cpp.md @@ -154,6 +154,6 @@ instance.assume_init_mut().method(); ``` You can easily verify this fact if you provide a implementation for `MyClass` -and `method` that prints the the `this` pointer address. However, you can +and `method` that prints the `this` pointer address. However, you can ignore this fact if you know that the original C++ code does not rely on the instance address in its internal logic. diff --git a/book/src/using-unions.md b/book/src/using-unions.md index 9e8e9b99d7..5ae764a33d 100644 --- a/book/src/using-unions.md +++ b/book/src/using-unions.md @@ -66,11 +66,11 @@ When using the `union` builtin type, there are two choices for initialization: mod bindings_builtin_union; fn union_builtin() { - // Initalize the union to zero + // Initialize the union to zero let x = bindings_builtin_union::greek_t::default(); // If `--with-derive-default` option is not used, the following may be used - // to initalize the union to zero: + // to initialize the union to zero: let x = unsafe { std::mem::zeroed::() }; // Or, it is possible to initialize exactly one variant of the enum: From 2126d83f7542b8dd627eb79d6f057bd953656e77 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Mon, 1 Apr 2024 22:33:11 +0200 Subject: [PATCH 654/942] remove redundant import (#2795) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Emilio Cobos Álvarez --- bindgen/ir/analysis/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindgen/ir/analysis/mod.rs b/bindgen/ir/analysis/mod.rs index 443384a487..8115944e3c 100644 --- a/bindgen/ir/analysis/mod.rs +++ b/bindgen/ir/analysis/mod.rs @@ -216,7 +216,7 @@ where #[cfg(test)] mod tests { use super::*; - use crate::{HashMap, HashSet}; + use crate::HashSet; // Here we find the set of nodes that are reachable from any given // node. This is a lattice mapping nodes to subsets of all nodes. Our join From 8d6f69c9c1366a31eb4fca1ff811cecb435b3b65 Mon Sep 17 00:00:00 2001 From: Jeremy Fitzhardinge Date: Sun, 25 Feb 2024 00:38:34 -0800 Subject: [PATCH 655/942] Add --flexarray-dst option This option uses Rust DST types to model C structures with flexible array members. For example, if you declare: ```c struct record { int len; float values[]; } ``` this means it's a C structure with a well-defined prefix, but a tail of `values` which depends on how much memory we've allocated for it. We can model this in Rust with: ```rust struct record { len: c_int, values: [f32], } ``` which means more or less the same thing - there's a type which has a known prefix, but its suffix is not directly known. --- bindgen-cli/options.rs | 8 ++ bindgen/codegen/mod.rs | 165 ++++++++++++++++++++++++++++--- bindgen/codegen/struct_layout.rs | 11 +++ bindgen/features.rs | 2 + bindgen/ir/comp.rs | 26 +++++ bindgen/options/mod.rs | 13 +++ 6 files changed, 213 insertions(+), 12 deletions(-) diff --git a/bindgen-cli/options.rs b/bindgen-cli/options.rs index 815a28f42a..5edc8c95e5 100644 --- a/bindgen-cli/options.rs +++ b/bindgen-cli/options.rs @@ -406,6 +406,9 @@ struct BindgenCommand { /// Set path for temporary files generated by fallback for clang macro parsing. #[arg(long)] clang_macro_fallback_build_dir: Option, + /// Use DSTs to represent structures with flexible array members. + #[arg(long)] + flexarray_dst: bool, /// Derive custom traits on any kind of type. The CUSTOM value must be of the shape REGEX=DERIVE where DERIVE is a coma-separated list of derive macros. #[arg(long, value_name = "CUSTOM", value_parser = parse_custom_derive)] with_derive_custom: Vec<(Vec, String)>, @@ -562,6 +565,7 @@ where wrap_unsafe_ops, clang_macro_fallback, clang_macro_fallback_build_dir, + flexarray_dst, with_derive_custom, with_derive_custom_struct, with_derive_custom_enum, @@ -1039,6 +1043,10 @@ where builder = builder.clang_macro_fallback_build_dir(path); } + if flexarray_dst { + builder = builder.flexarray_dst(true); + } + #[derive(Debug)] struct CustomDeriveCallback { derives: Vec, diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index b6f915a833..c2da991e1f 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -1454,10 +1454,13 @@ impl<'a> FieldCodegen<'a> for FieldData { wrap_union_field_if_needed(ctx, struct_layout, ty, result) } else if let Some(item) = field_ty.is_incomplete_array(ctx) { result.saw_incomplete_array(); + struct_layout.saw_flexible_array(); let inner = item.to_rust_ty_or_opaque(ctx, &()); - if ctx.options().enable_cxx_namespaces { + if ctx.options().flexarray_dst { + syn::parse_quote! { FAM } + } else if ctx.options().enable_cxx_namespaces { syn::parse_quote! { root::__IncompleteArrayField<#inner> } } else { syn::parse_quote! { __IncompleteArrayField<#inner> } @@ -2208,20 +2211,60 @@ impl CodeGenerator for CompInfo { }); } - let generics = if !generic_param_names.is_empty() { - let generic_param_names = generic_param_names.clone(); - quote! { - < #( #generic_param_names ),* > + let (flex_array_generic, flex_inner_ty) = if ctx.options().flexarray_dst + { + match self.flex_array_member(ctx) { + Some(ty) => { + let inner = ty.to_rust_ty_or_opaque(ctx, &()); + ( + Some(quote! { FAM: ?Sized = [ #inner; 0 ] }), + Some(quote! { #inner }), + ) + } + None => (None, None), } } else { - quote! {} + (None, None) }; + // Generics, including the flexible array member. + // + // generics - generic parameters for the struct declaration + // impl_generics_labels - generic parameters for `impl<...>` + // impl_generics_params - generic parameters for `impl structname<...>` + // + // `impl` blocks are for non-FAM related impls like Default, etc + let (generics, impl_generics_labels, impl_generics_params) = + if !generic_param_names.is_empty() || flex_array_generic.is_some() { + let (flex_sized, flex_fam) = match flex_inner_ty.as_ref() { + None => (None, None), + Some(ty) => ( + Some(quote! { [ #ty; 0 ] }), + Some(quote! { FAM: ?Sized = [ #ty; 0 ] }), + ), + }; + + ( + quote! { + < #( #generic_param_names , )* #flex_fam > + }, + quote! { + < #( #generic_param_names , )* > + }, + quote! { + < #( #generic_param_names , )* #flex_sized > + }, + ) + } else { + (quote! {}, quote! {}, quote! {}) + }; + let mut attributes = vec![]; let mut needs_clone_impl = false; let mut needs_default_impl = false; let mut needs_debug_impl = false; let mut needs_partialeq_impl = false; + let needs_flexarray_impl = flex_array_generic.is_some(); if let Some(comment) = item.comment(ctx) { attributes.push(attributes::doc(comment)); } @@ -2525,17 +2568,112 @@ impl CodeGenerator for CompInfo { // NB: We can't use to_rust_ty here since for opaque types this tries to // use the specialization knowledge to generate a blob field. let ty_for_impl = quote! { - #canonical_ident #generics + #canonical_ident #impl_generics_params }; if needs_clone_impl { result.push(quote! { - impl #generics Clone for #ty_for_impl { + impl #impl_generics_labels Clone for #ty_for_impl { fn clone(&self) -> Self { *self } } }); } + if needs_flexarray_impl { + let prefix = ctx.trait_prefix(); + + let flex_array = + flex_inner_ty.as_ref().map(|ty| quote! { [ #ty ] }); + + let dst_ty_for_impl = quote! { + #canonical_ident < #( #generic_param_names , )* #flex_array > + + }; + let sized_ty_for_impl = quote! { + #canonical_ident < #( #generic_param_names , )* [ #flex_inner_ty; 0 ] > + }; + + let turbo_dst_ty = quote! { + #canonical_ident :: < #( #generic_param_names , )* [ #flex_inner_ty ] > + }; + + let layout = if ctx.options().rust_features().layout_for_ptr { + quote! { + pub fn layout(len: usize) -> ::#prefix::alloc::Layout { + // SAFETY: Null pointers are OK if we don't deref them + unsafe { + let p: *const Self = ::#prefix::ptr::from_raw_parts(::#prefix::ptr::null(), len); + ::#prefix::alloc::Layout::for_value_raw(p) + } + } + } + } else { + quote!() + }; + + let (from_ptr_dst, from_ptr_sized) = if ctx + .options() + .rust_features() + .ptr_metadata + { + ( + quote! { + /// Construct a DST for `#canonical_ident` from a thin + /// pointer. + /// + /// SAFETY: the `len` must be <= the underlying storage. + /// Note: returned lifetime is unbounded. + pub unsafe fn from_ptr<'a>(ptr: *const #sized_ty_for_impl, len: usize) -> &'a Self { + let ptr: *const Self = ::#prefix::ptr::from_raw_parts(ptr as *const (), len); + &*ptr + } + + /// Construct a mutable DST for `#canonical_ident` from + /// a thin pointer. This is `MaybeUninit` to allow for + /// initialization. + /// + /// SAFETY: the `len` must be <= the underlying storage. + /// Note: returned lifetime is unbounded. + pub unsafe fn from_ptr_mut<'a>(ptr: *mut #sized_ty_for_impl, len: usize) -> ::#prefix::mem::MaybeUninit<&'a mut Self> { + let ptr: *mut Self = ::#prefix::ptr::from_raw_parts_mut(ptr as *mut (), len); + ::#prefix::mem::MaybeUninit::new(&mut *ptr) + } + }, + quote! { + /// Turn a sized reference for `#canonical_ident` into + /// DST with the given `len`. + /// + /// SAFETY: the `len` must be <= the underlying storage. + pub unsafe fn from_ref(&self, len: usize) -> & #dst_ty_for_impl { + // SAFETY: caller guarantees `len` is good + unsafe { #turbo_dst_ty :: from_ptr(self, len) } + } + + /// Turn a mutable sized reference for + /// `#canonical_ident` into DST with the given `len`. + /// + /// SAFETY: the `len` must be <= the underlying storage. + pub unsafe fn from_ref_mut(&mut self, len: usize) -> &mut #dst_ty_for_impl { + unsafe { #turbo_dst_ty :: from_ptr_mut(self, len).assume_init() } + } + }, + ) + } else { + (quote!(), quote!()) + }; + + result.push(quote! { + impl #impl_generics_labels #dst_ty_for_impl { + #layout + #from_ptr_dst + } + + impl #impl_generics_labels #sized_ty_for_impl { + #from_ptr_sized + } + }); + } + if needs_default_impl { let prefix = ctx.trait_prefix(); let body = if ctx.options().rust_features().maybe_uninit { @@ -2560,7 +2698,7 @@ impl CodeGenerator for CompInfo { // non-zero padding bytes, especially when forwards/backwards compatibility is // involved. result.push(quote! { - impl #generics Default for #ty_for_impl { + impl #impl_generics_labels Default for #ty_for_impl { fn default() -> Self { #body } @@ -2579,7 +2717,7 @@ impl CodeGenerator for CompInfo { let prefix = ctx.trait_prefix(); result.push(quote! { - impl #generics ::#prefix::fmt::Debug for #ty_for_impl { + impl #impl_generics_labels ::#prefix::fmt::Debug for #ty_for_impl { #impl_ } }); @@ -2603,7 +2741,7 @@ impl CodeGenerator for CompInfo { let prefix = ctx.trait_prefix(); result.push(quote! { - impl #generics ::#prefix::cmp::PartialEq for #ty_for_impl #partialeq_bounds { + impl #impl_generics_labels ::#prefix::cmp::PartialEq for #ty_for_impl #partialeq_bounds { #impl_ } }); @@ -2612,7 +2750,7 @@ impl CodeGenerator for CompInfo { if !methods.is_empty() { result.push(quote! { - impl #generics #ty_for_impl { + impl #impl_generics_labels #ty_for_impl { #( #methods )* } }); @@ -5130,6 +5268,9 @@ pub(crate) mod utils { ctx: &BindgenContext, result: &mut Vec, ) { + if ctx.options().flexarray_dst { + return; + } let prefix = ctx.trait_prefix(); // If the target supports `const fn`, declare eligible functions diff --git a/bindgen/codegen/struct_layout.rs b/bindgen/codegen/struct_layout.rs index 7349669871..507c8d40e2 100644 --- a/bindgen/codegen/struct_layout.rs +++ b/bindgen/codegen/struct_layout.rs @@ -28,6 +28,7 @@ pub(crate) struct StructLayoutTracker<'a> { max_field_align: usize, last_field_was_bitfield: bool, visibility: FieldVisibilityKind, + last_field_was_flexible_array: bool, } /// Returns a size aligned to a given value. @@ -110,6 +111,7 @@ impl<'a> StructLayoutTracker<'a> { latest_field_layout: None, max_field_align: 0, last_field_was_bitfield: false, + last_field_was_flexible_array: false, } } @@ -121,6 +123,10 @@ impl<'a> StructLayoutTracker<'a> { self.is_rust_union } + pub(crate) fn saw_flexible_array(&mut self) { + self.last_field_was_flexible_array = true; + } + pub(crate) fn saw_vtable(&mut self) { debug!("saw vtable for {}", self.name); @@ -295,6 +301,11 @@ impl<'a> StructLayoutTracker<'a> { return None; } + // Also doesn't make sense for structs with flexible array members + if self.last_field_was_flexible_array { + return None; + } + if self.latest_offset == comp_layout.size { // This struct does not contain tail padding. return None; diff --git a/bindgen/features.rs b/bindgen/features.rs index 6ac1d6a16d..c07318c5e2 100644 --- a/bindgen/features.rs +++ b/bindgen/features.rs @@ -96,6 +96,8 @@ macro_rules! define_rust_targets { define_rust_targets! { Nightly => { vectorcall_abi, + ptr_metadata: #81513, + layout_for_ptr: #69835, }, Stable_1_77(77) => { offset_of: #106655 }, Stable_1_73(73) => { thiscall_abi: #42202 }, diff --git a/bindgen/ir/comp.rs b/bindgen/ir/comp.rs index bd4d016261..5ae2d68747 100644 --- a/bindgen/ir/comp.rs +++ b/bindgen/ir/comp.rs @@ -825,6 +825,24 @@ impl CompFields { } } } + + /// Return the flex array member for the struct/class, if any. + fn flex_array_member(&self, ctx: &BindgenContext) -> Option { + let fields = match self { + CompFields::Before(_) => panic!("raw fields"), + CompFields::After { fields, .. } => fields, + CompFields::Error => return None, // panic? + }; + + // XXX correct with padding on end? + match fields.last() { + None | Some(Field::Bitfields(..)) => None, + Some(Field::DataMember(FieldData { ty, .. })) => ctx + .resolve_type(*ty) + .is_incomplete_array(ctx) + .map(|item| item.expect_type_id(ctx)), + } + } } impl Trace for CompFields { @@ -1122,6 +1140,14 @@ impl CompInfo { } } + /// Return the flex array member and its element type if any + pub(crate) fn flex_array_member( + &self, + ctx: &BindgenContext, + ) -> Option { + self.fields.flex_array_member(ctx) + } + fn has_fields(&self) -> bool { match self.fields { CompFields::Error => false, diff --git a/bindgen/options/mod.rs b/bindgen/options/mod.rs index f374d20732..d1486397bd 100644 --- a/bindgen/options/mod.rs +++ b/bindgen/options/mod.rs @@ -1981,6 +1981,19 @@ options! { }, as_args: "--wrap-unsafe-ops", }, + /// Use DSTs to represent structures with flexible array members. + flexarray_dst: bool { + methods: { + /// Use DSTs to represent structures with flexible array members. + /// + /// This option is disabled by default. + pub fn flexarray_dst(mut self, doit: bool) -> Self { + self.options.flexarray_dst = doit; + self + } + }, + as_args: "--flexarray-dst", + }, /// Patterns for functions whose ABI should be overridden. abi_overrides: HashMap { methods: { From 9f2a6f6241ed216721aa80dd79485603655571c4 Mon Sep 17 00:00:00 2001 From: Jeremy Fitzhardinge Date: Fri, 1 Mar 2024 23:06:58 -0500 Subject: [PATCH 656/942] Only generate flex array member for last field There are some tests which have two incomplete array fields; only the very last one is valid as a flexible array member (in C) or can be a DST field in Rust. --- bindgen/codegen/mod.rs | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index c2da991e1f..2c6aafe5a2 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -1333,6 +1333,7 @@ trait FieldCodegen<'a> { accessor_kind: FieldAccessorKind, parent: &CompInfo, parent_item: &Item, + last_field: bool, result: &mut CodegenResult, struct_layout: &mut StructLayoutTracker, fields: &mut F, @@ -1353,6 +1354,7 @@ impl<'a> FieldCodegen<'a> for Field { accessor_kind: FieldAccessorKind, parent: &CompInfo, parent_item: &Item, + last_field: bool, result: &mut CodegenResult, struct_layout: &mut StructLayoutTracker, fields: &mut F, @@ -1370,6 +1372,7 @@ impl<'a> FieldCodegen<'a> for Field { accessor_kind, parent, parent_item, + last_field, result, struct_layout, fields, @@ -1384,6 +1387,7 @@ impl<'a> FieldCodegen<'a> for Field { accessor_kind, parent, parent_item, + last_field, result, struct_layout, fields, @@ -1428,6 +1432,7 @@ impl<'a> FieldCodegen<'a> for FieldData { accessor_kind: FieldAccessorKind, parent: &CompInfo, parent_item: &Item, + last_field: bool, result: &mut CodegenResult, struct_layout: &mut StructLayoutTracker, fields: &mut F, @@ -1453,17 +1458,20 @@ impl<'a> FieldCodegen<'a> for FieldData { let ty = if parent.is_union() { wrap_union_field_if_needed(ctx, struct_layout, ty, result) } else if let Some(item) = field_ty.is_incomplete_array(ctx) { - result.saw_incomplete_array(); - struct_layout.saw_flexible_array(); - - let inner = item.to_rust_ty_or_opaque(ctx, &()); - - if ctx.options().flexarray_dst { + // Only FAM if its the last field + if ctx.options().flexarray_dst && last_field { + struct_layout.saw_flexible_array(); syn::parse_quote! { FAM } - } else if ctx.options().enable_cxx_namespaces { - syn::parse_quote! { root::__IncompleteArrayField<#inner> } } else { - syn::parse_quote! { __IncompleteArrayField<#inner> } + result.saw_incomplete_array(); + + let inner = item.to_rust_ty_or_opaque(ctx, &()); + + if ctx.options().enable_cxx_namespaces { + syn::parse_quote! { root::__IncompleteArrayField<#inner> } + } else { + syn::parse_quote! { __IncompleteArrayField<#inner> } + } } } else { ty @@ -1685,6 +1693,7 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit { accessor_kind: FieldAccessorKind, parent: &CompInfo, parent_item: &Item, + _last_field: bool, result: &mut CodegenResult, struct_layout: &mut StructLayoutTracker, fields: &mut F, @@ -1745,7 +1754,8 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit { let mut generate_ctor = layout.size <= RUST_DERIVE_IN_ARRAY_LIMIT; let mut unit_visibility = visibility_kind; - for bf in self.bitfields() { + let bfields = self.bitfields(); + for (idx, bf) in bfields.iter().enumerate() { // Codegen not allowed for anonymous bitfields if bf.name().is_none() { continue; @@ -1765,6 +1775,7 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit { accessor_kind, parent, parent_item, + idx == bfields.len() - 1, result, struct_layout, fields, @@ -1847,6 +1858,7 @@ impl<'a> FieldCodegen<'a> for Bitfield { _accessor_kind: FieldAccessorKind, parent: &CompInfo, parent_item: &Item, + _last_field: bool, _result: &mut CodegenResult, struct_layout: &mut StructLayoutTracker, _fields: &mut F, @@ -2080,13 +2092,15 @@ impl CodeGenerator for CompInfo { .annotations() .accessor_kind() .unwrap_or(FieldAccessorKind::None); - for field in self.fields() { + let field_decls = self.fields(); + for (idx, field) in field_decls.iter().enumerate() { field.codegen( ctx, visibility, struct_accessor_kind, self, item, + idx == field_decls.len() - 1, result, &mut struct_layout, &mut fields, @@ -5268,9 +5282,6 @@ pub(crate) mod utils { ctx: &BindgenContext, result: &mut Vec, ) { - if ctx.options().flexarray_dst { - return; - } let prefix = ctx.trait_prefix(); // If the target supports `const fn`, declare eligible functions From 9be36cbeb202b66675c6b4f9617747ac510e7fa6 Mon Sep 17 00:00:00 2001 From: Jeremy Fitzhardinge Date: Sat, 2 Mar 2024 18:32:42 -0500 Subject: [PATCH 657/942] Add flex array member tests --- .../tests/expectations/tests/flexarray.rs | 525 ++++++++++++++++++ bindgen-tests/tests/headers/flexarray.hpp | 32 ++ 2 files changed, 557 insertions(+) create mode 100644 bindgen-tests/tests/expectations/tests/flexarray.rs create mode 100644 bindgen-tests/tests/headers/flexarray.hpp diff --git a/bindgen-tests/tests/expectations/tests/flexarray.rs b/bindgen-tests/tests/expectations/tests/flexarray.rs new file mode 100644 index 0000000000..bbe7c4f202 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/flexarray.rs @@ -0,0 +1,525 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#![cfg(feature = "nightly")] +#![feature(ptr_metadata, layout_for_ptr)] +#[repr(C)] +#[derive(Default)] +pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); +impl __IncompleteArrayField { + #[inline] + pub const fn new() -> Self { + __IncompleteArrayField(::std::marker::PhantomData, []) + } + #[inline] + pub fn as_ptr(&self) -> *const T { + self as *const _ as *const T + } + #[inline] + pub fn as_mut_ptr(&mut self) -> *mut T { + self as *mut _ as *mut T + } + #[inline] + pub unsafe fn as_slice(&self, len: usize) -> &[T] { + ::std::slice::from_raw_parts(self.as_ptr(), len) + } + #[inline] + pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { + ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) + } +} +impl ::std::fmt::Debug for __IncompleteArrayField { + fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + fmt.write_str("__IncompleteArrayField") + } +} +#[repr(C)] +#[derive(Debug, Default)] +pub struct flexarray { + pub count: ::std::os::raw::c_int, + pub data: FAM, +} +#[test] +fn bindgen_test_layout_flexarray() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(flexarray)), + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(flexarray)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).count) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(flexarray), "::", stringify!(count)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(flexarray), "::", stringify!(data)), + ); +} +impl flexarray<[::std::os::raw::c_int]> { + pub fn layout(len: usize) -> ::std::alloc::Layout { + unsafe { + let p: *const Self = ::std::ptr::from_raw_parts(::std::ptr::null(), len); + ::std::alloc::Layout::for_value_raw(p) + } + } + /// Construct a DST for `#canonical_ident` from a thin + /// pointer. + /// + /// SAFETY: the `len` must be <= the underlying storage. + /// Note: returned lifetime is unbounded. + pub unsafe fn from_ptr<'a>( + ptr: *const flexarray<[::std::os::raw::c_int; 0]>, + len: usize, + ) -> &'a Self { + let ptr: *const Self = ::std::ptr::from_raw_parts(ptr as *const (), len); + &*ptr + } + /// Construct a mutable DST for `#canonical_ident` from + /// a thin pointer. This is `MaybeUninit` to allow for + /// initialization. + /// + /// SAFETY: the `len` must be <= the underlying storage. + /// Note: returned lifetime is unbounded. + pub unsafe fn from_ptr_mut<'a>( + ptr: *mut flexarray<[::std::os::raw::c_int; 0]>, + len: usize, + ) -> ::std::mem::MaybeUninit<&'a mut Self> { + let ptr: *mut Self = ::std::ptr::from_raw_parts_mut(ptr as *mut (), len); + ::std::mem::MaybeUninit::new(&mut *ptr) + } +} +impl flexarray<[::std::os::raw::c_int; 0]> { + /// Turn a sized reference for `#canonical_ident` into + /// DST with the given `len`. + /// + /// SAFETY: the `len` must be <= the underlying storage. + pub unsafe fn from_ref(&self, len: usize) -> &flexarray<[::std::os::raw::c_int]> { + unsafe { flexarray::<[::std::os::raw::c_int]>::from_ptr(self, len) } + } + /// Turn a mutable sized reference for + /// `#canonical_ident` into DST with the given `len`. + /// + /// SAFETY: the `len` must be <= the underlying storage. + pub unsafe fn from_ref_mut( + &mut self, + len: usize, + ) -> &mut flexarray<[::std::os::raw::c_int]> { + unsafe { + flexarray::<[::std::os::raw::c_int]>::from_ptr_mut(self, len).assume_init() + } + } +} +#[repr(C)] +#[derive(Debug, Default)] +pub struct flexarray_zero { + pub count: ::std::os::raw::c_int, + pub data: FAM, +} +#[test] +fn bindgen_test_layout_flexarray_zero() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(flexarray_zero)), + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(flexarray_zero)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).count) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(flexarray_zero), "::", stringify!(count)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(flexarray_zero), "::", stringify!(data)), + ); +} +impl flexarray_zero<[::std::os::raw::c_int]> { + pub fn layout(len: usize) -> ::std::alloc::Layout { + unsafe { + let p: *const Self = ::std::ptr::from_raw_parts(::std::ptr::null(), len); + ::std::alloc::Layout::for_value_raw(p) + } + } + /// Construct a DST for `#canonical_ident` from a thin + /// pointer. + /// + /// SAFETY: the `len` must be <= the underlying storage. + /// Note: returned lifetime is unbounded. + pub unsafe fn from_ptr<'a>( + ptr: *const flexarray_zero<[::std::os::raw::c_int; 0]>, + len: usize, + ) -> &'a Self { + let ptr: *const Self = ::std::ptr::from_raw_parts(ptr as *const (), len); + &*ptr + } + /// Construct a mutable DST for `#canonical_ident` from + /// a thin pointer. This is `MaybeUninit` to allow for + /// initialization. + /// + /// SAFETY: the `len` must be <= the underlying storage. + /// Note: returned lifetime is unbounded. + pub unsafe fn from_ptr_mut<'a>( + ptr: *mut flexarray_zero<[::std::os::raw::c_int; 0]>, + len: usize, + ) -> ::std::mem::MaybeUninit<&'a mut Self> { + let ptr: *mut Self = ::std::ptr::from_raw_parts_mut(ptr as *mut (), len); + ::std::mem::MaybeUninit::new(&mut *ptr) + } +} +impl flexarray_zero<[::std::os::raw::c_int; 0]> { + /// Turn a sized reference for `#canonical_ident` into + /// DST with the given `len`. + /// + /// SAFETY: the `len` must be <= the underlying storage. + pub unsafe fn from_ref( + &self, + len: usize, + ) -> &flexarray_zero<[::std::os::raw::c_int]> { + unsafe { flexarray_zero::<[::std::os::raw::c_int]>::from_ptr(self, len) } + } + /// Turn a mutable sized reference for + /// `#canonical_ident` into DST with the given `len`. + /// + /// SAFETY: the `len` must be <= the underlying storage. + pub unsafe fn from_ref_mut( + &mut self, + len: usize, + ) -> &mut flexarray_zero<[::std::os::raw::c_int]> { + unsafe { + flexarray_zero::<[::std::os::raw::c_int]>::from_ptr_mut(self, len) + .assume_init() + } + } +} +#[repr(C)] +#[derive(Debug)] +pub struct flexarray_template { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub count: ::std::os::raw::c_int, + pub data: FAM, +} +impl flexarray_template { + pub fn layout(len: usize) -> ::std::alloc::Layout { + unsafe { + let p: *const Self = ::std::ptr::from_raw_parts(::std::ptr::null(), len); + ::std::alloc::Layout::for_value_raw(p) + } + } + /// Construct a DST for `#canonical_ident` from a thin + /// pointer. + /// + /// SAFETY: the `len` must be <= the underlying storage. + /// Note: returned lifetime is unbounded. + pub unsafe fn from_ptr<'a>( + ptr: *const flexarray_template, + len: usize, + ) -> &'a Self { + let ptr: *const Self = ::std::ptr::from_raw_parts(ptr as *const (), len); + &*ptr + } + /// Construct a mutable DST for `#canonical_ident` from + /// a thin pointer. This is `MaybeUninit` to allow for + /// initialization. + /// + /// SAFETY: the `len` must be <= the underlying storage. + /// Note: returned lifetime is unbounded. + pub unsafe fn from_ptr_mut<'a>( + ptr: *mut flexarray_template, + len: usize, + ) -> ::std::mem::MaybeUninit<&'a mut Self> { + let ptr: *mut Self = ::std::ptr::from_raw_parts_mut(ptr as *mut (), len); + ::std::mem::MaybeUninit::new(&mut *ptr) + } +} +impl flexarray_template { + /// Turn a sized reference for `#canonical_ident` into + /// DST with the given `len`. + /// + /// SAFETY: the `len` must be <= the underlying storage. + pub unsafe fn from_ref(&self, len: usize) -> &flexarray_template { + unsafe { flexarray_template::::from_ptr(self, len) } + } + /// Turn a mutable sized reference for + /// `#canonical_ident` into DST with the given `len`. + /// + /// SAFETY: the `len` must be <= the underlying storage. + pub unsafe fn from_ref_mut( + &mut self, + len: usize, + ) -> &mut flexarray_template { + unsafe { flexarray_template::::from_ptr_mut(self, len).assume_init() } + } +} +impl Default for flexarray_template { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct flexarray_ref { + pub things: *mut flexarray, +} +#[test] +fn bindgen_test_layout_flexarray_ref() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(flexarray_ref)), + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(flexarray_ref)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).things) as usize - ptr as usize }, + 0usize, + concat!("Offset of field: ", stringify!(flexarray_ref), "::", stringify!(things)), + ); +} +impl Default for flexarray_ref { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +#[repr(C)] +#[derive(Debug, Default)] +pub struct flexarray_bogus_zero_fam { + pub count: ::std::os::raw::c_int, + pub data1: __IncompleteArrayField<::std::os::raw::c_int>, + pub data2: FAM, +} +#[test] +fn bindgen_test_layout_flexarray_bogus_zero_fam() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(flexarray_bogus_zero_fam)), + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(flexarray_bogus_zero_fam)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).count) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(flexarray_bogus_zero_fam), + "::", + stringify!(count), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).data1) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(flexarray_bogus_zero_fam), + "::", + stringify!(data1), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).data2) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(flexarray_bogus_zero_fam), + "::", + stringify!(data2), + ), + ); +} +impl flexarray_bogus_zero_fam<[::std::os::raw::c_char]> { + pub fn layout(len: usize) -> ::std::alloc::Layout { + unsafe { + let p: *const Self = ::std::ptr::from_raw_parts(::std::ptr::null(), len); + ::std::alloc::Layout::for_value_raw(p) + } + } + /// Construct a DST for `#canonical_ident` from a thin + /// pointer. + /// + /// SAFETY: the `len` must be <= the underlying storage. + /// Note: returned lifetime is unbounded. + pub unsafe fn from_ptr<'a>( + ptr: *const flexarray_bogus_zero_fam<[::std::os::raw::c_char; 0]>, + len: usize, + ) -> &'a Self { + let ptr: *const Self = ::std::ptr::from_raw_parts(ptr as *const (), len); + &*ptr + } + /// Construct a mutable DST for `#canonical_ident` from + /// a thin pointer. This is `MaybeUninit` to allow for + /// initialization. + /// + /// SAFETY: the `len` must be <= the underlying storage. + /// Note: returned lifetime is unbounded. + pub unsafe fn from_ptr_mut<'a>( + ptr: *mut flexarray_bogus_zero_fam<[::std::os::raw::c_char; 0]>, + len: usize, + ) -> ::std::mem::MaybeUninit<&'a mut Self> { + let ptr: *mut Self = ::std::ptr::from_raw_parts_mut(ptr as *mut (), len); + ::std::mem::MaybeUninit::new(&mut *ptr) + } +} +impl flexarray_bogus_zero_fam<[::std::os::raw::c_char; 0]> { + /// Turn a sized reference for `#canonical_ident` into + /// DST with the given `len`. + /// + /// SAFETY: the `len` must be <= the underlying storage. + pub unsafe fn from_ref( + &self, + len: usize, + ) -> &flexarray_bogus_zero_fam<[::std::os::raw::c_char]> { + unsafe { + flexarray_bogus_zero_fam::<[::std::os::raw::c_char]>::from_ptr(self, len) + } + } + /// Turn a mutable sized reference for + /// `#canonical_ident` into DST with the given `len`. + /// + /// SAFETY: the `len` must be <= the underlying storage. + pub unsafe fn from_ref_mut( + &mut self, + len: usize, + ) -> &mut flexarray_bogus_zero_fam<[::std::os::raw::c_char]> { + unsafe { + flexarray_bogus_zero_fam::<[::std::os::raw::c_char]>::from_ptr_mut(self, len) + .assume_init() + } + } +} +#[repr(C)] +#[repr(align(128))] +#[derive(Debug)] +pub struct flexarray_align { + pub count: ::std::os::raw::c_int, + pub data: FAM, +} +#[test] +fn bindgen_test_layout_flexarray_align() { + const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::std::mem::size_of::(), + 128usize, + concat!("Size of: ", stringify!(flexarray_align)), + ); + assert_eq!( + ::std::mem::align_of::(), + 128usize, + concat!("Alignment of ", stringify!(flexarray_align)), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).count) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(flexarray_align), + "::", + stringify!(count), + ), + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize }, + 4usize, + concat!("Offset of field: ", stringify!(flexarray_align), "::", stringify!(data)), + ); +} +impl flexarray_align<[::std::os::raw::c_int]> { + pub fn layout(len: usize) -> ::std::alloc::Layout { + unsafe { + let p: *const Self = ::std::ptr::from_raw_parts(::std::ptr::null(), len); + ::std::alloc::Layout::for_value_raw(p) + } + } + /// Construct a DST for `#canonical_ident` from a thin + /// pointer. + /// + /// SAFETY: the `len` must be <= the underlying storage. + /// Note: returned lifetime is unbounded. + pub unsafe fn from_ptr<'a>( + ptr: *const flexarray_align<[::std::os::raw::c_int; 0]>, + len: usize, + ) -> &'a Self { + let ptr: *const Self = ::std::ptr::from_raw_parts(ptr as *const (), len); + &*ptr + } + /// Construct a mutable DST for `#canonical_ident` from + /// a thin pointer. This is `MaybeUninit` to allow for + /// initialization. + /// + /// SAFETY: the `len` must be <= the underlying storage. + /// Note: returned lifetime is unbounded. + pub unsafe fn from_ptr_mut<'a>( + ptr: *mut flexarray_align<[::std::os::raw::c_int; 0]>, + len: usize, + ) -> ::std::mem::MaybeUninit<&'a mut Self> { + let ptr: *mut Self = ::std::ptr::from_raw_parts_mut(ptr as *mut (), len); + ::std::mem::MaybeUninit::new(&mut *ptr) + } +} +impl flexarray_align<[::std::os::raw::c_int; 0]> { + /// Turn a sized reference for `#canonical_ident` into + /// DST with the given `len`. + /// + /// SAFETY: the `len` must be <= the underlying storage. + pub unsafe fn from_ref( + &self, + len: usize, + ) -> &flexarray_align<[::std::os::raw::c_int]> { + unsafe { flexarray_align::<[::std::os::raw::c_int]>::from_ptr(self, len) } + } + /// Turn a mutable sized reference for + /// `#canonical_ident` into DST with the given `len`. + /// + /// SAFETY: the `len` must be <= the underlying storage. + pub unsafe fn from_ref_mut( + &mut self, + len: usize, + ) -> &mut flexarray_align<[::std::os::raw::c_int]> { + unsafe { + flexarray_align::<[::std::os::raw::c_int]>::from_ptr_mut(self, len) + .assume_init() + } + } +} +impl Default for flexarray_align<[::std::os::raw::c_int; 0]> { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} diff --git a/bindgen-tests/tests/headers/flexarray.hpp b/bindgen-tests/tests/headers/flexarray.hpp new file mode 100644 index 0000000000..b698c38d19 --- /dev/null +++ b/bindgen-tests/tests/headers/flexarray.hpp @@ -0,0 +1,32 @@ +// bindgen-flags: --rust-target nightly --flexarray-dst --raw-line '#![cfg(feature = "nightly")]' --raw-line '#![feature(ptr_metadata, layout_for_ptr)]' + +struct flexarray { + int count; + int data[]; +}; + +struct flexarray_zero { + int count; + int data[0]; +}; + +template +struct flexarray_template { + int count; + T data[]; +}; + +struct flexarray_ref { + flexarray *things; +}; + +struct flexarray_bogus_zero_fam { + int count; + int data1[0]; + char data2[]; +}; + +struct flexarray_align { + int count; + int data[]; +} __attribute__((aligned(128))); From e62e4b0b2761dfadaa42dcbf3cdc548a9021a83f Mon Sep 17 00:00:00 2001 From: Jeremy Fitzhardinge Date: Tue, 5 Mar 2024 15:14:04 -0800 Subject: [PATCH 658/942] Rework methods on flexarray types Put the pointer converting methods on the sized prefix types ([T; 0]) since they're the default type and what you're likely to be starting with. Emphasize the ones which work on references since they have safe lifetimes, but also have raw pointer variants, esp for handling uninitialized cases. The flex types have methods which return the sized type along with the length. --- .../tests/expectations/tests/flexarray.rs | 424 +++++++++++------- bindgen/codegen/mod.rs | 82 ++-- 2 files changed, 304 insertions(+), 202 deletions(-) diff --git a/bindgen-tests/tests/expectations/tests/flexarray.rs b/bindgen-tests/tests/expectations/tests/flexarray.rs index bbe7c4f202..0e735317ba 100644 --- a/bindgen-tests/tests/expectations/tests/flexarray.rs +++ b/bindgen-tests/tests/expectations/tests/flexarray.rs @@ -69,50 +69,63 @@ impl flexarray<[::std::os::raw::c_int]> { ::std::alloc::Layout::for_value_raw(p) } } - /// Construct a DST for `#canonical_ident` from a thin - /// pointer. - /// - /// SAFETY: the `len` must be <= the underlying storage. - /// Note: returned lifetime is unbounded. - pub unsafe fn from_ptr<'a>( - ptr: *const flexarray<[::std::os::raw::c_int; 0]>, - len: usize, - ) -> &'a Self { - let ptr: *const Self = ::std::ptr::from_raw_parts(ptr as *const (), len); - &*ptr + pub fn fixed(&self) -> (&flexarray<[::std::os::raw::c_int; 0]>, usize) { + unsafe { + let (ptr, len) = (self as *const Self).to_raw_parts(); + (&*(ptr as *const flexarray<[::std::os::raw::c_int; 0]>), len) + } } - /// Construct a mutable DST for `#canonical_ident` from - /// a thin pointer. This is `MaybeUninit` to allow for - /// initialization. - /// - /// SAFETY: the `len` must be <= the underlying storage. - /// Note: returned lifetime is unbounded. - pub unsafe fn from_ptr_mut<'a>( - ptr: *mut flexarray<[::std::os::raw::c_int; 0]>, - len: usize, - ) -> ::std::mem::MaybeUninit<&'a mut Self> { - let ptr: *mut Self = ::std::ptr::from_raw_parts_mut(ptr as *mut (), len); - ::std::mem::MaybeUninit::new(&mut *ptr) + pub fn fixed_mut(&mut self) -> (&mut flexarray<[::std::os::raw::c_int; 0]>, usize) { + unsafe { + let (ptr, len) = (self as *mut Self).to_raw_parts(); + (&mut *(ptr as *mut flexarray<[::std::os::raw::c_int; 0]>), len) + } } } impl flexarray<[::std::os::raw::c_int; 0]> { - /// Turn a sized reference for `#canonical_ident` into - /// DST with the given `len`. + /// Convert a sized prefix to an unsized structure with the given length. /// - /// SAFETY: the `len` must be <= the underlying storage. - pub unsafe fn from_ref(&self, len: usize) -> &flexarray<[::std::os::raw::c_int]> { - unsafe { flexarray::<[::std::os::raw::c_int]>::from_ptr(self, len) } + /// SAFETY: Underlying storage is initialized up to at least `len` elements. + pub unsafe fn flex_ref(&self, len: usize) -> &flexarray<[::std::os::raw::c_int]> { + unsafe { Self::flex_ptr(self, len) } } - /// Turn a mutable sized reference for - /// `#canonical_ident` into DST with the given `len`. + /// Convert a mutable sized prefix to an unsized structure with the given length. /// - /// SAFETY: the `len` must be <= the underlying storage. - pub unsafe fn from_ref_mut( + /// SAFETY: Underlying storage is initialized up to at least `len` elements. + pub unsafe fn flex_mut_ref( &mut self, len: usize, ) -> &mut flexarray<[::std::os::raw::c_int]> { + unsafe { Self::flex_ptr_mut(self, len).assume_init() } + } + /// Construct DST variant from a pointer and a size. + /// + /// NOTE: lifetime of returned reference is not tied to any underlying storage. + /// SAFETY: `ptr` is valid. Underlying storage is fully initialized up to at least `len` elements. + pub unsafe fn flex_ptr<'unbounded>( + ptr: *const Self, + len: usize, + ) -> &'unbounded flexarray<[::std::os::raw::c_int]> { + unsafe { &*::std::ptr::from_raw_parts(ptr as *const (), len) } + } + /// Construct mutable DST variant from a pointer and a + /// size. The returned `&mut` reference is initialized + /// pointing to memory referenced by `ptr`, but there's + /// no requirement that that memory be initialized. + /// + /// NOTE: lifetime of returned reference is not tied to any underlying storage. + /// SAFETY: `ptr` is valid. Underlying storage has space for at least `len` elements. + pub unsafe fn flex_ptr_mut<'unbounded>( + ptr: *mut Self, + len: usize, + ) -> ::std::mem::MaybeUninit<&'unbounded mut flexarray<[::std::os::raw::c_int]>> { unsafe { - flexarray::<[::std::os::raw::c_int]>::from_ptr_mut(self, len).assume_init() + let mut uninit = ::std::mem::MaybeUninit::< + &mut flexarray<[::std::os::raw::c_int]>, + >::uninit(); + (uninit.as_mut_ptr() as *mut *mut flexarray<[::std::os::raw::c_int]>) + .write(::std::ptr::from_raw_parts_mut(ptr as *mut (), len)); + uninit } } } @@ -154,54 +167,70 @@ impl flexarray_zero<[::std::os::raw::c_int]> { ::std::alloc::Layout::for_value_raw(p) } } - /// Construct a DST for `#canonical_ident` from a thin - /// pointer. - /// - /// SAFETY: the `len` must be <= the underlying storage. - /// Note: returned lifetime is unbounded. - pub unsafe fn from_ptr<'a>( - ptr: *const flexarray_zero<[::std::os::raw::c_int; 0]>, - len: usize, - ) -> &'a Self { - let ptr: *const Self = ::std::ptr::from_raw_parts(ptr as *const (), len); - &*ptr + pub fn fixed(&self) -> (&flexarray_zero<[::std::os::raw::c_int; 0]>, usize) { + unsafe { + let (ptr, len) = (self as *const Self).to_raw_parts(); + (&*(ptr as *const flexarray_zero<[::std::os::raw::c_int; 0]>), len) + } } - /// Construct a mutable DST for `#canonical_ident` from - /// a thin pointer. This is `MaybeUninit` to allow for - /// initialization. - /// - /// SAFETY: the `len` must be <= the underlying storage. - /// Note: returned lifetime is unbounded. - pub unsafe fn from_ptr_mut<'a>( - ptr: *mut flexarray_zero<[::std::os::raw::c_int; 0]>, - len: usize, - ) -> ::std::mem::MaybeUninit<&'a mut Self> { - let ptr: *mut Self = ::std::ptr::from_raw_parts_mut(ptr as *mut (), len); - ::std::mem::MaybeUninit::new(&mut *ptr) + pub fn fixed_mut( + &mut self, + ) -> (&mut flexarray_zero<[::std::os::raw::c_int; 0]>, usize) { + unsafe { + let (ptr, len) = (self as *mut Self).to_raw_parts(); + (&mut *(ptr as *mut flexarray_zero<[::std::os::raw::c_int; 0]>), len) + } } } impl flexarray_zero<[::std::os::raw::c_int; 0]> { - /// Turn a sized reference for `#canonical_ident` into - /// DST with the given `len`. + /// Convert a sized prefix to an unsized structure with the given length. /// - /// SAFETY: the `len` must be <= the underlying storage. - pub unsafe fn from_ref( + /// SAFETY: Underlying storage is initialized up to at least `len` elements. + pub unsafe fn flex_ref( &self, len: usize, ) -> &flexarray_zero<[::std::os::raw::c_int]> { - unsafe { flexarray_zero::<[::std::os::raw::c_int]>::from_ptr(self, len) } + unsafe { Self::flex_ptr(self, len) } } - /// Turn a mutable sized reference for - /// `#canonical_ident` into DST with the given `len`. + /// Convert a mutable sized prefix to an unsized structure with the given length. /// - /// SAFETY: the `len` must be <= the underlying storage. - pub unsafe fn from_ref_mut( + /// SAFETY: Underlying storage is initialized up to at least `len` elements. + pub unsafe fn flex_mut_ref( &mut self, len: usize, ) -> &mut flexarray_zero<[::std::os::raw::c_int]> { + unsafe { Self::flex_ptr_mut(self, len).assume_init() } + } + /// Construct DST variant from a pointer and a size. + /// + /// NOTE: lifetime of returned reference is not tied to any underlying storage. + /// SAFETY: `ptr` is valid. Underlying storage is fully initialized up to at least `len` elements. + pub unsafe fn flex_ptr<'unbounded>( + ptr: *const Self, + len: usize, + ) -> &'unbounded flexarray_zero<[::std::os::raw::c_int]> { + unsafe { &*::std::ptr::from_raw_parts(ptr as *const (), len) } + } + /// Construct mutable DST variant from a pointer and a + /// size. The returned `&mut` reference is initialized + /// pointing to memory referenced by `ptr`, but there's + /// no requirement that that memory be initialized. + /// + /// NOTE: lifetime of returned reference is not tied to any underlying storage. + /// SAFETY: `ptr` is valid. Underlying storage has space for at least `len` elements. + pub unsafe fn flex_ptr_mut<'unbounded>( + ptr: *mut Self, + len: usize, + ) -> ::std::mem::MaybeUninit< + &'unbounded mut flexarray_zero<[::std::os::raw::c_int]>, + > { unsafe { - flexarray_zero::<[::std::os::raw::c_int]>::from_ptr_mut(self, len) - .assume_init() + let mut uninit = ::std::mem::MaybeUninit::< + &mut flexarray_zero<[::std::os::raw::c_int]>, + >::uninit(); + (uninit.as_mut_ptr() as *mut *mut flexarray_zero<[::std::os::raw::c_int]>) + .write(::std::ptr::from_raw_parts_mut(ptr as *mut (), len)); + uninit } } } @@ -219,49 +248,64 @@ impl flexarray_template { ::std::alloc::Layout::for_value_raw(p) } } - /// Construct a DST for `#canonical_ident` from a thin - /// pointer. - /// - /// SAFETY: the `len` must be <= the underlying storage. - /// Note: returned lifetime is unbounded. - pub unsafe fn from_ptr<'a>( - ptr: *const flexarray_template, - len: usize, - ) -> &'a Self { - let ptr: *const Self = ::std::ptr::from_raw_parts(ptr as *const (), len); - &*ptr + pub fn fixed(&self) -> (&flexarray_template, usize) { + unsafe { + let (ptr, len) = (self as *const Self).to_raw_parts(); + (&*(ptr as *const flexarray_template), len) + } } - /// Construct a mutable DST for `#canonical_ident` from - /// a thin pointer. This is `MaybeUninit` to allow for - /// initialization. - /// - /// SAFETY: the `len` must be <= the underlying storage. - /// Note: returned lifetime is unbounded. - pub unsafe fn from_ptr_mut<'a>( - ptr: *mut flexarray_template, - len: usize, - ) -> ::std::mem::MaybeUninit<&'a mut Self> { - let ptr: *mut Self = ::std::ptr::from_raw_parts_mut(ptr as *mut (), len); - ::std::mem::MaybeUninit::new(&mut *ptr) + pub fn fixed_mut(&mut self) -> (&mut flexarray_template, usize) { + unsafe { + let (ptr, len) = (self as *mut Self).to_raw_parts(); + (&mut *(ptr as *mut flexarray_template), len) + } } } impl flexarray_template { - /// Turn a sized reference for `#canonical_ident` into - /// DST with the given `len`. + /// Convert a sized prefix to an unsized structure with the given length. /// - /// SAFETY: the `len` must be <= the underlying storage. - pub unsafe fn from_ref(&self, len: usize) -> &flexarray_template { - unsafe { flexarray_template::::from_ptr(self, len) } + /// SAFETY: Underlying storage is initialized up to at least `len` elements. + pub unsafe fn flex_ref(&self, len: usize) -> &flexarray_template { + unsafe { Self::flex_ptr(self, len) } } - /// Turn a mutable sized reference for - /// `#canonical_ident` into DST with the given `len`. + /// Convert a mutable sized prefix to an unsized structure with the given length. /// - /// SAFETY: the `len` must be <= the underlying storage. - pub unsafe fn from_ref_mut( + /// SAFETY: Underlying storage is initialized up to at least `len` elements. + pub unsafe fn flex_mut_ref( &mut self, len: usize, ) -> &mut flexarray_template { - unsafe { flexarray_template::::from_ptr_mut(self, len).assume_init() } + unsafe { Self::flex_ptr_mut(self, len).assume_init() } + } + /// Construct DST variant from a pointer and a size. + /// + /// NOTE: lifetime of returned reference is not tied to any underlying storage. + /// SAFETY: `ptr` is valid. Underlying storage is fully initialized up to at least `len` elements. + pub unsafe fn flex_ptr<'unbounded>( + ptr: *const Self, + len: usize, + ) -> &'unbounded flexarray_template { + unsafe { &*::std::ptr::from_raw_parts(ptr as *const (), len) } + } + /// Construct mutable DST variant from a pointer and a + /// size. The returned `&mut` reference is initialized + /// pointing to memory referenced by `ptr`, but there's + /// no requirement that that memory be initialized. + /// + /// NOTE: lifetime of returned reference is not tied to any underlying storage. + /// SAFETY: `ptr` is valid. Underlying storage has space for at least `len` elements. + pub unsafe fn flex_ptr_mut<'unbounded>( + ptr: *mut Self, + len: usize, + ) -> ::std::mem::MaybeUninit<&'unbounded mut flexarray_template> { + unsafe { + let mut uninit = ::std::mem::MaybeUninit::< + &mut flexarray_template, + >::uninit(); + (uninit.as_mut_ptr() as *mut *mut flexarray_template) + .write(::std::ptr::from_raw_parts_mut(ptr as *mut (), len)); + uninit + } } } impl Default for flexarray_template { @@ -366,56 +410,80 @@ impl flexarray_bogus_zero_fam<[::std::os::raw::c_char]> { ::std::alloc::Layout::for_value_raw(p) } } - /// Construct a DST for `#canonical_ident` from a thin - /// pointer. - /// - /// SAFETY: the `len` must be <= the underlying storage. - /// Note: returned lifetime is unbounded. - pub unsafe fn from_ptr<'a>( - ptr: *const flexarray_bogus_zero_fam<[::std::os::raw::c_char; 0]>, - len: usize, - ) -> &'a Self { - let ptr: *const Self = ::std::ptr::from_raw_parts(ptr as *const (), len); - &*ptr + pub fn fixed( + &self, + ) -> (&flexarray_bogus_zero_fam<[::std::os::raw::c_char; 0]>, usize) { + unsafe { + let (ptr, len) = (self as *const Self).to_raw_parts(); + ( + &*(ptr as *const flexarray_bogus_zero_fam<[::std::os::raw::c_char; 0]>), + len, + ) + } } - /// Construct a mutable DST for `#canonical_ident` from - /// a thin pointer. This is `MaybeUninit` to allow for - /// initialization. - /// - /// SAFETY: the `len` must be <= the underlying storage. - /// Note: returned lifetime is unbounded. - pub unsafe fn from_ptr_mut<'a>( - ptr: *mut flexarray_bogus_zero_fam<[::std::os::raw::c_char; 0]>, - len: usize, - ) -> ::std::mem::MaybeUninit<&'a mut Self> { - let ptr: *mut Self = ::std::ptr::from_raw_parts_mut(ptr as *mut (), len); - ::std::mem::MaybeUninit::new(&mut *ptr) + pub fn fixed_mut( + &mut self, + ) -> (&mut flexarray_bogus_zero_fam<[::std::os::raw::c_char; 0]>, usize) { + unsafe { + let (ptr, len) = (self as *mut Self).to_raw_parts(); + ( + &mut *(ptr + as *mut flexarray_bogus_zero_fam<[::std::os::raw::c_char; 0]>), + len, + ) + } } } impl flexarray_bogus_zero_fam<[::std::os::raw::c_char; 0]> { - /// Turn a sized reference for `#canonical_ident` into - /// DST with the given `len`. + /// Convert a sized prefix to an unsized structure with the given length. /// - /// SAFETY: the `len` must be <= the underlying storage. - pub unsafe fn from_ref( + /// SAFETY: Underlying storage is initialized up to at least `len` elements. + pub unsafe fn flex_ref( &self, len: usize, ) -> &flexarray_bogus_zero_fam<[::std::os::raw::c_char]> { - unsafe { - flexarray_bogus_zero_fam::<[::std::os::raw::c_char]>::from_ptr(self, len) - } + unsafe { Self::flex_ptr(self, len) } } - /// Turn a mutable sized reference for - /// `#canonical_ident` into DST with the given `len`. + /// Convert a mutable sized prefix to an unsized structure with the given length. /// - /// SAFETY: the `len` must be <= the underlying storage. - pub unsafe fn from_ref_mut( + /// SAFETY: Underlying storage is initialized up to at least `len` elements. + pub unsafe fn flex_mut_ref( &mut self, len: usize, ) -> &mut flexarray_bogus_zero_fam<[::std::os::raw::c_char]> { + unsafe { Self::flex_ptr_mut(self, len).assume_init() } + } + /// Construct DST variant from a pointer and a size. + /// + /// NOTE: lifetime of returned reference is not tied to any underlying storage. + /// SAFETY: `ptr` is valid. Underlying storage is fully initialized up to at least `len` elements. + pub unsafe fn flex_ptr<'unbounded>( + ptr: *const Self, + len: usize, + ) -> &'unbounded flexarray_bogus_zero_fam<[::std::os::raw::c_char]> { + unsafe { &*::std::ptr::from_raw_parts(ptr as *const (), len) } + } + /// Construct mutable DST variant from a pointer and a + /// size. The returned `&mut` reference is initialized + /// pointing to memory referenced by `ptr`, but there's + /// no requirement that that memory be initialized. + /// + /// NOTE: lifetime of returned reference is not tied to any underlying storage. + /// SAFETY: `ptr` is valid. Underlying storage has space for at least `len` elements. + pub unsafe fn flex_ptr_mut<'unbounded>( + ptr: *mut Self, + len: usize, + ) -> ::std::mem::MaybeUninit< + &'unbounded mut flexarray_bogus_zero_fam<[::std::os::raw::c_char]>, + > { unsafe { - flexarray_bogus_zero_fam::<[::std::os::raw::c_char]>::from_ptr_mut(self, len) - .assume_init() + let mut uninit = ::std::mem::MaybeUninit::< + &mut flexarray_bogus_zero_fam<[::std::os::raw::c_char]>, + >::uninit(); + (uninit.as_mut_ptr() + as *mut *mut flexarray_bogus_zero_fam<[::std::os::raw::c_char]>) + .write(::std::ptr::from_raw_parts_mut(ptr as *mut (), len)); + uninit } } } @@ -463,54 +531,70 @@ impl flexarray_align<[::std::os::raw::c_int]> { ::std::alloc::Layout::for_value_raw(p) } } - /// Construct a DST for `#canonical_ident` from a thin - /// pointer. - /// - /// SAFETY: the `len` must be <= the underlying storage. - /// Note: returned lifetime is unbounded. - pub unsafe fn from_ptr<'a>( - ptr: *const flexarray_align<[::std::os::raw::c_int; 0]>, - len: usize, - ) -> &'a Self { - let ptr: *const Self = ::std::ptr::from_raw_parts(ptr as *const (), len); - &*ptr + pub fn fixed(&self) -> (&flexarray_align<[::std::os::raw::c_int; 0]>, usize) { + unsafe { + let (ptr, len) = (self as *const Self).to_raw_parts(); + (&*(ptr as *const flexarray_align<[::std::os::raw::c_int; 0]>), len) + } } - /// Construct a mutable DST for `#canonical_ident` from - /// a thin pointer. This is `MaybeUninit` to allow for - /// initialization. - /// - /// SAFETY: the `len` must be <= the underlying storage. - /// Note: returned lifetime is unbounded. - pub unsafe fn from_ptr_mut<'a>( - ptr: *mut flexarray_align<[::std::os::raw::c_int; 0]>, - len: usize, - ) -> ::std::mem::MaybeUninit<&'a mut Self> { - let ptr: *mut Self = ::std::ptr::from_raw_parts_mut(ptr as *mut (), len); - ::std::mem::MaybeUninit::new(&mut *ptr) + pub fn fixed_mut( + &mut self, + ) -> (&mut flexarray_align<[::std::os::raw::c_int; 0]>, usize) { + unsafe { + let (ptr, len) = (self as *mut Self).to_raw_parts(); + (&mut *(ptr as *mut flexarray_align<[::std::os::raw::c_int; 0]>), len) + } } } impl flexarray_align<[::std::os::raw::c_int; 0]> { - /// Turn a sized reference for `#canonical_ident` into - /// DST with the given `len`. + /// Convert a sized prefix to an unsized structure with the given length. /// - /// SAFETY: the `len` must be <= the underlying storage. - pub unsafe fn from_ref( + /// SAFETY: Underlying storage is initialized up to at least `len` elements. + pub unsafe fn flex_ref( &self, len: usize, ) -> &flexarray_align<[::std::os::raw::c_int]> { - unsafe { flexarray_align::<[::std::os::raw::c_int]>::from_ptr(self, len) } + unsafe { Self::flex_ptr(self, len) } } - /// Turn a mutable sized reference for - /// `#canonical_ident` into DST with the given `len`. + /// Convert a mutable sized prefix to an unsized structure with the given length. /// - /// SAFETY: the `len` must be <= the underlying storage. - pub unsafe fn from_ref_mut( + /// SAFETY: Underlying storage is initialized up to at least `len` elements. + pub unsafe fn flex_mut_ref( &mut self, len: usize, ) -> &mut flexarray_align<[::std::os::raw::c_int]> { + unsafe { Self::flex_ptr_mut(self, len).assume_init() } + } + /// Construct DST variant from a pointer and a size. + /// + /// NOTE: lifetime of returned reference is not tied to any underlying storage. + /// SAFETY: `ptr` is valid. Underlying storage is fully initialized up to at least `len` elements. + pub unsafe fn flex_ptr<'unbounded>( + ptr: *const Self, + len: usize, + ) -> &'unbounded flexarray_align<[::std::os::raw::c_int]> { + unsafe { &*::std::ptr::from_raw_parts(ptr as *const (), len) } + } + /// Construct mutable DST variant from a pointer and a + /// size. The returned `&mut` reference is initialized + /// pointing to memory referenced by `ptr`, but there's + /// no requirement that that memory be initialized. + /// + /// NOTE: lifetime of returned reference is not tied to any underlying storage. + /// SAFETY: `ptr` is valid. Underlying storage has space for at least `len` elements. + pub unsafe fn flex_ptr_mut<'unbounded>( + ptr: *mut Self, + len: usize, + ) -> ::std::mem::MaybeUninit< + &'unbounded mut flexarray_align<[::std::os::raw::c_int]>, + > { unsafe { - flexarray_align::<[::std::os::raw::c_int]>::from_ptr_mut(self, len) - .assume_init() + let mut uninit = ::std::mem::MaybeUninit::< + &mut flexarray_align<[::std::os::raw::c_int]>, + >::uninit(); + (uninit.as_mut_ptr() as *mut *mut flexarray_align<[::std::os::raw::c_int]>) + .write(::std::ptr::from_raw_parts_mut(ptr as *mut (), len)); + uninit } } } diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 2c6aafe5a2..a0a57f1608 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -2607,10 +2607,6 @@ impl CodeGenerator for CompInfo { #canonical_ident < #( #generic_param_names , )* [ #flex_inner_ty; 0 ] > }; - let turbo_dst_ty = quote! { - #canonical_ident :: < #( #generic_param_names , )* [ #flex_inner_ty ] > - }; - let layout = if ctx.options().rust_features().layout_for_ptr { quote! { pub fn layout(len: usize) -> ::#prefix::alloc::Layout { @@ -2632,43 +2628,65 @@ impl CodeGenerator for CompInfo { { ( quote! { - /// Construct a DST for `#canonical_ident` from a thin - /// pointer. - /// - /// SAFETY: the `len` must be <= the underlying storage. - /// Note: returned lifetime is unbounded. - pub unsafe fn from_ptr<'a>(ptr: *const #sized_ty_for_impl, len: usize) -> &'a Self { - let ptr: *const Self = ::#prefix::ptr::from_raw_parts(ptr as *const (), len); - &*ptr + pub fn fixed(&self) -> (& #sized_ty_for_impl, usize) { + unsafe { + let (ptr, len) = (self as *const Self).to_raw_parts(); + (&*(ptr as *const #sized_ty_for_impl), len) + } } - /// Construct a mutable DST for `#canonical_ident` from - /// a thin pointer. This is `MaybeUninit` to allow for - /// initialization. - /// - /// SAFETY: the `len` must be <= the underlying storage. - /// Note: returned lifetime is unbounded. - pub unsafe fn from_ptr_mut<'a>(ptr: *mut #sized_ty_for_impl, len: usize) -> ::#prefix::mem::MaybeUninit<&'a mut Self> { - let ptr: *mut Self = ::#prefix::ptr::from_raw_parts_mut(ptr as *mut (), len); - ::#prefix::mem::MaybeUninit::new(&mut *ptr) + pub fn fixed_mut(&mut self) -> (&mut #sized_ty_for_impl, usize) { + unsafe { + let (ptr, len) = (self as *mut Self).to_raw_parts(); + (&mut *(ptr as *mut #sized_ty_for_impl), len) + + } } }, quote! { - /// Turn a sized reference for `#canonical_ident` into - /// DST with the given `len`. + /// Convert a sized prefix to an unsized structure with the given length. /// - /// SAFETY: the `len` must be <= the underlying storage. - pub unsafe fn from_ref(&self, len: usize) -> & #dst_ty_for_impl { - // SAFETY: caller guarantees `len` is good - unsafe { #turbo_dst_ty :: from_ptr(self, len) } + /// SAFETY: Underlying storage is initialized up to at least `len` elements. + pub unsafe fn flex_ref(&self, len: usize) -> &#dst_ty_for_impl { + // SAFETY: Reference is always valid as pointer. Caller is guaranteeing `len`. + unsafe { Self::flex_ptr(self, len) } } - /// Turn a mutable sized reference for - /// `#canonical_ident` into DST with the given `len`. + /// Convert a mutable sized prefix to an unsized structure with the given length. /// - /// SAFETY: the `len` must be <= the underlying storage. - pub unsafe fn from_ref_mut(&mut self, len: usize) -> &mut #dst_ty_for_impl { - unsafe { #turbo_dst_ty :: from_ptr_mut(self, len).assume_init() } + /// SAFETY: Underlying storage is initialized up to at least `len` elements. + pub unsafe fn flex_mut_ref(&mut self, len: usize) -> &mut #dst_ty_for_impl { + // SAFETY: Reference is always valid as pointer. Caller is guaranteeing `len`. + unsafe { Self::flex_ptr_mut(self, len).assume_init() } + } + + /// Construct DST variant from a pointer and a size. + /// + /// NOTE: lifetime of returned reference is not tied to any underlying storage. + /// SAFETY: `ptr` is valid. Underlying storage is fully initialized up to at least `len` elements. + pub unsafe fn flex_ptr<'unbounded>(ptr: *const Self, len: usize) -> &'unbounded #dst_ty_for_impl { + unsafe { &*::#prefix::ptr::from_raw_parts(ptr as *const (), len) } + } + + /// Construct mutable DST variant from a pointer and a + /// size. The returned `&mut` reference is initialized + /// pointing to memory referenced by `ptr`, but there's + /// no requirement that that memory be initialized. + /// + /// NOTE: lifetime of returned reference is not tied to any underlying storage. + /// SAFETY: `ptr` is valid. Underlying storage has space for at least `len` elements. + pub unsafe fn flex_ptr_mut<'unbounded>( + ptr: *mut Self, + len: usize, + ) -> ::#prefix::mem::MaybeUninit<&'unbounded mut #dst_ty_for_impl> { + unsafe { + // Initialize reference without ever exposing it, as its possibly uninitialized + let mut uninit = ::#prefix::mem::MaybeUninit::<&mut #dst_ty_for_impl>::uninit(); + (uninit.as_mut_ptr() as *mut *mut #dst_ty_for_impl) + .write(::#prefix::ptr::from_raw_parts_mut(ptr as *mut (), len)); + + uninit + } } }, ) From 77102b25b805ed3739312122480ec50629cd68ed Mon Sep 17 00:00:00 2001 From: Jeremy Fitzhardinge Date: Tue, 5 Mar 2024 19:34:07 -0800 Subject: [PATCH 659/942] Add documentation --- book/src/SUMMARY.md | 1 + book/src/using-fam.md | 163 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 164 insertions(+) create mode 100644 book/src/using-fam.md diff --git a/book/src/SUMMARY.md b/book/src/SUMMARY.md index dbdf3f700c..daaed04081 100644 --- a/book/src/SUMMARY.md +++ b/book/src/SUMMARY.md @@ -27,4 +27,5 @@ - [Generating Bindings to Objective-c](./objc.md) - [Using Unions](./using-unions.md) - [Using Bitfields](./using-bitfields.md) +- [Using Flexible Array Members](./using-fam.md) - [FAQ](./faq.md) diff --git a/book/src/using-fam.md b/book/src/using-fam.md new file mode 100644 index 0000000000..473a1764e2 --- /dev/null +++ b/book/src/using-fam.md @@ -0,0 +1,163 @@ +# Using C structures with Flexible Array Members + +Since time immemorial, C programmers have been using what was called "the struct +hack". This is a technique for packing a fixed-size structure and a +variable-sized tail within the same memory allocation. Typically this looks +like: + +```c +struct MyRecord { + time_t timestamp; + unsigned seq; + size_t len; + char payload[0]; +}; +``` + +Because this is so useful, it was standardized in C99 as "flexible array +members", using almost identical syntax: +```c +struct MyRecord { + time_t timestamp; + unsigned seq; + size_t len; + char payload[]; // NOTE: empty [] +}; +``` + +Bindgen supports these structures in two different ways. + +## `__IncompleteArrayField` + +By default, bindgen will the corresponding Rust structure: +```rust,ignore +#[repr(C)] +struct MyRecord { + pub timestamp: time_t, + pub seq: ::std::os::raw::c_uint, + pub len: usize, + pub payload: __IncompleteArrayField<::std::os::raw::c_char>, +} +``` + +The `__IncompleteArrayField` type is zero-sized, so this structure represents +the prefix without any trailing data. In order to access that data, it provides +the `as_slice` unsafe method: +```rust,ignore + // SAFETY: there's at least `len` bytes allocated and initialized after `myrecord` + let payload = unsafe { myrecord.payload.as_slice(myrecord.len) }; +``` +There's also `as_mut_slice` which does the obvious. + +These are `unsafe` simply because it's up to you to provide the right length (in +elements of whatever type `payload` is) as there's no way for Rust or Bindgen to +know. In this example, the length is a very straightforward `len` field in the +structure, but it could be encoded in any number of ways within the structure, +or come from somewhere else entirely. + +One big caveat with this technique is that `std::mem::size_of` (or +`size_of_val`) will *only* include the size of the prefix structure. if you're +working out how much storage the whole structure is using, you'll need to add +the suffix yourself. + +## Using Dynamically Sized Types + +If you invoke bindgen with the `--flexarray-dst` option, it will generate +something not quite like this: + +```rust,ignore +#[repr(C)] +struct MyRecord { + pub timestamp: time_t, + pub seq: ::std::os::raw::c_uint, + pub len: usize, + pub payload: [::std::os::raw::c_char], +} +``` +Rust has a set of types which are almost exact analogs for these Flexible Array +Member types: the Dynamically Sized Type ("DST"). For example: + +This looks almost identical to a normal Rust structure, except that you'll note +the type of the `payload` field is a raw slice `[...]` rather than the usual +reference to slice `&[...]`. + +That `payload: [c_char]` is telling Rust that it can't directly know the total +size of this structure - the `payload` field takes an amount of space that's +determined at runtime. This means you can't directly use values of this type, +only references: `&MyRecord`. + +In practice, this is very awkward. So instead, bindgen generates: +```rust,ignore +#[repr(C)] +struct MyRecord { + pub timestamp: time_t, + pub seq: ::std::os::raw::c_uint, + pub len: usize, + pub payload: FAM, +} +``` + +That is: +1. a type parameter `FAM` which represents the type of the `payload` field, +2. it's `?Sized` meaning it can be unsigned (ie, a DST) +3. it has the default type of `[c_char; 0]` - that is a zero-sized array of characters + +This means that referencing plain `MyRecord` will be exactly like `MyRecord` +with `__IncompleteArrayField`: it is a fixed-sized structure which you can +manipulate like a normal Rust value. + +But how do you get to the DST part? + +Bindgen will also implement a set of helper methods for this: + +```rust,ignore +// Static sized variant +impl MyRecord<[::std::os::raw::c_char; 0]> { + pub unsafe fn flex_ref(&self, len: usize) -> &MyRecord<[::std::os::raw::c_char]> { ... } + pub unsafe fn flex_mut_ref(&mut self, len: usize) -> &mut MyRecord<[::std::os::raw::c_char]> { ... } + // And some raw pointer variants +} +``` +These will take a sized `MyRecord<[c_char; 0]>` and a length in elements, and +return a reference to a DST `MyRecord<[c_char]>` where the `payload` field is a +fully usable slice of `len` characters. + +The magic here is that the reference is a fat pointer, which not only encodes +the address, but also the dynamic size of the final field, just like a reference +to a slice is. This means that you get full bounds checked access to the +`payload` field like any other Rust slice. + +It also means that doing `mem::size_of_val(myrecord)` will return the *complete* +size of this structure, including the suffix. + +You can go the other way: +```rust,ignore +// Dynamic sized variant +impl MyRecord<[::std::os::raw::c_char]> { + pub fn fixed(&self) -> (&MyRecord<[::std::os::raw::c_char; 0]>, usize) { ... } + pub fn fixed_mut(&mut self) -> (&mut MyRecord<[::std::os::raw::c_char; 0]>, usize) { ... } + pub fn layout(len: usize) -> std::alloc::Layout { ... } +} +``` +which takes the DST variant of the structure and returns the sized variant, +along with the number of elements are after it. These are all completely safe +because all the information needed is part of the fat `&self` reference. + +The `layout` function takes a length and returns the `Layout` - that is, size +and alignment, so that you can allocate memory for the structure (for example, +using `malloc` so you can pass it to a C function). + +Unfortunately the language features needed to support these methods are still unstable: +- [ptr_metadata](https://doc.rust-lang.org/beta/unstable-book/library-features/ptr-metadata.html), + which enables all the fixed<->DST conversions, and +- [layout_for_ptr](https://doc.rust-lang.org/beta/unstable-book/library-features/layout-for-ptr.html), + which allows he `layout` method + +As a result, if you don't specify `--rust-target nightly` you'll just get the +bare type definitions, but no real way to use them. It's often convenient to add +the +```bash +--raw-line '#![feature(ptr_metadata,layout_for_ptr)]' +``` +option if you're generating Rust as a stand-alone crate. Otherwise you'll need +to add the feature line to your containing crate. From 71cf0383ba93133f0ba743a403c868e4ac7b9bfa Mon Sep 17 00:00:00 2001 From: Jeremy Fitzhardinge Date: Tue, 19 Mar 2024 14:49:02 -0700 Subject: [PATCH 660/942] Update with review comments --- bindgen/codegen/mod.rs | 242 ++++++++++++++++++++++------------------- bindgen/ir/comp.rs | 7 +- 2 files changed, 133 insertions(+), 116 deletions(-) diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index a0a57f1608..fd6d877042 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -1693,7 +1693,7 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit { accessor_kind: FieldAccessorKind, parent: &CompInfo, parent_item: &Item, - _last_field: bool, + last_field: bool, result: &mut CodegenResult, struct_layout: &mut StructLayoutTracker, fields: &mut F, @@ -1775,7 +1775,7 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit { accessor_kind, parent, parent_item, - idx == bfields.len() - 1, + last_field && idx == bfields.len() - 1, result, struct_layout, fields, @@ -2594,116 +2594,13 @@ impl CodeGenerator for CompInfo { } if needs_flexarray_impl { - let prefix = ctx.trait_prefix(); - - let flex_array = - flex_inner_ty.as_ref().map(|ty| quote! { [ #ty ] }); - - let dst_ty_for_impl = quote! { - #canonical_ident < #( #generic_param_names , )* #flex_array > - - }; - let sized_ty_for_impl = quote! { - #canonical_ident < #( #generic_param_names , )* [ #flex_inner_ty; 0 ] > - }; - - let layout = if ctx.options().rust_features().layout_for_ptr { - quote! { - pub fn layout(len: usize) -> ::#prefix::alloc::Layout { - // SAFETY: Null pointers are OK if we don't deref them - unsafe { - let p: *const Self = ::#prefix::ptr::from_raw_parts(::#prefix::ptr::null(), len); - ::#prefix::alloc::Layout::for_value_raw(p) - } - } - } - } else { - quote!() - }; - - let (from_ptr_dst, from_ptr_sized) = if ctx - .options() - .rust_features() - .ptr_metadata - { - ( - quote! { - pub fn fixed(&self) -> (& #sized_ty_for_impl, usize) { - unsafe { - let (ptr, len) = (self as *const Self).to_raw_parts(); - (&*(ptr as *const #sized_ty_for_impl), len) - } - } - - pub fn fixed_mut(&mut self) -> (&mut #sized_ty_for_impl, usize) { - unsafe { - let (ptr, len) = (self as *mut Self).to_raw_parts(); - (&mut *(ptr as *mut #sized_ty_for_impl), len) - - } - } - }, - quote! { - /// Convert a sized prefix to an unsized structure with the given length. - /// - /// SAFETY: Underlying storage is initialized up to at least `len` elements. - pub unsafe fn flex_ref(&self, len: usize) -> &#dst_ty_for_impl { - // SAFETY: Reference is always valid as pointer. Caller is guaranteeing `len`. - unsafe { Self::flex_ptr(self, len) } - } - - /// Convert a mutable sized prefix to an unsized structure with the given length. - /// - /// SAFETY: Underlying storage is initialized up to at least `len` elements. - pub unsafe fn flex_mut_ref(&mut self, len: usize) -> &mut #dst_ty_for_impl { - // SAFETY: Reference is always valid as pointer. Caller is guaranteeing `len`. - unsafe { Self::flex_ptr_mut(self, len).assume_init() } - } - - /// Construct DST variant from a pointer and a size. - /// - /// NOTE: lifetime of returned reference is not tied to any underlying storage. - /// SAFETY: `ptr` is valid. Underlying storage is fully initialized up to at least `len` elements. - pub unsafe fn flex_ptr<'unbounded>(ptr: *const Self, len: usize) -> &'unbounded #dst_ty_for_impl { - unsafe { &*::#prefix::ptr::from_raw_parts(ptr as *const (), len) } - } - - /// Construct mutable DST variant from a pointer and a - /// size. The returned `&mut` reference is initialized - /// pointing to memory referenced by `ptr`, but there's - /// no requirement that that memory be initialized. - /// - /// NOTE: lifetime of returned reference is not tied to any underlying storage. - /// SAFETY: `ptr` is valid. Underlying storage has space for at least `len` elements. - pub unsafe fn flex_ptr_mut<'unbounded>( - ptr: *mut Self, - len: usize, - ) -> ::#prefix::mem::MaybeUninit<&'unbounded mut #dst_ty_for_impl> { - unsafe { - // Initialize reference without ever exposing it, as its possibly uninitialized - let mut uninit = ::#prefix::mem::MaybeUninit::<&mut #dst_ty_for_impl>::uninit(); - (uninit.as_mut_ptr() as *mut *mut #dst_ty_for_impl) - .write(::#prefix::ptr::from_raw_parts_mut(ptr as *mut (), len)); - - uninit - } - } - }, - ) - } else { - (quote!(), quote!()) - }; - - result.push(quote! { - impl #impl_generics_labels #dst_ty_for_impl { - #layout - #from_ptr_dst - } - - impl #impl_generics_labels #sized_ty_for_impl { - #from_ptr_sized - } - }); + result.push(self.generate_flexarray( + ctx, + &canonical_ident, + flex_inner_ty, + &*generic_param_names, + &impl_generics_labels, + )); } if needs_default_impl { @@ -2790,6 +2687,127 @@ impl CodeGenerator for CompInfo { } } +impl CompInfo { + fn generate_flexarray( + &self, + ctx: &BindgenContext, + canonical_ident: &Ident, + flex_inner_ty: Option, + generic_param_names: &[Ident], + impl_generics_labels: &proc_macro2::TokenStream, + ) -> proc_macro2::TokenStream { + let prefix = ctx.trait_prefix(); + + let flex_array = flex_inner_ty.as_ref().map(|ty| quote! { [ #ty ] }); + + let dst_ty_for_impl = quote! { + #canonical_ident < #( #generic_param_names , )* #flex_array > + + }; + let sized_ty_for_impl = quote! { + #canonical_ident < #( #generic_param_names , )* [ #flex_inner_ty; 0 ] > + }; + + let layout = if ctx.options().rust_features().layout_for_ptr { + quote! { + pub fn layout(len: usize) -> ::#prefix::alloc::Layout { + // SAFETY: Null pointers are OK if we don't deref them + unsafe { + let p: *const Self = ::#prefix::ptr::from_raw_parts(::#prefix::ptr::null(), len); + ::#prefix::alloc::Layout::for_value_raw(p) + } + } + } + } else { + quote!() + }; + + let (from_ptr_dst, from_ptr_sized) = if ctx + .options() + .rust_features() + .ptr_metadata + { + ( + quote! { + pub fn fixed(&self) -> (& #sized_ty_for_impl, usize) { + unsafe { + let (ptr, len) = (self as *const Self).to_raw_parts(); + (&*(ptr as *const #sized_ty_for_impl), len) + } + } + + pub fn fixed_mut(&mut self) -> (&mut #sized_ty_for_impl, usize) { + unsafe { + let (ptr, len) = (self as *mut Self).to_raw_parts(); + (&mut *(ptr as *mut #sized_ty_for_impl), len) + + } + } + }, + quote! { + /// Convert a sized prefix to an unsized structure with the given length. + /// + /// SAFETY: Underlying storage is initialized up to at least `len` elements. + pub unsafe fn flex_ref(&self, len: usize) -> &#dst_ty_for_impl { + // SAFETY: Reference is always valid as pointer. Caller is guaranteeing `len`. + unsafe { Self::flex_ptr(self, len) } + } + + /// Convert a mutable sized prefix to an unsized structure with the given length. + /// + /// SAFETY: Underlying storage is initialized up to at least `len` elements. + pub unsafe fn flex_mut_ref(&mut self, len: usize) -> &mut #dst_ty_for_impl { + // SAFETY: Reference is always valid as pointer. Caller is guaranteeing `len`. + unsafe { Self::flex_ptr_mut(self, len).assume_init() } + } + + /// Construct DST variant from a pointer and a size. + /// + /// NOTE: lifetime of returned reference is not tied to any underlying storage. + /// SAFETY: `ptr` is valid. Underlying storage is fully initialized up to at least `len` elements. + pub unsafe fn flex_ptr<'unbounded>(ptr: *const Self, len: usize) -> &'unbounded #dst_ty_for_impl { + unsafe { &*::#prefix::ptr::from_raw_parts(ptr as *const (), len) } + } + + /// Construct mutable DST variant from a pointer and a + /// size. The returned `&mut` reference is initialized + /// pointing to memory referenced by `ptr`, but there's + /// no requirement that that memory be initialized. + /// + /// NOTE: lifetime of returned reference is not tied to any underlying storage. + /// SAFETY: `ptr` is valid. Underlying storage has space for at least `len` elements. + pub unsafe fn flex_ptr_mut<'unbounded>( + ptr: *mut Self, + len: usize, + ) -> ::#prefix::mem::MaybeUninit<&'unbounded mut #dst_ty_for_impl> { + unsafe { + // Initialize reference without ever exposing it, as its possibly uninitialized + let mut uninit = ::#prefix::mem::MaybeUninit::<&mut #dst_ty_for_impl>::uninit(); + (uninit.as_mut_ptr() as *mut *mut #dst_ty_for_impl) + .write(::#prefix::ptr::from_raw_parts_mut(ptr as *mut (), len)); + + uninit + } + } + }, + ) + } else { + (quote!(), quote!()) + }; + + quote! { + impl #impl_generics_labels #dst_ty_for_impl { + #layout + #from_ptr_dst + } + + impl #impl_generics_labels #sized_ty_for_impl { + #from_ptr_sized + } + } + } +} + impl Method { fn codegen_method( &self, diff --git a/bindgen/ir/comp.rs b/bindgen/ir/comp.rs index 5ae2d68747..f6c9e629a1 100644 --- a/bindgen/ir/comp.rs +++ b/bindgen/ir/comp.rs @@ -834,10 +834,9 @@ impl CompFields { CompFields::Error => return None, // panic? }; - // XXX correct with padding on end? - match fields.last() { - None | Some(Field::Bitfields(..)) => None, - Some(Field::DataMember(FieldData { ty, .. })) => ctx + match fields.last()? { + Field::Bitfields(..) => None, + Field::DataMember(FieldData { ty, .. }) => ctx .resolve_type(*ty) .is_incomplete_array(ctx) .map(|item| item.expect_type_id(ctx)), From 0dae6d5fcef0697cd615223ae60cbb1ac5c4b185 Mon Sep 17 00:00:00 2001 From: Jeremy Fitzhardinge Date: Wed, 20 Mar 2024 09:00:46 -0700 Subject: [PATCH 661/942] Small doc tweaks --- book/src/using-fam.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/book/src/using-fam.md b/book/src/using-fam.md index 473a1764e2..aaf19c90fd 100644 --- a/book/src/using-fam.md +++ b/book/src/using-fam.md @@ -29,7 +29,7 @@ Bindgen supports these structures in two different ways. ## `__IncompleteArrayField` -By default, bindgen will the corresponding Rust structure: +By default, bindgen will generate the corresponding Rust structure: ```rust,ignore #[repr(C)] struct MyRecord { @@ -75,7 +75,7 @@ struct MyRecord { } ``` Rust has a set of types which are almost exact analogs for these Flexible Array -Member types: the Dynamically Sized Type ("DST"). For example: +Member types: the Dynamically Sized Type ("DST"). This looks almost identical to a normal Rust structure, except that you'll note the type of the `payload` field is a raw slice `[...]` rather than the usual @@ -99,7 +99,7 @@ struct MyRecord { That is: 1. a type parameter `FAM` which represents the type of the `payload` field, -2. it's `?Sized` meaning it can be unsigned (ie, a DST) +2. it's `?Sized` meaning it can be unsized (ie, a DST) 3. it has the default type of `[c_char; 0]` - that is a zero-sized array of characters This means that referencing plain `MyRecord` will be exactly like `MyRecord` From 0478a394ff9146f675bad030e86d05799b773392 Mon Sep 17 00:00:00 2001 From: Jeremy Fitzhardinge Date: Wed, 27 Mar 2024 12:36:07 -0700 Subject: [PATCH 662/942] Honour --wrap-unsafe-ops Previously it was generating inner `unsafe` blocks for all unsafe functions in conformance with Rust 2024, but now only do it when `--wrap-unsafe-ops` is enabled for consistency with other generated code. Also rename `flex_mut_ref` -> `flex_ref_mut` to make it consistent with `flex_ptr_mut` and general Rust convention. --- .../tests/expectations/tests/flexarray.rs | 112 ++++++++---------- bindgen/codegen/mod.rs | 36 ++++-- 2 files changed, 74 insertions(+), 74 deletions(-) diff --git a/bindgen-tests/tests/expectations/tests/flexarray.rs b/bindgen-tests/tests/expectations/tests/flexarray.rs index 0e735317ba..46579f2cf2 100644 --- a/bindgen-tests/tests/expectations/tests/flexarray.rs +++ b/bindgen-tests/tests/expectations/tests/flexarray.rs @@ -87,16 +87,16 @@ impl flexarray<[::std::os::raw::c_int; 0]> { /// /// SAFETY: Underlying storage is initialized up to at least `len` elements. pub unsafe fn flex_ref(&self, len: usize) -> &flexarray<[::std::os::raw::c_int]> { - unsafe { Self::flex_ptr(self, len) } + Self::flex_ptr(self, len) } /// Convert a mutable sized prefix to an unsized structure with the given length. /// /// SAFETY: Underlying storage is initialized up to at least `len` elements. - pub unsafe fn flex_mut_ref( + pub unsafe fn flex_ref_mut( &mut self, len: usize, ) -> &mut flexarray<[::std::os::raw::c_int]> { - unsafe { Self::flex_ptr_mut(self, len).assume_init() } + Self::flex_ptr_mut(self, len).assume_init() } /// Construct DST variant from a pointer and a size. /// @@ -106,7 +106,7 @@ impl flexarray<[::std::os::raw::c_int; 0]> { ptr: *const Self, len: usize, ) -> &'unbounded flexarray<[::std::os::raw::c_int]> { - unsafe { &*::std::ptr::from_raw_parts(ptr as *const (), len) } + &*::std::ptr::from_raw_parts(ptr as *const (), len) } /// Construct mutable DST variant from a pointer and a /// size. The returned `&mut` reference is initialized @@ -119,14 +119,12 @@ impl flexarray<[::std::os::raw::c_int; 0]> { ptr: *mut Self, len: usize, ) -> ::std::mem::MaybeUninit<&'unbounded mut flexarray<[::std::os::raw::c_int]>> { - unsafe { - let mut uninit = ::std::mem::MaybeUninit::< - &mut flexarray<[::std::os::raw::c_int]>, - >::uninit(); - (uninit.as_mut_ptr() as *mut *mut flexarray<[::std::os::raw::c_int]>) - .write(::std::ptr::from_raw_parts_mut(ptr as *mut (), len)); - uninit - } + let mut uninit = ::std::mem::MaybeUninit::< + &mut flexarray<[::std::os::raw::c_int]>, + >::uninit(); + (uninit.as_mut_ptr() as *mut *mut flexarray<[::std::os::raw::c_int]>) + .write(::std::ptr::from_raw_parts_mut(ptr as *mut (), len)); + uninit } } #[repr(C)] @@ -190,16 +188,16 @@ impl flexarray_zero<[::std::os::raw::c_int; 0]> { &self, len: usize, ) -> &flexarray_zero<[::std::os::raw::c_int]> { - unsafe { Self::flex_ptr(self, len) } + Self::flex_ptr(self, len) } /// Convert a mutable sized prefix to an unsized structure with the given length. /// /// SAFETY: Underlying storage is initialized up to at least `len` elements. - pub unsafe fn flex_mut_ref( + pub unsafe fn flex_ref_mut( &mut self, len: usize, ) -> &mut flexarray_zero<[::std::os::raw::c_int]> { - unsafe { Self::flex_ptr_mut(self, len).assume_init() } + Self::flex_ptr_mut(self, len).assume_init() } /// Construct DST variant from a pointer and a size. /// @@ -209,7 +207,7 @@ impl flexarray_zero<[::std::os::raw::c_int; 0]> { ptr: *const Self, len: usize, ) -> &'unbounded flexarray_zero<[::std::os::raw::c_int]> { - unsafe { &*::std::ptr::from_raw_parts(ptr as *const (), len) } + &*::std::ptr::from_raw_parts(ptr as *const (), len) } /// Construct mutable DST variant from a pointer and a /// size. The returned `&mut` reference is initialized @@ -224,14 +222,12 @@ impl flexarray_zero<[::std::os::raw::c_int; 0]> { ) -> ::std::mem::MaybeUninit< &'unbounded mut flexarray_zero<[::std::os::raw::c_int]>, > { - unsafe { - let mut uninit = ::std::mem::MaybeUninit::< - &mut flexarray_zero<[::std::os::raw::c_int]>, - >::uninit(); - (uninit.as_mut_ptr() as *mut *mut flexarray_zero<[::std::os::raw::c_int]>) - .write(::std::ptr::from_raw_parts_mut(ptr as *mut (), len)); - uninit - } + let mut uninit = ::std::mem::MaybeUninit::< + &mut flexarray_zero<[::std::os::raw::c_int]>, + >::uninit(); + (uninit.as_mut_ptr() as *mut *mut flexarray_zero<[::std::os::raw::c_int]>) + .write(::std::ptr::from_raw_parts_mut(ptr as *mut (), len)); + uninit } } #[repr(C)] @@ -266,16 +262,16 @@ impl flexarray_template { /// /// SAFETY: Underlying storage is initialized up to at least `len` elements. pub unsafe fn flex_ref(&self, len: usize) -> &flexarray_template { - unsafe { Self::flex_ptr(self, len) } + Self::flex_ptr(self, len) } /// Convert a mutable sized prefix to an unsized structure with the given length. /// /// SAFETY: Underlying storage is initialized up to at least `len` elements. - pub unsafe fn flex_mut_ref( + pub unsafe fn flex_ref_mut( &mut self, len: usize, ) -> &mut flexarray_template { - unsafe { Self::flex_ptr_mut(self, len).assume_init() } + Self::flex_ptr_mut(self, len).assume_init() } /// Construct DST variant from a pointer and a size. /// @@ -285,7 +281,7 @@ impl flexarray_template { ptr: *const Self, len: usize, ) -> &'unbounded flexarray_template { - unsafe { &*::std::ptr::from_raw_parts(ptr as *const (), len) } + &*::std::ptr::from_raw_parts(ptr as *const (), len) } /// Construct mutable DST variant from a pointer and a /// size. The returned `&mut` reference is initialized @@ -298,14 +294,12 @@ impl flexarray_template { ptr: *mut Self, len: usize, ) -> ::std::mem::MaybeUninit<&'unbounded mut flexarray_template> { - unsafe { - let mut uninit = ::std::mem::MaybeUninit::< - &mut flexarray_template, - >::uninit(); - (uninit.as_mut_ptr() as *mut *mut flexarray_template) - .write(::std::ptr::from_raw_parts_mut(ptr as *mut (), len)); - uninit - } + let mut uninit = ::std::mem::MaybeUninit::< + &mut flexarray_template, + >::uninit(); + (uninit.as_mut_ptr() as *mut *mut flexarray_template) + .write(::std::ptr::from_raw_parts_mut(ptr as *mut (), len)); + uninit } } impl Default for flexarray_template { @@ -442,16 +436,16 @@ impl flexarray_bogus_zero_fam<[::std::os::raw::c_char; 0]> { &self, len: usize, ) -> &flexarray_bogus_zero_fam<[::std::os::raw::c_char]> { - unsafe { Self::flex_ptr(self, len) } + Self::flex_ptr(self, len) } /// Convert a mutable sized prefix to an unsized structure with the given length. /// /// SAFETY: Underlying storage is initialized up to at least `len` elements. - pub unsafe fn flex_mut_ref( + pub unsafe fn flex_ref_mut( &mut self, len: usize, ) -> &mut flexarray_bogus_zero_fam<[::std::os::raw::c_char]> { - unsafe { Self::flex_ptr_mut(self, len).assume_init() } + Self::flex_ptr_mut(self, len).assume_init() } /// Construct DST variant from a pointer and a size. /// @@ -461,7 +455,7 @@ impl flexarray_bogus_zero_fam<[::std::os::raw::c_char; 0]> { ptr: *const Self, len: usize, ) -> &'unbounded flexarray_bogus_zero_fam<[::std::os::raw::c_char]> { - unsafe { &*::std::ptr::from_raw_parts(ptr as *const (), len) } + &*::std::ptr::from_raw_parts(ptr as *const (), len) } /// Construct mutable DST variant from a pointer and a /// size. The returned `&mut` reference is initialized @@ -476,15 +470,13 @@ impl flexarray_bogus_zero_fam<[::std::os::raw::c_char; 0]> { ) -> ::std::mem::MaybeUninit< &'unbounded mut flexarray_bogus_zero_fam<[::std::os::raw::c_char]>, > { - unsafe { - let mut uninit = ::std::mem::MaybeUninit::< - &mut flexarray_bogus_zero_fam<[::std::os::raw::c_char]>, - >::uninit(); - (uninit.as_mut_ptr() - as *mut *mut flexarray_bogus_zero_fam<[::std::os::raw::c_char]>) - .write(::std::ptr::from_raw_parts_mut(ptr as *mut (), len)); - uninit - } + let mut uninit = ::std::mem::MaybeUninit::< + &mut flexarray_bogus_zero_fam<[::std::os::raw::c_char]>, + >::uninit(); + (uninit.as_mut_ptr() + as *mut *mut flexarray_bogus_zero_fam<[::std::os::raw::c_char]>) + .write(::std::ptr::from_raw_parts_mut(ptr as *mut (), len)); + uninit } } #[repr(C)] @@ -554,16 +546,16 @@ impl flexarray_align<[::std::os::raw::c_int; 0]> { &self, len: usize, ) -> &flexarray_align<[::std::os::raw::c_int]> { - unsafe { Self::flex_ptr(self, len) } + Self::flex_ptr(self, len) } /// Convert a mutable sized prefix to an unsized structure with the given length. /// /// SAFETY: Underlying storage is initialized up to at least `len` elements. - pub unsafe fn flex_mut_ref( + pub unsafe fn flex_ref_mut( &mut self, len: usize, ) -> &mut flexarray_align<[::std::os::raw::c_int]> { - unsafe { Self::flex_ptr_mut(self, len).assume_init() } + Self::flex_ptr_mut(self, len).assume_init() } /// Construct DST variant from a pointer and a size. /// @@ -573,7 +565,7 @@ impl flexarray_align<[::std::os::raw::c_int; 0]> { ptr: *const Self, len: usize, ) -> &'unbounded flexarray_align<[::std::os::raw::c_int]> { - unsafe { &*::std::ptr::from_raw_parts(ptr as *const (), len) } + &*::std::ptr::from_raw_parts(ptr as *const (), len) } /// Construct mutable DST variant from a pointer and a /// size. The returned `&mut` reference is initialized @@ -588,14 +580,12 @@ impl flexarray_align<[::std::os::raw::c_int; 0]> { ) -> ::std::mem::MaybeUninit< &'unbounded mut flexarray_align<[::std::os::raw::c_int]>, > { - unsafe { - let mut uninit = ::std::mem::MaybeUninit::< - &mut flexarray_align<[::std::os::raw::c_int]>, - >::uninit(); - (uninit.as_mut_ptr() as *mut *mut flexarray_align<[::std::os::raw::c_int]>) - .write(::std::ptr::from_raw_parts_mut(ptr as *mut (), len)); - uninit - } + let mut uninit = ::std::mem::MaybeUninit::< + &mut flexarray_align<[::std::os::raw::c_int]>, + >::uninit(); + (uninit.as_mut_ptr() as *mut *mut flexarray_align<[::std::os::raw::c_int]>) + .write(::std::ptr::from_raw_parts_mut(ptr as *mut (), len)); + uninit } } impl Default for flexarray_align<[::std::os::raw::c_int; 0]> { diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index fd6d877042..0ceac5e9ee 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -2727,6 +2727,24 @@ impl CompInfo { .rust_features() .ptr_metadata { + let flex_ref_inner = ctx.wrap_unsafe_ops(quote! { + Self::flex_ptr(self, len) + }); + let flex_ref_mut_inner = ctx.wrap_unsafe_ops(quote! { + Self::flex_ptr_mut(self, len).assume_init() + }); + let flex_ptr_inner = ctx.wrap_unsafe_ops(quote! { + &*::#prefix::ptr::from_raw_parts(ptr as *const (), len) + }); + let flex_ptr_mut_inner = ctx.wrap_unsafe_ops(quote! { + // Initialize reference without ever exposing it, as its possibly uninitialized + let mut uninit = ::#prefix::mem::MaybeUninit::<&mut #dst_ty_for_impl>::uninit(); + (uninit.as_mut_ptr() as *mut *mut #dst_ty_for_impl) + .write(::#prefix::ptr::from_raw_parts_mut(ptr as *mut (), len)); + + uninit + }); + ( quote! { pub fn fixed(&self) -> (& #sized_ty_for_impl, usize) { @@ -2740,7 +2758,6 @@ impl CompInfo { unsafe { let (ptr, len) = (self as *mut Self).to_raw_parts(); (&mut *(ptr as *mut #sized_ty_for_impl), len) - } } }, @@ -2750,15 +2767,15 @@ impl CompInfo { /// SAFETY: Underlying storage is initialized up to at least `len` elements. pub unsafe fn flex_ref(&self, len: usize) -> &#dst_ty_for_impl { // SAFETY: Reference is always valid as pointer. Caller is guaranteeing `len`. - unsafe { Self::flex_ptr(self, len) } + #flex_ref_inner } /// Convert a mutable sized prefix to an unsized structure with the given length. /// /// SAFETY: Underlying storage is initialized up to at least `len` elements. - pub unsafe fn flex_mut_ref(&mut self, len: usize) -> &mut #dst_ty_for_impl { + pub unsafe fn flex_ref_mut(&mut self, len: usize) -> &mut #dst_ty_for_impl { // SAFETY: Reference is always valid as pointer. Caller is guaranteeing `len`. - unsafe { Self::flex_ptr_mut(self, len).assume_init() } + #flex_ref_mut_inner } /// Construct DST variant from a pointer and a size. @@ -2766,7 +2783,7 @@ impl CompInfo { /// NOTE: lifetime of returned reference is not tied to any underlying storage. /// SAFETY: `ptr` is valid. Underlying storage is fully initialized up to at least `len` elements. pub unsafe fn flex_ptr<'unbounded>(ptr: *const Self, len: usize) -> &'unbounded #dst_ty_for_impl { - unsafe { &*::#prefix::ptr::from_raw_parts(ptr as *const (), len) } + #flex_ptr_inner } /// Construct mutable DST variant from a pointer and a @@ -2780,14 +2797,7 @@ impl CompInfo { ptr: *mut Self, len: usize, ) -> ::#prefix::mem::MaybeUninit<&'unbounded mut #dst_ty_for_impl> { - unsafe { - // Initialize reference without ever exposing it, as its possibly uninitialized - let mut uninit = ::#prefix::mem::MaybeUninit::<&mut #dst_ty_for_impl>::uninit(); - (uninit.as_mut_ptr() as *mut *mut #dst_ty_for_impl) - .write(::#prefix::ptr::from_raw_parts_mut(ptr as *mut (), len)); - - uninit - } + #flex_ptr_mut_inner } }, ) From 4778df57db0f88aa9957b0f0cf60cf6cebafbbff Mon Sep 17 00:00:00 2001 From: Jeremy Fitzhardinge Date: Wed, 27 Mar 2024 12:42:27 -0700 Subject: [PATCH 663/942] Make all the flexarray helpers inline The conversions between fixed and dynamically sized forms are essentially type-level transforms which should have trivial implementations in terms of generated code, so there's no reason not to make them inline. --- .../tests/expectations/tests/flexarray.rs | 25 +++++++++++++++++++ bindgen/codegen/mod.rs | 5 ++++ 2 files changed, 30 insertions(+) diff --git a/bindgen-tests/tests/expectations/tests/flexarray.rs b/bindgen-tests/tests/expectations/tests/flexarray.rs index 46579f2cf2..41d07311c5 100644 --- a/bindgen-tests/tests/expectations/tests/flexarray.rs +++ b/bindgen-tests/tests/expectations/tests/flexarray.rs @@ -69,12 +69,14 @@ impl flexarray<[::std::os::raw::c_int]> { ::std::alloc::Layout::for_value_raw(p) } } + #[inline] pub fn fixed(&self) -> (&flexarray<[::std::os::raw::c_int; 0]>, usize) { unsafe { let (ptr, len) = (self as *const Self).to_raw_parts(); (&*(ptr as *const flexarray<[::std::os::raw::c_int; 0]>), len) } } + #[inline] pub fn fixed_mut(&mut self) -> (&mut flexarray<[::std::os::raw::c_int; 0]>, usize) { unsafe { let (ptr, len) = (self as *mut Self).to_raw_parts(); @@ -92,6 +94,7 @@ impl flexarray<[::std::os::raw::c_int; 0]> { /// Convert a mutable sized prefix to an unsized structure with the given length. /// /// SAFETY: Underlying storage is initialized up to at least `len` elements. + #[inline] pub unsafe fn flex_ref_mut( &mut self, len: usize, @@ -102,6 +105,7 @@ impl flexarray<[::std::os::raw::c_int; 0]> { /// /// NOTE: lifetime of returned reference is not tied to any underlying storage. /// SAFETY: `ptr` is valid. Underlying storage is fully initialized up to at least `len` elements. + #[inline] pub unsafe fn flex_ptr<'unbounded>( ptr: *const Self, len: usize, @@ -115,6 +119,7 @@ impl flexarray<[::std::os::raw::c_int; 0]> { /// /// NOTE: lifetime of returned reference is not tied to any underlying storage. /// SAFETY: `ptr` is valid. Underlying storage has space for at least `len` elements. + #[inline] pub unsafe fn flex_ptr_mut<'unbounded>( ptr: *mut Self, len: usize, @@ -165,12 +170,14 @@ impl flexarray_zero<[::std::os::raw::c_int]> { ::std::alloc::Layout::for_value_raw(p) } } + #[inline] pub fn fixed(&self) -> (&flexarray_zero<[::std::os::raw::c_int; 0]>, usize) { unsafe { let (ptr, len) = (self as *const Self).to_raw_parts(); (&*(ptr as *const flexarray_zero<[::std::os::raw::c_int; 0]>), len) } } + #[inline] pub fn fixed_mut( &mut self, ) -> (&mut flexarray_zero<[::std::os::raw::c_int; 0]>, usize) { @@ -193,6 +200,7 @@ impl flexarray_zero<[::std::os::raw::c_int; 0]> { /// Convert a mutable sized prefix to an unsized structure with the given length. /// /// SAFETY: Underlying storage is initialized up to at least `len` elements. + #[inline] pub unsafe fn flex_ref_mut( &mut self, len: usize, @@ -203,6 +211,7 @@ impl flexarray_zero<[::std::os::raw::c_int; 0]> { /// /// NOTE: lifetime of returned reference is not tied to any underlying storage. /// SAFETY: `ptr` is valid. Underlying storage is fully initialized up to at least `len` elements. + #[inline] pub unsafe fn flex_ptr<'unbounded>( ptr: *const Self, len: usize, @@ -216,6 +225,7 @@ impl flexarray_zero<[::std::os::raw::c_int; 0]> { /// /// NOTE: lifetime of returned reference is not tied to any underlying storage. /// SAFETY: `ptr` is valid. Underlying storage has space for at least `len` elements. + #[inline] pub unsafe fn flex_ptr_mut<'unbounded>( ptr: *mut Self, len: usize, @@ -244,12 +254,14 @@ impl flexarray_template { ::std::alloc::Layout::for_value_raw(p) } } + #[inline] pub fn fixed(&self) -> (&flexarray_template, usize) { unsafe { let (ptr, len) = (self as *const Self).to_raw_parts(); (&*(ptr as *const flexarray_template), len) } } + #[inline] pub fn fixed_mut(&mut self) -> (&mut flexarray_template, usize) { unsafe { let (ptr, len) = (self as *mut Self).to_raw_parts(); @@ -267,6 +279,7 @@ impl flexarray_template { /// Convert a mutable sized prefix to an unsized structure with the given length. /// /// SAFETY: Underlying storage is initialized up to at least `len` elements. + #[inline] pub unsafe fn flex_ref_mut( &mut self, len: usize, @@ -277,6 +290,7 @@ impl flexarray_template { /// /// NOTE: lifetime of returned reference is not tied to any underlying storage. /// SAFETY: `ptr` is valid. Underlying storage is fully initialized up to at least `len` elements. + #[inline] pub unsafe fn flex_ptr<'unbounded>( ptr: *const Self, len: usize, @@ -290,6 +304,7 @@ impl flexarray_template { /// /// NOTE: lifetime of returned reference is not tied to any underlying storage. /// SAFETY: `ptr` is valid. Underlying storage has space for at least `len` elements. + #[inline] pub unsafe fn flex_ptr_mut<'unbounded>( ptr: *mut Self, len: usize, @@ -404,6 +419,7 @@ impl flexarray_bogus_zero_fam<[::std::os::raw::c_char]> { ::std::alloc::Layout::for_value_raw(p) } } + #[inline] pub fn fixed( &self, ) -> (&flexarray_bogus_zero_fam<[::std::os::raw::c_char; 0]>, usize) { @@ -415,6 +431,7 @@ impl flexarray_bogus_zero_fam<[::std::os::raw::c_char]> { ) } } + #[inline] pub fn fixed_mut( &mut self, ) -> (&mut flexarray_bogus_zero_fam<[::std::os::raw::c_char; 0]>, usize) { @@ -441,6 +458,7 @@ impl flexarray_bogus_zero_fam<[::std::os::raw::c_char; 0]> { /// Convert a mutable sized prefix to an unsized structure with the given length. /// /// SAFETY: Underlying storage is initialized up to at least `len` elements. + #[inline] pub unsafe fn flex_ref_mut( &mut self, len: usize, @@ -451,6 +469,7 @@ impl flexarray_bogus_zero_fam<[::std::os::raw::c_char; 0]> { /// /// NOTE: lifetime of returned reference is not tied to any underlying storage. /// SAFETY: `ptr` is valid. Underlying storage is fully initialized up to at least `len` elements. + #[inline] pub unsafe fn flex_ptr<'unbounded>( ptr: *const Self, len: usize, @@ -464,6 +483,7 @@ impl flexarray_bogus_zero_fam<[::std::os::raw::c_char; 0]> { /// /// NOTE: lifetime of returned reference is not tied to any underlying storage. /// SAFETY: `ptr` is valid. Underlying storage has space for at least `len` elements. + #[inline] pub unsafe fn flex_ptr_mut<'unbounded>( ptr: *mut Self, len: usize, @@ -523,12 +543,14 @@ impl flexarray_align<[::std::os::raw::c_int]> { ::std::alloc::Layout::for_value_raw(p) } } + #[inline] pub fn fixed(&self) -> (&flexarray_align<[::std::os::raw::c_int; 0]>, usize) { unsafe { let (ptr, len) = (self as *const Self).to_raw_parts(); (&*(ptr as *const flexarray_align<[::std::os::raw::c_int; 0]>), len) } } + #[inline] pub fn fixed_mut( &mut self, ) -> (&mut flexarray_align<[::std::os::raw::c_int; 0]>, usize) { @@ -551,6 +573,7 @@ impl flexarray_align<[::std::os::raw::c_int; 0]> { /// Convert a mutable sized prefix to an unsized structure with the given length. /// /// SAFETY: Underlying storage is initialized up to at least `len` elements. + #[inline] pub unsafe fn flex_ref_mut( &mut self, len: usize, @@ -561,6 +584,7 @@ impl flexarray_align<[::std::os::raw::c_int; 0]> { /// /// NOTE: lifetime of returned reference is not tied to any underlying storage. /// SAFETY: `ptr` is valid. Underlying storage is fully initialized up to at least `len` elements. + #[inline] pub unsafe fn flex_ptr<'unbounded>( ptr: *const Self, len: usize, @@ -574,6 +598,7 @@ impl flexarray_align<[::std::os::raw::c_int; 0]> { /// /// NOTE: lifetime of returned reference is not tied to any underlying storage. /// SAFETY: `ptr` is valid. Underlying storage has space for at least `len` elements. + #[inline] pub unsafe fn flex_ptr_mut<'unbounded>( ptr: *mut Self, len: usize, diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 0ceac5e9ee..070d9dec6f 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -2747,6 +2747,7 @@ impl CompInfo { ( quote! { + #[inline] pub fn fixed(&self) -> (& #sized_ty_for_impl, usize) { unsafe { let (ptr, len) = (self as *const Self).to_raw_parts(); @@ -2754,6 +2755,7 @@ impl CompInfo { } } + #[inline] pub fn fixed_mut(&mut self) -> (&mut #sized_ty_for_impl, usize) { unsafe { let (ptr, len) = (self as *mut Self).to_raw_parts(); @@ -2773,6 +2775,7 @@ impl CompInfo { /// Convert a mutable sized prefix to an unsized structure with the given length. /// /// SAFETY: Underlying storage is initialized up to at least `len` elements. + #[inline] pub unsafe fn flex_ref_mut(&mut self, len: usize) -> &mut #dst_ty_for_impl { // SAFETY: Reference is always valid as pointer. Caller is guaranteeing `len`. #flex_ref_mut_inner @@ -2782,6 +2785,7 @@ impl CompInfo { /// /// NOTE: lifetime of returned reference is not tied to any underlying storage. /// SAFETY: `ptr` is valid. Underlying storage is fully initialized up to at least `len` elements. + #[inline] pub unsafe fn flex_ptr<'unbounded>(ptr: *const Self, len: usize) -> &'unbounded #dst_ty_for_impl { #flex_ptr_inner } @@ -2793,6 +2797,7 @@ impl CompInfo { /// /// NOTE: lifetime of returned reference is not tied to any underlying storage. /// SAFETY: `ptr` is valid. Underlying storage has space for at least `len` elements. + #[inline] pub unsafe fn flex_ptr_mut<'unbounded>( ptr: *mut Self, len: usize, From 7e9043497297e04e91ae76dfe0d2e7998828e529 Mon Sep 17 00:00:00 2001 From: Jeremy Fitzhardinge Date: Mon, 1 Apr 2024 15:13:09 -0700 Subject: [PATCH 664/942] Update test fixtures --- .../tests/expectations/tests/flexarray.rs | 201 +++++------------- 1 file changed, 56 insertions(+), 145 deletions(-) diff --git a/bindgen-tests/tests/expectations/tests/flexarray.rs b/bindgen-tests/tests/expectations/tests/flexarray.rs index 41d07311c5..2c47f0ec55 100644 --- a/bindgen-tests/tests/expectations/tests/flexarray.rs +++ b/bindgen-tests/tests/expectations/tests/flexarray.rs @@ -37,31 +37,16 @@ pub struct flexarray { pub count: ::std::os::raw::c_int, pub data: FAM, } -#[test] -fn bindgen_test_layout_flexarray() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(flexarray)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(flexarray)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).count) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(flexarray), "::", stringify!(count)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(flexarray), "::", stringify!(data)), - ); -} +const _: () = { + ["Size of flexarray"][::std::mem::size_of::() - 4usize]; + ["Alignment of flexarray"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: flexarray::count", + ][::std::mem::offset_of!(flexarray, count) - 0usize]; + [ + "Offset of field: flexarray::data", + ][::std::mem::offset_of!(flexarray, data) - 4usize]; +}; impl flexarray<[::std::os::raw::c_int]> { pub fn layout(len: usize) -> ::std::alloc::Layout { unsafe { @@ -138,31 +123,16 @@ pub struct flexarray_zero { pub count: ::std::os::raw::c_int, pub data: FAM, } -#[test] -fn bindgen_test_layout_flexarray_zero() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(flexarray_zero)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(flexarray_zero)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).count) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(flexarray_zero), "::", stringify!(count)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(flexarray_zero), "::", stringify!(data)), - ); -} +const _: () = { + ["Size of flexarray_zero"][::std::mem::size_of::() - 4usize]; + ["Alignment of flexarray_zero"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: flexarray_zero::count", + ][::std::mem::offset_of!(flexarray_zero, count) - 0usize]; + [ + "Offset of field: flexarray_zero::data", + ][::std::mem::offset_of!(flexarray_zero, data) - 4usize]; +}; impl flexarray_zero<[::std::os::raw::c_int]> { pub fn layout(len: usize) -> ::std::alloc::Layout { unsafe { @@ -331,26 +301,13 @@ impl Default for flexarray_template { pub struct flexarray_ref { pub things: *mut flexarray, } -#[test] -fn bindgen_test_layout_flexarray_ref() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(flexarray_ref)), - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(flexarray_ref)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).things) as usize - ptr as usize }, - 0usize, - concat!("Offset of field: ", stringify!(flexarray_ref), "::", stringify!(things)), - ); -} +const _: () = { + ["Size of flexarray_ref"][::std::mem::size_of::() - 8usize]; + ["Alignment of flexarray_ref"][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: flexarray_ref::things", + ][::std::mem::offset_of!(flexarray_ref, things) - 0usize]; +}; impl Default for flexarray_ref { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); @@ -367,51 +324,23 @@ pub struct flexarray_bogus_zero_fam { pub data1: __IncompleteArrayField<::std::os::raw::c_int>, pub data2: FAM, } -#[test] -fn bindgen_test_layout_flexarray_bogus_zero_fam() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(flexarray_bogus_zero_fam)), - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(flexarray_bogus_zero_fam)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).count) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(flexarray_bogus_zero_fam), - "::", - stringify!(count), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).data1) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(flexarray_bogus_zero_fam), - "::", - stringify!(data1), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).data2) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(flexarray_bogus_zero_fam), - "::", - stringify!(data2), - ), - ); -} +const _: () = { + [ + "Size of flexarray_bogus_zero_fam", + ][::std::mem::size_of::() - 4usize]; + [ + "Alignment of flexarray_bogus_zero_fam", + ][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: flexarray_bogus_zero_fam::count", + ][::std::mem::offset_of!(flexarray_bogus_zero_fam, count) - 0usize]; + [ + "Offset of field: flexarray_bogus_zero_fam::data1", + ][::std::mem::offset_of!(flexarray_bogus_zero_fam, data1) - 4usize]; + [ + "Offset of field: flexarray_bogus_zero_fam::data2", + ][::std::mem::offset_of!(flexarray_bogus_zero_fam, data2) - 4usize]; +}; impl flexarray_bogus_zero_fam<[::std::os::raw::c_char]> { pub fn layout(len: usize) -> ::std::alloc::Layout { unsafe { @@ -506,36 +435,18 @@ pub struct flexarray_align { pub count: ::std::os::raw::c_int, pub data: FAM, } -#[test] -fn bindgen_test_layout_flexarray_align() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 128usize, - concat!("Size of: ", stringify!(flexarray_align)), - ); - assert_eq!( - ::std::mem::align_of::(), - 128usize, - concat!("Alignment of ", stringify!(flexarray_align)), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).count) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(flexarray_align), - "::", - stringify!(count), - ), - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize }, - 4usize, - concat!("Offset of field: ", stringify!(flexarray_align), "::", stringify!(data)), - ); -} +const _: () = { + ["Size of flexarray_align"][::std::mem::size_of::() - 128usize]; + [ + "Alignment of flexarray_align", + ][::std::mem::align_of::() - 128usize]; + [ + "Offset of field: flexarray_align::count", + ][::std::mem::offset_of!(flexarray_align, count) - 0usize]; + [ + "Offset of field: flexarray_align::data", + ][::std::mem::offset_of!(flexarray_align, data) - 4usize]; +}; impl flexarray_align<[::std::os::raw::c_int]> { pub fn layout(len: usize) -> ::std::alloc::Layout { unsafe { From 5260c911c29ce5b64f4a839e2139c12137da0e18 Mon Sep 17 00:00:00 2001 From: forcedebug Date: Tue, 23 Apr 2024 20:11:16 +0800 Subject: [PATCH 665/942] chore: fix some typos in comments Signed-off-by: forcedebug --- bindgen-tests/tests/headers/constructors.hpp | 2 +- bindgen-tests/tests/headers/constructors_1_33.hpp | 2 +- bindgen/ir/comp.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bindgen-tests/tests/headers/constructors.hpp b/bindgen-tests/tests/headers/constructors.hpp index d417488917..2f8d57b00b 100644 --- a/bindgen-tests/tests/headers/constructors.hpp +++ b/bindgen-tests/tests/headers/constructors.hpp @@ -1,6 +1,6 @@ class TestOverload { - // This one shouldnt' be generated. + // This one shouldn't be generated. TestOverload(); public: TestOverload(int); diff --git a/bindgen-tests/tests/headers/constructors_1_33.hpp b/bindgen-tests/tests/headers/constructors_1_33.hpp index 7c6262d417..e275f8907e 100644 --- a/bindgen-tests/tests/headers/constructors_1_33.hpp +++ b/bindgen-tests/tests/headers/constructors_1_33.hpp @@ -1,7 +1,7 @@ // bindgen-flags: --rust-target 1.33 class TestOverload { - // This one shouldnt' be generated. + // This one shouldn't be generated. TestOverload(); public: /// Calling this should use `mem::unintialized()` and not `MaybeUninit()` as only rust 1.36 includes that. diff --git a/bindgen/ir/comp.rs b/bindgen/ir/comp.rs index f6c9e629a1..13a8184fc5 100644 --- a/bindgen/ir/comp.rs +++ b/bindgen/ir/comp.rs @@ -1449,7 +1449,7 @@ impl CompInfo { } CXCursor_TemplateTypeParameter => { let param = Item::type_param(None, cur, ctx).expect( - "Item::type_param should't fail when pointing \ + "Item::type_param shouldn't fail when pointing \ at a TemplateTypeParameter", ); ci.template_params.push(param); From 9eb512e27168d406e5a0dc406cc8f8b706fdf0c6 Mon Sep 17 00:00:00 2001 From: discord9 Date: Tue, 23 Apr 2024 15:31:32 +0800 Subject: [PATCH 666/942] feat: add dynamic loading of variable --- .../dynamic_loading_variable_required.rs | 32 +++++++++++++ .../tests/dynamic_loading_variable_simple.rs | 32 +++++++++++++ ...dynamic_loading_variable_with_allowlist.rs | 30 ++++++++++++ .../dynamic_loading_variable_required.h | 4 ++ .../headers/dynamic_loading_variable_simple.h | 4 ++ ...ynamic_loading_variable_with_allowlist.hpp | 5 ++ bindgen/codegen/dyngen.rs | 47 ++++++++++++++++++- bindgen/codegen/mod.rs | 16 +++++-- 8 files changed, 165 insertions(+), 5 deletions(-) create mode 100644 bindgen-tests/tests/expectations/tests/dynamic_loading_variable_required.rs create mode 100644 bindgen-tests/tests/expectations/tests/dynamic_loading_variable_simple.rs create mode 100644 bindgen-tests/tests/expectations/tests/dynamic_loading_variable_with_allowlist.rs create mode 100644 bindgen-tests/tests/headers/dynamic_loading_variable_required.h create mode 100644 bindgen-tests/tests/headers/dynamic_loading_variable_simple.h create mode 100644 bindgen-tests/tests/headers/dynamic_loading_variable_with_allowlist.hpp diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_variable_required.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_variable_required.rs new file mode 100644 index 0000000000..a96efbe546 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_variable_required.rs @@ -0,0 +1,32 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub struct TestLib { + __library: ::libloading::Library, + pub foo: *mut ::std::os::raw::c_int, + pub baz: *mut *mut ::std::os::raw::c_int, +} +impl TestLib { + pub unsafe fn new

(path: P) -> Result + where + P: AsRef<::std::ffi::OsStr>, + { + let library = ::libloading::Library::new(path)?; + Self::from_library(library) + } + pub unsafe fn from_library(library: L) -> Result + where + L: Into<::libloading::Library>, + { + let __library = library.into(); + let foo = __library.get::<*mut ::std::os::raw::c_int>(b"foo\0").map(|sym| *sym)?; + let baz = __library + .get::<*mut *mut ::std::os::raw::c_int>(b"baz\0") + .map(|sym| *sym)?; + Ok(TestLib { __library, foo, baz }) + } + pub unsafe fn foo(&self) -> *mut ::std::os::raw::c_int { + self.foo + } + pub unsafe fn baz(&self) -> *mut *mut ::std::os::raw::c_int { + self.baz + } +} diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_variable_simple.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_variable_simple.rs new file mode 100644 index 0000000000..ced70dbdba --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_variable_simple.rs @@ -0,0 +1,32 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub struct TestLib { + __library: ::libloading::Library, + pub foo: Result<*mut ::std::os::raw::c_int, ::libloading::Error>, + pub baz: Result<*mut *mut ::std::os::raw::c_int, ::libloading::Error>, +} +impl TestLib { + pub unsafe fn new

(path: P) -> Result + where + P: AsRef<::std::ffi::OsStr>, + { + let library = ::libloading::Library::new(path)?; + Self::from_library(library) + } + pub unsafe fn from_library(library: L) -> Result + where + L: Into<::libloading::Library>, + { + let __library = library.into(); + let foo = __library.get::<*mut ::std::os::raw::c_int>(b"foo\0").map(|sym| *sym); + let baz = __library + .get::<*mut *mut ::std::os::raw::c_int>(b"baz\0") + .map(|sym| *sym); + Ok(TestLib { __library, foo, baz }) + } + pub unsafe fn foo(&self) -> *mut ::std::os::raw::c_int { + *self.foo.as_ref().expect("Expected variable, got error.") + } + pub unsafe fn baz(&self) -> *mut *mut ::std::os::raw::c_int { + *self.baz.as_ref().expect("Expected variable, got error.") + } +} diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_variable_with_allowlist.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_variable_with_allowlist.rs new file mode 100644 index 0000000000..3f29e73814 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_variable_with_allowlist.rs @@ -0,0 +1,30 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub struct TestLib { + __library: ::libloading::Library, + pub foo: Result<*mut ::std::os::raw::c_int, ::libloading::Error>, + pub bar: Result<*mut ::std::os::raw::c_int, ::libloading::Error>, +} +impl TestLib { + pub unsafe fn new

(path: P) -> Result + where + P: AsRef<::std::ffi::OsStr>, + { + let library = ::libloading::Library::new(path)?; + Self::from_library(library) + } + pub unsafe fn from_library(library: L) -> Result + where + L: Into<::libloading::Library>, + { + let __library = library.into(); + let foo = __library.get::<*mut ::std::os::raw::c_int>(b"foo\0").map(|sym| *sym); + let bar = __library.get::<*mut ::std::os::raw::c_int>(b"bar\0").map(|sym| *sym); + Ok(TestLib { __library, foo, bar }) + } + pub unsafe fn foo(&self) -> *mut ::std::os::raw::c_int { + *self.foo.as_ref().expect("Expected variable, got error.") + } + pub unsafe fn bar(&self) -> *mut ::std::os::raw::c_int { + *self.bar.as_ref().expect("Expected variable, got error.") + } +} diff --git a/bindgen-tests/tests/headers/dynamic_loading_variable_required.h b/bindgen-tests/tests/headers/dynamic_loading_variable_required.h new file mode 100644 index 0000000000..8e811bb320 --- /dev/null +++ b/bindgen-tests/tests/headers/dynamic_loading_variable_required.h @@ -0,0 +1,4 @@ +// bindgen-flags: --dynamic-loading TestLib --dynamic-link-require-all + +int foo; +int *baz; \ No newline at end of file diff --git a/bindgen-tests/tests/headers/dynamic_loading_variable_simple.h b/bindgen-tests/tests/headers/dynamic_loading_variable_simple.h new file mode 100644 index 0000000000..5ecad752ed --- /dev/null +++ b/bindgen-tests/tests/headers/dynamic_loading_variable_simple.h @@ -0,0 +1,4 @@ +// bindgen-flags: --dynamic-loading TestLib + +int foo; +int *baz; \ No newline at end of file diff --git a/bindgen-tests/tests/headers/dynamic_loading_variable_with_allowlist.hpp b/bindgen-tests/tests/headers/dynamic_loading_variable_with_allowlist.hpp new file mode 100644 index 0000000000..5e27303063 --- /dev/null +++ b/bindgen-tests/tests/headers/dynamic_loading_variable_with_allowlist.hpp @@ -0,0 +1,5 @@ +// bindgen-flags: --dynamic-loading TestLib --allowlist-var foo --allowlist-var bar + +int foo; +int bar; +int baz; // should not be allowed \ No newline at end of file diff --git a/bindgen/codegen/dyngen.rs b/bindgen/codegen/dyngen.rs index b26c0b1817..4b2749ec0c 100644 --- a/bindgen/codegen/dyngen.rs +++ b/bindgen/codegen/dyngen.rs @@ -1,7 +1,7 @@ use crate::codegen; use crate::ir::context::BindgenContext; use crate::ir::function::ClangAbi; -use proc_macro2::Ident; +use proc_macro2::{Ident, TokenStream}; /// Used to build the output tokens for dynamic bindings. #[derive(Default)] @@ -122,7 +122,7 @@ impl DynamicItems { } #[allow(clippy::too_many_arguments)] - pub(crate) fn push( + pub(crate) fn push_func( &mut self, ident: Ident, abi: ClangAbi, @@ -196,4 +196,47 @@ impl DynamicItems { #ident }); } + + pub fn push_var( + &mut self, + ident: Ident, + ty: TokenStream, + is_required: bool, + ) { + let member = if is_required { + quote! { *mut #ty } + } else { + quote! { Result<*mut #ty, ::libloading::Error> } + }; + + self.struct_members.push(quote! { + pub #ident: #member, + }); + + let deref = if is_required { + quote! { self.#ident } + } else { + quote! { *self.#ident.as_ref().expect("Expected variable, got error.") } + }; + self.struct_implementation.push(quote! { + pub unsafe fn #ident (&self) -> *mut #ty { + #deref + } + }); + + let ident_str = codegen::helpers::ast_ty::cstr_expr(ident.to_string()); + self.constructor_inits.push(if is_required { + quote! { + let #ident = __library.get::<*mut #ty>(#ident_str).map(|sym| *sym)?; + } + } else { + quote! { + let #ident = __library.get::<*mut #ty>(#ident_str).map(|sym| *sym); + } + }); + + self.init_fields.push(quote! { + #ident + }); + } } diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 070d9dec6f..0770275d2e 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -53,7 +53,7 @@ use crate::ir::ty::{Type, TypeKind}; use crate::ir::var::Var; use proc_macro2::{Ident, Span}; -use quote::TokenStreamExt; +use quote::{ToTokens, TokenStreamExt}; use crate::{Entry, HashMap, HashSet}; use std::borrow::Cow; @@ -799,7 +799,17 @@ impl CodeGenerator for Var { } ); - result.push(tokens); + if ctx.options().dynamic_library_name.is_some() { + result.dynamic_items().push_var( + canonical_ident, + self.ty() + .to_rust_ty_or_opaque(ctx, &()) + .into_token_stream(), + ctx.options().dynamic_link_require_all, + ); + } else { + result.push(tokens); + } } } } @@ -4576,7 +4586,7 @@ impl CodeGenerator for Function { let args_identifiers = utils::fnsig_argument_identifiers(ctx, signature); let ret_ty = utils::fnsig_return_ty(ctx, signature); - result.dynamic_items().push( + result.dynamic_items().push_func( ident, abi, signature.is_variadic(), From c03964c0257b03ad4762b57f3ffb96d32d49c0ce Mon Sep 17 00:00:00 2001 From: Lucas Kent Date: Thu, 18 Apr 2024 09:37:50 +1000 Subject: [PATCH 667/942] Remove which dependency --- Cargo.lock | 12 ------------ bindgen-cli/Cargo.toml | 4 +--- bindgen-tests/Cargo.toml | 1 - bindgen/Cargo.toml | 7 +++---- bindgen/lib.rs | 8 -------- 5 files changed, 4 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4fa9dbcf51..dcf6240a27 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -40,7 +40,6 @@ dependencies = [ "rustc-hash", "shlex", "syn 2.0.18", - "which", ] [[package]] @@ -661,17 +660,6 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" -[[package]] -name = "which" -version = "4.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2441c784c52b289a054b7201fc93253e288f094e2f4be9058343127c4226a269" -dependencies = [ - "either", - "libc", - "once_cell", -] - [[package]] name = "winapi" version = "0.3.9" diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index 24066c4c34..40b4b4cb4b 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -28,12 +28,10 @@ log = { version = "0.4", optional = true } shlex = "1" [features] -default = ["logging", "runtime", "which-rustfmt"] +default = ["logging", "runtime"] logging = ["bindgen/logging", "dep:env_logger", "dep:log"] static = ["bindgen/static"] runtime = ["bindgen/runtime"] -# Dynamically discover a `rustfmt` binary using the `which` crate -which-rustfmt = ["bindgen/which-rustfmt"] prettyplease = ["bindgen/prettyplease"] ## The following features are for internal use and they shouldn't be used if diff --git a/bindgen-tests/Cargo.toml b/bindgen-tests/Cargo.toml index 1c06c3f10d..a253b349b9 100644 --- a/bindgen-tests/Cargo.toml +++ b/bindgen-tests/Cargo.toml @@ -19,7 +19,6 @@ owo-colors = "3.5.0" logging = ["bindgen/logging"] static = ["bindgen/static"] runtime = ["bindgen/runtime"] -which-rustfmt = ["bindgen/which-rustfmt"] __testing_only_extra_assertions = ["bindgen/__testing_only_extra_assertions"] __testing_only_libclang_9 = ["bindgen/__testing_only_libclang_9"] diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index 95293daf61..4e3ad81bfc 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -40,15 +40,14 @@ regex = { version = "1.5.3", default-features = false, features = ["std", "unico rustc-hash = "1.0.1" shlex = "1" syn = { version = "2.0", features = ["full", "extra-traits", "visit-mut"] } -which = { version = "4.2.1", optional = true, default-features = false } [features] -default = ["logging", "prettyplease", "runtime", "which-rustfmt"] +default = ["logging", "prettyplease", "runtime"] logging = ["dep:log"] static = ["clang-sys/static"] runtime = ["clang-sys/runtime"] -# Dynamically discover a `rustfmt` binary using the `which` crate -which-rustfmt = ["dep:which"] +# This feature is no longer used for anything and should be removed in bindgen 0.70 +which-rustfmt = [] experimental = ["dep:annotate-snippets"] ## The following features are for internal use and they shouldn't be used if diff --git a/bindgen/lib.rs b/bindgen/lib.rs index c2df8a8a1f..84dc111123 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -983,14 +983,6 @@ impl Bindings { if let Ok(rustfmt) = env::var("RUSTFMT") { return Ok(Cow::Owned(rustfmt.into())); } - #[cfg(feature = "which-rustfmt")] - match which::which("rustfmt") { - Ok(p) => Ok(Cow::Owned(p)), - Err(e) => { - Err(io::Error::new(io::ErrorKind::Other, format!("{}", e))) - } - } - #[cfg(not(feature = "which-rustfmt"))] // No rustfmt binary was specified, so assume that the binary is called // "rustfmt" and that it is in the user's PATH. Ok(Cow::Owned("rustfmt".into())) From aa780dba3e84441662612fa193a2dfc4b670fb93 Mon Sep 17 00:00:00 2001 From: jorolf Date: Wed, 17 Apr 2024 16:30:13 +0200 Subject: [PATCH 668/942] Simplify rust_to_clang_target --- bindgen/lib.rs | 66 +++++++++++++++++++++----------------------------- 1 file changed, 28 insertions(+), 38 deletions(-) diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 84dc111123..8cc69f470a 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -686,45 +686,31 @@ pub(crate) const HOST_TARGET: &str = // Some architecture triplets are different between rust and libclang, see #1211 // and duplicates. fn rust_to_clang_target(rust_target: &str) -> Box { - if rust_target.starts_with("aarch64-apple-") { - let mut clang_target = "arm64-apple-".to_owned(); - clang_target - .push_str(rust_target.strip_prefix("aarch64-apple-").unwrap()); - return clang_target.into(); - } else if rust_target.starts_with("riscv64gc-") { - let mut clang_target = "riscv64-".to_owned(); - clang_target.push_str(rust_target.strip_prefix("riscv64gc-").unwrap()); - return clang_target.into(); - } else if rust_target.starts_with("riscv64imac-") { - let mut clang_target = "riscv64-".to_owned(); - clang_target - .push_str(rust_target.strip_prefix("riscv64imac-").unwrap()); - return clang_target.into(); - } else if rust_target.ends_with("-espidf") { - let mut clang_target = - rust_target.strip_suffix("-espidf").unwrap().to_owned(); - clang_target.push_str("-elf"); - if clang_target.starts_with("riscv32imc-") { - clang_target = "riscv32-".to_owned() + - clang_target.strip_prefix("riscv32imc-").unwrap(); - } - return clang_target.into(); - } else if rust_target.starts_with("riscv32imc-") { - let mut clang_target = "riscv32-".to_owned(); - clang_target.push_str(rust_target.strip_prefix("riscv32imc-").unwrap()); - return clang_target.into(); - } else if rust_target.starts_with("riscv32imac-") { - let mut clang_target = "riscv32-".to_owned(); - clang_target - .push_str(rust_target.strip_prefix("riscv32imac-").unwrap()); - return clang_target.into(); - } else if rust_target.starts_with("riscv32imafc-") { - let mut clang_target = "riscv32-".to_owned(); - clang_target - .push_str(rust_target.strip_prefix("riscv32imafc-").unwrap()); - return clang_target.into(); + const TRIPLE_HYPHENS_MESSAGE: &str = "Target triple should contain hyphens"; + + let mut clang_target = rust_target.to_owned(); + + if clang_target.starts_with("riscv32") { + let idx = clang_target.find('-').expect(TRIPLE_HYPHENS_MESSAGE); + + clang_target.replace_range(..idx, "riscv32"); + } else if clang_target.starts_with("riscv64") { + let idx = clang_target.find('-').expect(TRIPLE_HYPHENS_MESSAGE); + + clang_target.replace_range(..idx, "riscv64"); + } else if clang_target.starts_with("aarch64-apple-") { + let idx = clang_target.find('-').expect(TRIPLE_HYPHENS_MESSAGE); + + clang_target.replace_range(..idx, "arm64"); } - rust_target.into() + + if clang_target.ends_with("-espidf") { + let idx = clang_target.rfind('-').expect(TRIPLE_HYPHENS_MESSAGE); + + clang_target.replace_range((idx + 1).., "elf"); + } + + clang_target.into() } /// Returns the effective target, and whether it was explicitly specified on the @@ -1375,6 +1361,10 @@ fn test_rust_to_clang_target_riscv() { rust_to_clang_target("riscv32imafc-unknown-none-elf").as_ref(), "riscv32-unknown-none-elf" ); + assert_eq!( + rust_to_clang_target("riscv32i-unknown-none-elf").as_ref(), + "riscv32-unknown-none-elf" + ); } #[test] From 79e970d92b3179f975efb0c2950466ab9e37b8f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sat, 27 Apr 2024 21:20:29 +0200 Subject: [PATCH 669/942] ci: Try to fix macOS runners by running on macos-12. --- .github/workflows/bindgen.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 21f96aed27..3fdc75b561 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -122,7 +122,7 @@ jobs: runs-on: ${{matrix.os}} strategy: matrix: - os: [ubuntu-latest, macos-latest] + os: [ubuntu-latest, macos-12] steps: - uses: actions/checkout@v3 @@ -181,7 +181,7 @@ jobs: # FIXME: Ideally should use the latest llvm version, but llvm doesn't # provide releases for x86-64 macOS anymore which is what the runner uses. # - - os: macos-latest + - os: macos-12 llvm_version: "9.0" release_build: 0 no_default_features: 0 From b7ed526aa9c05a58bbd4a7a290d79e7eeb5fe330 Mon Sep 17 00:00:00 2001 From: George Bateman Date: Fri, 26 Apr 2024 18:55:01 +0100 Subject: [PATCH 670/942] Remove lazy_static and lazycell dependencies --- .github/workflows/bindgen.yml | 8 ++--- Cargo.lock | 8 ----- README.md | 4 +-- bindgen-cli/Cargo.toml | 2 +- bindgen-tests/tests/quickchecking/Cargo.toml | 2 +- bindgen/Cargo.toml | 4 +-- bindgen/clang.rs | 15 ++++----- bindgen/ir/item.rs | 32 +++++++++----------- bindgen/lib.rs | 20 +++++------- 9 files changed, 40 insertions(+), 55 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 3fdc75b561..502f914697 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -50,20 +50,20 @@ jobs: with: # MSRV below is documented in Cargo.toml and README.md, please update those if you # change this. - toolchain: 1.60.0 + toolchain: 1.70.0 - name: Test lib with msrv - run: cargo +1.60.0 test --package bindgen + run: cargo +1.70.0 test --package bindgen - name: Install msrv for cli uses: dtolnay/rust-toolchain@master with: # MSRV below is documented in Cargo.toml and README.md, please update those if you # change this. - toolchain: 1.64.0 + toolchain: 1.70.0 - name: Test cli with msrv - run: cargo +1.64.0 build --package bindgen-cli + run: cargo +1.70.0 build --package bindgen-cli minimal: runs-on: ubuntu-latest diff --git a/Cargo.lock b/Cargo.lock index dcf6240a27..5bb3700013 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -30,8 +30,6 @@ dependencies = [ "cexpr", "clang-sys", "itertools", - "lazy_static", - "lazycell", "log", "prettyplease", "proc-macro2", @@ -313,12 +311,6 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -[[package]] -name = "lazycell" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" - [[package]] name = "libc" version = "0.2.139" diff --git a/README.md b/README.md index 620ad0ab94..b35dee3bef 100644 --- a/README.md +++ b/README.md @@ -39,9 +39,9 @@ extern "C" { ## MSRV -The `bindgen` minimum supported Rust version is **1.60.0**. +The `bindgen` minimum supported Rust version is **1.70.0**. -The `bindgen-cli` minimum supported Rust version is **1.64.0**. +The `bindgen-cli` minimum supported Rust version is **1.70.0**. No MSRV bump policy has been established yet, so MSRV may increase in any release. diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index 40b4b4cb4b..4f8e182fd7 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -13,7 +13,7 @@ documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" version = "0.69.4" edition = "2018" -rust-version = "1.64.0" +rust-version = "1.70.0" [[bin]] path = "main.rs" diff --git a/bindgen-tests/tests/quickchecking/Cargo.toml b/bindgen-tests/tests/quickchecking/Cargo.toml index 294961baf9..ba8c54c64f 100644 --- a/bindgen-tests/tests/quickchecking/Cargo.toml +++ b/bindgen-tests/tests/quickchecking/Cargo.toml @@ -3,7 +3,7 @@ name = "quickchecking" description = "Bindgen property tests with quickcheck. Generate random valid C code and pass it to the csmith/predicate.py script" version = "0.0.0" publish = false -rust-version = "1.64" +rust-version = "1.70" edition = "2018" [lib] diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index 4e3ad81bfc..bbd5ecc5d1 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -18,7 +18,7 @@ version = "0.69.4" edition = "2018" build = "build.rs" # If you change this, also update README.md and msrv in .github/workflows/bindgen.yml -rust-version = "1.60.0" +rust-version = "1.70.0" [lib] name = "bindgen" @@ -30,8 +30,6 @@ bitflags = "2.2.1" cexpr = "0.6" clang-sys = { version = "1", features = ["clang_6_0"] } itertools = { version = ">=0.10,<0.13", default-features = false } -lazy_static = "1" -lazycell = "1" log = { version = "0.4", optional = true } prettyplease = { version = "0.2.7", optional = true, features = ["verbatim"] } proc-macro2 = { version = "1", default-features = false } diff --git a/bindgen/clang.rs b/bindgen/clang.rs index 04465b6be9..0422a0c3cd 100644 --- a/bindgen/clang.rs +++ b/bindgen/clang.rs @@ -15,6 +15,7 @@ use std::hash::Hash; use std::hash::Hasher; use std::os::raw::{c_char, c_int, c_longlong, c_uint, c_ulong, c_ulonglong}; use std::{mem, ptr, slice}; +use std::sync::OnceLock; /// Type representing a clang attribute. /// @@ -1528,13 +1529,13 @@ impl Type { pub(crate) fn is_associated_type(&self) -> bool { // This is terrible :( fn hacky_parse_associated_type>(spelling: S) -> bool { - lazy_static! { - static ref ASSOC_TYPE_RE: regex::Regex = regex::Regex::new( - r"typename type\-parameter\-\d+\-\d+::.+" - ) - .unwrap(); - } - ASSOC_TYPE_RE.is_match(spelling.as_ref()) + static ASSOC_TYPE_RE: OnceLock = OnceLock::new(); + ASSOC_TYPE_RE + .get_or_init(|| { + regex::Regex::new(r"typename type\-parameter\-\d+\-\d+::.+") + .unwrap() + }) + .is_match(spelling.as_ref()) } self.kind() == CXType_Unexposed && diff --git a/bindgen/ir/item.rs b/bindgen/ir/item.rs index 4eb9ef8bf4..bb6bae0947 100644 --- a/bindgen/ir/item.rs +++ b/bindgen/ir/item.rs @@ -20,13 +20,12 @@ use super::ty::{Type, TypeKind}; use crate::clang; use crate::parse::{ClangSubItemParser, ParseError, ParseResult}; -use lazycell::LazyCell; - -use std::cell::Cell; +use std::cell::{Cell, OnceCell}; use std::collections::BTreeSet; use std::fmt::Write; use std::io; use std::iter; +use std::sync::OnceLock; /// A trait to get the canonical name from an item. /// @@ -380,7 +379,7 @@ pub(crate) struct Item { /// /// Note that only structs, unions, and enums get a local type ID. In any /// case this is an implementation detail. - local_id: LazyCell, + local_id: OnceCell, /// The next local ID to use for a child or template instantiation. next_child_local_id: Cell, @@ -389,11 +388,11 @@ pub(crate) struct Item { /// /// This is a fairly used operation during codegen so this makes bindgen /// considerably faster in those cases. - canonical_name: LazyCell, + canonical_name: OnceCell, /// The path to use for allowlisting and other name-based checks, as /// returned by `path_for_allowlisting`, lazily constructed. - path_for_allowlisting: LazyCell>, + path_for_allowlisting: OnceCell>, /// A doc comment over the item, if any. comment: Option, @@ -431,10 +430,10 @@ impl Item { debug_assert!(id != parent_id || kind.is_module()); Item { id, - local_id: LazyCell::new(), + local_id: OnceCell::new(), next_child_local_id: Cell::new(1), - canonical_name: LazyCell::new(), - path_for_allowlisting: LazyCell::new(), + canonical_name: OnceCell::new(), + path_for_allowlisting: OnceCell::new(), parent_id, comment, annotations: annotations.unwrap_or_default(), @@ -535,7 +534,7 @@ impl Item { /// below this item's lexical scope, meaning that this can be useful for /// generating relatively stable identifiers within a scope. pub(crate) fn local_id(&self, ctx: &BindgenContext) -> usize { - *self.local_id.borrow_with(|| { + *self.local_id.get_or_init(|| { let parent = ctx.resolve_item(self.parent_id); parent.next_child_local_id() }) @@ -1037,7 +1036,7 @@ impl Item { ctx: &BindgenContext, ) -> &Vec { self.path_for_allowlisting - .borrow_with(|| self.compute_path(ctx, UserMangled::No)) + .get_or_init(|| self.compute_path(ctx, UserMangled::No)) } fn compute_path( @@ -1807,10 +1806,9 @@ impl Item { refd: &clang::Cursor, spelling: &str, ) -> bool { - lazy_static! { - static ref ANON_TYPE_PARAM_RE: regex::Regex = - regex::Regex::new(r"^type\-parameter\-\d+\-\d+$").unwrap(); - } + static ANON_TYPE_PARAM_RE: OnceLock = OnceLock::new(); + let anon_type_param_re = ANON_TYPE_PARAM_RE.get_or_init(|| + regex::Regex::new(r"^type\-parameter\-\d+\-\d+$").unwrap()); if refd.kind() != clang_sys::CXCursor_TemplateTypeParameter { return false; @@ -1819,7 +1817,7 @@ impl Item { let refd_spelling = refd.spelling(); refd_spelling == spelling || // Allow for anonymous template parameters. - (refd_spelling.is_empty() && ANON_TYPE_PARAM_RE.is_match(spelling.as_ref())) + (refd_spelling.is_empty() && anon_type_param_re.is_match(spelling.as_ref())) } let definition = if is_template_with_spelling(&location, &ty_spelling) { @@ -1909,7 +1907,7 @@ impl ItemCanonicalName for Item { "You're not supposed to call this yet" ); self.canonical_name - .borrow_with(|| { + .get_or_init(|| { let in_namespace = ctx.options().enable_cxx_namespaces || ctx.options().disable_name_namespacing; diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 8cc69f470a..5cf8244df2 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -19,8 +19,6 @@ #[macro_use] extern crate bitflags; #[macro_use] -extern crate lazy_static; -#[macro_use] extern crate quote; #[cfg(feature = "logging")] @@ -77,6 +75,7 @@ use std::path::{Path, PathBuf}; use std::process::{Command, Stdio}; use std::rc::Rc; use std::str::FromStr; +use std::sync::{Arc, OnceLock}; // Some convenient typedefs for a fast hash map and hash set. type HashMap = rustc_hash::FxHashMap; @@ -617,17 +616,14 @@ fn ensure_libclang_is_loaded() { // doesn't get dropped prematurely, nor is loaded multiple times // across different threads. - lazy_static! { - static ref LIBCLANG: std::sync::Arc = { - clang_sys::load().expect("Unable to find libclang"); - clang_sys::get_library().expect( - "We just loaded libclang and it had better still be \ - here!", - ) - }; - } + static LIBCLANG: OnceLock> = OnceLock::new(); + let libclang = LIBCLANG.get_or_init(|| { + clang_sys::load().expect("Unable to find libclang"); + clang_sys::get_library() + .expect("We just loaded libclang and it had better still be here!") + }); - clang_sys::set_library(Some(LIBCLANG.clone())); + clang_sys::set_library(Some(libclang.clone())); } #[cfg(not(feature = "runtime"))] From 5aa9c71430ba761d60664988308d47dc3b725df3 Mon Sep 17 00:00:00 2001 From: George Bateman Date: Fri, 26 Apr 2024 19:07:35 +0100 Subject: [PATCH 671/942] Also remove lazy_static from quickchecking --- Cargo.lock | 7 ------- bindgen-tests/tests/quickchecking/Cargo.toml | 1 - bindgen-tests/tests/quickchecking/src/lib.rs | 8 +------- 3 files changed, 1 insertion(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5bb3700013..a8be27905d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -305,12 +305,6 @@ dependencies = [ "either", ] -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - [[package]] name = "libc" version = "0.2.139" @@ -465,7 +459,6 @@ name = "quickchecking" version = "0.0.0" dependencies = [ "clap", - "lazy_static", "quickcheck", "tempfile", ] diff --git a/bindgen-tests/tests/quickchecking/Cargo.toml b/bindgen-tests/tests/quickchecking/Cargo.toml index ba8c54c64f..0fafac97f3 100644 --- a/bindgen-tests/tests/quickchecking/Cargo.toml +++ b/bindgen-tests/tests/quickchecking/Cargo.toml @@ -16,7 +16,6 @@ path = "src/bin.rs" [dependencies] clap = "4" -lazy_static = "1.0" quickcheck = "1.0" tempfile = "3" diff --git a/bindgen-tests/tests/quickchecking/src/lib.rs b/bindgen-tests/tests/quickchecking/src/lib.rs index 38da62f6ee..d23ea792aa 100644 --- a/bindgen-tests/tests/quickchecking/src/lib.rs +++ b/bindgen-tests/tests/quickchecking/src/lib.rs @@ -14,10 +14,7 @@ //! println!("{}", header); //! } //! ``` -//! #![deny(missing_docs)] -#[macro_use] -extern crate lazy_static; use quickcheck::{Gen, QuickCheck, TestResult}; use std::error::Error; @@ -38,10 +35,7 @@ struct Context { } // Initialize global context. -lazy_static! { - static ref CONTEXT: Mutex = - Mutex::new(Context { output_path: None }); -} +static CONTEXT: Mutex = Mutex::new(Context { output_path: None }); // Passes fuzzed header to the `csmith-fuzzing/predicate.py` script, returns // output of the associated command. From 12215f580b2f75e262a53d93defe24afd1a68df5 Mon Sep 17 00:00:00 2001 From: George Bateman Date: Fri, 26 Apr 2024 19:20:41 +0100 Subject: [PATCH 672/942] Resolve new Clippy lints --- bindgen/callbacks.rs | 9 ++------- bindgen/clang.rs | 2 +- bindgen/codegen/mod.rs | 29 +++++++---------------------- bindgen/ir/analysis/has_vtable.rs | 9 ++------- bindgen/ir/analysis/mod.rs | 9 ++------- bindgen/ir/analysis/sizedness.rs | 9 ++------- bindgen/ir/annotations.rs | 9 ++------- bindgen/ir/derive.rs | 9 ++------- bindgen/ir/item.rs | 5 +++-- 9 files changed, 23 insertions(+), 67 deletions(-) diff --git a/bindgen/callbacks.rs b/bindgen/callbacks.rs index c22ba975dd..0f16c4c0bf 100644 --- a/bindgen/callbacks.rs +++ b/bindgen/callbacks.rs @@ -7,21 +7,16 @@ pub use crate::ir::int::IntKind; use std::fmt; /// An enum to allow ignoring parsing of macros. -#[derive(Copy, Clone, Debug, PartialEq, Eq)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Default)] pub enum MacroParsingBehavior { /// Ignore the macro, generating no code for it, or anything that depends on /// it. Ignore, /// The default behavior bindgen would have otherwise. + #[default] Default, } -impl Default for MacroParsingBehavior { - fn default() -> Self { - MacroParsingBehavior::Default - } -} - /// A trait to allow configuring different kinds of types in different /// situations. pub trait ParseCallbacks: fmt::Debug { diff --git a/bindgen/clang.rs b/bindgen/clang.rs index 0422a0c3cd..4d793904c3 100644 --- a/bindgen/clang.rs +++ b/bindgen/clang.rs @@ -14,8 +14,8 @@ use std::fs::OpenOptions; use std::hash::Hash; use std::hash::Hasher; use std::os::raw::{c_char, c_int, c_longlong, c_uint, c_ulong, c_ulonglong}; -use std::{mem, ptr, slice}; use std::sync::OnceLock; +use std::{mem, ptr, slice}; /// Type representing a clang attribute. /// diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 0770275d2e..0b23e0acc3 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -2608,7 +2608,7 @@ impl CodeGenerator for CompInfo { ctx, &canonical_ident, flex_inner_ty, - &*generic_param_names, + &generic_param_names, &impl_generics_labels, )); } @@ -3010,7 +3010,7 @@ impl Method { } /// A helper type that represents different enum variations. -#[derive(Copy, Clone, PartialEq, Eq, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)] pub enum EnumVariation { /// The code for this enum will use a Rust enum. Note that creating this in unsafe code /// (including FFI) with an invalid value will invoke undefined behaviour, whether or not @@ -3027,6 +3027,7 @@ pub enum EnumVariation { is_global: bool, }, /// The code for this enum will use consts + #[default] Consts, /// The code for this enum will use a module containing consts ModuleConsts, @@ -3044,12 +3045,6 @@ impl EnumVariation { } } -impl Default for EnumVariation { - fn default() -> EnumVariation { - EnumVariation::Consts - } -} - impl fmt::Display for EnumVariation { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let s = match self { @@ -3757,11 +3752,12 @@ impl CodeGenerator for Enum { } /// Enum for the default type of macro constants. -#[derive(Copy, Clone, PartialEq, Eq, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)] pub enum MacroTypeVariation { /// Use i32 or i64 Signed, /// Use u32 or u64 + #[default] Unsigned, } @@ -3775,12 +3771,6 @@ impl fmt::Display for MacroTypeVariation { } } -impl Default for MacroTypeVariation { - fn default() -> MacroTypeVariation { - MacroTypeVariation::Unsigned - } -} - impl std::str::FromStr for MacroTypeVariation { type Err = std::io::Error; @@ -3801,9 +3791,10 @@ impl std::str::FromStr for MacroTypeVariation { } /// Enum for how aliases should be translated. -#[derive(Copy, Clone, PartialEq, Eq, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)] pub enum AliasVariation { /// Convert to regular Rust alias + #[default] TypeAlias, /// Create a new type by wrapping the old type in a struct and using #[repr(transparent)] NewType, @@ -3823,12 +3814,6 @@ impl fmt::Display for AliasVariation { } } -impl Default for AliasVariation { - fn default() -> AliasVariation { - AliasVariation::TypeAlias - } -} - impl std::str::FromStr for AliasVariation { type Err = std::io::Error; diff --git a/bindgen/ir/analysis/has_vtable.rs b/bindgen/ir/analysis/has_vtable.rs index 980a551b88..45dea55e6b 100644 --- a/bindgen/ir/analysis/has_vtable.rs +++ b/bindgen/ir/analysis/has_vtable.rs @@ -9,9 +9,10 @@ use std::cmp; use std::ops; /// The result of the `HasVtableAnalysis` for an individual item. -#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Default)] pub(crate) enum HasVtableResult { /// The item does not have a vtable pointer. + #[default] No, /// The item has a vtable and the actual vtable pointer is within this item. @@ -22,12 +23,6 @@ pub(crate) enum HasVtableResult { BaseHasVtable, } -impl Default for HasVtableResult { - fn default() -> Self { - HasVtableResult::No - } -} - impl HasVtableResult { /// Take the least upper bound of `self` and `rhs`. pub(crate) fn join(self, rhs: Self) -> Self { diff --git a/bindgen/ir/analysis/mod.rs b/bindgen/ir/analysis/mod.rs index 8115944e3c..1c05f1216d 100644 --- a/bindgen/ir/analysis/mod.rs +++ b/bindgen/ir/analysis/mod.rs @@ -125,22 +125,17 @@ pub(crate) trait MonotoneFramework: Sized + fmt::Debug { /// Whether an analysis's `constrain` function modified the incremental results /// or not. -#[derive(Debug, Copy, Clone, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Default)] pub(crate) enum ConstrainResult { /// The incremental results were updated, and the fix-point computation /// should continue. Changed, /// The incremental results were not updated. + #[default] Same, } -impl Default for ConstrainResult { - fn default() -> Self { - ConstrainResult::Same - } -} - impl ops::BitOr for ConstrainResult { type Output = Self; diff --git a/bindgen/ir/analysis/sizedness.rs b/bindgen/ir/analysis/sizedness.rs index 995d700794..ea93f2f103 100644 --- a/bindgen/ir/analysis/sizedness.rs +++ b/bindgen/ir/analysis/sizedness.rs @@ -24,13 +24,14 @@ use std::{cmp, ops}; /// /// We initially assume that all types are `ZeroSized` and then update our /// understanding as we learn more about each type. -#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Default)] pub(crate) enum SizednessResult { /// The type is zero-sized. /// /// This means that if it is a C++ type, and is not being used as a base /// member, then we must add an `_address` byte to enforce the /// unique-address-per-distinct-object-instance rule. + #[default] ZeroSized, /// Whether this type is zero-sized or not depends on whether a type @@ -62,12 +63,6 @@ pub(crate) enum SizednessResult { NonZeroSized, } -impl Default for SizednessResult { - fn default() -> Self { - SizednessResult::ZeroSized - } -} - impl SizednessResult { /// Take the least upper bound of `self` and `rhs`. pub(crate) fn join(self, rhs: Self) -> Self { diff --git a/bindgen/ir/annotations.rs b/bindgen/ir/annotations.rs index 9165f3d39a..fc9cc0ffe7 100644 --- a/bindgen/ir/annotations.rs +++ b/bindgen/ir/annotations.rs @@ -9,13 +9,14 @@ use std::str::FromStr; use crate::clang; /// What kind of visibility modifier should be used for a struct or field? -#[derive(Copy, PartialEq, Eq, PartialOrd, Ord, Clone, Debug)] +#[derive(Copy, PartialEq, Eq, PartialOrd, Ord, Clone, Debug, Default)] pub enum FieldVisibilityKind { /// Fields are marked as private, i.e., struct Foo {bar: bool} Private, /// Fields are marked as crate public, i.e., struct Foo {pub(crate) bar: bool} PublicCrate, /// Fields are marked as public, i.e., struct Foo {pub bar: bool} + #[default] Public, } @@ -44,12 +45,6 @@ impl std::fmt::Display for FieldVisibilityKind { } } -impl Default for FieldVisibilityKind { - fn default() -> Self { - FieldVisibilityKind::Public - } -} - /// What kind of accessor should we provide for a field? #[derive(Copy, PartialEq, Eq, Clone, Debug)] pub(crate) enum FieldAccessorKind { diff --git a/bindgen/ir/derive.rs b/bindgen/ir/derive.rs index 3877b42f8f..7491e3efc4 100644 --- a/bindgen/ir/derive.rs +++ b/bindgen/ir/derive.rs @@ -92,9 +92,10 @@ pub(crate) trait CanDeriveOrd { /// /// Initially we assume that we can derive trait for all types and then /// update our understanding as we learn more about each type. -#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Default)] pub enum CanDerive { /// Yes, we can derive automatically. + #[default] Yes, /// The only thing that stops us from automatically deriving is that @@ -107,12 +108,6 @@ pub enum CanDerive { No, } -impl Default for CanDerive { - fn default() -> CanDerive { - CanDerive::Yes - } -} - impl CanDerive { /// Take the least upper bound of `self` and `rhs`. pub(crate) fn join(self, rhs: Self) -> Self { diff --git a/bindgen/ir/item.rs b/bindgen/ir/item.rs index bb6bae0947..8dc7bf84ee 100644 --- a/bindgen/ir/item.rs +++ b/bindgen/ir/item.rs @@ -1807,8 +1807,9 @@ impl Item { spelling: &str, ) -> bool { static ANON_TYPE_PARAM_RE: OnceLock = OnceLock::new(); - let anon_type_param_re = ANON_TYPE_PARAM_RE.get_or_init(|| - regex::Regex::new(r"^type\-parameter\-\d+\-\d+$").unwrap()); + let anon_type_param_re = ANON_TYPE_PARAM_RE.get_or_init(|| { + regex::Regex::new(r"^type\-parameter\-\d+\-\d+$").unwrap() + }); if refd.kind() != clang_sys::CXCursor_TemplateTypeParameter { return false; From 2013b8cb52381fce7b72d8ca7ae93d65f0cf7118 Mon Sep 17 00:00:00 2001 From: George Bateman Date: Fri, 26 Apr 2024 21:23:42 +0100 Subject: [PATCH 673/942] Remove legacy integer methods --- bindgen/clang.rs | 6 +++--- bindgen/ir/var.rs | 20 ++++++++------------ 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/bindgen/clang.rs b/bindgen/clang.rs index 4d793904c3..0dcd5385f6 100644 --- a/bindgen/clang.rs +++ b/bindgen/clang.rs @@ -2356,7 +2356,7 @@ impl EvalResult { if unsafe { clang_EvalResult_isUnsignedInt(self.x) } != 0 { let value = unsafe { clang_EvalResult_getAsUnsigned(self.x) }; - if value > i64::max_value() as c_ulonglong { + if value > i64::MAX as c_ulonglong { return None; } @@ -2364,10 +2364,10 @@ impl EvalResult { } let value = unsafe { clang_EvalResult_getAsLongLong(self.x) }; - if value > i64::max_value() as c_longlong { + if value > i64::MAX as c_longlong { return None; } - if value < i64::min_value() as c_longlong { + if value < i64::MIN as c_longlong { return None; } #[allow(clippy::unnecessary_cast)] diff --git a/bindgen/ir/var.rs b/bindgen/ir/var.rs index a970cf1588..9d46135f74 100644 --- a/bindgen/ir/var.rs +++ b/bindgen/ir/var.rs @@ -129,27 +129,23 @@ fn default_macro_constant_type(ctx: &BindgenContext, value: i64) -> IntKind { ctx.options().default_macro_constant_type == MacroTypeVariation::Signed { - if value < i32::min_value() as i64 || value > i32::max_value() as i64 { + if value < i32::MIN as i64 || value > i32::MAX as i64 { IntKind::I64 } else if !ctx.options().fit_macro_constants || - value < i16::min_value() as i64 || - value > i16::max_value() as i64 + value < i16::MIN as i64 || + value > i16::MAX as i64 { IntKind::I32 - } else if value < i8::min_value() as i64 || - value > i8::max_value() as i64 - { + } else if value < i8::MIN as i64 || value > i8::MAX as i64 { IntKind::I16 } else { IntKind::I8 } - } else if value > u32::max_value() as i64 { + } else if value > u32::MAX as i64 { IntKind::U64 - } else if !ctx.options().fit_macro_constants || - value > u16::max_value() as i64 - { + } else if !ctx.options().fit_macro_constants || value > u16::MAX as i64 { IntKind::U32 - } else if value > u8::max_value() as i64 { + } else if value > u8::MAX as i64 { IntKind::U16 } else { IntKind::U8 @@ -243,7 +239,7 @@ impl ClangSubItemParser for Var { c as u8 } CChar::Raw(c) => { - assert!(c <= ::std::u8::MAX as u64); + assert!(c <= u8::MAX as u64); c as u8 } }; From 600f63895f73c80d6bf7ff3c71b86a068d1663d2 Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Tue, 30 Apr 2024 05:40:58 +0900 Subject: [PATCH 674/942] Use clang_getFileLocation instead of clang_getSpellingLocation Both had the same behavior... until https://github.com/llvm/llvm-project/commit/2e770edd8ce13f48402f1d93e5fb982d8a2ebe64 which fixed getSpellingLocation, but bindgen looks like it actually expects the getFileLocation result. --- bindgen/clang.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindgen/clang.rs b/bindgen/clang.rs index 0dcd5385f6..08d3381557 100644 --- a/bindgen/clang.rs +++ b/bindgen/clang.rs @@ -1610,7 +1610,7 @@ impl SourceLocation { let mut line = 0; let mut col = 0; let mut off = 0; - clang_getSpellingLocation( + clang_getFileLocation( self.x, &mut file, &mut line, &mut col, &mut off, ); (File { x: file }, line as usize, col as usize, off as usize) From e0bab7bfb060177c4cd1aa68da7dd328a55ed32b Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Tue, 30 Apr 2024 11:11:49 -0500 Subject: [PATCH 675/942] Fix `--allowlist-item` --- bindgen/ir/context.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index c4465df9ec..2e608b0714 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -2530,7 +2530,11 @@ If you encounter an error missing from this list, please file an issue or a PR!" ); let name = prefix_path[1..].join("::"); prefix_path.pop().unwrap(); - self.options().allowlisted_vars.matches(name) + self.options().allowlisted_vars.matches(&name) + || self + .options() + .allowlisted_items + .matches(name) }) } } From 877f3e0b9b184a99a3a4cad7ee0c65fd550913bd Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Tue, 30 Apr 2024 11:12:01 -0500 Subject: [PATCH 676/942] Add test --- .../tests/expectations/tests/anon_enum_allowlist_item.rs | 4 ++++ bindgen-tests/tests/headers/anon_enum_allowlist_item.h | 6 ++++++ 2 files changed, 10 insertions(+) create mode 100644 bindgen-tests/tests/expectations/tests/anon_enum_allowlist_item.rs create mode 100644 bindgen-tests/tests/headers/anon_enum_allowlist_item.h diff --git a/bindgen-tests/tests/expectations/tests/anon_enum_allowlist_item.rs b/bindgen-tests/tests/expectations/tests/anon_enum_allowlist_item.rs new file mode 100644 index 0000000000..4d28c3abc7 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/anon_enum_allowlist_item.rs @@ -0,0 +1,4 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub const NODE_FLAG_FOO: _bindgen_ty_1 = 0; +pub const NODE_FLAG_BAR: _bindgen_ty_1 = 1; +pub type _bindgen_ty_1 = ::std::os::raw::c_uint; diff --git a/bindgen-tests/tests/headers/anon_enum_allowlist_item.h b/bindgen-tests/tests/headers/anon_enum_allowlist_item.h new file mode 100644 index 0000000000..23caacc9a1 --- /dev/null +++ b/bindgen-tests/tests/headers/anon_enum_allowlist_item.h @@ -0,0 +1,6 @@ +// bindgen-flags: --allowlist-item "NODE_.*" + +enum { + NODE_FLAG_FOO, + NODE_FLAG_BAR, +}; From ba0ccdb471afa7815c8754f4d43603586aaa9f7a Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Tue, 30 Apr 2024 11:12:07 -0500 Subject: [PATCH 677/942] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 390660f2ad..2dbcb14619 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -209,6 +209,7 @@ ## Fixed - Fix `--formatter=prettyplease` not working in `bindgen-cli` by adding `prettyplease` feature and enabling it by default for `bindgen-cli` (#2789) . +- Fix `--allowlist-item` so anonymous enums are no longer ignored. ## Security # 0.69.4 (2024-02-04) From e847ef1a646016ca007fb4f78e079544dac75ae6 Mon Sep 17 00:00:00 2001 From: John Baublitz Date: Mon, 29 Apr 2024 10:34:43 -0400 Subject: [PATCH 678/942] Switch to single precompiled header in macro fallback It appears that Clang only supports a single precompiled header at a time. Because the macro fallback depends on the ability to provide multiple precompiled headers at once, this commit changes the code to include all provided headers into a single header to precompile and then pass to the TranslationUnit. This should resolve the issue where the macro fallback would not function as intended when multiple headers were provided as input. This commit also resolves an issue where clang args passed to the builder were not forwarded to the precompilation translation unit, resulting in headers not in standard system directories not being found. --- .../macro_fallback_non_system_dir.rs | 1 + .../test_macro_fallback_non_system_dir.rs | 6 + bindgen-tests/tests/headers/issue-753.h | 5 + .../another_header.h | 10 ++ .../macro_fallback_test_headers/one_header.h | 8 ++ bindgen-tests/tests/tests.rs | 55 ++++++++ bindgen/clang.rs | 14 +- bindgen/ir/context.rs | 124 ++++++++++++------ 8 files changed, 174 insertions(+), 49 deletions(-) create mode 100644 bindgen-tests/tests/expectations/tests/libclang-9/macro_fallback_non_system_dir.rs create mode 100644 bindgen-tests/tests/expectations/tests/test_macro_fallback_non_system_dir.rs create mode 100644 bindgen-tests/tests/macro_fallback_test_headers/another_header.h create mode 100644 bindgen-tests/tests/macro_fallback_test_headers/one_header.h diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/macro_fallback_non_system_dir.rs b/bindgen-tests/tests/expectations/tests/libclang-9/macro_fallback_non_system_dir.rs new file mode 100644 index 0000000000..8f5c4ba2da --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/libclang-9/macro_fallback_non_system_dir.rs @@ -0,0 +1 @@ +pub const NEGATIVE: i32 = -1; diff --git a/bindgen-tests/tests/expectations/tests/test_macro_fallback_non_system_dir.rs b/bindgen-tests/tests/expectations/tests/test_macro_fallback_non_system_dir.rs new file mode 100644 index 0000000000..bf9739f3fa --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/test_macro_fallback_non_system_dir.rs @@ -0,0 +1,6 @@ +pub const CONST: u32 = 5; +pub const OTHER_CONST: u32 = 6; +pub const LARGE_CONST: u32 = 1536; +pub const THE_CONST: u32 = 28; +pub const MY_CONST: u32 = 69; +pub const NEGATIVE: i32 = -1; diff --git a/bindgen-tests/tests/headers/issue-753.h b/bindgen-tests/tests/headers/issue-753.h index 94bb8e1c31..3a6c82528a 100644 --- a/bindgen-tests/tests/headers/issue-753.h +++ b/bindgen-tests/tests/headers/issue-753.h @@ -1,7 +1,12 @@ // bindgen-flags: --clang-macro-fallback +#ifndef ISSUE_753_H +#define ISSUE_753_H + #define UINT32_C(c) c ## U #define CONST UINT32_C(5) #define OTHER_CONST UINT32_C(6) #define LARGE_CONST UINT32_C(6 << 8) + +#endif diff --git a/bindgen-tests/tests/macro_fallback_test_headers/another_header.h b/bindgen-tests/tests/macro_fallback_test_headers/another_header.h new file mode 100644 index 0000000000..b0c40eb43f --- /dev/null +++ b/bindgen-tests/tests/macro_fallback_test_headers/another_header.h @@ -0,0 +1,10 @@ +#ifndef ANOTHER_HEADER_H +#define ANOTHER_HEADER_H + +#include + +#define SHOULD_NOT_GENERATE UINT64_C(~0) +#define MY_CONST UINT32_C(69) +#define NEGATIVE ~0 + +#endif diff --git a/bindgen-tests/tests/macro_fallback_test_headers/one_header.h b/bindgen-tests/tests/macro_fallback_test_headers/one_header.h new file mode 100644 index 0000000000..5058814bba --- /dev/null +++ b/bindgen-tests/tests/macro_fallback_test_headers/one_header.h @@ -0,0 +1,8 @@ +#ifndef ONE_HEADER_H +#define ONE_HEADER_H + +#include + +#define THE_CONST UINT32_C(28) + +#endif diff --git a/bindgen-tests/tests/tests.rs b/bindgen-tests/tests/tests.rs index e6c038a064..14988e463f 100644 --- a/bindgen-tests/tests/tests.rs +++ b/bindgen-tests/tests/tests.rs @@ -565,6 +565,61 @@ fn test_mixed_header_and_header_contents() { } } +#[test] +fn test_macro_fallback_non_system_dir() { + let actual = builder() + .header(concat!( + env!("CARGO_MANIFEST_DIR"), + "/tests/macro_fallback_test_headers/one_header.h" + )) + .header(concat!( + env!("CARGO_MANIFEST_DIR"), + "/tests/macro_fallback_test_headers/another_header.h" + )) + .clang_macro_fallback() + .clang_arg(format!("-I{}/tests/headers", env!("CARGO_MANIFEST_DIR"))) + .generate() + .unwrap() + .to_string(); + + let actual = format_code(actual).unwrap(); + + let (expected_filename, expected) = match clang_version().parsed { + Some((9, _)) => { + let expected_filename = concat!( + env!("CARGO_MANIFEST_DIR"), + "/tests/expectations/tests/libclang-9/macro_fallback_non_system_dir.rs", + ); + let expected = include_str!(concat!( + env!("CARGO_MANIFEST_DIR"), + "/tests/expectations/tests/libclang-9/macro_fallback_non_system_dir.rs", + )); + (expected_filename, expected) + } + _ => { + let expected_filename = concat!( + env!("CARGO_MANIFEST_DIR"), + "/tests/expectations/tests/test_macro_fallback_non_system_dir.rs", + ); + let expected = include_str!(concat!( + env!("CARGO_MANIFEST_DIR"), + "/tests/expectations/tests/test_macro_fallback_non_system_dir.rs", + )); + (expected_filename, expected) + } + }; + let expected = format_code(expected).unwrap(); + if expected != actual { + error_diff_mismatch( + &actual, + &expected, + None, + Path::new(expected_filename), + ) + .unwrap(); + } +} + #[test] // Doesn't support executing sh file on Windows. // We may want to implement it in Rust so that we support all systems. diff --git a/bindgen/clang.rs b/bindgen/clang.rs index 08d3381557..26c02acec9 100644 --- a/bindgen/clang.rs +++ b/bindgen/clang.rs @@ -1908,7 +1908,8 @@ impl Drop for TranslationUnit { /// Translation unit used for macro fallback parsing pub(crate) struct FallbackTranslationUnit { file_path: String, - pch_paths: Vec, + header_path: String, + pch_path: String, idx: Box, tu: TranslationUnit, } @@ -1923,7 +1924,8 @@ impl FallbackTranslationUnit { /// Create a new fallback translation unit pub(crate) fn new( file: String, - pch_paths: Vec, + header_path: String, + pch_path: String, c_args: &[Box], ) -> Option { // Create empty file @@ -1944,7 +1946,8 @@ impl FallbackTranslationUnit { )?; Some(FallbackTranslationUnit { file_path: file, - pch_paths, + header_path, + pch_path, tu: f_translation_unit, idx: f_index, }) @@ -1982,9 +1985,8 @@ impl FallbackTranslationUnit { impl Drop for FallbackTranslationUnit { fn drop(&mut self) { let _ = std::fs::remove_file(&self.file_path); - for pch in self.pch_paths.iter() { - let _ = std::fs::remove_file(pch); - } + let _ = std::fs::remove_file(&self.header_path); + let _ = std::fs::remove_file(&self.pch_path); } } diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index 2e608b0714..a1536935b6 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -29,6 +29,8 @@ use quote::ToTokens; use std::borrow::Cow; use std::cell::{Cell, RefCell}; use std::collections::{BTreeSet, HashMap as StdHashMap}; +use std::fs::OpenOptions; +use std::io::Write; use std::mem; use std::path::Path; @@ -2081,55 +2083,91 @@ If you encounter an error missing from this list, please file an issue or a PR!" let index = clang::Index::new(false, false); - let mut c_args = Vec::new(); - let mut pch_paths = Vec::new(); - for input_header in self.options().input_headers.iter() { + let mut header_names_to_compile = Vec::new(); + let mut header_paths = Vec::new(); + let mut header_contents = String::new(); + for input_header in self.options.input_headers.iter() { let path = Path::new(input_header.as_ref()); - let header_name = path - .file_name() - .and_then(|hn| hn.to_str()) - .map(|s| s.to_owned()); - let header_path = path - .parent() - .and_then(|hp| hp.to_str()) - .map(|s| s.to_owned()); - - let (header, pch) = if let (Some(ref hp), Some(hn)) = - (header_path, header_name) - { - let header_path = if hp.is_empty() { "." } else { hp }; - let header = format!("{header_path}/{hn}"); - let pch_path = if let Some(ref path) = - self.options().clang_macro_fallback_build_dir - { - path.as_os_str().to_str()? + if let Some(header_path) = path.parent() { + if header_path == Path::new("") { + header_paths.push("."); } else { - header_path - }; - (header, format!("{pch_path}/{hn}.pch")) + header_paths.push(header_path.as_os_str().to_str()?); + } } else { - return None; - }; - - let mut tu = clang::TranslationUnit::parse( - &index, - &header, - &[ - "-x".to_owned().into_boxed_str(), - "c-header".to_owned().into_boxed_str(), - ], - &[], - clang_sys::CXTranslationUnit_ForSerialization, - )?; - tu.save(&pch).ok()?; - - c_args.push("-include-pch".to_string().into_boxed_str()); - c_args.push(pch.clone().into_boxed_str()); - pch_paths.push(pch); + header_paths.push("."); + } + let header_name = path.file_name()?.to_str()?; + header_names_to_compile + .push(header_name.split(".h").next()?.to_string()); + header_contents += + format!("\n#include <{header_name}>").as_str(); } + let header_to_precompile = format!( + "{}/{}", + match self.options().clang_macro_fallback_build_dir { + Some(ref path) => path.as_os_str().to_str()?, + None => ".", + }, + header_names_to_compile.join("-") + "-precompile.h" + ); + let pch = header_to_precompile.clone() + ".pch"; + + let mut header_to_precompile_file = OpenOptions::new() + .create(true) + .truncate(true) + .write(true) + .open(&header_to_precompile) + .ok()?; + header_to_precompile_file + .write_all(header_contents.as_bytes()) + .ok()?; + let mut c_args = Vec::new(); + c_args.push("-x".to_string().into_boxed_str()); + c_args.push("c-header".to_string().into_boxed_str()); + for header_path in header_paths { + c_args.push(format!("-I{header_path}").into_boxed_str()); + } + c_args.extend( + self.options + .clang_args + .iter() + .filter(|next| { + !self.options.input_headers.contains(next) && + next.as_ref() != "-include" + }) + .cloned(), + ); + let mut tu = clang::TranslationUnit::parse( + &index, + &header_to_precompile, + &c_args, + &[], + clang_sys::CXTranslationUnit_ForSerialization, + )?; + tu.save(&pch).ok()?; + + let mut c_args = vec![ + "-include-pch".to_string().into_boxed_str(), + pch.clone().into_boxed_str(), + ]; + c_args.extend( + self.options + .clang_args + .clone() + .iter() + .filter(|next| { + !self.options.input_headers.contains(next) && + next.as_ref() != "-include" + }) + .cloned(), + ); self.fallback_tu = Some(clang::FallbackTranslationUnit::new( - file, pch_paths, &c_args, + file, + header_to_precompile, + pch, + &c_args, )?); } From 770abd9699a520ebc27b3fe4dd010a577179b494 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 2 May 2024 13:40:12 +0200 Subject: [PATCH 679/942] chore: Update changelog before release. --- CHANGELOG.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2dbcb14619..1671f13af0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -203,13 +203,20 @@ -------------------------------------------------------------------------------- # Unreleased ## Added -## Changed - Add target mappings for riscv64imac and riscv32imafc. +- Add a complex macro fallback API (#2779). +- Add option to use DST structs for flexible arrays (--flexarray-dst, #2772). +- Add option to dynamically load variables (#2812). +## Changed +- Remove which and lazy-static dependencies (#2809, #2817). +- Generate compile-time layout tests (#2787). ## Removed ## Fixed - Fix `--formatter=prettyplease` not working in `bindgen-cli` by adding `prettyplease` feature and enabling it by default for `bindgen-cli` (#2789) . - Fix `--allowlist-item` so anonymous enums are no longer ignored. +- Use clang_getFileLocation instead of clang_getSpellingLocation to fix clang-trunk (#2824) + ## Security # 0.69.4 (2024-02-04) From 9ed74e7575b8f5cfa3402dc1de021861f935008a Mon Sep 17 00:00:00 2001 From: Jingyun Hua Date: Thu, 16 May 2024 01:44:59 +0000 Subject: [PATCH 680/942] Update Cargo.lock --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a8be27905d..8b4b61278e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -307,9 +307,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.139" +version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" [[package]] name = "libloading" From 4b3cd6cb8e42a673ee6cc2296bf26fa667514e19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=96R=C3=96K=20Attila?= Date: Tue, 21 May 2024 11:54:21 +0200 Subject: [PATCH 681/942] Allow itertools 0.13, bump Cargo.lock to it --- Cargo.lock | 4 ++-- bindgen/Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8b4b61278e..ace73d6b07 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -298,9 +298,9 @@ dependencies = [ [[package]] name = "itertools" -version = "0.12.1" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" dependencies = [ "either", ] diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index bbd5ecc5d1..2ea1def69d 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -29,7 +29,7 @@ annotate-snippets = { version = "0.9.1", features = ["color"], optional = true } bitflags = "2.2.1" cexpr = "0.6" clang-sys = { version = "1", features = ["clang_6_0"] } -itertools = { version = ">=0.10,<0.13", default-features = false } +itertools = { version = ">=0.10,<0.14", default-features = false } log = { version = "0.4", optional = true } prettyplease = { version = "0.2.7", optional = true, features = ["verbatim"] } proc-macro2 = { version = "1", default-features = false } From 0e4a5cc1ad64d3bb1a62513dfeab66d74ade3aca Mon Sep 17 00:00:00 2001 From: Ian Chamberlain Date: Sat, 18 May 2024 17:06:50 -0400 Subject: [PATCH 682/942] Support blocklisting __BindgenBitfieldUnit Simply skip emitting it if the list of blocklisted types/items matches its name. Also add a test that verifies blocklisting anonymous types by `_bindgen_ty_*` works as expected. --- .../expectations/tests/anon_enum_blocklist.rs | 4 ++ .../tests/blocklist_bitfield_unit.rs | 68 +++++++++++++++++++ .../tests/headers/anon_enum_blocklist.h | 11 +++ .../tests/headers/blocklist_bitfield_unit.h | 7 ++ bindgen/codegen/helpers.rs | 7 +- bindgen/codegen/mod.rs | 7 ++ 6 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 bindgen-tests/tests/expectations/tests/anon_enum_blocklist.rs create mode 100644 bindgen-tests/tests/expectations/tests/blocklist_bitfield_unit.rs create mode 100644 bindgen-tests/tests/headers/anon_enum_blocklist.h create mode 100644 bindgen-tests/tests/headers/blocklist_bitfield_unit.h diff --git a/bindgen-tests/tests/expectations/tests/anon_enum_blocklist.rs b/bindgen-tests/tests/expectations/tests/anon_enum_blocklist.rs new file mode 100644 index 0000000000..28ab3ad786 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/anon_enum_blocklist.rs @@ -0,0 +1,4 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub const FLAG_Z: _bindgen_ty_2 = 0; +pub const FLAG_W: _bindgen_ty_2 = 1; +pub type _bindgen_ty_2 = ::std::os::raw::c_uint; diff --git a/bindgen-tests/tests/expectations/tests/blocklist_bitfield_unit.rs b/bindgen-tests/tests/expectations/tests/blocklist_bitfield_unit.rs new file mode 100644 index 0000000000..d802e28253 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/blocklist_bitfield_unit.rs @@ -0,0 +1,68 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[path = "./struct_with_bitfields.rs"] +mod bitfields; +use bitfields::*; +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct C { + pub x: ::std::os::raw::c_uchar, + pub _bitfield_align_1: [u8; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, + pub baz: ::std::os::raw::c_uint, +} +const _: () = { + ["Size of C"][::std::mem::size_of::() - 8usize]; + ["Alignment of C"][::std::mem::align_of::() - 4usize]; + ["Offset of field: C::x"][::std::mem::offset_of!(C, x) - 0usize]; + ["Offset of field: C::baz"][::std::mem::offset_of!(C, baz) - 4usize]; +}; +impl C { + #[inline] + pub fn b1(&self) -> ::std::os::raw::c_uint { + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u32) } + } + #[inline] + pub fn set_b1(&mut self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + self._bitfield_1.set(0usize, 1u8, val as u64) + } + } + #[inline] + pub fn b2(&self) -> ::std::os::raw::c_uint { + unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u32) } + } + #[inline] + pub fn set_b2(&mut self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + self._bitfield_1.set(1usize, 1u8, val as u64) + } + } + #[inline] + pub fn new_bitfield_1( + b1: ::std::os::raw::c_uint, + b2: ::std::os::raw::c_uint, + ) -> __BindgenBitfieldUnit<[u8; 1usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 1u8, + { + let b1: u32 = unsafe { ::std::mem::transmute(b1) }; + b1 as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 1usize, + 1u8, + { + let b2: u32 = unsafe { ::std::mem::transmute(b2) }; + b2 as u64 + }, + ); + __bindgen_bitfield_unit + } +} diff --git a/bindgen-tests/tests/headers/anon_enum_blocklist.h b/bindgen-tests/tests/headers/anon_enum_blocklist.h new file mode 100644 index 0000000000..61aa6e680c --- /dev/null +++ b/bindgen-tests/tests/headers/anon_enum_blocklist.h @@ -0,0 +1,11 @@ +// bindgen-flags: --blocklist-type "_bindgen_ty_1" + +enum { + FLAG_X, + FLAG_Y, +}; + +enum { + FLAG_Z, + FLAG_W, +}; diff --git a/bindgen-tests/tests/headers/blocklist_bitfield_unit.h b/bindgen-tests/tests/headers/blocklist_bitfield_unit.h new file mode 100644 index 0000000000..5f7d94ced9 --- /dev/null +++ b/bindgen-tests/tests/headers/blocklist_bitfield_unit.h @@ -0,0 +1,7 @@ +// bindgen-flags: --blocklist-type "__BindgenBitfieldUnit" --raw-line '#[path = "./struct_with_bitfields.rs"] mod bitfields;' --raw-line 'use bitfields::*;' +struct C { + unsigned char x; + unsigned b1 : 1; + unsigned b2 : 1; + unsigned baz; +}; diff --git a/bindgen/codegen/helpers.rs b/bindgen/codegen/helpers.rs index fa1dde8786..257ea5965a 100644 --- a/bindgen/codegen/helpers.rs +++ b/bindgen/codegen/helpers.rs @@ -1,5 +1,7 @@ //! Helpers for code generation that don't need macro expansion. +use proc_macro2::{Ident, Span}; + use crate::ir::context::BindgenContext; use crate::ir::layout::Layout; @@ -109,10 +111,13 @@ pub(crate) fn integer_type( Layout::known_type_for_size(ctx, layout.size) } +pub(crate) const BITFIELD_UNIT: &str = "__BindgenBitfieldUnit"; + /// Generates a bitfield allocation unit type for a type with the given `Layout`. pub(crate) fn bitfield_unit(ctx: &BindgenContext, layout: Layout) -> syn::Type { let size = layout.size; - let ty = syn::parse_quote! { __BindgenBitfieldUnit<[u8; #size]> }; + let bitfield_unit_name = Ident::new(BITFIELD_UNIT, Span::call_site()); + let ty = syn::parse_quote! { #bitfield_unit_name<[u8; #size]> }; if ctx.options().enable_cxx_namespaces { return syn::parse_quote! { root::#ty }; diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 0b23e0acc3..7c1c55abb5 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -5017,6 +5017,7 @@ pub(crate) fn codegen( } pub(crate) mod utils { + use super::helpers::BITFIELD_UNIT; use super::serialize::CSerialize; use super::{error, CodegenError, CodegenResult, ToRustTyOrOpaque}; use crate::ir::context::BindgenContext; @@ -5153,6 +5154,12 @@ pub(crate) mod utils { ctx: &BindgenContext, result: &mut Vec, ) { + if ctx.options().blocklisted_items.matches(BITFIELD_UNIT) || + ctx.options().blocklisted_types.matches(BITFIELD_UNIT) + { + return; + } + let bitfield_unit_src = include_str!("./bitfield_unit.rs"); let bitfield_unit_src = if ctx.options().rust_features().min_const_fn { Cow::Borrowed(bitfield_unit_src) From 9452ba1080b87f3d24880135eb4631dd15e9268e Mon Sep 17 00:00:00 2001 From: Ian Chamberlain Date: Sat, 18 May 2024 17:55:03 -0400 Subject: [PATCH 683/942] Mention blocklisting bitfield types in book --- book/src/using-bitfields.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/book/src/using-bitfields.md b/book/src/using-bitfields.md index 0ee9f0329c..8929f73705 100644 --- a/book/src/using-bitfields.md +++ b/book/src/using-bitfields.md @@ -8,6 +8,11 @@ As Rust does not support bitfields, Bindgen generates a struct for each with the * For each contiguous block of bitfields, Bindgen emits an opaque physical field that contains one or more logical bitfields * A static constructor ```new_bitfield_{1, 2, ...}``` with a parameter for each bitfield contained within the opaque physical field. +To keep bindgen from generating the bitfield unit struct, it can be blocklisted like any +other type, i.e. `--blocklist-type "__BindgenBitfieldUnit"`. This may be useful if +you want to define a custom implementation, or your generated bindings import a +pre-existing definition for the bitfield unit type. + ## Bitfield examples For this discussion, we will use the following C type definitions and functions. From cf9b02f57cc6138f60b4d35a5ff109b433dd8238 Mon Sep 17 00:00:00 2001 From: Christian Meusel Date: Sun, 26 May 2024 15:38:41 +0200 Subject: [PATCH 684/942] Print CLI errors to stderr instead of stdout This prevents them of sneaking into output files instead of being displayed when manually generating bindings by redirecting stdout. --- bindgen-cli/main.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bindgen-cli/main.rs b/bindgen-cli/main.rs index a3a011fcc7..caa47c6268 100644 --- a/bindgen-cli/main.rs +++ b/bindgen-cli/main.rs @@ -38,7 +38,7 @@ pub fn main() { if verbose { print_verbose_err() } - println!("{}", info); + eprintln!("{}", info); })); let bindings = @@ -49,21 +49,21 @@ pub fn main() { bindings.write(output).expect("Unable to write output"); } Err(error) => { - println!("{}", error); + eprintln!("{}", error); std::process::exit(1); } }; } fn print_verbose_err() { - println!("Bindgen unexpectedly panicked"); - println!( + eprintln!("Bindgen unexpectedly panicked"); + eprintln!( "This may be caused by one of the known-unsupported \ things (https://rust-lang.github.io/rust-bindgen/cpp.html), \ please modify the bindgen flags to work around it as \ described in https://rust-lang.github.io/rust-bindgen/cpp.html" ); - println!( + eprintln!( "Otherwise, please file an issue at \ https://github.com/rust-lang/rust-bindgen/issues/new" ); From a90bd840a53c471d3c0ee494dc09571b9cdc371f Mon Sep 17 00:00:00 2001 From: Ricardo Delfin Date: Mon, 10 Jun 2024 10:19:32 +0000 Subject: [PATCH 685/942] Added non-exhaustive enums to the CLI --- bindgen-cli/options.rs | 12 ++++++++++-- bindgen/lib.rs | 17 +++++++++-------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/bindgen-cli/options.rs b/bindgen-cli/options.rs index 5edc8c95e5..bf49644245 100644 --- a/bindgen-cli/options.rs +++ b/bindgen-cli/options.rs @@ -114,6 +114,9 @@ struct BindgenCommand { /// Mark any enum whose name matches REGEX as a Rust enum. #[arg(long, value_name = "REGEX")] rustified_enum: Vec, + /// Mark any enum whose name matches REGEX as a non-exhaustive Rust enum. + #[arg(long, value_name = "REGEX")] + rustified_non_exhaustive_enum: Vec, /// Mark any enum whose name matches REGEX as a series of constants. #[arg(long, value_name = "REGEX")] constified_enum: Vec, @@ -469,6 +472,7 @@ where newtype_enum, newtype_global_enum, rustified_enum, + rustified_non_exhaustive_enum, constified_enum, constified_enum_module, default_macro_constant_type, @@ -635,6 +639,10 @@ where builder = builder.rustified_enum(regex); } + for regex in rustified_non_exhaustive_enum { + builder = builder.rustified_non_exhaustive_enum(regex); + } + for regex in constified_enum { builder = builder.constified_enum(regex); } @@ -1081,8 +1089,8 @@ where &self, info: &bindgen::callbacks::DeriveInfo<'_>, ) -> Vec { - if self.kind.map(|kind| kind == info.kind).unwrap_or(true) && - self.regex_set.matches(info.name) + if self.kind.map(|kind| kind == info.kind).unwrap_or(true) + && self.regex_set.matches(info.name) { return self.derives.clone(); } diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 5cf8244df2..1dedd0f40b 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -87,10 +87,10 @@ pub const DEFAULT_ANON_FIELDS_PREFIX: &str = "__bindgen_anon_"; const DEFAULT_NON_EXTERN_FNS_SUFFIX: &str = "__extern"; fn file_is_cpp(name_file: &str) -> bool { - name_file.ends_with(".hpp") || - name_file.ends_with(".hxx") || - name_file.ends_with(".hh") || - name_file.ends_with(".h++") + name_file.ends_with(".hpp") + || name_file.ends_with(".hxx") + || name_file.ends_with(".hh") + || name_file.ends_with(".h++") } fn args_are_cpp(clang_args: &[Box]) -> bool { @@ -237,6 +237,7 @@ impl std::fmt::Display for Formatter { /// 2. [`bitfield_enum()`](#method.bitfield_enum) /// 3. [`newtype_enum()`](#method.newtype_enum) /// 4. [`rustified_enum()`](#method.rustified_enum) +/// 4. [`rustified_non_exhaustive_enum()`](#method.rustified_non_exhaustive_enum) /// /// For each C enum, bindgen tries to match the pattern in the following order: /// @@ -798,8 +799,8 @@ impl Bindings { return false; } - if arg.starts_with("-I") || - arg.starts_with("--include-directory=") + if arg.starts_with("-I") + || arg.starts_with("--include-directory=") { return false; } @@ -826,8 +827,8 @@ impl Bindings { debug!("Found clang: {:?}", clang); // Whether we are working with C or C++ inputs. - let is_cpp = args_are_cpp(&options.clang_args) || - options.input_headers.iter().any(|h| file_is_cpp(h)); + let is_cpp = args_are_cpp(&options.clang_args) + || options.input_headers.iter().any(|h| file_is_cpp(h)); let search_paths = if is_cpp { clang.cpp_search_paths From 1a98a2258de4962062a4d1761f0429e78ddda4f9 Mon Sep 17 00:00:00 2001 From: Ricardo Delfin Date: Mon, 10 Jun 2024 12:16:41 +0000 Subject: [PATCH 686/942] Revert formatting changes --- bindgen-cli/options.rs | 4 ++-- bindgen/lib.rs | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/bindgen-cli/options.rs b/bindgen-cli/options.rs index bf49644245..a8780b79ca 100644 --- a/bindgen-cli/options.rs +++ b/bindgen-cli/options.rs @@ -1089,8 +1089,8 @@ where &self, info: &bindgen::callbacks::DeriveInfo<'_>, ) -> Vec { - if self.kind.map(|kind| kind == info.kind).unwrap_or(true) - && self.regex_set.matches(info.name) + if self.kind.map(|kind| kind == info.kind).unwrap_or(true) && + self.regex_set.matches(info.name) { return self.derives.clone(); } diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 1dedd0f40b..a1961a5110 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -87,10 +87,10 @@ pub const DEFAULT_ANON_FIELDS_PREFIX: &str = "__bindgen_anon_"; const DEFAULT_NON_EXTERN_FNS_SUFFIX: &str = "__extern"; fn file_is_cpp(name_file: &str) -> bool { - name_file.ends_with(".hpp") - || name_file.ends_with(".hxx") - || name_file.ends_with(".hh") - || name_file.ends_with(".h++") + name_file.ends_with(".hpp") || + name_file.ends_with(".hxx") || + name_file.ends_with(".hh") || + name_file.ends_with(".h++") } fn args_are_cpp(clang_args: &[Box]) -> bool { @@ -799,8 +799,8 @@ impl Bindings { return false; } - if arg.starts_with("-I") - || arg.starts_with("--include-directory=") + if arg.starts_with("-I") || + arg.starts_with("--include-directory=") { return false; } @@ -827,8 +827,8 @@ impl Bindings { debug!("Found clang: {:?}", clang); // Whether we are working with C or C++ inputs. - let is_cpp = args_are_cpp(&options.clang_args) - || options.input_headers.iter().any(|h| file_is_cpp(h)); + let is_cpp = args_are_cpp(&options.clang_args) || + options.input_headers.iter().any(|h| file_is_cpp(h)); let search_paths = if is_cpp { clang.cpp_search_paths From 9d5991bca5a41b11cf24b7ad31c885fdde428336 Mon Sep 17 00:00:00 2001 From: Ricardo Delfin Date: Sat, 22 Jun 2024 13:37:24 +0100 Subject: [PATCH 687/942] Addressed comments --- CHANGELOG.md | 1 + bindgen/lib.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1671f13af0..613292439a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -207,6 +207,7 @@ - Add a complex macro fallback API (#2779). - Add option to use DST structs for flexible arrays (--flexarray-dst, #2772). - Add option to dynamically load variables (#2812). +- Add option in CLI to use rustified non-exhaustive enums (--rustified-non-exhaustive-enum, #2847). ## Changed - Remove which and lazy-static dependencies (#2809, #2817). - Generate compile-time layout tests (#2787). diff --git a/bindgen/lib.rs b/bindgen/lib.rs index a1961a5110..3bf0bc3c1d 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -237,7 +237,7 @@ impl std::fmt::Display for Formatter { /// 2. [`bitfield_enum()`](#method.bitfield_enum) /// 3. [`newtype_enum()`](#method.newtype_enum) /// 4. [`rustified_enum()`](#method.rustified_enum) -/// 4. [`rustified_non_exhaustive_enum()`](#method.rustified_non_exhaustive_enum) +/// 5. [`rustified_non_exhaustive_enum()`](#method.rustified_non_exhaustive_enum) /// /// For each C enum, bindgen tries to match the pattern in the following order: /// From 35f09bdd4bfad17336a0143e0bd8d1b1fa799178 Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Sun, 30 Jun 2024 12:14:52 +0700 Subject: [PATCH 688/942] ci: Consistently use `actions/checkout@v4` --- .github/workflows/bindgen.yml | 18 +++++++++--------- .github/workflows/deploy-book.yml | 2 +- .github/workflows/publish.yml | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 502f914697..899d771342 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -16,7 +16,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install stable uses: actions-rs/toolchain@v1 @@ -43,7 +43,7 @@ jobs: msrv: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install msrv for lib uses: dtolnay/rust-toolchain@master @@ -70,7 +70,7 @@ jobs: env: RUSTFLAGS: -D warnings steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install stable uses: actions-rs/toolchain@v1 @@ -87,7 +87,7 @@ jobs: env: RUSTDOCFLAGS: -D warnings steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install stable uses: actions-rs/toolchain@v1 @@ -105,7 +105,7 @@ jobs: quickchecking: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install stable uses: actions-rs/toolchain@v1 @@ -124,7 +124,7 @@ jobs: matrix: os: [ubuntu-latest, macos-12] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install stable uses: actions-rs/toolchain@v1 @@ -187,7 +187,7 @@ jobs: no_default_features: 0 feature_extra_asserts: 0 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install multiarch packages if: matrix.target.debian @@ -234,7 +234,7 @@ jobs: env: RUSTFLAGS: -D warnings steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install nightly uses: actions-rs/toolchain@v1 @@ -249,7 +249,7 @@ jobs: test-book: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 # NOTE(emilio): Change deploy-book as well if you change this. - name: Test book diff --git a/.github/workflows/deploy-book.yml b/.github/workflows/deploy-book.yml index 9bb1e1b852..5eaeed5839 100644 --- a/.github/workflows/deploy-book.yml +++ b/.github/workflows/deploy-book.yml @@ -9,7 +9,7 @@ jobs: deploy-book: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: persist-credentials: false diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 1fbc15049d..352199d7d7 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -13,7 +13,7 @@ jobs: if: ${{ github.event.workflow_run.conclusion == 'success' }} steps: - name: Checkout sources - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install stable toolchain uses: dtolnay/rust-toolchain@master with: From b581fc2a32e6329db92a3283ab05c077fe62abab Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Sun, 30 Jun 2024 12:20:22 +0700 Subject: [PATCH 689/942] CONTRIBUTING.md: Update toc This fixes a broken link and adds 2 missing entries. --- CONTRIBUTING.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index af069be2da..0ffc58565e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -37,7 +37,9 @@ and introduce yourself. - [Updating the changelog](#updating-the-changelog) - [Merge to `main`](#merge-to-main) - [Tag and publish](#tag-and-publish) - - [Create a new release on GitHub](create-a-new-relese-on-github) + - [Create a new release on Github](#create-a-new-release-on-github) + - [What to do if a Github release fails](#what-to-do-if-a-github-release-fails) + - [Create a new crates.io release](#create-a-new-cratesio-release) From 774046436ae8ff7118ff9cbffd72b76641342110 Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Sun, 30 Jun 2024 12:24:33 +0700 Subject: [PATCH 690/942] Fix some typos. --- CHANGELOG.md | 4 ++-- bindgen-cli/options.rs | 2 +- bindgen/clang.rs | 2 +- bindgen/ir/comp.rs | 4 ++-- bindgen/ir/var.rs | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 613292439a..a48136ca52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -448,7 +448,7 @@ This version was skipped due to some problems on the release workflow. * The `ParseCallbacks::generated_name_override` method now receives `ItemInfo<'_>` as argument instead of a `&str`. * Updated the `clang-sys` crate version to 1.4.0 to support clang 15. - * The return type is now ommited in signatures of functions returning `void`. + * The return type is now omitted in signatures of functions returning `void`. * Updated the `clap` dependency for `bindgen-cli` to 4. * Rewrote the `bindgen-cli` argument parser which could introduce unexpected behavior changes. @@ -1485,7 +1485,7 @@ Released 2017/10/27 We <3 folks who [help us find and fix issues via fuzzing][fuzzing]! *hint hint* -* Added experimental support for the `thiscall` ABI when targetting Rust +* Added experimental support for the `thiscall` ABI when targeting Rust nightly. [#1065][] ## Changed diff --git a/bindgen-cli/options.rs b/bindgen-cli/options.rs index a8780b79ca..cd5e9bb127 100644 --- a/bindgen-cli/options.rs +++ b/bindgen-cli/options.rs @@ -376,7 +376,7 @@ struct BindgenCommand { /// Prefix the name of exported symbols. #[arg(long)] prefix_link_name: Option, - /// Makes generated bindings `pub` only for items if the items are publically accessible in C++. + /// Makes generated bindings `pub` only for items if the items are publicly accessible in C++. #[arg(long)] respect_cxx_access_specs: bool, /// Always translate enum integer types to native Rust integer types. diff --git a/bindgen/clang.rs b/bindgen/clang.rs index 26c02acec9..47c7b1704a 100644 --- a/bindgen/clang.rs +++ b/bindgen/clang.rs @@ -876,7 +876,7 @@ impl Cursor { unsafe { clang_getCXXAccessSpecifier(self.x) } } - /// Is the cursor's referent publically accessible in C++? + /// Is the cursor's referent publicly accessible in C++? /// /// Returns true if self.access_specifier() is `CX_CXXPublic` or /// `CX_CXXInvalidAccessSpecifier`. diff --git a/bindgen/ir/comp.rs b/bindgen/ir/comp.rs index 13a8184fc5..036e7e5c8f 100644 --- a/bindgen/ir/comp.rs +++ b/bindgen/ir/comp.rs @@ -948,7 +948,7 @@ pub(crate) struct Base { pub(crate) kind: BaseKind, /// Name of the field in which this base should be stored. pub(crate) field_name: String, - /// Whether this base is inherited from publically. + /// Whether this base is inherited from publicly. pub(crate) is_pub: bool, } @@ -978,7 +978,7 @@ impl Base { true } - /// Whether this base is inherited from publically. + /// Whether this base is inherited from publicly. pub(crate) fn is_public(&self) -> bool { self.is_pub } diff --git a/bindgen/ir/var.rs b/bindgen/ir/var.rs index 9d46135f74..40a061e16c 100644 --- a/bindgen/ir/var.rs +++ b/bindgen/ir/var.rs @@ -489,7 +489,7 @@ fn duplicated_macro_diagnostic( #[cfg(feature = "experimental")] // FIXME (pvdrz & amanjeev): This diagnostic message shows way too often to be actually // useful. We have to change the logic where this function is called to be able to emit this - // message only when the duplication is an actuall issue. + // message only when the duplication is an actual issue. // // If I understood correctly, `bindgen` ignores all `#undef` directives. Meaning that this: // ```c From d84eb1c464b33f6d31229a2d19b022a01b37ffb8 Mon Sep 17 00:00:00 2001 From: Gabi Ganam Date: Tue, 25 Jun 2024 10:09:01 +0300 Subject: [PATCH 691/942] Fix generated constants: f64::INFINITY & f64::NEG_ INFINITY https://github.com/rust-lang/rust-bindgen/issues/2853 --- bindgen/codegen/helpers.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bindgen/codegen/helpers.rs b/bindgen/codegen/helpers.rs index 257ea5965a..f05b2eb1f9 100644 --- a/bindgen/codegen/helpers.rs +++ b/bindgen/codegen/helpers.rs @@ -322,11 +322,11 @@ pub(crate) mod ast_ty { if f.is_infinite() { return Ok(if f.is_sign_positive() { quote! { - ::#prefix::f64::INFINITY + f64::INFINITY } } else { quote! { - ::#prefix::f64::NEG_INFINITY + f64::NEG_INFINITY } }); } From 22a1b72ea50242e67ccb0e8dbba60440a33671fd Mon Sep 17 00:00:00 2001 From: Gabi Ganam Date: Tue, 25 Jun 2024 07:19:18 +0000 Subject: [PATCH 692/942] Fix generated constants: `f64::INFINITY`, `f64::NEG_ INFINITY`, `f64::NAN` https://github.com/rust-lang/rust-bindgen/issues/2853 --- bindgen-tests/tests/expectations/tests/infinite-macro.rs | 4 ++-- bindgen/codegen/helpers.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bindgen-tests/tests/expectations/tests/infinite-macro.rs b/bindgen-tests/tests/expectations/tests/infinite-macro.rs index 455a7ae5ed..f19879fb17 100644 --- a/bindgen-tests/tests/expectations/tests/infinite-macro.rs +++ b/bindgen-tests/tests/expectations/tests/infinite-macro.rs @@ -1,3 +1,3 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -pub const INFINITY: f64 = ::std::f64::INFINITY; -pub const NAN: f64 = ::std::f64::NAN; +pub const INFINITY: f64 = f64::INFINITY; +pub const NAN: f64 = f64::NAN; diff --git a/bindgen/codegen/helpers.rs b/bindgen/codegen/helpers.rs index f05b2eb1f9..918a85999e 100644 --- a/bindgen/codegen/helpers.rs +++ b/bindgen/codegen/helpers.rs @@ -315,7 +315,7 @@ pub(crate) mod ast_ty { if f.is_nan() { return Ok(quote! { - ::#prefix::f64::NAN + f64::NAN }); } From a2360d19b11a93b064413a302a45cf9817af4f50 Mon Sep 17 00:00:00 2001 From: Gabi Ganam Date: Tue, 25 Jun 2024 07:21:33 +0000 Subject: [PATCH 693/942] Fix generated constants: `f64::INFINITY`, `f64::NEG_ INFINITY`, `f64::NAN` https://github.com/rust-lang/rust-bindgen/issues/2853 --- bindgen/codegen/helpers.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/bindgen/codegen/helpers.rs b/bindgen/codegen/helpers.rs index 918a85999e..115ac2618c 100644 --- a/bindgen/codegen/helpers.rs +++ b/bindgen/codegen/helpers.rs @@ -311,8 +311,6 @@ pub(crate) mod ast_ty { return Ok(quote!(#val)); } - let prefix = ctx.trait_prefix(); - if f.is_nan() { return Ok(quote! { f64::NAN From a2c147b05090d07b84ad7ded49aa5294aba0e33b Mon Sep 17 00:00:00 2001 From: Gabi Ganam Date: Tue, 25 Jun 2024 07:23:20 +0000 Subject: [PATCH 694/942] Fix generated constants: `f64::INFINITY`, `f64::NEG_ INFINITY`, `f64::NAN` https://github.com/rust-lang/rust-bindgen/issues/2853 --- bindgen/codegen/helpers.rs | 1 - bindgen/codegen/mod.rs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/bindgen/codegen/helpers.rs b/bindgen/codegen/helpers.rs index 115ac2618c..5d9d540803 100644 --- a/bindgen/codegen/helpers.rs +++ b/bindgen/codegen/helpers.rs @@ -302,7 +302,6 @@ pub(crate) mod ast_ty { } pub(crate) fn float_expr( - ctx: &BindgenContext, f: f64, ) -> Result { if f.is_finite() { diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 7c1c55abb5..db8436bd32 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -756,7 +756,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 ; From 590788c51d6efd8ceb2acf42ed1f6f688303dde4 Mon Sep 17 00:00:00 2001 From: Gabi Ganam Date: Tue, 25 Jun 2024 07:24:50 +0000 Subject: [PATCH 695/942] Fix generated constants: `f64::INFINITY`, `f64::NEG_ INFINITY`, `f64::NAN` https://github.com/rust-lang/rust-bindgen/issues/2853 --- bindgen/codegen/helpers.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bindgen/codegen/helpers.rs b/bindgen/codegen/helpers.rs index 5d9d540803..8a02e19bdd 100644 --- a/bindgen/codegen/helpers.rs +++ b/bindgen/codegen/helpers.rs @@ -301,9 +301,7 @@ pub(crate) mod ast_ty { } } - pub(crate) fn float_expr( - f: f64, - ) -> Result { + pub(crate) fn float_expr(f: f64) -> Result { if f.is_finite() { let val = proc_macro2::Literal::f64_unsuffixed(f); From 9ed4b68a889965328a42358fd866a473d6ccd776 Mon Sep 17 00:00:00 2001 From: Gabi Ganam Date: Wed, 26 Jun 2024 06:34:39 +0000 Subject: [PATCH 696/942] Fix generated constants: `f64::INFINITY`, `f64::NEG_ INFINITY`, `f64::NAN` https://github.com/rust-lang/rust-bindgen/issues/2853 --- bindgen/codegen/helpers.rs | 25 +++++++++++++++++++++---- bindgen/codegen/mod.rs | 2 +- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/bindgen/codegen/helpers.rs b/bindgen/codegen/helpers.rs index 8a02e19bdd..41d1800623 100644 --- a/bindgen/codegen/helpers.rs +++ b/bindgen/codegen/helpers.rs @@ -301,27 +301,44 @@ pub(crate) mod ast_ty { } } - pub(crate) fn float_expr(f: f64) -> Result { + pub(crate) fn float_expr( + ctx: &BindgenContext, + f: f64, + ) -> Result { if f.is_finite() { let val = proc_macro2::Literal::f64_unsuffixed(f); return Ok(quote!(#val)); } + let prefix = ctx.trait_prefix(); + if f.is_nan() { return Ok(quote! { - f64::NAN + if rust_target >= RustTarget::Stable_1_43 { + f64::NAN + } else { + ::#prefix::f64::NAN + } }); } if f.is_infinite() { return Ok(if f.is_sign_positive() { quote! { - f64::INFINITY + if rust_target >= RustTarget::Stable_1_43 { + f64::INFINITY + } else { + ::#prefix::f64::INFINITY + } } } else { quote! { - f64::NEG_INFINITY + if rust_target >= RustTarget::Stable_1_43 { + f64::NEG_INFINITY + } else { + ::#prefix::f64::NEG_INFINITY + } } }); } diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index db8436bd32..7c1c55abb5 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -756,7 +756,7 @@ impl CodeGenerator for Var { } } VarType::Float(f) => { - if let Ok(expr) = helpers::ast_ty::float_expr(f) { + if let Ok(expr) = helpers::ast_ty::float_expr(ctx, f) { result.push(quote! { #(#attrs)* pub const #canonical_ident : #ty = #expr ; From 9482941de0f6f0ded56ce82f8091e32c49e9f6a2 Mon Sep 17 00:00:00 2001 From: Gabi Ganam Date: Wed, 26 Jun 2024 06:53:11 +0000 Subject: [PATCH 697/942] Fix generated constants: `f64::INFINITY`, `f64::NEG_ INFINITY`, `f64::NAN` https://github.com/rust-lang/rust-bindgen/issues/2853 --- bindgen/codegen/helpers.rs | 36 +++++++++++++++++++++++------------- bindgen/features.rs | 3 ++- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/bindgen/codegen/helpers.rs b/bindgen/codegen/helpers.rs index 41d1800623..bfe1e3d814 100644 --- a/bindgen/codegen/helpers.rs +++ b/bindgen/codegen/helpers.rs @@ -131,6 +131,7 @@ 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; @@ -312,35 +313,44 @@ pub(crate) mod ast_ty { } let prefix = ctx.trait_prefix(); + let rust_target = ctx.options().rust_target; if f.is_nan() { - return Ok(quote! { - if rust_target >= RustTarget::Stable_1_43 { + let tokens = if rust_target >= RustTarget::Stable_1_43 { + quote! { f64::NAN - } else { + } + } else { + quote! { ::#prefix::f64::NAN } - }); + }; + return Ok(tokens); } if f.is_infinite() { - return Ok(if f.is_sign_positive() { - quote! { - if rust_target >= RustTarget::Stable_1_43 { + let tokens = if f.is_sign_positive() { + if rust_target >= RustTarget::Stable_1_43 { + quote! { f64::INFINITY - } else { + } + } else { + quote! { ::#prefix::f64::INFINITY } } - } else { - quote! { - if rust_target >= RustTarget::Stable_1_43 { + } else { // sign_negative + if rust_target >= RustTarget::Stable_1_43 { + quote! { f64::NEG_INFINITY - } else { + } + } else { + quote! { ::#prefix::f64::NEG_INFINITY } } - }); + }; + return Ok(tokens); } warn!("Unknown non-finite float number: {:?}", f); diff --git a/bindgen/features.rs b/bindgen/features.rs index c07318c5e2..6c19c5b2a2 100644 --- a/bindgen/features.rs +++ b/bindgen/features.rs @@ -106,7 +106,8 @@ define_rust_targets! { Stable_1_64(64) => { core_ffi_c: #94503 }, Stable_1_59(59) => { const_cstr: #54745 }, Stable_1_47(47) => { larger_arrays: #74060 }, - Stable_1_40(40) => { non_exhaustive: #44109 }, + Stable_1_43(43) => { non_exhaustive: #44109 }, + Stable_1_40(40) => {}, Stable_1_36(36) => { maybe_uninit: #60445 }, Stable_1_33(33) => { repr_packed_n: #57049 }, #[deprecated] From 42295d583b0eb5dd388ae2d1ee683cfe6877f88b Mon Sep 17 00:00:00 2001 From: Gabi Ganam Date: Wed, 26 Jun 2024 06:54:33 +0000 Subject: [PATCH 698/942] Fix generated constants: `f64::INFINITY`, `f64::NEG_ INFINITY`, `f64::NAN` https://github.com/rust-lang/rust-bindgen/issues/2853 --- bindgen/codegen/helpers.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindgen/codegen/helpers.rs b/bindgen/codegen/helpers.rs index bfe1e3d814..77a2261b8a 100644 --- a/bindgen/codegen/helpers.rs +++ b/bindgen/codegen/helpers.rs @@ -339,7 +339,7 @@ pub(crate) mod ast_ty { ::#prefix::f64::INFINITY } } - } else { // sign_negative + } else { if rust_target >= RustTarget::Stable_1_43 { quote! { f64::NEG_INFINITY From 93f962a73eae467aeaeb9116b16cfd4b1210ddfe Mon Sep 17 00:00:00 2001 From: Gabi Ganam Date: Wed, 26 Jun 2024 07:08:01 +0000 Subject: [PATCH 699/942] Fix generated constants: `f64::INFINITY`, `f64::NEG_ INFINITY`, `f64::NAN` https://github.com/rust-lang/rust-bindgen/issues/2853 --- bindgen/codegen/helpers.rs | 1 + bindgen/features.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/bindgen/codegen/helpers.rs b/bindgen/codegen/helpers.rs index 77a2261b8a..4038340100 100644 --- a/bindgen/codegen/helpers.rs +++ b/bindgen/codegen/helpers.rs @@ -340,6 +340,7 @@ pub(crate) mod ast_ty { } } } else { + // Negative infinity if rust_target >= RustTarget::Stable_1_43 { quote! { f64::NEG_INFINITY diff --git a/bindgen/features.rs b/bindgen/features.rs index 6c19c5b2a2..32f572c4c9 100644 --- a/bindgen/features.rs +++ b/bindgen/features.rs @@ -107,7 +107,7 @@ define_rust_targets! { Stable_1_59(59) => { const_cstr: #54745 }, Stable_1_47(47) => { larger_arrays: #74060 }, Stable_1_43(43) => { non_exhaustive: #44109 }, - Stable_1_40(40) => {}, + Stable_1_40(40) => { associated_constants: #68952}, Stable_1_36(36) => { maybe_uninit: #60445 }, Stable_1_33(33) => { repr_packed_n: #57049 }, #[deprecated] From f29a8d7e454b0235cb64efa90b358092817722fa Mon Sep 17 00:00:00 2001 From: Gabi Ganam Date: Thu, 27 Jun 2024 05:47:31 +0000 Subject: [PATCH 700/942] Fix generated constants: `f64::INFINITY`, `f64::NEG_ INFINITY`, `f64::NAN`. https://github.com/rust-lang/rust-bindgen/issues/2853 --- bindgen/features.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bindgen/features.rs b/bindgen/features.rs index 32f572c4c9..bd6a25cb84 100644 --- a/bindgen/features.rs +++ b/bindgen/features.rs @@ -106,8 +106,8 @@ define_rust_targets! { Stable_1_64(64) => { core_ffi_c: #94503 }, Stable_1_59(59) => { const_cstr: #54745 }, Stable_1_47(47) => { larger_arrays: #74060 }, - Stable_1_43(43) => { non_exhaustive: #44109 }, - Stable_1_40(40) => { associated_constants: #68952}, + 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 }, #[deprecated] From 2f64f48c219278168221e03600f6bad696294f7c Mon Sep 17 00:00:00 2001 From: Gabi Ganam Date: Sun, 30 Jun 2024 07:47:49 +0000 Subject: [PATCH 701/942] Fix generated constants: `f64::INFINITY`, `f64::NEG_ INFINITY`, `f64::NAN`. https://github.com/rust-lang/rust-bindgen/issues/2853 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a48136ca52..348420e9b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -217,6 +217,7 @@ enabling it by default for `bindgen-cli` (#2789) . - Fix `--allowlist-item` so anonymous enums are no longer ignored. - Use clang_getFileLocation instead of clang_getSpellingLocation to fix clang-trunk (#2824) +- Fix generated constants: `f64::INFINITY`, `f64::NEG_ INFINITY`, `f64::NAN`. ## Security From 99ae2d3d32a7978e32f240cee57f7d7ccd5a2363 Mon Sep 17 00:00:00 2001 From: Gabi Ganam Date: Sun, 30 Jun 2024 07:57:13 +0000 Subject: [PATCH 702/942] Fix generated constants: `f64::INFINITY`, `f64::NEG_ INFINITY`, `f64::NAN`. https://github.com/rust-lang/rust-bindgen/issues/2853 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 348420e9b7..266db1dcbd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -217,7 +217,7 @@ enabling it by default for `bindgen-cli` (#2789) . - Fix `--allowlist-item` so anonymous enums are no longer ignored. - Use clang_getFileLocation instead of clang_getSpellingLocation to fix clang-trunk (#2824) -- Fix generated constants: `f64::INFINITY`, `f64::NEG_ INFINITY`, `f64::NAN`. +- Fix generated constants: `f64::INFINITY`, `f64::NEG_ INFINITY`, `f64::NAN` (#2854). ## Security From 218bae98cfc8445c23d8c5c7c599575295217b6d Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Tue, 2 Jul 2024 21:19:46 +0700 Subject: [PATCH 703/942] ci: Use `dtolnay/rust-toolchain`, not `actions-rs` The `actions-rs` actions are not maintained (and haven't been for a long time). Some tests used `dtolnay/rust-toolchain`, so use it consistently. --- .github/workflows/bindgen.yml | 38 +++++++++-------------------------- 1 file changed, 9 insertions(+), 29 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 899d771342..7e9c254e83 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -19,26 +19,18 @@ jobs: - uses: actions/checkout@v4 - name: Install stable - uses: actions-rs/toolchain@v1 + uses: dtolnay/rust-toolchain@master with: - profile: minimal # TODO: Should ideally be stable, but we use some nightly-only # features. toolchain: nightly - override: true components: rustfmt, clippy - name: Run rustfmt - uses: actions-rs/cargo@v1 - with: - command: fmt - args: -- --check + run: cargo fmt -- --check - name: Run clippy - uses: actions-rs/cargo@v1 - with: - command: clippy - args: --tests + run: cargo clippy --tests msrv: runs-on: ubuntu-latest @@ -73,11 +65,9 @@ jobs: - uses: actions/checkout@v4 - name: Install stable - uses: actions-rs/toolchain@v1 + uses: dtolnay/rust-toolchain@master with: - profile: minimal toolchain: stable - override: true - name: Check without default features run: cargo check -p bindgen --no-default-features --features=runtime @@ -90,11 +80,9 @@ jobs: - uses: actions/checkout@v4 - name: Install stable - uses: actions-rs/toolchain@v1 + uses: dtolnay/rust-toolchain@master with: - profile: minimal toolchain: stable - override: true - name: Generate documentation for `bindgen` run: cargo doc --document-private-items --no-deps -p bindgen @@ -108,11 +96,9 @@ jobs: - uses: actions/checkout@v4 - name: Install stable - uses: actions-rs/toolchain@v1 + uses: dtolnay/rust-toolchain@master with: - profile: minimal toolchain: stable - override: true # TODO: Actually run quickchecks once `bindgen` is reliable enough. - name: Build quickcheck tests @@ -127,11 +113,9 @@ jobs: - uses: actions/checkout@v4 - name: Install stable - uses: actions-rs/toolchain@v1 + uses: dtolnay/rust-toolchain@master with: - profile: minimal toolchain: stable - override: true - name: Test expectations run: cd bindgen-tests/tests/expectations && cargo test @@ -205,12 +189,10 @@ jobs: sudo apt-get install libc6:${{matrix.target.debian}} libstdc++6:${{matrix.target.debian}} - name: Install stable - uses: actions-rs/toolchain@v1 + uses: dtolnay/rust-toolchain@master with: - profile: minimal toolchain: stable target: ${{matrix.target.rust}} - override: true - name: Install libtinfo if: matrix.os == 'ubuntu-latest' run: | @@ -237,11 +219,9 @@ jobs: - uses: actions/checkout@v4 - name: Install nightly - uses: actions-rs/toolchain@v1 + uses: dtolnay/rust-toolchain@master with: - profile: minimal toolchain: nightly - override: true - name: Check cfg run: cargo check -Z unstable-options -Z check-cfg From 7600bf8097fd47d61f91948f2b36be6ea41f7d89 Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Tue, 2 Jul 2024 21:33:52 +0700 Subject: [PATCH 704/942] Fix `clippy::doc_lazy_continuation` lints --- bindgen/codegen/mod.rs | 6 +++--- bindgen/ir/analysis/sizedness.rs | 6 +++--- bindgen/ir/analysis/template_params.rs | 4 ++-- bindgen/ir/derive.rs | 4 ++-- bindgen/ir/template.rs | 8 ++++---- bindgen/options/mod.rs | 18 +++++++++--------- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 7c1c55abb5..e2aaee9820 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -1658,13 +1658,13 @@ fn access_specifier( /// Compute a fields or structs visibility based on multiple conditions. /// 1. If the element was declared public, and we respect such CXX accesses specs -/// (context option) => By default Public, but this can be overruled by an `annotation`. +/// (context option) => By default Public, but this can be overruled by an `annotation`. /// /// 2. If the element was declared private, and we respect such CXX accesses specs -/// (context option) => By default Private, but this can be overruled by an `annotation`. +/// (context option) => By default Private, but this can be overruled by an `annotation`. /// /// 3. If we do not respect visibility modifiers, the result depends on the `annotation`, -/// if any, or the passed `default_kind`. +/// if any, or the passed `default_kind`. /// fn compute_visibility( ctx: &BindgenContext, diff --git a/bindgen/ir/analysis/sizedness.rs b/bindgen/ir/analysis/sizedness.rs index ea93f2f103..edcf47f5c6 100644 --- a/bindgen/ir/analysis/sizedness.rs +++ b/bindgen/ir/analysis/sizedness.rs @@ -87,13 +87,13 @@ impl ops::BitOrAssign for SizednessResult { /// An analysis that computes the sizedness of all types. /// /// * For types with known sizes -- for example pointers, scalars, etc... -- -/// they are assigned `NonZeroSized`. +/// they are assigned `NonZeroSized`. /// /// * For compound structure types with one or more fields, they are assigned -/// `NonZeroSized`. +/// `NonZeroSized`. /// /// * For compound structure types without any fields, the results of the bases -/// are `join`ed. +/// are `join`ed. /// /// * For type parameters, `DependsOnTypeParam` is assigned. #[derive(Debug)] diff --git a/bindgen/ir/analysis/template_params.rs b/bindgen/ir/analysis/template_params.rs index e4261cf675..a35dcd98e3 100644 --- a/bindgen/ir/analysis/template_params.rs +++ b/bindgen/ir/analysis/template_params.rs @@ -124,8 +124,8 @@ use crate::{HashMap, HashSet}; /// ``` /// /// * Finally, for all other IR item kinds, we use our lattice's `join` -/// operation: set union with each successor of the given item's template -/// parameter usage: +/// operation: set union with each successor of the given item's template +/// parameter usage: /// /// ```ignore /// template_param_usage(v) = diff --git a/bindgen/ir/derive.rs b/bindgen/ir/derive.rs index 7491e3efc4..5475ffdb22 100644 --- a/bindgen/ir/derive.rs +++ b/bindgen/ir/derive.rs @@ -3,10 +3,10 @@ //! These traits tend to come in pairs: //! //! 1. A "trivial" version, whose implementations aren't allowed to recursively -//! look at other types or the results of fix point analyses. +//! look at other types or the results of fix point analyses. //! //! 2. A "normal" version, whose implementations simply query the results of a -//! fix point analysis. +//! fix point analysis. //! //! The former is used by the analyses when creating the results queried by the //! second. diff --git a/bindgen/ir/template.rs b/bindgen/ir/template.rs index 4dd8442c58..59bd4bfde4 100644 --- a/bindgen/ir/template.rs +++ b/bindgen/ir/template.rs @@ -4,7 +4,7 @@ //! brief definitions: //! //! * "Template definition": a class/struct/alias/function definition that takes -//! generic template parameters. For example: +//! generic template parameters. For example: //! //! ```c++ //! template @@ -14,11 +14,11 @@ //! ``` //! //! * "Template instantiation": an instantiation is a use of a template with -//! concrete template arguments. For example, `List`. +//! concrete template arguments. For example, `List`. //! //! * "Template specialization": an alternative template definition providing a -//! custom definition for instantiations with the matching template -//! arguments. This C++ feature is unsupported by bindgen. For example: +//! custom definition for instantiations with the matching template +//! arguments. This C++ feature is unsupported by bindgen. For example: //! //! ```c++ //! template<> diff --git a/bindgen/options/mod.rs b/bindgen/options/mod.rs index d1486397bd..e4c03ecd4d 100644 --- a/bindgen/options/mod.rs +++ b/bindgen/options/mod.rs @@ -35,20 +35,20 @@ use helpers::ignore; /// a block of code with the following items: /// /// - `default`: The default value for the field. If this item is omitted, `Default::default()` is -/// used instead, meaning that the type of the field must implement `Default`. +/// used instead, meaning that the type of the field must implement `Default`. /// - `methods`: A block of code containing methods for the `Builder` type. These methods should be -/// related to the field being declared. +/// related to the field being declared. /// - `as_args`: This item declares how the field should be converted into a valid CLI argument for -/// `bindgen` and is used in the [`Builder::command_line_flags`] method which is used to do a -/// roundtrip test of the CLI args in the `bindgen-test` crate. This item can take one of the -/// following: +/// `bindgen` and is used in the [`Builder::command_line_flags`] method which is used to do a +/// roundtrip test of the CLI args in the `bindgen-test` crate. This item can take one of the +/// following: /// - A string literal with the flag if the type of the field implements the [`AsArgs`] trait. /// - A closure with the signature `|field, args: &mut Vec| -> ()` that pushes arguments -/// into the `args` buffer based on the value of the field. This is used if the field does not -/// implement `AsArgs` or if the implementation of the trait is not logically correct for the -/// option and a custom behavior must be taken into account. +/// into the `args` buffer based on the value of the field. This is used if the field does not +/// implement `AsArgs` or if the implementation of the trait is not logically correct for the +/// option and a custom behavior must be taken into account. /// - The `ignore` literal, which does not emit any CLI arguments for this field. This is useful -/// if the field cannot be used from the `bindgen` CLI. +/// if the field cannot be used from the `bindgen` CLI. /// /// As an example, this would be the declaration of a `bool` field called `be_fun` whose default /// value is `false` (the `Default` value for `bool`): From 66b65517b5568e122e9ce5902dd4868aa2b43d25 Mon Sep 17 00:00:00 2001 From: beetrees Date: Sat, 13 Jul 2024 02:59:36 +0100 Subject: [PATCH 705/942] Add tracking issue number for `"vectorcall"` ABI feature --- bindgen/features.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindgen/features.rs b/bindgen/features.rs index bd6a25cb84..990e4513cb 100644 --- a/bindgen/features.rs +++ b/bindgen/features.rs @@ -95,7 +95,7 @@ macro_rules! define_rust_targets { // not stable. define_rust_targets! { Nightly => { - vectorcall_abi, + vectorcall_abi: #124485, ptr_metadata: #81513, layout_for_ptr: #69835, }, From bd6794234e7a1f6fc58b2bf61e9c2555f55d82fb Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Tue, 30 Jul 2024 12:08:17 -0700 Subject: [PATCH 706/942] Update flex-array implementation to work with Rust 1.80 --- .../tests/expectations/tests/flexarray.rs | 25 +++++++++++++++---- bindgen/codegen/mod.rs | 2 +- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/bindgen-tests/tests/expectations/tests/flexarray.rs b/bindgen-tests/tests/expectations/tests/flexarray.rs index 2c47f0ec55..ece5e62419 100644 --- a/bindgen-tests/tests/expectations/tests/flexarray.rs +++ b/bindgen-tests/tests/expectations/tests/flexarray.rs @@ -50,7 +50,10 @@ const _: () = { impl flexarray<[::std::os::raw::c_int]> { pub fn layout(len: usize) -> ::std::alloc::Layout { unsafe { - let p: *const Self = ::std::ptr::from_raw_parts(::std::ptr::null(), len); + let p: *const Self = ::std::ptr::from_raw_parts( + ::std::ptr::null::<()>(), + len, + ); ::std::alloc::Layout::for_value_raw(p) } } @@ -136,7 +139,10 @@ const _: () = { impl flexarray_zero<[::std::os::raw::c_int]> { pub fn layout(len: usize) -> ::std::alloc::Layout { unsafe { - let p: *const Self = ::std::ptr::from_raw_parts(::std::ptr::null(), len); + let p: *const Self = ::std::ptr::from_raw_parts( + ::std::ptr::null::<()>(), + len, + ); ::std::alloc::Layout::for_value_raw(p) } } @@ -220,7 +226,10 @@ pub struct flexarray_template { impl flexarray_template { pub fn layout(len: usize) -> ::std::alloc::Layout { unsafe { - let p: *const Self = ::std::ptr::from_raw_parts(::std::ptr::null(), len); + let p: *const Self = ::std::ptr::from_raw_parts( + ::std::ptr::null::<()>(), + len, + ); ::std::alloc::Layout::for_value_raw(p) } } @@ -344,7 +353,10 @@ const _: () = { impl flexarray_bogus_zero_fam<[::std::os::raw::c_char]> { pub fn layout(len: usize) -> ::std::alloc::Layout { unsafe { - let p: *const Self = ::std::ptr::from_raw_parts(::std::ptr::null(), len); + let p: *const Self = ::std::ptr::from_raw_parts( + ::std::ptr::null::<()>(), + len, + ); ::std::alloc::Layout::for_value_raw(p) } } @@ -450,7 +462,10 @@ const _: () = { impl flexarray_align<[::std::os::raw::c_int]> { pub fn layout(len: usize) -> ::std::alloc::Layout { unsafe { - let p: *const Self = ::std::ptr::from_raw_parts(::std::ptr::null(), len); + let p: *const Self = ::std::ptr::from_raw_parts( + ::std::ptr::null::<()>(), + len, + ); ::std::alloc::Layout::for_value_raw(p) } } diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index e2aaee9820..46d615b25d 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -2723,7 +2723,7 @@ impl CompInfo { pub fn layout(len: usize) -> ::#prefix::alloc::Layout { // SAFETY: Null pointers are OK if we don't deref them unsafe { - let p: *const Self = ::#prefix::ptr::from_raw_parts(::#prefix::ptr::null(), len); + let p: *const Self = ::#prefix::ptr::from_raw_parts(::#prefix::ptr::null::<()>(), len); ::#prefix::alloc::Layout::for_value_raw(p) } } From 4850f1f83946e989556f8f24d25b4ac36f849be5 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Fri, 16 Aug 2024 10:51:25 -0500 Subject: [PATCH 707/942] Update `tempfile` and `rustix` --- Cargo.lock | 40 ++++++++++------------------------------ 1 file changed, 10 insertions(+), 30 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ace73d6b07..f34d8d3dfd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -292,7 +292,7 @@ checksum = "adcf93614601c8129ddf72e2d5633df827ba6551541c6d8c59520a371475be1f" dependencies = [ "hermit-abi", "io-lifetimes", - "rustix 0.37.3", + "rustix", "windows-sys 0.48.0", ] @@ -321,12 +321,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "linux-raw-sys" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" - [[package]] name = "linux-raw-sys" version = "0.3.8" @@ -492,9 +486,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.2.16" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" dependencies = [ "bitflags 1.3.2", ] @@ -524,29 +518,15 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" [[package]] name = "rustix" -version = "0.36.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6da3636faa25820d8648e0e31c5d519bbb01f72fdf57131f0f5f7da5fed36eab" -dependencies = [ - "bitflags 1.3.2", - "errno", - "io-lifetimes", - "libc", - "linux-raw-sys 0.1.4", - "windows-sys 0.45.0", -] - -[[package]] -name = "rustix" -version = "0.37.3" +version = "0.37.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b24138615de35e32031d041a09032ef3487a616d901ca4db224e7d557efae2" +checksum = "2aae838e49b3d63e9274e1c01833cc8139d3fec468c3b84688c628f44b1ae11d" dependencies = [ "bitflags 1.3.2", "errno", "io-lifetimes", "libc", - "linux-raw-sys 0.3.8", + "linux-raw-sys", "windows-sys 0.45.0", ] @@ -592,15 +572,15 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.4.0" +version = "3.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af18f7ae1acd354b992402e9ec5864359d693cd8a79dcbef59f76891701c1e95" +checksum = "b9fbec84f381d5795b08656e4912bec604d162bff9291d6189a78f4c8ab87998" dependencies = [ "cfg-if", "fastrand", "redox_syscall", - "rustix 0.36.16", - "windows-sys 0.42.0", + "rustix", + "windows-sys 0.45.0", ] [[package]] From 4ec9950ed850c7f619431364e7ae1f194ca6ab6d Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Fri, 16 Aug 2024 10:40:07 -0500 Subject: [PATCH 708/942] Update the changelog --- CHANGELOG.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 266db1dcbd..1671ab394a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -211,15 +211,16 @@ ## Changed - Remove which and lazy-static dependencies (#2809, #2817). - Generate compile-time layout tests (#2787). +- Print `bindgen-cli` errors to stderr instead of stdout (#2840) ## Removed ## Fixed - Fix `--formatter=prettyplease` not working in `bindgen-cli` by adding `prettyplease` feature and enabling it by default for `bindgen-cli` (#2789) . -- Fix `--allowlist-item` so anonymous enums are no longer ignored. -- Use clang_getFileLocation instead of clang_getSpellingLocation to fix clang-trunk (#2824) +- Fix `--allowlist-item` so anonymous enums are no longer ignored (#2827). +- Use clang_getFileLocation instead of clang_getSpellingLocation to fix clang-trunk (#2824). - Fix generated constants: `f64::INFINITY`, `f64::NEG_ INFINITY`, `f64::NAN` (#2854). - ## Security +- Update `tempfile` and `rustix` due to [GHSA-c827-hfw6-qwvm](https://github.com/advisories/GHSA-c827-hfw6-qwvm). # 0.69.4 (2024-02-04) ## Added From 26fc39b23df7cd27f34b9eec944d2964df9b0e1d Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Fri, 16 Aug 2024 12:27:37 -0500 Subject: [PATCH 709/942] Only trigger the publish workflow manually --- .github/workflows/publish.yml | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 352199d7d7..1aaeb006df 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,10 +1,8 @@ -# This is triggered after the Release workflow successfully completes its run -on: - workflow_run: - workflows: - - Release - types: - - completed +# To trigger this: +# - go to Actions > Publish +# - click the Run Workflow dropdown in the top-right +name: Publish +on: workflow_dispatch env: CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} jobs: From d5f9dfe4a0a4bd31860ca9082e39ad9d8c2056ec Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Fri, 16 Aug 2024 12:58:41 -0500 Subject: [PATCH 710/942] Add workflow to create release PR --- .github/workflows/create-release-pr.yml | 44 +++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 .github/workflows/create-release-pr.yml diff --git a/.github/workflows/create-release-pr.yml b/.github/workflows/create-release-pr.yml new file mode 100644 index 0000000000..ebccab1508 --- /dev/null +++ b/.github/workflows/create-release-pr.yml @@ -0,0 +1,44 @@ +on: + workflow_dispatch: + inputs: + level: + description: | + Select the level of the release: + - minor: Increase the minor version (x.y.0) + - patch: Increase the patch version (x.y.z) + required: true + type: choice + options: + - minor + - patch + +jobs: + Create Release PR: + permissions: + id-token: write # Enable OIDC + pull-requests: write + contents: write + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Configure gitsign + uses: chainguard-dev/actions/setup-gitsign@main + + - name: Install `cargo-release` + uses: taiki-e/install-action@v1 + with: + tool: cargo-release + + - name: Install `npm` + uses: actions/setup-node@v4 + + - name: Install `doctoc` + run: npm install doctoc + + - name: Create a release pull request + uses: cargo-bins/release-pr@v2 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + version: ${{ github.event.inputs.level }} From cbf3a3bbe86ee7431458b5be24ee205a88bd1eea Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Fri, 16 Aug 2024 13:54:11 -0500 Subject: [PATCH 711/942] Fix job identifier --- .github/workflows/create-release-pr.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/create-release-pr.yml b/.github/workflows/create-release-pr.yml index ebccab1508..59b7090c13 100644 --- a/.github/workflows/create-release-pr.yml +++ b/.github/workflows/create-release-pr.yml @@ -1,3 +1,5 @@ +name: Create release PR + on: workflow_dispatch: inputs: @@ -13,7 +15,7 @@ on: - patch jobs: - Create Release PR: + create-release-pr: permissions: id-token: write # Enable OIDC pull-requests: write From 112e90efc09f8d5a58b93ec4a32a847c726418d1 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Fri, 16 Aug 2024 14:12:30 -0500 Subject: [PATCH 712/942] Add workflow that only bumps the crates version --- .github/workflows/bump-version.yml | 68 +++++++++++++++++++++++++ .github/workflows/create-release-pr.yml | 46 ----------------- 2 files changed, 68 insertions(+), 46 deletions(-) create mode 100644 .github/workflows/bump-version.yml delete mode 100644 .github/workflows/create-release-pr.yml diff --git a/.github/workflows/bump-version.yml b/.github/workflows/bump-version.yml new file mode 100644 index 0000000000..56a264f7f7 --- /dev/null +++ b/.github/workflows/bump-version.yml @@ -0,0 +1,68 @@ +name: Bump version for release + +on: + workflow_dispatch: + inputs: + level: + description: | + Select the level of the release + required: true + type: choice + options: + - minor + - patch + +jobs: + bump-version: + permissions: + id-token: write + pull-requests: write + contents: write + + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Configure gitsign + uses: chainguard-dev/actions/setup-gitsign@main + + - name: Install cargo-release + uses: taiki-e/install-action@v1 + with: + tool: cargo-release + + - name: Install sd + uses: taiki-e/install-action@v1 + with: + tool: sd + + - name: Install npm + uses: actions/setup-node@v4 + + - name: Install doctoc + run: npm install doctoc + + - name: Bump version + run: | + cargo release version ${{ inputs.level }} --execute --no-confirm + + - name: Extract version + run: | + echo "version=$(cargo pkgid -p bindgen | cut -d '#' -f 2)" >> $GITHUB_ENV + + - name: Update changelog + run: | + sd "# Unreleased" "# Unreleased\n## Added\n## Changed\n## Removed\n## Fixed\n## Security\n\n# ${{ env.version }} ($(date -I))" CHANGELOG.md + ./node_modules/doctoc/doctoc.js CHANGELOG.md + + - name: Create PR + uses: peter-evans/create-pull-request@v5 + with: + token: ${{ secrets.GITHUB_TOKEN }} + branch: bump-version/${{ env.version }} + base: main + commit-message: "Bump crates version to ${{ env.version }}" + title: "Bump crates version to ${{ env.version }}" + body: | + This pull request was created automatically by GitHub Actions. diff --git a/.github/workflows/create-release-pr.yml b/.github/workflows/create-release-pr.yml deleted file mode 100644 index 59b7090c13..0000000000 --- a/.github/workflows/create-release-pr.yml +++ /dev/null @@ -1,46 +0,0 @@ -name: Create release PR - -on: - workflow_dispatch: - inputs: - level: - description: | - Select the level of the release: - - minor: Increase the minor version (x.y.0) - - patch: Increase the patch version (x.y.z) - required: true - type: choice - options: - - minor - - patch - -jobs: - create-release-pr: - permissions: - id-token: write # Enable OIDC - pull-requests: write - contents: write - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Configure gitsign - uses: chainguard-dev/actions/setup-gitsign@main - - - name: Install `cargo-release` - uses: taiki-e/install-action@v1 - with: - tool: cargo-release - - - name: Install `npm` - uses: actions/setup-node@v4 - - - name: Install `doctoc` - run: npm install doctoc - - - name: Create a release pull request - uses: cargo-bins/release-pr@v2 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - version: ${{ github.event.inputs.level }} From e4fcb548d02093cc2b0a5f8b5e8552ef594dcc3a Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Fri, 16 Aug 2024 17:31:22 -0500 Subject: [PATCH 713/942] Add github action workflow that creates tags --- .github/workflows/create-tag.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .github/workflows/create-tag.yml diff --git a/.github/workflows/create-tag.yml b/.github/workflows/create-tag.yml new file mode 100644 index 0000000000..10bf2be81d --- /dev/null +++ b/.github/workflows/create-tag.yml @@ -0,0 +1,25 @@ +name: Create tag for release + +on: + pull_request: + types: + - closed + +jobs: + create-tag: + if: github.event.pull_request.merged == true && github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name && startsWith(github.event.pull_request.head.ref, 'bump-version') + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Extract version + uses: dtolnay/rust-toolchain@stable + run: | + echo "version=$(cargo pkgid -p bindgen | cut -d '#' -f 2)" >> $GITHUB_ENV + + - name: Create tag + run: | + TAG_NAME="v${{ env.VERSION }}" + git tag $TAG_NAME + git push origin $TAG_NAME From 7efb92410813cdd8ac27d40e96e3aa3cf705d540 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Fri, 16 Aug 2024 17:32:42 -0500 Subject: [PATCH 714/942] fix error --- .github/workflows/create-tag.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/create-tag.yml b/.github/workflows/create-tag.yml index 10bf2be81d..b9eb8b1a5c 100644 --- a/.github/workflows/create-tag.yml +++ b/.github/workflows/create-tag.yml @@ -13,8 +13,10 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - name: Extract version + - name: Install rust toolchain uses: dtolnay/rust-toolchain@stable + + - name: Extract version run: | echo "version=$(cargo pkgid -p bindgen | cut -d '#' -f 2)" >> $GITHUB_ENV From 190ff2a6a4739f3a703125d9ed290dcd2dc9c808 Mon Sep 17 00:00:00 2001 From: pvdrz Date: Fri, 16 Aug 2024 22:24:02 +0000 Subject: [PATCH 715/942] Bump crates version to 0.70.0 --- CHANGELOG.md | 191 ++++++++++++++++++++++------------------- Cargo.lock | 4 +- bindgen-cli/Cargo.toml | 4 +- bindgen/Cargo.toml | 2 +- 4 files changed, 107 insertions(+), 94 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1671ab394a..d80fa4fa81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,202 +7,215 @@ - [Removed](#removed) - [Fixed](#fixed) - [Security](#security) -- [0.69.4 (2024-02-04)](#0694-2024-02-04) +- [0.70.0 (2024-08-16)](#0700-2024-08-16) - [Added](#added-1) - [Changed](#changed-1) - [Removed](#removed-1) - [Fixed](#fixed-1) - [Security](#security-1) -- [0.69.3 (2024-02-04)](#0693-2024-02-04) +- [0.69.4 (2024-02-04)](#0694-2024-02-04) - [Added](#added-2) - [Changed](#changed-2) - [Removed](#removed-2) - [Fixed](#fixed-2) - [Security](#security-2) -- [0.69.2 (2024-01-13)](#0692-2024-01-13) +- [0.69.3 (2024-02-04)](#0693-2024-02-04) - [Added](#added-3) - [Changed](#changed-3) - [Removed](#removed-3) - [Fixed](#fixed-3) - [Security](#security-3) -- [0.69.1 (2023-11-02)](#0691-2023-11-02) - - [Fixed](#fixed-4) -- [0.69.0 (2023-11-01)](#0690-2023-11-01) +- [0.69.2 (2024-01-13)](#0692-2024-01-13) - [Added](#added-4) - [Changed](#changed-4) - [Removed](#removed-4) - - [Fixed](#fixed-5) + - [Fixed](#fixed-4) - [Security](#security-4) -- [0.68.1](#0681) - - [Fixed](#fixed-6) -- [0.68.0](#0680) +- [0.69.1 (2023-11-02)](#0691-2023-11-02) + - [Fixed](#fixed-5) +- [0.69.0 (2023-11-01)](#0690-2023-11-01) - [Added](#added-5) - [Changed](#changed-5) - [Removed](#removed-5) + - [Fixed](#fixed-6) + - [Security](#security-5) +- [0.68.1](#0681) - [Fixed](#fixed-7) -- [0.67.0](#0670) -- [0.66.1](#0661) - - [Removed](#removed-6) -- [0.66.0](#0660) +- [0.68.0](#0680) - [Added](#added-6) - [Changed](#changed-6) - - [Removed](#removed-7) -- [0.65.1](#0651) + - [Removed](#removed-6) - [Fixed](#fixed-8) -- [0.65.0](#0650) +- [0.67.0](#0670) +- [0.66.1](#0661) + - [Removed](#removed-7) +- [0.66.0](#0660) - [Added](#added-7) - [Changed](#changed-7) - [Removed](#removed-8) -- [0.64.0](#0640) +- [0.65.1](#0651) + - [Fixed](#fixed-9) +- [0.65.0](#0650) - [Added](#added-8) - [Changed](#changed-8) -- [0.63.0](#0630) + - [Removed](#removed-9) +- [0.64.0](#0640) - [Added](#added-9) - [Changed](#changed-9) - - [Removed](#removed-9) -- [0.62.0](#0620) +- [0.63.0](#0630) - [Added](#added-10) - [Changed](#changed-10) - - [Fixed](#fixed-9) -- [0.61.0](#0610) + - [Removed](#removed-10) +- [0.62.0](#0620) - [Added](#added-11) - [Changed](#changed-11) - [Fixed](#fixed-10) -- [0.60.1](#0601) - - [Fixed](#fixed-11) -- [0.60.0](#0600) +- [0.61.0](#0610) - [Added](#added-12) - - [Fixed](#fixed-12) - [Changed](#changed-12) - - [Removed](#removed-10) + - [Fixed](#fixed-11) +- [0.60.1](#0601) + - [Fixed](#fixed-12) +- [0.60.0](#0600) + - [Added](#added-13) + - [Fixed](#fixed-13) + - [Changed](#changed-13) + - [Removed](#removed-11) - [0.59.2](#0592) - [0.59.1](#0591) - - [Fixed](#fixed-13) -- [0.59.0](#0590) - - [Added](#added-13) - [Fixed](#fixed-14) - - [Changed](#changed-13) -- [0.58.1](#0581) +- [0.59.0](#0590) - [Added](#added-14) -- [0.58.0](#0580) - - [Added](#added-15) - [Fixed](#fixed-15) - [Changed](#changed-14) - - [Deprecated](#deprecated) - - [Removed](#removed-11) - - [Fixed](#fixed-16) - - [Security](#security-5) -- [0.57.0](#0570) +- [0.58.1](#0581) + - [Added](#added-15) +- [0.58.0](#0580) - [Added](#added-16) + - [Fixed](#fixed-16) + - [Changed](#changed-15) + - [Deprecated](#deprecated) + - [Removed](#removed-12) - [Fixed](#fixed-17) -- [0.56.0](#0560) + - [Security](#security-6) +- [0.57.0](#0570) - [Added](#added-17) - - [Changed](#changed-15) - [Fixed](#fixed-18) -- [0.55.1](#0551) - - [Fixed](#fixed-19) -- [0.55.0](#0550) - - [Removed](#removed-12) +- [0.56.0](#0560) - [Added](#added-18) - [Changed](#changed-16) + - [Fixed](#fixed-19) +- [0.55.1](#0551) - [Fixed](#fixed-20) -- [0.54.1](#0541) +- [0.55.0](#0550) + - [Removed](#removed-13) - [Added](#added-19) - [Changed](#changed-17) - [Fixed](#fixed-21) -- [0.54.0](#0540) +- [0.54.1](#0541) - [Added](#added-20) - [Changed](#changed-18) - [Fixed](#fixed-22) -- [0.53.3](#0533) +- [0.54.0](#0540) - [Added](#added-21) + - [Changed](#changed-19) - [Fixed](#fixed-23) +- [0.53.3](#0533) + - [Added](#added-22) + - [Fixed](#fixed-24) - [0.53.2](#0532) - - [Changed](#changed-19) + - [Changed](#changed-20) - [0.53.1](#0531) - - [Added](#added-22) -- [0.53.0](#0530) - [Added](#added-23) - - [Changed](#changed-20) - - [Fixed](#fixed-24) -- [0.52.0](#0520) +- [0.53.0](#0530) - [Added](#added-24) - [Changed](#changed-21) - [Fixed](#fixed-25) -- [0.51.1](#0511) - - [Fixed](#fixed-26) +- [0.52.0](#0520) + - [Added](#added-25) - [Changed](#changed-22) -- [0.51.0](#0510) + - [Fixed](#fixed-26) +- [0.51.1](#0511) - [Fixed](#fixed-27) - [Changed](#changed-23) - - [Added](#added-25) -- [0.50.0](#0500) +- [0.51.0](#0510) + - [Fixed](#fixed-28) + - [Changed](#changed-24) - [Added](#added-26) -- [0.49.3](#0493) +- [0.50.0](#0500) - [Added](#added-27) +- [0.49.3](#0493) + - [Added](#added-28) - [0.49.2](#0492) - - [Changed](#changed-24) -- [0.49.1](#0491) - - [Fixed](#fixed-28) - [Changed](#changed-25) -- [0.49.0](#0490) - - [Added](#added-28) +- [0.49.1](#0491) - [Fixed](#fixed-29) - [Changed](#changed-26) -- [0.48.1](#0481) +- [0.49.0](#0490) + - [Added](#added-29) - [Fixed](#fixed-30) -- [0.48.0](#0480) - [Changed](#changed-27) +- [0.48.1](#0481) - [Fixed](#fixed-31) -- [0.47.4](#0474) - - [Added](#added-29) -- [0.47.3](#0473) +- [0.48.0](#0480) - [Changed](#changed-28) -- [0.47.2](#0472) - [Fixed](#fixed-32) -- [0.47.1](#0471) +- [0.47.4](#0474) + - [Added](#added-30) +- [0.47.3](#0473) - [Changed](#changed-29) +- [0.47.2](#0472) - [Fixed](#fixed-33) -- [0.47.0](#0470) +- [0.47.1](#0471) - [Changed](#changed-30) - [Fixed](#fixed-34) -- [0.33.1 .. 0.46.0](#0331--0460) - - [Added](#added-30) - - [Removed](#removed-13) +- [0.47.0](#0470) - [Changed](#changed-31) - [Fixed](#fixed-35) -- [0.33.1](#0331) +- [0.33.1 .. 0.46.0](#0331--0460) + - [Added](#added-31) + - [Removed](#removed-14) + - [Changed](#changed-32) - [Fixed](#fixed-36) +- [0.33.1](#0331) + - [Fixed](#fixed-37) - [0.33.0](#0330) - [0.32.2](#0322) - - [Fixed](#fixed-37) -- [0.32.1](#0321) - [Fixed](#fixed-38) -- [0.32.0](#0320) - - [Added](#added-31) - - [Changed](#changed-32) +- [0.32.1](#0321) - [Fixed](#fixed-39) -- [0.31.0](#0310) +- [0.32.0](#0320) - [Added](#added-32) - [Changed](#changed-33) - - [Deprecated](#deprecated-1) - - [Removed](#removed-14) - [Fixed](#fixed-40) -- [0.30.0](#0300) +- [0.31.0](#0310) - [Added](#added-33) - [Changed](#changed-34) - - [Deprecated](#deprecated-2) + - [Deprecated](#deprecated-1) + - [Removed](#removed-15) - [Fixed](#fixed-41) -- [0.29.0](#0290) +- [0.30.0](#0300) - [Added](#added-34) - [Changed](#changed-35) + - [Deprecated](#deprecated-2) - [Fixed](#fixed-42) +- [0.29.0](#0290) + - [Added](#added-35) + - [Changed](#changed-36) + - [Fixed](#fixed-43) -------------------------------------------------------------------------------- # Unreleased ## Added +## Changed +## Removed +## Fixed +## Security + +# 0.70.0 (2024-08-16) +## Added - Add target mappings for riscv64imac and riscv32imafc. - Add a complex macro fallback API (#2779). - Add option to use DST structs for flexible arrays (--flexarray-dst, #2772). diff --git a/Cargo.lock b/Cargo.lock index f34d8d3dfd..980aa6d6f7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -23,7 +23,7 @@ dependencies = [ [[package]] name = "bindgen" -version = "0.69.4" +version = "0.70.0" dependencies = [ "annotate-snippets", "bitflags 2.2.1", @@ -42,7 +42,7 @@ dependencies = [ [[package]] name = "bindgen-cli" -version = "0.69.4" +version = "0.70.0" dependencies = [ "bindgen", "clap", diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index 4f8e182fd7..a74ce57cfc 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -11,7 +11,7 @@ readme = "../README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.69.4" +version = "0.70.0" edition = "2018" rust-version = "1.70.0" @@ -20,7 +20,7 @@ path = "main.rs" name = "bindgen" [dependencies] -bindgen = { path = "../bindgen", version = "=0.69.4", default-features = false, features = ["__cli", "experimental", "prettyplease"] } +bindgen = { path = "../bindgen", version = "=0.70.0", default-features = false, features = ["__cli", "experimental", "prettyplease"] } clap = { version = "4", features = ["derive"] } clap_complete = "4" env_logger = { version = "0.10.0", optional = true } diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index 2ea1def69d..6e12505855 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -14,7 +14,7 @@ readme = "../README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.69.4" +version = "0.70.0" edition = "2018" build = "build.rs" # If you change this, also update README.md and msrv in .github/workflows/bindgen.yml From d71972abc543219c0619c41634bf68a5623be4be Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Fri, 16 Aug 2024 17:56:01 -0500 Subject: [PATCH 716/942] Fix create-tag.yml --- .github/workflows/create-tag.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/create-tag.yml b/.github/workflows/create-tag.yml index b9eb8b1a5c..27dcbb5741 100644 --- a/.github/workflows/create-tag.yml +++ b/.github/workflows/create-tag.yml @@ -22,6 +22,6 @@ jobs: - name: Create tag run: | - TAG_NAME="v${{ env.VERSION }}" + TAG_NAME="v${{ env.version }}" git tag $TAG_NAME git push origin $TAG_NAME From 7a4f04a03385924433081be560941711352dacb2 Mon Sep 17 00:00:00 2001 From: Kriskras99 Date: Tue, 20 Aug 2024 15:40:29 +0200 Subject: [PATCH 717/942] Fix creduce install link They seem to have renamed their main branch to master --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0ffc58565e..29cbc69947 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -425,7 +425,7 @@ $ brew install creduce $ # Etc... ``` -Otherwise, follow [these instructions](https://github.com/csmith-project/creduce/blob/main/INSTALL.md) for building and/or installing `creduce`. +Otherwise, follow [these instructions](https://github.com/csmith-project/creduce/blob/master/INSTALL.md) for building and/or installing `creduce`. Running `creduce` requires two things: From 8c718489a6d9426dee62d52950929583fc9318b8 Mon Sep 17 00:00:00 2001 From: Kriskras99 Date: Tue, 20 Aug 2024 16:01:02 +0200 Subject: [PATCH 718/942] Fix creduce example rustc-grep won't find [E0277] as it's reading it as a regex. The arguments need to be escaped --- CONTRIBUTING.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 29cbc69947..ff48cf1df7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -490,10 +490,11 @@ to fail to compile `bindgen`'s emitted bindings, you can invoke `predicate.py` like this: ```bash +# the rustc-grep argument expects a regex, thus escape where necessary path/to/rust-bindgen/csmith-fuzzing/predicate.py \ --bindings-grep NameOfTheStructThatIsErroneouslyDerivingEq \ --expect-compile-fail \ - --rustc-grep 'error[E0277]: the trait bound `f64: std::cmp::Eq` is not satisfied' \ + --rustc-grep 'error\[E0277\]: the trait bound `f64: std::cmp::Eq` is not satisfied' \ ./isolated-test-case.h ``` From 9bd603e74131ee734ea24e27fabd8ca082dd4fec Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Tue, 20 Aug 2024 11:28:23 -0500 Subject: [PATCH 719/942] Add `#[clippy::allow]` attribute to `const` layout tests --- CHANGELOG.md | 1 + .../expectations/tests/16-byte-alignment.rs | 7 +++++ .../tests/expectations/tests/accessors.rs | 6 +++++ .../expectations/tests/allowlist-file.rs | 4 +++ .../tests/allowlist-namespaces-basic.rs | 1 + .../tests/allowlist-namespaces.rs | 2 ++ .../expectations/tests/allowlist_item.rs | 1 + .../allowlisted-item-references-no-hash.rs | 2 ++ ...llowlisted-item-references-no-partialeq.rs | 2 ++ .../allowlisted_item_references_no_copy.rs | 2 ++ .../expectations/tests/annotation_hide.rs | 2 ++ .../expectations/tests/anon-fields-prefix.rs | 3 +++ .../tests/expectations/tests/anon_enum.rs | 1 + .../expectations/tests/anon_enum_trait.rs | 1 + .../tests/anon_struct_in_union.rs | 3 +++ .../tests/expectations/tests/anon_union.rs | 2 ++ .../tests/array-of-zero-sized-types.rs | 2 ++ .../attribute_warn_unused_result_pre_1_27.rs | 1 + .../tests/expectations/tests/auto.rs | 1 + .../expectations/tests/base-to-derived.rs | 1 + .../tests/bitfield-32bit-overflow.rs | 1 + .../expectations/tests/bitfield-enum-basic.rs | 1 + .../expectations/tests/bitfield-large.rs | 2 ++ .../expectations/tests/bitfield-linux-32.rs | 1 + .../tests/bitfield-method-same-name.rs | 1 + .../expectations/tests/bitfield_align.rs | 6 +++++ .../expectations/tests/bitfield_align_2.rs | 1 + .../tests/bitfield_large_overflow.rs | 1 + .../tests/bitfield_method_mangling.rs | 1 + .../tests/bitfield_pragma_packed.rs | 3 +++ .../tests/blocklist-and-impl-debug.rs | 1 + .../expectations/tests/blocklist-file.rs | 2 ++ .../expectations/tests/blocklist-function.rs | 1 + .../expectations/tests/blocklist-methods.rs | 1 + .../tests/blocklist_bitfield_unit.rs | 1 + .../expectations/tests/blocks-signature.rs | 1 + .../tests/expectations/tests/blocks.rs | 1 + .../tests/expectations/tests/bug-1529681.rs | 1 + .../expectations/tests/c-empty-layout.rs | 1 + .../tests/expectations/tests/c_naming.rs | 2 ++ .../expectations/tests/call-conv-field.rs | 1 + .../expectations/tests/canonical-types.rs | 7 +++++ .../canonical_path_without_namespacing.rs | 1 + .../tests/expectations/tests/char.rs | 1 + .../tests/expectations/tests/class_nested.rs | 5 ++++ .../expectations/tests/class_no_members.rs | 3 +++ .../tests/expectations/tests/class_static.rs | 1 + .../expectations/tests/class_static_const.rs | 1 + .../tests/expectations/tests/class_use_as.rs | 2 ++ .../expectations/tests/class_with_dtor.rs | 2 ++ .../tests/class_with_inner_struct.rs | 11 ++++++++ .../expectations/tests/class_with_typedef.rs | 2 ++ .../expectations/tests/comment-indent.rs | 5 ++++ .../tests/expectations/tests/complex.rs | 4 +++ .../expectations/tests/const-const-mut-ptr.rs | 1 + .../expectations/tests/const_array_typedef.rs | 1 + .../tests/expectations/tests/const_bool.rs | 1 + .../expectations/tests/const_enum_unnamed.rs | 1 + .../tests/constified-enum-module-overflow.rs | 3 +++ .../expectations/tests/constify-all-enums.rs | 1 + .../tests/constify-module-enums-basic.rs | 1 + .../tests/constify-module-enums-namespace.rs | 1 + .../constify-module-enums-shadow-name.rs | 1 + .../constify-module-enums-simple-alias.rs | 1 + ...onstify-module-enums-simple-nonamespace.rs | 1 + .../tests/constify-module-enums-types.rs | 3 +++ .../expectations/tests/constructor-tp.rs | 1 + .../tests/expectations/tests/constructors.rs | 2 ++ .../tests/contains-vs-inherits-zero-sized.rs | 3 +++ .../expectations/tests/convert-floats.rs | 1 + .../expectations/tests/cpp-empty-layout.rs | 1 + .../tests/expectations/tests/crtp.rs | 4 +++ .../expectations/tests/ctypes-prefix-path.rs | 1 + .../tests/default-template-parameter.rs | 1 + .../expectations/tests/deleted-function.rs | 3 +++ .../expectations/tests/derive-custom-cli.rs | 3 +++ .../tests/derive-debug-mangle-name.rs | 2 ++ .../tests/derive-default-and-blocklist.rs | 1 + .../tests/expectations/tests/derive-fn-ptr.rs | 2 ++ .../tests/derive-hash-and-blocklist.rs | 1 + .../tests/derive-hash-blocklisting.rs | 2 ++ ...rive-hash-struct-with-anon-struct-float.rs | 2 ++ .../derive-hash-struct-with-float-array.rs | 1 + ...erive-hash-struct-with-incomplete-array.rs | 3 +++ .../tests/derive-hash-struct-with-pointer.rs | 4 +++ .../tests/derive-hash-template-inst-float.rs | 4 +++ .../tests/derive-partialeq-and-blocklist.rs | 1 + .../tests/derive-partialeq-anonfield.rs | 2 ++ .../tests/derive-partialeq-pointer.rs | 4 +++ .../tests/derive-partialeq-union.rs | 1 + .../tests/disable-nested-struct-naming.rs | 8 ++++++ .../tests/disable-untagged-union.rs | 1 + .../expectations/tests/do-not-derive-copy.rs | 1 + .../tests/expectations/tests/doggo-or-null.rs | 3 +++ .../tests/duplicated-definition-count.rs | 1 + .../duplicated-namespaces-definitions.rs | 2 ++ .../tests/dynamic_loading_with_blocklist.rs | 1 + .../tests/dynamic_loading_with_class.rs | 1 + .../tests/enum-default-bitfield.rs | 1 + .../expectations/tests/enum-default-consts.rs | 1 + .../expectations/tests/enum-default-module.rs | 1 + .../expectations/tests/enum-default-rust.rs | 1 + .../expectations/tests/enum-no-debug-rust.rs | 1 + .../tests/expectations/tests/enum.rs | 1 + .../tests/enum_and_vtable_mangling.rs | 1 + .../expectations/tests/explicit-padding.rs | 2 ++ .../tests/field-visibility-callback.rs | 1 + .../expectations/tests/field-visibility.rs | 2 ++ .../tests/expectations/tests/flexarray.rs | 5 ++++ .../tests/expectations/tests/float16.rs | 2 ++ .../tests/forward-declaration-autoptr.rs | 2 ++ .../tests/forward_declared_complex_types.rs | 2 ++ .../tests/forward_declared_struct.rs | 2 ++ .../expectations/tests/func_ptr_in_struct.rs | 1 + .../tests/func_return_must_use.rs | 2 ++ .../tests/gen-constructors-neg.rs | 1 + .../expectations/tests/gen-constructors.rs | 1 + .../expectations/tests/gen-destructors-neg.rs | 1 + .../expectations/tests/gen-destructors.rs | 1 + .../expectations/tests/generate-inline.rs | 1 + .../tests/incomplete-array-padding.rs | 1 + ...from-template-instantiation-with-vtable.rs | 8 ++++++ .../tests/inherit_multiple_interfaces.rs | 3 +++ .../expectations/tests/inherit_typedef.rs | 2 ++ .../expectations/tests/inline_namespace.rs | 1 + .../tests/inline_namespace_conservative.rs | 1 + .../tests/expectations/tests/inner_const.rs | 1 + .../expectations/tests/inner_template_self.rs | 2 ++ .../tests/expectations/tests/issue-1034.rs | 1 + .../issue-1076-unnamed-bitfield-alignment.rs | 1 + .../tests/issue-1118-using-forward-decl.rs | 4 +++ .../tests/issue-1197-pure-virtual-stuff.rs | 1 + .../tests/issue-1216-variadic-member.rs | 1 + .../tests/expectations/tests/issue-1281.rs | 3 +++ .../tests/expectations/tests/issue-1285.rs | 2 ++ .../tests/issue-1382-rust-primitive-types.rs | 1 + .../tests/expectations/tests/issue-1443.rs | 4 +++ .../tests/expectations/tests/issue-1454.rs | 1 + .../tests/expectations/tests/issue-1498.rs | 2 ++ .../tests/expectations/tests/issue-1947.rs | 1 + .../tests/issue-1977-larger-arrays.rs | 1 + .../tests/expectations/tests/issue-1995.rs | 1 + .../tests/expectations/tests/issue-2019.rs | 2 ++ .../tests/expectations/tests/issue-2556.rs | 1 + .../tests/expectations/tests/issue-2695.rs | 1 + .../tests/expectations/tests/issue-410.rs | 1 + .../tests/expectations/tests/issue-447.rs | 2 ++ .../tests/expectations/tests/issue-537.rs | 4 +++ ...ate-params-causing-layout-test-failures.rs | 2 ++ .../tests/issue-573-layout-test-failures.rs | 2 ++ .../issue-574-assertion-failure-in-codegen.rs | 2 ++ ...issue-584-stylo-template-analysis-panic.rs | 4 +++ .../tests/issue-639-typedef-anon-field.rs | 4 +++ .../tests/issue-643-inner-struct.rs | 3 +++ .../tests/expectations/tests/issue-674-1.rs | 1 + .../tests/expectations/tests/issue-674-2.rs | 3 +++ .../tests/expectations/tests/issue-674-3.rs | 2 ++ .../issue-691-template-parameter-virtual.rs | 3 +++ .../tests/issue-739-pointer-wide-bitfield.rs | 1 + .../tests/issue-769-bad-instantiation-test.rs | 2 ++ .../tests/issue-801-opaque-sloppiness.rs | 2 ++ ...07-opaque-types-methods-being-generated.rs | 5 ++++ .../tests/expectations/tests/issue-816.rs | 1 + ...26-generating-methods-when-asked-not-to.rs | 1 + .../tests/expectations/tests/issue-834.rs | 1 + .../tests/issue-888-enum-var-decl-jump.rs | 1 + .../issue-944-derive-copy-and-blocklisting.rs | 1 + .../tests/expectations/tests/issue-946.rs | 1 + .../tests/expectations/tests/issue_311.rs | 2 ++ .../expectations/tests/jsval_layout_opaque.rs | 5 ++++ .../tests/expectations/tests/layout_align.rs | 2 ++ .../tests/expectations/tests/layout_arp.rs | 3 +++ .../tests/layout_cmdline_token.rs | 4 +++ .../tests/expectations/tests/layout_mbuf.rs | 13 ++++++++++ .../constified-enum-module-overflow.rs | 2 ++ .../libclang-9/ptr32-has-different-size.rs | 1 + .../tests/libclang-9/struct_typedef_ns.rs | 2 ++ .../expectations/tests/mangling-linux32.rs | 1 + .../expectations/tests/mangling-linux64.rs | 1 + .../expectations/tests/mangling-macos.rs | 1 + .../expectations/tests/mangling-win32.rs | 1 + .../expectations/tests/mangling-win64.rs | 1 + .../expectations/tests/merge-extern-blocks.rs | 2 ++ .../expectations/tests/method-mangling.rs | 1 + .../expectations/tests/module-allowlisted.rs | 1 + .../tests/expectations/tests/msvc-no-usr.rs | 1 + .../multiple-inherit-empty-correct-layout.rs | 3 +++ .../tests/expectations/tests/mutable.rs | 3 +++ .../tests/expectations/tests/namespace.rs | 1 + .../tests/expectations/tests/nested.rs | 4 +++ .../tests/expectations/tests/nested_vtable.rs | 3 +++ .../tests/nested_within_namespace.rs | 3 +++ .../tests/expectations/tests/no-comments.rs | 1 + .../expectations/tests/no-derive-debug.rs | 1 + .../expectations/tests/no-derive-default.rs | 1 + .../expectations/tests/no-hash-allowlisted.rs | 1 + .../expectations/tests/no-hash-opaque.rs | 1 + .../tests/no-partialeq-allowlisted.rs | 1 + .../expectations/tests/no-partialeq-opaque.rs | 1 + .../tests/no-recursive-allowlisting.rs | 1 + .../tests/expectations/tests/no-std.rs | 1 + .../expectations/tests/no_copy_allowlisted.rs | 1 + .../expectations/tests/no_copy_opaque.rs | 1 + .../tests/no_debug_allowlisted.rs | 1 + .../expectations/tests/no_debug_opaque.rs | 1 + .../tests/no_default_allowlisted.rs | 1 + .../expectations/tests/no_default_opaque.rs | 1 + .../expectations/tests/no_size_t_is_usize.rs | 1 + .../expectations/tests/non-type-params.rs | 1 + .../expectations/tests/objc_interface_type.rs | 1 + .../expectations/tests/only_bitfields.rs | 1 + .../tests/opaque-template-inst-member-2.rs | 2 ++ ...paque-template-instantiation-namespaced.rs | 5 ++++ .../tests/opaque-template-instantiation.rs | 3 +++ .../expectations/tests/opaque-tracing.rs | 1 + .../expectations/tests/opaque_in_struct.rs | 2 ++ .../expectations/tests/opaque_pointer.rs | 2 ++ .../expectations/tests/packed-bitfield.rs | 1 + .../tests/packed-n-with-padding.rs | 1 + .../tests/expectations/tests/parm-union.rs | 1 + .../partial-specialization-and-inheritance.rs | 1 + .../tests/expectations/tests/private.rs | 3 +++ .../expectations/tests/private_fields.rs | 13 ++++++++++ .../tests/ptr32-has-different-size.rs | 1 + .../tests/expectations/tests/public-dtor.rs | 2 ++ .../tests/redundant-packed-and-align.rs | 6 +++++ .../expectations/tests/ref_argument_array.rs | 1 + .../tests/reparented_replacement.rs | 1 + .../tests/expectations/tests/replace_use.rs | 2 ++ ...ame_struct_name_in_different_namespaces.rs | 1 + .../tests/sentry-defined-multiple-times.rs | 12 +++++++++ .../expectations/tests/size_t_template.rs | 1 + .../tests/expectations/tests/sorted_items.rs | 4 +++ .../expectations/tests/stdint_typedef.rs | 1 + ...ruct_containing_forward_declared_struct.rs | 2 ++ .../expectations/tests/struct_typedef.rs | 2 ++ .../expectations/tests/struct_typedef_ns.rs | 2 ++ .../tests/struct_with_anon_struct.rs | 2 ++ .../tests/struct_with_anon_struct_array.rs | 3 +++ .../tests/struct_with_anon_struct_pointer.rs | 2 ++ .../tests/struct_with_anon_union.rs | 2 ++ .../tests/struct_with_anon_unnamed_struct.rs | 2 ++ .../tests/struct_with_anon_unnamed_union.rs | 2 ++ .../tests/struct_with_bitfields.rs | 1 + .../expectations/tests/struct_with_nesting.rs | 4 +++ .../expectations/tests/struct_with_packing.rs | 1 + .../expectations/tests/struct_with_struct.rs | 2 ++ .../tests/expectations/tests/template.rs | 26 +++++++++++++++++++ ...mplate_instantiation_with_fn_local_type.rs | 5 ++++ .../test_mixed_header_and_header_contents.rs | 1 + .../test_multiple_header_calls_in_builder.rs | 1 + .../tests/expectations/tests/timex.rs | 2 ++ ...type-referenced-by-allowlisted-function.rs | 1 + .../tests/type_alias_template_specialized.rs | 2 ++ .../tests/typedef-pointer-overlap.rs | 3 +++ .../tests/expectations/tests/typeref.rs | 5 ++++ .../tests/expectations/tests/underscore.rs | 1 + .../tests/expectations/tests/union-in-ns.rs | 1 + .../expectations/tests/union_bitfield.rs | 2 ++ .../tests/expectations/tests/union_dtor.rs | 1 + .../tests/expectations/tests/union_fields.rs | 1 + .../tests/union_with_anon_struct.rs | 2 ++ .../tests/union_with_anon_struct_bitfield.rs | 2 ++ .../tests/union_with_anon_union.rs | 2 ++ .../tests/union_with_anon_unnamed_struct.rs | 2 ++ .../tests/union_with_anon_unnamed_union.rs | 2 ++ .../tests/union_with_big_member.rs | 3 +++ .../expectations/tests/union_with_nesting.rs | 4 +++ .../tests/union_with_non_copy_member.rs | 4 +++ .../tests/expectations/tests/unknown_attr.rs | 1 + .../expectations/tests/unsorted-items.rs | 2 ++ .../tests/expectations/tests/use-core.rs | 2 ++ .../tests/expectations/tests/var-tracing.rs | 2 ++ .../expectations/tests/variadic-method.rs | 1 + .../tests/expectations/tests/vector.rs | 1 + .../tests/expectations/tests/virtual_dtor.rs | 1 + .../expectations/tests/virtual_interface.rs | 4 +++ .../expectations/tests/virtual_overloaded.rs | 1 + .../tests/vtable_recursive_sig.rs | 2 ++ .../tests/wasm-constructor-returns.rs | 1 + .../expectations/tests/weird_bitfields.rs | 1 + .../expectations/tests/what_is_going_on.rs | 1 + .../tests/win32-thiscall_nightly.rs | 1 + .../tests/zero-size-array-align.rs | 1 + .../expectations/tests/zero-sized-array.rs | 5 ++++ bindgen/codegen/mod.rs | 2 ++ 286 files changed, 610 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d80fa4fa81..9bcb0eec6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -212,6 +212,7 @@ ## Changed ## Removed ## Fixed +- Fix regression where the `const` layout tests were triggering the `unnecessary_operation` and `identity_op` clippy warnings. ## Security # 0.70.0 (2024-08-16) diff --git a/bindgen-tests/tests/expectations/tests/16-byte-alignment.rs b/bindgen-tests/tests/expectations/tests/16-byte-alignment.rs index 8eb78eaf6c..c55d0b075b 100644 --- a/bindgen-tests/tests/expectations/tests/16-byte-alignment.rs +++ b/bindgen-tests/tests/expectations/tests/16-byte-alignment.rs @@ -18,6 +18,7 @@ pub struct rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 { pub dport: u16, pub sport: u16, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1", @@ -34,6 +35,7 @@ const _: () = { ][::std::mem::offset_of!(rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1, sport) - 2usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of rte_ipv4_tuple__bindgen_ty_1", @@ -54,6 +56,7 @@ impl Default for rte_ipv4_tuple__bindgen_ty_1 { } } } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of rte_ipv4_tuple"][::std::mem::size_of::() - 12usize]; ["Alignment of rte_ipv4_tuple"][::std::mem::align_of::() - 4usize]; @@ -92,6 +95,7 @@ pub struct rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 { pub dport: u16, pub sport: u16, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1", @@ -108,6 +112,7 @@ const _: () = { ][::std::mem::offset_of!(rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1, sport) - 2usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of rte_ipv6_tuple__bindgen_ty_1", @@ -128,6 +133,7 @@ impl Default for rte_ipv6_tuple__bindgen_ty_1 { } } } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of rte_ipv6_tuple"][::std::mem::size_of::() - 36usize]; ["Alignment of rte_ipv6_tuple"][::std::mem::align_of::() - 4usize]; @@ -154,6 +160,7 @@ pub union rte_thash_tuple { pub v4: rte_ipv4_tuple, pub v6: rte_ipv6_tuple, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of rte_thash_tuple"][::std::mem::size_of::() - 48usize]; [ diff --git a/bindgen-tests/tests/expectations/tests/accessors.rs b/bindgen-tests/tests/expectations/tests/accessors.rs index 0bd4d8169d..586edf2d79 100644 --- a/bindgen-tests/tests/expectations/tests/accessors.rs +++ b/bindgen-tests/tests/expectations/tests/accessors.rs @@ -10,6 +10,7 @@ pub struct SomeAccessors { ///

pub mImmutableAccessor: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of SomeAccessors"][::std::mem::size_of::() - 16usize]; ["Alignment of SomeAccessors"][::std::mem::align_of::() - 4usize]; @@ -55,6 +56,7 @@ pub struct AllAccessors { pub mBothAccessors: ::std::os::raw::c_int, pub mAlsoBothAccessors: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of AllAccessors"][::std::mem::size_of::() - 8usize]; ["Alignment of AllAccessors"][::std::mem::align_of::() - 4usize]; @@ -90,6 +92,7 @@ pub struct AllUnsafeAccessors { pub mBothAccessors: ::std::os::raw::c_int, pub mAlsoBothAccessors: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of AllUnsafeAccessors"][::std::mem::size_of::() - 8usize]; [ @@ -132,6 +135,7 @@ pub struct ContradictAccessors { ///
pub mImmutableAccessor: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of ContradictAccessors", @@ -180,6 +184,7 @@ impl ContradictAccessors { pub struct Replaced { pub mAccessor: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Replaced"][::std::mem::size_of::() - 4usize]; ["Alignment of Replaced"][::std::mem::align_of::() - 4usize]; @@ -203,6 +208,7 @@ impl Replaced { pub struct Wrapper { pub mReplaced: Replaced, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Wrapper"][::std::mem::size_of::() - 4usize]; ["Alignment of Wrapper"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/allowlist-file.rs b/bindgen-tests/tests/expectations/tests/allowlist-file.rs index cb2aa01c59..a0053653f3 100644 --- a/bindgen-tests/tests/expectations/tests/allowlist-file.rs +++ b/bindgen-tests/tests/expectations/tests/allowlist-file.rs @@ -12,6 +12,7 @@ extern "C" { pub struct someClass { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of someClass"][::std::mem::size_of::() - 1usize]; ["Alignment of someClass"][::std::mem::align_of::() - 1usize]; @@ -38,6 +39,7 @@ extern "C" { pub struct StructWithAllowlistedDefinition { pub other: *mut StructWithAllowlistedFwdDecl, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of StructWithAllowlistedDefinition", @@ -63,6 +65,7 @@ impl Default for StructWithAllowlistedDefinition { pub struct StructWithAllowlistedFwdDecl { pub b: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of StructWithAllowlistedFwdDecl", @@ -79,6 +82,7 @@ const _: () = { pub struct AllowlistMe { pub foo: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of AllowlistMe"][::std::mem::size_of::() - 4usize]; ["Alignment of AllowlistMe"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/allowlist-namespaces-basic.rs b/bindgen-tests/tests/expectations/tests/allowlist-namespaces-basic.rs index be6fac2117..151d03f4a4 100644 --- a/bindgen-tests/tests/expectations/tests/allowlist-namespaces-basic.rs +++ b/bindgen-tests/tests/expectations/tests/allowlist-namespaces-basic.rs @@ -14,6 +14,7 @@ pub mod root { pub struct Helper { pub _address: u8, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Helper"][::std::mem::size_of::() - 1usize]; ["Alignment of Helper"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/allowlist-namespaces.rs b/bindgen-tests/tests/expectations/tests/allowlist-namespaces.rs index 1c7078504f..563c97ca1d 100644 --- a/bindgen-tests/tests/expectations/tests/allowlist-namespaces.rs +++ b/bindgen-tests/tests/expectations/tests/allowlist-namespaces.rs @@ -14,6 +14,7 @@ pub mod root { pub struct Helper { pub _address: u8, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Helper"][::std::mem::size_of::() - 1usize]; ["Alignment of Helper"][::std::mem::align_of::() - 1usize]; @@ -24,6 +25,7 @@ pub mod root { pub struct Test { pub helper: root::outer::inner::Helper, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Test"][::std::mem::size_of::() - 1usize]; ["Alignment of Test"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/allowlist_item.rs b/bindgen-tests/tests/expectations/tests/allowlist_item.rs index f816f5170b..e5aa4b2172 100644 --- a/bindgen-tests/tests/expectations/tests/allowlist_item.rs +++ b/bindgen-tests/tests/expectations/tests/allowlist_item.rs @@ -5,6 +5,7 @@ pub const FooDefault: u32 = 0; pub struct Foo { pub field: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Foo"][::std::mem::size_of::() - 4usize]; ["Alignment of Foo"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/allowlisted-item-references-no-hash.rs b/bindgen-tests/tests/expectations/tests/allowlisted-item-references-no-hash.rs index ce1d463f57..6c1d13a837 100644 --- a/bindgen-tests/tests/expectations/tests/allowlisted-item-references-no-hash.rs +++ b/bindgen-tests/tests/expectations/tests/allowlisted-item-references-no-hash.rs @@ -4,6 +4,7 @@ pub struct NoHash { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of NoHash"][::std::mem::size_of::() - 1usize]; ["Alignment of NoHash"][::std::mem::align_of::() - 1usize]; @@ -13,6 +14,7 @@ const _: () = { pub struct AllowlistMe { pub a: NoHash, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of AllowlistMe"][::std::mem::size_of::() - 1usize]; ["Alignment of AllowlistMe"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/allowlisted-item-references-no-partialeq.rs b/bindgen-tests/tests/expectations/tests/allowlisted-item-references-no-partialeq.rs index 2b699f61db..b969727dbb 100644 --- a/bindgen-tests/tests/expectations/tests/allowlisted-item-references-no-partialeq.rs +++ b/bindgen-tests/tests/expectations/tests/allowlisted-item-references-no-partialeq.rs @@ -4,6 +4,7 @@ pub struct NoPartialEq { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of NoPartialEq"][::std::mem::size_of::() - 1usize]; ["Alignment of NoPartialEq"][::std::mem::align_of::() - 1usize]; @@ -13,6 +14,7 @@ const _: () = { pub struct AllowlistMe { pub a: NoPartialEq, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of AllowlistMe"][::std::mem::size_of::() - 1usize]; ["Alignment of AllowlistMe"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/allowlisted_item_references_no_copy.rs b/bindgen-tests/tests/expectations/tests/allowlisted_item_references_no_copy.rs index cbcce1ef44..8c671b4e84 100644 --- a/bindgen-tests/tests/expectations/tests/allowlisted_item_references_no_copy.rs +++ b/bindgen-tests/tests/expectations/tests/allowlisted_item_references_no_copy.rs @@ -4,6 +4,7 @@ pub struct NoCopy { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of NoCopy"][::std::mem::size_of::() - 1usize]; ["Alignment of NoCopy"][::std::mem::align_of::() - 1usize]; @@ -13,6 +14,7 @@ const _: () = { pub struct AllowlistMe { pub a: NoCopy, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of AllowlistMe"][::std::mem::size_of::() - 1usize]; ["Alignment of AllowlistMe"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/annotation_hide.rs b/bindgen-tests/tests/expectations/tests/annotation_hide.rs index 0343c92272..e79c88214d 100644 --- a/bindgen-tests/tests/expectations/tests/annotation_hide.rs +++ b/bindgen-tests/tests/expectations/tests/annotation_hide.rs @@ -6,6 +6,7 @@ pub struct D { pub _bindgen_opaque_blob: u32, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of D"][::std::mem::size_of::() - 4usize]; ["Alignment of D"][::std::mem::align_of::() - 4usize]; @@ -15,6 +16,7 @@ const _: () = { pub struct NotAnnotated { pub f: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of NotAnnotated"][::std::mem::size_of::() - 4usize]; ["Alignment of NotAnnotated"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/anon-fields-prefix.rs b/bindgen-tests/tests/expectations/tests/anon-fields-prefix.rs index c408a08b0c..2b96804c9b 100644 --- a/bindgen-tests/tests/expectations/tests/anon-fields-prefix.rs +++ b/bindgen-tests/tests/expectations/tests/anon-fields-prefix.rs @@ -13,6 +13,7 @@ pub struct color__bindgen_ty_1 { pub g: ::std::os::raw::c_uchar, pub b: ::std::os::raw::c_uchar, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of color__bindgen_ty_1", @@ -37,6 +38,7 @@ pub struct color__bindgen_ty_2 { pub u: ::std::os::raw::c_uchar, pub v: ::std::os::raw::c_uchar, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of color__bindgen_ty_2", @@ -54,6 +56,7 @@ const _: () = { "Offset of field: color__bindgen_ty_2::v", ][::std::mem::offset_of!(color__bindgen_ty_2, v) - 2usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of color"][::std::mem::size_of::() - 3usize]; ["Alignment of color"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/anon_enum.rs b/bindgen-tests/tests/expectations/tests/anon_enum.rs index 5324e499e4..c3790a2a24 100644 --- a/bindgen-tests/tests/expectations/tests/anon_enum.rs +++ b/bindgen-tests/tests/expectations/tests/anon_enum.rs @@ -11,6 +11,7 @@ pub const Test_T_NONE: Test__bindgen_ty_1 = Test__bindgen_ty_1::T_NONE; pub enum Test__bindgen_ty_1 { T_NONE = 0, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Test"][::std::mem::size_of::() - 8usize]; ["Alignment of Test"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/anon_enum_trait.rs b/bindgen-tests/tests/expectations/tests/anon_enum_trait.rs index 97d97d6afd..cfd4d03200 100644 --- a/bindgen-tests/tests/expectations/tests/anon_enum_trait.rs +++ b/bindgen-tests/tests/expectations/tests/anon_enum_trait.rs @@ -30,6 +30,7 @@ pub const Foo_Baz: Foo__bindgen_ty_1 = Foo__bindgen_ty_1::Bar; pub enum Foo__bindgen_ty_1 { Bar = 0, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Foo"][::std::mem::size_of::() - 1usize]; ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/anon_struct_in_union.rs b/bindgen-tests/tests/expectations/tests/anon_struct_in_union.rs index dc61f38911..dceca1adf3 100644 --- a/bindgen-tests/tests/expectations/tests/anon_struct_in_union.rs +++ b/bindgen-tests/tests/expectations/tests/anon_struct_in_union.rs @@ -14,6 +14,7 @@ pub union s__bindgen_ty_1 { pub struct s__bindgen_ty_1_inner { pub b: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of s__bindgen_ty_1_inner", @@ -25,6 +26,7 @@ const _: () = { "Offset of field: s__bindgen_ty_1_inner::b", ][::std::mem::offset_of!(s__bindgen_ty_1_inner, b) - 0usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of s__bindgen_ty_1"][::std::mem::size_of::() - 4usize]; ["Alignment of s__bindgen_ty_1"][::std::mem::align_of::() - 4usize]; @@ -41,6 +43,7 @@ impl Default for s__bindgen_ty_1 { } } } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of s"][::std::mem::size_of::() - 4usize]; ["Alignment of s"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/anon_union.rs b/bindgen-tests/tests/expectations/tests/anon_union.rs index caf5f93ece..d9bf3cf183 100644 --- a/bindgen-tests/tests/expectations/tests/anon_union.rs +++ b/bindgen-tests/tests/expectations/tests/anon_union.rs @@ -51,6 +51,7 @@ impl Default for TErrorResult { pub struct ErrorResult { pub _base: TErrorResult, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of ErrorResult"][::std::mem::size_of::() - 24usize]; ["Alignment of ErrorResult"][::std::mem::align_of::() - 8usize]; @@ -64,6 +65,7 @@ impl Default for ErrorResult { } } } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: TErrorResult_open0_int_close0", diff --git a/bindgen-tests/tests/expectations/tests/array-of-zero-sized-types.rs b/bindgen-tests/tests/expectations/tests/array-of-zero-sized-types.rs index 3477e83dc2..4630abd275 100644 --- a/bindgen-tests/tests/expectations/tests/array-of-zero-sized-types.rs +++ b/bindgen-tests/tests/expectations/tests/array-of-zero-sized-types.rs @@ -5,6 +5,7 @@ pub struct Empty { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Empty"][::std::mem::size_of::() - 1usize]; ["Alignment of Empty"][::std::mem::align_of::() - 1usize]; @@ -16,6 +17,7 @@ const _: () = { pub struct HasArrayOfEmpty { pub empties: [Empty; 10usize], } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of HasArrayOfEmpty"][::std::mem::size_of::() - 10usize]; ["Alignment of HasArrayOfEmpty"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_pre_1_27.rs b/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_pre_1_27.rs index 92f6eaf97d..f545f9e6bb 100644 --- a/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_pre_1_27.rs +++ b/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_pre_1_27.rs @@ -4,6 +4,7 @@ pub struct Foo { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Foo"][::std::mem::size_of::() - 1usize]; ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/auto.rs b/bindgen-tests/tests/expectations/tests/auto.rs index 2ee0ebbaff..0173f0409f 100644 --- a/bindgen-tests/tests/expectations/tests/auto.rs +++ b/bindgen-tests/tests/expectations/tests/auto.rs @@ -5,6 +5,7 @@ pub struct Foo { pub _address: u8, } pub const Foo_kFoo: bool = true; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Foo"][::std::mem::size_of::() - 1usize]; ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/base-to-derived.rs b/bindgen-tests/tests/expectations/tests/base-to-derived.rs index 26d8d799ba..22ef4fdb08 100644 --- a/bindgen-tests/tests/expectations/tests/base-to-derived.rs +++ b/bindgen-tests/tests/expectations/tests/base-to-derived.rs @@ -4,6 +4,7 @@ pub struct false_type { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of false_type"][::std::mem::size_of::() - 1usize]; ["Alignment of false_type"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/bitfield-32bit-overflow.rs b/bindgen-tests/tests/expectations/tests/bitfield-32bit-overflow.rs index 9e365e48ef..475cbae837 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-32bit-overflow.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-32bit-overflow.rs @@ -89,6 +89,7 @@ pub struct MuchBitfield { pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 5usize]>, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of MuchBitfield"][::std::mem::size_of::() - 5usize]; ["Alignment of MuchBitfield"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/bitfield-enum-basic.rs b/bindgen-tests/tests/expectations/tests/bitfield-enum-basic.rs index 9775f07c60..adc4690c86 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-enum-basic.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-enum-basic.rs @@ -148,6 +148,7 @@ impl ::std::ops::BitAndAssign for Dummy__bindgen_ty_1 { #[repr(transparent)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Dummy__bindgen_ty_1(pub ::std::os::raw::c_uint); +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Dummy"][::std::mem::size_of::() - 1usize]; ["Alignment of Dummy"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/bitfield-large.rs b/bindgen-tests/tests/expectations/tests/bitfield-large.rs index 44f9e5b765..27118083d5 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-large.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-large.rs @@ -90,6 +90,7 @@ pub struct HasBigBitfield { pub _bitfield_align_1: [u64; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 16usize]>, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of HasBigBitfield"][::std::mem::size_of::() - 16usize]; ["Alignment of HasBigBitfield"][::std::mem::align_of::() - 16usize]; @@ -128,6 +129,7 @@ pub struct HasTwoBigBitfields { pub _bitfield_align_1: [u64; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 16usize]>, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of HasTwoBigBitfields", diff --git a/bindgen-tests/tests/expectations/tests/bitfield-linux-32.rs b/bindgen-tests/tests/expectations/tests/bitfield-linux-32.rs index ffd5e61cb5..9e69bf9de5 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-linux-32.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-linux-32.rs @@ -90,6 +90,7 @@ pub struct Test { pub _bitfield_align_1: [u64; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 8usize]>, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Test"][::std::mem::size_of::() - 16usize]; ["Alignment of Test"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs b/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs index ea8618280f..dd4286496c 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs @@ -89,6 +89,7 @@ pub struct Foo { pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Foo"][::std::mem::size_of::() - 1usize]; ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/bitfield_align.rs b/bindgen-tests/tests/expectations/tests/bitfield_align.rs index dc0cc52183..828f176de9 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_align.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_align.rs @@ -92,6 +92,7 @@ pub struct A { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 2usize]>, pub y: ::std::os::raw::c_uchar, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of A"][::std::mem::size_of::
() - 4usize]; ["Alignment of A"][::std::mem::align_of::() - 4usize]; @@ -322,6 +323,7 @@ pub struct B { pub _bitfield_align_1: [u32; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of B"][::std::mem::size_of::() - 4usize]; ["Alignment of B"][::std::mem::align_of::() - 4usize]; @@ -384,6 +386,7 @@ pub struct C { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub baz: ::std::os::raw::c_uint, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of C"][::std::mem::size_of::() - 8usize]; ["Alignment of C"][::std::mem::align_of::() - 4usize]; @@ -448,6 +451,7 @@ pub struct Date1 { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 3usize]>, pub __bindgen_padding_0: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Date1"][::std::mem::size_of::() - 4usize]; ["Alignment of Date1"][::std::mem::align_of::() - 2usize]; @@ -551,6 +555,7 @@ pub struct Date2 { pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Date2"][::std::mem::size_of::() - 4usize]; ["Alignment of Date2"][::std::mem::align_of::() - 2usize]; @@ -676,6 +681,7 @@ pub struct Date3 { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 3usize]>, pub byte: ::std::os::raw::c_uchar, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Date3"][::std::mem::size_of::() - 4usize]; ["Alignment of Date3"][::std::mem::align_of::() - 2usize]; diff --git a/bindgen-tests/tests/expectations/tests/bitfield_align_2.rs b/bindgen-tests/tests/expectations/tests/bitfield_align_2.rs index 4cb0aaa48c..b87af0c99c 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_align_2.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_align_2.rs @@ -98,6 +98,7 @@ pub struct TaggedPtr { pub _bitfield_align_1: [u64; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 8usize]>, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of TaggedPtr"][::std::mem::size_of::() - 8usize]; ["Alignment of TaggedPtr"][::std::mem::align_of::() - 8usize]; diff --git a/bindgen-tests/tests/expectations/tests/bitfield_large_overflow.rs b/bindgen-tests/tests/expectations/tests/bitfield_large_overflow.rs index 3040e3e47c..8967bb9856 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_large_overflow.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_large_overflow.rs @@ -5,6 +5,7 @@ pub struct _bindgen_ty_1 { pub _bindgen_opaque_blob: [u64; 10usize], } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of _bindgen_ty_1"][::std::mem::size_of::<_bindgen_ty_1>() - 80usize]; ["Alignment of _bindgen_ty_1"][::std::mem::align_of::<_bindgen_ty_1>() - 8usize]; diff --git a/bindgen-tests/tests/expectations/tests/bitfield_method_mangling.rs b/bindgen-tests/tests/expectations/tests/bitfield_method_mangling.rs index 19e415e2c6..b6fe8a5257 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_method_mangling.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_method_mangling.rs @@ -89,6 +89,7 @@ pub struct mach_msg_type_descriptor_t { pub _bitfield_align_1: [u32; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of mach_msg_type_descriptor_t", diff --git a/bindgen-tests/tests/expectations/tests/bitfield_pragma_packed.rs b/bindgen-tests/tests/expectations/tests/bitfield_pragma_packed.rs index 54cf2ff1d0..60cf6b8056 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_pragma_packed.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_pragma_packed.rs @@ -89,6 +89,7 @@ pub struct Struct { pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Struct"][::std::mem::size_of::() - 4usize]; ["Alignment of Struct"][::std::mem::align_of::() - 1usize]; @@ -212,6 +213,7 @@ pub struct Inner { pub _bitfield_align_1: [u16; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Inner"][::std::mem::size_of::() - 4usize]; ["Alignment of Inner"][::std::mem::align_of::() - 2usize]; @@ -271,6 +273,7 @@ impl Inner { pub struct Outer { pub inner: Inner, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Outer"][::std::mem::size_of::() - 4usize]; ["Alignment of Outer"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/blocklist-and-impl-debug.rs b/bindgen-tests/tests/expectations/tests/blocklist-and-impl-debug.rs index e77967c930..43e645bfc3 100644 --- a/bindgen-tests/tests/expectations/tests/blocklist-and-impl-debug.rs +++ b/bindgen-tests/tests/expectations/tests/blocklist-and-impl-debug.rs @@ -5,6 +5,7 @@ pub struct BlocklistMe(u8); pub struct ShouldManuallyImplDebug { pub a: BlocklistMe, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of ShouldManuallyImplDebug", diff --git a/bindgen-tests/tests/expectations/tests/blocklist-file.rs b/bindgen-tests/tests/expectations/tests/blocklist-file.rs index 834db1834d..4056ef4d2c 100644 --- a/bindgen-tests/tests/expectations/tests/blocklist-file.rs +++ b/bindgen-tests/tests/expectations/tests/blocklist-file.rs @@ -6,6 +6,7 @@ pub struct SizedIntegers { pub y: u16, pub z: u32, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of SizedIntegers"][::std::mem::size_of::() - 8usize]; ["Alignment of SizedIntegers"][::std::mem::align_of::() - 4usize]; @@ -24,6 +25,7 @@ const _: () = { pub struct StructWithBlocklistedFwdDecl { pub b: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of StructWithBlocklistedFwdDecl", diff --git a/bindgen-tests/tests/expectations/tests/blocklist-function.rs b/bindgen-tests/tests/expectations/tests/blocklist-function.rs index 2d0ab9d573..2e12a01e9e 100644 --- a/bindgen-tests/tests/expectations/tests/blocklist-function.rs +++ b/bindgen-tests/tests/expectations/tests/blocklist-function.rs @@ -20,6 +20,7 @@ pub mod root { pub struct C { pub _address: u8, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of C"][::std::mem::size_of::() - 1usize]; ["Alignment of C"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/blocklist-methods.rs b/bindgen-tests/tests/expectations/tests/blocklist-methods.rs index 835b1fd385..37bb95492d 100644 --- a/bindgen-tests/tests/expectations/tests/blocklist-methods.rs +++ b/bindgen-tests/tests/expectations/tests/blocklist-methods.rs @@ -4,6 +4,7 @@ pub struct Foo { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Foo"][::std::mem::size_of::() - 1usize]; ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/blocklist_bitfield_unit.rs b/bindgen-tests/tests/expectations/tests/blocklist_bitfield_unit.rs index d802e28253..b5737a8d99 100644 --- a/bindgen-tests/tests/expectations/tests/blocklist_bitfield_unit.rs +++ b/bindgen-tests/tests/expectations/tests/blocklist_bitfield_unit.rs @@ -10,6 +10,7 @@ pub struct C { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub baz: ::std::os::raw::c_uint, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of C"][::std::mem::size_of::() - 8usize]; ["Alignment of C"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/blocks-signature.rs b/bindgen-tests/tests/expectations/tests/blocks-signature.rs index be5eed7d19..b1615839ca 100644 --- a/bindgen-tests/tests/expectations/tests/blocks-signature.rs +++ b/bindgen-tests/tests/expectations/tests/blocks-signature.rs @@ -28,6 +28,7 @@ pub struct contains_block_pointers { pub val: contains_block_pointers__bindgen_ty_id_61, pub ptr_val: *mut _bindgen_ty_id_68, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of contains_block_pointers", diff --git a/bindgen-tests/tests/expectations/tests/blocks.rs b/bindgen-tests/tests/expectations/tests/blocks.rs index 1d79678292..ea15d22464 100644 --- a/bindgen-tests/tests/expectations/tests/blocks.rs +++ b/bindgen-tests/tests/expectations/tests/blocks.rs @@ -27,6 +27,7 @@ pub struct contains_block_pointers { pub val: *mut ::std::os::raw::c_void, pub ptr_val: *mut *mut ::std::os::raw::c_void, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of contains_block_pointers", diff --git a/bindgen-tests/tests/expectations/tests/bug-1529681.rs b/bindgen-tests/tests/expectations/tests/bug-1529681.rs index 2681c36faf..bd59c1971f 100644 --- a/bindgen-tests/tests/expectations/tests/bug-1529681.rs +++ b/bindgen-tests/tests/expectations/tests/bug-1529681.rs @@ -4,6 +4,7 @@ pub struct BrowsingContext { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of BrowsingContext"][::std::mem::size_of::() - 1usize]; ["Alignment of BrowsingContext"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/c-empty-layout.rs b/bindgen-tests/tests/expectations/tests/c-empty-layout.rs index e82d70cea1..709a9a59d8 100644 --- a/bindgen-tests/tests/expectations/tests/c-empty-layout.rs +++ b/bindgen-tests/tests/expectations/tests/c-empty-layout.rs @@ -2,6 +2,7 @@ #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo {} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Foo"][::std::mem::size_of::() - 0usize]; ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/c_naming.rs b/bindgen-tests/tests/expectations/tests/c_naming.rs index 83ccbeadcf..502c4486eb 100644 --- a/bindgen-tests/tests/expectations/tests/c_naming.rs +++ b/bindgen-tests/tests/expectations/tests/c_naming.rs @@ -4,6 +4,7 @@ pub struct struct_a { pub a: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of struct_a"][::std::mem::size_of::() - 4usize]; ["Alignment of struct_a"][::std::mem::align_of::() - 4usize]; @@ -16,6 +17,7 @@ pub union union_b { pub a: ::std::os::raw::c_int, pub b: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of union_b"][::std::mem::size_of::() - 4usize]; ["Alignment of union_b"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/call-conv-field.rs b/bindgen-tests/tests/expectations/tests/call-conv-field.rs index 73fc76e208..089b34b134 100644 --- a/bindgen-tests/tests/expectations/tests/call-conv-field.rs +++ b/bindgen-tests/tests/expectations/tests/call-conv-field.rs @@ -10,6 +10,7 @@ pub struct JNINativeInterface_ { >, pub __hack: ::std::os::raw::c_ulonglong, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of JNINativeInterface_", diff --git a/bindgen-tests/tests/expectations/tests/canonical-types.rs b/bindgen-tests/tests/expectations/tests/canonical-types.rs index a6e22c7788..81d2e488a2 100644 --- a/bindgen-tests/tests/expectations/tests/canonical-types.rs +++ b/bindgen-tests/tests/expectations/tests/canonical-types.rs @@ -76,6 +76,7 @@ impl Default for ClassC_ClassCInnerCRTP { pub struct ClassD { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of ClassD"][::std::mem::size_of::() - 1usize]; ["Alignment of ClassD"][::std::mem::align_of::() - 1usize]; @@ -89,6 +90,7 @@ impl Default for ClassD { } } } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: ClassB_open0_ClassD_ClassCInnerCRTP_close0", @@ -102,6 +104,7 @@ const _: () = { pub struct ClassCInnerCRTP { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of ClassCInnerCRTP"][::std::mem::size_of::() - 1usize]; ["Alignment of ClassCInnerCRTP"][::std::mem::align_of::() - 1usize]; @@ -115,6 +118,7 @@ impl Default for ClassCInnerCRTP { } } } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: ClassB_open0_ClassCInnerCRTP_ClassAInner_close0", @@ -128,6 +132,7 @@ const _: () = { pub struct ClassAInner { pub x: *mut ClassCInnerA, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of ClassAInner"][::std::mem::size_of::() - 8usize]; ["Alignment of ClassAInner"][::std::mem::align_of::() - 8usize]; @@ -147,6 +152,7 @@ impl Default for ClassAInner { pub struct ClassCInnerA { pub member: *mut ClassCInnerB, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of ClassCInnerA"][::std::mem::size_of::() - 8usize]; ["Alignment of ClassCInnerA"][::std::mem::align_of::() - 8usize]; @@ -168,6 +174,7 @@ impl Default for ClassCInnerA { pub struct ClassCInnerB { pub cache: *mut ClassCInnerA, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of ClassCInnerB"][::std::mem::size_of::() - 8usize]; ["Alignment of ClassCInnerB"][::std::mem::align_of::() - 8usize]; diff --git a/bindgen-tests/tests/expectations/tests/canonical_path_without_namespacing.rs b/bindgen-tests/tests/expectations/tests/canonical_path_without_namespacing.rs index 6882c57fa4..d07751a8db 100644 --- a/bindgen-tests/tests/expectations/tests/canonical_path_without_namespacing.rs +++ b/bindgen-tests/tests/expectations/tests/canonical_path_without_namespacing.rs @@ -4,6 +4,7 @@ pub struct Bar { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Bar"][::std::mem::size_of::() - 1usize]; ["Alignment of Bar"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/char.rs b/bindgen-tests/tests/expectations/tests/char.rs index 531c70213b..61a81269d7 100644 --- a/bindgen-tests/tests/expectations/tests/char.rs +++ b/bindgen-tests/tests/expectations/tests/char.rs @@ -18,6 +18,7 @@ pub struct Test { pub Ccu: UChar, pub Ccd: SChar, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Test"][::std::mem::size_of::() - 12usize]; ["Alignment of Test"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/class_nested.rs b/bindgen-tests/tests/expectations/tests/class_nested.rs index e3d4c2e65e..881a95fd93 100644 --- a/bindgen-tests/tests/expectations/tests/class_nested.rs +++ b/bindgen-tests/tests/expectations/tests/class_nested.rs @@ -9,6 +9,7 @@ pub struct A { pub struct A_B { pub member_b: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of A_B"][::std::mem::size_of::() - 4usize]; ["Alignment of A_B"][::std::mem::align_of::() - 4usize]; @@ -29,6 +30,7 @@ impl Default for A_D { } } } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of A"][::std::mem::size_of::() - 4usize]; ["Alignment of A"][::std::mem::align_of::() - 4usize]; @@ -39,6 +41,7 @@ const _: () = { pub struct A_C { pub baz: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of A_C"][::std::mem::size_of::() - 4usize]; ["Alignment of A_C"][::std::mem::align_of::() - 4usize]; @@ -47,6 +50,7 @@ const _: () = { extern "C" { pub static mut var: A_B; } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: A_D_open0_int_close0", @@ -63,6 +67,7 @@ extern "C" { pub struct D { pub member: A_B, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of D"][::std::mem::size_of::() - 4usize]; ["Alignment of D"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/class_no_members.rs b/bindgen-tests/tests/expectations/tests/class_no_members.rs index 13e6410c3d..c50da6a02d 100644 --- a/bindgen-tests/tests/expectations/tests/class_no_members.rs +++ b/bindgen-tests/tests/expectations/tests/class_no_members.rs @@ -4,6 +4,7 @@ pub struct whatever { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of whatever"][::std::mem::size_of::() - 1usize]; ["Alignment of whatever"][::std::mem::align_of::() - 1usize]; @@ -13,6 +14,7 @@ const _: () = { pub struct whatever_child { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of whatever_child"][::std::mem::size_of::() - 1usize]; ["Alignment of whatever_child"][::std::mem::align_of::() - 1usize]; @@ -22,6 +24,7 @@ const _: () = { pub struct whatever_child_with_member { pub m_member: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of whatever_child_with_member", diff --git a/bindgen-tests/tests/expectations/tests/class_static.rs b/bindgen-tests/tests/expectations/tests/class_static.rs index a1ded6bf35..c93968fa0c 100644 --- a/bindgen-tests/tests/expectations/tests/class_static.rs +++ b/bindgen-tests/tests/expectations/tests/class_static.rs @@ -12,6 +12,7 @@ extern "C" { #[link_name = "\u{1}_ZN7MyClass26example_check_no_collisionE"] pub static mut MyClass_example_check_no_collision: *const ::std::os::raw::c_int; } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of MyClass"][::std::mem::size_of::() - 1usize]; ["Alignment of MyClass"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/class_static_const.rs b/bindgen-tests/tests/expectations/tests/class_static_const.rs index 68b2a8a45c..d628239c4c 100644 --- a/bindgen-tests/tests/expectations/tests/class_static_const.rs +++ b/bindgen-tests/tests/expectations/tests/class_static_const.rs @@ -7,6 +7,7 @@ pub struct A { pub const A_a: ::std::os::raw::c_int = 0; pub const A_b: i32 = 63; pub const A_c: u32 = 255; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of A"][::std::mem::size_of::() - 1usize]; ["Alignment of A"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/class_use_as.rs b/bindgen-tests/tests/expectations/tests/class_use_as.rs index b91c32c723..ec898ff7eb 100644 --- a/bindgen-tests/tests/expectations/tests/class_use_as.rs +++ b/bindgen-tests/tests/expectations/tests/class_use_as.rs @@ -5,6 +5,7 @@ pub struct whatever { pub replacement: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of whatever"][::std::mem::size_of::() - 4usize]; ["Alignment of whatever"][::std::mem::align_of::() - 4usize]; @@ -17,6 +18,7 @@ const _: () = { pub struct container { pub c: whatever, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of container"][::std::mem::size_of::() - 4usize]; ["Alignment of container"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/class_with_dtor.rs b/bindgen-tests/tests/expectations/tests/class_with_dtor.rs index 01d7399e59..aa99f42468 100644 --- a/bindgen-tests/tests/expectations/tests/class_with_dtor.rs +++ b/bindgen-tests/tests/expectations/tests/class_with_dtor.rs @@ -20,6 +20,7 @@ pub type HandleValue = HandleWithDtor<::std::os::raw::c_int>; pub struct WithoutDtor { pub shouldBeWithDtor: HandleValue, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of WithoutDtor"][::std::mem::size_of::() - 8usize]; ["Alignment of WithoutDtor"][::std::mem::align_of::() - 8usize]; @@ -36,6 +37,7 @@ impl Default for WithoutDtor { } } } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: HandleWithDtor_open0_int_close0", diff --git a/bindgen-tests/tests/expectations/tests/class_with_inner_struct.rs b/bindgen-tests/tests/expectations/tests/class_with_inner_struct.rs index e7483370b4..710026c72f 100644 --- a/bindgen-tests/tests/expectations/tests/class_with_inner_struct.rs +++ b/bindgen-tests/tests/expectations/tests/class_with_inner_struct.rs @@ -12,6 +12,7 @@ pub struct A_Segment { pub begin: ::std::os::raw::c_int, pub end: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of A_Segment"][::std::mem::size_of::() - 8usize]; ["Alignment of A_Segment"][::std::mem::align_of::() - 4usize]; @@ -25,6 +26,7 @@ const _: () = { pub union A__bindgen_ty_1 { pub f: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of A__bindgen_ty_1"][::std::mem::size_of::() - 4usize]; ["Alignment of A__bindgen_ty_1"][::std::mem::align_of::() - 4usize]; @@ -46,6 +48,7 @@ impl Default for A__bindgen_ty_1 { pub union A__bindgen_ty_2 { pub d: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of A__bindgen_ty_2"][::std::mem::size_of::() - 4usize]; ["Alignment of A__bindgen_ty_2"][::std::mem::align_of::() - 4usize]; @@ -62,6 +65,7 @@ impl Default for A__bindgen_ty_2 { } } } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of A"][::std::mem::size_of::() - 12usize]; ["Alignment of A"][::std::mem::align_of::() - 4usize]; @@ -88,6 +92,7 @@ pub struct B_Segment { pub begin: ::std::os::raw::c_int, pub end: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of B_Segment"][::std::mem::size_of::() - 8usize]; ["Alignment of B_Segment"][::std::mem::align_of::() - 4usize]; @@ -96,6 +101,7 @@ const _: () = { ][::std::mem::offset_of!(B_Segment, begin) - 0usize]; ["Offset of field: B_Segment::end"][::std::mem::offset_of!(B_Segment, end) - 4usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of B"][::std::mem::size_of::() - 4usize]; ["Alignment of B"][::std::mem::align_of::() - 4usize]; @@ -129,6 +135,7 @@ pub struct C__bindgen_ty_1__bindgen_ty_1 { pub mX2: f32, pub mY2: f32, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of C__bindgen_ty_1__bindgen_ty_1", @@ -155,6 +162,7 @@ pub struct C__bindgen_ty_1__bindgen_ty_2 { pub mStepSyntax: StepSyntax, pub mSteps: ::std::os::raw::c_uint, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of C__bindgen_ty_1__bindgen_ty_2", @@ -178,6 +186,7 @@ impl Default for C__bindgen_ty_1__bindgen_ty_2 { } } } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of C__bindgen_ty_1"][::std::mem::size_of::() - 16usize]; ["Alignment of C__bindgen_ty_1"][::std::mem::align_of::() - 4usize]; @@ -200,6 +209,7 @@ pub struct C_Segment { pub begin: ::std::os::raw::c_int, pub end: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of C_Segment"][::std::mem::size_of::() - 8usize]; ["Alignment of C_Segment"][::std::mem::align_of::() - 4usize]; @@ -208,6 +218,7 @@ const _: () = { ][::std::mem::offset_of!(C_Segment, begin) - 0usize]; ["Offset of field: C_Segment::end"][::std::mem::offset_of!(C_Segment, end) - 4usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of C"][::std::mem::size_of::() - 20usize]; ["Alignment of C"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/class_with_typedef.rs b/bindgen-tests/tests/expectations/tests/class_with_typedef.rs index 2d078541bf..9a89732036 100644 --- a/bindgen-tests/tests/expectations/tests/class_with_typedef.rs +++ b/bindgen-tests/tests/expectations/tests/class_with_typedef.rs @@ -11,6 +11,7 @@ pub struct C { } pub type C_MyInt = ::std::os::raw::c_int; pub type C_Lookup = *const ::std::os::raw::c_char; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of C"][::std::mem::size_of::() - 72usize]; ["Alignment of C"][::std::mem::align_of::() - 8usize]; @@ -69,6 +70,7 @@ pub struct D { pub _base: C, pub ptr: *mut C_MyInt, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of D"][::std::mem::size_of::() - 80usize]; ["Alignment of D"][::std::mem::align_of::() - 8usize]; diff --git a/bindgen-tests/tests/expectations/tests/comment-indent.rs b/bindgen-tests/tests/expectations/tests/comment-indent.rs index 47e6ebb185..72b167d00c 100644 --- a/bindgen-tests/tests/expectations/tests/comment-indent.rs +++ b/bindgen-tests/tests/expectations/tests/comment-indent.rs @@ -19,10 +19,12 @@ pub mod root { pub struct Foo_Bar { pub _address: u8, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Foo_Bar"][::std::mem::size_of::() - 1usize]; ["Alignment of Foo_Bar"][::std::mem::align_of::() - 1usize]; }; + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Foo"][::std::mem::size_of::() - 1usize]; ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; @@ -44,6 +46,7 @@ pub mod root { +------+ +-------+*/ pub member: ::std::os::raw::c_int, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Baz"][::std::mem::size_of::() - 4usize]; ["Alignment of Baz"][::std::mem::align_of::() - 4usize]; @@ -59,6 +62,7 @@ pub mod root { pub struct InInlineNS { pub _address: u8, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of InInlineNS"][::std::mem::size_of::() - 1usize]; ["Alignment of InInlineNS"][::std::mem::align_of::() - 1usize]; @@ -68,6 +72,7 @@ pub mod root { pub struct Bazz { pub _address: u8, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Bazz"][::std::mem::size_of::() - 1usize]; ["Alignment of Bazz"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/complex.rs b/bindgen-tests/tests/expectations/tests/complex.rs index b3e165ae0e..233b86ea36 100644 --- a/bindgen-tests/tests/expectations/tests/complex.rs +++ b/bindgen-tests/tests/expectations/tests/complex.rs @@ -10,6 +10,7 @@ pub struct __BindgenComplex { pub struct TestDouble { pub mMember: __BindgenComplex, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of TestDouble"][::std::mem::size_of::() - 16usize]; ["Alignment of TestDouble"][::std::mem::align_of::() - 8usize]; @@ -22,6 +23,7 @@ const _: () = { pub struct TestDoublePtr { pub mMember: *mut __BindgenComplex, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of TestDoublePtr"][::std::mem::size_of::() - 8usize]; ["Alignment of TestDoublePtr"][::std::mem::align_of::() - 8usize]; @@ -43,6 +45,7 @@ impl Default for TestDoublePtr { pub struct TestFloat { pub mMember: __BindgenComplex, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of TestFloat"][::std::mem::size_of::() - 8usize]; ["Alignment of TestFloat"][::std::mem::align_of::() - 4usize]; @@ -55,6 +58,7 @@ const _: () = { pub struct TestFloatPtr { pub mMember: *mut __BindgenComplex, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of TestFloatPtr"][::std::mem::size_of::() - 8usize]; ["Alignment of TestFloatPtr"][::std::mem::align_of::() - 8usize]; diff --git a/bindgen-tests/tests/expectations/tests/const-const-mut-ptr.rs b/bindgen-tests/tests/expectations/tests/const-const-mut-ptr.rs index e3bf776898..72a34da105 100644 --- a/bindgen-tests/tests/expectations/tests/const-const-mut-ptr.rs +++ b/bindgen-tests/tests/expectations/tests/const-const-mut-ptr.rs @@ -4,6 +4,7 @@ pub struct foo { pub bar: *const *const *mut *const ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo"][::std::mem::size_of::() - 8usize]; ["Alignment of foo"][::std::mem::align_of::() - 8usize]; diff --git a/bindgen-tests/tests/expectations/tests/const_array_typedef.rs b/bindgen-tests/tests/expectations/tests/const_array_typedef.rs index 115c934813..a9ddc0c85e 100644 --- a/bindgen-tests/tests/expectations/tests/const_array_typedef.rs +++ b/bindgen-tests/tests/expectations/tests/const_array_typedef.rs @@ -4,6 +4,7 @@ pub struct strct { pub field: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of strct"][::std::mem::size_of::() - 4usize]; ["Alignment of strct"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/const_bool.rs b/bindgen-tests/tests/expectations/tests/const_bool.rs index 1625454a9f..2cbab47390 100644 --- a/bindgen-tests/tests/expectations/tests/const_bool.rs +++ b/bindgen-tests/tests/expectations/tests/const_bool.rs @@ -6,6 +6,7 @@ pub struct A { pub _address: u8, } pub const A_k: bool = false; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of A"][::std::mem::size_of::() - 1usize]; ["Alignment of A"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/const_enum_unnamed.rs b/bindgen-tests/tests/expectations/tests/const_enum_unnamed.rs index e3484479db..f49d825224 100644 --- a/bindgen-tests/tests/expectations/tests/const_enum_unnamed.rs +++ b/bindgen-tests/tests/expectations/tests/const_enum_unnamed.rs @@ -18,6 +18,7 @@ pub const Foo_FOO_BAR: Foo__bindgen_ty_1 = Foo__bindgen_ty_1::FOO_BAR; pub enum Foo__bindgen_ty_1 { FOO_BAR = 10, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Foo"][::std::mem::size_of::() - 1usize]; ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/constified-enum-module-overflow.rs b/bindgen-tests/tests/expectations/tests/constified-enum-module-overflow.rs index c72ecf57dd..e5eada9abc 100644 --- a/bindgen-tests/tests/expectations/tests/constified-enum-module-overflow.rs +++ b/bindgen-tests/tests/expectations/tests/constified-enum-module-overflow.rs @@ -15,11 +15,13 @@ pub type C_U = B; pub struct A { pub u: B, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of A"][::std::mem::size_of::() - 1usize]; ["Alignment of A"][::std::mem::align_of::() - 1usize]; ["Offset of field: A::u"][::std::mem::offset_of!(A, u) - 0usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: C_open0_A_close0", @@ -28,6 +30,7 @@ const _: () = { "Align of template specialization: C_open0_A_close0", ][::std::mem::align_of::() - 1usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: B_open0_A_close0", diff --git a/bindgen-tests/tests/expectations/tests/constify-all-enums.rs b/bindgen-tests/tests/expectations/tests/constify-all-enums.rs index 0447a147ff..7913454b56 100644 --- a/bindgen-tests/tests/expectations/tests/constify-all-enums.rs +++ b/bindgen-tests/tests/expectations/tests/constify-all-enums.rs @@ -8,6 +8,7 @@ pub type foo = ::std::os::raw::c_uint; pub struct bar { pub this_should_work: foo, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of bar"][::std::mem::size_of::() - 4usize]; ["Alignment of bar"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/constify-module-enums-basic.rs b/bindgen-tests/tests/expectations/tests/constify-module-enums-basic.rs index 6bbcda650d..ec0e51c49e 100644 --- a/bindgen-tests/tests/expectations/tests/constify-module-enums-basic.rs +++ b/bindgen-tests/tests/expectations/tests/constify-module-enums-basic.rs @@ -12,6 +12,7 @@ pub use self::foo_alias1 as foo_alias2; pub struct bar { pub this_should_work: foo::Type, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of bar"][::std::mem::size_of::() - 4usize]; ["Alignment of bar"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/constify-module-enums-namespace.rs b/bindgen-tests/tests/expectations/tests/constify-module-enums-namespace.rs index 1f96f8aacc..883478a824 100644 --- a/bindgen-tests/tests/expectations/tests/constify-module-enums-namespace.rs +++ b/bindgen-tests/tests/expectations/tests/constify-module-enums-namespace.rs @@ -24,6 +24,7 @@ pub mod root { pub struct bar { pub this_should_work: root::ns1::ns2::foo::Type, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of bar"][::std::mem::size_of::() - 4usize]; ["Alignment of bar"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/constify-module-enums-shadow-name.rs b/bindgen-tests/tests/expectations/tests/constify-module-enums-shadow-name.rs index d65bcd81b7..b5e4243c94 100644 --- a/bindgen-tests/tests/expectations/tests/constify-module-enums-shadow-name.rs +++ b/bindgen-tests/tests/expectations/tests/constify-module-enums-shadow-name.rs @@ -11,6 +11,7 @@ pub mod foo { pub struct bar { pub member: foo::Type, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of bar"][::std::mem::size_of::() - 4usize]; ["Alignment of bar"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-alias.rs b/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-alias.rs index 0aa58bb9a1..63d48ef795 100644 --- a/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-alias.rs +++ b/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-alias.rs @@ -20,6 +20,7 @@ pub struct Bar { pub baz_ptr3: *mut Foo_alias2, pub baz_ptr4: *mut Foo_alias3, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Bar"][::std::mem::size_of::() - 48usize]; ["Alignment of Bar"][::std::mem::align_of::() - 8usize]; diff --git a/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs b/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs index b12bfab49e..80fa0734da 100644 --- a/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs +++ b/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs @@ -10,6 +10,7 @@ pub struct Bar { pub baz1: one_Foo::Type, pub baz2: *mut one_Foo::Type, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Bar"][::std::mem::size_of::() - 16usize]; ["Alignment of Bar"][::std::mem::align_of::() - 8usize]; diff --git a/bindgen-tests/tests/expectations/tests/constify-module-enums-types.rs b/bindgen-tests/tests/expectations/tests/constify-module-enums-types.rs index 24b6b21fa5..754f6ceedb 100644 --- a/bindgen-tests/tests/expectations/tests/constify-module-enums-types.rs +++ b/bindgen-tests/tests/expectations/tests/constify-module-enums-types.rs @@ -45,6 +45,7 @@ pub struct bar { pub member9: anon_enum_alias2, pub member10: anon_enum_alias3, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of bar"][::std::mem::size_of::() - 48usize]; ["Alignment of bar"][::std::mem::align_of::() - 8usize]; @@ -73,6 +74,7 @@ impl Default for bar { pub struct Baz { pub member1: ns2_Foo::Type, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Baz"][::std::mem::size_of::() - 4usize]; ["Alignment of Baz"][::std::mem::align_of::() - 4usize]; @@ -97,6 +99,7 @@ pub mod one_Foo { pub struct Bar { pub baz: *mut one_Foo::Type, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Bar"][::std::mem::size_of::() - 8usize]; ["Alignment of Bar"][::std::mem::align_of::() - 8usize]; diff --git a/bindgen-tests/tests/expectations/tests/constructor-tp.rs b/bindgen-tests/tests/expectations/tests/constructor-tp.rs index 30cbd86c18..1a6e9c40dc 100644 --- a/bindgen-tests/tests/expectations/tests/constructor-tp.rs +++ b/bindgen-tests/tests/expectations/tests/constructor-tp.rs @@ -9,6 +9,7 @@ pub struct Foo { pub struct Bar { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Bar"][::std::mem::size_of::() - 1usize]; ["Alignment of Bar"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/constructors.rs b/bindgen-tests/tests/expectations/tests/constructors.rs index aa54ae4c4a..9da761e40a 100644 --- a/bindgen-tests/tests/expectations/tests/constructors.rs +++ b/bindgen-tests/tests/expectations/tests/constructors.rs @@ -4,6 +4,7 @@ pub struct TestOverload { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of TestOverload"][::std::mem::size_of::() - 1usize]; ["Alignment of TestOverload"][::std::mem::align_of::() - 1usize]; @@ -38,6 +39,7 @@ impl TestOverload { pub struct TestPublicNoArgs { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of TestPublicNoArgs"][::std::mem::size_of::() - 1usize]; [ diff --git a/bindgen-tests/tests/expectations/tests/contains-vs-inherits-zero-sized.rs b/bindgen-tests/tests/expectations/tests/contains-vs-inherits-zero-sized.rs index 8cec58751c..3362280843 100644 --- a/bindgen-tests/tests/expectations/tests/contains-vs-inherits-zero-sized.rs +++ b/bindgen-tests/tests/expectations/tests/contains-vs-inherits-zero-sized.rs @@ -5,6 +5,7 @@ pub struct Empty { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Empty"][::std::mem::size_of::() - 1usize]; ["Alignment of Empty"][::std::mem::align_of::() - 1usize]; @@ -16,6 +17,7 @@ const _: () = { pub struct Inherits { pub b: bool, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Inherits"][::std::mem::size_of::() - 1usize]; ["Alignment of Inherits"][::std::mem::align_of::() - 1usize]; @@ -29,6 +31,7 @@ pub struct Contains { pub empty: Empty, pub b: bool, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Contains"][::std::mem::size_of::() - 2usize]; ["Alignment of Contains"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/convert-floats.rs b/bindgen-tests/tests/expectations/tests/convert-floats.rs index bef0f6e5b7..9ca939f7c5 100644 --- a/bindgen-tests/tests/expectations/tests/convert-floats.rs +++ b/bindgen-tests/tests/expectations/tests/convert-floats.rs @@ -15,6 +15,7 @@ pub struct foo { pub complexFloat: __BindgenComplex<::std::os::raw::c_float>, pub complexDouble: __BindgenComplex<::std::os::raw::c_double>, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo"][::std::mem::size_of::() - 48usize]; ["Alignment of foo"][::std::mem::align_of::() - 8usize]; diff --git a/bindgen-tests/tests/expectations/tests/cpp-empty-layout.rs b/bindgen-tests/tests/expectations/tests/cpp-empty-layout.rs index 30de3dce72..551dff82cf 100644 --- a/bindgen-tests/tests/expectations/tests/cpp-empty-layout.rs +++ b/bindgen-tests/tests/expectations/tests/cpp-empty-layout.rs @@ -4,6 +4,7 @@ pub struct Foo { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Foo"][::std::mem::size_of::() - 1usize]; ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/crtp.rs b/bindgen-tests/tests/expectations/tests/crtp.rs index 0685411bf8..68397041b7 100644 --- a/bindgen-tests/tests/expectations/tests/crtp.rs +++ b/bindgen-tests/tests/expectations/tests/crtp.rs @@ -9,6 +9,7 @@ pub struct Base { pub struct Derived { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Derived"][::std::mem::size_of::() - 1usize]; ["Alignment of Derived"][::std::mem::align_of::() - 1usize]; @@ -23,6 +24,7 @@ pub struct BaseWithDestructor { pub struct DerivedFromBaseWithDestructor { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of DerivedFromBaseWithDestructor", @@ -31,6 +33,7 @@ const _: () = { "Alignment of DerivedFromBaseWithDestructor", ][::std::mem::align_of::() - 1usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: Base_open0_Derived_close0", @@ -39,6 +42,7 @@ const _: () = { "Align of template specialization: Base_open0_Derived_close0", ][::std::mem::align_of::() - 1usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: BaseWithDestructor_open0_DerivedFromBaseWithDestructor_close0", diff --git a/bindgen-tests/tests/expectations/tests/ctypes-prefix-path.rs b/bindgen-tests/tests/expectations/tests/ctypes-prefix-path.rs index 14b4917f0b..5f947f9cea 100644 --- a/bindgen-tests/tests/expectations/tests/ctypes-prefix-path.rs +++ b/bindgen-tests/tests/expectations/tests/ctypes-prefix-path.rs @@ -13,6 +13,7 @@ pub struct foo { pub b: libc::foo::c_int, pub bar: *mut libc::foo::c_void, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo"][::core::mem::size_of::() - 16usize]; ["Alignment of foo"][::core::mem::align_of::() - 8usize]; diff --git a/bindgen-tests/tests/expectations/tests/default-template-parameter.rs b/bindgen-tests/tests/expectations/tests/default-template-parameter.rs index a1fdcf9016..797fc03253 100644 --- a/bindgen-tests/tests/expectations/tests/default-template-parameter.rs +++ b/bindgen-tests/tests/expectations/tests/default-template-parameter.rs @@ -16,6 +16,7 @@ impl Default for Foo { } } } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: Foo_open0_bool__int_close0", diff --git a/bindgen-tests/tests/expectations/tests/deleted-function.rs b/bindgen-tests/tests/expectations/tests/deleted-function.rs index 3abcf618cf..913e2d4b4a 100644 --- a/bindgen-tests/tests/expectations/tests/deleted-function.rs +++ b/bindgen-tests/tests/expectations/tests/deleted-function.rs @@ -4,6 +4,7 @@ pub struct A { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of A"][::std::mem::size_of::() - 1usize]; ["Alignment of A"][::std::mem::align_of::() - 1usize]; @@ -31,6 +32,7 @@ impl A { pub struct B { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of B"][::std::mem::size_of::() - 1usize]; ["Alignment of B"][::std::mem::align_of::() - 1usize]; @@ -40,6 +42,7 @@ const _: () = { pub struct C { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of C"][::std::mem::size_of::() - 1usize]; ["Alignment of C"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/derive-custom-cli.rs b/bindgen-tests/tests/expectations/tests/derive-custom-cli.rs index 48dbede146..59a3a76571 100644 --- a/bindgen-tests/tests/expectations/tests/derive-custom-cli.rs +++ b/bindgen-tests/tests/expectations/tests/derive-custom-cli.rs @@ -4,6 +4,7 @@ pub struct foo_struct { pub inner: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo_struct"][::std::mem::size_of::() - 4usize]; ["Alignment of foo_struct"][::std::mem::align_of::() - 4usize]; @@ -22,6 +23,7 @@ pub union foo_union { pub fst: ::std::mem::ManuallyDrop<::std::os::raw::c_int>, pub snd: ::std::mem::ManuallyDrop, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo_union"][::std::mem::size_of::() - 4usize]; ["Alignment of foo_union"][::std::mem::align_of::() - 4usize]; @@ -32,6 +34,7 @@ const _: () = { pub struct non_matching { pub inner: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of non_matching"][::std::mem::size_of::() - 4usize]; ["Alignment of non_matching"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/derive-debug-mangle-name.rs b/bindgen-tests/tests/expectations/tests/derive-debug-mangle-name.rs index c61fb0149a..34b4a87d65 100644 --- a/bindgen-tests/tests/expectations/tests/derive-debug-mangle-name.rs +++ b/bindgen-tests/tests/expectations/tests/derive-debug-mangle-name.rs @@ -12,6 +12,7 @@ pub union perf_event_attr__bindgen_ty_1 { pub b: ::std::os::raw::c_int, pub c: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of perf_event_attr__bindgen_ty_1", @@ -40,6 +41,7 @@ impl ::std::fmt::Debug for perf_event_attr__bindgen_ty_1 { write!(f, "perf_event_attr__bindgen_ty_1 {{ union }}") } } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of perf_event_attr"][::std::mem::size_of::() - 12usize]; ["Alignment of perf_event_attr"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/derive-default-and-blocklist.rs b/bindgen-tests/tests/expectations/tests/derive-default-and-blocklist.rs index 75404fcc0b..6ce99e5093 100644 --- a/bindgen-tests/tests/expectations/tests/derive-default-and-blocklist.rs +++ b/bindgen-tests/tests/expectations/tests/derive-default-and-blocklist.rs @@ -6,6 +6,7 @@ pub struct BlocklistMe(u8); pub struct ShouldNotDeriveDefault { pub a: BlocklistMe, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of ShouldNotDeriveDefault", diff --git a/bindgen-tests/tests/expectations/tests/derive-fn-ptr.rs b/bindgen-tests/tests/expectations/tests/derive-fn-ptr.rs index 3e0b984bbc..f4b09474ae 100644 --- a/bindgen-tests/tests/expectations/tests/derive-fn-ptr.rs +++ b/bindgen-tests/tests/expectations/tests/derive-fn-ptr.rs @@ -24,6 +24,7 @@ pub type my_fun_t = ::std::option::Option< pub struct Foo { pub callback: my_fun_t, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Foo"][::std::mem::size_of::() - 8usize]; ["Alignment of Foo"][::std::mem::align_of::() - 8usize]; @@ -50,6 +51,7 @@ pub type my_fun2_t = ::std::option::Option< pub struct Bar { pub callback: my_fun2_t, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Bar"][::std::mem::size_of::() - 8usize]; ["Alignment of Bar"][::std::mem::align_of::() - 8usize]; diff --git a/bindgen-tests/tests/expectations/tests/derive-hash-and-blocklist.rs b/bindgen-tests/tests/expectations/tests/derive-hash-and-blocklist.rs index 092244d5ba..c52047e8b8 100644 --- a/bindgen-tests/tests/expectations/tests/derive-hash-and-blocklist.rs +++ b/bindgen-tests/tests/expectations/tests/derive-hash-and-blocklist.rs @@ -5,6 +5,7 @@ pub struct BlocklistMe(u8); pub struct ShouldNotDeriveHash { pub a: BlocklistMe, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of ShouldNotDeriveHash", diff --git a/bindgen-tests/tests/expectations/tests/derive-hash-blocklisting.rs b/bindgen-tests/tests/expectations/tests/derive-hash-blocklisting.rs index d8b65e8e09..e3223f08d7 100644 --- a/bindgen-tests/tests/expectations/tests/derive-hash-blocklisting.rs +++ b/bindgen-tests/tests/expectations/tests/derive-hash-blocklisting.rs @@ -11,6 +11,7 @@ pub struct Blocklisted { pub struct AllowlistedOne { pub a: Blocklisted<::std::os::raw::c_int>, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of AllowlistedOne"][::std::mem::size_of::() - 4usize]; ["Alignment of AllowlistedOne"][::std::mem::align_of::() - 4usize]; @@ -32,6 +33,7 @@ impl Default for AllowlistedOne { pub struct AllowlistedTwo { pub b: Blocklisted, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of AllowlistedTwo"][::std::mem::size_of::() - 4usize]; ["Alignment of AllowlistedTwo"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs index ea434ae83b..2d66015fe7 100644 --- a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs +++ b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-anon-struct-float.rs @@ -11,6 +11,7 @@ pub struct foo__bindgen_ty_1 { pub a: f32, pub b: f32, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo__bindgen_ty_1"][::std::mem::size_of::() - 8usize]; [ @@ -23,6 +24,7 @@ const _: () = { "Offset of field: foo__bindgen_ty_1::b", ][::std::mem::offset_of!(foo__bindgen_ty_1, b) - 4usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo"][::std::mem::size_of::() - 8usize]; ["Alignment of foo"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-float-array.rs b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-float-array.rs index b22ce29e48..254a50b3e3 100644 --- a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-float-array.rs +++ b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-float-array.rs @@ -5,6 +5,7 @@ pub struct foo { pub bar: [f32; 3usize], } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo"][::std::mem::size_of::() - 12usize]; ["Alignment of foo"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs index 657f72ece4..2588a49eed 100644 --- a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs +++ b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-incomplete-array.rs @@ -35,6 +35,7 @@ pub struct test { pub a: ::std::os::raw::c_int, pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of test"][::std::mem::size_of::() - 4usize]; ["Alignment of test"][::std::mem::align_of::() - 4usize]; @@ -49,6 +50,7 @@ pub struct test2 { pub a: ::std::os::raw::c_int, pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of test2"][::std::mem::size_of::() - 4usize]; ["Alignment of test2"][::std::mem::align_of::() - 4usize]; @@ -64,6 +66,7 @@ pub struct test3 { pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of test3"][::std::mem::size_of::() - 4usize]; ["Alignment of test3"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-pointer.rs b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-pointer.rs index b27091fa69..5240d969db 100644 --- a/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-pointer.rs +++ b/bindgen-tests/tests/expectations/tests/derive-hash-struct-with-pointer.rs @@ -5,6 +5,7 @@ pub struct ConstPtrMutObj { pub bar: *mut ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of ConstPtrMutObj"][::std::mem::size_of::() - 8usize]; ["Alignment of ConstPtrMutObj"][::std::mem::align_of::() - 8usize]; @@ -26,6 +27,7 @@ impl Default for ConstPtrMutObj { pub struct MutPtrMutObj { pub bar: *mut ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of MutPtrMutObj"][::std::mem::size_of::() - 8usize]; ["Alignment of MutPtrMutObj"][::std::mem::align_of::() - 8usize]; @@ -47,6 +49,7 @@ impl Default for MutPtrMutObj { pub struct MutPtrConstObj { pub bar: *const ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of MutPtrConstObj"][::std::mem::size_of::() - 8usize]; ["Alignment of MutPtrConstObj"][::std::mem::align_of::() - 8usize]; @@ -68,6 +71,7 @@ impl Default for MutPtrConstObj { pub struct ConstPtrConstObj { pub bar: *const ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of ConstPtrConstObj"][::std::mem::size_of::() - 8usize]; [ diff --git a/bindgen-tests/tests/expectations/tests/derive-hash-template-inst-float.rs b/bindgen-tests/tests/expectations/tests/derive-hash-template-inst-float.rs index 03a8b22cbb..10ed002e6e 100644 --- a/bindgen-tests/tests/expectations/tests/derive-hash-template-inst-float.rs +++ b/bindgen-tests/tests/expectations/tests/derive-hash-template-inst-float.rs @@ -21,6 +21,7 @@ impl Default for foo { pub struct IntStr { pub a: foo<::std::os::raw::c_int>, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of IntStr"][::std::mem::size_of::() - 4usize]; ["Alignment of IntStr"][::std::mem::align_of::() - 4usize]; @@ -41,6 +42,7 @@ impl Default for IntStr { pub struct FloatStr { pub a: foo, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of FloatStr"][::std::mem::size_of::() - 4usize]; ["Alignment of FloatStr"][::std::mem::align_of::() - 4usize]; @@ -55,6 +57,7 @@ impl Default for FloatStr { } } } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: foo_open0_int_close0", @@ -63,6 +66,7 @@ const _: () = { "Align of template specialization: foo_open0_int_close0", ][::std::mem::align_of::>() - 4usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: foo_open0_float_close0", diff --git a/bindgen-tests/tests/expectations/tests/derive-partialeq-and-blocklist.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-and-blocklist.rs index 558fc86a44..d24981061c 100644 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-and-blocklist.rs +++ b/bindgen-tests/tests/expectations/tests/derive-partialeq-and-blocklist.rs @@ -6,6 +6,7 @@ pub struct BlocklistMe(u8); pub struct ShouldNotDerivePartialEq { pub a: BlocklistMe, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of ShouldNotDerivePartialEq", diff --git a/bindgen-tests/tests/expectations/tests/derive-partialeq-anonfield.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-anonfield.rs index 02fa0e7303..c4eb08df60 100644 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-anonfield.rs +++ b/bindgen-tests/tests/expectations/tests/derive-partialeq-anonfield.rs @@ -11,6 +11,7 @@ pub struct rte_mbuf { pub struct rte_mbuf__bindgen_ty_1 { pub bindgen_union_field: [u8; 0usize], } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of rte_mbuf__bindgen_ty_1", @@ -28,6 +29,7 @@ impl Default for rte_mbuf__bindgen_ty_1 { } } } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of rte_mbuf"][::std::mem::size_of::() - 0usize]; ["Alignment of rte_mbuf"][::std::mem::align_of::() - 64usize]; diff --git a/bindgen-tests/tests/expectations/tests/derive-partialeq-pointer.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-pointer.rs index fde2269b3b..3e48e5d8ce 100644 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-pointer.rs +++ b/bindgen-tests/tests/expectations/tests/derive-partialeq-pointer.rs @@ -4,6 +4,7 @@ pub struct Bar { pub b: *mut a, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Bar"][::std::mem::size_of::() - 8usize]; ["Alignment of Bar"][::std::mem::align_of::() - 8usize]; @@ -28,6 +29,7 @@ pub struct c { pub union c__bindgen_ty_1 { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of c__bindgen_ty_1"][::std::mem::size_of::() - 1usize]; ["Alignment of c__bindgen_ty_1"][::std::mem::align_of::() - 1usize]; @@ -41,6 +43,7 @@ impl Default for c__bindgen_ty_1 { } } } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of c"][::std::mem::size_of::() - 1usize]; ["Alignment of c"][::std::mem::align_of::() - 1usize]; @@ -59,6 +62,7 @@ impl Default for c { pub struct a { pub d: c, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of a"][::std::mem::size_of::() - 1usize]; ["Alignment of a"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/derive-partialeq-union.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-union.rs index 9dd183d073..0365c765eb 100644 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-union.rs +++ b/bindgen-tests/tests/expectations/tests/derive-partialeq-union.rs @@ -6,6 +6,7 @@ pub union ShouldNotDerivePartialEq { pub a: ::std::os::raw::c_char, pub b: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of ShouldNotDerivePartialEq", diff --git a/bindgen-tests/tests/expectations/tests/disable-nested-struct-naming.rs b/bindgen-tests/tests/expectations/tests/disable-nested-struct-naming.rs index cd020d2763..68c729b735 100644 --- a/bindgen-tests/tests/expectations/tests/disable-nested-struct-naming.rs +++ b/bindgen-tests/tests/expectations/tests/disable-nested-struct-naming.rs @@ -27,11 +27,13 @@ pub struct bar1__bindgen_ty_1__bindgen_ty_1 { pub struct bar4 { pub x4: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of bar4"][::std::mem::size_of::() - 4usize]; ["Alignment of bar4"][::std::mem::align_of::() - 4usize]; ["Offset of field: bar4::x4"][::std::mem::offset_of!(bar4, x4) - 0usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of bar1__bindgen_ty_1__bindgen_ty_1", @@ -46,6 +48,7 @@ const _: () = { "Offset of field: bar1__bindgen_ty_1__bindgen_ty_1::b4", ][::std::mem::offset_of!(bar1__bindgen_ty_1__bindgen_ty_1, b4) - 4usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of bar1__bindgen_ty_1", @@ -60,12 +63,14 @@ const _: () = { "Offset of field: bar1__bindgen_ty_1::b3", ][::std::mem::offset_of!(bar1__bindgen_ty_1, b3) - 4usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of bar1"][::std::mem::size_of::() - 16usize]; ["Alignment of bar1"][::std::mem::align_of::() - 4usize]; ["Offset of field: bar1::x1"][::std::mem::offset_of!(bar1, x1) - 0usize]; ["Offset of field: bar1::b2"][::std::mem::offset_of!(bar1, b2) - 4usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo"][::std::mem::size_of::() - 16usize]; ["Alignment of foo"][::std::mem::align_of::() - 4usize]; @@ -86,11 +91,13 @@ pub struct _bindgen_ty_1__bindgen_ty_1 { pub struct baz { pub x: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of baz"][::std::mem::size_of::() - 4usize]; ["Alignment of baz"][::std::mem::align_of::() - 4usize]; ["Offset of field: baz::x"][::std::mem::offset_of!(baz, x) - 0usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of _bindgen_ty_1__bindgen_ty_1", @@ -102,6 +109,7 @@ const _: () = { "Offset of field: _bindgen_ty_1__bindgen_ty_1::b", ][::std::mem::offset_of!(_bindgen_ty_1__bindgen_ty_1, b) - 0usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of _bindgen_ty_1"][::std::mem::size_of::<_bindgen_ty_1>() - 4usize]; ["Alignment of _bindgen_ty_1"][::std::mem::align_of::<_bindgen_ty_1>() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/disable-untagged-union.rs b/bindgen-tests/tests/expectations/tests/disable-untagged-union.rs index 3e45778f08..60636280e4 100644 --- a/bindgen-tests/tests/expectations/tests/disable-untagged-union.rs +++ b/bindgen-tests/tests/expectations/tests/disable-untagged-union.rs @@ -49,6 +49,7 @@ pub struct Foo { pub baz: __BindgenUnionField<::std::os::raw::c_uint>, pub bindgen_union_field: u32, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Foo"][::std::mem::size_of::() - 4usize]; ["Alignment of Foo"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/do-not-derive-copy.rs b/bindgen-tests/tests/expectations/tests/do-not-derive-copy.rs index 894bc93971..29ca6d6acf 100644 --- a/bindgen-tests/tests/expectations/tests/do-not-derive-copy.rs +++ b/bindgen-tests/tests/expectations/tests/do-not-derive-copy.rs @@ -4,6 +4,7 @@ pub struct WouldBeCopyButWeAreNotDerivingCopy { pub x: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of WouldBeCopyButWeAreNotDerivingCopy", diff --git a/bindgen-tests/tests/expectations/tests/doggo-or-null.rs b/bindgen-tests/tests/expectations/tests/doggo-or-null.rs index d9169b7ecd..972da871d3 100644 --- a/bindgen-tests/tests/expectations/tests/doggo-or-null.rs +++ b/bindgen-tests/tests/expectations/tests/doggo-or-null.rs @@ -4,6 +4,7 @@ pub struct Doggo { pub x: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Doggo"][::std::mem::size_of::() - 4usize]; ["Alignment of Doggo"][::std::mem::align_of::() - 4usize]; @@ -14,6 +15,7 @@ const _: () = { pub struct Null { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Null"][::std::mem::size_of::() - 1usize]; ["Alignment of Null"][::std::mem::align_of::() - 1usize]; @@ -30,6 +32,7 @@ const _: () = { pub union DoggoOrNull { pub _bindgen_opaque_blob: u32, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of DoggoOrNull"][::std::mem::size_of::() - 4usize]; ["Alignment of DoggoOrNull"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/duplicated-definition-count.rs b/bindgen-tests/tests/expectations/tests/duplicated-definition-count.rs index f757029c2b..85f28dcca6 100644 --- a/bindgen-tests/tests/expectations/tests/duplicated-definition-count.rs +++ b/bindgen-tests/tests/expectations/tests/duplicated-definition-count.rs @@ -4,6 +4,7 @@ pub struct BitStream { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of BitStream"][::std::mem::size_of::() - 1usize]; ["Alignment of BitStream"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/duplicated-namespaces-definitions.rs b/bindgen-tests/tests/expectations/tests/duplicated-namespaces-definitions.rs index de1b5ae94d..775a21ac30 100644 --- a/bindgen-tests/tests/expectations/tests/duplicated-namespaces-definitions.rs +++ b/bindgen-tests/tests/expectations/tests/duplicated-namespaces-definitions.rs @@ -12,6 +12,7 @@ pub mod root { pub foo: ::std::os::raw::c_int, pub baz: bool, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Bar"][::std::mem::size_of::() - 8usize]; ["Alignment of Bar"][::std::mem::align_of::() - 4usize]; @@ -27,6 +28,7 @@ pub mod root { pub struct Foo { pub ptr: *mut root::foo::Bar, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Foo"][::std::mem::size_of::() - 8usize]; ["Alignment of Foo"][::std::mem::align_of::() - 8usize]; diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_blocklist.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_blocklist.rs index 4908159826..776da1ca5f 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_blocklist.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_blocklist.rs @@ -4,6 +4,7 @@ pub struct X { pub _x: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of X"][::std::mem::size_of::() - 4usize]; ["Alignment of X"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs index 694d7e4ad5..93c636ebff 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs @@ -4,6 +4,7 @@ pub struct A { pub _x: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of A"][::std::mem::size_of::() - 4usize]; ["Alignment of A"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/enum-default-bitfield.rs b/bindgen-tests/tests/expectations/tests/enum-default-bitfield.rs index 56d30ae3a0..58b8bf092f 100644 --- a/bindgen-tests/tests/expectations/tests/enum-default-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/enum-default-bitfield.rs @@ -35,6 +35,7 @@ impl ::std::ops::BitAndAssign for foo__bindgen_ty_1 { #[repr(transparent)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct foo__bindgen_ty_1(pub ::std::os::raw::c_uint); +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo"][::std::mem::size_of::() - 4usize]; ["Alignment of foo"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/enum-default-consts.rs b/bindgen-tests/tests/expectations/tests/enum-default-consts.rs index 9c409690cf..af51864c2c 100644 --- a/bindgen-tests/tests/expectations/tests/enum-default-consts.rs +++ b/bindgen-tests/tests/expectations/tests/enum-default-consts.rs @@ -7,6 +7,7 @@ pub struct foo { pub const foo_FOO_A: foo__bindgen_ty_1 = 0; pub const foo_FOO_B: foo__bindgen_ty_1 = 1; pub type foo__bindgen_ty_1 = ::std::os::raw::c_uint; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo"][::std::mem::size_of::() - 4usize]; ["Alignment of foo"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/enum-default-module.rs b/bindgen-tests/tests/expectations/tests/enum-default-module.rs index 9e5d408d66..cc09d49425 100644 --- a/bindgen-tests/tests/expectations/tests/enum-default-module.rs +++ b/bindgen-tests/tests/expectations/tests/enum-default-module.rs @@ -9,6 +9,7 @@ pub mod foo__bindgen_ty_1 { pub const FOO_A: Type = 0; pub const FOO_B: Type = 1; } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo"][::std::mem::size_of::() - 4usize]; ["Alignment of foo"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/enum-default-rust.rs b/bindgen-tests/tests/expectations/tests/enum-default-rust.rs index d2ca40eeb7..f9a99166de 100644 --- a/bindgen-tests/tests/expectations/tests/enum-default-rust.rs +++ b/bindgen-tests/tests/expectations/tests/enum-default-rust.rs @@ -12,6 +12,7 @@ pub enum foo__bindgen_ty_1 { FOO_A = 0, FOO_B = 1, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo"][::std::mem::size_of::() - 4usize]; ["Alignment of foo"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/enum-no-debug-rust.rs b/bindgen-tests/tests/expectations/tests/enum-no-debug-rust.rs index 26bd668292..b728dfc898 100644 --- a/bindgen-tests/tests/expectations/tests/enum-no-debug-rust.rs +++ b/bindgen-tests/tests/expectations/tests/enum-no-debug-rust.rs @@ -12,6 +12,7 @@ pub enum foo__bindgen_ty_1 { FOO_A = 0, FOO_B = 1, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo"][::std::mem::size_of::() - 4usize]; ["Alignment of foo"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/enum.rs b/bindgen-tests/tests/expectations/tests/enum.rs index f542ad0bef..820182125a 100644 --- a/bindgen-tests/tests/expectations/tests/enum.rs +++ b/bindgen-tests/tests/expectations/tests/enum.rs @@ -7,6 +7,7 @@ pub struct foo { pub const foo_FOO_A: foo__bindgen_ty_1 = 0; pub const foo_FOO_B: foo__bindgen_ty_1 = 1; pub type foo__bindgen_ty_1 = ::std::os::raw::c_uint; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo"][::std::mem::size_of::() - 4usize]; ["Alignment of foo"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/enum_and_vtable_mangling.rs b/bindgen-tests/tests/expectations/tests/enum_and_vtable_mangling.rs index 4ee86d9251..18e1ad8e36 100644 --- a/bindgen-tests/tests/expectations/tests/enum_and_vtable_mangling.rs +++ b/bindgen-tests/tests/expectations/tests/enum_and_vtable_mangling.rs @@ -17,6 +17,7 @@ pub struct C { pub vtable_: *const C__bindgen_vtable, pub i: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of C"][::std::mem::size_of::() - 16usize]; ["Alignment of C"][::std::mem::align_of::() - 8usize]; diff --git a/bindgen-tests/tests/expectations/tests/explicit-padding.rs b/bindgen-tests/tests/expectations/tests/explicit-padding.rs index 847c8ed492..ec21399106 100644 --- a/bindgen-tests/tests/expectations/tests/explicit-padding.rs +++ b/bindgen-tests/tests/expectations/tests/explicit-padding.rs @@ -8,6 +8,7 @@ pub struct pad_me { pub third: u16, pub __bindgen_padding_1: [u8; 2usize], } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of pad_me"][::std::mem::size_of::() - 12usize]; ["Alignment of pad_me"][::std::mem::align_of::() - 4usize]; @@ -22,6 +23,7 @@ pub union dont_pad_me { pub second: u32, pub third: u16, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of dont_pad_me"][::std::mem::size_of::() - 4usize]; ["Alignment of dont_pad_me"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/field-visibility-callback.rs b/bindgen-tests/tests/expectations/tests/field-visibility-callback.rs index 2599c3ef9f..9be373e5a7 100644 --- a/bindgen-tests/tests/expectations/tests/field-visibility-callback.rs +++ b/bindgen-tests/tests/expectations/tests/field-visibility-callback.rs @@ -92,6 +92,7 @@ pub struct my_struct { _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, __bindgen_padding_0: [u8; 3usize], } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of my_struct"][::std::mem::size_of::() - 12usize]; ["Alignment of my_struct"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/field-visibility.rs b/bindgen-tests/tests/expectations/tests/field-visibility.rs index af74644c93..2ad5dc838e 100644 --- a/bindgen-tests/tests/expectations/tests/field-visibility.rs +++ b/bindgen-tests/tests/expectations/tests/field-visibility.rs @@ -91,6 +91,7 @@ pub struct my_struct1 { _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, __bindgen_padding_0: [u8; 3usize], } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of my_struct1"][::std::mem::size_of::() - 4usize]; ["Alignment of my_struct1"][::std::mem::align_of::() - 4usize]; @@ -130,6 +131,7 @@ pub struct my_struct2 { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub __bindgen_padding_0: [u8; 3usize], } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of my_struct2"][::std::mem::size_of::() - 4usize]; ["Alignment of my_struct2"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/flexarray.rs b/bindgen-tests/tests/expectations/tests/flexarray.rs index ece5e62419..b9c800366e 100644 --- a/bindgen-tests/tests/expectations/tests/flexarray.rs +++ b/bindgen-tests/tests/expectations/tests/flexarray.rs @@ -37,6 +37,7 @@ pub struct flexarray { pub count: ::std::os::raw::c_int, pub data: FAM, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of flexarray"][::std::mem::size_of::() - 4usize]; ["Alignment of flexarray"][::std::mem::align_of::() - 4usize]; @@ -126,6 +127,7 @@ pub struct flexarray_zero { pub count: ::std::os::raw::c_int, pub data: FAM, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of flexarray_zero"][::std::mem::size_of::() - 4usize]; ["Alignment of flexarray_zero"][::std::mem::align_of::() - 4usize]; @@ -310,6 +312,7 @@ impl Default for flexarray_template { pub struct flexarray_ref { pub things: *mut flexarray, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of flexarray_ref"][::std::mem::size_of::() - 8usize]; ["Alignment of flexarray_ref"][::std::mem::align_of::() - 8usize]; @@ -333,6 +336,7 @@ pub struct flexarray_bogus_zero_fam { pub data1: __IncompleteArrayField<::std::os::raw::c_int>, pub data2: FAM, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of flexarray_bogus_zero_fam", @@ -447,6 +451,7 @@ pub struct flexarray_align { pub count: ::std::os::raw::c_int, pub data: FAM, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of flexarray_align"][::std::mem::size_of::() - 128usize]; [ diff --git a/bindgen-tests/tests/expectations/tests/float16.rs b/bindgen-tests/tests/expectations/tests/float16.rs index f218df495d..1804d1007a 100644 --- a/bindgen-tests/tests/expectations/tests/float16.rs +++ b/bindgen-tests/tests/expectations/tests/float16.rs @@ -10,6 +10,7 @@ extern "C" { pub struct Test__Float16 { pub f: __BindgenFloat16, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Test__Float16"][::std::mem::size_of::() - 2usize]; ["Alignment of Test__Float16"][::std::mem::align_of::() - 2usize]; @@ -22,6 +23,7 @@ const _: () = { pub struct Test__Float16Ref { pub f: *mut __BindgenFloat16, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Test__Float16Ref"][::std::mem::size_of::() - 8usize]; [ diff --git a/bindgen-tests/tests/expectations/tests/forward-declaration-autoptr.rs b/bindgen-tests/tests/expectations/tests/forward-declaration-autoptr.rs index 162c4b6004..b74b408841 100644 --- a/bindgen-tests/tests/expectations/tests/forward-declaration-autoptr.rs +++ b/bindgen-tests/tests/expectations/tests/forward-declaration-autoptr.rs @@ -24,6 +24,7 @@ impl Default for RefPtr { pub struct Bar { pub m_member: RefPtr, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Bar"][::std::mem::size_of::() - 8usize]; ["Alignment of Bar"][::std::mem::align_of::() - 8usize]; @@ -38,6 +39,7 @@ impl Default for Bar { } } } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: RefPtr_open0_Foo_close0", diff --git a/bindgen-tests/tests/expectations/tests/forward_declared_complex_types.rs b/bindgen-tests/tests/expectations/tests/forward_declared_complex_types.rs index 17dd065a85..2ba1071c8e 100644 --- a/bindgen-tests/tests/expectations/tests/forward_declared_complex_types.rs +++ b/bindgen-tests/tests/expectations/tests/forward_declared_complex_types.rs @@ -4,6 +4,7 @@ pub struct Foo_empty { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Foo_empty"][::std::mem::size_of::() - 1usize]; ["Alignment of Foo_empty"][::std::mem::align_of::() - 1usize]; @@ -18,6 +19,7 @@ pub struct Foo { pub struct Bar { pub f: *mut Foo, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Bar"][::std::mem::size_of::() - 8usize]; ["Alignment of Bar"][::std::mem::align_of::() - 8usize]; diff --git a/bindgen-tests/tests/expectations/tests/forward_declared_struct.rs b/bindgen-tests/tests/expectations/tests/forward_declared_struct.rs index 20ae5c2e4f..1f6dfd0f58 100644 --- a/bindgen-tests/tests/expectations/tests/forward_declared_struct.rs +++ b/bindgen-tests/tests/expectations/tests/forward_declared_struct.rs @@ -4,6 +4,7 @@ pub struct a { pub b: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of a"][::std::mem::size_of::() - 4usize]; ["Alignment of a"][::std::mem::align_of::() - 4usize]; @@ -14,6 +15,7 @@ const _: () = { pub struct c { pub d: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of c"][::std::mem::size_of::() - 4usize]; ["Alignment of c"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/func_ptr_in_struct.rs b/bindgen-tests/tests/expectations/tests/func_ptr_in_struct.rs index c09ba012a3..308bb069e0 100644 --- a/bindgen-tests/tests/expectations/tests/func_ptr_in_struct.rs +++ b/bindgen-tests/tests/expectations/tests/func_ptr_in_struct.rs @@ -11,6 +11,7 @@ pub struct Foo { unsafe extern "C" fn(x: ::std::os::raw::c_int, y: ::std::os::raw::c_int) -> baz, >, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Foo"][::std::mem::size_of::() - 8usize]; ["Alignment of Foo"][::std::mem::align_of::() - 8usize]; diff --git a/bindgen-tests/tests/expectations/tests/func_return_must_use.rs b/bindgen-tests/tests/expectations/tests/func_return_must_use.rs index 08c3e28443..bc9deb0818 100644 --- a/bindgen-tests/tests/expectations/tests/func_return_must_use.rs +++ b/bindgen-tests/tests/expectations/tests/func_return_must_use.rs @@ -28,6 +28,7 @@ extern "C" { #[derive(Debug, Default, Copy, Clone)] #[must_use] pub struct AnnotatedStruct {} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of AnnotatedStruct"][::std::mem::size_of::() - 0usize]; ["Alignment of AnnotatedStruct"][::std::mem::align_of::() - 1usize]; @@ -39,6 +40,7 @@ extern "C" { #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct PlainStruct {} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of PlainStruct"][::std::mem::size_of::() - 0usize]; ["Alignment of PlainStruct"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/gen-constructors-neg.rs b/bindgen-tests/tests/expectations/tests/gen-constructors-neg.rs index 30de3dce72..551dff82cf 100644 --- a/bindgen-tests/tests/expectations/tests/gen-constructors-neg.rs +++ b/bindgen-tests/tests/expectations/tests/gen-constructors-neg.rs @@ -4,6 +4,7 @@ pub struct Foo { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Foo"][::std::mem::size_of::() - 1usize]; ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/gen-constructors.rs b/bindgen-tests/tests/expectations/tests/gen-constructors.rs index 870e645493..c1a8b676fd 100644 --- a/bindgen-tests/tests/expectations/tests/gen-constructors.rs +++ b/bindgen-tests/tests/expectations/tests/gen-constructors.rs @@ -4,6 +4,7 @@ pub struct Foo { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Foo"][::std::mem::size_of::() - 1usize]; ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/gen-destructors-neg.rs b/bindgen-tests/tests/expectations/tests/gen-destructors-neg.rs index 95eeb8a508..77b6a07bb1 100644 --- a/bindgen-tests/tests/expectations/tests/gen-destructors-neg.rs +++ b/bindgen-tests/tests/expectations/tests/gen-destructors-neg.rs @@ -4,6 +4,7 @@ pub struct Foo { pub bar: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Foo"][::std::mem::size_of::() - 4usize]; ["Alignment of Foo"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/gen-destructors.rs b/bindgen-tests/tests/expectations/tests/gen-destructors.rs index 35af32923b..f3dc655f08 100644 --- a/bindgen-tests/tests/expectations/tests/gen-destructors.rs +++ b/bindgen-tests/tests/expectations/tests/gen-destructors.rs @@ -4,6 +4,7 @@ pub struct Foo { pub bar: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Foo"][::std::mem::size_of::() - 4usize]; ["Alignment of Foo"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/generate-inline.rs b/bindgen-tests/tests/expectations/tests/generate-inline.rs index e63ae1862c..1d60a98570 100644 --- a/bindgen-tests/tests/expectations/tests/generate-inline.rs +++ b/bindgen-tests/tests/expectations/tests/generate-inline.rs @@ -4,6 +4,7 @@ pub struct Foo { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Foo"][::std::mem::size_of::() - 1usize]; ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs b/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs index 214667a23a..148f4ffa41 100644 --- a/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs +++ b/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs @@ -120,6 +120,7 @@ pub struct foo { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub b: __IncompleteArrayField<*mut ::std::os::raw::c_void>, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo"][::std::mem::size_of::() - 8usize]; ["Alignment of foo"][::std::mem::align_of::() - 8usize]; diff --git a/bindgen-tests/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs b/bindgen-tests/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs index 11b1df8703..59e35f7b6c 100644 --- a/bindgen-tests/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs +++ b/bindgen-tests/tests/expectations/tests/inherit-from-template-instantiation-with-vtable.rs @@ -24,6 +24,7 @@ impl Default for BaseWithVtable { pub struct DerivedWithNoVirtualMethods { pub _base: BaseWithVtable<*mut ::std::os::raw::c_char>, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of DerivedWithNoVirtualMethods", @@ -47,6 +48,7 @@ impl Default for DerivedWithNoVirtualMethods { pub struct DerivedWithVirtualMethods { pub _base: BaseWithVtable<*mut ::std::os::raw::c_char>, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of DerivedWithVirtualMethods", @@ -89,6 +91,7 @@ pub struct DerivedWithVtable { pub vtable_: *const DerivedWithVtable__bindgen_vtable, pub _base: BaseWithoutVtable<*mut ::std::os::raw::c_char>, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of DerivedWithVtable"][::std::mem::size_of::() - 16usize]; [ @@ -110,6 +113,7 @@ impl Default for DerivedWithVtable { pub struct DerivedWithoutVtable { pub _base: BaseWithoutVtable<*mut ::std::os::raw::c_char>, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of DerivedWithoutVtable", @@ -127,6 +131,7 @@ impl Default for DerivedWithoutVtable { } } } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: BaseWithVtable_open0_ptr_char_close0", @@ -135,6 +140,7 @@ const _: () = { "Align of template specialization: BaseWithVtable_open0_ptr_char_close0", ][::std::mem::align_of::>() - 8usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: BaseWithVtable_open0_ptr_char_close0", @@ -143,6 +149,7 @@ const _: () = { "Align of template specialization: BaseWithVtable_open0_ptr_char_close0", ][::std::mem::align_of::>() - 8usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: BaseWithoutVtable_open0_ptr_char_close0", @@ -151,6 +158,7 @@ const _: () = { "Align of template specialization: BaseWithoutVtable_open0_ptr_char_close0", ][::std::mem::align_of::>() - 8usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: BaseWithoutVtable_open0_ptr_char_close0", diff --git a/bindgen-tests/tests/expectations/tests/inherit_multiple_interfaces.rs b/bindgen-tests/tests/expectations/tests/inherit_multiple_interfaces.rs index a4b0d2a867..da9e519156 100644 --- a/bindgen-tests/tests/expectations/tests/inherit_multiple_interfaces.rs +++ b/bindgen-tests/tests/expectations/tests/inherit_multiple_interfaces.rs @@ -7,6 +7,7 @@ pub struct A { pub vtable_: *const A__bindgen_vtable, pub member: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of A"][::std::mem::size_of::() - 16usize]; ["Alignment of A"][::std::mem::align_of::() - 8usize]; @@ -29,6 +30,7 @@ pub struct B { pub vtable_: *const B__bindgen_vtable, pub member2: *mut ::std::os::raw::c_void, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of B"][::std::mem::size_of::() - 16usize]; ["Alignment of B"][::std::mem::align_of::() - 8usize]; @@ -50,6 +52,7 @@ pub struct C { pub _base_1: B, pub member3: f32, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of C"][::std::mem::size_of::() - 40usize]; ["Alignment of C"][::std::mem::align_of::() - 8usize]; diff --git a/bindgen-tests/tests/expectations/tests/inherit_typedef.rs b/bindgen-tests/tests/expectations/tests/inherit_typedef.rs index e82fc06ce9..92320f45ef 100644 --- a/bindgen-tests/tests/expectations/tests/inherit_typedef.rs +++ b/bindgen-tests/tests/expectations/tests/inherit_typedef.rs @@ -4,6 +4,7 @@ pub struct Foo { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Foo"][::std::mem::size_of::() - 1usize]; ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; @@ -14,6 +15,7 @@ pub type TypedefedFoo = Foo; pub struct Bar { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Bar"][::std::mem::size_of::() - 1usize]; ["Alignment of Bar"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/inline_namespace.rs b/bindgen-tests/tests/expectations/tests/inline_namespace.rs index 72839492c1..df05ab7b9d 100644 --- a/bindgen-tests/tests/expectations/tests/inline_namespace.rs +++ b/bindgen-tests/tests/expectations/tests/inline_namespace.rs @@ -13,6 +13,7 @@ pub mod root { pub struct Bar { pub baz: root::foo::Ty, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Bar"][::std::mem::size_of::() - 4usize]; ["Alignment of Bar"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/inline_namespace_conservative.rs b/bindgen-tests/tests/expectations/tests/inline_namespace_conservative.rs index 6ac6cb7d6c..6941e74adb 100644 --- a/bindgen-tests/tests/expectations/tests/inline_namespace_conservative.rs +++ b/bindgen-tests/tests/expectations/tests/inline_namespace_conservative.rs @@ -18,6 +18,7 @@ pub mod root { pub struct Bar { pub baz: root::foo::bar::Ty, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Bar"][::std::mem::size_of::() - 4usize]; ["Alignment of Bar"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/inner_const.rs b/bindgen-tests/tests/expectations/tests/inner_const.rs index 157ccce994..f8f0c45a29 100644 --- a/bindgen-tests/tests/expectations/tests/inner_const.rs +++ b/bindgen-tests/tests/expectations/tests/inner_const.rs @@ -12,6 +12,7 @@ extern "C" { #[link_name = "\u{1}_ZN3Foo8whateverE"] pub static mut Foo_whatever: Foo; } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Foo"][::std::mem::size_of::() - 4usize]; ["Alignment of Foo"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/inner_template_self.rs b/bindgen-tests/tests/expectations/tests/inner_template_self.rs index 1c42ebea43..c8f9799be6 100644 --- a/bindgen-tests/tests/expectations/tests/inner_template_self.rs +++ b/bindgen-tests/tests/expectations/tests/inner_template_self.rs @@ -19,6 +19,7 @@ impl Default for LinkedList { pub struct InstantiateIt { pub m_list: LinkedList, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of InstantiateIt"][::std::mem::size_of::() - 16usize]; ["Alignment of InstantiateIt"][::std::mem::align_of::() - 8usize]; @@ -35,6 +36,7 @@ impl Default for InstantiateIt { } } } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: LinkedList_open0_int_close0", diff --git a/bindgen-tests/tests/expectations/tests/issue-1034.rs b/bindgen-tests/tests/expectations/tests/issue-1034.rs index fff0e13ef9..17450a1346 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1034.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1034.rs @@ -89,6 +89,7 @@ pub struct S2 { pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 2usize]>, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of S2"][::std::mem::size_of::() - 2usize]; ["Alignment of S2"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs b/bindgen-tests/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs index 8f9c0489ed..5bdf08d992 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs @@ -89,6 +89,7 @@ pub struct S1 { pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 3usize]>, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of S1"][::std::mem::size_of::() - 3usize]; ["Alignment of S1"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/issue-1118-using-forward-decl.rs b/bindgen-tests/tests/expectations/tests/issue-1118-using-forward-decl.rs index 13350e2b5c..7356aa679a 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1118-using-forward-decl.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1118-using-forward-decl.rs @@ -5,6 +5,7 @@ pub type c = nsTArray; pub struct nsTArray_base { pub d: *mut ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of nsTArray_base"][::std::mem::size_of::() - 8usize]; ["Alignment of nsTArray_base"][::std::mem::align_of::() - 8usize]; @@ -40,6 +41,7 @@ impl Default for nsTArray { pub struct nsIContent { pub foo: nsTArray, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of nsIContent"][::std::mem::size_of::() - 8usize]; ["Alignment of nsIContent"][::std::mem::align_of::() - 8usize]; @@ -60,6 +62,7 @@ extern "C" { #[link_name = "\u{1}_Z35Gecko_GetAnonymousContentForElementv"] pub fn Gecko_GetAnonymousContentForElement() -> *mut nsTArray; } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: nsTArray_open0_ptr_nsIContent_close0", @@ -68,6 +71,7 @@ const _: () = { "Align of template specialization: nsTArray_open0_ptr_nsIContent_close0", ][::std::mem::align_of::() - 8usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: nsTArray_open0_ptr_nsIContent_close0", diff --git a/bindgen-tests/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs b/bindgen-tests/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs index eef11c24c3..10c769c38c 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1197-pure-virtual-stuff.rs @@ -6,6 +6,7 @@ pub struct Foo__bindgen_vtable(::std::os::raw::c_void); pub struct Foo { pub vtable_: *const Foo__bindgen_vtable, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Foo"][::std::mem::size_of::() - 8usize]; ["Alignment of Foo"][::std::mem::align_of::() - 8usize]; diff --git a/bindgen-tests/tests/expectations/tests/issue-1216-variadic-member.rs b/bindgen-tests/tests/expectations/tests/issue-1216-variadic-member.rs index 25fba1d1f1..e3fe803654 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1216-variadic-member.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1216-variadic-member.rs @@ -14,6 +14,7 @@ pub struct Foo { ), >, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Foo"][::std::mem::size_of::() - 8usize]; ["Alignment of Foo"][::std::mem::align_of::() - 8usize]; diff --git a/bindgen-tests/tests/expectations/tests/issue-1281.rs b/bindgen-tests/tests/expectations/tests/issue-1281.rs index e5f82313e6..03c80d21fb 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1281.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1281.rs @@ -9,11 +9,13 @@ pub struct bar { pub struct foo { pub foo: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo"][::std::mem::size_of::() - 4usize]; ["Alignment of foo"][::std::mem::align_of::() - 4usize]; ["Offset of field: foo::foo"][::std::mem::offset_of!(foo, foo) - 0usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of bar"][::std::mem::size_of::() - 4usize]; ["Alignment of bar"][::std::mem::align_of::() - 4usize]; @@ -25,6 +27,7 @@ pub type bar_t = bar; pub struct baz { pub f: foo, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of baz"][::std::mem::size_of::() - 4usize]; ["Alignment of baz"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/issue-1285.rs b/bindgen-tests/tests/expectations/tests/issue-1285.rs index 5cd95f777f..6520163259 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1285.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1285.rs @@ -10,6 +10,7 @@ pub union foo__bindgen_ty_1 { pub a: ::std::os::raw::c_uint, pub b: ::std::os::raw::c_ushort, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo__bindgen_ty_1"][::std::mem::size_of::() - 4usize]; [ @@ -31,6 +32,7 @@ impl Default for foo__bindgen_ty_1 { } } } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo"][::std::mem::size_of::() - 4usize]; ["Alignment of foo"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/issue-1382-rust-primitive-types.rs b/bindgen-tests/tests/expectations/tests/issue-1382-rust-primitive-types.rs index 094a6d2c94..277978d93c 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1382-rust-primitive-types.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1382-rust-primitive-types.rs @@ -25,6 +25,7 @@ pub struct Foo { pub f32_: ::std::os::raw::c_int, pub f64_: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Foo"][::std::mem::size_of::() - 56usize]; ["Alignment of Foo"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/issue-1443.rs b/bindgen-tests/tests/expectations/tests/issue-1443.rs index 9412d58f5d..ee1ffca8e5 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1443.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1443.rs @@ -10,6 +10,7 @@ pub struct Bar { pub f: *const Foo, pub m: ::std::os::raw::c_uint, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Bar"][::std::mem::size_of::() - 16usize]; ["Alignment of Bar"][::std::mem::align_of::() - 8usize]; @@ -31,6 +32,7 @@ pub struct Baz { pub f: *mut Foo, pub m: ::std::os::raw::c_uint, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Baz"][::std::mem::size_of::() - 16usize]; ["Alignment of Baz"][::std::mem::align_of::() - 8usize]; @@ -52,6 +54,7 @@ pub struct Tar { pub f: *const Foo, pub m: ::std::os::raw::c_uint, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Tar"][::std::mem::size_of::() - 16usize]; ["Alignment of Tar"][::std::mem::align_of::() - 8usize]; @@ -73,6 +76,7 @@ pub struct Taz { pub f: *mut Foo, pub m: ::std::os::raw::c_uint, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Taz"][::std::mem::size_of::() - 16usize]; ["Alignment of Taz"][::std::mem::align_of::() - 8usize]; diff --git a/bindgen-tests/tests/expectations/tests/issue-1454.rs b/bindgen-tests/tests/expectations/tests/issue-1454.rs index caa0339662..325ccfd977 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1454.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1454.rs @@ -7,6 +7,7 @@ pub struct extern_type; pub struct local_type { pub inner: extern_type, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of local_type"][::std::mem::size_of::() - 0usize]; ["Alignment of local_type"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/issue-1498.rs b/bindgen-tests/tests/expectations/tests/issue-1498.rs index 993777da46..286d2eb6ee 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1498.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1498.rs @@ -24,6 +24,7 @@ pub union rte_memseg__bindgen_ty_1 { ///< Makes sure addr is always 64 bits pub addr_64: u64, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of rte_memseg__bindgen_ty_1", @@ -47,6 +48,7 @@ impl Default for rte_memseg__bindgen_ty_1 { } } } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of rte_memseg"][::std::mem::size_of::() - 44usize]; ["Alignment of rte_memseg"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/issue-1947.rs b/bindgen-tests/tests/expectations/tests/issue-1947.rs index 46925bc19e..32f9bbe146 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1947.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1947.rs @@ -96,6 +96,7 @@ pub struct V56AMDY { pub _bitfield_2: __BindgenBitfieldUnit<[u8; 3usize]>, pub _rB_: U8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of V56AMDY"][::std::mem::size_of::() - 8usize]; ["Alignment of V56AMDY"][::std::mem::align_of::() - 2usize]; diff --git a/bindgen-tests/tests/expectations/tests/issue-1977-larger-arrays.rs b/bindgen-tests/tests/expectations/tests/issue-1977-larger-arrays.rs index 077d2a5ccb..df7a2192ed 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1977-larger-arrays.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1977-larger-arrays.rs @@ -4,6 +4,7 @@ pub struct S { pub large_array: [::std::os::raw::c_char; 33usize], } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of S"][::std::mem::size_of::() - 33usize]; ["Alignment of S"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/issue-1995.rs b/bindgen-tests/tests/expectations/tests/issue-1995.rs index a598f71b86..0e36bdd9c9 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1995.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1995.rs @@ -11,6 +11,7 @@ pub const FOO: ::std::os::raw::c_int = 1; pub struct Bar { pub baz: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Bar"][::std::mem::size_of::() - 4usize]; ["Alignment of Bar"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/issue-2019.rs b/bindgen-tests/tests/expectations/tests/issue-2019.rs index 72fe8bf1b9..88921d615a 100644 --- a/bindgen-tests/tests/expectations/tests/issue-2019.rs +++ b/bindgen-tests/tests/expectations/tests/issue-2019.rs @@ -4,6 +4,7 @@ pub struct A { pub a: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of A"][::std::mem::size_of::() - 4usize]; ["Alignment of A"][::std::mem::align_of::() - 4usize]; @@ -24,6 +25,7 @@ impl A { pub struct B { pub b: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of B"][::std::mem::size_of::() - 4usize]; ["Alignment of B"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/issue-2556.rs b/bindgen-tests/tests/expectations/tests/issue-2556.rs index b78fa4237d..5f7c1d369a 100644 --- a/bindgen-tests/tests/expectations/tests/issue-2556.rs +++ b/bindgen-tests/tests/expectations/tests/issue-2556.rs @@ -9,6 +9,7 @@ pub mod root { pub width: ::std::os::raw::c_int, pub height: ::std::os::raw::c_int, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of nsSize"][::std::mem::size_of::() - 8usize]; ["Alignment of nsSize"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/issue-2695.rs b/bindgen-tests/tests/expectations/tests/issue-2695.rs index daf218356a..20a016dbab 100644 --- a/bindgen-tests/tests/expectations/tests/issue-2695.rs +++ b/bindgen-tests/tests/expectations/tests/issue-2695.rs @@ -8,6 +8,7 @@ pub struct Test { pub c: ::std::os::raw::c_char, pub __bindgen_padding_0: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Test"][::std::mem::size_of::() - 12usize]; ["Alignment of Test"][::std::mem::align_of::() - 2usize]; diff --git a/bindgen-tests/tests/expectations/tests/issue-410.rs b/bindgen-tests/tests/expectations/tests/issue-410.rs index 28a2893035..e52aa25a13 100644 --- a/bindgen-tests/tests/expectations/tests/issue-410.rs +++ b/bindgen-tests/tests/expectations/tests/issue-410.rs @@ -11,6 +11,7 @@ pub mod root { pub struct Value { pub _address: u8, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Value"][::std::mem::size_of::() - 1usize]; ["Alignment of Value"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/issue-447.rs b/bindgen-tests/tests/expectations/tests/issue-447.rs index 0231b40aa8..305fa739d0 100644 --- a/bindgen-tests/tests/expectations/tests/issue-447.rs +++ b/bindgen-tests/tests/expectations/tests/issue-447.rs @@ -14,6 +14,7 @@ pub mod root { pub struct GuardObjectNotifier { pub _address: u8, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of GuardObjectNotifier", @@ -29,6 +30,7 @@ pub mod root { pub struct JSAutoCompartment { pub _address: u8, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of JSAutoCompartment", diff --git a/bindgen-tests/tests/expectations/tests/issue-537.rs b/bindgen-tests/tests/expectations/tests/issue-537.rs index 6a7bc3edfd..d630b9ea4c 100644 --- a/bindgen-tests/tests/expectations/tests/issue-537.rs +++ b/bindgen-tests/tests/expectations/tests/issue-537.rs @@ -6,6 +6,7 @@ pub struct AlignedToOne { pub i: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of AlignedToOne"][::std::mem::size_of::() - 4usize]; ["Alignment of AlignedToOne"][::std::mem::align_of::() - 1usize]; @@ -20,6 +21,7 @@ const _: () = { pub struct AlignedToTwo { pub i: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of AlignedToTwo"][::std::mem::size_of::() - 4usize]; ["Alignment of AlignedToTwo"][::std::mem::align_of::() - 2usize]; @@ -36,6 +38,7 @@ pub struct PackedToOne { pub x: ::std::os::raw::c_int, pub y: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of PackedToOne"][::std::mem::size_of::() - 8usize]; ["Alignment of PackedToOne"][::std::mem::align_of::() - 1usize]; @@ -51,6 +54,7 @@ pub struct PackedToTwo { pub x: ::std::os::raw::c_int, pub y: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of PackedToTwo"][::std::mem::size_of::() - 8usize]; ["Alignment of PackedToTwo"][::std::mem::align_of::() - 2usize]; diff --git a/bindgen-tests/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs b/bindgen-tests/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs index ffbbe792ca..567325b82d 100644 --- a/bindgen-tests/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs +++ b/bindgen-tests/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs @@ -27,6 +27,7 @@ impl Default for JS_Base { pub struct JS_AutoIdVector { pub _base: JS_Base, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of JS_AutoIdVector"][::std::mem::size_of::() - 1usize]; ["Alignment of JS_AutoIdVector"][::std::mem::align_of::() - 1usize]; @@ -40,6 +41,7 @@ impl Default for JS_AutoIdVector { } } } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: JS_Base_open0_int_close0", diff --git a/bindgen-tests/tests/expectations/tests/issue-573-layout-test-failures.rs b/bindgen-tests/tests/expectations/tests/issue-573-layout-test-failures.rs index 2c5936e761..aa5f457792 100644 --- a/bindgen-tests/tests/expectations/tests/issue-573-layout-test-failures.rs +++ b/bindgen-tests/tests/expectations/tests/issue-573-layout-test-failures.rs @@ -9,6 +9,7 @@ pub struct Outer { pub struct AutoIdVector { pub ar: Outer, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of AutoIdVector"][::std::mem::size_of::() - 1usize]; ["Alignment of AutoIdVector"][::std::mem::align_of::() - 1usize]; @@ -16,6 +17,7 @@ const _: () = { "Offset of field: AutoIdVector::ar", ][::std::mem::offset_of!(AutoIdVector, ar) - 0usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: Outer_open0_int_close0", diff --git a/bindgen-tests/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs b/bindgen-tests/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs index bcc8ecdb75..85f66c5a73 100644 --- a/bindgen-tests/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs +++ b/bindgen-tests/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs @@ -9,6 +9,7 @@ pub struct a { pub struct _bindgen_ty_1 { pub ar: a, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of _bindgen_ty_1"][::std::mem::size_of::<_bindgen_ty_1>() - 1usize]; ["Alignment of _bindgen_ty_1"][::std::mem::align_of::<_bindgen_ty_1>() - 1usize]; @@ -19,6 +20,7 @@ const _: () = { extern "C" { pub static mut AutoIdVector: _bindgen_ty_1; } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: a_open0_int_close0", diff --git a/bindgen-tests/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs b/bindgen-tests/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs index cfa6a195e2..e53b10d4af 100644 --- a/bindgen-tests/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs +++ b/bindgen-tests/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs @@ -6,6 +6,7 @@ pub struct A { pub _address: u8, } pub type A_a = b; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of A"][::std::mem::size_of::() - 1usize]; ["Alignment of A"][::std::mem::align_of::() - 1usize]; @@ -33,6 +34,7 @@ pub struct f { pub struct g { pub h: f, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of g"][::std::mem::size_of::() - 1usize]; ["Alignment of g"][::std::mem::align_of::() - 1usize]; @@ -51,6 +53,7 @@ impl Default for g { pub struct b { pub _base: g, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of b"][::std::mem::size_of::() - 1usize]; ["Alignment of b"][::std::mem::align_of::() - 1usize]; @@ -68,6 +71,7 @@ extern "C" { #[link_name = "\u{1}_Z25Servo_Element_GetSnapshotv"] pub fn Servo_Element_GetSnapshot() -> A; } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: f_open0_e_open1_int_close1_close0", diff --git a/bindgen-tests/tests/expectations/tests/issue-639-typedef-anon-field.rs b/bindgen-tests/tests/expectations/tests/issue-639-typedef-anon-field.rs index 3909ce4e2f..e940db1103 100644 --- a/bindgen-tests/tests/expectations/tests/issue-639-typedef-anon-field.rs +++ b/bindgen-tests/tests/expectations/tests/issue-639-typedef-anon-field.rs @@ -9,11 +9,13 @@ pub struct Foo { pub struct Foo_Bar { pub abc: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Foo_Bar"][::std::mem::size_of::() - 4usize]; ["Alignment of Foo_Bar"][::std::mem::align_of::() - 4usize]; ["Offset of field: Foo_Bar::abc"][::std::mem::offset_of!(Foo_Bar, abc) - 0usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Foo"][::std::mem::size_of::() - 4usize]; ["Alignment of Foo"][::std::mem::align_of::() - 4usize]; @@ -29,11 +31,13 @@ pub struct Baz { pub struct Baz_Bar { pub abc: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Baz_Bar"][::std::mem::size_of::() - 4usize]; ["Alignment of Baz_Bar"][::std::mem::align_of::() - 4usize]; ["Offset of field: Baz_Bar::abc"][::std::mem::offset_of!(Baz_Bar, abc) - 0usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Baz"][::std::mem::size_of::() - 1usize]; ["Alignment of Baz"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/issue-643-inner-struct.rs b/bindgen-tests/tests/expectations/tests/issue-643-inner-struct.rs index 3e3f2ada59..0012c8f6aa 100644 --- a/bindgen-tests/tests/expectations/tests/issue-643-inner-struct.rs +++ b/bindgen-tests/tests/expectations/tests/issue-643-inner-struct.rs @@ -42,6 +42,7 @@ pub struct rte_ring { pub struct rte_ring_prod { pub watermark: ::std::os::raw::c_uint, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of rte_ring_prod"][::std::mem::size_of::() - 4usize]; ["Alignment of rte_ring_prod"][::std::mem::align_of::() - 4usize]; @@ -54,6 +55,7 @@ const _: () = { pub struct rte_ring_cons { pub sc_dequeue: ::std::os::raw::c_uint, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of rte_ring_cons"][::std::mem::size_of::() - 4usize]; ["Alignment of rte_ring_cons"][::std::mem::align_of::() - 4usize]; @@ -61,6 +63,7 @@ const _: () = { "Offset of field: rte_ring_cons::sc_dequeue", ][::std::mem::offset_of!(rte_ring_cons, sc_dequeue) - 0usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of rte_ring"][::std::mem::size_of::() - 16usize]; ["Alignment of rte_ring"][::std::mem::align_of::() - 8usize]; diff --git a/bindgen-tests/tests/expectations/tests/issue-674-1.rs b/bindgen-tests/tests/expectations/tests/issue-674-1.rs index 0c45f11f52..1a3dce44d0 100644 --- a/bindgen-tests/tests/expectations/tests/issue-674-1.rs +++ b/bindgen-tests/tests/expectations/tests/issue-674-1.rs @@ -18,6 +18,7 @@ pub mod root { pub struct CapturingContentInfo { pub a: u8, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of CapturingContentInfo", diff --git a/bindgen-tests/tests/expectations/tests/issue-674-2.rs b/bindgen-tests/tests/expectations/tests/issue-674-2.rs index 7a42d02584..980928fe97 100644 --- a/bindgen-tests/tests/expectations/tests/issue-674-2.rs +++ b/bindgen-tests/tests/expectations/tests/issue-674-2.rs @@ -18,6 +18,7 @@ pub mod root { pub struct c { pub b: u8, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of c"][::std::mem::size_of::() - 1usize]; ["Alignment of c"][::std::mem::align_of::() - 1usize]; @@ -28,6 +29,7 @@ pub mod root { pub struct B { pub a: root::c, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of B"][::std::mem::size_of::() - 1usize]; ["Alignment of B"][::std::mem::align_of::() - 1usize]; @@ -38,6 +40,7 @@ pub mod root { pub struct StaticRefPtr { pub _address: u8, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: StaticRefPtr_open0_B_close0", diff --git a/bindgen-tests/tests/expectations/tests/issue-674-3.rs b/bindgen-tests/tests/expectations/tests/issue-674-3.rs index 8b9f2705bc..4e2f26a46f 100644 --- a/bindgen-tests/tests/expectations/tests/issue-674-3.rs +++ b/bindgen-tests/tests/expectations/tests/issue-674-3.rs @@ -14,6 +14,7 @@ pub mod root { pub struct a { pub b: u8, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of a"][::std::mem::size_of::() - 1usize]; ["Alignment of a"][::std::mem::align_of::() - 1usize]; @@ -24,6 +25,7 @@ pub mod root { pub struct nsCSSValue { pub c: root::a, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of nsCSSValue"][::std::mem::size_of::() - 1usize]; ["Alignment of nsCSSValue"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/issue-691-template-parameter-virtual.rs b/bindgen-tests/tests/expectations/tests/issue-691-template-parameter-virtual.rs index 9c3b00d163..1313d61168 100644 --- a/bindgen-tests/tests/expectations/tests/issue-691-template-parameter-virtual.rs +++ b/bindgen-tests/tests/expectations/tests/issue-691-template-parameter-virtual.rs @@ -6,6 +6,7 @@ pub struct VirtualMethods__bindgen_vtable {} pub struct VirtualMethods { pub vtable_: *const VirtualMethods__bindgen_vtable, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of VirtualMethods"][::std::mem::size_of::() - 8usize]; ["Alignment of VirtualMethods"][::std::mem::align_of::() - 8usize]; @@ -29,6 +30,7 @@ pub struct Set { pub struct ServoElementSnapshotTable { pub _base: Set, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of ServoElementSnapshotTable", @@ -46,6 +48,7 @@ impl Default for ServoElementSnapshotTable { } } } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: Set_open0_VirtualMethods_close0", diff --git a/bindgen-tests/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs b/bindgen-tests/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs index be1eeee425..84dc763e6f 100644 --- a/bindgen-tests/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs @@ -90,6 +90,7 @@ pub struct Foo { pub _bitfield_align_1: [u64; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 32usize]>, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Foo"][::std::mem::size_of::() - 32usize]; ["Alignment of Foo"][::std::mem::align_of::() - 8usize]; diff --git a/bindgen-tests/tests/expectations/tests/issue-769-bad-instantiation-test.rs b/bindgen-tests/tests/expectations/tests/issue-769-bad-instantiation-test.rs index cdfe5f652a..59a1d9afa3 100644 --- a/bindgen-tests/tests/expectations/tests/issue-769-bad-instantiation-test.rs +++ b/bindgen-tests/tests/expectations/tests/issue-769-bad-instantiation-test.rs @@ -19,6 +19,7 @@ pub mod root { } } pub type AutoValueVector_Alias = ::std::os::raw::c_int; + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: Rooted_open0_int_close0", @@ -27,6 +28,7 @@ pub mod root { "Align of template specialization: Rooted_open0_int_close0", ][::std::mem::align_of::>() - 4usize]; }; + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: Rooted_open0_AutoValueVector_Alias_close0", diff --git a/bindgen-tests/tests/expectations/tests/issue-801-opaque-sloppiness.rs b/bindgen-tests/tests/expectations/tests/issue-801-opaque-sloppiness.rs index 3d39c6642b..b08ef2fd1d 100644 --- a/bindgen-tests/tests/expectations/tests/issue-801-opaque-sloppiness.rs +++ b/bindgen-tests/tests/expectations/tests/issue-801-opaque-sloppiness.rs @@ -10,6 +10,7 @@ pub struct A { pub struct B { pub _bindgen_opaque_blob: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of B"][::std::mem::size_of::() - 1usize]; ["Alignment of B"][::std::mem::align_of::() - 1usize]; @@ -23,6 +24,7 @@ extern "C" { pub struct C { pub b: B, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of C"][::std::mem::size_of::() - 1usize]; ["Alignment of C"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs b/bindgen-tests/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs index c268b0cbad..c0150a73f0 100644 --- a/bindgen-tests/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs +++ b/bindgen-tests/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs @@ -4,6 +4,7 @@ pub struct Pupper { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Pupper"][::std::mem::size_of::() - 1usize]; ["Alignment of Pupper"][::std::mem::align_of::() - 1usize]; @@ -13,6 +14,7 @@ const _: () = { pub struct Doggo { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Doggo"][::std::mem::size_of::() - 1usize]; ["Alignment of Doggo"][::std::mem::align_of::() - 1usize]; @@ -22,6 +24,7 @@ const _: () = { pub struct SuchWow { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of SuchWow"][::std::mem::size_of::() - 1usize]; ["Alignment of SuchWow"][::std::mem::align_of::() - 1usize]; @@ -32,6 +35,7 @@ const _: () = { pub struct Opaque { pub _bindgen_opaque_blob: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Opaque"][::std::mem::size_of::() - 1usize]; ["Alignment of Opaque"][::std::mem::align_of::() - 1usize]; @@ -65,6 +69,7 @@ extern "C" { pub struct Allowlisted { pub some_member: Opaque, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Allowlisted"][::std::mem::size_of::() - 1usize]; ["Alignment of Allowlisted"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/issue-816.rs b/bindgen-tests/tests/expectations/tests/issue-816.rs index 219bd3c89e..1f1112eff5 100644 --- a/bindgen-tests/tests/expectations/tests/issue-816.rs +++ b/bindgen-tests/tests/expectations/tests/issue-816.rs @@ -90,6 +90,7 @@ pub struct capabilities { pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 16usize]>, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of capabilities"][::std::mem::size_of::() - 16usize]; ["Alignment of capabilities"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/issue-826-generating-methods-when-asked-not-to.rs b/bindgen-tests/tests/expectations/tests/issue-826-generating-methods-when-asked-not-to.rs index 30de3dce72..551dff82cf 100644 --- a/bindgen-tests/tests/expectations/tests/issue-826-generating-methods-when-asked-not-to.rs +++ b/bindgen-tests/tests/expectations/tests/issue-826-generating-methods-when-asked-not-to.rs @@ -4,6 +4,7 @@ pub struct Foo { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Foo"][::std::mem::size_of::() - 1usize]; ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/issue-834.rs b/bindgen-tests/tests/expectations/tests/issue-834.rs index b8cbd24714..4119a450e0 100644 --- a/bindgen-tests/tests/expectations/tests/issue-834.rs +++ b/bindgen-tests/tests/expectations/tests/issue-834.rs @@ -4,6 +4,7 @@ pub struct U { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of U"][::std::mem::size_of::() - 1usize]; ["Alignment of U"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/issue-888-enum-var-decl-jump.rs b/bindgen-tests/tests/expectations/tests/issue-888-enum-var-decl-jump.rs index 66a72aa845..0a0d05f9f9 100644 --- a/bindgen-tests/tests/expectations/tests/issue-888-enum-var-decl-jump.rs +++ b/bindgen-tests/tests/expectations/tests/issue-888-enum-var-decl-jump.rs @@ -15,6 +15,7 @@ pub mod root { #[link_name = "\u{1}_ZN6Halide4Type1bE"] pub static mut Type_b: root::a; } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Type"][::std::mem::size_of::() - 1usize]; ["Alignment of Type"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs b/bindgen-tests/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs index 778b9514a0..5e8dde04e3 100644 --- a/bindgen-tests/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs +++ b/bindgen-tests/tests/expectations/tests/issue-944-derive-copy-and-blocklisting.rs @@ -5,6 +5,7 @@ pub struct BlocklistMe(u8); pub struct ShouldNotBeCopy { pub a: BlocklistMe, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of ShouldNotBeCopy"][::std::mem::size_of::() - 1usize]; ["Alignment of ShouldNotBeCopy"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/issue-946.rs b/bindgen-tests/tests/expectations/tests/issue-946.rs index 042feccbc1..bdd56c0326 100644 --- a/bindgen-tests/tests/expectations/tests/issue-946.rs +++ b/bindgen-tests/tests/expectations/tests/issue-946.rs @@ -2,6 +2,7 @@ #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct foo {} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo"][::std::mem::size_of::() - 0usize]; ["Alignment of foo"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/issue_311.rs b/bindgen-tests/tests/expectations/tests/issue_311.rs index fd2e6e80fb..2e0114e43e 100644 --- a/bindgen-tests/tests/expectations/tests/issue_311.rs +++ b/bindgen-tests/tests/expectations/tests/issue_311.rs @@ -13,6 +13,7 @@ pub mod root { pub struct jsval_layout__bindgen_ty_1 { pub _address: u8, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of jsval_layout__bindgen_ty_1", @@ -21,6 +22,7 @@ pub mod root { "Alignment of jsval_layout__bindgen_ty_1", ][::std::mem::align_of::() - 1usize]; }; + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of jsval_layout"][::std::mem::size_of::() - 1usize]; ["Alignment of jsval_layout"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs index 93fcc92b48..e7cb9af39e 100644 --- a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs +++ b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs @@ -186,6 +186,7 @@ pub struct jsval_layout__bindgen_ty_1 { pub _bitfield_align_1: [u64; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 8usize]>, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of jsval_layout__bindgen_ty_1", @@ -265,6 +266,7 @@ pub union jsval_layout__bindgen_ty_2__bindgen_ty_1 { pub u32_: u32, pub why: JSWhyMagic, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of jsval_layout__bindgen_ty_2__bindgen_ty_1", @@ -291,6 +293,7 @@ impl Default for jsval_layout__bindgen_ty_2__bindgen_ty_1 { } } } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of jsval_layout__bindgen_ty_2", @@ -311,6 +314,7 @@ impl Default for jsval_layout__bindgen_ty_2 { } } } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of jsval_layout"][::std::mem::size_of::() - 8usize]; ["Alignment of jsval_layout"][::std::mem::align_of::() - 8usize]; @@ -350,6 +354,7 @@ impl Default for jsval_layout { pub struct Value { pub data: jsval_layout, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Value"][::std::mem::size_of::() - 8usize]; ["Alignment of Value"][::std::mem::align_of::() - 8usize]; diff --git a/bindgen-tests/tests/expectations/tests/layout_align.rs b/bindgen-tests/tests/expectations/tests/layout_align.rs index f7f22120ad..c641ff843f 100644 --- a/bindgen-tests/tests/expectations/tests/layout_align.rs +++ b/bindgen-tests/tests/expectations/tests/layout_align.rs @@ -127,6 +127,7 @@ pub struct rte_kni_fifo { ///< The buffer contains mbuf pointers pub buffer: __IncompleteArrayField<*mut ::std::os::raw::c_void>, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of rte_kni_fifo"][::std::mem::size_of::() - 16usize]; ["Alignment of rte_kni_fifo"][::std::mem::align_of::() - 8usize]; @@ -165,6 +166,7 @@ pub struct rte_eth_link { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub __bindgen_padding_0: [u8; 3usize], } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of rte_eth_link"][::std::mem::size_of::() - 8usize]; ["Alignment of rte_eth_link"][::std::mem::align_of::() - 8usize]; diff --git a/bindgen-tests/tests/expectations/tests/layout_arp.rs b/bindgen-tests/tests/expectations/tests/layout_arp.rs index c48fd0e24e..c94dc2ce24 100644 --- a/bindgen-tests/tests/expectations/tests/layout_arp.rs +++ b/bindgen-tests/tests/expectations/tests/layout_arp.rs @@ -22,6 +22,7 @@ pub struct ether_addr { ///< Addr bytes in tx order pub addr_bytes: [u8; 6usize], } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of ether_addr"][::std::mem::size_of::() - 6usize]; ["Alignment of ether_addr"][::std::mem::align_of::() - 1usize]; @@ -42,6 +43,7 @@ pub struct arp_ipv4 { ///< target IP address pub arp_tip: u32, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of arp_ipv4"][::std::mem::size_of::() - 20usize]; ["Alignment of arp_ipv4"][::std::mem::align_of::() - 1usize]; @@ -69,6 +71,7 @@ pub struct arp_hdr { pub arp_op: u16, pub arp_data: arp_ipv4, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of arp_hdr"][::std::mem::size_of::() - 28usize]; ["Alignment of arp_hdr"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/layout_cmdline_token.rs b/bindgen-tests/tests/expectations/tests/layout_cmdline_token.rs index e187a4a7f6..fb7b3bf584 100644 --- a/bindgen-tests/tests/expectations/tests/layout_cmdline_token.rs +++ b/bindgen-tests/tests/expectations/tests/layout_cmdline_token.rs @@ -7,6 +7,7 @@ pub struct cmdline_token_hdr { pub ops: *mut cmdline_token_ops, pub offset: ::std::os::raw::c_uint, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of cmdline_token_hdr"][::std::mem::size_of::() - 16usize]; [ @@ -84,6 +85,7 @@ pub struct cmdline_token_ops { ) -> ::std::os::raw::c_int, >, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of cmdline_token_ops"][::std::mem::size_of::() - 32usize]; [ @@ -119,6 +121,7 @@ pub enum cmdline_numtype { pub struct cmdline_token_num_data { pub type_: cmdline_numtype, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of cmdline_token_num_data", @@ -145,6 +148,7 @@ pub struct cmdline_token_num { pub hdr: cmdline_token_hdr, pub num_data: cmdline_token_num_data, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of cmdline_token_num"][::std::mem::size_of::() - 24usize]; [ diff --git a/bindgen-tests/tests/expectations/tests/layout_mbuf.rs b/bindgen-tests/tests/expectations/tests/layout_mbuf.rs index c512ad33a2..aa2c121c2d 100644 --- a/bindgen-tests/tests/expectations/tests/layout_mbuf.rs +++ b/bindgen-tests/tests/expectations/tests/layout_mbuf.rs @@ -96,6 +96,7 @@ pub struct rte_atomic16_t { ///< An internal counter value. pub cnt: i16, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of rte_atomic16_t"][::std::mem::size_of::() - 2usize]; ["Alignment of rte_atomic16_t"][::std::mem::align_of::() - 2usize]; @@ -164,6 +165,7 @@ pub union rte_mbuf__bindgen_ty_1 { ///< Non-atomically accessed refcnt pub refcnt: u16, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of rte_mbuf__bindgen_ty_1", @@ -201,6 +203,7 @@ pub struct rte_mbuf__bindgen_ty_2__bindgen_ty_1 { pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of rte_mbuf__bindgen_ty_2__bindgen_ty_1", @@ -370,6 +373,7 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { __bindgen_bitfield_unit } } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of rte_mbuf__bindgen_ty_2", @@ -420,6 +424,7 @@ pub struct rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 { pub hash: u16, pub id: u16, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1", @@ -442,6 +447,7 @@ const _: () = { rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1, id ) - 2usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1", @@ -465,6 +471,7 @@ impl Default for rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 { } } } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of rte_mbuf__bindgen_ty_3__bindgen_ty_1", @@ -491,6 +498,7 @@ pub struct rte_mbuf__bindgen_ty_3__bindgen_ty_2 { pub lo: u32, pub hi: u32, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of rte_mbuf__bindgen_ty_3__bindgen_ty_2", @@ -505,6 +513,7 @@ const _: () = { "Offset of field: rte_mbuf__bindgen_ty_3__bindgen_ty_2::hi", ][::std::mem::offset_of!(rte_mbuf__bindgen_ty_3__bindgen_ty_2, hi) - 4usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of rte_mbuf__bindgen_ty_3", @@ -542,6 +551,7 @@ pub union rte_mbuf__bindgen_ty_4 { ///< Allow 8-byte userdata on 32-bit pub udata64: u64, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of rte_mbuf__bindgen_ty_4", @@ -579,6 +589,7 @@ pub struct rte_mbuf__bindgen_ty_5__bindgen_ty_1 { pub _bitfield_align_1: [u16; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 7usize]>, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of rte_mbuf__bindgen_ty_5__bindgen_ty_1", @@ -725,6 +736,7 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { __bindgen_bitfield_unit } } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of rte_mbuf__bindgen_ty_5", @@ -745,6 +757,7 @@ impl Default for rte_mbuf__bindgen_ty_5 { } } } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of rte_mbuf"][::std::mem::size_of::() - 128usize]; ["Alignment of rte_mbuf"][::std::mem::align_of::() - 64usize]; diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/constified-enum-module-overflow.rs b/bindgen-tests/tests/expectations/tests/libclang-9/constified-enum-module-overflow.rs index a4bdacf3a7..4f8296c65c 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/constified-enum-module-overflow.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/constified-enum-module-overflow.rs @@ -15,11 +15,13 @@ pub type C_U = B; pub struct A { pub u: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of A"][::std::mem::size_of::() - 1usize]; ["Alignment of A"][::std::mem::align_of::() - 1usize]; ["Offset of field: A::u"][::std::mem::offset_of!(A, u) - 0usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: C_open0_A_close0", diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/ptr32-has-different-size.rs b/bindgen-tests/tests/expectations/tests/libclang-9/ptr32-has-different-size.rs index 1ffc5249bc..f55f88f496 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/ptr32-has-different-size.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/ptr32-has-different-size.rs @@ -4,6 +4,7 @@ pub struct TEST_STRUCT { pub ptr_32bit: *mut ::std::os::raw::c_void, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of TEST_STRUCT"][::std::mem::size_of::() - 8usize]; ["Alignment of TEST_STRUCT"][::std::mem::align_of::() - 8usize]; diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/struct_typedef_ns.rs b/bindgen-tests/tests/expectations/tests/libclang-9/struct_typedef_ns.rs index 34e44b7417..d93a62e746 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/struct_typedef_ns.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/struct_typedef_ns.rs @@ -11,6 +11,7 @@ pub mod root { pub struct typedef_struct { pub foo: ::std::os::raw::c_int, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of typedef_struct"][::std::mem::size_of::() - 4usize]; [ @@ -34,6 +35,7 @@ pub mod root { pub struct _bindgen_ty_1 { pub foo: ::std::os::raw::c_int, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of _bindgen_ty_1"][::std::mem::size_of::<_bindgen_ty_1>() - 4usize]; [ diff --git a/bindgen-tests/tests/expectations/tests/mangling-linux32.rs b/bindgen-tests/tests/expectations/tests/mangling-linux32.rs index dd34ac92f7..ab1f799694 100644 --- a/bindgen-tests/tests/expectations/tests/mangling-linux32.rs +++ b/bindgen-tests/tests/expectations/tests/mangling-linux32.rs @@ -11,6 +11,7 @@ extern "C" { #[link_name = "\u{1}_ZN3Foo4sBarE"] pub static mut Foo_sBar: bool; } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Foo"][::std::mem::size_of::() - 1usize]; ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/mangling-linux64.rs b/bindgen-tests/tests/expectations/tests/mangling-linux64.rs index dd34ac92f7..ab1f799694 100644 --- a/bindgen-tests/tests/expectations/tests/mangling-linux64.rs +++ b/bindgen-tests/tests/expectations/tests/mangling-linux64.rs @@ -11,6 +11,7 @@ extern "C" { #[link_name = "\u{1}_ZN3Foo4sBarE"] pub static mut Foo_sBar: bool; } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Foo"][::std::mem::size_of::() - 1usize]; ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/mangling-macos.rs b/bindgen-tests/tests/expectations/tests/mangling-macos.rs index 8a95f99249..b5d78cedb5 100644 --- a/bindgen-tests/tests/expectations/tests/mangling-macos.rs +++ b/bindgen-tests/tests/expectations/tests/mangling-macos.rs @@ -11,6 +11,7 @@ extern "C" { #[link_name = "\u{1}__ZN3Foo4sBarE"] pub static mut Foo_sBar: bool; } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Foo"][::std::mem::size_of::() - 1usize]; ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/mangling-win32.rs b/bindgen-tests/tests/expectations/tests/mangling-win32.rs index dddbde0bc7..572b69962c 100644 --- a/bindgen-tests/tests/expectations/tests/mangling-win32.rs +++ b/bindgen-tests/tests/expectations/tests/mangling-win32.rs @@ -11,6 +11,7 @@ extern "C" { #[link_name = "\u{1}?sBar@Foo@@2_NA"] pub static mut Foo_sBar: bool; } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Foo"][::std::mem::size_of::() - 1usize]; ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/mangling-win64.rs b/bindgen-tests/tests/expectations/tests/mangling-win64.rs index 655992271d..1e71710f6c 100644 --- a/bindgen-tests/tests/expectations/tests/mangling-win64.rs +++ b/bindgen-tests/tests/expectations/tests/mangling-win64.rs @@ -11,6 +11,7 @@ extern "C" { #[link_name = "\u{1}?sBar@Foo@@2_NA"] pub static mut Foo_sBar: bool; } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Foo"][::std::mem::size_of::() - 1usize]; ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/merge-extern-blocks.rs b/bindgen-tests/tests/expectations/tests/merge-extern-blocks.rs index 0b2eb59af9..595d865af1 100644 --- a/bindgen-tests/tests/expectations/tests/merge-extern-blocks.rs +++ b/bindgen-tests/tests/expectations/tests/merge-extern-blocks.rs @@ -8,6 +8,7 @@ pub mod root { pub struct Point { pub x: ::std::os::raw::c_int, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Point"][::std::mem::size_of::() - 4usize]; ["Alignment of Point"][::std::mem::align_of::() - 4usize]; @@ -21,6 +22,7 @@ pub mod root { pub struct Point { pub x: ::std::os::raw::c_int, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Point"][::std::mem::size_of::() - 4usize]; ["Alignment of Point"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/method-mangling.rs b/bindgen-tests/tests/expectations/tests/method-mangling.rs index e7127376cd..bde0a0f2ff 100644 --- a/bindgen-tests/tests/expectations/tests/method-mangling.rs +++ b/bindgen-tests/tests/expectations/tests/method-mangling.rs @@ -4,6 +4,7 @@ pub struct Foo { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Foo"][::std::mem::size_of::() - 1usize]; ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/module-allowlisted.rs b/bindgen-tests/tests/expectations/tests/module-allowlisted.rs index 257da9fb31..9ac408dc8f 100644 --- a/bindgen-tests/tests/expectations/tests/module-allowlisted.rs +++ b/bindgen-tests/tests/expectations/tests/module-allowlisted.rs @@ -8,6 +8,7 @@ pub mod root { pub struct Test { pub _address: u8, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Test"][::std::mem::size_of::() - 1usize]; ["Alignment of Test"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/msvc-no-usr.rs b/bindgen-tests/tests/expectations/tests/msvc-no-usr.rs index 29363b07f7..adaa1a07b2 100644 --- a/bindgen-tests/tests/expectations/tests/msvc-no-usr.rs +++ b/bindgen-tests/tests/expectations/tests/msvc-no-usr.rs @@ -4,6 +4,7 @@ pub struct A { pub foo: usize, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of A"][::std::mem::size_of::() - 8usize]; ["Alignment of A"][::std::mem::align_of::() - 8usize]; diff --git a/bindgen-tests/tests/expectations/tests/multiple-inherit-empty-correct-layout.rs b/bindgen-tests/tests/expectations/tests/multiple-inherit-empty-correct-layout.rs index b8963d6499..b0cf27451c 100644 --- a/bindgen-tests/tests/expectations/tests/multiple-inherit-empty-correct-layout.rs +++ b/bindgen-tests/tests/expectations/tests/multiple-inherit-empty-correct-layout.rs @@ -4,6 +4,7 @@ pub struct Foo { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Foo"][::std::mem::size_of::() - 1usize]; ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; @@ -13,6 +14,7 @@ const _: () = { pub struct Bar { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Bar"][::std::mem::size_of::() - 1usize]; ["Alignment of Bar"][::std::mem::align_of::() - 1usize]; @@ -22,6 +24,7 @@ const _: () = { pub struct Baz { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Baz"][::std::mem::size_of::() - 1usize]; ["Alignment of Baz"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/mutable.rs b/bindgen-tests/tests/expectations/tests/mutable.rs index ca59bd15cc..ff98d31f24 100644 --- a/bindgen-tests/tests/expectations/tests/mutable.rs +++ b/bindgen-tests/tests/expectations/tests/mutable.rs @@ -5,6 +5,7 @@ pub struct C { pub m_member: ::std::os::raw::c_int, pub m_other: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of C"][::std::mem::size_of::() - 8usize]; ["Alignment of C"][::std::mem::align_of::() - 4usize]; @@ -16,6 +17,7 @@ const _: () = { pub struct NonCopiable { pub m_member: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of NonCopiable"][::std::mem::size_of::() - 4usize]; ["Alignment of NonCopiable"][::std::mem::align_of::() - 4usize]; @@ -28,6 +30,7 @@ const _: () = { pub struct NonCopiableWithNonCopiableMutableMember { pub m_member: NonCopiable, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of NonCopiableWithNonCopiableMutableMember", diff --git a/bindgen-tests/tests/expectations/tests/namespace.rs b/bindgen-tests/tests/expectations/tests/namespace.rs index 93e201d329..f4f2a76c3e 100644 --- a/bindgen-tests/tests/expectations/tests/namespace.rs +++ b/bindgen-tests/tests/expectations/tests/namespace.rs @@ -25,6 +25,7 @@ pub mod root { pub struct A { pub b: root::whatever::whatever_int_t, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of A"][::std::mem::size_of::() - 4usize]; ["Alignment of A"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/nested.rs b/bindgen-tests/tests/expectations/tests/nested.rs index a083b7b341..5e0a8b07c8 100644 --- a/bindgen-tests/tests/expectations/tests/nested.rs +++ b/bindgen-tests/tests/expectations/tests/nested.rs @@ -4,6 +4,7 @@ pub struct Calc { pub w: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Calc"][::std::mem::size_of::() - 4usize]; ["Alignment of Calc"][::std::mem::align_of::() - 4usize]; @@ -25,6 +26,7 @@ pub struct Test_Size { pub struct Test_Size_Dimension { pub _base: Calc, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of Test_Size_Dimension", @@ -33,6 +35,7 @@ const _: () = { "Alignment of Test_Size_Dimension", ][::std::mem::align_of::() - 4usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Test_Size"][::std::mem::size_of::() - 8usize]; ["Alignment of Test_Size"][::std::mem::align_of::() - 4usize]; @@ -43,6 +46,7 @@ const _: () = { "Offset of field: Test_Size::mHeight", ][::std::mem::offset_of!(Test_Size, mHeight) - 4usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Test"][::std::mem::size_of::() - 1usize]; ["Alignment of Test"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/nested_vtable.rs b/bindgen-tests/tests/expectations/tests/nested_vtable.rs index 7c4fd14f4f..6356f9efd1 100644 --- a/bindgen-tests/tests/expectations/tests/nested_vtable.rs +++ b/bindgen-tests/tests/expectations/tests/nested_vtable.rs @@ -10,6 +10,7 @@ pub struct nsISupports__bindgen_vtable { pub struct nsISupports { pub vtable_: *const nsISupports__bindgen_vtable, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of nsISupports"][::std::mem::size_of::() - 8usize]; ["Alignment of nsISupports"][::std::mem::align_of::() - 8usize]; @@ -34,6 +35,7 @@ extern "C" { pub struct nsIRunnable { pub _base: nsISupports, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of nsIRunnable"][::std::mem::size_of::() - 8usize]; ["Alignment of nsIRunnable"][::std::mem::align_of::() - 8usize]; @@ -52,6 +54,7 @@ impl Default for nsIRunnable { pub struct Runnable { pub _base: nsIRunnable, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Runnable"][::std::mem::size_of::() - 8usize]; ["Alignment of Runnable"][::std::mem::align_of::() - 8usize]; diff --git a/bindgen-tests/tests/expectations/tests/nested_within_namespace.rs b/bindgen-tests/tests/expectations/tests/nested_within_namespace.rs index 1cc81efed9..f470571ddc 100644 --- a/bindgen-tests/tests/expectations/tests/nested_within_namespace.rs +++ b/bindgen-tests/tests/expectations/tests/nested_within_namespace.rs @@ -16,6 +16,7 @@ pub mod root { pub struct Bar_Baz { pub foo: ::std::os::raw::c_int, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Bar_Baz"][::std::mem::size_of::() - 4usize]; ["Alignment of Bar_Baz"][::std::mem::align_of::() - 4usize]; @@ -23,6 +24,7 @@ pub mod root { "Offset of field: Bar_Baz::foo", ][::std::mem::offset_of!(Bar_Baz, foo) - 0usize]; }; + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Bar"][::std::mem::size_of::() - 4usize]; ["Alignment of Bar"][::std::mem::align_of::() - 4usize]; @@ -33,6 +35,7 @@ pub mod root { pub struct Baz { pub baz: ::std::os::raw::c_int, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Baz"][::std::mem::size_of::() - 4usize]; ["Alignment of Baz"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/no-comments.rs b/bindgen-tests/tests/expectations/tests/no-comments.rs index 20fa648a47..6a60973fb4 100644 --- a/bindgen-tests/tests/expectations/tests/no-comments.rs +++ b/bindgen-tests/tests/expectations/tests/no-comments.rs @@ -4,6 +4,7 @@ pub struct Foo { pub s: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Foo"][::std::mem::size_of::() - 4usize]; ["Alignment of Foo"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/no-derive-debug.rs b/bindgen-tests/tests/expectations/tests/no-derive-debug.rs index 9c58b9855b..5e525068fd 100644 --- a/bindgen-tests/tests/expectations/tests/no-derive-debug.rs +++ b/bindgen-tests/tests/expectations/tests/no-derive-debug.rs @@ -12,6 +12,7 @@ pub struct bar { pub foo: foo, pub baz: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of bar"][::std::mem::size_of::() - 8usize]; ["Alignment of bar"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/no-derive-default.rs b/bindgen-tests/tests/expectations/tests/no-derive-default.rs index 3b2ebcc807..a1d86a6502 100644 --- a/bindgen-tests/tests/expectations/tests/no-derive-default.rs +++ b/bindgen-tests/tests/expectations/tests/no-derive-default.rs @@ -12,6 +12,7 @@ pub struct bar { pub foo: foo, pub baz: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of bar"][::std::mem::size_of::() - 8usize]; ["Alignment of bar"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/no-hash-allowlisted.rs b/bindgen-tests/tests/expectations/tests/no-hash-allowlisted.rs index 538d2109d5..ff4dd1e38e 100644 --- a/bindgen-tests/tests/expectations/tests/no-hash-allowlisted.rs +++ b/bindgen-tests/tests/expectations/tests/no-hash-allowlisted.rs @@ -4,6 +4,7 @@ pub struct NoHash { pub i: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of NoHash"][::std::mem::size_of::() - 4usize]; ["Alignment of NoHash"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/no-hash-opaque.rs b/bindgen-tests/tests/expectations/tests/no-hash-opaque.rs index b8869924b5..9dc9e01989 100644 --- a/bindgen-tests/tests/expectations/tests/no-hash-opaque.rs +++ b/bindgen-tests/tests/expectations/tests/no-hash-opaque.rs @@ -5,6 +5,7 @@ pub struct NoHash { pub _bindgen_opaque_blob: u32, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of NoHash"][::std::mem::size_of::() - 4usize]; ["Alignment of NoHash"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/no-partialeq-allowlisted.rs b/bindgen-tests/tests/expectations/tests/no-partialeq-allowlisted.rs index ad09f91cc9..68ae1a7449 100644 --- a/bindgen-tests/tests/expectations/tests/no-partialeq-allowlisted.rs +++ b/bindgen-tests/tests/expectations/tests/no-partialeq-allowlisted.rs @@ -4,6 +4,7 @@ pub struct NoPartialEq { pub i: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of NoPartialEq"][::std::mem::size_of::() - 4usize]; ["Alignment of NoPartialEq"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/no-partialeq-opaque.rs b/bindgen-tests/tests/expectations/tests/no-partialeq-opaque.rs index f16b92f5d4..4b488df6a5 100644 --- a/bindgen-tests/tests/expectations/tests/no-partialeq-opaque.rs +++ b/bindgen-tests/tests/expectations/tests/no-partialeq-opaque.rs @@ -5,6 +5,7 @@ pub struct NoPartialEq { pub _bindgen_opaque_blob: u32, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of NoPartialEq"][::std::mem::size_of::() - 4usize]; ["Alignment of NoPartialEq"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/no-recursive-allowlisting.rs b/bindgen-tests/tests/expectations/tests/no-recursive-allowlisting.rs index 0fc566bc2a..dc1e4721ab 100644 --- a/bindgen-tests/tests/expectations/tests/no-recursive-allowlisting.rs +++ b/bindgen-tests/tests/expectations/tests/no-recursive-allowlisting.rs @@ -5,6 +5,7 @@ pub enum Bar {} pub struct Foo { pub baz: *mut Bar, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Foo"][::std::mem::size_of::() - 8usize]; ["Alignment of Foo"][::std::mem::align_of::() - 8usize]; diff --git a/bindgen-tests/tests/expectations/tests/no-std.rs b/bindgen-tests/tests/expectations/tests/no-std.rs index 32defdf1f5..0f03c222ef 100644 --- a/bindgen-tests/tests/expectations/tests/no-std.rs +++ b/bindgen-tests/tests/expectations/tests/no-std.rs @@ -11,6 +11,7 @@ pub struct foo { pub b: libc::c_int, pub bar: *mut libc::c_void, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo"][::core::mem::size_of::() - 16usize]; ["Alignment of foo"][::core::mem::align_of::() - 8usize]; diff --git a/bindgen-tests/tests/expectations/tests/no_copy_allowlisted.rs b/bindgen-tests/tests/expectations/tests/no_copy_allowlisted.rs index 409dd56784..67be391799 100644 --- a/bindgen-tests/tests/expectations/tests/no_copy_allowlisted.rs +++ b/bindgen-tests/tests/expectations/tests/no_copy_allowlisted.rs @@ -4,6 +4,7 @@ pub struct NoCopy { pub i: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of NoCopy"][::std::mem::size_of::() - 4usize]; ["Alignment of NoCopy"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/no_copy_opaque.rs b/bindgen-tests/tests/expectations/tests/no_copy_opaque.rs index 5cf9a9f65f..dea6a0a6cf 100644 --- a/bindgen-tests/tests/expectations/tests/no_copy_opaque.rs +++ b/bindgen-tests/tests/expectations/tests/no_copy_opaque.rs @@ -5,6 +5,7 @@ pub struct NoCopy { pub _bindgen_opaque_blob: u32, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of NoCopy"][::std::mem::size_of::() - 4usize]; ["Alignment of NoCopy"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/no_debug_allowlisted.rs b/bindgen-tests/tests/expectations/tests/no_debug_allowlisted.rs index 042a3f00ad..1ddb20a747 100644 --- a/bindgen-tests/tests/expectations/tests/no_debug_allowlisted.rs +++ b/bindgen-tests/tests/expectations/tests/no_debug_allowlisted.rs @@ -4,6 +4,7 @@ pub struct NoDebug { pub i: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of NoDebug"][::std::mem::size_of::() - 4usize]; ["Alignment of NoDebug"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/no_debug_opaque.rs b/bindgen-tests/tests/expectations/tests/no_debug_opaque.rs index ca486739e0..0bb37ec711 100644 --- a/bindgen-tests/tests/expectations/tests/no_debug_opaque.rs +++ b/bindgen-tests/tests/expectations/tests/no_debug_opaque.rs @@ -5,6 +5,7 @@ pub struct NoDebug { pub _bindgen_opaque_blob: u32, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of NoDebug"][::std::mem::size_of::() - 4usize]; ["Alignment of NoDebug"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/no_default_allowlisted.rs b/bindgen-tests/tests/expectations/tests/no_default_allowlisted.rs index 379596a065..593e644343 100644 --- a/bindgen-tests/tests/expectations/tests/no_default_allowlisted.rs +++ b/bindgen-tests/tests/expectations/tests/no_default_allowlisted.rs @@ -4,6 +4,7 @@ pub struct NoDefault { pub i: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of NoDefault"][::std::mem::size_of::() - 4usize]; ["Alignment of NoDefault"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/no_default_opaque.rs b/bindgen-tests/tests/expectations/tests/no_default_opaque.rs index 28cd7b8cb5..ba2f63f91c 100644 --- a/bindgen-tests/tests/expectations/tests/no_default_opaque.rs +++ b/bindgen-tests/tests/expectations/tests/no_default_opaque.rs @@ -5,6 +5,7 @@ pub struct NoDefault { pub _bindgen_opaque_blob: u32, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of NoDefault"][::std::mem::size_of::() - 4usize]; ["Alignment of NoDefault"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/no_size_t_is_usize.rs b/bindgen-tests/tests/expectations/tests/no_size_t_is_usize.rs index 326f0730a8..94ce735b31 100644 --- a/bindgen-tests/tests/expectations/tests/no_size_t_is_usize.rs +++ b/bindgen-tests/tests/expectations/tests/no_size_t_is_usize.rs @@ -8,6 +8,7 @@ pub struct A { pub offset: ssize_t, pub next: *mut A, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of A"][::std::mem::size_of::() - 24usize]; ["Alignment of A"][::std::mem::align_of::() - 8usize]; diff --git a/bindgen-tests/tests/expectations/tests/non-type-params.rs b/bindgen-tests/tests/expectations/tests/non-type-params.rs index 6fa250455c..64b293cb1b 100644 --- a/bindgen-tests/tests/expectations/tests/non-type-params.rs +++ b/bindgen-tests/tests/expectations/tests/non-type-params.rs @@ -8,6 +8,7 @@ pub struct UsesArray { pub array_bool_8: [u8; 8usize], pub array_int_4: ArrayInt4, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of UsesArray"][::std::mem::size_of::() - 40usize]; ["Alignment of UsesArray"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/objc_interface_type.rs b/bindgen-tests/tests/expectations/tests/objc_interface_type.rs index 53c7101e7d..66c65be2d7 100644 --- a/bindgen-tests/tests/expectations/tests/objc_interface_type.rs +++ b/bindgen-tests/tests/expectations/tests/objc_interface_type.rs @@ -25,6 +25,7 @@ pub trait IFoo: Sized + std::ops::Deref {} pub struct FooStruct { pub foo: Foo, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of FooStruct"][::std::mem::size_of::() - 8usize]; ["Alignment of FooStruct"][::std::mem::align_of::() - 8usize]; diff --git a/bindgen-tests/tests/expectations/tests/only_bitfields.rs b/bindgen-tests/tests/expectations/tests/only_bitfields.rs index f3c9658762..5cd01b4485 100644 --- a/bindgen-tests/tests/expectations/tests/only_bitfields.rs +++ b/bindgen-tests/tests/expectations/tests/only_bitfields.rs @@ -89,6 +89,7 @@ pub struct C { pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of C"][::std::mem::size_of::() - 1usize]; ["Alignment of C"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/opaque-template-inst-member-2.rs b/bindgen-tests/tests/expectations/tests/opaque-template-inst-member-2.rs index 58b5004a4c..14718a9312 100644 --- a/bindgen-tests/tests/expectations/tests/opaque-template-inst-member-2.rs +++ b/bindgen-tests/tests/expectations/tests/opaque-template-inst-member-2.rs @@ -13,6 +13,7 @@ pub struct ContainsOpaqueTemplate { pub mBlah: u32, pub mBaz: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of ContainsOpaqueTemplate", @@ -34,6 +35,7 @@ pub struct InheritsOpaqueTemplate { pub _base: u8, pub wow: *mut ::std::os::raw::c_char, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of InheritsOpaqueTemplate", diff --git a/bindgen-tests/tests/expectations/tests/opaque-template-instantiation-namespaced.rs b/bindgen-tests/tests/expectations/tests/opaque-template-instantiation-namespaced.rs index 2199785d9b..58644e053d 100644 --- a/bindgen-tests/tests/expectations/tests/opaque-template-instantiation-namespaced.rs +++ b/bindgen-tests/tests/expectations/tests/opaque-template-instantiation-namespaced.rs @@ -26,6 +26,7 @@ pub mod root { pub struct Foo { pub c: ::std::os::raw::c_char, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Foo"][::std::mem::size_of::() - 1usize]; ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; @@ -36,6 +37,7 @@ pub mod root { pub struct Bar { pub i: ::std::os::raw::c_int, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Bar"][::std::mem::size_of::() - 4usize]; ["Alignment of Bar"][::std::mem::align_of::() - 4usize]; @@ -46,6 +48,7 @@ pub mod root { pub struct ContainsInstantiation { pub not_opaque: root::zoidberg::Template, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of ContainsInstantiation", @@ -71,6 +74,7 @@ pub mod root { pub struct ContainsOpaqueInstantiation { pub opaque: u32, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of ContainsOpaqueInstantiation", @@ -83,6 +87,7 @@ pub mod root { ][::std::mem::offset_of!(ContainsOpaqueInstantiation, opaque) - 0usize]; }; } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: Template_open0_Foo_close0", diff --git a/bindgen-tests/tests/expectations/tests/opaque-template-instantiation.rs b/bindgen-tests/tests/expectations/tests/opaque-template-instantiation.rs index 83b4e08063..ab68c21856 100644 --- a/bindgen-tests/tests/expectations/tests/opaque-template-instantiation.rs +++ b/bindgen-tests/tests/expectations/tests/opaque-template-instantiation.rs @@ -19,6 +19,7 @@ impl Default for Template { pub struct ContainsInstantiation { pub not_opaque: Template<::std::os::raw::c_char>, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of ContainsInstantiation", @@ -44,6 +45,7 @@ impl Default for ContainsInstantiation { pub struct ContainsOpaqueInstantiation { pub opaque: u32, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of ContainsOpaqueInstantiation", @@ -55,6 +57,7 @@ const _: () = { "Offset of field: ContainsOpaqueInstantiation::opaque", ][::std::mem::offset_of!(ContainsOpaqueInstantiation, opaque) - 0usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: Template_open0_char_close0", diff --git a/bindgen-tests/tests/expectations/tests/opaque-tracing.rs b/bindgen-tests/tests/expectations/tests/opaque-tracing.rs index 59afbf8ad9..c181dc90d6 100644 --- a/bindgen-tests/tests/expectations/tests/opaque-tracing.rs +++ b/bindgen-tests/tests/expectations/tests/opaque-tracing.rs @@ -9,6 +9,7 @@ extern "C" { pub struct Container { pub _bindgen_opaque_blob: [u32; 2usize], } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Container"][::std::mem::size_of::() - 8usize]; ["Alignment of Container"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/opaque_in_struct.rs b/bindgen-tests/tests/expectations/tests/opaque_in_struct.rs index 1fb26f8406..b651cd3354 100644 --- a/bindgen-tests/tests/expectations/tests/opaque_in_struct.rs +++ b/bindgen-tests/tests/expectations/tests/opaque_in_struct.rs @@ -6,6 +6,7 @@ pub struct opaque { pub _bindgen_opaque_blob: u32, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of opaque"][::std::mem::size_of::() - 4usize]; ["Alignment of opaque"][::std::mem::align_of::() - 4usize]; @@ -15,6 +16,7 @@ const _: () = { pub struct container { pub contained: opaque, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of container"][::std::mem::size_of::() - 4usize]; ["Alignment of container"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/opaque_pointer.rs b/bindgen-tests/tests/expectations/tests/opaque_pointer.rs index 9835e7f46e..ec519d9c6b 100644 --- a/bindgen-tests/tests/expectations/tests/opaque_pointer.rs +++ b/bindgen-tests/tests/expectations/tests/opaque_pointer.rs @@ -6,6 +6,7 @@ pub struct OtherOpaque { pub _bindgen_opaque_blob: u32, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of OtherOpaque"][::std::mem::size_of::() - 4usize]; ["Alignment of OtherOpaque"][::std::mem::align_of::() - 4usize]; @@ -23,6 +24,7 @@ pub struct WithOpaquePtr { pub other: u32, pub t: OtherOpaque, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of WithOpaquePtr"][::std::mem::size_of::() - 16usize]; ["Alignment of WithOpaquePtr"][::std::mem::align_of::() - 8usize]; diff --git a/bindgen-tests/tests/expectations/tests/packed-bitfield.rs b/bindgen-tests/tests/expectations/tests/packed-bitfield.rs index d788a4d5d4..852126ecfc 100644 --- a/bindgen-tests/tests/expectations/tests/packed-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/packed-bitfield.rs @@ -89,6 +89,7 @@ pub struct Date { pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 3usize]>, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Date"][::std::mem::size_of::() - 3usize]; ["Alignment of Date"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/packed-n-with-padding.rs b/bindgen-tests/tests/expectations/tests/packed-n-with-padding.rs index cfb3bbec9b..162a1bebed 100644 --- a/bindgen-tests/tests/expectations/tests/packed-n-with-padding.rs +++ b/bindgen-tests/tests/expectations/tests/packed-n-with-padding.rs @@ -7,6 +7,7 @@ pub struct Packed { pub c: ::std::os::raw::c_char, pub d: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Packed"][::std::mem::size_of::() - 10usize]; ["Alignment of Packed"][::std::mem::align_of::() - 2usize]; diff --git a/bindgen-tests/tests/expectations/tests/parm-union.rs b/bindgen-tests/tests/expectations/tests/parm-union.rs index 85c4718aa2..9c4f2f4e25 100644 --- a/bindgen-tests/tests/expectations/tests/parm-union.rs +++ b/bindgen-tests/tests/expectations/tests/parm-union.rs @@ -4,6 +4,7 @@ pub struct Struct { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Struct"][::std::mem::size_of::() - 1usize]; ["Alignment of Struct"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/partial-specialization-and-inheritance.rs b/bindgen-tests/tests/expectations/tests/partial-specialization-and-inheritance.rs index bb28bffcae..e7c9a38d7f 100644 --- a/bindgen-tests/tests/expectations/tests/partial-specialization-and-inheritance.rs +++ b/bindgen-tests/tests/expectations/tests/partial-specialization-and-inheritance.rs @@ -18,6 +18,7 @@ extern "C" { #[link_name = "\u{1}_ZN5Usage13static_memberE"] pub static mut Usage_static_member: [u32; 2usize]; } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Usage"][::std::mem::size_of::() - 1usize]; ["Alignment of Usage"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/private.rs b/bindgen-tests/tests/expectations/tests/private.rs index 86d0120e04..bf1e853e6a 100644 --- a/bindgen-tests/tests/expectations/tests/private.rs +++ b/bindgen-tests/tests/expectations/tests/private.rs @@ -6,6 +6,7 @@ pub struct HasPrivate { ///
mIsPrivate: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of HasPrivate"][::std::mem::size_of::() - 8usize]; ["Alignment of HasPrivate"][::std::mem::align_of::() - 4usize]; @@ -23,6 +24,7 @@ pub struct VeryPrivate { mIsPrivate: ::std::os::raw::c_int, mIsAlsoPrivate: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of VeryPrivate"][::std::mem::size_of::() - 8usize]; ["Alignment of VeryPrivate"][::std::mem::align_of::() - 4usize]; @@ -41,6 +43,7 @@ pub struct ContradictPrivate { pub mNotPrivate: ::std::os::raw::c_int, mIsPrivate: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of ContradictPrivate"][::std::mem::size_of::() - 8usize]; [ diff --git a/bindgen-tests/tests/expectations/tests/private_fields.rs b/bindgen-tests/tests/expectations/tests/private_fields.rs index 88e4797c73..5a7bee9508 100644 --- a/bindgen-tests/tests/expectations/tests/private_fields.rs +++ b/bindgen-tests/tests/expectations/tests/private_fields.rs @@ -89,6 +89,7 @@ pub struct PubPriv { pub x: ::std::os::raw::c_int, y: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of PubPriv"][::std::mem::size_of::() - 8usize]; ["Alignment of PubPriv"][::std::mem::align_of::() - 4usize]; @@ -103,6 +104,7 @@ pub struct PrivateBitFields { _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub __bindgen_padding_0: [u8; 3usize], } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of PrivateBitFields"][::std::mem::size_of::() - 4usize]; [ @@ -167,6 +169,7 @@ pub struct PublicBitFields { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub __bindgen_padding_0: [u8; 3usize], } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of PublicBitFields"][::std::mem::size_of::() - 4usize]; ["Alignment of PublicBitFields"][::std::mem::align_of::() - 4usize]; @@ -229,6 +232,7 @@ pub struct MixedBitFields { _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub __bindgen_padding_0: [u8; 3usize], } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of MixedBitFields"][::std::mem::size_of::() - 4usize]; ["Alignment of MixedBitFields"][::std::mem::align_of::() - 4usize]; @@ -288,6 +292,7 @@ impl MixedBitFields { pub struct Base { pub member: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Base"][::std::mem::size_of::() - 4usize]; ["Alignment of Base"][::std::mem::align_of::() - 4usize]; @@ -298,6 +303,7 @@ const _: () = { pub struct InheritsPrivately { _base: Base, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of InheritsPrivately"][::std::mem::size_of::() - 4usize]; [ @@ -309,6 +315,7 @@ const _: () = { pub struct InheritsPublically { pub _base: Base, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of InheritsPublically"][::std::mem::size_of::() - 4usize]; [ @@ -326,6 +333,7 @@ pub struct WithAnonStruct { pub struct WithAnonStruct__bindgen_ty_1 { pub a: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of WithAnonStruct__bindgen_ty_1", @@ -342,6 +350,7 @@ const _: () = { pub struct WithAnonStruct__bindgen_ty_2 { pub b: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of WithAnonStruct__bindgen_ty_2", @@ -353,6 +362,7 @@ const _: () = { "Offset of field: WithAnonStruct__bindgen_ty_2::b", ][::std::mem::offset_of!(WithAnonStruct__bindgen_ty_2, b) - 0usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of WithAnonStruct"][::std::mem::size_of::() - 8usize]; ["Alignment of WithAnonStruct"][::std::mem::align_of::() - 4usize]; @@ -367,6 +377,7 @@ pub struct WithAnonUnion { pub union WithAnonUnion__bindgen_ty_1 { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of WithAnonUnion__bindgen_ty_1", @@ -384,6 +395,7 @@ impl Default for WithAnonUnion__bindgen_ty_1 { } } } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of WithAnonUnion"][::std::mem::size_of::() - 1usize]; ["Alignment of WithAnonUnion"][::std::mem::align_of::() - 1usize]; @@ -408,6 +420,7 @@ pub struct Override { _bitfield_1: __BindgenBitfieldUnit<[u8; 2usize]>, pub __bindgen_padding_0: u16, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Override"][::std::mem::size_of::() - 16usize]; ["Alignment of Override"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/ptr32-has-different-size.rs b/bindgen-tests/tests/expectations/tests/ptr32-has-different-size.rs index d03d66f1a4..f4f3ab4294 100644 --- a/bindgen-tests/tests/expectations/tests/ptr32-has-different-size.rs +++ b/bindgen-tests/tests/expectations/tests/ptr32-has-different-size.rs @@ -4,6 +4,7 @@ pub struct TEST_STRUCT { pub ptr_32bit: u32, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of TEST_STRUCT"][::std::mem::size_of::() - 4usize]; ["Alignment of TEST_STRUCT"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/public-dtor.rs b/bindgen-tests/tests/expectations/tests/public-dtor.rs index fc9e85ced0..c271125097 100644 --- a/bindgen-tests/tests/expectations/tests/public-dtor.rs +++ b/bindgen-tests/tests/expectations/tests/public-dtor.rs @@ -4,6 +4,7 @@ pub struct cv_Foo { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of cv_Foo"][::std::mem::size_of::() - 1usize]; ["Alignment of cv_Foo"][::std::mem::align_of::() - 1usize]; @@ -23,6 +24,7 @@ impl cv_Foo { pub struct cv_Bar { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of cv_Bar"][::std::mem::size_of::() - 1usize]; ["Alignment of cv_Bar"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/redundant-packed-and-align.rs b/bindgen-tests/tests/expectations/tests/redundant-packed-and-align.rs index f4f2b95408..6e7db24870 100644 --- a/bindgen-tests/tests/expectations/tests/redundant-packed-and-align.rs +++ b/bindgen-tests/tests/expectations/tests/redundant-packed-and-align.rs @@ -90,6 +90,7 @@ pub struct redundant_packed { pub a: u32, pub b: u32, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of redundant_packed"][::std::mem::size_of::() - 8usize]; [ @@ -111,6 +112,7 @@ pub struct redundant_packed_bitfield { pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub c: u32, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of redundant_packed_bitfield", @@ -179,6 +181,7 @@ pub union redundant_packed_union { pub a: u64, pub b: u32, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of redundant_packed_union", @@ -208,6 +211,7 @@ impl Default for redundant_packed_union { pub struct inner { pub a: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of inner"][::std::mem::size_of::() - 2usize]; ["Alignment of inner"][::std::mem::align_of::() - 2usize]; @@ -220,6 +224,7 @@ pub struct outer_redundant_packed { pub a: [inner; 2usize], pub b: u32, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of outer_redundant_packed", @@ -241,6 +246,7 @@ pub struct redundant_pragma_packed { pub a: u8, pub b: u16, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of redundant_pragma_packed", diff --git a/bindgen-tests/tests/expectations/tests/ref_argument_array.rs b/bindgen-tests/tests/expectations/tests/ref_argument_array.rs index 855fdec6ed..de5f81c3c0 100644 --- a/bindgen-tests/tests/expectations/tests/ref_argument_array.rs +++ b/bindgen-tests/tests/expectations/tests/ref_argument_array.rs @@ -12,6 +12,7 @@ pub struct nsID__bindgen_vtable { pub struct nsID { pub vtable_: *const nsID__bindgen_vtable, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of nsID"][::std::mem::size_of::() - 8usize]; ["Alignment of nsID"][::std::mem::align_of::() - 8usize]; diff --git a/bindgen-tests/tests/expectations/tests/reparented_replacement.rs b/bindgen-tests/tests/expectations/tests/reparented_replacement.rs index 48ad6f3f5b..9b2cc33ce9 100644 --- a/bindgen-tests/tests/expectations/tests/reparented_replacement.rs +++ b/bindgen-tests/tests/expectations/tests/reparented_replacement.rs @@ -12,6 +12,7 @@ pub mod root { pub struct Bar { pub bazz: ::std::os::raw::c_int, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Bar"][::std::mem::size_of::() - 4usize]; ["Alignment of Bar"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/replace_use.rs b/bindgen-tests/tests/expectations/tests/replace_use.rs index d7d4e33536..ebf9657176 100644 --- a/bindgen-tests/tests/expectations/tests/replace_use.rs +++ b/bindgen-tests/tests/expectations/tests/replace_use.rs @@ -10,11 +10,13 @@ pub struct nsTArray { pub struct Test { pub a: nsTArray, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Test"][::std::mem::size_of::() - 4usize]; ["Alignment of Test"][::std::mem::align_of::() - 4usize]; ["Offset of field: Test::a"][::std::mem::offset_of!(Test, a) - 0usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: nsTArray_open0_long_close0", diff --git a/bindgen-tests/tests/expectations/tests/same_struct_name_in_different_namespaces.rs b/bindgen-tests/tests/expectations/tests/same_struct_name_in_different_namespaces.rs index 9fb546fc0c..e6e4088abf 100644 --- a/bindgen-tests/tests/expectations/tests/same_struct_name_in_different_namespaces.rs +++ b/bindgen-tests/tests/expectations/tests/same_struct_name_in_different_namespaces.rs @@ -10,6 +10,7 @@ pub struct JS_shadow_Zone { pub x: ::std::os::raw::c_int, pub y: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of JS_shadow_Zone"][::std::mem::size_of::() - 8usize]; ["Alignment of JS_shadow_Zone"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/sentry-defined-multiple-times.rs b/bindgen-tests/tests/expectations/tests/sentry-defined-multiple-times.rs index 0d9d3a47ef..0fe153e700 100644 --- a/bindgen-tests/tests/expectations/tests/sentry-defined-multiple-times.rs +++ b/bindgen-tests/tests/expectations/tests/sentry-defined-multiple-times.rs @@ -21,6 +21,7 @@ pub mod root { pub struct sentry { pub i_am_plain_sentry: bool, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of sentry"][::std::mem::size_of::() - 1usize]; ["Alignment of sentry"][::std::mem::align_of::() - 1usize]; @@ -33,6 +34,7 @@ pub mod root { pub struct NotTemplateWrapper { pub _address: u8, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of NotTemplateWrapper", @@ -46,6 +48,7 @@ pub mod root { pub struct NotTemplateWrapper_sentry { pub i_am_not_template_wrapper_sentry: ::std::os::raw::c_char, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of NotTemplateWrapper_sentry", @@ -69,6 +72,7 @@ pub mod root { pub struct InlineNotTemplateWrapper_sentry { pub i_am_inline_not_template_wrapper_sentry: bool, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of InlineNotTemplateWrapper_sentry", @@ -82,6 +86,7 @@ pub mod root { InlineNotTemplateWrapper_sentry, i_am_inline_not_template_wrapper_sentry ) - 0usize]; }; + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of InlineNotTemplateWrapper", @@ -110,6 +115,7 @@ pub mod root { pub struct OuterDoubleWrapper_InnerDoubleWrapper { pub _address: u8, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of OuterDoubleWrapper_InnerDoubleWrapper", @@ -118,6 +124,7 @@ pub mod root { "Alignment of OuterDoubleWrapper_InnerDoubleWrapper", ][::std::mem::align_of::() - 1usize]; }; + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of OuterDoubleWrapper", @@ -131,6 +138,7 @@ pub mod root { pub struct OuterDoubleWrapper_InnerDoubleWrapper_sentry { pub i_am_double_wrapper_sentry: ::std::os::raw::c_int, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of OuterDoubleWrapper_InnerDoubleWrapper_sentry", @@ -161,6 +169,7 @@ pub mod root { pub struct OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry { pub i_am_double_wrapper_inline_sentry: ::std::os::raw::c_int, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of OuterDoubleInlineWrapper_InnerDoubleInlineWrapper_sentry", @@ -179,6 +188,7 @@ pub mod root { i_am_double_wrapper_inline_sentry ) - 0usize]; }; + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of OuterDoubleInlineWrapper_InnerDoubleInlineWrapper", @@ -189,6 +199,7 @@ pub mod root { ][::std::mem::align_of::() - 1usize]; }; + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of OuterDoubleInlineWrapper", @@ -213,6 +224,7 @@ pub mod root { pub struct sentry { pub i_am_outside_namespace_sentry: ::std::os::raw::c_int, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of sentry"][::std::mem::size_of::() - 4usize]; ["Alignment of sentry"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/size_t_template.rs b/bindgen-tests/tests/expectations/tests/size_t_template.rs index 7ca85c2ca1..e422131ca7 100644 --- a/bindgen-tests/tests/expectations/tests/size_t_template.rs +++ b/bindgen-tests/tests/expectations/tests/size_t_template.rs @@ -4,6 +4,7 @@ pub struct C { pub arr: [u32; 3usize], } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of C"][::std::mem::size_of::() - 12usize]; ["Alignment of C"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/sorted_items.rs b/bindgen-tests/tests/expectations/tests/sorted_items.rs index ab2a6dc27a..5f1505bd86 100644 --- a/bindgen-tests/tests/expectations/tests/sorted_items.rs +++ b/bindgen-tests/tests/expectations/tests/sorted_items.rs @@ -14,12 +14,14 @@ pub mod root { pub a: root::number, pub b: root::number, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Point"][::std::mem::size_of::() - 8usize]; ["Alignment of Point"][::std::mem::align_of::() - 4usize]; ["Offset of field: Point::x"][::std::mem::offset_of!(Point, x) - 0usize]; ["Offset of field: Point::y"][::std::mem::offset_of!(Point, y) - 4usize]; }; + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Angle"][::std::mem::size_of::() - 8usize]; ["Alignment of Angle"][::std::mem::align_of::() - 4usize]; @@ -41,12 +43,14 @@ pub mod root { pub a: root::ns::number, pub b: root::ns::number, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Point"][::std::mem::size_of::() - 8usize]; ["Alignment of Point"][::std::mem::align_of::() - 4usize]; ["Offset of field: Point::x"][::std::mem::offset_of!(Point, x) - 0usize]; ["Offset of field: Point::y"][::std::mem::offset_of!(Point, y) - 4usize]; }; + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Angle"][::std::mem::size_of::() - 8usize]; ["Alignment of Angle"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/stdint_typedef.rs b/bindgen-tests/tests/expectations/tests/stdint_typedef.rs index 67c0ea5685..8594727dfa 100644 --- a/bindgen-tests/tests/expectations/tests/stdint_typedef.rs +++ b/bindgen-tests/tests/expectations/tests/stdint_typedef.rs @@ -7,6 +7,7 @@ extern "C" { pub struct Struct { pub field: u64, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Struct"][::std::mem::size_of::() - 8usize]; ["Alignment of Struct"][::std::mem::align_of::() - 8usize]; diff --git a/bindgen-tests/tests/expectations/tests/struct_containing_forward_declared_struct.rs b/bindgen-tests/tests/expectations/tests/struct_containing_forward_declared_struct.rs index 39880f2f5a..0fe9024a5f 100644 --- a/bindgen-tests/tests/expectations/tests/struct_containing_forward_declared_struct.rs +++ b/bindgen-tests/tests/expectations/tests/struct_containing_forward_declared_struct.rs @@ -4,6 +4,7 @@ pub struct a { pub val_a: *mut b, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of a"][::std::mem::size_of::
() - 8usize]; ["Alignment of a"][::std::mem::align_of::() - 8usize]; @@ -23,6 +24,7 @@ impl Default for a { pub struct b { pub val_b: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of b"][::std::mem::size_of::() - 4usize]; ["Alignment of b"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/struct_typedef.rs b/bindgen-tests/tests/expectations/tests/struct_typedef.rs index efcea67c39..bc12a1bce8 100644 --- a/bindgen-tests/tests/expectations/tests/struct_typedef.rs +++ b/bindgen-tests/tests/expectations/tests/struct_typedef.rs @@ -4,6 +4,7 @@ pub struct typedef_named_struct { pub has_name: bool, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of typedef_named_struct", @@ -20,6 +21,7 @@ const _: () = { pub struct _bindgen_ty_1 { pub no_name: *mut ::std::os::raw::c_void, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of _bindgen_ty_1"][::std::mem::size_of::<_bindgen_ty_1>() - 8usize]; ["Alignment of _bindgen_ty_1"][::std::mem::align_of::<_bindgen_ty_1>() - 8usize]; diff --git a/bindgen-tests/tests/expectations/tests/struct_typedef_ns.rs b/bindgen-tests/tests/expectations/tests/struct_typedef_ns.rs index 14091c9dc6..82f93dfd16 100644 --- a/bindgen-tests/tests/expectations/tests/struct_typedef_ns.rs +++ b/bindgen-tests/tests/expectations/tests/struct_typedef_ns.rs @@ -11,6 +11,7 @@ pub mod root { pub struct typedef_struct { pub foo: ::std::os::raw::c_int, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of typedef_struct"][::std::mem::size_of::() - 4usize]; [ @@ -34,6 +35,7 @@ pub mod root { pub struct typedef_struct { pub foo: ::std::os::raw::c_int, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of typedef_struct"][::std::mem::size_of::() - 4usize]; [ diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_struct.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_struct.rs index f279a61378..51aa19c572 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_struct.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_anon_struct.rs @@ -10,6 +10,7 @@ pub struct foo__bindgen_ty_1 { pub a: ::std::os::raw::c_int, pub b: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo__bindgen_ty_1"][::std::mem::size_of::() - 8usize]; [ @@ -22,6 +23,7 @@ const _: () = { "Offset of field: foo__bindgen_ty_1::b", ][::std::mem::offset_of!(foo__bindgen_ty_1, b) - 4usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo"][::std::mem::size_of::() - 8usize]; ["Alignment of foo"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_struct_array.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_struct_array.rs index 48fb6ac03e..930e6b9aba 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_struct_array.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_anon_struct_array.rs @@ -11,6 +11,7 @@ pub struct foo__bindgen_ty_1 { pub a: ::std::os::raw::c_int, pub b: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo__bindgen_ty_1"][::std::mem::size_of::() - 8usize]; [ @@ -29,6 +30,7 @@ pub struct foo__bindgen_ty_2 { pub a: ::std::os::raw::c_int, pub b: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo__bindgen_ty_2"][::std::mem::size_of::() - 8usize]; [ @@ -41,6 +43,7 @@ const _: () = { "Offset of field: foo__bindgen_ty_2::b", ][::std::mem::offset_of!(foo__bindgen_ty_2, b) - 4usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo"][::std::mem::size_of::() - 208usize]; ["Alignment of foo"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_struct_pointer.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_struct_pointer.rs index 04b78064aa..6bdee34590 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_struct_pointer.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_anon_struct_pointer.rs @@ -10,6 +10,7 @@ pub struct foo__bindgen_ty_1 { pub a: ::std::os::raw::c_int, pub b: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo__bindgen_ty_1"][::std::mem::size_of::() - 8usize]; [ @@ -22,6 +23,7 @@ const _: () = { "Offset of field: foo__bindgen_ty_1::b", ][::std::mem::offset_of!(foo__bindgen_ty_1, b) - 4usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo"][::std::mem::size_of::() - 8usize]; ["Alignment of foo"][::std::mem::align_of::() - 8usize]; diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_union.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_union.rs index 5cd95f777f..6520163259 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_union.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_anon_union.rs @@ -10,6 +10,7 @@ pub union foo__bindgen_ty_1 { pub a: ::std::os::raw::c_uint, pub b: ::std::os::raw::c_ushort, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo__bindgen_ty_1"][::std::mem::size_of::() - 4usize]; [ @@ -31,6 +32,7 @@ impl Default for foo__bindgen_ty_1 { } } } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo"][::std::mem::size_of::() - 4usize]; ["Alignment of foo"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_struct.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_struct.rs index 4e4a3f2d74..29cf382e5f 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_struct.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_struct.rs @@ -10,6 +10,7 @@ pub struct foo__bindgen_ty_1 { pub a: ::std::os::raw::c_uint, pub b: ::std::os::raw::c_uint, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo__bindgen_ty_1"][::std::mem::size_of::() - 8usize]; [ @@ -22,6 +23,7 @@ const _: () = { "Offset of field: foo__bindgen_ty_1::b", ][::std::mem::offset_of!(foo__bindgen_ty_1, b) - 4usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo"][::std::mem::size_of::() - 8usize]; ["Alignment of foo"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union.rs index 325aa820bf..2f95e0f5e0 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union.rs @@ -10,6 +10,7 @@ pub union foo__bindgen_ty_1 { pub a: ::std::os::raw::c_uint, pub b: ::std::os::raw::c_ushort, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo__bindgen_ty_1"][::std::mem::size_of::() - 4usize]; [ @@ -31,6 +32,7 @@ impl Default for foo__bindgen_ty_1 { } } } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo"][::std::mem::size_of::() - 4usize]; ["Alignment of foo"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/struct_with_bitfields.rs b/bindgen-tests/tests/expectations/tests/struct_with_bitfields.rs index 9ec90061b3..fb21433415 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_bitfields.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_bitfields.rs @@ -92,6 +92,7 @@ pub struct bitfield { pub _bitfield_align_2: [u32; 0], pub _bitfield_2: __BindgenBitfieldUnit<[u8; 8usize]>, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of bitfield"][::std::mem::size_of::() - 16usize]; ["Alignment of bitfield"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/struct_with_nesting.rs b/bindgen-tests/tests/expectations/tests/struct_with_nesting.rs index ec3a07f613..369384e88c 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_nesting.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_nesting.rs @@ -18,6 +18,7 @@ pub struct foo__bindgen_ty_1__bindgen_ty_1 { pub c1: ::std::os::raw::c_ushort, pub c2: ::std::os::raw::c_ushort, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of foo__bindgen_ty_1__bindgen_ty_1", @@ -40,6 +41,7 @@ pub struct foo__bindgen_ty_1__bindgen_ty_2 { pub d3: ::std::os::raw::c_uchar, pub d4: ::std::os::raw::c_uchar, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of foo__bindgen_ty_1__bindgen_ty_2", @@ -60,6 +62,7 @@ const _: () = { "Offset of field: foo__bindgen_ty_1__bindgen_ty_2::d4", ][::std::mem::offset_of!(foo__bindgen_ty_1__bindgen_ty_2, d4) - 3usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo__bindgen_ty_1"][::std::mem::size_of::() - 4usize]; [ @@ -78,6 +81,7 @@ impl Default for foo__bindgen_ty_1 { } } } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo"][::std::mem::size_of::() - 8usize]; ["Alignment of foo"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/struct_with_packing.rs b/bindgen-tests/tests/expectations/tests/struct_with_packing.rs index 2d041a4678..2687f9750b 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_packing.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_packing.rs @@ -5,6 +5,7 @@ pub struct a { pub b: ::std::os::raw::c_char, pub c: ::std::os::raw::c_short, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of a"][::std::mem::size_of::() - 3usize]; ["Alignment of a"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/struct_with_struct.rs b/bindgen-tests/tests/expectations/tests/struct_with_struct.rs index 13bd782e87..40c3972600 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_struct.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_struct.rs @@ -10,6 +10,7 @@ pub struct foo__bindgen_ty_1 { pub x: ::std::os::raw::c_uint, pub y: ::std::os::raw::c_uint, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo__bindgen_ty_1"][::std::mem::size_of::() - 8usize]; [ @@ -22,6 +23,7 @@ const _: () = { "Offset of field: foo__bindgen_ty_1::y", ][::std::mem::offset_of!(foo__bindgen_ty_1, y) - 4usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo"][::std::mem::size_of::() - 8usize]; ["Alignment of foo"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/template.rs b/bindgen-tests/tests/expectations/tests/template.rs index 13c9f0066e..aa2a7753e2 100644 --- a/bindgen-tests/tests/expectations/tests/template.rs +++ b/bindgen-tests/tests/expectations/tests/template.rs @@ -60,6 +60,7 @@ pub struct C { pub mArrayRef: B<*mut [::std::os::raw::c_int; 1usize]>, pub mBConstArray: B<[::std::os::raw::c_int; 1usize]>, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of C"][::std::mem::size_of::() - 104usize]; ["Alignment of C"][::std::mem::align_of::() - 8usize]; @@ -152,6 +153,7 @@ impl Default for Rooted { pub struct RootedContainer { pub root: Rooted<*mut ::std::os::raw::c_void>, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of RootedContainer"][::std::mem::size_of::() - 24usize]; ["Alignment of RootedContainer"][::std::mem::align_of::() - 8usize]; @@ -189,6 +191,7 @@ impl Default for WithDtor { pub struct PODButContainsDtor { pub member: WithDtorIntFwd, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of PODButContainsDtor"][::std::mem::size_of::() - 4usize]; [ @@ -218,6 +221,7 @@ pub struct Opaque { pub struct POD { pub opaque_member: u32, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of POD"][::std::mem::size_of::() - 4usize]; ["Alignment of POD"][::std::mem::align_of::() - 4usize]; @@ -293,6 +297,7 @@ impl Default for Incomplete { pub struct Untemplated { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Untemplated"][::std::mem::size_of::() - 1usize]; ["Alignment of Untemplated"][::std::mem::align_of::() - 1usize]; @@ -370,6 +375,7 @@ impl Default for ReplacedWithoutDestructorFwd { } } } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: Foo_open0_int_int_close0", @@ -378,6 +384,7 @@ const _: () = { "Align of template specialization: Foo_open0_int_int_close0", ][::std::mem::align_of::>() - 8usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: B_open0_unsigned_int_close0", @@ -386,6 +393,7 @@ const _: () = { "Align of template specialization: B_open0_unsigned_int_close0", ][::std::mem::align_of::>() - 4usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: B_open0_ptr_const_int_close0", @@ -394,6 +402,7 @@ const _: () = { "Align of template specialization: B_open0_ptr_const_int_close0", ][::std::mem::align_of::>() - 8usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: B_open0_ptr_const_mozilla__Foo_close0", @@ -402,6 +411,7 @@ const _: () = { "Align of template specialization: B_open0_ptr_const_mozilla__Foo_close0", ][::std::mem::align_of::>() - 8usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: B_open0_array1_ptr_const_mozilla__Foo_close0", @@ -410,6 +420,7 @@ const _: () = { "Align of template specialization: B_open0_array1_ptr_const_mozilla__Foo_close0", ][::std::mem::align_of::>() - 8usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: B_open0_const_int_close0", @@ -418,6 +429,7 @@ const _: () = { "Align of template specialization: B_open0_const_int_close0", ][::std::mem::align_of::>() - 4usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: B_open0_volatile_int_close0", @@ -426,6 +438,7 @@ const _: () = { "Align of template specialization: B_open0_volatile_int_close0", ][::std::mem::align_of::>() - 4usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: B_open0_const_bool_close0", @@ -434,6 +447,7 @@ const _: () = { "Align of template specialization: B_open0_const_bool_close0", ][::std::mem::align_of::>() - 1usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: B_open0_const_char16_t_close0", @@ -442,6 +456,7 @@ const _: () = { "Align of template specialization: B_open0_const_char16_t_close0", ][::std::mem::align_of::>() - 2usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: B_open0_array1_int_close0", @@ -450,6 +465,7 @@ const _: () = { "Align of template specialization: B_open0_array1_int_close0", ][::std::mem::align_of::>() - 4usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: B_open0_array1_ptr_int_close0", @@ -458,6 +474,7 @@ const _: () = { "Align of template specialization: B_open0_array1_ptr_int_close0", ][::std::mem::align_of::>() - 8usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: B_open0_ptr_array1_int_close0", @@ -466,6 +483,7 @@ const _: () = { "Align of template specialization: B_open0_ptr_array1_int_close0", ][::std::mem::align_of::>() - 8usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: B_open0_ref_int_close0", @@ -474,6 +492,7 @@ const _: () = { "Align of template specialization: B_open0_ref_int_close0", ][::std::mem::align_of::>() - 8usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: B_open0_ref_const_int_close0", @@ -482,6 +501,7 @@ const _: () = { "Align of template specialization: B_open0_ref_const_int_close0", ][::std::mem::align_of::>() - 8usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: B_open0_ref_ptr_int_close0", @@ -490,6 +510,7 @@ const _: () = { "Align of template specialization: B_open0_ref_ptr_int_close0", ][::std::mem::align_of::>() - 8usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: B_open0_ref_array1_int_close0", @@ -498,6 +519,7 @@ const _: () = { "Align of template specialization: B_open0_ref_array1_int_close0", ][::std::mem::align_of::>() - 8usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: B_open0_array1_const_int_close0", @@ -506,6 +528,7 @@ const _: () = { "Align of template specialization: B_open0_array1_const_int_close0", ][::std::mem::align_of::>() - 4usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: Foo_open0_int_int_close0", @@ -514,6 +537,7 @@ const _: () = { "Align of template specialization: Foo_open0_int_int_close0", ][::std::mem::align_of::>() - 8usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: Rooted_open0_ptr_void_close0", @@ -522,6 +546,7 @@ const _: () = { "Align of template specialization: Rooted_open0_ptr_void_close0", ][::std::mem::align_of::>() - 8usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: Rooted_open0_ptr_void_close0", @@ -530,6 +555,7 @@ const _: () = { "Align of template specialization: Rooted_open0_ptr_void_close0", ][::std::mem::align_of::>() - 8usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: WithDtor_open0_int_close0", diff --git a/bindgen-tests/tests/expectations/tests/template_instantiation_with_fn_local_type.rs b/bindgen-tests/tests/expectations/tests/template_instantiation_with_fn_local_type.rs index f152f1ae8e..0bf9cc6d82 100644 --- a/bindgen-tests/tests/expectations/tests/template_instantiation_with_fn_local_type.rs +++ b/bindgen-tests/tests/expectations/tests/template_instantiation_with_fn_local_type.rs @@ -8,6 +8,7 @@ extern "C" { #[link_name = "\u{1}_Z1fv"] pub fn f(); } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: Foo_open0_Bar_close0", @@ -21,10 +22,12 @@ const _: () = { pub struct Baz { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Baz"][::std::mem::size_of::() - 1usize]; ["Alignment of Baz"][::std::mem::align_of::() - 1usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: Foo_open0_Boo_close0", @@ -38,6 +41,7 @@ const _: () = { pub struct Bar { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Bar"][::std::mem::size_of::() - 1usize]; ["Alignment of Bar"][::std::mem::align_of::() - 1usize]; @@ -47,6 +51,7 @@ const _: () = { pub struct Boo { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Boo"][::std::mem::size_of::() - 1usize]; ["Alignment of Boo"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/test_mixed_header_and_header_contents.rs b/bindgen-tests/tests/expectations/tests/test_mixed_header_and_header_contents.rs index fe346d112f..a2910b9b24 100644 --- a/bindgen-tests/tests/expectations/tests/test_mixed_header_and_header_contents.rs +++ b/bindgen-tests/tests/expectations/tests/test_mixed_header_and_header_contents.rs @@ -31,6 +31,7 @@ pub struct Test { pub Ccu: UChar, pub Ccd: SChar, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Test"][::std::mem::size_of::() - 12usize]; ["Alignment of Test"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/test_multiple_header_calls_in_builder.rs b/bindgen-tests/tests/expectations/tests/test_multiple_header_calls_in_builder.rs index 92122d1714..bcc27d259f 100644 --- a/bindgen-tests/tests/expectations/tests/test_multiple_header_calls_in_builder.rs +++ b/bindgen-tests/tests/expectations/tests/test_multiple_header_calls_in_builder.rs @@ -25,6 +25,7 @@ pub struct Test { pub Ccu: UChar, pub Ccd: SChar, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Test"][::std::mem::size_of::() - 12usize]; ["Alignment of Test"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/timex.rs b/bindgen-tests/tests/expectations/tests/timex.rs index cece8f099d..a9f78066f0 100644 --- a/bindgen-tests/tests/expectations/tests/timex.rs +++ b/bindgen-tests/tests/expectations/tests/timex.rs @@ -90,6 +90,7 @@ pub struct timex { pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 44usize]>, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of timex"][::std::mem::size_of::() - 48usize]; ["Alignment of timex"][::std::mem::align_of::() - 4usize]; @@ -111,6 +112,7 @@ pub struct timex_named { pub _bitfield_align_1: [u32; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 44usize]>, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of timex_named"][::std::mem::size_of::() - 48usize]; ["Alignment of timex_named"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/type-referenced-by-allowlisted-function.rs b/bindgen-tests/tests/expectations/tests/type-referenced-by-allowlisted-function.rs index 7d0973f994..8ddfaa7c68 100644 --- a/bindgen-tests/tests/expectations/tests/type-referenced-by-allowlisted-function.rs +++ b/bindgen-tests/tests/expectations/tests/type-referenced-by-allowlisted-function.rs @@ -4,6 +4,7 @@ pub struct dl_phdr_info { pub x: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of dl_phdr_info"][::std::mem::size_of::() - 4usize]; ["Alignment of dl_phdr_info"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/type_alias_template_specialized.rs b/bindgen-tests/tests/expectations/tests/type_alias_template_specialized.rs index bcd6c43af7..13e3f8139c 100644 --- a/bindgen-tests/tests/expectations/tests/type_alias_template_specialized.rs +++ b/bindgen-tests/tests/expectations/tests/type_alias_template_specialized.rs @@ -4,6 +4,7 @@ pub struct Rooted { pub ptr: MaybeWrapped<::std::os::raw::c_int>, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Rooted"][::std::mem::size_of::() - 4usize]; ["Alignment of Rooted"][::std::mem::align_of::() - 4usize]; @@ -20,6 +21,7 @@ impl Default for Rooted { } ///
pub type MaybeWrapped
= a; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: MaybeWrapped_open0_int_close0", diff --git a/bindgen-tests/tests/expectations/tests/typedef-pointer-overlap.rs b/bindgen-tests/tests/expectations/tests/typedef-pointer-overlap.rs index e25c19394e..f2376ed227 100644 --- a/bindgen-tests/tests/expectations/tests/typedef-pointer-overlap.rs +++ b/bindgen-tests/tests/expectations/tests/typedef-pointer-overlap.rs @@ -4,6 +4,7 @@ pub struct foo { pub inner: ::std::os::raw::c_char, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo"][::std::mem::size_of::() - 1usize]; ["Alignment of foo"][::std::mem::align_of::() - 1usize]; @@ -15,6 +16,7 @@ pub type foo_ptr = *const foo; pub struct bar { pub inner: ::std::os::raw::c_char, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of bar"][::std::mem::size_of::() - 1usize]; ["Alignment of bar"][::std::mem::align_of::() - 1usize]; @@ -32,6 +34,7 @@ pub type baz_ptr = *mut baz; pub union cat { pub standard_issue: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of cat"][::std::mem::size_of::() - 4usize]; ["Alignment of cat"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/typeref.rs b/bindgen-tests/tests/expectations/tests/typeref.rs index 3ef184578d..e48f0eb254 100644 --- a/bindgen-tests/tests/expectations/tests/typeref.rs +++ b/bindgen-tests/tests/expectations/tests/typeref.rs @@ -4,6 +4,7 @@ pub struct mozilla_FragmentOrURL { pub mIsLocalRef: bool, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of mozilla_FragmentOrURL", @@ -20,6 +21,7 @@ const _: () = { pub struct mozilla_Position { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of mozilla_Position"][::std::mem::size_of::() - 1usize]; [ @@ -58,6 +60,7 @@ impl Default for mozilla_StyleShapeSource { pub struct Bar { pub mFoo: *mut nsFoo, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Bar"][::std::mem::size_of::() - 8usize]; ["Alignment of Bar"][::std::mem::align_of::() - 8usize]; @@ -76,6 +79,7 @@ impl Default for Bar { pub struct nsFoo { pub mBar: mozilla_StyleShapeSource, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of nsFoo"][::std::mem::size_of::() - 8usize]; ["Alignment of nsFoo"][::std::mem::align_of::() - 8usize]; @@ -90,6 +94,7 @@ impl Default for nsFoo { } } } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of template specialization: mozilla_StyleShapeSource_open0_int_close0", diff --git a/bindgen-tests/tests/expectations/tests/underscore.rs b/bindgen-tests/tests/expectations/tests/underscore.rs index 65482d7b14..f94d5fc580 100644 --- a/bindgen-tests/tests/expectations/tests/underscore.rs +++ b/bindgen-tests/tests/expectations/tests/underscore.rs @@ -5,6 +5,7 @@ pub const __: ::std::os::raw::c_int = 10; pub struct ptr_t { pub __: [::std::os::raw::c_uchar; 8usize], } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of ptr_t"][::std::mem::size_of::() - 8usize]; ["Alignment of ptr_t"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/union-in-ns.rs b/bindgen-tests/tests/expectations/tests/union-in-ns.rs index e1925d82cc..781041addb 100644 --- a/bindgen-tests/tests/expectations/tests/union-in-ns.rs +++ b/bindgen-tests/tests/expectations/tests/union-in-ns.rs @@ -8,6 +8,7 @@ pub mod root { pub union bar { pub baz: ::std::os::raw::c_int, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of bar"][::std::mem::size_of::() - 4usize]; ["Alignment of bar"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/union_bitfield.rs b/bindgen-tests/tests/expectations/tests/union_bitfield.rs index fea7dd00d9..b529dcfbc8 100644 --- a/bindgen-tests/tests/expectations/tests/union_bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/union_bitfield.rs @@ -90,6 +90,7 @@ pub union U4 { pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of U4"][::std::mem::size_of::() - 4usize]; ["Alignment of U4"][::std::mem::align_of::() - 4usize]; @@ -138,6 +139,7 @@ pub union B { pub _bitfield_align_1: [u32; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of B"][::std::mem::size_of::() - 4usize]; ["Alignment of B"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/union_dtor.rs b/bindgen-tests/tests/expectations/tests/union_dtor.rs index 9f12f8e84f..168b0a0b1e 100644 --- a/bindgen-tests/tests/expectations/tests/union_dtor.rs +++ b/bindgen-tests/tests/expectations/tests/union_dtor.rs @@ -4,6 +4,7 @@ pub union UnionWithDtor { pub mFoo: ::std::os::raw::c_int, pub mBar: *mut ::std::os::raw::c_void, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of UnionWithDtor"][::std::mem::size_of::() - 8usize]; ["Alignment of UnionWithDtor"][::std::mem::align_of::() - 8usize]; diff --git a/bindgen-tests/tests/expectations/tests/union_fields.rs b/bindgen-tests/tests/expectations/tests/union_fields.rs index cc68bce506..c3d0f8db61 100644 --- a/bindgen-tests/tests/expectations/tests/union_fields.rs +++ b/bindgen-tests/tests/expectations/tests/union_fields.rs @@ -6,6 +6,7 @@ pub union nsStyleUnion { pub mFloat: f32, pub mPointer: *mut ::std::os::raw::c_void, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of nsStyleUnion"][::std::mem::size_of::() - 8usize]; ["Alignment of nsStyleUnion"][::std::mem::align_of::() - 8usize]; diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_struct.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_struct.rs index c01c6d516b..20f4dd2265 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_struct.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_struct.rs @@ -10,6 +10,7 @@ pub struct foo__bindgen_ty_1 { pub a: ::std::os::raw::c_uint, pub b: ::std::os::raw::c_uint, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo__bindgen_ty_1"][::std::mem::size_of::() - 8usize]; [ @@ -22,6 +23,7 @@ const _: () = { "Offset of field: foo__bindgen_ty_1::b", ][::std::mem::offset_of!(foo__bindgen_ty_1, b) - 4usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo"][::std::mem::size_of::() - 8usize]; ["Alignment of foo"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield.rs index 737ec715d3..f850f6a3da 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield.rs @@ -95,6 +95,7 @@ pub struct foo__bindgen_ty_1 { pub _bitfield_align_1: [u32; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo__bindgen_ty_1"][::std::mem::size_of::() - 4usize]; [ @@ -151,6 +152,7 @@ impl foo__bindgen_ty_1 { __bindgen_bitfield_unit } } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo"][::std::mem::size_of::() - 4usize]; ["Alignment of foo"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_union.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_union.rs index f32fe6973f..212a159cd2 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_union.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_union.rs @@ -10,6 +10,7 @@ pub union foo__bindgen_ty_1 { pub a: ::std::os::raw::c_uint, pub b: ::std::os::raw::c_ushort, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo__bindgen_ty_1"][::std::mem::size_of::() - 4usize]; [ @@ -31,6 +32,7 @@ impl Default for foo__bindgen_ty_1 { } } } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo"][::std::mem::size_of::() - 4usize]; ["Alignment of foo"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct.rs index 7579dd1dcf..859188e891 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct.rs @@ -13,6 +13,7 @@ pub struct pixel__bindgen_ty_1 { pub b: ::std::os::raw::c_uchar, pub a: ::std::os::raw::c_uchar, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of pixel__bindgen_ty_1", @@ -33,6 +34,7 @@ const _: () = { "Offset of field: pixel__bindgen_ty_1::a", ][::std::mem::offset_of!(pixel__bindgen_ty_1, a) - 3usize]; }; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of pixel"][::std::mem::size_of::() - 4usize]; ["Alignment of pixel"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union.rs index bd24400324..6e136c0d92 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union.rs @@ -11,6 +11,7 @@ pub union foo__bindgen_ty_1 { pub b: ::std::os::raw::c_ushort, pub c: ::std::os::raw::c_uchar, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo__bindgen_ty_1"][::std::mem::size_of::() - 2usize]; [ @@ -32,6 +33,7 @@ impl Default for foo__bindgen_ty_1 { } } } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo"][::std::mem::size_of::() - 4usize]; ["Alignment of foo"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/union_with_big_member.rs b/bindgen-tests/tests/expectations/tests/union_with_big_member.rs index b6b2bc25d7..9d69957a85 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_big_member.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_big_member.rs @@ -5,6 +5,7 @@ pub union WithBigArray { pub a: ::std::os::raw::c_int, pub b: [::std::os::raw::c_int; 33usize], } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of WithBigArray"][::std::mem::size_of::() - 132usize]; ["Alignment of WithBigArray"][::std::mem::align_of::() - 4usize]; @@ -30,6 +31,7 @@ pub union WithBigArray2 { pub a: ::std::os::raw::c_int, pub b: [::std::os::raw::c_char; 33usize], } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of WithBigArray2"][::std::mem::size_of::() - 36usize]; ["Alignment of WithBigArray2"][::std::mem::align_of::() - 4usize]; @@ -55,6 +57,7 @@ pub union WithBigMember { pub a: ::std::os::raw::c_int, pub b: WithBigArray, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of WithBigMember"][::std::mem::size_of::() - 132usize]; ["Alignment of WithBigMember"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/union_with_nesting.rs b/bindgen-tests/tests/expectations/tests/union_with_nesting.rs index 774a410231..5b60193ba4 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_nesting.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_nesting.rs @@ -17,6 +17,7 @@ pub union foo__bindgen_ty_1__bindgen_ty_1 { pub b1: ::std::os::raw::c_ushort, pub b2: ::std::os::raw::c_ushort, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of foo__bindgen_ty_1__bindgen_ty_1", @@ -46,6 +47,7 @@ pub union foo__bindgen_ty_1__bindgen_ty_2 { pub c1: ::std::os::raw::c_ushort, pub c2: ::std::os::raw::c_ushort, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of foo__bindgen_ty_1__bindgen_ty_2", @@ -69,6 +71,7 @@ impl Default for foo__bindgen_ty_1__bindgen_ty_2 { } } } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo__bindgen_ty_1"][::std::mem::size_of::() - 4usize]; [ @@ -84,6 +87,7 @@ impl Default for foo__bindgen_ty_1 { } } } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo"][::std::mem::size_of::() - 4usize]; ["Alignment of foo"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/union_with_non_copy_member.rs b/bindgen-tests/tests/expectations/tests/union_with_non_copy_member.rs index fb00e14d4a..d13c24d2d8 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_non_copy_member.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_non_copy_member.rs @@ -47,6 +47,7 @@ impl ::std::cmp::Eq for __BindgenUnionField {} pub struct NonCopyType { pub foo: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of NonCopyType"][::std::mem::size_of::() - 4usize]; ["Alignment of NonCopyType"][::std::mem::align_of::() - 4usize]; @@ -60,6 +61,7 @@ pub struct WithBindgenGeneratedWrapper { pub bar: __BindgenUnionField<::std::os::raw::c_int>, pub bindgen_union_field: u32, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of WithBindgenGeneratedWrapper", @@ -88,6 +90,7 @@ pub union WithManuallyDrop { pub non_copy_type: ::std::mem::ManuallyDrop, pub bar: ::std::mem::ManuallyDrop<::std::os::raw::c_int>, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of WithManuallyDrop"][::std::mem::size_of::() - 4usize]; [ @@ -115,6 +118,7 @@ pub struct WithDefaultWrapper { pub bar: __BindgenUnionField<::std::os::raw::c_int>, pub bindgen_union_field: u32, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of WithDefaultWrapper"][::std::mem::size_of::() - 4usize]; [ diff --git a/bindgen-tests/tests/expectations/tests/unknown_attr.rs b/bindgen-tests/tests/expectations/tests/unknown_attr.rs index 58c64f7fdb..bdfebb29dc 100644 --- a/bindgen-tests/tests/expectations/tests/unknown_attr.rs +++ b/bindgen-tests/tests/expectations/tests/unknown_attr.rs @@ -7,6 +7,7 @@ pub struct max_align_t { pub __bindgen_padding_0: u64, pub __clang_max_align_nonce2: ::std::os::raw::c_longlong, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of max_align_t"][::std::mem::size_of::() - 32usize]; ["Alignment of max_align_t"][::std::mem::align_of::() - 16usize]; diff --git a/bindgen-tests/tests/expectations/tests/unsorted-items.rs b/bindgen-tests/tests/expectations/tests/unsorted-items.rs index c73ae5124c..fca5715533 100644 --- a/bindgen-tests/tests/expectations/tests/unsorted-items.rs +++ b/bindgen-tests/tests/expectations/tests/unsorted-items.rs @@ -12,6 +12,7 @@ pub struct Point { pub x: number, pub y: number, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Point"][::std::mem::size_of::() - 8usize]; ["Alignment of Point"][::std::mem::align_of::() - 4usize]; @@ -24,6 +25,7 @@ pub struct Angle { pub a: number, pub b: number, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Angle"][::std::mem::size_of::() - 8usize]; ["Alignment of Angle"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/use-core.rs b/bindgen-tests/tests/expectations/tests/use-core.rs index 20272bc5fb..e7b3ce8982 100644 --- a/bindgen-tests/tests/expectations/tests/use-core.rs +++ b/bindgen-tests/tests/expectations/tests/use-core.rs @@ -8,6 +8,7 @@ pub struct foo { pub b: ::core::ffi::c_int, pub bar: *mut ::core::ffi::c_void, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo"][::core::mem::size_of::() - 16usize]; ["Alignment of foo"][::core::mem::align_of::() - 8usize]; @@ -30,6 +31,7 @@ pub union _bindgen_ty_1 { pub bar: ::core::ffi::c_int, pub baz: ::core::ffi::c_long, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of _bindgen_ty_1"][::core::mem::size_of::<_bindgen_ty_1>() - 8usize]; ["Alignment of _bindgen_ty_1"][::core::mem::align_of::<_bindgen_ty_1>() - 8usize]; diff --git a/bindgen-tests/tests/expectations/tests/var-tracing.rs b/bindgen-tests/tests/expectations/tests/var-tracing.rs index 8c61ee9d39..606cdd70b8 100644 --- a/bindgen-tests/tests/expectations/tests/var-tracing.rs +++ b/bindgen-tests/tests/expectations/tests/var-tracing.rs @@ -4,6 +4,7 @@ pub struct Bar { pub m_baz: ::std::os::raw::c_int, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Bar"][::std::mem::size_of::() - 4usize]; ["Alignment of Bar"][::std::mem::align_of::() - 4usize]; @@ -30,6 +31,7 @@ extern "C" { #[link_name = "\u{1}_ZN3Baz3FOOE"] pub static Baz_FOO: [Bar; 0usize]; } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Baz"][::std::mem::size_of::() - 1usize]; ["Alignment of Baz"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/variadic-method.rs b/bindgen-tests/tests/expectations/tests/variadic-method.rs index 8abf4343cf..93ce01b813 100644 --- a/bindgen-tests/tests/expectations/tests/variadic-method.rs +++ b/bindgen-tests/tests/expectations/tests/variadic-method.rs @@ -8,6 +8,7 @@ extern "C" { pub struct Bar { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Bar"][::std::mem::size_of::() - 1usize]; ["Alignment of Bar"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/vector.rs b/bindgen-tests/tests/expectations/tests/vector.rs index d4aed8a235..2278b520d9 100644 --- a/bindgen-tests/tests/expectations/tests/vector.rs +++ b/bindgen-tests/tests/expectations/tests/vector.rs @@ -4,6 +4,7 @@ pub struct foo { pub mMember: [::std::os::raw::c_longlong; 1usize], } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of foo"][::std::mem::size_of::() - 8usize]; ["Alignment of foo"][::std::mem::align_of::() - 8usize]; diff --git a/bindgen-tests/tests/expectations/tests/virtual_dtor.rs b/bindgen-tests/tests/expectations/tests/virtual_dtor.rs index 26198a1b4d..84211429b1 100644 --- a/bindgen-tests/tests/expectations/tests/virtual_dtor.rs +++ b/bindgen-tests/tests/expectations/tests/virtual_dtor.rs @@ -6,6 +6,7 @@ pub struct nsSlots__bindgen_vtable(::std::os::raw::c_void); pub struct nsSlots { pub vtable_: *const nsSlots__bindgen_vtable, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of nsSlots"][::std::mem::size_of::() - 8usize]; ["Alignment of nsSlots"][::std::mem::align_of::() - 8usize]; diff --git a/bindgen-tests/tests/expectations/tests/virtual_interface.rs b/bindgen-tests/tests/expectations/tests/virtual_interface.rs index ef46cbe6c4..44b245c4ea 100644 --- a/bindgen-tests/tests/expectations/tests/virtual_interface.rs +++ b/bindgen-tests/tests/expectations/tests/virtual_interface.rs @@ -12,6 +12,7 @@ pub struct PureVirtualIFace__bindgen_vtable { pub struct PureVirtualIFace { pub vtable_: *const PureVirtualIFace__bindgen_vtable, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of PureVirtualIFace"][::std::mem::size_of::() - 8usize]; [ @@ -36,6 +37,7 @@ pub struct AnotherInterface__bindgen_vtable { pub struct AnotherInterface { pub vtable_: *const AnotherInterface__bindgen_vtable, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of AnotherInterface"][::std::mem::size_of::() - 8usize]; [ @@ -56,6 +58,7 @@ impl Default for AnotherInterface { pub struct Implementation { pub _base: PureVirtualIFace, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Implementation"][::std::mem::size_of::() - 8usize]; ["Alignment of Implementation"][::std::mem::align_of::() - 8usize]; @@ -75,6 +78,7 @@ pub struct DoubleImpl { pub _base: PureVirtualIFace, pub _base_1: AnotherInterface, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of DoubleImpl"][::std::mem::size_of::() - 16usize]; ["Alignment of DoubleImpl"][::std::mem::align_of::() - 8usize]; diff --git a/bindgen-tests/tests/expectations/tests/virtual_overloaded.rs b/bindgen-tests/tests/expectations/tests/virtual_overloaded.rs index ab2df5f191..800ebbef8f 100644 --- a/bindgen-tests/tests/expectations/tests/virtual_overloaded.rs +++ b/bindgen-tests/tests/expectations/tests/virtual_overloaded.rs @@ -9,6 +9,7 @@ pub struct C__bindgen_vtable { pub struct C { pub vtable_: *const C__bindgen_vtable, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of C"][::std::mem::size_of::() - 8usize]; ["Alignment of C"][::std::mem::align_of::() - 8usize]; diff --git a/bindgen-tests/tests/expectations/tests/vtable_recursive_sig.rs b/bindgen-tests/tests/expectations/tests/vtable_recursive_sig.rs index 78b240ba09..fe08228ab9 100644 --- a/bindgen-tests/tests/expectations/tests/vtable_recursive_sig.rs +++ b/bindgen-tests/tests/expectations/tests/vtable_recursive_sig.rs @@ -8,6 +8,7 @@ pub struct Base__bindgen_vtable { pub struct Base { pub vtable_: *const Base__bindgen_vtable, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Base"][::std::mem::size_of::() - 8usize]; ["Alignment of Base"][::std::mem::align_of::() - 8usize]; @@ -30,6 +31,7 @@ extern "C" { pub struct Derived { pub _base: Base, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Derived"][::std::mem::size_of::() - 8usize]; ["Alignment of Derived"][::std::mem::align_of::() - 8usize]; diff --git a/bindgen-tests/tests/expectations/tests/wasm-constructor-returns.rs b/bindgen-tests/tests/expectations/tests/wasm-constructor-returns.rs index 00db5776c6..092d592e29 100644 --- a/bindgen-tests/tests/expectations/tests/wasm-constructor-returns.rs +++ b/bindgen-tests/tests/expectations/tests/wasm-constructor-returns.rs @@ -4,6 +4,7 @@ pub struct Foo { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Foo"][::std::mem::size_of::() - 1usize]; ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/weird_bitfields.rs b/bindgen-tests/tests/expectations/tests/weird_bitfields.rs index c6ab6fb7c4..f76189eb74 100644 --- a/bindgen-tests/tests/expectations/tests/weird_bitfields.rs +++ b/bindgen-tests/tests/expectations/tests/weird_bitfields.rs @@ -111,6 +111,7 @@ pub struct Weird { pub _bitfield_2: __BindgenBitfieldUnit<[u8; 2usize]>, pub __bindgen_padding_0: [u8; 3usize], } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Weird"][::std::mem::size_of::() - 24usize]; ["Alignment of Weird"][::std::mem::align_of::() - 4usize]; diff --git a/bindgen-tests/tests/expectations/tests/what_is_going_on.rs b/bindgen-tests/tests/expectations/tests/what_is_going_on.rs index bfc26f3950..aaeab668e1 100644 --- a/bindgen-tests/tests/expectations/tests/what_is_going_on.rs +++ b/bindgen-tests/tests/expectations/tests/what_is_going_on.rs @@ -4,6 +4,7 @@ pub struct UnknownUnits { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of UnknownUnits"][::std::mem::size_of::() - 1usize]; ["Alignment of UnknownUnits"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/win32-thiscall_nightly.rs b/bindgen-tests/tests/expectations/tests/win32-thiscall_nightly.rs index 187fa75ee4..3c84de7b95 100644 --- a/bindgen-tests/tests/expectations/tests/win32-thiscall_nightly.rs +++ b/bindgen-tests/tests/expectations/tests/win32-thiscall_nightly.rs @@ -6,6 +6,7 @@ pub struct Foo { pub _address: u8, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of Foo"][::std::mem::size_of::() - 1usize]; ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; diff --git a/bindgen-tests/tests/expectations/tests/zero-size-array-align.rs b/bindgen-tests/tests/expectations/tests/zero-size-array-align.rs index f1e18874a4..48fc0cb1d6 100644 --- a/bindgen-tests/tests/expectations/tests/zero-size-array-align.rs +++ b/bindgen-tests/tests/expectations/tests/zero-size-array-align.rs @@ -36,6 +36,7 @@ pub struct dm_deps { pub filler: ::std::os::raw::c_uint, pub device: __IncompleteArrayField<::std::os::raw::c_ulonglong>, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of dm_deps"][::std::mem::size_of::() - 8usize]; ["Alignment of dm_deps"][::std::mem::align_of::() - 8usize]; diff --git a/bindgen-tests/tests/expectations/tests/zero-sized-array.rs b/bindgen-tests/tests/expectations/tests/zero-sized-array.rs index ba8310b747..229a6ee4db 100644 --- a/bindgen-tests/tests/expectations/tests/zero-sized-array.rs +++ b/bindgen-tests/tests/expectations/tests/zero-sized-array.rs @@ -35,6 +35,7 @@ impl ::std::fmt::Debug for __IncompleteArrayField { pub struct ZeroSizedArray { pub arr: __IncompleteArrayField<::std::os::raw::c_char>, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { ["Size of ZeroSizedArray"][::std::mem::size_of::() - 0usize]; ["Alignment of ZeroSizedArray"][::std::mem::align_of::() - 1usize]; @@ -48,6 +49,7 @@ const _: () = { pub struct ContainsZeroSizedArray { pub zsa: ZeroSizedArray, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of ContainsZeroSizedArray", @@ -66,6 +68,7 @@ const _: () = { pub struct InheritsZeroSizedArray { pub _base: ZeroSizedArray, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of InheritsZeroSizedArray", @@ -80,6 +83,7 @@ const _: () = { pub struct DynamicallySizedArray { pub arr: __IncompleteArrayField<::std::os::raw::c_char>, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of DynamicallySizedArray", @@ -97,6 +101,7 @@ const _: () = { pub struct ContainsDynamicallySizedArray { pub dsa: DynamicallySizedArray, } +#[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [ "Size of ContainsDynamicallySizedArray", diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 46d615b25d..741a3fbe43 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -1313,6 +1313,7 @@ impl CodeGenerator for TemplateInstantiation { // #size_of_expr < #size, the subtraction will overflow, both // of which print enough information to see what has gone wrong. result.push(quote! { + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [#size_of_err][#size_of_expr - #size]; [#align_of_err][#align_of_expr - #align]; @@ -2523,6 +2524,7 @@ impl CodeGenerator for CompInfo { if compile_time { result.push(quote! { + #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { [#size_of_err][#size_of_expr - #size]; #check_struct_align From 93648e43b79c0382594aa351fbc219534bc24d41 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Tue, 20 Aug 2024 11:35:18 -0500 Subject: [PATCH 720/942] Fix `collapsible_match` clippy warning --- bindgen/ir/item.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/bindgen/ir/item.rs b/bindgen/ir/item.rs index 8dc7bf84ee..94abe4a86b 100644 --- a/bindgen/ir/item.rs +++ b/bindgen/ir/item.rs @@ -940,13 +940,13 @@ impl Item { // Only use local ids for enums, classes, structs and union types. All // other items use their global ID. let ty_kind = self.kind().as_type().map(|t| t.kind()); - if let Some(ty_kind) = ty_kind { - match *ty_kind { - TypeKind::Comp(..) | - TypeKind::TemplateInstantiation(..) | - TypeKind::Enum(..) => return self.local_id(ctx).to_string(), - _ => {} - } + if let Some( + TypeKind::Comp(..) | + TypeKind::TemplateInstantiation(..) | + TypeKind::Enum(..), + ) = ty_kind + { + return self.local_id(ctx).to_string(); } // Note that this `id_` prefix prevents (really unlikely) collisions From 1f3fafef2fd864a39858a3bce322c0a35d9fddc1 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Tue, 20 Aug 2024 12:43:27 -0500 Subject: [PATCH 721/942] Revert "Only trigger the publish workflow manually" This reverts commit 26fc39b23df7cd27f34b9eec944d2964df9b0e1d. --- .github/workflows/publish.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 1aaeb006df..352199d7d7 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,8 +1,10 @@ -# To trigger this: -# - go to Actions > Publish -# - click the Run Workflow dropdown in the top-right -name: Publish -on: workflow_dispatch +# This is triggered after the Release workflow successfully completes its run +on: + workflow_run: + workflows: + - Release + types: + - completed env: CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} jobs: From 21c60f473f4e824d4aa9b2b508056320d474b110 Mon Sep 17 00:00:00 2001 From: pvdrz Date: Tue, 20 Aug 2024 17:51:40 +0000 Subject: [PATCH 722/942] Bump crates version to 0.70.1 --- CHANGELOG.md | 193 ++++++++++++++++++++++------------------- Cargo.lock | 4 +- bindgen-cli/Cargo.toml | 4 +- bindgen/Cargo.toml | 2 +- 4 files changed, 108 insertions(+), 95 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bcb0eec6e..76e18d5c1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,202 +7,208 @@ - [Removed](#removed) - [Fixed](#fixed) - [Security](#security) -- [0.70.0 (2024-08-16)](#0700-2024-08-16) +- [0.70.1 (2024-08-20)](#0701-2024-08-20) - [Added](#added-1) - [Changed](#changed-1) - [Removed](#removed-1) - [Fixed](#fixed-1) - [Security](#security-1) -- [0.69.4 (2024-02-04)](#0694-2024-02-04) +- [0.70.0 (2024-08-16)](#0700-2024-08-16) - [Added](#added-2) - [Changed](#changed-2) - [Removed](#removed-2) - [Fixed](#fixed-2) - [Security](#security-2) -- [0.69.3 (2024-02-04)](#0693-2024-02-04) +- [0.69.4 (2024-02-04)](#0694-2024-02-04) - [Added](#added-3) - [Changed](#changed-3) - [Removed](#removed-3) - [Fixed](#fixed-3) - [Security](#security-3) -- [0.69.2 (2024-01-13)](#0692-2024-01-13) +- [0.69.3 (2024-02-04)](#0693-2024-02-04) - [Added](#added-4) - [Changed](#changed-4) - [Removed](#removed-4) - [Fixed](#fixed-4) - [Security](#security-4) -- [0.69.1 (2023-11-02)](#0691-2023-11-02) - - [Fixed](#fixed-5) -- [0.69.0 (2023-11-01)](#0690-2023-11-01) +- [0.69.2 (2024-01-13)](#0692-2024-01-13) - [Added](#added-5) - [Changed](#changed-5) - [Removed](#removed-5) - - [Fixed](#fixed-6) + - [Fixed](#fixed-5) - [Security](#security-5) -- [0.68.1](#0681) - - [Fixed](#fixed-7) -- [0.68.0](#0680) +- [0.69.1 (2023-11-02)](#0691-2023-11-02) + - [Fixed](#fixed-6) +- [0.69.0 (2023-11-01)](#0690-2023-11-01) - [Added](#added-6) - [Changed](#changed-6) - [Removed](#removed-6) + - [Fixed](#fixed-7) + - [Security](#security-6) +- [0.68.1](#0681) - [Fixed](#fixed-8) -- [0.67.0](#0670) -- [0.66.1](#0661) - - [Removed](#removed-7) -- [0.66.0](#0660) +- [0.68.0](#0680) - [Added](#added-7) - [Changed](#changed-7) - - [Removed](#removed-8) -- [0.65.1](#0651) + - [Removed](#removed-7) - [Fixed](#fixed-9) -- [0.65.0](#0650) +- [0.67.0](#0670) +- [0.66.1](#0661) + - [Removed](#removed-8) +- [0.66.0](#0660) - [Added](#added-8) - [Changed](#changed-8) - [Removed](#removed-9) -- [0.64.0](#0640) +- [0.65.1](#0651) + - [Fixed](#fixed-10) +- [0.65.0](#0650) - [Added](#added-9) - [Changed](#changed-9) -- [0.63.0](#0630) + - [Removed](#removed-10) +- [0.64.0](#0640) - [Added](#added-10) - [Changed](#changed-10) - - [Removed](#removed-10) -- [0.62.0](#0620) +- [0.63.0](#0630) - [Added](#added-11) - [Changed](#changed-11) - - [Fixed](#fixed-10) -- [0.61.0](#0610) + - [Removed](#removed-11) +- [0.62.0](#0620) - [Added](#added-12) - [Changed](#changed-12) - [Fixed](#fixed-11) -- [0.60.1](#0601) - - [Fixed](#fixed-12) -- [0.60.0](#0600) +- [0.61.0](#0610) - [Added](#added-13) - - [Fixed](#fixed-13) - [Changed](#changed-13) - - [Removed](#removed-11) + - [Fixed](#fixed-12) +- [0.60.1](#0601) + - [Fixed](#fixed-13) +- [0.60.0](#0600) + - [Added](#added-14) + - [Fixed](#fixed-14) + - [Changed](#changed-14) + - [Removed](#removed-12) - [0.59.2](#0592) - [0.59.1](#0591) - - [Fixed](#fixed-14) -- [0.59.0](#0590) - - [Added](#added-14) - [Fixed](#fixed-15) - - [Changed](#changed-14) -- [0.58.1](#0581) +- [0.59.0](#0590) - [Added](#added-15) -- [0.58.0](#0580) - - [Added](#added-16) - [Fixed](#fixed-16) - [Changed](#changed-15) - - [Deprecated](#deprecated) - - [Removed](#removed-12) - - [Fixed](#fixed-17) - - [Security](#security-6) -- [0.57.0](#0570) +- [0.58.1](#0581) + - [Added](#added-16) +- [0.58.0](#0580) - [Added](#added-17) + - [Fixed](#fixed-17) + - [Changed](#changed-16) + - [Deprecated](#deprecated) + - [Removed](#removed-13) - [Fixed](#fixed-18) -- [0.56.0](#0560) + - [Security](#security-7) +- [0.57.0](#0570) - [Added](#added-18) - - [Changed](#changed-16) - [Fixed](#fixed-19) -- [0.55.1](#0551) - - [Fixed](#fixed-20) -- [0.55.0](#0550) - - [Removed](#removed-13) +- [0.56.0](#0560) - [Added](#added-19) - [Changed](#changed-17) + - [Fixed](#fixed-20) +- [0.55.1](#0551) - [Fixed](#fixed-21) -- [0.54.1](#0541) +- [0.55.0](#0550) + - [Removed](#removed-14) - [Added](#added-20) - [Changed](#changed-18) - [Fixed](#fixed-22) -- [0.54.0](#0540) +- [0.54.1](#0541) - [Added](#added-21) - [Changed](#changed-19) - [Fixed](#fixed-23) -- [0.53.3](#0533) +- [0.54.0](#0540) - [Added](#added-22) + - [Changed](#changed-20) - [Fixed](#fixed-24) +- [0.53.3](#0533) + - [Added](#added-23) + - [Fixed](#fixed-25) - [0.53.2](#0532) - - [Changed](#changed-20) + - [Changed](#changed-21) - [0.53.1](#0531) - - [Added](#added-23) -- [0.53.0](#0530) - [Added](#added-24) - - [Changed](#changed-21) - - [Fixed](#fixed-25) -- [0.52.0](#0520) +- [0.53.0](#0530) - [Added](#added-25) - [Changed](#changed-22) - [Fixed](#fixed-26) -- [0.51.1](#0511) - - [Fixed](#fixed-27) +- [0.52.0](#0520) + - [Added](#added-26) - [Changed](#changed-23) -- [0.51.0](#0510) + - [Fixed](#fixed-27) +- [0.51.1](#0511) - [Fixed](#fixed-28) - [Changed](#changed-24) - - [Added](#added-26) -- [0.50.0](#0500) +- [0.51.0](#0510) + - [Fixed](#fixed-29) + - [Changed](#changed-25) - [Added](#added-27) -- [0.49.3](#0493) +- [0.50.0](#0500) - [Added](#added-28) +- [0.49.3](#0493) + - [Added](#added-29) - [0.49.2](#0492) - - [Changed](#changed-25) -- [0.49.1](#0491) - - [Fixed](#fixed-29) - [Changed](#changed-26) -- [0.49.0](#0490) - - [Added](#added-29) +- [0.49.1](#0491) - [Fixed](#fixed-30) - [Changed](#changed-27) -- [0.48.1](#0481) +- [0.49.0](#0490) + - [Added](#added-30) - [Fixed](#fixed-31) -- [0.48.0](#0480) - [Changed](#changed-28) +- [0.48.1](#0481) - [Fixed](#fixed-32) -- [0.47.4](#0474) - - [Added](#added-30) -- [0.47.3](#0473) +- [0.48.0](#0480) - [Changed](#changed-29) -- [0.47.2](#0472) - [Fixed](#fixed-33) -- [0.47.1](#0471) +- [0.47.4](#0474) + - [Added](#added-31) +- [0.47.3](#0473) - [Changed](#changed-30) +- [0.47.2](#0472) - [Fixed](#fixed-34) -- [0.47.0](#0470) +- [0.47.1](#0471) - [Changed](#changed-31) - [Fixed](#fixed-35) -- [0.33.1 .. 0.46.0](#0331--0460) - - [Added](#added-31) - - [Removed](#removed-14) +- [0.47.0](#0470) - [Changed](#changed-32) - [Fixed](#fixed-36) -- [0.33.1](#0331) +- [0.33.1 .. 0.46.0](#0331--0460) + - [Added](#added-32) + - [Removed](#removed-15) + - [Changed](#changed-33) - [Fixed](#fixed-37) +- [0.33.1](#0331) + - [Fixed](#fixed-38) - [0.33.0](#0330) - [0.32.2](#0322) - - [Fixed](#fixed-38) -- [0.32.1](#0321) - [Fixed](#fixed-39) -- [0.32.0](#0320) - - [Added](#added-32) - - [Changed](#changed-33) +- [0.32.1](#0321) - [Fixed](#fixed-40) -- [0.31.0](#0310) +- [0.32.0](#0320) - [Added](#added-33) - [Changed](#changed-34) - - [Deprecated](#deprecated-1) - - [Removed](#removed-15) - [Fixed](#fixed-41) -- [0.30.0](#0300) +- [0.31.0](#0310) - [Added](#added-34) - [Changed](#changed-35) - - [Deprecated](#deprecated-2) + - [Deprecated](#deprecated-1) + - [Removed](#removed-16) - [Fixed](#fixed-42) -- [0.29.0](#0290) +- [0.30.0](#0300) - [Added](#added-35) - [Changed](#changed-36) + - [Deprecated](#deprecated-2) - [Fixed](#fixed-43) +- [0.29.0](#0290) + - [Added](#added-36) + - [Changed](#changed-37) + - [Fixed](#fixed-44) @@ -212,6 +218,13 @@ ## Changed ## Removed ## Fixed +## Security + +# 0.70.1 (2024-08-20) +## Added +## Changed +## Removed +## Fixed - Fix regression where the `const` layout tests were triggering the `unnecessary_operation` and `identity_op` clippy warnings. ## Security diff --git a/Cargo.lock b/Cargo.lock index 980aa6d6f7..8fea3f5b5e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -23,7 +23,7 @@ dependencies = [ [[package]] name = "bindgen" -version = "0.70.0" +version = "0.70.1" dependencies = [ "annotate-snippets", "bitflags 2.2.1", @@ -42,7 +42,7 @@ dependencies = [ [[package]] name = "bindgen-cli" -version = "0.70.0" +version = "0.70.1" dependencies = [ "bindgen", "clap", diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index a74ce57cfc..6fc02f3a55 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -11,7 +11,7 @@ readme = "../README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.70.0" +version = "0.70.1" edition = "2018" rust-version = "1.70.0" @@ -20,7 +20,7 @@ path = "main.rs" name = "bindgen" [dependencies] -bindgen = { path = "../bindgen", version = "=0.70.0", default-features = false, features = ["__cli", "experimental", "prettyplease"] } +bindgen = { path = "../bindgen", version = "=0.70.1", default-features = false, features = ["__cli", "experimental", "prettyplease"] } clap = { version = "4", features = ["derive"] } clap_complete = "4" env_logger = { version = "0.10.0", optional = true } diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index 6e12505855..9eddd5157d 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -14,7 +14,7 @@ readme = "../README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.70.0" +version = "0.70.1" edition = "2018" build = "build.rs" # If you change this, also update README.md and msrv in .github/workflows/bindgen.yml From 8c1ffdaaf791ea28b9244ee04719163695b87cbd Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Tue, 20 Aug 2024 16:00:40 -0500 Subject: [PATCH 723/942] Update cargo-dist config --- .github/workflows/release.yml | 89 ++++++++++++++++++++--------------- Cargo.toml | 10 ++-- 2 files changed, 58 insertions(+), 41 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 502a5ff8da..6d739c57d9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,4 +1,4 @@ -# Copyright 2022-2023, axodotdev +# Copyright 2022-2024, axodotdev # SPDX-License-Identifier: MIT or Apache-2.0 # # CI that: @@ -6,15 +6,14 @@ # * checks for a Git Tag that looks like a release # * builds artifacts with cargo-dist (archives, installers, hashes) # * uploads those artifacts to temporary workflow zip -# * on success, uploads the artifacts to a Github Release +# * on success, uploads the artifacts to a GitHub Release # -# Note that the Github Release will be created with a generated +# Note that the GitHub Release will be created with a generated # title/body based on your changelogs. name: Release - permissions: - contents: write + "contents": "write" # This task will run whenever you push a git tag that looks like a version # like "1.0.0", "v0.1.0-prerelease.1", "my-app/0.1.0", "releases/v1.0.0", etc. @@ -31,22 +30,22 @@ permissions: # packages versioned/released in lockstep). # # If you push multiple tags at once, separate instances of this workflow will -# spin up, creating an independent announcement for each one. However Github +# spin up, creating an independent announcement for each one. However, GitHub # will hard limit this to 3 tags per commit, as it will assume more tags is a # mistake. # # If there's a prerelease-style suffix to the version, then the release(s) # will be marked as a prerelease. on: + pull_request: push: tags: - '**[0-9]+.[0-9]+.[0-9]+*' - pull_request: jobs: # Run 'cargo dist plan' (or host) to determine what tasks we need to do plan: - runs-on: ubuntu-latest + runs-on: "ubuntu-20.04" outputs: val: ${{ steps.plan.outputs.manifest }} tag: ${{ !github.event.pull_request && github.ref_name || '' }} @@ -62,7 +61,12 @@ jobs: # we specify bash to get pipefail; it guards against the `curl` command # failing. otherwise `sh` won't catch that `curl` returned non-0 shell: bash - run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.12.0/cargo-dist-installer.sh | sh" + run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.21.0/cargo-dist-installer.sh | sh" + - name: Cache cargo-dist + uses: actions/upload-artifact@v4 + with: + name: cargo-dist-cache + path: ~/.cargo/bin/cargo-dist # sure would be cool if github gave us proper conditionals... # so here's a doubly-nested ternary-via-truthiness to try to provide the best possible # functionality based on whether this is a pull_request, and whether it's from a fork. @@ -105,10 +109,12 @@ jobs: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} BUILD_MANIFEST_NAME: target/distrib/${{ join(matrix.targets, '-') }}-dist-manifest.json steps: + - name: enable windows longpaths + run: | + git config --global core.longpaths true - uses: actions/checkout@v4 with: submodules: recursive - - uses: swatinem/rust-cache@v2 - name: Install cargo-dist run: ${{ matrix.install_dist }} # Get the dist-manifest @@ -135,7 +141,7 @@ jobs: run: | # Parse out what we just built and upload it to scratch storage echo "paths<> "$GITHUB_OUTPUT" - jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json >> "$GITHUB_OUTPUT" + jq --raw-output ".upload_files[]" dist-manifest.json >> "$GITHUB_OUTPUT" echo "EOF" >> "$GITHUB_OUTPUT" cp dist-manifest.json "$BUILD_MANIFEST_NAME" @@ -160,9 +166,12 @@ jobs: - uses: actions/checkout@v4 with: submodules: recursive - - name: Install cargo-dist - shell: bash - run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.12.0/cargo-dist-installer.sh | sh" + - name: Install cached cargo-dist + uses: actions/download-artifact@v4 + with: + name: cargo-dist-cache + path: ~/.cargo/bin/ + - run: chmod +x ~/.cargo/bin/cargo-dist # Get all the local artifacts for the global tasks to use (for e.g. checksums) - name: Fetch local artifacts uses: actions/download-artifact@v4 @@ -178,7 +187,7 @@ jobs: # Parse out what we just built and upload it to scratch storage echo "paths<> "$GITHUB_OUTPUT" - jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json >> "$GITHUB_OUTPUT" + jq --raw-output ".upload_files[]" dist-manifest.json >> "$GITHUB_OUTPUT" echo "EOF" >> "$GITHUB_OUTPUT" cp dist-manifest.json "$BUILD_MANIFEST_NAME" @@ -206,8 +215,12 @@ jobs: - uses: actions/checkout@v4 with: submodules: recursive - - name: Install cargo-dist - run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.12.0/cargo-dist-installer.sh | sh" + - name: Install cached cargo-dist + uses: actions/download-artifact@v4 + with: + name: cargo-dist-cache + path: ~/.cargo/bin/ + - run: chmod +x ~/.cargo/bin/cargo-dist # Fetch artifacts from scratch-storage - name: Fetch artifacts uses: actions/download-artifact@v4 @@ -215,7 +228,6 @@ jobs: pattern: artifacts-* path: target/distrib/ merge-multiple: true - # This is a harmless no-op for Github Releases, hosting for that happens in "announce" - id: host shell: bash run: | @@ -229,8 +241,29 @@ jobs: # Overwrite the previous copy name: artifacts-dist-manifest path: dist-manifest.json + # Create a GitHub Release while uploading all files to it + - name: "Download GitHub Artifacts" + uses: actions/download-artifact@v4 + with: + pattern: artifacts-* + path: artifacts + merge-multiple: true + - name: Cleanup + run: | + # Remove the granular manifests + rm -f artifacts/*-dist-manifest.json + - name: Create GitHub Release + env: + PRERELEASE_FLAG: "${{ fromJson(steps.host.outputs.manifest).announcement_is_prerelease && '--prerelease' || '' }}" + ANNOUNCEMENT_TITLE: "${{ fromJson(steps.host.outputs.manifest).announcement_title }}" + ANNOUNCEMENT_BODY: "${{ fromJson(steps.host.outputs.manifest).announcement_github_body }}" + RELEASE_COMMIT: "${{ github.sha }}" + run: | + # Write and read notes from a file to avoid quoting breaking things + echo "$ANNOUNCEMENT_BODY" > $RUNNER_TEMP/notes.txt + + gh release create "${{ needs.plan.outputs.tag }}" --target "$RELEASE_COMMIT" $PRERELEASE_FLAG --title "$ANNOUNCEMENT_TITLE" --notes-file "$RUNNER_TEMP/notes.txt" artifacts/* - # Create a Github Release while uploading all files to it announce: needs: - plan @@ -246,21 +279,3 @@ jobs: - uses: actions/checkout@v4 with: submodules: recursive - - name: "Download Github Artifacts" - uses: actions/download-artifact@v4 - with: - pattern: artifacts-* - path: artifacts - merge-multiple: true - - name: Cleanup - run: | - # Remove the granular manifests - rm -f artifacts/*-dist-manifest.json - - name: Create Github Release - uses: ncipollo/release-action@v1 - with: - tag: ${{ needs.plan.outputs.tag }} - name: ${{ fromJson(needs.host.outputs.val).announcement_title }} - body: ${{ fromJson(needs.host.outputs.val).announcement_github_body }} - prerelease: ${{ fromJson(needs.host.outputs.val).announcement_is_prerelease }} - artifacts: "artifacts/*" diff --git a/Cargo.toml b/Cargo.toml index bc9a80555d..400fd8788a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,19 +17,21 @@ default-members = [ # Config for 'cargo dist' [workspace.metadata.dist] # The preferred cargo-dist version to use in CI (Cargo.toml SemVer syntax) -cargo-dist-version = "0.12.0" +cargo-dist-version = "0.21.0" # CI backends to support -ci = ["github"] +ci = "github" # The installers to generate for each app installers = ["shell", "powershell"] # Target platforms to build apps for (Rust target-triple syntax) -targets = ["aarch64-apple-darwin", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu"] +targets = ["aarch64-apple-darwin", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu", "x86_64-pc-windows-msvc"] # Whether to consider the binaries in a package for distribution (defaults true) dist = false -# Publish jobs to run in CI +# Which actions to run on pull requests pr-run-mode = "plan" # Whether to install an updater program install-updater = false +# Path that installers should place binaries in +install-path = "CARGO_HOME" # Config for 'cargo release' [workspace.metadata.release] From 2fb25e3be6a6a8e9ba13a8d1c736d5d8180dab1e Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Thu, 22 Aug 2024 11:15:54 -0500 Subject: [PATCH 724/942] Only publish on crates.io if the workflow event is called `'Release'` --- .github/workflows/publish.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 352199d7d7..7333d62aff 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,4 +1,5 @@ # This is triggered after the Release workflow successfully completes its run +name: Publish on crates.io on: workflow_run: workflows: @@ -10,8 +11,10 @@ env: jobs: cargo-publish: runs-on: ubuntu-latest - if: ${{ github.event.workflow_run.conclusion == 'success' }} + if: ${{ (github.event.workflow_run.conclusion == 'success') && (github.event.workflow.name == 'Release') }} steps: + - name: Print workflow event name + run: echo "${{ github.event.workflow.name }}" - name: Checkout sources uses: actions/checkout@v4 - name: Install stable toolchain From d89ebe4823c8fbc8e4e2876f685dbdded44b39b7 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Thu, 29 Aug 2024 22:14:53 -0500 Subject: [PATCH 725/942] Explain how to generate documentation for system headers --- book/src/faq.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/book/src/faq.md b/book/src/faq.md index e82b4a446a..bbaaab6368 100644 --- a/book/src/faq.md +++ b/book/src/faq.md @@ -8,6 +8,7 @@ - [Does `bindgen` support the C++ Standard Template Library (STL)?](#does-bindgen-support-the-c-standard-template-library-stl) - [How to deal with bindgen generated padding fields?](#how-to-deal-with-bindgen-generated-padding-fields) - [How to generate bindings for a custom target?](#how-to-generate-bindings-for-a-custom-target) +- [Why isn't `bindgen` generating documentation for system headers?](#why-isnt-bindgen-generating-documentation-for-system-headers) @@ -115,3 +116,9 @@ $ bindgen -- --target=armv7a-none-eabi ``` If you are using `bindgen` as a library, you should call `builder.clang_arg("--target=armv7a-none-eabi")` on your `builder`. + +### Why isn't `bindgen` generating documentation for system headers? + +By default, Bindgen does not generate documentation for system headers because +`libclang` does not provide this information. To address this, you should call +`builder.clang_arg("-fretain-comments-from-system-headers")` on your `builder`. From 39232cc6e00e61df6e130d06fd2858218cce1c32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 2 Sep 2024 15:40:37 +0200 Subject: [PATCH 726/942] ir: Dig into atomic types. Fixes #2920 --- .../tests/expectations/tests/atomic-constant.rs | 7 +++++++ .../expectations/tests/libclang-9/atomic-constant.rs | 4 ++++ bindgen-tests/tests/headers/atomic-constant.h | 2 ++ bindgen/Cargo.toml | 2 +- bindgen/clang.rs | 9 +++++++++ bindgen/ir/ty.rs | 12 ++++++++++++ bindgen/ir/var.rs | 3 ++- 7 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 bindgen-tests/tests/expectations/tests/atomic-constant.rs create mode 100644 bindgen-tests/tests/expectations/tests/libclang-9/atomic-constant.rs create mode 100644 bindgen-tests/tests/headers/atomic-constant.h diff --git a/bindgen-tests/tests/expectations/tests/atomic-constant.rs b/bindgen-tests/tests/expectations/tests/atomic-constant.rs new file mode 100644 index 0000000000..bd3c18697b --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/atomic-constant.rs @@ -0,0 +1,7 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +extern "C" { + pub static mut a: ::std::os::raw::c_int; +} +extern "C" { + pub static mut b: ::std::os::raw::c_int; +} diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/atomic-constant.rs b/bindgen-tests/tests/expectations/tests/libclang-9/atomic-constant.rs new file mode 100644 index 0000000000..ce12eaad3a --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/libclang-9/atomic-constant.rs @@ -0,0 +1,4 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +extern "C" { + pub static mut b: ::std::os::raw::c_int; +} diff --git a/bindgen-tests/tests/headers/atomic-constant.h b/bindgen-tests/tests/headers/atomic-constant.h new file mode 100644 index 0000000000..b28f76f7e4 --- /dev/null +++ b/bindgen-tests/tests/headers/atomic-constant.h @@ -0,0 +1,2 @@ +_Atomic(int) a; +int b; diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index 9eddd5157d..1c19cc3539 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -28,7 +28,7 @@ path = "lib.rs" annotate-snippets = { version = "0.9.1", features = ["color"], optional = true } bitflags = "2.2.1" cexpr = "0.6" -clang-sys = { version = "1", features = ["clang_6_0"] } +clang-sys = { version = "1", features = ["clang_11_0"] } itertools = { version = ">=0.10,<0.14", default-features = false } log = { version = "0.4", optional = true } prettyplease = { version = "0.2.7", optional = true, features = ["verbatim"] } diff --git a/bindgen/clang.rs b/bindgen/clang.rs index 47c7b1704a..e585fb31bd 100644 --- a/bindgen/clang.rs +++ b/bindgen/clang.rs @@ -1493,6 +1493,15 @@ impl Type { } } + /// For atomic types, get the underlying type. + pub(crate) fn atomic_value_type(&self) -> Type { + unsafe { + Type { + x: clang_Type_getValueType(self.x), + } + } + } + /// Is this a valid type? pub(crate) fn is_valid(&self) -> bool { self.kind() != CXType_Invalid diff --git a/bindgen/ir/ty.rs b/bindgen/ir/ty.rs index 2a24dd0291..6d4c5666dc 100644 --- a/bindgen/ir/ty.rs +++ b/bindgen/ir/ty.rs @@ -1167,6 +1167,18 @@ impl Type { .expect("Not able to resolve array element?"); TypeKind::Array(inner, ty.num_elements().unwrap()) } + CXType_Atomic => { + // TODO(emilio): Maybe we can preserve the "is atomic" bit somehow and generate + // something more useful... But for now this is better than panicking or + // generating nothing. + return Self::from_clang_ty( + potential_id, + &ty.atomic_value_type(), + location, + parent_id, + ctx, + ); + } CXType_Elaborated => { return Self::from_clang_ty( potential_id, diff --git a/bindgen/ir/var.rs b/bindgen/ir/var.rs index 40a061e16c..b8fffc7d66 100644 --- a/bindgen/ir/var.rs +++ b/bindgen/ir/var.rs @@ -320,7 +320,8 @@ impl ClangSubItemParser for Var { matches!(ty.kind(), CXType_Auto | CXType_Unexposed), "Couldn't resolve constant type, and it \ wasn't an nondeductible auto type or unexposed \ - type!" + type: {:?}", + ty ); return Err(e); } From 2d9273cefa7667068cfe82e75ca5f7091746f787 Mon Sep 17 00:00:00 2001 From: Zhang Jingqiang Date: Mon, 19 Aug 2024 15:06:37 +0800 Subject: [PATCH 727/942] update to annotate-snippets 0.10.2 --- Cargo.lock | 25 +++++++++++-------------- bindgen/Cargo.toml | 2 +- bindgen/diagnostics.rs | 12 +++--------- 3 files changed, 15 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8fea3f5b5e..dff0e9c477 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,14 +13,20 @@ dependencies = [ [[package]] name = "annotate-snippets" -version = "0.9.1" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3b9d411ecbaf79885c6df4d75fff75858d5995ff25385657a28af47e82f9c36" +checksum = "6d9b665789884a7e8fb06c84b295e923b03ca51edbb7d08f91a6a50322ecbfe6" dependencies = [ + "anstyle", "unicode-width", - "yansi-term", ] +[[package]] +name = "anstyle" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" + [[package]] name = "bindgen" version = "0.70.1" @@ -609,9 +615,9 @@ checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" [[package]] name = "unicode-width" -version = "0.1.10" +version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" +checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" [[package]] name = "version_check" @@ -802,12 +808,3 @@ name = "windows_x86_64_msvc" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" - -[[package]] -name = "yansi-term" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe5c30ade05e61656247b2e334a031dfd0cc466fadef865bdcdea8d537951bf1" -dependencies = [ - "winapi", -] diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index 1c19cc3539..a01ad56a02 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -25,7 +25,7 @@ name = "bindgen" path = "lib.rs" [dependencies] -annotate-snippets = { version = "0.9.1", features = ["color"], optional = true } +annotate-snippets = { version = "0.10.2", optional = true } bitflags = "2.2.1" cexpr = "0.6" clang-sys = { version = "1", features = ["clang_11_0"] } diff --git a/bindgen/diagnostics.rs b/bindgen/diagnostics.rs index f765afe970..3071f9a5af 100644 --- a/bindgen/diagnostics.rs +++ b/bindgen/diagnostics.rs @@ -7,12 +7,9 @@ use std::io::{self, BufRead, BufReader}; use std::{borrow::Cow, fs::File}; use annotate_snippets::{ - display_list::{DisplayList, FormatOptions}, - snippet::{Annotation, Slice as ExtSlice, Snippet}, + Annotation, AnnotationType, Renderer, Slice as ExtSlice, Snippet, }; -use annotate_snippets::snippet::AnnotationType; - #[derive(Clone, Copy, Debug)] pub(crate) enum Level { Error, @@ -121,12 +118,9 @@ impl<'a> Diagnostic<'a> { title, footer, slices, - opt: FormatOptions { - color: true, - ..Default::default() - }, }; - let dl = DisplayList::from(snippet); + let renderer = Renderer::styled(); + let dl = renderer.render(snippet); if INVOKED_BY_BUILD_SCRIPT.with(Clone::clone) { // This is just a hack which hides the `warning:` added by cargo at the beginning of From 82ffe4060d9c2422a47bc4a5d80d7eb3aa3d9b72 Mon Sep 17 00:00:00 2001 From: Zhang Jingqiang Date: Mon, 19 Aug 2024 15:56:59 +0800 Subject: [PATCH 728/942] update to use annotate-snippets 0.11.4 - re-export annotate-snippets::Level in diagnostics.rs - require title is always set in Diagnostic --- Cargo.lock | 4 +-- bindgen/Cargo.toml | 2 +- bindgen/codegen/mod.rs | 6 ++-- bindgen/diagnostics.rs | 72 +++++++++++------------------------------- bindgen/ir/context.rs | 2 +- bindgen/ir/var.rs | 2 +- bindgen/lib.rs | 4 +-- bindgen/regex_set.rs | 6 ++-- 8 files changed, 31 insertions(+), 67 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dff0e9c477..9ba69946ec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,9 +13,9 @@ dependencies = [ [[package]] name = "annotate-snippets" -version = "0.10.2" +version = "0.11.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d9b665789884a7e8fb06c84b295e923b03ca51edbb7d08f91a6a50322ecbfe6" +checksum = "24e35ed54e5ea7997c14ed4c70ba043478db1112e98263b3b035907aa197d991" dependencies = [ "anstyle", "unicode-width", diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index a01ad56a02..cad94d0c16 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -25,7 +25,7 @@ name = "bindgen" path = "lib.rs" [dependencies] -annotate-snippets = { version = "0.10.2", optional = true } +annotate-snippets = { version = "0.11.4", optional = true } bitflags = "2.2.1" cexpr = "0.6" clang-sys = { version = "1", features = ["clang_11_0"] } diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 741a3fbe43..1cccac6761 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -4619,11 +4619,11 @@ fn unsupported_abi_diagnostic( fn_name, error ), - Level::Warn, + Level::Warning, ) .add_annotation( "No code will be generated for this function.", - Level::Warn, + Level::Warning, ) .add_annotation( format!( @@ -4667,7 +4667,7 @@ fn variadic_fn_diagnostic( let mut diag = Diagnostic::default(); - diag.with_title(format!("Cannot generate wrapper for the static function `{}`.", fn_name), Level::Warn) + diag.with_title(format!("Cannot generate wrapper for the static function `{}`.", fn_name), Level::Warning) .add_annotation("The `--wrap-static-fns` feature does not support variadic functions.", Level::Note) .add_annotation("No code will be generated for this function.", Level::Note); diff --git a/bindgen/diagnostics.rs b/bindgen/diagnostics.rs index 3071f9a5af..e6f169e260 100644 --- a/bindgen/diagnostics.rs +++ b/bindgen/diagnostics.rs @@ -6,30 +6,9 @@ use std::fmt::Write; use std::io::{self, BufRead, BufReader}; use std::{borrow::Cow, fs::File}; -use annotate_snippets::{ - Annotation, AnnotationType, Renderer, Slice as ExtSlice, Snippet, -}; - -#[derive(Clone, Copy, Debug)] -pub(crate) enum Level { - Error, - Warn, - Info, - Note, - Help, -} +use annotate_snippets::{Renderer, Snippet}; -impl From for AnnotationType { - fn from(level: Level) -> Self { - match level { - Level::Error => Self::Error, - Level::Warn => Self::Warning, - Level::Info => Self::Info, - Level::Note => Self::Note, - Level::Help => Self::Help, - } - } -} +pub(crate) use annotate_snippets::Level; /// A `bindgen` diagnostic. #[derive(Default)] @@ -75,52 +54,37 @@ impl<'a> Diagnostic<'a> { static INVOKED_BY_BUILD_SCRIPT: bool = std::env::var_os("CARGO_CFG_TARGET_ARCH").is_some(); } - let mut title = None; let mut footer = vec![]; let mut slices = vec![]; - if let Some((msg, level)) = &self.title { - title = Some(Annotation { - id: Some("bindgen"), - label: Some(msg.as_ref()), - annotation_type: (*level).into(), - }) - } + let snippet = if let Some((msg, level)) = &self.title { + (*level).title(msg) + } else { + return; + }; for (msg, level) in &self.footer { - footer.push(Annotation { - id: None, - label: Some(msg.as_ref()), - annotation_type: (*level).into(), - }); + footer.push((*level).title(msg)); } // add additional info that this is generated by bindgen // so as to not confuse with rustc warnings - footer.push(Annotation { - id: None, - label: Some("This diagnostic was generated by bindgen."), - annotation_type: AnnotationType::Info, - }); + footer.push( + Level::Info.title("This diagnostic was generated by bindgen."), + ); for slice in &self.slices { if let Some(source) = &slice.source { - slices.push(ExtSlice { - source: source.as_ref(), - line_start: slice.line.unwrap_or_default(), - origin: slice.filename.as_deref(), - annotations: vec![], - fold: false, - }) + let mut snippet = Snippet::source(source) + .line_start(slice.line.unwrap_or_default()); + if let Some(origin) = &slice.filename { + snippet = snippet.origin(origin); + } + slices.push(snippet); } } - let snippet = Snippet { - title, - footer, - slices, - }; let renderer = Renderer::styled(); - let dl = renderer.render(snippet); + let dl = renderer.render(snippet.snippets(slices).footers(footer)); if INVOKED_BY_BUILD_SCRIPT.with(Clone::clone) { // This is just a hack which hides the `warning:` added by cargo at the beginning of diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index a1536935b6..75f6a1ec8f 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -3144,7 +3144,7 @@ fn unused_regex_diagnostic(item: &str, name: &str, _ctx: &BindgenContext) { Diagnostic::default() .with_title( format!("Unused regular expression: `{}`.", item), - Level::Warn, + Level::Warning, ) .add_annotation( format!("This regular expression was passed to `{}`.", name), diff --git a/bindgen/ir/var.rs b/bindgen/ir/var.rs index b8fffc7d66..01c57704d3 100644 --- a/bindgen/ir/var.rs +++ b/bindgen/ir/var.rs @@ -519,7 +519,7 @@ fn duplicated_macro_diagnostic( slice.with_source(source); Diagnostic::default() - .with_title("Duplicated macro definition.", Level::Warn) + .with_title("Duplicated macro definition.", Level::Warning) .add_slice(slice) .add_annotation("This macro had a duplicate.", Level::Note) .display(); diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 3bf0bc3c1d..3da4e61f1e 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -596,7 +596,7 @@ fn deprecated_target_diagnostic(target: RustTarget, _options: &BindgenOptions) { let mut diagnostic = Diagnostic::default(); diagnostic.with_title( format!("The {} Rust target is deprecated.", target), - Level::Warn, + Level::Warning, ); diagnostic.add_annotation( "This Rust target was passed to `--rust-target`", @@ -1057,7 +1057,7 @@ fn rustfmt_non_fatal_error_diagnostic(msg: &str, _options: &BindgenOptions) { use crate::diagnostics::{Diagnostic, Level}; Diagnostic::default() - .with_title(msg, Level::Warn) + .with_title(msg, Level::Warning) .add_annotation( "The bindings will be generated but not formatted.", Level::Note, diff --git a/bindgen/regex_set.rs b/bindgen/regex_set.rs index b78424aae1..7f40af3c79 100644 --- a/bindgen/regex_set.rs +++ b/bindgen/regex_set.rs @@ -180,15 +180,15 @@ fn invalid_regex_warning( diagnostic.with_title( "Error while parsing a regular expression.", - Level::Warn, + Level::Warning, ); } else { - diagnostic.with_title(string, Level::Warn); + diagnostic.with_title(string, Level::Warning); } } err => { let err = err.to_string(); - diagnostic.with_title(err, Level::Warn); + diagnostic.with_title(err, Level::Warning); } } From 9a8e5ca2f4089e21300fbea6b73e82efd7f18882 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Mon, 8 Jul 2024 16:47:07 +0200 Subject: [PATCH 729/942] Add support for custom attributes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- CHANGELOG.md | 1 + Cargo.lock | 2 + bindgen-cli/Cargo.toml | 1 + bindgen-cli/options.rs | 131 ++++++++++++++++++ bindgen-integration/build.rs | 12 ++ bindgen-integration/src/lib.rs | 9 ++ bindgen-tests/Cargo.toml | 1 + .../tests/attribute-custom-cli.rs | 48 +++++++ .../expectations/tests/attribute-custom.rs | 22 +++ .../tests/headers/attribute-custom-cli.h | 14 ++ .../tests/headers/attribute-custom.h | 28 ++++ bindgen/callbacks.rs | 19 +++ bindgen/codegen/mod.rs | 53 ++++++- bindgen/ir/annotations.rs | 8 ++ 14 files changed, 348 insertions(+), 1 deletion(-) create mode 100644 bindgen-tests/tests/expectations/tests/attribute-custom-cli.rs create mode 100644 bindgen-tests/tests/expectations/tests/attribute-custom.rs create mode 100644 bindgen-tests/tests/headers/attribute-custom-cli.h create mode 100644 bindgen-tests/tests/headers/attribute-custom.h diff --git a/CHANGELOG.md b/CHANGELOG.md index 76e18d5c1b..308ed7675e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -235,6 +235,7 @@ - Add option to use DST structs for flexible arrays (--flexarray-dst, #2772). - Add option to dynamically load variables (#2812). - Add option in CLI to use rustified non-exhaustive enums (--rustified-non-exhaustive-enum, #2847). +- Add support for custom attributes (--with-attribute-custom, #2866) ## Changed - Remove which and lazy-static dependencies (#2809, #2817). - Generate compile-time layout tests (#2787). diff --git a/Cargo.lock b/Cargo.lock index 9ba69946ec..4786857205 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -55,6 +55,7 @@ dependencies = [ "clap_complete", "env_logger 0.10.0", "log", + "proc-macro2", "shlex", ] @@ -75,6 +76,7 @@ dependencies = [ "clap_complete", "owo-colors", "prettyplease", + "proc-macro2", "shlex", "similar", "syn 2.0.18", diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index 6fc02f3a55..d75867b76b 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -25,6 +25,7 @@ clap = { version = "4", features = ["derive"] } clap_complete = "4" env_logger = { version = "0.10.0", optional = true } log = { version = "0.4", optional = true } +proc-macro2 = { version = "1", default-features = false } shlex = "1" [features] diff --git a/bindgen-cli/options.rs b/bindgen-cli/options.rs index cd5e9bb127..5311d87aa7 100644 --- a/bindgen-cli/options.rs +++ b/bindgen-cli/options.rs @@ -6,10 +6,12 @@ use bindgen::{ }; use clap::error::{Error, ErrorKind}; use clap::{CommandFactory, Parser}; +use proc_macro2::TokenStream; use std::fs::File; use std::io; use std::path::{Path, PathBuf}; use std::process::exit; +use std::str::FromStr; fn rust_target_help() -> String { format!( @@ -87,6 +89,43 @@ fn parse_custom_derive( Ok((derives, regex.to_owned())) } +fn parse_custom_attribute( + custom_attribute: &str, +) -> Result<(Vec, String), Error> { + let mut brace_level = 0; + let (regex, attributes) = custom_attribute + .rsplit_once(|c| { + match c { + ']' => brace_level += 1, + '[' => brace_level -= 1, + _ => {} + } + c == '=' && brace_level == 0 + }) + .ok_or_else(|| Error::raw(ErrorKind::InvalidValue, "Missing `=`"))?; + + let mut brace_level = 0; + let attributes = attributes + .split(|c| { + match c { + ']' => brace_level += 1, + '[' => brace_level -= 1, + _ => {} + } + c == ',' && brace_level == 0 + }) + .map(|s| s.to_owned()) + .collect::>(); + + for attribute in &attributes { + if let Err(err) = TokenStream::from_str(attribute) { + return Err(Error::raw(ErrorKind::InvalidValue, err)); + } + } + + Ok((attributes, regex.to_owned())) +} + #[derive(Parser, Debug)] #[clap( about = "Generates Rust bindings from C/C++ headers.", @@ -424,6 +463,18 @@ struct BindgenCommand { /// Derive custom traits on a `union`. The CUSTOM value must be of the shape REGEX=DERIVE where DERIVE is a coma-separated list of derive macros. #[arg(long, value_name = "CUSTOM", value_parser = parse_custom_derive)] with_derive_custom_union: Vec<(Vec, String)>, + /// Add custom attributes on any kind of type. The CUSTOM value must be of the shape REGEX=ATTRIBUTE where ATTRIBUTE is a coma-separated list of attributes. + #[arg(long, value_name = "CUSTOM", value_parser = parse_custom_attribute)] + with_attribute_custom: Vec<(Vec, String)>, + /// Add custom attributes on a `struct`. The CUSTOM value must be of the shape REGEX=ATTRIBUTE where ATTRIBUTE is a coma-separated list of attributes. + #[arg(long, value_name = "CUSTOM", value_parser = parse_custom_attribute)] + with_attribute_custom_struct: Vec<(Vec, String)>, + /// Add custom attributes on an `enum. The CUSTOM value must be of the shape REGEX=ATTRIBUTE where ATTRIBUTE is a coma-separated list of attributes. + #[arg(long, value_name = "CUSTOM", value_parser = parse_custom_attribute)] + with_attribute_custom_enum: Vec<(Vec, String)>, + /// Add custom attributes on a `union`. The CUSTOM value must be of the shape REGEX=ATTRIBUTE where ATTRIBUTE is a coma-separated list of attributes. + #[arg(long, value_name = "CUSTOM", value_parser = parse_custom_attribute)] + with_attribute_custom_union: Vec<(Vec, String)>, /// Generate wrappers for `static` and `static inline` functions. #[arg(long, requires = "experimental")] wrap_static_fns: bool, @@ -574,6 +625,10 @@ where with_derive_custom_struct, with_derive_custom_enum, with_derive_custom_union, + with_attribute_custom, + with_attribute_custom_struct, + with_attribute_custom_enum, + with_attribute_custom_union, wrap_static_fns, wrap_static_fns_path, wrap_static_fns_suffix, @@ -1130,6 +1185,82 @@ where } } + #[derive(Debug)] + struct CustomAttributeCallback { + attributes: Vec, + kind: Option, + regex_set: bindgen::RegexSet, + } + + impl bindgen::callbacks::ParseCallbacks for CustomAttributeCallback { + fn cli_args(&self) -> Vec { + let mut args = vec![]; + + let flag = match &self.kind { + None => "--with-attribute-custom", + Some(TypeKind::Struct) => "--with-attribute-custom-struct", + Some(TypeKind::Enum) => "--with-attribute-custom-enum", + Some(TypeKind::Union) => "--with-attribute-custom-union", + }; + + let attributes = self.attributes.join(","); + + for item in self.regex_set.get_items() { + args.extend_from_slice(&[ + flag.to_owned(), + format!("{}={}", item, attributes), + ]); + } + + args + } + + fn add_attributes( + &self, + info: &bindgen::callbacks::AttributeInfo<'_>, + ) -> Vec { + if self.kind.map(|kind| kind == info.kind).unwrap_or(true) && + self.regex_set.matches(info.name) + { + return self.attributes.clone(); + } + vec![] + } + } + + for (custom_attributes, kind, name) in [ + (with_attribute_custom, None, "--with-attribute-custom"), + ( + with_attribute_custom_struct, + Some(TypeKind::Struct), + "--with-attribute-custom-struct", + ), + ( + with_attribute_custom_enum, + Some(TypeKind::Enum), + "--with-attribute-custom-enum", + ), + ( + with_attribute_custom_union, + Some(TypeKind::Union), + "--with-attribute-custom-union", + ), + ] { + let name = emit_diagnostics.then_some(name); + for (attributes, regex) in custom_attributes { + let mut regex_set = RegexSet::new(); + regex_set.insert(regex); + regex_set.build_with_diagnostics(false, name); + + builder = + builder.parse_callbacks(Box::new(CustomAttributeCallback { + attributes, + kind, + regex_set, + })); + } + } + if wrap_static_fns { builder = builder.wrap_static_fns(true); } diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs index 6b06c91bc3..88ba945366 100644 --- a/bindgen-integration/build.rs +++ b/bindgen-integration/build.rs @@ -133,6 +133,18 @@ impl ParseCallbacks for MacroCallback { vec![] } } + + // Test the "custom attributes" capability. + fn add_attributes( + &self, + info: &bindgen::callbacks::AttributeInfo<'_>, + ) -> Vec { + if info.name == "Test" { + vec!["#[cfg_attr(test, derive(PartialOrd))]".into()] + } else { + vec![] + } + } } impl Drop for MacroCallback { diff --git a/bindgen-integration/src/lib.rs b/bindgen-integration/src/lib.rs index c37055ee7d..48cfe092d2 100755 --- a/bindgen-integration/src/lib.rs +++ b/bindgen-integration/src/lib.rs @@ -297,6 +297,15 @@ fn test_custom_derive() { assert!(!(test1 > test2)); } +#[test] +fn test_custom_attributes() { + // The `add_attributes` callback should have added `#[cfg_attr(test, derive(PartialOrd))])` + // to the `Test` struct. If it didn't, this will fail to compile. + let test1 = unsafe { bindings::Test::new(5) }; + let test2 = unsafe { bindings::Test::new(6) }; + assert!(test1 < test2); +} + #[test] fn test_wrap_static_fns() { // GH-1090: https://github.com/rust-lang/rust-bindgen/issues/1090 diff --git a/bindgen-tests/Cargo.toml b/bindgen-tests/Cargo.toml index a253b349b9..47fc0b8ca0 100644 --- a/bindgen-tests/Cargo.toml +++ b/bindgen-tests/Cargo.toml @@ -10,6 +10,7 @@ clap = { version = "4", features = ["derive"] } clap_complete = "4" shlex = "1" prettyplease = { version = "0.2.7", features = ["verbatim"] } +proc-macro2 = { version = "1", default-features = false } syn = { version = "2.0" } tempfile = "3" similar = { version = "2.2.1", features = ["inline"] } diff --git a/bindgen-tests/tests/expectations/tests/attribute-custom-cli.rs b/bindgen-tests/tests/expectations/tests/attribute-custom-cli.rs new file mode 100644 index 0000000000..55353116d3 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/attribute-custom-cli.rs @@ -0,0 +1,48 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[repr(C)] +#[doc(hidden)] +#[derive(Default)] +pub struct foo_struct { + pub inner: ::std::os::raw::c_int, +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo_struct"][::std::mem::size_of::() - 4usize]; + ["Alignment of foo_struct"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: foo_struct::inner", + ][::std::mem::offset_of!(foo_struct, inner) - 0usize]; +}; +#[repr(u32)] +#[cfg_attr(test, derive(PartialOrd, Copy))] +#[derive(Clone, Hash, PartialEq, Eq)] +pub enum foo_enum { + inner = 0, +} +#[repr(C)] +#[doc(hidden)] +#[derive(Clone)] +#[derive(Copy)] +pub union foo_union { + pub fst: ::std::mem::ManuallyDrop<::std::os::raw::c_int>, + pub snd: ::std::mem::ManuallyDrop, +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of foo_union"][::std::mem::size_of::() - 4usize]; + ["Alignment of foo_union"][::std::mem::align_of::() - 4usize]; + ["Offset of field: foo_union::fst"][::std::mem::offset_of!(foo_union, fst) - 0usize]; + ["Offset of field: foo_union::snd"][::std::mem::offset_of!(foo_union, snd) - 0usize]; +}; +#[repr(C)] +pub struct non_matching { + pub inner: ::std::os::raw::c_int, +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of non_matching"][::std::mem::size_of::() - 4usize]; + ["Alignment of non_matching"][::std::mem::align_of::() - 4usize]; + [ + "Offset of field: non_matching::inner", + ][::std::mem::offset_of!(non_matching, inner) - 0usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/attribute-custom.rs b/bindgen-tests/tests/expectations/tests/attribute-custom.rs new file mode 100644 index 0000000000..6d616d3f3e --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/attribute-custom.rs @@ -0,0 +1,22 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +///
+#[repr(C)] +#[derive(Debug)] +pub struct my_type { + pub a: ::std::os::raw::c_int, +} +/**
+
*/ +#[repr(C)] +#[derive(Debug)] +#[derive(Clone)] +pub struct my_type2 { + pub a: ::std::os::raw::c_uint, +} +///
+#[repr(C)] +#[derive(Debug)] +#[derive(Clone)] +pub struct my_type3 { + pub a: ::std::os::raw::c_ulong, +} diff --git a/bindgen-tests/tests/headers/attribute-custom-cli.h b/bindgen-tests/tests/headers/attribute-custom-cli.h new file mode 100644 index 0000000000..a5f73c78e5 --- /dev/null +++ b/bindgen-tests/tests/headers/attribute-custom-cli.h @@ -0,0 +1,14 @@ +// bindgen-flags: --default-enum-style rust --default-non-copy-union-style manually_drop --no-default=".*" --no-hash=".*" --no-partialeq=".*" --no-debug=".*" --no-copy=".*" --with-attribute-custom="foo_[^e].*=#[doc(hidden)]" --with-attribute-custom-struct="foo.*=#[derive(Default)]" --with-attribute-custom-enum="foo.*=#[cfg_attr(test, derive(PartialOrd, Copy))]" --with-attribute-custom-union="foo.*=#[derive(Clone)],#[derive(Copy)]" +struct foo_struct { + int inner; +}; +enum foo_enum { + inner = 0 +}; +union foo_union { + int fst; + float snd; +}; +struct non_matching { + int inner; +}; diff --git a/bindgen-tests/tests/headers/attribute-custom.h b/bindgen-tests/tests/headers/attribute-custom.h new file mode 100644 index 0000000000..dd382bf8cd --- /dev/null +++ b/bindgen-tests/tests/headers/attribute-custom.h @@ -0,0 +1,28 @@ +// bindgen-flags: --no-derive-debug --no-derive-copy --no-derive-default --default-enum-style rust --no-layout-tests + +/**
*/ +struct my_type; + +/**
*/ +struct my_type; + +struct my_type { + int a; +}; + +/** + *
+ *
+ */ +struct my_type2; + +struct my_type2 { + unsigned a; +}; + +/** + *
+ */ +struct my_type3 { + unsigned long a; +}; diff --git a/bindgen/callbacks.rs b/bindgen/callbacks.rs index 0f16c4c0bf..43dc37d595 100644 --- a/bindgen/callbacks.rs +++ b/bindgen/callbacks.rs @@ -129,6 +129,14 @@ pub trait ParseCallbacks: fmt::Debug { vec![] } + /// Provide a list of custom attributes. + /// + /// If no additional attributes are wanted, this function should return an + /// empty `Vec`. + fn add_attributes(&self, _info: &AttributeInfo<'_>) -> Vec { + vec![] + } + /// Process a source code comment. fn process_comment(&self, _comment: &str) -> Option { None @@ -167,6 +175,17 @@ pub struct DeriveInfo<'a> { pub kind: TypeKind, } +/// Relevant information about a type to which new attributes will be added using +/// [`ParseCallbacks::add_attributes`]. +#[derive(Debug)] +#[non_exhaustive] +pub struct AttributeInfo<'a> { + /// The name of the type. + pub name: &'a str, + /// The kind of the type. + pub kind: TypeKind, +} + #[derive(Debug, Clone, Copy, PartialEq, Eq)] /// The kind of the current type. pub enum TypeKind { diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 1cccac6761..b92f5e127a 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -20,7 +20,9 @@ use self::struct_layout::StructLayoutTracker; use super::BindgenOptions; -use crate::callbacks::{DeriveInfo, FieldInfo, TypeKind as DeriveTypeKind}; +use crate::callbacks::{ + AttributeInfo, DeriveInfo, FieldInfo, TypeKind as DeriveTypeKind, +}; use crate::codegen::error::Error; use crate::ir::analysis::{HasVtable, Sizedness}; use crate::ir::annotations::{ @@ -1047,6 +1049,19 @@ impl CodeGenerator for Type { .extend(custom_derives.iter().map(|s| s.as_str())); attributes.push(attributes::derives(&derives)); + let custom_attributes = + ctx.options().all_callbacks(|cb| { + cb.add_attributes(&AttributeInfo { + name: &name, + kind: DeriveTypeKind::Struct, + }) + }); + attributes.extend( + custom_attributes + .iter() + .map(|s| s.parse().unwrap()), + ); + quote! { #( #attributes )* pub struct #rust_name @@ -2378,6 +2393,25 @@ impl CodeGenerator for CompInfo { attributes.push(attributes::derives(&derives)) } + attributes.extend( + item.annotations() + .attributes() + .iter() + .map(|s| s.parse().unwrap()), + ); + + let custom_attributes = ctx.options().all_callbacks(|cb| { + cb.add_attributes(&AttributeInfo { + name: &canonical_name, + kind: if is_rust_union { + DeriveTypeKind::Union + } else { + DeriveTypeKind::Struct + }, + }) + }); + attributes.extend(custom_attributes.iter().map(|s| s.parse().unwrap())); + if item.must_use(ctx) { attributes.push(attributes::must_use()); } @@ -3570,6 +3604,23 @@ impl CodeGenerator for Enum { // In most cases this will be a no-op, since custom_derives will be empty. derives.extend(custom_derives.iter().map(|s| s.as_str())); + attrs.extend( + item.annotations() + .attributes() + .iter() + .map(|s| s.parse().unwrap()), + ); + + // The custom attribute callback may return a list of attributes; + // add them to the end of the list. + let custom_attributes = ctx.options().all_callbacks(|cb| { + cb.add_attributes(&AttributeInfo { + name: &name, + kind: DeriveTypeKind::Enum, + }) + }); + attrs.extend(custom_attributes.iter().map(|s| s.parse().unwrap())); + attrs.push(attributes::derives(&derives)); } diff --git a/bindgen/ir/annotations.rs b/bindgen/ir/annotations.rs index fc9cc0ffe7..12295288c1 100644 --- a/bindgen/ir/annotations.rs +++ b/bindgen/ir/annotations.rs @@ -102,6 +102,8 @@ pub(crate) struct Annotations { constify_enum_variant: bool, /// List of explicit derives for this type. derives: Vec, + /// List of explicit attributes for this type. + attributes: Vec, } fn parse_accessor(s: &str) -> FieldAccessorKind { @@ -169,6 +171,11 @@ impl Annotations { &self.derives } + /// The list of attributes that have been specified in this annotation. + pub(crate) fn attributes(&self) -> &[String] { + &self.attributes + } + /// Should we avoid implementing the `Copy` trait? pub(crate) fn disallow_copy(&self) -> bool { self.disallow_copy @@ -223,6 +230,7 @@ impl Annotations { ) } "derive" => self.derives.push(attr.value), + "attribute" => self.attributes.push(attr.value), "private" => { self.visibility_kind = if attr.value != "false" { Some(FieldVisibilityKind::Private) From 7873db7627d1a2f3587856433aac2f144b20fe20 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Wed, 4 Sep 2024 12:00:52 -0500 Subject: [PATCH 730/942] Use `\r\n\r\n` on Windows --- bindgen/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 3da4e61f1e..572e1d4598 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -927,9 +927,9 @@ impl Bindings { if !self.options.disable_header_comment { let version = option_env!("CARGO_PKG_VERSION").unwrap_or("(unknown version)"); - writeln!( + write!( writer, - "/* automatically generated by rust-bindgen {version} */{NL}", + "/* automatically generated by rust-bindgen {version} */{NL}{NL}", )?; } From fd37d68572b765b0aa6daa21ceb55f7a659a13eb Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Wed, 4 Sep 2024 12:01:45 -0500 Subject: [PATCH 731/942] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 308ed7675e..69e763990e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -218,6 +218,7 @@ ## Changed ## Removed ## Fixed +- Use the right characters for newlines on windows. ## Security # 0.70.1 (2024-08-20) From b50d72485d4b00babf195c2156ccf8d0f6dd202d Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Sat, 7 Sep 2024 14:02:12 +0200 Subject: [PATCH 732/942] Stabilize `--wrap-static-fns` --- bindgen-cli/options.rs | 6 +++--- bindgen-tests/tests/headers/wrap-static-fns.h | 2 +- bindgen/options/mod.rs | 9 ++------- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/bindgen-cli/options.rs b/bindgen-cli/options.rs index 5311d87aa7..ad96664bd2 100644 --- a/bindgen-cli/options.rs +++ b/bindgen-cli/options.rs @@ -476,15 +476,15 @@ struct BindgenCommand { #[arg(long, value_name = "CUSTOM", value_parser = parse_custom_attribute)] with_attribute_custom_union: Vec<(Vec, String)>, /// Generate wrappers for `static` and `static inline` functions. - #[arg(long, requires = "experimental")] + #[arg(long)] wrap_static_fns: bool, /// Sets the PATH for the source file that must be created due to the presence of `static` and /// `static inline` functions. - #[arg(long, requires = "experimental", value_name = "PATH")] + #[arg(long, value_name = "PATH")] wrap_static_fns_path: Option, /// Sets the SUFFIX added to the extern wrapper functions generated for `static` and `static /// inline` functions. - #[arg(long, requires = "experimental", value_name = "SUFFIX")] + #[arg(long, value_name = "SUFFIX")] wrap_static_fns_suffix: Option, /// Set the default VISIBILITY of fields, including bitfields and accessor methods for /// bitfields. This flag is ignored if the `--respect-cxx-access-specs` flag is used. diff --git a/bindgen-tests/tests/headers/wrap-static-fns.h b/bindgen-tests/tests/headers/wrap-static-fns.h index 2be7bd93d9..5cd3d41aee 100644 --- a/bindgen-tests/tests/headers/wrap-static-fns.h +++ b/bindgen-tests/tests/headers/wrap-static-fns.h @@ -1,4 +1,4 @@ -// bindgen-flags: --experimental --wrap-static-fns +// bindgen-flags: --wrap-static-fns // bindgen-parse-callbacks: wrap-as-variadic-fn // to avoid polluting the expectation tests we put the stdarg.h behind a conditional diff --git a/bindgen/options/mod.rs b/bindgen/options/mod.rs index e4c03ecd4d..e9f4fb811c 100644 --- a/bindgen/options/mod.rs +++ b/bindgen/options/mod.rs @@ -1419,10 +1419,8 @@ options! { /// Note that they will usually not work. However you can use `-fkeep-inline-functions` /// or `-fno-inline-functions` if you are responsible of compiling the library to make /// them callable. - #[cfg_attr( - feature = "experimental", - doc = "\nCheck the [`Builder::wrap_static_fns`] method for an alternative." - )] + /// + /// Check the [`Builder::wrap_static_fns`] method for an alternative. pub fn generate_inline_functions(mut self, doit: bool) -> Self { self.options.generate_inline_functions = doit; self @@ -2021,7 +2019,6 @@ options! { /// Whether to generate wrappers for `static` functions. wrap_static_fns: bool { methods: { - #[cfg(feature = "experimental")] /// Set whether to generate wrappers for `static`` functions. /// /// Passing `true` to this method will generate a C source file with non-`static` @@ -2040,7 +2037,6 @@ options! { /// The suffix to be added to the function wrappers for `static` functions. wrap_static_fns_suffix: Option { methods: { - #[cfg(feature = "experimental")] /// Set the suffix added to the wrappers for `static` functions. /// /// This option only comes into effect if `true` is passed to the @@ -2057,7 +2053,6 @@ options! { /// The path of the file where the wrappers for `static` functions will be emitted. wrap_static_fns_path: Option { methods: { - #[cfg(feature = "experimental")] /// Set the path for the source code file that would be created if any wrapper /// functions must be generated due to the presence of `static` functions. /// From f518815cc14a7f8c292964bb37179a1070d7e18a Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Sat, 7 Sep 2024 14:02:54 +0200 Subject: [PATCH 733/942] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 69e763990e..cfecc5cee6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -216,6 +216,7 @@ # Unreleased ## Added ## Changed +- The `--wrap-static-fns` related options no longer require the experimental feature or flag. ## Removed ## Fixed - Use the right characters for newlines on windows. From d39fc1b22a64038ea77dd379afb0b3321d1b0597 Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Mon, 17 Jun 2024 19:12:17 +0200 Subject: [PATCH 734/942] ci: Add Rust for Linux Rust for Linux, so far, has pinned the Rust compiler and `bindgen` versions. The kernel is looking into expanding that support to several versions, i.e. establishing a minimum supported version, so that the kernel can start to be more easily built. In particular, it should be possible to build the kernel using the tools provided directly by Linux distributions. In order to help achieve that goal, the Rust project has added the kernel to its Rust pre-merge CI. This commit does the same for `bindgen`. In particular, it adds a quick, build-only test of the Rust code in the kernel as an extra step in the `test` workflow. This is intended to be an end-to-end test that runs what kernel developers/users would do. In particular, it is useful to catch certain issues that go beyond the C header comparisons. For instance, it would have been able to catch an issue like the `--version` option unexpectedly requiring a header in 0.69.0 (fixed in 0.69.1) [1]. It would also have detected another issue present in 0.66.0 and 0.66.1: a panic handling certain C headers with string literals containing an interior NUL [2]. While the kernel is not really a stable test, and such an issue would still require that a proper test is added, it is nevertheless a good test case of non-trivial C headers that may trigger edge cases like that. Of course, `bindgen` may need to disable the test for different reasons, i.e. there is no expectation to block any urgent/important PR, and the kernel can also call `bindgen` differently depending on the version, i.e. we are happy to adjust on our side too. Even if it gets disabled often, we would still be in a better situation than not having the test at all. The Linux version (hash or tag) should ideally be updated from time to time (e.g. every kernel `-rc1`), and each update should only contain that change. Link: https://github.com/rust-lang/rust-bindgen/pull/2678 [1] Link: https://github.com/rust-lang/rust-bindgen/pull/2567 [2] Signed-off-by: Miguel Ojeda --- .github/workflows/bindgen.yml | 1 + ci/test.sh | 76 +++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 7e9c254e83..b54d6fdc3a 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -209,6 +209,7 @@ jobs: BINDGEN_FEATURE_RUNTIME: ${{matrix.feature_runtime}} BINDGEN_FEATURE_EXTRA_ASSERTS: ${{matrix.feature_extra_asserts}} BINDGEN_NO_DEFAULT_FEATURES: ${{matrix.no_default_features}} + BINDGEN_RUST_FOR_LINUX_TEST: ${{matrix.os == 'ubuntu-latest' && matrix.llvm_version == '16.0' && matrix.feature_extra_asserts == 0 && 1 || 0}} run: ./ci/test.sh check-cfg: diff --git a/ci/test.sh b/ci/test.sh index 11e091f49f..bec7cfbb0c 100755 --- a/ci/test.sh +++ b/ci/test.sh @@ -118,3 +118,79 @@ assert_no_diff # Run the integration tests (cd bindgen-integration && cargo test $CARGO_ARGS) + +if [ "$BINDGEN_RUST_FOR_LINUX_TEST" == "1" ]; then + # Run the Rust for Linux test + # + # This is intended to be an end-to-end test that runs what Linux kernel + # developers/users would do. It is a quick, build-only test of the Rust code + # in the Linux kernel. + + # Put LLVM binaries in the path for `LLVM=1`. The LLVM `bin` directory should + # go first since there are others in the Ubuntu image. + export PATH="${LLVM_DIRECTORY}/bin:${PATH}" + + # Kernel build dependency: `bindgen-cli`, which is under test. + # + # Using `cargo build` (and adding the two common profiles to the `$PATH`) so + # that we can use `$CARGO_ARGS` as is, since `cargo install` does not support + # `--release`. `--target-dir` is used to isolate from other possible tests. + # A cleaner alternative is using `--out-dir`, but it is unstable. + (cd bindgen-cli && cargo build --target-dir ${HOME}/.bindgen $CARGO_ARGS) + export PATH="${HOME}/.bindgen/release:${HOME}/.bindgen/debug:${PATH}" + + # Kernel build dependency: `libelf-dev`. + sudo apt-get update + sudo apt-get install libelf-dev + + # Kernel build dependency: the Rust standard library sources. + # + # `rustup` is used here to install the `rust-src` component (instead of using + # `actions-rs/toolchain`'s `components` option in the workflow step) since we + # only need it for this test, and anyway the action installs `rustup`. + rustup component add rust-src + + # Ideally this should be updated from time to time (e.g. every kernel `-rc1`), + # and each update should only contain this change. + # + # Both commit hashes and tags are supported. + LINUX_VERSION=c13320499ba0efd93174ef6462ae8a7a2933f6e7 + + # Download Linux at a specific commit + mkdir -p linux + git -C linux init + git -C linux remote add origin https://github.com/torvalds/linux.git + git -C linux fetch --depth 1 origin ${LINUX_VERSION} + git -C linux checkout FETCH_HEAD + + # Configure Rust for Linux + cat < linux/kernel/configs/rfl-for-bindgen-ci.config +# CONFIG_WERROR is not set + +CONFIG_RUST=y + +CONFIG_SAMPLES=y +CONFIG_SAMPLES_RUST=y + +CONFIG_SAMPLE_RUST_MINIMAL=m +CONFIG_SAMPLE_RUST_PRINT=y + +CONFIG_RUST_PHYLIB_ABSTRACTIONS=y +CONFIG_AX88796B_PHY=y +CONFIG_AX88796B_RUST_PHY=y + +CONFIG_KUNIT=y +CONFIG_RUST_KERNEL_DOCTESTS=y +EOF + + make -C linux LLVM=1 -j$(($(nproc) + 1)) \ + rustavailable \ + defconfig \ + rfl-for-bindgen-ci.config + + # Build Rust for Linux + make -C linux LLVM=1 -j$(($(nproc) + 1)) \ + samples/rust/rust_minimal.o \ + samples/rust/rust_print.o \ + drivers/net/phy/ax88796b_rust.o +fi From 3c09db0b5646b3d229d5c5f5e13cf2b2373ae2d9 Mon Sep 17 00:00:00 2001 From: John Baublitz Date: Tue, 30 Jul 2024 15:28:08 -0400 Subject: [PATCH 735/942] Add additional helpers to bitfield data structure This commit addresses the case where a struct containing a bitfield is wrapped in a struct such as UnsafeCell which allows interior mutability. Previously, bitfield accessors only allowed a receiver. This becomes problematic in the case of interior mutability as raw pointer access may be required so as not to violate the aliasing rules in Rust. --- .../tests/bitfield-32bit-overflow.rs | 895 ++++++++++++- .../expectations/tests/bitfield-large.rs | 155 ++- .../expectations/tests/bitfield-linux-32.rs | 130 +- .../tests/bitfield-method-same-name.rs | 109 +- .../expectations/tests/bitfield_align.rs | 755 ++++++++++- .../expectations/tests/bitfield_align_2.rs | 130 +- .../tests/bitfield_method_mangling.rs | 130 +- .../tests/bitfield_pragma_packed.rs | 252 +++- .../tests/blocklist_bitfield_unit.rs | 50 + .../tests/default_visibility_crate.rs | 152 ++- .../tests/default_visibility_private.rs | 152 ++- ...bility_private_respects_cxx_access_spec.rs | 152 ++- .../tests/derive-bitfield-method-same-name.rs | 109 +- .../tests/derive-debug-bitfield-core.rs | 130 +- .../tests/derive-debug-bitfield.rs | 128 +- .../tests/derive-partialeq-bitfield.rs | 128 +- .../tests/divide-by-zero-in-struct-layout.rs | 80 +- .../tests/field-visibility-callback.rs | 130 +- .../expectations/tests/field-visibility.rs | 130 +- .../tests/incomplete-array-padding.rs | 104 +- .../tests/expectations/tests/issue-1034.rs | 80 +- .../issue-1076-unnamed-bitfield-alignment.rs | 80 +- .../tests/expectations/tests/issue-1947.rs | 330 ++++- .../tests/issue-739-pointer-wide-bitfield.rs | 180 ++- .../tests/expectations/tests/issue-816.rs | 1105 ++++++++++++++++- .../expectations/tests/jsval_layout_opaque.rs | 130 +- .../tests/jsval_layout_opaque_1_0.rs | 130 +- .../tests/expectations/tests/layout_align.rs | 155 ++- .../expectations/tests/layout_eth_conf.rs | 377 +++++- .../expectations/tests/layout_eth_conf_1_0.rs | 377 +++++- .../tests/expectations/tests/layout_mbuf.rs | 405 +++++- .../expectations/tests/layout_mbuf_1_0.rs | 405 +++++- .../expectations/tests/only_bitfields.rs | 128 +- .../expectations/tests/packed-bitfield.rs | 153 ++- .../expectations/tests/private_fields.rs | 305 ++++- .../tests/redundant-packed-and-align.rs | 128 +- .../tests/struct_with_bitfields.rs | 230 +++- .../tests/expectations/tests/timex.rs | 355 +++++- .../expectations/tests/union_bitfield.rs | 155 ++- .../expectations/tests/union_bitfield_1_0.rs | 164 ++- .../tests/union_with_anon_struct_bitfield.rs | 130 +- .../union_with_anon_struct_bitfield_1_0.rs | 130 +- .../expectations/tests/weird_bitfields.rs | 260 +++- bindgen/codegen/bitfield_unit.rs | 107 +- bindgen/codegen/mod.rs | 84 +- 45 files changed, 9610 insertions(+), 474 deletions(-) diff --git a/bindgen-tests/tests/expectations/tests/bitfield-32bit-overflow.rs b/bindgen-tests/tests/expectations/tests/bitfield-32bit-overflow.rs index 475cbae837..7125be5607 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-32bit-overflow.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-32bit-overflow.rs @@ -15,10 +15,7 @@ where Storage: AsRef<[u8]> + AsMut<[u8]>, { #[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]; + fn extract_bit(byte: u8, index: usize) -> bool { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) } else { @@ -28,21 +25,44 @@ where byte & mask == mask } #[inline] - pub fn set_bit(&mut self, index: usize, val: bool) { + pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); let byte_index = index / 8; - let byte = &mut self.storage.as_mut()[byte_index]; + 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 = *(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; - } + 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize); + *byte = Self::change_bit(*byte, index, val); } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -65,6 +85,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 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()); @@ -82,6 +122,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 + }; + Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + } + } } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -107,6 +165,30 @@ impl MuchBitfield { } } #[inline] + pub unsafe fn m0_raw(this: *const Self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 1u8) as u8, + ) + } + } + #[inline] + pub unsafe fn set_m0_raw(this: *mut Self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 0usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn m1(&self) -> ::std::os::raw::c_char { unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u8) } } @@ -118,6 +200,30 @@ impl MuchBitfield { } } #[inline] + pub unsafe fn m1_raw(this: *const Self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 1usize, 1u8) as u8, + ) + } + } + #[inline] + pub unsafe fn set_m1_raw(this: *mut Self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 1usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn m2(&self) -> ::std::os::raw::c_char { unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u8) } } @@ -129,6 +235,30 @@ impl MuchBitfield { } } #[inline] + pub unsafe fn m2_raw(this: *const Self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 2usize, 1u8) as u8, + ) + } + } + #[inline] + pub unsafe fn set_m2_raw(this: *mut Self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 2usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn m3(&self) -> ::std::os::raw::c_char { unsafe { ::std::mem::transmute(self._bitfield_1.get(3usize, 1u8) as u8) } } @@ -140,6 +270,30 @@ impl MuchBitfield { } } #[inline] + pub unsafe fn m3_raw(this: *const Self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 3usize, 1u8) as u8, + ) + } + } + #[inline] + pub unsafe fn set_m3_raw(this: *mut Self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 3usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn m4(&self) -> ::std::os::raw::c_char { unsafe { ::std::mem::transmute(self._bitfield_1.get(4usize, 1u8) as u8) } } @@ -151,6 +305,30 @@ impl MuchBitfield { } } #[inline] + pub unsafe fn m4_raw(this: *const Self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 4usize, 1u8) as u8, + ) + } + } + #[inline] + pub unsafe fn set_m4_raw(this: *mut Self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 4usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn m5(&self) -> ::std::os::raw::c_char { unsafe { ::std::mem::transmute(self._bitfield_1.get(5usize, 1u8) as u8) } } @@ -162,6 +340,30 @@ impl MuchBitfield { } } #[inline] + pub unsafe fn m5_raw(this: *const Self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 5usize, 1u8) as u8, + ) + } + } + #[inline] + pub unsafe fn set_m5_raw(this: *mut Self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 5usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn m6(&self) -> ::std::os::raw::c_char { unsafe { ::std::mem::transmute(self._bitfield_1.get(6usize, 1u8) as u8) } } @@ -173,6 +375,30 @@ impl MuchBitfield { } } #[inline] + pub unsafe fn m6_raw(this: *const Self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 6usize, 1u8) as u8, + ) + } + } + #[inline] + pub unsafe fn set_m6_raw(this: *mut Self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 6usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn m7(&self) -> ::std::os::raw::c_char { unsafe { ::std::mem::transmute(self._bitfield_1.get(7usize, 1u8) as u8) } } @@ -184,6 +410,30 @@ impl MuchBitfield { } } #[inline] + pub unsafe fn m7_raw(this: *const Self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 7usize, 1u8) as u8, + ) + } + } + #[inline] + pub unsafe fn set_m7_raw(this: *mut Self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 7usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn m8(&self) -> ::std::os::raw::c_char { unsafe { ::std::mem::transmute(self._bitfield_1.get(8usize, 1u8) as u8) } } @@ -195,6 +445,30 @@ impl MuchBitfield { } } #[inline] + pub unsafe fn m8_raw(this: *const Self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 8usize, 1u8) as u8, + ) + } + } + #[inline] + pub unsafe fn set_m8_raw(this: *mut Self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 8usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn m9(&self) -> ::std::os::raw::c_char { unsafe { ::std::mem::transmute(self._bitfield_1.get(9usize, 1u8) as u8) } } @@ -206,6 +480,30 @@ impl MuchBitfield { } } #[inline] + pub unsafe fn m9_raw(this: *const Self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 9usize, 1u8) as u8, + ) + } + } + #[inline] + pub unsafe fn set_m9_raw(this: *mut Self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 9usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn m10(&self) -> ::std::os::raw::c_char { unsafe { ::std::mem::transmute(self._bitfield_1.get(10usize, 1u8) as u8) } } @@ -217,6 +515,31 @@ impl MuchBitfield { } } #[inline] + pub unsafe fn m10_raw(this: *const Self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 10usize, 1u8) + as u8, + ) + } + } + #[inline] + pub unsafe fn set_m10_raw(this: *mut Self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 10usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn m11(&self) -> ::std::os::raw::c_char { unsafe { ::std::mem::transmute(self._bitfield_1.get(11usize, 1u8) as u8) } } @@ -228,6 +551,31 @@ impl MuchBitfield { } } #[inline] + pub unsafe fn m11_raw(this: *const Self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 11usize, 1u8) + as u8, + ) + } + } + #[inline] + pub unsafe fn set_m11_raw(this: *mut Self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 11usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn m12(&self) -> ::std::os::raw::c_char { unsafe { ::std::mem::transmute(self._bitfield_1.get(12usize, 1u8) as u8) } } @@ -239,6 +587,31 @@ impl MuchBitfield { } } #[inline] + pub unsafe fn m12_raw(this: *const Self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 12usize, 1u8) + as u8, + ) + } + } + #[inline] + pub unsafe fn set_m12_raw(this: *mut Self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 12usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn m13(&self) -> ::std::os::raw::c_char { unsafe { ::std::mem::transmute(self._bitfield_1.get(13usize, 1u8) as u8) } } @@ -250,6 +623,31 @@ impl MuchBitfield { } } #[inline] + pub unsafe fn m13_raw(this: *const Self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 13usize, 1u8) + as u8, + ) + } + } + #[inline] + pub unsafe fn set_m13_raw(this: *mut Self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 13usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn m14(&self) -> ::std::os::raw::c_char { unsafe { ::std::mem::transmute(self._bitfield_1.get(14usize, 1u8) as u8) } } @@ -261,6 +659,31 @@ impl MuchBitfield { } } #[inline] + pub unsafe fn m14_raw(this: *const Self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 14usize, 1u8) + as u8, + ) + } + } + #[inline] + pub unsafe fn set_m14_raw(this: *mut Self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 14usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn m15(&self) -> ::std::os::raw::c_char { unsafe { ::std::mem::transmute(self._bitfield_1.get(15usize, 1u8) as u8) } } @@ -272,6 +695,31 @@ impl MuchBitfield { } } #[inline] + pub unsafe fn m15_raw(this: *const Self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 15usize, 1u8) + as u8, + ) + } + } + #[inline] + pub unsafe fn set_m15_raw(this: *mut Self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 15usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn m16(&self) -> ::std::os::raw::c_char { unsafe { ::std::mem::transmute(self._bitfield_1.get(16usize, 1u8) as u8) } } @@ -283,6 +731,31 @@ impl MuchBitfield { } } #[inline] + pub unsafe fn m16_raw(this: *const Self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 16usize, 1u8) + as u8, + ) + } + } + #[inline] + pub unsafe fn set_m16_raw(this: *mut Self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 16usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn m17(&self) -> ::std::os::raw::c_char { unsafe { ::std::mem::transmute(self._bitfield_1.get(17usize, 1u8) as u8) } } @@ -294,6 +767,31 @@ impl MuchBitfield { } } #[inline] + pub unsafe fn m17_raw(this: *const Self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 17usize, 1u8) + as u8, + ) + } + } + #[inline] + pub unsafe fn set_m17_raw(this: *mut Self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 17usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn m18(&self) -> ::std::os::raw::c_char { unsafe { ::std::mem::transmute(self._bitfield_1.get(18usize, 1u8) as u8) } } @@ -305,6 +803,31 @@ impl MuchBitfield { } } #[inline] + pub unsafe fn m18_raw(this: *const Self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 18usize, 1u8) + as u8, + ) + } + } + #[inline] + pub unsafe fn set_m18_raw(this: *mut Self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 18usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn m19(&self) -> ::std::os::raw::c_char { unsafe { ::std::mem::transmute(self._bitfield_1.get(19usize, 1u8) as u8) } } @@ -316,6 +839,31 @@ impl MuchBitfield { } } #[inline] + pub unsafe fn m19_raw(this: *const Self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 19usize, 1u8) + as u8, + ) + } + } + #[inline] + pub unsafe fn set_m19_raw(this: *mut Self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 19usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn m20(&self) -> ::std::os::raw::c_char { unsafe { ::std::mem::transmute(self._bitfield_1.get(20usize, 1u8) as u8) } } @@ -327,6 +875,31 @@ impl MuchBitfield { } } #[inline] + pub unsafe fn m20_raw(this: *const Self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 20usize, 1u8) + as u8, + ) + } + } + #[inline] + pub unsafe fn set_m20_raw(this: *mut Self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 20usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn m21(&self) -> ::std::os::raw::c_char { unsafe { ::std::mem::transmute(self._bitfield_1.get(21usize, 1u8) as u8) } } @@ -338,6 +911,31 @@ impl MuchBitfield { } } #[inline] + pub unsafe fn m21_raw(this: *const Self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 21usize, 1u8) + as u8, + ) + } + } + #[inline] + pub unsafe fn set_m21_raw(this: *mut Self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 21usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn m22(&self) -> ::std::os::raw::c_char { unsafe { ::std::mem::transmute(self._bitfield_1.get(22usize, 1u8) as u8) } } @@ -349,6 +947,31 @@ impl MuchBitfield { } } #[inline] + pub unsafe fn m22_raw(this: *const Self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 22usize, 1u8) + as u8, + ) + } + } + #[inline] + pub unsafe fn set_m22_raw(this: *mut Self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 22usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn m23(&self) -> ::std::os::raw::c_char { unsafe { ::std::mem::transmute(self._bitfield_1.get(23usize, 1u8) as u8) } } @@ -360,6 +983,31 @@ impl MuchBitfield { } } #[inline] + pub unsafe fn m23_raw(this: *const Self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 23usize, 1u8) + as u8, + ) + } + } + #[inline] + pub unsafe fn set_m23_raw(this: *mut Self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 23usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn m24(&self) -> ::std::os::raw::c_char { unsafe { ::std::mem::transmute(self._bitfield_1.get(24usize, 1u8) as u8) } } @@ -371,6 +1019,31 @@ impl MuchBitfield { } } #[inline] + pub unsafe fn m24_raw(this: *const Self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 24usize, 1u8) + as u8, + ) + } + } + #[inline] + pub unsafe fn set_m24_raw(this: *mut Self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 24usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn m25(&self) -> ::std::os::raw::c_char { unsafe { ::std::mem::transmute(self._bitfield_1.get(25usize, 1u8) as u8) } } @@ -382,6 +1055,31 @@ impl MuchBitfield { } } #[inline] + pub unsafe fn m25_raw(this: *const Self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 25usize, 1u8) + as u8, + ) + } + } + #[inline] + pub unsafe fn set_m25_raw(this: *mut Self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 25usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn m26(&self) -> ::std::os::raw::c_char { unsafe { ::std::mem::transmute(self._bitfield_1.get(26usize, 1u8) as u8) } } @@ -393,6 +1091,31 @@ impl MuchBitfield { } } #[inline] + pub unsafe fn m26_raw(this: *const Self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 26usize, 1u8) + as u8, + ) + } + } + #[inline] + pub unsafe fn set_m26_raw(this: *mut Self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 26usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn m27(&self) -> ::std::os::raw::c_char { unsafe { ::std::mem::transmute(self._bitfield_1.get(27usize, 1u8) as u8) } } @@ -404,6 +1127,31 @@ impl MuchBitfield { } } #[inline] + pub unsafe fn m27_raw(this: *const Self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 27usize, 1u8) + as u8, + ) + } + } + #[inline] + pub unsafe fn set_m27_raw(this: *mut Self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 27usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn m28(&self) -> ::std::os::raw::c_char { unsafe { ::std::mem::transmute(self._bitfield_1.get(28usize, 1u8) as u8) } } @@ -415,6 +1163,31 @@ impl MuchBitfield { } } #[inline] + pub unsafe fn m28_raw(this: *const Self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 28usize, 1u8) + as u8, + ) + } + } + #[inline] + pub unsafe fn set_m28_raw(this: *mut Self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 28usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn m29(&self) -> ::std::os::raw::c_char { unsafe { ::std::mem::transmute(self._bitfield_1.get(29usize, 1u8) as u8) } } @@ -426,6 +1199,31 @@ impl MuchBitfield { } } #[inline] + pub unsafe fn m29_raw(this: *const Self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 29usize, 1u8) + as u8, + ) + } + } + #[inline] + pub unsafe fn set_m29_raw(this: *mut Self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 29usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn m30(&self) -> ::std::os::raw::c_char { unsafe { ::std::mem::transmute(self._bitfield_1.get(30usize, 1u8) as u8) } } @@ -437,6 +1235,31 @@ impl MuchBitfield { } } #[inline] + pub unsafe fn m30_raw(this: *const Self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 30usize, 1u8) + as u8, + ) + } + } + #[inline] + pub unsafe fn set_m30_raw(this: *mut Self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 30usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn m31(&self) -> ::std::os::raw::c_char { unsafe { ::std::mem::transmute(self._bitfield_1.get(31usize, 1u8) as u8) } } @@ -448,6 +1271,31 @@ impl MuchBitfield { } } #[inline] + pub unsafe fn m31_raw(this: *const Self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 31usize, 1u8) + as u8, + ) + } + } + #[inline] + pub unsafe fn set_m31_raw(this: *mut Self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 31usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn m32(&self) -> ::std::os::raw::c_char { unsafe { ::std::mem::transmute(self._bitfield_1.get(32usize, 1u8) as u8) } } @@ -459,6 +1307,31 @@ impl MuchBitfield { } } #[inline] + pub unsafe fn m32_raw(this: *const Self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 32usize, 1u8) + as u8, + ) + } + } + #[inline] + pub unsafe fn set_m32_raw(this: *mut Self, val: ::std::os::raw::c_char) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 5usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 32usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn new_bitfield_1( m0: ::std::os::raw::c_char, m1: ::std::os::raw::c_char, diff --git a/bindgen-tests/tests/expectations/tests/bitfield-large.rs b/bindgen-tests/tests/expectations/tests/bitfield-large.rs index 27118083d5..47afa9a3ba 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-large.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-large.rs @@ -15,10 +15,7 @@ where Storage: AsRef<[u8]> + AsMut<[u8]>, { #[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]; + fn extract_bit(byte: u8, index: usize) -> bool { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) } else { @@ -28,21 +25,44 @@ where byte & mask == mask } #[inline] - pub fn set_bit(&mut self, index: usize, val: bool) { + pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); let byte_index = index / 8; - let byte = &mut self.storage.as_mut()[byte_index]; + 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 = *(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; - } + 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize); + *byte = Self::change_bit(*byte, index, val); } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -65,6 +85,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 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()); @@ -82,6 +122,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 + }; + Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + } + } } #[repr(C)] #[repr(align(16))] @@ -108,6 +166,31 @@ impl HasBigBitfield { } } #[inline] + pub unsafe fn x_raw(this: *const Self) -> i128 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 128u8) + as u128, + ) + } + } + #[inline] + pub unsafe fn set_x_raw(this: *mut Self, val: i128) { + unsafe { + let val: u128 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 0usize, + 128u8, + val as u64, + ) + } + } + #[inline] pub fn new_bitfield_1(x: i128) -> __BindgenBitfieldUnit<[u8; 16usize]> { let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 16usize]> = Default::default(); __bindgen_bitfield_unit @@ -151,6 +234,31 @@ impl HasTwoBigBitfields { } } #[inline] + pub unsafe fn x_raw(this: *const Self) -> i128 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 80u8) + as u128, + ) + } + } + #[inline] + pub unsafe fn set_x_raw(this: *mut Self, val: i128) { + unsafe { + let val: u128 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 0usize, + 80u8, + val as u64, + ) + } + } + #[inline] pub fn y(&self) -> i128 { unsafe { ::std::mem::transmute(self._bitfield_1.get(80usize, 48u8) as u128) } } @@ -162,6 +270,31 @@ impl HasTwoBigBitfields { } } #[inline] + pub unsafe fn y_raw(this: *const Self) -> i128 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 80usize, 48u8) + as u128, + ) + } + } + #[inline] + pub unsafe fn set_y_raw(this: *mut Self, val: i128) { + unsafe { + let val: u128 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 80usize, + 48u8, + val as u64, + ) + } + } + #[inline] pub fn new_bitfield_1(x: i128, y: i128) -> __BindgenBitfieldUnit<[u8; 16usize]> { let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 16usize]> = Default::default(); __bindgen_bitfield_unit diff --git a/bindgen-tests/tests/expectations/tests/bitfield-linux-32.rs b/bindgen-tests/tests/expectations/tests/bitfield-linux-32.rs index 9e69bf9de5..075aa27e5e 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-linux-32.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-linux-32.rs @@ -15,10 +15,7 @@ where Storage: AsRef<[u8]> + AsMut<[u8]>, { #[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]; + fn extract_bit(byte: u8, index: usize) -> bool { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) } else { @@ -28,21 +25,44 @@ where byte & mask == mask } #[inline] - pub fn set_bit(&mut self, index: usize, val: bool) { + pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); let byte_index = index / 8; - let byte = &mut self.storage.as_mut()[byte_index]; + 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 = *(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; - } + 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize); + *byte = Self::change_bit(*byte, index, val); } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -65,6 +85,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 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()); @@ -82,6 +122,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 + }; + Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + } + } } #[repr(C, packed(4))] #[derive(Debug, Default, Copy, Clone)] @@ -109,6 +167,31 @@ impl Test { } } #[inline] + pub unsafe fn x_raw(this: *const Self) -> u64 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 8usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 56u8) + as u64, + ) + } + } + #[inline] + pub unsafe fn set_x_raw(this: *mut Self, val: u64) { + unsafe { + let val: u64 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 8usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 0usize, + 56u8, + val as u64, + ) + } + } + #[inline] pub fn y(&self) -> u64 { unsafe { ::std::mem::transmute(self._bitfield_1.get(56usize, 8u8) as u64) } } @@ -120,6 +203,31 @@ impl Test { } } #[inline] + pub unsafe fn y_raw(this: *const Self) -> u64 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 8usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 56usize, 8u8) + as u64, + ) + } + } + #[inline] + pub unsafe fn set_y_raw(this: *mut Self, val: u64) { + unsafe { + let val: u64 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 8usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 56usize, + 8u8, + val as u64, + ) + } + } + #[inline] pub fn new_bitfield_1(x: u64, y: u64) -> __BindgenBitfieldUnit<[u8; 8usize]> { let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 8usize]> = Default::default(); __bindgen_bitfield_unit diff --git a/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs b/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs index dd4286496c..4dc321a8ce 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs @@ -15,10 +15,7 @@ where Storage: AsRef<[u8]> + AsMut<[u8]>, { #[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]; + fn extract_bit(byte: u8, index: usize) -> bool { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) } else { @@ -28,21 +25,44 @@ where byte & mask == mask } #[inline] - pub fn set_bit(&mut self, index: usize, val: bool) { + pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); let byte_index = index / 8; - let byte = &mut self.storage.as_mut()[byte_index]; + 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 = *(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; - } + 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize); + *byte = Self::change_bit(*byte, index, val); } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -65,6 +85,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 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()); @@ -82,6 +122,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 + }; + Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + } + } } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -119,6 +177,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; 1usize], + >>::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; 1usize], + >>::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; 1usize]> { diff --git a/bindgen-tests/tests/expectations/tests/bitfield_align.rs b/bindgen-tests/tests/expectations/tests/bitfield_align.rs index 828f176de9..c1c72f3132 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_align.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_align.rs @@ -15,10 +15,7 @@ where Storage: AsRef<[u8]> + AsMut<[u8]>, { #[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]; + fn extract_bit(byte: u8, index: usize) -> bool { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) } else { @@ -28,21 +25,44 @@ where byte & mask == mask } #[inline] - pub fn set_bit(&mut self, index: usize, val: bool) { + pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); let byte_index = index / 8; - let byte = &mut self.storage.as_mut()[byte_index]; + 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 = *(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; - } + 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize); + *byte = Self::change_bit(*byte, index, val); } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -65,6 +85,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 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()); @@ -82,6 +122,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 + }; + Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + } + } } #[repr(C)] #[repr(align(4))] @@ -112,6 +170,31 @@ impl A { } } #[inline] + pub unsafe fn b1_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_b1_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::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 b2(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u32) } } @@ -123,6 +206,31 @@ impl A { } } #[inline] + pub unsafe fn b2_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 1usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_b2_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::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 b3(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u32) } } @@ -134,6 +242,31 @@ impl A { } } #[inline] + pub unsafe fn b3_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 2usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_b3_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::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 b4(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(3usize, 1u8) as u32) } } @@ -145,6 +278,31 @@ impl A { } } #[inline] + pub unsafe fn b4_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 3usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_b4_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::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 b5(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(4usize, 1u8) as u32) } } @@ -156,6 +314,31 @@ impl A { } } #[inline] + pub unsafe fn b5_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 4usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_b5_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::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 b6(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(5usize, 1u8) as u32) } } @@ -167,6 +350,31 @@ impl A { } } #[inline] + pub unsafe fn b6_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 5usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_b6_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::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 b7(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(6usize, 1u8) as u32) } } @@ -178,6 +386,31 @@ impl A { } } #[inline] + pub unsafe fn b7_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 6usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_b7_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::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 b8(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(7usize, 1u8) as u32) } } @@ -189,6 +422,31 @@ impl A { } } #[inline] + pub unsafe fn b8_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 7usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_b8_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::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 b9(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(8usize, 1u8) as u32) } } @@ -200,6 +458,31 @@ impl A { } } #[inline] + pub unsafe fn b9_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 8usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_b9_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::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 b10(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(9usize, 1u8) as u32) } } @@ -211,6 +494,31 @@ impl A { } } #[inline] + pub unsafe fn b10_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 9usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_b10_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 9usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn new_bitfield_1( b1: ::std::os::raw::c_uint, b2: ::std::os::raw::c_uint, @@ -341,6 +649,31 @@ impl B { } } #[inline] + pub unsafe fn foo_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 31u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_foo_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 0usize, + 31u8, + val as u64, + ) + } + } + #[inline] pub fn bar(&self) -> ::std::os::raw::c_uchar { unsafe { ::std::mem::transmute(self._bitfield_1.get(31usize, 1u8) as u8) } } @@ -352,6 +685,31 @@ impl B { } } #[inline] + pub unsafe fn bar_raw(this: *const Self) -> ::std::os::raw::c_uchar { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 31usize, 1u8) + as u8, + ) + } + } + #[inline] + pub unsafe fn set_bar_raw(this: *mut Self, val: ::std::os::raw::c_uchar) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 31usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn new_bitfield_1( foo: ::std::os::raw::c_uint, bar: ::std::os::raw::c_uchar, @@ -406,6 +764,31 @@ impl C { } } #[inline] + pub unsafe fn b1_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_b1_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::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 b2(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u32) } } @@ -417,6 +800,31 @@ impl C { } } #[inline] + pub unsafe fn b2_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 1usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_b2_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::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 new_bitfield_1( b1: ::std::os::raw::c_uint, b2: ::std::os::raw::c_uint, @@ -469,6 +877,31 @@ impl Date1 { } } #[inline] + pub unsafe fn nWeekDay_raw(this: *const Self) -> ::std::os::raw::c_ushort { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 3usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 3u8) + as u16, + ) + } + } + #[inline] + pub unsafe fn set_nWeekDay_raw(this: *mut Self, val: ::std::os::raw::c_ushort) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 3usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 0usize, + 3u8, + val as u64, + ) + } + } + #[inline] pub fn nMonthDay(&self) -> ::std::os::raw::c_ushort { unsafe { ::std::mem::transmute(self._bitfield_1.get(3usize, 6u8) as u16) } } @@ -480,6 +913,31 @@ impl Date1 { } } #[inline] + pub unsafe fn nMonthDay_raw(this: *const Self) -> ::std::os::raw::c_ushort { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 3usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 3usize, 6u8) + as u16, + ) + } + } + #[inline] + pub unsafe fn set_nMonthDay_raw(this: *mut Self, val: ::std::os::raw::c_ushort) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 3usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 3usize, + 6u8, + val as u64, + ) + } + } + #[inline] pub fn nMonth(&self) -> ::std::os::raw::c_ushort { unsafe { ::std::mem::transmute(self._bitfield_1.get(9usize, 5u8) as u16) } } @@ -491,6 +949,31 @@ impl Date1 { } } #[inline] + pub unsafe fn nMonth_raw(this: *const Self) -> ::std::os::raw::c_ushort { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 3usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 9usize, 5u8) + as u16, + ) + } + } + #[inline] + pub unsafe fn set_nMonth_raw(this: *mut Self, val: ::std::os::raw::c_ushort) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 3usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 9usize, + 5u8, + val as u64, + ) + } + } + #[inline] pub fn nYear(&self) -> ::std::os::raw::c_ushort { unsafe { ::std::mem::transmute(self._bitfield_1.get(16usize, 8u8) as u16) } } @@ -502,6 +985,31 @@ impl Date1 { } } #[inline] + pub unsafe fn nYear_raw(this: *const Self) -> ::std::os::raw::c_ushort { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 3usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 16usize, 8u8) + as u16, + ) + } + } + #[inline] + pub unsafe fn set_nYear_raw(this: *mut Self, val: ::std::os::raw::c_ushort) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 3usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 16usize, + 8u8, + val as u64, + ) + } + } + #[inline] pub fn new_bitfield_1( nWeekDay: ::std::os::raw::c_ushort, nMonthDay: ::std::os::raw::c_ushort, @@ -573,6 +1081,31 @@ impl Date2 { } } #[inline] + pub unsafe fn nWeekDay_raw(this: *const Self) -> ::std::os::raw::c_ushort { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 3u8) + as u16, + ) + } + } + #[inline] + pub unsafe fn set_nWeekDay_raw(this: *mut Self, val: ::std::os::raw::c_ushort) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 0usize, + 3u8, + val as u64, + ) + } + } + #[inline] pub fn nMonthDay(&self) -> ::std::os::raw::c_ushort { unsafe { ::std::mem::transmute(self._bitfield_1.get(3usize, 6u8) as u16) } } @@ -584,6 +1117,31 @@ impl Date2 { } } #[inline] + pub unsafe fn nMonthDay_raw(this: *const Self) -> ::std::os::raw::c_ushort { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 3usize, 6u8) + as u16, + ) + } + } + #[inline] + pub unsafe fn set_nMonthDay_raw(this: *mut Self, val: ::std::os::raw::c_ushort) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 3usize, + 6u8, + val as u64, + ) + } + } + #[inline] pub fn nMonth(&self) -> ::std::os::raw::c_ushort { unsafe { ::std::mem::transmute(self._bitfield_1.get(9usize, 5u8) as u16) } } @@ -595,6 +1153,31 @@ impl Date2 { } } #[inline] + pub unsafe fn nMonth_raw(this: *const Self) -> ::std::os::raw::c_ushort { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 9usize, 5u8) + as u16, + ) + } + } + #[inline] + pub unsafe fn set_nMonth_raw(this: *mut Self, val: ::std::os::raw::c_ushort) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 9usize, + 5u8, + val as u64, + ) + } + } + #[inline] pub fn nYear(&self) -> ::std::os::raw::c_ushort { unsafe { ::std::mem::transmute(self._bitfield_1.get(16usize, 8u8) as u16) } } @@ -606,6 +1189,31 @@ impl Date2 { } } #[inline] + pub unsafe fn nYear_raw(this: *const Self) -> ::std::os::raw::c_ushort { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 16usize, 8u8) + as u16, + ) + } + } + #[inline] + pub unsafe fn set_nYear_raw(this: *mut Self, val: ::std::os::raw::c_ushort) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 16usize, + 8u8, + val as u64, + ) + } + } + #[inline] pub fn byte(&self) -> ::std::os::raw::c_uchar { unsafe { ::std::mem::transmute(self._bitfield_1.get(24usize, 8u8) as u8) } } @@ -617,6 +1225,31 @@ impl Date2 { } } #[inline] + pub unsafe fn byte_raw(this: *const Self) -> ::std::os::raw::c_uchar { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 24usize, 8u8) + as u8, + ) + } + } + #[inline] + pub unsafe fn set_byte_raw(this: *mut Self, val: ::std::os::raw::c_uchar) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 24usize, + 8u8, + val as u64, + ) + } + } + #[inline] pub fn new_bitfield_1( nWeekDay: ::std::os::raw::c_ushort, nMonthDay: ::std::os::raw::c_ushort, @@ -700,6 +1333,31 @@ impl Date3 { } } #[inline] + pub unsafe fn nWeekDay_raw(this: *const Self) -> ::std::os::raw::c_ushort { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 3usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 3u8) + as u16, + ) + } + } + #[inline] + pub unsafe fn set_nWeekDay_raw(this: *mut Self, val: ::std::os::raw::c_ushort) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 3usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 0usize, + 3u8, + val as u64, + ) + } + } + #[inline] pub fn nMonthDay(&self) -> ::std::os::raw::c_ushort { unsafe { ::std::mem::transmute(self._bitfield_1.get(3usize, 6u8) as u16) } } @@ -711,6 +1369,31 @@ impl Date3 { } } #[inline] + pub unsafe fn nMonthDay_raw(this: *const Self) -> ::std::os::raw::c_ushort { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 3usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 3usize, 6u8) + as u16, + ) + } + } + #[inline] + pub unsafe fn set_nMonthDay_raw(this: *mut Self, val: ::std::os::raw::c_ushort) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 3usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 3usize, + 6u8, + val as u64, + ) + } + } + #[inline] pub fn nMonth(&self) -> ::std::os::raw::c_ushort { unsafe { ::std::mem::transmute(self._bitfield_1.get(9usize, 5u8) as u16) } } @@ -722,6 +1405,31 @@ impl Date3 { } } #[inline] + pub unsafe fn nMonth_raw(this: *const Self) -> ::std::os::raw::c_ushort { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 3usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 9usize, 5u8) + as u16, + ) + } + } + #[inline] + pub unsafe fn set_nMonth_raw(this: *mut Self, val: ::std::os::raw::c_ushort) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 3usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 9usize, + 5u8, + val as u64, + ) + } + } + #[inline] pub fn nYear(&self) -> ::std::os::raw::c_ushort { unsafe { ::std::mem::transmute(self._bitfield_1.get(16usize, 8u8) as u16) } } @@ -733,6 +1441,31 @@ impl Date3 { } } #[inline] + pub unsafe fn nYear_raw(this: *const Self) -> ::std::os::raw::c_ushort { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 3usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 16usize, 8u8) + as u16, + ) + } + } + #[inline] + pub unsafe fn set_nYear_raw(this: *mut Self, val: ::std::os::raw::c_ushort) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 3usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 16usize, + 8u8, + val as u64, + ) + } + } + #[inline] pub fn new_bitfield_1( nWeekDay: ::std::os::raw::c_ushort, nMonthDay: ::std::os::raw::c_ushort, diff --git a/bindgen-tests/tests/expectations/tests/bitfield_align_2.rs b/bindgen-tests/tests/expectations/tests/bitfield_align_2.rs index b87af0c99c..0f783fe76e 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_align_2.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_align_2.rs @@ -16,10 +16,7 @@ where Storage: AsRef<[u8]> + AsMut<[u8]>, { #[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]; + fn extract_bit(byte: u8, index: usize) -> bool { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) } else { @@ -29,21 +26,44 @@ where byte & mask == mask } #[inline] - pub fn set_bit(&mut self, index: usize, val: bool) { + pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); let byte_index = index / 8; - let byte = &mut self.storage.as_mut()[byte_index]; + 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 = *(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; - } + 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize); + *byte = Self::change_bit(*byte, index, val); } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -66,6 +86,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 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()); @@ -83,6 +123,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 + }; + Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + } + } } #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] @@ -125,6 +183,31 @@ impl TaggedPtr { } } #[inline] + pub unsafe fn tag_raw(this: *const Self) -> MyEnum { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 8usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 2u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_tag_raw(this: *mut Self, val: MyEnum) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 8usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 0usize, + 2u8, + val as u64, + ) + } + } + #[inline] pub fn ptr(&self) -> ::std::os::raw::c_long { unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 62u8) as u64) } } @@ -136,6 +219,31 @@ impl TaggedPtr { } } #[inline] + pub unsafe fn ptr_raw(this: *const Self) -> ::std::os::raw::c_long { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 8usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 2usize, 62u8) + as u64, + ) + } + } + #[inline] + pub unsafe fn set_ptr_raw(this: *mut Self, val: ::std::os::raw::c_long) { + unsafe { + let val: u64 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 8usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 2usize, + 62u8, + val as u64, + ) + } + } + #[inline] pub fn new_bitfield_1( tag: MyEnum, ptr: ::std::os::raw::c_long, diff --git a/bindgen-tests/tests/expectations/tests/bitfield_method_mangling.rs b/bindgen-tests/tests/expectations/tests/bitfield_method_mangling.rs index b6fe8a5257..966943f935 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_method_mangling.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_method_mangling.rs @@ -15,10 +15,7 @@ where Storage: AsRef<[u8]> + AsMut<[u8]>, { #[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]; + fn extract_bit(byte: u8, index: usize) -> bool { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) } else { @@ -28,21 +25,44 @@ where byte & mask == mask } #[inline] - pub fn set_bit(&mut self, index: usize, val: bool) { + pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); let byte_index = index / 8; - let byte = &mut self.storage.as_mut()[byte_index]; + 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 = *(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; - } + 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize); + *byte = Self::change_bit(*byte, index, val); } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -65,6 +85,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 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()); @@ -82,6 +122,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 + }; + Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + } + } } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -111,6 +169,31 @@ impl mach_msg_type_descriptor_t { } } #[inline] + pub unsafe fn pad3_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 24u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_pad3_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 0usize, + 24u8, + val as u64, + ) + } + } + #[inline] pub fn type_(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(24usize, 8u8) as u32) } } @@ -122,6 +205,31 @@ impl mach_msg_type_descriptor_t { } } #[inline] + pub unsafe fn type__raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 24usize, 8u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_type_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 24usize, + 8u8, + val as u64, + ) + } + } + #[inline] pub fn new_bitfield_1( pad3: ::std::os::raw::c_uint, type_: ::std::os::raw::c_uint, diff --git a/bindgen-tests/tests/expectations/tests/bitfield_pragma_packed.rs b/bindgen-tests/tests/expectations/tests/bitfield_pragma_packed.rs index 60cf6b8056..0cd2002fb6 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_pragma_packed.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_pragma_packed.rs @@ -15,10 +15,7 @@ where Storage: AsRef<[u8]> + AsMut<[u8]>, { #[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]; + fn extract_bit(byte: u8, index: usize) -> bool { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) } else { @@ -28,21 +25,44 @@ where byte & mask == mask } #[inline] - pub fn set_bit(&mut self, index: usize, val: bool) { + pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); let byte_index = index / 8; - let byte = &mut self.storage.as_mut()[byte_index]; + 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 = *(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; - } + 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize); + *byte = Self::change_bit(*byte, index, val); } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -65,6 +85,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 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()); @@ -82,6 +122,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 + }; + Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + } + } } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -107,6 +165,30 @@ impl Struct { } } #[inline] + pub unsafe fn a_raw(this: *const Self) -> ::std::os::raw::c_uchar { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 1u8) as u8, + ) + } + } + #[inline] + pub unsafe fn set_a_raw(this: *mut Self, val: ::std::os::raw::c_uchar) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 0usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn b(&self) -> ::std::os::raw::c_uchar { unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u8) } } @@ -118,6 +200,30 @@ impl Struct { } } #[inline] + pub unsafe fn b_raw(this: *const Self) -> ::std::os::raw::c_uchar { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 1usize, 1u8) as u8, + ) + } + } + #[inline] + pub unsafe fn set_b_raw(this: *mut Self, val: ::std::os::raw::c_uchar) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 1usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn c(&self) -> ::std::os::raw::c_uchar { unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 6u8) as u8) } } @@ -129,6 +235,30 @@ impl Struct { } } #[inline] + pub unsafe fn c_raw(this: *const Self) -> ::std::os::raw::c_uchar { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 2usize, 6u8) as u8, + ) + } + } + #[inline] + pub unsafe fn set_c_raw(this: *mut Self, val: ::std::os::raw::c_uchar) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 2usize, + 6u8, + val as u64, + ) + } + } + #[inline] pub fn d(&self) -> ::std::os::raw::c_ushort { unsafe { ::std::mem::transmute(self._bitfield_1.get(8usize, 16u8) as u16) } } @@ -140,6 +270,31 @@ impl Struct { } } #[inline] + pub unsafe fn d_raw(this: *const Self) -> ::std::os::raw::c_ushort { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 8usize, 16u8) + as u16, + ) + } + } + #[inline] + pub unsafe fn set_d_raw(this: *mut Self, val: ::std::os::raw::c_ushort) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 8usize, + 16u8, + val as u64, + ) + } + } + #[inline] pub fn e(&self) -> ::std::os::raw::c_uchar { unsafe { ::std::mem::transmute(self._bitfield_1.get(24usize, 8u8) as u8) } } @@ -151,6 +306,31 @@ impl Struct { } } #[inline] + pub unsafe fn e_raw(this: *const Self) -> ::std::os::raw::c_uchar { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 24usize, 8u8) + as u8, + ) + } + } + #[inline] + pub unsafe fn set_e_raw(this: *mut Self, val: ::std::os::raw::c_uchar) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 24usize, + 8u8, + val as u64, + ) + } + } + #[inline] pub fn new_bitfield_1( a: ::std::os::raw::c_uchar, b: ::std::os::raw::c_uchar, @@ -231,6 +411,31 @@ impl Inner { } } #[inline] + pub unsafe fn a_raw(this: *const Self) -> ::std::os::raw::c_ushort { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 16u8) + as u16, + ) + } + } + #[inline] + pub unsafe fn set_a_raw(this: *mut Self, val: ::std::os::raw::c_ushort) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 0usize, + 16u8, + val as u64, + ) + } + } + #[inline] pub fn b(&self) -> ::std::os::raw::c_ushort { unsafe { ::std::mem::transmute(self._bitfield_1.get(16usize, 16u8) as u16) } } @@ -242,6 +447,31 @@ impl Inner { } } #[inline] + pub unsafe fn b_raw(this: *const Self) -> ::std::os::raw::c_ushort { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 16usize, 16u8) + as u16, + ) + } + } + #[inline] + pub unsafe fn set_b_raw(this: *mut Self, val: ::std::os::raw::c_ushort) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 16usize, + 16u8, + val as u64, + ) + } + } + #[inline] pub fn new_bitfield_1( a: ::std::os::raw::c_ushort, b: ::std::os::raw::c_ushort, diff --git a/bindgen-tests/tests/expectations/tests/blocklist_bitfield_unit.rs b/bindgen-tests/tests/expectations/tests/blocklist_bitfield_unit.rs index b5737a8d99..fc9f9a38c7 100644 --- a/bindgen-tests/tests/expectations/tests/blocklist_bitfield_unit.rs +++ b/bindgen-tests/tests/expectations/tests/blocklist_bitfield_unit.rs @@ -30,6 +30,31 @@ impl C { } } #[inline] + pub unsafe fn b1_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_b1_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::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 b2(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u32) } } @@ -41,6 +66,31 @@ impl C { } } #[inline] + pub unsafe fn b2_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 1usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_b2_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::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 new_bitfield_1( b1: ::std::os::raw::c_uint, b2: ::std::os::raw::c_uint, diff --git a/bindgen-tests/tests/expectations/tests/default_visibility_crate.rs b/bindgen-tests/tests/expectations/tests/default_visibility_crate.rs index aef1a61a08..0aca5a3b8a 100644 --- a/bindgen-tests/tests/expectations/tests/default_visibility_crate.rs +++ b/bindgen-tests/tests/expectations/tests/default_visibility_crate.rs @@ -15,10 +15,7 @@ where Storage: AsRef<[u8]> + AsMut<[u8]>, { #[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]; + fn extract_bit(byte: u8, index: usize) -> bool { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) } else { @@ -28,21 +25,44 @@ where byte & mask == mask } #[inline] - pub fn set_bit(&mut self, index: usize, val: bool) { + pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); let byte_index = index / 8; - let byte = &mut self.storage.as_mut()[byte_index]; + 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 = *(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; - } + 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize); + *byte = Self::change_bit(*byte, index, val); } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -65,6 +85,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 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()); @@ -82,6 +122,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 + }; + Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + } + } } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -108,6 +166,30 @@ impl Color { } } #[inline] + pub(crate) unsafe fn r_raw(this: *const Self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 1u8) as u8, + ) + } + } + #[inline] + pub(crate) unsafe fn set_r_raw(this: *mut Self, val: ::std::os::raw::c_char) { + 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(crate) fn g(&self) -> ::std::os::raw::c_char { unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u8) } } @@ -119,6 +201,30 @@ impl Color { } } #[inline] + pub(crate) unsafe fn g_raw(this: *const Self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 1usize, 1u8) as u8, + ) + } + } + #[inline] + pub(crate) unsafe fn set_g_raw(this: *mut Self, val: ::std::os::raw::c_char) { + 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(crate) fn b(&self) -> ::std::os::raw::c_char { unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u8) } } @@ -130,6 +236,30 @@ impl Color { } } #[inline] + pub(crate) unsafe fn b_raw(this: *const Self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 2usize, 1u8) as u8, + ) + } + } + #[inline] + pub(crate) unsafe fn set_b_raw(this: *mut Self, val: ::std::os::raw::c_char) { + 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(crate) fn new_bitfield_1( r: ::std::os::raw::c_char, g: ::std::os::raw::c_char, diff --git a/bindgen-tests/tests/expectations/tests/default_visibility_private.rs b/bindgen-tests/tests/expectations/tests/default_visibility_private.rs index 8b3099c0d8..0d4d42cfdb 100644 --- a/bindgen-tests/tests/expectations/tests/default_visibility_private.rs +++ b/bindgen-tests/tests/expectations/tests/default_visibility_private.rs @@ -15,10 +15,7 @@ where Storage: AsRef<[u8]> + AsMut<[u8]>, { #[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]; + fn extract_bit(byte: u8, index: usize) -> bool { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) } else { @@ -28,21 +25,44 @@ where byte & mask == mask } #[inline] - pub fn set_bit(&mut self, index: usize, val: bool) { + pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); let byte_index = index / 8; - let byte = &mut self.storage.as_mut()[byte_index]; + 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 = *(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; - } + 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize); + *byte = Self::change_bit(*byte, index, val); } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -65,6 +85,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 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()); @@ -82,6 +122,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 + }; + Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + } + } } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -108,6 +166,30 @@ impl Color { } } #[inline] + unsafe fn r_raw(this: *const Self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 1u8) as u8, + ) + } + } + #[inline] + unsafe fn set_r_raw(this: *mut Self, val: ::std::os::raw::c_char) { + 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] fn g(&self) -> ::std::os::raw::c_char { unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u8) } } @@ -119,6 +201,30 @@ impl Color { } } #[inline] + unsafe fn g_raw(this: *const Self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 1usize, 1u8) as u8, + ) + } + } + #[inline] + unsafe fn set_g_raw(this: *mut Self, val: ::std::os::raw::c_char) { + 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] fn b(&self) -> ::std::os::raw::c_char { unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u8) } } @@ -130,6 +236,30 @@ impl Color { } } #[inline] + unsafe fn b_raw(this: *const Self) -> ::std::os::raw::c_char { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 2usize, 1u8) as u8, + ) + } + } + #[inline] + unsafe fn set_b_raw(this: *mut Self, val: ::std::os::raw::c_char) { + 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] fn new_bitfield_1( r: ::std::os::raw::c_char, g: ::std::os::raw::c_char, diff --git a/bindgen-tests/tests/expectations/tests/default_visibility_private_respects_cxx_access_spec.rs b/bindgen-tests/tests/expectations/tests/default_visibility_private_respects_cxx_access_spec.rs index 29fbb3a893..cf135cfd3d 100644 --- a/bindgen-tests/tests/expectations/tests/default_visibility_private_respects_cxx_access_spec.rs +++ b/bindgen-tests/tests/expectations/tests/default_visibility_private_respects_cxx_access_spec.rs @@ -15,10 +15,7 @@ where Storage: AsRef<[u8]> + AsMut<[u8]>, { #[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]; + fn extract_bit(byte: u8, index: usize) -> bool { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) } else { @@ -28,21 +25,44 @@ where byte & mask == mask } #[inline] - pub fn set_bit(&mut self, index: usize, val: bool) { + pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); let byte_index = index / 8; - let byte = &mut self.storage.as_mut()[byte_index]; + 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 = *(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; - } + 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize); + *byte = Self::change_bit(*byte, index, val); } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -65,6 +85,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 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()); @@ -82,6 +122,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 + }; + Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + } + } } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -108,6 +166,30 @@ impl Color { } } #[inline] + pub unsafe fn r_raw(this: *const Self) -> ::std::os::raw::c_char { + 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_r_raw(this: *mut Self, val: ::std::os::raw::c_char) { + 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 g(&self) -> ::std::os::raw::c_char { unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u8) } } @@ -119,6 +201,30 @@ impl Color { } } #[inline] + pub unsafe fn g_raw(this: *const Self) -> ::std::os::raw::c_char { + 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_g_raw(this: *mut Self, val: ::std::os::raw::c_char) { + 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 b(&self) -> ::std::os::raw::c_char { unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u8) } } @@ -130,6 +236,30 @@ impl Color { } } #[inline] + pub unsafe fn b_raw(this: *const Self) -> ::std::os::raw::c_char { + 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_b_raw(this: *mut Self, val: ::std::os::raw::c_char) { + 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] fn new_bitfield_1( r: ::std::os::raw::c_char, g: ::std::os::raw::c_char, 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 feded416f7..88b9ceaa24 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 @@ -15,10 +15,7 @@ where Storage: AsRef<[u8]> + AsMut<[u8]>, { #[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]; + fn extract_bit(byte: u8, index: usize) -> bool { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) } else { @@ -28,21 +25,44 @@ where byte & mask == mask } #[inline] - pub fn set_bit(&mut self, index: usize, val: bool) { + pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); let byte_index = index / 8; - let byte = &mut self.storage.as_mut()[byte_index]; + 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 = *(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; - } + 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize); + *byte = Self::change_bit(*byte, index, val); } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -65,6 +85,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 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()); @@ -82,6 +122,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 + }; + 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, @@ -161,6 +219,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-debug-bitfield-core.rs b/bindgen-tests/tests/expectations/tests/derive-debug-bitfield-core.rs index 64c20f91ba..e88d1d6d38 100644 --- a/bindgen-tests/tests/expectations/tests/derive-debug-bitfield-core.rs +++ b/bindgen-tests/tests/expectations/tests/derive-debug-bitfield-core.rs @@ -16,10 +16,7 @@ where Storage: AsRef<[u8]> + AsMut<[u8]>, { #[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]; + fn extract_bit(byte: u8, index: usize) -> bool { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) } else { @@ -29,21 +26,44 @@ where byte & mask == mask } #[inline] - pub fn set_bit(&mut self, index: usize, val: bool) { + pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); let byte_index = index / 8; - let byte = &mut self.storage.as_mut()[byte_index]; + 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 = *(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; - } + 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize); + *byte = Self::change_bit(*byte, index, val); } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -66,6 +86,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 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()); @@ -83,6 +123,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 + }; + Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + } + } } #[repr(C)] #[derive(Copy, Clone)] @@ -130,6 +188,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) } } @@ -141,6 +224,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 0471b48bfa..09ca288b07 100644 --- a/bindgen-tests/tests/expectations/tests/derive-debug-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/derive-debug-bitfield.rs @@ -15,10 +15,7 @@ where Storage: AsRef<[u8]> + AsMut<[u8]>, { #[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]; + fn extract_bit(byte: u8, index: usize) -> bool { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) } else { @@ -28,21 +25,44 @@ where byte & mask == mask } #[inline] - pub fn set_bit(&mut self, index: usize, val: bool) { + pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); let byte_index = index / 8; - let byte = &mut self.storage.as_mut()[byte_index]; + 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 = *(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; - } + 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize); + *byte = Self::change_bit(*byte, index, val); } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -65,6 +85,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 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()); @@ -82,6 +122,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 + }; + Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + } + } } #[repr(C)] #[derive(Copy, Clone)] @@ -140,6 +198,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) } } @@ -151,6 +233,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-bitfield.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-bitfield.rs index 7c325620cf..b27a9bb32d 100644 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/derive-partialeq-bitfield.rs @@ -15,10 +15,7 @@ where Storage: AsRef<[u8]> + AsMut<[u8]>, { #[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]; + fn extract_bit(byte: u8, index: usize) -> bool { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) } else { @@ -28,21 +25,44 @@ where byte & mask == mask } #[inline] - pub fn set_bit(&mut self, index: usize, val: bool) { + pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); let byte_index = index / 8; - let byte = &mut self.storage.as_mut()[byte_index]; + 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 = *(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; - } + 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize); + *byte = Self::change_bit(*byte, index, val); } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -65,6 +85,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 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()); @@ -82,6 +122,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 + }; + Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + } + } } #[repr(C)] #[derive(Copy, Clone)] @@ -130,6 +188,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) } } @@ -141,6 +223,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/divide-by-zero-in-struct-layout.rs b/bindgen-tests/tests/expectations/tests/divide-by-zero-in-struct-layout.rs index 707c2d56bc..0e1fe567ac 100644 --- a/bindgen-tests/tests/expectations/tests/divide-by-zero-in-struct-layout.rs +++ b/bindgen-tests/tests/expectations/tests/divide-by-zero-in-struct-layout.rs @@ -15,10 +15,7 @@ where Storage: AsRef<[u8]> + AsMut<[u8]>, { #[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]; + fn extract_bit(byte: u8, index: usize) -> bool { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) } else { @@ -28,21 +25,44 @@ where byte & mask == mask } #[inline] - pub fn set_bit(&mut self, index: usize, val: bool) { + pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); let byte_index = index / 8; - let byte = &mut self.storage.as_mut()[byte_index]; + 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 = *(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; - } + 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize); + *byte = Self::change_bit(*byte, index, val); } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -65,6 +85,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 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()); @@ -82,6 +122,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 + }; + Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + } + } } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] diff --git a/bindgen-tests/tests/expectations/tests/field-visibility-callback.rs b/bindgen-tests/tests/expectations/tests/field-visibility-callback.rs index 9be373e5a7..8634dafba1 100644 --- a/bindgen-tests/tests/expectations/tests/field-visibility-callback.rs +++ b/bindgen-tests/tests/expectations/tests/field-visibility-callback.rs @@ -15,10 +15,7 @@ where Storage: AsRef<[u8]> + AsMut<[u8]>, { #[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]; + fn extract_bit(byte: u8, index: usize) -> bool { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) } else { @@ -28,21 +25,44 @@ where byte & mask == mask } #[inline] - pub fn set_bit(&mut self, index: usize, val: bool) { + pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); let byte_index = index / 8; - let byte = &mut self.storage.as_mut()[byte_index]; + 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 = *(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; - } + 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize); + *byte = Self::change_bit(*byte, index, val); } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -65,6 +85,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 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()); @@ -82,6 +122,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 + }; + Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + } + } } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -114,6 +172,31 @@ impl my_struct { } } #[inline] + pub unsafe fn c_raw(this: *const Self) -> ::std::os::raw::c_int { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_c_raw(this: *mut Self, val: ::std::os::raw::c_int) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 0usize, + 1u8, + val as u64, + ) + } + } + #[inline] fn private_d(&self) -> ::std::os::raw::c_int { unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u32) } } @@ -125,6 +208,31 @@ impl my_struct { } } #[inline] + unsafe fn private_d_raw(this: *const Self) -> ::std::os::raw::c_int { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 1usize, 1u8) + as u32, + ) + } + } + #[inline] + unsafe fn set_private_d_raw(this: *mut Self, val: ::std::os::raw::c_int) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 1usize, + 1u8, + val as u64, + ) + } + } + #[inline] fn new_bitfield_1( c: ::std::os::raw::c_int, private_d: ::std::os::raw::c_int, diff --git a/bindgen-tests/tests/expectations/tests/field-visibility.rs b/bindgen-tests/tests/expectations/tests/field-visibility.rs index 2ad5dc838e..5dfe7502d3 100644 --- a/bindgen-tests/tests/expectations/tests/field-visibility.rs +++ b/bindgen-tests/tests/expectations/tests/field-visibility.rs @@ -15,10 +15,7 @@ where Storage: AsRef<[u8]> + AsMut<[u8]>, { #[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]; + fn extract_bit(byte: u8, index: usize) -> bool { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) } else { @@ -28,21 +25,44 @@ where byte & mask == mask } #[inline] - pub fn set_bit(&mut self, index: usize, val: bool) { + pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); let byte_index = index / 8; - let byte = &mut self.storage.as_mut()[byte_index]; + 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 = *(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; - } + 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize); + *byte = Self::change_bit(*byte, index, val); } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -65,6 +85,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 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()); @@ -82,6 +122,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 + }; + Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + } + } } #[repr(C)] #[repr(align(4))] @@ -109,6 +167,31 @@ impl my_struct1 { } } #[inline] + unsafe fn a_raw(this: *const Self) -> ::std::os::raw::c_int { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 1u8) + as u32, + ) + } + } + #[inline] + unsafe fn set_a_raw(this: *mut Self, val: ::std::os::raw::c_int) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 0usize, + 1u8, + val as u64, + ) + } + } + #[inline] fn new_bitfield_1(a: ::std::os::raw::c_int) -> __BindgenBitfieldUnit<[u8; 1usize]> { let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); __bindgen_bitfield_unit @@ -149,6 +232,31 @@ impl my_struct2 { } } #[inline] + pub unsafe fn a_raw(this: *const Self) -> ::std::os::raw::c_int { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_a_raw(this: *mut Self, val: ::std::os::raw::c_int) { + unsafe { + let val: u32 = ::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 new_bitfield_1( a: ::std::os::raw::c_int, ) -> __BindgenBitfieldUnit<[u8; 1usize]> { diff --git a/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs b/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs index 148f4ffa41..6e420e9fc3 100644 --- a/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs +++ b/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs @@ -15,10 +15,7 @@ where Storage: AsRef<[u8]> + AsMut<[u8]>, { #[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]; + fn extract_bit(byte: u8, index: usize) -> bool { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) } else { @@ -28,21 +25,44 @@ where byte & mask == mask } #[inline] - pub fn set_bit(&mut self, index: usize, val: bool) { + pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); let byte_index = index / 8; - let byte = &mut self.storage.as_mut()[byte_index]; + 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 = *(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; - } + 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize); + *byte = Self::change_bit(*byte, index, val); } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -65,6 +85,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 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()); @@ -82,6 +122,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 + }; + Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + } + } } #[repr(C)] #[derive(Default)] @@ -148,6 +206,30 @@ impl foo { } } #[inline] + pub unsafe fn a_raw(this: *const Self) -> ::std::os::raw::c_char { + 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: ::std::os::raw::c_char) { + 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 new_bitfield_1( a: ::std::os::raw::c_char, ) -> __BindgenBitfieldUnit<[u8; 1usize]> { diff --git a/bindgen-tests/tests/expectations/tests/issue-1034.rs b/bindgen-tests/tests/expectations/tests/issue-1034.rs index 17450a1346..75e3ed3858 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1034.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1034.rs @@ -15,10 +15,7 @@ where Storage: AsRef<[u8]> + AsMut<[u8]>, { #[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]; + fn extract_bit(byte: u8, index: usize) -> bool { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) } else { @@ -28,21 +25,44 @@ where byte & mask == mask } #[inline] - pub fn set_bit(&mut self, index: usize, val: bool) { + pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); let byte_index = index / 8; - let byte = &mut self.storage.as_mut()[byte_index]; + 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 = *(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; - } + 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize); + *byte = Self::change_bit(*byte, index, val); } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -65,6 +85,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 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()); @@ -82,6 +122,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 + }; + Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + } + } } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] diff --git a/bindgen-tests/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs b/bindgen-tests/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs index 5bdf08d992..7d517e5633 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs @@ -15,10 +15,7 @@ where Storage: AsRef<[u8]> + AsMut<[u8]>, { #[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]; + fn extract_bit(byte: u8, index: usize) -> bool { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) } else { @@ -28,21 +25,44 @@ where byte & mask == mask } #[inline] - pub fn set_bit(&mut self, index: usize, val: bool) { + pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); let byte_index = index / 8; - let byte = &mut self.storage.as_mut()[byte_index]; + 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 = *(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; - } + 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize); + *byte = Self::change_bit(*byte, index, val); } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -65,6 +85,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 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()); @@ -82,6 +122,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 + }; + Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + } + } } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] diff --git a/bindgen-tests/tests/expectations/tests/issue-1947.rs b/bindgen-tests/tests/expectations/tests/issue-1947.rs index 32f9bbe146..bec383bbdb 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1947.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1947.rs @@ -15,10 +15,7 @@ where Storage: AsRef<[u8]> + AsMut<[u8]>, { #[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]; + fn extract_bit(byte: u8, index: usize) -> bool { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) } else { @@ -28,21 +25,44 @@ where byte & mask == mask } #[inline] - pub fn set_bit(&mut self, index: usize, val: bool) { + pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); let byte_index = index / 8; - let byte = &mut self.storage.as_mut()[byte_index]; + 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 = *(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; - } + 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize); + *byte = Self::change_bit(*byte, index, val); } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -65,6 +85,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 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()); @@ -82,6 +122,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 + }; + Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + } + } } pub type U8 = ::std::os::raw::c_uchar; pub type U16 = ::std::os::raw::c_ushort; @@ -117,6 +175,31 @@ impl V56AMDY { } } #[inline] + pub unsafe fn MADZ_raw(this: *const Self) -> U16 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 10u8) + as u16, + ) + } + } + #[inline] + pub unsafe fn set_MADZ_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, + 10u8, + val as u64, + ) + } + } + #[inline] pub fn MAI0(&self) -> U16 { unsafe { ::std::mem::transmute(self._bitfield_1.get(10usize, 2u8) as u16) } } @@ -128,6 +211,31 @@ impl V56AMDY { } } #[inline] + pub unsafe fn MAI0_raw(this: *const Self) -> U16 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 10usize, 2u8) + as u16, + ) + } + } + #[inline] + pub unsafe fn set_MAI0_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), + 10usize, + 2u8, + val as u64, + ) + } + } + #[inline] pub fn MAI1(&self) -> U16 { unsafe { ::std::mem::transmute(self._bitfield_1.get(12usize, 2u8) as u16) } } @@ -139,6 +247,31 @@ impl V56AMDY { } } #[inline] + pub unsafe fn MAI1_raw(this: *const Self) -> U16 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 12usize, 2u8) + as u16, + ) + } + } + #[inline] + pub unsafe fn set_MAI1_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), + 12usize, + 2u8, + val as u64, + ) + } + } + #[inline] pub fn MAI2(&self) -> U16 { unsafe { ::std::mem::transmute(self._bitfield_1.get(14usize, 2u8) as u16) } } @@ -150,6 +283,31 @@ impl V56AMDY { } } #[inline] + pub unsafe fn MAI2_raw(this: *const Self) -> U16 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 14usize, 2u8) + as u16, + ) + } + } + #[inline] + pub unsafe fn set_MAI2_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), + 14usize, + 2u8, + val as u64, + ) + } + } + #[inline] pub fn new_bitfield_1( MADZ: U16, MAI0: U16, @@ -207,6 +365,31 @@ impl V56AMDY { } } #[inline] + pub unsafe fn MATH_raw(this: *const Self) -> U16 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 3usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_2), 0usize, 10u8) + as u16, + ) + } + } + #[inline] + pub unsafe fn set_MATH_raw(this: *mut Self, val: U16) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 3usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_2), + 0usize, + 10u8, + val as u64, + ) + } + } + #[inline] pub fn MATE(&self) -> U16 { unsafe { ::std::mem::transmute(self._bitfield_2.get(10usize, 4u8) as u16) } } @@ -218,6 +401,31 @@ impl V56AMDY { } } #[inline] + pub unsafe fn MATE_raw(this: *const Self) -> U16 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 3usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_2), 10usize, 4u8) + as u16, + ) + } + } + #[inline] + pub unsafe fn set_MATE_raw(this: *mut Self, val: U16) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 3usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_2), + 10usize, + 4u8, + val as u64, + ) + } + } + #[inline] pub fn MATW(&self) -> U16 { unsafe { ::std::mem::transmute(self._bitfield_2.get(14usize, 2u8) as u16) } } @@ -229,6 +437,31 @@ impl V56AMDY { } } #[inline] + pub unsafe fn MATW_raw(this: *const Self) -> U16 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 3usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_2), 14usize, 2u8) + as u16, + ) + } + } + #[inline] + pub unsafe fn set_MATW_raw(this: *mut Self, val: U16) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 3usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_2), + 14usize, + 2u8, + val as u64, + ) + } + } + #[inline] pub fn MASW(&self) -> U8 { unsafe { ::std::mem::transmute(self._bitfield_2.get(16usize, 4u8) as u8) } } @@ -240,6 +473,31 @@ impl V56AMDY { } } #[inline] + pub unsafe fn MASW_raw(this: *const Self) -> U8 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 3usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_2), 16usize, 4u8) + as u8, + ) + } + } + #[inline] + pub unsafe fn set_MASW_raw(this: *mut Self, val: U8) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 3usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_2), + 16usize, + 4u8, + val as u64, + ) + } + } + #[inline] pub fn MABW(&self) -> U8 { unsafe { ::std::mem::transmute(self._bitfield_2.get(20usize, 3u8) as u8) } } @@ -251,6 +509,31 @@ impl V56AMDY { } } #[inline] + pub unsafe fn MABW_raw(this: *const Self) -> U8 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 3usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_2), 20usize, 3u8) + as u8, + ) + } + } + #[inline] + pub unsafe fn set_MABW_raw(this: *mut Self, val: U8) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 3usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_2), + 20usize, + 3u8, + val as u64, + ) + } + } + #[inline] pub fn MAXN(&self) -> U8 { unsafe { ::std::mem::transmute(self._bitfield_2.get(23usize, 1u8) as u8) } } @@ -262,6 +545,31 @@ impl V56AMDY { } } #[inline] + pub unsafe fn MAXN_raw(this: *const Self) -> U8 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 3usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_2), 23usize, 1u8) + as u8, + ) + } + } + #[inline] + pub unsafe fn set_MAXN_raw(this: *mut Self, val: U8) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 3usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_2), + 23usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn new_bitfield_2( MATH: U16, MATE: U16, diff --git a/bindgen-tests/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs b/bindgen-tests/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs index 84dc763e6f..7fbc89b21c 100644 --- a/bindgen-tests/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs @@ -16,10 +16,7 @@ where Storage: AsRef<[u8]> + AsMut<[u8]>, { #[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]; + fn extract_bit(byte: u8, index: usize) -> bool { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) } else { @@ -29,21 +26,44 @@ where byte & mask == mask } #[inline] - pub fn set_bit(&mut self, index: usize, val: bool) { + pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); let byte_index = index / 8; - let byte = &mut self.storage.as_mut()[byte_index]; + 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 = *(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; - } + 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize); + *byte = Self::change_bit(*byte, index, val); } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -66,6 +86,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 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()); @@ -83,6 +123,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 + }; + Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + } + } } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -108,6 +166,31 @@ impl Foo { } } #[inline] + pub unsafe fn m_bitfield_raw(this: *const Self) -> ::std::os::raw::c_ulong { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 32usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 64u8) + as u64, + ) + } + } + #[inline] + pub unsafe fn set_m_bitfield_raw(this: *mut Self, val: ::std::os::raw::c_ulong) { + unsafe { + let val: u64 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 32usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 0usize, + 64u8, + val as u64, + ) + } + } + #[inline] pub fn m_bar(&self) -> ::std::os::raw::c_ulong { unsafe { ::std::mem::transmute(self._bitfield_1.get(64usize, 64u8) as u64) } } @@ -119,6 +202,31 @@ impl Foo { } } #[inline] + pub unsafe fn m_bar_raw(this: *const Self) -> ::std::os::raw::c_ulong { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 32usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 64usize, 64u8) + as u64, + ) + } + } + #[inline] + pub unsafe fn set_m_bar_raw(this: *mut Self, val: ::std::os::raw::c_ulong) { + unsafe { + let val: u64 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 32usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 64usize, + 64u8, + val as u64, + ) + } + } + #[inline] pub fn foo(&self) -> ::std::os::raw::c_ulong { unsafe { ::std::mem::transmute(self._bitfield_1.get(128usize, 1u8) as u64) } } @@ -130,6 +238,31 @@ impl Foo { } } #[inline] + pub unsafe fn foo_raw(this: *const Self) -> ::std::os::raw::c_ulong { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 32usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 128usize, 1u8) + as u64, + ) + } + } + #[inline] + pub unsafe fn set_foo_raw(this: *mut Self, val: ::std::os::raw::c_ulong) { + unsafe { + let val: u64 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 32usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 128usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn bar(&self) -> ::std::os::raw::c_ulong { unsafe { ::std::mem::transmute(self._bitfield_1.get(192usize, 64u8) as u64) } } @@ -141,6 +274,31 @@ impl Foo { } } #[inline] + pub unsafe fn bar_raw(this: *const Self) -> ::std::os::raw::c_ulong { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 32usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 192usize, 64u8) + as u64, + ) + } + } + #[inline] + pub unsafe fn set_bar_raw(this: *mut Self, val: ::std::os::raw::c_ulong) { + unsafe { + let val: u64 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 32usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 192usize, + 64u8, + val as u64, + ) + } + } + #[inline] pub fn new_bitfield_1( m_bitfield: ::std::os::raw::c_ulong, m_bar: ::std::os::raw::c_ulong, diff --git a/bindgen-tests/tests/expectations/tests/issue-816.rs b/bindgen-tests/tests/expectations/tests/issue-816.rs index 1f1112eff5..9ee600fd74 100644 --- a/bindgen-tests/tests/expectations/tests/issue-816.rs +++ b/bindgen-tests/tests/expectations/tests/issue-816.rs @@ -15,10 +15,7 @@ where Storage: AsRef<[u8]> + AsMut<[u8]>, { #[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]; + fn extract_bit(byte: u8, index: usize) -> bool { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) } else { @@ -28,21 +25,44 @@ where byte & mask == mask } #[inline] - pub fn set_bit(&mut self, index: usize, val: bool) { + pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); let byte_index = index / 8; - let byte = &mut self.storage.as_mut()[byte_index]; + 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 = *(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; - } + 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize); + *byte = Self::change_bit(*byte, index, val); } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -65,6 +85,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 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()); @@ -82,6 +122,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 + }; + Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + } + } } #[repr(C)] #[repr(align(4))] @@ -108,6 +166,31 @@ impl capabilities { } } #[inline] + pub unsafe fn bit_1_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_bit_1_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 0usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn bit_2(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u32) } } @@ -119,6 +202,31 @@ impl capabilities { } } #[inline] + pub unsafe fn bit_2_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 1usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_bit_2_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 1usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn bit_3(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u32) } } @@ -130,6 +238,31 @@ impl capabilities { } } #[inline] + pub unsafe fn bit_3_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 2usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_bit_3_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 2usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn bit_4(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(3usize, 1u8) as u32) } } @@ -141,6 +274,31 @@ impl capabilities { } } #[inline] + pub unsafe fn bit_4_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 3usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_bit_4_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 3usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn bit_5(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(4usize, 1u8) as u32) } } @@ -152,6 +310,31 @@ impl capabilities { } } #[inline] + pub unsafe fn bit_5_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 4usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_bit_5_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 4usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn bit_6(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(5usize, 1u8) as u32) } } @@ -163,6 +346,31 @@ impl capabilities { } } #[inline] + pub unsafe fn bit_6_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 5usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_bit_6_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 5usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn bit_7(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(6usize, 1u8) as u32) } } @@ -174,6 +382,31 @@ impl capabilities { } } #[inline] + pub unsafe fn bit_7_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 6usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_bit_7_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 6usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn bit_8(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(7usize, 1u8) as u32) } } @@ -185,6 +418,31 @@ impl capabilities { } } #[inline] + pub unsafe fn bit_8_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 7usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_bit_8_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 7usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn bit_9(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(8usize, 1u8) as u32) } } @@ -196,6 +454,31 @@ impl capabilities { } } #[inline] + pub unsafe fn bit_9_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 8usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_bit_9_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 8usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn bit_10(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(9usize, 1u8) as u32) } } @@ -207,6 +490,31 @@ impl capabilities { } } #[inline] + pub unsafe fn bit_10_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 9usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_bit_10_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 9usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn bit_11(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(10usize, 1u8) as u32) } } @@ -218,6 +526,31 @@ impl capabilities { } } #[inline] + pub unsafe fn bit_11_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 10usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_bit_11_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 10usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn bit_12(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(11usize, 1u8) as u32) } } @@ -229,6 +562,31 @@ impl capabilities { } } #[inline] + pub unsafe fn bit_12_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 11usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_bit_12_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 11usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn bit_13(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(12usize, 1u8) as u32) } } @@ -240,6 +598,31 @@ impl capabilities { } } #[inline] + pub unsafe fn bit_13_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 12usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_bit_13_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 12usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn bit_14(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(13usize, 1u8) as u32) } } @@ -251,6 +634,31 @@ impl capabilities { } } #[inline] + pub unsafe fn bit_14_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 13usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_bit_14_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 13usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn bit_15(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(14usize, 1u8) as u32) } } @@ -262,6 +670,31 @@ impl capabilities { } } #[inline] + pub unsafe fn bit_15_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 14usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_bit_15_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 14usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn bit_16(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(15usize, 1u8) as u32) } } @@ -273,6 +706,31 @@ impl capabilities { } } #[inline] + pub unsafe fn bit_16_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 15usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_bit_16_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 15usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn bit_17(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(16usize, 1u8) as u32) } } @@ -284,6 +742,31 @@ impl capabilities { } } #[inline] + pub unsafe fn bit_17_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 16usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_bit_17_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 16usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn bit_18(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(17usize, 1u8) as u32) } } @@ -295,6 +778,31 @@ impl capabilities { } } #[inline] + pub unsafe fn bit_18_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 17usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_bit_18_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 17usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn bit_19(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(18usize, 1u8) as u32) } } @@ -306,6 +814,31 @@ impl capabilities { } } #[inline] + pub unsafe fn bit_19_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 18usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_bit_19_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 18usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn bit_20(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(19usize, 1u8) as u32) } } @@ -317,6 +850,31 @@ impl capabilities { } } #[inline] + pub unsafe fn bit_20_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 19usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_bit_20_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 19usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn bit_21(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(20usize, 1u8) as u32) } } @@ -328,6 +886,31 @@ impl capabilities { } } #[inline] + pub unsafe fn bit_21_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 20usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_bit_21_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 20usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn bit_22(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(21usize, 1u8) as u32) } } @@ -339,6 +922,31 @@ impl capabilities { } } #[inline] + pub unsafe fn bit_22_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 21usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_bit_22_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 21usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn bit_23(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(22usize, 1u8) as u32) } } @@ -350,6 +958,31 @@ impl capabilities { } } #[inline] + pub unsafe fn bit_23_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 22usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_bit_23_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 22usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn bit_24(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(23usize, 1u8) as u32) } } @@ -361,6 +994,31 @@ impl capabilities { } } #[inline] + pub unsafe fn bit_24_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 23usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_bit_24_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 23usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn bit_25(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(24usize, 1u8) as u32) } } @@ -372,6 +1030,31 @@ impl capabilities { } } #[inline] + pub unsafe fn bit_25_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 24usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_bit_25_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 24usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn bit_26(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(25usize, 1u8) as u32) } } @@ -383,6 +1066,31 @@ impl capabilities { } } #[inline] + pub unsafe fn bit_26_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 25usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_bit_26_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 25usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn bit_27(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(26usize, 1u8) as u32) } } @@ -394,6 +1102,31 @@ impl capabilities { } } #[inline] + pub unsafe fn bit_27_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 26usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_bit_27_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 26usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn bit_28(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(27usize, 1u8) as u32) } } @@ -405,6 +1138,31 @@ impl capabilities { } } #[inline] + pub unsafe fn bit_28_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 27usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_bit_28_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 27usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn bit_29(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(28usize, 1u8) as u32) } } @@ -416,6 +1174,31 @@ impl capabilities { } } #[inline] + pub unsafe fn bit_29_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 28usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_bit_29_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 28usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn bit_30(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(29usize, 1u8) as u32) } } @@ -427,6 +1210,31 @@ impl capabilities { } } #[inline] + pub unsafe fn bit_30_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 29usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_bit_30_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 29usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn bit_31(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(30usize, 1u8) as u32) } } @@ -438,6 +1246,31 @@ impl capabilities { } } #[inline] + pub unsafe fn bit_31_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 30usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_bit_31_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 30usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn bit_32(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(31usize, 1u8) as u32) } } @@ -449,6 +1282,31 @@ impl capabilities { } } #[inline] + pub unsafe fn bit_32_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 31usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_bit_32_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 31usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn bit_33(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(32usize, 1u8) as u32) } } @@ -460,6 +1318,31 @@ impl capabilities { } } #[inline] + pub unsafe fn bit_33_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 32usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_bit_33_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 32usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn bit_34(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(33usize, 1u8) as u32) } } @@ -471,6 +1354,31 @@ impl capabilities { } } #[inline] + pub unsafe fn bit_34_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 33usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_bit_34_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 33usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn bit_35(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(34usize, 1u8) as u32) } } @@ -482,6 +1390,31 @@ impl capabilities { } } #[inline] + pub unsafe fn bit_35_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 34usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_bit_35_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 34usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn bit_36(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(35usize, 1u8) as u32) } } @@ -493,6 +1426,31 @@ impl capabilities { } } #[inline] + pub unsafe fn bit_36_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 35usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_bit_36_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 35usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn bit_37(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(36usize, 1u8) as u32) } } @@ -504,6 +1462,31 @@ impl capabilities { } } #[inline] + pub unsafe fn bit_37_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 36usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_bit_37_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 36usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn bit_38(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(37usize, 1u8) as u32) } } @@ -515,6 +1498,31 @@ impl capabilities { } } #[inline] + pub unsafe fn bit_38_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 37usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_bit_38_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 37usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn bit_39(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(38usize, 1u8) as u32) } } @@ -526,6 +1534,31 @@ impl capabilities { } } #[inline] + pub unsafe fn bit_39_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 38usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_bit_39_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 38usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn bit_40(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(39usize, 1u8) as u32) } } @@ -537,6 +1570,31 @@ impl capabilities { } } #[inline] + pub unsafe fn bit_40_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 39usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_bit_40_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 39usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn bit_41(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(40usize, 1u8) as u32) } } @@ -548,6 +1606,31 @@ impl capabilities { } } #[inline] + pub unsafe fn bit_41_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 40usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_bit_41_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 16usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 40usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn new_bitfield_1( bit_1: ::std::os::raw::c_uint, bit_2: ::std::os::raw::c_uint, diff --git a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs index e7cb9af39e..c8f406db19 100644 --- a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs +++ b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs @@ -15,10 +15,7 @@ where Storage: AsRef<[u8]> + AsMut<[u8]>, { #[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]; + fn extract_bit(byte: u8, index: usize) -> bool { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) } else { @@ -28,21 +25,44 @@ where byte & mask == mask } #[inline] - pub fn set_bit(&mut self, index: usize, val: bool) { + pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); let byte_index = index / 8; - let byte = &mut self.storage.as_mut()[byte_index]; + 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 = *(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; - } + 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize); + *byte = Self::change_bit(*byte, index, val); } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -65,6 +85,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 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()); @@ -82,6 +122,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 + }; + Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + } + } } pub const JSVAL_TAG_SHIFT: u32 = 47; pub const JSVAL_PAYLOAD_MASK: u64 = 140737488355327; @@ -217,6 +275,31 @@ impl jsval_layout__bindgen_ty_1 { } } #[inline] + pub unsafe fn payload47_raw(this: *const Self) -> u64 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 8usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 47u8) + as u64, + ) + } + } + #[inline] + pub unsafe fn set_payload47_raw(this: *mut Self, val: u64) { + unsafe { + let val: u64 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 8usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 0usize, + 47u8, + val as u64, + ) + } + } + #[inline] pub fn tag(&self) -> JSValueTag { unsafe { ::std::mem::transmute(self._bitfield_1.get(47usize, 17u8) as u32) } } @@ -228,6 +311,31 @@ impl jsval_layout__bindgen_ty_1 { } } #[inline] + pub unsafe fn tag_raw(this: *const Self) -> JSValueTag { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 8usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 47usize, 17u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_tag_raw(this: *mut Self, val: JSValueTag) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 8usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 47usize, + 17u8, + val as u64, + ) + } + } + #[inline] pub fn new_bitfield_1( payload47: u64, tag: JSValueTag, diff --git a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs index 7ae53bc40f..5da0e7995f 100644 --- a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs @@ -15,10 +15,7 @@ where Storage: AsRef<[u8]> + AsMut<[u8]>, { #[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]; + fn extract_bit(byte: u8, index: usize) -> bool { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) } else { @@ -28,21 +25,44 @@ where byte & mask == mask } #[inline] - pub fn set_bit(&mut self, index: usize, val: bool) { + pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); let byte_index = index / 8; - let byte = &mut self.storage.as_mut()[byte_index]; + 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 = *(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; - } + 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize); + *byte = Self::change_bit(*byte, index, val); } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -65,6 +85,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 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()); @@ -82,6 +122,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 + }; + Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + } + } } #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); @@ -270,6 +328,31 @@ impl jsval_layout__bindgen_ty_1 { } } #[inline] + pub unsafe fn payload47_raw(this: *const Self) -> u64 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 8usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 47u8) + as u64, + ) + } + } + #[inline] + pub unsafe fn set_payload47_raw(this: *mut Self, val: u64) { + unsafe { + let val: u64 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 8usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 0usize, + 47u8, + val as u64, + ) + } + } + #[inline] pub fn tag(&self) -> JSValueTag { unsafe { ::std::mem::transmute(self._bitfield_1.get(47usize, 17u8) as u32) } } @@ -281,6 +364,31 @@ impl jsval_layout__bindgen_ty_1 { } } #[inline] + pub unsafe fn tag_raw(this: *const Self) -> JSValueTag { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 8usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 47usize, 17u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_tag_raw(this: *mut Self, val: JSValueTag) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 8usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 47usize, + 17u8, + val as u64, + ) + } + } + #[inline] pub fn new_bitfield_1( payload47: u64, tag: JSValueTag, diff --git a/bindgen-tests/tests/expectations/tests/layout_align.rs b/bindgen-tests/tests/expectations/tests/layout_align.rs index c641ff843f..906c26d57e 100644 --- a/bindgen-tests/tests/expectations/tests/layout_align.rs +++ b/bindgen-tests/tests/expectations/tests/layout_align.rs @@ -15,10 +15,7 @@ where Storage: AsRef<[u8]> + AsMut<[u8]>, { #[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]; + fn extract_bit(byte: u8, index: usize) -> bool { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) } else { @@ -28,21 +25,44 @@ where byte & mask == mask } #[inline] - pub fn set_bit(&mut self, index: usize, val: bool) { + pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); let byte_index = index / 8; - let byte = &mut self.storage.as_mut()[byte_index]; + 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 = *(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; - } + 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize); + *byte = Self::change_bit(*byte, index, val); } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -65,6 +85,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 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()); @@ -82,6 +122,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 + }; + Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + } + } } #[repr(C)] #[derive(Default)] @@ -187,6 +245,31 @@ impl rte_eth_link { } } #[inline] + pub unsafe fn link_duplex_raw(this: *const Self) -> u16 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 1u8) + as u16, + ) + } + } + #[inline] + pub unsafe fn set_link_duplex_raw(this: *mut Self, val: u16) { + unsafe { + let val: u16 = ::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 link_autoneg(&self) -> u16 { unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u16) } } @@ -198,6 +281,31 @@ impl rte_eth_link { } } #[inline] + pub unsafe fn link_autoneg_raw(this: *const Self) -> u16 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 1usize, 1u8) + as u16, + ) + } + } + #[inline] + pub unsafe fn set_link_autoneg_raw(this: *mut Self, val: u16) { + unsafe { + let val: u16 = ::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 link_status(&self) -> u16 { unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u16) } } @@ -209,6 +317,31 @@ impl rte_eth_link { } } #[inline] + pub unsafe fn link_status_raw(this: *const Self) -> u16 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 2usize, 1u8) + as u16, + ) + } + } + #[inline] + pub unsafe fn set_link_status_raw(this: *mut Self, val: u16) { + unsafe { + let val: u16 = ::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( link_duplex: u16, link_autoneg: u16, diff --git a/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs b/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs index 9b98bac376..d9d30e1d88 100644 --- a/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs +++ b/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs @@ -15,10 +15,7 @@ where Storage: AsRef<[u8]> + AsMut<[u8]>, { #[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]; + fn extract_bit(byte: u8, index: usize) -> bool { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) } else { @@ -28,21 +25,44 @@ where byte & mask == mask } #[inline] - pub fn set_bit(&mut self, index: usize, val: bool) { + pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); let byte_index = index / 8; - let byte = &mut self.storage.as_mut()[byte_index]; + 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 = *(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; - } + 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize); + *byte = Self::change_bit(*byte, index, val); } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -65,6 +85,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 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()); @@ -82,6 +122,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 + }; + 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; @@ -202,6 +260,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) } } @@ -213,6 +296,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) } } @@ -224,6 +332,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) } } @@ -235,6 +368,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) } } @@ -246,6 +404,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) } } @@ -257,6 +440,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) } } @@ -268,6 +476,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) } } @@ -279,6 +512,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) } } @@ -290,6 +548,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, @@ -472,6 +755,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) } } @@ -483,6 +790,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) } } @@ -494,6 +825,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, diff --git a/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs b/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs index 34688b20b3..c5ccdd0959 100644 --- a/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs @@ -15,10 +15,7 @@ where Storage: AsRef<[u8]> + AsMut<[u8]>, { #[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]; + fn extract_bit(byte: u8, index: usize) -> bool { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) } else { @@ -28,21 +25,44 @@ where byte & mask == mask } #[inline] - pub fn set_bit(&mut self, index: usize, val: bool) { + pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); let byte_index = index / 8; - let byte = &mut self.storage.as_mut()[byte_index]; + 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 = *(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; - } + 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize); + *byte = Self::change_bit(*byte, index, val); } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -65,6 +85,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 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()); @@ -82,6 +122,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 + }; + Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + } + } } #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); @@ -250,6 +308,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) } } @@ -261,6 +344,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) } } @@ -272,6 +380,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) } } @@ -283,6 +416,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) } } @@ -294,6 +452,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) } } @@ -305,6 +488,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) } } @@ -316,6 +524,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) } } @@ -327,6 +560,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) } } @@ -338,6 +596,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, @@ -525,6 +808,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) } } @@ -536,6 +843,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) } } @@ -547,6 +878,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, diff --git a/bindgen-tests/tests/expectations/tests/layout_mbuf.rs b/bindgen-tests/tests/expectations/tests/layout_mbuf.rs index aa2c121c2d..47ea51d2c2 100644 --- a/bindgen-tests/tests/expectations/tests/layout_mbuf.rs +++ b/bindgen-tests/tests/expectations/tests/layout_mbuf.rs @@ -15,10 +15,7 @@ where Storage: AsRef<[u8]> + AsMut<[u8]>, { #[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]; + fn extract_bit(byte: u8, index: usize) -> bool { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) } else { @@ -28,21 +25,44 @@ where byte & mask == mask } #[inline] - pub fn set_bit(&mut self, index: usize, val: bool) { + pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); let byte_index = index / 8; - let byte = &mut self.storage.as_mut()[byte_index]; + 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 = *(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; - } + 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize); + *byte = Self::change_bit(*byte, index, val); } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -65,6 +85,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 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()); @@ -82,6 +122,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 + }; + Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + } + } } pub const RTE_CACHE_LINE_MIN_SIZE: u32 = 64; pub const RTE_CACHE_LINE_SIZE: u32 = 64; @@ -225,6 +283,31 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } } #[inline] + pub unsafe fn l2_type_raw(this: *const Self) -> u32 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 4u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_l2_type_raw(this: *mut Self, val: u32) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 0usize, + 4u8, + val as u64, + ) + } + } + #[inline] pub fn l3_type(&self) -> u32 { unsafe { ::std::mem::transmute(self._bitfield_1.get(4usize, 4u8) as u32) } } @@ -236,6 +319,31 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } } #[inline] + pub unsafe fn l3_type_raw(this: *const Self) -> u32 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 4usize, 4u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_l3_type_raw(this: *mut Self, val: u32) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 4usize, + 4u8, + val as u64, + ) + } + } + #[inline] pub fn l4_type(&self) -> u32 { unsafe { ::std::mem::transmute(self._bitfield_1.get(8usize, 4u8) as u32) } } @@ -247,6 +355,31 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } } #[inline] + pub unsafe fn l4_type_raw(this: *const Self) -> u32 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 8usize, 4u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_l4_type_raw(this: *mut Self, val: u32) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 8usize, + 4u8, + val as u64, + ) + } + } + #[inline] pub fn tun_type(&self) -> u32 { unsafe { ::std::mem::transmute(self._bitfield_1.get(12usize, 4u8) as u32) } } @@ -258,6 +391,31 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } } #[inline] + pub unsafe fn tun_type_raw(this: *const Self) -> u32 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 12usize, 4u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_tun_type_raw(this: *mut Self, val: u32) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 12usize, + 4u8, + val as u64, + ) + } + } + #[inline] pub fn inner_l2_type(&self) -> u32 { unsafe { ::std::mem::transmute(self._bitfield_1.get(16usize, 4u8) as u32) } } @@ -269,6 +427,31 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } } #[inline] + pub unsafe fn inner_l2_type_raw(this: *const Self) -> u32 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 16usize, 4u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_inner_l2_type_raw(this: *mut Self, val: u32) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 16usize, + 4u8, + val as u64, + ) + } + } + #[inline] pub fn inner_l3_type(&self) -> u32 { unsafe { ::std::mem::transmute(self._bitfield_1.get(20usize, 4u8) as u32) } } @@ -280,6 +463,31 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } } #[inline] + pub unsafe fn inner_l3_type_raw(this: *const Self) -> u32 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 20usize, 4u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_inner_l3_type_raw(this: *mut Self, val: u32) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 20usize, + 4u8, + val as u64, + ) + } + } + #[inline] pub fn inner_l4_type(&self) -> u32 { unsafe { ::std::mem::transmute(self._bitfield_1.get(24usize, 4u8) as u32) } } @@ -291,6 +499,31 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } } #[inline] + pub unsafe fn inner_l4_type_raw(this: *const Self) -> u32 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 24usize, 4u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_inner_l4_type_raw(this: *mut Self, val: u32) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 24usize, + 4u8, + val as u64, + ) + } + } + #[inline] pub fn new_bitfield_1( l2_type: u32, l3_type: u32, @@ -611,6 +844,31 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { } } #[inline] + pub unsafe fn l2_len_raw(this: *const Self) -> u64 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 7usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 7u8) + as u64, + ) + } + } + #[inline] + pub unsafe fn set_l2_len_raw(this: *mut Self, val: u64) { + unsafe { + let val: u64 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 7usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 0usize, + 7u8, + val as u64, + ) + } + } + #[inline] pub fn l3_len(&self) -> u64 { unsafe { ::std::mem::transmute(self._bitfield_1.get(7usize, 9u8) as u64) } } @@ -622,6 +880,31 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { } } #[inline] + pub unsafe fn l3_len_raw(this: *const Self) -> u64 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 7usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 7usize, 9u8) + as u64, + ) + } + } + #[inline] + pub unsafe fn set_l3_len_raw(this: *mut Self, val: u64) { + unsafe { + let val: u64 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 7usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 7usize, + 9u8, + val as u64, + ) + } + } + #[inline] pub fn l4_len(&self) -> u64 { unsafe { ::std::mem::transmute(self._bitfield_1.get(16usize, 8u8) as u64) } } @@ -633,6 +916,31 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { } } #[inline] + pub unsafe fn l4_len_raw(this: *const Self) -> u64 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 7usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 16usize, 8u8) + as u64, + ) + } + } + #[inline] + pub unsafe fn set_l4_len_raw(this: *mut Self, val: u64) { + unsafe { + let val: u64 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 7usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 16usize, + 8u8, + val as u64, + ) + } + } + #[inline] pub fn tso_segsz(&self) -> u64 { unsafe { ::std::mem::transmute(self._bitfield_1.get(24usize, 16u8) as u64) } } @@ -644,6 +952,31 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { } } #[inline] + pub unsafe fn tso_segsz_raw(this: *const Self) -> u64 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 7usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 24usize, 16u8) + as u64, + ) + } + } + #[inline] + pub unsafe fn set_tso_segsz_raw(this: *mut Self, val: u64) { + unsafe { + let val: u64 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 7usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 24usize, + 16u8, + val as u64, + ) + } + } + #[inline] pub fn outer_l3_len(&self) -> u64 { unsafe { ::std::mem::transmute(self._bitfield_1.get(40usize, 9u8) as u64) } } @@ -655,6 +988,31 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { } } #[inline] + pub unsafe fn outer_l3_len_raw(this: *const Self) -> u64 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 7usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 40usize, 9u8) + as u64, + ) + } + } + #[inline] + pub unsafe fn set_outer_l3_len_raw(this: *mut Self, val: u64) { + unsafe { + let val: u64 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 7usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 40usize, + 9u8, + val as u64, + ) + } + } + #[inline] pub fn outer_l2_len(&self) -> u64 { unsafe { ::std::mem::transmute(self._bitfield_1.get(49usize, 7u8) as u64) } } @@ -666,6 +1024,31 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { } } #[inline] + pub unsafe fn outer_l2_len_raw(this: *const Self) -> u64 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 7usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 49usize, 7u8) + as u64, + ) + } + } + #[inline] + pub unsafe fn set_outer_l2_len_raw(this: *mut Self, val: u64) { + unsafe { + let val: u64 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 7usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 49usize, + 7u8, + val as u64, + ) + } + } + #[inline] pub fn new_bitfield_1( l2_len: u64, l3_len: u64, diff --git a/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs b/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs index 19394d271f..db4f078aad 100644 --- a/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs @@ -15,10 +15,7 @@ where Storage: AsRef<[u8]> + AsMut<[u8]>, { #[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]; + fn extract_bit(byte: u8, index: usize) -> bool { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) } else { @@ -28,21 +25,44 @@ where byte & mask == mask } #[inline] - pub fn set_bit(&mut self, index: usize, val: bool) { + pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); let byte_index = index / 8; - let byte = &mut self.storage.as_mut()[byte_index]; + 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 = *(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; - } + 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize); + *byte = Self::change_bit(*byte, index, val); } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -65,6 +85,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 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()); @@ -82,6 +122,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 + }; + Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + } + } } #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); @@ -302,6 +360,31 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } } #[inline] + pub unsafe fn l2_type_raw(this: *const Self) -> u32 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 4u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_l2_type_raw(this: *mut Self, val: u32) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 0usize, + 4u8, + val as u64, + ) + } + } + #[inline] pub fn l3_type(&self) -> u32 { unsafe { ::std::mem::transmute(self._bitfield_1.get(4usize, 4u8) as u32) } } @@ -313,6 +396,31 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } } #[inline] + pub unsafe fn l3_type_raw(this: *const Self) -> u32 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 4usize, 4u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_l3_type_raw(this: *mut Self, val: u32) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 4usize, + 4u8, + val as u64, + ) + } + } + #[inline] pub fn l4_type(&self) -> u32 { unsafe { ::std::mem::transmute(self._bitfield_1.get(8usize, 4u8) as u32) } } @@ -324,6 +432,31 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } } #[inline] + pub unsafe fn l4_type_raw(this: *const Self) -> u32 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 8usize, 4u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_l4_type_raw(this: *mut Self, val: u32) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 8usize, + 4u8, + val as u64, + ) + } + } + #[inline] pub fn tun_type(&self) -> u32 { unsafe { ::std::mem::transmute(self._bitfield_1.get(12usize, 4u8) as u32) } } @@ -335,6 +468,31 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } } #[inline] + pub unsafe fn tun_type_raw(this: *const Self) -> u32 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 12usize, 4u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_tun_type_raw(this: *mut Self, val: u32) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 12usize, + 4u8, + val as u64, + ) + } + } + #[inline] pub fn inner_l2_type(&self) -> u32 { unsafe { ::std::mem::transmute(self._bitfield_1.get(16usize, 4u8) as u32) } } @@ -346,6 +504,31 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } } #[inline] + pub unsafe fn inner_l2_type_raw(this: *const Self) -> u32 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 16usize, 4u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_inner_l2_type_raw(this: *mut Self, val: u32) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 16usize, + 4u8, + val as u64, + ) + } + } + #[inline] pub fn inner_l3_type(&self) -> u32 { unsafe { ::std::mem::transmute(self._bitfield_1.get(20usize, 4u8) as u32) } } @@ -357,6 +540,31 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } } #[inline] + pub unsafe fn inner_l3_type_raw(this: *const Self) -> u32 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 20usize, 4u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_inner_l3_type_raw(this: *mut Self, val: u32) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 20usize, + 4u8, + val as u64, + ) + } + } + #[inline] pub fn inner_l4_type(&self) -> u32 { unsafe { ::std::mem::transmute(self._bitfield_1.get(24usize, 4u8) as u32) } } @@ -368,6 +576,31 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } } #[inline] + pub unsafe fn inner_l4_type_raw(this: *const Self) -> u32 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 24usize, 4u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_inner_l4_type_raw(this: *mut Self, val: u32) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 24usize, + 4u8, + val as u64, + ) + } + } + #[inline] pub fn new_bitfield_1( l2_type: u32, l3_type: u32, @@ -758,6 +991,31 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { } } #[inline] + pub unsafe fn l2_len_raw(this: *const Self) -> u64 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 7usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 7u8) + as u64, + ) + } + } + #[inline] + pub unsafe fn set_l2_len_raw(this: *mut Self, val: u64) { + unsafe { + let val: u64 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 7usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 0usize, + 7u8, + val as u64, + ) + } + } + #[inline] pub fn l3_len(&self) -> u64 { unsafe { ::std::mem::transmute(self._bitfield_1.get(7usize, 9u8) as u64) } } @@ -769,6 +1027,31 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { } } #[inline] + pub unsafe fn l3_len_raw(this: *const Self) -> u64 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 7usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 7usize, 9u8) + as u64, + ) + } + } + #[inline] + pub unsafe fn set_l3_len_raw(this: *mut Self, val: u64) { + unsafe { + let val: u64 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 7usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 7usize, + 9u8, + val as u64, + ) + } + } + #[inline] pub fn l4_len(&self) -> u64 { unsafe { ::std::mem::transmute(self._bitfield_1.get(16usize, 8u8) as u64) } } @@ -780,6 +1063,31 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { } } #[inline] + pub unsafe fn l4_len_raw(this: *const Self) -> u64 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 7usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 16usize, 8u8) + as u64, + ) + } + } + #[inline] + pub unsafe fn set_l4_len_raw(this: *mut Self, val: u64) { + unsafe { + let val: u64 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 7usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 16usize, + 8u8, + val as u64, + ) + } + } + #[inline] pub fn tso_segsz(&self) -> u64 { unsafe { ::std::mem::transmute(self._bitfield_1.get(24usize, 16u8) as u64) } } @@ -791,6 +1099,31 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { } } #[inline] + pub unsafe fn tso_segsz_raw(this: *const Self) -> u64 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 7usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 24usize, 16u8) + as u64, + ) + } + } + #[inline] + pub unsafe fn set_tso_segsz_raw(this: *mut Self, val: u64) { + unsafe { + let val: u64 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 7usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 24usize, + 16u8, + val as u64, + ) + } + } + #[inline] pub fn outer_l3_len(&self) -> u64 { unsafe { ::std::mem::transmute(self._bitfield_1.get(40usize, 9u8) as u64) } } @@ -802,6 +1135,31 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { } } #[inline] + pub unsafe fn outer_l3_len_raw(this: *const Self) -> u64 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 7usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 40usize, 9u8) + as u64, + ) + } + } + #[inline] + pub unsafe fn set_outer_l3_len_raw(this: *mut Self, val: u64) { + unsafe { + let val: u64 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 7usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 40usize, + 9u8, + val as u64, + ) + } + } + #[inline] pub fn outer_l2_len(&self) -> u64 { unsafe { ::std::mem::transmute(self._bitfield_1.get(49usize, 7u8) as u64) } } @@ -813,6 +1171,31 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { } } #[inline] + pub unsafe fn outer_l2_len_raw(this: *const Self) -> u64 { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 7usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 49usize, 7u8) + as u64, + ) + } + } + #[inline] + pub unsafe fn set_outer_l2_len_raw(this: *mut Self, val: u64) { + unsafe { + let val: u64 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 7usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 49usize, + 7u8, + val as u64, + ) + } + } + #[inline] pub fn new_bitfield_1( l2_len: u64, l3_len: u64, diff --git a/bindgen-tests/tests/expectations/tests/only_bitfields.rs b/bindgen-tests/tests/expectations/tests/only_bitfields.rs index 5cd01b4485..fe317dc126 100644 --- a/bindgen-tests/tests/expectations/tests/only_bitfields.rs +++ b/bindgen-tests/tests/expectations/tests/only_bitfields.rs @@ -15,10 +15,7 @@ where Storage: AsRef<[u8]> + AsMut<[u8]>, { #[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]; + fn extract_bit(byte: u8, index: usize) -> bool { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) } else { @@ -28,21 +25,44 @@ where byte & mask == mask } #[inline] - pub fn set_bit(&mut self, index: usize, val: bool) { + pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); let byte_index = index / 8; - let byte = &mut self.storage.as_mut()[byte_index]; + 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 = *(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; - } + 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize); + *byte = Self::change_bit(*byte, index, val); } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -65,6 +85,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 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()); @@ -82,6 +122,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 + }; + Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + } + } } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -107,6 +165,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) } } @@ -118,6 +200,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/packed-bitfield.rs b/bindgen-tests/tests/expectations/tests/packed-bitfield.rs index 852126ecfc..6aa59ec8a3 100644 --- a/bindgen-tests/tests/expectations/tests/packed-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/packed-bitfield.rs @@ -15,10 +15,7 @@ where Storage: AsRef<[u8]> + AsMut<[u8]>, { #[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]; + fn extract_bit(byte: u8, index: usize) -> bool { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) } else { @@ -28,21 +25,44 @@ where byte & mask == mask } #[inline] - pub fn set_bit(&mut self, index: usize, val: bool) { + pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); let byte_index = index / 8; - let byte = &mut self.storage.as_mut()[byte_index]; + 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 = *(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; - } + 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize); + *byte = Self::change_bit(*byte, index, val); } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -65,6 +85,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 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()); @@ -82,6 +122,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 + }; + Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + } + } } #[repr(C, packed)] #[derive(Debug, Default, Copy, Clone)] @@ -107,6 +165,30 @@ impl Date { } } #[inline] + pub unsafe fn day_raw(this: *const Self) -> ::std::os::raw::c_uchar { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 3usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 5u8) as u8, + ) + } + } + #[inline] + pub unsafe fn set_day_raw(this: *mut Self, val: ::std::os::raw::c_uchar) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 3usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 0usize, + 5u8, + val as u64, + ) + } + } + #[inline] pub fn month(&self) -> ::std::os::raw::c_uchar { unsafe { ::std::mem::transmute(self._bitfield_1.get(5usize, 4u8) as u8) } } @@ -118,6 +200,30 @@ impl Date { } } #[inline] + pub unsafe fn month_raw(this: *const Self) -> ::std::os::raw::c_uchar { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 3usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 5usize, 4u8) as u8, + ) + } + } + #[inline] + pub unsafe fn set_month_raw(this: *mut Self, val: ::std::os::raw::c_uchar) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 3usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 5usize, + 4u8, + val as u64, + ) + } + } + #[inline] pub fn year(&self) -> ::std::os::raw::c_short { unsafe { ::std::mem::transmute(self._bitfield_1.get(9usize, 15u8) as u16) } } @@ -129,6 +235,31 @@ impl Date { } } #[inline] + pub unsafe fn year_raw(this: *const Self) -> ::std::os::raw::c_short { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 3usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 9usize, 15u8) + as u16, + ) + } + } + #[inline] + pub unsafe fn set_year_raw(this: *mut Self, val: ::std::os::raw::c_short) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 3usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 9usize, + 15u8, + val as u64, + ) + } + } + #[inline] pub fn new_bitfield_1( day: ::std::os::raw::c_uchar, month: ::std::os::raw::c_uchar, diff --git a/bindgen-tests/tests/expectations/tests/private_fields.rs b/bindgen-tests/tests/expectations/tests/private_fields.rs index 5a7bee9508..0614b7417f 100644 --- a/bindgen-tests/tests/expectations/tests/private_fields.rs +++ b/bindgen-tests/tests/expectations/tests/private_fields.rs @@ -15,10 +15,7 @@ where Storage: AsRef<[u8]> + AsMut<[u8]>, { #[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]; + fn extract_bit(byte: u8, index: usize) -> bool { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) } else { @@ -28,21 +25,44 @@ where byte & mask == mask } #[inline] - pub fn set_bit(&mut self, index: usize, val: bool) { + pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); let byte_index = index / 8; - let byte = &mut self.storage.as_mut()[byte_index]; + 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 = *(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; - } + 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize); + *byte = Self::change_bit(*byte, index, val); } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -65,6 +85,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 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()); @@ -82,6 +122,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 + }; + Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + } + } } #[repr(C)] #[derive(Debug, Default, Copy, Clone)] @@ -124,6 +182,31 @@ impl PrivateBitFields { } } #[inline] + unsafe fn a_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 4u8) + as u32, + ) + } + } + #[inline] + unsafe fn set_a_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 0usize, + 4u8, + val as u64, + ) + } + } + #[inline] fn b(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(4usize, 4u8) as u32) } } @@ -135,6 +218,31 @@ impl PrivateBitFields { } } #[inline] + unsafe fn b_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 4usize, 4u8) + as u32, + ) + } + } + #[inline] + unsafe fn set_b_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 4usize, + 4u8, + val as u64, + ) + } + } + #[inline] fn new_bitfield_1( a: ::std::os::raw::c_uint, b: ::std::os::raw::c_uint, @@ -187,6 +295,31 @@ impl PublicBitFields { } } #[inline] + pub unsafe fn a_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 4u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_a_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 0usize, + 4u8, + val as u64, + ) + } + } + #[inline] pub fn b(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(4usize, 4u8) as u32) } } @@ -198,6 +331,31 @@ impl PublicBitFields { } } #[inline] + pub unsafe fn b_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 4usize, 4u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_b_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 4usize, + 4u8, + val as u64, + ) + } + } + #[inline] pub fn new_bitfield_1( a: ::std::os::raw::c_uint, b: ::std::os::raw::c_uint, @@ -250,6 +408,31 @@ impl MixedBitFields { } } #[inline] + unsafe fn a_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 4u8) + as u32, + ) + } + } + #[inline] + unsafe fn set_a_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 0usize, + 4u8, + val as u64, + ) + } + } + #[inline] pub fn d(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(4usize, 4u8) as u32) } } @@ -261,6 +444,31 @@ impl MixedBitFields { } } #[inline] + pub unsafe fn d_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 4usize, 4u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_d_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 4usize, + 4u8, + val as u64, + ) + } + } + #[inline] fn new_bitfield_1( a: ::std::os::raw::c_uint, d: ::std::os::raw::c_uint, @@ -443,6 +651,31 @@ impl Override { } } #[inline] + pub unsafe fn bf_a_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 4u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_bf_a_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 0usize, + 4u8, + val as u64, + ) + } + } + #[inline] fn bf_b(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(4usize, 4u8) as u32) } } @@ -454,6 +687,31 @@ impl Override { } } #[inline] + unsafe fn bf_b_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 4usize, 4u8) + as u32, + ) + } + } + #[inline] + unsafe fn set_bf_b_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 4usize, + 4u8, + val as u64, + ) + } + } + #[inline] fn private_bf_c(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(8usize, 4u8) as u32) } } @@ -465,6 +723,31 @@ impl Override { } } #[inline] + unsafe fn private_bf_c_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 8usize, 4u8) + as u32, + ) + } + } + #[inline] + unsafe fn set_private_bf_c_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 8usize, + 4u8, + val as u64, + ) + } + } + #[inline] fn new_bitfield_1( bf_a: ::std::os::raw::c_uint, bf_b: ::std::os::raw::c_uint, diff --git a/bindgen-tests/tests/expectations/tests/redundant-packed-and-align.rs b/bindgen-tests/tests/expectations/tests/redundant-packed-and-align.rs index 6e7db24870..43d88df698 100644 --- a/bindgen-tests/tests/expectations/tests/redundant-packed-and-align.rs +++ b/bindgen-tests/tests/expectations/tests/redundant-packed-and-align.rs @@ -15,10 +15,7 @@ where Storage: AsRef<[u8]> + AsMut<[u8]>, { #[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]; + fn extract_bit(byte: u8, index: usize) -> bool { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) } else { @@ -28,21 +25,44 @@ where byte & mask == mask } #[inline] - pub fn set_bit(&mut self, index: usize, val: bool) { + pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); let byte_index = index / 8; - let byte = &mut self.storage.as_mut()[byte_index]; + 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 = *(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; - } + 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize); + *byte = Self::change_bit(*byte, index, val); } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -65,6 +85,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 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()); @@ -82,6 +122,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 + }; + Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + } + } } #[repr(C)] #[repr(align(8))] @@ -140,6 +198,30 @@ impl redundant_packed_bitfield { } } #[inline] + pub unsafe fn b0_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_b0_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 b1(&self) -> u8 { unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u8) } } @@ -151,6 +233,30 @@ impl redundant_packed_bitfield { } } #[inline] + pub unsafe fn b1_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_b1_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 new_bitfield_1(b0: u8, b1: u8) -> __BindgenBitfieldUnit<[u8; 1usize]> { let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); __bindgen_bitfield_unit diff --git a/bindgen-tests/tests/expectations/tests/struct_with_bitfields.rs b/bindgen-tests/tests/expectations/tests/struct_with_bitfields.rs index fb21433415..3cdf6fce1c 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_bitfields.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_bitfields.rs @@ -15,10 +15,7 @@ where Storage: AsRef<[u8]> + AsMut<[u8]>, { #[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]; + fn extract_bit(byte: u8, index: usize) -> bool { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) } else { @@ -28,21 +25,44 @@ where byte & mask == mask } #[inline] - pub fn set_bit(&mut self, index: usize, val: bool) { + pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); let byte_index = index / 8; - let byte = &mut self.storage.as_mut()[byte_index]; + 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 = *(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; - } + 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize); + *byte = Self::change_bit(*byte, index, val); } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -65,6 +85,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 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()); @@ -82,6 +122,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 + }; + Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + } + } } #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] @@ -111,6 +169,31 @@ impl bitfield { } } #[inline] + pub unsafe fn a_raw(this: *const Self) -> ::std::os::raw::c_ushort { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 1u8) + as u16, + ) + } + } + #[inline] + pub unsafe fn set_a_raw(this: *mut Self, val: ::std::os::raw::c_ushort) { + unsafe { + let val: u16 = ::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) -> ::std::os::raw::c_ushort { unsafe { ::std::mem::transmute(self._bitfield_1.get(1usize, 1u8) as u16) } } @@ -122,6 +205,31 @@ impl bitfield { } } #[inline] + pub unsafe fn b_raw(this: *const Self) -> ::std::os::raw::c_ushort { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 1usize, 1u8) + as u16, + ) + } + } + #[inline] + pub unsafe fn set_b_raw(this: *mut Self, val: ::std::os::raw::c_ushort) { + unsafe { + let val: u16 = ::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 c(&self) -> ::std::os::raw::c_ushort { unsafe { ::std::mem::transmute(self._bitfield_1.get(2usize, 1u8) as u16) } } @@ -133,6 +241,31 @@ impl bitfield { } } #[inline] + pub unsafe fn c_raw(this: *const Self) -> ::std::os::raw::c_ushort { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 2usize, 1u8) + as u16, + ) + } + } + #[inline] + pub unsafe fn set_c_raw(this: *mut Self, val: ::std::os::raw::c_ushort) { + unsafe { + let val: u16 = ::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 d(&self) -> ::std::os::raw::c_ushort { unsafe { ::std::mem::transmute(self._bitfield_1.get(6usize, 2u8) as u16) } } @@ -144,6 +277,31 @@ impl bitfield { } } #[inline] + pub unsafe fn d_raw(this: *const Self) -> ::std::os::raw::c_ushort { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 6usize, 2u8) + as u16, + ) + } + } + #[inline] + pub unsafe fn set_d_raw(this: *mut Self, val: ::std::os::raw::c_ushort) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 6usize, + 2u8, + val as u64, + ) + } + } + #[inline] pub fn new_bitfield_1( a: ::std::os::raw::c_ushort, b: ::std::os::raw::c_ushort, @@ -201,6 +359,31 @@ impl bitfield { } } #[inline] + pub unsafe fn f_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 8usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_2), 0usize, 2u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_f_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 8usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_2), + 0usize, + 2u8, + val as u64, + ) + } + } + #[inline] pub fn g(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_2.get(32usize, 32u8) as u32) } } @@ -212,6 +395,31 @@ impl bitfield { } } #[inline] + pub unsafe fn g_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 8usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_2), 32usize, 32u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_g_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 8usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_2), + 32usize, + 32u8, + val as u64, + ) + } + } + #[inline] pub fn new_bitfield_2( f: ::std::os::raw::c_uint, g: ::std::os::raw::c_uint, diff --git a/bindgen-tests/tests/expectations/tests/timex.rs b/bindgen-tests/tests/expectations/tests/timex.rs index a9f78066f0..0c8391c76b 100644 --- a/bindgen-tests/tests/expectations/tests/timex.rs +++ b/bindgen-tests/tests/expectations/tests/timex.rs @@ -15,10 +15,7 @@ where Storage: AsRef<[u8]> + AsMut<[u8]>, { #[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]; + fn extract_bit(byte: u8, index: usize) -> bool { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) } else { @@ -28,21 +25,44 @@ where byte & mask == mask } #[inline] - pub fn set_bit(&mut self, index: usize, val: bool) { + pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); let byte_index = index / 8; - let byte = &mut self.storage.as_mut()[byte_index]; + 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 = *(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; - } + 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize); + *byte = Self::change_bit(*byte, index, val); } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -65,6 +85,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 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()); @@ -82,6 +122,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 + }; + Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + } + } } #[repr(C)] #[derive(Debug, Copy, Clone)] @@ -142,6 +200,31 @@ impl timex_named { } } #[inline] + pub unsafe fn a_raw(this: *const Self) -> ::std::os::raw::c_int { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 44usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 32u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_a_raw(this: *mut Self, val: ::std::os::raw::c_int) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 44usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 0usize, + 32u8, + val as u64, + ) + } + } + #[inline] pub fn b(&self) -> ::std::os::raw::c_int { unsafe { ::std::mem::transmute(self._bitfield_1.get(32usize, 32u8) as u32) } } @@ -153,6 +236,31 @@ impl timex_named { } } #[inline] + pub unsafe fn b_raw(this: *const Self) -> ::std::os::raw::c_int { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 44usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 32usize, 32u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_b_raw(this: *mut Self, val: ::std::os::raw::c_int) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 44usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 32usize, + 32u8, + val as u64, + ) + } + } + #[inline] pub fn c(&self) -> ::std::os::raw::c_int { unsafe { ::std::mem::transmute(self._bitfield_1.get(64usize, 32u8) as u32) } } @@ -164,6 +272,31 @@ impl timex_named { } } #[inline] + pub unsafe fn c_raw(this: *const Self) -> ::std::os::raw::c_int { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 44usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 64usize, 32u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_c_raw(this: *mut Self, val: ::std::os::raw::c_int) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 44usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 64usize, + 32u8, + val as u64, + ) + } + } + #[inline] pub fn d(&self) -> ::std::os::raw::c_int { unsafe { ::std::mem::transmute(self._bitfield_1.get(96usize, 32u8) as u32) } } @@ -175,6 +308,31 @@ impl timex_named { } } #[inline] + pub unsafe fn d_raw(this: *const Self) -> ::std::os::raw::c_int { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 44usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 96usize, 32u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_d_raw(this: *mut Self, val: ::std::os::raw::c_int) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 44usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 96usize, + 32u8, + val as u64, + ) + } + } + #[inline] pub fn e(&self) -> ::std::os::raw::c_int { unsafe { ::std::mem::transmute(self._bitfield_1.get(128usize, 32u8) as u32) } } @@ -186,6 +344,31 @@ impl timex_named { } } #[inline] + pub unsafe fn e_raw(this: *const Self) -> ::std::os::raw::c_int { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 44usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 128usize, 32u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_e_raw(this: *mut Self, val: ::std::os::raw::c_int) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 44usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 128usize, + 32u8, + val as u64, + ) + } + } + #[inline] pub fn f(&self) -> ::std::os::raw::c_int { unsafe { ::std::mem::transmute(self._bitfield_1.get(160usize, 32u8) as u32) } } @@ -197,6 +380,31 @@ impl timex_named { } } #[inline] + pub unsafe fn f_raw(this: *const Self) -> ::std::os::raw::c_int { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 44usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 160usize, 32u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_f_raw(this: *mut Self, val: ::std::os::raw::c_int) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 44usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 160usize, + 32u8, + val as u64, + ) + } + } + #[inline] pub fn g(&self) -> ::std::os::raw::c_int { unsafe { ::std::mem::transmute(self._bitfield_1.get(192usize, 32u8) as u32) } } @@ -208,6 +416,31 @@ impl timex_named { } } #[inline] + pub unsafe fn g_raw(this: *const Self) -> ::std::os::raw::c_int { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 44usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 192usize, 32u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_g_raw(this: *mut Self, val: ::std::os::raw::c_int) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 44usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 192usize, + 32u8, + val as u64, + ) + } + } + #[inline] pub fn h(&self) -> ::std::os::raw::c_int { unsafe { ::std::mem::transmute(self._bitfield_1.get(224usize, 32u8) as u32) } } @@ -219,6 +452,31 @@ impl timex_named { } } #[inline] + pub unsafe fn h_raw(this: *const Self) -> ::std::os::raw::c_int { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 44usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 224usize, 32u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_h_raw(this: *mut Self, val: ::std::os::raw::c_int) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 44usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 224usize, + 32u8, + val as u64, + ) + } + } + #[inline] pub fn i(&self) -> ::std::os::raw::c_int { unsafe { ::std::mem::transmute(self._bitfield_1.get(256usize, 32u8) as u32) } } @@ -230,6 +488,31 @@ impl timex_named { } } #[inline] + pub unsafe fn i_raw(this: *const Self) -> ::std::os::raw::c_int { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 44usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 256usize, 32u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_i_raw(this: *mut Self, val: ::std::os::raw::c_int) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 44usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 256usize, + 32u8, + val as u64, + ) + } + } + #[inline] pub fn j(&self) -> ::std::os::raw::c_int { unsafe { ::std::mem::transmute(self._bitfield_1.get(288usize, 32u8) as u32) } } @@ -241,6 +524,31 @@ impl timex_named { } } #[inline] + pub unsafe fn j_raw(this: *const Self) -> ::std::os::raw::c_int { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 44usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 288usize, 32u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_j_raw(this: *mut Self, val: ::std::os::raw::c_int) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 44usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 288usize, + 32u8, + val as u64, + ) + } + } + #[inline] pub fn k(&self) -> ::std::os::raw::c_int { unsafe { ::std::mem::transmute(self._bitfield_1.get(320usize, 32u8) as u32) } } @@ -251,4 +559,29 @@ impl timex_named { self._bitfield_1.set(320usize, 32u8, val as u64) } } + #[inline] + pub unsafe fn k_raw(this: *const Self) -> ::std::os::raw::c_int { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 44usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 320usize, 32u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_k_raw(this: *mut Self, val: ::std::os::raw::c_int) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 44usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 320usize, + 32u8, + val as u64, + ) + } + } } diff --git a/bindgen-tests/tests/expectations/tests/union_bitfield.rs b/bindgen-tests/tests/expectations/tests/union_bitfield.rs index b529dcfbc8..e924801114 100644 --- a/bindgen-tests/tests/expectations/tests/union_bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/union_bitfield.rs @@ -15,10 +15,7 @@ where Storage: AsRef<[u8]> + AsMut<[u8]>, { #[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]; + fn extract_bit(byte: u8, index: usize) -> bool { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) } else { @@ -28,21 +25,44 @@ where byte & mask == mask } #[inline] - pub fn set_bit(&mut self, index: usize, val: bool) { + pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); let byte_index = index / 8; - let byte = &mut self.storage.as_mut()[byte_index]; + 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 = *(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; - } + 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize); + *byte = Self::change_bit(*byte, index, val); } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -65,6 +85,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 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()); @@ -82,6 +122,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 + }; + Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + } + } } #[repr(C)] #[repr(align(4))] @@ -117,6 +175,31 @@ impl U4 { } } #[inline] + pub unsafe fn derp_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 1u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_derp_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::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 new_bitfield_1( derp: ::std::os::raw::c_uint, ) -> __BindgenBitfieldUnit<[u8; 1usize]> { @@ -166,6 +249,31 @@ impl B { } } #[inline] + pub unsafe fn foo_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 31u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_foo_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 0usize, + 31u8, + val as u64, + ) + } + } + #[inline] pub fn bar(&self) -> ::std::os::raw::c_uchar { unsafe { ::std::mem::transmute(self._bitfield_1.get(31usize, 1u8) as u8) } } @@ -177,6 +285,31 @@ impl B { } } #[inline] + pub unsafe fn bar_raw(this: *const Self) -> ::std::os::raw::c_uchar { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 31usize, 1u8) + as u8, + ) + } + } + #[inline] + pub unsafe fn set_bar_raw(this: *mut Self, val: ::std::os::raw::c_uchar) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 31usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn new_bitfield_1( foo: ::std::os::raw::c_uint, bar: ::std::os::raw::c_uchar, diff --git a/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs b/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs index c2c7173bfe..9cf2bf8e47 100644 --- a/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs @@ -15,10 +15,7 @@ where Storage: AsRef<[u8]> + AsMut<[u8]>, { #[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]; + fn extract_bit(byte: u8, index: usize) -> bool { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) } else { @@ -28,21 +25,44 @@ where byte & mask == mask } #[inline] - pub fn set_bit(&mut self, index: usize, val: bool) { + pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); let byte_index = index / 8; - let byte = &mut self.storage.as_mut()[byte_index]; + 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 = *(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; - } + 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize); + *byte = Self::change_bit(*byte, index, val); } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -65,6 +85,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 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()); @@ -82,6 +122,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 + }; + Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + } + } } #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); @@ -158,6 +216,34 @@ impl U4 { } } #[inline] + pub unsafe fn derp_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_get( + (*::std::ptr::addr_of!((*this)._bitfield_1)).as_ref() as *const _, + 0usize, + 1u8, + ) as u32, + ) + } + } + #[inline] + pub unsafe fn set_derp_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_set( + (*::std::ptr::addr_of_mut!((*this)._bitfield_1)).as_mut() as *mut _, + 0usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn new_bitfield_1( derp: ::std::os::raw::c_uint, ) -> __BindgenBitfieldUnit<[u8; 1usize]> { @@ -206,6 +292,34 @@ impl B { } } #[inline] + pub unsafe fn foo_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_get( + (*::std::ptr::addr_of!((*this)._bitfield_1)).as_ref() as *const _, + 0usize, + 31u8, + ) as u32, + ) + } + } + #[inline] + pub unsafe fn set_foo_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_set( + (*::std::ptr::addr_of_mut!((*this)._bitfield_1)).as_mut() as *mut _, + 0usize, + 31u8, + val as u64, + ) + } + } + #[inline] pub fn bar(&self) -> ::std::os::raw::c_uchar { unsafe { ::std::mem::transmute(self._bitfield_1.as_ref().get(31usize, 1u8) as u8) @@ -219,6 +333,34 @@ impl B { } } #[inline] + pub unsafe fn bar_raw(this: *const Self) -> ::std::os::raw::c_uchar { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_get( + (*::std::ptr::addr_of!((*this)._bitfield_1)).as_ref() as *const _, + 31usize, + 1u8, + ) as u8, + ) + } + } + #[inline] + pub unsafe fn set_bar_raw(this: *mut Self, val: ::std::os::raw::c_uchar) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_set( + (*::std::ptr::addr_of_mut!((*this)._bitfield_1)).as_mut() as *mut _, + 31usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn new_bitfield_1( foo: ::std::os::raw::c_uint, bar: ::std::os::raw::c_uchar, diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield.rs index f850f6a3da..8be065da94 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield.rs @@ -15,10 +15,7 @@ where Storage: AsRef<[u8]> + AsMut<[u8]>, { #[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]; + fn extract_bit(byte: u8, index: usize) -> bool { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) } else { @@ -28,21 +25,44 @@ where byte & mask == mask } #[inline] - pub fn set_bit(&mut self, index: usize, val: bool) { + pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); let byte_index = index / 8; - let byte = &mut self.storage.as_mut()[byte_index]; + 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 = *(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; - } + 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize); + *byte = Self::change_bit(*byte, index, val); } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -65,6 +85,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 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()); @@ -82,6 +122,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 + }; + Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + } + } } #[repr(C)] #[derive(Copy, Clone)] @@ -115,6 +173,31 @@ impl foo__bindgen_ty_1 { } } #[inline] + pub unsafe fn b_raw(this: *const Self) -> ::std::os::raw::c_int { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 7u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_b_raw(this: *mut Self, val: ::std::os::raw::c_int) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 0usize, + 7u8, + val as u64, + ) + } + } + #[inline] pub fn c(&self) -> ::std::os::raw::c_int { unsafe { ::std::mem::transmute(self._bitfield_1.get(7usize, 25u8) as u32) } } @@ -126,6 +209,31 @@ impl foo__bindgen_ty_1 { } } #[inline] + pub unsafe fn c_raw(this: *const Self) -> ::std::os::raw::c_int { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 7usize, 25u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_c_raw(this: *mut Self, val: ::std::os::raw::c_int) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 7usize, + 25u8, + val as u64, + ) + } + } + #[inline] pub fn new_bitfield_1( b: ::std::os::raw::c_int, c: ::std::os::raw::c_int, diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs index ce81f8a04e..287bfebfba 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs @@ -15,10 +15,7 @@ where Storage: AsRef<[u8]> + AsMut<[u8]>, { #[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]; + fn extract_bit(byte: u8, index: usize) -> bool { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) } else { @@ -28,21 +25,44 @@ where byte & mask == mask } #[inline] - pub fn set_bit(&mut self, index: usize, val: bool) { + pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); let byte_index = index / 8; - let byte = &mut self.storage.as_mut()[byte_index]; + 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 = *(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; - } + 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize); + *byte = Self::change_bit(*byte, index, val); } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -65,6 +85,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 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()); @@ -82,6 +122,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 + }; + Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + } + } } #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); @@ -170,6 +228,31 @@ impl foo__bindgen_ty_1 { } } #[inline] + pub unsafe fn b_raw(this: *const Self) -> ::std::os::raw::c_int { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 7u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_b_raw(this: *mut Self, val: ::std::os::raw::c_int) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 0usize, + 7u8, + val as u64, + ) + } + } + #[inline] pub fn c(&self) -> ::std::os::raw::c_int { unsafe { ::std::mem::transmute(self._bitfield_1.get(7usize, 25u8) as u32) } } @@ -181,6 +264,31 @@ impl foo__bindgen_ty_1 { } } #[inline] + pub unsafe fn c_raw(this: *const Self) -> ::std::os::raw::c_int { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 7usize, 25u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_c_raw(this: *mut Self, val: ::std::os::raw::c_int) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 7usize, + 25u8, + val as u64, + ) + } + } + #[inline] pub fn new_bitfield_1( b: ::std::os::raw::c_int, c: ::std::os::raw::c_int, diff --git a/bindgen-tests/tests/expectations/tests/weird_bitfields.rs b/bindgen-tests/tests/expectations/tests/weird_bitfields.rs index f76189eb74..b3f16242f8 100644 --- a/bindgen-tests/tests/expectations/tests/weird_bitfields.rs +++ b/bindgen-tests/tests/expectations/tests/weird_bitfields.rs @@ -15,10 +15,7 @@ where Storage: AsRef<[u8]> + AsMut<[u8]>, { #[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]; + fn extract_bit(byte: u8, index: usize) -> bool { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) } else { @@ -28,21 +25,44 @@ where byte & mask == mask } #[inline] - pub fn set_bit(&mut self, index: usize, val: bool) { + pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); let byte_index = index / 8; - let byte = &mut self.storage.as_mut()[byte_index]; + 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 = *(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; - } + 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize); + *byte = Self::change_bit(*byte, index, val); } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -65,6 +85,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 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()); @@ -82,6 +122,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 + }; + Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + } + } } #[repr(u32)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] @@ -174,6 +232,31 @@ impl Weird { } } #[inline] + pub unsafe fn bitTest_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 16u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_bitTest_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 0usize, + 16u8, + val as u64, + ) + } + } + #[inline] pub fn bitTest2(&self) -> ::std::os::raw::c_uint { unsafe { ::std::mem::transmute(self._bitfield_1.get(16usize, 15u8) as u32) } } @@ -185,6 +268,31 @@ impl Weird { } } #[inline] + pub unsafe fn bitTest2_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 16usize, 15u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_bitTest2_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 4usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 16usize, + 15u8, + val as u64, + ) + } + } + #[inline] pub fn new_bitfield_1( bitTest: ::std::os::raw::c_uint, bitTest2: ::std::os::raw::c_uint, @@ -222,6 +330,34 @@ impl Weird { } } #[inline] + pub unsafe fn mFillOpacitySource_raw(this: *const Self) -> nsStyleSVGOpacitySource { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_2), 0usize, 3u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_mFillOpacitySource_raw( + this: *mut Self, + val: nsStyleSVGOpacitySource, + ) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_2), + 0usize, + 3u8, + val as u64, + ) + } + } + #[inline] pub fn mStrokeOpacitySource(&self) -> nsStyleSVGOpacitySource { unsafe { ::std::mem::transmute(self._bitfield_2.get(3usize, 3u8) as u32) } } @@ -233,6 +369,36 @@ impl Weird { } } #[inline] + pub unsafe fn mStrokeOpacitySource_raw( + this: *const Self, + ) -> nsStyleSVGOpacitySource { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_2), 3usize, 3u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_mStrokeOpacitySource_raw( + this: *mut Self, + val: nsStyleSVGOpacitySource, + ) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_2), + 3usize, + 3u8, + val as u64, + ) + } + } + #[inline] pub fn mStrokeDasharrayFromObject(&self) -> bool { unsafe { ::std::mem::transmute(self._bitfield_2.get(6usize, 1u8) as u8) } } @@ -244,6 +410,30 @@ impl Weird { } } #[inline] + pub unsafe fn mStrokeDasharrayFromObject_raw(this: *const Self) -> bool { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_2), 6usize, 1u8) as u8, + ) + } + } + #[inline] + pub unsafe fn set_mStrokeDasharrayFromObject_raw(this: *mut Self, val: bool) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_2), + 6usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn mStrokeDashoffsetFromObject(&self) -> bool { unsafe { ::std::mem::transmute(self._bitfield_2.get(7usize, 1u8) as u8) } } @@ -255,6 +445,30 @@ impl Weird { } } #[inline] + pub unsafe fn mStrokeDashoffsetFromObject_raw(this: *const Self) -> bool { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_2), 7usize, 1u8) as u8, + ) + } + } + #[inline] + pub unsafe fn set_mStrokeDashoffsetFromObject_raw(this: *mut Self, val: bool) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_2), + 7usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn mStrokeWidthFromObject(&self) -> bool { unsafe { ::std::mem::transmute(self._bitfield_2.get(8usize, 1u8) as u8) } } @@ -266,6 +480,30 @@ impl Weird { } } #[inline] + pub unsafe fn mStrokeWidthFromObject_raw(this: *const Self) -> bool { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_2), 8usize, 1u8) as u8, + ) + } + } + #[inline] + pub unsafe fn set_mStrokeWidthFromObject_raw(this: *mut Self, val: bool) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_2), + 8usize, + 1u8, + val as u64, + ) + } + } + #[inline] pub fn new_bitfield_2( mFillOpacitySource: nsStyleSVGOpacitySource, mStrokeOpacitySource: nsStyleSVGOpacitySource, diff --git a/bindgen/codegen/bitfield_unit.rs b/bindgen/codegen/bitfield_unit.rs index 73ec2bd629..3411c22eac 100644 --- a/bindgen/codegen/bitfield_unit.rs +++ b/bindgen/codegen/bitfield_unit.rs @@ -16,12 +16,7 @@ where Storage: AsRef<[u8]> + AsMut<[u8]>, { #[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]; - + fn extract_bit(byte: u8, index: usize) -> bool { let bit_index = if cfg!(target_endian = "big") { 7 - (index % 8) } else { @@ -34,12 +29,28 @@ where } #[inline] - pub fn set_bit(&mut self, index: usize, val: bool) { + pub fn get_bit(&self, index: usize) -> bool { debug_assert!(index / 8 < self.storage.as_ref().len()); let byte_index = index / 8; - let byte = &mut self.storage.as_mut()[byte_index]; + 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 = *(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 { @@ -48,12 +59,33 @@ where let mask = 1 << bit_index; if val { - *byte |= mask; + byte | mask } else { - *byte &= !mask; + 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize); + + *byte = Self::change_bit(*byte, index, val); + } + #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); @@ -79,6 +111,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 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); @@ -99,4 +160,30 @@ 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 + }; + Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + } + } } diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index b92f5e127a..c6e3364234 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -1808,6 +1808,7 @@ impl<'a> FieldCodegen<'a> for BitfieldUnit { methods, ( &unit_field_name, + &unit_field_ty, &mut bitfield_representable_as_int, &mut bitfield_visibility, ), @@ -1865,6 +1866,15 @@ fn bitfield_getter_name( quote! { #name } } +fn bitfield_raw_getter_name( + ctx: &BindgenContext, + bitfield: &Bitfield, +) -> proc_macro2::TokenStream { + let name = bitfield.getter_name(); + let name = ctx.rust_ident_raw(format!("{name}_raw")); + quote! { #name } +} + fn bitfield_setter_name( ctx: &BindgenContext, bitfield: &Bitfield, @@ -1874,8 +1884,22 @@ fn bitfield_setter_name( quote! { #setter } } +fn bitfield_raw_setter_name( + ctx: &BindgenContext, + bitfield: &Bitfield, +) -> proc_macro2::TokenStream { + let setter = bitfield.setter_name(); + let setter = ctx.rust_ident_raw(format!("{setter}_raw")); + quote! { #setter } +} + impl<'a> FieldCodegen<'a> for Bitfield { - type Extra = (&'a str, &'a mut bool, &'a mut FieldVisibilityKind); + type Extra = ( + &'a str, + &'a syn::Type, + &'a mut bool, + &'a mut FieldVisibilityKind, + ); fn codegen( &self, @@ -1889,8 +1913,14 @@ impl<'a> FieldCodegen<'a> for Bitfield { struct_layout: &mut StructLayoutTracker, _fields: &mut F, methods: &mut M, - (unit_field_name, bitfield_representable_as_int, bitfield_visibility): ( + ( + unit_field_name, + unit_field_ty, + bitfield_representable_as_int, + bitfield_visibility, + ): ( &'a str, + &'a syn::Type, &mut bool, &'a mut FieldVisibilityKind, ), @@ -1901,6 +1931,8 @@ impl<'a> FieldCodegen<'a> for Bitfield { let prefix = ctx.trait_prefix(); let getter_name = bitfield_getter_name(ctx, self); let setter_name = bitfield_setter_name(ctx, self); + let raw_getter_name = bitfield_raw_getter_name(ctx, self); + let raw_setter_name = bitfield_raw_setter_name(ctx, self); let unit_field_ident = Ident::new(unit_field_name, Span::call_site()); let bitfield_ty_item = ctx.resolve_item(self.ty()); @@ -1967,6 +1999,30 @@ impl<'a> FieldCodegen<'a> for Bitfield { ) } } + + #[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, + ) + } + } })); } else { methods.extend(Some(quote! { @@ -1991,6 +2047,30 @@ impl<'a> FieldCodegen<'a> for Bitfield { ) } } + + #[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), + #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), + #offset, + #width, + val as u64, + ) + } + } })); } } From 458182b6d131d5f86c27948534fd5a6ad011f5f5 Mon Sep 17 00:00:00 2001 From: Christiaan Biesterbosch Date: Mon, 16 Sep 2024 19:34:35 +0200 Subject: [PATCH 736/942] Require libclang 9.0 or newer Adds a check for the loaded libclang version and logs a warning if the version is unsupported. Will not print a warning if libclang is statically linked. --- bindgen/lib.rs | 12 ++++++++++++ book/src/requirements.md | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 572e1d4598..1a9932b534 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -744,6 +744,18 @@ impl Bindings { ) -> Result { ensure_libclang_is_loaded(); + #[cfg(feature = "runtime")] + match clang_sys::get_library().unwrap().version() { + None => { + warn!("Could not detect a Clang version, make sure you are using libclang 9 or newer"); + } + Some(version) => { + if version < clang_sys::Version::V9_0 { + warn!("Detected Clang version {version:?} which is unsupported and can cause invalid code generation, use libclang 9 or newer"); + } + } + } + #[cfg(feature = "runtime")] debug!( "Generating bindings, libclang at {}", diff --git a/book/src/requirements.md b/book/src/requirements.md index b701234fad..6553b7c15c 100644 --- a/book/src/requirements.md +++ b/book/src/requirements.md @@ -7,7 +7,7 @@ This page lists the requirements for running `bindgen` and how to get them. `bindgen` leverages `libclang` to preprocess, parse, and type check C and C++ header files. -It is required to use Clang 5.0 or greater. +It is required to use Clang 9.0 or greater. ### Installing Clang From 5eafd91c98674b44cdcca951b451a5da505b491b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 25 Sep 2024 12:19:13 -0700 Subject: [PATCH 737/942] Update libc. Fixes #2914 --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4786857205..0ea9474809 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -315,9 +315,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.154" +version = "0.2.159" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" +checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" [[package]] name = "libloading" From 7cc265811146067660dd341874ce9c211266834a Mon Sep 17 00:00:00 2001 From: Valentin Date: Thu, 26 Sep 2024 14:35:06 +0200 Subject: [PATCH 738/942] Update documentation of Debian dependencies Bindgen doesn't need the llvm package at all and only needs the clang package for one function. I've tested this by running the bindgen tests on a fresh Debian installation. I removed the line about Ubuntu because it is not relevant anymore. closes #2934 --- book/src/requirements.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/book/src/requirements.md b/book/src/requirements.md index 6553b7c15c..d13e3a85c2 100644 --- a/book/src/requirements.md +++ b/book/src/requirements.md @@ -48,10 +48,10 @@ $ port install clang #### Debian-based Linuxes ```bash -# apt install llvm-dev libclang-dev clang +# apt install libclang-dev ``` -Ubuntu 18.04 provides the necessary packages directly. +If you want to use the function `bindgen::Builder::dump_preprocessed_input`, then you also need the package `clang`. #### Arch From af26991da8161f4d401d0d0532a05079449e7379 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Tue, 8 Oct 2024 11:02:47 -0500 Subject: [PATCH 739/942] Update `cargo-dist` --- .github/workflows/release.yml | 4 +++- Cargo.toml | 10 +++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6d739c57d9..5df0c7b1c1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,3 +1,5 @@ +# This file was autogenerated by cargo-dist: https://opensource.axo.dev/cargo-dist/ +# # Copyright 2022-2024, axodotdev # SPDX-License-Identifier: MIT or Apache-2.0 # @@ -61,7 +63,7 @@ jobs: # we specify bash to get pipefail; it guards against the `curl` command # failing. otherwise `sh` won't catch that `curl` returned non-0 shell: bash - run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.21.0/cargo-dist-installer.sh | sh" + run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.22.1/cargo-dist-installer.sh | sh" - name: Cache cargo-dist uses: actions/upload-artifact@v4 with: diff --git a/Cargo.toml b/Cargo.toml index 400fd8788a..9170e18fed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,13 +17,13 @@ default-members = [ # Config for 'cargo dist' [workspace.metadata.dist] # The preferred cargo-dist version to use in CI (Cargo.toml SemVer syntax) -cargo-dist-version = "0.21.0" +cargo-dist-version = "0.22.1" # CI backends to support ci = "github" # The installers to generate for each app -installers = ["shell", "powershell"] +installers = ["shell"] # Target platforms to build apps for (Rust target-triple syntax) -targets = ["aarch64-apple-darwin", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu", "x86_64-pc-windows-msvc"] +targets = ["aarch64-apple-darwin", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu"] # Whether to consider the binaries in a package for distribution (defaults true) dist = false # Which actions to run on pull requests @@ -33,6 +33,10 @@ install-updater = false # Path that installers should place binaries in install-path = "CARGO_HOME" +[workspace.metadata.dist.github-custom-runners] +aarch64-apple-darwin = "macos-14" +x86_64-apple-darwin = "macos-12" + # Config for 'cargo release' [workspace.metadata.release] shared-version = true # ensures published packages share the same version From 07bbd04ea5f386aa3b83e792548127e2a2e33c43 Mon Sep 17 00:00:00 2001 From: myyrakle Date: Fri, 18 Oct 2024 00:56:57 +0900 Subject: [PATCH 740/942] Docs: Fix example code error --- book/src/tutorial-3.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/src/tutorial-3.md b/book/src/tutorial-3.md index 3248f2847f..b2d15dbc59 100644 --- a/book/src/tutorial-3.md +++ b/book/src/tutorial-3.md @@ -30,7 +30,7 @@ fn main() { .header("wrapper.h") // Tell cargo to invalidate the built crate whenever any of the // included header files changed. - .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) + .parse_callbacks(Box::new(bindgen::CargoCallbacks)) // Finish the builder and generate the bindings. .generate() // Unwrap the Result and panic on failure. From 9f59212761046166d3a446fa67e6c8004e6129ea Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Sat, 2 Nov 2024 01:51:13 +0100 Subject: [PATCH 741/942] ci: Move forward Rust for Linux version The CI is hitting errors and warnings now [1], due to Rust 1.82.0 being used to build an older Linux kernel: warning: the feature `new_uninit` has been stable since 1.82.0 and no longer requires an attribute to enable --> rust/kernel/lib.rs:17:12 | 17 | #![feature(new_uninit)] | ^^^^^^^^^^ | = note: `#[warn(stable_features)]` on by default error[E0658]: use of unstable library feature 'box_uninit_write' --> rust/kernel/alloc/box_ext.rs:25:12 | 25 | Ok(Box::write(b, x)) | ^^^^^^^^^^ | = note: see issue #129397 for more information = help: add `#![feature(box_uninit_write)]` to the crate attributes to enable = note: this compiler was built on 2024-10-15; consider upgrading it if it is out of date Which is due to the current commit hash being from the Linux v6.10 cycle, when we did not yet support several Rust versions. Thus update the hash with a newer tag (the latest available) that does support several Rust versions, including the latest. In any case, updating is a good idea since it has been a while since we introduced Rust for Linux in the CI, and the intention is to update it from time to time nevertheless. Link: https://github.com/rust-lang/rust-bindgen/actions/runs/11637602211/job/32411071463?pr=2969#step:6:1362 [1] Signed-off-by: Miguel Ojeda --- ci/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/test.sh b/ci/test.sh index bec7cfbb0c..a90af84484 100755 --- a/ci/test.sh +++ b/ci/test.sh @@ -154,7 +154,7 @@ if [ "$BINDGEN_RUST_FOR_LINUX_TEST" == "1" ]; then # and each update should only contain this change. # # Both commit hashes and tags are supported. - LINUX_VERSION=c13320499ba0efd93174ef6462ae8a7a2933f6e7 + LINUX_VERSION=v6.12-rc5 # Download Linux at a specific commit mkdir -p linux From 8a6d851318153b7304b651a7fd8f559938683de3 Mon Sep 17 00:00:00 2001 From: Enes Date: Sat, 2 Nov 2024 02:07:48 +0300 Subject: [PATCH 742/942] update small typo it makes sense that "traits" is the correct word... :-) --- bindgen/codegen/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index c6e3364234..2de56c19c5 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -4130,7 +4130,7 @@ where /// ### Fallible vs. Infallible Conversions to Rust Types /// /// When should one use this infallible `ToRustTyOrOpaque` trait versus the -/// fallible `TryTo{RustTy, Opaque, RustTyOrOpaque}` triats? All fallible trait +/// fallible `TryTo{RustTy, Opaque, RustTyOrOpaque}` traits? All fallible trait /// implementations that need to convert another thing into a Rust type or /// opaque blob in a nested manner should also use fallible trait methods and /// propagate failure up the stack. Only infallible functions and methods like From 594009bd5ee5449ea267de7e19ff1fbf35c1e85c Mon Sep 17 00:00:00 2001 From: Brian Ward Date: Mon, 21 Oct 2024 10:54:31 -0400 Subject: [PATCH 743/942] Wrap libloading::Library::new call in unsafe if --wrap-unsafe-ops --- .../tests/wrap_unsafe_ops_dynamic_loading_simple.rs | 2 +- bindgen/codegen/dyngen.rs | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_dynamic_loading_simple.rs b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_dynamic_loading_simple.rs index 2f5b4cc5ba..82ed764934 100644 --- a/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_dynamic_loading_simple.rs +++ b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_dynamic_loading_simple.rs @@ -22,7 +22,7 @@ impl TestLib { where P: AsRef<::std::ffi::OsStr>, { - let library = ::libloading::Library::new(path)?; + let library = unsafe { ::libloading::Library::new(path) }?; unsafe { Self::from_library(library) } } pub unsafe fn from_library(library: L) -> Result diff --git a/bindgen/codegen/dyngen.rs b/bindgen/codegen/dyngen.rs index 4b2749ec0c..3109ddf296 100644 --- a/bindgen/codegen/dyngen.rs +++ b/bindgen/codegen/dyngen.rs @@ -83,6 +83,12 @@ impl DynamicItems { let init_fields = &self.init_fields; let struct_implementation = &self.struct_implementation; + let library_new = if ctx.options().wrap_unsafe_ops { + quote!(unsafe { ::libloading::Library::new(path) }) + } else { + quote!(::libloading::Library::new(path)) + }; + let from_library = if ctx.options().wrap_unsafe_ops { quote!(unsafe { Self::from_library(library) }) } else { @@ -100,7 +106,7 @@ impl DynamicItems { path: P ) -> Result where P: AsRef<::std::ffi::OsStr> { - let library = ::libloading::Library::new(path)?; + let library = #library_new?; #from_library } From cd5b8433ca26cea74ffba873414eb510a123623d Mon Sep 17 00:00:00 2001 From: Brian Ward Date: Mon, 21 Oct 2024 11:00:08 -0400 Subject: [PATCH 744/942] Add test showing bad behavior for non-functions --- .../tests/wrap_unsafe_ops_dynamic_loading_simple.rs | 8 ++++++++ .../headers/wrap_unsafe_ops_dynamic_loading_simple.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_dynamic_loading_simple.rs b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_dynamic_loading_simple.rs index 82ed764934..d261cc77ec 100644 --- a/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_dynamic_loading_simple.rs +++ b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_dynamic_loading_simple.rs @@ -16,6 +16,7 @@ pub struct TestLib { unsafe extern "C" fn() -> ::std::os::raw::c_int, ::libloading::Error, >, + pub FLUX: Result<*mut ::std::os::raw::c_int, ::libloading::Error>, } impl TestLib { pub unsafe fn new
= ::std::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); assert_eq!(::std::mem::size_of::
(), 16usize, "Size of header"); + assert_eq!(::std::mem::align_of::
(), 16usize, "Alignment of header"); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize }, + 0usize, + "Offset of field: header::proto", + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).size) as usize - ptr as usize }, + 1usize, + "Offset of field: header::size", + ); + assert_eq!( + unsafe { ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize }, + 8usize, + "Offset of field: header::data", + ); } impl Default for header { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs b/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs deleted file mode 100644 index 6cbeb042aa..0000000000 --- a/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs +++ /dev/null @@ -1,1837 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit { - storage: Storage, -} -impl __BindgenBitfieldUnit { - #[inline] - pub 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] - 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 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 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); - } - } -} -#[repr(C)] -pub struct __BindgenUnionField(::std::marker::PhantomData); -impl __BindgenUnionField { - #[inline] - pub fn new() -> Self { - __BindgenUnionField(::std::marker::PhantomData) - } - #[inline] - pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) - } - #[inline] - pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) - } -} -impl ::std::default::Default for __BindgenUnionField { - #[inline] - fn default() -> Self { - Self::new() - } -} -impl ::std::clone::Clone for __BindgenUnionField { - #[inline] - fn clone(&self) -> Self { - *self - } -} -impl ::std::marker::Copy for __BindgenUnionField {} -impl ::std::fmt::Debug for __BindgenUnionField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__BindgenUnionField") - } -} -impl ::std::hash::Hash for __BindgenUnionField { - fn hash(&self, _state: &mut H) {} -} -impl ::std::cmp::PartialEq for __BindgenUnionField { - fn eq(&self, _other: &__BindgenUnionField) -> bool { - true - } -} -impl ::std::cmp::Eq for __BindgenUnionField {} -pub const ETH_MQ_RX_RSS_FLAG: u32 = 1; -pub const ETH_MQ_RX_DCB_FLAG: u32 = 2; -pub const ETH_MQ_RX_VMDQ_FLAG: u32 = 4; -pub const ETH_VMDQ_MAX_VLAN_FILTERS: u32 = 64; -pub const ETH_DCB_NUM_USER_PRIORITIES: u32 = 8; -pub const ETH_VMDQ_DCB_NUM_QUEUES: u32 = 128; -pub const ETH_DCB_NUM_QUEUES: u32 = 128; -pub const RTE_ETH_FDIR_MAX_FLEXLEN: u32 = 16; -pub const RTE_ETH_INSET_SIZE_MAX: u32 = 128; -pub const RTE_ETH_FLOW_UNKNOWN: u32 = 0; -pub const RTE_ETH_FLOW_RAW: u32 = 1; -pub const RTE_ETH_FLOW_IPV4: u32 = 2; -pub const RTE_ETH_FLOW_FRAG_IPV4: u32 = 3; -pub const RTE_ETH_FLOW_NONFRAG_IPV4_TCP: u32 = 4; -pub const RTE_ETH_FLOW_NONFRAG_IPV4_UDP: u32 = 5; -pub const RTE_ETH_FLOW_NONFRAG_IPV4_SCTP: u32 = 6; -pub const RTE_ETH_FLOW_NONFRAG_IPV4_OTHER: u32 = 7; -pub const RTE_ETH_FLOW_IPV6: u32 = 8; -pub const RTE_ETH_FLOW_FRAG_IPV6: u32 = 9; -pub const RTE_ETH_FLOW_NONFRAG_IPV6_TCP: u32 = 10; -pub const RTE_ETH_FLOW_NONFRAG_IPV6_UDP: u32 = 11; -pub const RTE_ETH_FLOW_NONFRAG_IPV6_SCTP: u32 = 12; -pub const RTE_ETH_FLOW_NONFRAG_IPV6_OTHER: u32 = 13; -pub const RTE_ETH_FLOW_L2_PAYLOAD: u32 = 14; -pub const RTE_ETH_FLOW_IPV6_EX: u32 = 15; -pub const RTE_ETH_FLOW_IPV6_TCP_EX: u32 = 16; -pub const RTE_ETH_FLOW_IPV6_UDP_EX: u32 = 17; -pub const RTE_ETH_FLOW_PORT: u32 = 18; -pub const RTE_ETH_FLOW_VXLAN: u32 = 19; -pub const RTE_ETH_FLOW_GENEVE: u32 = 20; -pub const RTE_ETH_FLOW_NVGRE: u32 = 21; -pub const RTE_ETH_FLOW_MAX: u32 = 22; -#[repr(u32)] -/** A set of values to identify what method is to be used to route - packets to multiple queues.*/ -#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] -pub enum rte_eth_rx_mq_mode { - /// None of DCB,RSS or VMDQ mode - ETH_MQ_RX_NONE = 0, - /// For RX side, only RSS is on - ETH_MQ_RX_RSS = 1, - /// For RX side,only DCB is on. - ETH_MQ_RX_DCB = 2, - /// Both DCB and RSS enable - ETH_MQ_RX_DCB_RSS = 3, - /// Only VMDQ, no RSS nor DCB - ETH_MQ_RX_VMDQ_ONLY = 4, - /// RSS mode with VMDQ - ETH_MQ_RX_VMDQ_RSS = 5, - /// Use VMDQ+DCB to route traffic to queues - ETH_MQ_RX_VMDQ_DCB = 6, - /// Enable both VMDQ and DCB in VMDq - ETH_MQ_RX_VMDQ_DCB_RSS = 7, -} -/// A structure used to configure the RX features of an Ethernet port. -#[repr(C)] -#[derive(Debug, Copy, Hash, PartialEq, Eq)] -pub struct rte_eth_rxmode { - /// The multi-queue packet distribution mode to be used, e.g. RSS. - pub mq_mode: rte_eth_rx_mq_mode, - ///< Only used if jumbo_frame enabled. - pub max_rx_pkt_len: u32, - ///< hdr buf size (header_split enabled). - pub split_hdr_size: u16, - pub _bitfield_align_1: [u8; 0], - 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, - "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, - "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, - "Offset of field: rte_eth_rxmode::split_hdr_size", - ); -} -impl Clone for rte_eth_rxmode { - fn clone(&self) -> Self { - *self - } -} -impl Default for rte_eth_rxmode { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} -impl rte_eth_rxmode { - #[inline] - pub fn header_split(&self) -> u16 { - unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u16) } - } - #[inline] - pub fn set_header_split(&mut self, val: u16) { - unsafe { - let val: u16 = ::std::mem::transmute(val); - self._bitfield_1.set(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) } - } - #[inline] - pub fn set_hw_ip_checksum(&mut self, val: u16) { - unsafe { - let val: u16 = ::std::mem::transmute(val); - self._bitfield_1.set(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) } - } - #[inline] - pub fn set_hw_vlan_filter(&mut self, val: u16) { - unsafe { - let val: u16 = ::std::mem::transmute(val); - self._bitfield_1.set(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) } - } - #[inline] - pub fn set_hw_vlan_strip(&mut self, val: u16) { - unsafe { - let val: u16 = ::std::mem::transmute(val); - self._bitfield_1.set(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) } - } - #[inline] - pub fn set_hw_vlan_extend(&mut self, val: u16) { - unsafe { - let val: u16 = ::std::mem::transmute(val); - self._bitfield_1.set(4usize, 1u8, val as u64) - } - } - #[inline] - pub fn jumbo_frame(&self) -> u16 { - unsafe { ::std::mem::transmute(self._bitfield_1.get(5usize, 1u8) as u16) } - } - #[inline] - pub fn set_jumbo_frame(&mut self, val: u16) { - unsafe { - let val: u16 = ::std::mem::transmute(val); - self._bitfield_1.set(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) } - } - #[inline] - pub fn set_hw_strip_crc(&mut self, val: u16) { - unsafe { - let val: u16 = ::std::mem::transmute(val); - self._bitfield_1.set(6usize, 1u8, val as u64) - } - } - #[inline] - pub fn enable_scatter(&self) -> u16 { - unsafe { ::std::mem::transmute(self._bitfield_1.get(7usize, 1u8) as u16) } - } - #[inline] - pub fn set_enable_scatter(&mut self, val: u16) { - unsafe { - let val: u16 = ::std::mem::transmute(val); - self._bitfield_1.set(7usize, 1u8, val as u64) - } - } - #[inline] - pub fn enable_lro(&self) -> u16 { - unsafe { ::std::mem::transmute(self._bitfield_1.get(8usize, 1u8) as u16) } - } - #[inline] - pub fn set_enable_lro(&mut self, val: u16) { - unsafe { - let val: u16 = ::std::mem::transmute(val); - self._bitfield_1.set(8usize, 1u8, val as u64) - } - } - #[inline] - pub fn new_bitfield_1( - header_split: u16, - hw_ip_checksum: u16, - hw_vlan_filter: u16, - hw_vlan_strip: u16, - hw_vlan_extend: u16, - jumbo_frame: u16, - hw_strip_crc: u16, - enable_scatter: u16, - enable_lro: u16, - ) -> __BindgenBitfieldUnit<[u8; 2usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 2usize]> = Default::default(); - __bindgen_bitfield_unit - .set( - 0usize, - 1u8, - { - let header_split: u16 = unsafe { - ::std::mem::transmute(header_split) - }; - header_split as u64 - }, - ); - __bindgen_bitfield_unit - .set( - 1usize, - 1u8, - { - let hw_ip_checksum: u16 = unsafe { - ::std::mem::transmute(hw_ip_checksum) - }; - hw_ip_checksum as u64 - }, - ); - __bindgen_bitfield_unit - .set( - 2usize, - 1u8, - { - let hw_vlan_filter: u16 = unsafe { - ::std::mem::transmute(hw_vlan_filter) - }; - hw_vlan_filter as u64 - }, - ); - __bindgen_bitfield_unit - .set( - 3usize, - 1u8, - { - let hw_vlan_strip: u16 = unsafe { - ::std::mem::transmute(hw_vlan_strip) - }; - hw_vlan_strip as u64 - }, - ); - __bindgen_bitfield_unit - .set( - 4usize, - 1u8, - { - let hw_vlan_extend: u16 = unsafe { - ::std::mem::transmute(hw_vlan_extend) - }; - hw_vlan_extend as u64 - }, - ); - __bindgen_bitfield_unit - .set( - 5usize, - 1u8, - { - let jumbo_frame: u16 = unsafe { ::std::mem::transmute(jumbo_frame) }; - jumbo_frame as u64 - }, - ); - __bindgen_bitfield_unit - .set( - 6usize, - 1u8, - { - let hw_strip_crc: u16 = unsafe { - ::std::mem::transmute(hw_strip_crc) - }; - hw_strip_crc as u64 - }, - ); - __bindgen_bitfield_unit - .set( - 7usize, - 1u8, - { - let enable_scatter: u16 = unsafe { - ::std::mem::transmute(enable_scatter) - }; - enable_scatter as u64 - }, - ); - __bindgen_bitfield_unit - .set( - 8usize, - 1u8, - { - let enable_lro: u16 = unsafe { ::std::mem::transmute(enable_lro) }; - enable_lro as u64 - }, - ); - __bindgen_bitfield_unit - } -} -#[repr(u32)] -/** A set of values to identify what method is to be used to transmit - packets using multi-TCs.*/ -#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] -pub enum rte_eth_tx_mq_mode { - ///< It is in neither DCB nor VT mode. - ETH_MQ_TX_NONE = 0, - ///< For TX side,only DCB is on. - ETH_MQ_TX_DCB = 1, - ///< For TX side,both DCB and VT is on. - ETH_MQ_TX_VMDQ_DCB = 2, - ///< Only VT on, no DCB - ETH_MQ_TX_VMDQ_ONLY = 3, -} -/// A structure used to configure the TX features of an Ethernet port. -#[repr(C)] -#[derive(Debug, Copy, Hash, PartialEq, Eq)] -pub struct rte_eth_txmode { - ///< TX multi-queues mode. - pub mq_mode: rte_eth_tx_mq_mode, - pub pvid: u16, - pub _bitfield_align_1: [u8; 0], - 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, - "Offset of field: rte_eth_txmode::mq_mode", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).pvid) as usize - ptr as usize }, - 4usize, - "Offset of field: rte_eth_txmode::pvid", - ); -} -impl Clone for rte_eth_txmode { - fn clone(&self) -> Self { - *self - } -} -impl Default for rte_eth_txmode { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} -impl rte_eth_txmode { - #[inline] - pub fn hw_vlan_reject_tagged(&self) -> u8 { - unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) } - } - #[inline] - pub fn set_hw_vlan_reject_tagged(&mut self, val: u8) { - unsafe { - let val: u8 = ::std::mem::transmute(val); - self._bitfield_1.set(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) } - } - #[inline] - pub fn set_hw_vlan_reject_untagged(&mut self, val: u8) { - unsafe { - let val: u8 = ::std::mem::transmute(val); - self._bitfield_1.set(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) } - } - #[inline] - pub fn set_hw_vlan_insert_pvid(&mut self, val: u8) { - unsafe { - let val: u8 = ::std::mem::transmute(val); - self._bitfield_1.set(2usize, 1u8, val as u64) - } - } - #[inline] - pub fn new_bitfield_1( - hw_vlan_reject_tagged: u8, - hw_vlan_reject_untagged: u8, - hw_vlan_insert_pvid: u8, - ) -> __BindgenBitfieldUnit<[u8; 1usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); - __bindgen_bitfield_unit - .set( - 0usize, - 1u8, - { - let hw_vlan_reject_tagged: u8 = unsafe { - ::std::mem::transmute(hw_vlan_reject_tagged) - }; - hw_vlan_reject_tagged as u64 - }, - ); - __bindgen_bitfield_unit - .set( - 1usize, - 1u8, - { - let hw_vlan_reject_untagged: u8 = unsafe { - ::std::mem::transmute(hw_vlan_reject_untagged) - }; - hw_vlan_reject_untagged as u64 - }, - ); - __bindgen_bitfield_unit - .set( - 2usize, - 1u8, - { - let hw_vlan_insert_pvid: u8 = unsafe { - ::std::mem::transmute(hw_vlan_insert_pvid) - }; - hw_vlan_insert_pvid as u64 - }, - ); - __bindgen_bitfield_unit - } -} -/** A structure used to configure the Receive Side Scaling (RSS) feature - of an Ethernet port. - If not NULL, the *rss_key* pointer of the *rss_conf* structure points - to an array holding the RSS key to use for hashing specific header - fields of received packets. The length of this array should be indicated - by *rss_key_len* below. Otherwise, a default random hash key is used by - the device driver. - - The *rss_key_len* field of the *rss_conf* structure indicates the length - in bytes of the array pointed by *rss_key*. To be compatible, this length - will be checked in i40e only. Others assume 40 bytes to be used as before. - - The *rss_hf* field of the *rss_conf* structure indicates the different - types of IPv4/IPv6 packets to which the RSS hashing must be applied. - Supplying an *rss_hf* equal to zero disables the RSS feature.*/ -#[repr(C)] -#[derive(Debug, Copy, Hash, PartialEq, Eq)] -pub struct rte_eth_rss_conf { - ///< If not NULL, 40-byte hash key. - pub rss_key: *mut u8, - ///< hash key length in bytes. - pub rss_key_len: u8, - ///< 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, - "Alignment of rte_eth_rss_conf", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).rss_key) as usize - ptr as usize }, - 0usize, - "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, - "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, - "Offset of field: rte_eth_rss_conf::rss_hf", - ); -} -impl Clone for rte_eth_rss_conf { - fn clone(&self) -> Self { - *self - } -} -impl Default for rte_eth_rss_conf { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} -#[repr(u32)] -/** This enum indicates the possible number of traffic classes - in DCB configratioins*/ -#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] -pub enum rte_eth_nb_tcs { - ///< 4 TCs with DCB. - ETH_4_TCS = 4, - ///< 8 TCs with DCB. - ETH_8_TCS = 8, -} -#[repr(u32)] -/** This enum indicates the possible number of queue pools - in VMDQ configurations.*/ -#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] -pub enum rte_eth_nb_pools { - ///< 8 VMDq pools. - ETH_8_POOLS = 8, - ///< 16 VMDq pools. - ETH_16_POOLS = 16, - ///< 32 VMDq pools. - ETH_32_POOLS = 32, - ///< 64 VMDq pools. - ETH_64_POOLS = 64, -} -/** A structure used to configure the VMDQ+DCB feature - of an Ethernet port. - - Using this feature, packets are routed to a pool of queues, based - on the vlan ID in the vlan tag, and then to a specific queue within - that pool, using the user priority vlan tag field. - - A default pool may be used, if desired, to route all traffic which - does not match the vlan filter rules.*/ -#[repr(C)] -#[derive(Copy)] -pub struct rte_eth_vmdq_dcb_conf { - ///< With DCB, 16 or 32 pools - pub nb_queue_pools: rte_eth_nb_pools, - ///< If non-zero, use a default pool - pub enable_default_pool: u8, - ///< The default pool, if applicable - pub default_pool: u8, - ///< We can have up to 64 filters/mappings - pub nb_pool_maps: u8, - ///< VMDq vlan pool maps. - pub pool_map: [rte_eth_vmdq_dcb_conf__bindgen_ty_1; 64usize], - pub dcb_tc: [u8; 8usize], -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct rte_eth_vmdq_dcb_conf__bindgen_ty_1 { - ///< The vlan ID of the received frame - pub vlan_id: u16, - ///< 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, - "Size of rte_eth_vmdq_dcb_conf__bindgen_ty_1", - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - "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, - "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, - "Offset of field: rte_eth_vmdq_dcb_conf__bindgen_ty_1::pools", - ); -} -impl Clone for rte_eth_vmdq_dcb_conf__bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} -#[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, - "Size of rte_eth_vmdq_dcb_conf", - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - "Alignment of rte_eth_vmdq_dcb_conf", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize }, - 0usize, - "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, - "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, - "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, - "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, - "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, - "Offset of field: rte_eth_vmdq_dcb_conf::dcb_tc", - ); -} -impl Clone for rte_eth_vmdq_dcb_conf { - fn clone(&self) -> Self { - *self - } -} -impl Default for rte_eth_vmdq_dcb_conf { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} -#[repr(C)] -#[derive(Debug, Copy, Hash, PartialEq, Eq)] -pub struct rte_eth_dcb_rx_conf { - ///< Possible DCB TCs, 4 or 8 TCs - pub nb_tcs: rte_eth_nb_tcs, - /// 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, - "Size of rte_eth_dcb_rx_conf", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - "Alignment of rte_eth_dcb_rx_conf", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize }, - 0usize, - "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, - "Offset of field: rte_eth_dcb_rx_conf::dcb_tc", - ); -} -impl Clone for rte_eth_dcb_rx_conf { - fn clone(&self) -> Self { - *self - } -} -impl Default for rte_eth_dcb_rx_conf { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} -#[repr(C)] -#[derive(Debug, Copy, Hash, PartialEq, Eq)] -pub struct rte_eth_vmdq_dcb_tx_conf { - ///< With DCB, 16 or 32 pools. - pub nb_queue_pools: rte_eth_nb_pools, - /// 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, - "Size of rte_eth_vmdq_dcb_tx_conf", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - "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, - "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, - "Offset of field: rte_eth_vmdq_dcb_tx_conf::dcb_tc", - ); -} -impl Clone for rte_eth_vmdq_dcb_tx_conf { - fn clone(&self) -> Self { - *self - } -} -impl Default for rte_eth_vmdq_dcb_tx_conf { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} -#[repr(C)] -#[derive(Debug, Copy, Hash, PartialEq, Eq)] -pub struct rte_eth_dcb_tx_conf { - ///< Possible DCB TCs, 4 or 8 TCs. - pub nb_tcs: rte_eth_nb_tcs, - /// 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, - "Size of rte_eth_dcb_tx_conf", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - "Alignment of rte_eth_dcb_tx_conf", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).nb_tcs) as usize - ptr as usize }, - 0usize, - "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, - "Offset of field: rte_eth_dcb_tx_conf::dcb_tc", - ); -} -impl Clone for rte_eth_dcb_tx_conf { - fn clone(&self) -> Self { - *self - } -} -impl Default for rte_eth_dcb_tx_conf { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} -#[repr(C)] -#[derive(Debug, Copy, Hash, PartialEq, Eq)] -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, - "Size of rte_eth_vmdq_tx_conf", - ); - assert_eq!( - ::std::mem::align_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, - "Offset of field: rte_eth_vmdq_tx_conf::nb_queue_pools", - ); -} -impl Clone for rte_eth_vmdq_tx_conf { - fn clone(&self) -> Self { - *self - } -} -impl Default for rte_eth_vmdq_tx_conf { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} -#[repr(C)] -#[derive(Copy)] -pub struct rte_eth_vmdq_rx_conf { - ///< VMDq only mode, 8 or 64 pools - pub nb_queue_pools: rte_eth_nb_pools, - ///< If non-zero, use a default pool - pub enable_default_pool: u8, - ///< The default pool, if applicable - pub default_pool: u8, - ///< Enable VT loop back - pub enable_loop_back: u8, - ///< We can have up to 64 filters/mappings - pub nb_pool_maps: u8, - ///< Flags from ETH_VMDQ_ACCEPT_* - pub rx_mode: u32, - ///< VMDq vlan pool maps. - pub pool_map: [rte_eth_vmdq_rx_conf__bindgen_ty_1; 64usize], -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct rte_eth_vmdq_rx_conf__bindgen_ty_1 { - ///< The vlan ID of the received frame - pub vlan_id: u16, - ///< 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, - "Size of rte_eth_vmdq_rx_conf__bindgen_ty_1", - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - "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, - "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, - "Offset of field: rte_eth_vmdq_rx_conf__bindgen_ty_1::pools", - ); -} -impl Clone for rte_eth_vmdq_rx_conf__bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} -#[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, - "Size of rte_eth_vmdq_rx_conf", - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - "Alignment of rte_eth_vmdq_rx_conf", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).nb_queue_pools) as usize - ptr as usize }, - 0usize, - "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, - "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, - "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, - "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, - "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, - "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, - "Offset of field: rte_eth_vmdq_rx_conf::pool_map", - ); -} -impl Clone for rte_eth_vmdq_rx_conf { - fn clone(&self) -> Self { - *self - } -} -impl Default for rte_eth_vmdq_rx_conf { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} -#[repr(u32)] -/// Flow Director setting modes: none, signature or perfect. -#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] -pub enum rte_fdir_mode { - ///< Disable FDIR support. - RTE_FDIR_MODE_NONE = 0, - ///< Enable FDIR signature filter mode. - RTE_FDIR_MODE_SIGNATURE = 1, - ///< Enable FDIR perfect filter mode. - RTE_FDIR_MODE_PERFECT = 2, - ///< Enable FDIR filter mode - MAC VLAN. - RTE_FDIR_MODE_PERFECT_MAC_VLAN = 3, - ///< Enable FDIR filter mode - tunnel. - RTE_FDIR_MODE_PERFECT_TUNNEL = 4, -} -#[repr(u32)] -/** Memory space that can be configured to store Flow Director filters - in the board memory.*/ -#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] -pub enum rte_fdir_pballoc_type { - ///< 64k. - RTE_FDIR_PBALLOC_64K = 0, - ///< 128k. - RTE_FDIR_PBALLOC_128K = 1, - ///< 256k. - RTE_FDIR_PBALLOC_256K = 2, -} -#[repr(u32)] -/// Select report mode of FDIR hash information in RX descriptors. -#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] -pub enum rte_fdir_status_mode { - ///< Never report FDIR hash. - RTE_FDIR_NO_REPORT_STATUS = 0, - ///< Only report FDIR hash for matching pkts. - RTE_FDIR_REPORT_STATUS = 1, - ///< Always report FDIR hash. - RTE_FDIR_REPORT_STATUS_ALWAYS = 2, -} -/// A structure used to define the input for IPV4 flow -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct rte_eth_ipv4_flow { - ///< IPv4 source address in big endian. - pub src_ip: u32, - ///< IPv4 destination address in big endian. - pub dst_ip: u32, - ///< Type of service to match. - pub tos: u8, - ///< Time to live to match. - pub ttl: u8, - ///< 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, - "Alignment of rte_eth_ipv4_flow", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize }, - 0usize, - "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, - "Offset of field: rte_eth_ipv4_flow::dst_ip", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).tos) as usize - ptr as usize }, - 8usize, - "Offset of field: rte_eth_ipv4_flow::tos", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ttl) as usize - ptr as usize }, - 9usize, - "Offset of field: rte_eth_ipv4_flow::ttl", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize }, - 10usize, - "Offset of field: rte_eth_ipv4_flow::proto", - ); -} -impl Clone for rte_eth_ipv4_flow { - fn clone(&self) -> Self { - *self - } -} -/// A structure used to define the input for IPV6 flow -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct rte_eth_ipv6_flow { - ///< IPv6 source address in big endian. - pub src_ip: [u32; 4usize], - ///< IPv6 destination address in big endian. - pub dst_ip: [u32; 4usize], - ///< Traffic class to match. - pub tc: u8, - ///< Protocol, next header to match. - pub proto: u8, - ///< 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, - "Alignment of rte_eth_ipv6_flow", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).src_ip) as usize - ptr as usize }, - 0usize, - "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, - "Offset of field: rte_eth_ipv6_flow::dst_ip", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).tc) as usize - ptr as usize }, - 32usize, - "Offset of field: rte_eth_ipv6_flow::tc", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize }, - 33usize, - "Offset of field: rte_eth_ipv6_flow::proto", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).hop_limits) as usize - ptr as usize }, - 34usize, - "Offset of field: rte_eth_ipv6_flow::hop_limits", - ); -} -impl Clone for rte_eth_ipv6_flow { - fn clone(&self) -> Self { - *self - } -} -/** A structure used to configure FDIR masks that are used by the device - to match the various fields of RX packet headers.*/ -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct rte_eth_fdir_masks { - ///< Bit mask for vlan_tci in big endian - pub vlan_tci_mask: u16, - /// Bit mask for ipv4 flow in big endian. - pub ipv4_mask: rte_eth_ipv4_flow, - /// Bit maks for ipv6 flow in big endian. - pub ipv6_mask: rte_eth_ipv6_flow, - /// Bit mask for L4 source port in big endian. - pub src_port_mask: u16, - /// Bit mask for L4 destination port in big endian. - pub dst_port_mask: u16, - /** 6 bit mask for proper 6 bytes of Mac address, bit 0 matches the -first byte on the wire*/ - pub mac_addr_byte_mask: u8, - /// Bit mask for tunnel ID in big endian. - pub tunnel_id_mask: u32, - /**< 1 - Match tunnel type, -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, - "Size of rte_eth_fdir_masks", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - "Alignment of rte_eth_fdir_masks", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).vlan_tci_mask) as usize - ptr as usize }, - 0usize, - "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, - "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, - "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, - "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, - "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, - "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, - "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, - "Offset of field: rte_eth_fdir_masks::tunnel_type_mask", - ); -} -impl Clone for rte_eth_fdir_masks { - fn clone(&self) -> Self { - *self - } -} -#[repr(u32)] -/// Payload type -#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] -pub enum rte_eth_payload_type { - RTE_ETH_PAYLOAD_UNKNOWN = 0, - RTE_ETH_RAW_PAYLOAD = 1, - RTE_ETH_L2_PAYLOAD = 2, - RTE_ETH_L3_PAYLOAD = 3, - RTE_ETH_L4_PAYLOAD = 4, - RTE_ETH_PAYLOAD_MAX = 8, -} -/** A structure used to select bytes extracted from the protocol layers to - flexible payload for filter*/ -#[repr(C)] -#[derive(Debug, Copy, Hash, PartialEq, Eq)] -pub struct rte_eth_flex_payload_cfg { - ///< Payload type - 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, - "Size of rte_eth_flex_payload_cfg", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - "Alignment of rte_eth_flex_payload_cfg", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize }, - 0usize, - "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, - "Offset of field: rte_eth_flex_payload_cfg::src_offset", - ); -} -impl Clone for rte_eth_flex_payload_cfg { - fn clone(&self) -> Self { - *self - } -} -impl Default for rte_eth_flex_payload_cfg { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} -/** A structure used to define FDIR masks for flexible payload - for each flow type*/ -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -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, - "Size of rte_eth_fdir_flex_mask", - ); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - "Alignment of rte_eth_fdir_flex_mask", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).flow_type) as usize - ptr as usize }, - 0usize, - "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, - "Offset of field: rte_eth_fdir_flex_mask::mask", - ); -} -impl Clone for rte_eth_fdir_flex_mask { - fn clone(&self) -> Self { - *self - } -} -/** A structure used to define all flexible payload related setting - include flex payload and flex mask*/ -#[repr(C)] -#[derive(Debug, Copy, Hash, PartialEq, Eq)] -pub struct rte_eth_fdir_flex_conf { - ///< The number of following payload cfg - pub nb_payloads: u16, - ///< The number of following mask - pub nb_flexmasks: u16, - 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, - "Size of rte_eth_fdir_flex_conf", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - "Alignment of rte_eth_fdir_flex_conf", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).nb_payloads) as usize - ptr as usize }, - 0usize, - "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, - "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, - "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, - "Offset of field: rte_eth_fdir_flex_conf::flex_mask", - ); -} -impl Clone for rte_eth_fdir_flex_conf { - fn clone(&self) -> Self { - *self - } -} -impl Default for rte_eth_fdir_flex_conf { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} -/** A structure used to configure the Flow Director (FDIR) feature - of an Ethernet port. - - If mode is RTE_FDIR_DISABLE, the pballoc value is ignored.*/ -#[repr(C)] -#[derive(Debug, Copy, Hash, PartialEq, Eq)] -pub struct rte_fdir_conf { - ///< Flow Director mode. - pub mode: rte_fdir_mode, - ///< Space for FDIR filters. - pub pballoc: rte_fdir_pballoc_type, - ///< How to report FDIR hash. - pub status: rte_fdir_status_mode, - /// RX queue of packets matching a "drop" filter in perfect mode. - pub drop_queue: u8, - 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, - "Offset of field: rte_fdir_conf::mode", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).pballoc) as usize - ptr as usize }, - 4usize, - "Offset of field: rte_fdir_conf::pballoc", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).status) as usize - ptr as usize }, - 8usize, - "Offset of field: rte_fdir_conf::status", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).drop_queue) as usize - ptr as usize }, - 12usize, - "Offset of field: rte_fdir_conf::drop_queue", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mask) as usize - ptr as usize }, - 16usize, - "Offset of field: rte_fdir_conf::mask", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).flex_conf) as usize - ptr as usize }, - 84usize, - "Offset of field: rte_fdir_conf::flex_conf", - ); -} -impl Clone for rte_fdir_conf { - fn clone(&self) -> Self { - *self - } -} -impl Default for rte_fdir_conf { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} -/// A structure used to enable/disable specific device interrupts. -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct rte_intr_conf { - /// enable/disable lsc interrupt. 0 (default) - disable, 1 enable - pub lsc: u16, - /// 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, - "Offset of field: rte_intr_conf::lsc", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).rxq) as usize - ptr as usize }, - 2usize, - "Offset of field: rte_intr_conf::rxq", - ); -} -impl Clone for rte_intr_conf { - fn clone(&self) -> Self { - *self - } -} -/** A structure used to configure an Ethernet port. - Depending upon the RX multi-queue mode, extra advanced - configuration settings may be needed.*/ -#[repr(C)] -#[derive(Copy)] -pub struct rte_eth_conf { - /**< bitmap of ETH_LINK_SPEED_XXX of speeds to be -used. ETH_LINK_SPEED_FIXED disables link -autonegotiation, and a unique speed shall be -set. Otherwise, the bitmap defines the set of -speeds to be advertised. If the special value -ETH_LINK_SPEED_AUTONEG (0) is used, all speeds -supported are advertised.*/ - pub link_speeds: u32, - ///< Port RX configuration. - pub rxmode: rte_eth_rxmode, - ///< Port TX configuration. - pub txmode: rte_eth_txmode, - /**< Loopback operation mode. By default the value -is 0, meaning the loopback mode is disabled. -Read the datasheet of given ethernet controller -for details. The possible values of this field -are defined in implementation of each driver.*/ - pub lpbk_mode: u32, - ///< Port RX filtering configuration (union). - pub rx_adv_conf: rte_eth_conf__bindgen_ty_1, - ///< Port TX DCB configuration (union). - pub tx_adv_conf: rte_eth_conf__bindgen_ty_2, - /** Currently,Priority Flow Control(PFC) are supported,if DCB with PFC -is needed,and the variable must be set ETH_DCB_PFC_SUPPORT.*/ - pub dcb_capability_en: u32, - ///< FDIR configuration. - pub fdir_conf: rte_fdir_conf, - ///< Interrupt mode configuration. - pub intr_conf: rte_intr_conf, -} -#[repr(C)] -#[derive(Copy)] -pub struct rte_eth_conf__bindgen_ty_1 { - ///< Port RSS configuration - pub rss_conf: rte_eth_rss_conf, - pub vmdq_dcb_conf: rte_eth_vmdq_dcb_conf, - 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, - "Size of rte_eth_conf__bindgen_ty_1", - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - "Alignment of rte_eth_conf__bindgen_ty_1", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).rss_conf) as usize - ptr as usize }, - 0usize, - "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, - "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, - "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, - "Offset of field: rte_eth_conf__bindgen_ty_1::vmdq_rx_conf", - ); -} -impl Clone for rte_eth_conf__bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} -impl Default for rte_eth_conf__bindgen_ty_1 { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct rte_eth_conf__bindgen_ty_2 { - pub vmdq_dcb_tx_conf: __BindgenUnionField, - pub dcb_tx_conf: __BindgenUnionField, - pub vmdq_tx_conf: __BindgenUnionField, - pub bindgen_union_field: [u32; 3usize], -} -#[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, - "Size of rte_eth_conf__bindgen_ty_2", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - "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, - "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, - "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, - "Offset of field: rte_eth_conf__bindgen_ty_2::vmdq_tx_conf", - ); -} -impl Clone for rte_eth_conf__bindgen_ty_2 { - fn clone(&self) -> Self { - *self - } -} -#[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, - "Offset of field: rte_eth_conf::link_speeds", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).rxmode) as usize - ptr as usize }, - 4usize, - "Offset of field: rte_eth_conf::rxmode", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).txmode) as usize - ptr as usize }, - 16usize, - "Offset of field: rte_eth_conf::txmode", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).lpbk_mode) as usize - ptr as usize }, - 24usize, - "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, - "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, - "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, - "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, - "Offset of field: rte_eth_conf::fdir_conf", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).intr_conf) as usize - ptr as usize }, - 2940usize, - "Offset of field: rte_eth_conf::intr_conf", - ); -} -impl Clone for rte_eth_conf { - fn clone(&self) -> Self { - *self - } -} -impl Default for rte_eth_conf { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} diff --git a/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs b/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs deleted file mode 100644 index 38e221f3ca..0000000000 --- a/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs +++ /dev/null @@ -1,1047 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit { - storage: Storage, -} -impl __BindgenBitfieldUnit { - #[inline] - pub 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] - 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 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 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); - } - } -} -#[repr(C)] -pub struct __BindgenUnionField(::std::marker::PhantomData); -impl __BindgenUnionField { - #[inline] - pub fn new() -> Self { - __BindgenUnionField(::std::marker::PhantomData) - } - #[inline] - pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) - } - #[inline] - pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) - } -} -impl ::std::default::Default for __BindgenUnionField { - #[inline] - fn default() -> Self { - Self::new() - } -} -impl ::std::clone::Clone for __BindgenUnionField { - #[inline] - fn clone(&self) -> Self { - *self - } -} -impl ::std::marker::Copy for __BindgenUnionField {} -impl ::std::fmt::Debug for __BindgenUnionField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__BindgenUnionField") - } -} -impl ::std::hash::Hash for __BindgenUnionField { - fn hash(&self, _state: &mut H) {} -} -impl ::std::cmp::PartialEq for __BindgenUnionField { - fn eq(&self, _other: &__BindgenUnionField) -> bool { - true - } -} -impl ::std::cmp::Eq for __BindgenUnionField {} -pub const RTE_CACHE_LINE_MIN_SIZE: u32 = 64; -pub const RTE_CACHE_LINE_SIZE: u32 = 64; -pub type phys_addr_t = u64; -pub type MARKER = [*mut ::std::os::raw::c_void; 0usize]; -pub type MARKER8 = [u8; 0usize]; -pub type MARKER64 = [u64; 0usize]; -/// The atomic counter structure. -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct rte_atomic16_t { - ///< An internal counter value. - pub cnt: i16, -} -#[test] -fn bindgen_test_layout_rte_atomic16_t() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 2usize, - "Size of rte_atomic16_t", - ); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - "Alignment of rte_atomic16_t", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).cnt) as usize - ptr as usize }, - 0usize, - "Offset of field: rte_atomic16_t::cnt", - ); -} -impl Clone for rte_atomic16_t { - fn clone(&self) -> Self { - *self - } -} -/// The generic rte_mbuf, containing a packet mbuf. -#[repr(C)] -pub struct rte_mbuf { - pub cacheline0: MARKER, - ///< Virtual address of segment buffer. - pub buf_addr: *mut ::std::os::raw::c_void, - ///< Physical address of segment buffer. - pub buf_physaddr: phys_addr_t, - ///< Length of segment buffer. - pub buf_len: u16, - pub rearm_data: MARKER8, - pub data_off: u16, - pub __bindgen_anon_1: rte_mbuf__bindgen_ty_1, - ///< Number of segments. - pub nb_segs: u8, - ///< Input port. - pub port: u8, - ///< Offload features. - pub ol_flags: u64, - pub rx_descriptor_fields1: MARKER, - pub __bindgen_anon_2: rte_mbuf__bindgen_ty_2, - ///< Total pkt len: sum of all segments. - pub pkt_len: u32, - ///< Amount of data in segment buffer. - pub data_len: u16, - /// VLAN TCI (CPU order), valid if PKT_RX_VLAN_STRIPPED is set. - pub vlan_tci: u16, - ///< hash information - pub hash: rte_mbuf__bindgen_ty_3, - ///< Sequence number. See also rte_reorder_insert() - pub seqn: u32, - /// Outer VLAN TCI (CPU order), valid if PKT_RX_QINQ_STRIPPED is set. - pub vlan_tci_outer: u16, - pub cacheline1: MARKER, - pub __bindgen_anon_3: rte_mbuf__bindgen_ty_4, - ///< Pool from which mbuf was allocated. - pub pool: *mut rte_mempool, - ///< Next segment of scattered packet. - pub next: *mut rte_mbuf, - pub __bindgen_anon_4: rte_mbuf__bindgen_ty_5, - /** Size of the application private data. In case of an indirect - mbuf, it stores the direct mbuf private data size.*/ - pub priv_size: u16, - /// Timesync flags for use with IEEE1588. - pub timesync: u16, - pub __bindgen_padding_0: [u32; 7usize], -} -/** 16-bit Reference counter. - It should only be accessed using the following functions: - rte_mbuf_refcnt_update(), rte_mbuf_refcnt_read(), and - rte_mbuf_refcnt_set(). The functionality of these functions (atomic, - or non-atomic) is controlled by the CONFIG_RTE_MBUF_REFCNT_ATOMIC - config option.*/ -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct rte_mbuf__bindgen_ty_1 { - ///< Atomically accessed refcnt - pub refcnt_atomic: __BindgenUnionField, - ///< Non-atomically accessed refcnt - pub refcnt: __BindgenUnionField, - pub bindgen_union_field: u16, -} -#[test] -fn bindgen_test_layout_rte_mbuf__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 2usize, - "Size of rte_mbuf__bindgen_ty_1", - ); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - "Alignment of rte_mbuf__bindgen_ty_1", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).refcnt_atomic) as usize - ptr as usize }, - 0usize, - "Offset of field: rte_mbuf__bindgen_ty_1::refcnt_atomic", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).refcnt) as usize - ptr as usize }, - 0usize, - "Offset of field: rte_mbuf__bindgen_ty_1::refcnt", - ); -} -impl Clone for rte_mbuf__bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct rte_mbuf__bindgen_ty_2 { - ///< L2/L3/L4 and tunnel information. - pub packet_type: __BindgenUnionField, - pub __bindgen_anon_1: __BindgenUnionField, - pub bindgen_union_field: u32, -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct rte_mbuf__bindgen_ty_2__bindgen_ty_1 { - pub _bitfield_align_1: [u8; 0], - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, - pub __bindgen_align: [u32; 0usize], -} -#[test] -fn bindgen_test_layout_rte_mbuf__bindgen_ty_2__bindgen_ty_1() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - "Size of rte_mbuf__bindgen_ty_2__bindgen_ty_1", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - "Alignment of rte_mbuf__bindgen_ty_2__bindgen_ty_1", - ); -} -impl Clone for rte_mbuf__bindgen_ty_2__bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} -impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { - #[inline] - pub fn l2_type(&self) -> u32 { - unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 4u8) as u32) } - } - #[inline] - pub fn set_l2_type(&mut self, val: u32) { - unsafe { - let val: u32 = ::std::mem::transmute(val); - self._bitfield_1.set(0usize, 4u8, val as u64) - } - } - #[inline] - pub fn l3_type(&self) -> u32 { - unsafe { ::std::mem::transmute(self._bitfield_1.get(4usize, 4u8) as u32) } - } - #[inline] - pub fn set_l3_type(&mut self, val: u32) { - unsafe { - let val: u32 = ::std::mem::transmute(val); - self._bitfield_1.set(4usize, 4u8, val as u64) - } - } - #[inline] - pub fn l4_type(&self) -> u32 { - unsafe { ::std::mem::transmute(self._bitfield_1.get(8usize, 4u8) as u32) } - } - #[inline] - pub fn set_l4_type(&mut self, val: u32) { - unsafe { - let val: u32 = ::std::mem::transmute(val); - self._bitfield_1.set(8usize, 4u8, val as u64) - } - } - #[inline] - pub fn tun_type(&self) -> u32 { - unsafe { ::std::mem::transmute(self._bitfield_1.get(12usize, 4u8) as u32) } - } - #[inline] - pub fn set_tun_type(&mut self, val: u32) { - unsafe { - let val: u32 = ::std::mem::transmute(val); - self._bitfield_1.set(12usize, 4u8, val as u64) - } - } - #[inline] - pub fn inner_l2_type(&self) -> u32 { - unsafe { ::std::mem::transmute(self._bitfield_1.get(16usize, 4u8) as u32) } - } - #[inline] - pub fn set_inner_l2_type(&mut self, val: u32) { - unsafe { - let val: u32 = ::std::mem::transmute(val); - self._bitfield_1.set(16usize, 4u8, val as u64) - } - } - #[inline] - pub fn inner_l3_type(&self) -> u32 { - unsafe { ::std::mem::transmute(self._bitfield_1.get(20usize, 4u8) as u32) } - } - #[inline] - pub fn set_inner_l3_type(&mut self, val: u32) { - unsafe { - let val: u32 = ::std::mem::transmute(val); - self._bitfield_1.set(20usize, 4u8, val as u64) - } - } - #[inline] - pub fn inner_l4_type(&self) -> u32 { - unsafe { ::std::mem::transmute(self._bitfield_1.get(24usize, 4u8) as u32) } - } - #[inline] - pub fn set_inner_l4_type(&mut self, val: u32) { - unsafe { - let val: u32 = ::std::mem::transmute(val); - self._bitfield_1.set(24usize, 4u8, val as u64) - } - } - #[inline] - pub fn new_bitfield_1( - l2_type: u32, - l3_type: u32, - l4_type: u32, - tun_type: u32, - inner_l2_type: u32, - inner_l3_type: u32, - inner_l4_type: u32, - ) -> __BindgenBitfieldUnit<[u8; 4usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = Default::default(); - __bindgen_bitfield_unit - .set( - 0usize, - 4u8, - { - let l2_type: u32 = unsafe { ::std::mem::transmute(l2_type) }; - l2_type as u64 - }, - ); - __bindgen_bitfield_unit - .set( - 4usize, - 4u8, - { - let l3_type: u32 = unsafe { ::std::mem::transmute(l3_type) }; - l3_type as u64 - }, - ); - __bindgen_bitfield_unit - .set( - 8usize, - 4u8, - { - let l4_type: u32 = unsafe { ::std::mem::transmute(l4_type) }; - l4_type as u64 - }, - ); - __bindgen_bitfield_unit - .set( - 12usize, - 4u8, - { - let tun_type: u32 = unsafe { ::std::mem::transmute(tun_type) }; - tun_type as u64 - }, - ); - __bindgen_bitfield_unit - .set( - 16usize, - 4u8, - { - let inner_l2_type: u32 = unsafe { - ::std::mem::transmute(inner_l2_type) - }; - inner_l2_type as u64 - }, - ); - __bindgen_bitfield_unit - .set( - 20usize, - 4u8, - { - let inner_l3_type: u32 = unsafe { - ::std::mem::transmute(inner_l3_type) - }; - inner_l3_type as u64 - }, - ); - __bindgen_bitfield_unit - .set( - 24usize, - 4u8, - { - let inner_l4_type: u32 = unsafe { - ::std::mem::transmute(inner_l4_type) - }; - inner_l4_type as u64 - }, - ); - __bindgen_bitfield_unit - } -} -#[test] -fn bindgen_test_layout_rte_mbuf__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - "Size of rte_mbuf__bindgen_ty_2", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - "Alignment of rte_mbuf__bindgen_ty_2", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).packet_type) as usize - ptr as usize }, - 0usize, - "Offset of field: rte_mbuf__bindgen_ty_2::packet_type", - ); -} -impl Clone for rte_mbuf__bindgen_ty_2 { - fn clone(&self) -> Self { - *self - } -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct rte_mbuf__bindgen_ty_3 { - ///< RSS hash result if RSS enabled - pub rss: __BindgenUnionField, - ///< Filter identifier if FDIR enabled - pub fdir: __BindgenUnionField, - ///< Hierarchical scheduler - pub sched: __BindgenUnionField, - ///< User defined tags. See rte_distributor_process() - pub usr: __BindgenUnionField, - pub bindgen_union_field: [u32; 2usize], -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct rte_mbuf__bindgen_ty_3__bindgen_ty_1 { - pub __bindgen_anon_1: rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1, - pub hi: u32, -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 { - pub __bindgen_anon_1: __BindgenUnionField< - rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1, - >, - pub lo: __BindgenUnionField, - pub bindgen_union_field: u32, -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 { - pub hash: u16, - pub id: u16, -} -#[test] -fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit< - rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1, - > = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::< - rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1, - >(), - 4usize, - "Size of rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1", - ); - assert_eq!( - ::std::mem::align_of::< - rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1, - >(), - 2usize, - "Alignment of rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).hash) as usize - ptr as usize }, - 0usize, - "Offset of field: rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1::hash", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).id) as usize - ptr as usize }, - 2usize, - "Offset of field: rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1::id", - ); -} -impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} -#[test] -fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit< - rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1, - > = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - "Size of rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - "Alignment of rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).lo) as usize - ptr as usize }, - 0usize, - "Offset of field: rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1::lo", - ); -} -impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_1__bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} -#[test] -fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - "Size of rte_mbuf__bindgen_ty_3__bindgen_ty_1", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - "Alignment of rte_mbuf__bindgen_ty_3__bindgen_ty_1", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).hi) as usize - ptr as usize }, - 4usize, - "Offset of field: rte_mbuf__bindgen_ty_3__bindgen_ty_1::hi", - ); -} -impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct rte_mbuf__bindgen_ty_3__bindgen_ty_2 { - pub lo: u32, - pub hi: u32, -} -#[test] -fn bindgen_test_layout_rte_mbuf__bindgen_ty_3__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - "Size of rte_mbuf__bindgen_ty_3__bindgen_ty_2", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - "Alignment of rte_mbuf__bindgen_ty_3__bindgen_ty_2", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).lo) as usize - ptr as usize }, - 0usize, - "Offset of field: rte_mbuf__bindgen_ty_3__bindgen_ty_2::lo", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).hi) as usize - ptr as usize }, - 4usize, - "Offset of field: rte_mbuf__bindgen_ty_3__bindgen_ty_2::hi", - ); -} -impl Clone for rte_mbuf__bindgen_ty_3__bindgen_ty_2 { - fn clone(&self) -> Self { - *self - } -} -#[test] -fn bindgen_test_layout_rte_mbuf__bindgen_ty_3() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - "Size of rte_mbuf__bindgen_ty_3", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - "Alignment of rte_mbuf__bindgen_ty_3", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).rss) as usize - ptr as usize }, - 0usize, - "Offset of field: rte_mbuf__bindgen_ty_3::rss", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).fdir) as usize - ptr as usize }, - 0usize, - "Offset of field: rte_mbuf__bindgen_ty_3::fdir", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).sched) as usize - ptr as usize }, - 0usize, - "Offset of field: rte_mbuf__bindgen_ty_3::sched", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).usr) as usize - ptr as usize }, - 0usize, - "Offset of field: rte_mbuf__bindgen_ty_3::usr", - ); -} -impl Clone for rte_mbuf__bindgen_ty_3 { - fn clone(&self) -> Self { - *self - } -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct rte_mbuf__bindgen_ty_4 { - ///< Can be used for external metadata - pub userdata: __BindgenUnionField<*mut ::std::os::raw::c_void>, - ///< Allow 8-byte userdata on 32-bit - pub udata64: __BindgenUnionField, - pub bindgen_union_field: u64, -} -#[test] -fn bindgen_test_layout_rte_mbuf__bindgen_ty_4() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - "Size of rte_mbuf__bindgen_ty_4", - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - "Alignment of rte_mbuf__bindgen_ty_4", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).userdata) as usize - ptr as usize }, - 0usize, - "Offset of field: rte_mbuf__bindgen_ty_4::userdata", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).udata64) as usize - ptr as usize }, - 0usize, - "Offset of field: rte_mbuf__bindgen_ty_4::udata64", - ); -} -impl Clone for rte_mbuf__bindgen_ty_4 { - fn clone(&self) -> Self { - *self - } -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct rte_mbuf__bindgen_ty_5 { - ///< combined for easy fetch - pub tx_offload: __BindgenUnionField, - pub __bindgen_anon_1: __BindgenUnionField, - pub bindgen_union_field: u64, -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct rte_mbuf__bindgen_ty_5__bindgen_ty_1 { - pub _bitfield_align_1: [u16; 0], - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 7usize]>, - pub __bindgen_align: [u64; 0usize], -} -#[test] -fn bindgen_test_layout_rte_mbuf__bindgen_ty_5__bindgen_ty_1() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - "Size of rte_mbuf__bindgen_ty_5__bindgen_ty_1", - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - "Alignment of rte_mbuf__bindgen_ty_5__bindgen_ty_1", - ); -} -impl Clone for rte_mbuf__bindgen_ty_5__bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} -impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { - #[inline] - pub fn l2_len(&self) -> u64 { - unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 7u8) as u64) } - } - #[inline] - pub fn set_l2_len(&mut self, val: u64) { - unsafe { - let val: u64 = ::std::mem::transmute(val); - self._bitfield_1.set(0usize, 7u8, val as u64) - } - } - #[inline] - pub fn l3_len(&self) -> u64 { - unsafe { ::std::mem::transmute(self._bitfield_1.get(7usize, 9u8) as u64) } - } - #[inline] - pub fn set_l3_len(&mut self, val: u64) { - unsafe { - let val: u64 = ::std::mem::transmute(val); - self._bitfield_1.set(7usize, 9u8, val as u64) - } - } - #[inline] - pub fn l4_len(&self) -> u64 { - unsafe { ::std::mem::transmute(self._bitfield_1.get(16usize, 8u8) as u64) } - } - #[inline] - pub fn set_l4_len(&mut self, val: u64) { - unsafe { - let val: u64 = ::std::mem::transmute(val); - self._bitfield_1.set(16usize, 8u8, val as u64) - } - } - #[inline] - pub fn tso_segsz(&self) -> u64 { - unsafe { ::std::mem::transmute(self._bitfield_1.get(24usize, 16u8) as u64) } - } - #[inline] - pub fn set_tso_segsz(&mut self, val: u64) { - unsafe { - let val: u64 = ::std::mem::transmute(val); - self._bitfield_1.set(24usize, 16u8, val as u64) - } - } - #[inline] - pub fn outer_l3_len(&self) -> u64 { - unsafe { ::std::mem::transmute(self._bitfield_1.get(40usize, 9u8) as u64) } - } - #[inline] - pub fn set_outer_l3_len(&mut self, val: u64) { - unsafe { - let val: u64 = ::std::mem::transmute(val); - self._bitfield_1.set(40usize, 9u8, val as u64) - } - } - #[inline] - pub fn outer_l2_len(&self) -> u64 { - unsafe { ::std::mem::transmute(self._bitfield_1.get(49usize, 7u8) as u64) } - } - #[inline] - pub fn set_outer_l2_len(&mut self, val: u64) { - unsafe { - let val: u64 = ::std::mem::transmute(val); - self._bitfield_1.set(49usize, 7u8, val as u64) - } - } - #[inline] - pub fn new_bitfield_1( - l2_len: u64, - l3_len: u64, - l4_len: u64, - tso_segsz: u64, - outer_l3_len: u64, - outer_l2_len: u64, - ) -> __BindgenBitfieldUnit<[u8; 7usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 7usize]> = Default::default(); - __bindgen_bitfield_unit - .set( - 0usize, - 7u8, - { - let l2_len: u64 = unsafe { ::std::mem::transmute(l2_len) }; - l2_len as u64 - }, - ); - __bindgen_bitfield_unit - .set( - 7usize, - 9u8, - { - let l3_len: u64 = unsafe { ::std::mem::transmute(l3_len) }; - l3_len as u64 - }, - ); - __bindgen_bitfield_unit - .set( - 16usize, - 8u8, - { - let l4_len: u64 = unsafe { ::std::mem::transmute(l4_len) }; - l4_len as u64 - }, - ); - __bindgen_bitfield_unit - .set( - 24usize, - 16u8, - { - let tso_segsz: u64 = unsafe { ::std::mem::transmute(tso_segsz) }; - tso_segsz as u64 - }, - ); - __bindgen_bitfield_unit - .set( - 40usize, - 9u8, - { - let outer_l3_len: u64 = unsafe { - ::std::mem::transmute(outer_l3_len) - }; - outer_l3_len as u64 - }, - ); - __bindgen_bitfield_unit - .set( - 49usize, - 7u8, - { - let outer_l2_len: u64 = unsafe { - ::std::mem::transmute(outer_l2_len) - }; - outer_l2_len as u64 - }, - ); - __bindgen_bitfield_unit - } -} -#[test] -fn bindgen_test_layout_rte_mbuf__bindgen_ty_5() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - "Size of rte_mbuf__bindgen_ty_5", - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - "Alignment of rte_mbuf__bindgen_ty_5", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).tx_offload) as usize - ptr as usize }, - 0usize, - "Offset of field: rte_mbuf__bindgen_ty_5::tx_offload", - ); -} -impl Clone for rte_mbuf__bindgen_ty_5 { - fn clone(&self) -> Self { - *self - } -} -#[test] -fn bindgen_test_layout_rte_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_mbuf"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).cacheline0) as usize - ptr as usize }, - 0usize, - "Offset of field: rte_mbuf::cacheline0", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).buf_addr) as usize - ptr as usize }, - 0usize, - "Offset of field: rte_mbuf::buf_addr", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).buf_physaddr) as usize - ptr as usize }, - 8usize, - "Offset of field: rte_mbuf::buf_physaddr", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).buf_len) as usize - ptr as usize }, - 16usize, - "Offset of field: rte_mbuf::buf_len", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).rearm_data) as usize - ptr as usize }, - 18usize, - "Offset of field: rte_mbuf::rearm_data", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).data_off) as usize - ptr as usize }, - 18usize, - "Offset of field: rte_mbuf::data_off", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).nb_segs) as usize - ptr as usize }, - 22usize, - "Offset of field: rte_mbuf::nb_segs", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).port) as usize - ptr as usize }, - 23usize, - "Offset of field: rte_mbuf::port", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).ol_flags) as usize - ptr as usize }, - 24usize, - "Offset of field: rte_mbuf::ol_flags", - ); - assert_eq!( - unsafe { - ::std::ptr::addr_of!((*ptr).rx_descriptor_fields1) as usize - ptr as usize - }, - 32usize, - "Offset of field: rte_mbuf::rx_descriptor_fields1", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).pkt_len) as usize - ptr as usize }, - 36usize, - "Offset of field: rte_mbuf::pkt_len", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).data_len) as usize - ptr as usize }, - 40usize, - "Offset of field: rte_mbuf::data_len", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).vlan_tci) as usize - ptr as usize }, - 42usize, - "Offset of field: rte_mbuf::vlan_tci", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).hash) as usize - ptr as usize }, - 44usize, - "Offset of field: rte_mbuf::hash", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).seqn) as usize - ptr as usize }, - 52usize, - "Offset of field: rte_mbuf::seqn", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).vlan_tci_outer) as usize - ptr as usize }, - 56usize, - "Offset of field: rte_mbuf::vlan_tci_outer", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).cacheline1) as usize - ptr as usize }, - 64usize, - "Offset of field: rte_mbuf::cacheline1", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).pool) as usize - ptr as usize }, - 72usize, - "Offset of field: rte_mbuf::pool", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize }, - 80usize, - "Offset of field: rte_mbuf::next", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).priv_size) as usize - ptr as usize }, - 96usize, - "Offset of field: rte_mbuf::priv_size", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).timesync) as usize - ptr as usize }, - 98usize, - "Offset of field: rte_mbuf::timesync", - ); -} -impl Default for rte_mbuf { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} -///< Pool from which mbuf was allocated. -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct rte_mempool { - pub _address: u8, -} -impl Clone for rte_mempool { - fn clone(&self) -> Self { - *self - } -} diff --git a/bindgen-tests/tests/expectations/tests/macro_const_1_0.rs b/bindgen-tests/tests/expectations/tests/macro_const_1_0.rs deleted file mode 100644 index 2f3e228d80..0000000000 --- a/bindgen-tests/tests/expectations/tests/macro_const_1_0.rs +++ /dev/null @@ -1,8 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -pub const foo: &'static [u8; 4] = b"bar\0"; -pub const CHAR: u8 = 98u8; -pub const CHARR: u8 = 0u8; -pub const FLOAT: f64 = 5.09; -pub const FLOAT_EXPR: f64 = 0.005; -pub const LONG: u32 = 3; -pub const INVALID_UTF8: &'static [u8; 5] = b"\xF0(\x8C(\0"; diff --git a/bindgen-tests/tests/expectations/tests/strings_array.rs b/bindgen-tests/tests/expectations/tests/strings_array.rs index 6f352b32ca..12543e59a8 100644 --- a/bindgen-tests/tests/expectations/tests/strings_array.rs +++ b/bindgen-tests/tests/expectations/tests/strings_array.rs @@ -1,4 +1,4 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -pub const MY_STRING_UTF8: &'static [u8; 14] = b"Hello, world!\0"; -pub const MY_STRING_INTERIOR_NULL: &'static [u8; 7] = b"Hello,\0"; -pub const MY_STRING_NON_UTF8: &'static [u8; 7] = b"ABCDE\xFF\0"; +pub const MY_STRING_UTF8: &[u8; 14] = b"Hello, world!\0"; +pub const MY_STRING_INTERIOR_NULL: &[u8; 7] = b"Hello,\0"; +pub const MY_STRING_NON_UTF8: &[u8; 7] = b"ABCDE\xFF\0"; diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_union_1_0.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_union_1_0.rs deleted file mode 100644 index dda2d06eb8..0000000000 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_union_1_0.rs +++ /dev/null @@ -1,103 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -pub struct __BindgenUnionField(::std::marker::PhantomData); -impl __BindgenUnionField { - #[inline] - pub fn new() -> Self { - __BindgenUnionField(::std::marker::PhantomData) - } - #[inline] - pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) - } - #[inline] - pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) - } -} -impl ::std::default::Default for __BindgenUnionField { - #[inline] - fn default() -> Self { - Self::new() - } -} -impl ::std::clone::Clone for __BindgenUnionField { - #[inline] - fn clone(&self) -> Self { - *self - } -} -impl ::std::marker::Copy for __BindgenUnionField {} -impl ::std::fmt::Debug for __BindgenUnionField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__BindgenUnionField") - } -} -impl ::std::hash::Hash for __BindgenUnionField { - fn hash(&self, _state: &mut H) {} -} -impl ::std::cmp::PartialEq for __BindgenUnionField { - fn eq(&self, _other: &__BindgenUnionField) -> bool { - true - } -} -impl ::std::cmp::Eq for __BindgenUnionField {} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct foo { - pub bar: foo__bindgen_ty_1, -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct foo__bindgen_ty_1 { - pub a: __BindgenUnionField<::std::os::raw::c_uint>, - pub b: __BindgenUnionField<::std::os::raw::c_ushort>, - pub bindgen_union_field: u32, -} -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - "Size of foo__bindgen_ty_1", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - "Alignment of foo__bindgen_ty_1", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - "Offset of field: foo__bindgen_ty_1::a", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - "Offset of field: foo__bindgen_ty_1::b", - ); -} -impl Clone for foo__bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} -#[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::(), 4usize, "Size of foo"); - assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of foo"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - "Offset of field: foo::bar", - ); -} -impl Clone for foo { - fn clone(&self) -> Self { - *self - } -} diff --git a/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs b/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs deleted file mode 100644 index b9977c688b..0000000000 --- a/bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs +++ /dev/null @@ -1,96 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -pub struct __BindgenUnionField(::std::marker::PhantomData); -impl __BindgenUnionField { - #[inline] - pub fn new() -> Self { - __BindgenUnionField(::std::marker::PhantomData) - } - #[inline] - pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) - } - #[inline] - pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) - } -} -impl ::std::default::Default for __BindgenUnionField { - #[inline] - fn default() -> Self { - Self::new() - } -} -impl ::std::clone::Clone for __BindgenUnionField { - #[inline] - fn clone(&self) -> Self { - *self - } -} -impl ::std::marker::Copy for __BindgenUnionField {} -impl ::std::fmt::Debug for __BindgenUnionField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__BindgenUnionField") - } -} -impl ::std::hash::Hash for __BindgenUnionField { - fn hash(&self, _state: &mut H) {} -} -impl ::std::cmp::PartialEq for __BindgenUnionField { - fn eq(&self, _other: &__BindgenUnionField) -> bool { - true - } -} -impl ::std::cmp::Eq for __BindgenUnionField {} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct foo { - pub __bindgen_anon_1: foo__bindgen_ty_1, -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct foo__bindgen_ty_1 { - pub a: __BindgenUnionField<::std::os::raw::c_uint>, - pub b: __BindgenUnionField<::std::os::raw::c_ushort>, - pub bindgen_union_field: u32, -} -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - "Size of foo__bindgen_ty_1", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - "Alignment of foo__bindgen_ty_1", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - "Offset of field: foo__bindgen_ty_1::a", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - "Offset of field: foo__bindgen_ty_1::b", - ); -} -impl Clone for foo__bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} -#[test] -fn bindgen_test_layout_foo() { - assert_eq!(::std::mem::size_of::(), 4usize, "Size of foo"); - assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of foo"); -} -impl Clone for foo { - fn clone(&self) -> Self { - *self - } -} diff --git a/bindgen-tests/tests/expectations/tests/struct_with_nesting_1_0.rs b/bindgen-tests/tests/expectations/tests/struct_with_nesting_1_0.rs deleted file mode 100644 index 0753326174..0000000000 --- a/bindgen-tests/tests/expectations/tests/struct_with_nesting_1_0.rs +++ /dev/null @@ -1,184 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -pub struct __BindgenUnionField(::std::marker::PhantomData); -impl __BindgenUnionField { - #[inline] - pub fn new() -> Self { - __BindgenUnionField(::std::marker::PhantomData) - } - #[inline] - pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) - } - #[inline] - pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) - } -} -impl ::std::default::Default for __BindgenUnionField { - #[inline] - fn default() -> Self { - Self::new() - } -} -impl ::std::clone::Clone for __BindgenUnionField { - #[inline] - fn clone(&self) -> Self { - *self - } -} -impl ::std::marker::Copy for __BindgenUnionField {} -impl ::std::fmt::Debug for __BindgenUnionField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__BindgenUnionField") - } -} -impl ::std::hash::Hash for __BindgenUnionField { - fn hash(&self, _state: &mut H) {} -} -impl ::std::cmp::PartialEq for __BindgenUnionField { - fn eq(&self, _other: &__BindgenUnionField) -> bool { - true - } -} -impl ::std::cmp::Eq for __BindgenUnionField {} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct foo { - pub a: ::std::os::raw::c_uint, - pub __bindgen_anon_1: foo__bindgen_ty_1, -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct foo__bindgen_ty_1 { - pub b: __BindgenUnionField<::std::os::raw::c_uint>, - pub __bindgen_anon_1: __BindgenUnionField, - pub __bindgen_anon_2: __BindgenUnionField, - pub bindgen_union_field: u32, -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct foo__bindgen_ty_1__bindgen_ty_1 { - pub c1: ::std::os::raw::c_ushort, - pub c2: ::std::os::raw::c_ushort, -} -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - "Size of foo__bindgen_ty_1__bindgen_ty_1", - ); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - "Alignment of foo__bindgen_ty_1__bindgen_ty_1", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c1) as usize - ptr as usize }, - 0usize, - "Offset of field: foo__bindgen_ty_1__bindgen_ty_1::c1", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c2) as usize - ptr as usize }, - 2usize, - "Offset of field: foo__bindgen_ty_1__bindgen_ty_1::c2", - ); -} -impl Clone for foo__bindgen_ty_1__bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct foo__bindgen_ty_1__bindgen_ty_2 { - pub d1: ::std::os::raw::c_uchar, - pub d2: ::std::os::raw::c_uchar, - pub d3: ::std::os::raw::c_uchar, - pub d4: ::std::os::raw::c_uchar, -} -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - "Size of foo__bindgen_ty_1__bindgen_ty_2", - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - "Alignment of foo__bindgen_ty_1__bindgen_ty_2", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d1) as usize - ptr as usize }, - 0usize, - "Offset of field: foo__bindgen_ty_1__bindgen_ty_2::d1", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d2) as usize - ptr as usize }, - 1usize, - "Offset of field: foo__bindgen_ty_1__bindgen_ty_2::d2", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d3) as usize - ptr as usize }, - 2usize, - "Offset of field: foo__bindgen_ty_1__bindgen_ty_2::d3", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d4) as usize - ptr as usize }, - 3usize, - "Offset of field: foo__bindgen_ty_1__bindgen_ty_2::d4", - ); -} -impl Clone for foo__bindgen_ty_1__bindgen_ty_2 { - fn clone(&self) -> Self { - *self - } -} -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - "Size of foo__bindgen_ty_1", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - "Alignment of foo__bindgen_ty_1", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - "Offset of field: foo__bindgen_ty_1::b", - ); -} -impl Clone for foo__bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} -#[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::(), 8usize, "Size of foo"); - assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of foo"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - "Offset of field: foo::a", - ); -} -impl Clone for foo { - fn clone(&self) -> Self { - *self - } -} diff --git a/bindgen-tests/tests/expectations/tests/transform-op.rs b/bindgen-tests/tests/expectations/tests/transform-op.rs index b53cea166a..c626049b46 100644 --- a/bindgen-tests/tests/expectations/tests/transform-op.rs +++ b/bindgen-tests/tests/expectations/tests/transform-op.rs @@ -3,7 +3,7 @@ pub struct __BindgenUnionField(::std::marker::PhantomData); impl __BindgenUnionField { #[inline] - pub fn new() -> Self { + pub const fn new() -> Self { __BindgenUnionField(::std::marker::PhantomData) } #[inline] @@ -59,7 +59,7 @@ impl Default for StylePoint { } } #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[repr(align(1))] pub struct StyleFoo { pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub __bindgen_anon_1: __BindgenUnionField, @@ -137,8 +137,16 @@ impl Default for StyleFoo__bindgen_ty_1 { } } } +impl Default for StyleFoo { + fn default() -> Self { + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } + } +} #[repr(C)] -#[derive(Debug, Copy, Clone)] pub struct StyleBar { pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub tag: StyleBar_Tag, @@ -197,7 +205,7 @@ impl Default for StyleBar_StyleBar3_Body { } } #[repr(C)] -#[derive(Debug, Default, Copy, Clone)] +#[repr(align(1))] pub struct StyleBar__bindgen_ty_1 { pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, pub bar1: __BindgenUnionField>, @@ -205,6 +213,15 @@ pub struct StyleBar__bindgen_ty_1 { pub bar3: __BindgenUnionField>, pub bindgen_union_field: [u8; 0usize], } +impl Default for StyleBar__bindgen_ty_1 { + fn default() -> Self { + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } + } +} impl Default for StyleBar { fn default() -> Self { unsafe { diff --git a/bindgen-tests/tests/expectations/tests/typeref_1_0.rs b/bindgen-tests/tests/expectations/tests/typeref_1_0.rs deleted file mode 100644 index 2cf1633a61..0000000000 --- a/bindgen-tests/tests/expectations/tests/typeref_1_0.rs +++ /dev/null @@ -1,175 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -pub struct __BindgenUnionField(::std::marker::PhantomData); -impl __BindgenUnionField { - #[inline] - pub fn new() -> Self { - __BindgenUnionField(::std::marker::PhantomData) - } - #[inline] - pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) - } - #[inline] - pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) - } -} -impl ::std::default::Default for __BindgenUnionField { - #[inline] - fn default() -> Self { - Self::new() - } -} -impl ::std::clone::Clone for __BindgenUnionField { - #[inline] - fn clone(&self) -> Self { - *self - } -} -impl ::std::marker::Copy for __BindgenUnionField {} -impl ::std::fmt::Debug for __BindgenUnionField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__BindgenUnionField") - } -} -impl ::std::hash::Hash for __BindgenUnionField { - fn hash(&self, _state: &mut H) {} -} -impl ::std::cmp::PartialEq for __BindgenUnionField { - fn eq(&self, _other: &__BindgenUnionField) -> bool { - true - } -} -impl ::std::cmp::Eq for __BindgenUnionField {} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct mozilla_FragmentOrURL { - pub mIsLocalRef: bool, -} -#[test] -fn bindgen_test_layout_mozilla_FragmentOrURL() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 1usize, - "Size of mozilla_FragmentOrURL", - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - "Alignment of mozilla_FragmentOrURL", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mIsLocalRef) as usize - ptr as usize }, - 0usize, - "Offset of field: mozilla_FragmentOrURL::mIsLocalRef", - ); -} -impl Clone for mozilla_FragmentOrURL { - fn clone(&self) -> Self { - *self - } -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct mozilla_Position { - pub _address: u8, -} -#[test] -fn bindgen_test_layout_mozilla_Position() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - "Size of mozilla_Position", - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - "Alignment of mozilla_Position", - ); -} -impl Clone for mozilla_Position { - fn clone(&self) -> Self { - *self - } -} -#[repr(C)] -#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] -pub struct mozilla_StyleShapeSource { - pub __bindgen_anon_1: mozilla_StyleShapeSource__bindgen_ty_1, -} -#[repr(C)] -#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] -pub struct mozilla_StyleShapeSource__bindgen_ty_1 { - pub mPosition: __BindgenUnionField<*mut mozilla_Position>, - pub mFragmentOrURL: __BindgenUnionField<*mut mozilla_FragmentOrURL>, - pub bindgen_union_field: u64, -} -#[repr(C)] -#[derive(Debug, Copy, Hash, PartialEq, Eq)] -pub struct Bar { - pub mFoo: *mut nsFoo, -} -#[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::(), 8usize, "Size of Bar"); - assert_eq!(::std::mem::align_of::(), 8usize, "Alignment of Bar"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mFoo) as usize - ptr as usize }, - 0usize, - "Offset of field: Bar::mFoo", - ); -} -impl Clone for Bar { - fn clone(&self) -> Self { - *self - } -} -impl Default for Bar { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct nsFoo { - pub mBar: mozilla_StyleShapeSource, -} -#[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::(), 8usize, "Size of nsFoo"); - assert_eq!(::std::mem::align_of::(), 8usize, "Alignment of nsFoo"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mBar) as usize - ptr as usize }, - 0usize, - "Offset of field: nsFoo::mBar", - ); -} -impl Clone for nsFoo { - fn clone(&self) -> Self { - *self - } -} -#[test] -fn __bindgen_test_layout_mozilla_StyleShapeSource_open0_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - "Size of template specialization: mozilla_StyleShapeSource_open0_int_close0", - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - "Align of template specialization: mozilla_StyleShapeSource_open0_int_close0", - ); -} diff --git a/bindgen-tests/tests/expectations/tests/union-in-ns_1_0.rs b/bindgen-tests/tests/expectations/tests/union-in-ns_1_0.rs deleted file mode 100644 index eac1df1a13..0000000000 --- a/bindgen-tests/tests/expectations/tests/union-in-ns_1_0.rs +++ /dev/null @@ -1,72 +0,0 @@ -#![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 { - #[repr(C)] - pub struct __BindgenUnionField(::std::marker::PhantomData); - impl __BindgenUnionField { - #[inline] - pub fn new() -> Self { - __BindgenUnionField(::std::marker::PhantomData) - } - #[inline] - pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) - } - #[inline] - pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) - } - } - impl ::std::default::Default for __BindgenUnionField { - #[inline] - fn default() -> Self { - Self::new() - } - } - impl ::std::clone::Clone for __BindgenUnionField { - #[inline] - fn clone(&self) -> Self { - *self - } - } - impl ::std::marker::Copy for __BindgenUnionField {} - impl ::std::fmt::Debug for __BindgenUnionField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__BindgenUnionField") - } - } - impl ::std::hash::Hash for __BindgenUnionField { - fn hash(&self, _state: &mut H) {} - } - impl ::std::cmp::PartialEq for __BindgenUnionField { - fn eq(&self, _other: &__BindgenUnionField) -> bool { - true - } - } - impl ::std::cmp::Eq for __BindgenUnionField {} - #[allow(unused_imports)] - use self::super::root; - #[repr(C)] - #[derive(Debug, Default, Copy)] - pub struct bar { - pub baz: root::__BindgenUnionField<::std::os::raw::c_int>, - pub bindgen_union_field: u32, - } - #[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).baz) as usize - ptr as usize }, - 0usize, - "Offset of field: bar::baz", - ); - } - impl Clone for bar { - fn clone(&self) -> Self { - *self - } - } -} diff --git a/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs b/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs deleted file mode 100644 index bd4a772cb7..0000000000 --- a/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs +++ /dev/null @@ -1,285 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit { - storage: Storage, -} -impl __BindgenBitfieldUnit { - #[inline] - pub 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] - 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 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 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); - } - } -} -#[repr(C)] -pub struct __BindgenUnionField(::std::marker::PhantomData); -impl __BindgenUnionField { - #[inline] - pub fn new() -> Self { - __BindgenUnionField(::std::marker::PhantomData) - } - #[inline] - pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) - } - #[inline] - pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) - } -} -impl ::std::default::Default for __BindgenUnionField { - #[inline] - fn default() -> Self { - Self::new() - } -} -impl ::std::clone::Clone for __BindgenUnionField { - #[inline] - fn clone(&self) -> Self { - *self - } -} -impl ::std::marker::Copy for __BindgenUnionField {} -impl ::std::fmt::Debug for __BindgenUnionField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__BindgenUnionField") - } -} -impl ::std::hash::Hash for __BindgenUnionField { - fn hash(&self, _state: &mut H) {} -} -impl ::std::cmp::PartialEq for __BindgenUnionField { - fn eq(&self, _other: &__BindgenUnionField) -> bool { - true - } -} -impl ::std::cmp::Eq for __BindgenUnionField {} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct U4 { - pub _bitfield_align_1: [u8; 0], - pub _bitfield_1: __BindgenUnionField<__BindgenBitfieldUnit<[u8; 1usize]>>, - pub bindgen_union_field: u32, -} -#[test] -fn bindgen_test_layout_U4() { - assert_eq!(::std::mem::size_of::(), 4usize, "Size of U4"); - assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of U4"); -} -impl Clone for U4 { - fn clone(&self) -> Self { - *self - } -} -impl U4 { - #[inline] - pub fn derp(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.as_ref().get(0usize, 1u8) as u32) - } - } - #[inline] - pub fn set_derp(&mut self, val: ::std::os::raw::c_uint) { - unsafe { - let val: u32 = ::std::mem::transmute(val); - self._bitfield_1.as_mut().set(0usize, 1u8, val as u64) - } - } - #[inline] - pub fn new_bitfield_1( - derp: ::std::os::raw::c_uint, - ) -> __BindgenBitfieldUnit<[u8; 1usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); - __bindgen_bitfield_unit - .set( - 0usize, - 1u8, - { - let derp: u32 = unsafe { ::std::mem::transmute(derp) }; - derp as u64 - }, - ); - __bindgen_bitfield_unit - } -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct B { - pub _bitfield_align_1: [u32; 0], - pub _bitfield_1: __BindgenUnionField<__BindgenBitfieldUnit<[u8; 4usize]>>, - pub bindgen_union_field: u32, -} -#[test] -fn bindgen_test_layout_B() { - assert_eq!(::std::mem::size_of::(), 4usize, "Size of B"); - assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of B"); -} -impl Clone for B { - fn clone(&self) -> Self { - *self - } -} -impl B { - #[inline] - pub fn foo(&self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute(self._bitfield_1.as_ref().get(0usize, 31u8) as u32) - } - } - #[inline] - pub fn set_foo(&mut self, val: ::std::os::raw::c_uint) { - unsafe { - let val: u32 = ::std::mem::transmute(val); - self._bitfield_1.as_mut().set(0usize, 31u8, val as u64) - } - } - #[inline] - pub fn bar(&self) -> ::std::os::raw::c_uchar { - unsafe { - ::std::mem::transmute(self._bitfield_1.as_ref().get(31usize, 1u8) as u8) - } - } - #[inline] - pub fn set_bar(&mut self, val: ::std::os::raw::c_uchar) { - unsafe { - let val: u8 = ::std::mem::transmute(val); - self._bitfield_1.as_mut().set(31usize, 1u8, val as u64) - } - } - #[inline] - pub fn new_bitfield_1( - foo: ::std::os::raw::c_uint, - bar: ::std::os::raw::c_uchar, - ) -> __BindgenBitfieldUnit<[u8; 4usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = Default::default(); - __bindgen_bitfield_unit - .set( - 0usize, - 31u8, - { - let foo: u32 = unsafe { ::std::mem::transmute(foo) }; - foo as u64 - }, - ); - __bindgen_bitfield_unit - .set( - 31usize, - 1u8, - { - let bar: u8 = unsafe { ::std::mem::transmute(bar) }; - bar as u64 - }, - ); - __bindgen_bitfield_unit - } -} -#[repr(C)] -#[derive(Copy)] -pub struct HasBigBitfield { - pub _bitfield_align_1: [u64; 0], - pub _bitfield_1: __BindgenUnionField<__BindgenBitfieldUnit<[u8; 16usize]>>, - pub bindgen_union_field: [u8; 16usize], -} -#[test] -fn bindgen_test_layout_HasBigBitfield() { - assert_eq!( - ::std::mem::size_of::(), - 16usize, - "Size of HasBigBitfield", - ); -} -impl Clone for HasBigBitfield { - fn clone(&self) -> Self { - *self - } -} -impl Default for HasBigBitfield { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} -impl ::std::cmp::PartialEq for HasBigBitfield { - fn eq(&self, other: &HasBigBitfield) -> bool { - &self.bindgen_union_field[..] == &other.bindgen_union_field[..] - } -} diff --git a/bindgen-tests/tests/expectations/tests/union_dtor_1_0.rs b/bindgen-tests/tests/expectations/tests/union_dtor_1_0.rs deleted file mode 100644 index e9c777df94..0000000000 --- a/bindgen-tests/tests/expectations/tests/union_dtor_1_0.rs +++ /dev/null @@ -1,82 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -pub struct __BindgenUnionField(::std::marker::PhantomData); -impl __BindgenUnionField { - #[inline] - pub fn new() -> Self { - __BindgenUnionField(::std::marker::PhantomData) - } - #[inline] - pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) - } - #[inline] - pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) - } -} -impl ::std::default::Default for __BindgenUnionField { - #[inline] - fn default() -> Self { - Self::new() - } -} -impl ::std::clone::Clone for __BindgenUnionField { - #[inline] - fn clone(&self) -> Self { - *self - } -} -impl ::std::marker::Copy for __BindgenUnionField {} -impl ::std::fmt::Debug for __BindgenUnionField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__BindgenUnionField") - } -} -impl ::std::hash::Hash for __BindgenUnionField { - fn hash(&self, _state: &mut H) {} -} -impl ::std::cmp::PartialEq for __BindgenUnionField { - fn eq(&self, _other: &__BindgenUnionField) -> bool { - true - } -} -impl ::std::cmp::Eq for __BindgenUnionField {} -#[repr(C)] -#[derive(Debug, Default)] -pub struct UnionWithDtor { - pub mFoo: __BindgenUnionField<::std::os::raw::c_int>, - pub mBar: __BindgenUnionField<*mut ::std::os::raw::c_void>, - pub bindgen_union_field: u64, -} -#[test] -fn bindgen_test_layout_UnionWithDtor() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 8usize, "Size of UnionWithDtor"); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - "Alignment of UnionWithDtor", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mFoo) as usize - ptr as usize }, - 0usize, - "Offset of field: UnionWithDtor::mFoo", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mBar) as usize - ptr as usize }, - 0usize, - "Offset of field: UnionWithDtor::mBar", - ); -} -extern "C" { - #[link_name = "\u{1}_ZN13UnionWithDtorD1Ev"] - pub fn UnionWithDtor_UnionWithDtor_destructor(this: *mut UnionWithDtor); -} -impl UnionWithDtor { - #[inline] - pub unsafe fn destruct(&mut self) { - UnionWithDtor_UnionWithDtor_destructor(self) - } -} diff --git a/bindgen-tests/tests/expectations/tests/union_fields_1_0.rs b/bindgen-tests/tests/expectations/tests/union_fields_1_0.rs deleted file mode 100644 index 9cf2f09832..0000000000 --- a/bindgen-tests/tests/expectations/tests/union_fields_1_0.rs +++ /dev/null @@ -1,83 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -pub struct __BindgenUnionField(::std::marker::PhantomData); -impl __BindgenUnionField { - #[inline] - pub fn new() -> Self { - __BindgenUnionField(::std::marker::PhantomData) - } - #[inline] - pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) - } - #[inline] - pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) - } -} -impl ::std::default::Default for __BindgenUnionField { - #[inline] - fn default() -> Self { - Self::new() - } -} -impl ::std::clone::Clone for __BindgenUnionField { - #[inline] - fn clone(&self) -> Self { - *self - } -} -impl ::std::marker::Copy for __BindgenUnionField {} -impl ::std::fmt::Debug for __BindgenUnionField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__BindgenUnionField") - } -} -impl ::std::hash::Hash for __BindgenUnionField { - fn hash(&self, _state: &mut H) {} -} -impl ::std::cmp::PartialEq for __BindgenUnionField { - fn eq(&self, _other: &__BindgenUnionField) -> bool { - true - } -} -impl ::std::cmp::Eq for __BindgenUnionField {} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq)] -pub struct nsStyleUnion { - pub mInt: __BindgenUnionField<::std::os::raw::c_int>, - pub mFloat: __BindgenUnionField, - pub mPointer: __BindgenUnionField<*mut ::std::os::raw::c_void>, - pub bindgen_union_field: u64, -} -#[test] -fn bindgen_test_layout_nsStyleUnion() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 8usize, "Size of nsStyleUnion"); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - "Alignment of nsStyleUnion", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mInt) as usize - ptr as usize }, - 0usize, - "Offset of field: nsStyleUnion::mInt", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mFloat) as usize - ptr as usize }, - 0usize, - "Offset of field: nsStyleUnion::mFloat", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mPointer) as usize - ptr as usize }, - 0usize, - "Offset of field: nsStyleUnion::mPointer", - ); -} -impl Clone for nsStyleUnion { - fn clone(&self) -> Self { - *self - } -} diff --git a/bindgen-tests/tests/expectations/tests/union_template_1_0.rs b/bindgen-tests/tests/expectations/tests/union_template_1_0.rs deleted file mode 100644 index 4ebad2a2e2..0000000000 --- a/bindgen-tests/tests/expectations/tests/union_template_1_0.rs +++ /dev/null @@ -1,72 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -pub struct __BindgenUnionField(::std::marker::PhantomData); -impl __BindgenUnionField { - #[inline] - pub fn new() -> Self { - __BindgenUnionField(::std::marker::PhantomData) - } - #[inline] - pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) - } - #[inline] - pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) - } -} -impl ::std::default::Default for __BindgenUnionField { - #[inline] - fn default() -> Self { - Self::new() - } -} -impl ::std::clone::Clone for __BindgenUnionField { - #[inline] - fn clone(&self) -> Self { - *self - } -} -impl ::std::marker::Copy for __BindgenUnionField {} -impl ::std::fmt::Debug for __BindgenUnionField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__BindgenUnionField") - } -} -impl ::std::hash::Hash for __BindgenUnionField { - fn hash(&self, _state: &mut H) {} -} -impl ::std::cmp::PartialEq for __BindgenUnionField { - fn eq(&self, _other: &__BindgenUnionField) -> bool { - true - } -} -impl ::std::cmp::Eq for __BindgenUnionField {} -#[repr(C)] -#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] -pub struct NastyStruct { - pub mIsSome: bool, - pub mStorage: NastyStruct__bindgen_ty_1, - pub __bindgen_anon_1: NastyStruct__bindgen_ty_2, -} -#[repr(C)] -#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] -pub struct NastyStruct__bindgen_ty_1 { - pub mFoo: __BindgenUnionField<*mut ::std::os::raw::c_void>, - pub mDummy: __BindgenUnionField<::std::os::raw::c_ulong>, - pub bindgen_union_field: u64, -} -#[repr(C)] -#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] -pub struct NastyStruct__bindgen_ty_2 { - pub wat: __BindgenUnionField<::std::os::raw::c_short>, - pub wut: __BindgenUnionField<*mut ::std::os::raw::c_int>, - pub bindgen_union_field: u64, -} -#[repr(C)] -#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] -pub struct Whatever { - pub mTPtr: __BindgenUnionField<*mut ::std::os::raw::c_void>, - pub mInt: __BindgenUnionField<::std::os::raw::c_int>, - pub bindgen_union_field: u64, -} diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_1_0.rs deleted file mode 100644 index 7ea38b8bae..0000000000 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_1_0.rs +++ /dev/null @@ -1,103 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -pub struct __BindgenUnionField(::std::marker::PhantomData); -impl __BindgenUnionField { - #[inline] - pub fn new() -> Self { - __BindgenUnionField(::std::marker::PhantomData) - } - #[inline] - pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) - } - #[inline] - pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) - } -} -impl ::std::default::Default for __BindgenUnionField { - #[inline] - fn default() -> Self { - Self::new() - } -} -impl ::std::clone::Clone for __BindgenUnionField { - #[inline] - fn clone(&self) -> Self { - *self - } -} -impl ::std::marker::Copy for __BindgenUnionField {} -impl ::std::fmt::Debug for __BindgenUnionField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__BindgenUnionField") - } -} -impl ::std::hash::Hash for __BindgenUnionField { - fn hash(&self, _state: &mut H) {} -} -impl ::std::cmp::PartialEq for __BindgenUnionField { - fn eq(&self, _other: &__BindgenUnionField) -> bool { - true - } -} -impl ::std::cmp::Eq for __BindgenUnionField {} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct foo { - pub bar: __BindgenUnionField, - pub bindgen_union_field: [u32; 2usize], -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct foo__bindgen_ty_1 { - pub a: ::std::os::raw::c_uint, - pub b: ::std::os::raw::c_uint, -} -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - "Size of foo__bindgen_ty_1", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - "Alignment of foo__bindgen_ty_1", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - "Offset of field: foo__bindgen_ty_1::a", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 4usize, - "Offset of field: foo__bindgen_ty_1::b", - ); -} -impl Clone for foo__bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} -#[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::(), 8usize, "Size of foo"); - assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of foo"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - "Offset of field: foo::bar", - ); -} -impl Clone for foo { - fn clone(&self) -> Self { - *self - } -} diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs deleted file mode 100644 index ff19f398ad..0000000000 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs +++ /dev/null @@ -1,230 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit { - storage: Storage, -} -impl __BindgenBitfieldUnit { - #[inline] - pub 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] - 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 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 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); - } - } -} -#[repr(C)] -pub struct __BindgenUnionField(::std::marker::PhantomData); -impl __BindgenUnionField { - #[inline] - pub fn new() -> Self { - __BindgenUnionField(::std::marker::PhantomData) - } - #[inline] - pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) - } - #[inline] - pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) - } -} -impl ::std::default::Default for __BindgenUnionField { - #[inline] - fn default() -> Self { - Self::new() - } -} -impl ::std::clone::Clone for __BindgenUnionField { - #[inline] - fn clone(&self) -> Self { - *self - } -} -impl ::std::marker::Copy for __BindgenUnionField {} -impl ::std::fmt::Debug for __BindgenUnionField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__BindgenUnionField") - } -} -impl ::std::hash::Hash for __BindgenUnionField { - fn hash(&self, _state: &mut H) {} -} -impl ::std::cmp::PartialEq for __BindgenUnionField { - fn eq(&self, _other: &__BindgenUnionField) -> bool { - true - } -} -impl ::std::cmp::Eq for __BindgenUnionField {} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct foo { - pub a: __BindgenUnionField<::std::os::raw::c_int>, - pub __bindgen_anon_1: __BindgenUnionField, - pub bindgen_union_field: u32, -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct foo__bindgen_ty_1 { - pub _bitfield_align_1: [u32; 0], - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, -} -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - "Size of foo__bindgen_ty_1", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - "Alignment of foo__bindgen_ty_1", - ); -} -impl Clone for foo__bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} -impl foo__bindgen_ty_1 { - #[inline] - pub fn b(&self) -> ::std::os::raw::c_int { - unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 7u8) as u32) } - } - #[inline] - pub fn set_b(&mut self, val: ::std::os::raw::c_int) { - unsafe { - let val: u32 = ::std::mem::transmute(val); - self._bitfield_1.set(0usize, 7u8, val as u64) - } - } - #[inline] - pub fn c(&self) -> ::std::os::raw::c_int { - unsafe { ::std::mem::transmute(self._bitfield_1.get(7usize, 25u8) as u32) } - } - #[inline] - pub fn set_c(&mut self, val: ::std::os::raw::c_int) { - unsafe { - let val: u32 = ::std::mem::transmute(val); - self._bitfield_1.set(7usize, 25u8, val as u64) - } - } - #[inline] - pub fn new_bitfield_1( - b: ::std::os::raw::c_int, - c: ::std::os::raw::c_int, - ) -> __BindgenBitfieldUnit<[u8; 4usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = Default::default(); - __bindgen_bitfield_unit - .set( - 0usize, - 7u8, - { - let b: u32 = unsafe { ::std::mem::transmute(b) }; - b as u64 - }, - ); - __bindgen_bitfield_unit - .set( - 7usize, - 25u8, - { - let c: u32 = unsafe { ::std::mem::transmute(c) }; - c as u64 - }, - ); - __bindgen_bitfield_unit - } -} -#[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::(), 4usize, "Size of foo"); - assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of foo"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - "Offset of field: foo::a", - ); -} -impl Clone for foo { - fn clone(&self) -> Self { - *self - } -} diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_union_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_union_1_0.rs deleted file mode 100644 index ad6d9c7e16..0000000000 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_union_1_0.rs +++ /dev/null @@ -1,104 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -pub struct __BindgenUnionField(::std::marker::PhantomData); -impl __BindgenUnionField { - #[inline] - pub fn new() -> Self { - __BindgenUnionField(::std::marker::PhantomData) - } - #[inline] - pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) - } - #[inline] - pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) - } -} -impl ::std::default::Default for __BindgenUnionField { - #[inline] - fn default() -> Self { - Self::new() - } -} -impl ::std::clone::Clone for __BindgenUnionField { - #[inline] - fn clone(&self) -> Self { - *self - } -} -impl ::std::marker::Copy for __BindgenUnionField {} -impl ::std::fmt::Debug for __BindgenUnionField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__BindgenUnionField") - } -} -impl ::std::hash::Hash for __BindgenUnionField { - fn hash(&self, _state: &mut H) {} -} -impl ::std::cmp::PartialEq for __BindgenUnionField { - fn eq(&self, _other: &__BindgenUnionField) -> bool { - true - } -} -impl ::std::cmp::Eq for __BindgenUnionField {} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct foo { - pub bar: __BindgenUnionField, - pub bindgen_union_field: u32, -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct foo__bindgen_ty_1 { - pub a: __BindgenUnionField<::std::os::raw::c_uint>, - pub b: __BindgenUnionField<::std::os::raw::c_ushort>, - pub bindgen_union_field: u32, -} -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - "Size of foo__bindgen_ty_1", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - "Alignment of foo__bindgen_ty_1", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - "Offset of field: foo__bindgen_ty_1::a", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - "Offset of field: foo__bindgen_ty_1::b", - ); -} -impl Clone for foo__bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} -#[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::(), 4usize, "Size of foo"); - assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of foo"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - "Offset of field: foo::bar", - ); -} -impl Clone for foo { - fn clone(&self) -> Self { - *self - } -} diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs deleted file mode 100644 index 20ceaee90c..0000000000 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs +++ /dev/null @@ -1,116 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -pub struct __BindgenUnionField(::std::marker::PhantomData); -impl __BindgenUnionField { - #[inline] - pub fn new() -> Self { - __BindgenUnionField(::std::marker::PhantomData) - } - #[inline] - pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) - } - #[inline] - pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) - } -} -impl ::std::default::Default for __BindgenUnionField { - #[inline] - fn default() -> Self { - Self::new() - } -} -impl ::std::clone::Clone for __BindgenUnionField { - #[inline] - fn clone(&self) -> Self { - *self - } -} -impl ::std::marker::Copy for __BindgenUnionField {} -impl ::std::fmt::Debug for __BindgenUnionField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__BindgenUnionField") - } -} -impl ::std::hash::Hash for __BindgenUnionField { - fn hash(&self, _state: &mut H) {} -} -impl ::std::cmp::PartialEq for __BindgenUnionField { - fn eq(&self, _other: &__BindgenUnionField) -> bool { - true - } -} -impl ::std::cmp::Eq for __BindgenUnionField {} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct pixel { - pub rgba: __BindgenUnionField<::std::os::raw::c_uint>, - pub __bindgen_anon_1: __BindgenUnionField, - pub bindgen_union_field: u32, -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct pixel__bindgen_ty_1 { - pub r: ::std::os::raw::c_uchar, - pub g: ::std::os::raw::c_uchar, - pub b: ::std::os::raw::c_uchar, - pub a: ::std::os::raw::c_uchar, -} -#[test] -fn bindgen_test_layout_pixel__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - "Size of pixel__bindgen_ty_1", - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - "Alignment of pixel__bindgen_ty_1", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).r) as usize - ptr as usize }, - 0usize, - "Offset of field: pixel__bindgen_ty_1::r", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).g) as usize - ptr as usize }, - 1usize, - "Offset of field: pixel__bindgen_ty_1::g", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 2usize, - "Offset of field: pixel__bindgen_ty_1::b", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 3usize, - "Offset of field: pixel__bindgen_ty_1::a", - ); -} -impl Clone for pixel__bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} -#[test] -fn bindgen_test_layout_pixel() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 4usize, "Size of pixel"); - assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of pixel"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).rgba) as usize - ptr as usize }, - 0usize, - "Offset of field: pixel::rgba", - ); -} -impl Clone for pixel { - fn clone(&self) -> Self { - *self - } -} diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs deleted file mode 100644 index 561c7f8071..0000000000 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs +++ /dev/null @@ -1,105 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -pub struct __BindgenUnionField(::std::marker::PhantomData); -impl __BindgenUnionField { - #[inline] - pub fn new() -> Self { - __BindgenUnionField(::std::marker::PhantomData) - } - #[inline] - pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) - } - #[inline] - pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) - } -} -impl ::std::default::Default for __BindgenUnionField { - #[inline] - fn default() -> Self { - Self::new() - } -} -impl ::std::clone::Clone for __BindgenUnionField { - #[inline] - fn clone(&self) -> Self { - *self - } -} -impl ::std::marker::Copy for __BindgenUnionField {} -impl ::std::fmt::Debug for __BindgenUnionField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__BindgenUnionField") - } -} -impl ::std::hash::Hash for __BindgenUnionField { - fn hash(&self, _state: &mut H) {} -} -impl ::std::cmp::PartialEq for __BindgenUnionField { - fn eq(&self, _other: &__BindgenUnionField) -> bool { - true - } -} -impl ::std::cmp::Eq for __BindgenUnionField {} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct foo { - pub a: __BindgenUnionField<::std::os::raw::c_uint>, - pub __bindgen_anon_1: __BindgenUnionField, - pub bindgen_union_field: u32, -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct foo__bindgen_ty_1 { - pub b: __BindgenUnionField<::std::os::raw::c_ushort>, - pub c: __BindgenUnionField<::std::os::raw::c_uchar>, - pub bindgen_union_field: u16, -} -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 2usize, - "Size of foo__bindgen_ty_1", - ); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - "Alignment of foo__bindgen_ty_1", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - "Offset of field: foo__bindgen_ty_1::b", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, - 0usize, - "Offset of field: foo__bindgen_ty_1::c", - ); -} -impl Clone for foo__bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} -#[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::(), 4usize, "Size of foo"); - assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of foo"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - "Offset of field: foo::a", - ); -} -impl Clone for foo { - fn clone(&self) -> Self { - *self - } -} diff --git a/bindgen-tests/tests/expectations/tests/union_with_big_member_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_big_member_1_0.rs deleted file mode 100644 index 14a68fc0bf..0000000000 --- a/bindgen-tests/tests/expectations/tests/union_with_big_member_1_0.rs +++ /dev/null @@ -1,165 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -pub struct __BindgenUnionField(::std::marker::PhantomData); -impl __BindgenUnionField { - #[inline] - pub fn new() -> Self { - __BindgenUnionField(::std::marker::PhantomData) - } - #[inline] - pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) - } - #[inline] - pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) - } -} -impl ::std::default::Default for __BindgenUnionField { - #[inline] - fn default() -> Self { - Self::new() - } -} -impl ::std::clone::Clone for __BindgenUnionField { - #[inline] - fn clone(&self) -> Self { - *self - } -} -impl ::std::marker::Copy for __BindgenUnionField {} -impl ::std::fmt::Debug for __BindgenUnionField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__BindgenUnionField") - } -} -impl ::std::hash::Hash for __BindgenUnionField { - fn hash(&self, _state: &mut H) {} -} -impl ::std::cmp::PartialEq for __BindgenUnionField { - fn eq(&self, _other: &__BindgenUnionField) -> bool { - true - } -} -impl ::std::cmp::Eq for __BindgenUnionField {} -#[repr(C)] -#[derive(Copy)] -pub struct WithBigArray { - pub a: __BindgenUnionField<::std::os::raw::c_int>, - pub b: __BindgenUnionField<[::std::os::raw::c_int; 33usize]>, - pub bindgen_union_field: [u32; 33usize], -} -#[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, - "Offset of field: WithBigArray::a", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - "Offset of field: WithBigArray::b", - ); -} -impl Clone for WithBigArray { - fn clone(&self) -> Self { - *self - } -} -impl Default for WithBigArray { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct WithBigArray2 { - pub a: __BindgenUnionField<::std::os::raw::c_int>, - pub b: __BindgenUnionField<[::std::os::raw::c_char; 33usize]>, - pub bindgen_union_field: [u32; 9usize], -} -#[test] -fn bindgen_test_layout_WithBigArray2() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 36usize, "Size of WithBigArray2"); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - "Alignment of WithBigArray2", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - "Offset of field: WithBigArray2::a", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - "Offset of field: WithBigArray2::b", - ); -} -impl Clone for WithBigArray2 { - fn clone(&self) -> Self { - *self - } -} -#[repr(C)] -#[derive(Copy)] -pub struct WithBigMember { - pub a: __BindgenUnionField<::std::os::raw::c_int>, - pub b: __BindgenUnionField, - pub bindgen_union_field: [u32; 33usize], -} -#[test] -fn bindgen_test_layout_WithBigMember() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 132usize, - "Size of WithBigMember", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - "Alignment of WithBigMember", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - "Offset of field: WithBigMember::a", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - "Offset of field: WithBigMember::b", - ); -} -impl Clone for WithBigMember { - fn clone(&self) -> Self { - *self - } -} -impl Default for WithBigMember { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} diff --git a/bindgen-tests/tests/expectations/tests/union_with_nesting_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_nesting_1_0.rs deleted file mode 100644 index 22b902d82c..0000000000 --- a/bindgen-tests/tests/expectations/tests/union_with_nesting_1_0.rs +++ /dev/null @@ -1,166 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -pub struct __BindgenUnionField(::std::marker::PhantomData); -impl __BindgenUnionField { - #[inline] - pub fn new() -> Self { - __BindgenUnionField(::std::marker::PhantomData) - } - #[inline] - pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) - } - #[inline] - pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) - } -} -impl ::std::default::Default for __BindgenUnionField { - #[inline] - fn default() -> Self { - Self::new() - } -} -impl ::std::clone::Clone for __BindgenUnionField { - #[inline] - fn clone(&self) -> Self { - *self - } -} -impl ::std::marker::Copy for __BindgenUnionField {} -impl ::std::fmt::Debug for __BindgenUnionField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__BindgenUnionField") - } -} -impl ::std::hash::Hash for __BindgenUnionField { - fn hash(&self, _state: &mut H) {} -} -impl ::std::cmp::PartialEq for __BindgenUnionField { - fn eq(&self, _other: &__BindgenUnionField) -> bool { - true - } -} -impl ::std::cmp::Eq for __BindgenUnionField {} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct foo { - pub a: __BindgenUnionField<::std::os::raw::c_uint>, - pub __bindgen_anon_1: __BindgenUnionField, - pub bindgen_union_field: u32, -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct foo__bindgen_ty_1 { - pub __bindgen_anon_1: foo__bindgen_ty_1__bindgen_ty_1, - pub __bindgen_anon_2: foo__bindgen_ty_1__bindgen_ty_2, -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct foo__bindgen_ty_1__bindgen_ty_1 { - pub b1: __BindgenUnionField<::std::os::raw::c_ushort>, - pub b2: __BindgenUnionField<::std::os::raw::c_ushort>, - pub bindgen_union_field: u16, -} -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 2usize, - "Size of foo__bindgen_ty_1__bindgen_ty_1", - ); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - "Alignment of foo__bindgen_ty_1__bindgen_ty_1", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b1) as usize - ptr as usize }, - 0usize, - "Offset of field: foo__bindgen_ty_1__bindgen_ty_1::b1", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b2) as usize - ptr as usize }, - 0usize, - "Offset of field: foo__bindgen_ty_1__bindgen_ty_1::b2", - ); -} -impl Clone for foo__bindgen_ty_1__bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct foo__bindgen_ty_1__bindgen_ty_2 { - pub c1: __BindgenUnionField<::std::os::raw::c_ushort>, - pub c2: __BindgenUnionField<::std::os::raw::c_ushort>, - pub bindgen_union_field: u16, -} -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 2usize, - "Size of foo__bindgen_ty_1__bindgen_ty_2", - ); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - "Alignment of foo__bindgen_ty_1__bindgen_ty_2", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c1) as usize - ptr as usize }, - 0usize, - "Offset of field: foo__bindgen_ty_1__bindgen_ty_2::c1", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c2) as usize - ptr as usize }, - 0usize, - "Offset of field: foo__bindgen_ty_1__bindgen_ty_2::c2", - ); -} -impl Clone for foo__bindgen_ty_1__bindgen_ty_2 { - fn clone(&self) -> Self { - *self - } -} -#[test] -fn bindgen_test_layout_foo__bindgen_ty_1() { - assert_eq!( - ::std::mem::size_of::(), - 4usize, - "Size of foo__bindgen_ty_1", - ); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - "Alignment of foo__bindgen_ty_1", - ); -} -impl Clone for foo__bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} -#[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::(), 4usize, "Size of foo"); - assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of foo"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - "Offset of field: foo::a", - ); -} -impl Clone for foo { - fn clone(&self) -> Self { - *self - } -} diff --git a/bindgen-tests/tests/expectations/tests/use-core_1_0.rs b/bindgen-tests/tests/expectations/tests/use-core_1_0.rs deleted file mode 100644 index 707ca3d962..0000000000 --- a/bindgen-tests/tests/expectations/tests/use-core_1_0.rs +++ /dev/null @@ -1,127 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern crate core; -#[repr(C)] -pub struct __BindgenUnionField(::core::marker::PhantomData); -impl __BindgenUnionField { - #[inline] - pub fn new() -> Self { - __BindgenUnionField(::core::marker::PhantomData) - } - #[inline] - pub unsafe fn as_ref(&self) -> &T { - ::core::mem::transmute(self) - } - #[inline] - pub unsafe fn as_mut(&mut self) -> &mut T { - ::core::mem::transmute(self) - } -} -impl ::core::default::Default for __BindgenUnionField { - #[inline] - fn default() -> Self { - Self::new() - } -} -impl ::core::clone::Clone for __BindgenUnionField { - #[inline] - fn clone(&self) -> Self { - *self - } -} -impl ::core::marker::Copy for __BindgenUnionField {} -impl ::core::fmt::Debug for __BindgenUnionField { - fn fmt(&self, fmt: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { - fmt.write_str("__BindgenUnionField") - } -} -impl ::core::hash::Hash for __BindgenUnionField { - fn hash(&self, _state: &mut H) {} -} -impl ::core::cmp::PartialEq for __BindgenUnionField { - fn eq(&self, _other: &__BindgenUnionField) -> bool { - true - } -} -impl ::core::cmp::Eq for __BindgenUnionField {} -#[repr(C)] -#[derive(Debug, Copy, Hash, PartialEq, Eq)] -pub struct foo { - pub a: ::std::os::raw::c_int, - pub b: ::std::os::raw::c_int, - pub bar: *mut ::std::os::raw::c_void, -} -#[test] -fn bindgen_test_layout_foo() { - const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::core::mem::size_of::(), 16usize, "Size of foo"); - assert_eq!(::core::mem::align_of::(), 8usize, "Alignment of foo"); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - "Offset of field: foo::a", - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 4usize, - "Offset of field: foo::b", - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 8usize, - "Offset of field: foo::bar", - ); -} -impl Clone for foo { - fn clone(&self) -> Self { - *self - } -} -impl Default for foo { - fn default() -> Self { - unsafe { - let mut s: Self = ::core::mem::uninitialized(); - ::core::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct _bindgen_ty_1 { - pub bar: __BindgenUnionField<::std::os::raw::c_int>, - pub baz: __BindgenUnionField<::std::os::raw::c_long>, - pub bindgen_union_field: u64, -} -#[test] -fn bindgen_test_layout__bindgen_ty_1() { - const UNINIT: ::core::mem::MaybeUninit<_bindgen_ty_1> = ::core::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::core::mem::size_of::<_bindgen_ty_1>(), 8usize, "Size of _bindgen_ty_1"); - assert_eq!( - ::core::mem::align_of::<_bindgen_ty_1>(), - 8usize, - "Alignment of _bindgen_ty_1", - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).bar) as usize - ptr as usize }, - 0usize, - "Offset of field: _bindgen_ty_1::bar", - ); - assert_eq!( - unsafe { ::core::ptr::addr_of!((*ptr).baz) as usize - ptr as usize }, - 0usize, - "Offset of field: _bindgen_ty_1::baz", - ); -} -impl Clone for _bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} -extern "C" { - pub static mut bazz: _bindgen_ty_1; -} -pub type fooFunction = ::core::option::Option< - unsafe extern "C" fn(bar: ::std::os::raw::c_int), ->; diff --git a/bindgen-tests/tests/expectations/tests/win32-thiscall_1_0.rs b/bindgen-tests/tests/expectations/tests/win32-thiscall.rs similarity index 75% rename from bindgen-tests/tests/expectations/tests/win32-thiscall_1_0.rs rename to bindgen-tests/tests/expectations/tests/win32-thiscall.rs index 185b935808..d50348e799 100644 --- a/bindgen-tests/tests/expectations/tests/win32-thiscall_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/win32-thiscall.rs @@ -1,6 +1,6 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] -#[derive(Debug, Default, Copy)] +#[derive(Debug, Default, Copy, Clone)] pub struct Foo { pub _address: u8, } @@ -9,8 +9,3 @@ 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"); } -impl Clone for Foo { - fn clone(&self) -> Self { - *self - } -} diff --git a/bindgen-tests/tests/expectations/tests/win32-vectorcall-1_0.rs b/bindgen-tests/tests/expectations/tests/win32-vectorcall.rs similarity index 100% rename from bindgen-tests/tests/expectations/tests/win32-vectorcall-1_0.rs rename to bindgen-tests/tests/expectations/tests/win32-vectorcall.rs 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 new file mode 100644 index 0000000000..50cefed043 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_anon_union.rs @@ -0,0 +1,57 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[repr(C)] +pub struct TErrorResult { + pub mResult: ::std::os::raw::c_int, + pub __bindgen_anon_1: TErrorResult__bindgen_ty_1, + pub mMightHaveUnreported: bool, + pub mUnionState: TErrorResult_UnionState, +} +pub const TErrorResult_UnionState_HasMessage: TErrorResult_UnionState = 0; +pub const TErrorResult_UnionState_HasException: TErrorResult_UnionState = 0; +pub type TErrorResult_UnionState = i32; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct TErrorResult_Message { + _unused: [u8; 0], +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct TErrorResult_DOMExceptionInfo { + _unused: [u8; 0], +} +#[repr(C)] +pub union TErrorResult__bindgen_ty_1 { + pub mMessage: *mut TErrorResult_Message, + pub mDOMExceptionInfo: *mut TErrorResult_DOMExceptionInfo, +} +impl Default for TErrorResult__bindgen_ty_1 { + fn default() -> Self { + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } + } +} +impl Default for TErrorResult { + fn default() -> Self { + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } + } +} +#[repr(C)] +pub struct ErrorResult { + pub _base: TErrorResult, +} +impl Default for ErrorResult { + fn default() -> Self { + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } + } +} diff --git a/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_anon_union_1_0.rs b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_anon_union_1_0.rs deleted file mode 100644 index dfe2213ed4..0000000000 --- a/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_anon_union_1_0.rs +++ /dev/null @@ -1,100 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -pub struct __BindgenUnionField(::std::marker::PhantomData); -impl __BindgenUnionField { - #[inline] - pub fn new() -> Self { - __BindgenUnionField(::std::marker::PhantomData) - } - #[inline] - pub unsafe fn as_ref(&self) -> &T { - unsafe { ::std::mem::transmute(self) } - } - #[inline] - pub unsafe fn as_mut(&mut self) -> &mut T { - unsafe { ::std::mem::transmute(self) } - } -} -impl ::std::default::Default for __BindgenUnionField { - #[inline] - fn default() -> Self { - Self::new() - } -} -impl ::std::clone::Clone for __BindgenUnionField { - #[inline] - fn clone(&self) -> Self { - *self - } -} -impl ::std::marker::Copy for __BindgenUnionField {} -impl ::std::fmt::Debug for __BindgenUnionField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__BindgenUnionField") - } -} -impl ::std::hash::Hash for __BindgenUnionField { - fn hash(&self, _state: &mut H) {} -} -impl ::std::cmp::PartialEq for __BindgenUnionField { - fn eq(&self, _other: &__BindgenUnionField) -> bool { - true - } -} -impl ::std::cmp::Eq for __BindgenUnionField {} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct TErrorResult { - pub mResult: ::std::os::raw::c_int, - pub __bindgen_anon_1: TErrorResult__bindgen_ty_1, - pub mMightHaveUnreported: bool, - pub mUnionState: TErrorResult_UnionState, -} -pub const TErrorResult_UnionState_HasMessage: TErrorResult_UnionState = 0; -pub const TErrorResult_UnionState_HasException: TErrorResult_UnionState = 0; -pub type TErrorResult_UnionState = i32; -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct TErrorResult_Message { - _unused: [u8; 0], -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct TErrorResult_DOMExceptionInfo { - _unused: [u8; 0], -} -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct TErrorResult__bindgen_ty_1 { - pub mMessage: __BindgenUnionField<*mut TErrorResult_Message>, - pub mDOMExceptionInfo: __BindgenUnionField<*mut TErrorResult_DOMExceptionInfo>, - pub bindgen_union_field: u64, -} -impl Default for TErrorResult { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} -#[repr(C)] -#[derive(Debug, Copy)] -pub struct ErrorResult { - pub _base: TErrorResult, -} -impl Clone for ErrorResult { - fn clone(&self) -> Self { - *self - } -} -impl Default for ErrorResult { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} diff --git a/bindgen-tests/tests/headers/16-byte-alignment_1_0.h b/bindgen-tests/tests/headers/16-byte-alignment_1_0.h deleted file mode 100644 index 8a9fd4910e..0000000000 --- a/bindgen-tests/tests/headers/16-byte-alignment_1_0.h +++ /dev/null @@ -1,34 +0,0 @@ -// bindgen-flags: --rust-target 1.0 --with-derive-hash --with-derive-partialeq --with-derive-eq - -typedef unsigned char uint8_t; -typedef unsigned short uint16_t; -typedef unsigned int uint32_t; - -struct rte_ipv4_tuple { - uint32_t src_addr; - uint32_t dst_addr; - union { - struct { - uint16_t dport; - uint16_t sport; - }; - uint32_t sctp_tag; - }; -}; - -struct rte_ipv6_tuple { - uint8_t src_addr[16]; - uint8_t dst_addr[16]; - union { - struct { - uint16_t dport; - uint16_t sport; - }; - uint32_t sctp_tag; - }; -}; - -union rte_thash_tuple { - struct rte_ipv4_tuple v4; - struct rte_ipv6_tuple v6; -} __attribute__((aligned(16))); diff --git a/bindgen-tests/tests/headers/anon_struct_in_union_1_0.h b/bindgen-tests/tests/headers/anon_struct_in_union_1_0.h deleted file mode 100644 index 6b59723a3c..0000000000 --- a/bindgen-tests/tests/headers/anon_struct_in_union_1_0.h +++ /dev/null @@ -1,9 +0,0 @@ -// bindgen-flags: --rust-target 1.0 --with-derive-hash --with-derive-partialeq --with-derive-eq - -struct s { - union { - struct inner { - int b; - } field; - } u; -}; diff --git a/bindgen-tests/tests/headers/anon_union_1_0.hpp b/bindgen-tests/tests/headers/anon_union_1_0.hpp deleted file mode 100644 index 3d9ae3dde9..0000000000 --- a/bindgen-tests/tests/headers/anon_union_1_0.hpp +++ /dev/null @@ -1,22 +0,0 @@ -// bindgen-flags: --rust-target 1.0 --with-derive-hash --with-derive-partialeq --with-derive-eq --rustified-enum ".*" - -template -struct TErrorResult { - enum UnionState { - HasMessage, - HasException, - }; - int mResult; - struct Message; - struct DOMExceptionInfo; - union { - Message* mMessage; - DOMExceptionInfo* mDOMExceptionInfo; - }; - - bool mMightHaveUnreported; - UnionState mUnionState; -}; - -struct ErrorResult : public TErrorResult { -}; diff --git a/bindgen-tests/tests/headers/attribute_warn_unused_result.hpp b/bindgen-tests/tests/headers/attribute_warn_unused_result.hpp index 26fda0910c..258b6396de 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.27 --enable-function-attribute-detection +// bindgen-flags: \-\-rust-target=1.33 --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 2155030711..a102cbf100 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,4 +1,4 @@ -// bindgen-flags: --rust-target 1.27 +// bindgen-flags: \-\-rust-target=1.33 class Foo { public: diff --git a/bindgen-tests/tests/headers/attribute_warn_unused_result_pre_1_27.hpp b/bindgen-tests/tests/headers/attribute_warn_unused_result_pre_1_27.hpp deleted file mode 100644 index 25127d9cd0..0000000000 --- a/bindgen-tests/tests/headers/attribute_warn_unused_result_pre_1_27.hpp +++ /dev/null @@ -1,8 +0,0 @@ -class Foo { -public: - __attribute__((warn_unused_result)) - int foo(int); -}; - -__attribute__((warn_unused_result)) -int foo(int); diff --git a/bindgen-tests/tests/headers/bindgen-union-inside-namespace.hpp b/bindgen-tests/tests/headers/bindgen-union-inside-namespace.hpp index 6a7d3a300c..78b05b4f92 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.0 --enable-cxx-namespaces +// bindgen-flags: \-\-rust-target=1.33 --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 20a3f9dbbe..b80f5d99a5 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.27 -- -std=c++11 +// bindgen-flags: --bitfield-enum "Foo" \-\-rust-target=1.33 -- -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 e53bb0753c..b80f5d99a5 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.28 -- -std=c++11 +// bindgen-flags: --bitfield-enum "Foo" \-\-rust-target=1.33 -- -std=c++11 enum Foo { Bar = 1 << 1, diff --git a/bindgen-tests/tests/headers/class_1_0.hpp b/bindgen-tests/tests/headers/class_1_0.hpp deleted file mode 100644 index e3735eb68d..0000000000 --- a/bindgen-tests/tests/headers/class_1_0.hpp +++ /dev/null @@ -1,76 +0,0 @@ -// bindgen-flags: --rust-target 1.0 --with-derive-hash --with-derive-partialeq --impl-partialeq --with-derive-eq - -class C { - int a; - // More than rust limits (32) - char big_array[33]; -}; - -class C_with_zero_length_array { - int a; - // More than rust limits (32) - char big_array[33]; - char zero_length_array[0]; -}; - -class C_with_zero_length_array_2 { - int a; - char zero_length_array[0]; -}; - -class C_with_incomplete_array { - int a; - // More than rust limits (32) - char big_array[33]; - char incomplete_array[]; -}; - -class C_with_incomplete_array_2 { - int a; - char incomplete_array[]; -}; - - -class C_with_zero_length_array_and_incomplete_array { - int a; - // More than rust limits (32) - char big_array[33]; - char zero_length_array[0]; - char incomplete_array[]; -}; - -class C_with_zero_length_array_and_incomplete_array_2 { - int a; - char zero_length_array[0]; - char incomplete_array[]; -}; - - -class WithDtor { - int b; - - ~WithDtor() {} -}; - -class IncompleteArrayNonCopiable { - void* whatever; - C incomplete_array[]; -}; - -union Union { - float d; - int i; -}; - -class WithUnion { - Union data; -}; - -class RealAbstractionWithTonsOfMethods { - void foo(); -public: - void bar() const; - void bar(); - void bar(int foo); - static void sta(); -}; diff --git a/bindgen-tests/tests/headers/class_with_inner_struct_1_0.hpp b/bindgen-tests/tests/headers/class_with_inner_struct_1_0.hpp deleted file mode 100644 index 34ed96e722..0000000000 --- a/bindgen-tests/tests/headers/class_with_inner_struct_1_0.hpp +++ /dev/null @@ -1,44 +0,0 @@ -// bindgen-flags: --rust-target 1.0 --with-derive-hash --with-derive-partialeq --with-derive-eq --rustified-enum ".*" -// bindgen-flags: -- -std=c++11 - -class A { - unsigned c; - struct Segment { int begin, end; }; - union { - int f; - } named_union; - union { - int d; - }; -}; - -class B { - unsigned d; - struct Segment { int begin, end; }; -}; - - -enum class StepSyntax { - Keyword, // step-start and step-end - FunctionalWithoutKeyword, // steps(...) - FunctionalWithStartKeyword, // steps(..., start) - FunctionalWithEndKeyword, // steps(..., end) -}; - -class C { - unsigned d; - union { - struct { - float mX1; - float mY1; - float mX2; - float mY2; - } mFunc; - struct { - StepSyntax mStepSyntax; - unsigned int mSteps; - }; - }; - // To ensure it doesn't collide - struct Segment { int begin, end; }; -}; diff --git a/bindgen-tests/tests/headers/derive-clone_1_0.h b/bindgen-tests/tests/headers/derive-clone_1_0.h deleted file mode 100644 index 34ef40ae97..0000000000 --- a/bindgen-tests/tests/headers/derive-clone_1_0.h +++ /dev/null @@ -1,7 +0,0 @@ -// bindgen-flags: --rust-target 1.0 - -/// Since builtin `Clone` impls were introduced in Rust 1.21 this struct -/// should impl `Clone` "manually". -struct ShouldImplClone { - int large[33]; -}; diff --git a/bindgen-tests/tests/headers/derive-partialeq-union_1_0.hpp b/bindgen-tests/tests/headers/derive-partialeq-union_1_0.hpp deleted file mode 100644 index d546d77b10..0000000000 --- a/bindgen-tests/tests/headers/derive-partialeq-union_1_0.hpp +++ /dev/null @@ -1,7 +0,0 @@ -// bindgen-flags: --rust-target 1.0 --with-derive-partialeq --impl-partialeq - -/// This should manually derive PartialEq. -union ShouldDerivePartialEq { - char a[150]; - int b; -}; diff --git a/bindgen-tests/tests/headers/forward_declared_complex_types_1_0.hpp b/bindgen-tests/tests/headers/forward_declared_complex_types_1_0.hpp deleted file mode 100644 index ff6076fc43..0000000000 --- a/bindgen-tests/tests/headers/forward_declared_complex_types_1_0.hpp +++ /dev/null @@ -1,18 +0,0 @@ -// bindgen-flags: --rust-target 1.0 - -struct Foo_empty {}; -struct Foo; - -struct Bar { - Foo *f; -}; - -void baz_struct(Foo* f); - -union Union; - -void baz_union(Union* u); - -class Quux; - -void baz_class(Quux* q); diff --git a/bindgen-tests/tests/headers/i128.h b/bindgen-tests/tests/headers/i128.h index 6ec399c726..609d546190 100644 --- a/bindgen-tests/tests/headers/i128.h +++ b/bindgen-tests/tests/headers/i128.h @@ -1,4 +1,4 @@ -// bindgen-flags: --rust-target 1.26 +// bindgen-flags: \-\-rust-target=1.33 struct foo { __int128 my_signed; diff --git a/bindgen-tests/tests/headers/issue-1291.hpp b/bindgen-tests/tests/headers/issue-1291.hpp index 4ec524f12f..313f7f7103 100644 --- a/bindgen-tests/tests/headers/issue-1291.hpp +++ b/bindgen-tests/tests/headers/issue-1291.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --rust-target 1.25 +// bindgen-flags: \-\-rust-target=1.33 // bindgen-unstable struct __attribute__((aligned(16))) RTCRay diff --git a/bindgen-tests/tests/headers/issue-493_1_0.hpp b/bindgen-tests/tests/headers/issue-493_1_0.hpp deleted file mode 100644 index af6fd47c41..0000000000 --- a/bindgen-tests/tests/headers/issue-493_1_0.hpp +++ /dev/null @@ -1,49 +0,0 @@ -// bindgen-flags: --rust-target 1.0 --with-derive-hash --with-derive-partialeq --with-derive-eq --rustified-enum ".*" - -template -class basic_string -{ -public: - typedef unsigned long long size_type; - typedef char value_type; - typedef value_type * pointer; - - struct __long - { - size_type __cap_; - size_type __size_; - pointer __data_; - }; - - enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ? - (sizeof(__long) - 1)/sizeof(value_type) : 2}; - - struct __short - { - union - { - unsigned char __size_; - value_type __lx; - }; - value_type __data_[__min_cap]; - }; - - union __ulx{__long __lx; __short __lxx;}; - - enum {__n_words = sizeof(__ulx) / sizeof(size_type)}; - - struct __raw - { - size_type __words[__n_words]; - }; - - struct __rep - { - union - { - __long __l; - __short __s; - __raw __r; - }; - }; -}; diff --git a/bindgen-tests/tests/headers/jsval_layout_opaque_1_0.hpp b/bindgen-tests/tests/headers/jsval_layout_opaque_1_0.hpp deleted file mode 100644 index c8e665516b..0000000000 --- a/bindgen-tests/tests/headers/jsval_layout_opaque_1_0.hpp +++ /dev/null @@ -1,425 +0,0 @@ -// bindgen-flags: --rust-target 1.0 --with-derive-hash --with-derive-partialeq --with-derive-eq --rustified-enum ".*" -// bindgen-flags: -- -std=c++11 - -/** - * These typedefs are hacky, but keep our tests consistent across 64-bit - * platforms, otherwise the id's change and our CI is unhappy. - */ -typedef unsigned char uint8_t; -typedef int int32_t; -typedef unsigned int uint32_t; -typedef unsigned long long uint64_t; -typedef unsigned long long size_t; -typedef unsigned long long uintptr_t; - - -#define JS_PUNBOX64 -#define IS_LITTLE_ENDIAN - -/* - * Try to get jsvals 64-bit aligned. We could almost assert that all values are - * aligned, but MSVC and GCC occasionally break alignment. - */ -#if defined(__GNUC__) || defined(__xlc__) || defined(__xlC__) -# define JSVAL_ALIGNMENT __attribute__((aligned (8))) -#elif defined(_MSC_VER) - /* - * Structs can be aligned with MSVC, but not if they are used as parameters, - * so we just don't try to align. - */ -# define JSVAL_ALIGNMENT -#elif defined(__SUNPRO_C) || defined(__SUNPRO_CC) -# define JSVAL_ALIGNMENT -#elif defined(__HP_cc) || defined(__HP_aCC) -# define JSVAL_ALIGNMENT -#endif - -#if defined(JS_PUNBOX64) -# define JSVAL_TAG_SHIFT 47 -#endif - -/* - * We try to use enums so that printing a jsval_layout in the debugger shows - * nice symbolic type tags, however we can only do this when we can force the - * underlying type of the enum to be the desired size. - */ -#if !defined(__SUNPRO_CC) && !defined(__xlC__) - -#if defined(_MSC_VER) -# define JS_ENUM_HEADER(id, type) enum id : type -# define JS_ENUM_FOOTER(id) -#else -# define JS_ENUM_HEADER(id, type) enum id -# define JS_ENUM_FOOTER(id) __attribute__((packed)) -#endif - -/* Remember to propagate changes to the C defines below. */ -JS_ENUM_HEADER(JSValueType, uint8_t) -{ - JSVAL_TYPE_DOUBLE = 0x00, - JSVAL_TYPE_INT32 = 0x01, - JSVAL_TYPE_UNDEFINED = 0x02, - JSVAL_TYPE_BOOLEAN = 0x03, - JSVAL_TYPE_MAGIC = 0x04, - JSVAL_TYPE_STRING = 0x05, - JSVAL_TYPE_SYMBOL = 0x06, - JSVAL_TYPE_NULL = 0x07, - JSVAL_TYPE_OBJECT = 0x08, - - /* These never appear in a jsval; they are only provided as an out-of-band value. */ - JSVAL_TYPE_UNKNOWN = 0x20, - JSVAL_TYPE_MISSING = 0x21 -} JS_ENUM_FOOTER(JSValueType); - -static_assert(sizeof(JSValueType) == 1, - "compiler typed enum support is apparently buggy"); - -#if defined(JS_NUNBOX32) - -/* Remember to propagate changes to the C defines below. */ -JS_ENUM_HEADER(JSValueTag, uint32_t) -{ - JSVAL_TAG_CLEAR = 0xFFFFFF80, - JSVAL_TAG_INT32 = JSVAL_TAG_CLEAR | JSVAL_TYPE_INT32, - JSVAL_TAG_UNDEFINED = JSVAL_TAG_CLEAR | JSVAL_TYPE_UNDEFINED, - JSVAL_TAG_STRING = JSVAL_TAG_CLEAR | JSVAL_TYPE_STRING, - JSVAL_TAG_SYMBOL = JSVAL_TAG_CLEAR | JSVAL_TYPE_SYMBOL, - JSVAL_TAG_BOOLEAN = JSVAL_TAG_CLEAR | JSVAL_TYPE_BOOLEAN, - JSVAL_TAG_MAGIC = JSVAL_TAG_CLEAR | JSVAL_TYPE_MAGIC, - JSVAL_TAG_NULL = JSVAL_TAG_CLEAR | JSVAL_TYPE_NULL, - JSVAL_TAG_OBJECT = JSVAL_TAG_CLEAR | JSVAL_TYPE_OBJECT -} JS_ENUM_FOOTER(JSValueTag); - -static_assert(sizeof(JSValueTag) == sizeof(uint32_t), - "compiler typed enum support is apparently buggy"); - -#elif defined(JS_PUNBOX64) - -/* Remember to propagate changes to the C defines below. */ -JS_ENUM_HEADER(JSValueTag, uint32_t) -{ - JSVAL_TAG_MAX_DOUBLE = 0x1FFF0, - JSVAL_TAG_INT32 = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_INT32, - JSVAL_TAG_UNDEFINED = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_UNDEFINED, - JSVAL_TAG_STRING = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_STRING, - JSVAL_TAG_SYMBOL = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_SYMBOL, - JSVAL_TAG_BOOLEAN = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_BOOLEAN, - JSVAL_TAG_MAGIC = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_MAGIC, - JSVAL_TAG_NULL = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_NULL, - JSVAL_TAG_OBJECT = JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_OBJECT -} JS_ENUM_FOOTER(JSValueTag); - -static_assert(sizeof(JSValueTag) == sizeof(uint32_t), - "compiler typed enum support is apparently buggy"); - -JS_ENUM_HEADER(JSValueShiftedTag, uint64_t) -{ - JSVAL_SHIFTED_TAG_MAX_DOUBLE = ((((uint64_t)JSVAL_TAG_MAX_DOUBLE) << JSVAL_TAG_SHIFT) | 0xFFFFFFFF), - JSVAL_SHIFTED_TAG_INT32 = (((uint64_t)JSVAL_TAG_INT32) << JSVAL_TAG_SHIFT), - JSVAL_SHIFTED_TAG_UNDEFINED = (((uint64_t)JSVAL_TAG_UNDEFINED) << JSVAL_TAG_SHIFT), - JSVAL_SHIFTED_TAG_STRING = (((uint64_t)JSVAL_TAG_STRING) << JSVAL_TAG_SHIFT), - JSVAL_SHIFTED_TAG_SYMBOL = (((uint64_t)JSVAL_TAG_SYMBOL) << JSVAL_TAG_SHIFT), - JSVAL_SHIFTED_TAG_BOOLEAN = (((uint64_t)JSVAL_TAG_BOOLEAN) << JSVAL_TAG_SHIFT), - JSVAL_SHIFTED_TAG_MAGIC = (((uint64_t)JSVAL_TAG_MAGIC) << JSVAL_TAG_SHIFT), - JSVAL_SHIFTED_TAG_NULL = (((uint64_t)JSVAL_TAG_NULL) << JSVAL_TAG_SHIFT), - JSVAL_SHIFTED_TAG_OBJECT = (((uint64_t)JSVAL_TAG_OBJECT) << JSVAL_TAG_SHIFT) -} JS_ENUM_FOOTER(JSValueShiftedTag); - -static_assert(sizeof(JSValueShiftedTag) == sizeof(uint64_t), - "compiler typed enum support is apparently buggy"); - -#endif - -/* - * All our supported compilers implement C++11 |enum Foo : T| syntax, so don't - * expose these macros. (This macro exists *only* because gcc bug 51242 - * makes bit-fields of - * typed enums trigger a warning that can't be turned off. Don't expose it - * beyond this file!) - */ -#undef JS_ENUM_HEADER -#undef JS_ENUM_FOOTER - -#else /* !defined(__SUNPRO_CC) && !defined(__xlC__) */ - -typedef uint8_t JSValueType; -#define JSVAL_TYPE_DOUBLE ((uint8_t)0x00) -#define JSVAL_TYPE_INT32 ((uint8_t)0x01) -#define JSVAL_TYPE_UNDEFINED ((uint8_t)0x02) -#define JSVAL_TYPE_BOOLEAN ((uint8_t)0x03) -#define JSVAL_TYPE_MAGIC ((uint8_t)0x04) -#define JSVAL_TYPE_STRING ((uint8_t)0x05) -#define JSVAL_TYPE_SYMBOL ((uint8_t)0x06) -#define JSVAL_TYPE_NULL ((uint8_t)0x07) -#define JSVAL_TYPE_OBJECT ((uint8_t)0x08) -#define JSVAL_TYPE_UNKNOWN ((uint8_t)0x20) - -#if defined(JS_NUNBOX32) - -typedef uint32_t JSValueTag; -#define JSVAL_TAG_CLEAR ((uint32_t)(0xFFFFFF80)) -#define JSVAL_TAG_INT32 ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_INT32)) -#define JSVAL_TAG_UNDEFINED ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_UNDEFINED)) -#define JSVAL_TAG_STRING ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_STRING)) -#define JSVAL_TAG_SYMBOL ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_SYMBOL)) -#define JSVAL_TAG_BOOLEAN ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_BOOLEAN)) -#define JSVAL_TAG_MAGIC ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_MAGIC)) -#define JSVAL_TAG_NULL ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_NULL)) -#define JSVAL_TAG_OBJECT ((uint32_t)(JSVAL_TAG_CLEAR | JSVAL_TYPE_OBJECT)) - -#elif defined(JS_PUNBOX64) - -typedef uint32_t JSValueTag; -#define JSVAL_TAG_MAX_DOUBLE ((uint32_t)(0x1FFF0)) -#define JSVAL_TAG_INT32 (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_INT32) -#define JSVAL_TAG_UNDEFINED (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_UNDEFINED) -#define JSVAL_TAG_STRING (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_STRING) -#define JSVAL_TAG_SYMBOL (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_SYMBOL) -#define JSVAL_TAG_BOOLEAN (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_BOOLEAN) -#define JSVAL_TAG_MAGIC (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_MAGIC) -#define JSVAL_TAG_NULL (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_NULL) -#define JSVAL_TAG_OBJECT (uint32_t)(JSVAL_TAG_MAX_DOUBLE | JSVAL_TYPE_OBJECT) - -typedef uint64_t JSValueShiftedTag; -#define JSVAL_SHIFTED_TAG_MAX_DOUBLE ((((uint64_t)JSVAL_TAG_MAX_DOUBLE) << JSVAL_TAG_SHIFT) | 0xFFFFFFFF) -#define JSVAL_SHIFTED_TAG_INT32 (((uint64_t)JSVAL_TAG_INT32) << JSVAL_TAG_SHIFT) -#define JSVAL_SHIFTED_TAG_UNDEFINED (((uint64_t)JSVAL_TAG_UNDEFINED) << JSVAL_TAG_SHIFT) -#define JSVAL_SHIFTED_TAG_STRING (((uint64_t)JSVAL_TAG_STRING) << JSVAL_TAG_SHIFT) -#define JSVAL_SHIFTED_TAG_SYMBOL (((uint64_t)JSVAL_TAG_SYMBOL) << JSVAL_TAG_SHIFT) -#define JSVAL_SHIFTED_TAG_BOOLEAN (((uint64_t)JSVAL_TAG_BOOLEAN) << JSVAL_TAG_SHIFT) -#define JSVAL_SHIFTED_TAG_MAGIC (((uint64_t)JSVAL_TAG_MAGIC) << JSVAL_TAG_SHIFT) -#define JSVAL_SHIFTED_TAG_NULL (((uint64_t)JSVAL_TAG_NULL) << JSVAL_TAG_SHIFT) -#define JSVAL_SHIFTED_TAG_OBJECT (((uint64_t)JSVAL_TAG_OBJECT) << JSVAL_TAG_SHIFT) - -#endif /* JS_PUNBOX64 */ -#endif /* !defined(__SUNPRO_CC) && !defined(__xlC__) */ - -#if defined(JS_NUNBOX32) - -#define JSVAL_TYPE_TO_TAG(type) ((JSValueTag)(JSVAL_TAG_CLEAR | (type))) - -#define JSVAL_LOWER_INCL_TAG_OF_OBJ_OR_NULL_SET JSVAL_TAG_NULL -#define JSVAL_UPPER_EXCL_TAG_OF_PRIMITIVE_SET JSVAL_TAG_OBJECT -#define JSVAL_UPPER_INCL_TAG_OF_NUMBER_SET JSVAL_TAG_INT32 -#define JSVAL_LOWER_INCL_TAG_OF_GCTHING_SET JSVAL_TAG_STRING - -#elif defined(JS_PUNBOX64) - -#define JSVAL_PAYLOAD_MASK 0x00007FFFFFFFFFFFLL -#define JSVAL_TAG_MASK 0xFFFF800000000000LL -#define JSVAL_TYPE_TO_TAG(type) ((JSValueTag)(JSVAL_TAG_MAX_DOUBLE | (type))) -#define JSVAL_TYPE_TO_SHIFTED_TAG(type) (((uint64_t)JSVAL_TYPE_TO_TAG(type)) << JSVAL_TAG_SHIFT) - -#define JSVAL_LOWER_INCL_TAG_OF_OBJ_OR_NULL_SET JSVAL_TAG_NULL -#define JSVAL_UPPER_EXCL_TAG_OF_PRIMITIVE_SET JSVAL_TAG_OBJECT -#define JSVAL_UPPER_INCL_TAG_OF_NUMBER_SET JSVAL_TAG_INT32 -#define JSVAL_LOWER_INCL_TAG_OF_GCTHING_SET JSVAL_TAG_STRING - -#define JSVAL_LOWER_INCL_SHIFTED_TAG_OF_OBJ_OR_NULL_SET JSVAL_SHIFTED_TAG_NULL -#define JSVAL_UPPER_EXCL_SHIFTED_TAG_OF_PRIMITIVE_SET JSVAL_SHIFTED_TAG_OBJECT -#define JSVAL_UPPER_EXCL_SHIFTED_TAG_OF_NUMBER_SET JSVAL_SHIFTED_TAG_UNDEFINED -#define JSVAL_LOWER_INCL_SHIFTED_TAG_OF_GCTHING_SET JSVAL_SHIFTED_TAG_STRING - -#endif /* JS_PUNBOX64 */ - -typedef enum JSWhyMagic -{ - /** a hole in a native object's elements */ - JS_ELEMENTS_HOLE, - - /** there is not a pending iterator value */ - JS_NO_ITER_VALUE, - - /** exception value thrown when closing a generator */ - JS_GENERATOR_CLOSING, - - /** compiler sentinel value */ - JS_NO_CONSTANT, - - /** used in debug builds to catch tracing errors */ - JS_THIS_POISON, - - /** used in debug builds to catch tracing errors */ - JS_ARG_POISON, - - /** an empty subnode in the AST serializer */ - JS_SERIALIZE_NO_NODE, - - /** lazy arguments value on the stack */ - JS_LAZY_ARGUMENTS, - - /** optimized-away 'arguments' value */ - JS_OPTIMIZED_ARGUMENTS, - - /** magic value passed to natives to indicate construction */ - JS_IS_CONSTRUCTING, - - /** arguments.callee has been overwritten */ - JS_OVERWRITTEN_CALLEE, - - /** value of static block object slot */ - JS_BLOCK_NEEDS_CLONE, - - /** see class js::HashableValue */ - JS_HASH_KEY_EMPTY, - - /** error while running Ion code */ - JS_ION_ERROR, - - /** missing recover instruction result */ - JS_ION_BAILOUT, - - /** optimized out slot */ - JS_OPTIMIZED_OUT, - - /** uninitialized lexical bindings that produce ReferenceError on touch. */ - JS_UNINITIALIZED_LEXICAL, - - /** for local use */ - JS_GENERIC_MAGIC, - - JS_WHY_MAGIC_COUNT -} JSWhyMagic; - -#if defined(IS_LITTLE_ENDIAN) -# if defined(JS_NUNBOX32) -typedef union jsval_layout -{ - uint64_t asBits; - struct { - union { - int32_t i32; - uint32_t u32; - uint32_t boo; // Don't use |bool| -- it must be four bytes. - JSString* str; - JS::Symbol* sym; - JSObject* obj; - js::gc::Cell* cell; - void* ptr; - JSWhyMagic why; - size_t word; - uintptr_t uintptr; - } payload; - JSValueTag tag; - } s; - double asDouble; - void* asPtr; -} JSVAL_ALIGNMENT jsval_layout; -# elif defined(JS_PUNBOX64) -typedef union jsval_layout -{ - uint64_t asBits; -#if !defined(_WIN64) - /* MSVC does not pack these correctly :-( */ - struct { - uint64_t payload47 : 47; - JSValueTag tag : 17; - } debugView; -#endif - struct { - union { - int32_t i32; - uint32_t u32; - JSWhyMagic why; - } payload; - } s; - double asDouble; - void* asPtr; - size_t asWord; - uintptr_t asUIntPtr; -} JSVAL_ALIGNMENT jsval_layout; -# endif /* JS_PUNBOX64 */ -#else /* defined(IS_LITTLE_ENDIAN) */ -# if defined(JS_NUNBOX32) -typedef union jsval_layout -{ - uint64_t asBits; - struct { - JSValueTag tag; - union { - int32_t i32; - uint32_t u32; - uint32_t boo; // Don't use |bool| -- it must be four bytes. - JSString* str; - JS::Symbol* sym; - JSObject* obj; - js::gc::Cell* cell; - void* ptr; - JSWhyMagic why; - size_t word; - uintptr_t uintptr; - } payload; - } s; - double asDouble; - void* asPtr; -} JSVAL_ALIGNMENT jsval_layout; -# elif defined(JS_PUNBOX64) -typedef union jsval_layout -{ - uint64_t asBits; - struct { - JSValueTag tag : 17; - uint64_t payload47 : 47; - } debugView; - struct { - uint32_t padding; - union { - int32_t i32; - uint32_t u32; - JSWhyMagic why; - } payload; - } s; - double asDouble; - void* asPtr; - size_t asWord; - uintptr_t asUIntPtr; -} JSVAL_ALIGNMENT jsval_layout; -# endif /* JS_PUNBOX64 */ -#endif /* defined(IS_LITTLE_ENDIAN) */ - -/* - * For codesize purposes on some platforms, it's important that the - * compiler know that JS::Values constructed from constant values can be - * folded to constant bit patterns at compile time, rather than - * constructed at runtime. Doing this requires a fair amount of C++11 - * features, which are not supported on all of our compilers. Set up - * some defines and helper macros in an attempt to confine the ugliness - * here, rather than scattering it all about the file. The important - * features are: - * - * - constexpr; - * - defaulted functions; - * - C99-style designated initializers. - */ -#if defined(__clang__) -# if __has_feature(cxx_constexpr) && __has_feature(cxx_defaulted_functions) -# define JS_VALUE_IS_CONSTEXPR -# endif -#elif defined(__GNUC__) -/* - * We need 4.5 for defaulted functions, 4.6 for constexpr, 4.7 because 4.6 - * doesn't understand |(X) { .field = ... }| syntax, and 4.7.3 because - * versions prior to that have bugs in the C++ front-end that cause crashes. - */ -# if MOZ_GCC_VERSION_AT_LEAST(4, 7, 3) -# define JS_VALUE_IS_CONSTEXPR -# endif -#endif - -#if defined(JS_VALUE_IS_CONSTEXPR) -# define JS_RETURN_LAYOUT_FROM_BITS(BITS) \ - return (jsval_layout) { .asBits = (BITS) } -# define JS_VALUE_CONSTEXPR MOZ_CONSTEXPR -# define JS_VALUE_CONSTEXPR_VAR MOZ_CONSTEXPR_VAR -#else -# define JS_RETURN_LAYOUT_FROM_BITS(BITS) \ - jsval_layout l; \ - l.asBits = (BITS); \ - return l; -# define JS_VALUE_CONSTEXPR -# define JS_VALUE_CONSTEXPR_VAR const -#endif - -struct Value { - jsval_layout data; -}; diff --git a/bindgen-tests/tests/headers/layout.h b/bindgen-tests/tests/headers/layout.h index b290ee856b..6a3df9b3f5 100644 --- a/bindgen-tests/tests/headers/layout.h +++ b/bindgen-tests/tests/headers/layout.h @@ -1,4 +1,4 @@ -// bindgen-flags: --rust-target 1.21 +// bindgen-flags: \-\-rust-target=1.33 // // FIXME: https://github.com/rust-lang/rust-bindgen/issues/1498 diff --git a/bindgen-tests/tests/headers/layout_eth_conf_1_0.h b/bindgen-tests/tests/headers/layout_eth_conf_1_0.h deleted file mode 100644 index 7da582ba19..0000000000 --- a/bindgen-tests/tests/headers/layout_eth_conf_1_0.h +++ /dev/null @@ -1,429 +0,0 @@ -// bindgen-flags: --rust-target 1.0 --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; -typedef unsigned long long uint64_t; - -/** - * Simple flags are used for rte_eth_conf.rxmode.mq_mode. - */ -#define ETH_MQ_RX_RSS_FLAG 0x1 -#define ETH_MQ_RX_DCB_FLAG 0x2 -#define ETH_MQ_RX_VMDQ_FLAG 0x4 - -/* Definitions used for VMDQ and DCB functionality */ -#define ETH_VMDQ_MAX_VLAN_FILTERS 64 /**< Maximum nb. of VMDQ vlan filters. */ -#define ETH_DCB_NUM_USER_PRIORITIES 8 /**< Maximum nb. of DCB priorities. */ -#define ETH_VMDQ_DCB_NUM_QUEUES 128 /**< Maximum nb. of VMDQ DCB queues. */ -#define ETH_DCB_NUM_QUEUES 128 /**< Maximum nb. of DCB queues. */ - -/** - * A set of values to identify what method is to be used to route - * packets to multiple queues. - */ -enum rte_eth_rx_mq_mode { - /** None of DCB,RSS or VMDQ mode */ - ETH_MQ_RX_NONE = 0, - - /** For RX side, only RSS is on */ - ETH_MQ_RX_RSS = ETH_MQ_RX_RSS_FLAG, - /** For RX side,only DCB is on. */ - ETH_MQ_RX_DCB = ETH_MQ_RX_DCB_FLAG, - /** Both DCB and RSS enable */ - ETH_MQ_RX_DCB_RSS = ETH_MQ_RX_RSS_FLAG | ETH_MQ_RX_DCB_FLAG, - - /** Only VMDQ, no RSS nor DCB */ - ETH_MQ_RX_VMDQ_ONLY = ETH_MQ_RX_VMDQ_FLAG, - /** RSS mode with VMDQ */ - ETH_MQ_RX_VMDQ_RSS = ETH_MQ_RX_RSS_FLAG | ETH_MQ_RX_VMDQ_FLAG, - /** Use VMDQ+DCB to route traffic to queues */ - ETH_MQ_RX_VMDQ_DCB = ETH_MQ_RX_VMDQ_FLAG | ETH_MQ_RX_DCB_FLAG, - /** Enable both VMDQ and DCB in VMDq */ - ETH_MQ_RX_VMDQ_DCB_RSS = ETH_MQ_RX_RSS_FLAG | ETH_MQ_RX_DCB_FLAG | - ETH_MQ_RX_VMDQ_FLAG, -}; - -/** - * A structure used to configure the RX features of an Ethernet port. - */ -struct rte_eth_rxmode { - /** The multi-queue packet distribution mode to be used, e.g. RSS. */ - enum rte_eth_rx_mq_mode mq_mode; - uint32_t max_rx_pkt_len; /**< Only used if jumbo_frame enabled. */ - uint16_t split_hdr_size; /**< hdr buf size (header_split enabled).*/ - __extension__ - uint16_t header_split : 1, /**< Header Split enable. */ - hw_ip_checksum : 1, /**< IP/UDP/TCP checksum offload enable. */ - hw_vlan_filter : 1, /**< VLAN filter enable. */ - hw_vlan_strip : 1, /**< VLAN strip enable. */ - hw_vlan_extend : 1, /**< Extended VLAN enable. */ - jumbo_frame : 1, /**< Jumbo Frame Receipt enable. */ - hw_strip_crc : 1, /**< Enable CRC stripping by hardware. */ - enable_scatter : 1, /**< Enable scatter packets rx handler */ - enable_lro : 1; /**< Enable LRO */ -}; - -/** - * A set of values to identify what method is to be used to transmit - * packets using multi-TCs. - */ -enum rte_eth_tx_mq_mode { - ETH_MQ_TX_NONE = 0, /**< It is in neither DCB nor VT mode. */ - ETH_MQ_TX_DCB, /**< For TX side,only DCB is on. */ - ETH_MQ_TX_VMDQ_DCB, /**< For TX side,both DCB and VT is on. */ - ETH_MQ_TX_VMDQ_ONLY, /**< Only VT on, no DCB */ -}; - -/** - * A structure used to configure the TX features of an Ethernet port. - */ -struct rte_eth_txmode { - enum rte_eth_tx_mq_mode mq_mode; /**< TX multi-queues mode. */ - - /* For i40e specifically */ - uint16_t pvid; - __extension__ - uint8_t hw_vlan_reject_tagged : 1, - /**< If set, reject sending out tagged pkts */ - hw_vlan_reject_untagged : 1, - /**< If set, reject sending out untagged pkts */ - hw_vlan_insert_pvid : 1; - /**< If set, enable port based VLAN insertion */ -}; - -/** - * A structure used to configure the Receive Side Scaling (RSS) feature - * of an Ethernet port. - * If not NULL, the *rss_key* pointer of the *rss_conf* structure points - * to an array holding the RSS key to use for hashing specific header - * fields of received packets. The length of this array should be indicated - * by *rss_key_len* below. Otherwise, a default random hash key is used by - * the device driver. - * - * The *rss_key_len* field of the *rss_conf* structure indicates the length - * in bytes of the array pointed by *rss_key*. To be compatible, this length - * will be checked in i40e only. Others assume 40 bytes to be used as before. - * - * The *rss_hf* field of the *rss_conf* structure indicates the different - * types of IPv4/IPv6 packets to which the RSS hashing must be applied. - * Supplying an *rss_hf* equal to zero disables the RSS feature. - */ -struct rte_eth_rss_conf { - uint8_t *rss_key; /**< If not NULL, 40-byte hash key. */ - uint8_t rss_key_len; /**< hash key length in bytes. */ - uint64_t rss_hf; /**< Hash functions to apply - see below. */ -}; - -/** - * This enum indicates the possible number of traffic classes - * in DCB configratioins - */ -enum rte_eth_nb_tcs { - ETH_4_TCS = 4, /**< 4 TCs with DCB. */ - ETH_8_TCS = 8 /**< 8 TCs with DCB. */ -}; - -/** - * This enum indicates the possible number of queue pools - * in VMDQ configurations. - */ -enum rte_eth_nb_pools { - ETH_8_POOLS = 8, /**< 8 VMDq pools. */ - ETH_16_POOLS = 16, /**< 16 VMDq pools. */ - ETH_32_POOLS = 32, /**< 32 VMDq pools. */ - ETH_64_POOLS = 64 /**< 64 VMDq pools. */ -}; - -/** - * A structure used to configure the VMDQ+DCB feature - * of an Ethernet port. - * - * Using this feature, packets are routed to a pool of queues, based - * on the vlan ID in the vlan tag, and then to a specific queue within - * that pool, using the user priority vlan tag field. - * - * A default pool may be used, if desired, to route all traffic which - * does not match the vlan filter rules. - */ -struct rte_eth_vmdq_dcb_conf { - enum rte_eth_nb_pools nb_queue_pools; /**< With DCB, 16 or 32 pools */ - uint8_t enable_default_pool; /**< If non-zero, use a default pool */ - uint8_t default_pool; /**< The default pool, if applicable */ - uint8_t nb_pool_maps; /**< We can have up to 64 filters/mappings */ - struct { - uint16_t vlan_id; /**< The vlan ID of the received frame */ - uint64_t pools; /**< Bitmask of pools for packet rx */ - } pool_map[ETH_VMDQ_MAX_VLAN_FILTERS]; /**< VMDq vlan pool maps. */ - uint8_t dcb_tc[ETH_DCB_NUM_USER_PRIORITIES]; - /**< Selects a queue in a pool */ -}; - -/* This structure may be extended in future. */ -struct rte_eth_dcb_rx_conf { - enum rte_eth_nb_tcs nb_tcs; /**< Possible DCB TCs, 4 or 8 TCs */ - /** Traffic class each UP mapped to. */ - uint8_t dcb_tc[ETH_DCB_NUM_USER_PRIORITIES]; -}; - -struct rte_eth_vmdq_dcb_tx_conf { - enum rte_eth_nb_pools nb_queue_pools; /**< With DCB, 16 or 32 pools. */ - /** Traffic class each UP mapped to. */ - uint8_t dcb_tc[ETH_DCB_NUM_USER_PRIORITIES]; -}; - -struct rte_eth_dcb_tx_conf { - enum rte_eth_nb_tcs nb_tcs; /**< Possible DCB TCs, 4 or 8 TCs. */ - /** Traffic class each UP mapped to. */ - uint8_t dcb_tc[ETH_DCB_NUM_USER_PRIORITIES]; -}; - -struct rte_eth_vmdq_tx_conf { - enum rte_eth_nb_pools nb_queue_pools; /**< VMDq mode, 64 pools. */ -}; - -struct rte_eth_vmdq_rx_conf { - enum rte_eth_nb_pools nb_queue_pools; /**< VMDq only mode, 8 or 64 pools */ - uint8_t enable_default_pool; /**< If non-zero, use a default pool */ - uint8_t default_pool; /**< The default pool, if applicable */ - uint8_t enable_loop_back; /**< Enable VT loop back */ - uint8_t nb_pool_maps; /**< We can have up to 64 filters/mappings */ - uint32_t rx_mode; /**< Flags from ETH_VMDQ_ACCEPT_* */ - struct { - uint16_t vlan_id; /**< The vlan ID of the received frame */ - uint64_t pools; /**< Bitmask of pools for packet rx */ - } pool_map[ETH_VMDQ_MAX_VLAN_FILTERS]; /**< VMDq vlan pool maps. */ -}; - -/** - * Flow Director setting modes: none, signature or perfect. - */ -enum rte_fdir_mode { - RTE_FDIR_MODE_NONE = 0, /**< Disable FDIR support. */ - RTE_FDIR_MODE_SIGNATURE, /**< Enable FDIR signature filter mode. */ - RTE_FDIR_MODE_PERFECT, /**< Enable FDIR perfect filter mode. */ - RTE_FDIR_MODE_PERFECT_MAC_VLAN, /**< Enable FDIR filter mode - MAC VLAN. */ - RTE_FDIR_MODE_PERFECT_TUNNEL, /**< Enable FDIR filter mode - tunnel. */ -}; - -/** - * Memory space that can be configured to store Flow Director filters - * in the board memory. - */ -enum rte_fdir_pballoc_type { - RTE_FDIR_PBALLOC_64K = 0, /**< 64k. */ - RTE_FDIR_PBALLOC_128K, /**< 128k. */ - RTE_FDIR_PBALLOC_256K, /**< 256k. */ -}; - -/** - * Select report mode of FDIR hash information in RX descriptors. - */ -enum rte_fdir_status_mode { - RTE_FDIR_NO_REPORT_STATUS = 0, /**< Never report FDIR hash. */ - RTE_FDIR_REPORT_STATUS, /**< Only report FDIR hash for matching pkts. */ - RTE_FDIR_REPORT_STATUS_ALWAYS, /**< Always report FDIR hash. */ -}; - -/** - * A structure used to define the input for IPV4 flow - */ -struct rte_eth_ipv4_flow { - uint32_t src_ip; /**< IPv4 source address in big endian. */ - uint32_t dst_ip; /**< IPv4 destination address in big endian. */ - uint8_t tos; /**< Type of service to match. */ - uint8_t ttl; /**< Time to live to match. */ - uint8_t proto; /**< Protocol, next header in big endian. */ -}; - -/** - * A structure used to define the input for IPV6 flow - */ -struct rte_eth_ipv6_flow { - uint32_t src_ip[4]; /**< IPv6 source address in big endian. */ - uint32_t dst_ip[4]; /**< IPv6 destination address in big endian. */ - uint8_t tc; /**< Traffic class to match. */ - uint8_t proto; /**< Protocol, next header to match. */ - uint8_t hop_limits; /**< Hop limits to match. */ -}; - -/** - * A structure used to configure FDIR masks that are used by the device - * to match the various fields of RX packet headers. - */ -struct rte_eth_fdir_masks { - uint16_t vlan_tci_mask; /**< Bit mask for vlan_tci in big endian */ - /** Bit mask for ipv4 flow in big endian. */ - struct rte_eth_ipv4_flow ipv4_mask; - /** Bit maks for ipv6 flow in big endian. */ - struct rte_eth_ipv6_flow ipv6_mask; - /** Bit mask for L4 source port in big endian. */ - uint16_t src_port_mask; - /** Bit mask for L4 destination port in big endian. */ - uint16_t dst_port_mask; - /** 6 bit mask for proper 6 bytes of Mac address, bit 0 matches the - first byte on the wire */ - uint8_t mac_addr_byte_mask; - /** Bit mask for tunnel ID in big endian. */ - uint32_t tunnel_id_mask; - uint8_t tunnel_type_mask; /**< 1 - Match tunnel type, - 0 - Ignore tunnel type. */ -}; - -/** - * Payload type - */ -enum rte_eth_payload_type { - RTE_ETH_PAYLOAD_UNKNOWN = 0, - RTE_ETH_RAW_PAYLOAD, - RTE_ETH_L2_PAYLOAD, - RTE_ETH_L3_PAYLOAD, - RTE_ETH_L4_PAYLOAD, - RTE_ETH_PAYLOAD_MAX = 8, -}; - -#define RTE_ETH_FDIR_MAX_FLEXLEN 16 /**< Max length of flexbytes. */ -#define RTE_ETH_INSET_SIZE_MAX 128 /**< Max length of input set. */ - -/** - * A structure used to select bytes extracted from the protocol layers to - * flexible payload for filter - */ -struct rte_eth_flex_payload_cfg { - enum rte_eth_payload_type type; /**< Payload type */ - uint16_t src_offset[RTE_ETH_FDIR_MAX_FLEXLEN]; - /**< Offset in bytes from the beginning of packet's payload - src_offset[i] indicates the flexbyte i's offset in original - packet payload. This value should be less than - flex_payload_limit in struct rte_eth_fdir_info.*/ -}; - -/** - * A structure used to define FDIR masks for flexible payload - * for each flow type - */ -struct rte_eth_fdir_flex_mask { - uint16_t flow_type; - uint8_t mask[RTE_ETH_FDIR_MAX_FLEXLEN]; - /**< Mask for the whole flexible payload */ -}; - - -/* - * A packet can be identified by hardware as different flow types. Different - * NIC hardwares may support different flow types. - * Basically, the NIC hardware identifies the flow type as deep protocol as - * possible, and exclusively. For example, if a packet is identified as - * 'RTE_ETH_FLOW_NONFRAG_IPV4_TCP', it will not be any of other flow types, - * though it is an actual IPV4 packet. - * Note that the flow types are used to define RSS offload types in - * rte_ethdev.h. - */ -#define RTE_ETH_FLOW_UNKNOWN 0 -#define RTE_ETH_FLOW_RAW 1 -#define RTE_ETH_FLOW_IPV4 2 -#define RTE_ETH_FLOW_FRAG_IPV4 3 -#define RTE_ETH_FLOW_NONFRAG_IPV4_TCP 4 -#define RTE_ETH_FLOW_NONFRAG_IPV4_UDP 5 -#define RTE_ETH_FLOW_NONFRAG_IPV4_SCTP 6 -#define RTE_ETH_FLOW_NONFRAG_IPV4_OTHER 7 -#define RTE_ETH_FLOW_IPV6 8 -#define RTE_ETH_FLOW_FRAG_IPV6 9 -#define RTE_ETH_FLOW_NONFRAG_IPV6_TCP 10 -#define RTE_ETH_FLOW_NONFRAG_IPV6_UDP 11 -#define RTE_ETH_FLOW_NONFRAG_IPV6_SCTP 12 -#define RTE_ETH_FLOW_NONFRAG_IPV6_OTHER 13 -#define RTE_ETH_FLOW_L2_PAYLOAD 14 -#define RTE_ETH_FLOW_IPV6_EX 15 -#define RTE_ETH_FLOW_IPV6_TCP_EX 16 -#define RTE_ETH_FLOW_IPV6_UDP_EX 17 -#define RTE_ETH_FLOW_PORT 18 - /**< Consider device port number as a flow differentiator */ -#define RTE_ETH_FLOW_VXLAN 19 /**< VXLAN protocol based flow */ -#define RTE_ETH_FLOW_GENEVE 20 /**< GENEVE protocol based flow */ -#define RTE_ETH_FLOW_NVGRE 21 /**< NVGRE protocol based flow */ -#define RTE_ETH_FLOW_MAX 22 - -/** - * A structure used to define all flexible payload related setting - * include flex payload and flex mask - */ -struct rte_eth_fdir_flex_conf { - uint16_t nb_payloads; /**< The number of following payload cfg */ - uint16_t nb_flexmasks; /**< The number of following mask */ - struct rte_eth_flex_payload_cfg flex_set[RTE_ETH_PAYLOAD_MAX]; - /**< Flex payload configuration for each payload type */ - struct rte_eth_fdir_flex_mask flex_mask[RTE_ETH_FLOW_MAX]; - /**< Flex mask configuration for each flow type */ -}; - -/** - * A structure used to configure the Flow Director (FDIR) feature - * of an Ethernet port. - * - * If mode is RTE_FDIR_DISABLE, the pballoc value is ignored. - */ -struct rte_fdir_conf { - enum rte_fdir_mode mode; /**< Flow Director mode. */ - enum rte_fdir_pballoc_type pballoc; /**< Space for FDIR filters. */ - enum rte_fdir_status_mode status; /**< How to report FDIR hash. */ - /** RX queue of packets matching a "drop" filter in perfect mode. */ - uint8_t drop_queue; - struct rte_eth_fdir_masks mask; - struct rte_eth_fdir_flex_conf flex_conf; - /**< Flex payload configuration. */ -}; - -/** - * A structure used to enable/disable specific device interrupts. - */ -struct rte_intr_conf { - /** enable/disable lsc interrupt. 0 (default) - disable, 1 enable */ - uint16_t lsc; - /** enable/disable rxq interrupt. 0 (default) - disable, 1 enable */ - uint16_t rxq; -}; - -/** - * A structure used to configure an Ethernet port. - * Depending upon the RX multi-queue mode, extra advanced - * configuration settings may be needed. - */ -struct rte_eth_conf { - uint32_t link_speeds; /**< bitmap of ETH_LINK_SPEED_XXX of speeds to be - used. ETH_LINK_SPEED_FIXED disables link - autonegotiation, and a unique speed shall be - set. Otherwise, the bitmap defines the set of - speeds to be advertised. If the special value - ETH_LINK_SPEED_AUTONEG (0) is used, all speeds - supported are advertised. */ - struct rte_eth_rxmode rxmode; /**< Port RX configuration. */ - struct rte_eth_txmode txmode; /**< Port TX configuration. */ - uint32_t lpbk_mode; /**< Loopback operation mode. By default the value - is 0, meaning the loopback mode is disabled. - Read the datasheet of given ethernet controller - for details. The possible values of this field - are defined in implementation of each driver. */ - struct { - struct rte_eth_rss_conf rss_conf; /**< Port RSS configuration */ - struct rte_eth_vmdq_dcb_conf vmdq_dcb_conf; - /**< Port vmdq+dcb configuration. */ - struct rte_eth_dcb_rx_conf dcb_rx_conf; - /**< Port dcb RX configuration. */ - struct rte_eth_vmdq_rx_conf vmdq_rx_conf; - /**< Port vmdq RX configuration. */ - } rx_adv_conf; /**< Port RX filtering configuration (union). */ - union { - struct rte_eth_vmdq_dcb_tx_conf vmdq_dcb_tx_conf; - /**< Port vmdq+dcb TX configuration. */ - struct rte_eth_dcb_tx_conf dcb_tx_conf; - /**< Port dcb TX configuration. */ - struct rte_eth_vmdq_tx_conf vmdq_tx_conf; - /**< Port vmdq TX configuration. */ - } tx_adv_conf; /**< Port TX DCB configuration (union). */ - /** Currently,Priority Flow Control(PFC) are supported,if DCB with PFC - is needed,and the variable must be set ETH_DCB_PFC_SUPPORT. */ - uint32_t dcb_capability_en; - struct rte_fdir_conf fdir_conf; /**< FDIR configuration. */ - struct rte_intr_conf intr_conf; /**< Interrupt mode configuration. */ -}; diff --git a/bindgen-tests/tests/headers/layout_mbuf_1_0.h b/bindgen-tests/tests/headers/layout_mbuf_1_0.h deleted file mode 100644 index 2854de5038..0000000000 --- a/bindgen-tests/tests/headers/layout_mbuf_1_0.h +++ /dev/null @@ -1,189 +0,0 @@ -// bindgen-flags: --rust-target 1.0 --with-derive-hash --with-derive-partialeq --with-derive-eq - - -#define RTE_CACHE_LINE_MIN_SIZE 64 /**< Minimum Cache line size. */ - -#define RTE_CACHE_LINE_SIZE 64 - -typedef char int8_t; -typedef short int16_t; -typedef int int32_t; -typedef long long int64_t; - -typedef unsigned char uint8_t; -typedef unsigned short uint16_t; -typedef unsigned int uint32_t; -typedef unsigned long long uint64_t; - -typedef uint64_t phys_addr_t; - -/** - * Force alignment - */ -#define __rte_aligned(a) __attribute__((__aligned__(a))) - -/** - * Force alignment to cache line. - */ -#define __rte_cache_aligned __rte_aligned(RTE_CACHE_LINE_SIZE) - -/** - * Force minimum cache line alignment. - */ -#define __rte_cache_min_aligned __rte_aligned(RTE_CACHE_LINE_MIN_SIZE) - -/* define a set of marker types that can be used to refer to set points in the - * mbuf */ -__extension__ -typedef void *MARKER[0]; /**< generic marker for a point in a structure */ -__extension__ -typedef uint8_t MARKER8[0]; /**< generic marker with 1B alignment */ -__extension__ -typedef uint64_t MARKER64[0]; /**< marker that allows us to overwrite 8 bytes - * with a single assignment */ - -/** C extension macro for environments lacking C11 features. */ -#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L -#define RTE_STD_C11 __extension__ -#else -#define RTE_STD_C11 -#endif - -/** - * The atomic counter structure. - */ -typedef struct { - volatile int16_t cnt; /**< An internal counter value. */ -} rte_atomic16_t; - -/** - * The generic rte_mbuf, containing a packet mbuf. - */ -struct rte_mbuf { - MARKER cacheline0; - - void *buf_addr; /**< Virtual address of segment buffer. */ - phys_addr_t buf_physaddr; /**< Physical address of segment buffer. */ - - uint16_t buf_len; /**< Length of segment buffer. */ - - /* next 6 bytes are initialised on RX descriptor rearm */ - MARKER8 rearm_data; - uint16_t data_off; - - /** - * 16-bit Reference counter. - * It should only be accessed using the following functions: - * rte_mbuf_refcnt_update(), rte_mbuf_refcnt_read(), and - * rte_mbuf_refcnt_set(). The functionality of these functions (atomic, - * or non-atomic) is controlled by the CONFIG_RTE_MBUF_REFCNT_ATOMIC - * config option. - */ - RTE_STD_C11 - union { - rte_atomic16_t refcnt_atomic; /**< Atomically accessed refcnt */ - uint16_t refcnt; /**< Non-atomically accessed refcnt */ - }; - uint8_t nb_segs; /**< Number of segments. */ - uint8_t port; /**< Input port. */ - - uint64_t ol_flags; /**< Offload features. */ - - /* remaining bytes are set on RX when pulling packet from descriptor */ - MARKER rx_descriptor_fields1; - - /* - * The packet type, which is the combination of outer/inner L2, L3, L4 - * and tunnel types. The packet_type is about data really present in the - * mbuf. Example: if vlan stripping is enabled, a received vlan packet - * would have RTE_PTYPE_L2_ETHER and not RTE_PTYPE_L2_VLAN because the - * vlan is stripped from the data. - */ - RTE_STD_C11 - union { - uint32_t packet_type; /**< L2/L3/L4 and tunnel information. */ - struct { - uint32_t l2_type:4; /**< (Outer) L2 type. */ - uint32_t l3_type:4; /**< (Outer) L3 type. */ - uint32_t l4_type:4; /**< (Outer) L4 type. */ - uint32_t tun_type:4; /**< Tunnel type. */ - uint32_t inner_l2_type:4; /**< Inner L2 type. */ - uint32_t inner_l3_type:4; /**< Inner L3 type. */ - uint32_t inner_l4_type:4; /**< Inner L4 type. */ - }; - }; - - uint32_t pkt_len; /**< Total pkt len: sum of all segments. */ - uint16_t data_len; /**< Amount of data in segment buffer. */ - /** VLAN TCI (CPU order), valid if PKT_RX_VLAN_STRIPPED is set. */ - uint16_t vlan_tci; - - union { - uint32_t rss; /**< RSS hash result if RSS enabled */ - struct { - RTE_STD_C11 - union { - struct { - uint16_t hash; - uint16_t id; - }; - uint32_t lo; - /**< Second 4 flexible bytes */ - }; - uint32_t hi; - /**< First 4 flexible bytes or FD ID, dependent on - PKT_RX_FDIR_* flag in ol_flags. */ - } fdir; /**< Filter identifier if FDIR enabled */ - struct { - uint32_t lo; - uint32_t hi; - } sched; /**< Hierarchical scheduler */ - uint32_t usr; /**< User defined tags. See rte_distributor_process() */ - } hash; /**< hash information */ - - uint32_t seqn; /**< Sequence number. See also rte_reorder_insert() */ - - /** Outer VLAN TCI (CPU order), valid if PKT_RX_QINQ_STRIPPED is set. */ - uint16_t vlan_tci_outer; - - /* second cache line - fields only used in slow path or on TX */ - MARKER cacheline1 __rte_cache_min_aligned; - - RTE_STD_C11 - union { - void *userdata; /**< Can be used for external metadata */ - uint64_t udata64; /**< Allow 8-byte userdata on 32-bit */ - }; - - struct rte_mempool *pool; /**< Pool from which mbuf was allocated. */ - struct rte_mbuf *next; /**< Next segment of scattered packet. */ - - /* fields to support TX offloads */ - RTE_STD_C11 - union { - uint64_t tx_offload; /**< combined for easy fetch */ - __extension__ - struct { - uint64_t l2_len:7; - /**< L2 (MAC) Header Length for non-tunneling pkt. - * Outer_L4_len + ... + Inner_L2_len for tunneling pkt. - */ - uint64_t l3_len:9; /**< L3 (IP) Header Length. */ - uint64_t l4_len:8; /**< L4 (TCP/UDP) Header Length. */ - uint64_t tso_segsz:16; /**< TCP TSO segment size */ - - /* fields for TX offloading of tunnels */ - uint64_t outer_l3_len:9; /**< Outer L3 (IP) Hdr Length. */ - uint64_t outer_l2_len:7; /**< Outer L2 (MAC) Hdr Length. */ - - /* uint64_t unused:8; */ - }; - }; - - /** Size of the application private data. In case of an indirect - * mbuf, it stores the direct mbuf private data size. */ - uint16_t priv_size; - - /** Timesync flags for use with IEEE1588. */ - uint16_t timesync; -} __rte_cache_aligned; diff --git a/bindgen-tests/tests/headers/long_double.h b/bindgen-tests/tests/headers/long_double.h index 91c4ed6ce9..c8872d6ebf 100644 --- a/bindgen-tests/tests/headers/long_double.h +++ b/bindgen-tests/tests/headers/long_double.h @@ -1,4 +1,4 @@ -// bindgen-flags: --rust-target 1.26 +// bindgen-flags: \-\-rust-target=1.33 struct foo { long double bar; diff --git a/bindgen-tests/tests/headers/macro_const_1_0.h b/bindgen-tests/tests/headers/macro_const_1_0.h deleted file mode 100644 index 3be86b4fd2..0000000000 --- a/bindgen-tests/tests/headers/macro_const_1_0.h +++ /dev/null @@ -1,10 +0,0 @@ -// bindgen-flags: --rust-target 1.0 - -#define foo "bar" -#define CHAR 'b' -#define CHARR '\0' -#define FLOAT 5.09f -#define FLOAT_EXPR (5 / 1000.0f) -#define LONG 3L - -#define INVALID_UTF8 "\xf0\x28\x8c\x28" diff --git a/bindgen-tests/tests/headers/newtype-enum.hpp b/bindgen-tests/tests/headers/newtype-enum.hpp index 890683ae85..45f3303c8c 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.28 -- -std=c++11 +// bindgen-flags: --newtype-enum "Foo" \-\-rust-target=1.33 -- -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 8021a3cc72..e52b19b84a 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.28 -- -std=c++11 +// bindgen-flags: --newtype-global-enum "Foo" \-\-rust-target=1.33 -- -std=c++11 enum Foo { Bar = 1 << 1, diff --git a/bindgen-tests/tests/headers/repr-align.hpp b/bindgen-tests/tests/headers/repr-align.hpp index 3347594b5c..b3231d39bc 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.25 -- -std=c++11 +// bindgen-flags: --raw-line '#![cfg(feature = "nightly")]' \-\-rust-target=1.33 -- -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 6a61d71049..212b0903a7 100644 --- a/bindgen-tests/tests/headers/strings_array.h +++ b/bindgen-tests/tests/headers/strings_array.h @@ -1,4 +1,4 @@ -// bindgen-flags: --rust-target=1.0 +// bindgen-flags: \-\-rust-target=1.33 const char* MY_STRING_UTF8 = "Hello, world!"; const char* MY_STRING_INTERIOR_NULL = "Hello,\0World!"; diff --git a/bindgen-tests/tests/headers/struct_with_anon_union_1_0.h b/bindgen-tests/tests/headers/struct_with_anon_union_1_0.h deleted file mode 100644 index 847c354b59..0000000000 --- a/bindgen-tests/tests/headers/struct_with_anon_union_1_0.h +++ /dev/null @@ -1,8 +0,0 @@ -// bindgen-flags: --rust-target 1.0 --with-derive-hash --with-derive-partialeq --with-derive-eq - -struct foo { - union { - unsigned int a; - unsigned short b; - } bar; -}; diff --git a/bindgen-tests/tests/headers/struct_with_anon_unnamed_union_1_0.h b/bindgen-tests/tests/headers/struct_with_anon_unnamed_union_1_0.h deleted file mode 100644 index 791a1593af..0000000000 --- a/bindgen-tests/tests/headers/struct_with_anon_unnamed_union_1_0.h +++ /dev/null @@ -1,8 +0,0 @@ -// bindgen-flags: --rust-target 1.0 --with-derive-hash --with-derive-partialeq --with-derive-eq - -struct foo { - union { - unsigned int a; - unsigned short b; - }; -}; diff --git a/bindgen-tests/tests/headers/struct_with_nesting_1_0.h b/bindgen-tests/tests/headers/struct_with_nesting_1_0.h deleted file mode 100644 index a24ae1db58..0000000000 --- a/bindgen-tests/tests/headers/struct_with_nesting_1_0.h +++ /dev/null @@ -1,19 +0,0 @@ -// bindgen-flags: --rust-target 1.0 --with-derive-hash --with-derive-partialeq --with-derive-eq - -struct foo { - unsigned int a; - union { - unsigned int b; - struct { - unsigned short c1; - unsigned short c2; - }; - - struct { - unsigned char d1; - unsigned char d2; - unsigned char d3; - unsigned char d4; - }; - }; -}; diff --git a/bindgen-tests/tests/headers/transform-op.hpp b/bindgen-tests/tests/headers/transform-op.hpp index aa6118eb67..907a5a4657 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.0 -- -std=c++11 +// bindgen-flags: \-\-rust-target=1.33 -- -std=c++11 typedef unsigned char uint8_t; typedef int int32_t; diff --git a/bindgen-tests/tests/headers/typeref_1_0.hpp b/bindgen-tests/tests/headers/typeref_1_0.hpp deleted file mode 100644 index 70dfc11fb1..0000000000 --- a/bindgen-tests/tests/headers/typeref_1_0.hpp +++ /dev/null @@ -1,30 +0,0 @@ -// bindgen-flags: --rust-target 1.0 --with-derive-hash --with-derive-partialeq --with-derive-eq - -struct nsFoo; - -namespace mozilla { - -struct FragmentOrURL { bool mIsLocalRef; }; -struct Position { }; - -} // namespace mozilla - -class Bar { - nsFoo* mFoo; -}; - -namespace mozilla { - -template -struct StyleShapeSource { - union { - Position* mPosition; - FragmentOrURL* mFragmentOrURL; - }; -}; - -} // namespace mozilla - -struct nsFoo { - mozilla::StyleShapeSource mBar; -}; diff --git a/bindgen-tests/tests/headers/union-align.h b/bindgen-tests/tests/headers/union-align.h index 9557b2798a..bfb5b5a199 100644 --- a/bindgen-tests/tests/headers/union-align.h +++ b/bindgen-tests/tests/headers/union-align.h @@ -1,4 +1,4 @@ -// bindgen-flags: --rust-target 1.26 +// bindgen-flags: \-\-rust-target=1.33 union Bar { unsigned char foo; diff --git a/bindgen-tests/tests/headers/union-in-ns_1_0.hpp b/bindgen-tests/tests/headers/union-in-ns_1_0.hpp deleted file mode 100644 index f3ae221057..0000000000 --- a/bindgen-tests/tests/headers/union-in-ns_1_0.hpp +++ /dev/null @@ -1,5 +0,0 @@ -// bindgen-flags: --rust-target 1.0 --enable-cxx-namespaces - -union bar { - int baz; -}; diff --git a/bindgen-tests/tests/headers/union_bitfield_1_0.h b/bindgen-tests/tests/headers/union_bitfield_1_0.h deleted file mode 100644 index 06b61ad771..0000000000 --- a/bindgen-tests/tests/headers/union_bitfield_1_0.h +++ /dev/null @@ -1,14 +0,0 @@ -// bindgen-flags: --rust-target 1.0 --with-derive-hash --with-derive-partialeq --with-derive-eq --impl-partialeq - -union U4 { - unsigned derp : 1; -}; - -union B { - unsigned foo : 31; - unsigned char bar : 1; -}; - -union HasBigBitfield { - __int128 x : 128; -}; diff --git a/bindgen-tests/tests/headers/union_dtor_1_0.hpp b/bindgen-tests/tests/headers/union_dtor_1_0.hpp deleted file mode 100644 index 01f7636671..0000000000 --- a/bindgen-tests/tests/headers/union_dtor_1_0.hpp +++ /dev/null @@ -1,7 +0,0 @@ -// bindgen-flags: --rust-target 1.0 - -union UnionWithDtor { - ~UnionWithDtor(); - int mFoo; - void* mBar; -}; diff --git a/bindgen-tests/tests/headers/union_fields_1_0.hpp b/bindgen-tests/tests/headers/union_fields_1_0.hpp deleted file mode 100644 index bbb67fbc6e..0000000000 --- a/bindgen-tests/tests/headers/union_fields_1_0.hpp +++ /dev/null @@ -1,7 +0,0 @@ -// bindgen-flags: --rust-target 1.0 --with-derive-hash --with-derive-partialeq --with-derive-eq - -typedef union { - int mInt; - float mFloat; - void* mPointer; -} nsStyleUnion; diff --git a/bindgen-tests/tests/headers/union_template_1_0.hpp b/bindgen-tests/tests/headers/union_template_1_0.hpp deleted file mode 100644 index 18e3d74a37..0000000000 --- a/bindgen-tests/tests/headers/union_template_1_0.hpp +++ /dev/null @@ -1,21 +0,0 @@ -// bindgen-flags: --rust-target 1.0 --with-derive-hash --with-derive-partialeq --with-derive-eq - -template -struct NastyStruct { - bool mIsSome; - union { - void* mFoo; - unsigned long mDummy; - } mStorage; - - union { - short wat; - int* wut; - }; -}; - -template -union Whatever { - void* mTPtr; - int mInt; -}; diff --git a/bindgen-tests/tests/headers/union_with_anon_struct_1_0.h b/bindgen-tests/tests/headers/union_with_anon_struct_1_0.h deleted file mode 100644 index 9313299eb0..0000000000 --- a/bindgen-tests/tests/headers/union_with_anon_struct_1_0.h +++ /dev/null @@ -1,8 +0,0 @@ -// bindgen-flags: --rust-target 1.0 --with-derive-hash --with-derive-partialeq --with-derive-eq - -union foo { - struct { - unsigned int a; - unsigned int b; - } bar; -}; diff --git a/bindgen-tests/tests/headers/union_with_anon_struct_bitfield_1_0.h b/bindgen-tests/tests/headers/union_with_anon_struct_bitfield_1_0.h deleted file mode 100644 index 0b0e3d7371..0000000000 --- a/bindgen-tests/tests/headers/union_with_anon_struct_bitfield_1_0.h +++ /dev/null @@ -1,9 +0,0 @@ -// bindgen-flags: --rust-target 1.0 --with-derive-hash --with-derive-partialeq --with-derive-eq - -union foo { - int a; - struct { - int b : 7; - int c : 25; - }; -}; diff --git a/bindgen-tests/tests/headers/union_with_anon_union_1_0.h b/bindgen-tests/tests/headers/union_with_anon_union_1_0.h deleted file mode 100644 index 28a7231dbf..0000000000 --- a/bindgen-tests/tests/headers/union_with_anon_union_1_0.h +++ /dev/null @@ -1,8 +0,0 @@ -// bindgen-flags: --rust-target 1.0 --with-derive-hash --with-derive-partialeq --with-derive-eq - -union foo { - union { - unsigned int a; - unsigned short b; - } bar; -}; diff --git a/bindgen-tests/tests/headers/union_with_anon_unnamed_struct_1_0.h b/bindgen-tests/tests/headers/union_with_anon_unnamed_struct_1_0.h deleted file mode 100644 index 506a41f661..0000000000 --- a/bindgen-tests/tests/headers/union_with_anon_unnamed_struct_1_0.h +++ /dev/null @@ -1,11 +0,0 @@ -// bindgen-flags: --rust-target 1.0 --with-derive-hash --with-derive-partialeq --with-derive-eq - -union pixel { - unsigned int rgba; - struct { - unsigned char r; - unsigned char g; - unsigned char b; - unsigned char a; - }; -}; diff --git a/bindgen-tests/tests/headers/union_with_anon_unnamed_union_1_0.h b/bindgen-tests/tests/headers/union_with_anon_unnamed_union_1_0.h deleted file mode 100644 index c556a61311..0000000000 --- a/bindgen-tests/tests/headers/union_with_anon_unnamed_union_1_0.h +++ /dev/null @@ -1,9 +0,0 @@ -// bindgen-flags: --rust-target 1.0 --with-derive-hash --with-derive-partialeq --with-derive-eq - -union foo { - unsigned int a; - union { - unsigned short b; - unsigned char c; - }; -}; diff --git a/bindgen-tests/tests/headers/union_with_big_member_1_0.h b/bindgen-tests/tests/headers/union_with_big_member_1_0.h deleted file mode 100644 index 0429435478..0000000000 --- a/bindgen-tests/tests/headers/union_with_big_member_1_0.h +++ /dev/null @@ -1,16 +0,0 @@ -// bindgen-flags: --rust-target 1.0 --with-derive-hash --with-derive-partialeq --with-derive-eq - -union WithBigArray { - int a; - int b[33]; -}; - -union WithBigArray2 { - int a; - char b[33]; -}; - -union WithBigMember { - int a; - union WithBigArray b; -}; diff --git a/bindgen-tests/tests/headers/union_with_nesting_1_0.h b/bindgen-tests/tests/headers/union_with_nesting_1_0.h deleted file mode 100644 index 3cdb7238bc..0000000000 --- a/bindgen-tests/tests/headers/union_with_nesting_1_0.h +++ /dev/null @@ -1,16 +0,0 @@ -// bindgen-flags: --rust-target 1.0 --with-derive-hash --with-derive-partialeq --with-derive-eq - -union foo { - unsigned int a; - struct { - union { - unsigned short b1; - unsigned short b2; - }; - - union { - unsigned short c1; - unsigned short c2; - }; - }; -}; diff --git a/bindgen-tests/tests/headers/use-core_1_0.h b/bindgen-tests/tests/headers/use-core_1_0.h deleted file mode 100644 index 40de9d158d..0000000000 --- a/bindgen-tests/tests/headers/use-core_1_0.h +++ /dev/null @@ -1,13 +0,0 @@ -// bindgen-flags: --rust-target 1.0 --use-core --raw-line "extern crate core;" --with-derive-hash --with-derive-partialeq --with-derive-eq - -struct foo { - int a, b; - void* bar; -}; - -union { - int bar; - long baz; -} bazz; - -typedef void (*fooFunction)(int bar); diff --git a/bindgen-tests/tests/headers/win32-dtors.hpp b/bindgen-tests/tests/headers/win32-dtors.hpp index dc9b0fdc6e..7faa5e9562 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.0 -- --target=x86_64-pc-windows-msvc +// bindgen-flags: \-\-rust-target=1.33 -- --target=x86_64-pc-windows-msvc struct CppObj { int x; diff --git a/bindgen-tests/tests/headers/win32-thiscall.hpp b/bindgen-tests/tests/headers/win32-thiscall.hpp new file mode 100644 index 0000000000..d4e3976303 --- /dev/null +++ b/bindgen-tests/tests/headers/win32-thiscall.hpp @@ -0,0 +1,7 @@ +// bindgen-flags: \-\-rust-target=1.33 -- --target=i686-pc-windows-msvc + +class Foo { + public: + void test(); + int test2(int var); +}; diff --git a/bindgen-tests/tests/headers/win32-thiscall_1_0.hpp b/bindgen-tests/tests/headers/win32-thiscall_1_0.hpp deleted file mode 100644 index 5907c76eaf..0000000000 --- a/bindgen-tests/tests/headers/win32-thiscall_1_0.hpp +++ /dev/null @@ -1,7 +0,0 @@ -// bindgen-flags: --rust-target 1.0 -- --target=i686-pc-windows-msvc - -class Foo { - public: - void test(); - int test2(int var); -}; diff --git a/bindgen-tests/tests/headers/win32-vectorcall-1_0.h b/bindgen-tests/tests/headers/win32-vectorcall-1_0.h deleted file mode 100644 index a1f852b52f..0000000000 --- a/bindgen-tests/tests/headers/win32-vectorcall-1_0.h +++ /dev/null @@ -1,3 +0,0 @@ -// bindgen-flags: --rust-target 1.0 -- --target=x86_64-pc-windows-msvc - -int __vectorcall test_vectorcall(int a, int b); diff --git a/bindgen-tests/tests/headers/win32-vectorcall.h b/bindgen-tests/tests/headers/win32-vectorcall.h new file mode 100644 index 0000000000..245d97b340 --- /dev/null +++ b/bindgen-tests/tests/headers/win32-vectorcall.h @@ -0,0 +1,3 @@ +// bindgen-flags: \-\-rust-target=1.33 -- --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_1_0.hpp b/bindgen-tests/tests/headers/wrap_unsafe_ops_anon_union.hpp similarity index 82% rename from bindgen-tests/tests/headers/wrap_unsafe_ops_anon_union_1_0.hpp rename to bindgen-tests/tests/headers/wrap_unsafe_ops_anon_union.hpp index 3b595f2ea7..e44b43285a 100644 --- a/bindgen-tests/tests/headers/wrap_unsafe_ops_anon_union_1_0.hpp +++ b/bindgen-tests/tests/headers/wrap_unsafe_ops_anon_union.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --rust-target 1.0 --wrap-unsafe-ops --no-layout-tests +// bindgen-flags: \-\-rust-target=1.33 --wrap-unsafe-ops --no-layout-tests template struct TErrorResult { diff --git a/bindgen/codegen/helpers.rs b/bindgen/codegen/helpers.rs index 4038340100..4bd08011f9 100644 --- a/bindgen/codegen/helpers.rs +++ b/bindgen/codegen/helpers.rs @@ -79,14 +79,14 @@ pub(crate) mod attributes { /// Generates a proper type for a field or type with a given `Layout`, that is, /// a type with the correct size and alignment restrictions. -pub(crate) fn blob(ctx: &BindgenContext, layout: Layout) -> syn::Type { +pub(crate) fn blob(layout: Layout) -> syn::Type { let opaque = layout.opaque(); // FIXME(emilio, #412): We fall back to byte alignment, but there are // some things that legitimately are more than 8-byte aligned. // // Eventually we should be able to `unwrap` here, but... - let ty = match opaque.known_rust_type_for_array(ctx) { + let ty = match opaque.known_rust_type_for_array() { Some(ty) => ty, None => { warn!("Found unknown alignment on code generation!"); @@ -94,7 +94,7 @@ pub(crate) fn blob(ctx: &BindgenContext, layout: Layout) -> syn::Type { } }; - let data_len = opaque.array_size(ctx).unwrap_or(layout.size); + let data_len = opaque.array_size().unwrap_or(layout.size); if data_len == 1 { ty @@ -104,11 +104,8 @@ pub(crate) fn blob(ctx: &BindgenContext, layout: Layout) -> syn::Type { } /// Integer type of the same size as the given `Layout`. -pub(crate) fn integer_type( - ctx: &BindgenContext, - layout: Layout, -) -> Option { - Layout::known_type_for_size(ctx, layout.size) +pub(crate) fn integer_type(layout: Layout) -> Option { + Layout::known_type_for_size(layout.size) } pub(crate) const BITFIELD_UNIT: &str = "__BindgenBitfieldUnit"; @@ -143,9 +140,7 @@ pub(crate) mod ast_ty { syn::parse_quote! { #prefix::c_void } } None => { - if ctx.options().use_core && - ctx.options().rust_features.core_ffi_c_void - { + if ctx.options().use_core { syn::parse_quote! { ::core::ffi::c_void } } else { syn::parse_quote! { ::std::os::raw::c_void } @@ -194,7 +189,7 @@ pub(crate) mod ast_ty { IntKind::WChar => { let layout = layout.expect("Couldn't compute wchar_t's layout?"); - Layout::known_type_for_size(ctx, layout.size) + Layout::known_type_for_size(layout.size) .expect("Non-representable wchar_t?") } @@ -210,7 +205,7 @@ pub(crate) mod ast_ty { syn::parse_str(name).expect("Invalid integer type.") } IntKind::U128 => { - if ctx.options().rust_features.i128_and_u128 { + if true { syn::parse_quote! { u128 } } else { // Best effort thing, but wrong alignment @@ -219,7 +214,7 @@ pub(crate) mod ast_ty { } } IntKind::I128 => { - if ctx.options().rust_features.i128_and_u128 { + if true { syn::parse_quote! { i128 } } else { syn::parse_quote! { [u64; 2] } @@ -259,7 +254,7 @@ pub(crate) mod ast_ty { 8 => syn::parse_quote! { f64 }, // TODO(emilio): If rust ever gains f128 we should // use it here and below. - _ => super::integer_type(ctx, layout) + _ => super::integer_type(layout) .unwrap_or(syn::parse_quote! { f64 }), } } @@ -273,7 +268,7 @@ pub(crate) mod ast_ty { } } (FloatKind::Float128, _) => { - if ctx.options().rust_features.i128_and_u128 { + if true { syn::parse_quote! { u128 } } else { syn::parse_quote! { [u64; 2] } @@ -316,6 +311,8 @@ pub(crate) mod ast_ty { 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 @@ -330,6 +327,8 @@ pub(crate) mod ast_ty { 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 @@ -340,6 +339,8 @@ pub(crate) mod ast_ty { } } } else { + // FIXME: This should be done behind a `RustFeature` instead + #[allow(deprecated)] // Negative infinity if rust_target >= RustTarget::Stable_1_43 { quote! { diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index ccc5758a14..943d8c7513 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -151,22 +151,16 @@ fn derives_of_item( ) -> DerivableTraits { let mut derivable_traits = DerivableTraits::empty(); - let all_template_params = item.all_template_params(ctx); - if item.can_derive_copy(ctx) && !item.annotations().disallow_copy() { derivable_traits |= DerivableTraits::COPY; - if ctx.options().rust_features().builtin_clone_impls || - !all_template_params.is_empty() - { - // FIXME: This requires extra logic if you have a big array in a - // templated struct. The reason for this is that the magic: - // fn clone(&self) -> Self { *self } - // doesn't work for templates. - // - // It's not hard to fix though. - derivable_traits |= DerivableTraits::CLONE; - } + // FIXME: This requires extra logic if you have a big array in a + // templated struct. The reason for this is that the magic: + // fn clone(&self) -> Self { *self } + // doesn't work for templates. + // + // It's not hard to fix though. + derivable_traits |= DerivableTraits::CLONE; } else if packed { // If the struct or union is packed, deriving from Copy is required for // deriving from any other trait. @@ -743,13 +737,9 @@ impl CodeGenerator for Var { }; }); } else { - let lifetime = if rust_features.static_lifetime_elision - { - None - } else { - Some(quote! { 'static }) - } - .into_iter(); + let lifetime = + if true { None } else { Some(quote! { 'static }) } + .into_iter(); result.push(quote! { #(#attrs)* @@ -1024,12 +1014,6 @@ impl CodeGenerator for Type { pub type #rust_name }, AliasVariation::NewType | AliasVariation::NewTypeDeref => { - assert!( - ctx.options().rust_features().repr_transparent, - "repr_transparent feature is required to use {:?}", - alias_style - ); - let mut attributes = vec![attributes::repr("transparent")]; let packed = false; // Types can't be packed in Rust. @@ -1644,11 +1628,10 @@ impl Bitfield { let bitfield_ty_layout = bitfield_ty .layout(ctx) .expect("Bitfield without layout? Gah!"); - let bitfield_int_ty = helpers::integer_type(ctx, bitfield_ty_layout) - .expect( - "Should already have verified that the bitfield is \ + let bitfield_int_ty = helpers::integer_type(bitfield_ty_layout).expect( + "Should already have verified that the bitfield is \ representable as an int", - ); + ); let offset = self.offset_into_unit(); let width = self.width() as u8; @@ -1950,17 +1933,16 @@ impl<'a> FieldCodegen<'a> for Bitfield { let bitfield_ty_layout = bitfield_ty .layout(ctx) .expect("Bitfield without layout? Gah!"); - let bitfield_int_ty = - match helpers::integer_type(ctx, bitfield_ty_layout) { - Some(int_ty) => { - *bitfield_representable_as_int = true; - int_ty - } - None => { - *bitfield_representable_as_int = false; - return; - } - }; + let bitfield_int_ty = match helpers::integer_type(bitfield_ty_layout) { + Some(int_ty) => { + *bitfield_representable_as_int = true; + int_ty + } + None => { + *bitfield_representable_as_int = false; + return; + } + }; let bitfield_ty = bitfield_ty.to_rust_ty_or_opaque(ctx, bitfield_ty_item); @@ -2275,7 +2257,7 @@ impl CodeGenerator for CompInfo { if has_address { let layout = Layout::new(1, 1); - let ty = helpers::blob(ctx, Layout::new(1, 1)); + let ty = helpers::blob(Layout::new(1, 1)); struct_layout.saw_field_with_layout( "_address", layout, @@ -2292,7 +2274,7 @@ impl CodeGenerator for CompInfo { Some(l) => { explicit_align = Some(l.align); - let ty = helpers::blob(ctx, l); + let ty = helpers::blob(l); fields.push(quote! { pub _bindgen_opaque_blob: #ty , }); @@ -2314,15 +2296,6 @@ impl CodeGenerator for CompInfo { packed = true; } else { explicit_align = Some(layout.align); - if !ctx.options().rust_features.repr_align { - let ty = helpers::blob( - ctx, - Layout::new(0, layout.align), - ); - fields.push(quote! { - pub __bindgen_align: #ty , - }); - } } } } @@ -2335,7 +2308,7 @@ impl CodeGenerator for CompInfo { } if !struct_layout.is_rust_union() { - let ty = helpers::blob(ctx, layout); + let ty = helpers::blob(layout); fields.push(quote! { pub bindgen_union_field: #ty , }) @@ -2425,7 +2398,7 @@ impl CodeGenerator for CompInfo { attributes.push(attributes::repr("C")); } - if ctx.options().rust_features().repr_align { + if true { if let Some(explicit) = explicit_align { // Ensure that the struct has the correct alignment even in // presence of alignas. @@ -2582,19 +2555,14 @@ impl CodeGenerator for CompInfo { let align_of_err = format!("Alignment of {canonical_ident}"); - let check_struct_align = if align > - ctx.target_pointer_size() && - !ctx.options().rust_features().repr_align - { - None - } else if compile_time { - Some(quote! { + let check_struct_align = if compile_time { + quote! { [#align_of_err][#align_of_expr - #align]; - }) + } } else { - Some(quote! { + quote! { assert_eq!(#align_of_expr, #align, #align_of_err); - }) + } }; let should_skip_field_offset_checks = is_opaque; @@ -3126,9 +3094,7 @@ impl Method { let mut attrs = vec![attributes::inline()]; - if signature.must_use() && - ctx.options().rust_features().must_use_function - { + if signature.must_use() { attrs.push(attributes::must_use()); } @@ -3396,10 +3362,7 @@ impl<'a> EnumBuilder<'a> { is_global, .. } => { - if ctx.options().rust_features().associated_const && - is_ty_named && - !is_global - { + if is_ty_named && !is_global { let enum_ident = ctx.rust_ident(canonical_name); let variant_ident = ctx.rust_ident(variant_name); @@ -3654,7 +3617,7 @@ impl CodeGenerator for Enum { } } EnumVariation::NewType { .. } => { - if ctx.options().rust_features.repr_transparent { + if true { attrs.push(attributes::repr("transparent")); } else { attrs.push(attributes::repr("C")); @@ -3816,9 +3779,7 @@ impl CodeGenerator for Enum { let existing_variant_name = entry.get(); // Use associated constants for named enums. - if enum_ty.name().is_some() && - ctx.options().rust_features().associated_const - { + if enum_ty.name().is_some() { let enum_canonical_name = &ident; let variant_name = ctx.rust_ident_raw(&*mangled_name); @@ -4052,8 +4013,7 @@ pub(crate) trait TryToOpaque { ctx: &BindgenContext, extra: &Self::Extra, ) -> error::Result { - self.try_get_layout(ctx, extra) - .map(|layout| helpers::blob(ctx, layout)) + self.try_get_layout(ctx, extra).map(helpers::blob) } } @@ -4079,7 +4039,7 @@ pub(crate) trait ToOpaque: TryToOpaque { extra: &Self::Extra, ) -> syn::Type { let layout = self.get_layout(ctx, extra); - helpers::blob(ctx, layout) + helpers::blob(layout) } } @@ -4130,7 +4090,7 @@ where ) -> error::Result { self.try_to_rust_ty(ctx, extra).or_else(|_| { if let Ok(layout) = self.try_get_layout(ctx, extra) { - Ok(helpers::blob(ctx, layout)) + Ok(helpers::blob(layout)) } else { Err(error::Error::NoLayoutForOpaqueBlob) } @@ -4583,7 +4543,7 @@ impl CodeGenerator for Function { let mut attributes = vec![]; - if ctx.options().rust_features().must_use_function { + if true { let must_use = signature.must_use() || { let ret_ty = signature .return_type() @@ -5316,7 +5276,7 @@ pub(crate) mod utils { } else { include_str!("./bitfield_unit.rs") }; - let bitfield_unit_src = if ctx.options().rust_features().min_const_fn { + let bitfield_unit_src = if true { Cow::Borrowed(bitfield_unit_src) } else { Cow::Owned(bitfield_unit_src.replace("const fn ", "fn ")) @@ -5382,7 +5342,7 @@ pub(crate) mod utils { // If the target supports `const fn`, declare eligible functions // as `const fn` else just `fn`. - let const_fn = if ctx.options().rust_features().min_const_fn { + let const_fn = if true { quote! { const fn } } else { quote! { fn } @@ -5494,7 +5454,7 @@ pub(crate) mod utils { // If the target supports `const fn`, declare eligible functions // as `const fn` else just `fn`. - let const_fn = if ctx.options().rust_features().min_const_fn { + let const_fn = if true { quote! { const fn } } else { quote! { fn } diff --git a/bindgen/codegen/struct_layout.rs b/bindgen/codegen/struct_layout.rs index 507c8d40e2..b78c65e55b 100644 --- a/bindgen/codegen/struct_layout.rs +++ b/bindgen/codegen/struct_layout.rs @@ -344,7 +344,7 @@ impl<'a> StructLayoutTracker<'a> { return None; } - let repr_align = self.ctx.options().rust_features().repr_align; + let repr_align = true; // We always pad to get to the correct size if the struct is one of // those we can't align properly. @@ -377,7 +377,7 @@ impl<'a> StructLayoutTracker<'a> { } pub(crate) fn requires_explicit_align(&self, layout: Layout) -> bool { - let repr_align = self.ctx.options().rust_features().repr_align; + let repr_align = true; // Always force explicit repr(align) for stuff more than 16-byte aligned // to work-around https://github.com/rust-lang/rust/issues/54341. @@ -401,7 +401,7 @@ impl<'a> StructLayoutTracker<'a> { } fn padding_field(&mut self, layout: Layout) -> proc_macro2::TokenStream { - let ty = helpers::blob(self.ctx, layout); + let ty = helpers::blob(layout); let padding_count = self.padding_count; self.padding_count += 1; diff --git a/bindgen/features.rs b/bindgen/features.rs index 799b15a55f..915e8ebef0 100644 --- a/bindgen/features.rs +++ b/bindgen/features.rs @@ -82,7 +82,6 @@ macro_rules! define_rust_targets { ( Nightly => {$($nightly_feature:ident $(: #$issue:literal)?),* $(,)?} $(,)? $( - $(#[$attrs:meta])* $variant:ident($minor:literal) => {$($feature:ident $(: #$pull:literal)?),* $(,)?}, )* $(,)? @@ -94,6 +93,7 @@ macro_rules! define_rust_targets { "- [`", stringify!($nightly_feature), "`]", "(", $("https://github.com/rust-lang/rust/pull/", stringify!($issue),)* ")", )])* + #[deprecated = "The use of this constant is deprecated, please use `RustTarget::nightly` instead."] pub const Nightly: Self = Self::nightly(); /// The nightly version of Rust, which introduces the following features:" @@ -111,7 +111,7 @@ macro_rules! define_rust_targets { "- [`", stringify!($feature), "`]", "(", $("https://github.com/rust-lang/rust/pull/", stringify!($pull),)* ")", )])* - $(#[$attrs])* + #[deprecated = "The use of this constant is deprecated, please use `RustTarget::stable` instead."] pub const $variant: Self = Self(Version::Stable($minor, 0)); )* @@ -175,29 +175,6 @@ define_rust_targets! { Stable_1_40(40) => { non_exhaustive: #44109 }, Stable_1_36(36) => { maybe_uninit: #60445 }, Stable_1_33(33) => { repr_packed_n: #57049 }, - #[deprecated] - Stable_1_30(30) => { - core_ffi_c_void: #53910, - min_const_fn: #54835, - }, - #[deprecated] - Stable_1_28(28) => { repr_transparent: #51562 }, - #[deprecated] - Stable_1_27(27) => { must_use_function: #48925 }, - #[deprecated] - Stable_1_26(26) => { i128_and_u128: #49101 }, - #[deprecated] - Stable_1_25(25) => { repr_align: #47006 }, - #[deprecated] - Stable_1_21(21) => { builtin_clone_impls: #43690 }, - #[deprecated] - Stable_1_20(20) => { associated_const: #42809 }, - #[deprecated] - Stable_1_19(19) => { untagged_union: #42068 }, - #[deprecated] - Stable_1_17(17) => { static_lifetime_elision: #39265 }, - #[deprecated] - Stable_1_0(0) => {}, } /// Latest stable release of Rust that is supported by bindgen @@ -330,28 +307,6 @@ mod test { #[test] fn target_features() { - let f_1_0 = RustFeatures::from(RustTarget::Stable_1_0); - assert!( - !f_1_0.static_lifetime_elision && - !f_1_0.core_ffi_c_void && - !f_1_0.untagged_union && - !f_1_0.associated_const && - !f_1_0.builtin_clone_impls && - !f_1_0.repr_align && - !f_1_0.thiscall_abi && - !f_1_0.vectorcall_abi - ); - let f_1_21 = RustFeatures::from(RustTarget::Stable_1_21); - assert!( - f_1_21.static_lifetime_elision && - !f_1_21.core_ffi_c_void && - f_1_21.untagged_union && - f_1_21.associated_const && - f_1_21.builtin_clone_impls && - !f_1_21.repr_align && - !f_1_21.thiscall_abi && - !f_1_21.vectorcall_abi - ); let features = RustFeatures::from(RustTarget::Stable_1_71); assert!( features.c_unwind_abi && @@ -360,13 +315,7 @@ mod test { ); let f_nightly = RustFeatures::from(RustTarget::Nightly); assert!( - f_nightly.static_lifetime_elision && - f_nightly.core_ffi_c_void && - f_nightly.untagged_union && - f_nightly.associated_const && - f_nightly.builtin_clone_impls && - f_nightly.maybe_uninit && - f_nightly.repr_align && + f_nightly.maybe_uninit && f_nightly.thiscall_abi && f_nightly.vectorcall_abi ); @@ -412,5 +361,7 @@ mod test { test_invalid_target("1.-1.0"); test_invalid_target("1.0.-1"); test_invalid_target("beta"); + test_invalid_target("1.0.0"); + test_invalid_target("1.32.0"); } } diff --git a/bindgen/ir/analysis/derive.rs b/bindgen/ir/analysis/derive.rs index d8d29ed9a8..f3c64307c4 100644 --- a/bindgen/ir/analysis/derive.rs +++ b/bindgen/ir/analysis/derive.rs @@ -183,7 +183,7 @@ impl<'ctx> CannotDerive<'ctx> { let layout_can_derive = ty.layout(self.ctx).map_or(CanDerive::Yes, |l| { - l.opaque().array_size_within_derive_limit(self.ctx) + l.opaque().array_size_within_derive_limit() }); match layout_can_derive { @@ -344,8 +344,7 @@ impl<'ctx> CannotDerive<'ctx> { let layout_can_derive = ty.layout(self.ctx).map_or(CanDerive::Yes, |l| { - l.opaque() - .array_size_within_derive_limit(self.ctx) + l.opaque().array_size_within_derive_limit() }); match layout_can_derive { CanDerive::Yes => { diff --git a/bindgen/ir/layout.rs b/bindgen/ir/layout.rs index 85a553da31..9aee857948 100644 --- a/bindgen/ir/layout.rs +++ b/bindgen/ir/layout.rs @@ -34,14 +34,9 @@ fn test_layout_for_size() { impl Layout { /// Gets the integer type name for a given known size. - pub(crate) fn known_type_for_size( - ctx: &BindgenContext, - size: usize, - ) -> Option { + pub(crate) fn known_type_for_size(size: usize) -> Option { Some(match size { - 16 if ctx.options().rust_features.i128_and_u128 => { - syn::parse_quote! { u128 } - } + 16 => syn::parse_quote! { u128 }, 8 => syn::parse_quote! { u64 }, 4 => syn::parse_quote! { u32 }, 2 => syn::parse_quote! { u16 }, @@ -102,17 +97,14 @@ impl Opaque { /// Return the known rust type we should use to create a correctly-aligned /// field with this layout. - pub(crate) fn known_rust_type_for_array( - &self, - ctx: &BindgenContext, - ) -> Option { - Layout::known_type_for_size(ctx, self.0.align) + pub(crate) fn known_rust_type_for_array(&self) -> Option { + Layout::known_type_for_size(self.0.align) } /// Return the array size that an opaque type for this layout should have if /// we know the correct type for it, or `None` otherwise. - pub(crate) fn array_size(&self, ctx: &BindgenContext) -> Option { - if self.known_rust_type_for_array(ctx).is_some() { + pub(crate) fn array_size(&self) -> Option { + if self.known_rust_type_for_array().is_some() { Some(self.0.size / cmp::max(self.0.align, 1)) } else { None @@ -122,12 +114,9 @@ impl Opaque { /// Return `true` if this opaque layout's array size will fit within the /// maximum number of array elements that Rust allows deriving traits /// with. Return `false` otherwise. - pub(crate) fn array_size_within_derive_limit( - &self, - ctx: &BindgenContext, - ) -> CanDerive { + pub(crate) fn array_size_within_derive_limit(&self) -> CanDerive { if self - .array_size(ctx) + .array_size() .map_or(false, |size| size <= RUST_DERIVE_IN_ARRAY_LIMIT) { CanDerive::Yes diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 134e3d6d91..b9b4888aa8 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -526,17 +526,6 @@ impl BindgenOptions { for regex_set in self.abi_overrides.values_mut().chain(regex_sets) { regex_set.build(record_matches); } - - let rust_target = self.rust_target; - #[allow(deprecated)] - if rust_target <= RustTarget::Stable_1_30 { - deprecated_target_diagnostic(rust_target, self); - } - - // Disable `untagged_union` if the target does not support it. - if !self.rust_features.untagged_union { - self.untagged_union = false; - } } /// Update rust target version @@ -585,27 +574,6 @@ impl BindgenOptions { } } -fn deprecated_target_diagnostic(target: RustTarget, _options: &BindgenOptions) { - warn!("The {} Rust target is deprecated. If you have a need to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues", target); - - #[cfg(feature = "experimental")] - if _options.emit_diagnostics { - use crate::diagnostics::{Diagnostic, Level}; - - let mut diagnostic = Diagnostic::default(); - diagnostic.with_title( - format!("The {} Rust target is deprecated.", target), - Level::Warning, - ); - diagnostic.add_annotation( - "This Rust target was passed to `--rust-target`", - Level::Info, - ); - diagnostic.add_annotation("If you have a good reason to use this target please report it at https://github.com/rust-lang/rust-bindgen/issues", Level::Help); - diagnostic.display(); - } -} - #[cfg(feature = "runtime")] fn ensure_libclang_is_loaded() { if clang_sys::is_loaded() { From 887196838a06044e6673d140d8a84e17054b24f9 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Wed, 27 Nov 2024 14:17:23 -0500 Subject: [PATCH 766/942] Make clippy happy :) --- bindgen/ir/ty.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindgen/ir/ty.rs b/bindgen/ir/ty.rs index 6d4c5666dc..d527b1c778 100644 --- a/bindgen/ir/ty.rs +++ b/bindgen/ir/ty.rs @@ -248,7 +248,7 @@ impl Type { return Cow::Borrowed(name); } - let name = name.replace(|c| c == ' ' || c == ':' || c == '.', "_"); + let name = name.replace([' ', ':', '.'], "_"); Cow::Owned(name) } From a8a60572d4775c4a1f2643752a86a534c8855cd8 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Wed, 27 Nov 2024 14:17:23 -0500 Subject: [PATCH 767/942] Ignore the `layout.h` test This is done because bindgen is producing bogus code where a single struct has both `packed` and `align` attributes. --- Cargo.toml | 1 + .../tests/expectations/tests/layout.rs | 70 +------------------ bindgen-tests/tests/headers/layout.h | 3 + 3 files changed, 5 insertions(+), 69 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e0535a1c66..bd87aacf0b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -54,3 +54,4 @@ release = false [profile.dist] inherits = "release" lto = "thin" + diff --git a/bindgen-tests/tests/expectations/tests/layout.rs b/bindgen-tests/tests/expectations/tests/layout.rs index 073f184f11..fe64295a68 100644 --- a/bindgen-tests/tests/expectations/tests/layout.rs +++ b/bindgen-tests/tests/expectations/tests/layout.rs @@ -1,69 +1 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -#[derive(Default)] -pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); -impl __IncompleteArrayField { - #[inline] - pub const fn new() -> Self { - __IncompleteArrayField(::std::marker::PhantomData, []) - } - #[inline] - pub fn as_ptr(&self) -> *const T { - self as *const _ as *const T - } - #[inline] - pub fn as_mut_ptr(&mut self) -> *mut T { - self as *mut _ as *mut T - } - #[inline] - pub unsafe fn as_slice(&self, len: usize) -> &[T] { - ::std::slice::from_raw_parts(self.as_ptr(), len) - } - #[inline] - pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) - } -} -impl ::std::fmt::Debug for __IncompleteArrayField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__IncompleteArrayField") - } -} -#[repr(C, packed(16))] -#[repr(align(16))] -pub struct header { - pub proto: ::std::os::raw::c_char, - pub size: ::std::os::raw::c_uint, - pub data: __IncompleteArrayField<::std::os::raw::c_uchar>, -} -#[test] -fn bindgen_test_layout_header() { - const UNINIT: ::std::mem::MaybeUninit
= ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::
(), 16usize, "Size of header"); - assert_eq!(::std::mem::align_of::
(), 16usize, "Alignment of header"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).proto) as usize - ptr as usize }, - 0usize, - "Offset of field: header::proto", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).size) as usize - ptr as usize }, - 1usize, - "Offset of field: header::size", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize }, - 8usize, - "Offset of field: header::data", - ); -} -impl Default for header { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] \ No newline at end of file diff --git a/bindgen-tests/tests/headers/layout.h b/bindgen-tests/tests/headers/layout.h index 6a3df9b3f5..0b3df26347 100644 --- a/bindgen-tests/tests/headers/layout.h +++ b/bindgen-tests/tests/headers/layout.h @@ -2,9 +2,12 @@ // // FIXME: https://github.com/rust-lang/rust-bindgen/issues/1498 + +#if 0 struct header { char proto; unsigned int size __attribute__ ((packed)); unsigned char data[] __attribute__ ((aligned(8))); } __attribute__ ((aligned, packed)); +#endif From 887dc7378461c3a5f05fed823671c049106afd81 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Wed, 27 Nov 2024 23:20:07 -0500 Subject: [PATCH 768/942] Update the help message for `--rust-target` --- bindgen/features.rs | 4 ---- bindgen/options/cli.rs | 5 ++--- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/bindgen/features.rs b/bindgen/features.rs index 915e8ebef0..9991522497 100644 --- a/bindgen/features.rs +++ b/bindgen/features.rs @@ -120,10 +120,6 @@ macro_rules! define_rust_targets { } } - #[cfg(feature = "__cli")] - /// Strings of allowed `RustTarget` values - pub(crate) const RUST_TARGET_STRINGS: &[&str] = &[$(concat!("1.", stringify!($minor)),)*]; - #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] pub(crate) struct RustFeatures { $($(pub(crate) $feature: bool,)*)* diff --git a/bindgen/options/cli.rs b/bindgen/options/cli.rs index 747ff2d5e0..a20ebb1020 100644 --- a/bindgen/options/cli.rs +++ b/bindgen/options/cli.rs @@ -3,7 +3,7 @@ use crate::{ callbacks::{ AttributeInfo, DeriveInfo, ItemInfo, ParseCallbacks, TypeKind, }, - features::RUST_TARGET_STRINGS, + features::EARLIEST_STABLE_RUST, regex_set::RegexSet, Abi, AliasVariation, Builder, CodegenConfig, EnumVariation, FieldVisibilityKind, Formatter, MacroTypeVariation, NonCopyUnionStyle, @@ -21,8 +21,7 @@ use std::{fs::File, process::exit}; fn rust_target_help() -> String { format!( - "Version of the Rust compiler to target. Valid options are: {:?}. Defaults to {}.", - RUST_TARGET_STRINGS, + "Version of the Rust compiler to target. Any Rust version after {EARLIEST_STABLE_RUST} is supported. Defaults to {}.", RustTarget::default() ) } From d2e30fb2ef77e6eadc50c85e162b89a1cd6aaa38 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Fri, 29 Nov 2024 05:01:55 -0500 Subject: [PATCH 769/942] Bump to 2021 edition This will make it possible to introduce C-string literals and possibly other language features in separate PRs --- bindgen-cli/Cargo.toml | 2 +- bindgen-integration/Cargo.toml | 2 +- bindgen-integration/src/lib.rs | 2 +- bindgen-tests/Cargo.toml | 2 +- bindgen-tests/tests/expectations/Cargo.toml | 2 +- bindgen-tests/tests/quickchecking/Cargo.toml | 2 +- bindgen/Cargo.toml | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index 2e5bf1b47f..d6ab1b06e2 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -12,7 +12,7 @@ repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" version = "0.70.1" -edition = "2018" +edition = "2021" rust-version = "1.70.0" [[bin]] diff --git a/bindgen-integration/Cargo.toml b/bindgen-integration/Cargo.toml index cf89e2d9b9..38b52322cc 100644 --- a/bindgen-integration/Cargo.toml +++ b/bindgen-integration/Cargo.toml @@ -4,7 +4,7 @@ description = "A package to test various bindgen features" version = "0.1.0" authors = ["Emilio Cobos Álvarez "] publish = false -edition = "2018" +edition = "2021" build = "build.rs" [build-dependencies] diff --git a/bindgen-integration/src/lib.rs b/bindgen-integration/src/lib.rs index 48cfe092d2..b939d25b25 100755 --- a/bindgen-integration/src/lib.rs +++ b/bindgen-integration/src/lib.rs @@ -259,7 +259,7 @@ fn test_matching_with_rename() { #[test] fn test_macro_customintkind_path() { - let v: &std::any::Any = &bindings::TESTMACRO_CUSTOMINTKIND_PATH; + let v: &dyn std::any::Any = &bindings::TESTMACRO_CUSTOMINTKIND_PATH; assert!(v.is::()) } diff --git a/bindgen-tests/Cargo.toml b/bindgen-tests/Cargo.toml index 4a92f81f55..b9547bb1ad 100644 --- a/bindgen-tests/Cargo.toml +++ b/bindgen-tests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bindgen-tests" -edition = "2018" +edition = "2021" version = "0.1.0" publish = false diff --git a/bindgen-tests/tests/expectations/Cargo.toml b/bindgen-tests/tests/expectations/Cargo.toml index adb95d56d2..e95e9dcb1c 100644 --- a/bindgen-tests/tests/expectations/Cargo.toml +++ b/bindgen-tests/tests/expectations/Cargo.toml @@ -7,7 +7,7 @@ authors = [ "Emilio Cobos Álvarez ", "The Servo project developers", ] -edition = "2018" +edition = "2021" publish = false [dependencies] diff --git a/bindgen-tests/tests/quickchecking/Cargo.toml b/bindgen-tests/tests/quickchecking/Cargo.toml index 0fafac97f3..998643bbf4 100644 --- a/bindgen-tests/tests/quickchecking/Cargo.toml +++ b/bindgen-tests/tests/quickchecking/Cargo.toml @@ -4,7 +4,7 @@ description = "Bindgen property tests with quickcheck. Generate random valid C c version = "0.0.0" publish = false rust-version = "1.70" -edition = "2018" +edition = "2021" [lib] name = "quickchecking" diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index d8b872b77c..47462e1788 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -15,7 +15,7 @@ repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" version = "0.70.1" -edition = "2018" +edition = "2021" build = "build.rs" # If you change this, also update README.md and msrv in .github/workflows/bindgen.yml rust-version = "1.70.0" From ee3efc8b89e0628bb726a78b312be876782c4329 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Thu, 28 Nov 2024 14:18:55 -0500 Subject: [PATCH 770/942] Automatic support for C-String literals When `generate_cstr` is enabled, and the target rust version is >= 1.77, generate `c"..."` literals instead of the unsafe `from_bytes_with_nul_unchecked` calls. --- Cargo.lock | 4 +- .../tests/expectations/tests/strings_cstr2.rs | 4 ++ bindgen-tests/tests/headers/strings_cstr2.h | 5 ++ bindgen/codegen/mod.rs | 48 ++++++++++++------- bindgen/features.rs | 5 +- 5 files changed, 45 insertions(+), 21 deletions(-) create mode 100644 bindgen-tests/tests/expectations/tests/strings_cstr2.rs create mode 100644 bindgen-tests/tests/headers/strings_cstr2.h diff --git a/Cargo.lock b/Cargo.lock index 251244184c..e5918dcc6d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -436,9 +436,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.60" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dec2b086b7a862cf4de201096214fa870344cf922b2b30c167badb3af3195406" +checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" dependencies = [ "unicode-ident", ] diff --git a/bindgen-tests/tests/expectations/tests/strings_cstr2.rs b/bindgen-tests/tests/expectations/tests/strings_cstr2.rs new file mode 100644 index 0000000000..2ce21f4374 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/strings_cstr2.rs @@ -0,0 +1,4 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub const MY_STRING_UTF8: &::std::ffi::CStr = c"Hello, world!"; +pub const MY_STRING_INTERIOR_NULL: &::std::ffi::CStr = c"Hello,"; +pub const MY_STRING_NON_UTF8: &::std::ffi::CStr = c"ABCDE\xFF"; diff --git a/bindgen-tests/tests/headers/strings_cstr2.h b/bindgen-tests/tests/headers/strings_cstr2.h new file mode 100644 index 0000000000..2cd7e6222d --- /dev/null +++ b/bindgen-tests/tests/headers/strings_cstr2.h @@ -0,0 +1,5 @@ +// bindgen-flags: --rust-target=1.77 --generate-cstr + +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/codegen/mod.rs b/bindgen/codegen/mod.rs index 943d8c7513..9f25369479 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -717,26 +717,38 @@ impl CodeGenerator for Var { let len = proc_macro2::Literal::usize_unsuffixed( cstr_bytes.len(), ); + let cstr = + if options.generate_cstr && rust_features.const_cstr { + CStr::from_bytes_with_nul(&cstr_bytes).ok() + } else { + None + }; - // TODO: Here we ignore the type we just made up, probably - // we should refactor how the variable type and ty ID work. - let array_ty = quote! { [u8; #len] }; - let cstr_ty = quote! { ::#prefix::ffi::CStr }; - - let bytes = proc_macro2::Literal::byte_string(&cstr_bytes); - - if options.generate_cstr && - rust_features.const_cstr && - CStr::from_bytes_with_nul(&cstr_bytes).is_ok() - { - result.push(quote! { - #(#attrs)* - #[allow(unsafe_code)] - pub const #canonical_ident: &#cstr_ty = unsafe { - #cstr_ty::from_bytes_with_nul_unchecked(#bytes) - }; - }); + if let Some(cstr) = cstr { + let cstr_ty = quote! { ::#prefix::ffi::CStr }; + if rust_features.literal_cstr { + let cstr = proc_macro2::Literal::c_string(&cstr); + result.push(quote! { + #(#attrs)* + pub const #canonical_ident: &#cstr_ty = #cstr; + }); + } else { + let bytes = + proc_macro2::Literal::byte_string(&cstr_bytes); + result.push(quote! { + #(#attrs)* + #[allow(unsafe_code)] + pub const #canonical_ident: &#cstr_ty = unsafe { + #cstr_ty::from_bytes_with_nul_unchecked(#bytes) + }; + }); + } } else { + // TODO: Here we ignore the type we just made up, probably + // we should refactor how the variable type and ty ID work. + let array_ty = quote! { [u8; #len] }; + let bytes = + proc_macro2::Literal::byte_string(&cstr_bytes); let lifetime = if true { None } else { Some(quote! { 'static }) } .into_iter(); diff --git a/bindgen/features.rs b/bindgen/features.rs index 9991522497..174491fae0 100644 --- a/bindgen/features.rs +++ b/bindgen/features.rs @@ -159,7 +159,10 @@ define_rust_targets! { ptr_metadata: #81513, layout_for_ptr: #69835, }, - Stable_1_77(77) => { offset_of: #106655 }, + Stable_1_77(77) => { + offset_of: #106655, + literal_cstr: #117472, + }, Stable_1_73(73) => { thiscall_abi: #42202 }, Stable_1_71(71) => { c_unwind_abi: #106075 }, Stable_1_68(68) => { abi_efiapi: #105795 }, From d5a2c81ce8a1770b5a4adfd6bf82c38d73175ec7 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Fri, 29 Nov 2024 15:14:33 -0500 Subject: [PATCH 771/942] avoid compiler warning --- bindgen/ir/analysis/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindgen/ir/analysis/mod.rs b/bindgen/ir/analysis/mod.rs index 1c05f1216d..3dd0780c0e 100644 --- a/bindgen/ir/analysis/mod.rs +++ b/bindgen/ir/analysis/mod.rs @@ -306,7 +306,7 @@ mod tests { type Extra = &'a Graph; type Output = HashMap>; - fn new(graph: &'a Graph) -> ReachableFrom { + fn new(graph: &'a Graph) -> Self { let reversed = graph.reverse(); ReachableFrom { reachable: Default::default(), From 7ca75a64ba64bb72b9d1f76d5c3d13759fddda85 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Fri, 29 Nov 2024 15:23:10 -0500 Subject: [PATCH 772/942] a few more lints --- bindgen-tests/tests/quickchecking/src/lib.rs | 11 ++++------- bindgen/clang.rs | 4 ++-- bindgen/codegen/impl_debug.rs | 4 ++-- bindgen/codegen/mod.rs | 18 +++++++++--------- bindgen/codegen/serialize.rs | 2 +- bindgen/ir/analysis/derive.rs | 6 ++---- bindgen/ir/analysis/has_destructor.rs | 2 +- bindgen/ir/analysis/has_float.rs | 2 +- bindgen/ir/analysis/has_type_param_in_array.rs | 2 +- bindgen/ir/analysis/has_vtable.rs | 2 +- bindgen/ir/analysis/sizedness.rs | 2 +- bindgen/ir/analysis/template_params.rs | 2 +- bindgen/ir/context.rs | 2 +- bindgen/ir/item.rs | 2 +- bindgen/time.rs | 2 +- 15 files changed, 29 insertions(+), 34 deletions(-) diff --git a/bindgen-tests/tests/quickchecking/src/lib.rs b/bindgen-tests/tests/quickchecking/src/lib.rs index d23ea792aa..c631742ec8 100644 --- a/bindgen-tests/tests/quickchecking/src/lib.rs +++ b/bindgen-tests/tests/quickchecking/src/lib.rs @@ -6,13 +6,10 @@ //! use quickcheck::{Arbitrary, Gen}; //! use quickchecking::fuzzers; //! -//! fn main() { -//! let generate_range: usize = 10; // Determines things like the length of -//! // arbitrary vectors generated. -//! let header = fuzzers::HeaderC::arbitrary( -//! &mut Gen::new(generate_range)); -//! println!("{}", header); -//! } +//! let generate_range: usize = 10; // Determines things like the length of +//! // arbitrary vectors generated. +//! let header = fuzzers::HeaderC::arbitrary(&mut Gen::new(generate_range)); +//! println!("{}", header); //! ``` #![deny(missing_docs)] diff --git a/bindgen/clang.rs b/bindgen/clang.rs index 47f07a384e..d8dc27a562 100644 --- a/bindgen/clang.rs +++ b/bindgen/clang.rs @@ -1016,7 +1016,7 @@ impl<'a> RawTokens<'a> { } } -impl<'a> Drop for RawTokens<'a> { +impl Drop for RawTokens<'_> { fn drop(&mut self) { if !self.tokens.is_null() { unsafe { @@ -1090,7 +1090,7 @@ pub(crate) struct ClangTokenIterator<'a> { raw: slice::Iter<'a, CXToken>, } -impl<'a> Iterator for ClangTokenIterator<'a> { +impl Iterator for ClangTokenIterator<'_> { type Item = ClangToken; fn next(&mut self) -> Option { diff --git a/bindgen/codegen/impl_debug.rs b/bindgen/codegen/impl_debug.rs index 67ec214ee8..87d5d14964 100644 --- a/bindgen/codegen/impl_debug.rs +++ b/bindgen/codegen/impl_debug.rs @@ -64,7 +64,7 @@ pub(crate) trait ImplDebug<'a> { ) -> Option<(String, Vec)>; } -impl<'a> ImplDebug<'a> for FieldData { +impl ImplDebug<'_> for FieldData { type Extra = (); fn impl_debug( @@ -80,7 +80,7 @@ impl<'a> ImplDebug<'a> for FieldData { } } -impl<'a> ImplDebug<'a> for BitfieldUnit { +impl ImplDebug<'_> for BitfieldUnit { type Extra = (); fn impl_debug( diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 9f25369479..b5ec56273e 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -372,7 +372,7 @@ impl<'a> CodegenResult<'a> { } } -impl<'a> ops::Deref for CodegenResult<'a> { +impl ops::Deref for CodegenResult<'_> { type Target = Vec; fn deref(&self) -> &Self::Target { @@ -380,7 +380,7 @@ impl<'a> ops::Deref for CodegenResult<'a> { } } -impl<'a> ops::DerefMut for CodegenResult<'a> { +impl ops::DerefMut for CodegenResult<'_> { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.items } @@ -727,7 +727,7 @@ impl CodeGenerator for Var { if let Some(cstr) = cstr { let cstr_ty = quote! { ::#prefix::ffi::CStr }; if rust_features.literal_cstr { - let cstr = proc_macro2::Literal::c_string(&cstr); + let cstr = proc_macro2::Literal::c_string(cstr); result.push(quote! { #(#attrs)* pub const #canonical_ident: &#cstr_ty = #cstr; @@ -1165,7 +1165,7 @@ impl<'a> Vtable<'a> { } } -impl<'a> CodeGenerator for Vtable<'a> { +impl CodeGenerator for Vtable<'_> { type Extra = Item; type Return = (); @@ -1243,13 +1243,13 @@ impl<'a> CodeGenerator for Vtable<'a> { } } -impl<'a> ItemCanonicalName for Vtable<'a> { +impl ItemCanonicalName for Vtable<'_> { fn canonical_name(&self, ctx: &BindgenContext) -> String { format!("{}__bindgen_vtable", self.item_id.canonical_name(ctx)) } } -impl<'a> TryToRustTy for Vtable<'a> { +impl TryToRustTy for Vtable<'_> { type Extra = (); fn try_to_rust_ty( @@ -1375,7 +1375,7 @@ trait FieldCodegen<'a> { M: Extend; } -impl<'a> FieldCodegen<'a> for Field { +impl FieldCodegen<'_> for Field { type Extra = (); fn codegen( @@ -1453,7 +1453,7 @@ fn wrap_union_field_if_needed( } } -impl<'a> FieldCodegen<'a> for FieldData { +impl FieldCodegen<'_> for FieldData { type Extra = (); fn codegen( @@ -1713,7 +1713,7 @@ fn compute_visibility( }) } -impl<'a> FieldCodegen<'a> for BitfieldUnit { +impl FieldCodegen<'_> for BitfieldUnit { type Extra = (); fn codegen( diff --git a/bindgen/codegen/serialize.rs b/bindgen/codegen/serialize.rs index 7f00f809f4..19df21e3d5 100644 --- a/bindgen/codegen/serialize.rs +++ b/bindgen/codegen/serialize.rs @@ -198,7 +198,7 @@ impl<'a> CSerialize<'a> for Function { } } -impl<'a> CSerialize<'a> for TypeId { +impl CSerialize<'_> for TypeId { type Extra = (); fn serialize( diff --git a/bindgen/ir/analysis/derive.rs b/bindgen/ir/analysis/derive.rs index f3c64307c4..47e433e015 100644 --- a/bindgen/ir/analysis/derive.rs +++ b/bindgen/ir/analysis/derive.rs @@ -104,7 +104,7 @@ fn consider_edge_default(kind: EdgeKind) -> bool { } } -impl<'ctx> CannotDerive<'ctx> { +impl CannotDerive<'_> { fn insert>( &mut self, id: Id, @@ -217,9 +217,7 @@ impl<'ctx> CannotDerive<'ctx> { TypeKind::Reference(..) | TypeKind::ObjCInterface(..) | TypeKind::ObjCId | - TypeKind::ObjCSel => { - return self.derive_trait.can_derive_simple(ty.kind()); - } + TypeKind::ObjCSel => self.derive_trait.can_derive_simple(ty.kind()), TypeKind::Pointer(inner) => { let inner_type = self.ctx.resolve_type(inner).canonical_type(self.ctx); diff --git a/bindgen/ir/analysis/has_destructor.rs b/bindgen/ir/analysis/has_destructor.rs index cbcbe55af2..f7b52b4a03 100644 --- a/bindgen/ir/analysis/has_destructor.rs +++ b/bindgen/ir/analysis/has_destructor.rs @@ -39,7 +39,7 @@ pub(crate) struct HasDestructorAnalysis<'ctx> { dependencies: HashMap>, } -impl<'ctx> HasDestructorAnalysis<'ctx> { +impl HasDestructorAnalysis<'_> { fn consider_edge(kind: EdgeKind) -> bool { // These are the only edges that can affect whether a type has a // destructor or not. diff --git a/bindgen/ir/analysis/has_float.rs b/bindgen/ir/analysis/has_float.rs index 219c5a5a8d..f27b4dc5dc 100644 --- a/bindgen/ir/analysis/has_float.rs +++ b/bindgen/ir/analysis/has_float.rs @@ -39,7 +39,7 @@ pub(crate) struct HasFloat<'ctx> { dependencies: HashMap>, } -impl<'ctx> HasFloat<'ctx> { +impl HasFloat<'_> { fn consider_edge(kind: EdgeKind) -> bool { match kind { EdgeKind::BaseMember | diff --git a/bindgen/ir/analysis/has_type_param_in_array.rs b/bindgen/ir/analysis/has_type_param_in_array.rs index 6665547ca6..c11f9df82e 100644 --- a/bindgen/ir/analysis/has_type_param_in_array.rs +++ b/bindgen/ir/analysis/has_type_param_in_array.rs @@ -39,7 +39,7 @@ pub(crate) struct HasTypeParameterInArray<'ctx> { dependencies: HashMap>, } -impl<'ctx> HasTypeParameterInArray<'ctx> { +impl HasTypeParameterInArray<'_> { fn consider_edge(kind: EdgeKind) -> bool { match kind { // These are the only edges that can affect whether a type has type parameter diff --git a/bindgen/ir/analysis/has_vtable.rs b/bindgen/ir/analysis/has_vtable.rs index 45dea55e6b..1f1c46ffd7 100644 --- a/bindgen/ir/analysis/has_vtable.rs +++ b/bindgen/ir/analysis/has_vtable.rs @@ -72,7 +72,7 @@ pub(crate) struct HasVtableAnalysis<'ctx> { dependencies: HashMap>, } -impl<'ctx> HasVtableAnalysis<'ctx> { +impl HasVtableAnalysis<'_> { fn consider_edge(kind: EdgeKind) -> bool { // These are the only edges that can affect whether a type has a // vtable or not. diff --git a/bindgen/ir/analysis/sizedness.rs b/bindgen/ir/analysis/sizedness.rs index edcf47f5c6..4dc52facba 100644 --- a/bindgen/ir/analysis/sizedness.rs +++ b/bindgen/ir/analysis/sizedness.rs @@ -105,7 +105,7 @@ pub(crate) struct SizednessAnalysis<'ctx> { sized: HashMap, } -impl<'ctx> SizednessAnalysis<'ctx> { +impl SizednessAnalysis<'_> { fn consider_edge(kind: EdgeKind) -> bool { // These are the only edges that can affect whether a type is // zero-sized or not. diff --git a/bindgen/ir/analysis/template_params.rs b/bindgen/ir/analysis/template_params.rs index a35dcd98e3..4015fb1728 100644 --- a/bindgen/ir/analysis/template_params.rs +++ b/bindgen/ir/analysis/template_params.rs @@ -161,7 +161,7 @@ pub(crate) struct UsedTemplateParameters<'ctx> { allowlisted_items: HashSet, } -impl<'ctx> UsedTemplateParameters<'ctx> { +impl UsedTemplateParameters<'_> { fn consider_edge(kind: EdgeKind) -> bool { match kind { // For each of these kinds of edges, if the referent uses a template diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index d32bb144a1..ccd559e58f 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -501,7 +501,7 @@ struct AllowlistedItemsTraversal<'ctx> { traversal: ItemTraversal<'ctx, ItemSet, Vec>, } -impl<'ctx> Iterator for AllowlistedItemsTraversal<'ctx> { +impl Iterator for AllowlistedItemsTraversal<'_> { type Item = ItemId; fn next(&mut self) -> Option { diff --git a/bindgen/ir/item.rs b/bindgen/ir/item.rs index 94abe4a86b..67976c9805 100644 --- a/bindgen/ir/item.rs +++ b/bindgen/ir/item.rs @@ -127,7 +127,7 @@ impl<'a> ItemAncestorsIter<'a> { } } -impl<'a> Iterator for ItemAncestorsIter<'a> { +impl Iterator for ItemAncestorsIter<'_> { type Item = ItemId; fn next(&mut self) -> Option { diff --git a/bindgen/time.rs b/bindgen/time.rs index c13a640c46..402327fd5a 100644 --- a/bindgen/time.rs +++ b/bindgen/time.rs @@ -45,7 +45,7 @@ impl<'a> Timer<'a> { } } -impl<'a> Drop for Timer<'a> { +impl Drop for Timer<'_> { fn drop(&mut self) { self.print_elapsed(); } From 72e85ef91325b7fad25cbde029355bed07159fae Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Fri, 29 Nov 2024 12:48:32 -0500 Subject: [PATCH 773/942] Use v2 cargo resolver The 2021 usually implies resolver v2, and warns otherwise. --- Cargo.toml | 3 +-- bindgen/lib.rs | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index bd87aacf0b..31c386bc26 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,4 +1,5 @@ [workspace] +resolver = "2" members = [ "bindgen", "bindgen-cli", @@ -7,7 +8,6 @@ members = [ "bindgen-tests/tests/quickchecking", "bindgen-tests/tests/expectations", ] - default-members = [ "bindgen", "bindgen-cli", @@ -54,4 +54,3 @@ release = false [profile.dist] inherits = "release" lto = "thin" - diff --git a/bindgen/lib.rs b/bindgen/lib.rs index b9b4888aa8..18b5023b1f 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -74,7 +74,6 @@ use std::path::{Path, PathBuf}; use std::process::{Command, Stdio}; use std::rc::Rc; use std::str::FromStr; -use std::sync::{Arc, OnceLock}; // Some convenient typedefs for a fast hash map and hash set. type HashMap = rustc_hash::FxHashMap; @@ -576,6 +575,8 @@ impl BindgenOptions { #[cfg(feature = "runtime")] fn ensure_libclang_is_loaded() { + use std::sync::{Arc, OnceLock}; + if clang_sys::is_loaded() { return; } From dc696e16239d09cfd783f71f032c3d737eaa361b Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Fri, 29 Nov 2024 18:06:00 -0500 Subject: [PATCH 774/942] Inline format args Ran this to auto-inline all format args: ``` cargo clippy --workspace --fix --all-targets -- -A clippy::all -W clippy::uninlined_format_args ``` --- bindgen-cli/main.rs | 4 +- bindgen-integration/build.rs | 4 +- bindgen-tests/tests/parse_callbacks/mod.rs | 4 +- .../tests/quickchecking/src/fuzzers.rs | 36 +++++----- bindgen-tests/tests/quickchecking/src/lib.rs | 2 +- bindgen-tests/tests/tests.rs | 14 ++-- bindgen/clang.rs | 22 +++--- bindgen/codegen/bitfield_unit_tests.rs | 2 +- bindgen/codegen/error.rs | 5 +- bindgen/codegen/helpers.rs | 4 +- bindgen/codegen/impl_debug.rs | 25 +++---- bindgen/codegen/mod.rs | 70 +++++++++---------- bindgen/codegen/serialize.rs | 35 +++++----- bindgen/codegen/struct_layout.rs | 2 +- bindgen/diagnostics.rs | 7 +- bindgen/features.rs | 3 +- bindgen/ir/analysis/has_destructor.rs | 5 +- bindgen/ir/analysis/has_float.rs | 5 +- .../ir/analysis/has_type_param_in_array.rs | 5 +- bindgen/ir/analysis/mod.rs | 4 +- bindgen/ir/annotations.rs | 2 +- bindgen/ir/comp.rs | 4 +- bindgen/ir/context.rs | 12 ++-- bindgen/ir/enum_ty.rs | 2 +- bindgen/ir/function.rs | 11 +-- bindgen/ir/item.rs | 6 +- bindgen/ir/objc.rs | 13 ++-- bindgen/ir/traversal.rs | 3 +- bindgen/ir/ty.rs | 4 +- bindgen/ir/var.rs | 9 +-- bindgen/lib.rs | 27 ++++--- bindgen/options/cli.rs | 6 +- bindgen/options/mod.rs | 2 +- bindgen/regex_set.rs | 4 +- 34 files changed, 162 insertions(+), 201 deletions(-) diff --git a/bindgen-cli/main.rs b/bindgen-cli/main.rs index c15aa00f91..0edf3a84d5 100644 --- a/bindgen-cli/main.rs +++ b/bindgen-cli/main.rs @@ -37,7 +37,7 @@ pub fn main() { if verbose { print_verbose_err() } - eprintln!("{}", info); + eprintln!("{info}"); })); let bindings = @@ -48,7 +48,7 @@ pub fn main() { bindings.write(output).expect("Unable to write output"); } Err(error) => { - eprintln!("{}", error); + eprintln!("{error}"); std::process::exit(1); } }; diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs index 88ba945366..c712569816 100644 --- a/bindgen-integration/build.rs +++ b/bindgen-integration/build.rs @@ -98,7 +98,7 @@ impl ParseCallbacks for MacroCallback { _ => { // The system might provide lots of functional macros. // Ensure we did not miss handling one that we meant to handle. - assert!(!name.starts_with("TESTMACRO_"), "name = {}", name); + assert!(!name.starts_with("TESTMACRO_"), "name = {name}"); } } } @@ -258,7 +258,7 @@ fn setup_wrap_static_fns_test() { .expect("Unable to generate bindings"); println!("cargo:rustc-link-lib=static=wrap_static_fns"); // tell cargo to link libextern - println!("bindings generated: {}", bindings); + println!("bindings generated: {bindings}"); let obj_path = out_path.join("wrap_static_fns.o"); let lib_path = out_path.join("libwrap_static_fns.a"); diff --git a/bindgen-tests/tests/parse_callbacks/mod.rs b/bindgen-tests/tests/parse_callbacks/mod.rs index 9f4b04a202..c372ce1057 100644 --- a/bindgen-tests/tests/parse_callbacks/mod.rs +++ b/bindgen-tests/tests/parse_callbacks/mod.rs @@ -66,7 +66,7 @@ impl ParseCallbacks for EnumVariantRename { original_variant_name: &str, _variant_value: EnumVariantValue, ) -> Option { - Some(format!("RENAMED_{}", original_variant_name)) + Some(format!("RENAMED_{original_variant_name}")) } } @@ -172,7 +172,7 @@ pub fn lookup(cb: &str) -> Box { ), }) } else { - panic!("Couldn't find name ParseCallbacks: {}", cb) + panic!("Couldn't find name ParseCallbacks: {cb}") } } } diff --git a/bindgen-tests/tests/quickchecking/src/fuzzers.rs b/bindgen-tests/tests/quickchecking/src/fuzzers.rs index 569ed6e09b..fffe78f8c7 100644 --- a/bindgen-tests/tests/quickchecking/src/fuzzers.rs +++ b/bindgen-tests/tests/quickchecking/src/fuzzers.rs @@ -201,11 +201,11 @@ impl Arbitrary for DeclarationC { impl fmt::Display for DeclarationC { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { - DeclarationC::FunctionPtrDecl(ref d) => write!(f, "{}", d), - DeclarationC::StructDecl(ref d) => write!(f, "{}", d), - DeclarationC::UnionDecl(ref d) => write!(f, "{}", d), - DeclarationC::VariableDecl(ref d) => write!(f, "{}", d), - DeclarationC::FunctionDecl(ref d) => write!(f, "{}", d), + DeclarationC::FunctionPtrDecl(ref d) => write!(f, "{d}"), + DeclarationC::StructDecl(ref d) => write!(f, "{d}"), + DeclarationC::UnionDecl(ref d) => write!(f, "{d}"), + DeclarationC::VariableDecl(ref d) => write!(f, "{d}"), + DeclarationC::FunctionDecl(ref d) => write!(f, "{d}"), } } } @@ -225,9 +225,9 @@ impl fmt::Display for DeclarationListC { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut display = String::new(); for decl in &self.decls { - display += &format!("{}", decl); + display += &format!("{decl}"); } - write!(f, "{}", display) + write!(f, "{display}") } } @@ -347,7 +347,7 @@ impl fmt::Display for ArrayDimensionC { /// identifiers unique. impl MakeUnique for BasicTypeDeclarationC { fn make_unique(&mut self, stamp: usize) { - self.ident_id += &format!("_{}", stamp); + self.ident_id += &format!("_{stamp}"); } } @@ -384,7 +384,7 @@ impl fmt::Display for BasicTypeDeclarationC { /// identifiers unique. impl MakeUnique for StructDeclarationC { fn make_unique(&mut self, stamp: usize) { - self.ident_id += &format!("_{}", stamp); + self.ident_id += &format!("_{stamp}"); } } @@ -432,7 +432,7 @@ impl fmt::Display for StructDeclarationC { /// identifiers unique. impl MakeUnique for UnionDeclarationC { fn make_unique(&mut self, stamp: usize) { - self.ident_id += &format!("_{}", stamp); + self.ident_id += &format!("_{stamp}"); } } @@ -480,7 +480,7 @@ impl fmt::Display for UnionDeclarationC { /// FunctionPointerDeclarationC identifiers unique. impl MakeUnique for FunctionPointerDeclarationC { fn make_unique(&mut self, stamp: usize) { - self.ident_id += &format!("_{}", stamp); + self.ident_id += &format!("_{stamp}"); } } @@ -517,7 +517,7 @@ impl fmt::Display for FunctionPointerDeclarationC { /// identifiers unique. impl MakeUnique for FunctionPrototypeC { fn make_unique(&mut self, stamp: usize) { - self.ident_id += &format!("_{}", stamp); + self.ident_id += &format!("_{stamp}"); } } @@ -589,11 +589,11 @@ impl fmt::Display for ParameterListC { let mut display = String::new(); for (i, p) in self.params.iter().enumerate() { match i { - 0 => display += &format!("{}", p), - _ => display += &format!(",{}", p), + 0 => display += &format!("{p}"), + _ => display += &format!(",{p}"), } } - write!(f, "{}", display) + write!(f, "{display}") } } @@ -614,9 +614,9 @@ impl fmt::Display for HeaderC { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut display = String::new(); for decl in &self.def.decls { - display += &format!("{}", decl); + display += &format!("{decl}"); } - write!(f, "{}", display) + write!(f, "{display}") } } @@ -624,7 +624,7 @@ impl fmt::Display for HeaderC { /// generated C code rather than the data structures that contain it. impl fmt::Debug for HeaderC { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}", self) + write!(f, "{self}") } } diff --git a/bindgen-tests/tests/quickchecking/src/lib.rs b/bindgen-tests/tests/quickchecking/src/lib.rs index c631742ec8..2c33858af2 100644 --- a/bindgen-tests/tests/quickchecking/src/lib.rs +++ b/bindgen-tests/tests/quickchecking/src/lib.rs @@ -81,7 +81,7 @@ fn bindgen_prop(header: fuzzers::HeaderC) -> TestResult { match run_predicate_script(header) { Ok(o) => TestResult::from_bool(o.status.success()), Err(e) => { - println!("{:?}", e); + println!("{e:?}"); TestResult::from_bool(false) } } diff --git a/bindgen-tests/tests/tests.rs b/bindgen-tests/tests/tests.rs index c008766d72..18262851cd 100644 --- a/bindgen-tests/tests/tests.rs +++ b/bindgen-tests/tests/tests.rs @@ -40,9 +40,9 @@ fn error_diff_mismatch( filename: &Path, ) -> Result<(), Error> { println!("diff expected generated"); - println!("--- expected: {:?}", filename); + println!("--- expected: {filename:?}"); if let Some(header) = header { - println!("+++ generated from: {:?}", header); + println!("+++ generated from: {header:?}"); } show_diff(expected, actual); @@ -153,9 +153,9 @@ fn compare_generated_header( } else if maj >= 9 { "9".to_owned() } else { - format!("{}.{}", maj, min) + format!("{maj}.{min}") }; - expectation.push(format!("libclang-{}", version_str)); + expectation.push(format!("libclang-{version_str}")); } } } @@ -194,7 +194,7 @@ fn compare_generated_header( Ok(bindings) => format_code(bindings.to_string()).map_err(|err| { Error::new( ErrorKind::Other, - format!("Cannot parse the generated bindings: {}", err), + format!("Cannot parse the generated bindings: {err}"), ) })?, Err(_) => "/* error generating bindings */\n".into(), @@ -219,7 +219,7 @@ fn compare_generated_header( if let Err(e) = compare_generated_header(header, roundtrip_builder, false) { - return Err(Error::new(ErrorKind::Other, format!("Checking CLI flags roundtrip errored! You probably need to fix Builder::command_line_flags. {}", e))); + return Err(Error::new(ErrorKind::Other, format!("Checking CLI flags roundtrip errored! You probably need to fix Builder::command_line_flags. {e}"))); } } @@ -703,7 +703,7 @@ fn build_flags_output_helper(builder: &bindgen::Builder) { .map(|x| format!("{}", shlex::try_quote(x).unwrap())) .collect(); let flags_str = flags_quoted.join(" "); - println!("{}", flags_str); + println!("{flags_str}"); let (builder, _output, _verbose) = builder_from_flags(command_line_flags.into_iter()).unwrap(); diff --git a/bindgen/clang.rs b/bindgen/clang.rs index d8dc27a562..03af94c8af 100644 --- a/bindgen/clang.rs +++ b/bindgen/clang.rs @@ -1636,7 +1636,7 @@ impl fmt::Display for SourceLocation { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let (file, line, col, _) = self.location(); if let Some(name) = file.name() { - write!(f, "{}:{}:{}", name, line, col) + write!(f, "{name}:{line}:{col}") } else { "builtin definitions".fmt(f) } @@ -1645,7 +1645,7 @@ impl fmt::Display for SourceLocation { impl fmt::Debug for SourceLocation { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self) + write!(f, "{self}") } } @@ -2126,15 +2126,15 @@ pub(crate) fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult { ); } if let Some(usr) = c.usr() { - print_indent(depth, format!(" {}usr = \"{}\"", prefix, usr)); + print_indent(depth, format!(" {prefix}usr = \"{usr}\"")); } if let Ok(num) = c.num_args() { - print_indent(depth, format!(" {}number-of-args = {}", prefix, num)); + print_indent(depth, format!(" {prefix}number-of-args = {num}")); } if let Some(num) = c.num_template_args() { print_indent( depth, - format!(" {}number-of-template-args = {}", prefix, num), + format!(" {prefix}number-of-template-args = {num}"), ); } @@ -2143,7 +2143,7 @@ pub(crate) fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult { Some(w) => w.to_string(), None => "".to_string(), }; - print_indent(depth, format!(" {}bit-width = {}", prefix, width)); + print_indent(depth, format!(" {prefix}bit-width = {width}")); } if let Some(ty) = c.enum_type() { @@ -2153,7 +2153,7 @@ pub(crate) fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult { ); } if let Some(val) = c.enum_val_signed() { - print_indent(depth, format!(" {}enum-val = {}", prefix, val)); + print_indent(depth, format!(" {prefix}enum-val = {val}")); } if let Some(ty) = c.typedef_type() { print_indent( @@ -2231,16 +2231,12 @@ pub(crate) fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult { print_indent( depth, format!( - " {}number-of-template-args = {}", - prefix, num_template_args + " {prefix}number-of-template-args = {num_template_args}" ), ); } if let Some(num) = ty.num_elements() { - print_indent( - depth, - format!(" {}number-of-elements = {}", prefix, num), - ); + print_indent(depth, format!(" {prefix}number-of-elements = {num}")); } print_indent( depth, diff --git a/bindgen/codegen/bitfield_unit_tests.rs b/bindgen/codegen/bitfield_unit_tests.rs index e143e4ea78..12b7204871 100644 --- a/bindgen/codegen/bitfield_unit_tests.rs +++ b/bindgen/codegen/bitfield_unit_tests.rs @@ -33,7 +33,7 @@ fn bitfield_unit_get_bit() { } println!(); - println!("bits = {:?}", bits); + println!("bits = {bits:?}"); assert_eq!( bits, &[ diff --git a/bindgen/codegen/error.rs b/bindgen/codegen/error.rs index 82e921d771..b82ba2aef1 100644 --- a/bindgen/codegen/error.rs +++ b/bindgen/codegen/error.rs @@ -36,12 +36,11 @@ impl fmt::Display for Error { Error::UnsupportedAbi(abi) => { write!( f, - "{} ABI is not supported by the configured Rust target.", - abi + "{abi} ABI is not supported by the configured Rust target." ) } Error::InvalidPointerSize { ty_name, ty_size, ptr_size } => { - write!(f, "The {} pointer type has size {} but the current target's pointer size is {}.", ty_name, ty_size, ptr_size) + write!(f, "The {ty_name} pointer type has size {ty_size} but the current target's pointer size is {ptr_size}.") } } } diff --git a/bindgen/codegen/helpers.rs b/bindgen/codegen/helpers.rs index 4bd08011f9..89665380e7 100644 --- a/bindgen/codegen/helpers.rs +++ b/bindgen/codegen/helpers.rs @@ -68,7 +68,7 @@ pub(crate) mod attributes { let name: Cow<'_, str> = if MANGLE { name.into() } else { - format!("\u{1}{}", name).into() + format!("\u{1}{name}").into() }; quote! { @@ -375,7 +375,7 @@ pub(crate) mod ast_ty { None => { unnamed_arguments += 1; let name = - ctx.rust_ident(format!("arg{}", unnamed_arguments)); + ctx.rust_ident(format!("arg{unnamed_arguments}")); quote! { #name } } }) diff --git a/bindgen/codegen/impl_debug.rs b/bindgen/codegen/impl_debug.rs index 87d5d14964..fd4422547e 100644 --- a/bindgen/codegen/impl_debug.rs +++ b/bindgen/codegen/impl_debug.rs @@ -10,7 +10,7 @@ pub(crate) fn gen_debug_impl( kind: CompKind, ) -> proc_macro2::TokenStream { let struct_name = item.canonical_name(ctx); - let mut format_string = format!("{} {{{{ ", struct_name); + let mut format_string = format!("{struct_name} {{{{ "); let mut tokens = vec![]; if item.is_opaque(ctx, &()) { @@ -96,7 +96,7 @@ impl ImplDebug<'_> for BitfieldUnit { } if let Some(bitfield_name) = bitfield.name() { - format_string.push_str(&format!("{} : {{:?}}", bitfield_name)); + format_string.push_str(&format!("{bitfield_name} : {{:?}}")); let getter_name = bitfield.getter_name(); let name_ident = ctx.rust_ident_raw(getter_name); tokens.push(quote! { @@ -137,7 +137,7 @@ impl<'a> ImplDebug<'a> for Item { name_ident: proc_macro2::TokenStream, ) -> Option<(String, Vec)> { Some(( - format!("{}: {{:?}}", name), + format!("{name}: {{:?}}"), vec![quote! { self.#name_ident }], @@ -162,7 +162,7 @@ impl<'a> ImplDebug<'a> for Item { TypeKind::TemplateInstantiation(ref inst) => { if inst.is_opaque(ctx, self) { - Some((format!("{}: opaque", name), vec![])) + Some((format!("{name}: opaque"), vec![])) } else { debug_print(name, quote! { #name_ident }) } @@ -170,16 +170,13 @@ impl<'a> ImplDebug<'a> for Item { // The generic is not required to implement Debug, so we can not debug print that type TypeKind::TypeParam => { - Some((format!("{}: Non-debuggable generic", name), vec![])) + Some((format!("{name}: Non-debuggable generic"), vec![])) } TypeKind::Array(_, len) => { // Generics are not required to implement Debug if self.has_type_param_in_array(ctx) { - Some(( - format!("{}: Array with length {}", name, len), - vec![], - )) + Some((format!("{name}: Array with length {len}"), vec![])) } else if len < RUST_DERIVE_IN_ARRAY_LIMIT || ctx.options().rust_features().larger_arrays { @@ -188,11 +185,11 @@ impl<'a> ImplDebug<'a> for Item { } 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![])) + Some((format!("{name}: [...]"), vec![])) } else { // Let's implement our own print function Some(( - format!("{}: [{{}}]", name), + format!("{name}: [{{}}]"), vec![quote! { self.#name_ident .iter() @@ -207,11 +204,11 @@ impl<'a> ImplDebug<'a> for Item { if ctx.options().use_core { // There is no format! in core; reducing field visibility to avoid breaking // no_std setups. - Some((format!("{}(...)", name), vec![])) + Some((format!("{name}(...)"), vec![])) } else { let self_ids = 0..len; Some(( - format!("{}({{}})", name), + format!("{name}({{}})"), vec![quote! { #(format!("{:?}", self.#self_ids)),* }], @@ -233,7 +230,7 @@ impl<'a> ImplDebug<'a> for Item { TypeKind::Function(ref sig) if !sig.function_pointers_can_derive() => { - Some((format!("{}: FunctionPointer", name), vec![])) + Some((format!("{name}: FunctionPointer"), vec![])) } _ => debug_print(name, quote! { #name_ident }), } diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index b5ec56273e..88809e2fbd 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -82,7 +82,7 @@ impl fmt::Display for CodegenError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::Serialize { msg, loc } => { - write!(f, "serialization error at {}: {}", loc, msg) + write!(f, "serialization error at {loc}: {msg}") } Self::Io(err) => err.fmt(f), } @@ -869,7 +869,7 @@ impl CodeGenerator for Type { { utils::fnsig_block(ctx, fnsig) } else { - panic!("invalid block typedef: {:?}", inner_item) + panic!("invalid block typedef: {inner_item:?}") } }; @@ -1569,9 +1569,9 @@ impl FieldCodegen<'_> for FieldData { return; } - let getter_name = ctx.rust_ident_raw(format!("get_{}", field_name)); + let getter_name = ctx.rust_ident_raw(format!("get_{field_name}")); let mutable_getter_name = - ctx.rust_ident_raw(format!("get_{}_mut", field_name)); + ctx.rust_ident_raw(format!("get_{field_name}_mut")); methods.extend(Some(match accessor_kind { FieldAccessorKind::None => unreachable!(), @@ -2149,7 +2149,7 @@ impl CodeGenerator for CompInfo { generic_param_names.push(ident.clone()); let prefix = ctx.trait_prefix(); - let field_name = ctx.rust_ident(format!("_phantom_{}", idx)); + let field_name = ctx.rust_ident(format!("_phantom_{idx}")); fields.push(quote! { pub #field_name : ::#prefix::marker::PhantomData< ::#prefix::cell::UnsafeCell<#ident> @@ -2403,7 +2403,7 @@ impl CodeGenerator for CompInfo { let packed_repr = if n == 1 { "packed".to_string() } else { - format!("packed({})", n) + format!("packed({n})") }; attributes.push(attributes::repr_list(&["C", &packed_repr])); } else { @@ -3011,7 +3011,7 @@ impl Method { let mut new_name; while { - new_name = format!("{}{}", name, count); + new_name = format!("{name}{count}"); method_names.contains(&new_name) } { count += 1; @@ -3024,7 +3024,7 @@ impl Method { let mut function_name = function_item.canonical_name(ctx); if times_seen > 0 { - write!(&mut function_name, "{}", times_seen).unwrap(); + write!(&mut function_name, "{times_seen}").unwrap(); } let function_name = ctx.rust_ident(function_name); let mut args = utils::fnsig_arguments(ctx, signature); @@ -3387,7 +3387,7 @@ impl<'a> EnumBuilder<'a> { } else { let ident = ctx.rust_ident(match mangling_prefix { Some(prefix) => { - Cow::Owned(format!("{}_{}", prefix, variant_name)) + Cow::Owned(format!("{prefix}_{variant_name}")) } None => variant_name, }); @@ -3403,7 +3403,7 @@ impl<'a> EnumBuilder<'a> { EnumBuilder::Consts { .. } => { let constant_name = match mangling_prefix { Some(prefix) => { - Cow::Owned(format!("{}_{}", prefix, variant_name)) + Cow::Owned(format!("{prefix}_{variant_name}")) } None => variant_name, }; @@ -3711,12 +3711,12 @@ impl CodeGenerator for Enum { ) { let constant_name = if enum_.name().is_some() { if ctx.options().prepend_enum_name { - format!("{}_{}", enum_canonical_name, variant_name) + format!("{enum_canonical_name}_{variant_name}") } else { - format!("{}", variant_name) + format!("{variant_name}") } } else { - format!("{}", variant_name) + format!("{variant_name}") }; let constant_name = ctx.rust_ident(constant_name); @@ -3776,18 +3776,16 @@ impl CodeGenerator for Enum { Entry::Occupied(ref entry) => { if variation.is_rust() { let variant_name = ctx.rust_mangle(variant.name()); - let mangled_name = - if is_toplevel || enum_ty.name().is_some() { - variant_name - } else { - let parent_name = - parent_canonical_name.as_ref().unwrap(); + let mangled_name = if is_toplevel || + enum_ty.name().is_some() + { + variant_name + } else { + let parent_name = + parent_canonical_name.as_ref().unwrap(); - Cow::Owned(format!( - "{}_{}", - parent_name, variant_name - )) - }; + Cow::Owned(format!("{parent_name}_{variant_name}")) + }; let existing_variant_name = entry.get(); // Use associated constants for named enums. @@ -3848,7 +3846,7 @@ impl CodeGenerator for Enum { parent_canonical_name.as_ref().unwrap(); Ident::new( - &format!("{}_{}", parent_name, variant_name), + &format!("{parent_name}_{variant_name}"), Span::call_site(), ) }; @@ -4498,7 +4496,7 @@ impl CodeGenerator for Function { let signature = signature_item.kind().expect_type().canonical_type(ctx); let signature = match *signature.kind() { TypeKind::Function(ref sig) => sig, - _ => panic!("Signature kind is not a Function: {:?}", signature), + _ => panic!("Signature kind is not a Function: {signature:?}"), }; if is_internal { @@ -4590,8 +4588,7 @@ impl CodeGenerator for Function { } Ok(ClangAbi::Unknown(unknown_abi)) => { panic!( - "Invalid or unknown abi {:?} for function {:?} ({:?})", - unknown_abi, canonical_name, self + "Invalid or unknown abi {unknown_abi:?} for function {canonical_name:?} ({self:?})" ); } Ok(abi) => abi, @@ -4601,7 +4598,7 @@ impl CodeGenerator for Function { // suffix. let times_seen = result.overload_number(&canonical_name); if times_seen > 0 { - write!(&mut canonical_name, "{}", times_seen).unwrap(); + write!(&mut canonical_name, "{times_seen}").unwrap(); } let mut has_link_name_attr = false; @@ -4787,7 +4784,7 @@ fn variadic_fn_diagnostic( let mut diag = Diagnostic::default(); - diag.with_title(format!("Cannot generate wrapper for the static function `{}`.", fn_name), Level::Warning) + diag.with_title(format!("Cannot generate wrapper for the static function `{fn_name}`."), Level::Warning) .add_annotation("The `--wrap-static-fns` feature does not support variadic functions.", Level::Note) .add_annotation("No code will be generated for this function.", Level::Note); @@ -5031,8 +5028,7 @@ impl CodeGenerator for ObjCInterface { result.push(from_block); let error_msg = format!( - "This {} cannot be downcasted to {}", - parent_struct_name, child_struct_name + "This {parent_struct_name} cannot be downcasted to {child_struct_name}" ); let try_into_block = quote! { impl std::convert::TryFrom<#parent_struct> for #class_name { @@ -5091,7 +5087,7 @@ pub(crate) fn codegen( let codegen_items = context.codegen_items(); for (id, item) in context.items() { if codegen_items.contains(&id) { - println!("ir: {:?} = {:#?}", id, item); + println!("ir: {id:?} = {item:#?}"); } } } @@ -5190,7 +5186,7 @@ pub(crate) mod utils { if !context.options().input_headers.is_empty() { for header in &context.options().input_headers { - writeln!(code, "#include \"{}\"", header)?; + writeln!(code, "#include \"{header}\"")?; } writeln!(code)?; @@ -5198,7 +5194,7 @@ pub(crate) mod utils { if !context.options().input_header_contents.is_empty() { for (name, contents) in &context.options().input_header_contents { - writeln!(code, "// {}\n{}", name, contents)?; + writeln!(code, "// {name}\n{contents}")?; } writeln!(code)?; @@ -5708,7 +5704,7 @@ pub(crate) mod utils { Some(ref name) => ctx.rust_mangle(name).into_owned(), None => { unnamed_arguments += 1; - format!("arg{}", unnamed_arguments) + format!("arg{unnamed_arguments}") } }; @@ -5752,7 +5748,7 @@ pub(crate) mod utils { Some(ref name) => ctx.rust_mangle(name).into_owned(), None => { unnamed_arguments += 1; - format!("arg{}", unnamed_arguments) + format!("arg{unnamed_arguments}") } }; diff --git a/bindgen/codegen/serialize.rs b/bindgen/codegen/serialize.rs index 19df21e3d5..7f25c28dda 100644 --- a/bindgen/codegen/serialize.rs +++ b/bindgen/codegen/serialize.rs @@ -45,7 +45,7 @@ impl<'a> CSerialize<'a> for Item { func.serialize(ctx, (self, extra), stack, writer) } kind => Err(CodegenError::Serialize { - msg: format!("Cannot serialize item kind {:?}", kind), + msg: format!("Cannot serialize item kind {kind:?}"), loc: get_loc(self), }), } @@ -102,7 +102,7 @@ impl<'a> CSerialize<'a> for Function { } else { Some(( opt_name.unwrap_or_else(|| { - let name = format!("arg_{}", count); + let name = format!("arg_{count}"); count += 1; name }), @@ -131,15 +131,15 @@ impl<'a> CSerialize<'a> for Function { const INDENT: &str = " "; // Write `wrap_name(args`. - write!(writer, " {}(", wrap_name)?; + write!(writer, " {wrap_name}(")?; serialize_args(&args, ctx, writer)?; if wrap_as_variadic.is_none() { // Write `) { name(` if the function returns void and `) { return name(` if it does not. if ret_ty.is_void() { - write!(writer, ") {{ {}(", name)?; + write!(writer, ") {{ {name}(")?; } else { - write!(writer, ") {{ return {}(", name)?; + write!(writer, ") {{ return {name}(")?; } } else { // Write `, ...) {` @@ -165,7 +165,7 @@ impl<'a> CSerialize<'a> for Function { if !ret_ty.is_void() { write!(writer, "ret = ")?; } - write!(writer, "{}(", name)?; + write!(writer, "{name}(")?; } // Get the arguments names and insert at the right place if necessary `ap` @@ -179,7 +179,7 @@ impl<'a> CSerialize<'a> for Function { // Write `arg_names);`. serialize_sep(", ", args.iter(), ctx, writer, |name, _, buf| { - write!(buf, "{}", name).map_err(From::from) + write!(buf, "{name}").map_err(From::from) })?; #[rustfmt::skip] write!(writer, ");{}", if wrap_as_variadic.is_none() { " " } else { "\n" })?; @@ -257,8 +257,7 @@ impl<'a> CSerialize<'a> for Type { int_kind => { return Err(CodegenError::Serialize { msg: format!( - "Cannot serialize integer kind {:?}", - int_kind + "Cannot serialize integer kind {int_kind:?}" ), loc: get_loc(item), }) @@ -294,9 +293,9 @@ impl<'a> CSerialize<'a> for Type { TypeKind::Alias(type_id) => { if let Some(name) = self.name() { if self.is_const() { - write!(writer, "const {}", name)?; + write!(writer, "const {name}")?; } else { - write!(writer, "{}", name)?; + write!(writer, "{name}")?; } } else { type_id.serialize(ctx, (), stack, writer)?; @@ -304,7 +303,7 @@ impl<'a> CSerialize<'a> for Type { } TypeKind::Array(type_id, length) => { type_id.serialize(ctx, (), stack, writer)?; - write!(writer, " [{}]", length)? + write!(writer, " [{length}]")? } TypeKind::Function(signature) => { if self.is_const() { @@ -320,7 +319,7 @@ impl<'a> CSerialize<'a> for Type { write!(writer, " (")?; while let Some(item) = stack.pop() { - write!(writer, "{}", item)?; + write!(writer, "{item}")?; } write!(writer, ")")?; @@ -367,8 +366,8 @@ impl<'a> CSerialize<'a> for Type { let name = item.canonical_name(ctx); match comp_info.kind() { - CompKind::Struct => write!(writer, "struct {}", name)?, - CompKind::Union => write!(writer, "union {}", name)?, + CompKind::Struct => write!(writer, "struct {name}")?, + CompKind::Union => write!(writer, "union {name}")?, }; } TypeKind::Enum(_enum_ty) => { @@ -377,11 +376,11 @@ impl<'a> CSerialize<'a> for Type { } let name = item.canonical_name(ctx); - write!(writer, "enum {}", name)?; + write!(writer, "enum {name}")?; } ty => { return Err(CodegenError::Serialize { - msg: format!("Cannot serialize type kind {:?}", ty), + msg: format!("Cannot serialize type kind {ty:?}"), loc: get_loc(item), }) } @@ -390,7 +389,7 @@ impl<'a> CSerialize<'a> for Type { if !stack.is_empty() { write!(writer, " ")?; while let Some(item) = stack.pop() { - write!(writer, "{}", item)?; + write!(writer, "{item}")?; } } diff --git a/bindgen/codegen/struct_layout.rs b/bindgen/codegen/struct_layout.rs index b78c65e55b..e3235dd84c 100644 --- a/bindgen/codegen/struct_layout.rs +++ b/bindgen/codegen/struct_layout.rs @@ -407,7 +407,7 @@ impl<'a> StructLayoutTracker<'a> { self.padding_count += 1; let padding_field_name = Ident::new( - &format!("__bindgen_padding_{}", padding_count), + &format!("__bindgen_padding_{padding_count}"), Span::call_site(), ); diff --git a/bindgen/diagnostics.rs b/bindgen/diagnostics.rs index e6f169e260..f22402ac0e 100644 --- a/bindgen/diagnostics.rs +++ b/bindgen/diagnostics.rs @@ -93,10 +93,10 @@ impl<'a> Diagnostic<'a> { let hide_warning = "\r \r"; let string = dl.to_string(); for line in string.lines() { - println!("cargo:warning={}{}", hide_warning, line); + println!("cargo:warning={hide_warning}{line}"); } } else { - eprintln!("{}\n", dl); + eprintln!("{dl}\n"); } } } @@ -126,8 +126,7 @@ impl<'a> Slice<'a> { line: usize, col: usize, ) -> &mut Self { - write!(name, ":{}:{}", line, col) - .expect("Writing to a string cannot fail"); + write!(name, ":{line}:{col}").expect("Writing to a string cannot fail"); self.filename = Some(name); self.line = Some(line); self diff --git a/bindgen/features.rs b/bindgen/features.rs index 174491fae0..650c810b0e 100644 --- a/bindgen/features.rs +++ b/bindgen/features.rs @@ -334,8 +334,7 @@ mod test { fn test_invalid_target(input: &str) { assert!( input.parse::().is_err(), - "{} should be an invalid target", - input + "{input} should be an invalid target" ); } diff --git a/bindgen/ir/analysis/has_destructor.rs b/bindgen/ir/analysis/has_destructor.rs index f7b52b4a03..2f5cf1127d 100644 --- a/bindgen/ir/analysis/has_destructor.rs +++ b/bindgen/ir/analysis/has_destructor.rs @@ -58,9 +58,8 @@ impl HasDestructorAnalysis<'_> { let was_not_already_in_set = self.have_destructor.insert(id); assert!( was_not_already_in_set, - "We shouldn't try and insert {:?} twice because if it was \ - already in the set, `constrain` should have exited early.", - id + "We shouldn't try and insert {id:?} twice because if it was \ + already in the set, `constrain` should have exited early." ); ConstrainResult::Changed } diff --git a/bindgen/ir/analysis/has_float.rs b/bindgen/ir/analysis/has_float.rs index f27b4dc5dc..75778ba7f4 100644 --- a/bindgen/ir/analysis/has_float.rs +++ b/bindgen/ir/analysis/has_float.rs @@ -68,9 +68,8 @@ impl HasFloat<'_> { let was_not_already_in_set = self.has_float.insert(id); assert!( was_not_already_in_set, - "We shouldn't try and insert {:?} twice because if it was \ - already in the set, `constrain` should have exited early.", - id + "We shouldn't try and insert {id:?} twice because if it was \ + already in the set, `constrain` should have exited early." ); ConstrainResult::Changed diff --git a/bindgen/ir/analysis/has_type_param_in_array.rs b/bindgen/ir/analysis/has_type_param_in_array.rs index c11f9df82e..2ac378bf75 100644 --- a/bindgen/ir/analysis/has_type_param_in_array.rs +++ b/bindgen/ir/analysis/has_type_param_in_array.rs @@ -74,9 +74,8 @@ impl HasTypeParameterInArray<'_> { self.has_type_parameter_in_array.insert(id); assert!( was_not_already_in_set, - "We shouldn't try and insert {:?} twice because if it was \ - already in the set, `constrain` should have exited early.", - id + "We shouldn't try and insert {id:?} twice because if it was \ + already in the set, `constrain` should have exited early." ); ConstrainResult::Changed diff --git a/bindgen/ir/analysis/mod.rs b/bindgen/ir/analysis/mod.rs index 3dd0780c0e..b40a66ccb9 100644 --- a/bindgen/ir/analysis/mod.rs +++ b/bindgen/ir/analysis/mod.rs @@ -370,7 +370,7 @@ mod tests { fn monotone() { let g = Graph::make_test_graph(); let reachable = analyze::(&g); - println!("reachable = {:#?}", reachable); + println!("reachable = {reachable:#?}"); fn nodes(nodes: A) -> HashSet where @@ -388,7 +388,7 @@ mod tests { expected.insert(Node(6), nodes([8])); expected.insert(Node(7), nodes([3, 4, 5, 6, 7, 8])); expected.insert(Node(8), nodes([])); - println!("expected = {:#?}", expected); + println!("expected = {expected:#?}"); assert_eq!(reachable, expected); } diff --git a/bindgen/ir/annotations.rs b/bindgen/ir/annotations.rs index 12295288c1..70d392f110 100644 --- a/bindgen/ir/annotations.rs +++ b/bindgen/ir/annotations.rs @@ -28,7 +28,7 @@ impl FromStr for FieldVisibilityKind { "private" => Ok(Self::Private), "crate" => Ok(Self::PublicCrate), "public" => Ok(Self::Public), - _ => Err(format!("Invalid visibility kind: `{}`", s)), + _ => Err(format!("Invalid visibility kind: `{s}`")), } } } diff --git a/bindgen/ir/comp.rs b/bindgen/ir/comp.rs index 036e7e5c8f..422f553b64 100644 --- a/bindgen/ir/comp.rs +++ b/bindgen/ir/comp.rs @@ -782,7 +782,7 @@ impl CompFields { getter }; let setter = { - let setter = format!("set_{}", bitfield_name); + let setter = format!("set_{bitfield_name}"); let mut setter = ctx.rust_mangle(&setter).to_string(); if has_method(methods, ctx, &setter) { setter.push_str("_bindgen_bitfield"); @@ -1466,7 +1466,7 @@ impl CompInfo { let field_name = match ci.base_members.len() { 0 => "_base".into(), - n => format!("_base_{}", n), + n => format!("_base_{n}"), }; let type_id = Item::from_ty_or_ref(cur.cur_type(), cur, None, ctx); diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index ccd559e58f..9cdb26c0c8 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -1294,8 +1294,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" }) }) }, - "{:?} should be in some ancestor module's children set", - id + "{id:?} should be in some ancestor module's children set" ); } } @@ -1515,7 +1514,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" let item_id = item_id.into(); match self.resolve_item_fallible(item_id) { Some(item) => item, - None => panic!("Not an item: {:?}", item_id), + None => panic!("Not an item: {item_id:?}"), } } @@ -2035,8 +2034,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" CXType_LongDouble => FloatKind::LongDouble, CXType_Float128 => FloatKind::Float128, _ => panic!( - "Non floating-type complex? {:?}, {:?}", - ty, float_type, + "Non floating-type complex? {ty:?}, {float_type:?}", ), }; TypeKind::Complex(float_kind) @@ -3147,11 +3145,11 @@ fn unused_regex_diagnostic(item: &str, name: &str, _ctx: &BindgenContext) { Diagnostic::default() .with_title( - format!("Unused regular expression: `{}`.", item), + format!("Unused regular expression: `{item}`."), Level::Warning, ) .add_annotation( - format!("This regular expression was passed to `{}`.", name), + format!("This regular expression was passed to `{name}`."), Level::Note, ) .display(); diff --git a/bindgen/ir/enum_ty.rs b/bindgen/ir/enum_ty.rs index 70cf0eae88..8a90cf99a4 100644 --- a/bindgen/ir/enum_ty.rs +++ b/bindgen/ir/enum_ty.rs @@ -79,7 +79,7 @@ impl Enum { let is_signed = variant_ty.map_or(true, |ty| match *ty.kind() { TypeKind::Int(ref int_kind) => int_kind.is_signed(), ref other => { - panic!("Since when enums can be non-integers? {:?}", other) + panic!("Since when enums can be non-integers? {other:?}") } }); diff --git a/bindgen/ir/function.rs b/bindgen/ir/function.rs index 1557843d03..5b6f8196e6 100644 --- a/bindgen/ir/function.rs +++ b/bindgen/ir/function.rs @@ -158,11 +158,7 @@ impl DotAttributes for Function { if let Some(ref mangled) = self.mangled_name { let mangled: String = mangled.chars().flat_map(|c| c.escape_default()).collect(); - writeln!( - out, - "

(path: P) -> Result @@ -33,11 +34,15 @@ impl TestLib { let foo = unsafe { __library.get(b"foo\0") }.map(|sym| *sym); let bar = unsafe { __library.get(b"bar\0") }.map(|sym| *sym); let baz = unsafe { __library.get(b"baz\0") }.map(|sym| *sym); + let FLUX = __library + .get::<*mut ::std::os::raw::c_int>(b"FLUX\0") + .map(|sym| *sym); Ok(TestLib { __library, foo, bar, baz, + FLUX, }) } pub unsafe fn foo( @@ -53,4 +58,7 @@ impl TestLib { pub unsafe fn baz(&self) -> ::std::os::raw::c_int { unsafe { (self.baz.as_ref().expect("Expected function, got error."))() } } + pub unsafe fn FLUX(&self) -> *mut ::std::os::raw::c_int { + *self.FLUX.as_ref().expect("Expected variable, got error.") + } } diff --git a/bindgen-tests/tests/headers/wrap_unsafe_ops_dynamic_loading_simple.h b/bindgen-tests/tests/headers/wrap_unsafe_ops_dynamic_loading_simple.h index 2b8c107185..36a638ae2a 100644 --- a/bindgen-tests/tests/headers/wrap_unsafe_ops_dynamic_loading_simple.h +++ b/bindgen-tests/tests/headers/wrap_unsafe_ops_dynamic_loading_simple.h @@ -3,3 +3,5 @@ int foo(int x, int y); int bar(void *x); int baz(); + +const int FLUX; From 492a9421e53892064abf64bf3fc45b9a798d31f5 Mon Sep 17 00:00:00 2001 From: Brian Ward Date: Mon, 21 Oct 2024 11:10:16 -0400 Subject: [PATCH 745/942] Wrap __library.get calls for variables if wrap_unsafe_ops --- .../wrap_unsafe_ops_dynamic_loading_simple.rs | 3 +-- bindgen/codegen/dyngen.rs | 22 ++++++++++++------- bindgen/codegen/mod.rs | 1 + 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_dynamic_loading_simple.rs b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_dynamic_loading_simple.rs index d261cc77ec..05be5d9944 100644 --- a/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_dynamic_loading_simple.rs +++ b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_dynamic_loading_simple.rs @@ -34,8 +34,7 @@ impl TestLib { let foo = unsafe { __library.get(b"foo\0") }.map(|sym| *sym); let bar = unsafe { __library.get(b"bar\0") }.map(|sym| *sym); let baz = unsafe { __library.get(b"baz\0") }.map(|sym| *sym); - let FLUX = __library - .get::<*mut ::std::os::raw::c_int>(b"FLUX\0") + let FLUX = unsafe { __library.get::<*mut ::std::os::raw::c_int>(b"FLUX\0") } .map(|sym| *sym); Ok(TestLib { __library, diff --git a/bindgen/codegen/dyngen.rs b/bindgen/codegen/dyngen.rs index 3109ddf296..e75e11a297 100644 --- a/bindgen/codegen/dyngen.rs +++ b/bindgen/codegen/dyngen.rs @@ -208,6 +208,7 @@ impl DynamicItems { ident: Ident, ty: TokenStream, is_required: bool, + wrap_unsafe_ops: bool, ) { let member = if is_required { quote! { *mut #ty } @@ -231,15 +232,20 @@ impl DynamicItems { }); let ident_str = codegen::helpers::ast_ty::cstr_expr(ident.to_string()); - self.constructor_inits.push(if is_required { - quote! { - let #ident = __library.get::<*mut #ty>(#ident_str).map(|sym| *sym)?; - } + + let library_get = if wrap_unsafe_ops { + quote!(unsafe { __library.get::<*mut #ty>(#ident_str) }) } else { - quote! { - let #ident = __library.get::<*mut #ty>(#ident_str).map(|sym| *sym); - } - }); + quote!(__library.get::<*mut #ty>(#ident_str)) + }; + + let qmark = if is_required { quote!(?) } else { quote!() }; + + let var_get = quote! { + let #ident = #library_get.map(|sym| *sym)#qmark; + }; + + self.constructor_inits.push(var_get); self.init_fields.push(quote! { #ident diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 2de56c19c5..ff6daac362 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -808,6 +808,7 @@ impl CodeGenerator for Var { .to_rust_ty_or_opaque(ctx, &()) .into_token_stream(), ctx.options().dynamic_link_require_all, + ctx.options().wrap_unsafe_ops, ); } else { result.push(tokens); From 2269982ab9a921a4d3e57d92090c8703b34fdd33 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Wed, 30 Oct 2024 22:42:38 -0400 Subject: [PATCH 746/942] Use `field_visibility` callback for new-type aliases The `field_visibility` callback is now called in case of alias new-type and new-type-deref with the type name and field_name set to `"0"` --- .../tests/expectations/tests/issue-2966.rs | 10 +++++++ bindgen-tests/tests/headers/issue-2966.h | 6 +++++ bindgen-tests/tests/parse_callbacks/mod.rs | 27 +++++++++++++++++-- bindgen/codegen/mod.rs | 12 +++++++-- 4 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 bindgen-tests/tests/expectations/tests/issue-2966.rs create mode 100644 bindgen-tests/tests/headers/issue-2966.h diff --git a/bindgen-tests/tests/expectations/tests/issue-2966.rs b/bindgen-tests/tests/expectations/tests/issue-2966.rs new file mode 100644 index 0000000000..bfdcbd9e2f --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/issue-2966.rs @@ -0,0 +1,10 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[repr(transparent)] +#[derive(Debug, Copy, Clone)] +pub struct pub_var1(pub *const ::std::os::raw::c_char); +#[repr(transparent)] +#[derive(Debug, Copy, Clone)] +pub struct pubcrate_var2(pub(crate) *const ::std::os::raw::c_char); +#[repr(transparent)] +#[derive(Debug, Copy, Clone)] +pub struct private_var3(*const ::std::os::raw::c_char); diff --git a/bindgen-tests/tests/headers/issue-2966.h b/bindgen-tests/tests/headers/issue-2966.h new file mode 100644 index 0000000000..3f00dec65d --- /dev/null +++ b/bindgen-tests/tests/headers/issue-2966.h @@ -0,0 +1,6 @@ +// bindgen-flags: --default-alias-style=new_type +// bindgen-parse-callbacks: type-visibility + +typedef const char * pub_var1; +typedef const char * pubcrate_var2; +typedef const char * private_var3; diff --git a/bindgen-tests/tests/parse_callbacks/mod.rs b/bindgen-tests/tests/parse_callbacks/mod.rs index ee31d56e49..9f4b04a202 100644 --- a/bindgen-tests/tests/parse_callbacks/mod.rs +++ b/bindgen-tests/tests/parse_callbacks/mod.rs @@ -93,8 +93,8 @@ struct FieldVisibility { } /// Implements the `field_visibility` function of the trait by checking if the -/// field name starts with `private_`. If it does it makes it private, if it -/// doesn't it makes it public, taking into account the default visibility. +/// field name starts with `private_`. If it does, it makes it private, if it +/// doesn't, it makes it public, taking into account the default visibility. impl ParseCallbacks for FieldVisibility { fn field_visibility( &self, @@ -113,6 +113,28 @@ impl ParseCallbacks for FieldVisibility { } } +#[derive(Debug)] +struct TypeVisibility; + +/// Implements the `field_visibility` function of the trait by checking the +/// type name. Depending on name prefix, it will return a different visibility. +impl ParseCallbacks for TypeVisibility { + fn field_visibility( + &self, + FieldInfo { type_name, .. }: FieldInfo, + ) -> Option { + if type_name.starts_with("private_") { + Some(FieldVisibilityKind::Private) + } else if type_name.starts_with("pubcrate_") { + Some(FieldVisibilityKind::PublicCrate) + } else if type_name.starts_with("pub_") { + Some(FieldVisibilityKind::Public) + } else { + None + } + } +} + #[derive(Debug)] pub(super) struct WrapAsVariadicFn; @@ -129,6 +151,7 @@ pub fn lookup(cb: &str) -> Box { Box::new(BlocklistedTypeImplementsTrait) } "wrap-as-variadic-fn" => Box::new(WrapAsVariadicFn), + "type-visibility" => Box::new(TypeVisibility), call_back => { if let Some(prefix) = call_back.strip_prefix("remove-function-prefix-") diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index ff6daac362..4cab877362 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -1100,13 +1100,21 @@ impl CodeGenerator for Type { }); } - let access_spec = - access_specifier(ctx.options().default_visibility); tokens.append_all(match alias_style { AliasVariation::TypeAlias => quote! { = #inner_rust_type ; }, AliasVariation::NewType | AliasVariation::NewTypeDeref => { + let visibility = ctx + .options() + .last_callback(|cb| { + cb.field_visibility(FieldInfo { + type_name: &item.canonical_name(ctx), + field_name: "0", + }) + }) + .unwrap_or(ctx.options().default_visibility); + let access_spec = access_specifier(visibility); quote! { (#access_spec #inner_rust_type) ; } From bb2cfd397ee26a6f62d0cb0a217a69bdd2671f82 Mon Sep 17 00:00:00 2001 From: Jonathan Schwender Date: Wed, 13 Nov 2024 13:30:02 +0100 Subject: [PATCH 747/942] Restrict release workflow to pushes The release workflow should not run on pull requests. --- .github/workflows/release.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5df0c7b1c1..61098dea41 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -39,7 +39,6 @@ permissions: # If there's a prerelease-style suffix to the version, then the release(s) # will be marked as a prerelease. on: - pull_request: push: tags: - '**[0-9]+.[0-9]+.[0-9]+*' From 2093c6f3afc2950015d2f94aa44611ac9c0ab6b6 Mon Sep 17 00:00:00 2001 From: Jonathan Schwender Date: Wed, 13 Nov 2024 13:03:51 +0100 Subject: [PATCH 748/942] Changelog: Move --with-attribute-custom to unreleased This option was added after the 0.70.1 release and is not available yet. --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cfecc5cee6..9a57f07e6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -215,6 +215,7 @@ -------------------------------------------------------------------------------- # Unreleased ## Added +- Add support for custom attributes (--with-attribute-custom, #2866) ## Changed - The `--wrap-static-fns` related options no longer require the experimental feature or flag. ## Removed @@ -237,7 +238,6 @@ - Add option to use DST structs for flexible arrays (--flexarray-dst, #2772). - Add option to dynamically load variables (#2812). - Add option in CLI to use rustified non-exhaustive enums (--rustified-non-exhaustive-enum, #2847). -- Add support for custom attributes (--with-attribute-custom, #2866) ## Changed - Remove which and lazy-static dependencies (#2809, #2817). - Generate compile-time layout tests (#2787). From 2b943c68f46044da7e3246010ad86b832280fd2e Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Tue, 19 Nov 2024 14:15:45 -0500 Subject: [PATCH 749/942] Use workspace inheritance for dependencies --- Cargo.toml | 8 ++++++++ bindgen-cli/Cargo.toml | 9 +++++---- bindgen-tests/Cargo.toml | 15 ++++++++------- bindgen/Cargo.toml | 7 ++++--- 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9170e18fed..7bfd8baca1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,14 @@ default-members = [ "bindgen-tests", ] +# Dependencies shared between crates +[workspace.dependencies] +clap = { version = "4", features = ["derive"] } +clap_complete = "4" +shlex = "1" +syn = "2.0" +proc-macro2 = { version = "1", default-features = false } + # Config for 'cargo dist' [workspace.metadata.dist] # The preferred cargo-dist version to use in CI (Cargo.toml SemVer syntax) diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index d75867b76b..dc5a8ae706 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -21,12 +21,13 @@ name = "bindgen" [dependencies] bindgen = { path = "../bindgen", version = "=0.70.1", default-features = false, features = ["__cli", "experimental", "prettyplease"] } -clap = { version = "4", features = ["derive"] } -clap_complete = "4" env_logger = { version = "0.10.0", optional = true } log = { version = "0.4", optional = true } -proc-macro2 = { version = "1", default-features = false } -shlex = "1" + +clap.workspace = true +clap_complete.workspace = true +proc-macro2.workspace = true +shlex.workspace = true [features] default = ["logging", "runtime"] diff --git a/bindgen-tests/Cargo.toml b/bindgen-tests/Cargo.toml index 47fc0b8ca0..613994a04e 100644 --- a/bindgen-tests/Cargo.toml +++ b/bindgen-tests/Cargo.toml @@ -6,15 +6,16 @@ publish = false [dev-dependencies] bindgen = { path = "../bindgen", features = ["__cli", "experimental"] } -clap = { version = "4", features = ["derive"] } -clap_complete = "4" -shlex = "1" +owo-colors = "3.5.0" prettyplease = { version = "0.2.7", features = ["verbatim"] } -proc-macro2 = { version = "1", default-features = false } -syn = { version = "2.0" } -tempfile = "3" similar = { version = "2.2.1", features = ["inline"] } -owo-colors = "3.5.0" +tempfile = "3" + +clap.workspace = true +clap_complete.workspace = true +proc-macro2.workspace = true +shlex.workspace = true +syn.workspace = true [features] logging = ["bindgen/logging"] diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index cad94d0c16..9c351f28c6 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -32,12 +32,13 @@ clang-sys = { version = "1", features = ["clang_11_0"] } itertools = { version = ">=0.10,<0.14", default-features = false } log = { version = "0.4", optional = true } prettyplease = { version = "0.2.7", optional = true, features = ["verbatim"] } -proc-macro2 = { version = "1", default-features = false } quote = { version = "1", default-features = false } regex = { version = "1.5.3", default-features = false, features = ["std", "unicode-perl"] } rustc-hash = "1.0.1" -shlex = "1" -syn = { version = "2.0", features = ["full", "extra-traits", "visit-mut"] } + +proc-macro2.workspace = true +shlex.workspace = true +syn = { workspace = true, features = ["full", "extra-traits", "visit-mut"] } [features] default = ["logging", "prettyplease", "runtime"] From 1c834b75661825df817914027355fe2522ce75e8 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Tue, 19 Nov 2024 14:48:28 -0500 Subject: [PATCH 750/942] Set edition for `bindgen-integration` --- bindgen-integration/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/bindgen-integration/Cargo.toml b/bindgen-integration/Cargo.toml index ccdd1467df..cf89e2d9b9 100644 --- a/bindgen-integration/Cargo.toml +++ b/bindgen-integration/Cargo.toml @@ -4,6 +4,7 @@ description = "A package to test various bindgen features" version = "0.1.0" authors = ["Emilio Cobos Álvarez "] publish = false +edition = "2018" build = "build.rs" [build-dependencies] From 0f9dcdb4282a2462bf8ffeda4e7e2c40f95c9e86 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Tue, 19 Nov 2024 19:37:21 -0500 Subject: [PATCH 751/942] Move CLI options to `bindgen` --- Cargo.lock | 6 +- Cargo.toml | 2 - bindgen-cli/Cargo.toml | 2 - bindgen-cli/main.rs | 3 +- bindgen-tests/Cargo.toml | 2 - bindgen-tests/tests/tests.rs | 8 +-- bindgen/Cargo.toml | 4 +- bindgen/lib.rs | 4 +- .../options.rs => bindgen/options/cli.rs | 65 ++++++++++++------- bindgen/options/mod.rs | 2 + 10 files changed, 52 insertions(+), 46 deletions(-) rename bindgen-cli/options.rs => bindgen/options/cli.rs (96%) diff --git a/Cargo.lock b/Cargo.lock index 0ea9474809..251244184c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -35,6 +35,8 @@ dependencies = [ "bitflags 2.2.1", "cexpr", "clang-sys", + "clap", + "clap_complete", "itertools", "log", "prettyplease", @@ -51,8 +53,6 @@ name = "bindgen-cli" version = "0.70.1" dependencies = [ "bindgen", - "clap", - "clap_complete", "env_logger 0.10.0", "log", "proc-macro2", @@ -72,8 +72,6 @@ name = "bindgen-tests" version = "0.1.0" dependencies = [ "bindgen", - "clap", - "clap_complete", "owo-colors", "prettyplease", "proc-macro2", diff --git a/Cargo.toml b/Cargo.toml index 7bfd8baca1..e0535a1c66 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,8 +16,6 @@ default-members = [ # Dependencies shared between crates [workspace.dependencies] -clap = { version = "4", features = ["derive"] } -clap_complete = "4" shlex = "1" syn = "2.0" proc-macro2 = { version = "1", default-features = false } diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index dc5a8ae706..2e5bf1b47f 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -24,8 +24,6 @@ bindgen = { path = "../bindgen", version = "=0.70.1", default-features = false, env_logger = { version = "0.10.0", optional = true } log = { version = "0.4", optional = true } -clap.workspace = true -clap_complete.workspace = true proc-macro2.workspace = true shlex.workspace = true diff --git a/bindgen-cli/main.rs b/bindgen-cli/main.rs index caa47c6268..c15aa00f91 100644 --- a/bindgen-cli/main.rs +++ b/bindgen-cli/main.rs @@ -1,7 +1,6 @@ use std::env; -mod options; -use crate::options::builder_from_flags; +use bindgen::builder_from_flags; #[cfg(feature = "logging")] fn clang_version_check() { diff --git a/bindgen-tests/Cargo.toml b/bindgen-tests/Cargo.toml index 613994a04e..4a92f81f55 100644 --- a/bindgen-tests/Cargo.toml +++ b/bindgen-tests/Cargo.toml @@ -11,8 +11,6 @@ prettyplease = { version = "0.2.7", features = ["verbatim"] } similar = { version = "2.2.1", features = ["inline"] } tempfile = "3" -clap.workspace = true -clap_complete.workspace = true proc-macro2.workspace = true shlex.workspace = true syn.workspace = true diff --git a/bindgen-tests/tests/tests.rs b/bindgen-tests/tests/tests.rs index 14988e463f..c008766d72 100644 --- a/bindgen-tests/tests/tests.rs +++ b/bindgen-tests/tests/tests.rs @@ -7,10 +7,7 @@ use std::fs; use std::io::{BufRead, BufReader, Error, ErrorKind, Read, Write}; use std::path::{Path, PathBuf}; -use crate::options::builder_from_flags; - -#[path = "../../bindgen-cli/options.rs"] -mod options; +use bindgen::builder_from_flags; mod parse_callbacks; @@ -709,8 +706,7 @@ fn build_flags_output_helper(builder: &bindgen::Builder) { println!("{}", flags_str); let (builder, _output, _verbose) = - crate::options::builder_from_flags(command_line_flags.into_iter()) - .unwrap(); + builder_from_flags(command_line_flags.into_iter()).unwrap(); builder.generate().expect("failed to generate bindings"); } diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index 9c351f28c6..d8b872b77c 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -29,6 +29,8 @@ annotate-snippets = { version = "0.11.4", optional = true } bitflags = "2.2.1" cexpr = "0.6" clang-sys = { version = "1", features = ["clang_11_0"] } +clap = { version = "4", features = ["derive"], optional = true } +clap_complete = { version = "4", optional = true} itertools = { version = ">=0.10,<0.14", default-features = false } log = { version = "0.4", optional = true } prettyplease = { version = "0.2.7", optional = true, features = ["verbatim"] } @@ -52,7 +54,7 @@ experimental = ["dep:annotate-snippets"] ## The following features are for internal use and they shouldn't be used if ## you're not hacking on bindgen # Features used by `bindgen-cli` -__cli = [] +__cli = ["dep:clap", "dep:clap_complete"] # Features used for CI testing __testing_only_extra_assertions = [] __testing_only_libclang_9 = [] diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 1a9932b534..6d54bbb344 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -50,11 +50,11 @@ mod regex_set; pub use codegen::{ AliasVariation, EnumVariation, MacroTypeVariation, NonCopyUnionStyle, }; -#[cfg(feature = "__cli")] -pub use features::RUST_TARGET_STRINGS; pub use features::{RustTarget, LATEST_STABLE_RUST}; pub use ir::annotations::FieldVisibilityKind; pub use ir::function::Abi; +#[cfg(feature = "__cli")] +pub use options::cli::builder_from_flags; pub use regex_set::RegexSet; use codegen::CodegenError; diff --git a/bindgen-cli/options.rs b/bindgen/options/cli.rs similarity index 96% rename from bindgen-cli/options.rs rename to bindgen/options/cli.rs index ad96664bd2..dfe8ad5884 100644 --- a/bindgen-cli/options.rs +++ b/bindgen/options/cli.rs @@ -1,11 +1,17 @@ -use bindgen::callbacks::TypeKind; -use bindgen::{ - builder, Abi, AliasVariation, Builder, CodegenConfig, EnumVariation, +use crate::{ + builder, + callbacks::{ + AttributeInfo, DeriveInfo, ItemInfo, ParseCallbacks, TypeKind, + }, + features::RUST_TARGET_STRINGS, + Abi, AliasVariation, Builder, CodegenConfig, EnumVariation, FieldVisibilityKind, Formatter, MacroTypeVariation, NonCopyUnionStyle, - RegexSet, RustTarget, DEFAULT_ANON_FIELDS_PREFIX, RUST_TARGET_STRINGS, + RegexSet, RustTarget, DEFAULT_ANON_FIELDS_PREFIX, +}; +use clap::{ + error::{Error, ErrorKind}, + CommandFactory, Parser, }; -use clap::error::{Error, ErrorKind}; -use clap::{CommandFactory, Parser}; use proc_macro2::TokenStream; use std::fs::File; use std::io; @@ -491,6 +497,7 @@ struct BindgenCommand { #[arg(long, value_name = "VISIBILITY")] default_visibility: Option, /// Whether to emit diagnostics or not. + #[cfg(feature = "experimental")] #[arg(long, requires = "experimental")] emit_diagnostics: bool, /// Generates completions for the specified SHELL, sends them to `stdout` and exits. @@ -633,6 +640,7 @@ where wrap_static_fns_path, wrap_static_fns_suffix, default_visibility, + #[cfg(feature = "experimental")] emit_diagnostics, generate_shell_completions, experimental: _, @@ -657,7 +665,7 @@ where option_env!("CARGO_PKG_VERSION").unwrap_or("unknown") ); if verbose { - println!("Clang: {}", bindgen::clang_version().full); + println!("Clang: {}", crate::clang_version().full); } std::process::exit(0); } @@ -1046,10 +1054,10 @@ where prefix: String, } - impl bindgen::callbacks::ParseCallbacks for PrefixLinkNameCallback { + impl ParseCallbacks for PrefixLinkNameCallback { fn generated_link_name_override( &self, - item_info: bindgen::callbacks::ItemInfo<'_>, + item_info: ItemInfo<'_>, ) -> Option { let mut prefix = self.prefix.clone(); prefix.push_str(item_info.name); @@ -1114,10 +1122,10 @@ where struct CustomDeriveCallback { derives: Vec, kind: Option, - regex_set: bindgen::RegexSet, + regex_set: RegexSet, } - impl bindgen::callbacks::ParseCallbacks for CustomDeriveCallback { + impl ParseCallbacks for CustomDeriveCallback { fn cli_args(&self) -> Vec { let mut args = vec![]; @@ -1140,10 +1148,7 @@ where args } - fn add_derives( - &self, - info: &bindgen::callbacks::DeriveInfo<'_>, - ) -> Vec { + fn add_derives(&self, info: &DeriveInfo<'_>) -> Vec { if self.kind.map(|kind| kind == info.kind).unwrap_or(true) && self.regex_set.matches(info.name) { @@ -1153,7 +1158,7 @@ where } } - for (custom_derives, kind, name) in [ + for (custom_derives, kind, _name) in [ (with_derive_custom, None, "--with-derive-custom"), ( with_derive_custom_struct, @@ -1171,11 +1176,17 @@ where "--with-derive-custom-union", ), ] { - let name = emit_diagnostics.then_some(name); + #[cfg(feature = "experimental")] + let name = emit_diagnostics.then_some(_name); + for (derives, regex) in custom_derives { let mut regex_set = RegexSet::new(); regex_set.insert(regex); + + #[cfg(feature = "experimental")] regex_set.build_with_diagnostics(false, name); + #[cfg(not(feature = "experimental"))] + regex_set.build(false); builder = builder.parse_callbacks(Box::new(CustomDeriveCallback { derives, @@ -1189,10 +1200,10 @@ where struct CustomAttributeCallback { attributes: Vec, kind: Option, - regex_set: bindgen::RegexSet, + regex_set: RegexSet, } - impl bindgen::callbacks::ParseCallbacks for CustomAttributeCallback { + impl ParseCallbacks for CustomAttributeCallback { fn cli_args(&self) -> Vec { let mut args = vec![]; @@ -1215,10 +1226,7 @@ where args } - fn add_attributes( - &self, - info: &bindgen::callbacks::AttributeInfo<'_>, - ) -> Vec { + fn add_attributes(&self, info: &AttributeInfo<'_>) -> Vec { if self.kind.map(|kind| kind == info.kind).unwrap_or(true) && self.regex_set.matches(info.name) { @@ -1228,7 +1236,7 @@ where } } - for (custom_attributes, kind, name) in [ + for (custom_attributes, kind, _name) in [ (with_attribute_custom, None, "--with-attribute-custom"), ( with_attribute_custom_struct, @@ -1246,11 +1254,17 @@ where "--with-attribute-custom-union", ), ] { - let name = emit_diagnostics.then_some(name); + #[cfg(feature = "experimental")] + let name = emit_diagnostics.then_some(_name); + for (attributes, regex) in custom_attributes { let mut regex_set = RegexSet::new(); regex_set.insert(regex); + + #[cfg(feature = "experimental")] regex_set.build_with_diagnostics(false, name); + #[cfg(not(feature = "experimental"))] + regex_set.build(false); builder = builder.parse_callbacks(Box::new(CustomAttributeCallback { @@ -1277,6 +1291,7 @@ where builder = builder.default_visibility(visibility); } + #[cfg(feature = "experimental")] if emit_diagnostics { builder = builder.emit_diagnostics(); } diff --git a/bindgen/options/mod.rs b/bindgen/options/mod.rs index e9f4fb811c..57988e79e6 100644 --- a/bindgen/options/mod.rs +++ b/bindgen/options/mod.rs @@ -4,6 +4,8 @@ #[macro_use] mod helpers; mod as_args; +#[cfg(feature = "__cli")] +pub(crate) mod cli; use crate::callbacks::ParseCallbacks; use crate::codegen::{ From 1d8de67f762ed556cb3165c4c3cbc679e3b91d23 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Tue, 19 Nov 2024 20:15:40 -0500 Subject: [PATCH 752/942] make `RegexSet` non-public --- bindgen/lib.rs | 1 - bindgen/options/as_args.rs | 2 +- bindgen/options/cli.rs | 7 ++++--- bindgen/regex_set.rs | 22 +++++++++------------- 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 6d54bbb344..134e3d6d91 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -55,7 +55,6 @@ pub use ir::annotations::FieldVisibilityKind; pub use ir::function::Abi; #[cfg(feature = "__cli")] pub use options::cli::builder_from_flags; -pub use regex_set::RegexSet; use codegen::CodegenError; use features::RustFeatures; diff --git a/bindgen/options/as_args.rs b/bindgen/options/as_args.rs index 6918ad9fec..83103fdaf4 100644 --- a/bindgen/options/as_args.rs +++ b/bindgen/options/as_args.rs @@ -1,6 +1,6 @@ use std::path::PathBuf; -use crate::RegexSet; +use crate::regex_set::RegexSet; /// Trait used to turn [`crate::BindgenOptions`] fields into CLI args. pub(super) trait AsArgs { diff --git a/bindgen/options/cli.rs b/bindgen/options/cli.rs index dfe8ad5884..1f51b3bece 100644 --- a/bindgen/options/cli.rs +++ b/bindgen/options/cli.rs @@ -4,9 +4,10 @@ use crate::{ AttributeInfo, DeriveInfo, ItemInfo, ParseCallbacks, TypeKind, }, features::RUST_TARGET_STRINGS, + regex_set::RegexSet, Abi, AliasVariation, Builder, CodegenConfig, EnumVariation, FieldVisibilityKind, Formatter, MacroTypeVariation, NonCopyUnionStyle, - RegexSet, RustTarget, DEFAULT_ANON_FIELDS_PREFIX, + RustTarget, DEFAULT_ANON_FIELDS_PREFIX, }; use clap::{ error::{Error, ErrorKind}, @@ -1180,7 +1181,7 @@ where let name = emit_diagnostics.then_some(_name); for (derives, regex) in custom_derives { - let mut regex_set = RegexSet::new(); + let mut regex_set = RegexSet::default(); regex_set.insert(regex); #[cfg(feature = "experimental")] @@ -1258,7 +1259,7 @@ where let name = emit_diagnostics.then_some(_name); for (attributes, regex) in custom_attributes { - let mut regex_set = RegexSet::new(); + let mut regex_set = RegexSet::default(); regex_set.insert(regex); #[cfg(feature = "experimental")] diff --git a/bindgen/regex_set.rs b/bindgen/regex_set.rs index 7f40af3c79..3375632761 100644 --- a/bindgen/regex_set.rs +++ b/bindgen/regex_set.rs @@ -6,7 +6,7 @@ use std::cell::Cell; /// A dynamic set of regular expressions. #[derive(Clone, Debug, Default)] -pub struct RegexSet { +pub(crate) struct RegexSet { items: Vec>, /// Whether any of the items in the set was ever matched. The length of this /// vector is exactly the length of `items`. @@ -17,18 +17,13 @@ pub struct RegexSet { } impl RegexSet { - /// Create a new RegexSet - pub fn new() -> RegexSet { - RegexSet::default() - } - /// Is this set empty? - pub fn is_empty(&self) -> bool { + pub(crate) fn is_empty(&self) -> bool { self.items.is_empty() } /// Insert a new regex into this set. - pub fn insert(&mut self, string: S) + pub(crate) fn insert(&mut self, string: S) where S: AsRef, { @@ -38,13 +33,13 @@ impl RegexSet { } /// Returns slice of String from its field 'items' - pub fn get_items(&self) -> &[Box] { + pub(crate) fn get_items(&self) -> &[Box] { &self.items } /// Returns an iterator over regexes in the set which didn't match any /// strings yet. - pub fn unmatched_items(&self) -> impl Iterator { + pub(crate) fn unmatched_items(&self) -> impl Iterator { self.items.iter().enumerate().filter_map(move |(i, item)| { if !self.record_matches || self.matched[i].get() { return None; @@ -59,7 +54,8 @@ impl RegexSet { /// Must be called before calling `matches()`, or it will always return /// false. #[inline] - pub fn build(&mut self, record_matches: bool) { + #[allow(unused)] + pub(crate) fn build(&mut self, record_matches: bool) { self.build_inner(record_matches, None) } @@ -70,7 +66,7 @@ impl RegexSet { /// Must be called before calling `matches()`, or it will always return /// false. #[inline] - pub fn build_with_diagnostics( + pub(crate) fn build_with_diagnostics( &mut self, record_matches: bool, name: Option<&'static str>, @@ -114,7 +110,7 @@ impl RegexSet { } /// Does the given `string` match any of the regexes in this set? - pub fn matches(&self, string: S) -> bool + pub(crate) fn matches(&self, string: S) -> bool where S: AsRef, { From 3147afd73fd41f718ce5792c642719460d7d2adc Mon Sep 17 00:00:00 2001 From: Mossa Date: Thu, 21 Nov 2024 13:10:50 +0100 Subject: [PATCH 753/942] Formatted `CONTRIBUTING.md`. - Passes `markdownlint` (mostly) - Removed `$` from shell instructions, as to be more copy/paste friendly - Annotated code-like things with backticks. - Annotated all shell blocks with `sh` to format nicely on GitHub.com. --- CONTRIBUTING.md | 207 ++++++++++++++++++++++++------------------------ 1 file changed, 105 insertions(+), 102 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ff48cf1df7..9c28e198c9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -54,18 +54,18 @@ We abide by the [Rust Code of Conduct][coc] and ask that you do as well. Think you've found a bug? File an issue! To help us understand and reproduce the issue, provide us with: -* A (preferably reduced) C/C++ header file that reproduces the issue -* The `bindgen` flags used to reproduce the issue with the header file -* The expected `bindgen` output -* The actual `bindgen` output -* The [debugging logs](#debug-logging) generated when running `bindgen` on this testcase +- A (preferably reduced) C/C++ header file that reproduces the issue +- The `bindgen` flags used to reproduce the issue with the header file +- The expected `bindgen` output +- The actual `bindgen` output +- The [debugging logs](#debug-logging) generated when running `bindgen` on this testcase ## Looking to Start Contributing to `bindgen`? -* [Issues labeled "easy"](https://github.com/rust-lang/rust-bindgen/issues?q=is%3Aopen+is%3Aissue+label%3AE-easy) -* [Issues labeled "less easy"](https://github.com/rust-lang/rust-bindgen/issues?q=is%3Aopen+is%3Aissue+label%3AE-less-easy) -* [Issues labeled "help wanted"](https://github.com/rust-lang/rust-bindgen/labels/help%20wanted) -* Still can't find something to work on? [Drop a comment here](https://github.com/rust-lang/rust-bindgen/issues/747) +- [Issues labeled "easy"](https://github.com/rust-lang/rust-bindgen/issues?q=is%3Aopen+is%3Aissue+label%3AE-easy) +- [Issues labeled "less easy"](https://github.com/rust-lang/rust-bindgen/issues?q=is%3Aopen+is%3Aissue+label%3AE-less-easy) +- [Issues labeled "help wanted"](https://github.com/rust-lang/rust-bindgen/labels/help%20wanted) +- Still can't find something to work on? [Drop a comment here](https://github.com/rust-lang/rust-bindgen/issues/747) ## Prerequisites @@ -82,16 +82,16 @@ To check via command line, you can run `cargo +nightly fmt --check`. To build the `bindgen` library and the `bindgen` executable: -``` -$ cargo build +```sh +cargo build ``` If you installed multiple versions of llvm, it may not be able to locate the -latest version of libclang. In that case, you may want to either uninstall other -versions of llvm, or specify the path of the desired libclang explicitly: +latest version of `libclang`. In that case, you may want to either uninstall other +versions of llvm, or specify the path of the desired `libclang` explicitly: -``` -$ export LIBCLANG_PATH=path/to/clang-9.0/lib +```sh +export LIBCLANG_PATH=path/to/clang-9.0/lib ``` ## Testing @@ -107,7 +107,7 @@ There are also some integration tests in the `./bindgen-integration` crate, whic generate bindings to some C++ code, and then uses the bindings, asserting that values are what we expect them to be, both on the Rust and C++ side. -The generated and expected bindings are formatted with [prettyplease] before they are +The generated and expected bindings are formatted with [`prettyplease`] before they are compared. It is a default (but optional) dependency of `bindgen`, so be sure to keep that in mind (if you built `bindgen` with the `--no-default-features` option of Cargo). @@ -118,14 +118,13 @@ Note: running `cargo test` from the root directory of `bindgen`'s repository doe automatically test the generated bindings or run the integration tests. These steps must be performed manually when needed. - ### Testing Bindings Generation To regenerate bindings from the corpus of test headers in `bindgen-tests/tests/headers` and compare them against the expected bindings in `bindgen-tests/tests/expectations/tests`, run: -``` -$ cargo test +```sh +cargo test ``` As long as you aren't making any changes to `bindgen`'s output, running this @@ -134,12 +133,12 @@ should be sufficient to test your local modifications. You may set the `BINDGEN_OVERWRITE_EXPECTED` environment variable to overwrite the expected bindings with `bindgen`'s current output: -``` -$ BINDGEN_OVERWRITE_EXPECTED=1 cargo test +```sh +BINDGEN_OVERWRITE_EXPECTED=1 cargo test ``` -If you set the BINDGEN_TESTS_DIFFTOOL environment variable, `cargo test` will -execute $BINDGEN_TESTS_DIFFTOOL /path/of/expected/output /path/of/actual/output +If you set the `BINDGEN_TESTS_DIFFTOOL` environment variable, `cargo test` will +execute `BINDGEN_TESTS_DIFFTOOL /path/of/expected/output /path/of/actual/output` when the expected output differs from the actual output. You can use this to hand check differences by setting it to e.g. "meld" (assuming you have meld installed). @@ -157,14 +156,14 @@ pass. Also, run the integration tests (see below). You can do this with these commands: -``` -$ cd bindgen-tests/tests/expectations -$ cargo test +```sh +cd bindgen-tests/tests/expectations +cargo test ``` ### Testing a Single Header's Bindings Generation and Compiling its Bindings -Note: You will need to install [Graphviz](https://graphviz.org/) since that +Note: You will need to install [graphviz](https://graphviz.org/) since that is a dependency for running `test-one.sh`. Sometimes it's useful to work with one test header from start (generating @@ -173,8 +172,8 @@ tests). This can be done with the `bindgen-tests/tests/test-one.sh` script. It s searching for test headers. For example, to test `tests/headers/what_is_going_on.hpp`, execute this command: -``` -$ ./bindgen-tests/tests/test-one.sh going +```sh +./bindgen-tests/tests/test-one.sh going ``` Note that `test-one.sh` does not recompile `bindgen`, so if you change the code, @@ -197,9 +196,9 @@ specify them at the top of the test header, with a comment like this: Then verify the new Rust bindings compile and pass their layout tests: -``` -$ cd bindgen-tests/tests/expectations -$ cargo test new_test_header +```sh +cd bindgen-tests/tests/expectations +cargo test new_test_header ``` ### Test Expectations and `libclang` Versions @@ -210,8 +209,8 @@ can add multiple test expectations, one for each supported `libclang` version. Instead of having a single `bindgen-tests/tests/expectations/tests/my_test.rs` file, add each of: -* `bindgen-tests/tests/expectations/tests/libclang-16/my_test.rs` -* `bindgen-tests/tests/expectations/tests/libclang-9/my_test.rs` +- `bindgen-tests/tests/expectations/tests/libclang-16/my_test.rs` +- `bindgen-tests/tests/expectations/tests/libclang-9/my_test.rs` If you need to update the test expectations for a test file that generates different bindings for different `libclang` versions, you *don't* need to have @@ -224,8 +223,8 @@ Usually, `bindgen`'s test runner can infer which version of `libclang` you have. If for some reason it can't, you can force a specific `libclang` version to check the bindings against with a cargo feature: -``` -$ cargo test --features __testing_only_libclang_$VERSION +```sh +cargo test --features __testing_only_libclang_$VERSION ``` depending on which version of `libclang` you have installed. @@ -238,9 +237,9 @@ values are what we expect them to be, both on the Rust and C++ side. To run the integration tests, issue the following: -``` -$ cd bindgen-integration -$ cargo test +```sh +cd bindgen-integration +cargo test ``` ### Fuzzing `bindgen` with `csmith` @@ -257,7 +256,7 @@ The `tests/quickchecking` crate generates property tests for `bindgen`. From the crate's directory you can run the tests with `cargo run`. For details on additional configuration including how to preserve / inspect the generated property tests, see -[./tests/quickchecking/README.md](./tests/quickchecking/README.md). +[`./tests/quickchecking/README.md`](./tests/quickchecking/README.md). ## Code Overview @@ -274,39 +273,39 @@ The umbrella IR type is the `Item`. It contains various nested `enum`s that let us drill down and get more specific about the kind of construct that we're looking at. Here is a summary of the IR types and their relationships: -* `Item` contains: - * An `ItemId` to uniquely identify it. - * An `ItemKind`, which is one of: - * A `Module`, which is originally a C++ namespace and becomes a Rust +- `Item` contains: + - An `ItemId` to uniquely identify it. + - An `ItemKind`, which is one of: + - A `Module`, which is originally a C++ namespace and becomes a Rust module. It contains the set of `ItemId`s of `Item`s that are defined within it. - * A `Type`, which contains: - * A `Layout`, describing the type's size and alignment. - * A `TypeKind`, which is one of: - * Some integer type. - * Some float type. - * A `Pointer` to another type. - * A function pointer type, with `ItemId`s of its parameter types + - A `Type`, which contains: + - A `Layout`, describing the type's size and alignment. + - A `TypeKind`, which is one of: + - Some integer type. + - Some float type. + - A `Pointer` to another type. + - A function pointer type, with `ItemId`s of its parameter types and return type. - * An `Alias` to another type (`typedef` or `using X = ...`). - * A fixed size `Array` of `n` elements of another type. - * A `Comp` compound type, which is either a `struct`, `class`, + - An `Alias` to another type (`typedef` or `using X = ...`). + - A fixed size `Array` of `n` elements of another type. + - A `Comp` compound type, which is either a `struct`, `class`, or `union`. This is potentially a template definition. - * A `TemplateInstantiation` referencing some template definition + - A `TemplateInstantiation` referencing some template definition and a set of template argument types. - * Etc... - * A `Function`, which contains: - * An ABI - * A mangled name - * a `FunctionKind`, which describes whether this function is a plain + - Etc... + - A `Function`, which contains: + - An ABI + - A mangled name + - a `FunctionKind`, which describes whether this function is a plain function, method, static method, constructor, destructor, etc. - * The `ItemId` of its function pointer type. - * A `Var` representing a static variable or `#define` constant, which + - The `ItemId` of its function pointer type. + - A `Var` representing a static variable or `#define` constant, which contains: - * Its type's `ItemId` - * Optionally, a mangled name - * Optionally, a value - * An optional `clang::SourceLocation` that holds the first source code + - Its type's `ItemId` + - Optionally, a mangled name + - Optionally, a value + - An optional `clang::SourceLocation` that holds the first source code location where the `Item` was encountered. The IR forms a graph of interconnected and inter-referencing types and @@ -323,8 +322,8 @@ parameters a given type uses. The analyses are defined in `ir::analysis::MonotoneFramework` trait. The final phase is generating Rust source text from the analyzed IR, and it is -defined in `src/codegen/*`. We use the `quote` crate, which provides the `quote! -{ ... }` macro for quasi-quoting Rust forms. Some options that affect the +defined in `src/codegen/*`. We use the `quote` crate, which provides the `quote!{ ... }` +macro for quasi-quoting Rust forms. Some options that affect the generated Rust code are implemented using the [`syn`](https://docs.rs/syn) crate. ### Implementing new options using `syn` @@ -351,13 +350,13 @@ changes should be squashed into the original commit. Unsure who to ask for review? Ask any of: -* `@emilio` -* `@pvdrz` +- `@emilio` +- `@pvdrz` More resources: -* [Servo's GitHub Workflow](https://github.com/servo/servo/wiki/Github-workflow) -* [Beginner's Guide to Rebasing and Squashing](https://github.com/servo/servo/wiki/Beginner's-guide-to-rebasing-and-squashing) +- [Servo's GitHub Workflow](https://github.com/servo/servo/wiki/Github-workflow) +- [Beginner's Guide to Rebasing and Squashing](https://github.com/servo/servo/wiki/Beginner's-guide-to-rebasing-and-squashing) ## Generating Graphviz Dot Files @@ -368,22 +367,22 @@ debugging bindgen! First, make sure you have Graphviz and `dot` installed: -``` -$ brew install graphviz # OS X -$ sudo dnf install graphviz # Fedora -$ # Etc... +```sh +brew install graphviz # OS X +sudo dnf install graphviz # Fedora +# Etc... ``` Then, use the `--emit-ir-graphviz` flag to generate a `dot` file from our IR: -``` -$ cargo run -- example.hpp --emit-ir-graphviz output.dot +```sh +cargo run -- example.hpp --emit-ir-graphviz output.dot ``` Finally, convert the `dot` file to an image: -``` -$ dot -Tpng output.dot -o output.png +```sh +dot -Tpng output.dot -o output.png ``` The final result will look something like this: @@ -395,14 +394,14 @@ The final result will look something like this: To help debug what `bindgen` is doing, you can define the environment variable `RUST_LOG=bindgen` to get a bunch of debugging log spew. -``` -$ RUST_LOG=bindgen ./target/debug/bindgen [flags...] ~/path/to/some/header.h +```sh +RUST_LOG=bindgen ./target/debug/bindgen [flags...] ~/path/to/some/header.h ``` This logging can also be used when debugging failing tests: -``` -$ RUST_LOG=bindgen cargo test +```sh +RUST_LOG=bindgen cargo test ``` ## Using `creduce` to Minimize Test Cases @@ -419,10 +418,10 @@ that same bad behavior. Often, you can install `creduce` from your OS's package manager: -``` -$ sudo apt install creduce -$ brew install creduce -$ # Etc... +```sh +sudo apt install creduce +brew install creduce +# Etc... ``` Otherwise, follow [these instructions](https://github.com/csmith-project/creduce/blob/master/INSTALL.md) for building and/or installing `creduce`. @@ -436,7 +435,9 @@ Running `creduce` requires two things: With those two things in hand, running `creduce` looks like this: - $ creduce ./predicate.sh ./isolated-test-case.h +```sh +creduce ./predicate.sh ./isolated-test-case.h +``` ### Isolating Your Test Case @@ -511,8 +512,8 @@ path/to/rust-bindgen/csmith-fuzzing/predicate.py \ For details on all the flags that you can pass to `predicate.py`, run: -``` -$ path/to/rust-bindgen/csmith-fuzzing/predicate.py --help +```sh +path/to/rust-bindgen/csmith-fuzzing/predicate.py --help ``` And you can always write your own, arbitrary predicate script if you prefer. @@ -535,9 +536,9 @@ To cut a release, the following needs to happen: Update the CHANGELOG.md file with the changes from the last release. Something like the following is a useful way to check what has landed: - ``` - $ git log --oneline v0.62.0..HEAD - ``` +```sh +git log --oneline v0.62.0..HEAD +``` Also worth checking the [next-release tag](https://github.com/rust-lang/rust-bindgen/pulls?q=is%3Apr+label%3Anext-release). @@ -554,12 +555,14 @@ important fix) you can skip this. ### Tag and publish Once you're in `main`. Remember to install `doctoc` by running: -``` + +```sh npm install doctoc ``` And then run: -``` + +```sh cargo release [patch|minor] --no-publish --execute ``` @@ -573,8 +576,8 @@ This does the following: The `patch` and `minor` refer to semver concepts: -- `patch` would bump __v0.68.1__ to __v0.68.2__ -- `minor` would bump __v0.68.2__ to __v0.69.0__ +- `patch` would bump **v0.68.1** to **v0.68.2** +- `minor` would bump **v0.68.2** to **v0.69.0** > NOTE: > We use the `--no-publish` so that the crates are only published after the release is complete. @@ -595,12 +598,12 @@ to avoid notifying watchers of the repo should a CI step fail. If everything succeeds, tarballs containing bindgen cli executables for Linux and MacOS (both for x86 and Arm) will be created. -See `[workspace.metadata.dist]` section in Cargo.toml for the configuration. +See `[workspace.metadata.dist]` section in `Cargo.toml` for the configuration. To update the release configuration, -when a new cargo-dist is available: +when a new `cargo-dist` is available: -``` +```sh cargo dist init # from "cargo install cargo-dist" ``` @@ -620,4 +623,4 @@ and run a new workflow using the "Run Workflow" button. Remember that crates.io releases cannot be deleted! -[prettyplease]: https://github.com/dtolnay/prettyplease +[`prettyplease`]: https://github.com/dtolnay/prettyplease From 16cdd2ab2ae44268d43cc5bbc7ff9dcdbb2dcff4 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Tue, 19 Nov 2024 21:21:02 -0500 Subject: [PATCH 754/942] delete duplicated default logic for `--anon-fields-prefix` --- bindgen/options/cli.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bindgen/options/cli.rs b/bindgen/options/cli.rs index 1f51b3bece..40e8936ec3 100644 --- a/bindgen/options/cli.rs +++ b/bindgen/options/cli.rs @@ -7,7 +7,7 @@ use crate::{ regex_set::RegexSet, Abi, AliasVariation, Builder, CodegenConfig, EnumVariation, FieldVisibilityKind, Formatter, MacroTypeVariation, NonCopyUnionStyle, - RustTarget, DEFAULT_ANON_FIELDS_PREFIX, + RustTarget, }; use clap::{ error::{Error, ErrorKind}, @@ -272,8 +272,8 @@ struct BindgenCommand { #[arg(long, value_name = "PREFIX")] ctypes_prefix: Option, /// Use the given PREFIX for anonymous fields. - #[arg(long, default_value = DEFAULT_ANON_FIELDS_PREFIX, value_name = "PREFIX")] - anon_fields_prefix: String, + #[arg(long, value_name = "PREFIX")] + anon_fields_prefix: Option, /// Time the different bindgen phases and print to stderr #[arg(long)] time_phases: bool, @@ -848,7 +848,9 @@ where builder = builder.ctypes_prefix(prefix); } - builder = builder.anon_fields_prefix(anon_fields_prefix); + if let Some(prefix) = anon_fields_prefix { + builder = builder.anon_fields_prefix(prefix); + } if let Some(config) = generate { builder = builder.with_codegen_config(config); From c2d193d6d7af5a4b17bc8a94edcd412637f45daf Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Tue, 19 Nov 2024 21:39:23 -0500 Subject: [PATCH 755/942] abstract away the control-flow for applying args --- bindgen/options/cli.rs | 778 ++++++++++++++++------------------------- 1 file changed, 292 insertions(+), 486 deletions(-) diff --git a/bindgen/options/cli.rs b/bindgen/options/cli.rs index 40e8936ec3..86edd50455 100644 --- a/bindgen/options/cli.rs +++ b/bindgen/options/cli.rs @@ -679,262 +679,258 @@ where return Err(io::Error::new(io::ErrorKind::Other, "Header not found")); } - if let Some(rust_target) = rust_target { - builder = builder.rust_target(rust_target); - } - - if let Some(variant) = default_enum_style { - builder = builder.default_enum_style(variant); - } - - for regex in bitfield_enum { - builder = builder.bitfield_enum(regex); - } - - for regex in newtype_enum { - builder = builder.newtype_enum(regex); - } - - for regex in newtype_global_enum { - builder = builder.newtype_global_enum(regex); - } - - for regex in rustified_enum { - builder = builder.rustified_enum(regex); - } - - for regex in rustified_non_exhaustive_enum { - builder = builder.rustified_non_exhaustive_enum(regex); - } - - for regex in constified_enum { - builder = builder.constified_enum(regex); - } - - for regex in constified_enum_module { - builder = builder.constified_enum_module(regex); - } - - if let Some(default_macro_constant_type) = default_macro_constant_type { - builder = - builder.default_macro_constant_type(default_macro_constant_type) - } - - if let Some(variant) = default_alias_style { - builder = builder.default_alias_style(variant); - } - - for regex in normal_alias { - builder = builder.type_alias(regex); - } - - for regex in new_type_alias { - builder = builder.new_type_alias(regex); - } - - for regex in new_type_alias_deref { - builder = builder.new_type_alias_deref(regex); - } - - if let Some(variant) = default_non_copy_union_style { - builder = builder.default_non_copy_union_style(variant); - } - - for regex in bindgen_wrapper_union { - builder = builder.bindgen_wrapper_union(regex); - } - - for regex in manually_drop_union { - builder = builder.manually_drop_union(regex); - } - - for ty in blocklist_type { - builder = builder.blocklist_type(ty); - } - - for fun in blocklist_function { - builder = builder.blocklist_function(fun); - } - - for id in blocklist_item { - builder = builder.blocklist_item(id); - } - - for file in blocklist_file { - builder = builder.blocklist_file(file); - } - - for var in blocklist_var { - builder = builder.blocklist_var(var); - } - - if builtins { - builder = builder.emit_builtins(); - } - - if no_layout_tests { - builder = builder.layout_tests(false); - } - - if no_derive_copy { - builder = builder.derive_copy(false); - } - - if no_derive_debug { - builder = builder.derive_debug(false); - } - - if impl_debug { - builder = builder.impl_debug(true); - } - - if impl_partialeq { - builder = builder.impl_partialeq(true); - } - - if with_derive_default { - builder = builder.derive_default(true); - } - - if with_derive_hash { - builder = builder.derive_hash(true); - } - - if with_derive_partialeq { - builder = builder.derive_partialeq(true); - } - - if with_derive_partialord { - builder = builder.derive_partialord(true); - } - - if with_derive_eq { - builder = builder.derive_eq(true); - } - - if with_derive_ord { - builder = builder.derive_ord(true); - } - - if no_derive_default { - builder = builder.derive_default(false); - } - - if no_prepend_enum_name { - builder = builder.prepend_enum_name(false); - } - - if no_include_path_detection { - builder = builder.detect_include_paths(false); - } - - if fit_macro_constant_types { - builder = builder.fit_macro_constants(true); - } - - if time_phases { - builder = builder.time_phases(true); - } - - if use_array_pointers_in_arguments { - builder = builder.array_pointers_in_arguments(true); - } - - if let Some(wasm_import_name) = wasm_import_module_name { - builder = builder.wasm_import_module_name(wasm_import_name); - } - - if let Some(prefix) = ctypes_prefix { - builder = builder.ctypes_prefix(prefix); - } - - if let Some(prefix) = anon_fields_prefix { - builder = builder.anon_fields_prefix(prefix); - } - - if let Some(config) = generate { - builder = builder.with_codegen_config(config); - } - - if emit_clang_ast { - builder = builder.emit_clang_ast(); - } - - if emit_ir { - builder = builder.emit_ir(); - } - - if let Some(path) = emit_ir_graphviz { - builder = builder.emit_ir_graphviz(path); - } - - if enable_cxx_namespaces { - builder = builder.enable_cxx_namespaces(); + #[derive(Debug)] + struct PrefixLinkNameCallback { + prefix: String, + } + + impl ParseCallbacks for PrefixLinkNameCallback { + fn generated_link_name_override( + &self, + item_info: ItemInfo<'_>, + ) -> Option { + let mut prefix = self.prefix.clone(); + prefix.push_str(item_info.name); + Some(prefix) + } } - if enable_function_attribute_detection { - builder = builder.enable_function_attribute_detection(); + #[derive(Debug)] + struct CustomDeriveCallback { + derives: Vec, + kind: Option, + regex_set: RegexSet, } - if disable_name_namespacing { - builder = builder.disable_name_namespacing(); - } + impl ParseCallbacks for CustomDeriveCallback { + fn cli_args(&self) -> Vec { + let mut args = vec![]; - if disable_nested_struct_naming { - builder = builder.disable_nested_struct_naming(); - } + let flag = match &self.kind { + None => "--with-derive-custom", + Some(TypeKind::Struct) => "--with-derive-custom-struct", + Some(TypeKind::Enum) => "--with-derive-custom-enum", + Some(TypeKind::Union) => "--with-derive-custom-union", + }; - if disable_untagged_union { - builder = builder.disable_untagged_union(); - } + let derives = self.derives.join(","); - if disable_header_comment { - builder = builder.disable_header_comment(); - } + for item in self.regex_set.get_items() { + args.extend_from_slice(&[ + flag.to_owned(), + format!("{}={}", item, derives), + ]); + } - if ignore_functions { - builder = builder.ignore_functions(); - } + args + } - if ignore_methods { - builder = builder.ignore_methods(); + fn add_derives(&self, info: &DeriveInfo<'_>) -> Vec { + if self.kind.map(|kind| kind == info.kind).unwrap_or(true) && + self.regex_set.matches(info.name) + { + return self.derives.clone(); + } + vec![] + } } - if no_convert_floats { - builder = builder.no_convert_floats(); + #[derive(Debug)] + struct CustomAttributeCallback { + attributes: Vec, + kind: Option, + regex_set: RegexSet, } - if no_doc_comments { - builder = builder.generate_comments(false); - } + impl ParseCallbacks for CustomAttributeCallback { + fn cli_args(&self) -> Vec { + let mut args = vec![]; - if no_recursive_allowlist { - builder = builder.allowlist_recursively(false); - } + let flag = match &self.kind { + None => "--with-attribute-custom", + Some(TypeKind::Struct) => "--with-attribute-custom-struct", + Some(TypeKind::Enum) => "--with-attribute-custom-enum", + Some(TypeKind::Union) => "--with-attribute-custom-union", + }; - if objc_extern_crate { - builder = builder.objc_extern_crate(true); - } + let attributes = self.attributes.join(","); - if generate_block { - builder = builder.generate_block(true); - } + for item in self.regex_set.get_items() { + args.extend_from_slice(&[ + flag.to_owned(), + format!("{}={}", item, attributes), + ]); + } - if generate_cstr { - builder = builder.generate_cstr(true); - } + args + } - if block_extern_crate { - builder = builder.block_extern_crate(true); + fn add_attributes(&self, info: &AttributeInfo<'_>) -> Vec { + if self.kind.map(|kind| kind == info.kind).unwrap_or(true) && + self.regex_set.matches(info.name) + { + return self.attributes.clone(); + } + vec![] + } } - for ty in opaque_type { - builder = builder.opaque_type(ty); + /// Macro used to apply CLI arguments to a builder. + /// + /// This is done by passing an identifier for each argument and a function to be applied over + /// the builder. For example: + /// ```rust,ignore + /// fn apply_arg(builder: Builder, arg_value: Value) -> Builder { + /// todo!() + /// } + /// + /// apply_args!( + /// builder { + /// arg => apply_arg, + /// } + /// ); + /// ``` + /// + /// If the identifier of the argument is the same as an already existing builder method then + /// you can omit the second part: + /// ```rust,ignore + /// apply_args!( + /// builder { + /// arg + /// } + /// ); + /// ``` + /// Which expands to the same code as: + /// ```rust,ignore + /// apply_args!( + /// builder { + /// arg => Builder::arg, + /// } + /// ); + /// ``` + macro_rules! apply_args { + ($builder:ident {}) => { $builder }; + ($builder:ident {$arg:ident => $function:expr, $($token:tt)*}) => { + { + $builder = CliArg::apply($arg, $builder, $function); + apply_args!($builder {$($token)*}) + } + }; + ($builder:ident {$arg:ident, $($token:tt)*}) => { + { + $builder = CliArg::apply($arg, $builder, Builder::$arg); + apply_args!($builder {$($token)*}) + } + } } - for line in raw_line { - builder = builder.raw_line(line); - } + builder = apply_args!( + builder { + rust_target, + default_enum_style, + bitfield_enum, + newtype_enum, + newtype_global_enum, + rustified_enum, + rustified_non_exhaustive_enum, + constified_enum, + constified_enum_module, + default_macro_constant_type, + default_alias_style, + normal_alias => Builder::type_alias, + new_type_alias, + new_type_alias_deref, + default_non_copy_union_style, + bindgen_wrapper_union, + manually_drop_union, + blocklist_type, + blocklist_function, + blocklist_item, + blocklist_file, + blocklist_var, + builtins => |b, _| b.emit_builtins(), + no_layout_tests => |b, _| b.layout_tests(false), + no_derive_copy => |b, _| b.derive_copy(false), + no_derive_debug => |b, _| b.derive_debug(false), + impl_debug, + impl_partialeq, + with_derive_default => Builder::derive_default, + with_derive_hash => Builder::derive_hash, + with_derive_partialeq => Builder::derive_partialeq, + with_derive_partialord => Builder::derive_partialord, + with_derive_eq => Builder::derive_eq, + with_derive_ord => Builder::derive_ord, + no_derive_default => |b, _| b.derive_default(false), + no_prepend_enum_name => |b, _| b.prepend_enum_name(false), + no_include_path_detection => |b, _| b.detect_include_paths(false), + fit_macro_constant_types => Builder::fit_macro_constants, + time_phases, + use_array_pointers_in_arguments => Builder::array_pointers_in_arguments, + wasm_import_module_name, + ctypes_prefix, + anon_fields_prefix, + generate => Builder::with_codegen_config, + emit_clang_ast => |b, _| b.emit_clang_ast(), + emit_ir => |b, _| b.emit_ir(), + emit_ir_graphviz, + enable_cxx_namespaces => |b, _| b.enable_cxx_namespaces(), + enable_function_attribute_detection => |b, _| b.enable_function_attribute_detection(), + disable_name_namespacing => |b, _| b.disable_name_namespacing(), + disable_nested_struct_naming => |b, _| b.disable_nested_struct_naming(), + disable_untagged_union => |b, _| b.disable_untagged_union(), + disable_header_comment => |b, _| b.disable_header_comment(), + ignore_functions => |b, _| b.ignore_functions(), + ignore_methods => |b, _| b.ignore_methods(), + no_convert_floats => |b, _| b.no_convert_floats(), + no_doc_comments => |b, _| b.generate_comments(false), + no_recursive_allowlist => |b, _| b.allowlist_recursively(false), + objc_extern_crate, + generate_block, + generate_cstr, + block_extern_crate, + opaque_type, + raw_line, + use_core => |b, _| b.use_core(), + distrust_clang_mangling => |b, _| b.trust_clang_mangling(false), + conservative_inline_namespaces => |b, _| b.conservative_inline_namespaces(), + generate_inline_functions, + allowlist_function, + allowlist_type, + allowlist_var, + allowlist_file, + allowlist_item, + clang_args => Builder::clang_arg, + no_record_matches => |b, _| b.record_matches(false), + no_size_t_is_usize => |b, _| b.size_t_is_usize(false), + no_rustfmt_bindings => |b, _| b.formatter(Formatter::None), + formatter, + no_partialeq, + no_copy, + no_debug, + no_default, + no_hash, + must_use_type, + dynamic_loading => Builder::dynamic_library_name, + dynamic_link_require_all, + prefix_link_name => |b, prefix| b.parse_callbacks(Box::new(PrefixLinkNameCallback { prefix })), + respect_cxx_access_specs, + translate_enum_integer_types, + c_naming, + explicit_padding, + vtable_generation, + sort_semantically, + merge_extern_blocks, + override_abi => |b, (abi, regex)| b.override_abi(abi, regex), + wrap_unsafe_ops, + clang_macro_fallback => |b, _| b.clang_macro_fallback(), + clang_macro_fallback_build_dir, + flexarray_dst, + wrap_static_fns, + wrap_static_fns_path, + wrap_static_fns_suffix, + default_visibility, + } + ); let mut values = module_raw_line.into_iter(); while let Some(module) = values.next() { @@ -942,46 +938,6 @@ where builder = builder.module_raw_line(module, line); } - if use_core { - builder = builder.use_core(); - } - - if distrust_clang_mangling { - builder = builder.trust_clang_mangling(false); - } - - if conservative_inline_namespaces { - builder = builder.conservative_inline_namespaces(); - } - - if generate_inline_functions { - builder = builder.generate_inline_functions(true); - } - - for regex in allowlist_function { - builder = builder.allowlist_function(regex); - } - - for regex in allowlist_type { - builder = builder.allowlist_type(regex); - } - - for regex in allowlist_var { - builder = builder.allowlist_var(regex); - } - - for file in allowlist_file { - builder = builder.allowlist_file(file); - } - - for item in allowlist_item { - builder = builder.allowlist_item(item); - } - - for arg in clang_args { - builder = builder.clang_arg(arg); - } - let output = if let Some(path) = &output { let file = File::create(path)?; if let Some(depfile) = depfile { @@ -999,168 +955,10 @@ where builder.dump_preprocessed_input()?; } - if no_record_matches { - builder = builder.record_matches(false); - } - - if no_size_t_is_usize { - builder = builder.size_t_is_usize(false); - } - - if no_rustfmt_bindings { - builder = builder.formatter(Formatter::None); - } - - if let Some(formatter) = formatter { - builder = builder.formatter(formatter); - } - if let Some(path) = rustfmt_configuration_file { builder = builder.rustfmt_configuration_file(Some(path)); } - for regex in no_partialeq { - builder = builder.no_partialeq(regex); - } - - for regex in no_copy { - builder = builder.no_copy(regex); - } - - for regex in no_debug { - builder = builder.no_debug(regex); - } - - for regex in no_default { - builder = builder.no_default(regex); - } - - for regex in no_hash { - builder = builder.no_hash(regex); - } - - for regex in must_use_type { - builder = builder.must_use_type(regex); - } - - if let Some(dynamic_library_name) = dynamic_loading { - builder = builder.dynamic_library_name(dynamic_library_name); - } - - if dynamic_link_require_all { - builder = builder.dynamic_link_require_all(true); - } - - if let Some(prefix_link_name) = prefix_link_name { - #[derive(Debug)] - struct PrefixLinkNameCallback { - prefix: String, - } - - impl ParseCallbacks for PrefixLinkNameCallback { - fn generated_link_name_override( - &self, - item_info: ItemInfo<'_>, - ) -> Option { - let mut prefix = self.prefix.clone(); - prefix.push_str(item_info.name); - Some(prefix) - } - } - - builder = builder.parse_callbacks(Box::new(PrefixLinkNameCallback { - prefix: prefix_link_name, - })) - } - - if respect_cxx_access_specs { - builder = builder.respect_cxx_access_specs(true); - } - - if translate_enum_integer_types { - builder = builder.translate_enum_integer_types(true); - } - - if c_naming { - builder = builder.c_naming(true); - } - - if explicit_padding { - builder = builder.explicit_padding(true); - } - - if vtable_generation { - builder = builder.vtable_generation(true); - } - - if sort_semantically { - builder = builder.sort_semantically(true); - } - - if merge_extern_blocks { - builder = builder.merge_extern_blocks(true); - } - - for (abi, regex) in override_abi { - builder = builder.override_abi(abi, regex); - } - - if wrap_unsafe_ops { - builder = builder.wrap_unsafe_ops(true); - } - - if clang_macro_fallback { - builder = builder.clang_macro_fallback(); - } - - if let Some(path) = clang_macro_fallback_build_dir { - builder = builder.clang_macro_fallback_build_dir(path); - } - - if flexarray_dst { - builder = builder.flexarray_dst(true); - } - - #[derive(Debug)] - struct CustomDeriveCallback { - derives: Vec, - kind: Option, - regex_set: RegexSet, - } - - impl ParseCallbacks for CustomDeriveCallback { - fn cli_args(&self) -> Vec { - let mut args = vec![]; - - let flag = match &self.kind { - None => "--with-derive-custom", - Some(TypeKind::Struct) => "--with-derive-custom-struct", - Some(TypeKind::Enum) => "--with-derive-custom-enum", - Some(TypeKind::Union) => "--with-derive-custom-union", - }; - - let derives = self.derives.join(","); - - for item in self.regex_set.get_items() { - args.extend_from_slice(&[ - flag.to_owned(), - format!("{}={}", item, derives), - ]); - } - - args - } - - fn add_derives(&self, info: &DeriveInfo<'_>) -> Vec { - if self.kind.map(|kind| kind == info.kind).unwrap_or(true) && - self.regex_set.matches(info.name) - { - return self.derives.clone(); - } - vec![] - } - } - for (custom_derives, kind, _name) in [ (with_derive_custom, None, "--with-derive-custom"), ( @@ -1199,46 +997,6 @@ where } } - #[derive(Debug)] - struct CustomAttributeCallback { - attributes: Vec, - kind: Option, - regex_set: RegexSet, - } - - impl ParseCallbacks for CustomAttributeCallback { - fn cli_args(&self) -> Vec { - let mut args = vec![]; - - let flag = match &self.kind { - None => "--with-attribute-custom", - Some(TypeKind::Struct) => "--with-attribute-custom-struct", - Some(TypeKind::Enum) => "--with-attribute-custom-enum", - Some(TypeKind::Union) => "--with-attribute-custom-union", - }; - - let attributes = self.attributes.join(","); - - for item in self.regex_set.get_items() { - args.extend_from_slice(&[ - flag.to_owned(), - format!("{}={}", item, attributes), - ]); - } - - args - } - - fn add_attributes(&self, info: &AttributeInfo<'_>) -> Vec { - if self.kind.map(|kind| kind == info.kind).unwrap_or(true) && - self.regex_set.matches(info.name) - { - return self.attributes.clone(); - } - vec![] - } - } - for (custom_attributes, kind, _name) in [ (with_attribute_custom, None, "--with-attribute-custom"), ( @@ -1278,26 +1036,74 @@ where } } - if wrap_static_fns { - builder = builder.wrap_static_fns(true); + #[cfg(feature = "experimental")] + if emit_diagnostics { + builder = builder.emit_diagnostics(); } - if let Some(path) = wrap_static_fns_path { - builder = builder.wrap_static_fns_path(path); - } + Ok((builder, output, verbose)) +} - if let Some(suffix) = wrap_static_fns_suffix { - builder = builder.wrap_static_fns_suffix(suffix); - } +/// Trait for CLI arguments that can be applied to a [`Builder`]. +trait CliArg { + /// The value of this argument. + type Value; + + /// Apply the current argument to the passed [`Builder`]. + fn apply( + self, + builder: Builder, + f: impl Fn(Builder, Self::Value) -> Builder, + ) -> Builder; +} - if let Some(visibility) = default_visibility { - builder = builder.default_visibility(visibility); +/// Boolean arguments are applied when they evaluate to `true`. +impl CliArg for bool { + type Value = bool; + + fn apply( + self, + mut builder: Builder, + f: impl Fn(Builder, Self::Value) -> Builder, + ) -> Builder { + if self { + builder = f(builder, self) + } + + builder } +} - #[cfg(feature = "experimental")] - if emit_diagnostics { - builder = builder.emit_diagnostics(); +/// Optional arguments are applied when they are `Some`. +impl CliArg for Option { + type Value = T; + + fn apply( + self, + mut builder: Builder, + f: impl Fn(Builder, Self::Value) -> Builder, + ) -> Builder { + if let Some(value) = self { + builder = f(builder, value); + } + + builder } +} - Ok((builder, output, verbose)) +/// Multiple valued arguments are applied once for each value. +impl CliArg for Vec { + type Value = T; + + fn apply( + self, + mut builder: Builder, + f: impl Fn(Builder, Self::Value) -> Builder, + ) -> Builder { + for value in self { + builder = f(builder, value); + } + + builder + } } From 4d809171a7acb034ce7e3c6cd585936eaf72b927 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Thu, 21 Nov 2024 15:16:17 -0500 Subject: [PATCH 756/942] Let clap handle missing headers --- bindgen/options/cli.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/bindgen/options/cli.rs b/bindgen/options/cli.rs index 86edd50455..0dc7fc0aa7 100644 --- a/bindgen/options/cli.rs +++ b/bindgen/options/cli.rs @@ -141,7 +141,7 @@ fn parse_custom_attribute( )] struct BindgenCommand { /// C or C++ header file. - header: Option, + header: String, /// Path to write depfile to. #[arg(long)] depfile: Option, @@ -673,12 +673,6 @@ where let mut builder = builder(); - if let Some(header) = header { - builder = builder.header(header); - } else { - return Err(io::Error::new(io::ErrorKind::Other, "Header not found")); - } - #[derive(Debug)] struct PrefixLinkNameCallback { prefix: String, @@ -824,8 +818,11 @@ where } } + let header = Some(header); + builder = apply_args!( builder { + header, rust_target, default_enum_style, bitfield_enum, From 713dbdab8a588f107936bd3e8d83288130d4b498 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Thu, 21 Nov 2024 15:35:00 -0500 Subject: [PATCH 757/942] Handle version and shell completions --- bindgen/options/cli.rs | 46 ++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/bindgen/options/cli.rs b/bindgen/options/cli.rs index 0dc7fc0aa7..747ff2d5e0 100644 --- a/bindgen/options/cli.rs +++ b/bindgen/options/cli.rs @@ -14,11 +14,10 @@ use clap::{ CommandFactory, Parser, }; use proc_macro2::TokenStream; -use std::fs::File; use std::io; use std::path::{Path, PathBuf}; -use std::process::exit; use std::str::FromStr; +use std::{fs::File, process::exit}; fn rust_target_help() -> String { format!( @@ -649,28 +648,6 @@ where clang_args, } = command; - if let Some(shell) = generate_shell_completions { - clap_complete::generate( - shell, - &mut BindgenCommand::command(), - "bindgen", - &mut std::io::stdout(), - ); - - exit(0); - } - - if version { - println!( - "bindgen {}", - option_env!("CARGO_PKG_VERSION").unwrap_or("unknown") - ); - if verbose { - println!("Clang: {}", crate::clang_version().full); - } - std::process::exit(0); - } - let mut builder = builder(); #[derive(Debug)] @@ -822,6 +799,27 @@ where builder = apply_args!( builder { + generate_shell_completions => |_, shell| { + clap_complete::generate( + shell, + &mut BindgenCommand::command(), + "bindgen", + &mut std::io::stdout(), + ); + + exit(0) + }, + version => |_, _| { + println!( + "bindgen {}", + option_env!("CARGO_PKG_VERSION").unwrap_or("unknown") + ); + if verbose { + println!("Clang: {}", crate::clang_version().full); + } + + exit(0) + }, header, rust_target, default_enum_style, From 33006185b7878e0a8b96a44cb64c5ef705bdc66b Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Fri, 22 Nov 2024 16:38:04 -0500 Subject: [PATCH 758/942] Add `raw_ref_macros` feature --- .../tests/derive-bitfield-method-same-name.rs | 83 ---- .../tests/derive-debug-bitfield-1-51.rs | 266 ++++++++++++ .../tests/derive-debug-bitfield-core.rs | 104 ----- .../tests/derive-debug-bitfield.rs | 102 ----- .../tests/derive-partialeq-bitfield.rs | 102 ----- .../tests/jsval_layout_opaque_1_0.rs | 104 ----- .../expectations/tests/layout_eth_conf.rs | 351 ---------------- .../expectations/tests/layout_eth_conf_1_0.rs | 351 ---------------- .../expectations/tests/layout_mbuf_1_0.rs | 379 ------------------ .../expectations/tests/union_bitfield_1_0.rs | 138 ------- .../union_with_anon_struct_bitfield_1_0.rs | 104 ----- .../headers/derive-debug-bitfield-1-51.hpp | 7 + bindgen/codegen/bitfield_unit.rs | 77 ---- .../codegen/bitfield_unit_raw_ref_macros.rs | 189 +++++++++ bindgen/codegen/mod.rs | 57 ++- bindgen/features.rs | 1 + 16 files changed, 498 insertions(+), 1917 deletions(-) create mode 100644 bindgen-tests/tests/expectations/tests/derive-debug-bitfield-1-51.rs create mode 100644 bindgen-tests/tests/headers/derive-debug-bitfield-1-51.hpp create mode 100644 bindgen/codegen/bitfield_unit_raw_ref_macros.rs 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 88b9ceaa24..c8f19bc5af 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,14 +32,6 @@ 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 = *(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) @@ -57,14 +49,6 @@ 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); - *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()); @@ -85,26 +69,6 @@ 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 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()); @@ -122,24 +86,6 @@ 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 - }; - 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, @@ -219,35 +165,6 @@ 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-debug-bitfield-1-51.rs b/bindgen-tests/tests/expectations/tests/derive-debug-bitfield-1-51.rs new file mode 100644 index 0000000000..fa007056a1 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/derive-debug-bitfield-1-51.rs @@ -0,0 +1,266 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[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 = *(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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize); + *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 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 + }; + Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + } + } +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct C { + pub _bitfield_align_1: [u8; 0], + 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", + ); +} +impl Default for C { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +impl C { + #[inline] + pub fn a(&self) -> bool { + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) } + } + #[inline] + pub fn set_a(&mut self, val: bool) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + self._bitfield_1.set(0usize, 1u8, val as u64) + } + } + #[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) } + } + #[inline] + pub fn set_b(&mut self, val: bool) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + self._bitfield_1.set(1usize, 7u8, val as u64) + } + } + #[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 + .set( + 0usize, + 1u8, + { + let a: u8 = unsafe { ::std::mem::transmute(a) }; + a as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 1usize, + 7u8, + { + let b: u8 = unsafe { ::std::mem::transmute(b) }; + b as u64 + }, + ); + __bindgen_bitfield_unit + } +} 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 e88d1d6d38..edcb4e2a02 100644 --- a/bindgen-tests/tests/expectations/tests/derive-debug-bitfield-core.rs +++ b/bindgen-tests/tests/expectations/tests/derive-debug-bitfield-core.rs @@ -33,14 +33,6 @@ 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 = *(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) @@ -58,14 +50,6 @@ 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); - *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()); @@ -86,26 +70,6 @@ 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 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()); @@ -123,24 +87,6 @@ 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 - }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); - } - } } #[repr(C)] #[derive(Copy, Clone)] @@ -188,31 +134,6 @@ 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) } } @@ -224,31 +145,6 @@ 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 09ca288b07..20c7cf0c88 100644 --- a/bindgen-tests/tests/expectations/tests/derive-debug-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/derive-debug-bitfield.rs @@ -32,14 +32,6 @@ 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 = *(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) @@ -57,14 +49,6 @@ 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); - *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()); @@ -85,26 +69,6 @@ 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 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()); @@ -122,24 +86,6 @@ 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 - }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); - } - } } #[repr(C)] #[derive(Copy, Clone)] @@ -198,30 +144,6 @@ 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) } } @@ -233,30 +155,6 @@ 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-bitfield.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-bitfield.rs index b27a9bb32d..eaf3f45e5f 100644 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/derive-partialeq-bitfield.rs @@ -32,14 +32,6 @@ 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 = *(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) @@ -57,14 +49,6 @@ 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); - *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()); @@ -85,26 +69,6 @@ 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 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()); @@ -122,24 +86,6 @@ 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 - }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); - } - } } #[repr(C)] #[derive(Copy, Clone)] @@ -188,30 +134,6 @@ 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) } } @@ -223,30 +145,6 @@ 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/jsval_layout_opaque_1_0.rs b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs index 5da0e7995f..422782d66d 100644 --- a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs @@ -32,14 +32,6 @@ 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 = *(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) @@ -57,14 +49,6 @@ 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); - *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()); @@ -85,26 +69,6 @@ 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 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()); @@ -122,24 +86,6 @@ 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 - }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); - } - } } #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); @@ -328,31 +274,6 @@ impl jsval_layout__bindgen_ty_1 { } } #[inline] - pub unsafe fn payload47_raw(this: *const Self) -> u64 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 8usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 47u8) - as u64, - ) - } - } - #[inline] - pub unsafe fn set_payload47_raw(this: *mut Self, val: u64) { - unsafe { - let val: u64 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 8usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 0usize, - 47u8, - val as u64, - ) - } - } - #[inline] pub fn tag(&self) -> JSValueTag { unsafe { ::std::mem::transmute(self._bitfield_1.get(47usize, 17u8) as u32) } } @@ -364,31 +285,6 @@ impl jsval_layout__bindgen_ty_1 { } } #[inline] - pub unsafe fn tag_raw(this: *const Self) -> JSValueTag { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 8usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 47usize, 17u8) - as u32, - ) - } - } - #[inline] - pub unsafe fn set_tag_raw(this: *mut Self, val: JSValueTag) { - unsafe { - let val: u32 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 8usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 47usize, - 17u8, - val as u64, - ) - } - } - #[inline] pub fn new_bitfield_1( payload47: u64, tag: JSValueTag, diff --git a/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs b/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs index d9d30e1d88..4a62ddbea3 100644 --- a/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs +++ b/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs @@ -32,14 +32,6 @@ 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 = *(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) @@ -57,14 +49,6 @@ 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); - *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()); @@ -85,26 +69,6 @@ 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 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()); @@ -122,24 +86,6 @@ 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 - }; - 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; @@ -260,31 +206,6 @@ 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) } } @@ -296,31 +217,6 @@ 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) } } @@ -332,31 +228,6 @@ 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) } } @@ -368,31 +239,6 @@ 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) } } @@ -404,31 +250,6 @@ 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) } } @@ -440,31 +261,6 @@ 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) } } @@ -476,31 +272,6 @@ 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) } } @@ -512,31 +283,6 @@ 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) } } @@ -548,31 +294,6 @@ 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, @@ -755,30 +476,6 @@ 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) } } @@ -790,30 +487,6 @@ 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) } } @@ -825,30 +498,6 @@ 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, diff --git a/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs b/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs index c5ccdd0959..6cbeb042aa 100644 --- a/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs @@ -32,14 +32,6 @@ 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 = *(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) @@ -57,14 +49,6 @@ 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); - *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()); @@ -85,26 +69,6 @@ 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 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()); @@ -122,24 +86,6 @@ 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 - }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); - } - } } #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); @@ -308,31 +254,6 @@ 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) } } @@ -344,31 +265,6 @@ 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) } } @@ -380,31 +276,6 @@ 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) } } @@ -416,31 +287,6 @@ 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) } } @@ -452,31 +298,6 @@ 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) } } @@ -488,31 +309,6 @@ 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) } } @@ -524,31 +320,6 @@ 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) } } @@ -560,31 +331,6 @@ 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) } } @@ -596,31 +342,6 @@ 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, @@ -808,30 +529,6 @@ 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) } } @@ -843,30 +540,6 @@ 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) } } @@ -878,30 +551,6 @@ 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, diff --git a/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs b/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs index db4f078aad..38e221f3ca 100644 --- a/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs @@ -32,14 +32,6 @@ 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 = *(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) @@ -57,14 +49,6 @@ 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); - *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()); @@ -85,26 +69,6 @@ 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 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()); @@ -122,24 +86,6 @@ 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 - }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); - } - } } #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); @@ -360,31 +306,6 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } } #[inline] - pub unsafe fn l2_type_raw(this: *const Self) -> u32 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 4usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 4u8) - as u32, - ) - } - } - #[inline] - pub unsafe fn set_l2_type_raw(this: *mut Self, val: u32) { - unsafe { - let val: u32 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 4usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 0usize, - 4u8, - val as u64, - ) - } - } - #[inline] pub fn l3_type(&self) -> u32 { unsafe { ::std::mem::transmute(self._bitfield_1.get(4usize, 4u8) as u32) } } @@ -396,31 +317,6 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } } #[inline] - pub unsafe fn l3_type_raw(this: *const Self) -> u32 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 4usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 4usize, 4u8) - as u32, - ) - } - } - #[inline] - pub unsafe fn set_l3_type_raw(this: *mut Self, val: u32) { - unsafe { - let val: u32 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 4usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 4usize, - 4u8, - val as u64, - ) - } - } - #[inline] pub fn l4_type(&self) -> u32 { unsafe { ::std::mem::transmute(self._bitfield_1.get(8usize, 4u8) as u32) } } @@ -432,31 +328,6 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } } #[inline] - pub unsafe fn l4_type_raw(this: *const Self) -> u32 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 4usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 8usize, 4u8) - as u32, - ) - } - } - #[inline] - pub unsafe fn set_l4_type_raw(this: *mut Self, val: u32) { - unsafe { - let val: u32 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 4usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 8usize, - 4u8, - val as u64, - ) - } - } - #[inline] pub fn tun_type(&self) -> u32 { unsafe { ::std::mem::transmute(self._bitfield_1.get(12usize, 4u8) as u32) } } @@ -468,31 +339,6 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } } #[inline] - pub unsafe fn tun_type_raw(this: *const Self) -> u32 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 4usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 12usize, 4u8) - as u32, - ) - } - } - #[inline] - pub unsafe fn set_tun_type_raw(this: *mut Self, val: u32) { - unsafe { - let val: u32 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 4usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 12usize, - 4u8, - val as u64, - ) - } - } - #[inline] pub fn inner_l2_type(&self) -> u32 { unsafe { ::std::mem::transmute(self._bitfield_1.get(16usize, 4u8) as u32) } } @@ -504,31 +350,6 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } } #[inline] - pub unsafe fn inner_l2_type_raw(this: *const Self) -> u32 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 4usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 16usize, 4u8) - as u32, - ) - } - } - #[inline] - pub unsafe fn set_inner_l2_type_raw(this: *mut Self, val: u32) { - unsafe { - let val: u32 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 4usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 16usize, - 4u8, - val as u64, - ) - } - } - #[inline] pub fn inner_l3_type(&self) -> u32 { unsafe { ::std::mem::transmute(self._bitfield_1.get(20usize, 4u8) as u32) } } @@ -540,31 +361,6 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } } #[inline] - pub unsafe fn inner_l3_type_raw(this: *const Self) -> u32 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 4usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 20usize, 4u8) - as u32, - ) - } - } - #[inline] - pub unsafe fn set_inner_l3_type_raw(this: *mut Self, val: u32) { - unsafe { - let val: u32 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 4usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 20usize, - 4u8, - val as u64, - ) - } - } - #[inline] pub fn inner_l4_type(&self) -> u32 { unsafe { ::std::mem::transmute(self._bitfield_1.get(24usize, 4u8) as u32) } } @@ -576,31 +372,6 @@ impl rte_mbuf__bindgen_ty_2__bindgen_ty_1 { } } #[inline] - pub unsafe fn inner_l4_type_raw(this: *const Self) -> u32 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 4usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 24usize, 4u8) - as u32, - ) - } - } - #[inline] - pub unsafe fn set_inner_l4_type_raw(this: *mut Self, val: u32) { - unsafe { - let val: u32 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 4usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 24usize, - 4u8, - val as u64, - ) - } - } - #[inline] pub fn new_bitfield_1( l2_type: u32, l3_type: u32, @@ -991,31 +762,6 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { } } #[inline] - pub unsafe fn l2_len_raw(this: *const Self) -> u64 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 7usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 7u8) - as u64, - ) - } - } - #[inline] - pub unsafe fn set_l2_len_raw(this: *mut Self, val: u64) { - unsafe { - let val: u64 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 7usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 0usize, - 7u8, - val as u64, - ) - } - } - #[inline] pub fn l3_len(&self) -> u64 { unsafe { ::std::mem::transmute(self._bitfield_1.get(7usize, 9u8) as u64) } } @@ -1027,31 +773,6 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { } } #[inline] - pub unsafe fn l3_len_raw(this: *const Self) -> u64 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 7usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 7usize, 9u8) - as u64, - ) - } - } - #[inline] - pub unsafe fn set_l3_len_raw(this: *mut Self, val: u64) { - unsafe { - let val: u64 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 7usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 7usize, - 9u8, - val as u64, - ) - } - } - #[inline] pub fn l4_len(&self) -> u64 { unsafe { ::std::mem::transmute(self._bitfield_1.get(16usize, 8u8) as u64) } } @@ -1063,31 +784,6 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { } } #[inline] - pub unsafe fn l4_len_raw(this: *const Self) -> u64 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 7usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 16usize, 8u8) - as u64, - ) - } - } - #[inline] - pub unsafe fn set_l4_len_raw(this: *mut Self, val: u64) { - unsafe { - let val: u64 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 7usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 16usize, - 8u8, - val as u64, - ) - } - } - #[inline] pub fn tso_segsz(&self) -> u64 { unsafe { ::std::mem::transmute(self._bitfield_1.get(24usize, 16u8) as u64) } } @@ -1099,31 +795,6 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { } } #[inline] - pub unsafe fn tso_segsz_raw(this: *const Self) -> u64 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 7usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 24usize, 16u8) - as u64, - ) - } - } - #[inline] - pub unsafe fn set_tso_segsz_raw(this: *mut Self, val: u64) { - unsafe { - let val: u64 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 7usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 24usize, - 16u8, - val as u64, - ) - } - } - #[inline] pub fn outer_l3_len(&self) -> u64 { unsafe { ::std::mem::transmute(self._bitfield_1.get(40usize, 9u8) as u64) } } @@ -1135,31 +806,6 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { } } #[inline] - pub unsafe fn outer_l3_len_raw(this: *const Self) -> u64 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 7usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 40usize, 9u8) - as u64, - ) - } - } - #[inline] - pub unsafe fn set_outer_l3_len_raw(this: *mut Self, val: u64) { - unsafe { - let val: u64 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 7usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 40usize, - 9u8, - val as u64, - ) - } - } - #[inline] pub fn outer_l2_len(&self) -> u64 { unsafe { ::std::mem::transmute(self._bitfield_1.get(49usize, 7u8) as u64) } } @@ -1171,31 +817,6 @@ impl rte_mbuf__bindgen_ty_5__bindgen_ty_1 { } } #[inline] - pub unsafe fn outer_l2_len_raw(this: *const Self) -> u64 { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 7usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 49usize, 7u8) - as u64, - ) - } - } - #[inline] - pub unsafe fn set_outer_l2_len_raw(this: *mut Self, val: u64) { - unsafe { - let val: u64 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 7usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 49usize, - 7u8, - val as u64, - ) - } - } - #[inline] pub fn new_bitfield_1( l2_len: u64, l3_len: u64, diff --git a/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs b/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs index 9cf2bf8e47..bd4a772cb7 100644 --- a/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs @@ -32,14 +32,6 @@ 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 = *(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) @@ -57,14 +49,6 @@ 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); - *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()); @@ -85,26 +69,6 @@ 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 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()); @@ -122,24 +86,6 @@ 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 - }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); - } - } } #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); @@ -216,34 +162,6 @@ impl U4 { } } #[inline] - pub unsafe fn derp_raw(this: *const Self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 1usize], - >>::raw_get( - (*::std::ptr::addr_of!((*this)._bitfield_1)).as_ref() as *const _, - 0usize, - 1u8, - ) as u32, - ) - } - } - #[inline] - pub unsafe fn set_derp_raw(this: *mut Self, val: ::std::os::raw::c_uint) { - unsafe { - let val: u32 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 1usize], - >>::raw_set( - (*::std::ptr::addr_of_mut!((*this)._bitfield_1)).as_mut() as *mut _, - 0usize, - 1u8, - val as u64, - ) - } - } - #[inline] pub fn new_bitfield_1( derp: ::std::os::raw::c_uint, ) -> __BindgenBitfieldUnit<[u8; 1usize]> { @@ -292,34 +210,6 @@ impl B { } } #[inline] - pub unsafe fn foo_raw(this: *const Self) -> ::std::os::raw::c_uint { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 4usize], - >>::raw_get( - (*::std::ptr::addr_of!((*this)._bitfield_1)).as_ref() as *const _, - 0usize, - 31u8, - ) as u32, - ) - } - } - #[inline] - pub unsafe fn set_foo_raw(this: *mut Self, val: ::std::os::raw::c_uint) { - unsafe { - let val: u32 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 4usize], - >>::raw_set( - (*::std::ptr::addr_of_mut!((*this)._bitfield_1)).as_mut() as *mut _, - 0usize, - 31u8, - val as u64, - ) - } - } - #[inline] pub fn bar(&self) -> ::std::os::raw::c_uchar { unsafe { ::std::mem::transmute(self._bitfield_1.as_ref().get(31usize, 1u8) as u8) @@ -333,34 +223,6 @@ impl B { } } #[inline] - pub unsafe fn bar_raw(this: *const Self) -> ::std::os::raw::c_uchar { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 4usize], - >>::raw_get( - (*::std::ptr::addr_of!((*this)._bitfield_1)).as_ref() as *const _, - 31usize, - 1u8, - ) as u8, - ) - } - } - #[inline] - pub unsafe fn set_bar_raw(this: *mut Self, val: ::std::os::raw::c_uchar) { - unsafe { - let val: u8 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 4usize], - >>::raw_set( - (*::std::ptr::addr_of_mut!((*this)._bitfield_1)).as_mut() as *mut _, - 31usize, - 1u8, - val as u64, - ) - } - } - #[inline] pub fn new_bitfield_1( foo: ::std::os::raw::c_uint, bar: ::std::os::raw::c_uchar, diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs index 287bfebfba..ff19f398ad 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs @@ -32,14 +32,6 @@ 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 = *(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) @@ -57,14 +49,6 @@ 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); - *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()); @@ -85,26 +69,6 @@ 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 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()); @@ -122,24 +86,6 @@ 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 - }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); - } - } } #[repr(C)] pub struct __BindgenUnionField(::std::marker::PhantomData); @@ -228,31 +174,6 @@ impl foo__bindgen_ty_1 { } } #[inline] - pub unsafe fn b_raw(this: *const Self) -> ::std::os::raw::c_int { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 4usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 7u8) - as u32, - ) - } - } - #[inline] - pub unsafe fn set_b_raw(this: *mut Self, val: ::std::os::raw::c_int) { - unsafe { - let val: u32 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 4usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 0usize, - 7u8, - val as u64, - ) - } - } - #[inline] pub fn c(&self) -> ::std::os::raw::c_int { unsafe { ::std::mem::transmute(self._bitfield_1.get(7usize, 25u8) as u32) } } @@ -264,31 +185,6 @@ impl foo__bindgen_ty_1 { } } #[inline] - pub unsafe fn c_raw(this: *const Self) -> ::std::os::raw::c_int { - unsafe { - ::std::mem::transmute( - <__BindgenBitfieldUnit< - [u8; 4usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 7usize, 25u8) - as u32, - ) - } - } - #[inline] - pub unsafe fn set_c_raw(this: *mut Self, val: ::std::os::raw::c_int) { - unsafe { - let val: u32 = ::std::mem::transmute(val); - <__BindgenBitfieldUnit< - [u8; 4usize], - >>::raw_set( - ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 7usize, - 25u8, - val as u64, - ) - } - } - #[inline] pub fn new_bitfield_1( b: ::std::os::raw::c_int, c: ::std::os::raw::c_int, diff --git a/bindgen-tests/tests/headers/derive-debug-bitfield-1-51.hpp b/bindgen-tests/tests/headers/derive-debug-bitfield-1-51.hpp new file mode 100644 index 0000000000..a68611d98b --- /dev/null +++ b/bindgen-tests/tests/headers/derive-debug-bitfield-1-51.hpp @@ -0,0 +1,7 @@ +// bindgen-flags: --impl-debug --rust-target 1.51 + +class C { + bool a: 1; + bool b: 7; + int large_array[50]; +}; diff --git a/bindgen/codegen/bitfield_unit.rs b/bindgen/codegen/bitfield_unit.rs index 3411c22eac..59c66f8cb7 100644 --- a/bindgen/codegen/bitfield_unit.rs +++ b/bindgen/codegen/bitfield_unit.rs @@ -38,17 +38,6 @@ 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 = *(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") { @@ -75,17 +64,6 @@ 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); - - *byte = Self::change_bit(*byte, index, val); - } - #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { debug_assert!(bit_width <= 64); @@ -111,35 +89,6 @@ 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 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); @@ -160,30 +109,4 @@ 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 - }; - 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 new file mode 100644 index 0000000000..3411c22eac --- /dev/null +++ b/bindgen/codegen/bitfield_unit_raw_ref_macros.rs @@ -0,0 +1,189 @@ +#[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 = *(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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) + .offset(byte_index as isize); + + *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 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 + }; + Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + } + } +} diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 4cab877362..ccc5758a14 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -2008,31 +2008,35 @@ impl<'a> FieldCodegen<'a> for Bitfield { ) } } + })); - #[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) + 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) + } } - } - #[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] @@ -2056,7 +2060,10 @@ 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 { @@ -2081,6 +2088,7 @@ impl<'a> FieldCodegen<'a> for Bitfield { } } })); + } } } } @@ -5302,7 +5310,12 @@ pub(crate) mod utils { return; } - let bitfield_unit_src = include_str!("./bitfield_unit.rs"); + 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 = if ctx.options().rust_features().min_const_fn { Cow::Borrowed(bitfield_unit_src) } else { diff --git a/bindgen/features.rs b/bindgen/features.rs index 990e4513cb..e67b00f0d3 100644 --- a/bindgen/features.rs +++ b/bindgen/features.rs @@ -104,6 +104,7 @@ 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 }, Stable_1_59(59) => { const_cstr: #54745 }, Stable_1_47(47) => { larger_arrays: #74060 }, Stable_1_43(43) => { associated_constants: #68952 }, From 6f2e563827444b26886706b801cc56ac09a3cfe2 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Tue, 15 Oct 2024 17:30:05 -0700 Subject: [PATCH 759/942] Install libtinfo5 from jammy-updates --- .github/workflows/bindgen.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index b54d6fdc3a..d1a11712d0 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -196,8 +196,8 @@ jobs: - name: Install libtinfo if: matrix.os == 'ubuntu-latest' run: | - sudo apt-get update - sudo apt-get install libtinfo5 + wget https://mirrors.kernel.org/ubuntu/pool/universe/n/ncurses/libtinfo5_6.3-2ubuntu0.1_amd64.deb + sudo dpkg -i libtinfo5_6.3-2ubuntu0.1_amd64.deb - name: Run all the tests env: GITHUB_ACTIONS_OS: ${{matrix.os}} From 91238467f17d8464bb03d38fe0b8351f53c3554e Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Tue, 15 Oct 2024 17:14:36 -0700 Subject: [PATCH 760/942] Add test of macro-generated inline namespace --- .../tests/inline_namespace_macro.rs | 24 +++++++++++++++++++ .../tests/headers/inline_namespace_macro.hpp | 9 +++++++ .../tests/headers/namespace/nsdefine.h | 4 ++++ 3 files changed, 37 insertions(+) create mode 100644 bindgen-tests/tests/expectations/tests/inline_namespace_macro.rs create mode 100644 bindgen-tests/tests/headers/inline_namespace_macro.hpp create mode 100644 bindgen-tests/tests/headers/namespace/nsdefine.h diff --git a/bindgen-tests/tests/expectations/tests/inline_namespace_macro.rs b/bindgen-tests/tests/expectations/tests/inline_namespace_macro.rs new file mode 100644 index 0000000000..507dd28999 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/inline_namespace_macro.rs @@ -0,0 +1,24 @@ +#![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 { + #[allow(unused_imports)] + use self::super::root; + pub mod repro { + #[allow(unused_imports)] + use self::super::super::root; + pub mod __1 { + #[allow(unused_imports)] + use self::super::super::super::root; + #[repr(C)] + #[derive(Debug, Default, Copy, Clone)] + pub struct duration { + pub _address: u8, + } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of duration"][::std::mem::size_of::() - 1usize]; + ["Alignment of duration"][::std::mem::align_of::() - 1usize]; + }; + } + } +} diff --git a/bindgen-tests/tests/headers/inline_namespace_macro.hpp b/bindgen-tests/tests/headers/inline_namespace_macro.hpp new file mode 100644 index 0000000000..c7cf5caf98 --- /dev/null +++ b/bindgen-tests/tests/headers/inline_namespace_macro.hpp @@ -0,0 +1,9 @@ +// bindgen-flags: --enable-cxx-namespaces -- -std=c++11 + +#include "namespace/nsdefine.h" + +BEGIN_NAMESPACE + +class duration {}; + +END_NAMESPACE diff --git a/bindgen-tests/tests/headers/namespace/nsdefine.h b/bindgen-tests/tests/headers/namespace/nsdefine.h new file mode 100644 index 0000000000..6504fa9f0a --- /dev/null +++ b/bindgen-tests/tests/headers/namespace/nsdefine.h @@ -0,0 +1,4 @@ +#pragma once + +#define BEGIN_NAMESPACE namespace repro { inline namespace __1 { +#define END_NAMESPACE } } From 7fd78ad70c0c4329206421109dc5259b7b923f7e Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Tue, 15 Oct 2024 17:20:53 -0700 Subject: [PATCH 761/942] Recognize inline namespaces using clang's dedicated API for that --- .../tests/inline_namespace_macro.rs | 22 ++++++++----------- bindgen/clang.rs | 5 +++++ bindgen/ir/context.rs | 4 ++++ 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/bindgen-tests/tests/expectations/tests/inline_namespace_macro.rs b/bindgen-tests/tests/expectations/tests/inline_namespace_macro.rs index 507dd28999..99ca607d2f 100644 --- a/bindgen-tests/tests/expectations/tests/inline_namespace_macro.rs +++ b/bindgen-tests/tests/expectations/tests/inline_namespace_macro.rs @@ -6,19 +6,15 @@ pub mod root { pub mod repro { #[allow(unused_imports)] use self::super::super::root; - pub mod __1 { - #[allow(unused_imports)] - use self::super::super::super::root; - #[repr(C)] - #[derive(Debug, Default, Copy, Clone)] - pub struct duration { - pub _address: u8, - } - #[allow(clippy::unnecessary_operation, clippy::identity_op)] - const _: () = { - ["Size of duration"][::std::mem::size_of::() - 1usize]; - ["Alignment of duration"][::std::mem::align_of::() - 1usize]; - }; + #[repr(C)] + #[derive(Debug, Default, Copy, Clone)] + pub struct duration { + pub _address: u8, } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of duration"][::std::mem::size_of::() - 1usize]; + ["Alignment of duration"][::std::mem::align_of::() - 1usize]; + }; } } diff --git a/bindgen/clang.rs b/bindgen/clang.rs index e585fb31bd..47f07a384e 100644 --- a/bindgen/clang.rs +++ b/bindgen/clang.rs @@ -970,6 +970,11 @@ impl Cursor { }) } } + + /// Is this cursor's referent a namespace that is inline? + pub(crate) fn is_inline_namespace(&self) -> bool { + unsafe { clang_Cursor_isInlineNamespace(self.x) != 0 } + } } /// A struct that owns the tokenizer result from a given cursor. diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index 75f6a1ec8f..d32bb144a1 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -2328,6 +2328,10 @@ If you encounter an error missing from this list, please file an issue or a PR!" } } + if cursor.is_inline_namespace() { + kind = ModuleKind::Inline; + } + (module_name, kind) } From 7c569c99e4b63656d1308610913f4bed8a817ef6 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Tue, 26 Nov 2024 19:49:04 -0500 Subject: [PATCH 762/942] Make `RustTarget` parsing more permissive --- bindgen/features.rs | 140 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 114 insertions(+), 26 deletions(-) diff --git a/bindgen/features.rs b/bindgen/features.rs index e67b00f0d3..ccc4191552 100644 --- a/bindgen/features.rs +++ b/bindgen/features.rs @@ -44,7 +44,7 @@ macro_rules! define_rust_targets { } impl RustTarget { - fn minor(self) -> Option { + const fn minor(self) -> Option { match self { $( Self::$variant => Some($minor),)* Self::Nightly => None @@ -136,7 +136,7 @@ define_rust_targets! { Stable_1_0(0) => {}, } -/// Latest stable release of Rust +/// Latest stable release of Rust that is supported by bindgen pub const LATEST_STABLE_RUST: RustTarget = { // FIXME: replace all this code by // ``` @@ -144,7 +144,7 @@ pub const LATEST_STABLE_RUST: RustTarget = { // .into_iter() // .max_by_key(|(_, m)| m) // .map(|(t, _)| t) - // .unwrap_or(RustTarget::Nightly) + // .unwrap() // ``` // once those operations can be used in constants. let targets = RustTarget::stable_releases(); @@ -170,6 +170,42 @@ pub const LATEST_STABLE_RUST: RustTarget = { } }; +/// Earliest stable release of Rust that is supported by bindgen +pub const EARLIEST_STABLE_RUST: RustTarget = { + // FIXME: replace all this code by + // ``` + // RustTarget::stable_releases() + // .into_iter() + // .min_by_key(|(_, m)| m) + // .map(|(t, _)| t) + // .unwrap_or(LATEST_STABLE_RUST) + // ``` + // once those operations can be used in constants. + let targets = RustTarget::stable_releases(); + + let mut i = 0; + let mut earliest_target = None; + let Some(mut earliest_minor) = LATEST_STABLE_RUST.minor() else { + unreachable!() + }; + + while i < targets.len() { + let (target, minor) = targets[i]; + + if earliest_minor > minor { + earliest_minor = minor; + earliest_target = Some(target); + } + + i += 1; + } + + match earliest_target { + Some(target) => target, + None => unreachable!(), + } +}; + impl Default for RustTarget { fn default() -> Self { LATEST_STABLE_RUST @@ -193,28 +229,62 @@ impl Ord for RustTarget { } } +fn invalid_input(input: &str, msg: impl std::fmt::Display) -> io::Result { + Err(io::Error::new( + io::ErrorKind::InvalidInput, + format!("\"{input}\" is not a valid Rust target, {msg}"), + )) +} + impl FromStr for RustTarget { type Err = io::Error; - fn from_str(s: &str) -> Result { - if s == "nightly" { + fn from_str(input: &str) -> Result { + if input == "nightly" { return Ok(Self::Nightly); } - if let Some(("1", str_minor)) = s.split_once('.') { - if let Ok(minor) = str_minor.parse::() { - for (target, target_minor) in Self::stable_releases() { - if minor == target_minor { - return Ok(target); - } - } - } + let Some((major_str, tail)) = input.split_once('.') else { + return invalid_input(input, "accepted values are of the form \"1.71\", \"1.71.1\" or \"nightly\"." ); + }; + + if major_str != "1" { + return invalid_input( + input, + "The largest major version of Rust released is \"1\"", + ); } - Err(io::Error::new( - io::ErrorKind::InvalidInput, - "Got an invalid Rust target. Accepted values are of the form \"1.71\" or \"nightly\"." - )) + // We ignore the patch version number as they only include backwards compatible bug fixes. + let (minor, _patch) = match tail.split_once('.') { + Some((minor_str, patch_str)) => { + let Ok(minor) = minor_str.parse::() else { + return invalid_input(input, "the minor version number must be an unsigned 64-bit integer"); + }; + let Ok(patch) = patch_str.parse::() else { + return invalid_input(input, "the patch version number must be an unsigned 64-bit integer"); + }; + (minor, patch) + } + None => { + let Ok(minor) = tail.parse::() else { + return invalid_input(input, "the minor version number must be an unsigned 64-bit integer"); + }; + (minor, 0) + } + }; + + let Some(target) = Self::stable_releases() + .iter() + .filter(|(_, target_minor)| minor >= *target_minor) + .max_by_key(|(_, target_minor)| target_minor) + .map(|(target, _)| target) + .cloned() + else { + return invalid_input(input, format!("the earliest Rust target supported by bindgen is {EARLIEST_STABLE_RUST}")); + }; + + Ok(target) } } @@ -282,19 +352,37 @@ mod test { } fn test_target(target_str: &str, target: RustTarget) { - let target_string = target.to_string(); - assert_eq!(target_str, target_string); - assert_eq!(target, RustTarget::from_str(target_str).unwrap()); + assert_eq!( + target, + target_str.parse::().unwrap(), + "{target_str}" + ); + } + + fn test_invalid_target(target_str: &str) { + assert!(target_str.parse::().is_err(), "{}", target_str); } #[test] - fn str_to_target() { - test_target("1.0", RustTarget::Stable_1_0); - test_target("1.17", RustTarget::Stable_1_17); - test_target("1.19", RustTarget::Stable_1_19); - test_target("1.21", RustTarget::Stable_1_21); - test_target("1.25", RustTarget::Stable_1_25); + fn valid_targets() { test_target("1.71", RustTarget::Stable_1_71); + test_target("1.71.0", RustTarget::Stable_1_71); + test_target("1.71.1", RustTarget::Stable_1_71); + test_target("1.72", RustTarget::Stable_1_71); + test_target("1.73", RustTarget::Stable_1_73); + test_target("1.18446744073709551615", LATEST_STABLE_RUST); test_target("nightly", RustTarget::Nightly); } + + #[test] + fn invalid_targets() { + test_invalid_target("2.0"); + test_invalid_target("1.cat"); + test_invalid_target("1.0.cat"); + test_invalid_target("1.18446744073709551616"); + test_invalid_target("1.0.18446744073709551616"); + test_invalid_target("1.-1.0"); + test_invalid_target("1.0.-1"); + test_invalid_target("beta"); + } } From 6f35a9b1f96b109eb4cacdd71df4c315f0105e1e Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Tue, 26 Nov 2024 22:30:51 -0500 Subject: [PATCH 763/942] Represent Rust versions with integers --- bindgen/features.rs | 146 +++++++++++++++++++++----------------------- 1 file changed, 71 insertions(+), 75 deletions(-) diff --git a/bindgen/features.rs b/bindgen/features.rs index ccc4191552..97d85c1693 100644 --- a/bindgen/features.rs +++ b/bindgen/features.rs @@ -4,10 +4,56 @@ #![deny(clippy::missing_docs_in_private_items)] #![allow(deprecated)] -use std::cmp::Ordering; use std::io; use std::str::FromStr; +/// Represents the version of the Rust language to target. +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] +#[repr(transparent)] +pub struct RustTarget(Version); + +impl RustTarget { + const fn minor(&self) -> Option { + match self.0 { + Version::Nightly => None, + Version::Stable(minor, _) => Some(minor), + } + } + + const fn is_compatible(&self, other: &Self) -> bool { + match (self.0, other.0) { + (Version::Stable(minor, _), Version::Stable(other_minor, _)) => { + // We ignore the patch version number as they only include backwards compatible bug + // fixes. + minor >= other_minor + } + (_, Version::Nightly) => false, + (Version::Nightly, _) => true, + } + } +} + +impl Default for RustTarget { + fn default() -> Self { + LATEST_STABLE_RUST + } +} + +impl std::fmt::Display for RustTarget { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self.0 { + Version::Stable(minor, patch) => write!(f, "1.{minor}.{patch}"), + Version::Nightly => "nightly".fmt(f), + } + } +} + +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] +enum Version { + Stable(u64, u64), + Nightly, +} + /// This macro defines the [`RustTarget`] and [`RustFeatures`] types. macro_rules! define_rust_targets { ( @@ -18,38 +64,24 @@ macro_rules! define_rust_targets { )* $(,)? ) => { - /// Represents the version of the Rust language to target. - /// - /// To support a beta release, use the corresponding stable release. - /// - /// This enum will have more variants added as necessary. - #[allow(non_camel_case_types)] - #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] - pub enum RustTarget { - /// Rust Nightly + + impl RustTarget { + /// The nightly version of Rust, which introduces the following features:" $(#[doc = concat!( "- [`", stringify!($nightly_feature), "`]", "(", $("https://github.com/rust-lang/rust/pull/", stringify!($issue),)* ")", )])* - Nightly, + pub const Nightly: Self = Self(Version::Nightly); + $( - #[doc = concat!("Rust 1.", stringify!($minor))] + #[doc = concat!("Version 1.", stringify!($minor), " of Rust, which introduced the following features:")] $(#[doc = concat!( "- [`", stringify!($feature), "`]", "(", $("https://github.com/rust-lang/rust/pull/", stringify!($pull),)* ")", )])* $(#[$attrs])* - $variant, + pub const $variant: Self = Self(Version::Stable($minor, 0)); )* - } - - impl RustTarget { - const fn minor(self) -> Option { - match self { - $( Self::$variant => Some($minor),)* - Self::Nightly => None - } - } const fn stable_releases() -> [(Self, u64); [$($minor,)*].len()] { [$((Self::$variant, $minor),)*] @@ -58,7 +90,7 @@ macro_rules! define_rust_targets { #[cfg(feature = "__cli")] /// Strings of allowed `RustTarget` values - pub const RUST_TARGET_STRINGS: &[&str] = &[$(concat!("1.", stringify!($minor)),)*]; + pub(crate) const RUST_TARGET_STRINGS: &[&str] = &[$(concat!("1.", stringify!($minor)),)*]; #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] pub(crate) struct RustFeatures { @@ -80,7 +112,7 @@ macro_rules! define_rust_targets { $($nightly_feature: false,)* }; - $(if target >= RustTarget::$variant { + $(if target.is_compatible(&RustTarget::$variant) { $(features.$feature = true;)* })* @@ -206,29 +238,6 @@ pub const EARLIEST_STABLE_RUST: RustTarget = { } }; -impl Default for RustTarget { - fn default() -> Self { - LATEST_STABLE_RUST - } -} - -impl PartialOrd for RustTarget { - fn partial_cmp(&self, other: &Self) -> Option { - Some(self.cmp(other)) - } -} - -impl Ord for RustTarget { - fn cmp(&self, other: &Self) -> Ordering { - match (self.minor(), other.minor()) { - (Some(a), Some(b)) => a.cmp(&b), - (Some(_), None) => Ordering::Less, - (None, Some(_)) => Ordering::Greater, - (None, None) => Ordering::Equal, - } - } -} - fn invalid_input(input: &str, msg: impl std::fmt::Display) -> io::Result { Err(io::Error::new( io::ErrorKind::InvalidInput, @@ -255,8 +264,7 @@ impl FromStr for RustTarget { ); } - // We ignore the patch version number as they only include backwards compatible bug fixes. - let (minor, _patch) = match tail.split_once('.') { + let (minor, patch) = match tail.split_once('.') { Some((minor_str, patch_str)) => { let Ok(minor) = minor_str.parse::() else { return invalid_input(input, "the minor version number must be an unsigned 64-bit integer"); @@ -274,26 +282,7 @@ impl FromStr for RustTarget { } }; - let Some(target) = Self::stable_releases() - .iter() - .filter(|(_, target_minor)| minor >= *target_minor) - .max_by_key(|(_, target_minor)| target_minor) - .map(|(target, _)| target) - .cloned() - else { - return invalid_input(input, format!("the earliest Rust target supported by bindgen is {EARLIEST_STABLE_RUST}")); - }; - - Ok(target) - } -} - -impl std::fmt::Display for RustTarget { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self.minor() { - Some(minor) => write!(f, "1.{}", minor), - None => "nightly".fmt(f), - } + Ok(Self(Version::Stable(minor, patch))) } } @@ -351,16 +340,23 @@ mod test { ); } - fn test_target(target_str: &str, target: RustTarget) { + fn test_target(input: &str, expected: RustTarget) { + // Two targets are equivalent if they enable the same set of features + let expected = RustFeatures::from(expected); + let found = RustFeatures::from(input.parse::().unwrap()); assert_eq!( - target, - target_str.parse::().unwrap(), - "{target_str}" + expected, + found, + "target {input} enables features:\n{found:#?}\nand should enable features:\n{expected:#?}" ); } - fn test_invalid_target(target_str: &str) { - assert!(target_str.parse::().is_err(), "{}", target_str); + fn test_invalid_target(input: &str) { + assert!( + input.parse::().is_err(), + "{} should be an invalid target", + input + ); } #[test] From f2ebf031f65acdc1e0d78d2381c72b0452fb3dbb Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Wed, 27 Nov 2024 11:58:04 -0500 Subject: [PATCH 764/942] Add constructors to `RustTarget` --- bindgen/features.rs | 60 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 46 insertions(+), 14 deletions(-) diff --git a/bindgen/features.rs b/bindgen/features.rs index 97d85c1693..799b15a55f 100644 --- a/bindgen/features.rs +++ b/bindgen/features.rs @@ -4,8 +4,8 @@ #![deny(clippy::missing_docs_in_private_items)] #![allow(deprecated)] -use std::io; use std::str::FromStr; +use std::{fmt, io}; /// Represents the version of the Rust language to target. #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] @@ -13,6 +13,17 @@ use std::str::FromStr; pub struct RustTarget(Version); impl RustTarget { + /// Create a new [`RustTarget`] for a stable release of Rust. + pub fn stable(minor: u64, patch: u64) -> Result { + let target = Self(Version::Stable(minor, patch)); + + if target < EARLIEST_STABLE_RUST { + return Err(InvalidRustTarget::TooEarly); + } + + Ok(target) + } + const fn minor(&self) -> Option { match self.0 { Version::Nightly => None, @@ -39,8 +50,8 @@ impl Default for RustTarget { } } -impl std::fmt::Display for RustTarget { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl fmt::Display for RustTarget { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self.0 { Version::Stable(minor, patch) => write!(f, "1.{minor}.{patch}"), Version::Nightly => "nightly".fmt(f), @@ -54,6 +65,18 @@ enum Version { Nightly, } +pub enum InvalidRustTarget { + TooEarly, +} + +impl fmt::Display for InvalidRustTarget { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Self::TooEarly => write!(f, "the earliest Rust version supported by bindgen is {EARLIEST_STABLE_RUST}"), + } + } +} + /// This macro defines the [`RustTarget`] and [`RustFeatures`] types. macro_rules! define_rust_targets { ( @@ -71,7 +94,16 @@ macro_rules! define_rust_targets { "- [`", stringify!($nightly_feature), "`]", "(", $("https://github.com/rust-lang/rust/pull/", stringify!($issue),)* ")", )])* - pub const Nightly: Self = Self(Version::Nightly); + pub const Nightly: Self = Self::nightly(); + + /// The nightly version of Rust, which introduces the following features:" + $(#[doc = concat!( + "- [`", stringify!($nightly_feature), "`]", + "(", $("https://github.com/rust-lang/rust/pull/", stringify!($issue),)* ")", + )])* + pub const fn nightly() -> Self { + Self(Version::Nightly) + } $( #[doc = concat!("Version 1.", stringify!($minor), " of Rust, which introduced the following features:")] @@ -238,11 +270,11 @@ pub const EARLIEST_STABLE_RUST: RustTarget = { } }; -fn invalid_input(input: &str, msg: impl std::fmt::Display) -> io::Result { - Err(io::Error::new( +fn invalid_input(input: &str, msg: impl fmt::Display) -> io::Error { + io::Error::new( io::ErrorKind::InvalidInput, format!("\"{input}\" is not a valid Rust target, {msg}"), - )) + ) } impl FromStr for RustTarget { @@ -254,35 +286,35 @@ impl FromStr for RustTarget { } let Some((major_str, tail)) = input.split_once('.') else { - return invalid_input(input, "accepted values are of the form \"1.71\", \"1.71.1\" or \"nightly\"." ); + return Err(invalid_input(input, "accepted values are of the form \"1.71\", \"1.71.1\" or \"nightly\"." ) ); }; if major_str != "1" { - return invalid_input( + return Err(invalid_input( input, "The largest major version of Rust released is \"1\"", - ); + )); } let (minor, patch) = match tail.split_once('.') { Some((minor_str, patch_str)) => { let Ok(minor) = minor_str.parse::() else { - return invalid_input(input, "the minor version number must be an unsigned 64-bit integer"); + return Err(invalid_input(input, "the minor version number must be an unsigned 64-bit integer")); }; let Ok(patch) = patch_str.parse::() else { - return invalid_input(input, "the patch version number must be an unsigned 64-bit integer"); + return Err(invalid_input(input, "the patch version number must be an unsigned 64-bit integer")); }; (minor, patch) } None => { let Ok(minor) = tail.parse::() else { - return invalid_input(input, "the minor version number must be an unsigned 64-bit integer"); + return Err(invalid_input(input, "the minor version number must be an unsigned 64-bit integer")); }; (minor, 0) } }; - Ok(Self(Version::Stable(minor, patch))) + Self::stable(minor, patch).map_err(|err| invalid_input(input, err)) } } From 12d650dc0bce7d4cf9fe6f5a6f96506020718077 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Wed, 27 Nov 2024 11:58:04 -0500 Subject: [PATCH 765/942] Remove deprecated targets --- .../tests/16-byte-alignment_1_0.rs | 299 --- .../tests/anon_struct_in_union_1_0.rs | 127 -- .../expectations/tests/anon_union_1_0.rs | 125 -- .../attribute_warn_unused_result_pre_1_27.rs | 25 - .../tests/bindgen-union-inside-namespace.rs | 62 +- .../tests/bitfield-enum-repr-c.rs | 2 +- .../tests/expectations/tests/class_1_0.rs | 539 ----- .../tests/class_with_inner_struct_1_0.rs | 397 ---- .../expectations/tests/derive-clone_1_0.rs | 42 - .../tests/derive-partialeq-union_1_0.rs | 96 - .../forward_declared_complex_types_1_0.rs | 89 - .../tests/expectations/tests/issue-493_1_0.rs | 136 -- .../tests/jsval_layout_opaque_1_0.rs | 459 ---- .../tests/expectations/tests/layout.rs | 53 +- .../expectations/tests/layout_eth_conf_1_0.rs | 1837 ----------------- .../expectations/tests/layout_mbuf_1_0.rs | 1047 ---------- .../expectations/tests/macro_const_1_0.rs | 8 - .../tests/expectations/tests/strings_array.rs | 6 +- .../tests/struct_with_anon_union_1_0.rs | 103 - .../struct_with_anon_unnamed_union_1_0.rs | 96 - .../tests/struct_with_nesting_1_0.rs | 184 -- .../tests/expectations/tests/transform-op.rs | 25 +- .../tests/expectations/tests/typeref_1_0.rs | 175 -- .../expectations/tests/union-in-ns_1_0.rs | 72 - .../expectations/tests/union_bitfield_1_0.rs | 285 --- .../expectations/tests/union_dtor_1_0.rs | 82 - .../expectations/tests/union_fields_1_0.rs | 83 - .../expectations/tests/union_template_1_0.rs | 72 - .../tests/union_with_anon_struct_1_0.rs | 103 - .../union_with_anon_struct_bitfield_1_0.rs | 230 --- .../tests/union_with_anon_union_1_0.rs | 104 - .../union_with_anon_unnamed_struct_1_0.rs | 116 -- .../union_with_anon_unnamed_union_1_0.rs | 105 - .../tests/union_with_big_member_1_0.rs | 165 -- .../tests/union_with_nesting_1_0.rs | 166 -- .../tests/expectations/tests/use-core_1_0.rs | 127 -- ...in32-thiscall_1_0.rs => win32-thiscall.rs} | 7 +- ...-vectorcall-1_0.rs => win32-vectorcall.rs} | 0 .../tests/wrap_unsafe_ops_anon_union.rs | 57 + .../tests/wrap_unsafe_ops_anon_union_1_0.rs | 100 - .../tests/headers/16-byte-alignment_1_0.h | 34 - .../tests/headers/anon_struct_in_union_1_0.h | 9 - .../tests/headers/anon_union_1_0.hpp | 22 - .../headers/attribute_warn_unused_result.hpp | 2 +- ...n_unused_result_no_attribute_detection.hpp | 2 +- .../attribute_warn_unused_result_pre_1_27.hpp | 8 - .../bindgen-union-inside-namespace.hpp | 2 +- .../tests/headers/bitfield-enum-repr-c.hpp | 2 +- .../bitfield-enum-repr-transparent.hpp | 2 +- bindgen-tests/tests/headers/class_1_0.hpp | 76 - .../headers/class_with_inner_struct_1_0.hpp | 44 - .../tests/headers/derive-clone_1_0.h | 7 - .../headers/derive-partialeq-union_1_0.hpp | 7 - .../forward_declared_complex_types_1_0.hpp | 18 - bindgen-tests/tests/headers/i128.h | 2 +- bindgen-tests/tests/headers/issue-1291.hpp | 2 +- bindgen-tests/tests/headers/issue-493_1_0.hpp | 49 - .../tests/headers/jsval_layout_opaque_1_0.hpp | 425 ---- bindgen-tests/tests/headers/layout.h | 2 +- .../tests/headers/layout_eth_conf_1_0.h | 429 ---- bindgen-tests/tests/headers/layout_mbuf_1_0.h | 189 -- bindgen-tests/tests/headers/long_double.h | 2 +- bindgen-tests/tests/headers/macro_const_1_0.h | 10 - bindgen-tests/tests/headers/newtype-enum.hpp | 2 +- .../tests/headers/newtype-global-enum.hpp | 2 +- bindgen-tests/tests/headers/repr-align.hpp | 2 +- bindgen-tests/tests/headers/strings_array.h | 2 +- .../headers/struct_with_anon_union_1_0.h | 8 - .../struct_with_anon_unnamed_union_1_0.h | 8 - .../tests/headers/struct_with_nesting_1_0.h | 19 - bindgen-tests/tests/headers/transform-op.hpp | 2 +- bindgen-tests/tests/headers/typeref_1_0.hpp | 30 - bindgen-tests/tests/headers/union-align.h | 2 +- .../tests/headers/union-in-ns_1_0.hpp | 5 - .../tests/headers/union_bitfield_1_0.h | 14 - .../tests/headers/union_dtor_1_0.hpp | 7 - .../tests/headers/union_fields_1_0.hpp | 7 - .../tests/headers/union_template_1_0.hpp | 21 - .../headers/union_with_anon_struct_1_0.h | 8 - .../union_with_anon_struct_bitfield_1_0.h | 9 - .../tests/headers/union_with_anon_union_1_0.h | 8 - .../union_with_anon_unnamed_struct_1_0.h | 11 - .../union_with_anon_unnamed_union_1_0.h | 9 - .../tests/headers/union_with_big_member_1_0.h | 16 - .../tests/headers/union_with_nesting_1_0.h | 16 - bindgen-tests/tests/headers/use-core_1_0.h | 13 - bindgen-tests/tests/headers/win32-dtors.hpp | 2 +- .../tests/headers/win32-thiscall.hpp | 7 + .../tests/headers/win32-thiscall_1_0.hpp | 7 - .../tests/headers/win32-vectorcall-1_0.h | 3 - .../tests/headers/win32-vectorcall.h | 3 + ...1_0.hpp => wrap_unsafe_ops_anon_union.hpp} | 2 +- bindgen/codegen/helpers.rs | 33 +- bindgen/codegen/mod.rs | 126 +- bindgen/codegen/struct_layout.rs | 6 +- bindgen/features.rs | 59 +- bindgen/ir/analysis/derive.rs | 5 +- bindgen/ir/layout.rs | 27 +- bindgen/lib.rs | 32 - 99 files changed, 251 insertions(+), 9433 deletions(-) delete mode 100644 bindgen-tests/tests/expectations/tests/16-byte-alignment_1_0.rs delete mode 100644 bindgen-tests/tests/expectations/tests/anon_struct_in_union_1_0.rs delete mode 100644 bindgen-tests/tests/expectations/tests/anon_union_1_0.rs delete mode 100644 bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_pre_1_27.rs delete mode 100644 bindgen-tests/tests/expectations/tests/class_1_0.rs delete mode 100644 bindgen-tests/tests/expectations/tests/class_with_inner_struct_1_0.rs delete mode 100644 bindgen-tests/tests/expectations/tests/derive-clone_1_0.rs delete mode 100644 bindgen-tests/tests/expectations/tests/derive-partialeq-union_1_0.rs delete mode 100644 bindgen-tests/tests/expectations/tests/forward_declared_complex_types_1_0.rs delete mode 100644 bindgen-tests/tests/expectations/tests/issue-493_1_0.rs delete mode 100644 bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs delete mode 100644 bindgen-tests/tests/expectations/tests/layout_eth_conf_1_0.rs delete mode 100644 bindgen-tests/tests/expectations/tests/layout_mbuf_1_0.rs delete mode 100644 bindgen-tests/tests/expectations/tests/macro_const_1_0.rs delete mode 100644 bindgen-tests/tests/expectations/tests/struct_with_anon_union_1_0.rs delete mode 100644 bindgen-tests/tests/expectations/tests/struct_with_anon_unnamed_union_1_0.rs delete mode 100644 bindgen-tests/tests/expectations/tests/struct_with_nesting_1_0.rs delete mode 100644 bindgen-tests/tests/expectations/tests/typeref_1_0.rs delete mode 100644 bindgen-tests/tests/expectations/tests/union-in-ns_1_0.rs delete mode 100644 bindgen-tests/tests/expectations/tests/union_bitfield_1_0.rs delete mode 100644 bindgen-tests/tests/expectations/tests/union_dtor_1_0.rs delete mode 100644 bindgen-tests/tests/expectations/tests/union_fields_1_0.rs delete mode 100644 bindgen-tests/tests/expectations/tests/union_template_1_0.rs delete mode 100644 bindgen-tests/tests/expectations/tests/union_with_anon_struct_1_0.rs delete mode 100644 bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield_1_0.rs delete mode 100644 bindgen-tests/tests/expectations/tests/union_with_anon_union_1_0.rs delete mode 100644 bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_struct_1_0.rs delete mode 100644 bindgen-tests/tests/expectations/tests/union_with_anon_unnamed_union_1_0.rs delete mode 100644 bindgen-tests/tests/expectations/tests/union_with_big_member_1_0.rs delete mode 100644 bindgen-tests/tests/expectations/tests/union_with_nesting_1_0.rs delete mode 100644 bindgen-tests/tests/expectations/tests/use-core_1_0.rs rename bindgen-tests/tests/expectations/tests/{win32-thiscall_1_0.rs => win32-thiscall.rs} (75%) rename bindgen-tests/tests/expectations/tests/{win32-vectorcall-1_0.rs => win32-vectorcall.rs} (100%) create mode 100644 bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_anon_union.rs delete mode 100644 bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_anon_union_1_0.rs delete mode 100644 bindgen-tests/tests/headers/16-byte-alignment_1_0.h delete mode 100644 bindgen-tests/tests/headers/anon_struct_in_union_1_0.h delete mode 100644 bindgen-tests/tests/headers/anon_union_1_0.hpp delete mode 100644 bindgen-tests/tests/headers/attribute_warn_unused_result_pre_1_27.hpp delete mode 100644 bindgen-tests/tests/headers/class_1_0.hpp delete mode 100644 bindgen-tests/tests/headers/class_with_inner_struct_1_0.hpp delete mode 100644 bindgen-tests/tests/headers/derive-clone_1_0.h delete mode 100644 bindgen-tests/tests/headers/derive-partialeq-union_1_0.hpp delete mode 100644 bindgen-tests/tests/headers/forward_declared_complex_types_1_0.hpp delete mode 100644 bindgen-tests/tests/headers/issue-493_1_0.hpp delete mode 100644 bindgen-tests/tests/headers/jsval_layout_opaque_1_0.hpp delete mode 100644 bindgen-tests/tests/headers/layout_eth_conf_1_0.h delete mode 100644 bindgen-tests/tests/headers/layout_mbuf_1_0.h delete mode 100644 bindgen-tests/tests/headers/macro_const_1_0.h delete mode 100644 bindgen-tests/tests/headers/struct_with_anon_union_1_0.h delete mode 100644 bindgen-tests/tests/headers/struct_with_anon_unnamed_union_1_0.h delete mode 100644 bindgen-tests/tests/headers/struct_with_nesting_1_0.h delete mode 100644 bindgen-tests/tests/headers/typeref_1_0.hpp delete mode 100644 bindgen-tests/tests/headers/union-in-ns_1_0.hpp delete mode 100644 bindgen-tests/tests/headers/union_bitfield_1_0.h delete mode 100644 bindgen-tests/tests/headers/union_dtor_1_0.hpp delete mode 100644 bindgen-tests/tests/headers/union_fields_1_0.hpp delete mode 100644 bindgen-tests/tests/headers/union_template_1_0.hpp delete mode 100644 bindgen-tests/tests/headers/union_with_anon_struct_1_0.h delete mode 100644 bindgen-tests/tests/headers/union_with_anon_struct_bitfield_1_0.h delete mode 100644 bindgen-tests/tests/headers/union_with_anon_union_1_0.h delete mode 100644 bindgen-tests/tests/headers/union_with_anon_unnamed_struct_1_0.h delete mode 100644 bindgen-tests/tests/headers/union_with_anon_unnamed_union_1_0.h delete mode 100644 bindgen-tests/tests/headers/union_with_big_member_1_0.h delete mode 100644 bindgen-tests/tests/headers/union_with_nesting_1_0.h delete mode 100644 bindgen-tests/tests/headers/use-core_1_0.h create mode 100644 bindgen-tests/tests/headers/win32-thiscall.hpp delete mode 100644 bindgen-tests/tests/headers/win32-thiscall_1_0.hpp delete mode 100644 bindgen-tests/tests/headers/win32-vectorcall-1_0.h create mode 100644 bindgen-tests/tests/headers/win32-vectorcall.h rename bindgen-tests/tests/headers/{wrap_unsafe_ops_anon_union_1_0.hpp => wrap_unsafe_ops_anon_union.hpp} (82%) diff --git a/bindgen-tests/tests/expectations/tests/16-byte-alignment_1_0.rs b/bindgen-tests/tests/expectations/tests/16-byte-alignment_1_0.rs deleted file mode 100644 index 06d008982c..0000000000 --- a/bindgen-tests/tests/expectations/tests/16-byte-alignment_1_0.rs +++ /dev/null @@ -1,299 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -pub struct __BindgenUnionField(::std::marker::PhantomData); -impl __BindgenUnionField { - #[inline] - pub fn new() -> Self { - __BindgenUnionField(::std::marker::PhantomData) - } - #[inline] - pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) - } - #[inline] - pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) - } -} -impl ::std::default::Default for __BindgenUnionField { - #[inline] - fn default() -> Self { - Self::new() - } -} -impl ::std::clone::Clone for __BindgenUnionField { - #[inline] - fn clone(&self) -> Self { - *self - } -} -impl ::std::marker::Copy for __BindgenUnionField {} -impl ::std::fmt::Debug for __BindgenUnionField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__BindgenUnionField") - } -} -impl ::std::hash::Hash for __BindgenUnionField { - fn hash(&self, _state: &mut H) {} -} -impl ::std::cmp::PartialEq for __BindgenUnionField { - fn eq(&self, _other: &__BindgenUnionField) -> bool { - true - } -} -impl ::std::cmp::Eq for __BindgenUnionField {} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct rte_ipv4_tuple { - pub src_addr: u32, - pub dst_addr: u32, - pub __bindgen_anon_1: rte_ipv4_tuple__bindgen_ty_1, -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct rte_ipv4_tuple__bindgen_ty_1 { - pub __bindgen_anon_1: __BindgenUnionField< - rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1, - >, - pub sctp_tag: __BindgenUnionField, - pub bindgen_union_field: u32, -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 { - pub dport: u16, - pub sport: u16, -} -#[test] -fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - "Size of rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1", - ); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - "Alignment of rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dport) as usize - ptr as usize }, - 0usize, - "Offset of field: rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1::dport", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).sport) as usize - ptr as usize }, - 2usize, - "Offset of field: rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1::sport", - ); -} -impl Clone for rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} -#[test] -fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - "Size of rte_ipv4_tuple__bindgen_ty_1", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - "Alignment of rte_ipv4_tuple__bindgen_ty_1", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).sctp_tag) as usize - ptr as usize }, - 0usize, - "Offset of field: rte_ipv4_tuple__bindgen_ty_1::sctp_tag", - ); -} -impl Clone for rte_ipv4_tuple__bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} -#[test] -fn bindgen_test_layout_rte_ipv4_tuple() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 12usize, - "Size of rte_ipv4_tuple", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - "Alignment of rte_ipv4_tuple", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).src_addr) as usize - ptr as usize }, - 0usize, - "Offset of field: rte_ipv4_tuple::src_addr", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dst_addr) as usize - ptr as usize }, - 4usize, - "Offset of field: rte_ipv4_tuple::dst_addr", - ); -} -impl Clone for rte_ipv4_tuple { - fn clone(&self) -> Self { - *self - } -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct rte_ipv6_tuple { - pub src_addr: [u8; 16usize], - pub dst_addr: [u8; 16usize], - pub __bindgen_anon_1: rte_ipv6_tuple__bindgen_ty_1, -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct rte_ipv6_tuple__bindgen_ty_1 { - pub __bindgen_anon_1: __BindgenUnionField< - rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1, - >, - pub sctp_tag: __BindgenUnionField, - pub bindgen_union_field: u32, -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 { - pub dport: u16, - pub sport: u16, -} -#[test] -fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - "Size of rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1", - ); - assert_eq!( - ::std::mem::align_of::(), - 2usize, - "Alignment of rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dport) as usize - ptr as usize }, - 0usize, - "Offset of field: rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1::dport", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).sport) as usize - ptr as usize }, - 2usize, - "Offset of field: rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1::sport", - ); -} -impl Clone for rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} -#[test] -fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - "Size of rte_ipv6_tuple__bindgen_ty_1", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - "Alignment of rte_ipv6_tuple__bindgen_ty_1", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).sctp_tag) as usize - ptr as usize }, - 0usize, - "Offset of field: rte_ipv6_tuple__bindgen_ty_1::sctp_tag", - ); -} -impl Clone for rte_ipv6_tuple__bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} -#[test] -fn bindgen_test_layout_rte_ipv6_tuple() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 36usize, - "Size of rte_ipv6_tuple", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - "Alignment of rte_ipv6_tuple", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).src_addr) as usize - ptr as usize }, - 0usize, - "Offset of field: rte_ipv6_tuple::src_addr", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dst_addr) as usize - ptr as usize }, - 16usize, - "Offset of field: rte_ipv6_tuple::dst_addr", - ); -} -impl Clone for rte_ipv6_tuple { - fn clone(&self) -> Self { - *self - } -} -#[repr(C)] -#[derive(Copy)] -pub struct rte_thash_tuple { - pub v4: __BindgenUnionField, - pub v6: __BindgenUnionField, - pub bindgen_union_field: [u8; 48usize], -} -#[test] -fn bindgen_test_layout_rte_thash_tuple() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 48usize, - "Size of rte_thash_tuple", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).v4) as usize - ptr as usize }, - 0usize, - "Offset of field: rte_thash_tuple::v4", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).v6) as usize - ptr as usize }, - 0usize, - "Offset of field: rte_thash_tuple::v6", - ); -} -impl Clone for rte_thash_tuple { - fn clone(&self) -> Self { - *self - } -} -impl Default for rte_thash_tuple { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} diff --git a/bindgen-tests/tests/expectations/tests/anon_struct_in_union_1_0.rs b/bindgen-tests/tests/expectations/tests/anon_struct_in_union_1_0.rs deleted file mode 100644 index 5a6e3ca477..0000000000 --- a/bindgen-tests/tests/expectations/tests/anon_struct_in_union_1_0.rs +++ /dev/null @@ -1,127 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -pub struct __BindgenUnionField(::std::marker::PhantomData); -impl __BindgenUnionField { - #[inline] - pub fn new() -> Self { - __BindgenUnionField(::std::marker::PhantomData) - } - #[inline] - pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) - } - #[inline] - pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) - } -} -impl ::std::default::Default for __BindgenUnionField { - #[inline] - fn default() -> Self { - Self::new() - } -} -impl ::std::clone::Clone for __BindgenUnionField { - #[inline] - fn clone(&self) -> Self { - *self - } -} -impl ::std::marker::Copy for __BindgenUnionField {} -impl ::std::fmt::Debug for __BindgenUnionField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__BindgenUnionField") - } -} -impl ::std::hash::Hash for __BindgenUnionField { - fn hash(&self, _state: &mut H) {} -} -impl ::std::cmp::PartialEq for __BindgenUnionField { - fn eq(&self, _other: &__BindgenUnionField) -> bool { - true - } -} -impl ::std::cmp::Eq for __BindgenUnionField {} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct s { - pub u: s__bindgen_ty_1, -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct s__bindgen_ty_1 { - pub field: __BindgenUnionField, - pub bindgen_union_field: u32, -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct s__bindgen_ty_1_inner { - pub b: ::std::os::raw::c_int, -} -#[test] -fn bindgen_test_layout_s__bindgen_ty_1_inner() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - "Size of s__bindgen_ty_1_inner", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - "Alignment of s__bindgen_ty_1_inner", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - "Offset of field: s__bindgen_ty_1_inner::b", - ); -} -impl Clone for s__bindgen_ty_1_inner { - fn clone(&self) -> Self { - *self - } -} -#[test] -fn bindgen_test_layout_s__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - "Size of s__bindgen_ty_1", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - "Alignment of s__bindgen_ty_1", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).field) as usize - ptr as usize }, - 0usize, - "Offset of field: s__bindgen_ty_1::field", - ); -} -impl Clone for s__bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} -#[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::(), 4usize, "Size of s"); - assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of s"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).u) as usize - ptr as usize }, - 0usize, - "Offset of field: s::u", - ); -} -impl Clone for s { - fn clone(&self) -> Self { - *self - } -} diff --git a/bindgen-tests/tests/expectations/tests/anon_union_1_0.rs b/bindgen-tests/tests/expectations/tests/anon_union_1_0.rs deleted file mode 100644 index 29b13d010d..0000000000 --- a/bindgen-tests/tests/expectations/tests/anon_union_1_0.rs +++ /dev/null @@ -1,125 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -pub struct __BindgenUnionField(::std::marker::PhantomData); -impl __BindgenUnionField { - #[inline] - pub fn new() -> Self { - __BindgenUnionField(::std::marker::PhantomData) - } - #[inline] - pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) - } - #[inline] - pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) - } -} -impl ::std::default::Default for __BindgenUnionField { - #[inline] - fn default() -> Self { - Self::new() - } -} -impl ::std::clone::Clone for __BindgenUnionField { - #[inline] - fn clone(&self) -> Self { - *self - } -} -impl ::std::marker::Copy for __BindgenUnionField {} -impl ::std::fmt::Debug for __BindgenUnionField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__BindgenUnionField") - } -} -impl ::std::hash::Hash for __BindgenUnionField { - fn hash(&self, _state: &mut H) {} -} -impl ::std::cmp::PartialEq for __BindgenUnionField { - fn eq(&self, _other: &__BindgenUnionField) -> bool { - true - } -} -impl ::std::cmp::Eq for __BindgenUnionField {} -#[repr(C)] -#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] -pub struct TErrorResult { - pub mResult: ::std::os::raw::c_int, - pub __bindgen_anon_1: TErrorResult__bindgen_ty_1, - pub mMightHaveUnreported: bool, - pub mUnionState: TErrorResult_UnionState, -} -pub const TErrorResult_UnionState_HasException: TErrorResult_UnionState = TErrorResult_UnionState::HasMessage; -#[repr(i32)] -#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] -pub enum TErrorResult_UnionState { - HasMessage = 0, -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct TErrorResult_Message { - _unused: [u8; 0], -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct TErrorResult_DOMExceptionInfo { - _unused: [u8; 0], -} -#[repr(C)] -#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] -pub struct TErrorResult__bindgen_ty_1 { - pub mMessage: __BindgenUnionField<*mut TErrorResult_Message>, - pub mDOMExceptionInfo: __BindgenUnionField<*mut TErrorResult_DOMExceptionInfo>, - pub bindgen_union_field: u64, -} -impl Default for TErrorResult { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} -#[repr(C)] -#[derive(Debug, Copy, Hash, PartialEq, Eq)] -pub struct ErrorResult { - pub _base: TErrorResult, -} -#[test] -fn bindgen_test_layout_ErrorResult() { - assert_eq!(::std::mem::size_of::(), 24usize, "Size of ErrorResult"); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - "Alignment of ErrorResult", - ); -} -impl Clone for ErrorResult { - fn clone(&self) -> Self { - *self - } -} -impl Default for ErrorResult { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} -#[test] -fn __bindgen_test_layout_TErrorResult_open0_int_close0_instantiation() { - assert_eq!( - ::std::mem::size_of::(), - 24usize, - "Size of template specialization: TErrorResult_open0_int_close0", - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - "Align of template specialization: TErrorResult_open0_int_close0", - ); -} diff --git a/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_pre_1_27.rs b/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_pre_1_27.rs deleted file mode 100644 index f545f9e6bb..0000000000 --- a/bindgen-tests/tests/expectations/tests/attribute_warn_unused_result_pre_1_27.rs +++ /dev/null @@ -1,25 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct Foo { - pub _address: u8, -} -#[allow(clippy::unnecessary_operation, clippy::identity_op)] -const _: () = { - ["Size of Foo"][::std::mem::size_of::() - 1usize]; - ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; -}; -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; -} -impl Foo { - #[inline] - pub unsafe fn foo(&mut self, arg1: ::std::os::raw::c_int) -> ::std::os::raw::c_int { - Foo_foo(self, arg1) - } -} -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 70f9216a68..f3d7893b00 100644 --- a/bindgen-tests/tests/expectations/tests/bindgen-union-inside-namespace.rs +++ b/bindgen-tests/tests/expectations/tests/bindgen-union-inside-namespace.rs @@ -1,60 +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 { - #[repr(C)] - pub struct __BindgenUnionField(::std::marker::PhantomData); - impl __BindgenUnionField { - #[inline] - pub fn new() -> Self { - __BindgenUnionField(::std::marker::PhantomData) - } - #[inline] - pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) - } - #[inline] - pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) - } - } - impl ::std::default::Default for __BindgenUnionField { - #[inline] - fn default() -> Self { - Self::new() - } - } - impl ::std::clone::Clone for __BindgenUnionField { - #[inline] - fn clone(&self) -> Self { - *self - } - } - impl ::std::marker::Copy for __BindgenUnionField {} - impl ::std::fmt::Debug for __BindgenUnionField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__BindgenUnionField") - } - } - impl ::std::hash::Hash for __BindgenUnionField { - fn hash(&self, _state: &mut H) {} - } - impl ::std::cmp::PartialEq for __BindgenUnionField { - fn eq(&self, _other: &__BindgenUnionField) -> bool { - true - } - } - impl ::std::cmp::Eq for __BindgenUnionField {} #[allow(unused_imports)] use self::super::root; pub mod foo { #[allow(unused_imports)] use self::super::super::root; #[repr(C)] - #[derive(Debug, Default, Copy)] - pub struct Bar { - pub foo: root::__BindgenUnionField<::std::os::raw::c_int>, - pub bar: root::__BindgenUnionField<::std::os::raw::c_int>, - pub bindgen_union_field: u32, + #[derive(Copy, Clone)] + pub union Bar { + pub foo: ::std::os::raw::c_int, + pub bar: ::std::os::raw::c_int, } #[test] fn bindgen_test_layout_Bar() { @@ -73,9 +29,13 @@ pub mod root { "Offset of field: Bar::bar", ); } - impl Clone for Bar { - fn clone(&self) -> Self { - *self + impl Default for Bar { + fn default() -> Self { + unsafe { + let mut s: Self = ::std::mem::uninitialized(); + ::std::ptr::write_bytes(&mut s, 0, 1); + s + } } } } diff --git a/bindgen-tests/tests/expectations/tests/bitfield-enum-repr-c.rs b/bindgen-tests/tests/expectations/tests/bitfield-enum-repr-c.rs index 0403e844e2..0b5202dfe3 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-enum-repr-c.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-enum-repr-c.rs @@ -37,6 +37,6 @@ impl ::std::ops::BitAndAssign for Foo { self.0 &= rhs.0; } } -#[repr(C)] +#[repr(transparent)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Foo(pub ::std::os::raw::c_int); diff --git a/bindgen-tests/tests/expectations/tests/class_1_0.rs b/bindgen-tests/tests/expectations/tests/class_1_0.rs deleted file mode 100644 index 9db5b3a338..0000000000 --- a/bindgen-tests/tests/expectations/tests/class_1_0.rs +++ /dev/null @@ -1,539 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -#[derive(Default)] -pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); -impl __IncompleteArrayField { - #[inline] - pub fn new() -> Self { - __IncompleteArrayField(::std::marker::PhantomData, []) - } - #[inline] - pub fn as_ptr(&self) -> *const T { - self as *const _ as *const T - } - #[inline] - pub fn as_mut_ptr(&mut self) -> *mut T { - self as *mut _ as *mut T - } - #[inline] - pub unsafe fn as_slice(&self, len: usize) -> &[T] { - ::std::slice::from_raw_parts(self.as_ptr(), len) - } - #[inline] - pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { - ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) - } -} -impl ::std::fmt::Debug for __IncompleteArrayField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__IncompleteArrayField") - } -} -#[repr(C)] -pub struct __BindgenUnionField(::std::marker::PhantomData); -impl __BindgenUnionField { - #[inline] - pub fn new() -> Self { - __BindgenUnionField(::std::marker::PhantomData) - } - #[inline] - pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) - } - #[inline] - pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) - } -} -impl ::std::default::Default for __BindgenUnionField { - #[inline] - fn default() -> Self { - Self::new() - } -} -impl ::std::clone::Clone for __BindgenUnionField { - #[inline] - fn clone(&self) -> Self { - *self - } -} -impl ::std::marker::Copy for __BindgenUnionField {} -impl ::std::fmt::Debug for __BindgenUnionField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__BindgenUnionField") - } -} -impl ::std::hash::Hash for __BindgenUnionField { - fn hash(&self, _state: &mut H) {} -} -impl ::std::cmp::PartialEq for __BindgenUnionField { - fn eq(&self, _other: &__BindgenUnionField) -> bool { - true - } -} -impl ::std::cmp::Eq for __BindgenUnionField {} -#[repr(C)] -#[derive(Copy)] -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", - ); -} -impl Clone for C { - fn clone(&self) -> Self { - *self - } -} -impl Default for C { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} -impl ::std::cmp::PartialEq for C { - fn eq(&self, other: &C) -> bool { - self.a == other.a && &self.big_array[..] == &other.big_array[..] - } -} -#[repr(C)] -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, - "Size of C_with_zero_length_array", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - "Alignment of C_with_zero_length_array", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - "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, - "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, - "Offset of field: C_with_zero_length_array::zero_length_array", - ); -} -impl Default for C_with_zero_length_array { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} -#[repr(C)] -#[derive(Debug, Default)] -pub struct C_with_zero_length_array_2 { - pub a: ::std::os::raw::c_int, - pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, -} -#[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, - "Size of C_with_zero_length_array_2", - ); - assert_eq!( - ::std::mem::align_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, - "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, - "Offset of field: C_with_zero_length_array_2::zero_length_array", - ); -} -#[repr(C)] -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, - "Size of C_with_incomplete_array", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - "Alignment of C_with_incomplete_array", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - "Offset of field: C_with_incomplete_array::a", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).big_array) as usize - ptr as usize }, - 4usize, - "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, - "Offset of field: C_with_incomplete_array::incomplete_array", - ); -} -impl Default for C_with_incomplete_array { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} -#[repr(C)] -#[derive(Debug, Default)] -pub struct C_with_incomplete_array_2 { - pub a: ::std::os::raw::c_int, - pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, -} -#[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, - "Size of C_with_incomplete_array_2", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - "Alignment of C_with_incomplete_array_2", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - "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, - "Offset of field: C_with_incomplete_array_2::incomplete_array", - ); -} -#[repr(C)] -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, - "Size of C_with_zero_length_array_and_incomplete_array", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - "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, - "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, - "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, - "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, - "Offset of field: C_with_zero_length_array_and_incomplete_array::incomplete_array", - ); -} -impl Default for C_with_zero_length_array_and_incomplete_array { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} -#[repr(C)] -#[derive(Debug, Default)] -pub struct C_with_zero_length_array_and_incomplete_array_2 { - pub a: ::std::os::raw::c_int, - pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, - pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, -} -#[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, - "Size of C_with_zero_length_array_and_incomplete_array_2", - ); - assert_eq!( - ::std::mem::align_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, - "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, - "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, - "Offset of field: C_with_zero_length_array_and_incomplete_array_2::incomplete_array", - ); -} -#[repr(C)] -#[derive(Debug, Default, Hash, 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", - ); -} -#[repr(C)] -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, - "Size of IncompleteArrayNonCopiable", - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - "Alignment of IncompleteArrayNonCopiable", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).whatever) as usize - ptr as usize }, - 0usize, - "Offset of field: IncompleteArrayNonCopiable::whatever", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).incomplete_array) as usize - ptr as usize }, - 8usize, - "Offset of field: IncompleteArrayNonCopiable::incomplete_array", - ); -} -impl Default for IncompleteArrayNonCopiable { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq)] -pub struct Union { - pub d: __BindgenUnionField, - pub i: __BindgenUnionField<::std::os::raw::c_int>, - pub bindgen_union_field: u32, -} -#[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", - ); -} -impl Clone for Union { - fn clone(&self) -> Self { - *self - } -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq)] -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, - "Offset of field: WithUnion::data", - ); -} -impl Clone for WithUnion { - fn clone(&self) -> Self { - *self - } -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct RealAbstractionWithTonsOfMethods { - pub _address: u8, -} -#[test] -fn bindgen_test_layout_RealAbstractionWithTonsOfMethods() { - assert_eq!( - ::std::mem::size_of::(), - 1usize, - "Size of RealAbstractionWithTonsOfMethods", - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - "Alignment of RealAbstractionWithTonsOfMethods", - ); -} -extern "C" { - #[link_name = "\u{1}_ZNK32RealAbstractionWithTonsOfMethods3barEv"] - pub fn RealAbstractionWithTonsOfMethods_bar( - this: *const RealAbstractionWithTonsOfMethods, - ); -} -extern "C" { - #[link_name = "\u{1}_ZN32RealAbstractionWithTonsOfMethods3barEv"] - pub fn RealAbstractionWithTonsOfMethods_bar1( - this: *mut RealAbstractionWithTonsOfMethods, - ); -} -extern "C" { - #[link_name = "\u{1}_ZN32RealAbstractionWithTonsOfMethods3barEi"] - pub fn RealAbstractionWithTonsOfMethods_bar2( - this: *mut RealAbstractionWithTonsOfMethods, - foo: ::std::os::raw::c_int, - ); -} -extern "C" { - #[link_name = "\u{1}_ZN32RealAbstractionWithTonsOfMethods3staEv"] - pub fn RealAbstractionWithTonsOfMethods_sta(); -} -impl Clone for RealAbstractionWithTonsOfMethods { - fn clone(&self) -> Self { - *self - } -} -impl RealAbstractionWithTonsOfMethods { - #[inline] - pub unsafe fn bar(&self) { - RealAbstractionWithTonsOfMethods_bar(self) - } - #[inline] - pub unsafe fn bar1(&mut self) { - RealAbstractionWithTonsOfMethods_bar1(self) - } - #[inline] - pub unsafe fn bar2(&mut self, foo: ::std::os::raw::c_int) { - RealAbstractionWithTonsOfMethods_bar2(self, foo) - } - #[inline] - pub unsafe fn sta() { - RealAbstractionWithTonsOfMethods_sta() - } -} diff --git a/bindgen-tests/tests/expectations/tests/class_with_inner_struct_1_0.rs b/bindgen-tests/tests/expectations/tests/class_with_inner_struct_1_0.rs deleted file mode 100644 index 23afad6319..0000000000 --- a/bindgen-tests/tests/expectations/tests/class_with_inner_struct_1_0.rs +++ /dev/null @@ -1,397 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -pub struct __BindgenUnionField(::std::marker::PhantomData); -impl __BindgenUnionField { - #[inline] - pub fn new() -> Self { - __BindgenUnionField(::std::marker::PhantomData) - } - #[inline] - pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) - } - #[inline] - pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) - } -} -impl ::std::default::Default for __BindgenUnionField { - #[inline] - fn default() -> Self { - Self::new() - } -} -impl ::std::clone::Clone for __BindgenUnionField { - #[inline] - fn clone(&self) -> Self { - *self - } -} -impl ::std::marker::Copy for __BindgenUnionField {} -impl ::std::fmt::Debug for __BindgenUnionField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__BindgenUnionField") - } -} -impl ::std::hash::Hash for __BindgenUnionField { - fn hash(&self, _state: &mut H) {} -} -impl ::std::cmp::PartialEq for __BindgenUnionField { - fn eq(&self, _other: &__BindgenUnionField) -> bool { - true - } -} -impl ::std::cmp::Eq for __BindgenUnionField {} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct A { - pub c: ::std::os::raw::c_uint, - pub named_union: A__bindgen_ty_1, - pub __bindgen_anon_1: A__bindgen_ty_2, -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct A_Segment { - pub begin: ::std::os::raw::c_int, - pub end: ::std::os::raw::c_int, -} -#[test] -fn bindgen_test_layout_A_Segment() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 8usize, "Size of A_Segment"); - assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of A_Segment"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize }, - 0usize, - "Offset of field: A_Segment::begin", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize }, - 4usize, - "Offset of field: A_Segment::end", - ); -} -impl Clone for A_Segment { - fn clone(&self) -> Self { - *self - } -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct A__bindgen_ty_1 { - pub f: __BindgenUnionField<::std::os::raw::c_int>, - pub bindgen_union_field: u32, -} -#[test] -fn bindgen_test_layout_A__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - "Size of A__bindgen_ty_1", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - "Alignment of A__bindgen_ty_1", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, - 0usize, - "Offset of field: A__bindgen_ty_1::f", - ); -} -impl Clone for A__bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct A__bindgen_ty_2 { - pub d: __BindgenUnionField<::std::os::raw::c_int>, - pub bindgen_union_field: u32, -} -#[test] -fn bindgen_test_layout_A__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - "Size of A__bindgen_ty_2", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - "Alignment of A__bindgen_ty_2", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 0usize, - "Offset of field: A__bindgen_ty_2::d", - ); -} -impl Clone for A__bindgen_ty_2 { - fn clone(&self) -> Self { - *self - } -} -#[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::(), 12usize, "Size of A"); - assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of A"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }, - 0usize, - "Offset of field: A::c", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).named_union) as usize - ptr as usize }, - 4usize, - "Offset of field: A::named_union", - ); -} -impl Clone for A { - fn clone(&self) -> Self { - *self - } -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct B { - pub d: ::std::os::raw::c_uint, -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct B_Segment { - pub begin: ::std::os::raw::c_int, - pub end: ::std::os::raw::c_int, -} -#[test] -fn bindgen_test_layout_B_Segment() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 8usize, "Size of B_Segment"); - assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of B_Segment"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize }, - 0usize, - "Offset of field: B_Segment::begin", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize }, - 4usize, - "Offset of field: B_Segment::end", - ); -} -impl Clone for B_Segment { - fn clone(&self) -> Self { - *self - } -} -#[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::(), 4usize, "Size of B"); - assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of B"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 0usize, - "Offset of field: B::d", - ); -} -impl Clone for B { - fn clone(&self) -> Self { - *self - } -} -#[repr(i32)] -#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] -pub enum StepSyntax { - Keyword = 0, - FunctionalWithoutKeyword = 1, - FunctionalWithStartKeyword = 2, - FunctionalWithEndKeyword = 3, -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq)] -pub struct C { - pub d: ::std::os::raw::c_uint, - pub __bindgen_anon_1: C__bindgen_ty_1, -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq)] -pub struct C__bindgen_ty_1 { - pub mFunc: __BindgenUnionField, - pub __bindgen_anon_1: __BindgenUnionField, - pub bindgen_union_field: [u32; 4usize], -} -#[repr(C)] -#[derive(Debug, Default, Copy, PartialEq)] -pub struct C__bindgen_ty_1__bindgen_ty_1 { - pub mX1: f32, - pub mY1: f32, - pub mX2: f32, - pub mY2: f32, -} -#[test] -fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - "Size of C__bindgen_ty_1__bindgen_ty_1", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - "Alignment of C__bindgen_ty_1__bindgen_ty_1", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mX1) as usize - ptr as usize }, - 0usize, - "Offset of field: C__bindgen_ty_1__bindgen_ty_1::mX1", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mY1) as usize - ptr as usize }, - 4usize, - "Offset of field: C__bindgen_ty_1__bindgen_ty_1::mY1", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mX2) as usize - ptr as usize }, - 8usize, - "Offset of field: C__bindgen_ty_1__bindgen_ty_1::mX2", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mY2) as usize - ptr as usize }, - 12usize, - "Offset of field: C__bindgen_ty_1__bindgen_ty_1::mY2", - ); -} -impl Clone for C__bindgen_ty_1__bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} -#[repr(C)] -#[derive(Debug, Copy, Hash, PartialEq, Eq)] -pub struct C__bindgen_ty_1__bindgen_ty_2 { - pub mStepSyntax: StepSyntax, - pub mSteps: ::std::os::raw::c_uint, -} -#[test] -fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - "Size of C__bindgen_ty_1__bindgen_ty_2", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - "Alignment of C__bindgen_ty_1__bindgen_ty_2", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mStepSyntax) as usize - ptr as usize }, - 0usize, - "Offset of field: C__bindgen_ty_1__bindgen_ty_2::mStepSyntax", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mSteps) as usize - ptr as usize }, - 4usize, - "Offset of field: C__bindgen_ty_1__bindgen_ty_2::mSteps", - ); -} -impl Clone for C__bindgen_ty_1__bindgen_ty_2 { - fn clone(&self) -> Self { - *self - } -} -impl Default for C__bindgen_ty_1__bindgen_ty_2 { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} -#[test] -fn bindgen_test_layout_C__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - "Size of C__bindgen_ty_1", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - "Alignment of C__bindgen_ty_1", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).mFunc) as usize - ptr as usize }, - 0usize, - "Offset of field: C__bindgen_ty_1::mFunc", - ); -} -impl Clone for C__bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct C_Segment { - pub begin: ::std::os::raw::c_int, - pub end: ::std::os::raw::c_int, -} -#[test] -fn bindgen_test_layout_C_Segment() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 8usize, "Size of C_Segment"); - assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of C_Segment"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).begin) as usize - ptr as usize }, - 0usize, - "Offset of field: C_Segment::begin", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize }, - 4usize, - "Offset of field: C_Segment::end", - ); -} -impl Clone for C_Segment { - fn clone(&self) -> Self { - *self - } -} -#[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::(), 20usize, "Size of C"); - assert_eq!(::std::mem::align_of::(), 4usize, "Alignment of C"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }, - 0usize, - "Offset of field: C::d", - ); -} -impl Clone for C { - fn clone(&self) -> Self { - *self - } -} diff --git a/bindgen-tests/tests/expectations/tests/derive-clone_1_0.rs b/bindgen-tests/tests/expectations/tests/derive-clone_1_0.rs deleted file mode 100644 index 7b3a00738c..0000000000 --- a/bindgen-tests/tests/expectations/tests/derive-clone_1_0.rs +++ /dev/null @@ -1,42 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -/** Since builtin `Clone` impls were introduced in Rust 1.21 this struct - should impl `Clone` "manually".*/ -#[repr(C)] -#[derive(Copy)] -pub struct ShouldImplClone { - pub large: [::std::os::raw::c_int; 33usize], -} -#[test] -fn bindgen_test_layout_ShouldImplClone() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 132usize, - "Size of ShouldImplClone", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - "Alignment of ShouldImplClone", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).large) as usize - ptr as usize }, - 0usize, - "Offset of field: ShouldImplClone::large", - ); -} -impl Clone for ShouldImplClone { - fn clone(&self) -> Self { - *self - } -} -impl Default for ShouldImplClone { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} diff --git a/bindgen-tests/tests/expectations/tests/derive-partialeq-union_1_0.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-union_1_0.rs deleted file mode 100644 index f120f4fc12..0000000000 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-union_1_0.rs +++ /dev/null @@ -1,96 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -pub struct __BindgenUnionField(::std::marker::PhantomData); -impl __BindgenUnionField { - #[inline] - pub fn new() -> Self { - __BindgenUnionField(::std::marker::PhantomData) - } - #[inline] - pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) - } - #[inline] - pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) - } -} -impl ::std::default::Default for __BindgenUnionField { - #[inline] - fn default() -> Self { - Self::new() - } -} -impl ::std::clone::Clone for __BindgenUnionField { - #[inline] - fn clone(&self) -> Self { - *self - } -} -impl ::std::marker::Copy for __BindgenUnionField {} -impl ::std::fmt::Debug for __BindgenUnionField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__BindgenUnionField") - } -} -impl ::std::hash::Hash for __BindgenUnionField { - fn hash(&self, _state: &mut H) {} -} -impl ::std::cmp::PartialEq for __BindgenUnionField { - fn eq(&self, _other: &__BindgenUnionField) -> bool { - true - } -} -impl ::std::cmp::Eq for __BindgenUnionField {} -/// This should manually derive PartialEq. -#[repr(C)] -#[derive(Copy)] -pub struct ShouldDerivePartialEq { - pub a: __BindgenUnionField<[::std::os::raw::c_char; 150usize]>, - pub b: __BindgenUnionField<::std::os::raw::c_int>, - pub bindgen_union_field: [u32; 38usize], -} -#[test] -fn bindgen_test_layout_ShouldDerivePartialEq() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 152usize, - "Size of ShouldDerivePartialEq", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - "Alignment of ShouldDerivePartialEq", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).a) as usize - ptr as usize }, - 0usize, - "Offset of field: ShouldDerivePartialEq::a", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).b) as usize - ptr as usize }, - 0usize, - "Offset of field: ShouldDerivePartialEq::b", - ); -} -impl Clone for ShouldDerivePartialEq { - fn clone(&self) -> Self { - *self - } -} -impl Default for ShouldDerivePartialEq { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} -impl ::std::cmp::PartialEq for ShouldDerivePartialEq { - fn eq(&self, other: &ShouldDerivePartialEq) -> bool { - &self.bindgen_union_field[..] == &other.bindgen_union_field[..] - } -} diff --git a/bindgen-tests/tests/expectations/tests/forward_declared_complex_types_1_0.rs b/bindgen-tests/tests/expectations/tests/forward_declared_complex_types_1_0.rs deleted file mode 100644 index e891a6b01b..0000000000 --- a/bindgen-tests/tests/expectations/tests/forward_declared_complex_types_1_0.rs +++ /dev/null @@ -1,89 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -#[derive(Debug, Default, Copy)] -pub struct Foo_empty { - pub _address: u8, -} -#[test] -fn bindgen_test_layout_Foo_empty() { - assert_eq!(::std::mem::size_of::(), 1usize, "Size of Foo_empty"); - assert_eq!(::std::mem::align_of::(), 1usize, "Alignment of Foo_empty"); -} -impl Clone for Foo_empty { - fn clone(&self) -> Self { - *self - } -} -#[repr(C)] -#[derive(Debug, Copy)] -pub struct Foo { - _unused: [u8; 0], -} -impl Clone for Foo { - fn clone(&self) -> Self { - *self - } -} -#[repr(C)] -#[derive(Debug, Copy)] -pub struct Bar { - pub f: *mut Foo, -} -#[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::(), 8usize, "Size of Bar"); - assert_eq!(::std::mem::align_of::(), 8usize, "Alignment of Bar"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).f) as usize - ptr as usize }, - 0usize, - "Offset of field: Bar::f", - ); -} -impl Clone for Bar { - fn clone(&self) -> Self { - *self - } -} -impl Default for Bar { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} -extern "C" { - #[link_name = "\u{1}_Z10baz_structP3Foo"] - pub fn baz_struct(f: *mut Foo); -} -#[repr(C)] -#[derive(Debug, Copy)] -pub struct Union { - _unused: [u8; 0], -} -impl Clone for Union { - fn clone(&self) -> Self { - *self - } -} -extern "C" { - #[link_name = "\u{1}_Z9baz_unionP5Union"] - pub fn baz_union(u: *mut Union); -} -#[repr(C)] -#[derive(Debug, Copy)] -pub struct Quux { - _unused: [u8; 0], -} -impl Clone for Quux { - fn clone(&self) -> Self { - *self - } -} -extern "C" { - #[link_name = "\u{1}_Z9baz_classP4Quux"] - pub fn baz_class(q: *mut Quux); -} diff --git a/bindgen-tests/tests/expectations/tests/issue-493_1_0.rs b/bindgen-tests/tests/expectations/tests/issue-493_1_0.rs deleted file mode 100644 index ff0c93428b..0000000000 --- a/bindgen-tests/tests/expectations/tests/issue-493_1_0.rs +++ /dev/null @@ -1,136 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -pub struct __BindgenUnionField(::std::marker::PhantomData); -impl __BindgenUnionField { - #[inline] - pub fn new() -> Self { - __BindgenUnionField(::std::marker::PhantomData) - } - #[inline] - pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) - } - #[inline] - pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) - } -} -impl ::std::default::Default for __BindgenUnionField { - #[inline] - fn default() -> Self { - Self::new() - } -} -impl ::std::clone::Clone for __BindgenUnionField { - #[inline] - fn clone(&self) -> Self { - *self - } -} -impl ::std::marker::Copy for __BindgenUnionField {} -impl ::std::fmt::Debug for __BindgenUnionField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__BindgenUnionField") - } -} -impl ::std::hash::Hash for __BindgenUnionField { - fn hash(&self, _state: &mut H) {} -} -impl ::std::cmp::PartialEq for __BindgenUnionField { - fn eq(&self, _other: &__BindgenUnionField) -> bool { - true - } -} -impl ::std::cmp::Eq for __BindgenUnionField {} -#[repr(C)] -#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] -pub struct basic_string { - pub _address: u8, -} -pub type basic_string_size_type = ::std::os::raw::c_ulonglong; -pub type basic_string_value_type = ::std::os::raw::c_char; -pub type basic_string_pointer = *mut basic_string_value_type; -#[repr(C)] -#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] -pub struct basic_string___long { - pub __cap_: basic_string_size_type, - pub __size_: basic_string_size_type, - pub __data_: basic_string_pointer, -} -impl Default for basic_string___long { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} -pub const basic_string___min_cap: basic_string__bindgen_ty_1 = basic_string__bindgen_ty_1::__min_cap; -#[repr(i32)] -#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] -pub enum basic_string__bindgen_ty_1 { - __min_cap = 0, -} -#[repr(C)] -#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] -pub struct basic_string___short { - pub __bindgen_anon_1: basic_string___short__bindgen_ty_1, - pub __data_: *mut basic_string_value_type, -} -#[repr(C)] -#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] -pub struct basic_string___short__bindgen_ty_1 { - pub __size_: __BindgenUnionField<::std::os::raw::c_uchar>, - pub __lx: __BindgenUnionField, - pub bindgen_union_field: u8, -} -impl Default for basic_string___short { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} -#[repr(C)] -#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] -pub struct basic_string___ulx { - pub __lx: __BindgenUnionField, - pub __lxx: __BindgenUnionField, - pub bindgen_union_field: [u8; 0usize], -} -pub const basic_string___n_words: basic_string__bindgen_ty_2 = basic_string__bindgen_ty_2::__n_words; -#[repr(i32)] -#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] -pub enum basic_string__bindgen_ty_2 { - __n_words = 0, -} -#[repr(C)] -#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] -pub struct basic_string___raw { - pub __words: *mut basic_string_size_type, -} -impl Default for basic_string___raw { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} -#[repr(C)] -#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] -pub struct basic_string___rep { - pub __bindgen_anon_1: basic_string___rep__bindgen_ty_1, -} -#[repr(C)] -#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] -pub struct basic_string___rep__bindgen_ty_1 { - pub __l: __BindgenUnionField, - pub __s: __BindgenUnionField, - pub __r: __BindgenUnionField, - pub bindgen_union_field: [u8; 0usize], -} diff --git a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs deleted file mode 100644 index 422782d66d..0000000000 --- a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque_1_0.rs +++ /dev/null @@ -1,459 +0,0 @@ -#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -#[repr(C)] -#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct __BindgenBitfieldUnit { - storage: Storage, -} -impl __BindgenBitfieldUnit { - #[inline] - pub 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] - 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 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 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); - } - } -} -#[repr(C)] -pub struct __BindgenUnionField(::std::marker::PhantomData); -impl __BindgenUnionField { - #[inline] - pub fn new() -> Self { - __BindgenUnionField(::std::marker::PhantomData) - } - #[inline] - pub unsafe fn as_ref(&self) -> &T { - ::std::mem::transmute(self) - } - #[inline] - pub unsafe fn as_mut(&mut self) -> &mut T { - ::std::mem::transmute(self) - } -} -impl ::std::default::Default for __BindgenUnionField { - #[inline] - fn default() -> Self { - Self::new() - } -} -impl ::std::clone::Clone for __BindgenUnionField { - #[inline] - fn clone(&self) -> Self { - *self - } -} -impl ::std::marker::Copy for __BindgenUnionField {} -impl ::std::fmt::Debug for __BindgenUnionField { - fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - fmt.write_str("__BindgenUnionField") - } -} -impl ::std::hash::Hash for __BindgenUnionField { - fn hash(&self, _state: &mut H) {} -} -impl ::std::cmp::PartialEq for __BindgenUnionField { - fn eq(&self, _other: &__BindgenUnionField) -> bool { - true - } -} -impl ::std::cmp::Eq for __BindgenUnionField {} -pub const JSVAL_TAG_SHIFT: u32 = 47; -pub const JSVAL_PAYLOAD_MASK: u64 = 140737488355327; -pub const JSVAL_TAG_MASK: i64 = -140737488355328; -#[repr(u8)] -#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] -pub enum JSValueType { - JSVAL_TYPE_DOUBLE = 0, - JSVAL_TYPE_INT32 = 1, - JSVAL_TYPE_UNDEFINED = 2, - JSVAL_TYPE_BOOLEAN = 3, - JSVAL_TYPE_MAGIC = 4, - JSVAL_TYPE_STRING = 5, - JSVAL_TYPE_SYMBOL = 6, - JSVAL_TYPE_NULL = 7, - JSVAL_TYPE_OBJECT = 8, - JSVAL_TYPE_UNKNOWN = 32, - JSVAL_TYPE_MISSING = 33, -} -#[repr(u32)] -#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] -pub enum JSValueTag { - JSVAL_TAG_MAX_DOUBLE = 131056, - JSVAL_TAG_INT32 = 131057, - JSVAL_TAG_UNDEFINED = 131058, - JSVAL_TAG_STRING = 131061, - JSVAL_TAG_SYMBOL = 131062, - JSVAL_TAG_BOOLEAN = 131059, - JSVAL_TAG_MAGIC = 131060, - JSVAL_TAG_NULL = 131063, - JSVAL_TAG_OBJECT = 131064, -} -#[repr(u64)] -#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] -pub enum JSValueShiftedTag { - JSVAL_SHIFTED_TAG_MAX_DOUBLE = 18444492278190833663, - JSVAL_SHIFTED_TAG_INT32 = 18444633011384221696, - JSVAL_SHIFTED_TAG_UNDEFINED = 18444773748872577024, - JSVAL_SHIFTED_TAG_STRING = 18445195961337643008, - JSVAL_SHIFTED_TAG_SYMBOL = 18445336698825998336, - JSVAL_SHIFTED_TAG_BOOLEAN = 18444914486360932352, - JSVAL_SHIFTED_TAG_MAGIC = 18445055223849287680, - JSVAL_SHIFTED_TAG_NULL = 18445477436314353664, - JSVAL_SHIFTED_TAG_OBJECT = 18445618173802708992, -} -#[repr(u32)] -#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] -pub enum JSWhyMagic { - /// a hole in a native object's elements - JS_ELEMENTS_HOLE = 0, - /// there is not a pending iterator value - JS_NO_ITER_VALUE = 1, - /// exception value thrown when closing a generator - JS_GENERATOR_CLOSING = 2, - /// compiler sentinel value - JS_NO_CONSTANT = 3, - /// used in debug builds to catch tracing errors - JS_THIS_POISON = 4, - /// used in debug builds to catch tracing errors - JS_ARG_POISON = 5, - /// an empty subnode in the AST serializer - JS_SERIALIZE_NO_NODE = 6, - /// lazy arguments value on the stack - JS_LAZY_ARGUMENTS = 7, - /// optimized-away 'arguments' value - JS_OPTIMIZED_ARGUMENTS = 8, - /// magic value passed to natives to indicate construction - JS_IS_CONSTRUCTING = 9, - /// arguments.callee has been overwritten - JS_OVERWRITTEN_CALLEE = 10, - /// value of static block object slot - JS_BLOCK_NEEDS_CLONE = 11, - /// see class js::HashableValue - JS_HASH_KEY_EMPTY = 12, - /// error while running Ion code - JS_ION_ERROR = 13, - /// missing recover instruction result - JS_ION_BAILOUT = 14, - /// optimized out slot - JS_OPTIMIZED_OUT = 15, - /// uninitialized lexical bindings that produce ReferenceError on touch. - JS_UNINITIALIZED_LEXICAL = 16, - /// for local use - JS_GENERIC_MAGIC = 17, - /// for local use - JS_WHY_MAGIC_COUNT = 18, -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq)] -pub struct jsval_layout { - pub asBits: __BindgenUnionField, - pub debugView: __BindgenUnionField, - pub s: __BindgenUnionField, - pub asDouble: __BindgenUnionField, - pub asPtr: __BindgenUnionField<*mut ::std::os::raw::c_void>, - pub asWord: __BindgenUnionField, - pub asUIntPtr: __BindgenUnionField, - pub bindgen_union_field: u64, -} -#[repr(C)] -#[derive(Debug, Copy, Hash, PartialEq, Eq)] -pub struct jsval_layout__bindgen_ty_1 { - pub _bitfield_align_1: [u64; 0], - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 8usize]>, -} -#[test] -fn bindgen_test_layout_jsval_layout__bindgen_ty_1() { - assert_eq!( - ::std::mem::size_of::(), - 8usize, - "Size of jsval_layout__bindgen_ty_1", - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - "Alignment of jsval_layout__bindgen_ty_1", - ); -} -impl Clone for jsval_layout__bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} -impl Default for jsval_layout__bindgen_ty_1 { - fn default() -> Self { - unsafe { - let mut s: Self = ::std::mem::uninitialized(); - ::std::ptr::write_bytes(&mut s, 0, 1); - s - } - } -} -impl jsval_layout__bindgen_ty_1 { - #[inline] - pub fn payload47(&self) -> u64 { - unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 47u8) as u64) } - } - #[inline] - pub fn set_payload47(&mut self, val: u64) { - unsafe { - let val: u64 = ::std::mem::transmute(val); - self._bitfield_1.set(0usize, 47u8, val as u64) - } - } - #[inline] - pub fn tag(&self) -> JSValueTag { - unsafe { ::std::mem::transmute(self._bitfield_1.get(47usize, 17u8) as u32) } - } - #[inline] - pub fn set_tag(&mut self, val: JSValueTag) { - unsafe { - let val: u32 = ::std::mem::transmute(val); - self._bitfield_1.set(47usize, 17u8, val as u64) - } - } - #[inline] - pub fn new_bitfield_1( - payload47: u64, - tag: JSValueTag, - ) -> __BindgenBitfieldUnit<[u8; 8usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 8usize]> = Default::default(); - __bindgen_bitfield_unit - .set( - 0usize, - 47u8, - { - let payload47: u64 = unsafe { ::std::mem::transmute(payload47) }; - payload47 as u64 - }, - ); - __bindgen_bitfield_unit - .set( - 47usize, - 17u8, - { - let tag: u32 = unsafe { ::std::mem::transmute(tag) }; - tag as u64 - }, - ); - __bindgen_bitfield_unit - } -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct jsval_layout__bindgen_ty_2 { - pub payload: jsval_layout__bindgen_ty_2__bindgen_ty_1, -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq, Eq)] -pub struct jsval_layout__bindgen_ty_2__bindgen_ty_1 { - pub i32_: __BindgenUnionField, - pub u32_: __BindgenUnionField, - pub why: __BindgenUnionField, - pub bindgen_union_field: u32, -} -#[test] -fn bindgen_test_layout_jsval_layout__bindgen_ty_2__bindgen_ty_1() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - "Size of jsval_layout__bindgen_ty_2__bindgen_ty_1", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - "Alignment of jsval_layout__bindgen_ty_2__bindgen_ty_1", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).i32_) as usize - ptr as usize }, - 0usize, - "Offset of field: jsval_layout__bindgen_ty_2__bindgen_ty_1::i32_", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).u32_) as usize - ptr as usize }, - 0usize, - "Offset of field: jsval_layout__bindgen_ty_2__bindgen_ty_1::u32_", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).why) as usize - ptr as usize }, - 0usize, - "Offset of field: jsval_layout__bindgen_ty_2__bindgen_ty_1::why", - ); -} -impl Clone for jsval_layout__bindgen_ty_2__bindgen_ty_1 { - fn clone(&self) -> Self { - *self - } -} -#[test] -fn bindgen_test_layout_jsval_layout__bindgen_ty_2() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - "Size of jsval_layout__bindgen_ty_2", - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - "Alignment of jsval_layout__bindgen_ty_2", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).payload) as usize - ptr as usize }, - 0usize, - "Offset of field: jsval_layout__bindgen_ty_2::payload", - ); -} -impl Clone for jsval_layout__bindgen_ty_2 { - fn clone(&self) -> Self { - *self - } -} -#[test] -fn bindgen_test_layout_jsval_layout() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 8usize, "Size of jsval_layout"); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - "Alignment of jsval_layout", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).asBits) as usize - ptr as usize }, - 0usize, - "Offset of field: jsval_layout::asBits", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).debugView) as usize - ptr as usize }, - 0usize, - "Offset of field: jsval_layout::debugView", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).s) as usize - ptr as usize }, - 0usize, - "Offset of field: jsval_layout::s", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).asDouble) as usize - ptr as usize }, - 0usize, - "Offset of field: jsval_layout::asDouble", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).asPtr) as usize - ptr as usize }, - 0usize, - "Offset of field: jsval_layout::asPtr", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).asWord) as usize - ptr as usize }, - 0usize, - "Offset of field: jsval_layout::asWord", - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).asUIntPtr) as usize - ptr as usize }, - 0usize, - "Offset of field: jsval_layout::asUIntPtr", - ); -} -impl Clone for jsval_layout { - fn clone(&self) -> Self { - *self - } -} -#[repr(C)] -#[derive(Debug, Default, Copy, Hash, PartialEq)] -pub struct Value { - pub data: jsval_layout, -} -#[test] -fn bindgen_test_layout_Value() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!(::std::mem::size_of::(), 8usize, "Size of Value"); - assert_eq!(::std::mem::align_of::(), 8usize, "Alignment of Value"); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize }, - 0usize, - "Offset of field: Value::data", - ); -} -impl Clone for Value { - fn clone(&self) -> Self { - *self - } -} diff --git a/bindgen-tests/tests/expectations/tests/layout.rs b/bindgen-tests/tests/expectations/tests/layout.rs index 8c4819f543..073f184f11 100644 --- a/bindgen-tests/tests/expectations/tests/layout.rs +++ b/bindgen-tests/tests/expectations/tests/layout.rs @@ -1,11 +1,62 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] +#[derive(Default)] +pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); +impl __IncompleteArrayField { + #[inline] + pub const fn new() -> Self { + __IncompleteArrayField(::std::marker::PhantomData, []) + } + #[inline] + pub fn as_ptr(&self) -> *const T { + self as *const _ as *const T + } + #[inline] + pub fn as_mut_ptr(&mut self) -> *mut T { + self as *mut _ as *mut T + } + #[inline] + pub unsafe fn as_slice(&self, len: usize) -> &[T] { + ::std::slice::from_raw_parts(self.as_ptr(), len) + } + #[inline] + pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { + ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) + } +} +impl ::std::fmt::Debug for __IncompleteArrayField { + fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + fmt.write_str("__IncompleteArrayField") + } +} +#[repr(C, packed(16))] +#[repr(align(16))] pub struct header { - pub _bindgen_opaque_blob: [u8; 16usize], + pub proto: ::std::os::raw::c_char, + pub size: ::std::os::raw::c_uint, + pub data: __IncompleteArrayField<::std::os::raw::c_uchar>, } #[test] fn bindgen_test_layout_header() { + const UNINIT: ::std::mem::MaybeUninit

", - mangled - )?; + writeln!(out, "")?; } Ok(()) @@ -209,7 +205,7 @@ impl FromStr for Abi { "win64" => Ok(Self::Win64), "C-unwind" => Ok(Self::CUnwind), "system" => Ok(Self::System), - _ => Err(format!("Invalid or unknown ABI {:?}", s)), + _ => Err(format!("Invalid or unknown ABI {s:?}")), } } } @@ -261,8 +257,7 @@ impl quote::ToTokens for ClangAbi { match *self { Self::Known(abi) => abi.to_tokens(tokens), Self::Unknown(cc) => panic!( - "Cannot turn unknown calling convention to tokens: {:?}", - cc + "Cannot turn unknown calling convention to tokens: {cc:?}" ), } } diff --git a/bindgen/ir/item.rs b/bindgen/ir/item.rs index 67976c9805..ea82ec5f75 100644 --- a/bindgen/ir/item.rs +++ b/bindgen/ir/item.rs @@ -727,7 +727,7 @@ impl Item { to.push_str(&self.canonical_name(ctx)); if let ItemKind::Type(ref ty) = *self.kind() { if let TypeKind::TemplateInstantiation(ref inst) = *ty.kind() { - to.push_str(&format!("_open{}_", level)); + to.push_str(&format!("_open{level}_")); for arg in inst.template_arguments() { arg.into_resolver() .through_type_refs() @@ -735,7 +735,7 @@ impl Item { .push_disambiguated_name(ctx, to, level + 1); to.push('_'); } - to.push_str(&format!("close{}", level)); + to.push_str(&format!("close{level}")); } } } @@ -801,7 +801,7 @@ impl Item { if let Some(idx) = self.overload_index(ctx) { if idx > 0 { - write!(&mut name, "{}", idx).unwrap(); + write!(&mut name, "{idx}").unwrap(); } } diff --git a/bindgen/ir/objc.rs b/bindgen/ir/objc.rs index d7f7cc65a6..a748d9a171 100644 --- a/bindgen/ir/objc.rs +++ b/bindgen/ir/objc.rs @@ -262,10 +262,7 @@ impl ObjCMethod { // unless it is `crate`, `self`, `super` or `Self`, so we try to add the `_` // suffix to it and parse it. if ["crate", "self", "super", "Self"].contains(&name) { - Some(Ident::new( - &format!("{}_", name), - Span::call_site(), - )) + Some(Ident::new(&format!("{name}_"), Span::call_site())) } else { Some(Ident::new(name, Span::call_site())) } @@ -278,11 +275,11 @@ impl ObjCMethod { Some( syn::parse_str::(name) .or_else(|err| { - syn::parse_str::(&format!("r#{}", name)) + syn::parse_str::(&format!("r#{name}")) .map_err(|_| err) }) .or_else(|err| { - syn::parse_str::(&format!("{}_", name)) + syn::parse_str::(&format!("{name}_")) .map_err(|_| err) }) .expect("Invalid identifier"), @@ -302,9 +299,7 @@ impl ObjCMethod { // Check right amount of arguments assert!( args.len() == split_name.len() - 1, - "Incorrect method name or arguments for objc method, {:?} vs {:?}", - args, - split_name + "Incorrect method name or arguments for objc method, {args:?} vs {split_name:?}" ); // Get arguments without type signatures to pass to `msg_send!` diff --git a/bindgen/ir/traversal.rs b/bindgen/ir/traversal.rs index 17e24f701e..9a0a02b8c4 100644 --- a/bindgen/ir/traversal.rs +++ b/bindgen/ir/traversal.rs @@ -287,8 +287,7 @@ impl<'ctx> TraversalStorage<'ctx> for Paths<'ctx> { } path.reverse(); panic!( - "Found reference to dangling id = {:?}\nvia path = {:?}", - item, path + "Found reference to dangling id = {item:?}\nvia path = {path:?}" ); } diff --git a/bindgen/ir/ty.rs b/bindgen/ir/ty.rs index d527b1c778..8f39a2c388 100644 --- a/bindgen/ir/ty.rs +++ b/bindgen/ir/ty.rs @@ -261,7 +261,7 @@ impl Type { TypeKind::Pointer(inner) => Some((inner, Cow::Borrowed("ptr"))), TypeKind::Reference(inner) => Some((inner, Cow::Borrowed("ref"))), TypeKind::Array(inner, length) => { - Some((inner, format!("array{}", length).into())) + Some((inner, format!("array{length}").into())) } _ => None, }; @@ -269,7 +269,7 @@ impl Type { ctx.resolve_item(inner) .expect_type() .sanitized_name(ctx) - .map(|name| format!("{}_{}", prefix, name).into()) + .map(|name| format!("{prefix}_{name}").into()) } else { self.name().map(Self::sanitize_name) } diff --git a/bindgen/ir/var.rs b/bindgen/ir/var.rs index 01c57704d3..707d14f470 100644 --- a/bindgen/ir/var.rs +++ b/bindgen/ir/var.rs @@ -113,11 +113,7 @@ impl DotAttributes for Var { } if let Some(ref mangled) = self.mangled_name { - writeln!( - out, - "", - mangled - )?; + writeln!(out, "")?; } Ok(()) @@ -320,8 +316,7 @@ impl ClangSubItemParser for Var { matches!(ty.kind(), CXType_Auto | CXType_Unexposed), "Couldn't resolve constant type, and it \ wasn't an nondeductible auto type or unexposed \ - type: {:?}", - ty + type: {ty:?}" ); return Err(e); } diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 18b5023b1f..2230926293 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -191,7 +191,7 @@ impl FromStr for Formatter { "rustfmt" => Ok(Self::Rustfmt), #[cfg(feature = "prettyplease")] "prettyplease" => Ok(Self::Prettyplease), - _ => Err(format!("`{}` is not a valid formatter", s)), + _ => Err(format!("`{s}` is not a valid formatter")), } } } @@ -627,10 +627,10 @@ impl std::fmt::Display for BindgenError { write!(f, "header '{}' does not exist.", h.display()) } BindgenError::ClangDiagnostic(message) => { - write!(f, "clang diagnosed error: {}", message) + write!(f, "clang diagnosed error: {message}") } BindgenError::Codegen(err) => { - write!(f, "codegen error: {}", err) + write!(f, "codegen error: {err}") } } } @@ -748,7 +748,7 @@ impl Bindings { if !explicit_target && !is_host_build { options.clang_args.insert( 0, - format!("--target={}", effective_target).into_boxed_str(), + format!("--target={effective_target}").into_boxed_str(), ); }; @@ -872,9 +872,7 @@ impl Bindings { debug_assert_eq!( context.target_pointer_size(), std::mem::size_of::<*mut ()>(), - "{:?} {:?}", - effective_target, - HOST_TARGET + "{effective_target:?} {HOST_TARGET:?}" ); } @@ -928,8 +926,7 @@ impl Bindings { } Err(err) => { eprintln!( - "Failed to run rustfmt: {} (non-fatal, continuing)", - err + "Failed to run rustfmt: {err} (non-fatal, continuing)" ); writer.write_all(self.module.to_string().as_bytes())?; } @@ -1097,7 +1094,7 @@ fn parse(context: &mut BindgenContext) -> Result<(), BindgenError> { error.push_str(&msg); error.push('\n'); } else { - eprintln!("clang diag: {}", msg); + eprintln!("clang diag: {msg}"); } } @@ -1183,7 +1180,7 @@ fn get_target_dependent_env_var( var: &str, ) -> Option { if let Ok(target) = env_var(parse_callbacks, "TARGET") { - if let Ok(v) = env_var(parse_callbacks, format!("{}_{}", var, target)) { + if let Ok(v) = env_var(parse_callbacks, format!("{var}_{target}")) { return Some(v); } if let Ok(v) = env_var( @@ -1250,16 +1247,16 @@ impl Default for CargoCallbacks { impl callbacks::ParseCallbacks for CargoCallbacks { fn header_file(&self, filename: &str) { if self.rerun_on_header_files { - println!("cargo:rerun-if-changed={}", filename); + println!("cargo:rerun-if-changed={filename}"); } } fn include_file(&self, filename: &str) { - println!("cargo:rerun-if-changed={}", filename); + println!("cargo:rerun-if-changed={filename}"); } fn read_env_var(&self, key: &str) { - println!("cargo:rerun-if-env-changed={}", key); + println!("cargo:rerun-if-env-changed={key}"); } } @@ -1303,7 +1300,7 @@ fn commandline_flag_unit_test_function() { .iter() .map(|&x| x.into()) .collect::>(); - println!("{:?}", command_line_flags); + println!("{command_line_flags:?}"); assert!(test_cases.iter().all(|x| command_line_flags.contains(x))); } diff --git a/bindgen/options/cli.rs b/bindgen/options/cli.rs index a20ebb1020..c683de178e 100644 --- a/bindgen/options/cli.rs +++ b/bindgen/options/cli.rs @@ -41,7 +41,7 @@ fn parse_codegen_config( otherwise => { return Err(Error::raw( ErrorKind::InvalidValue, - format!("Unknown codegen item kind: {}", otherwise), + format!("Unknown codegen item kind: {otherwise}"), )); } } @@ -688,7 +688,7 @@ where for item in self.regex_set.get_items() { args.extend_from_slice(&[ flag.to_owned(), - format!("{}={}", item, derives), + format!("{item}={derives}"), ]); } @@ -728,7 +728,7 @@ where for item in self.regex_set.get_items() { args.extend_from_slice(&[ flag.to_owned(), - format!("{}={}", item, attributes), + format!("{item}={attributes}"), ]); } diff --git a/bindgen/options/mod.rs b/bindgen/options/mod.rs index 57988e79e6..baac4bcee1 100644 --- a/bindgen/options/mod.rs +++ b/bindgen/options/mod.rs @@ -2013,7 +2013,7 @@ options! { for (abi, set) in overrides { for item in set.get_items() { args.push("--override-abi".to_owned()); - args.push(format!("{}={}", item, abi)); + args.push(format!("{item}={abi}")); } } }, diff --git a/bindgen/regex_set.rs b/bindgen/regex_set.rs index 3375632761..d842af4835 100644 --- a/bindgen/regex_set.rs +++ b/bindgen/regex_set.rs @@ -94,7 +94,7 @@ impl RegexSet { record_matches: bool, _name: Option<&'static str>, ) { - let items = self.items.iter().map(|item| format!("^({})$", item)); + let items = self.items.iter().map(|item| format!("^({item})$")); self.record_matches = record_matches; self.set = match RxSet::new(items) { Ok(x) => Some(x), @@ -189,7 +189,7 @@ fn invalid_regex_warning( } diagnostic.add_annotation( - format!("This regular expression was passed via `{}`.", name), + format!("This regular expression was passed via `{name}`."), Level::Note, ); From e97f4a63fcf478149caa3569ffffd47d6a1c9624 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Fri, 29 Nov 2024 17:17:06 -0500 Subject: [PATCH 775/942] Clippify, and hide some lints in test output Happy clippy = happy developers The test expectations generate a bunch of lints that are mostly irrelevant, at least at the moment, so might as well record them to avoid `cargo clippy` from reporting them. --- bindgen-tests/tests/expectations/Cargo.toml | 20 ++++++++++++++++++++ bindgen/clang.rs | 4 ++-- bindgen/ir/analysis/derive.rs | 2 +- bindgen/ir/annotations.rs | 2 +- bindgen/ir/comment.rs | 2 +- bindgen/ir/comp.rs | 2 +- bindgen/ir/context.rs | 11 ++++------- bindgen/ir/enum_ty.rs | 8 +++----- bindgen/ir/function.rs | 4 +--- bindgen/ir/item.rs | 10 +++++----- bindgen/ir/layout.rs | 2 +- bindgen/ir/ty.rs | 8 ++------ bindgen/ir/var.rs | 6 +++--- bindgen/lib.rs | 2 +- 14 files changed, 46 insertions(+), 37 deletions(-) diff --git a/bindgen-tests/tests/expectations/Cargo.toml b/bindgen-tests/tests/expectations/Cargo.toml index e95e9dcb1c..e720636062 100644 --- a/bindgen-tests/tests/expectations/Cargo.toml +++ b/bindgen-tests/tests/expectations/Cargo.toml @@ -14,3 +14,23 @@ publish = false block = "0.1" libloading = "0.7" objc = "0.2" + +[lints.rust] +### FIXME: these might need to be fixed, +### esp the calling convention, because it is a hard error now +# deprecated = "allow" +# invalid-value = "allow" +# unsupported_calling_conventions = "allow" +non-snake-case = "allow" +unexpected-cfgs = "allow" + +[lints.clippy] +disallowed-names = "allow" +manual-c-str-literals = "allow" +missing-safety-doc = "allow" +op-ref = "allow" +ptr-offset-with-cast = "allow" +too-many-arguments = "allow" +transmute-int-to-bool = "allow" +unnecessary-cast = "allow" +useless-transmute = "allow" diff --git a/bindgen/clang.rs b/bindgen/clang.rs index 03af94c8af..32eb855991 100644 --- a/bindgen/clang.rs +++ b/bindgen/clang.rs @@ -788,7 +788,7 @@ impl Cursor { let found_attr = &mut found_attrs[idx]; if !*found_attr { // `attr.name` and` attr.token_kind` are checked against unexposed attributes only. - if attr.kind.map_or(false, |k| k == kind) || + if attr.kind == Some(kind) || (kind == CXCursor_UnexposedAttr && cur.tokens().iter().any(|t| { t.kind == attr.token_kind && @@ -1522,7 +1522,7 @@ impl Type { // Yep, the spelling of this containing type-parameter is extremely // nasty... But can happen in . Unfortunately I couldn't // reduce it enough :( - self.template_args().map_or(false, |args| args.len() > 0) && + self.template_args().is_some_and(|args| args.len() > 0) && !matches!( self.declaration().kind(), CXCursor_ClassTemplatePartialSpecialization | diff --git a/bindgen/ir/analysis/derive.rs b/bindgen/ir/analysis/derive.rs index 47e433e015..d333a04880 100644 --- a/bindgen/ir/analysis/derive.rs +++ b/bindgen/ir/analysis/derive.rs @@ -673,7 +673,7 @@ impl<'ctx> MonotoneFramework for CannotDerive<'ctx> { let is_reached_limit = |l: Layout| l.align > RUST_DERIVE_IN_ARRAY_LIMIT; if !self.derive_trait.can_derive_large_array(self.ctx) && - ty.layout(self.ctx).map_or(false, is_reached_limit) + ty.layout(self.ctx).is_some_and(is_reached_limit) { // We have to be conservative: the struct *could* have enough // padding that we emit an array that is longer than diff --git a/bindgen/ir/annotations.rs b/bindgen/ir/annotations.rs index 70d392f110..79f42df983 100644 --- a/bindgen/ir/annotations.rs +++ b/bindgen/ir/annotations.rs @@ -213,7 +213,7 @@ impl Annotations { comment .get_tag_attrs() .next() - .map_or(false, |attr| attr.name == "rustbindgen") + .is_some_and(|attr| attr.name == "rustbindgen") { *matched = true; for attr in comment.get_tag_attrs() { diff --git a/bindgen/ir/comment.rs b/bindgen/ir/comment.rs index 7b6f105a4d..03fc76ff98 100644 --- a/bindgen/ir/comment.rs +++ b/bindgen/ir/comment.rs @@ -58,7 +58,7 @@ fn preprocess_multi_line(comment: &str) -> String { .collect(); // Remove the trailing line corresponding to the `*/`. - if lines.last().map_or(false, |l| l.trim().is_empty()) { + if lines.last().is_some_and(|l| l.trim().is_empty()) { lines.pop(); } diff --git a/bindgen/ir/comp.rs b/bindgen/ir/comp.rs index 422f553b64..b202888397 100644 --- a/bindgen/ir/comp.rs +++ b/bindgen/ir/comp.rs @@ -1753,7 +1753,7 @@ impl CompInfo { return (false, false); } - if layout.map_or(false, |l| l.size == 0) { + if layout.is_some_and(|l| l.size == 0) { return (false, false); } diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index 9cdb26c0c8..1b488f9917 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -1148,7 +1148,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" .chain(Some(immut_self.root_module.into())) .find(|id| { let item = immut_self.resolve_item(*id); - item.as_module().map_or(false, |m| { + item.as_module().is_some_and(|m| { m.children().contains(&replacement_id.into()) }) }) @@ -1289,9 +1289,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" ); self.resolve_item(ancestor) .as_module() - .map_or(false, |m| { - m.children().contains(&id) - }) + .is_some_and(|m| m.children().contains(&id)) }) }, "{id:?} should be in some ancestor module's children set" @@ -1423,8 +1421,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" self.used_template_parameters .as_ref() .expect("should have found template parameter usage if we're in codegen") - .get(&item) - .map_or(false, |items_used_params| items_used_params.contains(&template_param)) + .get(&item).is_some_and(|items_used_params| items_used_params.contains(&template_param)) } /// Return `true` if `item` uses any unbound, generic template parameters, @@ -1443,7 +1440,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" "should have template parameter usage info in codegen phase", ) .get(&item) - .map_or(false, |used| !used.is_empty()) + .is_some_and(|used| !used.is_empty()) } // This deserves a comment. Builtin types don't get a valid declaration, so diff --git a/bindgen/ir/enum_ty.rs b/bindgen/ir/enum_ty.rs index 8a90cf99a4..1efa1a630b 100644 --- a/bindgen/ir/enum_ty.rs +++ b/bindgen/ir/enum_ty.rs @@ -73,7 +73,7 @@ impl Enum { let variant_ty = repr.and_then(|r| ctx.resolve_type(r).safe_canonical_type(ctx)); - let is_bool = variant_ty.map_or(false, Type::is_bool); + let is_bool = variant_ty.is_some_and(Type::is_bool); // Assume signedness since the default type by the C standard is an int. let is_signed = variant_ty.map_or(true, |ty| match *ty.kind() { @@ -310,14 +310,12 @@ impl EnumVariant { /// Returns whether this variant should be enforced to be a constant by code /// generation. pub(crate) fn force_constification(&self) -> bool { - self.custom_behavior - .map_or(false, |b| b == EnumVariantCustomBehavior::Constify) + self.custom_behavior == Some(EnumVariantCustomBehavior::Constify) } /// Returns whether the current variant should be hidden completely from the /// resulting rust enum. pub(crate) fn hidden(&self) -> bool { - self.custom_behavior - .map_or(false, |b| b == EnumVariantCustomBehavior::Hide) + self.custom_behavior == Some(EnumVariantCustomBehavior::Hide) } } diff --git a/bindgen/ir/function.rs b/bindgen/ir/function.rs index 5b6f8196e6..f90fe0efe3 100644 --- a/bindgen/ir/function.rs +++ b/bindgen/ir/function.rs @@ -744,9 +744,7 @@ impl ClangSubItemParser for Function { }; if cursor.is_inlined_function() || - cursor - .definition() - .map_or(false, |x| x.is_inlined_function()) + cursor.definition().is_some_and(|x| x.is_inlined_function()) { if !context.options().generate_inline_functions && !context.options().wrap_static_fns diff --git a/bindgen/ir/item.rs b/bindgen/ir/item.rs index ea82ec5f75..a728983884 100644 --- a/bindgen/ir/item.rs +++ b/bindgen/ir/item.rs @@ -492,7 +492,7 @@ impl Item { self.ancestors(ctx) .filter(|id| { - ctx.resolve_item(*id).as_module().map_or(false, |module| { + ctx.resolve_item(*id).as_module().is_some_and(|module| { !module.is_inline() || ctx.options().conservative_inline_namespaces }) @@ -1058,7 +1058,7 @@ impl Item { .map(|id| ctx.resolve_item(id)) .filter(|item| { item.id() == target.id() || - item.as_module().map_or(false, |module| { + item.as_module().is_some_and(|module| { !module.is_inline() || ctx.options().conservative_inline_namespaces }) @@ -1122,7 +1122,7 @@ impl IsOpaque for Item { "You're not supposed to call this yet" ); self.annotations.opaque() || - self.as_type().map_or(false, |ty| ty.is_opaque(ctx, self)) || + self.as_type().is_some_and(|ty| ty.is_opaque(ctx, self)) || ctx.opaque_by_name(self.path_for_allowlisting(ctx)) } } @@ -1133,14 +1133,14 @@ where { fn has_vtable(&self, ctx: &BindgenContext) -> bool { let id: ItemId = (*self).into(); - id.as_type_id(ctx).map_or(false, |id| { + id.as_type_id(ctx).is_some_and(|id| { !matches!(ctx.lookup_has_vtable(id), HasVtableResult::No) }) } fn has_vtable_ptr(&self, ctx: &BindgenContext) -> bool { let id: ItemId = (*self).into(); - id.as_type_id(ctx).map_or(false, |id| { + id.as_type_id(ctx).is_some_and(|id| { matches!(ctx.lookup_has_vtable(id), HasVtableResult::SelfHasVtable) }) } diff --git a/bindgen/ir/layout.rs b/bindgen/ir/layout.rs index 9aee857948..fc248e1dfa 100644 --- a/bindgen/ir/layout.rs +++ b/bindgen/ir/layout.rs @@ -117,7 +117,7 @@ impl Opaque { pub(crate) fn array_size_within_derive_limit(&self) -> CanDerive { if self .array_size() - .map_or(false, |size| size <= RUST_DERIVE_IN_ARRAY_LIMIT) + .is_some_and(|size| size <= RUST_DERIVE_IN_ARRAY_LIMIT) { CanDerive::Yes } else { diff --git a/bindgen/ir/ty.rs b/bindgen/ir/ty.rs index 8f39a2c388..e55175eba0 100644 --- a/bindgen/ir/ty.rs +++ b/bindgen/ir/ty.rs @@ -1217,8 +1217,7 @@ impl Type { let is_const = ty.is_const() || (ty.kind() == CXType_ConstantArray && - ty.elem_type() - .map_or(false, |element| element.is_const())); + ty.elem_type().is_some_and(|element| element.is_const())); let ty = Type::new(name, layout, kind, is_const); // TODO: maybe declaration.canonical()? @@ -1233,10 +1232,7 @@ impl Trace for Type { where T: Tracer, { - if self - .name() - .map_or(false, |name| context.is_stdint_type(name)) - { + if self.name().is_some_and(|name| context.is_stdint_type(name)) { // These types are special-cased in codegen and don't need to be traversed. return; } diff --git a/bindgen/ir/var.rs b/bindgen/ir/var.rs index 707d14f470..2ff148971c 100644 --- a/bindgen/ir/var.rs +++ b/bindgen/ir/var.rs @@ -307,7 +307,7 @@ impl ClangSubItemParser for Var { ([CXType_ConstantArray, CXType_IncompleteArray] .contains(&ty.kind()) && ty.elem_type() - .map_or(false, |element| element.is_const())); + .is_some_and(|element| element.is_const())); let ty = match Item::from_ty(&ty, cursor, None, ctx) { Ok(ty) => ty, @@ -330,8 +330,8 @@ impl ClangSubItemParser for Var { .safe_resolve_type(ty) .and_then(|t| t.safe_canonical_type(ctx)); - let is_integer = canonical_ty.map_or(false, |t| t.is_integer()); - let is_float = canonical_ty.map_or(false, |t| t.is_float()); + let is_integer = canonical_ty.is_some_and(|t| t.is_integer()); + let is_float = canonical_ty.is_some_and(|t| t.is_float()); // TODO: We could handle `char` more gracefully. // TODO: Strings, though the lookup is a bit more hard (we need diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 2230926293..25ba44eb1e 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -1144,7 +1144,7 @@ pub fn clang_version() -> ClangVersion { let raw_v: String = clang::extract_clang_version(); let split_v: Option> = raw_v .split_whitespace() - .find(|t| t.chars().next().map_or(false, |v| v.is_ascii_digit())) + .find(|t| t.chars().next().is_some_and(|v| v.is_ascii_digit())) .map(|v| v.split('.').collect()); if let Some(v) = split_v { if v.len() >= 2 { From 869cd655c3dcd4e86d81f4eda7afbfdcf1ff5e49 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Fri, 29 Nov 2024 12:13:10 -0500 Subject: [PATCH 776/942] Use `Display` for `Builder::generate` errors --- bindgen-cli/main.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bindgen-cli/main.rs b/bindgen-cli/main.rs index 0edf3a84d5..3eca487f8c 100644 --- a/bindgen-cli/main.rs +++ b/bindgen-cli/main.rs @@ -40,8 +40,13 @@ pub fn main() { eprintln!("{info}"); })); - let bindings = - builder.generate().expect("Unable to generate bindings"); + let bindings = match builder.generate() { + Ok(bindings) => bindings, + Err(err) => { + eprintln!("Unable to generate bindings: {err}"); + std::process::exit(1) + } + }; let _ = std::panic::take_hook(); From 1945b0d43f87aab71c9d405d3227d8de271d4430 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Fri, 29 Nov 2024 12:13:10 -0500 Subject: [PATCH 777/942] Make nightly target compatible with every other target --- bindgen/features.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bindgen/features.rs b/bindgen/features.rs index 650c810b0e..1b971a4e42 100644 --- a/bindgen/features.rs +++ b/bindgen/features.rs @@ -38,8 +38,10 @@ impl RustTarget { // fixes. minor >= other_minor } - (_, Version::Nightly) => false, + // Nightly is compatible with everything (Version::Nightly, _) => true, + // No stable release is compatible with nightly + (Version::Stable { .. }, Version::Nightly) => false, } } } From 3e9a176ba1c5f2e60d4cdde3a3a3e49134cf7a9b Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Fri, 29 Nov 2024 12:13:10 -0500 Subject: [PATCH 778/942] Introduce `--rust-edition` --- bindgen/features.rs | 161 +++++++++++++++++++++++++++++++++++------ bindgen/lib.rs | 26 ++++++- bindgen/options/cli.rs | 10 ++- bindgen/options/mod.rs | 21 +++++- 4 files changed, 188 insertions(+), 30 deletions(-) diff --git a/bindgen/features.rs b/bindgen/features.rs index 1b971a4e42..13dcb43b85 100644 --- a/bindgen/features.rs +++ b/bindgen/features.rs @@ -79,12 +79,92 @@ impl fmt::Display for InvalidRustTarget { } } +/// This macro defines the Rust editions supported by bindgen. +macro_rules! define_rust_editions { + ($($variant:ident($value:literal) => $minor:literal,)*) => { + #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] + pub enum RustEdition { + $( + #[doc = concat!("The ", stringify!($value), " edition of Rust.")] + $variant, + )* + } + + impl FromStr for RustEdition { + type Err = InvalidRustEdition; + + fn from_str(s: &str) -> Result { + match s { + $(stringify!($value) => Ok(Self::$variant),)* + _ => Err(InvalidRustEdition(s.to_owned())), + } + } + } + + impl fmt::Display for RustEdition { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + $(Self::$variant => stringify!($value).fmt(f),)* + } + } + } + + impl RustEdition { + pub(crate) const ALL: [Self; [$($value,)*].len()] = [$(Self::$variant,)*]; + + pub(crate) fn is_available(self, target: RustTarget) -> bool { + let Some(minor) = target.minor() else { + return true; + }; + + match self { + $(Self::$variant => $minor <= minor,)* + } + } + } + } +} + +#[derive(Debug)] +pub struct InvalidRustEdition(String); + +impl fmt::Display for InvalidRustEdition { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "\"{}\" is not a valid Rust edition", self.0) + } +} + +impl std::error::Error for InvalidRustEdition {} + +define_rust_editions! { + Edition2018(2018) => 31, + Edition2021(2021) => 56, +} + +impl RustTarget { + /// Returns the latest edition supported by this target. + pub(crate) fn latest_edition(self) -> RustEdition { + RustEdition::ALL + .iter() + .rev() + .find(|edition| edition.is_available(self)) + .copied() + .expect("bindgen should always support at least one edition") + } +} + +impl Default for RustEdition { + fn default() -> Self { + RustTarget::default().latest_edition() + } +} + /// This macro defines the [`RustTarget`] and [`RustFeatures`] types. macro_rules! define_rust_targets { ( - Nightly => {$($nightly_feature:ident $(: #$issue:literal)?),* $(,)?} $(,)? + Nightly => {$($nightly_feature:ident $(($nightly_edition:literal))* $(: #$issue:literal)?),* $(,)?} $(,)? $( - $variant:ident($minor:literal) => {$($feature:ident $(: #$pull:literal)?),* $(,)?}, + $variant:ident($minor:literal) => {$($feature:ident $(($edition:literal))* $(: #$pull:literal)?),* $(,)?}, )* $(,)? ) => { @@ -128,23 +208,35 @@ macro_rules! define_rust_targets { $(pub(crate) $nightly_feature: bool,)* } - impl From for RustFeatures { - fn from(target: RustTarget) -> Self { - if target == RustTarget::Nightly { - return Self { - $($($feature: true,)*)* - $($nightly_feature: true,)* - }; - } - + impl RustFeatures { + /// Compute the features that must be enabled in a specific Rust target with a specific edition. + pub(crate) fn new(target: RustTarget, edition: RustEdition) -> Self { let mut features = Self { $($($feature: false,)*)* $($nightly_feature: false,)* }; - $(if target.is_compatible(&RustTarget::$variant) { - $(features.$feature = true;)* - })* + if target.is_compatible(&RustTarget::nightly()) { + $( + let editions: &[RustEdition] = &[$(stringify!($nightly_edition).parse::().ok().expect("invalid edition"),)*]; + + if editions.is_empty() || editions.contains(&edition) { + features.$nightly_feature = true; + } + )* + } + + $( + if target.is_compatible(&RustTarget::$variant) { + $( + let editions: &[RustEdition] = &[$(stringify!($edition).parse::().ok().expect("invalid edition"),)*]; + + if editions.is_empty() || editions.contains(&edition) { + features.$feature = true; + } + )* + } + )* features } @@ -163,7 +255,7 @@ define_rust_targets! { }, Stable_1_77(77) => { offset_of: #106655, - literal_cstr: #117472, + literal_cstr(2021): #117472, }, Stable_1_73(73) => { thiscall_abi: #42202 }, Stable_1_71(71) => { c_unwind_abi: #106075 }, @@ -296,9 +388,17 @@ impl FromStr for RustTarget { } } +impl RustFeatures { + /// Compute the features that must be enabled in a specific Rust target with the latest edition + /// available in that target. + pub(crate) fn new_with_latest_edition(target: RustTarget) -> Self { + Self::new(target, target.latest_edition()) + } +} + impl Default for RustFeatures { fn default() -> Self { - RustTarget::default().into() + Self::new_with_latest_edition(RustTarget::default()) } } @@ -308,24 +408,39 @@ mod test { #[test] fn target_features() { - let features = RustFeatures::from(RustTarget::Stable_1_71); + let features = + RustFeatures::new_with_latest_edition(RustTarget::Stable_1_71); assert!( features.c_unwind_abi && features.abi_efiapi && !features.thiscall_abi ); - let f_nightly = RustFeatures::from(RustTarget::Nightly); + + let features = RustFeatures::new( + RustTarget::Stable_1_77, + RustEdition::Edition2018, + ); + assert!(!features.literal_cstr); + + let features = + RustFeatures::new_with_latest_edition(RustTarget::Stable_1_77); + assert!(features.literal_cstr); + + let f_nightly = + RustFeatures::new_with_latest_edition(RustTarget::Nightly); assert!( - f_nightly.maybe_uninit && - f_nightly.thiscall_abi && - f_nightly.vectorcall_abi + f_nightly.vectorcall_abi && + f_nightly.ptr_metadata && + f_nightly.layout_for_ptr ); } fn test_target(input: &str, expected: RustTarget) { // Two targets are equivalent if they enable the same set of features - let expected = RustFeatures::from(expected); - let found = RustFeatures::from(input.parse::().unwrap()); + let expected = RustFeatures::new_with_latest_edition(expected); + let found = RustFeatures::new_with_latest_edition( + input.parse::().unwrap(), + ); assert_eq!( expected, found, diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 25ba44eb1e..3c09069e2f 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -57,7 +57,7 @@ pub use ir::function::Abi; pub use options::cli::builder_from_flags; use codegen::CodegenError; -use features::RustFeatures; +use features::{RustEdition, RustFeatures}; use ir::comment; use ir::context::{BindgenContext, ItemId}; use ir::item::Item; @@ -316,6 +316,22 @@ fn get_extra_clang_args( impl Builder { /// Generate the Rust bindings using the options built up thus far. pub fn generate(mut self) -> Result { + // Keep rust_features synced with rust_target + self.options.rust_features = match self.options.rust_edition { + Some(edition) => { + if !edition.is_available(self.options.rust_target) { + return Err(BindgenError::UnsupportedEdition( + edition, + self.options.rust_target, + )); + } + RustFeatures::new(self.options.rust_target, edition) + } + None => { + RustFeatures::new_with_latest_edition(self.options.rust_target) + } + }; + // Add any extra arguments from the environment to the clang command line. self.options.clang_args.extend( get_extra_clang_args(&self.options.parse_callbacks) @@ -530,9 +546,6 @@ impl BindgenOptions { /// Update rust target version pub fn set_rust_target(&mut self, rust_target: RustTarget) { self.rust_target = rust_target; - - // Keep rust_features synced with rust_target - self.rust_features = rust_target.into(); } /// Get features supported by target Rust version @@ -612,6 +625,8 @@ pub enum BindgenError { ClangDiagnostic(String), /// Code generation reported an error. Codegen(CodegenError), + /// The passed edition is not available on that Rust target. + UnsupportedEdition(RustEdition, RustTarget), } impl std::fmt::Display for BindgenError { @@ -632,6 +647,9 @@ impl std::fmt::Display for BindgenError { BindgenError::Codegen(err) => { write!(f, "codegen error: {err}") } + BindgenError::UnsupportedEdition(edition, target) => { + write!(f, "edition {edition} is not available on Rust {target}") + } } } } diff --git a/bindgen/options/cli.rs b/bindgen/options/cli.rs index c683de178e..e444432d16 100644 --- a/bindgen/options/cli.rs +++ b/bindgen/options/cli.rs @@ -3,7 +3,7 @@ use crate::{ callbacks::{ AttributeInfo, DeriveInfo, ItemInfo, ParseCallbacks, TypeKind, }, - features::EARLIEST_STABLE_RUST, + features::{RustEdition, EARLIEST_STABLE_RUST}, regex_set::RegexSet, Abi, AliasVariation, Builder, CodegenConfig, EnumVariation, FieldVisibilityKind, Formatter, MacroTypeVariation, NonCopyUnionStyle, @@ -26,6 +26,10 @@ fn rust_target_help() -> String { ) } +fn rust_edition_help() -> String { + format!("Rust edition to target. Defaults to the latest edition supported by the chosen Rust target. Possible values: ({}). ", RustEdition::ALL.map(|e| e.to_string()).join("|")) +} + fn parse_codegen_config( what_to_generate: &str, ) -> Result { @@ -334,6 +338,8 @@ struct BindgenCommand { module_raw_line: Vec, #[arg(long, help = rust_target_help())] rust_target: Option, + #[arg(long, value_name = "EDITION", help = rust_edition_help())] + rust_edition: Option, /// Use types from Rust core instead of std. #[arg(long)] use_core: bool, @@ -588,6 +594,7 @@ where raw_line, module_raw_line, rust_target, + rust_edition, use_core, conservative_inline_namespaces, allowlist_function, @@ -821,6 +828,7 @@ where }, header, rust_target, + rust_edition, default_enum_style, bitfield_enum, newtype_enum, diff --git a/bindgen/options/mod.rs b/bindgen/options/mod.rs index baac4bcee1..4e68dfb7cd 100644 --- a/bindgen/options/mod.rs +++ b/bindgen/options/mod.rs @@ -12,7 +12,7 @@ use crate::codegen::{ AliasVariation, EnumVariation, MacroTypeVariation, NonCopyUnionStyle, }; use crate::deps::DepfileSpec; -use crate::features::{RustFeatures, RustTarget}; +use crate::features::{RustEdition, RustFeatures, RustTarget}; use crate::regex_set::RegexSet; use crate::Abi; use crate::Builder; @@ -1609,9 +1609,26 @@ options! { args.push(rust_target.to_string()); }, }, + /// The Rust edition to use for code generation. + rust_edition: Option { + methods: { + /// Specify the Rust target edition. + /// + /// The default edition is the latest edition supported by the chosen Rust target. + pub fn rust_edition(mut self, rust_edition: RustEdition) -> Self { + self.options.rust_edition = Some(rust_edition); + self + } + } + as_args: |edition, args| { + if let Some(edition) = edition { + args.push("--rust-edition".to_owned()); + args.push(edition.to_string()); + } + }, + }, /// Features to be enabled. They are derived from `rust_target`. rust_features: RustFeatures { - default: RustTarget::default().into(), methods: {}, // This field cannot be set from the CLI, as_args: ignore, From dccbdf1a675fe81e3d77ccfd2868c1ee0dcb5415 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Fri, 29 Nov 2024 16:51:41 -0500 Subject: [PATCH 779/942] Add support for edition 2024 Co-authored-by: Yuri Astrakhan --- bindgen/features.rs | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/bindgen/features.rs b/bindgen/features.rs index 13dcb43b85..b018354eb1 100644 --- a/bindgen/features.rs +++ b/bindgen/features.rs @@ -139,6 +139,7 @@ impl std::error::Error for InvalidRustEdition {} define_rust_editions! { Edition2018(2018) => 31, Edition2021(2021) => 56, + Edition2024(2024) => 85, } impl RustTarget { @@ -162,9 +163,9 @@ impl Default for RustEdition { /// This macro defines the [`RustTarget`] and [`RustFeatures`] types. macro_rules! define_rust_targets { ( - Nightly => {$($nightly_feature:ident $(($nightly_edition:literal))* $(: #$issue:literal)?),* $(,)?} $(,)? + Nightly => {$($nightly_feature:ident $(($nightly_edition:literal))|* $(: #$issue:literal)?),* $(,)?} $(,)? $( - $variant:ident($minor:literal) => {$($feature:ident $(($edition:literal))* $(: #$pull:literal)?),* $(,)?}, + $variant:ident($minor:literal) => {$($feature:ident $(($edition:literal))|* $(: #$pull:literal)?),* $(,)?}, )* $(,)? ) => { @@ -255,7 +256,7 @@ define_rust_targets! { }, Stable_1_77(77) => { offset_of: #106655, - literal_cstr(2021): #117472, + literal_cstr(2021)|(2024): #117472, }, Stable_1_73(73) => { thiscall_abi: #42202 }, Stable_1_71(71) => { c_unwind_abi: #106075 }, @@ -406,6 +407,26 @@ impl Default for RustFeatures { mod test { use super::*; + #[test] + fn release_versions_for_editions() { + assert_eq!( + "1.33".parse::().unwrap().latest_edition(), + RustEdition::Edition2018 + ); + assert_eq!( + "1.56".parse::().unwrap().latest_edition(), + RustEdition::Edition2021 + ); + assert_eq!( + "1.85".parse::().unwrap().latest_edition(), + RustEdition::Edition2024 + ); + assert_eq!( + "nightly".parse::().unwrap().latest_edition(), + RustEdition::Edition2024 + ); + } + #[test] fn target_features() { let features = From c4440b31ebd52bd81f0588de0d48033dc3bfc82a Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Fri, 29 Nov 2024 17:07:23 -0500 Subject: [PATCH 780/942] Test the `literal_cstr` feature with different editions Co-authored-by: Yuri Astrakhan --- .../tests/expectations/tests/strings_cstr2_2018.rs | 13 +++++++++++++ bindgen-tests/tests/headers/strings_cstr2_2018.h | 5 +++++ 2 files changed, 18 insertions(+) create mode 100644 bindgen-tests/tests/expectations/tests/strings_cstr2_2018.rs create mode 100644 bindgen-tests/tests/headers/strings_cstr2_2018.h diff --git a/bindgen-tests/tests/expectations/tests/strings_cstr2_2018.rs b/bindgen-tests/tests/expectations/tests/strings_cstr2_2018.rs new file mode 100644 index 0000000000..ca089cf130 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/strings_cstr2_2018.rs @@ -0,0 +1,13 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[allow(unsafe_code)] +pub const MY_STRING_UTF8: &::std::ffi::CStr = unsafe { + ::std::ffi::CStr::from_bytes_with_nul_unchecked(b"Hello, world!\0") +}; +#[allow(unsafe_code)] +pub const MY_STRING_INTERIOR_NULL: &::std::ffi::CStr = unsafe { + ::std::ffi::CStr::from_bytes_with_nul_unchecked(b"Hello,\0") +}; +#[allow(unsafe_code)] +pub const MY_STRING_NON_UTF8: &::std::ffi::CStr = unsafe { + ::std::ffi::CStr::from_bytes_with_nul_unchecked(b"ABCDE\xFF\0") +}; diff --git a/bindgen-tests/tests/headers/strings_cstr2_2018.h b/bindgen-tests/tests/headers/strings_cstr2_2018.h new file mode 100644 index 0000000000..67d117a1bc --- /dev/null +++ b/bindgen-tests/tests/headers/strings_cstr2_2018.h @@ -0,0 +1,5 @@ +// bindgen-flags: --rust-target=1.77 --rust-edition=2018 --generate-cstr + +const char* MY_STRING_UTF8 = "Hello, world!"; +const char* MY_STRING_INTERIOR_NULL = "Hello,\0World!"; +const char* MY_STRING_NON_UTF8 = "ABCDE\xFF"; From bacacde1671a31440b46a9650c2f2ef1317531b2 Mon Sep 17 00:00:00 2001 From: Nik Konyuchenko Date: Sat, 30 Nov 2024 15:59:23 -0800 Subject: [PATCH 781/942] Make RustEdition public Making RustEdition public allows calling Builder::rust_edition() from the build.rs scripts. + Adding documentation to the RustEdition enum to not break linter rules. Signed-off-by: Nik Konyuchenko --- bindgen/features.rs | 1 + bindgen/lib.rs | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/bindgen/features.rs b/bindgen/features.rs index b018354eb1..af36ffca9b 100644 --- a/bindgen/features.rs +++ b/bindgen/features.rs @@ -83,6 +83,7 @@ impl fmt::Display for InvalidRustTarget { macro_rules! define_rust_editions { ($($variant:ident($value:literal) => $minor:literal,)*) => { #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] + #[doc = "Represents Rust Edition for the generated bindings"] pub enum RustEdition { $( #[doc = concat!("The ", stringify!($value), " edition of Rust.")] diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 3c09069e2f..7b205e9f80 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -50,14 +50,14 @@ mod regex_set; pub use codegen::{ AliasVariation, EnumVariation, MacroTypeVariation, NonCopyUnionStyle, }; -pub use features::{RustTarget, LATEST_STABLE_RUST}; +pub use features::{RustEdition, RustTarget, LATEST_STABLE_RUST}; pub use ir::annotations::FieldVisibilityKind; pub use ir::function::Abi; #[cfg(feature = "__cli")] pub use options::cli::builder_from_flags; use codegen::CodegenError; -use features::{RustEdition, RustFeatures}; +use features::RustFeatures; use ir::comment; use ir::context::{BindgenContext, ItemId}; use ir::item::Item; From 74b27709de23134f7a74a7de9641a85ed6fdb98d Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Sat, 30 Nov 2024 18:57:59 -0500 Subject: [PATCH 782/942] Applied clippy cloned->copied, and cleanup Removed a few unneeded cloning --- bindgen/codegen/helpers.rs | 2 -- bindgen/ir/analysis/derive.rs | 10 +++++----- bindgen/ir/analysis/has_destructor.rs | 2 +- bindgen/ir/analysis/has_float.rs | 2 +- bindgen/ir/analysis/has_type_param_in_array.rs | 2 +- bindgen/ir/analysis/has_vtable.rs | 6 +++--- bindgen/ir/analysis/mod.rs | 4 ++-- bindgen/ir/analysis/sizedness.rs | 9 +++------ bindgen/ir/analysis/template_params.rs | 13 +++++-------- bindgen/ir/context.rs | 13 ++++++------- 10 files changed, 27 insertions(+), 36 deletions(-) diff --git a/bindgen/codegen/helpers.rs b/bindgen/codegen/helpers.rs index 89665380e7..c550d16679 100644 --- a/bindgen/codegen/helpers.rs +++ b/bindgen/codegen/helpers.rs @@ -19,7 +19,6 @@ pub(crate) mod attributes { pub(crate) fn repr_list(which_ones: &[&str]) -> TokenStream { let which_ones = which_ones .iter() - .cloned() .map(|one| TokenStream::from_str(one).expect("repr to be valid")); quote! { #[repr( #( #which_ones ),* )] @@ -29,7 +28,6 @@ pub(crate) mod attributes { pub(crate) fn derives(which_ones: &[&str]) -> TokenStream { let which_ones = which_ones .iter() - .cloned() .map(|one| TokenStream::from_str(one).expect("derive to be valid")); quote! { #[derive( #( #which_ones ),* )] diff --git a/bindgen/ir/analysis/derive.rs b/bindgen/ir/analysis/derive.rs index d333a04880..a5140b6000 100644 --- a/bindgen/ir/analysis/derive.rs +++ b/bindgen/ir/analysis/derive.rs @@ -234,7 +234,7 @@ impl CannotDerive<'_> { // Complex cases need more information TypeKind::Array(t, len) => { let inner_type = - self.can_derive.get(&t.into()).cloned().unwrap_or_default(); + self.can_derive.get(&t.into()).copied().unwrap_or_default(); if inner_type != CanDerive::Yes { trace!( " arrays of T for which we cannot derive {} \ @@ -273,7 +273,7 @@ impl CannotDerive<'_> { } TypeKind::Vector(t, len) => { let inner_type = - self.can_derive.get(&t.into()).cloned().unwrap_or_default(); + self.can_derive.get(&t.into()).copied().unwrap_or_default(); if inner_type != CanDerive::Yes { trace!( " vectors of T for which we cannot derive {} \ @@ -428,7 +428,7 @@ impl CannotDerive<'_> { let can_derive = self.can_derive .get(&sub_id) - .cloned() + .copied() .unwrap_or_default(); match can_derive { @@ -642,7 +642,7 @@ impl<'ctx> MonotoneFramework for CannotDerive<'ctx> { self.ctx .allowlisted_items() .iter() - .cloned() + .copied() .flat_map(|i| { let mut reachable = vec![i]; i.trace( @@ -660,7 +660,7 @@ impl<'ctx> MonotoneFramework for CannotDerive<'ctx> { fn constrain(&mut self, id: ItemId) -> ConstrainResult { trace!("constrain: {:?}", id); - if let Some(CanDerive::No) = self.can_derive.get(&id).cloned() { + if let Some(CanDerive::No) = self.can_derive.get(&id) { trace!(" already know it cannot derive {}", self.derive_trait); return ConstrainResult::Same; } diff --git a/bindgen/ir/analysis/has_destructor.rs b/bindgen/ir/analysis/has_destructor.rs index 2f5cf1127d..3a433956e6 100644 --- a/bindgen/ir/analysis/has_destructor.rs +++ b/bindgen/ir/analysis/has_destructor.rs @@ -82,7 +82,7 @@ impl<'ctx> MonotoneFramework for HasDestructorAnalysis<'ctx> { } fn initial_worklist(&self) -> Vec { - self.ctx.allowlisted_items().iter().cloned().collect() + self.ctx.allowlisted_items().iter().copied().collect() } fn constrain(&mut self, id: ItemId) -> ConstrainResult { diff --git a/bindgen/ir/analysis/has_float.rs b/bindgen/ir/analysis/has_float.rs index 75778ba7f4..86858813e2 100644 --- a/bindgen/ir/analysis/has_float.rs +++ b/bindgen/ir/analysis/has_float.rs @@ -93,7 +93,7 @@ impl<'ctx> MonotoneFramework for HasFloat<'ctx> { } fn initial_worklist(&self) -> Vec { - self.ctx.allowlisted_items().iter().cloned().collect() + self.ctx.allowlisted_items().iter().copied().collect() } fn constrain(&mut self, id: ItemId) -> ConstrainResult { diff --git a/bindgen/ir/analysis/has_type_param_in_array.rs b/bindgen/ir/analysis/has_type_param_in_array.rs index 2ac378bf75..1029546aad 100644 --- a/bindgen/ir/analysis/has_type_param_in_array.rs +++ b/bindgen/ir/analysis/has_type_param_in_array.rs @@ -99,7 +99,7 @@ impl<'ctx> MonotoneFramework for HasTypeParameterInArray<'ctx> { } fn initial_worklist(&self) -> Vec { - self.ctx.allowlisted_items().iter().cloned().collect() + self.ctx.allowlisted_items().iter().copied().collect() } fn constrain(&mut self, id: ItemId) -> ConstrainResult { diff --git a/bindgen/ir/analysis/has_vtable.rs b/bindgen/ir/analysis/has_vtable.rs index 1f1c46ffd7..6391be8e76 100644 --- a/bindgen/ir/analysis/has_vtable.rs +++ b/bindgen/ir/analysis/has_vtable.rs @@ -118,9 +118,9 @@ impl HasVtableAnalysis<'_> { let from = from.into(); let to = to.into(); - match self.have_vtable.get(&from).cloned() { + match self.have_vtable.get(&from) { None => ConstrainResult::Same, - Some(r) => self.insert(to, r), + Some(r) => self.insert(to, *r), } } } @@ -142,7 +142,7 @@ impl<'ctx> MonotoneFramework for HasVtableAnalysis<'ctx> { } fn initial_worklist(&self) -> Vec { - self.ctx.allowlisted_items().iter().cloned().collect() + self.ctx.allowlisted_items().iter().copied().collect() } fn constrain(&mut self, id: ItemId) -> ConstrainResult { diff --git a/bindgen/ir/analysis/mod.rs b/bindgen/ir/analysis/mod.rs index b40a66ccb9..731080cb4e 100644 --- a/bindgen/ir/analysis/mod.rs +++ b/bindgen/ir/analysis/mod.rs @@ -316,7 +316,7 @@ mod tests { } fn initial_worklist(&self) -> Vec { - self.graph.0.keys().cloned().collect() + self.graph.0.keys().copied().collect() } fn constrain(&mut self, node: Node) -> ConstrainResult { @@ -376,7 +376,7 @@ mod tests { where A: AsRef<[usize]>, { - nodes.as_ref().iter().cloned().map(Node).collect() + nodes.as_ref().iter().copied().map(Node).collect() } let mut expected = HashMap::default(); diff --git a/bindgen/ir/analysis/sizedness.rs b/bindgen/ir/analysis/sizedness.rs index 4dc52facba..c6492787ee 100644 --- a/bindgen/ir/analysis/sizedness.rs +++ b/bindgen/ir/analysis/sizedness.rs @@ -150,9 +150,9 @@ impl SizednessAnalysis<'_> { } fn forward(&mut self, from: TypeId, to: TypeId) -> ConstrainResult { - match self.sized.get(&from).cloned() { + match self.sized.get(&from) { None => ConstrainResult::Same, - Some(r) => self.insert(to, r), + Some(r) => self.insert(to, *r), } } } @@ -191,7 +191,6 @@ impl<'ctx> MonotoneFramework for SizednessAnalysis<'ctx> { self.ctx .allowlisted_items() .iter() - .cloned() .filter_map(|id| id.as_type_id(self.ctx)) .collect() } @@ -199,9 +198,7 @@ impl<'ctx> MonotoneFramework for SizednessAnalysis<'ctx> { fn constrain(&mut self, id: TypeId) -> ConstrainResult { trace!("constrain {:?}", id); - if let Some(SizednessResult::NonZeroSized) = - self.sized.get(&id).cloned() - { + if let Some(SizednessResult::NonZeroSized) = self.sized.get(&id) { trace!(" already know it is not zero-sized"); return ConstrainResult::Same; } diff --git a/bindgen/ir/analysis/template_params.rs b/bindgen/ir/analysis/template_params.rs index 4015fb1728..98504b429e 100644 --- a/bindgen/ir/analysis/template_params.rs +++ b/bindgen/ir/analysis/template_params.rs @@ -259,7 +259,6 @@ impl UsedTemplateParameters<'_> { a's used template param set should be `Some`", ) .iter() - .cloned() }); used_by_this_id.extend(args); @@ -322,8 +321,7 @@ impl UsedTemplateParameters<'_> { arg's used template param set should be \ `Some`", ) - .iter() - .cloned(); + .iter(); used_by_this_id.extend(used_by_arg); } } @@ -355,8 +353,7 @@ impl UsedTemplateParameters<'_> { sub_id's used template param set should be \ `Some`", ) - .iter() - .cloned(); + .iter(); trace!( " union with {:?}'s usage: {:?}", @@ -380,11 +377,11 @@ impl<'ctx> MonotoneFramework for UsedTemplateParameters<'ctx> { let mut used = HashMap::default(); let mut dependencies = HashMap::default(); let allowlisted_items: HashSet<_> = - ctx.allowlisted_items().iter().cloned().collect(); + ctx.allowlisted_items().iter().copied().collect(); let allowlisted_and_blocklisted_items: ItemSet = allowlisted_items .iter() - .cloned() + .copied() .flat_map(|i| { let mut reachable = vec![i]; i.trace( @@ -498,7 +495,7 @@ impl<'ctx> MonotoneFramework for UsedTemplateParameters<'ctx> { self.ctx .allowlisted_items() .iter() - .cloned() + .copied() .flat_map(|i| { let mut reachable = vec![i]; i.trace( diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index 1b488f9917..ed6c5406ac 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -864,7 +864,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" definition.kind(), clang_sys::CXCursor_TemplateTypeParameter ); - self.type_params.get(definition).cloned() + self.type_params.get(definition).copied() } // TODO: Move all this syntax crap to other part of the code. @@ -1317,7 +1317,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" .as_ref() .unwrap() .get(&id) - .cloned() + .copied() .unwrap_or(SizednessResult::ZeroSized) } @@ -1341,7 +1341,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" .as_ref() .unwrap() .get(&id.into()) - .cloned() + .copied() .unwrap_or(HasVtableResult::No) } @@ -1541,7 +1541,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" &self, definition: clang::Cursor, ) -> Option { - self.semantic_parents.get(&definition).cloned() + self.semantic_parents.get(&definition).copied() } /// Given a cursor pointing to the location of a template instantiation, @@ -1589,7 +1589,6 @@ If you encounter an error missing from this list, please file an issue or a PR!" self.currently_parsed_types() .iter() .find(|partial_ty| *partial_ty.decl() == referenced) - .cloned() }) .and_then(|template_decl| { let num_template_params = @@ -1861,7 +1860,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" .usr() .and_then(|usr| self.types.get(&TypeKey::Usr(usr))) }) - .cloned() + .copied() } /// Looks up for an already resolved type, either because it's builtin, or @@ -2865,7 +2864,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" .as_ref() .unwrap() .get(&id) - .cloned() + .copied() .unwrap_or(CanDerive::Yes) } From fab3026551ff209fba9cbc26efefb8b0e1f17bc4 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Sat, 30 Nov 2024 18:04:27 -0500 Subject: [PATCH 783/942] Inline more format args, spelink * fixed `insantiation` -> `instantiation` in some logging * inlined a lot of format arg to make them a bit more readable --- bindgen-tests/build.rs | 3 +- bindgen-tests/tests/parse_callbacks/mod.rs | 2 +- bindgen-tests/tests/quickchecking/src/lib.rs | 2 +- bindgen-tests/tests/tests.rs | 2 +- bindgen/clang.rs | 35 +++++------ bindgen/codegen/bitfield_unit_tests.rs | 6 +- bindgen/codegen/helpers.rs | 2 +- bindgen/codegen/impl_debug.rs | 3 +- bindgen/codegen/mod.rs | 57 +++++++----------- bindgen/codegen/serialize.rs | 2 +- bindgen/codegen/struct_layout.rs | 24 +++----- bindgen/deps.rs | 2 +- bindgen/ir/analysis/derive.rs | 28 ++++----- bindgen/ir/analysis/has_destructor.rs | 2 +- bindgen/ir/analysis/has_float.rs | 10 ++-- .../ir/analysis/has_type_param_in_array.rs | 13 ++-- bindgen/ir/analysis/has_vtable.rs | 6 +- bindgen/ir/analysis/sizedness.rs | 6 +- bindgen/ir/analysis/template_params.rs | 17 +++--- bindgen/ir/comp.rs | 7 +-- bindgen/ir/context.rs | 59 ++++++------------- bindgen/ir/dot.rs | 3 +- bindgen/ir/enum_ty.rs | 2 +- bindgen/ir/function.rs | 6 +- bindgen/ir/item.rs | 31 ++++------ bindgen/ir/objc.rs | 11 ++-- bindgen/ir/ty.rs | 41 ++++--------- bindgen/ir/var.rs | 4 +- bindgen/lib.rs | 11 ++-- bindgen/regex_set.rs | 2 +- bindgen/time.rs | 2 +- book/src/code-formatting.md | 3 +- book/src/tutorial-5.md | 12 ++-- 33 files changed, 160 insertions(+), 256 deletions(-) diff --git a/bindgen-tests/build.rs b/bindgen-tests/build.rs index 6b2f2c7274..713dbb3c57 100644 --- a/bindgen-tests/build.rs +++ b/bindgen-tests/build.rs @@ -35,8 +35,7 @@ pub fn main() { .to_lowercase(); writeln!( dst, - "test_header!(header_{}, {:?});", - func, + "test_header!(header_{func}, {:?});", entry.path(), ) .unwrap(); diff --git a/bindgen-tests/tests/parse_callbacks/mod.rs b/bindgen-tests/tests/parse_callbacks/mod.rs index c372ce1057..2fba5f11a2 100644 --- a/bindgen-tests/tests/parse_callbacks/mod.rs +++ b/bindgen-tests/tests/parse_callbacks/mod.rs @@ -52,7 +52,7 @@ impl ParseCallbacks for PrefixLinkNameParseCallback { ) -> Option { self.prefix .as_deref() - .map(|prefix| format!("{}{}", prefix, item_info.name)) + .map(|prefix| format!("{prefix}{}", item_info.name)) } } diff --git a/bindgen-tests/tests/quickchecking/src/lib.rs b/bindgen-tests/tests/quickchecking/src/lib.rs index 2c33858af2..382e4f9935 100644 --- a/bindgen-tests/tests/quickchecking/src/lib.rs +++ b/bindgen-tests/tests/quickchecking/src/lib.rs @@ -9,7 +9,7 @@ //! let generate_range: usize = 10; // Determines things like the length of //! // arbitrary vectors generated. //! let header = fuzzers::HeaderC::arbitrary(&mut Gen::new(generate_range)); -//! println!("{}", header); +//! println!("{header}"); //! ``` #![deny(missing_docs)] diff --git a/bindgen-tests/tests/tests.rs b/bindgen-tests/tests/tests.rs index 18262851cd..bbe7eb2e24 100644 --- a/bindgen-tests/tests/tests.rs +++ b/bindgen-tests/tests/tests.rs @@ -359,7 +359,7 @@ macro_rules! test_header { }); if let Err(err) = result { - panic!("{}", err); + panic!("{err}"); } } }; diff --git a/bindgen/clang.rs b/bindgen/clang.rs index 32eb855991..f34f680343 100644 --- a/bindgen/clang.rs +++ b/bindgen/clang.rs @@ -1066,7 +1066,7 @@ impl ClangToken { // expressions, so we strip them down here. CXToken_Comment => return None, _ => { - warn!("Found unexpected token kind: {:?}", self); + warn!("Found unexpected token kind: {self:?}"); return None; } }; @@ -2090,26 +2090,25 @@ pub(crate) fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult { let prefix = prefix.as_ref(); print_indent( depth, - format!(" {}kind = {}", prefix, kind_to_str(c.kind())), + format!(" {prefix}kind = {}", kind_to_str(c.kind())), ); print_indent( depth, - format!(" {}spelling = \"{}\"", prefix, c.spelling()), + format!(" {prefix}spelling = \"{}\"", c.spelling()), ); - print_indent(depth, format!(" {}location = {}", prefix, c.location())); + print_indent(depth, format!(" {prefix}location = {}", c.location())); print_indent( depth, - format!(" {}is-definition? {}", prefix, c.is_definition()), + format!(" {prefix}is-definition? {}", c.is_definition()), ); print_indent( depth, - format!(" {}is-declaration? {}", prefix, c.is_declaration()), + format!(" {prefix}is-declaration? {}", c.is_declaration()), ); print_indent( depth, format!( - " {}is-inlined-function? {}", - prefix, + " {prefix}is-inlined-function? {}", c.is_inlined_function() ), ); @@ -2118,11 +2117,7 @@ pub(crate) fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult { if templ_kind != CXCursor_NoDeclFound { print_indent( depth, - format!( - " {}template-kind = {}", - prefix, - kind_to_str(templ_kind) - ), + format!(" {prefix}template-kind = {}", kind_to_str(templ_kind)), ); } if let Some(usr) = c.usr() { @@ -2149,7 +2144,7 @@ pub(crate) fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult { if let Some(ty) = c.enum_type() { print_indent( depth, - format!(" {}enum-type = {}", prefix, type_to_str(ty.kind())), + format!(" {prefix}enum-type = {}", type_to_str(ty.kind())), ); } if let Some(val) = c.enum_val_signed() { @@ -2158,13 +2153,13 @@ pub(crate) fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult { if let Some(ty) = c.typedef_type() { print_indent( depth, - format!(" {}typedef-type = {}", prefix, type_to_str(ty.kind())), + format!(" {prefix}typedef-type = {}", type_to_str(ty.kind())), ); } if let Some(ty) = c.ret_type() { print_indent( depth, - format!(" {}ret-type = {}", prefix, type_to_str(ty.kind())), + format!(" {prefix}ret-type = {}", type_to_str(ty.kind())), ); } @@ -2214,16 +2209,16 @@ pub(crate) fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult { let prefix = prefix.as_ref(); let kind = ty.kind(); - print_indent(depth, format!(" {}kind = {}", prefix, type_to_str(kind))); + print_indent(depth, format!(" {prefix}kind = {}", type_to_str(kind))); if kind == CXType_Invalid { return; } - print_indent(depth, format!(" {}cconv = {}", prefix, ty.call_conv())); + print_indent(depth, format!(" {prefix}cconv = {}", ty.call_conv())); print_indent( depth, - format!(" {}spelling = \"{}\"", prefix, ty.spelling()), + format!(" {prefix}spelling = \"{}\"", ty.spelling()), ); let num_template_args = unsafe { clang_Type_getNumTemplateArguments(ty.x) }; @@ -2240,7 +2235,7 @@ pub(crate) fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult { } print_indent( depth, - format!(" {}is-variadic? {}", prefix, ty.is_variadic()), + format!(" {prefix}is-variadic? {}", ty.is_variadic()), ); let canonical = ty.canonical_type(); diff --git a/bindgen/codegen/bitfield_unit_tests.rs b/bindgen/codegen/bitfield_unit_tests.rs index 12b7204871..ead0ffec0c 100644 --- a/bindgen/codegen/bitfield_unit_tests.rs +++ b/bindgen/codegen/bitfield_unit_tests.rs @@ -88,8 +88,8 @@ macro_rules! bitfield_unit_get { let actual = unit.get($start, $len); println!(); - println!("expected = {:064b}", expected); - println!("actual = {:064b}", actual); + println!("expected = {expected:064b}"); + println!("actual = {actual:064b}"); assert_eq!(expected, actual); })* @@ -191,7 +191,7 @@ macro_rules! bitfield_unit_set { println!(); println!("set({}, {}, {:032b}", $start, $len, $val); println!("expected = {:064b}", $expected); - println!("actual = {:064b}", actual); + println!("actual = {actual:064b}"); assert_eq!($expected, actual); )* diff --git a/bindgen/codegen/helpers.rs b/bindgen/codegen/helpers.rs index c550d16679..abefeba347 100644 --- a/bindgen/codegen/helpers.rs +++ b/bindgen/codegen/helpers.rs @@ -353,7 +353,7 @@ pub(crate) mod ast_ty { return Ok(tokens); } - warn!("Unknown non-finite float number: {:?}", f); + warn!("Unknown non-finite float number: {f:?}"); Err(()) } diff --git a/bindgen/codegen/impl_debug.rs b/bindgen/codegen/impl_debug.rs index fd4422547e..b0e73b6137 100644 --- a/bindgen/codegen/impl_debug.rs +++ b/bindgen/codegen/impl_debug.rs @@ -2,6 +2,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 std::fmt::Write as _; pub(crate) fn gen_debug_impl( ctx: &BindgenContext, @@ -96,7 +97,7 @@ impl ImplDebug<'_> for BitfieldUnit { } if let Some(bitfield_name) = bitfield.name() { - format_string.push_str(&format!("{bitfield_name} : {{:?}}")); + let _ = write!(format_string, "{bitfield_name} : {{:?}}"); let getter_name = bitfield.getter_name(); let name_ident = ctx.rust_ident_raw(getter_name); tokens.push(quote! { diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 88809e2fbd..4b6561996d 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -503,7 +503,7 @@ impl Item { // TODO(emilio, #453): Figure out what to do when this happens // legitimately, we could track the opaque stuff and disable the // assertion there I guess. - warn!("Found non-allowlisted item in code generation: {:?}", self); + warn!("Found non-allowlisted item in code generation: {self:?}"); } result.set_seen(self.id()); @@ -521,7 +521,7 @@ impl CodeGenerator for Item { result: &mut CodegenResult<'_>, _extra: &(), ) { - debug!("::codegen: self = {:?}", self); + debug!("::codegen: self = {self:?}"); if !self.process_before_codegen(ctx, result) { return; } @@ -553,7 +553,7 @@ impl CodeGenerator for Module { result: &mut CodegenResult<'_>, item: &Item, ) { - debug!("::codegen: item = {:?}", item); + debug!("::codegen: item = {item:?}"); let codegen_self = |result: &mut CodegenResult, found_any: &mut bool| { @@ -652,7 +652,7 @@ impl CodeGenerator for Var { item: &Item, ) { use crate::ir::var::VarType; - debug!("::codegen: item = {:?}", item); + debug!("::codegen: item = {item:?}"); debug_assert!(item.is_enabled_for_codegen(ctx)); let canonical_name = item.canonical_name(ctx); @@ -829,7 +829,7 @@ impl CodeGenerator for Type { result: &mut CodegenResult<'_>, item: &Item, ) { - debug!("::codegen: item = {:?}", item); + debug!("::codegen: item = {item:?}"); debug_assert!(item.is_enabled_for_codegen(ctx)); match *self.kind() { @@ -927,16 +927,14 @@ impl CodeGenerator for Type { assert_eq!( layout.size, ctx.target_pointer_size(), - "Target platform requires `--no-size_t-is-usize`. The size of `{}` ({}) does not match the target pointer size ({})", - spelling, + "Target platform requires `--no-size_t-is-usize`. The size of `{spelling}` ({}) does not match the target pointer size ({})", layout.size, ctx.target_pointer_size(), ); assert_eq!( layout.align, ctx.target_pointer_size(), - "Target platform requires `--no-size_t-is-usize`. The alignment of `{}` ({}) does not match the target pointer size ({})", - spelling, + "Target platform requires `--no-size_t-is-usize`. The alignment of `{spelling}` ({}) does not match the target pointer size ({})", layout.align, ctx.target_pointer_size(), ); @@ -1146,7 +1144,7 @@ impl CodeGenerator for Type { interface.codegen(ctx, result, item) } ref u @ TypeKind::UnresolvedTypeRef(..) => { - unreachable!("Should have been resolved after parsing {:?}!", u) + unreachable!("Should have been resolved after parsing {u:?}!") } } } @@ -2097,7 +2095,7 @@ impl CodeGenerator for CompInfo { result: &mut CodegenResult<'_>, item: &Item, ) { - debug!("::codegen: item = {:?}", item); + debug!("::codegen: item = {item:?}"); debug_assert!(item.is_enabled_for_codegen(ctx)); // Don't output classes with template parameters that aren't types, and @@ -2531,10 +2529,7 @@ impl CodeGenerator for CompInfo { // affect layout, so we're bad and pray to the gods for avoid sending // all the tests to shit when parsing things like max_align_t. if self.found_unknown_attr() { - warn!( - "Type {} has an unknown attribute that may affect layout", - canonical_ident - ); + warn!("Type {canonical_ident} has an unknown attribute that may affect layout"); } if all_template_params.is_empty() { @@ -3544,7 +3539,7 @@ impl CodeGenerator for Enum { result: &mut CodegenResult<'_>, item: &Item, ) { - debug!("::codegen: item = {:?}", item); + debug!("::codegen: item = {item:?}"); debug_assert!(item.is_enabled_for_codegen(ctx)); let name = item.canonical_name(ctx); @@ -3600,8 +3595,7 @@ impl CodeGenerator for Enum { (false, 8) => IntKind::U64, _ => { warn!( - "invalid enum decl: signed: {}, size: {}", - signed, size + "invalid enum decl: signed: {signed}, size: {size}" ); IntKind::I32 } @@ -4355,7 +4349,7 @@ impl TryToRustTy for Type { Ok(syn::parse_quote! { #name }) } ref u @ TypeKind::UnresolvedTypeRef(..) => { - unreachable!("Should have been resolved after parsing {:?}!", u) + unreachable!("Should have been resolved after parsing {u:?}!") } } } @@ -4487,7 +4481,7 @@ impl CodeGenerator for Function { result: &mut CodegenResult<'_>, item: &Item, ) -> Self::Return { - debug!("::codegen: item = {:?}", item); + debug!("::codegen: item = {item:?}"); debug_assert!(item.is_enabled_for_codegen(ctx)); let is_internal = matches!(self.linkage(), Linkage::Internal); @@ -4718,10 +4712,8 @@ fn unsupported_abi_diagnostic( error: &error::Error, ) { warn!( - "Skipping {}function `{}` because the {}", + "Skipping {}function `{fn_name}` because the {error}", if variadic { "variadic " } else { "" }, - fn_name, - error ); #[cfg(feature = "experimental")] @@ -4731,10 +4723,8 @@ fn unsupported_abi_diagnostic( let mut diag = Diagnostic::default(); diag.with_title( format!( - "Skipping {}function `{}` because the {}", + "Skipping {}function `{fn_name}` because the {error}", if variadic { "variadic " } else { "" }, - fn_name, - error ), Level::Warning, ) @@ -4774,8 +4764,7 @@ fn variadic_fn_diagnostic( _ctx: &BindgenContext, ) { warn!( - "Cannot generate wrapper for the static variadic function `{}`.", - fn_name, + "Cannot generate wrapper for the static variadic function `{fn_name}`." ); #[cfg(feature = "experimental")] @@ -4817,7 +4806,7 @@ fn objc_method_codegen( // This would ideally resolve the method into an Item, and use // Item::process_before_codegen; however, ObjC methods are not currently // made into function items. - let name = format!("{}::{}{}", rust_class_name, prefix, method.rust_name()); + let name = format!("{rust_class_name}::{prefix}{}", method.rust_name()); if ctx.options().blocklisted_items.matches(name) { return; } @@ -4854,8 +4843,7 @@ fn objc_method_codegen( ctx.wrap_unsafe_ops(body) }; - let method_name = - ctx.rust_ident(format!("{}{}", prefix, method.rust_name())); + let method_name = ctx.rust_ident(format!("{prefix}{}", method.rust_name())); methods.push(quote! { unsafe fn #method_name #sig where ::Target: objc::Message + Sized { @@ -5095,10 +5083,9 @@ pub(crate) fn codegen( if let Some(path) = context.options().emit_ir_graphviz.as_ref() { match dot::write_dot_file(context, path) { Ok(()) => info!( - "Your dot file was generated successfully into: {}", - path + "Your dot file was generated successfully into: {path}" ), - Err(e) => warn!("{}", e), + Err(e) => warn!("{e}"), } } @@ -5108,7 +5095,7 @@ pub(crate) fn codegen( "Your depfile was generated successfully into: {}", spec.depfile_path.display() ), - Err(e) => warn!("{}", e), + Err(e) => warn!("{e}"), } } diff --git a/bindgen/codegen/serialize.rs b/bindgen/codegen/serialize.rs index 7f25c28dda..a411f63c6d 100644 --- a/bindgen/codegen/serialize.rs +++ b/bindgen/codegen/serialize.rs @@ -114,7 +114,7 @@ impl<'a> CSerialize<'a> for Function { }; // The name used for the wrapper self. - let wrap_name = format!("{}{}", name, ctx.wrap_static_fns_suffix()); + let wrap_name = format!("{name}{}", ctx.wrap_static_fns_suffix()); // The function's return type let (ret_item, ret_ty) = { diff --git a/bindgen/codegen/struct_layout.rs b/bindgen/codegen/struct_layout.rs index e3235dd84c..40edefd540 100644 --- a/bindgen/codegen/struct_layout.rs +++ b/bindgen/codegen/struct_layout.rs @@ -148,7 +148,7 @@ impl<'a> StructLayoutTracker<'a> { } pub(crate) fn saw_bitfield_unit(&mut self, layout: Layout) { - debug!("saw bitfield unit for {}: {:?}", self.name, layout); + debug!("saw bitfield unit for {}: {layout:?}", self.name); self.align_to_latest_field(layout); @@ -248,12 +248,9 @@ impl<'a> StructLayoutTracker<'a> { ); debug!( - "align field {} to {}/{} with {} padding bytes {:?}", - field_name, + "align field {field_name} to {}/{} with {padding_bytes} padding bytes {field_layout:?}", self.latest_offset, field_offset.unwrap_or(0) / 8, - padding_bytes, - field_layout ); let padding_align = if force_padding { @@ -276,8 +273,7 @@ impl<'a> StructLayoutTracker<'a> { self.last_field_was_bitfield = false; debug!( - "Offset: {}: {} -> {}", - field_name, + "Offset: {field_name}: {} -> {}", self.latest_offset - field_layout.size, self.latest_offset ); @@ -312,8 +308,7 @@ impl<'a> StructLayoutTracker<'a> { } trace!( - "need a tail padding field for {}: offset {} -> size {}", - comp_name, + "need a tail padding field for {comp_name}: offset {} -> size {}", self.latest_offset, comp_layout.size ); @@ -325,10 +320,7 @@ impl<'a> StructLayoutTracker<'a> { &mut self, layout: Layout, ) -> Option { - debug!( - "pad_struct:\n\tself = {:#?}\n\tlayout = {:#?}", - self, layout - ); + debug!("pad_struct:\n\tself = {self:#?}\n\tlayout = {layout:#?}"); if layout.size < self.latest_offset { warn!( @@ -368,7 +360,7 @@ impl<'a> StructLayoutTracker<'a> { Layout::new(padding_bytes, layout.align) }; - debug!("pad bytes to struct {}, {:?}", self.name, layout); + debug!("pad bytes to struct {}, {layout:?}", self.name); Some(self.padding_field(layout)) } else { @@ -437,8 +429,8 @@ impl<'a> StructLayoutTracker<'a> { // If it was, we may or may not need to align, depending on what the // current field alignment and the bitfield size and alignment are. debug!( - "align_to_bitfield? {}: {:?} {:?}", - self.last_field_was_bitfield, layout, new_field_layout + "align_to_bitfield? {}: {layout:?} {new_field_layout:?}", + self.last_field_was_bitfield, ); // Avoid divide-by-zero errors if align is 0. diff --git a/bindgen/deps.rs b/bindgen/deps.rs index be31f92896..3f95ac1e89 100644 --- a/bindgen/deps.rs +++ b/bindgen/deps.rs @@ -18,7 +18,7 @@ impl DepfileSpec { let mut buf = format!("{}:", escape(&self.output_module)); for file in deps { - buf = format!("{} {}", buf, escape(file)); + buf = format!("{buf} {}", escape(file)); } buf } diff --git a/bindgen/ir/analysis/derive.rs b/bindgen/ir/analysis/derive.rs index a5140b6000..ef063e188d 100644 --- a/bindgen/ir/analysis/derive.rs +++ b/bindgen/ir/analysis/derive.rs @@ -112,10 +112,8 @@ impl CannotDerive<'_> { ) -> ConstrainResult { let id = id.into(); trace!( - "inserting {:?} can_derive<{}>={:?}", - id, + "inserting {id:?} can_derive<{}>={can_derive:?}", self.derive_trait, - can_derive ); if let CanDerive::Yes = can_derive { @@ -168,7 +166,7 @@ impl CannotDerive<'_> { return CanDerive::No; } - trace!("ty: {:?}", ty); + trace!("ty: {ty:?}"); if item.is_opaque(self.ctx, &()) { if !self.derive_trait.can_derive_union() && ty.is_union() && @@ -432,9 +430,9 @@ impl CannotDerive<'_> { .unwrap_or_default(); match can_derive { - CanDerive::Yes => trace!(" member {:?} can derive {}", sub_id, self.derive_trait), - CanDerive::Manually => trace!(" member {:?} cannot derive {}, but it may be implemented", sub_id, self.derive_trait), - CanDerive::No => trace!(" member {:?} cannot derive {}", sub_id, self.derive_trait), + CanDerive::Yes => trace!(" member {sub_id:?} can derive {}", self.derive_trait), + CanDerive::Manually => trace!(" member {sub_id:?} cannot derive {}, but it may be implemented", self.derive_trait), + CanDerive::No => trace!(" member {sub_id:?} cannot derive {}", self.derive_trait), } *candidate.get_or_insert(CanDerive::Yes) |= can_derive; @@ -527,15 +525,15 @@ impl DeriveTrait { fn can_derive_fnptr(&self, f: &FunctionSig) -> CanDerive { match (self, f.function_pointers_can_derive()) { (DeriveTrait::Copy, _) | (DeriveTrait::Default, _) | (_, true) => { - trace!(" function pointer can derive {}", self); + trace!(" function pointer can derive {self}"); CanDerive::Yes } (DeriveTrait::Debug, false) => { - trace!(" function pointer cannot derive {}, but it may be implemented", self); + trace!(" function pointer cannot derive {self}, but it may be implemented"); CanDerive::Manually } (_, false) => { - trace!(" function pointer cannot derive {}", self); + trace!(" function pointer cannot derive {self}"); CanDerive::No } } @@ -551,7 +549,7 @@ impl DeriveTrait { CanDerive::No } _ => { - trace!(" vector can derive {}", self); + trace!(" vector can derive {self}"); CanDerive::Yes } } @@ -564,7 +562,7 @@ impl DeriveTrait { CanDerive::No } _ => { - trace!(" pointer can derive {}", self); + trace!(" pointer can derive {self}"); CanDerive::Yes } } @@ -597,7 +595,7 @@ impl DeriveTrait { } // === others === _ => { - trace!(" simple type that can always derive {}", self); + trace!(" simple type that can always derive {self}"); CanDerive::Yes } } @@ -658,7 +656,7 @@ impl<'ctx> MonotoneFramework for CannotDerive<'ctx> { } fn constrain(&mut self, id: ItemId) -> ConstrainResult { - trace!("constrain: {:?}", id); + trace!("constrain: {id:?}"); if let Some(CanDerive::No) = self.can_derive.get(&id) { trace!(" already know it cannot derive {}", self.derive_trait); @@ -697,7 +695,7 @@ impl<'ctx> MonotoneFramework for CannotDerive<'ctx> { { if let Some(edges) = self.dependencies.get(&id) { for item in edges { - trace!("enqueue {:?} into worklist", item); + trace!("enqueue {item:?} into worklist"); f(*item); } } diff --git a/bindgen/ir/analysis/has_destructor.rs b/bindgen/ir/analysis/has_destructor.rs index 3a433956e6..4893f8f807 100644 --- a/bindgen/ir/analysis/has_destructor.rs +++ b/bindgen/ir/analysis/has_destructor.rs @@ -161,7 +161,7 @@ impl<'ctx> MonotoneFramework for HasDestructorAnalysis<'ctx> { { if let Some(edges) = self.dependencies.get(&id) { for item in edges { - trace!("enqueue {:?} into worklist", item); + trace!("enqueue {item:?} into worklist"); f(*item); } } diff --git a/bindgen/ir/analysis/has_float.rs b/bindgen/ir/analysis/has_float.rs index 86858813e2..630458e527 100644 --- a/bindgen/ir/analysis/has_float.rs +++ b/bindgen/ir/analysis/has_float.rs @@ -63,7 +63,7 @@ impl HasFloat<'_> { fn insert>(&mut self, id: Id) -> ConstrainResult { let id = id.into(); - trace!("inserting {:?} into the has_float set", id); + trace!("inserting {id:?} into the has_float set"); let was_not_already_in_set = self.has_float.insert(id); assert!( @@ -97,7 +97,7 @@ impl<'ctx> MonotoneFramework for HasFloat<'ctx> { } fn constrain(&mut self, id: ItemId) -> ConstrainResult { - trace!("constrain: {:?}", id); + trace!("constrain: {id:?}"); if self.has_float.contains(&id) { trace!(" already know it do not have float"); @@ -209,7 +209,7 @@ impl<'ctx> MonotoneFramework for HasFloat<'ctx> { if args_have { trace!( " template args have float, so \ - insantiation also has float" + instantiation also has float" ); return self.insert(id); } @@ -220,7 +220,7 @@ impl<'ctx> MonotoneFramework for HasFloat<'ctx> { if def_has { trace!( " template definition has float, so \ - insantiation also has" + instantiation also has" ); return self.insert(id); } @@ -237,7 +237,7 @@ impl<'ctx> MonotoneFramework for HasFloat<'ctx> { { if let Some(edges) = self.dependencies.get(&id) { for item in edges { - trace!("enqueue {:?} into worklist", item); + trace!("enqueue {item:?} into worklist"); f(*item); } } diff --git a/bindgen/ir/analysis/has_type_param_in_array.rs b/bindgen/ir/analysis/has_type_param_in_array.rs index 1029546aad..61a8d631d1 100644 --- a/bindgen/ir/analysis/has_type_param_in_array.rs +++ b/bindgen/ir/analysis/has_type_param_in_array.rs @@ -65,10 +65,7 @@ impl HasTypeParameterInArray<'_> { fn insert>(&mut self, id: Id) -> ConstrainResult { let id = id.into(); - trace!( - "inserting {:?} into the has_type_parameter_in_array set", - id - ); + trace!("inserting {id:?} into the has_type_parameter_in_array set"); let was_not_already_in_set = self.has_type_parameter_in_array.insert(id); @@ -103,7 +100,7 @@ impl<'ctx> MonotoneFramework for HasTypeParameterInArray<'ctx> { } fn constrain(&mut self, id: ItemId) -> ConstrainResult { - trace!("constrain: {:?}", id); + trace!("constrain: {id:?}"); if self.has_type_parameter_in_array.contains(&id) { trace!(" already know it do not have array"); @@ -209,7 +206,7 @@ impl<'ctx> MonotoneFramework for HasTypeParameterInArray<'ctx> { if args_have { trace!( " template args have array, so \ - insantiation also has array" + instantiation also has array" ); return self.insert(id); } @@ -220,7 +217,7 @@ impl<'ctx> MonotoneFramework for HasTypeParameterInArray<'ctx> { if def_has { trace!( " template definition has array, so \ - insantiation also has" + instantiation also has" ); return self.insert(id); } @@ -237,7 +234,7 @@ impl<'ctx> MonotoneFramework for HasTypeParameterInArray<'ctx> { { if let Some(edges) = self.dependencies.get(&id) { for item in edges { - trace!("enqueue {:?} into worklist", item); + trace!("enqueue {item:?} into worklist"); f(*item); } } diff --git a/bindgen/ir/analysis/has_vtable.rs b/bindgen/ir/analysis/has_vtable.rs index 6391be8e76..5099026bbc 100644 --- a/bindgen/ir/analysis/has_vtable.rs +++ b/bindgen/ir/analysis/has_vtable.rs @@ -146,7 +146,7 @@ impl<'ctx> MonotoneFramework for HasVtableAnalysis<'ctx> { } fn constrain(&mut self, id: ItemId) -> ConstrainResult { - trace!("constrain {:?}", id); + trace!("constrain {id:?}"); let item = self.ctx.resolve_item(id); let ty = match item.as_type() { @@ -176,7 +176,7 @@ impl<'ctx> MonotoneFramework for HasVtableAnalysis<'ctx> { } let bases_has_vtable = info.base_members().iter().any(|base| { - trace!(" comp has a base with a vtable: {:?}", base); + trace!(" comp has a base with a vtable: {base:?}"); self.have_vtable.contains_key(&base.ty.into()) }); if bases_has_vtable { @@ -200,7 +200,7 @@ impl<'ctx> MonotoneFramework for HasVtableAnalysis<'ctx> { { if let Some(edges) = self.dependencies.get(&id) { for item in edges { - trace!("enqueue {:?} into worklist", item); + trace!("enqueue {item:?} into worklist"); f(*item); } } diff --git a/bindgen/ir/analysis/sizedness.rs b/bindgen/ir/analysis/sizedness.rs index c6492787ee..ac9921c97a 100644 --- a/bindgen/ir/analysis/sizedness.rs +++ b/bindgen/ir/analysis/sizedness.rs @@ -127,7 +127,7 @@ impl SizednessAnalysis<'_> { id: TypeId, result: SizednessResult, ) -> ConstrainResult { - trace!("inserting {:?} for {:?}", result, id); + trace!("inserting {result:?} for {id:?}"); if let SizednessResult::ZeroSized = result { return ConstrainResult::Same; @@ -196,7 +196,7 @@ impl<'ctx> MonotoneFramework for SizednessAnalysis<'ctx> { } fn constrain(&mut self, id: TypeId) -> ConstrainResult { - trace!("constrain {:?}", id); + trace!("constrain {id:?}"); if let Some(SizednessResult::NonZeroSized) = self.sized.get(&id) { trace!(" already know it is not zero-sized"); @@ -319,7 +319,7 @@ impl<'ctx> MonotoneFramework for SizednessAnalysis<'ctx> { { if let Some(edges) = self.dependencies.get(&id) { for ty in edges { - trace!("enqueue {:?} into worklist", ty); + trace!("enqueue {ty:?} into worklist"); f(*ty); } } diff --git a/bindgen/ir/analysis/template_params.rs b/bindgen/ir/analysis/template_params.rs index 98504b429e..1992473b82 100644 --- a/bindgen/ir/analysis/template_params.rs +++ b/bindgen/ir/analysis/template_params.rs @@ -290,10 +290,8 @@ impl UsedTemplateParameters<'_> { for (arg, param) in args.iter().zip(params.iter()) { trace!( - " instantiation's argument {:?} is used if definition's \ - parameter {:?} is used", - arg, - param + " instantiation's argument {arg:?} is used if definition's \ + parameter {param:?} is used", ); if used_by_def.contains(¶m.into()) { @@ -356,8 +354,7 @@ impl UsedTemplateParameters<'_> { .iter(); trace!( - " union with {:?}'s usage: {:?}", - sub_id, + " union with {sub_id:?}'s usage: {:?}", used_by_sub_id.clone().collect::>() ); @@ -521,8 +518,8 @@ impl<'ctx> MonotoneFramework for UsedTemplateParameters<'ctx> { // an analog to slice::split_at_mut. let mut used_by_this_id = self.take_this_id_usage_set(id); - trace!("constrain {:?}", id); - trace!(" initially, used set is {:?}", used_by_this_id); + trace!("constrain {id:?}"); + trace!(" initially, used set is {used_by_this_id:?}"); let original_len = used_by_this_id.len(); @@ -559,7 +556,7 @@ impl<'ctx> MonotoneFramework for UsedTemplateParameters<'ctx> { _ => self.constrain_join(&mut used_by_this_id, item), } - trace!(" finally, used set is {:?}", used_by_this_id); + trace!(" finally, used set is {used_by_this_id:?}"); let new_len = used_by_this_id.len(); assert!( @@ -586,7 +583,7 @@ impl<'ctx> MonotoneFramework for UsedTemplateParameters<'ctx> { { if let Some(edges) = self.dependencies.get(&item) { for item in edges { - trace!("enqueue {:?} into worklist", item); + trace!("enqueue {item:?} into worklist"); f(*item); } } diff --git a/bindgen/ir/comp.rs b/bindgen/ir/comp.rs index b202888397..ef79641ce2 100644 --- a/bindgen/ir/comp.rs +++ b/bindgen/ir/comp.rs @@ -803,9 +803,8 @@ impl CompFields { anon_field_counter += 1; *name = Some(format!( - "{}{}", + "{}{anon_field_counter}", ctx.options().anon_fields_prefix, - anon_field_counter )); } Field::Bitfields(ref mut bu) => { @@ -1278,7 +1277,7 @@ impl CompInfo { let kind = kind?; - debug!("CompInfo::from_ty({:?}, {:?})", kind, cursor); + debug!("CompInfo::from_ty({kind:?}, {cursor:?})"); let mut ci = CompInfo::new(kind); ci.is_forward_declaration = @@ -1614,7 +1613,7 @@ impl CompInfo { _ => CompKind::Struct, }, _ => { - warn!("Unknown kind for comp type: {:?}", cursor); + warn!("Unknown kind for comp type: {cursor:?}"); return Err(ParseError::Continue); } }) diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index ed6c5406ac..3aa95767c8 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -698,10 +698,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" declaration: Option, location: Option, ) { - debug!( - "BindgenContext::add_item({:?}, declaration: {:?}, loc: {:?}", - item, declaration, location - ); + debug!("BindgenContext::add_item({item:?}, declaration: {declaration:?}, loc: {location:?}"); debug_assert!( declaration.is_some() || !item.kind().is_type() || @@ -753,8 +750,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" // Fortunately, we don't care about those types being // duplicated, so we can just ignore them. debug!( - "Invalid declaration {:?} found for type {:?}", - declaration, + "Invalid declaration {declaration:?} found for type {:?}", self.resolve_item_fallible(id) .unwrap() .kind() @@ -768,10 +764,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" } else if let Some(usr) = declaration.usr() { TypeKey::Usr(usr) } else { - warn!( - "Valid declaration with no USR: {:?}, {:?}", - declaration, location - ); + warn!("Valid declaration with no USR: {declaration:?}, {location:?}"); TypeKey::Declaration(declaration) }; @@ -822,10 +815,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" item: Item, definition: clang::Cursor, ) { - debug!( - "BindgenContext::add_type_param: item = {:?}; definition = {:?}", - item, definition - ); + debug!("BindgenContext::add_type_param: item = {item:?}; definition = {definition:?}"); assert!( item.expect_type().is_type_param(), @@ -1111,7 +1101,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" } for (id, replacement_id) in replacements { - debug!("Replacing {:?} with {:?}", id, replacement_id); + debug!("Replacing {id:?} with {replacement_id:?}"); let new_parent = { let item_id: ItemId = id.into(); let item = self.items[item_id.0].as_mut().unwrap(); @@ -1283,10 +1273,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" id.ancestors(self) .chain(Some(self.root_module.into())) .any(|ancestor| { - debug!( - "Checking if {:?} is a child of {:?}", - id, ancestor - ); + debug!("Checking if {id:?} is a child of {ancestor:?}"); self.resolve_item(ancestor) .as_module() .is_some_and(|m| m.children().contains(&id)) @@ -1452,7 +1439,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" // If at some point we care about the memory here, probably a map TypeKind // -> builtin type ItemId would be the best to improve that. fn add_builtin_item(&mut self, item: Item) { - debug!("add_builtin_item: item = {:?}", item); + debug!("add_builtin_item: item = {item:?}"); debug_assert!(item.kind().is_type()); self.add_item_to_module(&item); let id = item.id(); @@ -1788,8 +1775,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" } _ => { warn!( - "Found template arg cursor we can't handle: {:?}", - child + "Found template arg cursor we can't handle: {child:?}" ); found_const_arg = true; } @@ -1840,7 +1826,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" ); // Bypass all the validations in add_item explicitly. - debug!("instantiate_template: inserting item: {:?}", item); + debug!("instantiate_template: inserting item: {item:?}"); self.add_item_to_module(&item); debug_assert_eq!(with_id, item.id()); self.items[with_id.0] = Some(item); @@ -1873,16 +1859,12 @@ If you encounter an error missing from this list, please file an issue or a PR!" location: Option, ) -> Option { use clang_sys::{CXCursor_TypeAliasTemplateDecl, CXCursor_TypeRef}; - debug!( - "builtin_or_resolved_ty: {:?}, {:?}, {:?}, {:?}", - ty, location, with_id, parent_id - ); + debug!("builtin_or_resolved_ty: {ty:?}, {location:?}, {with_id:?}, {parent_id:?}"); if let Some(decl) = ty.canonical_declaration(location.as_ref()) { if let Some(id) = self.get_resolved_type(&decl) { debug!( - "Already resolved ty {:?}, {:?}, {:?} {:?}", - id, decl, ty, location + "Already resolved ty {id:?}, {decl:?}, {ty:?} {location:?}" ); // If the declaration already exists, then either: // @@ -2203,19 +2185,14 @@ If you encounter an error missing from this list, please file an issue or a PR!" pub(crate) fn replace(&mut self, name: &[String], potential_ty: ItemId) { match self.replacements.entry(name.into()) { Entry::Vacant(entry) => { - debug!( - "Defining replacement for {:?} as {:?}", - name, potential_ty - ); + debug!("Defining replacement for {name:?} as {potential_ty:?}"); entry.insert(potential_ty); } Entry::Occupied(occupied) => { warn!( - "Replacement for {:?} already defined as {:?}; \ - ignoring duplicate replacement definition as {:?}", - name, + "Replacement for {name:?} already defined as {:?}; \ + ignoring duplicate replacement definition as {potential_ty:?}", occupied.get(), - potential_ty ); } } @@ -2312,10 +2289,8 @@ If you encounter an error missing from this list, please file an issue or a PR!" // // See also https://github.com/rust-lang/rust-bindgen/issues/1676. warn!( - "Ignored unknown namespace prefix '{}' at {:?} in {:?}", + "Ignored unknown namespace prefix '{}' at {token:?} in {cursor:?}", String::from_utf8_lossy(name), - token, - cursor ); } } @@ -2495,7 +2470,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" } let name = item.path_for_allowlisting(self)[1..].join("::"); - debug!("allowlisted_items: testing {:?}", name); + debug!("allowlisted_items: testing {name:?}"); if self.options().allowlisted_items.matches(&name) { return true; @@ -3133,7 +3108,7 @@ impl TemplateParameters for PartialType { } fn unused_regex_diagnostic(item: &str, name: &str, _ctx: &BindgenContext) { - warn!("unused option: {} {}", name, item); + warn!("unused option: {name} {item}"); #[cfg(feature = "experimental")] if _ctx.options().emit_diagnostics { diff --git a/bindgen/ir/dot.rs b/bindgen/ir/dot.rs index d5c1a42fdc..9b81b8749c 100644 --- a/bindgen/ir/dot.rs +++ b/bindgen/ir/dot.rs @@ -52,10 +52,9 @@ where match writeln!( &mut dot_file, - "{} -> {} [label={:?}, color={}];", + "{} -> {} [label={edge_kind:?}, color={}];", id.as_usize(), sub_id.as_usize(), - edge_kind, if is_allowlisted { "black" } else { "gray" } ) { Ok(_) => {} diff --git a/bindgen/ir/enum_ty.rs b/bindgen/ir/enum_ty.rs index 1efa1a630b..9b08da3bce 100644 --- a/bindgen/ir/enum_ty.rs +++ b/bindgen/ir/enum_ty.rs @@ -59,7 +59,7 @@ impl Enum { ctx: &mut BindgenContext, ) -> Result { use clang_sys::*; - debug!("Enum::from_ty {:?}", ty); + debug!("Enum::from_ty {ty:?}"); if ty.kind() != CXType_Enum { return Err(ParseError::Continue); diff --git a/bindgen/ir/function.rs b/bindgen/ir/function.rs index f90fe0efe3..6fcb8d1fbb 100644 --- a/bindgen/ir/function.rs +++ b/bindgen/ir/function.rs @@ -418,7 +418,7 @@ impl FunctionSig { ctx: &mut BindgenContext, ) -> Result { use clang_sys::*; - debug!("FunctionSig::from_ty {:?} {:?}", ty, cursor); + debug!("FunctionSig::from_ty {ty:?} {cursor:?}"); // Skip function templates let kind = cursor.kind(); @@ -596,7 +596,7 @@ impl FunctionSig { let abi = get_abi(call_conv); if abi.is_unknown() { - warn!("Unknown calling convention: {:?}", call_conv); + warn!("Unknown calling convention: {call_conv:?}"); } Ok(Self { @@ -726,7 +726,7 @@ impl ClangSubItemParser for Function { Some(k) => k, }; - debug!("Function::parse({:?}, {:?})", cursor, cursor.cur_type()); + debug!("Function::parse({cursor:?}, {:?})", cursor.cur_type()); let visibility = cursor.visibility(); if visibility != CXVisibility_Default { return Err(ParseError::Continue); diff --git a/bindgen/ir/item.rs b/bindgen/ir/item.rs index a728983884..ee0fdc525b 100644 --- a/bindgen/ir/item.rs +++ b/bindgen/ir/item.rs @@ -1420,11 +1420,7 @@ impl Item { CXCursor_UsingDirective | CXCursor_StaticAssert | CXCursor_FunctionTemplate => { - debug!( - "Unhandled cursor kind {:?}: {:?}", - cursor.kind(), - cursor - ); + debug!("Unhandled cursor kind {:?}: {cursor:?}", cursor.kind(),); Err(ParseError::Continue) } @@ -1432,7 +1428,7 @@ impl Item { let file = cursor.get_included_file_name(); match file { None => { - warn!("Inclusion of a nameless file in {:?}", cursor); + warn!("Inclusion of a nameless file in {cursor:?}"); } Some(included_file) => { for cb in &ctx.options().parse_callbacks { @@ -1450,9 +1446,8 @@ impl Item { let spelling = cursor.spelling(); if !spelling.starts_with("operator") { warn!( - "Unhandled cursor kind {:?}: {:?}", + "Unhandled cursor kind {:?}: {cursor:?}", cursor.kind(), - cursor ); } Err(ParseError::Continue) @@ -1489,10 +1484,7 @@ impl Item { parent_id: Option, ctx: &mut BindgenContext, ) -> TypeId { - debug!( - "from_ty_or_ref_with_id: {:?} {:?}, {:?}, {:?}", - potential_id, ty, location, parent_id - ); + debug!("from_ty_or_ref_with_id: {potential_id:?} {ty:?}, {location:?}, {parent_id:?}"); if ctx.collected_typerefs() { debug!("refs already collected, resolving directly"); @@ -1512,11 +1504,11 @@ impl Item { &ty, Some(location), ) { - debug!("{:?} already resolved: {:?}", ty, location); + debug!("{ty:?} already resolved: {location:?}"); return ty; } - debug!("New unresolved type reference: {:?}, {:?}", ty, location); + debug!("New unresolved type reference: {ty:?}, {location:?}"); let is_const = ty.is_const(); let kind = TypeKind::UnresolvedTypeRef(ty, location, parent_id); @@ -1566,10 +1558,9 @@ impl Item { use clang_sys::*; debug!( - "Item::from_ty_with_id: {:?}\n\ - \tty = {:?},\n\ - \tlocation = {:?}", - id, ty, location + "Item::from_ty_with_id: {id:?}\n\ + \tty = {ty:?},\n\ + \tlocation = {location:?}", ); if ty.kind() == clang_sys::CXType_Unexposed || @@ -1593,7 +1584,7 @@ impl Item { // ignore function bodies. See issue #2036.) if let Some(ref parent) = ty.declaration().fallible_semantic_parent() { if FunctionKind::from_cursor(parent).is_some() { - debug!("Skipping type declared inside function: {:?}", ty); + debug!("Skipping type declared inside function: {ty:?}"); return Ok(Item::new_opaque_type(id, ty, ctx)); } } @@ -1640,7 +1631,7 @@ impl Item { .iter() .find(|ty| *ty.decl() == declaration_to_look_for) { - debug!("Avoiding recursion parsing type: {:?}", ty); + debug!("Avoiding recursion parsing type: {ty:?}"); // Unchecked because we haven't finished this type yet. return Ok(partial.id().as_type_id_unchecked()); } diff --git a/bindgen/ir/objc.rs b/bindgen/ir/objc.rs index a748d9a171..d117e152f5 100644 --- a/bindgen/ir/objc.rs +++ b/bindgen/ir/objc.rs @@ -87,7 +87,7 @@ impl ObjCInterface { /// and protocols are like PNSObject pub(crate) fn rust_name(&self) -> String { if let Some(ref cat) = self.category { - format!("{}_{}", self.name(), cat) + format!("{}_{cat}", self.name()) } else if self.is_protocol { format!("P{}", self.name()) } else { @@ -147,8 +147,8 @@ impl ObjCInterface { let needle = format!("P{}", c.spelling()); let items_map = ctx.items(); debug!( - "Interface {} conforms to {}, find the item", - interface.name, needle + "Interface {} conforms to {needle}, find the item", + interface.name, ); for (id, item) in items_map { @@ -163,10 +163,7 @@ impl ObjCInterface { ty.name() ); if Some(needle.as_ref()) == ty.name() { - debug!( - "Found conforming protocol {:?}", - item - ); + debug!("Found conforming protocol {item:?}"); interface.conforms_to.push(id); break; } diff --git a/bindgen/ir/ty.rs b/bindgen/ir/ty.rs index e55175eba0..b3c899c157 100644 --- a/bindgen/ir/ty.rs +++ b/bindgen/ir/ty.rs @@ -685,7 +685,7 @@ impl Type { Some(location), ); if let Some(ty) = already_resolved { - debug!("{:?} already resolved: {:?}", ty, location); + debug!("{ty:?} already resolved: {location:?}"); return Ok(ParseResult::AlreadyResolved(ty.into())); } } @@ -700,8 +700,7 @@ impl Type { }; debug!( - "from_clang_ty: {:?}, ty: {:?}, loc: {:?}", - potential_id, ty, location + "from_clang_ty: {potential_id:?}, ty: {ty:?}, loc: {location:?}" ); debug!("currently_parsed_types: {:?}", ctx.currently_parsed_types()); @@ -776,7 +775,7 @@ impl Type { // etc. !canonical_ty.spelling().contains("type-parameter") => { - debug!("Looking for canonical type: {:?}", canonical_ty); + debug!("Looking for canonical type: {canonical_ty:?}"); return Self::from_clang_ty( potential_id, &canonical_ty, @@ -797,10 +796,7 @@ impl Type { // Same here, with template specialisations we can safely // assume this is a Comp(..) } else if ty.is_fully_instantiated_template() { - debug!( - "Template specialization: {:?}, {:?} {:?}", - ty, location, canonical_ty - ); + debug!("Template specialization: {ty:?}, {location:?} {canonical_ty:?}"); let complex = CompInfo::from_ty( potential_id, ty, @@ -948,13 +944,7 @@ impl Type { let referenced = location.referenced().unwrap(); let referenced_ty = referenced.cur_type(); - debug!( - "TemplateRef: location = {:?}; referenced = \ - {:?}; referenced_ty = {:?}", - location, - referenced, - referenced_ty - ); + debug!("TemplateRef: location = {location:?}; referenced = {referenced:?}; referenced_ty = {referenced_ty:?}"); return Self::from_clang_ty( potential_id, @@ -969,11 +959,7 @@ impl Type { let referenced_ty = referenced.cur_type(); let declaration = referenced_ty.declaration(); - debug!( - "TypeRef: location = {:?}; referenced = \ - {:?}; referenced_ty = {:?}", - location, referenced, referenced_ty - ); + debug!("TypeRef: location = {location:?}; referenced = {referenced:?}; referenced_ty = {referenced_ty:?}"); let id = Item::from_ty_or_ref_with_id( potential_id, @@ -991,16 +977,11 @@ impl Type { } _ => { if ty.kind() == CXType_Unexposed { - warn!( - "Unexposed type {:?}, recursing inside, \ - loc: {:?}", - ty, - location - ); + warn!("Unexposed type {ty:?}, recursing inside, loc: {location:?}"); return Err(ParseError::Recurse); } - warn!("invalid type {:?}", ty); + warn!("invalid type {ty:?}"); return Err(ParseError::Continue); } } @@ -1008,7 +989,7 @@ impl Type { } CXType_Auto => { if canonical_ty == *ty { - debug!("Couldn't find deduced type: {:?}", ty); + debug!("Couldn't find deduced type: {ty:?}"); return Err(ParseError::Continue); } @@ -1203,10 +1184,8 @@ impl Type { } _ => { warn!( - "unsupported type: kind = {:?}; ty = {:?}; at {:?}", + "unsupported type: kind = {:?}; ty = {ty:?}; at {location:?}", ty.kind(), - ty, - location ); return Err(ParseError::Continue); } diff --git a/bindgen/ir/var.rs b/bindgen/ir/var.rs index 2ff148971c..2aa92f84bd 100644 --- a/bindgen/ir/var.rs +++ b/bindgen/ir/var.rs @@ -399,7 +399,7 @@ fn parse_macro_clang_fallback( } let ftu = ctx.try_ensure_fallback_translation_unit()?; - let contents = format!("int main() {{ {}; }}", cursor.spelling(),); + let contents = format!("int main() {{ {}; }}", cursor.spelling()); ftu.reparse(&contents).ok()?; // Children of root node of AST let root_children = ftu.translation_unit().cursor().collect_children(); @@ -480,7 +480,7 @@ fn duplicated_macro_diagnostic( _location: crate::clang::SourceLocation, _ctx: &BindgenContext, ) { - warn!("Duplicated macro definition: {}", macro_name); + warn!("Duplicated macro definition: {macro_name}"); #[cfg(feature = "experimental")] // FIXME (pvdrz & amanjeev): This diagnostic message shows way too often to be actually diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 7b205e9f80..ec8d9a4e65 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -810,8 +810,7 @@ impl Bindings { }; debug!( - "Trying to find clang with flags: {:?}", - clang_args_for_clang_sys + "Trying to find clang with flags: {clang_args_for_clang_sys:?}" ); let clang = match clang_sys::support::Clang::find( @@ -822,7 +821,7 @@ impl Bindings { Some(clang) => clang, }; - debug!("Found clang: {:?}", clang); + debug!("Found clang: {clang:?}"); // Whether we are working with C or C++ inputs. let is_cpp = args_are_cpp(&options.clang_args) || @@ -881,7 +880,7 @@ impl Bindings { options.clang_args.push(f.name.to_str().unwrap().into()) } - debug!("Fixed-up options: {:?}", options); + debug!("Fixed-up options: {options:?}"); let time_phases = options.time_phases; let mut context = BindgenContext::new(options, &input_unsaved_files); @@ -1045,7 +1044,7 @@ impl Bindings { } fn rustfmt_non_fatal_error_diagnostic(msg: &str, _options: &BindgenOptions) { - warn!("{}", msg); + warn!("{msg}"); #[cfg(feature = "experimental")] if _options.emit_diagnostics { @@ -1203,7 +1202,7 @@ fn get_target_dependent_env_var( } if let Ok(v) = env_var( parse_callbacks, - format!("{}_{}", var, target.replace('-', "_")), + format!("{var}_{}", target.replace('-', "_")), ) { return Some(v); } diff --git a/bindgen/regex_set.rs b/bindgen/regex_set.rs index d842af4835..a0825ec010 100644 --- a/bindgen/regex_set.rs +++ b/bindgen/regex_set.rs @@ -99,7 +99,7 @@ impl RegexSet { self.set = match RxSet::new(items) { Ok(x) => Some(x), Err(e) => { - warn!("Invalid regex in {:?}: {:?}", self.items, e); + warn!("Invalid regex in {:?}: {e:?}", self.items); #[cfg(feature = "experimental")] if let Some(name) = _name { invalid_regex_warning(self, e, name); diff --git a/bindgen/time.rs b/bindgen/time.rs index 402327fd5a..435890c42c 100644 --- a/bindgen/time.rs +++ b/bindgen/time.rs @@ -39,7 +39,7 @@ impl<'a> Timer<'a> { (elapsed.subsec_nanos() as f64) / 1e6; let stderr = io::stderr(); // Arbitrary output format, subject to change. - writeln!(stderr.lock(), " time: {:>9.3} ms.\t{}", time, self.name) + writeln!(stderr.lock(), " time: {time:>9.3} ms.\t{}", self.name) .expect("timer write should not fail"); } } diff --git a/book/src/code-formatting.md b/book/src/code-formatting.md index 9c82e83a32..368535c452 100644 --- a/book/src/code-formatting.md +++ b/book/src/code-formatting.md @@ -47,8 +47,7 @@ fn main() { assert!( output.status.success(), - "Unsuccessful status code when running `rustup`: {:?}", - output + "Unsuccessful status code when running `rustup`: {output:?}", ); let rustfmt_path = diff --git a/book/src/tutorial-5.md b/book/src/tutorial-5.md index de91d092a1..8a71dac355 100644 --- a/book/src/tutorial-5.md +++ b/book/src/tutorial-5.md @@ -40,7 +40,7 @@ mod tests { r if r == (BZ_PARAM_ERROR as _) => panic!("BZ_PARAM_ERROR"), r if r == (BZ_MEM_ERROR as _) => panic!("BZ_MEM_ERROR"), r if r == (BZ_OK as _) => {}, - r => panic!("Unknown return value = {}", r), + r => panic!("Unknown return value = {r}"), } // Compress `input` into `compressed_output`. @@ -55,7 +55,7 @@ mod tests { r if r == (BZ_FINISH_OK as _) => panic!("BZ_FINISH_OK"), r if r == (BZ_SEQUENCE_ERROR as _) => panic!("BZ_SEQUENCE_ERROR"), r if r == (BZ_STREAM_END as _) => {}, - r => panic!("Unknown return value = {}", r), + r => panic!("Unknown return value = {r}"), } // Finish the compression stream. @@ -63,7 +63,7 @@ mod tests { match result { r if r == (BZ_PARAM_ERROR as _) => panic!("BZ_PARAM_ERROR"), r if r == (BZ_OK as _) => {}, - r => panic!("Unknown return value = {}", r), + r => panic!("Unknown return value = {r}"), } // Construct a decompression stream. @@ -76,7 +76,7 @@ mod tests { r if r == (BZ_PARAM_ERROR as _) => panic!("BZ_PARAM_ERROR"), r if r == (BZ_MEM_ERROR as _) => panic!("BZ_MEM_ERROR"), r if r == (BZ_OK as _) => {}, - r => panic!("Unknown return value = {}", r), + r => panic!("Unknown return value = {r}"), } // Decompress `compressed_output` into `decompressed_output`. @@ -92,7 +92,7 @@ mod tests { r if r == (BZ_MEM_ERROR as _) => panic!("BZ_MEM_ERROR"), r if r == (BZ_OK as _) => panic!("BZ_OK"), r if r == (BZ_STREAM_END as _) => {}, - r => panic!("Unknown return value = {}", r), + r => panic!("Unknown return value = {r}"), } // Close the decompression stream. @@ -100,7 +100,7 @@ mod tests { match result { r if r == (BZ_PARAM_ERROR as _) => panic!("BZ_PARAM_ERROR"), r if r == (BZ_OK as _) => {}, - r => panic!("Unknown return value = {}", r), + r => panic!("Unknown return value = {r}"), } assert_eq!(input, &decompressed_output[..]); From 6f0b754367748595cb9c2f60b011559c72181375 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Sat, 30 Nov 2024 12:44:38 -0500 Subject: [PATCH 784/942] Linting semicolons ``` cargo clippy --workspace --fix --all-targets -- -A clippy::all -W clippy::semicolon_if_nothing_returned ``` --- bindgen-cli/main.rs | 2 +- bindgen-tests/tests/expectations/Cargo.toml | 4 ++++ bindgen-tests/tests/expectations/lib.rs | 3 --- bindgen-tests/tests/quickchecking/src/bin.rs | 2 +- bindgen-tests/tests/quickchecking/src/lib.rs | 2 +- bindgen/clang.rs | 2 +- bindgen/codegen/mod.rs | 22 +++++++++---------- .../postprocessing/merge_extern_blocks.rs | 6 ++--- .../postprocessing/sort_semantically.rs | 6 ++--- bindgen/codegen/serialize.rs | 14 ++++++------ bindgen/ir/analysis/has_vtable.rs | 2 +- bindgen/ir/analysis/sizedness.rs | 2 +- bindgen/ir/analysis/template_params.rs | 2 +- bindgen/ir/annotations.rs | 4 ++-- bindgen/ir/comp.rs | 2 +- bindgen/ir/context.rs | 6 ++--- bindgen/ir/derive.rs | 2 +- bindgen/ir/module.rs | 4 ++-- bindgen/ir/objc.rs | 2 +- bindgen/ir/traversal.rs | 4 ++-- bindgen/ir/ty.rs | 16 +++++++------- bindgen/lib.rs | 4 ++-- bindgen/options/cli.rs | 2 +- bindgen/regex_set.rs | 6 ++--- 24 files changed, 61 insertions(+), 60 deletions(-) diff --git a/bindgen-cli/main.rs b/bindgen-cli/main.rs index 3eca487f8c..2d8d370ef1 100644 --- a/bindgen-cli/main.rs +++ b/bindgen-cli/main.rs @@ -35,7 +35,7 @@ pub fn main() { std::panic::set_hook(Box::new(move |info| { if verbose { - print_verbose_err() + print_verbose_err(); } eprintln!("{info}"); })); diff --git a/bindgen-tests/tests/expectations/Cargo.toml b/bindgen-tests/tests/expectations/Cargo.toml index e720636062..c096a197e5 100644 --- a/bindgen-tests/tests/expectations/Cargo.toml +++ b/bindgen-tests/tests/expectations/Cargo.toml @@ -21,7 +21,10 @@ objc = "0.2" # deprecated = "allow" # invalid-value = "allow" # unsupported_calling_conventions = "allow" +dead_code = "allow" non-snake-case = "allow" +non_camel_case_types = "allow" +non_upper_case_globals = "allow" unexpected-cfgs = "allow" [lints.clippy] @@ -30,6 +33,7 @@ manual-c-str-literals = "allow" missing-safety-doc = "allow" op-ref = "allow" ptr-offset-with-cast = "allow" +semicolon_if_nothing_returned = "allow" too-many-arguments = "allow" transmute-int-to-bool = "allow" unnecessary-cast = "allow" diff --git a/bindgen-tests/tests/expectations/lib.rs b/bindgen-tests/tests/expectations/lib.rs index 562dc5548d..e69de29bb2 100755 --- a/bindgen-tests/tests/expectations/lib.rs +++ b/bindgen-tests/tests/expectations/lib.rs @@ -1,3 +0,0 @@ -#![allow(dead_code)] -#![allow(non_camel_case_types)] -#![allow(non_upper_case_globals)] diff --git a/bindgen-tests/tests/quickchecking/src/bin.rs b/bindgen-tests/tests/quickchecking/src/bin.rs index fcd56652be..66da94fe7e 100644 --- a/bindgen-tests/tests/quickchecking/src/bin.rs +++ b/bindgen-tests/tests/quickchecking/src/bin.rs @@ -105,5 +105,5 @@ fn main() { let generate_range = *matches.get_one::("range").unwrap(); let tests = *matches.get_one::("count").unwrap(); - quickchecking::test_bindgen(generate_range, tests, output_path) + quickchecking::test_bindgen(generate_range, tests, output_path); } diff --git a/bindgen-tests/tests/quickchecking/src/lib.rs b/bindgen-tests/tests/quickchecking/src/lib.rs index 382e4f9935..2f0b575c3f 100644 --- a/bindgen-tests/tests/quickchecking/src/lib.rs +++ b/bindgen-tests/tests/quickchecking/src/lib.rs @@ -103,5 +103,5 @@ pub fn test_bindgen( QuickCheck::new() .tests(tests) .gen(Gen::new(generate_range)) - .quickcheck(bindgen_prop as fn(fuzzers::HeaderC) -> TestResult) + .quickcheck(bindgen_prop as fn(fuzzers::HeaderC) -> TestResult); } diff --git a/bindgen/clang.rs b/bindgen/clang.rs index f34f680343..bca4a80978 100644 --- a/bindgen/clang.rs +++ b/bindgen/clang.rs @@ -1144,7 +1144,7 @@ impl Eq for Cursor {} impl Hash for Cursor { fn hash(&self, state: &mut H) { - unsafe { clang_hashCursor(self.x) }.hash(state) + unsafe { clang_hashCursor(self.x) }.hash(state); } } diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 4b6561996d..c58237c17b 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -852,7 +852,7 @@ impl CodeGenerator for Type { // it to BindgenContext::compute_allowlisted_and_codegen_items. } TypeKind::TemplateInstantiation(ref inst) => { - inst.codegen(ctx, result, item) + inst.codegen(ctx, result, item); } TypeKind::BlockPointer(inner) => { if !ctx.options().generate_block { @@ -1141,7 +1141,7 @@ impl CodeGenerator for Type { result.saw_objc(); } TypeKind::ObjCInterface(ref interface) => { - interface.codegen(ctx, result, item) + interface.codegen(ctx, result, item); } ref u @ TypeKind::UnresolvedTypeRef(..) => { unreachable!("Should have been resolved after parsing {u:?}!") @@ -1228,7 +1228,7 @@ impl CodeGenerator for Vtable<'_> { pub struct #name { #( #methods ),* } - }) + }); } else { // For the cases we don't support, simply generate an empty struct. let void = helpers::ast_ty::c_void(ctx); @@ -2321,7 +2321,7 @@ impl CodeGenerator for CompInfo { let ty = helpers::blob(layout); fields.push(quote! { pub bindgen_union_field: #ty , - }) + }); } } @@ -2470,7 +2470,7 @@ impl CodeGenerator for CompInfo { derives.extend(custom_derives.iter().map(|s| s.as_str())); if !derives.is_empty() { - attributes.push(attributes::derives(&derives)) + attributes.push(attributes::derives(&derives)); } attributes.extend( @@ -3094,7 +3094,7 @@ impl Method { quote! { __bindgen_tmp } - }) + }); } let block = ctx.wrap_unsafe_ops(quote! ( #( #stmts );*)); @@ -4754,7 +4754,7 @@ fn unsupported_abi_diagnostic( } } - diag.display() + diag.display(); } } @@ -4791,7 +4791,7 @@ fn variadic_fn_diagnostic( } } - diag.display() + diag.display(); } } @@ -5221,10 +5221,10 @@ pub(crate) mod utils { } match ty.kind() { TypeKind::Alias(type_id_alias) => { - type_id = *type_id_alias + type_id = *type_id_alias; } TypeKind::ResolvedTypeRef(type_id_typedef) => { - type_id = *type_id_typedef + type_id = *type_id_typedef; } _ => break, } @@ -5705,7 +5705,7 @@ pub(crate) mod utils { .collect::>(); if is_variadic { - args.push(quote! { ... }) + args.push(quote! { ... }); } args diff --git a/bindgen/codegen/postprocessing/merge_extern_blocks.rs b/bindgen/codegen/postprocessing/merge_extern_blocks.rs index 10fa0ec80b..e0f6a34baa 100644 --- a/bindgen/codegen/postprocessing/merge_extern_blocks.rs +++ b/bindgen/codegen/postprocessing/merge_extern_blocks.rs @@ -4,7 +4,7 @@ use syn::{ }; pub(super) fn merge_extern_blocks(file: &mut File) { - Visitor.visit_file_mut(file) + Visitor.visit_file_mut(file); } struct Visitor; @@ -12,14 +12,14 @@ struct Visitor; impl VisitMut for Visitor { fn visit_file_mut(&mut self, file: &mut File) { visit_items(&mut file.items); - visit_file_mut(self, file) + visit_file_mut(self, file); } fn visit_item_mod_mut(&mut self, item_mod: &mut ItemMod) { if let Some((_, ref mut items)) = item_mod.content { visit_items(items); } - visit_item_mod_mut(self, item_mod) + visit_item_mod_mut(self, item_mod); } } diff --git a/bindgen/codegen/postprocessing/sort_semantically.rs b/bindgen/codegen/postprocessing/sort_semantically.rs index be94ce69c5..e9bb5dc308 100644 --- a/bindgen/codegen/postprocessing/sort_semantically.rs +++ b/bindgen/codegen/postprocessing/sort_semantically.rs @@ -4,7 +4,7 @@ use syn::{ }; pub(super) fn sort_semantically(file: &mut File) { - Visitor.visit_file_mut(file) + Visitor.visit_file_mut(file); } struct Visitor; @@ -12,14 +12,14 @@ struct Visitor; impl VisitMut for Visitor { fn visit_file_mut(&mut self, file: &mut File) { visit_items(&mut file.items); - visit_file_mut(self, file) + visit_file_mut(self, file); } fn visit_item_mod_mut(&mut self, item_mod: &mut ItemMod) { if let Some((_, ref mut items)) = item_mod.content { visit_items(items); } - visit_item_mod_mut(self, item_mod) + visit_item_mod_mut(self, item_mod); } } diff --git a/bindgen/codegen/serialize.rs b/bindgen/codegen/serialize.rs index a411f63c6d..864d86b452 100644 --- a/bindgen/codegen/serialize.rs +++ b/bindgen/codegen/serialize.rs @@ -228,13 +228,13 @@ impl<'a> CSerialize<'a> for Type { if self.is_const() { write!(writer, "const ")?; } - write!(writer, "void")? + write!(writer, "void")?; } TypeKind::NullPtr => { if self.is_const() { write!(writer, "const ")?; } - write!(writer, "nullptr_t")? + write!(writer, "nullptr_t")?; } TypeKind::Int(int_kind) => { if self.is_const() { @@ -285,7 +285,7 @@ impl<'a> CSerialize<'a> for Type { FloatKind::Float => write!(writer, "float complex")?, FloatKind::Double => write!(writer, "double complex")?, FloatKind::LongDouble => { - write!(writer, "long double complex")? + write!(writer, "long double complex")?; } FloatKind::Float128 => write!(writer, "__complex128")?, } @@ -303,7 +303,7 @@ impl<'a> CSerialize<'a> for Type { } TypeKind::Array(type_id, length) => { type_id.serialize(ctx, (), stack, writer)?; - write!(writer, " [{length}]")? + write!(writer, " [{length}]")?; } TypeKind::Function(signature) => { if self.is_const() { @@ -341,14 +341,14 @@ impl<'a> CSerialize<'a> for Type { type_id.serialize(ctx, (), &mut stack, buf) }, )?; - write!(writer, ")")? + write!(writer, ")")?; } } TypeKind::ResolvedTypeRef(type_id) => { if self.is_const() { write!(writer, "const ")?; } - type_id.serialize(ctx, (), stack, writer)? + type_id.serialize(ctx, (), stack, writer)?; } TypeKind::Pointer(type_id) => { if self.is_const() { @@ -356,7 +356,7 @@ impl<'a> CSerialize<'a> for Type { } else { stack.push("*".to_owned()); } - type_id.serialize(ctx, (), stack, writer)? + type_id.serialize(ctx, (), stack, writer)?; } TypeKind::Comp(comp_info) => { if self.is_const() { diff --git a/bindgen/ir/analysis/has_vtable.rs b/bindgen/ir/analysis/has_vtable.rs index 5099026bbc..0953df6eba 100644 --- a/bindgen/ir/analysis/has_vtable.rs +++ b/bindgen/ir/analysis/has_vtable.rs @@ -40,7 +40,7 @@ impl ops::BitOr for HasVtableResult { impl ops::BitOrAssign for HasVtableResult { fn bitor_assign(&mut self, rhs: HasVtableResult) { - *self = self.join(rhs) + *self = self.join(rhs); } } diff --git a/bindgen/ir/analysis/sizedness.rs b/bindgen/ir/analysis/sizedness.rs index ac9921c97a..ce3c2c3da1 100644 --- a/bindgen/ir/analysis/sizedness.rs +++ b/bindgen/ir/analysis/sizedness.rs @@ -80,7 +80,7 @@ impl ops::BitOr for SizednessResult { impl ops::BitOrAssign for SizednessResult { fn bitor_assign(&mut self, rhs: SizednessResult) { - *self = self.join(rhs) + *self = self.join(rhs); } } diff --git a/bindgen/ir/analysis/template_params.rs b/bindgen/ir/analysis/template_params.rs index 1992473b82..778a515d4c 100644 --- a/bindgen/ir/analysis/template_params.rs +++ b/bindgen/ir/analysis/template_params.rs @@ -474,7 +474,7 @@ impl<'ctx> MonotoneFramework for UsedTemplateParameters<'ctx> { extra_assert!(dependencies.contains_key(&sub_item)); }, &(), - ) + ); } } diff --git a/bindgen/ir/annotations.rs b/bindgen/ir/annotations.rs index 79f42df983..600bfa8b64 100644 --- a/bindgen/ir/annotations.rs +++ b/bindgen/ir/annotations.rs @@ -227,7 +227,7 @@ impl Annotations { "replaces" => { self.use_instead_of = Some( attr.value.split("::").map(Into::into).collect(), - ) + ); } "derive" => self.derives.push(attr.value), "attribute" => self.attributes.push(attr.value), @@ -239,7 +239,7 @@ impl Annotations { }; } "accessor" => { - self.accessor_kind = Some(parse_accessor(&attr.value)) + self.accessor_kind = Some(parse_accessor(&attr.value)); } "constant" => self.constify_enum_variant = true, _ => {} diff --git a/bindgen/ir/comp.rs b/bindgen/ir/comp.rs index ef79641ce2..68884bd20a 100644 --- a/bindgen/ir/comp.rs +++ b/bindgen/ir/comp.rs @@ -1698,7 +1698,7 @@ impl CompInfo { layout: Option<&Layout>, ) { let packed = self.is_packed(ctx, layout); - self.fields.compute_bitfield_units(ctx, packed) + self.fields.compute_bitfield_units(ctx, packed); } /// Assign for each anonymous field a generated name. diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index 3aa95767c8..d8bcaba1d4 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -2238,7 +2238,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" let mut module_name = None; let spelling = cursor.spelling(); if !spelling.is_empty() { - module_name = Some(spelling) + module_name = Some(spelling); } let mut kind = ModuleKind::Normal; @@ -2621,7 +2621,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// Call if a bindgen complex is generated pub(crate) fn generated_bindgen_complex(&self) { - self.generated_bindgen_complex.set(true) + self.generated_bindgen_complex.set(true); } /// Whether we need to generate the bindgen complex type @@ -2631,7 +2631,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// Call if a bindgen float16 is generated pub(crate) fn generated_bindgen_float16(&self) { - self.generated_bindgen_float16.set(true) + self.generated_bindgen_float16.set(true); } /// Whether we need to generate the bindgen float16 type diff --git a/bindgen/ir/derive.rs b/bindgen/ir/derive.rs index 5475ffdb22..3ee6476af9 100644 --- a/bindgen/ir/derive.rs +++ b/bindgen/ir/derive.rs @@ -125,6 +125,6 @@ impl ops::BitOr for CanDerive { impl ops::BitOrAssign for CanDerive { fn bitor_assign(&mut self, rhs: Self) { - *self = self.join(rhs) + *self = self.join(rhs); } } diff --git a/bindgen/ir/module.rs b/bindgen/ir/module.rs index 5ec55e9048..4788cf4285 100644 --- a/bindgen/ir/module.rs +++ b/bindgen/ir/module.rs @@ -84,8 +84,8 @@ impl ClangSubItemParser for Module { let module_id = ctx.module(cursor); ctx.with_module(module_id, |ctx| { cursor.visit_sorted(ctx, |ctx, child| { - parse_one(ctx, child, Some(module_id.into())) - }) + parse_one(ctx, child, Some(module_id.into())); + }); }); Ok(ParseResult::AlreadyResolved(module_id.into())) diff --git a/bindgen/ir/objc.rs b/bindgen/ir/objc.rs index d117e152f5..6d83095924 100644 --- a/bindgen/ir/objc.rs +++ b/bindgen/ir/objc.rs @@ -305,7 +305,7 @@ impl ObjCMethod { let arg = arg.to_string(); let name_and_sig: Vec<&str> = arg.split(' ').collect(); let name = name_and_sig[0]; - args_without_types.push(Ident::new(name, Span::call_site())) + args_without_types.push(Ident::new(name, Span::call_site())); } let args = split_name.into_iter().zip(args_without_types).map( diff --git a/bindgen/ir/traversal.rs b/bindgen/ir/traversal.rs index 9a0a02b8c4..ccf3af9a25 100644 --- a/bindgen/ir/traversal.rs +++ b/bindgen/ir/traversal.rs @@ -344,7 +344,7 @@ where F: FnMut(ItemId, EdgeKind), { fn visit_kind(&mut self, item: ItemId, kind: EdgeKind) { - (*self)(item, kind) + (*self)(item, kind); } } @@ -437,7 +437,7 @@ where let is_newly_discovered = self.seen.add(self.currently_traversing, item); if is_newly_discovered { - self.queue.push(item) + self.queue.push(item); } } } diff --git a/bindgen/ir/ty.rs b/bindgen/ir/ty.rs index b3c899c157..fc3bfa6088 100644 --- a/bindgen/ir/ty.rs +++ b/bindgen/ir/ty.rs @@ -471,7 +471,7 @@ impl TypeKind { #[test] fn is_invalid_type_param_valid() { let ty = Type::new(Some("foo".into()), None, TypeKind::TypeParam, false); - assert!(!ty.is_invalid_type_param()) + assert!(!ty.is_invalid_type_param()); } #[test] @@ -482,38 +482,38 @@ fn is_invalid_type_param_valid_underscore_and_numbers() { TypeKind::TypeParam, false, ); - assert!(!ty.is_invalid_type_param()) + assert!(!ty.is_invalid_type_param()); } #[test] fn is_invalid_type_param_valid_unnamed_kind() { let ty = Type::new(Some("foo".into()), None, TypeKind::Void, false); - assert!(!ty.is_invalid_type_param()) + assert!(!ty.is_invalid_type_param()); } #[test] fn is_invalid_type_param_invalid_start() { let ty = Type::new(Some("1foo".into()), None, TypeKind::TypeParam, false); - assert!(ty.is_invalid_type_param()) + assert!(ty.is_invalid_type_param()); } #[test] fn is_invalid_type_param_invalid_remaining() { let ty = Type::new(Some("foo-".into()), None, TypeKind::TypeParam, false); - assert!(ty.is_invalid_type_param()) + assert!(ty.is_invalid_type_param()); } #[test] #[should_panic] fn is_invalid_type_param_unnamed() { let ty = Type::new(None, None, TypeKind::TypeParam, false); - assert!(ty.is_invalid_type_param()) + assert!(ty.is_invalid_type_param()); } #[test] fn is_invalid_type_param_empty_name() { let ty = Type::new(Some("".into()), None, TypeKind::TypeParam, false); - assert!(ty.is_invalid_type_param()) + assert!(ty.is_invalid_type_param()); } impl TemplateParameters for Type { @@ -710,7 +710,7 @@ impl Type { let mut ty_kind = ty.kind(); match location.kind() { CXCursor_ObjCProtocolDecl | CXCursor_ObjCCategoryDecl => { - ty_kind = CXType_ObjCInterface + ty_kind = CXType_ObjCInterface; } _ => {} } diff --git a/bindgen/lib.rs b/bindgen/lib.rs index ec8d9a4e65..e599f759c7 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -877,7 +877,7 @@ impl Bindings { if idx != 0 || !options.input_headers.is_empty() { options.clang_args.push("-include".into()); } - options.clang_args.push(f.name.to_str().unwrap().into()) + options.clang_args.push(f.name.to_str().unwrap().into()); } debug!("Fixed-up options: {options:?}"); @@ -1134,7 +1134,7 @@ fn parse(context: &mut BindgenContext) -> Result<(), BindgenError> { let root = context.root_module(); context.with_module(root, |ctx| { - cursor.visit_sorted(ctx, |ctx, child| parse_one(ctx, child, None)) + cursor.visit_sorted(ctx, |ctx, child| parse_one(ctx, child, None)); }); assert!( diff --git a/bindgen/options/cli.rs b/bindgen/options/cli.rs index e444432d16..834c7c7625 100644 --- a/bindgen/options/cli.rs +++ b/bindgen/options/cli.rs @@ -1069,7 +1069,7 @@ impl CliArg for bool { f: impl Fn(Builder, Self::Value) -> Builder, ) -> Builder { if self { - builder = f(builder, self) + builder = f(builder, self); } builder diff --git a/bindgen/regex_set.rs b/bindgen/regex_set.rs index a0825ec010..be0041dcfa 100644 --- a/bindgen/regex_set.rs +++ b/bindgen/regex_set.rs @@ -56,7 +56,7 @@ impl RegexSet { #[inline] #[allow(unused)] pub(crate) fn build(&mut self, record_matches: bool) { - self.build_inner(record_matches, None) + self.build_inner(record_matches, None); } #[cfg(all(feature = "__cli", feature = "experimental"))] @@ -71,7 +71,7 @@ impl RegexSet { record_matches: bool, name: Option<&'static str>, ) { - self.build_inner(record_matches, name) + self.build_inner(record_matches, name); } #[cfg(all(not(feature = "__cli"), feature = "experimental"))] @@ -86,7 +86,7 @@ impl RegexSet { record_matches: bool, name: Option<&'static str>, ) { - self.build_inner(record_matches, name) + self.build_inner(record_matches, name); } fn build_inner( From d5b72c497cf00a55326c840b4ca73d9a188c903f Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Sat, 30 Nov 2024 14:29:35 -0500 Subject: [PATCH 785/942] sort dependencies --- Cargo.toml | 4 ++-- bindgen-cli/Cargo.toml | 1 - bindgen-tests/Cargo.toml | 5 ++--- bindgen/Cargo.toml | 3 +-- 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 31c386bc26..34b949b1ed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,9 +16,9 @@ default-members = [ # Dependencies shared between crates [workspace.dependencies] -shlex = "1" -syn = "2.0" proc-macro2 = { version = "1", default-features = false } +shlex = "1" +syn = "2.0" # Config for 'cargo dist' [workspace.metadata.dist] diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index d6ab1b06e2..0dd1d7378f 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -23,7 +23,6 @@ name = "bindgen" bindgen = { path = "../bindgen", version = "=0.70.1", default-features = false, features = ["__cli", "experimental", "prettyplease"] } env_logger = { version = "0.10.0", optional = true } log = { version = "0.4", optional = true } - proc-macro2.workspace = true shlex.workspace = true diff --git a/bindgen-tests/Cargo.toml b/bindgen-tests/Cargo.toml index b9547bb1ad..061d824ad9 100644 --- a/bindgen-tests/Cargo.toml +++ b/bindgen-tests/Cargo.toml @@ -8,12 +8,11 @@ publish = false bindgen = { path = "../bindgen", features = ["__cli", "experimental"] } owo-colors = "3.5.0" prettyplease = { version = "0.2.7", features = ["verbatim"] } -similar = { version = "2.2.1", features = ["inline"] } -tempfile = "3" - proc-macro2.workspace = true shlex.workspace = true +similar = { version = "2.2.1", features = ["inline"] } syn.workspace = true +tempfile = "3" [features] logging = ["bindgen/logging"] diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index 47462e1788..d8b95de7ca 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -34,11 +34,10 @@ clap_complete = { version = "4", optional = true} itertools = { version = ">=0.10,<0.14", default-features = false } log = { version = "0.4", optional = true } prettyplease = { version = "0.2.7", optional = true, features = ["verbatim"] } +proc-macro2.workspace = true quote = { version = "1", default-features = false } regex = { version = "1.5.3", default-features = false, features = ["std", "unicode-perl"] } rustc-hash = "1.0.1" - -proc-macro2.workspace = true shlex.workspace = true syn = { workspace = true, features = ["full", "extra-traits", "visit-mut"] } From e55cc8da77ff4942cea65c6bcd606017a02d456f Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Sat, 30 Nov 2024 14:41:18 -0500 Subject: [PATCH 786/942] consolidate versions in one place --- Cargo.toml | 31 ++++++++++++++-- bindgen-cli/Cargo.toml | 12 +++---- bindgen-integration/Cargo.toml | 7 ++-- bindgen-tests/Cargo.toml | 13 +++---- bindgen-tests/tests/expectations/Cargo.toml | 9 ++--- bindgen-tests/tests/quickchecking/Cargo.toml | 10 +++--- bindgen/Cargo.toml | 37 ++++++++++---------- 7 files changed, 74 insertions(+), 45 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 34b949b1ed..a6bb4f8acc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,11 +14,38 @@ default-members = [ "bindgen-tests", ] -# Dependencies shared between crates +[workspace.package] +# If you change this, also update README.md and msrv in .github/workflows/bindgen.yml +rust-version = "1.70.0" +edition = "2021" + +# All dependency version management is centralized here [workspace.dependencies] -proc-macro2 = { version = "1", default-features = false } +annotate-snippets = "0.11.4" +bindgen = { path = "./bindgen", default-features = false } +bitflags = "2.2.1" +block = "0.1" +cc = "1.0" +cexpr = "0.6" +clang-sys = "1" +clap = "4" +clap_complete = "4" +env_logger = "0.10.0" +itertools = { version = ">=0.10,<0.14", default-features = false } +libloading = "0.7" +log = "0.4" +objc = "0.2" +owo-colors = "3.5.0" +prettyplease = "0.2.7" +proc-macro2 = "1" +quickcheck = "1.0" +quote = { version = "1", default-features = false } +regex = { version = "1.5.3", default-features = false } +rustc-hash = "1.0.1" shlex = "1" +similar = "2.2.1" syn = "2.0" +tempfile = "3" # Config for 'cargo dist' [workspace.metadata.dist] diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index 0dd1d7378f..09a3f554f7 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -1,6 +1,6 @@ [package] authors = [ - "The rust-bindgen project contributors", + "The rust-bindgen project contributors", ] description = "Automatically generates Rust FFI bindings to C and C++ libraries." keywords = ["bindings", "ffi", "code-generation"] @@ -12,17 +12,17 @@ repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" version = "0.70.1" -edition = "2021" -rust-version = "1.70.0" +rust-version.workspace = true +edition.workspace = true [[bin]] path = "main.rs" name = "bindgen" [dependencies] -bindgen = { path = "../bindgen", version = "=0.70.1", default-features = false, features = ["__cli", "experimental", "prettyplease"] } -env_logger = { version = "0.10.0", optional = true } -log = { version = "0.4", optional = true } +bindgen = { workspace = true, features = ["__cli", "experimental", "prettyplease"] } +env_logger = { workspace = true, optional = true } +log = { workspace = true, optional = true } proc-macro2.workspace = true shlex.workspace = true diff --git a/bindgen-integration/Cargo.toml b/bindgen-integration/Cargo.toml index 38b52322cc..13bbcd094d 100644 --- a/bindgen-integration/Cargo.toml +++ b/bindgen-integration/Cargo.toml @@ -4,12 +4,13 @@ description = "A package to test various bindgen features" version = "0.1.0" authors = ["Emilio Cobos Álvarez "] publish = false -edition = "2021" build = "build.rs" +rust-version.workspace = true +edition.workspace = true [build-dependencies] -bindgen = { path = "../bindgen", features = ["experimental"] } -cc = "1.0" +bindgen = { workspace = true, default-features = true, features = ["experimental"] } +cc.workspace = true [features] static = ["bindgen/static"] diff --git a/bindgen-tests/Cargo.toml b/bindgen-tests/Cargo.toml index 061d824ad9..346be51cd7 100644 --- a/bindgen-tests/Cargo.toml +++ b/bindgen-tests/Cargo.toml @@ -1,18 +1,19 @@ [package] name = "bindgen-tests" -edition = "2021" version = "0.1.0" publish = false +rust-version.workspace = true +edition.workspace = true [dev-dependencies] -bindgen = { path = "../bindgen", features = ["__cli", "experimental"] } -owo-colors = "3.5.0" -prettyplease = { version = "0.2.7", features = ["verbatim"] } +bindgen = { workspace = true, default-features = true, features = ["__cli", "experimental"] } +owo-colors.workspace = true +prettyplease = { workspace = true, features = ["verbatim"] } proc-macro2.workspace = true shlex.workspace = true -similar = { version = "2.2.1", features = ["inline"] } +similar = { workspace = true, features = ["inline"] } syn.workspace = true -tempfile = "3" +tempfile.workspace = true [features] logging = ["bindgen/logging"] diff --git a/bindgen-tests/tests/expectations/Cargo.toml b/bindgen-tests/tests/expectations/Cargo.toml index c096a197e5..2f77baf774 100644 --- a/bindgen-tests/tests/expectations/Cargo.toml +++ b/bindgen-tests/tests/expectations/Cargo.toml @@ -7,13 +7,14 @@ authors = [ "Emilio Cobos Álvarez ", "The Servo project developers", ] -edition = "2021" publish = false +rust-version.workspace = true +edition.workspace = true [dependencies] -block = "0.1" -libloading = "0.7" -objc = "0.2" +block.workspace = true +libloading.workspace = true +objc.workspace = true [lints.rust] ### FIXME: these might need to be fixed, diff --git a/bindgen-tests/tests/quickchecking/Cargo.toml b/bindgen-tests/tests/quickchecking/Cargo.toml index 998643bbf4..ca36eb1c37 100644 --- a/bindgen-tests/tests/quickchecking/Cargo.toml +++ b/bindgen-tests/tests/quickchecking/Cargo.toml @@ -3,8 +3,8 @@ name = "quickchecking" description = "Bindgen property tests with quickcheck. Generate random valid C code and pass it to the csmith/predicate.py script" version = "0.0.0" publish = false -rust-version = "1.70" -edition = "2021" +rust-version.workspace = true +edition.workspace = true [lib] name = "quickchecking" @@ -15,9 +15,9 @@ name = "quickchecking" path = "src/bin.rs" [dependencies] -clap = "4" -quickcheck = "1.0" -tempfile = "3" +clap.workspace = true +quickcheck.workspace = true +tempfile.workspace = true [features] # No features by default. diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index d8b95de7ca..dd4166de95 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -1,9 +1,9 @@ [package] authors = [ - "Jyun-Yan You ", - "Emilio Cobos Álvarez ", - "Nick Fitzgerald ", - "The Servo project developers", + "Jyun-Yan You ", + "Emilio Cobos Álvarez ", + "Nick Fitzgerald ", + "The Servo project developers", ] description = "Automatically generates Rust FFI bindings to C and C++ libraries." keywords = ["bindings", "ffi", "code-generation"] @@ -15,29 +15,28 @@ repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" version = "0.70.1" -edition = "2021" build = "build.rs" -# If you change this, also update README.md and msrv in .github/workflows/bindgen.yml -rust-version = "1.70.0" +rust-version.workspace = true +edition.workspace = true [lib] name = "bindgen" path = "lib.rs" [dependencies] -annotate-snippets = { version = "0.11.4", optional = true } -bitflags = "2.2.1" -cexpr = "0.6" -clang-sys = { version = "1", features = ["clang_11_0"] } -clap = { version = "4", features = ["derive"], optional = true } -clap_complete = { version = "4", optional = true} -itertools = { version = ">=0.10,<0.14", default-features = false } -log = { version = "0.4", optional = true } -prettyplease = { version = "0.2.7", optional = true, features = ["verbatim"] } +annotate-snippets = { workspace = true, optional = true } +bitflags.workspace = true +cexpr.workspace = true +clang-sys = { workspace = true, features = ["clang_11_0"] } +clap = { workspace = true, features = ["derive"], optional = true } +clap_complete = { workspace = true, optional = true } +itertools = { workspace = true } +log = { workspace = true, optional = true } +prettyplease = { workspace = true, optional = true, features = ["verbatim"] } proc-macro2.workspace = true -quote = { version = "1", default-features = false } -regex = { version = "1.5.3", default-features = false, features = ["std", "unicode-perl"] } -rustc-hash = "1.0.1" +quote.workspace = true +regex = { workspace = true, features = ["std", "unicode-perl"] } +rustc-hash.workspace = true shlex.workspace = true syn = { workspace = true, features = ["full", "extra-traits", "visit-mut"] } From 061cc5ea31a5f38db243b6fd4733014c93dcc610 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Sat, 30 Nov 2024 15:28:05 -0500 Subject: [PATCH 787/942] automate MSRV in CI --- .github/workflows/bindgen.yml | 16 ++++++++-------- Cargo.toml | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index d1a11712d0..836052a5a6 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -37,25 +37,25 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Read crate metadata + id: metadata + run: echo "rust-version=$(sed -ne 's/rust-version *= *\"\(.*\)\"/\1/p' Cargo.toml)" >> $GITHUB_OUTPUT + - name: Install msrv for lib uses: dtolnay/rust-toolchain@master with: - # MSRV below is documented in Cargo.toml and README.md, please update those if you - # change this. - toolchain: 1.70.0 + toolchain: ${{ steps.metadata.outputs.rust-version }} - name: Test lib with msrv - run: cargo +1.70.0 test --package bindgen + run: cargo +${{ steps.metadata.outputs.rust-version }} test --package bindgen - name: Install msrv for cli uses: dtolnay/rust-toolchain@master with: - # MSRV below is documented in Cargo.toml and README.md, please update those if you - # change this. - toolchain: 1.70.0 + toolchain: ${{ steps.metadata.outputs.rust-version }} - name: Test cli with msrv - run: cargo +1.70.0 build --package bindgen-cli + run: cargo +${{ steps.metadata.outputs.rust-version }} build --package bindgen-cli minimal: runs-on: ubuntu-latest diff --git a/Cargo.toml b/Cargo.toml index a6bb4f8acc..87b464aa50 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ default-members = [ ] [workspace.package] -# If you change this, also update README.md and msrv in .github/workflows/bindgen.yml +# If you change this, also update README.md rust-version = "1.70.0" edition = "2021" From 491549abb0d0827298b36404c7540a7cec53dc93 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Sat, 30 Nov 2024 22:17:35 -0500 Subject: [PATCH 788/942] Consolidate clippy configuration Move all clippy configurations to one central place, except for the expected tests - they seem to require their own handling for now due to a Cargo limitation. Also, fixed a lot of `unused_qualifications` lints. --- Cargo.toml | 14 ++++++++++++++ bindgen-cli/Cargo.toml | 2 ++ bindgen-integration/Cargo.toml | 2 ++ bindgen-tests/Cargo.toml | 2 ++ bindgen-tests/tests/expectations/Cargo.toml | 5 +++++ bindgen-tests/tests/quickchecking/Cargo.toml | 2 ++ bindgen/Cargo.toml | 2 ++ 7 files changed, 29 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 87b464aa50..5e6f348f17 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,6 +47,20 @@ similar = "2.2.1" syn = "2.0" tempfile = "3" +[workspace.lints.rust] +# unused_qualifications = "warn" + +[workspace.lints.clippy] +# disallowed-names = "allow" +# manual-c-str-literals = "allow" +# missing-safety-doc = "allow" +# op-ref = "allow" +# ptr-offset-with-cast = "allow" +# too-many-arguments = "allow" +# transmute-int-to-bool = "allow" +# unnecessary-cast = "allow" +# useless-transmute = "allow" + # Config for 'cargo dist' [workspace.metadata.dist] # The preferred cargo-dist version to use in CI (Cargo.toml SemVer syntax) diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index 09a3f554f7..d1e0bf4012 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -1,3 +1,5 @@ +lints.workspace = true + [package] authors = [ "The rust-bindgen project contributors", diff --git a/bindgen-integration/Cargo.toml b/bindgen-integration/Cargo.toml index 13bbcd094d..5c8c89d528 100644 --- a/bindgen-integration/Cargo.toml +++ b/bindgen-integration/Cargo.toml @@ -1,3 +1,5 @@ +lints.workspace = true + [package] name = "bindgen-integration" description = "A package to test various bindgen features" diff --git a/bindgen-tests/Cargo.toml b/bindgen-tests/Cargo.toml index 346be51cd7..3a13c59cfa 100644 --- a/bindgen-tests/Cargo.toml +++ b/bindgen-tests/Cargo.toml @@ -1,3 +1,5 @@ +lints.workspace = true + [package] name = "bindgen-tests" version = "0.1.0" diff --git a/bindgen-tests/tests/expectations/Cargo.toml b/bindgen-tests/tests/expectations/Cargo.toml index 2f77baf774..975fd16678 100644 --- a/bindgen-tests/tests/expectations/Cargo.toml +++ b/bindgen-tests/tests/expectations/Cargo.toml @@ -16,17 +16,22 @@ block.workspace = true libloading.workspace = true objc.workspace = true +# Both of these sections need to be copied here from the workspace because +# Cargo currently does not allow overriding workspace settings in a member [lints.rust] ### FIXME: these might need to be fixed, ### esp the calling convention, because it is a hard error now # deprecated = "allow" # invalid-value = "allow" # unsupported_calling_conventions = "allow" +# +# Different from the workspace dead_code = "allow" non-snake-case = "allow" non_camel_case_types = "allow" non_upper_case_globals = "allow" unexpected-cfgs = "allow" +unused_qualifications = "allow" [lints.clippy] disallowed-names = "allow" diff --git a/bindgen-tests/tests/quickchecking/Cargo.toml b/bindgen-tests/tests/quickchecking/Cargo.toml index ca36eb1c37..b26ba3b392 100644 --- a/bindgen-tests/tests/quickchecking/Cargo.toml +++ b/bindgen-tests/tests/quickchecking/Cargo.toml @@ -1,3 +1,5 @@ +lints.workspace = true + [package] name = "quickchecking" description = "Bindgen property tests with quickcheck. Generate random valid C code and pass it to the csmith/predicate.py script" diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index dd4166de95..8f61afe23b 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -1,3 +1,5 @@ +lints.workspace = true + [package] authors = [ "Jyun-Yan You ", From 6bb890b0c6567eda870f1158d411e021d3dee6c2 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Sat, 30 Nov 2024 14:41:18 -0500 Subject: [PATCH 789/942] Bump some dependencies --- Cargo.lock | 316 +++++++++++++++++++++++++++-------------------------- Cargo.toml | 6 +- 2 files changed, 164 insertions(+), 158 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e5918dcc6d..f7accc9e68 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "aho-corasick" -version = "0.7.20" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" dependencies = [ "memchr", ] @@ -23,9 +23,15 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.8" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" +checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" + +[[package]] +name = "autocfg" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] name = "bindgen" @@ -45,7 +51,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.18", + "syn 2.0.90", ] [[package]] @@ -77,7 +83,7 @@ dependencies = [ "proc-macro2", "shlex", "similar", - "syn 2.0.18", + "syn 2.0.90", "tempfile", ] @@ -101,9 +107,12 @@ checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" [[package]] name = "cc" -version = "1.0.78" +version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a20104e2335ce8a659d6dd92a51a767a0c062599c73b343fd152cb401e828c3d" +checksum = "f34d93e62b03caf570cccc334cbc6c2fceca82f39211051345108adcba3eebdc" +dependencies = [ + "shlex", +] [[package]] name = "cexpr" @@ -122,9 +131,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clang-sys" -version = "1.4.0" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa2e27ae6ab525c3d369ded447057bca5438d86dc3a68f6faafb8269ba82ebf3" +checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" dependencies = [ "glob", "libc", @@ -165,7 +174,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 1.0.107", + "syn 1.0.109", ] [[package]] @@ -179,9 +188,9 @@ dependencies = [ [[package]] name = "either" -version = "1.8.1" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] name = "env_logger" @@ -208,39 +217,28 @@ dependencies = [ [[package]] name = "errno" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a" -dependencies = [ - "errno-dragonfly", - "libc", - "windows-sys 0.48.0", -] - -[[package]] -name = "errno-dragonfly" -version = "0.1.2" +version = "0.3.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" dependencies = [ - "cc", "libc", + "windows-sys 0.52.0", ] [[package]] name = "fastrand" -version = "1.8.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499" +checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" dependencies = [ "instant", ] [[package]] name = "getrandom" -version = "0.2.8" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", "libc", @@ -255,15 +253,21 @@ checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" [[package]] name = "heck" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "hermit-abi" -version = "0.3.2" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "hermit-abi" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc" [[package]] name = "humantime" @@ -282,24 +286,24 @@ dependencies = [ [[package]] name = "io-lifetimes" -version = "1.0.4" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7d6c6f8c91b4b9ed43484ad1a938e393caf35960fce7f82a040497207bd8e9e" +checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" dependencies = [ + "hermit-abi 0.3.9", "libc", - "windows-sys 0.42.0", + "windows-sys 0.48.0", ] [[package]] name = "is-terminal" -version = "0.4.7" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adcf93614601c8129ddf72e2d5633df827ba6551541c6d8c59520a371475be1f" +checksum = "261f68e344040fbd0edea105bef17c66edf46f984ddb1115b775ce31be948f4b" dependencies = [ - "hermit-abi", - "io-lifetimes", - "rustix", - "windows-sys 0.48.0", + "hermit-abi 0.4.0", + "libc", + "windows-sys 0.52.0", ] [[package]] @@ -313,18 +317,18 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.159" +version = "0.2.167" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" +checksum = "09d6582e104315a817dff97f75133544b2e094ee22447d2acf4a74e189ba06fc" [[package]] name = "libloading" -version = "0.7.4" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" +checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34" dependencies = [ "cfg-if", - "winapi", + "windows-targets 0.52.6", ] [[package]] @@ -335,12 +339,9 @@ checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" [[package]] name = "log" -version = "0.4.17" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" -dependencies = [ - "cfg-if", -] +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] name = "malloc_buf" @@ -353,9 +354,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.5.0" +version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "minimal-lexical" @@ -384,9 +385,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.17.0" +version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] name = "os_str_bytes" @@ -396,18 +397,18 @@ checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee" [[package]] name = "owo-colors" -version = "3.5.0" +version = "4.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" +checksum = "fb37767f6569cd834a413442455e0f066d0d522de8630436e2a1761d9726ba56" [[package]] name = "prettyplease" -version = "0.2.7" +version = "0.2.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43ded2b5b204571f065ab8540367d738dfe1b3606ab9eb669dcfb5e7a3a07501" +checksum = "64d1ec885c64d0457d564db4ec299b2dae3f9c02808b8ad9c3a089c591b18033" dependencies = [ "proc-macro2", - "syn 2.0.18", + "syn 2.0.90", ] [[package]] @@ -419,7 +420,7 @@ dependencies = [ "proc-macro-error-attr", "proc-macro2", "quote", - "syn 1.0.107", + "syn 1.0.109", "version_check", ] @@ -465,9 +466,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.28" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b9ab9c7eadfd8df19006f1cf1a4aed13540ed5cbc047010ece5826e10825488" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -501,9 +502,21 @@ dependencies = [ [[package]] name = "regex" -version = "1.7.1" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" dependencies = [ "aho-corasick", "memchr", @@ -512,28 +525,28 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.28" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "rustc-hash" -version = "1.1.0" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" +checksum = "c7fb8039b3032c191086b10f11f319a6e99e1e82889c5cc6046f515c9db1d497" [[package]] name = "rustix" -version = "0.37.7" +version = "0.37.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2aae838e49b3d63e9274e1c01833cc8139d3fec468c3b84688c628f44b1ae11d" +checksum = "fea8ca367a3a01fe35e6943c400addf443c0f57670e6ec51196f71a4b8762dd2" dependencies = [ "bitflags 1.3.2", "errno", "io-lifetimes", "libc", "linux-raw-sys", - "windows-sys 0.45.0", + "windows-sys 0.48.0", ] [[package]] @@ -544,9 +557,9 @@ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "similar" -version = "2.2.1" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "420acb44afdae038210c99e69aae24109f32f15500aa708e81d46c9f29d55fcf" +checksum = "1de1d4f81173b03af4c0cbed3c898f6bff5b870e4a7f5d6f4057d62a7a4b686e" [[package]] name = "strsim" @@ -556,9 +569,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "1.0.107" +version = "1.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ "proc-macro2", "quote", @@ -567,9 +580,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.18" +version = "2.0.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32d41677bcbe24c20c52e7c70b0d8db04134c5d1066bf98662e2871ad200ea3e" +checksum = "919d3b74a5dd0ccd15aeb8f93e7006bd9e14c295087c9896a110f490752bcf31" dependencies = [ "proc-macro2", "quote", @@ -578,15 +591,16 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.5.0" +version = "3.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9fbec84f381d5795b08656e4912bec604d162bff9291d6189a78f4c8ab87998" +checksum = "31c0432476357e58790aaa47a8efb0c5138f137343f3b5f23bd36a27e3b0a6d6" dependencies = [ + "autocfg", "cfg-if", "fastrand", "redox_syscall", "rustix", - "windows-sys 0.45.0", + "windows-sys 0.48.0", ] [[package]] @@ -609,15 +623,15 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.6" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" +checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" [[package]] name = "unicode-width" -version = "0.1.13" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" [[package]] name = "version_check" @@ -664,147 +678,139 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows-sys" -version = "0.42.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" -dependencies = [ - "windows_aarch64_gnullvm 0.42.2", - "windows_aarch64_msvc 0.42.2", - "windows_i686_gnu 0.42.2", - "windows_i686_msvc 0.42.2", - "windows_x86_64_gnu 0.42.2", - "windows_x86_64_gnullvm 0.42.2", - "windows_x86_64_msvc 0.42.2", -] - -[[package]] -name = "windows-sys" -version = "0.45.0" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ - "windows-targets 0.42.2", + "windows-targets 0.48.5", ] [[package]] name = "windows-sys" -version = "0.48.0" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.48.1", + "windows-targets 0.52.6", ] [[package]] name = "windows-targets" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ - "windows_aarch64_gnullvm 0.42.2", - "windows_aarch64_msvc 0.42.2", - "windows_i686_gnu 0.42.2", - "windows_i686_msvc 0.42.2", - "windows_x86_64_gnu 0.42.2", - "windows_x86_64_gnullvm 0.42.2", - "windows_x86_64_msvc 0.42.2", + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", ] [[package]] name = "windows-targets" -version = "0.48.1" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm 0.48.0", - "windows_aarch64_msvc 0.48.0", - "windows_i686_gnu 0.48.0", - "windows_i686_msvc 0.48.0", - "windows_x86_64_gnu 0.48.0", - "windows_x86_64_gnullvm 0.48.0", - "windows_x86_64_msvc 0.48.0", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", ] [[package]] name = "windows_aarch64_gnullvm" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_gnullvm" -version = "0.48.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_msvc" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_aarch64_msvc" -version = "0.48.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_i686_gnu" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_gnu" -version = "0.48.0" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_i686_msvc" -version = "0.48.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_x86_64_gnu" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnu" -version = "0.48.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnullvm" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_gnullvm" -version = "0.48.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_msvc" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "windows_x86_64_msvc" -version = "0.48.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" diff --git a/Cargo.toml b/Cargo.toml index 5e6f348f17..cd5e4e6223 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,16 +32,16 @@ clap = "4" clap_complete = "4" env_logger = "0.10.0" itertools = { version = ">=0.10,<0.14", default-features = false } -libloading = "0.7" +libloading = "0.8" log = "0.4" objc = "0.2" -owo-colors = "3.5.0" +owo-colors = "4.1.0" prettyplease = "0.2.7" proc-macro2 = "1" quickcheck = "1.0" quote = { version = "1", default-features = false } regex = { version = "1.5.3", default-features = false } -rustc-hash = "1.0.1" +rustc-hash = "2.1.0" shlex = "1" similar = "2.2.1" syn = "2.0" From 76a11344400d7489da0e9dd2f9ca72982e31a391 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Sat, 30 Nov 2024 22:17:35 -0500 Subject: [PATCH 790/942] Fix a lot of `unused_qualifications` lints --- bindgen-integration/build.rs | 2 +- bindgen-tests/tests/tests.rs | 10 +++++----- bindgen/build.rs | 4 ++-- bindgen/clang.rs | 6 ++---- bindgen/codegen/dyngen.rs | 20 ++++++++++---------- bindgen/codegen/mod.rs | 26 +++++++++++++------------- bindgen/ir/comment.rs | 2 +- bindgen/ir/comp.rs | 3 +-- bindgen/ir/context.rs | 29 +++++++++++------------------ bindgen/ir/dot.rs | 2 +- bindgen/ir/item.rs | 4 ++-- bindgen/ir/layout.rs | 5 ++--- bindgen/ir/ty.rs | 7 +------ bindgen/ir/var.rs | 2 +- bindgen/lib.rs | 11 ++++++----- bindgen/options/cli.rs | 4 +++- 16 files changed, 62 insertions(+), 75 deletions(-) diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs index c712569816..583f46ea93 100644 --- a/bindgen-integration/build.rs +++ b/bindgen-integration/build.rs @@ -183,7 +183,7 @@ fn setup_macro_test() { let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); let out_rust_file = out_path.join("test.rs"); let out_rust_file_relative = out_rust_file - .strip_prefix(std::env::current_dir().unwrap().parent().unwrap()) + .strip_prefix(env::current_dir().unwrap().parent().unwrap()) .unwrap(); let out_dep_file = out_path.join("test.d"); diff --git a/bindgen-tests/tests/tests.rs b/bindgen-tests/tests/tests.rs index bbe7eb2e24..abb5f96953 100644 --- a/bindgen-tests/tests/tests.rs +++ b/bindgen-tests/tests/tests.rs @@ -371,7 +371,7 @@ include!(concat!(env!("OUT_DIR"), "/tests.rs")); #[test] #[cfg_attr(target_os = "windows", ignore)] fn test_clang_env_args() { - std::env::set_var( + env::set_var( "BINDGEN_EXTRA_CLANG_ARGS", "-D_ENV_ONE=1 -D_ENV_TWO=\"2 -DNOT_THREE=1\"", ); @@ -653,8 +653,8 @@ fn emit_depfile() { builder.into_builder(check_roundtrip).unwrap(); let _bindings = builder.generate().unwrap(); - let observed = std::fs::read_to_string(observed_depfile).unwrap(); - let expected = std::fs::read_to_string(expected_depfile).unwrap(); + let observed = fs::read_to_string(observed_depfile).unwrap(); + let expected = fs::read_to_string(expected_depfile).unwrap(); assert_eq!(observed.trim(), expected.trim()); } @@ -694,7 +694,7 @@ fn dump_preprocessed_input() { ); } -fn build_flags_output_helper(builder: &bindgen::Builder) { +fn build_flags_output_helper(builder: &Builder) { let mut command_line_flags = builder.command_line_flags(); command_line_flags.insert(0, "bindgen".to_string()); @@ -712,7 +712,7 @@ fn build_flags_output_helper(builder: &bindgen::Builder) { #[test] fn commandline_multiple_headers() { - let bindings = bindgen::Builder::default() + let bindings = Builder::default() .header("tests/headers/char.h") .header("tests/headers/func_ptr.h") .header("tests/headers/16-byte-alignment.h"); diff --git a/bindgen/build.rs b/bindgen/build.rs index 8407ceae8f..4fb2d3075e 100644 --- a/bindgen/build.rs +++ b/bindgen/build.rs @@ -20,10 +20,10 @@ fn main() { println!("cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS"); println!( "cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_{}", - std::env::var("TARGET").unwrap() + env::var("TARGET").unwrap() ); println!( "cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_{}", - std::env::var("TARGET").unwrap().replace('-', "_") + env::var("TARGET").unwrap().replace('-', "_") ); } diff --git a/bindgen/clang.rs b/bindgen/clang.rs index bca4a80978..327ec137b0 100644 --- a/bindgen/clang.rs +++ b/bindgen/clang.rs @@ -961,13 +961,11 @@ impl Cursor { /// /// Returns None if the cursor does not include a file, otherwise the file's full name pub(crate) fn get_included_file_name(&self) -> Option { - let file = unsafe { clang_sys::clang_getIncludedFile(self.x) }; + let file = unsafe { clang_getIncludedFile(self.x) }; if file.is_null() { None } else { - Some(unsafe { - cxstring_into_string(clang_sys::clang_getFileName(file)) - }) + Some(unsafe { cxstring_into_string(clang_getFileName(file)) }) } } diff --git a/bindgen/codegen/dyngen.rs b/bindgen/codegen/dyngen.rs index e75e11a297..6bdea51eff 100644 --- a/bindgen/codegen/dyngen.rs +++ b/bindgen/codegen/dyngen.rs @@ -14,7 +14,7 @@ pub(crate) struct DynamicItems { /// ... /// } /// ``` - struct_members: Vec, + struct_members: Vec, /// Tracks the tokens that will appear inside the library struct's implementation, e.g.: /// @@ -26,7 +26,7 @@ pub(crate) struct DynamicItems { /// } /// } /// ``` - struct_implementation: Vec, + struct_implementation: Vec, /// Tracks the initialization of the fields inside the `::new` constructor of the library /// struct, e.g.: @@ -45,7 +45,7 @@ pub(crate) struct DynamicItems { /// ... /// } /// ``` - constructor_inits: Vec, + constructor_inits: Vec, /// Tracks the information that is passed to the library struct at the end of the `::new` /// constructor, e.g.: @@ -65,7 +65,7 @@ pub(crate) struct DynamicItems { /// } /// } /// ``` - init_fields: Vec, + init_fields: Vec, } impl DynamicItems { @@ -77,7 +77,7 @@ impl DynamicItems { &self, lib_ident: Ident, ctx: &BindgenContext, - ) -> proc_macro2::TokenStream { + ) -> TokenStream { let struct_members = &self.struct_members; let constructor_inits = &self.constructor_inits; let init_fields = &self.init_fields; @@ -134,11 +134,11 @@ impl DynamicItems { abi: ClangAbi, is_variadic: bool, is_required: bool, - args: Vec, - args_identifiers: Vec, - ret: proc_macro2::TokenStream, - ret_ty: proc_macro2::TokenStream, - attributes: Vec, + args: Vec, + args_identifiers: Vec, + ret: TokenStream, + ret_ty: TokenStream, + attributes: Vec, ctx: &BindgenContext, ) { if !is_variadic { diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index c58237c17b..f60a75d23a 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -3180,7 +3180,7 @@ impl fmt::Display for EnumVariation { } } -impl std::str::FromStr for EnumVariation { +impl FromStr for EnumVariation { type Err = std::io::Error; /// Create a `EnumVariation` from a string. @@ -3886,7 +3886,7 @@ impl fmt::Display for MacroTypeVariation { } } -impl std::str::FromStr for MacroTypeVariation { +impl FromStr for MacroTypeVariation { type Err = std::io::Error; /// Create a `MacroTypeVariation` from a string. @@ -3929,7 +3929,7 @@ impl fmt::Display for AliasVariation { } } -impl std::str::FromStr for AliasVariation { +impl FromStr for AliasVariation { type Err = std::io::Error; /// Create an `AliasVariation` from a string. @@ -3978,7 +3978,7 @@ impl Default for NonCopyUnionStyle { } } -impl std::str::FromStr for NonCopyUnionStyle { +impl FromStr for NonCopyUnionStyle { type Err = std::io::Error; fn from_str(s: &str) -> Result { @@ -4096,7 +4096,7 @@ where if let Ok(layout) = self.try_get_layout(ctx, extra) { Ok(helpers::blob(layout)) } else { - Err(error::Error::NoLayoutForOpaqueBlob) + Err(Error::NoLayoutForOpaqueBlob) } }) } @@ -4207,7 +4207,7 @@ impl TryToOpaque for Type { ctx: &BindgenContext, _: &Item, ) -> error::Result { - self.layout(ctx).ok_or(error::Error::NoLayoutForOpaqueBlob) + self.layout(ctx).ok_or(Error::NoLayoutForOpaqueBlob) } } @@ -4365,7 +4365,7 @@ impl TryToOpaque for TemplateInstantiation { ) -> error::Result { item.expect_type() .layout(ctx) - .ok_or(error::Error::NoLayoutForOpaqueBlob) + .ok_or(Error::NoLayoutForOpaqueBlob) } } @@ -4378,7 +4378,7 @@ impl TryToRustTy for TemplateInstantiation { item: &Item, ) -> error::Result { if self.is_opaque(ctx, item) { - return Err(error::Error::InstantiationOfOpaqueType); + return Err(Error::InstantiationOfOpaqueType); } let def = self @@ -4400,7 +4400,7 @@ impl TryToRustTy for TemplateInstantiation { // template specialization, and we've hit an instantiation of // that partial specialization. extra_assert!(def.is_opaque(ctx, &())); - return Err(error::Error::InstantiationOfOpaqueType); + return Err(Error::InstantiationOfOpaqueType); } // TODO: If the definition type is a template class/struct @@ -4452,7 +4452,7 @@ impl TryToRustTy for FunctionSig { syn::parse_quote! { unsafe extern #abi fn ( #( #arguments ),* ) #ret }, ), Err(err) => { - if matches!(err, error::Error::UnsupportedAbi(_)) { + if matches!(err, Error::UnsupportedAbi(_)) { unsupported_abi_diagnostic( self.name(), self.is_variadic(), @@ -4568,7 +4568,7 @@ impl CodeGenerator for Function { let abi = match signature.abi(ctx, Some(name)) { Err(err) => { - if matches!(err, error::Error::UnsupportedAbi(_)) { + if matches!(err, Error::UnsupportedAbi(_)) { unsupported_abi_diagnostic( name, signature.is_variadic(), @@ -4709,7 +4709,7 @@ fn unsupported_abi_diagnostic( variadic: bool, location: Option<&crate::clang::SourceLocation>, ctx: &BindgenContext, - error: &error::Error, + error: &Error, ) { warn!( "Skipping {}function `{fn_name}` because the {error}", @@ -5676,7 +5676,7 @@ pub(crate) mod utils { pub(crate) fn fnsig_arguments_iter< 'a, - I: Iterator, crate::ir::context::TypeId)>, + I: Iterator, TypeId)>, >( ctx: &BindgenContext, args_iter: I, diff --git a/bindgen/ir/comment.rs b/bindgen/ir/comment.rs index 03fc76ff98..a4ba320186 100644 --- a/bindgen/ir/comment.rs +++ b/bindgen/ir/comment.rs @@ -13,7 +13,7 @@ enum Kind { /// Preprocesses a C/C++ comment so that it is a valid Rust comment. pub(crate) fn preprocess(comment: &str) -> String { - match self::kind(comment) { + match kind(comment) { Some(Kind::SingleLines) => preprocess_single_lines(comment), Some(Kind::MultiLine) => preprocess_multi_line(comment), None => comment.to_owned(), diff --git a/bindgen/ir/comp.rs b/bindgen/ir/comp.rs index 68884bd20a..093d553ad0 100644 --- a/bindgen/ir/comp.rs +++ b/bindgen/ir/comp.rs @@ -1473,8 +1473,7 @@ impl CompInfo { ty: type_id, kind, field_name, - is_pub: cur.access_specifier() == - clang_sys::CX_CXXPublic, + is_pub: cur.access_specifier() == CX_CXXPublic, }); } CXCursor_Constructor | CXCursor_Destructor | diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index d8bcaba1d4..6cdf8b4af8 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -319,7 +319,7 @@ pub(crate) struct BindgenContext { /// Maps from a cursor to the item ID of the named template type parameter /// for that cursor. - type_params: HashMap, + type_params: HashMap, /// A cursor to module map. Similar reason than above. modules: HashMap, @@ -336,7 +336,7 @@ pub(crate) struct BindgenContext { /// This is used to handle the cases where the semantic and the lexical /// parents of the cursor differ, like when a nested class is defined /// outside of the parent class. - semantic_parents: HashMap, + semantic_parents: HashMap, /// A stack with the current type declarations and types we're parsing. This /// is needed to avoid infinite recursion when parsing a type like: @@ -810,11 +810,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Add a new named template type parameter to this context's item set. - pub(crate) fn add_type_param( - &mut self, - item: Item, - definition: clang::Cursor, - ) { + pub(crate) fn add_type_param(&mut self, item: Item, definition: Cursor) { debug!("BindgenContext::add_type_param: item = {item:?}; definition = {definition:?}"); assert!( @@ -846,10 +842,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// Get the named type defined at the given cursor location, if we've /// already added one. - pub(crate) fn get_type_param( - &self, - definition: &clang::Cursor, - ) -> Option { + pub(crate) fn get_type_param(&self, definition: &Cursor) -> Option { assert_eq!( definition.kind(), clang_sys::CXCursor_TemplateTypeParameter @@ -923,7 +916,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// Gather all the unresolved type references. fn collect_typerefs( &mut self, - ) -> Vec<(ItemId, clang::Type, clang::Cursor, Option)> { + ) -> Vec<(ItemId, clang::Type, Cursor, Option)> { debug_assert!(!self.collected_typerefs); self.collected_typerefs = true; let mut typerefs = vec![]; @@ -1517,7 +1510,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// not sure it's worth it. pub(crate) fn add_semantic_parent( &mut self, - definition: clang::Cursor, + definition: Cursor, parent_id: ItemId, ) { self.semantic_parents.insert(definition, parent_id); @@ -1526,7 +1519,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// Returns a known semantic parent for a given definition. pub(crate) fn known_semantic_parent( &self, - definition: clang::Cursor, + definition: Cursor, ) -> Option { self.semantic_parents.get(&definition).copied() } @@ -1631,7 +1624,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" with_id: ItemId, template: TypeId, ty: &clang::Type, - location: clang::Cursor, + location: Cursor, ) -> Option { let num_expected_args = self.resolve_type(template).num_self_template_params(self); @@ -1856,7 +1849,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" with_id: ItemId, parent_id: Option, ty: &clang::Type, - location: Option, + location: Option, ) -> Option { use clang_sys::{CXCursor_TypeAliasTemplateDecl, CXCursor_TypeRef}; debug!("builtin_or_resolved_ty: {ty:?}, {location:?}, {with_id:?}, {parent_id:?}"); @@ -2227,7 +2220,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// namespace. fn tokenize_namespace( &self, - cursor: &clang::Cursor, + cursor: &Cursor, ) -> (Option, ModuleKind) { assert_eq!( cursor.kind(), @@ -2306,7 +2299,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// Given a CXCursor_Namespace cursor, return the item ID of the /// corresponding module, or create one on the fly. - pub(crate) fn module(&mut self, cursor: clang::Cursor) -> ModuleId { + pub(crate) fn module(&mut self, cursor: Cursor) -> ModuleId { use clang_sys::*; assert_eq!(cursor.kind(), CXCursor_Namespace, "Be a nice person"); let cursor = cursor.canonical(); diff --git a/bindgen/ir/dot.rs b/bindgen/ir/dot.rs index 9b81b8749c..0ccee42c0d 100644 --- a/bindgen/ir/dot.rs +++ b/bindgen/ir/dot.rs @@ -17,7 +17,7 @@ pub(crate) trait DotAttributes { out: &mut W, ) -> io::Result<()> where - W: io::Write; + W: Write; } /// Write a graphviz dot file containing our IR. diff --git a/bindgen/ir/item.rs b/bindgen/ir/item.rs index ee0fdc525b..1157149529 100644 --- a/bindgen/ir/item.rs +++ b/bindgen/ir/item.rs @@ -1563,8 +1563,8 @@ impl Item { \tlocation = {location:?}", ); - if ty.kind() == clang_sys::CXType_Unexposed || - location.cur_type().kind() == clang_sys::CXType_Unexposed + if ty.kind() == CXType_Unexposed || + location.cur_type().kind() == CXType_Unexposed { if ty.is_associated_type() || location.cur_type().is_associated_type() diff --git a/bindgen/ir/layout.rs b/bindgen/ir/layout.rs index fc248e1dfa..905e47c732 100644 --- a/bindgen/ir/layout.rs +++ b/bindgen/ir/layout.rs @@ -19,9 +19,8 @@ pub(crate) struct Layout { #[test] fn test_layout_for_size() { - use std::mem; - - let ptr_size = mem::size_of::<*mut ()>(); + use std::mem::size_of; + let ptr_size = size_of::<*mut ()>(); assert_eq!( Layout::for_size_internal(ptr_size, ptr_size), Layout::new(ptr_size, ptr_size) diff --git a/bindgen/ir/ty.rs b/bindgen/ir/ty.rs index fc3bfa6088..5aea619808 100644 --- a/bindgen/ir/ty.rs +++ b/bindgen/ir/ty.rs @@ -637,12 +637,7 @@ pub(crate) enum TypeKind { /// already known types, and are converted to ResolvedTypeRef. /// /// see tests/headers/typeref.hpp to see somewhere where this is a problem. - UnresolvedTypeRef( - clang::Type, - clang::Cursor, - /* parent_id */ - Option, - ), + UnresolvedTypeRef(clang::Type, Cursor, /* parent_id */ Option), /// An indirection to another type. /// diff --git a/bindgen/ir/var.rs b/bindgen/ir/var.rs index 2aa92f84bd..8f9aa4441c 100644 --- a/bindgen/ir/var.rs +++ b/bindgen/ir/var.rs @@ -477,7 +477,7 @@ fn get_integer_literal_from_cursor(cursor: &clang::Cursor) -> Option { fn duplicated_macro_diagnostic( macro_name: &str, - _location: crate::clang::SourceLocation, + _location: clang::SourceLocation, _ctx: &BindgenContext, ) { warn!("Duplicated macro definition: {macro_name}"); diff --git a/bindgen/lib.rs b/bindgen/lib.rs index e599f759c7..5bc325ed0d 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -70,6 +70,7 @@ use std::env; use std::ffi::OsStr; use std::fs::{File, OpenOptions}; use std::io::{self, Write}; +use std::mem::size_of; use std::path::{Path, PathBuf}; use std::process::{Command, Stdio}; use std::rc::Rc; @@ -888,7 +889,7 @@ impl Bindings { if is_host_build { debug_assert_eq!( context.target_pointer_size(), - std::mem::size_of::<*mut ()>(), + size_of::<*mut ()>(), "{effective_target:?} {HOST_TARGET:?}" ); } @@ -1184,11 +1185,11 @@ pub fn clang_version() -> ClangVersion { fn env_var + AsRef>( parse_callbacks: &[Rc], key: K, -) -> Result { +) -> Result { for callback in parse_callbacks { callback.read_env_var(key.as_ref()); } - std::env::var(key) + env::var(key) } /// Looks for the env var `var_${TARGET}`, and falls back to just `var` when it is not found. @@ -1281,7 +1282,7 @@ impl callbacks::ParseCallbacks for CargoCallbacks { #[test] fn commandline_flag_unit_test_function() { //Test 1 - let bindings = crate::builder(); + let bindings = builder(); let command_line_flags = bindings.command_line_flags(); let test_cases = [ @@ -1297,7 +1298,7 @@ fn commandline_flag_unit_test_function() { assert!(test_cases.iter().all(|x| command_line_flags.contains(x))); //Test 2 - let bindings = crate::builder() + let bindings = builder() .header("input_header") .allowlist_type("Distinct_Type") .allowlist_function("safe_function"); diff --git a/bindgen/options/cli.rs b/bindgen/options/cli.rs index 834c7c7625..0bfb290d35 100644 --- a/bindgen/options/cli.rs +++ b/bindgen/options/cli.rs @@ -1,3 +1,5 @@ +#![allow(unused_qualifications)] // Clap somehow generates a lot of these + use crate::{ builder, callbacks::{ @@ -810,7 +812,7 @@ where shell, &mut BindgenCommand::command(), "bindgen", - &mut std::io::stdout(), + &mut io::stdout(), ); exit(0) From 3c1a6191c476f12c77671cef0231bbb9167f724f Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Sun, 1 Dec 2024 01:45:20 -0500 Subject: [PATCH 791/942] Fix `cast_lossless` lint ``` cargo clippy --fix --workspace --exclude bindgen-integration --exclude tests_expectations -- -W clippy::cast_lossless ``` --- bindgen/clang.rs | 2 +- bindgen/codegen/mod.rs | 2 +- bindgen/ir/var.rs | 17 +++++++++-------- bindgen/time.rs | 2 +- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/bindgen/clang.rs b/bindgen/clang.rs index 327ec137b0..037d526b1f 100644 --- a/bindgen/clang.rs +++ b/bindgen/clang.rs @@ -1791,7 +1791,7 @@ impl Index { pub(crate) fn new(pch: bool, diag: bool) -> Index { unsafe { Index { - x: clang_createIndex(pch as c_int, diag as c_int), + x: clang_createIndex(c_int::from(pch), c_int::from(diag)), } } } diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index f60a75d23a..035cc9386f 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -3329,7 +3329,7 @@ impl<'a> EnumBuilder<'a> { let is_rust_enum = self.is_rust_enum(); let expr = match variant.val() { EnumVariantValue::Boolean(v) if is_rust_enum => { - helpers::ast_ty::uint_expr(v as u64) + helpers::ast_ty::uint_expr(u64::from(v)) } EnumVariantValue::Boolean(v) => quote!(#v), EnumVariantValue::Signed(v) => helpers::ast_ty::int_expr(v), diff --git a/bindgen/ir/var.rs b/bindgen/ir/var.rs index 8f9aa4441c..b84950aad6 100644 --- a/bindgen/ir/var.rs +++ b/bindgen/ir/var.rs @@ -125,23 +125,24 @@ fn default_macro_constant_type(ctx: &BindgenContext, value: i64) -> IntKind { ctx.options().default_macro_constant_type == MacroTypeVariation::Signed { - if value < i32::MIN as i64 || value > i32::MAX as i64 { + if value < i64::from(i32::MIN) || value > i64::from(i32::MAX) { IntKind::I64 } else if !ctx.options().fit_macro_constants || - value < i16::MIN as i64 || - value > i16::MAX as i64 + value < i64::from(i16::MIN) || + value > i64::from(i16::MAX) { IntKind::I32 - } else if value < i8::MIN as i64 || value > i8::MAX as i64 { + } else if value < i64::from(i8::MIN) || value > i64::from(i8::MAX) { IntKind::I16 } else { IntKind::I8 } - } else if value > u32::MAX as i64 { + } else if value > i64::from(u32::MAX) { IntKind::U64 - } else if !ctx.options().fit_macro_constants || value > u16::MAX as i64 { + } else if !ctx.options().fit_macro_constants || value > i64::from(u16::MAX) + { IntKind::U32 - } else if value > u8::MAX as i64 { + } else if value > i64::from(u8::MAX) { IntKind::U16 } else { IntKind::U8 @@ -235,7 +236,7 @@ impl ClangSubItemParser for Var { c as u8 } CChar::Raw(c) => { - assert!(c <= u8::MAX as u64); + assert!(c <= u64::from(u8::MAX)); c as u8 } }; diff --git a/bindgen/time.rs b/bindgen/time.rs index 435890c42c..a220de7d9f 100644 --- a/bindgen/time.rs +++ b/bindgen/time.rs @@ -36,7 +36,7 @@ impl<'a> Timer<'a> { if self.output { let elapsed = self.elapsed(); let time = (elapsed.as_secs() as f64) * 1e3 + - (elapsed.subsec_nanos() as f64) / 1e6; + f64::from(elapsed.subsec_nanos()) / 1e6; let stderr = io::stderr(); // Arbitrary output format, subject to change. writeln!(stderr.lock(), " time: {time:>9.3} ms.\t{}", self.name) From 09f32b336eeb4a2b6b072415ba91ec2217f878c9 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Sun, 1 Dec 2024 01:59:14 -0500 Subject: [PATCH 792/942] Fix `map_unwrap_or` lint ``` cargo clippy --workspace --exclude bindgen-integration --exclude tests_expectations -- -W clippy::map_unwrap_or ``` --- bindgen/clang.rs | 6 ++---- bindgen/codegen/mod.rs | 12 ++++-------- bindgen/codegen/serialize.rs | 3 +-- bindgen/ir/item.rs | 21 +++++++++------------ bindgen/options/cli.rs | 4 ++-- 5 files changed, 18 insertions(+), 28 deletions(-) diff --git a/bindgen/clang.rs b/bindgen/clang.rs index 037d526b1f..46596e2a0b 100644 --- a/bindgen/clang.rs +++ b/bindgen/clang.rs @@ -1110,10 +1110,8 @@ impl Iterator for ClangTokenIterator<'_> { /// (including '_') and does not start with a digit. pub(crate) fn is_valid_identifier(name: &str) -> bool { let mut chars = name.chars(); - let first_valid = chars - .next() - .map(|c| c.is_alphabetic() || c == '_') - .unwrap_or(false); + let first_valid = + chars.next().is_some_and(|c| c.is_alphabetic() || c == '_'); first_valid && chars.all(|c| c.is_alphanumeric() || c == '_') } diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 035cc9386f..38dcfed156 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -5145,14 +5145,10 @@ pub(crate) mod utils { return Ok(()); } - let path = context - .options() - .wrap_static_fns_path - .as_ref() - .map(PathBuf::from) - .unwrap_or_else(|| { - std::env::temp_dir().join("bindgen").join("extern") - }); + let path = context.options().wrap_static_fns_path.as_ref().map_or_else( + || std::env::temp_dir().join("bindgen").join("extern"), + PathBuf::from, + ); let dir = path.parent().unwrap(); diff --git a/bindgen/codegen/serialize.rs b/bindgen/codegen/serialize.rs index 864d86b452..9a2176c4b0 100644 --- a/bindgen/codegen/serialize.rs +++ b/bindgen/codegen/serialize.rs @@ -14,8 +14,7 @@ use super::{CodegenError, WrapAsVariadic}; fn get_loc(item: &Item) -> String { item.location() - .map(|x| x.to_string()) - .unwrap_or_else(|| "unknown".to_owned()) + .map_or_else(|| "unknown".to_owned(), |x| x.to_string()) } pub(super) trait CSerialize<'a> { diff --git a/bindgen/ir/item.rs b/bindgen/ir/item.rs index 1157149529..b79e99065f 100644 --- a/bindgen/ir/item.rs +++ b/bindgen/ir/item.rs @@ -786,16 +786,14 @@ impl Item { match *self.kind() { ItemKind::Var(ref var) => var.name().to_owned(), - ItemKind::Module(ref module) => { - module.name().map(ToOwned::to_owned).unwrap_or_else(|| { - format!("_bindgen_mod_{}", self.exposed_id(ctx)) - }) - } - ItemKind::Type(ref ty) => { - ty.sanitized_name(ctx).map(Into::into).unwrap_or_else(|| { - format!("_bindgen_ty_{}", self.exposed_id(ctx)) - }) - } + ItemKind::Module(ref module) => module.name().map_or_else( + || format!("_bindgen_mod_{}", self.exposed_id(ctx)), + ToOwned::to_owned, + ), + ItemKind::Type(ref ty) => ty.sanitized_name(ctx).map_or_else( + || format!("_bindgen_ty_{}", self.exposed_id(ctx)), + Into::into, + ), ItemKind::Function(ref fun) => { let mut name = fun.name().to_owned(); @@ -1702,8 +1700,7 @@ impl Item { ty.spelling() ); Item::type_param(Some(id), location, ctx) - .map(Ok) - .unwrap_or(Err(ParseError::Recurse)) + .ok_or(ParseError::Recurse) } else { result } diff --git a/bindgen/options/cli.rs b/bindgen/options/cli.rs index 0bfb290d35..29b4413b1b 100644 --- a/bindgen/options/cli.rs +++ b/bindgen/options/cli.rs @@ -705,7 +705,7 @@ where } fn add_derives(&self, info: &DeriveInfo<'_>) -> Vec { - if self.kind.map(|kind| kind == info.kind).unwrap_or(true) && + if self.kind.map_or(true, |kind| kind == info.kind) && self.regex_set.matches(info.name) { return self.derives.clone(); @@ -745,7 +745,7 @@ where } fn add_attributes(&self, info: &AttributeInfo<'_>) -> Vec { - if self.kind.map(|kind| kind == info.kind).unwrap_or(true) && + if self.kind.map_or(true, |kind| kind == info.kind) && self.regex_set.matches(info.name) { return self.attributes.clone(); From 4eb99c7ba876b35a67e935776ac7b66dfbd64b67 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Sun, 1 Dec 2024 01:51:36 -0500 Subject: [PATCH 793/942] Fix `if_not_else` lint Using negations in the `if` makes them a bit harder to read... and there is a lint for that :) ``` cargo clippy --workspace --exclude bindgen-integration --exclude tests_expectations -- -W clippy::if_not_else ``` --- bindgen/clang.rs | 12 ++++++------ bindgen/codegen/mod.rs | 12 ++++++------ bindgen/ir/analysis/derive.rs | 2 +- bindgen/ir/analysis/mod.rs | 6 +++--- bindgen/ir/analysis/template_params.rs | 6 +++--- bindgen/ir/annotations.rs | 6 +++--- bindgen/lib.rs | 6 +++--- 7 files changed, 25 insertions(+), 25 deletions(-) diff --git a/bindgen/clang.rs b/bindgen/clang.rs index 46596e2a0b..4554a56241 100644 --- a/bindgen/clang.rs +++ b/bindgen/clang.rs @@ -216,10 +216,10 @@ impl Cursor { }) .or_else(|| { let canonical = self.canonical(); - if canonical != *self { - canonical.num_template_args() - } else { + if canonical == *self { None + } else { + canonical.num_template_args() } }) } @@ -1443,10 +1443,10 @@ impl Type { /// elements. pub(crate) fn num_elements(&self) -> Option { let num_elements_returned = unsafe { clang_getNumElements(self.x) }; - if num_elements_returned != -1 { - Some(num_elements_returned as usize) - } else { + if num_elements_returned == -1 { None + } else { + Some(num_elements_returned as usize) } } diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 38dcfed156..f215371376 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -2777,13 +2777,13 @@ impl CodeGenerator for CompInfo { item, &ty_for_impl, ) { - let partialeq_bounds = if !generic_param_names.is_empty() { + let partialeq_bounds = if generic_param_names.is_empty() { + quote! {} + } else { let bounds = generic_param_names.iter().map(|t| { quote! { #t: PartialEq } }); quote! { where #( #bounds ),* } - } else { - quote! {} }; let prefix = ctx.trait_prefix(); @@ -3444,10 +3444,10 @@ impl<'a> EnumBuilder<'a> { emitted_any_variants, .. } => { - let variants = if !emitted_any_variants { - quote!(__bindgen_cannot_repr_c_on_empty_enum = 0) - } else { + let variants = if emitted_any_variants { tokens + } else { + quote!(__bindgen_cannot_repr_c_on_empty_enum = 0) }; quote! { diff --git a/bindgen/ir/analysis/derive.rs b/bindgen/ir/analysis/derive.rs index ef063e188d..eb2874ee6e 100644 --- a/bindgen/ir/analysis/derive.rs +++ b/bindgen/ir/analysis/derive.rs @@ -722,6 +722,6 @@ pub(crate) fn as_cannot_derive_set( ) -> HashSet { can_derive .into_iter() - .filter_map(|(k, v)| if v != CanDerive::Yes { Some(k) } else { None }) + .filter_map(|(k, v)| if v == CanDerive::Yes { None } else { Some(k) }) .collect() } diff --git a/bindgen/ir/analysis/mod.rs b/bindgen/ir/analysis/mod.rs index 731080cb4e..be49386308 100644 --- a/bindgen/ir/analysis/mod.rs +++ b/bindgen/ir/analysis/mod.rs @@ -343,10 +343,10 @@ mod tests { } let new_size = self.reachable[&node].len(); - if original_size != new_size { - ConstrainResult::Changed - } else { + if original_size == new_size { ConstrainResult::Same + } else { + ConstrainResult::Changed } } diff --git a/bindgen/ir/analysis/template_params.rs b/bindgen/ir/analysis/template_params.rs index 778a515d4c..c64878c10e 100644 --- a/bindgen/ir/analysis/template_params.rs +++ b/bindgen/ir/analysis/template_params.rs @@ -570,10 +570,10 @@ impl<'ctx> MonotoneFramework for UsedTemplateParameters<'ctx> { self.used.insert(id, Some(used_by_this_id)); extra_assert!(self.used.values().all(|v| v.is_some())); - if new_len != original_len { - ConstrainResult::Changed - } else { + if new_len == original_len { ConstrainResult::Same + } else { + ConstrainResult::Changed } } diff --git a/bindgen/ir/annotations.rs b/bindgen/ir/annotations.rs index 600bfa8b64..7f5d74b3ee 100644 --- a/bindgen/ir/annotations.rs +++ b/bindgen/ir/annotations.rs @@ -232,10 +232,10 @@ impl Annotations { "derive" => self.derives.push(attr.value), "attribute" => self.attributes.push(attr.value), "private" => { - self.visibility_kind = if attr.value != "false" { - Some(FieldVisibilityKind::Private) - } else { + self.visibility_kind = if attr.value == "false" { Some(FieldVisibilityKind::Public) + } else { + Some(FieldVisibilityKind::Private) }; } "accessor" => { diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 5bc325ed0d..b97459beab 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -1124,10 +1124,10 @@ fn parse(context: &mut BindgenContext) -> Result<(), BindgenError> { if context.options().emit_ast { fn dump_if_not_builtin(cur: &clang::Cursor) -> CXChildVisitResult { - if !cur.is_builtin() { - clang::ast_dump(cur, 0) - } else { + if cur.is_builtin() { CXChildVisit_Continue + } else { + clang::ast_dump(cur, 0) } } cursor.visit(|cur| dump_if_not_builtin(&cur)); From 8f21aa6a976dba4bf8378d1574209e41cb5cf610 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Sun, 1 Dec 2024 01:42:00 -0500 Subject: [PATCH 794/942] Fix `explicit_iter_loop` lint ``` cargo clippy --fix --workspace --exclude bindgen-integration --exclude tests_expectations -- -W clippy::explicit_iter_loop ``` --- bindgen/codegen/impl_partialeq.rs | 2 +- bindgen/codegen/mod.rs | 6 +++--- bindgen/ir/analysis/mod.rs | 8 ++++---- bindgen/ir/analysis/template_params.rs | 2 +- bindgen/ir/comp.rs | 6 +++--- bindgen/ir/context.rs | 2 +- bindgen/ir/objc.rs | 2 +- bindgen/lib.rs | 4 ++-- bindgen/options/mod.rs | 2 +- bindgen/regex_set.rs | 2 +- 10 files changed, 18 insertions(+), 18 deletions(-) diff --git a/bindgen/codegen/impl_partialeq.rs b/bindgen/codegen/impl_partialeq.rs index 42fabf6ad0..6c7b43959b 100644 --- a/bindgen/codegen/impl_partialeq.rs +++ b/bindgen/codegen/impl_partialeq.rs @@ -23,7 +23,7 @@ pub(crate) fn gen_partialeq_impl( &self.bindgen_union_field[..] == &other.bindgen_union_field[..] }); } else { - for base in comp_info.base_members().iter() { + for base in comp_info.base_members() { if !base.requires_storage(ctx) { continue; } diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index f215371376..b775460c11 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -3653,7 +3653,7 @@ impl CodeGenerator for Enum { DerivableTraits::EQ, ); let mut derives: Vec<_> = derives.into(); - for derive in item.annotations().derives().iter() { + for derive in item.annotations().derives() { if !derives.contains(&derive.as_str()) { derives.push(derive); } @@ -4944,7 +4944,7 @@ impl CodeGenerator for ObjCInterface { }; result.push(struct_block); let mut protocol_set: HashSet = Default::default(); - for protocol_id in self.conforms_to.iter() { + for protocol_id in &self.conforms_to { protocol_set.insert(*protocol_id); let protocol_name = ctx.rust_ident( ctx.resolve_type(protocol_id.expect_type_id(ctx)) @@ -4989,7 +4989,7 @@ impl CodeGenerator for ObjCInterface { } }; result.push(impl_trait); - for protocol_id in parent.conforms_to.iter() { + for protocol_id in &parent.conforms_to { if protocol_set.insert(*protocol_id) { let protocol_name = ctx.rust_ident( ctx.resolve_type(protocol_id.expect_type_id(ctx)) diff --git a/bindgen/ir/analysis/mod.rs b/bindgen/ir/analysis/mod.rs index be49386308..74a305edfb 100644 --- a/bindgen/ir/analysis/mod.rs +++ b/bindgen/ir/analysis/mod.rs @@ -280,9 +280,9 @@ mod tests { fn reverse(&self) -> Graph { let mut reversed = Graph::default(); - for (node, edges) in self.0.iter() { + for (node, edges) in &self.0 { reversed.0.entry(*node).or_insert_with(Vec::new); - for referent in edges.iter() { + for referent in edges { reversed .0 .entry(*referent) @@ -331,7 +331,7 @@ mod tests { let original_size = self.reachable.entry(node).or_default().len(); - for sub_node in self.graph.0[&node].iter() { + for sub_node in &self.graph.0[&node] { self.reachable.get_mut(&node).unwrap().insert(*sub_node); let sub_reachable = @@ -354,7 +354,7 @@ mod tests { where F: FnMut(Node), { - for dep in self.reversed.0[&node].iter() { + for dep in &self.reversed.0[&node] { f(*dep); } } diff --git a/bindgen/ir/analysis/template_params.rs b/bindgen/ir/analysis/template_params.rs index c64878c10e..df8f861cfe 100644 --- a/bindgen/ir/analysis/template_params.rs +++ b/bindgen/ir/analysis/template_params.rs @@ -464,7 +464,7 @@ impl<'ctx> MonotoneFramework for UsedTemplateParameters<'ctx> { // (This is so that every item we call `constrain` on is guaranteed // to have a set of template parameters, and we can allow // blocklisted templates to use all of their parameters). - for item in allowlisted_items.iter() { + for item in &allowlisted_items { extra_assert!(used.contains_key(item)); extra_assert!(dependencies.contains_key(item)); item.trace( diff --git a/bindgen/ir/comp.rs b/bindgen/ir/comp.rs index 093d553ad0..a978af581f 100644 --- a/bindgen/ir/comp.rs +++ b/bindgen/ir/comp.rs @@ -1162,14 +1162,14 @@ impl CompInfo { match self.fields { CompFields::Error => {} CompFields::After { ref fields, .. } => { - for field in fields.iter() { + for field in fields { if let Some(layout) = field.layout(ctx) { callback(layout); } } } CompFields::Before(ref raw_fields) => { - for field in raw_fields.iter() { + for field in raw_fields { let field_ty = ctx.resolve_type(field.0.ty); if let Some(layout) = field_ty.layout(ctx) { callback(layout); @@ -1672,7 +1672,7 @@ impl CompInfo { pub(crate) fn already_packed(&self, ctx: &BindgenContext) -> Option { let mut total_size: usize = 0; - for field in self.fields().iter() { + for field in self.fields() { let layout = field.layout(ctx)?; if layout.align != 0 && total_size % layout.align != 0 { diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index 6cdf8b4af8..ae1acb925d 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -2055,7 +2055,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" let mut header_names_to_compile = Vec::new(); let mut header_paths = Vec::new(); let mut header_contents = String::new(); - for input_header in self.options.input_headers.iter() { + for input_header in &self.options.input_headers { let path = Path::new(input_header.as_ref()); if let Some(header_path) = path.parent() { if header_path == Path::new("") { diff --git a/bindgen/ir/objc.rs b/bindgen/ir/objc.rs index 6d83095924..81560da4d1 100644 --- a/bindgen/ir/objc.rs +++ b/bindgen/ir/objc.rs @@ -301,7 +301,7 @@ impl ObjCMethod { // Get arguments without type signatures to pass to `msg_send!` let mut args_without_types = vec![]; - for arg in args.iter() { + for arg in args { let arg = arg.to_string(); let name_and_sig: Vec<&str> = arg.split(' ').collect(); let name = name_and_sig[0]; diff --git a/bindgen/lib.rs b/bindgen/lib.rs index b97459beab..58e1da8665 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -929,7 +929,7 @@ impl Bindings { )?; } - for line in self.options.raw_lines.iter() { + for line in &self.options.raw_lines { writer.write_all(line.as_bytes())?; writer.write_all(NL.as_bytes())?; } @@ -1104,7 +1104,7 @@ fn parse(context: &mut BindgenContext) -> Result<(), BindgenError> { use clang_sys::*; let mut error = None; - for d in context.translation_unit().diags().iter() { + for d in &context.translation_unit().diags() { let msg = d.format(); let is_err = d.severity() >= CXDiagnostic_Error; if is_err { diff --git a/bindgen/options/mod.rs b/bindgen/options/mod.rs index 4e68dfb7cd..6bf652d4e1 100644 --- a/bindgen/options/mod.rs +++ b/bindgen/options/mod.rs @@ -1143,7 +1143,7 @@ options! { }, as_args: |module_lines, args| { for (module, lines) in module_lines { - for line in lines.iter() { + for line in lines { args.push("--module-raw-line".to_owned()); args.push(module.clone().into()); args.push(line.clone().into()); diff --git a/bindgen/regex_set.rs b/bindgen/regex_set.rs index be0041dcfa..17e9708385 100644 --- a/bindgen/regex_set.rs +++ b/bindgen/regex_set.rs @@ -128,7 +128,7 @@ impl RegexSet { if !matches.matched_any() { return false; } - for i in matches.iter() { + for i in &matches { self.matched[i].set(true); } From 0c3ae5c2cc0a25d9c61adc9a5f8a3592a942e22e Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Sun, 1 Dec 2024 01:21:09 -0500 Subject: [PATCH 795/942] Fix `manual_let_else` and `single_match_else` lint Used this to find issues, apply suggestions, and manually fixed a clippy bug ```bash cargo clippy --all-targets --workspace --exclude bindgen-integration --exclude tests_expectations -- -W clippy::manual_let_else -W clippy::single_match_else ``` --- bindgen-tests/build.rs | 5 +- bindgen-tests/tests/tests.rs | 52 ++++++------- bindgen/clang.rs | 4 +- bindgen/codegen/helpers.rs | 59 ++++++-------- bindgen/codegen/impl_debug.rs | 7 +- bindgen/codegen/mod.rs | 76 ++++++++----------- bindgen/codegen/serialize.rs | 7 +- bindgen/codegen/struct_layout.rs | 5 +- bindgen/features.rs | 31 ++++---- bindgen/ir/analysis/derive.rs | 36 ++++----- bindgen/ir/analysis/has_float.rs | 9 +-- .../ir/analysis/has_type_param_in_array.rs | 28 +++---- bindgen/ir/context.rs | 15 ++-- bindgen/ir/item.rs | 15 ++-- bindgen/ir/template.rs | 15 ++-- bindgen/ir/ty.rs | 39 ++++------ bindgen/ir/var.rs | 11 ++- bindgen/regex_set.rs | 5 +- 18 files changed, 177 insertions(+), 242 deletions(-) diff --git a/bindgen-tests/build.rs b/bindgen-tests/build.rs index 713dbb3c57..d98e823919 100644 --- a/bindgen-tests/build.rs +++ b/bindgen-tests/build.rs @@ -12,10 +12,9 @@ pub fn main() { let manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()); let headers_dir = manifest_dir.join("tests").join("headers"); - let headers = match fs::read_dir(headers_dir) { - Ok(dir) => dir, + let Ok(headers) = fs::read_dir(headers_dir) else { // We may not have headers directory after packaging. - Err(..) => return, + return; }; let entries = diff --git a/bindgen-tests/tests/tests.rs b/bindgen-tests/tests/tests.rs index abb5f96953..0b3ebe1533 100644 --- a/bindgen-tests/tests/tests.rs +++ b/bindgen-tests/tests/tests.rs @@ -55,9 +55,10 @@ fn error_diff_mismatch( if let Some(var) = env::var_os("BINDGEN_TESTS_DIFFTOOL") { //usecase: var = "meld" -> You can hand check differences - let name = match filename.components().last() { - Some(std::path::Component::Normal(name)) => name, - _ => panic!("Why is the header variable so weird?"), + let Some(std::path::Component::Normal(name)) = + filename.components().last() + else { + panic!("Why is the header variable so weird?") }; let actual_result_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join(name); @@ -581,29 +582,28 @@ fn test_macro_fallback_non_system_dir() { let actual = format_code(actual).unwrap(); - let (expected_filename, expected) = match clang_version().parsed { - Some((9, _)) => { - let expected_filename = concat!( - env!("CARGO_MANIFEST_DIR"), - "/tests/expectations/tests/libclang-9/macro_fallback_non_system_dir.rs", - ); - let expected = include_str!(concat!( - env!("CARGO_MANIFEST_DIR"), - "/tests/expectations/tests/libclang-9/macro_fallback_non_system_dir.rs", - )); - (expected_filename, expected) - } - _ => { - let expected_filename = concat!( - env!("CARGO_MANIFEST_DIR"), - "/tests/expectations/tests/test_macro_fallback_non_system_dir.rs", - ); - let expected = include_str!(concat!( - env!("CARGO_MANIFEST_DIR"), - "/tests/expectations/tests/test_macro_fallback_non_system_dir.rs", - )); - (expected_filename, expected) - } + let (expected_filename, expected) = if let Some((9, _)) = + clang_version().parsed + { + let expected_filename = concat!( + env!("CARGO_MANIFEST_DIR"), + "/tests/expectations/tests/libclang-9/macro_fallback_non_system_dir.rs", + ); + let expected = include_str!(concat!( + env!("CARGO_MANIFEST_DIR"), + "/tests/expectations/tests/libclang-9/macro_fallback_non_system_dir.rs", + )); + (expected_filename, expected) + } else { + let expected_filename = concat!( + env!("CARGO_MANIFEST_DIR"), + "/tests/expectations/tests/test_macro_fallback_non_system_dir.rs", + ); + let expected = include_str!(concat!( + env!("CARGO_MANIFEST_DIR"), + "/tests/expectations/tests/test_macro_fallback_non_system_dir.rs", + )); + (expected_filename, expected) }; let expected = format_code(expected).unwrap(); if expected != actual { diff --git a/bindgen/clang.rs b/bindgen/clang.rs index 4554a56241..7a21aa9f4e 100644 --- a/bindgen/clang.rs +++ b/bindgen/clang.rs @@ -1882,9 +1882,7 @@ impl TranslationUnit { /// Save a translation unit to the given file. pub(crate) fn save(&mut self, file: &str) -> Result<(), CXSaveError> { - let file = if let Ok(cstring) = CString::new(file) { - cstring - } else { + let Ok(file) = CString::new(file) else { return Err(CXSaveError_Unknown); }; let ret = unsafe { diff --git a/bindgen/codegen/helpers.rs b/bindgen/codegen/helpers.rs index abefeba347..aac04a12cb 100644 --- a/bindgen/codegen/helpers.rs +++ b/bindgen/codegen/helpers.rs @@ -84,13 +84,10 @@ pub(crate) fn blob(layout: Layout) -> syn::Type { // some things that legitimately are more than 8-byte aligned. // // Eventually we should be able to `unwrap` here, but... - let ty = match opaque.known_rust_type_for_array() { - Some(ty) => ty, - None => { - warn!("Found unknown alignment on code generation!"); - syn::parse_quote! { u8 } - } - }; + let ty = opaque.known_rust_type_for_array().unwrap_or_else(|| { + warn!("Found unknown alignment on code generation!"); + syn::parse_quote! { u8 } + }); let data_len = opaque.array_size().unwrap_or(layout.size); @@ -245,24 +242,21 @@ pub(crate) mod ast_ty { (FloatKind::Float, false) => raw_type(ctx, "c_float"), (FloatKind::Double, false) => raw_type(ctx, "c_double"), (FloatKind::LongDouble, _) => { - match layout { - Some(layout) => { - match layout.size { - 4 => syn::parse_quote! { f32 }, - 8 => syn::parse_quote! { f64 }, - // TODO(emilio): If rust ever gains f128 we should - // use it here and below. - _ => super::integer_type(layout) - .unwrap_or(syn::parse_quote! { f64 }), - } - } - None => { - debug_assert!( - false, - "How didn't we know the layout for a primitive type?" - ); - syn::parse_quote! { f64 } + if let Some(layout) = layout { + match layout.size { + 4 => syn::parse_quote! { f32 }, + 8 => syn::parse_quote! { f64 }, + // TODO(emilio): If rust ever gains f128 we should + // use it here and below. + _ => super::integer_type(layout) + .unwrap_or(syn::parse_quote! { f64 }), } + } else { + debug_assert!( + false, + "How didn't we know the layout for a primitive type?" + ); + syn::parse_quote! { f64 } } } (FloatKind::Float128, _) => { @@ -365,17 +359,14 @@ pub(crate) mod ast_ty { signature .argument_types() .iter() - .map(|&(ref name, _ty)| match *name { - Some(ref name) => { - let name = ctx.rust_ident(name); - quote! { #name } - } - None => { + .map(|&(ref name, _ty)| { + let name = if let Some(ref name) = *name { + ctx.rust_ident(name) + } else { unnamed_arguments += 1; - let name = - ctx.rust_ident(format!("arg{unnamed_arguments}")); - quote! { #name } - } + ctx.rust_ident(format!("arg{unnamed_arguments}")) + }; + quote! { #name } }) .collect() } diff --git a/bindgen/codegen/impl_debug.rs b/bindgen/codegen/impl_debug.rs index b0e73b6137..c4daddf260 100644 --- a/bindgen/codegen/impl_debug.rs +++ b/bindgen/codegen/impl_debug.rs @@ -126,12 +126,7 @@ impl<'a> ImplDebug<'a> for Item { return None; } - let ty = match self.as_type() { - Some(ty) => ty, - None => { - return None; - } - }; + let ty = self.as_type()?; fn debug_print( name: &str, diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index b775460c11..82dd8b7199 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -1198,10 +1198,7 @@ impl CodeGenerator for Vtable<'_> { let function_item = ctx.resolve_item(m.signature()); let function = function_item.expect_function(); let signature_item = ctx.resolve_item(function.signature()); - let signature = match signature_item.expect_type().kind() { - TypeKind::Function(ref sig) => sig, - _ => panic!("Function signature type mismatch"), - }; + let TypeKind::Function(ref signature) = signature_item.expect_type().kind() else { panic!("Function signature type mismatch") }; // FIXME: Is there a canonical name without the class prepended? let function_name = function_item.canonical_name(ctx); @@ -1943,16 +1940,14 @@ impl<'a> FieldCodegen<'a> for Bitfield { let bitfield_ty_layout = bitfield_ty .layout(ctx) .expect("Bitfield without layout? Gah!"); - let bitfield_int_ty = match helpers::integer_type(bitfield_ty_layout) { - Some(int_ty) => { + let bitfield_int_ty = + if let Some(int_ty) = helpers::integer_type(bitfield_ty_layout) { *bitfield_representable_as_int = true; int_ty - } - None => { + } else { *bitfield_representable_as_int = false; return; - } - }; + }; let bitfield_ty = bitfield_ty.to_rust_ty_or_opaque(ctx, bitfield_ty_item); @@ -2974,10 +2969,7 @@ impl Method { } let function = function_item.expect_function(); let times_seen = function.codegen(ctx, result, function_item); - let times_seen = match times_seen { - Some(seen) => seen, - None => return, - }; + let Some(times_seen) = times_seen else { return }; let signature_item = ctx.resolve_item(function.signature()); let mut name = match self.kind() { MethodKind::Constructor => "new".into(), @@ -2985,9 +2977,10 @@ impl Method { _ => function.name().to_owned(), }; - let signature = match *signature_item.expect_type().kind() { - TypeKind::Function(ref sig) => sig, - _ => panic!("How in the world?"), + let TypeKind::Function(ref signature) = + *signature_item.expect_type().kind() + else { + panic!("How in the world?") }; let supported_abi = signature.abi(ctx, Some(&*name)).is_ok(); @@ -3564,18 +3557,17 @@ impl CodeGenerator for Enum { // * the representation couldn't be determined from the C source // * it was explicitly requested as a bindgen option - let kind = match repr { - Some(repr) => match *repr.canonical_type(ctx).kind() { + let kind = if let Some(repr) = repr { + match *repr.canonical_type(ctx).kind() { TypeKind::Int(int_kind) => int_kind, _ => panic!("Unexpected type as enum repr"), - }, - None => { - warn!( - "Guessing type of enum! Forward declarations of enums \ - shouldn't be legal!" - ); - IntKind::Int } + } else { + warn!( + "Guessing type of enum! Forward declarations of enums \ + shouldn't be legal!" + ); + IntKind::Int }; let signed = kind.is_signed(); @@ -4488,9 +4480,8 @@ impl CodeGenerator for Function { let signature_item = ctx.resolve_item(self.signature()); let signature = signature_item.kind().expect_type().canonical_type(ctx); - let signature = match *signature.kind() { - TypeKind::Function(ref sig) => sig, - _ => panic!("Signature kind is not a Function: {signature:?}"), + let TypeKind::Function(ref signature) = *signature.kind() else { + panic!("Signature kind is not a Function: {signature:?}") }; if is_internal { @@ -4966,9 +4957,8 @@ impl CodeGenerator for ObjCInterface { .expect_type() .kind(); - let parent = match parent { - TypeKind::ObjCInterface(ref parent) => parent, - _ => break, + let TypeKind::ObjCInterface(parent) = parent else { + break; }; parent_class = parent.parent_class; @@ -5683,12 +5673,11 @@ pub(crate) mod utils { .map(|(name, ty)| { let arg_ty = fnsig_argument_type(ctx, ty); - let arg_name = match *name { - Some(ref name) => ctx.rust_mangle(name).into_owned(), - None => { - unnamed_arguments += 1; - format!("arg{unnamed_arguments}") - } + let arg_name = if let Some(ref name) = *name { + ctx.rust_mangle(name).into_owned() + } else { + unnamed_arguments += 1; + format!("arg{unnamed_arguments}") }; assert!(!arg_name.is_empty()); @@ -5727,12 +5716,11 @@ pub(crate) mod utils { .argument_types() .iter() .map(|&(ref name, _ty)| { - let arg_name = match *name { - Some(ref name) => ctx.rust_mangle(name).into_owned(), - None => { - unnamed_arguments += 1; - format!("arg{unnamed_arguments}") - } + let arg_name = if let Some(ref name) = *name { + ctx.rust_mangle(name).into_owned() + } else { + unnamed_arguments += 1; + format!("arg{unnamed_arguments}") }; assert!(!arg_name.is_empty()); diff --git a/bindgen/codegen/serialize.rs b/bindgen/codegen/serialize.rs index 9a2176c4b0..c7bb6cecef 100644 --- a/bindgen/codegen/serialize.rs +++ b/bindgen/codegen/serialize.rs @@ -71,9 +71,10 @@ impl<'a> CSerialize<'a> for Function { }); } - let signature = match ctx.resolve_type(self.signature()).kind() { - TypeKind::Function(signature) => signature, - _ => unreachable!(), + let TypeKind::Function(signature) = + ctx.resolve_type(self.signature()).kind() + else { + unreachable!() }; assert!(!signature.is_variadic()); diff --git a/bindgen/codegen/struct_layout.rs b/bindgen/codegen/struct_layout.rs index 40edefd540..0645d8a84a 100644 --- a/bindgen/codegen/struct_layout.rs +++ b/bindgen/codegen/struct_layout.rs @@ -421,9 +421,8 @@ impl<'a> StructLayoutTracker<'a> { return false; } - let layout = match self.latest_field_layout { - Some(l) => l, - None => return false, + let Some(layout) = self.latest_field_layout else { + return false; }; // If it was, we may or may not need to align, depending on what the diff --git a/bindgen/features.rs b/bindgen/features.rs index af36ffca9b..c278d10fe6 100644 --- a/bindgen/features.rs +++ b/bindgen/features.rs @@ -368,22 +368,21 @@ impl FromStr for RustTarget { )); } - let (minor, patch) = match tail.split_once('.') { - Some((minor_str, patch_str)) => { - let Ok(minor) = minor_str.parse::() else { - return Err(invalid_input(input, "the minor version number must be an unsigned 64-bit integer")); - }; - let Ok(patch) = patch_str.parse::() else { - return Err(invalid_input(input, "the patch version number must be an unsigned 64-bit integer")); - }; - (minor, patch) - } - None => { - let Ok(minor) = tail.parse::() else { - return Err(invalid_input(input, "the minor version number must be an unsigned 64-bit integer")); - }; - (minor, 0) - } + let (minor, patch) = if let Some((minor_str, patch_str)) = + tail.split_once('.') + { + let Ok(minor) = minor_str.parse::() else { + return Err(invalid_input(input, "the minor version number must be an unsigned 64-bit integer")); + }; + let Ok(patch) = patch_str.parse::() else { + return Err(invalid_input(input, "the patch version number must be an unsigned 64-bit integer")); + }; + (minor, patch) + } else { + let Ok(minor) = tail.parse::() else { + return Err(invalid_input(input, "the minor version number must be an unsigned 64-bit integer")); + }; + (minor, 0) }; Self::stable(minor, patch).map_err(|err| invalid_input(input, err)) diff --git a/bindgen/ir/analysis/derive.rs b/bindgen/ir/analysis/derive.rs index eb2874ee6e..1643a91461 100644 --- a/bindgen/ir/analysis/derive.rs +++ b/bindgen/ir/analysis/derive.rs @@ -540,31 +540,25 @@ impl DeriveTrait { } fn can_derive_vector(&self) -> CanDerive { - match self { - DeriveTrait::PartialEqOrPartialOrd => { - // FIXME: vectors always can derive PartialEq, but they should - // not derive PartialOrd: - // https://github.com/rust-lang-nursery/packed_simd/issues/48 - trace!(" vectors cannot derive PartialOrd"); - CanDerive::No - } - _ => { - trace!(" vector can derive {self}"); - CanDerive::Yes - } + if *self == DeriveTrait::PartialEqOrPartialOrd { + // FIXME: vectors always can derive PartialEq, but they should + // not derive PartialOrd: + // https://github.com/rust-lang-nursery/packed_simd/issues/48 + trace!(" vectors cannot derive PartialOrd"); + CanDerive::No + } else { + trace!(" vector can derive {self}"); + CanDerive::Yes } } fn can_derive_pointer(&self) -> CanDerive { - match self { - DeriveTrait::Default => { - trace!(" pointer cannot derive Default"); - CanDerive::No - } - _ => { - trace!(" pointer can derive {self}"); - CanDerive::Yes - } + if *self == DeriveTrait::Default { + trace!(" pointer cannot derive Default"); + CanDerive::No + } else { + trace!(" pointer can derive {self}"); + CanDerive::Yes } } diff --git a/bindgen/ir/analysis/has_float.rs b/bindgen/ir/analysis/has_float.rs index 630458e527..da4b413372 100644 --- a/bindgen/ir/analysis/has_float.rs +++ b/bindgen/ir/analysis/has_float.rs @@ -105,12 +105,9 @@ impl<'ctx> MonotoneFramework for HasFloat<'ctx> { } let item = self.ctx.resolve_item(id); - let ty = match item.as_type() { - Some(ty) => ty, - None => { - trace!(" not a type; ignoring"); - return ConstrainResult::Same; - } + let Some(ty) = item.as_type() else { + trace!(" not a type; ignoring"); + return ConstrainResult::Same; }; match *ty.kind() { diff --git a/bindgen/ir/analysis/has_type_param_in_array.rs b/bindgen/ir/analysis/has_type_param_in_array.rs index 61a8d631d1..466ccb2ae8 100644 --- a/bindgen/ir/analysis/has_type_param_in_array.rs +++ b/bindgen/ir/analysis/has_type_param_in_array.rs @@ -108,12 +108,9 @@ impl<'ctx> MonotoneFramework for HasTypeParameterInArray<'ctx> { } let item = self.ctx.resolve_item(id); - let ty = match item.as_type() { - Some(ty) => ty, - None => { - trace!(" not a type; ignoring"); - return ConstrainResult::Same; - } + let Some(ty) = item.as_type() else { + trace!(" not a type; ignoring"); + return ConstrainResult::Same; }; match *ty.kind() { @@ -142,17 +139,14 @@ impl<'ctx> MonotoneFramework for HasTypeParameterInArray<'ctx> { TypeKind::Array(t, _) => { let inner_ty = self.ctx.resolve_type(t).canonical_type(self.ctx); - match *inner_ty.kind() { - TypeKind::TypeParam => { - trace!(" Array with Named type has type parameter"); - self.insert(id) - } - _ => { - trace!( - " Array without Named type does have type parameter" - ); - ConstrainResult::Same - } + if let TypeKind::TypeParam = *inner_ty.kind() { + trace!(" Array with Named type has type parameter"); + self.insert(id) + } else { + trace!( + " Array without Named type does have type parameter" + ); + ConstrainResult::Same } } diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index ae1acb925d..df7db899b5 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -923,10 +923,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" for (id, item) in self.items() { let kind = item.kind(); - let ty = match kind.as_type() { - Some(ty) => ty, - None => continue, - }; + let Some(ty) = kind.as_type() else { continue }; if let TypeKind::UnresolvedTypeRef(ref ty, loc, parent_id) = *ty.kind() @@ -1063,9 +1060,8 @@ If you encounter an error missing from this list, please file an issue or a PR!" // Calls to `canonical_name` are expensive, so eagerly filter out // items that cannot be replaced. - let ty = match item.kind().as_type() { - Some(ty) => ty, - None => continue, + let Some(ty) = item.kind().as_type() else { + continue; }; match *ty.kind() { @@ -2517,9 +2513,8 @@ If you encounter an error missing from this list, please file an issue or a PR!" return false; } - let enum_ = match *ty.kind() { - TypeKind::Enum(ref e) => e, - _ => return false, + let TypeKind::Enum(ref enum_) = *ty.kind() else { + return false; }; if ty.name().is_some() { diff --git a/bindgen/ir/item.rs b/bindgen/ir/item.rs index b79e99065f..010297615d 100644 --- a/bindgen/ir/item.rs +++ b/bindgen/ir/item.rs @@ -582,9 +582,8 @@ impl Item { let mut parent = self.parent_id; loop { - let parent_item = match ctx.resolve_item_fallible(parent) { - Some(item) => item, - None => return false, + let Some(parent_item) = ctx.resolve_item_fallible(parent) else { + return false; }; if parent_item.id() == ctx.root_module() { @@ -976,9 +975,8 @@ impl Item { // Do not jump through aliases, except for aliases that point to a type // with the same name, since we dont generate coe for them. let item = self.id.into_resolver().through_type_refs().resolve(ctx); - let type_ = match *item.kind() { - ItemKind::Type(ref type_) => type_, - _ => return false, + let ItemKind::Type(ref type_) = *item.kind() else { + return false; }; match *type_.kind() { @@ -1075,9 +1073,8 @@ impl Item { /// Returns a prefix for the canonical name when C naming is enabled. fn c_naming_prefix(&self) -> Option<&str> { - let ty = match self.kind { - ItemKind::Type(ref ty) => ty, - _ => return None, + let ItemKind::Type(ref ty) = self.kind else { + return None; }; Some(match ty.kind() { diff --git a/bindgen/ir/template.rs b/bindgen/ir/template.rs index 59bd4bfde4..2783b414d8 100644 --- a/bindgen/ir/template.rs +++ b/bindgen/ir/template.rs @@ -266,17 +266,14 @@ impl TemplateInstantiation { }) }; - let definition = match definition { - Some(def) => def, - None => { - if !ty.declaration().is_builtin() { - warn!( - "Could not find template definition for template \ + let Some(definition) = definition else { + if !ty.declaration().is_builtin() { + warn!( + "Could not find template definition for template \ instantiation" - ); - } - return None; + ); } + return None; }; let template_definition = diff --git a/bindgen/ir/ty.rs b/bindgen/ir/ty.rs index 5aea619808..31606465b8 100644 --- a/bindgen/ir/ty.rs +++ b/bindgen/ir/ty.rs @@ -860,20 +860,16 @@ impl Type { Some(location), ctx, ); - match complex { - Ok(complex) => TypeKind::Comp(complex), - Err(_) => { - warn!( - "Could not create complex type \ - from class template or base \ - specifier, using opaque blob" - ); - let opaque = - Opaque::from_clang_ty(ty, ctx); - return Ok(ParseResult::New( - opaque, None, - )); - } + if let Ok(complex) = complex { + TypeKind::Comp(complex) + } else { + warn!( + "Could not create complex type \ + from class template or base \ + specifier, using opaque blob" + ); + let opaque = Opaque::from_clang_ty(ty, ctx); + return Ok(ParseResult::New(opaque, None)); } } CXCursor_TypeAliasTemplateDecl => { @@ -921,16 +917,13 @@ impl Type { CXChildVisit_Continue }); - let inner_type = match inner { - Ok(inner) => inner, - Err(..) => { - warn!( - "Failed to parse template alias \ + let Ok(inner_type) = inner else { + warn!( + "Failed to parse template alias \ {:?}", - location - ); - return Err(ParseError::Continue); - } + location + ); + return Err(ParseError::Continue); }; TypeKind::TemplateAlias(inner_type, args) diff --git a/bindgen/ir/var.rs b/bindgen/ir/var.rs index b84950aad6..fa6930ec14 100644 --- a/bindgen/ir/var.rs +++ b/bindgen/ir/var.rs @@ -199,9 +199,8 @@ impl ClangSubItemParser for Var { let value = parse_macro(ctx, &cursor); - let (id, value) = match value { - Some(v) => v, - None => return Err(ParseError::Continue), + let Some((id, value)) = value else { + return Err(ParseError::Continue); }; assert!(!id.is_empty(), "Empty macro name?"); @@ -339,9 +338,9 @@ impl ClangSubItemParser for Var { // to look at the canonical type of the pointee too, and check // is char, u8, or i8 I guess). let value = if is_integer { - let kind = match *canonical_ty.unwrap().kind() { - TypeKind::Int(kind) => kind, - _ => unreachable!(), + let TypeKind::Int(kind) = *canonical_ty.unwrap().kind() + else { + unreachable!() }; let mut val = cursor.evaluate().and_then(|v| v.as_int()); diff --git a/bindgen/regex_set.rs b/bindgen/regex_set.rs index 17e9708385..3b6aa34101 100644 --- a/bindgen/regex_set.rs +++ b/bindgen/regex_set.rs @@ -115,9 +115,8 @@ impl RegexSet { S: AsRef, { let s = string.as_ref(); - let set = match self.set { - Some(ref set) => set, - None => return false, + let Some(ref set) = self.set else { + return false; }; if !self.record_matches { From d9576ea65bed584c1b67d780bb771061dd9a0f53 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Sat, 30 Nov 2024 17:22:03 -0500 Subject: [PATCH 796/942] Improve debug str generator Generates more optimized code per https://rust-lang.github.io/rust-clippy/master/index.html#format_collect --- .../tests/derive-bitfield-method-same-name.rs | 18 ++++++++++++------ .../tests/derive-debug-bitfield.rs | 18 ++++++++++++------ .../tests/derive-debug-function-pointer.rs | 18 ++++++++++++------ bindgen/codegen/impl_debug.rs | 19 ++++++++++++------- 4 files changed, 48 insertions(+), 25 deletions(-) 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 c8f19bc5af..05e66a72bc 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 @@ -136,12 +136,18 @@ impl ::std::fmt::Debug for Foo { write!( f, "Foo {{ large: [{}], type_ : {:?}, }}", - self - .large - .iter() - .enumerate() - .map(|(i, v)| format!("{}{:?}", if i > 0 { ", " } else { "" }, v)) - .collect::(), + { + 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(), ) } diff --git a/bindgen-tests/tests/expectations/tests/derive-debug-bitfield.rs b/bindgen-tests/tests/expectations/tests/derive-debug-bitfield.rs index 20c7cf0c88..e266880509 100644 --- a/bindgen-tests/tests/expectations/tests/derive-debug-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/derive-debug-bitfield.rs @@ -122,12 +122,18 @@ impl ::std::fmt::Debug for C { "C {{ a : {:?}, b : {:?}, large_array: [{}] }}", self.a(), self.b(), - self - .large_array - .iter() - .enumerate() - .map(|(i, v)| format!("{}{:?}", if i > 0 { ", " } else { "" }, v)) - .collect::(), + { + 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-function-pointer.rs b/bindgen-tests/tests/expectations/tests/derive-debug-function-pointer.rs index 9077201a77..9fe1f5518c 100644 --- a/bindgen-tests/tests/expectations/tests/derive-debug-function-pointer.rs +++ b/bindgen-tests/tests/expectations/tests/derive-debug-function-pointer.rs @@ -40,12 +40,18 @@ impl ::std::fmt::Debug for Nice { f, "Nice {{ pointer: {:?}, large_array: [{}] }}", self.pointer, - self - .large_array - .iter() - .enumerate() - .map(|(i, v)| format!("{}{:?}", if i > 0 { ", " } else { "" }, v)) - .collect::(), + { + 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/codegen/impl_debug.rs b/bindgen/codegen/impl_debug.rs index c4daddf260..319c89b58e 100644 --- a/bindgen/codegen/impl_debug.rs +++ b/bindgen/codegen/impl_debug.rs @@ -186,13 +186,18 @@ impl<'a> ImplDebug<'a> for Item { // Let's implement our own print function Some(( format!("{name}: [{{}}]"), - vec![quote! { - self.#name_ident - .iter() - .enumerate() - .map(|(i, v)| format!("{}{:?}", if i > 0 { ", " } else { "" }, v)) - .collect::() - }], + 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 + }}], )) } } From dd28f0b5787ab7577f802b0e1b7a91b88d2de090 Mon Sep 17 00:00:00 2001 From: Maxence Younsi Date: Fri, 6 Oct 2023 01:21:58 +0200 Subject: [PATCH 797/942] expose discovered composite types and aliases to parse callbacks --- bindgen/callbacks.rs | 56 ++++++++++++++++++++++++++++++++++++++++++ bindgen/codegen/mod.rs | 41 ++++++++++++++++++++++++++++++- 2 files changed, 96 insertions(+), 1 deletion(-) diff --git a/bindgen/callbacks.rs b/bindgen/callbacks.rs index 43dc37d595..71ed325405 100644 --- a/bindgen/callbacks.rs +++ b/bindgen/callbacks.rs @@ -162,6 +162,62 @@ pub trait ParseCallbacks: fmt::Debug { fn wrap_as_variadic_fn(&self, _name: &str) -> Option { None } + + /// This will get called everytime an item (currently struct, union, and alias) is found with some information about it + fn new_item_found(&self, _id: DiscoveredItemId, _item: DiscoveredItem) {} + + // TODO add callback for ResolvedTypeRef +} + +/// An identifier for a discovered item. Used to identify an aliased type (see [DiscoveredItem::Alias]) +#[derive(Ord, PartialOrd, PartialEq, Eq, Hash, Debug, Clone, Copy)] +pub struct DiscoveredItemId(usize); + +impl DiscoveredItemId { + /// Constructor + pub fn new(value: usize) -> Self { + Self(value) + } +} + +/// Struct passed to [ParseCallbacks::new_item_found] containing information about discovered +/// items (struct, union, and alias) +#[derive(Debug, Hash, Clone, Ord, PartialOrd, Eq, PartialEq)] +pub enum DiscoveredItem { + /// Represents a struct with its original name in C and its generated binding name + Struct { + /// The original name (learnt from C) of the structure + /// Can be None if the union is anonymous. + original_name: Option, + + /// The name of the generated binding + final_name: String, + }, + + /// Represents a union with its original name in C and its generated binding name + Union { + /// The original name (learnt from C) of the structure. + /// Can be None if the union is anonymous. + original_name: Option, + + /// The name of the generated binding + final_name: String, + }, + + /// Represents an alias like a typedef + /// ```c + /// typedef struct MyStruct { + /// ... + /// } StructAlias; + /// ``` + /// Here, the name of the alias is `StructAlias` and it's an alias for `MyStruct` + Alias { + /// The name of the alias in C (`StructAlias`) + alias_name: String, + + /// The identifier of the discovered type + alias_for: DiscoveredItemId, + }, // functions, modules, etc. } /// Relevant information about a type to which new derive attributes will be added using diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 82dd8b7199..1561d4d8cd 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -21,7 +21,8 @@ use self::struct_layout::StructLayoutTracker; use super::BindgenOptions; use crate::callbacks::{ - AttributeInfo, DeriveInfo, FieldInfo, TypeKind as DeriveTypeKind, + AttributeInfo, DeriveInfo, DiscoveredItem, DiscoveredItemId, FieldInfo, + TypeKind as DeriveTypeKind, }; use crate::codegen::error::Error; use crate::ir::analysis::{HasVtable, Sizedness}; @@ -983,6 +984,18 @@ impl CodeGenerator for Type { let rust_name = ctx.rust_ident(&name); + ctx.options().for_each_callback(|cb| { + cb.new_item_found( + DiscoveredItemId::new(item.id().as_usize()), + DiscoveredItem::Alias { + alias_name: rust_name.to_string(), + alias_for: DiscoveredItemId::new( + inner_item.id().as_usize(), + ), + }, + ); + }); + let mut tokens = if let Some(comment) = item.comment(ctx) { attributes::doc(comment) } else { @@ -2449,6 +2462,32 @@ impl CodeGenerator for CompInfo { let is_rust_union = is_union && struct_layout.is_rust_union(); + ctx.options().for_each_callback(|cb| { + let discovered_item = match self.kind() { + CompKind::Struct => DiscoveredItem::Struct { + original_name: item + .kind() + .expect_type() + .name() + .map(String::from), + final_name: canonical_ident.to_string(), + }, + CompKind::Union => DiscoveredItem::Union { + original_name: item + .kind() + .expect_type() + .name() + .map(String::from), + final_name: canonical_ident.to_string(), + }, + }; + + cb.new_item_found( + DiscoveredItemId::new(item.id().as_usize()), + discovered_item, + ); + }); + // The custom derives callback may return a list of derive attributes; // add them to the end of the list. let custom_derives = ctx.options().all_callbacks(|cb| { From b23d97874d44df8e41f518790b48f65d57f8bba4 Mon Sep 17 00:00:00 2001 From: Maxence Younsi Date: Mon, 9 Sep 2024 17:06:35 +0200 Subject: [PATCH 798/942] example test for item discovery callback (new_item_found) --- Cargo.lock | 1 + bindgen-tests/Cargo.toml | 1 + .../header_item_discovery.h | 16 ++ .../item_discovery_callback/mod.rs | 246 ++++++++++++++++++ bindgen-tests/tests/parse_callbacks/mod.rs | 2 + 5 files changed, 266 insertions(+) create mode 100644 bindgen-tests/tests/parse_callbacks/item_discovery_callback/header_item_discovery.h create mode 100644 bindgen-tests/tests/parse_callbacks/item_discovery_callback/mod.rs diff --git a/Cargo.lock b/Cargo.lock index f7accc9e68..142112a213 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -81,6 +81,7 @@ dependencies = [ "owo-colors", "prettyplease", "proc-macro2", + "regex", "shlex", "similar", "syn 2.0.90", diff --git a/bindgen-tests/Cargo.toml b/bindgen-tests/Cargo.toml index 3a13c59cfa..77a28ca3cb 100644 --- a/bindgen-tests/Cargo.toml +++ b/bindgen-tests/Cargo.toml @@ -12,6 +12,7 @@ bindgen = { workspace = true, default-features = true, features = ["__cli", "exp owo-colors.workspace = true prettyplease = { workspace = true, features = ["verbatim"] } proc-macro2.workspace = true +regex.workspace = true shlex.workspace = true similar = { workspace = true, features = ["inline"] } syn.workspace = true diff --git a/bindgen-tests/tests/parse_callbacks/item_discovery_callback/header_item_discovery.h b/bindgen-tests/tests/parse_callbacks/item_discovery_callback/header_item_discovery.h new file mode 100644 index 0000000000..10e97ea480 --- /dev/null +++ b/bindgen-tests/tests/parse_callbacks/item_discovery_callback/header_item_discovery.h @@ -0,0 +1,16 @@ +// Unions +void function_using_anonymous_struct(struct {} arg0); + +struct NamedStruct { +}; + +typedef struct NamedStruct AliasOfNamedStruct; + + +// Unions +void function_using_anonymous_union(union {} arg0); + +union NamedUnion { +}; + +typedef union NamedUnion AliasOfNamedUnion; \ No newline at end of file diff --git a/bindgen-tests/tests/parse_callbacks/item_discovery_callback/mod.rs b/bindgen-tests/tests/parse_callbacks/item_discovery_callback/mod.rs new file mode 100644 index 0000000000..da37eeec97 --- /dev/null +++ b/bindgen-tests/tests/parse_callbacks/item_discovery_callback/mod.rs @@ -0,0 +1,246 @@ +use std::cell::RefCell; +use std::collections::HashMap; +use std::rc::Rc; + +use regex::Regex; + +use bindgen::callbacks::{DiscoveredItem, DiscoveredItemId, ParseCallbacks}; +use bindgen::Builder; + +#[derive(Debug, Default)] +struct ItemDiscovery(Rc>); + +pub type ItemCache = HashMap; + +impl ParseCallbacks for ItemDiscovery { + fn new_item_found(&self, _id: DiscoveredItemId, _item: DiscoveredItem) { + self.0.borrow_mut().insert(_id, _item); + } +} +#[test] +pub fn test_item_discovery_callback() { + let discovery = ItemDiscovery::default(); + let info = Rc::clone(&discovery.0); + + Builder::default() + .header(concat!( + env!("CARGO_MANIFEST_DIR"), + "/tests/parse_callbacks/item_discovery_callback/header_item_discovery.h" + )) + .parse_callbacks(Box::new(discovery)) + .generate() + .expect("TODO: panic message"); + + let expected = ItemCache::from([ + ( + DiscoveredItemId::new(10), + DiscoveredItem::Struct { + original_name: Some("NamedStruct".to_string()), + final_name: "NamedStruct".to_string(), + }, + ), + ( + DiscoveredItemId::new(11), + DiscoveredItem::Alias { + alias_name: "AliasOfNamedStruct".to_string(), + alias_for: DiscoveredItemId::new(10), + }, + ), + ( + DiscoveredItemId::new(20), + DiscoveredItem::Union { + original_name: Some("NamedUnion".to_string()), + final_name: "NamedUnion".to_string(), + }, + ), + ( + DiscoveredItemId::new(21), + DiscoveredItem::Alias { + alias_name: "AliasOfNamedUnion".to_string(), + alias_for: DiscoveredItemId::new(20), + }, + ), + ( + DiscoveredItemId::new(30), + DiscoveredItem::Struct { + original_name: None, + final_name: "_bindgen_ty_*".to_string(), + }, + ), + ( + DiscoveredItemId::new(40), + DiscoveredItem::Union { + original_name: None, + final_name: "_bindgen_ty_*".to_string(), + }, + ), + ]); + + compare_item_caches(info.borrow().clone(), expected); +} + +pub fn compare_item_caches(generated: ItemCache, expected: ItemCache) { + // We can't use a simple Eq::eq comparison because of two reasons: + // - anonymous structs/unions will have a final name generated by bindgen which may change + // if the header file or the bindgen logic is altered + // - aliases have a DiscoveredItemId that we can't directly compare for the same instability reasons + for expected_item in expected.values() { + let found = generated.iter().find(|(_generated_id, generated_item)| { + compare_item_info( + expected_item, + generated_item, + &expected, + &generated, + ) + }); + + if found.is_none() { + panic!( + "Missing Expected Item: {:#?}\n in {:#?}", + expected_item, generated + ); + } + } +} + +fn compare_item_info( + expected_item: &DiscoveredItem, + generated_item: &DiscoveredItem, + expected: &ItemCache, + generated: &ItemCache, +) -> bool { + if std::mem::discriminant(expected_item) != + std::mem::discriminant(generated_item) + { + return false; + } + + match generated_item { + DiscoveredItem::Struct { .. } => { + compare_struct_info(expected_item, generated_item) + } + DiscoveredItem::Union { .. } => { + compare_union_info(expected_item, generated_item) + } + DiscoveredItem::Alias { .. } => compare_alias_info( + expected_item, + generated_item, + expected, + generated, + ), + } +} + +pub fn compare_names(expected_name: &str, generated_name: &str) -> bool { + if let Ok(regex) = Regex::new(expected_name) { + regex.is_match(generated_name) + } else { + false + } +} + +pub fn compare_struct_info( + expected_item: &DiscoveredItem, + generated_item: &DiscoveredItem, +) -> bool { + let DiscoveredItem::Struct { + original_name: expected_original_name, + final_name: expected_final_name, + } = expected_item + else { + unreachable!() + }; + + let DiscoveredItem::Struct { + original_name: generated_original_name, + final_name: generated_final_name, + } = generated_item + else { + unreachable!() + }; + + if !compare_names(expected_final_name, generated_final_name) { + return false; + } + + match (expected_original_name, generated_original_name) { + (None, None) => true, + (Some(expected_original_name), Some(generated_original_name)) => { + compare_names(expected_original_name, generated_original_name) + } + _ => false, + } +} + +pub fn compare_union_info( + expected_item: &DiscoveredItem, + generated_item: &DiscoveredItem, +) -> bool { + let DiscoveredItem::Union { + original_name: expected_original_name, + final_name: expected_final_name, + } = expected_item + else { + unreachable!() + }; + + let DiscoveredItem::Union { + original_name: generated_original_name, + final_name: generated_final_name, + } = generated_item + else { + unreachable!() + }; + + if !compare_names(expected_final_name, generated_final_name) { + return false; + } + + match (expected_original_name, generated_original_name) { + (None, None) => true, + (Some(expected_original_name), Some(generated_original_name)) => { + compare_names(expected_original_name, generated_original_name) + } + _ => false, + } +} + +pub fn compare_alias_info( + expected_item: &DiscoveredItem, + generated_item: &DiscoveredItem, + expected: &ItemCache, + generated: &ItemCache, +) -> bool { + let DiscoveredItem::Alias { + alias_name: expected_alias_name, + alias_for: expected_alias_for, + } = expected_item + else { + unreachable!() + }; + + let DiscoveredItem::Alias { + alias_name: generated_alias_name, + alias_for: generated_alias_for, + } = generated_item + else { + unreachable!() + }; + + if !compare_names(expected_alias_name, generated_alias_name) { + return false; + } + + // Assumes correct test definition + let expected_aliased = expected.get(expected_alias_for).unwrap(); + + // We must have the aliased type in the cache + let generated_aliased = + if let Some(generated_aliased) = generated.get(generated_alias_for) { + generated_aliased + } else { + return false; + }; + + compare_item_info(expected_aliased, generated_aliased, expected, generated) +} diff --git a/bindgen-tests/tests/parse_callbacks/mod.rs b/bindgen-tests/tests/parse_callbacks/mod.rs index 2fba5f11a2..7aca0fd1a1 100644 --- a/bindgen-tests/tests/parse_callbacks/mod.rs +++ b/bindgen-tests/tests/parse_callbacks/mod.rs @@ -1,3 +1,5 @@ +mod item_discovery_callback; + use bindgen::callbacks::*; use bindgen::FieldVisibilityKind; From 0267b0e43b3e9ab30977d1e2ee1e327854eef89c Mon Sep 17 00:00:00 2001 From: George Bateman Date: Fri, 9 Aug 2024 21:41:14 +0100 Subject: [PATCH 799/942] Wrap the array representation of opaque types in a #[repr(C)] struct --- bindgen-integration/src/lib.rs | 2 +- .../tests/issue-544-stylo-creduce-2.rs | 12 ++++++- .../libclang-9/issue-544-stylo-creduce-2.rs | 16 +++++++-- .../expectations/tests/non-type-params.rs | 16 +++++++-- .../expectations/tests/nsBaseHashtable.rs | 12 ++++++- .../partial-specialization-and-inheritance.rs | 12 ++++++- .../expectations/tests/size_t_template.rs | 12 ++++++- .../tests/va_list_aarch64_linux.rs | 18 ++++++++++ .../tests/headers/va_list_aarch64_linux.h | 4 +++ bindgen/codegen/helpers.rs | 18 ++++++++-- bindgen/codegen/mod.rs | 35 +++++++++++++++---- bindgen/codegen/struct_layout.rs | 2 +- bindgen/features.rs | 5 ++- bindgen/ir/context.rs | 14 ++++++++ bindgen/ir/ty.rs | 2 +- 15 files changed, 157 insertions(+), 23 deletions(-) create mode 100644 bindgen-tests/tests/expectations/tests/va_list_aarch64_linux.rs create mode 100644 bindgen-tests/tests/headers/va_list_aarch64_linux.h diff --git a/bindgen-integration/src/lib.rs b/bindgen-integration/src/lib.rs index b939d25b25..13f5bd889a 100755 --- a/bindgen-integration/src/lib.rs +++ b/bindgen-integration/src/lib.rs @@ -254,7 +254,7 @@ fn test_item_rename() { #[test] fn test_matching_with_rename() { assert_eq!(bindings::enum_to_be_constified_THREE, 3); - assert_eq!(unsafe { bindings::TEMPLATED_CONST_VALUE.len() }, 30); + assert_eq!(unsafe { bindings::TEMPLATED_CONST_VALUE.0.len() }, 30); } #[test] diff --git a/bindgen-tests/tests/expectations/tests/issue-544-stylo-creduce-2.rs b/bindgen-tests/tests/expectations/tests/issue-544-stylo-creduce-2.rs index c81b672956..8a752f6999 100644 --- a/bindgen-tests/tests/expectations/tests/issue-544-stylo-creduce-2.rs +++ b/bindgen-tests/tests/expectations/tests/issue-544-stylo-creduce-2.rs @@ -1,10 +1,20 @@ #![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, Copy, Clone)] pub struct Foo { pub member: *mut Foo_SecondAlias, } -pub type Foo_FirstAlias = [u8; 0usize]; +pub type Foo_FirstAlias = __BindgenOpaqueArray; pub type Foo_SecondAlias = Foo; impl Default for Foo { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/issue-544-stylo-creduce-2.rs b/bindgen-tests/tests/expectations/tests/libclang-9/issue-544-stylo-creduce-2.rs index 5c5ad156e3..7f0471bd96 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/issue-544-stylo-creduce-2.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/issue-544-stylo-creduce-2.rs @@ -1,11 +1,21 @@ #![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, Copy, Clone)] pub struct Foo { - pub member: *mut [u8; 0usize], + pub member: *mut __BindgenOpaqueArray, } -pub type Foo_FirstAlias = [u8; 0usize]; -pub type Foo_SecondAlias = [u8; 0usize]; +pub type Foo_FirstAlias = __BindgenOpaqueArray; +pub type Foo_SecondAlias = __BindgenOpaqueArray; impl Default for Foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/non-type-params.rs b/bindgen-tests/tests/expectations/tests/non-type-params.rs index 64b293cb1b..afd21fb767 100644 --- a/bindgen-tests/tests/expectations/tests/non-type-params.rs +++ b/bindgen-tests/tests/expectations/tests/non-type-params.rs @@ -1,11 +1,21 @@ #![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]) + } +} pub type Array16 = u8; -pub type ArrayInt4 = [u32; 4usize]; +pub type ArrayInt4 = __BindgenOpaqueArray; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct UsesArray { - pub array_char_16: [u8; 16usize], - pub array_bool_8: [u8; 8usize], + pub array_char_16: __BindgenOpaqueArray, + pub array_bool_8: __BindgenOpaqueArray, pub array_int_4: ArrayInt4, } #[allow(clippy::unnecessary_operation, clippy::identity_op)] diff --git a/bindgen-tests/tests/expectations/tests/nsBaseHashtable.rs b/bindgen-tests/tests/expectations/tests/nsBaseHashtable.rs index f2f7eefb46..32fcc37aba 100644 --- a/bindgen-tests/tests/expectations/tests/nsBaseHashtable.rs +++ b/bindgen-tests/tests/expectations/tests/nsBaseHashtable.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)] pub struct nsBaseHashtableET { @@ -14,7 +24,7 @@ pub struct nsTHashtable { pub struct nsBaseHashtable { pub _address: u8, } -pub type nsBaseHashtable_KeyType = [u8; 0usize]; +pub type nsBaseHashtable_KeyType = __BindgenOpaqueArray; pub type nsBaseHashtable_EntryType = nsBaseHashtableET; #[repr(C)] #[derive(Debug, Copy, Clone)] diff --git a/bindgen-tests/tests/expectations/tests/partial-specialization-and-inheritance.rs b/bindgen-tests/tests/expectations/tests/partial-specialization-and-inheritance.rs index e7c9a38d7f..cd22cce4ea 100644 --- a/bindgen-tests/tests/expectations/tests/partial-specialization-and-inheritance.rs +++ b/bindgen-tests/tests/expectations/tests/partial-specialization-and-inheritance.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)] pub struct Base { @@ -16,7 +26,7 @@ pub struct Usage { } extern "C" { #[link_name = "\u{1}_ZN5Usage13static_memberE"] - pub static mut Usage_static_member: [u32; 2usize]; + pub static mut Usage_static_member: __BindgenOpaqueArray; } #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { diff --git a/bindgen-tests/tests/expectations/tests/size_t_template.rs b/bindgen-tests/tests/expectations/tests/size_t_template.rs index e422131ca7..9126c5071a 100644 --- a/bindgen-tests/tests/expectations/tests/size_t_template.rs +++ b/bindgen-tests/tests/expectations/tests/size_t_template.rs @@ -1,8 +1,18 @@ #![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)] pub struct C { - pub arr: [u32; 3usize], + pub arr: __BindgenOpaqueArray, } #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { diff --git a/bindgen-tests/tests/expectations/tests/va_list_aarch64_linux.rs b/bindgen-tests/tests/expectations/tests/va_list_aarch64_linux.rs new file mode 100644 index 0000000000..c4cc944639 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/va_list_aarch64_linux.rs @@ -0,0 +1,18 @@ +#![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]) + } +} +pub type va_list = __BindgenOpaqueArray; +extern "C" { + pub fn vprintf( + format: *const ::std::os::raw::c_char, + vlist: __BindgenOpaqueArray, + ) -> ::std::os::raw::c_int; +} diff --git a/bindgen-tests/tests/headers/va_list_aarch64_linux.h b/bindgen-tests/tests/headers/va_list_aarch64_linux.h new file mode 100644 index 0000000000..7d2206a76e --- /dev/null +++ b/bindgen-tests/tests/headers/va_list_aarch64_linux.h @@ -0,0 +1,4 @@ +// bindgen-flags: -- --target=aarch64-unknown-linux-gnu + +typedef __builtin_va_list va_list; +int vprintf(const char* format, va_list vlist); diff --git a/bindgen/codegen/helpers.rs b/bindgen/codegen/helpers.rs index aac04a12cb..c572b8887f 100644 --- a/bindgen/codegen/helpers.rs +++ b/bindgen/codegen/helpers.rs @@ -75,9 +75,16 @@ pub(crate) mod attributes { } } -/// Generates a proper type for a field or type with a given `Layout`, that is, -/// a type with the correct size and alignment restrictions. -pub(crate) fn blob(layout: Layout) -> syn::Type { +/// The `ffi_safe` argument should be true if this is a type that the user might +/// reasonably use, e.g. not struct padding, where the __BindgenOpaqueArray is +/// just noise. +/// TODO: Should this be `MaybeUninit`, since padding bytes are effectively +/// uninitialized? +pub(crate) fn blob( + ctx: &BindgenContext, + layout: Layout, + ffi_safe: bool, +) -> syn::Type { let opaque = layout.opaque(); // FIXME(emilio, #412): We fall back to byte alignment, but there are @@ -93,7 +100,12 @@ pub(crate) fn blob(layout: Layout) -> syn::Type { if data_len == 1 { ty + } else if ffi_safe && ctx.options().rust_features().min_const_generics { + ctx.generated_opaque_array(); + syn::parse_quote! { __BindgenOpaqueArray<#ty, #data_len> } } else { + // This is not FFI safe as an argument; the struct above is + // preferable. syn::parse_quote! { [ #ty ; #data_len ] } } } diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 1561d4d8cd..ab3e0ce8df 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -581,6 +581,9 @@ impl CodeGenerator for Module { if ctx.need_bindgen_complex_type() { utils::prepend_complex_type(&mut *result); } + if ctx.need_opaque_array_type() { + utils::prepend_opaque_array_type(&mut *result); + } if result.saw_objc { utils::prepend_objc_header(ctx, &mut *result); } @@ -2275,7 +2278,7 @@ impl CodeGenerator for CompInfo { if has_address { let layout = Layout::new(1, 1); - let ty = helpers::blob(Layout::new(1, 1)); + let ty = helpers::blob(ctx, Layout::new(1, 1), false); struct_layout.saw_field_with_layout( "_address", layout, @@ -2292,7 +2295,7 @@ impl CodeGenerator for CompInfo { Some(l) => { explicit_align = Some(l.align); - let ty = helpers::blob(l); + let ty = helpers::blob(ctx, l, false); fields.push(quote! { pub _bindgen_opaque_blob: #ty , }); @@ -2326,7 +2329,7 @@ impl CodeGenerator for CompInfo { } if !struct_layout.is_rust_union() { - let ty = helpers::blob(layout); + let ty = helpers::blob(ctx, layout, false); fields.push(quote! { pub bindgen_union_field: #ty , }); @@ -4048,7 +4051,8 @@ pub(crate) trait TryToOpaque { ctx: &BindgenContext, extra: &Self::Extra, ) -> error::Result { - self.try_get_layout(ctx, extra).map(helpers::blob) + self.try_get_layout(ctx, extra) + .map(|layout| helpers::blob(ctx, layout, true)) } } @@ -4074,7 +4078,7 @@ pub(crate) trait ToOpaque: TryToOpaque { extra: &Self::Extra, ) -> syn::Type { let layout = self.get_layout(ctx, extra); - helpers::blob(layout) + helpers::blob(ctx, layout, true) } } @@ -4125,7 +4129,7 @@ where ) -> error::Result { self.try_to_rust_ty(ctx, extra).or_else(|_| { if let Ok(layout) = self.try_get_layout(ctx, extra) { - Ok(helpers::blob(layout)) + Ok(helpers::blob(ctx, layout, true)) } else { Err(Error::NoLayoutForOpaqueBlob) } @@ -5573,6 +5577,25 @@ pub(crate) mod utils { result.extend(old_items); } + pub(crate) fn prepend_opaque_array_type( + result: &mut Vec, + ) { + let ty = quote! { + /// 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]) + } + } + }; + + result.insert(0, ty); + } + pub(crate) fn build_path( item: &Item, ctx: &BindgenContext, diff --git a/bindgen/codegen/struct_layout.rs b/bindgen/codegen/struct_layout.rs index 0645d8a84a..88b250cf35 100644 --- a/bindgen/codegen/struct_layout.rs +++ b/bindgen/codegen/struct_layout.rs @@ -393,7 +393,7 @@ impl<'a> StructLayoutTracker<'a> { } fn padding_field(&mut self, layout: Layout) -> proc_macro2::TokenStream { - let ty = helpers::blob(layout); + let ty = helpers::blob(self.ctx, layout, false); let padding_count = self.padding_count; self.padding_count += 1; diff --git a/bindgen/features.rs b/bindgen/features.rs index c278d10fe6..e434c70163 100644 --- a/bindgen/features.rs +++ b/bindgen/features.rs @@ -263,7 +263,10 @@ 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 }, + 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 }, diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index df7db899b5..fe97a8c540 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -388,6 +388,9 @@ pub(crate) struct BindgenContext { /// The options given by the user via cli or other medium. options: BindgenOptions, + /// Whether an opaque array was generated + generated_opaque_array: Cell, + /// Whether a bindgen complex was generated generated_bindgen_complex: Cell, @@ -595,6 +598,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" options, generated_bindgen_complex: Cell::new(false), generated_bindgen_float16: Cell::new(false), + generated_opaque_array: Cell::new(false), allowlisted: None, blocklisted_types_implement_traits: Default::default(), codegen_items: None, @@ -2607,6 +2611,16 @@ If you encounter an error missing from this list, please file an issue or a PR!" } } + /// Call if an opaque array is generated + pub(crate) fn generated_opaque_array(&self) { + self.generated_opaque_array.set(true) + } + + /// Whether we need to generate the opaque array type + pub(crate) fn need_opaque_array_type(&self) -> bool { + self.generated_opaque_array.get() + } + /// Call if a bindgen complex is generated pub(crate) fn generated_bindgen_complex(&self) { self.generated_bindgen_complex.set(true); diff --git a/bindgen/ir/ty.rs b/bindgen/ir/ty.rs index 31606465b8..98df40d2b3 100644 --- a/bindgen/ir/ty.rs +++ b/bindgen/ir/ty.rs @@ -582,7 +582,7 @@ pub(crate) enum TypeKind { /// A compound type, that is, a class, struct, or union. Comp(CompInfo), - /// An opaque type that we just don't understand. All usage of this shoulf + /// An opaque type that we just don't understand. All usage of this should /// result in an opaque blob of bytes generated from the containing type's /// layout. Opaque, From 3dee8ba95fad5ed136821c89f5ca0759b5dfc8f5 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Fri, 5 Jul 2024 11:41:40 -0700 Subject: [PATCH 800/942] Add FieldInfo::field_type_name The relevance of making a ield private may depend on a field's type. Some fields should be protected against manipulation by Rust code for the same reason `Vec::set_len` is `unsafe`. --- CHANGELOG.md | 1 + bindgen/callbacks.rs | 2 ++ bindgen/codegen/mod.rs | 3 +++ 3 files changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a57f07e6e..04fc283d5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -238,6 +238,7 @@ - Add option to use DST structs for flexible arrays (--flexarray-dst, #2772). - Add option to dynamically load variables (#2812). - Add option in CLI to use rustified non-exhaustive enums (--rustified-non-exhaustive-enum, #2847). +- Add field_type_name to FieldInfo. ## Changed - Remove which and lazy-static dependencies (#2809, #2817). - Generate compile-time layout tests (#2787). diff --git a/bindgen/callbacks.rs b/bindgen/callbacks.rs index 71ed325405..c824f92bc9 100644 --- a/bindgen/callbacks.rs +++ b/bindgen/callbacks.rs @@ -280,4 +280,6 @@ pub struct FieldInfo<'a> { pub type_name: &'a str, /// The name of the field. pub field_name: &'a str, + /// The name of the type of the field. + pub field_type_name: Option<&'a str>, } diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index ab3e0ce8df..b67e22b998 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -1547,6 +1547,7 @@ impl FieldCodegen<'_> for FieldData { cb.field_visibility(FieldInfo { type_name: &parent_item.canonical_name(ctx), field_name, + field_type_name: field_ty.name(), }) }), self.annotations(), @@ -1952,6 +1953,7 @@ impl<'a> FieldCodegen<'a> for Bitfield { let bitfield_ty_item = ctx.resolve_item(self.ty()); let bitfield_ty = bitfield_ty_item.expect_type(); + let bitfield_ty_ident = bitfield_ty.name(); let bitfield_ty_layout = bitfield_ty .layout(ctx) @@ -1976,6 +1978,7 @@ impl<'a> FieldCodegen<'a> for Bitfield { cb.field_visibility(FieldInfo { type_name: &parent_item.canonical_name(ctx), field_name, + field_type_name: bitfield_ty_ident, }) }) }); From c1714142945d50e7afc0437df2be2b355576a23c Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Sun, 1 Dec 2024 22:57:10 -0500 Subject: [PATCH 801/942] Expose the name of the inner type of an alias --- bindgen/codegen/mod.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index b67e22b998..94f65669bd 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -1121,6 +1121,9 @@ impl CodeGenerator for Type { cb.field_visibility(FieldInfo { type_name: &item.canonical_name(ctx), field_name: "0", + field_type_name: inner_item + .expect_type() + .name(), }) }) .unwrap_or(ctx.options().default_visibility); From 35e7078e1c6dffc3ed11c5d8a1ae16f139118686 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Mon, 2 Dec 2024 00:23:32 -0500 Subject: [PATCH 802/942] Fix some markdown First ran this ``` cargo clippy --fix --workspace --exclude bindgen-integration --exclude tests_expectations -- -W clippy::doc_markdown ``` followed by a bunch of manual fixes. --- .../tests/quickchecking/src/fuzzers.rs | 108 +++++++++--------- bindgen/callbacks.rs | 6 +- bindgen/clang.rs | 6 +- bindgen/codegen/helpers.rs | 2 +- bindgen/codegen/mod.rs | 6 +- bindgen/codegen/struct_layout.rs | 2 +- bindgen/extra_assertions.rs | 2 +- bindgen/ir/analysis/has_vtable.rs | 2 +- bindgen/ir/comp.rs | 16 +-- bindgen/ir/context.rs | 20 ++-- bindgen/ir/function.rs | 2 +- bindgen/ir/item.rs | 8 +- bindgen/ir/objc.rs | 20 ++-- bindgen/ir/template.rs | 36 +++--- bindgen/ir/traversal.rs | 2 +- bindgen/ir/ty.rs | 6 +- bindgen/ir/var.rs | 4 +- bindgen/lib.rs | 4 +- bindgen/options/cli.rs | 1 + bindgen/regex_set.rs | 4 +- 20 files changed, 128 insertions(+), 129 deletions(-) diff --git a/bindgen-tests/tests/quickchecking/src/fuzzers.rs b/bindgen-tests/tests/quickchecking/src/fuzzers.rs index fffe78f8c7..eea0393239 100644 --- a/bindgen-tests/tests/quickchecking/src/fuzzers.rs +++ b/bindgen-tests/tests/quickchecking/src/fuzzers.rs @@ -1,7 +1,7 @@ use quickcheck::{Arbitrary, Gen}; use std::fmt; -/// BaseTypeC is used in generation of C headers to represent the C language's +/// `BaseTypeC` is used in generation of C headers to represent the C language's /// primitive types as well as `void*`. #[derive(Debug, Clone)] pub struct BaseTypeC { @@ -9,7 +9,7 @@ pub struct BaseTypeC { pub def: String, } -/// TypeQualifierC is used in generation of C headers to represent qualifiers +/// `TypeQualifierC` is used in generation of C headers to represent qualifiers /// such as `const`. #[derive(Debug, Clone)] pub struct TypeQualifierC { @@ -17,7 +17,7 @@ pub struct TypeQualifierC { pub def: String, } -/// PointerLevelC is used in generation of C headers to represent number of +/// `PointerLevelC` is used in generation of C headers to represent number of /// `*` for pointer types. #[derive(Debug, Clone)] pub struct PointerLevelC { @@ -25,7 +25,7 @@ pub struct PointerLevelC { pub def: String, } -/// ArrayDimensionC is used in generation of C headers to represent number of +/// `ArrayDimensionC` is used in generation of C headers to represent number of /// `[]` used to define array types. #[derive(Debug, Clone)] pub struct ArrayDimensionC { @@ -33,7 +33,7 @@ pub struct ArrayDimensionC { pub def: String, } -/// BasicTypeDeclarationC is used in generation of C headers to represent +/// `BasicTypeDeclarationC` is used in generation of C headers to represent /// declarations outside of function pointers that take the form /// `BaseTypeC` + `TypeQualifierC` + `PointerLevelC` + `ident_id`. #[derive(Debug, Clone)] @@ -46,11 +46,11 @@ pub struct BasicTypeDeclarationC { pub pointer_level: PointerLevelC, /// The declaration's array dimension, i.e. [][][]. pub array_dimension: ArrayDimensionC, - /// The declaration's identifier, i.e. ident_N. + /// The declaration's identifier, i.e. `ident_N`. pub ident_id: String, } -/// StructDeclarationC is used in generation of C headers to represent the +/// `StructDeclarationC` is used in generation of C headers to represent the /// definition of a struct type. #[derive(Debug, Clone)] pub struct StructDeclarationC { @@ -58,11 +58,11 @@ pub struct StructDeclarationC { pub fields: DeclarationListC, /// The declaration's array dimension, i.e. [][][]. pub array_dimension: ArrayDimensionC, - /// The declaration's identifier, i.e. struct_N. + /// The declaration's identifier, i.e. `struct_N`. pub ident_id: String, } -/// UnionDeclarationC is used in generation of C headers to represent the +/// `UnionDeclarationC` is used in generation of C headers to represent the /// definition of a union type. #[derive(Debug, Clone)] pub struct UnionDeclarationC { @@ -70,11 +70,11 @@ pub struct UnionDeclarationC { pub fields: DeclarationListC, /// The declaration's array dimension, i.e. [][][]. pub array_dimension: ArrayDimensionC, - /// The declaration's identifier, i.e. union_N. + /// The declaration's identifier, i.e. `union_N`. pub ident_id: String, } -/// FunctionPointerDeclarationC is used in generation of C headers to represent +/// `FunctionPointerDeclarationC` is used in generation of C headers to represent /// the definition of a function pointer type. #[derive(Debug, Clone)] pub struct FunctionPointerDeclarationC { @@ -86,11 +86,11 @@ pub struct FunctionPointerDeclarationC { pub pointer_level: PointerLevelC, /// The function's parameters. pub params: ParameterListC, - /// The declaration's identifier, i.e. func_ptr_N. + /// The declaration's identifier, i.e. `func_ptr_N`. pub ident_id: String, } -/// FunctionPrototypeC is used in generation of C headers to represent the +/// `FunctionPrototypeC` is used in generation of C headers to represent the /// definition of a function prototype. #[derive(Debug, Clone)] pub struct FunctionPrototypeC { @@ -106,7 +106,7 @@ pub struct FunctionPrototypeC { pub ident_id: String, } -/// ParameterC is used in generation of C headers to represent the +/// `ParameterC` is used in generation of C headers to represent the /// definition function parameters. #[derive(Debug, Clone)] pub struct ParameterC { @@ -118,7 +118,7 @@ pub struct ParameterC { pub pointer_level: PointerLevelC, } -/// ParameterListC is used in generation of C headers to represent a list of +/// `ParameterListC` is used in generation of C headers to represent a list of /// definitions of function parameters. #[derive(Debug, Clone)] pub struct ParameterListC { @@ -126,7 +126,7 @@ pub struct ParameterListC { pub params: Vec, } -/// DeclarationC is used in generation of C headers to represent all supported +/// `DeclarationC` is used in generation of C headers to represent all supported /// C type declarations allowed in the generated header. #[derive(Debug, Clone)] pub enum DeclarationC { @@ -142,7 +142,7 @@ pub enum DeclarationC { VariableDecl(BasicTypeDeclarationC), } -/// DeclarationListC is used in generation of C headers to represent a list of +/// `DeclarationListC` is used in generation of C headers to represent a list of /// declarations. #[derive(Debug, Clone)] pub struct DeclarationListC { @@ -150,7 +150,7 @@ pub struct DeclarationListC { pub decls: Vec, } -/// HeaderC is used in generation of C headers to represent a collection of +/// `HeaderC` is used in generation of C headers to represent a collection of /// declarations. #[derive(Clone)] pub struct HeaderC { @@ -158,13 +158,13 @@ pub struct HeaderC { pub def: DeclarationListC, } -/// MakeUnique is used in generation of C headers to make declaration +/// `MakeUnique` is used in generation of C headers to make declaration /// identifiers unique by incorporating the `stamp` parameter into it's name. trait MakeUnique { fn make_unique(&mut self, stamp: usize); } -/// MakeUnique is used in generation of C headers to make DeclarationC +/// `MakeUnique` is used in generation of C headers to make `DeclarationC` /// identifiers unique. impl MakeUnique for DeclarationC { fn make_unique(&mut self, stamp: usize) { @@ -178,7 +178,7 @@ impl MakeUnique for DeclarationC { } } -/// A qucickcheck trait for describing how DeclarationC types can be +/// A qucickcheck trait for describing how `DeclarationC` types can be /// randomly generated and shrunk. impl Arbitrary for DeclarationC { fn arbitrary(g: &mut Gen) -> DeclarationC { @@ -197,7 +197,7 @@ impl Arbitrary for DeclarationC { } } -/// Enables to string and format for DeclarationC types. +/// Enables to string and format for `DeclarationC` types. impl fmt::Display for DeclarationC { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { @@ -210,7 +210,7 @@ impl fmt::Display for DeclarationC { } } -/// A qucickcheck trait for describing how DeclarationListC types can be +/// A qucickcheck trait for describing how `DeclarationListC` types can be /// randomly generated and shrunk. impl Arbitrary for DeclarationListC { fn arbitrary(g: &mut Gen) -> DeclarationListC { @@ -220,7 +220,7 @@ impl Arbitrary for DeclarationListC { } } -/// Enables to string and format for DeclarationListC types. +/// Enables to string and format for `DeclarationListC` types. impl fmt::Display for DeclarationListC { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut display = String::new(); @@ -231,7 +231,7 @@ impl fmt::Display for DeclarationListC { } } -/// A quickcheck trait for describing how BaseTypeC types can be +/// A quickcheck trait for describing how `BaseTypeC` types can be /// randomly generated and shrunk. impl Arbitrary for BaseTypeC { fn arbitrary(g: &mut Gen) -> BaseTypeC { @@ -275,14 +275,14 @@ impl Arbitrary for BaseTypeC { } } -/// Enables to string and format for BaseTypeC types, +/// Enables to string and format for `BaseTypeC` types, impl fmt::Display for BaseTypeC { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.def) } } -/// A qucickcheck trait for describing how TypeQualifierC types can be +/// A qucickcheck trait for describing how `TypeQualifierC` types can be /// randomly generated and shrunk. impl Arbitrary for TypeQualifierC { fn arbitrary(g: &mut Gen) -> TypeQualifierC { @@ -293,14 +293,14 @@ impl Arbitrary for TypeQualifierC { } } -/// Enables to string and format for TypeQualifierC types. +/// Enables to string and format for `TypeQualifierC` types. impl fmt::Display for TypeQualifierC { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.def) } } -/// A qucickcheck trait for describing how PointerLevelC types can be +/// A qucickcheck trait for describing how `PointerLevelC` types can be /// randomly generated and shrunk. impl Arbitrary for PointerLevelC { fn arbitrary(g: &mut Gen) -> PointerLevelC { @@ -311,14 +311,14 @@ impl Arbitrary for PointerLevelC { } } -/// Enables to string and format for PointerLevelC types. +/// Enables to string and format for `PointerLevelC` types. impl fmt::Display for PointerLevelC { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.def) } } -/// A qucickcheck trait for describing how ArrayDimensionC types can be +/// A qucickcheck trait for describing how `ArrayDimensionC` types can be /// randomly generated and shrunk. impl Arbitrary for ArrayDimensionC { fn arbitrary(g: &mut Gen) -> ArrayDimensionC { @@ -336,14 +336,14 @@ impl Arbitrary for ArrayDimensionC { } } -/// Enables to string and format for ArrayDimensionC types. +/// Enables to string and format for `ArrayDimensionC` types. impl fmt::Display for ArrayDimensionC { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.def) } } -/// MakeUnique is used in generation of C headers to make BasicTypeDeclarationC +/// `MakeUnique` is used in generation of C headers to make `BasicTypeDeclarationC` /// identifiers unique. impl MakeUnique for BasicTypeDeclarationC { fn make_unique(&mut self, stamp: usize) { @@ -351,7 +351,7 @@ impl MakeUnique for BasicTypeDeclarationC { } } -/// A qucickcheck trait for describing how BasicTypeDeclarationC types can be +/// A qucickcheck trait for describing how `BasicTypeDeclarationC` types can be /// randomly generated and shrunk. impl Arbitrary for BasicTypeDeclarationC { fn arbitrary(g: &mut Gen) -> BasicTypeDeclarationC { @@ -365,7 +365,7 @@ impl Arbitrary for BasicTypeDeclarationC { } } -/// Enables to string and format for BasicTypeDeclarationC types. +/// Enables to string and format for `BasicTypeDeclarationC` types. impl fmt::Display for BasicTypeDeclarationC { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( @@ -380,7 +380,7 @@ impl fmt::Display for BasicTypeDeclarationC { } } -/// MakeUnique is used in generation of C headers to make StructDeclarationC +/// `MakeUnique` is used in generation of C headers to make `StructDeclarationC` /// identifiers unique. impl MakeUnique for StructDeclarationC { fn make_unique(&mut self, stamp: usize) { @@ -388,7 +388,7 @@ impl MakeUnique for StructDeclarationC { } } -/// A qucickcheck trait for describing how StructDeclarationC types can be +/// A qucickcheck trait for describing how `StructDeclarationC` types can be /// randomly generated and shrunk. impl Arbitrary for StructDeclarationC { fn arbitrary(g: &mut Gen) -> StructDeclarationC { @@ -417,7 +417,7 @@ impl Arbitrary for StructDeclarationC { } } -/// Enables to string and format for StructDeclarationC types. +/// Enables to string and format for `StructDeclarationC` types. impl fmt::Display for StructDeclarationC { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( @@ -428,7 +428,7 @@ impl fmt::Display for StructDeclarationC { } } -/// MakeUnique is used in generation of C headers to make UnionDeclarationC +/// `MakeUnique` is used in generation of C headers to make `UnionDeclarationC` /// identifiers unique. impl MakeUnique for UnionDeclarationC { fn make_unique(&mut self, stamp: usize) { @@ -436,7 +436,7 @@ impl MakeUnique for UnionDeclarationC { } } -/// A qucickcheck trait for describing how UnionDeclarationC types can be +/// A qucickcheck trait for describing how `UnionDeclarationC` types can be /// randomly generated and shrunk. impl Arbitrary for UnionDeclarationC { fn arbitrary(g: &mut Gen) -> UnionDeclarationC { @@ -465,7 +465,7 @@ impl Arbitrary for UnionDeclarationC { } } -/// Enables to string and format for UnionDeclarationC types. +/// Enables to string and format for `UnionDeclarationC` types. impl fmt::Display for UnionDeclarationC { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( @@ -476,15 +476,15 @@ impl fmt::Display for UnionDeclarationC { } } -/// MakeUnique is used in generation of C headers to make -/// FunctionPointerDeclarationC identifiers unique. +/// `MakeUnique` is used in generation of C headers to make +/// `FunctionPointerDeclarationC` identifiers unique. impl MakeUnique for FunctionPointerDeclarationC { fn make_unique(&mut self, stamp: usize) { self.ident_id += &format!("_{stamp}"); } } -/// A qucickcheck trait for describing how FunctionPointerDeclarationC types can +/// A qucickcheck trait for describing how `FunctionPointerDeclarationC` types can /// be randomly generated and shrunk. impl Arbitrary for FunctionPointerDeclarationC { fn arbitrary(g: &mut Gen) -> FunctionPointerDeclarationC { @@ -498,7 +498,7 @@ impl Arbitrary for FunctionPointerDeclarationC { } } -/// Enables to string and format for FunctionPointerDeclarationC types. +/// Enables to string and format for `FunctionPointerDeclarationC` types. impl fmt::Display for FunctionPointerDeclarationC { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( @@ -513,7 +513,7 @@ impl fmt::Display for FunctionPointerDeclarationC { } } -/// MakeUnique is used in generation of C headers to make FunctionPrototypeC +/// `MakeUnique` is used in generation of C headers to make `FunctionPrototypeC` /// identifiers unique. impl MakeUnique for FunctionPrototypeC { fn make_unique(&mut self, stamp: usize) { @@ -521,7 +521,7 @@ impl MakeUnique for FunctionPrototypeC { } } -/// A qucickcheck trait for describing how FunctionPrototypeC types can be +/// A qucickcheck trait for describing how `FunctionPrototypeC` types can be /// randomly generated and shrunk. impl Arbitrary for FunctionPrototypeC { fn arbitrary(g: &mut Gen) -> FunctionPrototypeC { @@ -535,7 +535,7 @@ impl Arbitrary for FunctionPrototypeC { } } -/// Enables to string and format for FunctionPrototypeC types. +/// Enables to string and format for `FunctionPrototypeC` types. impl fmt::Display for FunctionPrototypeC { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( @@ -550,7 +550,7 @@ impl fmt::Display for FunctionPrototypeC { } } -/// A qucickcheck trait for describing how ParameterC types can be +/// A qucickcheck trait for describing how `ParameterC` types can be /// randomly generated and shrunk. impl Arbitrary for ParameterC { fn arbitrary(g: &mut Gen) -> ParameterC { @@ -562,7 +562,7 @@ impl Arbitrary for ParameterC { } } -/// Enables to string and format for ParameterC types. +/// Enables to string and format for `ParameterC` types. impl fmt::Display for ParameterC { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( @@ -573,7 +573,7 @@ impl fmt::Display for ParameterC { } } -/// A qucickcheck trait for describing how ParameterListC types can be +/// A qucickcheck trait for describing how `ParameterListC` types can be /// randomly generated and shrunk. impl Arbitrary for ParameterListC { fn arbitrary(g: &mut Gen) -> ParameterListC { @@ -583,7 +583,7 @@ impl Arbitrary for ParameterListC { } } -/// Enables to string and format for ParameterListC types. +/// Enables to string and format for `ParameterListC` types. impl fmt::Display for ParameterListC { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut display = String::new(); @@ -597,7 +597,7 @@ impl fmt::Display for ParameterListC { } } -/// A qucickcheck trait for describing how HeaderC types can be +/// A qucickcheck trait for describing how `HeaderC` types can be /// randomly generated and shrunk. impl Arbitrary for HeaderC { fn arbitrary(g: &mut Gen) -> HeaderC { @@ -609,7 +609,7 @@ impl Arbitrary for HeaderC { } } -/// Enables to string and format for HeaderC types. +/// Enables to string and format for `HeaderC` types. impl fmt::Display for HeaderC { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut display = String::new(); diff --git a/bindgen/callbacks.rs b/bindgen/callbacks.rs index c824f92bc9..8a21e98dea 100644 --- a/bindgen/callbacks.rs +++ b/bindgen/callbacks.rs @@ -169,7 +169,7 @@ pub trait ParseCallbacks: fmt::Debug { // TODO add callback for ResolvedTypeRef } -/// An identifier for a discovered item. Used to identify an aliased type (see [DiscoveredItem::Alias]) +/// An identifier for a discovered item. Used to identify an aliased type (see [`DiscoveredItem::Alias`]) #[derive(Ord, PartialOrd, PartialEq, Eq, Hash, Debug, Clone, Copy)] pub struct DiscoveredItemId(usize); @@ -180,7 +180,7 @@ impl DiscoveredItemId { } } -/// Struct passed to [ParseCallbacks::new_item_found] containing information about discovered +/// Struct passed to [`ParseCallbacks::new_item_found`] containing information about discovered /// items (struct, union, and alias) #[derive(Debug, Hash, Clone, Ord, PartialOrd, Eq, PartialEq)] pub enum DiscoveredItem { @@ -262,7 +262,7 @@ pub struct ItemInfo<'a> { pub kind: ItemKind, } -/// An enum indicating the kind of item for an ItemInfo. +/// An enum indicating the kind of item for an `ItemInfo`. #[non_exhaustive] pub enum ItemKind { /// A Function diff --git a/bindgen/clang.rs b/bindgen/clang.rs index 7a21aa9f4e..0c35dbe69d 100644 --- a/bindgen/clang.rs +++ b/bindgen/clang.rs @@ -878,7 +878,7 @@ impl Cursor { /// Is the cursor's referent publicly accessible in C++? /// - /// Returns true if self.access_specifier() is `CX_CXXPublic` or + /// Returns true if `self.access_specifier()` is `CX_CXXPublic` or /// `CX_CXXInvalidAccessSpecifier`. pub(crate) fn public_accessible(&self) -> bool { let access = self.access_specifier(); @@ -957,7 +957,7 @@ impl Cursor { .collect() } - /// Obtain the real path name of a cursor of InclusionDirective kind. + /// Obtain the real path name of a cursor of `InclusionDirective` kind. /// /// Returns None if the cursor does not include a file, otherwise the file's full name pub(crate) fn get_included_file_name(&self) -> Option { @@ -1051,7 +1051,7 @@ impl ClangToken { c_str.to_bytes() } - /// Converts a ClangToken to a `cexpr` token if possible. + /// Converts a `ClangToken` to a `cexpr` token if possible. pub(crate) fn as_cexpr_token(&self) -> Option { use cexpr::token; diff --git a/bindgen/codegen/helpers.rs b/bindgen/codegen/helpers.rs index c572b8887f..1827705433 100644 --- a/bindgen/codegen/helpers.rs +++ b/bindgen/codegen/helpers.rs @@ -76,7 +76,7 @@ pub(crate) mod attributes { } /// The `ffi_safe` argument should be true if this is a type that the user might -/// reasonably use, e.g. not struct padding, where the __BindgenOpaqueArray is +/// reasonably use, e.g. not struct padding, where the `__BindgenOpaqueArray` is /// just noise. /// TODO: Should this be `MaybeUninit`, since padding bytes are effectively /// uninitialized? diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 94f65669bd..574b2def09 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -3161,7 +3161,7 @@ impl Method { pub enum EnumVariation { /// The code for this enum will use a Rust enum. Note that creating this in unsafe code /// (including FFI) with an invalid value will invoke undefined behaviour, whether or not - /// its marked as non_exhaustive. + /// its marked as `#[non_exhaustive]`. Rust { /// Indicates whether the generated struct should be `#[non_exhaustive]` non_exhaustive: bool, @@ -3953,7 +3953,7 @@ pub enum AliasVariation { TypeAlias, /// Create a new type by wrapping the old type in a struct and using #[repr(transparent)] NewType, - /// Same as NewStruct but also impl Deref to be able to use the methods of the wrapped type + /// Same as `NewType` but also impl Deref to be able to use the methods of the wrapped type NewTypeDeref, } @@ -4156,7 +4156,7 @@ where /// implementations that need to convert another thing into a Rust type or /// opaque blob in a nested manner should also use fallible trait methods and /// propagate failure up the stack. Only infallible functions and methods like -/// CodeGenerator implementations should use the infallible +/// `CodeGenerator` implementations should use the infallible /// `ToRustTyOrOpaque`. The further out we push error recovery, the more likely /// we are to get a usable `Layout` even if we can't generate an equivalent Rust /// type for a C++ construct. diff --git a/bindgen/codegen/struct_layout.rs b/bindgen/codegen/struct_layout.rs index 88b250cf35..f7f66373fb 100644 --- a/bindgen/codegen/struct_layout.rs +++ b/bindgen/codegen/struct_layout.rs @@ -414,7 +414,7 @@ impl<'a> StructLayoutTracker<'a> { /// Returns whether the new field is known to merge with a bitfield. /// - /// This is just to avoid doing the same check also in pad_field. + /// This is just to avoid doing the same check also in `pad_field`. fn align_to_latest_field(&mut self, new_field_layout: Layout) -> bool { if self.is_packed { // Skip to align fields when packed. diff --git a/bindgen/extra_assertions.rs b/bindgen/extra_assertions.rs index fbddad7825..8526fd42d2 100644 --- a/bindgen/extra_assertions.rs +++ b/bindgen/extra_assertions.rs @@ -2,7 +2,7 @@ //! and/or CI when the `__testing_only_extra_assertions` feature is enabled. /// Simple macro that forwards to assert! when using -/// __testing_only_extra_assertions. +/// `__testing_only_extra_assertions`. macro_rules! extra_assert { ( $cond:expr ) => { if cfg!(feature = "__testing_only_extra_assertions") { diff --git a/bindgen/ir/analysis/has_vtable.rs b/bindgen/ir/analysis/has_vtable.rs index 0953df6eba..3ff64a6d2b 100644 --- a/bindgen/ir/analysis/has_vtable.rs +++ b/bindgen/ir/analysis/has_vtable.rs @@ -223,7 +223,7 @@ impl<'ctx> From> for HashMap { /// vtable during codegen. /// /// This is not for _computing_ whether the thing has a vtable, it is for -/// looking up the results of the HasVtableAnalysis's computations for a +/// looking up the results of the `HasVtableAnalysis`'s computations for a /// specific thing. pub(crate) trait HasVtable { /// Return `true` if this thing has vtable, `false` otherwise. diff --git a/bindgen/ir/comp.rs b/bindgen/ir/comp.rs index a978af581f..1dd074ba4d 100644 --- a/bindgen/ir/comp.rs +++ b/bindgen/ir/comp.rs @@ -1017,6 +1017,7 @@ pub(crate) struct CompInfo { /// The inner types that were declared inside this class, in something like: /// + /// ```c++ /// class Foo { /// typedef int FooTy; /// struct Bar { @@ -1025,6 +1026,7 @@ pub(crate) struct CompInfo { /// } /// /// static Foo::Bar const = {3}; + /// ``` inner_types: Vec, /// Set of static constants declared inside this class. @@ -1043,7 +1045,7 @@ pub(crate) struct CompInfo { has_nonempty_base: bool, /// If this type has a template parameter which is not a type (e.g.: a - /// size_t) + /// `size_t`) has_non_type_template_params: bool, /// Whether this type has a bit field member whose width couldn't be @@ -1056,7 +1058,7 @@ pub(crate) struct CompInfo { /// Used to know if we've found an opaque attribute that could cause us to /// generate a type with invalid layout. This is explicitly used to avoid us - /// generating bad alignments when parsing types like max_align_t. + /// generating bad alignments when parsing types like `max_align_t`. /// /// It's not clear what the behavior should be here, if generating the item /// and pray, or behave as an opaque type. @@ -1098,7 +1100,7 @@ impl CompInfo { /// /// If we're a union without known layout, we try to compute it from our /// members. This is not ideal, but clang fails to report the size for these - /// kind of unions, see test/headers/template_union.hpp + /// kind of unions, see `test/headers/template_union.hpp` pub(crate) fn layout(&self, ctx: &BindgenContext) -> Option { // We can't do better than clang here, sorry. if self.kind == CompKind::Struct { @@ -1213,7 +1215,7 @@ impl CompInfo { } /// Do we see a virtual function during parsing? - /// Get the has_own_virtual_method boolean. + /// Get the `has_own_virtual_method` boolean. pub(crate) fn has_own_virtual_method(&self) -> bool { self.has_own_virtual_method } @@ -1708,12 +1710,12 @@ impl CompInfo { /// Returns whether the current union can be represented as a Rust `union` /// /// Requirements: - /// 1. Current RustTarget allows for `untagged_union` - /// 2. Each field can derive `Copy` or we use ManuallyDrop. + /// 1. Current `RustTarget` allows for `untagged_union` + /// 2. Each field can derive `Copy` or we use `ManuallyDrop`. /// 3. It's not zero-sized. /// /// Second boolean returns whether all fields can be copied (and thus - /// ManuallyDrop is not needed). + /// `ManuallyDrop` is not needed). pub(crate) fn is_rust_union( &self, ctx: &BindgenContext, diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index fe97a8c540..9bc13de63d 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -310,7 +310,7 @@ enum TypeKey { /// A context used during parsing and generation of structs. #[derive(Debug)] pub(crate) struct BindgenContext { - /// The map of all the items parsed so far, keyed off ItemId. + /// The map of all the items parsed so far, keyed off `ItemId`. items: Vec>, /// Clang USR to type map. This is needed to be able to associate types with @@ -330,7 +330,7 @@ pub(crate) struct BindgenContext { /// Current module being traversed. current_module: ModuleId, - /// A HashMap keyed on a type definition, and whose value is the parent ID + /// A `HashMap` keyed on a type definition, and whose value is the parent ID /// of the declaration. /// /// This is used to handle the cases where the semantic and the lexical @@ -346,7 +346,7 @@ pub(crate) struct BindgenContext { /// This means effectively, that a type has a potential ID before knowing if /// it's a correct type. But that's not important in practice. /// - /// We could also use the `types` HashMap, but my intention with it is that + /// We could also use the `types` `HashMap`, but my intention with it is that /// only valid types and declarations end up there, and this could /// potentially break that assumption. currently_parsed_types: Vec, @@ -355,7 +355,7 @@ pub(crate) struct BindgenContext { /// hard errors while parsing duplicated macros, as well to allow macro /// expression parsing. /// - /// This needs to be an std::HashMap because the cexpr API requires it. + /// This needs to be an `std::HashMap` because the `cexpr` API requires it. parsed_macros: StdHashMap, cexpr::expr::EvalResult>, /// A map with all include locations. @@ -623,7 +623,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" self.target_info.triple.starts_with("wasm32-") } - /// Creates a timer for the current bindgen phase. If time_phases is `true`, + /// Creates a timer for the current bindgen phase. If `time_phases` is `true`, /// the timer will print to stderr when it is dropped, otherwise it will do /// nothing. pub(crate) fn timer<'a>(&self, name: &'a str) -> Timer<'a> { @@ -1219,7 +1219,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// When the `__testing_only_extra_assertions` feature is enabled, this /// function walks the IR graph and asserts that we do not have any edges - /// referencing an ItemId for which we do not have an associated IR item. + /// referencing an `ItemId` for which we do not have an associated IR item. fn assert_no_dangling_references(&self) { if cfg!(feature = "__testing_only_extra_assertions") { for _ in self.assert_no_dangling_item_traversal() { @@ -1506,7 +1506,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// correct type definition afterwards. /// /// TODO(emilio): We could consider doing this only when - /// declaration.lexical_parent() != definition.lexical_parent(), but it's + /// `declaration.lexical_parent() != definition.lexical_parent()`, but it's /// not sure it's worth it. pub(crate) fn add_semantic_parent( &mut self, @@ -1593,7 +1593,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// function template declarations(!?!??!). /// /// The only way to do this is manually inspecting the AST and looking for - /// TypeRefs and TemplateRefs inside. This, unfortunately, doesn't work for + /// `TypeRefs` and `TemplateRefs` inside. This, unfortunately, doesn't work for /// more complex cases, see the comment on the assertion below. /// /// To add insult to injury, the AST itself has structure that doesn't make @@ -2297,7 +2297,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" (module_name, kind) } - /// Given a CXCursor_Namespace cursor, return the item ID of the + /// Given a `CXCursor_Namespace` cursor, return the item ID of the /// corresponding module, or create one on the fly. pub(crate) fn module(&mut self, cursor: Cursor) -> ModuleId { use clang_sys::*; @@ -2806,7 +2806,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" !self.cannot_derive_hash.as_ref().unwrap().contains(&id) } - /// Compute whether we can derive PartialOrd, PartialEq or Eq. + /// Compute whether we can derive `PartialOrd`, `PartialEq` or `Eq`. fn compute_cannot_derive_partialord_partialeq_or_eq(&mut self) { let _t = self.timer("compute_cannot_derive_partialord_partialeq_or_eq"); assert!(self.cannot_derive_partialeq_or_partialord.is_none()); diff --git a/bindgen/ir/function.rs b/bindgen/ir/function.rs index 6fcb8d1fbb..6da986e2d9 100644 --- a/bindgen/ir/function.rs +++ b/bindgen/ir/function.rs @@ -82,7 +82,7 @@ pub(crate) struct Function { /// The mangled name, that is, the symbol. mangled_name: Option, - /// The link name. If specified, overwrite mangled_name. + /// The link name. If specified, overwrite `mangled_name`. link_name: Option, /// The ID pointing to the current function signature. diff --git a/bindgen/ir/item.rs b/bindgen/ir/item.rs index 010297615d..0717f3e877 100644 --- a/bindgen/ir/item.rs +++ b/bindgen/ir/item.rs @@ -44,7 +44,7 @@ pub(crate) trait ItemCanonicalName { /// The same, but specifies the path that needs to be followed to reach an item. /// -/// To contrast with canonical_name, here's an example: +/// To contrast with `canonical_name`, here's an example: /// /// ```c++ /// namespace foo { @@ -375,7 +375,7 @@ pub(crate) struct Item { /// The item's local ID, unique only amongst its siblings. Only used for /// anonymous items. /// - /// Lazily initialized in local_id(). + /// Lazily initialized in `local_id()`. /// /// Note that only structs, unions, and enums get a local type ID. In any /// case this is an implementation detail. @@ -668,7 +668,7 @@ impl Item { } } - /// Take out item NameOptions + /// Take out item `NameOptions` pub(crate) fn name<'a>( &'a self, ctx: &'a BindgenContext, @@ -716,7 +716,7 @@ impl Item { s } - /// Helper function for full_disambiguated_name + /// Helper function for `full_disambiguated_name` fn push_disambiguated_name( &self, ctx: &BindgenContext, diff --git a/bindgen/ir/objc.rs b/bindgen/ir/objc.rs index 81560da4d1..d413d6bb95 100644 --- a/bindgen/ir/objc.rs +++ b/bindgen/ir/objc.rs @@ -17,20 +17,20 @@ use clang_sys::CXCursor_ObjCSuperClassRef; use clang_sys::CXCursor_TemplateTypeParameter; use proc_macro2::{Ident, Span, TokenStream}; -/// Objective C interface as used in TypeKind +/// Objective-C interface as used in `TypeKind` /// -/// Also protocols and categories are parsed as this type +/// Also, protocols and categories are parsed as this type #[derive(Debug)] pub(crate) struct ObjCInterface { /// The name - /// like, NSObject + /// like, `NSObject` name: String, category: Option, is_protocol: bool, - /// The list of template names almost always, ObjectType or KeyType + /// The list of template names almost always, `ObjectType` or `KeyType` pub(crate) template_names: Vec, /// The list of protocols that this interface conforms to. @@ -53,7 +53,7 @@ pub(crate) struct ObjCMethod { name: String, /// Method name as converted to rust - /// like, dataWithBytes_length_ + /// like, `dataWithBytes_length`_ rust_name: String, signature: FunctionSig, @@ -77,14 +77,14 @@ impl ObjCInterface { } /// The name - /// like, NSObject + /// like, `NSObject` pub(crate) fn name(&self) -> &str { self.name.as_ref() } /// Formats the name for rust - /// Can be like NSObject, but with categories might be like NSObject_NSCoderMethods - /// and protocols are like PNSObject + /// Can be like `NSObject`, but with categories might be like `NSObject_NSCoderMethods` + /// and protocols are like `PNSObject` pub(crate) fn rust_name(&self) -> String { if let Some(ref cat) = self.category { format!("{}_{cat}", self.name()) @@ -227,12 +227,12 @@ impl ObjCMethod { } /// Method name as converted to rust - /// like, dataWithBytes_length_ + /// like, `dataWithBytes_length`_ pub(crate) fn rust_name(&self) -> &str { self.rust_name.as_ref() } - /// Returns the methods signature as FunctionSig + /// Returns the methods signature as `FunctionSig` pub(crate) fn signature(&self) -> &FunctionSig { &self.signature } diff --git a/bindgen/ir/template.rs b/bindgen/ir/template.rs index 2783b414d8..7f3667879d 100644 --- a/bindgen/ir/template.rs +++ b/bindgen/ir/template.rs @@ -77,27 +77,23 @@ use crate::clang; /// The following table depicts the results of each trait method when invoked on /// each of the declarations above: /// -/// +------+----------------------+--------------------------+-------------------------+---- -/// |Decl. | self_template_params | num_self_template_params | all_template_parameters | ... -/// +------+----------------------+--------------------------+-------------------------+---- -/// |Foo | T, U | 2 | T, U | ... -/// |Bar | V | 1 | T, U, V | ... -/// |Inner | | 0 | T, U | ... -/// |Lol | W | 1 | T, U, W | ... -/// |Wtf | X | 1 | T, U, X | ... -/// |Qux | | 0 | | ... -/// +------+----------------------+--------------------------+------------------------+---- +/// |Decl. | self_template_params | num_self_template_params | all_template_parameters | +/// |------|----------------------|--------------------------|-------------------------| +/// |Foo | T, U | 2 | T, U | +/// |Bar | V | 1 | T, U, V | +/// |Inner | | 0 | T, U | +/// |Lol | W | 1 | T, U, W | +/// |Wtf | X | 1 | T, U, X | +/// |Qux | | 0 | | /// -/// ----+------+-----+----------------------+ -/// ... |Decl. | ... | used_template_params | -/// ----+------+-----+----------------------+ -/// ... |Foo | ... | T, U | -/// ... |Bar | ... | V | -/// ... |Inner | ... | | -/// ... |Lol | ... | T | -/// ... |Wtf | ... | T | -/// ... |Qux | ... | | -/// ----+------+-----+----------------------+ +/// | Decl. | used_template_params | +/// |-------|----------------------| +/// | Foo | T, U | +/// | Bar | V | +/// | Inner | | +/// | Lol | T | +/// | Wtf | T | +/// | Qux | | pub(crate) trait TemplateParameters: Sized { /// Get the set of `ItemId`s that make up this template declaration's free /// template parameters. diff --git a/bindgen/ir/traversal.rs b/bindgen/ir/traversal.rs index ccf3af9a25..01f3a8bd50 100644 --- a/bindgen/ir/traversal.rs +++ b/bindgen/ir/traversal.rs @@ -235,7 +235,7 @@ pub(crate) fn codegen_edges(ctx: &BindgenContext, edge: Edge) -> bool { /// outgoing edges might not have been fully traversed yet) in an active /// traversal. pub(crate) trait TraversalStorage<'ctx> { - /// Construct a new instance of this TraversalStorage, for a new traversal. + /// Construct a new instance of this `TraversalStorage`, for a new traversal. fn new(ctx: &'ctx BindgenContext) -> Self; /// Add the given item to the storage. If the item has never been seen diff --git a/bindgen/ir/ty.rs b/bindgen/ir/ty.rs index 98df40d2b3..cd9a9a1edf 100644 --- a/bindgen/ir/ty.rs +++ b/bindgen/ir/ty.rs @@ -275,7 +275,7 @@ impl Type { } } - /// See safe_canonical_type. + /// See [`Self::safe_canonical_type`]. pub(crate) fn canonical_type<'tr>( &'tr self, ctx: &'tr BindgenContext, @@ -623,7 +623,7 @@ pub(crate) enum TypeKind { /// A pointer to an Apple block. BlockPointer(TypeId), - /// A reference to a type, as in: int& foo(). + /// A reference to a type, as in: int& `foo()`. Reference(TypeId), /// An instantiation of an abstract template definition with a set of @@ -634,7 +634,7 @@ pub(crate) enum TypeKind { /// itself, and postpones its resolution. /// /// These are gone in a phase after parsing where these are mapped to - /// already known types, and are converted to ResolvedTypeRef. + /// already known types, and are converted to `ResolvedTypeRef`. /// /// see tests/headers/typeref.hpp to see somewhere where this is a problem. UnresolvedTypeRef(clang::Type, Cursor, /* parent_id */ Option), diff --git a/bindgen/ir/var.rs b/bindgen/ir/var.rs index fa6930ec14..4f61448fea 100644 --- a/bindgen/ir/var.rs +++ b/bindgen/ir/var.rs @@ -149,8 +149,8 @@ fn default_macro_constant_type(ctx: &BindgenContext, value: i64) -> IntKind { } } -/// Parses tokens from a CXCursor_MacroDefinition pointing into a function-like -/// macro, and calls the func_macro callback. +/// Parses tokens from a `CXCursor_MacroDefinition` pointing into a function-like +/// macro, and calls the `func_macro` callback. fn handle_function_macro( cursor: &clang::Cursor, callbacks: &dyn crate::callbacks::ParseCallbacks, diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 58e1da8665..c9b529ac66 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -1212,7 +1212,7 @@ fn get_target_dependent_env_var( env_var(parse_callbacks, var).ok() } -/// A ParseCallbacks implementation that will act on file includes by echoing a rerun-if-changed +/// A `ParseCallbacks` implementation that will act on file includes by echoing a rerun-if-changed /// line and on env variable usage by echoing a rerun-if-env-changed line /// /// When running inside a `build.rs` script, this can be used to make cargo invalidate the @@ -1278,7 +1278,7 @@ impl callbacks::ParseCallbacks for CargoCallbacks { } } -/// Test command_line_flag function. +/// Test `command_line_flag` function. #[test] fn commandline_flag_unit_test_function() { //Test 1 diff --git a/bindgen/options/cli.rs b/bindgen/options/cli.rs index 29b4413b1b..9d5cea3dc6 100644 --- a/bindgen/options/cli.rs +++ b/bindgen/options/cli.rs @@ -143,6 +143,7 @@ fn parse_custom_attribute( override_usage = "bindgen
-- ...", trailing_var_arg = true )] +#[allow(clippy::doc_markdown)] struct BindgenCommand { /// C or C++ header file. header: String, diff --git a/bindgen/regex_set.rs b/bindgen/regex_set.rs index 3b6aa34101..32279557b5 100644 --- a/bindgen/regex_set.rs +++ b/bindgen/regex_set.rs @@ -49,7 +49,7 @@ impl RegexSet { }) } - /// Construct a RegexSet from the set of entries we've accumulated. + /// Construct a `RegexSet` from the set of entries we've accumulated. /// /// Must be called before calling `matches()`, or it will always return /// false. @@ -60,7 +60,7 @@ impl RegexSet { } #[cfg(all(feature = "__cli", feature = "experimental"))] - /// Construct a RegexSet from the set of entries we've accumulated and emit diagnostics if the + /// Construct a `RegexSet` from the set of entries we've accumulated and emit diagnostics if the /// name of the regex set is passed to it. /// /// Must be called before calling `matches()`, or it will always return From 130a3103a579b58c15eb5637af7b8e0a1404d831 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Sat, 30 Nov 2024 20:24:27 -0500 Subject: [PATCH 803/942] Add support for unsafe extern blocks --- bindgen/codegen/mod.rs | 17 +++++++++++++++-- bindgen/features.rs | 3 +++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 574b2def09..403ac42839 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -800,8 +800,14 @@ impl CodeGenerator for Var { quote! { mut } }; + let safety = ctx + .options() + .rust_features + .unsafe_extern_blocks + .then(|| quote!(unsafe)); + let tokens = quote!( - extern "C" { + #safety extern "C" { #(#attrs)* pub static #maybe_mut #canonical_ident: #ty; } @@ -4704,9 +4710,16 @@ impl CodeGenerator for Function { let ret = utils::fnsig_return_ty(ctx, signature); let ident = ctx.rust_ident(ident); + + let safety = ctx + .options() + .rust_features + .unsafe_extern_blocks + .then(|| quote!(unsafe)); + let tokens = quote! { #wasm_link_attribute - extern #abi { + #safety extern #abi { #(#attributes)* pub fn #ident ( #( #args ),* ) #ret; } diff --git a/bindgen/features.rs b/bindgen/features.rs index e434c70163..9871a58ecf 100644 --- a/bindgen/features.rs +++ b/bindgen/features.rs @@ -255,6 +255,9 @@ define_rust_targets! { ptr_metadata: #81513, layout_for_ptr: #69835, }, + Stable_1_82(82) => { + unsafe_extern_blocks: #127921, + }, Stable_1_77(77) => { offset_of: #106655, literal_cstr(2021)|(2024): #117472, From 0e568fa4fc520cef424bdfedd9af6fd70021580b Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Sat, 30 Nov 2024 20:24:27 -0500 Subject: [PATCH 804/942] Test the `unsafe_extern_blocks` feature --- .../tests/expectations/tests/extern_blocks_post_1_82.rs | 7 +++++++ .../tests/expectations/tests/extern_blocks_pre_1_82.rs | 7 +++++++ bindgen-tests/tests/headers/extern_blocks_post_1_82.h | 5 +++++ bindgen-tests/tests/headers/extern_blocks_pre_1_82.h | 5 +++++ 4 files changed, 24 insertions(+) create mode 100644 bindgen-tests/tests/expectations/tests/extern_blocks_post_1_82.rs create mode 100644 bindgen-tests/tests/expectations/tests/extern_blocks_pre_1_82.rs create mode 100644 bindgen-tests/tests/headers/extern_blocks_post_1_82.h create mode 100644 bindgen-tests/tests/headers/extern_blocks_pre_1_82.h diff --git a/bindgen-tests/tests/expectations/tests/extern_blocks_post_1_82.rs b/bindgen-tests/tests/expectations/tests/extern_blocks_post_1_82.rs new file mode 100644 index 0000000000..a322df78ce --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/extern_blocks_post_1_82.rs @@ -0,0 +1,7 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +unsafe extern "C" { + pub fn cool_function(i: ::std::os::raw::c_int, c: ::std::os::raw::c_char); +} +unsafe extern "C" { + pub static mut cool_static: ::std::os::raw::c_int; +} 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 new file mode 100644 index 0000000000..9f684084ba --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/extern_blocks_pre_1_82.rs @@ -0,0 +1,7 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +extern "C" { + pub fn cool_function(i: ::std::os::raw::c_int, c: ::std::os::raw::c_char); +} +extern "C" { + pub static mut cool_static: ::std::os::raw::c_int; +} diff --git a/bindgen-tests/tests/headers/extern_blocks_post_1_82.h b/bindgen-tests/tests/headers/extern_blocks_post_1_82.h new file mode 100644 index 0000000000..f7f3464e98 --- /dev/null +++ b/bindgen-tests/tests/headers/extern_blocks_post_1_82.h @@ -0,0 +1,5 @@ +// bindgen-flags: --no-layout-tests --rust-target=1.82 + +void cool_function(int i, char c); + +static int cool_static; diff --git a/bindgen-tests/tests/headers/extern_blocks_pre_1_82.h b/bindgen-tests/tests/headers/extern_blocks_pre_1_82.h new file mode 100644 index 0000000000..abed05d11f --- /dev/null +++ b/bindgen-tests/tests/headers/extern_blocks_pre_1_82.h @@ -0,0 +1,5 @@ +// bindgen-flags: --no-layout-tests --rust-target=1.81 + +void cool_function(int i, char c); + +static int cool_static; From 9b6d34fc35234480ca3ec1cf3e0e5555cb4cc8dc Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Sat, 30 Nov 2024 20:24:27 -0500 Subject: [PATCH 805/942] Update the `--merge-extern-blocks` tests --- .../tests/merge_extern_blocks_post_1_82.rs | 44 +++++++++++++++++++ .../tests/merge_extern_blocks_pre_1_82.rs | 44 +++++++++++++++++++ .../headers/merge_extern_blocks_post_1_82.hpp | 14 ++++++ .../headers/merge_extern_blocks_pre_1_82.hpp | 14 ++++++ 4 files changed, 116 insertions(+) create mode 100644 bindgen-tests/tests/expectations/tests/merge_extern_blocks_post_1_82.rs create mode 100644 bindgen-tests/tests/expectations/tests/merge_extern_blocks_pre_1_82.rs create mode 100644 bindgen-tests/tests/headers/merge_extern_blocks_post_1_82.hpp create mode 100644 bindgen-tests/tests/headers/merge_extern_blocks_pre_1_82.hpp diff --git a/bindgen-tests/tests/expectations/tests/merge_extern_blocks_post_1_82.rs b/bindgen-tests/tests/expectations/tests/merge_extern_blocks_post_1_82.rs new file mode 100644 index 0000000000..98659f6382 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/merge_extern_blocks_post_1_82.rs @@ -0,0 +1,44 @@ +#![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 { + #[allow(unused_imports)] + use self::super::root; + #[repr(C)] + #[derive(Debug, Default, Copy, Clone)] + pub struct Point { + pub x: ::std::os::raw::c_int, + } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of Point"][::std::mem::size_of::() - 4usize]; + ["Alignment of Point"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Point::x"][::std::mem::offset_of!(Point, x) - 0usize]; + }; + pub mod ns { + #[allow(unused_imports)] + use self::super::super::root; + #[repr(C)] + #[derive(Debug, Default, Copy, Clone)] + pub struct Point { + pub x: ::std::os::raw::c_int, + } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of Point"][::std::mem::size_of::() - 4usize]; + ["Alignment of Point"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Point::x"][::std::mem::offset_of!(Point, x) - 0usize]; + }; + unsafe extern "C" { + #[link_name = "\u{1}_ZN2ns3fooEv"] + pub fn foo() -> ::std::os::raw::c_int; + #[link_name = "\u{1}_ZN2ns3barEv"] + pub fn bar() -> ::std::os::raw::c_int; + } + } + unsafe extern "C" { + #[link_name = "\u{1}_Z3foov"] + pub fn foo() -> ::std::os::raw::c_int; + #[link_name = "\u{1}_Z3barv"] + pub fn bar() -> ::std::os::raw::c_int; + } +} diff --git a/bindgen-tests/tests/expectations/tests/merge_extern_blocks_pre_1_82.rs b/bindgen-tests/tests/expectations/tests/merge_extern_blocks_pre_1_82.rs new file mode 100644 index 0000000000..595d865af1 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/merge_extern_blocks_pre_1_82.rs @@ -0,0 +1,44 @@ +#![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 { + #[allow(unused_imports)] + use self::super::root; + #[repr(C)] + #[derive(Debug, Default, Copy, Clone)] + pub struct Point { + pub x: ::std::os::raw::c_int, + } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of Point"][::std::mem::size_of::() - 4usize]; + ["Alignment of Point"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Point::x"][::std::mem::offset_of!(Point, x) - 0usize]; + }; + pub mod ns { + #[allow(unused_imports)] + use self::super::super::root; + #[repr(C)] + #[derive(Debug, Default, Copy, Clone)] + pub struct Point { + pub x: ::std::os::raw::c_int, + } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of Point"][::std::mem::size_of::() - 4usize]; + ["Alignment of Point"][::std::mem::align_of::() - 4usize]; + ["Offset of field: Point::x"][::std::mem::offset_of!(Point, x) - 0usize]; + }; + extern "C" { + #[link_name = "\u{1}_ZN2ns3fooEv"] + pub fn foo() -> ::std::os::raw::c_int; + #[link_name = "\u{1}_ZN2ns3barEv"] + pub fn bar() -> ::std::os::raw::c_int; + } + } + extern "C" { + #[link_name = "\u{1}_Z3foov"] + pub fn foo() -> ::std::os::raw::c_int; + #[link_name = "\u{1}_Z3barv"] + pub fn bar() -> ::std::os::raw::c_int; + } +} diff --git a/bindgen-tests/tests/headers/merge_extern_blocks_post_1_82.hpp b/bindgen-tests/tests/headers/merge_extern_blocks_post_1_82.hpp new file mode 100644 index 0000000000..080979f17b --- /dev/null +++ b/bindgen-tests/tests/headers/merge_extern_blocks_post_1_82.hpp @@ -0,0 +1,14 @@ +// bindgen-flags: --merge-extern-blocks --enable-cxx-namespaces --rust-target=1.82 -- --target=x86_64-unknown-linux +int foo(); +typedef struct Point { + int x; +} Point; +int bar(); + +namespace ns { + int foo(); + typedef struct Point { + int x; + } Point; + int bar(); +} diff --git a/bindgen-tests/tests/headers/merge_extern_blocks_pre_1_82.hpp b/bindgen-tests/tests/headers/merge_extern_blocks_pre_1_82.hpp new file mode 100644 index 0000000000..779abf174b --- /dev/null +++ b/bindgen-tests/tests/headers/merge_extern_blocks_pre_1_82.hpp @@ -0,0 +1,14 @@ +// bindgen-flags: --merge-extern-blocks --enable-cxx-namespaces --rust-target=1.81 -- --target=x86_64-unknown-linux +int foo(); +typedef struct Point { + int x; +} Point; +int bar(); + +namespace ns { + int foo(); + typedef struct Point { + int x; + } Point; + int bar(); +} From d8dbe3e5b0eb6328e8a42fcfb68124676a52cb38 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Sat, 30 Nov 2024 20:24:27 -0500 Subject: [PATCH 806/942] Bless all the tests --- .../tests/expectations/tests/abi-override.rs | 8 +- .../tests/abi_variadic_function.rs | 2 +- .../expectations/tests/allowlist-file.rs | 10 +- .../tests/expectations/tests/allowlist_fix.rs | 2 +- .../expectations/tests/allowlist_item.rs | 2 +- .../tests/expectations/tests/arg_keyword.rs | 2 +- .../expectations/tests/atomic-constant.rs | 4 +- .../tests/expectations/tests/auto.rs | 2 +- .../tests/bitfield-method-same-name.rs | 6 +- .../tests/bitfield_large_overflow.rs | 2 +- .../expectations/tests/block_return_type.rs | 2 +- .../expectations/tests/blocklist-function.rs | 2 +- .../expectations/tests/blocklist-item.rs | 2 +- .../expectations/tests/blocklist-methods.rs | 2 +- .../expectations/tests/blocks-signature.rs | 8 +- .../tests/expectations/tests/blocks.rs | 8 +- .../tests/c-unwind-abi-override.rs | 6 +- .../tests/expectations/tests/c_naming.rs | 6 +- .../expectations/tests/call-conv-field.rs | 2 +- .../canonical_path_without_namespacing.rs | 2 +- .../tests/expectations/tests/class_nested.rs | 4 +- .../tests/expectations/tests/class_static.rs | 6 +- .../expectations/tests/class_with_typedef.rs | 8 +- .../expectations/tests/complex_global.rs | 6 +- .../tests/expectations/tests/const_array.rs | 4 +- .../expectations/tests/const_array_fn_arg.rs | 2 +- .../expectations/tests/const_array_typedef.rs | 10 +- .../tests/const_multidim_array_fn_arg.rs | 2 +- .../tests/expectations/tests/const_ptr.rs | 2 +- .../expectations/tests/const_resolved_ty.rs | 2 +- .../tests/constify-module-enums-basic.rs | 4 +- .../tests/constify-module-enums-types.rs | 8 +- .../expectations/tests/constructor-tp.rs | 2 +- .../tests/expectations/tests/constructors.rs | 6 +- .../tests/decl_extern_int_twice.rs | 2 +- .../expectations/tests/decl_ptr_to_array.rs | 2 +- .../default-enum-style-constified-module.rs | 2 +- .../default-macro-constant-type-signed.rs | 4 +- .../default-macro-constant-type-unsigned.rs | 4 +- .../tests/default-macro-constant-type.rs | 4 +- .../tests/default-template-parameter.rs | 2 +- .../expectations/tests/deleted-function.rs | 6 +- .../tests/disable-nested-struct-naming.rs | 2 +- .../tests/duplicated-definition-count.rs | 6 +- .../tests/dynamic_loading_with_blocklist.rs | 6 +- .../tests/dynamic_loading_with_class.rs | 6 +- .../tests/expectations/tests/elaborated.rs | 2 +- .../tests/enum_and_vtable_mangling.rs | 2 +- .../tests/fit-macro-constant-types-signed.rs | 4 +- .../tests/fit-macro-constant-types.rs | 4 +- .../tests/expectations/tests/float16.rs | 2 +- .../tests/forward_declared_complex_types.rs | 6 +- .../tests/expectations/tests/func_ptr.rs | 2 +- .../tests/func_ptr_return_type.rs | 2 +- .../tests/func_return_must_use.rs | 14 +-- .../expectations/tests/func_with_array_arg.rs | 2 +- .../tests/func_with_func_ptr_arg.rs | 4 +- .../expectations/tests/gen-constructors.rs | 2 +- .../expectations/tests/gen-destructors.rs | 2 +- .../expectations/tests/generate-inline.rs | 4 +- .../expectations/tests/inner-typedef-gh422.rs | 2 +- .../tests/expectations/tests/inner_const.rs | 4 +- .../tests/issue-1118-using-forward-decl.rs | 2 +- .../tests/issue-1216-variadic-member.rs | 2 +- .../issue-1350-attribute-overloadable.rs | 4 +- .../tests/issue-1375-prefixed-functions.rs | 6 +- .../tests/expectations/tests/issue-1435.rs | 2 +- .../tests/expectations/tests/issue-2019.rs | 4 +- .../tests/expectations/tests/issue-2556.rs | 2 +- .../tests/expectations/tests/issue-410.rs | 2 +- .../tests/expectations/tests/issue-447.rs | 2 +- .../tests/expectations/tests/issue-511.rs | 8 +- .../issue-574-assertion-failure-in-codegen.rs | 2 +- ...issue-584-stylo-template-analysis-panic.rs | 2 +- .../tests/issue-654-struct-fn-collision.rs | 2 +- .../tests/issue-801-opaque-sloppiness.rs | 2 +- ...07-opaque-types-methods-being-generated.rs | 6 +- .../tests/expectations/tests/issue-833-1.rs | 2 +- .../tests/expectations/tests/issue-833.rs | 2 +- .../issue-848-replacement-system-include.rs | 2 +- .../tests/issue-888-enum-var-decl-jump.rs | 2 +- .../tests/expectations/tests/keywords.rs | 110 +++++++++--------- .../tests/libclang-9/atomic-constant.rs | 2 +- .../tests/macro-expr-uncommon-token.rs | 2 +- .../tests/expectations/tests/mangling-ios.rs | 2 +- .../expectations/tests/mangling-linux32.rs | 4 +- .../expectations/tests/mangling-linux64.rs | 4 +- .../expectations/tests/mangling-macos.rs | 4 +- .../expectations/tests/mangling-win32.rs | 12 +- .../expectations/tests/mangling-win64.rs | 4 +- .../expectations/tests/merge-extern-blocks.rs | 44 ------- .../expectations/tests/method-mangling.rs | 2 +- .../tests/expectations/tests/namespace.rs | 14 +-- .../tests/expectations/tests/nested_vtable.rs | 2 +- .../tests/expectations/tests/noreturn.rs | 10 +- .../tests/expectations/tests/objc_class.rs | 2 +- .../expectations/tests/objc_interface_type.rs | 4 +- .../expectations/tests/objc_sel_and_id.rs | 6 +- .../expectations/tests/opaque-tracing.rs | 2 +- .../tests/expectations/tests/operator.rs | 2 +- .../tests/expectations/tests/overloading.rs | 8 +- .../tests/expectations/tests/parm-union.rs | 2 +- .../partial-specialization-and-inheritance.rs | 2 +- .../tests/expectations/tests/pointer-attr.rs | 2 +- .../expectations/tests/prefix-link-name-c.rs | 2 +- .../tests/prefix-link-name-cpp.rs | 2 +- .../tests/expectations/tests/public-dtor.rs | 2 +- .../tests/expectations/tests/redeclaration.rs | 2 +- .../expectations/tests/ref_argument_array.rs | 2 +- .../tests/resolved_type_def_function.rs | 2 +- .../tests/expectations/tests/sorted_items.rs | 12 +- .../expectations/tests/stdint_typedef.rs | 2 +- .../tests/expectations/tests/template.rs | 2 +- ...mplate_instantiation_with_fn_local_type.rs | 2 +- .../test_mixed_header_and_header_contents.rs | 6 +- .../test_multiple_header_calls_in_builder.rs | 2 +- ...type-referenced-by-allowlisted-function.rs | 2 +- .../tests/typedef-pointer-overlap.rs | 20 ++-- .../tests/typedefd-array-as-function-arg.rs | 2 +- .../tests/expectations/tests/union_dtor.rs | 2 +- .../expectations/tests/unsorted-items.rs | 6 +- .../tests/expectations/tests/use-core.rs | 2 +- .../tests/va_list_aarch64_linux.rs | 2 +- .../tests/expectations/tests/var-tracing.rs | 4 +- .../expectations/tests/variadic-method.rs | 4 +- .../tests/expectations/tests/vector.rs | 2 +- .../tests/expectations/tests/virtual_dtor.rs | 2 +- .../expectations/tests/virtual_overloaded.rs | 4 +- .../tests/expectations/tests/void_typedef.rs | 6 +- .../tests/vtable_recursive_sig.rs | 2 +- .../tests/wasm-constructor-returns.rs | 2 +- .../expectations/tests/wasm-import-module.rs | 2 +- .../tests/win32-thiscall_nightly.rs | 4 +- .../tests/win32-vectorcall-nightly.rs | 2 +- .../tests/with_array_pointers_arguments.rs | 6 +- .../tests/without_array_pointers_arguments.rs | 6 +- .../expectations/tests/wrap-static-fns.rs | 28 ++--- .../tests/wrap_unsafe_ops_class.rs | 8 +- .../tests/wrap_unsafe_ops_objc_class.rs | 2 +- .../tests/headers/merge-extern-blocks.hpp | 14 --- bindgen-tests/tests/tests.rs | 10 +- 141 files changed, 338 insertions(+), 396 deletions(-) delete mode 100644 bindgen-tests/tests/expectations/tests/merge-extern-blocks.rs delete mode 100644 bindgen-tests/tests/headers/merge-extern-blocks.hpp diff --git a/bindgen-tests/tests/expectations/tests/abi-override.rs b/bindgen-tests/tests/expectations/tests/abi-override.rs index 13132f9c45..38fe76fd63 100644 --- a/bindgen-tests/tests/expectations/tests/abi-override.rs +++ b/bindgen-tests/tests/expectations/tests/abi-override.rs @@ -1,14 +1,14 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern "fastcall" { +unsafe extern "fastcall" { pub fn foo(); } -extern "stdcall" { +unsafe extern "stdcall" { pub fn bar(); } -extern "C" { +unsafe extern "C" { pub fn baz(); } -extern "system" { +unsafe extern "system" { pub fn qux(); } pub type boo = ::std::option::Option; diff --git a/bindgen-tests/tests/expectations/tests/abi_variadic_function.rs b/bindgen-tests/tests/expectations/tests/abi_variadic_function.rs index 3cb7248c93..b57ddafd32 100644 --- a/bindgen-tests/tests/expectations/tests/abi_variadic_function.rs +++ b/bindgen-tests/tests/expectations/tests/abi_variadic_function.rs @@ -1,5 +1,5 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_Z1bcz"] pub fn b(arg1: ::std::os::raw::c_char, ...) -> ::std::os::raw::c_char; } diff --git a/bindgen-tests/tests/expectations/tests/allowlist-file.rs b/bindgen-tests/tests/expectations/tests/allowlist-file.rs index a0053653f3..b1fb170de0 100644 --- a/bindgen-tests/tests/expectations/tests/allowlist-file.rs +++ b/bindgen-tests/tests/expectations/tests/allowlist-file.rs @@ -1,10 +1,10 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const SOME_DEFUN: u32 = 123; -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_Z12SomeFunctionv"] pub fn SomeFunction(); } -extern "C" { +unsafe extern "C" { pub static mut someVar: ::std::os::raw::c_int; } #[repr(C)] @@ -17,7 +17,7 @@ const _: () = { ["Size of someClass"][::std::mem::size_of::() - 1usize]; ["Alignment of someClass"][::std::mem::align_of::() - 1usize]; }; -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN9someClass16somePublicMethodEi"] pub fn someClass_somePublicMethod(this: *mut someClass, foo: ::std::os::raw::c_int); } @@ -27,10 +27,10 @@ impl someClass { someClass_somePublicMethod(self, foo) } } -extern "C" { +unsafe extern "C" { pub fn ExternFunction(); } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN3foo18NamespacedFunctionEv"] pub fn foo_NamespacedFunction(); } diff --git a/bindgen-tests/tests/expectations/tests/allowlist_fix.rs b/bindgen-tests/tests/expectations/tests/allowlist_fix.rs index e3ce7bc100..772772c56c 100644 --- a/bindgen-tests/tests/expectations/tests/allowlist_fix.rs +++ b/bindgen-tests/tests/expectations/tests/allowlist_fix.rs @@ -1,5 +1,5 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub enum Test {} -extern "C" { +unsafe extern "C" { pub fn Servo_Test(a: *mut Test); } diff --git a/bindgen-tests/tests/expectations/tests/allowlist_item.rs b/bindgen-tests/tests/expectations/tests/allowlist_item.rs index e5aa4b2172..93eab7e147 100644 --- a/bindgen-tests/tests/expectations/tests/allowlist_item.rs +++ b/bindgen-tests/tests/expectations/tests/allowlist_item.rs @@ -11,6 +11,6 @@ const _: () = { ["Alignment of Foo"][::std::mem::align_of::() - 4usize]; ["Offset of field: Foo::field"][::std::mem::offset_of!(Foo, field) - 0usize]; }; -extern "C" { +unsafe extern "C" { pub fn FooNew(value: ::std::os::raw::c_int) -> Foo; } diff --git a/bindgen-tests/tests/expectations/tests/arg_keyword.rs b/bindgen-tests/tests/expectations/tests/arg_keyword.rs index e7dd10b048..5a48aba011 100644 --- a/bindgen-tests/tests/expectations/tests/arg_keyword.rs +++ b/bindgen-tests/tests/expectations/tests/arg_keyword.rs @@ -1,5 +1,5 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_Z3fooPKc"] pub fn foo(type_: *const ::std::os::raw::c_char); } diff --git a/bindgen-tests/tests/expectations/tests/atomic-constant.rs b/bindgen-tests/tests/expectations/tests/atomic-constant.rs index bd3c18697b..344e632085 100644 --- a/bindgen-tests/tests/expectations/tests/atomic-constant.rs +++ b/bindgen-tests/tests/expectations/tests/atomic-constant.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 static mut a: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { pub static mut b: ::std::os::raw::c_int; } diff --git a/bindgen-tests/tests/expectations/tests/auto.rs b/bindgen-tests/tests/expectations/tests/auto.rs index 0173f0409f..ba93e7a20b 100644 --- a/bindgen-tests/tests/expectations/tests/auto.rs +++ b/bindgen-tests/tests/expectations/tests/auto.rs @@ -15,7 +15,7 @@ const _: () = { pub struct Bar { pub _address: u8, } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_Z5Test2v"] pub fn Test2() -> ::std::os::raw::c_uint; } diff --git a/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs b/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs index 4dc321a8ce..25cc182929 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs @@ -152,15 +152,15 @@ const _: () = { ["Size of Foo"][::std::mem::size_of::() - 1usize]; ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; }; -extern "C" { +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); } diff --git a/bindgen-tests/tests/expectations/tests/bitfield_large_overflow.rs b/bindgen-tests/tests/expectations/tests/bitfield_large_overflow.rs index 8967bb9856..51c777497b 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_large_overflow.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_large_overflow.rs @@ -10,6 +10,6 @@ const _: () = { ["Size of _bindgen_ty_1"][::std::mem::size_of::<_bindgen_ty_1>() - 80usize]; ["Alignment of _bindgen_ty_1"][::std::mem::align_of::<_bindgen_ty_1>() - 8usize]; }; -extern "C" { +unsafe extern "C" { pub static mut a: _bindgen_ty_1; } diff --git a/bindgen-tests/tests/expectations/tests/block_return_type.rs b/bindgen-tests/tests/expectations/tests/block_return_type.rs index fa6c0ac67c..8ab2d70f11 100644 --- a/bindgen-tests/tests/expectations/tests/block_return_type.rs +++ b/bindgen-tests/tests/expectations/tests/block_return_type.rs @@ -1,7 +1,7 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] extern crate block; -extern "C" { +unsafe extern "C" { pub fn func() -> _bindgen_ty_id_4; } pub type _bindgen_ty_id_4 = *const ::block::Block< diff --git a/bindgen-tests/tests/expectations/tests/blocklist-function.rs b/bindgen-tests/tests/expectations/tests/blocklist-function.rs index 2e12a01e9e..65b66b2ac2 100644 --- a/bindgen-tests/tests/expectations/tests/blocklist-function.rs +++ b/bindgen-tests/tests/expectations/tests/blocklist-function.rs @@ -10,7 +10,7 @@ pub mod root { pub mod bar { #[allow(unused_imports)] use self::super::super::root; - extern "C" { + unsafe extern "C" { #[link_name = "\u{1}_ZN3bar18NamespacedFunctionEv"] pub fn NamespacedFunction(); } diff --git a/bindgen-tests/tests/expectations/tests/blocklist-item.rs b/bindgen-tests/tests/expectations/tests/blocklist-item.rs index 39de8002b3..c5daf050a1 100644 --- a/bindgen-tests/tests/expectations/tests/blocklist-item.rs +++ b/bindgen-tests/tests/expectations/tests/blocklist-item.rs @@ -10,7 +10,7 @@ pub mod root { pub mod bar { #[allow(unused_imports)] use self::super::super::root; - extern "C" { + unsafe extern "C" { #[link_name = "\u{1}_ZN3bar18NamespacedFunctionEv"] pub fn NamespacedFunction(); } diff --git a/bindgen-tests/tests/expectations/tests/blocklist-methods.rs b/bindgen-tests/tests/expectations/tests/blocklist-methods.rs index 37bb95492d..c89cadb3d5 100644 --- a/bindgen-tests/tests/expectations/tests/blocklist-methods.rs +++ b/bindgen-tests/tests/expectations/tests/blocklist-methods.rs @@ -9,7 +9,7 @@ const _: () = { ["Size of Foo"][::std::mem::size_of::() - 1usize]; ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; }; -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN3Foo3fooEv"] pub fn Foo_foo(this: *mut Foo) -> ::std::os::raw::c_int; } diff --git a/bindgen-tests/tests/expectations/tests/blocks-signature.rs b/bindgen-tests/tests/expectations/tests/blocks-signature.rs index b1615839ca..93cf28e009 100644 --- a/bindgen-tests/tests/expectations/tests/blocks-signature.rs +++ b/bindgen-tests/tests/expectations/tests/blocks-signature.rs @@ -1,24 +1,24 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] extern crate block; -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_Z8atexit_bU13block_pointerFvvE"] pub fn atexit_b(arg1: _bindgen_ty_id_33); } pub type dispatch_data_t = *mut ::std::os::raw::c_void; pub type dispatch_data_applier_t = _bindgen_ty_id_40; -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_Z19dispatch_data_applyPvU13block_pointerFbS_yPKvyE"] pub fn dispatch_data_apply( data: dispatch_data_t, applier: dispatch_data_applier_t, ) -> bool; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_Z3fooU13block_pointerFvyE"] pub fn foo(arg1: _bindgen_ty_id_50) -> bool; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_Z7foo_ptrPU13block_pointerFvyE"] pub fn foo_ptr(arg1: *mut _bindgen_ty_id_56) -> bool; } diff --git a/bindgen-tests/tests/expectations/tests/blocks.rs b/bindgen-tests/tests/expectations/tests/blocks.rs index ea15d22464..4f51113c4b 100644 --- a/bindgen-tests/tests/expectations/tests/blocks.rs +++ b/bindgen-tests/tests/expectations/tests/blocks.rs @@ -1,23 +1,23 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(target_os = "macos")] -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_Z8atexit_bU13block_pointerFvvE"] pub fn atexit_b(arg1: *mut ::std::os::raw::c_void); } pub type dispatch_data_t = *mut ::std::os::raw::c_void; pub type dispatch_data_applier_t = *mut ::std::os::raw::c_void; -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_Z19dispatch_data_applyPvU13block_pointerFbS_yPKvyE"] pub fn dispatch_data_apply( data: dispatch_data_t, applier: dispatch_data_applier_t, ) -> bool; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_Z3fooU13block_pointerFvyE"] pub fn foo(arg1: *mut ::std::os::raw::c_void) -> bool; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_Z7foo_ptrPU13block_pointerFvyE"] pub fn foo_ptr(arg1: *mut *mut ::std::os::raw::c_void) -> bool; } diff --git a/bindgen-tests/tests/expectations/tests/c-unwind-abi-override.rs b/bindgen-tests/tests/expectations/tests/c-unwind-abi-override.rs index 25fd333cea..a158565033 100644 --- a/bindgen-tests/tests/expectations/tests/c-unwind-abi-override.rs +++ b/bindgen-tests/tests/expectations/tests/c-unwind-abi-override.rs @@ -1,10 +1,10 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern "C-unwind" { +unsafe extern "C-unwind" { pub fn foo(); } -extern "C-unwind" { +unsafe extern "C-unwind" { pub fn bar(); } -extern "C" { +unsafe extern "C" { pub fn baz(); } diff --git a/bindgen-tests/tests/expectations/tests/c_naming.rs b/bindgen-tests/tests/expectations/tests/c_naming.rs index 502c4486eb..38e63ce874 100644 --- a/bindgen-tests/tests/expectations/tests/c_naming.rs +++ b/bindgen-tests/tests/expectations/tests/c_naming.rs @@ -36,12 +36,12 @@ impl Default for union_b { pub type b = union_b; pub const enum_c_A: enum_c = 0; pub type enum_c = ::std::os::raw::c_uint; -extern "C" { +unsafe extern "C" { pub fn takes_a(arg: a); } -extern "C" { +unsafe extern "C" { pub fn takes_b(arg: b); } -extern "C" { +unsafe extern "C" { pub fn takes_c(arg: enum_c); } diff --git a/bindgen-tests/tests/expectations/tests/call-conv-field.rs b/bindgen-tests/tests/expectations/tests/call-conv-field.rs index 089b34b134..8f0502a435 100644 --- a/bindgen-tests/tests/expectations/tests/call-conv-field.rs +++ b/bindgen-tests/tests/expectations/tests/call-conv-field.rs @@ -25,6 +25,6 @@ const _: () = { "Offset of field: JNINativeInterface_::__hack", ][::std::mem::offset_of!(JNINativeInterface_, __hack) - 8usize]; }; -extern "stdcall" { +unsafe extern "stdcall" { pub fn bar(); } diff --git a/bindgen-tests/tests/expectations/tests/canonical_path_without_namespacing.rs b/bindgen-tests/tests/expectations/tests/canonical_path_without_namespacing.rs index d07751a8db..613da3060f 100644 --- a/bindgen-tests/tests/expectations/tests/canonical_path_without_namespacing.rs +++ b/bindgen-tests/tests/expectations/tests/canonical_path_without_namespacing.rs @@ -9,7 +9,7 @@ const _: () = { ["Size of Bar"][::std::mem::size_of::() - 1usize]; ["Alignment of Bar"][::std::mem::align_of::() - 1usize]; }; -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_Z3bazPN3foo3BarE"] pub fn baz(arg1: *mut Bar); } diff --git a/bindgen-tests/tests/expectations/tests/class_nested.rs b/bindgen-tests/tests/expectations/tests/class_nested.rs index 881a95fd93..080f5968bc 100644 --- a/bindgen-tests/tests/expectations/tests/class_nested.rs +++ b/bindgen-tests/tests/expectations/tests/class_nested.rs @@ -47,7 +47,7 @@ const _: () = { ["Alignment of A_C"][::std::mem::align_of::() - 4usize]; ["Offset of field: A_C::baz"][::std::mem::offset_of!(A_C, baz) - 0usize]; }; -extern "C" { +unsafe extern "C" { pub static mut var: A_B; } #[allow(clippy::unnecessary_operation, clippy::identity_op)] @@ -59,7 +59,7 @@ const _: () = { "Align of template specialization: A_D_open0_int_close0", ][::std::mem::align_of::>() - 4usize]; }; -extern "C" { +unsafe extern "C" { pub static mut baz: A_D<::std::os::raw::c_int>; } #[repr(C)] diff --git a/bindgen-tests/tests/expectations/tests/class_static.rs b/bindgen-tests/tests/expectations/tests/class_static.rs index c93968fa0c..d448165d62 100644 --- a/bindgen-tests/tests/expectations/tests/class_static.rs +++ b/bindgen-tests/tests/expectations/tests/class_static.rs @@ -4,11 +4,11 @@ pub struct MyClass { pub _address: u8, } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN7MyClass7exampleE"] pub static mut MyClass_example: *const ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN7MyClass26example_check_no_collisionE"] pub static mut MyClass_example_check_no_collision: *const ::std::os::raw::c_int; } @@ -17,7 +17,7 @@ const _: () = { ["Size of MyClass"][::std::mem::size_of::() - 1usize]; ["Alignment of MyClass"][::std::mem::align_of::() - 1usize]; }; -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZL26example_check_no_collision"] pub static mut example_check_no_collision: *const ::std::os::raw::c_int; } diff --git a/bindgen-tests/tests/expectations/tests/class_with_typedef.rs b/bindgen-tests/tests/expectations/tests/class_with_typedef.rs index 9a89732036..73f2b55cc3 100644 --- a/bindgen-tests/tests/expectations/tests/class_with_typedef.rs +++ b/bindgen-tests/tests/expectations/tests/class_with_typedef.rs @@ -21,19 +21,19 @@ const _: () = { ["Offset of field: C::d"][::std::mem::offset_of!(C, d) - 56usize]; ["Offset of field: C::other_ptr"][::std::mem::offset_of!(C, other_ptr) - 64usize]; }; -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN1C6methodEi"] pub fn C_method(this: *mut C, c: C_MyInt); } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN1C9methodRefERi"] pub fn C_methodRef(this: *mut C, c: *mut C_MyInt); } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN1C16complexMethodRefERPKc"] pub fn C_complexMethodRef(this: *mut C, c: *mut C_Lookup); } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN1C13anotherMethodEi"] pub fn C_anotherMethod(this: *mut C, c: AnotherInt); } diff --git a/bindgen-tests/tests/expectations/tests/complex_global.rs b/bindgen-tests/tests/expectations/tests/complex_global.rs index 101ad0f49f..c818df676e 100644 --- a/bindgen-tests/tests/expectations/tests/complex_global.rs +++ b/bindgen-tests/tests/expectations/tests/complex_global.rs @@ -5,12 +5,12 @@ pub struct __BindgenComplex { pub re: T, pub im: T, } -extern "C" { +unsafe extern "C" { pub static mut globalValueFloat: __BindgenComplex; } -extern "C" { +unsafe extern "C" { pub static mut globalValueDouble: __BindgenComplex; } -extern "C" { +unsafe extern "C" { pub static mut globalValueLongDouble: __BindgenComplex; } diff --git a/bindgen-tests/tests/expectations/tests/const_array.rs b/bindgen-tests/tests/expectations/tests/const_array.rs index 8dae42d116..30852deb36 100644 --- a/bindgen-tests/tests/expectations/tests/const_array.rs +++ b/bindgen-tests/tests/expectations/tests/const_array.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 static foo: [::std::os::raw::c_int; 1usize]; } -extern "C" { +unsafe extern "C" { pub static mut bar: [::std::os::raw::c_int; 1usize]; } diff --git a/bindgen-tests/tests/expectations/tests/const_array_fn_arg.rs b/bindgen-tests/tests/expectations/tests/const_array_fn_arg.rs index 035a56fa78..fb26311115 100644 --- a/bindgen-tests/tests/expectations/tests/const_array_fn_arg.rs +++ b/bindgen-tests/tests/expectations/tests/const_array_fn_arg.rs @@ -1,4 +1,4 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern "C" { +unsafe extern "C" { pub fn f(a: *const ::std::os::raw::c_int); } diff --git a/bindgen-tests/tests/expectations/tests/const_array_typedef.rs b/bindgen-tests/tests/expectations/tests/const_array_typedef.rs index a9ddc0c85e..034856d359 100644 --- a/bindgen-tests/tests/expectations/tests/const_array_typedef.rs +++ b/bindgen-tests/tests/expectations/tests/const_array_typedef.rs @@ -11,18 +11,18 @@ const _: () = { ["Offset of field: strct::field"][::std::mem::offset_of!(strct, field) - 0usize]; }; pub type typ = [strct; 1usize]; -extern "C" { +unsafe extern "C" { pub static mut w: typ; } -extern "C" { +unsafe extern "C" { pub static mut x: *mut strct; } -extern "C" { +unsafe extern "C" { pub static y: typ; } -extern "C" { +unsafe extern "C" { pub static mut z: *const strct; } -extern "C" { +unsafe extern "C" { pub fn function(a: *const strct, b: *const strct); } diff --git a/bindgen-tests/tests/expectations/tests/const_multidim_array_fn_arg.rs b/bindgen-tests/tests/expectations/tests/const_multidim_array_fn_arg.rs index 0c4670b0ed..db0ce114fb 100644 --- a/bindgen-tests/tests/expectations/tests/const_multidim_array_fn_arg.rs +++ b/bindgen-tests/tests/expectations/tests/const_multidim_array_fn_arg.rs @@ -1,4 +1,4 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern "C" { +unsafe extern "C" { pub fn f(a: *const [::std::os::raw::c_int; 1usize]); } diff --git a/bindgen-tests/tests/expectations/tests/const_ptr.rs b/bindgen-tests/tests/expectations/tests/const_ptr.rs index c08aa73d7e..9b9e38c1e7 100644 --- a/bindgen-tests/tests/expectations/tests/const_ptr.rs +++ b/bindgen-tests/tests/expectations/tests/const_ptr.rs @@ -1,4 +1,4 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern "C" { +unsafe extern "C" { pub fn foo(bar: *const ::std::os::raw::c_void); } diff --git a/bindgen-tests/tests/expectations/tests/const_resolved_ty.rs b/bindgen-tests/tests/expectations/tests/const_resolved_ty.rs index 20a124b474..ed49b69f64 100644 --- a/bindgen-tests/tests/expectations/tests/const_resolved_ty.rs +++ b/bindgen-tests/tests/expectations/tests/const_resolved_ty.rs @@ -1,4 +1,4 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern "C" { +unsafe extern "C" { pub fn foo(foo: *const u8); } diff --git a/bindgen-tests/tests/expectations/tests/constify-module-enums-basic.rs b/bindgen-tests/tests/expectations/tests/constify-module-enums-basic.rs index ec0e51c49e..f7d0f1baa6 100644 --- a/bindgen-tests/tests/expectations/tests/constify-module-enums-basic.rs +++ b/bindgen-tests/tests/expectations/tests/constify-module-enums-basic.rs @@ -29,14 +29,14 @@ impl Default for bar { } } } -extern "C" { +unsafe extern "C" { pub fn func1( arg1: foo::Type, arg2: *mut foo::Type, arg3: *mut *mut foo::Type, ) -> *mut foo::Type; } -extern "C" { +unsafe extern "C" { pub fn func2( arg1: foo_alias1, arg2: *mut foo_alias1, diff --git a/bindgen-tests/tests/expectations/tests/constify-module-enums-types.rs b/bindgen-tests/tests/expectations/tests/constify-module-enums-types.rs index 754f6ceedb..6ba94cb3b9 100644 --- a/bindgen-tests/tests/expectations/tests/constify-module-enums-types.rs +++ b/bindgen-tests/tests/expectations/tests/constify-module-enums-types.rs @@ -114,7 +114,7 @@ impl Default for Bar { } } } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_Z5func13fooPS_PS0_"] pub fn func1( arg1: foo::Type, @@ -122,7 +122,7 @@ extern "C" { arg3: *mut *mut foo::Type, ) -> *mut foo::Type; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_Z5func23fooPS_PS0_"] pub fn func2( arg1: foo_alias1, @@ -145,11 +145,11 @@ impl Default for Thing { } } } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_Z5func35ThingI3fooE"] pub fn func3(arg1: Thing) -> foo::Type; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_Z5func45ThingIS_I3fooEE"] pub fn func4(arg1: Thing>) -> foo::Type; } diff --git a/bindgen-tests/tests/expectations/tests/constructor-tp.rs b/bindgen-tests/tests/expectations/tests/constructor-tp.rs index 1a6e9c40dc..2585311d29 100644 --- a/bindgen-tests/tests/expectations/tests/constructor-tp.rs +++ b/bindgen-tests/tests/expectations/tests/constructor-tp.rs @@ -14,7 +14,7 @@ const _: () = { ["Size of Bar"][::std::mem::size_of::() - 1usize]; ["Alignment of Bar"][::std::mem::align_of::() - 1usize]; }; -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN3BarC1Ev"] pub fn Bar_Bar(this: *mut Bar); } diff --git a/bindgen-tests/tests/expectations/tests/constructors.rs b/bindgen-tests/tests/expectations/tests/constructors.rs index 9da761e40a..45c29e61e5 100644 --- a/bindgen-tests/tests/expectations/tests/constructors.rs +++ b/bindgen-tests/tests/expectations/tests/constructors.rs @@ -9,14 +9,14 @@ const _: () = { ["Size of TestOverload"][::std::mem::size_of::() - 1usize]; ["Alignment of TestOverload"][::std::mem::align_of::() - 1usize]; }; -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN12TestOverloadC1Ei"] pub fn TestOverload_TestOverload( this: *mut TestOverload, arg1: ::std::os::raw::c_int, ); } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN12TestOverloadC1Ed"] pub fn TestOverload_TestOverload1(this: *mut TestOverload, arg1: f64); } @@ -46,7 +46,7 @@ const _: () = { "Alignment of TestPublicNoArgs", ][::std::mem::align_of::() - 1usize]; }; -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN16TestPublicNoArgsC1Ev"] pub fn TestPublicNoArgs_TestPublicNoArgs(this: *mut TestPublicNoArgs); } diff --git a/bindgen-tests/tests/expectations/tests/decl_extern_int_twice.rs b/bindgen-tests/tests/expectations/tests/decl_extern_int_twice.rs index 8be0ea58e9..122d41a12d 100644 --- a/bindgen-tests/tests/expectations/tests/decl_extern_int_twice.rs +++ b/bindgen-tests/tests/expectations/tests/decl_extern_int_twice.rs @@ -1,4 +1,4 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern "C" { +unsafe extern "C" { pub static mut foo: ::std::os::raw::c_int; } diff --git a/bindgen-tests/tests/expectations/tests/decl_ptr_to_array.rs b/bindgen-tests/tests/expectations/tests/decl_ptr_to_array.rs index 08cf113a4c..a559d33b4a 100644 --- a/bindgen-tests/tests/expectations/tests/decl_ptr_to_array.rs +++ b/bindgen-tests/tests/expectations/tests/decl_ptr_to_array.rs @@ -1,4 +1,4 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern "C" { +unsafe extern "C" { pub static mut foo: *mut [::std::os::raw::c_int; 1usize]; } diff --git a/bindgen-tests/tests/expectations/tests/default-enum-style-constified-module.rs b/bindgen-tests/tests/expectations/tests/default-enum-style-constified-module.rs index c9897de70b..60c84e47df 100644 --- a/bindgen-tests/tests/expectations/tests/default-enum-style-constified-module.rs +++ b/bindgen-tests/tests/expectations/tests/default-enum-style-constified-module.rs @@ -5,6 +5,6 @@ pub mod Foo { pub const baz: Type = 1; pub const blap: Type = 2; } -extern "C" { +unsafe extern "C" { pub fn func(x: Foo::Type); } diff --git a/bindgen-tests/tests/expectations/tests/default-macro-constant-type-signed.rs b/bindgen-tests/tests/expectations/tests/default-macro-constant-type-signed.rs index db4eaa99bd..7fca57b6b9 100644 --- a/bindgen-tests/tests/expectations/tests/default-macro-constant-type-signed.rs +++ b/bindgen-tests/tests/expectations/tests/default-macro-constant-type-signed.rs @@ -30,7 +30,7 @@ pub const MIN_U32_Minus1: i32 = -1; pub const MIN_I32_Minus1: i64 = -2147483649; pub const LONG12: i64 = 123456789012; pub const LONG_12: i64 = -123456789012; -extern "C" { +unsafe extern "C" { pub fn foo( arg1: ::std::os::raw::c_int, arg2: ::std::os::raw::c_int, @@ -40,7 +40,7 @@ extern "C" { arg6: ::std::os::raw::c_schar, ) -> ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { pub fn bar( arg1: ::std::os::raw::c_long, arg2: ::std::os::raw::c_longlong, diff --git a/bindgen-tests/tests/expectations/tests/default-macro-constant-type-unsigned.rs b/bindgen-tests/tests/expectations/tests/default-macro-constant-type-unsigned.rs index bc122e981f..d34d050a1a 100644 --- a/bindgen-tests/tests/expectations/tests/default-macro-constant-type-unsigned.rs +++ b/bindgen-tests/tests/expectations/tests/default-macro-constant-type-unsigned.rs @@ -30,7 +30,7 @@ pub const MIN_U32_Minus1: i32 = -1; pub const MIN_I32_Minus1: i64 = -2147483649; pub const LONG12: u64 = 123456789012; pub const LONG_12: i64 = -123456789012; -extern "C" { +unsafe extern "C" { pub fn foo( arg1: ::std::os::raw::c_int, arg2: ::std::os::raw::c_int, @@ -40,7 +40,7 @@ extern "C" { arg6: ::std::os::raw::c_schar, ) -> ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { pub fn bar( arg1: ::std::os::raw::c_long, arg2: ::std::os::raw::c_longlong, diff --git a/bindgen-tests/tests/expectations/tests/default-macro-constant-type.rs b/bindgen-tests/tests/expectations/tests/default-macro-constant-type.rs index bc122e981f..d34d050a1a 100644 --- a/bindgen-tests/tests/expectations/tests/default-macro-constant-type.rs +++ b/bindgen-tests/tests/expectations/tests/default-macro-constant-type.rs @@ -30,7 +30,7 @@ pub const MIN_U32_Minus1: i32 = -1; pub const MIN_I32_Minus1: i64 = -2147483649; pub const LONG12: u64 = 123456789012; pub const LONG_12: i64 = -123456789012; -extern "C" { +unsafe extern "C" { pub fn foo( arg1: ::std::os::raw::c_int, arg2: ::std::os::raw::c_int, @@ -40,7 +40,7 @@ extern "C" { arg6: ::std::os::raw::c_schar, ) -> ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { pub fn bar( arg1: ::std::os::raw::c_long, arg2: ::std::os::raw::c_longlong, diff --git a/bindgen-tests/tests/expectations/tests/default-template-parameter.rs b/bindgen-tests/tests/expectations/tests/default-template-parameter.rs index 797fc03253..67f8a486de 100644 --- a/bindgen-tests/tests/expectations/tests/default-template-parameter.rs +++ b/bindgen-tests/tests/expectations/tests/default-template-parameter.rs @@ -25,7 +25,7 @@ const _: () = { "Align of template specialization: Foo_open0_bool__int_close0", ][::std::mem::align_of::>() - 4usize]; }; -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZL3bar"] pub static mut bar: Foo; } diff --git a/bindgen-tests/tests/expectations/tests/deleted-function.rs b/bindgen-tests/tests/expectations/tests/deleted-function.rs index 913e2d4b4a..fc8588121f 100644 --- a/bindgen-tests/tests/expectations/tests/deleted-function.rs +++ b/bindgen-tests/tests/expectations/tests/deleted-function.rs @@ -9,11 +9,11 @@ const _: () = { ["Size of A"][::std::mem::size_of::() - 1usize]; ["Alignment of A"][::std::mem::align_of::() - 1usize]; }; -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN1A17inline_definitionEv"] pub fn A_inline_definition(this: *mut A); } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN1A22out_of_line_definitionEv"] pub fn A_out_of_line_definition(this: *mut A); } @@ -47,7 +47,7 @@ const _: () = { ["Size of C"][::std::mem::size_of::() - 1usize]; ["Alignment of C"][::std::mem::align_of::() - 1usize]; }; -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN1CC1ERS_"] pub fn C_C(this: *mut C, arg1: *mut C); } diff --git a/bindgen-tests/tests/expectations/tests/disable-nested-struct-naming.rs b/bindgen-tests/tests/expectations/tests/disable-nested-struct-naming.rs index 68c729b735..757e0481aa 100644 --- a/bindgen-tests/tests/expectations/tests/disable-nested-struct-naming.rs +++ b/bindgen-tests/tests/expectations/tests/disable-nested-struct-naming.rs @@ -117,6 +117,6 @@ const _: () = { "Offset of field: _bindgen_ty_1::anon2", ][::std::mem::offset_of!(_bindgen_ty_1, anon2) - 0usize]; }; -extern "C" { +unsafe extern "C" { pub static mut anon1: _bindgen_ty_1; } diff --git a/bindgen-tests/tests/expectations/tests/duplicated-definition-count.rs b/bindgen-tests/tests/expectations/tests/duplicated-definition-count.rs index 85f28dcca6..86e1edbbf9 100644 --- a/bindgen-tests/tests/expectations/tests/duplicated-definition-count.rs +++ b/bindgen-tests/tests/expectations/tests/duplicated-definition-count.rs @@ -9,7 +9,7 @@ const _: () = { ["Size of BitStream"][::std::mem::size_of::() - 1usize]; ["Alignment of BitStream"][::std::mem::align_of::() - 1usize]; }; -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN9BitStream5WriteEPKcj"] pub fn BitStream_Write( this: *mut BitStream, @@ -17,7 +17,7 @@ extern "C" { numberOfBytes: ::std::os::raw::c_uint, ); } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN9BitStream5WriteEPS_j"] pub fn BitStream_Write1( this: *mut BitStream, @@ -25,7 +25,7 @@ extern "C" { numberOfBits: ::std::os::raw::c_uint, ); } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN9BitStream6Write1Ev"] pub fn BitStream_Write11(this: *mut BitStream); } diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_blocklist.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_blocklist.rs index 776da1ca5f..b214d0ef4e 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_blocklist.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_blocklist.rs @@ -10,15 +10,15 @@ const _: () = { ["Alignment of X"][::std::mem::align_of::() - 4usize]; ["Offset of field: X::_x"][::std::mem::offset_of!(X, _x) - 0usize]; }; -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN1X13some_functionEv"] pub fn X_some_function(this: *mut X); } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN1X19some_other_functionEv"] pub fn X_some_other_function(this: *mut X); } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN1XC1Ei"] pub fn X_X(this: *mut X, x: ::std::os::raw::c_int); } diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs index 93c636ebff..6395b0c6d3 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs @@ -10,15 +10,15 @@ const _: () = { ["Alignment of A"][::std::mem::align_of::() - 4usize]; ["Offset of field: A::_x"][::std::mem::offset_of!(A, _x) - 0usize]; }; -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN1A13some_functionEv"] pub fn A_some_function(this: *mut A); } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN1A19some_other_functionEv"] pub fn A_some_other_function(this: *mut A); } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN1AC1Ei"] pub fn A_A(this: *mut A, x: ::std::os::raw::c_int); } diff --git a/bindgen-tests/tests/expectations/tests/elaborated.rs b/bindgen-tests/tests/expectations/tests/elaborated.rs index 80bf30f89a..81c0733089 100644 --- a/bindgen-tests/tests/expectations/tests/elaborated.rs +++ b/bindgen-tests/tests/expectations/tests/elaborated.rs @@ -1,6 +1,6 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type whatever_whatever_t = ::std::os::raw::c_int; -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_Z9somethingPKi"] pub fn something(wat: *const whatever_whatever_t); } diff --git a/bindgen-tests/tests/expectations/tests/enum_and_vtable_mangling.rs b/bindgen-tests/tests/expectations/tests/enum_and_vtable_mangling.rs index 18e1ad8e36..0a7e16d6dd 100644 --- a/bindgen-tests/tests/expectations/tests/enum_and_vtable_mangling.rs +++ b/bindgen-tests/tests/expectations/tests/enum_and_vtable_mangling.rs @@ -32,7 +32,7 @@ impl Default for C { } } } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN1C5matchEv"] pub fn C_match(this: *mut ::std::os::raw::c_void); } diff --git a/bindgen-tests/tests/expectations/tests/fit-macro-constant-types-signed.rs b/bindgen-tests/tests/expectations/tests/fit-macro-constant-types-signed.rs index 0602f7714a..d4ad5e0fcc 100644 --- a/bindgen-tests/tests/expectations/tests/fit-macro-constant-types-signed.rs +++ b/bindgen-tests/tests/expectations/tests/fit-macro-constant-types-signed.rs @@ -30,7 +30,7 @@ pub const MIN_U32_Minus1: i8 = -1; pub const MIN_I32_Minus1: i64 = -2147483649; pub const LONG12: i64 = 123456789012; pub const LONG_12: i64 = -123456789012; -extern "C" { +unsafe extern "C" { pub fn foo( arg1: ::std::os::raw::c_int, arg2: ::std::os::raw::c_int, @@ -40,7 +40,7 @@ extern "C" { arg6: ::std::os::raw::c_schar, ) -> ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { pub fn bar( arg1: ::std::os::raw::c_long, arg2: ::std::os::raw::c_longlong, diff --git a/bindgen-tests/tests/expectations/tests/fit-macro-constant-types.rs b/bindgen-tests/tests/expectations/tests/fit-macro-constant-types.rs index f5d2a56ff2..5542a645da 100644 --- a/bindgen-tests/tests/expectations/tests/fit-macro-constant-types.rs +++ b/bindgen-tests/tests/expectations/tests/fit-macro-constant-types.rs @@ -30,7 +30,7 @@ pub const MIN_U32_Minus1: i8 = -1; pub const MIN_I32_Minus1: i64 = -2147483649; pub const LONG12: u64 = 123456789012; pub const LONG_12: i64 = -123456789012; -extern "C" { +unsafe extern "C" { pub fn foo( arg1: ::std::os::raw::c_int, arg2: ::std::os::raw::c_int, @@ -40,7 +40,7 @@ extern "C" { arg6: ::std::os::raw::c_schar, ) -> ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { pub fn bar( arg1: ::std::os::raw::c_long, arg2: ::std::os::raw::c_longlong, diff --git a/bindgen-tests/tests/expectations/tests/float16.rs b/bindgen-tests/tests/expectations/tests/float16.rs index 1804d1007a..2066b71801 100644 --- a/bindgen-tests/tests/expectations/tests/float16.rs +++ b/bindgen-tests/tests/expectations/tests/float16.rs @@ -2,7 +2,7 @@ #[derive(PartialEq, Copy, Clone, Hash, Debug, Default)] #[repr(transparent)] pub struct __BindgenFloat16(pub u16); -extern "C" { +unsafe extern "C" { pub static mut global: __BindgenFloat16; } #[repr(C)] diff --git a/bindgen-tests/tests/expectations/tests/forward_declared_complex_types.rs b/bindgen-tests/tests/expectations/tests/forward_declared_complex_types.rs index 2ba1071c8e..79554d58e4 100644 --- a/bindgen-tests/tests/expectations/tests/forward_declared_complex_types.rs +++ b/bindgen-tests/tests/expectations/tests/forward_declared_complex_types.rs @@ -34,7 +34,7 @@ impl Default for Bar { } } } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_Z10baz_structP3Foo"] pub fn baz_struct(f: *mut Foo); } @@ -43,7 +43,7 @@ extern "C" { pub struct Union { _unused: [u8; 0], } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_Z9baz_unionP5Union"] pub fn baz_union(u: *mut Union); } @@ -52,7 +52,7 @@ extern "C" { pub struct Quux { _unused: [u8; 0], } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_Z9baz_classP4Quux"] pub fn baz_class(q: *mut Quux); } diff --git a/bindgen-tests/tests/expectations/tests/func_ptr.rs b/bindgen-tests/tests/expectations/tests/func_ptr.rs index 4e9c5b131d..b91bdba872 100644 --- a/bindgen-tests/tests/expectations/tests/func_ptr.rs +++ b/bindgen-tests/tests/expectations/tests/func_ptr.rs @@ -1,5 +1,5 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern "C" { +unsafe extern "C" { pub static mut foo: ::std::option::Option< unsafe extern "C" fn( x: ::std::os::raw::c_int, diff --git a/bindgen-tests/tests/expectations/tests/func_ptr_return_type.rs b/bindgen-tests/tests/expectations/tests/func_ptr_return_type.rs index c1c890249f..504eefdfb1 100644 --- a/bindgen-tests/tests/expectations/tests/func_ptr_return_type.rs +++ b/bindgen-tests/tests/expectations/tests/func_ptr_return_type.rs @@ -1,5 +1,5 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern "C" { +unsafe extern "C" { pub fn func() -> ::std::option::Option< unsafe extern "C" fn( arg1: ::std::os::raw::c_int, diff --git a/bindgen-tests/tests/expectations/tests/func_return_must_use.rs b/bindgen-tests/tests/expectations/tests/func_return_must_use.rs index bc9deb0818..904c71cbe3 100644 --- a/bindgen-tests/tests/expectations/tests/func_return_must_use.rs +++ b/bindgen-tests/tests/expectations/tests/func_return_must_use.rs @@ -1,6 +1,6 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type MustUseInt = ::std::os::raw::c_int; -extern "C" { +unsafe extern "C" { #[must_use] pub fn return_int() -> MustUseInt; } @@ -10,17 +10,17 @@ extern "C" { pub struct MustUseStruct { _unused: [u8; 0], } -extern "C" { +unsafe extern "C" { #[must_use] pub fn return_struct() -> MustUseStruct; } ///
pub type AnnotatedInt = ::std::os::raw::c_int; -extern "C" { +unsafe extern "C" { #[must_use] pub fn return_annotated_int() -> AnnotatedInt; } -extern "C" { +unsafe extern "C" { pub fn return_plain_int() -> ::std::os::raw::c_int; } ///
@@ -33,7 +33,7 @@ const _: () = { ["Size of AnnotatedStruct"][::std::mem::size_of::() - 0usize]; ["Alignment of AnnotatedStruct"][::std::mem::align_of::() - 1usize]; }; -extern "C" { +unsafe extern "C" { #[must_use] pub fn return_annotated_struct() -> AnnotatedStruct; } @@ -47,10 +47,10 @@ const _: () = { }; ///
pub type TypedefPlainStruct = PlainStruct; -extern "C" { +unsafe extern "C" { pub fn return_plain_struct() -> PlainStruct; } -extern "C" { +unsafe extern "C" { #[must_use] pub fn return_typedef_struct() -> TypedefPlainStruct; } diff --git a/bindgen-tests/tests/expectations/tests/func_with_array_arg.rs b/bindgen-tests/tests/expectations/tests/func_with_array_arg.rs index e41cb2ce44..20bdc4ac27 100644 --- a/bindgen-tests/tests/expectations/tests/func_with_array_arg.rs +++ b/bindgen-tests/tests/expectations/tests/func_with_array_arg.rs @@ -1,4 +1,4 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern "C" { +unsafe extern "C" { pub fn f(x: *mut ::std::os::raw::c_int); } diff --git a/bindgen-tests/tests/expectations/tests/func_with_func_ptr_arg.rs b/bindgen-tests/tests/expectations/tests/func_with_func_ptr_arg.rs index af8a3fc68c..56cf40fb59 100644 --- a/bindgen-tests/tests/expectations/tests/func_with_func_ptr_arg.rs +++ b/bindgen-tests/tests/expectations/tests/func_with_func_ptr_arg.rs @@ -1,8 +1,8 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern "C" { +unsafe extern "C" { pub fn foo(bar: ::std::option::Option); } -extern "C" { +unsafe extern "C" { pub fn bar( one: ::std::option::Option< unsafe extern "C" fn(a: ::std::os::raw::c_int, b: ::std::os::raw::c_int), diff --git a/bindgen-tests/tests/expectations/tests/gen-constructors.rs b/bindgen-tests/tests/expectations/tests/gen-constructors.rs index c1a8b676fd..80e6a25d70 100644 --- a/bindgen-tests/tests/expectations/tests/gen-constructors.rs +++ b/bindgen-tests/tests/expectations/tests/gen-constructors.rs @@ -9,7 +9,7 @@ const _: () = { ["Size of Foo"][::std::mem::size_of::() - 1usize]; ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; }; -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN3FooC1Ei"] pub fn Foo_Foo(this: *mut Foo, a: ::std::os::raw::c_int); } diff --git a/bindgen-tests/tests/expectations/tests/gen-destructors.rs b/bindgen-tests/tests/expectations/tests/gen-destructors.rs index f3dc655f08..c860c9985f 100644 --- a/bindgen-tests/tests/expectations/tests/gen-destructors.rs +++ b/bindgen-tests/tests/expectations/tests/gen-destructors.rs @@ -10,7 +10,7 @@ const _: () = { ["Alignment of Foo"][::std::mem::align_of::() - 4usize]; ["Offset of field: Foo::bar"][::std::mem::offset_of!(Foo, bar) - 0usize]; }; -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN3FooD1Ev"] pub fn Foo_Foo_destructor(this: *mut Foo); } diff --git a/bindgen-tests/tests/expectations/tests/generate-inline.rs b/bindgen-tests/tests/expectations/tests/generate-inline.rs index 1d60a98570..c100f3936c 100644 --- a/bindgen-tests/tests/expectations/tests/generate-inline.rs +++ b/bindgen-tests/tests/expectations/tests/generate-inline.rs @@ -9,7 +9,7 @@ const _: () = { ["Size of Foo"][::std::mem::size_of::() - 1usize]; ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; }; -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN3Foo3barEv"] pub fn Foo_bar() -> ::std::os::raw::c_int; } @@ -19,7 +19,7 @@ impl Foo { Foo_bar() } } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_Z3foov"] pub fn foo() -> ::std::os::raw::c_int; } diff --git a/bindgen-tests/tests/expectations/tests/inner-typedef-gh422.rs b/bindgen-tests/tests/expectations/tests/inner-typedef-gh422.rs index 69d2151bbb..16b1eb48ea 100644 --- a/bindgen-tests/tests/expectations/tests/inner-typedef-gh422.rs +++ b/bindgen-tests/tests/expectations/tests/inner-typedef-gh422.rs @@ -20,7 +20,7 @@ impl Default for Foo_InnerType { } } pub type Bar = InnerType; -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_Z4funcv"] pub fn func() -> Bar; } diff --git a/bindgen-tests/tests/expectations/tests/inner_const.rs b/bindgen-tests/tests/expectations/tests/inner_const.rs index f8f0c45a29..ad8af7ce35 100644 --- a/bindgen-tests/tests/expectations/tests/inner_const.rs +++ b/bindgen-tests/tests/expectations/tests/inner_const.rs @@ -4,11 +4,11 @@ pub struct Foo { pub bar: ::std::os::raw::c_int, } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN3Foo3BOOE"] pub static mut Foo_BOO: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN3Foo8whateverE"] pub static mut Foo_whatever: Foo; } diff --git a/bindgen-tests/tests/expectations/tests/issue-1118-using-forward-decl.rs b/bindgen-tests/tests/expectations/tests/issue-1118-using-forward-decl.rs index 7356aa679a..7df1cdb741 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1118-using-forward-decl.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1118-using-forward-decl.rs @@ -58,7 +58,7 @@ impl Default for nsIContent { } } } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_Z35Gecko_GetAnonymousContentForElementv"] pub fn Gecko_GetAnonymousContentForElement() -> *mut nsTArray; } diff --git a/bindgen-tests/tests/expectations/tests/issue-1216-variadic-member.rs b/bindgen-tests/tests/expectations/tests/issue-1216-variadic-member.rs index e3fe803654..7c562437e4 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1216-variadic-member.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1216-variadic-member.rs @@ -1,5 +1,5 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern "C" { +unsafe extern "C" { pub fn f(a: ::std::os::raw::c_int, ...); } #[repr(C)] diff --git a/bindgen-tests/tests/expectations/tests/issue-1350-attribute-overloadable.rs b/bindgen-tests/tests/expectations/tests/issue-1350-attribute-overloadable.rs index 908ccfbc2e..c033570793 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1350-attribute-overloadable.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1350-attribute-overloadable.rs @@ -1,9 +1,9 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_Z11my_functioni"] pub fn my_function(a: ::std::os::raw::c_int); } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_Z11my_functionPKc"] pub fn my_function1(a: *const ::std::os::raw::c_char); } diff --git a/bindgen-tests/tests/expectations/tests/issue-1375-prefixed-functions.rs b/bindgen-tests/tests/expectations/tests/issue-1375-prefixed-functions.rs index 2e9a594a31..f5e231ea96 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1375-prefixed-functions.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1375-prefixed-functions.rs @@ -1,13 +1,13 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}my_custom_prefix_var_const_name"] pub static var_const_name: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}my_custom_prefix_var_mut_name"] pub static mut var_mut_name: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}my_custom_prefix_function_name"] pub fn function_name(x: ::std::os::raw::c_int); } diff --git a/bindgen-tests/tests/expectations/tests/issue-1435.rs b/bindgen-tests/tests/expectations/tests/issue-1435.rs index 3040c1451e..7b9bfe8422 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1435.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1435.rs @@ -11,7 +11,7 @@ pub mod root { pub type AB = ::std::os::raw::c_int; } pub use self::super::root::ns::AB as AB; - extern "C" { + unsafe extern "C" { #[link_name = "\u{1}_ZL2kA"] pub static kA: root::AB; } diff --git a/bindgen-tests/tests/expectations/tests/issue-2019.rs b/bindgen-tests/tests/expectations/tests/issue-2019.rs index 88921d615a..4c91cf9972 100644 --- a/bindgen-tests/tests/expectations/tests/issue-2019.rs +++ b/bindgen-tests/tests/expectations/tests/issue-2019.rs @@ -10,7 +10,7 @@ const _: () = { ["Alignment of A"][::std::mem::align_of::
() - 4usize]; ["Offset of field: A::a"][::std::mem::offset_of!(A, a) - 0usize]; }; -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN1A4makeEv"] pub fn make() -> A; } @@ -31,7 +31,7 @@ const _: () = { ["Alignment of B"][::std::mem::align_of::() - 4usize]; ["Offset of field: B::b"][::std::mem::offset_of!(B, b) - 0usize]; }; -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN1B4makeEv"] pub fn make1() -> B; } diff --git a/bindgen-tests/tests/expectations/tests/issue-2556.rs b/bindgen-tests/tests/expectations/tests/issue-2556.rs index 5f7c1d369a..92fe5026b8 100644 --- a/bindgen-tests/tests/expectations/tests/issue-2556.rs +++ b/bindgen-tests/tests/expectations/tests/issue-2556.rs @@ -23,7 +23,7 @@ pub mod root { pub mod foo { #[allow(unused_imports)] use self::super::super::root; - extern "C" { + unsafe extern "C" { #[link_name = "\u{1}_ZN3fooL22kFallbackIntrinsicSizeE"] pub static kFallbackIntrinsicSize: root::nsSize; } diff --git a/bindgen-tests/tests/expectations/tests/issue-410.rs b/bindgen-tests/tests/expectations/tests/issue-410.rs index e52aa25a13..cda9b6e338 100644 --- a/bindgen-tests/tests/expectations/tests/issue-410.rs +++ b/bindgen-tests/tests/expectations/tests/issue-410.rs @@ -16,7 +16,7 @@ pub mod root { ["Size of Value"][::std::mem::size_of::() - 1usize]; ["Alignment of Value"][::std::mem::align_of::() - 1usize]; }; - extern "C" { + unsafe extern "C" { #[link_name = "\u{1}_ZN2JS5Value1aE10JSWhyMagic"] pub fn Value_a(this: *mut root::JS::Value, arg1: root::JSWhyMagic); } diff --git a/bindgen-tests/tests/expectations/tests/issue-447.rs b/bindgen-tests/tests/expectations/tests/issue-447.rs index 305fa739d0..8867a359a2 100644 --- a/bindgen-tests/tests/expectations/tests/issue-447.rs +++ b/bindgen-tests/tests/expectations/tests/issue-447.rs @@ -39,7 +39,7 @@ pub mod root { "Alignment of JSAutoCompartment", ][::std::mem::align_of::() - 1usize]; }; - extern "C" { + unsafe extern "C" { #[link_name = "\u{1}_ZN17JSAutoCompartmentC1EN7mozilla6detail19GuardObjectNotifierE"] pub fn JSAutoCompartment_JSAutoCompartment( this: *mut root::JSAutoCompartment, diff --git a/bindgen-tests/tests/expectations/tests/issue-511.rs b/bindgen-tests/tests/expectations/tests/issue-511.rs index e2bb991946..9d26b334c3 100644 --- a/bindgen-tests/tests/expectations/tests/issue-511.rs +++ b/bindgen-tests/tests/expectations/tests/issue-511.rs @@ -1,13 +1,13 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern "C" { +unsafe extern "C" { pub static mut a: *mut ::std::os::raw::c_char; } -extern "C" { +unsafe extern "C" { pub static mut b: *const ::std::os::raw::c_char; } -extern "C" { +unsafe extern "C" { pub static c: *mut ::std::os::raw::c_char; } -extern "C" { +unsafe extern "C" { pub static d: *const ::std::os::raw::c_char; } diff --git a/bindgen-tests/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs b/bindgen-tests/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs index 85f66c5a73..9968501397 100644 --- a/bindgen-tests/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs +++ b/bindgen-tests/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs @@ -17,7 +17,7 @@ const _: () = { "Offset of field: _bindgen_ty_1::ar", ][::std::mem::offset_of!(_bindgen_ty_1, ar) - 0usize]; }; -extern "C" { +unsafe extern "C" { pub static mut AutoIdVector: _bindgen_ty_1; } #[allow(clippy::unnecessary_operation, clippy::identity_op)] diff --git a/bindgen-tests/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs b/bindgen-tests/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs index e53b10d4af..2a85837e3d 100644 --- a/bindgen-tests/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs +++ b/bindgen-tests/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs @@ -67,7 +67,7 @@ impl Default for b { } } } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_Z25Servo_Element_GetSnapshotv"] pub fn Servo_Element_GetSnapshot() -> A; } diff --git a/bindgen-tests/tests/expectations/tests/issue-654-struct-fn-collision.rs b/bindgen-tests/tests/expectations/tests/issue-654-struct-fn-collision.rs index 289dac9a1c..6bf02be74e 100644 --- a/bindgen-tests/tests/expectations/tests/issue-654-struct-fn-collision.rs +++ b/bindgen-tests/tests/expectations/tests/issue-654-struct-fn-collision.rs @@ -4,6 +4,6 @@ pub struct foo { _unused: [u8; 0], } -extern "C" { +unsafe extern "C" { pub fn foo() -> ::std::os::raw::c_int; } diff --git a/bindgen-tests/tests/expectations/tests/issue-801-opaque-sloppiness.rs b/bindgen-tests/tests/expectations/tests/issue-801-opaque-sloppiness.rs index b08ef2fd1d..90eb048640 100644 --- a/bindgen-tests/tests/expectations/tests/issue-801-opaque-sloppiness.rs +++ b/bindgen-tests/tests/expectations/tests/issue-801-opaque-sloppiness.rs @@ -15,7 +15,7 @@ const _: () = { ["Size of B"][::std::mem::size_of::() - 1usize]; ["Alignment of B"][::std::mem::align_of::() - 1usize]; }; -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN1B1aE"] pub static mut B_a: A; } diff --git a/bindgen-tests/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs b/bindgen-tests/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs index c0150a73f0..3d3ee5e590 100644 --- a/bindgen-tests/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs +++ b/bindgen-tests/tests/expectations/tests/issue-807-opaque-types-methods-being-generated.rs @@ -40,11 +40,11 @@ const _: () = { ["Size of Opaque"][::std::mem::size_of::() - 1usize]; ["Alignment of Opaque"][::std::mem::align_of::() - 1usize]; }; -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN6Opaque17eleven_out_of_tenEv"] pub fn Opaque_eleven_out_of_ten(this: *mut Opaque) -> SuchWow; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN6OpaqueC1E6Pupper"] pub fn Opaque_Opaque(this: *mut Opaque, pup: Pupper); } @@ -60,7 +60,7 @@ impl Opaque { __bindgen_tmp.assume_init() } } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN6Opaque11MAJESTIC_AFE"] pub static mut Opaque_MAJESTIC_AF: Doggo; } diff --git a/bindgen-tests/tests/expectations/tests/issue-833-1.rs b/bindgen-tests/tests/expectations/tests/issue-833-1.rs index b86a4e0df3..5aa8c3078b 100644 --- a/bindgen-tests/tests/expectations/tests/issue-833-1.rs +++ b/bindgen-tests/tests/expectations/tests/issue-833-1.rs @@ -3,6 +3,6 @@ pub struct nsTArray { pub hdr: *const (), } -extern "C" { +unsafe extern "C" { pub fn func() -> *mut nsTArray; } diff --git a/bindgen-tests/tests/expectations/tests/issue-833.rs b/bindgen-tests/tests/expectations/tests/issue-833.rs index 2a2d375e89..9698fdb479 100644 --- a/bindgen-tests/tests/expectations/tests/issue-833.rs +++ b/bindgen-tests/tests/expectations/tests/issue-833.rs @@ -3,6 +3,6 @@ pub struct nsTArray { pub hdr: *const T, } -extern "C" { +unsafe extern "C" { pub fn func() -> *mut nsTArray<::std::os::raw::c_int>; } diff --git a/bindgen-tests/tests/expectations/tests/issue-848-replacement-system-include.rs b/bindgen-tests/tests/expectations/tests/issue-848-replacement-system-include.rs index d224612ba9..6beeae69d8 100644 --- a/bindgen-tests/tests/expectations/tests/issue-848-replacement-system-include.rs +++ b/bindgen-tests/tests/expectations/tests/issue-848-replacement-system-include.rs @@ -20,6 +20,6 @@ impl Default for nsTArray { } } } -extern "C" { +unsafe extern "C" { pub fn func() -> *mut nsTArray<::std::os::raw::c_int>; } diff --git a/bindgen-tests/tests/expectations/tests/issue-888-enum-var-decl-jump.rs b/bindgen-tests/tests/expectations/tests/issue-888-enum-var-decl-jump.rs index 0a0d05f9f9..023c8695e3 100644 --- a/bindgen-tests/tests/expectations/tests/issue-888-enum-var-decl-jump.rs +++ b/bindgen-tests/tests/expectations/tests/issue-888-enum-var-decl-jump.rs @@ -11,7 +11,7 @@ pub mod root { pub struct Type { pub _address: u8, } - extern "C" { + unsafe extern "C" { #[link_name = "\u{1}_ZN6Halide4Type1bE"] pub static mut Type_b: root::a; } diff --git a/bindgen-tests/tests/expectations/tests/keywords.rs b/bindgen-tests/tests/expectations/tests/keywords.rs index d07f241376..ec56bbfa8b 100644 --- a/bindgen-tests/tests/expectations/tests/keywords.rs +++ b/bindgen-tests/tests/expectations/tests/keywords.rs @@ -1,221 +1,221 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}u8"] pub static mut u8_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}u16"] pub static mut u16_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}u32"] pub static mut u32_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}u64"] pub static mut u64_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}i8"] pub static mut i8_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}i16"] pub static mut i16_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}i32"] pub static mut i32_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}i64"] pub static mut i64_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}f32"] pub static mut f32_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}f64"] pub static mut f64_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}usize"] pub static mut usize_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}isize"] pub static mut isize_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}bool"] pub static mut bool_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}str"] pub static mut str_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}dyn"] pub static mut dyn_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}as"] pub static mut as_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}async"] pub static mut async_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}await"] pub static mut await_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}box"] pub static mut box_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}crate"] pub static mut crate_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}false"] pub static mut false_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}fn"] pub static mut fn_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}impl"] pub static mut impl_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}in"] pub static mut in_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}let"] pub static mut let_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}loop"] pub static mut loop_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}match"] pub static mut match_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}mod"] pub static mut mod_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}move"] pub static mut move_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}mut"] pub static mut mut_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}pub"] pub static mut pub_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}ref"] pub static mut ref_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}self"] pub static mut self_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}Self"] pub static mut Self_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}super"] pub static mut super_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}trait"] pub static mut trait_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}true"] pub static mut true_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}try"] pub static mut try_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}type"] pub static mut type_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}unsafe"] pub static mut unsafe_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}use"] pub static mut use_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}where"] pub static mut where_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}abstract"] pub static mut abstract_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}alignof"] pub static mut alignof_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}become"] pub static mut become_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}final"] pub static mut final_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}macro"] pub static mut macro_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}offsetof"] pub static mut offsetof_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}override"] pub static mut override_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}priv"] pub static mut priv_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}proc"] pub static mut proc_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}pure"] pub static mut pure_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}unsized"] pub static mut unsized_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}virtual"] pub static mut virtual_: ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}yield"] pub static mut yield_: ::std::os::raw::c_int; } diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/atomic-constant.rs b/bindgen-tests/tests/expectations/tests/libclang-9/atomic-constant.rs index ce12eaad3a..098beb43de 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/atomic-constant.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/atomic-constant.rs @@ -1,4 +1,4 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern "C" { +unsafe extern "C" { pub static mut b: ::std::os::raw::c_int; } diff --git a/bindgen-tests/tests/expectations/tests/macro-expr-uncommon-token.rs b/bindgen-tests/tests/expectations/tests/macro-expr-uncommon-token.rs index c905e5aa90..785ef4bb9f 100644 --- a/bindgen-tests/tests/expectations/tests/macro-expr-uncommon-token.rs +++ b/bindgen-tests/tests/expectations/tests/macro-expr-uncommon-token.rs @@ -1,5 +1,5 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const MODBUS_WOOT: u32 = 3; -extern "C" { +unsafe extern "C" { pub fn foo(); } diff --git a/bindgen-tests/tests/expectations/tests/mangling-ios.rs b/bindgen-tests/tests/expectations/tests/mangling-ios.rs index 05b7aecd3e..736d379f01 100644 --- a/bindgen-tests/tests/expectations/tests/mangling-ios.rs +++ b/bindgen-tests/tests/expectations/tests/mangling-ios.rs @@ -1,4 +1,4 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern "C" { +unsafe extern "C" { pub fn foo(); } diff --git a/bindgen-tests/tests/expectations/tests/mangling-linux32.rs b/bindgen-tests/tests/expectations/tests/mangling-linux32.rs index ab1f799694..b6ed9146da 100644 --- a/bindgen-tests/tests/expectations/tests/mangling-linux32.rs +++ b/bindgen-tests/tests/expectations/tests/mangling-linux32.rs @@ -1,5 +1,5 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern "C" { +unsafe extern "C" { pub fn foo(); } #[repr(C)] @@ -7,7 +7,7 @@ extern "C" { pub struct Foo { pub _address: u8, } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN3Foo4sBarE"] pub static mut Foo_sBar: bool; } diff --git a/bindgen-tests/tests/expectations/tests/mangling-linux64.rs b/bindgen-tests/tests/expectations/tests/mangling-linux64.rs index ab1f799694..b6ed9146da 100644 --- a/bindgen-tests/tests/expectations/tests/mangling-linux64.rs +++ b/bindgen-tests/tests/expectations/tests/mangling-linux64.rs @@ -1,5 +1,5 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern "C" { +unsafe extern "C" { pub fn foo(); } #[repr(C)] @@ -7,7 +7,7 @@ extern "C" { pub struct Foo { pub _address: u8, } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN3Foo4sBarE"] pub static mut Foo_sBar: bool; } diff --git a/bindgen-tests/tests/expectations/tests/mangling-macos.rs b/bindgen-tests/tests/expectations/tests/mangling-macos.rs index b5d78cedb5..237859e23b 100644 --- a/bindgen-tests/tests/expectations/tests/mangling-macos.rs +++ b/bindgen-tests/tests/expectations/tests/mangling-macos.rs @@ -1,5 +1,5 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern "C" { +unsafe extern "C" { pub fn foo(); } #[repr(C)] @@ -7,7 +7,7 @@ extern "C" { pub struct Foo { pub _address: u8, } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}__ZN3Foo4sBarE"] pub static mut Foo_sBar: bool; } diff --git a/bindgen-tests/tests/expectations/tests/mangling-win32.rs b/bindgen-tests/tests/expectations/tests/mangling-win32.rs index 572b69962c..3a2f95bf70 100644 --- a/bindgen-tests/tests/expectations/tests/mangling-win32.rs +++ b/bindgen-tests/tests/expectations/tests/mangling-win32.rs @@ -1,5 +1,5 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern "C" { +unsafe extern "C" { pub fn foo(); } #[repr(C)] @@ -7,7 +7,7 @@ extern "C" { pub struct Foo { pub _address: u8, } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}?sBar@Foo@@2_NA"] pub static mut Foo_sBar: bool; } @@ -16,20 +16,20 @@ const _: () = { ["Size of Foo"][::std::mem::size_of::() - 1usize]; ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; }; -extern "fastcall" { +unsafe extern "fastcall" { pub fn fast_call_func_no_args() -> ::std::os::raw::c_int; } -extern "fastcall" { +unsafe extern "fastcall" { pub fn fast_call_func_many_args( arg1: ::std::os::raw::c_int, arg2: ::std::os::raw::c_int, arg3: ::std::os::raw::c_int, ) -> ::std::os::raw::c_int; } -extern "stdcall" { +unsafe extern "stdcall" { pub fn std_call_func_no_args() -> ::std::os::raw::c_int; } -extern "stdcall" { +unsafe extern "stdcall" { pub fn std_call_func_many_args( arg1: ::std::os::raw::c_int, arg2: ::std::os::raw::c_int, diff --git a/bindgen-tests/tests/expectations/tests/mangling-win64.rs b/bindgen-tests/tests/expectations/tests/mangling-win64.rs index 1e71710f6c..2a782480ed 100644 --- a/bindgen-tests/tests/expectations/tests/mangling-win64.rs +++ b/bindgen-tests/tests/expectations/tests/mangling-win64.rs @@ -1,5 +1,5 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern "C" { +unsafe extern "C" { pub fn foo(); } #[repr(C)] @@ -7,7 +7,7 @@ extern "C" { pub struct Foo { pub _address: u8, } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}?sBar@Foo@@2_NA"] pub static mut Foo_sBar: bool; } diff --git a/bindgen-tests/tests/expectations/tests/merge-extern-blocks.rs b/bindgen-tests/tests/expectations/tests/merge-extern-blocks.rs deleted file mode 100644 index 595d865af1..0000000000 --- a/bindgen-tests/tests/expectations/tests/merge-extern-blocks.rs +++ /dev/null @@ -1,44 +0,0 @@ -#![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 { - #[allow(unused_imports)] - use self::super::root; - #[repr(C)] - #[derive(Debug, Default, Copy, Clone)] - pub struct Point { - pub x: ::std::os::raw::c_int, - } - #[allow(clippy::unnecessary_operation, clippy::identity_op)] - const _: () = { - ["Size of Point"][::std::mem::size_of::() - 4usize]; - ["Alignment of Point"][::std::mem::align_of::() - 4usize]; - ["Offset of field: Point::x"][::std::mem::offset_of!(Point, x) - 0usize]; - }; - pub mod ns { - #[allow(unused_imports)] - use self::super::super::root; - #[repr(C)] - #[derive(Debug, Default, Copy, Clone)] - pub struct Point { - pub x: ::std::os::raw::c_int, - } - #[allow(clippy::unnecessary_operation, clippy::identity_op)] - const _: () = { - ["Size of Point"][::std::mem::size_of::() - 4usize]; - ["Alignment of Point"][::std::mem::align_of::() - 4usize]; - ["Offset of field: Point::x"][::std::mem::offset_of!(Point, x) - 0usize]; - }; - extern "C" { - #[link_name = "\u{1}_ZN2ns3fooEv"] - pub fn foo() -> ::std::os::raw::c_int; - #[link_name = "\u{1}_ZN2ns3barEv"] - pub fn bar() -> ::std::os::raw::c_int; - } - } - extern "C" { - #[link_name = "\u{1}_Z3foov"] - pub fn foo() -> ::std::os::raw::c_int; - #[link_name = "\u{1}_Z3barv"] - pub fn bar() -> ::std::os::raw::c_int; - } -} diff --git a/bindgen-tests/tests/expectations/tests/method-mangling.rs b/bindgen-tests/tests/expectations/tests/method-mangling.rs index bde0a0f2ff..4c86825cce 100644 --- a/bindgen-tests/tests/expectations/tests/method-mangling.rs +++ b/bindgen-tests/tests/expectations/tests/method-mangling.rs @@ -9,7 +9,7 @@ const _: () = { ["Size of Foo"][::std::mem::size_of::() - 1usize]; ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; }; -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN3Foo4typeEv"] pub fn Foo_type(this: *mut Foo) -> ::std::os::raw::c_int; } diff --git a/bindgen-tests/tests/expectations/tests/namespace.rs b/bindgen-tests/tests/expectations/tests/namespace.rs index f4f2a76c3e..4e58fa7ab1 100644 --- a/bindgen-tests/tests/expectations/tests/namespace.rs +++ b/bindgen-tests/tests/expectations/tests/namespace.rs @@ -3,7 +3,7 @@ pub mod root { #[allow(unused_imports)] use self::super::root; - extern "C" { + unsafe extern "C" { #[link_name = "\u{1}_Z9top_levelv"] pub fn top_level(); } @@ -12,7 +12,7 @@ pub mod root { use self::super::super::root; pub type whatever_other_thing_t = whatever_int_t; pub type whatever_int_t = ::std::os::raw::c_int; - extern "C" { + unsafe extern "C" { #[link_name = "\u{1}_ZN8whatever11in_whateverEv"] pub fn in_whatever(); } @@ -69,15 +69,15 @@ pub mod root { } } } - extern "C" { + unsafe extern "C" { #[link_name = "\u{1}_ZN1w3hehEv"] pub fn heh() -> root::w::whatever_int_t; } - extern "C" { + unsafe extern "C" { #[link_name = "\u{1}_ZN1w3fooEv"] pub fn foo() -> root::C<::std::os::raw::c_int>; } - extern "C" { + unsafe extern "C" { #[link_name = "\u{1}_ZN1w4barrEv"] pub fn barr() -> root::C; } @@ -85,7 +85,7 @@ pub mod root { pub mod foobar { #[allow(unused_imports)] use self::super::super::root; - extern "C" { + unsafe extern "C" { #[link_name = "\u{1}_ZN6foobar3fooEv"] pub fn foo(); } @@ -93,7 +93,7 @@ pub mod root { pub mod faraway { #[allow(unused_imports)] use self::super::super::root; - extern "C" { + unsafe extern "C" { #[link_name = "\u{1}_ZN7faraway3barEv"] pub fn bar(); } diff --git a/bindgen-tests/tests/expectations/tests/nested_vtable.rs b/bindgen-tests/tests/expectations/tests/nested_vtable.rs index 6356f9efd1..12aa2ea441 100644 --- a/bindgen-tests/tests/expectations/tests/nested_vtable.rs +++ b/bindgen-tests/tests/expectations/tests/nested_vtable.rs @@ -24,7 +24,7 @@ impl Default for nsISupports { } } } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN11nsISupports14QueryInterfaceEv"] pub fn nsISupports_QueryInterface( this: *mut ::std::os::raw::c_void, diff --git a/bindgen-tests/tests/expectations/tests/noreturn.rs b/bindgen-tests/tests/expectations/tests/noreturn.rs index 2081d3d44b..0e601b5510 100644 --- a/bindgen-tests/tests/expectations/tests/noreturn.rs +++ b/bindgen-tests/tests/expectations/tests/noreturn.rs @@ -1,21 +1,21 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_Z1fv"] pub fn f() -> !; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_Z1gv"] pub fn g() -> !; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_Z1hv"] pub fn h() -> !; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_Z1iPFvvE"] pub fn i(arg: ::std::option::Option !>); } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_Z1jPFvvE"] pub fn j(arg: ::std::option::Option !>) -> !; } diff --git a/bindgen-tests/tests/expectations/tests/objc_class.rs b/bindgen-tests/tests/expectations/tests/objc_class.rs index 50bdea53ee..a7346d1ee9 100644 --- a/bindgen-tests/tests/expectations/tests/objc_class.rs +++ b/bindgen-tests/tests/expectations/tests/objc_class.rs @@ -3,7 +3,7 @@ use objc::{self, msg_send, sel, sel_impl, class}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; -extern "C" { +unsafe extern "C" { pub static mut fooVar: Foo; } #[repr(transparent)] diff --git a/bindgen-tests/tests/expectations/tests/objc_interface_type.rs b/bindgen-tests/tests/expectations/tests/objc_interface_type.rs index 66c65be2d7..56ad75ed25 100644 --- a/bindgen-tests/tests/expectations/tests/objc_interface_type.rs +++ b/bindgen-tests/tests/expectations/tests/objc_interface_type.rs @@ -40,9 +40,9 @@ impl Default for FooStruct { } } } -extern "C" { +unsafe extern "C" { pub fn fooFunc(foo: Foo); } -extern "C" { +unsafe extern "C" { pub static mut kFoo: Foo; } diff --git a/bindgen-tests/tests/expectations/tests/objc_sel_and_id.rs b/bindgen-tests/tests/expectations/tests/objc_sel_and_id.rs index 25854d8488..cf38af4e64 100644 --- a/bindgen-tests/tests/expectations/tests/objc_sel_and_id.rs +++ b/bindgen-tests/tests/expectations/tests/objc_sel_and_id.rs @@ -3,12 +3,12 @@ use objc::{self, msg_send, sel, sel_impl, class}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; -extern "C" { +unsafe extern "C" { pub static mut object: id; } -extern "C" { +unsafe extern "C" { pub static mut selector: objc::runtime::Sel; } -extern "C" { +unsafe extern "C" { pub fn f(object: id, selector: objc::runtime::Sel); } diff --git a/bindgen-tests/tests/expectations/tests/opaque-tracing.rs b/bindgen-tests/tests/expectations/tests/opaque-tracing.rs index c181dc90d6..60d249a88c 100644 --- a/bindgen-tests/tests/expectations/tests/opaque-tracing.rs +++ b/bindgen-tests/tests/expectations/tests/opaque-tracing.rs @@ -1,5 +1,5 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_Z3fooP9Container"] pub fn foo(c: *mut Container); } diff --git a/bindgen-tests/tests/expectations/tests/operator.rs b/bindgen-tests/tests/expectations/tests/operator.rs index fa018724fc..ce5a652d8d 100644 --- a/bindgen-tests/tests/expectations/tests/operator.rs +++ b/bindgen-tests/tests/expectations/tests/operator.rs @@ -1,5 +1,5 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_Z20operator_informationv"] pub fn operator_information() -> ::std::os::raw::c_int; } diff --git a/bindgen-tests/tests/expectations/tests/overloading.rs b/bindgen-tests/tests/expectations/tests/overloading.rs index 3e8fced8e7..96504b38eb 100644 --- a/bindgen-tests/tests/expectations/tests/overloading.rs +++ b/bindgen-tests/tests/expectations/tests/overloading.rs @@ -1,17 +1,17 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_Z8Evaluatec"] pub fn Evaluate(r: ::std::os::raw::c_char) -> bool; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_Z8Evaluateii"] pub fn Evaluate1(x: ::std::os::raw::c_int, y: ::std::os::raw::c_int) -> bool; } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN3foo10MyFunctionEv"] pub fn foo_MyFunction(); } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN3bar10MyFunctionEv"] pub fn bar_MyFunction(); } diff --git a/bindgen-tests/tests/expectations/tests/parm-union.rs b/bindgen-tests/tests/expectations/tests/parm-union.rs index 9c4f2f4e25..6dee4ec7d5 100644 --- a/bindgen-tests/tests/expectations/tests/parm-union.rs +++ b/bindgen-tests/tests/expectations/tests/parm-union.rs @@ -9,7 +9,7 @@ const _: () = { ["Size of Struct"][::std::mem::size_of::() - 1usize]; ["Alignment of Struct"][::std::mem::align_of::() - 1usize]; }; -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN6Struct8FunctionER5Union"] pub fn Struct_Function(this: *mut Struct, arg1: *mut Union); } diff --git a/bindgen-tests/tests/expectations/tests/partial-specialization-and-inheritance.rs b/bindgen-tests/tests/expectations/tests/partial-specialization-and-inheritance.rs index cd22cce4ea..a4234d2aaa 100644 --- a/bindgen-tests/tests/expectations/tests/partial-specialization-and-inheritance.rs +++ b/bindgen-tests/tests/expectations/tests/partial-specialization-and-inheritance.rs @@ -24,7 +24,7 @@ pub struct Derived { pub struct Usage { pub _address: u8, } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN5Usage13static_memberE"] pub static mut Usage_static_member: __BindgenOpaqueArray; } diff --git a/bindgen-tests/tests/expectations/tests/pointer-attr.rs b/bindgen-tests/tests/expectations/tests/pointer-attr.rs index edb29dc499..4d7e250b9c 100644 --- a/bindgen-tests/tests/expectations/tests/pointer-attr.rs +++ b/bindgen-tests/tests/expectations/tests/pointer-attr.rs @@ -1,4 +1,4 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern "C" { +unsafe extern "C" { pub fn a(arg1: *const ::std::os::raw::c_char); } diff --git a/bindgen-tests/tests/expectations/tests/prefix-link-name-c.rs b/bindgen-tests/tests/expectations/tests/prefix-link-name-c.rs index e81a3b667d..cb1ebfa4f7 100644 --- a/bindgen-tests/tests/expectations/tests/prefix-link-name-c.rs +++ b/bindgen-tests/tests/expectations/tests/prefix-link-name-c.rs @@ -1,5 +1,5 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}foo_bar"] pub fn bar() -> ::std::os::raw::c_int; } diff --git a/bindgen-tests/tests/expectations/tests/prefix-link-name-cpp.rs b/bindgen-tests/tests/expectations/tests/prefix-link-name-cpp.rs index bf53473d88..07cacc5f7a 100644 --- a/bindgen-tests/tests/expectations/tests/prefix-link-name-cpp.rs +++ b/bindgen-tests/tests/expectations/tests/prefix-link-name-cpp.rs @@ -1,5 +1,5 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}foo_foo"] pub fn baz_foo() -> ::std::os::raw::c_int; } diff --git a/bindgen-tests/tests/expectations/tests/public-dtor.rs b/bindgen-tests/tests/expectations/tests/public-dtor.rs index c271125097..578d3e76a5 100644 --- a/bindgen-tests/tests/expectations/tests/public-dtor.rs +++ b/bindgen-tests/tests/expectations/tests/public-dtor.rs @@ -9,7 +9,7 @@ const _: () = { ["Size of cv_Foo"][::std::mem::size_of::() - 1usize]; ["Alignment of cv_Foo"][::std::mem::align_of::() - 1usize]; }; -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN2cv3FooD1Ev"] pub fn cv_Foo_Foo_destructor(this: *mut cv_Foo); } diff --git a/bindgen-tests/tests/expectations/tests/redeclaration.rs b/bindgen-tests/tests/expectations/tests/redeclaration.rs index 05b7aecd3e..736d379f01 100644 --- a/bindgen-tests/tests/expectations/tests/redeclaration.rs +++ b/bindgen-tests/tests/expectations/tests/redeclaration.rs @@ -1,4 +1,4 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern "C" { +unsafe extern "C" { pub fn foo(); } diff --git a/bindgen-tests/tests/expectations/tests/ref_argument_array.rs b/bindgen-tests/tests/expectations/tests/ref_argument_array.rs index de5f81c3c0..4928a185fe 100644 --- a/bindgen-tests/tests/expectations/tests/ref_argument_array.rs +++ b/bindgen-tests/tests/expectations/tests/ref_argument_array.rs @@ -26,7 +26,7 @@ impl Default for nsID { } } } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN4nsID16ToProvidedStringERA10_c"] pub fn nsID_ToProvidedString( this: *mut ::std::os::raw::c_void, diff --git a/bindgen-tests/tests/expectations/tests/resolved_type_def_function.rs b/bindgen-tests/tests/expectations/tests/resolved_type_def_function.rs index 8fe7eb7da2..cfbab6b968 100644 --- a/bindgen-tests/tests/expectations/tests/resolved_type_def_function.rs +++ b/bindgen-tests/tests/expectations/tests/resolved_type_def_function.rs @@ -1,5 +1,5 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type FuncType = ::std::option::Option; -extern "C" { +unsafe extern "C" { pub fn Func(); } diff --git a/bindgen-tests/tests/expectations/tests/sorted_items.rs b/bindgen-tests/tests/expectations/tests/sorted_items.rs index 5f1505bd86..1c235fb31d 100644 --- a/bindgen-tests/tests/expectations/tests/sorted_items.rs +++ b/bindgen-tests/tests/expectations/tests/sorted_items.rs @@ -60,30 +60,30 @@ pub mod root { pub const NUMBER: root::ns::number = 42; #[allow(unused_imports)] use self::super::super::root; - extern "C" { + unsafe extern "C" { #[link_name = "\u{1}_ZN2ns3fooEv"] pub fn foo() -> ::std::os::raw::c_int; } - extern "C" { + unsafe extern "C" { #[link_name = "\u{1}_ZN2ns3barEi"] pub fn bar(x: root::ns::number) -> ::std::os::raw::c_int; } - extern "C" { + unsafe extern "C" { #[link_name = "\u{1}_ZN2ns3bazENS_5PointE"] pub fn baz(point: root::ns::Point) -> ::std::os::raw::c_int; } } #[allow(unused_imports)] use self::super::root; - extern "C" { + unsafe extern "C" { #[link_name = "\u{1}_Z3foov"] pub fn foo() -> ::std::os::raw::c_int; } - extern "C" { + unsafe extern "C" { #[link_name = "\u{1}_Z3bari"] pub fn bar(x: root::number) -> ::std::os::raw::c_int; } - extern "C" { + unsafe extern "C" { #[link_name = "\u{1}_Z3baz5Point"] pub fn baz(point: root::Point) -> ::std::os::raw::c_int; } diff --git a/bindgen-tests/tests/expectations/tests/stdint_typedef.rs b/bindgen-tests/tests/expectations/tests/stdint_typedef.rs index 8594727dfa..7cb1a2a8fb 100644 --- a/bindgen-tests/tests/expectations/tests/stdint_typedef.rs +++ b/bindgen-tests/tests/expectations/tests/stdint_typedef.rs @@ -1,5 +1,5 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern "C" { +unsafe extern "C" { pub fn fun() -> u64; } #[repr(C)] diff --git a/bindgen-tests/tests/expectations/tests/template.rs b/bindgen-tests/tests/expectations/tests/template.rs index aa2a7753e2..94678cb49e 100644 --- a/bindgen-tests/tests/expectations/tests/template.rs +++ b/bindgen-tests/tests/expectations/tests/template.rs @@ -31,7 +31,7 @@ impl Default for B { } } } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_Z3bar3FooIiiE"] pub fn bar(foo: Foo<::std::os::raw::c_int>); } diff --git a/bindgen-tests/tests/expectations/tests/template_instantiation_with_fn_local_type.rs b/bindgen-tests/tests/expectations/tests/template_instantiation_with_fn_local_type.rs index 0bf9cc6d82..085278e603 100644 --- a/bindgen-tests/tests/expectations/tests/template_instantiation_with_fn_local_type.rs +++ b/bindgen-tests/tests/expectations/tests/template_instantiation_with_fn_local_type.rs @@ -4,7 +4,7 @@ pub struct Foo { pub _address: u8, } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_Z1fv"] pub fn f(); } diff --git a/bindgen-tests/tests/expectations/tests/test_mixed_header_and_header_contents.rs b/bindgen-tests/tests/expectations/tests/test_mixed_header_and_header_contents.rs index a2910b9b24..e1872623bc 100644 --- a/bindgen-tests/tests/expectations/tests/test_mixed_header_and_header_contents.rs +++ b/bindgen-tests/tests/expectations/tests/test_mixed_header_and_header_contents.rs @@ -1,4 +1,4 @@ -extern "C" { +unsafe extern "C" { pub static mut foo: ::std::option::Option< unsafe extern "C" fn( x: ::std::os::raw::c_int, @@ -6,10 +6,10 @@ extern "C" { ) -> ::std::os::raw::c_int, >; } -extern "C" { +unsafe extern "C" { pub fn bar(a: *const ::std::os::raw::c_char) -> ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { pub fn bar2(b: *const ::std::os::raw::c_char) -> f32; } pub type Char = ::std::os::raw::c_char; diff --git a/bindgen-tests/tests/expectations/tests/test_multiple_header_calls_in_builder.rs b/bindgen-tests/tests/expectations/tests/test_multiple_header_calls_in_builder.rs index bcc27d259f..2e62ac902f 100644 --- a/bindgen-tests/tests/expectations/tests/test_multiple_header_calls_in_builder.rs +++ b/bindgen-tests/tests/expectations/tests/test_multiple_header_calls_in_builder.rs @@ -1,4 +1,4 @@ -extern "C" { +unsafe extern "C" { pub static mut foo: ::std::option::Option< unsafe extern "C" fn( x: ::std::os::raw::c_int, diff --git a/bindgen-tests/tests/expectations/tests/type-referenced-by-allowlisted-function.rs b/bindgen-tests/tests/expectations/tests/type-referenced-by-allowlisted-function.rs index 8ddfaa7c68..6d1c43d9cc 100644 --- a/bindgen-tests/tests/expectations/tests/type-referenced-by-allowlisted-function.rs +++ b/bindgen-tests/tests/expectations/tests/type-referenced-by-allowlisted-function.rs @@ -12,6 +12,6 @@ const _: () = { "Offset of field: dl_phdr_info::x", ][::std::mem::offset_of!(dl_phdr_info, x) - 0usize]; }; -extern "C" { +unsafe extern "C" { pub fn dl_iterate_phdr(arg1: *mut dl_phdr_info) -> ::std::os::raw::c_int; } diff --git a/bindgen-tests/tests/expectations/tests/typedef-pointer-overlap.rs b/bindgen-tests/tests/expectations/tests/typedef-pointer-overlap.rs index f2376ed227..122059b4e1 100644 --- a/bindgen-tests/tests/expectations/tests/typedef-pointer-overlap.rs +++ b/bindgen-tests/tests/expectations/tests/typedef-pointer-overlap.rs @@ -55,33 +55,33 @@ pub type cat_ptr = *mut cat; pub const mad_scientist: mad = 0; pub type mad = ::std::os::raw::c_uint; pub type mad_ptr = *mut mad; -extern "C" { +unsafe extern "C" { pub fn takes_foo_ptr(arg1: foo_ptr); } -extern "C" { +unsafe extern "C" { pub fn takes_foo_struct(arg1: foo); } -extern "C" { +unsafe extern "C" { pub fn takes_bar_ptr(arg1: bar_ptr); } -extern "C" { +unsafe extern "C" { pub fn takes_bar_struct(arg1: bar); } -extern "C" { +unsafe extern "C" { pub fn takes_baz_ptr(arg1: baz_ptr); } -extern "C" { +unsafe extern "C" { pub fn takes_baz_struct(arg1: baz); } -extern "C" { +unsafe extern "C" { pub fn takes_cat_ptr(arg1: cat_ptr); } -extern "C" { +unsafe extern "C" { pub fn takes_cat_union(arg1: cat); } -extern "C" { +unsafe extern "C" { pub fn takes_mad_ptr(arg1: mad_ptr); } -extern "C" { +unsafe extern "C" { pub fn takes_mad_enum(arg1: mad); } diff --git a/bindgen-tests/tests/expectations/tests/typedefd-array-as-function-arg.rs b/bindgen-tests/tests/expectations/tests/typedefd-array-as-function-arg.rs index 792b243a7a..994b327da7 100644 --- a/bindgen-tests/tests/expectations/tests/typedefd-array-as-function-arg.rs +++ b/bindgen-tests/tests/expectations/tests/typedefd-array-as-function-arg.rs @@ -1,5 +1,5 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type myVector3 = [f32; 3usize]; -extern "C" { +unsafe extern "C" { pub fn modifyVectorFunc(v: *mut f32); } diff --git a/bindgen-tests/tests/expectations/tests/union_dtor.rs b/bindgen-tests/tests/expectations/tests/union_dtor.rs index 168b0a0b1e..3b89587098 100644 --- a/bindgen-tests/tests/expectations/tests/union_dtor.rs +++ b/bindgen-tests/tests/expectations/tests/union_dtor.rs @@ -15,7 +15,7 @@ const _: () = { "Offset of field: UnionWithDtor::mBar", ][::std::mem::offset_of!(UnionWithDtor, mBar) - 0usize]; }; -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN13UnionWithDtorD1Ev"] pub fn UnionWithDtor_UnionWithDtor_destructor(this: *mut UnionWithDtor); } diff --git a/bindgen-tests/tests/expectations/tests/unsorted-items.rs b/bindgen-tests/tests/expectations/tests/unsorted-items.rs index fca5715533..7d31c222a1 100644 --- a/bindgen-tests/tests/expectations/tests/unsorted-items.rs +++ b/bindgen-tests/tests/expectations/tests/unsorted-items.rs @@ -1,9 +1,9 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern "C" { +unsafe extern "C" { pub fn foo() -> ::std::os::raw::c_int; } pub type number = ::std::os::raw::c_int; -extern "C" { +unsafe extern "C" { pub fn bar(x: number) -> ::std::os::raw::c_int; } #[repr(C)] @@ -32,7 +32,7 @@ const _: () = { ["Offset of field: Angle::a"][::std::mem::offset_of!(Angle, a) - 0usize]; ["Offset of field: Angle::b"][::std::mem::offset_of!(Angle, b) - 4usize]; }; -extern "C" { +unsafe extern "C" { pub fn baz(point: Point) -> ::std::os::raw::c_int; } pub const NUMBER: number = 42; diff --git a/bindgen-tests/tests/expectations/tests/use-core.rs b/bindgen-tests/tests/expectations/tests/use-core.rs index e7b3ce8982..8d495459a0 100644 --- a/bindgen-tests/tests/expectations/tests/use-core.rs +++ b/bindgen-tests/tests/expectations/tests/use-core.rs @@ -51,7 +51,7 @@ impl Default for _bindgen_ty_1 { } } } -extern "C" { +unsafe extern "C" { pub static mut bazz: _bindgen_ty_1; } pub type fooFunction = ::core::option::Option< diff --git a/bindgen-tests/tests/expectations/tests/va_list_aarch64_linux.rs b/bindgen-tests/tests/expectations/tests/va_list_aarch64_linux.rs index c4cc944639..31f75ced23 100644 --- a/bindgen-tests/tests/expectations/tests/va_list_aarch64_linux.rs +++ b/bindgen-tests/tests/expectations/tests/va_list_aarch64_linux.rs @@ -10,7 +10,7 @@ impl Default for __BindgenOpaqueArray { } } pub type va_list = __BindgenOpaqueArray; -extern "C" { +unsafe extern "C" { pub fn vprintf( format: *const ::std::os::raw::c_char, vlist: __BindgenOpaqueArray, diff --git a/bindgen-tests/tests/expectations/tests/var-tracing.rs b/bindgen-tests/tests/expectations/tests/var-tracing.rs index 606cdd70b8..76ce0c50d6 100644 --- a/bindgen-tests/tests/expectations/tests/var-tracing.rs +++ b/bindgen-tests/tests/expectations/tests/var-tracing.rs @@ -10,7 +10,7 @@ const _: () = { ["Alignment of Bar"][::std::mem::align_of::() - 4usize]; ["Offset of field: Bar::m_baz"][::std::mem::offset_of!(Bar, m_baz) - 0usize]; }; -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN3BarC1Ei"] pub fn Bar_Bar(this: *mut Bar, baz: ::std::os::raw::c_int); } @@ -27,7 +27,7 @@ impl Bar { pub struct Baz { pub _address: u8, } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN3Baz3FOOE"] pub static Baz_FOO: [Bar; 0usize]; } diff --git a/bindgen-tests/tests/expectations/tests/variadic-method.rs b/bindgen-tests/tests/expectations/tests/variadic-method.rs index 93ce01b813..deac5f719e 100644 --- a/bindgen-tests/tests/expectations/tests/variadic-method.rs +++ b/bindgen-tests/tests/expectations/tests/variadic-method.rs @@ -1,5 +1,5 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_Z3fooPKcz"] pub fn foo(fmt: *const ::std::os::raw::c_char, ...); } @@ -13,7 +13,7 @@ const _: () = { ["Size of Bar"][::std::mem::size_of::() - 1usize]; ["Alignment of Bar"][::std::mem::align_of::() - 1usize]; }; -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN3Bar3fooEPKcz"] pub fn Bar_foo(this: *mut Bar, fmt: *const ::std::os::raw::c_char, ...); } diff --git a/bindgen-tests/tests/expectations/tests/vector.rs b/bindgen-tests/tests/expectations/tests/vector.rs index 2278b520d9..da53b4a8eb 100644 --- a/bindgen-tests/tests/expectations/tests/vector.rs +++ b/bindgen-tests/tests/expectations/tests/vector.rs @@ -13,7 +13,7 @@ const _: () = { pub type __m128 = [f32; 4usize]; pub type __m128d = [f64; 2usize]; pub type __m128i = [::std::os::raw::c_longlong; 2usize]; -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_Z3fooDv2_xDv2_d"] pub fn foo(arg1: __m128i, arg2: __m128d) -> __m128; } diff --git a/bindgen-tests/tests/expectations/tests/virtual_dtor.rs b/bindgen-tests/tests/expectations/tests/virtual_dtor.rs index 84211429b1..d42be25202 100644 --- a/bindgen-tests/tests/expectations/tests/virtual_dtor.rs +++ b/bindgen-tests/tests/expectations/tests/virtual_dtor.rs @@ -20,7 +20,7 @@ impl Default for nsSlots { } } } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN7nsSlotsD1Ev"] pub fn nsSlots_nsSlots_destructor(this: *mut nsSlots); } diff --git a/bindgen-tests/tests/expectations/tests/virtual_overloaded.rs b/bindgen-tests/tests/expectations/tests/virtual_overloaded.rs index 800ebbef8f..4c3702faeb 100644 --- a/bindgen-tests/tests/expectations/tests/virtual_overloaded.rs +++ b/bindgen-tests/tests/expectations/tests/virtual_overloaded.rs @@ -23,11 +23,11 @@ impl Default for C { } } } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN1C8do_thingEc"] pub fn C_do_thing(this: *mut ::std::os::raw::c_void, arg1: ::std::os::raw::c_char); } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN1C8do_thingEi"] pub fn C_do_thing1(this: *mut ::std::os::raw::c_void, arg1: ::std::os::raw::c_int); } diff --git a/bindgen-tests/tests/expectations/tests/void_typedef.rs b/bindgen-tests/tests/expectations/tests/void_typedef.rs index 6c3b45dcc7..4997d49086 100644 --- a/bindgen-tests/tests/expectations/tests/void_typedef.rs +++ b/bindgen-tests/tests/expectations/tests/void_typedef.rs @@ -1,12 +1,12 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub type VOID = ::std::os::raw::c_void; pub type ALSO_VOID = VOID; -extern "C" { +unsafe extern "C" { pub fn this_api_returns_nothing(); } -extern "C" { +unsafe extern "C" { pub fn this_api_also_returns_nothing(); } -extern "C" { +unsafe extern "C" { pub fn this_other_api_also_returns_nothing(); } diff --git a/bindgen-tests/tests/expectations/tests/vtable_recursive_sig.rs b/bindgen-tests/tests/expectations/tests/vtable_recursive_sig.rs index fe08228ab9..9b9c2467aa 100644 --- a/bindgen-tests/tests/expectations/tests/vtable_recursive_sig.rs +++ b/bindgen-tests/tests/expectations/tests/vtable_recursive_sig.rs @@ -22,7 +22,7 @@ impl Default for Base { } } } -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN4Base9AsDerivedEv"] pub fn Base_AsDerived(this: *mut ::std::os::raw::c_void) -> *mut Derived; } diff --git a/bindgen-tests/tests/expectations/tests/wasm-constructor-returns.rs b/bindgen-tests/tests/expectations/tests/wasm-constructor-returns.rs index 092d592e29..ee26600a6b 100644 --- a/bindgen-tests/tests/expectations/tests/wasm-constructor-returns.rs +++ b/bindgen-tests/tests/expectations/tests/wasm-constructor-returns.rs @@ -9,7 +9,7 @@ const _: () = { ["Size of Foo"][::std::mem::size_of::() - 1usize]; ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; }; -extern "C" { +unsafe extern "C" { #[link_name = "\u{1}_ZN3FooC1Ei"] pub fn Foo_Foo( this: *mut Foo, diff --git a/bindgen-tests/tests/expectations/tests/wasm-import-module.rs b/bindgen-tests/tests/expectations/tests/wasm-import-module.rs index 9725195e0e..aeeb17f1c1 100644 --- a/bindgen-tests/tests/expectations/tests/wasm-import-module.rs +++ b/bindgen-tests/tests/expectations/tests/wasm-import-module.rs @@ -1,5 +1,5 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[link(wasm_import_module = "test-module")] -extern "C" { +unsafe extern "C" { pub fn test_function(); } diff --git a/bindgen-tests/tests/expectations/tests/win32-thiscall_nightly.rs b/bindgen-tests/tests/expectations/tests/win32-thiscall_nightly.rs index 3c84de7b95..87b63574a9 100644 --- a/bindgen-tests/tests/expectations/tests/win32-thiscall_nightly.rs +++ b/bindgen-tests/tests/expectations/tests/win32-thiscall_nightly.rs @@ -11,11 +11,11 @@ const _: () = { ["Size of Foo"][::std::mem::size_of::() - 1usize]; ["Alignment of Foo"][::std::mem::align_of::() - 1usize]; }; -extern "thiscall" { +unsafe extern "thiscall" { #[link_name = "\u{1}?test@Foo@@QAEXXZ"] pub fn Foo_test(this: *mut Foo); } -extern "thiscall" { +unsafe extern "thiscall" { #[link_name = "\u{1}?test2@Foo@@QAEHH@Z"] pub fn Foo_test2( this: *mut Foo, diff --git a/bindgen-tests/tests/expectations/tests/win32-vectorcall-nightly.rs b/bindgen-tests/tests/expectations/tests/win32-vectorcall-nightly.rs index a262b78c59..1c7b2fdbf6 100644 --- a/bindgen-tests/tests/expectations/tests/win32-vectorcall-nightly.rs +++ b/bindgen-tests/tests/expectations/tests/win32-vectorcall-nightly.rs @@ -1,7 +1,7 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #![cfg(feature = "nightly")] #![feature(abi_vectorcall)] -extern "vectorcall" { +unsafe extern "vectorcall" { #[link_name = "\u{1}test_vectorcall@@16"] pub fn test_vectorcall( a: ::std::os::raw::c_int, diff --git a/bindgen-tests/tests/expectations/tests/with_array_pointers_arguments.rs b/bindgen-tests/tests/expectations/tests/with_array_pointers_arguments.rs index cc82fd4daf..7cc1d65daf 100644 --- a/bindgen-tests/tests/expectations/tests/with_array_pointers_arguments.rs +++ b/bindgen-tests/tests/expectations/tests/with_array_pointers_arguments.rs @@ -1,11 +1,11 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern "C" { +unsafe extern "C" { pub fn test_fn( a: f32, arr: *mut [::std::os::raw::c_int; 20usize], ) -> ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { pub fn test_fn2( arr: *const [f32; 20usize], b: ::std::os::raw::c_int, @@ -13,6 +13,6 @@ extern "C" { } pub type defArr = [::std::os::raw::c_char; 20usize]; pub type foo = ::std::option::Option; -extern "C" { +unsafe extern "C" { pub fn bar(a: *mut defArr); } diff --git a/bindgen-tests/tests/expectations/tests/without_array_pointers_arguments.rs b/bindgen-tests/tests/expectations/tests/without_array_pointers_arguments.rs index f48e5f7f5c..d642e84d27 100644 --- a/bindgen-tests/tests/expectations/tests/without_array_pointers_arguments.rs +++ b/bindgen-tests/tests/expectations/tests/without_array_pointers_arguments.rs @@ -1,14 +1,14 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern "C" { +unsafe extern "C" { pub fn test_fn(a: f32, arr: *mut ::std::os::raw::c_int) -> ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { pub fn test_fn2(arr: *const f32, b: ::std::os::raw::c_int) -> ::std::os::raw::c_int; } pub type defArr = [::std::os::raw::c_char; 20usize]; pub type foo = ::std::option::Option< unsafe extern "C" fn(a: *mut ::std::os::raw::c_char), >; -extern "C" { +unsafe extern "C" { pub fn bar(a: *mut ::std::os::raw::c_char); } diff --git a/bindgen-tests/tests/expectations/tests/wrap-static-fns.rs b/bindgen-tests/tests/expectations/tests/wrap-static-fns.rs index 46b369b2f4..bafcad8a7e 100644 --- a/bindgen-tests/tests/expectations/tests/wrap-static-fns.rs +++ b/bindgen-tests/tests/expectations/tests/wrap-static-fns.rs @@ -1,17 +1,17 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -extern "C" { +unsafe extern "C" { #[link_name = "foo__extern"] pub fn foo() -> ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "bar__extern"] pub fn bar() -> ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "takes_ptr__extern"] pub fn takes_ptr(arg: *mut ::std::os::raw::c_int) -> ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "takes_fn_ptr__extern"] pub fn takes_fn_ptr( f: ::std::option::Option< @@ -19,7 +19,7 @@ extern "C" { >, ) -> ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "takes_fn__extern"] pub fn takes_fn( f: ::std::option::Option< @@ -30,11 +30,11 @@ extern "C" { pub type func = ::std::option::Option< unsafe extern "C" fn(arg1: ::std::os::raw::c_int) -> ::std::os::raw::c_int, >; -extern "C" { +unsafe extern "C" { #[link_name = "takes_alias__extern"] pub fn takes_alias(f: func) -> ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "takes_qualified__extern"] pub fn takes_qualified( arg: *const *const ::std::os::raw::c_int, @@ -42,25 +42,25 @@ extern "C" { } pub const foo_BAR: foo = 0; pub type foo = ::std::os::raw::c_uint; -extern "C" { +unsafe extern "C" { #[link_name = "takes_enum__extern"] pub fn takes_enum(f: foo) -> foo; } -extern "C" { +unsafe extern "C" { #[link_name = "nevermore__extern"] pub fn nevermore(); } -extern "C" { +unsafe extern "C" { #[link_name = "takes_fn_with_no_args__extern"] pub fn takes_fn_with_no_args( f: ::std::option::Option ::std::os::raw::c_int>, ) -> ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "no_extra_argument__extern"] pub fn no_extra_argument(va: *mut __va_list_tag); } -extern "C" { +unsafe extern "C" { #[link_name = "many_va_list__extern"] pub fn many_va_list( i: ::std::os::raw::c_int, @@ -68,14 +68,14 @@ extern "C" { va2: *mut __va_list_tag, ) -> ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "wrap_as_variadic_fn1__extern"] pub fn wrap_as_variadic_fn1_wrapped( i: ::std::os::raw::c_int, ... ) -> ::std::os::raw::c_int; } -extern "C" { +unsafe extern "C" { #[link_name = "wrap_as_variadic_fn2__extern"] pub fn wrap_as_variadic_fn2_wrapped(i: ::std::os::raw::c_int, ...); } diff --git a/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_class.rs b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_class.rs index 5f64396f6b..617a037631 100644 --- a/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_class.rs +++ b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_class.rs @@ -166,26 +166,26 @@ impl Default for WithUnion { pub struct RealAbstractionWithTonsOfMethods { pub _address: u8, } -extern "C" { +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/wrap_unsafe_ops_objc_class.rs b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_objc_class.rs index c8f7241fcf..34252b10d3 100644 --- a/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_objc_class.rs +++ b/bindgen-tests/tests/expectations/tests/wrap_unsafe_ops_objc_class.rs @@ -3,7 +3,7 @@ use objc::{self, msg_send, sel, sel_impl, class}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; -extern "C" { +unsafe extern "C" { pub static mut fooVar: Foo; } #[repr(transparent)] diff --git a/bindgen-tests/tests/headers/merge-extern-blocks.hpp b/bindgen-tests/tests/headers/merge-extern-blocks.hpp deleted file mode 100644 index 392e34a390..0000000000 --- a/bindgen-tests/tests/headers/merge-extern-blocks.hpp +++ /dev/null @@ -1,14 +0,0 @@ -// bindgen-flags: --merge-extern-blocks --enable-cxx-namespaces -- --target=x86_64-unknown-linux -int foo(); -typedef struct Point { - int x; -} Point; -int bar(); - -namespace ns { - int foo(); - typedef struct Point { - int x; - } Point; - int bar(); -} diff --git a/bindgen-tests/tests/tests.rs b/bindgen-tests/tests/tests.rs index 0b3ebe1533..fc0b41d187 100644 --- a/bindgen-tests/tests/tests.rs +++ b/bindgen-tests/tests/tests.rs @@ -391,10 +391,10 @@ fn test_clang_env_args() { let actual = format_code(actual).unwrap(); let expected = format_code( - "extern \"C\" { + "unsafe extern \"C\" { pub static x: [::std::os::raw::c_int; 1usize]; } -extern \"C\" { +unsafe extern \"C\" { pub static y: [::std::os::raw::c_int; 1usize]; } ", @@ -417,7 +417,7 @@ fn test_header_contents() { let actual = format_code(actual).unwrap(); let expected = format_code( - "extern \"C\" { + "unsafe extern \"C\" { pub fn foo(a: *const ::std::os::raw::c_char) -> ::std::os::raw::c_int; } ", @@ -513,10 +513,10 @@ fn test_multiple_header_contents() { let actual = format_code(actual).unwrap(); let expected = format_code( - "extern \"C\" { + "unsafe extern \"C\" { pub fn foo2(b: *const ::std::os::raw::c_char) -> f32; } -extern \"C\" { +unsafe extern \"C\" { pub fn foo(a: *const ::std::os::raw::c_char) -> ::std::os::raw::c_int; } ", From f2d2266d4564cce1f6002c3ed9a4c13b4fc246c4 Mon Sep 17 00:00:00 2001 From: George Bateman Date: Mon, 2 Dec 2024 22:09:20 +0000 Subject: [PATCH 807/942] Fix regression spotted at #3027 --- .../tests/expectations/tests/issue-3027.rs | 31 +++++++++++++++++++ bindgen-tests/tests/headers/issue-3027.hpp | 6 ++++ bindgen/codegen/helpers.rs | 6 +++- 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 bindgen-tests/tests/expectations/tests/issue-3027.rs create mode 100644 bindgen-tests/tests/headers/issue-3027.hpp diff --git a/bindgen-tests/tests/expectations/tests/issue-3027.rs b/bindgen-tests/tests/expectations/tests/issue-3027.rs new file mode 100644 index 0000000000..757aa9d9df --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/issue-3027.rs @@ -0,0 +1,31 @@ +#![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; + pub mod regression { + #[allow(unused_imports)] + use self::super::super::root; + #[repr(C)] + #[derive(Debug, Default, Copy, Clone)] + pub struct C { + pub a: root::__BindgenOpaqueArray, + } + #[allow(clippy::unnecessary_operation, clippy::identity_op)] + const _: () = { + ["Size of C"][::std::mem::size_of::() - 3usize]; + ["Alignment of C"][::std::mem::align_of::() - 1usize]; + ["Offset of field: C::a"][::std::mem::offset_of!(C, a) - 0usize]; + }; + } +} diff --git a/bindgen-tests/tests/headers/issue-3027.hpp b/bindgen-tests/tests/headers/issue-3027.hpp new file mode 100644 index 0000000000..d9b87ee6e2 --- /dev/null +++ b/bindgen-tests/tests/headers/issue-3027.hpp @@ -0,0 +1,6 @@ +// bindgen-flags: --enable-cxx-namespaces + +namespace regression { + template class A { char c[N]; }; + class C { A<3> a; }; +} diff --git a/bindgen/codegen/helpers.rs b/bindgen/codegen/helpers.rs index 1827705433..812b6b6458 100644 --- a/bindgen/codegen/helpers.rs +++ b/bindgen/codegen/helpers.rs @@ -102,7 +102,11 @@ pub(crate) fn blob( ty } else if ffi_safe && ctx.options().rust_features().min_const_generics { ctx.generated_opaque_array(); - syn::parse_quote! { __BindgenOpaqueArray<#ty, #data_len> } + if ctx.options().enable_cxx_namespaces { + syn::parse_quote! { root::__BindgenOpaqueArray<#ty, #data_len> } + } else { + syn::parse_quote! { __BindgenOpaqueArray<#ty, #data_len> } + } } else { // This is not FFI safe as an argument; the struct above is // preferable. From cce8f7edad7c4c36619aab3067ce90b29dceac81 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Tue, 3 Dec 2024 19:39:33 -0500 Subject: [PATCH 808/942] Use `macos-latest` on CI --- .github/workflows/bindgen.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 836052a5a6..42d167b5bc 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -108,7 +108,7 @@ jobs: runs-on: ${{matrix.os}} strategy: matrix: - os: [ubuntu-latest, macos-12] + os: [ubuntu-latest, macos-latest] steps: - uses: actions/checkout@v4 @@ -165,7 +165,7 @@ jobs: # FIXME: Ideally should use the latest llvm version, but llvm doesn't # provide releases for x86-64 macOS anymore which is what the runner uses. # - - os: macos-12 + - os: macos-latest llvm_version: "9.0" release_build: 0 no_default_features: 0 From a154af5a3978fdd336754e4268a57f7d99c9a31e Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Tue, 3 Dec 2024 19:39:33 -0500 Subject: [PATCH 809/942] Use `KyleMayes/install-llvm-action` to install LLVM --- .github/workflows/bindgen.yml | 10 ++--- ci/test.sh | 71 ++++++----------------------------- 2 files changed, 16 insertions(+), 65 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 42d167b5bc..c29af7e989 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -162,11 +162,8 @@ jobs: # feature_extra_asserts: 0 # Ensure stuff works on macos too - # FIXME: Ideally should use the latest llvm version, but llvm doesn't - # provide releases for x86-64 macOS anymore which is what the runner uses. - # - os: macos-latest - llvm_version: "9.0" + llvm_version: "16.0" release_build: 0 no_default_features: 0 feature_extra_asserts: 0 @@ -198,12 +195,15 @@ jobs: run: | wget https://mirrors.kernel.org/ubuntu/pool/universe/n/ncurses/libtinfo5_6.3-2ubuntu0.1_amd64.deb sudo dpkg -i libtinfo5_6.3-2ubuntu0.1_amd64.deb + - name: Install LLVM and Clang + uses: KyleMayes/install-llvm-action@v2.0.5 + with: + version: ${{matrix.llvm_version}} - name: Run all the tests env: GITHUB_ACTIONS_OS: ${{matrix.os}} RUST_CROSS_COMPILER: ${{matrix.target.cross}} RUST_TARGET: ${{matrix.target.rust}} - LLVM_VERSION: ${{matrix.llvm_version}} BINDGEN_MAIN_TESTS: ${{matrix.main_tests}} BINDGEN_RELEASE_BUILD: ${{matrix.release_build}} BINDGEN_FEATURE_RUNTIME: ${{matrix.feature_runtime}} diff --git a/ci/test.sh b/ci/test.sh index a90af84484..b4629479ba 100755 --- a/ci/test.sh +++ b/ci/test.sh @@ -8,64 +8,15 @@ set -x # Give a pipeline a non-zero exit code if one of its constituents fails set -o pipefail -function llvm_linux_target_triple() { - case "$1" in - 9.0.1) echo "x86_64-linux-gnu-ubuntu-16.04" ;; - *) echo "x86_64-linux-gnu-ubuntu-18.04" ;; - esac -} - -function llvm_macos_target_triple() { - case "$1" in - 9.0.1) echo "x86_64-apple-darwin" ;; - *) echo "arm64-apple-darwin22.0" ;; - esac -} - -function llvm_version_triple() { - case "$1" in - 9.0) echo "9.0.1" ;; - # By default, take the .0 patch release - *) echo "$1.0" ;; - esac -} - -function llvm_base_url() { - local llvm_version_triple=$1 - echo "https://github.com/llvm/llvm-project/releases/download/llvmorg-$llvm_version_triple" -} - -function llvm_download() { - local base_url=$1 - local arch=$2 - - export LLVM=clang+llvm-${LLVM_VERSION_TRIPLE}-$arch - export LLVM_DIRECTORY="$HOME/.llvm/${LLVM}" - - if [ -d "${LLVM_DIRECTORY}" ]; then - echo "Using cached LLVM download for ${LLVM}..." - else - wget --no-verbose $base_url/${LLVM}.tar.xz - mkdir -p "${LLVM_DIRECTORY}" - tar xf ${LLVM}.tar.xz -C "${LLVM_DIRECTORY}" --strip-components=1 - fi - - export LIBCLANG_PATH="${LLVM_DIRECTORY}/lib" - export LLVM_CONFIG_PATH="${LLVM_DIRECTORY}/bin/llvm-config" -} - -# Download and set up a sane LLVM version set_llvm_env() { - export LLVM_VERSION_TRIPLE=`llvm_version_triple ${LLVM_VERSION}` - local base_url=`llvm_base_url ${LLVM_VERSION_TRIPLE}` - - if [ "$GITHUB_ACTIONS_OS" == "ubuntu-latest" ]; then - llvm_download $base_url `llvm_linux_target_triple ${LLVM_VERSION_TRIPLE}` - export LD_LIBRARY_PATH="${LLVM_DIRECTORY}/lib":${LD_LIBRARY_PATH:-} - else - llvm_download $base_url `llvm_macos_target_triple ${LLVM_VERSION_TRIPLE}` - export DYLD_LIBRARY_PATH="${LLVM_DIRECTORY}/lib":${DYLD_LIBRARY_PATH:-} - fi + export LLVM_CONFIG_PATH=${LLVM_PATH}/bin/llvm-config + echo "LLVM_CONFIG_PATH=$LLVM_CONFIG_PATH" + + export LIBCLANG_PATH=${LLVM_PATH}/lib/ + echo "LIBCLANG_PATH=$LIBCLANG_PATH" + + export CLANG_PATH=${LLVM_PATH}/bin/clang + echo "CLANG_PATH=$CLANG_PATH" } assert_no_diff() { @@ -74,8 +25,6 @@ assert_no_diff() { git diff-index --quiet HEAD } -set_llvm_env - get_cargo_args() { local args="" if [ ! -z "$RUST_TARGET" ]; then @@ -100,6 +49,8 @@ get_cargo_args() { echo $args } +set_llvm_env + if [ ! -z "$RUST_CROSS_COMPILER" ]; then export RUSTFLAGS="-C linker=${RUST_CROSS_COMPILER}-gcc" fi @@ -128,7 +79,7 @@ if [ "$BINDGEN_RUST_FOR_LINUX_TEST" == "1" ]; then # Put LLVM binaries in the path for `LLVM=1`. The LLVM `bin` directory should # go first since there are others in the Ubuntu image. - export PATH="${LLVM_DIRECTORY}/bin:${PATH}" + export PATH="${LLVM_PATH}/bin:${PATH}" # Kernel build dependency: `bindgen-cli`, which is under test. # From eeca12ded27777f45a55c1691d117643239502b0 Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Tue, 3 Dec 2024 21:27:13 +0100 Subject: [PATCH 810/942] ci: Move forward Rust for Linux version to v6.13-rc1 The kernel merge window has finished, so upgrade to the first release candidate tag so that `bindgen` CI tests the latest additions/changes. Signed-off-by: Miguel Ojeda --- ci/test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/test.sh b/ci/test.sh index b4629479ba..46d29484af 100755 --- a/ci/test.sh +++ b/ci/test.sh @@ -105,7 +105,7 @@ if [ "$BINDGEN_RUST_FOR_LINUX_TEST" == "1" ]; then # and each update should only contain this change. # # Both commit hashes and tags are supported. - LINUX_VERSION=v6.12-rc5 + LINUX_VERSION=v6.13-rc1 # Download Linux at a specific commit mkdir -p linux @@ -142,6 +142,6 @@ EOF # Build Rust for Linux make -C linux LLVM=1 -j$(($(nproc) + 1)) \ samples/rust/rust_minimal.o \ - samples/rust/rust_print.o \ + samples/rust/rust_print_main.o \ drivers/net/phy/ax88796b_rust.o fi From 260779805ca02db086d836919adca3bd2eb8f475 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Wed, 4 Dec 2024 11:26:08 -0500 Subject: [PATCH 811/942] docs(book): fix package name for the extra Clang tools --- book/src/requirements.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/src/requirements.md b/book/src/requirements.md index d13e3a85c2..f81defef60 100644 --- a/book/src/requirements.md +++ b/book/src/requirements.md @@ -82,6 +82,6 @@ instructions [here](http://clang.llvm.org/get_started.html). Those instructions list optional steps. For `bindgen`: * Checkout and build clang -* Checkout and build the extra-clang-tools +* Checkout and build `clang-tools-extra` * You do not need to checkout or build compiler-rt * You do not need to checkout or build libcxx From 42218df0668eedc04e681a134fd7bceeba9f1623 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Wed, 4 Dec 2024 11:27:06 -0500 Subject: [PATCH 812/942] docs(book): fix inconsistent use of Clang versions --- book/src/requirements.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/src/requirements.md b/book/src/requirements.md index f81defef60..cf719a0d61 100644 --- a/book/src/requirements.md +++ b/book/src/requirements.md @@ -75,7 +75,7 @@ Add `export LIBCLANG_PATH=/usr/local/lib` to your profile. #### From source -If your package manager doesn't yet offer Clang 5.0, you'll need to build from +If your package manager doesn't yet offer Clang 9.0, you'll need to build from source. For that, follow the instructions [here](http://clang.llvm.org/get_started.html). From 798d61832fc40b340307dcf0deb36b754e23c75c Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Wed, 4 Dec 2024 16:40:59 -0500 Subject: [PATCH 813/942] ci: remove unused targets --- .github/workflows/bindgen.yml | 36 ----------------------------------- ci/test.sh | 7 ------- 2 files changed, 43 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index c29af7e989..d0842d2626 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -125,10 +125,6 @@ jobs: strategy: matrix: os: [ubuntu-latest] - target: - - debian: null - cross: null - rust: null llvm_version: ["9.0", "16.0"] main_tests: [1] release_build: [0, 1] @@ -147,20 +143,6 @@ jobs: no_default_features: 0 feature_extra_asserts: 1 - # FIXME: Seems installing multiarch packages fails: - # - # https://github.com/rust-lang/rust-bindgen/pull/2037/checks?check_run_id=2441799333 - # - # - os: ubuntu-latest - # target: - # debian: arm64 - # cross: aarch64-linux-gnu - # rust: aarch64-unknown-linux-gnu - # llvm_version: "16.0" - # main_tests: 0 - # release_build: 0 - # feature_extra_asserts: 0 - # Ensure stuff works on macos too - os: macos-latest llvm_version: "16.0" @@ -170,26 +152,10 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Install multiarch packages - if: matrix.target.debian - run: | - sudo apt-get install binfmt-support qemu-user-static gcc-${{matrix.target.cross}} g++-${{matrix.target.cross}} - source /etc/lsb-release - sudo tee /etc/apt/sources.list </dev/null - deb [arch=${{matrix.target.debian}}] http://ports.ubuntu.com/ubuntu-ports/ $DISTRIB_CODENAME main - deb [arch=${{matrix.target.debian}}] http://ports.ubuntu.com/ubuntu-ports/ $DISTRIB_CODENAME-updates main - deb [arch=${{matrix.target.debian}}] http://ports.ubuntu.com/ubuntu-ports/ $DISTRIB_CODENAME-backports main - deb [arch=${{matrix.target.debian}}] http://ports.ubuntu.com/ubuntu-ports/ $DISTRIB_CODENAME-security main - EOF - sudo dpkg --add-architecture ${{matrix.target.debian}} - sudo apt-get update - sudo apt-get install libc6:${{matrix.target.debian}} libstdc++6:${{matrix.target.debian}} - - name: Install stable uses: dtolnay/rust-toolchain@master with: toolchain: stable - target: ${{matrix.target.rust}} - name: Install libtinfo if: matrix.os == 'ubuntu-latest' run: | @@ -202,8 +168,6 @@ jobs: - name: Run all the tests env: GITHUB_ACTIONS_OS: ${{matrix.os}} - RUST_CROSS_COMPILER: ${{matrix.target.cross}} - RUST_TARGET: ${{matrix.target.rust}} BINDGEN_MAIN_TESTS: ${{matrix.main_tests}} BINDGEN_RELEASE_BUILD: ${{matrix.release_build}} BINDGEN_FEATURE_RUNTIME: ${{matrix.feature_runtime}} diff --git a/ci/test.sh b/ci/test.sh index 46d29484af..9ccc58d01b 100755 --- a/ci/test.sh +++ b/ci/test.sh @@ -27,9 +27,6 @@ assert_no_diff() { get_cargo_args() { local args="" - if [ ! -z "$RUST_TARGET" ]; then - args+=" --target $RUST_TARGET" - fi if [ "$BINDGEN_RELEASE_BUILD" == "1" ]; then args+=" --release" fi @@ -51,10 +48,6 @@ get_cargo_args() { set_llvm_env -if [ ! -z "$RUST_CROSS_COMPILER" ]; then - export RUSTFLAGS="-C linker=${RUST_CROSS_COMPILER}-gcc" -fi - CARGO_ARGS=`get_cargo_args` # Ensure we build without warnings From 2da868db62745045d4fc5987663da85035ffa520 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Wed, 4 Dec 2024 16:47:25 -0500 Subject: [PATCH 814/942] ci: remove `main_tests` from matrix It is set to `1` all the time anyway. --- .github/workflows/bindgen.yml | 2 -- ci/test.sh | 6 ++---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index d0842d2626..d459fc2fc2 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -126,7 +126,6 @@ jobs: matrix: os: [ubuntu-latest] llvm_version: ["9.0", "16.0"] - main_tests: [1] release_build: [0, 1] no_default_features: [0, 1] # FIXME: There are no pre-built static libclang libraries, so the @@ -168,7 +167,6 @@ jobs: - name: Run all the tests env: GITHUB_ACTIONS_OS: ${{matrix.os}} - BINDGEN_MAIN_TESTS: ${{matrix.main_tests}} BINDGEN_RELEASE_BUILD: ${{matrix.release_build}} BINDGEN_FEATURE_RUNTIME: ${{matrix.feature_runtime}} BINDGEN_FEATURE_EXTRA_ASSERTS: ${{matrix.feature_extra_asserts}} diff --git a/ci/test.sh b/ci/test.sh index 9ccc58d01b..93bc9c2823 100755 --- a/ci/test.sh +++ b/ci/test.sh @@ -53,10 +53,8 @@ CARGO_ARGS=`get_cargo_args` # Ensure we build without warnings RUSTFLAGS="-Dwarnings" cargo check $CARGO_ARGS -if [ "$BINDGEN_MAIN_TESTS" == "1" ]; then - # Run the tests - (cd bindgen-tests && cargo test $CARGO_ARGS) -fi +# Run the tests +(cd bindgen-tests && cargo test $CARGO_ARGS) assert_no_diff From 80c7bcf738915dda522fd6c3da928f354893d546 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Sun, 1 Dec 2024 21:33:47 -0500 Subject: [PATCH 815/942] chore: update changelog --- CHANGELOG.md | 222 ++++++++++++++++++++++++++++----------------------- 1 file changed, 124 insertions(+), 98 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 04fc283d5d..5fceec85ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,222 +7,248 @@ - [Removed](#removed) - [Fixed](#fixed) - [Security](#security) -- [0.70.1 (2024-08-20)](#0701-2024-08-20) +- [0.71.0 (2024-12-06)](#0710-2024-12-06) - [Added](#added-1) - [Changed](#changed-1) - [Removed](#removed-1) - [Fixed](#fixed-1) - - [Security](#security-1) -- [0.70.0 (2024-08-16)](#0700-2024-08-16) +- [0.70.1 (2024-08-20)](#0701-2024-08-20) - [Added](#added-2) - [Changed](#changed-2) - [Removed](#removed-2) - [Fixed](#fixed-2) - - [Security](#security-2) -- [0.69.4 (2024-02-04)](#0694-2024-02-04) + - [Security](#security-1) +- [0.70.0 (2024-08-16)](#0700-2024-08-16) - [Added](#added-3) - [Changed](#changed-3) - [Removed](#removed-3) - [Fixed](#fixed-3) - - [Security](#security-3) -- [0.69.3 (2024-02-04)](#0693-2024-02-04) + - [Security](#security-2) +- [0.69.4 (2024-02-04)](#0694-2024-02-04) - [Added](#added-4) - [Changed](#changed-4) - [Removed](#removed-4) - [Fixed](#fixed-4) - - [Security](#security-4) -- [0.69.2 (2024-01-13)](#0692-2024-01-13) + - [Security](#security-3) +- [0.69.3 (2024-02-04)](#0693-2024-02-04) - [Added](#added-5) - [Changed](#changed-5) - [Removed](#removed-5) - [Fixed](#fixed-5) - - [Security](#security-5) -- [0.69.1 (2023-11-02)](#0691-2023-11-02) - - [Fixed](#fixed-6) -- [0.69.0 (2023-11-01)](#0690-2023-11-01) + - [Security](#security-4) +- [0.69.2 (2024-01-13)](#0692-2024-01-13) - [Added](#added-6) - [Changed](#changed-6) - [Removed](#removed-6) + - [Fixed](#fixed-6) + - [Security](#security-5) +- [0.69.1 (2023-11-02)](#0691-2023-11-02) - [Fixed](#fixed-7) - - [Security](#security-6) -- [0.68.1](#0681) - - [Fixed](#fixed-8) -- [0.68.0](#0680) +- [0.69.0 (2023-11-01)](#0690-2023-11-01) - [Added](#added-7) - [Changed](#changed-7) - [Removed](#removed-7) + - [Fixed](#fixed-8) + - [Security](#security-6) +- [0.68.1](#0681) - [Fixed](#fixed-9) -- [0.67.0](#0670) -- [0.66.1](#0661) - - [Removed](#removed-8) -- [0.66.0](#0660) +- [0.68.0](#0680) - [Added](#added-8) - [Changed](#changed-8) - - [Removed](#removed-9) -- [0.65.1](#0651) + - [Removed](#removed-8) - [Fixed](#fixed-10) -- [0.65.0](#0650) +- [0.67.0](#0670) +- [0.66.1](#0661) + - [Removed](#removed-9) +- [0.66.0](#0660) - [Added](#added-9) - [Changed](#changed-9) - [Removed](#removed-10) -- [0.64.0](#0640) +- [0.65.1](#0651) + - [Fixed](#fixed-11) +- [0.65.0](#0650) - [Added](#added-10) - [Changed](#changed-10) -- [0.63.0](#0630) + - [Removed](#removed-11) +- [0.64.0](#0640) - [Added](#added-11) - [Changed](#changed-11) - - [Removed](#removed-11) -- [0.62.0](#0620) +- [0.63.0](#0630) - [Added](#added-12) - [Changed](#changed-12) - - [Fixed](#fixed-11) -- [0.61.0](#0610) + - [Removed](#removed-12) +- [0.62.0](#0620) - [Added](#added-13) - [Changed](#changed-13) - [Fixed](#fixed-12) -- [0.60.1](#0601) - - [Fixed](#fixed-13) -- [0.60.0](#0600) +- [0.61.0](#0610) - [Added](#added-14) - - [Fixed](#fixed-14) - [Changed](#changed-14) - - [Removed](#removed-12) + - [Fixed](#fixed-13) +- [0.60.1](#0601) + - [Fixed](#fixed-14) +- [0.60.0](#0600) + - [Added](#added-15) + - [Fixed](#fixed-15) + - [Changed](#changed-15) + - [Removed](#removed-13) - [0.59.2](#0592) - [0.59.1](#0591) - - [Fixed](#fixed-15) -- [0.59.0](#0590) - - [Added](#added-15) - [Fixed](#fixed-16) - - [Changed](#changed-15) -- [0.58.1](#0581) +- [0.59.0](#0590) - [Added](#added-16) -- [0.58.0](#0580) - - [Added](#added-17) - [Fixed](#fixed-17) - [Changed](#changed-16) - - [Deprecated](#deprecated) - - [Removed](#removed-13) +- [0.58.1](#0581) + - [Added](#added-17) +- [0.58.0](#0580) + - [Added](#added-18) - [Fixed](#fixed-18) + - [Changed](#changed-17) + - [Deprecated](#deprecated) + - [Removed](#removed-14) + - [Fixed](#fixed-19) - [Security](#security-7) - [0.57.0](#0570) - - [Added](#added-18) - - [Fixed](#fixed-19) -- [0.56.0](#0560) - [Added](#added-19) - - [Changed](#changed-17) - [Fixed](#fixed-20) -- [0.55.1](#0551) - - [Fixed](#fixed-21) -- [0.55.0](#0550) - - [Removed](#removed-14) +- [0.56.0](#0560) - [Added](#added-20) - [Changed](#changed-18) + - [Fixed](#fixed-21) +- [0.55.1](#0551) - [Fixed](#fixed-22) -- [0.54.1](#0541) +- [0.55.0](#0550) + - [Removed](#removed-15) - [Added](#added-21) - [Changed](#changed-19) - [Fixed](#fixed-23) -- [0.54.0](#0540) +- [0.54.1](#0541) - [Added](#added-22) - [Changed](#changed-20) - [Fixed](#fixed-24) -- [0.53.3](#0533) +- [0.54.0](#0540) - [Added](#added-23) + - [Changed](#changed-21) - [Fixed](#fixed-25) +- [0.53.3](#0533) + - [Added](#added-24) + - [Fixed](#fixed-26) - [0.53.2](#0532) - - [Changed](#changed-21) + - [Changed](#changed-22) - [0.53.1](#0531) - - [Added](#added-24) -- [0.53.0](#0530) - [Added](#added-25) - - [Changed](#changed-22) - - [Fixed](#fixed-26) -- [0.52.0](#0520) +- [0.53.0](#0530) - [Added](#added-26) - [Changed](#changed-23) - [Fixed](#fixed-27) -- [0.51.1](#0511) - - [Fixed](#fixed-28) +- [0.52.0](#0520) + - [Added](#added-27) - [Changed](#changed-24) -- [0.51.0](#0510) + - [Fixed](#fixed-28) +- [0.51.1](#0511) - [Fixed](#fixed-29) - [Changed](#changed-25) - - [Added](#added-27) -- [0.50.0](#0500) +- [0.51.0](#0510) + - [Fixed](#fixed-30) + - [Changed](#changed-26) - [Added](#added-28) -- [0.49.3](#0493) +- [0.50.0](#0500) - [Added](#added-29) +- [0.49.3](#0493) + - [Added](#added-30) - [0.49.2](#0492) - - [Changed](#changed-26) -- [0.49.1](#0491) - - [Fixed](#fixed-30) - [Changed](#changed-27) -- [0.49.0](#0490) - - [Added](#added-30) +- [0.49.1](#0491) - [Fixed](#fixed-31) - [Changed](#changed-28) -- [0.48.1](#0481) +- [0.49.0](#0490) + - [Added](#added-31) - [Fixed](#fixed-32) -- [0.48.0](#0480) - [Changed](#changed-29) +- [0.48.1](#0481) - [Fixed](#fixed-33) -- [0.47.4](#0474) - - [Added](#added-31) -- [0.47.3](#0473) +- [0.48.0](#0480) - [Changed](#changed-30) -- [0.47.2](#0472) - [Fixed](#fixed-34) -- [0.47.1](#0471) +- [0.47.4](#0474) + - [Added](#added-32) +- [0.47.3](#0473) - [Changed](#changed-31) +- [0.47.2](#0472) - [Fixed](#fixed-35) -- [0.47.0](#0470) +- [0.47.1](#0471) - [Changed](#changed-32) - [Fixed](#fixed-36) -- [0.33.1 .. 0.46.0](#0331--0460) - - [Added](#added-32) - - [Removed](#removed-15) +- [0.47.0](#0470) - [Changed](#changed-33) - [Fixed](#fixed-37) -- [0.33.1](#0331) +- [0.33.1 .. 0.46.0](#0331--0460) + - [Added](#added-33) + - [Removed](#removed-16) + - [Changed](#changed-34) - [Fixed](#fixed-38) +- [0.33.1](#0331) + - [Fixed](#fixed-39) - [0.33.0](#0330) - [0.32.2](#0322) - - [Fixed](#fixed-39) -- [0.32.1](#0321) - [Fixed](#fixed-40) -- [0.32.0](#0320) - - [Added](#added-33) - - [Changed](#changed-34) +- [0.32.1](#0321) - [Fixed](#fixed-41) -- [0.31.0](#0310) +- [0.32.0](#0320) - [Added](#added-34) - [Changed](#changed-35) - - [Deprecated](#deprecated-1) - - [Removed](#removed-16) - [Fixed](#fixed-42) -- [0.30.0](#0300) +- [0.31.0](#0310) - [Added](#added-35) - [Changed](#changed-36) - - [Deprecated](#deprecated-2) + - [Deprecated](#deprecated-1) + - [Removed](#removed-17) - [Fixed](#fixed-43) -- [0.29.0](#0290) +- [0.30.0](#0300) - [Added](#added-36) - [Changed](#changed-37) + - [Deprecated](#deprecated-2) - [Fixed](#fixed-44) +- [0.29.0](#0290) + - [Added](#added-37) + - [Changed](#changed-38) + - [Fixed](#fixed-45) -------------------------------------------------------------------------------- # Unreleased ## Added -- Add support for custom attributes (--with-attribute-custom, #2866) ## Changed -- The `--wrap-static-fns` related options no longer require the experimental feature or flag. ## Removed ## Fixed -- Use the right characters for newlines on windows. ## Security +# 0.71.0 (2024-12-06) +## Added +- Add the `ParseCallbacks::new_item_found` callback to expose the original and final name of structs, unions and enums (#2658). +- Add the `field_type_name` field to `FieldInfo` to expose the name of the type of a field (#2863) +- Add support for custom attributes with the `--with-attribute-custom` flag (#2866) +- Allow setting `--rust-target` to any Rust version supported by bindgen (#2993) +- Use c-string literals if the `--generate-cstr` flag is used for Rust targets after 1.77 under the 2021 edition (#2996) +- Add the `--rust-edition` flag which allows to select which Rust edition to target. (#3002, #3013) +- Use `unsafe extern` instead of `extern` in blocks for any Rust target after 1.82. (#3015) +## Changed +- The `--wrap-static-fns` related options no longer require the experimental feature or flag (#2928) +- Use the `Display` implementation instead of the `Debug` one for `BindgenError` in `bindgen-cli` (#3005) +## Removed +- Dropped support for any Clang versions strictly lower than 9.0 (#2932) +- Dropped support for any Rust version strictly lower than 1.33 (#2993) +## Fixed +- Represent opaque types in a FFI-safe way (#2880) +- Use the underlying type of any atomic type instead of panicking (#2920) +- Use the right characters for newlines on windows (#2923) +- Inlined namespaces are properly recognized now (#2950) +- Unsafe calls to `libloading` are now wrapped in `unsafe` blocks when using dynamic loading (#2961) +- The `ParseCallbacks::field_visibility` callback is now called for newtypes as well (#2967) +- Gate the use of the `addr_of` and `addr_of_mut` macros under the 1.51 rust version (#2988) + # 0.70.1 (2024-08-20) ## Added ## Changed From c683f6f7dfac713f9881d12a57de2bdd4e4da4ca Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Sun, 1 Dec 2024 21:33:47 -0500 Subject: [PATCH 816/942] chore: bump versions --- Cargo.lock | 4 ++-- bindgen-cli/Cargo.toml | 2 +- bindgen/Cargo.toml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 142112a213..66a5dff2a8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -35,7 +35,7 @@ checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] name = "bindgen" -version = "0.70.1" +version = "0.71.0" dependencies = [ "annotate-snippets", "bitflags 2.2.1", @@ -56,7 +56,7 @@ dependencies = [ [[package]] name = "bindgen-cli" -version = "0.70.1" +version = "0.71.0" dependencies = [ "bindgen", "env_logger 0.10.0", diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index d1e0bf4012..54430d7fcd 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -13,7 +13,7 @@ readme = "../README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.70.1" +version = "0.71.0" rust-version.workspace = true edition.workspace = true diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index 8f61afe23b..f996e7d843 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -16,7 +16,7 @@ readme = "../README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.70.1" +version = "0.71.0" build = "build.rs" rust-version.workspace = true edition.workspace = true From d3c489f466b26ac062a993c33ba4c3a9f4e58cbe Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Fri, 6 Dec 2024 15:21:26 -0500 Subject: [PATCH 817/942] Add version field to `bindgen` as a dependency --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index cd5e4e6223..d8ab017b0f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ edition = "2021" # All dependency version management is centralized here [workspace.dependencies] annotate-snippets = "0.11.4" -bindgen = { path = "./bindgen", default-features = false } +bindgen = { version = "0.71.0", path = "./bindgen", default-features = false } bitflags = "2.2.1" block = "0.1" cc = "1.0" From d9f049b813dac7c2a163f550aa55c346adddb7e3 Mon Sep 17 00:00:00 2001 From: "Jan Alexander Steffens (heftig)" Date: Sat, 7 Dec 2024 18:54:51 +0100 Subject: [PATCH 818/942] Unbreak shell completion and --version without header This regressed again in #2984. Partially revert d75fe271418e and 42a86e288c43 and restore the previous behavior. Fixes: https://github.com/rust-lang/rust-bindgen/issues/3037 Fixes: https://github.com/rust-lang/rust-bindgen/issues/3039 --- bindgen/options/cli.rs | 52 +++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/bindgen/options/cli.rs b/bindgen/options/cli.rs index 9d5cea3dc6..8c4c05bc84 100644 --- a/bindgen/options/cli.rs +++ b/bindgen/options/cli.rs @@ -146,7 +146,7 @@ fn parse_custom_attribute( #[allow(clippy::doc_markdown)] struct BindgenCommand { /// C or C++ header file. - header: String, + header: Option, /// Path to write depfile to. #[arg(long)] depfile: Option, @@ -657,6 +657,33 @@ where clang_args, } = command; + if let Some(shell) = generate_shell_completions { + clap_complete::generate( + shell, + &mut BindgenCommand::command(), + "bindgen", + &mut io::stdout(), + ); + + exit(0) + } + + if version { + println!( + "bindgen {}", + option_env!("CARGO_PKG_VERSION").unwrap_or("unknown") + ); + if verbose { + println!("Clang: {}", crate::clang_version().full); + } + + exit(0) + } + + if header.is_none() { + return Err(io::Error::new(io::ErrorKind::Other, "Header not found")); + } + let mut builder = builder(); #[derive(Debug)] @@ -804,31 +831,8 @@ where } } - let header = Some(header); - builder = apply_args!( builder { - generate_shell_completions => |_, shell| { - clap_complete::generate( - shell, - &mut BindgenCommand::command(), - "bindgen", - &mut io::stdout(), - ); - - exit(0) - }, - version => |_, _| { - println!( - "bindgen {}", - option_env!("CARGO_PKG_VERSION").unwrap_or("unknown") - ); - if verbose { - println!("Clang: {}", crate::clang_version().full); - } - - exit(0) - }, header, rust_target, rust_edition, From 24045bc8a58adfff4aff33ea25eacee1d3f2d30b Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Sun, 8 Dec 2024 10:33:59 -0500 Subject: [PATCH 819/942] ci: add regression tests for #3037 and #3039 --- .github/workflows/bindgen.yml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index d459fc2fc2..ba95e42e23 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -201,12 +201,27 @@ jobs: ./mdbook build book ./mdbook test book + # FIXME(pvdrz): this should be done inside `bindgen-test` instead + test-no-headers: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Test `--help` + run: cargo run -- --help + + - name: Test `--version` + run: cargo run -- --version + + - name: Test `--generate-shell-completions` + run: cargo run -- --generate-shell-completions=bash + # One job that "summarizes" the success state of this pipeline. This can then # be added to branch protection, rather than having to add each job # separately. success: runs-on: ubuntu-latest - needs: [rustfmt-clippy, msrv, minimal, docs, quickchecking, test-expectations, test, check-cfg, test-book] + needs: [rustfmt-clippy, msrv, minimal, docs, quickchecking, test-expectations, test, check-cfg, test-book, test-no-headers] # GitHub branch protection is exceedingly silly and treats "jobs skipped # because a dependency failed" as success. So we have to do some # contortions to ensure the job fails if any of its dependencies fails. From 4a82cd0a063071c29a8297aca497eaf4cd2ba82a Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Sun, 8 Dec 2024 20:42:18 -0500 Subject: [PATCH 820/942] ci: update `cargo-dist` version --- .github/workflows/release.yml | 49 ++++++++++++++++++----------------- Cargo.toml | 23 ---------------- dist-workspace.toml | 25 ++++++++++++++++++ 3 files changed, 50 insertions(+), 47 deletions(-) create mode 100644 dist-workspace.toml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 61098dea41..0e9bca8310 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,4 +1,4 @@ -# This file was autogenerated by cargo-dist: https://opensource.axo.dev/cargo-dist/ +# This file was autogenerated by dist: https://opensource.axo.dev/cargo-dist/ # # Copyright 2022-2024, axodotdev # SPDX-License-Identifier: MIT or Apache-2.0 @@ -6,7 +6,7 @@ # CI that: # # * checks for a Git Tag that looks like a release -# * builds artifacts with cargo-dist (archives, installers, hashes) +# * builds artifacts with dist (archives, installers, hashes) # * uploads those artifacts to temporary workflow zip # * on success, uploads the artifacts to a GitHub Release # @@ -24,10 +24,10 @@ permissions: # must be a Cargo-style SemVer Version (must have at least major.minor.patch). # # If PACKAGE_NAME is specified, then the announcement will be for that -# package (erroring out if it doesn't have the given version or isn't cargo-dist-able). +# package (erroring out if it doesn't have the given version or isn't dist-able). # # If PACKAGE_NAME isn't specified, then the announcement will be for all -# (cargo-dist-able) packages in the workspace with that version (this mode is +# (dist-able) packages in the workspace with that version (this mode is # intended for workspaces with only one dist-able package, or with all dist-able # packages versioned/released in lockstep). # @@ -39,12 +39,13 @@ permissions: # If there's a prerelease-style suffix to the version, then the release(s) # will be marked as a prerelease. on: + pull_request: push: tags: - '**[0-9]+.[0-9]+.[0-9]+*' jobs: - # Run 'cargo dist plan' (or host) to determine what tasks we need to do + # Run 'dist plan' (or host) to determine what tasks we need to do plan: runs-on: "ubuntu-20.04" outputs: @@ -58,16 +59,16 @@ jobs: - uses: actions/checkout@v4 with: submodules: recursive - - name: Install cargo-dist + - name: Install dist # we specify bash to get pipefail; it guards against the `curl` command # failing. otherwise `sh` won't catch that `curl` returned non-0 shell: bash - run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.22.1/cargo-dist-installer.sh | sh" - - name: Cache cargo-dist + run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.25.1/cargo-dist-installer.sh | sh" + - name: Cache dist uses: actions/upload-artifact@v4 with: name: cargo-dist-cache - path: ~/.cargo/bin/cargo-dist + path: ~/.cargo/bin/dist # sure would be cool if github gave us proper conditionals... # so here's a doubly-nested ternary-via-truthiness to try to provide the best possible # functionality based on whether this is a pull_request, and whether it's from a fork. @@ -75,8 +76,8 @@ jobs: # but also really annoying to build CI around when it needs secrets to work right.) - id: plan run: | - cargo dist ${{ (!github.event.pull_request && format('host --steps=create --tag={0}', github.ref_name)) || 'plan' }} --output-format=json > plan-dist-manifest.json - echo "cargo dist ran successfully" + dist ${{ (!github.event.pull_request && format('host --steps=create --tag={0}', github.ref_name)) || 'plan' }} --output-format=json > plan-dist-manifest.json + echo "dist ran successfully" cat plan-dist-manifest.json echo "manifest=$(jq -c "." plan-dist-manifest.json)" >> "$GITHUB_OUTPUT" - name: "Upload dist-manifest.json" @@ -94,12 +95,12 @@ jobs: if: ${{ fromJson(needs.plan.outputs.val).ci.github.artifacts_matrix.include != null && (needs.plan.outputs.publishing == 'true' || fromJson(needs.plan.outputs.val).ci.github.pr_run_mode == 'upload') }} strategy: fail-fast: false - # Target platforms/runners are computed by cargo-dist in create-release. + # Target platforms/runners are computed by dist in create-release. # Each member of the matrix has the following arguments: # # - runner: the github runner - # - dist-args: cli flags to pass to cargo dist - # - install-dist: expression to run to install cargo-dist on the runner + # - dist-args: cli flags to pass to dist + # - install-dist: expression to run to install dist on the runner # # Typically there will be: # - 1 "global" task that builds universal installers @@ -116,7 +117,7 @@ jobs: - uses: actions/checkout@v4 with: submodules: recursive - - name: Install cargo-dist + - name: Install dist run: ${{ matrix.install_dist }} # Get the dist-manifest - name: Fetch local artifacts @@ -131,8 +132,8 @@ jobs: - name: Build artifacts run: | # Actually do builds and make zips and whatnot - cargo dist build ${{ needs.plan.outputs.tag-flag }} --print=linkage --output-format=json ${{ matrix.dist_args }} > dist-manifest.json - echo "cargo dist ran successfully" + dist build ${{ needs.plan.outputs.tag-flag }} --print=linkage --output-format=json ${{ matrix.dist_args }} > dist-manifest.json + echo "dist ran successfully" - id: cargo-dist name: Post-build # We force bash here just because github makes it really hard to get values up @@ -167,12 +168,12 @@ jobs: - uses: actions/checkout@v4 with: submodules: recursive - - name: Install cached cargo-dist + - name: Install cached dist uses: actions/download-artifact@v4 with: name: cargo-dist-cache path: ~/.cargo/bin/ - - run: chmod +x ~/.cargo/bin/cargo-dist + - run: chmod +x ~/.cargo/bin/dist # Get all the local artifacts for the global tasks to use (for e.g. checksums) - name: Fetch local artifacts uses: actions/download-artifact@v4 @@ -183,8 +184,8 @@ jobs: - id: cargo-dist shell: bash run: | - cargo dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json "--artifacts=global" > dist-manifest.json - echo "cargo dist ran successfully" + dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json "--artifacts=global" > dist-manifest.json + echo "dist ran successfully" # Parse out what we just built and upload it to scratch storage echo "paths<> "$GITHUB_OUTPUT" @@ -216,12 +217,12 @@ jobs: - uses: actions/checkout@v4 with: submodules: recursive - - name: Install cached cargo-dist + - name: Install cached dist uses: actions/download-artifact@v4 with: name: cargo-dist-cache path: ~/.cargo/bin/ - - run: chmod +x ~/.cargo/bin/cargo-dist + - run: chmod +x ~/.cargo/bin/dist # Fetch artifacts from scratch-storage - name: Fetch artifacts uses: actions/download-artifact@v4 @@ -232,7 +233,7 @@ jobs: - id: host shell: bash run: | - cargo dist host ${{ needs.plan.outputs.tag-flag }} --steps=upload --steps=release --output-format=json > dist-manifest.json + dist host ${{ needs.plan.outputs.tag-flag }} --steps=upload --steps=release --output-format=json > dist-manifest.json echo "artifacts uploaded and released successfully" cat dist-manifest.json echo "manifest=$(jq -c "." dist-manifest.json)" >> "$GITHUB_OUTPUT" diff --git a/Cargo.toml b/Cargo.toml index d8ab017b0f..48fbc8e5bd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -61,29 +61,6 @@ tempfile = "3" # unnecessary-cast = "allow" # useless-transmute = "allow" -# Config for 'cargo dist' -[workspace.metadata.dist] -# The preferred cargo-dist version to use in CI (Cargo.toml SemVer syntax) -cargo-dist-version = "0.22.1" -# CI backends to support -ci = "github" -# The installers to generate for each app -installers = ["shell"] -# Target platforms to build apps for (Rust target-triple syntax) -targets = ["aarch64-apple-darwin", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu"] -# Whether to consider the binaries in a package for distribution (defaults true) -dist = false -# Which actions to run on pull requests -pr-run-mode = "plan" -# Whether to install an updater program -install-updater = false -# Path that installers should place binaries in -install-path = "CARGO_HOME" - -[workspace.metadata.dist.github-custom-runners] -aarch64-apple-darwin = "macos-14" -x86_64-apple-darwin = "macos-12" - # Config for 'cargo release' [workspace.metadata.release] shared-version = true # ensures published packages share the same version diff --git a/dist-workspace.toml b/dist-workspace.toml new file mode 100644 index 0000000000..34de313338 --- /dev/null +++ b/dist-workspace.toml @@ -0,0 +1,25 @@ +[workspace] +members = ["cargo:."] + +# Config for 'dist' +[dist] +# The preferred dist version to use in CI (Cargo.toml SemVer syntax) +cargo-dist-version = "0.25.1" +# CI backends to support +ci = "github" +# The installers to generate for each app +installers = ["shell"] +# Target platforms to build apps for (Rust target-triple syntax) +targets = ["aarch64-apple-darwin", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu"] +# Whether to consider the binaries in a package for distribution (defaults true) +dist = false +# Which actions to run on pull requests +pr-run-mode = "plan" +# Whether to install an updater program +install-updater = false +# Path that installers should place binaries in +install-path = "CARGO_HOME" + +[dist.github-custom-runners] +aarch64-apple-darwin = "macos-14" +x86_64-apple-darwin = "macos-12" From 065eff979af211ae9c9cb550b5764ddadc6e6375 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Sun, 8 Dec 2024 21:02:16 -0500 Subject: [PATCH 821/942] ci: only trigger tag creation on github-actions PRs --- .github/workflows/create-tag.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/create-tag.yml b/.github/workflows/create-tag.yml index 27dcbb5741..411a338de8 100644 --- a/.github/workflows/create-tag.yml +++ b/.github/workflows/create-tag.yml @@ -7,7 +7,11 @@ on: jobs: create-tag: - if: github.event.pull_request.merged == true && github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name && startsWith(github.event.pull_request.head.ref, 'bump-version') + if: >- + github.event.pull_request.merged == true && + github.event.pull_request.user.login == 'github-actions' && + github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name && + startsWith(github.event.pull_request.head.ref, 'bump-version') runs-on: ubuntu-latest steps: - name: Checkout code From 0b6b179598cec193a2b61869513123c7129031a0 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Sun, 8 Dec 2024 21:29:14 -0500 Subject: [PATCH 822/942] ci: allow creating tags on manually --- .github/workflows/create-tag.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/create-tag.yml b/.github/workflows/create-tag.yml index 411a338de8..2eaa95e8b0 100644 --- a/.github/workflows/create-tag.yml +++ b/.github/workflows/create-tag.yml @@ -4,10 +4,16 @@ on: pull_request: types: - closed - + workflow_dispatch: + inputs: + commit: + description: 'Commit hash' + required: true + type: string jobs: create-tag: if: >- + (inputs.commit || false) github.event.pull_request.merged == true && github.event.pull_request.user.login == 'github-actions' && github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name && @@ -16,6 +22,8 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 + with: + ref: ${{ inputs.commit || '' }} - name: Install rust toolchain uses: dtolnay/rust-toolchain@stable From 3ef74b0296eb8a1654e3ef6b79572bf99d09857a Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Sun, 8 Dec 2024 21:34:07 -0500 Subject: [PATCH 823/942] ci: sign tag --- .github/workflows/create-tag.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/create-tag.yml b/.github/workflows/create-tag.yml index 2eaa95e8b0..2ea41bd333 100644 --- a/.github/workflows/create-tag.yml +++ b/.github/workflows/create-tag.yml @@ -35,5 +35,5 @@ jobs: - name: Create tag run: | TAG_NAME="v${{ env.version }}" - git tag $TAG_NAME + git tag -s $TAG_NAME git push origin $TAG_NAME From 0dec419d43553d3a48479e4b053d65d93ac44a5f Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Sun, 8 Dec 2024 21:43:19 -0500 Subject: [PATCH 824/942] ci: checkout to the right commit --- .github/workflows/create-tag.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/create-tag.yml b/.github/workflows/create-tag.yml index 2ea41bd333..2663395c5f 100644 --- a/.github/workflows/create-tag.yml +++ b/.github/workflows/create-tag.yml @@ -22,8 +22,15 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 - with: - ref: ${{ inputs.commit || '' }} + + - name: Checkout to the input commit + run: | + if [[ -z "${{ inputs.commit }}" ]]; then + COMMIT="${{ inputs.commit }}" + else + COMMIT=git rev-parse ${{ github.sha }}^@ | grep -Fvx ${{ github.event.pull_request.head.sha }} + fi + git checkout $COMMIT - name: Install rust toolchain uses: dtolnay/rust-toolchain@stable From 08f721ce329c90a187c505ed61900044bce98c54 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Sun, 8 Dec 2024 22:04:04 -0500 Subject: [PATCH 825/942] ci: add missing `&&` on `create-tag.yml` --- .github/workflows/create-tag.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/create-tag.yml b/.github/workflows/create-tag.yml index 2663395c5f..d35082f253 100644 --- a/.github/workflows/create-tag.yml +++ b/.github/workflows/create-tag.yml @@ -13,7 +13,7 @@ on: jobs: create-tag: if: >- - (inputs.commit || false) + (inputs.commit || false) && github.event.pull_request.merged == true && github.event.pull_request.user.login == 'github-actions' && github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name && From bff68e2afc86f0dba136d42efaa39ff09100406e Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Sun, 8 Dec 2024 22:28:51 -0500 Subject: [PATCH 826/942] chore: fix `create-tag` conditional logic --- .github/workflows/create-tag.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/create-tag.yml b/.github/workflows/create-tag.yml index d35082f253..acb6419219 100644 --- a/.github/workflows/create-tag.yml +++ b/.github/workflows/create-tag.yml @@ -13,11 +13,11 @@ on: jobs: create-tag: if: >- - (inputs.commit || false) && - github.event.pull_request.merged == true && - github.event.pull_request.user.login == 'github-actions' && - github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name && - startsWith(github.event.pull_request.head.ref, 'bump-version') + (inputs.commit || false) || + (github.event.pull_request.merged == true && + github.event.pull_request.user.login == 'github-actions' && + github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name && + startsWith(github.event.pull_request.head.ref, 'bump-version') ) runs-on: ubuntu-latest steps: - name: Checkout code From 8c6a62f2f4b0e11d09ecd7e5d3a65468614b4fbe Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Sun, 8 Dec 2024 22:35:30 -0500 Subject: [PATCH 827/942] ci: fix `git rev-parse` --- .github/workflows/create-tag.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/create-tag.yml b/.github/workflows/create-tag.yml index acb6419219..0ec4fc8e6c 100644 --- a/.github/workflows/create-tag.yml +++ b/.github/workflows/create-tag.yml @@ -28,7 +28,7 @@ jobs: if [[ -z "${{ inputs.commit }}" ]]; then COMMIT="${{ inputs.commit }}" else - COMMIT=git rev-parse ${{ github.sha }}^@ | grep -Fvx ${{ github.event.pull_request.head.sha }} + COMMIT=$(git rev-parse ${{ github.sha }}^@ | grep -Fvx ${{ github.event.pull_request.head.sha }}) fi git checkout $COMMIT From 7019d0dc605067ad19b36a2e6dfa697913570127 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Sun, 8 Dec 2024 22:39:46 -0500 Subject: [PATCH 828/942] ci: invert conditional --- .github/workflows/create-tag.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/create-tag.yml b/.github/workflows/create-tag.yml index 0ec4fc8e6c..02760909bd 100644 --- a/.github/workflows/create-tag.yml +++ b/.github/workflows/create-tag.yml @@ -26,9 +26,9 @@ jobs: - name: Checkout to the input commit run: | if [[ -z "${{ inputs.commit }}" ]]; then - COMMIT="${{ inputs.commit }}" - else COMMIT=$(git rev-parse ${{ github.sha }}^@ | grep -Fvx ${{ github.event.pull_request.head.sha }}) + else + COMMIT="${{ inputs.commit }}" fi git checkout $COMMIT From a6dcf41aa7ef86a756db297fbe751940e197ee97 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Sun, 8 Dec 2024 22:47:28 -0500 Subject: [PATCH 829/942] ci: fetch all the history --- .github/workflows/create-tag.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/create-tag.yml b/.github/workflows/create-tag.yml index 02760909bd..8f47f2d830 100644 --- a/.github/workflows/create-tag.yml +++ b/.github/workflows/create-tag.yml @@ -22,6 +22,8 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Checkout to the input commit run: | From d02d556e3f50827d70b315dcadc2f3e3cdf27b87 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Sun, 8 Dec 2024 23:21:11 -0500 Subject: [PATCH 830/942] chore: use custom action to create the tag --- .github/workflows/create-tag.yml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/create-tag.yml b/.github/workflows/create-tag.yml index 8f47f2d830..f636991c38 100644 --- a/.github/workflows/create-tag.yml +++ b/.github/workflows/create-tag.yml @@ -25,14 +25,14 @@ jobs: with: fetch-depth: 0 - - name: Checkout to the input commit + - name: Compute the commit run: | if [[ -z "${{ inputs.commit }}" ]]; then COMMIT=$(git rev-parse ${{ github.sha }}^@ | grep -Fvx ${{ github.event.pull_request.head.sha }}) else COMMIT="${{ inputs.commit }}" fi - git checkout $COMMIT + echo "commit=$COMMIT" >> $GITHUB_ENV - name: Install rust toolchain uses: dtolnay/rust-toolchain@stable @@ -42,7 +42,8 @@ jobs: echo "version=$(cargo pkgid -p bindgen | cut -d '#' -f 2)" >> $GITHUB_ENV - name: Create tag - run: | - TAG_NAME="v${{ env.version }}" - git tag -s $TAG_NAME - git push origin $TAG_NAME + uses: mathieudutour/github-tag-action@v6.2 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + commit_sha: ${{ env.commit }} + custom_tag: ${{ env.version }} From 76fff5e720583eaaca05d50d6bddc157fce77c9c Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Sun, 8 Dec 2024 23:37:41 -0500 Subject: [PATCH 831/942] ci: Revert `cargo-dist` update apparently `cargo dist init` and `dist init` produce different results. --- .github/workflows/release.yml | 48 +++++++++++++++++------------------ dist-workspace.toml | 6 ++--- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0e9bca8310..5df0c7b1c1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,4 +1,4 @@ -# This file was autogenerated by dist: https://opensource.axo.dev/cargo-dist/ +# This file was autogenerated by cargo-dist: https://opensource.axo.dev/cargo-dist/ # # Copyright 2022-2024, axodotdev # SPDX-License-Identifier: MIT or Apache-2.0 @@ -6,7 +6,7 @@ # CI that: # # * checks for a Git Tag that looks like a release -# * builds artifacts with dist (archives, installers, hashes) +# * builds artifacts with cargo-dist (archives, installers, hashes) # * uploads those artifacts to temporary workflow zip # * on success, uploads the artifacts to a GitHub Release # @@ -24,10 +24,10 @@ permissions: # must be a Cargo-style SemVer Version (must have at least major.minor.patch). # # If PACKAGE_NAME is specified, then the announcement will be for that -# package (erroring out if it doesn't have the given version or isn't dist-able). +# package (erroring out if it doesn't have the given version or isn't cargo-dist-able). # # If PACKAGE_NAME isn't specified, then the announcement will be for all -# (dist-able) packages in the workspace with that version (this mode is +# (cargo-dist-able) packages in the workspace with that version (this mode is # intended for workspaces with only one dist-able package, or with all dist-able # packages versioned/released in lockstep). # @@ -45,7 +45,7 @@ on: - '**[0-9]+.[0-9]+.[0-9]+*' jobs: - # Run 'dist plan' (or host) to determine what tasks we need to do + # Run 'cargo dist plan' (or host) to determine what tasks we need to do plan: runs-on: "ubuntu-20.04" outputs: @@ -59,16 +59,16 @@ jobs: - uses: actions/checkout@v4 with: submodules: recursive - - name: Install dist + - name: Install cargo-dist # we specify bash to get pipefail; it guards against the `curl` command # failing. otherwise `sh` won't catch that `curl` returned non-0 shell: bash - run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.25.1/cargo-dist-installer.sh | sh" - - name: Cache dist + run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.22.1/cargo-dist-installer.sh | sh" + - name: Cache cargo-dist uses: actions/upload-artifact@v4 with: name: cargo-dist-cache - path: ~/.cargo/bin/dist + path: ~/.cargo/bin/cargo-dist # sure would be cool if github gave us proper conditionals... # so here's a doubly-nested ternary-via-truthiness to try to provide the best possible # functionality based on whether this is a pull_request, and whether it's from a fork. @@ -76,8 +76,8 @@ jobs: # but also really annoying to build CI around when it needs secrets to work right.) - id: plan run: | - dist ${{ (!github.event.pull_request && format('host --steps=create --tag={0}', github.ref_name)) || 'plan' }} --output-format=json > plan-dist-manifest.json - echo "dist ran successfully" + cargo dist ${{ (!github.event.pull_request && format('host --steps=create --tag={0}', github.ref_name)) || 'plan' }} --output-format=json > plan-dist-manifest.json + echo "cargo dist ran successfully" cat plan-dist-manifest.json echo "manifest=$(jq -c "." plan-dist-manifest.json)" >> "$GITHUB_OUTPUT" - name: "Upload dist-manifest.json" @@ -95,12 +95,12 @@ jobs: if: ${{ fromJson(needs.plan.outputs.val).ci.github.artifacts_matrix.include != null && (needs.plan.outputs.publishing == 'true' || fromJson(needs.plan.outputs.val).ci.github.pr_run_mode == 'upload') }} strategy: fail-fast: false - # Target platforms/runners are computed by dist in create-release. + # Target platforms/runners are computed by cargo-dist in create-release. # Each member of the matrix has the following arguments: # # - runner: the github runner - # - dist-args: cli flags to pass to dist - # - install-dist: expression to run to install dist on the runner + # - dist-args: cli flags to pass to cargo dist + # - install-dist: expression to run to install cargo-dist on the runner # # Typically there will be: # - 1 "global" task that builds universal installers @@ -117,7 +117,7 @@ jobs: - uses: actions/checkout@v4 with: submodules: recursive - - name: Install dist + - name: Install cargo-dist run: ${{ matrix.install_dist }} # Get the dist-manifest - name: Fetch local artifacts @@ -132,8 +132,8 @@ jobs: - name: Build artifacts run: | # Actually do builds and make zips and whatnot - dist build ${{ needs.plan.outputs.tag-flag }} --print=linkage --output-format=json ${{ matrix.dist_args }} > dist-manifest.json - echo "dist ran successfully" + cargo dist build ${{ needs.plan.outputs.tag-flag }} --print=linkage --output-format=json ${{ matrix.dist_args }} > dist-manifest.json + echo "cargo dist ran successfully" - id: cargo-dist name: Post-build # We force bash here just because github makes it really hard to get values up @@ -168,12 +168,12 @@ jobs: - uses: actions/checkout@v4 with: submodules: recursive - - name: Install cached dist + - name: Install cached cargo-dist uses: actions/download-artifact@v4 with: name: cargo-dist-cache path: ~/.cargo/bin/ - - run: chmod +x ~/.cargo/bin/dist + - run: chmod +x ~/.cargo/bin/cargo-dist # Get all the local artifacts for the global tasks to use (for e.g. checksums) - name: Fetch local artifacts uses: actions/download-artifact@v4 @@ -184,8 +184,8 @@ jobs: - id: cargo-dist shell: bash run: | - dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json "--artifacts=global" > dist-manifest.json - echo "dist ran successfully" + cargo dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json "--artifacts=global" > dist-manifest.json + echo "cargo dist ran successfully" # Parse out what we just built and upload it to scratch storage echo "paths<> "$GITHUB_OUTPUT" @@ -217,12 +217,12 @@ jobs: - uses: actions/checkout@v4 with: submodules: recursive - - name: Install cached dist + - name: Install cached cargo-dist uses: actions/download-artifact@v4 with: name: cargo-dist-cache path: ~/.cargo/bin/ - - run: chmod +x ~/.cargo/bin/dist + - run: chmod +x ~/.cargo/bin/cargo-dist # Fetch artifacts from scratch-storage - name: Fetch artifacts uses: actions/download-artifact@v4 @@ -233,7 +233,7 @@ jobs: - id: host shell: bash run: | - dist host ${{ needs.plan.outputs.tag-flag }} --steps=upload --steps=release --output-format=json > dist-manifest.json + cargo dist host ${{ needs.plan.outputs.tag-flag }} --steps=upload --steps=release --output-format=json > dist-manifest.json echo "artifacts uploaded and released successfully" cat dist-manifest.json echo "manifest=$(jq -c "." dist-manifest.json)" >> "$GITHUB_OUTPUT" diff --git a/dist-workspace.toml b/dist-workspace.toml index 34de313338..3f559f28ef 100644 --- a/dist-workspace.toml +++ b/dist-workspace.toml @@ -1,10 +1,10 @@ [workspace] members = ["cargo:."] -# Config for 'dist' +# Config for 'cargo dist' [dist] -# The preferred dist version to use in CI (Cargo.toml SemVer syntax) -cargo-dist-version = "0.25.1" +# The preferred cargo-dist version to use in CI (Cargo.toml SemVer syntax) +cargo-dist-version = "0.22.1" # CI backends to support ci = "github" # The installers to generate for each app From 8109b37e73070e796800e0e2b3b7bf4b852a9fb0 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Sun, 8 Dec 2024 22:11:37 -0500 Subject: [PATCH 832/942] chore: update changelog for release --- CHANGELOG.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5fceec85ca..0f6946e876 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,6 @@ - [Changed](#changed) - [Removed](#removed) - [Fixed](#fixed) - - [Security](#security) - [0.71.0 (2024-12-06)](#0710-2024-12-06) - [Added](#added-1) - [Changed](#changed-1) @@ -219,11 +218,8 @@ -------------------------------------------------------------------------------- # Unreleased -## Added -## Changed -## Removed ## Fixed -## Security +- Fix `--version` and `--generate-shell-completions` (#3040) # 0.71.0 (2024-12-06) ## Added From 89659a84a9cbfdc5ddbc3cb064d4d555be45fbc8 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Mon, 9 Dec 2024 10:02:16 -0500 Subject: [PATCH 833/942] ci: bump macos image for x86 binaries --- dist-workspace.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist-workspace.toml b/dist-workspace.toml index 3f559f28ef..3a0f7c2c75 100644 --- a/dist-workspace.toml +++ b/dist-workspace.toml @@ -22,4 +22,4 @@ install-path = "CARGO_HOME" [dist.github-custom-runners] aarch64-apple-darwin = "macos-14" -x86_64-apple-darwin = "macos-12" +x86_64-apple-darwin = "macos-13" From af7fd38d5e80514406fb6a8bba2d407d252c30b9 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Mon, 9 Dec 2024 10:07:23 -0500 Subject: [PATCH 834/942] chore: bump versions and update changelog --- CHANGELOG.md | 100 ++++++++++++++++++++++------------------- Cargo.lock | 4 +- Cargo.toml | 2 +- bindgen-cli/Cargo.toml | 2 +- bindgen/Cargo.toml | 2 +- 5 files changed, 60 insertions(+), 50 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f6946e876..b7ca9f2124 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,56 +6,59 @@ - [Changed](#changed) - [Removed](#removed) - [Fixed](#fixed) + - [Security](#security) +- [v0.71.1 (2024-12-09)](#v0711-2024-12-09) + - [Fixed](#fixed-1) - [0.71.0 (2024-12-06)](#0710-2024-12-06) - [Added](#added-1) - [Changed](#changed-1) - [Removed](#removed-1) - - [Fixed](#fixed-1) + - [Fixed](#fixed-2) - [0.70.1 (2024-08-20)](#0701-2024-08-20) - [Added](#added-2) - [Changed](#changed-2) - [Removed](#removed-2) - - [Fixed](#fixed-2) + - [Fixed](#fixed-3) - [Security](#security-1) - [0.70.0 (2024-08-16)](#0700-2024-08-16) - [Added](#added-3) - [Changed](#changed-3) - [Removed](#removed-3) - - [Fixed](#fixed-3) + - [Fixed](#fixed-4) - [Security](#security-2) - [0.69.4 (2024-02-04)](#0694-2024-02-04) - [Added](#added-4) - [Changed](#changed-4) - [Removed](#removed-4) - - [Fixed](#fixed-4) + - [Fixed](#fixed-5) - [Security](#security-3) - [0.69.3 (2024-02-04)](#0693-2024-02-04) - [Added](#added-5) - [Changed](#changed-5) - [Removed](#removed-5) - - [Fixed](#fixed-5) + - [Fixed](#fixed-6) - [Security](#security-4) - [0.69.2 (2024-01-13)](#0692-2024-01-13) - [Added](#added-6) - [Changed](#changed-6) - [Removed](#removed-6) - - [Fixed](#fixed-6) + - [Fixed](#fixed-7) - [Security](#security-5) - [0.69.1 (2023-11-02)](#0691-2023-11-02) - - [Fixed](#fixed-7) + - [Fixed](#fixed-8) - [0.69.0 (2023-11-01)](#0690-2023-11-01) - [Added](#added-7) - [Changed](#changed-7) - [Removed](#removed-7) - - [Fixed](#fixed-8) + - [Fixed](#fixed-9) - [Security](#security-6) - [0.68.1](#0681) - - [Fixed](#fixed-9) + - [Fixed](#fixed-10) - [0.68.0](#0680) - [Added](#added-8) - [Changed](#changed-8) - [Removed](#removed-8) - - [Fixed](#fixed-10) + - [Fixed](#fixed-11) - [0.67.0](#0670) - [0.66.1](#0661) - [Removed](#removed-9) @@ -64,7 +67,7 @@ - [Changed](#changed-9) - [Removed](#removed-10) - [0.65.1](#0651) - - [Fixed](#fixed-11) + - [Fixed](#fixed-12) - [0.65.0](#0650) - [Added](#added-10) - [Changed](#changed-10) @@ -79,60 +82,60 @@ - [0.62.0](#0620) - [Added](#added-13) - [Changed](#changed-13) - - [Fixed](#fixed-12) + - [Fixed](#fixed-13) - [0.61.0](#0610) - [Added](#added-14) - [Changed](#changed-14) - - [Fixed](#fixed-13) -- [0.60.1](#0601) - [Fixed](#fixed-14) +- [0.60.1](#0601) + - [Fixed](#fixed-15) - [0.60.0](#0600) - [Added](#added-15) - - [Fixed](#fixed-15) + - [Fixed](#fixed-16) - [Changed](#changed-15) - [Removed](#removed-13) - [0.59.2](#0592) - [0.59.1](#0591) - - [Fixed](#fixed-16) + - [Fixed](#fixed-17) - [0.59.0](#0590) - [Added](#added-16) - - [Fixed](#fixed-17) + - [Fixed](#fixed-18) - [Changed](#changed-16) - [0.58.1](#0581) - [Added](#added-17) - [0.58.0](#0580) - [Added](#added-18) - - [Fixed](#fixed-18) + - [Fixed](#fixed-19) - [Changed](#changed-17) - [Deprecated](#deprecated) - [Removed](#removed-14) - - [Fixed](#fixed-19) + - [Fixed](#fixed-20) - [Security](#security-7) - [0.57.0](#0570) - [Added](#added-19) - - [Fixed](#fixed-20) + - [Fixed](#fixed-21) - [0.56.0](#0560) - [Added](#added-20) - [Changed](#changed-18) - - [Fixed](#fixed-21) -- [0.55.1](#0551) - [Fixed](#fixed-22) +- [0.55.1](#0551) + - [Fixed](#fixed-23) - [0.55.0](#0550) - [Removed](#removed-15) - [Added](#added-21) - [Changed](#changed-19) - - [Fixed](#fixed-23) + - [Fixed](#fixed-24) - [0.54.1](#0541) - [Added](#added-22) - [Changed](#changed-20) - - [Fixed](#fixed-24) + - [Fixed](#fixed-25) - [0.54.0](#0540) - [Added](#added-23) - [Changed](#changed-21) - - [Fixed](#fixed-25) + - [Fixed](#fixed-26) - [0.53.3](#0533) - [Added](#added-24) - - [Fixed](#fixed-26) + - [Fixed](#fixed-27) - [0.53.2](#0532) - [Changed](#changed-22) - [0.53.1](#0531) @@ -140,16 +143,16 @@ - [0.53.0](#0530) - [Added](#added-26) - [Changed](#changed-23) - - [Fixed](#fixed-27) + - [Fixed](#fixed-28) - [0.52.0](#0520) - [Added](#added-27) - [Changed](#changed-24) - - [Fixed](#fixed-28) -- [0.51.1](#0511) - [Fixed](#fixed-29) +- [0.51.1](#0511) + - [Fixed](#fixed-30) - [Changed](#changed-25) - [0.51.0](#0510) - - [Fixed](#fixed-30) + - [Fixed](#fixed-31) - [Changed](#changed-26) - [Added](#added-28) - [0.50.0](#0500) @@ -159,65 +162,72 @@ - [0.49.2](#0492) - [Changed](#changed-27) - [0.49.1](#0491) - - [Fixed](#fixed-31) + - [Fixed](#fixed-32) - [Changed](#changed-28) - [0.49.0](#0490) - [Added](#added-31) - - [Fixed](#fixed-32) + - [Fixed](#fixed-33) - [Changed](#changed-29) - [0.48.1](#0481) - - [Fixed](#fixed-33) + - [Fixed](#fixed-34) - [0.48.0](#0480) - [Changed](#changed-30) - - [Fixed](#fixed-34) + - [Fixed](#fixed-35) - [0.47.4](#0474) - [Added](#added-32) - [0.47.3](#0473) - [Changed](#changed-31) - [0.47.2](#0472) - - [Fixed](#fixed-35) + - [Fixed](#fixed-36) - [0.47.1](#0471) - [Changed](#changed-32) - - [Fixed](#fixed-36) + - [Fixed](#fixed-37) - [0.47.0](#0470) - [Changed](#changed-33) - - [Fixed](#fixed-37) + - [Fixed](#fixed-38) - [0.33.1 .. 0.46.0](#0331--0460) - [Added](#added-33) - [Removed](#removed-16) - [Changed](#changed-34) - - [Fixed](#fixed-38) -- [0.33.1](#0331) - [Fixed](#fixed-39) +- [0.33.1](#0331) + - [Fixed](#fixed-40) - [0.33.0](#0330) - [0.32.2](#0322) - - [Fixed](#fixed-40) -- [0.32.1](#0321) - [Fixed](#fixed-41) +- [0.32.1](#0321) + - [Fixed](#fixed-42) - [0.32.0](#0320) - [Added](#added-34) - [Changed](#changed-35) - - [Fixed](#fixed-42) + - [Fixed](#fixed-43) - [0.31.0](#0310) - [Added](#added-35) - [Changed](#changed-36) - [Deprecated](#deprecated-1) - [Removed](#removed-17) - - [Fixed](#fixed-43) + - [Fixed](#fixed-44) - [0.30.0](#0300) - [Added](#added-36) - [Changed](#changed-37) - [Deprecated](#deprecated-2) - - [Fixed](#fixed-44) + - [Fixed](#fixed-45) - [0.29.0](#0290) - [Added](#added-37) - [Changed](#changed-38) - - [Fixed](#fixed-45) + - [Fixed](#fixed-46) -------------------------------------------------------------------------------- # Unreleased +## Added +## Changed +## Removed +## Fixed +## Security + +# v0.71.1 (2024-12-09) ## Fixed - Fix `--version` and `--generate-shell-completions` (#3040) diff --git a/Cargo.lock b/Cargo.lock index 66a5dff2a8..4e88c224f5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -35,7 +35,7 @@ checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] name = "bindgen" -version = "0.71.0" +version = "0.71.1" dependencies = [ "annotate-snippets", "bitflags 2.2.1", @@ -56,7 +56,7 @@ dependencies = [ [[package]] name = "bindgen-cli" -version = "0.71.0" +version = "0.71.1" dependencies = [ "bindgen", "env_logger 0.10.0", diff --git a/Cargo.toml b/Cargo.toml index 48fbc8e5bd..e66777da95 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ edition = "2021" # All dependency version management is centralized here [workspace.dependencies] annotate-snippets = "0.11.4" -bindgen = { version = "0.71.0", path = "./bindgen", default-features = false } +bindgen = { version = "0.71.1", path = "./bindgen", default-features = false } bitflags = "2.2.1" block = "0.1" cc = "1.0" diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index 54430d7fcd..52fcaaeb1b 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -13,7 +13,7 @@ readme = "../README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.71.0" +version = "0.71.1" rust-version.workspace = true edition.workspace = true diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index f996e7d843..c01f8f0c44 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -16,7 +16,7 @@ readme = "../README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.71.0" +version = "0.71.1" build = "build.rs" rust-version.workspace = true edition.workspace = true From a36fe18e644685e6302edd240e0d093c11dc6136 Mon Sep 17 00:00:00 2001 From: Matthijs Brobbel Date: Mon, 9 Dec 2024 22:04:40 +0100 Subject: [PATCH 835/942] Update `proc-macro2` version requirement to `1.0.80` --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index e66777da95..58d8707e48 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,7 @@ log = "0.4" objc = "0.2" owo-colors = "4.1.0" prettyplease = "0.2.7" -proc-macro2 = "1" +proc-macro2 = "1.0.80" quickcheck = "1.0" quote = { version = "1", default-features = false } regex = { version = "1.5.3", default-features = false } From 856dcacbcb70765a8bf0ef6040a4665ad84ad603 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Mon, 9 Dec 2024 17:20:25 +0100 Subject: [PATCH 836/942] Use the latest verison of mBook to fix copy to clipboard Before this copy code to clipboard on pages with playground (tutorial-5.md) was copying the hidden lines --- .github/workflows/deploy-book.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-book.yml b/.github/workflows/deploy-book.yml index 5eaeed5839..7b8cacc55d 100644 --- a/.github/workflows/deploy-book.yml +++ b/.github/workflows/deploy-book.yml @@ -15,7 +15,7 @@ jobs: - name: Test book run: | - curl -L https://github.com/rust-lang/mdBook/releases/download/v0.4.5/mdbook-v0.4.5-x86_64-unknown-linux-gnu.tar.gz | tar xz + curl -L https://github.com/rust-lang/mdBook/releases/download/v0.4.34/mdbook-v0.4.34-x86_64-unknown-linux-gnu.tar.gz | tar xz ./mdbook build book ./mdbook test book From 1cd618e4a98c78a418cb778576744f6c7ae01f59 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Sun, 8 Dec 2024 21:31:12 +0100 Subject: [PATCH 837/942] Update tutorial To the latest version of bindgen Resolve the deprecation warning on CargoCallbacks --- book/src/tutorial-1.md | 2 +- book/src/tutorial-3.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/book/src/tutorial-1.md b/book/src/tutorial-1.md index 464b6b9d71..a26c393b3b 100644 --- a/book/src/tutorial-1.md +++ b/book/src/tutorial-1.md @@ -10,7 +10,7 @@ You can always check the latest version at ```toml [build-dependencies] -bindgen = "0.65.1" +bindgen = "0.71.0" ``` > ⚠ **Warning** diff --git a/book/src/tutorial-3.md b/book/src/tutorial-3.md index b2d15dbc59..3248f2847f 100644 --- a/book/src/tutorial-3.md +++ b/book/src/tutorial-3.md @@ -30,7 +30,7 @@ fn main() { .header("wrapper.h") // Tell cargo to invalidate the built crate whenever any of the // included header files changed. - .parse_callbacks(Box::new(bindgen::CargoCallbacks)) + .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) // Finish the builder and generate the bindings. .generate() // Unwrap the Result and panic on failure. From 3e0094ea4a240ae1b10bc46ae5db11f0bd46714a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Gonz=C3=A1lez?= Date: Fri, 13 Dec 2024 19:22:54 +0100 Subject: [PATCH 838/942] Derive `Debug` and eq. comparison traits for `InvalidRustTarget` enum These traits are useful to get expressions like `RustTarget::stable(82, 0).unwrap()` to build, as `unwrap()` requires such a `Result` to implement `Debug`. The equality comparison traits may also be useful in cases where pattern matching the enum variants through e.g. `matches!` or match expressions is deemed less stylish. --- bindgen/features.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/bindgen/features.rs b/bindgen/features.rs index 9871a58ecf..5864b88f42 100644 --- a/bindgen/features.rs +++ b/bindgen/features.rs @@ -67,6 +67,7 @@ enum Version { Nightly, } +#[derive(Debug, PartialEq, Eq, Hash)] pub enum InvalidRustTarget { TooEarly, } From 09173995c5e5e90198f1179894cdc16ae9c9dda4 Mon Sep 17 00:00:00 2001 From: Attila Repka Date: Thu, 26 Dec 2024 17:14:39 +0100 Subject: [PATCH 839/942] docs(book): fix deprecated bindgen constant in example --- book/src/non-system-libraries.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/book/src/non-system-libraries.md b/book/src/non-system-libraries.md index b080db80d7..598889d360 100644 --- a/book/src/non-system-libraries.md +++ b/book/src/non-system-libraries.md @@ -20,8 +20,6 @@ library: use std::env; use std::path::PathBuf; -use bindgen::CargoCallbacks; - fn main() { // This is the directory where the `c` library is located. let libdir_path = PathBuf::from("hello") @@ -86,7 +84,7 @@ fn main() { .header(headers_path_str) // Tell cargo to invalidate the built crate whenever any of the // included header files changed. - .parse_callbacks(Box::new(CargoCallbacks::new())) + .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) // Finish the builder and generate the bindings. .generate() // Unwrap the Result and panic on failure. From 78adb33b75c2cae08c23fa6d62f061e87df7addf Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Thu, 26 Dec 2024 22:51:02 -0500 Subject: [PATCH 840/942] Multiple minor lint fixes Added all detected pedantic lints, and allowed them all to keep track of them because some should be fixed. Also fixed a few minor simple ones. --- .github/workflows/bindgen.yml | 2 +- Cargo.toml | 53 +++++++++++++++---- .../item_discovery_callback/mod.rs | 19 +++---- bindgen-tests/tests/quickchecking/src/bin.rs | 7 +-- bindgen-tests/tests/tests.rs | 7 +-- bindgen/clang.rs | 2 +- bindgen/codegen/mod.rs | 4 +- bindgen/ir/context.rs | 26 ++++----- bindgen/ir/function.rs | 2 +- bindgen/ir/item.rs | 13 ++--- bindgen/ir/ty.rs | 4 +- bindgen/lib.rs | 10 ++-- bindgen/time.rs | 2 +- 13 files changed, 87 insertions(+), 64 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index ba95e42e23..df17f2c579 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -30,7 +30,7 @@ jobs: run: cargo fmt -- --check - name: Run clippy - run: cargo clippy --tests + run: cargo clippy --all-targets --workspace --exclude bindgen-integration --exclude tests_expectations msrv: runs-on: ubuntu-latest diff --git a/Cargo.toml b/Cargo.toml index 58d8707e48..248c041378 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,18 +48,51 @@ syn = "2.0" tempfile = "3" [workspace.lints.rust] -# unused_qualifications = "warn" +unused_qualifications = "warn" [workspace.lints.clippy] -# disallowed-names = "allow" -# manual-c-str-literals = "allow" -# missing-safety-doc = "allow" -# op-ref = "allow" -# ptr-offset-with-cast = "allow" -# too-many-arguments = "allow" -# transmute-int-to-bool = "allow" -# unnecessary-cast = "allow" -# useless-transmute = "allow" +pedantic = { level = "warn", priority = -1 } + +cast_possible_truncation = "allow" +cast_possible_wrap = "allow" +cast_precision_loss = "allow" +cast_sign_loss = "allow" +checked_conversions = "allow" +default_trait_access = "allow" +explicit_into_iter_loop = "allow" +flat_map_option = "allow" +ignored_unit_patterns = "allow" +implicit_hasher = "allow" +inconsistent_struct_constructor = "allow" +items_after_statements = "allow" +maybe_infinite_iter = "allow" +missing_errors_doc = "allow" +missing_panics_doc = "allow" +module_name_repetitions = "allow" +must_use_candidate = "allow" +ptr_as_ptr = "allow" +redundant_closure_for_method_calls = "allow" +return_self_not_must_use = "allow" +#should_panic_without_expect = "allow" +similar_names = "allow" +struct_excessive_bools = "allow" +struct_field_names = "allow" +unnecessary_wraps = "allow" +unnested_or_patterns = "allow" +unreadable_literal = "allow" +used_underscore_binding = "allow" +wildcard_imports = "allow" + +# TODO +borrow_as_ptr = "allow" +match_same_arms = "allow" +trivially_copy_pass_by_ref = "allow" +needless_pass_by_value = "allow" +unused_self = "allow" + +# Theese seem to be ok to ignore for now +enum_glob_use = "allow" +too_many_lines = "allow" # Config for 'cargo release' [workspace.metadata.release] diff --git a/bindgen-tests/tests/parse_callbacks/item_discovery_callback/mod.rs b/bindgen-tests/tests/parse_callbacks/item_discovery_callback/mod.rs index da37eeec97..b48d2d7c19 100644 --- a/bindgen-tests/tests/parse_callbacks/item_discovery_callback/mod.rs +++ b/bindgen-tests/tests/parse_callbacks/item_discovery_callback/mod.rs @@ -94,12 +94,10 @@ pub fn compare_item_caches(generated: ItemCache, expected: ItemCache) { ) }); - if found.is_none() { - panic!( - "Missing Expected Item: {:#?}\n in {:#?}", - expected_item, generated - ); - } + assert!( + found.is_some(), + "Missing Expected Item: {expected_item:#?}\n in {generated:#?}" + ); } } @@ -235,12 +233,9 @@ pub fn compare_alias_info( let expected_aliased = expected.get(expected_alias_for).unwrap(); // We must have the aliased type in the cache - let generated_aliased = - if let Some(generated_aliased) = generated.get(generated_alias_for) { - generated_aliased - } else { - return false; - }; + let Some(generated_aliased) = generated.get(generated_alias_for) else { + return false; + }; compare_item_info(expected_aliased, generated_aliased, expected, generated) } diff --git a/bindgen-tests/tests/quickchecking/src/bin.rs b/bindgen-tests/tests/quickchecking/src/bin.rs index 66da94fe7e..3072bc7b46 100644 --- a/bindgen-tests/tests/quickchecking/src/bin.rs +++ b/bindgen-tests/tests/quickchecking/src/bin.rs @@ -41,9 +41,10 @@ fn parse_tests_count(v: &str) -> Result { // Parse CLI argument input for fuzzed headers output path. fn parse_path(v: &str) -> Result { let path = PathBuf::from(v); - match path.is_dir() { - true => Ok(path), - false => Err(String::from("Provided directory path does not exist.")), + if path.is_dir() { + Ok(path) + } else { + Err(String::from("Provided directory path does not exist.")) } } diff --git a/bindgen-tests/tests/tests.rs b/bindgen-tests/tests/tests.rs index fc0b41d187..b808dfcd43 100644 --- a/bindgen-tests/tests/tests.rs +++ b/bindgen-tests/tests/tests.rs @@ -26,9 +26,10 @@ fn should_overwrite_expected() -> bool { if var == "1" { return true; } - if var != "0" && var != "" { - panic!("Invalid value of BINDGEN_OVERWRITE_EXPECTED"); - } + assert!( + var == "0" || var == "", + "Invalid value of BINDGEN_OVERWRITE_EXPECTED" + ); } false } diff --git a/bindgen/clang.rs b/bindgen/clang.rs index 0c35dbe69d..66558bc8cc 100644 --- a/bindgen/clang.rs +++ b/bindgen/clang.rs @@ -1761,7 +1761,7 @@ impl File { fn cxstring_to_string_leaky(s: CXString) -> String { if s.data.is_null() { - return "".to_owned(); + return String::new(); } let c_str = unsafe { CStr::from_ptr(clang_getCString(s) as *const _) }; c_str.to_string_lossy().into_owned() diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 403ac42839..cf819950db 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -4565,7 +4565,7 @@ impl CodeGenerator for Function { FunctionKind::Function => { ctx.options().dynamic_library_name.is_some() } - _ => false, + FunctionKind::Method(_) => false, }; // Similar to static member variables in a class template, we can't @@ -5878,7 +5878,7 @@ pub(crate) mod utils { // Check that the mangled name contains the canonical name after the // prefix - if &mangled_name[1..canonical_name.len() + 1] != canonical_name { + if &mangled_name[1..=canonical_name.len()] != canonical_name { return false; } diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index 9bc13de63d..098dd25e59 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -2271,21 +2271,17 @@ If you encounter an error missing from this list, please file an issue or a PR!" ); } break; - } else { - // This is _likely_, but not certainly, a macro that's - // been placed just before the namespace keyword. - // Unfortunately, clang tokens don't let us easily see - // through the ifdef tokens, so we don't know what this - // token should really be. Instead of panicking though, - // we warn the user that we assumed the token was blank, - // and then move on. - // - // See also https://github.com/rust-lang/rust-bindgen/issues/1676. - warn!( - "Ignored unknown namespace prefix '{}' at {token:?} in {cursor:?}", - String::from_utf8_lossy(name), - ); } + // This is _likely_, but not certainly, a macro that's + // been placed just before the namespace keyword. + // Unfortunately, clang tokens don't let us easily see + // through the ifdef tokens, so we don't know what this + // token should really be. Instead of panicking though, + // we warn the user that we assumed the token was blank, + // and then move on. + // + // See also https://github.com/rust-lang/rust-bindgen/issues/1676. + warn!("Ignored unknown namespace prefix '{}' at {token:?} in {cursor:?}", String::from_utf8_lossy(name)); } } } @@ -2613,7 +2609,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// Call if an opaque array is generated pub(crate) fn generated_opaque_array(&self) { - self.generated_opaque_array.set(true) + self.generated_opaque_array.set(true); } /// Whether we need to generate the opaque array type diff --git a/bindgen/ir/function.rs b/bindgen/ir/function.rs index 6da986e2d9..2474ea839a 100644 --- a/bindgen/ir/function.rs +++ b/bindgen/ir/function.rs @@ -17,7 +17,7 @@ use std::str::FromStr; const RUST_DERIVE_FUNPTR_LIMIT: usize = 12; -/// What kind of a function are we looking at? +/// What kind of function are we looking at? #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub(crate) enum FunctionKind { /// A plain, free function. diff --git a/bindgen/ir/item.rs b/bindgen/ir/item.rs index 0717f3e877..b131455849 100644 --- a/bindgen/ir/item.rs +++ b/bindgen/ir/item.rs @@ -1856,16 +1856,11 @@ impl Item { let parent = ctx.root_module().into(); if let Some(id) = ctx.get_type_param(&definition) { - if let Some(with_id) = with_id { - return Some(ctx.build_ty_wrapper( - with_id, - id, - Some(parent), - &ty, - )); + return Some(if let Some(with_id) = with_id { + ctx.build_ty_wrapper(with_id, id, Some(parent), &ty) } else { - return Some(id); - } + id + }); } // See tests/headers/const_tparam.hpp and diff --git a/bindgen/ir/ty.rs b/bindgen/ir/ty.rs index cd9a9a1edf..2589a56fca 100644 --- a/bindgen/ir/ty.rs +++ b/bindgen/ir/ty.rs @@ -504,7 +504,7 @@ fn is_invalid_type_param_invalid_remaining() { } #[test] -#[should_panic] +#[should_panic(expected = "Unnamed named type")] fn is_invalid_type_param_unnamed() { let ty = Type::new(None, None, TypeKind::TypeParam, false); assert!(ty.is_invalid_type_param()); @@ -512,7 +512,7 @@ fn is_invalid_type_param_unnamed() { #[test] fn is_invalid_type_param_empty_name() { - let ty = Type::new(Some("".into()), None, TypeKind::TypeParam, false); + let ty = Type::new(Some(String::new()), None, TypeKind::TypeParam, false); assert!(ty.is_invalid_type_param()); } diff --git a/bindgen/lib.rs b/bindgen/lib.rs index c9b529ac66..8a7453bbcd 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -86,10 +86,12 @@ pub const DEFAULT_ANON_FIELDS_PREFIX: &str = "__bindgen_anon_"; const DEFAULT_NON_EXTERN_FNS_SUFFIX: &str = "__extern"; fn file_is_cpp(name_file: &str) -> bool { - name_file.ends_with(".hpp") || - name_file.ends_with(".hxx") || - name_file.ends_with(".hh") || - name_file.ends_with(".h++") + Path::new(name_file).extension().map_or(false, |ext| { + ext.eq_ignore_ascii_case("hpp") || + ext.eq_ignore_ascii_case("hxx") || + ext.eq_ignore_ascii_case("hh") || + ext.eq_ignore_ascii_case("h++") + }) } fn args_are_cpp(clang_args: &[Box]) -> bool { diff --git a/bindgen/time.rs b/bindgen/time.rs index a220de7d9f..2952e36f76 100644 --- a/bindgen/time.rs +++ b/bindgen/time.rs @@ -29,7 +29,7 @@ impl<'a> Timer<'a> { /// Returns the time elapsed since the timer's creation pub fn elapsed(&self) -> Duration { - Instant::now() - self.start + self.start.elapsed() } fn print_elapsed(&mut self) { From 59a43e10b758bd86275aefceae29e874157087d8 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Thu, 26 Dec 2024 21:45:26 -0500 Subject: [PATCH 841/942] Use appropriate `rustfmt --format ...` param This fixes the issue with c-string literals which require edition 2021. Now the edition is automatically computed if not specified. --- bindgen/lib.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 8a7453bbcd..9e22e37ce6 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -208,7 +208,7 @@ impl std::fmt::Display for Formatter { Self::Prettyplease => "prettyplease", }; - s.fmt(f) + std::fmt::Display::fmt(&s, f) } } @@ -999,6 +999,12 @@ impl Bindings { cmd.args(["--config-path", path]); } + let edition = self + .options + .rust_edition + .unwrap_or_else(|| self.options.rust_target.latest_edition()); + cmd.args(["--edition", &format!("{edition}")]); + let mut child = cmd.spawn()?; let mut child_stdin = child.stdin.take().unwrap(); let mut child_stdout = child.stdout.take().unwrap(); From b7c7964381e0a558466c35ac870e2df51e0e53c8 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Wed, 15 Jan 2025 21:27:17 -0500 Subject: [PATCH 842/942] Fix calling convention tests Seems like recent compiler changes no longer allow invalid calling conventions --- bindgen-tests/tests/expectations/tests/abi-override.rs | 1 + bindgen-tests/tests/expectations/tests/mangling-win32.rs | 1 + bindgen-tests/tests/headers/abi-override.h | 2 +- bindgen-tests/tests/headers/mangling-win32.hpp | 2 +- 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/bindgen-tests/tests/expectations/tests/abi-override.rs b/bindgen-tests/tests/expectations/tests/abi-override.rs index 38fe76fd63..369bfd8d32 100644 --- a/bindgen-tests/tests/expectations/tests/abi-override.rs +++ b/bindgen-tests/tests/expectations/tests/abi-override.rs @@ -1,4 +1,5 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#![cfg(target = "i686-pc-windows-msvc")] unsafe extern "fastcall" { pub fn foo(); } diff --git a/bindgen-tests/tests/expectations/tests/mangling-win32.rs b/bindgen-tests/tests/expectations/tests/mangling-win32.rs index 3a2f95bf70..263f619374 100644 --- a/bindgen-tests/tests/expectations/tests/mangling-win32.rs +++ b/bindgen-tests/tests/expectations/tests/mangling-win32.rs @@ -1,4 +1,5 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#![cfg(target = "i686-pc-windows-msvc")] unsafe extern "C" { pub fn foo(); } diff --git a/bindgen-tests/tests/headers/abi-override.h b/bindgen-tests/tests/headers/abi-override.h index 578659733e..0b0fdcf245 100644 --- a/bindgen-tests/tests/headers/abi-override.h +++ b/bindgen-tests/tests/headers/abi-override.h @@ -1,4 +1,4 @@ -// bindgen-flags: --override-abi=foo=fastcall --override-abi=bar=stdcall --override-abi=boo=efiapi --override-abi=foobar=efiapi --override-abi qux=system +// bindgen-flags: --override-abi=foo=fastcall --override-abi=bar=stdcall --override-abi=boo=efiapi --override-abi=foobar=efiapi --override-abi qux=system --raw-line '#![cfg(target = "i686-pc-windows-msvc")]' void foo(); void bar(); diff --git a/bindgen-tests/tests/headers/mangling-win32.hpp b/bindgen-tests/tests/headers/mangling-win32.hpp index 386df4aba3..76a7e664ed 100644 --- a/bindgen-tests/tests/headers/mangling-win32.hpp +++ b/bindgen-tests/tests/headers/mangling-win32.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: -- --target=i686-pc-win32 +// bindgen-flags: --raw-line '#![cfg(target = "i686-pc-windows-msvc")]' -- --target=i686-pc-win32 extern "C" void foo(); From 14ee85bb5256b4a5df59b694f3e6fad4b94622eb Mon Sep 17 00:00:00 2001 From: Jonathan Schwender Date: Thu, 30 Jan 2025 11:42:10 +0100 Subject: [PATCH 843/942] process_comment: Use last defined callback Instead of using the last registered callback, iterate through all callbacks and use the last one that was actually implemented and returned `Some()`. This is essentially when users register more than one parse callback - the process_comment may not be the last. --- bindgen/lib.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 9e22e37ce6..6d15012704 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -582,9 +582,7 @@ impl BindgenOptions { fn process_comment(&self, comment: &str) -> String { let comment = comment::preprocess(comment); - self.parse_callbacks - .last() - .and_then(|cb| cb.process_comment(&comment)) + self.last_callback(|cb| cb.process_comment(&comment)) .unwrap_or(comment) } } From 4de3ada94044b51a6502d74b878705d3a7517978 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Wed, 8 Jan 2025 22:47:06 -0500 Subject: [PATCH 844/942] A few minor clippy lints * Fix `unnested_or_patterns` * Do a few `match_same_arms`, but keep the lint disabled --- Cargo.toml | 4 +-- bindgen-tests/build.rs | 29 ++++++++----------- bindgen/codegen/mod.rs | 2 +- bindgen/ir/analysis/derive.rs | 27 ++++++++++------- bindgen/ir/analysis/has_float.rs | 2 +- .../ir/analysis/has_type_param_in_array.rs | 2 +- bindgen/ir/function.rs | 8 ++--- bindgen/ir/int.rs | 4 +-- bindgen/ir/item.rs | 20 ++++++------- 9 files changed, 47 insertions(+), 51 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 248c041378..269f35a9e4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -65,6 +65,7 @@ ignored_unit_patterns = "allow" implicit_hasher = "allow" inconsistent_struct_constructor = "allow" items_after_statements = "allow" +match_same_arms = "allow" maybe_infinite_iter = "allow" missing_errors_doc = "allow" missing_panics_doc = "allow" @@ -73,19 +74,16 @@ must_use_candidate = "allow" ptr_as_ptr = "allow" redundant_closure_for_method_calls = "allow" return_self_not_must_use = "allow" -#should_panic_without_expect = "allow" similar_names = "allow" struct_excessive_bools = "allow" struct_field_names = "allow" unnecessary_wraps = "allow" -unnested_or_patterns = "allow" unreadable_literal = "allow" used_underscore_binding = "allow" wildcard_imports = "allow" # TODO borrow_as_ptr = "allow" -match_same_arms = "allow" trivially_copy_pass_by_ref = "allow" needless_pass_by_value = "allow" unused_self = "allow" diff --git a/bindgen-tests/build.rs b/bindgen-tests/build.rs index d98e823919..b261ed0a35 100644 --- a/bindgen-tests/build.rs +++ b/bindgen-tests/build.rs @@ -1,6 +1,5 @@ use std::char; use std::env; -use std::ffi::OsStr; use std::fs::{self, File}; use std::io::Write; use std::path::{Path, PathBuf}; @@ -23,23 +22,19 @@ pub fn main() { println!("cargo:rerun-if-changed=tests/headers"); for entry in entries { - match entry.path().extension().and_then(OsStr::to_str) { - Some("h") | Some("hpp") => { - let func = entry - .file_name() - .to_str() - .unwrap() - .replace(|c| !char::is_alphanumeric(c), "_") - .replace("__", "_") - .to_lowercase(); - writeln!( - dst, - "test_header!(header_{func}, {:?});", - entry.path(), - ) + // TODO: file_is_cpp() in bindgen/lib.rs checks for hpp,hxx,hh, and h++ - should this be consistent? + if entry.path().extension().map_or(false, |ext| { + ext.eq_ignore_ascii_case("h") || ext.eq_ignore_ascii_case("hpp") + }) { + let func = entry + .file_name() + .to_str() + .unwrap() + .replace(|c| !char::is_alphanumeric(c), "_") + .replace("__", "_") + .to_lowercase(); + writeln!(dst, "test_header!(header_{func}, {:?});", entry.path()) .unwrap(); - } - _ => {} } } diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index cf819950db..248c618174 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -3003,7 +3003,7 @@ impl Method { let cc = &ctx.options().codegen_config; match self.kind() { MethodKind::Constructor => cc.constructors(), - MethodKind::Destructor => cc.destructors(), + MethodKind::Destructor | MethodKind::VirtualDestructor { .. } => cc.destructors(), MethodKind::Static | MethodKind::Normal | diff --git a/bindgen/ir/analysis/derive.rs b/bindgen/ir/analysis/derive.rs index 1643a91461..bd4e40494e 100644 --- a/bindgen/ir/analysis/derive.rs +++ b/bindgen/ir/analysis/derive.rs @@ -524,7 +524,7 @@ impl DeriveTrait { fn can_derive_fnptr(&self, f: &FunctionSig) -> CanDerive { match (self, f.function_pointers_can_derive()) { - (DeriveTrait::Copy, _) | (DeriveTrait::Default, _) | (_, true) => { + (DeriveTrait::Copy | DeriveTrait::Default, _) | (_, true) => { trace!(" function pointer can derive {self}"); CanDerive::Yes } @@ -565,14 +565,17 @@ impl DeriveTrait { fn can_derive_simple(&self, kind: &TypeKind) -> CanDerive { match (self, kind) { // === Default === - (DeriveTrait::Default, TypeKind::Void) | - (DeriveTrait::Default, TypeKind::NullPtr) | - (DeriveTrait::Default, TypeKind::Enum(..)) | - (DeriveTrait::Default, TypeKind::Reference(..)) | - (DeriveTrait::Default, TypeKind::TypeParam) | - (DeriveTrait::Default, TypeKind::ObjCInterface(..)) | - (DeriveTrait::Default, TypeKind::ObjCId) | - (DeriveTrait::Default, TypeKind::ObjCSel) => { + ( + DeriveTrait::Default, + TypeKind::Void | + TypeKind::NullPtr | + TypeKind::Enum(..) | + TypeKind::Reference(..) | + TypeKind::TypeParam | + TypeKind::ObjCInterface(..) | + TypeKind::ObjCId | + TypeKind::ObjCSel, + ) => { trace!(" types that always cannot derive Default"); CanDerive::No } @@ -582,8 +585,10 @@ impl DeriveTrait { ) } // === Hash === - (DeriveTrait::Hash, TypeKind::Float(..)) | - (DeriveTrait::Hash, TypeKind::Complex(..)) => { + ( + DeriveTrait::Hash, + TypeKind::Float(..) | TypeKind::Complex(..), + ) => { trace!(" float cannot derive Hash"); CanDerive::No } diff --git a/bindgen/ir/analysis/has_float.rs b/bindgen/ir/analysis/has_float.rs index da4b413372..e2463ccb96 100644 --- a/bindgen/ir/analysis/has_float.rs +++ b/bindgen/ir/analysis/has_float.rs @@ -56,7 +56,7 @@ impl HasFloat<'_> { EdgeKind::FunctionParameter | EdgeKind::InnerType | EdgeKind::InnerVar | - EdgeKind::Method => false, + EdgeKind::Method | EdgeKind::Generic => false, } } diff --git a/bindgen/ir/analysis/has_type_param_in_array.rs b/bindgen/ir/analysis/has_type_param_in_array.rs index 466ccb2ae8..687f81560c 100644 --- a/bindgen/ir/analysis/has_type_param_in_array.rs +++ b/bindgen/ir/analysis/has_type_param_in_array.rs @@ -58,7 +58,7 @@ impl HasTypeParameterInArray<'_> { EdgeKind::FunctionParameter | EdgeKind::InnerType | EdgeKind::InnerVar | - EdgeKind::Method => false, + EdgeKind::Method | EdgeKind::Generic => false, } } diff --git a/bindgen/ir/function.rs b/bindgen/ir/function.rs index 2474ea839a..0a6ccb1e04 100644 --- a/bindgen/ir/function.rs +++ b/bindgen/ir/function.rs @@ -290,15 +290,15 @@ pub(crate) struct FunctionSig { fn get_abi(cc: CXCallingConv) -> ClangAbi { use clang_sys::*; match cc { - CXCallingConv_Default => ClangAbi::Known(Abi::C), - CXCallingConv_C => ClangAbi::Known(Abi::C), + CXCallingConv_Default | CXCallingConv_C => ClangAbi::Known(Abi::C), CXCallingConv_X86StdCall => ClangAbi::Known(Abi::Stdcall), CXCallingConv_X86FastCall => ClangAbi::Known(Abi::Fastcall), CXCallingConv_X86ThisCall => ClangAbi::Known(Abi::ThisCall), - CXCallingConv_X86VectorCall => ClangAbi::Known(Abi::Vectorcall), + CXCallingConv_X86VectorCall | CXCallingConv_AArch64VectorCall => { + ClangAbi::Known(Abi::Vectorcall) + } CXCallingConv_AAPCS => ClangAbi::Known(Abi::Aapcs), CXCallingConv_X86_64Win64 => ClangAbi::Known(Abi::Win64), - CXCallingConv_AArch64VectorCall => ClangAbi::Known(Abi::Vectorcall), other => ClangAbi::Unknown(other), } } diff --git a/bindgen/ir/int.rs b/bindgen/ir/int.rs index 4251b3753a..4b49931ed8 100644 --- a/bindgen/ir/int.rs +++ b/bindgen/ir/int.rs @@ -99,9 +99,7 @@ impl IntKind { SChar | Short | Int | Long | LongLong | I8 | I16 | I32 | I64 | I128 => true, - Char { is_signed } => is_signed, - - Custom { is_signed, .. } => is_signed, + Char { is_signed } | Custom { is_signed, .. } => is_signed, } } diff --git a/bindgen/ir/item.rs b/bindgen/ir/item.rs index b131455849..9a90b27eda 100644 --- a/bindgen/ir/item.rs +++ b/bindgen/ir/item.rs @@ -1012,15 +1012,15 @@ impl Item { FunctionKind::Method(MethodKind::Constructor) => { cc.constructors() } - FunctionKind::Method(MethodKind::Destructor) | - FunctionKind::Method(MethodKind::VirtualDestructor { - .. - }) => cc.destructors(), - FunctionKind::Method(MethodKind::Static) | - FunctionKind::Method(MethodKind::Normal) | - FunctionKind::Method(MethodKind::Virtual { .. }) => { - cc.methods() - } + FunctionKind::Method( + MethodKind::Destructor | + MethodKind::VirtualDestructor { .. }, + ) => cc.destructors(), + FunctionKind::Method( + MethodKind::Static | + MethodKind::Normal | + MethodKind::Virtual { .. }, + ) => cc.methods(), }, } } @@ -1415,7 +1415,7 @@ impl Item { CXCursor_UsingDirective | CXCursor_StaticAssert | CXCursor_FunctionTemplate => { - debug!("Unhandled cursor kind {:?}: {cursor:?}", cursor.kind(),); + debug!("Unhandled cursor kind {:?}: {cursor:?}", cursor.kind()); Err(ParseError::Continue) } From c704b14cd063082c2d03acc318d47834394eb063 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Wed, 8 Jan 2025 23:08:56 -0500 Subject: [PATCH 845/942] Fix `needless_pass_by_value` lint This also gets rid of some unneeded cloning --- Cargo.toml | 1 - .../item_discovery_callback/mod.rs | 8 +-- bindgen-tests/tests/quickchecking/src/lib.rs | 5 +- bindgen/codegen/dyngen.rs | 18 +++--- bindgen/codegen/helpers.rs | 2 +- bindgen/codegen/impl_debug.rs | 10 +-- bindgen/codegen/impl_partialeq.rs | 8 +-- bindgen/codegen/mod.rs | 63 ++++++++++--------- bindgen/lib.rs | 6 +- 9 files changed, 61 insertions(+), 60 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 269f35a9e4..3dda384ced 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -85,7 +85,6 @@ wildcard_imports = "allow" # TODO borrow_as_ptr = "allow" trivially_copy_pass_by_ref = "allow" -needless_pass_by_value = "allow" unused_self = "allow" # Theese seem to be ok to ignore for now diff --git a/bindgen-tests/tests/parse_callbacks/item_discovery_callback/mod.rs b/bindgen-tests/tests/parse_callbacks/item_discovery_callback/mod.rs index b48d2d7c19..74af110d00 100644 --- a/bindgen-tests/tests/parse_callbacks/item_discovery_callback/mod.rs +++ b/bindgen-tests/tests/parse_callbacks/item_discovery_callback/mod.rs @@ -76,10 +76,10 @@ pub fn test_item_discovery_callback() { ), ]); - compare_item_caches(info.borrow().clone(), expected); + compare_item_caches(&info.borrow(), &expected); } -pub fn compare_item_caches(generated: ItemCache, expected: ItemCache) { +pub fn compare_item_caches(generated: &ItemCache, expected: &ItemCache) { // We can't use a simple Eq::eq comparison because of two reasons: // - anonymous structs/unions will have a final name generated by bindgen which may change // if the header file or the bindgen logic is altered @@ -89,8 +89,8 @@ pub fn compare_item_caches(generated: ItemCache, expected: ItemCache) { compare_item_info( expected_item, generated_item, - &expected, - &generated, + expected, + generated, ) }); diff --git a/bindgen-tests/tests/quickchecking/src/lib.rs b/bindgen-tests/tests/quickchecking/src/lib.rs index 2f0b575c3f..7567a3bea6 100644 --- a/bindgen-tests/tests/quickchecking/src/lib.rs +++ b/bindgen-tests/tests/quickchecking/src/lib.rs @@ -37,7 +37,7 @@ static CONTEXT: Mutex = Mutex::new(Context { output_path: None }); // Passes fuzzed header to the `csmith-fuzzing/predicate.py` script, returns // output of the associated command. fn run_predicate_script( - header: fuzzers::HeaderC, + header: &fuzzers::HeaderC, ) -> Result> { let dir = Builder::new().prefix("bindgen_prop").tempdir()?; let header_path = dir.path().join("prop_test.h"); @@ -77,8 +77,9 @@ fn run_predicate_script( // Generatable property. Pass generated headers off to run through the // `csmith-fuzzing/predicate.py` script. Success is measured by the success // status of that command. +#[allow(clippy::needless_pass_by_value)] fn bindgen_prop(header: fuzzers::HeaderC) -> TestResult { - match run_predicate_script(header) { + match run_predicate_script(&header) { Ok(o) => TestResult::from_bool(o.status.success()), Err(e) => { println!("{e:?}"); diff --git a/bindgen/codegen/dyngen.rs b/bindgen/codegen/dyngen.rs index 6bdea51eff..410cc0d6cb 100644 --- a/bindgen/codegen/dyngen.rs +++ b/bindgen/codegen/dyngen.rs @@ -75,7 +75,7 @@ impl DynamicItems { pub(crate) fn get_tokens( &self, - lib_ident: Ident, + lib_ident: &Ident, ctx: &BindgenContext, ) -> TokenStream { let struct_members = &self.struct_members; @@ -130,15 +130,15 @@ impl DynamicItems { #[allow(clippy::too_many_arguments)] pub(crate) fn push_func( &mut self, - ident: Ident, + ident: &Ident, abi: ClangAbi, is_variadic: bool, is_required: bool, - args: Vec, - args_identifiers: Vec, - ret: TokenStream, - ret_ty: TokenStream, - attributes: Vec, + args: &[TokenStream], + args_identifiers: &[TokenStream], + ret: &TokenStream, + ret_ty: &TokenStream, + attributes: &[TokenStream], ctx: &BindgenContext, ) { if !is_variadic { @@ -205,8 +205,8 @@ impl DynamicItems { pub fn push_var( &mut self, - ident: Ident, - ty: TokenStream, + ident: &Ident, + ty: &TokenStream, is_required: bool, wrap_unsafe_ops: bool, ) { diff --git a/bindgen/codegen/helpers.rs b/bindgen/codegen/helpers.rs index 812b6b6458..7b09ed7cfb 100644 --- a/bindgen/codegen/helpers.rs +++ b/bindgen/codegen/helpers.rs @@ -52,7 +52,7 @@ pub(crate) mod attributes { } } - pub(crate) fn doc(comment: String) -> TokenStream { + pub(crate) fn doc(comment: &str) -> TokenStream { if comment.is_empty() { quote!() } else { diff --git a/bindgen/codegen/impl_debug.rs b/bindgen/codegen/impl_debug.rs index 319c89b58e..058a73bd13 100644 --- a/bindgen/codegen/impl_debug.rs +++ b/bindgen/codegen/impl_debug.rs @@ -130,7 +130,7 @@ impl<'a> ImplDebug<'a> for Item { fn debug_print( name: &str, - name_ident: proc_macro2::TokenStream, + name_ident: &proc_macro2::TokenStream, ) -> Option<(String, Vec)> { Some(( format!("{name}: {{:?}}"), @@ -154,13 +154,13 @@ impl<'a> ImplDebug<'a> for Item { TypeKind::ObjCInterface(..) | TypeKind::ObjCId | TypeKind::Comp(..) | - TypeKind::ObjCSel => debug_print(name, quote! { #name_ident }), + TypeKind::ObjCSel => debug_print(name, "e! { #name_ident }), TypeKind::TemplateInstantiation(ref inst) => { if inst.is_opaque(ctx, self) { Some((format!("{name}: opaque"), vec![])) } else { - debug_print(name, quote! { #name_ident }) + debug_print(name, "e! { #name_ident }) } } @@ -177,7 +177,7 @@ impl<'a> ImplDebug<'a> for Item { ctx.options().rust_features().larger_arrays { // The simple case - debug_print(name, quote! { #name_ident }) + 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. @@ -233,7 +233,7 @@ impl<'a> ImplDebug<'a> for Item { { Some((format!("{name}: FunctionPointer"), vec![])) } - _ => debug_print(name, quote! { #name_ident }), + _ => debug_print(name, "e! { #name_ident }), } } diff --git a/bindgen/codegen/impl_partialeq.rs b/bindgen/codegen/impl_partialeq.rs index 6c7b43959b..c2787967d8 100644 --- a/bindgen/codegen/impl_partialeq.rs +++ b/bindgen/codegen/impl_partialeq.rs @@ -76,7 +76,7 @@ fn gen_field( name: &str, ) -> proc_macro2::TokenStream { fn quote_equals( - name_ident: proc_macro2::Ident, + name_ident: &proc_macro2::Ident, ) -> proc_macro2::TokenStream { quote! { self.#name_ident == other.#name_ident } } @@ -100,7 +100,7 @@ fn gen_field( TypeKind::Comp(..) | TypeKind::Pointer(_) | TypeKind::Function(..) | - TypeKind::Opaque => quote_equals(name_ident), + TypeKind::Opaque => quote_equals(&name_ident), TypeKind::TemplateInstantiation(ref inst) => { if inst.is_opaque(ctx, ty_item) { @@ -108,7 +108,7 @@ fn gen_field( &self. #name_ident [..] == &other. #name_ident [..] } } else { - quote_equals(name_ident) + quote_equals(&name_ident) } } @@ -116,7 +116,7 @@ fn gen_field( if len <= RUST_DERIVE_IN_ARRAY_LIMIT || ctx.options().rust_features().larger_arrays { - quote_equals(name_ident) + quote_equals(&name_ident) } else { quote! { &self. #name_ident [..] == &other. #name_ident [..] diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 248c618174..8bd1b15fa6 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -677,7 +677,7 @@ impl CodeGenerator for Var { let mut attrs = vec![]; if let Some(comment) = item.comment(ctx) { - attrs.push(attributes::doc(comment)); + attrs.push(attributes::doc(&comment)); } let var_ty = self.ty(); @@ -815,8 +815,9 @@ impl CodeGenerator for Var { if ctx.options().dynamic_library_name.is_some() { result.dynamic_items().push_var( - canonical_ident, - self.ty() + &canonical_ident, + &self + .ty() .to_rust_ty_or_opaque(ctx, &()) .into_token_stream(), ctx.options().dynamic_link_require_all, @@ -886,7 +887,7 @@ impl CodeGenerator for Type { let rust_name = ctx.rust_ident(name); let mut tokens = if let Some(comment) = item.comment(ctx) { - attributes::doc(comment) + attributes::doc(&comment) } else { quote! {} }; @@ -1006,7 +1007,7 @@ impl CodeGenerator for Type { }); let mut tokens = if let Some(comment) = item.comment(ctx) { - attributes::doc(comment) + attributes::doc(&comment) } else { quote! {} }; @@ -1532,7 +1533,7 @@ impl FieldCodegen<'_> for FieldData { if ctx.options().generate_comments { if let Some(raw_comment) = self.comment() { let comment = ctx.options().process_comment(raw_comment); - field = attributes::doc(comment); + field = attributes::doc(&comment); } } @@ -1654,7 +1655,7 @@ impl Bitfield { fn extend_ctor_impl( &self, ctx: &BindgenContext, - param_name: proc_macro2::TokenStream, + param_name: &proc_macro2::TokenStream, mut ctor_impl: proc_macro2::TokenStream, ) -> proc_macro2::TokenStream { let bitfield_ty = ctx.resolve_type(self.ty()); @@ -1857,7 +1858,7 @@ impl FieldCodegen<'_> for BitfieldUnit { ctor_params.push(quote! { #param_name : #bitfield_ty }); - ctor_impl = bf.extend_ctor_impl(ctx, param_name, ctor_impl); + ctor_impl = bf.extend_ctor_impl(ctx, ¶m_name, ctor_impl); } let access_spec = access_specifier(unit_visibility); @@ -2409,7 +2410,7 @@ impl CodeGenerator for CompInfo { let mut needs_partialeq_impl = false; let needs_flexarray_impl = flex_array_generic.is_some(); if let Some(comment) = item.comment(ctx) { - attributes.push(attributes::doc(comment)); + attributes.push(attributes::doc(&comment)); } // if a type has both a "packed" attribute and an "align(N)" attribute, then check if the @@ -2764,7 +2765,7 @@ impl CodeGenerator for CompInfo { result.push(self.generate_flexarray( ctx, &canonical_ident, - flex_inner_ty, + flex_inner_ty.as_ref(), &generic_param_names, &impl_generics_labels, )); @@ -2859,7 +2860,7 @@ impl CompInfo { &self, ctx: &BindgenContext, canonical_ident: &Ident, - flex_inner_ty: Option, + flex_inner_ty: Option<&proc_macro2::TokenStream>, generic_param_names: &[Ident], impl_generics_labels: &proc_macro2::TokenStream, ) -> proc_macro2::TokenStream { @@ -3299,7 +3300,7 @@ impl<'a> EnumBuilder<'a> { fn new( name: &'a str, mut attrs: Vec, - repr: syn::Type, + repr: &syn::Type, enum_variation: EnumVariation, has_typedef: bool, ) -> Self { @@ -3368,7 +3369,7 @@ impl<'a> EnumBuilder<'a> { ctx: &BindgenContext, variant: &EnumVariant, mangling_prefix: Option<&str>, - rust_ty: syn::Type, + rust_ty: &syn::Type, result: &mut CodegenResult<'_>, is_ty_named: bool, ) -> Self { @@ -3387,7 +3388,7 @@ impl<'a> EnumBuilder<'a> { if ctx.options().generate_comments { if let Some(raw_comment) = variant.comment() { let comment = ctx.options().process_comment(raw_comment); - doc = attributes::doc(comment); + doc = attributes::doc(&comment); } } @@ -3480,7 +3481,7 @@ impl<'a> EnumBuilder<'a> { fn build( self, ctx: &BindgenContext, - rust_ty: syn::Type, + rust_ty: &syn::Type, result: &mut CodegenResult<'_>, ) -> proc_macro2::TokenStream { match self { @@ -3679,7 +3680,7 @@ impl CodeGenerator for Enum { }; if let Some(comment) = item.comment(ctx) { - attrs.push(attributes::doc(comment)); + attrs.push(attributes::doc(&comment)); } if item.must_use(ctx) { @@ -3746,7 +3747,7 @@ impl CodeGenerator for Enum { // value. variant_name: &Ident, referenced_name: &Ident, - enum_rust_ty: syn::Type, + enum_rust_ty: &syn::Type, result: &mut CodegenResult<'_>, ) { let constant_name = if enum_.name().is_some() { @@ -3770,7 +3771,7 @@ impl CodeGenerator for Enum { let has_typedef = ctx.is_enum_typedef_combo(item.id()); let mut builder = - EnumBuilder::new(&name, attrs, repr, variation, has_typedef); + EnumBuilder::new(&name, attrs, &repr, variation, has_typedef); // A map where we keep a value -> variant relation. let mut seen_values = HashMap::<_, Ident>::default(); @@ -3846,7 +3847,7 @@ impl CodeGenerator for Enum { &ident, &Ident::new(&mangled_name, Span::call_site()), existing_variant_name, - enum_rust_ty.clone(), + &enum_rust_ty, result, ); } @@ -3855,7 +3856,7 @@ impl CodeGenerator for Enum { ctx, variant, constant_mangling_prefix, - enum_rust_ty.clone(), + &enum_rust_ty, result, enum_ty.name().is_some(), ); @@ -3866,7 +3867,7 @@ impl CodeGenerator for Enum { ctx, variant, constant_mangling_prefix, - enum_rust_ty.clone(), + &enum_rust_ty, result, enum_ty.name().is_some(), ); @@ -3897,7 +3898,7 @@ impl CodeGenerator for Enum { &ident, &mangled_name, &variant_name, - enum_rust_ty.clone(), + &enum_rust_ty, result, ); } @@ -3907,7 +3908,7 @@ impl CodeGenerator for Enum { } } - let item = builder.build(ctx, enum_rust_ty, result); + let item = builder.build(ctx, &enum_rust_ty, result); result.push(item); } } @@ -4609,7 +4610,7 @@ impl CodeGenerator for Function { } if let Some(comment) = item.comment(ctx) { - attributes.push(attributes::doc(comment)); + attributes.push(attributes::doc(&comment)); } let abi = match signature.abi(ctx, Some(name)) { @@ -4738,15 +4739,15 @@ impl CodeGenerator for Function { utils::fnsig_argument_identifiers(ctx, signature); let ret_ty = utils::fnsig_return_ty(ctx, signature); result.dynamic_items().push_func( - ident, + &ident, abi, signature.is_variadic(), ctx.options().dynamic_link_require_all, - args, - args_identifiers, - ret, - ret_ty, - attributes, + &args, + &args_identifiers, + &ret, + &ret_ty, + &attributes, ctx, ); } else { @@ -5160,7 +5161,7 @@ pub(crate) fn codegen( if let Some(ref lib_name) = context.options().dynamic_library_name { let lib_ident = context.rust_ident(lib_name); let dynamic_items_tokens = - result.dynamic_items().get_tokens(lib_ident, context); + result.dynamic_items().get_tokens(&lib_ident, context); result.push(dynamic_items_tokens); } diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 6d15012704..2e56856083 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -363,7 +363,7 @@ impl Builder { }) .collect::>(); - Bindings::generate(self.options, input_unsaved_files) + Bindings::generate(self.options, &input_unsaved_files) } /// Preprocess and dump the input header files to disk. @@ -727,7 +727,7 @@ impl Bindings { /// Generate bindings for the given options. pub(crate) fn generate( mut options: BindgenOptions, - input_unsaved_files: Vec, + input_unsaved_files: &[clang::UnsavedFile], ) -> Result { ensure_libclang_is_loaded(); @@ -884,7 +884,7 @@ impl Bindings { debug!("Fixed-up options: {options:?}"); let time_phases = options.time_phases; - let mut context = BindgenContext::new(options, &input_unsaved_files); + let mut context = BindgenContext::new(options, input_unsaved_files); if is_host_build { debug_assert_eq!( From 493fba9cd9c3567b7ac689961277c7ffe14a964b Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Wed, 8 Jan 2025 23:19:19 -0500 Subject: [PATCH 846/942] Fix `trivially_copy_pass_by_ref` lint --- bindgen/codegen/mod.rs | 12 ++++++------ bindgen/ir/analysis/derive.rs | 32 ++++++++++++++++---------------- bindgen/ir/comp.rs | 8 ++++---- bindgen/ir/context.rs | 4 ++-- bindgen/ir/function.rs | 4 ++-- bindgen/ir/item.rs | 1 + 6 files changed, 31 insertions(+), 30 deletions(-) diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 8bd1b15fa6..157478d3c5 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -3188,14 +3188,14 @@ pub enum EnumVariation { } impl EnumVariation { - fn is_rust(&self) -> bool { - matches!(*self, EnumVariation::Rust { .. }) + fn is_rust(self) -> bool { + matches!(self, EnumVariation::Rust { .. }) } /// Both the `Const` and `ModuleConsts` variants will cause this to return /// true. - fn is_const(&self) -> bool { - matches!(*self, EnumVariation::Consts | EnumVariation::ModuleConsts) + fn is_const(self) -> bool { + matches!(self, EnumVariation::Consts | EnumVariation::ModuleConsts) } } @@ -5701,7 +5701,7 @@ pub(crate) mod utils { pub(crate) fn fnsig_argument_type( ctx: &BindgenContext, - ty: &TypeId, + ty: TypeId, ) -> syn::Type { use super::ToPtr; @@ -5753,7 +5753,7 @@ pub(crate) mod utils { let mut unnamed_arguments = 0; let mut args = args_iter .map(|(name, ty)| { - let arg_ty = fnsig_argument_type(ctx, ty); + let arg_ty = fnsig_argument_type(ctx, *ty); let arg_name = if let Some(ref name) = *name { ctx.rust_mangle(name).into_owned() diff --git a/bindgen/ir/analysis/derive.rs b/bindgen/ir/analysis/derive.rs index bd4e40494e..6c66998bee 100644 --- a/bindgen/ir/analysis/derive.rs +++ b/bindgen/ir/analysis/derive.rs @@ -451,7 +451,7 @@ impl CannotDerive<'_> { } impl DeriveTrait { - fn not_by_name(&self, ctx: &BindgenContext, item: &Item) -> bool { + fn not_by_name(self, ctx: &BindgenContext, item: &Item) -> bool { match self { DeriveTrait::Copy => ctx.no_copy_by_name(item), DeriveTrait::Debug => ctx.no_debug_by_name(item), @@ -463,21 +463,21 @@ impl DeriveTrait { } } - fn consider_edge_comp(&self) -> EdgePredicate { + fn consider_edge_comp(self) -> EdgePredicate { match self { DeriveTrait::PartialEqOrPartialOrd => consider_edge_default, _ => |kind| matches!(kind, EdgeKind::BaseMember | EdgeKind::Field), } } - fn consider_edge_typeref(&self) -> EdgePredicate { + fn consider_edge_typeref(self) -> EdgePredicate { match self { DeriveTrait::PartialEqOrPartialOrd => consider_edge_default, _ => |kind| kind == EdgeKind::TypeReference, } } - fn consider_edge_tmpl_inst(&self) -> EdgePredicate { + fn consider_edge_tmpl_inst(self) -> EdgePredicate { match self { DeriveTrait::PartialEqOrPartialOrd => consider_edge_default, _ => |kind| { @@ -489,7 +489,7 @@ impl DeriveTrait { } } - fn can_derive_large_array(&self, ctx: &BindgenContext) -> bool { + fn can_derive_large_array(self, ctx: &BindgenContext) -> bool { if ctx.options().rust_features().larger_arrays { !matches!(self, DeriveTrait::Default) } else { @@ -497,23 +497,23 @@ impl DeriveTrait { } } - fn can_derive_union(&self) -> bool { + fn can_derive_union(self) -> bool { matches!(self, DeriveTrait::Copy) } - fn can_derive_compound_with_destructor(&self) -> bool { + fn can_derive_compound_with_destructor(self) -> bool { !matches!(self, DeriveTrait::Copy) } - fn can_derive_compound_with_vtable(&self) -> bool { + fn can_derive_compound_with_vtable(self) -> bool { !matches!(self, DeriveTrait::Default) } - fn can_derive_compound_forward_decl(&self) -> bool { + fn can_derive_compound_forward_decl(self) -> bool { matches!(self, DeriveTrait::Copy | DeriveTrait::Debug) } - fn can_derive_incomplete_array(&self) -> bool { + fn can_derive_incomplete_array(self) -> bool { !matches!( self, DeriveTrait::Copy | @@ -522,7 +522,7 @@ impl DeriveTrait { ) } - fn can_derive_fnptr(&self, f: &FunctionSig) -> CanDerive { + fn can_derive_fnptr(self, f: &FunctionSig) -> CanDerive { match (self, f.function_pointers_can_derive()) { (DeriveTrait::Copy | DeriveTrait::Default, _) | (_, true) => { trace!(" function pointer can derive {self}"); @@ -539,8 +539,8 @@ impl DeriveTrait { } } - fn can_derive_vector(&self) -> CanDerive { - if *self == DeriveTrait::PartialEqOrPartialOrd { + fn can_derive_vector(self) -> CanDerive { + if self == DeriveTrait::PartialEqOrPartialOrd { // FIXME: vectors always can derive PartialEq, but they should // not derive PartialOrd: // https://github.com/rust-lang-nursery/packed_simd/issues/48 @@ -552,8 +552,8 @@ impl DeriveTrait { } } - fn can_derive_pointer(&self) -> CanDerive { - if *self == DeriveTrait::Default { + fn can_derive_pointer(self) -> CanDerive { + if self == DeriveTrait::Default { trace!(" pointer cannot derive Default"); CanDerive::No } else { @@ -562,7 +562,7 @@ impl DeriveTrait { } } - fn can_derive_simple(&self, kind: &TypeKind) -> CanDerive { + fn can_derive_simple(self, kind: &TypeKind) -> CanDerive { match (self, kind) { // === Default === ( diff --git a/bindgen/ir/comp.rs b/bindgen/ir/comp.rs index 1dd074ba4d..15f9cb4655 100644 --- a/bindgen/ir/comp.rs +++ b/bindgen/ir/comp.rs @@ -56,16 +56,16 @@ pub(crate) enum MethodKind { impl MethodKind { /// Is this a destructor method? - pub(crate) fn is_destructor(&self) -> bool { + pub(crate) fn is_destructor(self) -> bool { matches!( - *self, + self, MethodKind::Destructor | MethodKind::VirtualDestructor { .. } ) } /// Is this a pure virtual method? - pub(crate) fn is_pure_virtual(&self) -> bool { - match *self { + pub(crate) fn is_pure_virtual(self) -> bool { + match self { MethodKind::Virtual { pure_virtual } | MethodKind::VirtualDestructor { pure_virtual } => pure_virtual, _ => false, diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index 098dd25e59..6b47560e8c 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -198,8 +198,8 @@ impl From for usize { impl ItemId { /// Get a numeric representation of this ID. - pub(crate) fn as_usize(&self) -> usize { - (*self).into() + pub(crate) fn as_usize(self) -> usize { + self.into() } } diff --git a/bindgen/ir/function.rs b/bindgen/ir/function.rs index 0a6ccb1e04..83b748a5f4 100644 --- a/bindgen/ir/function.rs +++ b/bindgen/ir/function.rs @@ -247,8 +247,8 @@ pub(crate) enum ClangAbi { impl ClangAbi { /// Returns whether this Abi is known or not. - fn is_unknown(&self) -> bool { - matches!(*self, ClangAbi::Unknown(..)) + fn is_unknown(self) -> bool { + matches!(self, ClangAbi::Unknown(..)) } } diff --git a/bindgen/ir/item.rs b/bindgen/ir/item.rs index 9a90b27eda..bb03917792 100644 --- a/bindgen/ir/item.rs +++ b/bindgen/ir/item.rs @@ -103,6 +103,7 @@ impl DebugOnlyItemSet { DebugOnlyItemSet } + #[allow(clippy::trivially_copy_pass_by_ref)] fn contains(&self, _id: &ItemId) -> bool { false } From 2effeefc541ecc96858ceecf575bcb89ffcdaba8 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Wed, 8 Jan 2025 23:25:45 -0500 Subject: [PATCH 847/942] Fix `inconsistent_struct_constructor` and `ptr_as_ptr` lints --- Cargo.toml | 2 -- bindgen/clang.rs | 12 +++++------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3dda384ced..9537f4a184 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -63,7 +63,6 @@ explicit_into_iter_loop = "allow" flat_map_option = "allow" ignored_unit_patterns = "allow" implicit_hasher = "allow" -inconsistent_struct_constructor = "allow" items_after_statements = "allow" match_same_arms = "allow" maybe_infinite_iter = "allow" @@ -71,7 +70,6 @@ missing_errors_doc = "allow" missing_panics_doc = "allow" module_name_repetitions = "allow" must_use_candidate = "allow" -ptr_as_ptr = "allow" redundant_closure_for_method_calls = "allow" return_self_not_must_use = "allow" similar_names = "allow" diff --git a/bindgen/clang.rs b/bindgen/clang.rs index 66558bc8cc..2440bc0ae6 100644 --- a/bindgen/clang.rs +++ b/bindgen/clang.rs @@ -1045,9 +1045,7 @@ pub(crate) struct ClangToken { impl ClangToken { /// Get the token spelling, without being converted to utf-8. pub(crate) fn spelling(&self) -> &[u8] { - let c_str = unsafe { - CStr::from_ptr(clang_getCString(self.spelling) as *const _) - }; + let c_str = unsafe { CStr::from_ptr(clang_getCString(self.spelling)) }; c_str.to_bytes() } @@ -1098,9 +1096,9 @@ impl Iterator for ClangTokenIterator<'_> { let spelling = clang_getTokenSpelling(self.tu, *raw); let extent = clang_getTokenExtent(self.tu, *raw); Some(ClangToken { - kind, - extent, spelling, + extent, + kind, }) } } @@ -1124,7 +1122,7 @@ extern "C" fn visit_children( where Visitor: FnMut(Cursor) -> CXChildVisitResult, { - let func: &mut Visitor = unsafe { &mut *(data as *mut Visitor) }; + let func: &mut Visitor = unsafe { &mut *data.cast::() }; let child = Cursor { x: cur }; (*func)(child) @@ -1763,7 +1761,7 @@ fn cxstring_to_string_leaky(s: CXString) -> String { if s.data.is_null() { return String::new(); } - let c_str = unsafe { CStr::from_ptr(clang_getCString(s) as *const _) }; + let c_str = unsafe { CStr::from_ptr(clang_getCString(s)) }; c_str.to_string_lossy().into_owned() } From 2974d7c3078cd520e00b61b8405b7a9aa32941c1 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Thu, 9 Jan 2025 00:13:45 -0500 Subject: [PATCH 848/942] Fix `checked_conversions` lint --- Cargo.toml | 1 - bindgen/ir/var.rs | 5 +---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9537f4a184..17689e9c7e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -57,7 +57,6 @@ cast_possible_truncation = "allow" cast_possible_wrap = "allow" cast_precision_loss = "allow" cast_sign_loss = "allow" -checked_conversions = "allow" default_trait_access = "allow" explicit_into_iter_loop = "allow" flat_map_option = "allow" diff --git a/bindgen/ir/var.rs b/bindgen/ir/var.rs index 4f61448fea..85e127fdbc 100644 --- a/bindgen/ir/var.rs +++ b/bindgen/ir/var.rs @@ -234,10 +234,7 @@ impl ClangSubItemParser for Var { assert_eq!(c.len_utf8(), 1); c as u8 } - CChar::Raw(c) => { - assert!(c <= u64::from(u8::MAX)); - c as u8 - } + CChar::Raw(c) => u8::try_from(c).unwrap(), }; (TypeKind::Int(IntKind::U8), VarType::Char(c)) From 1adcacd1bf8ff369be0cf4935348b11b0e765541 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Thu, 9 Jan 2025 00:50:02 -0500 Subject: [PATCH 849/942] Fix `flat_map_option` lint --- Cargo.toml | 1 - bindgen/codegen/mod.rs | 9 +++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 17689e9c7e..6978f49e07 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -59,7 +59,6 @@ cast_precision_loss = "allow" cast_sign_loss = "allow" default_trait_access = "allow" explicit_into_iter_loop = "allow" -flat_map_option = "allow" ignored_unit_patterns = "allow" implicit_hasher = "allow" items_after_statements = "allow" diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 157478d3c5..1777aaf55a 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -2630,12 +2630,9 @@ impl CodeGenerator for CompInfo { } else { self.fields() .iter() - .filter_map(|field| match *field { - Field::DataMember(ref f) if f.name().is_some() => Some(f), - _ => None, - }) - .flat_map(|field| { - let name = field.name().unwrap(); + .filter_map(|field| { + let Field::DataMember(field) = field else { return None }; + let name = field.name()?; field.offset().map(|offset| { let field_offset = offset / 8; let field_name = ctx.rust_ident(name); From 9ce9a1ccd6992a22b8d317aff90d0df72fded5c9 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Thu, 9 Jan 2025 00:27:41 -0500 Subject: [PATCH 850/942] use `assert_eq|_ne` instead of `assert!` --- bindgen/codegen/mod.rs | 2 +- bindgen/ir/context.rs | 16 ++++++++-------- bindgen/ir/objc.rs | 5 +---- bindgen/lib.rs | 5 +++-- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 1777aaf55a..ccf632535e 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -2701,7 +2701,7 @@ impl CodeGenerator for CompInfo { let mut method_names = Default::default(); if ctx.options().codegen_config.methods() { for method in self.methods() { - assert!(method.kind() != MethodKind::Constructor); + assert_ne!(method.kind(), MethodKind::Constructor); method.codegen_method( ctx, &mut methods, diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index 6b47560e8c..69078f58f4 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -782,7 +782,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// codegen'd, even if its parent is not allowlisted. See issue #769 for /// details. fn add_item_to_module(&mut self, item: &Item) { - assert!(item.id() != self.root_module); + assert_ne!(item.id(), self.root_module); assert!(self.resolve_item_fallible(item.id()).is_none()); if let Some(ref mut parent) = self.items[item.parent_id().0] { @@ -804,7 +804,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" self.current_module ); - self.items[(self.current_module.0).0] + self.items[self.current_module.0 .0] .as_mut() .expect("Should always have an item for self.current_module") .as_module_mut() @@ -1232,7 +1232,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" &self, ) -> traversal::AssertNoDanglingItemsTraversal { assert!(self.in_codegen_phase()); - assert!(self.current_module == self.root_module); + assert_eq!(self.current_module, self.root_module); let roots = self.items().map(|(id, _)| id); traversal::AssertNoDanglingItemsTraversal::new( @@ -1248,7 +1248,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" fn assert_every_item_in_a_module(&self) { if cfg!(feature = "__testing_only_extra_assertions") { assert!(self.in_codegen_phase()); - assert!(self.current_module == self.root_module); + assert_eq!(self.current_module, self.root_module); for (id, _item) in self.items() { if id == self.root_module { @@ -2346,7 +2346,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// allowlisted. pub(crate) fn allowlisted_items(&self) -> &ItemSet { assert!(self.in_codegen_phase()); - assert!(self.current_module == self.root_module); + assert_eq!(self.current_module, self.root_module); self.allowlisted.as_ref().unwrap() } @@ -2359,7 +2359,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" derive_trait: DeriveTrait, ) -> CanDerive { assert!(self.in_codegen_phase()); - assert!(self.current_module == self.root_module); + assert_eq!(self.current_module, self.root_module); *self .blocklisted_types_implement_traits @@ -2407,14 +2407,14 @@ If you encounter an error missing from this list, please file an issue or a PR!" /// Get a reference to the set of items we should generate. pub(crate) fn codegen_items(&self) -> &ItemSet { assert!(self.in_codegen_phase()); - assert!(self.current_module == self.root_module); + assert_eq!(self.current_module, self.root_module); self.codegen_items.as_ref().unwrap() } /// Compute the allowlisted items set and populate `self.allowlisted`. fn compute_allowlisted_and_codegen_items(&mut self) { assert!(self.in_codegen_phase()); - assert!(self.current_module == self.root_module); + assert_eq!(self.current_module, self.root_module); assert!(self.allowlisted.is_none()); let _t = self.timer("compute_allowlisted_and_codegen_items"); diff --git a/bindgen/ir/objc.rs b/bindgen/ir/objc.rs index d413d6bb95..6cdadb131d 100644 --- a/bindgen/ir/objc.rs +++ b/bindgen/ir/objc.rs @@ -294,10 +294,7 @@ impl ObjCMethod { } // Check right amount of arguments - assert!( - args.len() == split_name.len() - 1, - "Incorrect method name or arguments for objc method, {args:?} vs {split_name:?}" - ); + assert_eq!(args.len(), split_name.len() - 1, "Incorrect method name or arguments for objc method, {args:?} vs {split_name:?}"); // Get arguments without type signatures to pass to `msg_send!` let mut args_without_types = vec![]; diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 2e56856083..94c6246e6a 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -1144,8 +1144,9 @@ fn parse(context: &mut BindgenContext) -> Result<(), BindgenError> { cursor.visit_sorted(ctx, |ctx, child| parse_one(ctx, child, None)); }); - assert!( - context.current_module() == context.root_module(), + assert_eq!( + context.current_module(), + context.root_module(), "How did this happen?" ); Ok(()) From e9bd42c3c7db9ce209cbeaf967477ca861b29bf9 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Wed, 8 Jan 2025 23:39:34 -0500 Subject: [PATCH 851/942] Fix CI to not run publish all the time --- .github/workflows/publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 7333d62aff..d8602f9ad9 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -11,7 +11,7 @@ env: jobs: cargo-publish: runs-on: ubuntu-latest - if: ${{ (github.event.workflow_run.conclusion == 'success') && (github.event.workflow.name == 'Release') }} + if: ${{ !github.event.pull_request && (github.event.workflow_run.conclusion == 'success') && (github.event.workflow.name == 'Release') }} steps: - name: Print workflow event name run: echo "${{ github.event.workflow.name }}" From a3f877bd6c628b3197429173675e4e8b7e4cdb64 Mon Sep 17 00:00:00 2001 From: Lofty Inclination Date: Mon, 27 Jan 2025 09:21:29 +0000 Subject: [PATCH 852/942] add "gen" to list of matches in 'rust_mangle' --- bindgen-tests/tests/expectations/tests/keywords.rs | 4 ++++ bindgen-tests/tests/headers/keywords.h | 1 + bindgen/ir/context.rs | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/bindgen-tests/tests/expectations/tests/keywords.rs b/bindgen-tests/tests/expectations/tests/keywords.rs index ec56bbfa8b..0a55ee0463 100644 --- a/bindgen-tests/tests/expectations/tests/keywords.rs +++ b/bindgen-tests/tests/expectations/tests/keywords.rs @@ -87,6 +87,10 @@ unsafe extern "C" { #[link_name = "\u{1}fn"] pub static mut fn_: ::std::os::raw::c_int; } +unsafe extern "C" { + #[link_name = "\u{1}gen"] + pub static mut gen_: ::std::os::raw::c_int; +} unsafe extern "C" { #[link_name = "\u{1}impl"] pub static mut impl_: ::std::os::raw::c_int; diff --git a/bindgen-tests/tests/headers/keywords.h b/bindgen-tests/tests/headers/keywords.h index 3b3fc4976e..49924193c7 100644 --- a/bindgen-tests/tests/headers/keywords.h +++ b/bindgen-tests/tests/headers/keywords.h @@ -21,6 +21,7 @@ int box; int crate; int false; int fn; +int gen; int impl; int in; int let; diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index 69078f58f4..c6bc9025ec 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -867,7 +867,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" "abstract" | "alignof" | "as" | "async" | "await" | "become" | "box" | "break" | "const" | "continue" | "crate" | "do" | "dyn" | "else" | "enum" | "extern" | "false" | "final" | - "fn" | "for" | "if" | "impl" | "in" | "let" | "loop" | + "fn" | "for" | "gen" | "if" | "impl" | "in" | "let" | "loop" | "macro" | "match" | "mod" | "move" | "mut" | "offsetof" | "override" | "priv" | "proc" | "pub" | "pure" | "ref" | "return" | "Self" | "self" | "sizeof" | "static" | From 43071a193a5d520b812ab4dfb0b8b5a6dd618c10 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Thu, 9 Jan 2025 00:31:47 -0500 Subject: [PATCH 853/942] Fix `explicit_into_iter_loop` lint --- Cargo.toml | 1 - bindgen/lib.rs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6978f49e07..e87c6b2018 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -58,7 +58,6 @@ cast_possible_wrap = "allow" cast_precision_loss = "allow" cast_sign_loss = "allow" default_trait_access = "allow" -explicit_into_iter_loop = "allow" ignored_unit_patterns = "allow" implicit_hasher = "allow" items_after_statements = "allow" diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 94c6246e6a..0a8f29d158 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -835,7 +835,7 @@ impl Bindings { }; if let Some(search_paths) = search_paths { - for path in search_paths.into_iter() { + for path in search_paths { if let Ok(path) = path.into_os_string().into_string() { options.clang_args.push("-isystem".into()); options.clang_args.push(path.into_boxed_str()); From d95359fe88f1cb7369af24af0f5c17cde4cb2463 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Wed, 8 Jan 2025 23:21:42 -0500 Subject: [PATCH 854/942] Fix `borrow_as_ptr` lint --- Cargo.toml | 1 - bindgen/clang.rs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e87c6b2018..b0a5bbb082 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -78,7 +78,6 @@ used_underscore_binding = "allow" wildcard_imports = "allow" # TODO -borrow_as_ptr = "allow" trivially_copy_pass_by_ref = "allow" unused_self = "allow" diff --git a/bindgen/clang.rs b/bindgen/clang.rs index 2440bc0ae6..9afc6e93b1 100644 --- a/bindgen/clang.rs +++ b/bindgen/clang.rs @@ -494,7 +494,7 @@ impl Cursor { where Visitor: FnMut(Cursor) -> CXChildVisitResult, { - let data = &mut visitor as *mut Visitor; + let data = ptr::addr_of_mut!(visitor); unsafe { clang_visitChildren(self.x, visit_children::, data.cast()); } From 03d49b6181c81ff07d709aefe966e0854197109f Mon Sep 17 00:00:00 2001 From: Molot2032 <117271367+Molot2032@users.noreply.github.com> Date: Tue, 28 Jan 2025 13:44:27 +1000 Subject: [PATCH 855/942] Use link_name for dynamic library loading --- .../tests/dynamic_loading_template.rs | 4 +- .../tests/dynamic_loading_with_allowlist.rs | 6 +-- .../tests/dynamic_loading_with_blocklist.rs | 4 +- .../tests/dynamic_loading_with_class.rs | 4 +- bindgen/codegen/dyngen.rs | 16 ++++--- bindgen/codegen/mod.rs | 47 ++++++++++--------- 6 files changed, 44 insertions(+), 37 deletions(-) diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_template.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_template.rs index 65f079bede..1f63a7893f 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_template.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_template.rs @@ -20,8 +20,8 @@ impl TestLib { L: Into<::libloading::Library>, { let __library = library.into(); - let foo = __library.get(b"foo\0").map(|sym| *sym); - let foo1 = __library.get(b"foo1\0").map(|sym| *sym); + let foo = __library.get(b"_Z3fooIiET_S0_\0").map(|sym| *sym); + let foo1 = __library.get(b"_Z3fooIfET_S0_\0").map(|sym| *sym); Ok(TestLib { __library, foo, foo1 }) } pub unsafe fn foo(&self, x: ::std::os::raw::c_int) -> ::std::os::raw::c_int { diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_allowlist.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_allowlist.rs index e65176b863..34ebe8d9a5 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_allowlist.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_allowlist.rs @@ -27,9 +27,9 @@ impl TestLib { L: Into<::libloading::Library>, { let __library = library.into(); - let foo = __library.get(b"foo\0").map(|sym| *sym); - let baz = __library.get(b"baz\0").map(|sym| *sym); - let bazz = __library.get(b"bazz\0").map(|sym| *sym); + let foo = __library.get(b"_Z3fooPv\0").map(|sym| *sym); + let baz = __library.get(b"_Z3bazPv\0").map(|sym| *sym); + let bazz = __library.get(b"_Z4bazziz\0").map(|sym| *sym); Ok(TestLib { __library, foo, diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_blocklist.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_blocklist.rs index b214d0ef4e..8c86674f7a 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_blocklist.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_blocklist.rs @@ -62,8 +62,8 @@ impl TestLib { L: Into<::libloading::Library>, { let __library = library.into(); - let foo = __library.get(b"foo\0").map(|sym| *sym); - let bar = __library.get(b"bar\0").map(|sym| *sym); + let foo = __library.get(b"_Z3fooPv\0").map(|sym| *sym); + let bar = __library.get(b"_Z3barPv\0").map(|sym| *sym); Ok(TestLib { __library, foo, bar }) } pub unsafe fn foo(&self, x: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int { diff --git a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs index 6395b0c6d3..65ff2b2f72 100644 --- a/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs +++ b/bindgen-tests/tests/expectations/tests/dynamic_loading_with_class.rs @@ -59,8 +59,8 @@ impl TestLib { L: Into<::libloading::Library>, { let __library = library.into(); - let foo = __library.get(b"foo\0").map(|sym| *sym); - let bar = __library.get(b"bar\0").map(|sym| *sym); + let foo = __library.get(b"_Z3fooPv\0").map(|sym| *sym); + let bar = __library.get(b"_Z3barv\0").map(|sym| *sym); Ok(TestLib { __library, foo, bar }) } pub unsafe fn foo(&self, x: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int { diff --git a/bindgen/codegen/dyngen.rs b/bindgen/codegen/dyngen.rs index 410cc0d6cb..76f3805795 100644 --- a/bindgen/codegen/dyngen.rs +++ b/bindgen/codegen/dyngen.rs @@ -131,6 +131,7 @@ impl DynamicItems { pub(crate) fn push_func( &mut self, ident: &Ident, + symbol: &str, abi: ClangAbi, is_variadic: bool, is_required: bool, @@ -181,11 +182,12 @@ impl DynamicItems { } // N.B: Unwrap the signature upon construction if it is required to be resolved. - let ident_str = codegen::helpers::ast_ty::cstr_expr(ident.to_string()); + let symbol_cstr = + codegen::helpers::ast_ty::cstr_expr(symbol.to_string()); let library_get = if ctx.options().wrap_unsafe_ops { - quote!(unsafe { __library.get(#ident_str) }) + quote!(unsafe { __library.get(#symbol_cstr) }) } else { - quote!(__library.get(#ident_str)) + quote!(__library.get(#symbol_cstr)) }; self.constructor_inits.push(if is_required { @@ -206,6 +208,7 @@ impl DynamicItems { pub fn push_var( &mut self, ident: &Ident, + symbol: &str, ty: &TokenStream, is_required: bool, wrap_unsafe_ops: bool, @@ -231,12 +234,13 @@ impl DynamicItems { } }); - let ident_str = codegen::helpers::ast_ty::cstr_expr(ident.to_string()); + let symbol_cstr = + codegen::helpers::ast_ty::cstr_expr(symbol.to_string()); let library_get = if wrap_unsafe_ops { - quote!(unsafe { __library.get::<*mut #ty>(#ident_str) }) + quote!(unsafe { __library.get::<*mut #ty>(#symbol_cstr) }) } else { - quote!(__library.get::<*mut #ty>(#ident_str)) + quote!(__library.get::<*mut #ty>(#symbol_cstr)) }; let qmark = if is_required { quote!(?) } else { quote!() }; diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index ccf632535e..f58a234117 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -779,20 +779,20 @@ impl CodeGenerator for Var { } } } else { - // If necessary, apply a `#[link_name]` attribute - if let Some(link_name) = self.link_name() { - attrs.push(attributes::link_name::(link_name)); - } else { + let symbol: &str = self.link_name().unwrap_or_else(|| { let link_name = self.mangled_name().unwrap_or_else(|| self.name()); - if !utils::names_will_be_identical_after_mangling( + if utils::names_will_be_identical_after_mangling( &canonical_name, link_name, None, ) { + canonical_name.as_str() + } else { attrs.push(attributes::link_name::(link_name)); + link_name } - } + }); let maybe_mut = if self.is_const() { quote! {} @@ -816,6 +816,7 @@ impl CodeGenerator for Var { if ctx.options().dynamic_library_name.is_some() { result.dynamic_items().push_var( &canonical_ident, + symbol, &self .ty() .to_rust_ty_or_opaque(ctx, &()) @@ -4639,21 +4640,19 @@ impl CodeGenerator for Function { write!(&mut canonical_name, "{times_seen}").unwrap(); } - let mut has_link_name_attr = false; - if let Some(link_name) = self.link_name() { - attributes.push(attributes::link_name::(link_name)); - has_link_name_attr = true; - } else { - let link_name = mangled_name.unwrap_or(name); - if !is_dynamic_function && - !utils::names_will_be_identical_after_mangling( - &canonical_name, - link_name, - Some(abi), - ) - { + let link_name_attr = self.link_name().or_else(|| { + let mangled_name = mangled_name.unwrap_or(name); + (!utils::names_will_be_identical_after_mangling( + &canonical_name, + mangled_name, + Some(abi), + )) + .then(|| mangled_name) + }); + + if let Some(link_name) = link_name_attr { + if !is_dynamic_function { attributes.push(attributes::link_name::(link_name)); - has_link_name_attr = true; } } @@ -4665,8 +4664,9 @@ impl CodeGenerator for Function { quote! { #[link(wasm_import_module = #name)] } }); - let should_wrap = - is_internal && ctx.options().wrap_static_fns && !has_link_name_attr; + let should_wrap = is_internal && + ctx.options().wrap_static_fns && + link_name_attr.is_none(); if should_wrap { let name = canonical_name.clone() + ctx.wrap_static_fns_suffix(); @@ -4732,11 +4732,14 @@ impl CodeGenerator for Function { // If we're doing dynamic binding generation, add to the dynamic items. if is_dynamic_function { + let ident_str = ident.to_string(); + let symbol = link_name_attr.unwrap_or(&ident_str); let args_identifiers = utils::fnsig_argument_identifiers(ctx, signature); let ret_ty = utils::fnsig_return_ty(ctx, signature); result.dynamic_items().push_func( &ident, + symbol, abi, signature.is_variadic(), ctx.options().dynamic_link_require_all, From 068d4ce0da69517ac7a017f201810ca86f166ce8 Mon Sep 17 00:00:00 2001 From: Nik Konyuchenko Date: Sat, 8 Feb 2025 18:59:28 -0800 Subject: [PATCH 856/942] Fixes #3123 Signed-off-by: Nik Konyuchenko --- .../expectations/tests/bitfield-32bit-overflow.rs | 12 +++++++----- .../tests/expectations/tests/bitfield-large.rs | 12 +++++++----- .../tests/expectations/tests/bitfield-linux-32.rs | 12 +++++++----- .../expectations/tests/bitfield-method-same-name.rs | 12 +++++++----- .../tests/expectations/tests/bitfield_align.rs | 12 +++++++----- .../tests/expectations/tests/bitfield_align_2.rs | 12 +++++++----- .../expectations/tests/bitfield_method_mangling.rs | 12 +++++++----- .../expectations/tests/bitfield_pragma_packed.rs | 12 +++++++----- .../expectations/tests/default_visibility_crate.rs | 12 +++++++----- .../expectations/tests/default_visibility_private.rs | 12 +++++++----- ...lt_visibility_private_respects_cxx_access_spec.rs | 12 +++++++----- .../expectations/tests/derive-debug-bitfield-1-51.rs | 12 +++++++----- .../tests/divide-by-zero-in-struct-layout.rs | 12 +++++++----- .../expectations/tests/field-visibility-callback.rs | 12 +++++++----- .../tests/expectations/tests/field-visibility.rs | 12 +++++++----- .../expectations/tests/incomplete-array-padding.rs | 12 +++++++----- bindgen-tests/tests/expectations/tests/issue-1034.rs | 12 +++++++----- .../tests/issue-1076-unnamed-bitfield-alignment.rs | 12 +++++++----- bindgen-tests/tests/expectations/tests/issue-1947.rs | 12 +++++++----- .../tests/issue-739-pointer-wide-bitfield.rs | 12 +++++++----- bindgen-tests/tests/expectations/tests/issue-816.rs | 12 +++++++----- .../tests/expectations/tests/jsval_layout_opaque.rs | 12 +++++++----- .../tests/expectations/tests/layout_align.rs | 12 +++++++----- .../tests/expectations/tests/layout_mbuf.rs | 12 +++++++----- .../tests/expectations/tests/only_bitfields.rs | 12 +++++++----- .../tests/expectations/tests/packed-bitfield.rs | 12 +++++++----- .../tests/expectations/tests/private_fields.rs | 12 +++++++----- .../expectations/tests/redundant-packed-and-align.rs | 12 +++++++----- .../expectations/tests/struct_with_bitfields.rs | 12 +++++++----- bindgen-tests/tests/expectations/tests/timex.rs | 12 +++++++----- .../tests/expectations/tests/union_bitfield.rs | 12 +++++++----- .../tests/union_with_anon_struct_bitfield.rs | 12 +++++++----- .../tests/expectations/tests/weird_bitfields.rs | 12 +++++++----- bindgen/codegen/bitfield_unit_raw_ref_macros.rs | 10 +++++----- 34 files changed, 236 insertions(+), 170 deletions(-) diff --git a/bindgen-tests/tests/expectations/tests/bitfield-32bit-overflow.rs b/bindgen-tests/tests/expectations/tests/bitfield-32bit-overflow.rs index 7125be5607..d45c8ed92b 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-32bit-overflow.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-32bit-overflow.rs @@ -35,8 +35,10 @@ where 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 = *(core::ptr::addr_of!((*this).storage) as *const u8) - .offset(byte_index as isize); + let byte = unsafe { + *(core::ptr::addr_of!((*this).storage) as *const u8) + .offset(byte_index as isize) + }; Self::extract_bit(byte, index) } #[inline] @@ -62,7 +64,7 @@ where let byte_index = index / 8; let byte = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) .offset(byte_index as isize); - *byte = Self::change_bit(*byte, index, val); + unsafe { *byte = Self::change_bit(*byte, index, val) }; } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -93,7 +95,7 @@ where ); let mut val = 0; for i in 0..(bit_width as usize) { - if Self::raw_get_bit(this, i + bit_offset) { + if unsafe { Self::raw_get_bit(this, i + bit_offset) } { let index = if cfg!(target_endian = "big") { bit_width as usize - 1 - i } else { @@ -137,7 +139,7 @@ where } else { i }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + unsafe { Self::raw_set_bit(this, index + bit_offset, val_bit_is_set) }; } } } diff --git a/bindgen-tests/tests/expectations/tests/bitfield-large.rs b/bindgen-tests/tests/expectations/tests/bitfield-large.rs index 47afa9a3ba..d32a689740 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-large.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-large.rs @@ -35,8 +35,10 @@ where 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 = *(core::ptr::addr_of!((*this).storage) as *const u8) - .offset(byte_index as isize); + let byte = unsafe { + *(core::ptr::addr_of!((*this).storage) as *const u8) + .offset(byte_index as isize) + }; Self::extract_bit(byte, index) } #[inline] @@ -62,7 +64,7 @@ where let byte_index = index / 8; let byte = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) .offset(byte_index as isize); - *byte = Self::change_bit(*byte, index, val); + unsafe { *byte = Self::change_bit(*byte, index, val) }; } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -93,7 +95,7 @@ where ); let mut val = 0; for i in 0..(bit_width as usize) { - if Self::raw_get_bit(this, i + bit_offset) { + if unsafe { Self::raw_get_bit(this, i + bit_offset) } { let index = if cfg!(target_endian = "big") { bit_width as usize - 1 - i } else { @@ -137,7 +139,7 @@ where } else { i }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + unsafe { Self::raw_set_bit(this, index + bit_offset, val_bit_is_set) }; } } } diff --git a/bindgen-tests/tests/expectations/tests/bitfield-linux-32.rs b/bindgen-tests/tests/expectations/tests/bitfield-linux-32.rs index 075aa27e5e..10935f5d12 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-linux-32.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-linux-32.rs @@ -35,8 +35,10 @@ where 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 = *(core::ptr::addr_of!((*this).storage) as *const u8) - .offset(byte_index as isize); + let byte = unsafe { + *(core::ptr::addr_of!((*this).storage) as *const u8) + .offset(byte_index as isize) + }; Self::extract_bit(byte, index) } #[inline] @@ -62,7 +64,7 @@ where let byte_index = index / 8; let byte = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) .offset(byte_index as isize); - *byte = Self::change_bit(*byte, index, val); + unsafe { *byte = Self::change_bit(*byte, index, val) }; } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -93,7 +95,7 @@ where ); let mut val = 0; for i in 0..(bit_width as usize) { - if Self::raw_get_bit(this, i + bit_offset) { + if unsafe { Self::raw_get_bit(this, i + bit_offset) } { let index = if cfg!(target_endian = "big") { bit_width as usize - 1 - i } else { @@ -137,7 +139,7 @@ where } else { i }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + unsafe { Self::raw_set_bit(this, index + bit_offset, val_bit_is_set) }; } } } diff --git a/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs b/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs index 25cc182929..6981d385f5 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs @@ -35,8 +35,10 @@ where 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 = *(core::ptr::addr_of!((*this).storage) as *const u8) - .offset(byte_index as isize); + let byte = unsafe { + *(core::ptr::addr_of!((*this).storage) as *const u8) + .offset(byte_index as isize) + }; Self::extract_bit(byte, index) } #[inline] @@ -62,7 +64,7 @@ where let byte_index = index / 8; let byte = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) .offset(byte_index as isize); - *byte = Self::change_bit(*byte, index, val); + unsafe { *byte = Self::change_bit(*byte, index, val) }; } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -93,7 +95,7 @@ where ); let mut val = 0; for i in 0..(bit_width as usize) { - if Self::raw_get_bit(this, i + bit_offset) { + if unsafe { Self::raw_get_bit(this, i + bit_offset) } { let index = if cfg!(target_endian = "big") { bit_width as usize - 1 - i } else { @@ -137,7 +139,7 @@ where } else { i }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + unsafe { Self::raw_set_bit(this, index + bit_offset, val_bit_is_set) }; } } } diff --git a/bindgen-tests/tests/expectations/tests/bitfield_align.rs b/bindgen-tests/tests/expectations/tests/bitfield_align.rs index c1c72f3132..233da23a46 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_align.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_align.rs @@ -35,8 +35,10 @@ where 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 = *(core::ptr::addr_of!((*this).storage) as *const u8) - .offset(byte_index as isize); + let byte = unsafe { + *(core::ptr::addr_of!((*this).storage) as *const u8) + .offset(byte_index as isize) + }; Self::extract_bit(byte, index) } #[inline] @@ -62,7 +64,7 @@ where let byte_index = index / 8; let byte = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) .offset(byte_index as isize); - *byte = Self::change_bit(*byte, index, val); + unsafe { *byte = Self::change_bit(*byte, index, val) }; } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -93,7 +95,7 @@ where ); let mut val = 0; for i in 0..(bit_width as usize) { - if Self::raw_get_bit(this, i + bit_offset) { + if unsafe { Self::raw_get_bit(this, i + bit_offset) } { let index = if cfg!(target_endian = "big") { bit_width as usize - 1 - i } else { @@ -137,7 +139,7 @@ where } else { i }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + unsafe { Self::raw_set_bit(this, index + bit_offset, val_bit_is_set) }; } } } diff --git a/bindgen-tests/tests/expectations/tests/bitfield_align_2.rs b/bindgen-tests/tests/expectations/tests/bitfield_align_2.rs index 0f783fe76e..303f7a5926 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_align_2.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_align_2.rs @@ -36,8 +36,10 @@ where 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 = *(core::ptr::addr_of!((*this).storage) as *const u8) - .offset(byte_index as isize); + let byte = unsafe { + *(core::ptr::addr_of!((*this).storage) as *const u8) + .offset(byte_index as isize) + }; Self::extract_bit(byte, index) } #[inline] @@ -63,7 +65,7 @@ where let byte_index = index / 8; let byte = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) .offset(byte_index as isize); - *byte = Self::change_bit(*byte, index, val); + unsafe { *byte = Self::change_bit(*byte, index, val) }; } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -94,7 +96,7 @@ where ); let mut val = 0; for i in 0..(bit_width as usize) { - if Self::raw_get_bit(this, i + bit_offset) { + if unsafe { Self::raw_get_bit(this, i + bit_offset) } { let index = if cfg!(target_endian = "big") { bit_width as usize - 1 - i } else { @@ -138,7 +140,7 @@ where } else { i }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + unsafe { Self::raw_set_bit(this, index + bit_offset, val_bit_is_set) }; } } } diff --git a/bindgen-tests/tests/expectations/tests/bitfield_method_mangling.rs b/bindgen-tests/tests/expectations/tests/bitfield_method_mangling.rs index 966943f935..50051ab03b 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_method_mangling.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_method_mangling.rs @@ -35,8 +35,10 @@ where 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 = *(core::ptr::addr_of!((*this).storage) as *const u8) - .offset(byte_index as isize); + let byte = unsafe { + *(core::ptr::addr_of!((*this).storage) as *const u8) + .offset(byte_index as isize) + }; Self::extract_bit(byte, index) } #[inline] @@ -62,7 +64,7 @@ where let byte_index = index / 8; let byte = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) .offset(byte_index as isize); - *byte = Self::change_bit(*byte, index, val); + unsafe { *byte = Self::change_bit(*byte, index, val) }; } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -93,7 +95,7 @@ where ); let mut val = 0; for i in 0..(bit_width as usize) { - if Self::raw_get_bit(this, i + bit_offset) { + if unsafe { Self::raw_get_bit(this, i + bit_offset) } { let index = if cfg!(target_endian = "big") { bit_width as usize - 1 - i } else { @@ -137,7 +139,7 @@ where } else { i }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + unsafe { Self::raw_set_bit(this, index + bit_offset, val_bit_is_set) }; } } } diff --git a/bindgen-tests/tests/expectations/tests/bitfield_pragma_packed.rs b/bindgen-tests/tests/expectations/tests/bitfield_pragma_packed.rs index 0cd2002fb6..ea10bca1d3 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_pragma_packed.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_pragma_packed.rs @@ -35,8 +35,10 @@ where 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 = *(core::ptr::addr_of!((*this).storage) as *const u8) - .offset(byte_index as isize); + let byte = unsafe { + *(core::ptr::addr_of!((*this).storage) as *const u8) + .offset(byte_index as isize) + }; Self::extract_bit(byte, index) } #[inline] @@ -62,7 +64,7 @@ where let byte_index = index / 8; let byte = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) .offset(byte_index as isize); - *byte = Self::change_bit(*byte, index, val); + unsafe { *byte = Self::change_bit(*byte, index, val) }; } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -93,7 +95,7 @@ where ); let mut val = 0; for i in 0..(bit_width as usize) { - if Self::raw_get_bit(this, i + bit_offset) { + if unsafe { Self::raw_get_bit(this, i + bit_offset) } { let index = if cfg!(target_endian = "big") { bit_width as usize - 1 - i } else { @@ -137,7 +139,7 @@ where } else { i }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + unsafe { Self::raw_set_bit(this, index + bit_offset, val_bit_is_set) }; } } } diff --git a/bindgen-tests/tests/expectations/tests/default_visibility_crate.rs b/bindgen-tests/tests/expectations/tests/default_visibility_crate.rs index 0aca5a3b8a..c535cdb874 100644 --- a/bindgen-tests/tests/expectations/tests/default_visibility_crate.rs +++ b/bindgen-tests/tests/expectations/tests/default_visibility_crate.rs @@ -35,8 +35,10 @@ where 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 = *(core::ptr::addr_of!((*this).storage) as *const u8) - .offset(byte_index as isize); + let byte = unsafe { + *(core::ptr::addr_of!((*this).storage) as *const u8) + .offset(byte_index as isize) + }; Self::extract_bit(byte, index) } #[inline] @@ -62,7 +64,7 @@ where let byte_index = index / 8; let byte = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) .offset(byte_index as isize); - *byte = Self::change_bit(*byte, index, val); + unsafe { *byte = Self::change_bit(*byte, index, val) }; } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -93,7 +95,7 @@ where ); let mut val = 0; for i in 0..(bit_width as usize) { - if Self::raw_get_bit(this, i + bit_offset) { + if unsafe { Self::raw_get_bit(this, i + bit_offset) } { let index = if cfg!(target_endian = "big") { bit_width as usize - 1 - i } else { @@ -137,7 +139,7 @@ where } else { i }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + unsafe { Self::raw_set_bit(this, index + bit_offset, val_bit_is_set) }; } } } diff --git a/bindgen-tests/tests/expectations/tests/default_visibility_private.rs b/bindgen-tests/tests/expectations/tests/default_visibility_private.rs index 0d4d42cfdb..7083e8231b 100644 --- a/bindgen-tests/tests/expectations/tests/default_visibility_private.rs +++ b/bindgen-tests/tests/expectations/tests/default_visibility_private.rs @@ -35,8 +35,10 @@ where 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 = *(core::ptr::addr_of!((*this).storage) as *const u8) - .offset(byte_index as isize); + let byte = unsafe { + *(core::ptr::addr_of!((*this).storage) as *const u8) + .offset(byte_index as isize) + }; Self::extract_bit(byte, index) } #[inline] @@ -62,7 +64,7 @@ where let byte_index = index / 8; let byte = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) .offset(byte_index as isize); - *byte = Self::change_bit(*byte, index, val); + unsafe { *byte = Self::change_bit(*byte, index, val) }; } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -93,7 +95,7 @@ where ); let mut val = 0; for i in 0..(bit_width as usize) { - if Self::raw_get_bit(this, i + bit_offset) { + if unsafe { Self::raw_get_bit(this, i + bit_offset) } { let index = if cfg!(target_endian = "big") { bit_width as usize - 1 - i } else { @@ -137,7 +139,7 @@ where } else { i }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + unsafe { Self::raw_set_bit(this, index + bit_offset, val_bit_is_set) }; } } } diff --git a/bindgen-tests/tests/expectations/tests/default_visibility_private_respects_cxx_access_spec.rs b/bindgen-tests/tests/expectations/tests/default_visibility_private_respects_cxx_access_spec.rs index cf135cfd3d..71ad6f9b12 100644 --- a/bindgen-tests/tests/expectations/tests/default_visibility_private_respects_cxx_access_spec.rs +++ b/bindgen-tests/tests/expectations/tests/default_visibility_private_respects_cxx_access_spec.rs @@ -35,8 +35,10 @@ where 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 = *(core::ptr::addr_of!((*this).storage) as *const u8) - .offset(byte_index as isize); + let byte = unsafe { + *(core::ptr::addr_of!((*this).storage) as *const u8) + .offset(byte_index as isize) + }; Self::extract_bit(byte, index) } #[inline] @@ -62,7 +64,7 @@ where let byte_index = index / 8; let byte = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) .offset(byte_index as isize); - *byte = Self::change_bit(*byte, index, val); + unsafe { *byte = Self::change_bit(*byte, index, val) }; } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -93,7 +95,7 @@ where ); let mut val = 0; for i in 0..(bit_width as usize) { - if Self::raw_get_bit(this, i + bit_offset) { + if unsafe { Self::raw_get_bit(this, i + bit_offset) } { let index = if cfg!(target_endian = "big") { bit_width as usize - 1 - i } else { @@ -137,7 +139,7 @@ where } else { i }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + unsafe { Self::raw_set_bit(this, index + bit_offset, val_bit_is_set) }; } } } 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 fa007056a1..01839b9f0b 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 @@ -35,8 +35,10 @@ where 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 = *(core::ptr::addr_of!((*this).storage) as *const u8) - .offset(byte_index as isize); + let byte = unsafe { + *(core::ptr::addr_of!((*this).storage) as *const u8) + .offset(byte_index as isize) + }; Self::extract_bit(byte, index) } #[inline] @@ -62,7 +64,7 @@ where let byte_index = index / 8; let byte = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) .offset(byte_index as isize); - *byte = Self::change_bit(*byte, index, val); + unsafe { *byte = Self::change_bit(*byte, index, val) }; } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -93,7 +95,7 @@ where ); let mut val = 0; for i in 0..(bit_width as usize) { - if Self::raw_get_bit(this, i + bit_offset) { + if unsafe { Self::raw_get_bit(this, i + bit_offset) } { let index = if cfg!(target_endian = "big") { bit_width as usize - 1 - i } else { @@ -137,7 +139,7 @@ where } else { i }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + unsafe { Self::raw_set_bit(this, index + bit_offset, val_bit_is_set) }; } } } diff --git a/bindgen-tests/tests/expectations/tests/divide-by-zero-in-struct-layout.rs b/bindgen-tests/tests/expectations/tests/divide-by-zero-in-struct-layout.rs index 0e1fe567ac..de5cf210e2 100644 --- a/bindgen-tests/tests/expectations/tests/divide-by-zero-in-struct-layout.rs +++ b/bindgen-tests/tests/expectations/tests/divide-by-zero-in-struct-layout.rs @@ -35,8 +35,10 @@ where 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 = *(core::ptr::addr_of!((*this).storage) as *const u8) - .offset(byte_index as isize); + let byte = unsafe { + *(core::ptr::addr_of!((*this).storage) as *const u8) + .offset(byte_index as isize) + }; Self::extract_bit(byte, index) } #[inline] @@ -62,7 +64,7 @@ where let byte_index = index / 8; let byte = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) .offset(byte_index as isize); - *byte = Self::change_bit(*byte, index, val); + unsafe { *byte = Self::change_bit(*byte, index, val) }; } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -93,7 +95,7 @@ where ); let mut val = 0; for i in 0..(bit_width as usize) { - if Self::raw_get_bit(this, i + bit_offset) { + if unsafe { Self::raw_get_bit(this, i + bit_offset) } { let index = if cfg!(target_endian = "big") { bit_width as usize - 1 - i } else { @@ -137,7 +139,7 @@ where } else { i }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + unsafe { Self::raw_set_bit(this, index + bit_offset, val_bit_is_set) }; } } } diff --git a/bindgen-tests/tests/expectations/tests/field-visibility-callback.rs b/bindgen-tests/tests/expectations/tests/field-visibility-callback.rs index 8634dafba1..9072cb15f5 100644 --- a/bindgen-tests/tests/expectations/tests/field-visibility-callback.rs +++ b/bindgen-tests/tests/expectations/tests/field-visibility-callback.rs @@ -35,8 +35,10 @@ where 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 = *(core::ptr::addr_of!((*this).storage) as *const u8) - .offset(byte_index as isize); + let byte = unsafe { + *(core::ptr::addr_of!((*this).storage) as *const u8) + .offset(byte_index as isize) + }; Self::extract_bit(byte, index) } #[inline] @@ -62,7 +64,7 @@ where let byte_index = index / 8; let byte = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) .offset(byte_index as isize); - *byte = Self::change_bit(*byte, index, val); + unsafe { *byte = Self::change_bit(*byte, index, val) }; } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -93,7 +95,7 @@ where ); let mut val = 0; for i in 0..(bit_width as usize) { - if Self::raw_get_bit(this, i + bit_offset) { + if unsafe { Self::raw_get_bit(this, i + bit_offset) } { let index = if cfg!(target_endian = "big") { bit_width as usize - 1 - i } else { @@ -137,7 +139,7 @@ where } else { i }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + unsafe { Self::raw_set_bit(this, index + bit_offset, val_bit_is_set) }; } } } diff --git a/bindgen-tests/tests/expectations/tests/field-visibility.rs b/bindgen-tests/tests/expectations/tests/field-visibility.rs index 5dfe7502d3..9c56ca3f9e 100644 --- a/bindgen-tests/tests/expectations/tests/field-visibility.rs +++ b/bindgen-tests/tests/expectations/tests/field-visibility.rs @@ -35,8 +35,10 @@ where 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 = *(core::ptr::addr_of!((*this).storage) as *const u8) - .offset(byte_index as isize); + let byte = unsafe { + *(core::ptr::addr_of!((*this).storage) as *const u8) + .offset(byte_index as isize) + }; Self::extract_bit(byte, index) } #[inline] @@ -62,7 +64,7 @@ where let byte_index = index / 8; let byte = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) .offset(byte_index as isize); - *byte = Self::change_bit(*byte, index, val); + unsafe { *byte = Self::change_bit(*byte, index, val) }; } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -93,7 +95,7 @@ where ); let mut val = 0; for i in 0..(bit_width as usize) { - if Self::raw_get_bit(this, i + bit_offset) { + if unsafe { Self::raw_get_bit(this, i + bit_offset) } { let index = if cfg!(target_endian = "big") { bit_width as usize - 1 - i } else { @@ -137,7 +139,7 @@ where } else { i }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + unsafe { Self::raw_set_bit(this, index + bit_offset, val_bit_is_set) }; } } } diff --git a/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs b/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs index 6e420e9fc3..4f52511400 100644 --- a/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs +++ b/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs @@ -35,8 +35,10 @@ where 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 = *(core::ptr::addr_of!((*this).storage) as *const u8) - .offset(byte_index as isize); + let byte = unsafe { + *(core::ptr::addr_of!((*this).storage) as *const u8) + .offset(byte_index as isize) + }; Self::extract_bit(byte, index) } #[inline] @@ -62,7 +64,7 @@ where let byte_index = index / 8; let byte = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) .offset(byte_index as isize); - *byte = Self::change_bit(*byte, index, val); + unsafe { *byte = Self::change_bit(*byte, index, val) }; } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -93,7 +95,7 @@ where ); let mut val = 0; for i in 0..(bit_width as usize) { - if Self::raw_get_bit(this, i + bit_offset) { + if unsafe { Self::raw_get_bit(this, i + bit_offset) } { let index = if cfg!(target_endian = "big") { bit_width as usize - 1 - i } else { @@ -137,7 +139,7 @@ where } else { i }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + unsafe { Self::raw_set_bit(this, index + bit_offset, val_bit_is_set) }; } } } diff --git a/bindgen-tests/tests/expectations/tests/issue-1034.rs b/bindgen-tests/tests/expectations/tests/issue-1034.rs index 75e3ed3858..8df55e7e49 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1034.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1034.rs @@ -35,8 +35,10 @@ where 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 = *(core::ptr::addr_of!((*this).storage) as *const u8) - .offset(byte_index as isize); + let byte = unsafe { + *(core::ptr::addr_of!((*this).storage) as *const u8) + .offset(byte_index as isize) + }; Self::extract_bit(byte, index) } #[inline] @@ -62,7 +64,7 @@ where let byte_index = index / 8; let byte = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) .offset(byte_index as isize); - *byte = Self::change_bit(*byte, index, val); + unsafe { *byte = Self::change_bit(*byte, index, val) }; } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -93,7 +95,7 @@ where ); let mut val = 0; for i in 0..(bit_width as usize) { - if Self::raw_get_bit(this, i + bit_offset) { + if unsafe { Self::raw_get_bit(this, i + bit_offset) } { let index = if cfg!(target_endian = "big") { bit_width as usize - 1 - i } else { @@ -137,7 +139,7 @@ where } else { i }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + unsafe { Self::raw_set_bit(this, index + bit_offset, val_bit_is_set) }; } } } diff --git a/bindgen-tests/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs b/bindgen-tests/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs index 7d517e5633..2dc273ab01 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs @@ -35,8 +35,10 @@ where 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 = *(core::ptr::addr_of!((*this).storage) as *const u8) - .offset(byte_index as isize); + let byte = unsafe { + *(core::ptr::addr_of!((*this).storage) as *const u8) + .offset(byte_index as isize) + }; Self::extract_bit(byte, index) } #[inline] @@ -62,7 +64,7 @@ where let byte_index = index / 8; let byte = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) .offset(byte_index as isize); - *byte = Self::change_bit(*byte, index, val); + unsafe { *byte = Self::change_bit(*byte, index, val) }; } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -93,7 +95,7 @@ where ); let mut val = 0; for i in 0..(bit_width as usize) { - if Self::raw_get_bit(this, i + bit_offset) { + if unsafe { Self::raw_get_bit(this, i + bit_offset) } { let index = if cfg!(target_endian = "big") { bit_width as usize - 1 - i } else { @@ -137,7 +139,7 @@ where } else { i }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + unsafe { Self::raw_set_bit(this, index + bit_offset, val_bit_is_set) }; } } } diff --git a/bindgen-tests/tests/expectations/tests/issue-1947.rs b/bindgen-tests/tests/expectations/tests/issue-1947.rs index bec383bbdb..e03d764bb8 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1947.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1947.rs @@ -35,8 +35,10 @@ where 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 = *(core::ptr::addr_of!((*this).storage) as *const u8) - .offset(byte_index as isize); + let byte = unsafe { + *(core::ptr::addr_of!((*this).storage) as *const u8) + .offset(byte_index as isize) + }; Self::extract_bit(byte, index) } #[inline] @@ -62,7 +64,7 @@ where let byte_index = index / 8; let byte = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) .offset(byte_index as isize); - *byte = Self::change_bit(*byte, index, val); + unsafe { *byte = Self::change_bit(*byte, index, val) }; } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -93,7 +95,7 @@ where ); let mut val = 0; for i in 0..(bit_width as usize) { - if Self::raw_get_bit(this, i + bit_offset) { + if unsafe { Self::raw_get_bit(this, i + bit_offset) } { let index = if cfg!(target_endian = "big") { bit_width as usize - 1 - i } else { @@ -137,7 +139,7 @@ where } else { i }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + unsafe { Self::raw_set_bit(this, index + bit_offset, val_bit_is_set) }; } } } diff --git a/bindgen-tests/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs b/bindgen-tests/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs index 7fbc89b21c..9f68752dea 100644 --- a/bindgen-tests/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs @@ -36,8 +36,10 @@ where 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 = *(core::ptr::addr_of!((*this).storage) as *const u8) - .offset(byte_index as isize); + let byte = unsafe { + *(core::ptr::addr_of!((*this).storage) as *const u8) + .offset(byte_index as isize) + }; Self::extract_bit(byte, index) } #[inline] @@ -63,7 +65,7 @@ where let byte_index = index / 8; let byte = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) .offset(byte_index as isize); - *byte = Self::change_bit(*byte, index, val); + unsafe { *byte = Self::change_bit(*byte, index, val) }; } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -94,7 +96,7 @@ where ); let mut val = 0; for i in 0..(bit_width as usize) { - if Self::raw_get_bit(this, i + bit_offset) { + if unsafe { Self::raw_get_bit(this, i + bit_offset) } { let index = if cfg!(target_endian = "big") { bit_width as usize - 1 - i } else { @@ -138,7 +140,7 @@ where } else { i }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + unsafe { Self::raw_set_bit(this, index + bit_offset, val_bit_is_set) }; } } } diff --git a/bindgen-tests/tests/expectations/tests/issue-816.rs b/bindgen-tests/tests/expectations/tests/issue-816.rs index 9ee600fd74..f6c94f24ed 100644 --- a/bindgen-tests/tests/expectations/tests/issue-816.rs +++ b/bindgen-tests/tests/expectations/tests/issue-816.rs @@ -35,8 +35,10 @@ where 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 = *(core::ptr::addr_of!((*this).storage) as *const u8) - .offset(byte_index as isize); + let byte = unsafe { + *(core::ptr::addr_of!((*this).storage) as *const u8) + .offset(byte_index as isize) + }; Self::extract_bit(byte, index) } #[inline] @@ -62,7 +64,7 @@ where let byte_index = index / 8; let byte = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) .offset(byte_index as isize); - *byte = Self::change_bit(*byte, index, val); + unsafe { *byte = Self::change_bit(*byte, index, val) }; } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -93,7 +95,7 @@ where ); let mut val = 0; for i in 0..(bit_width as usize) { - if Self::raw_get_bit(this, i + bit_offset) { + if unsafe { Self::raw_get_bit(this, i + bit_offset) } { let index = if cfg!(target_endian = "big") { bit_width as usize - 1 - i } else { @@ -137,7 +139,7 @@ where } else { i }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + unsafe { Self::raw_set_bit(this, index + bit_offset, val_bit_is_set) }; } } } diff --git a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs index c8f406db19..6b05adbf12 100644 --- a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs +++ b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs @@ -35,8 +35,10 @@ where 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 = *(core::ptr::addr_of!((*this).storage) as *const u8) - .offset(byte_index as isize); + let byte = unsafe { + *(core::ptr::addr_of!((*this).storage) as *const u8) + .offset(byte_index as isize) + }; Self::extract_bit(byte, index) } #[inline] @@ -62,7 +64,7 @@ where let byte_index = index / 8; let byte = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) .offset(byte_index as isize); - *byte = Self::change_bit(*byte, index, val); + unsafe { *byte = Self::change_bit(*byte, index, val) }; } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -93,7 +95,7 @@ where ); let mut val = 0; for i in 0..(bit_width as usize) { - if Self::raw_get_bit(this, i + bit_offset) { + if unsafe { Self::raw_get_bit(this, i + bit_offset) } { let index = if cfg!(target_endian = "big") { bit_width as usize - 1 - i } else { @@ -137,7 +139,7 @@ where } else { i }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + unsafe { Self::raw_set_bit(this, index + bit_offset, val_bit_is_set) }; } } } diff --git a/bindgen-tests/tests/expectations/tests/layout_align.rs b/bindgen-tests/tests/expectations/tests/layout_align.rs index 906c26d57e..858cfcdd23 100644 --- a/bindgen-tests/tests/expectations/tests/layout_align.rs +++ b/bindgen-tests/tests/expectations/tests/layout_align.rs @@ -35,8 +35,10 @@ where 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 = *(core::ptr::addr_of!((*this).storage) as *const u8) - .offset(byte_index as isize); + let byte = unsafe { + *(core::ptr::addr_of!((*this).storage) as *const u8) + .offset(byte_index as isize) + }; Self::extract_bit(byte, index) } #[inline] @@ -62,7 +64,7 @@ where let byte_index = index / 8; let byte = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) .offset(byte_index as isize); - *byte = Self::change_bit(*byte, index, val); + unsafe { *byte = Self::change_bit(*byte, index, val) }; } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -93,7 +95,7 @@ where ); let mut val = 0; for i in 0..(bit_width as usize) { - if Self::raw_get_bit(this, i + bit_offset) { + if unsafe { Self::raw_get_bit(this, i + bit_offset) } { let index = if cfg!(target_endian = "big") { bit_width as usize - 1 - i } else { @@ -137,7 +139,7 @@ where } else { i }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + unsafe { Self::raw_set_bit(this, index + bit_offset, val_bit_is_set) }; } } } diff --git a/bindgen-tests/tests/expectations/tests/layout_mbuf.rs b/bindgen-tests/tests/expectations/tests/layout_mbuf.rs index 47ea51d2c2..81093dab9d 100644 --- a/bindgen-tests/tests/expectations/tests/layout_mbuf.rs +++ b/bindgen-tests/tests/expectations/tests/layout_mbuf.rs @@ -35,8 +35,10 @@ where 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 = *(core::ptr::addr_of!((*this).storage) as *const u8) - .offset(byte_index as isize); + let byte = unsafe { + *(core::ptr::addr_of!((*this).storage) as *const u8) + .offset(byte_index as isize) + }; Self::extract_bit(byte, index) } #[inline] @@ -62,7 +64,7 @@ where let byte_index = index / 8; let byte = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) .offset(byte_index as isize); - *byte = Self::change_bit(*byte, index, val); + unsafe { *byte = Self::change_bit(*byte, index, val) }; } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -93,7 +95,7 @@ where ); let mut val = 0; for i in 0..(bit_width as usize) { - if Self::raw_get_bit(this, i + bit_offset) { + if unsafe { Self::raw_get_bit(this, i + bit_offset) } { let index = if cfg!(target_endian = "big") { bit_width as usize - 1 - i } else { @@ -137,7 +139,7 @@ where } else { i }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + unsafe { Self::raw_set_bit(this, index + bit_offset, val_bit_is_set) }; } } } diff --git a/bindgen-tests/tests/expectations/tests/only_bitfields.rs b/bindgen-tests/tests/expectations/tests/only_bitfields.rs index fe317dc126..fc668d74b0 100644 --- a/bindgen-tests/tests/expectations/tests/only_bitfields.rs +++ b/bindgen-tests/tests/expectations/tests/only_bitfields.rs @@ -35,8 +35,10 @@ where 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 = *(core::ptr::addr_of!((*this).storage) as *const u8) - .offset(byte_index as isize); + let byte = unsafe { + *(core::ptr::addr_of!((*this).storage) as *const u8) + .offset(byte_index as isize) + }; Self::extract_bit(byte, index) } #[inline] @@ -62,7 +64,7 @@ where let byte_index = index / 8; let byte = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) .offset(byte_index as isize); - *byte = Self::change_bit(*byte, index, val); + unsafe { *byte = Self::change_bit(*byte, index, val) }; } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -93,7 +95,7 @@ where ); let mut val = 0; for i in 0..(bit_width as usize) { - if Self::raw_get_bit(this, i + bit_offset) { + if unsafe { Self::raw_get_bit(this, i + bit_offset) } { let index = if cfg!(target_endian = "big") { bit_width as usize - 1 - i } else { @@ -137,7 +139,7 @@ where } else { i }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + unsafe { Self::raw_set_bit(this, index + bit_offset, val_bit_is_set) }; } } } diff --git a/bindgen-tests/tests/expectations/tests/packed-bitfield.rs b/bindgen-tests/tests/expectations/tests/packed-bitfield.rs index 6aa59ec8a3..79f81979e2 100644 --- a/bindgen-tests/tests/expectations/tests/packed-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/packed-bitfield.rs @@ -35,8 +35,10 @@ where 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 = *(core::ptr::addr_of!((*this).storage) as *const u8) - .offset(byte_index as isize); + let byte = unsafe { + *(core::ptr::addr_of!((*this).storage) as *const u8) + .offset(byte_index as isize) + }; Self::extract_bit(byte, index) } #[inline] @@ -62,7 +64,7 @@ where let byte_index = index / 8; let byte = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) .offset(byte_index as isize); - *byte = Self::change_bit(*byte, index, val); + unsafe { *byte = Self::change_bit(*byte, index, val) }; } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -93,7 +95,7 @@ where ); let mut val = 0; for i in 0..(bit_width as usize) { - if Self::raw_get_bit(this, i + bit_offset) { + if unsafe { Self::raw_get_bit(this, i + bit_offset) } { let index = if cfg!(target_endian = "big") { bit_width as usize - 1 - i } else { @@ -137,7 +139,7 @@ where } else { i }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + unsafe { Self::raw_set_bit(this, index + bit_offset, val_bit_is_set) }; } } } diff --git a/bindgen-tests/tests/expectations/tests/private_fields.rs b/bindgen-tests/tests/expectations/tests/private_fields.rs index 0614b7417f..a1051f6576 100644 --- a/bindgen-tests/tests/expectations/tests/private_fields.rs +++ b/bindgen-tests/tests/expectations/tests/private_fields.rs @@ -35,8 +35,10 @@ where 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 = *(core::ptr::addr_of!((*this).storage) as *const u8) - .offset(byte_index as isize); + let byte = unsafe { + *(core::ptr::addr_of!((*this).storage) as *const u8) + .offset(byte_index as isize) + }; Self::extract_bit(byte, index) } #[inline] @@ -62,7 +64,7 @@ where let byte_index = index / 8; let byte = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) .offset(byte_index as isize); - *byte = Self::change_bit(*byte, index, val); + unsafe { *byte = Self::change_bit(*byte, index, val) }; } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -93,7 +95,7 @@ where ); let mut val = 0; for i in 0..(bit_width as usize) { - if Self::raw_get_bit(this, i + bit_offset) { + if unsafe { Self::raw_get_bit(this, i + bit_offset) } { let index = if cfg!(target_endian = "big") { bit_width as usize - 1 - i } else { @@ -137,7 +139,7 @@ where } else { i }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + unsafe { Self::raw_set_bit(this, index + bit_offset, val_bit_is_set) }; } } } diff --git a/bindgen-tests/tests/expectations/tests/redundant-packed-and-align.rs b/bindgen-tests/tests/expectations/tests/redundant-packed-and-align.rs index 43d88df698..aec3d47dd8 100644 --- a/bindgen-tests/tests/expectations/tests/redundant-packed-and-align.rs +++ b/bindgen-tests/tests/expectations/tests/redundant-packed-and-align.rs @@ -35,8 +35,10 @@ where 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 = *(core::ptr::addr_of!((*this).storage) as *const u8) - .offset(byte_index as isize); + let byte = unsafe { + *(core::ptr::addr_of!((*this).storage) as *const u8) + .offset(byte_index as isize) + }; Self::extract_bit(byte, index) } #[inline] @@ -62,7 +64,7 @@ where let byte_index = index / 8; let byte = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) .offset(byte_index as isize); - *byte = Self::change_bit(*byte, index, val); + unsafe { *byte = Self::change_bit(*byte, index, val) }; } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -93,7 +95,7 @@ where ); let mut val = 0; for i in 0..(bit_width as usize) { - if Self::raw_get_bit(this, i + bit_offset) { + if unsafe { Self::raw_get_bit(this, i + bit_offset) } { let index = if cfg!(target_endian = "big") { bit_width as usize - 1 - i } else { @@ -137,7 +139,7 @@ where } else { i }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + unsafe { Self::raw_set_bit(this, index + bit_offset, val_bit_is_set) }; } } } diff --git a/bindgen-tests/tests/expectations/tests/struct_with_bitfields.rs b/bindgen-tests/tests/expectations/tests/struct_with_bitfields.rs index 3cdf6fce1c..d904128f9e 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_bitfields.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_bitfields.rs @@ -35,8 +35,10 @@ where 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 = *(core::ptr::addr_of!((*this).storage) as *const u8) - .offset(byte_index as isize); + let byte = unsafe { + *(core::ptr::addr_of!((*this).storage) as *const u8) + .offset(byte_index as isize) + }; Self::extract_bit(byte, index) } #[inline] @@ -62,7 +64,7 @@ where let byte_index = index / 8; let byte = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) .offset(byte_index as isize); - *byte = Self::change_bit(*byte, index, val); + unsafe { *byte = Self::change_bit(*byte, index, val) }; } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -93,7 +95,7 @@ where ); let mut val = 0; for i in 0..(bit_width as usize) { - if Self::raw_get_bit(this, i + bit_offset) { + if unsafe { Self::raw_get_bit(this, i + bit_offset) } { let index = if cfg!(target_endian = "big") { bit_width as usize - 1 - i } else { @@ -137,7 +139,7 @@ where } else { i }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + unsafe { Self::raw_set_bit(this, index + bit_offset, val_bit_is_set) }; } } } diff --git a/bindgen-tests/tests/expectations/tests/timex.rs b/bindgen-tests/tests/expectations/tests/timex.rs index 0c8391c76b..99817f3122 100644 --- a/bindgen-tests/tests/expectations/tests/timex.rs +++ b/bindgen-tests/tests/expectations/tests/timex.rs @@ -35,8 +35,10 @@ where 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 = *(core::ptr::addr_of!((*this).storage) as *const u8) - .offset(byte_index as isize); + let byte = unsafe { + *(core::ptr::addr_of!((*this).storage) as *const u8) + .offset(byte_index as isize) + }; Self::extract_bit(byte, index) } #[inline] @@ -62,7 +64,7 @@ where let byte_index = index / 8; let byte = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) .offset(byte_index as isize); - *byte = Self::change_bit(*byte, index, val); + unsafe { *byte = Self::change_bit(*byte, index, val) }; } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -93,7 +95,7 @@ where ); let mut val = 0; for i in 0..(bit_width as usize) { - if Self::raw_get_bit(this, i + bit_offset) { + if unsafe { Self::raw_get_bit(this, i + bit_offset) } { let index = if cfg!(target_endian = "big") { bit_width as usize - 1 - i } else { @@ -137,7 +139,7 @@ where } else { i }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + unsafe { Self::raw_set_bit(this, index + bit_offset, val_bit_is_set) }; } } } diff --git a/bindgen-tests/tests/expectations/tests/union_bitfield.rs b/bindgen-tests/tests/expectations/tests/union_bitfield.rs index e924801114..dd3e2dde3c 100644 --- a/bindgen-tests/tests/expectations/tests/union_bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/union_bitfield.rs @@ -35,8 +35,10 @@ where 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 = *(core::ptr::addr_of!((*this).storage) as *const u8) - .offset(byte_index as isize); + let byte = unsafe { + *(core::ptr::addr_of!((*this).storage) as *const u8) + .offset(byte_index as isize) + }; Self::extract_bit(byte, index) } #[inline] @@ -62,7 +64,7 @@ where let byte_index = index / 8; let byte = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) .offset(byte_index as isize); - *byte = Self::change_bit(*byte, index, val); + unsafe { *byte = Self::change_bit(*byte, index, val) }; } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -93,7 +95,7 @@ where ); let mut val = 0; for i in 0..(bit_width as usize) { - if Self::raw_get_bit(this, i + bit_offset) { + if unsafe { Self::raw_get_bit(this, i + bit_offset) } { let index = if cfg!(target_endian = "big") { bit_width as usize - 1 - i } else { @@ -137,7 +139,7 @@ where } else { i }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + unsafe { Self::raw_set_bit(this, index + bit_offset, val_bit_is_set) }; } } } diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield.rs index 8be065da94..036eec3b7c 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield.rs @@ -35,8 +35,10 @@ where 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 = *(core::ptr::addr_of!((*this).storage) as *const u8) - .offset(byte_index as isize); + let byte = unsafe { + *(core::ptr::addr_of!((*this).storage) as *const u8) + .offset(byte_index as isize) + }; Self::extract_bit(byte, index) } #[inline] @@ -62,7 +64,7 @@ where let byte_index = index / 8; let byte = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) .offset(byte_index as isize); - *byte = Self::change_bit(*byte, index, val); + unsafe { *byte = Self::change_bit(*byte, index, val) }; } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -93,7 +95,7 @@ where ); let mut val = 0; for i in 0..(bit_width as usize) { - if Self::raw_get_bit(this, i + bit_offset) { + if unsafe { Self::raw_get_bit(this, i + bit_offset) } { let index = if cfg!(target_endian = "big") { bit_width as usize - 1 - i } else { @@ -137,7 +139,7 @@ where } else { i }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + unsafe { Self::raw_set_bit(this, index + bit_offset, val_bit_is_set) }; } } } diff --git a/bindgen-tests/tests/expectations/tests/weird_bitfields.rs b/bindgen-tests/tests/expectations/tests/weird_bitfields.rs index b3f16242f8..c5fabe6b67 100644 --- a/bindgen-tests/tests/expectations/tests/weird_bitfields.rs +++ b/bindgen-tests/tests/expectations/tests/weird_bitfields.rs @@ -35,8 +35,10 @@ where 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 = *(core::ptr::addr_of!((*this).storage) as *const u8) - .offset(byte_index as isize); + let byte = unsafe { + *(core::ptr::addr_of!((*this).storage) as *const u8) + .offset(byte_index as isize) + }; Self::extract_bit(byte, index) } #[inline] @@ -62,7 +64,7 @@ where let byte_index = index / 8; let byte = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) .offset(byte_index as isize); - *byte = Self::change_bit(*byte, index, val); + unsafe { *byte = Self::change_bit(*byte, index, val) }; } #[inline] pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { @@ -93,7 +95,7 @@ where ); let mut val = 0; for i in 0..(bit_width as usize) { - if Self::raw_get_bit(this, i + bit_offset) { + if unsafe { Self::raw_get_bit(this, i + bit_offset) } { let index = if cfg!(target_endian = "big") { bit_width as usize - 1 - i } else { @@ -137,7 +139,7 @@ where } else { i }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + 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 index 3411c22eac..a7cad6ca7b 100644 --- a/bindgen/codegen/bitfield_unit_raw_ref_macros.rs +++ b/bindgen/codegen/bitfield_unit_raw_ref_macros.rs @@ -43,8 +43,8 @@ where debug_assert!(index / 8 < core::mem::size_of::()); let byte_index = index / 8; - let byte = *(core::ptr::addr_of!((*this).storage) as *const u8) - .offset(byte_index as isize); + let byte = unsafe { *(core::ptr::addr_of!((*this).storage) as *const u8) + .offset(byte_index as isize) }; Self::extract_bit(byte, index) } @@ -83,7 +83,7 @@ where let byte = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) .offset(byte_index as isize); - *byte = Self::change_bit(*byte, index, val); + unsafe { *byte = Self::change_bit(*byte, index, val) }; } #[inline] @@ -127,7 +127,7 @@ where let mut val = 0; for i in 0..(bit_width as usize) { - if Self::raw_get_bit(this, i + bit_offset) { + if unsafe { Self::raw_get_bit(this, i + bit_offset) } { let index = if cfg!(target_endian = "big") { bit_width as usize - 1 - i } else { @@ -183,7 +183,7 @@ where } else { i }; - Self::raw_set_bit(this, index + bit_offset, val_bit_is_set); + unsafe { Self::raw_set_bit(this, index + bit_offset, val_bit_is_set) }; } } } From ee2a2acc365eb83f3af779f903180e937f125dd8 Mon Sep 17 00:00:00 2001 From: Nik Konyuchenko Date: Sat, 8 Feb 2025 19:08:02 -0800 Subject: [PATCH 857/942] Add missed unsafe in the raw_set_bit function Signed-off-by: Nik Konyuchenko --- bindgen/codegen/bitfield_unit_raw_ref_macros.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bindgen/codegen/bitfield_unit_raw_ref_macros.rs b/bindgen/codegen/bitfield_unit_raw_ref_macros.rs index a7cad6ca7b..0c864c7369 100644 --- a/bindgen/codegen/bitfield_unit_raw_ref_macros.rs +++ b/bindgen/codegen/bitfield_unit_raw_ref_macros.rs @@ -80,8 +80,10 @@ where debug_assert!(index / 8 < core::mem::size_of::()); let byte_index = index / 8; - let byte = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); + 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) }; } From 115d94a5bfedf542fc35a318e24d042c11d40551 Mon Sep 17 00:00:00 2001 From: Nik Konyuchenko Date: Sat, 8 Feb 2025 19:23:19 -0800 Subject: [PATCH 858/942] Fix missed tests Signed-off-by: Nik Konyuchenko --- .../tests/expectations/tests/bitfield-32bit-overflow.rs | 6 ++++-- bindgen-tests/tests/expectations/tests/bitfield-large.rs | 6 ++++-- bindgen-tests/tests/expectations/tests/bitfield-linux-32.rs | 6 ++++-- .../tests/expectations/tests/bitfield-method-same-name.rs | 6 ++++-- bindgen-tests/tests/expectations/tests/bitfield_align.rs | 6 ++++-- bindgen-tests/tests/expectations/tests/bitfield_align_2.rs | 6 ++++-- .../tests/expectations/tests/bitfield_method_mangling.rs | 6 ++++-- .../tests/expectations/tests/bitfield_pragma_packed.rs | 6 ++++-- .../tests/expectations/tests/default_visibility_crate.rs | 6 ++++-- .../tests/expectations/tests/default_visibility_private.rs | 6 ++++-- .../default_visibility_private_respects_cxx_access_spec.rs | 6 ++++-- .../tests/expectations/tests/derive-debug-bitfield-1-51.rs | 6 ++++-- .../expectations/tests/divide-by-zero-in-struct-layout.rs | 6 ++++-- .../tests/expectations/tests/field-visibility-callback.rs | 6 ++++-- bindgen-tests/tests/expectations/tests/field-visibility.rs | 6 ++++-- .../tests/expectations/tests/incomplete-array-padding.rs | 6 ++++-- bindgen-tests/tests/expectations/tests/issue-1034.rs | 6 ++++-- .../tests/issue-1076-unnamed-bitfield-alignment.rs | 6 ++++-- bindgen-tests/tests/expectations/tests/issue-1947.rs | 6 ++++-- .../expectations/tests/issue-739-pointer-wide-bitfield.rs | 6 ++++-- bindgen-tests/tests/expectations/tests/issue-816.rs | 6 ++++-- .../tests/expectations/tests/jsval_layout_opaque.rs | 6 ++++-- bindgen-tests/tests/expectations/tests/layout_align.rs | 6 ++++-- bindgen-tests/tests/expectations/tests/layout_mbuf.rs | 6 ++++-- bindgen-tests/tests/expectations/tests/only_bitfields.rs | 6 ++++-- bindgen-tests/tests/expectations/tests/packed-bitfield.rs | 6 ++++-- bindgen-tests/tests/expectations/tests/private_fields.rs | 6 ++++-- .../tests/expectations/tests/redundant-packed-and-align.rs | 6 ++++-- .../tests/expectations/tests/struct_with_bitfields.rs | 6 ++++-- bindgen-tests/tests/expectations/tests/timex.rs | 6 ++++-- bindgen-tests/tests/expectations/tests/union_bitfield.rs | 6 ++++-- .../expectations/tests/union_with_anon_struct_bitfield.rs | 6 ++++-- bindgen-tests/tests/expectations/tests/weird_bitfields.rs | 6 ++++-- 33 files changed, 132 insertions(+), 66 deletions(-) diff --git a/bindgen-tests/tests/expectations/tests/bitfield-32bit-overflow.rs b/bindgen-tests/tests/expectations/tests/bitfield-32bit-overflow.rs index d45c8ed92b..81ce12a5c9 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-32bit-overflow.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-32bit-overflow.rs @@ -62,8 +62,10 @@ where 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); + 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] diff --git a/bindgen-tests/tests/expectations/tests/bitfield-large.rs b/bindgen-tests/tests/expectations/tests/bitfield-large.rs index d32a689740..8024d88c3b 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-large.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-large.rs @@ -62,8 +62,10 @@ where 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); + 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] diff --git a/bindgen-tests/tests/expectations/tests/bitfield-linux-32.rs b/bindgen-tests/tests/expectations/tests/bitfield-linux-32.rs index 10935f5d12..8b0b37b481 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-linux-32.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-linux-32.rs @@ -62,8 +62,10 @@ where 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); + 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] diff --git a/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs b/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs index 6981d385f5..84e152f3fd 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs @@ -62,8 +62,10 @@ where 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); + 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] diff --git a/bindgen-tests/tests/expectations/tests/bitfield_align.rs b/bindgen-tests/tests/expectations/tests/bitfield_align.rs index 233da23a46..5f1321bbb1 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_align.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_align.rs @@ -62,8 +62,10 @@ where 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); + 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] diff --git a/bindgen-tests/tests/expectations/tests/bitfield_align_2.rs b/bindgen-tests/tests/expectations/tests/bitfield_align_2.rs index 303f7a5926..2a676d5636 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_align_2.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_align_2.rs @@ -63,8 +63,10 @@ where 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); + 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] diff --git a/bindgen-tests/tests/expectations/tests/bitfield_method_mangling.rs b/bindgen-tests/tests/expectations/tests/bitfield_method_mangling.rs index 50051ab03b..1a08cd00f9 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_method_mangling.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_method_mangling.rs @@ -62,8 +62,10 @@ where 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); + 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] diff --git a/bindgen-tests/tests/expectations/tests/bitfield_pragma_packed.rs b/bindgen-tests/tests/expectations/tests/bitfield_pragma_packed.rs index ea10bca1d3..8869593ed5 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_pragma_packed.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_pragma_packed.rs @@ -62,8 +62,10 @@ where 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); + 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] diff --git a/bindgen-tests/tests/expectations/tests/default_visibility_crate.rs b/bindgen-tests/tests/expectations/tests/default_visibility_crate.rs index c535cdb874..aeb6a717f6 100644 --- a/bindgen-tests/tests/expectations/tests/default_visibility_crate.rs +++ b/bindgen-tests/tests/expectations/tests/default_visibility_crate.rs @@ -62,8 +62,10 @@ where 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); + 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] diff --git a/bindgen-tests/tests/expectations/tests/default_visibility_private.rs b/bindgen-tests/tests/expectations/tests/default_visibility_private.rs index 7083e8231b..4ee26721b0 100644 --- a/bindgen-tests/tests/expectations/tests/default_visibility_private.rs +++ b/bindgen-tests/tests/expectations/tests/default_visibility_private.rs @@ -62,8 +62,10 @@ where 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); + 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] diff --git a/bindgen-tests/tests/expectations/tests/default_visibility_private_respects_cxx_access_spec.rs b/bindgen-tests/tests/expectations/tests/default_visibility_private_respects_cxx_access_spec.rs index 71ad6f9b12..e676f6470d 100644 --- a/bindgen-tests/tests/expectations/tests/default_visibility_private_respects_cxx_access_spec.rs +++ b/bindgen-tests/tests/expectations/tests/default_visibility_private_respects_cxx_access_spec.rs @@ -62,8 +62,10 @@ where 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); + 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] 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 01839b9f0b..351d3b31e5 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 @@ -62,8 +62,10 @@ where 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); + 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] diff --git a/bindgen-tests/tests/expectations/tests/divide-by-zero-in-struct-layout.rs b/bindgen-tests/tests/expectations/tests/divide-by-zero-in-struct-layout.rs index de5cf210e2..e01a9b3c72 100644 --- a/bindgen-tests/tests/expectations/tests/divide-by-zero-in-struct-layout.rs +++ b/bindgen-tests/tests/expectations/tests/divide-by-zero-in-struct-layout.rs @@ -62,8 +62,10 @@ where 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); + 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] diff --git a/bindgen-tests/tests/expectations/tests/field-visibility-callback.rs b/bindgen-tests/tests/expectations/tests/field-visibility-callback.rs index 9072cb15f5..aebc04f03b 100644 --- a/bindgen-tests/tests/expectations/tests/field-visibility-callback.rs +++ b/bindgen-tests/tests/expectations/tests/field-visibility-callback.rs @@ -62,8 +62,10 @@ where 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); + 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] diff --git a/bindgen-tests/tests/expectations/tests/field-visibility.rs b/bindgen-tests/tests/expectations/tests/field-visibility.rs index 9c56ca3f9e..3e43755a57 100644 --- a/bindgen-tests/tests/expectations/tests/field-visibility.rs +++ b/bindgen-tests/tests/expectations/tests/field-visibility.rs @@ -62,8 +62,10 @@ where 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); + 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] diff --git a/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs b/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs index 4f52511400..6e9f6e7753 100644 --- a/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs +++ b/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs @@ -62,8 +62,10 @@ where 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); + 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] diff --git a/bindgen-tests/tests/expectations/tests/issue-1034.rs b/bindgen-tests/tests/expectations/tests/issue-1034.rs index 8df55e7e49..1034520c48 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1034.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1034.rs @@ -62,8 +62,10 @@ where 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); + 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] diff --git a/bindgen-tests/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs b/bindgen-tests/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs index 2dc273ab01..3d14c81a77 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs @@ -62,8 +62,10 @@ where 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); + 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] diff --git a/bindgen-tests/tests/expectations/tests/issue-1947.rs b/bindgen-tests/tests/expectations/tests/issue-1947.rs index e03d764bb8..cceb42d8c5 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1947.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1947.rs @@ -62,8 +62,10 @@ where 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); + 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] diff --git a/bindgen-tests/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs b/bindgen-tests/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs index 9f68752dea..4e79cfdf71 100644 --- a/bindgen-tests/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs @@ -63,8 +63,10 @@ where 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); + 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] diff --git a/bindgen-tests/tests/expectations/tests/issue-816.rs b/bindgen-tests/tests/expectations/tests/issue-816.rs index f6c94f24ed..56e719238b 100644 --- a/bindgen-tests/tests/expectations/tests/issue-816.rs +++ b/bindgen-tests/tests/expectations/tests/issue-816.rs @@ -62,8 +62,10 @@ where 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); + 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] diff --git a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs index 6b05adbf12..7dd23241e9 100644 --- a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs +++ b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs @@ -62,8 +62,10 @@ where 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); + 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] diff --git a/bindgen-tests/tests/expectations/tests/layout_align.rs b/bindgen-tests/tests/expectations/tests/layout_align.rs index 858cfcdd23..18662d4c83 100644 --- a/bindgen-tests/tests/expectations/tests/layout_align.rs +++ b/bindgen-tests/tests/expectations/tests/layout_align.rs @@ -62,8 +62,10 @@ where 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); + 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] diff --git a/bindgen-tests/tests/expectations/tests/layout_mbuf.rs b/bindgen-tests/tests/expectations/tests/layout_mbuf.rs index 81093dab9d..cb3698812b 100644 --- a/bindgen-tests/tests/expectations/tests/layout_mbuf.rs +++ b/bindgen-tests/tests/expectations/tests/layout_mbuf.rs @@ -62,8 +62,10 @@ where 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); + 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] diff --git a/bindgen-tests/tests/expectations/tests/only_bitfields.rs b/bindgen-tests/tests/expectations/tests/only_bitfields.rs index fc668d74b0..3aedce1e3f 100644 --- a/bindgen-tests/tests/expectations/tests/only_bitfields.rs +++ b/bindgen-tests/tests/expectations/tests/only_bitfields.rs @@ -62,8 +62,10 @@ where 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); + 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] diff --git a/bindgen-tests/tests/expectations/tests/packed-bitfield.rs b/bindgen-tests/tests/expectations/tests/packed-bitfield.rs index 79f81979e2..4e3918f558 100644 --- a/bindgen-tests/tests/expectations/tests/packed-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/packed-bitfield.rs @@ -62,8 +62,10 @@ where 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); + 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] diff --git a/bindgen-tests/tests/expectations/tests/private_fields.rs b/bindgen-tests/tests/expectations/tests/private_fields.rs index a1051f6576..a5d9e84499 100644 --- a/bindgen-tests/tests/expectations/tests/private_fields.rs +++ b/bindgen-tests/tests/expectations/tests/private_fields.rs @@ -62,8 +62,10 @@ where 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); + 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] diff --git a/bindgen-tests/tests/expectations/tests/redundant-packed-and-align.rs b/bindgen-tests/tests/expectations/tests/redundant-packed-and-align.rs index aec3d47dd8..c01762ca98 100644 --- a/bindgen-tests/tests/expectations/tests/redundant-packed-and-align.rs +++ b/bindgen-tests/tests/expectations/tests/redundant-packed-and-align.rs @@ -62,8 +62,10 @@ where 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); + 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] diff --git a/bindgen-tests/tests/expectations/tests/struct_with_bitfields.rs b/bindgen-tests/tests/expectations/tests/struct_with_bitfields.rs index d904128f9e..23588ee7da 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_bitfields.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_bitfields.rs @@ -62,8 +62,10 @@ where 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); + 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] diff --git a/bindgen-tests/tests/expectations/tests/timex.rs b/bindgen-tests/tests/expectations/tests/timex.rs index 99817f3122..3d25971315 100644 --- a/bindgen-tests/tests/expectations/tests/timex.rs +++ b/bindgen-tests/tests/expectations/tests/timex.rs @@ -62,8 +62,10 @@ where 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); + 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] diff --git a/bindgen-tests/tests/expectations/tests/union_bitfield.rs b/bindgen-tests/tests/expectations/tests/union_bitfield.rs index dd3e2dde3c..70da5c3b02 100644 --- a/bindgen-tests/tests/expectations/tests/union_bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/union_bitfield.rs @@ -62,8 +62,10 @@ where 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); + 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] diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield.rs index 036eec3b7c..dd1a55e9b5 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield.rs @@ -62,8 +62,10 @@ where 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); + 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] diff --git a/bindgen-tests/tests/expectations/tests/weird_bitfields.rs b/bindgen-tests/tests/expectations/tests/weird_bitfields.rs index c5fabe6b67..17accb01d9 100644 --- a/bindgen-tests/tests/expectations/tests/weird_bitfields.rs +++ b/bindgen-tests/tests/expectations/tests/weird_bitfields.rs @@ -62,8 +62,10 @@ where 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 = (core::ptr::addr_of_mut!((*this).storage) as *mut u8) - .offset(byte_index as isize); + 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] From efd157fb468f20645480c12039c186ac688b5d8a Mon Sep 17 00:00:00 2001 From: Jonathan Schwender Date: Sat, 8 Feb 2025 13:14:41 +0100 Subject: [PATCH 859/942] Remove warning for opaque forward declarations Forward declarations never have a known layout, and the warning makes no sense in that case. --- bindgen/codegen/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index f58a234117..a899ac4de9 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -2315,7 +2315,9 @@ impl CodeGenerator for CompInfo { }); } None => { - warn!("Opaque type without layout! Expect dragons!"); + if !forward_decl { + warn!("Opaque type without layout! Expect dragons!"); + } } } } else if !is_union && !zero_sized { From 1be53c68b24e55724a57b6954f539cb59e5448ad Mon Sep 17 00:00:00 2001 From: Jonathan Schwender Date: Sat, 8 Feb 2025 11:40:00 +0100 Subject: [PATCH 860/942] Remove useless fallback Remove the line, since we already tried location.raw_comment() first. Originally the last `or_else` branch debug printed `location.raw_comment()`, but the print was removed in c94367c8e9607d3b6d5cf80f0c589971dca40f7c. --- bindgen/ir/item.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/bindgen/ir/item.rs b/bindgen/ir/item.rs index bb03917792..8b0d24cd04 100644 --- a/bindgen/ir/item.rs +++ b/bindgen/ir/item.rs @@ -1590,10 +1590,7 @@ impl Item { canonical_def.unwrap_or_else(|| ty.declaration()) }; - let comment = location - .raw_comment() - .or_else(|| decl.raw_comment()) - .or_else(|| location.raw_comment()); + let comment = location.raw_comment().or_else(|| decl.raw_comment()); let annotations = Annotations::new(&decl).or_else(|| Annotations::new(&location)); From 76920aa742739115bb998fa6be4349cdb9952135 Mon Sep 17 00:00:00 2001 From: John Baublitz Date: Wed, 8 Jan 2025 11:04:49 -0500 Subject: [PATCH 861/942] Fix bugs in --clang-macro-fallback This commit resolves a bug where -include was not respected and a bug where -MMD was passed to the fallback translation unit which would cause the dependency file to be overwritten with useless information about temporary files. --- bindgen/clang.rs | 4 --- bindgen/ir/context.rs | 76 +++++++++++++++--------------------------- bindgen/lib.rs | 12 +++++++ bindgen/options/mod.rs | 5 +++ 4 files changed, 44 insertions(+), 53 deletions(-) diff --git a/bindgen/clang.rs b/bindgen/clang.rs index 9afc6e93b1..04fe3e1538 100644 --- a/bindgen/clang.rs +++ b/bindgen/clang.rs @@ -1914,7 +1914,6 @@ impl Drop for TranslationUnit { /// Translation unit used for macro fallback parsing pub(crate) struct FallbackTranslationUnit { file_path: String, - header_path: String, pch_path: String, idx: Box, tu: TranslationUnit, @@ -1930,7 +1929,6 @@ impl FallbackTranslationUnit { /// Create a new fallback translation unit pub(crate) fn new( file: String, - header_path: String, pch_path: String, c_args: &[Box], ) -> Option { @@ -1952,7 +1950,6 @@ impl FallbackTranslationUnit { )?; Some(FallbackTranslationUnit { file_path: file, - header_path, pch_path, tu: f_translation_unit, idx: f_index, @@ -1991,7 +1988,6 @@ impl FallbackTranslationUnit { impl Drop for FallbackTranslationUnit { fn drop(&mut self) { let _ = std::fs::remove_file(&self.file_path); - let _ = std::fs::remove_file(&self.header_path); let _ = std::fs::remove_file(&self.pch_path); } } diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index c6bc9025ec..78790d61c4 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -29,8 +29,6 @@ use quote::ToTokens; use std::borrow::Cow; use std::cell::{Cell, RefCell}; use std::collections::{BTreeSet, HashMap as StdHashMap}; -use std::fs::OpenOptions; -use std::io::Write; use std::mem; use std::path::Path; @@ -2054,8 +2052,11 @@ If you encounter an error missing from this list, please file an issue or a PR!" let mut header_names_to_compile = Vec::new(); let mut header_paths = Vec::new(); - let mut header_contents = String::new(); - for input_header in &self.options.input_headers { + let mut header_includes = Vec::new(); + let single_header = self.options().input_headers.last().cloned()?; + for input_header in &self.options.input_headers + [..self.options.input_headers.len() - 1] + { let path = Path::new(input_header.as_ref()); if let Some(header_path) = path.parent() { if header_path == Path::new("") { @@ -2067,50 +2068,32 @@ If you encounter an error missing from this list, please file an issue or a PR!" header_paths.push("."); } let header_name = path.file_name()?.to_str()?; + header_includes.push(header_name.to_string()); header_names_to_compile .push(header_name.split(".h").next()?.to_string()); - header_contents += - format!("\n#include <{header_name}>").as_str(); } - let header_to_precompile = format!( + let pch = format!( "{}/{}", match self.options().clang_macro_fallback_build_dir { Some(ref path) => path.as_os_str().to_str()?, None => ".", }, - header_names_to_compile.join("-") + "-precompile.h" + header_names_to_compile.join("-") + "-precompile.h.pch" ); - let pch = header_to_precompile.clone() + ".pch"; - - let mut header_to_precompile_file = OpenOptions::new() - .create(true) - .truncate(true) - .write(true) - .open(&header_to_precompile) - .ok()?; - header_to_precompile_file - .write_all(header_contents.as_bytes()) - .ok()?; - - let mut c_args = Vec::new(); + + let mut c_args = self.options.fallback_clang_args.clone(); c_args.push("-x".to_string().into_boxed_str()); c_args.push("c-header".to_string().into_boxed_str()); for header_path in header_paths { c_args.push(format!("-I{header_path}").into_boxed_str()); } - c_args.extend( - self.options - .clang_args - .iter() - .filter(|next| { - !self.options.input_headers.contains(next) && - next.as_ref() != "-include" - }) - .cloned(), - ); + for header_include in header_includes { + c_args.push("-include".to_string().into_boxed_str()); + c_args.push(header_include.into_boxed_str()); + } let mut tu = clang::TranslationUnit::parse( &index, - &header_to_precompile, + &single_header, &c_args, &[], clang_sys::CXTranslationUnit_ForSerialization, @@ -2121,23 +2104,18 @@ If you encounter an error missing from this list, please file an issue or a PR!" "-include-pch".to_string().into_boxed_str(), pch.clone().into_boxed_str(), ]; - c_args.extend( - self.options - .clang_args - .clone() - .iter() - .filter(|next| { - !self.options.input_headers.contains(next) && - next.as_ref() != "-include" - }) - .cloned(), - ); - self.fallback_tu = Some(clang::FallbackTranslationUnit::new( - file, - header_to_precompile, - pch, - &c_args, - )?); + let mut skip_next = false; + for arg in self.options.fallback_clang_args.iter() { + if arg.as_ref() == "-include" { + skip_next = true; + } else if skip_next { + skip_next = false; + } else { + c_args.push(arg.clone()) + } + } + self.fallback_tu = + Some(clang::FallbackTranslationUnit::new(file, pch, &c_args)?); } self.fallback_tu.as_mut() diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 0a8f29d158..1a15d51d67 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -348,6 +348,18 @@ impl Builder { } // Transform input headers to arguments on the clang command line. + self.options.fallback_clang_args = self + .options + .clang_args + .iter() + .filter(|arg| { + !arg.starts_with("-MMD") && + !arg.starts_with("-MD") && + !arg.starts_with("--write-user-dependencies") && + !arg.starts_with("--user-dependencies") + }) + .cloned() + .collect::>(); self.options.clang_args.extend( self.options.input_headers [..self.options.input_headers.len().saturating_sub(1)] diff --git a/bindgen/options/mod.rs b/bindgen/options/mod.rs index 6bf652d4e1..9d1d195980 100644 --- a/bindgen/options/mod.rs +++ b/bindgen/options/mod.rs @@ -1234,6 +1234,11 @@ options! { // This field is handled specially inside the macro. as_args: ignore, }, + /// The set of arguments to be passed straight through to Clang for the macro fallback code. + fallback_clang_args: Vec> { + methods: {}, + as_args: ignore, + }, /// Tuples of unsaved file contents of the form (name, contents). input_header_contents: Vec<(Box, Box)> { methods: { From a10bcfd0dd1e23c0139355deb567d83bd4b8a013 Mon Sep 17 00:00:00 2001 From: Adrian Taylor Date: Sun, 16 Feb 2025 16:25:28 +0000 Subject: [PATCH 862/942] Distinguish char16_t. With a new command-line option, this ensures that char16_t is distinct from uint16_t in generated bindings. On some platforms these are distinct types, so it can be important for downstream post processors to spot the difference. See the documentation on the new command-line option for expected behavior and usage here. Part of https://github.com/google/autocxx/issues/124. --- .../tests/expectations/tests/char16_t.rs | 7 ++++++ bindgen-tests/tests/headers/char16_t.hpp | 4 ++++ bindgen/codegen/helpers.rs | 6 +++++ bindgen/ir/context.rs | 3 +++ bindgen/ir/int.rs | 9 +++++--- bindgen/options/cli.rs | 5 +++++ bindgen/options/mod.rs | 22 +++++++++++++++++++ 7 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 bindgen-tests/tests/expectations/tests/char16_t.rs create mode 100644 bindgen-tests/tests/headers/char16_t.hpp diff --git a/bindgen-tests/tests/expectations/tests/char16_t.rs b/bindgen-tests/tests/expectations/tests/char16_t.rs new file mode 100644 index 0000000000..82d30fe517 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/char16_t.rs @@ -0,0 +1,7 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[repr(transparent)] +pub struct bindgen_cchar16_t(u16); +unsafe extern "C" { + #[link_name = "\u{1}_Z16receive_char16_tDs"] + pub fn receive_char16_t(input: bindgen_cchar16_t); +} diff --git a/bindgen-tests/tests/headers/char16_t.hpp b/bindgen-tests/tests/headers/char16_t.hpp new file mode 100644 index 0000000000..35e1f16dd3 --- /dev/null +++ b/bindgen-tests/tests/headers/char16_t.hpp @@ -0,0 +1,4 @@ +// bindgen-flags: --use-distinct-char16-t --raw-line '#[repr(transparent)] pub struct bindgen_cchar16_t(u16);' -- -x c++ -std=c++14 + +void receive_char16_t(char16_t input) { +} diff --git a/bindgen/codegen/helpers.rs b/bindgen/codegen/helpers.rs index 7b09ed7cfb..70f0125931 100644 --- a/bindgen/codegen/helpers.rs +++ b/bindgen/codegen/helpers.rs @@ -187,6 +187,12 @@ pub(crate) mod ast_ty { match ik { IntKind::Bool => syn::parse_quote! { bool }, IntKind::Char { .. } => raw_type(ctx, "c_char"), + // The following is used only when an unusual command-line + // argument is used. bindgen_cchar16_t is not a real type; + // but this allows downstream postprocessors to distinguish + // this case and do something special for C++ bindings + // containing char16_t. + IntKind::Char16 => syn::parse_quote! { bindgen_cchar16_t }, IntKind::SChar => raw_type(ctx, "c_schar"), IntKind::UChar => raw_type(ctx, "c_uchar"), IntKind::Short => raw_type(ctx, "c_short"), diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index 78790d61c4..99c75d63d8 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -1980,6 +1980,9 @@ If you encounter an error missing from this list, please file an issue or a PR!" CXType_Short => TypeKind::Int(IntKind::Short), CXType_UShort => TypeKind::Int(IntKind::UShort), CXType_WChar => TypeKind::Int(IntKind::WChar), + CXType_Char16 if self.options().use_distinct_char16_t => { + TypeKind::Int(IntKind::Char16) + } CXType_Char16 => TypeKind::Int(IntKind::U16), CXType_Char32 => TypeKind::Int(IntKind::U32), CXType_Long => TypeKind::Int(IntKind::Long), diff --git a/bindgen/ir/int.rs b/bindgen/ir/int.rs index 4b49931ed8..4caa6b2d06 100644 --- a/bindgen/ir/int.rs +++ b/bindgen/ir/int.rs @@ -54,9 +54,12 @@ pub enum IntKind { /// A 16-bit signed integer. I16, - /// Either a `char16_t` or a `wchar_t`. + /// A 16-bit integer, used only for enum size representation. U16, + /// Either a `char16_t` or a `wchar_t`. + Char16, + /// A 32-bit signed integer. I32, @@ -94,7 +97,7 @@ impl IntKind { // to know whether it is or not right now (unlike char, there's no // WChar_S / WChar_U). Bool | UChar | UShort | UInt | ULong | ULongLong | U8 | U16 | - WChar | U32 | U64 | U128 => false, + Char16 | WChar | U32 | U64 | U128 => false, SChar | Short | Int | Long | LongLong | I8 | I16 | I32 | I64 | I128 => true, @@ -110,7 +113,7 @@ impl IntKind { use self::IntKind::*; Some(match *self { Bool | UChar | SChar | U8 | I8 | Char { .. } => 1, - U16 | I16 => 2, + U16 | I16 | Char16 => 2, U32 | I32 => 4, U64 | I64 => 8, I128 | U128 => 16, diff --git a/bindgen/options/cli.rs b/bindgen/options/cli.rs index 8c4c05bc84..1efddb02f3 100644 --- a/bindgen/options/cli.rs +++ b/bindgen/options/cli.rs @@ -441,6 +441,9 @@ struct BindgenCommand { /// Always output explicit padding fields. #[arg(long)] explicit_padding: bool, + /// Use distinct char16_t + #[arg(long)] + use_distinct_char16_t: bool, /// Enables generation of vtable functions. #[arg(long)] vtable_generation: bool, @@ -629,6 +632,7 @@ where translate_enum_integer_types, c_naming, explicit_padding, + use_distinct_char16_t, vtable_generation, sort_semantically, merge_extern_blocks, @@ -926,6 +930,7 @@ where translate_enum_integer_types, c_naming, explicit_padding, + use_distinct_char16_t, vtable_generation, sort_semantically, merge_extern_blocks, diff --git a/bindgen/options/mod.rs b/bindgen/options/mod.rs index 9d1d195980..1a675401a4 100644 --- a/bindgen/options/mod.rs +++ b/bindgen/options/mod.rs @@ -153,6 +153,28 @@ macro_rules! options { } options! { + /// Whether we should distinguish between 'char16_t' and 'u16'. + /// As standard, bindgen represents `char16_t` as `u16`. + /// Rust does not have a `std::os::raw::c_char16_t` type, and thus + /// we can't use a built-in Rust type in the generated bindings. + /// But for some uses of bindgen, especially when downstream + /// post-processing occurs, it's important to distinguish `char16_t` + /// from normal `uint16_t`. When this option is enabled, bindgen + /// generates a fake type called `bindgen_cchar16_t`. Downstream + /// code post-processors should arrange to replace this with a + /// real type. + use_distinct_char16_t: bool { + methods: { + /// If this is true, denote 'char16_t' as a separate type from 'u16' + /// Disabled by default. + pub fn use_distinct_char16_t(mut self, doit: bool) -> Builder { + self.options.use_distinct_char16_t = doit; + self + } + }, + as_args: "--use-distinct-char16-t", + }, + /// Types that have been blocklisted and should not appear anywhere in the generated code. blocklisted_types: RegexSet { methods: { From 58805949e12abaa00c0ddc1f6587bbd371a35a9e Mon Sep 17 00:00:00 2001 From: Adrian Taylor Date: Sun, 16 Feb 2025 15:57:46 +0000 Subject: [PATCH 863/942] Report enums in ParseCallbacks. ParseCallbacks previously reported structs but not enums. Enhance it to do so. At the moment, little information is provided about enums - but bindgen doesn't handle (rare) anonymous enums so this seems the right amount of information to report. At the moment, effectively this just provides a mapping between name and DiscoveredItemId. One of a number of PRs I'll be raising for https://github.com/google/autocxx/issues/124. In future PRs I'll be hoping to add further callbacks which report more information based on DiscoveredItemId, so having the DiscoveredItemId for each enum is an important pre-requisite. --- .../header_item_discovery.h | 16 +++++++- .../item_discovery_callback/mod.rs | 40 +++++++++++++++++++ bindgen/callbacks.rs | 9 ++++- bindgen/codegen/mod.rs | 9 +++++ 4 files changed, 71 insertions(+), 3 deletions(-) diff --git a/bindgen-tests/tests/parse_callbacks/item_discovery_callback/header_item_discovery.h b/bindgen-tests/tests/parse_callbacks/item_discovery_callback/header_item_discovery.h index 10e97ea480..b2bb04f15f 100644 --- a/bindgen-tests/tests/parse_callbacks/item_discovery_callback/header_item_discovery.h +++ b/bindgen-tests/tests/parse_callbacks/item_discovery_callback/header_item_discovery.h @@ -1,4 +1,4 @@ -// Unions +// Structs void function_using_anonymous_struct(struct {} arg0); struct NamedStruct { @@ -13,4 +13,16 @@ void function_using_anonymous_union(union {} arg0); union NamedUnion { }; -typedef union NamedUnion AliasOfNamedUnion; \ No newline at end of file +typedef union NamedUnion AliasOfNamedUnion; + +// Enums + +// We don't include an anonymous enum because such enums +// are not visible outside the function, and thus tend not +// to be useful - bindgen doesn't handle them for this reason. + +enum NamedEnum { + Fish, +}; + +typedef enum NamedEnum AliasOfNamedEnum; \ No newline at end of file diff --git a/bindgen-tests/tests/parse_callbacks/item_discovery_callback/mod.rs b/bindgen-tests/tests/parse_callbacks/item_discovery_callback/mod.rs index 74af110d00..93a2b029d7 100644 --- a/bindgen-tests/tests/parse_callbacks/item_discovery_callback/mod.rs +++ b/bindgen-tests/tests/parse_callbacks/item_discovery_callback/mod.rs @@ -60,6 +60,19 @@ pub fn test_item_discovery_callback() { alias_for: DiscoveredItemId::new(20), }, ), + ( + DiscoveredItemId::new(27), + DiscoveredItem::Alias { + alias_name: "AliasOfNamedEnum".to_string(), + alias_for: DiscoveredItemId::new(24), + }, + ), + ( + DiscoveredItemId::new(24), + DiscoveredItem::Enum { + final_name: "NamedEnum".to_string(), + }, + ), ( DiscoveredItemId::new(30), DiscoveredItem::Struct { @@ -126,6 +139,9 @@ fn compare_item_info( expected, generated, ), + DiscoveredItem::Enum { .. } => { + compare_enum_info(expected_item, generated_item) + } } } @@ -203,6 +219,30 @@ pub fn compare_union_info( } } +pub fn compare_enum_info( + expected_item: &DiscoveredItem, + generated_item: &DiscoveredItem, +) -> bool { + let DiscoveredItem::Enum { + final_name: expected_final_name, + } = expected_item + else { + unreachable!() + }; + + let DiscoveredItem::Enum { + final_name: generated_final_name, + } = generated_item + else { + unreachable!() + }; + + if !compare_names(expected_final_name, generated_final_name) { + return false; + } + true +} + pub fn compare_alias_info( expected_item: &DiscoveredItem, generated_item: &DiscoveredItem, diff --git a/bindgen/callbacks.rs b/bindgen/callbacks.rs index 8a21e98dea..c2be66828a 100644 --- a/bindgen/callbacks.rs +++ b/bindgen/callbacks.rs @@ -217,7 +217,14 @@ pub enum DiscoveredItem { /// The identifier of the discovered type alias_for: DiscoveredItemId, - }, // functions, modules, etc. + }, + + /// Represents an enum. + Enum { + /// The final name of the generated binding + final_name: String, + }, + // functions, modules, etc. } /// Relevant information about a type to which new derive attributes will be added using diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index a899ac4de9..f5518e432d 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -3770,6 +3770,15 @@ impl CodeGenerator for Enum { let repr = repr.to_rust_ty_or_opaque(ctx, item); let has_typedef = ctx.is_enum_typedef_combo(item.id()); + ctx.options().for_each_callback(|cb| { + cb.new_item_found( + DiscoveredItemId::new(item.id().as_usize()), + DiscoveredItem::Enum { + final_name: name.to_string(), + }, + ); + }); + let mut builder = EnumBuilder::new(&name, attrs, &repr, variation, has_typedef); From 61603fcd6a738b1a0130eec036eba53993fec9b3 Mon Sep 17 00:00:00 2001 From: Adrian Taylor Date: Sun, 16 Feb 2025 16:11:12 +0000 Subject: [PATCH 864/942] Add extra tests. These files aspects of bindgen behavior which may not be generally useful to most consumers but are more important to downstream postprocessors such as autocxx. One of them tests enums embedded within classes, and the other tests various types of C++ constructor. Part of https://github.com/google/autocxx/issues/124. --- .../expectations/tests/class_with_enum.rs | 14 +++++ .../expectations/tests/special-members.rs | 51 +++++++++++++++++++ .../tests/headers/class_with_enum.hpp | 7 +++ .../tests/headers/special-members.hpp | 7 +++ 4 files changed, 79 insertions(+) create mode 100644 bindgen-tests/tests/expectations/tests/class_with_enum.rs create mode 100644 bindgen-tests/tests/expectations/tests/special-members.rs create mode 100644 bindgen-tests/tests/headers/class_with_enum.hpp create mode 100644 bindgen-tests/tests/headers/special-members.hpp diff --git a/bindgen-tests/tests/expectations/tests/class_with_enum.rs b/bindgen-tests/tests/expectations/tests/class_with_enum.rs new file mode 100644 index 0000000000..ca1806357c --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/class_with_enum.rs @@ -0,0 +1,14 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct A { + pub _address: u8, +} +pub const A_B_B1: A_B = 0; +pub const A_B_B2: A_B = 1; +pub type A_B = ::std::os::raw::c_uint; +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of A"][::std::mem::size_of::() - 1usize]; + ["Alignment of A"][::std::mem::align_of::() - 1usize]; +}; diff --git a/bindgen-tests/tests/expectations/tests/special-members.rs b/bindgen-tests/tests/expectations/tests/special-members.rs new file mode 100644 index 0000000000..4f54670c86 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/special-members.rs @@ -0,0 +1,51 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[repr(C)] +#[derive(Debug, Default)] +pub struct A { + pub _address: u8, +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of A"][::std::mem::size_of::() - 1usize]; + ["Alignment of A"][::std::mem::align_of::() - 1usize]; +}; +unsafe extern "C" { + #[link_name = "\u{1}_ZN1AC1Ev"] + pub fn A_A(this: *mut A); +} +unsafe extern "C" { + #[link_name = "\u{1}_ZN1AC1ERS_"] + pub fn A_A1(this: *mut A, arg1: *mut A); +} +unsafe extern "C" { + #[link_name = "\u{1}_ZN1AC1EOS_"] + pub fn A_A2(this: *mut A, arg1: *mut A); +} +unsafe extern "C" { + #[link_name = "\u{1}_ZN1AD1Ev"] + pub fn A_A_destructor(this: *mut A); +} +impl A { + #[inline] + pub unsafe fn new() -> Self { + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + A_A(__bindgen_tmp.as_mut_ptr()); + __bindgen_tmp.assume_init() + } + #[inline] + pub unsafe fn new1(arg1: *mut A) -> Self { + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + A_A1(__bindgen_tmp.as_mut_ptr(), arg1); + __bindgen_tmp.assume_init() + } + #[inline] + pub unsafe fn new2(arg1: *mut A) -> Self { + let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit(); + A_A2(__bindgen_tmp.as_mut_ptr(), arg1); + __bindgen_tmp.assume_init() + } + #[inline] + pub unsafe fn destruct(&mut self) { + A_A_destructor(self) + } +} diff --git a/bindgen-tests/tests/headers/class_with_enum.hpp b/bindgen-tests/tests/headers/class_with_enum.hpp new file mode 100644 index 0000000000..ebbc2c4049 --- /dev/null +++ b/bindgen-tests/tests/headers/class_with_enum.hpp @@ -0,0 +1,7 @@ +class A { +public: + enum B { + B1, + B2, + }; +}; \ No newline at end of file diff --git a/bindgen-tests/tests/headers/special-members.hpp b/bindgen-tests/tests/headers/special-members.hpp new file mode 100644 index 0000000000..753b2fdc0a --- /dev/null +++ b/bindgen-tests/tests/headers/special-members.hpp @@ -0,0 +1,7 @@ +class A { +public: + A(); + A(A&); + A(A&&); + ~A(); +}; \ No newline at end of file From 0df4256db456275d5bd3e2885541fc3d9e983120 Mon Sep 17 00:00:00 2001 From: Adrian Taylor Date: Wed, 19 Feb 2025 14:04:10 +0000 Subject: [PATCH 865/942] Improve comments and docs relating to char16_t. Part of https://github.com/google/autocxx/issues/124 --- bindgen/codegen/helpers.rs | 2 +- bindgen/ir/int.rs | 2 +- bindgen/options/mod.rs | 9 ++++++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/bindgen/codegen/helpers.rs b/bindgen/codegen/helpers.rs index 70f0125931..82172f3488 100644 --- a/bindgen/codegen/helpers.rs +++ b/bindgen/codegen/helpers.rs @@ -191,7 +191,7 @@ pub(crate) mod ast_ty { // argument is used. bindgen_cchar16_t is not a real type; // but this allows downstream postprocessors to distinguish // this case and do something special for C++ bindings - // containing char16_t. + // containing the C++ type char16_t. IntKind::Char16 => syn::parse_quote! { bindgen_cchar16_t }, IntKind::SChar => raw_type(ctx, "c_schar"), IntKind::UChar => raw_type(ctx, "c_uchar"), diff --git a/bindgen/ir/int.rs b/bindgen/ir/int.rs index 4caa6b2d06..ed18a99949 100644 --- a/bindgen/ir/int.rs +++ b/bindgen/ir/int.rs @@ -57,7 +57,7 @@ pub enum IntKind { /// A 16-bit integer, used only for enum size representation. U16, - /// Either a `char16_t` or a `wchar_t`. + /// The C++ type `char16_t`, which is its own type (unlike in C). Char16, /// A 32-bit signed integer. diff --git a/bindgen/options/mod.rs b/bindgen/options/mod.rs index 1a675401a4..74dd5c0b1d 100644 --- a/bindgen/options/mod.rs +++ b/bindgen/options/mod.rs @@ -153,10 +153,13 @@ macro_rules! options { } options! { - /// Whether we should distinguish between 'char16_t' and 'u16'. - /// As standard, bindgen represents `char16_t` as `u16`. + /// Whether we should distinguish between C++'s 'char16_t' and 'u16'. + /// The C++ type `char16_t` is its own special type; it's not a typedef + /// of some other integer (this differs from C). + /// As standard, bindgen represents C++ `char16_t` as `u16`. /// Rust does not have a `std::os::raw::c_char16_t` type, and thus - /// we can't use a built-in Rust type in the generated bindings. + /// we can't use a built-in Rust type in the generated bindings (and + /// nor would it be appropriate as it's a C++-specific type.) /// But for some uses of bindgen, especially when downstream /// post-processing occurs, it's important to distinguish `char16_t` /// from normal `uint16_t`. When this option is enabled, bindgen From 20aa65a0b9edfd5f8ab3e038197da5cb2c52ff18 Mon Sep 17 00:00:00 2001 From: Adrian Taylor Date: Wed, 19 Feb 2025 14:16:05 +0000 Subject: [PATCH 866/942] Provide option to get real virtual fn receiver. For virtual functions, bindgen has traditionally emitted a void* pointer because that's the least bad option for Rust code directly consuming the bindings. For downstream postprocessors and code generators, this throws away useful information about the actual type of the receiver. Provide a command-line option to put that back. Part of https://github.com/google/autocxx/issues/124 --- .../expectations/tests/specific_receiver.rs | 28 +++++++++++++++++++ .../tests/headers/specific_receiver.hpp | 7 +++++ bindgen/ir/function.rs | 5 +++- bindgen/options/cli.rs | 5 ++++ bindgen/options/mod.rs | 15 ++++++++++ 5 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 bindgen-tests/tests/expectations/tests/specific_receiver.rs create mode 100644 bindgen-tests/tests/headers/specific_receiver.hpp diff --git a/bindgen-tests/tests/expectations/tests/specific_receiver.rs b/bindgen-tests/tests/expectations/tests/specific_receiver.rs new file mode 100644 index 0000000000..ec001b12ad --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/specific_receiver.rs @@ -0,0 +1,28 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[repr(C)] +pub struct Fish__bindgen_vtable { + pub Fish_swim: unsafe extern "C" fn(this: *mut Fish), +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct Fish { + pub vtable_: *const Fish__bindgen_vtable, +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Fish"][::std::mem::size_of::() - 8usize]; + ["Alignment of Fish"][::std::mem::align_of::() - 8usize]; +}; +impl Default for Fish { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +unsafe extern "C" { + #[link_name = "\u{1}_ZN4Fish4swimEv"] + pub fn Fish_swim(this: *mut Fish); +} diff --git a/bindgen-tests/tests/headers/specific_receiver.hpp b/bindgen-tests/tests/headers/specific_receiver.hpp new file mode 100644 index 0000000000..a521f9f0b2 --- /dev/null +++ b/bindgen-tests/tests/headers/specific_receiver.hpp @@ -0,0 +1,7 @@ +// bindgen-flags: --use-specific-virtual-function-receiver --generate-inline-functions -- -x c++ -std=c++14 + +class Fish { +public: + virtual void swim() { + } +}; diff --git a/bindgen/ir/function.rs b/bindgen/ir/function.rs index 83b748a5f4..52fc94d974 100644 --- a/bindgen/ir/function.rs +++ b/bindgen/ir/function.rs @@ -533,7 +533,10 @@ impl FunctionSig { let is_const = is_method && cursor.method_is_const(); let is_virtual = is_method && cursor.method_is_virtual(); let is_static = is_method && cursor.method_is_static(); - if !is_static && !is_virtual { + if !is_static && + (!is_virtual || + ctx.options().use_specific_virtual_function_receiver) + { let parent = cursor.semantic_parent(); let class = Item::parse(parent, None, ctx) .expect("Expected to parse the class"); diff --git a/bindgen/options/cli.rs b/bindgen/options/cli.rs index 1efddb02f3..f9a8572976 100644 --- a/bindgen/options/cli.rs +++ b/bindgen/options/cli.rs @@ -441,6 +441,9 @@ struct BindgenCommand { /// Always output explicit padding fields. #[arg(long)] explicit_padding: bool, + /// Always be specific about the 'receiver' of a virtual function. + #[arg(long)] + use_specific_virtual_function_receiver: bool, /// Use distinct char16_t #[arg(long)] use_distinct_char16_t: bool, @@ -632,6 +635,7 @@ where translate_enum_integer_types, c_naming, explicit_padding, + use_specific_virtual_function_receiver, use_distinct_char16_t, vtable_generation, sort_semantically, @@ -930,6 +934,7 @@ where translate_enum_integer_types, c_naming, explicit_padding, + use_specific_virtual_function_receiver, use_distinct_char16_t, vtable_generation, sort_semantically, diff --git a/bindgen/options/mod.rs b/bindgen/options/mod.rs index 74dd5c0b1d..ab6b232ec3 100644 --- a/bindgen/options/mod.rs +++ b/bindgen/options/mod.rs @@ -153,6 +153,21 @@ macro_rules! options { } options! { + /// Whether to specify the type of a virtual function receiver + use_specific_virtual_function_receiver: bool { + methods: { + /// Normally, virtual functions have void* as their 'this' type. + /// If this flag is enabled, override that behavior to indicate a + /// pointer of the specific type. + /// Disabled by default. + pub fn use_specific_virtual_function_receiver(mut self, doit: bool) -> Builder { + self.options.use_specific_virtual_function_receiver = doit; + self + } + }, + as_args: "--use-specific-virtual-function-receiver", + }, + /// Whether we should distinguish between C++'s 'char16_t' and 'u16'. /// The C++ type `char16_t` is its own special type; it's not a typedef /// of some other integer (this differs from C). From 8159966cd92fed2b48ed5102ae98db751387d1f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Fri, 4 Apr 2025 16:04:22 +0200 Subject: [PATCH 867/942] Disable rust-for-linux test temporarily. --- .github/workflows/bindgen.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index df17f2c579..d0112e367f 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -171,7 +171,7 @@ jobs: BINDGEN_FEATURE_RUNTIME: ${{matrix.feature_runtime}} BINDGEN_FEATURE_EXTRA_ASSERTS: ${{matrix.feature_extra_asserts}} BINDGEN_NO_DEFAULT_FEATURES: ${{matrix.no_default_features}} - BINDGEN_RUST_FOR_LINUX_TEST: ${{matrix.os == 'ubuntu-latest' && matrix.llvm_version == '16.0' && matrix.feature_extra_asserts == 0 && 1 || 0}} + BINDGEN_RUST_FOR_LINUX_TEST: 0 run: ./ci/test.sh check-cfg: From bf919872215e13274009f86f7b43cc12fda050e0 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Thu, 20 Feb 2025 21:54:34 -0500 Subject: [PATCH 868/942] Mark all format-like macros for Clippy See https://doc.rust-lang.org/nightly/clippy/attribs.html#clippyformat_args --- bindgen/log_stubs.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bindgen/log_stubs.rs b/bindgen/log_stubs.rs index 8315983128..51d2f81fd1 100644 --- a/bindgen/log_stubs.rs +++ b/bindgen/log_stubs.rs @@ -1,5 +1,6 @@ #![allow(unused)] +#[clippy::format_args] macro_rules! log { (target: $target:expr, $lvl:expr, $($arg:tt)+) => {{ let _ = $target; @@ -10,22 +11,27 @@ macro_rules! log { let _ = format_args!($($arg)+); }}; } +#[clippy::format_args] macro_rules! error { (target: $target:expr, $($arg:tt)+) => { log!(target: $target, "", $($arg)+) }; ($($arg:tt)+) => { log!("", $($arg)+) }; } +#[clippy::format_args] macro_rules! warn { (target: $target:expr, $($arg:tt)*) => { log!(target: $target, "", $($arg)*) }; ($($arg:tt)*) => { log!("", $($arg)*) }; } +#[clippy::format_args] macro_rules! info { (target: $target:expr, $($arg:tt)+) => { log!(target: $target, "", $($arg)+) }; ($($arg:tt)+) => { log!("", $($arg)+) }; } +#[clippy::format_args] macro_rules! debug { (target: $target:expr, $($arg:tt)+) => { log!(target: $target, "", $($arg)+) }; ($($arg:tt)+) => { log!("", $($arg)+) }; } +#[clippy::format_args] macro_rules! trace { (target: $target:expr, $($arg:tt)+) => { log!(target: $target, "", $($arg)+) }; ($($arg:tt)+) => { log!("", $($arg)+) }; From e16a8ded58736cba5187480492859be5a9575be7 Mon Sep 17 00:00:00 2001 From: Adrian Taylor Date: Wed, 19 Feb 2025 14:47:14 +0000 Subject: [PATCH 869/942] Options to generate uncallable C++ functions. Downstream code generators may need to know about the existence of certain C++ functions even if those functions can't be called. This is counterintuitive but: * A type can't even be allocated if it contains pure virtual functions or if its constructor is private. * A type may not be relocatable if it contains a deleted move constructor. This PR provides command line options to reveal the existence of these functions. Subsequent PRs will announce their special status using the ParseCallbacks mechanism. Part of https://github.com/google/autocxx/issues/124. --- .../tests/uncallable_functions.rs | 46 ++++++++++++++++ .../tests/headers/uncallable_functions.hpp | 9 ++++ bindgen/codegen/mod.rs | 20 ++++--- bindgen/ir/function.rs | 5 +- bindgen/options/cli.rs | 18 +++++++ bindgen/options/mod.rs | 54 +++++++++++++++++++ 6 files changed, 142 insertions(+), 10 deletions(-) create mode 100644 bindgen-tests/tests/expectations/tests/uncallable_functions.rs create mode 100644 bindgen-tests/tests/headers/uncallable_functions.hpp diff --git a/bindgen-tests/tests/expectations/tests/uncallable_functions.rs b/bindgen-tests/tests/expectations/tests/uncallable_functions.rs new file mode 100644 index 0000000000..fddb5d41fc --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/uncallable_functions.rs @@ -0,0 +1,46 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[repr(C)] +pub struct Test__bindgen_vtable { + pub Test_a: unsafe extern "C" fn(this: *mut Test), +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct Test { + pub vtable_: *const Test__bindgen_vtable, +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Test"][::std::mem::size_of::() - 8usize]; + ["Alignment of Test"][::std::mem::align_of::() - 8usize]; +}; +unsafe extern "C" { + #[link_name = "\u{1}_ZN4Test1bEv"] + pub fn Test_b(this: *mut Test); +} +unsafe extern "C" { + #[link_name = "\u{1}_ZN4Test1cEv"] + pub fn Test_c(this: *mut Test); +} +impl Default for Test { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +impl Test { + #[inline] + pub unsafe fn b(&mut self) { + Test_b(self) + } + #[inline] + pub unsafe fn c(&mut self) { + Test_c(self) + } +} +unsafe extern "C" { + #[link_name = "\u{1}_ZN4Test1aEv"] + pub fn Test_a(this: *mut ::std::os::raw::c_void); +} diff --git a/bindgen-tests/tests/headers/uncallable_functions.hpp b/bindgen-tests/tests/headers/uncallable_functions.hpp new file mode 100644 index 0000000000..9187470c65 --- /dev/null +++ b/bindgen-tests/tests/headers/uncallable_functions.hpp @@ -0,0 +1,9 @@ +// bindgen-flags: --generate-deleted-functions --generate-private-functions --generate-pure-virtual-functions --generate-inline-functions -- -x c++ -std=c++14 + +class Test { +public: + virtual void a() = 0; + void b() = delete; +private: + void c() {} +}; diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index f5518e432d..8c623ff952 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -4564,14 +4564,20 @@ impl CodeGenerator for Function { } } - // Pure virtual methods have no actual symbol, so we can't generate - // something meaningful for them. - let is_dynamic_function = match self.kind() { - FunctionKind::Method(ref method_kind) - if method_kind.is_pure_virtual() => - { - return None; + let is_pure_virtual = match self.kind() { + FunctionKind::Method(ref method_kind) => { + method_kind.is_pure_virtual() } + _ => false, + }; + if is_pure_virtual && !ctx.options().generate_pure_virtual_functions { + // Pure virtual methods have no actual symbol, so we can't generate + // something meaningful for them. Downstream code postprocessors + // might want to find out about them. + return None; + } + + let is_dynamic_function = match self.kind() { FunctionKind::Function => { ctx.options().dynamic_library_name.is_some() } diff --git a/bindgen/ir/function.rs b/bindgen/ir/function.rs index 52fc94d974..2e741609f1 100644 --- a/bindgen/ir/function.rs +++ b/bindgen/ir/function.rs @@ -734,8 +734,7 @@ impl ClangSubItemParser for Function { if visibility != CXVisibility_Default { return Err(ParseError::Continue); } - - if cursor.access_specifier() == CX_CXXPrivate { + if cursor.access_specifier() == CX_CXXPrivate && !context.options().generate_private_functions { return Err(ParseError::Continue); } @@ -755,7 +754,7 @@ impl ClangSubItemParser for Function { return Err(ParseError::Continue); } - if cursor.is_deleted_function() { + if cursor.is_deleted_function() && !context.options().generate_deleted_functions { return Err(ParseError::Continue); } diff --git a/bindgen/options/cli.rs b/bindgen/options/cli.rs index f9a8572976..170df4f707 100644 --- a/bindgen/options/cli.rs +++ b/bindgen/options/cli.rs @@ -510,6 +510,18 @@ struct BindgenCommand { /// bitfields. This flag is ignored if the `--respect-cxx-access-specs` flag is used. #[arg(long, value_name = "VISIBILITY")] default_visibility: Option, + /// Whether to generate C++ functions marked with "=delete" even though they + /// can't be called. + #[arg(long)] + generate_deleted_functions: bool, + /// Whether to generate C++ "pure virtual" functions even though they can't + /// be called. + #[arg(long)] + generate_pure_virtual_functions: bool, + /// Whether to generate C++ private functions even though they can't + /// be called. + #[arg(long)] + generate_private_functions: bool, /// Whether to emit diagnostics or not. #[cfg(feature = "experimental")] #[arg(long, requires = "experimental")] @@ -657,6 +669,9 @@ where wrap_static_fns_path, wrap_static_fns_suffix, default_visibility, + generate_deleted_functions, + generate_pure_virtual_functions, + generate_private_functions, #[cfg(feature = "experimental")] emit_diagnostics, generate_shell_completions, @@ -948,6 +963,9 @@ where wrap_static_fns_path, wrap_static_fns_suffix, default_visibility, + generate_deleted_functions, + generate_pure_virtual_functions, + generate_private_functions, } ); diff --git a/bindgen/options/mod.rs b/bindgen/options/mod.rs index ab6b232ec3..7824f5d188 100644 --- a/bindgen/options/mod.rs +++ b/bindgen/options/mod.rs @@ -2211,4 +2211,58 @@ options! { }, as_args: "--clang-macro-fallback-build-dir", } + /// Whether to always report C++ "deleted" functions. + generate_deleted_functions: bool { + methods: { + /// Set whether to generate C++ functions even marked "=deleted" + /// + /// Although not useful to call these functions, downstream code + /// generators may need to know whether they've been deleted in + /// order to determine the relocatability of a C++ type + /// (specifically by virtue of which constructors exist.) + pub fn generate_deleted_functions(mut self, doit: bool) -> Self { + self.options.generate_deleted_functions = doit; + self + } + + }, + as_args: "--generate-deleted-functions", + }, + /// Whether to always report C++ "pure virtual" functions. + generate_pure_virtual_functions: bool { + methods: { + /// Set whether to generate C++ functions that are pure virtual. + /// + /// These functions can't be called, so the only reason + /// to generate them is if downstream postprocessors + /// need to know of their existence. This is necessary, + /// for instance, to determine whether a type itself is + /// pure virtual and thus can't be allocated. + /// Downstream code generators may choose to make code to + /// allow types to be allocated but need to avoid doing so + /// if the type contains pure virtual functions. + pub fn generate_pure_virtual_functions(mut self, doit: bool) -> Self { + self.options.generate_pure_virtual_functions = doit; + self + } + + }, + as_args: "--generate-pure-virtual-functions", + }, + /// Whether to always report C++ "private" functions. + generate_private_functions: bool { + methods: { + /// Set whether to generate C++ functions that are private. + /// + /// These functions can't be called, so the only reason + /// to generate them is if downstream postprocessors + /// need to know of their existence. + pub fn generate_private_functions(mut self, doit: bool) -> Self { + self.options.generate_private_functions = doit; + self + } + + }, + as_args: "--generate-private-functions", + }, } From bd513fac0cb8303d0e06602e7cebd3bce0ba6d8b Mon Sep 17 00:00:00 2001 From: Adrian Taylor Date: Wed, 19 Feb 2025 15:22:30 +0000 Subject: [PATCH 870/942] Formatting fixes. --- bindgen/ir/function.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bindgen/ir/function.rs b/bindgen/ir/function.rs index 2e741609f1..8331f25632 100644 --- a/bindgen/ir/function.rs +++ b/bindgen/ir/function.rs @@ -734,7 +734,8 @@ impl ClangSubItemParser for Function { if visibility != CXVisibility_Default { return Err(ParseError::Continue); } - if cursor.access_specifier() == CX_CXXPrivate && !context.options().generate_private_functions { + if cursor.access_specifier() == CX_CXXPrivate && + !context.options().generate_private_functions { return Err(ParseError::Continue); } @@ -754,7 +755,8 @@ impl ClangSubItemParser for Function { return Err(ParseError::Continue); } - if cursor.is_deleted_function() && !context.options().generate_deleted_functions { + if cursor.is_deleted_function() && + !context.options().generate_deleted_functions { return Err(ParseError::Continue); } From 0f2c9f226d38e22f917bf23257df044c6c415b7b Mon Sep 17 00:00:00 2001 From: Adrian Taylor Date: Wed, 19 Feb 2025 15:52:39 +0000 Subject: [PATCH 871/942] Further formatting fix. --- bindgen/ir/function.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bindgen/ir/function.rs b/bindgen/ir/function.rs index 8331f25632..bee0156695 100644 --- a/bindgen/ir/function.rs +++ b/bindgen/ir/function.rs @@ -735,7 +735,8 @@ impl ClangSubItemParser for Function { return Err(ParseError::Continue); } if cursor.access_specifier() == CX_CXXPrivate && - !context.options().generate_private_functions { + !context.options().generate_private_functions + { return Err(ParseError::Continue); } @@ -756,7 +757,8 @@ impl ClangSubItemParser for Function { } if cursor.is_deleted_function() && - !context.options().generate_deleted_functions { + !context.options().generate_deleted_functions + { return Err(ParseError::Continue); } From 32b6d8a10abe3821a5c2fb8dd1d8646b4455434d Mon Sep 17 00:00:00 2001 From: Adrian Taylor Date: Wed, 19 Feb 2025 15:32:29 +0000 Subject: [PATCH 872/942] Discovery callbacks for functions and methods. This extends the existing discovery callback mechanism to report on functions and methods. At this stage, we don't say much about them, in order to be consistent with other discovery callbacks. Subsequent PRs will add extra callbacks to provide information especially about methods (virtualness, C++ visibility, etc.) Please request changes if you think that sort of information should arrive in these callbacks. Because methods are a fundamentally C++ thing, this splits the current ParseCallbacks test to cover both a .h and a .hpp header. Part of https://github.com/google/autocxx/issues/124 --- .../header_item_discovery.h | 6 +- .../header_item_discovery.hpp | 6 + .../item_discovery_callback/mod.rs | 109 ++++++++++++++++-- bindgen/callbacks.rs | 17 ++- bindgen/codegen/mod.rs | 22 +++- 5 files changed, 150 insertions(+), 10 deletions(-) create mode 100644 bindgen-tests/tests/parse_callbacks/item_discovery_callback/header_item_discovery.hpp diff --git a/bindgen-tests/tests/parse_callbacks/item_discovery_callback/header_item_discovery.h b/bindgen-tests/tests/parse_callbacks/item_discovery_callback/header_item_discovery.h index b2bb04f15f..eb44e5fc58 100644 --- a/bindgen-tests/tests/parse_callbacks/item_discovery_callback/header_item_discovery.h +++ b/bindgen-tests/tests/parse_callbacks/item_discovery_callback/header_item_discovery.h @@ -25,4 +25,8 @@ enum NamedEnum { Fish, }; -typedef enum NamedEnum AliasOfNamedEnum; \ No newline at end of file +typedef enum NamedEnum AliasOfNamedEnum; + +// Functions + +void named_function(); diff --git a/bindgen-tests/tests/parse_callbacks/item_discovery_callback/header_item_discovery.hpp b/bindgen-tests/tests/parse_callbacks/item_discovery_callback/header_item_discovery.hpp new file mode 100644 index 0000000000..1de8d99e4d --- /dev/null +++ b/bindgen-tests/tests/parse_callbacks/item_discovery_callback/header_item_discovery.hpp @@ -0,0 +1,6 @@ +// Methods + +class SomeClass { +public: + void named_method(); +}; \ No newline at end of file diff --git a/bindgen-tests/tests/parse_callbacks/item_discovery_callback/mod.rs b/bindgen-tests/tests/parse_callbacks/item_discovery_callback/mod.rs index 93a2b029d7..dc16aa2078 100644 --- a/bindgen-tests/tests/parse_callbacks/item_discovery_callback/mod.rs +++ b/bindgen-tests/tests/parse_callbacks/item_discovery_callback/mod.rs @@ -17,20 +17,26 @@ impl ParseCallbacks for ItemDiscovery { self.0.borrow_mut().insert(_id, _item); } } -#[test] -pub fn test_item_discovery_callback() { + +fn test_item_discovery_callback(header: &str, expected: HashMap) { let discovery = ItemDiscovery::default(); let info = Rc::clone(&discovery.0); + let mut header_path = env!("CARGO_MANIFEST_DIR").to_string(); + header_path.push_str(header); + Builder::default() - .header(concat!( - env!("CARGO_MANIFEST_DIR"), - "/tests/parse_callbacks/item_discovery_callback/header_item_discovery.h" - )) + .header(header_path) .parse_callbacks(Box::new(discovery)) .generate() .expect("TODO: panic message"); + + compare_item_caches(&info.borrow(), &expected); +} + +#[test] +fn test_item_discovery_callback_c() { let expected = ItemCache::from([ ( DiscoveredItemId::new(10), @@ -87,9 +93,38 @@ pub fn test_item_discovery_callback() { final_name: "_bindgen_ty_*".to_string(), }, ), + ( + DiscoveredItemId::new(41), + DiscoveredItem::Function { + final_name: "named_function".to_string(), + }, + ), ]); + test_item_discovery_callback( + "/tests/parse_callbacks/item_discovery_callback/header_item_discovery.h", expected); +} - compare_item_caches(&info.borrow(), &expected); + +#[test] +fn test_item_discovery_callback_cpp() { + let expected = ItemCache::from([ + ( + DiscoveredItemId::new(1), + DiscoveredItem::Struct { + original_name: Some("SomeClass".to_string()), + final_name: "SomeClass".to_string(), + }, + ), + ( + DiscoveredItemId::new(2), + DiscoveredItem::Method { + final_name: "named_method".to_string(), + parent: DiscoveredItemId::new(1), + }, + ), + ]); + test_item_discovery_callback( + "/tests/parse_callbacks/item_discovery_callback/header_item_discovery.hpp", expected); } pub fn compare_item_caches(generated: &ItemCache, expected: &ItemCache) { @@ -142,6 +177,12 @@ fn compare_item_info( DiscoveredItem::Enum { .. } => { compare_enum_info(expected_item, generated_item) } + DiscoveredItem::Function { .. } => { + compare_function_info(expected_item, generated_item) + } + DiscoveredItem::Method { .. } => { + compare_method_info(expected_item, generated_item) + } } } @@ -279,3 +320,57 @@ pub fn compare_alias_info( compare_item_info(expected_aliased, generated_aliased, expected, generated) } + +pub fn compare_function_info( + expected_item: &DiscoveredItem, + generated_item: &DiscoveredItem, +) -> bool { + let DiscoveredItem::Function { + final_name: expected_final_name, + } = expected_item + else { + unreachable!() + }; + + let DiscoveredItem::Function { + final_name: generated_final_name, + } = generated_item + else { + unreachable!() + }; + + if !compare_names(expected_final_name, generated_final_name) { + return false; + } + true +} + +pub fn compare_method_info( + expected_item: &DiscoveredItem, + generated_item: &DiscoveredItem, +) -> bool { + let DiscoveredItem::Method { + final_name: expected_final_name, + parent: expected_parent, + } = expected_item + else { + unreachable!() + }; + + let DiscoveredItem::Method { + final_name: generated_final_name, + parent: generated_parent, + } = generated_item + else { + unreachable!() + }; + + if expected_parent != generated_parent { + return false; + } + + if !compare_names(expected_final_name, generated_final_name) { + return false; + } + true +} diff --git a/bindgen/callbacks.rs b/bindgen/callbacks.rs index c2be66828a..579d7083aa 100644 --- a/bindgen/callbacks.rs +++ b/bindgen/callbacks.rs @@ -224,7 +224,22 @@ pub enum DiscoveredItem { /// The final name of the generated binding final_name: String, }, - // functions, modules, etc. + + /// A function or method. + Function { + /// The final name used. + final_name: String, + }, + + /// A method. + Method { + /// The final name used. + final_name: String, + + /// Type to which this method belongs. + parent: DiscoveredItemId, + } + // modules, etc. } /// Relevant information about a type to which new derive attributes will be added using diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 8c623ff952..24b5ded03e 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -2481,6 +2481,7 @@ impl CodeGenerator for CompInfo { let is_rust_union = is_union && struct_layout.is_rust_union(); + let discovered_id = DiscoveredItemId::new(item.id().as_usize()); ctx.options().for_each_callback(|cb| { let discovered_item = match self.kind() { CompKind::Struct => DiscoveredItem::Struct { @@ -2502,7 +2503,7 @@ impl CodeGenerator for CompInfo { }; cb.new_item_found( - DiscoveredItemId::new(item.id().as_usize()), + discovered_id, discovered_item, ); }); @@ -2711,6 +2712,7 @@ impl CodeGenerator for CompInfo { &mut method_names, result, self, + discovered_id, ); } } @@ -2729,6 +2731,7 @@ impl CodeGenerator for CompInfo { &mut method_names, result, self, + discovered_id, ); } } @@ -2742,6 +2745,7 @@ impl CodeGenerator for CompInfo { &mut method_names, result, self, + discovered_id, ); } } @@ -2999,6 +3003,7 @@ impl Method { method_names: &mut HashSet, result: &mut CodegenResult<'_>, _parent: &CompInfo, + parent_id: DiscoveredItemId, ) { assert!({ let cc = &ctx.options().codegen_config; @@ -3019,6 +3024,7 @@ impl Method { // First of all, output the actual function. let function_item = ctx.resolve_item(self.signature()); + let id = DiscoveredItemId::new(function_item.id().as_usize()); if !function_item.process_before_codegen(ctx, result) { return; } @@ -3065,6 +3071,11 @@ impl Method { method_names.insert(name.clone()); + ctx.options().for_each_callback(|cb| cb.new_item_found(id, DiscoveredItem::Method { + parent: parent_id, + final_name: name.clone(), + })); + let mut function_name = function_item.canonical_name(ctx); if times_seen > 0 { write!(&mut function_name, "{times_seen}").unwrap(); @@ -4540,6 +4551,7 @@ impl CodeGenerator for Function { ) -> Self::Return { debug!("::codegen: item = {item:?}"); debug_assert!(item.is_enabled_for_codegen(ctx)); + let id = DiscoveredItemId::new(item.id().as_usize()); let is_internal = matches!(self.linkage(), Linkage::Internal); @@ -4656,6 +4668,14 @@ impl CodeGenerator for Function { if times_seen > 0 { write!(&mut canonical_name, "{times_seen}").unwrap(); } + ctx.options().for_each_callback(|cb| { + cb.new_item_found( + id, + DiscoveredItem::Function { + final_name: canonical_name.to_string(), + } + ); + }); let link_name_attr = self.link_name().or_else(|| { let mangled_name = mangled_name.unwrap_or(name); From fa2d8c3974a1ce4d90b14cd71631abdabbc51b97 Mon Sep 17 00:00:00 2001 From: Adrian Taylor Date: Wed, 19 Feb 2025 16:00:06 +0000 Subject: [PATCH 873/942] Formatting tweaks. --- .../item_discovery_callback/mod.rs | 7 ++++--- bindgen/callbacks.rs | 3 +-- bindgen/codegen/mod.rs | 20 ++++++++++--------- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/bindgen-tests/tests/parse_callbacks/item_discovery_callback/mod.rs b/bindgen-tests/tests/parse_callbacks/item_discovery_callback/mod.rs index dc16aa2078..645235b254 100644 --- a/bindgen-tests/tests/parse_callbacks/item_discovery_callback/mod.rs +++ b/bindgen-tests/tests/parse_callbacks/item_discovery_callback/mod.rs @@ -18,7 +18,10 @@ impl ParseCallbacks for ItemDiscovery { } } -fn test_item_discovery_callback(header: &str, expected: HashMap) { +fn test_item_discovery_callback( + header: &str, + expected: HashMap, +) { let discovery = ItemDiscovery::default(); let info = Rc::clone(&discovery.0); @@ -31,7 +34,6 @@ fn test_item_discovery_callback(header: &str, expected: HashMap 0 { @@ -4673,7 +4675,7 @@ impl CodeGenerator for Function { id, DiscoveredItem::Function { final_name: canonical_name.to_string(), - } + }, ); }); From 19c1f60a6891397b2d568354be7147d8d3d86680 Mon Sep 17 00:00:00 2001 From: Adrian Taylor Date: Thu, 20 Feb 2025 13:03:08 +0000 Subject: [PATCH 874/942] Option to represent all C++ operators. In its default behavior, bindgen does not emit information for any C++ operatorXYZ function (unless operatorXYZ is a valid identifier, which it isn't for C++ overloaded operators). This PR introduces a new command line option to represent all operators. This is not useful for those who directly consume the output of bindgen, but is useful for post-processors. Specifically, consumers will need to implement the callback to rename these items to something more useful. Part of https://github.com/google/autocxx/issues/124 --- .../expectations/tests/operator_equals.rs | 24 +++++++++++++++++++ .../tests/headers/operator_equals.hpp | 9 +++++++ bindgen-tests/tests/parse_callbacks/mod.rs | 14 +++++++++++ bindgen/ir/function.rs | 2 +- bindgen/options/cli.rs | 5 ++++ bindgen/options/mod.rs | 18 ++++++++++++++ 6 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 bindgen-tests/tests/expectations/tests/operator_equals.rs create mode 100644 bindgen-tests/tests/headers/operator_equals.hpp diff --git a/bindgen-tests/tests/expectations/tests/operator_equals.rs b/bindgen-tests/tests/expectations/tests/operator_equals.rs new file mode 100644 index 0000000000..ff9f4fdd22 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/operator_equals.rs @@ -0,0 +1,24 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct SomeClass { + pub _address: u8, +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of SomeClass"][::std::mem::size_of::() - 1usize]; + ["Alignment of SomeClass"][::std::mem::align_of::() - 1usize]; +}; +unsafe extern "C" { + #[link_name = "\u{1}_ZN9SomeClassaSERKS_"] + pub fn SomeClass_operatorequals( + this: *mut SomeClass, + another: *const SomeClass, + ) -> bool; +} +impl SomeClass { + #[inline] + pub unsafe fn operatorequals(&mut self, another: *const SomeClass) -> bool { + SomeClass_operatorequals(self, another) + } +} diff --git a/bindgen-tests/tests/headers/operator_equals.hpp b/bindgen-tests/tests/headers/operator_equals.hpp new file mode 100644 index 0000000000..38a3a092a9 --- /dev/null +++ b/bindgen-tests/tests/headers/operator_equals.hpp @@ -0,0 +1,9 @@ +// bindgen-flags: --represent-cxx-operators --generate-inline-functions -- -x c++ +// bindgen-parse-callbacks: operator-rename + +class SomeClass { +public: + bool operator=(const SomeClass& another) { + return false; + } +}; diff --git a/bindgen-tests/tests/parse_callbacks/mod.rs b/bindgen-tests/tests/parse_callbacks/mod.rs index 7aca0fd1a1..5fe8d90d4c 100644 --- a/bindgen-tests/tests/parse_callbacks/mod.rs +++ b/bindgen-tests/tests/parse_callbacks/mod.rs @@ -146,6 +146,19 @@ impl ParseCallbacks for WrapAsVariadicFn { } } +#[derive(Debug)] +pub(super) struct OperatorRename; + +impl ParseCallbacks for OperatorRename { + fn generated_name_override(&self, info: ItemInfo) -> Option { + if info.name == "operator=" { + Some("operatorequals".to_string()) + } else { + None + } + } +} + pub fn lookup(cb: &str) -> Box { match cb { "enum-variant-rename" => Box::new(EnumVariantRename), @@ -154,6 +167,7 @@ pub fn lookup(cb: &str) -> Box { } "wrap-as-variadic-fn" => Box::new(WrapAsVariadicFn), "type-visibility" => Box::new(TypeVisibility), + "operator-rename" => Box::new(OperatorRename), call_back => { if let Some(prefix) = call_back.strip_prefix("remove-function-prefix-") diff --git a/bindgen/ir/function.rs b/bindgen/ir/function.rs index bee0156695..65a12d4bb2 100644 --- a/bindgen/ir/function.rs +++ b/bindgen/ir/function.rs @@ -433,7 +433,7 @@ impl FunctionSig { spelling.starts_with("operator") && !clang::is_valid_identifier(spelling) }; - if is_operator(&spelling) { + if is_operator(&spelling) && !ctx.options().represent_cxx_operators { return Err(ParseError::Continue); } diff --git a/bindgen/options/cli.rs b/bindgen/options/cli.rs index 170df4f707..d3cf5d0916 100644 --- a/bindgen/options/cli.rs +++ b/bindgen/options/cli.rs @@ -447,6 +447,9 @@ struct BindgenCommand { /// Use distinct char16_t #[arg(long)] use_distinct_char16_t: bool, + /// Output C++ overloaded operators + #[arg(long)] + represent_cxx_operators: bool, /// Enables generation of vtable functions. #[arg(long)] vtable_generation: bool, @@ -649,6 +652,7 @@ where explicit_padding, use_specific_virtual_function_receiver, use_distinct_char16_t, + represent_cxx_operators, vtable_generation, sort_semantically, merge_extern_blocks, @@ -951,6 +955,7 @@ where explicit_padding, use_specific_virtual_function_receiver, use_distinct_char16_t, + represent_cxx_operators, vtable_generation, sort_semantically, merge_extern_blocks, diff --git a/bindgen/options/mod.rs b/bindgen/options/mod.rs index 7824f5d188..c9ef7c8b49 100644 --- a/bindgen/options/mod.rs +++ b/bindgen/options/mod.rs @@ -192,6 +192,24 @@ options! { }, as_args: "--use-distinct-char16-t", }, + /// Whether we should output C++ overloaded operators. By itself, + /// this option is not sufficient to produce valid output, because + /// such operators will have names that are not acceptable Rust + /// names (for example `operator=`). If you use this option, you'll also + /// have to rename the resulting functions - for example by using + /// [`ParseCallbacks::generated_name_override`]. + represent_cxx_operators: bool { + methods: { + /// If this is true, output existence of C++ overloaded operators. + /// At present, only operator= is noted. + /// Disabled by default. + pub fn represent_cxx_operators(mut self, doit: bool) -> Builder { + self.options.represent_cxx_operators = doit; + self + } + }, + as_args: "--represent-cxx-operators", + }, /// Types that have been blocklisted and should not appear anywhere in the generated code. blocklisted_types: RegexSet { From e5480dd602fa6bb5616d3c435b5b5e4403e6e389 Mon Sep 17 00:00:00 2001 From: Dusty DeWeese Date: Tue, 1 Apr 2025 13:56:49 -0700 Subject: [PATCH 875/942] rename *-apple-ios-sim to ...simulator --- bindgen/lib.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 1a15d51d67..8867e8180f 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -704,6 +704,10 @@ fn rust_to_clang_target(rust_target: &str) -> Box { let idx = clang_target.rfind('-').expect(TRIPLE_HYPHENS_MESSAGE); clang_target.replace_range((idx + 1).., "elf"); + } else if clang_target.ends_with("apple-ios-sim") { + let idx = clang_target.rfind('-').expect(TRIPLE_HYPHENS_MESSAGE); + + clang_target.replace_range((idx + 1).., "simulator"); } clang_target.into() @@ -1389,3 +1393,11 @@ fn test_rust_to_clang_target_espidf() { "xtensa-esp32-elf" ); } + +#[test] +fn test_rust_to_clang_target_simulator() { + assert_eq!( + rust_to_clang_target("aarch64-apple-ios-sim").as_ref(), + "arm64-apple-ios-simulator" + ); +} From b777e6a255f6608a79923996319a5a57c677a818 Mon Sep 17 00:00:00 2001 From: Dusty DeWeese Date: Tue, 1 Apr 2025 17:22:51 -0700 Subject: [PATCH 876/942] more sophisticated handling of the triple in rust_to_clang_target --- bindgen/lib.rs | 59 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 8867e8180f..5a946e6d13 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -684,33 +684,44 @@ pub(crate) const HOST_TARGET: &str = fn rust_to_clang_target(rust_target: &str) -> Box { const TRIPLE_HYPHENS_MESSAGE: &str = "Target triple should contain hyphens"; - let mut clang_target = rust_target.to_owned(); + let mut triple: Vec<&str> = rust_target.split_terminator('-').collect(); - if clang_target.starts_with("riscv32") { - let idx = clang_target.find('-').expect(TRIPLE_HYPHENS_MESSAGE); + assert!(!triple.is_empty(), "{}", TRIPLE_HYPHENS_MESSAGE); + triple.resize(4, ""); - clang_target.replace_range(..idx, "riscv32"); - } else if clang_target.starts_with("riscv64") { - let idx = clang_target.find('-').expect(TRIPLE_HYPHENS_MESSAGE); - - clang_target.replace_range(..idx, "riscv64"); - } else if clang_target.starts_with("aarch64-apple-") { - let idx = clang_target.find('-').expect(TRIPLE_HYPHENS_MESSAGE); - - clang_target.replace_range(..idx, "arm64"); + // RISC-V + if triple[0].starts_with("riscv32") { + triple[0] = "riscv32"; + } else if triple[0].starts_with("riscv64") { + triple[0] = "riscv64"; } - if clang_target.ends_with("-espidf") { - let idx = clang_target.rfind('-').expect(TRIPLE_HYPHENS_MESSAGE); - - clang_target.replace_range((idx + 1).., "elf"); - } else if clang_target.ends_with("apple-ios-sim") { - let idx = clang_target.rfind('-').expect(TRIPLE_HYPHENS_MESSAGE); + // Apple + if triple[1] == "apple" { + if triple[0] == "aarch64" { + triple[0] = "arm64"; + } + if triple[3] == "sim" { + triple[3] = "simulator"; + } + } - clang_target.replace_range((idx + 1).., "simulator"); + // ESP-IDF + if triple[2] == "espidf" { + triple[2] = "elf"; } - clang_target.into() + triple + .iter() + .skip(1) + .fold(triple[0].to_string(), |triple, part| { + if part.is_empty() { + triple + } else { + triple + "-" + part + } + }) + .into() } /// Returns the effective target, and whether it was explicitly specified on the @@ -1400,4 +1411,12 @@ fn test_rust_to_clang_target_simulator() { rust_to_clang_target("aarch64-apple-ios-sim").as_ref(), "arm64-apple-ios-simulator" ); + assert_eq!( + rust_to_clang_target("aarch64-apple-tvos-sim").as_ref(), + "arm64-apple-tvos-simulator" + ); + assert_eq!( + rust_to_clang_target("aarch64-apple-watchos-sim").as_ref(), + "arm64-apple-watchos-simulator" + ); } From 4f78a959db3743942e7223fe558073f21bf955f4 Mon Sep 17 00:00:00 2001 From: ilcheese2 <56899583+ilcheese2@users.noreply.github.com> Date: Fri, 21 Mar 2025 23:04:11 -0700 Subject: [PATCH 877/942] Fix OpenCL vectors that use "ext_vector_type" and add test --- bindgen-tests/tests/expectations/tests/opencl_vector.rs | 6 ++++++ bindgen-tests/tests/headers/opencl_vector.h | 9 +++++++++ bindgen/ir/ty.rs | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 bindgen-tests/tests/expectations/tests/opencl_vector.rs create mode 100644 bindgen-tests/tests/headers/opencl_vector.h diff --git a/bindgen-tests/tests/expectations/tests/opencl_vector.rs b/bindgen-tests/tests/expectations/tests/opencl_vector.rs new file mode 100644 index 0000000000..3c2525c845 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/opencl_vector.rs @@ -0,0 +1,6 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub type float4 = [f32; 4usize]; +pub type float2 = [f32; 2usize]; +unsafe extern "C" { + pub fn foo(a: float2, b: float2) -> float4; +} diff --git a/bindgen-tests/tests/headers/opencl_vector.h b/bindgen-tests/tests/headers/opencl_vector.h new file mode 100644 index 0000000000..79022c768f --- /dev/null +++ b/bindgen-tests/tests/headers/opencl_vector.h @@ -0,0 +1,9 @@ +typedef float float4 __attribute__((ext_vector_type(4))); +typedef float float2 __attribute__((ext_vector_type(2))); + +float4 foo(float2 a, float2 b) { + float4 c; + c.xz = a; + c.yw = b; + return c; +} \ No newline at end of file diff --git a/bindgen/ir/ty.rs b/bindgen/ir/ty.rs index 2589a56fca..baaa4a4907 100644 --- a/bindgen/ir/ty.rs +++ b/bindgen/ir/ty.rs @@ -1117,7 +1117,7 @@ impl Type { TypeKind::Comp(complex) } - CXType_Vector => { + CXType_Vector | CXType_ExtVector => { let inner = Item::from_ty( ty.elem_type().as_ref().unwrap(), location, From 8a3b0ec8e982773a0723441cbb57c5f0ea780ddc Mon Sep 17 00:00:00 2001 From: Jonathan Schwender Date: Tue, 4 Feb 2025 22:17:14 +0100 Subject: [PATCH 878/942] Refactor enum generation. Gather all the enum variants. This allows us to simplify some logic, make the code more readable, by putting the actual code generation close together in the build method. For users, the main benefit is that Newtype enums now only have a single impl block, instead of one impl block per enum variant. --- .../expectations/tests/bitfield-enum-basic.rs | 12 - .../tests/bitfield-enum-repr-c.rs | 6 - .../tests/bitfield-enum-repr-transparent.rs | 6 - .../tests/enum-default-bitfield.rs | 6 - .../expectations/tests/enum-doc-bitfield.rs | 10 - .../issue-1198-alias-rust-bitfield-enum.rs | 8 - .../tests/expectations/tests/issue-1435.rs | 4 +- .../tests/expectations/tests/newtype-enum.rs | 6 - bindgen/codegen/mod.rs | 465 ++++++++++-------- 9 files changed, 256 insertions(+), 267 deletions(-) diff --git a/bindgen-tests/tests/expectations/tests/bitfield-enum-basic.rs b/bindgen-tests/tests/expectations/tests/bitfield-enum-basic.rs index adc4690c86..aecb9dc639 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-enum-basic.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-enum-basic.rs @@ -1,14 +1,8 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] impl Foo { pub const Bar: Foo = Foo(2); -} -impl Foo { pub const Baz: Foo = Foo(4); -} -impl Foo { pub const Duplicated: Foo = Foo(4); -} -impl Foo { pub const Negative: Foo = Foo(-3); } impl ::std::ops::BitOr for Foo { @@ -42,14 +36,8 @@ impl ::std::ops::BitAndAssign for Foo { pub struct Foo(pub ::std::os::raw::c_int); impl Buz { pub const Bar: Buz = Buz(2); -} -impl Buz { pub const Baz: Buz = Buz(4); -} -impl Buz { pub const Duplicated: Buz = Buz(4); -} -impl Buz { pub const Negative: Buz = Buz(-3); } impl ::std::ops::BitOr for Buz { diff --git a/bindgen-tests/tests/expectations/tests/bitfield-enum-repr-c.rs b/bindgen-tests/tests/expectations/tests/bitfield-enum-repr-c.rs index 0b5202dfe3..df5a69eddd 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-enum-repr-c.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-enum-repr-c.rs @@ -1,14 +1,8 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] impl Foo { pub const Bar: Foo = Foo(2); -} -impl Foo { pub const Baz: Foo = Foo(4); -} -impl Foo { pub const Duplicated: Foo = Foo(4); -} -impl Foo { pub const Negative: Foo = Foo(-3); } impl ::std::ops::BitOr for Foo { diff --git a/bindgen-tests/tests/expectations/tests/bitfield-enum-repr-transparent.rs b/bindgen-tests/tests/expectations/tests/bitfield-enum-repr-transparent.rs index 0b5202dfe3..df5a69eddd 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-enum-repr-transparent.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-enum-repr-transparent.rs @@ -1,14 +1,8 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] impl Foo { pub const Bar: Foo = Foo(2); -} -impl Foo { pub const Baz: Foo = Foo(4); -} -impl Foo { pub const Duplicated: Foo = Foo(4); -} -impl Foo { pub const Negative: Foo = Foo(-3); } impl ::std::ops::BitOr for Foo { diff --git a/bindgen-tests/tests/expectations/tests/enum-default-bitfield.rs b/bindgen-tests/tests/expectations/tests/enum-default-bitfield.rs index 58b8bf092f..b7b14fbc1c 100644 --- a/bindgen-tests/tests/expectations/tests/enum-default-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/enum-default-bitfield.rs @@ -52,8 +52,6 @@ impl Default for foo { } impl Foo { pub const Bar: Foo = Foo(0); -} -impl Foo { pub const Qux: Foo = Foo(1); } impl ::std::ops::BitOr for Foo { @@ -92,8 +90,6 @@ pub mod Neg { } impl NoDebug { pub const NoDebug1: NoDebug = NoDebug(0); -} -impl NoDebug { pub const NoDebug2: NoDebug = NoDebug(1); } impl ::std::ops::BitOr for NoDebug { @@ -128,8 +124,6 @@ impl ::std::ops::BitAndAssign for NoDebug { pub struct NoDebug(pub ::std::os::raw::c_uint); impl Debug { pub const Debug1: Debug = Debug(0); -} -impl Debug { pub const Debug2: Debug = Debug(1); } impl ::std::ops::BitOr for Debug { diff --git a/bindgen-tests/tests/expectations/tests/enum-doc-bitfield.rs b/bindgen-tests/tests/expectations/tests/enum-doc-bitfield.rs index ba73a8ea3e..33eec3e44f 100644 --- a/bindgen-tests/tests/expectations/tests/enum-doc-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/enum-doc-bitfield.rs @@ -2,24 +2,14 @@ impl B { /// Document field with three slashes pub const VAR_A: B = B(0); -} -impl B { /// Document field with preceding star pub const VAR_B: B = B(1); -} -impl B { /// Document field with preceding exclamation pub const VAR_C: B = B(2); -} -impl B { ///< Document field with following star pub const VAR_D: B = B(3); -} -impl B { ///< Document field with following exclamation pub const VAR_E: B = B(4); -} -impl B { /** Document field with preceding star, with a loong long multiline comment. diff --git a/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-bitfield-enum.rs b/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-bitfield-enum.rs index 7bbcb0d50b..5aaff691b4 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-bitfield-enum.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-bitfield-enum.rs @@ -1,11 +1,7 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] impl MyDupeEnum { pub const A: MyDupeEnum = MyDupeEnum(0); -} -impl MyDupeEnum { pub const A_alias: MyDupeEnum = MyDupeEnum(0); -} -impl MyDupeEnum { pub const B: MyDupeEnum = MyDupeEnum(1); } impl ::std::ops::BitOr for MyDupeEnum { @@ -39,11 +35,7 @@ impl ::std::ops::BitAndAssign for MyDupeEnum { pub struct MyDupeEnum(pub ::std::os::raw::c_uint); impl MyOtherDupeEnum { pub const C: MyOtherDupeEnum = MyOtherDupeEnum(0); -} -impl MyOtherDupeEnum { pub const C_alias: MyOtherDupeEnum = MyOtherDupeEnum(0); -} -impl MyOtherDupeEnum { pub const D: MyOtherDupeEnum = MyOtherDupeEnum(1); } impl ::std::ops::BitOr for MyOtherDupeEnum { diff --git a/bindgen-tests/tests/expectations/tests/issue-1435.rs b/bindgen-tests/tests/expectations/tests/issue-1435.rs index 7b9bfe8422..b50e1f88c0 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1435.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1435.rs @@ -6,8 +6,8 @@ pub mod root { pub mod ns { #[allow(unused_imports)] use self::super::super::root; - pub const AB_A: root::ns::AB = 0; - pub const AB_B: root::ns::AB = 1; + pub const AB_A: AB = 0; + pub const AB_B: AB = 1; pub type AB = ::std::os::raw::c_int; } pub use self::super::root::ns::AB as AB; diff --git a/bindgen-tests/tests/expectations/tests/newtype-enum.rs b/bindgen-tests/tests/expectations/tests/newtype-enum.rs index ea25950de0..0045c52a61 100644 --- a/bindgen-tests/tests/expectations/tests/newtype-enum.rs +++ b/bindgen-tests/tests/expectations/tests/newtype-enum.rs @@ -1,14 +1,8 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] impl Foo { pub const Bar: Foo = Foo(2); -} -impl Foo { pub const Baz: Foo = Foo(4); -} -impl Foo { pub const Duplicated: Foo = Foo(4); -} -impl Foo { pub const Negative: Foo = Foo(-3); } #[repr(transparent)] diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 801eaaba6a..13c0b60526 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -3279,111 +3279,106 @@ impl FromStr for EnumVariation { } } +struct EnumBuilder { + /// Type identifier of the enum. + /// + /// This is the base name, i.e. for ModuleConst enums, this does not include the module name. + enum_type: Ident, + /// Attributes applying to the enum type + attrs: Vec, + /// The representation of the enum, e.g. `u32`. + repr: syn::Type, + /// The enum kind we are generating + kind: EnumBuilderKind, + /// A list of all variants this enum has. + enum_variants: Vec, +} + /// A helper type to construct different enum variations. -enum EnumBuilder<'a> { +enum EnumBuilderKind { Rust { - attrs: Vec, - ident: Ident, - tokens: proc_macro2::TokenStream, - emitted_any_variants: bool, + non_exhaustive: bool, }, NewType { - canonical_name: &'a str, - tokens: proc_macro2::TokenStream, is_bitfield: bool, is_global: bool, + /// if the enum is named or not. + is_anonymous: bool, }, Consts { - variants: Vec, + needs_typedef: bool, }, ModuleConsts { - module_name: &'a str, - module_items: Vec, + module_name: Ident, }, } -impl<'a> EnumBuilder<'a> { +impl EnumBuilder { /// Returns true if the builder is for a rustified enum. fn is_rust_enum(&self) -> bool { - matches!(*self, EnumBuilder::Rust { .. }) + matches!(self.kind, EnumBuilderKind::Rust { .. }) } /// Create a new enum given an item builder, a canonical name, a name for /// the representation, and which variation it should be generated as. fn new( - name: &'a str, - mut attrs: Vec, + name: &str, + attrs: Vec, repr: &syn::Type, enum_variation: EnumVariation, has_typedef: bool, + enum_is_anonymous: bool, ) -> Self { let ident = Ident::new(name, Span::call_site()); + // For most variants this is the same + let mut enum_ty = ident.clone(); - match enum_variation { + let kind = match enum_variation { EnumVariation::NewType { is_bitfield, is_global, - } => EnumBuilder::NewType { - canonical_name: name, - tokens: quote! { - #( #attrs )* - pub struct #ident (pub #repr); - }, + } => EnumBuilderKind::NewType { is_bitfield, is_global, + is_anonymous: enum_is_anonymous, }, - EnumVariation::Rust { .. } => { - // `repr` is guaranteed to be Rustified in Enum::codegen - attrs.insert(0, quote! { #[repr( #repr )] }); - let tokens = quote!(); - EnumBuilder::Rust { - attrs, - ident, - tokens, - emitted_any_variants: false, - } + EnumVariation::Rust { non_exhaustive } => { + EnumBuilderKind::Rust { non_exhaustive } } - EnumVariation::Consts => { - let mut variants = Vec::new(); - - if !has_typedef { - variants.push(quote! { - #( #attrs )* - pub type #ident = #repr; - }); - } - - EnumBuilder::Consts { variants } - } + EnumVariation::Consts => EnumBuilderKind::Consts { + needs_typedef: !has_typedef, + }, EnumVariation::ModuleConsts => { - let ident = Ident::new( + enum_ty = Ident::new( CONSTIFIED_ENUM_MODULE_REPR_NAME, Span::call_site(), ); - let type_definition = quote! { - #( #attrs )* - pub type #ident = #repr; - }; - EnumBuilder::ModuleConsts { - module_name: name, - module_items: vec![type_definition], + EnumBuilderKind::ModuleConsts { + module_name: ident.clone(), } } + }; + EnumBuilder { + enum_type: enum_ty, + attrs, + repr: repr.clone(), + kind, + enum_variants: vec![], } } /// Add a variant to this enum. fn with_variant( - self, + mut self, ctx: &BindgenContext, variant: &EnumVariant, + variant_doc: proc_macro2::TokenStream, mangling_prefix: Option<&str>, rust_ty: &syn::Type, - result: &mut CodegenResult<'_>, is_ty_named: bool, ) -> Self { let variant_name = ctx.rust_mangle(variant.name()); @@ -3397,66 +3392,38 @@ impl<'a> EnumBuilder<'a> { EnumVariantValue::Unsigned(v) => helpers::ast_ty::uint_expr(v), }; - let mut doc = quote! {}; - if ctx.options().generate_comments { - if let Some(raw_comment) = variant.comment() { - let comment = ctx.options().process_comment(raw_comment); - doc = attributes::doc(&comment); - } - } - - match self { - EnumBuilder::Rust { - attrs, - ident, - tokens, - emitted_any_variants: _, - } => { + match self.kind { + EnumBuilderKind::Rust { .. } => { let name = ctx.rust_ident(variant_name); - EnumBuilder::Rust { - attrs, - ident, - tokens: quote! { - #tokens - #doc - #name = #expr, - }, - emitted_any_variants: true, - } + self.enum_variants.push(EnumVariantInfo { + variant_name: name, + variant_doc, + value: expr, + }); + self } - EnumBuilder::NewType { - canonical_name, - is_global, - .. - } => { - if is_ty_named && !is_global { - let enum_ident = ctx.rust_ident(canonical_name); - let variant_ident = ctx.rust_ident(variant_name); - - result.push(quote! { - impl #enum_ident { - #doc - pub const #variant_ident : #rust_ty = #rust_ty ( #expr ); - } - }); + EnumBuilderKind::NewType { is_global, .. } => { + let variant_ident = if is_ty_named && !is_global { + ctx.rust_ident(variant_name) } else { - let ident = ctx.rust_ident(match mangling_prefix { + ctx.rust_ident(match mangling_prefix { Some(prefix) => { Cow::Owned(format!("{prefix}_{variant_name}")) } None => variant_name, - }); - result.push(quote! { - #doc - pub const #ident : #rust_ty = #rust_ty ( #expr ); - }); - } + }) + }; + self.enum_variants.push(EnumVariantInfo { + variant_name: variant_ident, + variant_doc, + value: quote! { #rust_ty ( #expr )}, + }); self } - EnumBuilder::Consts { .. } => { + EnumBuilderKind::Consts { .. } => { let constant_name = match mangling_prefix { Some(prefix) => { Cow::Owned(format!("{prefix}_{variant_name}")) @@ -3465,27 +3432,58 @@ impl<'a> EnumBuilder<'a> { }; let ident = ctx.rust_ident(constant_name); - result.push(quote! { - #doc - pub const #ident : #rust_ty = #expr ; + self.enum_variants.push(EnumVariantInfo { + variant_name: ident, + variant_doc, + value: quote! { #expr }, }); self } - EnumBuilder::ModuleConsts { - module_name, - mut module_items, - } => { + EnumBuilderKind::ModuleConsts { .. } => { let name = ctx.rust_ident(variant_name); - let ty = ctx.rust_ident(CONSTIFIED_ENUM_MODULE_REPR_NAME); - module_items.push(quote! { - #doc - pub const #name : #ty = #expr ; + self.enum_variants.push(EnumVariantInfo { + variant_name: name, + variant_doc, + value: quote! { #expr }, }); + self + } + } + } + + fn newtype_bitfield_impl( + prefix: Ident, + rust_ty: &syn::Type, + ) -> proc_macro2::TokenStream { + let rust_ty_name = &rust_ty; + quote! { + impl ::#prefix::ops::BitOr<#rust_ty> for #rust_ty { + type Output = Self; + + #[inline] + fn bitor(self, other: Self) -> Self { + #rust_ty_name(self.0 | other.0) + } + } + impl ::#prefix::ops::BitOrAssign for #rust_ty { + #[inline] + fn bitor_assign(&mut self, rhs: #rust_ty) { + self.0 |= rhs.0; + } + } + impl ::#prefix::ops::BitAnd<#rust_ty> for #rust_ty { + type Output = Self; - EnumBuilder::ModuleConsts { - module_name, - module_items, + #[inline] + fn bitand(self, other: Self) -> Self { + #rust_ty_name(self.0 & other.0) + } + } + impl ::#prefix::ops::BitAndAssign for #rust_ty { + #[inline] + fn bitand_assign(&mut self, rhs: #rust_ty) { + self.0 &= rhs.0; } } } @@ -3495,94 +3493,141 @@ impl<'a> EnumBuilder<'a> { self, ctx: &BindgenContext, rust_ty: &syn::Type, - result: &mut CodegenResult<'_>, ) -> proc_macro2::TokenStream { - match self { - EnumBuilder::Rust { - attrs, - ident, - tokens, - emitted_any_variants, - .. - } => { - let variants = if emitted_any_variants { - tokens - } else { - quote!(__bindgen_cannot_repr_c_on_empty_enum = 0) - }; + let enum_ident = self.enum_type; + + // 1. Construct a list of the enum variants + let variants = match self.kind { + EnumBuilderKind::Rust { .. } => { + let mut variants = vec![]; + + for v in self.enum_variants { + let variant_doc = &v.variant_doc; + let variant_ident = &v.variant_name; + let variant_value = &v.value; + + variants.push(quote! { + #variant_doc + #variant_ident = #variant_value, + }); + } + + if variants.is_empty() { + variants.push( + quote! {__bindgen_cannot_repr_c_on_empty_enum = 0,}, + ); + } + variants + } + EnumBuilderKind::NewType { .. } => { + let mut variants = vec![]; + + for v in self.enum_variants { + let variant_doc = &v.variant_doc; + let variant_ident = &v.variant_name; + let variant_value = &v.value; + + variants.push(quote! { + #variant_doc + pub const #variant_ident: #enum_ident = #variant_value; + }); + } + variants + } + EnumBuilderKind::Consts { .. } | + EnumBuilderKind::ModuleConsts { .. } => { + let mut variants = vec![]; + + for v in self.enum_variants { + let variant_doc = &v.variant_doc; + let variant_ident = &v.variant_name; + let variant_value = &v.value; + + variants.push(quote! { + #variant_doc + pub const #variant_ident: #enum_ident = #variant_value; + }); + } + variants + } + }; + let attrs = self.attrs; + let enum_repr = &self.repr; + + // 2. Generate the enum representation + match self.kind { + EnumBuilderKind::Rust { non_exhaustive } => { + let non_exhaustive_opt = + non_exhaustive.then(attributes::non_exhaustive); quote! { + // Note: repr is on top of attrs to keep the test expectations diff small. + // a future commit could move it further down. + #[repr(#enum_repr)] + #non_exhaustive_opt #( #attrs )* - pub enum #ident { - #variants + pub enum #enum_ident { + #( #variants )* } } } - EnumBuilder::NewType { - canonical_name, - tokens, + EnumBuilderKind::NewType { is_bitfield, - .. + is_global, + is_anonymous, } => { - if !is_bitfield { - return tokens; - } - - let rust_ty_name = ctx.rust_ident_raw(canonical_name); - let prefix = ctx.trait_prefix(); - - result.push(quote! { - impl ::#prefix::ops::BitOr<#rust_ty> for #rust_ty { - type Output = Self; - - #[inline] - fn bitor(self, other: Self) -> Self { - #rust_ty_name(self.0 | other.0) - } + // There doesn't seem to be a technical reason why we generate + // anon enum variants as global constants. + // We keep this behavior to avoid breaking changes in the bindings. + let impl_variants = if is_anonymous || is_global { + quote! { + #( #variants )* } - }); - - result.push(quote! { - impl ::#prefix::ops::BitOrAssign for #rust_ty { - #[inline] - fn bitor_assign(&mut self, rhs: #rust_ty) { - self.0 |= rhs.0; + } else { + quote! { + impl #enum_ident { + #( #variants )* } } - }); + }; - result.push(quote! { - impl ::#prefix::ops::BitAnd<#rust_ty> for #rust_ty { - type Output = Self; + let prefix = ctx.trait_prefix(); + let bitfield_impl_opt = is_bitfield + .then(|| Self::newtype_bitfield_impl(prefix, rust_ty)); - #[inline] - fn bitand(self, other: Self) -> Self { - #rust_ty_name(self.0 & other.0) - } - } - }); + quote! { + // Previously variant impls where before the enum definition. + // lets keep this as is for now, to reduce the diff in generated bindings. + #impl_variants - result.push(quote! { - impl ::#prefix::ops::BitAndAssign for #rust_ty { - #[inline] - fn bitand_assign(&mut self, rhs: #rust_ty) { - self.0 &= rhs.0; - } + #bitfield_impl_opt + + #[repr(transparent)] + #( #attrs )* + pub struct #enum_ident (pub #enum_repr); + } + } + EnumBuilderKind::Consts { needs_typedef } => { + let typedef_opt = needs_typedef.then(|| { + quote! { + #( #attrs )* + pub type #enum_ident = #enum_repr; } }); + quote! { + #( #variants )* - tokens + #typedef_opt + } } - EnumBuilder::Consts { variants, .. } => quote! { #( #variants )* }, - EnumBuilder::ModuleConsts { - module_items, - module_name, - .. - } => { - let ident = ctx.rust_ident(module_name); + EnumBuilderKind::ModuleConsts { module_name, .. } => { quote! { - pub mod #ident { - #( #module_items )* + // todo: Probably some attributes, e.g. `cfg` should apply to the `mod`. + pub mod #module_name { + #( #attrs )* + pub type #enum_ident = #enum_repr; + + #( #variants )* } } } @@ -3669,29 +3714,6 @@ impl CodeGenerator for Enum { let mut attrs = vec![]; - // TODO(emilio): Delegate this to the builders? - match variation { - EnumVariation::Rust { non_exhaustive } => { - if non_exhaustive && - ctx.options().rust_features().non_exhaustive - { - attrs.push(attributes::non_exhaustive()); - } else if non_exhaustive && - !ctx.options().rust_features().non_exhaustive - { - panic!("The rust target you're using doesn't seem to support non_exhaustive enums"); - } - } - EnumVariation::NewType { .. } => { - if true { - attrs.push(attributes::repr("transparent")); - } else { - attrs.push(attributes::repr("C")); - } - } - _ => {} - }; - if let Some(comment) = item.comment(ctx) { attrs.push(attributes::doc(&comment)); } @@ -3792,8 +3814,14 @@ impl CodeGenerator for Enum { ); }); - let mut builder = - EnumBuilder::new(&name, attrs, &repr, variation, has_typedef); + let mut builder = EnumBuilder::new( + &name, + attrs, + &repr, + variation, + has_typedef, + enum_ty.name().is_none(), + ); // A map where we keep a value -> variant relation. let mut seen_values = HashMap::<_, Ident>::default(); @@ -3835,6 +3863,15 @@ impl CodeGenerator for Enum { continue; } + let mut variant_doc = quote! {}; + if ctx.options().generate_comments { + if let Some(raw_comment) = variant.comment() { + let processed_comment = + ctx.options().process_comment(raw_comment); + variant_doc = attributes::doc(&processed_comment); + } + } + match seen_values.entry(variant.val()) { Entry::Occupied(ref entry) => { if variation.is_rust() { @@ -3877,9 +3914,9 @@ impl CodeGenerator for Enum { builder = builder.with_variant( ctx, variant, + variant_doc, constant_mangling_prefix, &enum_rust_ty, - result, enum_ty.name().is_some(), ); } @@ -3888,9 +3925,9 @@ impl CodeGenerator for Enum { builder = builder.with_variant( ctx, variant, + variant_doc, constant_mangling_prefix, &enum_rust_ty, - result, enum_ty.name().is_some(), ); @@ -3930,11 +3967,17 @@ impl CodeGenerator for Enum { } } - let item = builder.build(ctx, &enum_rust_ty, result); + let item = builder.build(ctx, &enum_rust_ty); result.push(item); } } +struct EnumVariantInfo { + variant_name: Ident, + variant_doc: proc_macro2::TokenStream, + value: proc_macro2::TokenStream, +} + /// Enum for the default type of macro constants. #[derive(Copy, Clone, PartialEq, Eq, Debug, Default)] pub enum MacroTypeVariation { From a50a2cf07ba26153c822ee858c0a022532ac87a4 Mon Sep 17 00:00:00 2001 From: Benjamin Lerman Date: Thu, 20 Mar 2025 13:40:15 +0100 Subject: [PATCH 879/942] Fix union layout when it contains 0 sized array. Fix #3068 --- .../tests/union_with_zero_sized_array.rs | 68 +++++++++++++++++++ .../headers/union_with_zero_sized_array.h | 5 ++ bindgen/codegen/struct_layout.rs | 7 +- 3 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 bindgen-tests/tests/expectations/tests/union_with_zero_sized_array.rs create mode 100644 bindgen-tests/tests/headers/union_with_zero_sized_array.h diff --git a/bindgen-tests/tests/expectations/tests/union_with_zero_sized_array.rs b/bindgen-tests/tests/expectations/tests/union_with_zero_sized_array.rs new file mode 100644 index 0000000000..aa23fcd734 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/union_with_zero_sized_array.rs @@ -0,0 +1,68 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[repr(C)] +pub struct __BindgenUnionField(::std::marker::PhantomData); +impl __BindgenUnionField { + #[inline] + pub const fn new() -> Self { + __BindgenUnionField(::std::marker::PhantomData) + } + #[inline] + pub unsafe fn as_ref(&self) -> &T { + ::std::mem::transmute(self) + } + #[inline] + pub unsafe fn as_mut(&mut self) -> &mut T { + ::std::mem::transmute(self) + } +} +impl ::std::default::Default for __BindgenUnionField { + #[inline] + fn default() -> Self { + Self::new() + } +} +impl ::std::clone::Clone for __BindgenUnionField { + #[inline] + fn clone(&self) -> Self { + *self + } +} +impl ::std::marker::Copy for __BindgenUnionField {} +impl ::std::fmt::Debug for __BindgenUnionField { + fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + fmt.write_str("__BindgenUnionField") + } +} +impl ::std::hash::Hash for __BindgenUnionField { + fn hash(&self, _state: &mut H) {} +} +impl ::std::cmp::PartialEq for __BindgenUnionField { + fn eq(&self, _other: &__BindgenUnionField) -> bool { + true + } +} +impl ::std::cmp::Eq for __BindgenUnionField {} +#[repr(C)] +pub struct U { + pub d0: __BindgenUnionField<[::std::os::raw::c_char; 0usize]>, + pub d1: __BindgenUnionField<[::std::os::raw::c_char; 1usize]>, + pub d2: __BindgenUnionField<[::std::os::raw::c_char; 2usize]>, + pub bindgen_union_field: [u8; 2usize], +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of U"][::std::mem::size_of::() - 2usize]; + ["Alignment of U"][::std::mem::align_of::() - 1usize]; + ["Offset of field: U::d0"][::std::mem::offset_of!(U, d0) - 0usize]; + ["Offset of field: U::d1"][::std::mem::offset_of!(U, d1) - 0usize]; + ["Offset of field: U::d2"][::std::mem::offset_of!(U, d2) - 0usize]; +}; +impl Default for U { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} diff --git a/bindgen-tests/tests/headers/union_with_zero_sized_array.h b/bindgen-tests/tests/headers/union_with_zero_sized_array.h new file mode 100644 index 0000000000..ace745f26c --- /dev/null +++ b/bindgen-tests/tests/headers/union_with_zero_sized_array.h @@ -0,0 +1,5 @@ +union U { + char d0[0]; + char d1[1]; + char d2[2]; +}; diff --git a/bindgen/codegen/struct_layout.rs b/bindgen/codegen/struct_layout.rs index f7f66373fb..0d97b8cc20 100644 --- a/bindgen/codegen/struct_layout.rs +++ b/bindgen/codegen/struct_layout.rs @@ -266,7 +266,12 @@ impl<'a> StructLayoutTracker<'a> { } }; - self.latest_offset += field_layout.size; + if !is_union { + self.latest_offset += field_layout.size; + } else { + self.latest_offset = + cmp::max(self.latest_offset, field_layout.size); + } self.latest_field_layout = Some(field_layout); self.max_field_align = cmp::max(self.max_field_align, field_layout.align); From 7eb87dbed4b0f8452efd3bb3cbc67338c5d4724f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Fri, 4 Apr 2025 16:06:34 +0200 Subject: [PATCH 880/942] ci: Re-enable rust for linux test. * Downgrade the rust toolchain for now to keep CI green. * Enable verbose kbuild. --- .github/workflows/bindgen.yml | 6 +++--- ci/test.sh | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index d0112e367f..97cbac794f 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -18,7 +18,7 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Install stable + - name: Install nightly uses: dtolnay/rust-toolchain@master with: # TODO: Should ideally be stable, but we use some nightly-only @@ -154,7 +154,7 @@ jobs: - name: Install stable uses: dtolnay/rust-toolchain@master with: - toolchain: stable + toolchain: 1.85.1 - name: Install libtinfo if: matrix.os == 'ubuntu-latest' run: | @@ -171,7 +171,7 @@ jobs: BINDGEN_FEATURE_RUNTIME: ${{matrix.feature_runtime}} BINDGEN_FEATURE_EXTRA_ASSERTS: ${{matrix.feature_extra_asserts}} BINDGEN_NO_DEFAULT_FEATURES: ${{matrix.no_default_features}} - BINDGEN_RUST_FOR_LINUX_TEST: 0 + BINDGEN_RUST_FOR_LINUX_TEST: ${{matrix.os == 'ubuntu-latest' && matrix.llvm_version == '16.0' && matrix.feature_extra_asserts == 0 && 1 || 0}} run: ./ci/test.sh check-cfg: diff --git a/ci/test.sh b/ci/test.sh index 93bc9c2823..1edd37b3d0 100755 --- a/ci/test.sh +++ b/ci/test.sh @@ -96,7 +96,7 @@ if [ "$BINDGEN_RUST_FOR_LINUX_TEST" == "1" ]; then # and each update should only contain this change. # # Both commit hashes and tags are supported. - LINUX_VERSION=v6.13-rc1 + LINUX_VERSION=v6.14-rc1 # Download Linux at a specific commit mkdir -p linux @@ -125,13 +125,13 @@ CONFIG_KUNIT=y CONFIG_RUST_KERNEL_DOCTESTS=y EOF - make -C linux LLVM=1 -j$(($(nproc) + 1)) \ + make -C linux KBUILD_VERBOSE=1 LLVM=1 -j$(($(nproc) + 1)) \ rustavailable \ defconfig \ rfl-for-bindgen-ci.config # Build Rust for Linux - make -C linux LLVM=1 -j$(($(nproc) + 1)) \ + make -C linux LLVM=1 KBUILD_VERBOSE=1 -j$(($(nproc) + 1)) \ samples/rust/rust_minimal.o \ samples/rust/rust_print_main.o \ drivers/net/phy/ax88796b_rust.o From adeba9e7a502c16902757ff1e389c52529d83e90 Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Fri, 4 Apr 2025 23:24:27 +0200 Subject: [PATCH 881/942] ci: move forward Rust for Linux version to v6.14 v6.14 is the latest tag and it contains v6.14-rc2 which included the fix for the `soft-float` error (commit 6273a058383e ("x86: rust: set rustc-abi=x86-softfloat on rustc>=1.86.0") in Linux). Signed-off-by: Miguel Ojeda --- ci/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/test.sh b/ci/test.sh index 1edd37b3d0..8cc2b511e0 100755 --- a/ci/test.sh +++ b/ci/test.sh @@ -96,7 +96,7 @@ if [ "$BINDGEN_RUST_FOR_LINUX_TEST" == "1" ]; then # and each update should only contain this change. # # Both commit hashes and tags are supported. - LINUX_VERSION=v6.14-rc1 + LINUX_VERSION=v6.14 # Download Linux at a specific commit mkdir -p linux From e098882ca416721778214ed536d76005760aafad Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Fri, 4 Apr 2025 23:25:28 +0200 Subject: [PATCH 882/942] ci: use stable toolchain again Now that the Rust for Linux job is moved forward to v6.14, we can use Rust 1.86.0, i.e. the current stable, again. Thus revert the previous change. Signed-off-by: Miguel Ojeda --- .github/workflows/bindgen.yml | 2 +- ci/test.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 97cbac794f..3a90263bd0 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -154,7 +154,7 @@ jobs: - name: Install stable uses: dtolnay/rust-toolchain@master with: - toolchain: 1.85.1 + toolchain: stable - name: Install libtinfo if: matrix.os == 'ubuntu-latest' run: | diff --git a/ci/test.sh b/ci/test.sh index 8cc2b511e0..ae93f2ad1d 100755 --- a/ci/test.sh +++ b/ci/test.sh @@ -125,13 +125,13 @@ CONFIG_KUNIT=y CONFIG_RUST_KERNEL_DOCTESTS=y EOF - make -C linux KBUILD_VERBOSE=1 LLVM=1 -j$(($(nproc) + 1)) \ + make -C linux LLVM=1 -j$(($(nproc) + 1)) \ rustavailable \ defconfig \ rfl-for-bindgen-ci.config # Build Rust for Linux - make -C linux LLVM=1 KBUILD_VERBOSE=1 -j$(($(nproc) + 1)) \ + make -C linux LLVM=1 -j$(($(nproc) + 1)) \ samples/rust/rust_minimal.o \ samples/rust/rust_print_main.o \ drivers/net/phy/ax88796b_rust.o From 5fcf09f501cf394f646788f95fd1b3aadc6cc6e0 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Sat, 1 Feb 2025 17:54:39 -0500 Subject: [PATCH 883/942] chore: fix new clippy lints, enforce in CI --- .github/workflows/bindgen.yml | 10 +--------- bindgen-tests/build.rs | 2 +- bindgen/ir/dot.rs | 2 +- bindgen/lib.rs | 2 +- 4 files changed, 4 insertions(+), 12 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 3a90263bd0..4e8f94c5b7 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -18,19 +18,11 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Install nightly - uses: dtolnay/rust-toolchain@master - with: - # TODO: Should ideally be stable, but we use some nightly-only - # features. - toolchain: nightly - components: rustfmt, clippy - - name: Run rustfmt run: cargo fmt -- --check - name: Run clippy - run: cargo clippy --all-targets --workspace --exclude bindgen-integration --exclude tests_expectations + run: cargo clippy --all-targets --workspace --exclude bindgen-integration --exclude tests_expectations -- -D warnings msrv: runs-on: ubuntu-latest diff --git a/bindgen-tests/build.rs b/bindgen-tests/build.rs index b261ed0a35..8fb33716a1 100644 --- a/bindgen-tests/build.rs +++ b/bindgen-tests/build.rs @@ -23,7 +23,7 @@ pub fn main() { for entry in entries { // TODO: file_is_cpp() in bindgen/lib.rs checks for hpp,hxx,hh, and h++ - should this be consistent? - if entry.path().extension().map_or(false, |ext| { + if entry.path().extension().is_some_and(|ext| { ext.eq_ignore_ascii_case("h") || ext.eq_ignore_ascii_case("hpp") }) { let func = entry diff --git a/bindgen/ir/dot.rs b/bindgen/ir/dot.rs index 0ccee42c0d..9bfc559f41 100644 --- a/bindgen/ir/dot.rs +++ b/bindgen/ir/dot.rs @@ -41,7 +41,7 @@ where if is_allowlisted { "black" } else { "gray" } )?; item.dot_attributes(ctx, &mut dot_file)?; - writeln!(&mut dot_file, r#"
mangled name{}
mangled name{mangled}
mangled name{}
mangled name{mangled}
>];"#)?; + writeln!(&mut dot_file, " >];")?; item.trace( ctx, diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 5a946e6d13..5423f00495 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -86,7 +86,7 @@ pub const DEFAULT_ANON_FIELDS_PREFIX: &str = "__bindgen_anon_"; const DEFAULT_NON_EXTERN_FNS_SUFFIX: &str = "__extern"; fn file_is_cpp(name_file: &str) -> bool { - Path::new(name_file).extension().map_or(false, |ext| { + Path::new(name_file).extension().is_some_and(|ext| { ext.eq_ignore_ascii_case("hpp") || ext.eq_ignore_ascii_case("hxx") || ext.eq_ignore_ascii_case("hh") || From bc00cd0bc12e3bc781bf125aa54941059343068c Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Sat, 1 Feb 2025 18:28:01 -0500 Subject: [PATCH 884/942] remove check-cfg, separate clippy from nightly --- .github/workflows/bindgen.yml | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 4e8f94c5b7..94022c21e1 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -12,14 +12,24 @@ on: - main jobs: - rustfmt-clippy: + rustfmt: runs-on: ubuntu-latest - steps: - uses: actions/checkout@v4 + - name: Install nightly + uses: dtolnay/rust-toolchain@master + with: + toolchain: nightly + components: rustfmt + - name: Run rustfmt - run: cargo fmt -- --check + run: cargo +nightly fmt -- --check + + clippy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 - name: Run clippy run: cargo clippy --all-targets --workspace --exclude bindgen-integration --exclude tests_expectations -- -D warnings @@ -166,21 +176,6 @@ jobs: BINDGEN_RUST_FOR_LINUX_TEST: ${{matrix.os == 'ubuntu-latest' && matrix.llvm_version == '16.0' && matrix.feature_extra_asserts == 0 && 1 || 0}} run: ./ci/test.sh - check-cfg: - runs-on: ubuntu-latest - env: - RUSTFLAGS: -D warnings - steps: - - uses: actions/checkout@v4 - - - name: Install nightly - uses: dtolnay/rust-toolchain@master - with: - toolchain: nightly - - - name: Check cfg - run: cargo check -Z unstable-options -Z check-cfg - test-book: runs-on: ubuntu-latest steps: @@ -213,7 +208,7 @@ jobs: # separately. success: runs-on: ubuntu-latest - needs: [rustfmt-clippy, msrv, minimal, docs, quickchecking, test-expectations, test, check-cfg, test-book, test-no-headers] + needs: [rustfmt, clippy, msrv, minimal, docs, quickchecking, test-expectations, test, test-book, test-no-headers] # GitHub branch protection is exceedingly silly and treats "jobs skipped # because a dependency failed" as success. So we have to do some # contortions to ensure the job fails if any of its dependencies fails. From 3b48e6bd0fc6510cb063e35a6f8a491e4ba4cac4 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Sat, 1 Feb 2025 18:31:05 -0500 Subject: [PATCH 885/942] remove stable rust installation --- .github/workflows/bindgen.yml | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 94022c21e1..1778de1d2b 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -66,12 +66,7 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Install stable - uses: dtolnay/rust-toolchain@master - with: - toolchain: stable - - - name: Check without default features + - name: Check without default features run: cargo check -p bindgen --no-default-features --features=runtime docs: @@ -81,12 +76,7 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Install stable - uses: dtolnay/rust-toolchain@master - with: - toolchain: stable - - - name: Generate documentation for `bindgen` + - name: Generate documentation for `bindgen` run: cargo doc --document-private-items --no-deps -p bindgen - name: Generate documentation for `bindgen-cli` @@ -97,11 +87,6 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Install stable - uses: dtolnay/rust-toolchain@master - with: - toolchain: stable - # TODO: Actually run quickchecks once `bindgen` is reliable enough. - name: Build quickcheck tests run: cd bindgen-tests/tests/quickchecking && cargo test @@ -114,11 +99,6 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Install stable - uses: dtolnay/rust-toolchain@master - with: - toolchain: stable - - name: Test expectations run: cd bindgen-tests/tests/expectations && cargo test From 9315a49a487077d4e4fcac751ca75b7443b827a3 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Sun, 2 Feb 2025 20:32:47 -0500 Subject: [PATCH 886/942] another minor clippy lint --- bindgen/codegen/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 13c0b60526..1d5796b4b4 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -4729,7 +4729,7 @@ impl CodeGenerator for Function { mangled_name, Some(abi), )) - .then(|| mangled_name) + .then_some(mangled_name) }); if let Some(link_name) = link_name_attr { From 8777ea8aa77118446cb7852926e58f3bacc36b0b Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Tue, 11 Feb 2025 13:19:49 -0500 Subject: [PATCH 887/942] fix clippy issues --- bindgen/ir/context.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index 99c75d63d8..37f8d5968d 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -2108,13 +2108,13 @@ If you encounter an error missing from this list, please file an issue or a PR!" pch.clone().into_boxed_str(), ]; let mut skip_next = false; - for arg in self.options.fallback_clang_args.iter() { + for arg in &self.options.fallback_clang_args { if arg.as_ref() == "-include" { skip_next = true; } else if skip_next { skip_next = false; } else { - c_args.push(arg.clone()) + c_args.push(arg.clone()); } } self.fallback_tu = From 97ab9152b5edb1fda1ced9bc1604f5e4dc9cfaa9 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Wed, 9 Apr 2025 16:15:14 -0400 Subject: [PATCH 888/942] fix all clippy lints --- .../item_discovery_callback/mod.rs | 8 ++--- .../tests/quickchecking/src/fuzzers.rs | 30 +++++++++---------- bindgen-tests/tests/tests.rs | 6 ++-- bindgen/codegen/mod.rs | 12 ++++---- bindgen/codegen/serialize.rs | 4 +-- bindgen/codegen/struct_layout.rs | 6 ++-- bindgen/ir/analysis/derive.rs | 4 +-- bindgen/ir/comp.rs | 2 +- bindgen/ir/context.rs | 4 +-- bindgen/ir/item.rs | 4 +-- bindgen/lib.rs | 6 ++-- 11 files changed, 42 insertions(+), 44 deletions(-) diff --git a/bindgen-tests/tests/parse_callbacks/item_discovery_callback/mod.rs b/bindgen-tests/tests/parse_callbacks/item_discovery_callback/mod.rs index 645235b254..6a6d0149f5 100644 --- a/bindgen-tests/tests/parse_callbacks/item_discovery_callback/mod.rs +++ b/bindgen-tests/tests/parse_callbacks/item_discovery_callback/mod.rs @@ -20,7 +20,7 @@ impl ParseCallbacks for ItemDiscovery { fn test_item_discovery_callback( header: &str, - expected: HashMap, + expected: &HashMap, ) { let discovery = ItemDiscovery::default(); let info = Rc::clone(&discovery.0); @@ -34,7 +34,7 @@ fn test_item_discovery_callback( .generate() .expect("TODO: panic message"); - compare_item_caches(&info.borrow(), &expected); + compare_item_caches(&info.borrow(), expected); } #[test] @@ -103,7 +103,7 @@ fn test_item_discovery_callback_c() { ), ]); test_item_discovery_callback( - "/tests/parse_callbacks/item_discovery_callback/header_item_discovery.h", expected); + "/tests/parse_callbacks/item_discovery_callback/header_item_discovery.h", &expected); } #[test] @@ -125,7 +125,7 @@ fn test_item_discovery_callback_cpp() { ), ]); test_item_discovery_callback( - "/tests/parse_callbacks/item_discovery_callback/header_item_discovery.hpp", expected); + "/tests/parse_callbacks/item_discovery_callback/header_item_discovery.hpp", &expected); } pub fn compare_item_caches(generated: &ItemCache, expected: &ItemCache) { diff --git a/bindgen-tests/tests/quickchecking/src/fuzzers.rs b/bindgen-tests/tests/quickchecking/src/fuzzers.rs index eea0393239..176636f66f 100644 --- a/bindgen-tests/tests/quickchecking/src/fuzzers.rs +++ b/bindgen-tests/tests/quickchecking/src/fuzzers.rs @@ -1,5 +1,6 @@ use quickcheck::{Arbitrary, Gen}; use std::fmt; +use std::fmt::Write as _; /// `BaseTypeC` is used in generation of C headers to represent the C language's /// primitive types as well as `void*`. @@ -223,11 +224,10 @@ impl Arbitrary for DeclarationListC { /// Enables to string and format for `DeclarationListC` types. impl fmt::Display for DeclarationListC { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let mut display = String::new(); for decl in &self.decls { - display += &format!("{decl}"); + write!(f, "{decl}")?; } - write!(f, "{display}") + Ok(()) } } @@ -330,7 +330,7 @@ impl Arbitrary for ArrayDimensionC { for _ in 1..dimensions { // 16 is an arbitrary "not too big" number for capping array size. - def += &format!("[{}]", gen_range(g, lower_bound, 16)); + let _ = write!(def, "[{}]", gen_range(g, lower_bound, 16)); } ArrayDimensionC { def } } @@ -347,7 +347,7 @@ impl fmt::Display for ArrayDimensionC { /// identifiers unique. impl MakeUnique for BasicTypeDeclarationC { fn make_unique(&mut self, stamp: usize) { - self.ident_id += &format!("_{stamp}"); + let _ = write!(self.ident_id, "_{stamp}"); } } @@ -384,7 +384,7 @@ impl fmt::Display for BasicTypeDeclarationC { /// identifiers unique. impl MakeUnique for StructDeclarationC { fn make_unique(&mut self, stamp: usize) { - self.ident_id += &format!("_{stamp}"); + let _ = write!(self.ident_id, "_{stamp}"); } } @@ -432,7 +432,7 @@ impl fmt::Display for StructDeclarationC { /// identifiers unique. impl MakeUnique for UnionDeclarationC { fn make_unique(&mut self, stamp: usize) { - self.ident_id += &format!("_{stamp}"); + let _ = write!(self.ident_id, "_{stamp}"); } } @@ -480,7 +480,7 @@ impl fmt::Display for UnionDeclarationC { /// `FunctionPointerDeclarationC` identifiers unique. impl MakeUnique for FunctionPointerDeclarationC { fn make_unique(&mut self, stamp: usize) { - self.ident_id += &format!("_{stamp}"); + let _ = write!(self.ident_id, "_{stamp}"); } } @@ -517,7 +517,7 @@ impl fmt::Display for FunctionPointerDeclarationC { /// identifiers unique. impl MakeUnique for FunctionPrototypeC { fn make_unique(&mut self, stamp: usize) { - self.ident_id += &format!("_{stamp}"); + let _ = write!(self.ident_id, "_{stamp}"); } } @@ -586,14 +586,13 @@ impl Arbitrary for ParameterListC { /// Enables to string and format for `ParameterListC` types. impl fmt::Display for ParameterListC { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let mut display = String::new(); for (i, p) in self.params.iter().enumerate() { match i { - 0 => display += &format!("{p}"), - _ => display += &format!(",{p}"), + 0 => write!(f, "{p}")?, + _ => write!(f, ",{p}")?, } } - write!(f, "{display}") + Ok(()) } } @@ -612,11 +611,10 @@ impl Arbitrary for HeaderC { /// Enables to string and format for `HeaderC` types. impl fmt::Display for HeaderC { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let mut display = String::new(); for decl in &self.def.decls { - display += &format!("{decl}"); + write!(f, "{decl}")?; } - write!(f, "{display}") + Ok(()) } } diff --git a/bindgen-tests/tests/tests.rs b/bindgen-tests/tests/tests.rs index b808dfcd43..3cc7cbe415 100644 --- a/bindgen-tests/tests/tests.rs +++ b/bindgen-tests/tests/tests.rs @@ -27,7 +27,7 @@ fn should_overwrite_expected() -> bool { return true; } assert!( - var == "0" || var == "", + var == "0" || var.is_empty(), "Invalid value of BINDGEN_OVERWRITE_EXPECTED" ); } @@ -57,7 +57,7 @@ fn error_diff_mismatch( if let Some(var) = env::var_os("BINDGEN_TESTS_DIFFTOOL") { //usecase: var = "meld" -> You can hand check differences let Some(std::path::Component::Normal(name)) = - filename.components().last() + filename.components().next_back() else { panic!("Why is the header variable so weird?") }; @@ -187,7 +187,7 @@ fn compare_generated_header( header.display(), looked_at, ), - }; + } let (builder, roundtrip_builder) = builder.into_builder(check_roundtrip)?; diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 1d5796b4b4..8da10ff051 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -3075,7 +3075,7 @@ impl Method { parent: parent_id, final_name: name.clone(), }, - ) + ); }); let mut function_name = function_item.canonical_name(ctx); @@ -3138,7 +3138,7 @@ impl Method { exprs[0] = quote! { self }; - }; + } let call = quote! { #function_name (#( #exprs ),* ) @@ -3282,7 +3282,7 @@ impl FromStr for EnumVariation { struct EnumBuilder { /// Type identifier of the enum. /// - /// This is the base name, i.e. for ModuleConst enums, this does not include the module name. + /// This is the base name, i.e. for `ModuleConst` enums, this does not include the module name. enum_type: Ident, /// Attributes applying to the enum type attrs: Vec, @@ -3453,7 +3453,7 @@ impl EnumBuilder { } fn newtype_bitfield_impl( - prefix: Ident, + prefix: &Ident, rust_ty: &syn::Type, ) -> proc_macro2::TokenStream { let rust_ty_name = &rust_ty; @@ -3593,7 +3593,7 @@ impl EnumBuilder { let prefix = ctx.trait_prefix(); let bitfield_impl_opt = is_bitfield - .then(|| Self::newtype_bitfield_impl(prefix, rust_ty)); + .then(|| Self::newtype_bitfield_impl(&prefix, rust_ty)); quote! { // Previously variant impls where before the enum definition. @@ -4625,7 +4625,7 @@ impl CodeGenerator for Function { FunctionKind::Method(ref method_kind) => { method_kind.is_pure_virtual() } - _ => false, + FunctionKind::Function => false, }; if is_pure_virtual && !ctx.options().generate_pure_virtual_functions { // Pure virtual methods have no actual symbol, so we can't generate diff --git a/bindgen/codegen/serialize.rs b/bindgen/codegen/serialize.rs index c7bb6cecef..9af48aa8ff 100644 --- a/bindgen/codegen/serialize.rs +++ b/bindgen/codegen/serialize.rs @@ -368,7 +368,7 @@ impl<'a> CSerialize<'a> for Type { match comp_info.kind() { CompKind::Struct => write!(writer, "struct {name}")?, CompKind::Union => write!(writer, "union {name}")?, - }; + } } TypeKind::Enum(_enum_ty) => { if self.is_const() { @@ -384,7 +384,7 @@ impl<'a> CSerialize<'a> for Type { loc: get_loc(item), }) } - }; + } if !stack.is_empty() { write!(writer, " ")?; diff --git a/bindgen/codegen/struct_layout.rs b/bindgen/codegen/struct_layout.rs index 0d97b8cc20..0d2e6a05c5 100644 --- a/bindgen/codegen/struct_layout.rs +++ b/bindgen/codegen/struct_layout.rs @@ -266,11 +266,11 @@ impl<'a> StructLayoutTracker<'a> { } }; - if !is_union { - self.latest_offset += field_layout.size; - } else { + if is_union { self.latest_offset = cmp::max(self.latest_offset, field_layout.size); + } else { + self.latest_offset += field_layout.size; } self.latest_field_layout = Some(field_layout); self.max_field_align = diff --git a/bindgen/ir/analysis/derive.rs b/bindgen/ir/analysis/derive.rs index 6c66998bee..eaa20fff46 100644 --- a/bindgen/ir/analysis/derive.rs +++ b/bindgen/ir/analysis/derive.rs @@ -197,7 +197,7 @@ impl CannotDerive<'_> { self.derive_trait ); } - }; + } return layout_can_derive; } @@ -355,7 +355,7 @@ impl CannotDerive<'_> { self.derive_trait ); } - }; + } return layout_can_derive; } } diff --git a/bindgen/ir/comp.rs b/bindgen/ir/comp.rs index 15f9cb4655..655e0f1fa5 100644 --- a/bindgen/ir/comp.rs +++ b/bindgen/ir/comp.rs @@ -1855,7 +1855,7 @@ impl IsOpaque for CompInfo { // 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.map_or(false, |l| l.align > 1) + 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 \ diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index 37f8d5968d..3f9e16ac9b 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -931,7 +931,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" *ty.kind() { typerefs.push((id, *ty, loc, parent_id)); - }; + } } typerefs } @@ -3076,7 +3076,7 @@ impl TemplateParameters for PartialType { num_params += 1; } _ => {} - }; + } clang_sys::CXChildVisit_Continue }); num_params diff --git a/bindgen/ir/item.rs b/bindgen/ir/item.rs index 8b0d24cd04..25c3c258aa 100644 --- a/bindgen/ir/item.rs +++ b/bindgen/ir/item.rs @@ -727,7 +727,7 @@ impl Item { to.push_str(&self.canonical_name(ctx)); if let ItemKind::Type(ref ty) = *self.kind() { if let TypeKind::TemplateInstantiation(ref inst) = *ty.kind() { - to.push_str(&format!("_open{level}_")); + let _ = write!(to, "_open{level}_"); for arg in inst.template_arguments() { arg.into_resolver() .through_type_refs() @@ -735,7 +735,7 @@ impl Item { .push_disambiguated_name(ctx, to, level + 1); to.push('_'); } - to.push_str(&format!("close{level}")); + let _ = write!(to, "close{level}"); } } } diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 5423f00495..12ac8a2998 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -575,7 +575,7 @@ impl BindgenOptions { self.parse_callbacks .iter() .filter_map(|cb| f(cb.as_ref())) - .last() + .next_back() } fn all_callbacks( @@ -796,7 +796,7 @@ impl Bindings { 0, format!("--target={effective_target}").into_boxed_str(), ); - }; + } fn detect_include_paths(options: &mut BindgenOptions) { if !options.detect_include_paths { @@ -1209,7 +1209,7 @@ pub fn clang_version() -> ClangVersion { }; } } - }; + } ClangVersion { parsed: None, full: raw_v.clone(), From 763c8b956808c850660c521059d4588bf4be05df Mon Sep 17 00:00:00 2001 From: David Cosby Date: Fri, 23 May 2025 13:41:06 -0700 Subject: [PATCH 889/942] Resolved unenclosed backticks for with_derive_custom_enum, with_attribute_custon_enum --- bindgen/options/cli.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bindgen/options/cli.rs b/bindgen/options/cli.rs index d3cf5d0916..bce7faed35 100644 --- a/bindgen/options/cli.rs +++ b/bindgen/options/cli.rs @@ -480,7 +480,7 @@ struct BindgenCommand { /// Derive custom traits on a `struct`. The CUSTOM value must be of the shape REGEX=DERIVE where DERIVE is a coma-separated list of derive macros. #[arg(long, value_name = "CUSTOM", value_parser = parse_custom_derive)] with_derive_custom_struct: Vec<(Vec, String)>, - /// Derive custom traits on an `enum. The CUSTOM value must be of the shape REGEX=DERIVE where DERIVE is a coma-separated list of derive macros. + /// Derive custom traits on an `enum`. The CUSTOM value must be of the shape REGEX=DERIVE where DERIVE is a coma-separated list of derive macros. #[arg(long, value_name = "CUSTOM", value_parser = parse_custom_derive)] with_derive_custom_enum: Vec<(Vec, String)>, /// Derive custom traits on a `union`. The CUSTOM value must be of the shape REGEX=DERIVE where DERIVE is a coma-separated list of derive macros. @@ -492,7 +492,7 @@ struct BindgenCommand { /// Add custom attributes on a `struct`. The CUSTOM value must be of the shape REGEX=ATTRIBUTE where ATTRIBUTE is a coma-separated list of attributes. #[arg(long, value_name = "CUSTOM", value_parser = parse_custom_attribute)] with_attribute_custom_struct: Vec<(Vec, String)>, - /// Add custom attributes on an `enum. The CUSTOM value must be of the shape REGEX=ATTRIBUTE where ATTRIBUTE is a coma-separated list of attributes. + /// Add custom attributes on an `enum`. The CUSTOM value must be of the shape REGEX=ATTRIBUTE where ATTRIBUTE is a coma-separated list of attributes. #[arg(long, value_name = "CUSTOM", value_parser = parse_custom_attribute)] with_attribute_custom_enum: Vec<(Vec, String)>, /// Add custom attributes on a `union`. The CUSTOM value must be of the shape REGEX=ATTRIBUTE where ATTRIBUTE is a coma-separated list of attributes. From 058c8f26e4e13c279ba1d67ea9cf0e4b9294f391 Mon Sep 17 00:00:00 2001 From: Niklas Dusenlund Date: Sat, 7 Jun 2025 10:49:40 +0200 Subject: [PATCH 890/942] ci/release: Ubuntu 20.04 being sunset Replace 20.04 with latest --- .github/workflows/release.yml | 8 ++++---- dist-workspace.toml | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5df0c7b1c1..071214f8d1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -47,7 +47,7 @@ on: jobs: # Run 'cargo dist plan' (or host) to determine what tasks we need to do plan: - runs-on: "ubuntu-20.04" + runs-on: "ubuntu-22.04" outputs: val: ${{ steps.plan.outputs.manifest }} tag: ${{ !github.event.pull_request && github.ref_name || '' }} @@ -160,7 +160,7 @@ jobs: needs: - plan - build-local-artifacts - runs-on: "ubuntu-20.04" + runs-on: "ubuntu-22.04" env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} BUILD_MANIFEST_NAME: target/distrib/global-dist-manifest.json @@ -210,7 +210,7 @@ jobs: if: ${{ always() && needs.plan.outputs.publishing == 'true' && (needs.build-global-artifacts.result == 'skipped' || needs.build-global-artifacts.result == 'success') && (needs.build-local-artifacts.result == 'skipped' || needs.build-local-artifacts.result == 'success') }} env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - runs-on: "ubuntu-20.04" + runs-on: "ubuntu-22.04" outputs: val: ${{ steps.host.outputs.manifest }} steps: @@ -274,7 +274,7 @@ jobs: # still allowing individual publish jobs to skip themselves (for prereleases). # "host" however must run to completion, no skipping allowed! if: ${{ always() && needs.host.result == 'success' }} - runs-on: "ubuntu-20.04" + runs-on: "ubuntu-22.04" env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: diff --git a/dist-workspace.toml b/dist-workspace.toml index 3a0f7c2c75..60a8c51fca 100644 --- a/dist-workspace.toml +++ b/dist-workspace.toml @@ -21,5 +21,6 @@ install-updater = false install-path = "CARGO_HOME" [dist.github-custom-runners] +global = "ubuntu-22.04" aarch64-apple-darwin = "macos-14" x86_64-apple-darwin = "macos-13" From 5155cfeba34cbd49abcd524e1afab4bf41a3d58a Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 25 Apr 2025 16:29:07 -0700 Subject: [PATCH 891/942] Generate bindings compatible with current rustc version by default --- bindgen/features.rs | 60 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/bindgen/features.rs b/bindgen/features.rs index 5864b88f42..45ea893947 100644 --- a/bindgen/features.rs +++ b/bindgen/features.rs @@ -48,6 +48,66 @@ impl RustTarget { impl Default for RustTarget { fn default() -> Self { + // Bindgen from build script: default to generating bindings compatible + // with the Rust version currently performing this build. + #[cfg(not(feature = "__cli"))] + { + use std::env; + use std::iter; + use std::process::Command; + use std::sync::OnceLock; + + static CURRENT_RUST: OnceLock> = OnceLock::new(); + + if let Some(current_rust) = *CURRENT_RUST.get_or_init(|| { + let is_build_script = + env::var_os("CARGO_CFG_TARGET_ARCH").is_some(); + if !is_build_script { + return None; + } + + let rustc = env::var_os("RUSTC")?; + let rustc_wrapper = env::var_os("RUSTC_WRAPPER") + .filter(|wrapper| !wrapper.is_empty()); + let wrapped_rustc = + rustc_wrapper.iter().chain(iter::once(&rustc)); + + let mut is_clippy_driver = false; + loop { + let mut wrapped_rustc = wrapped_rustc.clone(); + let mut command = + Command::new(wrapped_rustc.next().unwrap()); + command.args(wrapped_rustc); + if is_clippy_driver { + command.arg("--rustc"); + } + command.arg("--version"); + + let output = command.output().ok()?; + let string = String::from_utf8(output.stdout).ok()?; + + // Version string like "rustc 1.100.0-beta.5 (f0e1d2c3b 2026-10-17)" + let last_line = string.lines().last().unwrap_or(&string); + let (program, rest) = last_line.trim().split_once(' ')?; + if program != "rustc" { + if program.starts_with("clippy") && !is_clippy_driver { + is_clippy_driver = true; + continue; + } + return None; + } + + let number = rest.split([' ', '-', '+']).next()?; + break RustTarget::from_str(number).ok(); + } + }) { + return current_rust; + } + } + + // Bindgen from CLI, or cannot determine compiler version: default to + // generating bindings compatible with the latest stable release of Rust + // that Bindgen knows about. LATEST_STABLE_RUST } } From c6fdf9b84972a5a4ad0790ea20a7ffbb1f7667e7 Mon Sep 17 00:00:00 2001 From: chiichen Date: Sun, 18 May 2025 23:37:45 +0800 Subject: [PATCH 892/942] doc: enhance desc of cpp section --- book/src/cpp.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/src/cpp.md b/book/src/cpp.md index db368f6787..22e9dcf120 100644 --- a/book/src/cpp.md +++ b/book/src/cpp.md @@ -7,7 +7,7 @@ be nowhere near as nice as using them in C++. You will have to manually call constructors, destructors, overloaded operators, etc yourself. When passing in header files, the file will automatically be treated as C++ if -it ends in `.hpp`. If it doesn't, adding `-x c++` clang args can be used to +it ends in `.hpp`. If it doesn't, adding `clang_args(["-x", "c++"])` can be used to force C++ mode. You probably also want to use `-std=c++14` or similar clang args as well. From 8282a904917012ee9ccd1e462a970ce665e1bd74 Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Wed, 9 Apr 2025 16:27:05 +0200 Subject: [PATCH 893/942] ci: Move forward Rust for Linux version to v6.15-rc4 Signed-off-by: Miguel Ojeda --- ci/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/test.sh b/ci/test.sh index ae93f2ad1d..d134004709 100755 --- a/ci/test.sh +++ b/ci/test.sh @@ -96,7 +96,7 @@ if [ "$BINDGEN_RUST_FOR_LINUX_TEST" == "1" ]; then # and each update should only contain this change. # # Both commit hashes and tags are supported. - LINUX_VERSION=v6.14 + LINUX_VERSION=v6.15-rc4 # Download Linux at a specific commit mkdir -p linux From 0a6cf08581c3ef3e5e963d54683af784774d4540 Mon Sep 17 00:00:00 2001 From: Isaac Gelado Date: Fri, 27 Oct 2023 19:55:03 -0700 Subject: [PATCH 894/942] Add callback to modify contents of macro --- bindgen/callbacks.rs | 6 ++++++ bindgen/ir/var.rs | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/bindgen/callbacks.rs b/bindgen/callbacks.rs index cd7bb9773d..d2ef4f1245 100644 --- a/bindgen/callbacks.rs +++ b/bindgen/callbacks.rs @@ -4,6 +4,8 @@ pub use crate::ir::analysis::DeriveTrait; pub use crate::ir::derive::CanDerive as ImplementsTrait; pub use crate::ir::enum_ty::{EnumVariantCustomBehavior, EnumVariantValue}; pub use crate::ir::int::IntKind; +pub use cexpr::token::Kind as TokenKind; +pub use cexpr::token::Token; use std::fmt; /// An enum to allow ignoring parsing of macros. @@ -49,6 +51,10 @@ pub trait ParseCallbacks: fmt::Debug { None } + /// Modify the contents of a macro + fn modify_macro(&self, _name: &str, _tokens: &mut Vec) { + } + /// The integer kind an integer macro should have, given a name and the /// value of that macro, or `None` if you want the default to be chosen. fn int_macro(&self, _name: &str, _value: i64) -> Option { diff --git a/bindgen/ir/var.rs b/bindgen/ir/var.rs index 85e127fdbc..19c454f06b 100644 --- a/bindgen/ir/var.rs +++ b/bindgen/ir/var.rs @@ -429,6 +429,10 @@ fn parse_macro( let cexpr_tokens = cursor.cexpr_tokens(); + if let Some(callbacks) = ctx.parse_callbacks() { + callbacks.modify_macro(cursor.spelling(), &mut cexpr_tokens); + } + let parser = expr::IdentifierParser::new(ctx.parsed_macros()); match parser.macro_definition(&cexpr_tokens) { From 803d73ee09470005ce1a1d02ab559e1c7bd6dac8 Mon Sep 17 00:00:00 2001 From: Isaac Gelado Date: Fri, 27 Oct 2023 19:59:44 -0700 Subject: [PATCH 895/942] Use parse_callbacks from options --- bindgen/ir/var.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindgen/ir/var.rs b/bindgen/ir/var.rs index 19c454f06b..e227a772e7 100644 --- a/bindgen/ir/var.rs +++ b/bindgen/ir/var.rs @@ -429,7 +429,7 @@ fn parse_macro( let cexpr_tokens = cursor.cexpr_tokens(); - if let Some(callbacks) = ctx.parse_callbacks() { + if let Some(callbacks) = ctx.options.parse_callbacks() { callbacks.modify_macro(cursor.spelling(), &mut cexpr_tokens); } From b9c6984739fc76e4e088d4ea567634b8a0be1b73 Mon Sep 17 00:00:00 2001 From: Isaac Gelado Date: Fri, 27 Oct 2023 20:03:12 -0700 Subject: [PATCH 896/942] Use callbacks properly --- bindgen/ir/var.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bindgen/ir/var.rs b/bindgen/ir/var.rs index e227a772e7..45f4ba1ba0 100644 --- a/bindgen/ir/var.rs +++ b/bindgen/ir/var.rs @@ -427,10 +427,10 @@ fn parse_macro( ) -> Option<(Vec, cexpr::expr::EvalResult)> { use cexpr::expr; - let cexpr_tokens = cursor.cexpr_tokens(); + let mut cexpr_tokens = cursor.cexpr_tokens(); - if let Some(callbacks) = ctx.options.parse_callbacks() { - callbacks.modify_macro(cursor.spelling(), &mut cexpr_tokens); + for callbacks in &ctx.options().parse_callbacks { + callbacks.modify_macro(&cursor.spelling(), &mut cexpr_tokens); } let parser = expr::IdentifierParser::new(ctx.parsed_macros()); From 965a13cd6fc0946d4e98bfa36ce792777942fd12 Mon Sep 17 00:00:00 2001 From: Isaac Gelado Date: Fri, 23 May 2025 21:31:18 +0200 Subject: [PATCH 897/942] Add test --- bindgen-integration/build.rs | 50 +++++++++++++++++++++++++++++++--- bindgen-integration/cpp/Test.h | 2 ++ bindgen-integration/src/lib.rs | 6 ++++ 3 files changed, 54 insertions(+), 4 deletions(-) diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs index 583f46ea93..1c37448d77 100644 --- a/bindgen-integration/build.rs +++ b/bindgen-integration/build.rs @@ -1,7 +1,7 @@ extern crate bindgen; use bindgen::callbacks::{ - DeriveInfo, IntKind, MacroParsingBehavior, ParseCallbacks, + DeriveInfo, IntKind, MacroParsingBehavior, ParseCallbacks, Token, TokenKind, }; use bindgen::{Builder, EnumVariation, Formatter}; use std::collections::HashSet; @@ -44,9 +44,9 @@ impl ParseCallbacks for MacroCallback { assert_eq!(value, b"string"); *self.seen_hellos.lock().unwrap() += 1; } - "TESTMACRO_STRING_EXPANDED" | - "TESTMACRO_STRING" | - "TESTMACRO_INTEGER" => { + "TESTMACRO_STRING_EXPANDED" + | "TESTMACRO_STRING" + | "TESTMACRO_INTEGER" => { // The integer test macro is, actually, not expected to show up here at all -- but // should produce an error if it does. assert_eq!( @@ -145,6 +145,48 @@ impl ParseCallbacks for MacroCallback { vec![] } } + + fn modify_macro(&self, _name: &str, tokens: &mut Vec) { + // Handle macros dealing with bit positions of the format HI:LO + if tokens.len() == 4 && tokens[2].kind == TokenKind::Punctuation { + if let Ok(colon) = std::str::from_utf8(&tokens[2].raw) { + if colon != ":" { + return; + } + let high = match std::str::from_utf8(&tokens[1].raw) { + Ok(s) => { + if let Ok(val) = s.parse::() { + val + } else { + return; + } + } + Err(_) => { + return; + } + }; + + let low = match std::str::from_utf8(&tokens[3].raw) { + Ok(s) => { + if let Ok(val) = s.parse::() { + val + } else { + return; + } + } + Err(_) => { + return; + } + }; + let value: u32 = ((high as u32) << 16) | low as u32; + tokens[1] = Token::from(( + TokenKind::Literal, + value.to_string().as_bytes(), + )); + tokens.truncate(2); + } + } + } } impl Drop for MacroCallback { diff --git a/bindgen-integration/cpp/Test.h b/bindgen-integration/cpp/Test.h index 81a921b5f8..7f71210cdd 100644 --- a/bindgen-integration/cpp/Test.h +++ b/bindgen-integration/cpp/Test.h @@ -22,6 +22,8 @@ #define TESTMACRO_STRING_EXPR ("string") #define TESTMACRO_STRING_FUNC_NON_UTF8(x) (x "ᅵᅵ") /* invalid UTF-8 on purpose */ +#define TESTMACRO_COLON_VALUE 1:2 + enum { MY_ANNOYING_MACRO = #define MY_ANNOYING_MACRO 1 diff --git a/bindgen-integration/src/lib.rs b/bindgen-integration/src/lib.rs index 13f5bd889a..64f4926a8b 100755 --- a/bindgen-integration/src/lib.rs +++ b/bindgen-integration/src/lib.rs @@ -345,3 +345,9 @@ fn test_wrap_static_fns() { extern_bindings::wrap_as_variadic_fn2_wrapped(1, 2); } } + +#[test] +fn test_colon_define() { + let gold: u32 = (1u32 << 16) | 2; + assert_eq!(gold, bindings::TESTMACRO_COLON_VALUE); +} From fef156111e6e16e06f68511ee7fe7da69a8b9d97 Mon Sep 17 00:00:00 2001 From: Isaac Gelado Date: Fri, 23 May 2025 21:54:20 +0200 Subject: [PATCH 898/942] Fix rustfmt errors --- bindgen-integration/build.rs | 6 +++--- bindgen/callbacks.rs | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs index 1c37448d77..0d8fa33c93 100644 --- a/bindgen-integration/build.rs +++ b/bindgen-integration/build.rs @@ -44,9 +44,9 @@ impl ParseCallbacks for MacroCallback { assert_eq!(value, b"string"); *self.seen_hellos.lock().unwrap() += 1; } - "TESTMACRO_STRING_EXPANDED" - | "TESTMACRO_STRING" - | "TESTMACRO_INTEGER" => { + "TESTMACRO_STRING_EXPANDED" | + "TESTMACRO_STRING" | + "TESTMACRO_INTEGER" => { // The integer test macro is, actually, not expected to show up here at all -- but // should produce an error if it does. assert_eq!( diff --git a/bindgen/callbacks.rs b/bindgen/callbacks.rs index d2ef4f1245..f7f2f6cc9d 100644 --- a/bindgen/callbacks.rs +++ b/bindgen/callbacks.rs @@ -52,8 +52,7 @@ pub trait ParseCallbacks: fmt::Debug { } /// Modify the contents of a macro - fn modify_macro(&self, _name: &str, _tokens: &mut Vec) { - } + fn modify_macro(&self, _name: &str, _tokens: &mut Vec) {} /// The integer kind an integer macro should have, given a name and the /// value of that macro, or `None` if you want the default to be chosen. From 2613129f1b39cf61e6ad3db7ec7d2a6806ed4fbd Mon Sep 17 00:00:00 2001 From: Foxie Flakey Date: Sat, 12 Apr 2025 11:29:33 +0700 Subject: [PATCH 899/942] Remove unused which-rustfmt feature --- bindgen/Cargo.toml | 2 -- 1 file changed, 2 deletions(-) diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index c01f8f0c44..4e9fe5a4f9 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -47,8 +47,6 @@ default = ["logging", "prettyplease", "runtime"] logging = ["dep:log"] static = ["clang-sys/static"] runtime = ["clang-sys/runtime"] -# This feature is no longer used for anything and should be removed in bindgen 0.70 -which-rustfmt = [] experimental = ["dep:annotate-snippets"] ## The following features are for internal use and they shouldn't be used if From 5d7f6847690f84b6a4bf7b800cb3ae6057c5a207 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 8 Jun 2025 12:07:49 +0200 Subject: [PATCH 900/942] codegen: Avoid crashing on variadic unions without layout information. --- .../expectations/tests/variadic-union.rs | 14 +++++++++++ .../tests/headers/variadic-union.hpp | 3 +++ bindgen/codegen/mod.rs | 23 +++++++++---------- 3 files changed, 28 insertions(+), 12 deletions(-) create mode 100644 bindgen-tests/tests/expectations/tests/variadic-union.rs create mode 100644 bindgen-tests/tests/headers/variadic-union.hpp diff --git a/bindgen-tests/tests/expectations/tests/variadic-union.rs b/bindgen-tests/tests/expectations/tests/variadic-union.rs new file mode 100644 index 0000000000..471c9e7075 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/variadic-union.rs @@ -0,0 +1,14 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[repr(C)] +pub union _Variadic_union { + pub _address: u8, +} +impl Default for _Variadic_union { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} diff --git a/bindgen-tests/tests/headers/variadic-union.hpp b/bindgen-tests/tests/headers/variadic-union.hpp new file mode 100644 index 0000000000..62ed49fcc9 --- /dev/null +++ b/bindgen-tests/tests/headers/variadic-union.hpp @@ -0,0 +1,3 @@ +template union _Variadic_union { + _Variadic_union() = default; +}; diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 8da10ff051..59f2265c09 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -2337,18 +2337,17 @@ impl CodeGenerator for CompInfo { } } } else if is_union && !forward_decl { - // TODO(emilio): It'd be nice to unify this with the struct path - // above somehow. - let layout = layout.expect("Unable to get layout information?"); - if struct_layout.requires_explicit_align(layout) { - explicit_align = Some(layout.align); - } - - if !struct_layout.is_rust_union() { - let ty = helpers::blob(ctx, layout, false); - fields.push(quote! { - pub bindgen_union_field: #ty , - }); + if let Some(layout) = layout { + // TODO(emilio): It'd be nice to unify this with the struct path above somehow. + if struct_layout.requires_explicit_align(layout) { + explicit_align = Some(layout.align); + } + if !struct_layout.is_rust_union() { + let ty = helpers::blob(ctx, layout, false); + fields.push(quote! { + pub bindgen_union_field: #ty , + }); + } } } From e2940cdcc20967799bece79b46682e8acc3bc042 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 8 Jun 2025 12:13:24 +0200 Subject: [PATCH 901/942] chore: Fix some warnings with latest stable. --- bindgen/clang.rs | 4 ++-- bindgen/ir/context.rs | 2 +- bindgen/ir/ty.rs | 2 +- bindgen/lib.rs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bindgen/clang.rs b/bindgen/clang.rs index 04fe3e1538..e52fed0d4a 100644 --- a/bindgen/clang.rs +++ b/bindgen/clang.rs @@ -945,7 +945,7 @@ impl Cursor { } /// Gets the tokens that correspond to that cursor. - pub(crate) fn tokens(&self) -> RawTokens { + pub(crate) fn tokens(&self) -> RawTokens<'_> { RawTokens::new(self) } @@ -1006,7 +1006,7 @@ impl<'a> RawTokens<'a> { } /// Get an iterator over these tokens. - pub(crate) fn iter(&self) -> ClangTokenIterator { + pub(crate) fn iter(&self) -> ClangTokenIterator<'_> { ClangTokenIterator { tu: self.tu, raw: self.as_slice().iter(), diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index 3f9e16ac9b..c0201a114b 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -1228,7 +1228,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" fn assert_no_dangling_item_traversal( &self, - ) -> traversal::AssertNoDanglingItemsTraversal { + ) -> traversal::AssertNoDanglingItemsTraversal<'_> { assert!(self.in_codegen_phase()); assert_eq!(self.current_module, self.root_module); diff --git a/bindgen/ir/ty.rs b/bindgen/ir/ty.rs index baaa4a4907..38a7f6344a 100644 --- a/bindgen/ir/ty.rs +++ b/bindgen/ir/ty.rs @@ -243,7 +243,7 @@ impl Type { } /// Takes `name`, and returns a suitable identifier representation for it. - fn sanitize_name(name: &str) -> Cow { + fn sanitize_name(name: &str) -> Cow<'_, str> { if clang::is_valid_identifier(name) { return Cow::Borrowed(name); } diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 12ac8a2998..b2fecc2c3b 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -980,7 +980,7 @@ impl Bindings { } /// Gets the rustfmt path to rustfmt the generated bindings. - fn rustfmt_path(&self) -> io::Result> { + fn rustfmt_path(&self) -> io::Result> { debug_assert!(matches!(self.options.formatter, Formatter::Rustfmt)); if let Some(ref p) = self.options.rustfmt_path { return Ok(Cow::Borrowed(p)); From 2882af23b05cd29518b414fb4a023544b3ee645b Mon Sep 17 00:00:00 2001 From: Kevin Phoenix Date: Thu, 13 Feb 2025 11:16:31 -0700 Subject: [PATCH 902/942] Refactor item_name method to use ItemInfo struct --- bindgen-integration/build.rs | 15 +++++++++------ bindgen/callbacks.rs | 10 ++++++++-- bindgen/ir/item.rs | 14 +++++++++++++- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs index 0d8fa33c93..ef167775cf 100644 --- a/bindgen-integration/build.rs +++ b/bindgen-integration/build.rs @@ -1,7 +1,8 @@ extern crate bindgen; use bindgen::callbacks::{ - DeriveInfo, IntKind, MacroParsingBehavior, ParseCallbacks, Token, TokenKind, + DeriveInfo, IntKind, ItemInfo, MacroParsingBehavior, ParseCallbacks, Token, + TokenKind, }; use bindgen::{Builder, EnumVariation, Formatter}; use std::collections::HashSet; @@ -103,16 +104,18 @@ impl ParseCallbacks for MacroCallback { } } - fn item_name(&self, original_item_name: &str) -> Option { - if original_item_name.starts_with("my_prefixed_") { + fn item_name(&self, item_info: ItemInfo) -> Option { + if item_info.name.starts_with("my_prefixed_") { Some( - original_item_name + item_info + .name .trim_start_matches("my_prefixed_") .to_string(), ) - } else if original_item_name.starts_with("MY_PREFIXED_") { + } else if item_info.name.starts_with("MY_PREFIXED_") { Some( - original_item_name + item_info + .name .trim_start_matches("MY_PREFIXED_") .to_string(), ) diff --git a/bindgen/callbacks.rs b/bindgen/callbacks.rs index f7f2f6cc9d..93005ce8e5 100644 --- a/bindgen/callbacks.rs +++ b/bindgen/callbacks.rs @@ -94,8 +94,8 @@ pub trait ParseCallbacks: fmt::Debug { None } - /// Allows to rename an item, replacing `_original_item_name`. - fn item_name(&self, _original_item_name: &str) -> Option { + /// Allows to rename an item, replacing `_item_info.name`. + fn item_name(&self, _item_info: ItemInfo) -> Option { None } @@ -280,6 +280,7 @@ pub enum TypeKind { } /// A struct providing information about the item being passed to [`ParseCallbacks::generated_name_override`]. +#[derive(Clone, Copy)] #[non_exhaustive] pub struct ItemInfo<'a> { /// The name of the item @@ -289,8 +290,13 @@ pub struct ItemInfo<'a> { } /// An enum indicating the kind of item for an `ItemInfo`. +#[derive(Clone, Copy)] #[non_exhaustive] pub enum ItemKind { + /// A module + Module, + /// A type + Type, /// A Function Function, /// A Variable diff --git a/bindgen/ir/item.rs b/bindgen/ir/item.rs index 25c3c258aa..d38879f390 100644 --- a/bindgen/ir/item.rs +++ b/bindgen/ir/item.rs @@ -17,6 +17,7 @@ use super::module::Module; use super::template::{AsTemplateParam, TemplateParameters}; use super::traversal::{EdgeKind, Trace, Tracer}; use super::ty::{Type, TypeKind}; +use crate::callbacks::ItemInfo; use crate::clang; use crate::parse::{ClangSubItemParser, ParseError, ParseResult}; @@ -922,8 +923,19 @@ impl Item { let name = names.join("_"); let name = if opt.user_mangled == UserMangled::Yes { + let item_info = ItemInfo { + name: &name, + kind: match self.kind() { + ItemKind::Module(..) => crate::callbacks::ItemKind::Module, + ItemKind::Type(..) => crate::callbacks::ItemKind::Type, + ItemKind::Function(..) => { + crate::callbacks::ItemKind::Function + } + ItemKind::Var(..) => crate::callbacks::ItemKind::Var, + }, + }; ctx.options() - .last_callback(|callbacks| callbacks.item_name(&name)) + .last_callback(|callbacks| callbacks.item_name(item_info)) .unwrap_or(name) } else { name From e7f0b9d90110e0f7d7d1d3f6d2ece75780d819d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 8 Jun 2025 12:53:25 +0200 Subject: [PATCH 903/942] Update changelog. --- CHANGELOG.md | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b7ca9f2124..fd787da8f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -221,11 +221,38 @@ -------------------------------------------------------------------------------- # Unreleased + ## Added + + * Report enums in ParseCallbacks. + * Refactor item_name method to use ItemInfo struct. + * Add callback to modify contents of macro + * Discovery callbacks for functions and methods. + * Options to generate uncallable C++ functions. + * Provide option to get real virtual fn receiver. + ## Changed + + * Generate bindings compatible with current rustc version by default. + ## Removed + + * Remove unused which-rustfmt feature + * Remove warning for opaque forward declarations + ## Fixed -## Security + + * More sophisticated handling of the triple in rust_to_clang_target + * Rename *-apple-ios-sim to ...simulator + * Fix OpenCL vectors that use "ext_vector_type". + * Fix union layout when it contains 0 sized array. + * Avoid crashing on variadic unions without layout information. + * Distinguish char16_t. + * Fix bugs in --clang-macro-fallback + * Add missed unsafe in the raw_set_bit function + * Use link_name for dynamic library loading + * Add "gen" to list of rust keywords in 'rust_mangle' + * Use appropriate `rustfmt --format ...` param # v0.71.1 (2024-12-09) ## Fixed From 3a8bedfb97bcd956c1e920165f34a090490097a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 8 Jun 2025 13:15:47 +0200 Subject: [PATCH 904/942] chore: Release --- CHANGELOG.md | 208 ++++++++++++++++++++++------------------- Cargo.lock | 4 +- Cargo.toml | 2 +- bindgen-cli/Cargo.toml | 2 +- bindgen/Cargo.toml | 2 +- 5 files changed, 115 insertions(+), 103 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd787da8f7..5a6165b9ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,220 +7,232 @@ - [Removed](#removed) - [Fixed](#fixed) - [Security](#security) -- [v0.71.1 (2024-12-09)](#v0711-2024-12-09) - - [Fixed](#fixed-1) -- [0.71.0 (2024-12-06)](#0710-2024-12-06) +- [0.72.0 (2025-06-08)](#0720-2025-06-08) - [Added](#added-1) - [Changed](#changed-1) - [Removed](#removed-1) + - [Fixed](#fixed-1) +- [v0.71.1 (2024-12-09)](#v0711-2024-12-09) - [Fixed](#fixed-2) -- [0.70.1 (2024-08-20)](#0701-2024-08-20) +- [0.71.0 (2024-12-06)](#0710-2024-12-06) - [Added](#added-2) - [Changed](#changed-2) - [Removed](#removed-2) - [Fixed](#fixed-3) - - [Security](#security-1) -- [0.70.0 (2024-08-16)](#0700-2024-08-16) +- [0.70.1 (2024-08-20)](#0701-2024-08-20) - [Added](#added-3) - [Changed](#changed-3) - [Removed](#removed-3) - [Fixed](#fixed-4) - - [Security](#security-2) -- [0.69.4 (2024-02-04)](#0694-2024-02-04) + - [Security](#security-1) +- [0.70.0 (2024-08-16)](#0700-2024-08-16) - [Added](#added-4) - [Changed](#changed-4) - [Removed](#removed-4) - [Fixed](#fixed-5) - - [Security](#security-3) -- [0.69.3 (2024-02-04)](#0693-2024-02-04) + - [Security](#security-2) +- [0.69.4 (2024-02-04)](#0694-2024-02-04) - [Added](#added-5) - [Changed](#changed-5) - [Removed](#removed-5) - [Fixed](#fixed-6) - - [Security](#security-4) -- [0.69.2 (2024-01-13)](#0692-2024-01-13) + - [Security](#security-3) +- [0.69.3 (2024-02-04)](#0693-2024-02-04) - [Added](#added-6) - [Changed](#changed-6) - [Removed](#removed-6) - [Fixed](#fixed-7) - - [Security](#security-5) -- [0.69.1 (2023-11-02)](#0691-2023-11-02) - - [Fixed](#fixed-8) -- [0.69.0 (2023-11-01)](#0690-2023-11-01) + - [Security](#security-4) +- [0.69.2 (2024-01-13)](#0692-2024-01-13) - [Added](#added-7) - [Changed](#changed-7) - [Removed](#removed-7) + - [Fixed](#fixed-8) + - [Security](#security-5) +- [0.69.1 (2023-11-02)](#0691-2023-11-02) - [Fixed](#fixed-9) - - [Security](#security-6) -- [0.68.1](#0681) - - [Fixed](#fixed-10) -- [0.68.0](#0680) +- [0.69.0 (2023-11-01)](#0690-2023-11-01) - [Added](#added-8) - [Changed](#changed-8) - [Removed](#removed-8) + - [Fixed](#fixed-10) + - [Security](#security-6) +- [0.68.1](#0681) - [Fixed](#fixed-11) -- [0.67.0](#0670) -- [0.66.1](#0661) - - [Removed](#removed-9) -- [0.66.0](#0660) +- [0.68.0](#0680) - [Added](#added-9) - [Changed](#changed-9) - - [Removed](#removed-10) -- [0.65.1](#0651) + - [Removed](#removed-9) - [Fixed](#fixed-12) -- [0.65.0](#0650) +- [0.67.0](#0670) +- [0.66.1](#0661) + - [Removed](#removed-10) +- [0.66.0](#0660) - [Added](#added-10) - [Changed](#changed-10) - [Removed](#removed-11) -- [0.64.0](#0640) +- [0.65.1](#0651) + - [Fixed](#fixed-13) +- [0.65.0](#0650) - [Added](#added-11) - [Changed](#changed-11) -- [0.63.0](#0630) + - [Removed](#removed-12) +- [0.64.0](#0640) - [Added](#added-12) - [Changed](#changed-12) - - [Removed](#removed-12) -- [0.62.0](#0620) +- [0.63.0](#0630) - [Added](#added-13) - [Changed](#changed-13) - - [Fixed](#fixed-13) -- [0.61.0](#0610) + - [Removed](#removed-13) +- [0.62.0](#0620) - [Added](#added-14) - [Changed](#changed-14) - [Fixed](#fixed-14) -- [0.60.1](#0601) - - [Fixed](#fixed-15) -- [0.60.0](#0600) +- [0.61.0](#0610) - [Added](#added-15) - - [Fixed](#fixed-16) - [Changed](#changed-15) - - [Removed](#removed-13) + - [Fixed](#fixed-15) +- [0.60.1](#0601) + - [Fixed](#fixed-16) +- [0.60.0](#0600) + - [Added](#added-16) + - [Fixed](#fixed-17) + - [Changed](#changed-16) + - [Removed](#removed-14) - [0.59.2](#0592) - [0.59.1](#0591) - - [Fixed](#fixed-17) -- [0.59.0](#0590) - - [Added](#added-16) - [Fixed](#fixed-18) - - [Changed](#changed-16) -- [0.58.1](#0581) +- [0.59.0](#0590) - [Added](#added-17) -- [0.58.0](#0580) - - [Added](#added-18) - [Fixed](#fixed-19) - [Changed](#changed-17) - - [Deprecated](#deprecated) - - [Removed](#removed-14) +- [0.58.1](#0581) + - [Added](#added-18) +- [0.58.0](#0580) + - [Added](#added-19) - [Fixed](#fixed-20) + - [Changed](#changed-18) + - [Deprecated](#deprecated) + - [Removed](#removed-15) + - [Fixed](#fixed-21) - [Security](#security-7) - [0.57.0](#0570) - - [Added](#added-19) - - [Fixed](#fixed-21) -- [0.56.0](#0560) - [Added](#added-20) - - [Changed](#changed-18) - [Fixed](#fixed-22) -- [0.55.1](#0551) - - [Fixed](#fixed-23) -- [0.55.0](#0550) - - [Removed](#removed-15) +- [0.56.0](#0560) - [Added](#added-21) - [Changed](#changed-19) + - [Fixed](#fixed-23) +- [0.55.1](#0551) - [Fixed](#fixed-24) -- [0.54.1](#0541) +- [0.55.0](#0550) + - [Removed](#removed-16) - [Added](#added-22) - [Changed](#changed-20) - [Fixed](#fixed-25) -- [0.54.0](#0540) +- [0.54.1](#0541) - [Added](#added-23) - [Changed](#changed-21) - [Fixed](#fixed-26) -- [0.53.3](#0533) +- [0.54.0](#0540) - [Added](#added-24) + - [Changed](#changed-22) - [Fixed](#fixed-27) +- [0.53.3](#0533) + - [Added](#added-25) + - [Fixed](#fixed-28) - [0.53.2](#0532) - - [Changed](#changed-22) + - [Changed](#changed-23) - [0.53.1](#0531) - - [Added](#added-25) -- [0.53.0](#0530) - [Added](#added-26) - - [Changed](#changed-23) - - [Fixed](#fixed-28) -- [0.52.0](#0520) +- [0.53.0](#0530) - [Added](#added-27) - [Changed](#changed-24) - [Fixed](#fixed-29) -- [0.51.1](#0511) - - [Fixed](#fixed-30) +- [0.52.0](#0520) + - [Added](#added-28) - [Changed](#changed-25) -- [0.51.0](#0510) + - [Fixed](#fixed-30) +- [0.51.1](#0511) - [Fixed](#fixed-31) - [Changed](#changed-26) - - [Added](#added-28) -- [0.50.0](#0500) +- [0.51.0](#0510) + - [Fixed](#fixed-32) + - [Changed](#changed-27) - [Added](#added-29) -- [0.49.3](#0493) +- [0.50.0](#0500) - [Added](#added-30) +- [0.49.3](#0493) + - [Added](#added-31) - [0.49.2](#0492) - - [Changed](#changed-27) -- [0.49.1](#0491) - - [Fixed](#fixed-32) - [Changed](#changed-28) -- [0.49.0](#0490) - - [Added](#added-31) +- [0.49.1](#0491) - [Fixed](#fixed-33) - [Changed](#changed-29) -- [0.48.1](#0481) +- [0.49.0](#0490) + - [Added](#added-32) - [Fixed](#fixed-34) -- [0.48.0](#0480) - [Changed](#changed-30) +- [0.48.1](#0481) - [Fixed](#fixed-35) -- [0.47.4](#0474) - - [Added](#added-32) -- [0.47.3](#0473) +- [0.48.0](#0480) - [Changed](#changed-31) -- [0.47.2](#0472) - [Fixed](#fixed-36) -- [0.47.1](#0471) +- [0.47.4](#0474) + - [Added](#added-33) +- [0.47.3](#0473) - [Changed](#changed-32) +- [0.47.2](#0472) - [Fixed](#fixed-37) -- [0.47.0](#0470) +- [0.47.1](#0471) - [Changed](#changed-33) - [Fixed](#fixed-38) -- [0.33.1 .. 0.46.0](#0331--0460) - - [Added](#added-33) - - [Removed](#removed-16) +- [0.47.0](#0470) - [Changed](#changed-34) - [Fixed](#fixed-39) -- [0.33.1](#0331) +- [0.33.1 .. 0.46.0](#0331--0460) + - [Added](#added-34) + - [Removed](#removed-17) + - [Changed](#changed-35) - [Fixed](#fixed-40) +- [0.33.1](#0331) + - [Fixed](#fixed-41) - [0.33.0](#0330) - [0.32.2](#0322) - - [Fixed](#fixed-41) -- [0.32.1](#0321) - [Fixed](#fixed-42) -- [0.32.0](#0320) - - [Added](#added-34) - - [Changed](#changed-35) +- [0.32.1](#0321) - [Fixed](#fixed-43) -- [0.31.0](#0310) +- [0.32.0](#0320) - [Added](#added-35) - [Changed](#changed-36) - - [Deprecated](#deprecated-1) - - [Removed](#removed-17) - [Fixed](#fixed-44) -- [0.30.0](#0300) +- [0.31.0](#0310) - [Added](#added-36) - [Changed](#changed-37) - - [Deprecated](#deprecated-2) + - [Deprecated](#deprecated-1) + - [Removed](#removed-18) - [Fixed](#fixed-45) -- [0.29.0](#0290) +- [0.30.0](#0300) - [Added](#added-37) - [Changed](#changed-38) + - [Deprecated](#deprecated-2) - [Fixed](#fixed-46) +- [0.29.0](#0290) + - [Added](#added-38) + - [Changed](#changed-39) + - [Fixed](#fixed-47) -------------------------------------------------------------------------------- # Unreleased +## Added +## Changed +## Removed +## Fixed +## Security + +# 0.72.0 (2025-06-08) ## Added diff --git a/Cargo.lock b/Cargo.lock index 4e88c224f5..b302509cfc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -35,7 +35,7 @@ checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] name = "bindgen" -version = "0.71.1" +version = "0.72.0" dependencies = [ "annotate-snippets", "bitflags 2.2.1", @@ -56,7 +56,7 @@ dependencies = [ [[package]] name = "bindgen-cli" -version = "0.71.1" +version = "0.72.0" dependencies = [ "bindgen", "env_logger 0.10.0", diff --git a/Cargo.toml b/Cargo.toml index b0a5bbb082..cc3bc7def8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ edition = "2021" # All dependency version management is centralized here [workspace.dependencies] annotate-snippets = "0.11.4" -bindgen = { version = "0.71.1", path = "./bindgen", default-features = false } +bindgen = { version = "0.72.0", path = "./bindgen", default-features = false } bitflags = "2.2.1" block = "0.1" cc = "1.0" diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml index 52fcaaeb1b..e5d49a6ecc 100644 --- a/bindgen-cli/Cargo.toml +++ b/bindgen-cli/Cargo.toml @@ -13,7 +13,7 @@ readme = "../README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.71.1" +version = "0.72.0" rust-version.workspace = true edition.workspace = true diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index 4e9fe5a4f9..478574edb3 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -16,7 +16,7 @@ readme = "../README.md" repository = "https://github.com/rust-lang/rust-bindgen" documentation = "https://docs.rs/bindgen" homepage = "https://rust-lang.github.io/rust-bindgen/" -version = "0.71.1" +version = "0.72.0" build = "build.rs" rust-version.workspace = true edition.workspace = true From eae5b667a50afb69020a7b9fe30877c0aaa5cb95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 8 Jun 2025 13:37:50 +0200 Subject: [PATCH 905/942] chore: Update dist. --- .github/workflows/release.yml | 60 ++++++++++++++++++++--------------- dist-workspace.toml | 8 ++--- 2 files changed, 38 insertions(+), 30 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 071214f8d1..6620b80c98 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,4 +1,4 @@ -# This file was autogenerated by cargo-dist: https://opensource.axo.dev/cargo-dist/ +# This file was autogenerated by dist: https://opensource.axo.dev/cargo-dist/ # # Copyright 2022-2024, axodotdev # SPDX-License-Identifier: MIT or Apache-2.0 @@ -6,7 +6,7 @@ # CI that: # # * checks for a Git Tag that looks like a release -# * builds artifacts with cargo-dist (archives, installers, hashes) +# * builds artifacts with dist (archives, installers, hashes) # * uploads those artifacts to temporary workflow zip # * on success, uploads the artifacts to a GitHub Release # @@ -24,10 +24,10 @@ permissions: # must be a Cargo-style SemVer Version (must have at least major.minor.patch). # # If PACKAGE_NAME is specified, then the announcement will be for that -# package (erroring out if it doesn't have the given version or isn't cargo-dist-able). +# package (erroring out if it doesn't have the given version or isn't dist-able). # # If PACKAGE_NAME isn't specified, then the announcement will be for all -# (cargo-dist-able) packages in the workspace with that version (this mode is +# (dist-able) packages in the workspace with that version (this mode is # intended for workspaces with only one dist-able package, or with all dist-able # packages versioned/released in lockstep). # @@ -45,7 +45,7 @@ on: - '**[0-9]+.[0-9]+.[0-9]+*' jobs: - # Run 'cargo dist plan' (or host) to determine what tasks we need to do + # Run 'dist plan' (or host) to determine what tasks we need to do plan: runs-on: "ubuntu-22.04" outputs: @@ -59,16 +59,16 @@ jobs: - uses: actions/checkout@v4 with: submodules: recursive - - name: Install cargo-dist + - name: Install dist # we specify bash to get pipefail; it guards against the `curl` command # failing. otherwise `sh` won't catch that `curl` returned non-0 shell: bash - run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.22.1/cargo-dist-installer.sh | sh" - - name: Cache cargo-dist + run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.28.0/cargo-dist-installer.sh | sh" + - name: Cache dist uses: actions/upload-artifact@v4 with: name: cargo-dist-cache - path: ~/.cargo/bin/cargo-dist + path: ~/.cargo/bin/dist # sure would be cool if github gave us proper conditionals... # so here's a doubly-nested ternary-via-truthiness to try to provide the best possible # functionality based on whether this is a pull_request, and whether it's from a fork. @@ -76,8 +76,8 @@ jobs: # but also really annoying to build CI around when it needs secrets to work right.) - id: plan run: | - cargo dist ${{ (!github.event.pull_request && format('host --steps=create --tag={0}', github.ref_name)) || 'plan' }} --output-format=json > plan-dist-manifest.json - echo "cargo dist ran successfully" + dist ${{ (!github.event.pull_request && format('host --steps=create --tag={0}', github.ref_name)) || 'plan' }} --output-format=json > plan-dist-manifest.json + echo "dist ran successfully" cat plan-dist-manifest.json echo "manifest=$(jq -c "." plan-dist-manifest.json)" >> "$GITHUB_OUTPUT" - name: "Upload dist-manifest.json" @@ -95,18 +95,19 @@ jobs: if: ${{ fromJson(needs.plan.outputs.val).ci.github.artifacts_matrix.include != null && (needs.plan.outputs.publishing == 'true' || fromJson(needs.plan.outputs.val).ci.github.pr_run_mode == 'upload') }} strategy: fail-fast: false - # Target platforms/runners are computed by cargo-dist in create-release. + # Target platforms/runners are computed by dist in create-release. # Each member of the matrix has the following arguments: # # - runner: the github runner - # - dist-args: cli flags to pass to cargo dist - # - install-dist: expression to run to install cargo-dist on the runner + # - dist-args: cli flags to pass to dist + # - install-dist: expression to run to install dist on the runner # # Typically there will be: # - 1 "global" task that builds universal installers # - N "local" tasks that build each platform's binaries and platform-specific installers matrix: ${{ fromJson(needs.plan.outputs.val).ci.github.artifacts_matrix }} runs-on: ${{ matrix.runner }} + container: ${{ matrix.container && matrix.container.image || null }} env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} BUILD_MANIFEST_NAME: target/distrib/${{ join(matrix.targets, '-') }}-dist-manifest.json @@ -117,8 +118,15 @@ jobs: - uses: actions/checkout@v4 with: submodules: recursive - - name: Install cargo-dist - run: ${{ matrix.install_dist }} + - name: Install Rust non-interactively if not already installed + if: ${{ matrix.container }} + run: | + if ! command -v cargo > /dev/null 2>&1; then + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y + echo "$HOME/.cargo/bin" >> $GITHUB_PATH + fi + - name: Install dist + run: ${{ matrix.install_dist.run }} # Get the dist-manifest - name: Fetch local artifacts uses: actions/download-artifact@v4 @@ -132,8 +140,8 @@ jobs: - name: Build artifacts run: | # Actually do builds and make zips and whatnot - cargo dist build ${{ needs.plan.outputs.tag-flag }} --print=linkage --output-format=json ${{ matrix.dist_args }} > dist-manifest.json - echo "cargo dist ran successfully" + dist build ${{ needs.plan.outputs.tag-flag }} --print=linkage --output-format=json ${{ matrix.dist_args }} > dist-manifest.json + echo "dist ran successfully" - id: cargo-dist name: Post-build # We force bash here just because github makes it really hard to get values up @@ -143,7 +151,7 @@ jobs: run: | # Parse out what we just built and upload it to scratch storage echo "paths<> "$GITHUB_OUTPUT" - jq --raw-output ".upload_files[]" dist-manifest.json >> "$GITHUB_OUTPUT" + dist print-upload-files-from-manifest --manifest dist-manifest.json >> "$GITHUB_OUTPUT" echo "EOF" >> "$GITHUB_OUTPUT" cp dist-manifest.json "$BUILD_MANIFEST_NAME" @@ -168,12 +176,12 @@ jobs: - uses: actions/checkout@v4 with: submodules: recursive - - name: Install cached cargo-dist + - name: Install cached dist uses: actions/download-artifact@v4 with: name: cargo-dist-cache path: ~/.cargo/bin/ - - run: chmod +x ~/.cargo/bin/cargo-dist + - run: chmod +x ~/.cargo/bin/dist # Get all the local artifacts for the global tasks to use (for e.g. checksums) - name: Fetch local artifacts uses: actions/download-artifact@v4 @@ -184,8 +192,8 @@ jobs: - id: cargo-dist shell: bash run: | - cargo dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json "--artifacts=global" > dist-manifest.json - echo "cargo dist ran successfully" + dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json "--artifacts=global" > dist-manifest.json + echo "dist ran successfully" # Parse out what we just built and upload it to scratch storage echo "paths<> "$GITHUB_OUTPUT" @@ -217,12 +225,12 @@ jobs: - uses: actions/checkout@v4 with: submodules: recursive - - name: Install cached cargo-dist + - name: Install cached dist uses: actions/download-artifact@v4 with: name: cargo-dist-cache path: ~/.cargo/bin/ - - run: chmod +x ~/.cargo/bin/cargo-dist + - run: chmod +x ~/.cargo/bin/dist # Fetch artifacts from scratch-storage - name: Fetch artifacts uses: actions/download-artifact@v4 @@ -233,7 +241,7 @@ jobs: - id: host shell: bash run: | - cargo dist host ${{ needs.plan.outputs.tag-flag }} --steps=upload --steps=release --output-format=json > dist-manifest.json + dist host ${{ needs.plan.outputs.tag-flag }} --steps=upload --steps=release --output-format=json > dist-manifest.json echo "artifacts uploaded and released successfully" cat dist-manifest.json echo "manifest=$(jq -c "." dist-manifest.json)" >> "$GITHUB_OUTPUT" diff --git a/dist-workspace.toml b/dist-workspace.toml index 60a8c51fca..7a7609b05c 100644 --- a/dist-workspace.toml +++ b/dist-workspace.toml @@ -1,16 +1,16 @@ [workspace] members = ["cargo:."] -# Config for 'cargo dist' +# Config for 'dist' [dist] -# The preferred cargo-dist version to use in CI (Cargo.toml SemVer syntax) -cargo-dist-version = "0.22.1" +# The preferred dist version to use in CI (Cargo.toml SemVer syntax) +cargo-dist-version = "0.28.0" # CI backends to support ci = "github" # The installers to generate for each app installers = ["shell"] # Target platforms to build apps for (Rust target-triple syntax) -targets = ["aarch64-apple-darwin", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu"] +targets = ["aarch64-apple-darwin", "aarch64-unknown-linux-gnu", "aarch64-pc-windows-msvc", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu", "x86_64-pc-windows-msvc"] # Whether to consider the binaries in a package for distribution (defaults true) dist = false # Which actions to run on pull requests From 187bcced448990efdaabc9c5c2ee397852c5d1a5 Mon Sep 17 00:00:00 2001 From: usamoi Date: Tue, 25 Feb 2025 23:15:04 +0800 Subject: [PATCH 906/942] apply same rule to C and C-unwind in names_will_be_identical_after_mangling --- bindgen/codegen/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 59f2265c09..433fc85f01 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -5933,7 +5933,7 @@ pub(crate) mod utils { let mangled_name = mangled_name.as_bytes(); let (mangling_prefix, expect_suffix) = match call_conv { - Some(ClangAbi::Known(Abi::C)) | + Some(ClangAbi::Known(Abi::C | Abi::CUnwind)) | // None is the case for global variables None => { (b'_', false) From 6e13d4fe95baafc27e18b7bf3bffb8f8399e327f Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Sun, 8 Jun 2025 21:39:33 +0200 Subject: [PATCH 907/942] ci: Move forward Rust for Linux version to v6.16-rc1 Signed-off-by: Miguel Ojeda --- ci/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/test.sh b/ci/test.sh index d134004709..952b48e80d 100755 --- a/ci/test.sh +++ b/ci/test.sh @@ -96,7 +96,7 @@ if [ "$BINDGEN_RUST_FOR_LINUX_TEST" == "1" ]; then # and each update should only contain this change. # # Both commit hashes and tags are supported. - LINUX_VERSION=v6.15-rc4 + LINUX_VERSION=v6.16-rc1 # Download Linux at a specific commit mkdir -p linux From cc9bc705f7e7aec831dfc22a34a3eab760bfce78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 18 Jun 2025 13:49:42 +0200 Subject: [PATCH 908/942] chore: Do a clippy pass. --- bindgen-tests/build.rs | 2 ++ bindgen-tests/tests/tests.rs | 4 ++-- bindgen/ir/analysis/has_destructor.rs | 5 ++--- bindgen/ir/analysis/has_vtable.rs | 5 ++--- bindgen/ir/context.rs | 8 ++++---- bindgen/ir/function.rs | 5 ++--- bindgen/lib.rs | 16 +++++++--------- bindgen/options/mod.rs | 6 +++--- clippy.toml | 4 ---- 9 files changed, 24 insertions(+), 31 deletions(-) diff --git a/bindgen-tests/build.rs b/bindgen-tests/build.rs index 8fb33716a1..cf929b4b65 100644 --- a/bindgen-tests/build.rs +++ b/bindgen-tests/build.rs @@ -33,6 +33,8 @@ pub fn main() { .replace(|c| !char::is_alphanumeric(c), "_") .replace("__", "_") .to_lowercase(); + // We actually want the quotes and escape + #[allow(clippy::unnecessary_debug_formatting)] writeln!(dst, "test_header!(header_{func}, {:?});", entry.path()) .unwrap(); } diff --git a/bindgen-tests/tests/tests.rs b/bindgen-tests/tests/tests.rs index 3cc7cbe415..bcf9b7fcfa 100644 --- a/bindgen-tests/tests/tests.rs +++ b/bindgen-tests/tests/tests.rs @@ -41,9 +41,9 @@ fn error_diff_mismatch( filename: &Path, ) -> Result<(), Error> { println!("diff expected generated"); - println!("--- expected: {filename:?}"); + println!("--- expected: {}", filename.display()); if let Some(header) = header { - println!("+++ generated from: {header:?}"); + println!("+++ generated from: {}", header.display()); } show_diff(expected, actual); diff --git a/bindgen/ir/analysis/has_destructor.rs b/bindgen/ir/analysis/has_destructor.rs index 4893f8f807..44ef33c21b 100644 --- a/bindgen/ir/analysis/has_destructor.rs +++ b/bindgen/ir/analysis/has_destructor.rs @@ -93,9 +93,8 @@ impl<'ctx> MonotoneFramework for HasDestructorAnalysis<'ctx> { } let item = self.ctx.resolve_item(id); - let ty = match item.as_type() { - None => return ConstrainResult::Same, - Some(ty) => ty, + let Some(ty) = item.as_type() else { + return ConstrainResult::Same; }; match *ty.kind() { diff --git a/bindgen/ir/analysis/has_vtable.rs b/bindgen/ir/analysis/has_vtable.rs index 3ff64a6d2b..b8ecc6088e 100644 --- a/bindgen/ir/analysis/has_vtable.rs +++ b/bindgen/ir/analysis/has_vtable.rs @@ -149,9 +149,8 @@ impl<'ctx> MonotoneFramework for HasVtableAnalysis<'ctx> { trace!("constrain {id:?}"); let item = self.ctx.resolve_item(id); - let ty = match item.as_type() { - None => return ConstrainResult::Same, - Some(ty) => ty, + let Some(ty) = item.as_type() else { + return ConstrainResult::Same; }; // TODO #851: figure out a way to handle deriving from template type parameters. diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index c0201a114b..6adbcd5989 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -724,7 +724,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" self.need_bitfield_allocation.push(id); } - let old_item = mem::replace(&mut self.items[id.0], Some(item)); + let old_item = self.items[id.0].replace(item); assert!( old_item.is_none(), "should not have already associated an item with the given id" @@ -827,7 +827,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" self.add_item_to_module(&item); let id = item.id(); - let old_item = mem::replace(&mut self.items[id.0], Some(item)); + let old_item = self.items[id.0].replace(item); assert!( old_item.is_none(), "should not have already associated an item with the given id" @@ -987,7 +987,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" let result = f(self, &mut item); - let existing = mem::replace(&mut self.items[id.0], Some(item)); + let existing = self.items[id.0].replace(item); assert!(existing.is_none()); result @@ -1434,7 +1434,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" debug_assert!(item.kind().is_type()); self.add_item_to_module(&item); let id = item.id(); - let old_item = mem::replace(&mut self.items[id.0], Some(item)); + let old_item = self.items[id.0].replace(item); assert!(old_item.is_none(), "Inserted type twice?"); } diff --git a/bindgen/ir/function.rs b/bindgen/ir/function.rs index 65a12d4bb2..6f8c00fa89 100644 --- a/bindgen/ir/function.rs +++ b/bindgen/ir/function.rs @@ -724,9 +724,8 @@ impl ClangSubItemParser for Function { ) -> Result, ParseError> { use clang_sys::*; - let kind = match FunctionKind::from_cursor(&cursor) { - None => return Err(ParseError::Continue), - Some(k) => k, + let Some(kind) = FunctionKind::from_cursor(&cursor) else { + return Err(ParseError::Continue); }; debug!("Function::parse({cursor:?}, {:?})", cursor.cur_type()); diff --git a/bindgen/lib.rs b/bindgen/lib.rs index b2fecc2c3b..e4294c505a 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -301,12 +301,11 @@ fn get_extra_clang_args( parse_callbacks: &[Rc], ) -> Vec { // Add any extra arguments from the environment to the clang command line. - let extra_clang_args = match get_target_dependent_env_var( + let Some(extra_clang_args) = get_target_dependent_env_var( parse_callbacks, "BINDGEN_EXTRA_CLANG_ARGS", - ) { - None => return vec![], - Some(s) => s, + ) else { + return vec![]; }; // Try to parse it with shell quoting. If we fail, make it one single big argument. @@ -841,12 +840,11 @@ impl Bindings { "Trying to find clang with flags: {clang_args_for_clang_sys:?}" ); - let clang = match clang_sys::support::Clang::find( + let Some(clang) = clang_sys::support::Clang::find( None, &clang_args_for_clang_sys, - ) { - None => return, - Some(clang) => clang, + ) else { + return; }; debug!("Found clang: {clang:?}"); @@ -980,7 +978,7 @@ impl Bindings { } /// Gets the rustfmt path to rustfmt the generated bindings. - fn rustfmt_path(&self) -> io::Result> { + fn rustfmt_path(&self) -> io::Result> { debug_assert!(matches!(self.options.formatter, Formatter::Rustfmt)); if let Some(ref p) = self.options.rustfmt_path { return Ok(Cow::Borrowed(p)); diff --git a/bindgen/options/mod.rs b/bindgen/options/mod.rs index c9ef7c8b49..b876b4d5b3 100644 --- a/bindgen/options/mod.rs +++ b/bindgen/options/mod.rs @@ -168,7 +168,7 @@ options! { as_args: "--use-specific-virtual-function-receiver", }, - /// Whether we should distinguish between C++'s 'char16_t' and 'u16'. + /// Whether we should distinguish between C++'s `char16_t` and `u16`. /// The C++ type `char16_t` is its own special type; it's not a typedef /// of some other integer (this differs from C). /// As standard, bindgen represents C++ `char16_t` as `u16`. @@ -183,7 +183,7 @@ options! { /// real type. use_distinct_char16_t: bool { methods: { - /// If this is true, denote 'char16_t' as a separate type from 'u16' + /// If this is true, denote `char16_t` as a separate type from `u16`. /// Disabled by default. pub fn use_distinct_char16_t(mut self, doit: bool) -> Builder { self.options.use_distinct_char16_t = doit; @@ -2101,7 +2101,7 @@ options! { /// Whether to generate wrappers for `static` functions. wrap_static_fns: bool { methods: { - /// Set whether to generate wrappers for `static`` functions. + /// Set whether to generate wrappers for `static` functions. /// /// Passing `true` to this method will generate a C source file with non-`static` /// functions that call the `static` functions found in the input headers and can be diff --git a/clippy.toml b/clippy.toml index 26a0605343..ec210a9878 100644 --- a/clippy.toml +++ b/clippy.toml @@ -1,5 +1 @@ -disallowed-methods = [ - { path = "clang_sys::CXCursor_TranslationUnit", reason = "This value was changed in clang 15"}, - { path = "clang_sys::CXCursor_LastStmt", reason = "This value was changed in clang 15"} -] missing-docs-in-crate-items = true From bba0875aa838b88addae03954798ef30a43dfdbc Mon Sep 17 00:00:00 2001 From: Niklas Dusenlund Date: Mon, 9 Jun 2025 12:27:58 +0200 Subject: [PATCH 909/942] ci: use ubuntu-22.04 for local linux builds --- dist-workspace.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/dist-workspace.toml b/dist-workspace.toml index 7a7609b05c..f2706c7473 100644 --- a/dist-workspace.toml +++ b/dist-workspace.toml @@ -24,3 +24,4 @@ install-path = "CARGO_HOME" global = "ubuntu-22.04" aarch64-apple-darwin = "macos-14" x86_64-apple-darwin = "macos-13" +x86_64-unknown-linux-gnu = "ubuntu-22.04" From 1f02556afc120f24b778b4150649e221177b163f Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Wed, 11 Jun 2025 14:33:57 -0400 Subject: [PATCH 910/942] feat: add Debug,Clone,Eq traits to callback objects Add common traits like `Debug` to the callback objects like `ItemKind` and `ItemInfo`. --- bindgen/callbacks.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bindgen/callbacks.rs b/bindgen/callbacks.rs index 93005ce8e5..8ad06b3375 100644 --- a/bindgen/callbacks.rs +++ b/bindgen/callbacks.rs @@ -248,7 +248,7 @@ pub enum DiscoveredItem { /// Relevant information about a type to which new derive attributes will be added using /// [`ParseCallbacks::add_derives`]. -#[derive(Debug)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[non_exhaustive] pub struct DeriveInfo<'a> { /// The name of the type. @@ -259,7 +259,7 @@ pub struct DeriveInfo<'a> { /// Relevant information about a type to which new attributes will be added using /// [`ParseCallbacks::add_attributes`]. -#[derive(Debug)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[non_exhaustive] pub struct AttributeInfo<'a> { /// The name of the type. @@ -280,7 +280,7 @@ pub enum TypeKind { } /// A struct providing information about the item being passed to [`ParseCallbacks::generated_name_override`]. -#[derive(Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[non_exhaustive] pub struct ItemInfo<'a> { /// The name of the item @@ -290,7 +290,7 @@ pub struct ItemInfo<'a> { } /// An enum indicating the kind of item for an `ItemInfo`. -#[derive(Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[non_exhaustive] pub enum ItemKind { /// A module @@ -305,7 +305,7 @@ pub enum ItemKind { /// Relevant information about a field for which visibility can be determined using /// [`ParseCallbacks::field_visibility`]. -#[derive(Debug)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[non_exhaustive] pub struct FieldInfo<'a> { /// The name of the type. From 88c7bd15b7795f2c2aadc85c47856d402e6e5e84 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Wed, 9 Jul 2025 14:13:59 -0700 Subject: [PATCH 911/942] cargo update --- Cargo.lock | 480 ++++++++++++++++++++++------------------------------- 1 file changed, 200 insertions(+), 280 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b302509cfc..92f1f78ebf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,32 +13,70 @@ dependencies = [ [[package]] name = "annotate-snippets" -version = "0.11.4" +version = "0.11.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24e35ed54e5ea7997c14ed4c70ba043478db1112e98263b3b035907aa197d991" +checksum = "710e8eae58854cdc1790fcb56cca04d712a17be849eeb81da2a724bf4bae2bc4" dependencies = [ "anstyle", "unicode-width", ] +[[package]] +name = "anstream" +version = "0.6.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "301af1932e46185686725e0fad2f8f2aa7da69dd70bf6ecc44d6b703844a3933" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + [[package]] name = "anstyle" -version = "1.0.10" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "862ed96ca487e809f1c8e5a8447f6ee2cf102f846893800b20cebdf541fc6bbd" + +[[package]] +name = "anstyle-parse" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" +checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2" +dependencies = [ + "utf8parse", +] [[package]] -name = "autocfg" -version = "1.4.0" +name = "anstyle-query" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" +checksum = "6c8bdeb6047d8983be085bab0ba1472e6dc604e7041dbf6fcd5e71523014fae9" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "403f75924867bb1033c59fbf0797484329750cfbe3c4325cd33127941fabc882" +dependencies = [ + "anstyle", + "once_cell_polyfill", + "windows-sys", +] [[package]] name = "bindgen" version = "0.72.0" dependencies = [ "annotate-snippets", - "bitflags 2.2.1", + "bitflags", "cexpr", "clang-sys", "clap", @@ -51,7 +89,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.90", + "syn", ] [[package]] @@ -59,7 +97,7 @@ name = "bindgen-cli" version = "0.72.0" dependencies = [ "bindgen", - "env_logger 0.10.0", + "env_logger 0.10.2", "log", "proc-macro2", "shlex", @@ -84,21 +122,15 @@ dependencies = [ "regex", "shlex", "similar", - "syn 2.0.90", + "syn", "tempfile", ] [[package]] name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "bitflags" -version = "2.2.1" +version = "2.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24a6904aef64d73cf10ab17ebace7befb918b82164785cb89907993be7f83813" +checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967" [[package]] name = "block" @@ -108,9 +140,9 @@ checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" [[package]] name = "cc" -version = "1.2.2" +version = "1.2.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f34d93e62b03caf570cccc334cbc6c2fceca82f39211051345108adcba3eebdc" +checksum = "5c1599538de2394445747c8cf7935946e3cc27e9625f889d979bfb2aaf569362" dependencies = [ "shlex", ] @@ -126,9 +158,9 @@ dependencies = [ [[package]] name = "cfg-if" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268" [[package]] name = "clang-sys" @@ -143,55 +175,64 @@ dependencies = [ [[package]] name = "clap" -version = "4.1.4" +version = "4.4.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f13b9c79b5d1dd500d20ef541215a6423c75829ef43117e1b4d17fd8af0b5d76" +checksum = "1e578d6ec4194633722ccf9544794b71b1385c3c027efe0c55db226fc880865c" dependencies = [ - "bitflags 1.3.2", + "clap_builder", "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.4.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4df4df40ec50c46000231c914968278b1eb05098cf8f1b3a518a95030e71d1c7" +dependencies = [ + "anstream", + "anstyle", "clap_lex", - "is-terminal", - "once_cell", "strsim", - "termcolor", ] [[package]] name = "clap_complete" -version = "4.2.0" +version = "4.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01c22dcfb410883764b29953103d9ef7bb8fe21b3fa1158bc99986c2067294bd" +checksum = "abb745187d7f4d76267b37485a65e0149edd0e91a4cfcdd3f27524ad86cee9f3" dependencies = [ "clap", ] [[package]] name = "clap_derive" -version = "4.1.0" +version = "4.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "684a277d672e91966334af371f1a7b5833f9aa00b07c84e92fbce95e00208ce8" +checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442" dependencies = [ "heck", - "proc-macro-error", "proc-macro2", "quote", - "syn 1.0.109", + "syn", ] [[package]] name = "clap_lex" -version = "0.3.1" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "783fe232adfca04f90f56201b26d79682d4cd2625e0bc7290b95123afe558ade" -dependencies = [ - "os_str_bytes", -] +checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" + +[[package]] +name = "colorchoice" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" [[package]] name = "either" -version = "1.13.0" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" +checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" [[package]] name = "env_logger" @@ -205,9 +246,9 @@ dependencies = [ [[package]] name = "env_logger" -version = "0.10.0" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0" +checksum = "4cd405aab171cb85d6735e5c8d9db038c17d3ca007a4d2c25f337935c3d90580" dependencies = [ "humantime", "is-terminal", @@ -218,39 +259,48 @@ dependencies = [ [[package]] name = "errno" -version = "0.3.10" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" +checksum = "778e2ac28f6c47af28e4907f13ffd1e1ddbd400980a9abd7c8df189bf578a5ad" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys", ] [[package]] name = "fastrand" -version = "1.9.0" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" + +[[package]] +name = "getrandom" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" +checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" dependencies = [ - "instant", + "cfg-if", + "libc", + "wasi 0.11.1+wasi-snapshot-preview1", ] [[package]] name = "getrandom" -version = "0.2.15" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4" dependencies = [ "cfg-if", "libc", - "wasi", + "r-efi", + "wasi 0.14.2+wasi-0.2.4", ] [[package]] name = "glob" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" +checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2" [[package]] name = "heck" @@ -260,52 +310,32 @@ checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "hermit-abi" -version = "0.3.9" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - -[[package]] -name = "hermit-abi" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc" +checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c" [[package]] name = "humantime" -version = "2.1.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" - -[[package]] -name = "instant" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" -dependencies = [ - "cfg-if", -] +checksum = "9b112acc8b3adf4b107a8ec20977da0273a8c386765a3ec0229bd500a1443f9f" [[package]] -name = "io-lifetimes" -version = "1.0.11" +name = "is-terminal" +version = "0.4.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" +checksum = "e04d7f318608d35d4b61ddd75cbdaee86b023ebe2bd5a66ee0915f0bf93095a9" dependencies = [ - "hermit-abi 0.3.9", + "hermit-abi", "libc", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] -name = "is-terminal" -version = "0.4.13" +name = "is_terminal_polyfill" +version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "261f68e344040fbd0edea105bef17c66edf46f984ddb1115b775ce31be948f4b" -dependencies = [ - "hermit-abi 0.4.0", - "libc", - "windows-sys 0.52.0", -] +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" [[package]] name = "itertools" @@ -318,31 +348,31 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.167" +version = "0.2.174" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09d6582e104315a817dff97f75133544b2e094ee22447d2acf4a74e189ba06fc" +checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" [[package]] name = "libloading" -version = "0.8.6" +version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34" +checksum = "07033963ba89ebaf1584d767badaa2e8fcec21aedea6b8c0346d487d49c28667" dependencies = [ "cfg-if", - "windows-targets 0.52.6", + "windows-targets", ] [[package]] name = "linux-raw-sys" -version = "0.3.8" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" +checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12" [[package]] name = "log" -version = "0.4.22" +version = "0.4.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" +checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" [[package]] name = "malloc_buf" @@ -355,9 +385,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.7.4" +version = "2.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0" [[package]] name = "minimal-lexical" @@ -386,61 +416,37 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.20.2" +version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" [[package]] -name = "os_str_bytes" -version = "6.4.1" +name = "once_cell_polyfill" +version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee" +checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad" [[package]] name = "owo-colors" -version = "4.1.0" +version = "4.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb37767f6569cd834a413442455e0f066d0d522de8630436e2a1761d9726ba56" +checksum = "48dd4f4a2c8405440fd0462561f0e5806bd0f77e86f51c761481bdd4018b545e" [[package]] name = "prettyplease" -version = "0.2.25" +version = "0.2.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64d1ec885c64d0457d564db4ec299b2dae3f9c02808b8ad9c3a089c591b18033" +checksum = "061c1221631e079b26479d25bbf2275bfe5917ae8419cd7e34f13bfc2aa7539a" dependencies = [ "proc-macro2", - "syn 2.0.90", -] - -[[package]] -name = "proc-macro-error" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" -dependencies = [ - "proc-macro-error-attr", - "proc-macro2", - "quote", - "syn 1.0.109", - "version_check", -] - -[[package]] -name = "proc-macro-error-attr" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" -dependencies = [ - "proc-macro2", - "quote", - "version_check", + "syn", ] [[package]] name = "proc-macro2" -version = "1.0.92" +version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" +checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" dependencies = [ "unicode-ident", ] @@ -467,13 +473,19 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.37" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" dependencies = [ "proc-macro2", ] +[[package]] +name = "r-efi" +version = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" + [[package]] name = "rand" version = "0.8.5" @@ -489,16 +501,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom", -] - -[[package]] -name = "redox_syscall" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" -dependencies = [ - "bitflags 1.3.2", + "getrandom 0.2.16", ] [[package]] @@ -532,22 +535,21 @@ checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "rustc-hash" -version = "2.1.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7fb8039b3032c191086b10f11f319a6e99e1e82889c5cc6046f515c9db1d497" +checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" [[package]] name = "rustix" -version = "0.37.27" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fea8ca367a3a01fe35e6943c400addf443c0f57670e6ec51196f71a4b8762dd2" +checksum = "c71e83d6afe7ff64890ec6b71d6a69bb8a610ab78ce364b3352876bb4c801266" dependencies = [ - "bitflags 1.3.2", + "bitflags", "errno", - "io-lifetimes", "libc", "linux-raw-sys", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] @@ -558,9 +560,9 @@ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "similar" -version = "2.6.0" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1de1d4f81173b03af4c0cbed3c898f6bff5b870e4a7f5d6f4057d62a7a4b686e" +checksum = "bbbb5d9659141646ae647b42fe094daf6c6192d1620870b449d9557f748b2daa" [[package]] name = "strsim" @@ -570,20 +572,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "syn" -version = "2.0.90" +version = "2.0.104" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "919d3b74a5dd0ccd15aeb8f93e7006bd9e14c295087c9896a110f490752bcf31" +checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40" dependencies = [ "proc-macro2", "quote", @@ -592,23 +583,22 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.6.0" +version = "3.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31c0432476357e58790aaa47a8efb0c5138f137343f3b5f23bd36a27e3b0a6d6" +checksum = "e8a64e3985349f2441a1a9ef0b853f869006c3855f2cda6862a94d26ebb9d6a1" dependencies = [ - "autocfg", - "cfg-if", "fastrand", - "redox_syscall", + "getrandom 0.3.3", + "once_cell", "rustix", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] name = "termcolor" -version = "1.2.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" dependencies = [ "winapi-util", ] @@ -624,90 +614,53 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.14" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" +checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" [[package]] name = "unicode-width" -version = "0.1.14" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" +checksum = "4a1a07cc7db3810833284e8d372ccdc6da29741639ecc70c9ec107df0fa6154c" [[package]] -name = "version_check" -version = "0.9.4" +name = "utf8parse" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" +version = "0.11.1+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" [[package]] -name = "winapi" -version = "0.3.9" +name = "wasi" +version = "0.14.2+wasi-0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3" dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", + "wit-bindgen-rt", ] -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - [[package]] name = "winapi-util" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" -dependencies = [ - "winapi", -] - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "windows-sys" -version = "0.48.0" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-targets 0.48.5", + "windows-sys", ] [[package]] name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.6", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" +version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", + "windows-targets", ] [[package]] @@ -716,46 +669,28 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm 0.52.6", - "windows_aarch64_msvc 0.52.6", - "windows_i686_gnu 0.52.6", + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", "windows_i686_gnullvm", - "windows_i686_msvc 0.52.6", - "windows_x86_64_gnu 0.52.6", - "windows_x86_64_gnullvm 0.52.6", - "windows_x86_64_msvc 0.52.6", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", ] -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - [[package]] name = "windows_aarch64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - [[package]] name = "windows_aarch64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - [[package]] name = "windows_i686_gnu" version = "0.52.6" @@ -768,36 +703,18 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - [[package]] name = "windows_i686_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - [[package]] name = "windows_x86_64_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - [[package]] name = "windows_x86_64_gnullvm" version = "0.52.6" @@ -806,12 +723,15 @@ checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_msvc" -version = "0.48.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] -name = "windows_x86_64_msvc" -version = "0.52.6" +name = "wit-bindgen-rt" +version = "0.39.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1" +dependencies = [ + "bitflags", +] From e23f0a7ad6fe7a394cd83f92979eb5871a040052 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Thu, 10 Jul 2025 17:42:53 -0700 Subject: [PATCH 912/942] Fix `clippy::uninlined_format_args` in log macros These are newly in effect since rust-lang/log#665. --- bindgen/codegen/mod.rs | 9 +++------ bindgen/ir/context.rs | 3 +-- bindgen/ir/ty.rs | 3 +-- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 433fc85f01..bdda6add57 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -494,8 +494,7 @@ impl Item { if self.is_blocklisted(ctx) || result.seen(self.id()) { debug!( "::process_before_codegen: Ignoring hidden or seen: \ - self = {:?}", - self + self = {self:?}" ); return false; } @@ -986,8 +985,7 @@ impl CodeGenerator for Type { if inner_canon_type.is_invalid_type_param() { warn!( "Item contained invalid named type, skipping: \ - {:?}, {:?}", - item, inner_item + {item:?}, {inner_item:?}" ); return; } @@ -1098,8 +1096,7 @@ impl CodeGenerator for Type { { warn!( "Item contained invalid template \ - parameter: {:?}", - item + parameter: {item:?}" ); return; } diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index 6adbcd5989..47f837f966 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -1755,8 +1755,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" // Bypass all the validations in add_item explicitly. debug!( "instantiate_template: inserting nested \ - instantiation item: {:?}", - sub_item + instantiation item: {sub_item:?}" ); self.add_item_to_module(&sub_item); debug_assert_eq!(sub_id, sub_item.id()); diff --git a/bindgen/ir/ty.rs b/bindgen/ir/ty.rs index 38a7f6344a..5819f1118f 100644 --- a/bindgen/ir/ty.rs +++ b/bindgen/ir/ty.rs @@ -920,8 +920,7 @@ impl Type { let Ok(inner_type) = inner else { warn!( "Failed to parse template alias \ - {:?}", - location + {location:?}" ); return Err(ParseError::Continue); }; From aa725f90a011277149d7c68c3bb5b3915aed4bb2 Mon Sep 17 00:00:00 2001 From: Adrian Taylor Date: Thu, 20 Feb 2025 08:19:03 +0000 Subject: [PATCH 913/942] Deduplicate logic to call discovery callback. No functional change - just deduplicating the logic which calls this callback, which will make it easier to make further changes in future. Part of https://github.com/google/autocxx/issues/124 --- bindgen/codegen/mod.rs | 108 ++++++++++++++++++++--------------------- 1 file changed, 52 insertions(+), 56 deletions(-) diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index bdda6add57..09ed9a36c0 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -993,16 +993,13 @@ impl CodeGenerator for Type { let rust_name = ctx.rust_ident(&name); - ctx.options().for_each_callback(|cb| { - cb.new_item_found( - DiscoveredItemId::new(item.id().as_usize()), - DiscoveredItem::Alias { - alias_name: rust_name.to_string(), - alias_for: DiscoveredItemId::new( - inner_item.id().as_usize(), - ), - }, - ); + utils::call_discovered_item_callback(ctx, item, || { + DiscoveredItem::Alias { + alias_name: rust_name.to_string(), + alias_for: DiscoveredItemId::new( + inner_item.id().as_usize(), + ), + } }); let mut tokens = if let Some(comment) = item.comment(ctx) { @@ -2477,28 +2474,23 @@ impl CodeGenerator for CompInfo { let is_rust_union = is_union && struct_layout.is_rust_union(); - let discovered_id = DiscoveredItemId::new(item.id().as_usize()); - ctx.options().for_each_callback(|cb| { - let discovered_item = match self.kind() { - CompKind::Struct => DiscoveredItem::Struct { - original_name: item - .kind() - .expect_type() - .name() - .map(String::from), - final_name: canonical_ident.to_string(), - }, - CompKind::Union => DiscoveredItem::Union { - original_name: item - .kind() - .expect_type() - .name() - .map(String::from), - final_name: canonical_ident.to_string(), - }, - }; - - cb.new_item_found(discovered_id, discovered_item); + utils::call_discovered_item_callback(ctx, item, || match self.kind() { + CompKind::Struct => DiscoveredItem::Struct { + original_name: item + .kind() + .expect_type() + .name() + .map(String::from), + final_name: canonical_ident.to_string(), + }, + CompKind::Union => DiscoveredItem::Union { + original_name: item + .kind() + .expect_type() + .name() + .map(String::from), + final_name: canonical_ident.to_string(), + }, }); // The custom derives callback may return a list of derive attributes; @@ -2696,6 +2688,7 @@ impl CodeGenerator for CompInfo { } let mut method_names = Default::default(); + let discovered_id = DiscoveredItemId::new(item.id().as_usize()); if ctx.options().codegen_config.methods() { for method in self.methods() { assert_ne!(method.kind(), MethodKind::Constructor); @@ -3017,7 +3010,6 @@ impl Method { // First of all, output the actual function. let function_item = ctx.resolve_item(self.signature()); - let id = DiscoveredItemId::new(function_item.id().as_usize()); if !function_item.process_before_codegen(ctx, result) { return; } @@ -3064,14 +3056,11 @@ impl Method { method_names.insert(name.clone()); - ctx.options().for_each_callback(|cb| { - cb.new_item_found( - id, - DiscoveredItem::Method { - parent: parent_id, - final_name: name.clone(), - }, - ); + utils::call_discovered_item_callback(ctx, function_item, || { + DiscoveredItem::Method { + parent: parent_id, + final_name: name.clone(), + } }); let mut function_name = function_item.canonical_name(ctx); @@ -3801,13 +3790,10 @@ impl CodeGenerator for Enum { let repr = repr.to_rust_ty_or_opaque(ctx, item); let has_typedef = ctx.is_enum_typedef_combo(item.id()); - ctx.options().for_each_callback(|cb| { - cb.new_item_found( - DiscoveredItemId::new(item.id().as_usize()), - DiscoveredItem::Enum { - final_name: name.to_string(), - }, - ); + utils::call_discovered_item_callback(ctx, item, || { + DiscoveredItem::Enum { + final_name: name.to_string(), + } }); let mut builder = EnumBuilder::new( @@ -4592,7 +4578,6 @@ impl CodeGenerator for Function { ) -> Self::Return { debug!("::codegen: item = {item:?}"); debug_assert!(item.is_enabled_for_codegen(ctx)); - let id = DiscoveredItemId::new(item.id().as_usize()); let is_internal = matches!(self.linkage(), Linkage::Internal); @@ -4709,13 +4694,10 @@ impl CodeGenerator for Function { if times_seen > 0 { write!(&mut canonical_name, "{times_seen}").unwrap(); } - ctx.options().for_each_callback(|cb| { - cb.new_item_found( - id, - DiscoveredItem::Function { - final_name: canonical_name.to_string(), - }, - ); + utils::call_discovered_item_callback(ctx, item, || { + DiscoveredItem::Function { + final_name: canonical_name.to_string(), + } }); let link_name_attr = self.link_name().or_else(|| { @@ -5256,6 +5238,7 @@ pub(crate) mod utils { use super::helpers::BITFIELD_UNIT; use super::serialize::CSerialize; use super::{error, CodegenError, CodegenResult, ToRustTyOrOpaque}; + use crate::callbacks::DiscoveredItemId; use crate::ir::context::BindgenContext; use crate::ir::context::TypeId; use crate::ir::function::{Abi, ClangAbi, FunctionSig}; @@ -5985,4 +5968,17 @@ pub(crate) mod utils { true } + + pub(super) fn call_discovered_item_callback( + ctx: &BindgenContext, + item: &Item, + discovered_item_creator: impl Fn() -> crate::callbacks::DiscoveredItem, + ) { + ctx.options().for_each_callback(|cb| { + cb.new_item_found( + DiscoveredItemId::new(item.id().as_usize()), + discovered_item_creator(), + ); + }); + } } From a34c91f10c28f78f999f38ac7bb978e33a4cc243 Mon Sep 17 00:00:00 2001 From: Adrian Taylor Date: Wed, 19 Feb 2025 16:54:05 +0000 Subject: [PATCH 914/942] Include source location in callback. This adds more information to ParseCallbacks which indicates the location in the original source code at which a given item was found. This has proven to be useful in downstream code generators in providing diagnostics to explain why a given item can't be represented in Rust. (There are lots of reasons why this might not be the case - autocxx has around 100 which can be found here - https://github.com/google/autocxx/blob/d85eac76c9b3089d0d86249e857ff0e8c36b988f/engine/src/conversion/convert_error.rs#L39 - but irrespective of the specific reasons, it's useful to be able to point to the original location when emitting diagnostics). Should we make this a new callback or include this information within the existing callback? Pros of making it a new callback: * No compatibility breakage. Pros of including it in this existing callback: * No need to specify and test a policy about whether such callbacks always happen together, or may arrive individually * Easier for recipients (including bindgen's own test suite) to keep track of the source code location received. * Because we add new items to the DiscoveryItem enum anyway, we seem to have accepted it's OK to break compatibility in this callback (for now at least). Therefore I'm adding it as a parameter to the existing callback. If it's deemed acceptable to break compatibility in this way, I will follow the same thought process for some other changes too. Part of https://github.com/google/autocxx/issues/124. --- .../item_discovery_callback/mod.rs | 284 +++++++++++++----- bindgen/callbacks.rs | 16 +- bindgen/codegen/mod.rs | 11 + 3 files changed, 236 insertions(+), 75 deletions(-) diff --git a/bindgen-tests/tests/parse_callbacks/item_discovery_callback/mod.rs b/bindgen-tests/tests/parse_callbacks/item_discovery_callback/mod.rs index 6a6d0149f5..8873ecede9 100644 --- a/bindgen-tests/tests/parse_callbacks/item_discovery_callback/mod.rs +++ b/bindgen-tests/tests/parse_callbacks/item_discovery_callback/mod.rs @@ -4,23 +4,57 @@ use std::rc::Rc; use regex::Regex; -use bindgen::callbacks::{DiscoveredItem, DiscoveredItemId, ParseCallbacks}; +use bindgen::callbacks::{ + DiscoveredItem, DiscoveredItemId, ParseCallbacks, SourceLocation, +}; use bindgen::Builder; #[derive(Debug, Default)] struct ItemDiscovery(Rc>); -pub type ItemCache = HashMap; +pub type ItemCache = HashMap; + +#[derive(Debug)] +pub struct DiscoveredInformation(DiscoveredItem, Option); impl ParseCallbacks for ItemDiscovery { - fn new_item_found(&self, _id: DiscoveredItemId, _item: DiscoveredItem) { - self.0.borrow_mut().insert(_id, _item); + fn new_item_found( + &self, + id: DiscoveredItemId, + item: DiscoveredItem, + source_location: Option<&SourceLocation>, + ) { + self.0 + .borrow_mut() + .insert(id, DiscoveredInformation(item, source_location.cloned())); } } +#[derive(Debug)] +pub struct ItemExpectations { + item: DiscoveredItem, + source_location: Option<(usize, usize, usize)>, +} + +impl ItemExpectations { + fn new( + item: DiscoveredItem, + line: usize, + col: usize, + byte_offset: usize, + ) -> Self { + Self { + item, + source_location: Some((line, col, byte_offset)), + } + } +} + +type ExpectationMap = HashMap; + fn test_item_discovery_callback( header: &str, - expected: &HashMap, + expected: &HashMap, ) { let discovery = ItemDiscovery::default(); let info = Rc::clone(&discovery.0); @@ -34,72 +68,117 @@ fn test_item_discovery_callback( .generate() .expect("TODO: panic message"); - compare_item_caches(&info.borrow(), expected); + compare_item_caches(&info.borrow(), expected, header); } #[test] fn test_item_discovery_callback_c() { - let expected = ItemCache::from([ + let expected = ExpectationMap::from([ ( DiscoveredItemId::new(10), - DiscoveredItem::Struct { - original_name: Some("NamedStruct".to_string()), - final_name: "NamedStruct".to_string(), - }, + ItemExpectations::new( + DiscoveredItem::Struct { + original_name: Some("NamedStruct".to_string()), + final_name: "NamedStruct".to_string(), + }, + 4, + 8, + 73, + ), ), ( DiscoveredItemId::new(11), - DiscoveredItem::Alias { - alias_name: "AliasOfNamedStruct".to_string(), - alias_for: DiscoveredItemId::new(10), - }, + ItemExpectations::new( + DiscoveredItem::Alias { + alias_name: "AliasOfNamedStruct".to_string(), + alias_for: DiscoveredItemId::new(10), + }, + 7, + 28, + 118, + ), ), ( DiscoveredItemId::new(20), - DiscoveredItem::Union { - original_name: Some("NamedUnion".to_string()), - final_name: "NamedUnion".to_string(), - }, + ItemExpectations::new( + DiscoveredItem::Union { + original_name: Some("NamedUnion".to_string()), + final_name: "NamedUnion".to_string(), + }, + 13, + 7, + 209, + ), ), ( DiscoveredItemId::new(21), - DiscoveredItem::Alias { - alias_name: "AliasOfNamedUnion".to_string(), - alias_for: DiscoveredItemId::new(20), - }, + ItemExpectations::new( + DiscoveredItem::Alias { + alias_name: "AliasOfNamedUnion".to_string(), + alias_for: DiscoveredItemId::new(20), + }, + 16, + 26, + 251, + ), ), ( DiscoveredItemId::new(27), - DiscoveredItem::Alias { - alias_name: "AliasOfNamedEnum".to_string(), - alias_for: DiscoveredItemId::new(24), - }, + ItemExpectations::new( + DiscoveredItem::Alias { + alias_name: "AliasOfNamedEnum".to_string(), + alias_for: DiscoveredItemId::new(24), + }, + 28, + 24, + 515, + ), ), ( DiscoveredItemId::new(24), - DiscoveredItem::Enum { - final_name: "NamedEnum".to_string(), - }, + ItemExpectations::new( + DiscoveredItem::Enum { + final_name: "NamedEnum".to_string(), + }, + 24, + 6, + 466, + ), ), ( DiscoveredItemId::new(30), - DiscoveredItem::Struct { - original_name: None, - final_name: "_bindgen_ty_*".to_string(), - }, + ItemExpectations::new( + DiscoveredItem::Struct { + original_name: None, + final_name: "_bindgen_ty_*".to_string(), + }, + 2, + 38, + 48, + ), ), ( DiscoveredItemId::new(40), - DiscoveredItem::Union { - original_name: None, - final_name: "_bindgen_ty_*".to_string(), - }, + ItemExpectations::new( + DiscoveredItem::Union { + original_name: None, + final_name: "_bindgen_ty_*".to_string(), + }, + 11, + 37, + 186, + ), ), ( DiscoveredItemId::new(41), - DiscoveredItem::Function { - final_name: "named_function".to_string(), - }, + ItemExpectations::new( + DiscoveredItem::Function { + final_name: "named_function".to_string(), + }, + 32, + 6, + 553, + ), ), ]); test_item_discovery_callback( @@ -108,40 +187,58 @@ fn test_item_discovery_callback_c() { #[test] fn test_item_discovery_callback_cpp() { - let expected = ItemCache::from([ + let expected = ExpectationMap::from([ ( DiscoveredItemId::new(1), - DiscoveredItem::Struct { - original_name: Some("SomeClass".to_string()), - final_name: "SomeClass".to_string(), - }, + ItemExpectations::new( + DiscoveredItem::Struct { + original_name: Some("SomeClass".to_string()), + final_name: "SomeClass".to_string(), + }, + 3, + 7, + 18, + ), ), ( DiscoveredItemId::new(2), - DiscoveredItem::Method { - final_name: "named_method".to_string(), - parent: DiscoveredItemId::new(1), - }, + ItemExpectations::new( + DiscoveredItem::Method { + final_name: "named_method".to_string(), + parent: DiscoveredItemId::new(1), + }, + 5, + 10, + 47, + ), ), ]); test_item_discovery_callback( "/tests/parse_callbacks/item_discovery_callback/header_item_discovery.hpp", &expected); } -pub fn compare_item_caches(generated: &ItemCache, expected: &ItemCache) { +fn compare_item_caches( + generated: &ItemCache, + expected: &ExpectationMap, + expected_filename: &str, +) { // We can't use a simple Eq::eq comparison because of two reasons: // - anonymous structs/unions will have a final name generated by bindgen which may change // if the header file or the bindgen logic is altered // - aliases have a DiscoveredItemId that we can't directly compare for the same instability reasons for expected_item in expected.values() { - let found = generated.iter().find(|(_generated_id, generated_item)| { - compare_item_info( - expected_item, - generated_item, - expected, - generated, - ) - }); + let found = + generated + .iter() + .find(|(_generated_id, generated_item)| { + compare_item_info( + expected_item, + generated_item, + expected, + generated, + expected_filename, + ) + }); assert!( found.is_some(), @@ -151,40 +248,72 @@ pub fn compare_item_caches(generated: &ItemCache, expected: &ItemCache) { } fn compare_item_info( - expected_item: &DiscoveredItem, - generated_item: &DiscoveredItem, - expected: &ItemCache, + expected_item: &ItemExpectations, + generated_item: &DiscoveredInformation, + expected: &ExpectationMap, generated: &ItemCache, + expected_filename: &str, ) -> bool { - if std::mem::discriminant(expected_item) != - std::mem::discriminant(generated_item) + if std::mem::discriminant(&expected_item.item) + != std::mem::discriminant(&generated_item.0) { return false; } - match generated_item { + let is_a_match = match generated_item.0 { DiscoveredItem::Struct { .. } => { - compare_struct_info(expected_item, generated_item) + compare_struct_info(&expected_item.item, &generated_item.0) } DiscoveredItem::Union { .. } => { - compare_union_info(expected_item, generated_item) + compare_union_info(&expected_item.item, &generated_item.0) } DiscoveredItem::Alias { .. } => compare_alias_info( - expected_item, - generated_item, + &expected_item.item, + &generated_item.0, expected, generated, + expected_filename, ), DiscoveredItem::Enum { .. } => { - compare_enum_info(expected_item, generated_item) + compare_enum_info(&expected_item.item, &generated_item.0) } DiscoveredItem::Function { .. } => { - compare_function_info(expected_item, generated_item) + compare_function_info(&expected_item.item, &generated_item.0) } DiscoveredItem::Method { .. } => { - compare_method_info(expected_item, generated_item) + compare_method_info(&expected_item.item, &generated_item.0) + } + }; + + if is_a_match { + // Compare source location + assert!( + generated_item.1.is_some() + == expected_item.source_location.is_some(), + "No source location provided when one was expected" + ); + if let Some(generated_location) = generated_item.1.as_ref() { + let expected_location = expected_item.source_location.unwrap(); + assert!( + generated_location + .file_name + .as_ref() + .expect("No filename provided") + .ends_with(expected_filename), + "Filename differed" + ); + assert_eq!( + ( + generated_location.line, + generated_location.col, + generated_location.byte_offset + ), + expected_location, + "Line/col/offsets differ" + ); } } + is_a_match } pub fn compare_names(expected_name: &str, generated_name: &str) -> bool { @@ -288,8 +417,9 @@ pub fn compare_enum_info( pub fn compare_alias_info( expected_item: &DiscoveredItem, generated_item: &DiscoveredItem, - expected: &ItemCache, + expected: &ExpectationMap, generated: &ItemCache, + expected_filename: &str, ) -> bool { let DiscoveredItem::Alias { alias_name: expected_alias_name, @@ -319,7 +449,13 @@ pub fn compare_alias_info( return false; }; - compare_item_info(expected_aliased, generated_aliased, expected, generated) + compare_item_info( + expected_aliased, + generated_aliased, + expected, + generated, + expected_filename, + ) } pub fn compare_function_info( diff --git a/bindgen/callbacks.rs b/bindgen/callbacks.rs index 8ad06b3375..ea53f0fbb0 100644 --- a/bindgen/callbacks.rs +++ b/bindgen/callbacks.rs @@ -169,7 +169,7 @@ pub trait ParseCallbacks: fmt::Debug { } /// This will get called everytime an item (currently struct, union, and alias) is found with some information about it - fn new_item_found(&self, _id: DiscoveredItemId, _item: DiscoveredItem) {} + fn new_item_found(&self, _id: DiscoveredItemId, _item: DiscoveredItem, _source_location: Option<&SourceLocation>) {} // TODO add callback for ResolvedTypeRef } @@ -315,3 +315,17 @@ pub struct FieldInfo<'a> { /// The name of the type of the field. pub field_type_name: Option<&'a str>, } + +/// Location in the source code. Roughly equivalent to the same type +/// within `clang_sys`. +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct SourceLocation { + /// Line number. + pub line: usize, + /// Column number within line. + pub col: usize, + /// Byte offset within file. + pub byte_offset: usize, + /// Filename, if known. + pub file_name: Option, +} diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 09ed9a36c0..c0f461b326 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -5974,10 +5974,21 @@ pub(crate) mod utils { item: &Item, discovered_item_creator: impl Fn() -> crate::callbacks::DiscoveredItem, ) { + let source_location = item.location().map(|clang_location| { + let (file, line, col, byte_offset) = clang_location.location(); + let file_name = file.name(); + crate::callbacks::SourceLocation { + line, + col, + byte_offset, + file_name, + } + }); ctx.options().for_each_callback(|cb| { cb.new_item_found( DiscoveredItemId::new(item.id().as_usize()), discovered_item_creator(), + source_location.as_ref(), ); }); } From f015c10d0861e41ca33e8af463f01277dbc9b251 Mon Sep 17 00:00:00 2001 From: Adrian Taylor Date: Thu, 20 Feb 2025 13:09:01 +0000 Subject: [PATCH 915/942] Clippy formatting fixes. --- .../item_discovery_callback/mod.rs | 29 +++++++++---------- bindgen/callbacks.rs | 8 ++++- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/bindgen-tests/tests/parse_callbacks/item_discovery_callback/mod.rs b/bindgen-tests/tests/parse_callbacks/item_discovery_callback/mod.rs index 8873ecede9..a9a9523895 100644 --- a/bindgen-tests/tests/parse_callbacks/item_discovery_callback/mod.rs +++ b/bindgen-tests/tests/parse_callbacks/item_discovery_callback/mod.rs @@ -227,18 +227,15 @@ fn compare_item_caches( // if the header file or the bindgen logic is altered // - aliases have a DiscoveredItemId that we can't directly compare for the same instability reasons for expected_item in expected.values() { - let found = - generated - .iter() - .find(|(_generated_id, generated_item)| { - compare_item_info( - expected_item, - generated_item, - expected, - generated, - expected_filename, - ) - }); + let found = generated.iter().find(|(_generated_id, generated_item)| { + compare_item_info( + expected_item, + generated_item, + expected, + generated, + expected_filename, + ) + }); assert!( found.is_some(), @@ -254,8 +251,8 @@ fn compare_item_info( generated: &ItemCache, expected_filename: &str, ) -> bool { - if std::mem::discriminant(&expected_item.item) - != std::mem::discriminant(&generated_item.0) + if std::mem::discriminant(&expected_item.item) != + std::mem::discriminant(&generated_item.0) { return false; } @@ -288,8 +285,8 @@ fn compare_item_info( if is_a_match { // Compare source location assert!( - generated_item.1.is_some() - == expected_item.source_location.is_some(), + generated_item.1.is_some() == + expected_item.source_location.is_some(), "No source location provided when one was expected" ); if let Some(generated_location) = generated_item.1.as_ref() { diff --git a/bindgen/callbacks.rs b/bindgen/callbacks.rs index ea53f0fbb0..c8ac9a5e15 100644 --- a/bindgen/callbacks.rs +++ b/bindgen/callbacks.rs @@ -169,7 +169,13 @@ pub trait ParseCallbacks: fmt::Debug { } /// This will get called everytime an item (currently struct, union, and alias) is found with some information about it - fn new_item_found(&self, _id: DiscoveredItemId, _item: DiscoveredItem, _source_location: Option<&SourceLocation>) {} + fn new_item_found( + &self, + _id: DiscoveredItemId, + _item: DiscoveredItem, + _source_location: Option<&SourceLocation>, + ) { + } // TODO add callback for ResolvedTypeRef } From bd011d43e2d18078606350eb8c33048bf8a59bac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Fri, 11 Jul 2025 22:45:07 +0200 Subject: [PATCH 916/942] comp: Fix alignment of bitfields in some edge cases. In order to properly compute the size of the bitfield for overaligned fields, we need to know the offset in the struct, not just in the allocation unit. E.g., something like: char; // Byte 1 char: 8; // Byte 2 short: 16; // Bytes 3 and 4 Should align differently than: char: 8; // Byte 1 short: 16; // Bytes 3 and 4 If we can't find the start offset in the struct, we fall back to our previous behavior (this can happen with C++ templates for example). We remove some code related to `is_ms_struct`, which was effectively dead. If someone cares about it they can resurrect it. We also don't align per-bitfield unit, but in order to mostly preserve behavior, we keep inserting a field at the beginning of the struct rather than using repr(align). Otherwise we hit #2179 in cases where we did not use to. We might want to extend that approach to repr(align) stuff, in order to try to fix #2179 more often, but for now do the minimal change. Fixes #1377 Fixes #3105 Fixes #743 Fixes #981 Fixes #1314 Co-authored-by: qinghon --- bindgen-integration/src/lib.rs | 5 +- .../tests/bitfield-32bit-overflow.rs | 1 - .../expectations/tests/bitfield-large.rs | 2 - .../expectations/tests/bitfield-linux-32.rs | 9 +- .../tests/bitfield-method-same-name.rs | 1 - .../expectations/tests/bitfield-template.rs | 214 ++++++++ .../expectations/tests/bitfield_align.rs | 15 +- .../expectations/tests/bitfield_align_2.rs | 2 +- .../tests/bitfield_large_overflow.rs | 2 +- .../tests/bitfield_method_mangling.rs | 2 +- .../tests/bitfield_pack_offset.rs | 507 ++++++++++++++++++ .../tests/bitfield_pragma_packed.rs | 3 +- .../tests/blocklist_bitfield_unit.rs | 1 - .../tests/default_visibility_crate.rs | 1 - .../tests/default_visibility_private.rs | 1 - ...bility_private_respects_cxx_access_spec.rs | 1 - .../tests/derive-bitfield-method-same-name.rs | 1 - .../tests/derive-debug-bitfield-1-51.rs | 1 - .../tests/derive-debug-bitfield-core.rs | 1 - .../tests/derive-debug-bitfield.rs | 1 - .../tests/derive-partialeq-bitfield.rs | 1 - .../tests/divide-by-zero-in-struct-layout.rs | 3 - .../tests/field-visibility-callback.rs | 1 - .../expectations/tests/field-visibility.rs | 6 +- .../tests/incomplete-array-padding.rs | 1 - .../tests/expectations/tests/issue-1034.rs | 1 - .../issue-1076-unnamed-bitfield-alignment.rs | 1 - .../tests/expectations/tests/issue-1947.rs | 3 +- .../tests/issue-739-pointer-wide-bitfield.rs | 2 +- .../tests/expectations/tests/issue-743.rs | 225 ++++++++ .../tests/expectations/tests/issue-816.rs | 3 +- .../expectations/tests/jsval_layout_opaque.rs | 2 +- .../tests/expectations/tests/layout_align.rs | 3 +- .../expectations/tests/layout_eth_conf.rs | 2 - .../tests/expectations/tests/layout_mbuf.rs | 7 +- .../expectations/tests/only_bitfields.rs | 1 - .../expectations/tests/packed-bitfield.rs | 1 - .../expectations/tests/private_fields.rs | 10 +- .../tests/redundant-packed-and-align.rs | 3 +- .../tests/struct_with_bitfields.rs | 2 - .../tests/expectations/tests/timex.rs | 2 - .../expectations/tests/union_bitfield.rs | 30 +- .../tests/union_with_anon_struct_bitfield.rs | 2 +- .../expectations/tests/weird_bitfields.rs | 2 - .../tests/headers/bitfield-linux-32.hpp | 2 +- .../tests/headers/bitfield-template.hpp | 4 + .../tests/headers/bitfield_pack_offset.h | 21 + bindgen-tests/tests/headers/issue-743.h | 6 + bindgen-tests/tests/headers/union_bitfield.h | 6 +- bindgen/codegen/mod.rs | 38 +- bindgen/codegen/struct_layout.rs | 31 -- bindgen/ir/comp.rs | 103 ++-- 52 files changed, 1074 insertions(+), 222 deletions(-) create mode 100644 bindgen-tests/tests/expectations/tests/bitfield-template.rs create mode 100644 bindgen-tests/tests/expectations/tests/bitfield_pack_offset.rs create mode 100644 bindgen-tests/tests/expectations/tests/issue-743.rs create mode 100644 bindgen-tests/tests/headers/bitfield-template.hpp create mode 100644 bindgen-tests/tests/headers/bitfield_pack_offset.h create mode 100644 bindgen-tests/tests/headers/issue-743.h diff --git a/bindgen-integration/src/lib.rs b/bindgen-integration/src/lib.rs index 64f4926a8b..c5362bf450 100755 --- a/bindgen-integration/src/lib.rs +++ b/bindgen-integration/src/lib.rs @@ -178,19 +178,18 @@ fn test_bitfields_seventh() { fn test_bitfield_constructors() { use std::mem; let mut first = bindings::bitfields::First { - _bitfield_align_1: [], _bitfield_1: bindings::bitfields::First::new_bitfield_1(1, 2, 3), }; assert!(unsafe { first.assert(1, 2, 3) }); let mut second = bindings::bitfields::Second { - _bitfield_align_1: [], + _bindgen_align: [], _bitfield_1: bindings::bitfields::Second::new_bitfield_1(1337, true), }; assert!(unsafe { second.assert(1337, true) }); let mut third = bindings::bitfields::Third { - _bitfield_align_1: [], + _bindgen_align: [], _bitfield_1: bindings::bitfields::Third::new_bitfield_1( 42, false, diff --git a/bindgen-tests/tests/expectations/tests/bitfield-32bit-overflow.rs b/bindgen-tests/tests/expectations/tests/bitfield-32bit-overflow.rs index 81ce12a5c9..783f0ef7a9 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-32bit-overflow.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-32bit-overflow.rs @@ -148,7 +148,6 @@ where #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct MuchBitfield { - pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 5usize]>, } #[allow(clippy::unnecessary_operation, clippy::identity_op)] diff --git a/bindgen-tests/tests/expectations/tests/bitfield-large.rs b/bindgen-tests/tests/expectations/tests/bitfield-large.rs index 8024d88c3b..5d614ab936 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-large.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-large.rs @@ -149,7 +149,6 @@ where #[repr(align(16))] #[derive(Debug, Default, Copy, Clone)] pub struct HasBigBitfield { - pub _bitfield_align_1: [u64; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 16usize]>, } #[allow(clippy::unnecessary_operation, clippy::identity_op)] @@ -213,7 +212,6 @@ impl HasBigBitfield { #[repr(align(16))] #[derive(Debug, Default, Copy, Clone)] pub struct HasTwoBigBitfields { - pub _bitfield_align_1: [u64; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 16usize]>, } #[allow(clippy::unnecessary_operation, clippy::identity_op)] diff --git a/bindgen-tests/tests/expectations/tests/bitfield-linux-32.rs b/bindgen-tests/tests/expectations/tests/bitfield-linux-32.rs index 8b0b37b481..3e676c53b5 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-linux-32.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-linux-32.rs @@ -145,19 +145,12 @@ where } } } -#[repr(C, packed(4))] +#[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Test { pub foo: u64, - pub _bitfield_align_1: [u64; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 8usize]>, } -#[allow(clippy::unnecessary_operation, clippy::identity_op)] -const _: () = { - ["Size of Test"][::std::mem::size_of::() - 16usize]; - ["Alignment of Test"][::std::mem::align_of::() - 4usize]; - ["Offset of field: Test::foo"][::std::mem::offset_of!(Test, foo) - 0usize]; -}; impl Test { #[inline] pub fn x(&self) -> u64 { diff --git a/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs b/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs index 84e152f3fd..09ca005589 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield-method-same-name.rs @@ -148,7 +148,6 @@ where #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { - pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, } #[allow(clippy::unnecessary_operation, clippy::identity_op)] diff --git a/bindgen-tests/tests/expectations/tests/bitfield-template.rs b/bindgen-tests/tests/expectations/tests/bitfield-template.rs new file mode 100644 index 0000000000..eb454e0db4 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/bitfield-template.rs @@ -0,0 +1,214 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[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) }; + } + } +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct foo { + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell>, + pub member: T, + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, +} +impl Default for foo { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +impl foo { + #[inline] + pub fn b(&self) -> bool { + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 8u8) as u8) } + } + #[inline] + pub fn set_b(&mut self, val: bool) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + self._bitfield_1.set(0usize, 8u8, val as u64) + } + } + #[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), 0usize, 8u8) 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), + 0usize, + 8u8, + val as u64, + ) + } + } + #[inline] + pub fn new_bitfield_1(b: bool) -> __BindgenBitfieldUnit<[u8; 1usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 8u8, + { + let b: u8 = unsafe { ::std::mem::transmute(b) }; + b as u64 + }, + ); + __bindgen_bitfield_unit + } +} diff --git a/bindgen-tests/tests/expectations/tests/bitfield_align.rs b/bindgen-tests/tests/expectations/tests/bitfield_align.rs index 5f1321bbb1..0c70917fc5 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_align.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_align.rs @@ -146,11 +146,10 @@ where } } #[repr(C)] -#[repr(align(4))] #[derive(Debug, Default, Copy, Clone)] pub struct A { + pub _bindgen_align: [u32; 0], pub x: ::std::os::raw::c_uchar, - pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 2usize]>, pub y: ::std::os::raw::c_uchar, } @@ -632,7 +631,7 @@ impl A { #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct B { - pub _bitfield_align_1: [u32; 0], + pub _bindgen_align: [u32; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, } #[allow(clippy::unnecessary_operation, clippy::identity_op)] @@ -744,7 +743,6 @@ impl B { #[derive(Debug, Default, Copy, Clone)] pub struct C { pub x: ::std::os::raw::c_uchar, - pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub baz: ::std::os::raw::c_uint, } @@ -856,10 +854,9 @@ impl C { } } #[repr(C)] -#[repr(align(2))] #[derive(Debug, Default, Copy, Clone)] pub struct Date1 { - pub _bitfield_align_1: [u8; 0], + pub _bindgen_align: [u16; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 3usize]>, pub __bindgen_padding_0: u8, } @@ -1061,10 +1058,9 @@ impl Date1 { } } #[repr(C)] -#[repr(align(2))] #[derive(Debug, Default, Copy, Clone)] pub struct Date2 { - pub _bitfield_align_1: [u8; 0], + pub _bindgen_align: [u16; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, } #[allow(clippy::unnecessary_operation, clippy::identity_op)] @@ -1311,10 +1307,9 @@ impl Date2 { } } #[repr(C)] -#[repr(align(2))] #[derive(Debug, Default, Copy, Clone)] pub struct Date3 { - pub _bitfield_align_1: [u8; 0], + pub _bindgen_align: [u16; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 3usize]>, pub byte: ::std::os::raw::c_uchar, } diff --git a/bindgen-tests/tests/expectations/tests/bitfield_align_2.rs b/bindgen-tests/tests/expectations/tests/bitfield_align_2.rs index 2a676d5636..b71bba18ad 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_align_2.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_align_2.rs @@ -157,7 +157,7 @@ pub enum MyEnum { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct TaggedPtr { - pub _bitfield_align_1: [u64; 0], + pub _bindgen_align: [u64; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 8usize]>, } #[allow(clippy::unnecessary_operation, clippy::identity_op)] diff --git a/bindgen-tests/tests/expectations/tests/bitfield_large_overflow.rs b/bindgen-tests/tests/expectations/tests/bitfield_large_overflow.rs index 51c777497b..ed7d1b3bb7 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_large_overflow.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_large_overflow.rs @@ -1,8 +1,8 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] #[repr(C)] -#[repr(align(8))] #[derive(Debug, Default, Copy, Clone)] pub struct _bindgen_ty_1 { + pub _bindgen_align: [u64; 0], pub _bindgen_opaque_blob: [u64; 10usize], } #[allow(clippy::unnecessary_operation, clippy::identity_op)] diff --git a/bindgen-tests/tests/expectations/tests/bitfield_method_mangling.rs b/bindgen-tests/tests/expectations/tests/bitfield_method_mangling.rs index 1a08cd00f9..35117c74b6 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_method_mangling.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_method_mangling.rs @@ -148,7 +148,7 @@ where #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct mach_msg_type_descriptor_t { - pub _bitfield_align_1: [u32; 0], + pub _bindgen_align: [u32; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, } #[allow(clippy::unnecessary_operation, clippy::identity_op)] diff --git a/bindgen-tests/tests/expectations/tests/bitfield_pack_offset.rs b/bindgen-tests/tests/expectations/tests/bitfield_pack_offset.rs new file mode 100644 index 0000000000..d654e25b27 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/bitfield_pack_offset.rs @@ -0,0 +1,507 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[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) }; + } + } +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct A { + pub name: [::std::os::raw::c_uchar; 7usize], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 3usize]>, + pub maxYield: ::std::os::raw::c_uchar, + pub _bitfield_2: __BindgenBitfieldUnit<[u8; 1usize]>, + pub description1: *const ::std::os::raw::c_uchar, +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of A"][::std::mem::size_of::() - 24usize]; + ["Alignment of A"][::std::mem::align_of::() - 8usize]; + ["Offset of field: A::name"][::std::mem::offset_of!(A, name) - 0usize]; + ["Offset of field: A::maxYield"][::std::mem::offset_of!(A, maxYield) - 10usize]; + [ + "Offset of field: A::description1", + ][::std::mem::offset_of!(A, description1) - 16usize]; +}; +impl Default for A { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +impl A { + #[inline] + pub fn firmness(&self) -> ::std::os::raw::c_uchar { + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 4u8) as u8) } + } + #[inline] + pub fn set_firmness(&mut self, val: ::std::os::raw::c_uchar) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + self._bitfield_1.set(0usize, 4u8, val as u64) + } + } + #[inline] + pub unsafe fn firmness_raw(this: *const Self) -> ::std::os::raw::c_uchar { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 3usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 4u8) as u8, + ) + } + } + #[inline] + pub unsafe fn set_firmness_raw(this: *mut Self, val: ::std::os::raw::c_uchar) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 3usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 0usize, + 4u8, + val as u64, + ) + } + } + #[inline] + pub fn color(&self) -> ::std::os::raw::c_uchar { + unsafe { ::std::mem::transmute(self._bitfield_1.get(4usize, 4u8) as u8) } + } + #[inline] + pub fn set_color(&mut self, val: ::std::os::raw::c_uchar) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + self._bitfield_1.set(4usize, 4u8, val as u64) + } + } + #[inline] + pub unsafe fn color_raw(this: *const Self) -> ::std::os::raw::c_uchar { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 3usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 4usize, 4u8) as u8, + ) + } + } + #[inline] + pub unsafe fn set_color_raw(this: *mut Self, val: ::std::os::raw::c_uchar) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 3usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 4usize, + 4u8, + val as u64, + ) + } + } + #[inline] + pub fn weedsBonus(&self) -> ::std::os::raw::c_ushort { + unsafe { ::std::mem::transmute(self._bitfield_1.get(8usize, 3u8) as u16) } + } + #[inline] + pub fn set_weedsBonus(&mut self, val: ::std::os::raw::c_ushort) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + self._bitfield_1.set(8usize, 3u8, val as u64) + } + } + #[inline] + pub unsafe fn weedsBonus_raw(this: *const Self) -> ::std::os::raw::c_ushort { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 3usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 8usize, 3u8) + as u16, + ) + } + } + #[inline] + pub unsafe fn set_weedsBonus_raw(this: *mut Self, val: ::std::os::raw::c_ushort) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 3usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 8usize, + 3u8, + val as u64, + ) + } + } + #[inline] + pub fn pestsBonus(&self) -> ::std::os::raw::c_ushort { + unsafe { ::std::mem::transmute(self._bitfield_1.get(11usize, 3u8) as u16) } + } + #[inline] + pub fn set_pestsBonus(&mut self, val: ::std::os::raw::c_ushort) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + self._bitfield_1.set(11usize, 3u8, val as u64) + } + } + #[inline] + pub unsafe fn pestsBonus_raw(this: *const Self) -> ::std::os::raw::c_ushort { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 3usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 11usize, 3u8) + as u16, + ) + } + } + #[inline] + pub unsafe fn set_pestsBonus_raw(this: *mut Self, val: ::std::os::raw::c_ushort) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 3usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 11usize, + 3u8, + val as u64, + ) + } + } + #[inline] + pub fn size(&self) -> ::std::os::raw::c_ushort { + unsafe { ::std::mem::transmute(self._bitfield_1.get(14usize, 10u8) as u16) } + } + #[inline] + pub fn set_size(&mut self, val: ::std::os::raw::c_ushort) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + self._bitfield_1.set(14usize, 10u8, val as u64) + } + } + #[inline] + pub unsafe fn size_raw(this: *const Self) -> ::std::os::raw::c_ushort { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 3usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 14usize, 10u8) + as u16, + ) + } + } + #[inline] + pub unsafe fn set_size_raw(this: *mut Self, val: ::std::os::raw::c_ushort) { + unsafe { + let val: u16 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 3usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 14usize, + 10u8, + val as u64, + ) + } + } + #[inline] + pub fn new_bitfield_1( + firmness: ::std::os::raw::c_uchar, + color: ::std::os::raw::c_uchar, + weedsBonus: ::std::os::raw::c_ushort, + pestsBonus: ::std::os::raw::c_ushort, + size: ::std::os::raw::c_ushort, + ) -> __BindgenBitfieldUnit<[u8; 3usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 3usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 4u8, + { + let firmness: u8 = unsafe { ::std::mem::transmute(firmness) }; + firmness as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 4usize, + 4u8, + { + let color: u8 = unsafe { ::std::mem::transmute(color) }; + color as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 8usize, + 3u8, + { + let weedsBonus: u16 = unsafe { ::std::mem::transmute(weedsBonus) }; + weedsBonus as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 11usize, + 3u8, + { + let pestsBonus: u16 = unsafe { ::std::mem::transmute(pestsBonus) }; + pestsBonus as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 14usize, + 10u8, + { + let size: u16 = unsafe { ::std::mem::transmute(size) }; + size as u64 + }, + ); + __bindgen_bitfield_unit + } + #[inline] + pub fn minYield(&self) -> ::std::os::raw::c_uchar { + unsafe { ::std::mem::transmute(self._bitfield_2.get(0usize, 4u8) as u8) } + } + #[inline] + pub fn set_minYield(&mut self, val: ::std::os::raw::c_uchar) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + self._bitfield_2.set(0usize, 4u8, val as u64) + } + } + #[inline] + pub unsafe fn minYield_raw(this: *const Self) -> ::std::os::raw::c_uchar { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_2), 0usize, 4u8) as u8, + ) + } + } + #[inline] + pub unsafe fn set_minYield_raw(this: *mut Self, val: ::std::os::raw::c_uchar) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_2), + 0usize, + 4u8, + val as u64, + ) + } + } + #[inline] + pub fn waterBonus(&self) -> ::std::os::raw::c_uchar { + unsafe { ::std::mem::transmute(self._bitfield_2.get(4usize, 4u8) as u8) } + } + #[inline] + pub fn set_waterBonus(&mut self, val: ::std::os::raw::c_uchar) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + self._bitfield_2.set(4usize, 4u8, val as u64) + } + } + #[inline] + pub unsafe fn waterBonus_raw(this: *const Self) -> ::std::os::raw::c_uchar { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_2), 4usize, 4u8) as u8, + ) + } + } + #[inline] + pub unsafe fn set_waterBonus_raw(this: *mut Self, val: ::std::os::raw::c_uchar) { + unsafe { + let val: u8 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 1usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_2), + 4usize, + 4u8, + val as u64, + ) + } + } + #[inline] + pub fn new_bitfield_2( + minYield: ::std::os::raw::c_uchar, + waterBonus: ::std::os::raw::c_uchar, + ) -> __BindgenBitfieldUnit<[u8; 1usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 4u8, + { + let minYield: u8 = unsafe { ::std::mem::transmute(minYield) }; + minYield as u64 + }, + ); + __bindgen_bitfield_unit + .set( + 4usize, + 4u8, + { + let waterBonus: u8 = unsafe { ::std::mem::transmute(waterBonus) }; + waterBonus as u64 + }, + ); + __bindgen_bitfield_unit + } +} diff --git a/bindgen-tests/tests/expectations/tests/bitfield_pragma_packed.rs b/bindgen-tests/tests/expectations/tests/bitfield_pragma_packed.rs index 8869593ed5..6f9adcb5ab 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_pragma_packed.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_pragma_packed.rs @@ -148,7 +148,6 @@ where #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Struct { - pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, } #[allow(clippy::unnecessary_operation, clippy::identity_op)] @@ -394,7 +393,7 @@ impl Struct { #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Inner { - pub _bitfield_align_1: [u16; 0], + pub _bindgen_align: [u16; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, } #[allow(clippy::unnecessary_operation, clippy::identity_op)] diff --git a/bindgen-tests/tests/expectations/tests/blocklist_bitfield_unit.rs b/bindgen-tests/tests/expectations/tests/blocklist_bitfield_unit.rs index fc9f9a38c7..77c263e3cc 100644 --- a/bindgen-tests/tests/expectations/tests/blocklist_bitfield_unit.rs +++ b/bindgen-tests/tests/expectations/tests/blocklist_bitfield_unit.rs @@ -6,7 +6,6 @@ use bitfields::*; #[derive(Debug, Default, Copy, Clone)] pub struct C { pub x: ::std::os::raw::c_uchar, - pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub baz: ::std::os::raw::c_uint, } diff --git a/bindgen-tests/tests/expectations/tests/default_visibility_crate.rs b/bindgen-tests/tests/expectations/tests/default_visibility_crate.rs index aeb6a717f6..aeefb2e0f9 100644 --- a/bindgen-tests/tests/expectations/tests/default_visibility_crate.rs +++ b/bindgen-tests/tests/expectations/tests/default_visibility_crate.rs @@ -154,7 +154,6 @@ pub struct Point { #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Color { - pub(crate) _bitfield_align_1: [u8; 0], pub(crate) _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, } impl Color { diff --git a/bindgen-tests/tests/expectations/tests/default_visibility_private.rs b/bindgen-tests/tests/expectations/tests/default_visibility_private.rs index 4ee26721b0..dceed75e36 100644 --- a/bindgen-tests/tests/expectations/tests/default_visibility_private.rs +++ b/bindgen-tests/tests/expectations/tests/default_visibility_private.rs @@ -154,7 +154,6 @@ pub struct Point { #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Color { - _bitfield_align_1: [u8; 0], _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, } impl Color { diff --git a/bindgen-tests/tests/expectations/tests/default_visibility_private_respects_cxx_access_spec.rs b/bindgen-tests/tests/expectations/tests/default_visibility_private_respects_cxx_access_spec.rs index e676f6470d..f43be84bb0 100644 --- a/bindgen-tests/tests/expectations/tests/default_visibility_private_respects_cxx_access_spec.rs +++ b/bindgen-tests/tests/expectations/tests/default_visibility_private_respects_cxx_access_spec.rs @@ -154,7 +154,6 @@ pub struct Point { #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Color { - _bitfield_align_1: [u8; 0], _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, } impl Color { 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 05e66a72bc..c2a9d33ca6 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 @@ -94,7 +94,6 @@ where #[derive(Copy, Clone)] pub struct Foo { pub large: [::std::os::raw::c_int; 33usize], - pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 2usize]>, pub __bindgen_padding_0: u16, } 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 351d3b31e5..c5eed87ae5 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 @@ -148,7 +148,6 @@ where #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct C { - pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub large_array: [::std::os::raw::c_int; 50usize], } 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 edcb4e2a02..baeb87545d 100644 --- a/bindgen-tests/tests/expectations/tests/derive-debug-bitfield-core.rs +++ b/bindgen-tests/tests/expectations/tests/derive-debug-bitfield-core.rs @@ -91,7 +91,6 @@ where #[repr(C)] #[derive(Copy, Clone)] pub struct C { - pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub large_array: [::std::os::raw::c_int; 50usize], } diff --git a/bindgen-tests/tests/expectations/tests/derive-debug-bitfield.rs b/bindgen-tests/tests/expectations/tests/derive-debug-bitfield.rs index e266880509..e414b6fa32 100644 --- a/bindgen-tests/tests/expectations/tests/derive-debug-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/derive-debug-bitfield.rs @@ -90,7 +90,6 @@ where #[repr(C)] #[derive(Copy, Clone)] pub struct C { - pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub large_array: [::std::os::raw::c_int; 50usize], } diff --git a/bindgen-tests/tests/expectations/tests/derive-partialeq-bitfield.rs b/bindgen-tests/tests/expectations/tests/derive-partialeq-bitfield.rs index eaf3f45e5f..7bcdce32a3 100644 --- a/bindgen-tests/tests/expectations/tests/derive-partialeq-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/derive-partialeq-bitfield.rs @@ -90,7 +90,6 @@ where #[repr(C)] #[derive(Copy, Clone)] pub struct C { - pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub large_array: [::std::os::raw::c_int; 50usize], } diff --git a/bindgen-tests/tests/expectations/tests/divide-by-zero-in-struct-layout.rs b/bindgen-tests/tests/expectations/tests/divide-by-zero-in-struct-layout.rs index e01a9b3c72..37139d3136 100644 --- a/bindgen-tests/tests/expectations/tests/divide-by-zero-in-struct-layout.rs +++ b/bindgen-tests/tests/expectations/tests/divide-by-zero-in-struct-layout.rs @@ -148,7 +148,6 @@ where #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct WithBitfield { - pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub a: ::std::os::raw::c_uint, } @@ -162,7 +161,6 @@ impl WithBitfield { #[repr(C, packed)] #[derive(Debug, Default, Copy, Clone)] pub struct WithBitfieldAndAttrPacked { - pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub a: ::std::os::raw::c_uint, } @@ -176,7 +174,6 @@ impl WithBitfieldAndAttrPacked { #[repr(C, packed)] #[derive(Debug, Default, Copy, Clone)] pub struct WithBitfieldAndPacked { - pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub a: ::std::os::raw::c_uint, } diff --git a/bindgen-tests/tests/expectations/tests/field-visibility-callback.rs b/bindgen-tests/tests/expectations/tests/field-visibility-callback.rs index aebc04f03b..99ca3d4b9b 100644 --- a/bindgen-tests/tests/expectations/tests/field-visibility-callback.rs +++ b/bindgen-tests/tests/expectations/tests/field-visibility-callback.rs @@ -150,7 +150,6 @@ where pub struct my_struct { pub a: ::std::os::raw::c_int, private_b: ::std::os::raw::c_int, - _bitfield_align_1: [u8; 0], _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, __bindgen_padding_0: [u8; 3usize], } diff --git a/bindgen-tests/tests/expectations/tests/field-visibility.rs b/bindgen-tests/tests/expectations/tests/field-visibility.rs index 3e43755a57..13a1d9a543 100644 --- a/bindgen-tests/tests/expectations/tests/field-visibility.rs +++ b/bindgen-tests/tests/expectations/tests/field-visibility.rs @@ -146,10 +146,9 @@ where } } #[repr(C)] -#[repr(align(4))] #[derive(Debug, Default, Copy, Clone)] pub struct my_struct1 { - _bitfield_align_1: [u8; 0], + pub _bindgen_align: [u32; 0], _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, __bindgen_padding_0: [u8; 3usize], } @@ -211,10 +210,9 @@ impl my_struct1 { } } #[repr(C)] -#[repr(align(4))] #[derive(Debug, Default, Copy, Clone)] pub struct my_struct2 { - pub _bitfield_align_1: [u8; 0], + pub _bindgen_align: [u32; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub __bindgen_padding_0: [u8; 3usize], } diff --git a/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs b/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs index 6e9f6e7753..a90fe54bf3 100644 --- a/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs +++ b/bindgen-tests/tests/expectations/tests/incomplete-array-padding.rs @@ -178,7 +178,6 @@ impl ::std::fmt::Debug for __IncompleteArrayField { #[repr(C)] #[derive(Debug)] pub struct foo { - pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub b: __IncompleteArrayField<*mut ::std::os::raw::c_void>, } diff --git a/bindgen-tests/tests/expectations/tests/issue-1034.rs b/bindgen-tests/tests/expectations/tests/issue-1034.rs index 1034520c48..90cc768a94 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1034.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1034.rs @@ -148,7 +148,6 @@ where #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct S2 { - pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 2usize]>, } #[allow(clippy::unnecessary_operation, clippy::identity_op)] diff --git a/bindgen-tests/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs b/bindgen-tests/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs index 3d14c81a77..50e9283b5a 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs @@ -148,7 +148,6 @@ where #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct S1 { - pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 3usize]>, } #[allow(clippy::unnecessary_operation, clippy::identity_op)] diff --git a/bindgen-tests/tests/expectations/tests/issue-1947.rs b/bindgen-tests/tests/expectations/tests/issue-1947.rs index cceb42d8c5..795b033a12 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1947.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1947.rs @@ -150,11 +150,10 @@ pub type U16 = ::std::os::raw::c_ushort; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct V56AMDY { - pub _bitfield_align_1: [u16; 0], + pub _bindgen_align: [u16; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 2usize]>, pub MADK: U8, pub MABR: U8, - pub _bitfield_align_2: [u16; 0], pub _bitfield_2: __BindgenBitfieldUnit<[u8; 3usize]>, pub _rB_: U8, } diff --git a/bindgen-tests/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs b/bindgen-tests/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs index 4e79cfdf71..bc1951e7d1 100644 --- a/bindgen-tests/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/issue-739-pointer-wide-bitfield.rs @@ -149,7 +149,7 @@ where #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct Foo { - pub _bitfield_align_1: [u64; 0], + pub _bindgen_align: [u64; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 32usize]>, } #[allow(clippy::unnecessary_operation, clippy::identity_op)] diff --git a/bindgen-tests/tests/expectations/tests/issue-743.rs b/bindgen-tests/tests/expectations/tests/issue-743.rs new file mode 100644 index 0000000000..af3eb5bf6e --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/issue-743.rs @@ -0,0 +1,225 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[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) }; + } + } +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct S { + pub p: *mut ::std::os::raw::c_void, + pub b: bool, + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 2usize]>, + pub __bindgen_padding_0: [u8; 5usize], +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of S"][::std::mem::size_of::() - 16usize]; + ["Alignment of S"][::std::mem::align_of::() - 8usize]; + ["Offset of field: S::p"][::std::mem::offset_of!(S, p) - 0usize]; + ["Offset of field: S::b"][::std::mem::offset_of!(S, b) - 8usize]; +}; +impl Default for S { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +impl S { + #[inline] + pub fn u(&self) -> ::std::os::raw::c_uint { + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 16u8) as u32) } + } + #[inline] + pub fn set_u(&mut self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + self._bitfield_1.set(0usize, 16u8, val as u64) + } + } + #[inline] + pub unsafe fn u_raw(this: *const Self) -> ::std::os::raw::c_uint { + unsafe { + ::std::mem::transmute( + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 16u8) + as u32, + ) + } + } + #[inline] + pub unsafe fn set_u_raw(this: *mut Self, val: ::std::os::raw::c_uint) { + unsafe { + let val: u32 = ::std::mem::transmute(val); + <__BindgenBitfieldUnit< + [u8; 2usize], + >>::raw_set( + ::std::ptr::addr_of_mut!((*this)._bitfield_1), + 0usize, + 16u8, + val as u64, + ) + } + } + #[inline] + pub fn new_bitfield_1( + u: ::std::os::raw::c_uint, + ) -> __BindgenBitfieldUnit<[u8; 2usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 2usize]> = Default::default(); + __bindgen_bitfield_unit + .set( + 0usize, + 16u8, + { + let u: u32 = unsafe { ::std::mem::transmute(u) }; + u as u64 + }, + ); + __bindgen_bitfield_unit + } +} diff --git a/bindgen-tests/tests/expectations/tests/issue-816.rs b/bindgen-tests/tests/expectations/tests/issue-816.rs index 56e719238b..b1494afede 100644 --- a/bindgen-tests/tests/expectations/tests/issue-816.rs +++ b/bindgen-tests/tests/expectations/tests/issue-816.rs @@ -146,10 +146,9 @@ where } } #[repr(C)] -#[repr(align(4))] #[derive(Debug, Default, Copy, Clone)] pub struct capabilities { - pub _bitfield_align_1: [u8; 0], + pub _bindgen_align: [u32; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 16usize]>, } #[allow(clippy::unnecessary_operation, clippy::identity_op)] diff --git a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs index 7dd23241e9..dc0ef8ed7f 100644 --- a/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs +++ b/bindgen-tests/tests/expectations/tests/jsval_layout_opaque.rs @@ -245,7 +245,7 @@ pub union jsval_layout { #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct jsval_layout__bindgen_ty_1 { - pub _bitfield_align_1: [u64; 0], + pub _bindgen_align: [u64; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 8usize]>, } #[allow(clippy::unnecessary_operation, clippy::identity_op)] diff --git a/bindgen-tests/tests/expectations/tests/layout_align.rs b/bindgen-tests/tests/expectations/tests/layout_align.rs index 18662d4c83..a942adb8f2 100644 --- a/bindgen-tests/tests/expectations/tests/layout_align.rs +++ b/bindgen-tests/tests/expectations/tests/layout_align.rs @@ -219,12 +219,11 @@ impl Default for rte_kni_fifo { } } #[repr(C)] -#[repr(align(8))] #[derive(Debug, Default, Copy, Clone)] pub struct rte_eth_link { + pub _bindgen_align: [u64; 0], ///< ETH_SPEED_NUM_ pub link_speed: u32, - pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub __bindgen_padding_0: [u8; 3usize], } diff --git a/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs b/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs index 4a62ddbea3..2686d8f5fa 100644 --- a/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs +++ b/bindgen-tests/tests/expectations/tests/layout_eth_conf.rs @@ -151,7 +151,6 @@ pub struct rte_eth_rxmode { pub max_rx_pkt_len: u32, ///< hdr buf size (header_split enabled). pub split_hdr_size: u16, - pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 2usize]>, } #[test] @@ -425,7 +424,6 @@ pub struct rte_eth_txmode { ///< TX multi-queues mode. pub mq_mode: rte_eth_tx_mq_mode, pub pvid: u16, - pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub __bindgen_padding_0: u8, } diff --git a/bindgen-tests/tests/expectations/tests/layout_mbuf.rs b/bindgen-tests/tests/expectations/tests/layout_mbuf.rs index cb3698812b..ce6c58e39e 100644 --- a/bindgen-tests/tests/expectations/tests/layout_mbuf.rs +++ b/bindgen-tests/tests/expectations/tests/layout_mbuf.rs @@ -259,10 +259,9 @@ pub union rte_mbuf__bindgen_ty_2 { pub __bindgen_anon_1: rte_mbuf__bindgen_ty_2__bindgen_ty_1, } #[repr(C)] -#[repr(align(4))] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_mbuf__bindgen_ty_2__bindgen_ty_1 { - pub _bitfield_align_1: [u8; 0], + pub _bindgen_align: [u32; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, } #[allow(clippy::unnecessary_operation, clippy::identity_op)] @@ -820,11 +819,11 @@ pub union rte_mbuf__bindgen_ty_5 { pub __bindgen_anon_1: rte_mbuf__bindgen_ty_5__bindgen_ty_1, } #[repr(C)] -#[repr(align(8))] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct rte_mbuf__bindgen_ty_5__bindgen_ty_1 { - pub _bitfield_align_1: [u16; 0], + pub _bindgen_align: [u64; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 7usize]>, + pub __bindgen_padding_0: u8, } #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { diff --git a/bindgen-tests/tests/expectations/tests/only_bitfields.rs b/bindgen-tests/tests/expectations/tests/only_bitfields.rs index 3aedce1e3f..9a73fc2fee 100644 --- a/bindgen-tests/tests/expectations/tests/only_bitfields.rs +++ b/bindgen-tests/tests/expectations/tests/only_bitfields.rs @@ -148,7 +148,6 @@ where #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct C { - pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, } #[allow(clippy::unnecessary_operation, clippy::identity_op)] diff --git a/bindgen-tests/tests/expectations/tests/packed-bitfield.rs b/bindgen-tests/tests/expectations/tests/packed-bitfield.rs index 4e3918f558..b5a734454a 100644 --- a/bindgen-tests/tests/expectations/tests/packed-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/packed-bitfield.rs @@ -148,7 +148,6 @@ where #[repr(C, packed)] #[derive(Debug, Default, Copy, Clone)] pub struct Date { - pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 3usize]>, } #[allow(clippy::unnecessary_operation, clippy::identity_op)] diff --git a/bindgen-tests/tests/expectations/tests/private_fields.rs b/bindgen-tests/tests/expectations/tests/private_fields.rs index a5d9e84499..abb2886d39 100644 --- a/bindgen-tests/tests/expectations/tests/private_fields.rs +++ b/bindgen-tests/tests/expectations/tests/private_fields.rs @@ -159,10 +159,9 @@ const _: () = { ["Offset of field: PubPriv::y"][::std::mem::offset_of!(PubPriv, y) - 4usize]; }; #[repr(C)] -#[repr(align(4))] #[derive(Debug, Default, Copy, Clone)] pub struct PrivateBitFields { - pub _bitfield_align_1: [u8; 0], + pub _bindgen_align: [u32; 0], _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub __bindgen_padding_0: [u8; 3usize], } @@ -274,10 +273,9 @@ impl PrivateBitFields { } } #[repr(C)] -#[repr(align(4))] #[derive(Debug, Default, Copy, Clone)] pub struct PublicBitFields { - pub _bitfield_align_1: [u8; 0], + pub _bindgen_align: [u32; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub __bindgen_padding_0: [u8; 3usize], } @@ -387,10 +385,9 @@ impl PublicBitFields { } } #[repr(C)] -#[repr(align(4))] #[derive(Debug, Default, Copy, Clone)] pub struct MixedBitFields { - pub _bitfield_align_1: [u8; 0], + pub _bindgen_align: [u32; 0], _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub __bindgen_padding_0: [u8; 3usize], } @@ -628,7 +625,6 @@ pub struct Override { ///
b: ::std::os::raw::c_uint, private_c: ::std::os::raw::c_uint, - pub _bitfield_align_1: [u8; 0], _bitfield_1: __BindgenBitfieldUnit<[u8; 2usize]>, pub __bindgen_padding_0: u16, } diff --git a/bindgen-tests/tests/expectations/tests/redundant-packed-and-align.rs b/bindgen-tests/tests/expectations/tests/redundant-packed-and-align.rs index c01762ca98..05401e52ca 100644 --- a/bindgen-tests/tests/expectations/tests/redundant-packed-and-align.rs +++ b/bindgen-tests/tests/expectations/tests/redundant-packed-and-align.rs @@ -166,11 +166,10 @@ const _: () = { ][::std::mem::offset_of!(redundant_packed, b) - 4usize]; }; #[repr(C)] -#[repr(align(8))] #[derive(Debug, Default, Copy, Clone)] pub struct redundant_packed_bitfield { + pub _bindgen_align: [u64; 0], pub a: [u8; 3usize], - pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub c: u32, } diff --git a/bindgen-tests/tests/expectations/tests/struct_with_bitfields.rs b/bindgen-tests/tests/expectations/tests/struct_with_bitfields.rs index 23588ee7da..a294c871d3 100644 --- a/bindgen-tests/tests/expectations/tests/struct_with_bitfields.rs +++ b/bindgen-tests/tests/expectations/tests/struct_with_bitfields.rs @@ -148,10 +148,8 @@ where #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct bitfield { - pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, pub e: ::std::os::raw::c_int, - pub _bitfield_align_2: [u32; 0], pub _bitfield_2: __BindgenBitfieldUnit<[u8; 8usize]>, } #[allow(clippy::unnecessary_operation, clippy::identity_op)] diff --git a/bindgen-tests/tests/expectations/tests/timex.rs b/bindgen-tests/tests/expectations/tests/timex.rs index 3d25971315..f73b608de2 100644 --- a/bindgen-tests/tests/expectations/tests/timex.rs +++ b/bindgen-tests/tests/expectations/tests/timex.rs @@ -149,7 +149,6 @@ where #[derive(Debug, Copy, Clone)] pub struct timex { pub tai: ::std::os::raw::c_int, - pub _bitfield_align_1: [u8; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 44usize]>, } #[allow(clippy::unnecessary_operation, clippy::identity_op)] @@ -171,7 +170,6 @@ impl Default for timex { #[derive(Debug, Copy, Clone)] pub struct timex_named { pub tai: ::std::os::raw::c_int, - pub _bitfield_align_1: [u32; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 44usize]>, } #[allow(clippy::unnecessary_operation, clippy::identity_op)] diff --git a/bindgen-tests/tests/expectations/tests/union_bitfield.rs b/bindgen-tests/tests/expectations/tests/union_bitfield.rs index 70da5c3b02..8df0724738 100644 --- a/bindgen-tests/tests/expectations/tests/union_bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/union_bitfield.rs @@ -146,10 +146,9 @@ where } } #[repr(C)] -#[repr(align(4))] #[derive(Copy, Clone)] pub union U4 { - pub _bitfield_align_1: [u8; 0], + pub _bindgen_align: [u32; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, } #[allow(clippy::unnecessary_operation, clippy::identity_op)] @@ -223,8 +222,8 @@ impl U4 { #[repr(C)] #[derive(Copy, Clone)] pub union B { - pub _bitfield_align_1: [u32; 0], - pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, + pub _bindgen_align: [u32; 0], + pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, } #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { @@ -257,7 +256,7 @@ impl B { unsafe { ::std::mem::transmute( <__BindgenBitfieldUnit< - [u8; 4usize], + [u8; 1usize], >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 31u8) as u32, ) @@ -268,7 +267,7 @@ impl B { unsafe { let val: u32 = ::std::mem::transmute(val); <__BindgenBitfieldUnit< - [u8; 4usize], + [u8; 1usize], >>::raw_set( ::std::ptr::addr_of_mut!((*this)._bitfield_1), 0usize, @@ -279,13 +278,13 @@ impl B { } #[inline] pub fn bar(&self) -> ::std::os::raw::c_uchar { - unsafe { ::std::mem::transmute(self._bitfield_1.get(31usize, 1u8) as u8) } + unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u8) } } #[inline] pub fn set_bar(&mut self, val: ::std::os::raw::c_uchar) { unsafe { let val: u8 = ::std::mem::transmute(val); - self._bitfield_1.set(31usize, 1u8, val as u64) + self._bitfield_1.set(0usize, 1u8, val as u64) } } #[inline] @@ -293,9 +292,8 @@ impl B { unsafe { ::std::mem::transmute( <__BindgenBitfieldUnit< - [u8; 4usize], - >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 31usize, 1u8) - as u8, + [u8; 1usize], + >>::raw_get(::std::ptr::addr_of!((*this)._bitfield_1), 0usize, 1u8) as u8, ) } } @@ -304,10 +302,10 @@ impl B { unsafe { let val: u8 = ::std::mem::transmute(val); <__BindgenBitfieldUnit< - [u8; 4usize], + [u8; 1usize], >>::raw_set( ::std::ptr::addr_of_mut!((*this)._bitfield_1), - 31usize, + 0usize, 1u8, val as u64, ) @@ -317,8 +315,8 @@ impl B { pub fn new_bitfield_1( foo: ::std::os::raw::c_uint, bar: ::std::os::raw::c_uchar, - ) -> __BindgenBitfieldUnit<[u8; 4usize]> { - let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 4usize]> = Default::default(); + ) -> __BindgenBitfieldUnit<[u8; 1usize]> { + let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); __bindgen_bitfield_unit .set( 0usize, @@ -330,7 +328,7 @@ impl B { ); __bindgen_bitfield_unit .set( - 31usize, + 0usize, 1u8, { let bar: u8 = unsafe { ::std::mem::transmute(bar) }; diff --git a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield.rs b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield.rs index dd1a55e9b5..a1b61c035d 100644 --- a/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/union_with_anon_struct_bitfield.rs @@ -154,7 +154,7 @@ pub union foo { #[repr(C)] #[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct foo__bindgen_ty_1 { - pub _bitfield_align_1: [u32; 0], + pub _bindgen_align: [u32; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, } #[allow(clippy::unnecessary_operation, clippy::identity_op)] diff --git a/bindgen-tests/tests/expectations/tests/weird_bitfields.rs b/bindgen-tests/tests/expectations/tests/weird_bitfields.rs index 17accb01d9..ca8d84520b 100644 --- a/bindgen-tests/tests/expectations/tests/weird_bitfields.rs +++ b/bindgen-tests/tests/expectations/tests/weird_bitfields.rs @@ -156,7 +156,6 @@ pub enum nsStyleSVGOpacitySource { #[derive(Debug, Copy, Clone)] pub struct Weird { pub mStrokeDasharrayLength: ::std::os::raw::c_uint, - pub _bitfield_align_1: [u16; 0], pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>, pub mClipRule: ::std::os::raw::c_uchar, pub mColorInterpolation: ::std::os::raw::c_uchar, @@ -169,7 +168,6 @@ pub struct Weird { pub mStrokeLinejoin: ::std::os::raw::c_uchar, pub mTextAnchor: ::std::os::raw::c_uchar, pub mTextRendering: ::std::os::raw::c_uchar, - pub _bitfield_align_2: [u8; 0], pub _bitfield_2: __BindgenBitfieldUnit<[u8; 2usize]>, pub __bindgen_padding_0: [u8; 3usize], } diff --git a/bindgen-tests/tests/headers/bitfield-linux-32.hpp b/bindgen-tests/tests/headers/bitfield-linux-32.hpp index b9a480df15..71ee6a7e1d 100644 --- a/bindgen-tests/tests/headers/bitfield-linux-32.hpp +++ b/bindgen-tests/tests/headers/bitfield-linux-32.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: -- --target=i586-unknown-linux +// bindgen-flags: --no-layout-tests -- --target=i586-unknown-linux typedef unsigned long long uint64_t; diff --git a/bindgen-tests/tests/headers/bitfield-template.hpp b/bindgen-tests/tests/headers/bitfield-template.hpp new file mode 100644 index 0000000000..664199b9c0 --- /dev/null +++ b/bindgen-tests/tests/headers/bitfield-template.hpp @@ -0,0 +1,4 @@ +template struct foo { + T member; + bool b : 8; +}; diff --git a/bindgen-tests/tests/headers/bitfield_pack_offset.h b/bindgen-tests/tests/headers/bitfield_pack_offset.h new file mode 100644 index 0000000000..5118a64642 --- /dev/null +++ b/bindgen-tests/tests/headers/bitfield_pack_offset.h @@ -0,0 +1,21 @@ +struct A { + const unsigned char name[7]; /* 0 7 */ + unsigned char firmness:4; /* 7: 0 1 */ + unsigned char color:4; /* 7: 4 1 */ + unsigned short weedsBonus:3; /* 8: 0 2 */ + unsigned short pestsBonus:3; /* 8: 3 2 */ + unsigned short size:10; /* 8: 6 2 */ + unsigned char maxYield; /* 10 1 */ + unsigned char minYield:4; /* 11: 0 1 */ + unsigned char waterBonus:4; /* 11: 4 1 */ + + /* XXX 4 bytes hole, try to pack */ + + const unsigned char * description1; /* 16 8 */ + + /* size: 24, cachelines: 1, members: 10 */ + /* sum members: 16, holes: 1, sum holes: 4 */ + /* sum bitfield members: 32 bits (4 bytes) */ + /* last cacheline: 24 bytes */ +}; + diff --git a/bindgen-tests/tests/headers/issue-743.h b/bindgen-tests/tests/headers/issue-743.h new file mode 100644 index 0000000000..1f8e0ccd78 --- /dev/null +++ b/bindgen-tests/tests/headers/issue-743.h @@ -0,0 +1,6 @@ + +struct S { + void *p; + _Bool b; + unsigned u : 16; +}; \ No newline at end of file diff --git a/bindgen-tests/tests/headers/union_bitfield.h b/bindgen-tests/tests/headers/union_bitfield.h index 990729574a..4592a8973a 100644 --- a/bindgen-tests/tests/headers/union_bitfield.h +++ b/bindgen-tests/tests/headers/union_bitfield.h @@ -1,10 +1,10 @@ // bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --impl-partialeq union U4 { - unsigned derp : 1; + unsigned int derp:1; /* 0: 0 4 */ }; union B { - unsigned foo : 31; - unsigned char bar : 1; + unsigned int foo:31; /* 0: 0 4 */ + unsigned char bar:1; /* 0: 0 1 */ }; diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index c0f461b326..5425962bac 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -1770,22 +1770,6 @@ impl FieldCodegen<'_> for BitfieldUnit { } }; - { - let align_field_name = format!("_bitfield_align_{}", self.nth()); - let align_field_ident = ctx.rust_ident(align_field_name); - let align_ty = match self.layout().align { - n if n >= 8 => quote! { u64 }, - 4 => quote! { u32 }, - 2 => quote! { u16 }, - _ => quote! { u8 }, - }; - let access_spec = access_specifier(visibility_kind); - let align_field = quote! { - #access_spec #align_field_ident: [#align_ty; 0], - }; - fields.extend(Some(align_field)); - } - let unit_field_name = format!("_bitfield_{}", self.nth()); let unit_field_ident = ctx.rust_ident(&unit_field_name); @@ -2428,10 +2412,24 @@ impl CodeGenerator for CompInfo { attributes.push(attributes::repr("C")); } - if true { - if let Some(explicit) = explicit_align { - // Ensure that the struct has the correct alignment even in - // presence of alignas. + // Ensure that the struct has the correct alignment even in presence of alignas and co. + if let Some(explicit) = explicit_align { + // If we need explicit alignment and can do it, we prefer to insert a dummy field at + // the beginning of the struct. This avoids hitting + // https://github.com/rust-lang/rust-bindgen/issues/2179 + // Do it for bitfields only for now for backwards compat. + if self.has_bitfields() && explicit <= 8 { + let align_ty = match explicit { + 8 => quote! { u64 }, + 4 => quote! { u32 }, + 2 => quote! { u16 }, + _ => quote! { u8 }, + }; + let align_field = quote! { + pub _bindgen_align: [#align_ty; 0], + }; + fields.insert(0, align_field); + } else { let explicit = helpers::ast_ty::int_expr(explicit as i64); attributes.push(quote! { #[repr(align(#explicit))] diff --git a/bindgen/codegen/struct_layout.rs b/bindgen/codegen/struct_layout.rs index 0d2e6a05c5..3dfd076c25 100644 --- a/bindgen/codegen/struct_layout.rs +++ b/bindgen/codegen/struct_layout.rs @@ -45,23 +45,6 @@ pub(crate) fn align_to(size: usize, align: usize) -> usize { size + align - rem } -/// Returns the lower power of two byte count that can hold at most n bits. -pub(crate) fn bytes_from_bits_pow2(mut n: usize) -> usize { - if n == 0 { - return 0; - } - - if n <= 8 { - return 1; - } - - if !n.is_power_of_two() { - n = n.next_power_of_two(); - } - - n / 8 -} - #[test] fn test_align_to() { assert_eq!(align_to(1, 1), 1); @@ -71,20 +54,6 @@ fn test_align_to() { assert_eq!(align_to(17, 4), 20); } -#[test] -fn test_bytes_from_bits_pow2() { - assert_eq!(bytes_from_bits_pow2(0), 0); - for i in 1..9 { - assert_eq!(bytes_from_bits_pow2(i), 1); - } - for i in 9..17 { - assert_eq!(bytes_from_bits_pow2(i), 2); - } - for i in 17..33 { - assert_eq!(bytes_from_bits_pow2(i), 4); - } -} - impl<'a> StructLayoutTracker<'a> { pub(crate) fn new( ctx: &'a BindgenContext, diff --git a/bindgen/ir/comp.rs b/bindgen/ir/comp.rs index 655e0f1fa5..c0860f9fe3 100644 --- a/bindgen/ir/comp.rs +++ b/bindgen/ir/comp.rs @@ -12,7 +12,7 @@ use super::template::TemplateParameters; use super::traversal::{EdgeKind, Trace, Tracer}; use super::ty::RUST_DERIVE_IN_ARRAY_LIMIT; use crate::clang; -use crate::codegen::struct_layout::{align_to, bytes_from_bits_pow2}; +use crate::codegen::struct_layout::align_to; use crate::ir::derive::CanDeriveCopy; use crate::parse::ParseError; use crate::HashMap; @@ -560,18 +560,12 @@ where fields: &mut E, bitfield_unit_count: &mut usize, unit_size_in_bits: usize, - unit_align_in_bits: usize, bitfields: Vec, - packed: bool, ) where E: Extend, { *bitfield_unit_count += 1; - let align = if packed { - 1 - } else { - bytes_from_bits_pow2(unit_align_in_bits) - }; + let align = 1; let size = align_to(unit_size_in_bits, 8) / 8; let layout = Layout::new(size, align); fields.extend(Some(Field::Bitfields(BitfieldUnit { @@ -581,70 +575,45 @@ where }))); } + // The offset we're in inside the struct, if we know it (we might not know it in presence of + // templates). + let mut start_offset_in_struct = 0; let mut max_align = 0; - let mut unfilled_bits_in_unit = 0; let mut unit_size_in_bits = 0; - let mut unit_align = 0; let mut bitfields_in_unit = vec![]; - // TODO(emilio): Determine this from attributes or pragma ms_struct - // directives. Also, perhaps we should check if the target is MSVC? - const is_ms_struct: bool = false; - + // TODO(emilio): Deal with ms_struct bitfield layout for MSVC? for bitfield in raw_bitfields { let bitfield_width = bitfield.bitfield_width().unwrap() as usize; let bitfield_layout = ctx.resolve_type(bitfield.ty()).layout(ctx).ok_or(())?; - let bitfield_size = bitfield_layout.size; let bitfield_align = bitfield_layout.align; + let bitfield_size = bitfield_layout.size; - let mut offset = unit_size_in_bits; - if !packed { - if is_ms_struct { - if unit_size_in_bits != 0 && - (bitfield_width == 0 || - bitfield_width > unfilled_bits_in_unit) - { - // We've reached the end of this allocation unit, so flush it - // and its bitfields. - unit_size_in_bits = - align_to(unit_size_in_bits, unit_align * 8); - flush_allocation_unit( - fields, - bitfield_unit_count, - unit_size_in_bits, - unit_align, - mem::take(&mut bitfields_in_unit), - packed, - ); + if unit_size_in_bits == 0 { + start_offset_in_struct = bitfield.offset().unwrap_or(0); + } - // Now we're working on a fresh bitfield allocation unit, so reset - // the current unit size and alignment. - offset = 0; - unit_align = 0; - } - } else if offset != 0 && - (bitfield_width == 0 || - (offset & (bitfield_align * 8 - 1)) + bitfield_width > - bitfield_size * 8) - { - offset = align_to(offset, bitfield_align * 8); - } + let mut offset_in_struct = + bitfield.offset().unwrap_or(unit_size_in_bits); + + // A zero-width field serves as alignment / padding. + if !packed && + offset_in_struct != 0 && + (bitfield_width == 0 || + (offset_in_struct & (bitfield_align * 8 - 1)) + + bitfield_width > + bitfield_size * 8) + { + offset_in_struct = align_to(offset_in_struct, bitfield_align * 8); } - // According to the x86[-64] ABI spec: "Unnamed bit-fields’ types do not - // affect the alignment of a structure or union". This makes sense: such - // bit-fields are only used for padding, and we can't perform an - // un-aligned read of something we can't read because we can't even name - // it. + // According to the x86[-64] ABI spec: "Unnamed bit-fields’ types do not affect the + // alignment of a structure or union". This makes sense: such bit-fields are only used for + // padding, and we can't perform an un-aligned read of something we can't read because we + // can't even name it. if bitfield.name().is_some() { max_align = cmp::max(max_align, bitfield_align); - - // NB: The `bitfield_width` here is completely, absolutely - // intentional. Alignment of the allocation unit is based on the - // maximum bitfield width, not (directly) on the bitfields' types' - // alignment. - unit_align = cmp::max(unit_align, bitfield_width); } // Always keep all bitfields around. While unnamed bitifields are used @@ -652,15 +621,12 @@ where // bitfields over their types size cause weird allocation size behavior from clang. // Therefore, all bitfields needed to be kept around in order to check for this // and make the struct opaque in this case - bitfields_in_unit.push(Bitfield::new(offset, bitfield)); - - unit_size_in_bits = offset + bitfield_width; - - // Compute what the physical unit's final size would be given what we - // have seen so far, and use that to compute how many bits are still - // available in the unit. - let data_size = align_to(unit_size_in_bits, bitfield_align * 8); - unfilled_bits_in_unit = data_size - unit_size_in_bits; + bitfields_in_unit.push(Bitfield::new( + offset_in_struct - start_offset_in_struct, + bitfield, + )); + unit_size_in_bits = + offset_in_struct - start_offset_in_struct + bitfield_width; } if unit_size_in_bits != 0 { @@ -669,9 +635,7 @@ where fields, bitfield_unit_count, unit_size_in_bits, - unit_align, bitfields_in_unit, - packed, ); } @@ -1181,7 +1145,8 @@ impl CompInfo { } } - fn has_bitfields(&self) -> bool { + /// Returns whether we have any bitfield within the struct. + pub(crate) fn has_bitfields(&self) -> bool { match self.fields { CompFields::Error => false, CompFields::After { From bf87357115d2ef8753b57987f16c81413f816756 Mon Sep 17 00:00:00 2001 From: Paolo Barbolini Date: Sat, 19 Jul 2025 17:58:50 +0200 Subject: [PATCH 917/942] Allow itertools 0.14, bump Cargo.lock to it --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 92f1f78ebf..28bc2732ac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -339,9 +339,9 @@ checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" [[package]] name = "itertools" -version = "0.13.0" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" +checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285" dependencies = [ "either", ] diff --git a/Cargo.toml b/Cargo.toml index cc3bc7def8..edb0d35371 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,7 +31,7 @@ clang-sys = "1" clap = "4" clap_complete = "4" env_logger = "0.10.0" -itertools = { version = ">=0.10,<0.14", default-features = false } +itertools = { version = ">=0.10,<0.15", default-features = false } libloading = "0.8" log = "0.4" objc = "0.2" From a236cea73f34f077930bc36942887700b08f34c0 Mon Sep 17 00:00:00 2001 From: Niklas Dusenlund Date: Fri, 6 Jun 2025 12:05:49 +0200 Subject: [PATCH 918/942] Add linux aarch64 target to test and release --- .github/workflows/bindgen.yml | 30 ++++++++++++++++++++---------- dist-workspace.toml | 1 + 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 1778de1d2b..bd1489911e 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -95,7 +95,7 @@ jobs: runs-on: ${{matrix.os}} strategy: matrix: - os: [ubuntu-latest, macos-latest] + os: [ubuntu-latest, ubuntu-24.04-arm, macos-latest] steps: - uses: actions/checkout@v4 @@ -103,10 +103,16 @@ jobs: run: cd bindgen-tests/tests/expectations && cargo test test: - runs-on: ${{matrix.os}} + runs-on: ${{matrix.platform.os}} strategy: matrix: - os: [ubuntu-latest] + platform: + - os: ubuntu-latest + libtinfo: libtinfo5_6.3-2ubuntu0.1_amd64.deb + ubuntu_repo: https://mirrors.kernel.org/ubuntu/pool/universe/n/ncurses/ + - os: ubuntu-24.04-arm + libtinfo: libtinfo5_6.3-2ubuntu0.1_arm64.deb + ubuntu_repo: https://ports.ubuntu.com/ubuntu-ports/pool/universe/n/ncurses/ llvm_version: ["9.0", "16.0"] release_build: [0, 1] no_default_features: [0, 1] @@ -118,14 +124,18 @@ jobs: include: # Test with extra asserts + docs just with latest llvm versions to # prevent explosion - - os: ubuntu-latest + - platform: + os: ubuntu-latest + libtinfo: libtinfo5_6.3-2ubuntu0.1_amd64.deb + ubuntu_repo: https://mirrors.kernel.org/ubuntu/pool/universe/n/ncurses/ llvm_version: "16.0" release_build: 0 no_default_features: 0 feature_extra_asserts: 1 # Ensure stuff works on macos too - - os: macos-latest + - platform: + os: macos-latest llvm_version: "16.0" release_build: 0 no_default_features: 0 @@ -138,22 +148,22 @@ jobs: with: toolchain: stable - name: Install libtinfo - if: matrix.os == 'ubuntu-latest' + if: startsWith(matrix.platform.os, 'ubuntu') run: | - wget https://mirrors.kernel.org/ubuntu/pool/universe/n/ncurses/libtinfo5_6.3-2ubuntu0.1_amd64.deb - sudo dpkg -i libtinfo5_6.3-2ubuntu0.1_amd64.deb + wget ${{matrix.platform.ubuntu_repo}}${{matrix.platform.libtinfo}} + sudo dpkg -i ${{matrix.platform.libtinfo}} - name: Install LLVM and Clang uses: KyleMayes/install-llvm-action@v2.0.5 with: version: ${{matrix.llvm_version}} - name: Run all the tests env: - GITHUB_ACTIONS_OS: ${{matrix.os}} + GITHUB_ACTIONS_OS: ${{matrix.platform.os}} BINDGEN_RELEASE_BUILD: ${{matrix.release_build}} BINDGEN_FEATURE_RUNTIME: ${{matrix.feature_runtime}} BINDGEN_FEATURE_EXTRA_ASSERTS: ${{matrix.feature_extra_asserts}} BINDGEN_NO_DEFAULT_FEATURES: ${{matrix.no_default_features}} - BINDGEN_RUST_FOR_LINUX_TEST: ${{matrix.os == 'ubuntu-latest' && matrix.llvm_version == '16.0' && matrix.feature_extra_asserts == 0 && 1 || 0}} + BINDGEN_RUST_FOR_LINUX_TEST: ${{startsWith(matrix.platform.os, 'ubuntu') && matrix.llvm_version == '16.0' && matrix.feature_extra_asserts == 0 && 1 || 0}} run: ./ci/test.sh test-book: diff --git a/dist-workspace.toml b/dist-workspace.toml index f2706c7473..9da713f523 100644 --- a/dist-workspace.toml +++ b/dist-workspace.toml @@ -25,3 +25,4 @@ global = "ubuntu-22.04" aarch64-apple-darwin = "macos-14" x86_64-apple-darwin = "macos-13" x86_64-unknown-linux-gnu = "ubuntu-22.04" +aarch64-unknown-linux-gnu = "ubuntu-24.04-arm" From 93b956648942874f6d12ec43f3ec963bb663e96c Mon Sep 17 00:00:00 2001 From: Niklas Dusenlund Date: Wed, 18 Jun 2025 14:56:32 +0200 Subject: [PATCH 919/942] ignore failed test --- bindgen-integration/build.rs | 28 +++++++++++++------ bindgen-integration/src/lib.rs | 13 +++++---- .../generated/wrap_static_fns_aarch64_linux.c | 14 ++++++++++ bindgen-tests/tests/headers/wrap-static-fns.h | 3 ++ bindgen-tests/tests/tests.rs | 24 ++++++++++++---- 5 files changed, 64 insertions(+), 18 deletions(-) create mode 100644 bindgen-tests/tests/expectations/tests/generated/wrap_static_fns_aarch64_linux.c diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs index ef167775cf..fc9ee25d8b 100644 --- a/bindgen-integration/build.rs +++ b/bindgen-integration/build.rs @@ -288,7 +288,8 @@ fn setup_wrap_static_fns_test() { .expect("Path could not be converted to a str"); // generate external bindings with the external .c and .h files - let bindings = Builder::default() + #[allow(unused_mut)] + let mut builder = Builder::default() .header(input_header_file_path_str) .parse_callbacks(Box::new( bindgen::CargoCallbacks::new().rerun_on_header_files(true), @@ -298,9 +299,14 @@ fn setup_wrap_static_fns_test() { .wrap_static_fns_path( out_path.join("wrap_static_fns").display().to_string(), ) - .clang_arg("-DUSE_VA_HEADER") - .generate() - .expect("Unable to generate bindings"); + .clang_arg("-DUSE_VA_HEADER"); + + #[cfg(all(target_arch = "aarch64", target_os = "linux"))] + { + builder = builder.clang_arg("-DDISABLE_VA"); + } + + let bindings = builder.generate().expect("Unable to generate bindings"); println!("cargo:rustc-link-lib=static=wrap_static_fns"); // tell cargo to link libextern println!("bindings generated: {bindings}"); @@ -309,14 +315,20 @@ fn setup_wrap_static_fns_test() { let lib_path = out_path.join("libwrap_static_fns.a"); // build the external files to check if they work - let clang_output = std::process::Command::new("clang") + let mut command = std::process::Command::new("clang"); + command .arg("-c") .arg("-o") .arg(&obj_path) .arg(out_path.join("wrap_static_fns.c")) - .arg("-DUSE_VA_HEADER") - .output() - .expect("`clang` command error"); + .arg("-DUSE_VA_HEADER"); + + #[cfg(all(target_arch = "aarch64", target_os = "linux"))] + { + command.arg("-DDISABLE_VA"); + } + + let clang_output = command.output().expect("`clang` command error"); if !clang_output.status.success() { panic!( "Could not compile object file:\n{}", diff --git a/bindgen-integration/src/lib.rs b/bindgen-integration/src/lib.rs index c5362bf450..f667069002 100755 --- a/bindgen-integration/src/lib.rs +++ b/bindgen-integration/src/lib.rs @@ -335,13 +335,16 @@ fn test_wrap_static_fns() { extern_bindings::takes_qualified(&(&5 as *const _) as *const _); assert_eq!(5, tq); - let wv1 = extern_bindings::wrap_as_variadic_fn1_wrapped(0); - assert_eq!(0, wv1); + #[cfg(not(all(target_arch = "aarch64", target_os = "linux")))] + { + let wv1 = extern_bindings::wrap_as_variadic_fn1_wrapped(0); + assert_eq!(0, wv1); - let wv1 = extern_bindings::wrap_as_variadic_fn1_wrapped(2, 5, 3); - assert_eq!(8, wv1); + let wv1 = extern_bindings::wrap_as_variadic_fn1_wrapped(2, 5, 3); + assert_eq!(8, wv1); - extern_bindings::wrap_as_variadic_fn2_wrapped(1, 2); + extern_bindings::wrap_as_variadic_fn2_wrapped(1, 2); + } } } diff --git a/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns_aarch64_linux.c b/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns_aarch64_linux.c new file mode 100644 index 0000000000..a4269d8505 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns_aarch64_linux.c @@ -0,0 +1,14 @@ +#include "tests/headers/wrap-static-fns.h" + +// Static wrappers + +int foo__extern(void) { return foo(); } +int bar__extern(void) { return bar(); } +int takes_ptr__extern(int *arg) { return takes_ptr(arg); } +int takes_fn_ptr__extern(int (*f) (int)) { return takes_fn_ptr(f); } +int takes_fn__extern(int (f) (int)) { return takes_fn(f); } +int takes_alias__extern(func f) { return takes_alias(f); } +int takes_qualified__extern(const int *const *arg) { return takes_qualified(arg); } +enum foo takes_enum__extern(const enum foo f) { return takes_enum(f); } +void nevermore__extern(void) { nevermore(); } +int takes_fn_with_no_args__extern(int (f) (void)) { return takes_fn_with_no_args(f); } diff --git a/bindgen-tests/tests/headers/wrap-static-fns.h b/bindgen-tests/tests/headers/wrap-static-fns.h index 5cd3d41aee..27757a8476 100644 --- a/bindgen-tests/tests/headers/wrap-static-fns.h +++ b/bindgen-tests/tests/headers/wrap-static-fns.h @@ -60,6 +60,8 @@ static inline int variadic(int x, ...) { return x; } +#ifndef DISABLE_VA + static inline void no_extra_argument(__builtin_va_list va) {} static inline int many_va_list(int i, __builtin_va_list va1, __builtin_va_list va2) { @@ -84,3 +86,4 @@ static inline int wrap_as_variadic_fn1(int i, va_list va) { static inline void wrap_as_variadic_fn2(int i, va_list va) {} #endif +#endif diff --git a/bindgen-tests/tests/tests.rs b/bindgen-tests/tests/tests.rs index bcf9b7fcfa..637f66bb52 100644 --- a/bindgen-tests/tests/tests.rs +++ b/bindgen-tests/tests/tests.rs @@ -725,21 +725,35 @@ fn test_wrap_static_fns() { // This test is for testing diffs of the generated C source and header files // TODO: If another such feature is added, convert this test into a more generic // test that looks at `tests/headers/generated` directory. + + let wrap_static_fns_c_name = + if cfg!(all(target_arch = "aarch64", target_os = "linux")) { + "wrap_static_fns_aarch64_linux" + } else { + "wrap_static_fns" + }; + let expect_path = PathBuf::from("tests/expectations/tests/generated") - .join("wrap_static_fns"); + .join(wrap_static_fns_c_name); println!("In path is ::: {}", expect_path.display()); let generated_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("wrap_static_fns"); println!("Out path is ::: {}", generated_path.display()); - let _bindings = Builder::default() + #[allow(unused_mut)] + let mut builder = Builder::default() .header("tests/headers/wrap-static-fns.h") .wrap_static_fns(true) .wrap_static_fns_path(generated_path.display().to_string()) - .parse_callbacks(Box::new(parse_callbacks::WrapAsVariadicFn)) - .generate() - .expect("Failed to generate bindings"); + .parse_callbacks(Box::new(parse_callbacks::WrapAsVariadicFn)); + + #[cfg(all(target_arch = "aarch64", target_os = "linux"))] + { + builder = builder.clang_arg("-DDISABLE_VA"); + } + + builder.generate().expect("Failed to generate bindings"); let expected_c = fs::read_to_string(expect_path.with_extension("c")) .expect("Could not read generated wrap_static_fns.c"); From de9627ffa4860c6ed56cd40470fc7a96afc09d44 Mon Sep 17 00:00:00 2001 From: Niklas Dusenlund Date: Mon, 14 Jul 2025 11:47:24 +0200 Subject: [PATCH 920/942] Add references to issue --- bindgen-integration/build.rs | 4 ++++ bindgen-integration/src/lib.rs | 2 ++ bindgen-tests/tests/headers/wrap-static-fns.h | 2 ++ bindgen-tests/tests/tests.rs | 4 ++++ 4 files changed, 12 insertions(+) diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs index fc9ee25d8b..c940c3e9fa 100644 --- a/bindgen-integration/build.rs +++ b/bindgen-integration/build.rs @@ -301,6 +301,8 @@ fn setup_wrap_static_fns_test() { ) .clang_arg("-DUSE_VA_HEADER"); + // aarch64-linux has a bug, remove again when it is solved: + // https://github.com/rust-lang/rust-bindgen/issues/3234 #[cfg(all(target_arch = "aarch64", target_os = "linux"))] { builder = builder.clang_arg("-DDISABLE_VA"); @@ -323,6 +325,8 @@ fn setup_wrap_static_fns_test() { .arg(out_path.join("wrap_static_fns.c")) .arg("-DUSE_VA_HEADER"); + // aarch64-linux has a bug, remove again when it is solved: + // https://github.com/rust-lang/rust-bindgen/issues/3234 #[cfg(all(target_arch = "aarch64", target_os = "linux"))] { command.arg("-DDISABLE_VA"); diff --git a/bindgen-integration/src/lib.rs b/bindgen-integration/src/lib.rs index f667069002..22dd224ae8 100755 --- a/bindgen-integration/src/lib.rs +++ b/bindgen-integration/src/lib.rs @@ -335,6 +335,8 @@ fn test_wrap_static_fns() { extern_bindings::takes_qualified(&(&5 as *const _) as *const _); assert_eq!(5, tq); + // aarch64-linux has a bug, enable again when it is solved: + // https://github.com/rust-lang/rust-bindgen/issues/3234 #[cfg(not(all(target_arch = "aarch64", target_os = "linux")))] { let wv1 = extern_bindings::wrap_as_variadic_fn1_wrapped(0); diff --git a/bindgen-tests/tests/headers/wrap-static-fns.h b/bindgen-tests/tests/headers/wrap-static-fns.h index 27757a8476..a35e713f2b 100644 --- a/bindgen-tests/tests/headers/wrap-static-fns.h +++ b/bindgen-tests/tests/headers/wrap-static-fns.h @@ -60,6 +60,8 @@ static inline int variadic(int x, ...) { return x; } +// aarch64-linux has a bug, remove ifdef when it is solved: +// https://github.com/rust-lang/rust-bindgen/issues/3234 #ifndef DISABLE_VA static inline void no_extra_argument(__builtin_va_list va) {} diff --git a/bindgen-tests/tests/tests.rs b/bindgen-tests/tests/tests.rs index 637f66bb52..27e8108052 100644 --- a/bindgen-tests/tests/tests.rs +++ b/bindgen-tests/tests/tests.rs @@ -726,6 +726,8 @@ fn test_wrap_static_fns() { // TODO: If another such feature is added, convert this test into a more generic // test that looks at `tests/headers/generated` directory. + // aarch64-linux has a bug, remove custom source when it is solved: + // https://github.com/rust-lang/rust-bindgen/issues/3234 let wrap_static_fns_c_name = if cfg!(all(target_arch = "aarch64", target_os = "linux")) { "wrap_static_fns_aarch64_linux" @@ -748,6 +750,8 @@ fn test_wrap_static_fns() { .wrap_static_fns_path(generated_path.display().to_string()) .parse_callbacks(Box::new(parse_callbacks::WrapAsVariadicFn)); + // aarch64-linux has a bug, remove when it is solved: + // https://github.com/rust-lang/rust-bindgen/issues/3234 #[cfg(all(target_arch = "aarch64", target_os = "linux"))] { builder = builder.clang_arg("-DDISABLE_VA"); From 5f7aa4b4edcb11a20f251e829bbc66034e21c8e2 Mon Sep 17 00:00:00 2001 From: Per Larsen Date: Fri, 8 Aug 2025 01:13:11 +0000 Subject: [PATCH 921/942] Fix typos in the descriptions of a few flags s/coma/comma/ in the strings added by PR #2866. Signed-off-by: Per Larsen --- bindgen/options/cli.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/bindgen/options/cli.rs b/bindgen/options/cli.rs index bce7faed35..b60de39603 100644 --- a/bindgen/options/cli.rs +++ b/bindgen/options/cli.rs @@ -474,28 +474,28 @@ struct BindgenCommand { /// Use DSTs to represent structures with flexible array members. #[arg(long)] flexarray_dst: bool, - /// Derive custom traits on any kind of type. The CUSTOM value must be of the shape REGEX=DERIVE where DERIVE is a coma-separated list of derive macros. + /// Derive custom traits on any kind of type. The CUSTOM value must be of the shape REGEX=DERIVE where DERIVE is a comma-separated list of derive macros. #[arg(long, value_name = "CUSTOM", value_parser = parse_custom_derive)] with_derive_custom: Vec<(Vec, String)>, - /// Derive custom traits on a `struct`. The CUSTOM value must be of the shape REGEX=DERIVE where DERIVE is a coma-separated list of derive macros. + /// Derive custom traits on a `struct`. The CUSTOM value must be of the shape REGEX=DERIVE where DERIVE is a comma-separated list of derive macros. #[arg(long, value_name = "CUSTOM", value_parser = parse_custom_derive)] with_derive_custom_struct: Vec<(Vec, String)>, - /// Derive custom traits on an `enum`. The CUSTOM value must be of the shape REGEX=DERIVE where DERIVE is a coma-separated list of derive macros. + /// Derive custom traits on an `enum`. The CUSTOM value must be of the shape REGEX=DERIVE where DERIVE is a comma-separated list of derive macros. #[arg(long, value_name = "CUSTOM", value_parser = parse_custom_derive)] with_derive_custom_enum: Vec<(Vec, String)>, - /// Derive custom traits on a `union`. The CUSTOM value must be of the shape REGEX=DERIVE where DERIVE is a coma-separated list of derive macros. + /// Derive custom traits on a `union`. The CUSTOM value must be of the shape REGEX=DERIVE where DERIVE is a comma-separated list of derive macros. #[arg(long, value_name = "CUSTOM", value_parser = parse_custom_derive)] with_derive_custom_union: Vec<(Vec, String)>, - /// Add custom attributes on any kind of type. The CUSTOM value must be of the shape REGEX=ATTRIBUTE where ATTRIBUTE is a coma-separated list of attributes. + /// Add custom attributes on any kind of type. The CUSTOM value must be of the shape REGEX=ATTRIBUTE where ATTRIBUTE is a comma-separated list of attributes. #[arg(long, value_name = "CUSTOM", value_parser = parse_custom_attribute)] with_attribute_custom: Vec<(Vec, String)>, - /// Add custom attributes on a `struct`. The CUSTOM value must be of the shape REGEX=ATTRIBUTE where ATTRIBUTE is a coma-separated list of attributes. + /// Add custom attributes on a `struct`. The CUSTOM value must be of the shape REGEX=ATTRIBUTE where ATTRIBUTE is a comma-separated list of attributes. #[arg(long, value_name = "CUSTOM", value_parser = parse_custom_attribute)] with_attribute_custom_struct: Vec<(Vec, String)>, - /// Add custom attributes on an `enum`. The CUSTOM value must be of the shape REGEX=ATTRIBUTE where ATTRIBUTE is a coma-separated list of attributes. + /// Add custom attributes on an `enum`. The CUSTOM value must be of the shape REGEX=ATTRIBUTE where ATTRIBUTE is a comma-separated list of attributes. #[arg(long, value_name = "CUSTOM", value_parser = parse_custom_attribute)] with_attribute_custom_enum: Vec<(Vec, String)>, - /// Add custom attributes on a `union`. The CUSTOM value must be of the shape REGEX=ATTRIBUTE where ATTRIBUTE is a coma-separated list of attributes. + /// Add custom attributes on a `union`. The CUSTOM value must be of the shape REGEX=ATTRIBUTE where ATTRIBUTE is a comma-separated list of attributes. #[arg(long, value_name = "CUSTOM", value_parser = parse_custom_attribute)] with_attribute_custom_union: Vec<(Vec, String)>, /// Generate wrappers for `static` and `static inline` functions. From 0b6f8f6466e630213647683aba36bd09a6d61871 Mon Sep 17 00:00:00 2001 From: Miikka Salminen Date: Fri, 15 Aug 2025 17:07:08 +0300 Subject: [PATCH 922/942] Configure an assign section to allow rustbot to assign PRs --- triagebot.toml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/triagebot.toml b/triagebot.toml index c196fb3d4d..77eb2925a3 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -25,4 +25,6 @@ trigger_files = [ "**/*.cpp", "**/*.cc", "**/*.hpp", -] \ No newline at end of file +] + +[assign] \ No newline at end of file From 4be63a7183685fad7e57d9f96cc39ee94fc85777 Mon Sep 17 00:00:00 2001 From: Miikka Salminen Date: Wed, 20 Aug 2025 12:34:17 +0300 Subject: [PATCH 923/942] Small fixes and clarifications to user guide Some letter casing, typing, formatting, and grammar errors are fixed. Links added to docs.rs in some text referring to documentation there, as well as to other external resources. For inclusivity, the tutorial's sanity test is renamed to a smoke test. --- book/src/SUMMARY.md | 12 ++++++------ book/src/command-line-usage.md | 2 +- book/src/faq.md | 18 +++++++++--------- book/src/must-use-types.md | 10 ++++++---- book/src/nocopy.md | 5 ++++- book/src/nodebug.md | 4 +++- book/src/nodefault.md | 10 +++++++--- book/src/objc.md | 28 ++++++++++++++-------------- book/src/tutorial-5.md | 6 +++--- book/src/using-bitfields.md | 6 ++++-- 10 files changed, 57 insertions(+), 44 deletions(-) diff --git a/book/src/SUMMARY.md b/book/src/SUMMARY.md index daaed04081..ac57aaad64 100644 --- a/book/src/SUMMARY.md +++ b/book/src/SUMMARY.md @@ -8,9 +8,9 @@ - [Create a `wrapper.h` Header](./tutorial-2.md) - [Create a `build.rs` File](./tutorial-3.md) - [Include the Generated Bindings in `src/lib.rs`](./tutorial-4.md) - - [Write a Sanity Test](./tutorial-5.md) + - [Write a Smoke Test](./tutorial-5.md) - [Publish Your Crate!](./tutorial-6.md) - - [Bindings for non-system libraries](./non-system-libraries.md) + - [Bindings for Non-System Libraries](./non-system-libraries.md) - [Command Line Usage](./command-line-usage.md) - [Customizing the Generated Bindings](./customizing-generated-bindings.md) - [Allowlisting](./allowlisting.md) @@ -20,11 +20,11 @@ - [Preventing the Derivation of `Copy` and `Clone`](./nocopy.md) - [Preventing the Derivation of `Debug`](./nodebug.md) - [Preventing the Derivation of `Default`](./nodefault.md) - - [Annotating types with `#[must-use]`](./must-use-types.md) - - [Field visibility](./visibility.md) - - [Code formatting](./code-formatting.md) + - [Annotating Types with `#[must-use]`](./must-use-types.md) + - [Field Visibility](./visibility.md) + - [Code Formatting](./code-formatting.md) - [Generating Bindings to C++](./cpp.md) -- [Generating Bindings to Objective-c](./objc.md) +- [Generating Bindings to Objective-C](./objc.md) - [Using Unions](./using-unions.md) - [Using Bitfields](./using-bitfields.md) - [Using Flexible Array Members](./using-fam.md) diff --git a/book/src/command-line-usage.md b/book/src/command-line-usage.md index b3356d70c7..051a63efad 100644 --- a/book/src/command-line-usage.md +++ b/book/src/command-line-usage.md @@ -13,7 +13,7 @@ directory to your `$PATH` to use `bindgen`. output file path for the generated bindings. If the output file path is not supplied, the bindings are printed to `stdout`. -If we wanted to generated Rust FFI bindings from a C header named `input.h` and +If we wanted to generate Rust FFI bindings from a C header named `input.h` and put them in the `bindings.rs` file, we would invoke `bindgen` like this: ```bash diff --git a/book/src/faq.md b/book/src/faq.md index bbaaab6368..59699ac757 100644 --- a/book/src/faq.md +++ b/book/src/faq.md @@ -47,18 +47,18 @@ creates linking errors. However, if you are compiling the C/C++ yourself (rather than using a system shared library, for example), then you can pass `-fkeep-inline-functions` or `-fno-inline-functions` to `gcc` or `clang`, and invoke `bindgen` with either -the `bindgen::Builder::generate_inline_functions` method or the -`--generate-inline-functions` flag. +the [`bindgen::Builder::generate_inline_functions`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.generate_inline_functions) +method or the `--generate-inline-functions` flag. Note that these functions and methods are usually marked inline for a reason: they tend to be hot. The above workaround makes them an out-of-line call, which might not provide acceptable performance. As an alternative, you can invoke `bindgen` with either the -`bindgen::Builder::wrap_static_fns` method or the `--wrap-static-fns` flag. -Which generates a C source file that can be compiled against the input headers -to produce Rust headers for `static` and `static inline` functions. See [How to -handle `static inline` functions](https://github.com/rust-lang/rust-bindgen/discussions/2405) +[`bindgen::Builder::wrap_static_fns`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.wrap_static_fns) +method or the `--wrap-static-fns` flag. That generates a C source file that can +be compiled against the input headers to produce Rust bindings for `static` and +`static inline` functions. See [How to handle `static inline` functions](https://github.com/rust-lang/rust-bindgen/discussions/2405) for further information. ### Does `bindgen` support the C++ Standard Template Library (STL)? @@ -81,8 +81,8 @@ possible that bindgen will generate padding fields named `__bindgen_padding_N`. As these fields might be present when compiling for one architecture but not for an other, you should not initialize these fields manually when initializing the struct. Instead, use the `Default` trait. You can either enable this when -constructing the `Builder` using the `derive_default` method, or you can -implement this per struct using: +constructing the `Builder` using the [`derive_default`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.derive_default) +method, or you can implement this per struct using: ```rust,ignore impl Default for SRC_DATA { @@ -107,7 +107,7 @@ be automatically initialized by `..Default::default()`. ### How to generate bindings for a custom target? -To generate bindings for a custom target you only need to pass the `--target` +To generate bindings for a custom target you only need to pass the [`--target`](https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-target) argument to `libclang`. For example, if you want to generate bindings for the `armv7a-none-eabi` target using the command line, you need to invoke `bindgen` like so: diff --git a/book/src/must-use-types.md b/book/src/must-use-types.md index 490339c9d2..1792e5a485 100644 --- a/book/src/must-use-types.md +++ b/book/src/must-use-types.md @@ -1,11 +1,13 @@ -# Annotating types with `#[must-use]` +# Annotating Types with `#[must-use]` `bindgen` can be instructed to annotate certain types with [`#[must_use]`](https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-must_use-attribute). -Some libraries have a common error type, returned by lots of their functions, -which needs to be checked after every call. In these cases it's useful to add `#[must_use]` to this type, so the Rust -compiler emits a warning when the check is missing. +Some libraries have a common error type, returned by many of their functions, +which needs to be checked after every call. In these cases it's useful to add +`#[must_use]` to this type, so the Rust compiler emits a warning when the check +is missing. + ### Library * [`bindgen::Builder::must_use_type`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.must_use_type) diff --git a/book/src/nocopy.md b/book/src/nocopy.md index 8a637a59c3..e0d17ed0cb 100644 --- a/book/src/nocopy.md +++ b/book/src/nocopy.md @@ -4,14 +4,17 @@ basis. Sometimes, it might not understand that although adding `#[derive(Copy, Clone)]` to a translated type definition will compile, it still shouldn't do that for reasons it can't know. In these cases, the `nocopy` annotation can be -used to prevent bindgen to autoderive the `Copy` and `Clone` traits for a type. +used to prevent bindgen from automatically deriving the `Copy` and `Clone` +traits for a type. ### Library +* [`bindgen::Builder::derive_copy`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.derive_copy) * [`bindgen::Builder::no_copy`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.no_copy) ### Command Line +* `--no-derive-copy` * `--no-copy ` ### Annotations diff --git a/book/src/nodebug.md b/book/src/nodebug.md index c412a7dfca..4fa820134b 100644 --- a/book/src/nodebug.md +++ b/book/src/nodebug.md @@ -3,14 +3,16 @@ `bindgen` will attempt to derive the `Debug` traits on a best-effort basis. Sometimes, it might not understand that although adding `#[derive(Debug)]` to a translated type definition will compile, it still shouldn't do that for reasons it can't know. In these cases, the `nodebug` annotation can be -used to prevent bindgen to autoderive the `Debug` traits for a type. +used to prevent bindgen from automatically deriving the `Debug` trait for a type. ### Library +* [`bindgen::Builder::derive_debug`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.derive_debug) * [`bindgen::Builder::no_debug`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.no_debug) ### Command Line +* `--no-derive-debug` * `--no-debug ` ### Annotations diff --git a/book/src/nodefault.md b/book/src/nodefault.md index 37896f6c5c..9561d7c17f 100644 --- a/book/src/nodefault.md +++ b/book/src/nodefault.md @@ -1,16 +1,20 @@ # Preventing the Derivation of `Default` +By default, `Default` is not derived. + `bindgen` will attempt to derive/impl the `Default` traits on a best-effort basis. -Sometimes, we need customize the implement of `Default` for certain types, -In these cases, the `nodefault` annotation can be used to prevent bindgen -to autoderive the `Default` traits for a type. +Sometimes, we need customize the implementation of `Default` for certain types. +In these cases, the `nodefault` annotation can be used to prevent bindgen from +automatically deriving the `Default` trait for a type. ### Library +* [`bindgen::Builder::derive_default`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.derive_default) * [`bindgen::Builder::no_default`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.no_default) ### Command Line +* `--with-derive-default` * `--no-default ` ### Annotations diff --git a/book/src/objc.md b/book/src/objc.md index ed6f2cb881..3845ed5a2e 100644 --- a/book/src/objc.md +++ b/book/src/objc.md @@ -1,10 +1,10 @@ # Generating Bindings to Objective-C -`bindgen` does not (yet) have full objective-c support but it can generate bindings -for a lot of the apple frameworks without too much blocklisting. +`bindgen` does not (yet) have full Objective-C support, but it can generate +bindings for many of the Apple frameworks without too much blocklisting. -In order to generate bindings, you will need `-x objective-c` as the clang -args. If you'd like to use [block](https://crates.io/crates/block) you will need +In order to generate bindings, you will need `-x objective-c` as a clang arg. If +you'd like to use [block](https://crates.io/crates/block) you will need `-fblocks` as a clang arg as well. Depending on your setup, you may need `--generate-block` to generate the block @@ -12,14 +12,14 @@ function aliases and `--block-extern-crate` to insert a `extern crate block` at the beginning of the generated bindings. The same logic applies to the `--objc-extern-crate` parameter. -The objective-c classes will be represented as a `struct Foo(id)` and a trait -`IFoo` where `Foo` is the objective-c class and `id` is an alias for `*mut -objc::runtime::Object` (the pointer to the objective-c instance). The trait +The Objective-C classes will be represented as a `struct Foo(id)` and a trait +`IFoo` where `Foo` is the Objective-C class and `id` is an alias for `*mut +objc::runtime::Object` (the pointer to the Objective-C instance). The trait `IFoo` is needed to allow for the generated inheritance. -Functions that use or return objective-c pointers of instance `Foo` will return +Functions that use or return Objective-C pointers of instance `Foo` will return `Foo`. The reason this works is because `Foo` represented as `transparent`. -This will be helpful for a lot of objective-c frameworks however there are some +This will be helpful for many Objective-C frameworks. However, there are some cases where functions return `instancetype` which is a type alias for `id` so an occasional `foo.0` may be required. An example of this would in the UIKit framework should you want to add a `UILabel` to a @@ -42,7 +42,7 @@ stands for interface. * Protocols which match to rust traits with prefixes of `P` which stands for Protocol. * Classes will generate `struct Foo(id)` where `Foo` is the class -name and `id` is a pointer to the objective-c Object. +name and `id` is a pointer to the Objective-C Object. * Blocks ## Useful Notes @@ -52,16 +52,16 @@ name and `id` is a pointer to the objective-c Object. [here](https://github.com/rust-lang/rust-bindgen/issues/1211#issuecomment-569804287). * The generated bindings will almost certainly have some conflicts so you will have to blocklist a few things. There are a few cases of the parameters being -poorly named in the objective-c headers. But if you're using anything with +poorly named in the Objective-C headers. But if you're using anything with Core Foundation, you'll find that `time.h` as has a variable called timezone that conflicts with some of the things in `NSCalendar.h`. -* Some small subset of the function headers in the apple frameworks go against -apple's guidelines for parameter names and duplicate the names in the header +* Some small subset of the function headers in the Apple frameworks go against +Apple's guidelines for parameter names and duplicate the names in the header which won't compile as mentioned [here](https://github.com/rust-lang/rust-bindgen/issues/1705). * instancetype return methods does not return `Self` for you given class, it returns a `mut * objc::runtime::Objc` which is aliased as `id`. This is because -objective-c's inheritance doesn't perfectly match that of rusts. +Objective-C's inheritance doesn't perfectly match that of Rust's. * Depending on what you're trying `bindgen` against, you may end up including all of Core Foundation and any other frameworks. This will result in a very long compile time. diff --git a/book/src/tutorial-5.md b/book/src/tutorial-5.md index 8a71dac355..8e308f82d6 100644 --- a/book/src/tutorial-5.md +++ b/book/src/tutorial-5.md @@ -1,11 +1,11 @@ -# Write a Sanity Test +# Write a Smoke Test -Finally, to tie everything together, let's write a sanity test that round trips +Finally, to tie everything together, let's write a smoke test that round trips some text through compression and decompression, and then asserts that it came back out the same as it went in. This is a little wordy using the raw FFI bindings, but hopefully we wouldn't usually ask people to do this, we'd provide a nice Rust-y API on top of the raw FFI bindings for them. However, since this -is for testing the bindings directly, our sanity test will use the bindings +is for testing the bindings directly, our smoke test will use the bindings directly. The test data I'm round tripping are some Futurama quotes I got off the internet diff --git a/book/src/using-bitfields.md b/book/src/using-bitfields.md index 8929f73705..6aaab2203d 100644 --- a/book/src/using-bitfields.md +++ b/book/src/using-bitfields.md @@ -15,7 +15,7 @@ pre-existing definition for the bitfield unit type. ## Bitfield examples -For this discussion, we will use the following C type definitions and functions. +For this discussion, we will use the following C type definitions and functions: ```c typedef struct { unsigned int a: 1; @@ -76,7 +76,9 @@ StructWithBitfields: a:1, b:1, c:0 To create a new bitfield in Rust, use the bitfield allocation unit constructor. -Note: This requires the Builder's derive_default to be set to true, otherwise the necessary Default functions won't be generated. +Note: This requires the `Builder`'s [`derive_default`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.derive_default) +to be set to `true`. Otherwise the necessary `Default` functions won't be +generated. ```rust,ignore let bfield = StructWithBitfields{ From 00d91a1daae03176186bd1447bfa5298ea8e4f30 Mon Sep 17 00:00:00 2001 From: Per Larsen Date: Fri, 15 Aug 2025 01:31:42 +0000 Subject: [PATCH 924/942] Test --rustified-non-exhaustive-enum flag --- .../tests/enum-doc-rusty-non-exhaustive.rs | 22 +++++++++++++++++++ .../headers/enum-doc-rusty-non-exhaustive.h | 3 +++ 2 files changed, 25 insertions(+) create mode 100644 bindgen-tests/tests/expectations/tests/enum-doc-rusty-non-exhaustive.rs create mode 100644 bindgen-tests/tests/headers/enum-doc-rusty-non-exhaustive.h diff --git a/bindgen-tests/tests/expectations/tests/enum-doc-rusty-non-exhaustive.rs b/bindgen-tests/tests/expectations/tests/enum-doc-rusty-non-exhaustive.rs new file mode 100644 index 0000000000..1d09466119 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/enum-doc-rusty-non-exhaustive.rs @@ -0,0 +1,22 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[repr(u32)] +#[non_exhaustive] +/// Document enum +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +pub enum B { + /// Document field with three slashes + VAR_A = 0, + /// Document field with preceding star + VAR_B = 1, + /// Document field with preceding exclamation + VAR_C = 2, + ///< Document field with following star + VAR_D = 3, + ///< Document field with following exclamation + VAR_E = 4, + /** Document field with preceding star, with a loong long multiline + comment. + + Very interesting documentation, definitely.*/ + VAR_F = 5, +} diff --git a/bindgen-tests/tests/headers/enum-doc-rusty-non-exhaustive.h b/bindgen-tests/tests/headers/enum-doc-rusty-non-exhaustive.h new file mode 100644 index 0000000000..b544a0c4fc --- /dev/null +++ b/bindgen-tests/tests/headers/enum-doc-rusty-non-exhaustive.h @@ -0,0 +1,3 @@ +// bindgen-flags: --rustified-non-exhaustive-enum B + +#include "enum-doc.h" From 45931da96b008788b66dd63434464bf30b16d4e8 Mon Sep 17 00:00:00 2001 From: Per Larsen Date: Fri, 15 Aug 2025 01:34:10 +0000 Subject: [PATCH 925/942] Fix typo in option handling for rustified non-exhaustive enums --rustified-non-exhaustive-enums should be --rustified-non-exhaustive-enum Necessary for tests added in parent to pass. --- bindgen/options/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindgen/options/mod.rs b/bindgen/options/mod.rs index b876b4d5b3..767be03e35 100644 --- a/bindgen/options/mod.rs +++ b/bindgen/options/mod.rs @@ -547,7 +547,7 @@ options! { } } }, - as_args: "--rustified-non-exhaustive-enums", + as_args: "--rustified-non-exhaustive-enum", }, /// `enum`s marked as modules of constants. constified_enum_modules: RegexSet { From 4f3fb8f0b3c89e42ea9fcf02b67612ad52ca5da7 Mon Sep 17 00:00:00 2001 From: Per Larsen Date: Fri, 15 Aug 2025 01:44:58 +0000 Subject: [PATCH 926/942] Update CHANGELOG.md Record fix in https://github.com/rust-lang/rust-bindgen/pull/3266 --- CHANGELOG.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a6165b9ac..c0d3494e75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -230,6 +230,7 @@ ## Changed ## Removed ## Fixed +- Typo in code for `--rustified-non-exhaustive-enums` (#3266) ## Security # 0.72.0 (2025-06-08) @@ -277,8 +278,8 @@ - Add support for custom attributes with the `--with-attribute-custom` flag (#2866) - Allow setting `--rust-target` to any Rust version supported by bindgen (#2993) - Use c-string literals if the `--generate-cstr` flag is used for Rust targets after 1.77 under the 2021 edition (#2996) -- Add the `--rust-edition` flag which allows to select which Rust edition to target. (#3002, #3013) -- Use `unsafe extern` instead of `extern` in blocks for any Rust target after 1.82. (#3015) +- Add the `--rust-edition` flag which allows to select which Rust edition to target. (#3002, #3013) +- Use `unsafe extern` instead of `extern` in blocks for any Rust target after 1.82. (#3015) ## Changed - The `--wrap-static-fns` related options no longer require the experimental feature or flag (#2928) - Use the `Display` implementation instead of the `Debug` one for `BindgenError` in `bindgen-cli` (#3005) @@ -443,7 +444,7 @@ This version was skipped due to some problems on the release workflow. * The `--wrap-static-fns` option can now wrap `va_list` functions as variadic functions with the experimental `ParseCallbacks::wrap_as_variadic_fn` method. * Add target mappings for riscv32imc and riscv32imac. -* Add the `ParseCallbacks::field_visibility` method to modify field visibility. +* Add the `ParseCallbacks::field_visibility` method to modify field visibility. ## Changed @@ -467,7 +468,7 @@ This version was skipped due to some problems on the release workflow. * Compute visibility of bitfield unit based on actual field visibility: A bitfield unit field and its related functions now have their visibility determined based on the most private between the default visibility and the - actual visibility of the bitfields within the unit. + actual visibility of the bitfields within the unit. ## Removed * Remove redundant Cargo features, which were all implicit: @@ -523,7 +524,7 @@ This version was skipped due to some problems on the release workflow. types. (#2463) * The `Builder::rustfmt_bindings` methods and the `--no-rustfmt-bindings` flag are now deprecated in favor of the formatter API. (#2453) - + ## Removed * The following deprecated flags were removed: `--use-msvc-mangling`, `--rustfmt-bindings` and `--size_t-is-usize`. (#2408) From b03b2221a46f14269364b196324cf39497d9b024 Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Fri, 22 Aug 2025 11:20:04 +0200 Subject: [PATCH 927/942] ci: Move forward Rust for Linux version to v6.17-rc2 Signed-off-by: Miguel Ojeda --- ci/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/test.sh b/ci/test.sh index 952b48e80d..587263804b 100755 --- a/ci/test.sh +++ b/ci/test.sh @@ -96,7 +96,7 @@ if [ "$BINDGEN_RUST_FOR_LINUX_TEST" == "1" ]; then # and each update should only contain this change. # # Both commit hashes and tags are supported. - LINUX_VERSION=v6.16-rc1 + LINUX_VERSION=v6.17-rc2 # Download Linux at a specific commit mkdir -p linux From 6b6af6b148dd92e2fa8ee78d56e2985e42481333 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Tue, 26 Aug 2025 19:21:17 -0400 Subject: [PATCH 928/942] chore: minor cleanup * fix error messages missing spaces * simplify rustfmt_path() --- bindgen/ir/comp.rs | 4 ++-- bindgen/lib.rs | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/bindgen/ir/comp.rs b/bindgen/ir/comp.rs index c0860f9fe3..0b50bf3244 100644 --- a/bindgen/ir/comp.rs +++ b/bindgen/ir/comp.rs @@ -361,7 +361,7 @@ impl Bitfield { "`Bitfield::getter_name` called on anonymous field" ); self.getter_name.as_ref().expect( - "`Bitfield::getter_name` should only be called after\ + "`Bitfield::getter_name` should only be called after \ assigning bitfield accessor names", ) } @@ -376,7 +376,7 @@ impl Bitfield { "`Bitfield::setter_name` called on anonymous field" ); self.setter_name.as_ref().expect( - "`Bitfield::setter_name` should only be called\ + "`Bitfield::setter_name` should only be called \ after assigning bitfield accessor names", ) } diff --git a/bindgen/lib.rs b/bindgen/lib.rs index e4294c505a..3582e6af80 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -978,17 +978,17 @@ impl Bindings { } /// Gets the rustfmt path to rustfmt the generated bindings. - fn rustfmt_path(&self) -> io::Result> { + fn rustfmt_path(&self) -> Cow<'_, Path> { debug_assert!(matches!(self.options.formatter, Formatter::Rustfmt)); if let Some(ref p) = self.options.rustfmt_path { - return Ok(Cow::Borrowed(p)); - } - if let Ok(rustfmt) = env::var("RUSTFMT") { - return Ok(Cow::Owned(rustfmt.into())); + Cow::Borrowed(p) + } else if let Ok(rustfmt) = env::var("RUSTFMT") { + Cow::Owned(rustfmt.into()) + } else { + // No rustfmt binary was specified, so assume that the binary is called + // "rustfmt" and that it is in the user's PATH. + Cow::Borrowed(Path::new("rustfmt")) } - // No rustfmt binary was specified, so assume that the binary is called - // "rustfmt" and that it is in the user's PATH. - Ok(Cow::Owned("rustfmt".into())) } /// Formats a token stream with the formatter set up in `BindgenOptions`. @@ -1008,7 +1008,7 @@ impl Bindings { Formatter::Rustfmt => (), } - let rustfmt = self.rustfmt_path()?; + let rustfmt = self.rustfmt_path(); let mut cmd = Command::new(&*rustfmt); cmd.stdin(Stdio::piped()).stdout(Stdio::piped()); From 5fa4a1fa83ee8f03d26bde3a60885ac989554f05 Mon Sep 17 00:00:00 2001 From: Hans Wennborg Date: Wed, 27 Aug 2025 14:05:50 +0200 Subject: [PATCH 929/942] Get the type's definition in CompInfo::from_ty In https://github.com/llvm/llvm-project/pull/147835, Clang's AST changed so that a TagType's decl will not necessarily refer to the type's definition, but to the exact declaration which produced the type. For example, in typedef struct S T; struct S { int x; }; the 'struct S' type would refer to the incomplete type decl in the typedef, causing CompInfo to fail to see the type's definition. This patch inserts a call to use the definition when available. It fixes the original test case in https://github.com/rust-lang/rust-bindgen/issues/3275 and most of the test failures caused by the Clang change but not all. --- bindgen/ir/comp.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bindgen/ir/comp.rs b/bindgen/ir/comp.rs index 0b50bf3244..f0c4e6f03c 100644 --- a/bindgen/ir/comp.rs +++ b/bindgen/ir/comp.rs @@ -1234,6 +1234,12 @@ impl CompInfo { ); let mut cursor = ty.declaration(); + + // If there is a definition, that's what we want. + if let Some(def) = cursor.definition() { + cursor = def; + } + let mut kind = Self::kind_from_cursor(&cursor); if kind.is_err() { if let Some(location) = location { From 2426dd68cd12e0ac022bca18efb9c7d0acd27e12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 27 Aug 2025 15:57:15 +0200 Subject: [PATCH 930/942] clang: Push the fix for #3277 into Type::declaration. Fixes #3264. --- .../expectations/tests/nested-class-field.rs | 22 +++++++++++++++++++ .../tests/headers/nested-class-field.hpp | 7 ++++++ bindgen/clang.rs | 10 ++++----- bindgen/ir/comp.rs | 6 ----- 4 files changed, 34 insertions(+), 11 deletions(-) create mode 100644 bindgen-tests/tests/expectations/tests/nested-class-field.rs create mode 100644 bindgen-tests/tests/headers/nested-class-field.hpp diff --git a/bindgen-tests/tests/expectations/tests/nested-class-field.rs b/bindgen-tests/tests/expectations/tests/nested-class-field.rs new file mode 100644 index 0000000000..91500f4142 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/nested-class-field.rs @@ -0,0 +1,22 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct A { + pub _address: u8, +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of A"][::std::mem::size_of::
() - 1usize]; + ["Alignment of A"][::std::mem::align_of::() - 1usize]; +}; +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct A_I { + pub i: ::std::os::raw::c_int, +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of A_I"][::std::mem::size_of::() - 4usize]; + ["Alignment of A_I"][::std::mem::align_of::() - 4usize]; + ["Offset of field: A_I::i"][::std::mem::offset_of!(A_I, i) - 0usize]; +}; diff --git a/bindgen-tests/tests/headers/nested-class-field.hpp b/bindgen-tests/tests/headers/nested-class-field.hpp new file mode 100644 index 0000000000..295ebe8129 --- /dev/null +++ b/bindgen-tests/tests/headers/nested-class-field.hpp @@ -0,0 +1,7 @@ +class A { + class I; +}; + +class A::I { + int i; +}; diff --git a/bindgen/clang.rs b/bindgen/clang.rs index e52fed0d4a..1e8326ed82 100644 --- a/bindgen/clang.rs +++ b/bindgen/clang.rs @@ -1211,11 +1211,11 @@ impl Type { /// Get a cursor pointing to this type's declaration. pub(crate) fn declaration(&self) -> Cursor { - unsafe { - Cursor { - x: clang_getTypeDeclaration(self.x), - } - } + let decl = Cursor { + x: unsafe { clang_getTypeDeclaration(self.x) }, + }; + // Prior to clang 22, the declaration pointed to the definition. + decl.definition().unwrap_or(decl) } /// Get the canonical declaration of this type, if it is available. diff --git a/bindgen/ir/comp.rs b/bindgen/ir/comp.rs index f0c4e6f03c..0b50bf3244 100644 --- a/bindgen/ir/comp.rs +++ b/bindgen/ir/comp.rs @@ -1234,12 +1234,6 @@ impl CompInfo { ); let mut cursor = ty.declaration(); - - // If there is a definition, that's what we want. - if let Some(def) = cursor.definition() { - cursor = def; - } - let mut kind = Self::kind_from_cursor(&cursor); if kind.is_err() { if let Some(location) = location { From fc747b70919316aa93e8ccbdae6d462b4fab8eab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 27 Aug 2025 18:08:04 +0200 Subject: [PATCH 931/942] codegen: Bump minimum stable target. Supporting const generics significantly simplifies some upcoming correctness fixes, and rust 1.51 is more than four years old at this point. This highlighted some issues with some of the features that we've implemented since (e.g. the code to generate partialeq was broken in a lot of cases). --- CHANGELOG.md | 1 + .../tests/attribute_warn_unused_result.rs | 14 +- ...rn_unused_result_no_attribute_detection.rs | 14 +- .../tests/bindgen-union-inside-namespace.rs | 30 +- .../tests/expectations/tests/class.rs | 393 ++--- .../expectations/tests/constructors_1_33.rs | 56 +- .../tests/derive-bitfield-method-same-name.rs | 140 +- .../tests/expectations/tests/derive-clone.rs | 28 +- .../tests/derive-debug-bitfield-1-51.rs | 18 +- .../tests/derive-debug-bitfield-core.rs | 135 +- .../tests/derive-debug-bitfield.rs | 148 +- .../tests/derive-debug-function-pointer.rs | 47 +- .../tests/derive-debug-generic.rs | 6 +- ...ive-debug-opaque-template-instantiation.rs | 30 +- .../expectations/tests/derive-debug-opaque.rs | 28 +- .../tests/derive-partialeq-base.rs | 50 +- .../tests/derive-partialeq-bitfield.rs | 132 +- .../tests/derive-partialeq-core.rs | 27 +- .../expectations/tests/extern-const-struct.rs | 22 +- .../tests/extern_blocks_pre_1_82.rs | 4 +- .../tests/expectations/tests/i128.rs | 24 +- .../tests/expectations/tests/issue-1291.rs | 102 +- .../tests/expectations/tests/issue-372.rs | 78 +- .../tests/issue-537-repr-packed-n.rs | 100 +- .../issue-648-derive-debug-with-padding.rs | 64 +- .../tests/expectations/tests/layout_array.rs | 206 +-- .../tests/layout_array_too_long.rs | 163 +-- .../expectations/tests/layout_eth_conf.rs | 1293 +++++++++-------- .../expectations/tests/layout_kni_mbuf.rs | 102 +- .../tests/layout_large_align_field.rs | 329 ++--- .../tests/expectations/tests/long_double.rs | 18 +- .../tests/no_debug_bypass_impl_debug.rs | 6 +- .../tests/no_default_bypass_derive_default.rs | 2 + .../tests/opaque-template-inst-member.rs | 76 +- .../tests/expectations/tests/packed-vtable.rs | 22 +- .../tests/expectations/tests/repr-align.rs | 48 +- .../tests/struct_with_derive_debug.rs | 92 +- .../tests/struct_with_large_array.rs | 21 +- .../tests/expectations/tests/transform-op.rs | 102 +- .../tests/expectations/tests/union-align.rs | 48 +- .../tests/expectations/tests/win32-dtors.rs | 130 +- .../expectations/tests/win32-thiscall.rs | 30 +- .../tests/wrap_unsafe_ops_anon_union.rs | 18 +- .../headers/attribute_warn_unused_result.hpp | 2 +- ...n_unused_result_no_attribute_detection.hpp | 2 - .../bindgen-union-inside-namespace.hpp | 2 +- .../tests/headers/bitfield-enum-repr-c.hpp | 2 +- .../bitfield-enum-repr-transparent.hpp | 2 +- bindgen-tests/tests/headers/class.hpp | 2 +- .../tests/headers/constructors_1_33.hpp | 2 - .../derive-bitfield-method-same-name.hpp | 2 +- bindgen-tests/tests/headers/derive-clone.h | 3 - .../headers/derive-debug-bitfield-1-51.hpp | 2 +- .../headers/derive-debug-bitfield-core.hpp | 2 +- .../tests/headers/derive-debug-bitfield.hpp | 2 +- .../headers/derive-debug-function-pointer.hpp | 2 +- .../tests/headers/derive-debug-generic.hpp | 2 +- ...ve-debug-opaque-template-instantiation.hpp | 2 +- .../tests/headers/derive-debug-opaque.hpp | 2 +- .../tests/headers/derive-partialeq-base.hpp | 2 +- .../headers/derive-partialeq-bitfield.hpp | 2 +- .../tests/headers/derive-partialeq-core.h | 2 +- .../tests/headers/extern-const-struct.h | 2 - .../tests/headers/extern_blocks_pre_1_82.h | 2 +- bindgen-tests/tests/headers/i128.h | 2 - bindgen-tests/tests/headers/issue-1291.hpp | 1 - bindgen-tests/tests/headers/issue-372.hpp | 2 +- .../tests/headers/issue-537-repr-packed-n.h | 2 +- .../issue-648-derive-debug-with-padding.h | 2 +- bindgen-tests/tests/headers/layout.h | 2 - bindgen-tests/tests/headers/layout_array.h | 2 +- .../tests/headers/layout_array_too_long.h | 2 +- bindgen-tests/tests/headers/layout_eth_conf.h | 2 +- bindgen-tests/tests/headers/layout_kni_mbuf.h | 2 - .../tests/headers/layout_large_align_field.h | 2 +- bindgen-tests/tests/headers/long_double.h | 2 - bindgen-tests/tests/headers/newtype-enum.hpp | 2 +- .../tests/headers/newtype-global-enum.hpp | 2 +- .../headers/no_debug_bypass_impl_debug.hpp | 2 +- .../no_default_bypass_derive_default.hpp | 2 +- .../headers/opaque-template-inst-member.hpp | 2 +- bindgen-tests/tests/headers/packed-vtable.h | 2 +- bindgen-tests/tests/headers/repr-align.hpp | 2 +- bindgen-tests/tests/headers/strings_array.h | 2 - .../tests/headers/struct_with_derive_debug.h | 2 +- .../tests/headers/struct_with_large_array.hpp | 2 +- bindgen-tests/tests/headers/transform-op.hpp | 2 +- bindgen-tests/tests/headers/union-align.h | 2 - bindgen-tests/tests/headers/win32-dtors.hpp | 4 +- .../tests/headers/win32-thiscall.hpp | 2 +- .../tests/headers/win32-vectorcall.h | 2 +- .../headers/wrap_unsafe_ops_anon_union.hpp | 2 +- bindgen/codegen/bitfield_unit.rs | 83 ++ .../codegen/bitfield_unit_raw_ref_macros.rs | 191 --- bindgen/codegen/helpers.rs | 49 +- bindgen/codegen/impl_debug.rs | 27 +- bindgen/codegen/impl_partialeq.rs | 36 +- bindgen/codegen/mod.rs | 118 +- bindgen/features.rs | 14 +- bindgen/ir/analysis/derive.rs | 8 +- bindgen/ir/comp.rs | 23 +- 101 files changed, 2180 insertions(+), 2866 deletions(-) delete mode 100644 bindgen/codegen/bitfield_unit_raw_ref_macros.rs 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 } } From 159c833c9e3423b124f511d28e2e7f2def5d3d57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 27 Aug 2025 18:45:50 +0200 Subject: [PATCH 932/942] codegen: Appease nightly clippy too. --- bindgen/codegen/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 25118f2a89..60e3404875 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -3749,7 +3749,7 @@ impl CodeGenerator for Enum { utils::call_discovered_item_callback(ctx, item, || { DiscoveredItem::Enum { - final_name: name.to_string(), + final_name: name.clone(), } }); @@ -4653,7 +4653,7 @@ impl CodeGenerator for Function { } utils::call_discovered_item_callback(ctx, item, || { DiscoveredItem::Function { - final_name: canonical_name.to_string(), + final_name: canonical_name.clone(), } }); From 9366e0af8da529c958b4cd4fcbe492d951c86f5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 27 Aug 2025 16:46:50 +0200 Subject: [PATCH 933/942] codegen: Guarantee opaque type layout across all architectures. Fixes #3279 --- .../tests/bitfield_large_overflow.rs | 10 +++- ...ive-debug-opaque-template-instantiation.rs | 25 ++------- .../expectations/tests/derive-debug-opaque.rs | 40 ++++--------- .../tests/expectations/tests/issue-3027.rs | 10 ++-- .../tests/expectations/tests/issue-372.rs | 22 ++------ .../tests/issue-544-stylo-creduce-2.rs | 10 ++-- .../tests/expectations/tests/layout_array.rs | 10 +++- .../tests/layout_large_align_field.rs | 10 +++- .../libclang-9/issue-544-stylo-creduce-2.rs | 14 ++--- .../expectations/tests/non-type-params.rs | 14 ++--- .../expectations/tests/nsBaseHashtable.rs | 10 ++-- .../tests/expectations/tests/objc_template.rs | 15 ++++- .../tests/opaque-template-inst-member.rs | 33 +++-------- .../partial-specialization-and-inheritance.rs | 10 ++-- .../expectations/tests/size_t_template.rs | 10 ++-- .../tests/expectations/tests/unknown_attr.rs | 10 +++- .../tests/va_list_aarch64_linux.rs | 14 ++--- bindgen/codegen/helpers.rs | 50 +++++++++-------- bindgen/codegen/mod.rs | 52 ++++++++++------- bindgen/ir/analysis/derive.rs | 49 ++++------------ bindgen/ir/context.rs | 19 +++++-- bindgen/ir/item.rs | 3 +- bindgen/ir/layout.rs | 56 ------------------- bindgen/ir/ty.rs | 18 +++++- 24 files changed, 212 insertions(+), 302 deletions(-) diff --git a/bindgen-tests/tests/expectations/tests/bitfield_large_overflow.rs b/bindgen-tests/tests/expectations/tests/bitfield_large_overflow.rs index ed7d1b3bb7..ac5d75735e 100644 --- a/bindgen-tests/tests/expectations/tests/bitfield_large_overflow.rs +++ b/bindgen-tests/tests/expectations/tests/bitfield_large_overflow.rs @@ -1,9 +1,17 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[derive(PartialEq, Eq, Copy, Clone, Debug, Hash)] +#[repr(C, align(8))] +pub struct __BindgenOpaqueArray8(pub T); +impl Default for __BindgenOpaqueArray8<[T; N]> { + fn default() -> Self { + Self([::default(); N]) + } +} #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct _bindgen_ty_1 { pub _bindgen_align: [u64; 0], - pub _bindgen_opaque_blob: [u64; 10usize], + pub _bindgen_opaque_blob: __BindgenOpaqueArray8<[u8; 80usize]>, } #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { 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 ac564a3cf6..9d75e74d77 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,17 +1,16 @@ #![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)] +#[derive(PartialEq, Eq, Copy, Clone, Debug, Hash)] #[repr(C)] -pub struct __BindgenOpaqueArray(pub [T; N]); -impl Default for __BindgenOpaqueArray { +pub struct __BindgenOpaqueArray(pub T); +impl Default for __BindgenOpaqueArray<[T; N]> { fn default() -> Self { Self([::default(); N]) } } #[repr(C)] +#[derive(Debug, Default, Copy, Clone)] pub struct Instance { - pub val: __BindgenOpaqueArray, + pub val: __BindgenOpaqueArray<[u32; 50usize]>, } #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { @@ -19,17 +18,3 @@ const _: () = { ["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(); - unsafe { - ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); - s.assume_init() - } - } -} -impl ::std::fmt::Debug for Instance { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - write!(f, "Instance {{ val: opaque }}") - } -} diff --git a/bindgen-tests/tests/expectations/tests/derive-debug-opaque.rs b/bindgen-tests/tests/expectations/tests/derive-debug-opaque.rs index c8b3f10b93..4ec1fb2a35 100644 --- a/bindgen-tests/tests/expectations/tests/derive-debug-opaque.rs +++ b/bindgen-tests/tests/expectations/tests/derive-debug-opaque.rs @@ -1,29 +1,25 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[derive(PartialEq, Eq, Copy, Clone, Debug, Hash)] +#[repr(C)] +pub struct __BindgenOpaqueArray(pub T); +impl Default for __BindgenOpaqueArray<[T; N]> { + fn default() -> Self { + Self([::default(); N]) + } +} #[repr(C)] #[repr(align(4))] +#[derive(Debug, Default, Copy, Clone)] pub struct Opaque { - pub _bindgen_opaque_blob: [u32; 41usize], + pub _bindgen_opaque_blob: __BindgenOpaqueArray<[u32; 41usize]>, } #[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(); - unsafe { - ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); - s.assume_init() - } - } -} -impl ::std::fmt::Debug for Opaque { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - write!(f, "Opaque {{ opaque }}") - } -} #[repr(C)] +#[derive(Debug, Default, Copy, Clone)] pub struct OpaqueUser { pub opaque: Opaque, } @@ -35,17 +31,3 @@ const _: () = { "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(); - unsafe { - ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); - s.assume_init() - } - } -} -impl ::std::fmt::Debug for OpaqueUser { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - write!(f, "OpaqueUser {{ opaque: {:?} }}", self.opaque) - } -} diff --git a/bindgen-tests/tests/expectations/tests/issue-3027.rs b/bindgen-tests/tests/expectations/tests/issue-3027.rs index 757aa9d9df..c8c2a7e542 100644 --- a/bindgen-tests/tests/expectations/tests/issue-3027.rs +++ b/bindgen-tests/tests/expectations/tests/issue-3027.rs @@ -1,12 +1,10 @@ #![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)] + #[derive(PartialEq, Eq, Copy, Clone, Debug, Hash)] #[repr(C)] - pub struct __BindgenOpaqueArray(pub [T; N]); - impl Default for __BindgenOpaqueArray { + pub struct __BindgenOpaqueArray(pub T); + impl Default for __BindgenOpaqueArray<[T; N]> { fn default() -> Self { Self([::default(); N]) } @@ -19,7 +17,7 @@ pub mod root { #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct C { - pub a: root::__BindgenOpaqueArray, + pub a: root::__BindgenOpaqueArray<[u8; 3usize]>, } #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { diff --git a/bindgen-tests/tests/expectations/tests/issue-372.rs b/bindgen-tests/tests/expectations/tests/issue-372.rs index 62160d6351..cf00a70743 100644 --- a/bindgen-tests/tests/expectations/tests/issue-372.rs +++ b/bindgen-tests/tests/expectations/tests/issue-372.rs @@ -1,12 +1,10 @@ #![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 { + #[derive(PartialEq, Eq, Copy, Clone, Debug, Hash)] + #[repr(C, align(8))] + pub struct __BindgenOpaqueArray8(pub T); + impl Default for __BindgenOpaqueArray8<[T; N]> { fn default() -> Self { Self([::default(); N]) } @@ -74,8 +72,9 @@ pub mod root { ai = 11, } #[repr(C)] + #[derive(Debug, Default, Copy, Clone)] pub struct F { - pub w: root::__BindgenOpaqueArray, + pub w: root::__BindgenOpaqueArray8<[u8; 264usize]>, } #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { @@ -83,13 +82,4 @@ pub mod root { ["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(); - unsafe { - ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); - s.assume_init() - } - } - } } diff --git a/bindgen-tests/tests/expectations/tests/issue-544-stylo-creduce-2.rs b/bindgen-tests/tests/expectations/tests/issue-544-stylo-creduce-2.rs index 8a752f6999..a160d0275d 100644 --- a/bindgen-tests/tests/expectations/tests/issue-544-stylo-creduce-2.rs +++ b/bindgen-tests/tests/expectations/tests/issue-544-stylo-creduce-2.rs @@ -1,10 +1,8 @@ #![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)] +#[derive(PartialEq, Eq, Copy, Clone, Debug, Hash)] #[repr(C)] -pub struct __BindgenOpaqueArray(pub [T; N]); -impl Default for __BindgenOpaqueArray { +pub struct __BindgenOpaqueArray(pub T); +impl Default for __BindgenOpaqueArray<[T; N]> { fn default() -> Self { Self([::default(); N]) } @@ -14,7 +12,7 @@ impl Default for __BindgenOpaqueArray { pub struct Foo { pub member: *mut Foo_SecondAlias, } -pub type Foo_FirstAlias = __BindgenOpaqueArray; +pub type Foo_FirstAlias = __BindgenOpaqueArray<[u8; 0usize]>; pub type Foo_SecondAlias = Foo; impl Default for Foo { fn default() -> Self { diff --git a/bindgen-tests/tests/expectations/tests/layout_array.rs b/bindgen-tests/tests/expectations/tests/layout_array.rs index a2805b7060..3afe1c2dd8 100644 --- a/bindgen-tests/tests/expectations/tests/layout_array.rs +++ b/bindgen-tests/tests/expectations/tests/layout_array.rs @@ -1,4 +1,12 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[derive(PartialEq, Eq, Copy, Clone, Debug, Hash)] +#[repr(C, align(8))] +pub struct __BindgenOpaqueArray8(pub T); +impl Default for __BindgenOpaqueArray8<[T; N]> { + fn default() -> Self { + Self([::default(); N]) + } +} pub const RTE_CACHE_LINE_SIZE: u32 = 64; pub const RTE_MEMPOOL_OPS_NAMESIZE: u32 = 32; pub const RTE_MEMPOOL_MAX_OPS_IDX: u32 = 16; @@ -125,7 +133,7 @@ pub struct rte_mempool_ops_table { pub sl: rte_spinlock_t, ///< Number of used ops structs in the table. pub num_ops: u32, - pub __bindgen_padding_0: [u64; 7usize], + pub __bindgen_padding_0: __BindgenOpaqueArray8<[u8; 56usize]>, /// Storage for all possible ops structs. pub ops: [rte_mempool_ops; 16usize], } 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 3be68eb925..0ccd40a5f8 100644 --- a/bindgen-tests/tests/expectations/tests/layout_large_align_field.rs +++ b/bindgen-tests/tests/expectations/tests/layout_large_align_field.rs @@ -1,4 +1,12 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[derive(PartialEq, Eq, Copy, Clone, Debug, Hash)] +#[repr(C, align(8))] +pub struct __BindgenOpaqueArray8(pub T); +impl Default for __BindgenOpaqueArray8<[T; N]> { + fn default() -> Self { + Self([::default(); N]) + } +} #[repr(C)] #[derive(Default)] pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); @@ -286,7 +294,7 @@ pub struct rte_ip_frag_tbl { pub last: *mut ip_frag_pkt, ///< LRU list for table entries. pub lru: ip_pkt_list, - pub __bindgen_padding_0: u64, + pub __bindgen_padding_0: __BindgenOpaqueArray8<[u8; 8usize]>, ///< statistics counters. pub stat: ip_frag_tbl_stat, ///< hash table. diff --git a/bindgen-tests/tests/expectations/tests/libclang-9/issue-544-stylo-creduce-2.rs b/bindgen-tests/tests/expectations/tests/libclang-9/issue-544-stylo-creduce-2.rs index 7f0471bd96..d64a8948ee 100644 --- a/bindgen-tests/tests/expectations/tests/libclang-9/issue-544-stylo-creduce-2.rs +++ b/bindgen-tests/tests/expectations/tests/libclang-9/issue-544-stylo-creduce-2.rs @@ -1,10 +1,8 @@ #![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)] +#[derive(PartialEq, Eq, Copy, Clone, Debug, Hash)] #[repr(C)] -pub struct __BindgenOpaqueArray(pub [T; N]); -impl Default for __BindgenOpaqueArray { +pub struct __BindgenOpaqueArray(pub T); +impl Default for __BindgenOpaqueArray<[T; N]> { fn default() -> Self { Self([::default(); N]) } @@ -12,10 +10,10 @@ impl Default for __BindgenOpaqueArray { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct Foo { - pub member: *mut __BindgenOpaqueArray, + pub member: *mut __BindgenOpaqueArray<[u8; 0usize]>, } -pub type Foo_FirstAlias = __BindgenOpaqueArray; -pub type Foo_SecondAlias = __BindgenOpaqueArray; +pub type Foo_FirstAlias = __BindgenOpaqueArray<[u8; 0usize]>; +pub type Foo_SecondAlias = __BindgenOpaqueArray<[u8; 0usize]>; impl Default for Foo { fn default() -> Self { let mut s = ::std::mem::MaybeUninit::::uninit(); diff --git a/bindgen-tests/tests/expectations/tests/non-type-params.rs b/bindgen-tests/tests/expectations/tests/non-type-params.rs index afd21fb767..325620b9bb 100644 --- a/bindgen-tests/tests/expectations/tests/non-type-params.rs +++ b/bindgen-tests/tests/expectations/tests/non-type-params.rs @@ -1,21 +1,19 @@ #![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)] +#[derive(PartialEq, Eq, Copy, Clone, Debug, Hash)] #[repr(C)] -pub struct __BindgenOpaqueArray(pub [T; N]); -impl Default for __BindgenOpaqueArray { +pub struct __BindgenOpaqueArray(pub T); +impl Default for __BindgenOpaqueArray<[T; N]> { fn default() -> Self { Self([::default(); N]) } } pub type Array16 = u8; -pub type ArrayInt4 = __BindgenOpaqueArray; +pub type ArrayInt4 = __BindgenOpaqueArray<[u32; 4usize]>; #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct UsesArray { - pub array_char_16: __BindgenOpaqueArray, - pub array_bool_8: __BindgenOpaqueArray, + pub array_char_16: __BindgenOpaqueArray<[u8; 16usize]>, + pub array_bool_8: __BindgenOpaqueArray<[u8; 8usize]>, pub array_int_4: ArrayInt4, } #[allow(clippy::unnecessary_operation, clippy::identity_op)] diff --git a/bindgen-tests/tests/expectations/tests/nsBaseHashtable.rs b/bindgen-tests/tests/expectations/tests/nsBaseHashtable.rs index 32fcc37aba..81b9f000c6 100644 --- a/bindgen-tests/tests/expectations/tests/nsBaseHashtable.rs +++ b/bindgen-tests/tests/expectations/tests/nsBaseHashtable.rs @@ -1,10 +1,8 @@ #![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)] +#[derive(PartialEq, Eq, Copy, Clone, Debug, Hash)] #[repr(C)] -pub struct __BindgenOpaqueArray(pub [T; N]); -impl Default for __BindgenOpaqueArray { +pub struct __BindgenOpaqueArray(pub T); +impl Default for __BindgenOpaqueArray<[T; N]> { fn default() -> Self { Self([::default(); N]) } @@ -24,7 +22,7 @@ pub struct nsTHashtable { pub struct nsBaseHashtable { pub _address: u8, } -pub type nsBaseHashtable_KeyType = __BindgenOpaqueArray; +pub type nsBaseHashtable_KeyType = __BindgenOpaqueArray<[u8; 0usize]>; pub type nsBaseHashtable_EntryType = nsBaseHashtableET; #[repr(C)] #[derive(Debug, Copy, Clone)] diff --git a/bindgen-tests/tests/expectations/tests/objc_template.rs b/bindgen-tests/tests/expectations/tests/objc_template.rs index ee47f67d4c..1c70009df3 100644 --- a/bindgen-tests/tests/expectations/tests/objc_template.rs +++ b/bindgen-tests/tests/expectations/tests/objc_template.rs @@ -3,6 +3,14 @@ use objc::{self, msg_send, sel, sel_impl, class}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; +#[derive(PartialEq, Eq, Copy, Clone, Debug, Hash)] +#[repr(C, align(8))] +pub struct __BindgenOpaqueArray8(pub T); +impl Default for __BindgenOpaqueArray8<[T; N]> { + fn default() -> Self { + Self([::default(); N]) + } +} #[repr(transparent)] #[derive(Debug, Copy, Clone)] pub struct Foo(pub id); @@ -20,7 +28,7 @@ impl Foo { } impl IFoo for Foo {} pub trait IFoo: Sized + std::ops::Deref { - unsafe fn get(&self) -> u64 + unsafe fn get(&self) -> __BindgenOpaqueArray8<[u8; 8usize]> where ::Target: objc::Message + Sized, { @@ -48,7 +56,10 @@ pub trait IFooMultiGeneric< KeyType: 'static, ObjectType: 'static, >: Sized + std::ops::Deref { - unsafe fn objectForKey_(&self, key: u64) -> u64 + unsafe fn objectForKey_( + &self, + key: __BindgenOpaqueArray8<[u8; 8usize]>, + ) -> __BindgenOpaqueArray8<[u8; 8usize]> where ::Target: objc::Message + Sized, { 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 cc02195939..f765f01150 100644 --- a/bindgen-tests/tests/expectations/tests/opaque-template-inst-member.rs +++ b/bindgen-tests/tests/expectations/tests/opaque-template-inst-member.rs @@ -1,10 +1,8 @@ #![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)] +#[derive(PartialEq, Eq, Copy, Clone, Debug, Hash)] #[repr(C)] -pub struct __BindgenOpaqueArray(pub [T; N]); -impl Default for __BindgenOpaqueArray { +pub struct __BindgenOpaqueArray(pub T); +impl Default for __BindgenOpaqueArray<[T; N]> { fn default() -> Self { Self([::default(); N]) } @@ -17,8 +15,9 @@ pub struct OpaqueTemplate { /** This should not end up deriving Debug/Hash because its `mBlah` field cannot derive Debug/Hash because the instantiation's definition cannot derive Debug/Hash.*/ #[repr(C)] +#[derive(Debug, Default, Copy, Clone, Hash, PartialEq, Eq)] pub struct ContainsOpaqueTemplate { - pub mBlah: __BindgenOpaqueArray, + pub mBlah: __BindgenOpaqueArray<[u32; 101usize]>, pub mBaz: ::std::os::raw::c_int, } #[allow(clippy::unnecessary_operation, clippy::identity_op)] @@ -36,25 +35,12 @@ const _: () = { "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(); - unsafe { - ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); - s.assume_init() - } - } -} -impl ::std::cmp::PartialEq for ContainsOpaqueTemplate { - fn eq(&self, other: &ContainsOpaqueTemplate) -> bool { - 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)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct InheritsOpaqueTemplate { - pub _base: __BindgenOpaqueArray, + pub _base: __BindgenOpaqueArray<[u8; 401usize]>, pub wow: *mut ::std::os::raw::c_char, } #[allow(clippy::unnecessary_operation, clippy::identity_op)] @@ -78,8 +64,3 @@ impl Default for InheritsOpaqueTemplate { } } } -impl ::std::cmp::PartialEq for InheritsOpaqueTemplate { - fn eq(&self, other: &InheritsOpaqueTemplate) -> bool { - self._base == other._base && self.wow == other.wow - } -} diff --git a/bindgen-tests/tests/expectations/tests/partial-specialization-and-inheritance.rs b/bindgen-tests/tests/expectations/tests/partial-specialization-and-inheritance.rs index a4234d2aaa..cba5cfbb52 100644 --- a/bindgen-tests/tests/expectations/tests/partial-specialization-and-inheritance.rs +++ b/bindgen-tests/tests/expectations/tests/partial-specialization-and-inheritance.rs @@ -1,10 +1,8 @@ #![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)] +#[derive(PartialEq, Eq, Copy, Clone, Debug, Hash)] #[repr(C)] -pub struct __BindgenOpaqueArray(pub [T; N]); -impl Default for __BindgenOpaqueArray { +pub struct __BindgenOpaqueArray(pub T); +impl Default for __BindgenOpaqueArray<[T; N]> { fn default() -> Self { Self([::default(); N]) } @@ -26,7 +24,7 @@ pub struct Usage { } unsafe extern "C" { #[link_name = "\u{1}_ZN5Usage13static_memberE"] - pub static mut Usage_static_member: __BindgenOpaqueArray; + pub static mut Usage_static_member: __BindgenOpaqueArray<[u32; 2usize]>; } #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { diff --git a/bindgen-tests/tests/expectations/tests/size_t_template.rs b/bindgen-tests/tests/expectations/tests/size_t_template.rs index 9126c5071a..08ffa22750 100644 --- a/bindgen-tests/tests/expectations/tests/size_t_template.rs +++ b/bindgen-tests/tests/expectations/tests/size_t_template.rs @@ -1,10 +1,8 @@ #![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)] +#[derive(PartialEq, Eq, Copy, Clone, Debug, Hash)] #[repr(C)] -pub struct __BindgenOpaqueArray(pub [T; N]); -impl Default for __BindgenOpaqueArray { +pub struct __BindgenOpaqueArray(pub T); +impl Default for __BindgenOpaqueArray<[T; N]> { fn default() -> Self { Self([::default(); N]) } @@ -12,7 +10,7 @@ impl Default for __BindgenOpaqueArray { #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct C { - pub arr: __BindgenOpaqueArray, + pub arr: __BindgenOpaqueArray<[u32; 3usize]>, } #[allow(clippy::unnecessary_operation, clippy::identity_op)] const _: () = { diff --git a/bindgen-tests/tests/expectations/tests/unknown_attr.rs b/bindgen-tests/tests/expectations/tests/unknown_attr.rs index bdfebb29dc..d749dad977 100644 --- a/bindgen-tests/tests/expectations/tests/unknown_attr.rs +++ b/bindgen-tests/tests/expectations/tests/unknown_attr.rs @@ -1,10 +1,18 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[derive(PartialEq, Eq, Copy, Clone, Debug, Hash)] +#[repr(C, align(8))] +pub struct __BindgenOpaqueArray8(pub T); +impl Default for __BindgenOpaqueArray8<[T; N]> { + fn default() -> Self { + Self([::default(); N]) + } +} #[repr(C)] #[repr(align(16))] #[derive(Debug, Default, Copy, Clone)] pub struct max_align_t { pub __clang_max_align_nonce1: ::std::os::raw::c_longlong, - pub __bindgen_padding_0: u64, + pub __bindgen_padding_0: __BindgenOpaqueArray8<[u8; 8usize]>, pub __clang_max_align_nonce2: ::std::os::raw::c_longlong, } #[allow(clippy::unnecessary_operation, clippy::identity_op)] diff --git a/bindgen-tests/tests/expectations/tests/va_list_aarch64_linux.rs b/bindgen-tests/tests/expectations/tests/va_list_aarch64_linux.rs index 31f75ced23..b33f4894c1 100644 --- a/bindgen-tests/tests/expectations/tests/va_list_aarch64_linux.rs +++ b/bindgen-tests/tests/expectations/tests/va_list_aarch64_linux.rs @@ -1,18 +1,16 @@ #![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 { +#[derive(PartialEq, Eq, Copy, Clone, Debug, Hash)] +#[repr(C, align(8))] +pub struct __BindgenOpaqueArray8(pub T); +impl Default for __BindgenOpaqueArray8<[T; N]> { fn default() -> Self { Self([::default(); N]) } } -pub type va_list = __BindgenOpaqueArray; +pub type va_list = __BindgenOpaqueArray8<[u8; 32usize]>; unsafe extern "C" { pub fn vprintf( format: *const ::std::os::raw::c_char, - vlist: __BindgenOpaqueArray, + vlist: __BindgenOpaqueArray8<[u8; 32usize]>, ) -> ::std::os::raw::c_int; } diff --git a/bindgen/codegen/helpers.rs b/bindgen/codegen/helpers.rs index 9b2e5256c3..19338ee65f 100644 --- a/bindgen/codegen/helpers.rs +++ b/bindgen/codegen/helpers.rs @@ -4,6 +4,7 @@ use proc_macro2::{Ident, Span}; use crate::ir::context::BindgenContext; use crate::ir::layout::Layout; +use crate::ir::ty::RUST_DERIVE_IN_ARRAY_LIMIT; pub(crate) mod attributes { use proc_macro2::{Ident, Span, TokenStream}; @@ -85,32 +86,33 @@ pub(crate) fn blob( layout: Layout, ffi_safe: bool, ) -> syn::Type { - let opaque = layout.opaque(); - - // FIXME(emilio, #412): We fall back to byte alignment, but there are - // some things that legitimately are more than 8-byte aligned. - // - // Eventually we should be able to `unwrap` here, but... - let ty = opaque.known_rust_type_for_array().unwrap_or_else(|| { - warn!("Found unknown alignment on code generation!"); - syn::parse_quote! { u8 } - }); - - let data_len = opaque.array_size().unwrap_or(layout.size); - - if data_len == 1 { - ty - } else if ffi_safe { - ctx.generated_opaque_array(); - if ctx.options().enable_cxx_namespaces { - syn::parse_quote! { root::__BindgenOpaqueArray<#ty, #data_len> } + let align = layout.align.max(1); + // For alignments <= 4, it holds that the integer type of the same size aligns to that same + // size. For bigger alignments that's not guaranteed, e.g. on x86 u64 is aligned to 4 bytes. + if align <= 4 { + let ty = Layout::known_type_for_size(align).unwrap(); + let len = layout.size / align; + return if len == 1 { + ty + } else if !ffi_safe && len <= RUST_DERIVE_IN_ARRAY_LIMIT { + syn::parse_quote! { [#ty; #len] } } else { - syn::parse_quote! { __BindgenOpaqueArray<#ty, #data_len> } - } + ctx.generated_opaque_array(1); + if ctx.options().enable_cxx_namespaces { + syn::parse_quote! { root::__BindgenOpaqueArray<[#ty; #len]> } + } else { + syn::parse_quote! { __BindgenOpaqueArray<[#ty; #len]> } + } + }; + } + + ctx.generated_opaque_array(align); + let ident = format_ident!("__BindgenOpaqueArray{}", align); + let size = layout.size; + if ctx.options().enable_cxx_namespaces { + syn::parse_quote! { root::#ident<[u8; #size]> } } else { - // This is not FFI safe as an argument; the struct above is - // preferable. - syn::parse_quote! { [ #ty ; #data_len ] } + syn::parse_quote! { #ident<[u8; #size]> } } } diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 60e3404875..295029e0d9 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -580,9 +580,7 @@ impl CodeGenerator for Module { if ctx.need_bindgen_complex_type() { utils::prepend_complex_type(&mut *result); } - if ctx.need_opaque_array_type() { - utils::prepend_opaque_array_type(&mut *result); - } + utils::prepend_opaque_array_types(ctx, &mut *result); if result.saw_objc { utils::prepend_objc_header(ctx, &mut *result); } @@ -2259,14 +2257,13 @@ impl CodeGenerator for CompInfo { if has_address { let layout = Layout::new(1, 1); - let ty = helpers::blob(ctx, Layout::new(1, 1), false); struct_layout.saw_field_with_layout( "_address", layout, /* offset = */ Some(0), ); fields.push(quote! { - pub _address: #ty, + pub _address: u8, }); } } @@ -2275,7 +2272,6 @@ impl CodeGenerator for CompInfo { match layout { Some(l) => { explicit_align = Some(l.align); - let ty = helpers::blob(ctx, l, false); fields.push(quote! { pub _bindgen_opaque_blob: #ty , @@ -2312,7 +2308,7 @@ impl CodeGenerator for CompInfo { if !struct_layout.is_rust_union() { let ty = helpers::blob(ctx, layout, false); fields.push(quote! { - pub bindgen_union_field: #ty , + pub bindgen_union_field: #ty, }); } } @@ -5610,23 +5606,37 @@ pub(crate) mod utils { result.extend(old_items); } - pub(crate) fn prepend_opaque_array_type( + pub(crate) fn prepend_opaque_array_types( + ctx: &BindgenContext, result: &mut Vec, ) { - let ty = quote! { - /// 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]) + let mut tys = vec![]; + // If Bindgen could only determine the size and alignment of a type, it is represented like + // this. + for align in ctx.opaque_array_types_needed() { + let ident = if align == 1 { + format_ident!("__BindgenOpaqueArray") + } else { + format_ident!("__BindgenOpaqueArray{}", align) + }; + let repr = if align <= 1 { + quote! { #[repr(C)] } + } else { + let explicit = super::helpers::ast_ty::int_expr(align as i64); + quote! { #[repr(C, align(#explicit))] } + }; + tys.push(quote! { + #[derive(PartialEq, Eq, Copy, Clone, Debug, Hash)] + #repr + pub struct #ident(pub T); + impl Default for #ident<[T; N]> { + fn default() -> Self { + Self([::default(); N]) + } } - } - }; - - result.insert(0, ty); + }); + } + result.splice(0..0, tys); } pub(crate) fn build_path( diff --git a/bindgen/ir/analysis/derive.rs b/bindgen/ir/analysis/derive.rs index b1f167fb6c..7316950ba2 100644 --- a/bindgen/ir/analysis/derive.rs +++ b/bindgen/ir/analysis/derive.rs @@ -179,26 +179,11 @@ impl CannotDerive<'_> { return CanDerive::No; } - let layout_can_derive = - ty.layout(self.ctx).map_or(CanDerive::Yes, |l| { - l.opaque().array_size_within_derive_limit() - }); - - match layout_can_derive { - CanDerive::Yes => { - trace!( - " we can trivially derive {} for the layout", - self.derive_trait - ); - } - _ => { - trace!( - " we cannot derive {} for the layout", - self.derive_trait - ); - } - } - return layout_can_derive; + trace!( + " we can trivially derive {} for the layout", + self.derive_trait + ); + return CanDerive::Yes; } match *ty.kind() { @@ -338,25 +323,11 @@ impl CannotDerive<'_> { return CanDerive::No; } - let layout_can_derive = - ty.layout(self.ctx).map_or(CanDerive::Yes, |l| { - l.opaque().array_size_within_derive_limit() - }); - match layout_can_derive { - CanDerive::Yes => { - trace!( - " union layout can trivially derive {}", - self.derive_trait - ); - } - _ => { - trace!( - " union layout cannot derive {}", - self.derive_trait - ); - } - } - return layout_can_derive; + trace!( + " union layout can trivially derive {}", + self.derive_trait + ); + return CanDerive::Yes; } } diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index 47f837f966..346d2932f7 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -387,7 +387,7 @@ pub(crate) struct BindgenContext { options: BindgenOptions, /// Whether an opaque array was generated - generated_opaque_array: Cell, + generated_opaque_array: RefCell>, /// Whether a bindgen complex was generated generated_bindgen_complex: Cell, @@ -596,7 +596,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" options, generated_bindgen_complex: Cell::new(false), generated_bindgen_float16: Cell::new(false), - generated_opaque_array: Cell::new(false), + generated_opaque_array: Default::default(), allowlisted: None, blocklisted_types_implement_traits: Default::default(), codegen_items: None, @@ -2588,13 +2588,20 @@ If you encounter an error missing from this list, please file an issue or a PR!" } /// Call if an opaque array is generated - pub(crate) fn generated_opaque_array(&self) { - self.generated_opaque_array.set(true); + pub(crate) fn generated_opaque_array(&self, align: usize) { + self.generated_opaque_array.borrow_mut().insert(align); } /// Whether we need to generate the opaque array type - pub(crate) fn need_opaque_array_type(&self) -> bool { - self.generated_opaque_array.get() + pub(crate) fn opaque_array_types_needed(&self) -> Vec { + let mut alignments = self + .generated_opaque_array + .borrow() + .iter() + .copied() + .collect::>(); + alignments.sort_unstable(); + alignments } /// Call if a bindgen complex is generated diff --git a/bindgen/ir/item.rs b/bindgen/ir/item.rs index d38879f390..260c5e8764 100644 --- a/bindgen/ir/item.rs +++ b/bindgen/ir/item.rs @@ -12,7 +12,6 @@ use super::derive::{ use super::dot::DotAttributes; use super::function::{Function, FunctionKind}; use super::item_kind::ItemKind; -use super::layout::Opaque; use super::module::Module; use super::template::{AsTemplateParam, TemplateParameters}; use super::traversal::{EdgeKind, Trace, Tracer}; @@ -451,7 +450,7 @@ impl Item { ctx: &mut BindgenContext, ) -> TypeId { let location = ty.declaration().location(); - let ty = Opaque::from_clang_ty(ty, ctx); + let ty = Type::new_opaque_from_clang_ty(ty, ctx); let kind = ItemKind::Type(ty); let parent = ctx.root_module().into(); ctx.add_item( diff --git a/bindgen/ir/layout.rs b/bindgen/ir/layout.rs index 905e47c732..ba570e3702 100644 --- a/bindgen/ir/layout.rs +++ b/bindgen/ir/layout.rs @@ -1,10 +1,6 @@ //! Intermediate representation for the physical layout of some type. -use super::derive::CanDerive; -use super::ty::{Type, TypeKind, RUST_DERIVE_IN_ARRAY_LIMIT}; -use crate::clang; use crate::ir::context::BindgenContext; -use std::cmp; /// A type that represents the struct layout of a type. #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -71,56 +67,4 @@ impl Layout { pub(crate) fn for_size(ctx: &BindgenContext, size: usize) -> Self { Self::for_size_internal(ctx.target_pointer_size(), size) } - - /// Get this layout as an opaque type. - pub(crate) fn opaque(&self) -> Opaque { - Opaque(*self) - } -} - -/// When we are treating a type as opaque, it is just a blob with a `Layout`. -#[derive(Clone, Debug, PartialEq, Eq)] -pub(crate) struct Opaque(pub(crate) Layout); - -impl Opaque { - /// Construct a new opaque type from the given clang type. - pub(crate) fn from_clang_ty( - ty: &clang::Type, - ctx: &BindgenContext, - ) -> Type { - let layout = Layout::new(ty.size(ctx), ty.align(ctx)); - let ty_kind = TypeKind::Opaque; - let is_const = ty.is_const(); - Type::new(None, Some(layout), ty_kind, is_const) - } - - /// Return the known rust type we should use to create a correctly-aligned - /// field with this layout. - pub(crate) fn known_rust_type_for_array(&self) -> Option { - Layout::known_type_for_size(self.0.align) - } - - /// Return the array size that an opaque type for this layout should have if - /// we know the correct type for it, or `None` otherwise. - pub(crate) fn array_size(&self) -> Option { - if self.known_rust_type_for_array().is_some() { - Some(self.0.size / cmp::max(self.0.align, 1)) - } else { - None - } - } - - /// Return `true` if this opaque layout's array size will fit within the - /// maximum number of array elements that Rust allows deriving traits - /// with. Return `false` otherwise. - pub(crate) fn array_size_within_derive_limit(&self) -> CanDerive { - if self - .array_size() - .is_some_and(|size| size <= RUST_DERIVE_IN_ARRAY_LIMIT) - { - CanDerive::Yes - } else { - CanDerive::Manually - } - } } diff --git a/bindgen/ir/ty.rs b/bindgen/ir/ty.rs index 5819f1118f..a53de31c6a 100644 --- a/bindgen/ir/ty.rs +++ b/bindgen/ir/ty.rs @@ -6,7 +6,7 @@ use super::dot::DotAttributes; use super::enum_ty::Enum; use super::function::FunctionSig; use super::item::{IsOpaque, Item}; -use super::layout::{Layout, Opaque}; +use super::layout::Layout; use super::objc::ObjCInterface; use super::template::{ AsTemplateParam, TemplateInstantiation, TemplateParameters, @@ -67,6 +67,17 @@ impl Type { } } + /// Construct an opaque item from a clang type. + pub(crate) fn new_opaque_from_clang_ty( + ty: &clang::Type, + ctx: &BindgenContext, + ) -> Self { + let layout = Layout::new(ty.size(ctx), ty.align(ctx)); + let ty_kind = TypeKind::Opaque; + let is_const = ty.is_const(); + Type::new(None, Some(layout), ty_kind, is_const) + } + /// Which kind of type is this? pub(crate) fn kind(&self) -> &TypeKind { &self.kind @@ -737,7 +748,7 @@ impl Type { opaque type instead." ); return Ok(ParseResult::New( - Opaque::from_clang_ty(&canonical_ty, ctx), + Self::new_opaque_from_clang_ty(&canonical_ty, ctx), None, )); } @@ -868,7 +879,8 @@ impl Type { from class template or base \ specifier, using opaque blob" ); - let opaque = Opaque::from_clang_ty(ty, ctx); + let opaque = + Self::new_opaque_from_clang_ty(ty, ctx); return Ok(ParseResult::New(opaque, None)); } } From cc2b361b57858c1e0721df9c9f868b1091f46a2c Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Wed, 27 Aug 2025 16:25:40 -0400 Subject: [PATCH 934/942] chore: inline format args --- bindgen-tests/tests/expectations/build.rs | 3 +-- bindgen-tests/tests/tests.rs | 3 +-- bindgen/codegen/helpers.rs | 2 +- bindgen/codegen/mod.rs | 2 +- bindgen/ir/item.rs | 12 ++++-------- bindgen/lib.rs | 2 +- 6 files changed, 9 insertions(+), 15 deletions(-) diff --git a/bindgen-tests/tests/expectations/build.rs b/bindgen-tests/tests/expectations/build.rs index 6136823e21..f4ded7e12d 100644 --- a/bindgen-tests/tests/expectations/build.rs +++ b/bindgen-tests/tests/expectations/build.rs @@ -47,10 +47,9 @@ fn main() { test_string.push_str(&format!( r###" #[path = "{}"] -mod {}; +mod {module_name}; "###, path.display().to_string().replace('\\', "\\\\"), - module_name, )); } } diff --git a/bindgen-tests/tests/tests.rs b/bindgen-tests/tests/tests.rs index 27e8108052..6e3c358d3e 100644 --- a/bindgen-tests/tests/tests.rs +++ b/bindgen-tests/tests/tests.rs @@ -183,9 +183,8 @@ fn compare_generated_header( } None => panic!( "missing test expectation file and/or '__testing_only_libclang_$VERSION' \ - feature for header '{}'; looking for expectation file at '{:?}'", + feature for header '{}'; looking for expectation file at '{looked_at:?}'", header.display(), - looked_at, ), } diff --git a/bindgen/codegen/helpers.rs b/bindgen/codegen/helpers.rs index 19338ee65f..49928cce3a 100644 --- a/bindgen/codegen/helpers.rs +++ b/bindgen/codegen/helpers.rs @@ -107,7 +107,7 @@ pub(crate) fn blob( } ctx.generated_opaque_array(align); - let ident = format_ident!("__BindgenOpaqueArray{}", align); + let ident = format_ident!("__BindgenOpaqueArray{align}"); let size = layout.size; if ctx.options().enable_cxx_namespaces { syn::parse_quote! { root::#ident<[u8; #size]> } diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 295029e0d9..371f9e6609 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -5617,7 +5617,7 @@ pub(crate) mod utils { let ident = if align == 1 { format_ident!("__BindgenOpaqueArray") } else { - format_ident!("__BindgenOpaqueArray{}", align) + format_ident!("__BindgenOpaqueArray{align}") }; let repr = if align <= 1 { quote! { #[repr(C)] } diff --git a/bindgen/ir/item.rs b/bindgen/ir/item.rs index 260c5e8764..47aa248688 100644 --- a/bindgen/ir/item.rs +++ b/bindgen/ir/item.rs @@ -1701,8 +1701,7 @@ impl Item { if let Err(ParseError::Recurse) = result { warn!( "Unknown type, assuming named template type: \ - id = {:?}; spelling = {}", - id, + id = {id:?}; spelling = {}", ty.spelling() ); Item::type_param(Some(id), location, ctx) @@ -1732,13 +1731,10 @@ impl Item { debug!( "Item::type_param:\n\ - \twith_id = {:?},\n\ - \tty = {} {:?},\n\ - \tlocation: {:?}", - with_id, + \twith_id = {with_id:?},\n\ + \tty = {} {ty:?},\n\ + \tlocation: {location:?}", ty.spelling(), - ty, - location ); if ty.kind() != clang_sys::CXType_Unexposed { diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 3582e6af80..f2c8870e05 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -685,7 +685,7 @@ fn rust_to_clang_target(rust_target: &str) -> Box { let mut triple: Vec<&str> = rust_target.split_terminator('-').collect(); - assert!(!triple.is_empty(), "{}", TRIPLE_HYPHENS_MESSAGE); + assert!(!triple.is_empty(), "{TRIPLE_HYPHENS_MESSAGE}"); triple.resize(4, ""); // RISC-V From 1cf0a1fa98ec856b0253f1cfb0b6542968a72ab4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 31 Aug 2025 19:29:01 +0200 Subject: [PATCH 935/942] codegen: Fix typedefs inside constified modules. Fixes #3272 --- .../tests/constify-module-enums-basic.rs | 2 ++ .../tests/constify-module-enums-namespace.rs | 2 ++ .../tests/constify-module-enums-shadow-name.rs | 2 ++ .../constify-module-enums-simple-alias.rs | 2 ++ ...constify-module-enums-simple-nonamespace.rs | 2 ++ .../tests/constify-module-enums-types.rs | 18 ++++++++++++++++++ .../default-enum-style-constified-module.rs | 2 ++ .../tests/expectations/tests/empty-enum.rs | 6 ++++++ .../tests/enum-default-bitfield.rs | 2 ++ .../expectations/tests/enum-default-consts.rs | 2 ++ .../expectations/tests/enum-default-module.rs | 10 ++++++++++ .../expectations/tests/enum-default-rust.rs | 2 ++ .../tests/expectations/tests/enum-doc-mod.rs | 2 ++ .../expectations/tests/enum-no-debug-rust.rs | 2 ++ ...-1198-alias-rust-const-mod-bitfield-enum.rs | 4 ++++ .../issue-1198-alias-rust-const-mod-enum.rs | 4 ++++ .../tests/issue-1488-enum-new-type.rs | 2 ++ .../headers/constify-module-enums-types.hpp | 6 ++++++ bindgen/codegen/mod.rs | 3 +++ 19 files changed, 75 insertions(+) diff --git a/bindgen-tests/tests/expectations/tests/constify-module-enums-basic.rs b/bindgen-tests/tests/expectations/tests/constify-module-enums-basic.rs index f7d0f1baa6..aad696d074 100644 --- a/bindgen-tests/tests/expectations/tests/constify-module-enums-basic.rs +++ b/bindgen-tests/tests/expectations/tests/constify-module-enums-basic.rs @@ -1,5 +1,7 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod foo { + #[allow(unused_imports)] + use super::*; pub type Type = ::std::os::raw::c_uint; pub const THIS: Type = 0; pub const SHOULD_BE: Type = 1; diff --git a/bindgen-tests/tests/expectations/tests/constify-module-enums-namespace.rs b/bindgen-tests/tests/expectations/tests/constify-module-enums-namespace.rs index 883478a824..cdf6e7ebb4 100644 --- a/bindgen-tests/tests/expectations/tests/constify-module-enums-namespace.rs +++ b/bindgen-tests/tests/expectations/tests/constify-module-enums-namespace.rs @@ -10,6 +10,8 @@ pub mod root { #[allow(unused_imports)] use self::super::super::super::root; pub mod foo { + #[allow(unused_imports)] + use super::*; pub type Type = ::std::os::raw::c_uint; pub const THIS: Type = 0; pub const SHOULD_BE: Type = 1; diff --git a/bindgen-tests/tests/expectations/tests/constify-module-enums-shadow-name.rs b/bindgen-tests/tests/expectations/tests/constify-module-enums-shadow-name.rs index b5e4243c94..987f4463a2 100644 --- a/bindgen-tests/tests/expectations/tests/constify-module-enums-shadow-name.rs +++ b/bindgen-tests/tests/expectations/tests/constify-module-enums-shadow-name.rs @@ -1,5 +1,7 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod foo { + #[allow(unused_imports)] + use super::*; pub type Type = ::std::os::raw::c_uint; pub const Type: Type = 0; pub const Type_: Type = 1; diff --git a/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-alias.rs b/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-alias.rs index 63d48ef795..5f7b9ede4a 100644 --- a/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-alias.rs +++ b/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-alias.rs @@ -1,5 +1,7 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod Foo { + #[allow(unused_imports)] + use super::*; pub type Type = ::std::os::raw::c_int; pub const Variant1: Type = 0; pub const Variant2: Type = 1; diff --git a/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs b/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs index 80fa0734da..dc59f5fc1d 100644 --- a/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs +++ b/bindgen-tests/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs @@ -1,5 +1,7 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod one_Foo { + #[allow(unused_imports)] + use super::*; pub type Type = ::std::os::raw::c_int; pub const Variant1: Type = 0; pub const Variant2: Type = 1; diff --git a/bindgen-tests/tests/expectations/tests/constify-module-enums-types.rs b/bindgen-tests/tests/expectations/tests/constify-module-enums-types.rs index 6ba94cb3b9..a4a69fd72d 100644 --- a/bindgen-tests/tests/expectations/tests/constify-module-enums-types.rs +++ b/bindgen-tests/tests/expectations/tests/constify-module-enums-types.rs @@ -1,5 +1,15 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub type Uint = ::std::os::raw::c_uint; +pub mod ExplicitTypeAlias { + #[allow(unused_imports)] + use super::*; + pub type Type = Uint; + pub const SOME_CONSTANT: Type = 0; + pub const SOME_OTHER_CONSTANT: Type = 1; +} pub mod foo { + #[allow(unused_imports)] + use super::*; pub type Type = ::std::os::raw::c_uint; pub const THIS: Type = 0; pub const SHOULD_BE: Type = 1; @@ -8,12 +18,16 @@ pub mod foo { pub const AND_ALSO_THIS: Type = 42; } pub mod anon_enum { + #[allow(unused_imports)] + use super::*; pub type Type = ::std::os::raw::c_uint; pub const Variant1: Type = 0; pub const Variant2: Type = 1; pub const Variant3: Type = 2; } pub mod ns1_foo { + #[allow(unused_imports)] + use super::*; pub type Type = ::std::os::raw::c_uint; pub const THIS: Type = 0; pub const SHOULD_BE: Type = 1; @@ -21,6 +35,8 @@ pub mod ns1_foo { pub const ALSO_THIS: Type = 42; } pub mod ns2_Foo { + #[allow(unused_imports)] + use super::*; pub type Type = ::std::os::raw::c_int; pub const Variant1: Type = 0; pub const Variant2: Type = 1; @@ -90,6 +106,8 @@ impl Default for Baz { } } pub mod one_Foo { + #[allow(unused_imports)] + use super::*; pub type Type = ::std::os::raw::c_int; pub const Variant1: Type = 0; pub const Variant2: Type = 1; diff --git a/bindgen-tests/tests/expectations/tests/default-enum-style-constified-module.rs b/bindgen-tests/tests/expectations/tests/default-enum-style-constified-module.rs index 60c84e47df..2a75aa8d86 100644 --- a/bindgen-tests/tests/expectations/tests/default-enum-style-constified-module.rs +++ b/bindgen-tests/tests/expectations/tests/default-enum-style-constified-module.rs @@ -1,5 +1,7 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod Foo { + #[allow(unused_imports)] + use super::*; pub type Type = ::std::os::raw::c_uint; pub const bar: Type = 0; pub const baz: Type = 1; diff --git a/bindgen-tests/tests/expectations/tests/empty-enum.rs b/bindgen-tests/tests/expectations/tests/empty-enum.rs index fda6f581df..d19aa41845 100644 --- a/bindgen-tests/tests/expectations/tests/empty-enum.rs +++ b/bindgen-tests/tests/expectations/tests/empty-enum.rs @@ -6,6 +6,8 @@ pub enum EmptyRustified { __bindgen_cannot_repr_c_on_empty_enum = 0, } pub mod EmptyModule { + #[allow(unused_imports)] + use super::*; pub type Type = ::std::os::raw::c_uint; } #[repr(i8)] @@ -15,6 +17,8 @@ pub enum EmptyClassRustified { } pub type EmptyClassConstified = ::std::os::raw::c_char; pub mod EmptyClassModule { + #[allow(unused_imports)] + use super::*; pub type Type = ::std::os::raw::c_char; } #[repr(i8)] @@ -24,5 +28,7 @@ pub enum ForwardClassRustified { } pub type ForwardClassConstified = ::std::os::raw::c_char; pub mod ForwardClassModule { + #[allow(unused_imports)] + use super::*; pub type Type = ::std::os::raw::c_char; } diff --git a/bindgen-tests/tests/expectations/tests/enum-default-bitfield.rs b/bindgen-tests/tests/expectations/tests/enum-default-bitfield.rs index b7b14fbc1c..dda688617c 100644 --- a/bindgen-tests/tests/expectations/tests/enum-default-bitfield.rs +++ b/bindgen-tests/tests/expectations/tests/enum-default-bitfield.rs @@ -84,6 +84,8 @@ impl ::std::ops::BitAndAssign for Foo { #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Foo(pub ::std::os::raw::c_uint); pub mod Neg { + #[allow(unused_imports)] + use super::*; pub type Type = ::std::os::raw::c_int; pub const MinusOne: Type = -1; pub const One: Type = 1; diff --git a/bindgen-tests/tests/expectations/tests/enum-default-consts.rs b/bindgen-tests/tests/expectations/tests/enum-default-consts.rs index af51864c2c..1432182310 100644 --- a/bindgen-tests/tests/expectations/tests/enum-default-consts.rs +++ b/bindgen-tests/tests/expectations/tests/enum-default-consts.rs @@ -26,6 +26,8 @@ pub const Foo_Bar: Foo = 0; pub const Foo_Qux: Foo = 1; pub type Foo = ::std::os::raw::c_uint; pub mod Neg { + #[allow(unused_imports)] + use super::*; pub type Type = ::std::os::raw::c_int; pub const MinusOne: Type = -1; pub const One: Type = 1; diff --git a/bindgen-tests/tests/expectations/tests/enum-default-module.rs b/bindgen-tests/tests/expectations/tests/enum-default-module.rs index cc09d49425..23fbd22c6e 100644 --- a/bindgen-tests/tests/expectations/tests/enum-default-module.rs +++ b/bindgen-tests/tests/expectations/tests/enum-default-module.rs @@ -5,6 +5,8 @@ pub struct foo { pub member: foo__bindgen_ty_1::Type, } pub mod foo__bindgen_ty_1 { + #[allow(unused_imports)] + use super::*; pub type Type = ::std::os::raw::c_uint; pub const FOO_A: Type = 0; pub const FOO_B: Type = 1; @@ -25,22 +27,30 @@ impl Default for foo { } } pub mod Foo { + #[allow(unused_imports)] + use super::*; pub type Type = ::std::os::raw::c_uint; pub const Bar: Type = 0; pub const Qux: Type = 1; } pub mod Neg { + #[allow(unused_imports)] + use super::*; pub type Type = ::std::os::raw::c_int; pub const MinusOne: Type = -1; pub const One: Type = 1; } pub mod NoDebug { + #[allow(unused_imports)] + use super::*; ///
pub type Type = ::std::os::raw::c_uint; pub const NoDebug1: Type = 0; pub const NoDebug2: Type = 1; } pub mod Debug { + #[allow(unused_imports)] + use super::*; ///
pub type Type = ::std::os::raw::c_uint; pub const Debug1: Type = 0; diff --git a/bindgen-tests/tests/expectations/tests/enum-default-rust.rs b/bindgen-tests/tests/expectations/tests/enum-default-rust.rs index f9a99166de..59901a78ac 100644 --- a/bindgen-tests/tests/expectations/tests/enum-default-rust.rs +++ b/bindgen-tests/tests/expectations/tests/enum-default-rust.rs @@ -34,6 +34,8 @@ pub enum Foo { Qux = 1, } pub mod Neg { + #[allow(unused_imports)] + use super::*; pub type Type = ::std::os::raw::c_int; pub const MinusOne: Type = -1; pub const One: Type = 1; diff --git a/bindgen-tests/tests/expectations/tests/enum-doc-mod.rs b/bindgen-tests/tests/expectations/tests/enum-doc-mod.rs index 2b18b35df0..580d8165ac 100644 --- a/bindgen-tests/tests/expectations/tests/enum-doc-mod.rs +++ b/bindgen-tests/tests/expectations/tests/enum-doc-mod.rs @@ -1,5 +1,7 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod B { + #[allow(unused_imports)] + use super::*; /// Document enum pub type Type = ::std::os::raw::c_uint; /// Document field with three slashes diff --git a/bindgen-tests/tests/expectations/tests/enum-no-debug-rust.rs b/bindgen-tests/tests/expectations/tests/enum-no-debug-rust.rs index b728dfc898..643577e1e3 100644 --- a/bindgen-tests/tests/expectations/tests/enum-no-debug-rust.rs +++ b/bindgen-tests/tests/expectations/tests/enum-no-debug-rust.rs @@ -34,6 +34,8 @@ pub enum Foo { Qux = 1, } pub mod Neg { + #[allow(unused_imports)] + use super::*; pub type Type = ::std::os::raw::c_int; pub const MinusOne: Type = -1; pub const One: Type = 1; diff --git a/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-const-mod-bitfield-enum.rs b/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-const-mod-bitfield-enum.rs index 76c1de0b1c..a69d005623 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-const-mod-bitfield-enum.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-const-mod-bitfield-enum.rs @@ -1,11 +1,15 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod MyDupeEnum { + #[allow(unused_imports)] + use super::*; pub type Type = ::std::os::raw::c_uint; pub const A: Type = 0; pub const A_alias: Type = 0; pub const B: Type = 1; } pub mod MyOtherDupeEnum { + #[allow(unused_imports)] + use super::*; pub type Type = ::std::os::raw::c_uint; pub const C: Type = 0; pub const C_alias: Type = 0; diff --git a/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-const-mod-enum.rs b/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-const-mod-enum.rs index 76c1de0b1c..a69d005623 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-const-mod-enum.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1198-alias-rust-const-mod-enum.rs @@ -1,11 +1,15 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub mod MyDupeEnum { + #[allow(unused_imports)] + use super::*; pub type Type = ::std::os::raw::c_uint; pub const A: Type = 0; pub const A_alias: Type = 0; pub const B: Type = 1; } pub mod MyOtherDupeEnum { + #[allow(unused_imports)] + use super::*; pub type Type = ::std::os::raw::c_uint; pub const C: Type = 0; pub const C_alias: Type = 0; diff --git a/bindgen-tests/tests/expectations/tests/issue-1488-enum-new-type.rs b/bindgen-tests/tests/expectations/tests/issue-1488-enum-new-type.rs index 60882da2d5..ab4b6fc971 100644 --- a/bindgen-tests/tests/expectations/tests/issue-1488-enum-new-type.rs +++ b/bindgen-tests/tests/expectations/tests/issue-1488-enum-new-type.rs @@ -6,6 +6,8 @@ pub type Foo = ::std::os::raw::c_uint; #[derive(Debug, Copy, Clone)] pub struct FooAlias(pub Foo); pub mod Bar { + #[allow(unused_imports)] + use super::*; pub type Type = ::std::os::raw::c_uint; pub const C: Type = 0; pub const D: Type = 1; diff --git a/bindgen-tests/tests/headers/constify-module-enums-types.hpp b/bindgen-tests/tests/headers/constify-module-enums-types.hpp index decf935a00..96bed18f4b 100644 --- a/bindgen-tests/tests/headers/constify-module-enums-types.hpp +++ b/bindgen-tests/tests/headers/constify-module-enums-types.hpp @@ -1,5 +1,11 @@ // bindgen-flags: --constified-enum-module ".*" +using Uint = unsigned; +enum ExplicitTypeAlias : Uint { + SOME_CONSTANT, + SOME_OTHER_CONSTANT, +}; + typedef enum foo { THIS, SHOULD_BE, diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 371f9e6609..585845baeb 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -3562,6 +3562,9 @@ impl EnumBuilder { quote! { // todo: Probably some attributes, e.g. `cfg` should apply to the `mod`. pub mod #module_name { + #[allow(unused_imports)] + use super::*; + #( #attrs )* pub type #enum_ident = #enum_repr; From 50ec3ee0d9436ff0d6e50c5ff59bf05ef137b386 Mon Sep 17 00:00:00 2001 From: Matthew Maurer Date: Thu, 4 Sep 2025 22:05:31 +0000 Subject: [PATCH 936/942] codegen: Support new-type-alias constants Fixes #3287 --- bindgen-integration/build.rs | 4 ++ bindgen-integration/cpp/Test.h | 13 +++++ bindgen-integration/src/lib.rs | 8 +++ .../expectations/tests/new-type-alias.rs | 20 +++++++ bindgen-tests/tests/headers/new-type-alias.h | 22 ++++++++ bindgen/codegen/mod.rs | 53 +++++++------------ bindgen/ir/item.rs | 18 ++++++- 7 files changed, 104 insertions(+), 34 deletions(-) create mode 100644 bindgen-tests/tests/expectations/tests/new-type-alias.rs create mode 100644 bindgen-tests/tests/headers/new-type-alias.h diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs index c940c3e9fa..1b7c2b3b82 100644 --- a/bindgen-integration/build.rs +++ b/bindgen-integration/build.rs @@ -251,6 +251,10 @@ fn setup_macro_test() { .blocklist_function("my_prefixed_function_to_remove") .constified_enum("my_prefixed_enum_to_be_constified") .opaque_type("my_prefixed_templated_foo") + .new_type_alias("MyInt") + .new_type_alias("MyBool") + .new_type_alias("MyFloat") + .new_type_alias("MyChar") .new_type_alias("TestDeriveOnAlias") .depfile(out_rust_file_relative.display().to_string(), &out_dep_file) .generate() diff --git a/bindgen-integration/cpp/Test.h b/bindgen-integration/cpp/Test.h index 7f71210cdd..25858b2790 100644 --- a/bindgen-integration/cpp/Test.h +++ b/bindgen-integration/cpp/Test.h @@ -246,3 +246,16 @@ enum MyOrderedEnum { // Used to test custom derives on new-type alias. See `test_custom_derive`. typedef int TestDeriveOnAlias; + +// Used to test new-type alias constants. See `test_new_type_alias_const`. +typedef int MyInt; +const MyInt MY_INT = 5; + +typedef bool MyBool; +const MyBool MY_BOOL = true; + +typedef float MyFloat; +const MyFloat MY_FLOAT = 1.23f; + +typedef char MyChar; +const MyChar MY_CHAR = 'a'; diff --git a/bindgen-integration/src/lib.rs b/bindgen-integration/src/lib.rs index 22dd224ae8..8c31121b4b 100755 --- a/bindgen-integration/src/lib.rs +++ b/bindgen-integration/src/lib.rs @@ -355,3 +355,11 @@ fn test_colon_define() { let gold: u32 = (1u32 << 16) | 2; assert_eq!(gold, bindings::TESTMACRO_COLON_VALUE); } + +#[test] +fn test_new_type_alias_const() { + assert_eq!(bindings::MY_INT.0, 5); + assert_eq!(bindings::MY_BOOL.0, true); + assert_eq!(bindings::MY_FLOAT.0, 1.23f32); + assert_eq!(bindings::MY_CHAR.0, b'a' as std::ffi::c_char); +} diff --git a/bindgen-tests/tests/expectations/tests/new-type-alias.rs b/bindgen-tests/tests/expectations/tests/new-type-alias.rs new file mode 100644 index 0000000000..f63069cbe2 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/new-type-alias.rs @@ -0,0 +1,20 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub const true_: u32 = 1; +#[repr(transparent)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Foo(pub u64); +pub const Foo_A: Foo = Foo(1); +#[repr(transparent)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Bar(pub ::std::os::raw::c_char); +pub const Bar_A: Bar = Bar(97); +#[repr(transparent)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Baz(pub f32); +pub const Baz_A: Baz = Baz(3.25); +#[repr(transparent)] +#[derive(Debug, Default, Copy, Clone)] +pub struct Bang(pub bool); +pub const Bang_A: Bang = Bang(true); +pub type Boom = u64; +pub const Boom_A: Boom = 2; diff --git a/bindgen-tests/tests/headers/new-type-alias.h b/bindgen-tests/tests/headers/new-type-alias.h new file mode 100644 index 0000000000..73de94884c --- /dev/null +++ b/bindgen-tests/tests/headers/new-type-alias.h @@ -0,0 +1,22 @@ +// bindgen-flags: --new-type-alias (Foo|Bar|Baz|Bang) + +// Fake stdint.h and stdbool.h +typedef __UINT64_TYPE__ uint64_t; +#define bool _Bool +#define true 1 + +typedef uint64_t Foo; +static const Foo Foo_A = 1; + +typedef char Bar; +static const Bar Bar_A = 'a'; + +typedef float Baz; +static const Baz Baz_A = 3.25; + +typedef bool Bang; +static const Bang Bang_A = true; + +// Not wrapped +typedef uint64_t Boom; +static const Boom Boom_A = 2; diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 585845baeb..1dc108f62a 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -681,13 +681,8 @@ impl CodeGenerator for Var { let ty = var_ty.to_rust_ty_or_opaque(ctx, &()); if let Some(val) = self.val() { - match *val { - VarType::Bool(val) => { - result.push(quote! { - #(#attrs)* - pub const #canonical_ident : #ty = #val ; - }); - } + let const_expr = match *val { + VarType::Bool(val) => Some(val.to_token_stream()), VarType::Int(val) => { let int_kind = var_ty .into_resolver() @@ -702,10 +697,7 @@ impl CodeGenerator for Var { } else { helpers::ast_ty::uint_expr(val as _) }; - result.push(quote! { - #(#attrs)* - pub const #canonical_ident : #ty = #val ; - }); + Some(val) } VarType::String(ref bytes) => { let prefix = ctx.trait_prefix(); @@ -758,21 +750,24 @@ impl CodeGenerator for Var { pub const #canonical_ident: &#(#lifetime )*#array_ty = #bytes ; }); } + None } - VarType::Float(f) => { - if let Ok(expr) = helpers::ast_ty::float_expr(f) { - result.push(quote! { - #(#attrs)* - pub const #canonical_ident : #ty = #expr ; - }); - } - } - VarType::Char(c) => { - result.push(quote! { - #(#attrs)* - pub const #canonical_ident : #ty = #c ; - }); + VarType::Float(f) => helpers::ast_ty::float_expr(f).ok(), + VarType::Char(c) => Some(c.to_token_stream()), + }; + + if let Some(mut val) = const_expr { + let var_ty_item = ctx.resolve_item(var_ty); + if matches!( + var_ty_item.alias_style(ctx), + AliasVariation::NewType | AliasVariation::NewTypeDeref + ) { + val = quote! { #ty(#val) }; } + result.push(quote! { + #(#attrs)* + pub const #canonical_ident : #ty = #val ; + }); } } else { let symbol: &str = self.link_name().unwrap_or_else(|| { @@ -1005,15 +1000,7 @@ impl CodeGenerator for Type { quote! {} }; - let alias_style = if ctx.options().type_alias.matches(&name) { - AliasVariation::TypeAlias - } else if ctx.options().new_type_alias.matches(&name) { - AliasVariation::NewType - } else if ctx.options().new_type_alias_deref.matches(&name) { - AliasVariation::NewTypeDeref - } else { - ctx.options().default_alias_style - }; + let alias_style = item.alias_style(ctx); // We prefer using `pub use` over `pub type` because of: // https://github.com/rust-lang/rust/issues/26264 diff --git a/bindgen/ir/item.rs b/bindgen/ir/item.rs index 47aa248688..eea02cce6c 100644 --- a/bindgen/ir/item.rs +++ b/bindgen/ir/item.rs @@ -1,6 +1,8 @@ //! Bindgen's core intermediate representation type. -use super::super::codegen::{EnumVariation, CONSTIFIED_ENUM_MODULE_REPR_NAME}; +use super::super::codegen::{ + AliasVariation, EnumVariation, CONSTIFIED_ENUM_MODULE_REPR_NAME, +}; use super::analysis::{HasVtable, HasVtableResult, Sizedness, SizednessResult}; use super::annotations::Annotations; use super::comp::{CompKind, MethodKind}; @@ -1103,6 +1105,20 @@ impl Item { pub(crate) fn must_use(&self, ctx: &BindgenContext) -> bool { self.annotations().must_use_type() || ctx.must_use_type_by_name(self) } + + /// Get the alias style for this item. + pub(crate) fn alias_style(&self, ctx: &BindgenContext) -> AliasVariation { + let name = self.canonical_name(ctx); + if ctx.options().type_alias.matches(&name) { + AliasVariation::TypeAlias + } else if ctx.options().new_type_alias.matches(&name) { + AliasVariation::NewType + } else if ctx.options().new_type_alias_deref.matches(&name) { + AliasVariation::NewTypeDeref + } else { + ctx.options().default_alias_style + } + } } impl IsOpaque for T From dbe8ed9d9a94ceb77589b35bd8e766b65902ebd3 Mon Sep 17 00:00:00 2001 From: Felix Solcher Date: Sun, 28 Sep 2025 14:40:18 +0200 Subject: [PATCH 937/942] Add undefined behaviour warning to `rustified_non_exhaustive_enum` --- bindgen/options/mod.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bindgen/options/mod.rs b/bindgen/options/mod.rs index 767be03e35..debe16cd76 100644 --- a/bindgen/options/mod.rs +++ b/bindgen/options/mod.rs @@ -541,6 +541,11 @@ options! { /// /// This is similar to the [`Builder::rustified_enum`] style, but the `enum` is /// tagged with the `#[non_exhaustive]` attribute. + /// + /// **Use this with caution**, creating an instance of a Rust `enum` with an + /// invalid value will cause undefined behaviour, even if it's tagged with + /// `#[non_exhaustive]`. To avoid this, use the [`Builder::newtype_enum`] style + /// instead. pub fn rustified_non_exhaustive_enum>(mut self, arg: T) -> Builder { self.options.rustified_non_exhaustive_enums.insert(arg); self From af3694f07741607654500bb27532f78e78c57137 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Sun, 28 Sep 2025 16:40:36 +0100 Subject: [PATCH 938/942] Fix generation of f32 NAN, INFINITY, and NEG_INFINITY Signed-off-by: Nico Burns --- bindgen-tests/tests/expectations/tests/infinite-macro.rs | 4 ++-- bindgen/codegen/helpers.rs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bindgen-tests/tests/expectations/tests/infinite-macro.rs b/bindgen-tests/tests/expectations/tests/infinite-macro.rs index f19879fb17..63b70a1715 100644 --- a/bindgen-tests/tests/expectations/tests/infinite-macro.rs +++ b/bindgen-tests/tests/expectations/tests/infinite-macro.rs @@ -1,3 +1,3 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] -pub const INFINITY: f64 = f64::INFINITY; -pub const NAN: f64 = f64::NAN; +pub const INFINITY: f64 = f64::INFINITY as _; +pub const NAN: f64 = f64::NAN as _; diff --git a/bindgen/codegen/helpers.rs b/bindgen/codegen/helpers.rs index 49928cce3a..9b86ba47b0 100644 --- a/bindgen/codegen/helpers.rs +++ b/bindgen/codegen/helpers.rs @@ -320,14 +320,14 @@ pub(crate) mod ast_ty { } if f.is_nan() { - return Ok(quote! { f64::NAN }); + return Ok(quote! { f64::NAN as _ }); } if f.is_infinite() { let tokens = if f.is_sign_positive() { - quote! { f64::INFINITY } + quote! { f64::INFINITY as _ } } else { - quote! { f64::NEG_INFINITY } + quote! { f64::NEG_INFINITY as _ } }; return Ok(tokens); } From e604f6b5d8a29391d911501054beeec52fb7c0df Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Thu, 2 Oct 2025 01:04:35 +0100 Subject: [PATCH 939/942] Add tests for f32 literals --- bindgen-tests/tests/expectations/tests/infinite-macro.rs | 4 ++++ bindgen-tests/tests/headers/infinite-macro.h | 2 -- bindgen-tests/tests/headers/infinite-macro.hpp | 7 +++++++ 3 files changed, 11 insertions(+), 2 deletions(-) delete mode 100644 bindgen-tests/tests/headers/infinite-macro.h create mode 100644 bindgen-tests/tests/headers/infinite-macro.hpp diff --git a/bindgen-tests/tests/expectations/tests/infinite-macro.rs b/bindgen-tests/tests/expectations/tests/infinite-macro.rs index 63b70a1715..cf2b32f0ed 100644 --- a/bindgen-tests/tests/expectations/tests/infinite-macro.rs +++ b/bindgen-tests/tests/expectations/tests/infinite-macro.rs @@ -1,3 +1,7 @@ #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] pub const INFINITY: f64 = f64::INFINITY as _; +pub const NEG_INFINITY: f64 = f64::NEG_INFINITY as _; pub const NAN: f64 = f64::NAN as _; +pub const F32_INFINITY: f32 = f64::INFINITY as _; +pub const F32_NEG_INFINITY: f32 = f64::NEG_INFINITY as _; +pub const F32_NAN: f32 = f64::NAN as _; diff --git a/bindgen-tests/tests/headers/infinite-macro.h b/bindgen-tests/tests/headers/infinite-macro.h deleted file mode 100644 index ab352c5785..0000000000 --- a/bindgen-tests/tests/headers/infinite-macro.h +++ /dev/null @@ -1,2 +0,0 @@ -#define INFINITY (1.0f/0.0f) -#define NAN (0.0f/0.0f) diff --git a/bindgen-tests/tests/headers/infinite-macro.hpp b/bindgen-tests/tests/headers/infinite-macro.hpp new file mode 100644 index 0000000000..32c8b61911 --- /dev/null +++ b/bindgen-tests/tests/headers/infinite-macro.hpp @@ -0,0 +1,7 @@ +#define INFINITY (1.0f/0.0f) +#define NEG_INFINITY (-1.0f/0.0f) +#define NAN (0.0f/0.0f) + +static const float F32_INFINITY = 1.0f / 0.0f; +static const float F32_NEG_INFINITY = -1.0f / 0.0f; +static const float F32_NAN = 0.0f / 0.0f; From e2460d9891dd0bf661852fa1af52213b9d30a5d7 Mon Sep 17 00:00:00 2001 From: Vegard Eriksen Date: Thu, 2 Oct 2025 13:58:04 +0200 Subject: [PATCH 940/942] Allow constant expressions that doesn't fit in i64. Fixes #2618 --- .../tests/expectations/tests/issue-2618.rs | 13 +++++++++++++ bindgen-tests/tests/headers/issue-2618.h | 18 ++++++++++++++++++ bindgen/clang.rs | 3 ++- bindgen/ir/int.rs | 5 ----- bindgen/ir/var.rs | 2 +- 5 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 bindgen-tests/tests/expectations/tests/issue-2618.rs create mode 100644 bindgen-tests/tests/headers/issue-2618.h diff --git a/bindgen-tests/tests/expectations/tests/issue-2618.rs b/bindgen-tests/tests/expectations/tests/issue-2618.rs new file mode 100644 index 0000000000..ecac1ec81e --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/issue-2618.rs @@ -0,0 +1,13 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub const val1: u32 = 2147483647; +pub const val2: u32 = 2147483648; +pub const val3: u32 = 4294967295; +pub const val4: u64 = 9223372036854775807; +pub const val5: u64 = 9223372036854775808; +pub const val6: u64 = 18446744073709551615; +pub const val7: u32 = 2147483647; +pub const val8: u32 = 2147483648; +pub const val9: u32 = 4294967295; +pub const val10: u64 = 9223372036854775807; +pub const val11: u64 = 9223372036854775808; +pub const val12: u64 = 18446744073709551615; diff --git a/bindgen-tests/tests/headers/issue-2618.h b/bindgen-tests/tests/headers/issue-2618.h new file mode 100644 index 0000000000..841ff61d77 --- /dev/null +++ b/bindgen-tests/tests/headers/issue-2618.h @@ -0,0 +1,18 @@ +// bindgen-flags: --allowlist-var "val[0-9]+" + +typedef __UINT32_TYPE__ uint32_t; +typedef __UINT64_TYPE__ uint64_t; + +static const uint32_t val1 = 0x7fffffff; +static const uint32_t val2 = 0x80000000; +static const uint32_t val3 = 0xffffffff; +static const uint64_t val4 = 0x7fffffffffffffff; +static const uint64_t val5 = 0x8000000000000000; +static const uint64_t val6 = 0xffffffffffffffff; + +static const uint32_t val7 = (0x7fffffff); +static const uint32_t val8 = (0x80000000); +static const uint32_t val9 = (0xffffffff); +static const uint64_t val10 = (0x7fffffffffffffff); +static const uint64_t val11 = (0x8000000000000000); +static const uint64_t val12 = (0xffffffffffffffff); diff --git a/bindgen/clang.rs b/bindgen/clang.rs index 1e8326ed82..9e614da9f8 100644 --- a/bindgen/clang.rs +++ b/bindgen/clang.rs @@ -2351,10 +2351,11 @@ impl EvalResult { if unsafe { clang_EvalResult_isUnsignedInt(self.x) } != 0 { let value = unsafe { clang_EvalResult_getAsUnsigned(self.x) }; - if value > i64::MAX as c_ulonglong { + if value > u64::MAX as c_ulonglong { return None; } + // Do a wrapping cast to i64. This will be losslessly cast back to u64 later. return Some(value as i64); } diff --git a/bindgen/ir/int.rs b/bindgen/ir/int.rs index ed18a99949..217fc11efa 100644 --- a/bindgen/ir/int.rs +++ b/bindgen/ir/int.rs @@ -120,9 +120,4 @@ impl IntKind { _ => return None, }) } - - /// Whether this type's signedness matches the value. - pub(crate) fn signedness_matches(&self, val: i64) -> bool { - val >= 0 || self.is_signed() - } } diff --git a/bindgen/ir/var.rs b/bindgen/ir/var.rs index 45f4ba1ba0..9d72dcf06e 100644 --- a/bindgen/ir/var.rs +++ b/bindgen/ir/var.rs @@ -341,7 +341,7 @@ impl ClangSubItemParser for Var { }; let mut val = cursor.evaluate().and_then(|v| v.as_int()); - if val.is_none() || !kind.signedness_matches(val.unwrap()) { + if val.is_none() { val = get_integer_literal_from_cursor(&cursor); } From ac0fa3bff3c17b6b0f42f48aa4950a9a03b43611 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tin=20=C5=A0vagelj?= Date: Sat, 13 Sep 2025 23:04:00 +0200 Subject: [PATCH 941/942] Use NonNull for C++ references MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Make feature disabled by default until usability concerns are resolved. - Add test for --nonnull-references argument Signed-off-by: Tin Å vagelj --- .../tests/expectations/tests/references.rs | 61 +++++++++++++++++++ bindgen-tests/tests/headers/references.hpp | 17 ++++++ bindgen/codegen/mod.rs | 6 ++ bindgen/options/cli.rs | 5 ++ bindgen/options/mod.rs | 20 ++++++ 5 files changed, 109 insertions(+) create mode 100644 bindgen-tests/tests/expectations/tests/references.rs create mode 100644 bindgen-tests/tests/headers/references.hpp diff --git a/bindgen-tests/tests/expectations/tests/references.rs b/bindgen-tests/tests/expectations/tests/references.rs new file mode 100644 index 0000000000..799e855793 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/references.rs @@ -0,0 +1,61 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct Container { + pub normalPointer: *mut ::std::os::raw::c_int, + pub constPointer: *const ::std::os::raw::c_int, + pub normalRef: ::std::ptr::NonNull<::std::os::raw::c_int>, + pub constRef: ::std::ptr::NonNull<::std::os::raw::c_int>, + pub pointerRef: ::std::ptr::NonNull<*mut ::std::os::raw::c_int>, + pub constPointerRef: ::std::ptr::NonNull<*const ::std::os::raw::c_int>, +} +#[allow(clippy::unnecessary_operation, clippy::identity_op)] +const _: () = { + ["Size of Container"][::std::mem::size_of::() - 48usize]; + ["Alignment of Container"][::std::mem::align_of::() - 8usize]; + [ + "Offset of field: Container::normalPointer", + ][::std::mem::offset_of!(Container, normalPointer) - 0usize]; + [ + "Offset of field: Container::constPointer", + ][::std::mem::offset_of!(Container, constPointer) - 8usize]; + [ + "Offset of field: Container::normalRef", + ][::std::mem::offset_of!(Container, normalRef) - 16usize]; + [ + "Offset of field: Container::constRef", + ][::std::mem::offset_of!(Container, constRef) - 24usize]; + [ + "Offset of field: Container::pointerRef", + ][::std::mem::offset_of!(Container, pointerRef) - 32usize]; + [ + "Offset of field: Container::constPointerRef", + ][::std::mem::offset_of!(Container, constPointerRef) - 40usize]; +}; +impl Default for Container { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} +unsafe extern "C" { + #[link_name = "\u{1}_Z20refReturningFunctionv"] + pub fn refReturningFunction() -> ::std::ptr::NonNull<::std::os::raw::c_int>; +} +unsafe extern "C" { + #[link_name = "\u{1}_Z20functionConsumingRefRifRKi"] + pub fn functionConsumingRef( + someRef: ::std::ptr::NonNull<::std::os::raw::c_int>, + normalArgument: f32, + constRef: ::std::ptr::NonNull<::std::os::raw::c_int>, + ); +} +unsafe extern "C" { + #[link_name = "\u{1}_Z27functionConsumingPointerRefRPi"] + pub fn functionConsumingPointerRef( + pointerRef: ::std::ptr::NonNull<*mut ::std::os::raw::c_int>, + ); +} diff --git a/bindgen-tests/tests/headers/references.hpp b/bindgen-tests/tests/headers/references.hpp new file mode 100644 index 0000000000..6b56823d12 --- /dev/null +++ b/bindgen-tests/tests/headers/references.hpp @@ -0,0 +1,17 @@ +// bindgen-flags: --nonnull-references + +struct Container { + int *normalPointer; + const int *constPointer; + int &normalRef; + const int &constRef; + int *&pointerRef; + const int *&constPointerRef; +}; + +int &refReturningFunction(); + +void functionConsumingRef(int &someRef, float normalArgument, + const int &constRef); + +void functionConsumingPointerRef(int* &pointerRef); diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 1dc108f62a..88a5416ea4 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -4371,6 +4371,12 @@ impl TryToRustTy for Type { if inner_ty.canonical_type(ctx).is_function() || is_objc_pointer { Ok(ty) + } else if ctx.options().generate_cxx_nonnull_references && + matches!(self.kind(), TypeKind::Reference(_)) + { + // It's UB to pass null values in place of C++ references + let prefix = ctx.trait_prefix(); + Ok(syn::parse_quote! { ::#prefix::ptr::NonNull<#ty> }) } else { Ok(ty.to_ptr(is_const)) } diff --git a/bindgen/options/cli.rs b/bindgen/options/cli.rs index b60de39603..4334e9c239 100644 --- a/bindgen/options/cli.rs +++ b/bindgen/options/cli.rs @@ -258,6 +258,9 @@ struct BindgenCommand { /// Use extern crate instead of use for objc. #[arg(long)] objc_extern_crate: bool, + /// Use `NonNull` in place of raw pointers for C++ references. + #[arg(long)] + nonnull_references: bool, /// Generate block signatures instead of void pointers. #[arg(long)] generate_block: bool, @@ -590,6 +593,7 @@ where no_doc_comments, no_recursive_allowlist, objc_extern_crate, + nonnull_references, generate_block, generate_cstr, block_extern_crate, @@ -921,6 +925,7 @@ where no_doc_comments => |b, _| b.generate_comments(false), no_recursive_allowlist => |b, _| b.allowlist_recursively(false), objc_extern_crate, + nonnull_references => |b, _| b.generate_cxx_nonnull_references(true), generate_block, generate_cstr, block_extern_crate, diff --git a/bindgen/options/mod.rs b/bindgen/options/mod.rs index debe16cd76..edc979e01f 100644 --- a/bindgen/options/mod.rs +++ b/bindgen/options/mod.rs @@ -1479,6 +1479,26 @@ options! { }, as_args: |value, args| (!value).as_args(args, "--no-doc-comments"), }, + /// Whether to generate [`NonNull`] pointers for C++ references. + /// + /// [`NonNull`]: core::ptr::NonNull + generate_cxx_nonnull_references: bool { + default: false, + methods: { + /// Generate `NonNull` pointers in place of raw pointers for C++ + /// references. + /// + /// This option is disabled by default: + /// + /// Enabling it erases information about constness in generated + /// code, and `NonNull` is more cumbersome to use than raw pointers. + pub fn generate_cxx_nonnull_references(mut self, doit: bool) -> Self { + self.options.generate_cxx_nonnull_references = doit; + self + } + }, + as_args: |value, args| value.as_args(args, "--nonnull-references"), + }, /// Whether to generate inline functions. generate_inline_functions: bool { methods: { From d5fc49cd5a971895965bdfed3793e5dabf504c67 Mon Sep 17 00:00:00 2001 From: Konrad Koschel Date: Wed, 30 Jul 2025 16:00:01 +0200 Subject: [PATCH 942/942] feat: Custom attributes for extern fn blocks chore: allow both wasm_import and raw-dylib feat: Refactor specific attribute solution to general solution chore: rustfmt fix: wasm import module binding order fix: Use different test attribute --- .../tests/extern-fn-block-attrs-many.rs | 6 +++++ .../tests/extern-fn-block-attrs-wasm.rs | 6 +++++ .../tests/extern-fn-block-attrs.rs | 5 ++++ .../headers/extern-fn-block-attrs-many.h | 3 +++ .../headers/extern-fn-block-attrs-wasm.h | 3 +++ .../tests/headers/extern-fn-block-attrs.h | 3 +++ bindgen/codegen/mod.rs | 20 ++++++++++------ bindgen/options/cli.rs | 5 ++++ bindgen/options/mod.rs | 23 ++++++++++++++++++- 9 files changed, 66 insertions(+), 8 deletions(-) create mode 100644 bindgen-tests/tests/expectations/tests/extern-fn-block-attrs-many.rs create mode 100644 bindgen-tests/tests/expectations/tests/extern-fn-block-attrs-wasm.rs create mode 100644 bindgen-tests/tests/expectations/tests/extern-fn-block-attrs.rs create mode 100644 bindgen-tests/tests/headers/extern-fn-block-attrs-many.h create mode 100644 bindgen-tests/tests/headers/extern-fn-block-attrs-wasm.h create mode 100644 bindgen-tests/tests/headers/extern-fn-block-attrs.h diff --git a/bindgen-tests/tests/expectations/tests/extern-fn-block-attrs-many.rs b/bindgen-tests/tests/expectations/tests/extern-fn-block-attrs-many.rs new file mode 100644 index 0000000000..5aa9e45ec2 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/extern-fn-block-attrs-many.rs @@ -0,0 +1,6 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[allow(dead_code)] +#[cfg_attr(not(windows), link(wasm_import_module = "test-module"))] +unsafe extern "C" { + pub fn test_function(); +} diff --git a/bindgen-tests/tests/expectations/tests/extern-fn-block-attrs-wasm.rs b/bindgen-tests/tests/expectations/tests/extern-fn-block-attrs-wasm.rs new file mode 100644 index 0000000000..388594b27e --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/extern-fn-block-attrs-wasm.rs @@ -0,0 +1,6 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[link(wasm_import_module = "test-module")] +#[allow(dead_code)] +unsafe extern "C" { + pub fn test_function(); +} diff --git a/bindgen-tests/tests/expectations/tests/extern-fn-block-attrs.rs b/bindgen-tests/tests/expectations/tests/extern-fn-block-attrs.rs new file mode 100644 index 0000000000..657cec106a --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/extern-fn-block-attrs.rs @@ -0,0 +1,5 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +#[allow(dead_code)] +unsafe extern "C" { + pub fn test_function(); +} diff --git a/bindgen-tests/tests/headers/extern-fn-block-attrs-many.h b/bindgen-tests/tests/headers/extern-fn-block-attrs-many.h new file mode 100644 index 0000000000..0de6eebb36 --- /dev/null +++ b/bindgen-tests/tests/headers/extern-fn-block-attrs-many.h @@ -0,0 +1,3 @@ +// bindgen-flags: --extern-fn-block-attrs '#[allow(dead_code)]' --extern-fn-block-attrs '#[cfg_attr(not(windows), link(wasm_import_module = "test-module"))]' + +void test_function(); \ No newline at end of file diff --git a/bindgen-tests/tests/headers/extern-fn-block-attrs-wasm.h b/bindgen-tests/tests/headers/extern-fn-block-attrs-wasm.h new file mode 100644 index 0000000000..2f475f1ed1 --- /dev/null +++ b/bindgen-tests/tests/headers/extern-fn-block-attrs-wasm.h @@ -0,0 +1,3 @@ +// bindgen-flags: --extern-fn-block-attrs '#[allow(dead_code)]' --wasm-import-module-name test-module + +void test_function(); \ No newline at end of file diff --git a/bindgen-tests/tests/headers/extern-fn-block-attrs.h b/bindgen-tests/tests/headers/extern-fn-block-attrs.h new file mode 100644 index 0000000000..26480e2ef0 --- /dev/null +++ b/bindgen-tests/tests/headers/extern-fn-block-attrs.h @@ -0,0 +1,3 @@ +// bindgen-flags: --extern-fn-block-attrs '#[allow(dead_code)]' + +void test_function(); \ No newline at end of file diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 88a5416ea4..eee4f46121 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -4665,13 +4665,19 @@ impl CodeGenerator for Function { } } - // Unfortunately this can't piggyback on the `attributes` list because - // the #[link(wasm_import_module)] needs to happen before the `extern - // "C"` block. It doesn't get picked up properly otherwise - let wasm_link_attribute = - ctx.options().wasm_import_module_name.as_ref().map(|name| { - quote! { #[link(wasm_import_module = #name)] } + let mut block_attributes = quote! {}; + for attr in &ctx.options().extern_fn_block_attrs { + let parsed_attr = proc_macro2::TokenStream::from_str(attr).unwrap_or_else( + |err| { + panic!( + "Error parsing extern fn block attribute `{attr}`: {err}" + ) + }, + ); + block_attributes.extend(quote! { + #parsed_attr }); + } let should_wrap = is_internal && ctx.options().wrap_static_fns && @@ -4725,7 +4731,7 @@ impl CodeGenerator for Function { .then(|| quote!(unsafe)); let tokens = quote! { - #wasm_link_attribute + #block_attributes #safety extern #abi { #(#attributes)* pub fn #ident ( #( #args ),* ) #ret; diff --git a/bindgen/options/cli.rs b/bindgen/options/cli.rs index 4334e9c239..972b487c25 100644 --- a/bindgen/options/cli.rs +++ b/bindgen/options/cli.rs @@ -423,6 +423,9 @@ struct BindgenCommand { /// The NAME to be used in a #[link(wasm_import_module = ...)] statement #[arg(long, value_name = "NAME")] wasm_import_module_name: Option, + /// Attributes to apply to the extern function block. + #[arg(long, value_name = "ATTRS")] + extern_fn_block_attrs: Vec, /// Use dynamic loading mode with the given library NAME. #[arg(long, value_name = "NAME")] dynamic_loading: Option, @@ -647,6 +650,7 @@ where enable_function_attribute_detection, use_array_pointers_in_arguments, wasm_import_module_name, + extern_fn_block_attrs, dynamic_loading, dynamic_link_require_all, prefix_link_name, @@ -907,6 +911,7 @@ where time_phases, use_array_pointers_in_arguments => Builder::array_pointers_in_arguments, wasm_import_module_name, + extern_fn_block_attrs => Builder::extern_fn_block_attrs, ctypes_prefix, anon_fields_prefix, generate => Builder::with_codegen_config, diff --git a/bindgen/options/mod.rs b/bindgen/options/mod.rs index edc979e01f..b9b33a850b 100644 --- a/bindgen/options/mod.rs +++ b/bindgen/options/mod.rs @@ -1916,6 +1916,25 @@ options! { }, as_args: "--use-array-pointers-in-arguments", }, + /// Attributes to add to all `extern` blocks. + extern_fn_block_attrs: Vec { + methods: { + /// Add an attribute to all the `extern` blocks generated by `bindgen`. + /// + /// This can be used to add attributes such as `#[link(...)]` to all + /// the `extern` blocks. + pub fn extern_fn_block_attrs>(mut self, attr: T) -> Self { + self.options.extern_fn_block_attrs.push(attr.into()); + self + } + }, + as_args: |attrs, args| { + for attr in attrs { + args.push("--extern-fn-block-attrs".to_owned()); + args.push(attr.clone()); + } + }, + }, /// The name of the `wasm_import_module`. wasm_import_module_name: Option { methods: { @@ -1927,7 +1946,9 @@ options! { mut self, import_name: T, ) -> Self { - self.options.wasm_import_module_name = Some(import_name.into()); + self.options.extern_fn_block_attrs.push(format!( + "#[link(wasm_import_module = \"{}\")]", import_name.into() + )); self } },